*** empty log message ***
[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"
27
28#include "gdb_assert.h"
29
85be1ca6 30#include "amd64-tdep.h"
7e654c37
MK
31#include "nbsd-tdep.h"
32#include "solib-svr4.h"
cced5e27
MK
33
34/* Support for signal handlers. */
35
36/* Assuming NEXT_FRAME is for a frame following a BSD sigtramp
37 routine, return the address of the associated sigcontext structure. */
38
39static CORE_ADDR
40amd64nbsd_sigcontext_addr (struct frame_info *next_frame)
41{
42 CORE_ADDR sp;
43
44 /* The stack pointer points at `struct sigcontext' upon entry of a
45 signal trampoline. */
90f90721 46 sp = frame_unwind_register_unsigned (next_frame, AMD64_RSP_REGNUM);
cced5e27
MK
47 return sp;
48}
49\f
50/* NetBSD 2.0 or later. */
51
52/* Mapping between the general-purpose registers in `struct reg'
53 format and GDB's register cache layout. */
54
55/* From <machine/reg.h>. */
56int amd64nbsd_r_reg_offset[] =
57{
58 14 * 8, /* %rax */
59 13 * 8, /* %rbx */
60 3 * 8, /* %rcx */
61 2 * 8, /* %rdx */
62 1 * 8, /* %rsi */
63 0 * 8, /* %rdi */
64 12 * 8, /* %rbp */
65 24 * 8, /* %rsp */
66 4 * 8, /* %r8 .. */
67 5 * 8,
68 6 * 8,
69 7 * 8,
70 8 * 8,
71 9 * 8,
72 10 * 8,
73 11 * 8, /* ... %r15 */
74 21 * 8, /* %rip */
75 23 * 8, /* %eflags */
af233647
MK
76 22 * 8, /* %cs */
77 25 * 8, /* %ss */
cced5e27
MK
78 18 * 8, /* %ds */
79 17 * 8, /* %es */
80 16 * 8, /* %fs */
81 15 * 8 /* %gs */
82};
83
84static void
85amd64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
86{
87 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
88 int *sc_reg_offset;
89 int i;
90
91 /* Initialize general-purpose register set details first. */
92 tdep->gregset_reg_offset = amd64nbsd_r_reg_offset;
93 tdep->gregset_num_regs = ARRAY_SIZE (amd64nbsd_r_reg_offset);
94 tdep->sizeof_gregset = 26 * 8;
95
90f90721 96 amd64_init_abi (info, gdbarch);
cced5e27
MK
97
98 tdep->jb_pc_offset = 7 * 8;
99
100 /* NetBSD has its own convention for signal trampolines. */
101 set_gdbarch_pc_in_sigtramp (gdbarch, nbsd_pc_in_sigtramp);
7e654c37 102 tdep->sigcontext_addr = amd64nbsd_sigcontext_addr;
cced5e27
MK
103
104 /* Initialize the array with register offsets in `struct
105 sigcontext'. This `struct sigcontext' has an sc_mcontext member
106 at offset 32, and in <machine/reg.h> we have an explicit comment
107 saying that `struct reg' is the same as mcontext.__gregs. */
108 tdep->sc_num_regs = ARRAY_SIZE (amd64nbsd_r_reg_offset);
109 tdep->sc_reg_offset = XCALLOC (tdep->sc_num_regs, int);
110 for (i = 0; i < tdep->sc_num_regs; i++)
111 {
112 if (amd64nbsd_r_reg_offset[i] < 0)
113 tdep->sc_reg_offset[i] = -1;
114 else
115 tdep->sc_reg_offset[i] = 32 + amd64nbsd_r_reg_offset[i];
116 }
117
7e654c37
MK
118 /* NetBSD uses SVR4-style shared libraries. */
119 set_solib_svr4_fetch_link_map_offsets
120 (gdbarch, svr4_lp64_fetch_link_map_offsets);
cced5e27
MK
121}
122\f
123
124/* Provide a prototype to silence -Wmissing-prototypes. */
125void _initialize_amd64nbsd_tdep (void);
126
127void
128_initialize_amd64nbsd_ndep (void)
129{
130 /* The NetBSD/amd64 native dependent code makes this assumption. */
90f90721 131 gdb_assert (ARRAY_SIZE (amd64nbsd_r_reg_offset) == AMD64_NUM_GREGS);
cced5e27
MK
132
133 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
134 GDB_OSABI_NETBSD_ELF, amd64nbsd_init_abi);
135}
This page took 0.051419 seconds and 4 git commands to generate.