ALPHA: Migrate from 'regset_from_core_section' to 'iterate_over_regset_sections'
[deliverable/binutils-gdb.git] / gdb / alphanbsd-tdep.c
CommitLineData
789f3b5f
MK
1/* Target-dependent code for NetBSD/alpha.
2
ecd75fc8 3 Copyright (C) 2002-2014 Free Software Foundation, Inc.
2031c21a 4
da8ca43d
JT
5 Contributed by Wasabi Systems, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
da8ca43d
JT
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
da8ca43d
JT
21
22#include "defs.h"
2ca8ae21 23#include "frame.h"
3beabdb2
MK
24#include "gdbcore.h"
25#include "osabi.h"
8513dd2d 26#include "regcache.h"
3beabdb2 27#include "regset.h"
da8ca43d 28#include "value.h"
da8ca43d
JT
29
30#include "alpha-tdep.h"
8513dd2d 31#include "alphabsd-tdep.h"
ea5bc2a6 32#include "nbsd-tdep.h"
527ca6bb 33#include "solib-svr4.h"
effa26a9 34#include "target.h"
8513dd2d 35
3beabdb2
MK
36/* Core file support. */
37
38/* Even though NetBSD/alpha used ELF since day one, it used the
39 traditional a.out-style core dump format before NetBSD 1.6. */
40
41/* Sizeof `struct reg' in <machine/reg.h>. */
42#define ALPHANBSD_SIZEOF_GREGS (32 * 8)
43
44/* Sizeof `struct fpreg' in <machine/reg.h. */
45#define ALPHANBSD_SIZEOF_FPREGS ((32 * 8) + 8)
46
47/* Supply register REGNUM from the buffer specified by FPREGS and LEN
48 in the floating-point register set REGSET to register cache
49 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
50
8513dd2d 51static void
3beabdb2
MK
52alphanbsd_supply_fpregset (const struct regset *regset,
53 struct regcache *regcache,
54 int regnum, const void *fpregs, size_t len)
8513dd2d 55{
3beabdb2
MK
56 const gdb_byte *regs = fpregs;
57 int i;
58
59 gdb_assert (len >= ALPHANBSD_SIZEOF_FPREGS);
60
61 for (i = ALPHA_FP0_REGNUM; i < ALPHA_FP0_REGNUM + 31; i++)
62 {
63 if (regnum == i || regnum == -1)
64 regcache_raw_supply (regcache, i, regs + (i - ALPHA_FP0_REGNUM) * 8);
65 }
66
67 if (regnum == ALPHA_FPCR_REGNUM || regnum == -1)
68 regcache_raw_supply (regcache, ALPHA_FPCR_REGNUM, regs + 32 * 8);
69}
70
3beabdb2
MK
71/* Supply register REGNUM from the buffer specified by GREGS and LEN
72 in the general-purpose register set REGSET to register cache
73 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
74
75static void
76alphanbsd_aout_supply_gregset (const struct regset *regset,
77 struct regcache *regcache,
78 int regnum, const void *gregs, size_t len)
79{
80 const gdb_byte *regs = gregs;
81 int i;
82
83 /* Table to map a GDB register number to a trapframe register index. */
8513dd2d
JT
84 static const int regmap[] =
85 {
86 0, 1, 2, 3,
87 4, 5, 6, 7,
88 8, 9, 10, 11,
89 12, 13, 14, 15,
90 30, 31, 32, 16,
91 17, 18, 19, 20,
92 21, 22, 23, 24,
93 25, 29, 26
94 };
8513dd2d 95
3beabdb2 96 gdb_assert (len >= ALPHANBSD_SIZEOF_GREGS);
8513dd2d 97
3beabdb2 98 for (i = 0; i < ARRAY_SIZE(regmap); i++)
8513dd2d 99 {
3beabdb2
MK
100 if (regnum == i || regnum == -1)
101 regcache_raw_supply (regcache, i, regs + regmap[i] * 8);
8513dd2d
JT
102 }
103
3beabdb2
MK
104 if (regnum == ALPHA_PC_REGNUM || regnum == -1)
105 regcache_raw_supply (regcache, ALPHA_PC_REGNUM, regs + 31 * 8);
8513dd2d 106
3beabdb2 107 if (len >= ALPHANBSD_SIZEOF_GREGS + ALPHANBSD_SIZEOF_FPREGS)
8513dd2d 108 {
3beabdb2
MK
109 regs += ALPHANBSD_SIZEOF_GREGS;
110 len -= ALPHANBSD_SIZEOF_GREGS;
111 alphanbsd_supply_fpregset (regset, regcache, regnum, regs, len);
8513dd2d
JT
112 }
113}
114
dff2166e
AA
115/* Supply register REGNUM from the buffer specified by GREGS and LEN
116 in the general-purpose register set REGSET to register cache
117 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
118
119static void
120alphanbsd_supply_gregset (const struct regset *regset,
121 struct regcache *regcache,
122 int regnum, const void *gregs, size_t len)
123{
124 const gdb_byte *regs = gregs;
125 int i;
126
127 if (len >= ALPHANBSD_SIZEOF_GREGS + ALPHANBSD_SIZEOF_FPREGS)
128 {
129 alphanbsd_aout_supply_gregset (regset, regcache, regnum, gregs, len);
130 return;
131 }
132
133 for (i = 0; i < ALPHA_ZERO_REGNUM; i++)
134 {
135 if (regnum == i || regnum == -1)
136 regcache_raw_supply (regcache, i, regs + i * 8);
137 }
138
139 if (regnum == ALPHA_PC_REGNUM || regnum == -1)
140 regcache_raw_supply (regcache, ALPHA_PC_REGNUM, regs + 31 * 8);
141}
142
3beabdb2
MK
143/* NetBSD/alpha register sets. */
144
3ca7dae4 145static const struct regset alphanbsd_gregset =
8513dd2d 146{
3beabdb2
MK
147 NULL,
148 alphanbsd_supply_gregset
8513dd2d
JT
149};
150
3ca7dae4 151static const struct regset alphanbsd_fpregset =
8513dd2d 152{
3beabdb2
MK
153 NULL,
154 alphanbsd_supply_fpregset
8513dd2d 155};
da8ca43d 156
dff2166e 157/* Iterate over supported core file register note sections. */
3beabdb2 158
dff2166e
AA
159void
160alphanbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
161 iterate_over_regset_sections_cb *cb,
162 void *cb_data,
163 const struct regcache *regcache)
3beabdb2 164{
dff2166e
AA
165 cb (".reg", ALPHANBSD_SIZEOF_GREGS, &alphanbsd_gregset, NULL, cb_data);
166 cb (".reg2", ALPHANBSD_SIZEOF_FPREGS, &alphanbsd_fpregset, NULL, cb_data);
3beabdb2 167}
3beabdb2
MK
168\f
169
170/* Signal trampolines. */
171
da8ca43d
JT
172/* Under NetBSD/alpha, signal handler invocations can be identified by the
173 designated code sequence that is used to return from a signal handler.
174 In particular, the return address of a signal handler points to the
175 following code sequence:
176
177 ldq a0, 0(sp)
178 lda sp, 16(sp)
179 lda v0, 295(zero) # __sigreturn14
180 call_pal callsys
181
182 Each instruction has a unique encoding, so we simply attempt to match
183 the instruction the PC is pointing to with any of the above instructions.
184 If there is a hit, we know the offset to the start of the designated
185 sequence and can then check whether we really are executing in the
186 signal trampoline. If not, -1 is returned, otherwise the offset from the
187 start of the return sequence is returned. */
948f8e3d 188static const gdb_byte sigtramp_retcode[] =
da8ca43d 189{
cfef91e4
JT
190 0x00, 0x00, 0x1e, 0xa6, /* ldq a0, 0(sp) */
191 0x10, 0x00, 0xde, 0x23, /* lda sp, 16(sp) */
192 0x27, 0x01, 0x1f, 0x20, /* lda v0, 295(zero) */
193 0x83, 0x00, 0x00, 0x00, /* call_pal callsys */
da8ca43d 194};
cfef91e4
JT
195#define RETCODE_NWORDS 4
196#define RETCODE_SIZE (RETCODE_NWORDS * 4)
da8ca43d 197
b0ca8573 198static LONGEST
e17a4113 199alphanbsd_sigtramp_offset (struct gdbarch *gdbarch, CORE_ADDR pc)
da8ca43d 200{
948f8e3d 201 gdb_byte ret[RETCODE_SIZE], w[4];
da8ca43d
JT
202 LONGEST off;
203 int i;
204
948f8e3d 205 if (target_read_memory (pc, w, 4) != 0)
da8ca43d
JT
206 return -1;
207
208 for (i = 0; i < RETCODE_NWORDS; i++)
209 {
cfef91e4 210 if (memcmp (w, sigtramp_retcode + (i * 4), 4) == 0)
da8ca43d
JT
211 break;
212 }
213 if (i == RETCODE_NWORDS)
214 return (-1);
215
216 off = i * 4;
217 pc -= off;
218
948f8e3d 219 if (target_read_memory (pc, ret, sizeof (ret)) != 0)
da8ca43d
JT
220 return -1;
221
cfef91e4 222 if (memcmp (ret, sigtramp_retcode, RETCODE_SIZE) == 0)
da8ca43d
JT
223 return off;
224
225 return -1;
226}
227
6c72f9f9 228static int
e17a4113 229alphanbsd_pc_in_sigtramp (struct gdbarch *gdbarch,
2c02bd72 230 CORE_ADDR pc, const char *func_name)
6c72f9f9 231{
3d9b49b0 232 return (nbsd_pc_in_sigtramp (pc, func_name)
e17a4113 233 || alphanbsd_sigtramp_offset (gdbarch, pc) >= 0);
6c72f9f9
JT
234}
235
2ca8ae21
JT
236static CORE_ADDR
237alphanbsd_sigcontext_addr (struct frame_info *frame)
238{
239 /* FIXME: This is not correct for all versions of NetBSD/alpha.
240 We will probably need to disassemble the trampoline to figure
241 out which trampoline frame type we have. */
94afd7a6
UW
242 if (!get_next_frame (frame))
243 return 0;
244 return get_frame_base (get_next_frame (frame));
2ca8ae21 245}
b0ca8573 246\f
2ca8ae21 247
da8ca43d
JT
248static void
249alphanbsd_init_abi (struct gdbarch_info info,
250 struct gdbarch *gdbarch)
251{
252 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
253
baa490c4
RH
254 /* Hook into the DWARF CFI frame unwinder. */
255 alpha_dwarf2_init_abi (info, gdbarch);
256
257 /* Hook into the MDEBUG frame unwinder. */
258 alpha_mdebug_init_abi (info, gdbarch);
259
da8ca43d
JT
260 /* NetBSD/alpha does not provide single step support via ptrace(2); we
261 must use software single-stepping. */
262 set_gdbarch_software_single_step (gdbarch, alpha_software_single_step);
263
789f3b5f
MK
264 /* NetBSD/alpha has SVR4-style shared libraries. */
265 set_solib_svr4_fetch_link_map_offsets
266 (gdbarch, svr4_lp64_fetch_link_map_offsets);
da8ca43d
JT
267
268 tdep->dynamic_sigtramp_offset = alphanbsd_sigtramp_offset;
f2524b93 269 tdep->pc_in_sigtramp = alphanbsd_pc_in_sigtramp;
2ca8ae21 270 tdep->sigcontext_addr = alphanbsd_sigcontext_addr;
accc6d1f
JT
271
272 tdep->jb_pc = 2;
273 tdep->jb_elt_size = 8;
3beabdb2 274
dff2166e
AA
275 set_gdbarch_iterate_over_regset_sections
276 (gdbarch, alphanbsd_iterate_over_regset_sections);
3beabdb2 277}
3beabdb2
MK
278\f
279
280static enum gdb_osabi
281alphanbsd_core_osabi_sniffer (bfd *abfd)
282{
283 if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0)
b0ca8573 284 return GDB_OSABI_NETBSD_ELF;
3beabdb2
MK
285
286 return GDB_OSABI_UNKNOWN;
287}
288\f
289
290/* Provide a prototype to silence -Wmissing-prototypes. */
291void _initialize_alphanbsd_tdep (void);
da8ca43d
JT
292
293void
294_initialize_alphanbsd_tdep (void)
295{
3beabdb2
MK
296 /* BFD doesn't set a flavour for NetBSD style a.out core files. */
297 gdbarch_register_osabi_sniffer (bfd_arch_alpha, bfd_target_unknown_flavour,
298 alphanbsd_core_osabi_sniffer);
299
05816f70 300 gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_NETBSD_ELF,
70f80edf 301 alphanbsd_init_abi);
da8ca43d 302}
This page took 0.728371 seconds and 4 git commands to generate.