1 /* Target-dependent code for NetBSD/alpha.
3 Copyright (C) 2002-2019 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 3 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, see <http://www.gnu.org/licenses/>. */
24 /* Local non-gdb includes. */
25 #include "alpha-bsd-tdep.h"
26 #include "alpha-tdep.h"
29 #include "nbsd-tdep.h"
33 #include "solib-svr4.h"
37 /* Core file support. */
39 /* Sizeof `struct reg' in <machine/reg.h>. */
40 #define ALPHANBSD_SIZEOF_GREGS (32 * 8)
42 /* Sizeof `struct fpreg' in <machine/reg.h. */
43 #define ALPHANBSD_SIZEOF_FPREGS ((32 * 8) + 8)
45 /* Supply register REGNUM from the buffer specified by FPREGS and LEN
46 in the floating-point register set REGSET to register cache
47 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
50 alphanbsd_supply_fpregset (const struct regset
*regset
,
51 struct regcache
*regcache
,
52 int regnum
, const void *fpregs
, size_t len
)
54 const gdb_byte
*regs
= (const gdb_byte
*) fpregs
;
57 gdb_assert (len
>= ALPHANBSD_SIZEOF_FPREGS
);
59 for (i
= ALPHA_FP0_REGNUM
; i
< ALPHA_FP0_REGNUM
+ 31; i
++)
61 if (regnum
== i
|| regnum
== -1)
62 regcache
->raw_supply (i
, regs
+ (i
- ALPHA_FP0_REGNUM
) * 8);
65 if (regnum
== ALPHA_FPCR_REGNUM
|| regnum
== -1)
66 regcache
->raw_supply (ALPHA_FPCR_REGNUM
, regs
+ 32 * 8);
69 /* Supply register REGNUM from the buffer specified by GREGS and LEN
70 in the general-purpose register set REGSET to register cache
71 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
74 alphanbsd_aout_supply_gregset (const struct regset
*regset
,
75 struct regcache
*regcache
,
76 int regnum
, const void *gregs
, size_t len
)
78 const gdb_byte
*regs
= (const gdb_byte
*) gregs
;
81 /* Table to map a GDB register number to a trapframe register index. */
82 static const int regmap
[] =
94 gdb_assert (len
>= ALPHANBSD_SIZEOF_GREGS
);
96 for (i
= 0; i
< ARRAY_SIZE(regmap
); i
++)
98 if (regnum
== i
|| regnum
== -1)
99 regcache
->raw_supply (i
, regs
+ regmap
[i
] * 8);
102 if (regnum
== ALPHA_PC_REGNUM
|| regnum
== -1)
103 regcache
->raw_supply (ALPHA_PC_REGNUM
, regs
+ 31 * 8);
105 if (len
>= ALPHANBSD_SIZEOF_GREGS
+ ALPHANBSD_SIZEOF_FPREGS
)
107 regs
+= ALPHANBSD_SIZEOF_GREGS
;
108 len
-= ALPHANBSD_SIZEOF_GREGS
;
109 alphanbsd_supply_fpregset (regset
, regcache
, regnum
, regs
, len
);
113 /* Supply register REGNUM from the buffer specified by GREGS and LEN
114 in the general-purpose register set REGSET to register cache
115 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
118 alphanbsd_supply_gregset (const struct regset
*regset
,
119 struct regcache
*regcache
,
120 int regnum
, const void *gregs
, size_t len
)
122 const gdb_byte
*regs
= (const gdb_byte
*) gregs
;
125 if (len
>= ALPHANBSD_SIZEOF_GREGS
+ ALPHANBSD_SIZEOF_FPREGS
)
127 alphanbsd_aout_supply_gregset (regset
, regcache
, regnum
, gregs
, len
);
131 for (i
= 0; i
< ALPHA_ZERO_REGNUM
; i
++)
133 if (regnum
== i
|| regnum
== -1)
134 regcache
->raw_supply (i
, regs
+ i
* 8);
137 if (regnum
== ALPHA_PC_REGNUM
|| regnum
== -1)
138 regcache
->raw_supply (ALPHA_PC_REGNUM
, regs
+ 31 * 8);
141 /* NetBSD/alpha register sets. */
143 static const struct regset alphanbsd_gregset
=
146 alphanbsd_supply_gregset
,
151 static const struct regset alphanbsd_fpregset
=
154 alphanbsd_supply_fpregset
157 /* Iterate over supported core file register note sections. */
160 alphanbsd_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
161 iterate_over_regset_sections_cb
*cb
,
163 const struct regcache
*regcache
)
165 cb (".reg", ALPHANBSD_SIZEOF_GREGS
, ALPHANBSD_SIZEOF_GREGS
,
166 &alphanbsd_gregset
, NULL
, cb_data
);
167 cb (".reg2", ALPHANBSD_SIZEOF_FPREGS
, ALPHANBSD_SIZEOF_FPREGS
,
168 &alphanbsd_fpregset
, NULL
, cb_data
);
172 /* Signal trampolines. */
174 /* Under NetBSD/alpha, signal handler invocations can be identified by the
175 designated code sequence that is used to return from a signal handler.
176 In particular, the return address of a signal handler points to the
177 following code sequence:
181 lda v0, 295(zero) # __sigreturn14
184 Each instruction has a unique encoding, so we simply attempt to match
185 the instruction the PC is pointing to with any of the above instructions.
186 If there is a hit, we know the offset to the start of the designated
187 sequence and can then check whether we really are executing in the
188 signal trampoline. If not, -1 is returned, otherwise the offset from the
189 start of the return sequence is returned. */
190 static const gdb_byte sigtramp_retcode
[] =
192 0x00, 0x00, 0x1e, 0xa6, /* ldq a0, 0(sp) */
193 0x10, 0x00, 0xde, 0x23, /* lda sp, 16(sp) */
194 0x27, 0x01, 0x1f, 0x20, /* lda v0, 295(zero) */
195 0x83, 0x00, 0x00, 0x00, /* call_pal callsys */
197 #define RETCODE_NWORDS 4
198 #define RETCODE_SIZE (RETCODE_NWORDS * 4)
201 alphanbsd_sigtramp_offset (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
203 gdb_byte ret
[RETCODE_SIZE
], w
[4];
207 if (target_read_memory (pc
, w
, 4) != 0)
210 for (i
= 0; i
< RETCODE_NWORDS
; i
++)
212 if (memcmp (w
, sigtramp_retcode
+ (i
* 4), 4) == 0)
215 if (i
== RETCODE_NWORDS
)
221 if (target_read_memory (pc
, ret
, sizeof (ret
)) != 0)
224 if (memcmp (ret
, sigtramp_retcode
, RETCODE_SIZE
) == 0)
231 alphanbsd_pc_in_sigtramp (struct gdbarch
*gdbarch
,
232 CORE_ADDR pc
, const char *func_name
)
234 return (nbsd_pc_in_sigtramp (pc
, func_name
)
235 || alphanbsd_sigtramp_offset (gdbarch
, pc
) >= 0);
239 alphanbsd_sigcontext_addr (struct frame_info
*frame
)
241 /* FIXME: This is not correct for all versions of NetBSD/alpha.
242 We will probably need to disassemble the trampoline to figure
243 out which trampoline frame type we have. */
244 if (!get_next_frame (frame
))
246 return get_frame_base (get_next_frame (frame
));
251 alphanbsd_init_abi (struct gdbarch_info info
,
252 struct gdbarch
*gdbarch
)
254 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
256 /* Hook into the DWARF CFI frame unwinder. */
257 alpha_dwarf2_init_abi (info
, gdbarch
);
259 /* Hook into the MDEBUG frame unwinder. */
260 alpha_mdebug_init_abi (info
, gdbarch
);
262 /* NetBSD/alpha does not provide single step support via ptrace(2); we
263 must use software single-stepping. */
264 set_gdbarch_software_single_step (gdbarch
, alpha_software_single_step
);
266 /* NetBSD/alpha has SVR4-style shared libraries. */
267 set_solib_svr4_fetch_link_map_offsets
268 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
270 tdep
->dynamic_sigtramp_offset
= alphanbsd_sigtramp_offset
;
271 tdep
->pc_in_sigtramp
= alphanbsd_pc_in_sigtramp
;
272 tdep
->sigcontext_addr
= alphanbsd_sigcontext_addr
;
275 tdep
->jb_elt_size
= 8;
277 set_gdbarch_iterate_over_regset_sections
278 (gdbarch
, alphanbsd_iterate_over_regset_sections
);
283 _initialize_alphanbsd_tdep (void)
285 /* Even though NetBSD/alpha used ELF since day one, it used the
286 traditional a.out-style core dump format before NetBSD 1.6, but
287 we don't support those. */
288 gdbarch_register_osabi (bfd_arch_alpha
, 0, GDB_OSABI_NETBSD
,