]>
Commit | Line | Data |
---|---|---|
d195bc9f MK |
1 | /* Target-dependent code for OpenBSD/powerpc. |
2 | ||
0fb0cc75 JB |
3 | Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 |
4 | Free Software Foundation, Inc. | |
d195bc9f MK |
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 |
d195bc9f 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/>. */ |
d195bc9f MK |
20 | |
21 | #include "defs.h" | |
22 | #include "arch-utils.h" | |
0dbe1904 MK |
23 | #include "frame.h" |
24 | #include "frame-unwind.h" | |
e6bb342a | 25 | #include "gdbtypes.h" |
d195bc9f MK |
26 | #include "osabi.h" |
27 | #include "regcache.h" | |
28 | #include "regset.h" | |
0dbe1904 | 29 | #include "symtab.h" |
18b2ae85 | 30 | #include "trad-frame.h" |
d195bc9f | 31 | |
18b2ae85 | 32 | #include "gdb_assert.h" |
d195bc9f MK |
33 | #include "gdb_string.h" |
34 | ||
35 | #include "ppc-tdep.h" | |
36 | #include "ppcobsd-tdep.h" | |
37 | #include "solib-svr4.h" | |
38 | ||
39 | /* Register offsets from <machine/reg.h>. */ | |
40 | struct ppc_reg_offsets ppcobsd_reg_offsets; | |
8599da2d | 41 | struct ppc_reg_offsets ppcobsd_fpreg_offsets; |
d195bc9f MK |
42 | \f |
43 | ||
44 | /* Core file support. */ | |
45 | ||
46 | /* Supply register REGNUM in the general-purpose register set REGSET | |
47 | from the buffer specified by GREGS and LEN to register cache | |
48 | REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */ | |
49 | ||
50 | void | |
51 | ppcobsd_supply_gregset (const struct regset *regset, | |
52 | struct regcache *regcache, int regnum, | |
53 | const void *gregs, size_t len) | |
54 | { | |
55 | ppc_supply_gregset (regset, regcache, regnum, gregs, len); | |
56 | ppc_supply_fpregset (regset, regcache, regnum, gregs, len); | |
57 | } | |
58 | ||
59 | /* Collect register REGNUM in the general-purpose register set | |
60 | REGSET. from register cache REGCACHE into the buffer specified by | |
61 | GREGS and LEN. If REGNUM is -1, do this for all registers in | |
62 | REGSET. */ | |
63 | ||
64 | void | |
65 | ppcobsd_collect_gregset (const struct regset *regset, | |
66 | const struct regcache *regcache, int regnum, | |
67 | void *gregs, size_t len) | |
68 | { | |
69 | ppc_collect_gregset (regset, regcache, regnum, gregs, len); | |
70 | ppc_collect_fpregset (regset, regcache, regnum, gregs, len); | |
71 | } | |
72 | ||
5d6210f0 | 73 | /* OpenBSD/powerpc register set. */ |
d195bc9f MK |
74 | |
75 | struct regset ppcobsd_gregset = | |
76 | { | |
77 | &ppcobsd_reg_offsets, | |
78 | ppcobsd_supply_gregset | |
79 | }; | |
80 | ||
8599da2d MK |
81 | struct regset ppcobsd_fpregset = |
82 | { | |
83 | &ppcobsd_fpreg_offsets, | |
84 | ppc_supply_fpregset | |
85 | }; | |
86 | ||
d195bc9f MK |
87 | /* Return the appropriate register set for the core section identified |
88 | by SECT_NAME and SECT_SIZE. */ | |
89 | ||
90 | static const struct regset * | |
91 | ppcobsd_regset_from_core_section (struct gdbarch *gdbarch, | |
92 | const char *sect_name, size_t sect_size) | |
93 | { | |
94 | if (strcmp (sect_name, ".reg") == 0 && sect_size >= 412) | |
95 | return &ppcobsd_gregset; | |
96 | ||
97 | return NULL; | |
98 | } | |
99 | \f | |
100 | ||
18b2ae85 MK |
101 | /* Signal trampolines. */ |
102 | ||
0dbe1904 MK |
103 | /* Since OpenBSD 3.2, the sigtramp routine is mapped at a random page |
104 | in virtual memory. The randomness makes it somewhat tricky to | |
105 | detect it, but fortunately we can rely on the fact that the start | |
106 | of the sigtramp routine is page-aligned. We recognize the | |
107 | trampoline by looking for the code that invokes the sigreturn | |
108 | system call. The offset where we can find that code varies from | |
109 | release to release. | |
110 | ||
111 | By the way, the mapping mentioned above is read-only, so you cannot | |
112 | place a breakpoint in the signal trampoline. */ | |
113 | ||
114 | /* Default page size. */ | |
115 | static const int ppcobsd_page_size = 4096; | |
116 | ||
117 | /* Offset for sigreturn(2). */ | |
118 | static const int ppcobsd_sigreturn_offset[] = { | |
119 | 0x98, /* OpenBSD 3.8 */ | |
120 | 0x0c, /* OpenBSD 3.2 */ | |
121 | -1 | |
122 | }; | |
123 | ||
124 | static int | |
1af5d7ce UW |
125 | ppcobsd_sigtramp_frame_sniffer (const struct frame_unwind *self, |
126 | struct frame_info *this_frame, | |
127 | void **this_cache) | |
0dbe1904 | 128 | { |
1af5d7ce | 129 | CORE_ADDR pc = get_frame_pc (this_frame); |
0dbe1904 MK |
130 | CORE_ADDR start_pc = (pc & ~(ppcobsd_page_size - 1)); |
131 | const int *offset; | |
132 | char *name; | |
133 | ||
134 | find_pc_partial_function (pc, &name, NULL, NULL); | |
135 | if (name) | |
136 | return 0; | |
137 | ||
138 | for (offset = ppcobsd_sigreturn_offset; *offset != -1; offset++) | |
139 | { | |
140 | gdb_byte buf[2 * PPC_INSN_SIZE]; | |
141 | unsigned long insn; | |
142 | ||
1af5d7ce | 143 | if (!safe_frame_unwind_memory (this_frame, start_pc + *offset, |
0dbe1904 MK |
144 | buf, sizeof buf)) |
145 | continue; | |
146 | ||
147 | /* Check for "li r0,SYS_sigreturn". */ | |
148 | insn = extract_unsigned_integer (buf, PPC_INSN_SIZE); | |
149 | if (insn != 0x38000067) | |
150 | continue; | |
151 | ||
152 | /* Check for "sc". */ | |
153 | insn = extract_unsigned_integer (buf + PPC_INSN_SIZE, PPC_INSN_SIZE); | |
154 | if (insn != 0x44000002) | |
155 | continue; | |
156 | ||
157 | return 1; | |
158 | } | |
159 | ||
160 | return 0; | |
161 | } | |
162 | ||
163 | static struct trad_frame_cache * | |
1af5d7ce | 164 | ppcobsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache) |
18b2ae85 | 165 | { |
1af5d7ce | 166 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
18b2ae85 | 167 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
0dbe1904 MK |
168 | struct trad_frame_cache *cache; |
169 | CORE_ADDR addr, base, func; | |
170 | gdb_byte buf[PPC_INSN_SIZE]; | |
171 | unsigned long insn, sigcontext_offset; | |
18b2ae85 MK |
172 | int i; |
173 | ||
0dbe1904 MK |
174 | if (*this_cache) |
175 | return *this_cache; | |
176 | ||
1af5d7ce | 177 | cache = trad_frame_cache_zalloc (this_frame); |
0dbe1904 MK |
178 | *this_cache = cache; |
179 | ||
1af5d7ce | 180 | func = get_frame_pc (this_frame); |
0dbe1904 | 181 | func &= ~(ppcobsd_page_size - 1); |
1af5d7ce | 182 | if (!safe_frame_unwind_memory (this_frame, func, buf, sizeof buf)) |
0dbe1904 MK |
183 | return cache; |
184 | ||
185 | /* Calculate the offset where we can find `struct sigcontext'. We | |
186 | base our calculation on the amount of stack space reserved by the | |
187 | first instruction of the signal trampoline. */ | |
188 | insn = extract_unsigned_integer (buf, PPC_INSN_SIZE); | |
189 | sigcontext_offset = (0x10000 - (insn & 0x0000ffff)) + 8; | |
190 | ||
1af5d7ce | 191 | base = get_frame_register_unsigned (this_frame, gdbarch_sp_regnum (gdbarch)); |
0dbe1904 | 192 | addr = base + sigcontext_offset + 2 * tdep->wordsize; |
18b2ae85 MK |
193 | for (i = 0; i < ppc_num_gprs; i++, addr += tdep->wordsize) |
194 | { | |
195 | int regnum = i + tdep->ppc_gp0_regnum; | |
0dbe1904 | 196 | trad_frame_set_reg_addr (cache, regnum, addr); |
18b2ae85 | 197 | } |
0dbe1904 | 198 | trad_frame_set_reg_addr (cache, tdep->ppc_lr_regnum, addr); |
18b2ae85 | 199 | addr += tdep->wordsize; |
0dbe1904 | 200 | trad_frame_set_reg_addr (cache, tdep->ppc_cr_regnum, addr); |
18b2ae85 | 201 | addr += tdep->wordsize; |
0dbe1904 | 202 | trad_frame_set_reg_addr (cache, tdep->ppc_xer_regnum, addr); |
18b2ae85 | 203 | addr += tdep->wordsize; |
0dbe1904 | 204 | trad_frame_set_reg_addr (cache, tdep->ppc_ctr_regnum, addr); |
18b2ae85 | 205 | addr += tdep->wordsize; |
40a6adc1 | 206 | trad_frame_set_reg_addr (cache, gdbarch_pc_regnum (gdbarch), addr); |
3e8c568d | 207 | /* SRR0? */ |
18b2ae85 MK |
208 | addr += tdep->wordsize; |
209 | ||
210 | /* Construct the frame ID using the function start. */ | |
0dbe1904 MK |
211 | trad_frame_set_id (cache, frame_id_build (base, func)); |
212 | ||
213 | return cache; | |
18b2ae85 MK |
214 | } |
215 | ||
0dbe1904 | 216 | static void |
1af5d7ce | 217 | ppcobsd_sigtramp_frame_this_id (struct frame_info *this_frame, |
0dbe1904 MK |
218 | void **this_cache, struct frame_id *this_id) |
219 | { | |
220 | struct trad_frame_cache *cache = | |
1af5d7ce | 221 | ppcobsd_sigtramp_frame_cache (this_frame, this_cache); |
0dbe1904 MK |
222 | |
223 | trad_frame_get_id (cache, this_id); | |
224 | } | |
225 | ||
1af5d7ce UW |
226 | static struct value * |
227 | ppcobsd_sigtramp_frame_prev_register (struct frame_info *this_frame, | |
228 | void **this_cache, int regnum) | |
18b2ae85 | 229 | { |
0dbe1904 | 230 | struct trad_frame_cache *cache = |
1af5d7ce | 231 | ppcobsd_sigtramp_frame_cache (this_frame, this_cache); |
0dbe1904 | 232 | |
1af5d7ce | 233 | return trad_frame_get_register (cache, this_frame, regnum); |
0dbe1904 MK |
234 | } |
235 | ||
236 | static const struct frame_unwind ppcobsd_sigtramp_frame_unwind = { | |
18b2ae85 | 237 | SIGTRAMP_FRAME, |
0dbe1904 | 238 | ppcobsd_sigtramp_frame_this_id, |
1af5d7ce UW |
239 | ppcobsd_sigtramp_frame_prev_register, |
240 | NULL, | |
241 | ppcobsd_sigtramp_frame_sniffer | |
18b2ae85 | 242 | }; |
18b2ae85 | 243 | \f |
5d6210f0 | 244 | |
d195bc9f MK |
245 | static void |
246 | ppcobsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
247 | { | |
5a49dfd0 MK |
248 | /* OpenBSD doesn't support the 128-bit `long double' from the psABI. */ |
249 | set_gdbarch_long_double_bit (gdbarch, 64); | |
8da61cc4 | 250 | set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double); |
5a49dfd0 | 251 | |
a86c5ab2 MK |
252 | /* OpenBSD currently uses a broken GCC. */ |
253 | set_gdbarch_return_value (gdbarch, ppc_sysv_abi_broken_return_value); | |
254 | ||
d195bc9f | 255 | /* OpenBSD uses SVR4-style shared libraries. */ |
d195bc9f MK |
256 | set_solib_svr4_fetch_link_map_offsets |
257 | (gdbarch, svr4_ilp32_fetch_link_map_offsets); | |
258 | ||
259 | set_gdbarch_regset_from_core_section | |
260 | (gdbarch, ppcobsd_regset_from_core_section); | |
18b2ae85 | 261 | |
1af5d7ce | 262 | frame_unwind_append_unwinder (gdbarch, &ppcobsd_sigtramp_frame_unwind); |
d195bc9f MK |
263 | } |
264 | \f | |
265 | ||
266 | /* OpenBSD uses uses the traditional NetBSD core file format, even for | |
267 | ports that use ELF. */ | |
268 | #define GDB_OSABI_NETBSD_CORE GDB_OSABI_OPENBSD_ELF | |
269 | ||
270 | static enum gdb_osabi | |
271 | ppcobsd_core_osabi_sniffer (bfd *abfd) | |
272 | { | |
273 | if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0) | |
274 | return GDB_OSABI_NETBSD_CORE; | |
275 | ||
276 | return GDB_OSABI_UNKNOWN; | |
277 | } | |
278 | \f | |
279 | ||
280 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
281 | void _initialize_ppcobsd_tdep (void); | |
282 | ||
283 | void | |
284 | _initialize_ppcobsd_tdep (void) | |
285 | { | |
286 | /* BFD doesn't set a flavour for NetBSD style a.out core files. */ | |
287 | gdbarch_register_osabi_sniffer (bfd_arch_powerpc, bfd_target_unknown_flavour, | |
288 | ppcobsd_core_osabi_sniffer); | |
289 | ||
5d6210f0 MK |
290 | gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_OPENBSD_ELF, |
291 | ppcobsd_init_abi); | |
d195bc9f MK |
292 | gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_OPENBSD_ELF, |
293 | ppcobsd_init_abi); | |
294 | ||
295 | /* Avoid initializing the register offsets again if they were | |
296 | already initailized by ppcobsd-nat.c. */ | |
297 | if (ppcobsd_reg_offsets.pc_offset == 0) | |
298 | { | |
299 | /* General-purpose registers. */ | |
300 | ppcobsd_reg_offsets.r0_offset = 0; | |
f2db237a AM |
301 | ppcobsd_reg_offsets.gpr_size = 4; |
302 | ppcobsd_reg_offsets.xr_size = 4; | |
d195bc9f MK |
303 | ppcobsd_reg_offsets.pc_offset = 384; |
304 | ppcobsd_reg_offsets.ps_offset = 388; | |
305 | ppcobsd_reg_offsets.cr_offset = 392; | |
306 | ppcobsd_reg_offsets.lr_offset = 396; | |
307 | ppcobsd_reg_offsets.ctr_offset = 400; | |
308 | ppcobsd_reg_offsets.xer_offset = 404; | |
309 | ppcobsd_reg_offsets.mq_offset = 408; | |
310 | ||
311 | /* Floating-point registers. */ | |
312 | ppcobsd_reg_offsets.f0_offset = 128; | |
313 | ppcobsd_reg_offsets.fpscr_offset = -1; | |
314 | ||
315 | /* AltiVec registers. */ | |
316 | ppcobsd_reg_offsets.vr0_offset = 0; | |
317 | ppcobsd_reg_offsets.vscr_offset = 512; | |
318 | ppcobsd_reg_offsets.vrsave_offset = 520; | |
319 | } | |
8599da2d MK |
320 | |
321 | if (ppcobsd_fpreg_offsets.fpscr_offset == 0) | |
322 | { | |
323 | /* Floating-point registers. */ | |
324 | ppcobsd_reg_offsets.f0_offset = 0; | |
325 | ppcobsd_reg_offsets.fpscr_offset = 256; | |
f2db237a | 326 | ppcobsd_reg_offsets.fpscr_size = 4; |
8599da2d | 327 | } |
d195bc9f | 328 | } |