Reviewed and approved by drow@mvista.com.
[deliverable/binutils-gdb.git] / gdb / sparcnbsd-tdep.c
CommitLineData
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 29#include "regcache.h"
4e7b0cd3 30#include "regset.h"
386c036b
MK
31#include "solib-svr4.h"
32#include "symtab.h"
33#include "trad-frame.h"
9ce5c36a 34
386c036b 35#include "gdb_assert.h"
f6ad61e3
MK
36#include "gdb_string.h"
37
c139e7d9 38#include "sparc-tdep.h"
9ce5c36a
JT
39#include "nbsd-tdep.h"
40
386c036b 41const struct sparc_gregset sparc32nbsd_gregset =
9ce5c36a 42{
386c036b
MK
43 0 * 4, /* %psr */
44 1 * 4, /* %pc */
45 2 * 4, /* %npc */
46 3 * 4, /* %y */
47 -1, /* %wim */
48 -1, /* %tbr */
49 5 * 4, /* %g1 */
50 -1 /* %l0 */
51};
9ce5c36a 52
9ce5c36a 53static void
4e7b0cd3
MK
54sparc32nbsd_supply_gregset (const struct regset *regset,
55 struct regcache *regcache,
56 int regnum, const void *gregs, size_t len)
9ce5c36a 57{
4e7b0cd3 58 sparc32_supply_gregset (regset->descr, regcache, regnum, gregs);
c8e737d5
MK
59
60 /* Traditional NetBSD core files don't use multiple register sets.
61 Instead, the general-purpose and floating-point registers are
62 lumped together in a single section. */
63 if (len >= 212)
64 sparc32_supply_fpregset (regcache, regnum, (const char *) gregs + 80);
9ce5c36a
JT
65}
66
4e7b0cd3
MK
67static void
68sparc32nbsd_supply_fpregset (const struct regset *regset,
69 struct regcache *regcache,
70 int regnum, const void *fpregs, size_t len)
9ce5c36a 71{
4e7b0cd3
MK
72 sparc32_supply_fpregset (regcache, regnum, fpregs);
73}
9ce5c36a 74
386c036b
MK
75\f
76/* Signal trampolines. */
77
78/* The following variables describe the location of an on-stack signal
79 trampoline. The current values correspond to the memory layout for
80 NetBSD 1.3 and up. These shouldn't be necessary for NetBSD 2.0 and
81 up, since NetBSD uses signal trampolines provided by libc now. */
9ce5c36a 82
386c036b
MK
83static const CORE_ADDR sparc32nbsd_sigtramp_start = 0xeffffef0;
84static const CORE_ADDR sparc32nbsd_sigtramp_end = 0xeffffff0;
9ce5c36a
JT
85
86static int
386c036b
MK
87sparc32nbsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
88{
89 if (pc >= sparc32nbsd_sigtramp_start && pc < sparc32nbsd_sigtramp_end)
90 return 1;
91
92 return nbsd_pc_in_sigtramp (pc, name);
93}
94
566626fa
MK
95struct trad_frame_saved_reg *
96sparc32nbsd_sigcontext_saved_regs (struct frame_info *next_frame)
9ce5c36a 97{
566626fa 98 struct trad_frame_saved_reg *saved_regs;
386c036b 99 CORE_ADDR addr, sigcontext_addr;
386c036b 100 int regnum, delta;
566626fa 101 ULONGEST psr;
9ce5c36a 102
566626fa 103 saved_regs = trad_frame_alloc_saved_regs (next_frame);
9ce5c36a 104
566626fa
MK
105 /* We find the appropriate instance of `struct sigcontext' at a
106 fixed offset in the signal frame. */
107 addr = frame_unwind_register_unsigned (next_frame, SPARC_FP_REGNUM);
108 sigcontext_addr = addr + 64 + 16;
9ce5c36a 109
386c036b
MK
110 /* The registers are saved in bits and pieces scattered all over the
111 place. The code below records their location on the assumption
112 that the part of the signal trampoline that saves the state has
113 been executed. */
9ce5c36a 114
566626fa
MK
115 saved_regs[SPARC_SP_REGNUM].addr = sigcontext_addr + 8;
116 saved_regs[SPARC32_PC_REGNUM].addr = sigcontext_addr + 12;
117 saved_regs[SPARC32_NPC_REGNUM].addr = sigcontext_addr + 16;
118 saved_regs[SPARC32_PSR_REGNUM].addr = sigcontext_addr + 20;
119 saved_regs[SPARC_G1_REGNUM].addr = sigcontext_addr + 24;
120 saved_regs[SPARC_O0_REGNUM].addr = sigcontext_addr + 28;
386c036b
MK
121
122 /* The remaining `global' registers and %y are saved in the `local'
123 registers. */
124 delta = SPARC_L0_REGNUM - SPARC_G0_REGNUM;
125 for (regnum = SPARC_G2_REGNUM; regnum <= SPARC_G7_REGNUM; regnum++)
566626fa
MK
126 saved_regs[regnum].realreg = regnum + delta;
127 saved_regs[SPARC32_Y_REGNUM].realreg = SPARC_L1_REGNUM;
386c036b
MK
128
129 /* The remaining `out' registers can be found in the current frame's
130 `in' registers. */
131 delta = SPARC_I0_REGNUM - SPARC_O0_REGNUM;
132 for (regnum = SPARC_O1_REGNUM; regnum <= SPARC_O5_REGNUM; regnum++)
566626fa
MK
133 saved_regs[regnum].realreg = regnum + delta;
134 saved_regs[SPARC_O7_REGNUM].realreg = SPARC_I7_REGNUM;
386c036b
MK
135
136 /* The `local' and `in' registers have been saved in the register
137 save area. */
566626fa 138 addr = saved_regs[SPARC_SP_REGNUM].addr;
386c036b
MK
139 addr = get_frame_memory_unsigned (next_frame, addr, 4);
140 for (regnum = SPARC_L0_REGNUM;
141 regnum <= SPARC_I7_REGNUM; regnum++, addr += 4)
566626fa 142 saved_regs[regnum].addr = addr;
386c036b
MK
143
144 /* The floating-point registers are only saved if the EF bit in %prs
145 has been set. */
146
147#define PSR_EF 0x00001000
148
566626fa 149 addr = saved_regs[SPARC32_PSR_REGNUM].addr;
386c036b
MK
150 psr = get_frame_memory_unsigned (next_frame, addr, 4);
151 if (psr & PSR_EF)
152 {
153 CORE_ADDR sp;
154
155 sp = frame_unwind_register_unsigned (next_frame, SPARC_SP_REGNUM);
566626fa 156 saved_regs[SPARC32_FSR_REGNUM].addr = sp + 96;
386c036b
MK
157 for (regnum = SPARC_F0_REGNUM, addr = sp + 96 + 8;
158 regnum <= SPARC_F31_REGNUM; regnum++, addr += 4)
566626fa
MK
159 saved_regs[regnum].addr = addr;
160 }
161
162 return saved_regs;
163}
164
165static struct sparc_frame_cache *
166sparc32nbsd_sigcontext_frame_cache (struct frame_info *next_frame,
167 void **this_cache)
168{
169 struct sparc_frame_cache *cache;
170 CORE_ADDR addr;
171
172 if (*this_cache)
173 return *this_cache;
174
175 cache = sparc_frame_cache (next_frame, this_cache);
176 gdb_assert (cache == *this_cache);
177
178 /* If we couldn't find the frame's function, we're probably dealing
179 with an on-stack signal trampoline. */
180 if (cache->pc == 0)
181 {
182 cache->pc = sparc32nbsd_sigtramp_start;
183
184 /* Since we couldn't find the frame's function, the cache was
185 initialized under the assumption that we're frameless. */
186 cache->frameless_p = 0;
187 addr = frame_unwind_register_unsigned (next_frame, SPARC_FP_REGNUM);
188 cache->base = addr;
386c036b
MK
189 }
190
566626fa
MK
191 cache->saved_regs = sparc32nbsd_sigcontext_saved_regs (next_frame);
192
386c036b 193 return cache;
9ce5c36a
JT
194}
195
386c036b
MK
196static void
197sparc32nbsd_sigcontext_frame_this_id (struct frame_info *next_frame,
198 void **this_cache,
199 struct frame_id *this_id)
200{
201 struct sparc_frame_cache *cache =
202 sparc32nbsd_sigcontext_frame_cache (next_frame, this_cache);
203
204 (*this_id) = frame_id_build (cache->base, cache->pc);
205}
206
207static void
208sparc32nbsd_sigcontext_frame_prev_register (struct frame_info *next_frame,
209 void **this_cache,
210 int regnum, int *optimizedp,
211 enum lval_type *lvalp,
212 CORE_ADDR *addrp,
213 int *realnump, void *valuep)
9ce5c36a 214{
386c036b
MK
215 struct sparc_frame_cache *cache =
216 sparc32nbsd_sigcontext_frame_cache (next_frame, this_cache);
9ce5c36a 217
386c036b
MK
218 trad_frame_prev_register (next_frame, cache->saved_regs, regnum,
219 optimizedp, lvalp, addrp, realnump, valuep);
220}
9ce5c36a 221
386c036b
MK
222static const struct frame_unwind sparc32nbsd_sigcontext_frame_unwind =
223{
224 SIGTRAMP_FRAME,
225 sparc32nbsd_sigcontext_frame_this_id,
226 sparc32nbsd_sigcontext_frame_prev_register
227};
9ce5c36a 228
386c036b
MK
229static const struct frame_unwind *
230sparc32nbsd_sigtramp_frame_sniffer (struct frame_info *next_frame)
231{
232 CORE_ADDR pc = frame_pc_unwind (next_frame);
233 char *name;
9ce5c36a 234
386c036b
MK
235 find_pc_partial_function (pc, &name, NULL, NULL);
236 if (sparc32nbsd_pc_in_sigtramp (pc, name))
237 {
238 if (name == NULL || strncmp (name, "__sigtramp_sigcontext", 21))
239 return &sparc32nbsd_sigcontext_frame_unwind;
240 }
241
242 return NULL;
9ce5c36a 243}
386c036b
MK
244\f
245
246/* Return non-zero if we are in a shared library trampoline code stub. */
9ce5c36a
JT
247
248static int
249sparcnbsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name)
250{
386c036b 251 return (name && !strcmp (name, "_DYNAMIC"));
9ce5c36a
JT
252}
253
254static void
386c036b 255sparc32nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
9ce5c36a 256{
4e7b0cd3
MK
257 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
258
386c036b
MK
259 /* NetBSD doesn't support the 128-bit `long double' from the psABI. */
260 set_gdbarch_long_double_bit (gdbarch, 64);
261 set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_big);
262
4e7b0cd3
MK
263 tdep->gregset = XMALLOC (struct regset);
264 tdep->gregset->descr = &sparc32nbsd_gregset;
265 tdep->gregset->supply_regset = sparc32nbsd_supply_gregset;
c8e737d5 266 tdep->sizeof_gregset = 20 * 4;
4e7b0cd3
MK
267
268 tdep->fpregset = XMALLOC (struct regset);
269 tdep->fpregset->supply_regset = sparc32nbsd_supply_fpregset;
c8e737d5 270 tdep->sizeof_fpregset = 33 * 4;
4e7b0cd3 271
386c036b
MK
272 set_gdbarch_pc_in_sigtramp (gdbarch, sparc32nbsd_pc_in_sigtramp);
273 frame_unwind_append_sniffer (gdbarch, sparc32nbsd_sigtramp_frame_sniffer);
9ce5c36a
JT
274}
275
276static void
386c036b 277sparc32nbsd_aout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
9ce5c36a 278{
386c036b 279 sparc32nbsd_init_abi (info, gdbarch);
9ce5c36a 280
386c036b
MK
281 set_gdbarch_in_solib_call_trampoline
282 (gdbarch, sparcnbsd_aout_in_solib_call_trampoline);
9ce5c36a
JT
283}
284
285static void
386c036b 286sparc32nbsd_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
9ce5c36a 287{
386c036b 288 sparc32nbsd_init_abi (info, gdbarch);
9ce5c36a 289
386c036b
MK
290 set_solib_svr4_fetch_link_map_offsets
291 (gdbarch, nbsd_ilp32_solib_svr4_fetch_link_map_offsets);
9ce5c36a
JT
292}
293
294static enum gdb_osabi
295sparcnbsd_aout_osabi_sniffer (bfd *abfd)
296{
297 if (strcmp (bfd_get_target (abfd), "a.out-sparc-netbsd") == 0)
298 return GDB_OSABI_NETBSD_AOUT;
299
300 return GDB_OSABI_UNKNOWN;
301}
302
7e5e9f88
MK
303/* OpenBSD uses the traditional NetBSD core file format, even for
304 ports that use ELF. Therefore, if the default OS ABI is OpenBSD
305 ELF, we return that instead of NetBSD a.out. This is mainly for
306 the benfit of OpenBSD/sparc64, which inherits the sniffer below
307 since we include this file for an OpenBSD/sparc64 target. For
308 OpenBSD/sparc, the NetBSD a.out OS ABI is probably similar enough
309 to both the OpenBSD a.out and the OpenBSD ELF OS ABI. */
310#if defined (GDB_OSABI_DEFAULT) && (GDB_OSABI_DEFAULT == GDB_OSABI_OPENBSD_ELF)
311#define GDB_OSABI_NETBSD_CORE GDB_OSABI_OPENBSD_ELF
312#else
313#define GDB_OSABI_NETBSD_CORE GDB_OSABI_NETBSD_AOUT
314#endif
315
89aac506
MK
316static enum gdb_osabi
317sparcnbsd_core_osabi_sniffer (bfd *abfd)
318{
319 if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0)
7e5e9f88 320 return GDB_OSABI_NETBSD_CORE;
89aac506
MK
321
322 return GDB_OSABI_UNKNOWN;
323}
324
386c036b
MK
325\f
326/* Provide a prototype to silence -Wmissing-prototypes. */
327void _initialize_sparcnbsd_tdep (void);
328
9ce5c36a
JT
329void
330_initialize_sparnbsd_tdep (void)
331{
332 gdbarch_register_osabi_sniffer (bfd_arch_sparc, bfd_target_aout_flavour,
333 sparcnbsd_aout_osabi_sniffer);
334
89aac506
MK
335 /* BFD doesn't set the architecture for NetBSD style a.out core
336 files. */
337 gdbarch_register_osabi_sniffer (bfd_arch_unknown, bfd_target_unknown_flavour,
338 sparcnbsd_core_osabi_sniffer);
339
05816f70 340 gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_NETBSD_AOUT,
386c036b 341 sparc32nbsd_aout_init_abi);
05816f70 342 gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_NETBSD_ELF,
386c036b 343 sparc32nbsd_elf_init_abi);
9ce5c36a 344}
This page took 0.218806 seconds and 4 git commands to generate.