Rename target descriptions to reflect actual content of description.
[deliverable/binutils-gdb.git] / gdb / gdbserver / linux-amd64-ipa.c
CommitLineData
fa593d66
PA
1/* GNU/Linux/x86-64 specific low level interface, for the in-process
2 agent library for GDB.
3
61baf725 4 Copyright (C) 2010-2017 Free Software Foundation, Inc.
fa593d66
PA
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21#include "server.h"
a13c4696 22#include <sys/mman.h>
7c3a12ca 23#include "tracepoint.h"
ae91f625 24#include "linux-x86-tdesc.h"
fa593d66
PA
25
26/* Defined in auto-generated file amd64-linux.c. */
27void init_registers_amd64_linux (void);
3aee8918 28extern const struct target_desc *tdesc_amd64_linux;
fa593d66
PA
29
30/* fast tracepoints collect registers. */
31
32#define FT_CR_RIP 0
33#define FT_CR_EFLAGS 1
34#define FT_CR_R8 2
35#define FT_CR_R9 3
36#define FT_CR_R10 4
37#define FT_CR_R11 5
38#define FT_CR_R12 6
39#define FT_CR_R13 7
40#define FT_CR_R14 8
41#define FT_CR_R15 9
42#define FT_CR_RAX 10
43#define FT_CR_RBX 11
44#define FT_CR_RCX 12
45#define FT_CR_RDX 13
46#define FT_CR_RSI 14
47#define FT_CR_RDI 15
48#define FT_CR_RBP 16
49#define FT_CR_RSP 17
50
51static const int x86_64_ft_collect_regmap[] = {
52 FT_CR_RAX * 8, FT_CR_RBX * 8, FT_CR_RCX * 8, FT_CR_RDX * 8,
53 FT_CR_RSI * 8, FT_CR_RDI * 8, FT_CR_RBP * 8, FT_CR_RSP * 8,
54 FT_CR_R8 * 8, FT_CR_R9 * 8, FT_CR_R10 * 8, FT_CR_R11 * 8,
55 FT_CR_R12 * 8, FT_CR_R13 * 8, FT_CR_R14 * 8, FT_CR_R15 * 8,
56 FT_CR_RIP * 8, FT_CR_EFLAGS * 8
57};
58
59#define X86_64_NUM_FT_COLLECT_GREGS \
60 (sizeof (x86_64_ft_collect_regmap) / sizeof(x86_64_ft_collect_regmap[0]))
61
62void
63supply_fast_tracepoint_registers (struct regcache *regcache,
64 const unsigned char *buf)
65{
66 int i;
67
68 for (i = 0; i < X86_64_NUM_FT_COLLECT_GREGS; i++)
69 supply_register (regcache, i,
70 ((char *) buf) + x86_64_ft_collect_regmap[i]);
71}
72
1cda1512
MK
73ULONGEST
74get_raw_reg (const unsigned char *raw_regs, int regnum)
6a271cae 75{
35f5825a 76 if (regnum >= X86_64_NUM_FT_COLLECT_GREGS)
6a271cae
PA
77 return 0;
78
79 return *(ULONGEST *) (raw_regs + x86_64_ft_collect_regmap[regnum]);
80}
81
0fb4aa4b
PA
82#ifdef HAVE_UST
83
84#include <ust/processor.h>
85
86/* "struct registers" is the UST object type holding the registers at
87 the time of the static tracepoint marker call. This doesn't
88 contain RIP, but we know what it must have been (the marker
89 address). */
90
91#define ST_REGENTRY(REG) \
92 { \
93 offsetof (struct registers, REG), \
94 sizeof (((struct registers *) NULL)->REG) \
95 }
96
97static struct
98{
99 int offset;
100 int size;
101} x86_64_st_collect_regmap[] =
102 {
103 ST_REGENTRY(rax),
104 ST_REGENTRY(rbx),
105 ST_REGENTRY(rcx),
106 ST_REGENTRY(rdx),
107 ST_REGENTRY(rsi),
108 ST_REGENTRY(rdi),
109 ST_REGENTRY(rbp),
110 ST_REGENTRY(rsp),
111 ST_REGENTRY(r8),
112 ST_REGENTRY(r9),
113 ST_REGENTRY(r10),
114 ST_REGENTRY(r11),
115 ST_REGENTRY(r12),
116 ST_REGENTRY(r13),
117 ST_REGENTRY(r14),
118 ST_REGENTRY(r15),
119 { -1, 0 },
120 ST_REGENTRY(rflags),
121 ST_REGENTRY(cs),
122 ST_REGENTRY(ss),
123 };
124
125#define X86_64_NUM_ST_COLLECT_GREGS \
126 (sizeof (x86_64_st_collect_regmap) / sizeof (x86_64_st_collect_regmap[0]))
127
128/* GDB's RIP register number. */
129#define AMD64_RIP_REGNUM 16
130
131void
132supply_static_tracepoint_registers (struct regcache *regcache,
133 const unsigned char *buf,
134 CORE_ADDR pc)
135{
136 int i;
137 unsigned long newpc = pc;
138
139 supply_register (regcache, AMD64_RIP_REGNUM, &newpc);
140
141 for (i = 0; i < X86_64_NUM_ST_COLLECT_GREGS; i++)
142 if (x86_64_st_collect_regmap[i].offset != -1)
143 {
144 switch (x86_64_st_collect_regmap[i].size)
145 {
146 case 8:
147 supply_register (regcache, i,
148 ((char *) buf)
149 + x86_64_st_collect_regmap[i].offset);
150 break;
151 case 2:
152 {
153 unsigned long reg
154 = * (short *) (((char *) buf)
155 + x86_64_st_collect_regmap[i].offset);
156 reg &= 0xffff;
157 supply_register (regcache, i, &reg);
158 }
159 break;
160 default:
161 internal_error (__FILE__, __LINE__,
162 "unhandled register size: %d",
163 x86_64_st_collect_regmap[i].size);
164 break;
165 }
166 }
167}
168
169#endif /* HAVE_UST */
170
ae91f625
MK
171/* Return target_desc to use for IPA, given the tdesc index passed by
172 gdbserver. */
173
174const struct target_desc *
175get_ipa_tdesc (int idx)
176{
201506da
PA
177#if defined __ILP32__
178 switch (idx)
179 {
180 case X86_TDESC_SSE:
181 return tdesc_x32_linux;
182 case X86_TDESC_AVX:
183 return tdesc_x32_avx_linux;
184 case X86_TDESC_AVX512:
185 return tdesc_x32_avx512_linux;
186 default:
187 break;
188 }
189#else
ae91f625
MK
190 switch (idx)
191 {
192 case X86_TDESC_SSE:
193 return tdesc_amd64_linux;
194 case X86_TDESC_AVX:
195 return tdesc_amd64_avx_linux;
196 case X86_TDESC_MPX:
197 return tdesc_amd64_mpx_linux;
2b863f51
WT
198 case X86_TDESC_AVX_MPX:
199 return tdesc_amd64_avx_mpx_linux;
22049425
MS
200 case X86_TDESC_AVX_MPX_AVX512:
201 return tdesc_amd64_avx_mpx_avx512_linux;
202 default:
203 internal_error (__FILE__, __LINE__,
204 "unknown ipa tdesc index: %d", idx);
205 return tdesc_amd64_linux;
ae91f625 206 }
201506da
PA
207#endif
208
209 internal_error (__FILE__, __LINE__,
210 "unknown ipa tdesc index: %d", idx);
ae91f625
MK
211}
212
9c235a72
PA
213/* Allocate buffer for the jump pads. The branch instruction has a
214 reach of +/- 31-bit, and the executable is loaded at low addresses.
215
216 64-bit: Use MAP_32BIT to allocate in the first 2GB. Shared
217 libraries, being allocated at the top, are unfortunately out of
218 luck.
219
220 x32: Since MAP_32BIT is 64-bit only, do the placement manually.
221 Try allocating at '0x80000000 - SIZE' initially, decreasing until
222 we hit a free area. This ensures the executable is fully covered,
223 and is as close as possible to the shared libraries, which are
224 usually mapped at the top of the first 4GB of the address space.
225*/
a13c4696
MK
226
227void *
228alloc_jump_pad_buffer (size_t size)
229{
9c235a72
PA
230#if __ILP32__
231 uintptr_t addr;
232 int pagesize;
233
234 pagesize = sysconf (_SC_PAGE_SIZE);
235 if (pagesize == -1)
236 perror_with_name ("sysconf");
237
238 addr = 0x80000000 - size;
239
240 /* size should already be page-aligned, but this can't hurt. */
241 addr &= ~(pagesize - 1);
242
243 /* Search for a free area. If we hit 0, we're out of luck. */
244 for (; addr; addr -= pagesize)
245 {
246 void *res;
247
248 /* No MAP_FIXED - we don't want to zap someone's mapping. */
249 res = mmap ((void *) addr, size,
250 PROT_READ | PROT_WRITE | PROT_EXEC,
251 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
252
253 /* If we got what we wanted, return. */
254 if ((uintptr_t) res == addr)
255 return res;
256
257 /* If we got a mapping, but at a wrong address, undo it. */
258 if (res != MAP_FAILED)
259 munmap (res, size);
260 }
261
262 return NULL;
263#else
a13c4696
MK
264 void *res = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
265 MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
266
267 if (res == MAP_FAILED)
268 return NULL;
269
270 return res;
9c235a72 271#endif
a13c4696
MK
272}
273
fa593d66
PA
274void
275initialize_low_tracepoint (void)
276{
201506da
PA
277#if defined __ILP32__
278 init_registers_x32_linux ();
279 init_registers_x32_avx_linux ();
280 init_registers_x32_avx512_linux ();
281#else
fa593d66 282 init_registers_amd64_linux ();
ae91f625 283 init_registers_amd64_avx_linux ();
2b863f51 284 init_registers_amd64_avx_mpx_linux ();
22049425 285 init_registers_amd64_avx_mpx_avx512_linux ();
201506da 286#endif
fa593d66 287}
This page took 0.545819 seconds and 4 git commands to generate.