Commit | Line | Data |
---|---|---|
68cc0bfb | 1 | /* Target-dependent code for FreeBSD/amd64. |
477f40d1 | 2 | |
68cc0bfb MK |
3 | Copyright 2003 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 "frame.h" | |
25 | #include "gdbcore.h" | |
26 | #include "regcache.h" | |
27 | #include "osabi.h" | |
28 | ||
29 | #include "gdb_string.h" | |
30 | ||
31 | #include "x86-64-tdep.h" | |
32 | ||
33 | /* Support for signal handlers. */ | |
34 | ||
35 | /* Assuming NEXT_FRAME is for a frame following a BSD sigtramp | |
36 | routine, return the address of the associated sigcontext structure. */ | |
37 | ||
38 | static CORE_ADDR | |
39 | amd64fbsd_sigcontext_addr (struct frame_info *next_frame) | |
40 | { | |
68cc0bfb MK |
41 | CORE_ADDR sp; |
42 | ||
212c460c MK |
43 | /* The `struct sigcontext' (which really is an `ucontext_t' on |
44 | FreeBSD/amd64) lives at a fixed offset in the signal frame. See | |
45 | <machine/sigframe.h>. */ | |
46 | sp = frame_unwind_register_unsigned (next_frame, X86_64_RSP_REGNUM); | |
47 | return sp + 16; | |
68cc0bfb MK |
48 | } |
49 | \f | |
50 | /* FreeBSD 5.1-RELEASE or later. */ | |
51 | ||
477f40d1 MK |
52 | /* Mapping between the general-purpose registers in `struct reg' |
53 | format and GDB's register cache layout. | |
54 | ||
55 | Note that some registers are 32-bit, but since we're little-endian | |
56 | we get away with that. */ | |
57 | ||
58 | /* From <machine/reg.h>. */ | |
59 | static int amd64fbsd_r_reg_offset[] = | |
60 | { | |
61 | 14 * 8, 11 * 8, /* %rax, %rbx */ | |
62 | 13 * 8, 12 * 8, /* %rcx, %rdx */ | |
63 | 9 * 8, 8 * 8, /* %rsi, %rdi */ | |
64 | 10 * 8, 20 * 8, /* %rbp, %rsp */ | |
65 | 7 * 8, 6 * 8, 5 * 8, 4 * 8, /* %r8 ... */ | |
66 | 3 * 8, 2 * 8, 1 * 8, 0 * 8, /* ... %r15 */ | |
67 | 17 * 8, 19 * 8, /* %rip, %eflags */ | |
68 | -1, -1, /* %ds, %es */ | |
69 | -1, -1 /* %fs, %gs */ | |
70 | }; | |
71 | ||
68cc0bfb | 72 | /* Location of the signal trampoline. */ |
212c460c MK |
73 | CORE_ADDR amd64fbsd_sigtramp_start = 0x7fffffffffc0; |
74 | CORE_ADDR amd64fbsd_sigtramp_end = 0x7fffffffffe0; | |
68cc0bfb MK |
75 | |
76 | /* From <machine/signal.h>. */ | |
77 | int amd64fbsd_sc_reg_offset[X86_64_NUM_GREGS] = | |
78 | { | |
212c460c MK |
79 | 24 + 6 * 8, /* %rax */ |
80 | 24 + 7 * 8, /* %rbx */ | |
81 | 24 + 3 * 8, /* %rcx */ | |
82 | 24 + 2 * 8, /* %rdx */ | |
83 | 24 + 1 * 8, /* %rsi */ | |
84 | 24 + 0 * 8, /* %rdi */ | |
85 | 24 + 8 * 8, /* %rbp */ | |
86 | 24 + 21 * 8, /* %rsp */ | |
87 | 24 + 4 * 8, /* %r8 */ | |
88 | 24 + 5 * 8, /* %r9 */ | |
89 | 24 + 9 * 8, /* %r10 */ | |
90 | 24 + 10 * 8, /* %r11 */ | |
91 | 24 + 11 * 8, /* %r12 */ | |
92 | 24 + 12 * 8, /* %r13 */ | |
93 | 24 + 13 * 8, /* %r14 */ | |
94 | 24 + 14 * 8, /* %r15 */ | |
95 | 24 + 18 * 8, /* %rip */ | |
96 | 24 + 20 * 8, /* %eflags */ | |
68cc0bfb MK |
97 | -1, /* %ds */ |
98 | -1, /* %es */ | |
99 | -1, /* %fs */ | |
100 | -1 /* %gs */ | |
101 | }; | |
102 | ||
103 | void | |
104 | amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
105 | { | |
106 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
107 | ||
108 | /* Obviously FreeBSD is BSD-based. */ | |
109 | i386bsd_init_abi (info, gdbarch); | |
110 | ||
477f40d1 MK |
111 | tdep->gregset_reg_offset = amd64fbsd_r_reg_offset; |
112 | tdep->gregset_num_regs = ARRAY_SIZE (amd64fbsd_r_reg_offset); | |
113 | tdep->sizeof_gregset = 22 * 8; | |
114 | ||
68cc0bfb MK |
115 | x86_64_init_abi (info, gdbarch); |
116 | ||
117 | tdep->sigtramp_start = amd64fbsd_sigtramp_start; | |
212c460c | 118 | tdep->sigtramp_end = amd64fbsd_sigtramp_end; |
68cc0bfb MK |
119 | tdep->sigcontext_addr = amd64fbsd_sigcontext_addr; |
120 | tdep->sc_reg_offset = amd64fbsd_sc_reg_offset; | |
477f40d1 | 121 | tdep->sc_num_regs = ARRAY_SIZE (amd64fbsd_sc_reg_offset); |
68cc0bfb MK |
122 | } |
123 | \f | |
124 | ||
125 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
126 | void _initialize_amd64fbsd_tdep (void); | |
127 | ||
128 | void | |
129 | _initialize_amd64fbsd_tdep (void) | |
130 | { | |
131 | gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, | |
132 | GDB_OSABI_FREEBSD_ELF, amd64fbsd_init_abi); | |
133 | } |