1 /* Target-dependent code for NetBSD/alpha.
3 Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
5 Contributed by Wasabi Systems, Inc.
7 This file is part of GDB.
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
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
32 #include "gdb_assert.h"
33 #include "gdb_string.h"
35 #include "alpha-tdep.h"
36 #include "alphabsd-tdep.h"
37 #include "nbsd-tdep.h"
38 #include "solib-svr4.h"
40 /* Core file support. */
42 /* Even though NetBSD/alpha used ELF since day one, it used the
43 traditional a.out-style core dump format before NetBSD 1.6. */
45 /* Sizeof `struct reg' in <machine/reg.h>. */
46 #define ALPHANBSD_SIZEOF_GREGS (32 * 8)
48 /* Sizeof `struct fpreg' in <machine/reg.h. */
49 #define ALPHANBSD_SIZEOF_FPREGS ((32 * 8) + 8)
51 /* Supply register REGNUM from the buffer specified by FPREGS and LEN
52 in the floating-point register set REGSET to register cache
53 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
56 alphanbsd_supply_fpregset (const struct regset
*regset
,
57 struct regcache
*regcache
,
58 int regnum
, const void *fpregs
, size_t len
)
60 const gdb_byte
*regs
= fpregs
;
63 gdb_assert (len
>= ALPHANBSD_SIZEOF_FPREGS
);
65 for (i
= ALPHA_FP0_REGNUM
; i
< ALPHA_FP0_REGNUM
+ 31; i
++)
67 if (regnum
== i
|| regnum
== -1)
68 regcache_raw_supply (regcache
, i
, regs
+ (i
- ALPHA_FP0_REGNUM
) * 8);
71 if (regnum
== ALPHA_FPCR_REGNUM
|| regnum
== -1)
72 regcache_raw_supply (regcache
, ALPHA_FPCR_REGNUM
, regs
+ 32 * 8);
75 /* Supply register REGNUM from the buffer specified by GREGS and LEN
76 in the general-purpose register set REGSET to register cache
77 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
80 alphanbsd_supply_gregset (const struct regset
*regset
,
81 struct regcache
*regcache
,
82 int regnum
, const void *gregs
, size_t len
)
84 const gdb_byte
*regs
= gregs
;
87 gdb_assert (len
>= ALPHANBSD_SIZEOF_GREGS
);
89 for (i
= 0; i
< ALPHA_ZERO_REGNUM
; i
++)
91 if (regnum
== i
|| regnum
== -1)
92 regcache_raw_supply (regcache
, i
, regs
+ i
* 8);
95 if (regnum
== ALPHA_PC_REGNUM
|| regnum
== -1)
96 regcache_raw_supply (regcache
, ALPHA_PC_REGNUM
, regs
+ 31 * 8);
99 /* Supply register REGNUM from the buffer specified by GREGS and LEN
100 in the general-purpose register set REGSET to register cache
101 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
104 alphanbsd_aout_supply_gregset (const struct regset
*regset
,
105 struct regcache
*regcache
,
106 int regnum
, const void *gregs
, size_t len
)
108 const gdb_byte
*regs
= gregs
;
111 /* Table to map a GDB register number to a trapframe register index. */
112 static const int regmap
[] =
124 gdb_assert (len
>= ALPHANBSD_SIZEOF_GREGS
);
126 for (i
= 0; i
< ARRAY_SIZE(regmap
); i
++)
128 if (regnum
== i
|| regnum
== -1)
129 regcache_raw_supply (regcache
, i
, regs
+ regmap
[i
] * 8);
132 if (regnum
== ALPHA_PC_REGNUM
|| regnum
== -1)
133 regcache_raw_supply (regcache
, ALPHA_PC_REGNUM
, regs
+ 31 * 8);
135 if (len
>= ALPHANBSD_SIZEOF_GREGS
+ ALPHANBSD_SIZEOF_FPREGS
)
137 regs
+= ALPHANBSD_SIZEOF_GREGS
;
138 len
-= ALPHANBSD_SIZEOF_GREGS
;
139 alphanbsd_supply_fpregset (regset
, regcache
, regnum
, regs
, len
);
143 /* NetBSD/alpha register sets. */
145 static struct regset alphanbsd_gregset
=
148 alphanbsd_supply_gregset
151 static struct regset alphanbsd_fpregset
=
154 alphanbsd_supply_fpregset
157 static struct regset alphanbsd_aout_gregset
=
160 alphanbsd_aout_supply_gregset
163 /* Return the appropriate register set for the core section identified
164 by SECT_NAME and SECT_SIZE. */
166 static const struct regset
*
167 alphanbsd_regset_from_core_section (struct gdbarch
*gdbarch
,
168 const char *sect_name
, size_t sect_size
)
170 if (strcmp (sect_name
, ".reg") == 0 && sect_size
>= ALPHANBSD_SIZEOF_GREGS
)
171 return &alphanbsd_gregset
;
173 if (strcmp (sect_name
, ".reg2") == 0 && sect_size
>= ALPHANBSD_SIZEOF_FPREGS
)
174 return &alphanbsd_fpregset
;
179 static const struct regset
*
180 alphanbsd_aout_regset_from_core_section (struct gdbarch
*gdbarch
,
181 const char *sect_name
,
184 if (strcmp (sect_name
, ".reg") == 0 && sect_size
>= ALPHANBSD_SIZEOF_GREGS
)
185 return &alphanbsd_aout_gregset
;
191 /* Signal trampolines. */
193 /* Under NetBSD/alpha, signal handler invocations can be identified by the
194 designated code sequence that is used to return from a signal handler.
195 In particular, the return address of a signal handler points to the
196 following code sequence:
200 lda v0, 295(zero) # __sigreturn14
203 Each instruction has a unique encoding, so we simply attempt to match
204 the instruction the PC is pointing to with any of the above instructions.
205 If there is a hit, we know the offset to the start of the designated
206 sequence and can then check whether we really are executing in the
207 signal trampoline. If not, -1 is returned, otherwise the offset from the
208 start of the return sequence is returned. */
209 static const unsigned char sigtramp_retcode
[] =
211 0x00, 0x00, 0x1e, 0xa6, /* ldq a0, 0(sp) */
212 0x10, 0x00, 0xde, 0x23, /* lda sp, 16(sp) */
213 0x27, 0x01, 0x1f, 0x20, /* lda v0, 295(zero) */
214 0x83, 0x00, 0x00, 0x00, /* call_pal callsys */
216 #define RETCODE_NWORDS 4
217 #define RETCODE_SIZE (RETCODE_NWORDS * 4)
220 alphanbsd_sigtramp_offset (CORE_ADDR pc
)
222 unsigned char ret
[RETCODE_SIZE
], w
[4];
226 if (deprecated_read_memory_nobpt (pc
, (char *) w
, 4) != 0)
229 for (i
= 0; i
< RETCODE_NWORDS
; i
++)
231 if (memcmp (w
, sigtramp_retcode
+ (i
* 4), 4) == 0)
234 if (i
== RETCODE_NWORDS
)
240 if (deprecated_read_memory_nobpt (pc
, (char *) ret
, sizeof (ret
)) != 0)
243 if (memcmp (ret
, sigtramp_retcode
, RETCODE_SIZE
) == 0)
250 alphanbsd_pc_in_sigtramp (CORE_ADDR pc
, char *func_name
)
252 return (nbsd_pc_in_sigtramp (pc
, func_name
)
253 || alphanbsd_sigtramp_offset (pc
) >= 0);
257 alphanbsd_sigcontext_addr (struct frame_info
*frame
)
259 /* FIXME: This is not correct for all versions of NetBSD/alpha.
260 We will probably need to disassemble the trampoline to figure
261 out which trampoline frame type we have. */
262 return get_frame_base (frame
);
266 alphanbsd_init_abi (struct gdbarch_info info
,
267 struct gdbarch
*gdbarch
)
269 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
271 /* Hook into the DWARF CFI frame unwinder. */
272 alpha_dwarf2_init_abi (info
, gdbarch
);
274 /* Hook into the MDEBUG frame unwinder. */
275 alpha_mdebug_init_abi (info
, gdbarch
);
277 /* NetBSD/alpha does not provide single step support via ptrace(2); we
278 must use software single-stepping. */
279 set_gdbarch_software_single_step (gdbarch
, alpha_software_single_step
);
281 /* NetBSD/alpha has SVR4-style shared libraries. */
282 set_solib_svr4_fetch_link_map_offsets
283 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
285 tdep
->dynamic_sigtramp_offset
= alphanbsd_sigtramp_offset
;
286 tdep
->pc_in_sigtramp
= alphanbsd_pc_in_sigtramp
;
287 tdep
->sigcontext_addr
= alphanbsd_sigcontext_addr
;
290 tdep
->jb_elt_size
= 8;
292 set_gdbarch_regset_from_core_section
293 (gdbarch
, alphanbsd_regset_from_core_section
);
297 alphanbsd_aout_init_abi (struct gdbarch_info info
,
298 struct gdbarch
*gdbarch
)
300 alphanbsd_init_abi(info
, gdbarch
);
302 set_gdbarch_regset_from_core_section
303 (gdbarch
, alphanbsd_aout_regset_from_core_section
);
307 static enum gdb_osabi
308 alphanbsd_core_osabi_sniffer (bfd
*abfd
)
310 if (strcmp (bfd_get_target (abfd
), "netbsd-core") == 0)
311 return GDB_OSABI_NETBSD_AOUT
;
313 return GDB_OSABI_UNKNOWN
;
317 /* Provide a prototype to silence -Wmissing-prototypes. */
318 void _initialize_alphanbsd_tdep (void);
321 _initialize_alphanbsd_tdep (void)
323 /* BFD doesn't set a flavour for NetBSD style a.out core files. */
324 gdbarch_register_osabi_sniffer (bfd_arch_alpha
, bfd_target_unknown_flavour
,
325 alphanbsd_core_osabi_sniffer
);
327 gdbarch_register_osabi (bfd_arch_alpha
, 0, GDB_OSABI_NETBSD_ELF
,
329 gdbarch_register_osabi (bfd_arch_alpha
, 0, GDB_OSABI_NETBSD_AOUT
,
330 alphanbsd_aout_init_abi
);
331 gdbarch_register_osabi (bfd_arch_alpha
, 0, GDB_OSABI_OPENBSD_ELF
,
332 alphanbsd_aout_init_abi
);