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, the "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/frv/kernel/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-frv/ucontext.h:
102 unsigned long uc_flags;
103 struct ucontext *uc_link;
105 struct sigcontext uc_mcontext;
109 From include/asm-frv/signal.h:
111 typedef struct sigaltstack {
117 From include/asm-frv/sigcontext.h:
120 struct user_context sc_context;
121 unsigned long sc_oldmask;
122 } __attribute__((aligned(8)));
124 From include/asm-frv/registers.h:
134 unsigned long __status;
135 unsigned long syscallno;
136 unsigned long orig_gr8;
137 unsigned long gner[2];
138 unsigned long long iacc[1];
142 unsigned long gr[64];
146 struct user_fpmedia_regs
148 unsigned long fr[64];
149 unsigned long fner[2];
150 unsigned long msr[2];
151 unsigned long acc[8];
152 unsigned char accg[8];
153 unsigned long fsr[1];
158 struct user_int_regs i;
159 struct user_fpmedia_regs f;
162 } __attribute__((aligned(8))); */
165 frv_linux_sigcontext_reg_addr (struct frame_info *next_frame, int regno,
166 CORE_ADDR *sc_addr_cache_ptr)
170 if (sc_addr_cache_ptr && *sc_addr_cache_ptr)
172 sc_addr = *sc_addr_cache_ptr;
180 pc = frame_pc_unwind (next_frame);
181 tramp_type = frv_linux_pc_in_sigtramp (pc, 0);
183 frame_unwind_register (next_frame, sp_regnum, buf);
184 sp = extract_unsigned_integer (buf, sizeof buf);
186 if (tramp_type == NORMAL_SIGTRAMP)
188 /* For a normal sigtramp frame, the sigcontext struct starts
192 else if (tramp_type == RT_SIGTRAMP)
194 /* For a realtime sigtramp frame, SP + 12 contains a pointer
195 to the a ucontext struct. The ucontext struct contains a
196 sigcontext struct starting 24 bytes in. (The offset of
197 uc_mcontext within struct ucontext is derived as follows:
198 stack_t is a 12-byte struct and struct sigcontext is
199 8-byte aligned. This gives an offset of 8 + 12 + 4 (for
201 if (target_read_memory (sp + 12, buf, sizeof buf) != 0)
203 warning (_("Can't read realtime sigtramp frame."));
206 sc_addr = extract_unsigned_integer (buf, sizeof buf);
210 internal_error (__FILE__, __LINE__, _("not a signal trampoline"));
212 if (sc_addr_cache_ptr)
213 *sc_addr_cache_ptr = sc_addr;
220 /* sc_addr + 4 has "isr", the Integer Status Register. */
231 /* sc_addr + 28 is __status, the exception status.
232 sc_addr + 32 is syscallno, the syscall number or -1.
233 sc_addr + 36 is orig_gr8, the original syscall arg #1.
234 sc_addr + 40 is gner[0].
235 sc_addr + 44 is gner[1]. */
241 if (first_gpr_regnum <= regno && regno <= last_gpr_regnum)
242 return sc_addr + 56 + 4 * (regno - first_gpr_regnum);
243 else if (first_fpr_regnum <= regno && regno <= last_fpr_regnum)
244 return sc_addr + 312 + 4 * (regno - first_fpr_regnum);
246 return -1; /* not saved. */
250 /* Signal trampolines. */
252 static struct trad_frame_cache *
253 frv_linux_sigtramp_frame_cache (struct frame_info *next_frame, void **this_cache)
255 struct trad_frame_cache *cache;
256 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
260 CORE_ADDR sc_addr_cache_val = 0;
261 struct frame_id this_id;
266 cache = trad_frame_cache_zalloc (next_frame);
268 /* FIXME: cagney/2004-05-01: This is is long standing broken code.
269 The frame ID's code address should be the start-address of the
270 signal trampoline and not the current PC within that
272 frame_unwind_register (next_frame, sp_regnum, buf);
273 this_id = frame_id_build (extract_unsigned_integer (buf, sizeof buf),
274 frame_pc_unwind (next_frame));
275 trad_frame_set_id (cache, this_id);
277 for (regnum = 0; regnum < frv_num_regs; regnum++)
279 LONGEST reg_addr = frv_linux_sigcontext_reg_addr (next_frame, regnum,
282 trad_frame_set_reg_addr (cache, regnum, reg_addr);
290 frv_linux_sigtramp_frame_this_id (struct frame_info *next_frame, void **this_cache,
291 struct frame_id *this_id)
293 struct trad_frame_cache *cache =
294 frv_linux_sigtramp_frame_cache (next_frame, this_cache);
295 trad_frame_get_id (cache, this_id);
299 frv_linux_sigtramp_frame_prev_register (struct frame_info *next_frame,
301 int regnum, int *optimizedp,
302 enum lval_type *lvalp, CORE_ADDR *addrp,
303 int *realnump, void *valuep)
305 /* Make sure we've initialized the cache. */
306 struct trad_frame_cache *cache =
307 frv_linux_sigtramp_frame_cache (next_frame, this_cache);
308 trad_frame_get_register (cache, next_frame, regnum, optimizedp, lvalp,
309 addrp, realnump, valuep);
312 static const struct frame_unwind frv_linux_sigtramp_frame_unwind =
315 frv_linux_sigtramp_frame_this_id,
316 frv_linux_sigtramp_frame_prev_register
319 static const struct frame_unwind *
320 frv_linux_sigtramp_frame_sniffer (struct frame_info *next_frame)
322 CORE_ADDR pc = frame_pc_unwind (next_frame);
325 find_pc_partial_function (pc, &name, NULL, NULL);
326 if (frv_linux_pc_in_sigtramp (pc, name))
327 return &frv_linux_sigtramp_frame_unwind;
333 frv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
335 /* Set the sigtramp frame sniffer. */
336 frame_unwind_append_sniffer (gdbarch, frv_linux_sigtramp_frame_sniffer);
339 static enum gdb_osabi
340 frv_linux_elf_osabi_sniffer (bfd *abfd)
344 elf_flags = elf_elfheader (abfd)->e_flags;
346 /* Assume GNU/Linux if using the FDPIC ABI. If/when another OS shows
347 up that uses this ABI, we'll need to start using .note sections
349 if (elf_flags & EF_FRV_FDPIC)
350 return GDB_OSABI_LINUX;
352 return GDB_OSABI_UNKNOWN;
355 /* Provide a prototype to silence -Wmissing-prototypes. */
356 void _initialize_frv_linux_tdep (void);
359 _initialize_frv_linux_tdep (void)
361 gdbarch_register_osabi (bfd_arch_frv, 0, GDB_OSABI_LINUX, frv_linux_init_abi);
362 gdbarch_register_osabi_sniffer (bfd_arch_frv,
363 bfd_target_elf_flavour,
364 frv_linux_elf_osabi_sniffer);