1 /* Target-dependent code for NetBSD/sparc64.
3 Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
4 Based on code 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. */
25 #include "frame-unwind.h"
31 #include "solib-svr4.h"
32 #include "trad-frame.h"
34 #include "gdb_assert.h"
35 #include "gdb_string.h"
37 #include "sparc64-tdep.h"
38 #include "nbsd-tdep.h"
40 /* From <machine/reg.h>. */
41 const struct sparc_gregset sparc64nbsd_gregset =
56 sparc64nbsd_supply_gregset (const struct regset *regset,
57 struct regcache *regcache,
58 int regnum, const void *gregs, size_t len)
60 sparc64_supply_gregset (&sparc64nbsd_gregset, regcache, regnum, gregs);
64 sparc64nbsd_supply_fpregset (const struct regset *regset,
65 struct regcache *regcache,
66 int regnum, const void *fpregs, size_t len)
68 sparc64_supply_fpregset (regcache, regnum, fpregs);
72 /* Signal trampolines. */
74 /* The following variables describe the location of an on-stack signal
75 trampoline. The current values correspond to the memory layout for
76 NetBSD 1.3 and up. These shouldn't be necessary for NetBSD 2.0 and
77 up, since NetBSD uses signal trampolines provided by libc now. */
79 static const CORE_ADDR sparc64nbsd_sigtramp_start = 0xffffffffffffdee4ULL;
80 static const CORE_ADDR sparc64nbsd_sigtramp_end = 0xffffffffffffe000ULL;
83 sparc64nbsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
85 if (pc >= sparc64nbsd_sigtramp_start && pc < sparc64nbsd_sigtramp_end)
88 return nbsd_pc_in_sigtramp (pc, name);
91 struct trad_frame_saved_reg *
92 sparc64nbsd_sigcontext_saved_regs (CORE_ADDR sigcontext_addr,
93 struct frame_info *next_frame)
95 struct trad_frame_saved_reg *saved_regs;
99 saved_regs = trad_frame_alloc_saved_regs (next_frame);
101 /* The registers are saved in bits and pieces scattered all over the
102 place. The code below records their location on the assumption
103 that the part of the signal trampoline that saves the state has
106 saved_regs[SPARC_SP_REGNUM].addr = sigcontext_addr + 8;
107 saved_regs[SPARC64_PC_REGNUM].addr = sigcontext_addr + 16;
108 saved_regs[SPARC64_NPC_REGNUM].addr = sigcontext_addr + 24;
109 saved_regs[SPARC64_STATE_REGNUM].addr = sigcontext_addr + 32;
110 saved_regs[SPARC_G1_REGNUM].addr = sigcontext_addr + 40;
111 saved_regs[SPARC_O0_REGNUM].addr = sigcontext_addr + 48;
113 /* The remaining `global' registers and %y are saved in the `local'
115 delta = SPARC_L0_REGNUM - SPARC_G0_REGNUM;
116 for (regnum = SPARC_G2_REGNUM; regnum <= SPARC_G7_REGNUM; regnum++)
117 saved_regs[regnum].realreg = regnum + delta;
118 saved_regs[SPARC64_Y_REGNUM].realreg = SPARC_L1_REGNUM;
120 /* The remaining `out' registers can be found in the current frame's
122 delta = SPARC_I0_REGNUM - SPARC_O0_REGNUM;
123 for (regnum = SPARC_O1_REGNUM; regnum <= SPARC_O5_REGNUM; regnum++)
124 saved_regs[regnum].realreg = regnum + delta;
125 saved_regs[SPARC_O7_REGNUM].realreg = SPARC_I7_REGNUM;
127 /* The `local' and `in' registers have been saved in the register
129 addr = saved_regs[SPARC_SP_REGNUM].addr;
130 sp = get_frame_memory_unsigned (next_frame, addr, 8);
131 for (regnum = SPARC_L0_REGNUM, addr = sp + BIAS;
132 regnum <= SPARC_I7_REGNUM; regnum++, addr += 8)
133 saved_regs[regnum].addr = addr;
135 /* TODO: Handle the floating-point registers. */
140 static struct sparc_frame_cache *
141 sparc64nbsd_sigcontext_frame_cache (struct frame_info *next_frame,
144 struct sparc_frame_cache *cache;
150 cache = sparc_frame_cache (next_frame, this_cache);
151 gdb_assert (cache == *this_cache);
153 /* If we couldn't find the frame's function, we're probably dealing
154 with an on-stack signal trampoline. */
157 cache->pc = sparc64nbsd_sigtramp_start;
159 /* Since we couldn't find the frame's function, the cache was
160 initialized under the assumption that we're frameless. */
161 cache->frameless_p = 0;
162 addr = frame_unwind_register_unsigned (next_frame, SPARC_FP_REGNUM);
166 /* We find the appropriate instance of `struct sigcontext' at a
167 fixed offset in the signal frame. */
168 addr = cache->base + BIAS + 128 + 8;
169 cache->saved_regs = sparc64nbsd_sigcontext_saved_regs (addr, next_frame);
175 sparc64nbsd_sigcontext_frame_this_id (struct frame_info *next_frame,
177 struct frame_id *this_id)
179 struct sparc_frame_cache *cache =
180 sparc64nbsd_sigcontext_frame_cache (next_frame, this_cache);
182 (*this_id) = frame_id_build (cache->base, cache->pc);
186 sparc64nbsd_sigcontext_frame_prev_register (struct frame_info *next_frame,
188 int regnum, int *optimizedp,
189 enum lval_type *lvalp,
191 int *realnump, void *valuep)
193 struct sparc_frame_cache *cache =
194 sparc64nbsd_sigcontext_frame_cache (next_frame, this_cache);
196 trad_frame_prev_register (next_frame, cache->saved_regs, regnum,
197 optimizedp, lvalp, addrp, realnump, valuep);
200 static const struct frame_unwind sparc64nbsd_sigcontext_frame_unwind =
203 sparc64nbsd_sigcontext_frame_this_id,
204 sparc64nbsd_sigcontext_frame_prev_register
207 static const struct frame_unwind *
208 sparc64nbsd_sigtramp_frame_sniffer (struct frame_info *next_frame)
210 CORE_ADDR pc = frame_pc_unwind (next_frame);
213 find_pc_partial_function (pc, &name, NULL, NULL);
214 if (sparc64nbsd_pc_in_sigtramp (pc, name))
216 if (name == NULL || strncmp (name, "__sigtramp_sigcontext", 21))
217 return &sparc64nbsd_sigcontext_frame_unwind;
225 sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
227 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
229 tdep->gregset = regset_alloc (gdbarch, sparc64nbsd_supply_gregset, NULL);
230 tdep->sizeof_gregset = 160;
232 tdep->fpregset = regset_alloc (gdbarch, sparc64nbsd_supply_fpregset, NULL);
233 tdep->sizeof_fpregset = 272;
235 frame_unwind_append_sniffer (gdbarch, sparc64nbsd_sigtramp_frame_sniffer);
237 sparc64_init_abi (info, gdbarch);
239 set_solib_svr4_fetch_link_map_offsets
240 (gdbarch, nbsd_lp64_solib_svr4_fetch_link_map_offsets);
244 /* Provide a prototype to silence -Wmissing-prototypes. */
245 void _initialize_sparc64nbsd_tdep (void);
248 _initialize_sparc64nbsd_tdep (void)
250 gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
251 GDB_OSABI_NETBSD_ELF, sparc64nbsd_init_abi);