1 /* Target-dependent code for FreeBSD/amd64.
3 Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "arch-utils.h"
28 #include "gdb_assert.h"
29 #include "gdb_string.h"
31 #include "amd64-tdep.h"
32 #include "bsd-uthread.h"
33 #include "solib-svr4.h"
35 /* Support for signal handlers. */
37 /* Assuming THIS_FRAME is for a BSD sigtramp routine, return the
38 address of the associated sigcontext structure. */
41 amd64fbsd_sigcontext_addr (struct frame_info
*this_frame
)
45 /* The `struct sigcontext' (which really is an `ucontext_t' on
46 FreeBSD/amd64) lives at a fixed offset in the signal frame. See
47 <machine/sigframe.h>. */
48 sp
= frame_unwind_register_unsigned (this_frame
, AMD64_RSP_REGNUM
);
52 /* FreeBSD 5.1-RELEASE or later. */
54 /* Mapping between the general-purpose registers in `struct reg'
55 format and GDB's register cache layout.
57 Note that some registers are 32-bit, but since we're little-endian
58 we get away with that. */
60 /* From <machine/reg.h>. */
61 static int amd64fbsd_r_reg_offset
[] =
89 /* Location of the signal trampoline. */
90 CORE_ADDR amd64fbsd_sigtramp_start_addr
= 0x7fffffffffc0ULL
;
91 CORE_ADDR amd64fbsd_sigtramp_end_addr
= 0x7fffffffffe0ULL
;
93 /* From <machine/signal.h>. */
94 int amd64fbsd_sc_reg_offset
[] =
96 24 + 6 * 8, /* %rax */
97 24 + 7 * 8, /* %rbx */
98 24 + 3 * 8, /* %rcx */
99 24 + 2 * 8, /* %rdx */
100 24 + 1 * 8, /* %rsi */
101 24 + 0 * 8, /* %rdi */
102 24 + 8 * 8, /* %rbp */
103 24 + 22 * 8, /* %rsp */
104 24 + 4 * 8, /* %r8 ... */
111 24 + 14 * 8, /* ... %r15 */
112 24 + 19 * 8, /* %rip */
113 24 + 21 * 8, /* %eflags */
114 24 + 20 * 8, /* %cs */
115 24 + 23 * 8, /* %ss */
122 /* From /usr/src/lib/libc/amd64/gen/_setjmp.S. */
123 static int amd64fbsd_jmp_buf_reg_offset
[] =
137 4 * 8, /* %r12 ... */
140 7 * 8, /* ... %r15 */
145 amd64fbsd_supply_uthread (struct regcache
*regcache
,
146 int regnum
, CORE_ADDR addr
)
151 gdb_assert (regnum
>= -1);
153 for (i
= 0; i
< ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset
); i
++)
155 if (amd64fbsd_jmp_buf_reg_offset
[i
] != -1
156 && (regnum
== -1 || regnum
== i
))
158 read_memory (addr
+ amd64fbsd_jmp_buf_reg_offset
[i
], buf
, 8);
159 regcache_raw_supply (regcache
, i
, buf
);
165 amd64fbsd_collect_uthread (const struct regcache
*regcache
,
166 int regnum
, CORE_ADDR addr
)
171 gdb_assert (regnum
>= -1);
173 for (i
= 0; i
< ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset
); i
++)
175 if (amd64fbsd_jmp_buf_reg_offset
[i
] != -1
176 && (regnum
== -1 || regnum
== i
))
178 regcache_raw_collect (regcache
, i
, buf
);
179 write_memory (addr
+ amd64fbsd_jmp_buf_reg_offset
[i
], buf
, 8);
185 amd64fbsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
187 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
189 /* Obviously FreeBSD is BSD-based. */
190 i386bsd_init_abi (info
, gdbarch
);
192 tdep
->gregset_reg_offset
= amd64fbsd_r_reg_offset
;
193 tdep
->gregset_num_regs
= ARRAY_SIZE (amd64fbsd_r_reg_offset
);
194 tdep
->sizeof_gregset
= 22 * 8;
196 amd64_init_abi (info
, gdbarch
);
198 tdep
->sigtramp_start
= amd64fbsd_sigtramp_start_addr
;
199 tdep
->sigtramp_end
= amd64fbsd_sigtramp_end_addr
;
200 tdep
->sigcontext_addr
= amd64fbsd_sigcontext_addr
;
201 tdep
->sc_reg_offset
= amd64fbsd_sc_reg_offset
;
202 tdep
->sc_num_regs
= ARRAY_SIZE (amd64fbsd_sc_reg_offset
);
204 /* FreeBSD provides a user-level threads implementation. */
205 bsd_uthread_set_supply_uthread (gdbarch
, amd64fbsd_supply_uthread
);
206 bsd_uthread_set_collect_uthread (gdbarch
, amd64fbsd_collect_uthread
);
208 /* FreeBSD uses SVR4-style shared libraries. */
209 set_solib_svr4_fetch_link_map_offsets
210 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
214 /* Provide a prototype to silence -Wmissing-prototypes. */
215 void _initialize_amd64fbsd_tdep (void);
218 _initialize_amd64fbsd_tdep (void)
220 gdbarch_register_osabi (bfd_arch_i386
, bfd_mach_x86_64
,
221 GDB_OSABI_FREEBSD_ELF
, amd64fbsd_init_abi
);