1 /* Intel 386 target-dependent stuff.
3 Copyright (C) 1988-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #include "extract-store-integer.h"
21 #include "opcode/i386.h"
22 #include "arch-utils.h"
24 #include "dummy-frame.h"
25 #include "dwarf2/frame.h"
27 #include "frame-base.h"
28 #include "frame-unwind.h"
31 #include "cli/cli-cmds.h"
37 #include "reggroups.h"
42 #include "target-float.h"
47 #include "i386-tdep.h"
48 #include "i387-tdep.h"
49 #include "gdbsupport/x86-xstate.h"
54 #include "record-full.h"
55 #include "target-descriptions.h"
56 #include "arch/i386.h"
61 #include "stap-probe.h"
62 #include "user-regs.h"
63 #include "cli/cli-utils.h"
64 #include "expression.h"
65 #include "parser-defs.h"
68 #include <unordered_set>
75 static const char * const i386_register_names
[] =
77 "eax", "ecx", "edx", "ebx",
78 "esp", "ebp", "esi", "edi",
79 "eip", "eflags", "cs", "ss",
80 "ds", "es", "fs", "gs",
81 "st0", "st1", "st2", "st3",
82 "st4", "st5", "st6", "st7",
83 "fctrl", "fstat", "ftag", "fiseg",
84 "fioff", "foseg", "fooff", "fop",
85 "xmm0", "xmm1", "xmm2", "xmm3",
86 "xmm4", "xmm5", "xmm6", "xmm7",
90 static const char * const i386_zmm_names
[] =
92 "zmm0", "zmm1", "zmm2", "zmm3",
93 "zmm4", "zmm5", "zmm6", "zmm7"
96 static const char * const i386_zmmh_names
[] =
98 "zmm0h", "zmm1h", "zmm2h", "zmm3h",
99 "zmm4h", "zmm5h", "zmm6h", "zmm7h"
102 static const char * const i386_k_names
[] =
104 "k0", "k1", "k2", "k3",
105 "k4", "k5", "k6", "k7"
108 static const char * const i386_ymm_names
[] =
110 "ymm0", "ymm1", "ymm2", "ymm3",
111 "ymm4", "ymm5", "ymm6", "ymm7",
114 static const char * const i386_ymmh_names
[] =
116 "ymm0h", "ymm1h", "ymm2h", "ymm3h",
117 "ymm4h", "ymm5h", "ymm6h", "ymm7h",
121 static const char * const i386_pkeys_names
[] =
126 /* Register names for MMX pseudo-registers. */
128 static const char * const i386_mmx_names
[] =
130 "mm0", "mm1", "mm2", "mm3",
131 "mm4", "mm5", "mm6", "mm7"
134 /* Register names for byte pseudo-registers. */
136 static const char * const i386_byte_names
[] =
138 "al", "cl", "dl", "bl",
139 "ah", "ch", "dh", "bh"
142 /* Register names for word pseudo-registers. */
144 static const char * const i386_word_names
[] =
146 "ax", "cx", "dx", "bx",
150 /* Constant used for reading/writing pseudo registers. In 64-bit mode, we have
151 16 lower ZMM regs that extend corresponding xmm/ymm registers. In addition,
152 we have 16 upper ZMM regs that have to be handled differently. */
154 const int num_lower_zmm_regs
= 16;
159 i386_mmx_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
161 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
162 int mm0_regnum
= tdep
->mm0_regnum
;
167 regnum
-= mm0_regnum
;
168 return regnum
>= 0 && regnum
< tdep
->num_mmx_regs
;
174 i386_byte_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
176 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
178 regnum
-= tdep
->al_regnum
;
179 return regnum
>= 0 && regnum
< tdep
->num_byte_regs
;
185 i386_word_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
187 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
189 regnum
-= tdep
->ax_regnum
;
190 return regnum
>= 0 && regnum
< tdep
->num_word_regs
;
193 /* Dword register? */
196 i386_dword_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
198 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
199 int eax_regnum
= tdep
->eax_regnum
;
204 regnum
-= eax_regnum
;
205 return regnum
>= 0 && regnum
< tdep
->num_dword_regs
;
208 /* AVX512 register? */
211 i386_zmmh_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
213 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
214 int zmm0h_regnum
= tdep
->zmm0h_regnum
;
216 if (zmm0h_regnum
< 0)
219 regnum
-= zmm0h_regnum
;
220 return regnum
>= 0 && regnum
< tdep
->num_zmm_regs
;
224 i386_zmm_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
226 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
227 int zmm0_regnum
= tdep
->zmm0_regnum
;
232 regnum
-= zmm0_regnum
;
233 return regnum
>= 0 && regnum
< tdep
->num_zmm_regs
;
237 i386_k_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
239 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
240 int k0_regnum
= tdep
->k0_regnum
;
246 return regnum
>= 0 && regnum
< I387_NUM_K_REGS
;
250 i386_ymmh_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
252 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
253 int ymm0h_regnum
= tdep
->ymm0h_regnum
;
255 if (ymm0h_regnum
< 0)
258 regnum
-= ymm0h_regnum
;
259 return regnum
>= 0 && regnum
< tdep
->num_ymm_regs
;
265 i386_ymm_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
267 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
268 int ymm0_regnum
= tdep
->ymm0_regnum
;
273 regnum
-= ymm0_regnum
;
274 return regnum
>= 0 && regnum
< tdep
->num_ymm_regs
;
278 i386_ymmh_avx512_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
280 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
281 int ymm16h_regnum
= tdep
->ymm16h_regnum
;
283 if (ymm16h_regnum
< 0)
286 regnum
-= ymm16h_regnum
;
287 return regnum
>= 0 && regnum
< tdep
->num_ymm_avx512_regs
;
291 i386_ymm_avx512_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
293 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
294 int ymm16_regnum
= tdep
->ymm16_regnum
;
296 if (ymm16_regnum
< 0)
299 regnum
-= ymm16_regnum
;
300 return regnum
>= 0 && regnum
< tdep
->num_ymm_avx512_regs
;
306 i386_xmm_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
308 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
309 int num_xmm_regs
= I387_NUM_XMM_REGS (tdep
);
311 if (num_xmm_regs
== 0)
314 regnum
-= I387_XMM0_REGNUM (tdep
);
315 return regnum
>= 0 && regnum
< num_xmm_regs
;
318 /* XMM_512 register? */
321 i386_xmm_avx512_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
323 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
324 int num_xmm_avx512_regs
= I387_NUM_XMM_AVX512_REGS (tdep
);
326 if (num_xmm_avx512_regs
== 0)
329 regnum
-= I387_XMM16_REGNUM (tdep
);
330 return regnum
>= 0 && regnum
< num_xmm_avx512_regs
;
334 i386_mxcsr_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
336 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
338 if (I387_NUM_XMM_REGS (tdep
) == 0)
341 return (regnum
== I387_MXCSR_REGNUM (tdep
));
347 i386_fp_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
349 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
351 if (I387_ST0_REGNUM (tdep
) < 0)
354 return (I387_ST0_REGNUM (tdep
) <= regnum
355 && regnum
< I387_FCTRL_REGNUM (tdep
));
359 i386_fpc_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
361 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
363 if (I387_ST0_REGNUM (tdep
) < 0)
366 return (I387_FCTRL_REGNUM (tdep
) <= regnum
367 && regnum
< I387_XMM0_REGNUM (tdep
));
373 i386_pkru_regnum_p (struct gdbarch
*gdbarch
, int regnum
)
375 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
376 int pkru_regnum
= tdep
->pkru_regnum
;
381 regnum
-= pkru_regnum
;
382 return regnum
>= 0 && regnum
< I387_NUM_PKEYS_REGS
;
385 /* Return the name of register REGNUM, or the empty string if it is
386 an anonymous register. */
389 i386_register_name (struct gdbarch
*gdbarch
, int regnum
)
391 /* Hide the upper YMM registers. */
392 if (i386_ymmh_regnum_p (gdbarch
, regnum
))
395 /* Hide the upper YMM16-31 registers. */
396 if (i386_ymmh_avx512_regnum_p (gdbarch
, regnum
))
399 /* Hide the upper ZMM registers. */
400 if (i386_zmmh_regnum_p (gdbarch
, regnum
))
403 return tdesc_register_name (gdbarch
, regnum
);
406 /* Return the name of register REGNUM. */
409 i386_pseudo_register_name (struct gdbarch
*gdbarch
, int regnum
)
411 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
412 if (i386_mmx_regnum_p (gdbarch
, regnum
))
413 return i386_mmx_names
[regnum
- I387_MM0_REGNUM (tdep
)];
414 else if (i386_ymm_regnum_p (gdbarch
, regnum
))
415 return i386_ymm_names
[regnum
- tdep
->ymm0_regnum
];
416 else if (i386_zmm_regnum_p (gdbarch
, regnum
))
417 return i386_zmm_names
[regnum
- tdep
->zmm0_regnum
];
418 else if (i386_byte_regnum_p (gdbarch
, regnum
))
419 return i386_byte_names
[regnum
- tdep
->al_regnum
];
420 else if (i386_word_regnum_p (gdbarch
, regnum
))
421 return i386_word_names
[regnum
- tdep
->ax_regnum
];
423 internal_error (_("invalid regnum"));
426 /* Convert a dbx register number REG to the appropriate register
427 number used by GDB. */
430 i386_dbx_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
432 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
434 /* This implements what GCC calls the "default" register map
435 (dbx_register_map[]). */
437 if (reg
>= 0 && reg
<= 7)
439 /* General-purpose registers. The debug info calls %ebp
440 register 4, and %esp register 5. */
447 else if (reg
>= 12 && reg
<= 19)
449 /* Floating-point registers. */
450 return reg
- 12 + I387_ST0_REGNUM (tdep
);
452 else if (reg
>= 21 && reg
<= 28)
455 int ymm0_regnum
= tdep
->ymm0_regnum
;
458 && i386_xmm_regnum_p (gdbarch
, reg
))
459 return reg
- 21 + ymm0_regnum
;
461 return reg
- 21 + I387_XMM0_REGNUM (tdep
);
463 else if (reg
>= 29 && reg
<= 36)
466 return reg
- 29 + I387_MM0_REGNUM (tdep
);
469 /* This will hopefully provoke a warning. */
470 return gdbarch_num_cooked_regs (gdbarch
);
473 /* Convert SVR4 DWARF register number REG to the appropriate register number
477 i386_svr4_dwarf_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
479 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
481 /* This implements the GCC register map that tries to be compatible
482 with the SVR4 C compiler for DWARF (svr4_dbx_register_map[]). */
484 /* The SVR4 register numbering includes %eip and %eflags, and
485 numbers the floating point registers differently. */
486 if (reg
>= 0 && reg
<= 9)
488 /* General-purpose registers. */
491 else if (reg
>= 11 && reg
<= 18)
493 /* Floating-point registers. */
494 return reg
- 11 + I387_ST0_REGNUM (tdep
);
496 else if (reg
>= 21 && reg
<= 36)
498 /* The SSE and MMX registers have the same numbers as with dbx. */
499 return i386_dbx_reg_to_regnum (gdbarch
, reg
);
504 case 37: return I387_FCTRL_REGNUM (tdep
);
505 case 38: return I387_FSTAT_REGNUM (tdep
);
506 case 39: return I387_MXCSR_REGNUM (tdep
);
507 case 40: return I386_ES_REGNUM
;
508 case 41: return I386_CS_REGNUM
;
509 case 42: return I386_SS_REGNUM
;
510 case 43: return I386_DS_REGNUM
;
511 case 44: return I386_FS_REGNUM
;
512 case 45: return I386_GS_REGNUM
;
518 /* Wrapper on i386_svr4_dwarf_reg_to_regnum to return
519 num_regs + num_pseudo_regs for other debug formats. */
522 i386_svr4_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
524 int regnum
= i386_svr4_dwarf_reg_to_regnum (gdbarch
, reg
);
527 return gdbarch_num_cooked_regs (gdbarch
);
533 /* This is the variable that is set with "set disassembly-flavor", and
534 its legitimate values. */
535 static const char att_flavor
[] = "att";
536 static const char intel_flavor
[] = "intel";
537 static const char *const valid_flavors
[] =
543 static const char *disassembly_flavor
= att_flavor
;
546 /* Use the program counter to determine the contents and size of a
547 breakpoint instruction. Return a pointer to a string of bytes that
548 encode a breakpoint instruction, store the length of the string in
549 *LEN and optionally adjust *PC to point to the correct memory
550 location for inserting the breakpoint.
552 On the i386 we have a single breakpoint that fits in a single byte
553 and can be inserted anywhere.
555 This function is 64-bit safe. */
557 constexpr gdb_byte i386_break_insn
[] = { 0xcc }; /* int 3 */
559 typedef BP_MANIPULATION (i386_break_insn
) i386_breakpoint
;
562 /* Displaced instruction handling. */
564 /* Skip the legacy instruction prefixes in INSN.
565 Not all prefixes are valid for any particular insn
566 but we needn't care, the insn will fault if it's invalid.
567 The result is a pointer to the first opcode byte,
568 or NULL if we run off the end of the buffer. */
571 i386_skip_prefixes (gdb_byte
*insn
, size_t max_len
)
573 gdb_byte
*end
= insn
+ max_len
;
579 case DATA_PREFIX_OPCODE
:
580 case ADDR_PREFIX_OPCODE
:
581 case CS_PREFIX_OPCODE
:
582 case DS_PREFIX_OPCODE
:
583 case ES_PREFIX_OPCODE
:
584 case FS_PREFIX_OPCODE
:
585 case GS_PREFIX_OPCODE
:
586 case SS_PREFIX_OPCODE
:
587 case LOCK_PREFIX_OPCODE
:
588 case REPE_PREFIX_OPCODE
:
589 case REPNE_PREFIX_OPCODE
:
601 i386_absolute_jmp_p (const gdb_byte
*insn
)
603 /* jmp far (absolute address in operand). */
609 /* jump near, absolute indirect (/4). */
610 if ((insn
[1] & 0x38) == 0x20)
613 /* jump far, absolute indirect (/5). */
614 if ((insn
[1] & 0x38) == 0x28)
621 /* Return non-zero if INSN is a jump, zero otherwise. */
624 i386_jmp_p (const gdb_byte
*insn
)
626 /* jump short, relative. */
630 /* jump near, relative. */
634 return i386_absolute_jmp_p (insn
);
638 i386_absolute_call_p (const gdb_byte
*insn
)
640 /* call far, absolute. */
646 /* Call near, absolute indirect (/2). */
647 if ((insn
[1] & 0x38) == 0x10)
650 /* Call far, absolute indirect (/3). */
651 if ((insn
[1] & 0x38) == 0x18)
659 i386_ret_p (const gdb_byte
*insn
)
663 case 0xc2: /* ret near, pop N bytes. */
664 case 0xc3: /* ret near */
665 case 0xca: /* ret far, pop N bytes. */
666 case 0xcb: /* ret far */
667 case 0xcf: /* iret */
676 i386_call_p (const gdb_byte
*insn
)
678 if (i386_absolute_call_p (insn
))
681 /* call near, relative. */
688 /* Return non-zero if INSN is a system call, and set *LENGTHP to its
689 length in bytes. Otherwise, return zero. */
692 i386_syscall_p (const gdb_byte
*insn
, int *lengthp
)
694 /* Is it 'int $0x80'? */
695 if ((insn
[0] == 0xcd && insn
[1] == 0x80)
696 /* Or is it 'sysenter'? */
697 || (insn
[0] == 0x0f && insn
[1] == 0x34)
698 /* Or is it 'syscall'? */
699 || (insn
[0] == 0x0f && insn
[1] == 0x05))
708 /* The gdbarch insn_is_call method. */
711 i386_insn_is_call (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
713 gdb_byte buf
[I386_MAX_INSN_LEN
], *insn
;
715 read_code (addr
, buf
, I386_MAX_INSN_LEN
);
716 insn
= i386_skip_prefixes (buf
, I386_MAX_INSN_LEN
);
718 return i386_call_p (insn
);
721 /* The gdbarch insn_is_ret method. */
724 i386_insn_is_ret (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
726 gdb_byte buf
[I386_MAX_INSN_LEN
], *insn
;
728 read_code (addr
, buf
, I386_MAX_INSN_LEN
);
729 insn
= i386_skip_prefixes (buf
, I386_MAX_INSN_LEN
);
731 return i386_ret_p (insn
);
734 /* The gdbarch insn_is_jump method. */
737 i386_insn_is_jump (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
739 gdb_byte buf
[I386_MAX_INSN_LEN
], *insn
;
741 read_code (addr
, buf
, I386_MAX_INSN_LEN
);
742 insn
= i386_skip_prefixes (buf
, I386_MAX_INSN_LEN
);
744 return i386_jmp_p (insn
);
747 /* Some kernels may run one past a syscall insn, so we have to cope. */
749 displaced_step_copy_insn_closure_up
750 i386_displaced_step_copy_insn (struct gdbarch
*gdbarch
,
751 CORE_ADDR from
, CORE_ADDR to
,
752 struct regcache
*regs
)
754 size_t len
= gdbarch_max_insn_length (gdbarch
);
755 std::unique_ptr
<i386_displaced_step_copy_insn_closure
> closure
756 (new i386_displaced_step_copy_insn_closure (len
));
757 gdb_byte
*buf
= closure
->buf
.data ();
759 read_memory (from
, buf
, len
);
761 /* GDB may get control back after the insn after the syscall.
762 Presumably this is a kernel bug.
763 If this is a syscall, make sure there's a nop afterwards. */
768 insn
= i386_skip_prefixes (buf
, len
);
769 if (insn
!= NULL
&& i386_syscall_p (insn
, &syscall_length
))
770 insn
[syscall_length
] = NOP_OPCODE
;
773 write_memory (to
, buf
, len
);
775 displaced_debug_printf ("%s->%s: %s",
776 paddress (gdbarch
, from
), paddress (gdbarch
, to
),
777 bytes_to_string (buf
, len
).c_str ());
779 /* This is a work around for a problem with g++ 4.8. */
780 return displaced_step_copy_insn_closure_up (closure
.release ());
783 /* Fix up the state of registers and memory after having single-stepped
784 a displaced instruction. */
787 i386_displaced_step_fixup (struct gdbarch
*gdbarch
,
788 struct displaced_step_copy_insn_closure
*closure_
,
789 CORE_ADDR from
, CORE_ADDR to
,
790 struct regcache
*regs
, bool completed_p
)
792 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
794 /* The offset we applied to the instruction's address.
795 This could well be negative (when viewed as a signed 32-bit
796 value), but ULONGEST won't reflect that, so take care when
798 ULONGEST insn_offset
= to
- from
;
800 i386_displaced_step_copy_insn_closure
*closure
801 = (i386_displaced_step_copy_insn_closure
*) closure_
;
802 gdb_byte
*insn
= closure
->buf
.data ();
803 /* The start of the insn, needed in case we see some prefixes. */
804 gdb_byte
*insn_start
= insn
;
806 displaced_debug_printf ("fixup (%s, %s), insn = 0x%02x 0x%02x ...",
807 paddress (gdbarch
, from
), paddress (gdbarch
, to
),
810 /* The list of issues to contend with here is taken from
811 resume_execution in arch/i386/kernel/kprobes.c, Linux 2.6.20.
812 Yay for Free Software! */
814 /* Relocate the %eip, if necessary. */
816 /* The instruction recognizers we use assume any leading prefixes
817 have been skipped. */
819 /* This is the size of the buffer in closure. */
820 size_t max_insn_len
= gdbarch_max_insn_length (gdbarch
);
821 gdb_byte
*opcode
= i386_skip_prefixes (insn
, max_insn_len
);
822 /* If there are too many prefixes, just ignore the insn.
823 It will fault when run. */
828 /* Except in the case of absolute or indirect jump or call
829 instructions, or a return instruction, the new eip is relative to
830 the displaced instruction; make it relative. Well, signal
831 handler returns don't need relocation either, but we use the
832 value of %eip to recognize those; see below. */
834 || (!i386_absolute_jmp_p (insn
)
835 && !i386_absolute_call_p (insn
)
836 && !i386_ret_p (insn
)))
840 CORE_ADDR pc
= regcache_read_pc (regs
);
842 /* A signal trampoline system call changes the %eip, resuming
843 execution of the main program after the signal handler has
844 returned. That makes them like 'return' instructions; we
845 shouldn't relocate %eip.
847 But most system calls don't, and we do need to relocate %eip.
849 Our heuristic for distinguishing these cases: if stepping
850 over the system call instruction left control directly after
851 the instruction, the we relocate --- control almost certainly
852 doesn't belong in the displaced copy. Otherwise, we assume
853 the instruction has put control where it belongs, and leave
854 it unrelocated. Goodness help us if there are PC-relative
856 if (i386_syscall_p (insn
, &insn_len
)
857 && pc
!= to
+ (insn
- insn_start
) + insn_len
858 /* GDB can get control back after the insn after the syscall.
859 Presumably this is a kernel bug.
860 i386_displaced_step_copy_insn ensures it's a nop,
861 we add one to the length for it. */
862 && pc
!= to
+ (insn
- insn_start
) + insn_len
+ 1)
863 displaced_debug_printf ("syscall changed %%eip; not relocating");
866 ULONGEST eip
= (pc
- insn_offset
) & 0xffffffffUL
;
868 /* If we just stepped over a breakpoint insn, we don't backup
869 the pc on purpose; this is to match behavior without
872 regcache_write_pc (regs
, eip
);
874 displaced_debug_printf ("relocated %%eip from %s to %s",
875 paddress (gdbarch
, pc
),
876 paddress (gdbarch
, eip
));
880 /* If the instruction was PUSHFL, then the TF bit will be set in the
881 pushed value, and should be cleared. We'll leave this for later,
882 since GDB already messes up the TF flag when stepping over a
885 /* If the instruction was a call, the return address now atop the
886 stack is the address following the copied instruction. We need
887 to make it the address following the original instruction. */
888 if (completed_p
&& i386_call_p (insn
))
892 const ULONGEST retaddr_len
= 4;
894 regcache_cooked_read_unsigned (regs
, I386_ESP_REGNUM
, &esp
);
895 retaddr
= read_memory_unsigned_integer (esp
, retaddr_len
, byte_order
);
896 retaddr
= (retaddr
- insn_offset
) & 0xffffffffUL
;
897 write_memory_unsigned_integer (esp
, retaddr_len
, byte_order
, retaddr
);
899 displaced_debug_printf ("relocated return addr at %s to %s",
900 paddress (gdbarch
, esp
),
901 paddress (gdbarch
, retaddr
));
906 append_insns (CORE_ADDR
*to
, ULONGEST len
, const gdb_byte
*buf
)
908 target_write_memory (*to
, buf
, len
);
913 i386_relocate_instruction (struct gdbarch
*gdbarch
,
914 CORE_ADDR
*to
, CORE_ADDR oldloc
)
916 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
917 gdb_byte buf
[I386_MAX_INSN_LEN
];
918 int offset
= 0, rel32
, newrel
;
920 gdb_byte
*insn
= buf
;
922 read_memory (oldloc
, buf
, I386_MAX_INSN_LEN
);
924 insn_length
= gdb_buffered_insn_length (gdbarch
, insn
,
925 I386_MAX_INSN_LEN
, oldloc
);
927 /* Get past the prefixes. */
928 insn
= i386_skip_prefixes (insn
, I386_MAX_INSN_LEN
);
930 /* Adjust calls with 32-bit relative addresses as push/jump, with
931 the address pushed being the location where the original call in
932 the user program would return to. */
935 gdb_byte push_buf
[16];
936 unsigned int ret_addr
;
938 /* Where "ret" in the original code will return to. */
939 ret_addr
= oldloc
+ insn_length
;
940 push_buf
[0] = 0x68; /* pushq $... */
941 store_unsigned_integer (&push_buf
[1], 4, byte_order
, ret_addr
);
943 append_insns (to
, 5, push_buf
);
945 /* Convert the relative call to a relative jump. */
948 /* Adjust the destination offset. */
949 rel32
= extract_signed_integer (insn
+ 1, 4, byte_order
);
950 newrel
= (oldloc
- *to
) + rel32
;
951 store_signed_integer (insn
+ 1, 4, byte_order
, newrel
);
953 displaced_debug_printf ("adjusted insn rel32=%s at %s to rel32=%s at %s",
954 hex_string (rel32
), paddress (gdbarch
, oldloc
),
955 hex_string (newrel
), paddress (gdbarch
, *to
));
957 /* Write the adjusted jump into its displaced location. */
958 append_insns (to
, 5, insn
);
962 /* Adjust jumps with 32-bit relative addresses. Calls are already
966 /* Adjust conditional jumps. */
967 else if (insn
[0] == 0x0f && (insn
[1] & 0xf0) == 0x80)
972 rel32
= extract_signed_integer (insn
+ offset
, 4, byte_order
);
973 newrel
= (oldloc
- *to
) + rel32
;
974 store_signed_integer (insn
+ offset
, 4, byte_order
, newrel
);
975 displaced_debug_printf ("adjusted insn rel32=%s at %s to rel32=%s at %s",
976 hex_string (rel32
), paddress (gdbarch
, oldloc
),
977 hex_string (newrel
), paddress (gdbarch
, *to
));
980 /* Write the adjusted instructions into their displaced
982 append_insns (to
, insn_length
, buf
);
986 #ifdef I386_REGNO_TO_SYMMETRY
987 #error "The Sequent Symmetry is no longer supported."
990 /* According to the System V ABI, the registers %ebp, %ebx, %edi, %esi
991 and %esp "belong" to the calling function. Therefore these
992 registers should be saved if they're going to be modified. */
994 /* The maximum number of saved registers. This should include all
995 registers mentioned above, and %eip. */
996 #define I386_NUM_SAVED_REGS I386_NUM_GREGS
998 struct i386_frame_cache
1006 /* Saved registers. */
1007 CORE_ADDR saved_regs
[I386_NUM_SAVED_REGS
];
1012 /* Stack space reserved for local variables. */
1016 /* Allocate and initialize a frame cache. */
1018 static struct i386_frame_cache
*
1019 i386_alloc_frame_cache (void)
1021 struct i386_frame_cache
*cache
;
1024 cache
= FRAME_OBSTACK_ZALLOC (struct i386_frame_cache
);
1029 cache
->sp_offset
= -4;
1032 /* Saved registers. We initialize these to -1 since zero is a valid
1033 offset (that's where %ebp is supposed to be stored). */
1034 for (i
= 0; i
< I386_NUM_SAVED_REGS
; i
++)
1035 cache
->saved_regs
[i
] = -1;
1036 cache
->saved_sp
= 0;
1037 cache
->saved_sp_reg
= -1;
1038 cache
->pc_in_eax
= 0;
1040 /* Frameless until proven otherwise. */
1046 /* If the instruction at PC is a jump, return the address of its
1047 target. Otherwise, return PC. */
1050 i386_follow_jump (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1052 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1057 if (target_read_code (pc
, &op
, 1))
1064 op
= read_code_unsigned_integer (pc
+ 1, 1, byte_order
);
1070 /* Relative jump: if data16 == 0, disp32, else disp16. */
1073 delta
= read_memory_integer (pc
+ 2, 2, byte_order
);
1075 /* Include the size of the jmp instruction (including the
1081 delta
= read_memory_integer (pc
+ 1, 4, byte_order
);
1083 /* Include the size of the jmp instruction. */
1088 /* Relative jump, disp8 (ignore data16). */
1089 delta
= read_memory_integer (pc
+ data16
+ 1, 1, byte_order
);
1091 delta
+= data16
+ 2;
1098 /* Check whether PC points at a prologue for a function returning a
1099 structure or union. If so, it updates CACHE and returns the
1100 address of the first instruction after the code sequence that
1101 removes the "hidden" argument from the stack or CURRENT_PC,
1102 whichever is smaller. Otherwise, return PC. */
1105 i386_analyze_struct_return (CORE_ADDR pc
, CORE_ADDR current_pc
,
1106 struct i386_frame_cache
*cache
)
1108 /* Functions that return a structure or union start with:
1111 xchgl %eax, (%esp) 0x87 0x04 0x24
1112 or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
1114 (the System V compiler puts out the second `xchg' instruction,
1115 and the assembler doesn't try to optimize it, so the 'sib' form
1116 gets generated). This sequence is used to get the address of the
1117 return buffer for a function that returns a structure. */
1118 static gdb_byte proto1
[3] = { 0x87, 0x04, 0x24 };
1119 static gdb_byte proto2
[4] = { 0x87, 0x44, 0x24, 0x00 };
1123 if (current_pc
<= pc
)
1126 if (target_read_code (pc
, &op
, 1))
1129 if (op
!= 0x58) /* popl %eax */
1132 if (target_read_code (pc
+ 1, buf
, 4))
1135 if (memcmp (buf
, proto1
, 3) != 0 && memcmp (buf
, proto2
, 4) != 0)
1138 if (current_pc
== pc
)
1140 cache
->sp_offset
+= 4;
1144 if (current_pc
== pc
+ 1)
1146 cache
->pc_in_eax
= 1;
1150 if (buf
[1] == proto1
[1])
1157 i386_skip_probe (CORE_ADDR pc
)
1159 /* A function may start with
1173 if (target_read_code (pc
, &op
, 1))
1176 if (op
== 0x68 || op
== 0x6a)
1180 /* Skip past the `pushl' instruction; it has either a one-byte or a
1181 four-byte operand, depending on the opcode. */
1187 /* Read the following 8 bytes, which should be `call _probe' (6
1188 bytes) followed by `addl $4,%esp' (2 bytes). */
1189 read_memory (pc
+ delta
, buf
, sizeof (buf
));
1190 if (buf
[0] == 0xe8 && buf
[6] == 0xc4 && buf
[7] == 0x4)
1191 pc
+= delta
+ sizeof (buf
);
1197 /* GCC 4.1 and later, can put code in the prologue to realign the
1198 stack pointer. Check whether PC points to such code, and update
1199 CACHE accordingly. Return the first instruction after the code
1200 sequence or CURRENT_PC, whichever is smaller. If we don't
1201 recognize the code, return PC. */
1204 i386_analyze_stack_align (CORE_ADDR pc
, CORE_ADDR current_pc
,
1205 struct i386_frame_cache
*cache
)
1207 /* There are 2 code sequences to re-align stack before the frame
1210 1. Use a caller-saved saved register:
1216 2. Use a callee-saved saved register:
1223 "andl $-XXX, %esp" can be either 3 bytes or 6 bytes:
1225 0x83 0xe4 0xf0 andl $-16, %esp
1226 0x81 0xe4 0x00 0xff 0xff 0xff andl $-256, %esp
1231 int offset
, offset_and
;
1232 static int regnums
[8] = {
1233 I386_EAX_REGNUM
, /* %eax */
1234 I386_ECX_REGNUM
, /* %ecx */
1235 I386_EDX_REGNUM
, /* %edx */
1236 I386_EBX_REGNUM
, /* %ebx */
1237 I386_ESP_REGNUM
, /* %esp */
1238 I386_EBP_REGNUM
, /* %ebp */
1239 I386_ESI_REGNUM
, /* %esi */
1240 I386_EDI_REGNUM
/* %edi */
1243 if (target_read_code (pc
, buf
, sizeof buf
))
1246 /* Check caller-saved saved register. The first instruction has
1247 to be "leal 4(%esp), %reg". */
1248 if (buf
[0] == 0x8d && buf
[2] == 0x24 && buf
[3] == 0x4)
1250 /* MOD must be binary 10 and R/M must be binary 100. */
1251 if ((buf
[1] & 0xc7) != 0x44)
1254 /* REG has register number. */
1255 reg
= (buf
[1] >> 3) & 7;
1260 /* Check callee-saved saved register. The first instruction
1261 has to be "pushl %reg". */
1262 if ((buf
[0] & 0xf8) != 0x50)
1268 /* The next instruction has to be "leal 8(%esp), %reg". */
1269 if (buf
[1] != 0x8d || buf
[3] != 0x24 || buf
[4] != 0x8)
1272 /* MOD must be binary 10 and R/M must be binary 100. */
1273 if ((buf
[2] & 0xc7) != 0x44)
1276 /* REG has register number. Registers in pushl and leal have to
1278 if (reg
!= ((buf
[2] >> 3) & 7))
1284 /* Rigister can't be %esp nor %ebp. */
1285 if (reg
== 4 || reg
== 5)
1288 /* The next instruction has to be "andl $-XXX, %esp". */
1289 if (buf
[offset
+ 1] != 0xe4
1290 || (buf
[offset
] != 0x81 && buf
[offset
] != 0x83))
1293 offset_and
= offset
;
1294 offset
+= buf
[offset
] == 0x81 ? 6 : 3;
1296 /* The next instruction has to be "pushl -4(%reg)". 8bit -4 is
1297 0xfc. REG must be binary 110 and MOD must be binary 01. */
1298 if (buf
[offset
] != 0xff
1299 || buf
[offset
+ 2] != 0xfc
1300 || (buf
[offset
+ 1] & 0xf8) != 0x70)
1303 /* R/M has register. Registers in leal and pushl have to be the
1305 if (reg
!= (buf
[offset
+ 1] & 7))
1308 if (current_pc
> pc
+ offset_and
)
1309 cache
->saved_sp_reg
= regnums
[reg
];
1311 return std::min (pc
+ offset
+ 3, current_pc
);
1314 /* Maximum instruction length we need to handle. */
1315 #define I386_MAX_MATCHED_INSN_LEN 6
1317 /* Instruction description. */
1321 gdb_byte insn
[I386_MAX_MATCHED_INSN_LEN
];
1322 gdb_byte mask
[I386_MAX_MATCHED_INSN_LEN
];
1325 /* Return whether instruction at PC matches PATTERN. */
1328 i386_match_pattern (CORE_ADDR pc
, struct i386_insn pattern
)
1332 if (target_read_code (pc
, &op
, 1))
1335 if ((op
& pattern
.mask
[0]) == pattern
.insn
[0])
1337 gdb_byte buf
[I386_MAX_MATCHED_INSN_LEN
- 1];
1338 int insn_matched
= 1;
1341 gdb_assert (pattern
.len
> 1);
1342 gdb_assert (pattern
.len
<= I386_MAX_MATCHED_INSN_LEN
);
1344 if (target_read_code (pc
+ 1, buf
, pattern
.len
- 1))
1347 for (i
= 1; i
< pattern
.len
; i
++)
1349 if ((buf
[i
- 1] & pattern
.mask
[i
]) != pattern
.insn
[i
])
1352 return insn_matched
;
1357 /* Search for the instruction at PC in the list INSN_PATTERNS. Return
1358 the first instruction description that matches. Otherwise, return
1361 static struct i386_insn
*
1362 i386_match_insn (CORE_ADDR pc
, struct i386_insn
*insn_patterns
)
1364 struct i386_insn
*pattern
;
1366 for (pattern
= insn_patterns
; pattern
->len
> 0; pattern
++)
1368 if (i386_match_pattern (pc
, *pattern
))
1375 /* Return whether PC points inside a sequence of instructions that
1376 matches INSN_PATTERNS. */
1379 i386_match_insn_block (CORE_ADDR pc
, struct i386_insn
*insn_patterns
)
1381 CORE_ADDR current_pc
;
1383 struct i386_insn
*insn
;
1385 insn
= i386_match_insn (pc
, insn_patterns
);
1390 ix
= insn
- insn_patterns
;
1391 for (i
= ix
- 1; i
>= 0; i
--)
1393 current_pc
-= insn_patterns
[i
].len
;
1395 if (!i386_match_pattern (current_pc
, insn_patterns
[i
]))
1399 current_pc
= pc
+ insn
->len
;
1400 for (insn
= insn_patterns
+ ix
+ 1; insn
->len
> 0; insn
++)
1402 if (!i386_match_pattern (current_pc
, *insn
))
1405 current_pc
+= insn
->len
;
1411 /* Some special instructions that might be migrated by GCC into the
1412 part of the prologue that sets up the new stack frame. Because the
1413 stack frame hasn't been setup yet, no registers have been saved
1414 yet, and only the scratch registers %eax, %ecx and %edx can be
1417 static i386_insn i386_frame_setup_skip_insns
[] =
1419 /* Check for `movb imm8, r' and `movl imm32, r'.
1421 ??? Should we handle 16-bit operand-sizes here? */
1423 /* `movb imm8, %al' and `movb imm8, %ah' */
1424 /* `movb imm8, %cl' and `movb imm8, %ch' */
1425 { 2, { 0xb0, 0x00 }, { 0xfa, 0x00 } },
1426 /* `movb imm8, %dl' and `movb imm8, %dh' */
1427 { 2, { 0xb2, 0x00 }, { 0xfb, 0x00 } },
1428 /* `movl imm32, %eax' and `movl imm32, %ecx' */
1429 { 5, { 0xb8 }, { 0xfe } },
1430 /* `movl imm32, %edx' */
1431 { 5, { 0xba }, { 0xff } },
1433 /* Check for `mov imm32, r32'. Note that there is an alternative
1434 encoding for `mov m32, %eax'.
1436 ??? Should we handle SIB addressing here?
1437 ??? Should we handle 16-bit operand-sizes here? */
1439 /* `movl m32, %eax' */
1440 { 5, { 0xa1 }, { 0xff } },
1441 /* `movl m32, %eax' and `mov; m32, %ecx' */
1442 { 6, { 0x89, 0x05 }, {0xff, 0xf7 } },
1443 /* `movl m32, %edx' */
1444 { 6, { 0x89, 0x15 }, {0xff, 0xff } },
1446 /* Check for `xorl r32, r32' and the equivalent `subl r32, r32'.
1447 Because of the symmetry, there are actually two ways to encode
1448 these instructions; opcode bytes 0x29 and 0x2b for `subl' and
1449 opcode bytes 0x31 and 0x33 for `xorl'. */
1451 /* `subl %eax, %eax' */
1452 { 2, { 0x29, 0xc0 }, { 0xfd, 0xff } },
1453 /* `subl %ecx, %ecx' */
1454 { 2, { 0x29, 0xc9 }, { 0xfd, 0xff } },
1455 /* `subl %edx, %edx' */
1456 { 2, { 0x29, 0xd2 }, { 0xfd, 0xff } },
1457 /* `xorl %eax, %eax' */
1458 { 2, { 0x31, 0xc0 }, { 0xfd, 0xff } },
1459 /* `xorl %ecx, %ecx' */
1460 { 2, { 0x31, 0xc9 }, { 0xfd, 0xff } },
1461 /* `xorl %edx, %edx' */
1462 { 2, { 0x31, 0xd2 }, { 0xfd, 0xff } },
1466 /* Check whether PC points to an endbr32 instruction. */
1468 i386_skip_endbr (CORE_ADDR pc
)
1470 static const gdb_byte endbr32
[] = { 0xf3, 0x0f, 0x1e, 0xfb };
1472 gdb_byte buf
[sizeof (endbr32
)];
1474 /* Stop there if we can't read the code */
1475 if (target_read_code (pc
, buf
, sizeof (endbr32
)))
1478 /* If the instruction isn't an endbr32, stop */
1479 if (memcmp (buf
, endbr32
, sizeof (endbr32
)) != 0)
1482 return pc
+ sizeof (endbr32
);
1485 /* Check whether PC points to a no-op instruction. */
1487 i386_skip_noop (CORE_ADDR pc
)
1492 if (target_read_code (pc
, &op
, 1))
1498 /* Ignore `nop' instruction. */
1502 if (target_read_code (pc
, &op
, 1))
1506 /* Ignore no-op instruction `mov %edi, %edi'.
1507 Microsoft system dlls often start with
1508 a `mov %edi,%edi' instruction.
1509 The 5 bytes before the function start are
1510 filled with `nop' instructions.
1511 This pattern can be used for hot-patching:
1512 The `mov %edi, %edi' instruction can be replaced by a
1513 near jump to the location of the 5 `nop' instructions
1514 which can be replaced by a 32-bit jump to anywhere
1515 in the 32-bit address space. */
1517 else if (op
== 0x8b)
1519 if (target_read_code (pc
+ 1, &op
, 1))
1525 if (target_read_code (pc
, &op
, 1))
1535 /* Check whether PC points at a code that sets up a new stack frame.
1536 If so, it updates CACHE and returns the address of the first
1537 instruction after the sequence that sets up the frame or LIMIT,
1538 whichever is smaller. If we don't recognize the code, return PC. */
1541 i386_analyze_frame_setup (struct gdbarch
*gdbarch
,
1542 CORE_ADDR pc
, CORE_ADDR limit
,
1543 struct i386_frame_cache
*cache
)
1545 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1546 struct i386_insn
*insn
;
1553 if (target_read_code (pc
, &op
, 1))
1556 if (op
== 0x55) /* pushl %ebp */
1558 /* Take into account that we've executed the `pushl %ebp' that
1559 starts this instruction sequence. */
1560 cache
->saved_regs
[I386_EBP_REGNUM
] = 0;
1561 cache
->sp_offset
+= 4;
1564 /* If that's all, return now. */
1568 /* Check for some special instructions that might be migrated by
1569 GCC into the prologue and skip them. At this point in the
1570 prologue, code should only touch the scratch registers %eax,
1571 %ecx and %edx, so while the number of possibilities is sheer,
1574 Make sure we only skip these instructions if we later see the
1575 `movl %esp, %ebp' that actually sets up the frame. */
1576 while (pc
+ skip
< limit
)
1578 insn
= i386_match_insn (pc
+ skip
, i386_frame_setup_skip_insns
);
1585 /* If that's all, return now. */
1586 if (limit
<= pc
+ skip
)
1589 if (target_read_code (pc
+ skip
, &op
, 1))
1592 /* The i386 prologue looks like
1598 and a different prologue can be generated for atom.
1602 lea -0x10(%esp),%esp
1604 We handle both of them here. */
1608 /* Check for `movl %esp, %ebp' -- can be written in two ways. */
1610 if (read_code_unsigned_integer (pc
+ skip
+ 1, 1, byte_order
)
1616 if (read_code_unsigned_integer (pc
+ skip
+ 1, 1, byte_order
)
1621 case 0x8d: /* Check for 'lea (%ebp), %ebp'. */
1622 if (read_code_unsigned_integer (pc
+ skip
+ 1, 2, byte_order
)
1631 /* OK, we actually have a frame. We just don't know how large
1632 it is yet. Set its size to zero. We'll adjust it if
1633 necessary. We also now commit to skipping the special
1634 instructions mentioned before. */
1637 /* If that's all, return now. */
1641 /* Check for stack adjustment
1647 NOTE: You can't subtract a 16-bit immediate from a 32-bit
1648 reg, so we don't have to worry about a data16 prefix. */
1649 if (target_read_code (pc
, &op
, 1))
1653 /* `subl' with 8-bit immediate. */
1654 if (read_code_unsigned_integer (pc
+ 1, 1, byte_order
) != 0xec)
1655 /* Some instruction starting with 0x83 other than `subl'. */
1658 /* `subl' with signed 8-bit immediate (though it wouldn't
1659 make sense to be negative). */
1660 cache
->locals
= read_code_integer (pc
+ 2, 1, byte_order
);
1663 else if (op
== 0x81)
1665 /* Maybe it is `subl' with a 32-bit immediate. */
1666 if (read_code_unsigned_integer (pc
+ 1, 1, byte_order
) != 0xec)
1667 /* Some instruction starting with 0x81 other than `subl'. */
1670 /* It is `subl' with a 32-bit immediate. */
1671 cache
->locals
= read_code_integer (pc
+ 2, 4, byte_order
);
1674 else if (op
== 0x8d)
1676 /* The ModR/M byte is 0x64. */
1677 if (read_code_unsigned_integer (pc
+ 1, 1, byte_order
) != 0x64)
1679 /* 'lea' with 8-bit displacement. */
1680 cache
->locals
= -1 * read_code_integer (pc
+ 3, 1, byte_order
);
1685 /* Some instruction other than `subl' nor 'lea'. */
1689 else if (op
== 0xc8) /* enter */
1691 cache
->locals
= read_code_unsigned_integer (pc
+ 1, 2, byte_order
);
1698 /* Check whether PC points at code that saves registers on the stack.
1699 If so, it updates CACHE and returns the address of the first
1700 instruction after the register saves or CURRENT_PC, whichever is
1701 smaller. Otherwise, return PC. */
1704 i386_analyze_register_saves (CORE_ADDR pc
, CORE_ADDR current_pc
,
1705 struct i386_frame_cache
*cache
)
1707 CORE_ADDR offset
= 0;
1711 if (cache
->locals
> 0)
1712 offset
-= cache
->locals
;
1713 for (i
= 0; i
< 8 && pc
< current_pc
; i
++)
1715 if (target_read_code (pc
, &op
, 1))
1717 if (op
< 0x50 || op
> 0x57)
1721 cache
->saved_regs
[op
- 0x50] = offset
;
1722 cache
->sp_offset
+= 4;
1729 /* Do a full analysis of the prologue at PC and update CACHE
1730 accordingly. Bail out early if CURRENT_PC is reached. Return the
1731 address where the analysis stopped.
1733 We handle these cases:
1735 The startup sequence can be at the start of the function, or the
1736 function can start with a branch to startup code at the end.
1738 %ebp can be set up with either the 'enter' instruction, or "pushl
1739 %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was
1740 once used in the System V compiler).
1742 Local space is allocated just below the saved %ebp by either the
1743 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a
1744 16-bit unsigned argument for space to allocate, and the 'addl'
1745 instruction could have either a signed byte, or 32-bit immediate.
1747 Next, the registers used by this function are pushed. With the
1748 System V compiler they will always be in the order: %edi, %esi,
1749 %ebx (and sometimes a harmless bug causes it to also save but not
1750 restore %eax); however, the code below is willing to see the pushes
1751 in any order, and will handle up to 8 of them.
1753 If the setup sequence is at the end of the function, then the next
1754 instruction will be a branch back to the start. */
1757 i386_analyze_prologue (struct gdbarch
*gdbarch
,
1758 CORE_ADDR pc
, CORE_ADDR current_pc
,
1759 struct i386_frame_cache
*cache
)
1761 pc
= i386_skip_endbr (pc
);
1762 pc
= i386_skip_noop (pc
);
1763 pc
= i386_follow_jump (gdbarch
, pc
);
1764 pc
= i386_analyze_struct_return (pc
, current_pc
, cache
);
1765 pc
= i386_skip_probe (pc
);
1766 pc
= i386_analyze_stack_align (pc
, current_pc
, cache
);
1767 pc
= i386_analyze_frame_setup (gdbarch
, pc
, current_pc
, cache
);
1768 return i386_analyze_register_saves (pc
, current_pc
, cache
);
1771 /* Return PC of first real instruction. */
1774 i386_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR start_pc
)
1776 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1778 static gdb_byte pic_pat
[6] =
1780 0xe8, 0, 0, 0, 0, /* call 0x0 */
1781 0x5b, /* popl %ebx */
1783 struct i386_frame_cache cache
;
1787 CORE_ADDR func_addr
;
1789 if (find_pc_partial_function (start_pc
, NULL
, &func_addr
, NULL
))
1791 CORE_ADDR post_prologue_pc
1792 = skip_prologue_using_sal (gdbarch
, func_addr
);
1793 struct compunit_symtab
*cust
= find_pc_compunit_symtab (func_addr
);
1795 /* LLVM backend (Clang/Flang) always emits a line note before the
1796 prologue and another one after. We trust clang and newer Intel
1797 compilers to emit usable line notes. */
1798 if (post_prologue_pc
1800 && cust
->producer () != NULL
1801 && (producer_is_llvm (cust
->producer ())
1802 || producer_is_icc_ge_19 (cust
->producer ()))))
1803 return std::max (start_pc
, post_prologue_pc
);
1807 pc
= i386_analyze_prologue (gdbarch
, start_pc
, 0xffffffff, &cache
);
1808 if (cache
.locals
< 0)
1811 /* Found valid frame setup. */
1813 /* The native cc on SVR4 in -K PIC mode inserts the following code
1814 to get the address of the global offset table (GOT) into register
1819 movl %ebx,x(%ebp) (optional)
1822 This code is with the rest of the prologue (at the end of the
1823 function), so we have to skip it to get to the first real
1824 instruction at the start of the function. */
1826 for (i
= 0; i
< 6; i
++)
1828 if (target_read_code (pc
+ i
, &op
, 1))
1831 if (pic_pat
[i
] != op
)
1838 if (target_read_code (pc
+ delta
, &op
, 1))
1841 if (op
== 0x89) /* movl %ebx, x(%ebp) */
1843 op
= read_code_unsigned_integer (pc
+ delta
+ 1, 1, byte_order
);
1845 if (op
== 0x5d) /* One byte offset from %ebp. */
1847 else if (op
== 0x9d) /* Four byte offset from %ebp. */
1849 else /* Unexpected instruction. */
1852 if (target_read_code (pc
+ delta
, &op
, 1))
1857 if (delta
> 0 && op
== 0x81
1858 && read_code_unsigned_integer (pc
+ delta
+ 1, 1, byte_order
)
1865 /* If the function starts with a branch (to startup code at the end)
1866 the last instruction should bring us back to the first
1867 instruction of the real code. */
1868 if (i386_follow_jump (gdbarch
, start_pc
) != start_pc
)
1869 pc
= i386_follow_jump (gdbarch
, pc
);
1874 /* Check that the code pointed to by PC corresponds to a call to
1875 __main, skip it if so. Return PC otherwise. */
1878 i386_skip_main_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1880 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1883 if (target_read_code (pc
, &op
, 1))
1889 if (target_read_code (pc
+ 1, buf
, sizeof buf
) == 0)
1891 /* Make sure address is computed correctly as a 32bit
1892 integer even if CORE_ADDR is 64 bit wide. */
1893 CORE_ADDR call_dest
;
1895 call_dest
= pc
+ 5 + extract_signed_integer (buf
, 4, byte_order
);
1896 call_dest
= call_dest
& 0xffffffffU
;
1897 bound_minimal_symbol s
= lookup_minimal_symbol_by_pc (call_dest
);
1898 if (s
.minsym
!= NULL
1899 && s
.minsym
->linkage_name () != NULL
1900 && strcmp (s
.minsym
->linkage_name (), "__main") == 0)
1908 /* This function is 64-bit safe. */
1911 i386_unwind_pc (struct gdbarch
*gdbarch
, const frame_info_ptr
&next_frame
)
1915 frame_unwind_register (next_frame
, gdbarch_pc_regnum (gdbarch
), buf
);
1916 return extract_typed_address (buf
, builtin_type (gdbarch
)->builtin_func_ptr
);
1920 /* Normal frames. */
1923 i386_frame_cache_1 (const frame_info_ptr
&this_frame
,
1924 struct i386_frame_cache
*cache
)
1926 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1927 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1931 cache
->pc
= get_frame_func (this_frame
);
1933 /* In principle, for normal frames, %ebp holds the frame pointer,
1934 which holds the base address for the current stack frame.
1935 However, for functions that don't need it, the frame pointer is
1936 optional. For these "frameless" functions the frame pointer is
1937 actually the frame pointer of the calling frame. Signal
1938 trampolines are just a special case of a "frameless" function.
1939 They (usually) share their frame pointer with the frame that was
1940 in progress when the signal occurred. */
1942 get_frame_register (this_frame
, I386_EBP_REGNUM
, buf
);
1943 cache
->base
= extract_unsigned_integer (buf
, 4, byte_order
);
1944 if (cache
->base
== 0)
1950 /* For normal frames, %eip is stored at 4(%ebp). */
1951 cache
->saved_regs
[I386_EIP_REGNUM
] = 4;
1954 i386_analyze_prologue (gdbarch
, cache
->pc
, get_frame_pc (this_frame
),
1957 if (cache
->locals
< 0)
1959 /* We didn't find a valid frame, which means that CACHE->base
1960 currently holds the frame pointer for our calling frame. If
1961 we're at the start of a function, or somewhere half-way its
1962 prologue, the function's frame probably hasn't been fully
1963 setup yet. Try to reconstruct the base address for the stack
1964 frame by looking at the stack pointer. For truly "frameless"
1965 functions this might work too. */
1967 if (cache
->saved_sp_reg
!= -1)
1969 /* Saved stack pointer has been saved. */
1970 get_frame_register (this_frame
, cache
->saved_sp_reg
, buf
);
1971 cache
->saved_sp
= extract_unsigned_integer (buf
, 4, byte_order
);
1973 /* We're halfway aligning the stack. */
1974 cache
->base
= ((cache
->saved_sp
- 4) & 0xfffffff0) - 4;
1975 cache
->saved_regs
[I386_EIP_REGNUM
] = cache
->saved_sp
- 4;
1977 /* This will be added back below. */
1978 cache
->saved_regs
[I386_EIP_REGNUM
] -= cache
->base
;
1980 else if (cache
->pc
!= 0
1981 || target_read_code (get_frame_pc (this_frame
), buf
, 1))
1983 /* We're in a known function, but did not find a frame
1984 setup. Assume that the function does not use %ebp.
1985 Alternatively, we may have jumped to an invalid
1986 address; in that case there is definitely no new
1988 get_frame_register (this_frame
, I386_ESP_REGNUM
, buf
);
1989 cache
->base
= extract_unsigned_integer (buf
, 4, byte_order
)
1993 /* We're in an unknown function. We could not find the start
1994 of the function to analyze the prologue; our best option is
1995 to assume a typical frame layout with the caller's %ebp
1997 cache
->saved_regs
[I386_EBP_REGNUM
] = 0;
2000 if (cache
->saved_sp_reg
!= -1)
2002 /* Saved stack pointer has been saved (but the SAVED_SP_REG
2003 register may be unavailable). */
2004 if (cache
->saved_sp
== 0
2005 && deprecated_frame_register_read (this_frame
,
2006 cache
->saved_sp_reg
, buf
))
2007 cache
->saved_sp
= extract_unsigned_integer (buf
, 4, byte_order
);
2009 /* Now that we have the base address for the stack frame we can
2010 calculate the value of %esp in the calling frame. */
2011 else if (cache
->saved_sp
== 0)
2012 cache
->saved_sp
= cache
->base
+ 8;
2014 /* Adjust all the saved registers such that they contain addresses
2015 instead of offsets. */
2016 for (i
= 0; i
< I386_NUM_SAVED_REGS
; i
++)
2017 if (cache
->saved_regs
[i
] != -1)
2018 cache
->saved_regs
[i
] += cache
->base
;
2023 static struct i386_frame_cache
*
2024 i386_frame_cache (const frame_info_ptr
&this_frame
, void **this_cache
)
2026 struct i386_frame_cache
*cache
;
2029 return (struct i386_frame_cache
*) *this_cache
;
2031 cache
= i386_alloc_frame_cache ();
2032 *this_cache
= cache
;
2036 i386_frame_cache_1 (this_frame
, cache
);
2038 catch (const gdb_exception_error
&ex
)
2040 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
2048 i386_frame_this_id (const frame_info_ptr
&this_frame
, void **this_cache
,
2049 struct frame_id
*this_id
)
2051 struct i386_frame_cache
*cache
= i386_frame_cache (this_frame
, this_cache
);
2054 (*this_id
) = frame_id_build_unavailable_stack (cache
->pc
);
2055 else if (cache
->base
== 0)
2057 /* This marks the outermost frame. */
2061 /* See the end of i386_push_dummy_call. */
2062 (*this_id
) = frame_id_build (cache
->base
+ 8, cache
->pc
);
2066 static enum unwind_stop_reason
2067 i386_frame_unwind_stop_reason (const frame_info_ptr
&this_frame
,
2070 struct i386_frame_cache
*cache
= i386_frame_cache (this_frame
, this_cache
);
2073 return UNWIND_UNAVAILABLE
;
2075 /* This marks the outermost frame. */
2076 if (cache
->base
== 0)
2077 return UNWIND_OUTERMOST
;
2079 return UNWIND_NO_REASON
;
2082 static struct value
*
2083 i386_frame_prev_register (const frame_info_ptr
&this_frame
, void **this_cache
,
2086 struct i386_frame_cache
*cache
= i386_frame_cache (this_frame
, this_cache
);
2088 gdb_assert (regnum
>= 0);
2090 /* The System V ABI says that:
2092 "The flags register contains the system flags, such as the
2093 direction flag and the carry flag. The direction flag must be
2094 set to the forward (that is, zero) direction before entry and
2095 upon exit from a function. Other user flags have no specified
2096 role in the standard calling sequence and are not preserved."
2098 To guarantee the "upon exit" part of that statement we fake a
2099 saved flags register that has its direction flag cleared.
2101 Note that GCC doesn't seem to rely on the fact that the direction
2102 flag is cleared after a function return; it always explicitly
2103 clears the flag before operations where it matters.
2105 FIXME: kettenis/20030316: I'm not quite sure whether this is the
2106 right thing to do. The way we fake the flags register here makes
2107 it impossible to change it. */
2109 if (regnum
== I386_EFLAGS_REGNUM
)
2113 val
= get_frame_register_unsigned (this_frame
, regnum
);
2115 return frame_unwind_got_constant (this_frame
, regnum
, val
);
2118 if (regnum
== I386_EIP_REGNUM
&& cache
->pc_in_eax
)
2119 return frame_unwind_got_register (this_frame
, regnum
, I386_EAX_REGNUM
);
2121 if (regnum
== I386_ESP_REGNUM
2122 && (cache
->saved_sp
!= 0 || cache
->saved_sp_reg
!= -1))
2124 /* If the SP has been saved, but we don't know where, then this
2125 means that SAVED_SP_REG register was found unavailable back
2126 when we built the cache. */
2127 if (cache
->saved_sp
== 0)
2128 return frame_unwind_got_register (this_frame
, regnum
,
2129 cache
->saved_sp_reg
);
2131 return frame_unwind_got_constant (this_frame
, regnum
,
2135 if (regnum
< I386_NUM_SAVED_REGS
&& cache
->saved_regs
[regnum
] != -1)
2136 return frame_unwind_got_memory (this_frame
, regnum
,
2137 cache
->saved_regs
[regnum
]);
2139 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
2142 static const struct frame_unwind i386_frame_unwind
=
2146 i386_frame_unwind_stop_reason
,
2148 i386_frame_prev_register
,
2150 default_frame_sniffer
2153 /* Normal frames, but in a function epilogue. */
2155 /* Implement the stack_frame_destroyed_p gdbarch method.
2157 The epilogue is defined here as the 'ret' instruction, which will
2158 follow any instruction such as 'leave' or 'pop %ebp' that destroys
2159 the function's stack frame. */
2162 i386_stack_frame_destroyed_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
2165 if (target_read_memory (pc
, &insn
, 1))
2166 return 0; /* Can't read memory at pc. */
2168 if (insn
!= 0xc3) /* 'ret' instruction. */
2175 i386_epilogue_frame_sniffer_1 (const struct frame_unwind
*self
,
2176 const frame_info_ptr
&this_frame
,
2177 void **this_prologue_cache
, bool override_p
)
2179 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
2180 CORE_ADDR pc
= get_frame_pc (this_frame
);
2182 if (frame_relative_level (this_frame
) != 0)
2183 /* We're not in the inner frame, so assume we're not in an epilogue. */
2187 = compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc
));
2191 /* Don't override the symtab unwinders, skip
2192 "i386 epilogue override". */
2197 if (!unwind_valid_p
)
2198 /* "i386 epilogue override" unwinder already ran, skip
2203 /* Check whether we're in an epilogue. */
2204 return i386_stack_frame_destroyed_p (gdbarch
, pc
);
2208 i386_epilogue_override_frame_sniffer (const struct frame_unwind
*self
,
2209 const frame_info_ptr
&this_frame
,
2210 void **this_prologue_cache
)
2212 return i386_epilogue_frame_sniffer_1 (self
, this_frame
, this_prologue_cache
,
2217 i386_epilogue_frame_sniffer (const struct frame_unwind
*self
,
2218 const frame_info_ptr
&this_frame
,
2219 void **this_prologue_cache
)
2221 return i386_epilogue_frame_sniffer_1 (self
, this_frame
, this_prologue_cache
,
2225 static struct i386_frame_cache
*
2226 i386_epilogue_frame_cache (const frame_info_ptr
&this_frame
, void **this_cache
)
2228 struct i386_frame_cache
*cache
;
2232 return (struct i386_frame_cache
*) *this_cache
;
2234 cache
= i386_alloc_frame_cache ();
2235 *this_cache
= cache
;
2239 cache
->pc
= get_frame_func (this_frame
);
2241 /* At this point the stack looks as if we just entered the
2242 function, with the return address at the top of the
2244 sp
= get_frame_register_unsigned (this_frame
, I386_ESP_REGNUM
);
2245 cache
->base
= sp
+ cache
->sp_offset
;
2246 cache
->saved_sp
= cache
->base
+ 8;
2247 cache
->saved_regs
[I386_EIP_REGNUM
] = cache
->base
+ 4;
2251 catch (const gdb_exception_error
&ex
)
2253 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
2260 static enum unwind_stop_reason
2261 i386_epilogue_frame_unwind_stop_reason (const frame_info_ptr
&this_frame
,
2264 struct i386_frame_cache
*cache
=
2265 i386_epilogue_frame_cache (this_frame
, this_cache
);
2268 return UNWIND_UNAVAILABLE
;
2270 return UNWIND_NO_REASON
;
2274 i386_epilogue_frame_this_id (const frame_info_ptr
&this_frame
,
2276 struct frame_id
*this_id
)
2278 struct i386_frame_cache
*cache
=
2279 i386_epilogue_frame_cache (this_frame
, this_cache
);
2282 (*this_id
) = frame_id_build_unavailable_stack (cache
->pc
);
2284 (*this_id
) = frame_id_build (cache
->base
+ 8, cache
->pc
);
2287 static struct value
*
2288 i386_epilogue_frame_prev_register (const frame_info_ptr
&this_frame
,
2289 void **this_cache
, int regnum
)
2291 /* Make sure we've initialized the cache. */
2292 i386_epilogue_frame_cache (this_frame
, this_cache
);
2294 return i386_frame_prev_register (this_frame
, this_cache
, regnum
);
2297 static const struct frame_unwind i386_epilogue_override_frame_unwind
=
2299 "i386 epilogue override",
2301 i386_epilogue_frame_unwind_stop_reason
,
2302 i386_epilogue_frame_this_id
,
2303 i386_epilogue_frame_prev_register
,
2305 i386_epilogue_override_frame_sniffer
2308 static const struct frame_unwind i386_epilogue_frame_unwind
=
2312 i386_epilogue_frame_unwind_stop_reason
,
2313 i386_epilogue_frame_this_id
,
2314 i386_epilogue_frame_prev_register
,
2316 i386_epilogue_frame_sniffer
2320 /* Stack-based trampolines. */
2322 /* These trampolines are used on cross x86 targets, when taking the
2323 address of a nested function. When executing these trampolines,
2324 no stack frame is set up, so we are in a similar situation as in
2325 epilogues and i386_epilogue_frame_this_id can be re-used. */
2327 /* Static chain passed in register. */
2329 static i386_insn i386_tramp_chain_in_reg_insns
[] =
2331 /* `movl imm32, %eax' and `movl imm32, %ecx' */
2332 { 5, { 0xb8 }, { 0xfe } },
2335 { 5, { 0xe9 }, { 0xff } },
2340 /* Static chain passed on stack (when regparm=3). */
2342 static i386_insn i386_tramp_chain_on_stack_insns
[] =
2345 { 5, { 0x68 }, { 0xff } },
2348 { 5, { 0xe9 }, { 0xff } },
2353 /* Return whether PC points inside a stack trampoline. */
2356 i386_in_stack_tramp_p (CORE_ADDR pc
)
2361 /* A stack trampoline is detected if no name is associated
2362 to the current pc and if it points inside a trampoline
2365 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
2369 if (target_read_memory (pc
, &insn
, 1))
2372 if (!i386_match_insn_block (pc
, i386_tramp_chain_in_reg_insns
)
2373 && !i386_match_insn_block (pc
, i386_tramp_chain_on_stack_insns
))
2380 i386_stack_tramp_frame_sniffer (const struct frame_unwind
*self
,
2381 const frame_info_ptr
&this_frame
,
2384 if (frame_relative_level (this_frame
) == 0)
2385 return i386_in_stack_tramp_p (get_frame_pc (this_frame
));
2390 static const struct frame_unwind i386_stack_tramp_frame_unwind
=
2394 i386_epilogue_frame_unwind_stop_reason
,
2395 i386_epilogue_frame_this_id
,
2396 i386_epilogue_frame_prev_register
,
2398 i386_stack_tramp_frame_sniffer
2401 /* Generate a bytecode expression to get the value of the saved PC. */
2404 i386_gen_return_address (struct gdbarch
*gdbarch
,
2405 struct agent_expr
*ax
, struct axs_value
*value
,
2408 /* The following sequence assumes the traditional use of the base
2410 ax_reg (ax
, I386_EBP_REGNUM
);
2412 ax_simple (ax
, aop_add
);
2413 value
->type
= register_type (gdbarch
, I386_EIP_REGNUM
);
2414 value
->kind
= axs_lvalue_memory
;
2418 /* Signal trampolines. */
2420 static struct i386_frame_cache
*
2421 i386_sigtramp_frame_cache (const frame_info_ptr
&this_frame
, void **this_cache
)
2423 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
2424 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
2425 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2426 struct i386_frame_cache
*cache
;
2431 return (struct i386_frame_cache
*) *this_cache
;
2433 cache
= i386_alloc_frame_cache ();
2437 get_frame_register (this_frame
, I386_ESP_REGNUM
, buf
);
2438 cache
->base
= extract_unsigned_integer (buf
, 4, byte_order
) - 4;
2440 addr
= tdep
->sigcontext_addr (this_frame
);
2441 if (tdep
->sc_reg_offset
)
2445 gdb_assert (tdep
->sc_num_regs
<= I386_NUM_SAVED_REGS
);
2447 for (i
= 0; i
< tdep
->sc_num_regs
; i
++)
2448 if (tdep
->sc_reg_offset
[i
] != -1)
2449 cache
->saved_regs
[i
] = addr
+ tdep
->sc_reg_offset
[i
];
2453 cache
->saved_regs
[I386_EIP_REGNUM
] = addr
+ tdep
->sc_pc_offset
;
2454 cache
->saved_regs
[I386_ESP_REGNUM
] = addr
+ tdep
->sc_sp_offset
;
2459 catch (const gdb_exception_error
&ex
)
2461 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
2465 *this_cache
= cache
;
2469 static enum unwind_stop_reason
2470 i386_sigtramp_frame_unwind_stop_reason (const frame_info_ptr
&this_frame
,
2473 struct i386_frame_cache
*cache
=
2474 i386_sigtramp_frame_cache (this_frame
, this_cache
);
2477 return UNWIND_UNAVAILABLE
;
2479 return UNWIND_NO_REASON
;
2483 i386_sigtramp_frame_this_id (const frame_info_ptr
&this_frame
, void **this_cache
,
2484 struct frame_id
*this_id
)
2486 struct i386_frame_cache
*cache
=
2487 i386_sigtramp_frame_cache (this_frame
, this_cache
);
2490 (*this_id
) = frame_id_build_unavailable_stack (get_frame_pc (this_frame
));
2493 /* See the end of i386_push_dummy_call. */
2494 (*this_id
) = frame_id_build (cache
->base
+ 8, get_frame_pc (this_frame
));
2498 static struct value
*
2499 i386_sigtramp_frame_prev_register (const frame_info_ptr
&this_frame
,
2500 void **this_cache
, int regnum
)
2502 /* Make sure we've initialized the cache. */
2503 i386_sigtramp_frame_cache (this_frame
, this_cache
);
2505 return i386_frame_prev_register (this_frame
, this_cache
, regnum
);
2509 i386_sigtramp_frame_sniffer (const struct frame_unwind
*self
,
2510 const frame_info_ptr
&this_frame
,
2511 void **this_prologue_cache
)
2513 gdbarch
*arch
= get_frame_arch (this_frame
);
2514 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (arch
);
2516 /* We shouldn't even bother if we don't have a sigcontext_addr
2518 if (tdep
->sigcontext_addr
== NULL
)
2521 if (tdep
->sigtramp_p
!= NULL
)
2523 if (tdep
->sigtramp_p (this_frame
))
2527 if (tdep
->sigtramp_start
!= 0)
2529 CORE_ADDR pc
= get_frame_pc (this_frame
);
2531 gdb_assert (tdep
->sigtramp_end
!= 0);
2532 if (pc
>= tdep
->sigtramp_start
&& pc
< tdep
->sigtramp_end
)
2539 static const struct frame_unwind i386_sigtramp_frame_unwind
=
2543 i386_sigtramp_frame_unwind_stop_reason
,
2544 i386_sigtramp_frame_this_id
,
2545 i386_sigtramp_frame_prev_register
,
2547 i386_sigtramp_frame_sniffer
2552 i386_frame_base_address (const frame_info_ptr
&this_frame
, void **this_cache
)
2554 struct i386_frame_cache
*cache
= i386_frame_cache (this_frame
, this_cache
);
2559 static const struct frame_base i386_frame_base
=
2562 i386_frame_base_address
,
2563 i386_frame_base_address
,
2564 i386_frame_base_address
2567 static struct frame_id
2568 i386_dummy_id (struct gdbarch
*gdbarch
, const frame_info_ptr
&this_frame
)
2572 fp
= get_frame_register_unsigned (this_frame
, I386_EBP_REGNUM
);
2574 /* See the end of i386_push_dummy_call. */
2575 return frame_id_build (fp
+ 8, get_frame_pc (this_frame
));
2578 /* _Decimal128 function return values need 16-byte alignment on the
2582 i386_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR sp
)
2584 return sp
& -(CORE_ADDR
)16;
2588 /* Figure out where the longjmp will land. Slurp the args out of the
2589 stack. We expect the first arg to be a pointer to the jmp_buf
2590 structure from which we extract the address that we will land at.
2591 This address is copied into PC. This routine returns non-zero on
2595 i386_get_longjmp_target (const frame_info_ptr
&frame
, CORE_ADDR
*pc
)
2598 CORE_ADDR sp
, jb_addr
;
2599 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2600 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2601 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
2602 int jb_pc_offset
= tdep
->jb_pc_offset
;
2604 /* If JB_PC_OFFSET is -1, we have no way to find out where the
2605 longjmp will land. */
2606 if (jb_pc_offset
== -1)
2609 get_frame_register (frame
, I386_ESP_REGNUM
, buf
);
2610 sp
= extract_unsigned_integer (buf
, 4, byte_order
);
2611 if (target_read_memory (sp
+ 4, buf
, 4))
2614 jb_addr
= extract_unsigned_integer (buf
, 4, byte_order
);
2615 if (target_read_memory (jb_addr
+ jb_pc_offset
, buf
, 4))
2618 *pc
= extract_unsigned_integer (buf
, 4, byte_order
);
2623 /* Check whether TYPE must be 16-byte-aligned when passed as a
2624 function argument. 16-byte vectors, _Decimal128 and structures or
2625 unions containing such types must be 16-byte-aligned; other
2626 arguments are 4-byte-aligned. */
2629 i386_16_byte_align_p (struct type
*type
)
2631 type
= check_typedef (type
);
2632 if ((type
->code () == TYPE_CODE_DECFLOAT
2633 || (type
->code () == TYPE_CODE_ARRAY
&& type
->is_vector ()))
2634 && type
->length () == 16)
2636 if (type
->code () == TYPE_CODE_ARRAY
)
2637 return i386_16_byte_align_p (type
->target_type ());
2638 if (type
->code () == TYPE_CODE_STRUCT
2639 || type
->code () == TYPE_CODE_UNION
)
2642 for (i
= 0; i
< type
->num_fields (); i
++)
2644 if (type
->field (i
).is_static ())
2646 if (i386_16_byte_align_p (type
->field (i
).type ()))
2653 /* Implementation for set_gdbarch_push_dummy_code. */
2656 i386_push_dummy_code (struct gdbarch
*gdbarch
, CORE_ADDR sp
, CORE_ADDR funaddr
,
2657 struct value
**args
, int nargs
, struct type
*value_type
,
2658 CORE_ADDR
*real_pc
, CORE_ADDR
*bp_addr
,
2659 struct regcache
*regcache
)
2661 /* Use 0xcc breakpoint - 1 byte. */
2665 /* Keep the stack aligned. */
2669 /* The "push_dummy_call" gdbarch method, optionally with the thiscall
2670 calling convention. */
2673 i386_thiscall_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
2674 struct regcache
*regcache
, CORE_ADDR bp_addr
,
2675 int nargs
, struct value
**args
, CORE_ADDR sp
,
2676 function_call_return_method return_method
,
2677 CORE_ADDR struct_addr
, bool thiscall
)
2679 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2685 /* Determine the total space required for arguments and struct
2686 return address in a first pass (allowing for 16-byte-aligned
2687 arguments), then push arguments in a second pass. */
2689 for (write_pass
= 0; write_pass
< 2; write_pass
++)
2691 int args_space_used
= 0;
2693 if (return_method
== return_method_struct
)
2697 /* Push value address. */
2698 store_unsigned_integer (buf
, 4, byte_order
, struct_addr
);
2699 write_memory (sp
, buf
, 4);
2700 args_space_used
+= 4;
2706 for (i
= thiscall
? 1 : 0; i
< nargs
; i
++)
2708 int len
= args
[i
]->enclosing_type ()->length ();
2712 if (i386_16_byte_align_p (args
[i
]->enclosing_type ()))
2713 args_space_used
= align_up (args_space_used
, 16);
2715 write_memory (sp
+ args_space_used
,
2716 args
[i
]->contents_all ().data (), len
);
2717 /* The System V ABI says that:
2719 "An argument's size is increased, if necessary, to make it a
2720 multiple of [32-bit] words. This may require tail padding,
2721 depending on the size of the argument."
2723 This makes sure the stack stays word-aligned. */
2724 args_space_used
+= align_up (len
, 4);
2728 if (i386_16_byte_align_p (args
[i
]->enclosing_type ()))
2729 args_space
= align_up (args_space
, 16);
2730 args_space
+= align_up (len
, 4);
2738 /* The original System V ABI only requires word alignment,
2739 but modern incarnations need 16-byte alignment in order
2740 to support SSE. Since wasting a few bytes here isn't
2741 harmful we unconditionally enforce 16-byte alignment. */
2746 /* Store return address. */
2748 store_unsigned_integer (buf
, 4, byte_order
, bp_addr
);
2749 write_memory (sp
, buf
, 4);
2751 /* Finally, update the stack pointer... */
2752 store_unsigned_integer (buf
, 4, byte_order
, sp
);
2753 regcache
->cooked_write (I386_ESP_REGNUM
, buf
);
2755 /* ...and fake a frame pointer. */
2756 regcache
->cooked_write (I386_EBP_REGNUM
, buf
);
2758 /* The 'this' pointer needs to be in ECX. */
2760 regcache
->cooked_write (I386_ECX_REGNUM
,
2761 args
[0]->contents_all ().data ());
2763 /* If the PLT is position-independent, the SYSTEM V ABI requires %ebx to be
2764 set to the address of the GOT when doing a call to a PLT address.
2765 Note that we do not try to determine whether the PLT is
2766 position-independent, we just set the register regardless. */
2767 CORE_ADDR func_addr
= find_function_addr (function
, nullptr, nullptr);
2768 if (in_plt_section (func_addr
))
2770 struct objfile
*objf
= nullptr;
2771 asection
*asect
= nullptr;
2772 obj_section
*osect
= nullptr;
2774 /* Get object file containing func_addr. */
2775 obj_section
*func_section
= find_pc_section (func_addr
);
2776 if (func_section
!= nullptr)
2777 objf
= func_section
->objfile
;
2779 if (objf
!= nullptr)
2781 /* Get corresponding .got.plt or .got section. */
2782 asect
= bfd_get_section_by_name (objf
->obfd
.get (), ".got.plt");
2783 if (asect
== nullptr)
2784 asect
= bfd_get_section_by_name (objf
->obfd
.get (), ".got");
2787 if (asect
!= nullptr)
2788 /* Translate asection to obj_section. */
2789 osect
= maint_obj_section_from_bfd_section (objf
->obfd
.get (),
2792 if (osect
!= nullptr)
2794 /* Store the section address in %ebx. */
2795 store_unsigned_integer (buf
, 4, byte_order
, osect
->addr ());
2796 regcache
->cooked_write (I386_EBX_REGNUM
, buf
);
2800 /* If we would only do this for a position-independent PLT, it would
2801 make sense to issue a warning here. */
2805 /* MarkK wrote: This "+ 8" is all over the place:
2806 (i386_frame_this_id, i386_sigtramp_frame_this_id,
2807 i386_dummy_id). It's there, since all frame unwinders for
2808 a given target have to agree (within a certain margin) on the
2809 definition of the stack address of a frame. Otherwise frame id
2810 comparison might not work correctly. Since DWARF2/GCC uses the
2811 stack address *before* the function call as a frame's CFA. On
2812 the i386, when %ebp is used as a frame pointer, the offset
2813 between the contents %ebp and the CFA as defined by GCC. */
2817 /* Implement the "push_dummy_call" gdbarch method. */
2820 i386_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
2821 struct regcache
*regcache
, CORE_ADDR bp_addr
, int nargs
,
2822 struct value
**args
, CORE_ADDR sp
,
2823 function_call_return_method return_method
,
2824 CORE_ADDR struct_addr
)
2826 return i386_thiscall_push_dummy_call (gdbarch
, function
, regcache
, bp_addr
,
2827 nargs
, args
, sp
, return_method
,
2828 struct_addr
, false);
2831 /* These registers are used for returning integers (and on some
2832 targets also for returning `struct' and `union' values when their
2833 size and alignment match an integer type). */
2834 #define LOW_RETURN_REGNUM I386_EAX_REGNUM /* %eax */
2835 #define HIGH_RETURN_REGNUM I386_EDX_REGNUM /* %edx */
2837 /* Read, for architecture GDBARCH, a function return value of TYPE
2838 from REGCACHE, and copy that into VALBUF. */
2841 i386_extract_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
2842 struct regcache
*regcache
, gdb_byte
*valbuf
)
2844 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
2845 int len
= type
->length ();
2846 gdb_byte buf
[I386_MAX_REGISTER_SIZE
];
2848 /* _Float16 and _Float16 _Complex values are returned via xmm0. */
2849 if (((type
->code () == TYPE_CODE_FLT
) && len
== 2)
2850 || ((type
->code () == TYPE_CODE_COMPLEX
) && len
== 4))
2852 regcache
->raw_read (I387_XMM0_REGNUM (tdep
), valbuf
);
2855 else if (type
->code () == TYPE_CODE_FLT
)
2857 if (tdep
->st0_regnum
< 0)
2859 warning (_("Cannot find floating-point return value."));
2860 memset (valbuf
, 0, len
);
2864 /* Floating-point return values can be found in %st(0). Convert
2865 its contents to the desired type. This is probably not
2866 exactly how it would happen on the target itself, but it is
2867 the best we can do. */
2868 regcache
->raw_read (I386_ST0_REGNUM
, buf
);
2869 target_float_convert (buf
, i387_ext_type (gdbarch
), valbuf
, type
);
2873 int low_size
= register_size (gdbarch
, LOW_RETURN_REGNUM
);
2874 int high_size
= register_size (gdbarch
, HIGH_RETURN_REGNUM
);
2876 if (len
<= low_size
)
2878 regcache
->raw_read (LOW_RETURN_REGNUM
, buf
);
2879 memcpy (valbuf
, buf
, len
);
2881 else if (len
<= (low_size
+ high_size
))
2883 regcache
->raw_read (LOW_RETURN_REGNUM
, buf
);
2884 memcpy (valbuf
, buf
, low_size
);
2885 regcache
->raw_read (HIGH_RETURN_REGNUM
, buf
);
2886 memcpy (valbuf
+ low_size
, buf
, len
- low_size
);
2889 internal_error (_("Cannot extract return value of %d bytes long."),
2894 /* Write, for architecture GDBARCH, a function return value of TYPE
2895 from VALBUF into REGCACHE. */
2898 i386_store_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
2899 struct regcache
*regcache
, const gdb_byte
*valbuf
)
2901 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
2902 int len
= type
->length ();
2904 if (type
->code () == TYPE_CODE_FLT
)
2907 gdb_byte buf
[I386_MAX_REGISTER_SIZE
];
2909 if (tdep
->st0_regnum
< 0)
2911 warning (_("Cannot set floating-point return value."));
2915 /* Returning floating-point values is a bit tricky. Apart from
2916 storing the return value in %st(0), we have to simulate the
2917 state of the FPU at function return point. */
2919 /* Convert the value found in VALBUF to the extended
2920 floating-point format used by the FPU. This is probably
2921 not exactly how it would happen on the target itself, but
2922 it is the best we can do. */
2923 target_float_convert (valbuf
, type
, buf
, i387_ext_type (gdbarch
));
2924 regcache
->raw_write (I386_ST0_REGNUM
, buf
);
2926 /* Set the top of the floating-point register stack to 7. The
2927 actual value doesn't really matter, but 7 is what a normal
2928 function return would end up with if the program started out
2929 with a freshly initialized FPU. */
2930 regcache_raw_read_unsigned (regcache
, I387_FSTAT_REGNUM (tdep
), &fstat
);
2932 regcache_raw_write_unsigned (regcache
, I387_FSTAT_REGNUM (tdep
), fstat
);
2934 /* Mark %st(1) through %st(7) as empty. Since we set the top of
2935 the floating-point register stack to 7, the appropriate value
2936 for the tag word is 0x3fff. */
2937 regcache_raw_write_unsigned (regcache
, I387_FTAG_REGNUM (tdep
), 0x3fff);
2941 int low_size
= register_size (gdbarch
, LOW_RETURN_REGNUM
);
2942 int high_size
= register_size (gdbarch
, HIGH_RETURN_REGNUM
);
2944 if (len
<= low_size
)
2945 regcache
->raw_write_part (LOW_RETURN_REGNUM
, 0, len
, valbuf
);
2946 else if (len
<= (low_size
+ high_size
))
2948 regcache
->raw_write (LOW_RETURN_REGNUM
, valbuf
);
2949 regcache
->raw_write_part (HIGH_RETURN_REGNUM
, 0, len
- low_size
,
2953 internal_error (_("Cannot store return value of %d bytes long."), len
);
2958 /* This is the variable that is set with "set struct-convention", and
2959 its legitimate values. */
2960 static const char default_struct_convention
[] = "default";
2961 static const char pcc_struct_convention
[] = "pcc";
2962 static const char reg_struct_convention
[] = "reg";
2963 static const char *const valid_conventions
[] =
2965 default_struct_convention
,
2966 pcc_struct_convention
,
2967 reg_struct_convention
,
2970 static const char *struct_convention
= default_struct_convention
;
2972 /* Return non-zero if TYPE, which is assumed to be a structure,
2973 a union type, or an array type, should be returned in registers
2974 for architecture GDBARCH. */
2977 i386_reg_struct_return_p (struct gdbarch
*gdbarch
, struct type
*type
)
2979 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
2980 enum type_code code
= type
->code ();
2981 int len
= type
->length ();
2983 gdb_assert (code
== TYPE_CODE_STRUCT
2984 || code
== TYPE_CODE_UNION
2985 || code
== TYPE_CODE_ARRAY
);
2987 if (struct_convention
== pcc_struct_convention
2988 || (struct_convention
== default_struct_convention
2989 && tdep
->struct_return
== pcc_struct_return
)
2990 || TYPE_HAS_DYNAMIC_LENGTH (type
))
2993 /* Structures consisting of a single `float', `double' or 'long
2994 double' member are returned in %st(0). */
2995 if (code
== TYPE_CODE_STRUCT
&& type
->num_fields () == 1)
2997 type
= check_typedef (type
->field (0).type ());
2998 if (type
->code () == TYPE_CODE_FLT
)
2999 return (len
== 4 || len
== 8 || len
== 12);
3002 return (len
== 1 || len
== 2 || len
== 4 || len
== 8);
3005 /* Determine, for architecture GDBARCH, how a return value of TYPE
3006 should be returned. If it is supposed to be returned in registers,
3007 and READBUF is non-zero, read the appropriate value from REGCACHE,
3008 and copy it into READBUF. If WRITEBUF is non-zero, write the value
3009 from WRITEBUF into REGCACHE. */
3011 static enum return_value_convention
3012 i386_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
3013 struct type
*type
, struct regcache
*regcache
,
3014 struct value
**read_value
, const gdb_byte
*writebuf
)
3016 enum type_code code
= type
->code ();
3018 if (((code
== TYPE_CODE_STRUCT
3019 || code
== TYPE_CODE_UNION
3020 || code
== TYPE_CODE_ARRAY
)
3021 && !i386_reg_struct_return_p (gdbarch
, type
))
3022 /* Complex double and long double uses the struct return convention. */
3023 || (code
== TYPE_CODE_COMPLEX
&& type
->length () == 16)
3024 || (code
== TYPE_CODE_COMPLEX
&& type
->length () == 24)
3025 /* 128-bit decimal float uses the struct return convention. */
3026 || (code
== TYPE_CODE_DECFLOAT
&& type
->length () == 16))
3028 /* The System V ABI says that:
3030 "A function that returns a structure or union also sets %eax
3031 to the value of the original address of the caller's area
3032 before it returns. Thus when the caller receives control
3033 again, the address of the returned object resides in register
3034 %eax and can be used to access the object."
3036 So the ABI guarantees that we can always find the return
3037 value just after the function has returned. */
3039 /* Note that the ABI doesn't mention functions returning arrays,
3040 which is something possible in certain languages such as Ada.
3041 In this case, the value is returned as if it was wrapped in
3042 a record, so the convention applied to records also applies
3045 if (read_value
!= nullptr)
3049 regcache_raw_read_unsigned (regcache
, I386_EAX_REGNUM
, &addr
);
3050 *read_value
= value_at_non_lval (type
, addr
);
3053 return RETURN_VALUE_ABI_RETURNS_ADDRESS
;
3056 /* This special case is for structures consisting of a single
3057 `float', `double' or 'long double' member. These structures are
3058 returned in %st(0). For these structures, we call ourselves
3059 recursively, changing TYPE into the type of the first member of
3060 the structure. Since that should work for all structures that
3061 have only one member, we don't bother to check the member's type
3063 if (code
== TYPE_CODE_STRUCT
&& type
->num_fields () == 1)
3065 struct type
*inner_type
= check_typedef (type
->field (0).type ());
3066 enum return_value_convention result
3067 = i386_return_value (gdbarch
, function
, inner_type
, regcache
,
3068 read_value
, writebuf
);
3069 if (read_value
!= nullptr)
3070 (*read_value
)->deprecated_set_type (type
);
3074 if (read_value
!= nullptr)
3076 *read_value
= value::allocate (type
);
3077 i386_extract_return_value (gdbarch
, type
, regcache
,
3078 (*read_value
)->contents_raw ().data ());
3081 i386_store_return_value (gdbarch
, type
, regcache
, writebuf
);
3083 return RETURN_VALUE_REGISTER_CONVENTION
;
3088 i387_ext_type (struct gdbarch
*gdbarch
)
3090 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
3092 if (!tdep
->i387_ext_type
)
3094 tdep
->i387_ext_type
= tdesc_find_type (gdbarch
, "i387_ext");
3095 gdb_assert (tdep
->i387_ext_type
!= NULL
);
3098 return tdep
->i387_ext_type
;
3101 /* Construct vector type for pseudo ZMM registers. We can't use
3102 tdesc_find_type since ZMM isn't described in target description. */
3104 static struct type
*
3105 i386_zmm_type (struct gdbarch
*gdbarch
)
3107 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
3109 if (!tdep
->i386_zmm_type
)
3111 const struct builtin_type
*bt
= builtin_type (gdbarch
);
3113 /* The type we're building is this: */
3115 union __gdb_builtin_type_vec512i
3117 int128_t v4_int128
[4];
3118 int64_t v8_int64
[8];
3119 int32_t v16_int32
[16];
3120 int16_t v32_int16
[32];
3121 int8_t v64_int8
[64];
3122 double v8_double
[8];
3123 float v16_float
[16];
3124 float16_t v32_half
[32];
3125 bfloat16_t v32_bfloat16
[32];
3131 t
= arch_composite_type (gdbarch
,
3132 "__gdb_builtin_type_vec512i", TYPE_CODE_UNION
);
3133 append_composite_type_field (t
, "v32_bfloat16",
3134 init_vector_type (bt
->builtin_bfloat16
, 32));
3135 append_composite_type_field (t
, "v32_half",
3136 init_vector_type (bt
->builtin_half
, 32));
3137 append_composite_type_field (t
, "v16_float",
3138 init_vector_type (bt
->builtin_float
, 16));
3139 append_composite_type_field (t
, "v8_double",
3140 init_vector_type (bt
->builtin_double
, 8));
3141 append_composite_type_field (t
, "v64_int8",
3142 init_vector_type (bt
->builtin_int8
, 64));
3143 append_composite_type_field (t
, "v32_int16",
3144 init_vector_type (bt
->builtin_int16
, 32));
3145 append_composite_type_field (t
, "v16_int32",
3146 init_vector_type (bt
->builtin_int32
, 16));
3147 append_composite_type_field (t
, "v8_int64",
3148 init_vector_type (bt
->builtin_int64
, 8));
3149 append_composite_type_field (t
, "v4_int128",
3150 init_vector_type (bt
->builtin_int128
, 4));
3152 t
->set_is_vector (true);
3153 t
->set_name ("builtin_type_vec512i");
3154 tdep
->i386_zmm_type
= t
;
3157 return tdep
->i386_zmm_type
;
3160 /* Construct vector type for pseudo YMM registers. We can't use
3161 tdesc_find_type since YMM isn't described in target description. */
3163 static struct type
*
3164 i386_ymm_type (struct gdbarch
*gdbarch
)
3166 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
3168 if (!tdep
->i386_ymm_type
)
3170 const struct builtin_type
*bt
= builtin_type (gdbarch
);
3172 /* The type we're building is this: */
3174 union __gdb_builtin_type_vec256i
3176 int128_t v2_int128
[2];
3177 int64_t v4_int64
[4];
3178 int32_t v8_int32
[8];
3179 int16_t v16_int16
[16];
3180 int8_t v32_int8
[32];
3181 double v4_double
[4];
3183 float16_t v16_half
[16];
3184 bfloat16_t v16_bfloat16
[16];
3190 t
= arch_composite_type (gdbarch
,
3191 "__gdb_builtin_type_vec256i", TYPE_CODE_UNION
);
3192 append_composite_type_field (t
, "v16_bfloat16",
3193 init_vector_type (bt
->builtin_bfloat16
, 16));
3194 append_composite_type_field (t
, "v16_half",
3195 init_vector_type (bt
->builtin_half
, 16));
3196 append_composite_type_field (t
, "v8_float",
3197 init_vector_type (bt
->builtin_float
, 8));
3198 append_composite_type_field (t
, "v4_double",
3199 init_vector_type (bt
->builtin_double
, 4));
3200 append_composite_type_field (t
, "v32_int8",
3201 init_vector_type (bt
->builtin_int8
, 32));
3202 append_composite_type_field (t
, "v16_int16",
3203 init_vector_type (bt
->builtin_int16
, 16));
3204 append_composite_type_field (t
, "v8_int32",
3205 init_vector_type (bt
->builtin_int32
, 8));
3206 append_composite_type_field (t
, "v4_int64",
3207 init_vector_type (bt
->builtin_int64
, 4));
3208 append_composite_type_field (t
, "v2_int128",
3209 init_vector_type (bt
->builtin_int128
, 2));
3211 t
->set_is_vector (true);
3212 t
->set_name ("builtin_type_vec256i");
3213 tdep
->i386_ymm_type
= t
;
3216 return tdep
->i386_ymm_type
;
3219 /* Construct vector type for MMX registers. */
3220 static struct type
*
3221 i386_mmx_type (struct gdbarch
*gdbarch
)
3223 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
3225 if (!tdep
->i386_mmx_type
)
3227 const struct builtin_type
*bt
= builtin_type (gdbarch
);
3229 /* The type we're building is this: */
3231 union __gdb_builtin_type_vec64i
3234 int32_t v2_int32
[2];
3235 int16_t v4_int16
[4];
3242 t
= arch_composite_type (gdbarch
,
3243 "__gdb_builtin_type_vec64i", TYPE_CODE_UNION
);
3245 append_composite_type_field (t
, "uint64", bt
->builtin_int64
);
3246 append_composite_type_field (t
, "v2_int32",
3247 init_vector_type (bt
->builtin_int32
, 2));
3248 append_composite_type_field (t
, "v4_int16",
3249 init_vector_type (bt
->builtin_int16
, 4));
3250 append_composite_type_field (t
, "v8_int8",
3251 init_vector_type (bt
->builtin_int8
, 8));
3253 t
->set_is_vector (true);
3254 t
->set_name ("builtin_type_vec64i");
3255 tdep
->i386_mmx_type
= t
;
3258 return tdep
->i386_mmx_type
;
3261 /* Return the GDB type object for the "standard" data type of data in
3265 i386_pseudo_register_type (struct gdbarch
*gdbarch
, int regnum
)
3267 if (i386_mmx_regnum_p (gdbarch
, regnum
))
3268 return i386_mmx_type (gdbarch
);
3269 else if (i386_ymm_regnum_p (gdbarch
, regnum
))
3270 return i386_ymm_type (gdbarch
);
3271 else if (i386_ymm_avx512_regnum_p (gdbarch
, regnum
))
3272 return i386_ymm_type (gdbarch
);
3273 else if (i386_zmm_regnum_p (gdbarch
, regnum
))
3274 return i386_zmm_type (gdbarch
);
3277 const struct builtin_type
*bt
= builtin_type (gdbarch
);
3278 if (i386_byte_regnum_p (gdbarch
, regnum
))
3279 return bt
->builtin_int8
;
3280 else if (i386_word_regnum_p (gdbarch
, regnum
))
3281 return bt
->builtin_int16
;
3282 else if (i386_dword_regnum_p (gdbarch
, regnum
))
3283 return bt
->builtin_int32
;
3284 else if (i386_k_regnum_p (gdbarch
, regnum
))
3285 return bt
->builtin_int64
;
3288 internal_error (_("invalid regnum"));
3291 /* Map a cooked register onto a raw register or memory. For the i386,
3292 the MMX registers need to be mapped onto floating point registers. */
3295 i386_mmx_regnum_to_fp_regnum (const frame_info_ptr
&next_frame
, int regnum
)
3297 gdbarch
*arch
= frame_unwind_arch (next_frame
);
3298 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (arch
);
3300 = frame_unwind_register_unsigned (next_frame
, I387_FSTAT_REGNUM (tdep
));
3301 int tos
= (fstat
>> 11) & 0x7;
3302 int mmxreg
= regnum
- tdep
->mm0_regnum
;
3303 int fpreg
= (mmxreg
+ tos
) % 8;
3305 return (I387_ST0_REGNUM (tdep
) + fpreg
);
3308 /* A helper function for us by i386_pseudo_register_read_value and
3309 amd64_pseudo_register_read_value. It does all the work but reads
3310 the data into an already-allocated value. */
3313 i386_pseudo_register_read_value (gdbarch
*gdbarch
, const frame_info_ptr
&next_frame
,
3314 const int pseudo_reg_num
)
3316 if (i386_mmx_regnum_p (gdbarch
, pseudo_reg_num
))
3318 int fpnum
= i386_mmx_regnum_to_fp_regnum (next_frame
, pseudo_reg_num
);
3320 /* Extract (always little endian). */
3321 return pseudo_from_raw_part (next_frame
, pseudo_reg_num
, fpnum
, 0);
3325 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
3326 if (i386_zmm_regnum_p (gdbarch
, pseudo_reg_num
))
3328 /* Which register is it, relative to zmm0. */
3329 int i_0
= pseudo_reg_num
- tdep
->zmm0_regnum
;
3331 if (i_0
< num_lower_zmm_regs
)
3332 return pseudo_from_concat_raw (next_frame
, pseudo_reg_num
,
3333 I387_XMM0_REGNUM (tdep
) + i_0
,
3334 tdep
->ymm0h_regnum
+ i_0
,
3335 tdep
->zmm0h_regnum
+ i_0
);
3338 /* Which register is it, relative to zmm16. */
3339 int i_16
= i_0
- num_lower_zmm_regs
;
3341 return pseudo_from_concat_raw (next_frame
, pseudo_reg_num
,
3342 I387_XMM16_REGNUM (tdep
) + i_16
,
3343 I387_YMM16H_REGNUM (tdep
) + i_16
,
3344 tdep
->zmm0h_regnum
+ i_0
);
3347 else if (i386_ymm_regnum_p (gdbarch
, pseudo_reg_num
))
3349 int i
= pseudo_reg_num
- tdep
->ymm0_regnum
;
3351 return pseudo_from_concat_raw (next_frame
, pseudo_reg_num
,
3352 I387_XMM0_REGNUM (tdep
) + i
,
3353 tdep
->ymm0h_regnum
+ i
);
3355 else if (i386_ymm_avx512_regnum_p (gdbarch
, pseudo_reg_num
))
3357 int i
= pseudo_reg_num
- tdep
->ymm16_regnum
;
3359 return pseudo_from_concat_raw (next_frame
, pseudo_reg_num
,
3360 I387_XMM16_REGNUM (tdep
) + i
,
3361 tdep
->ymm16h_regnum
+ i
);
3363 else if (i386_word_regnum_p (gdbarch
, pseudo_reg_num
))
3365 int gpnum
= pseudo_reg_num
- tdep
->ax_regnum
;
3367 /* Extract (always little endian). */
3368 return pseudo_from_raw_part (next_frame
, pseudo_reg_num
, gpnum
, 0);
3370 else if (i386_byte_regnum_p (gdbarch
, pseudo_reg_num
))
3372 int gpnum
= pseudo_reg_num
- tdep
->al_regnum
;
3374 /* Extract (always little endian). We read both lower and
3376 return pseudo_from_raw_part (next_frame
, pseudo_reg_num
, gpnum
% 4,
3377 gpnum
>= 4 ? 1 : 0);
3380 internal_error (_("invalid regnum"));
3385 i386_pseudo_register_write (gdbarch
*gdbarch
, const frame_info_ptr
&next_frame
,
3386 const int pseudo_reg_num
,
3387 gdb::array_view
<const gdb_byte
> buf
)
3389 if (i386_mmx_regnum_p (gdbarch
, pseudo_reg_num
))
3391 int fpnum
= i386_mmx_regnum_to_fp_regnum (next_frame
, pseudo_reg_num
);
3393 pseudo_to_raw_part (next_frame
, buf
, fpnum
, 0);
3397 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
3399 if (i386_zmm_regnum_p (gdbarch
, pseudo_reg_num
))
3401 /* Which register is it, relative to zmm0. */
3402 int reg_index_0
= pseudo_reg_num
- tdep
->zmm0_regnum
;
3404 if (reg_index_0
< num_lower_zmm_regs
)
3405 pseudo_to_concat_raw (next_frame
, buf
,
3406 I387_XMM0_REGNUM (tdep
) + reg_index_0
,
3407 I387_YMM0_REGNUM (tdep
) + reg_index_0
,
3408 tdep
->zmm0h_regnum
+ reg_index_0
);
3411 /* Which register is it, relative to zmm16. */
3412 int reg_index_16
= reg_index_0
- num_lower_zmm_regs
;
3414 pseudo_to_concat_raw (next_frame
, buf
,
3415 I387_XMM16_REGNUM (tdep
) + reg_index_16
,
3416 I387_YMM16H_REGNUM (tdep
) + reg_index_16
,
3417 tdep
->zmm0h_regnum
+ +reg_index_0
);
3420 else if (i386_ymm_regnum_p (gdbarch
, pseudo_reg_num
))
3422 int i
= pseudo_reg_num
- tdep
->ymm0_regnum
;
3424 pseudo_to_concat_raw (next_frame
, buf
, I387_XMM0_REGNUM (tdep
) + i
,
3425 tdep
->ymm0h_regnum
+ i
);
3427 else if (i386_ymm_avx512_regnum_p (gdbarch
, pseudo_reg_num
))
3429 int i
= pseudo_reg_num
- tdep
->ymm16_regnum
;
3431 pseudo_to_concat_raw (next_frame
, buf
, I387_XMM16_REGNUM (tdep
) + i
,
3432 tdep
->ymm16h_regnum
+ i
);
3434 else if (i386_word_regnum_p (gdbarch
, pseudo_reg_num
))
3436 int gpnum
= pseudo_reg_num
- tdep
->ax_regnum
;
3438 pseudo_to_raw_part (next_frame
, buf
, gpnum
, 0);
3440 else if (i386_byte_regnum_p (gdbarch
, pseudo_reg_num
))
3442 int gpnum
= pseudo_reg_num
- tdep
->al_regnum
;
3444 pseudo_to_raw_part (next_frame
, buf
, gpnum
% 4, gpnum
>= 4 ? 1 : 0);
3447 internal_error (_("invalid regnum"));
3451 /* Implement the 'ax_pseudo_register_collect' gdbarch method. */
3454 i386_ax_pseudo_register_collect (struct gdbarch
*gdbarch
,
3455 struct agent_expr
*ax
, int regnum
)
3457 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
3459 if (i386_mmx_regnum_p (gdbarch
, regnum
))
3461 /* MMX to FPU register mapping depends on current TOS. Let's just
3462 not care and collect everything... */
3465 ax_reg_mask (ax
, I387_FSTAT_REGNUM (tdep
));
3466 for (i
= 0; i
< 8; i
++)
3467 ax_reg_mask (ax
, I387_ST0_REGNUM (tdep
) + i
);
3470 else if (i386_zmm_regnum_p (gdbarch
, regnum
))
3472 regnum
-= tdep
->zmm0_regnum
;
3473 if (regnum
< num_lower_zmm_regs
)
3475 ax_reg_mask (ax
, I387_XMM0_REGNUM (tdep
) + regnum
);
3476 ax_reg_mask (ax
, tdep
->ymm0h_regnum
+ regnum
);
3480 ax_reg_mask (ax
, I387_XMM16_REGNUM (tdep
) + regnum
3481 - num_lower_zmm_regs
);
3482 ax_reg_mask (ax
, I387_YMM16H_REGNUM (tdep
) + regnum
3483 - num_lower_zmm_regs
);
3485 ax_reg_mask (ax
, tdep
->zmm0h_regnum
+ regnum
);
3488 else if (i386_ymm_regnum_p (gdbarch
, regnum
))
3490 regnum
-= tdep
->ymm0_regnum
;
3491 ax_reg_mask (ax
, I387_XMM0_REGNUM (tdep
) + regnum
);
3492 ax_reg_mask (ax
, tdep
->ymm0h_regnum
+ regnum
);
3495 else if (i386_ymm_avx512_regnum_p (gdbarch
, regnum
))
3497 regnum
-= tdep
->ymm16_regnum
;
3498 ax_reg_mask (ax
, I387_XMM16_REGNUM (tdep
) + regnum
);
3499 ax_reg_mask (ax
, tdep
->ymm16h_regnum
+ regnum
);
3502 else if (i386_word_regnum_p (gdbarch
, regnum
))
3504 int gpnum
= regnum
- tdep
->ax_regnum
;
3506 ax_reg_mask (ax
, gpnum
);
3509 else if (i386_byte_regnum_p (gdbarch
, regnum
))
3511 int gpnum
= regnum
- tdep
->al_regnum
;
3513 ax_reg_mask (ax
, gpnum
% 4);
3517 internal_error (_("invalid regnum"));
3522 /* Return the register number of the register allocated by GCC after
3523 REGNUM, or -1 if there is no such register. */
3526 i386_next_regnum (int regnum
)
3528 /* GCC allocates the registers in the order:
3530 %eax, %edx, %ecx, %ebx, %esi, %edi, %ebp, %esp, ...
3532 Since storing a variable in %esp doesn't make any sense we return
3533 -1 for %ebp and for %esp itself. */
3534 static int next_regnum
[] =
3536 I386_EDX_REGNUM
, /* Slot for %eax. */
3537 I386_EBX_REGNUM
, /* Slot for %ecx. */
3538 I386_ECX_REGNUM
, /* Slot for %edx. */
3539 I386_ESI_REGNUM
, /* Slot for %ebx. */
3540 -1, -1, /* Slots for %esp and %ebp. */
3541 I386_EDI_REGNUM
, /* Slot for %esi. */
3542 I386_EBP_REGNUM
/* Slot for %edi. */
3545 if (regnum
>= 0 && regnum
< sizeof (next_regnum
) / sizeof (next_regnum
[0]))
3546 return next_regnum
[regnum
];
3551 /* Return nonzero if a value of type TYPE stored in register REGNUM
3552 needs any special handling. */
3555 i386_convert_register_p (struct gdbarch
*gdbarch
,
3556 int regnum
, struct type
*type
)
3558 int len
= type
->length ();
3560 /* Values may be spread across multiple registers. Most debugging
3561 formats aren't expressive enough to specify the locations, so
3562 some heuristics is involved. Right now we only handle types that
3563 have a length that is a multiple of the word size, since GCC
3564 doesn't seem to put any other types into registers. */
3565 if (len
> 4 && len
% 4 == 0)
3567 int last_regnum
= regnum
;
3571 last_regnum
= i386_next_regnum (last_regnum
);
3575 if (last_regnum
!= -1)
3579 return i387_convert_register_p (gdbarch
, regnum
, type
);
3582 /* Read a value of type TYPE from register REGNUM in frame FRAME, and
3583 return its contents in TO. */
3586 i386_register_to_value (const frame_info_ptr
&frame
, int regnum
,
3587 struct type
*type
, gdb_byte
*to
,
3588 int *optimizedp
, int *unavailablep
)
3590 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
3591 int len
= type
->length ();
3593 if (i386_fp_regnum_p (gdbarch
, regnum
))
3594 return i387_register_to_value (frame
, regnum
, type
, to
,
3595 optimizedp
, unavailablep
);
3597 /* Read a value spread across multiple registers. */
3599 gdb_assert (len
> 4 && len
% 4 == 0);
3603 gdb_assert (regnum
!= -1);
3604 gdb_assert (register_size (gdbarch
, regnum
) == 4);
3607 = gdb::make_array_view (to
, register_size (gdbarch
, regnum
));
3608 frame_info_ptr next_frame
= get_next_frame_sentinel_okay (frame
);
3609 if (!get_frame_register_bytes (next_frame
, regnum
, 0, to_view
,
3610 optimizedp
, unavailablep
))
3613 regnum
= i386_next_regnum (regnum
);
3618 *optimizedp
= *unavailablep
= 0;
3622 /* Write the contents FROM of a value of type TYPE into register
3623 REGNUM in frame FRAME. */
3626 i386_value_to_register (const frame_info_ptr
&frame
, int regnum
,
3627 struct type
*type
, const gdb_byte
*from
)
3629 int len
= type
->length ();
3631 if (i386_fp_regnum_p (get_frame_arch (frame
), regnum
))
3633 i387_value_to_register (frame
, regnum
, type
, from
);
3637 /* Write a value spread across multiple registers. */
3639 gdb_assert (len
> 4 && len
% 4 == 0);
3643 gdb_assert (regnum
!= -1);
3644 gdb_assert (register_size (get_frame_arch (frame
), regnum
) == 4);
3646 auto from_view
= gdb::make_array_view (from
, 4);
3647 put_frame_register (get_next_frame_sentinel_okay (frame
), regnum
,
3649 regnum
= i386_next_regnum (regnum
);
3655 /* Supply register REGNUM from the buffer specified by GREGS and LEN
3656 in the general-purpose register set REGSET to register cache
3657 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
3660 i386_supply_gregset (const struct regset
*regset
, struct regcache
*regcache
,
3661 int regnum
, const void *gregs
, size_t len
)
3663 struct gdbarch
*gdbarch
= regcache
->arch ();
3664 const i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
3665 const gdb_byte
*regs
= (const gdb_byte
*) gregs
;
3668 gdb_assert (len
>= tdep
->sizeof_gregset
);
3670 for (i
= 0; i
< tdep
->gregset_num_regs
; i
++)
3672 if ((regnum
== i
|| regnum
== -1)
3673 && tdep
->gregset_reg_offset
[i
] != -1)
3674 regcache
->raw_supply (i
, regs
+ tdep
->gregset_reg_offset
[i
]);
3678 /* Collect register REGNUM from the register cache REGCACHE and store
3679 it in the buffer specified by GREGS and LEN as described by the
3680 general-purpose register set REGSET. If REGNUM is -1, do this for
3681 all registers in REGSET. */
3684 i386_collect_gregset (const struct regset
*regset
,
3685 const struct regcache
*regcache
,
3686 int regnum
, void *gregs
, size_t len
)
3688 struct gdbarch
*gdbarch
= regcache
->arch ();
3689 const i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
3690 gdb_byte
*regs
= (gdb_byte
*) gregs
;
3693 gdb_assert (len
>= tdep
->sizeof_gregset
);
3695 for (i
= 0; i
< tdep
->gregset_num_regs
; i
++)
3697 if ((regnum
== i
|| regnum
== -1)
3698 && tdep
->gregset_reg_offset
[i
] != -1)
3699 regcache
->raw_collect (i
, regs
+ tdep
->gregset_reg_offset
[i
]);
3703 /* Supply register REGNUM from the buffer specified by FPREGS and LEN
3704 in the floating-point register set REGSET to register cache
3705 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
3708 i386_supply_fpregset (const struct regset
*regset
, struct regcache
*regcache
,
3709 int regnum
, const void *fpregs
, size_t len
)
3711 struct gdbarch
*gdbarch
= regcache
->arch ();
3712 const i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
3714 if (len
== I387_SIZEOF_FXSAVE
)
3716 i387_supply_fxsave (regcache
, regnum
, fpregs
);
3720 gdb_assert (len
>= tdep
->sizeof_fpregset
);
3721 i387_supply_fsave (regcache
, regnum
, fpregs
);
3724 /* Collect register REGNUM from the register cache REGCACHE and store
3725 it in the buffer specified by FPREGS and LEN as described by the
3726 floating-point register set REGSET. If REGNUM is -1, do this for
3727 all registers in REGSET. */
3730 i386_collect_fpregset (const struct regset
*regset
,
3731 const struct regcache
*regcache
,
3732 int regnum
, void *fpregs
, size_t len
)
3734 struct gdbarch
*gdbarch
= regcache
->arch ();
3735 const i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
3737 if (len
== I387_SIZEOF_FXSAVE
)
3739 i387_collect_fxsave (regcache
, regnum
, fpregs
);
3743 gdb_assert (len
>= tdep
->sizeof_fpregset
);
3744 i387_collect_fsave (regcache
, regnum
, fpregs
);
3747 /* Register set definitions. */
3749 const struct regset i386_gregset
=
3751 NULL
, i386_supply_gregset
, i386_collect_gregset
3754 const struct regset i386_fpregset
=
3756 NULL
, i386_supply_fpregset
, i386_collect_fpregset
3759 /* Default iterator over core file register note sections. */
3762 i386_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
3763 iterate_over_regset_sections_cb
*cb
,
3765 const struct regcache
*regcache
)
3767 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
3769 cb (".reg", tdep
->sizeof_gregset
, tdep
->sizeof_gregset
, &i386_gregset
, NULL
,
3771 if (tdep
->sizeof_fpregset
)
3772 cb (".reg2", tdep
->sizeof_fpregset
, tdep
->sizeof_fpregset
, tdep
->fpregset
,
3777 /* Stuff for WIN32 PE style DLL's but is pretty generic really. */
3780 i386_pe_skip_trampoline_code (const frame_info_ptr
&frame
,
3781 CORE_ADDR pc
, char *name
)
3783 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
3784 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3787 if (pc
&& read_memory_unsigned_integer (pc
, 2, byte_order
) == 0x25ff)
3789 unsigned long indirect
=
3790 read_memory_unsigned_integer (pc
+ 2, 4, byte_order
);
3791 struct minimal_symbol
*indsym
=
3792 indirect
? lookup_minimal_symbol_by_pc (indirect
).minsym
: 0;
3793 const char *symname
= indsym
? indsym
->linkage_name () : 0;
3797 if (startswith (symname
, "__imp_")
3798 || startswith (symname
, "_imp_"))
3800 read_memory_unsigned_integer (indirect
, 4, byte_order
);
3803 return 0; /* Not a trampoline. */
3807 /* Return whether the THIS_FRAME corresponds to a sigtramp
3811 i386_sigtramp_p (const frame_info_ptr
&this_frame
)
3813 CORE_ADDR pc
= get_frame_pc (this_frame
);
3816 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
3817 return (name
&& strcmp ("_sigtramp", name
) == 0);
3821 /* We have two flavours of disassembly. The machinery on this page
3822 deals with switching between those. */
3825 i386_print_insn (bfd_vma pc
, struct disassemble_info
*info
)
3827 gdb_assert (disassembly_flavor
== att_flavor
3828 || disassembly_flavor
== intel_flavor
);
3830 info
->disassembler_options
= disassembly_flavor
;
3832 return default_print_insn (pc
, info
);
3836 /* There are a few i386 architecture variants that differ only
3837 slightly from the generic i386 target. For now, we don't give them
3838 their own source file, but include them here. As a consequence,
3839 they'll always be included. */
3841 /* System V Release 4 (SVR4). */
3843 /* Return whether THIS_FRAME corresponds to a SVR4 sigtramp
3847 i386_svr4_sigtramp_p (const frame_info_ptr
&this_frame
)
3849 CORE_ADDR pc
= get_frame_pc (this_frame
);
3852 /* The origin of these symbols is currently unknown. */
3853 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
3854 return (name
&& (strcmp ("_sigreturn", name
) == 0
3855 || strcmp ("sigvechandler", name
) == 0));
3858 /* Assuming THIS_FRAME is for a SVR4 sigtramp routine, return the
3859 address of the associated sigcontext (ucontext) structure. */
3862 i386_svr4_sigcontext_addr (const frame_info_ptr
&this_frame
)
3864 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
3865 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3869 get_frame_register (this_frame
, I386_ESP_REGNUM
, buf
);
3870 sp
= extract_unsigned_integer (buf
, 4, byte_order
);
3872 return read_memory_unsigned_integer (sp
+ 8, 4, byte_order
);
3877 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
3881 i386_stap_is_single_operand (struct gdbarch
*gdbarch
, const char *s
)
3883 return (*s
== '$' /* Literal number. */
3884 || (isdigit (*s
) && s
[1] == '(' && s
[2] == '%') /* Displacement. */
3885 || (*s
== '(' && s
[1] == '%') /* Register indirection. */
3886 || (*s
== '%' && isalpha (s
[1]))); /* Register access. */
3889 /* Helper function for i386_stap_parse_special_token.
3891 This function parses operands of the form `-8+3+1(%rbp)', which
3892 must be interpreted as `*(-8 + 3 - 1 + (void *) $eax)'.
3894 Return true if the operand was parsed successfully, false
3897 static expr::operation_up
3898 i386_stap_parse_special_token_triplet (struct gdbarch
*gdbarch
,
3899 struct stap_parse_info
*p
)
3901 const char *s
= p
->arg
;
3903 if (isdigit (*s
) || *s
== '-' || *s
== '+')
3907 long displacements
[3];
3912 got_minus
[0] = false;
3918 got_minus
[0] = true;
3921 if (!isdigit ((unsigned char) *s
))
3924 displacements
[0] = strtol (s
, &endp
, 10);
3927 if (*s
!= '+' && *s
!= '-')
3929 /* We are not dealing with a triplet. */
3933 got_minus
[1] = false;
3939 got_minus
[1] = true;
3942 if (!isdigit ((unsigned char) *s
))
3945 displacements
[1] = strtol (s
, &endp
, 10);
3948 if (*s
!= '+' && *s
!= '-')
3950 /* We are not dealing with a triplet. */
3954 got_minus
[2] = false;
3960 got_minus
[2] = true;
3963 if (!isdigit ((unsigned char) *s
))
3966 displacements
[2] = strtol (s
, &endp
, 10);
3969 if (*s
!= '(' || s
[1] != '%')
3975 while (isalnum (*s
))
3981 len
= s
- start
- 1;
3982 std::string
regname (start
, len
);
3984 if (user_reg_map_name_to_regnum (gdbarch
, regname
.c_str (), len
) == -1)
3985 error (_("Invalid register name `%s' on expression `%s'."),
3986 regname
.c_str (), p
->saved_arg
);
3989 for (i
= 0; i
< 3; i
++)
3991 LONGEST this_val
= displacements
[i
];
3993 this_val
= -this_val
;
3999 using namespace expr
;
4001 struct type
*long_type
= builtin_type (gdbarch
)->builtin_long
;
4003 = make_operation
<long_const_operation
> (long_type
, value
);
4006 = make_operation
<register_operation
> (std::move (regname
));
4007 struct type
*void_ptr
= builtin_type (gdbarch
)->builtin_data_ptr
;
4008 reg
= make_operation
<unop_cast_operation
> (std::move (reg
), void_ptr
);
4011 = make_operation
<add_operation
> (std::move (reg
), std::move (offset
));
4012 struct type
*arg_ptr_type
= lookup_pointer_type (p
->arg_type
);
4013 sum
= make_operation
<unop_cast_operation
> (std::move (sum
),
4015 return make_operation
<unop_ind_operation
> (std::move (sum
));
4021 /* Helper function for i386_stap_parse_special_token.
4023 This function parses operands of the form `register base +
4024 (register index * size) + offset', as represented in
4025 `(%rcx,%rax,8)', or `[OFFSET](BASE_REG,INDEX_REG[,SIZE])'.
4027 Return true if the operand was parsed successfully, false
4030 static expr::operation_up
4031 i386_stap_parse_special_token_three_arg_disp (struct gdbarch
*gdbarch
,
4032 struct stap_parse_info
*p
)
4034 const char *s
= p
->arg
;
4036 if (isdigit (*s
) || *s
== '(' || *s
== '-' || *s
== '+')
4038 bool offset_minus
= false;
4040 bool size_minus
= false;
4051 offset_minus
= true;
4054 if (offset_minus
&& !isdigit (*s
))
4061 offset
= strtol (s
, &endp
, 10);
4065 if (*s
!= '(' || s
[1] != '%')
4071 while (isalnum (*s
))
4074 if (*s
!= ',' || s
[1] != '%')
4077 len_base
= s
- start
;
4078 std::string
base (start
, len_base
);
4080 if (user_reg_map_name_to_regnum (gdbarch
, base
.c_str (), len_base
) == -1)
4081 error (_("Invalid register name `%s' on expression `%s'."),
4082 base
.c_str (), p
->saved_arg
);
4087 while (isalnum (*s
))
4090 len_index
= s
- start
;
4091 std::string
index (start
, len_index
);
4093 if (user_reg_map_name_to_regnum (gdbarch
, index
.c_str (),
4095 error (_("Invalid register name `%s' on expression `%s'."),
4096 index
.c_str (), p
->saved_arg
);
4098 if (*s
!= ',' && *s
!= ')')
4114 size
= strtol (s
, &endp
, 10);
4124 using namespace expr
;
4126 struct type
*long_type
= builtin_type (gdbarch
)->builtin_long
;
4127 operation_up reg
= make_operation
<register_operation
> (std::move (base
));
4134 = make_operation
<long_const_operation
> (long_type
, offset
);
4135 reg
= make_operation
<add_operation
> (std::move (reg
),
4139 operation_up ind_reg
4140 = make_operation
<register_operation
> (std::move (index
));
4147 = make_operation
<long_const_operation
> (long_type
, size
);
4148 ind_reg
= make_operation
<mul_operation
> (std::move (ind_reg
),
4153 = make_operation
<add_operation
> (std::move (reg
),
4154 std::move (ind_reg
));
4156 struct type
*arg_ptr_type
= lookup_pointer_type (p
->arg_type
);
4157 sum
= make_operation
<unop_cast_operation
> (std::move (sum
),
4159 return make_operation
<unop_ind_operation
> (std::move (sum
));
4165 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
4169 i386_stap_parse_special_token (struct gdbarch
*gdbarch
,
4170 struct stap_parse_info
*p
)
4172 /* The special tokens to be parsed here are:
4174 - `register base + (register index * size) + offset', as represented
4175 in `(%rcx,%rax,8)', or `[OFFSET](BASE_REG,INDEX_REG[,SIZE])'.
4177 - Operands of the form `-8+3+1(%rbp)', which must be interpreted as
4178 `*(-8 + 3 - 1 + (void *) $eax)'. */
4180 expr::operation_up result
4181 = i386_stap_parse_special_token_triplet (gdbarch
, p
);
4183 if (result
== nullptr)
4184 result
= i386_stap_parse_special_token_three_arg_disp (gdbarch
, p
);
4189 /* Implementation of 'gdbarch_stap_adjust_register', as defined in
4193 i386_stap_adjust_register (struct gdbarch
*gdbarch
, struct stap_parse_info
*p
,
4194 const std::string
®name
, int regnum
)
4196 static const std::unordered_set
<std::string
> reg_assoc
4197 = { "ax", "bx", "cx", "dx",
4198 "si", "di", "bp", "sp" };
4200 /* If we are dealing with a register whose size is less than the size
4201 specified by the "[-]N@" prefix, and it is one of the registers that
4202 we know has an extended variant available, then use the extended
4203 version of the register instead. */
4204 if (register_size (gdbarch
, regnum
) < p
->arg_type
->length ()
4205 && reg_assoc
.find (regname
) != reg_assoc
.end ())
4206 return "e" + regname
;
4208 /* Otherwise, just use the requested register. */
4214 /* gdbarch gnu_triplet_regexp method. Both arches are acceptable as GDB always
4215 also supplies -m64 or -m32 by gdbarch_gcc_target_options. */
4218 i386_gnu_triplet_regexp (struct gdbarch
*gdbarch
)
4220 return "(x86_64|i.86)";
4225 /* Implement the "in_indirect_branch_thunk" gdbarch function. */
4228 i386_in_indirect_branch_thunk (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
4230 return x86_in_indirect_branch_thunk (pc
, i386_register_names
,
4231 I386_EAX_REGNUM
, I386_EIP_REGNUM
);
4237 i386_elf_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
4239 static const char *const stap_integer_prefixes
[] = { "$", NULL
};
4240 static const char *const stap_register_prefixes
[] = { "%", NULL
};
4241 static const char *const stap_register_indirection_prefixes
[] = { "(",
4243 static const char *const stap_register_indirection_suffixes
[] = { ")",
4246 /* We typically use stabs-in-ELF with the SVR4 register numbering. */
4247 set_gdbarch_stab_reg_to_regnum (gdbarch
, i386_svr4_reg_to_regnum
);
4249 /* Registering SystemTap handlers. */
4250 set_gdbarch_stap_integer_prefixes (gdbarch
, stap_integer_prefixes
);
4251 set_gdbarch_stap_register_prefixes (gdbarch
, stap_register_prefixes
);
4252 set_gdbarch_stap_register_indirection_prefixes (gdbarch
,
4253 stap_register_indirection_prefixes
);
4254 set_gdbarch_stap_register_indirection_suffixes (gdbarch
,
4255 stap_register_indirection_suffixes
);
4256 set_gdbarch_stap_is_single_operand (gdbarch
,
4257 i386_stap_is_single_operand
);
4258 set_gdbarch_stap_parse_special_token (gdbarch
,
4259 i386_stap_parse_special_token
);
4260 set_gdbarch_stap_adjust_register (gdbarch
,
4261 i386_stap_adjust_register
);
4263 set_gdbarch_in_indirect_branch_thunk (gdbarch
,
4264 i386_in_indirect_branch_thunk
);
4267 /* System V Release 4 (SVR4). */
4270 i386_svr4_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
4272 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
4274 /* System V Release 4 uses ELF. */
4275 i386_elf_init_abi (info
, gdbarch
);
4277 /* System V Release 4 has shared libraries. */
4278 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
4280 tdep
->sigtramp_p
= i386_svr4_sigtramp_p
;
4281 tdep
->sigcontext_addr
= i386_svr4_sigcontext_addr
;
4282 tdep
->sc_pc_offset
= 36 + 14 * 4;
4283 tdep
->sc_sp_offset
= 36 + 17 * 4;
4285 tdep
->jb_pc_offset
= 20;
4290 /* i386 register groups. In addition to the normal groups, add "mmx"
4293 static const reggroup
*i386_sse_reggroup
;
4294 static const reggroup
*i386_mmx_reggroup
;
4297 i386_init_reggroups (void)
4299 i386_sse_reggroup
= reggroup_new ("sse", USER_REGGROUP
);
4300 i386_mmx_reggroup
= reggroup_new ("mmx", USER_REGGROUP
);
4304 i386_add_reggroups (struct gdbarch
*gdbarch
)
4306 reggroup_add (gdbarch
, i386_sse_reggroup
);
4307 reggroup_add (gdbarch
, i386_mmx_reggroup
);
4311 i386_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
4312 const struct reggroup
*group
)
4314 const i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
4315 int fp_regnum_p
, mmx_regnum_p
, xmm_regnum_p
, mxcsr_regnum_p
,
4316 ymm_regnum_p
, ymmh_regnum_p
, ymm_avx512_regnum_p
, ymmh_avx512_regnum_p
,
4317 zmm_regnum_p
, zmmh_regnum_p
, xmm_avx512_regnum_p
, avx512_p
, avx_p
,
4318 sse_p
, pkru_regnum_p
;
4320 /* Don't include pseudo registers, except for MMX, in any register
4322 if (i386_byte_regnum_p (gdbarch
, regnum
))
4325 if (i386_word_regnum_p (gdbarch
, regnum
))
4328 if (i386_dword_regnum_p (gdbarch
, regnum
))
4331 mmx_regnum_p
= i386_mmx_regnum_p (gdbarch
, regnum
);
4332 if (group
== i386_mmx_reggroup
)
4333 return mmx_regnum_p
;
4335 pkru_regnum_p
= i386_pkru_regnum_p(gdbarch
, regnum
);
4336 xmm_regnum_p
= i386_xmm_regnum_p (gdbarch
, regnum
);
4337 xmm_avx512_regnum_p
= i386_xmm_avx512_regnum_p (gdbarch
, regnum
);
4338 mxcsr_regnum_p
= i386_mxcsr_regnum_p (gdbarch
, regnum
);
4339 if (group
== i386_sse_reggroup
)
4340 return xmm_regnum_p
|| xmm_avx512_regnum_p
|| mxcsr_regnum_p
;
4342 ymm_regnum_p
= i386_ymm_regnum_p (gdbarch
, regnum
);
4343 ymm_avx512_regnum_p
= i386_ymm_avx512_regnum_p (gdbarch
, regnum
);
4344 zmm_regnum_p
= i386_zmm_regnum_p (gdbarch
, regnum
);
4346 avx512_p
= ((tdep
->xcr0
& X86_XSTATE_AVX_AVX512_MASK
)
4347 == X86_XSTATE_AVX_AVX512_MASK
);
4348 avx_p
= ((tdep
->xcr0
& X86_XSTATE_AVX_AVX512_MASK
)
4349 == X86_XSTATE_AVX_MASK
) && !avx512_p
;
4350 sse_p
= ((tdep
->xcr0
& X86_XSTATE_AVX_AVX512_MASK
)
4351 == X86_XSTATE_SSE_MASK
) && !avx512_p
&& ! avx_p
;
4353 if (group
== vector_reggroup
)
4354 return (mmx_regnum_p
4355 || (zmm_regnum_p
&& avx512_p
)
4356 || ((ymm_regnum_p
|| ymm_avx512_regnum_p
) && avx_p
)
4357 || ((xmm_regnum_p
|| xmm_avx512_regnum_p
) && sse_p
)
4360 fp_regnum_p
= (i386_fp_regnum_p (gdbarch
, regnum
)
4361 || i386_fpc_regnum_p (gdbarch
, regnum
));
4362 if (group
== float_reggroup
)
4365 /* For "info reg all", don't include upper YMM registers nor XMM
4366 registers when AVX is supported. */
4367 ymmh_regnum_p
= i386_ymmh_regnum_p (gdbarch
, regnum
);
4368 ymmh_avx512_regnum_p
= i386_ymmh_avx512_regnum_p (gdbarch
, regnum
);
4369 zmmh_regnum_p
= i386_zmmh_regnum_p (gdbarch
, regnum
);
4370 if (group
== all_reggroup
4371 && (((xmm_regnum_p
|| xmm_avx512_regnum_p
) && !sse_p
)
4372 || ((ymm_regnum_p
|| ymm_avx512_regnum_p
) && !avx_p
)
4374 || ymmh_avx512_regnum_p
4378 if (group
== general_reggroup
)
4379 return (!fp_regnum_p
4383 && !xmm_avx512_regnum_p
4386 && !ymm_avx512_regnum_p
4387 && !ymmh_avx512_regnum_p
4392 return default_register_reggroup_p (gdbarch
, regnum
, group
);
4396 /* Get the ARGIth function argument for the current function. */
4399 i386_fetch_pointer_argument (const frame_info_ptr
&frame
, int argi
,
4402 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
4403 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4404 CORE_ADDR sp
= get_frame_register_unsigned (frame
, I386_ESP_REGNUM
);
4405 return read_memory_unsigned_integer (sp
+ (4 * (argi
+ 1)), 4, byte_order
);
4408 #define PREFIX_REPZ 0x01
4409 #define PREFIX_REPNZ 0x02
4410 #define PREFIX_LOCK 0x04
4411 #define PREFIX_DATA 0x08
4412 #define PREFIX_ADDR 0x10
4424 /* i386 arith/logic operations */
4437 struct i386_record_s
4439 struct gdbarch
*gdbarch
;
4440 struct regcache
*regcache
;
4441 CORE_ADDR orig_addr
;
4447 uint8_t mod
, reg
, rm
;
4455 /* These are used by VEX and XOP prefixes. */
4462 /* Parse the "modrm" part of the memory address irp->addr points at.
4463 Returns -1 if something goes wrong, 0 otherwise. */
4466 i386_record_modrm (struct i386_record_s
*irp
)
4468 struct gdbarch
*gdbarch
= irp
->gdbarch
;
4470 if (record_read_memory (gdbarch
, irp
->addr
, &irp
->modrm
, 1))
4474 irp
->mod
= (irp
->modrm
>> 6) & 3;
4475 irp
->reg
= (irp
->modrm
>> 3) & 7;
4476 irp
->rm
= irp
->modrm
& 7;
4481 /* Extract the memory address that the current instruction writes to,
4482 and return it in *ADDR. Return -1 if something goes wrong. */
4485 i386_record_lea_modrm_addr (struct i386_record_s
*irp
, uint64_t *addr
)
4487 struct gdbarch
*gdbarch
= irp
->gdbarch
;
4488 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4493 if (irp
->aflag
|| irp
->regmap
[X86_RECORD_R8_REGNUM
])
4500 uint8_t base
= irp
->rm
;
4505 if (record_read_memory (gdbarch
, irp
->addr
, &byte
, 1))
4508 scale
= (byte
>> 6) & 3;
4509 index
= ((byte
>> 3) & 7) | irp
->rex_x
;
4517 if ((base
& 7) == 5)
4520 if (record_read_memory (gdbarch
, irp
->addr
, buf
, 4))
4523 *addr
= extract_signed_integer (buf
, 4, byte_order
);
4524 if (irp
->regmap
[X86_RECORD_R8_REGNUM
] && !havesib
)
4525 *addr
+= irp
->addr
+ irp
->rip_offset
;
4529 if (record_read_memory (gdbarch
, irp
->addr
, buf
, 1))
4532 *addr
= (int8_t) buf
[0];
4535 if (record_read_memory (gdbarch
, irp
->addr
, buf
, 4))
4537 *addr
= extract_signed_integer (buf
, 4, byte_order
);
4545 if (base
== 4 && irp
->popl_esp_hack
)
4546 *addr
+= irp
->popl_esp_hack
;
4547 regcache_raw_read_unsigned (irp
->regcache
, irp
->regmap
[base
],
4550 if (irp
->aflag
== 2)
4555 *addr
= (uint32_t) (offset64
+ *addr
);
4557 if (havesib
&& (index
!= 4 || scale
!= 0))
4559 regcache_raw_read_unsigned (irp
->regcache
, irp
->regmap
[index
],
4561 if (irp
->aflag
== 2)
4562 *addr
+= offset64
<< scale
;
4564 *addr
= (uint32_t) (*addr
+ (offset64
<< scale
));
4569 /* Since we are in 64-bit mode with ADDR32 prefix, zero-extend
4570 address from 32-bit to 64-bit. */
4571 *addr
= (uint32_t) *addr
;
4582 if (record_read_memory (gdbarch
, irp
->addr
, buf
, 2))
4585 *addr
= extract_signed_integer (buf
, 2, byte_order
);
4591 if (record_read_memory (gdbarch
, irp
->addr
, buf
, 1))
4594 *addr
= (int8_t) buf
[0];
4597 if (record_read_memory (gdbarch
, irp
->addr
, buf
, 2))
4600 *addr
= extract_signed_integer (buf
, 2, byte_order
);
4607 regcache_raw_read_unsigned (irp
->regcache
,
4608 irp
->regmap
[X86_RECORD_REBX_REGNUM
],
4610 *addr
= (uint32_t) (*addr
+ offset64
);
4611 regcache_raw_read_unsigned (irp
->regcache
,
4612 irp
->regmap
[X86_RECORD_RESI_REGNUM
],
4614 *addr
= (uint32_t) (*addr
+ offset64
);
4617 regcache_raw_read_unsigned (irp
->regcache
,
4618 irp
->regmap
[X86_RECORD_REBX_REGNUM
],
4620 *addr
= (uint32_t) (*addr
+ offset64
);
4621 regcache_raw_read_unsigned (irp
->regcache
,
4622 irp
->regmap
[X86_RECORD_REDI_REGNUM
],
4624 *addr
= (uint32_t) (*addr
+ offset64
);
4627 regcache_raw_read_unsigned (irp
->regcache
,
4628 irp
->regmap
[X86_RECORD_REBP_REGNUM
],
4630 *addr
= (uint32_t) (*addr
+ offset64
);
4631 regcache_raw_read_unsigned (irp
->regcache
,
4632 irp
->regmap
[X86_RECORD_RESI_REGNUM
],
4634 *addr
= (uint32_t) (*addr
+ offset64
);
4637 regcache_raw_read_unsigned (irp
->regcache
,
4638 irp
->regmap
[X86_RECORD_REBP_REGNUM
],
4640 *addr
= (uint32_t) (*addr
+ offset64
);
4641 regcache_raw_read_unsigned (irp
->regcache
,
4642 irp
->regmap
[X86_RECORD_REDI_REGNUM
],
4644 *addr
= (uint32_t) (*addr
+ offset64
);
4647 regcache_raw_read_unsigned (irp
->regcache
,
4648 irp
->regmap
[X86_RECORD_RESI_REGNUM
],
4650 *addr
= (uint32_t) (*addr
+ offset64
);
4653 regcache_raw_read_unsigned (irp
->regcache
,
4654 irp
->regmap
[X86_RECORD_REDI_REGNUM
],
4656 *addr
= (uint32_t) (*addr
+ offset64
);
4659 regcache_raw_read_unsigned (irp
->regcache
,
4660 irp
->regmap
[X86_RECORD_REBP_REGNUM
],
4662 *addr
= (uint32_t) (*addr
+ offset64
);
4665 regcache_raw_read_unsigned (irp
->regcache
,
4666 irp
->regmap
[X86_RECORD_REBX_REGNUM
],
4668 *addr
= (uint32_t) (*addr
+ offset64
);
4678 /* Record the address and contents of the memory that will be changed
4679 by the current instruction. Return -1 if something goes wrong, 0
4683 i386_record_lea_modrm (struct i386_record_s
*irp
)
4685 struct gdbarch
*gdbarch
= irp
->gdbarch
;
4688 if (irp
->override
>= 0)
4690 if (record_full_memory_query
)
4693 Process record ignores the memory change of instruction at address %s\n\
4694 because it can't get the value of the segment register.\n\
4695 Do you want to stop the program?"),
4696 paddress (gdbarch
, irp
->orig_addr
)))
4703 if (i386_record_lea_modrm_addr (irp
, &addr
))
4706 if (record_full_arch_list_add_mem (addr
, 1 << irp
->ot
))
4712 /* Record the effects of a push operation. Return -1 if something
4713 goes wrong, 0 otherwise. */
4716 i386_record_push (struct i386_record_s
*irp
, int size
)
4720 if (record_full_arch_list_add_reg (irp
->regcache
,
4721 irp
->regmap
[X86_RECORD_RESP_REGNUM
]))
4723 regcache_raw_read_unsigned (irp
->regcache
,
4724 irp
->regmap
[X86_RECORD_RESP_REGNUM
],
4726 if (record_full_arch_list_add_mem ((CORE_ADDR
) addr
- size
, size
))
4733 /* Defines contents to record. */
4734 #define I386_SAVE_FPU_REGS 0xfffd
4735 #define I386_SAVE_FPU_ENV 0xfffe
4736 #define I386_SAVE_FPU_ENV_REG_STACK 0xffff
4738 /* Record the values of the floating point registers which will be
4739 changed by the current instruction. Returns -1 if something is
4740 wrong, 0 otherwise. */
4742 static int i386_record_floats (struct gdbarch
*gdbarch
,
4743 struct i386_record_s
*ir
,
4746 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
4749 /* Oza: Because of floating point insn push/pop of fpu stack is going to
4750 happen. Currently we store st0-st7 registers, but we need not store all
4751 registers all the time, in future we use ftag register and record only
4752 those who are not marked as an empty. */
4754 if (I386_SAVE_FPU_REGS
== iregnum
)
4756 for (i
= I387_ST0_REGNUM (tdep
); i
<= I387_ST0_REGNUM (tdep
) + 7; i
++)
4758 if (record_full_arch_list_add_reg (ir
->regcache
, i
))
4762 else if (I386_SAVE_FPU_ENV
== iregnum
)
4764 for (i
= I387_FCTRL_REGNUM (tdep
); i
<= I387_FOP_REGNUM (tdep
); i
++)
4766 if (record_full_arch_list_add_reg (ir
->regcache
, i
))
4770 else if (I386_SAVE_FPU_ENV_REG_STACK
== iregnum
)
4772 for (i
= I387_ST0_REGNUM (tdep
); i
<= I387_FOP_REGNUM (tdep
); i
++)
4773 if (record_full_arch_list_add_reg (ir
->regcache
, i
))
4776 else if ((iregnum
>= I387_ST0_REGNUM (tdep
)) &&
4777 (iregnum
<= I387_FOP_REGNUM (tdep
)))
4779 if (record_full_arch_list_add_reg (ir
->regcache
,iregnum
))
4784 /* Parameter error. */
4787 if(I386_SAVE_FPU_ENV
!= iregnum
)
4789 for (i
= I387_FCTRL_REGNUM (tdep
); i
<= I387_FOP_REGNUM (tdep
); i
++)
4791 if (record_full_arch_list_add_reg (ir
->regcache
, i
))
4798 /* i386_process_record helper to deal with instructions that start
4802 i386_record_vex (struct i386_record_s
*ir
, uint8_t vex_w
, uint8_t vex_r
,
4803 int opcode
, struct gdbarch
*gdbarch
)
4805 /* We need this to find YMM (and once AVX-512 is supported, ZMM) registers.
4806 We should always save the largest available register, since an
4807 instruction that handles a smaller reg may zero out the higher bits,
4808 so we must have them saved. */
4809 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
4811 /* Since we are reading pseudo registers, we need to tell GDB that it is
4812 safe to do so, by saying we aren't _really_ running the inferior right
4814 SCOPE_EXIT
{ inferior_thread ()->set_executing (true); };
4815 inferior_thread () -> set_executing (false);
4819 case 0x6e: /* VMOVD XMM, reg/mem */
4820 /* This is moving from a regular register or memory region into an
4822 i386_record_modrm (ir
);
4823 /* ModR/M only has the 3 least significant bits of the destination
4824 register, the last one is indicated by VEX.R (stored inverted). */
4825 record_full_arch_list_add_reg (ir
->regcache
,
4827 + ir
->reg
+ vex_r
* 8);
4829 case 0x7e: /* VMOV(D/Q) */
4830 i386_record_modrm (ir
);
4831 /* Both the intel and AMD manual are wrong about this. According to
4832 it, the only difference between vmovq and vmovd should be the rex_w
4833 bit, but in empirical testing, it seems that they share this opcode,
4834 and the way to differentiate it here is looking at VEX.PP. */
4837 /* This is vmovq moving from a regular register or memory
4838 into an XMM register. As above, VEX.R is the final bit for
4839 destination register. */
4840 record_full_arch_list_add_reg (ir
->regcache
,
4842 + ir
->reg
+ vex_r
* 8);
4844 else if (ir
->pp
== 1)
4846 /* This is the vmovd version that stores into a regular register
4847 or memory region. */
4848 /* If ModRM.mod is 11 we are saving into a register. */
4850 record_full_arch_list_add_reg (ir
->regcache
, ir
->regmap
[ir
->rm
]);
4853 /* Calculate the size of memory that will be modified
4854 and store it in the form of 1 << ir->ot, since that
4855 is how the function uses it. In theory, VEX.W is supposed
4856 to indicate the size of the memory. In practice, I only
4857 ever seen it set to 0, and for 16 bytes, 0xD6 opcode
4864 i386_record_lea_modrm (ir
);
4869 gdb_printf ("Unrecognized VEX.PP value %d at address %s.",
4870 ir
->pp
, paddress(gdbarch
, ir
->orig_addr
));
4874 case 0xd6: /* VMOVQ reg/mem XMM */
4875 i386_record_modrm (ir
);
4876 /* This is the vmovq version that stores into a regular register
4877 or memory region. */
4878 /* If ModRM.mod is 11 we are saving into a register. */
4880 record_full_arch_list_add_reg (ir
->regcache
, ir
->regmap
[ir
->rm
]);
4883 /* We know that this operation is always 64 bits. */
4885 i386_record_lea_modrm (ir
);
4889 case 0x6f: /* VMOVDQ (U|A) */
4890 case 0x7f: /* VMOVDQ (U|A) */
4891 /* vmovdq instructions have information about source/destination
4892 spread over many places, so this code ended up messier than
4894 /* The VEX.pp bits identify if the move is aligned or not, but this
4895 doesn't influence the recording so we can ignore it. */
4896 i386_record_modrm (ir
);
4897 /* The first bit of modrm identifies if both operands of the instruction
4898 are registers (bit = 1) or if one of the operands is memory. */
4903 /* vex_r will identify the high bit of the destination
4904 register. Source is identified by ir->rex_b, but that
4905 doesn't matter for recording. */
4906 record_full_arch_list_add_reg (ir
->regcache
,
4907 tdep
->ymm0_regnum
+ 8*vex_r
+ ir
->reg
);
4911 /* The origin operand is >7 and destination operand is <= 7.
4912 This is special cased because in this one vex_r is used to
4913 identify the high bit of the SOURCE operand, not destination
4914 which would mess the previous expression. */
4915 record_full_arch_list_add_reg (ir
->regcache
,
4916 tdep
->ymm0_regnum
+ ir
->rm
);
4921 /* This is the easy branch. We just need to check the opcode
4922 to see if the source or destination is memory. */
4925 record_full_arch_list_add_reg (ir
->regcache
,
4927 + ir
->reg
+ vex_r
* 8);
4931 /* We're writing 256 bits, so 1<<8. */
4933 i386_record_lea_modrm (ir
);
4938 case 0x60: /* VPUNPCKLBW */
4939 case 0x61: /* VPUNPCKLWD */
4940 case 0x62: /* VPUNPCKLDQ */
4941 case 0x6c: /* VPUNPCKLQDQ */
4942 case 0x68: /* VPUNPCKHBW */
4943 case 0x69: /* VPUNPCKHWD */
4944 case 0x6a: /* VPUNPCKHDQ */
4945 case 0x6d: /* VPUNPCKHQDQ */
4947 i386_record_modrm (ir
);
4948 int reg_offset
= ir
->reg
+ vex_r
* 8;
4949 record_full_arch_list_add_reg (ir
->regcache
,
4950 tdep
->ymm0_regnum
+ reg_offset
);
4954 case 0x74: /* VPCMPEQB */
4955 case 0x75: /* VPCMPEQB */
4956 case 0x76: /* VPCMPEQB */
4958 i386_record_modrm (ir
);
4959 int reg_offset
= ir
->reg
+ vex_r
* 8;
4960 record_full_arch_list_add_reg (ir
->regcache
,
4961 tdep
->ymm0_regnum
+ reg_offset
);
4965 case 0x78: /* VPBROADCASTB */
4966 case 0x79: /* VPBROADCASTW */
4967 case 0x58: /* VPBROADCASTD */
4968 case 0x59: /* VPBROADCASTQ */
4970 i386_record_modrm (ir
);
4971 int reg_offset
= ir
->reg
+ vex_r
* 8;
4972 gdb_assert (tdep
->num_ymm_regs
> reg_offset
);
4973 record_full_arch_list_add_reg (ir
->regcache
,
4974 tdep
->ymm0_regnum
+ reg_offset
);
4978 case 0x77:/* VZEROUPPER */
4980 int num_regs
= tdep
->num_ymm_regs
;
4981 /* This instruction only works on ymm0..15, even if 16..31 are
4985 for (int i
= 0; i
< num_regs
; i
++)
4987 /* We only need to record ymm_h, because the low bits
4989 record_full_arch_list_add_reg (ir
->regcache
,
4990 tdep
->ymm0h_regnum
+ i
);
4995 case 0xd7: /* VPMOVMSKB */
4997 i386_record_modrm (ir
);
4998 record_full_arch_list_add_reg (ir
->regcache
,
4999 ir
->regmap
[X86_RECORD_REAX_REGNUM
5000 + ir
->reg
+ 8 * vex_r
]);
5004 case 0xef: /* VPXOR */
5005 case 0xeb: /* VPOR */
5007 i386_record_modrm (ir
);
5008 int reg_offset
= ir
->reg
+ vex_r
* 8;
5009 record_full_arch_list_add_reg (ir
->regcache
,
5010 tdep
->ymm0_regnum
+ reg_offset
);
5015 gdb_printf (gdb_stderr
,
5016 _("Process record does not support VEX instruction 0x%02x "
5017 "at address %s.\n"),
5018 (unsigned int) (opcode
),
5019 paddress (gdbarch
, ir
->orig_addr
));
5023 record_full_arch_list_add_reg (ir
->regcache
, ir
->regmap
[X86_RECORD_REIP_REGNUM
]);
5024 if (record_full_arch_list_add_end ())
5030 /* Parse the current instruction, and record the values of the
5031 registers and memory that will be changed by the current
5032 instruction. Returns -1 if something goes wrong, 0 otherwise. */
5034 #define I386_RECORD_FULL_ARCH_LIST_ADD_REG(regnum) \
5035 record_full_arch_list_add_reg (ir.regcache, ir.regmap[(regnum)])
5038 i386_process_record (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
5039 CORE_ADDR input_addr
)
5041 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
5047 gdb_byte buf
[I386_MAX_REGISTER_SIZE
];
5048 struct i386_record_s ir
;
5049 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
5052 bool vex_prefix
= false;
5054 memset (&ir
, 0, sizeof (struct i386_record_s
));
5055 ir
.regcache
= regcache
;
5056 ir
.addr
= input_addr
;
5057 ir
.orig_addr
= input_addr
;
5061 ir
.popl_esp_hack
= 0;
5062 ir
.regmap
= tdep
->record_regmap
;
5063 ir
.gdbarch
= gdbarch
;
5065 if (record_debug
> 1)
5066 gdb_printf (gdb_stdlog
, "Process record: i386_process_record "
5068 paddress (gdbarch
, ir
.addr
));
5073 if (record_read_memory (gdbarch
, ir
.addr
, &opcode8
, 1))
5076 switch (opcode8
) /* Instruction prefixes */
5078 case REPE_PREFIX_OPCODE
:
5079 prefixes
|= PREFIX_REPZ
;
5081 case REPNE_PREFIX_OPCODE
:
5082 prefixes
|= PREFIX_REPNZ
;
5084 case LOCK_PREFIX_OPCODE
:
5085 prefixes
|= PREFIX_LOCK
;
5087 case CS_PREFIX_OPCODE
:
5088 ir
.override
= X86_RECORD_CS_REGNUM
;
5090 case SS_PREFIX_OPCODE
:
5091 ir
.override
= X86_RECORD_SS_REGNUM
;
5093 case DS_PREFIX_OPCODE
:
5094 ir
.override
= X86_RECORD_DS_REGNUM
;
5096 case ES_PREFIX_OPCODE
:
5097 ir
.override
= X86_RECORD_ES_REGNUM
;
5099 case FS_PREFIX_OPCODE
:
5100 ir
.override
= X86_RECORD_FS_REGNUM
;
5102 case GS_PREFIX_OPCODE
:
5103 ir
.override
= X86_RECORD_GS_REGNUM
;
5105 case DATA_PREFIX_OPCODE
:
5106 prefixes
|= PREFIX_DATA
;
5108 case ADDR_PREFIX_OPCODE
:
5109 prefixes
|= PREFIX_ADDR
;
5111 case 0x40: /* i386 inc %eax */
5112 case 0x41: /* i386 inc %ecx */
5113 case 0x42: /* i386 inc %edx */
5114 case 0x43: /* i386 inc %ebx */
5115 case 0x44: /* i386 inc %esp */
5116 case 0x45: /* i386 inc %ebp */
5117 case 0x46: /* i386 inc %esi */
5118 case 0x47: /* i386 inc %edi */
5119 case 0x48: /* i386 dec %eax */
5120 case 0x49: /* i386 dec %ecx */
5121 case 0x4a: /* i386 dec %edx */
5122 case 0x4b: /* i386 dec %ebx */
5123 case 0x4c: /* i386 dec %esp */
5124 case 0x4d: /* i386 dec %ebp */
5125 case 0x4e: /* i386 dec %esi */
5126 case 0x4f: /* i386 dec %edi */
5127 if (ir
.regmap
[X86_RECORD_R8_REGNUM
]) /* 64 bit target */
5130 rex_w
= (opcode8
>> 3) & 1;
5131 rex_r
= (opcode8
& 0x4) << 1;
5132 ir
.rex_x
= (opcode8
& 0x2) << 2;
5133 ir
.rex_b
= (opcode8
& 0x1) << 3;
5135 else /* 32 bit target */
5138 case 0xc4: /* 3-byte VEX prefixes (for AVX/AVX2 instructions). */
5140 /* The first byte just identifies the VEX prefix. Data is stored
5141 on the following 2 bytes. */
5143 if (record_read_memory (gdbarch
, ir
.addr
, &byte
, 1))
5147 rex_r
= !((byte
>> 7) & 0x1);
5148 ir
.rex_x
= !((byte
>> 6) & 0x1);
5149 ir
.rex_b
= !((byte
>> 5) & 0x1);
5150 ir
.map_select
= byte
& 0x1f;
5151 /* Collect the last byte of the prefix. */
5152 if (record_read_memory (gdbarch
, ir
.addr
, &byte
, 1))
5155 rex_w
= (byte
>> 7) & 0x1;
5156 ir
.vvvv
= (~(byte
>> 3) & 0xf);
5157 ir
.l
= (byte
>> 2) & 0x1;
5163 case 0xc5: /* 2-byte VEX prefix for AVX/AVX2 instructions. */
5165 /* The first byte just identifies the VEX prefix. Data is stored
5166 on the following 2 bytes. */
5168 if (record_read_memory (gdbarch
, ir
.addr
, &byte
, 1))
5172 /* On the 2-byte versions, these are pre-defined. */
5178 rex_r
= !((byte
>> 7) & 0x1);
5179 ir
.vvvv
= (~(byte
>> 3) & 0xf);
5180 ir
.l
= (byte
>> 2) & 0x1;
5191 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && rex_w
== 1)
5197 if (prefixes
& PREFIX_DATA
)
5200 if (prefixes
& PREFIX_ADDR
)
5202 else if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5205 /* Now check op code. */
5206 opcode
= (uint32_t) opcode8
;
5209 /* If we found the VEX prefix, i386 will either record or warn that
5210 the instruction isn't supported, so we can return the VEX result. */
5211 return i386_record_vex (&ir
, rex_w
, rex_r
, opcode
, gdbarch
);
5217 if (record_read_memory (gdbarch
, ir
.addr
, &opcode8
, 1))
5220 opcode
= (uint32_t) opcode8
| 0x0f00;
5224 case 0x00: /* arith & logic */
5272 if (((opcode
>> 3) & 7) != OP_CMPL
)
5274 if ((opcode
& 1) == 0)
5277 ir
.ot
= ir
.dflag
+ OT_WORD
;
5279 switch ((opcode
>> 1) & 3)
5281 case 0: /* OP Ev, Gv */
5282 if (i386_record_modrm (&ir
))
5286 if (i386_record_lea_modrm (&ir
))
5292 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5294 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
5297 case 1: /* OP Gv, Ev */
5298 if (i386_record_modrm (&ir
))
5301 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5303 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5305 case 2: /* OP A, Iv */
5306 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5310 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5313 case 0x80: /* GRP1 */
5317 if (i386_record_modrm (&ir
))
5320 if (ir
.reg
!= OP_CMPL
)
5322 if ((opcode
& 1) == 0)
5325 ir
.ot
= ir
.dflag
+ OT_WORD
;
5332 ir
.rip_offset
= (ir
.ot
> OT_LONG
) ? 4 : (1 << ir
.ot
);
5333 if (i386_record_lea_modrm (&ir
))
5337 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
5339 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5342 case 0x40: /* inc */
5351 case 0x48: /* dec */
5360 I386_RECORD_FULL_ARCH_LIST_ADD_REG (opcode
& 7);
5361 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5364 case 0xf6: /* GRP3 */
5366 if ((opcode
& 1) == 0)
5369 ir
.ot
= ir
.dflag
+ OT_WORD
;
5370 if (i386_record_modrm (&ir
))
5373 if (ir
.mod
!= 3 && ir
.reg
== 0)
5374 ir
.rip_offset
= (ir
.ot
> OT_LONG
) ? 4 : (1 << ir
.ot
);
5379 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5385 if (i386_record_lea_modrm (&ir
))
5391 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5393 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
5395 if (ir
.reg
== 3) /* neg */
5396 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5402 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5403 if (ir
.ot
!= OT_BYTE
)
5404 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
5405 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5409 opcode
= opcode
<< 8 | ir
.modrm
;
5415 case 0xfe: /* GRP4 */
5416 case 0xff: /* GRP5 */
5417 if (i386_record_modrm (&ir
))
5419 if (ir
.reg
>= 2 && opcode
== 0xfe)
5422 opcode
= opcode
<< 8 | ir
.modrm
;
5429 if ((opcode
& 1) == 0)
5432 ir
.ot
= ir
.dflag
+ OT_WORD
;
5435 if (i386_record_lea_modrm (&ir
))
5441 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5443 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
5445 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5448 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && ir
.dflag
)
5450 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5452 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5455 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM
);
5456 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5458 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5462 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5465 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && ir
.dflag
)
5467 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5472 opcode
= opcode
<< 8 | ir
.modrm
;
5478 case 0x84: /* test */
5482 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5485 case 0x98: /* CWDE/CBW */
5486 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5489 case 0x99: /* CDQ/CWD */
5490 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5491 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
5494 case 0x0faf: /* imul */
5497 ir
.ot
= ir
.dflag
+ OT_WORD
;
5498 if (i386_record_modrm (&ir
))
5501 ir
.rip_offset
= (ir
.ot
> OT_LONG
) ? 4 : (1 << ir
.ot
);
5502 else if (opcode
== 0x6b)
5505 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5507 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5508 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5511 case 0x0fc0: /* xadd */
5513 if ((opcode
& 1) == 0)
5516 ir
.ot
= ir
.dflag
+ OT_WORD
;
5517 if (i386_record_modrm (&ir
))
5522 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5524 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5525 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5527 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
5531 if (i386_record_lea_modrm (&ir
))
5533 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5535 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5537 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5540 case 0x0fb0: /* cmpxchg */
5542 if ((opcode
& 1) == 0)
5545 ir
.ot
= ir
.dflag
+ OT_WORD
;
5546 if (i386_record_modrm (&ir
))
5551 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5552 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5554 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5558 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5559 if (i386_record_lea_modrm (&ir
))
5562 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5565 case 0x0fc7: /* cmpxchg8b / rdrand / rdseed */
5566 if (i386_record_modrm (&ir
))
5570 /* rdrand and rdseed use the 3 bits of the REG field of ModR/M as
5571 an extended opcode. rdrand has bits 110 (/6) and rdseed
5572 has bits 111 (/7). */
5573 if (ir
.reg
== 6 || ir
.reg
== 7)
5575 /* The storage register is described by the 3 R/M bits, but the
5576 REX.B prefix may be used to give access to registers
5577 R8~R15. In this case ir.rex_b + R/M will give us the register
5578 in the range R8~R15.
5580 REX.W may also be used to access 64-bit registers, but we
5581 already record entire registers and not just partial bits
5583 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rex_b
+ ir
.rm
);
5584 /* These instructions also set conditional bits. */
5585 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5590 /* We don't handle this particular instruction yet. */
5592 opcode
= opcode
<< 8 | ir
.modrm
;
5596 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5597 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
5598 if (i386_record_lea_modrm (&ir
))
5600 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5603 case 0x50: /* push */
5613 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && ir
.dflag
)
5615 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5619 case 0x06: /* push es */
5620 case 0x0e: /* push cs */
5621 case 0x16: /* push ss */
5622 case 0x1e: /* push ds */
5623 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5628 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5632 case 0x0fa0: /* push fs */
5633 case 0x0fa8: /* push gs */
5634 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5639 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5643 case 0x60: /* pusha */
5644 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5649 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 4)))
5653 case 0x58: /* pop */
5661 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5662 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode
& 0x7) | ir
.rex_b
);
5665 case 0x61: /* popa */
5666 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5671 for (regnum
= X86_RECORD_REAX_REGNUM
;
5672 regnum
<= X86_RECORD_REDI_REGNUM
;
5674 I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum
);
5677 case 0x8f: /* pop */
5678 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5679 ir
.ot
= ir
.dflag
? OT_QUAD
: OT_WORD
;
5681 ir
.ot
= ir
.dflag
+ OT_WORD
;
5682 if (i386_record_modrm (&ir
))
5685 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
5688 ir
.popl_esp_hack
= 1 << ir
.ot
;
5689 if (i386_record_lea_modrm (&ir
))
5692 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5695 case 0xc8: /* enter */
5696 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM
);
5697 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && ir
.dflag
)
5699 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5703 case 0xc9: /* leave */
5704 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5705 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM
);
5708 case 0x07: /* pop es */
5709 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5714 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5715 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_ES_REGNUM
);
5716 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5719 case 0x17: /* pop ss */
5720 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5725 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5726 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_SS_REGNUM
);
5727 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5730 case 0x1f: /* pop ds */
5731 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5736 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5737 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_DS_REGNUM
);
5738 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5741 case 0x0fa1: /* pop fs */
5742 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5743 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_FS_REGNUM
);
5744 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5747 case 0x0fa9: /* pop gs */
5748 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5749 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_GS_REGNUM
);
5750 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5753 case 0x88: /* mov */
5757 if ((opcode
& 1) == 0)
5760 ir
.ot
= ir
.dflag
+ OT_WORD
;
5762 if (i386_record_modrm (&ir
))
5767 if (opcode
== 0xc6 || opcode
== 0xc7)
5768 ir
.rip_offset
= (ir
.ot
> OT_LONG
) ? 4 : (1 << ir
.ot
);
5769 if (i386_record_lea_modrm (&ir
))
5774 if (opcode
== 0xc6 || opcode
== 0xc7)
5776 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5778 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
5782 case 0x8a: /* mov */
5784 if ((opcode
& 1) == 0)
5787 ir
.ot
= ir
.dflag
+ OT_WORD
;
5788 if (i386_record_modrm (&ir
))
5791 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5793 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5796 case 0x8c: /* mov seg */
5797 if (i386_record_modrm (&ir
))
5802 opcode
= opcode
<< 8 | ir
.modrm
;
5807 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
5811 if (i386_record_lea_modrm (&ir
))
5816 case 0x8e: /* mov seg */
5817 if (i386_record_modrm (&ir
))
5822 regnum
= X86_RECORD_ES_REGNUM
;
5825 regnum
= X86_RECORD_SS_REGNUM
;
5828 regnum
= X86_RECORD_DS_REGNUM
;
5831 regnum
= X86_RECORD_FS_REGNUM
;
5834 regnum
= X86_RECORD_GS_REGNUM
;
5838 opcode
= opcode
<< 8 | ir
.modrm
;
5842 I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum
);
5843 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5846 case 0x0fb6: /* movzbS */
5847 case 0x0fb7: /* movzwS */
5848 case 0x0fbe: /* movsbS */
5849 case 0x0fbf: /* movswS */
5850 if (i386_record_modrm (&ir
))
5852 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
| rex_r
);
5855 case 0x8d: /* lea */
5856 if (i386_record_modrm (&ir
))
5861 opcode
= opcode
<< 8 | ir
.modrm
;
5866 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5868 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5871 case 0xa0: /* mov EAX */
5874 case 0xd7: /* xlat */
5875 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5878 case 0xa2: /* mov EAX */
5880 if (ir
.override
>= 0)
5882 if (record_full_memory_query
)
5885 Process record ignores the memory change of instruction at address %s\n\
5886 because it can't get the value of the segment register.\n\
5887 Do you want to stop the program?"),
5888 paddress (gdbarch
, ir
.orig_addr
)))
5894 if ((opcode
& 1) == 0)
5897 ir
.ot
= ir
.dflag
+ OT_WORD
;
5900 if (record_read_memory (gdbarch
, ir
.addr
, buf
, 8))
5903 addr
= extract_unsigned_integer (buf
, 8, byte_order
);
5907 if (record_read_memory (gdbarch
, ir
.addr
, buf
, 4))
5910 addr
= extract_unsigned_integer (buf
, 4, byte_order
);
5914 if (record_read_memory (gdbarch
, ir
.addr
, buf
, 2))
5917 addr
= extract_unsigned_integer (buf
, 2, byte_order
);
5919 if (record_full_arch_list_add_mem (addr
, 1 << ir
.ot
))
5924 case 0xb0: /* mov R, Ib */
5932 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((ir
.regmap
[X86_RECORD_R8_REGNUM
])
5933 ? ((opcode
& 0x7) | ir
.rex_b
)
5934 : ((opcode
& 0x7) & 0x3));
5937 case 0xb8: /* mov R, Iv */
5945 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode
& 0x7) | ir
.rex_b
);
5948 case 0x91: /* xchg R, EAX */
5955 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5956 I386_RECORD_FULL_ARCH_LIST_ADD_REG (opcode
& 0x7);
5959 case 0x86: /* xchg Ev, Gv */
5961 if ((opcode
& 1) == 0)
5964 ir
.ot
= ir
.dflag
+ OT_WORD
;
5965 if (i386_record_modrm (&ir
))
5970 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5972 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
5976 if (i386_record_lea_modrm (&ir
))
5980 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5982 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5985 case 0xc4: /* les Gv */
5986 case 0xc5: /* lds Gv */
5987 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5993 case 0x0fb2: /* lss Gv */
5994 case 0x0fb4: /* lfs Gv */
5995 case 0x0fb5: /* lgs Gv */
5996 if (i386_record_modrm (&ir
))
6004 opcode
= opcode
<< 8 | ir
.modrm
;
6009 case 0xc4: /* les Gv */
6010 regnum
= X86_RECORD_ES_REGNUM
;
6012 case 0xc5: /* lds Gv */
6013 regnum
= X86_RECORD_DS_REGNUM
;
6015 case 0x0fb2: /* lss Gv */
6016 regnum
= X86_RECORD_SS_REGNUM
;
6018 case 0x0fb4: /* lfs Gv */
6019 regnum
= X86_RECORD_FS_REGNUM
;
6021 case 0x0fb5: /* lgs Gv */
6022 regnum
= X86_RECORD_GS_REGNUM
;
6025 I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum
);
6026 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
| rex_r
);
6027 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6030 case 0xc0: /* shifts */
6036 if ((opcode
& 1) == 0)
6039 ir
.ot
= ir
.dflag
+ OT_WORD
;
6040 if (i386_record_modrm (&ir
))
6042 if (ir
.mod
!= 3 && (opcode
== 0xd2 || opcode
== 0xd3))
6044 if (i386_record_lea_modrm (&ir
))
6050 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
6052 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
6054 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6061 if (i386_record_modrm (&ir
))
6065 if (record_full_arch_list_add_reg (ir
.regcache
, ir
.rm
))
6070 if (i386_record_lea_modrm (&ir
))
6075 case 0xd8: /* Floats. */
6083 if (i386_record_modrm (&ir
))
6085 ir
.reg
|= ((opcode
& 7) << 3);
6091 if (i386_record_lea_modrm_addr (&ir
, &addr64
))
6099 /* For fcom, ficom nothing to do. */
6105 /* For fcomp, ficomp pop FPU stack, store all. */
6106 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6133 /* For fadd, fmul, fsub, fsubr, fdiv, fdivr, fiadd, fimul,
6134 fisub, fisubr, fidiv, fidivr, modR/M.reg is an extension
6135 of code, always affects st(0) register. */
6136 if (i386_record_floats (gdbarch
, &ir
, I387_ST0_REGNUM (tdep
)))
6160 /* Handling fld, fild. */
6161 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6165 switch (ir
.reg
>> 4)
6168 if (record_full_arch_list_add_mem (addr64
, 4))
6172 if (record_full_arch_list_add_mem (addr64
, 8))
6178 if (record_full_arch_list_add_mem (addr64
, 2))
6184 switch (ir
.reg
>> 4)
6187 if (record_full_arch_list_add_mem (addr64
, 4))
6189 if (3 == (ir
.reg
& 7))
6191 /* For fstp m32fp. */
6192 if (i386_record_floats (gdbarch
, &ir
,
6193 I386_SAVE_FPU_REGS
))
6198 if (record_full_arch_list_add_mem (addr64
, 4))
6200 if ((3 == (ir
.reg
& 7))
6201 || (5 == (ir
.reg
& 7))
6202 || (7 == (ir
.reg
& 7)))
6204 /* For fstp insn. */
6205 if (i386_record_floats (gdbarch
, &ir
,
6206 I386_SAVE_FPU_REGS
))
6211 if (record_full_arch_list_add_mem (addr64
, 8))
6213 if (3 == (ir
.reg
& 7))
6215 /* For fstp m64fp. */
6216 if (i386_record_floats (gdbarch
, &ir
,
6217 I386_SAVE_FPU_REGS
))
6222 if ((3 <= (ir
.reg
& 7)) && (6 <= (ir
.reg
& 7)))
6224 /* For fistp, fbld, fild, fbstp. */
6225 if (i386_record_floats (gdbarch
, &ir
,
6226 I386_SAVE_FPU_REGS
))
6231 if (record_full_arch_list_add_mem (addr64
, 2))
6240 if (i386_record_floats (gdbarch
, &ir
,
6241 I386_SAVE_FPU_ENV_REG_STACK
))
6246 if (i386_record_floats (gdbarch
, &ir
, I387_FCTRL_REGNUM (tdep
)))
6251 if (i386_record_floats (gdbarch
, &ir
,
6252 I386_SAVE_FPU_ENV_REG_STACK
))
6258 if (record_full_arch_list_add_mem (addr64
, 28))
6263 if (record_full_arch_list_add_mem (addr64
, 14))
6269 if (record_full_arch_list_add_mem (addr64
, 2))
6271 /* Insn fstp, fbstp. */
6272 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6277 if (record_full_arch_list_add_mem (addr64
, 10))
6283 if (record_full_arch_list_add_mem (addr64
, 28))
6289 if (record_full_arch_list_add_mem (addr64
, 14))
6293 if (record_full_arch_list_add_mem (addr64
, 80))
6296 if (i386_record_floats (gdbarch
, &ir
,
6297 I386_SAVE_FPU_ENV_REG_STACK
))
6301 if (record_full_arch_list_add_mem (addr64
, 8))
6304 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6309 opcode
= opcode
<< 8 | ir
.modrm
;
6314 /* Opcode is an extension of modR/M byte. */
6320 if (i386_record_floats (gdbarch
, &ir
, I387_ST0_REGNUM (tdep
)))
6324 if (0x0c == (ir
.modrm
>> 4))
6326 if ((ir
.modrm
& 0x0f) <= 7)
6328 if (i386_record_floats (gdbarch
, &ir
,
6329 I386_SAVE_FPU_REGS
))
6334 if (i386_record_floats (gdbarch
, &ir
,
6335 I387_ST0_REGNUM (tdep
)))
6337 /* If only st(0) is changing, then we have already
6339 if ((ir
.modrm
& 0x0f) - 0x08)
6341 if (i386_record_floats (gdbarch
, &ir
,
6342 I387_ST0_REGNUM (tdep
) +
6343 ((ir
.modrm
& 0x0f) - 0x08)))
6361 if (i386_record_floats (gdbarch
, &ir
,
6362 I387_ST0_REGNUM (tdep
)))
6380 if (i386_record_floats (gdbarch
, &ir
,
6381 I386_SAVE_FPU_REGS
))
6385 if (i386_record_floats (gdbarch
, &ir
,
6386 I387_ST0_REGNUM (tdep
)))
6388 if (i386_record_floats (gdbarch
, &ir
,
6389 I387_ST0_REGNUM (tdep
) + 1))
6396 if (0xe9 == ir
.modrm
)
6398 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6401 else if ((0x0c == ir
.modrm
>> 4) || (0x0d == ir
.modrm
>> 4))
6403 if (i386_record_floats (gdbarch
, &ir
,
6404 I387_ST0_REGNUM (tdep
)))
6406 if (((ir
.modrm
& 0x0f) > 0) && ((ir
.modrm
& 0x0f) <= 7))
6408 if (i386_record_floats (gdbarch
, &ir
,
6409 I387_ST0_REGNUM (tdep
) +
6413 else if ((ir
.modrm
& 0x0f) - 0x08)
6415 if (i386_record_floats (gdbarch
, &ir
,
6416 I387_ST0_REGNUM (tdep
) +
6417 ((ir
.modrm
& 0x0f) - 0x08)))
6423 if (0xe3 == ir
.modrm
)
6425 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_ENV
))
6428 else if ((0x0c == ir
.modrm
>> 4) || (0x0d == ir
.modrm
>> 4))
6430 if (i386_record_floats (gdbarch
, &ir
,
6431 I387_ST0_REGNUM (tdep
)))
6433 if (((ir
.modrm
& 0x0f) > 0) && ((ir
.modrm
& 0x0f) <= 7))
6435 if (i386_record_floats (gdbarch
, &ir
,
6436 I387_ST0_REGNUM (tdep
) +
6440 else if ((ir
.modrm
& 0x0f) - 0x08)
6442 if (i386_record_floats (gdbarch
, &ir
,
6443 I387_ST0_REGNUM (tdep
) +
6444 ((ir
.modrm
& 0x0f) - 0x08)))
6450 if ((0x0c == ir
.modrm
>> 4)
6451 || (0x0d == ir
.modrm
>> 4)
6452 || (0x0f == ir
.modrm
>> 4))
6454 if ((ir
.modrm
& 0x0f) <= 7)
6456 if (i386_record_floats (gdbarch
, &ir
,
6457 I387_ST0_REGNUM (tdep
) +
6463 if (i386_record_floats (gdbarch
, &ir
,
6464 I387_ST0_REGNUM (tdep
) +
6465 ((ir
.modrm
& 0x0f) - 0x08)))
6471 if (0x0c == ir
.modrm
>> 4)
6473 if (i386_record_floats (gdbarch
, &ir
,
6474 I387_FTAG_REGNUM (tdep
)))
6477 else if ((0x0d == ir
.modrm
>> 4) || (0x0e == ir
.modrm
>> 4))
6479 if ((ir
.modrm
& 0x0f) <= 7)
6481 if (i386_record_floats (gdbarch
, &ir
,
6482 I387_ST0_REGNUM (tdep
) +
6488 if (i386_record_floats (gdbarch
, &ir
,
6489 I386_SAVE_FPU_REGS
))
6495 if ((0x0c == ir
.modrm
>> 4)
6496 || (0x0e == ir
.modrm
>> 4)
6497 || (0x0f == ir
.modrm
>> 4)
6498 || (0xd9 == ir
.modrm
))
6500 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6505 if (0xe0 == ir
.modrm
)
6507 if (record_full_arch_list_add_reg (ir
.regcache
,
6511 else if ((0x0f == ir
.modrm
>> 4) || (0x0e == ir
.modrm
>> 4))
6513 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6521 case 0xa4: /* movsS */
6523 case 0xaa: /* stosS */
6525 case 0x6c: /* insS */
6527 regcache_raw_read_unsigned (ir
.regcache
,
6528 ir
.regmap
[X86_RECORD_RECX_REGNUM
],
6534 if ((opcode
& 1) == 0)
6537 ir
.ot
= ir
.dflag
+ OT_WORD
;
6538 regcache_raw_read_unsigned (ir
.regcache
,
6539 ir
.regmap
[X86_RECORD_REDI_REGNUM
],
6542 regcache_raw_read_unsigned (ir
.regcache
,
6543 ir
.regmap
[X86_RECORD_ES_REGNUM
],
6545 regcache_raw_read_unsigned (ir
.regcache
,
6546 ir
.regmap
[X86_RECORD_DS_REGNUM
],
6548 if (ir
.aflag
&& (es
!= ds
))
6550 /* addr += ((uint32_t) read_register (I386_ES_REGNUM)) << 4; */
6551 if (record_full_memory_query
)
6554 Process record ignores the memory change of instruction at address %s\n\
6555 because it can't get the value of the segment register.\n\
6556 Do you want to stop the program?"),
6557 paddress (gdbarch
, ir
.orig_addr
)))
6563 if (record_full_arch_list_add_mem (addr
, 1 << ir
.ot
))
6567 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
))
6568 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
6569 if (opcode
== 0xa4 || opcode
== 0xa5)
6570 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM
);
6571 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM
);
6572 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6576 case 0xa6: /* cmpsS */
6578 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM
);
6579 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM
);
6580 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
))
6581 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
6582 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6585 case 0xac: /* lodsS */
6587 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
6588 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM
);
6589 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
))
6590 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
6591 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6594 case 0xae: /* scasS */
6596 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM
);
6597 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
))
6598 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
6599 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6602 case 0x6e: /* outsS */
6604 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM
);
6605 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
))
6606 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
6607 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6610 case 0xe4: /* port I/O */
6614 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6615 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
6625 case 0xc2: /* ret im */
6626 case 0xc3: /* ret */
6627 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
6628 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6631 case 0xca: /* lret im */
6632 case 0xcb: /* lret */
6633 case 0xcf: /* iret */
6634 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM
);
6635 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
6636 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6639 case 0xe8: /* call im */
6640 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && ir
.dflag
)
6642 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
6646 case 0x9a: /* lcall im */
6647 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
6652 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM
);
6653 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
6657 case 0xe9: /* jmp im */
6658 case 0xea: /* ljmp im */
6659 case 0xeb: /* jmp Jb */
6660 case 0x70: /* jcc Jb */
6676 case 0x0f80: /* jcc Jv */
6694 case 0x0f90: /* setcc Gv */
6710 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6712 if (i386_record_modrm (&ir
))
6715 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rex_b
? (ir
.rm
| ir
.rex_b
)
6719 if (i386_record_lea_modrm (&ir
))
6724 case 0x0f40: /* cmov Gv, Ev */
6740 if (i386_record_modrm (&ir
))
6743 if (ir
.dflag
== OT_BYTE
)
6745 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
6749 case 0x9c: /* pushf */
6750 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6751 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && ir
.dflag
)
6753 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
6757 case 0x9d: /* popf */
6758 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
6759 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6762 case 0x9e: /* sahf */
6763 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
6769 case 0xf5: /* cmc */
6770 case 0xf8: /* clc */
6771 case 0xf9: /* stc */
6772 case 0xfc: /* cld */
6773 case 0xfd: /* std */
6774 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6777 case 0x9f: /* lahf */
6778 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
6783 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6784 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
6787 /* bit operations */
6788 case 0x0fba: /* bt/bts/btr/btc Gv, im */
6789 ir
.ot
= ir
.dflag
+ OT_WORD
;
6790 if (i386_record_modrm (&ir
))
6795 opcode
= opcode
<< 8 | ir
.modrm
;
6801 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
6804 if (i386_record_lea_modrm (&ir
))
6808 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6811 case 0x0fa3: /* bt Gv, Ev */
6812 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6815 case 0x0fab: /* bts */
6816 case 0x0fb3: /* btr */
6817 case 0x0fbb: /* btc */
6818 ir
.ot
= ir
.dflag
+ OT_WORD
;
6819 if (i386_record_modrm (&ir
))
6822 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
6826 if (i386_record_lea_modrm_addr (&ir
, &addr64
))
6828 regcache_raw_read_unsigned (ir
.regcache
,
6829 ir
.regmap
[ir
.reg
| rex_r
],
6834 addr64
+= ((int16_t) addr
>> 4) << 4;
6837 addr64
+= ((int32_t) addr
>> 5) << 5;
6840 addr64
+= ((int64_t) addr
>> 6) << 6;
6843 if (record_full_arch_list_add_mem (addr64
, 1 << ir
.ot
))
6845 if (i386_record_lea_modrm (&ir
))
6848 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6851 case 0x0fbc: /* bsf */
6852 case 0x0fbd: /* bsr */
6853 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
| rex_r
);
6854 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6858 case 0x27: /* daa */
6859 case 0x2f: /* das */
6860 case 0x37: /* aaa */
6861 case 0x3f: /* aas */
6862 case 0xd4: /* aam */
6863 case 0xd5: /* aad */
6864 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
6869 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
6870 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6874 case 0x90: /* nop */
6875 if (prefixes
& PREFIX_LOCK
)
6882 case 0x9b: /* fwait */
6883 if (record_read_memory (gdbarch
, ir
.addr
, &opcode8
, 1))
6885 opcode
= (uint32_t) opcode8
;
6891 case 0xcc: /* int3 */
6892 gdb_printf (gdb_stderr
,
6893 _("Process record does not support instruction "
6900 case 0xcd: /* int */
6904 if (record_read_memory (gdbarch
, ir
.addr
, &interrupt
, 1))
6907 if (interrupt
!= 0x80
6908 || tdep
->i386_intx80_record
== NULL
)
6910 gdb_printf (gdb_stderr
,
6911 _("Process record does not support "
6912 "instruction int 0x%02x.\n"),
6917 ret
= tdep
->i386_intx80_record (ir
.regcache
);
6924 case 0xce: /* into */
6925 gdb_printf (gdb_stderr
,
6926 _("Process record does not support "
6927 "instruction into.\n"));
6932 case 0xfa: /* cli */
6933 case 0xfb: /* sti */
6936 case 0x62: /* bound */
6937 gdb_printf (gdb_stderr
,
6938 _("Process record does not support "
6939 "instruction bound.\n"));
6944 case 0x0fc8: /* bswap reg */
6952 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode
& 7) | ir
.rex_b
);
6955 case 0xd6: /* salc */
6956 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
6961 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
6962 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6965 case 0xe0: /* loopnz */
6966 case 0xe1: /* loopz */
6967 case 0xe2: /* loop */
6968 case 0xe3: /* jecxz */
6969 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
6970 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6973 case 0x0f30: /* wrmsr */
6974 gdb_printf (gdb_stderr
,
6975 _("Process record does not support "
6976 "instruction wrmsr.\n"));
6981 case 0x0f32: /* rdmsr */
6982 gdb_printf (gdb_stderr
,
6983 _("Process record does not support "
6984 "instruction rdmsr.\n"));
6989 case 0x0f01f9: /* rdtscp */
6990 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
6992 case 0x0f31: /* rdtsc */
6993 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
6994 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
6997 case 0x0f34: /* sysenter */
7000 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
7005 if (tdep
->i386_sysenter_record
== NULL
)
7007 gdb_printf (gdb_stderr
,
7008 _("Process record does not support "
7009 "instruction sysenter.\n"));
7013 ret
= tdep
->i386_sysenter_record (ir
.regcache
);
7019 case 0x0f35: /* sysexit */
7020 gdb_printf (gdb_stderr
,
7021 _("Process record does not support "
7022 "instruction sysexit.\n"));
7027 case 0x0f05: /* syscall */
7030 if (tdep
->i386_syscall_record
== NULL
)
7032 gdb_printf (gdb_stderr
,
7033 _("Process record does not support "
7034 "instruction syscall.\n"));
7038 ret
= tdep
->i386_syscall_record (ir
.regcache
);
7044 case 0x0f07: /* sysret */
7045 gdb_printf (gdb_stderr
,
7046 _("Process record does not support "
7047 "instruction sysret.\n"));
7052 case 0x0fa2: /* cpuid */
7053 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
7054 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
7055 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
7056 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBX_REGNUM
);
7059 case 0xf4: /* hlt */
7060 gdb_printf (gdb_stderr
,
7061 _("Process record does not support "
7062 "instruction hlt.\n"));
7068 if (i386_record_modrm (&ir
))
7075 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
7079 if (i386_record_lea_modrm (&ir
))
7088 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7092 opcode
= opcode
<< 8 | ir
.modrm
;
7099 if (i386_record_modrm (&ir
))
7101 if (ir
.modrm
== 0xf9)
7103 opcode
= (opcode
<< 8) | 0xf9;
7115 opcode
= opcode
<< 8 | ir
.modrm
;
7118 if (ir
.override
>= 0)
7120 if (record_full_memory_query
)
7123 Process record ignores the memory change of instruction at address %s\n\
7124 because it can't get the value of the segment register.\n\
7125 Do you want to stop the program?"),
7126 paddress (gdbarch
, ir
.orig_addr
)))
7132 if (i386_record_lea_modrm_addr (&ir
, &addr64
))
7134 if (record_full_arch_list_add_mem (addr64
, 2))
7137 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
7139 if (record_full_arch_list_add_mem (addr64
, 8))
7144 if (record_full_arch_list_add_mem (addr64
, 4))
7155 case 0: /* monitor */
7158 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7162 opcode
= opcode
<< 8 | ir
.modrm
;
7170 if (ir
.override
>= 0)
7172 if (record_full_memory_query
)
7175 Process record ignores the memory change of instruction at address %s\n\
7176 because it can't get the value of the segment register.\n\
7177 Do you want to stop the program?"),
7178 paddress (gdbarch
, ir
.orig_addr
)))
7186 if (i386_record_lea_modrm_addr (&ir
, &addr64
))
7188 if (record_full_arch_list_add_mem (addr64
, 2))
7191 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
7193 if (record_full_arch_list_add_mem (addr64
, 8))
7198 if (record_full_arch_list_add_mem (addr64
, 4))
7210 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
7211 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
7215 else if (ir
.rm
== 1)
7223 opcode
= opcode
<< 8 | ir
.modrm
;
7230 if (record_full_arch_list_add_reg (ir
.regcache
, ir
.rm
| ir
.rex_b
))
7236 if (i386_record_lea_modrm (&ir
))
7239 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7242 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7244 case 7: /* invlpg */
7247 if (ir
.rm
== 0 && ir
.regmap
[X86_RECORD_R8_REGNUM
])
7248 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_GS_REGNUM
);
7252 opcode
= opcode
<< 8 | ir
.modrm
;
7257 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7261 opcode
= opcode
<< 8 | ir
.modrm
;
7267 case 0x0f08: /* invd */
7268 case 0x0f09: /* wbinvd */
7271 case 0x63: /* arpl */
7272 if (i386_record_modrm (&ir
))
7274 if (ir
.mod
== 3 || ir
.regmap
[X86_RECORD_R8_REGNUM
])
7276 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.regmap
[X86_RECORD_R8_REGNUM
]
7277 ? (ir
.reg
| rex_r
) : ir
.rm
);
7281 ir
.ot
= ir
.dflag
? OT_LONG
: OT_WORD
;
7282 if (i386_record_lea_modrm (&ir
))
7285 if (!ir
.regmap
[X86_RECORD_R8_REGNUM
])
7286 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7289 case 0x0f02: /* lar */
7290 case 0x0f03: /* lsl */
7291 if (i386_record_modrm (&ir
))
7293 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
| rex_r
);
7294 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7298 if (i386_record_modrm (&ir
))
7300 if (ir
.mod
== 3 && ir
.reg
== 3)
7303 opcode
= opcode
<< 8 | ir
.modrm
;
7315 /* nop (multi byte) */
7318 case 0x0f20: /* mov reg, crN */
7319 case 0x0f22: /* mov crN, reg */
7320 if (i386_record_modrm (&ir
))
7322 if ((ir
.modrm
& 0xc0) != 0xc0)
7325 opcode
= opcode
<< 8 | ir
.modrm
;
7336 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7338 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
7342 opcode
= opcode
<< 8 | ir
.modrm
;
7348 case 0x0f21: /* mov reg, drN */
7349 case 0x0f23: /* mov drN, reg */
7350 if (i386_record_modrm (&ir
))
7352 if ((ir
.modrm
& 0xc0) != 0xc0 || ir
.reg
== 4
7353 || ir
.reg
== 5 || ir
.reg
>= 8)
7356 opcode
= opcode
<< 8 | ir
.modrm
;
7360 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7362 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
7365 case 0x0f06: /* clts */
7366 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7369 /* MMX 3DNow! SSE SSE2 SSE3 SSSE3 SSE4 */
7371 case 0x0f0d: /* 3DNow! prefetch */
7374 case 0x0f0e: /* 3DNow! femms */
7375 case 0x0f77: /* emms */
7376 if (i386_fpc_regnum_p (gdbarch
, I387_FTAG_REGNUM(tdep
)))
7378 record_full_arch_list_add_reg (ir
.regcache
, I387_FTAG_REGNUM(tdep
));
7381 case 0x0f0f: /* 3DNow! data */
7382 if (i386_record_modrm (&ir
))
7384 if (record_read_memory (gdbarch
, ir
.addr
, &opcode8
, 1))
7389 case 0x0c: /* 3DNow! pi2fw */
7390 case 0x0d: /* 3DNow! pi2fd */
7391 case 0x1c: /* 3DNow! pf2iw */
7392 case 0x1d: /* 3DNow! pf2id */
7393 case 0x8a: /* 3DNow! pfnacc */
7394 case 0x8e: /* 3DNow! pfpnacc */
7395 case 0x90: /* 3DNow! pfcmpge */
7396 case 0x94: /* 3DNow! pfmin */
7397 case 0x96: /* 3DNow! pfrcp */
7398 case 0x97: /* 3DNow! pfrsqrt */
7399 case 0x9a: /* 3DNow! pfsub */
7400 case 0x9e: /* 3DNow! pfadd */
7401 case 0xa0: /* 3DNow! pfcmpgt */
7402 case 0xa4: /* 3DNow! pfmax */
7403 case 0xa6: /* 3DNow! pfrcpit1 */
7404 case 0xa7: /* 3DNow! pfrsqit1 */
7405 case 0xaa: /* 3DNow! pfsubr */
7406 case 0xae: /* 3DNow! pfacc */
7407 case 0xb0: /* 3DNow! pfcmpeq */
7408 case 0xb4: /* 3DNow! pfmul */
7409 case 0xb6: /* 3DNow! pfrcpit2 */
7410 case 0xb7: /* 3DNow! pmulhrw */
7411 case 0xbb: /* 3DNow! pswapd */
7412 case 0xbf: /* 3DNow! pavgusb */
7413 if (!i386_mmx_regnum_p (gdbarch
, I387_MM0_REGNUM (tdep
) + ir
.reg
))
7414 goto no_support_3dnow_data
;
7415 record_full_arch_list_add_reg (ir
.regcache
, ir
.reg
);
7419 no_support_3dnow_data
:
7420 opcode
= (opcode
<< 8) | opcode8
;
7426 case 0x0faa: /* rsm */
7427 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7428 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
7429 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
7430 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
7431 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBX_REGNUM
);
7432 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
7433 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM
);
7434 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM
);
7435 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM
);
7439 if (i386_record_modrm (&ir
))
7443 case 0: /* fxsave */
7447 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7448 if (i386_record_lea_modrm_addr (&ir
, &tmpu64
))
7450 if (record_full_arch_list_add_mem (tmpu64
, 512))
7455 case 1: /* fxrstor */
7459 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7461 for (i
= I387_MM0_REGNUM (tdep
);
7462 i386_mmx_regnum_p (gdbarch
, i
); i
++)
7463 record_full_arch_list_add_reg (ir
.regcache
, i
);
7465 for (i
= I387_XMM0_REGNUM (tdep
);
7466 i386_xmm_regnum_p (gdbarch
, i
); i
++)
7467 record_full_arch_list_add_reg (ir
.regcache
, i
);
7469 if (i386_mxcsr_regnum_p (gdbarch
, I387_MXCSR_REGNUM(tdep
)))
7470 record_full_arch_list_add_reg (ir
.regcache
,
7471 I387_MXCSR_REGNUM(tdep
));
7473 for (i
= I387_ST0_REGNUM (tdep
);
7474 i386_fp_regnum_p (gdbarch
, i
); i
++)
7475 record_full_arch_list_add_reg (ir
.regcache
, i
);
7477 for (i
= I387_FCTRL_REGNUM (tdep
);
7478 i386_fpc_regnum_p (gdbarch
, i
); i
++)
7479 record_full_arch_list_add_reg (ir
.regcache
, i
);
7483 case 2: /* ldmxcsr */
7484 if (!i386_mxcsr_regnum_p (gdbarch
, I387_MXCSR_REGNUM(tdep
)))
7486 record_full_arch_list_add_reg (ir
.regcache
, I387_MXCSR_REGNUM(tdep
));
7489 case 3: /* stmxcsr */
7491 if (i386_record_lea_modrm (&ir
))
7495 case 5: /* lfence */
7496 case 6: /* mfence */
7497 case 7: /* sfence clflush */
7501 opcode
= (opcode
<< 8) | ir
.modrm
;
7507 case 0x0fc3: /* movnti */
7508 ir
.ot
= (ir
.dflag
== 2) ? OT_QUAD
: OT_LONG
;
7509 if (i386_record_modrm (&ir
))
7514 if (i386_record_lea_modrm (&ir
))
7518 /* Add prefix to opcode. */
7633 /* Mask out PREFIX_ADDR. */
7634 switch ((prefixes
& ~PREFIX_ADDR
))
7646 reswitch_prefix_add
:
7654 if (record_read_memory (gdbarch
, ir
.addr
, &opcode8
, 1))
7657 opcode
= (uint32_t) opcode8
| opcode
<< 8;
7658 goto reswitch_prefix_add
;
7661 case 0x0f10: /* movups */
7662 case 0x660f10: /* movupd */
7663 case 0xf30f10: /* movss */
7664 case 0xf20f10: /* movsd */
7665 case 0x0f12: /* movlps */
7666 case 0x660f12: /* movlpd */
7667 case 0xf30f12: /* movsldup */
7668 case 0xf20f12: /* movddup */
7669 case 0x0f14: /* unpcklps */
7670 case 0x660f14: /* unpcklpd */
7671 case 0x0f15: /* unpckhps */
7672 case 0x660f15: /* unpckhpd */
7673 case 0x0f16: /* movhps */
7674 case 0x660f16: /* movhpd */
7675 case 0xf30f16: /* movshdup */
7676 case 0x0f28: /* movaps */
7677 case 0x660f28: /* movapd */
7678 case 0x0f2a: /* cvtpi2ps */
7679 case 0x660f2a: /* cvtpi2pd */
7680 case 0xf30f2a: /* cvtsi2ss */
7681 case 0xf20f2a: /* cvtsi2sd */
7682 case 0x0f2c: /* cvttps2pi */
7683 case 0x660f2c: /* cvttpd2pi */
7684 case 0x0f2d: /* cvtps2pi */
7685 case 0x660f2d: /* cvtpd2pi */
7686 case 0x660f3800: /* pshufb */
7687 case 0x660f3801: /* phaddw */
7688 case 0x660f3802: /* phaddd */
7689 case 0x660f3803: /* phaddsw */
7690 case 0x660f3804: /* pmaddubsw */
7691 case 0x660f3805: /* phsubw */
7692 case 0x660f3806: /* phsubd */
7693 case 0x660f3807: /* phsubsw */
7694 case 0x660f3808: /* psignb */
7695 case 0x660f3809: /* psignw */
7696 case 0x660f380a: /* psignd */
7697 case 0x660f380b: /* pmulhrsw */
7698 case 0x660f3810: /* pblendvb */
7699 case 0x660f3814: /* blendvps */
7700 case 0x660f3815: /* blendvpd */
7701 case 0x660f381c: /* pabsb */
7702 case 0x660f381d: /* pabsw */
7703 case 0x660f381e: /* pabsd */
7704 case 0x660f3820: /* pmovsxbw */
7705 case 0x660f3821: /* pmovsxbd */
7706 case 0x660f3822: /* pmovsxbq */
7707 case 0x660f3823: /* pmovsxwd */
7708 case 0x660f3824: /* pmovsxwq */
7709 case 0x660f3825: /* pmovsxdq */
7710 case 0x660f3828: /* pmuldq */
7711 case 0x660f3829: /* pcmpeqq */
7712 case 0x660f382a: /* movntdqa */
7713 case 0x660f3a08: /* roundps */
7714 case 0x660f3a09: /* roundpd */
7715 case 0x660f3a0a: /* roundss */
7716 case 0x660f3a0b: /* roundsd */
7717 case 0x660f3a0c: /* blendps */
7718 case 0x660f3a0d: /* blendpd */
7719 case 0x660f3a0e: /* pblendw */
7720 case 0x660f3a0f: /* palignr */
7721 case 0x660f3a20: /* pinsrb */
7722 case 0x660f3a21: /* insertps */
7723 case 0x660f3a22: /* pinsrd pinsrq */
7724 case 0x660f3a40: /* dpps */
7725 case 0x660f3a41: /* dppd */
7726 case 0x660f3a42: /* mpsadbw */
7727 case 0x660f3a60: /* pcmpestrm */
7728 case 0x660f3a61: /* pcmpestri */
7729 case 0x660f3a62: /* pcmpistrm */
7730 case 0x660f3a63: /* pcmpistri */
7731 case 0x0f51: /* sqrtps */
7732 case 0x660f51: /* sqrtpd */
7733 case 0xf20f51: /* sqrtsd */
7734 case 0xf30f51: /* sqrtss */
7735 case 0x0f52: /* rsqrtps */
7736 case 0xf30f52: /* rsqrtss */
7737 case 0x0f53: /* rcpps */
7738 case 0xf30f53: /* rcpss */
7739 case 0x0f54: /* andps */
7740 case 0x660f54: /* andpd */
7741 case 0x0f55: /* andnps */
7742 case 0x660f55: /* andnpd */
7743 case 0x0f56: /* orps */
7744 case 0x660f56: /* orpd */
7745 case 0x0f57: /* xorps */
7746 case 0x660f57: /* xorpd */
7747 case 0x0f58: /* addps */
7748 case 0x660f58: /* addpd */
7749 case 0xf20f58: /* addsd */
7750 case 0xf30f58: /* addss */
7751 case 0x0f59: /* mulps */
7752 case 0x660f59: /* mulpd */
7753 case 0xf20f59: /* mulsd */
7754 case 0xf30f59: /* mulss */
7755 case 0x0f5a: /* cvtps2pd */
7756 case 0x660f5a: /* cvtpd2ps */
7757 case 0xf20f5a: /* cvtsd2ss */
7758 case 0xf30f5a: /* cvtss2sd */
7759 case 0x0f5b: /* cvtdq2ps */
7760 case 0x660f5b: /* cvtps2dq */
7761 case 0xf30f5b: /* cvttps2dq */
7762 case 0x0f5c: /* subps */
7763 case 0x660f5c: /* subpd */
7764 case 0xf20f5c: /* subsd */
7765 case 0xf30f5c: /* subss */
7766 case 0x0f5d: /* minps */
7767 case 0x660f5d: /* minpd */
7768 case 0xf20f5d: /* minsd */
7769 case 0xf30f5d: /* minss */
7770 case 0x0f5e: /* divps */
7771 case 0x660f5e: /* divpd */
7772 case 0xf20f5e: /* divsd */
7773 case 0xf30f5e: /* divss */
7774 case 0x0f5f: /* maxps */
7775 case 0x660f5f: /* maxpd */
7776 case 0xf20f5f: /* maxsd */
7777 case 0xf30f5f: /* maxss */
7778 case 0x660f60: /* punpcklbw */
7779 case 0x660f61: /* punpcklwd */
7780 case 0x660f62: /* punpckldq */
7781 case 0x660f63: /* packsswb */
7782 case 0x660f64: /* pcmpgtb */
7783 case 0x660f65: /* pcmpgtw */
7784 case 0x660f66: /* pcmpgtd */
7785 case 0x660f67: /* packuswb */
7786 case 0x660f68: /* punpckhbw */
7787 case 0x660f69: /* punpckhwd */
7788 case 0x660f6a: /* punpckhdq */
7789 case 0x660f6b: /* packssdw */
7790 case 0x660f6c: /* punpcklqdq */
7791 case 0x660f6d: /* punpckhqdq */
7792 case 0x660f6e: /* movd */
7793 case 0x660f6f: /* movdqa */
7794 case 0xf30f6f: /* movdqu */
7795 case 0x660f70: /* pshufd */
7796 case 0xf20f70: /* pshuflw */
7797 case 0xf30f70: /* pshufhw */
7798 case 0x660f74: /* pcmpeqb */
7799 case 0x660f75: /* pcmpeqw */
7800 case 0x660f76: /* pcmpeqd */
7801 case 0x660f7c: /* haddpd */
7802 case 0xf20f7c: /* haddps */
7803 case 0x660f7d: /* hsubpd */
7804 case 0xf20f7d: /* hsubps */
7805 case 0xf30f7e: /* movq */
7806 case 0x0fc2: /* cmpps */
7807 case 0x660fc2: /* cmppd */
7808 case 0xf20fc2: /* cmpsd */
7809 case 0xf30fc2: /* cmpss */
7810 case 0x660fc4: /* pinsrw */
7811 case 0x0fc6: /* shufps */
7812 case 0x660fc6: /* shufpd */
7813 case 0x660fd0: /* addsubpd */
7814 case 0xf20fd0: /* addsubps */
7815 case 0x660fd1: /* psrlw */
7816 case 0x660fd2: /* psrld */
7817 case 0x660fd3: /* psrlq */
7818 case 0x660fd4: /* paddq */
7819 case 0x660fd5: /* pmullw */
7820 case 0xf30fd6: /* movq2dq */
7821 case 0x660fd8: /* psubusb */
7822 case 0x660fd9: /* psubusw */
7823 case 0x660fda: /* pminub */
7824 case 0x660fdb: /* pand */
7825 case 0x660fdc: /* paddusb */
7826 case 0x660fdd: /* paddusw */
7827 case 0x660fde: /* pmaxub */
7828 case 0x660fdf: /* pandn */
7829 case 0x660fe0: /* pavgb */
7830 case 0x660fe1: /* psraw */
7831 case 0x660fe2: /* psrad */
7832 case 0x660fe3: /* pavgw */
7833 case 0x660fe4: /* pmulhuw */
7834 case 0x660fe5: /* pmulhw */
7835 case 0x660fe6: /* cvttpd2dq */
7836 case 0xf20fe6: /* cvtpd2dq */
7837 case 0xf30fe6: /* cvtdq2pd */
7838 case 0x660fe8: /* psubsb */
7839 case 0x660fe9: /* psubsw */
7840 case 0x660fea: /* pminsw */
7841 case 0x660feb: /* por */
7842 case 0x660fec: /* paddsb */
7843 case 0x660fed: /* paddsw */
7844 case 0x660fee: /* pmaxsw */
7845 case 0x660fef: /* pxor */
7846 case 0xf20ff0: /* lddqu */
7847 case 0x660ff1: /* psllw */
7848 case 0x660ff2: /* pslld */
7849 case 0x660ff3: /* psllq */
7850 case 0x660ff4: /* pmuludq */
7851 case 0x660ff5: /* pmaddwd */
7852 case 0x660ff6: /* psadbw */
7853 case 0x660ff8: /* psubb */
7854 case 0x660ff9: /* psubw */
7855 case 0x660ffa: /* psubd */
7856 case 0x660ffb: /* psubq */
7857 case 0x660ffc: /* paddb */
7858 case 0x660ffd: /* paddw */
7859 case 0x660ffe: /* paddd */
7860 if (i386_record_modrm (&ir
))
7863 if (!i386_xmm_regnum_p (gdbarch
, I387_XMM0_REGNUM (tdep
) + ir
.reg
))
7865 record_full_arch_list_add_reg (ir
.regcache
,
7866 I387_XMM0_REGNUM (tdep
) + ir
.reg
);
7867 if ((opcode
& 0xfffffffc) == 0x660f3a60)
7868 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7871 case 0x0f11: /* movups */
7872 case 0x660f11: /* movupd */
7873 case 0xf30f11: /* movss */
7874 case 0xf20f11: /* movsd */
7875 case 0x0f13: /* movlps */
7876 case 0x660f13: /* movlpd */
7877 case 0x0f17: /* movhps */
7878 case 0x660f17: /* movhpd */
7879 case 0x0f29: /* movaps */
7880 case 0x660f29: /* movapd */
7881 case 0x660f3a14: /* pextrb */
7882 case 0x660f3a15: /* pextrw */
7883 case 0x660f3a16: /* pextrd pextrq */
7884 case 0x660f3a17: /* extractps */
7885 case 0x660f7f: /* movdqa */
7886 case 0xf30f7f: /* movdqu */
7887 if (i386_record_modrm (&ir
))
7891 if (opcode
== 0x0f13 || opcode
== 0x660f13
7892 || opcode
== 0x0f17 || opcode
== 0x660f17)
7895 if (!i386_xmm_regnum_p (gdbarch
,
7896 I387_XMM0_REGNUM (tdep
) + ir
.rm
))
7898 record_full_arch_list_add_reg (ir
.regcache
,
7899 I387_XMM0_REGNUM (tdep
) + ir
.rm
);
7921 if (i386_record_lea_modrm (&ir
))
7926 case 0x0f2b: /* movntps */
7927 case 0x660f2b: /* movntpd */
7928 case 0x0fe7: /* movntq */
7929 case 0x660fe7: /* movntdq */
7932 if (opcode
== 0x0fe7)
7936 if (i386_record_lea_modrm (&ir
))
7940 case 0xf30f2c: /* cvttss2si */
7941 case 0xf20f2c: /* cvttsd2si */
7942 case 0xf30f2d: /* cvtss2si */
7943 case 0xf20f2d: /* cvtsd2si */
7944 case 0xf20f38f0: /* crc32 */
7945 case 0xf20f38f1: /* crc32 */
7946 case 0x0f50: /* movmskps */
7947 case 0x660f50: /* movmskpd */
7948 case 0x0fc5: /* pextrw */
7949 case 0x660fc5: /* pextrw */
7950 case 0x0fd7: /* pmovmskb */
7951 case 0x660fd7: /* pmovmskb */
7952 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
| rex_r
);
7955 case 0x0f3800: /* pshufb */
7956 case 0x0f3801: /* phaddw */
7957 case 0x0f3802: /* phaddd */
7958 case 0x0f3803: /* phaddsw */
7959 case 0x0f3804: /* pmaddubsw */
7960 case 0x0f3805: /* phsubw */
7961 case 0x0f3806: /* phsubd */
7962 case 0x0f3807: /* phsubsw */
7963 case 0x0f3808: /* psignb */
7964 case 0x0f3809: /* psignw */
7965 case 0x0f380a: /* psignd */
7966 case 0x0f380b: /* pmulhrsw */
7967 case 0x0f381c: /* pabsb */
7968 case 0x0f381d: /* pabsw */
7969 case 0x0f381e: /* pabsd */
7970 case 0x0f382b: /* packusdw */
7971 case 0x0f3830: /* pmovzxbw */
7972 case 0x0f3831: /* pmovzxbd */
7973 case 0x0f3832: /* pmovzxbq */
7974 case 0x0f3833: /* pmovzxwd */
7975 case 0x0f3834: /* pmovzxwq */
7976 case 0x0f3835: /* pmovzxdq */
7977 case 0x0f3837: /* pcmpgtq */
7978 case 0x0f3838: /* pminsb */
7979 case 0x0f3839: /* pminsd */
7980 case 0x0f383a: /* pminuw */
7981 case 0x0f383b: /* pminud */
7982 case 0x0f383c: /* pmaxsb */
7983 case 0x0f383d: /* pmaxsd */
7984 case 0x0f383e: /* pmaxuw */
7985 case 0x0f383f: /* pmaxud */
7986 case 0x0f3840: /* pmulld */
7987 case 0x0f3841: /* phminposuw */
7988 case 0x0f3a0f: /* palignr */
7989 case 0x0f60: /* punpcklbw */
7990 case 0x0f61: /* punpcklwd */
7991 case 0x0f62: /* punpckldq */
7992 case 0x0f63: /* packsswb */
7993 case 0x0f64: /* pcmpgtb */
7994 case 0x0f65: /* pcmpgtw */
7995 case 0x0f66: /* pcmpgtd */
7996 case 0x0f67: /* packuswb */
7997 case 0x0f68: /* punpckhbw */
7998 case 0x0f69: /* punpckhwd */
7999 case 0x0f6a: /* punpckhdq */
8000 case 0x0f6b: /* packssdw */
8001 case 0x0f6e: /* movd */
8002 case 0x0f6f: /* movq */
8003 case 0x0f70: /* pshufw */
8004 case 0x0f74: /* pcmpeqb */
8005 case 0x0f75: /* pcmpeqw */
8006 case 0x0f76: /* pcmpeqd */
8007 case 0x0fc4: /* pinsrw */
8008 case 0x0fd1: /* psrlw */
8009 case 0x0fd2: /* psrld */
8010 case 0x0fd3: /* psrlq */
8011 case 0x0fd4: /* paddq */
8012 case 0x0fd5: /* pmullw */
8013 case 0xf20fd6: /* movdq2q */
8014 case 0x0fd8: /* psubusb */
8015 case 0x0fd9: /* psubusw */
8016 case 0x0fda: /* pminub */
8017 case 0x0fdb: /* pand */
8018 case 0x0fdc: /* paddusb */
8019 case 0x0fdd: /* paddusw */
8020 case 0x0fde: /* pmaxub */
8021 case 0x0fdf: /* pandn */
8022 case 0x0fe0: /* pavgb */
8023 case 0x0fe1: /* psraw */
8024 case 0x0fe2: /* psrad */
8025 case 0x0fe3: /* pavgw */
8026 case 0x0fe4: /* pmulhuw */
8027 case 0x0fe5: /* pmulhw */
8028 case 0x0fe8: /* psubsb */
8029 case 0x0fe9: /* psubsw */
8030 case 0x0fea: /* pminsw */
8031 case 0x0feb: /* por */
8032 case 0x0fec: /* paddsb */
8033 case 0x0fed: /* paddsw */
8034 case 0x0fee: /* pmaxsw */
8035 case 0x0fef: /* pxor */
8036 case 0x0ff1: /* psllw */
8037 case 0x0ff2: /* pslld */
8038 case 0x0ff3: /* psllq */
8039 case 0x0ff4: /* pmuludq */
8040 case 0x0ff5: /* pmaddwd */
8041 case 0x0ff6: /* psadbw */
8042 case 0x0ff8: /* psubb */
8043 case 0x0ff9: /* psubw */
8044 case 0x0ffa: /* psubd */
8045 case 0x0ffb: /* psubq */
8046 case 0x0ffc: /* paddb */
8047 case 0x0ffd: /* paddw */
8048 case 0x0ffe: /* paddd */
8049 if (i386_record_modrm (&ir
))
8051 if (!i386_mmx_regnum_p (gdbarch
, I387_MM0_REGNUM (tdep
) + ir
.reg
))
8053 record_full_arch_list_add_reg (ir
.regcache
,
8054 I387_MM0_REGNUM (tdep
) + ir
.reg
);
8057 case 0x0f71: /* psllw */
8058 case 0x0f72: /* pslld */
8059 case 0x0f73: /* psllq */
8060 if (i386_record_modrm (&ir
))
8062 if (!i386_mmx_regnum_p (gdbarch
, I387_MM0_REGNUM (tdep
) + ir
.rm
))
8064 record_full_arch_list_add_reg (ir
.regcache
,
8065 I387_MM0_REGNUM (tdep
) + ir
.rm
);
8068 case 0x660f71: /* psllw */
8069 case 0x660f72: /* pslld */
8070 case 0x660f73: /* psllq */
8071 if (i386_record_modrm (&ir
))
8074 if (!i386_xmm_regnum_p (gdbarch
, I387_XMM0_REGNUM (tdep
) + ir
.rm
))
8076 record_full_arch_list_add_reg (ir
.regcache
,
8077 I387_XMM0_REGNUM (tdep
) + ir
.rm
);
8080 case 0x0f7e: /* movd */
8081 case 0x660f7e: /* movd */
8082 if (i386_record_modrm (&ir
))
8085 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
8092 if (i386_record_lea_modrm (&ir
))
8097 case 0x0f7f: /* movq */
8098 if (i386_record_modrm (&ir
))
8102 if (!i386_mmx_regnum_p (gdbarch
, I387_MM0_REGNUM (tdep
) + ir
.rm
))
8104 record_full_arch_list_add_reg (ir
.regcache
,
8105 I387_MM0_REGNUM (tdep
) + ir
.rm
);
8110 if (i386_record_lea_modrm (&ir
))
8115 case 0xf30fb8: /* popcnt */
8116 if (i386_record_modrm (&ir
))
8118 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
8119 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
8122 case 0x660fd6: /* movq */
8123 if (i386_record_modrm (&ir
))
8128 if (!i386_xmm_regnum_p (gdbarch
,
8129 I387_XMM0_REGNUM (tdep
) + ir
.rm
))
8131 record_full_arch_list_add_reg (ir
.regcache
,
8132 I387_XMM0_REGNUM (tdep
) + ir
.rm
);
8137 if (i386_record_lea_modrm (&ir
))
8142 case 0x660f3817: /* ptest */
8143 case 0x0f2e: /* ucomiss */
8144 case 0x660f2e: /* ucomisd */
8145 case 0x0f2f: /* comiss */
8146 case 0x660f2f: /* comisd */
8147 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
8150 case 0x0ff7: /* maskmovq */
8151 regcache_raw_read_unsigned (ir
.regcache
,
8152 ir
.regmap
[X86_RECORD_REDI_REGNUM
],
8154 if (record_full_arch_list_add_mem (addr
, 64))
8158 case 0x660ff7: /* maskmovdqu */
8159 regcache_raw_read_unsigned (ir
.regcache
,
8160 ir
.regmap
[X86_RECORD_REDI_REGNUM
],
8162 if (record_full_arch_list_add_mem (addr
, 128))
8177 /* In the future, maybe still need to deal with need_dasm. */
8178 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REIP_REGNUM
);
8179 if (record_full_arch_list_add_end ())
8185 gdb_printf (gdb_stderr
,
8186 _("Process record does not support instruction 0x%02x "
8187 "at address %s.\n"),
8188 (unsigned int) (opcode
),
8189 paddress (gdbarch
, ir
.orig_addr
));
8193 static const int i386_record_regmap
[] =
8195 I386_EAX_REGNUM
, I386_ECX_REGNUM
, I386_EDX_REGNUM
, I386_EBX_REGNUM
,
8196 I386_ESP_REGNUM
, I386_EBP_REGNUM
, I386_ESI_REGNUM
, I386_EDI_REGNUM
,
8199 I386_EIP_REGNUM
, I386_EFLAGS_REGNUM
, I386_CS_REGNUM
, I386_SS_REGNUM
,
8200 I386_DS_REGNUM
, I386_ES_REGNUM
, I386_FS_REGNUM
, I386_GS_REGNUM
,
8204 /* Check that the given address appears suitable for a fast
8205 tracepoint, which on x86-64 means that we need an instruction of at
8206 least 5 bytes, so that we can overwrite it with a 4-byte-offset
8207 jump and not have to worry about program jumps to an address in the
8208 middle of the tracepoint jump. On x86, it may be possible to use
8209 4-byte jumps with a 2-byte offset to a trampoline located in the
8210 bottom 64 KiB of memory. Returns 1 if OK, and writes a size
8211 of instruction to replace, and 0 if not, plus an explanatory
8215 i386_fast_tracepoint_valid_at (struct gdbarch
*gdbarch
, CORE_ADDR addr
,
8220 /* Ask the target for the minimum instruction length supported. */
8221 jumplen
= target_get_min_fast_tracepoint_insn_len ();
8225 /* If the target does not support the get_min_fast_tracepoint_insn_len
8226 operation, assume that fast tracepoints will always be implemented
8227 using 4-byte relative jumps on both x86 and x86-64. */
8230 else if (jumplen
== 0)
8232 /* If the target does support get_min_fast_tracepoint_insn_len but
8233 returns zero, then the IPA has not loaded yet. In this case,
8234 we optimistically assume that truncated 2-byte relative jumps
8235 will be available on x86, and compensate later if this assumption
8236 turns out to be incorrect. On x86-64 architectures, 4-byte relative
8237 jumps will always be used. */
8238 jumplen
= (register_size (gdbarch
, 0) == 8) ? 5 : 4;
8241 /* Check for fit. */
8242 len
= gdb_insn_length (gdbarch
, addr
);
8246 /* Return a bit of target-specific detail to add to the caller's
8247 generic failure message. */
8249 *msg
= string_printf (_("; instruction is only %d bytes long, "
8250 "need at least %d bytes for the jump"),
8262 /* Return a floating-point format for a floating-point variable of
8263 length LEN in bits. If non-NULL, NAME is the name of its type.
8264 If no suitable type is found, return NULL. */
8266 static const struct floatformat
**
8267 i386_floatformat_for_type (struct gdbarch
*gdbarch
,
8268 const char *name
, int len
)
8270 if (len
== 128 && name
)
8271 if (strcmp (name
, "__float128") == 0
8272 || strcmp (name
, "_Float128") == 0
8273 || strcmp (name
, "complex _Float128") == 0
8274 || strcmp (name
, "complex(kind=16)") == 0
8275 || strcmp (name
, "COMPLEX(16)") == 0
8276 || strcmp (name
, "complex*32") == 0
8277 || strcmp (name
, "COMPLEX*32") == 0
8278 || strcmp (name
, "quad complex") == 0
8279 || strcmp (name
, "real(kind=16)") == 0
8280 || strcmp (name
, "real*16") == 0
8281 || strcmp (name
, "REAL*16") == 0
8282 || strcmp (name
, "REAL(16)") == 0)
8283 return floatformats_ieee_quad
;
8285 return default_floatformat_for_type (gdbarch
, name
, len
);
8288 /* Compute an XCR0 mask based on a target description. */
8291 i386_xcr0_from_tdesc (const struct target_desc
*tdesc
)
8293 if (! tdesc_has_registers (tdesc
))
8296 const struct tdesc_feature
*feature_core
;
8298 const struct tdesc_feature
*feature_sse
, *feature_avx
,
8299 *feature_avx512
, *feature_pkeys
;
8301 /* Get core registers. */
8302 feature_core
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.core");
8303 if (feature_core
== NULL
)
8306 /* Get SSE registers. */
8307 feature_sse
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.sse");
8309 /* Try AVX registers. */
8310 feature_avx
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.avx");
8312 /* Try AVX512 registers. */
8313 feature_avx512
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.avx512");
8316 feature_pkeys
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.pkeys");
8318 /* The XCR0 bits. */
8319 uint64_t xcr0
= X86_XSTATE_X87
;
8322 xcr0
|= X86_XSTATE_SSE
;
8326 /* AVX register description requires SSE register description. */
8330 xcr0
|= X86_XSTATE_AVX
;
8335 /* AVX512 register description requires AVX register description. */
8339 xcr0
|= X86_XSTATE_AVX512
;
8343 xcr0
|= X86_XSTATE_PKRU
;
8349 i386_validate_tdesc_p (i386_gdbarch_tdep
*tdep
,
8350 struct tdesc_arch_data
*tdesc_data
)
8352 const struct target_desc
*tdesc
= tdep
->tdesc
;
8353 const struct tdesc_feature
*feature_core
;
8355 const struct tdesc_feature
*feature_sse
, *feature_avx
, *feature_avx512
,
8356 *feature_pkeys
, *feature_segments
;
8357 int i
, num_regs
, valid_p
;
8359 if (! tdesc_has_registers (tdesc
))
8362 /* Get core registers. */
8363 feature_core
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.core");
8364 if (feature_core
== NULL
)
8367 /* Get SSE registers. */
8368 feature_sse
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.sse");
8370 /* Try AVX registers. */
8371 feature_avx
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.avx");
8373 /* Try AVX512 registers. */
8374 feature_avx512
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.avx512");
8376 /* Try segment base registers. */
8377 feature_segments
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.segments");
8380 feature_pkeys
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.pkeys");
8384 /* The XCR0 bits. */
8387 /* AVX512 register description requires AVX register description. */
8391 tdep
->xcr0
= X86_XSTATE_AVX_AVX512_MASK
;
8393 /* It may have been set by OSABI initialization function. */
8394 if (tdep
->k0_regnum
< 0)
8396 tdep
->k_register_names
= i386_k_names
;
8397 tdep
->k0_regnum
= I386_K0_REGNUM
;
8400 for (i
= 0; i
< I387_NUM_K_REGS
; i
++)
8401 valid_p
&= tdesc_numbered_register (feature_avx512
, tdesc_data
,
8402 tdep
->k0_regnum
+ i
,
8405 if (tdep
->num_zmm_regs
== 0)
8407 tdep
->zmmh_register_names
= i386_zmmh_names
;
8408 tdep
->num_zmm_regs
= 8;
8409 tdep
->zmm0h_regnum
= I386_ZMM0H_REGNUM
;
8412 for (i
= 0; i
< tdep
->num_zmm_regs
; i
++)
8413 valid_p
&= tdesc_numbered_register (feature_avx512
, tdesc_data
,
8414 tdep
->zmm0h_regnum
+ i
,
8415 tdep
->zmmh_register_names
[i
]);
8417 for (i
= 0; i
< tdep
->num_xmm_avx512_regs
; i
++)
8418 valid_p
&= tdesc_numbered_register (feature_avx512
, tdesc_data
,
8419 tdep
->xmm16_regnum
+ i
,
8420 tdep
->xmm_avx512_register_names
[i
]);
8422 for (i
= 0; i
< tdep
->num_ymm_avx512_regs
; i
++)
8423 valid_p
&= tdesc_numbered_register (feature_avx512
, tdesc_data
,
8424 tdep
->ymm16h_regnum
+ i
,
8425 tdep
->ymm16h_register_names
[i
]);
8429 /* AVX register description requires SSE register description. */
8433 if (!feature_avx512
)
8434 tdep
->xcr0
= X86_XSTATE_AVX_MASK
;
8436 /* It may have been set by OSABI initialization function. */
8437 if (tdep
->num_ymm_regs
== 0)
8439 tdep
->ymmh_register_names
= i386_ymmh_names
;
8440 tdep
->num_ymm_regs
= 8;
8441 tdep
->ymm0h_regnum
= I386_YMM0H_REGNUM
;
8444 for (i
= 0; i
< tdep
->num_ymm_regs
; i
++)
8445 valid_p
&= tdesc_numbered_register (feature_avx
, tdesc_data
,
8446 tdep
->ymm0h_regnum
+ i
,
8447 tdep
->ymmh_register_names
[i
]);
8449 else if (feature_sse
)
8450 tdep
->xcr0
= X86_XSTATE_SSE_MASK
;
8453 tdep
->xcr0
= X86_XSTATE_X87_MASK
;
8454 tdep
->num_xmm_regs
= 0;
8457 num_regs
= tdep
->num_core_regs
;
8458 for (i
= 0; i
< num_regs
; i
++)
8459 valid_p
&= tdesc_numbered_register (feature_core
, tdesc_data
, i
,
8460 tdep
->register_names
[i
]);
8464 /* Need to include %mxcsr, so add one. */
8465 num_regs
+= tdep
->num_xmm_regs
+ 1;
8466 for (; i
< num_regs
; i
++)
8467 valid_p
&= tdesc_numbered_register (feature_sse
, tdesc_data
, i
,
8468 tdep
->register_names
[i
]);
8471 if (feature_segments
)
8473 if (tdep
->fsbase_regnum
< 0)
8474 tdep
->fsbase_regnum
= I386_FSBASE_REGNUM
;
8475 valid_p
&= tdesc_numbered_register (feature_segments
, tdesc_data
,
8476 tdep
->fsbase_regnum
, "fs_base");
8477 valid_p
&= tdesc_numbered_register (feature_segments
, tdesc_data
,
8478 tdep
->fsbase_regnum
+ 1, "gs_base");
8483 tdep
->xcr0
|= X86_XSTATE_PKRU
;
8484 if (tdep
->pkru_regnum
< 0)
8486 tdep
->pkeys_register_names
= i386_pkeys_names
;
8487 tdep
->pkru_regnum
= I386_PKRU_REGNUM
;
8488 tdep
->num_pkeys_regs
= 1;
8491 for (i
= 0; i
< I387_NUM_PKEYS_REGS
; i
++)
8492 valid_p
&= tdesc_numbered_register (feature_pkeys
, tdesc_data
,
8493 I387_PKRU_REGNUM (tdep
) + i
,
8494 tdep
->pkeys_register_names
[i
]);
8502 /* Implement the type_align gdbarch function. */
8505 i386_type_align (struct gdbarch
*gdbarch
, struct type
*type
)
8507 type
= check_typedef (type
);
8509 if (gdbarch_ptr_bit (gdbarch
) == 32)
8511 if ((type
->code () == TYPE_CODE_INT
8512 || type
->code () == TYPE_CODE_FLT
)
8513 && type
->length () > 4)
8516 /* Handle x86's funny long double. */
8517 if (type
->code () == TYPE_CODE_FLT
8518 && gdbarch_long_double_bit (gdbarch
) == type
->length () * 8)
8526 /* Note: This is called for both i386 and amd64. */
8528 static struct gdbarch
*
8529 i386_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
8531 const struct target_desc
*tdesc
;
8535 x86_xsave_layout xsave_layout
= target_fetch_x86_xsave_layout ();
8537 /* If the target did not provide an XSAVE layout but the target
8538 description includes registers from the XSAVE extended region,
8539 use a fallback XSAVE layout. Specifically, this fallback layout
8540 is used when writing out a local core dump for a remote
8542 if (xsave_layout
.sizeof_xsave
== 0)
8544 = i387_fallback_xsave_layout (i386_xcr0_from_tdesc (info
.target_desc
));
8546 /* If there is already a candidate, use it. */
8547 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
8549 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
8551 /* Check that the XSAVE layout of ARCHES matches the layout for
8552 the current target. */
8553 i386_gdbarch_tdep
*other_tdep
8554 = gdbarch_tdep
<i386_gdbarch_tdep
> (arches
->gdbarch
);
8556 if (other_tdep
->xsave_layout
== xsave_layout
)
8557 return arches
->gdbarch
;
8560 /* Allocate space for the new architecture. Assume i386 for now. */
8562 = gdbarch_alloc (&info
, gdbarch_tdep_up (new i386_gdbarch_tdep
));
8563 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
8565 /* General-purpose registers. */
8566 tdep
->gregset_reg_offset
= NULL
;
8567 tdep
->gregset_num_regs
= I386_NUM_GREGS
;
8568 tdep
->sizeof_gregset
= 0;
8570 /* Floating-point registers. */
8571 tdep
->sizeof_fpregset
= I387_SIZEOF_FSAVE
;
8572 tdep
->fpregset
= &i386_fpregset
;
8574 /* The default settings include the FPU registers, the MMX registers
8575 and the SSE registers. This can be overridden for a specific ABI
8576 by adjusting the members `st0_regnum', `mm0_regnum' and
8577 `num_xmm_regs' of `struct gdbarch_tdep', otherwise the registers
8578 will show up in the output of "info all-registers". */
8580 tdep
->st0_regnum
= I386_ST0_REGNUM
;
8582 /* I386_NUM_XREGS includes %mxcsr, so subtract one. */
8583 tdep
->num_xmm_regs
= I386_NUM_XREGS
- 1;
8585 tdep
->jb_pc_offset
= -1;
8586 tdep
->struct_return
= pcc_struct_return
;
8587 tdep
->sigtramp_start
= 0;
8588 tdep
->sigtramp_end
= 0;
8589 tdep
->sigtramp_p
= i386_sigtramp_p
;
8590 tdep
->sigcontext_addr
= NULL
;
8591 tdep
->sc_reg_offset
= NULL
;
8592 tdep
->sc_pc_offset
= -1;
8593 tdep
->sc_sp_offset
= -1;
8595 tdep
->xsave_xcr0_offset
= -1;
8597 tdep
->record_regmap
= i386_record_regmap
;
8599 set_gdbarch_type_align (gdbarch
, i386_type_align
);
8601 /* The format used for `long double' on almost all i386 targets is
8602 the i387 extended floating-point format. In fact, of all targets
8603 in the GCC 2.95 tree, only OSF/1 does it different, and insists
8604 on having a `long double' that's not `long' at all. */
8605 set_gdbarch_long_double_format (gdbarch
, floatformats_i387_ext
);
8607 /* Although the i387 extended floating-point has only 80 significant
8608 bits, a `long double' actually takes up 96, probably to enforce
8610 set_gdbarch_long_double_bit (gdbarch
, 96);
8612 /* Support of bfloat16 format. */
8613 set_gdbarch_bfloat16_format (gdbarch
, floatformats_bfloat16
);
8615 /* Support for floating-point data type variants. */
8616 set_gdbarch_floatformat_for_type (gdbarch
, i386_floatformat_for_type
);
8618 /* Register numbers of various important registers. */
8619 set_gdbarch_sp_regnum (gdbarch
, I386_ESP_REGNUM
); /* %esp */
8620 set_gdbarch_pc_regnum (gdbarch
, I386_EIP_REGNUM
); /* %eip */
8621 set_gdbarch_ps_regnum (gdbarch
, I386_EFLAGS_REGNUM
); /* %eflags */
8622 set_gdbarch_fp0_regnum (gdbarch
, I386_ST0_REGNUM
); /* %st(0) */
8624 /* NOTE: kettenis/20040418: GCC does have two possible register
8625 numbering schemes on the i386: dbx and SVR4. These schemes
8626 differ in how they number %ebp, %esp, %eflags, and the
8627 floating-point registers, and are implemented by the arrays
8628 dbx_register_map[] and svr4_dbx_register_map in
8629 gcc/config/i386.c. GCC also defines a third numbering scheme in
8630 gcc/config/i386.c, which it designates as the "default" register
8631 map used in 64bit mode. This last register numbering scheme is
8632 implemented in dbx64_register_map, and is used for AMD64; see
8635 Currently, each GCC i386 target always uses the same register
8636 numbering scheme across all its supported debugging formats
8637 i.e. SDB (COFF), stabs and DWARF 2. This is because
8638 gcc/sdbout.c, gcc/dbxout.c and gcc/dwarf2out.c all use the
8639 DBX_REGISTER_NUMBER macro which is defined by each target's
8640 respective config header in a manner independent of the requested
8641 output debugging format.
8643 This does not match the arrangement below, which presumes that
8644 the SDB and stabs numbering schemes differ from the DWARF and
8645 DWARF 2 ones. The reason for this arrangement is that it is
8646 likely to get the numbering scheme for the target's
8647 default/native debug format right. For targets where GCC is the
8648 native compiler (FreeBSD, NetBSD, OpenBSD, GNU/Linux) or for
8649 targets where the native toolchain uses a different numbering
8650 scheme for a particular debug format (stabs-in-ELF on Solaris)
8651 the defaults below will have to be overridden, like
8652 i386_elf_init_abi() does. */
8654 /* Use the dbx register numbering scheme for stabs and COFF. */
8655 set_gdbarch_stab_reg_to_regnum (gdbarch
, i386_dbx_reg_to_regnum
);
8656 set_gdbarch_sdb_reg_to_regnum (gdbarch
, i386_dbx_reg_to_regnum
);
8658 /* Use the SVR4 register numbering scheme for DWARF 2. */
8659 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, i386_svr4_dwarf_reg_to_regnum
);
8661 /* We don't set gdbarch_stab_reg_to_regnum, since ECOFF doesn't seem to
8662 be in use on any of the supported i386 targets. */
8664 set_gdbarch_print_float_info (gdbarch
, i387_print_float_info
);
8666 set_gdbarch_get_longjmp_target (gdbarch
, i386_get_longjmp_target
);
8668 /* Call dummy code. */
8669 set_gdbarch_call_dummy_location (gdbarch
, ON_STACK
);
8670 set_gdbarch_push_dummy_code (gdbarch
, i386_push_dummy_code
);
8671 set_gdbarch_push_dummy_call (gdbarch
, i386_push_dummy_call
);
8672 set_gdbarch_frame_align (gdbarch
, i386_frame_align
);
8674 set_gdbarch_convert_register_p (gdbarch
, i386_convert_register_p
);
8675 set_gdbarch_register_to_value (gdbarch
, i386_register_to_value
);
8676 set_gdbarch_value_to_register (gdbarch
, i386_value_to_register
);
8678 set_gdbarch_return_value_as_value (gdbarch
, i386_return_value
);
8680 set_gdbarch_skip_prologue (gdbarch
, i386_skip_prologue
);
8682 /* Stack grows downward. */
8683 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
8685 set_gdbarch_breakpoint_kind_from_pc (gdbarch
, i386_breakpoint::kind_from_pc
);
8686 set_gdbarch_sw_breakpoint_from_kind (gdbarch
, i386_breakpoint::bp_from_kind
);
8688 set_gdbarch_decr_pc_after_break (gdbarch
, 1);
8689 set_gdbarch_max_insn_length (gdbarch
, I386_MAX_INSN_LEN
);
8691 set_gdbarch_frame_args_skip (gdbarch
, 8);
8693 set_gdbarch_print_insn (gdbarch
, i386_print_insn
);
8695 set_gdbarch_dummy_id (gdbarch
, i386_dummy_id
);
8697 set_gdbarch_unwind_pc (gdbarch
, i386_unwind_pc
);
8699 /* Add the i386 register groups. */
8700 i386_add_reggroups (gdbarch
);
8701 tdep
->register_reggroup_p
= i386_register_reggroup_p
;
8703 /* Helper for function argument information. */
8704 set_gdbarch_fetch_pointer_argument (gdbarch
, i386_fetch_pointer_argument
);
8706 /* Hook the function epilogue frame unwinder. This unwinder is
8707 appended to the list first, so that it supersedes the DWARF
8708 unwinder in function epilogues (where the DWARF unwinder
8709 currently fails). */
8710 if (info
.bfd_arch_info
->bits_per_word
== 32)
8711 frame_unwind_append_unwinder (gdbarch
, &i386_epilogue_override_frame_unwind
);
8713 /* Hook in the DWARF CFI frame unwinder. This unwinder is appended
8714 to the list before the prologue-based unwinders, so that DWARF
8715 CFI info will be used if it is available. */
8716 dwarf2_append_unwinders (gdbarch
);
8718 if (info
.bfd_arch_info
->bits_per_word
== 32)
8719 frame_unwind_append_unwinder (gdbarch
, &i386_epilogue_frame_unwind
);
8721 frame_base_set_default (gdbarch
, &i386_frame_base
);
8723 /* Pseudo registers may be changed by amd64_init_abi. */
8724 set_gdbarch_pseudo_register_read_value (gdbarch
,
8725 i386_pseudo_register_read_value
);
8726 set_gdbarch_pseudo_register_write (gdbarch
, i386_pseudo_register_write
);
8727 set_gdbarch_ax_pseudo_register_collect (gdbarch
,
8728 i386_ax_pseudo_register_collect
);
8730 set_tdesc_pseudo_register_type (gdbarch
, i386_pseudo_register_type
);
8731 set_tdesc_pseudo_register_name (gdbarch
, i386_pseudo_register_name
);
8733 /* Override the normal target description method to make the AVX
8734 upper halves anonymous. */
8735 set_gdbarch_register_name (gdbarch
, i386_register_name
);
8737 /* Even though the default ABI only includes general-purpose registers,
8738 floating-point registers and the SSE registers, we have to leave a
8739 gap for the upper AVX, (deprecated) MPX and AVX512 registers. */
8740 set_gdbarch_num_regs (gdbarch
, I386_NUM_REGS
);
8742 set_gdbarch_gnu_triplet_regexp (gdbarch
, i386_gnu_triplet_regexp
);
8744 /* Get the x86 target description from INFO. */
8745 tdesc
= info
.target_desc
;
8746 if (! tdesc_has_registers (tdesc
))
8747 tdesc
= i386_target_description (X86_XSTATE_SSE_MASK
, false);
8748 tdep
->tdesc
= tdesc
;
8750 tdep
->num_core_regs
= I386_NUM_GREGS
+ I387_NUM_REGS
;
8751 tdep
->register_names
= i386_register_names
;
8753 /* No upper YMM registers. */
8754 tdep
->ymmh_register_names
= NULL
;
8755 tdep
->ymm0h_regnum
= -1;
8757 /* No upper ZMM registers. */
8758 tdep
->zmmh_register_names
= NULL
;
8759 tdep
->zmm0h_regnum
= -1;
8761 /* No high XMM registers. */
8762 tdep
->xmm_avx512_register_names
= NULL
;
8763 tdep
->xmm16_regnum
= -1;
8765 /* No upper YMM16-31 registers. */
8766 tdep
->ymm16h_register_names
= NULL
;
8767 tdep
->ymm16h_regnum
= -1;
8769 tdep
->num_byte_regs
= 8;
8770 tdep
->num_word_regs
= 8;
8771 tdep
->num_dword_regs
= 0;
8772 tdep
->num_mmx_regs
= 8;
8773 tdep
->num_ymm_regs
= 0;
8775 /* No AVX512 registers. */
8776 tdep
->k0_regnum
= -1;
8777 tdep
->num_zmm_regs
= 0;
8778 tdep
->num_ymm_avx512_regs
= 0;
8779 tdep
->num_xmm_avx512_regs
= 0;
8781 /* No PKEYS registers */
8782 tdep
->pkru_regnum
= -1;
8783 tdep
->num_pkeys_regs
= 0;
8785 /* No segment base registers. */
8786 tdep
->fsbase_regnum
= -1;
8788 tdesc_arch_data_up tdesc_data
= tdesc_data_alloc ();
8790 set_gdbarch_relocate_instruction (gdbarch
, i386_relocate_instruction
);
8792 set_gdbarch_gen_return_address (gdbarch
, i386_gen_return_address
);
8794 set_gdbarch_insn_is_call (gdbarch
, i386_insn_is_call
);
8795 set_gdbarch_insn_is_ret (gdbarch
, i386_insn_is_ret
);
8796 set_gdbarch_insn_is_jump (gdbarch
, i386_insn_is_jump
);
8798 /* Hook in ABI-specific overrides, if they have been registered.
8799 Note: If INFO specifies a 64 bit arch, this is where we turn
8800 a 32-bit i386 into a 64-bit amd64. */
8801 info
.tdesc_data
= tdesc_data
.get ();
8802 gdbarch_init_osabi (info
, gdbarch
);
8804 if (!i386_validate_tdesc_p (tdep
, tdesc_data
.get ()))
8806 gdbarch_free (gdbarch
);
8809 tdep
->xsave_layout
= xsave_layout
;
8811 /* Wire in pseudo registers. Number of pseudo registers may be
8813 set_gdbarch_num_pseudo_regs (gdbarch
, (tdep
->num_byte_regs
8814 + tdep
->num_word_regs
8815 + tdep
->num_dword_regs
8816 + tdep
->num_mmx_regs
8817 + tdep
->num_ymm_regs
8818 + tdep
->num_ymm_avx512_regs
8819 + tdep
->num_zmm_regs
));
8821 /* Target description may be changed. */
8822 tdesc
= tdep
->tdesc
;
8824 tdesc_use_registers (gdbarch
, tdesc
, std::move (tdesc_data
));
8826 /* Override gdbarch_register_reggroup_p set in tdesc_use_registers. */
8827 set_gdbarch_register_reggroup_p (gdbarch
, tdep
->register_reggroup_p
);
8829 /* Make %al the first pseudo-register. */
8830 tdep
->al_regnum
= gdbarch_num_regs (gdbarch
);
8831 tdep
->ax_regnum
= tdep
->al_regnum
+ tdep
->num_byte_regs
;
8833 ymm0_regnum
= tdep
->ax_regnum
+ tdep
->num_word_regs
;
8834 if (tdep
->num_dword_regs
)
8836 /* Support dword pseudo-register if it hasn't been disabled. */
8837 tdep
->eax_regnum
= ymm0_regnum
;
8838 ymm0_regnum
+= tdep
->num_dword_regs
;
8841 tdep
->eax_regnum
= -1;
8843 mm0_regnum
= ymm0_regnum
;
8844 if (tdep
->num_ymm_regs
)
8846 /* Support YMM pseudo-register if it is available. */
8847 tdep
->ymm0_regnum
= ymm0_regnum
;
8848 mm0_regnum
+= tdep
->num_ymm_regs
;
8851 tdep
->ymm0_regnum
= -1;
8853 if (tdep
->num_ymm_avx512_regs
)
8855 /* Support YMM16-31 pseudo registers if available. */
8856 tdep
->ymm16_regnum
= mm0_regnum
;
8857 mm0_regnum
+= tdep
->num_ymm_avx512_regs
;
8860 tdep
->ymm16_regnum
= -1;
8862 if (tdep
->num_zmm_regs
)
8864 /* Support ZMM pseudo-register if it is available. */
8865 tdep
->zmm0_regnum
= mm0_regnum
;
8866 mm0_regnum
+= tdep
->num_zmm_regs
;
8869 tdep
->zmm0_regnum
= -1;
8871 if (tdep
->num_mmx_regs
!= 0)
8873 /* Support MMX pseudo-register if MMX hasn't been disabled. */
8874 tdep
->mm0_regnum
= mm0_regnum
;
8877 tdep
->mm0_regnum
= -1;
8879 /* Hook in the legacy prologue-based unwinders last (fallback). */
8880 if (info
.bfd_arch_info
->bits_per_word
== 32)
8882 frame_unwind_append_unwinder (gdbarch
, &i386_stack_tramp_frame_unwind
);
8883 frame_unwind_append_unwinder (gdbarch
, &i386_sigtramp_frame_unwind
);
8884 frame_unwind_append_unwinder (gdbarch
, &i386_frame_unwind
);
8887 /* If we have a register mapping, enable the generic core file
8888 support, unless it has already been enabled. */
8889 if (tdep
->gregset_reg_offset
8890 && !gdbarch_iterate_over_regset_sections_p (gdbarch
))
8891 set_gdbarch_iterate_over_regset_sections
8892 (gdbarch
, i386_iterate_over_regset_sections
);
8894 set_gdbarch_fast_tracepoint_valid_at (gdbarch
,
8895 i386_fast_tracepoint_valid_at
);
8902 /* Return the target description for a specified XSAVE feature mask. */
8904 const struct target_desc
*
8905 i386_target_description (uint64_t xcr0
, bool segments
)
8907 static target_desc
*i386_tdescs \
8908 [2/*SSE*/][2/*AVX*/][2/*AVX512*/][2/*PKRU*/][2/*segments*/] = {};
8909 target_desc
**tdesc
;
8911 tdesc
= &i386_tdescs
[(xcr0
& X86_XSTATE_SSE
) ? 1 : 0]
8912 [(xcr0
& X86_XSTATE_AVX
) ? 1 : 0]
8913 [(xcr0
& X86_XSTATE_AVX512
) ? 1 : 0]
8914 [(xcr0
& X86_XSTATE_PKRU
) ? 1 : 0]
8918 *tdesc
= i386_create_target_description (xcr0
, false, segments
);
8923 void _initialize_i386_tdep ();
8925 _initialize_i386_tdep ()
8927 gdbarch_register (bfd_arch_i386
, i386_gdbarch_init
);
8929 /* Add the variable that controls the disassembly flavor. */
8930 add_setshow_enum_cmd ("disassembly-flavor", no_class
, valid_flavors
,
8931 &disassembly_flavor
, _("\
8932 Set the disassembly flavor."), _("\
8933 Show the disassembly flavor."), _("\
8934 The valid values are \"att\" and \"intel\", and the default value is \"att\"."),
8936 NULL
, /* FIXME: i18n: */
8937 &setlist
, &showlist
);
8939 /* Add the variable that controls the convention for returning
8941 add_setshow_enum_cmd ("struct-convention", no_class
, valid_conventions
,
8942 &struct_convention
, _("\
8943 Set the convention for returning small structs."), _("\
8944 Show the convention for returning small structs."), _("\
8945 Valid values are \"default\", \"pcc\" and \"reg\", and the default value\n\
8948 NULL
, /* FIXME: i18n: */
8949 &setlist
, &showlist
);
8951 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_SVR4
,
8952 i386_svr4_init_abi
);
8954 /* Initialize the i386-specific register groups. */
8955 i386_init_reggroups ();
8957 /* Tell remote stub that we support XML target description. */
8958 register_remote_support_xml ("i386");