* bucomm.c (bfd_nonfatal_message): New.
[deliverable/binutils-gdb.git] / gdb / ppcobsd-tdep.c
CommitLineData
d195bc9f
MK
1/* Target-dependent code for OpenBSD/powerpc.
2
6aba47ca 3 Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
d195bc9f
MK
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
d195bc9f
MK
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
d195bc9f
MK
19
20#include "defs.h"
21#include "arch-utils.h"
0dbe1904
MK
22#include "frame.h"
23#include "frame-unwind.h"
e6bb342a 24#include "gdbtypes.h"
d195bc9f
MK
25#include "osabi.h"
26#include "regcache.h"
27#include "regset.h"
0dbe1904 28#include "symtab.h"
18b2ae85 29#include "trad-frame.h"
d195bc9f 30
18b2ae85 31#include "gdb_assert.h"
d195bc9f
MK
32#include "gdb_string.h"
33
34#include "ppc-tdep.h"
35#include "ppcobsd-tdep.h"
36#include "solib-svr4.h"
37
38/* Register offsets from <machine/reg.h>. */
39struct ppc_reg_offsets ppcobsd_reg_offsets;
8599da2d 40struct ppc_reg_offsets ppcobsd_fpreg_offsets;
d195bc9f
MK
41\f
42
43/* Core file support. */
44
45/* Supply register REGNUM in the general-purpose register set REGSET
46 from the buffer specified by GREGS and LEN to register cache
47 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
48
49void
50ppcobsd_supply_gregset (const struct regset *regset,
51 struct regcache *regcache, int regnum,
52 const void *gregs, size_t len)
53{
383f0f5b
JB
54 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
55 point registers. Traditionally, GDB's register set has still
56 listed the floating point registers for such machines, so this
57 code is harmless. However, the new E500 port actually omits the
58 floating point registers entirely from the register set --- they
59 don't even have register numbers assigned to them.
60
61 It's not clear to me how best to update this code, so this assert
62 will alert the first person to encounter the OpenBSD/E500
63 combination to the problem. */
64 gdb_assert (ppc_floating_point_unit_p (current_gdbarch));
65
d195bc9f
MK
66 ppc_supply_gregset (regset, regcache, regnum, gregs, len);
67 ppc_supply_fpregset (regset, regcache, regnum, gregs, len);
68}
69
70/* Collect register REGNUM in the general-purpose register set
71 REGSET. from register cache REGCACHE into the buffer specified by
72 GREGS and LEN. If REGNUM is -1, do this for all registers in
73 REGSET. */
74
75void
76ppcobsd_collect_gregset (const struct regset *regset,
77 const struct regcache *regcache, int regnum,
78 void *gregs, size_t len)
79{
383f0f5b
JB
80 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
81 point registers. Traditionally, GDB's register set has still
82 listed the floating point registers for such machines, so this
83 code is harmless. However, the new E500 port actually omits the
84 floating point registers entirely from the register set --- they
85 don't even have register numbers assigned to them.
86
87 It's not clear to me how best to update this code, so this assert
88 will alert the first person to encounter the OpenBSD/E500
89 combination to the problem. */
90 gdb_assert (ppc_floating_point_unit_p (current_gdbarch));
91
d195bc9f
MK
92 ppc_collect_gregset (regset, regcache, regnum, gregs, len);
93 ppc_collect_fpregset (regset, regcache, regnum, gregs, len);
94}
95
5d6210f0 96/* OpenBSD/powerpc register set. */
d195bc9f
MK
97
98struct regset ppcobsd_gregset =
99{
100 &ppcobsd_reg_offsets,
101 ppcobsd_supply_gregset
102};
103
8599da2d
MK
104struct regset ppcobsd_fpregset =
105{
106 &ppcobsd_fpreg_offsets,
107 ppc_supply_fpregset
108};
109
d195bc9f
MK
110/* Return the appropriate register set for the core section identified
111 by SECT_NAME and SECT_SIZE. */
112
113static const struct regset *
114ppcobsd_regset_from_core_section (struct gdbarch *gdbarch,
115 const char *sect_name, size_t sect_size)
116{
117 if (strcmp (sect_name, ".reg") == 0 && sect_size >= 412)
118 return &ppcobsd_gregset;
119
120 return NULL;
121}
122\f
123
18b2ae85
MK
124/* Signal trampolines. */
125
0dbe1904
MK
126/* Since OpenBSD 3.2, the sigtramp routine is mapped at a random page
127 in virtual memory. The randomness makes it somewhat tricky to
128 detect it, but fortunately we can rely on the fact that the start
129 of the sigtramp routine is page-aligned. We recognize the
130 trampoline by looking for the code that invokes the sigreturn
131 system call. The offset where we can find that code varies from
132 release to release.
133
134 By the way, the mapping mentioned above is read-only, so you cannot
135 place a breakpoint in the signal trampoline. */
136
137/* Default page size. */
138static const int ppcobsd_page_size = 4096;
139
140/* Offset for sigreturn(2). */
141static const int ppcobsd_sigreturn_offset[] = {
142 0x98, /* OpenBSD 3.8 */
143 0x0c, /* OpenBSD 3.2 */
144 -1
145};
146
147static int
148ppcobsd_sigtramp_p (struct frame_info *next_frame)
149{
150 CORE_ADDR pc = frame_pc_unwind (next_frame);
151 CORE_ADDR start_pc = (pc & ~(ppcobsd_page_size - 1));
152 const int *offset;
153 char *name;
154
155 find_pc_partial_function (pc, &name, NULL, NULL);
156 if (name)
157 return 0;
158
159 for (offset = ppcobsd_sigreturn_offset; *offset != -1; offset++)
160 {
161 gdb_byte buf[2 * PPC_INSN_SIZE];
162 unsigned long insn;
163
164 if (!safe_frame_unwind_memory (next_frame, start_pc + *offset,
165 buf, sizeof buf))
166 continue;
167
168 /* Check for "li r0,SYS_sigreturn". */
169 insn = extract_unsigned_integer (buf, PPC_INSN_SIZE);
170 if (insn != 0x38000067)
171 continue;
172
173 /* Check for "sc". */
174 insn = extract_unsigned_integer (buf + PPC_INSN_SIZE, PPC_INSN_SIZE);
175 if (insn != 0x44000002)
176 continue;
177
178 return 1;
179 }
180
181 return 0;
182}
183
184static struct trad_frame_cache *
185ppcobsd_sigtramp_frame_cache (struct frame_info *next_frame, void **this_cache)
18b2ae85
MK
186{
187 struct gdbarch *gdbarch = get_frame_arch (next_frame);
188 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
0dbe1904
MK
189 struct trad_frame_cache *cache;
190 CORE_ADDR addr, base, func;
191 gdb_byte buf[PPC_INSN_SIZE];
192 unsigned long insn, sigcontext_offset;
18b2ae85
MK
193 int i;
194
0dbe1904
MK
195 if (*this_cache)
196 return *this_cache;
197
198 cache = trad_frame_cache_zalloc (next_frame);
199 *this_cache = cache;
200
201 func = frame_pc_unwind (next_frame);
202 func &= ~(ppcobsd_page_size - 1);
203 if (!safe_frame_unwind_memory (next_frame, func, buf, sizeof buf))
204 return cache;
205
206 /* Calculate the offset where we can find `struct sigcontext'. We
207 base our calculation on the amount of stack space reserved by the
208 first instruction of the signal trampoline. */
209 insn = extract_unsigned_integer (buf, PPC_INSN_SIZE);
210 sigcontext_offset = (0x10000 - (insn & 0x0000ffff)) + 8;
211
3e8c568d
UW
212 base = frame_unwind_register_unsigned (next_frame,
213 gdbarch_sp_regnum (current_gdbarch));
0dbe1904 214 addr = base + sigcontext_offset + 2 * tdep->wordsize;
18b2ae85
MK
215 for (i = 0; i < ppc_num_gprs; i++, addr += tdep->wordsize)
216 {
217 int regnum = i + tdep->ppc_gp0_regnum;
0dbe1904 218 trad_frame_set_reg_addr (cache, regnum, addr);
18b2ae85 219 }
0dbe1904 220 trad_frame_set_reg_addr (cache, tdep->ppc_lr_regnum, addr);
18b2ae85 221 addr += tdep->wordsize;
0dbe1904 222 trad_frame_set_reg_addr (cache, tdep->ppc_cr_regnum, addr);
18b2ae85 223 addr += tdep->wordsize;
0dbe1904 224 trad_frame_set_reg_addr (cache, tdep->ppc_xer_regnum, addr);
18b2ae85 225 addr += tdep->wordsize;
0dbe1904 226 trad_frame_set_reg_addr (cache, tdep->ppc_ctr_regnum, addr);
18b2ae85 227 addr += tdep->wordsize;
3e8c568d
UW
228 trad_frame_set_reg_addr (cache, gdbarch_pc_regnum (current_gdbarch), addr);
229 /* SRR0? */
18b2ae85
MK
230 addr += tdep->wordsize;
231
232 /* Construct the frame ID using the function start. */
0dbe1904
MK
233 trad_frame_set_id (cache, frame_id_build (base, func));
234
235 return cache;
18b2ae85
MK
236}
237
0dbe1904
MK
238static void
239ppcobsd_sigtramp_frame_this_id (struct frame_info *next_frame,
240 void **this_cache, struct frame_id *this_id)
241{
242 struct trad_frame_cache *cache =
243 ppcobsd_sigtramp_frame_cache (next_frame, this_cache);
244
245 trad_frame_get_id (cache, this_id);
246}
247
248static void
249ppcobsd_sigtramp_frame_prev_register (struct frame_info *next_frame,
250 void **this_cache, int regnum,
251 int *optimizedp, enum lval_type *lvalp,
252 CORE_ADDR *addrp, int *realnump,
253 gdb_byte *valuep)
18b2ae85 254{
0dbe1904
MK
255 struct trad_frame_cache *cache =
256 ppcobsd_sigtramp_frame_cache (next_frame, this_cache);
257
258 trad_frame_get_register (cache, next_frame, regnum,
259 optimizedp, lvalp, addrp, realnump, valuep);
260}
261
262static const struct frame_unwind ppcobsd_sigtramp_frame_unwind = {
18b2ae85 263 SIGTRAMP_FRAME,
0dbe1904
MK
264 ppcobsd_sigtramp_frame_this_id,
265 ppcobsd_sigtramp_frame_prev_register
18b2ae85 266};
0dbe1904
MK
267
268static const struct frame_unwind *
269ppcobsd_sigtramp_frame_sniffer (struct frame_info *next_frame)
270{
271 if (ppcobsd_sigtramp_p (next_frame))
272 return &ppcobsd_sigtramp_frame_unwind;
273
274 return NULL;
275}
18b2ae85 276\f
5d6210f0 277
d195bc9f
MK
278static void
279ppcobsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
280{
5a49dfd0
MK
281 /* OpenBSD doesn't support the 128-bit `long double' from the psABI. */
282 set_gdbarch_long_double_bit (gdbarch, 64);
8da61cc4 283 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
5a49dfd0 284
a86c5ab2
MK
285 /* OpenBSD currently uses a broken GCC. */
286 set_gdbarch_return_value (gdbarch, ppc_sysv_abi_broken_return_value);
287
d195bc9f 288 /* OpenBSD uses SVR4-style shared libraries. */
d195bc9f
MK
289 set_solib_svr4_fetch_link_map_offsets
290 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
291
292 set_gdbarch_regset_from_core_section
293 (gdbarch, ppcobsd_regset_from_core_section);
18b2ae85 294
0dbe1904 295 frame_unwind_append_sniffer (gdbarch, ppcobsd_sigtramp_frame_sniffer);
d195bc9f
MK
296}
297\f
298
299/* OpenBSD uses uses the traditional NetBSD core file format, even for
300 ports that use ELF. */
301#define GDB_OSABI_NETBSD_CORE GDB_OSABI_OPENBSD_ELF
302
303static enum gdb_osabi
304ppcobsd_core_osabi_sniffer (bfd *abfd)
305{
306 if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0)
307 return GDB_OSABI_NETBSD_CORE;
308
309 return GDB_OSABI_UNKNOWN;
310}
311\f
312
313/* Provide a prototype to silence -Wmissing-prototypes. */
314void _initialize_ppcobsd_tdep (void);
315
316void
317_initialize_ppcobsd_tdep (void)
318{
319 /* BFD doesn't set a flavour for NetBSD style a.out core files. */
320 gdbarch_register_osabi_sniffer (bfd_arch_powerpc, bfd_target_unknown_flavour,
321 ppcobsd_core_osabi_sniffer);
322
5d6210f0
MK
323 gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_OPENBSD_ELF,
324 ppcobsd_init_abi);
d195bc9f
MK
325 gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_OPENBSD_ELF,
326 ppcobsd_init_abi);
327
328 /* Avoid initializing the register offsets again if they were
329 already initailized by ppcobsd-nat.c. */
330 if (ppcobsd_reg_offsets.pc_offset == 0)
331 {
332 /* General-purpose registers. */
333 ppcobsd_reg_offsets.r0_offset = 0;
334 ppcobsd_reg_offsets.pc_offset = 384;
335 ppcobsd_reg_offsets.ps_offset = 388;
336 ppcobsd_reg_offsets.cr_offset = 392;
337 ppcobsd_reg_offsets.lr_offset = 396;
338 ppcobsd_reg_offsets.ctr_offset = 400;
339 ppcobsd_reg_offsets.xer_offset = 404;
340 ppcobsd_reg_offsets.mq_offset = 408;
341
342 /* Floating-point registers. */
343 ppcobsd_reg_offsets.f0_offset = 128;
344 ppcobsd_reg_offsets.fpscr_offset = -1;
345
346 /* AltiVec registers. */
347 ppcobsd_reg_offsets.vr0_offset = 0;
348 ppcobsd_reg_offsets.vscr_offset = 512;
349 ppcobsd_reg_offsets.vrsave_offset = 520;
350 }
8599da2d
MK
351
352 if (ppcobsd_fpreg_offsets.fpscr_offset == 0)
353 {
354 /* Floating-point registers. */
355 ppcobsd_reg_offsets.f0_offset = 0;
356 ppcobsd_reg_offsets.fpscr_offset = 256;
357 }
d195bc9f 358}
This page took 0.312179 seconds and 4 git commands to generate.