1 /* Target-dependent code for NetBSD/i386.
3 Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002,
5 Free Software Foundation, Inc.
7 This file is part of GDB.
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.
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.
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., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
25 #include "arch-utils.h"
33 #include "gdb_assert.h"
34 #include "gdb_string.h"
36 #include "i386-tdep.h"
37 #include "i387-tdep.h"
38 #include "nbsd-tdep.h"
39 #include "solib-svr4.h"
41 /* From <machine/reg.h>. */
42 static int i386nbsd_r_reg_offset[] =
63 i386nbsd_aout_supply_regset (const struct regset *regset,
64 struct regcache *regcache, int regnum,
65 const void *regs, size_t len)
67 const struct gdbarch_tdep *tdep = regset->descr;
69 gdb_assert (len >= tdep->sizeof_gregset + I387_SIZEOF_FSAVE);
71 i386_supply_gregset (regset, regcache, regnum, regs, tdep->sizeof_gregset);
72 i387_supply_fsave (regcache, regnum, (char *) regs + tdep->sizeof_gregset);
75 static const struct regset *
76 i386nbsd_aout_regset_from_core_section (struct gdbarch *gdbarch,
77 const char *sect_name,
80 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
82 /* NetBSD a.out core dumps don't use seperate register sets for the
83 general-purpose and floating-point registers. */
85 if (strcmp (sect_name, ".reg") == 0
86 && sect_size >= tdep->sizeof_gregset + I387_SIZEOF_FSAVE)
88 if (tdep->gregset == NULL)
90 = regset_xmalloc (tdep, i386nbsd_aout_supply_regset, NULL);
97 /* Under NetBSD/i386, signal handler invocations can be identified by the
98 designated code sequence that is used to return from a signal handler.
99 In particular, the return address of a signal handler points to the
100 following code sequence:
102 leal 0x10(%esp), %eax
105 movl $0x127, %eax # __sigreturn14
108 Each instruction has a unique encoding, so we simply attempt to match
109 the instruction the PC is pointing to with any of the above instructions.
110 If there is a hit, we know the offset to the start of the designated
111 sequence and can then check whether we really are executing in the
112 signal trampoline. If not, -1 is returned, otherwise the offset from the
113 start of the return sequence is returned. */
114 #define RETCODE_INSN1 0x8d
115 #define RETCODE_INSN2 0x50
116 #define RETCODE_INSN3 0x50
117 #define RETCODE_INSN4 0xb8
118 #define RETCODE_INSN5 0xcd
120 #define RETCODE_INSN2_OFF 4
121 #define RETCODE_INSN3_OFF 5
122 #define RETCODE_INSN4_OFF 6
123 #define RETCODE_INSN5_OFF 11
125 static const unsigned char sigtramp_retcode[] =
127 RETCODE_INSN1, 0x44, 0x24, 0x10,
130 RETCODE_INSN4, 0x27, 0x01, 0x00, 0x00,
135 i386nbsd_sigtramp_offset (CORE_ADDR pc)
137 unsigned char ret[sizeof(sigtramp_retcode)], insn;
141 if (read_memory_nobpt (pc, &insn, 1) != 0)
151 /* INSN2 and INSN3 are the same. Read at the location of PC+1
152 to determine if we're actually looking at INSN2 or INSN3. */
153 if (read_memory_nobpt (pc + 1, &insn, 1) != 0)
156 if (insn == RETCODE_INSN3)
157 off = RETCODE_INSN2_OFF;
159 off = RETCODE_INSN3_OFF;
163 off = RETCODE_INSN4_OFF;
167 off = RETCODE_INSN5_OFF;
176 if (read_memory_nobpt (pc, (char *) ret, sizeof (ret)) != 0)
179 if (memcmp (ret, sigtramp_retcode, sizeof (ret)) == 0)
185 /* Return whether the frame preceding NEXT_FRAME corresponds to a
186 NetBSD sigtramp routine. */
189 i386nbsd_sigtramp_p (struct frame_info *next_frame)
191 CORE_ADDR pc = frame_pc_unwind (next_frame);
194 find_pc_partial_function (pc, &name, NULL, NULL);
195 return (nbsd_pc_in_sigtramp (pc, name)
196 || i386nbsd_sigtramp_offset (pc) >= 0);
199 /* From <machine/signal.h>. */
200 int i386nbsd_sc_reg_offset[] =
211 13 * 4, /* %eflags */
221 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
223 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
225 /* Obviously NetBSD is BSD-based. */
226 i386bsd_init_abi (info, gdbarch);
228 /* NetBSD has a different `struct reg'. */
229 tdep->gregset_reg_offset = i386nbsd_r_reg_offset;
230 tdep->gregset_num_regs = ARRAY_SIZE (i386nbsd_r_reg_offset);
231 tdep->sizeof_gregset = 16 * 4;
233 /* NetBSD has different signal trampoline conventions. */
234 tdep->sigtramp_start = 0;
235 tdep->sigtramp_end = 0;
236 tdep->sigtramp_p = i386nbsd_sigtramp_p;
238 /* NetBSD uses -freg-struct-return by default. */
239 tdep->struct_return = reg_struct_return;
241 /* NetBSD has a `struct sigcontext' that's different from the
243 tdep->sc_reg_offset = i386nbsd_sc_reg_offset;
244 tdep->sc_num_regs = ARRAY_SIZE (i386nbsd_sc_reg_offset);
250 i386nbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
252 i386nbsd_init_abi (info, gdbarch);
254 /* NetBSD a.out has a single register set. */
255 set_gdbarch_regset_from_core_section
256 (gdbarch, i386nbsd_aout_regset_from_core_section);
262 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
264 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
266 /* It's still NetBSD. */
267 i386nbsd_init_abi (info, gdbarch);
270 i386_elf_init_abi (info, gdbarch);
272 /* NetBSD ELF uses SVR4-style shared libraries. */
273 set_gdbarch_in_solib_call_trampoline
274 (gdbarch, generic_in_solib_call_trampoline);
275 set_solib_svr4_fetch_link_map_offsets
276 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
278 /* NetBSD ELF uses -fpcc-struct-return by default. */
279 tdep->struct_return = pcc_struct_return;
283 _initialize_i386nbsd_tdep (void)
285 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD_AOUT,
286 i386nbsdaout_init_abi);
287 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD_ELF,
288 i386nbsdelf_init_abi);