* macrotab.h: Do not include "obstack.h" or "bcache.h".
[deliverable/binutils-gdb.git] / gdb / i386bsd-tdep.c
CommitLineData
b7247919 1/* Target-dependent code for i386 BSD's.
8201327c 2 Copyright 2001, 2002 Free Software Foundation, Inc.
b7247919
MK
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21#include "defs.h"
22#include "frame.h"
23#include "gdbcore.h"
24#include "regcache.h"
25
8201327c 26#include "i386-tdep.h"
b7247919 27
8201327c 28/* Support for signal handlers. */
b7247919
MK
29
30/* Return whether PC is in a BSD sigtramp routine. */
31
8201327c
MK
32static int
33i386bsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
b7247919 34{
8201327c 35 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
b7247919 36
8201327c
MK
37 return (pc >= tdep->sigtramp_start && pc < tdep->sigtramp_end);
38}
b7247919
MK
39
40/* Assuming FRAME is for a BSD sigtramp routine, return the address of
41 the associated sigcontext structure. */
42
43static CORE_ADDR
44i386bsd_sigcontext_addr (struct frame_info *frame)
45{
46 if (frame->next)
47 /* If this isn't the top frame, the next frame must be for the
48 signal handler itself. A pointer to the sigcontext structure
49 is passed as the third argument to the signal handler. */
50 return read_memory_unsigned_integer (frame->next->frame + 16, 4);
51
52 /* This is the top frame. We'll have to find the address of the
53 sigcontext structure by looking at the stack pointer. */
54 return read_memory_unsigned_integer (read_register (SP_REGNUM) + 8, 4);
55}
56
57/* Assuming FRAME is for a BSD sigtramp routine, return the saved
8201327c 58 program counter.
b7247919 59
8201327c
MK
60 Note: This function is used for Solaris 2 too, so don't make it
61 static. */
62
63CORE_ADDR
b7247919
MK
64i386bsd_sigtramp_saved_pc (struct frame_info *frame)
65{
8201327c 66 int sc_pc_offset = gdbarch_tdep (current_gdbarch)->sc_pc_offset;
b7247919 67 CORE_ADDR addr;
8201327c 68
b7247919 69 addr = i386bsd_sigcontext_addr (frame);
8201327c 70 return read_memory_unsigned_integer (addr + sc_pc_offset, 4);
b7247919
MK
71}
72
73/* Return the saved program counter for FRAME. */
74
8201327c 75static CORE_ADDR
b7247919
MK
76i386bsd_frame_saved_pc (struct frame_info *frame)
77{
78 if (frame->signal_handler_caller)
79 return i386bsd_sigtramp_saved_pc (frame);
80
81 return read_memory_unsigned_integer (frame->frame + 4, 4);
82}
8201327c
MK
83
84/* Return the start address of the sigtramp routine. */
85
86CORE_ADDR
87i386bsd_sigtramp_start (CORE_ADDR pc)
88{
89 return gdbarch_tdep (current_gdbarch)->sigtramp_start;
90}
91
92/* Return the end address of the sigtramp routine. */
93
94CORE_ADDR
95i386bsd_sigtramp_end (CORE_ADDR pc)
96{
97 return gdbarch_tdep (current_gdbarch)->sigtramp_end;
98}
99\f
100
101/* Traditional BSD (4.3 BSD, still used for BSDI and 386BSD). */
102
103/* From <machine/signal.h>. */
104int i386bsd_sc_pc_offset = 20;
105
106static void
107i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
108{
109 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
110
111 set_gdbarch_pc_in_sigtramp (gdbarch, i386bsd_pc_in_sigtramp);
112
113 tdep->jb_pc_offset = 0;
114
115 tdep->sigtramp_saved_pc = i386bsd_sigtramp_saved_pc;
116 tdep->sigtramp_start = 0xfdbfdfc0;
117 tdep->sigtramp_end = 0xfdbfe000;
118 tdep->sc_pc_offset = i386bsd_sc_pc_offset;
119}
120
121/* NetBSD 1.0 or later. */
122
123/* From <machine/signal.h>. */
124int i386nbsd_sc_pc_offset = 44;
125
126static void
127i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
128{
129 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
130
131 /* Obviously NetBSD is BSD-based. */
132 i386bsd_init_abi (info, gdbarch);
133
134 /* NetBSD uses -freg-struct-return by default. */
135 tdep->struct_return = reg_struct_return;
136
137 /* NetBSD uses a different memory layout. */
138 tdep->sigtramp_start = 0xbfbfdf20;
139 tdep->sigtramp_end = 0xbfbfdff0;
140
141 /* NetBSD has a `struct sigcontext' that's different from the
142 origional 4.3 BSD. */
143 tdep->sc_pc_offset = i386nbsd_sc_pc_offset;
144}
145
146/* NetBSD ELF. */
147static void
148i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
149{
150 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
151
152 /* It's still NetBSD. */
153 i386nbsd_init_abi (info, gdbarch);
154
155 /* But ELF-based. */
156 i386_elf_init_abi (info, gdbarch);
157
158 /* NetBSD ELF uses -fpcc-struct-return by default. */
159 tdep->struct_return = pcc_struct_return;
160
161 /* We support the SSE registers on NetBSD ELF. */
162 tdep->num_xmm_regs = I386_NUM_XREGS - 1;
163 set_gdbarch_num_regs (gdbarch, I386_NUM_GREGS + I386_NUM_FREGS
164 + I386_NUM_XREGS);
165}
166
167/* FreeBSD 3.0-RELEASE or later. */
168
169CORE_ADDR i386fbsd_sigtramp_start = 0xbfbfdf20;
170CORE_ADDR i386fbsd_sigtramp_end = 0xbfbfdff0;
171
172static void
173i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
174{
175 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
176
177 /* Obviously FreeBSD is BSD-based. */
178 i386bsd_init_abi (info, gdbarch);
179
180 /* FreeBSD uses -freg-struct-return by default. */
181 tdep->struct_return = reg_struct_return;
182
183 /* FreeBSD uses a different memory layout. */
184 tdep->sigtramp_start = i386fbsd_sigtramp_start;
185 tdep->sigtramp_end = i386fbsd_sigtramp_end;
186}
187
188static void
189i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
190{
191 /* It's almost identical to FreeBSD a.out. */
192 i386fbsdaout_init_abi (info, gdbarch);
193
194 /* Except that it uses ELF. */
195 i386_elf_init_abi (info, gdbarch);
196}
197
198/* FreeBSD 4.0-RELEASE or later. */
199
200/* From <machine/signal.h>. */
201int i386fbsd4_sc_pc_offset = 76;
202
203static void
204i386fbsd4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
205{
206 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
207
208 /* Inherit stuff from older releases. We assume that FreeBSD
209 4.0-RELEASE always uses ELF. */
210 i386fbsd_init_abi (info, gdbarch);
211
212 /* FreeBSD 4.0 introduced a new `struct sigcontext'. */
213 tdep->sc_pc_offset = i386fbsd4_sc_pc_offset;
214}
215
216\f
217static enum gdb_osabi
218i386bsd_aout_osabi_sniffer (bfd *abfd)
219{
220 if (strcmp (bfd_get_target (abfd), "a.out-i386-netbsd") == 0)
221 return GDB_OSABI_NETBSD_AOUT;
222
223 if (strcmp (bfd_get_target (abfd), "a.out-i386-freebsd") == 0)
224 return GDB_OSABI_FREEBSD_AOUT;
225
226 return GDB_OSABI_UNKNOWN;
227}
228
229\f
230/* Provide a prototype to silence -Wmissing-prototypes. */
231void _initialize_i386bsd_tdep (void);
232
233void
234_initialize_i386bsd_tdep (void)
235{
236 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_aout_flavour,
237 i386bsd_aout_osabi_sniffer);
238
239 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_NETBSD_AOUT,
240 i386nbsd_init_abi);
241 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_NETBSD_ELF,
242 i386nbsdelf_init_abi);
243 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_FREEBSD_AOUT,
244 i386fbsdaout_init_abi);
245 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_FREEBSD_ELF,
246 i386fbsd4_init_abi);
247}
This page took 0.136043 seconds and 4 git commands to generate.