GDB (xrefs)
Loading...
Searching...
No Matches
ppc-fbsd-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for PowerPC systems running FreeBSD.
2
3 Copyright (C) 2013-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "arch-utils.h"
22#include "frame.h"
23#include "gdbcore.h"
24#include "frame-unwind.h"
25#include "gdbtypes.h"
26#include "osabi.h"
27#include "regcache.h"
28#include "regset.h"
29#include "symtab.h"
30#include "target.h"
31#include "trad-frame.h"
32
33#include "ppc-tdep.h"
34#include "ppc64-tdep.h"
35#include "ppc-fbsd-tdep.h"
36#include "fbsd-tdep.h"
37#include "solib-svr4.h"
38#include "inferior.h"
39
40
41/* 32-bit regset descriptions. */
42
44 {
45 /* General-purpose registers. */
46 /* .r0_offset = */ 0,
47 /* .gpr_size = */ 4,
48 /* .xr_size = */ 4,
49 /* .pc_offset = */ 144,
50 /* .ps_offset = */ -1,
51 /* .cr_offset = */ 132,
52 /* .lr_offset = */ 128,
53 /* .ctr_offset = */ 140,
54 /* .xer_offset = */ 136,
55 /* .mq_offset = */ -1,
56
57 /* Floating-point registers. */
58 /* .f0_offset = */ 0,
59 /* .fpscr_offset = */ 256,
60 /* .fpscr_size = */ 8
61 };
62
63/* 64-bit regset descriptions. */
64
66 {
67 /* General-purpose registers. */
68 /* .r0_offset = */ 0,
69 /* .gpr_size = */ 8,
70 /* .xr_size = */ 8,
71 /* .pc_offset = */ 288,
72 /* .ps_offset = */ -1,
73 /* .cr_offset = */ 264,
74 /* .lr_offset = */ 256,
75 /* .ctr_offset = */ 280,
76 /* .xer_offset = */ 272,
77 /* .mq_offset = */ -1,
78
79 /* Floating-point registers. */
80 /* .f0_offset = */ 0,
81 /* .fpscr_offset = */ 256,
82 /* .fpscr_size = */ 8
83 };
84
85/* 32-bit general-purpose register set. */
86
92
93/* 64-bit general-purpose register set. */
94
100
101/* 32-/64-bit floating-point register set. */
102
108
109const struct regset *
110ppc_fbsd_gregset (int wordsize)
111{
112 return wordsize == 8 ? &ppc64_fbsd_gregset : &ppc32_fbsd_gregset;
113}
114
115const struct regset *
117{
118 return &ppc32_fbsd_fpregset;
119}
120
121/* Iterate over core file register note sections. */
122
123static void
126 void *cb_data,
127 const struct regcache *regcache)
128{
129 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
130
131 if (tdep->wordsize == 4)
132 cb (".reg", 148, 148, &ppc32_fbsd_gregset, NULL, cb_data);
133 else
134 cb (".reg", 296, 296, &ppc64_fbsd_gregset, NULL, cb_data);
135 cb (".reg2", 264, 264, &ppc32_fbsd_fpregset, NULL, cb_data);
136}
137
138/* Default page size. */
139
140static const int ppcfbsd_page_size = 4096;
141
142/* Offset for sigreturn(2). */
143
144static const int ppcfbsd_sigreturn_offset[] = {
145 0xc, /* FreeBSD 32-bit */
146 -1
147};
148
149/* Signal trampolines. */
150
151static int
153 frame_info_ptr this_frame,
154 void **this_cache)
155{
156 struct gdbarch *gdbarch = get_frame_arch (this_frame);
157 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
158 CORE_ADDR pc = get_frame_pc (this_frame);
159 CORE_ADDR start_pc = (pc & ~(ppcfbsd_page_size - 1));
160 const int *offset;
161 const char *name;
162
163 /* A stack trampoline is detected if no name is associated
164 to the current pc and if it points inside a trampoline
165 sequence. */
166
167 find_pc_partial_function (pc, &name, NULL, NULL);
168
169 /* If we have a name, we have no trampoline, return. */
170 if (name)
171 return 0;
172
173 for (offset = ppcfbsd_sigreturn_offset; *offset != -1; offset++)
174 {
175 gdb_byte buf[2 * PPC_INSN_SIZE];
176 unsigned long insn;
177
178 if (!safe_frame_unwind_memory (this_frame, start_pc + *offset,
179 {buf, sizeof buf}))
180 continue;
181
182 /* Check for "li r0,SYS_sigreturn". */
183 insn = extract_unsigned_integer (buf, PPC_INSN_SIZE, byte_order);
184 if (insn != 0x380001a1)
185 continue;
186
187 /* Check for "sc". */
189 PPC_INSN_SIZE, byte_order);
190 if (insn != 0x44000002)
191 continue;
192
193 return 1;
194 }
195
196 return 0;
197}
198
199static struct trad_frame_cache *
201{
202 struct gdbarch *gdbarch = get_frame_arch (this_frame);
203 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
204 struct trad_frame_cache *cache;
205 CORE_ADDR addr, base, func;
206 gdb_byte buf[PPC_INSN_SIZE];
207 int i;
208
209 if (*this_cache)
210 return (struct trad_frame_cache *) *this_cache;
211
213 *this_cache = cache;
214
216 func &= ~(ppcfbsd_page_size - 1);
217 if (!safe_frame_unwind_memory (this_frame, func, {buf, sizeof buf}))
218 return cache;
219
221 addr = base + 0x10 + 2 * tdep->wordsize;
222 for (i = 0; i < ppc_num_gprs; i++, addr += tdep->wordsize)
223 {
224 int regnum = i + tdep->ppc_gp0_regnum;
225 trad_frame_set_reg_addr (cache, regnum, addr);
226 }
227 trad_frame_set_reg_addr (cache, tdep->ppc_lr_regnum, addr);
228 addr += tdep->wordsize;
229 trad_frame_set_reg_addr (cache, tdep->ppc_cr_regnum, addr);
230 addr += tdep->wordsize;
231 trad_frame_set_reg_addr (cache, tdep->ppc_xer_regnum, addr);
232 addr += tdep->wordsize;
233 trad_frame_set_reg_addr (cache, tdep->ppc_ctr_regnum, addr);
234 addr += tdep->wordsize;
236 /* SRR0? */
237 addr += tdep->wordsize;
238
239 /* Construct the frame ID using the function start. */
240 trad_frame_set_id (cache, frame_id_build (base, func));
241
242 return cache;
243}
244
245static void
247 void **this_cache, struct frame_id *this_id)
248{
249 struct trad_frame_cache *cache =
251
252 trad_frame_get_id (cache, this_id);
253}
254
255static struct value *
257 void **this_cache, int regnum)
258{
259 struct trad_frame_cache *cache =
261
263}
264
274
275static enum return_value_convention
276ppcfbsd_return_value (struct gdbarch *gdbarch, struct value *function,
277 struct type *valtype, struct regcache *regcache,
278 gdb_byte *readbuf, const gdb_byte *writebuf)
279{
280 return ppc_sysv_abi_broken_return_value (gdbarch, function, valtype,
281 regcache, readbuf, writebuf);
282}
283
284/* Implement the "get_thread_local_address" gdbarch method. */
285
286static CORE_ADDR
288 CORE_ADDR lm_addr, CORE_ADDR offset)
289{
290 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
291 struct regcache *regcache;
292 int tp_offset, tp_regnum;
293
294 regcache = get_thread_arch_regcache (current_inferior ()->process_target (),
295 ptid, gdbarch);
296
297 if (tdep->wordsize == 4)
298 {
299 tp_offset = 0x7008;
300 tp_regnum = PPC_R0_REGNUM + 2;
301 }
302 else
303 {
304 tp_offset = 0x7010;
305 tp_regnum = PPC_R0_REGNUM + 13;
306 }
307 target_fetch_registers (regcache, tp_regnum);
308
309 ULONGEST tp;
310 if (regcache->cooked_read (tp_regnum, &tp) != REG_VALID)
311 error (_("Unable to fetch tcb pointer"));
312
313 /* tp points to the end of the TCB block. The first member of the
314 TCB is the pointer to the DTV array. */
315 CORE_ADDR dtv_addr = tp - tp_offset;
316 return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset);
317}
318
319static void
321{
322 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
323
324 /* Generic FreeBSD support. */
325 fbsd_init_abi (info, gdbarch);
326
327 /* FreeBSD doesn't support the 128-bit `long double' from the psABI. */
330
331 if (tdep->wordsize == 4)
332 {
334
338
340 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
341 }
342
343 if (tdep->wordsize == 8)
344 {
349
353 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
354 }
355
358
363}
364
366void
368{
369 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_FREEBSD,
371 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_FREEBSD,
373 gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_FREEBSD,
375}
int regnum
const char *const name
bool find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr, const struct block **block)
Definition blockframe.c:373
enum register_status cooked_read(int regnum, gdb_byte *buf)
Definition regcache.c:698
friend class regcache
Definition regcache.h:269
ptid_t ptid() const
Definition regcache.h:408
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
return_value_convention
Definition defs.h:257
CORE_ADDR fbsd_get_thread_local_address(struct gdbarch *gdbarch, CORE_ADDR dtv_addr, CORE_ADDR lm_addr, CORE_ADDR offset)
Definition fbsd-tdep.c:2027
void fbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition fbsd-tdep.c:2380
enum unwind_stop_reason default_frame_unwind_stop_reason(frame_info_ptr this_frame, void **this_cache)
void frame_unwind_append_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
ULONGEST get_frame_register_unsigned(frame_info_ptr frame, int regnum)
Definition frame.c:1399
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition frame.c:736
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
Definition frame.c:3027
bool safe_frame_unwind_memory(frame_info_ptr this_frame, CORE_ADDR addr, gdb::array_view< gdb_byte > buffer)
Definition frame.c:3017
@ SIGTRAMP_FRAME
Definition frame.h:198
int gdbarch_pc_regnum(struct gdbarch *gdbarch)
Definition gdbarch.c:2054
void set_gdbarch_convert_from_func_ptr_addr(struct gdbarch *gdbarch, gdbarch_convert_from_func_ptr_addr_ftype *convert_from_func_ptr_addr)
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
void set_gdbarch_get_thread_local_address(struct gdbarch *gdbarch, gdbarch_get_thread_local_address_ftype *get_thread_local_address)
void set_gdbarch_elf_make_msymbol_special(struct gdbarch *gdbarch, gdbarch_elf_make_msymbol_special_ftype *elf_make_msymbol_special)
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype *skip_trampoline_code)
void set_gdbarch_return_value(struct gdbarch *gdbarch, gdbarch_return_value_ftype *return_value)
void set_gdbarch_gcore_bfd_target(struct gdbarch *gdbarch, const char *gcore_bfd_target)
Definition gdbarch.c:4017
int gdbarch_sp_regnum(struct gdbarch *gdbarch)
Definition gdbarch.c:2037
void set_gdbarch_long_double_format(struct gdbarch *gdbarch, const struct floatformat **long_double_format)
Definition gdbarch.c:1663
void set_gdbarch_fetch_tls_load_module_address(struct gdbarch *gdbarch, gdbarch_fetch_tls_load_module_address_ftype *fetch_tls_load_module_address)
void set_gdbarch_long_double_bit(struct gdbarch *gdbarch, int long_double_bit)
Definition gdbarch.c:1646
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype *iterate_over_regset_sections)
void iterate_over_regset_sections_cb(const char *sect_name, int supply_size, int collect_size, const struct regset *regset, const char *human_name, void *cb_data)
Definition gdbarch.h:104
const struct floatformat * floatformats_ieee_double[BFD_ENDIAN_UNKNOWN]
Definition gdbtypes.c:89
struct inferior * current_inferior(void)
Definition inferior.c:55
CORE_ADDR find_solib_trampoline_target(frame_info_ptr frame, CORE_ADDR pc)
Definition minsyms.c:1554
static CORE_ADDR lm_addr(struct so_list *so)
Definition nto-tdep.c:246
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition osabi.c:146
@ GDB_OSABI_FREEBSD
Definition osabi.h:33
static const int ppcfbsd_page_size
static struct value * ppcfbsd_sigtramp_frame_prev_register(frame_info_ptr this_frame, void **this_cache, int regnum)
static void ppcfbsd_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
static const struct frame_unwind ppcfbsd_sigtramp_frame_unwind
static struct trad_frame_cache * ppcfbsd_sigtramp_frame_cache(frame_info_ptr this_frame, void **this_cache)
static void ppcfbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
static CORE_ADDR ppcfbsd_get_thread_local_address(struct gdbarch *gdbarch, ptid_t ptid, CORE_ADDR lm_addr, CORE_ADDR offset)
static const struct ppc_reg_offsets ppc32_fbsd_reg_offsets
static const struct regset ppc32_fbsd_gregset
static const struct regset ppc64_fbsd_gregset
void _initialize_ppcfbsd_tdep()
static const struct regset ppc32_fbsd_fpregset
const struct regset * ppc_fbsd_gregset(int wordsize)
static int ppcfbsd_sigtramp_frame_sniffer(const struct frame_unwind *self, frame_info_ptr this_frame, void **this_cache)
static enum return_value_convention ppcfbsd_return_value(struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
static void ppcfbsd_sigtramp_frame_this_id(frame_info_ptr this_frame, void **this_cache, struct frame_id *this_id)
static const int ppcfbsd_sigreturn_offset[]
const struct regset * ppc_fbsd_fpregset(void)
static const struct ppc_reg_offsets ppc64_fbsd_reg_offsets
enum return_value_convention ppc_sysv_abi_broken_return_value(struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
void ppc_collect_gregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *gregs, size_t len)
void ppc_supply_fpregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *fpregs, size_t len)
void ppc_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
@ ppc_num_gprs
Definition ppc-tdep.h:318
@ PPC_R0_REGNUM
Definition ppc-tdep.h:334
void ppc_collect_fpregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *fpregs, size_t len)
#define PPC_INSN_SIZE
Definition ppc-tdep.h:440
CORE_ADDR ppc64_skip_trampoline_code(frame_info_ptr frame, CORE_ADDR pc)
Definition ppc64-tdep.c:710
void ppc64_elf_make_msymbol_special(asymbol *sym, struct minimal_symbol *msym)
Definition ppc64-tdep.c:796
CORE_ADDR ppc64_convert_from_func_ptr_addr(struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ)
Definition ppc64-tdep.c:747
struct regcache * get_thread_arch_regcache(process_stratum_target *target, ptid_t ptid, struct gdbarch *gdbarch)
Definition regcache.c:384
void(* func)(remote_target *remote, char *)
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
struct link_map_offsets * svr4_lp64_fetch_link_map_offsets(void)
CORE_ADDR svr4_fetch_objfile_link_map(struct objfile *objfile)
struct link_map_offsets * svr4_ilp32_fetch_link_map_offsets(void)
struct frame_id this_id
Definition trad-frame.c:35
frame_info_ptr this_frame
Definition trad-frame.c:32
Definition value.h:130
void target_fetch_registers(struct regcache *regcache, int regno)
Definition target.c:3928
struct trad_frame_cache * trad_frame_cache_zalloc(frame_info_ptr this_frame)
Definition trad-frame.c:39
void trad_frame_set_reg_addr(struct trad_frame_cache *this_trad_cache, int regnum, CORE_ADDR addr)
Definition trad-frame.c:110
void trad_frame_get_id(struct trad_frame_cache *this_trad_cache, struct frame_id *this_id)
Definition trad-frame.c:227
void trad_frame_set_id(struct trad_frame_cache *this_trad_cache, struct frame_id this_id)
Definition trad-frame.c:220
struct value * trad_frame_get_register(struct trad_frame_cache *this_trad_cache, frame_info_ptr this_frame, int regnum)
Definition trad-frame.c:211