1 /* Target-dependent code for OpenBSD/amd64.
3 Copyright 2003, 2004 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. */
28 #include "gdb_assert.h"
29 #include "gdb_string.h"
31 #include "x86-64-tdep.h"
33 /* Support for signal handlers. */
35 static const int amd64obsd_page_size = 4096;
38 amd64obsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
40 CORE_ADDR start_pc = (pc & ~(amd64obsd_page_size - 1));
41 const char sigreturn[] =
44 0x67, 0x00, 0x00, 0x00, /* movq $SYS_sigreturn, %rax */
45 0x0f, 0x05 /* syscall */
52 /* If we can't read the instructions at START_PC, return zero. */
53 buf = alloca (sizeof sigreturn);
54 if (target_read_memory (start_pc + 0x7, buf, sizeof sigreturn))
57 /* Check for sigreturn(2). */
58 if (memcmp (buf, sigreturn, sizeof sigreturn))
64 /* Assuming NEXT_FRAME is for a frame following a BSD sigtramp
65 routine, return the address of the associated sigcontext structure. */
68 amd64obsd_sigcontext_addr (struct frame_info *next_frame)
70 /* The %rsp register points at `struct sigcontext' upon entry of a
72 return frame_unwind_register_unsigned (next_frame, X86_64_RSP_REGNUM);
75 /* OpenBSD 3.5 or later. */
77 /* Mapping between the general-purpose registers in `struct reg'
78 format and GDB's register cache layout. */
80 /* From <machine/reg.h>. Used for ptrace(2), but not for core dumps. */
81 int amd64obsd_r_reg_offset[] =
98 11 * 8, /* ... %r15 */
100 17 * 8, /* %eflags */
109 /* From <machine/signal.h>. Also used for core dumps. */
110 static int amd64obsd_sc_reg_offset[] =
127 11 * 8, /* ... %r15 */
129 23 * 8, /* %eflags */
139 amd64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
141 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
143 /* Initialize general-purpose register set details first. */
144 tdep->gregset_reg_offset = amd64obsd_sc_reg_offset;
145 tdep->gregset_num_regs = ARRAY_SIZE (amd64obsd_sc_reg_offset);
146 tdep->sizeof_gregset = 26 * 8;
148 x86_64_init_abi (info, gdbarch);
150 tdep->jb_pc_offset = 7 * 8;
152 set_gdbarch_pc_in_sigtramp (gdbarch, amd64obsd_pc_in_sigtramp);
153 tdep->sigcontext_addr = amd64obsd_sigcontext_addr;
154 tdep->sc_reg_offset = amd64obsd_sc_reg_offset;
155 tdep->sc_num_regs = ARRAY_SIZE (amd64obsd_sc_reg_offset);
159 /* Provide a prototype to silence -Wmissing-prototypes. */
160 void _initialize_amd64obsd_tdep (void);
163 _initialize_amd64obsd_ndep (void)
165 /* The OpenBSD/amd64 native dependent code makes this assumption. */
166 gdb_assert (ARRAY_SIZE (amd64obsd_r_reg_offset) == X86_64_NUM_GREGS);
168 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
169 GDB_OSABI_OPENBSD_ELF, amd64obsd_init_abi);