]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/amd64fbsd-tdep.c
* configure.ac: Switch license to GPLv3.
[thirdparty/binutils-gdb.git] / gdb / amd64fbsd-tdep.c
CommitLineData
68cc0bfb 1/* Target-dependent code for FreeBSD/amd64.
477f40d1 2
6aba47ca 3 Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
68cc0bfb
MK
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
197e01b6
EZ
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
68cc0bfb
MK
21
22#include "defs.h"
23#include "arch-utils.h"
24#include "frame.h"
25#include "gdbcore.h"
26#include "regcache.h"
27#include "osabi.h"
28
1c02b2a5 29#include "gdb_assert.h"
68cc0bfb
MK
30#include "gdb_string.h"
31
85be1ca6 32#include "amd64-tdep.h"
1c02b2a5 33#include "bsd-uthread.h"
7e654c37 34#include "solib-svr4.h"
68cc0bfb
MK
35
36/* Support for signal handlers. */
37
38/* Assuming NEXT_FRAME is for a frame following a BSD sigtramp
39 routine, return the address of the associated sigcontext structure. */
40
41static CORE_ADDR
42amd64fbsd_sigcontext_addr (struct frame_info *next_frame)
43{
68cc0bfb
MK
44 CORE_ADDR sp;
45
212c460c
MK
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>. */
90f90721 49 sp = frame_unwind_register_unsigned (next_frame, AMD64_RSP_REGNUM);
212c460c 50 return sp + 16;
68cc0bfb
MK
51}
52\f
53/* FreeBSD 5.1-RELEASE or later. */
54
477f40d1
MK
55/* Mapping between the general-purpose registers in `struct reg'
56 format and GDB's register cache layout.
57
58 Note that some registers are 32-bit, but since we're little-endian
59 we get away with that. */
60
61/* From <machine/reg.h>. */
62static int amd64fbsd_r_reg_offset[] =
63{
af233647
MK
64 14 * 8, /* %rax */
65 11 * 8, /* %rbx */
66 13 * 8, /* %rcx */
67 12 * 8, /* %rdx */
68 9 * 8, /* %rsi */
69 8 * 8, /* %rdi */
70 10 * 8, /* %rbp */
71 20 * 8, /* %rsp */
72 7 * 8, /* %r8 ... */
73 6 * 8,
74 5 * 8,
75 4 * 8,
76 3 * 8,
77 2 * 8,
78 1 * 8,
79 0 * 8, /* ... %r15 */
80 17 * 8, /* %rip */
81 19 * 8, /* %eflags */
82 18 * 8, /* %cs */
83 21 * 8, /* %ss */
84 -1, /* %ds */
85 -1, /* %es */
86 -1, /* %fs */
87 -1 /* %gs */
477f40d1
MK
88};
89
68cc0bfb 90/* Location of the signal trampoline. */
10fc94a4
MK
91CORE_ADDR amd64fbsd_sigtramp_start_addr = 0x7fffffffffc0;
92CORE_ADDR amd64fbsd_sigtramp_end_addr = 0x7fffffffffe0;
68cc0bfb
MK
93
94/* From <machine/signal.h>. */
af233647 95int amd64fbsd_sc_reg_offset[] =
68cc0bfb 96{
212c460c
MK
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 */
dac94105 104 24 + 22 * 8, /* %rsp */
af233647
MK
105 24 + 4 * 8, /* %r8 ... */
106 24 + 5 * 8,
107 24 + 9 * 8,
108 24 + 10 * 8,
109 24 + 11 * 8,
110 24 + 12 * 8,
111 24 + 13 * 8,
112 24 + 14 * 8, /* ... %r15 */
dac94105
MK
113 24 + 19 * 8, /* %rip */
114 24 + 21 * 8, /* %eflags */
af233647
MK
115 24 + 20 * 8, /* %cs */
116 24 + 23 * 8, /* %ss */
68cc0bfb
MK
117 -1, /* %ds */
118 -1, /* %es */
119 -1, /* %fs */
120 -1 /* %gs */
121};
122
1c02b2a5
MK
123/* From /usr/src/lib/libc/amd64/gen/_setjmp.S. */
124static int amd64fbsd_jmp_buf_reg_offset[] =
125{
126 -1, /* %rax */
127 1 * 8, /* %rbx */
128 -1, /* %rcx */
129 -1, /* %rdx */
130 -1, /* %rsi */
131 -1, /* %rdi */
132 3 * 8, /* %rbp */
133 2 * 8, /* %rsp */
134 -1, /* %r8 ... */
135 -1,
136 -1,
137 -1, /* ... %r11 */
138 4 * 8, /* %r12 ... */
139 5 * 8,
140 6 * 8,
141 7 * 8, /* ... %r15 */
142 0 * 8 /* %rip */
143};
144
145static void
146amd64fbsd_supply_uthread (struct regcache *regcache,
147 int regnum, CORE_ADDR addr)
148{
4252dc94 149 gdb_byte buf[8];
1c02b2a5
MK
150 int i;
151
152 gdb_assert (regnum >= -1);
153
154 for (i = 0; i < ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset); i++)
155 {
156 if (amd64fbsd_jmp_buf_reg_offset[i] != -1
157 && (regnum == -1 || regnum == i))
158 {
159 read_memory (addr + amd64fbsd_jmp_buf_reg_offset[i], buf, 8);
160 regcache_raw_supply (regcache, i, buf);
161 }
162 }
163}
164
165static void
166amd64fbsd_collect_uthread (const struct regcache *regcache,
167 int regnum, CORE_ADDR addr)
168{
4252dc94 169 gdb_byte buf[8];
1c02b2a5
MK
170 int i;
171
172 gdb_assert (regnum >= -1);
173
174 for (i = 0; i < ARRAY_SIZE (amd64fbsd_jmp_buf_reg_offset); i++)
175 {
176 if (amd64fbsd_jmp_buf_reg_offset[i] != -1
177 && (regnum == -1 || regnum == i))
178 {
179 regcache_raw_collect (regcache, i, buf);
180 write_memory (addr + amd64fbsd_jmp_buf_reg_offset[i], buf, 8);
181 }
182 }
183}
184
68cc0bfb
MK
185void
186amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
187{
188 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
189
190 /* Obviously FreeBSD is BSD-based. */
191 i386bsd_init_abi (info, gdbarch);
192
477f40d1
MK
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;
196
90f90721 197 amd64_init_abi (info, gdbarch);
68cc0bfb 198
10fc94a4
MK
199 tdep->sigtramp_start = amd64fbsd_sigtramp_start_addr;
200 tdep->sigtramp_end = amd64fbsd_sigtramp_end_addr;
68cc0bfb
MK
201 tdep->sigcontext_addr = amd64fbsd_sigcontext_addr;
202 tdep->sc_reg_offset = amd64fbsd_sc_reg_offset;
477f40d1 203 tdep->sc_num_regs = ARRAY_SIZE (amd64fbsd_sc_reg_offset);
7e654c37 204
1c02b2a5
MK
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);
208
7e654c37
MK
209 /* FreeBSD uses SVR4-style shared libraries. */
210 set_solib_svr4_fetch_link_map_offsets
211 (gdbarch, svr4_lp64_fetch_link_map_offsets);
68cc0bfb
MK
212}
213\f
214
215/* Provide a prototype to silence -Wmissing-prototypes. */
216void _initialize_amd64fbsd_tdep (void);
217
218void
219_initialize_amd64fbsd_tdep (void)
220{
221 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
222 GDB_OSABI_FREEBSD_ELF, amd64fbsd_init_abi);
223}