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 #include "solib-svr4.h"
34 /* Map a GDB register number to an offset in the reg structure. */
46 ( 9 * 4), /* %eflags */
55 #define SIZEOF_STRUCT_REG (16 * 4)
58 i386nbsd_supply_reg (char *regs, int regno)
62 for (i = 0; i <= 15; i++)
63 if (regno == i || regno == -1)
64 supply_register (i, regs + regmap[i]);
68 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
73 /* We get everything from one section. */
77 if (core_reg_size < (SIZEOF_STRUCT_REG + 108))
79 warning ("Wrong size register set in core file.");
84 fsave = core_reg_sect + SIZEOF_STRUCT_REG;
86 /* Integer registers. */
87 i386nbsd_supply_reg (regs, -1);
89 /* Floating point registers. */
90 i387_supply_fsave (fsave);
94 fetch_elfcore_registers (char *core_reg_sect, unsigned core_reg_size,
95 int which, CORE_ADDR ignore)
99 case 0: /* Integer registers. */
100 if (core_reg_size != SIZEOF_STRUCT_REG)
101 warning ("Wrong size register set in core file.");
103 i386nbsd_supply_reg (core_reg_sect, -1);
106 case 2: /* Floating point registers. */
107 if (core_reg_size != 108)
108 warning ("Wrong size FP register set in core file.");
110 i387_supply_fsave (core_reg_sect);
113 case 3: /* "Extended" floating point registers. This is gdb-speak
115 if (core_reg_size != 512)
116 warning ("Wrong size XMM register set in core file.");
118 i387_supply_fxsave (core_reg_sect);
122 /* Don't know what kind of register request this is; just ignore it. */
127 static struct core_fns i386nbsd_core_fns =
129 bfd_target_unknown_flavour, /* core_flavour */
130 default_check_format, /* check_format */
131 default_core_sniffer, /* core_sniffer */
132 fetch_core_registers, /* core_read_registers */
136 static struct core_fns i386nbsd_elfcore_fns =
138 bfd_target_elf_flavour, /* core_flavour */
139 default_check_format, /* check_format */
140 default_core_sniffer, /* core_sniffer */
141 fetch_elfcore_registers, /* core_read_registers */
145 /* Under NetBSD/i386, signal handler invocations can be identified by the
146 designated code sequence that is used to return from a signal handler.
147 In particular, the return address of a signal handler points to the
148 following code sequence:
150 leal 0x10(%esp), %eax
153 movl $0x127, %eax # __sigreturn14
156 Each instruction has a unique encoding, so we simply attempt to match
157 the instruction the PC is pointing to with any of the above instructions.
158 If there is a hit, we know the offset to the start of the designated
159 sequence and can then check whether we really are executing in the
160 signal trampoline. If not, -1 is returned, otherwise the offset from the
161 start of the return sequence is returned. */
162 #define RETCODE_INSN1 0x8d
163 #define RETCODE_INSN2 0x50
164 #define RETCODE_INSN3 0x50
165 #define RETCODE_INSN4 0xb8
166 #define RETCODE_INSN5 0xcd
168 #define RETCODE_INSN2_OFF 4
169 #define RETCODE_INSN3_OFF 5
170 #define RETCODE_INSN4_OFF 6
171 #define RETCODE_INSN5_OFF 11
173 static const unsigned char sigtramp_retcode[] =
175 RETCODE_INSN1, 0x44, 0x24, 0x10,
178 RETCODE_INSN4, 0x27, 0x01, 0x00, 0x00,
183 i386nbsd_sigtramp_offset (CORE_ADDR pc)
185 unsigned char ret[sizeof(sigtramp_retcode)], insn;
189 if (read_memory_nobpt (pc, &insn, 1) != 0)
199 /* INSN2 and INSN3 are the same. Read at the location of PC+1
200 to determine if we're actually looking at INSN2 or INSN3. */
201 if (read_memory_nobpt (pc + 1, &insn, 1) != 0)
204 if (insn == RETCODE_INSN3)
205 off = RETCODE_INSN2_OFF;
207 off = RETCODE_INSN3_OFF;
211 off = RETCODE_INSN4_OFF;
215 off = RETCODE_INSN5_OFF;
224 if (read_memory_nobpt (pc, (char *) ret, sizeof (ret)) != 0)
227 if (memcmp (ret, sigtramp_retcode, sizeof (ret)) == 0)
234 i386nbsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
236 return (nbsd_pc_in_sigtramp (pc, name)
237 || i386nbsd_sigtramp_offset (pc) >= 0);
240 /* From <machine/signal.h>. */
241 int i386nbsd_sc_pc_offset = 44;
242 int i386nbsd_sc_sp_offset = 56;
245 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
247 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
249 /* Obviously NetBSD is BSD-based. */
250 i386bsd_init_abi (info, gdbarch);
252 /* NetBSD has different signal trampoline conventions. */
253 set_gdbarch_pc_in_sigtramp (gdbarch, i386nbsd_pc_in_sigtramp);
254 /* FIXME: kettenis/20020906: We should probably provide
255 NetBSD-specific versions of these functions if we want to
256 recognize signal trampolines that live on the stack. */
257 set_gdbarch_sigtramp_start (gdbarch, NULL);
258 set_gdbarch_sigtramp_end (gdbarch, NULL);
260 /* NetBSD uses -freg-struct-return by default. */
261 tdep->struct_return = reg_struct_return;
263 /* NetBSD has a `struct sigcontext' that's different from the
264 origional 4.3 BSD. */
265 tdep->sc_pc_offset = i386nbsd_sc_pc_offset;
266 tdep->sc_sp_offset = i386nbsd_sc_sp_offset;
271 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
273 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
275 /* It's still NetBSD. */
276 i386nbsd_init_abi (info, gdbarch);
279 i386_elf_init_abi (info, gdbarch);
281 /* NetBSD ELF uses SVR4-style shared libraries. */
282 set_gdbarch_in_solib_call_trampoline (gdbarch,
283 generic_in_solib_call_trampoline);
284 set_solib_svr4_fetch_link_map_offsets (gdbarch,
285 nbsd_ilp32_solib_svr4_fetch_link_map_offsets);
287 /* NetBSD ELF uses -fpcc-struct-return by default. */
288 tdep->struct_return = pcc_struct_return;
290 /* We support the SSE registers on NetBSD ELF. */
291 tdep->num_xmm_regs = I386_NUM_XREGS - 1;
292 set_gdbarch_num_regs (gdbarch, I386_NUM_GREGS + I386_NUM_FREGS
297 _initialize_i386nbsd_tdep (void)
299 add_core_fns (&i386nbsd_core_fns);
300 add_core_fns (&i386nbsd_elfcore_fns);
302 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD_AOUT,
304 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD_ELF,
305 i386nbsdelf_init_abi);