1 /* Target-dependent code for NetBSD/Alpha.
3 Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
4 Contributed by Wasabi Systems, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
30 #include "solib-svr4.h"
32 #include "alpha-tdep.h"
33 #include "alphabsd-tdep.h"
34 #include "nbsd-tdep.h"
37 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
43 /* Table to map a gdb register number to a trapframe register index. */
44 static const int regmap[] =
55 #define SIZEOF_TRAPFRAME (33 * 8)
57 /* We get everything from one section. */
62 fpregs = core_reg_sect + SIZEOF_TRAPFRAME;
64 if (core_reg_size < (SIZEOF_TRAPFRAME + SIZEOF_STRUCT_FPREG))
66 warning ("Wrong size register set in core file.");
70 /* Integer registers. */
71 for (regno = 0; regno < ALPHA_ZERO_REGNUM; regno++)
72 supply_register (regno, regs + (regmap[regno] * 8));
73 supply_register (ALPHA_ZERO_REGNUM, NULL);
74 supply_register (PC_REGNUM, regs + (28 * 8));
76 /* Floating point registers. */
77 alphabsd_supply_fpreg (fpregs, -1);
81 fetch_elfcore_registers (char *core_reg_sect, unsigned core_reg_size, int which,
86 case 0: /* Integer registers. */
87 if (core_reg_size != SIZEOF_STRUCT_REG)
88 warning ("Wrong size register set in core file.");
90 alphabsd_supply_reg (core_reg_sect, -1);
93 case 2: /* Floating point registers. */
94 if (core_reg_size != SIZEOF_STRUCT_FPREG)
95 warning ("Wrong size FP register set in core file.");
97 alphabsd_supply_fpreg (core_reg_sect, -1);
101 /* Don't know what kind of register request this is; just ignore it. */
106 static struct core_fns alphanbsd_core_fns =
108 bfd_target_unknown_flavour, /* core_flavour */
109 default_check_format, /* check_format */
110 default_core_sniffer, /* core_sniffer */
111 fetch_core_registers, /* core_read_registers */
115 static struct core_fns alphanbsd_elfcore_fns =
117 bfd_target_elf_flavour, /* core_flavour */
118 default_check_format, /* check_format */
119 default_core_sniffer, /* core_sniffer */
120 fetch_elfcore_registers, /* core_read_registers */
124 /* Under NetBSD/alpha, signal handler invocations can be identified by the
125 designated code sequence that is used to return from a signal handler.
126 In particular, the return address of a signal handler points to the
127 following code sequence:
131 lda v0, 295(zero) # __sigreturn14
134 Each instruction has a unique encoding, so we simply attempt to match
135 the instruction the PC is pointing to with any of the above instructions.
136 If there is a hit, we know the offset to the start of the designated
137 sequence and can then check whether we really are executing in the
138 signal trampoline. If not, -1 is returned, otherwise the offset from the
139 start of the return sequence is returned. */
140 static const unsigned char sigtramp_retcode[] =
142 0x00, 0x00, 0x1e, 0xa6, /* ldq a0, 0(sp) */
143 0x10, 0x00, 0xde, 0x23, /* lda sp, 16(sp) */
144 0x27, 0x01, 0x1f, 0x20, /* lda v0, 295(zero) */
145 0x83, 0x00, 0x00, 0x00, /* call_pal callsys */
147 #define RETCODE_NWORDS 4
148 #define RETCODE_SIZE (RETCODE_NWORDS * 4)
151 alphanbsd_sigtramp_offset (CORE_ADDR pc)
153 unsigned char ret[RETCODE_SIZE], w[4];
157 if (read_memory_nobpt (pc, (char *) w, 4) != 0)
160 for (i = 0; i < RETCODE_NWORDS; i++)
162 if (memcmp (w, sigtramp_retcode + (i * 4), 4) == 0)
165 if (i == RETCODE_NWORDS)
171 if (read_memory_nobpt (pc, (char *) ret, sizeof (ret)) != 0)
174 if (memcmp (ret, sigtramp_retcode, RETCODE_SIZE) == 0)
181 alphanbsd_pc_in_sigtramp (CORE_ADDR pc, char *func_name)
183 return (nbsd_pc_in_sigtramp (pc, func_name)
184 || alphanbsd_sigtramp_offset (pc) >= 0);
188 alphanbsd_sigcontext_addr (struct frame_info *frame)
190 /* FIXME: This is not correct for all versions of NetBSD/alpha.
191 We will probably need to disassemble the trampoline to figure
192 out which trampoline frame type we have. */
193 return get_frame_base (frame);
197 alphanbsd_init_abi (struct gdbarch_info info,
198 struct gdbarch *gdbarch)
200 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
202 /* Hook into the DWARF CFI frame unwinder. */
203 alpha_dwarf2_init_abi (info, gdbarch);
205 /* Hook into the MDEBUG frame unwinder. */
206 alpha_mdebug_init_abi (info, gdbarch);
208 set_gdbarch_pc_in_sigtramp (gdbarch, alphanbsd_pc_in_sigtramp);
210 /* NetBSD/alpha does not provide single step support via ptrace(2); we
211 must use software single-stepping. */
212 set_gdbarch_software_single_step (gdbarch, alpha_software_single_step);
214 set_solib_svr4_fetch_link_map_offsets (gdbarch,
215 nbsd_lp64_solib_svr4_fetch_link_map_offsets);
217 tdep->dynamic_sigtramp_offset = alphanbsd_sigtramp_offset;
218 tdep->sigcontext_addr = alphanbsd_sigcontext_addr;
221 tdep->jb_elt_size = 8;
225 _initialize_alphanbsd_tdep (void)
227 gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_NETBSD_ELF,
229 gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_OPENBSD_ELF,
232 add_core_fns (&alphanbsd_core_fns);
233 add_core_fns (&alphanbsd_elfcore_fns);