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