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