Sort includes for files gdb/[a-f]*.[chyl].
[deliverable/binutils-gdb.git] / gdb / amd64-nbsd-tdep.c
CommitLineData
cced5e27
MK
1/* Target-dependent code for NetBSD/amd64.
2
42a4f53d 3 Copyright (C) 2003-2019 Free Software Foundation, Inc.
cced5e27
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
cced5e27
MK
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
cced5e27
MK
19
20#include "defs.h"
cced5e27 21
d55e5aa6 22/* Local non-gdb includes. */
85be1ca6 23#include "amd64-tdep.h"
d55e5aa6 24#include "arch-utils.h"
0747795c 25#include "common/x86-xstate.h"
d55e5aa6
TT
26#include "frame.h"
27#include "gdbcore.h"
7e654c37 28#include "nbsd-tdep.h"
d55e5aa6 29#include "osabi.h"
7e654c37 30#include "solib-svr4.h"
d55e5aa6 31#include "symtab.h"
cced5e27
MK
32
33/* Support for signal handlers. */
34
10458914
DJ
35/* Return whether THIS_FRAME corresponds to a NetBSD sigtramp
36 routine. */
911bc6ee
MK
37
38static int
10458914 39amd64nbsd_sigtramp_p (struct frame_info *this_frame)
911bc6ee 40{
10458914 41 CORE_ADDR pc = get_frame_pc (this_frame);
2c02bd72 42 const char *name;
911bc6ee
MK
43
44 find_pc_partial_function (pc, &name, NULL, NULL);
45 return nbsd_pc_in_sigtramp (pc, name);
46}
47
10458914
DJ
48/* Assuming THIS_FRAME corresponds to a NetBSD sigtramp routine,
49 return the address of the associated mcontext structure. */
cced5e27
MK
50
51static CORE_ADDR
10458914 52amd64nbsd_mcontext_addr (struct frame_info *this_frame)
cced5e27 53{
fa34704a 54 CORE_ADDR addr;
cced5e27 55
fa34704a 56 /* The register %r15 points at `struct ucontext' upon entry of a
cced5e27 57 signal trampoline. */
10458914 58 addr = get_frame_register_unsigned (this_frame, AMD64_R15_REGNUM);
fa34704a
MK
59
60 /* The mcontext structure lives as offset 56 in `struct ucontext'. */
61 return addr + 56;
cced5e27
MK
62}
63\f
64/* NetBSD 2.0 or later. */
65
66/* Mapping between the general-purpose registers in `struct reg'
67 format and GDB's register cache layout. */
68
69/* From <machine/reg.h>. */
70int amd64nbsd_r_reg_offset[] =
71{
72 14 * 8, /* %rax */
73 13 * 8, /* %rbx */
74 3 * 8, /* %rcx */
75 2 * 8, /* %rdx */
76 1 * 8, /* %rsi */
77 0 * 8, /* %rdi */
78 12 * 8, /* %rbp */
79 24 * 8, /* %rsp */
0963b4bd 80 4 * 8, /* %r8 .. */
cced5e27
MK
81 5 * 8,
82 6 * 8,
83 7 * 8,
84 8 * 8,
85 9 * 8,
86 10 * 8,
87 11 * 8, /* ... %r15 */
88 21 * 8, /* %rip */
89 23 * 8, /* %eflags */
af233647
MK
90 22 * 8, /* %cs */
91 25 * 8, /* %ss */
cced5e27
MK
92 18 * 8, /* %ds */
93 17 * 8, /* %es */
94 16 * 8, /* %fs */
95 15 * 8 /* %gs */
96};
97
98static void
99amd64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
100{
101 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
cced5e27
MK
102
103 /* Initialize general-purpose register set details first. */
104 tdep->gregset_reg_offset = amd64nbsd_r_reg_offset;
105 tdep->gregset_num_regs = ARRAY_SIZE (amd64nbsd_r_reg_offset);
106 tdep->sizeof_gregset = 26 * 8;
107
2434b019 108 amd64_init_abi (info, gdbarch,
41206e32 109 amd64_target_description (X86_XSTATE_SSE_MASK, true));
cced5e27
MK
110
111 tdep->jb_pc_offset = 7 * 8;
112
113 /* NetBSD has its own convention for signal trampolines. */
911bc6ee 114 tdep->sigtramp_p = amd64nbsd_sigtramp_p;
fa34704a
MK
115 tdep->sigcontext_addr = amd64nbsd_mcontext_addr;
116 tdep->sc_reg_offset = amd64nbsd_r_reg_offset;
cced5e27 117 tdep->sc_num_regs = ARRAY_SIZE (amd64nbsd_r_reg_offset);
cced5e27 118
7e654c37
MK
119 /* NetBSD uses SVR4-style shared libraries. */
120 set_solib_svr4_fetch_link_map_offsets
121 (gdbarch, svr4_lp64_fetch_link_map_offsets);
cced5e27 122}
cced5e27
MK
123
124void
63807e1d 125_initialize_amd64nbsd_tdep (void)
cced5e27
MK
126{
127 /* The NetBSD/amd64 native dependent code makes this assumption. */
90f90721 128 gdb_assert (ARRAY_SIZE (amd64nbsd_r_reg_offset) == AMD64_NUM_GREGS);
cced5e27
MK
129
130 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
1736a7bd 131 GDB_OSABI_NETBSD, amd64nbsd_init_abi);
cced5e27 132}
This page took 0.887453 seconds and 4 git commands to generate.