*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / i386fbsd-tdep.c
1 /* Target-dependent code for FreeBSD/i386.
2
3 Copyright 2003, 2004, 2005 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include "defs.h"
23 #include "arch-utils.h"
24 #include "gdbcore.h"
25 #include "osabi.h"
26 #include "regcache.h"
27
28 #include "gdb_assert.h"
29
30 #include "i386-tdep.h"
31 #include "i387-tdep.h"
32 #include "bsd-uthread.h"
33 #include "solib-svr4.h"
34
35 /* FreeBSD 3.0-RELEASE or later. */
36
37 /* From <machine/reg.h>. */
38 static int i386fbsd_r_reg_offset[] =
39 {
40 9 * 4, 8 * 4, 7 * 4, 6 * 4, /* %eax, %ecx, %edx, %ebx */
41 15 * 4, 4 * 4, /* %esp, %ebp */
42 3 * 4, 2 * 4, /* %esi, %edi */
43 12 * 4, 14 * 4, /* %eip, %eflags */
44 13 * 4, 16 * 4, /* %cs, %ss */
45 1 * 4, 0 * 4, -1, -1 /* %ds, %es, %fs, %gs */
46 };
47
48 /* Sigtramp routine location. */
49 CORE_ADDR i386fbsd_sigtramp_start_addr = 0xbfbfdf20;
50 CORE_ADDR i386fbsd_sigtramp_end_addr = 0xbfbfdff0;
51
52 /* From <machine/signal.h>. */
53 static int i386fbsd_sc_reg_offset[] =
54 {
55 8 + 14 * 4, /* %eax */
56 8 + 13 * 4, /* %ecx */
57 8 + 12 * 4, /* %edx */
58 8 + 11 * 4, /* %ebx */
59 8 + 0 * 4, /* %esp */
60 8 + 1 * 4, /* %ebp */
61 8 + 10 * 4, /* %esi */
62 8 + 9 * 4, /* %edi */
63 8 + 3 * 4, /* %eip */
64 8 + 4 * 4, /* %eflags */
65 8 + 7 * 4, /* %cs */
66 8 + 8 * 4, /* %ss */
67 8 + 6 * 4, /* %ds */
68 8 + 5 * 4, /* %es */
69 8 + 15 * 4, /* %fs */
70 8 + 16 * 4 /* %gs */
71 };
72
73 /* From /usr/src/lib/libc/i386/gen/_setjmp.S. */
74 static int i386fbsd_jmp_buf_reg_offset[] =
75 {
76 -1, /* %eax */
77 -1, /* %ecx */
78 -1, /* %edx */
79 1 * 4, /* %ebx */
80 2 * 4, /* %esp */
81 3 * 4, /* %ebp */
82 4 * 4, /* %esi */
83 5 * 4, /* %edi */
84 0 * 4 /* %eip */
85 };
86
87 static void
88 i386fbsd_supply_uthread (struct regcache *regcache,
89 int regnum, CORE_ADDR addr)
90 {
91 char buf[4];
92 int i;
93
94 gdb_assert (regnum >= -1);
95
96 for (i = 0; i < ARRAY_SIZE (i386fbsd_jmp_buf_reg_offset); i++)
97 {
98 if (i386fbsd_jmp_buf_reg_offset[i] != -1
99 && (regnum == -1 || regnum == i))
100 {
101 read_memory (addr + i386fbsd_jmp_buf_reg_offset[i], buf, 4);
102 regcache_raw_supply (regcache, i, buf);
103 }
104 }
105 }
106
107 static void
108 i386fbsd_collect_uthread (const struct regcache *regcache,
109 int regnum, CORE_ADDR addr)
110 {
111 char buf[4];
112 int i;
113
114 gdb_assert (regnum >= -1);
115
116 for (i = 0; i < ARRAY_SIZE (i386fbsd_jmp_buf_reg_offset); i++)
117 {
118 if (i386fbsd_jmp_buf_reg_offset[i] != -1
119 && (regnum == -1 || regnum == i))
120 {
121 regcache_raw_collect (regcache, i, buf);
122 write_memory (addr + i386fbsd_jmp_buf_reg_offset[i], buf, 4);
123 }
124 }
125 }
126
127 static void
128 i386fbsdaout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
129 {
130 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
131
132 /* Obviously FreeBSD is BSD-based. */
133 i386bsd_init_abi (info, gdbarch);
134
135 /* FreeBSD has a different `struct reg', and reserves some space for
136 its FPU emulator in `struct fpreg'. */
137 tdep->gregset_reg_offset = i386fbsd_r_reg_offset;
138 tdep->gregset_num_regs = ARRAY_SIZE (i386fbsd_r_reg_offset);
139 tdep->sizeof_gregset = 18 * 4;
140 tdep->sizeof_fpregset = 176;
141
142 /* FreeBSD uses -freg-struct-return by default. */
143 tdep->struct_return = reg_struct_return;
144
145 /* FreeBSD uses a different memory layout. */
146 tdep->sigtramp_start = i386fbsd_sigtramp_start_addr;
147 tdep->sigtramp_end = i386fbsd_sigtramp_end_addr;
148
149 /* FreeBSD has a more complete `struct sigcontext'. */
150 tdep->sc_reg_offset = i386fbsd_sc_reg_offset;
151 tdep->sc_num_regs = ARRAY_SIZE (i386fbsd_sc_reg_offset);
152
153 /* FreeBSD provides a user-level threads implementation. */
154 bsd_uthread_set_supply_uthread (gdbarch, i386fbsd_supply_uthread);
155 bsd_uthread_set_collect_uthread (gdbarch, i386fbsd_collect_uthread);
156 }
157
158 static void
159 i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
160 {
161 /* It's almost identical to FreeBSD a.out. */
162 i386fbsdaout_init_abi (info, gdbarch);
163
164 /* Except that it uses ELF. */
165 i386_elf_init_abi (info, gdbarch);
166
167 /* FreeBSD ELF uses SVR4-style shared libraries. */
168 set_solib_svr4_fetch_link_map_offsets
169 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
170 }
171
172 /* FreeBSD 4.0-RELEASE or later. */
173
174 /* From <machine/reg.h>. */
175 static int i386fbsd4_r_reg_offset[] =
176 {
177 10 * 4, 9 * 4, 8 * 4, 7 * 4, /* %eax, %ecx, %edx, %ebx */
178 16 * 4, 5 * 4, /* %esp, %ebp */
179 4 * 4, 3 * 4, /* %esi, %edi */
180 13 * 4, 15 * 4, /* %eip, %eflags */
181 14 * 4, 17 * 4, /* %cs, %ss */
182 2 * 4, 1 * 4, 0 * 4, 18 * 4 /* %ds, %es, %fs, %gs */
183 };
184
185 /* From <machine/signal.h>. */
186 int i386fbsd4_sc_reg_offset[] =
187 {
188 20 + 11 * 4, /* %eax */
189 20 + 10 * 4, /* %ecx */
190 20 + 9 * 4, /* %edx */
191 20 + 8 * 4, /* %ebx */
192 20 + 17 * 4, /* %esp */
193 20 + 6 * 4, /* %ebp */
194 20 + 5 * 4, /* %esi */
195 20 + 4 * 4, /* %edi */
196 20 + 14 * 4, /* %eip */
197 20 + 16 * 4, /* %eflags */
198 20 + 15 * 4, /* %cs */
199 20 + 18 * 4, /* %ss */
200 20 + 3 * 4, /* %ds */
201 20 + 2 * 4, /* %es */
202 20 + 1 * 4, /* %fs */
203 20 + 0 * 4 /* %gs */
204 };
205
206 static void
207 i386fbsd4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
208 {
209 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
210
211 /* Inherit stuff from older releases. We assume that FreeBSD
212 4.0-RELEASE always uses ELF. */
213 i386fbsd_init_abi (info, gdbarch);
214
215 /* FreeBSD 4.0 introduced a new `struct reg'. */
216 tdep->gregset_reg_offset = i386fbsd4_r_reg_offset;
217 tdep->gregset_num_regs = ARRAY_SIZE (i386fbsd4_r_reg_offset);
218 tdep->sizeof_gregset = 19 * 4;
219
220 /* FreeBSD 4.0 introduced a new `struct sigcontext'. */
221 tdep->sc_reg_offset = i386fbsd4_sc_reg_offset;
222 tdep->sc_num_regs = ARRAY_SIZE (i386fbsd4_sc_reg_offset);
223 }
224
225 \f
226 /* Provide a prototype to silence -Wmissing-prototypes. */
227 void _initialize_i386fbsd_tdep (void);
228
229 void
230 _initialize_i386fbsd_tdep (void)
231 {
232 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_FREEBSD_AOUT,
233 i386fbsdaout_init_abi);
234 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_FREEBSD_ELF,
235 i386fbsd4_init_abi);
236 }
This page took 0.044675 seconds and 4 git commands to generate.