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[] =
59 /* Under NetBSD/i386, signal handler invocations can be identified by the
60 designated code sequence that is used to return from a signal handler.
61 In particular, the return address of a signal handler points to the
62 following code sequence:
67 movl $0x127, %eax # __sigreturn14
70 Each instruction has a unique encoding, so we simply attempt to match
71 the instruction the PC is pointing to with any of the above instructions.
72 If there is a hit, we know the offset to the start of the designated
73 sequence and can then check whether we really are executing in the
74 signal trampoline. If not, -1 is returned, otherwise the offset from the
75 start of the return sequence is returned. */
76 #define RETCODE_INSN1 0x8d
77 #define RETCODE_INSN2 0x50
78 #define RETCODE_INSN3 0x50
79 #define RETCODE_INSN4 0xb8
80 #define RETCODE_INSN5 0xcd
82 #define RETCODE_INSN2_OFF 4
83 #define RETCODE_INSN3_OFF 5
84 #define RETCODE_INSN4_OFF 6
85 #define RETCODE_INSN5_OFF 11
87 static const unsigned char sigtramp_retcode[] =
89 RETCODE_INSN1, 0x44, 0x24, 0x10,
92 RETCODE_INSN4, 0x27, 0x01, 0x00, 0x00,
97 i386nbsd_sigtramp_offset (struct frame_info *next_frame)
99 CORE_ADDR pc = frame_pc_unwind (next_frame);
100 unsigned char ret[sizeof(sigtramp_retcode)], insn;
104 if (!safe_frame_unwind_memory (next_frame, pc, &insn, 1))
114 /* INSN2 and INSN3 are the same. Read at the location of PC+1
115 to determine if we're actually looking at INSN2 or INSN3. */
116 if (!safe_frame_unwind_memory (next_frame, pc + 1, &insn, 1))
119 if (insn == RETCODE_INSN3)
120 off = RETCODE_INSN2_OFF;
122 off = RETCODE_INSN3_OFF;
126 off = RETCODE_INSN4_OFF;
130 off = RETCODE_INSN5_OFF;
139 if (!safe_frame_unwind_memory (next_frame, pc, ret, sizeof (ret)))
142 if (memcmp (ret, sigtramp_retcode, sizeof (ret)) == 0)
148 /* Return whether the frame preceding NEXT_FRAME corresponds to a
149 NetBSD sigtramp routine. */
152 i386nbsd_sigtramp_p (struct frame_info *next_frame)
154 CORE_ADDR pc = frame_pc_unwind (next_frame);
157 find_pc_partial_function (pc, &name, NULL, NULL);
158 return (nbsd_pc_in_sigtramp (pc, name)
159 || i386nbsd_sigtramp_offset (next_frame) >= 0);
162 /* From <machine/signal.h>. */
163 int i386nbsd_sc_reg_offset[] =
174 13 * 4, /* %eflags */
184 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
186 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
188 /* Obviously NetBSD is BSD-based. */
189 i386bsd_init_abi (info, gdbarch);
191 /* NetBSD has a different `struct reg'. */
192 tdep->gregset_reg_offset = i386nbsd_r_reg_offset;
193 tdep->gregset_num_regs = ARRAY_SIZE (i386nbsd_r_reg_offset);
194 tdep->sizeof_gregset = 16 * 4;
196 /* NetBSD has different signal trampoline conventions. */
197 tdep->sigtramp_start = 0;
198 tdep->sigtramp_end = 0;
199 tdep->sigtramp_p = i386nbsd_sigtramp_p;
201 /* NetBSD uses -freg-struct-return by default. */
202 tdep->struct_return = reg_struct_return;
204 /* NetBSD has a `struct sigcontext' that's different from the
206 tdep->sc_reg_offset = i386nbsd_sc_reg_offset;
207 tdep->sc_num_regs = ARRAY_SIZE (i386nbsd_sc_reg_offset);
213 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
215 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
217 /* It's still NetBSD. */
218 i386nbsd_init_abi (info, gdbarch);
221 i386_elf_init_abi (info, gdbarch);
223 /* NetBSD ELF uses SVR4-style shared libraries. */
224 set_solib_svr4_fetch_link_map_offsets
225 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
227 /* NetBSD ELF uses -fpcc-struct-return by default. */
228 tdep->struct_return = pcc_struct_return;
232 _initialize_i386nbsd_tdep (void)
234 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD_ELF,
235 i386nbsdelf_init_abi);