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