1 /* Target-dependent code for NetBSD/i386.
3 Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002, 2003
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
27 #include "arch-utils.h"
30 #include "i386-tdep.h"
31 #include "i387-tdep.h"
32 #include "nbsd-tdep.h"
34 #include "solib-svr4.h"
36 /* Map a GDB register number to an offset in the reg structure. */
48 ( 9 * 4), /* %eflags */
57 #define SIZEOF_STRUCT_REG (16 * 4)
60 i386nbsd_supply_reg (char *regs, int regno)
64 for (i = 0; i <= 15; i++)
65 if (regno == i || regno == -1)
66 supply_register (i, regs + regmap[i]);
70 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
75 /* We get everything from one section. */
79 if (core_reg_size < (SIZEOF_STRUCT_REG + 108))
81 warning ("Wrong size register set in core file.");
86 fsave = core_reg_sect + SIZEOF_STRUCT_REG;
88 /* Integer registers. */
89 i386nbsd_supply_reg (regs, -1);
91 /* Floating point registers. */
92 i387_supply_fsave (current_regcache, -1, fsave);
96 fetch_elfcore_registers (char *core_reg_sect, unsigned core_reg_size,
97 int which, CORE_ADDR ignore)
101 case 0: /* Integer registers. */
102 if (core_reg_size != SIZEOF_STRUCT_REG)
103 warning ("Wrong size register set in core file.");
105 i386nbsd_supply_reg (core_reg_sect, -1);
108 case 2: /* Floating point registers. */
109 if (core_reg_size != 108)
110 warning ("Wrong size FP register set in core file.");
112 i387_supply_fsave (current_regcache, -1, core_reg_sect);
115 case 3: /* "Extended" floating point registers. This is gdb-speak
117 if (core_reg_size != 512)
118 warning ("Wrong size XMM register set in core file.");
120 i387_supply_fxsave (current_regcache, -1, core_reg_sect);
124 /* Don't know what kind of register request this is; just ignore it. */
129 static struct core_fns i386nbsd_core_fns =
131 bfd_target_unknown_flavour, /* core_flavour */
132 default_check_format, /* check_format */
133 default_core_sniffer, /* core_sniffer */
134 fetch_core_registers, /* core_read_registers */
138 static struct core_fns i386nbsd_elfcore_fns =
140 bfd_target_elf_flavour, /* core_flavour */
141 default_check_format, /* check_format */
142 default_core_sniffer, /* core_sniffer */
143 fetch_elfcore_registers, /* core_read_registers */
147 /* Under NetBSD/i386, signal handler invocations can be identified by the
148 designated code sequence that is used to return from a signal handler.
149 In particular, the return address of a signal handler points to the
150 following code sequence:
152 leal 0x10(%esp), %eax
155 movl $0x127, %eax # __sigreturn14
158 Each instruction has a unique encoding, so we simply attempt to match
159 the instruction the PC is pointing to with any of the above instructions.
160 If there is a hit, we know the offset to the start of the designated
161 sequence and can then check whether we really are executing in the
162 signal trampoline. If not, -1 is returned, otherwise the offset from the
163 start of the return sequence is returned. */
164 #define RETCODE_INSN1 0x8d
165 #define RETCODE_INSN2 0x50
166 #define RETCODE_INSN3 0x50
167 #define RETCODE_INSN4 0xb8
168 #define RETCODE_INSN5 0xcd
170 #define RETCODE_INSN2_OFF 4
171 #define RETCODE_INSN3_OFF 5
172 #define RETCODE_INSN4_OFF 6
173 #define RETCODE_INSN5_OFF 11
175 static const unsigned char sigtramp_retcode[] =
177 RETCODE_INSN1, 0x44, 0x24, 0x10,
180 RETCODE_INSN4, 0x27, 0x01, 0x00, 0x00,
185 i386nbsd_sigtramp_offset (CORE_ADDR pc)
187 unsigned char ret[sizeof(sigtramp_retcode)], insn;
191 if (read_memory_nobpt (pc, &insn, 1) != 0)
201 /* INSN2 and INSN3 are the same. Read at the location of PC+1
202 to determine if we're actually looking at INSN2 or INSN3. */
203 if (read_memory_nobpt (pc + 1, &insn, 1) != 0)
206 if (insn == RETCODE_INSN3)
207 off = RETCODE_INSN2_OFF;
209 off = RETCODE_INSN3_OFF;
213 off = RETCODE_INSN4_OFF;
217 off = RETCODE_INSN5_OFF;
226 if (read_memory_nobpt (pc, (char *) ret, sizeof (ret)) != 0)
229 if (memcmp (ret, sigtramp_retcode, sizeof (ret)) == 0)
236 i386nbsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
238 return (nbsd_pc_in_sigtramp (pc, name)
239 || i386nbsd_sigtramp_offset (pc) >= 0);
242 /* From <machine/signal.h>. */
243 int i386nbsd_sc_reg_offset[I386_NUM_GREGS] =
254 13 * 4, /* %eflags */
264 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
266 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
268 /* Obviously NetBSD is BSD-based. */
269 i386bsd_init_abi (info, gdbarch);
271 /* NetBSD has different signal trampoline conventions. */
272 set_gdbarch_pc_in_sigtramp (gdbarch, i386nbsd_pc_in_sigtramp);
273 /* FIXME: kettenis/20020906: We should probably provide
274 NetBSD-specific versions of these functions if we want to
275 recognize signal trampolines that live on the stack. */
276 set_gdbarch_sigtramp_start (gdbarch, NULL);
277 set_gdbarch_sigtramp_end (gdbarch, NULL);
279 /* NetBSD uses -freg-struct-return by default. */
280 tdep->struct_return = reg_struct_return;
282 /* NetBSD has a `struct sigcontext' that's different from the
283 origional 4.3 BSD. */
284 tdep->sc_reg_offset = i386nbsd_sc_reg_offset;
285 tdep->sc_num_regs = I386_NUM_GREGS;
290 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
292 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
294 /* It's still NetBSD. */
295 i386nbsd_init_abi (info, gdbarch);
298 i386_elf_init_abi (info, gdbarch);
300 /* NetBSD ELF uses SVR4-style shared libraries. */
301 set_gdbarch_in_solib_call_trampoline (gdbarch,
302 generic_in_solib_call_trampoline);
303 set_solib_svr4_fetch_link_map_offsets (gdbarch,
304 nbsd_ilp32_solib_svr4_fetch_link_map_offsets);
306 /* NetBSD ELF uses -fpcc-struct-return by default. */
307 tdep->struct_return = pcc_struct_return;
309 /* We support the SSE registers on NetBSD ELF. */
310 tdep->num_xmm_regs = I386_NUM_XREGS - 1;
311 set_gdbarch_num_regs (gdbarch, I386_NUM_GREGS + I386_NUM_FREGS
316 _initialize_i386nbsd_tdep (void)
318 add_core_fns (&i386nbsd_core_fns);
319 add_core_fns (&i386nbsd_elfcore_fns);
321 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD_AOUT,
323 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD_ELF,
324 i386nbsdelf_init_abi);