Commit | Line | Data |
---|---|---|
386c036b MK |
1 | /* Target-dependent code for NetBSD/sparc. |
2 | ||
3 | Copyright 2002, 2003, 2004 Free Software Foundation, Inc. | |
9ce5c36a JT |
4 | Contributed by Wasabi Systems, 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 2 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, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
22 | ||
23 | #include "defs.h" | |
386c036b MK |
24 | #include "floatformat.h" |
25 | #include "frame.h" | |
26 | #include "frame-unwind.h" | |
9ce5c36a | 27 | #include "gdbcore.h" |
9ce5c36a | 28 | #include "osabi.h" |
386c036b MK |
29 | #include "regcache.h" |
30 | #include "solib-svr4.h" | |
31 | #include "symtab.h" | |
32 | #include "trad-frame.h" | |
9ce5c36a | 33 | |
386c036b | 34 | #include "gdb_assert.h" |
f6ad61e3 MK |
35 | #include "gdb_string.h" |
36 | ||
c139e7d9 | 37 | #include "sparc-tdep.h" |
9ce5c36a JT |
38 | #include "nbsd-tdep.h" |
39 | ||
386c036b | 40 | const struct sparc_gregset sparc32nbsd_gregset = |
9ce5c36a | 41 | { |
386c036b MK |
42 | 0 * 4, /* %psr */ |
43 | 1 * 4, /* %pc */ | |
44 | 2 * 4, /* %npc */ | |
45 | 3 * 4, /* %y */ | |
46 | -1, /* %wim */ | |
47 | -1, /* %tbr */ | |
48 | 5 * 4, /* %g1 */ | |
49 | -1 /* %l0 */ | |
50 | }; | |
9ce5c36a | 51 | |
386c036b MK |
52 | /* Unlike other NetBSD implementations, the SPARC port historically |
53 | used .reg and .reg2 (see bfd/netbsd-core.c), and as such, we can | |
54 | share one routine for a.out and ELF core files. */ | |
9ce5c36a | 55 | |
9ce5c36a JT |
56 | static void |
57 | fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which, | |
58 | CORE_ADDR ignore) | |
59 | { | |
386c036b MK |
60 | int reg_size = 20 * 4; |
61 | int fpreg_size = 33 * 4; | |
9ce5c36a JT |
62 | |
63 | switch (which) | |
64 | { | |
386c036b | 65 | case 0: /* Integer registers. */ |
9ce5c36a JT |
66 | if (core_reg_size != reg_size) |
67 | warning ("Wrong size register set in core file."); | |
386c036b MK |
68 | sparc32_supply_gregset (&sparc32nbsd_gregset, current_regcache, |
69 | -1, core_reg_sect); | |
9ce5c36a JT |
70 | break; |
71 | ||
386c036b | 72 | case 2: /* Floating pointer registers. */ |
9ce5c36a JT |
73 | if (core_reg_size != fpreg_size) |
74 | warning ("Wrong size FP register set in core file."); | |
386c036b | 75 | sparc32_supply_fpregset (current_regcache, -1, core_reg_sect); |
9ce5c36a JT |
76 | break; |
77 | ||
78 | default: | |
79 | /* Don't know what kind of register request this is; just ignore it. */ | |
80 | break; | |
81 | } | |
82 | } | |
83 | ||
84 | static struct core_fns sparcnbsd_core_fns = | |
85 | { | |
86 | bfd_target_unknown_flavour, /* core_flavour */ | |
87 | default_check_format, /* check_format */ | |
88 | default_core_sniffer, /* core_sniffer */ | |
89 | fetch_core_registers, /* core_read_registers */ | |
90 | NULL | |
91 | }; | |
92 | ||
93 | static struct core_fns sparcnbsd_elfcore_fns = | |
94 | { | |
95 | bfd_target_elf_flavour, /* core_flavour */ | |
96 | default_check_format, /* check_format */ | |
97 | default_core_sniffer, /* core_sniffer */ | |
98 | fetch_core_registers, /* core_read_registers */ | |
99 | NULL | |
100 | }; | |
386c036b MK |
101 | \f |
102 | /* Signal trampolines. */ | |
103 | ||
104 | /* The following variables describe the location of an on-stack signal | |
105 | trampoline. The current values correspond to the memory layout for | |
106 | NetBSD 1.3 and up. These shouldn't be necessary for NetBSD 2.0 and | |
107 | up, since NetBSD uses signal trampolines provided by libc now. */ | |
9ce5c36a | 108 | |
386c036b MK |
109 | static const CORE_ADDR sparc32nbsd_sigtramp_start = 0xeffffef0; |
110 | static const CORE_ADDR sparc32nbsd_sigtramp_end = 0xeffffff0; | |
9ce5c36a JT |
111 | |
112 | static int | |
386c036b MK |
113 | sparc32nbsd_pc_in_sigtramp (CORE_ADDR pc, char *name) |
114 | { | |
115 | if (pc >= sparc32nbsd_sigtramp_start && pc < sparc32nbsd_sigtramp_end) | |
116 | return 1; | |
117 | ||
118 | return nbsd_pc_in_sigtramp (pc, name); | |
119 | } | |
120 | ||
121 | static struct sparc_frame_cache * | |
122 | sparc32nbsd_sigcontext_frame_cache (struct frame_info *next_frame, | |
123 | void **this_cache) | |
9ce5c36a | 124 | { |
386c036b MK |
125 | struct sparc_frame_cache *cache; |
126 | CORE_ADDR addr, sigcontext_addr; | |
127 | LONGEST psr; | |
128 | int regnum, delta; | |
9ce5c36a | 129 | |
386c036b MK |
130 | if (*this_cache) |
131 | return *this_cache; | |
9ce5c36a | 132 | |
386c036b MK |
133 | cache = sparc_frame_cache (next_frame, this_cache); |
134 | gdb_assert (cache == *this_cache); | |
9ce5c36a | 135 | |
386c036b MK |
136 | /* The registers are saved in bits and pieces scattered all over the |
137 | place. The code below records their location on the assumption | |
138 | that the part of the signal trampoline that saves the state has | |
139 | been executed. */ | |
9ce5c36a | 140 | |
386c036b MK |
141 | /* If we couldn't find the frame's function, we're probably dealing |
142 | with an on-stack signal trampoline. */ | |
143 | if (cache->pc == 0) | |
144 | { | |
145 | cache->pc = sparc32nbsd_sigtramp_start; | |
146 | ||
147 | /* Since we couldn't find the frame's function, the cache was | |
148 | initialized under the assumption that we're frameless. */ | |
149 | cache->frameless_p = 0; | |
150 | addr = frame_unwind_register_unsigned (next_frame, SPARC_FP_REGNUM); | |
151 | cache->base = addr; | |
152 | } | |
153 | ||
154 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
155 | ||
156 | /* We find the appropriate instance of `struct sigcontext' at a | |
157 | fixed offset in the signal frame. */ | |
158 | sigcontext_addr = cache->base + 64 + 16; | |
159 | ||
160 | cache->saved_regs[SPARC_SP_REGNUM].addr = sigcontext_addr + 8; | |
161 | cache->saved_regs[SPARC32_PC_REGNUM].addr = sigcontext_addr + 12; | |
162 | cache->saved_regs[SPARC32_NPC_REGNUM].addr = sigcontext_addr + 16; | |
163 | cache->saved_regs[SPARC32_PSR_REGNUM].addr = sigcontext_addr + 20; | |
164 | cache->saved_regs[SPARC_G1_REGNUM].addr = sigcontext_addr + 24; | |
165 | cache->saved_regs[SPARC_O0_REGNUM].addr = sigcontext_addr + 28; | |
166 | ||
167 | /* The remaining `global' registers and %y are saved in the `local' | |
168 | registers. */ | |
169 | delta = SPARC_L0_REGNUM - SPARC_G0_REGNUM; | |
170 | for (regnum = SPARC_G2_REGNUM; regnum <= SPARC_G7_REGNUM; regnum++) | |
171 | cache->saved_regs[regnum].realreg = regnum + delta; | |
172 | cache->saved_regs[SPARC32_Y_REGNUM].realreg = SPARC_L1_REGNUM; | |
173 | ||
174 | /* The remaining `out' registers can be found in the current frame's | |
175 | `in' registers. */ | |
176 | delta = SPARC_I0_REGNUM - SPARC_O0_REGNUM; | |
177 | for (regnum = SPARC_O1_REGNUM; regnum <= SPARC_O5_REGNUM; regnum++) | |
178 | cache->saved_regs[regnum].realreg = regnum + delta; | |
179 | cache->saved_regs[SPARC_O7_REGNUM].realreg = SPARC_I7_REGNUM; | |
180 | ||
181 | /* The `local' and `in' registers have been saved in the register | |
182 | save area. */ | |
183 | addr = cache->saved_regs[SPARC_SP_REGNUM].addr; | |
184 | addr = get_frame_memory_unsigned (next_frame, addr, 4); | |
185 | for (regnum = SPARC_L0_REGNUM; | |
186 | regnum <= SPARC_I7_REGNUM; regnum++, addr += 4) | |
187 | cache->saved_regs[regnum].addr = addr; | |
188 | ||
189 | /* The floating-point registers are only saved if the EF bit in %prs | |
190 | has been set. */ | |
191 | ||
192 | #define PSR_EF 0x00001000 | |
193 | ||
194 | addr = cache->saved_regs[SPARC32_PSR_REGNUM].addr; | |
195 | psr = get_frame_memory_unsigned (next_frame, addr, 4); | |
196 | if (psr & PSR_EF) | |
197 | { | |
198 | CORE_ADDR sp; | |
199 | ||
200 | sp = frame_unwind_register_unsigned (next_frame, SPARC_SP_REGNUM); | |
201 | cache->saved_regs[SPARC32_FSR_REGNUM].addr = sp + 96; | |
202 | for (regnum = SPARC_F0_REGNUM, addr = sp + 96 + 8; | |
203 | regnum <= SPARC_F31_REGNUM; regnum++, addr += 4) | |
204 | cache->saved_regs[regnum].addr = addr; | |
205 | } | |
206 | ||
207 | return cache; | |
9ce5c36a JT |
208 | } |
209 | ||
386c036b MK |
210 | static void |
211 | sparc32nbsd_sigcontext_frame_this_id (struct frame_info *next_frame, | |
212 | void **this_cache, | |
213 | struct frame_id *this_id) | |
214 | { | |
215 | struct sparc_frame_cache *cache = | |
216 | sparc32nbsd_sigcontext_frame_cache (next_frame, this_cache); | |
217 | ||
218 | (*this_id) = frame_id_build (cache->base, cache->pc); | |
219 | } | |
220 | ||
221 | static void | |
222 | sparc32nbsd_sigcontext_frame_prev_register (struct frame_info *next_frame, | |
223 | void **this_cache, | |
224 | int regnum, int *optimizedp, | |
225 | enum lval_type *lvalp, | |
226 | CORE_ADDR *addrp, | |
227 | int *realnump, void *valuep) | |
9ce5c36a | 228 | { |
386c036b MK |
229 | struct sparc_frame_cache *cache = |
230 | sparc32nbsd_sigcontext_frame_cache (next_frame, this_cache); | |
9ce5c36a | 231 | |
386c036b MK |
232 | trad_frame_prev_register (next_frame, cache->saved_regs, regnum, |
233 | optimizedp, lvalp, addrp, realnump, valuep); | |
234 | } | |
9ce5c36a | 235 | |
386c036b MK |
236 | static const struct frame_unwind sparc32nbsd_sigcontext_frame_unwind = |
237 | { | |
238 | SIGTRAMP_FRAME, | |
239 | sparc32nbsd_sigcontext_frame_this_id, | |
240 | sparc32nbsd_sigcontext_frame_prev_register | |
241 | }; | |
9ce5c36a | 242 | |
386c036b MK |
243 | static const struct frame_unwind * |
244 | sparc32nbsd_sigtramp_frame_sniffer (struct frame_info *next_frame) | |
245 | { | |
246 | CORE_ADDR pc = frame_pc_unwind (next_frame); | |
247 | char *name; | |
9ce5c36a | 248 | |
386c036b MK |
249 | find_pc_partial_function (pc, &name, NULL, NULL); |
250 | if (sparc32nbsd_pc_in_sigtramp (pc, name)) | |
251 | { | |
252 | if (name == NULL || strncmp (name, "__sigtramp_sigcontext", 21)) | |
253 | return &sparc32nbsd_sigcontext_frame_unwind; | |
254 | } | |
255 | ||
256 | return NULL; | |
9ce5c36a | 257 | } |
386c036b MK |
258 | \f |
259 | ||
260 | /* Return non-zero if we are in a shared library trampoline code stub. */ | |
9ce5c36a JT |
261 | |
262 | static int | |
263 | sparcnbsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name) | |
264 | { | |
386c036b | 265 | return (name && !strcmp (name, "_DYNAMIC")); |
9ce5c36a JT |
266 | } |
267 | ||
268 | static void | |
386c036b | 269 | sparc32nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
9ce5c36a | 270 | { |
386c036b MK |
271 | /* NetBSD doesn't support the 128-bit `long double' from the psABI. */ |
272 | set_gdbarch_long_double_bit (gdbarch, 64); | |
273 | set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_big); | |
274 | ||
275 | set_gdbarch_pc_in_sigtramp (gdbarch, sparc32nbsd_pc_in_sigtramp); | |
276 | frame_unwind_append_sniffer (gdbarch, sparc32nbsd_sigtramp_frame_sniffer); | |
9ce5c36a JT |
277 | } |
278 | ||
279 | static void | |
386c036b | 280 | sparc32nbsd_aout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
9ce5c36a | 281 | { |
386c036b | 282 | sparc32nbsd_init_abi (info, gdbarch); |
9ce5c36a | 283 | |
386c036b MK |
284 | set_gdbarch_in_solib_call_trampoline |
285 | (gdbarch, sparcnbsd_aout_in_solib_call_trampoline); | |
9ce5c36a JT |
286 | } |
287 | ||
288 | static void | |
386c036b | 289 | sparc32nbsd_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
9ce5c36a | 290 | { |
386c036b | 291 | sparc32nbsd_init_abi (info, gdbarch); |
9ce5c36a | 292 | |
386c036b MK |
293 | set_solib_svr4_fetch_link_map_offsets |
294 | (gdbarch, nbsd_ilp32_solib_svr4_fetch_link_map_offsets); | |
9ce5c36a JT |
295 | } |
296 | ||
297 | static enum gdb_osabi | |
298 | sparcnbsd_aout_osabi_sniffer (bfd *abfd) | |
299 | { | |
300 | if (strcmp (bfd_get_target (abfd), "a.out-sparc-netbsd") == 0) | |
301 | return GDB_OSABI_NETBSD_AOUT; | |
302 | ||
303 | return GDB_OSABI_UNKNOWN; | |
304 | } | |
305 | ||
386c036b MK |
306 | \f |
307 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
308 | void _initialize_sparcnbsd_tdep (void); | |
309 | ||
9ce5c36a JT |
310 | void |
311 | _initialize_sparnbsd_tdep (void) | |
312 | { | |
313 | gdbarch_register_osabi_sniffer (bfd_arch_sparc, bfd_target_aout_flavour, | |
314 | sparcnbsd_aout_osabi_sniffer); | |
315 | ||
05816f70 | 316 | gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_NETBSD_AOUT, |
386c036b | 317 | sparc32nbsd_aout_init_abi); |
05816f70 | 318 | gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_NETBSD_ELF, |
386c036b | 319 | sparc32nbsd_elf_init_abi); |
9ce5c36a JT |
320 | |
321 | add_core_fns (&sparcnbsd_core_fns); | |
322 | add_core_fns (&sparcnbsd_elfcore_fns); | |
323 | } |