1 /* Target-dependent code for NetBSD/i386, for GDB.
2 Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002
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"
28 #include "i386-tdep.h"
29 #include "i387-tdep.h"
30 #include "nbsd-tdep.h"
32 /* Map a GDB register number to an offset in the reg structure. */
44 ( 9 * 4), /* %eflags */
53 #define SIZEOF_STRUCT_REG (16 * 4)
56 i386nbsd_supply_reg (char *regs
, int regno
)
60 for (i
= 0; i
<= 15; i
++)
61 if (regno
== i
|| regno
== -1)
62 supply_register (i
, regs
+ regmap
[i
]);
66 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
, int which
,
71 /* We get everything from one section. */
75 if (core_reg_size
< (SIZEOF_STRUCT_REG
+ 108))
77 warning ("Wrong size register set in core file.");
82 fsave
= core_reg_sect
+ SIZEOF_STRUCT_REG
;
84 /* Integer registers. */
85 i386nbsd_supply_reg (regs
, -1);
87 /* Floating point registers. */
88 i387_supply_fsave (fsave
);
92 fetch_elfcore_registers (char *core_reg_sect
, unsigned core_reg_size
,
93 int which
, CORE_ADDR ignore
)
97 case 0: /* Integer registers. */
98 if (core_reg_size
!= SIZEOF_STRUCT_REG
)
99 warning ("Wrong size register set in core file.");
101 i386nbsd_supply_reg (core_reg_sect
, -1);
104 case 2: /* Floating point registers. */
105 if (core_reg_size
!= 108)
106 warning ("Wrong size FP register set in core file.");
108 i387_supply_fsave (core_reg_sect
);
111 case 3: /* "Extended" floating point registers. This is gdb-speak
113 if (core_reg_size
!= 512)
114 warning ("Wrong size XMM register set in core file.");
116 i387_supply_fxsave (core_reg_sect
);
120 /* Don't know what kind of register request this is; just ignore it. */
125 static struct core_fns i386nbsd_core_fns
=
127 bfd_target_unknown_flavour
, /* core_flavour */
128 default_check_format
, /* check_format */
129 default_core_sniffer
, /* core_sniffer */
130 fetch_core_registers
, /* core_read_registers */
134 static struct core_fns i386nbsd_elfcore_fns
=
136 bfd_target_elf_flavour
, /* core_flavour */
137 default_check_format
, /* check_format */
138 default_core_sniffer
, /* core_sniffer */
139 fetch_elfcore_registers
, /* core_read_registers */
143 /* Under NetBSD/i386, signal handler invocations can be identified by the
144 designated code sequence that is used to return from a signal handler.
145 In particular, the return address of a signal handler points to the
146 following code sequence:
148 leal 0x10(%esp), %eax
151 movl $0x127, %eax # __sigreturn14
154 Each instruction has a unique encoding, so we simply attempt to match
155 the instruction the PC is pointing to with any of the above instructions.
156 If there is a hit, we know the offset to the start of the designated
157 sequence and can then check whether we really are executing in the
158 signal trampoline. If not, -1 is returned, otherwise the offset from the
159 start of the return sequence is returned. */
160 #define RETCODE_INSN1 0x8d
161 #define RETCODE_INSN2 0x50
162 #define RETCODE_INSN3 0x50
163 #define RETCODE_INSN4 0xb8
164 #define RETCODE_INSN5 0xcd
166 #define RETCODE_INSN2_OFF 4
167 #define RETCODE_INSN3_OFF 5
168 #define RETCODE_INSN4_OFF 6
169 #define RETCODE_INSN5_OFF 11
171 static const unsigned char sigtramp_retcode
[] =
173 RETCODE_INSN1
, 0x44, 0x24, 0x10,
176 RETCODE_INSN4
, 0x27, 0x01, 0x00, 0x00,
181 i386nbsd_sigtramp_offset (CORE_ADDR pc
)
183 unsigned char ret
[sizeof(sigtramp_retcode
)], insn
;
187 if (read_memory_nobpt (pc
, &insn
, 1) != 0)
197 /* INSN2 and INSN3 are the same. Read at the location of PC+1
198 to determine if we're actually looking at INSN2 or INSN3. */
199 if (read_memory_nobpt (pc
+ 1, &insn
, 1) != 0)
202 if (insn
== RETCODE_INSN3
)
203 off
= RETCODE_INSN2_OFF
;
205 off
= RETCODE_INSN3_OFF
;
209 off
= RETCODE_INSN4_OFF
;
213 off
= RETCODE_INSN5_OFF
;
222 if (read_memory_nobpt (pc
, (char *) ret
, sizeof (ret
)) != 0)
225 if (memcmp (ret
, sigtramp_retcode
, sizeof (ret
)) == 0)
232 i386nbsd_pc_in_sigtramp (CORE_ADDR pc
, char *name
)
235 return (nbsd_pc_in_sigtramp (pc
, name
)
236 || i386nbsd_sigtramp_offset (pc
) >= 0);
239 /* From <machine/signal.h>. */
240 int i386nbsd_sc_pc_offset
= 44;
241 int i386nbsd_sc_sp_offset
= 56;
244 i386nbsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
246 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
248 /* Obviously NetBSD is BSD-based. */
249 i386bsd_init_abi (info
, gdbarch
);
251 /* NetBSD has different signal trampoline conventions. */
252 set_gdbarch_pc_in_sigtramp (gdbarch
, i386nbsd_pc_in_sigtramp
);
254 /* NetBSD uses -freg-struct-return by default. */
255 tdep
->struct_return
= reg_struct_return
;
257 /* NetBSD has a `struct sigcontext' that's different from the
258 origional 4.3 BSD. */
259 tdep
->sc_pc_offset
= i386nbsd_sc_pc_offset
;
260 tdep
->sc_sp_offset
= i386nbsd_sc_sp_offset
;
265 i386nbsdelf_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
267 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
269 /* It's still NetBSD. */
270 i386nbsd_init_abi (info
, gdbarch
);
273 i386_elf_init_abi (info
, gdbarch
);
275 /* NetBSD ELF uses SVR4-style shared libraries. */
276 set_gdbarch_in_solib_call_trampoline (gdbarch
,
277 generic_in_solib_call_trampoline
);
279 /* NetBSD ELF uses -fpcc-struct-return by default. */
280 tdep
->struct_return
= pcc_struct_return
;
282 /* We support the SSE registers on NetBSD ELF. */
283 tdep
->num_xmm_regs
= I386_NUM_XREGS
- 1;
284 set_gdbarch_num_regs (gdbarch
, I386_NUM_GREGS
+ I386_NUM_FREGS
289 _initialize_i386nbsd_tdep (void)
291 add_core_fns (&i386nbsd_core_fns
);
292 add_core_fns (&i386nbsd_elfcore_fns
);
294 gdbarch_register_osabi (bfd_arch_i386
, GDB_OSABI_NETBSD_AOUT
,
296 gdbarch_register_osabi (bfd_arch_i386
, GDB_OSABI_NETBSD_ELF
,
297 i386nbsdelf_init_abi
);