* i386bsd-tdep.c (i386nbsd_sigtramp_start, i386nbsd_sigtramp_end):
[platform/upstream/binutils.git] / gdb / i386bsd-tdep.c
1 /* Target-dependent code for i386 BSD's.
2    Copyright 2001, 2002 Free Software Foundation, Inc.
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"
22 #include "arch-utils.h"
23 #include "frame.h"
24 #include "gdbcore.h"
25 #include "regcache.h"
26
27 #include "i386-tdep.h"
28
29 /* Support for signal handlers.  */
30
31 /* Return whether PC is in a BSD sigtramp routine.  */
32
33 static int
34 i386bsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
35 {
36   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
37
38   return (pc >= tdep->sigtramp_start && pc < tdep->sigtramp_end);
39 }
40
41 /* Assuming FRAME is for a BSD sigtramp routine, return the address of
42    the associated sigcontext structure.
43
44    Note: This function is used for Solaris 2 too, so don't make it
45    static.  */
46
47 CORE_ADDR
48 i386bsd_sigcontext_addr (struct frame_info *frame)
49 {
50   if (frame->next)
51     /* If this isn't the top frame, the next frame must be for the
52        signal handler itself.  A pointer to the sigcontext structure
53        is passed as the third argument to the signal handler.  */
54     return read_memory_unsigned_integer (frame->next->frame + 16, 4);
55
56   /* This is the top frame.  We'll have to find the address of the
57      sigcontext structure by looking at the stack pointer.  */
58   return read_memory_unsigned_integer (read_register (SP_REGNUM) + 8, 4);
59 }
60
61 /* Return the start address of the sigtramp routine.  */
62
63 CORE_ADDR
64 i386bsd_sigtramp_start (CORE_ADDR pc)
65 {
66   return gdbarch_tdep (current_gdbarch)->sigtramp_start;
67 }
68
69 /* Return the end address of the sigtramp routine.  */
70
71 CORE_ADDR
72 i386bsd_sigtramp_end (CORE_ADDR pc)
73 {
74   return gdbarch_tdep (current_gdbarch)->sigtramp_end;
75 }
76 \f
77
78 /* Support for shared libraries.  */
79
80 /* Return non-zero if we are in a shared library trampoline code stub.  */
81
82 int
83 i386bsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name)
84 {
85   return (name && !strcmp (name, "_DYNAMIC"));
86 }
87
88 /* Traditional BSD (4.3 BSD, still used for BSDI and 386BSD).  */
89
90 /* From <machine/signal.h>.  */
91 int i386bsd_sc_pc_offset = 20;
92 int i386bsd_sc_sp_offset = 8;
93
94 static void
95 i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
96 {
97   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
98
99   set_gdbarch_pc_in_sigtramp (gdbarch, i386bsd_pc_in_sigtramp);
100
101   /* Assume SunOS-style shared libraries.  */
102   set_gdbarch_in_solib_call_trampoline (gdbarch,
103                                         i386bsd_aout_in_solib_call_trampoline);
104
105   tdep->jb_pc_offset = 0;
106
107   tdep->sigtramp_start = 0xfdbfdfc0;
108   tdep->sigtramp_end = 0xfdbfe000;
109   tdep->sigcontext_addr = i386bsd_sigcontext_addr;
110   tdep->sc_pc_offset = i386bsd_sc_pc_offset;
111   tdep->sc_sp_offset = i386bsd_sc_sp_offset;
112 }
113
114 /* NetBSD 1.0 or later.  */
115
116 CORE_ADDR i386nbsd_sigtramp_start = 0xbfbfdf20;
117 CORE_ADDR i386nbsd_sigtramp_end = 0xbfbfdff0;
118
119 /* From <machine/signal.h>.  */
120 int i386nbsd_sc_pc_offset = 44;
121 int i386nbsd_sc_sp_offset = 56;
122
123 static void
124 i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
125 {
126   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
127
128   /* Obviously NetBSD is BSD-based.  */
129   i386bsd_init_abi (info, gdbarch);
130
131   /* NetBSD uses -freg-struct-return by default.  */
132   tdep->struct_return = reg_struct_return;
133
134   /* NetBSD uses a different memory layout.  */
135   tdep->sigtramp_start = i386nbsd_sigtramp_start;
136   tdep->sigtramp_end = i386nbsd_sigtramp_end;
137
138   /* NetBSD has a `struct sigcontext' that's different from the
139      origional 4.3 BSD.  */
140   tdep->sc_pc_offset = i386nbsd_sc_pc_offset;
141   tdep->sc_sp_offset = i386nbsd_sc_sp_offset;
142 }
143
144 /* NetBSD ELF.  */
145 static void
146 i386nbsdelf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
147 {
148   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
149
150   /* It's still NetBSD.  */
151   i386nbsd_init_abi (info, gdbarch);
152
153   /* But ELF-based.  */
154   i386_elf_init_abi (info, gdbarch);
155
156   /* NetBSD ELF uses SVR4-style shared libraries.  */
157   set_gdbarch_in_solib_call_trampoline (gdbarch,
158                                         generic_in_solib_call_trampoline);
159
160   /* NetBSD ELF uses -fpcc-struct-return by default.  */
161   tdep->struct_return = pcc_struct_return;
162
163   /* We support the SSE registers on NetBSD ELF.  */
164   tdep->num_xmm_regs = I386_NUM_XREGS - 1;
165   set_gdbarch_num_regs (gdbarch, I386_NUM_GREGS + I386_NUM_FREGS
166                         + I386_NUM_XREGS);
167 }
168
169 /* FreeBSD 3.0-RELEASE or later.  */
170
171 CORE_ADDR i386fbsd_sigtramp_start = 0xbfbfdf20;
172 CORE_ADDR i386fbsd_sigtramp_end = 0xbfbfdff0;
173
174 static void
175 i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
176 {
177   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
178
179   /* Obviously FreeBSD is BSD-based.  */
180   i386bsd_init_abi (info, gdbarch);
181
182   /* FreeBSD uses -freg-struct-return by default.  */
183   tdep->struct_return = reg_struct_return;
184
185   /* FreeBSD uses a different memory layout.  */
186   tdep->sigtramp_start = i386fbsd_sigtramp_start;
187   tdep->sigtramp_end = i386fbsd_sigtramp_end;
188 }
189
190 static void
191 i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
192 {
193   /* It's almost identical to FreeBSD a.out.  */
194   i386fbsdaout_init_abi (info, gdbarch);
195
196   /* Except that it uses ELF.  */
197   i386_elf_init_abi (info, gdbarch);
198
199   /* FreeBSD ELF uses SVR4-style shared libraries.  */
200   set_gdbarch_in_solib_call_trampoline (gdbarch,
201                                         generic_in_solib_call_trampoline);
202 }
203
204 /* FreeBSD 4.0-RELEASE or later.  */
205
206 /* From <machine/signal.h>.  */
207 int i386fbsd4_sc_pc_offset = 76;
208 int i386fbsd4_sc_sp_offset = 88;
209
210 static void
211 i386fbsd4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
212 {
213   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
214
215   /* Inherit stuff from older releases.  We assume that FreeBSD
216      4.0-RELEASE always uses ELF.  */
217   i386fbsd_init_abi (info, gdbarch);
218
219   /* FreeBSD 4.0 introduced a new `struct sigcontext'.  */
220   tdep->sc_pc_offset = i386fbsd4_sc_pc_offset;
221   tdep->sc_sp_offset = i386fbsd4_sc_sp_offset;
222 }
223
224 \f
225 static enum gdb_osabi
226 i386bsd_aout_osabi_sniffer (bfd *abfd)
227 {
228   if (strcmp (bfd_get_target (abfd), "a.out-i386-netbsd") == 0)
229     return GDB_OSABI_NETBSD_AOUT;
230
231   if (strcmp (bfd_get_target (abfd), "a.out-i386-freebsd") == 0)
232     return GDB_OSABI_FREEBSD_AOUT;
233
234   return GDB_OSABI_UNKNOWN;
235 }
236
237 \f
238 /* Provide a prototype to silence -Wmissing-prototypes.  */
239 void _initialize_i386bsd_tdep (void);
240
241 void
242 _initialize_i386bsd_tdep (void)
243 {
244   gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_aout_flavour,
245                                   i386bsd_aout_osabi_sniffer);
246
247   gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_NETBSD_AOUT,
248                           i386nbsd_init_abi);
249   gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_NETBSD_ELF,
250                           i386nbsdelf_init_abi);
251   gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_FREEBSD_AOUT,
252                           i386fbsdaout_init_abi);
253   gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_FREEBSD_ELF,
254                           i386fbsd4_init_abi);
255 }