1 /* Target-dependent code for NetBSD/i386.
3 Copyright (C) 1988-2017 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 { 0x8d, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x10, -1 },
110 /* leal 0x10(%esp), %eax */
111 { 0x50, -1 }, /* pushl %eax */
112 { 0x50, -1 }, /* pushl %eax */
113 { 0xb8, -1 }, { 0x27, -1 }, {0x01, -1 }, {0x00, -1 }, {0x00, -1 },
114 /* movl $0x127, %eax # __sigreturn14 */
115 { 0xcd, -1 }, { 0x80, -1},
117 { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
118 /* movl $0x1, %eax # exit */
119 { 0xcd, -1 }, { 0x80, -1},
121 { TRAMP_SENTINEL_INSN
, -1 }
123 i386nbsd_sigtramp_cache_init
126 static const struct tramp_frame i386nbsd_sigtramp_sc2
=
131 { 0x8d, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x0c, -1 },
132 /* leal 0x0c(%esp), %eax */
133 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
134 /* movl %eax, 0x4(%esp) */
135 { 0xb8, -1 }, { 0x27, -1 }, {0x01, -1 }, {0x00, -1 }, {0x00, -1 },
136 /* movl $0x127, %eax # __sigreturn14 */
137 { 0xcd, -1 }, { 0x80, -1},
139 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
140 /* movl %eax, 0x4(%esp) */
141 { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
142 /* movl $0x1, %eax */
143 { 0xcd, -1 }, { 0x80, -1},
145 { TRAMP_SENTINEL_INSN
, -1 }
147 i386nbsd_sigtramp_cache_init
150 static const struct tramp_frame i386nbsd_sigtramp_si2
=
155 { 0x8b, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x08, -1 },
156 /* movl 8(%esp),%eax */
157 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
158 /* movl %eax, 0x4(%esp) */
159 { 0xb8, -1 }, { 0x34, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 },
160 /* movl $0x134, %eax # setcontext */
161 { 0xcd, -1 }, { 0x80, -1 },
163 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
164 /* movl %eax, 0x4(%esp) */
165 { 0xb8, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 }, { 0x00, -1 },
166 /* movl $0x1, %eax */
167 { 0xcd, -1 }, { 0x80, -1 },
169 { TRAMP_SENTINEL_INSN
, -1 }
171 i386nbsd_sigtramp_cache_init
174 static const struct tramp_frame i386nbsd_sigtramp_si31
=
179 { 0x8d, -1 }, { 0x84, -1 }, { 0x24, -1 },
180 { 0x8c, -1 }, { 0x00, -1 }, { 0x00, -1 }, { 0x00, -1 },
181 /* leal 0x8c(%esp), %eax */
182 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
183 /* movl %eax, 0x4(%esp) */
184 { 0xb8, -1 }, { 0x34, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 },
185 /* movl $0x134, %eax # setcontext */
186 { 0xcd, -1 }, { 0x80, -1},
188 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
189 /* movl %eax, 0x4(%esp) */
190 { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
191 /* movl $0x1, %eax */
192 { 0xcd, -1 }, { 0x80, -1},
194 { TRAMP_SENTINEL_INSN
, -1 }
196 i386nbsd_sigtramp_cache_init
199 static const struct tramp_frame i386nbsd_sigtramp_si4
=
204 { 0x8d, -1 }, { 0x84, -1 }, { 0x24, -1 },
205 { 0x8c, -1 }, { 0x00, -1 }, { 0x00, -1 }, { 0x00, -1 },
206 /* leal 0x8c(%esp), %eax */
207 { 0x89, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
208 /* movl %eax, 0x4(%esp) */
209 { 0xb8, -1 }, { 0x34, -1 }, { 0x01, -1 }, { 0x00, -1 }, { 0x00, -1 },
210 /* movl $0x134, %eax # setcontext */
211 { 0xcd, -1 }, { 0x80, -1},
213 { 0xc7, -1 }, { 0x44, -1 }, { 0x24, -1 }, { 0x04, -1 },
214 { 0xff, -1 }, { 0xff, -1 }, { 0xff, -1 }, { 0xff, -1 },
215 /* movl $0xffffffff,0x4(%esp) */
216 { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
217 /* movl $0x1, %eax */
218 { 0xcd, -1 }, { 0x80, -1},
220 { TRAMP_SENTINEL_INSN
, -1 }
222 i386nbsd_sigtramp_cache_init
226 i386nbsd_sigtramp_cache_init (const struct tramp_frame
*self
,
227 struct frame_info
*this_frame
,
228 struct trad_frame_cache
*this_cache
,
231 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
232 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
233 CORE_ADDR sp
= get_frame_register_unsigned (this_frame
, I386_ESP_REGNUM
);
239 if (self
== &i386nbsd_sigtramp_sc16
|| self
== &i386nbsd_sigtramp_sc2
)
241 reg_offset
= i386nbsd_sc_reg_offset
;
242 num_regs
= ARRAY_SIZE (i386nbsd_sc_reg_offset
);
244 /* Read in the sigcontext address. */
245 base
= read_memory_unsigned_integer (sp
+ 8, 4, byte_order
);
249 reg_offset
= i386nbsd_mc_reg_offset
;
250 num_regs
= ARRAY_SIZE (i386nbsd_mc_reg_offset
);
252 /* Read in the ucontext address. */
253 base
= read_memory_unsigned_integer (sp
+ 8, 4, byte_order
);
254 /* offsetof(ucontext_t, uc_mcontext) == 36 */
258 for (i
= 0; i
< num_regs
; i
++)
259 if (reg_offset
[i
] != -1)
260 trad_frame_set_reg_addr (this_cache
, i
, base
+ reg_offset
[i
]);
262 /* Construct the frame ID using the function start. */
263 trad_frame_set_id (this_cache
, frame_id_build (sp
, func
));
268 i386nbsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
270 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
272 /* Obviously NetBSD is BSD-based. */
273 i386bsd_init_abi (info
, gdbarch
);
275 /* NetBSD has a different `struct reg'. */
276 tdep
->gregset_reg_offset
= i386nbsd_r_reg_offset
;
277 tdep
->gregset_num_regs
= ARRAY_SIZE (i386nbsd_r_reg_offset
);
278 tdep
->sizeof_gregset
= 16 * 4;
280 /* NetBSD uses -freg-struct-return by default. */
281 tdep
->struct_return
= reg_struct_return
;
283 /* NetBSD uses tramp_frame sniffers for signal trampolines. */
284 tdep
->sigcontext_addr
= 0;
285 tdep
->sigtramp_start
= 0;
286 tdep
->sigtramp_end
= 0;
287 tdep
->sigtramp_p
= 0;
288 tdep
->sc_reg_offset
= 0;
289 tdep
->sc_num_regs
= 0;
291 tramp_frame_prepend_unwinder (gdbarch
, &i386nbsd_sigtramp_sc16
);
292 tramp_frame_prepend_unwinder (gdbarch
, &i386nbsd_sigtramp_sc2
);
293 tramp_frame_prepend_unwinder (gdbarch
, &i386nbsd_sigtramp_si2
);
294 tramp_frame_prepend_unwinder (gdbarch
, &i386nbsd_sigtramp_si31
);
295 tramp_frame_prepend_unwinder (gdbarch
, &i386nbsd_sigtramp_si4
);
301 i386nbsdelf_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
303 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
305 /* It's still NetBSD. */
306 i386nbsd_init_abi (info
, gdbarch
);
309 i386_elf_init_abi (info
, gdbarch
);
311 /* NetBSD ELF uses SVR4-style shared libraries. */
312 set_solib_svr4_fetch_link_map_offsets
313 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
315 /* NetBSD ELF uses -fpcc-struct-return by default. */
316 tdep
->struct_return
= pcc_struct_return
;
320 _initialize_i386nbsd_tdep (void)
322 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_NETBSD
,
323 i386nbsdelf_init_abi
);