* amd64-tdep.c (amd64_supply_fxsave): Only fiddle with
[deliverable/binutils-gdb.git] / gdb / amd64nbsd-tdep.c
CommitLineData
cced5e27
MK
1/* Target-dependent code for NetBSD/amd64.
2
af233647 3 Copyright 2003, 2004 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
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 "osabi.h"
911bc6ee 27#include "symtab.h"
cced5e27
MK
28
29#include "gdb_assert.h"
30
85be1ca6 31#include "amd64-tdep.h"
7e654c37
MK
32#include "nbsd-tdep.h"
33#include "solib-svr4.h"
cced5e27
MK
34
35/* Support for signal handlers. */
36
911bc6ee
MK
37/* Return whether the frame preciding NEXT_FRAME corresponds to a
38 NetBSD sigtramp routine. */
39
40static int
41amd64nbsd_sigtramp_p (struct frame_info *next_frame)
42{
43 CORE_ADDR pc = frame_pc_unwind (next_frame);
44 char *name;
45
46 find_pc_partial_function (pc, &name, NULL, NULL);
47 return nbsd_pc_in_sigtramp (pc, name);
48}
49
cced5e27
MK
50/* Assuming NEXT_FRAME is for a frame following a BSD sigtramp
51 routine, return the address of the associated sigcontext structure. */
52
53static CORE_ADDR
54amd64nbsd_sigcontext_addr (struct frame_info *next_frame)
55{
56 CORE_ADDR sp;
57
58 /* The stack pointer points at `struct sigcontext' upon entry of a
59 signal trampoline. */
90f90721 60 sp = frame_unwind_register_unsigned (next_frame, AMD64_RSP_REGNUM);
cced5e27
MK
61 return sp;
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 */
80 4 * 8, /* %r8 .. */
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);
102 int *sc_reg_offset;
103 int i;
104
105 /* Initialize general-purpose register set details first. */
106 tdep->gregset_reg_offset = amd64nbsd_r_reg_offset;
107 tdep->gregset_num_regs = ARRAY_SIZE (amd64nbsd_r_reg_offset);
108 tdep->sizeof_gregset = 26 * 8;
109
90f90721 110 amd64_init_abi (info, gdbarch);
cced5e27
MK
111
112 tdep->jb_pc_offset = 7 * 8;
113
114 /* NetBSD has its own convention for signal trampolines. */
911bc6ee 115 tdep->sigtramp_p = amd64nbsd_sigtramp_p;
7e654c37 116 tdep->sigcontext_addr = amd64nbsd_sigcontext_addr;
cced5e27
MK
117
118 /* Initialize the array with register offsets in `struct
119 sigcontext'. This `struct sigcontext' has an sc_mcontext member
120 at offset 32, and in <machine/reg.h> we have an explicit comment
121 saying that `struct reg' is the same as mcontext.__gregs. */
122 tdep->sc_num_regs = ARRAY_SIZE (amd64nbsd_r_reg_offset);
123 tdep->sc_reg_offset = XCALLOC (tdep->sc_num_regs, int);
124 for (i = 0; i < tdep->sc_num_regs; i++)
125 {
126 if (amd64nbsd_r_reg_offset[i] < 0)
127 tdep->sc_reg_offset[i] = -1;
128 else
129 tdep->sc_reg_offset[i] = 32 + amd64nbsd_r_reg_offset[i];
130 }
131
7e654c37
MK
132 /* NetBSD uses SVR4-style shared libraries. */
133 set_solib_svr4_fetch_link_map_offsets
134 (gdbarch, svr4_lp64_fetch_link_map_offsets);
cced5e27
MK
135}
136\f
137
138/* Provide a prototype to silence -Wmissing-prototypes. */
139void _initialize_amd64nbsd_tdep (void);
140
141void
142_initialize_amd64nbsd_ndep (void)
143{
144 /* The NetBSD/amd64 native dependent code makes this assumption. */
90f90721 145 gdb_assert (ARRAY_SIZE (amd64nbsd_r_reg_offset) == AMD64_NUM_GREGS);
cced5e27
MK
146
147 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
148 GDB_OSABI_NETBSD_ELF, amd64nbsd_init_abi);
149}
This page took 0.059021 seconds and 4 git commands to generate.