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 "gdb_string.h"
29 #include "i386-tdep.h"
31 /* Support for signal handlers. */
33 /* Return whether PC is in a BSD sigtramp routine. */
36 i386bsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
38 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
40 return (pc >= tdep->sigtramp_start && pc < tdep->sigtramp_end);
43 /* Assuming FRAME is for a BSD sigtramp routine, return the address of
44 the associated sigcontext structure.
46 Note: This function is used for Solaris 2 too, so don't make it
50 i386bsd_sigcontext_addr (struct frame_info *frame)
53 /* If this isn't the top frame, the next frame must be for the
54 signal handler itself. A pointer to the sigcontext structure
55 is passed as the third argument to the signal handler. */
56 return read_memory_unsigned_integer (frame->next->frame + 16, 4);
58 /* This is the top frame. We'll have to find the address of the
59 sigcontext structure by looking at the stack pointer. */
60 return read_memory_unsigned_integer (read_register (SP_REGNUM) + 8, 4);
63 /* Return the start address of the sigtramp routine. */
66 i386bsd_sigtramp_start (CORE_ADDR pc)
68 return gdbarch_tdep (current_gdbarch)->sigtramp_start;
71 /* Return the end address of the sigtramp routine. */
74 i386bsd_sigtramp_end (CORE_ADDR pc)
76 return gdbarch_tdep (current_gdbarch)->sigtramp_end;
80 /* Support for shared libraries. */
82 /* Return non-zero if we are in a shared library trampoline code stub. */
85 i386bsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name)
87 return (name && !strcmp (name, "_DYNAMIC"));
90 /* Traditional BSD (4.3 BSD, still used for BSDI and 386BSD). */
92 /* From <machine/signal.h>. */
93 int i386bsd_sc_pc_offset = 20;
94 int i386bsd_sc_sp_offset = 8;
97 i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
99 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
101 set_gdbarch_pc_in_sigtramp (gdbarch, i386bsd_pc_in_sigtramp);
103 /* Allow the recognition of sigtramps as a function named <sigtramp>. */
104 set_gdbarch_sigtramp_start (gdbarch, i386bsd_sigtramp_start);
105 set_gdbarch_sigtramp_end (gdbarch, i386bsd_sigtramp_end);
107 /* Assume SunOS-style shared libraries. */
108 set_gdbarch_in_solib_call_trampoline (gdbarch,
109 i386bsd_aout_in_solib_call_trampoline);
111 tdep->jb_pc_offset = 0;
113 tdep->sigtramp_start = 0xfdbfdfc0;
114 tdep->sigtramp_end = 0xfdbfe000;
115 tdep->sigcontext_addr = i386bsd_sigcontext_addr;
116 tdep->sc_pc_offset = i386bsd_sc_pc_offset;
117 tdep->sc_sp_offset = i386bsd_sc_sp_offset;
120 /* FreeBSD 3.0-RELEASE or later. */
122 CORE_ADDR i386fbsd_sigtramp_start = 0xbfbfdf20;
123 CORE_ADDR i386fbsd_sigtramp_end = 0xbfbfdff0;
126 i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
128 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
130 /* Obviously FreeBSD is BSD-based. */
131 i386bsd_init_abi (info, gdbarch);
133 /* FreeBSD uses -freg-struct-return by default. */
134 tdep->struct_return = reg_struct_return;
136 /* FreeBSD uses a different memory layout. */
137 tdep->sigtramp_start = i386fbsd_sigtramp_start;
138 tdep->sigtramp_end = i386fbsd_sigtramp_end;
142 i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
144 /* It's almost identical to FreeBSD a.out. */
145 i386fbsdaout_init_abi (info, gdbarch);
147 /* Except that it uses ELF. */
148 i386_elf_init_abi (info, gdbarch);
150 /* FreeBSD ELF uses SVR4-style shared libraries. */
151 set_gdbarch_in_solib_call_trampoline (gdbarch,
152 generic_in_solib_call_trampoline);
155 /* FreeBSD 4.0-RELEASE or later. */
157 /* From <machine/signal.h>. */
158 int i386fbsd4_sc_pc_offset = 76;
159 int i386fbsd4_sc_sp_offset = 88;
162 i386fbsd4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
164 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
166 /* Inherit stuff from older releases. We assume that FreeBSD
167 4.0-RELEASE always uses ELF. */
168 i386fbsd_init_abi (info, gdbarch);
170 /* FreeBSD 4.0 introduced a new `struct sigcontext'. */
171 tdep->sc_pc_offset = i386fbsd4_sc_pc_offset;
172 tdep->sc_sp_offset = i386fbsd4_sc_sp_offset;
176 static enum gdb_osabi
177 i386bsd_aout_osabi_sniffer (bfd *abfd)
179 if (strcmp (bfd_get_target (abfd), "a.out-i386-netbsd") == 0)
180 return GDB_OSABI_NETBSD_AOUT;
182 if (strcmp (bfd_get_target (abfd), "a.out-i386-freebsd") == 0)
183 return GDB_OSABI_FREEBSD_AOUT;
185 return GDB_OSABI_UNKNOWN;
189 /* Provide a prototype to silence -Wmissing-prototypes. */
190 void _initialize_i386bsd_tdep (void);
193 _initialize_i386bsd_tdep (void)
195 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_aout_flavour,
196 i386bsd_aout_osabi_sniffer);
198 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_FREEBSD_AOUT,
199 i386fbsdaout_init_abi);
200 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_FREEBSD_ELF,