* amd64-tdep.c (amd64_supply_fxsave): Only fiddle with
[deliverable/binutils-gdb.git] / gdb / amd64obsd-tdep.c
CommitLineData
e2879ccb
MK
1/* Target-dependent code for OpenBSD/amd64.
2
3 Copyright 2003, 2004 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 "frame.h"
24#include "gdbcore.h"
911bc6ee
MK
25#include "symtab.h"
26#include "objfiles.h"
e2879ccb 27#include "osabi.h"
30b344b1 28#include "regset.h"
e2879ccb
MK
29#include "target.h"
30
31#include "gdb_assert.h"
32#include "gdb_string.h"
33
85be1ca6 34#include "amd64-tdep.h"
30b344b1 35#include "i387-tdep.h"
7e654c37 36#include "solib-svr4.h"
30b344b1
MK
37
38/* Support for core dumps. */
39
40static void
41amd64obsd_supply_regset (const struct regset *regset,
42 struct regcache *regcache, int regnum,
43 const void *regs, size_t len)
44{
45 const struct gdbarch_tdep *tdep = regset->descr;
46
47 gdb_assert (len >= tdep->sizeof_gregset + I387_SIZEOF_FXSAVE);
48
49 i386_supply_gregset (regset, regcache, regnum, regs, tdep->sizeof_gregset);
90f90721 50 amd64_supply_fxsave (regcache, regnum, (char *)regs + tdep->sizeof_gregset);
30b344b1
MK
51}
52
53static const struct regset *
54amd64obsd_regset_from_core_section (struct gdbarch *gdbarch,
55 const char *sect_name, size_t sect_size)
56{
57 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
58
59 /* OpenBSD core dumps don't use seperate register sets for the
60 general-purpose and floating-point registers. */
61
62 if (strcmp (sect_name, ".reg") == 0
63 && sect_size >= tdep->sizeof_gregset + I387_SIZEOF_FXSAVE)
64 {
65 if (tdep->gregset == NULL)
66 {
67 tdep->gregset = XMALLOC (struct regset);
68 tdep->gregset->descr = tdep;
69 tdep->gregset->supply_regset = amd64obsd_supply_regset;
70 }
71 return tdep->gregset;
72 }
73
74 return NULL;
75}
76\f
e2879ccb
MK
77
78/* Support for signal handlers. */
79
911bc6ee 80/* Default page size. */
e2879ccb
MK
81static const int amd64obsd_page_size = 4096;
82
911bc6ee
MK
83/* Return whether the frame preciding NEXT_FRAME corresponds to an
84 OpenBSD sigtramp routine. */
85
e2879ccb 86static int
911bc6ee 87amd64obsd_sigtramp_p (struct frame_info *next_frame)
e2879ccb 88{
911bc6ee 89 CORE_ADDR pc = frame_pc_unwind (next_frame);
e2879ccb
MK
90 CORE_ADDR start_pc = (pc & ~(amd64obsd_page_size - 1));
91 const char sigreturn[] =
92 {
93 0x48, 0xc7, 0xc0,
94 0x67, 0x00, 0x00, 0x00, /* movq $SYS_sigreturn, %rax */
84d04465 95 0xcd, 0x80 /* int $0x80 */
e2879ccb 96 };
911bc6ee
MK
97 char *name, *buf;
98
99 /* If the function has a valid symbol name, it isn't a
100 trampoline. */
101 find_pc_partial_function (pc, &name, NULL, NULL);
102 if (name != NULL)
103 return 0;
e2879ccb 104
911bc6ee
MK
105 /* If the function lives in a valid section (even without a starting
106 point) it isn't a trampoline. */
107 if (find_pc_section (pc) != NULL)
e2879ccb
MK
108 return 0;
109
110 /* If we can't read the instructions at START_PC, return zero. */
111 buf = alloca (sizeof sigreturn);
112 if (target_read_memory (start_pc + 0x7, buf, sizeof sigreturn))
113 return 0;
114
115 /* Check for sigreturn(2). */
116 if (memcmp (buf, sigreturn, sizeof sigreturn))
117 return 0;
118
119 return 1;
120}
121
122/* Assuming NEXT_FRAME is for a frame following a BSD sigtramp
123 routine, return the address of the associated sigcontext structure. */
124
125static CORE_ADDR
126amd64obsd_sigcontext_addr (struct frame_info *next_frame)
127{
128 /* The %rsp register points at `struct sigcontext' upon entry of a
129 signal trampoline. */
90f90721 130 return frame_unwind_register_unsigned (next_frame, AMD64_RSP_REGNUM);
e2879ccb
MK
131}
132\f
133/* OpenBSD 3.5 or later. */
134
135/* Mapping between the general-purpose registers in `struct reg'
136 format and GDB's register cache layout. */
137
30b344b1 138/* From <machine/reg.h>. */
e2879ccb
MK
139int amd64obsd_r_reg_offset[] =
140{
141 14 * 8, /* %rax */
142 13 * 8, /* %rbx */
143 3 * 8, /* %rcx */
144 2 * 8, /* %rdx */
145 1 * 8, /* %rsi */
146 0 * 8, /* %rdi */
147 12 * 8, /* %rbp */
148 15 * 8, /* %rsp */
149 4 * 8, /* %r8 .. */
150 5 * 8,
151 6 * 8,
152 7 * 8,
153 8 * 8,
154 9 * 8,
155 10 * 8,
156 11 * 8, /* ... %r15 */
157 16 * 8, /* %rip */
158 17 * 8, /* %eflags */
159 18 * 8, /* %cs */
160 19 * 8, /* %ss */
161 20 * 8, /* %ds */
162 21 * 8, /* %es */
163 22 * 8, /* %fs */
164 23 * 8 /* %gs */
165};
166
30b344b1 167/* From <machine/signal.h>. */
e2879ccb
MK
168static int amd64obsd_sc_reg_offset[] =
169{
170 14 * 8, /* %rax */
171 13 * 8, /* %rbx */
172 3 * 8, /* %rcx */
173 2 * 8, /* %rdx */
174 1 * 8, /* %rsi */
175 0 * 8, /* %rdi */
176 12 * 8, /* %rbp */
177 24 * 8, /* %rsp */
178 4 * 8, /* %r8 ... */
179 5 * 8,
180 6 * 8,
181 7 * 8,
182 8 * 8,
183 9 * 8,
184 10 * 8,
185 11 * 8, /* ... %r15 */
186 21 * 8, /* %rip */
187 23 * 8, /* %eflags */
188 22 * 8, /* %cs */
189 25 * 8, /* %ss */
190 18 * 8, /* %ds */
191 17 * 8, /* %es */
192 16 * 8, /* %fs */
193 15 * 8 /* %gs */
194};
195
196static void
197amd64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
198{
199 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
200
90f90721 201 amd64_init_abi (info, gdbarch);
e2879ccb 202
30b344b1
MK
203 /* Initialize general-purpose register set details. */
204 tdep->gregset_reg_offset = amd64obsd_r_reg_offset;
205 tdep->gregset_num_regs = ARRAY_SIZE (amd64obsd_r_reg_offset);
206 tdep->sizeof_gregset = 24 * 8;
207
208 set_gdbarch_regset_from_core_section (gdbarch,
209 amd64obsd_regset_from_core_section);
210
e2879ccb
MK
211 tdep->jb_pc_offset = 7 * 8;
212
911bc6ee 213 tdep->sigtramp_p = amd64obsd_sigtramp_p;
e2879ccb
MK
214 tdep->sigcontext_addr = amd64obsd_sigcontext_addr;
215 tdep->sc_reg_offset = amd64obsd_sc_reg_offset;
216 tdep->sc_num_regs = ARRAY_SIZE (amd64obsd_sc_reg_offset);
7e654c37
MK
217
218 /* OpenBSD uses SVR4-style shared libraries. */
219 set_solib_svr4_fetch_link_map_offsets
220 (gdbarch, svr4_lp64_fetch_link_map_offsets);
e2879ccb
MK
221}
222\f
223
224/* Provide a prototype to silence -Wmissing-prototypes. */
225void _initialize_amd64obsd_tdep (void);
226
227void
30b344b1 228_initialize_amd64obsd_tdep (void)
e2879ccb
MK
229{
230 /* The OpenBSD/amd64 native dependent code makes this assumption. */
90f90721 231 gdb_assert (ARRAY_SIZE (amd64obsd_r_reg_offset) == AMD64_NUM_GREGS);
e2879ccb
MK
232
233 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
234 GDB_OSABI_OPENBSD_ELF, amd64obsd_init_abi);
30b344b1
MK
235
236 /* OpenBSD uses traditional (a.out) NetBSD-style core dumps. */
237 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
238 GDB_OSABI_NETBSD_AOUT, amd64obsd_init_abi);
e2879ccb 239}
This page took 0.041881 seconds and 4 git commands to generate.