1 /* Target-dependent code for NetBSD/Alpha.
2 Copyright 2002 Free Software Foundation, Inc.
3 Contributed by Wasabi Systems, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "solib-svr4.h"
28 #include "alpha-tdep.h"
29 #include "alphabsd-tdep.h"
32 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
38 /* Table to map a gdb register number to a trapframe register index. */
39 static const int regmap[] =
50 #define SIZEOF_TRAPFRAME (33 * 8)
52 /* We get everything from one section. */
57 fpregs = core_reg_sect + SIZEOF_TRAPFRAME;
59 if (core_reg_size < (SIZEOF_TRAPFRAME + SIZEOF_STRUCT_FPREG))
61 warning ("Wrong size register set in core file.");
65 /* Integer registers. */
66 for (regno = 0; regno < ALPHA_ZERO_REGNUM; regno++)
67 supply_register (regno, regs + (regmap[regno] * 8));
68 supply_register (ALPHA_ZERO_REGNUM, NULL);
69 supply_register (FP_REGNUM, NULL);
70 supply_register (PC_REGNUM, regs + (28 * 8));
72 /* Floating point registers. */
73 alphabsd_supply_fpreg (fpregs, -1);
77 fetch_elfcore_registers (char *core_reg_sect, unsigned core_reg_size, int which,
82 case 0: /* Integer registers. */
83 if (core_reg_size != SIZEOF_STRUCT_REG)
84 warning ("Wrong size register set in core file.");
86 alphabsd_supply_reg (core_reg_sect, -1);
89 case 2: /* Floating point registers. */
90 if (core_reg_size != SIZEOF_STRUCT_FPREG)
91 warning ("Wrong size FP register set in core file.");
93 alphabsd_supply_fpreg (core_reg_sect, -1);
97 /* Don't know what kind of register request this is; just ignore it. */
102 static struct core_fns alphanbsd_core_fns =
104 bfd_target_unknown_flavour, /* core_flavour */
105 default_check_format, /* check_format */
106 default_core_sniffer, /* core_sniffer */
107 fetch_core_registers, /* core_read_registers */
111 static struct core_fns alphanbsd_elfcore_fns =
113 bfd_target_elf_flavour, /* core_flavour */
114 default_check_format, /* check_format */
115 default_core_sniffer, /* core_sniffer */
116 fetch_elfcore_registers, /* core_read_registers */
120 /* Fetch (and possibly build) an appropriate link_map_offsets
121 structure for NetBSD/alpha targets using the struct offsets
122 defined in <link.h> (but without actual reference to that file).
124 This makes it possible to access NetBSD/alpha shared libraries
125 from a GDB that was not built on a NetBSD/alpha host (for cross
128 static struct link_map_offsets *
129 alphanbsd_solib_svr4_fetch_link_map_offsets (void)
131 static struct link_map_offsets lmo;
132 static struct link_map_offsets *lmp = NULL;
138 lmo.r_debug_size = 32;
140 lmo.r_map_offset = 8;
143 lmo.link_map_size = 40;
145 lmo.l_addr_offset = 0;
148 lmo.l_name_offset = 8;
151 lmo.l_next_offset = 24;
154 lmo.l_prev_offset = 32;
161 /* Under NetBSD/alpha, signal handler invocations can be identified by the
162 designated code sequence that is used to return from a signal handler.
163 In particular, the return address of a signal handler points to the
164 following code sequence:
168 lda v0, 295(zero) # __sigreturn14
171 Each instruction has a unique encoding, so we simply attempt to match
172 the instruction the PC is pointing to with any of the above instructions.
173 If there is a hit, we know the offset to the start of the designated
174 sequence and can then check whether we really are executing in the
175 signal trampoline. If not, -1 is returned, otherwise the offset from the
176 start of the return sequence is returned. */
177 static const unsigned int sigtramp_retcode[] =
179 0xa61e0000, /* ldq a0, 0(sp) */
180 0x23de0010, /* lda sp, 16(sp) */
181 0x201f0127, /* lda v0, 295(zero) */
182 0x00000083, /* call_pal callsys */
184 #define RETCODE_NWORDS \
185 (sizeof (sigtramp_retcode) / sizeof (sigtramp_retcode[0]))
188 alphanbsd_sigtramp_offset (CORE_ADDR pc)
190 unsigned int ret[4], w;
194 if (read_memory_nobpt (pc, (char *) &w, 4) != 0)
197 for (i = 0; i < RETCODE_NWORDS; i++)
199 if (w == sigtramp_retcode[i])
202 if (i == RETCODE_NWORDS)
208 if (read_memory_nobpt (pc, (char *) ret, sizeof (ret)) != 0)
211 if (memcmp (ret, sigtramp_retcode, sizeof (sigtramp_retcode)) == 0)
218 alphanbsd_pc_in_sigtramp (CORE_ADDR pc, char *func_name)
220 return (alphanbsd_sigtramp_offset (pc) >= 0);
224 alphanbsd_init_abi (struct gdbarch_info info,
225 struct gdbarch *gdbarch)
227 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
229 set_gdbarch_pc_in_sigtramp (gdbarch, alphanbsd_pc_in_sigtramp);
231 /* NetBSD/alpha does not provide single step support via ptrace(2); we
232 must use software single-stepping. */
233 set_gdbarch_software_single_step (gdbarch, alpha_software_single_step);
235 set_solib_svr4_fetch_link_map_offsets (gdbarch,
236 alphanbsd_solib_svr4_fetch_link_map_offsets);
238 tdep->dynamic_sigtramp_offset = alphanbsd_sigtramp_offset;
241 tdep->jb_elt_size = 8;
245 _initialize_alphanbsd_tdep (void)
247 alpha_gdbarch_register_os_abi (ALPHA_ABI_NETBSD, alphanbsd_init_abi);
249 add_core_fns (&alphanbsd_core_fns);
250 add_core_fns (&alphanbsd_elfcore_fns);