1 /* Target-dependent code for i386 BSD's.
2 Copyright 2001, 2002 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
22 #include "arch-utils.h"
27 #include "i386-tdep.h"
29 /* Support for signal handlers. */
31 /* Return whether PC is in a BSD sigtramp routine. */
34 i386bsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
36 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
38 return (pc >= tdep->sigtramp_start && pc < tdep->sigtramp_end);
41 /* Assuming FRAME is for a BSD sigtramp routine, return the address of
42 the associated sigcontext structure.
44 Note: This function is used for Solaris 2 too, so don't make it
48 i386bsd_sigcontext_addr (struct frame_info *frame)
51 /* If this isn't the top frame, the next frame must be for the
52 signal handler itself. A pointer to the sigcontext structure
53 is passed as the third argument to the signal handler. */
54 return read_memory_unsigned_integer (frame->next->frame + 16, 4);
56 /* This is the top frame. We'll have to find the address of the
57 sigcontext structure by looking at the stack pointer. */
58 return read_memory_unsigned_integer (read_register (SP_REGNUM) + 8, 4);
61 /* Return the start address of the sigtramp routine. */
64 i386bsd_sigtramp_start (CORE_ADDR pc)
66 return gdbarch_tdep (current_gdbarch)->sigtramp_start;
69 /* Return the end address of the sigtramp routine. */
72 i386bsd_sigtramp_end (CORE_ADDR pc)
74 return gdbarch_tdep (current_gdbarch)->sigtramp_end;
78 /* Support for shared libraries. */
80 /* Return non-zero if we are in a shared library trampoline code stub. */
83 i386bsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name)
85 return (name && !strcmp (name, "_DYNAMIC"));
88 /* Traditional BSD (4.3 BSD, still used for BSDI and 386BSD). */
90 /* From <machine/signal.h>. */
91 int i386bsd_sc_pc_offset = 20;
92 int i386bsd_sc_sp_offset = 8;
95 i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
97 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
99 set_gdbarch_pc_in_sigtramp (gdbarch, i386bsd_pc_in_sigtramp);
101 /* Assume SunOS-style shared libraries. */
102 set_gdbarch_in_solib_call_trampoline (gdbarch,
103 i386bsd_aout_in_solib_call_trampoline);
105 tdep->jb_pc_offset = 0;
107 tdep->sigtramp_start = 0xfdbfdfc0;
108 tdep->sigtramp_end = 0xfdbfe000;
109 tdep->sigcontext_addr = i386bsd_sigcontext_addr;
110 tdep->sc_pc_offset = i386bsd_sc_pc_offset;
111 tdep->sc_sp_offset = i386bsd_sc_sp_offset;
114 /* NetBSD 1.0 or later. */
116 /* From <machine/signal.h>. */
117 int i386nbsd_sc_pc_offset = 44;
118 int i386nbsd_sc_sp_offset = 56;
121 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
123 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
125 /* Obviously NetBSD is BSD-based. */
126 i386bsd_init_abi (info, gdbarch);
128 /* NetBSD uses -freg-struct-return by default. */
129 tdep->struct_return = reg_struct_return;
131 /* NetBSD uses a different memory layout. */
132 tdep->sigtramp_start = 0xbfbfdf20;
133 tdep->sigtramp_end = 0xbfbfdff0;
135 /* NetBSD has a `struct sigcontext' that's different from the
136 origional 4.3 BSD. */
137 tdep->sc_pc_offset = i386nbsd_sc_pc_offset;
138 tdep->sc_sp_offset = i386nbsd_sc_sp_offset;
143 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
145 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
147 /* It's still NetBSD. */
148 i386nbsd_init_abi (info, gdbarch);
151 i386_elf_init_abi (info, gdbarch);
153 /* NetBSD ELF uses SVR4-style shared libraries. */
154 set_gdbarch_in_solib_call_trampoline (gdbarch,
155 generic_in_solib_call_trampoline);
157 /* NetBSD ELF uses -fpcc-struct-return by default. */
158 tdep->struct_return = pcc_struct_return;
160 /* We support the SSE registers on NetBSD ELF. */
161 tdep->num_xmm_regs = I386_NUM_XREGS - 1;
162 set_gdbarch_num_regs (gdbarch, I386_NUM_GREGS + I386_NUM_FREGS
166 /* FreeBSD 3.0-RELEASE or later. */
168 CORE_ADDR i386fbsd_sigtramp_start = 0xbfbfdf20;
169 CORE_ADDR i386fbsd_sigtramp_end = 0xbfbfdff0;
172 i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
174 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
176 /* Obviously FreeBSD is BSD-based. */
177 i386bsd_init_abi (info, gdbarch);
179 /* FreeBSD uses -freg-struct-return by default. */
180 tdep->struct_return = reg_struct_return;
182 /* FreeBSD uses a different memory layout. */
183 tdep->sigtramp_start = i386fbsd_sigtramp_start;
184 tdep->sigtramp_end = i386fbsd_sigtramp_end;
188 i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
190 /* It's almost identical to FreeBSD a.out. */
191 i386fbsdaout_init_abi (info, gdbarch);
193 /* Except that it uses ELF. */
194 i386_elf_init_abi (info, gdbarch);
196 /* FreeBSD ELF uses SVR4-style shared libraries. */
197 set_gdbarch_in_solib_call_trampoline (gdbarch,
198 generic_in_solib_call_trampoline);
201 /* FreeBSD 4.0-RELEASE or later. */
203 /* From <machine/signal.h>. */
204 int i386fbsd4_sc_pc_offset = 76;
205 int i386fbsd4_sc_sp_offset = 88;
208 i386fbsd4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
210 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
212 /* Inherit stuff from older releases. We assume that FreeBSD
213 4.0-RELEASE always uses ELF. */
214 i386fbsd_init_abi (info, gdbarch);
216 /* FreeBSD 4.0 introduced a new `struct sigcontext'. */
217 tdep->sc_pc_offset = i386fbsd4_sc_pc_offset;
218 tdep->sc_sp_offset = i386fbsd4_sc_sp_offset;
222 static enum gdb_osabi
223 i386bsd_aout_osabi_sniffer (bfd *abfd)
225 if (strcmp (bfd_get_target (abfd), "a.out-i386-netbsd") == 0)
226 return GDB_OSABI_NETBSD_AOUT;
228 if (strcmp (bfd_get_target (abfd), "a.out-i386-freebsd") == 0)
229 return GDB_OSABI_FREEBSD_AOUT;
231 return GDB_OSABI_UNKNOWN;
235 /* Provide a prototype to silence -Wmissing-prototypes. */
236 void _initialize_i386bsd_tdep (void);
239 _initialize_i386bsd_tdep (void)
241 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_aout_flavour,
242 i386bsd_aout_osabi_sniffer);
244 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_NETBSD_AOUT,
246 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_NETBSD_ELF,
247 i386nbsdelf_init_abi);
248 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_FREEBSD_AOUT,
249 i386fbsdaout_init_abi);
250 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_FREEBSD_ELF,