* amd64fbsd-tdep.c: Fix sigtramp recognition.
[binutils-gdb.git] / gdb / amd64fbsd-tdep.c
1 /* Target-dependent code for FreeBSD/amd64.
2 Copyright 2003 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include "defs.h"
22 #include "arch-utils.h"
23 #include "frame.h"
24 #include "gdbcore.h"
25 #include "regcache.h"
26 #include "osabi.h"
27
28 #include "gdb_string.h"
29
30 #include "x86-64-tdep.h"
31
32 /* Support for signal handlers. */
33
34 /* Assuming NEXT_FRAME is for a frame following a BSD sigtramp
35 routine, return the address of the associated sigcontext structure. */
36
37 static CORE_ADDR
38 amd64fbsd_sigcontext_addr (struct frame_info *next_frame)
39 {
40 CORE_ADDR sp;
41
42 /* The `struct sigcontext' (which really is an `ucontext_t' on
43 FreeBSD/amd64) lives at a fixed offset in the signal frame. See
44 <machine/sigframe.h>. */
45 sp = frame_unwind_register_unsigned (next_frame, X86_64_RSP_REGNUM);
46 return sp + 16;
47 }
48 \f
49 /* FreeBSD 5.1-RELEASE or later. */
50
51 /* Location of the signal trampoline. */
52 CORE_ADDR amd64fbsd_sigtramp_start = 0x7fffffffffc0;
53 CORE_ADDR amd64fbsd_sigtramp_end = 0x7fffffffffe0;
54
55 /* From <machine/signal.h>. */
56 int amd64fbsd_sc_reg_offset[X86_64_NUM_GREGS] =
57 {
58 24 + 6 * 8, /* %rax */
59 24 + 7 * 8, /* %rbx */
60 24 + 3 * 8, /* %rcx */
61 24 + 2 * 8, /* %rdx */
62 24 + 1 * 8, /* %rsi */
63 24 + 0 * 8, /* %rdi */
64 24 + 8 * 8, /* %rbp */
65 24 + 21 * 8, /* %rsp */
66 24 + 4 * 8, /* %r8 */
67 24 + 5 * 8, /* %r9 */
68 24 + 9 * 8, /* %r10 */
69 24 + 10 * 8, /* %r11 */
70 24 + 11 * 8, /* %r12 */
71 24 + 12 * 8, /* %r13 */
72 24 + 13 * 8, /* %r14 */
73 24 + 14 * 8, /* %r15 */
74 24 + 18 * 8, /* %rip */
75 24 + 20 * 8, /* %eflags */
76 -1, /* %ds */
77 -1, /* %es */
78 -1, /* %fs */
79 -1 /* %gs */
80 };
81
82 void
83 amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
84 {
85 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
86
87 /* Obviously FreeBSD is BSD-based. */
88 i386bsd_init_abi (info, gdbarch);
89
90 x86_64_init_abi (info, gdbarch);
91
92 tdep->sigtramp_start = amd64fbsd_sigtramp_start;
93 tdep->sigtramp_end = amd64fbsd_sigtramp_end;
94 tdep->sigcontext_addr = amd64fbsd_sigcontext_addr;
95 tdep->sc_reg_offset = amd64fbsd_sc_reg_offset;
96 tdep->sc_num_regs = X86_64_NUM_GREGS;
97 }
98 \f
99
100 /* Provide a prototype to silence -Wmissing-prototypes. */
101 void _initialize_amd64fbsd_tdep (void);
102
103 void
104 _initialize_amd64fbsd_tdep (void)
105 {
106 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
107 GDB_OSABI_FREEBSD_ELF, amd64fbsd_init_abi);
108 }