gdb - Local mods (compile)
[dragonfly.git] / contrib / gdb-7 / amd64dfly-tdep.c
1 /* Target-dependent code for DragonFly/amd64.
2
3    Copyright (C) 2003-2013 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 3 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, see <http://www.gnu.org/licenses/>.  */
19
20 #include "defs.h"
21 #include "arch-utils.h"
22 #include "frame.h"
23 #include "gdbcore.h"
24 #include "regcache.h"
25 #include "osabi.h"
26
27 #include "gdb_assert.h"
28 #include "gdb_string.h"
29
30 #include "amd64-tdep.h"
31 #include "solib-svr4.h"
32
33 /* Support for signal handlers.  */
34
35 /* Assuming THIS_FRAME is for a BSD sigtramp routine, return the
36    address of the associated sigcontext structure.  */
37
38 static CORE_ADDR
39 amd64dfly_sigcontext_addr (struct frame_info *this_frame)
40 {
41   struct gdbarch *gdbarch = get_frame_arch (this_frame);
42   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
43   CORE_ADDR sp;
44   gdb_byte buf[8];
45
46   /* The `struct sigcontext' (which really is an `ucontext_t' on
47      DragonFly/amd64) lives at a fixed offset in the signal frame.  See
48      <machine/sigframe.h>.  */
49   get_frame_register (this_frame, AMD64_RSP_REGNUM, buf);
50   sp = extract_unsigned_integer (buf, 8, byte_order);
51   return sp + 16;
52 }
53 \f
54 /* Mapping between the general-purpose registers in `struct reg'
55    format and GDB's register cache layout.
56
57    Note that some registers are 32-bit, but since we're little-endian
58    we get away with that.  */
59
60 /* From <machine/reg.h>.  */
61 static int amd64dfly_r_reg_offset[] =
62 {
63   6 * 8,                        /* %rax */
64   7 * 8,                        /* %rbx */
65   3 * 8,                        /* %rcx */
66   2 * 8,                        /* %rdx */
67   1 * 8,                        /* %rsi */
68   0 * 8,                        /* %rdi */
69   8 * 8,                        /* %rbp */
70   23 * 8,                       /* %rsp */
71   4 * 8,                        /* %r8 ... */
72   5 * 8,
73   9 * 8,
74   10 * 8,
75   11 * 8,
76   12 * 8,
77   13 * 8,
78   14 * 8,                       /* ... %r15 */
79   20 * 8,                       /* %rip */
80   22 * 8,                       /* %eflags */
81   21 * 8,                       /* %cs */
82   24 * 8,                       /* %ss */
83   -1,                           /* %ds */
84   -1,                           /* %es */
85   -1,                           /* %fs */
86   -1                            /* %gs */
87 };
88
89 /* Location of the signal trampoline.  */
90 CORE_ADDR amd64dfly_sigtramp_start_addr = 0x7fffffffffc0ULL;
91 CORE_ADDR amd64dfly_sigtramp_end_addr = 0x7fffffffffe0ULL;
92
93 /* From <machine/signal.h>.  */
94 int amd64dfly_sc_reg_offset[] =
95 {
96   24 + 6 * 8,                   /* %rax */
97   24 + 7 * 8,                   /* %rbx */
98   24 + 3 * 8,                   /* %rcx */
99   24 + 2 * 8,                   /* %rdx */
100   24 + 1 * 8,                   /* %rsi */
101   24 + 0 * 8,                   /* %rdi */
102   24 + 8 * 8,                   /* %rbp */
103   24 + 23 * 8,                  /* %rsp */
104   24 + 4 * 8,                   /* %r8 ... */
105   24 + 5 * 8,
106   24 + 9 * 8,
107   24 + 10 * 8,
108   24 + 11 * 8,
109   24 + 12 * 8,
110   24 + 13 * 8,
111   24 + 14 * 8,                  /* ... %r15 */
112   24 + 20 * 8,                  /* %rip */
113   24 + 22 * 8,                  /* %eflags */
114   24 + 21 * 8,                  /* %cs */
115   24 + 24 * 8,                  /* %ss */
116   -1,                           /* %ds */
117   -1,                           /* %es */
118   -1,                           /* %fs */
119   -1                            /* %gs */
120 };
121
122 /* From /usr/src/lib/libc/amd64/gen/_setjmp.S.  */
123 static int amd64dfly_jmp_buf_reg_offset[] =
124 {
125   -1,                           /* %rax */
126   1 * 8,                        /* %rbx */
127   -1,                           /* %rcx */
128   -1,                           /* %rdx */
129   -1,                           /* %rsi */
130   -1,                           /* %rdi */
131   3 * 8,                        /* %rbp */
132   2 * 8,                        /* %rsp */
133   -1,                           /* %r8 ... */
134   -1,
135   -1,
136   -1,                           /* ... %r11 */
137   4 * 8,                        /* %r12 ... */
138   5 * 8,
139   6 * 8,
140   7 * 8,                        /* ... %r15 */
141   0 * 8                         /* %rip */
142 };
143
144 static void
145 amd64dfly_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
146 {
147   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
148
149   i386bsd_init_abi (info, gdbarch);
150
151   tdep->gregset_reg_offset = amd64dfly_r_reg_offset;
152   tdep->gregset_num_regs = ARRAY_SIZE (amd64dfly_r_reg_offset);
153   tdep->sizeof_gregset = 25 * 8;
154
155   amd64_init_abi (info, gdbarch);
156
157   tdep->sigtramp_start = amd64dfly_sigtramp_start_addr;
158   tdep->sigtramp_end = amd64dfly_sigtramp_end_addr;
159   tdep->sigcontext_addr = amd64dfly_sigcontext_addr;
160   tdep->sc_reg_offset = amd64dfly_sc_reg_offset;
161   tdep->sc_num_regs = ARRAY_SIZE (amd64dfly_sc_reg_offset);
162
163   set_solib_svr4_fetch_link_map_offsets
164     (gdbarch, svr4_lp64_fetch_link_map_offsets);
165 }
166 \f
167
168 /* Provide a prototype to silence -Wmissing-prototypes.  */
169 void _initialize_amd64dfly_tdep (void);
170
171 void
172 _initialize_amd64dfly_tdep (void)
173 {
174   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
175                           GDB_OSABI_DRAGONFLY, amd64dfly_init_abi);
176 }