1 /* Target-dependent code for NetBSD/i386.
3 Copyright (C) 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002, 2003,
4 2004, 2007 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 3 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, see <http://www.gnu.org/licenses/>. */
22 #include "arch-utils.h"
30 #include "gdb_assert.h"
31 #include "gdb_string.h"
33 #include "i386-tdep.h"
34 #include "i387-tdep.h"
35 #include "nbsd-tdep.h"
36 #include "solib-svr4.h"
38 /* From <machine/reg.h>. */
39 static int i386nbsd_r_reg_offset[] =
60 i386nbsd_aout_supply_regset (const struct regset *regset,
61 struct regcache *regcache, int regnum,
62 const void *regs, size_t len)
64 const struct gdbarch_tdep *tdep = gdbarch_tdep (regset->arch);
66 gdb_assert (len >= tdep->sizeof_gregset + I387_SIZEOF_FSAVE);
68 i386_supply_gregset (regset, regcache, regnum, regs, tdep->sizeof_gregset);
69 i387_supply_fsave (regcache, regnum, (char *) regs + tdep->sizeof_gregset);
72 static const struct regset *
73 i386nbsd_aout_regset_from_core_section (struct gdbarch *gdbarch,
74 const char *sect_name,
77 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
79 /* NetBSD a.out core dumps don't use seperate register sets for the
80 general-purpose and floating-point registers. */
82 if (strcmp (sect_name, ".reg") == 0
83 && sect_size >= tdep->sizeof_gregset + I387_SIZEOF_FSAVE)
85 if (tdep->gregset == NULL)
87 regset_alloc (gdbarch, i386nbsd_aout_supply_regset, NULL);
94 /* Under NetBSD/i386, signal handler invocations can be identified by the
95 designated code sequence that is used to return from a signal handler.
96 In particular, the return address of a signal handler points to the
97 following code sequence:
102 movl $0x127, %eax # __sigreturn14
105 Each instruction has a unique encoding, so we simply attempt to match
106 the instruction the PC is pointing to with any of the above instructions.
107 If there is a hit, we know the offset to the start of the designated
108 sequence and can then check whether we really are executing in the
109 signal trampoline. If not, -1 is returned, otherwise the offset from the
110 start of the return sequence is returned. */
111 #define RETCODE_INSN1 0x8d
112 #define RETCODE_INSN2 0x50
113 #define RETCODE_INSN3 0x50
114 #define RETCODE_INSN4 0xb8
115 #define RETCODE_INSN5 0xcd
117 #define RETCODE_INSN2_OFF 4
118 #define RETCODE_INSN3_OFF 5
119 #define RETCODE_INSN4_OFF 6
120 #define RETCODE_INSN5_OFF 11
122 static const unsigned char sigtramp_retcode[] =
124 RETCODE_INSN1, 0x44, 0x24, 0x10,
127 RETCODE_INSN4, 0x27, 0x01, 0x00, 0x00,
132 i386nbsd_sigtramp_offset (struct frame_info *next_frame)
134 CORE_ADDR pc = frame_pc_unwind (next_frame);
135 unsigned char ret[sizeof(sigtramp_retcode)], insn;
139 if (!safe_frame_unwind_memory (next_frame, pc, &insn, 1))
149 /* INSN2 and INSN3 are the same. Read at the location of PC+1
150 to determine if we're actually looking at INSN2 or INSN3. */
151 if (!safe_frame_unwind_memory (next_frame, pc + 1, &insn, 1))
154 if (insn == RETCODE_INSN3)
155 off = RETCODE_INSN2_OFF;
157 off = RETCODE_INSN3_OFF;
161 off = RETCODE_INSN4_OFF;
165 off = RETCODE_INSN5_OFF;
174 if (!safe_frame_unwind_memory (next_frame, pc, ret, sizeof (ret)))
177 if (memcmp (ret, sigtramp_retcode, sizeof (ret)) == 0)
183 /* Return whether the frame preceding NEXT_FRAME corresponds to a
184 NetBSD sigtramp routine. */
187 i386nbsd_sigtramp_p (struct frame_info *next_frame)
189 CORE_ADDR pc = frame_pc_unwind (next_frame);
192 find_pc_partial_function (pc, &name, NULL, NULL);
193 return (nbsd_pc_in_sigtramp (pc, name)
194 || i386nbsd_sigtramp_offset (next_frame) >= 0);
197 /* From <machine/signal.h>. */
198 int i386nbsd_sc_reg_offset[] =
209 13 * 4, /* %eflags */
219 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
221 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
223 /* Obviously NetBSD is BSD-based. */
224 i386bsd_init_abi (info, gdbarch);
226 /* NetBSD has a different `struct reg'. */
227 tdep->gregset_reg_offset = i386nbsd_r_reg_offset;
228 tdep->gregset_num_regs = ARRAY_SIZE (i386nbsd_r_reg_offset);
229 tdep->sizeof_gregset = 16 * 4;
231 /* NetBSD has different signal trampoline conventions. */
232 tdep->sigtramp_start = 0;
233 tdep->sigtramp_end = 0;
234 tdep->sigtramp_p = i386nbsd_sigtramp_p;
236 /* NetBSD uses -freg-struct-return by default. */
237 tdep->struct_return = reg_struct_return;
239 /* NetBSD has a `struct sigcontext' that's different from the
241 tdep->sc_reg_offset = i386nbsd_sc_reg_offset;
242 tdep->sc_num_regs = ARRAY_SIZE (i386nbsd_sc_reg_offset);
248 i386nbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
250 i386nbsd_init_abi (info, gdbarch);
252 /* NetBSD a.out has a single register set. */
253 set_gdbarch_regset_from_core_section
254 (gdbarch, i386nbsd_aout_regset_from_core_section);
260 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
262 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
264 /* It's still NetBSD. */
265 i386nbsd_init_abi (info, gdbarch);
268 i386_elf_init_abi (info, gdbarch);
270 /* NetBSD ELF uses SVR4-style shared libraries. */
271 set_solib_svr4_fetch_link_map_offsets
272 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
274 /* NetBSD ELF uses -fpcc-struct-return by default. */
275 tdep->struct_return = pcc_struct_return;
279 _initialize_i386nbsd_tdep (void)
281 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD_AOUT,
282 i386nbsdaout_init_abi);
283 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD_ELF,
284 i386nbsdelf_init_abi);