Commit | Line | Data |
---|---|---|
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 |
36 | static int |
37 | i386bsd_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 MK |
43 | |
44 | /* Assuming FRAME is for a BSD sigtramp routine, return the address of | |
21d0e8a4 | 45 | the associated sigcontext structure. |
b7247919 | 46 | |
21d0e8a4 MK |
47 | Note: This function is used for Solaris 2 too, so don't make it |
48 | static. */ | |
49 | ||
50 | CORE_ADDR | |
b7247919 MK |
51 | i386bsd_sigcontext_addr (struct frame_info *frame) |
52 | { | |
53 | if (frame->next) | |
54 | /* If this isn't the top frame, the next frame must be for the | |
55 | signal handler itself. A pointer to the sigcontext structure | |
56 | is passed as the third argument to the signal handler. */ | |
57 | return read_memory_unsigned_integer (frame->next->frame + 16, 4); | |
58 | ||
59 | /* This is the top frame. We'll have to find the address of the | |
60 | sigcontext structure by looking at the stack pointer. */ | |
61 | return read_memory_unsigned_integer (read_register (SP_REGNUM) + 8, 4); | |
62 | } | |
63 | ||
8201327c MK |
64 | /* Return the start address of the sigtramp routine. */ |
65 | ||
66 | CORE_ADDR | |
67 | i386bsd_sigtramp_start (CORE_ADDR pc) | |
68 | { | |
69 | return gdbarch_tdep (current_gdbarch)->sigtramp_start; | |
70 | } | |
71 | ||
72 | /* Return the end address of the sigtramp routine. */ | |
73 | ||
74 | CORE_ADDR | |
75 | i386bsd_sigtramp_end (CORE_ADDR pc) | |
76 | { | |
77 | return gdbarch_tdep (current_gdbarch)->sigtramp_end; | |
78 | } | |
79 | \f | |
80 | ||
9c5045b5 MK |
81 | /* Support for shared libraries. */ |
82 | ||
83 | /* Return non-zero if we are in a shared library trampoline code stub. */ | |
84 | ||
85 | int | |
86 | i386bsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name) | |
87 | { | |
88 | return (name && !strcmp (name, "_DYNAMIC")); | |
89 | } | |
90 | ||
8201327c MK |
91 | /* Traditional BSD (4.3 BSD, still used for BSDI and 386BSD). */ |
92 | ||
93 | /* From <machine/signal.h>. */ | |
94 | int i386bsd_sc_pc_offset = 20; | |
6bff26de | 95 | int i386bsd_sc_sp_offset = 8; |
8201327c | 96 | |
3cac699e | 97 | void |
8201327c MK |
98 | i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
99 | { | |
100 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
101 | ||
102 | set_gdbarch_pc_in_sigtramp (gdbarch, i386bsd_pc_in_sigtramp); | |
103 | ||
4b218c18 MK |
104 | /* Allow the recognition of sigtramps as a function named <sigtramp>. */ |
105 | set_gdbarch_sigtramp_start (gdbarch, i386bsd_sigtramp_start); | |
106 | set_gdbarch_sigtramp_end (gdbarch, i386bsd_sigtramp_end); | |
107 | ||
9c5045b5 MK |
108 | /* Assume SunOS-style shared libraries. */ |
109 | set_gdbarch_in_solib_call_trampoline (gdbarch, | |
110 | i386bsd_aout_in_solib_call_trampoline); | |
111 | ||
8201327c MK |
112 | tdep->jb_pc_offset = 0; |
113 | ||
8201327c MK |
114 | tdep->sigtramp_start = 0xfdbfdfc0; |
115 | tdep->sigtramp_end = 0xfdbfe000; | |
21d0e8a4 | 116 | tdep->sigcontext_addr = i386bsd_sigcontext_addr; |
8201327c | 117 | tdep->sc_pc_offset = i386bsd_sc_pc_offset; |
6bff26de | 118 | tdep->sc_sp_offset = i386bsd_sc_sp_offset; |
8201327c MK |
119 | } |
120 | ||
8201327c MK |
121 | /* FreeBSD 3.0-RELEASE or later. */ |
122 | ||
123 | CORE_ADDR i386fbsd_sigtramp_start = 0xbfbfdf20; | |
124 | CORE_ADDR i386fbsd_sigtramp_end = 0xbfbfdff0; | |
125 | ||
126 | static void | |
127 | i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
128 | { | |
129 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
130 | ||
131 | /* Obviously FreeBSD is BSD-based. */ | |
132 | i386bsd_init_abi (info, gdbarch); | |
133 | ||
134 | /* FreeBSD uses -freg-struct-return by default. */ | |
135 | tdep->struct_return = reg_struct_return; | |
136 | ||
137 | /* FreeBSD uses a different memory layout. */ | |
138 | tdep->sigtramp_start = i386fbsd_sigtramp_start; | |
139 | tdep->sigtramp_end = i386fbsd_sigtramp_end; | |
140 | } | |
141 | ||
142 | static void | |
143 | i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
144 | { | |
145 | /* It's almost identical to FreeBSD a.out. */ | |
146 | i386fbsdaout_init_abi (info, gdbarch); | |
147 | ||
148 | /* Except that it uses ELF. */ | |
149 | i386_elf_init_abi (info, gdbarch); | |
9c5045b5 MK |
150 | |
151 | /* FreeBSD ELF uses SVR4-style shared libraries. */ | |
152 | set_gdbarch_in_solib_call_trampoline (gdbarch, | |
153 | generic_in_solib_call_trampoline); | |
8201327c MK |
154 | } |
155 | ||
156 | /* FreeBSD 4.0-RELEASE or later. */ | |
157 | ||
158 | /* From <machine/signal.h>. */ | |
159 | int i386fbsd4_sc_pc_offset = 76; | |
6bff26de | 160 | int i386fbsd4_sc_sp_offset = 88; |
8201327c MK |
161 | |
162 | static void | |
163 | i386fbsd4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
164 | { | |
165 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
166 | ||
167 | /* Inherit stuff from older releases. We assume that FreeBSD | |
168 | 4.0-RELEASE always uses ELF. */ | |
169 | i386fbsd_init_abi (info, gdbarch); | |
170 | ||
171 | /* FreeBSD 4.0 introduced a new `struct sigcontext'. */ | |
172 | tdep->sc_pc_offset = i386fbsd4_sc_pc_offset; | |
6bff26de | 173 | tdep->sc_sp_offset = i386fbsd4_sc_sp_offset; |
8201327c MK |
174 | } |
175 | ||
176 | \f | |
177 | static enum gdb_osabi | |
178 | i386bsd_aout_osabi_sniffer (bfd *abfd) | |
179 | { | |
180 | if (strcmp (bfd_get_target (abfd), "a.out-i386-netbsd") == 0) | |
181 | return GDB_OSABI_NETBSD_AOUT; | |
182 | ||
183 | if (strcmp (bfd_get_target (abfd), "a.out-i386-freebsd") == 0) | |
184 | return GDB_OSABI_FREEBSD_AOUT; | |
185 | ||
186 | return GDB_OSABI_UNKNOWN; | |
187 | } | |
188 | ||
189 | \f | |
190 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
191 | void _initialize_i386bsd_tdep (void); | |
192 | ||
193 | void | |
194 | _initialize_i386bsd_tdep (void) | |
195 | { | |
196 | gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_aout_flavour, | |
197 | i386bsd_aout_osabi_sniffer); | |
198 | ||
05816f70 | 199 | gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_FREEBSD_AOUT, |
8201327c | 200 | i386fbsdaout_init_abi); |
05816f70 | 201 | gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_FREEBSD_ELF, |
8201327c MK |
202 | i386fbsd4_init_abi); |
203 | } |