2013-06-12 Phil Muldoon <pmuldoon@redhat.com>
[deliverable/binutils-gdb.git] / gdb / gdbserver / linux-x86-low.c
CommitLineData
d0722149
DE
1/* GNU/Linux/x86-64 specific low level interface, for the remote server
2 for GDB.
28e7fd62 3 Copyright (C) 2002-2013 Free Software Foundation, Inc.
d0722149
DE
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
aa5ca48f 20#include <stddef.h>
d0722149 21#include <signal.h>
6a271cae 22#include <limits.h>
f4647387 23#include <inttypes.h>
d0722149
DE
24#include "server.h"
25#include "linux-low.h"
26#include "i387-fp.h"
aa5ca48f 27#include "i386-low.h"
1570b33e
L
28#include "i386-xstate.h"
29#include "elf/common.h"
d0722149
DE
30
31#include "gdb_proc_service.h"
58b4daa5 32#include "agent.h"
3aee8918 33#include "tdesc.h"
d0722149 34
3aee8918 35#ifdef __x86_64__
90884b2b
L
36/* Defined in auto-generated file amd64-linux.c. */
37void init_registers_amd64_linux (void);
3aee8918
PA
38extern const struct target_desc *tdesc_amd64_linux;
39
1570b33e
L
40/* Defined in auto-generated file amd64-avx-linux.c. */
41void init_registers_amd64_avx_linux (void);
3aee8918
PA
42extern const struct target_desc *tdesc_amd64_avx_linux;
43
4d47af5c
L
44/* Defined in auto-generated file x32-linux.c. */
45void init_registers_x32_linux (void);
3aee8918
PA
46extern const struct target_desc *tdesc_x32_linux;
47
4d47af5c
L
48/* Defined in auto-generated file x32-avx-linux.c. */
49void init_registers_x32_avx_linux (void);
3aee8918
PA
50extern const struct target_desc *tdesc_x32_avx_linux;
51#endif
52
53/* Defined in auto-generated file i386-linux.c. */
54void init_registers_i386_linux (void);
55extern const struct target_desc *tdesc_i386_linux;
56
57/* Defined in auto-generated file i386-mmx-linux.c. */
58void init_registers_i386_mmx_linux (void);
59extern const struct target_desc *tdesc_i386_mmx_linux;
60
61/* Defined in auto-generated file i386-avx-linux.c. */
62void init_registers_i386_avx_linux (void);
63extern const struct target_desc *tdesc_i386_avx_linux;
64
65#ifdef __x86_64__
66static struct target_desc *tdesc_amd64_linux_no_xml;
67#endif
68static struct target_desc *tdesc_i386_linux_no_xml;
69
1570b33e 70
fa593d66 71static unsigned char jump_insn[] = { 0xe9, 0, 0, 0, 0 };
405f8e94 72static unsigned char small_jump_insn[] = { 0x66, 0xe9, 0, 0 };
fa593d66 73
1570b33e
L
74/* Backward compatibility for gdb without XML support. */
75
76static const char *xmltarget_i386_linux_no_xml = "@<target>\
77<architecture>i386</architecture>\
78<osabi>GNU/Linux</osabi>\
79</target>";
f6d1620c
L
80
81#ifdef __x86_64__
1570b33e
L
82static const char *xmltarget_amd64_linux_no_xml = "@<target>\
83<architecture>i386:x86-64</architecture>\
84<osabi>GNU/Linux</osabi>\
85</target>";
f6d1620c 86#endif
d0722149
DE
87
88#include <sys/reg.h>
89#include <sys/procfs.h>
90#include <sys/ptrace.h>
1570b33e
L
91#include <sys/uio.h>
92
93#ifndef PTRACE_GETREGSET
94#define PTRACE_GETREGSET 0x4204
95#endif
96
97#ifndef PTRACE_SETREGSET
98#define PTRACE_SETREGSET 0x4205
99#endif
100
d0722149
DE
101
102#ifndef PTRACE_GET_THREAD_AREA
103#define PTRACE_GET_THREAD_AREA 25
104#endif
105
106/* This definition comes from prctl.h, but some kernels may not have it. */
107#ifndef PTRACE_ARCH_PRCTL
108#define PTRACE_ARCH_PRCTL 30
109#endif
110
111/* The following definitions come from prctl.h, but may be absent
112 for certain configurations. */
113#ifndef ARCH_GET_FS
114#define ARCH_SET_GS 0x1001
115#define ARCH_SET_FS 0x1002
116#define ARCH_GET_FS 0x1003
117#define ARCH_GET_GS 0x1004
118#endif
119
aa5ca48f
DE
120/* Per-process arch-specific data we want to keep. */
121
122struct arch_process_info
123{
124 struct i386_debug_reg_state debug_reg_state;
125};
126
127/* Per-thread arch-specific data we want to keep. */
128
129struct arch_lwp_info
130{
131 /* Non-zero if our copy differs from what's recorded in the thread. */
132 int debug_registers_changed;
133};
134
d0722149
DE
135#ifdef __x86_64__
136
137/* Mapping between the general-purpose registers in `struct user'
138 format and GDB's register array layout.
139 Note that the transfer layout uses 64-bit regs. */
140static /*const*/ int i386_regmap[] =
141{
142 RAX * 8, RCX * 8, RDX * 8, RBX * 8,
143 RSP * 8, RBP * 8, RSI * 8, RDI * 8,
144 RIP * 8, EFLAGS * 8, CS * 8, SS * 8,
145 DS * 8, ES * 8, FS * 8, GS * 8
146};
147
148#define I386_NUM_REGS (sizeof (i386_regmap) / sizeof (i386_regmap[0]))
149
150/* So code below doesn't have to care, i386 or amd64. */
151#define ORIG_EAX ORIG_RAX
152
153static const int x86_64_regmap[] =
154{
155 RAX * 8, RBX * 8, RCX * 8, RDX * 8,
156 RSI * 8, RDI * 8, RBP * 8, RSP * 8,
157 R8 * 8, R9 * 8, R10 * 8, R11 * 8,
158 R12 * 8, R13 * 8, R14 * 8, R15 * 8,
159 RIP * 8, EFLAGS * 8, CS * 8, SS * 8,
160 DS * 8, ES * 8, FS * 8, GS * 8,
161 -1, -1, -1, -1, -1, -1, -1, -1,
162 -1, -1, -1, -1, -1, -1, -1, -1,
163 -1, -1, -1, -1, -1, -1, -1, -1,
164 -1, -1, -1, -1, -1, -1, -1, -1, -1,
165 ORIG_RAX * 8
166};
167
168#define X86_64_NUM_REGS (sizeof (x86_64_regmap) / sizeof (x86_64_regmap[0]))
169
170#else /* ! __x86_64__ */
171
172/* Mapping between the general-purpose registers in `struct user'
173 format and GDB's register array layout. */
174static /*const*/ int i386_regmap[] =
175{
176 EAX * 4, ECX * 4, EDX * 4, EBX * 4,
177 UESP * 4, EBP * 4, ESI * 4, EDI * 4,
178 EIP * 4, EFL * 4, CS * 4, SS * 4,
179 DS * 4, ES * 4, FS * 4, GS * 4
180};
181
182#define I386_NUM_REGS (sizeof (i386_regmap) / sizeof (i386_regmap[0]))
183
184#endif
3aee8918
PA
185
186#ifdef __x86_64__
187
188/* Returns true if the current inferior belongs to a x86-64 process,
189 per the tdesc. */
190
191static int
192is_64bit_tdesc (void)
193{
194 struct regcache *regcache = get_thread_regcache (current_inferior, 0);
195
196 return register_size (regcache->tdesc, 0) == 8;
197}
198
199#endif
200
d0722149
DE
201\f
202/* Called by libthread_db. */
203
204ps_err_e
205ps_get_thread_area (const struct ps_prochandle *ph,
206 lwpid_t lwpid, int idx, void **base)
207{
208#ifdef __x86_64__
3aee8918 209 int use_64bit = is_64bit_tdesc ();
d0722149
DE
210
211 if (use_64bit)
212 {
213 switch (idx)
214 {
215 case FS:
216 if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_FS) == 0)
217 return PS_OK;
218 break;
219 case GS:
220 if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_GS) == 0)
221 return PS_OK;
222 break;
223 default:
224 return PS_BADADDR;
225 }
226 return PS_ERR;
227 }
228#endif
229
230 {
231 unsigned int desc[4];
232
233 if (ptrace (PTRACE_GET_THREAD_AREA, lwpid,
234 (void *) (intptr_t) idx, (unsigned long) &desc) < 0)
235 return PS_ERR;
236
d1ec4ce7
DE
237 /* Ensure we properly extend the value to 64-bits for x86_64. */
238 *base = (void *) (uintptr_t) desc[1];
d0722149
DE
239 return PS_OK;
240 }
241}
fa593d66
PA
242
243/* Get the thread area address. This is used to recognize which
244 thread is which when tracing with the in-process agent library. We
245 don't read anything from the address, and treat it as opaque; it's
246 the address itself that we assume is unique per-thread. */
247
248static int
249x86_get_thread_area (int lwpid, CORE_ADDR *addr)
250{
251#ifdef __x86_64__
3aee8918 252 int use_64bit = is_64bit_tdesc ();
fa593d66
PA
253
254 if (use_64bit)
255 {
256 void *base;
257 if (ptrace (PTRACE_ARCH_PRCTL, lwpid, &base, ARCH_GET_FS) == 0)
258 {
259 *addr = (CORE_ADDR) (uintptr_t) base;
260 return 0;
261 }
262
263 return -1;
264 }
265#endif
266
267 {
268 struct lwp_info *lwp = find_lwp_pid (pid_to_ptid (lwpid));
269 struct regcache *regcache = get_thread_regcache (get_lwp_thread (lwp), 1);
270 unsigned int desc[4];
271 ULONGEST gs = 0;
272 const int reg_thread_area = 3; /* bits to scale down register value. */
273 int idx;
274
275 collect_register_by_name (regcache, "gs", &gs);
276
277 idx = gs >> reg_thread_area;
278
279 if (ptrace (PTRACE_GET_THREAD_AREA,
493e2a69
MS
280 lwpid_of (lwp),
281 (void *) (long) idx, (unsigned long) &desc) < 0)
fa593d66
PA
282 return -1;
283
284 *addr = desc[1];
285 return 0;
286 }
287}
288
289
d0722149
DE
290\f
291static int
3aee8918 292x86_cannot_store_register (int regno)
d0722149 293{
3aee8918
PA
294#ifdef __x86_64__
295 if (is_64bit_tdesc ())
296 return 0;
297#endif
298
d0722149
DE
299 return regno >= I386_NUM_REGS;
300}
301
302static int
3aee8918 303x86_cannot_fetch_register (int regno)
d0722149 304{
3aee8918
PA
305#ifdef __x86_64__
306 if (is_64bit_tdesc ())
307 return 0;
308#endif
309
d0722149
DE
310 return regno >= I386_NUM_REGS;
311}
312
313static void
442ea881 314x86_fill_gregset (struct regcache *regcache, void *buf)
d0722149
DE
315{
316 int i;
317
318#ifdef __x86_64__
3aee8918 319 if (register_size (regcache->tdesc, 0) == 8)
d0722149
DE
320 {
321 for (i = 0; i < X86_64_NUM_REGS; i++)
322 if (x86_64_regmap[i] != -1)
442ea881 323 collect_register (regcache, i, ((char *) buf) + x86_64_regmap[i]);
d0722149
DE
324 return;
325 }
326#endif
327
328 for (i = 0; i < I386_NUM_REGS; i++)
442ea881 329 collect_register (regcache, i, ((char *) buf) + i386_regmap[i]);
d0722149 330
442ea881
PA
331 collect_register_by_name (regcache, "orig_eax",
332 ((char *) buf) + ORIG_EAX * 4);
d0722149
DE
333}
334
335static void
442ea881 336x86_store_gregset (struct regcache *regcache, const void *buf)
d0722149
DE
337{
338 int i;
339
340#ifdef __x86_64__
3aee8918 341 if (register_size (regcache->tdesc, 0) == 8)
d0722149
DE
342 {
343 for (i = 0; i < X86_64_NUM_REGS; i++)
344 if (x86_64_regmap[i] != -1)
442ea881 345 supply_register (regcache, i, ((char *) buf) + x86_64_regmap[i]);
d0722149
DE
346 return;
347 }
348#endif
349
350 for (i = 0; i < I386_NUM_REGS; i++)
442ea881 351 supply_register (regcache, i, ((char *) buf) + i386_regmap[i]);
d0722149 352
442ea881
PA
353 supply_register_by_name (regcache, "orig_eax",
354 ((char *) buf) + ORIG_EAX * 4);
d0722149
DE
355}
356
357static void
442ea881 358x86_fill_fpregset (struct regcache *regcache, void *buf)
d0722149
DE
359{
360#ifdef __x86_64__
442ea881 361 i387_cache_to_fxsave (regcache, buf);
d0722149 362#else
442ea881 363 i387_cache_to_fsave (regcache, buf);
d0722149
DE
364#endif
365}
366
367static void
442ea881 368x86_store_fpregset (struct regcache *regcache, const void *buf)
d0722149
DE
369{
370#ifdef __x86_64__
442ea881 371 i387_fxsave_to_cache (regcache, buf);
d0722149 372#else
442ea881 373 i387_fsave_to_cache (regcache, buf);
d0722149
DE
374#endif
375}
376
377#ifndef __x86_64__
378
379static void
442ea881 380x86_fill_fpxregset (struct regcache *regcache, void *buf)
d0722149 381{
442ea881 382 i387_cache_to_fxsave (regcache, buf);
d0722149
DE
383}
384
385static void
442ea881 386x86_store_fpxregset (struct regcache *regcache, const void *buf)
d0722149 387{
442ea881 388 i387_fxsave_to_cache (regcache, buf);
d0722149
DE
389}
390
391#endif
392
1570b33e
L
393static void
394x86_fill_xstateregset (struct regcache *regcache, void *buf)
395{
396 i387_cache_to_xsave (regcache, buf);
397}
398
399static void
400x86_store_xstateregset (struct regcache *regcache, const void *buf)
401{
402 i387_xsave_to_cache (regcache, buf);
403}
404
d0722149
DE
405/* ??? The non-biarch i386 case stores all the i387 regs twice.
406 Once in i387_.*fsave.* and once in i387_.*fxsave.*.
407 This is, presumably, to handle the case where PTRACE_[GS]ETFPXREGS
408 doesn't work. IWBN to avoid the duplication in the case where it
409 does work. Maybe the arch_setup routine could check whether it works
3aee8918 410 and update the supported regsets accordingly. */
d0722149 411
3aee8918 412static struct regset_info x86_regsets[] =
d0722149
DE
413{
414#ifdef HAVE_PTRACE_GETREGS
1570b33e 415 { PTRACE_GETREGS, PTRACE_SETREGS, 0, sizeof (elf_gregset_t),
d0722149
DE
416 GENERAL_REGS,
417 x86_fill_gregset, x86_store_gregset },
1570b33e
L
418 { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_X86_XSTATE, 0,
419 EXTENDED_REGS, x86_fill_xstateregset, x86_store_xstateregset },
d0722149
DE
420# ifndef __x86_64__
421# ifdef HAVE_PTRACE_GETFPXREGS
1570b33e 422 { PTRACE_GETFPXREGS, PTRACE_SETFPXREGS, 0, sizeof (elf_fpxregset_t),
d0722149
DE
423 EXTENDED_REGS,
424 x86_fill_fpxregset, x86_store_fpxregset },
425# endif
426# endif
1570b33e 427 { PTRACE_GETFPREGS, PTRACE_SETFPREGS, 0, sizeof (elf_fpregset_t),
d0722149
DE
428 FP_REGS,
429 x86_fill_fpregset, x86_store_fpregset },
430#endif /* HAVE_PTRACE_GETREGS */
1570b33e 431 { 0, 0, 0, -1, -1, NULL, NULL }
d0722149
DE
432};
433
434static CORE_ADDR
442ea881 435x86_get_pc (struct regcache *regcache)
d0722149 436{
3aee8918 437 int use_64bit = register_size (regcache->tdesc, 0) == 8;
d0722149
DE
438
439 if (use_64bit)
440 {
441 unsigned long pc;
442ea881 442 collect_register_by_name (regcache, "rip", &pc);
d0722149
DE
443 return (CORE_ADDR) pc;
444 }
445 else
446 {
447 unsigned int pc;
442ea881 448 collect_register_by_name (regcache, "eip", &pc);
d0722149
DE
449 return (CORE_ADDR) pc;
450 }
451}
452
453static void
442ea881 454x86_set_pc (struct regcache *regcache, CORE_ADDR pc)
d0722149 455{
3aee8918 456 int use_64bit = register_size (regcache->tdesc, 0) == 8;
d0722149
DE
457
458 if (use_64bit)
459 {
460 unsigned long newpc = pc;
442ea881 461 supply_register_by_name (regcache, "rip", &newpc);
d0722149
DE
462 }
463 else
464 {
465 unsigned int newpc = pc;
442ea881 466 supply_register_by_name (regcache, "eip", &newpc);
d0722149
DE
467 }
468}
469\f
470static const unsigned char x86_breakpoint[] = { 0xCC };
471#define x86_breakpoint_len 1
472
473static int
474x86_breakpoint_at (CORE_ADDR pc)
475{
476 unsigned char c;
477
fc7238bb 478 (*the_target->read_memory) (pc, &c, 1);
d0722149
DE
479 if (c == 0xCC)
480 return 1;
481
482 return 0;
483}
484\f
aa5ca48f
DE
485/* Support for debug registers. */
486
487static unsigned long
488x86_linux_dr_get (ptid_t ptid, int regnum)
489{
490 int tid;
491 unsigned long value;
492
493 tid = ptid_get_lwp (ptid);
494
495 errno = 0;
496 value = ptrace (PTRACE_PEEKUSER, tid,
497 offsetof (struct user, u_debugreg[regnum]), 0);
498 if (errno != 0)
499 error ("Couldn't read debug register");
500
501 return value;
502}
503
504static void
505x86_linux_dr_set (ptid_t ptid, int regnum, unsigned long value)
506{
507 int tid;
508
509 tid = ptid_get_lwp (ptid);
510
511 errno = 0;
512 ptrace (PTRACE_POKEUSER, tid,
513 offsetof (struct user, u_debugreg[regnum]), value);
514 if (errno != 0)
515 error ("Couldn't write debug register");
516}
517
964e4306
PA
518static int
519update_debug_registers_callback (struct inferior_list_entry *entry,
520 void *pid_p)
521{
522 struct lwp_info *lwp = (struct lwp_info *) entry;
523 int pid = *(int *) pid_p;
524
525 /* Only update the threads of this process. */
526 if (pid_of (lwp) == pid)
527 {
528 /* The actual update is done later just before resuming the lwp,
529 we just mark that the registers need updating. */
530 lwp->arch_private->debug_registers_changed = 1;
531
532 /* If the lwp isn't stopped, force it to momentarily pause, so
533 we can update its debug registers. */
534 if (!lwp->stopped)
535 linux_stop_lwp (lwp);
536 }
537
538 return 0;
539}
540
aa5ca48f
DE
541/* Update the inferior's debug register REGNUM from STATE. */
542
543void
544i386_dr_low_set_addr (const struct i386_debug_reg_state *state, int regnum)
545{
964e4306 546 /* Only update the threads of this process. */
aa5ca48f
DE
547 int pid = pid_of (get_thread_lwp (current_inferior));
548
549 if (! (regnum >= 0 && regnum <= DR_LASTADDR - DR_FIRSTADDR))
550 fatal ("Invalid debug register %d", regnum);
551
964e4306
PA
552 find_inferior (&all_lwps, update_debug_registers_callback, &pid);
553}
aa5ca48f 554
964e4306 555/* Return the inferior's debug register REGNUM. */
aa5ca48f 556
964e4306
PA
557CORE_ADDR
558i386_dr_low_get_addr (int regnum)
559{
560 struct lwp_info *lwp = get_thread_lwp (current_inferior);
561 ptid_t ptid = ptid_of (lwp);
562
563 /* DR6 and DR7 are retrieved with some other way. */
0a5b1e09 564 gdb_assert (DR_FIRSTADDR <= regnum && regnum <= DR_LASTADDR);
964e4306
PA
565
566 return x86_linux_dr_get (ptid, regnum);
aa5ca48f
DE
567}
568
569/* Update the inferior's DR7 debug control register from STATE. */
570
571void
572i386_dr_low_set_control (const struct i386_debug_reg_state *state)
573{
964e4306 574 /* Only update the threads of this process. */
aa5ca48f
DE
575 int pid = pid_of (get_thread_lwp (current_inferior));
576
964e4306
PA
577 find_inferior (&all_lwps, update_debug_registers_callback, &pid);
578}
aa5ca48f 579
964e4306
PA
580/* Return the inferior's DR7 debug control register. */
581
582unsigned
583i386_dr_low_get_control (void)
584{
585 struct lwp_info *lwp = get_thread_lwp (current_inferior);
586 ptid_t ptid = ptid_of (lwp);
587
588 return x86_linux_dr_get (ptid, DR_CONTROL);
aa5ca48f
DE
589}
590
591/* Get the value of the DR6 debug status register from the inferior
592 and record it in STATE. */
593
964e4306
PA
594unsigned
595i386_dr_low_get_status (void)
aa5ca48f
DE
596{
597 struct lwp_info *lwp = get_thread_lwp (current_inferior);
598 ptid_t ptid = ptid_of (lwp);
599
964e4306 600 return x86_linux_dr_get (ptid, DR_STATUS);
aa5ca48f
DE
601}
602\f
90d74c30 603/* Breakpoint/Watchpoint support. */
aa5ca48f
DE
604
605static int
606x86_insert_point (char type, CORE_ADDR addr, int len)
607{
608 struct process_info *proc = current_process ();
609 switch (type)
610 {
961bd387 611 case '0': /* software-breakpoint */
90d74c30
PA
612 {
613 int ret;
614
615 ret = prepare_to_access_memory ();
616 if (ret)
617 return -1;
618 ret = set_gdb_breakpoint_at (addr);
0146f85b 619 done_accessing_memory ();
90d74c30
PA
620 return ret;
621 }
961bd387
ME
622 case '1': /* hardware-breakpoint */
623 case '2': /* write watchpoint */
624 case '3': /* read watchpoint */
625 case '4': /* access watchpoint */
aa5ca48f
DE
626 return i386_low_insert_watchpoint (&proc->private->arch_private->debug_reg_state,
627 type, addr, len);
961bd387 628
aa5ca48f
DE
629 default:
630 /* Unsupported. */
631 return 1;
632 }
633}
634
635static int
636x86_remove_point (char type, CORE_ADDR addr, int len)
637{
638 struct process_info *proc = current_process ();
639 switch (type)
640 {
961bd387 641 case '0': /* software-breakpoint */
90d74c30
PA
642 {
643 int ret;
644
645 ret = prepare_to_access_memory ();
646 if (ret)
647 return -1;
648 ret = delete_gdb_breakpoint_at (addr);
0146f85b 649 done_accessing_memory ();
90d74c30
PA
650 return ret;
651 }
961bd387
ME
652 case '1': /* hardware-breakpoint */
653 case '2': /* write watchpoint */
654 case '3': /* read watchpoint */
655 case '4': /* access watchpoint */
aa5ca48f
DE
656 return i386_low_remove_watchpoint (&proc->private->arch_private->debug_reg_state,
657 type, addr, len);
658 default:
659 /* Unsupported. */
660 return 1;
661 }
662}
663
664static int
665x86_stopped_by_watchpoint (void)
666{
667 struct process_info *proc = current_process ();
668 return i386_low_stopped_by_watchpoint (&proc->private->arch_private->debug_reg_state);
669}
670
671static CORE_ADDR
672x86_stopped_data_address (void)
673{
674 struct process_info *proc = current_process ();
675 CORE_ADDR addr;
676 if (i386_low_stopped_data_address (&proc->private->arch_private->debug_reg_state,
677 &addr))
678 return addr;
679 return 0;
680}
681\f
682/* Called when a new process is created. */
683
684static struct arch_process_info *
685x86_linux_new_process (void)
686{
687 struct arch_process_info *info = xcalloc (1, sizeof (*info));
688
689 i386_low_init_dregs (&info->debug_reg_state);
690
691 return info;
692}
693
694/* Called when a new thread is detected. */
695
696static struct arch_lwp_info *
697x86_linux_new_thread (void)
698{
699 struct arch_lwp_info *info = xcalloc (1, sizeof (*info));
700
701 info->debug_registers_changed = 1;
702
703 return info;
704}
705
706/* Called when resuming a thread.
707 If the debug regs have changed, update the thread's copies. */
708
709static void
710x86_linux_prepare_to_resume (struct lwp_info *lwp)
711{
b9a881c2 712 ptid_t ptid = ptid_of (lwp);
6210a125 713 int clear_status = 0;
b9a881c2 714
aa5ca48f
DE
715 if (lwp->arch_private->debug_registers_changed)
716 {
717 int i;
aa5ca48f
DE
718 int pid = ptid_get_pid (ptid);
719 struct process_info *proc = find_process_pid (pid);
493e2a69
MS
720 struct i386_debug_reg_state *state
721 = &proc->private->arch_private->debug_reg_state;
aa5ca48f
DE
722
723 for (i = DR_FIRSTADDR; i <= DR_LASTADDR; i++)
6210a125
PA
724 if (state->dr_ref_count[i] > 0)
725 {
726 x86_linux_dr_set (ptid, i, state->dr_mirror[i]);
727
728 /* If we're setting a watchpoint, any change the inferior
729 had done itself to the debug registers needs to be
730 discarded, otherwise, i386_low_stopped_data_address can
731 get confused. */
732 clear_status = 1;
733 }
aa5ca48f
DE
734
735 x86_linux_dr_set (ptid, DR_CONTROL, state->dr_control_mirror);
736
737 lwp->arch_private->debug_registers_changed = 0;
738 }
b9a881c2 739
6210a125 740 if (clear_status || lwp->stopped_by_watchpoint)
b9a881c2 741 x86_linux_dr_set (ptid, DR_STATUS, 0);
aa5ca48f
DE
742}
743\f
d0722149
DE
744/* When GDBSERVER is built as a 64-bit application on linux, the
745 PTRACE_GETSIGINFO data is always presented in 64-bit layout. Since
746 debugging a 32-bit inferior with a 64-bit GDBSERVER should look the same
747 as debugging it with a 32-bit GDBSERVER, we do the 32-bit <-> 64-bit
748 conversion in-place ourselves. */
749
750/* These types below (compat_*) define a siginfo type that is layout
751 compatible with the siginfo type exported by the 32-bit userspace
752 support. */
753
754#ifdef __x86_64__
755
756typedef int compat_int_t;
757typedef unsigned int compat_uptr_t;
758
759typedef int compat_time_t;
760typedef int compat_timer_t;
761typedef int compat_clock_t;
762
763struct compat_timeval
764{
765 compat_time_t tv_sec;
766 int tv_usec;
767};
768
769typedef union compat_sigval
770{
771 compat_int_t sival_int;
772 compat_uptr_t sival_ptr;
773} compat_sigval_t;
774
775typedef struct compat_siginfo
776{
777 int si_signo;
778 int si_errno;
779 int si_code;
780
781 union
782 {
783 int _pad[((128 / sizeof (int)) - 3)];
784
785 /* kill() */
786 struct
787 {
788 unsigned int _pid;
789 unsigned int _uid;
790 } _kill;
791
792 /* POSIX.1b timers */
793 struct
794 {
795 compat_timer_t _tid;
796 int _overrun;
797 compat_sigval_t _sigval;
798 } _timer;
799
800 /* POSIX.1b signals */
801 struct
802 {
803 unsigned int _pid;
804 unsigned int _uid;
805 compat_sigval_t _sigval;
806 } _rt;
807
808 /* SIGCHLD */
809 struct
810 {
811 unsigned int _pid;
812 unsigned int _uid;
813 int _status;
814 compat_clock_t _utime;
815 compat_clock_t _stime;
816 } _sigchld;
817
818 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
819 struct
820 {
821 unsigned int _addr;
822 } _sigfault;
823
824 /* SIGPOLL */
825 struct
826 {
827 int _band;
828 int _fd;
829 } _sigpoll;
830 } _sifields;
831} compat_siginfo_t;
832
c92b5177
L
833/* For x32, clock_t in _sigchld is 64bit aligned at 4 bytes. */
834typedef long __attribute__ ((__aligned__ (4))) compat_x32_clock_t;
835
836typedef struct compat_x32_siginfo
837{
838 int si_signo;
839 int si_errno;
840 int si_code;
841
842 union
843 {
844 int _pad[((128 / sizeof (int)) - 3)];
845
846 /* kill() */
847 struct
848 {
849 unsigned int _pid;
850 unsigned int _uid;
851 } _kill;
852
853 /* POSIX.1b timers */
854 struct
855 {
856 compat_timer_t _tid;
857 int _overrun;
858 compat_sigval_t _sigval;
859 } _timer;
860
861 /* POSIX.1b signals */
862 struct
863 {
864 unsigned int _pid;
865 unsigned int _uid;
866 compat_sigval_t _sigval;
867 } _rt;
868
869 /* SIGCHLD */
870 struct
871 {
872 unsigned int _pid;
873 unsigned int _uid;
874 int _status;
875 compat_x32_clock_t _utime;
876 compat_x32_clock_t _stime;
877 } _sigchld;
878
879 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
880 struct
881 {
882 unsigned int _addr;
883 } _sigfault;
884
885 /* SIGPOLL */
886 struct
887 {
888 int _band;
889 int _fd;
890 } _sigpoll;
891 } _sifields;
892} compat_x32_siginfo_t __attribute__ ((__aligned__ (8)));
893
d0722149
DE
894#define cpt_si_pid _sifields._kill._pid
895#define cpt_si_uid _sifields._kill._uid
896#define cpt_si_timerid _sifields._timer._tid
897#define cpt_si_overrun _sifields._timer._overrun
898#define cpt_si_status _sifields._sigchld._status
899#define cpt_si_utime _sifields._sigchld._utime
900#define cpt_si_stime _sifields._sigchld._stime
901#define cpt_si_ptr _sifields._rt._sigval.sival_ptr
902#define cpt_si_addr _sifields._sigfault._addr
903#define cpt_si_band _sifields._sigpoll._band
904#define cpt_si_fd _sifields._sigpoll._fd
905
906/* glibc at least up to 2.3.2 doesn't have si_timerid, si_overrun.
907 In their place is si_timer1,si_timer2. */
908#ifndef si_timerid
909#define si_timerid si_timer1
910#endif
911#ifndef si_overrun
912#define si_overrun si_timer2
913#endif
914
915static void
916compat_siginfo_from_siginfo (compat_siginfo_t *to, siginfo_t *from)
917{
918 memset (to, 0, sizeof (*to));
919
920 to->si_signo = from->si_signo;
921 to->si_errno = from->si_errno;
922 to->si_code = from->si_code;
923
b53a1623 924 if (to->si_code == SI_TIMER)
d0722149 925 {
b53a1623
PA
926 to->cpt_si_timerid = from->si_timerid;
927 to->cpt_si_overrun = from->si_overrun;
d0722149
DE
928 to->cpt_si_ptr = (intptr_t) from->si_ptr;
929 }
930 else if (to->si_code == SI_USER)
931 {
932 to->cpt_si_pid = from->si_pid;
933 to->cpt_si_uid = from->si_uid;
934 }
b53a1623 935 else if (to->si_code < 0)
d0722149 936 {
b53a1623
PA
937 to->cpt_si_pid = from->si_pid;
938 to->cpt_si_uid = from->si_uid;
d0722149
DE
939 to->cpt_si_ptr = (intptr_t) from->si_ptr;
940 }
941 else
942 {
943 switch (to->si_signo)
944 {
945 case SIGCHLD:
946 to->cpt_si_pid = from->si_pid;
947 to->cpt_si_uid = from->si_uid;
948 to->cpt_si_status = from->si_status;
949 to->cpt_si_utime = from->si_utime;
950 to->cpt_si_stime = from->si_stime;
951 break;
952 case SIGILL:
953 case SIGFPE:
954 case SIGSEGV:
955 case SIGBUS:
956 to->cpt_si_addr = (intptr_t) from->si_addr;
957 break;
958 case SIGPOLL:
959 to->cpt_si_band = from->si_band;
960 to->cpt_si_fd = from->si_fd;
961 break;
962 default:
963 to->cpt_si_pid = from->si_pid;
964 to->cpt_si_uid = from->si_uid;
965 to->cpt_si_ptr = (intptr_t) from->si_ptr;
966 break;
967 }
968 }
969}
970
971static void
972siginfo_from_compat_siginfo (siginfo_t *to, compat_siginfo_t *from)
973{
974 memset (to, 0, sizeof (*to));
975
976 to->si_signo = from->si_signo;
977 to->si_errno = from->si_errno;
978 to->si_code = from->si_code;
979
b53a1623 980 if (to->si_code == SI_TIMER)
d0722149 981 {
b53a1623
PA
982 to->si_timerid = from->cpt_si_timerid;
983 to->si_overrun = from->cpt_si_overrun;
d0722149
DE
984 to->si_ptr = (void *) (intptr_t) from->cpt_si_ptr;
985 }
986 else if (to->si_code == SI_USER)
987 {
988 to->si_pid = from->cpt_si_pid;
989 to->si_uid = from->cpt_si_uid;
990 }
b53a1623 991 else if (to->si_code < 0)
d0722149 992 {
b53a1623
PA
993 to->si_pid = from->cpt_si_pid;
994 to->si_uid = from->cpt_si_uid;
d0722149
DE
995 to->si_ptr = (void *) (intptr_t) from->cpt_si_ptr;
996 }
997 else
998 {
999 switch (to->si_signo)
1000 {
1001 case SIGCHLD:
1002 to->si_pid = from->cpt_si_pid;
1003 to->si_uid = from->cpt_si_uid;
1004 to->si_status = from->cpt_si_status;
1005 to->si_utime = from->cpt_si_utime;
1006 to->si_stime = from->cpt_si_stime;
1007 break;
1008 case SIGILL:
1009 case SIGFPE:
1010 case SIGSEGV:
1011 case SIGBUS:
1012 to->si_addr = (void *) (intptr_t) from->cpt_si_addr;
1013 break;
1014 case SIGPOLL:
1015 to->si_band = from->cpt_si_band;
1016 to->si_fd = from->cpt_si_fd;
1017 break;
1018 default:
1019 to->si_pid = from->cpt_si_pid;
1020 to->si_uid = from->cpt_si_uid;
1021 to->si_ptr = (void* ) (intptr_t) from->cpt_si_ptr;
1022 break;
1023 }
1024 }
1025}
1026
c92b5177
L
1027static void
1028compat_x32_siginfo_from_siginfo (compat_x32_siginfo_t *to,
1029 siginfo_t *from)
1030{
1031 memset (to, 0, sizeof (*to));
1032
1033 to->si_signo = from->si_signo;
1034 to->si_errno = from->si_errno;
1035 to->si_code = from->si_code;
1036
1037 if (to->si_code == SI_TIMER)
1038 {
1039 to->cpt_si_timerid = from->si_timerid;
1040 to->cpt_si_overrun = from->si_overrun;
1041 to->cpt_si_ptr = (intptr_t) from->si_ptr;
1042 }
1043 else if (to->si_code == SI_USER)
1044 {
1045 to->cpt_si_pid = from->si_pid;
1046 to->cpt_si_uid = from->si_uid;
1047 }
1048 else if (to->si_code < 0)
1049 {
1050 to->cpt_si_pid = from->si_pid;
1051 to->cpt_si_uid = from->si_uid;
1052 to->cpt_si_ptr = (intptr_t) from->si_ptr;
1053 }
1054 else
1055 {
1056 switch (to->si_signo)
1057 {
1058 case SIGCHLD:
1059 to->cpt_si_pid = from->si_pid;
1060 to->cpt_si_uid = from->si_uid;
1061 to->cpt_si_status = from->si_status;
1062 to->cpt_si_utime = from->si_utime;
1063 to->cpt_si_stime = from->si_stime;
1064 break;
1065 case SIGILL:
1066 case SIGFPE:
1067 case SIGSEGV:
1068 case SIGBUS:
1069 to->cpt_si_addr = (intptr_t) from->si_addr;
1070 break;
1071 case SIGPOLL:
1072 to->cpt_si_band = from->si_band;
1073 to->cpt_si_fd = from->si_fd;
1074 break;
1075 default:
1076 to->cpt_si_pid = from->si_pid;
1077 to->cpt_si_uid = from->si_uid;
1078 to->cpt_si_ptr = (intptr_t) from->si_ptr;
1079 break;
1080 }
1081 }
1082}
1083
1084static void
1085siginfo_from_compat_x32_siginfo (siginfo_t *to,
1086 compat_x32_siginfo_t *from)
1087{
1088 memset (to, 0, sizeof (*to));
1089
1090 to->si_signo = from->si_signo;
1091 to->si_errno = from->si_errno;
1092 to->si_code = from->si_code;
1093
1094 if (to->si_code == SI_TIMER)
1095 {
1096 to->si_timerid = from->cpt_si_timerid;
1097 to->si_overrun = from->cpt_si_overrun;
1098 to->si_ptr = (void *) (intptr_t) from->cpt_si_ptr;
1099 }
1100 else if (to->si_code == SI_USER)
1101 {
1102 to->si_pid = from->cpt_si_pid;
1103 to->si_uid = from->cpt_si_uid;
1104 }
1105 else if (to->si_code < 0)
1106 {
1107 to->si_pid = from->cpt_si_pid;
1108 to->si_uid = from->cpt_si_uid;
1109 to->si_ptr = (void *) (intptr_t) from->cpt_si_ptr;
1110 }
1111 else
1112 {
1113 switch (to->si_signo)
1114 {
1115 case SIGCHLD:
1116 to->si_pid = from->cpt_si_pid;
1117 to->si_uid = from->cpt_si_uid;
1118 to->si_status = from->cpt_si_status;
1119 to->si_utime = from->cpt_si_utime;
1120 to->si_stime = from->cpt_si_stime;
1121 break;
1122 case SIGILL:
1123 case SIGFPE:
1124 case SIGSEGV:
1125 case SIGBUS:
1126 to->si_addr = (void *) (intptr_t) from->cpt_si_addr;
1127 break;
1128 case SIGPOLL:
1129 to->si_band = from->cpt_si_band;
1130 to->si_fd = from->cpt_si_fd;
1131 break;
1132 default:
1133 to->si_pid = from->cpt_si_pid;
1134 to->si_uid = from->cpt_si_uid;
1135 to->si_ptr = (void* ) (intptr_t) from->cpt_si_ptr;
1136 break;
1137 }
1138 }
1139}
1140
1141/* Is this process 64-bit? */
1142static int linux_is_elf64;
d0722149
DE
1143#endif /* __x86_64__ */
1144
1145/* Convert a native/host siginfo object, into/from the siginfo in the
1146 layout of the inferiors' architecture. Returns true if any
1147 conversion was done; false otherwise. If DIRECTION is 1, then copy
1148 from INF to NATIVE. If DIRECTION is 0, copy from NATIVE to
1149 INF. */
1150
1151static int
a5362b9a 1152x86_siginfo_fixup (siginfo_t *native, void *inf, int direction)
d0722149
DE
1153{
1154#ifdef __x86_64__
1155 /* Is the inferior 32-bit? If so, then fixup the siginfo object. */
3aee8918 1156 if (!is_64bit_tdesc ())
d0722149 1157 {
a5362b9a 1158 if (sizeof (siginfo_t) != sizeof (compat_siginfo_t))
9f1036c1 1159 fatal ("unexpected difference in siginfo");
d0722149
DE
1160
1161 if (direction == 0)
1162 compat_siginfo_from_siginfo ((struct compat_siginfo *) inf, native);
1163 else
1164 siginfo_from_compat_siginfo (native, (struct compat_siginfo *) inf);
1165
c92b5177
L
1166 return 1;
1167 }
1168 /* No fixup for native x32 GDB. */
1169 else if (!linux_is_elf64 && sizeof (void *) == 8)
1170 {
1171 if (sizeof (siginfo_t) != sizeof (compat_x32_siginfo_t))
1172 fatal ("unexpected difference in siginfo");
1173
1174 if (direction == 0)
1175 compat_x32_siginfo_from_siginfo ((struct compat_x32_siginfo *) inf,
1176 native);
1177 else
1178 siginfo_from_compat_x32_siginfo (native,
1179 (struct compat_x32_siginfo *) inf);
1180
d0722149
DE
1181 return 1;
1182 }
1183#endif
1184
1185 return 0;
1186}
1187\f
1570b33e
L
1188static int use_xml;
1189
3aee8918
PA
1190/* Format of XSAVE extended state is:
1191 struct
1192 {
1193 fxsave_bytes[0..463]
1194 sw_usable_bytes[464..511]
1195 xstate_hdr_bytes[512..575]
1196 avx_bytes[576..831]
1197 future_state etc
1198 };
1199
1200 Same memory layout will be used for the coredump NT_X86_XSTATE
1201 representing the XSAVE extended state registers.
1202
1203 The first 8 bytes of the sw_usable_bytes[464..467] is the OS enabled
1204 extended state mask, which is the same as the extended control register
1205 0 (the XFEATURE_ENABLED_MASK register), XCR0. We can use this mask
1206 together with the mask saved in the xstate_hdr_bytes to determine what
1207 states the processor/OS supports and what state, used or initialized,
1208 the process/thread is in. */
1209#define I386_LINUX_XSAVE_XCR0_OFFSET 464
1210
1211/* Does the current host support the GETFPXREGS request? The header
1212 file may or may not define it, and even if it is defined, the
1213 kernel will return EIO if it's running on a pre-SSE processor. */
1214int have_ptrace_getfpxregs =
1215#ifdef HAVE_PTRACE_GETFPXREGS
1216 -1
1217#else
1218 0
1219#endif
1220;
1570b33e 1221
3aee8918
PA
1222/* Does the current host support PTRACE_GETREGSET? */
1223static int have_ptrace_getregset = -1;
1224
1225/* Get Linux/x86 target description from running target. */
1226
1227static const struct target_desc *
1228x86_linux_read_description (void)
1570b33e 1229{
3aee8918
PA
1230 unsigned int machine;
1231 int is_elf64;
1232 int avx;
1233 int tid;
1234 static uint64_t xcr0;
3a13a53b 1235 struct regset_info *regset;
1570b33e 1236
3aee8918 1237 tid = lwpid_of (get_thread_lwp (current_inferior));
1570b33e 1238
3aee8918 1239 is_elf64 = linux_pid_exe_is_elf_64_file (tid, &machine);
45ba0d02 1240
3aee8918 1241 if (sizeof (void *) == 4)
3a13a53b 1242 {
3aee8918
PA
1243 if (is_elf64 > 0)
1244 error (_("Can't debug 64-bit process with 32-bit GDBserver"));
1245#ifndef __x86_64__
1246 else if (machine == EM_X86_64)
1247 error (_("Can't debug x86-64 process with 32-bit GDBserver"));
1248#endif
1249 }
3a13a53b 1250
3aee8918
PA
1251#if !defined __x86_64__ && defined HAVE_PTRACE_GETFPXREGS
1252 if (machine == EM_386 && have_ptrace_getfpxregs == -1)
1253 {
1254 elf_fpxregset_t fpxregs;
3a13a53b 1255
3aee8918 1256 if (ptrace (PTRACE_GETFPXREGS, tid, 0, (long) &fpxregs) < 0)
3a13a53b 1257 {
3aee8918
PA
1258 have_ptrace_getfpxregs = 0;
1259 have_ptrace_getregset = 0;
1260 return tdesc_i386_mmx_linux;
3a13a53b 1261 }
3aee8918
PA
1262 else
1263 have_ptrace_getfpxregs = 1;
3a13a53b 1264 }
1570b33e
L
1265#endif
1266
1267 if (!use_xml)
1268 {
3aee8918
PA
1269 x86_xcr0 = I386_XSTATE_SSE_MASK;
1270
1570b33e
L
1271 /* Don't use XML. */
1272#ifdef __x86_64__
3aee8918
PA
1273 if (machine == EM_X86_64)
1274 return tdesc_amd64_linux_no_xml;
1570b33e 1275 else
1570b33e 1276#endif
3aee8918 1277 return tdesc_i386_linux_no_xml;
1570b33e
L
1278 }
1279
1570b33e
L
1280 if (have_ptrace_getregset == -1)
1281 {
3aee8918 1282 uint64_t xstateregs[(I386_XSTATE_SSE_SIZE / sizeof (uint64_t))];
1570b33e 1283 struct iovec iov;
1570b33e
L
1284
1285 iov.iov_base = xstateregs;
1286 iov.iov_len = sizeof (xstateregs);
1287
1288 /* Check if PTRACE_GETREGSET works. */
3aee8918
PA
1289 if (ptrace (PTRACE_GETREGSET, tid,
1290 (unsigned int) NT_X86_XSTATE, (long) &iov) < 0)
1291 have_ptrace_getregset = 0;
1292 else
1570b33e 1293 {
3aee8918
PA
1294 have_ptrace_getregset = 1;
1295
1296 /* Get XCR0 from XSAVE extended state. */
1297 xcr0 = xstateregs[(I386_LINUX_XSAVE_XCR0_OFFSET
1298 / sizeof (uint64_t))];
1299
1300 /* Use PTRACE_GETREGSET if it is available. */
1301 for (regset = x86_regsets;
1302 regset->fill_function != NULL; regset++)
1303 if (regset->get_request == PTRACE_GETREGSET)
1304 regset->size = I386_XSTATE_SIZE (xcr0);
1305 else if (regset->type != GENERAL_REGS)
1306 regset->size = 0;
1570b33e 1307 }
1570b33e
L
1308 }
1309
3aee8918
PA
1310 /* Check the native XCR0 only if PTRACE_GETREGSET is available. */
1311 avx = (have_ptrace_getregset
1312 && (xcr0 & I386_XSTATE_AVX_MASK) == I386_XSTATE_AVX_MASK);
1313
1314 /* AVX is the highest feature we support. */
1315 if (avx)
1316 x86_xcr0 = xcr0;
1570b33e 1317
3aee8918
PA
1318 if (machine == EM_X86_64)
1319 {
1570b33e 1320#ifdef __x86_64__
3aee8918
PA
1321 if (avx)
1322 {
1323 if (!is_elf64)
1324 return tdesc_x32_avx_linux;
4d47af5c 1325 else
3aee8918
PA
1326 return tdesc_amd64_avx_linux;
1327 }
1328 else
1329 {
1330 if (!is_elf64)
1331 return tdesc_x32_linux;
1332 else
1333 return tdesc_amd64_linux;
1570b33e 1334 }
3aee8918 1335#endif
1570b33e 1336 }
3aee8918
PA
1337 else
1338 {
1339 if (avx)
1340 return tdesc_i386_avx_linux;
1341 else
1342 return tdesc_i386_linux;
1343 }
1344
1345 gdb_assert_not_reached ("failed to return tdesc");
1346}
1347
1348/* Callback for find_inferior. Stops iteration when a thread with a
1349 given PID is found. */
1350
1351static int
1352same_process_callback (struct inferior_list_entry *entry, void *data)
1353{
1354 int pid = *(int *) data;
1355
1356 return (ptid_get_pid (entry->id) == pid);
1357}
1358
1359/* Callback for for_each_inferior. Calls the arch_setup routine for
1360 each process. */
1361
1362static void
1363x86_arch_setup_process_callback (struct inferior_list_entry *entry)
1364{
1365 int pid = ptid_get_pid (entry->id);
1366
1367 /* Look up any thread of this processes. */
1368 current_inferior
1369 = (struct thread_info *) find_inferior (&all_threads,
1370 same_process_callback, &pid);
1371
1372 the_low_target.arch_setup ();
1373}
1374
1375/* Update all the target description of all processes; a new GDB
1376 connected, and it may or not support xml target descriptions. */
1377
1378static void
1379x86_linux_update_xmltarget (void)
1380{
1381 struct thread_info *save_inferior = current_inferior;
1382
1383 /* Before changing the register cache's internal layout, flush the
1384 contents of the current valid caches back to the threads, and
1385 release the current regcache objects. */
1386 regcache_release ();
1387
1388 for_each_inferior (&all_processes, x86_arch_setup_process_callback);
1389
1390 current_inferior = save_inferior;
1570b33e
L
1391}
1392
1393/* Process qSupported query, "xmlRegisters=". Update the buffer size for
1394 PTRACE_GETREGSET. */
1395
1396static void
1397x86_linux_process_qsupported (const char *query)
1398{
1399 /* Return if gdb doesn't support XML. If gdb sends "xmlRegisters="
1400 with "i386" in qSupported query, it supports x86 XML target
1401 descriptions. */
1402 use_xml = 0;
1403 if (query != NULL && strncmp (query, "xmlRegisters=", 13) == 0)
1404 {
1405 char *copy = xstrdup (query + 13);
1406 char *p;
1407
1408 for (p = strtok (copy, ","); p != NULL; p = strtok (NULL, ","))
1409 {
1410 if (strcmp (p, "i386") == 0)
1411 {
1412 use_xml = 1;
1413 break;
1414 }
1415 }
1416
1417 free (copy);
1418 }
1419
1420 x86_linux_update_xmltarget ();
1421}
1422
3aee8918 1423/* Common for x86/x86-64. */
d0722149 1424
3aee8918
PA
1425static struct regsets_info x86_regsets_info =
1426 {
1427 x86_regsets, /* regsets */
1428 0, /* num_regsets */
1429 NULL, /* disabled_regsets */
1430 };
214d508e
L
1431
1432#ifdef __x86_64__
3aee8918
PA
1433static struct regs_info amd64_linux_regs_info =
1434 {
1435 NULL, /* regset_bitmap */
1436 NULL, /* usrregs_info */
1437 &x86_regsets_info
1438 };
d0722149 1439#endif
3aee8918
PA
1440static struct usrregs_info i386_linux_usrregs_info =
1441 {
1442 I386_NUM_REGS,
1443 i386_regmap,
1444 };
d0722149 1445
3aee8918
PA
1446static struct regs_info i386_linux_regs_info =
1447 {
1448 NULL, /* regset_bitmap */
1449 &i386_linux_usrregs_info,
1450 &x86_regsets_info
1451 };
d0722149 1452
3aee8918
PA
1453const struct regs_info *
1454x86_linux_regs_info (void)
1455{
1456#ifdef __x86_64__
1457 if (is_64bit_tdesc ())
1458 return &amd64_linux_regs_info;
1459 else
1460#endif
1461 return &i386_linux_regs_info;
1462}
d0722149 1463
3aee8918
PA
1464/* Initialize the target description for the architecture of the
1465 inferior. */
1570b33e 1466
3aee8918
PA
1467static void
1468x86_arch_setup (void)
1469{
1470 current_process ()->tdesc = x86_linux_read_description ();
d0722149
DE
1471}
1472
219f2f23
PA
1473static int
1474x86_supports_tracepoints (void)
1475{
1476 return 1;
1477}
1478
fa593d66
PA
1479static void
1480append_insns (CORE_ADDR *to, size_t len, const unsigned char *buf)
1481{
1482 write_inferior_memory (*to, buf, len);
1483 *to += len;
1484}
1485
1486static int
1487push_opcode (unsigned char *buf, char *op)
1488{
1489 unsigned char *buf_org = buf;
1490
1491 while (1)
1492 {
1493 char *endptr;
1494 unsigned long ul = strtoul (op, &endptr, 16);
1495
1496 if (endptr == op)
1497 break;
1498
1499 *buf++ = ul;
1500 op = endptr;
1501 }
1502
1503 return buf - buf_org;
1504}
1505
1506#ifdef __x86_64__
1507
1508/* Build a jump pad that saves registers and calls a collection
1509 function. Writes a jump instruction to the jump pad to
1510 JJUMPAD_INSN. The caller is responsible to write it in at the
1511 tracepoint address. */
1512
1513static int
1514amd64_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, CORE_ADDR tpaddr,
1515 CORE_ADDR collector,
1516 CORE_ADDR lockaddr,
1517 ULONGEST orig_size,
1518 CORE_ADDR *jump_entry,
405f8e94
SS
1519 CORE_ADDR *trampoline,
1520 ULONGEST *trampoline_size,
fa593d66
PA
1521 unsigned char *jjump_pad_insn,
1522 ULONGEST *jjump_pad_insn_size,
1523 CORE_ADDR *adjusted_insn_addr,
405f8e94
SS
1524 CORE_ADDR *adjusted_insn_addr_end,
1525 char *err)
fa593d66
PA
1526{
1527 unsigned char buf[40];
1528 int i, offset;
f4647387
YQ
1529 int64_t loffset;
1530
fa593d66
PA
1531 CORE_ADDR buildaddr = *jump_entry;
1532
1533 /* Build the jump pad. */
1534
1535 /* First, do tracepoint data collection. Save registers. */
1536 i = 0;
1537 /* Need to ensure stack pointer saved first. */
1538 buf[i++] = 0x54; /* push %rsp */
1539 buf[i++] = 0x55; /* push %rbp */
1540 buf[i++] = 0x57; /* push %rdi */
1541 buf[i++] = 0x56; /* push %rsi */
1542 buf[i++] = 0x52; /* push %rdx */
1543 buf[i++] = 0x51; /* push %rcx */
1544 buf[i++] = 0x53; /* push %rbx */
1545 buf[i++] = 0x50; /* push %rax */
1546 buf[i++] = 0x41; buf[i++] = 0x57; /* push %r15 */
1547 buf[i++] = 0x41; buf[i++] = 0x56; /* push %r14 */
1548 buf[i++] = 0x41; buf[i++] = 0x55; /* push %r13 */
1549 buf[i++] = 0x41; buf[i++] = 0x54; /* push %r12 */
1550 buf[i++] = 0x41; buf[i++] = 0x53; /* push %r11 */
1551 buf[i++] = 0x41; buf[i++] = 0x52; /* push %r10 */
1552 buf[i++] = 0x41; buf[i++] = 0x51; /* push %r9 */
1553 buf[i++] = 0x41; buf[i++] = 0x50; /* push %r8 */
1554 buf[i++] = 0x9c; /* pushfq */
1555 buf[i++] = 0x48; /* movl <addr>,%rdi */
1556 buf[i++] = 0xbf;
1557 *((unsigned long *)(buf + i)) = (unsigned long) tpaddr;
1558 i += sizeof (unsigned long);
1559 buf[i++] = 0x57; /* push %rdi */
1560 append_insns (&buildaddr, i, buf);
1561
1562 /* Stack space for the collecting_t object. */
1563 i = 0;
1564 i += push_opcode (&buf[i], "48 83 ec 18"); /* sub $0x18,%rsp */
1565 i += push_opcode (&buf[i], "48 b8"); /* mov <tpoint>,%rax */
1566 memcpy (buf + i, &tpoint, 8);
1567 i += 8;
1568 i += push_opcode (&buf[i], "48 89 04 24"); /* mov %rax,(%rsp) */
1569 i += push_opcode (&buf[i],
1570 "64 48 8b 04 25 00 00 00 00"); /* mov %fs:0x0,%rax */
1571 i += push_opcode (&buf[i], "48 89 44 24 08"); /* mov %rax,0x8(%rsp) */
1572 append_insns (&buildaddr, i, buf);
1573
1574 /* spin-lock. */
1575 i = 0;
1576 i += push_opcode (&buf[i], "48 be"); /* movl <lockaddr>,%rsi */
1577 memcpy (&buf[i], (void *) &lockaddr, 8);
1578 i += 8;
1579 i += push_opcode (&buf[i], "48 89 e1"); /* mov %rsp,%rcx */
1580 i += push_opcode (&buf[i], "31 c0"); /* xor %eax,%eax */
1581 i += push_opcode (&buf[i], "f0 48 0f b1 0e"); /* lock cmpxchg %rcx,(%rsi) */
1582 i += push_opcode (&buf[i], "48 85 c0"); /* test %rax,%rax */
1583 i += push_opcode (&buf[i], "75 f4"); /* jne <again> */
1584 append_insns (&buildaddr, i, buf);
1585
1586 /* Set up the gdb_collect call. */
1587 /* At this point, (stack pointer + 0x18) is the base of our saved
1588 register block. */
1589
1590 i = 0;
1591 i += push_opcode (&buf[i], "48 89 e6"); /* mov %rsp,%rsi */
1592 i += push_opcode (&buf[i], "48 83 c6 18"); /* add $0x18,%rsi */
1593
1594 /* tpoint address may be 64-bit wide. */
1595 i += push_opcode (&buf[i], "48 bf"); /* movl <addr>,%rdi */
1596 memcpy (buf + i, &tpoint, 8);
1597 i += 8;
1598 append_insns (&buildaddr, i, buf);
1599
1600 /* The collector function being in the shared library, may be
1601 >31-bits away off the jump pad. */
1602 i = 0;
1603 i += push_opcode (&buf[i], "48 b8"); /* mov $collector,%rax */
1604 memcpy (buf + i, &collector, 8);
1605 i += 8;
1606 i += push_opcode (&buf[i], "ff d0"); /* callq *%rax */
1607 append_insns (&buildaddr, i, buf);
1608
1609 /* Clear the spin-lock. */
1610 i = 0;
1611 i += push_opcode (&buf[i], "31 c0"); /* xor %eax,%eax */
1612 i += push_opcode (&buf[i], "48 a3"); /* mov %rax, lockaddr */
1613 memcpy (buf + i, &lockaddr, 8);
1614 i += 8;
1615 append_insns (&buildaddr, i, buf);
1616
1617 /* Remove stack that had been used for the collect_t object. */
1618 i = 0;
1619 i += push_opcode (&buf[i], "48 83 c4 18"); /* add $0x18,%rsp */
1620 append_insns (&buildaddr, i, buf);
1621
1622 /* Restore register state. */
1623 i = 0;
1624 buf[i++] = 0x48; /* add $0x8,%rsp */
1625 buf[i++] = 0x83;
1626 buf[i++] = 0xc4;
1627 buf[i++] = 0x08;
1628 buf[i++] = 0x9d; /* popfq */
1629 buf[i++] = 0x41; buf[i++] = 0x58; /* pop %r8 */
1630 buf[i++] = 0x41; buf[i++] = 0x59; /* pop %r9 */
1631 buf[i++] = 0x41; buf[i++] = 0x5a; /* pop %r10 */
1632 buf[i++] = 0x41; buf[i++] = 0x5b; /* pop %r11 */
1633 buf[i++] = 0x41; buf[i++] = 0x5c; /* pop %r12 */
1634 buf[i++] = 0x41; buf[i++] = 0x5d; /* pop %r13 */
1635 buf[i++] = 0x41; buf[i++] = 0x5e; /* pop %r14 */
1636 buf[i++] = 0x41; buf[i++] = 0x5f; /* pop %r15 */
1637 buf[i++] = 0x58; /* pop %rax */
1638 buf[i++] = 0x5b; /* pop %rbx */
1639 buf[i++] = 0x59; /* pop %rcx */
1640 buf[i++] = 0x5a; /* pop %rdx */
1641 buf[i++] = 0x5e; /* pop %rsi */
1642 buf[i++] = 0x5f; /* pop %rdi */
1643 buf[i++] = 0x5d; /* pop %rbp */
1644 buf[i++] = 0x5c; /* pop %rsp */
1645 append_insns (&buildaddr, i, buf);
1646
1647 /* Now, adjust the original instruction to execute in the jump
1648 pad. */
1649 *adjusted_insn_addr = buildaddr;
1650 relocate_instruction (&buildaddr, tpaddr);
1651 *adjusted_insn_addr_end = buildaddr;
1652
1653 /* Finally, write a jump back to the program. */
f4647387
YQ
1654
1655 loffset = (tpaddr + orig_size) - (buildaddr + sizeof (jump_insn));
1656 if (loffset > INT_MAX || loffset < INT_MIN)
1657 {
1658 sprintf (err,
1659 "E.Jump back from jump pad too far from tracepoint "
1660 "(offset 0x%" PRIx64 " > int32).", loffset);
1661 return 1;
1662 }
1663
1664 offset = (int) loffset;
fa593d66
PA
1665 memcpy (buf, jump_insn, sizeof (jump_insn));
1666 memcpy (buf + 1, &offset, 4);
1667 append_insns (&buildaddr, sizeof (jump_insn), buf);
1668
1669 /* The jump pad is now built. Wire in a jump to our jump pad. This
1670 is always done last (by our caller actually), so that we can
1671 install fast tracepoints with threads running. This relies on
1672 the agent's atomic write support. */
f4647387
YQ
1673 loffset = *jump_entry - (tpaddr + sizeof (jump_insn));
1674 if (loffset > INT_MAX || loffset < INT_MIN)
1675 {
1676 sprintf (err,
1677 "E.Jump pad too far from tracepoint "
1678 "(offset 0x%" PRIx64 " > int32).", loffset);
1679 return 1;
1680 }
1681
1682 offset = (int) loffset;
1683
fa593d66
PA
1684 memcpy (buf, jump_insn, sizeof (jump_insn));
1685 memcpy (buf + 1, &offset, 4);
1686 memcpy (jjump_pad_insn, buf, sizeof (jump_insn));
1687 *jjump_pad_insn_size = sizeof (jump_insn);
1688
1689 /* Return the end address of our pad. */
1690 *jump_entry = buildaddr;
1691
1692 return 0;
1693}
1694
1695#endif /* __x86_64__ */
1696
1697/* Build a jump pad that saves registers and calls a collection
1698 function. Writes a jump instruction to the jump pad to
1699 JJUMPAD_INSN. The caller is responsible to write it in at the
1700 tracepoint address. */
1701
1702static int
1703i386_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, CORE_ADDR tpaddr,
1704 CORE_ADDR collector,
1705 CORE_ADDR lockaddr,
1706 ULONGEST orig_size,
1707 CORE_ADDR *jump_entry,
405f8e94
SS
1708 CORE_ADDR *trampoline,
1709 ULONGEST *trampoline_size,
fa593d66
PA
1710 unsigned char *jjump_pad_insn,
1711 ULONGEST *jjump_pad_insn_size,
1712 CORE_ADDR *adjusted_insn_addr,
405f8e94
SS
1713 CORE_ADDR *adjusted_insn_addr_end,
1714 char *err)
fa593d66
PA
1715{
1716 unsigned char buf[0x100];
1717 int i, offset;
1718 CORE_ADDR buildaddr = *jump_entry;
1719
1720 /* Build the jump pad. */
1721
1722 /* First, do tracepoint data collection. Save registers. */
1723 i = 0;
1724 buf[i++] = 0x60; /* pushad */
1725 buf[i++] = 0x68; /* push tpaddr aka $pc */
1726 *((int *)(buf + i)) = (int) tpaddr;
1727 i += 4;
1728 buf[i++] = 0x9c; /* pushf */
1729 buf[i++] = 0x1e; /* push %ds */
1730 buf[i++] = 0x06; /* push %es */
1731 buf[i++] = 0x0f; /* push %fs */
1732 buf[i++] = 0xa0;
1733 buf[i++] = 0x0f; /* push %gs */
1734 buf[i++] = 0xa8;
1735 buf[i++] = 0x16; /* push %ss */
1736 buf[i++] = 0x0e; /* push %cs */
1737 append_insns (&buildaddr, i, buf);
1738
1739 /* Stack space for the collecting_t object. */
1740 i = 0;
1741 i += push_opcode (&buf[i], "83 ec 08"); /* sub $0x8,%esp */
1742
1743 /* Build the object. */
1744 i += push_opcode (&buf[i], "b8"); /* mov <tpoint>,%eax */
1745 memcpy (buf + i, &tpoint, 4);
1746 i += 4;
1747 i += push_opcode (&buf[i], "89 04 24"); /* mov %eax,(%esp) */
1748
1749 i += push_opcode (&buf[i], "65 a1 00 00 00 00"); /* mov %gs:0x0,%eax */
1750 i += push_opcode (&buf[i], "89 44 24 04"); /* mov %eax,0x4(%esp) */
1751 append_insns (&buildaddr, i, buf);
1752
1753 /* spin-lock. Note this is using cmpxchg, which leaves i386 behind.
1754 If we cared for it, this could be using xchg alternatively. */
1755
1756 i = 0;
1757 i += push_opcode (&buf[i], "31 c0"); /* xor %eax,%eax */
1758 i += push_opcode (&buf[i], "f0 0f b1 25"); /* lock cmpxchg
1759 %esp,<lockaddr> */
1760 memcpy (&buf[i], (void *) &lockaddr, 4);
1761 i += 4;
1762 i += push_opcode (&buf[i], "85 c0"); /* test %eax,%eax */
1763 i += push_opcode (&buf[i], "75 f2"); /* jne <again> */
1764 append_insns (&buildaddr, i, buf);
1765
1766
1767 /* Set up arguments to the gdb_collect call. */
1768 i = 0;
1769 i += push_opcode (&buf[i], "89 e0"); /* mov %esp,%eax */
1770 i += push_opcode (&buf[i], "83 c0 08"); /* add $0x08,%eax */
1771 i += push_opcode (&buf[i], "89 44 24 fc"); /* mov %eax,-0x4(%esp) */
1772 append_insns (&buildaddr, i, buf);
1773
1774 i = 0;
1775 i += push_opcode (&buf[i], "83 ec 08"); /* sub $0x8,%esp */
1776 append_insns (&buildaddr, i, buf);
1777
1778 i = 0;
1779 i += push_opcode (&buf[i], "c7 04 24"); /* movl <addr>,(%esp) */
1780 memcpy (&buf[i], (void *) &tpoint, 4);
1781 i += 4;
1782 append_insns (&buildaddr, i, buf);
1783
1784 buf[0] = 0xe8; /* call <reladdr> */
1785 offset = collector - (buildaddr + sizeof (jump_insn));
1786 memcpy (buf + 1, &offset, 4);
1787 append_insns (&buildaddr, 5, buf);
1788 /* Clean up after the call. */
1789 buf[0] = 0x83; /* add $0x8,%esp */
1790 buf[1] = 0xc4;
1791 buf[2] = 0x08;
1792 append_insns (&buildaddr, 3, buf);
1793
1794
1795 /* Clear the spin-lock. This would need the LOCK prefix on older
1796 broken archs. */
1797 i = 0;
1798 i += push_opcode (&buf[i], "31 c0"); /* xor %eax,%eax */
1799 i += push_opcode (&buf[i], "a3"); /* mov %eax, lockaddr */
1800 memcpy (buf + i, &lockaddr, 4);
1801 i += 4;
1802 append_insns (&buildaddr, i, buf);
1803
1804
1805 /* Remove stack that had been used for the collect_t object. */
1806 i = 0;
1807 i += push_opcode (&buf[i], "83 c4 08"); /* add $0x08,%esp */
1808 append_insns (&buildaddr, i, buf);
1809
1810 i = 0;
1811 buf[i++] = 0x83; /* add $0x4,%esp (no pop of %cs, assume unchanged) */
1812 buf[i++] = 0xc4;
1813 buf[i++] = 0x04;
1814 buf[i++] = 0x17; /* pop %ss */
1815 buf[i++] = 0x0f; /* pop %gs */
1816 buf[i++] = 0xa9;
1817 buf[i++] = 0x0f; /* pop %fs */
1818 buf[i++] = 0xa1;
1819 buf[i++] = 0x07; /* pop %es */
405f8e94 1820 buf[i++] = 0x1f; /* pop %ds */
fa593d66
PA
1821 buf[i++] = 0x9d; /* popf */
1822 buf[i++] = 0x83; /* add $0x4,%esp (pop of tpaddr aka $pc) */
1823 buf[i++] = 0xc4;
1824 buf[i++] = 0x04;
1825 buf[i++] = 0x61; /* popad */
1826 append_insns (&buildaddr, i, buf);
1827
1828 /* Now, adjust the original instruction to execute in the jump
1829 pad. */
1830 *adjusted_insn_addr = buildaddr;
1831 relocate_instruction (&buildaddr, tpaddr);
1832 *adjusted_insn_addr_end = buildaddr;
1833
1834 /* Write the jump back to the program. */
1835 offset = (tpaddr + orig_size) - (buildaddr + sizeof (jump_insn));
1836 memcpy (buf, jump_insn, sizeof (jump_insn));
1837 memcpy (buf + 1, &offset, 4);
1838 append_insns (&buildaddr, sizeof (jump_insn), buf);
1839
1840 /* The jump pad is now built. Wire in a jump to our jump pad. This
1841 is always done last (by our caller actually), so that we can
1842 install fast tracepoints with threads running. This relies on
1843 the agent's atomic write support. */
405f8e94
SS
1844 if (orig_size == 4)
1845 {
1846 /* Create a trampoline. */
1847 *trampoline_size = sizeof (jump_insn);
1848 if (!claim_trampoline_space (*trampoline_size, trampoline))
1849 {
1850 /* No trampoline space available. */
1851 strcpy (err,
1852 "E.Cannot allocate trampoline space needed for fast "
1853 "tracepoints on 4-byte instructions.");
1854 return 1;
1855 }
1856
1857 offset = *jump_entry - (*trampoline + sizeof (jump_insn));
1858 memcpy (buf, jump_insn, sizeof (jump_insn));
1859 memcpy (buf + 1, &offset, 4);
1860 write_inferior_memory (*trampoline, buf, sizeof (jump_insn));
1861
1862 /* Use a 16-bit relative jump instruction to jump to the trampoline. */
1863 offset = (*trampoline - (tpaddr + sizeof (small_jump_insn))) & 0xffff;
1864 memcpy (buf, small_jump_insn, sizeof (small_jump_insn));
1865 memcpy (buf + 2, &offset, 2);
1866 memcpy (jjump_pad_insn, buf, sizeof (small_jump_insn));
1867 *jjump_pad_insn_size = sizeof (small_jump_insn);
1868 }
1869 else
1870 {
1871 /* Else use a 32-bit relative jump instruction. */
1872 offset = *jump_entry - (tpaddr + sizeof (jump_insn));
1873 memcpy (buf, jump_insn, sizeof (jump_insn));
1874 memcpy (buf + 1, &offset, 4);
1875 memcpy (jjump_pad_insn, buf, sizeof (jump_insn));
1876 *jjump_pad_insn_size = sizeof (jump_insn);
1877 }
fa593d66
PA
1878
1879 /* Return the end address of our pad. */
1880 *jump_entry = buildaddr;
1881
1882 return 0;
1883}
1884
1885static int
1886x86_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, CORE_ADDR tpaddr,
1887 CORE_ADDR collector,
1888 CORE_ADDR lockaddr,
1889 ULONGEST orig_size,
1890 CORE_ADDR *jump_entry,
405f8e94
SS
1891 CORE_ADDR *trampoline,
1892 ULONGEST *trampoline_size,
fa593d66
PA
1893 unsigned char *jjump_pad_insn,
1894 ULONGEST *jjump_pad_insn_size,
1895 CORE_ADDR *adjusted_insn_addr,
405f8e94
SS
1896 CORE_ADDR *adjusted_insn_addr_end,
1897 char *err)
fa593d66
PA
1898{
1899#ifdef __x86_64__
3aee8918 1900 if (is_64bit_tdesc ())
fa593d66
PA
1901 return amd64_install_fast_tracepoint_jump_pad (tpoint, tpaddr,
1902 collector, lockaddr,
1903 orig_size, jump_entry,
405f8e94 1904 trampoline, trampoline_size,
fa593d66
PA
1905 jjump_pad_insn,
1906 jjump_pad_insn_size,
1907 adjusted_insn_addr,
405f8e94
SS
1908 adjusted_insn_addr_end,
1909 err);
fa593d66
PA
1910#endif
1911
1912 return i386_install_fast_tracepoint_jump_pad (tpoint, tpaddr,
1913 collector, lockaddr,
1914 orig_size, jump_entry,
405f8e94 1915 trampoline, trampoline_size,
fa593d66
PA
1916 jjump_pad_insn,
1917 jjump_pad_insn_size,
1918 adjusted_insn_addr,
405f8e94
SS
1919 adjusted_insn_addr_end,
1920 err);
1921}
1922
1923/* Return the minimum instruction length for fast tracepoints on x86/x86-64
1924 architectures. */
1925
1926static int
1927x86_get_min_fast_tracepoint_insn_len (void)
1928{
1929 static int warned_about_fast_tracepoints = 0;
1930
1931#ifdef __x86_64__
1932 /* On x86-64, 5-byte jump instructions with a 4-byte offset are always
1933 used for fast tracepoints. */
3aee8918 1934 if (is_64bit_tdesc ())
405f8e94
SS
1935 return 5;
1936#endif
1937
58b4daa5 1938 if (agent_loaded_p ())
405f8e94
SS
1939 {
1940 char errbuf[IPA_BUFSIZ];
1941
1942 errbuf[0] = '\0';
1943
1944 /* On x86, if trampolines are available, then 4-byte jump instructions
1945 with a 2-byte offset may be used, otherwise 5-byte jump instructions
1946 with a 4-byte offset are used instead. */
1947 if (have_fast_tracepoint_trampoline_buffer (errbuf))
1948 return 4;
1949 else
1950 {
1951 /* GDB has no channel to explain to user why a shorter fast
1952 tracepoint is not possible, but at least make GDBserver
1953 mention that something has gone awry. */
1954 if (!warned_about_fast_tracepoints)
1955 {
1956 warning ("4-byte fast tracepoints not available; %s\n", errbuf);
1957 warned_about_fast_tracepoints = 1;
1958 }
1959 return 5;
1960 }
1961 }
1962 else
1963 {
1964 /* Indicate that the minimum length is currently unknown since the IPA
1965 has not loaded yet. */
1966 return 0;
1967 }
fa593d66
PA
1968}
1969
6a271cae
PA
1970static void
1971add_insns (unsigned char *start, int len)
1972{
1973 CORE_ADDR buildaddr = current_insn_ptr;
1974
1975 if (debug_threads)
1976 fprintf (stderr, "Adding %d bytes of insn at %s\n",
1977 len, paddress (buildaddr));
1978
1979 append_insns (&buildaddr, len, start);
1980 current_insn_ptr = buildaddr;
1981}
1982
6a271cae
PA
1983/* Our general strategy for emitting code is to avoid specifying raw
1984 bytes whenever possible, and instead copy a block of inline asm
1985 that is embedded in the function. This is a little messy, because
1986 we need to keep the compiler from discarding what looks like dead
1987 code, plus suppress various warnings. */
1988
9e4344e5
PA
1989#define EMIT_ASM(NAME, INSNS) \
1990 do \
1991 { \
1992 extern unsigned char start_ ## NAME, end_ ## NAME; \
1993 add_insns (&start_ ## NAME, &end_ ## NAME - &start_ ## NAME); \
493e2a69 1994 __asm__ ("jmp end_" #NAME "\n" \
9e4344e5
PA
1995 "\t" "start_" #NAME ":" \
1996 "\t" INSNS "\n" \
1997 "\t" "end_" #NAME ":"); \
1998 } while (0)
6a271cae
PA
1999
2000#ifdef __x86_64__
2001
2002#define EMIT_ASM32(NAME,INSNS) \
9e4344e5
PA
2003 do \
2004 { \
2005 extern unsigned char start_ ## NAME, end_ ## NAME; \
2006 add_insns (&start_ ## NAME, &end_ ## NAME - &start_ ## NAME); \
2007 __asm__ (".code32\n" \
2008 "\t" "jmp end_" #NAME "\n" \
2009 "\t" "start_" #NAME ":\n" \
2010 "\t" INSNS "\n" \
2011 "\t" "end_" #NAME ":\n" \
2012 ".code64\n"); \
2013 } while (0)
6a271cae
PA
2014
2015#else
2016
2017#define EMIT_ASM32(NAME,INSNS) EMIT_ASM(NAME,INSNS)
2018
2019#endif
2020
2021#ifdef __x86_64__
2022
2023static void
2024amd64_emit_prologue (void)
2025{
2026 EMIT_ASM (amd64_prologue,
2027 "pushq %rbp\n\t"
2028 "movq %rsp,%rbp\n\t"
2029 "sub $0x20,%rsp\n\t"
2030 "movq %rdi,-8(%rbp)\n\t"
2031 "movq %rsi,-16(%rbp)");
2032}
2033
2034
2035static void
2036amd64_emit_epilogue (void)
2037{
2038 EMIT_ASM (amd64_epilogue,
2039 "movq -16(%rbp),%rdi\n\t"
2040 "movq %rax,(%rdi)\n\t"
2041 "xor %rax,%rax\n\t"
2042 "leave\n\t"
2043 "ret");
2044}
2045
2046static void
2047amd64_emit_add (void)
2048{
2049 EMIT_ASM (amd64_add,
2050 "add (%rsp),%rax\n\t"
2051 "lea 0x8(%rsp),%rsp");
2052}
2053
2054static void
2055amd64_emit_sub (void)
2056{
2057 EMIT_ASM (amd64_sub,
2058 "sub %rax,(%rsp)\n\t"
2059 "pop %rax");
2060}
2061
2062static void
2063amd64_emit_mul (void)
2064{
2065 emit_error = 1;
2066}
2067
2068static void
2069amd64_emit_lsh (void)
2070{
2071 emit_error = 1;
2072}
2073
2074static void
2075amd64_emit_rsh_signed (void)
2076{
2077 emit_error = 1;
2078}
2079
2080static void
2081amd64_emit_rsh_unsigned (void)
2082{
2083 emit_error = 1;
2084}
2085
2086static void
2087amd64_emit_ext (int arg)
2088{
2089 switch (arg)
2090 {
2091 case 8:
2092 EMIT_ASM (amd64_ext_8,
2093 "cbtw\n\t"
2094 "cwtl\n\t"
2095 "cltq");
2096 break;
2097 case 16:
2098 EMIT_ASM (amd64_ext_16,
2099 "cwtl\n\t"
2100 "cltq");
2101 break;
2102 case 32:
2103 EMIT_ASM (amd64_ext_32,
2104 "cltq");
2105 break;
2106 default:
2107 emit_error = 1;
2108 }
2109}
2110
2111static void
2112amd64_emit_log_not (void)
2113{
2114 EMIT_ASM (amd64_log_not,
2115 "test %rax,%rax\n\t"
2116 "sete %cl\n\t"
2117 "movzbq %cl,%rax");
2118}
2119
2120static void
2121amd64_emit_bit_and (void)
2122{
2123 EMIT_ASM (amd64_and,
2124 "and (%rsp),%rax\n\t"
2125 "lea 0x8(%rsp),%rsp");
2126}
2127
2128static void
2129amd64_emit_bit_or (void)
2130{
2131 EMIT_ASM (amd64_or,
2132 "or (%rsp),%rax\n\t"
2133 "lea 0x8(%rsp),%rsp");
2134}
2135
2136static void
2137amd64_emit_bit_xor (void)
2138{
2139 EMIT_ASM (amd64_xor,
2140 "xor (%rsp),%rax\n\t"
2141 "lea 0x8(%rsp),%rsp");
2142}
2143
2144static void
2145amd64_emit_bit_not (void)
2146{
2147 EMIT_ASM (amd64_bit_not,
2148 "xorq $0xffffffffffffffff,%rax");
2149}
2150
2151static void
2152amd64_emit_equal (void)
2153{
2154 EMIT_ASM (amd64_equal,
2155 "cmp %rax,(%rsp)\n\t"
2156 "je .Lamd64_equal_true\n\t"
2157 "xor %rax,%rax\n\t"
2158 "jmp .Lamd64_equal_end\n\t"
2159 ".Lamd64_equal_true:\n\t"
2160 "mov $0x1,%rax\n\t"
2161 ".Lamd64_equal_end:\n\t"
2162 "lea 0x8(%rsp),%rsp");
2163}
2164
2165static void
2166amd64_emit_less_signed (void)
2167{
2168 EMIT_ASM (amd64_less_signed,
2169 "cmp %rax,(%rsp)\n\t"
2170 "jl .Lamd64_less_signed_true\n\t"
2171 "xor %rax,%rax\n\t"
2172 "jmp .Lamd64_less_signed_end\n\t"
2173 ".Lamd64_less_signed_true:\n\t"
2174 "mov $1,%rax\n\t"
2175 ".Lamd64_less_signed_end:\n\t"
2176 "lea 0x8(%rsp),%rsp");
2177}
2178
2179static void
2180amd64_emit_less_unsigned (void)
2181{
2182 EMIT_ASM (amd64_less_unsigned,
2183 "cmp %rax,(%rsp)\n\t"
2184 "jb .Lamd64_less_unsigned_true\n\t"
2185 "xor %rax,%rax\n\t"
2186 "jmp .Lamd64_less_unsigned_end\n\t"
2187 ".Lamd64_less_unsigned_true:\n\t"
2188 "mov $1,%rax\n\t"
2189 ".Lamd64_less_unsigned_end:\n\t"
2190 "lea 0x8(%rsp),%rsp");
2191}
2192
2193static void
2194amd64_emit_ref (int size)
2195{
2196 switch (size)
2197 {
2198 case 1:
2199 EMIT_ASM (amd64_ref1,
2200 "movb (%rax),%al");
2201 break;
2202 case 2:
2203 EMIT_ASM (amd64_ref2,
2204 "movw (%rax),%ax");
2205 break;
2206 case 4:
2207 EMIT_ASM (amd64_ref4,
2208 "movl (%rax),%eax");
2209 break;
2210 case 8:
2211 EMIT_ASM (amd64_ref8,
2212 "movq (%rax),%rax");
2213 break;
2214 }
2215}
2216
2217static void
2218amd64_emit_if_goto (int *offset_p, int *size_p)
2219{
2220 EMIT_ASM (amd64_if_goto,
2221 "mov %rax,%rcx\n\t"
2222 "pop %rax\n\t"
2223 "cmp $0,%rcx\n\t"
2224 ".byte 0x0f, 0x85, 0x0, 0x0, 0x0, 0x0");
2225 if (offset_p)
2226 *offset_p = 10;
2227 if (size_p)
2228 *size_p = 4;
2229}
2230
2231static void
2232amd64_emit_goto (int *offset_p, int *size_p)
2233{
2234 EMIT_ASM (amd64_goto,
2235 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0");
2236 if (offset_p)
2237 *offset_p = 1;
2238 if (size_p)
2239 *size_p = 4;
2240}
2241
2242static void
2243amd64_write_goto_address (CORE_ADDR from, CORE_ADDR to, int size)
2244{
2245 int diff = (to - (from + size));
2246 unsigned char buf[sizeof (int)];
2247
2248 if (size != 4)
2249 {
2250 emit_error = 1;
2251 return;
2252 }
2253
2254 memcpy (buf, &diff, sizeof (int));
2255 write_inferior_memory (from, buf, sizeof (int));
2256}
2257
2258static void
4e29fb54 2259amd64_emit_const (LONGEST num)
6a271cae
PA
2260{
2261 unsigned char buf[16];
2262 int i;
2263 CORE_ADDR buildaddr = current_insn_ptr;
2264
2265 i = 0;
2266 buf[i++] = 0x48; buf[i++] = 0xb8; /* mov $<n>,%rax */
b00ad6ff 2267 memcpy (&buf[i], &num, sizeof (num));
6a271cae
PA
2268 i += 8;
2269 append_insns (&buildaddr, i, buf);
2270 current_insn_ptr = buildaddr;
2271}
2272
2273static void
2274amd64_emit_call (CORE_ADDR fn)
2275{
2276 unsigned char buf[16];
2277 int i;
2278 CORE_ADDR buildaddr;
4e29fb54 2279 LONGEST offset64;
6a271cae
PA
2280
2281 /* The destination function being in the shared library, may be
2282 >31-bits away off the compiled code pad. */
2283
2284 buildaddr = current_insn_ptr;
2285
2286 offset64 = fn - (buildaddr + 1 /* call op */ + 4 /* 32-bit offset */);
2287
2288 i = 0;
2289
2290 if (offset64 > INT_MAX || offset64 < INT_MIN)
2291 {
2292 /* Offset is too large for a call. Use callq, but that requires
2293 a register, so avoid it if possible. Use r10, since it is
2294 call-clobbered, we don't have to push/pop it. */
2295 buf[i++] = 0x48; /* mov $fn,%r10 */
2296 buf[i++] = 0xba;
2297 memcpy (buf + i, &fn, 8);
2298 i += 8;
2299 buf[i++] = 0xff; /* callq *%r10 */
2300 buf[i++] = 0xd2;
2301 }
2302 else
2303 {
2304 int offset32 = offset64; /* we know we can't overflow here. */
2305 memcpy (buf + i, &offset32, 4);
2306 i += 4;
2307 }
2308
2309 append_insns (&buildaddr, i, buf);
2310 current_insn_ptr = buildaddr;
2311}
2312
2313static void
2314amd64_emit_reg (int reg)
2315{
2316 unsigned char buf[16];
2317 int i;
2318 CORE_ADDR buildaddr;
2319
2320 /* Assume raw_regs is still in %rdi. */
2321 buildaddr = current_insn_ptr;
2322 i = 0;
2323 buf[i++] = 0xbe; /* mov $<n>,%esi */
b00ad6ff 2324 memcpy (&buf[i], &reg, sizeof (reg));
6a271cae
PA
2325 i += 4;
2326 append_insns (&buildaddr, i, buf);
2327 current_insn_ptr = buildaddr;
2328 amd64_emit_call (get_raw_reg_func_addr ());
2329}
2330
2331static void
2332amd64_emit_pop (void)
2333{
2334 EMIT_ASM (amd64_pop,
2335 "pop %rax");
2336}
2337
2338static void
2339amd64_emit_stack_flush (void)
2340{
2341 EMIT_ASM (amd64_stack_flush,
2342 "push %rax");
2343}
2344
2345static void
2346amd64_emit_zero_ext (int arg)
2347{
2348 switch (arg)
2349 {
2350 case 8:
2351 EMIT_ASM (amd64_zero_ext_8,
2352 "and $0xff,%rax");
2353 break;
2354 case 16:
2355 EMIT_ASM (amd64_zero_ext_16,
2356 "and $0xffff,%rax");
2357 break;
2358 case 32:
2359 EMIT_ASM (amd64_zero_ext_32,
2360 "mov $0xffffffff,%rcx\n\t"
2361 "and %rcx,%rax");
2362 break;
2363 default:
2364 emit_error = 1;
2365 }
2366}
2367
2368static void
2369amd64_emit_swap (void)
2370{
2371 EMIT_ASM (amd64_swap,
2372 "mov %rax,%rcx\n\t"
2373 "pop %rax\n\t"
2374 "push %rcx");
2375}
2376
2377static void
2378amd64_emit_stack_adjust (int n)
2379{
2380 unsigned char buf[16];
2381 int i;
2382 CORE_ADDR buildaddr = current_insn_ptr;
2383
2384 i = 0;
2385 buf[i++] = 0x48; /* lea $<n>(%rsp),%rsp */
2386 buf[i++] = 0x8d;
2387 buf[i++] = 0x64;
2388 buf[i++] = 0x24;
2389 /* This only handles adjustments up to 16, but we don't expect any more. */
2390 buf[i++] = n * 8;
2391 append_insns (&buildaddr, i, buf);
2392 current_insn_ptr = buildaddr;
2393}
2394
2395/* FN's prototype is `LONGEST(*fn)(int)'. */
2396
2397static void
2398amd64_emit_int_call_1 (CORE_ADDR fn, int arg1)
2399{
2400 unsigned char buf[16];
2401 int i;
2402 CORE_ADDR buildaddr;
2403
2404 buildaddr = current_insn_ptr;
2405 i = 0;
2406 buf[i++] = 0xbf; /* movl $<n>,%edi */
b00ad6ff 2407 memcpy (&buf[i], &arg1, sizeof (arg1));
6a271cae
PA
2408 i += 4;
2409 append_insns (&buildaddr, i, buf);
2410 current_insn_ptr = buildaddr;
2411 amd64_emit_call (fn);
2412}
2413
4e29fb54 2414/* FN's prototype is `void(*fn)(int,LONGEST)'. */
6a271cae
PA
2415
2416static void
2417amd64_emit_void_call_2 (CORE_ADDR fn, int arg1)
2418{
2419 unsigned char buf[16];
2420 int i;
2421 CORE_ADDR buildaddr;
2422
2423 buildaddr = current_insn_ptr;
2424 i = 0;
2425 buf[i++] = 0xbf; /* movl $<n>,%edi */
b00ad6ff 2426 memcpy (&buf[i], &arg1, sizeof (arg1));
6a271cae
PA
2427 i += 4;
2428 append_insns (&buildaddr, i, buf);
2429 current_insn_ptr = buildaddr;
2430 EMIT_ASM (amd64_void_call_2_a,
2431 /* Save away a copy of the stack top. */
2432 "push %rax\n\t"
2433 /* Also pass top as the second argument. */
2434 "mov %rax,%rsi");
2435 amd64_emit_call (fn);
2436 EMIT_ASM (amd64_void_call_2_b,
2437 /* Restore the stack top, %rax may have been trashed. */
2438 "pop %rax");
2439}
2440
6b9801d4
SS
2441void
2442amd64_emit_eq_goto (int *offset_p, int *size_p)
2443{
2444 EMIT_ASM (amd64_eq,
2445 "cmp %rax,(%rsp)\n\t"
2446 "jne .Lamd64_eq_fallthru\n\t"
2447 "lea 0x8(%rsp),%rsp\n\t"
2448 "pop %rax\n\t"
2449 /* jmp, but don't trust the assembler to choose the right jump */
2450 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0\n\t"
2451 ".Lamd64_eq_fallthru:\n\t"
2452 "lea 0x8(%rsp),%rsp\n\t"
2453 "pop %rax");
2454
2455 if (offset_p)
2456 *offset_p = 13;
2457 if (size_p)
2458 *size_p = 4;
2459}
2460
2461void
2462amd64_emit_ne_goto (int *offset_p, int *size_p)
2463{
2464 EMIT_ASM (amd64_ne,
2465 "cmp %rax,(%rsp)\n\t"
2466 "je .Lamd64_ne_fallthru\n\t"
2467 "lea 0x8(%rsp),%rsp\n\t"
2468 "pop %rax\n\t"
2469 /* jmp, but don't trust the assembler to choose the right jump */
2470 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0\n\t"
2471 ".Lamd64_ne_fallthru:\n\t"
2472 "lea 0x8(%rsp),%rsp\n\t"
2473 "pop %rax");
2474
2475 if (offset_p)
2476 *offset_p = 13;
2477 if (size_p)
2478 *size_p = 4;
2479}
2480
2481void
2482amd64_emit_lt_goto (int *offset_p, int *size_p)
2483{
2484 EMIT_ASM (amd64_lt,
2485 "cmp %rax,(%rsp)\n\t"
2486 "jnl .Lamd64_lt_fallthru\n\t"
2487 "lea 0x8(%rsp),%rsp\n\t"
2488 "pop %rax\n\t"
2489 /* jmp, but don't trust the assembler to choose the right jump */
2490 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0\n\t"
2491 ".Lamd64_lt_fallthru:\n\t"
2492 "lea 0x8(%rsp),%rsp\n\t"
2493 "pop %rax");
2494
2495 if (offset_p)
2496 *offset_p = 13;
2497 if (size_p)
2498 *size_p = 4;
2499}
2500
2501void
2502amd64_emit_le_goto (int *offset_p, int *size_p)
2503{
2504 EMIT_ASM (amd64_le,
2505 "cmp %rax,(%rsp)\n\t"
2506 "jnle .Lamd64_le_fallthru\n\t"
2507 "lea 0x8(%rsp),%rsp\n\t"
2508 "pop %rax\n\t"
2509 /* jmp, but don't trust the assembler to choose the right jump */
2510 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0\n\t"
2511 ".Lamd64_le_fallthru:\n\t"
2512 "lea 0x8(%rsp),%rsp\n\t"
2513 "pop %rax");
2514
2515 if (offset_p)
2516 *offset_p = 13;
2517 if (size_p)
2518 *size_p = 4;
2519}
2520
2521void
2522amd64_emit_gt_goto (int *offset_p, int *size_p)
2523{
2524 EMIT_ASM (amd64_gt,
2525 "cmp %rax,(%rsp)\n\t"
2526 "jng .Lamd64_gt_fallthru\n\t"
2527 "lea 0x8(%rsp),%rsp\n\t"
2528 "pop %rax\n\t"
2529 /* jmp, but don't trust the assembler to choose the right jump */
2530 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0\n\t"
2531 ".Lamd64_gt_fallthru:\n\t"
2532 "lea 0x8(%rsp),%rsp\n\t"
2533 "pop %rax");
2534
2535 if (offset_p)
2536 *offset_p = 13;
2537 if (size_p)
2538 *size_p = 4;
2539}
2540
2541void
2542amd64_emit_ge_goto (int *offset_p, int *size_p)
2543{
2544 EMIT_ASM (amd64_ge,
2545 "cmp %rax,(%rsp)\n\t"
2546 "jnge .Lamd64_ge_fallthru\n\t"
2547 ".Lamd64_ge_jump:\n\t"
2548 "lea 0x8(%rsp),%rsp\n\t"
2549 "pop %rax\n\t"
2550 /* jmp, but don't trust the assembler to choose the right jump */
2551 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0\n\t"
2552 ".Lamd64_ge_fallthru:\n\t"
2553 "lea 0x8(%rsp),%rsp\n\t"
2554 "pop %rax");
2555
2556 if (offset_p)
2557 *offset_p = 13;
2558 if (size_p)
2559 *size_p = 4;
2560}
2561
6a271cae
PA
2562struct emit_ops amd64_emit_ops =
2563 {
2564 amd64_emit_prologue,
2565 amd64_emit_epilogue,
2566 amd64_emit_add,
2567 amd64_emit_sub,
2568 amd64_emit_mul,
2569 amd64_emit_lsh,
2570 amd64_emit_rsh_signed,
2571 amd64_emit_rsh_unsigned,
2572 amd64_emit_ext,
2573 amd64_emit_log_not,
2574 amd64_emit_bit_and,
2575 amd64_emit_bit_or,
2576 amd64_emit_bit_xor,
2577 amd64_emit_bit_not,
2578 amd64_emit_equal,
2579 amd64_emit_less_signed,
2580 amd64_emit_less_unsigned,
2581 amd64_emit_ref,
2582 amd64_emit_if_goto,
2583 amd64_emit_goto,
2584 amd64_write_goto_address,
2585 amd64_emit_const,
2586 amd64_emit_call,
2587 amd64_emit_reg,
2588 amd64_emit_pop,
2589 amd64_emit_stack_flush,
2590 amd64_emit_zero_ext,
2591 amd64_emit_swap,
2592 amd64_emit_stack_adjust,
2593 amd64_emit_int_call_1,
6b9801d4
SS
2594 amd64_emit_void_call_2,
2595 amd64_emit_eq_goto,
2596 amd64_emit_ne_goto,
2597 amd64_emit_lt_goto,
2598 amd64_emit_le_goto,
2599 amd64_emit_gt_goto,
2600 amd64_emit_ge_goto
6a271cae
PA
2601 };
2602
2603#endif /* __x86_64__ */
2604
2605static void
2606i386_emit_prologue (void)
2607{
2608 EMIT_ASM32 (i386_prologue,
2609 "push %ebp\n\t"
bf15cbda
SS
2610 "mov %esp,%ebp\n\t"
2611 "push %ebx");
6a271cae
PA
2612 /* At this point, the raw regs base address is at 8(%ebp), and the
2613 value pointer is at 12(%ebp). */
2614}
2615
2616static void
2617i386_emit_epilogue (void)
2618{
2619 EMIT_ASM32 (i386_epilogue,
2620 "mov 12(%ebp),%ecx\n\t"
2621 "mov %eax,(%ecx)\n\t"
2622 "mov %ebx,0x4(%ecx)\n\t"
2623 "xor %eax,%eax\n\t"
bf15cbda 2624 "pop %ebx\n\t"
6a271cae
PA
2625 "pop %ebp\n\t"
2626 "ret");
2627}
2628
2629static void
2630i386_emit_add (void)
2631{
2632 EMIT_ASM32 (i386_add,
2633 "add (%esp),%eax\n\t"
2634 "adc 0x4(%esp),%ebx\n\t"
2635 "lea 0x8(%esp),%esp");
2636}
2637
2638static void
2639i386_emit_sub (void)
2640{
2641 EMIT_ASM32 (i386_sub,
2642 "subl %eax,(%esp)\n\t"
2643 "sbbl %ebx,4(%esp)\n\t"
2644 "pop %eax\n\t"
2645 "pop %ebx\n\t");
2646}
2647
2648static void
2649i386_emit_mul (void)
2650{
2651 emit_error = 1;
2652}
2653
2654static void
2655i386_emit_lsh (void)
2656{
2657 emit_error = 1;
2658}
2659
2660static void
2661i386_emit_rsh_signed (void)
2662{
2663 emit_error = 1;
2664}
2665
2666static void
2667i386_emit_rsh_unsigned (void)
2668{
2669 emit_error = 1;
2670}
2671
2672static void
2673i386_emit_ext (int arg)
2674{
2675 switch (arg)
2676 {
2677 case 8:
2678 EMIT_ASM32 (i386_ext_8,
2679 "cbtw\n\t"
2680 "cwtl\n\t"
2681 "movl %eax,%ebx\n\t"
2682 "sarl $31,%ebx");
2683 break;
2684 case 16:
2685 EMIT_ASM32 (i386_ext_16,
2686 "cwtl\n\t"
2687 "movl %eax,%ebx\n\t"
2688 "sarl $31,%ebx");
2689 break;
2690 case 32:
2691 EMIT_ASM32 (i386_ext_32,
2692 "movl %eax,%ebx\n\t"
2693 "sarl $31,%ebx");
2694 break;
2695 default:
2696 emit_error = 1;
2697 }
2698}
2699
2700static void
2701i386_emit_log_not (void)
2702{
2703 EMIT_ASM32 (i386_log_not,
2704 "or %ebx,%eax\n\t"
2705 "test %eax,%eax\n\t"
2706 "sete %cl\n\t"
2707 "xor %ebx,%ebx\n\t"
2708 "movzbl %cl,%eax");
2709}
2710
2711static void
2712i386_emit_bit_and (void)
2713{
2714 EMIT_ASM32 (i386_and,
2715 "and (%esp),%eax\n\t"
2716 "and 0x4(%esp),%ebx\n\t"
2717 "lea 0x8(%esp),%esp");
2718}
2719
2720static void
2721i386_emit_bit_or (void)
2722{
2723 EMIT_ASM32 (i386_or,
2724 "or (%esp),%eax\n\t"
2725 "or 0x4(%esp),%ebx\n\t"
2726 "lea 0x8(%esp),%esp");
2727}
2728
2729static void
2730i386_emit_bit_xor (void)
2731{
2732 EMIT_ASM32 (i386_xor,
2733 "xor (%esp),%eax\n\t"
2734 "xor 0x4(%esp),%ebx\n\t"
2735 "lea 0x8(%esp),%esp");
2736}
2737
2738static void
2739i386_emit_bit_not (void)
2740{
2741 EMIT_ASM32 (i386_bit_not,
2742 "xor $0xffffffff,%eax\n\t"
2743 "xor $0xffffffff,%ebx\n\t");
2744}
2745
2746static void
2747i386_emit_equal (void)
2748{
2749 EMIT_ASM32 (i386_equal,
2750 "cmpl %ebx,4(%esp)\n\t"
2751 "jne .Li386_equal_false\n\t"
2752 "cmpl %eax,(%esp)\n\t"
2753 "je .Li386_equal_true\n\t"
2754 ".Li386_equal_false:\n\t"
2755 "xor %eax,%eax\n\t"
2756 "jmp .Li386_equal_end\n\t"
2757 ".Li386_equal_true:\n\t"
2758 "mov $1,%eax\n\t"
2759 ".Li386_equal_end:\n\t"
2760 "xor %ebx,%ebx\n\t"
2761 "lea 0x8(%esp),%esp");
2762}
2763
2764static void
2765i386_emit_less_signed (void)
2766{
2767 EMIT_ASM32 (i386_less_signed,
2768 "cmpl %ebx,4(%esp)\n\t"
2769 "jl .Li386_less_signed_true\n\t"
2770 "jne .Li386_less_signed_false\n\t"
2771 "cmpl %eax,(%esp)\n\t"
2772 "jl .Li386_less_signed_true\n\t"
2773 ".Li386_less_signed_false:\n\t"
2774 "xor %eax,%eax\n\t"
2775 "jmp .Li386_less_signed_end\n\t"
2776 ".Li386_less_signed_true:\n\t"
2777 "mov $1,%eax\n\t"
2778 ".Li386_less_signed_end:\n\t"
2779 "xor %ebx,%ebx\n\t"
2780 "lea 0x8(%esp),%esp");
2781}
2782
2783static void
2784i386_emit_less_unsigned (void)
2785{
2786 EMIT_ASM32 (i386_less_unsigned,
2787 "cmpl %ebx,4(%esp)\n\t"
2788 "jb .Li386_less_unsigned_true\n\t"
2789 "jne .Li386_less_unsigned_false\n\t"
2790 "cmpl %eax,(%esp)\n\t"
2791 "jb .Li386_less_unsigned_true\n\t"
2792 ".Li386_less_unsigned_false:\n\t"
2793 "xor %eax,%eax\n\t"
2794 "jmp .Li386_less_unsigned_end\n\t"
2795 ".Li386_less_unsigned_true:\n\t"
2796 "mov $1,%eax\n\t"
2797 ".Li386_less_unsigned_end:\n\t"
2798 "xor %ebx,%ebx\n\t"
2799 "lea 0x8(%esp),%esp");
2800}
2801
2802static void
2803i386_emit_ref (int size)
2804{
2805 switch (size)
2806 {
2807 case 1:
2808 EMIT_ASM32 (i386_ref1,
2809 "movb (%eax),%al");
2810 break;
2811 case 2:
2812 EMIT_ASM32 (i386_ref2,
2813 "movw (%eax),%ax");
2814 break;
2815 case 4:
2816 EMIT_ASM32 (i386_ref4,
2817 "movl (%eax),%eax");
2818 break;
2819 case 8:
2820 EMIT_ASM32 (i386_ref8,
2821 "movl 4(%eax),%ebx\n\t"
2822 "movl (%eax),%eax");
2823 break;
2824 }
2825}
2826
2827static void
2828i386_emit_if_goto (int *offset_p, int *size_p)
2829{
2830 EMIT_ASM32 (i386_if_goto,
2831 "mov %eax,%ecx\n\t"
2832 "or %ebx,%ecx\n\t"
2833 "pop %eax\n\t"
2834 "pop %ebx\n\t"
2835 "cmpl $0,%ecx\n\t"
2836 /* Don't trust the assembler to choose the right jump */
2837 ".byte 0x0f, 0x85, 0x0, 0x0, 0x0, 0x0");
2838
2839 if (offset_p)
2840 *offset_p = 11; /* be sure that this matches the sequence above */
2841 if (size_p)
2842 *size_p = 4;
2843}
2844
2845static void
2846i386_emit_goto (int *offset_p, int *size_p)
2847{
2848 EMIT_ASM32 (i386_goto,
2849 /* Don't trust the assembler to choose the right jump */
2850 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0");
2851 if (offset_p)
2852 *offset_p = 1;
2853 if (size_p)
2854 *size_p = 4;
2855}
2856
2857static void
2858i386_write_goto_address (CORE_ADDR from, CORE_ADDR to, int size)
2859{
2860 int diff = (to - (from + size));
2861 unsigned char buf[sizeof (int)];
2862
2863 /* We're only doing 4-byte sizes at the moment. */
2864 if (size != 4)
2865 {
2866 emit_error = 1;
2867 return;
2868 }
2869
2870 memcpy (buf, &diff, sizeof (int));
2871 write_inferior_memory (from, buf, sizeof (int));
2872}
2873
2874static void
4e29fb54 2875i386_emit_const (LONGEST num)
6a271cae
PA
2876{
2877 unsigned char buf[16];
b00ad6ff 2878 int i, hi, lo;
6a271cae
PA
2879 CORE_ADDR buildaddr = current_insn_ptr;
2880
2881 i = 0;
2882 buf[i++] = 0xb8; /* mov $<n>,%eax */
b00ad6ff
NF
2883 lo = num & 0xffffffff;
2884 memcpy (&buf[i], &lo, sizeof (lo));
6a271cae
PA
2885 i += 4;
2886 hi = ((num >> 32) & 0xffffffff);
2887 if (hi)
2888 {
2889 buf[i++] = 0xbb; /* mov $<n>,%ebx */
b00ad6ff 2890 memcpy (&buf[i], &hi, sizeof (hi));
6a271cae
PA
2891 i += 4;
2892 }
2893 else
2894 {
2895 buf[i++] = 0x31; buf[i++] = 0xdb; /* xor %ebx,%ebx */
2896 }
2897 append_insns (&buildaddr, i, buf);
2898 current_insn_ptr = buildaddr;
2899}
2900
2901static void
2902i386_emit_call (CORE_ADDR fn)
2903{
2904 unsigned char buf[16];
2905 int i, offset;
2906 CORE_ADDR buildaddr;
2907
2908 buildaddr = current_insn_ptr;
2909 i = 0;
2910 buf[i++] = 0xe8; /* call <reladdr> */
2911 offset = ((int) fn) - (buildaddr + 5);
2912 memcpy (buf + 1, &offset, 4);
2913 append_insns (&buildaddr, 5, buf);
2914 current_insn_ptr = buildaddr;
2915}
2916
2917static void
2918i386_emit_reg (int reg)
2919{
2920 unsigned char buf[16];
2921 int i;
2922 CORE_ADDR buildaddr;
2923
2924 EMIT_ASM32 (i386_reg_a,
2925 "sub $0x8,%esp");
2926 buildaddr = current_insn_ptr;
2927 i = 0;
2928 buf[i++] = 0xb8; /* mov $<n>,%eax */
b00ad6ff 2929 memcpy (&buf[i], &reg, sizeof (reg));
6a271cae
PA
2930 i += 4;
2931 append_insns (&buildaddr, i, buf);
2932 current_insn_ptr = buildaddr;
2933 EMIT_ASM32 (i386_reg_b,
2934 "mov %eax,4(%esp)\n\t"
2935 "mov 8(%ebp),%eax\n\t"
2936 "mov %eax,(%esp)");
2937 i386_emit_call (get_raw_reg_func_addr ());
2938 EMIT_ASM32 (i386_reg_c,
2939 "xor %ebx,%ebx\n\t"
2940 "lea 0x8(%esp),%esp");
2941}
2942
2943static void
2944i386_emit_pop (void)
2945{
2946 EMIT_ASM32 (i386_pop,
2947 "pop %eax\n\t"
2948 "pop %ebx");
2949}
2950
2951static void
2952i386_emit_stack_flush (void)
2953{
2954 EMIT_ASM32 (i386_stack_flush,
2955 "push %ebx\n\t"
2956 "push %eax");
2957}
2958
2959static void
2960i386_emit_zero_ext (int arg)
2961{
2962 switch (arg)
2963 {
2964 case 8:
2965 EMIT_ASM32 (i386_zero_ext_8,
2966 "and $0xff,%eax\n\t"
2967 "xor %ebx,%ebx");
2968 break;
2969 case 16:
2970 EMIT_ASM32 (i386_zero_ext_16,
2971 "and $0xffff,%eax\n\t"
2972 "xor %ebx,%ebx");
2973 break;
2974 case 32:
2975 EMIT_ASM32 (i386_zero_ext_32,
2976 "xor %ebx,%ebx");
2977 break;
2978 default:
2979 emit_error = 1;
2980 }
2981}
2982
2983static void
2984i386_emit_swap (void)
2985{
2986 EMIT_ASM32 (i386_swap,
2987 "mov %eax,%ecx\n\t"
2988 "mov %ebx,%edx\n\t"
2989 "pop %eax\n\t"
2990 "pop %ebx\n\t"
2991 "push %edx\n\t"
2992 "push %ecx");
2993}
2994
2995static void
2996i386_emit_stack_adjust (int n)
2997{
2998 unsigned char buf[16];
2999 int i;
3000 CORE_ADDR buildaddr = current_insn_ptr;
3001
3002 i = 0;
3003 buf[i++] = 0x8d; /* lea $<n>(%esp),%esp */
3004 buf[i++] = 0x64;
3005 buf[i++] = 0x24;
3006 buf[i++] = n * 8;
3007 append_insns (&buildaddr, i, buf);
3008 current_insn_ptr = buildaddr;
3009}
3010
3011/* FN's prototype is `LONGEST(*fn)(int)'. */
3012
3013static void
3014i386_emit_int_call_1 (CORE_ADDR fn, int arg1)
3015{
3016 unsigned char buf[16];
3017 int i;
3018 CORE_ADDR buildaddr;
3019
3020 EMIT_ASM32 (i386_int_call_1_a,
3021 /* Reserve a bit of stack space. */
3022 "sub $0x8,%esp");
3023 /* Put the one argument on the stack. */
3024 buildaddr = current_insn_ptr;
3025 i = 0;
3026 buf[i++] = 0xc7; /* movl $<arg1>,(%esp) */
3027 buf[i++] = 0x04;
3028 buf[i++] = 0x24;
b00ad6ff 3029 memcpy (&buf[i], &arg1, sizeof (arg1));
6a271cae
PA
3030 i += 4;
3031 append_insns (&buildaddr, i, buf);
3032 current_insn_ptr = buildaddr;
3033 i386_emit_call (fn);
3034 EMIT_ASM32 (i386_int_call_1_c,
3035 "mov %edx,%ebx\n\t"
3036 "lea 0x8(%esp),%esp");
3037}
3038
4e29fb54 3039/* FN's prototype is `void(*fn)(int,LONGEST)'. */
6a271cae
PA
3040
3041static void
3042i386_emit_void_call_2 (CORE_ADDR fn, int arg1)
3043{
3044 unsigned char buf[16];
3045 int i;
3046 CORE_ADDR buildaddr;
3047
3048 EMIT_ASM32 (i386_void_call_2_a,
3049 /* Preserve %eax only; we don't have to worry about %ebx. */
3050 "push %eax\n\t"
3051 /* Reserve a bit of stack space for arguments. */
3052 "sub $0x10,%esp\n\t"
3053 /* Copy "top" to the second argument position. (Note that
3054 we can't assume function won't scribble on its
3055 arguments, so don't try to restore from this.) */
3056 "mov %eax,4(%esp)\n\t"
3057 "mov %ebx,8(%esp)");
3058 /* Put the first argument on the stack. */
3059 buildaddr = current_insn_ptr;
3060 i = 0;
3061 buf[i++] = 0xc7; /* movl $<arg1>,(%esp) */
3062 buf[i++] = 0x04;
3063 buf[i++] = 0x24;
b00ad6ff 3064 memcpy (&buf[i], &arg1, sizeof (arg1));
6a271cae
PA
3065 i += 4;
3066 append_insns (&buildaddr, i, buf);
3067 current_insn_ptr = buildaddr;
3068 i386_emit_call (fn);
3069 EMIT_ASM32 (i386_void_call_2_b,
3070 "lea 0x10(%esp),%esp\n\t"
3071 /* Restore original stack top. */
3072 "pop %eax");
3073}
3074
6b9801d4
SS
3075
3076void
3077i386_emit_eq_goto (int *offset_p, int *size_p)
3078{
3079 EMIT_ASM32 (eq,
3080 /* Check low half first, more likely to be decider */
3081 "cmpl %eax,(%esp)\n\t"
3082 "jne .Leq_fallthru\n\t"
3083 "cmpl %ebx,4(%esp)\n\t"
3084 "jne .Leq_fallthru\n\t"
3085 "lea 0x8(%esp),%esp\n\t"
3086 "pop %eax\n\t"
3087 "pop %ebx\n\t"
3088 /* jmp, but don't trust the assembler to choose the right jump */
3089 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0\n\t"
3090 ".Leq_fallthru:\n\t"
3091 "lea 0x8(%esp),%esp\n\t"
3092 "pop %eax\n\t"
3093 "pop %ebx");
3094
3095 if (offset_p)
3096 *offset_p = 18;
3097 if (size_p)
3098 *size_p = 4;
3099}
3100
3101void
3102i386_emit_ne_goto (int *offset_p, int *size_p)
3103{
3104 EMIT_ASM32 (ne,
3105 /* Check low half first, more likely to be decider */
3106 "cmpl %eax,(%esp)\n\t"
3107 "jne .Lne_jump\n\t"
3108 "cmpl %ebx,4(%esp)\n\t"
3109 "je .Lne_fallthru\n\t"
3110 ".Lne_jump:\n\t"
3111 "lea 0x8(%esp),%esp\n\t"
3112 "pop %eax\n\t"
3113 "pop %ebx\n\t"
3114 /* jmp, but don't trust the assembler to choose the right jump */
3115 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0\n\t"
3116 ".Lne_fallthru:\n\t"
3117 "lea 0x8(%esp),%esp\n\t"
3118 "pop %eax\n\t"
3119 "pop %ebx");
3120
3121 if (offset_p)
3122 *offset_p = 18;
3123 if (size_p)
3124 *size_p = 4;
3125}
3126
3127void
3128i386_emit_lt_goto (int *offset_p, int *size_p)
3129{
3130 EMIT_ASM32 (lt,
3131 "cmpl %ebx,4(%esp)\n\t"
3132 "jl .Llt_jump\n\t"
3133 "jne .Llt_fallthru\n\t"
3134 "cmpl %eax,(%esp)\n\t"
3135 "jnl .Llt_fallthru\n\t"
3136 ".Llt_jump:\n\t"
3137 "lea 0x8(%esp),%esp\n\t"
3138 "pop %eax\n\t"
3139 "pop %ebx\n\t"
3140 /* jmp, but don't trust the assembler to choose the right jump */
3141 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0\n\t"
3142 ".Llt_fallthru:\n\t"
3143 "lea 0x8(%esp),%esp\n\t"
3144 "pop %eax\n\t"
3145 "pop %ebx");
3146
3147 if (offset_p)
3148 *offset_p = 20;
3149 if (size_p)
3150 *size_p = 4;
3151}
3152
3153void
3154i386_emit_le_goto (int *offset_p, int *size_p)
3155{
3156 EMIT_ASM32 (le,
3157 "cmpl %ebx,4(%esp)\n\t"
3158 "jle .Lle_jump\n\t"
3159 "jne .Lle_fallthru\n\t"
3160 "cmpl %eax,(%esp)\n\t"
3161 "jnle .Lle_fallthru\n\t"
3162 ".Lle_jump:\n\t"
3163 "lea 0x8(%esp),%esp\n\t"
3164 "pop %eax\n\t"
3165 "pop %ebx\n\t"
3166 /* jmp, but don't trust the assembler to choose the right jump */
3167 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0\n\t"
3168 ".Lle_fallthru:\n\t"
3169 "lea 0x8(%esp),%esp\n\t"
3170 "pop %eax\n\t"
3171 "pop %ebx");
3172
3173 if (offset_p)
3174 *offset_p = 20;
3175 if (size_p)
3176 *size_p = 4;
3177}
3178
3179void
3180i386_emit_gt_goto (int *offset_p, int *size_p)
3181{
3182 EMIT_ASM32 (gt,
3183 "cmpl %ebx,4(%esp)\n\t"
3184 "jg .Lgt_jump\n\t"
3185 "jne .Lgt_fallthru\n\t"
3186 "cmpl %eax,(%esp)\n\t"
3187 "jng .Lgt_fallthru\n\t"
3188 ".Lgt_jump:\n\t"
3189 "lea 0x8(%esp),%esp\n\t"
3190 "pop %eax\n\t"
3191 "pop %ebx\n\t"
3192 /* jmp, but don't trust the assembler to choose the right jump */
3193 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0\n\t"
3194 ".Lgt_fallthru:\n\t"
3195 "lea 0x8(%esp),%esp\n\t"
3196 "pop %eax\n\t"
3197 "pop %ebx");
3198
3199 if (offset_p)
3200 *offset_p = 20;
3201 if (size_p)
3202 *size_p = 4;
3203}
3204
3205void
3206i386_emit_ge_goto (int *offset_p, int *size_p)
3207{
3208 EMIT_ASM32 (ge,
3209 "cmpl %ebx,4(%esp)\n\t"
3210 "jge .Lge_jump\n\t"
3211 "jne .Lge_fallthru\n\t"
3212 "cmpl %eax,(%esp)\n\t"
3213 "jnge .Lge_fallthru\n\t"
3214 ".Lge_jump:\n\t"
3215 "lea 0x8(%esp),%esp\n\t"
3216 "pop %eax\n\t"
3217 "pop %ebx\n\t"
3218 /* jmp, but don't trust the assembler to choose the right jump */
3219 ".byte 0xe9, 0x0, 0x0, 0x0, 0x0\n\t"
3220 ".Lge_fallthru:\n\t"
3221 "lea 0x8(%esp),%esp\n\t"
3222 "pop %eax\n\t"
3223 "pop %ebx");
3224
3225 if (offset_p)
3226 *offset_p = 20;
3227 if (size_p)
3228 *size_p = 4;
3229}
3230
6a271cae
PA
3231struct emit_ops i386_emit_ops =
3232 {
3233 i386_emit_prologue,
3234 i386_emit_epilogue,
3235 i386_emit_add,
3236 i386_emit_sub,
3237 i386_emit_mul,
3238 i386_emit_lsh,
3239 i386_emit_rsh_signed,
3240 i386_emit_rsh_unsigned,
3241 i386_emit_ext,
3242 i386_emit_log_not,
3243 i386_emit_bit_and,
3244 i386_emit_bit_or,
3245 i386_emit_bit_xor,
3246 i386_emit_bit_not,
3247 i386_emit_equal,
3248 i386_emit_less_signed,
3249 i386_emit_less_unsigned,
3250 i386_emit_ref,
3251 i386_emit_if_goto,
3252 i386_emit_goto,
3253 i386_write_goto_address,
3254 i386_emit_const,
3255 i386_emit_call,
3256 i386_emit_reg,
3257 i386_emit_pop,
3258 i386_emit_stack_flush,
3259 i386_emit_zero_ext,
3260 i386_emit_swap,
3261 i386_emit_stack_adjust,
3262 i386_emit_int_call_1,
6b9801d4
SS
3263 i386_emit_void_call_2,
3264 i386_emit_eq_goto,
3265 i386_emit_ne_goto,
3266 i386_emit_lt_goto,
3267 i386_emit_le_goto,
3268 i386_emit_gt_goto,
3269 i386_emit_ge_goto
6a271cae
PA
3270 };
3271
3272
3273static struct emit_ops *
3274x86_emit_ops (void)
3275{
3276#ifdef __x86_64__
3aee8918 3277 if (is_64bit_tdesc ())
6a271cae
PA
3278 return &amd64_emit_ops;
3279 else
3280#endif
3281 return &i386_emit_ops;
3282}
3283
c2d6af84
PA
3284static int
3285x86_supports_range_stepping (void)
3286{
3287 return 1;
3288}
3289
d0722149
DE
3290/* This is initialized assuming an amd64 target.
3291 x86_arch_setup will correct it for i386 or amd64 targets. */
3292
3293struct linux_target_ops the_low_target =
3294{
3295 x86_arch_setup,
3aee8918
PA
3296 x86_linux_regs_info,
3297 x86_cannot_fetch_register,
3298 x86_cannot_store_register,
c14dfd32 3299 NULL, /* fetch_register */
d0722149
DE
3300 x86_get_pc,
3301 x86_set_pc,
3302 x86_breakpoint,
3303 x86_breakpoint_len,
3304 NULL,
3305 1,
3306 x86_breakpoint_at,
aa5ca48f
DE
3307 x86_insert_point,
3308 x86_remove_point,
3309 x86_stopped_by_watchpoint,
3310 x86_stopped_data_address,
d0722149
DE
3311 /* collect_ptrace_register/supply_ptrace_register are not needed in the
3312 native i386 case (no registers smaller than an xfer unit), and are not
3313 used in the biarch case (HAVE_LINUX_USRREGS is not defined). */
3314 NULL,
3315 NULL,
3316 /* need to fix up i386 siginfo if host is amd64 */
3317 x86_siginfo_fixup,
aa5ca48f
DE
3318 x86_linux_new_process,
3319 x86_linux_new_thread,
1570b33e 3320 x86_linux_prepare_to_resume,
219f2f23 3321 x86_linux_process_qsupported,
fa593d66
PA
3322 x86_supports_tracepoints,
3323 x86_get_thread_area,
6a271cae 3324 x86_install_fast_tracepoint_jump_pad,
405f8e94
SS
3325 x86_emit_ops,
3326 x86_get_min_fast_tracepoint_insn_len,
c2d6af84 3327 x86_supports_range_stepping,
d0722149 3328};
3aee8918
PA
3329
3330void
3331initialize_low_arch (void)
3332{
3333 /* Initialize the Linux target descriptions. */
3334#ifdef __x86_64__
3335 init_registers_amd64_linux ();
3336 init_registers_amd64_avx_linux ();
3337 init_registers_x32_linux ();
7e5aaa09 3338 init_registers_x32_avx_linux ();
3aee8918
PA
3339
3340 tdesc_amd64_linux_no_xml = xmalloc (sizeof (struct target_desc));
3341 copy_target_description (tdesc_amd64_linux_no_xml, tdesc_amd64_linux);
3342 tdesc_amd64_linux_no_xml->xmltarget = xmltarget_amd64_linux_no_xml;
3343#endif
3344 init_registers_i386_linux ();
3345 init_registers_i386_mmx_linux ();
3346 init_registers_i386_avx_linux ();
3347
3348 tdesc_i386_linux_no_xml = xmalloc (sizeof (struct target_desc));
3349 copy_target_description (tdesc_i386_linux_no_xml, tdesc_i386_linux);
3350 tdesc_i386_linux_no_xml->xmltarget = xmltarget_i386_linux_no_xml;
3351
3352 initialize_regsets_info (&x86_regsets_info);
3353}
This page took 0.507807 seconds and 4 git commands to generate.