1*5796c8dcSSimon Schubert /* Target-dependent code for i386 BSD's. 2*5796c8dcSSimon Schubert 3*5796c8dcSSimon Schubert Copyright (C) 2001, 2002, 2003, 2004, 2007, 2008, 2009 4*5796c8dcSSimon Schubert Free Software Foundation, Inc. 5*5796c8dcSSimon Schubert 6*5796c8dcSSimon Schubert This file is part of GDB. 7*5796c8dcSSimon Schubert 8*5796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 9*5796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 10*5796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 11*5796c8dcSSimon Schubert (at your option) any later version. 12*5796c8dcSSimon Schubert 13*5796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 14*5796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 15*5796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*5796c8dcSSimon Schubert GNU General Public License for more details. 17*5796c8dcSSimon Schubert 18*5796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 19*5796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20*5796c8dcSSimon Schubert 21*5796c8dcSSimon Schubert #include "defs.h" 22*5796c8dcSSimon Schubert #include "arch-utils.h" 23*5796c8dcSSimon Schubert #include "frame.h" 24*5796c8dcSSimon Schubert #include "gdbcore.h" 25*5796c8dcSSimon Schubert #include "regcache.h" 26*5796c8dcSSimon Schubert #include "osabi.h" 27*5796c8dcSSimon Schubert 28*5796c8dcSSimon Schubert #include "gdb_string.h" 29*5796c8dcSSimon Schubert 30*5796c8dcSSimon Schubert #include "i386-tdep.h" 31*5796c8dcSSimon Schubert 32*5796c8dcSSimon Schubert /* Support for signal handlers. */ 33*5796c8dcSSimon Schubert 34*5796c8dcSSimon Schubert /* Assuming THIS_FRAME is for a BSD sigtramp routine, return the 35*5796c8dcSSimon Schubert address of the associated sigcontext structure. */ 36*5796c8dcSSimon Schubert 37*5796c8dcSSimon Schubert static CORE_ADDR 38*5796c8dcSSimon Schubert i386bsd_sigcontext_addr (struct frame_info *this_frame) 39*5796c8dcSSimon Schubert { 40*5796c8dcSSimon Schubert struct gdbarch *gdbarch = get_frame_arch (this_frame); 41*5796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 42*5796c8dcSSimon Schubert gdb_byte buf[4]; 43*5796c8dcSSimon Schubert CORE_ADDR sp; 44*5796c8dcSSimon Schubert 45*5796c8dcSSimon Schubert get_frame_register (this_frame, I386_ESP_REGNUM, buf); 46*5796c8dcSSimon Schubert sp = extract_unsigned_integer (buf, 4, byte_order); 47*5796c8dcSSimon Schubert 48*5796c8dcSSimon Schubert return read_memory_unsigned_integer (sp + 8, 4, byte_order); 49*5796c8dcSSimon Schubert } 50*5796c8dcSSimon Schubert 51*5796c8dcSSimon Schubert 52*5796c8dcSSimon Schubert /* Support for shared libraries. */ 53*5796c8dcSSimon Schubert 54*5796c8dcSSimon Schubert /* Traditional BSD (4.3 BSD, still used for BSDI and 386BSD). */ 55*5796c8dcSSimon Schubert 56*5796c8dcSSimon Schubert /* From <machine/signal.h>. */ 57*5796c8dcSSimon Schubert int i386bsd_sc_reg_offset[] = 58*5796c8dcSSimon Schubert { 59*5796c8dcSSimon Schubert -1, /* %eax */ 60*5796c8dcSSimon Schubert -1, /* %ecx */ 61*5796c8dcSSimon Schubert -1, /* %edx */ 62*5796c8dcSSimon Schubert -1, /* %ebx */ 63*5796c8dcSSimon Schubert 8 + 0 * 4, /* %esp */ 64*5796c8dcSSimon Schubert 8 + 1 * 4, /* %ebp */ 65*5796c8dcSSimon Schubert -1, /* %esi */ 66*5796c8dcSSimon Schubert -1, /* %edi */ 67*5796c8dcSSimon Schubert 8 + 3 * 4, /* %eip */ 68*5796c8dcSSimon Schubert 8 + 4 * 4, /* %eflags */ 69*5796c8dcSSimon Schubert -1, /* %cs */ 70*5796c8dcSSimon Schubert -1, /* %ss */ 71*5796c8dcSSimon Schubert -1, /* %ds */ 72*5796c8dcSSimon Schubert -1, /* %es */ 73*5796c8dcSSimon Schubert -1, /* %fs */ 74*5796c8dcSSimon Schubert -1 /* %gs */ 75*5796c8dcSSimon Schubert }; 76*5796c8dcSSimon Schubert 77*5796c8dcSSimon Schubert void 78*5796c8dcSSimon Schubert i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) 79*5796c8dcSSimon Schubert { 80*5796c8dcSSimon Schubert struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 81*5796c8dcSSimon Schubert 82*5796c8dcSSimon Schubert tdep->jb_pc_offset = 0; 83*5796c8dcSSimon Schubert 84*5796c8dcSSimon Schubert tdep->sigtramp_start = 0xfdbfdfc0; 85*5796c8dcSSimon Schubert tdep->sigtramp_end = 0xfdbfe000; 86*5796c8dcSSimon Schubert tdep->sigcontext_addr = i386bsd_sigcontext_addr; 87*5796c8dcSSimon Schubert tdep->sc_reg_offset = i386bsd_sc_reg_offset; 88*5796c8dcSSimon Schubert tdep->sc_num_regs = ARRAY_SIZE (i386bsd_sc_reg_offset); 89*5796c8dcSSimon Schubert } 90*5796c8dcSSimon Schubert 91*5796c8dcSSimon Schubert 92*5796c8dcSSimon Schubert static enum gdb_osabi 93*5796c8dcSSimon Schubert i386bsd_aout_osabi_sniffer (bfd *abfd) 94*5796c8dcSSimon Schubert { 95*5796c8dcSSimon Schubert if (strcmp (bfd_get_target (abfd), "a.out-i386-netbsd") == 0) 96*5796c8dcSSimon Schubert return GDB_OSABI_NETBSD_AOUT; 97*5796c8dcSSimon Schubert 98*5796c8dcSSimon Schubert if (strcmp (bfd_get_target (abfd), "a.out-i386-freebsd") == 0) 99*5796c8dcSSimon Schubert return GDB_OSABI_FREEBSD_AOUT; 100*5796c8dcSSimon Schubert 101*5796c8dcSSimon Schubert return GDB_OSABI_UNKNOWN; 102*5796c8dcSSimon Schubert } 103*5796c8dcSSimon Schubert 104*5796c8dcSSimon Schubert static enum gdb_osabi 105*5796c8dcSSimon Schubert i386bsd_core_osabi_sniffer (bfd *abfd) 106*5796c8dcSSimon Schubert { 107*5796c8dcSSimon Schubert if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0) 108*5796c8dcSSimon Schubert return GDB_OSABI_NETBSD_AOUT; 109*5796c8dcSSimon Schubert 110*5796c8dcSSimon Schubert return GDB_OSABI_UNKNOWN; 111*5796c8dcSSimon Schubert } 112*5796c8dcSSimon Schubert 113*5796c8dcSSimon Schubert 114*5796c8dcSSimon Schubert /* Provide a prototype to silence -Wmissing-prototypes. */ 115*5796c8dcSSimon Schubert void _initialize_i386bsd_tdep (void); 116*5796c8dcSSimon Schubert 117*5796c8dcSSimon Schubert void 118*5796c8dcSSimon Schubert _initialize_i386bsd_tdep (void) 119*5796c8dcSSimon Schubert { 120*5796c8dcSSimon Schubert gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_aout_flavour, 121*5796c8dcSSimon Schubert i386bsd_aout_osabi_sniffer); 122*5796c8dcSSimon Schubert 123*5796c8dcSSimon Schubert /* BFD doesn't set a flavour for NetBSD style a.out core files. */ 124*5796c8dcSSimon Schubert gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_unknown_flavour, 125*5796c8dcSSimon Schubert i386bsd_core_osabi_sniffer); 126*5796c8dcSSimon Schubert } 127