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. */
30 /* Define the size (in bytes) of an FR-V instruction. */
31 static const int frv_instr_size = 4;
39 frv_linux_pc_in_sigtramp (CORE_ADDR pc, char *name)
41 char buf[frv_instr_size];
45 if (target_read_memory (pc, buf, sizeof buf) != 0)
48 instr = extract_unsigned_integer (buf, sizeof buf);
50 if (instr == 0x8efc0077) /* setlos #__NR_sigreturn, gr7 */
51 retval = NORMAL_SIGTRAMP;
52 else if (instr -= 0x8efc00ad) /* setlos #__NR_rt_sigreturn, gr7 */
57 if (target_read_memory (pc + frv_instr_size, buf, sizeof buf) != 0)
59 instr = extract_unsigned_integer (buf, sizeof buf);
60 if (instr != 0xc0700000) /* tira gr0, 0 */
63 /* If we get this far, we'll return a non-zero value, either
64 NORMAL_SIGTRAMP (1) or RT_SIGTRAMP (2). */
68 /* Given NEXT_FRAME, "callee" frame of the sigtramp frame that we
69 wish to decode, and REGNO, one of the frv register numbers defined
70 in frv-tdep.h, return the address of the saved register (corresponding
71 to REGNO) in the sigtramp frame. Return -1 if the register is not
72 found in the sigtramp frame. The magic numbers in the code below
73 were computed by examining the following kernel structs:
75 From arch/frvnommu/signal.c:
79 void (*pretcode)(void);
82 unsigned long extramask[_NSIG_WORDS-1];
88 void (*pretcode)(void);
90 struct siginfo *pinfo;
97 From include/asm-frvnommu/ucontext.h:
100 unsigned long uc_flags;
101 struct ucontext *uc_link;
103 struct sigcontext uc_mcontext;
107 From include/asm-frvnommu/sigcontext.h:
110 struct user_context sc_context;
111 unsigned long sc_oldmask;
112 } __attribute__((aligned(8)));
114 From include/asm-frvnommu/registers.h:
124 unsigned long __status;
125 unsigned long syscallno;
126 unsigned long orig_gr8;
127 unsigned long gner[2];
128 unsigned long long iacc[1];
132 unsigned long gr[64];
136 struct user_fpmedia_regs
138 unsigned long fr[64];
139 unsigned long fner[2];
140 unsigned long msr[2];
141 unsigned long acc[8];
142 unsigned char accg[8];
143 unsigned long fsr[1];
148 struct user_int_regs i;
149 struct user_fpmedia_regs f;
152 } __attribute__((aligned(8))); */
155 frv_linux_sigcontext_reg_addr (struct frame_info *next_frame, int regno,
156 CORE_ADDR *sc_addr_cache_ptr)
160 if (sc_addr_cache_ptr && *sc_addr_cache_ptr)
162 sc_addr = *sc_addr_cache_ptr;
170 pc = frame_pc_unwind (next_frame);
171 tramp_type = frv_linux_pc_in_sigtramp (pc, 0);
173 frame_unwind_register (next_frame, sp_regnum, buf);
174 sp = extract_unsigned_integer (buf, sizeof buf);
176 if (tramp_type == NORMAL_SIGTRAMP)
178 /* For a normal sigtramp frame, the sigcontext struct starts
182 else if (tramp_type == RT_SIGTRAMP)
184 /* For a realtime sigtramp frame, SP + 12 contains a pointer
185 to the a ucontext struct. The ucontext struct contains
186 a sigcontext struct starting 12 bytes in. */
187 if (target_read_memory (sp + 12, buf, sizeof buf) != 0)
189 warning ("Can't read realtime sigtramp frame.");
192 sc_addr = extract_unsigned_integer (buf, sizeof buf);
196 internal_error (__FILE__, __LINE__, "not a signal trampoline");
198 if (sc_addr_cache_ptr)
199 *sc_addr_cache_ptr = sc_addr;
206 /* sc_addr + 4 has "isr", the Integer Status Register. */
217 /* sc_addr + 28 is __status, the exception status.
218 sc_addr + 32 is syscallno, the syscall number or -1.
219 sc_addr + 36 is orig_gr8, the original syscall arg #1.
220 sc_addr + 40 is gner[0].
221 sc_addr + 44 is gner[1]. */
227 if (first_gpr_regnum <= regno && regno <= last_gpr_regnum)
228 return sc_addr + 56 + 4 * (regno - first_gpr_regnum);
229 else if (first_fpr_regnum <= regno && regno <= last_fpr_regnum)
230 return sc_addr + 312 + 4 * (regno - first_fpr_regnum);
232 return -1; /* not saved. */
237 frv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
239 /* When the FR-V Linux kernel calls a signal handler, the return
240 address points to a bit of code on the stack. This function is
241 used to identify this bit of code as a signal trampoline in order
242 to support backtracing through calls to signal handlers. */
243 set_gdbarch_pc_in_sigtramp (gdbarch, frv_linux_pc_in_sigtramp);
244 frv_set_sigcontext_reg_addr (gdbarch, frv_linux_sigcontext_reg_addr);
247 static enum gdb_osabi
248 frv_linux_elf_osabi_sniffer (bfd *abfd)
252 elf_flags = elf_elfheader (abfd)->e_flags;
254 /* Assume GNU/Linux if using the FDPIC ABI. If/when another OS shows
255 up that uses this ABI, we'll need to start using .note sections
257 if (elf_flags & EF_FRV_FDPIC)
258 return GDB_OSABI_LINUX;
260 return GDB_OSABI_UNKNOWN;
263 /* Provide a prototype to silence -Wmissing-prototypes. */
264 void _initialize_frv_linux_tdep (void);
267 _initialize_frv_linux_tdep (void)
269 gdbarch_register_osabi (bfd_arch_frv, 0, GDB_OSABI_LINUX, frv_linux_init_abi);
270 gdbarch_register_osabi_sniffer (bfd_arch_frv,
271 bfd_target_elf_flavour,
272 frv_linux_elf_osabi_sniffer);