daily update
[deliverable/binutils-gdb.git] / gdb / i386bsd-tdep.c
CommitLineData
b7247919 1/* Target-dependent code for i386 BSD's.
4be87837 2 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
b7247919
MK
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21#include "defs.h"
9c5045b5 22#include "arch-utils.h"
b7247919
MK
23#include "frame.h"
24#include "gdbcore.h"
25#include "regcache.h"
4be87837 26#include "osabi.h"
b7247919 27
ca39387d
MK
28#include "gdb_string.h"
29
8201327c 30#include "i386-tdep.h"
b7247919 31
8201327c 32/* Support for signal handlers. */
b7247919
MK
33
34/* Return whether PC is in a BSD sigtramp routine. */
35
8201327c
MK
36static int
37i386bsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
b7247919 38{
8201327c 39 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
b7247919 40
8201327c
MK
41 return (pc >= tdep->sigtramp_start && pc < tdep->sigtramp_end);
42}
b7247919 43
acd5c798
MK
44/* Assuming NEXT_FRAME is for a frame following a BSD sigtramp
45 routine, return the address of the associated sigcontext structure. */
b7247919 46
acd5c798
MK
47static CORE_ADDR
48i386bsd_sigcontext_addr (struct frame_info *next_frame)
b7247919 49{
acd5c798
MK
50 char buf[4];
51 CORE_ADDR sp;
b4700d91 52
c7f16359 53 frame_unwind_register (next_frame, I386_ESP_REGNUM, buf);
acd5c798 54 sp = extract_unsigned_integer (buf, 4);
b7247919 55
acd5c798 56 return read_memory_unsigned_integer (sp + 8, 4);
b7247919
MK
57}
58
8201327c
MK
59/* Return the start address of the sigtramp routine. */
60
61CORE_ADDR
62i386bsd_sigtramp_start (CORE_ADDR pc)
63{
64 return gdbarch_tdep (current_gdbarch)->sigtramp_start;
65}
66
67/* Return the end address of the sigtramp routine. */
68
69CORE_ADDR
70i386bsd_sigtramp_end (CORE_ADDR pc)
71{
72 return gdbarch_tdep (current_gdbarch)->sigtramp_end;
73}
74\f
75
9c5045b5
MK
76/* Support for shared libraries. */
77
78/* Return non-zero if we are in a shared library trampoline code stub. */
79
80int
81i386bsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name)
82{
83 return (name && !strcmp (name, "_DYNAMIC"));
84}
85
8201327c
MK
86/* Traditional BSD (4.3 BSD, still used for BSDI and 386BSD). */
87
88/* From <machine/signal.h>. */
a3386186
MK
89int i386bsd_sc_reg_offset[I386_NUM_GREGS] =
90{
91 -1, /* %eax */
92 -1, /* %ecx */
93 -1, /* %edx */
94 -1, /* %ebx */
95 8 + 0 * 4, /* %esp */
96 8 + 1 * 4, /* %ebp */
97 -1, /* %esi */
98 -1, /* %edi */
99 8 + 3 * 4, /* %eip */
100 8 + 4 * 4, /* %eflags */
101 -1, /* %cs */
102 -1, /* %ss */
103 -1, /* %ds */
104 -1, /* %es */
105 -1, /* %fs */
106 -1 /* %gs */
107};
8201327c 108
3cac699e 109void
8201327c
MK
110i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
111{
112 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
113
114 set_gdbarch_pc_in_sigtramp (gdbarch, i386bsd_pc_in_sigtramp);
115
4b218c18
MK
116 /* Allow the recognition of sigtramps as a function named <sigtramp>. */
117 set_gdbarch_sigtramp_start (gdbarch, i386bsd_sigtramp_start);
118 set_gdbarch_sigtramp_end (gdbarch, i386bsd_sigtramp_end);
119
9c5045b5
MK
120 /* Assume SunOS-style shared libraries. */
121 set_gdbarch_in_solib_call_trampoline (gdbarch,
122 i386bsd_aout_in_solib_call_trampoline);
123
8201327c
MK
124 tdep->jb_pc_offset = 0;
125
8201327c
MK
126 tdep->sigtramp_start = 0xfdbfdfc0;
127 tdep->sigtramp_end = 0xfdbfe000;
21d0e8a4 128 tdep->sigcontext_addr = i386bsd_sigcontext_addr;
a3386186
MK
129 tdep->sc_reg_offset = i386bsd_sc_reg_offset;
130 tdep->sc_num_regs = I386_NUM_GREGS;
8201327c
MK
131}
132
8201327c
MK
133/* FreeBSD 3.0-RELEASE or later. */
134
135CORE_ADDR i386fbsd_sigtramp_start = 0xbfbfdf20;
136CORE_ADDR i386fbsd_sigtramp_end = 0xbfbfdff0;
137
a3386186
MK
138/* From <machine/signal.h>. */
139int i386fbsd_sc_reg_offset[I386_NUM_GREGS] =
140{
141 8 + 14 * 4, /* %eax */
142 8 + 13 * 4, /* %ecx */
143 8 + 12 * 4, /* %edx */
144 8 + 11 * 4, /* %ebx */
145 8 + 0 * 4, /* %esp */
146 8 + 1 * 4, /* %ebp */
147 8 + 10 * 4, /* %esi */
148 8 + 9 * 4, /* %edi */
149 8 + 3 * 4, /* %eip */
150 8 + 4 * 4, /* %eflags */
151 8 + 7 * 4, /* %cs */
152 8 + 8 * 4, /* %ss */
153 8 + 6 * 4, /* %ds */
154 8 + 5 * 4, /* %es */
155 8 + 15 * 4, /* %fs */
156 8 + 16 * 4 /* %gs */
157};
158
8201327c
MK
159static void
160i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
161{
162 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
163
164 /* Obviously FreeBSD is BSD-based. */
165 i386bsd_init_abi (info, gdbarch);
166
167 /* FreeBSD uses -freg-struct-return by default. */
168 tdep->struct_return = reg_struct_return;
169
170 /* FreeBSD uses a different memory layout. */
171 tdep->sigtramp_start = i386fbsd_sigtramp_start;
172 tdep->sigtramp_end = i386fbsd_sigtramp_end;
a3386186
MK
173
174 /* FreeBSD has a more complete `struct sigcontext'. */
175 tdep->sc_reg_offset = i386fbsd_sc_reg_offset;
176 tdep->sc_num_regs = I386_NUM_GREGS;
8201327c
MK
177}
178
179static void
180i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
181{
182 /* It's almost identical to FreeBSD a.out. */
183 i386fbsdaout_init_abi (info, gdbarch);
184
185 /* Except that it uses ELF. */
186 i386_elf_init_abi (info, gdbarch);
9c5045b5
MK
187
188 /* FreeBSD ELF uses SVR4-style shared libraries. */
189 set_gdbarch_in_solib_call_trampoline (gdbarch,
190 generic_in_solib_call_trampoline);
8201327c
MK
191}
192
193/* FreeBSD 4.0-RELEASE or later. */
194
195/* From <machine/signal.h>. */
a3386186
MK
196int i386fbsd4_sc_reg_offset[I386_NUM_GREGS] =
197{
198 20 + 11 * 4, /* %eax */
199 20 + 10 * 4, /* %ecx */
200 20 + 9 * 4, /* %edx */
201 20 + 8 * 4, /* %ebx */
202 20 + 17 * 4, /* %esp */
203 20 + 6 * 4, /* %ebp */
204 20 + 5 * 4, /* %esi */
205 20 + 4 * 4, /* %edi */
206 20 + 14 * 4, /* %eip */
207 20 + 16 * 4, /* %eflags */
208 20 + 15 * 4, /* %cs */
209 20 + 18 * 4, /* %ss */
210 20 + 3 * 4, /* %ds */
211 20 + 2 * 4, /* %es */
212 20 + 1 * 4, /* %fs */
213 20 + 0 * 4 /* %gs */
214};
8201327c
MK
215
216static void
217i386fbsd4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
218{
219 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
220
221 /* Inherit stuff from older releases. We assume that FreeBSD
222 4.0-RELEASE always uses ELF. */
223 i386fbsd_init_abi (info, gdbarch);
224
225 /* FreeBSD 4.0 introduced a new `struct sigcontext'. */
a3386186
MK
226 tdep->sc_reg_offset = i386fbsd4_sc_reg_offset;
227 tdep->sc_num_regs = I386_NUM_GREGS;
8201327c
MK
228}
229
230\f
231static enum gdb_osabi
232i386bsd_aout_osabi_sniffer (bfd *abfd)
233{
234 if (strcmp (bfd_get_target (abfd), "a.out-i386-netbsd") == 0)
235 return GDB_OSABI_NETBSD_AOUT;
236
237 if (strcmp (bfd_get_target (abfd), "a.out-i386-freebsd") == 0)
238 return GDB_OSABI_FREEBSD_AOUT;
239
240 return GDB_OSABI_UNKNOWN;
241}
242
243\f
244/* Provide a prototype to silence -Wmissing-prototypes. */
245void _initialize_i386bsd_tdep (void);
246
247void
248_initialize_i386bsd_tdep (void)
249{
250 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_aout_flavour,
251 i386bsd_aout_osabi_sniffer);
252
05816f70 253 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_FREEBSD_AOUT,
8201327c 254 i386fbsdaout_init_abi);
05816f70 255 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_FREEBSD_ELF,
8201327c
MK
256 i386fbsd4_init_abi);
257}
This page took 0.237347 seconds and 4 git commands to generate.