1 /* Target-dependent code for NetBSD/sparc.
3 Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
4 Contributed by Wasabi Systems, Inc.
6 This file is part of GDB.
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.
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.
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. */
24 #include "floatformat.h"
26 #include "frame-unwind.h"
31 #include "solib-svr4.h"
33 #include "trad-frame.h"
35 #include "gdb_assert.h"
36 #include "gdb_string.h"
38 #include "sparc-tdep.h"
39 #include "nbsd-tdep.h"
41 const struct sparc_gregset sparc32nbsd_gregset
=
54 sparc32nbsd_supply_gregset (const struct regset
*regset
,
55 struct regcache
*regcache
,
56 int regnum
, const void *gregs
, size_t len
)
58 sparc32_supply_gregset (&sparc32nbsd_gregset
, regcache
, regnum
, gregs
);
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. */
64 sparc32_supply_fpregset (regcache
, regnum
, (const char *) gregs
+ 80);
68 sparc32nbsd_supply_fpregset (const struct regset
*regset
,
69 struct regcache
*regcache
,
70 int regnum
, const void *fpregs
, size_t len
)
72 sparc32_supply_fpregset (regcache
, regnum
, fpregs
);
76 /* Signal trampolines. */
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. */
83 static const CORE_ADDR sparc32nbsd_sigtramp_start
= 0xeffffef0;
84 static const CORE_ADDR sparc32nbsd_sigtramp_end
= 0xeffffff0;
87 sparc32nbsd_pc_in_sigtramp (CORE_ADDR pc
, char *name
)
89 if (pc
>= sparc32nbsd_sigtramp_start
&& pc
< sparc32nbsd_sigtramp_end
)
92 return nbsd_pc_in_sigtramp (pc
, name
);
95 struct trad_frame_saved_reg
*
96 sparc32nbsd_sigcontext_saved_regs (struct frame_info
*next_frame
)
98 struct trad_frame_saved_reg
*saved_regs
;
99 CORE_ADDR addr
, sigcontext_addr
;
103 saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
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;
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
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;
122 /* The remaining `global' registers and %y are saved in the `local'
124 delta
= SPARC_L0_REGNUM
- SPARC_G0_REGNUM
;
125 for (regnum
= SPARC_G2_REGNUM
; regnum
<= SPARC_G7_REGNUM
; regnum
++)
126 saved_regs
[regnum
].realreg
= regnum
+ delta
;
127 saved_regs
[SPARC32_Y_REGNUM
].realreg
= SPARC_L1_REGNUM
;
129 /* The remaining `out' registers can be found in the current frame's
131 delta
= SPARC_I0_REGNUM
- SPARC_O0_REGNUM
;
132 for (regnum
= SPARC_O1_REGNUM
; regnum
<= SPARC_O5_REGNUM
; regnum
++)
133 saved_regs
[regnum
].realreg
= regnum
+ delta
;
134 saved_regs
[SPARC_O7_REGNUM
].realreg
= SPARC_I7_REGNUM
;
136 /* The `local' and `in' registers have been saved in the register
138 addr
= saved_regs
[SPARC_SP_REGNUM
].addr
;
139 addr
= get_frame_memory_unsigned (next_frame
, addr
, 4);
140 for (regnum
= SPARC_L0_REGNUM
;
141 regnum
<= SPARC_I7_REGNUM
; regnum
++, addr
+= 4)
142 saved_regs
[regnum
].addr
= addr
;
144 /* Handle StackGhost. */
146 ULONGEST wcookie
= sparc_fetch_wcookie ();
152 addr
= saved_regs
[SPARC_I7_REGNUM
].addr
;
153 i7
= get_frame_memory_unsigned (next_frame
, addr
, 4);
154 trad_frame_set_value (saved_regs
, SPARC_I7_REGNUM
, i7
^ wcookie
);
158 /* The floating-point registers are only saved if the EF bit in %prs
161 #define PSR_EF 0x00001000
163 addr
= saved_regs
[SPARC32_PSR_REGNUM
].addr
;
164 psr
= get_frame_memory_unsigned (next_frame
, addr
, 4);
169 sp
= frame_unwind_register_unsigned (next_frame
, SPARC_SP_REGNUM
);
170 saved_regs
[SPARC32_FSR_REGNUM
].addr
= sp
+ 96;
171 for (regnum
= SPARC_F0_REGNUM
, addr
= sp
+ 96 + 8;
172 regnum
<= SPARC_F31_REGNUM
; regnum
++, addr
+= 4)
173 saved_regs
[regnum
].addr
= addr
;
179 static struct sparc_frame_cache
*
180 sparc32nbsd_sigcontext_frame_cache (struct frame_info
*next_frame
,
183 struct sparc_frame_cache
*cache
;
189 cache
= sparc_frame_cache (next_frame
, this_cache
);
190 gdb_assert (cache
== *this_cache
);
192 /* If we couldn't find the frame's function, we're probably dealing
193 with an on-stack signal trampoline. */
196 cache
->pc
= sparc32nbsd_sigtramp_start
;
198 /* Since we couldn't find the frame's function, the cache was
199 initialized under the assumption that we're frameless. */
200 cache
->frameless_p
= 0;
201 addr
= frame_unwind_register_unsigned (next_frame
, SPARC_FP_REGNUM
);
205 cache
->saved_regs
= sparc32nbsd_sigcontext_saved_regs (next_frame
);
211 sparc32nbsd_sigcontext_frame_this_id (struct frame_info
*next_frame
,
213 struct frame_id
*this_id
)
215 struct sparc_frame_cache
*cache
=
216 sparc32nbsd_sigcontext_frame_cache (next_frame
, this_cache
);
218 (*this_id
) = frame_id_build (cache
->base
, cache
->pc
);
222 sparc32nbsd_sigcontext_frame_prev_register (struct frame_info
*next_frame
,
224 int regnum
, int *optimizedp
,
225 enum lval_type
*lvalp
,
227 int *realnump
, void *valuep
)
229 struct sparc_frame_cache
*cache
=
230 sparc32nbsd_sigcontext_frame_cache (next_frame
, this_cache
);
232 trad_frame_get_prev_register (next_frame
, cache
->saved_regs
, regnum
,
233 optimizedp
, lvalp
, addrp
, realnump
, valuep
);
236 static const struct frame_unwind sparc32nbsd_sigcontext_frame_unwind
=
239 sparc32nbsd_sigcontext_frame_this_id
,
240 sparc32nbsd_sigcontext_frame_prev_register
243 static const struct frame_unwind
*
244 sparc32nbsd_sigtramp_frame_sniffer (struct frame_info
*next_frame
)
246 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
249 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
250 if (sparc32nbsd_pc_in_sigtramp (pc
, name
))
252 if (name
== NULL
|| strncmp (name
, "__sigtramp_sigcontext", 21))
253 return &sparc32nbsd_sigcontext_frame_unwind
;
261 sparc32nbsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
263 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
265 /* NetBSD doesn't support the 128-bit `long double' from the psABI. */
266 set_gdbarch_long_double_bit (gdbarch
, 64);
267 set_gdbarch_long_double_format (gdbarch
, &floatformat_ieee_double_big
);
269 tdep
->gregset
= regset_alloc (gdbarch
, sparc32nbsd_supply_gregset
, NULL
);
270 tdep
->sizeof_gregset
= 20 * 4;
272 tdep
->fpregset
= regset_alloc (gdbarch
, sparc32nbsd_supply_fpregset
, NULL
);
273 tdep
->sizeof_fpregset
= 33 * 4;
275 frame_unwind_append_sniffer (gdbarch
, sparc32nbsd_sigtramp_frame_sniffer
);
279 sparc32nbsd_aout_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
281 sparc32nbsd_init_abi (info
, gdbarch
);
285 sparc32nbsd_elf_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
287 sparc32nbsd_init_abi (info
, gdbarch
);
289 set_solib_svr4_fetch_link_map_offsets
290 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
293 static enum gdb_osabi
294 sparcnbsd_aout_osabi_sniffer (bfd
*abfd
)
296 if (strcmp (bfd_get_target (abfd
), "a.out-sparc-netbsd") == 0)
297 return GDB_OSABI_NETBSD_AOUT
;
299 return GDB_OSABI_UNKNOWN
;
302 /* OpenBSD uses the traditional NetBSD core file format, even for
303 ports that use ELF. Therefore, if the default OS ABI is OpenBSD
304 ELF, we return that instead of NetBSD a.out. This is mainly for
305 the benfit of OpenBSD/sparc64, which inherits the sniffer below
306 since we include this file for an OpenBSD/sparc64 target. For
307 OpenBSD/sparc, the NetBSD a.out OS ABI is probably similar enough
308 to both the OpenBSD a.out and the OpenBSD ELF OS ABI. */
309 #if defined (GDB_OSABI_DEFAULT) && (GDB_OSABI_DEFAULT == GDB_OSABI_OPENBSD_ELF)
310 #define GDB_OSABI_NETBSD_CORE GDB_OSABI_OPENBSD_ELF
312 #define GDB_OSABI_NETBSD_CORE GDB_OSABI_NETBSD_AOUT
315 static enum gdb_osabi
316 sparcnbsd_core_osabi_sniffer (bfd
*abfd
)
318 if (strcmp (bfd_get_target (abfd
), "netbsd-core") == 0)
319 return GDB_OSABI_NETBSD_CORE
;
321 return GDB_OSABI_UNKNOWN
;
325 /* Provide a prototype to silence -Wmissing-prototypes. */
326 void _initialize_sparcnbsd_tdep (void);
329 _initialize_sparnbsd_tdep (void)
331 gdbarch_register_osabi_sniffer (bfd_arch_sparc
, bfd_target_aout_flavour
,
332 sparcnbsd_aout_osabi_sniffer
);
334 /* BFD doesn't set a flavour for NetBSD style a.out core files. */
335 gdbarch_register_osabi_sniffer (bfd_arch_sparc
, bfd_target_unknown_flavour
,
336 sparcnbsd_core_osabi_sniffer
);
338 gdbarch_register_osabi (bfd_arch_sparc
, 0, GDB_OSABI_NETBSD_AOUT
,
339 sparc32nbsd_aout_init_abi
);
340 gdbarch_register_osabi (bfd_arch_sparc
, 0, GDB_OSABI_NETBSD_ELF
,
341 sparc32nbsd_elf_init_abi
);