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