* i386obsd-tdep.c (i386obsd_aout_regset_from_core_section): Make
[external/binutils.git] / gdb / i386obsd-tdep.c
1 /* Target-dependent code for OpenBSD/i386.
2
3    Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002, 2003
4    Free Software Foundation, Inc.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.  */
22
23 #include "defs.h"
24 #include "arch-utils.h"
25 #include "gdbcore.h"
26 #include "regcache.h"
27 #include "regset.h"
28 #include "osabi.h"
29
30 #include "gdb_assert.h"
31 #include "gdb_string.h"
32
33 #include "i386-tdep.h"
34 #include "i387-tdep.h"
35
36 /* From <machine/reg.h>.  */
37 static int i386obsd_r_reg_offset[] =
38 {
39   0 * 4,                        /* %eax */
40   1 * 4,                        /* %ecx */
41   2 * 4,                        /* %edx */
42   3 * 4,                        /* %ebx */
43   4 * 4,                        /* %esp */
44   5 * 4,                        /* %ebp */
45   6 * 4,                        /* %esi */
46   7 * 4,                        /* %edi */
47   8 * 4,                        /* %eip */
48   9 * 4,                        /* %eflags */
49   10 * 4,                       /* %cs */
50   11 * 4,                       /* %ss */
51   12 * 4,                       /* %ds */
52   13 * 4,                       /* %es */
53   14 * 4,                       /* %fs */
54   15 * 4                        /* %gs */
55 };
56
57 static void
58 i386obsd_aout_supply_regset (const struct regset *regset,
59                              struct regcache *regcache, int regnum,
60                              const void *regs, size_t len)
61 {
62   const struct gdbarch_tdep *tdep = regset->descr;
63
64   gdb_assert (len >= tdep->sizeof_gregset + I387_SIZEOF_FSAVE);
65
66   i386_supply_gregset (regset, regcache, regnum, regs, tdep->sizeof_gregset);
67   i387_supply_fsave (regcache, regnum, (char *) regs + tdep->sizeof_gregset);
68 }
69
70 static const struct regset *
71 i386obsd_aout_regset_from_core_section (struct gdbarch *gdbarch,
72                                         const char *sect_name,
73                                         size_t sect_size)
74 {
75   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
76
77   /* OpenBSD a.out core dumps don't use seperate register sets for the
78      general-purpose and floating-point registers.  */
79
80   if (strcmp (sect_name, ".reg") == 0
81       && sect_size >= tdep->sizeof_gregset + I387_SIZEOF_FSAVE)
82     {
83       if (tdep->gregset == NULL)
84         {
85           tdep->gregset = XMALLOC (struct regset);
86           tdep->gregset->descr = tdep;
87           tdep->gregset->supply_regset = i386obsd_aout_supply_regset;
88         }
89       return tdep->gregset;
90     }
91
92   return NULL;
93 }
94 \f
95
96 CORE_ADDR i386obsd_sigtramp_start = 0xbfbfdf20;
97 CORE_ADDR i386obsd_sigtramp_end = 0xbfbfdff0;
98
99 /* From <machine/signal.h>.  */
100 int i386obsd_sc_reg_offset[I386_NUM_GREGS] =
101 {
102   10 * 4,                       /* %eax */
103   9 * 4,                        /* %ecx */
104   8 * 4,                        /* %edx */
105   7 * 4,                        /* %ebx */
106   14 * 4,                       /* %esp */
107   6 * 4,                        /* %ebp */
108   5 * 4,                        /* %esi */
109   4 * 4,                        /* %edi */
110   11 * 4,                       /* %eip */
111   13 * 4,                       /* %eflags */
112   12 * 4,                       /* %cs */
113   15 * 4,                       /* %ss */
114   3 * 4,                        /* %ds */
115   2 * 4,                        /* %es */
116   1 * 4,                        /* %fs */
117   0 * 4                         /* %gs */
118 };
119
120 static void 
121 i386obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
122 {
123   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
124
125   /* Obviously OpenBSD is BSD-based.  */
126   i386bsd_init_abi (info, gdbarch);
127
128   /* OpenBSD has a different `struct reg'.  */
129   tdep->gregset_reg_offset = i386obsd_r_reg_offset;
130   tdep->gregset_num_regs = ARRAY_SIZE (i386obsd_r_reg_offset);
131   tdep->sizeof_gregset = 16 * 4;
132
133   /* OpenBSD has a single register set.  */
134   set_gdbarch_regset_from_core_section
135     (gdbarch, i386obsd_aout_regset_from_core_section);
136
137   /* OpenBSD uses -freg-struct-return by default.  */
138   tdep->struct_return = reg_struct_return;
139
140   /* OpenBSD uses a different memory layout.  */
141   tdep->sigtramp_start = i386obsd_sigtramp_start;
142   tdep->sigtramp_end = i386obsd_sigtramp_end;
143
144   /* OpenBSD has a `struct sigcontext' that's different from the
145      origional 4.3 BSD.  */
146   tdep->sc_reg_offset = i386obsd_sc_reg_offset;
147   tdep->sc_num_regs = ARRAY_SIZE (i386obsd_sc_reg_offset);
148 }
149 \f
150
151 /* Provide a prototype to silence -Wmissing-prototypes.  */
152 void _initialize_i386obsd_tdep (void);
153
154 void
155 _initialize_i386obsd_tdep (void)
156 {
157   /* FIXME: kettenis/20021020: Since OpenBSD/i386 binaries are
158      indistingushable from NetBSD/i386 a.out binaries, building a GDB
159      that should support both these targets will probably not work as
160      expected.  */
161 #define GDB_OSABI_OPENBSD_AOUT GDB_OSABI_NETBSD_AOUT
162
163   gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_OPENBSD_AOUT,
164                           i386obsd_init_abi);
165 }