1 /* Target-dependent code for NetBSD/i386.
3 Copyright (C) 1988-1989, 1991-1992, 1994, 1996, 2000-2004, 2007-2012
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 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"
29 #include "trad-frame.h"
30 #include "tramp-frame.h"
32 #include "gdb_assert.h"
33 #include "gdb_string.h"
35 #include "i386-tdep.h"
36 #include "i387-tdep.h"
37 #include "nbsd-tdep.h"
38 #include "solib-svr4.h"
40 /* From <machine/reg.h>. */
41 static int i386nbsd_r_reg_offset[] =
61 /* From <machine/signal.h>. */
62 int i386nbsd_sc_reg_offset[] =
82 /* From <machine/mcontext.h>. */
83 int i386nbsd_mc_reg_offset[] =
103 static void i386nbsd_sigtramp_cache_init (const struct tramp_frame *,
105 struct trad_frame_cache *,
108 static const struct tramp_frame i386nbsd_sigtramp_sc16 =
113 { 0x8d, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x10, -1 },
114 /* leal 0x10(%esp), %eax */
115 { 0x50, -1 }, /* pushl %eax */
116 { 0x50, -1 }, /* pushl %eax */
117 { 0xb8, -1 }, { 0x27, -1 }, {0x01, -1 }, {0x00, -1 }, {0x00, -1 },
118 /* movl $0x127, %eax # __sigreturn14 */
119 { 0xcd, -1 }, { 0x80, -1},
121 { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
122 /* movl $0x1, %eax # exit */
123 { 0xcd, -1 }, { 0x80, -1},
125 { TRAMP_SENTINEL_INSN, -1 }
127 i386nbsd_sigtramp_cache_init
130 static const struct tramp_frame i386nbsd_sigtramp_sc2 =
135 { 0x8d, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x0c, -1 },
136 /* leal 0x0c(%esp), %eax */
137 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
138 /* movl %eax, 0x4(%esp) */
139 { 0xb8, -1 }, { 0x27, -1 }, {0x01, -1 }, {0x00, -1 }, {0x00, -1 },
140 /* movl $0x127, %eax # __sigreturn14 */
141 { 0xcd, -1 }, { 0x80, -1},
143 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
144 /* movl %eax, 0x4(%esp) */
145 { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
146 /* movl $0x1, %eax */
147 { 0xcd, -1 }, { 0x80, -1},
149 { TRAMP_SENTINEL_INSN, -1 }
151 i386nbsd_sigtramp_cache_init
154 static const struct tramp_frame i386nbsd_sigtramp_si2 =
159 { 0x8b, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x08, -1 },
160 /* movl 8(%esp),%eax */
161 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
162 /* movl %eax, 0x4(%esp) */
163 { 0xb8, -1 }, { 0x34, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 },
164 /* movl $0x134, %eax # setcontext */
165 { 0xcd, -1 }, { 0x80, -1 },
167 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
168 /* movl %eax, 0x4(%esp) */
169 { 0xb8, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 }, { 0x00, -1 },
170 /* movl $0x1, %eax */
171 { 0xcd, -1 }, { 0x80, -1 },
173 { TRAMP_SENTINEL_INSN, -1 }
175 i386nbsd_sigtramp_cache_init
178 static const struct tramp_frame i386nbsd_sigtramp_si31 =
183 { 0x8d, -1 }, { 0x84, -1 }, { 0x24, -1 },
184 { 0x8c, -1 }, { 0x00, -1 }, { 0x00, -1 }, { 0x00, -1 },
185 /* leal 0x8c(%esp), %eax */
186 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
187 /* movl %eax, 0x4(%esp) */
188 { 0xb8, -1 }, { 0x34, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 },
189 /* movl $0x134, %eax # setcontext */
190 { 0xcd, -1 }, { 0x80, -1},
192 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
193 /* movl %eax, 0x4(%esp) */
194 { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
195 /* movl $0x1, %eax */
196 { 0xcd, -1 }, { 0x80, -1},
198 { TRAMP_SENTINEL_INSN, -1 }
200 i386nbsd_sigtramp_cache_init
203 static const struct tramp_frame i386nbsd_sigtramp_si4 =
208 { 0x8d, -1 }, { 0x84, -1 }, { 0x24, -1 },
209 { 0x8c, -1 }, { 0x00, -1 }, { 0x00, -1 }, { 0x00, -1 },
210 /* leal 0x8c(%esp), %eax */
211 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
212 /* movl %eax, 0x4(%esp) */
213 { 0xb8, -1 }, { 0x34, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 },
214 /* movl $0x134, %eax # setcontext */
215 { 0xcd, -1 }, { 0x80, -1},
217 { 0xc7, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
218 { 0xff, -1 }, { 0xff, -1 }, { 0xff, -1 }, { 0xff, -1 },
219 /* movl $0xffffffff,0x4(%esp) */
220 { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
221 /* movl $0x1, %eax */
222 { 0xcd, -1 }, { 0x80, -1},
224 { TRAMP_SENTINEL_INSN, -1 }
226 i386nbsd_sigtramp_cache_init
230 i386nbsd_sigtramp_cache_init (const struct tramp_frame *self,
231 struct frame_info *this_frame,
232 struct trad_frame_cache *this_cache,
235 struct gdbarch *gdbarch = get_frame_arch (this_frame);
236 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
237 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
238 CORE_ADDR sp = get_frame_register_unsigned (this_frame, I386_ESP_REGNUM);
244 if (self == &i386nbsd_sigtramp_sc16 || self == &i386nbsd_sigtramp_sc2)
246 reg_offset = i386nbsd_sc_reg_offset;
247 num_regs = ARRAY_SIZE (i386nbsd_sc_reg_offset);
249 /* Read in the sigcontext address. */
250 base = read_memory_unsigned_integer (sp + 8, 4, byte_order);
254 reg_offset = i386nbsd_mc_reg_offset;
255 num_regs = ARRAY_SIZE (i386nbsd_mc_reg_offset);
257 /* Read in the ucontext address. */
258 base = read_memory_unsigned_integer (sp + 8, 4, byte_order);
259 /* offsetof(ucontext_t, uc_mcontext) == 36 */
263 for (i = 0; i < num_regs; i++)
264 if (reg_offset[i] != -1)
265 trad_frame_set_reg_addr (this_cache, i, base + reg_offset[i]);
267 /* Construct the frame ID using the function start. */
268 trad_frame_set_id (this_cache, frame_id_build (sp, func));
273 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
275 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
277 /* Obviously NetBSD is BSD-based. */
278 i386bsd_init_abi (info, gdbarch);
280 /* NetBSD has a different `struct reg'. */
281 tdep->gregset_reg_offset = i386nbsd_r_reg_offset;
282 tdep->gregset_num_regs = ARRAY_SIZE (i386nbsd_r_reg_offset);
283 tdep->sizeof_gregset = 16 * 4;
285 /* NetBSD uses -freg-struct-return by default. */
286 tdep->struct_return = reg_struct_return;
288 /* NetBSD uses tramp_frame sniffers for signal trampolines. */
289 tdep->sigcontext_addr= 0;
290 tdep->sigtramp_start = 0;
291 tdep->sigtramp_end = 0;
292 tdep->sigtramp_p = 0;
293 tdep->sc_reg_offset = 0;
294 tdep->sc_num_regs = 0;
296 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_sc16);
297 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_sc2);
298 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si2);
299 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si31);
300 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si4);
306 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
308 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
310 /* It's still NetBSD. */
311 i386nbsd_init_abi (info, gdbarch);
314 i386_elf_init_abi (info, gdbarch);
316 /* NetBSD ELF uses SVR4-style shared libraries. */
317 set_solib_svr4_fetch_link_map_offsets
318 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
320 /* NetBSD ELF uses -fpcc-struct-return by default. */
321 tdep->struct_return = pcc_struct_return;
324 /* Provide a prototype to silence -Wmissing-prototypes. */
325 extern initialize_file_ftype _initialize_i386nbsd_tdep;
328 _initialize_i386nbsd_tdep (void)
330 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD_ELF,
331 i386nbsdelf_init_abi);