* config/i386/tm-fbsd.h [!SVR4_SHARED_LIBS]
[binutils-gdb.git] / gdb / i386bsd-tdep.c
1 /* Target-dependent code for i386 BSD's.
2 Copyright 2001, 2002 Free Software Foundation, Inc.
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 "arch-utils.h"
23 #include "frame.h"
24 #include "gdbcore.h"
25 #include "regcache.h"
26
27 #include "i386-tdep.h"
28
29 /* Support for signal handlers. */
30
31 /* Return whether PC is in a BSD sigtramp routine. */
32
33 static int
34 i386bsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
35 {
36 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
37
38 return (pc >= tdep->sigtramp_start && pc < tdep->sigtramp_end);
39 }
40
41 /* Assuming FRAME is for a BSD sigtramp routine, return the address of
42 the associated sigcontext structure. */
43
44 static CORE_ADDR
45 i386bsd_sigcontext_addr (struct frame_info *frame)
46 {
47 if (frame->next)
48 /* If this isn't the top frame, the next frame must be for the
49 signal handler itself. A pointer to the sigcontext structure
50 is passed as the third argument to the signal handler. */
51 return read_memory_unsigned_integer (frame->next->frame + 16, 4);
52
53 /* This is the top frame. We'll have to find the address of the
54 sigcontext structure by looking at the stack pointer. */
55 return read_memory_unsigned_integer (read_register (SP_REGNUM) + 8, 4);
56 }
57
58 /* Assuming FRAME is for a BSD sigtramp routine, return the saved
59 program counter.
60
61 Note: This function is used for Solaris 2 too, so don't make it
62 static. */
63
64 CORE_ADDR
65 i386bsd_sigtramp_saved_pc (struct frame_info *frame)
66 {
67 int sc_pc_offset = gdbarch_tdep (current_gdbarch)->sc_pc_offset;
68 CORE_ADDR addr;
69
70 addr = i386bsd_sigcontext_addr (frame);
71 return read_memory_unsigned_integer (addr + sc_pc_offset, 4);
72 }
73
74 /* Return the saved program counter for FRAME. */
75
76 static CORE_ADDR
77 i386bsd_frame_saved_pc (struct frame_info *frame)
78 {
79 if (frame->signal_handler_caller)
80 return i386bsd_sigtramp_saved_pc (frame);
81
82 return read_memory_unsigned_integer (frame->frame + 4, 4);
83 }
84
85 /* Return the start address of the sigtramp routine. */
86
87 CORE_ADDR
88 i386bsd_sigtramp_start (CORE_ADDR pc)
89 {
90 return gdbarch_tdep (current_gdbarch)->sigtramp_start;
91 }
92
93 /* Return the end address of the sigtramp routine. */
94
95 CORE_ADDR
96 i386bsd_sigtramp_end (CORE_ADDR pc)
97 {
98 return gdbarch_tdep (current_gdbarch)->sigtramp_end;
99 }
100 \f
101
102 /* Support for shared libraries. */
103
104 /* Return non-zero if we are in a shared library trampoline code stub. */
105
106 int
107 i386bsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name)
108 {
109 return (name && !strcmp (name, "_DYNAMIC"));
110 }
111
112 /* Traditional BSD (4.3 BSD, still used for BSDI and 386BSD). */
113
114 /* From <machine/signal.h>. */
115 int i386bsd_sc_pc_offset = 20;
116
117 static void
118 i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
119 {
120 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
121
122 set_gdbarch_pc_in_sigtramp (gdbarch, i386bsd_pc_in_sigtramp);
123
124 /* Assume SunOS-style shared libraries. */
125 set_gdbarch_in_solib_call_trampoline (gdbarch,
126 i386bsd_aout_in_solib_call_trampoline);
127
128 tdep->jb_pc_offset = 0;
129
130 tdep->sigtramp_saved_pc = i386bsd_sigtramp_saved_pc;
131 tdep->sigtramp_start = 0xfdbfdfc0;
132 tdep->sigtramp_end = 0xfdbfe000;
133 tdep->sc_pc_offset = i386bsd_sc_pc_offset;
134 }
135
136 /* NetBSD 1.0 or later. */
137
138 /* From <machine/signal.h>. */
139 int i386nbsd_sc_pc_offset = 44;
140
141 static void
142 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
143 {
144 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
145
146 /* Obviously NetBSD is BSD-based. */
147 i386bsd_init_abi (info, gdbarch);
148
149 /* NetBSD uses -freg-struct-return by default. */
150 tdep->struct_return = reg_struct_return;
151
152 /* NetBSD uses a different memory layout. */
153 tdep->sigtramp_start = 0xbfbfdf20;
154 tdep->sigtramp_end = 0xbfbfdff0;
155
156 /* NetBSD has a `struct sigcontext' that's different from the
157 origional 4.3 BSD. */
158 tdep->sc_pc_offset = i386nbsd_sc_pc_offset;
159 }
160
161 /* NetBSD ELF. */
162 static void
163 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
164 {
165 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
166
167 /* It's still NetBSD. */
168 i386nbsd_init_abi (info, gdbarch);
169
170 /* But ELF-based. */
171 i386_elf_init_abi (info, gdbarch);
172
173 /* NetBSD ELF uses SVR4-style shared libraries. */
174 set_gdbarch_in_solib_call_trampoline (gdbarch,
175 generic_in_solib_call_trampoline);
176
177 /* NetBSD ELF uses -fpcc-struct-return by default. */
178 tdep->struct_return = pcc_struct_return;
179
180 /* We support the SSE registers on NetBSD ELF. */
181 tdep->num_xmm_regs = I386_NUM_XREGS - 1;
182 set_gdbarch_num_regs (gdbarch, I386_NUM_GREGS + I386_NUM_FREGS
183 + I386_NUM_XREGS);
184 }
185
186 /* FreeBSD 3.0-RELEASE or later. */
187
188 CORE_ADDR i386fbsd_sigtramp_start = 0xbfbfdf20;
189 CORE_ADDR i386fbsd_sigtramp_end = 0xbfbfdff0;
190
191 static void
192 i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
193 {
194 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
195
196 /* Obviously FreeBSD is BSD-based. */
197 i386bsd_init_abi (info, gdbarch);
198
199 /* FreeBSD uses -freg-struct-return by default. */
200 tdep->struct_return = reg_struct_return;
201
202 /* FreeBSD uses a different memory layout. */
203 tdep->sigtramp_start = i386fbsd_sigtramp_start;
204 tdep->sigtramp_end = i386fbsd_sigtramp_end;
205 }
206
207 static void
208 i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
209 {
210 /* It's almost identical to FreeBSD a.out. */
211 i386fbsdaout_init_abi (info, gdbarch);
212
213 /* Except that it uses ELF. */
214 i386_elf_init_abi (info, gdbarch);
215
216 /* FreeBSD ELF uses SVR4-style shared libraries. */
217 set_gdbarch_in_solib_call_trampoline (gdbarch,
218 generic_in_solib_call_trampoline);
219 }
220
221 /* FreeBSD 4.0-RELEASE or later. */
222
223 /* From <machine/signal.h>. */
224 int i386fbsd4_sc_pc_offset = 76;
225
226 static void
227 i386fbsd4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
228 {
229 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
230
231 /* Inherit stuff from older releases. We assume that FreeBSD
232 4.0-RELEASE always uses ELF. */
233 i386fbsd_init_abi (info, gdbarch);
234
235 /* FreeBSD 4.0 introduced a new `struct sigcontext'. */
236 tdep->sc_pc_offset = i386fbsd4_sc_pc_offset;
237 }
238
239 \f
240 static enum gdb_osabi
241 i386bsd_aout_osabi_sniffer (bfd *abfd)
242 {
243 if (strcmp (bfd_get_target (abfd), "a.out-i386-netbsd") == 0)
244 return GDB_OSABI_NETBSD_AOUT;
245
246 if (strcmp (bfd_get_target (abfd), "a.out-i386-freebsd") == 0)
247 return GDB_OSABI_FREEBSD_AOUT;
248
249 return GDB_OSABI_UNKNOWN;
250 }
251
252 \f
253 /* Provide a prototype to silence -Wmissing-prototypes. */
254 void _initialize_i386bsd_tdep (void);
255
256 void
257 _initialize_i386bsd_tdep (void)
258 {
259 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_aout_flavour,
260 i386bsd_aout_osabi_sniffer);
261
262 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_NETBSD_AOUT,
263 i386nbsd_init_abi);
264 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_NETBSD_ELF,
265 i386nbsdelf_init_abi);
266 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_FREEBSD_AOUT,
267 i386fbsdaout_init_abi);
268 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_FREEBSD_ELF,
269 i386fbsd4_init_abi);
270 }