1 /* Target-dependent code for GNU/Linux running on the Fujitsu FR-V,
3 Copyright 2004 Free Software Foundation, Inc.
5 This file is part of GDB.
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 2 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
29 #include "trad-frame.h"
30 #include "frame-unwind.h"
32 /* Define the size (in bytes) of an FR-V instruction. */
33 static const int frv_instr_size
= 4;
41 frv_linux_pc_in_sigtramp (CORE_ADDR pc
, char *name
)
43 char buf
[frv_instr_size
];
47 if (target_read_memory (pc
, buf
, sizeof buf
) != 0)
50 instr
= extract_unsigned_integer (buf
, sizeof buf
);
52 if (instr
== 0x8efc0077) /* setlos #__NR_sigreturn, gr7 */
53 retval
= NORMAL_SIGTRAMP
;
54 else if (instr
-= 0x8efc00ad) /* setlos #__NR_rt_sigreturn, gr7 */
59 if (target_read_memory (pc
+ frv_instr_size
, buf
, sizeof buf
) != 0)
61 instr
= extract_unsigned_integer (buf
, sizeof buf
);
62 if (instr
!= 0xc0700000) /* tira gr0, 0 */
65 /* If we get this far, we'll return a non-zero value, either
66 NORMAL_SIGTRAMP (1) or RT_SIGTRAMP (2). */
70 /* Given NEXT_FRAME, "callee" frame of the sigtramp frame that we
71 wish to decode, and REGNO, one of the frv register numbers defined
72 in frv-tdep.h, return the address of the saved register (corresponding
73 to REGNO) in the sigtramp frame. Return -1 if the register is not
74 found in the sigtramp frame. The magic numbers in the code below
75 were computed by examining the following kernel structs:
77 From arch/frvnommu/signal.c:
81 void (*pretcode)(void);
84 unsigned long extramask[_NSIG_WORDS-1];
90 void (*pretcode)(void);
92 struct siginfo *pinfo;
99 From include/asm-frvnommu/ucontext.h:
102 unsigned long uc_flags;
103 struct ucontext *uc_link;
105 struct sigcontext uc_mcontext;
109 From include/asm-frvnommu/sigcontext.h:
112 struct user_context sc_context;
113 unsigned long sc_oldmask;
114 } __attribute__((aligned(8)));
116 From include/asm-frvnommu/registers.h:
126 unsigned long __status;
127 unsigned long syscallno;
128 unsigned long orig_gr8;
129 unsigned long gner[2];
130 unsigned long long iacc[1];
134 unsigned long gr[64];
138 struct user_fpmedia_regs
140 unsigned long fr[64];
141 unsigned long fner[2];
142 unsigned long msr[2];
143 unsigned long acc[8];
144 unsigned char accg[8];
145 unsigned long fsr[1];
150 struct user_int_regs i;
151 struct user_fpmedia_regs f;
154 } __attribute__((aligned(8))); */
157 frv_linux_sigcontext_reg_addr (struct frame_info
*next_frame
, int regno
,
158 CORE_ADDR
*sc_addr_cache_ptr
)
162 if (sc_addr_cache_ptr
&& *sc_addr_cache_ptr
)
164 sc_addr
= *sc_addr_cache_ptr
;
172 pc
= frame_pc_unwind (next_frame
);
173 tramp_type
= frv_linux_pc_in_sigtramp (pc
, 0);
175 frame_unwind_register (next_frame
, sp_regnum
, buf
);
176 sp
= extract_unsigned_integer (buf
, sizeof buf
);
178 if (tramp_type
== NORMAL_SIGTRAMP
)
180 /* For a normal sigtramp frame, the sigcontext struct starts
184 else if (tramp_type
== RT_SIGTRAMP
)
186 /* For a realtime sigtramp frame, SP + 12 contains a pointer
187 to the a ucontext struct. The ucontext struct contains
188 a sigcontext struct starting 12 bytes in. */
189 if (target_read_memory (sp
+ 12, buf
, sizeof buf
) != 0)
191 warning ("Can't read realtime sigtramp frame.");
194 sc_addr
= extract_unsigned_integer (buf
, sizeof buf
);
198 internal_error (__FILE__
, __LINE__
, "not a signal trampoline");
200 if (sc_addr_cache_ptr
)
201 *sc_addr_cache_ptr
= sc_addr
;
208 /* sc_addr + 4 has "isr", the Integer Status Register. */
219 /* sc_addr + 28 is __status, the exception status.
220 sc_addr + 32 is syscallno, the syscall number or -1.
221 sc_addr + 36 is orig_gr8, the original syscall arg #1.
222 sc_addr + 40 is gner[0].
223 sc_addr + 44 is gner[1]. */
229 if (first_gpr_regnum
<= regno
&& regno
<= last_gpr_regnum
)
230 return sc_addr
+ 56 + 4 * (regno
- first_gpr_regnum
);
231 else if (first_fpr_regnum
<= regno
&& regno
<= last_fpr_regnum
)
232 return sc_addr
+ 312 + 4 * (regno
- first_fpr_regnum
);
234 return -1; /* not saved. */
238 /* Signal trampolines. */
240 static struct trad_frame_cache
*
241 frv_linux_sigtramp_frame_cache (struct frame_info
*next_frame
, void **this_cache
)
243 struct trad_frame_cache
*cache
;
244 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
248 CORE_ADDR sc_addr_cache_val
= 0;
249 struct frame_id this_id
;
254 cache
= trad_frame_cache_zalloc (next_frame
);
256 /* FIXME: cagney/2004-05-01: This is is long standing broken code.
257 The frame ID's code address should be the start-address of the
258 signal trampoline and not the current PC within that
260 frame_unwind_register (next_frame
, sp_regnum
, buf
);
261 this_id
= frame_id_build (extract_unsigned_integer (buf
, sizeof buf
),
262 frame_pc_unwind (next_frame
));
263 trad_frame_set_id (cache
, this_id
);
265 for (regnum
= 0; regnum
< frv_num_regs
; regnum
++)
267 LONGEST reg_addr
= frv_linux_sigcontext_reg_addr (next_frame
, regnum
,
270 trad_frame_set_reg_addr (cache
, regnum
, reg_addr
);
278 frv_linux_sigtramp_frame_this_id (struct frame_info
*next_frame
, void **this_cache
,
279 struct frame_id
*this_id
)
281 struct trad_frame_cache
*cache
=
282 frv_linux_sigtramp_frame_cache (next_frame
, this_cache
);
283 trad_frame_get_id (cache
, this_id
);
287 frv_linux_sigtramp_frame_prev_register (struct frame_info
*next_frame
,
289 int regnum
, int *optimizedp
,
290 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
291 int *realnump
, void *valuep
)
293 /* Make sure we've initialized the cache. */
294 struct trad_frame_cache
*cache
=
295 frv_linux_sigtramp_frame_cache (next_frame
, this_cache
);
296 trad_frame_get_register (cache
, next_frame
, regnum
, optimizedp
, lvalp
,
297 addrp
, realnump
, valuep
);
300 static const struct frame_unwind frv_linux_sigtramp_frame_unwind
=
303 frv_linux_sigtramp_frame_this_id
,
304 frv_linux_sigtramp_frame_prev_register
307 static const struct frame_unwind
*
308 frv_linux_sigtramp_frame_sniffer (struct frame_info
*next_frame
)
310 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
313 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
314 if (frv_linux_pc_in_sigtramp (pc
, name
))
315 return &frv_linux_sigtramp_frame_unwind
;
321 frv_linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
323 /* Set the sigtramp frame sniffer. */
324 frame_unwind_append_sniffer (gdbarch
, frv_linux_sigtramp_frame_sniffer
);
327 static enum gdb_osabi
328 frv_linux_elf_osabi_sniffer (bfd
*abfd
)
332 elf_flags
= elf_elfheader (abfd
)->e_flags
;
334 /* Assume GNU/Linux if using the FDPIC ABI. If/when another OS shows
335 up that uses this ABI, we'll need to start using .note sections
337 if (elf_flags
& EF_FRV_FDPIC
)
338 return GDB_OSABI_LINUX
;
340 return GDB_OSABI_UNKNOWN
;
343 /* Provide a prototype to silence -Wmissing-prototypes. */
344 void _initialize_frv_linux_tdep (void);
347 _initialize_frv_linux_tdep (void)
349 gdbarch_register_osabi (bfd_arch_frv
, 0, GDB_OSABI_LINUX
, frv_linux_init_abi
);
350 gdbarch_register_osabi_sniffer (bfd_arch_frv
,
351 bfd_target_elf_flavour
,
352 frv_linux_elf_osabi_sniffer
);