1 /* Target-dependent code for FreeBSD/amd64.
3 Copyright 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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. */
23 #include "arch-utils.h"
29 #include "gdb_assert.h"
30 #include "gdb_string.h"
32 #include "amd64-tdep.h"
33 #include "bsd-uthread.h"
34 #include "solib-svr4.h"
36 /* Support for signal handlers. */
38 /* Assuming NEXT_FRAME is for a frame following a BSD sigtramp
39 routine, return the address of the associated sigcontext structure. */
42 amd64fbsd_sigcontext_addr (struct frame_info *next_frame)
46 /* The `struct sigcontext' (which really is an `ucontext_t' on
47 FreeBSD/amd64) lives at a fixed offset in the signal frame. See
48 <machine/sigframe.h>. */
49 sp = frame_unwind_register_unsigned (next_frame, AMD64_RSP_REGNUM);
53 /* FreeBSD 5.1-RELEASE or later. */
55 /* Mapping between the general-purpose registers in `struct reg'
56 format and GDB's register cache layout.
58 Note that some registers are 32-bit, but since we're little-endian
59 we get away with that. */
61 /* From <machine/reg.h>. */
62 static int amd64fbsd_r_reg_offset[] =
90 /* Location of the signal trampoline. */
91 CORE_ADDR amd64fbsd_sigtramp_start_addr = 0x7fffffffffc0;
92 CORE_ADDR amd64fbsd_sigtramp_end_addr = 0x7fffffffffe0;
94 /* From <machine/signal.h>. */
95 int amd64fbsd_sc_reg_offset[] =
97 24 + 6 * 8, /* %rax */
98 24 + 7 * 8, /* %rbx */
99 24 + 3 * 8, /* %rcx */
100 24 + 2 * 8, /* %rdx */
101 24 + 1 * 8, /* %rsi */
102 24 + 0 * 8, /* %rdi */
103 24 + 8 * 8, /* %rbp */
104 24 + 22 * 8, /* %rsp */
105 24 + 4 * 8, /* %r8 ... */
112 24 + 14 * 8, /* ... %r15 */
113 24 + 19 * 8, /* %rip */
114 24 + 21 * 8, /* %eflags */
115 24 + 20 * 8, /* %cs */
116 24 + 23 * 8, /* %ss */
123 /* From /usr/src/lib/libc/amd64/gen/_setjmp.S. */
124 static int amd64fbsd_jmp_buf_reg_offset[] =
138 4 * 8, /* %r12 ... */
141 7 * 8, /* ... %r15 */
146 amd64fbsd_supply_uthread (struct regcache *regcache,
147 int regnum, CORE_ADDR addr)
152 gdb_assert (regnum >= -1);
154 for (i = 0; i < ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset); i++)
156 if (amd64fbsd_jmp_buf_reg_offset[i] != -1
157 && (regnum == -1 || regnum == i))
159 read_memory (addr + amd64fbsd_jmp_buf_reg_offset[i], buf, 8);
160 regcache_raw_supply (regcache, i, buf);
166 amd64fbsd_collect_uthread (const struct regcache *regcache,
167 int regnum, CORE_ADDR addr)
172 gdb_assert (regnum >= -1);
174 for (i = 0; i < ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset); i++)
176 if (amd64fbsd_jmp_buf_reg_offset[i] != -1
177 && (regnum == -1 || regnum == i))
179 regcache_raw_collect (regcache, i, buf);
180 write_memory (addr + amd64fbsd_jmp_buf_reg_offset[i], buf, 8);
186 amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
188 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
190 /* Obviously FreeBSD is BSD-based. */
191 i386bsd_init_abi (info, gdbarch);
193 tdep->gregset_reg_offset = amd64fbsd_r_reg_offset;
194 tdep->gregset_num_regs = ARRAY_SIZE (amd64fbsd_r_reg_offset);
195 tdep->sizeof_gregset = 22 * 8;
197 amd64_init_abi (info, gdbarch);
199 tdep->sigtramp_start = amd64fbsd_sigtramp_start_addr;
200 tdep->sigtramp_end = amd64fbsd_sigtramp_end_addr;
201 tdep->sigcontext_addr = amd64fbsd_sigcontext_addr;
202 tdep->sc_reg_offset = amd64fbsd_sc_reg_offset;
203 tdep->sc_num_regs = ARRAY_SIZE (amd64fbsd_sc_reg_offset);
205 /* FreeBSD provides a user-level threads implementation. */
206 bsd_uthread_set_supply_uthread (gdbarch, amd64fbsd_supply_uthread);
207 bsd_uthread_set_collect_uthread (gdbarch, amd64fbsd_collect_uthread);
209 /* FreeBSD uses SVR4-style shared libraries. */
210 set_solib_svr4_fetch_link_map_offsets
211 (gdbarch, svr4_lp64_fetch_link_map_offsets);
215 /* Provide a prototype to silence -Wmissing-prototypes. */
216 void _initialize_amd64fbsd_tdep (void);
219 _initialize_amd64fbsd_tdep (void)
221 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
222 GDB_OSABI_FREEBSD_ELF, amd64fbsd_init_abi);