2004-02-15 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / i386obsd-tdep.c
CommitLineData
005328e3 1/* Target-dependent code for OpenBSD/i386.
67457012 2
4be87837 3 Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002, 2003
005328e3
MK
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"
67457012 27#include "regset.h"
4be87837 28#include "osabi.h"
005328e3 29
67457012
MK
30#include "gdb_assert.h"
31#include "gdb_string.h"
32
005328e3
MK
33#include "i386-tdep.h"
34#include "i387-tdep.h"
35
67457012
MK
36/* From <machine/reg.h>. */
37static 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};
005328e3
MK
56
57static void
67457012
MK
58i386obsd_aout_supply_regset (const struct regset *regset,
59 struct regcache *regcache, int regnum,
60 const void *regs, size_t len)
005328e3 61{
67457012
MK
62 const struct gdbarch_tdep *tdep = regset->descr;
63
64 gdb_assert (len >= tdep->sizeof_gregset + I387_SIZEOF_FSAVE);
005328e3 65
67457012
MK
66 i386_supply_gregset (regset, regcache, regnum, regs, tdep->sizeof_gregset);
67 i387_supply_fsave (regcache, regnum, (char *) regs + tdep->sizeof_gregset);
005328e3
MK
68}
69
67457012
MK
70const struct regset *
71i386obsd_aout_regset_from_core_section (struct gdbarch *gdbarch,
72 const char *sect_name,
73 size_t sect_size)
005328e3 74{
67457012 75 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
005328e3 76
67457012
MK
77 /* OpenBSD a.out core dumps don't use seperate register sets for the
78 general-purpose and floating-point registers. */
005328e3 79
67457012
MK
80 if (strcmp (sect_name, ".reg") == 0
81 && sect_size >= tdep->sizeof_gregset + I387_SIZEOF_FSAVE)
005328e3 82 {
67457012
MK
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;
005328e3
MK
90 }
91
67457012 92 return NULL;
005328e3
MK
93}
94
005328e3
MK
95\f
96
97CORE_ADDR i386obsd_sigtramp_start = 0xbfbfdf20;
98CORE_ADDR i386obsd_sigtramp_end = 0xbfbfdff0;
99
100/* From <machine/signal.h>. */
a3386186
MK
101int i386obsd_sc_reg_offset[I386_NUM_GREGS] =
102{
103 10 * 4, /* %eax */
104 9 * 4, /* %ecx */
105 8 * 4, /* %edx */
106 7 * 4, /* %ebx */
107 14 * 4, /* %esp */
108 6 * 4, /* %ebp */
109 5 * 4, /* %esi */
110 4 * 4, /* %edi */
111 11 * 4, /* %eip */
112 13 * 4, /* %eflags */
113 12 * 4, /* %cs */
114 15 * 4, /* %ss */
115 3 * 4, /* %ds */
116 2 * 4, /* %es */
117 1 * 4, /* %fs */
118 0 * 4 /* %gs */
119};
005328e3
MK
120
121static void
122i386obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
123{
124 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
125
126 /* Obviously OpenBSD is BSD-based. */
127 i386bsd_init_abi (info, gdbarch);
128
67457012
MK
129 /* OpenBSD has a different `struct reg'. */
130 tdep->gregset_reg_offset = i386obsd_r_reg_offset;
131 tdep->gregset_num_regs = ARRAY_SIZE (i386obsd_r_reg_offset);
132 tdep->sizeof_gregset = 16 * 4;
133
134 /* OpenBSD has a single register set. */
135 set_gdbarch_regset_from_core_section
136 (gdbarch, i386obsd_aout_regset_from_core_section);
137
005328e3
MK
138 /* OpenBSD uses -freg-struct-return by default. */
139 tdep->struct_return = reg_struct_return;
140
141 /* OpenBSD uses a different memory layout. */
142 tdep->sigtramp_start = i386obsd_sigtramp_start;
143 tdep->sigtramp_end = i386obsd_sigtramp_end;
144
145 /* OpenBSD has a `struct sigcontext' that's different from the
146 origional 4.3 BSD. */
a3386186 147 tdep->sc_reg_offset = i386obsd_sc_reg_offset;
67457012 148 tdep->sc_num_regs = ARRAY_SIZE (i386obsd_sc_reg_offset);
005328e3 149}
67457012
MK
150\f
151
152/* Provide a prototype to silence -Wmissing-prototypes. */
153void _initialize_i386obsd_tdep (void);
005328e3
MK
154
155void
156_initialize_i386obsd_tdep (void)
157{
005328e3
MK
158 /* FIXME: kettenis/20021020: Since OpenBSD/i386 binaries are
159 indistingushable from NetBSD/i386 a.out binaries, building a GDB
160 that should support both these targets will probably not work as
161 expected. */
162#define GDB_OSABI_OPENBSD_AOUT GDB_OSABI_NETBSD_AOUT
163
05816f70 164 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_OPENBSD_AOUT,
005328e3
MK
165 i386obsd_init_abi);
166}
This page took 0.155791 seconds and 4 git commands to generate.