* i386-tdep.h (i386bsd_sigcontext_addr): Remove prototype.
[platform/upstream/binutils.git] / gdb / i386bsd-tdep.c
1 /* Target-dependent code for i386 BSD's.
2    Copyright 2001, 2002, 2003 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 #include "osabi.h"
27
28 #include "gdb_string.h"
29
30 #include "i386-tdep.h"
31
32 /* Support for signal handlers.  */
33
34 /* Return whether PC is in a BSD sigtramp routine.  */
35
36 static int
37 i386bsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
38 {
39   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
40
41   return (pc >= tdep->sigtramp_start && pc < tdep->sigtramp_end);
42 }
43
44 /* Assuming NEXT_FRAME is for a frame following a BSD sigtramp
45    routine, return the address of the associated sigcontext structure.  */
46
47 static CORE_ADDR
48 i386bsd_sigcontext_addr (struct frame_info *next_frame)
49 {
50   char buf[4];
51   CORE_ADDR sp;
52
53   frame_unwind_register (next_frame, SP_REGNUM, buf);
54   sp = extract_unsigned_integer (buf, 4);
55
56   return read_memory_unsigned_integer (sp + 8, 4);
57 }
58
59 /* Return the start address of the sigtramp routine.  */
60
61 CORE_ADDR
62 i386bsd_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
69 CORE_ADDR
70 i386bsd_sigtramp_end (CORE_ADDR pc)
71 {
72   return gdbarch_tdep (current_gdbarch)->sigtramp_end;
73 }
74 \f
75
76 /* Support for shared libraries.  */
77
78 /* Return non-zero if we are in a shared library trampoline code stub.  */
79
80 int
81 i386bsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name)
82 {
83   return (name && !strcmp (name, "_DYNAMIC"));
84 }
85
86 /* Traditional BSD (4.3 BSD, still used for BSDI and 386BSD).  */
87
88 /* From <machine/signal.h>.  */
89 int i386bsd_sc_pc_offset = 20;
90 int i386bsd_sc_sp_offset = 8;
91
92 void
93 i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
94 {
95   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
96
97   set_gdbarch_pc_in_sigtramp (gdbarch, i386bsd_pc_in_sigtramp);
98
99   /* Allow the recognition of sigtramps as a function named <sigtramp>.  */
100   set_gdbarch_sigtramp_start (gdbarch, i386bsd_sigtramp_start);
101   set_gdbarch_sigtramp_end (gdbarch, i386bsd_sigtramp_end);
102
103   /* Assume SunOS-style shared libraries.  */
104   set_gdbarch_in_solib_call_trampoline (gdbarch,
105                                         i386bsd_aout_in_solib_call_trampoline);
106
107   tdep->jb_pc_offset = 0;
108
109   tdep->sigtramp_start = 0xfdbfdfc0;
110   tdep->sigtramp_end = 0xfdbfe000;
111   tdep->sigcontext_addr = i386bsd_sigcontext_addr;
112   tdep->sc_pc_offset = i386bsd_sc_pc_offset;
113   tdep->sc_sp_offset = i386bsd_sc_sp_offset;
114 }
115
116 /* FreeBSD 3.0-RELEASE or later.  */
117
118 CORE_ADDR i386fbsd_sigtramp_start = 0xbfbfdf20;
119 CORE_ADDR i386fbsd_sigtramp_end = 0xbfbfdff0;
120
121 static void
122 i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
123 {
124   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
125
126   /* Obviously FreeBSD is BSD-based.  */
127   i386bsd_init_abi (info, gdbarch);
128
129   /* FreeBSD uses -freg-struct-return by default.  */
130   tdep->struct_return = reg_struct_return;
131
132   /* FreeBSD uses a different memory layout.  */
133   tdep->sigtramp_start = i386fbsd_sigtramp_start;
134   tdep->sigtramp_end = i386fbsd_sigtramp_end;
135 }
136
137 static void
138 i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
139 {
140   /* It's almost identical to FreeBSD a.out.  */
141   i386fbsdaout_init_abi (info, gdbarch);
142
143   /* Except that it uses ELF.  */
144   i386_elf_init_abi (info, gdbarch);
145
146   /* FreeBSD ELF uses SVR4-style shared libraries.  */
147   set_gdbarch_in_solib_call_trampoline (gdbarch,
148                                         generic_in_solib_call_trampoline);
149 }
150
151 /* FreeBSD 4.0-RELEASE or later.  */
152
153 /* From <machine/signal.h>.  */
154 int i386fbsd4_sc_pc_offset = 76;
155 int i386fbsd4_sc_sp_offset = 88;
156
157 static void
158 i386fbsd4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
159 {
160   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
161
162   /* Inherit stuff from older releases.  We assume that FreeBSD
163      4.0-RELEASE always uses ELF.  */
164   i386fbsd_init_abi (info, gdbarch);
165
166   /* FreeBSD 4.0 introduced a new `struct sigcontext'.  */
167   tdep->sc_pc_offset = i386fbsd4_sc_pc_offset;
168   tdep->sc_sp_offset = i386fbsd4_sc_sp_offset;
169 }
170
171 \f
172 static enum gdb_osabi
173 i386bsd_aout_osabi_sniffer (bfd *abfd)
174 {
175   if (strcmp (bfd_get_target (abfd), "a.out-i386-netbsd") == 0)
176     return GDB_OSABI_NETBSD_AOUT;
177
178   if (strcmp (bfd_get_target (abfd), "a.out-i386-freebsd") == 0)
179     return GDB_OSABI_FREEBSD_AOUT;
180
181   return GDB_OSABI_UNKNOWN;
182 }
183
184 \f
185 /* Provide a prototype to silence -Wmissing-prototypes.  */
186 void _initialize_i386bsd_tdep (void);
187
188 void
189 _initialize_i386bsd_tdep (void)
190 {
191   gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_aout_flavour,
192                                   i386bsd_aout_osabi_sniffer);
193
194   gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_FREEBSD_AOUT,
195                           i386fbsdaout_init_abi);
196   gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_FREEBSD_ELF,
197                           i386fbsd4_init_abi);
198 }