GDB (xrefs)
Loading...
Searching...
No Matches
frv-linux-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for GNU/Linux running on the Fujitsu FR-V,
2 for GDB.
3
4 Copyright (C) 2004-2023 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21#include "defs.h"
22#include "gdbcore.h"
23#include "target.h"
24#include "frame.h"
25#include "osabi.h"
26#include "regcache.h"
27#include "elf-bfd.h"
28#include "elf/frv.h"
29#include "frv-tdep.h"
30#include "trad-frame.h"
31#include "frame-unwind.h"
32#include "regset.h"
33#include "linux-tdep.h"
34#include "gdbarch.h"
35
36/* Define the size (in bytes) of an FR-V instruction. */
37static const int frv_instr_size = 4;
38
39enum {
41 RT_SIGTRAMP = 2
42};
43
44static int
46 const char *name)
47{
48 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
49 gdb_byte buf[frv_instr_size];
50 LONGEST instr;
51 int retval = 0;
52
53 if (target_read_memory (pc, buf, sizeof buf) != 0)
54 return 0;
55
56 instr = extract_unsigned_integer (buf, sizeof buf, byte_order);
57
58 if (instr == 0x8efc0077) /* setlos #__NR_sigreturn, gr7 */
59 retval = NORMAL_SIGTRAMP;
60 else if (instr == 0x8efc00ad) /* setlos #__NR_rt_sigreturn, gr7 */
61 retval = RT_SIGTRAMP;
62 else
63 return 0;
64
65 if (target_read_memory (pc + frv_instr_size, buf, sizeof buf) != 0)
66 return 0;
67 instr = extract_unsigned_integer (buf, sizeof buf, byte_order);
68 if (instr != 0xc0700000) /* tira gr0, 0 */
69 return 0;
70
71 /* If we get this far, we'll return a non-zero value, either
72 NORMAL_SIGTRAMP (1) or RT_SIGTRAMP (2). */
73 return retval;
74}
75
76/* Given NEXT_FRAME, the "callee" frame of the sigtramp frame that we
77 wish to decode, and REGNO, one of the frv register numbers defined
78 in frv-tdep.h, return the address of the saved register (corresponding
79 to REGNO) in the sigtramp frame. Return -1 if the register is not
80 found in the sigtramp frame. The magic numbers in the code below
81 were computed by examining the following kernel structs:
82
83 From arch/frv/kernel/signal.c:
84
85 struct sigframe
86 {
87 void (*pretcode)(void);
88 int sig;
89 struct sigcontext sc;
90 unsigned long extramask[_NSIG_WORDS-1];
91 uint32_t retcode[2];
92 };
93
94 struct rt_sigframe
95 {
96 void (*pretcode)(void);
97 int sig;
98 struct siginfo *pinfo;
99 void *puc;
100 struct siginfo info;
101 struct ucontext uc;
102 uint32_t retcode[2];
103 };
104
105 From include/asm-frv/ucontext.h:
106
107 struct ucontext {
108 unsigned long uc_flags;
109 struct ucontext *uc_link;
110 stack_t uc_stack;
111 struct sigcontext uc_mcontext;
112 sigset_t uc_sigmask;
113 };
114
115 From include/asm-frv/signal.h:
116
117 typedef struct sigaltstack {
118 void *ss_sp;
119 int ss_flags;
120 size_t ss_size;
121 } stack_t;
122
123 From include/asm-frv/sigcontext.h:
124
125 struct sigcontext {
126 struct user_context sc_context;
127 unsigned long sc_oldmask;
128 } __attribute__((aligned(8)));
129
130 From include/asm-frv/registers.h:
131 struct user_int_regs
132 {
133 unsigned long psr;
134 unsigned long isr;
135 unsigned long ccr;
136 unsigned long cccr;
137 unsigned long lr;
138 unsigned long lcr;
139 unsigned long pc;
140 unsigned long __status;
141 unsigned long syscallno;
142 unsigned long orig_gr8;
143 unsigned long gner[2];
144 unsigned long long iacc[1];
145
146 union {
147 unsigned long tbr;
148 unsigned long gr[64];
149 };
150 };
151
152 struct user_fpmedia_regs
153 {
154 unsigned long fr[64];
155 unsigned long fner[2];
156 unsigned long msr[2];
157 unsigned long acc[8];
158 unsigned char accg[8];
159 unsigned long fsr[1];
160 };
161
162 struct user_context
163 {
164 struct user_int_regs i;
165 struct user_fpmedia_regs f;
166
167 void *extension;
168 } __attribute__((aligned(8))); */
169
170static LONGEST
172 CORE_ADDR *sc_addr_cache_ptr)
173{
174 struct gdbarch *gdbarch = get_frame_arch (this_frame);
175 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
176 CORE_ADDR sc_addr;
177
178 if (sc_addr_cache_ptr && *sc_addr_cache_ptr)
179 {
180 sc_addr = *sc_addr_cache_ptr;
181 }
182 else
183 {
184 CORE_ADDR pc, sp;
185 gdb_byte buf[4];
186 int tramp_type;
187
188 pc = get_frame_pc (this_frame);
189 tramp_type = frv_linux_pc_in_sigtramp (gdbarch, pc, 0);
190
191 get_frame_register (this_frame, sp_regnum, buf);
192 sp = extract_unsigned_integer (buf, sizeof buf, byte_order);
193
194 if (tramp_type == NORMAL_SIGTRAMP)
195 {
196 /* For a normal sigtramp frame, the sigcontext struct starts
197 at SP + 8. */
198 sc_addr = sp + 8;
199 }
200 else if (tramp_type == RT_SIGTRAMP)
201 {
202 /* For a realtime sigtramp frame, SP + 12 contains a pointer
203 to a ucontext struct. The ucontext struct contains a
204 sigcontext struct starting 24 bytes in. (The offset of
205 uc_mcontext within struct ucontext is derived as follows:
206 stack_t is a 12-byte struct and struct sigcontext is
207 8-byte aligned. This gives an offset of 8 + 12 + 4 (for
208 padding) = 24.) */
209 if (target_read_memory (sp + 12, buf, sizeof buf) != 0)
210 {
211 warning (_("Can't read realtime sigtramp frame."));
212 return 0;
213 }
214 sc_addr = extract_unsigned_integer (buf, sizeof buf, byte_order);
215 sc_addr += 24;
216 }
217 else
218 internal_error (_("not a signal trampoline"));
219
220 if (sc_addr_cache_ptr)
221 *sc_addr_cache_ptr = sc_addr;
222 }
223
224 switch (regno)
225 {
226 case psr_regnum :
227 return sc_addr + 0;
228 /* sc_addr + 4 has "isr", the Integer Status Register. */
229 case ccr_regnum :
230 return sc_addr + 8;
231 case cccr_regnum :
232 return sc_addr + 12;
233 case lr_regnum :
234 return sc_addr + 16;
235 case lcr_regnum :
236 return sc_addr + 20;
237 case pc_regnum :
238 return sc_addr + 24;
239 /* sc_addr + 28 is __status, the exception status.
240 sc_addr + 32 is syscallno, the syscall number or -1.
241 sc_addr + 36 is orig_gr8, the original syscall arg #1.
242 sc_addr + 40 is gner[0].
243 sc_addr + 44 is gner[1]. */
244 case iacc0h_regnum :
245 return sc_addr + 48;
246 case iacc0l_regnum :
247 return sc_addr + 52;
248 default :
249 if (first_gpr_regnum <= regno && regno <= last_gpr_regnum)
250 return sc_addr + 56 + 4 * (regno - first_gpr_regnum);
251 else if (first_fpr_regnum <= regno && regno <= last_fpr_regnum)
252 return sc_addr + 312 + 4 * (regno - first_fpr_regnum);
253 else
254 return -1; /* not saved. */
255 }
256}
257
258/* Signal trampolines. */
259
260static struct trad_frame_cache *
262 void **this_cache)
263{
264 struct gdbarch *gdbarch = get_frame_arch (this_frame);
265 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
266 struct trad_frame_cache *cache;
267 CORE_ADDR addr;
268 gdb_byte buf[4];
269 int regnum;
270 CORE_ADDR sc_addr_cache_val = 0;
271 struct frame_id this_id;
272
273 if (*this_cache)
274 return (struct trad_frame_cache *) *this_cache;
275
276 cache = trad_frame_cache_zalloc (this_frame);
277
278 /* FIXME: cagney/2004-05-01: This is is long standing broken code.
279 The frame ID's code address should be the start-address of the
280 signal trampoline and not the current PC within that
281 trampoline. */
282 get_frame_register (this_frame, sp_regnum, buf);
283 addr = extract_unsigned_integer (buf, sizeof buf, byte_order);
284 this_id = frame_id_build (addr, get_frame_pc (this_frame));
285 trad_frame_set_id (cache, this_id);
286
287 for (regnum = 0; regnum < frv_num_regs; regnum++)
288 {
289 LONGEST reg_addr = frv_linux_sigcontext_reg_addr (this_frame, regnum,
290 &sc_addr_cache_val);
291 if (reg_addr != -1)
292 trad_frame_set_reg_addr (cache, regnum, reg_addr);
293 }
294
295 *this_cache = cache;
296 return cache;
297}
298
299static void
301 void **this_cache,
302 struct frame_id *this_id)
303{
304 struct trad_frame_cache *cache
306 trad_frame_get_id (cache, this_id);
307}
308
309static struct value *
311 void **this_cache, int regnum)
312{
313 /* Make sure we've initialized the cache. */
314 struct trad_frame_cache *cache
317}
318
319static int
322 void **this_cache)
323{
324 struct gdbarch *gdbarch = get_frame_arch (this_frame);
325 CORE_ADDR pc = get_frame_pc (this_frame);
326 const char *name;
327
328 find_pc_partial_function (pc, &name, NULL, NULL);
330 return 1;
331
332 return 0;
333}
334
345
346/* The FRV kernel defines ELF_NGREG as 46. We add 2 in order to include
347 the loadmap addresses in the register set. (See below for more info.) */
348#define FRV_ELF_NGREG (46 + 2)
349typedef unsigned char frv_elf_greg_t[4];
351
352typedef unsigned char frv_elf_fpreg_t[4];
353typedef struct
354{
359 unsigned char accg[8];
362
363/* Register maps. */
364
366 {
367 { 1, psr_regnum, 4 },
368 { 1, REGCACHE_MAP_SKIP, 4 }, /* isr */
369 { 1, ccr_regnum, 4 },
370 { 1, cccr_regnum, 4 },
371 { 1, lr_regnum, 4 },
372 { 1, lcr_regnum, 4 },
373 { 1, pc_regnum, 4 },
374 { 1, REGCACHE_MAP_SKIP, 4 }, /* __status */
375 { 1, REGCACHE_MAP_SKIP, 4 }, /* syscallno */
376 { 1, REGCACHE_MAP_SKIP, 4 }, /* orig_gr8 */
377 { 1, gner0_regnum, 4 },
378 { 1, gner1_regnum, 4 },
379 { 1, REGCACHE_MAP_SKIP, 8 }, /* iacc0 */
380 { 1, tbr_regnum, 4 },
381 { 31, first_gpr_regnum + 1, 4 }, /* gr1 ... gr31 */
382
383 /* Technically, the loadmap addresses are not part of `pr_reg' as
384 found in the elf_prstatus struct. The fields which communicate
385 the loadmap address appear (by design) immediately after
386 `pr_reg' though, and the BFD function elf32_frv_grok_prstatus()
387 has been implemented to include these fields in the register
388 section that it extracts from the core file. So, for our
389 purposes, they may be viewed as registers. */
390
393 { 0 }
394 };
395
397 {
398 { 64, first_fpr_regnum, 4 }, /* fr0 ... fr63 */
399 { 1, fner0_regnum, 4 },
400 { 1, fner1_regnum, 4 },
401 { 1, msr0_regnum, 4 },
402 { 1, msr1_regnum, 4 },
403 { 8, acc0_regnum, 4 }, /* acc0 ... acc7 */
404 { 1, accg0123_regnum, 4 },
405 { 1, accg4567_regnum, 4 },
406 { 1, fsr0_regnum, 4 },
407 { 0 }
408 };
409
410/* Unpack an frv_elf_gregset_t into GDB's register cache. */
411
412static void
414 struct regcache *regcache,
415 int regnum, const void *gregs, size_t len)
416{
417 int regi;
418
419 /* gr0 always contains 0. Also, the kernel passes the TBR value in
420 this slot. */
422
423 /* Fill gr32, ..., gr63 with zeros. */
424 for (regi = first_gpr_regnum + 32; regi <= last_gpr_regnum; regi++)
426
428}
429
430/* FRV Linux kernel register sets. */
431
437
443
444static void
447 void *cb_data,
448 const struct regcache *regcache)
449{
450 cb (".reg", sizeof (frv_elf_gregset_t), sizeof (frv_elf_gregset_t),
451 &frv_linux_gregset, NULL, cb_data);
452 cb (".reg2", sizeof (frv_elf_fpregset_t), sizeof (frv_elf_fpregset_t),
453 &frv_linux_fpregset, NULL, cb_data);
454}
455
456
457static void
468
469static enum gdb_osabi
471{
472 int elf_flags;
473
474 elf_flags = elf_elfheader (abfd)->e_flags;
475
476 /* Assume GNU/Linux if using the FDPIC ABI. If/when another OS shows
477 up that uses this ABI, we'll need to start using .note sections
478 or some such. */
479 if (elf_flags & EF_FRV_FDPIC)
480 return GDB_OSABI_LINUX;
481 else
482 return GDB_OSABI_UNKNOWN;
483}
484
486void
488{
489 gdbarch_register_osabi (bfd_arch_frv, 0, GDB_OSABI_LINUX,
491 gdbarch_register_osabi_sniffer (bfd_arch_frv,
492 bfd_target_elf_flavour,
494}
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
void raw_supply_zeroed(int regnum)
Definition regcache.c:1110
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
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)
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
void get_frame_register(frame_info_ptr frame, int regnum, gdb_byte *buf)
Definition frame.c:1263
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
@ SIGTRAMP_FRAME
Definition frame.h:198
static enum gdb_osabi frv_linux_elf_osabi_sniffer(bfd *abfd)
static void frv_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
static struct trad_frame_cache * frv_linux_sigtramp_frame_cache(frame_info_ptr this_frame, void **this_cache)
static const struct regset frv_linux_gregset
unsigned char frv_elf_fpreg_t[4]
static void frv_linux_sigtramp_frame_this_id(frame_info_ptr this_frame, void **this_cache, struct frame_id *this_id)
#define FRV_ELF_NGREG
@ RT_SIGTRAMP
@ NORMAL_SIGTRAMP
static const struct regcache_map_entry frv_linux_gregmap[]
static void frv_linux_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
static int frv_linux_sigtramp_frame_sniffer(const struct frame_unwind *self, frame_info_ptr this_frame, void **this_cache)
static int frv_linux_pc_in_sigtramp(struct gdbarch *gdbarch, CORE_ADDR pc, const char *name)
void _initialize_frv_linux_tdep()
static LONGEST frv_linux_sigcontext_reg_addr(frame_info_ptr this_frame, int regno, CORE_ADDR *sc_addr_cache_ptr)
static const struct regset frv_linux_fpregset
static const struct regcache_map_entry frv_linux_fpregmap[]
static void frv_linux_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
static const int frv_instr_size
unsigned char frv_elf_greg_t[4]
static struct value * frv_linux_sigtramp_frame_prev_register(frame_info_ptr this_frame, void **this_cache, int regnum)
static const struct frame_unwind frv_linux_sigtramp_frame_unwind
@ frv_num_regs
Definition frv-tdep.h:84
@ msr1_regnum
Definition frv-tdep.h:76
@ accg4567_regnum
Definition frv-tdep.h:74
@ first_fpr_regnum
Definition frv-tdep.h:42
@ acc0_regnum
Definition frv-tdep.h:71
@ fner0_regnum
Definition frv-tdep.h:79
@ fsr0_regnum
Definition frv-tdep.h:70
@ iacc0l_regnum
Definition frv-tdep.h:69
@ lr_regnum
Definition frv-tdep.h:66
@ fdpic_loadmap_interp_regnum
Definition frv-tdep.h:55
@ cccr_regnum
Definition frv-tdep.h:53
@ gner1_regnum
Definition frv-tdep.h:78
@ last_gpr_regnum
Definition frv-tdep.h:38
@ psr_regnum
Definition frv-tdep.h:51
@ fner1_regnum
Definition frv-tdep.h:80
@ lcr_regnum
Definition frv-tdep.h:67
@ ccr_regnum
Definition frv-tdep.h:52
@ msr0_regnum
Definition frv-tdep.h:75
@ tbr_regnum
Definition frv-tdep.h:56
@ first_gpr_regnum
Definition frv-tdep.h:34
@ sp_regnum
Definition frv-tdep.h:35
@ accg0123_regnum
Definition frv-tdep.h:73
@ pc_regnum
Definition frv-tdep.h:46
@ last_fpr_regnum
Definition frv-tdep.h:43
@ fdpic_loadmap_exec_regnum
Definition frv-tdep.h:54
@ gner0_regnum
Definition frv-tdep.h:77
@ iacc0h_regnum
Definition frv-tdep.h:68
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
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
void linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch, int num_disp_step_buffers)
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
void gdbarch_register_osabi_sniffer(enum bfd_architecture arch, enum bfd_flavour flavour, enum gdb_osabi(*sniffer_fn)(bfd *))
Definition osabi.c:220
gdb_osabi
Definition osabi.h:25
@ GDB_OSABI_LINUX
Definition osabi.h:32
@ GDB_OSABI_UNKNOWN
Definition osabi.h:26
void regcache_collect_regset(const struct regset *regset, const struct regcache *regcache, int regnum, void *buf, size_t size)
Definition regcache.c:1273
void regcache_supply_regset(const struct regset *regset, struct regcache *regcache, int regnum, const void *buf, size_t size)
Definition regcache.c:1251
@ REGCACHE_MAP_SKIP
Definition regcache.h:121
Definition regcache.h:111
struct frame_id this_id
Definition trad-frame.c:35
frame_info_ptr this_frame
Definition trad-frame.c:32
Definition value.h:130
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition target.c:1785
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