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