a136fc1aa84660961253cf5d4f82f2865213d9b8
[deliverable/binutils-gdb.git] / gdb / alphanbsd-tdep.c
1 /* Target-dependent code for NetBSD/alpha.
2
3 Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
4
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
11 the Free Software Foundation; either version 2 of the License, or
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
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. */
23
24 #include "defs.h"
25 #include "gdbcore.h"
26 #include "frame.h"
27 #include "regcache.h"
28 #include "value.h"
29 #include "osabi.h"
30
31 #include "gdb_string.h"
32
33 #include "alpha-tdep.h"
34 #include "alphabsd-tdep.h"
35 #include "nbsd-tdep.h"
36 #include "solib-svr4.h"
37
38 static void
39 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
40 CORE_ADDR ignore)
41 {
42 char *regs, *fpregs;
43 int regno;
44
45 /* Table to map a gdb register number to a trapframe register index. */
46 static const int regmap[] =
47 {
48 0, 1, 2, 3,
49 4, 5, 6, 7,
50 8, 9, 10, 11,
51 12, 13, 14, 15,
52 30, 31, 32, 16,
53 17, 18, 19, 20,
54 21, 22, 23, 24,
55 25, 29, 26
56 };
57 #define SIZEOF_TRAPFRAME (33 * 8)
58
59 /* We get everything from one section. */
60 if (which != 0)
61 return;
62
63 regs = core_reg_sect;
64 fpregs = core_reg_sect + SIZEOF_TRAPFRAME;
65
66 if (core_reg_size < (SIZEOF_TRAPFRAME + SIZEOF_STRUCT_FPREG))
67 {
68 warning (_("Wrong size register set in core file."));
69 return;
70 }
71
72 /* Integer registers. */
73 for (regno = 0; regno < ALPHA_ZERO_REGNUM; regno++)
74 regcache_raw_supply (current_regcache, regno, regs + (regmap[regno] * 8));
75 regcache_raw_supply (current_regcache, ALPHA_ZERO_REGNUM, NULL);
76 regcache_raw_supply (current_regcache, PC_REGNUM, regs + (28 * 8));
77
78 /* Floating point registers. */
79 alphabsd_supply_fpreg (fpregs, -1);
80 }
81
82 static void
83 fetch_elfcore_registers (char *core_reg_sect, unsigned core_reg_size, int which,
84 CORE_ADDR ignore)
85 {
86 switch (which)
87 {
88 case 0: /* Integer registers. */
89 if (core_reg_size != SIZEOF_STRUCT_REG)
90 warning (_("Wrong size register set in core file."));
91 else
92 alphabsd_supply_reg (core_reg_sect, -1);
93 break;
94
95 case 2: /* Floating point registers. */
96 if (core_reg_size != SIZEOF_STRUCT_FPREG)
97 warning (_("Wrong size FP register set in core file."));
98 else
99 alphabsd_supply_fpreg (core_reg_sect, -1);
100 break;
101
102 default:
103 /* Don't know what kind of register request this is; just ignore it. */
104 break;
105 }
106 }
107
108 static struct core_fns alphanbsd_core_fns =
109 {
110 bfd_target_unknown_flavour, /* core_flavour */
111 default_check_format, /* check_format */
112 default_core_sniffer, /* core_sniffer */
113 fetch_core_registers, /* core_read_registers */
114 NULL /* next */
115 };
116
117 static struct core_fns alphanbsd_elfcore_fns =
118 {
119 bfd_target_elf_flavour, /* core_flavour */
120 default_check_format, /* check_format */
121 default_core_sniffer, /* core_sniffer */
122 fetch_elfcore_registers, /* core_read_registers */
123 NULL /* next */
124 };
125
126 /* Under NetBSD/alpha, signal handler invocations can be identified by the
127 designated code sequence that is used to return from a signal handler.
128 In particular, the return address of a signal handler points to the
129 following code sequence:
130
131 ldq a0, 0(sp)
132 lda sp, 16(sp)
133 lda v0, 295(zero) # __sigreturn14
134 call_pal callsys
135
136 Each instruction has a unique encoding, so we simply attempt to match
137 the instruction the PC is pointing to with any of the above instructions.
138 If there is a hit, we know the offset to the start of the designated
139 sequence and can then check whether we really are executing in the
140 signal trampoline. If not, -1 is returned, otherwise the offset from the
141 start of the return sequence is returned. */
142 static const unsigned char sigtramp_retcode[] =
143 {
144 0x00, 0x00, 0x1e, 0xa6, /* ldq a0, 0(sp) */
145 0x10, 0x00, 0xde, 0x23, /* lda sp, 16(sp) */
146 0x27, 0x01, 0x1f, 0x20, /* lda v0, 295(zero) */
147 0x83, 0x00, 0x00, 0x00, /* call_pal callsys */
148 };
149 #define RETCODE_NWORDS 4
150 #define RETCODE_SIZE (RETCODE_NWORDS * 4)
151
152 LONGEST
153 alphanbsd_sigtramp_offset (CORE_ADDR pc)
154 {
155 unsigned char ret[RETCODE_SIZE], w[4];
156 LONGEST off;
157 int i;
158
159 if (deprecated_read_memory_nobpt (pc, (char *) w, 4) != 0)
160 return -1;
161
162 for (i = 0; i < RETCODE_NWORDS; i++)
163 {
164 if (memcmp (w, sigtramp_retcode + (i * 4), 4) == 0)
165 break;
166 }
167 if (i == RETCODE_NWORDS)
168 return (-1);
169
170 off = i * 4;
171 pc -= off;
172
173 if (deprecated_read_memory_nobpt (pc, (char *) ret, sizeof (ret)) != 0)
174 return -1;
175
176 if (memcmp (ret, sigtramp_retcode, RETCODE_SIZE) == 0)
177 return off;
178
179 return -1;
180 }
181
182 static int
183 alphanbsd_pc_in_sigtramp (CORE_ADDR pc, char *func_name)
184 {
185 return (nbsd_pc_in_sigtramp (pc, func_name)
186 || alphanbsd_sigtramp_offset (pc) >= 0);
187 }
188
189 static CORE_ADDR
190 alphanbsd_sigcontext_addr (struct frame_info *frame)
191 {
192 /* FIXME: This is not correct for all versions of NetBSD/alpha.
193 We will probably need to disassemble the trampoline to figure
194 out which trampoline frame type we have. */
195 return get_frame_base (frame);
196 }
197
198 static void
199 alphanbsd_init_abi (struct gdbarch_info info,
200 struct gdbarch *gdbarch)
201 {
202 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
203
204 /* Hook into the DWARF CFI frame unwinder. */
205 alpha_dwarf2_init_abi (info, gdbarch);
206
207 /* Hook into the MDEBUG frame unwinder. */
208 alpha_mdebug_init_abi (info, gdbarch);
209
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);
213
214 /* NetBSD/alpha has SVR4-style shared libraries. */
215 set_solib_svr4_fetch_link_map_offsets
216 (gdbarch, svr4_lp64_fetch_link_map_offsets);
217
218 tdep->dynamic_sigtramp_offset = alphanbsd_sigtramp_offset;
219 tdep->pc_in_sigtramp = alphanbsd_pc_in_sigtramp;
220 tdep->sigcontext_addr = alphanbsd_sigcontext_addr;
221
222 tdep->jb_pc = 2;
223 tdep->jb_elt_size = 8;
224 }
225
226 void
227 _initialize_alphanbsd_tdep (void)
228 {
229 gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_NETBSD_ELF,
230 alphanbsd_init_abi);
231 gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_OPENBSD_ELF,
232 alphanbsd_init_abi);
233
234 deprecated_add_core_fns (&alphanbsd_core_fns);
235 deprecated_add_core_fns (&alphanbsd_elfcore_fns);
236 }
This page took 0.032469 seconds and 3 git commands to generate.