* arch-utils.c (gdbarch_info_init): Set osabi to
[external/binutils.git] / gdb / i386obsd-tdep.c
1 /* Target-dependent code for OpenBSD/i386.
2    Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002, 2003
3    Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330,
20    Boston, MA 02111-1307, USA.  */
21
22 #include "defs.h"
23 #include "arch-utils.h"
24 #include "gdbcore.h"
25 #include "regcache.h"
26 #include "osabi.h"
27
28 #include "i386-tdep.h"
29 #include "i387-tdep.h"
30
31 /* Provide a prototype to silence -Wmissing-prototypes.  */
32 void _initialize_i386obsd_tdep (void);
33
34 #define SIZEOF_STRUCT_REG       (16 * 4)
35
36 static void
37 i386obsd_supply_reg (char *regs, int regno)
38 {
39   int i;
40
41   for (i = 0; i <= 15; i++)
42     if (regno == i || regno == -1)
43       supply_register (i, regs + i * 4);
44 }
45
46 static void
47 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
48                       CORE_ADDR ignore)
49 {
50   char *regs, *fsave;
51
52   /* We get everything from one section.  */
53   if (which != 0)
54     return;
55
56   if (core_reg_size < (SIZEOF_STRUCT_REG + 108))
57     {
58       warning ("Wrong size register set in core file.");
59       return;
60     }
61
62   regs = core_reg_sect;
63   fsave = core_reg_sect + SIZEOF_STRUCT_REG;
64
65   /* Integer registers.  */
66   i386obsd_supply_reg (regs, -1);
67
68   /* Floating point registers.  */
69   i387_supply_fsave (fsave);
70 }
71
72 static struct core_fns i386obsd_core_fns =
73 {
74   bfd_target_unknown_flavour,           /* core_flavour */
75   default_check_format,                 /* check_format */
76   default_core_sniffer,                 /* core_sniffer */
77   fetch_core_registers,                 /* core_read_registers */
78   NULL                                  /* next */
79 };
80 \f
81
82 CORE_ADDR i386obsd_sigtramp_start = 0xbfbfdf20;
83 CORE_ADDR i386obsd_sigtramp_end = 0xbfbfdff0;
84
85 /* From <machine/signal.h>.  */
86 int i386obsd_sc_pc_offset = 44;
87 int i386obsd_sc_sp_offset = 56;
88
89 static void 
90 i386obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
91 {
92   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
93
94   /* Obviously OpenBSD is BSD-based.  */
95   i386bsd_init_abi (info, gdbarch);
96
97   /* OpenBSD uses -freg-struct-return by default.  */
98   tdep->struct_return = reg_struct_return;
99
100   /* OpenBSD uses a different memory layout.  */
101   tdep->sigtramp_start = i386obsd_sigtramp_start;
102   tdep->sigtramp_end = i386obsd_sigtramp_end;
103
104   /* OpenBSD has a `struct sigcontext' that's different from the
105      origional 4.3 BSD.  */
106   tdep->sc_pc_offset = i386obsd_sc_pc_offset;
107   tdep->sc_sp_offset = i386obsd_sc_sp_offset;
108 }
109
110 void
111 _initialize_i386obsd_tdep (void)
112 {
113   add_core_fns (&i386obsd_core_fns);
114
115   /* FIXME: kettenis/20021020: Since OpenBSD/i386 binaries are
116      indistingushable from NetBSD/i386 a.out binaries, building a GDB
117      that should support both these targets will probably not work as
118      expected.  */
119 #define GDB_OSABI_OPENBSD_AOUT GDB_OSABI_NETBSD_AOUT
120
121   gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_OPENBSD_AOUT,
122                           i386obsd_init_abi);
123 }