* top.c (print_gdb_version): Update copyright year.
[deliverable/binutils-gdb.git] / gdb / i386nbsd-tdep.c
CommitLineData
ed504bdf
MK
1/* Target-dependent code for NetBSD/i386.
2
6aba47ca 3 Copyright (C) 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002, 2003,
9b254dd1 4 2004, 2007, 2008 Free Software Foundation, Inc.
0fc93e6b
C
5
6 This file is part of GDB.
7
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
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
0fc93e6b
C
11 (at your option) any later version.
12
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.
17
18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
0fc93e6b
C
20
21#include "defs.h"
13739f4d 22#include "arch-utils.h"
911bc6ee 23#include "frame.h"
dfe6eb1f
JT
24#include "gdbcore.h"
25#include "regcache.h"
13739f4d 26#include "regset.h"
4be87837 27#include "osabi.h"
911bc6ee 28#include "symtab.h"
70f13f6b
MK
29#include "trad-frame.h"
30#include "tramp-frame.h"
0fc93e6b 31
13739f4d
MK
32#include "gdb_assert.h"
33#include "gdb_string.h"
34
3cac699e 35#include "i386-tdep.h"
dfe6eb1f 36#include "i387-tdep.h"
3cac699e 37#include "nbsd-tdep.h"
7d400e77
JT
38#include "solib-svr4.h"
39
13739f4d
MK
40/* From <machine/reg.h>. */
41static int i386nbsd_r_reg_offset[] =
dfe6eb1f 42{
13739f4d
MK
43 0 * 4, /* %eax */
44 1 * 4, /* %ecx */
45 2 * 4, /* %edx */
46 3 * 4, /* %ebx */
47 4 * 4, /* %esp */
48 5 * 4, /* %ebp */
49 6 * 4, /* %esi */
50 7 * 4, /* %edi */
51 8 * 4, /* %eip */
52 9 * 4, /* %eflags */
53 10 * 4, /* %cs */
54 11 * 4, /* %ss */
55 12 * 4, /* %ds */
56 13 * 4, /* %es */
57 14 * 4, /* %fs */
58 15 * 4 /* %gs */
dfe6eb1f
JT
59};
60
3cac699e 61/* From <machine/signal.h>. */
13739f4d 62int i386nbsd_sc_reg_offset[] =
a3386186
MK
63{
64 10 * 4, /* %eax */
65 9 * 4, /* %ecx */
66 8 * 4, /* %edx */
67 7 * 4, /* %ebx */
68 14 * 4, /* %esp */
69 6 * 4, /* %ebp */
70 5 * 4, /* %esi */
71 4 * 4, /* %edi */
72 11 * 4, /* %eip */
73 13 * 4, /* %eflags */
74 12 * 4, /* %cs */
75 15 * 4, /* %ss */
76 3 * 4, /* %ds */
77 2 * 4, /* %es */
78 1 * 4, /* %fs */
79 0 * 4 /* %gs */
80};
3cac699e 81
70f13f6b
MK
82/* From <machine/mcontext.h>. */
83int i386nbsd_mc_reg_offset[] =
84{
85 11 * 4, /* %eax */
86 10 * 4, /* %ecx */
87 9 * 4, /* %edx */
88 8 * 4, /* %ebx */
89 7 * 4, /* %esp */
90 6 * 4, /* %ebp */
91 5 * 4, /* %esi */
92 4 * 4, /* %edi */
93 14 * 4, /* %eip */
94 16 * 4, /* %eflags */
95 15 * 4, /* %cs */
96 18 * 4, /* %ss */
97 3 * 4, /* %ds */
98 2 * 4, /* %es */
99 1 * 4, /* %fs */
100 0 * 4 /* %gs */
101};
102
103static void i386nbsd_sigtramp_cache_init (const struct tramp_frame *,
104 struct frame_info *,
105 struct trad_frame_cache *,
106 CORE_ADDR);
107
108static const struct tramp_frame i386nbsd_sigtramp_sc16 =
109{
110 SIGTRAMP_FRAME,
111 1,
112 {
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},
120 /* int $0x80 */
121 { 0xb8, -1 }, { 0x01, -1 }, {0x00, -1 }, {0x00, -1 }, {0x00, -1 },
122 /* movl $0x1, %eax # exit */
123 { 0xcd, -1 }, { 0x80, -1},
124 /* int $0x80 */
125 { TRAMP_SENTINEL_INSN, -1 }
126 },
127 i386nbsd_sigtramp_cache_init
128};
129
130static const struct tramp_frame i386nbsd_sigtramp_sc2 =
131{
132 SIGTRAMP_FRAME,
133 1,
134 {
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},
142 /* int $0x80 */
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},
148 /* int $0x80 */
149 { TRAMP_SENTINEL_INSN, -1 }
150 },
151 i386nbsd_sigtramp_cache_init
152};
153
154static const struct tramp_frame i386nbsd_sigtramp_si2 =
155{
156 SIGTRAMP_FRAME,
157 1,
158 {
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 },
166 /* int $0x80 */
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 },
172 /* int $0x80 */
173 { TRAMP_SENTINEL_INSN, -1 }
174 },
175 i386nbsd_sigtramp_cache_init
176};
177
178static const struct tramp_frame i386nbsd_sigtramp_si31 =
179{
180 SIGTRAMP_FRAME,
181 1,
182 {
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},
191 /* int $0x80 */
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},
197 /* int $0x80 */
198 { TRAMP_SENTINEL_INSN, -1 }
199 },
200 i386nbsd_sigtramp_cache_init
201};
202
203static const struct tramp_frame i386nbsd_sigtramp_si4 =
204{
205 SIGTRAMP_FRAME,
206 1,
207 {
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},
216 /* int $0x80 */
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},
223 /* int $0x80 */
224 { TRAMP_SENTINEL_INSN, -1 }
225 },
226 i386nbsd_sigtramp_cache_init
227};
228
229static void
230i386nbsd_sigtramp_cache_init (const struct tramp_frame *self,
10458914
DJ
231 struct frame_info *this_frame,
232 struct trad_frame_cache *this_cache,
233 CORE_ADDR func)
70f13f6b 234{
10458914 235 struct gdbarch *gdbarch = get_frame_arch (this_frame);
70f13f6b 236 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
10458914 237 CORE_ADDR sp = get_frame_register_unsigned (this_frame, I386_ESP_REGNUM);
70f13f6b
MK
238 CORE_ADDR base;
239 int *reg_offset;
240 int num_regs;
241 int i;
242
243 if (self == &i386nbsd_sigtramp_sc16 || self == &i386nbsd_sigtramp_sc2)
244 {
245 reg_offset = i386nbsd_sc_reg_offset;
246 num_regs = ARRAY_SIZE (i386nbsd_sc_reg_offset);
247
248 /* Read in the sigcontext address */
249 base = read_memory_unsigned_integer (sp + 8, 4);
250 }
251 else
252 {
253 reg_offset = i386nbsd_mc_reg_offset;
254 num_regs = ARRAY_SIZE (i386nbsd_mc_reg_offset);
255
256 /* Read in the ucontext address */
257 base = read_memory_unsigned_integer (sp + 8, 4);
258 /* offsetof(ucontext_t, uc_mcontext) == 36 */
259 base += 36;
260 }
261
262 for (i = 0; i < num_regs; i++)
263 if (reg_offset[i] != -1)
264 trad_frame_set_reg_addr (this_cache, i, base + reg_offset[i]);
265
266 /* Construct the frame ID using the function start. */
267 trad_frame_set_id (this_cache, frame_id_build (sp, func));
268}
269\f
270
3cac699e
JT
271static void
272i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
273{
274 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
275
276 /* Obviously NetBSD is BSD-based. */
277 i386bsd_init_abi (info, gdbarch);
278
13739f4d
MK
279 /* NetBSD has a different `struct reg'. */
280 tdep->gregset_reg_offset = i386nbsd_r_reg_offset;
281 tdep->gregset_num_regs = ARRAY_SIZE (i386nbsd_r_reg_offset);
282 tdep->sizeof_gregset = 16 * 4;
283
3cac699e
JT
284 /* NetBSD uses -freg-struct-return by default. */
285 tdep->struct_return = reg_struct_return;
286
70f13f6b
MK
287 /* NetBSD uses tramp_frame sniffers for signal trampolines. */
288 tdep->sigcontext_addr= 0;
289 tdep->sigtramp_start = 0;
290 tdep->sigtramp_end = 0;
291 tdep->sigtramp_p = 0;
292 tdep->sc_reg_offset = 0;
293 tdep->sc_num_regs = 0;
294
295 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_sc16);
296 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_sc2);
297 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si2);
298 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si31);
299 tramp_frame_prepend_unwinder (gdbarch, &i386nbsd_sigtramp_si4);
13739f4d
MK
300}
301
3cac699e 302/* NetBSD ELF. */
13739f4d 303
3cac699e
JT
304static void
305i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
306{
307 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
308
309 /* It's still NetBSD. */
310 i386nbsd_init_abi (info, gdbarch);
311
312 /* But ELF-based. */
313 i386_elf_init_abi (info, gdbarch);
314
315 /* NetBSD ELF uses SVR4-style shared libraries. */
13739f4d 316 set_solib_svr4_fetch_link_map_offsets
7e654c37 317 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
3cac699e
JT
318
319 /* NetBSD ELF uses -fpcc-struct-return by default. */
320 tdep->struct_return = pcc_struct_return;
3cac699e
JT
321}
322
dfe6eb1f
JT
323void
324_initialize_i386nbsd_tdep (void)
325{
05816f70 326 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETBSD_ELF,
3cac699e 327 i386nbsdelf_init_abi);
dfe6eb1f 328}
This page took 0.606581 seconds and 4 git commands to generate.