| 1 | /* Target-dependent code for i386 BSD's. |
| 2 | Copyright 2001, 2002, 2003 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 | #include "osabi.h" |
| 27 | |
| 28 | #include "gdb_string.h" |
| 29 | |
| 30 | #include "i386-tdep.h" |
| 31 | |
| 32 | /* Support for signal handlers. */ |
| 33 | |
| 34 | /* Return whether PC is in a BSD sigtramp routine. */ |
| 35 | |
| 36 | static int |
| 37 | i386bsd_pc_in_sigtramp (CORE_ADDR pc, char *name) |
| 38 | { |
| 39 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
| 40 | |
| 41 | return (pc >= tdep->sigtramp_start && pc < tdep->sigtramp_end); |
| 42 | } |
| 43 | |
| 44 | /* Assuming FRAME is for a BSD sigtramp routine, return the address of |
| 45 | the associated sigcontext structure. |
| 46 | |
| 47 | Note: This function is used for Solaris 2 too, so don't make it |
| 48 | static. */ |
| 49 | |
| 50 | CORE_ADDR |
| 51 | i386bsd_sigcontext_addr (struct frame_info *frame) |
| 52 | { |
| 53 | struct frame_info *next_frame = get_next_frame (frame); |
| 54 | |
| 55 | if (next_frame) |
| 56 | /* If this isn't the top frame, the next frame must be for the |
| 57 | signal handler itself. A pointer to the sigcontext structure |
| 58 | is passed as the third argument to the signal handler. */ |
| 59 | return read_memory_unsigned_integer (get_frame_base (next_frame) + 16, 4); |
| 60 | |
| 61 | /* This is the top frame. We'll have to find the address of the |
| 62 | sigcontext structure by looking at the stack pointer. */ |
| 63 | return read_memory_unsigned_integer (read_register (SP_REGNUM) + 8, 4); |
| 64 | } |
| 65 | |
| 66 | /* Return the start address of the sigtramp routine. */ |
| 67 | |
| 68 | CORE_ADDR |
| 69 | i386bsd_sigtramp_start (CORE_ADDR pc) |
| 70 | { |
| 71 | return gdbarch_tdep (current_gdbarch)->sigtramp_start; |
| 72 | } |
| 73 | |
| 74 | /* Return the end address of the sigtramp routine. */ |
| 75 | |
| 76 | CORE_ADDR |
| 77 | i386bsd_sigtramp_end (CORE_ADDR pc) |
| 78 | { |
| 79 | return gdbarch_tdep (current_gdbarch)->sigtramp_end; |
| 80 | } |
| 81 | \f |
| 82 | |
| 83 | /* Support for shared libraries. */ |
| 84 | |
| 85 | /* Return non-zero if we are in a shared library trampoline code stub. */ |
| 86 | |
| 87 | int |
| 88 | i386bsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name) |
| 89 | { |
| 90 | return (name && !strcmp (name, "_DYNAMIC")); |
| 91 | } |
| 92 | |
| 93 | /* Traditional BSD (4.3 BSD, still used for BSDI and 386BSD). */ |
| 94 | |
| 95 | /* From <machine/signal.h>. */ |
| 96 | int i386bsd_sc_pc_offset = 20; |
| 97 | int i386bsd_sc_sp_offset = 8; |
| 98 | |
| 99 | void |
| 100 | i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
| 101 | { |
| 102 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 103 | |
| 104 | set_gdbarch_pc_in_sigtramp (gdbarch, i386bsd_pc_in_sigtramp); |
| 105 | |
| 106 | /* Allow the recognition of sigtramps as a function named <sigtramp>. */ |
| 107 | set_gdbarch_sigtramp_start (gdbarch, i386bsd_sigtramp_start); |
| 108 | set_gdbarch_sigtramp_end (gdbarch, i386bsd_sigtramp_end); |
| 109 | |
| 110 | /* Assume SunOS-style shared libraries. */ |
| 111 | set_gdbarch_in_solib_call_trampoline (gdbarch, |
| 112 | i386bsd_aout_in_solib_call_trampoline); |
| 113 | |
| 114 | tdep->jb_pc_offset = 0; |
| 115 | |
| 116 | tdep->sigtramp_start = 0xfdbfdfc0; |
| 117 | tdep->sigtramp_end = 0xfdbfe000; |
| 118 | tdep->sigcontext_addr = i386bsd_sigcontext_addr; |
| 119 | tdep->sc_pc_offset = i386bsd_sc_pc_offset; |
| 120 | tdep->sc_sp_offset = i386bsd_sc_sp_offset; |
| 121 | } |
| 122 | |
| 123 | /* FreeBSD 3.0-RELEASE or later. */ |
| 124 | |
| 125 | CORE_ADDR i386fbsd_sigtramp_start = 0xbfbfdf20; |
| 126 | CORE_ADDR i386fbsd_sigtramp_end = 0xbfbfdff0; |
| 127 | |
| 128 | static void |
| 129 | i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
| 130 | { |
| 131 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 132 | |
| 133 | /* Obviously FreeBSD is BSD-based. */ |
| 134 | i386bsd_init_abi (info, gdbarch); |
| 135 | |
| 136 | /* FreeBSD uses -freg-struct-return by default. */ |
| 137 | tdep->struct_return = reg_struct_return; |
| 138 | |
| 139 | /* FreeBSD uses a different memory layout. */ |
| 140 | tdep->sigtramp_start = i386fbsd_sigtramp_start; |
| 141 | tdep->sigtramp_end = i386fbsd_sigtramp_end; |
| 142 | } |
| 143 | |
| 144 | static void |
| 145 | i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
| 146 | { |
| 147 | /* It's almost identical to FreeBSD a.out. */ |
| 148 | i386fbsdaout_init_abi (info, gdbarch); |
| 149 | |
| 150 | /* Except that it uses ELF. */ |
| 151 | i386_elf_init_abi (info, gdbarch); |
| 152 | |
| 153 | /* FreeBSD ELF uses SVR4-style shared libraries. */ |
| 154 | set_gdbarch_in_solib_call_trampoline (gdbarch, |
| 155 | generic_in_solib_call_trampoline); |
| 156 | } |
| 157 | |
| 158 | /* FreeBSD 4.0-RELEASE or later. */ |
| 159 | |
| 160 | /* From <machine/signal.h>. */ |
| 161 | int i386fbsd4_sc_pc_offset = 76; |
| 162 | int i386fbsd4_sc_sp_offset = 88; |
| 163 | |
| 164 | static void |
| 165 | i386fbsd4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
| 166 | { |
| 167 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 168 | |
| 169 | /* Inherit stuff from older releases. We assume that FreeBSD |
| 170 | 4.0-RELEASE always uses ELF. */ |
| 171 | i386fbsd_init_abi (info, gdbarch); |
| 172 | |
| 173 | /* FreeBSD 4.0 introduced a new `struct sigcontext'. */ |
| 174 | tdep->sc_pc_offset = i386fbsd4_sc_pc_offset; |
| 175 | tdep->sc_sp_offset = i386fbsd4_sc_sp_offset; |
| 176 | } |
| 177 | |
| 178 | \f |
| 179 | static enum gdb_osabi |
| 180 | i386bsd_aout_osabi_sniffer (bfd *abfd) |
| 181 | { |
| 182 | if (strcmp (bfd_get_target (abfd), "a.out-i386-netbsd") == 0) |
| 183 | return GDB_OSABI_NETBSD_AOUT; |
| 184 | |
| 185 | if (strcmp (bfd_get_target (abfd), "a.out-i386-freebsd") == 0) |
| 186 | return GDB_OSABI_FREEBSD_AOUT; |
| 187 | |
| 188 | return GDB_OSABI_UNKNOWN; |
| 189 | } |
| 190 | |
| 191 | \f |
| 192 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
| 193 | void _initialize_i386bsd_tdep (void); |
| 194 | |
| 195 | void |
| 196 | _initialize_i386bsd_tdep (void) |
| 197 | { |
| 198 | gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_aout_flavour, |
| 199 | i386bsd_aout_osabi_sniffer); |
| 200 | |
| 201 | gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_FREEBSD_AOUT, |
| 202 | i386fbsdaout_init_abi); |
| 203 | gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_FREEBSD_ELF, |
| 204 | i386fbsd4_init_abi); |
| 205 | } |