1 /* Target-dependent code for NetBSD/i386.
3 Copyright (C) 1988-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
28 #include "trad-frame.h"
29 #include "tramp-frame.h"
31 #include "i386-tdep.h"
32 #include "i387-tdep.h"
33 #include "nbsd-tdep.h"
34 #include "solib-svr4.h"
36 /* From <machine/reg.h>. */
37 static int i386nbsd_r_reg_offset[] =
57 /* From <machine/signal.h>. */
58 int i386nbsd_sc_reg_offset[] =
78 /* From <machine/mcontext.h>. */
79 int i386nbsd_mc_reg_offset[] =
99 static void i386nbsd_sigtramp_cache_init (const struct tramp_frame *,
101 struct trad_frame_cache *,
104 static const struct tramp_frame i386nbsd_sigtramp_sc16 =
109 /* leal 0x10(%esp), %eax */
110 { 0x8d, ULONGEST_MAX },
111 { 0x44, ULONGEST_MAX },
112 { 0x24, ULONGEST_MAX },
113 { 0x10, ULONGEST_MAX },
116 { 0x50, ULONGEST_MAX },
119 { 0x50, ULONGEST_MAX },
121 /* movl $0x127, %eax # __sigreturn14 */
122 { 0xb8, ULONGEST_MAX },
123 { 0x27, ULONGEST_MAX },
124 {0x01, ULONGEST_MAX },
125 {0x00, ULONGEST_MAX },
126 {0x00, ULONGEST_MAX },
129 { 0xcd, ULONGEST_MAX },
130 { 0x80, ULONGEST_MAX},
132 /* movl $0x1, %eax # exit */
133 { 0xb8, ULONGEST_MAX },
134 { 0x01, ULONGEST_MAX },
135 {0x00, ULONGEST_MAX },
136 {0x00, ULONGEST_MAX },
137 {0x00, ULONGEST_MAX },
140 { 0xcd, ULONGEST_MAX },
141 { 0x80, ULONGEST_MAX},
143 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
145 i386nbsd_sigtramp_cache_init
148 static const struct tramp_frame i386nbsd_sigtramp_sc2 =
153 /* leal 0x0c(%esp), %eax */
154 { 0x8d, ULONGEST_MAX },
155 { 0x44, ULONGEST_MAX },
156 { 0x24, ULONGEST_MAX },
157 { 0x0c, ULONGEST_MAX },
158 /* movl %eax, 0x4(%esp) */
159 { 0x89, ULONGEST_MAX },
160 { 0x44, ULONGEST_MAX },
161 { 0x24, ULONGEST_MAX },
162 { 0x04, ULONGEST_MAX },
163 /* movl $0x127, %eax # __sigreturn14 */
164 { 0xb8, ULONGEST_MAX },
165 { 0x27, ULONGEST_MAX },
166 {0x01, ULONGEST_MAX },
167 {0x00, ULONGEST_MAX },
168 {0x00, ULONGEST_MAX },
170 { 0xcd, ULONGEST_MAX },
171 { 0x80, ULONGEST_MAX},
172 /* movl %eax, 0x4(%esp) */
173 { 0x89, ULONGEST_MAX },
174 { 0x44, ULONGEST_MAX },
175 { 0x24, ULONGEST_MAX },
176 { 0x04, ULONGEST_MAX },
177 /* movl $0x1, %eax */
178 { 0xb8, ULONGEST_MAX },
179 { 0x01, ULONGEST_MAX },
180 {0x00, ULONGEST_MAX },
181 {0x00, ULONGEST_MAX },
182 {0x00, ULONGEST_MAX },
184 { 0xcd, ULONGEST_MAX },
185 { 0x80, ULONGEST_MAX},
186 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
188 i386nbsd_sigtramp_cache_init
191 static const struct tramp_frame i386nbsd_sigtramp_si2 =
196 /* movl 8(%esp),%eax */
197 { 0x8b, ULONGEST_MAX },
198 { 0x44, ULONGEST_MAX },
199 { 0x24, ULONGEST_MAX },
200 { 0x08, ULONGEST_MAX },
201 /* movl %eax, 0x4(%esp) */
202 { 0x89, ULONGEST_MAX },
203 { 0x44, ULONGEST_MAX },
204 { 0x24, ULONGEST_MAX },
205 { 0x04, ULONGEST_MAX },
206 /* movl $0x134, %eax # setcontext */
207 { 0xb8, ULONGEST_MAX },
208 { 0x34, ULONGEST_MAX },
209 { 0x01, ULONGEST_MAX },
210 { 0x00, ULONGEST_MAX },
211 { 0x00, ULONGEST_MAX },
213 { 0xcd, ULONGEST_MAX },
214 { 0x80, ULONGEST_MAX },
215 /* movl %eax, 0x4(%esp) */
216 { 0x89, ULONGEST_MAX },
217 { 0x44, ULONGEST_MAX },
218 { 0x24, ULONGEST_MAX },
219 { 0x04, ULONGEST_MAX },
220 /* movl $0x1, %eax */
221 { 0xb8, ULONGEST_MAX },
222 { 0x01, ULONGEST_MAX },
223 { 0x00, ULONGEST_MAX },
224 { 0x00, ULONGEST_MAX },
225 { 0x00, ULONGEST_MAX },
227 { 0xcd, ULONGEST_MAX },
228 { 0x80, ULONGEST_MAX },
229 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
231 i386nbsd_sigtramp_cache_init
234 static const struct tramp_frame i386nbsd_sigtramp_si31 =
239 /* leal 0x8c(%esp), %eax */
240 { 0x8d, ULONGEST_MAX },
241 { 0x84, ULONGEST_MAX },
242 { 0x24, ULONGEST_MAX },
243 { 0x8c, ULONGEST_MAX },
244 { 0x00, ULONGEST_MAX },
245 { 0x00, ULONGEST_MAX },
246 { 0x00, ULONGEST_MAX },
247 /* movl %eax, 0x4(%esp) */
248 { 0x89, ULONGEST_MAX },
249 { 0x44, ULONGEST_MAX },
250 { 0x24, ULONGEST_MAX },
251 { 0x04, ULONGEST_MAX },
252 /* movl $0x134, %eax # setcontext */
253 { 0xb8, ULONGEST_MAX },
254 { 0x34, ULONGEST_MAX },
255 { 0x01, ULONGEST_MAX },
256 { 0x00, ULONGEST_MAX },
257 { 0x00, ULONGEST_MAX },
259 { 0xcd, ULONGEST_MAX },
260 { 0x80, ULONGEST_MAX},
261 /* movl %eax, 0x4(%esp) */
262 { 0x89, ULONGEST_MAX },
263 { 0x44, ULONGEST_MAX },
264 { 0x24, ULONGEST_MAX },
265 { 0x04, ULONGEST_MAX },
266 /* movl $0x1, %eax */
267 { 0xb8, ULONGEST_MAX },
268 { 0x01, ULONGEST_MAX },
269 {0x00, ULONGEST_MAX },
270 {0x00, ULONGEST_MAX },
271 {0x00, ULONGEST_MAX },
273 { 0xcd, ULONGEST_MAX },
274 { 0x80, ULONGEST_MAX},
275 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
277 i386nbsd_sigtramp_cache_init
280 static const struct tramp_frame i386nbsd_sigtramp_si4 =
285 /* leal 0x8c(%esp), %eax */
286 { 0x8d, ULONGEST_MAX },
287 { 0x84, ULONGEST_MAX },
288 { 0x24, ULONGEST_MAX },
289 { 0x8c, ULONGEST_MAX },
290 { 0x00, ULONGEST_MAX },
291 { 0x00, ULONGEST_MAX },
292 { 0x00, ULONGEST_MAX },
293 /* movl %eax, 0x4(%esp) */
294 { 0x89, ULONGEST_MAX },
295 { 0x44, ULONGEST_MAX },
296 { 0x24, ULONGEST_MAX },
297 { 0x04, ULONGEST_MAX },
298 /* movl $0x134, %eax # setcontext */
299 { 0xb8, ULONGEST_MAX },
300 { 0x34, ULONGEST_MAX },
301 { 0x01, ULONGEST_MAX },
302 { 0x00, ULONGEST_MAX },
303 { 0x00, ULONGEST_MAX },
305 { 0xcd, ULONGEST_MAX },
306 { 0x80, ULONGEST_MAX},
307 /* movl $0xffffffff,0x4(%esp) */
308 { 0xc7, ULONGEST_MAX },
309 { 0x44, ULONGEST_MAX },
310 { 0x24, ULONGEST_MAX },
311 { 0x04, ULONGEST_MAX },
312 { 0xff, ULONGEST_MAX },
313 { 0xff, ULONGEST_MAX },
314 { 0xff, ULONGEST_MAX },
315 { 0xff, ULONGEST_MAX },
316 /* movl $0x1, %eax */
317 { 0xb8, ULONGEST_MAX },
318 { 0x01, ULONGEST_MAX },
319 {0x00, ULONGEST_MAX },
320 {0x00, ULONGEST_MAX },
321 {0x00, ULONGEST_MAX },
323 { 0xcd, ULONGEST_MAX },
324 { 0x80, ULONGEST_MAX},
325 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
327 i386nbsd_sigtramp_cache_init
331 i386nbsd_sigtramp_cache_init (const struct tramp_frame *self,
332 struct frame_info *this_frame,
333 struct trad_frame_cache *this_cache,
336 struct gdbarch *gdbarch = get_frame_arch (this_frame);
337 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
338 CORE_ADDR sp = get_frame_register_unsigned (this_frame, I386_ESP_REGNUM);
344 if (self == &i386nbsd_sigtramp_sc16 || self == &i386nbsd_sigtramp_sc2)
346 reg_offset = i386nbsd_sc_reg_offset;
347 num_regs = ARRAY_SIZE (i386nbsd_sc_reg_offset);
349 /* Read in the sigcontext address. */
350 base = read_memory_unsigned_integer (sp + 8, 4, byte_order);
354 reg_offset = i386nbsd_mc_reg_offset;
355 num_regs = ARRAY_SIZE (i386nbsd_mc_reg_offset);
357 /* Read in the ucontext address. */
358 base = read_memory_unsigned_integer (sp + 8, 4, byte_order);
359 /* offsetof(ucontext_t, uc_mcontext) == 36 */
363 for (i = 0; i < num_regs; i++)
364 if (reg_offset[i] != -1)
365 trad_frame_set_reg_addr (this_cache, i, base + reg_offset[i]);
367 /* Construct the frame ID using the function start. */
368 trad_frame_set_id (this_cache, frame_id_build (sp, func));
373 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
375 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
377 /* Obviously NetBSD is BSD-based. */
378 i386bsd_init_abi (info, gdbarch);
380 /* NetBSD has a different `struct reg'. */
381 tdep->gregset_reg_offset = i386nbsd_r_reg_offset;
382 tdep->gregset_num_regs = ARRAY_SIZE (i386nbsd_r_reg_offset);
383 tdep->sizeof_gregset = 16 * 4;
385 /* NetBSD uses -freg-struct-return by default. */
386 tdep->struct_return = reg_struct_return;
388 /* NetBSD uses tramp_frame sniffers for signal trampolines. */
389 tdep->sigcontext_addr= 0;
390 tdep->sigtramp_start = 0;
391 tdep->sigtramp_end = 0;
392 tdep->sigtramp_p = 0;
393 tdep->sc_reg_offset = 0;
394 tdep->sc_num_regs = 0;
396 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_sc16);
397 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_sc2);
398 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si2);
399 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si31);
400 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si4);
406 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
408 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
410 /* It's still NetBSD. */
411 i386nbsd_init_abi (info, gdbarch);
414 i386_elf_init_abi (info, gdbarch);
416 /* NetBSD ELF uses SVR4-style shared libraries. */
417 set_solib_svr4_fetch_link_map_offsets
418 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
420 /* NetBSD ELF uses -fpcc-struct-return by default. */
421 tdep->struct_return = pcc_struct_return;
425 _initialize_i386nbsd_tdep (void)
427 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD,
428 i386nbsdelf_init_abi);