]>
Commit | Line | Data |
---|---|---|
386c036b MK |
1 | /* Target-dependent code for NetBSD/sparc64. |
2 | ||
3 | Copyright 2002, 2003, 2004 Free Software Foundation, Inc. | |
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 | |
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" | |
24 | #include "frame.h" | |
25 | #include "frame-unwind.h" | |
26 | #include "gdbcore.h" | |
27 | #include "osabi.h" | |
28 | #include "regcache.h" | |
2ca62865 | 29 | #include "regset.h" |
386c036b | 30 | #include "symtab.h" |
3510d1f2 | 31 | #include "objfiles.h" |
386c036b MK |
32 | #include "solib-svr4.h" |
33 | #include "trad-frame.h" | |
34 | ||
35 | #include "gdb_assert.h" | |
36 | #include "gdb_string.h" | |
37 | ||
38 | #include "sparc64-tdep.h" | |
39 | #include "nbsd-tdep.h" | |
40 | ||
41 | /* From <machine/reg.h>. */ | |
42 | const struct sparc_gregset sparc64nbsd_gregset = | |
43 | { | |
44 | 0 * 8, /* "tstate" */ | |
45 | 1 * 8, /* %pc */ | |
46 | 2 * 8, /* %npc */ | |
47 | 3 * 8, /* %y */ | |
48 | -1, /* %fprs */ | |
49 | -1, | |
50 | 5 * 8, /* %g1 */ | |
51 | -1, /* %l0 */ | |
52 | 4 /* sizeof (%y) */ | |
53 | }; | |
2ca62865 | 54 | \f |
386c036b MK |
55 | |
56 | static void | |
2ca62865 MK |
57 | sparc64nbsd_supply_gregset (const struct regset *regset, |
58 | struct regcache *regcache, | |
59 | int regnum, const void *gregs, size_t len) | |
386c036b | 60 | { |
9ea75c57 | 61 | sparc64_supply_gregset (&sparc64nbsd_gregset, regcache, regnum, gregs); |
386c036b MK |
62 | } |
63 | ||
2ca62865 MK |
64 | static void |
65 | sparc64nbsd_supply_fpregset (const struct regset *regset, | |
66 | struct regcache *regcache, | |
67 | int regnum, const void *fpregs, size_t len) | |
386c036b | 68 | { |
2ca62865 MK |
69 | sparc64_supply_fpregset (regcache, regnum, fpregs); |
70 | } | |
386c036b | 71 | \f |
2ca62865 | 72 | |
386c036b MK |
73 | /* Signal trampolines. */ |
74 | ||
75 | /* The following variables describe the location of an on-stack signal | |
76 | trampoline. The current values correspond to the memory layout for | |
77 | NetBSD 1.3 and up. These shouldn't be necessary for NetBSD 2.0 and | |
78 | up, since NetBSD uses signal trampolines provided by libc now. */ | |
79 | ||
80 | static const CORE_ADDR sparc64nbsd_sigtramp_start = 0xffffffffffffdee4ULL; | |
81 | static const CORE_ADDR sparc64nbsd_sigtramp_end = 0xffffffffffffe000ULL; | |
82 | ||
83 | static int | |
84 | sparc64nbsd_pc_in_sigtramp (CORE_ADDR pc, char *name) | |
85 | { | |
86 | if (pc >= sparc64nbsd_sigtramp_start && pc < sparc64nbsd_sigtramp_end) | |
87 | return 1; | |
88 | ||
89 | return nbsd_pc_in_sigtramp (pc, name); | |
90 | } | |
91 | ||
1e067c66 MK |
92 | struct trad_frame_saved_reg * |
93 | sparc64nbsd_sigcontext_saved_regs (CORE_ADDR sigcontext_addr, | |
94 | struct frame_info *next_frame) | |
386c036b | 95 | { |
1e067c66 MK |
96 | struct trad_frame_saved_reg *saved_regs; |
97 | CORE_ADDR addr, sp; | |
386c036b MK |
98 | int regnum, delta; |
99 | ||
1e067c66 | 100 | saved_regs = trad_frame_alloc_saved_regs (next_frame); |
386c036b MK |
101 | |
102 | /* The registers are saved in bits and pieces scattered all over the | |
103 | place. The code below records their location on the assumption | |
104 | that the part of the signal trampoline that saves the state has | |
105 | been executed. */ | |
106 | ||
1e067c66 MK |
107 | saved_regs[SPARC_SP_REGNUM].addr = sigcontext_addr + 8; |
108 | saved_regs[SPARC64_PC_REGNUM].addr = sigcontext_addr + 16; | |
109 | saved_regs[SPARC64_NPC_REGNUM].addr = sigcontext_addr + 24; | |
110 | saved_regs[SPARC64_STATE_REGNUM].addr = sigcontext_addr + 32; | |
111 | saved_regs[SPARC_G1_REGNUM].addr = sigcontext_addr + 40; | |
112 | saved_regs[SPARC_O0_REGNUM].addr = sigcontext_addr + 48; | |
386c036b MK |
113 | |
114 | /* The remaining `global' registers and %y are saved in the `local' | |
115 | registers. */ | |
116 | delta = SPARC_L0_REGNUM - SPARC_G0_REGNUM; | |
117 | for (regnum = SPARC_G2_REGNUM; regnum <= SPARC_G7_REGNUM; regnum++) | |
1e067c66 MK |
118 | saved_regs[regnum].realreg = regnum + delta; |
119 | saved_regs[SPARC64_Y_REGNUM].realreg = SPARC_L1_REGNUM; | |
386c036b MK |
120 | |
121 | /* The remaining `out' registers can be found in the current frame's | |
122 | `in' registers. */ | |
123 | delta = SPARC_I0_REGNUM - SPARC_O0_REGNUM; | |
124 | for (regnum = SPARC_O1_REGNUM; regnum <= SPARC_O5_REGNUM; regnum++) | |
1e067c66 MK |
125 | saved_regs[regnum].realreg = regnum + delta; |
126 | saved_regs[SPARC_O7_REGNUM].realreg = SPARC_I7_REGNUM; | |
386c036b MK |
127 | |
128 | /* The `local' and `in' registers have been saved in the register | |
129 | save area. */ | |
1e067c66 | 130 | addr = saved_regs[SPARC_SP_REGNUM].addr; |
386c036b MK |
131 | sp = get_frame_memory_unsigned (next_frame, addr, 8); |
132 | for (regnum = SPARC_L0_REGNUM, addr = sp + BIAS; | |
133 | regnum <= SPARC_I7_REGNUM; regnum++, addr += 8) | |
1e067c66 | 134 | saved_regs[regnum].addr = addr; |
386c036b MK |
135 | |
136 | /* TODO: Handle the floating-point registers. */ | |
137 | ||
1e067c66 MK |
138 | return saved_regs; |
139 | } | |
140 | ||
141 | static struct sparc_frame_cache * | |
142 | sparc64nbsd_sigcontext_frame_cache (struct frame_info *next_frame, | |
143 | void **this_cache) | |
144 | { | |
145 | struct sparc_frame_cache *cache; | |
146 | CORE_ADDR addr; | |
147 | ||
148 | if (*this_cache) | |
149 | return *this_cache; | |
150 | ||
151 | cache = sparc_frame_cache (next_frame, this_cache); | |
152 | gdb_assert (cache == *this_cache); | |
153 | ||
154 | /* If we couldn't find the frame's function, we're probably dealing | |
155 | with an on-stack signal trampoline. */ | |
156 | if (cache->pc == 0) | |
157 | { | |
158 | cache->pc = sparc64nbsd_sigtramp_start; | |
159 | ||
160 | /* Since we couldn't find the frame's function, the cache was | |
161 | initialized under the assumption that we're frameless. */ | |
162 | cache->frameless_p = 0; | |
163 | addr = frame_unwind_register_unsigned (next_frame, SPARC_FP_REGNUM); | |
164 | cache->base = addr; | |
165 | } | |
166 | ||
167 | /* We find the appropriate instance of `struct sigcontext' at a | |
168 | fixed offset in the signal frame. */ | |
169 | addr = cache->base + BIAS + 128 + 8; | |
170 | cache->saved_regs = sparc64nbsd_sigcontext_saved_regs (addr, next_frame); | |
171 | ||
386c036b MK |
172 | return cache; |
173 | } | |
174 | ||
175 | static void | |
176 | sparc64nbsd_sigcontext_frame_this_id (struct frame_info *next_frame, | |
177 | void **this_cache, | |
178 | struct frame_id *this_id) | |
179 | { | |
180 | struct sparc_frame_cache *cache = | |
181 | sparc64nbsd_sigcontext_frame_cache (next_frame, this_cache); | |
182 | ||
183 | (*this_id) = frame_id_build (cache->base, cache->pc); | |
184 | } | |
185 | ||
186 | static void | |
187 | sparc64nbsd_sigcontext_frame_prev_register (struct frame_info *next_frame, | |
188 | void **this_cache, | |
189 | int regnum, int *optimizedp, | |
190 | enum lval_type *lvalp, | |
191 | CORE_ADDR *addrp, | |
192 | int *realnump, void *valuep) | |
193 | { | |
194 | struct sparc_frame_cache *cache = | |
195 | sparc64nbsd_sigcontext_frame_cache (next_frame, this_cache); | |
196 | ||
1f67027d AC |
197 | trad_frame_get_prev_register (next_frame, cache->saved_regs, regnum, |
198 | optimizedp, lvalp, addrp, realnump, valuep); | |
386c036b MK |
199 | } |
200 | ||
201 | static const struct frame_unwind sparc64nbsd_sigcontext_frame_unwind = | |
202 | { | |
203 | SIGTRAMP_FRAME, | |
204 | sparc64nbsd_sigcontext_frame_this_id, | |
205 | sparc64nbsd_sigcontext_frame_prev_register | |
206 | }; | |
207 | ||
208 | static const struct frame_unwind * | |
209 | sparc64nbsd_sigtramp_frame_sniffer (struct frame_info *next_frame) | |
210 | { | |
211 | CORE_ADDR pc = frame_pc_unwind (next_frame); | |
212 | char *name; | |
213 | ||
214 | find_pc_partial_function (pc, &name, NULL, NULL); | |
215 | if (sparc64nbsd_pc_in_sigtramp (pc, name)) | |
216 | { | |
217 | if (name == NULL || strncmp (name, "__sigtramp_sigcontext", 21)) | |
218 | return &sparc64nbsd_sigcontext_frame_unwind; | |
219 | } | |
220 | ||
221 | return NULL; | |
222 | } | |
223 | \f | |
224 | ||
225 | static void | |
226 | sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
227 | { | |
2ca62865 MK |
228 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
229 | ||
9ea75c57 | 230 | tdep->gregset = regset_alloc (gdbarch, sparc64nbsd_supply_gregset, NULL); |
2ca62865 MK |
231 | tdep->sizeof_gregset = 160; |
232 | ||
9ea75c57 | 233 | tdep->fpregset = regset_alloc (gdbarch, sparc64nbsd_supply_fpregset, NULL); |
2ca62865 MK |
234 | tdep->sizeof_fpregset = 272; |
235 | ||
386c036b MK |
236 | frame_unwind_append_sniffer (gdbarch, sparc64nbsd_sigtramp_frame_sniffer); |
237 | ||
238 | sparc64_init_abi (info, gdbarch); | |
239 | ||
3510d1f2 | 240 | /* NetBSD/sparc64 has SVR4-style shared libraries... */ |
3510d1f2 | 241 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); |
386c036b | 242 | set_solib_svr4_fetch_link_map_offsets |
3510d1f2 | 243 | (gdbarch, svr4_lp64_fetch_link_map_offsets); |
386c036b MK |
244 | } |
245 | ||
246 | \f | |
247 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
248 | void _initialize_sparc64nbsd_tdep (void); | |
249 | ||
250 | void | |
251 | _initialize_sparc64nbsd_tdep (void) | |
252 | { | |
253 | gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9, | |
254 | GDB_OSABI_NETBSD_ELF, sparc64nbsd_init_abi); | |
386c036b | 255 | } |