1 /* Target-dependent code for NetBSD/i386, for GDB.
2 Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002, 2003
3 Free Software Foundation, 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 "arch-utils.h"
29 #include "i386-tdep.h"
30 #include "i387-tdep.h"
31 #include "nbsd-tdep.h"
33 #include "solib-svr4.h"
35 /* Map a GDB register number to an offset in the reg structure. */
47 ( 9 * 4), /* %eflags */
56 #define SIZEOF_STRUCT_REG (16 * 4)
59 i386nbsd_supply_reg (char *regs
, int regno
)
63 for (i
= 0; i
<= 15; i
++)
64 if (regno
== i
|| regno
== -1)
65 supply_register (i
, regs
+ regmap
[i
]);
69 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
, int which
,
74 /* We get everything from one section. */
78 if (core_reg_size
< (SIZEOF_STRUCT_REG
+ 108))
80 warning ("Wrong size register set in core file.");
85 fsave
= core_reg_sect
+ SIZEOF_STRUCT_REG
;
87 /* Integer registers. */
88 i386nbsd_supply_reg (regs
, -1);
90 /* Floating point registers. */
91 i387_supply_fsave (fsave
);
95 fetch_elfcore_registers (char *core_reg_sect
, unsigned core_reg_size
,
96 int which
, CORE_ADDR ignore
)
100 case 0: /* Integer registers. */
101 if (core_reg_size
!= SIZEOF_STRUCT_REG
)
102 warning ("Wrong size register set in core file.");
104 i386nbsd_supply_reg (core_reg_sect
, -1);
107 case 2: /* Floating point registers. */
108 if (core_reg_size
!= 108)
109 warning ("Wrong size FP register set in core file.");
111 i387_supply_fsave (core_reg_sect
);
114 case 3: /* "Extended" floating point registers. This is gdb-speak
116 if (core_reg_size
!= 512)
117 warning ("Wrong size XMM register set in core file.");
119 i387_supply_fxsave (core_reg_sect
);
123 /* Don't know what kind of register request this is; just ignore it. */
128 static struct core_fns i386nbsd_core_fns
=
130 bfd_target_unknown_flavour
, /* core_flavour */
131 default_check_format
, /* check_format */
132 default_core_sniffer
, /* core_sniffer */
133 fetch_core_registers
, /* core_read_registers */
137 static struct core_fns i386nbsd_elfcore_fns
=
139 bfd_target_elf_flavour
, /* core_flavour */
140 default_check_format
, /* check_format */
141 default_core_sniffer
, /* core_sniffer */
142 fetch_elfcore_registers
, /* core_read_registers */
146 /* Under NetBSD/i386, signal handler invocations can be identified by the
147 designated code sequence that is used to return from a signal handler.
148 In particular, the return address of a signal handler points to the
149 following code sequence:
151 leal 0x10(%esp), %eax
154 movl $0x127, %eax # __sigreturn14
157 Each instruction has a unique encoding, so we simply attempt to match
158 the instruction the PC is pointing to with any of the above instructions.
159 If there is a hit, we know the offset to the start of the designated
160 sequence and can then check whether we really are executing in the
161 signal trampoline. If not, -1 is returned, otherwise the offset from the
162 start of the return sequence is returned. */
163 #define RETCODE_INSN1 0x8d
164 #define RETCODE_INSN2 0x50
165 #define RETCODE_INSN3 0x50
166 #define RETCODE_INSN4 0xb8
167 #define RETCODE_INSN5 0xcd
169 #define RETCODE_INSN2_OFF 4
170 #define RETCODE_INSN3_OFF 5
171 #define RETCODE_INSN4_OFF 6
172 #define RETCODE_INSN5_OFF 11
174 static const unsigned char sigtramp_retcode
[] =
176 RETCODE_INSN1
, 0x44, 0x24, 0x10,
179 RETCODE_INSN4
, 0x27, 0x01, 0x00, 0x00,
184 i386nbsd_sigtramp_offset (CORE_ADDR pc
)
186 unsigned char ret
[sizeof(sigtramp_retcode
)], insn
;
190 if (read_memory_nobpt (pc
, &insn
, 1) != 0)
200 /* INSN2 and INSN3 are the same. Read at the location of PC+1
201 to determine if we're actually looking at INSN2 or INSN3. */
202 if (read_memory_nobpt (pc
+ 1, &insn
, 1) != 0)
205 if (insn
== RETCODE_INSN3
)
206 off
= RETCODE_INSN2_OFF
;
208 off
= RETCODE_INSN3_OFF
;
212 off
= RETCODE_INSN4_OFF
;
216 off
= RETCODE_INSN5_OFF
;
225 if (read_memory_nobpt (pc
, (char *) ret
, sizeof (ret
)) != 0)
228 if (memcmp (ret
, sigtramp_retcode
, sizeof (ret
)) == 0)
235 i386nbsd_pc_in_sigtramp (CORE_ADDR pc
, char *name
)
237 return (nbsd_pc_in_sigtramp (pc
, name
)
238 || i386nbsd_sigtramp_offset (pc
) >= 0);
241 /* From <machine/signal.h>. */
242 int i386nbsd_sc_pc_offset
= 44;
243 int i386nbsd_sc_sp_offset
= 56;
246 i386nbsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
248 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
250 /* Obviously NetBSD is BSD-based. */
251 i386bsd_init_abi (info
, gdbarch
);
253 /* NetBSD has different signal trampoline conventions. */
254 set_gdbarch_pc_in_sigtramp (gdbarch
, i386nbsd_pc_in_sigtramp
);
255 /* FIXME: kettenis/20020906: We should probably provide
256 NetBSD-specific versions of these functions if we want to
257 recognize signal trampolines that live on the stack. */
258 set_gdbarch_sigtramp_start (gdbarch
, NULL
);
259 set_gdbarch_sigtramp_end (gdbarch
, NULL
);
261 /* NetBSD uses -freg-struct-return by default. */
262 tdep
->struct_return
= reg_struct_return
;
264 /* NetBSD has a `struct sigcontext' that's different from the
265 origional 4.3 BSD. */
266 tdep
->sc_pc_offset
= i386nbsd_sc_pc_offset
;
267 tdep
->sc_sp_offset
= i386nbsd_sc_sp_offset
;
272 i386nbsdelf_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
274 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
276 /* It's still NetBSD. */
277 i386nbsd_init_abi (info
, gdbarch
);
280 i386_elf_init_abi (info
, gdbarch
);
282 /* NetBSD ELF uses SVR4-style shared libraries. */
283 set_gdbarch_in_solib_call_trampoline (gdbarch
,
284 generic_in_solib_call_trampoline
);
285 set_solib_svr4_fetch_link_map_offsets (gdbarch
,
286 nbsd_ilp32_solib_svr4_fetch_link_map_offsets
);
288 /* NetBSD ELF uses -fpcc-struct-return by default. */
289 tdep
->struct_return
= pcc_struct_return
;
291 /* We support the SSE registers on NetBSD ELF. */
292 tdep
->num_xmm_regs
= I386_NUM_XREGS
- 1;
293 set_gdbarch_num_regs (gdbarch
, I386_NUM_GREGS
+ I386_NUM_FREGS
298 _initialize_i386nbsd_tdep (void)
300 add_core_fns (&i386nbsd_core_fns
);
301 add_core_fns (&i386nbsd_elfcore_fns
);
303 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_NETBSD_AOUT
,
305 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_NETBSD_ELF
,
306 i386nbsdelf_init_abi
);