xref: /dflybsd-src/contrib/gdb-7/gdb/i386bsd-tdep.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Target-dependent code for i386 BSD's.
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 2001-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "arch-utils.h"
225796c8dcSSimon Schubert #include "frame.h"
235796c8dcSSimon Schubert #include "gdbcore.h"
245796c8dcSSimon Schubert #include "regcache.h"
255796c8dcSSimon Schubert #include "osabi.h"
265796c8dcSSimon Schubert 
275796c8dcSSimon Schubert #include "gdb_string.h"
285796c8dcSSimon Schubert 
295796c8dcSSimon Schubert #include "i386-tdep.h"
305796c8dcSSimon Schubert 
315796c8dcSSimon Schubert /* Support for signal handlers.  */
325796c8dcSSimon Schubert 
335796c8dcSSimon Schubert /* Assuming THIS_FRAME is for a BSD sigtramp routine, return the
345796c8dcSSimon Schubert    address of the associated sigcontext structure.  */
355796c8dcSSimon Schubert 
365796c8dcSSimon Schubert static CORE_ADDR
i386bsd_sigcontext_addr(struct frame_info * this_frame)375796c8dcSSimon Schubert i386bsd_sigcontext_addr (struct frame_info *this_frame)
385796c8dcSSimon Schubert {
395796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (this_frame);
405796c8dcSSimon Schubert   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
415796c8dcSSimon Schubert   gdb_byte buf[4];
425796c8dcSSimon Schubert   CORE_ADDR sp;
435796c8dcSSimon Schubert 
445796c8dcSSimon Schubert   get_frame_register (this_frame, I386_ESP_REGNUM, buf);
455796c8dcSSimon Schubert   sp = extract_unsigned_integer (buf, 4, byte_order);
465796c8dcSSimon Schubert 
475796c8dcSSimon Schubert   return read_memory_unsigned_integer (sp + 8, 4, byte_order);
485796c8dcSSimon Schubert }
495796c8dcSSimon Schubert 
505796c8dcSSimon Schubert 
515796c8dcSSimon Schubert /* Support for shared libraries.  */
525796c8dcSSimon Schubert 
535796c8dcSSimon Schubert /* Traditional BSD (4.3 BSD, still used for BSDI and 386BSD).  */
545796c8dcSSimon Schubert 
555796c8dcSSimon Schubert /* From <machine/signal.h>.  */
565796c8dcSSimon Schubert int i386bsd_sc_reg_offset[] =
575796c8dcSSimon Schubert {
585796c8dcSSimon Schubert   -1,				/* %eax */
595796c8dcSSimon Schubert   -1,				/* %ecx */
605796c8dcSSimon Schubert   -1,				/* %edx */
615796c8dcSSimon Schubert   -1,				/* %ebx */
625796c8dcSSimon Schubert   8 + 0 * 4,			/* %esp */
635796c8dcSSimon Schubert   8 + 1 * 4,			/* %ebp */
645796c8dcSSimon Schubert   -1,				/* %esi */
655796c8dcSSimon Schubert   -1,				/* %edi */
665796c8dcSSimon Schubert   8 + 3 * 4,			/* %eip */
675796c8dcSSimon Schubert   8 + 4 * 4,			/* %eflags */
685796c8dcSSimon Schubert   -1,				/* %cs */
695796c8dcSSimon Schubert   -1,				/* %ss */
705796c8dcSSimon Schubert   -1,				/* %ds */
715796c8dcSSimon Schubert   -1,				/* %es */
725796c8dcSSimon Schubert   -1,				/* %fs */
735796c8dcSSimon Schubert   -1				/* %gs */
745796c8dcSSimon Schubert };
755796c8dcSSimon Schubert 
765796c8dcSSimon Schubert void
i386bsd_init_abi(struct gdbarch_info info,struct gdbarch * gdbarch)775796c8dcSSimon Schubert i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
785796c8dcSSimon Schubert {
795796c8dcSSimon Schubert   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
805796c8dcSSimon Schubert 
815796c8dcSSimon Schubert   tdep->jb_pc_offset = 0;
825796c8dcSSimon Schubert 
835796c8dcSSimon Schubert   tdep->sigtramp_start = 0xfdbfdfc0;
845796c8dcSSimon Schubert   tdep->sigtramp_end = 0xfdbfe000;
855796c8dcSSimon Schubert   tdep->sigcontext_addr = i386bsd_sigcontext_addr;
865796c8dcSSimon Schubert   tdep->sc_reg_offset = i386bsd_sc_reg_offset;
875796c8dcSSimon Schubert   tdep->sc_num_regs = ARRAY_SIZE (i386bsd_sc_reg_offset);
885796c8dcSSimon Schubert }
895796c8dcSSimon Schubert 
905796c8dcSSimon Schubert 
915796c8dcSSimon Schubert static enum gdb_osabi
i386bsd_aout_osabi_sniffer(bfd * abfd)925796c8dcSSimon Schubert i386bsd_aout_osabi_sniffer (bfd *abfd)
935796c8dcSSimon Schubert {
945796c8dcSSimon Schubert   if (strcmp (bfd_get_target (abfd), "a.out-i386-netbsd") == 0)
955796c8dcSSimon Schubert     return GDB_OSABI_NETBSD_AOUT;
965796c8dcSSimon Schubert 
975796c8dcSSimon Schubert   if (strcmp (bfd_get_target (abfd), "a.out-i386-freebsd") == 0)
985796c8dcSSimon Schubert     return GDB_OSABI_FREEBSD_AOUT;
995796c8dcSSimon Schubert 
1005796c8dcSSimon Schubert   return GDB_OSABI_UNKNOWN;
1015796c8dcSSimon Schubert }
1025796c8dcSSimon Schubert 
1035796c8dcSSimon Schubert static enum gdb_osabi
i386bsd_core_osabi_sniffer(bfd * abfd)1045796c8dcSSimon Schubert i386bsd_core_osabi_sniffer (bfd *abfd)
1055796c8dcSSimon Schubert {
1065796c8dcSSimon Schubert   if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0)
1075796c8dcSSimon Schubert     return GDB_OSABI_NETBSD_AOUT;
1085796c8dcSSimon Schubert 
1095796c8dcSSimon Schubert   return GDB_OSABI_UNKNOWN;
1105796c8dcSSimon Schubert }
1115796c8dcSSimon Schubert 
1125796c8dcSSimon Schubert 
1135796c8dcSSimon Schubert /* Provide a prototype to silence -Wmissing-prototypes.  */
1145796c8dcSSimon Schubert void _initialize_i386bsd_tdep (void);
1155796c8dcSSimon Schubert 
1165796c8dcSSimon Schubert void
_initialize_i386bsd_tdep(void)1175796c8dcSSimon Schubert _initialize_i386bsd_tdep (void)
1185796c8dcSSimon Schubert {
1195796c8dcSSimon Schubert   gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_aout_flavour,
1205796c8dcSSimon Schubert 				  i386bsd_aout_osabi_sniffer);
1215796c8dcSSimon Schubert 
1225796c8dcSSimon Schubert   /* BFD doesn't set a flavour for NetBSD style a.out core files.  */
1235796c8dcSSimon Schubert   gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_unknown_flavour,
1245796c8dcSSimon Schubert 				  i386bsd_core_osabi_sniffer);
1255796c8dcSSimon Schubert }
126