2012-02-02 Pedro Alves <palves@redhat.com>
[deliverable/binutils-gdb.git] / gdb / sparc64nbsd-tdep.c
CommitLineData
386c036b
MK
1/* Target-dependent code for NetBSD/sparc64.
2
0b302171 3 Copyright (C) 2002-2012 Free Software Foundation, Inc.
386c036b
MK
4 Based on code 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
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
386c036b
MK
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
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
386c036b
MK
20
21#include "defs.h"
22#include "frame.h"
23#include "frame-unwind.h"
24#include "gdbcore.h"
25#include "osabi.h"
26#include "regcache.h"
2ca62865 27#include "regset.h"
386c036b 28#include "symtab.h"
3510d1f2 29#include "objfiles.h"
386c036b
MK
30#include "solib-svr4.h"
31#include "trad-frame.h"
32
33#include "gdb_assert.h"
34#include "gdb_string.h"
35
36#include "sparc64-tdep.h"
37#include "nbsd-tdep.h"
38
39/* From <machine/reg.h>. */
40const struct sparc_gregset sparc64nbsd_gregset =
41{
42 0 * 8, /* "tstate" */
43 1 * 8, /* %pc */
44 2 * 8, /* %npc */
45 3 * 8, /* %y */
46 -1, /* %fprs */
47 -1,
48 5 * 8, /* %g1 */
49 -1, /* %l0 */
50 4 /* sizeof (%y) */
51};
2ca62865 52\f
386c036b
MK
53
54static void
2ca62865
MK
55sparc64nbsd_supply_gregset (const struct regset *regset,
56 struct regcache *regcache,
57 int regnum, const void *gregs, size_t len)
386c036b 58{
9ea75c57 59 sparc64_supply_gregset (&sparc64nbsd_gregset, regcache, regnum, gregs);
386c036b
MK
60}
61
2ca62865
MK
62static void
63sparc64nbsd_supply_fpregset (const struct regset *regset,
64 struct regcache *regcache,
65 int regnum, const void *fpregs, size_t len)
386c036b 66{
2ca62865
MK
67 sparc64_supply_fpregset (regcache, regnum, fpregs);
68}
386c036b 69\f
2ca62865 70
386c036b
MK
71/* Signal trampolines. */
72
73/* The following variables describe the location of an on-stack signal
74 trampoline. The current values correspond to the memory layout for
75 NetBSD 1.3 and up. These shouldn't be necessary for NetBSD 2.0 and
76 up, since NetBSD uses signal trampolines provided by libc now. */
77
78static const CORE_ADDR sparc64nbsd_sigtramp_start = 0xffffffffffffdee4ULL;
79static const CORE_ADDR sparc64nbsd_sigtramp_end = 0xffffffffffffe000ULL;
80
81static int
82sparc64nbsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
83{
84 if (pc >= sparc64nbsd_sigtramp_start && pc < sparc64nbsd_sigtramp_end)
85 return 1;
86
87 return nbsd_pc_in_sigtramp (pc, name);
88}
89
1e067c66
MK
90struct trad_frame_saved_reg *
91sparc64nbsd_sigcontext_saved_regs (CORE_ADDR sigcontext_addr,
94afd7a6 92 struct frame_info *this_frame)
386c036b 93{
e17a4113 94 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1e067c66
MK
95 struct trad_frame_saved_reg *saved_regs;
96 CORE_ADDR addr, sp;
386c036b
MK
97 int regnum, delta;
98
94afd7a6 99 saved_regs = trad_frame_alloc_saved_regs (this_frame);
386c036b
MK
100
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
104 been executed. */
105
1e067c66
MK
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;
386c036b
MK
112
113 /* The remaining `global' registers and %y are saved in the `local'
114 registers. */
115 delta = SPARC_L0_REGNUM - SPARC_G0_REGNUM;
116 for (regnum = SPARC_G2_REGNUM; regnum <= SPARC_G7_REGNUM; regnum++)
1e067c66
MK
117 saved_regs[regnum].realreg = regnum + delta;
118 saved_regs[SPARC64_Y_REGNUM].realreg = SPARC_L1_REGNUM;
386c036b
MK
119
120 /* The remaining `out' registers can be found in the current frame's
121 `in' registers. */
122 delta = SPARC_I0_REGNUM - SPARC_O0_REGNUM;
123 for (regnum = SPARC_O1_REGNUM; regnum <= SPARC_O5_REGNUM; regnum++)
1e067c66
MK
124 saved_regs[regnum].realreg = regnum + delta;
125 saved_regs[SPARC_O7_REGNUM].realreg = SPARC_I7_REGNUM;
386c036b
MK
126
127 /* The `local' and `in' registers have been saved in the register
128 save area. */
1e067c66 129 addr = saved_regs[SPARC_SP_REGNUM].addr;
94afd7a6 130 sp = get_frame_memory_unsigned (this_frame, addr, 8);
386c036b
MK
131 for (regnum = SPARC_L0_REGNUM, addr = sp + BIAS;
132 regnum <= SPARC_I7_REGNUM; regnum++, addr += 8)
1e067c66 133 saved_regs[regnum].addr = addr;
386c036b 134
8391b9b1
MK
135 /* Handle StackGhost. */
136 {
e17a4113 137 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);
8391b9b1
MK
138
139 if (wcookie != 0)
140 {
141 ULONGEST i7;
142
143 addr = saved_regs[SPARC_I7_REGNUM].addr;
94afd7a6 144 i7 = get_frame_memory_unsigned (this_frame, addr, 8);
8391b9b1
MK
145 trad_frame_set_value (saved_regs, SPARC_I7_REGNUM, i7 ^ wcookie);
146 }
147 }
148
386c036b
MK
149 /* TODO: Handle the floating-point registers. */
150
1e067c66
MK
151 return saved_regs;
152}
153
154static struct sparc_frame_cache *
94afd7a6 155sparc64nbsd_sigcontext_frame_cache (struct frame_info *this_frame,
1e067c66
MK
156 void **this_cache)
157{
158 struct sparc_frame_cache *cache;
159 CORE_ADDR addr;
160
161 if (*this_cache)
162 return *this_cache;
163
94afd7a6 164 cache = sparc_frame_cache (this_frame, this_cache);
1e067c66
MK
165 gdb_assert (cache == *this_cache);
166
167 /* If we couldn't find the frame's function, we're probably dealing
168 with an on-stack signal trampoline. */
169 if (cache->pc == 0)
170 {
171 cache->pc = sparc64nbsd_sigtramp_start;
172
173 /* Since we couldn't find the frame's function, the cache was
174 initialized under the assumption that we're frameless. */
369c397b 175 sparc_record_save_insn (cache);
94afd7a6 176 addr = get_frame_register_unsigned (this_frame, SPARC_FP_REGNUM);
5b2d44a0
MK
177 if (addr & 1)
178 addr += BIAS;
1e067c66
MK
179 cache->base = addr;
180 }
181
182 /* We find the appropriate instance of `struct sigcontext' at a
183 fixed offset in the signal frame. */
5b2d44a0 184 addr = cache->base + 128 + 8;
94afd7a6 185 cache->saved_regs = sparc64nbsd_sigcontext_saved_regs (addr, this_frame);
1e067c66 186
386c036b
MK
187 return cache;
188}
189
190static void
94afd7a6 191sparc64nbsd_sigcontext_frame_this_id (struct frame_info *this_frame,
386c036b
MK
192 void **this_cache,
193 struct frame_id *this_id)
194{
195 struct sparc_frame_cache *cache =
94afd7a6 196 sparc64nbsd_sigcontext_frame_cache (this_frame, this_cache);
386c036b
MK
197
198 (*this_id) = frame_id_build (cache->base, cache->pc);
199}
200
94afd7a6
UW
201static struct value *
202sparc64nbsd_sigcontext_frame_prev_register (struct frame_info *this_frame,
203 void **this_cache, int regnum)
386c036b
MK
204{
205 struct sparc_frame_cache *cache =
94afd7a6 206 sparc64nbsd_sigcontext_frame_cache (this_frame, this_cache);
386c036b 207
94afd7a6 208 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
386c036b
MK
209}
210
94afd7a6
UW
211static int
212sparc64nbsd_sigtramp_frame_sniffer (const struct frame_unwind *self,
213 struct frame_info *this_frame,
214 void **this_cache)
386c036b 215{
94afd7a6 216 CORE_ADDR pc = get_frame_pc (this_frame);
386c036b
MK
217 char *name;
218
219 find_pc_partial_function (pc, &name, NULL, NULL);
220 if (sparc64nbsd_pc_in_sigtramp (pc, name))
221 {
222 if (name == NULL || strncmp (name, "__sigtramp_sigcontext", 21))
94afd7a6 223 return 1;
386c036b
MK
224 }
225
94afd7a6 226 return 0;
386c036b 227}
94afd7a6
UW
228
229static const struct frame_unwind sparc64nbsd_sigcontext_frame_unwind =
230{
231 SIGTRAMP_FRAME,
8fbca658 232 default_frame_unwind_stop_reason,
94afd7a6
UW
233 sparc64nbsd_sigcontext_frame_this_id,
234 sparc64nbsd_sigcontext_frame_prev_register,
235 NULL,
236 sparc64nbsd_sigtramp_frame_sniffer
237};
386c036b
MK
238\f
239
240static void
241sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
242{
2ca62865
MK
243 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
244
9ea75c57 245 tdep->gregset = regset_alloc (gdbarch, sparc64nbsd_supply_gregset, NULL);
2ca62865
MK
246 tdep->sizeof_gregset = 160;
247
9ea75c57 248 tdep->fpregset = regset_alloc (gdbarch, sparc64nbsd_supply_fpregset, NULL);
2ca62865
MK
249 tdep->sizeof_fpregset = 272;
250
c893be75
MK
251 /* Make sure we can single-step "new" syscalls. */
252 tdep->step_trap = sparcnbsd_step_trap;
253
94afd7a6 254 frame_unwind_append_unwinder (gdbarch, &sparc64nbsd_sigcontext_frame_unwind);
386c036b
MK
255
256 sparc64_init_abi (info, gdbarch);
257
5b2d44a0 258 /* NetBSD/sparc64 has SVR4-style shared libraries. */
3510d1f2 259 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
386c036b 260 set_solib_svr4_fetch_link_map_offsets
3510d1f2 261 (gdbarch, svr4_lp64_fetch_link_map_offsets);
386c036b 262}
386c036b 263\f
5b2d44a0 264
386c036b
MK
265/* Provide a prototype to silence -Wmissing-prototypes. */
266void _initialize_sparc64nbsd_tdep (void);
267
268void
269_initialize_sparc64nbsd_tdep (void)
270{
271 gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
272 GDB_OSABI_NETBSD_ELF, sparc64nbsd_init_abi);
386c036b 273}
This page took 0.777159 seconds and 4 git commands to generate.