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_legacy
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_legacy
i386_epilogue_override_frame_unwind (
2298 "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_legacy
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_legacy
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_legacy
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 0x10: /* VMOVS[S|D] XMM, mem. */
4820 /* VMOVUP[S|D] XMM, mem. */
4821 case 0x28: /* VMOVAP[S|D] XMM, mem. */
4822 /* Moving from memory region or XMM registers into an XMM register. */
4823 i386_record_modrm (ir
);
4824 record_full_arch_list_add_reg (ir
->regcache
,
4825 ir
->regmap
[X86_RECORD_XMM0_REGNUM
]
4826 + ir
->reg
+ vex_r
* 8);
4828 case 0x11: /* VMOVS[S|D] mem, XMM. */
4829 /* VMOVUP[S|D] mem, XMM. */
4830 case 0x29: /* VMOVAP[S|D] mem, XMM. */
4831 /* Moving from memory region into an XMM register. */
4832 /* This can also be used for XMM -> XMM in some scenarios. */
4833 i386_record_modrm (ir
);
4836 /* In this case the destination register is encoded differently
4837 to any other AVX instruction I've seen so far. In this one,
4838 VEX.B is the most important bit of the destination. */
4839 record_full_arch_list_add_reg (ir
->regcache
,
4840 ir
->regmap
[X86_RECORD_XMM0_REGNUM
]
4841 + ir
->rm
+ ir
->rex_b
* 8);
4845 /* Opcode 0x29 is trivial, the size of memory written is defined by
4846 VEX.L. Opcode 0x11 can refer to vmovs[s|d] or vmovup[s|d]; they
4847 are differentiated by the most significant bit of VEX.pp, and the
4848 latter works exactly like 0x29, but the former encodes the size
4849 on VEX.pp itself. */
4850 if (opcode
== 0x11 && (ir
->pp
& 2) != 0)
4854 i386_record_lea_modrm (ir
);
4857 case 0x14: /* VUNPCKL[PS|PD]. */
4858 case 0x15: /* VUNPCKH [PS|PD]. */
4859 i386_record_modrm (ir
);
4860 record_full_arch_list_add_reg (ir
->regcache
,
4861 tdep
->ymm0_regnum
+ ir
->reg
+ vex_r
* 8);
4863 case 0x6e: /* VMOVD XMM, reg/mem */
4864 /* This is moving from a regular register or memory region into an
4866 i386_record_modrm (ir
);
4867 /* ModR/M only has the 3 least significant bits of the destination
4868 register, the last one is indicated by VEX.R (stored inverted). */
4869 record_full_arch_list_add_reg (ir
->regcache
,
4871 + ir
->reg
+ vex_r
* 8);
4873 case 0x7e: /* VMOV(D/Q) */
4874 i386_record_modrm (ir
);
4875 /* Both the intel and AMD manual are wrong about this. According to
4876 it, the only difference between vmovq and vmovd should be the rex_w
4877 bit, but in empirical testing, it seems that they share this opcode,
4878 and the way to differentiate it here is looking at VEX.PP. */
4881 /* This is vmovq moving from a regular register or memory
4882 into an XMM register. As above, VEX.R is the final bit for
4883 destination register. */
4884 record_full_arch_list_add_reg (ir
->regcache
,
4886 + ir
->reg
+ vex_r
* 8);
4888 else if (ir
->pp
== 1)
4890 /* This is the vmovd version that stores into a regular register
4891 or memory region. */
4892 /* If ModRM.mod is 11 we are saving into a register. */
4894 record_full_arch_list_add_reg (ir
->regcache
, ir
->regmap
[ir
->rm
]);
4897 /* Calculate the size of memory that will be modified
4898 and store it in the form of 1 << ir->ot, since that
4899 is how the function uses it. In theory, VEX.W is supposed
4900 to indicate the size of the memory. In practice, I only
4901 ever seen it set to 0, and for 16 bytes, 0xD6 opcode
4908 i386_record_lea_modrm (ir
);
4913 gdb_printf ("Unrecognized VEX.PP value %d at address %s.",
4914 ir
->pp
, paddress(gdbarch
, ir
->orig_addr
));
4918 case 0xd6: /* VMOVQ reg/mem XMM */
4919 i386_record_modrm (ir
);
4920 /* This is the vmovq version that stores into a regular register
4921 or memory region. */
4922 /* If ModRM.mod is 11 we are saving into a register. */
4924 record_full_arch_list_add_reg (ir
->regcache
, ir
->regmap
[ir
->rm
]);
4927 /* We know that this operation is always 64 bits. */
4929 i386_record_lea_modrm (ir
);
4933 case 0x6f: /* VMOVDQ (U|A) */
4934 case 0x7f: /* VMOVDQ (U|A) */
4935 /* vmovdq instructions have information about source/destination
4936 spread over many places, so this code ended up messier than
4938 /* The VEX.pp bits identify if the move is aligned or not, but this
4939 doesn't influence the recording so we can ignore it. */
4940 i386_record_modrm (ir
);
4941 /* The first bit of modrm identifies if both operands of the instruction
4942 are registers (bit = 1) or if one of the operands is memory. */
4947 /* vex_r will identify the high bit of the destination
4948 register. Source is identified by ir->rex_b, but that
4949 doesn't matter for recording. */
4950 record_full_arch_list_add_reg (ir
->regcache
,
4951 tdep
->ymm0_regnum
+ 8*vex_r
+ ir
->reg
);
4955 /* The origin operand is >7 and destination operand is <= 7.
4956 This is special cased because in this one vex_r is used to
4957 identify the high bit of the SOURCE operand, not destination
4958 which would mess the previous expression. */
4959 record_full_arch_list_add_reg (ir
->regcache
,
4960 tdep
->ymm0_regnum
+ ir
->rm
);
4965 /* This is the easy branch. We just need to check the opcode
4966 to see if the source or destination is memory. */
4969 record_full_arch_list_add_reg (ir
->regcache
,
4971 + ir
->reg
+ vex_r
* 8);
4975 /* We're writing 256 bits, so 1<<8. */
4977 i386_record_lea_modrm (ir
);
4982 case 0x60: /* VPUNPCKLBW */
4983 case 0x61: /* VPUNPCKLWD */
4984 case 0x62: /* VPUNPCKLDQ */
4985 case 0x6c: /* VPUNPCKLQDQ */
4986 case 0x68: /* VPUNPCKHBW */
4987 case 0x69: /* VPUNPCKHWD */
4988 case 0x6a: /* VPUNPCKHDQ */
4989 case 0x6d: /* VPUNPCKHQDQ */
4991 i386_record_modrm (ir
);
4992 int reg_offset
= ir
->reg
+ vex_r
* 8;
4993 record_full_arch_list_add_reg (ir
->regcache
,
4994 tdep
->ymm0_regnum
+ reg_offset
);
4998 case 0x74: /* VPCMPEQB */
4999 case 0x75: /* VPCMPEQB */
5000 case 0x76: /* VPCMPEQB */
5002 i386_record_modrm (ir
);
5003 int reg_offset
= ir
->reg
+ vex_r
* 8;
5004 record_full_arch_list_add_reg (ir
->regcache
,
5005 tdep
->ymm0_regnum
+ reg_offset
);
5009 case 0x78: /* VPBROADCASTB */
5010 case 0x79: /* VPBROADCASTW */
5011 case 0x58: /* VPBROADCASTD and VADD[P|S][S|D] */
5012 case 0x59: /* VPBROADCASTQ and VMUL[P|S][S|D] */
5013 case 0x5c: /* VSUB[P|S][S|D] */
5014 case 0x5d: /* VMIN[P|S][S|D] */
5015 case 0x5e: /* VDIV[P|S][S|D] */
5016 case 0x5f: /* VMAX[P|S][S|D] */
5018 /* vpbroadcast and arithmethic operations are differentiated
5019 by map_select, but it doesn't change the recording mechanics. */
5020 i386_record_modrm (ir
);
5021 int reg_offset
= ir
->reg
+ vex_r
* 8;
5022 gdb_assert (tdep
->num_ymm_regs
> reg_offset
);
5023 record_full_arch_list_add_reg (ir
->regcache
,
5024 tdep
->ymm0_regnum
+ reg_offset
);
5028 case 0x77:/* VZEROUPPER */
5030 int num_regs
= tdep
->num_ymm_regs
;
5031 /* This instruction only works on ymm0..15, even if 16..31 are
5035 for (int i
= 0; i
< num_regs
; i
++)
5037 /* We only need to record ymm_h, because the low bits
5039 record_full_arch_list_add_reg (ir
->regcache
,
5040 tdep
->ymm0h_regnum
+ i
);
5045 case 0xd7: /* VPMOVMSKB */
5047 i386_record_modrm (ir
);
5048 record_full_arch_list_add_reg (ir
->regcache
,
5049 ir
->regmap
[X86_RECORD_REAX_REGNUM
5050 + ir
->reg
+ 8 * vex_r
]);
5054 case 0xef: /* VPXOR */
5055 case 0xeb: /* VPOR */
5057 i386_record_modrm (ir
);
5058 int reg_offset
= ir
->reg
+ vex_r
* 8;
5059 record_full_arch_list_add_reg (ir
->regcache
,
5060 tdep
->ymm0_regnum
+ reg_offset
);
5065 gdb_printf (gdb_stderr
,
5066 _("Process record does not support VEX instruction 0x%02x "
5067 "at address %s.\n"),
5068 (unsigned int) (opcode
),
5069 paddress (gdbarch
, ir
->orig_addr
));
5073 record_full_arch_list_add_reg (ir
->regcache
, ir
->regmap
[X86_RECORD_REIP_REGNUM
]);
5074 if (record_full_arch_list_add_end ())
5080 /* Parse the current instruction, and record the values of the
5081 registers and memory that will be changed by the current
5082 instruction. Returns -1 if something goes wrong, 0 otherwise. */
5084 #define I386_RECORD_FULL_ARCH_LIST_ADD_REG(regnum) \
5085 record_full_arch_list_add_reg (ir.regcache, ir.regmap[(regnum)])
5088 i386_process_record (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
5089 CORE_ADDR input_addr
)
5091 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
5097 gdb_byte buf
[I386_MAX_REGISTER_SIZE
];
5098 struct i386_record_s ir
;
5099 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
5102 bool vex_prefix
= false;
5104 memset (&ir
, 0, sizeof (struct i386_record_s
));
5105 ir
.regcache
= regcache
;
5106 ir
.addr
= input_addr
;
5107 ir
.orig_addr
= input_addr
;
5111 ir
.popl_esp_hack
= 0;
5112 ir
.regmap
= tdep
->record_regmap
;
5113 ir
.gdbarch
= gdbarch
;
5115 if (record_debug
> 1)
5116 gdb_printf (gdb_stdlog
, "Process record: i386_process_record "
5118 paddress (gdbarch
, ir
.addr
));
5123 if (record_read_memory (gdbarch
, ir
.addr
, &opcode8
, 1))
5126 switch (opcode8
) /* Instruction prefixes */
5128 case REPE_PREFIX_OPCODE
:
5129 prefixes
|= PREFIX_REPZ
;
5131 case REPNE_PREFIX_OPCODE
:
5132 prefixes
|= PREFIX_REPNZ
;
5134 case LOCK_PREFIX_OPCODE
:
5135 prefixes
|= PREFIX_LOCK
;
5137 case CS_PREFIX_OPCODE
:
5138 ir
.override
= X86_RECORD_CS_REGNUM
;
5140 case SS_PREFIX_OPCODE
:
5141 ir
.override
= X86_RECORD_SS_REGNUM
;
5143 case DS_PREFIX_OPCODE
:
5144 ir
.override
= X86_RECORD_DS_REGNUM
;
5146 case ES_PREFIX_OPCODE
:
5147 ir
.override
= X86_RECORD_ES_REGNUM
;
5149 case FS_PREFIX_OPCODE
:
5150 ir
.override
= X86_RECORD_FS_REGNUM
;
5152 case GS_PREFIX_OPCODE
:
5153 ir
.override
= X86_RECORD_GS_REGNUM
;
5155 case DATA_PREFIX_OPCODE
:
5156 prefixes
|= PREFIX_DATA
;
5158 case ADDR_PREFIX_OPCODE
:
5159 prefixes
|= PREFIX_ADDR
;
5161 case 0x40: /* i386 inc %eax */
5162 case 0x41: /* i386 inc %ecx */
5163 case 0x42: /* i386 inc %edx */
5164 case 0x43: /* i386 inc %ebx */
5165 case 0x44: /* i386 inc %esp */
5166 case 0x45: /* i386 inc %ebp */
5167 case 0x46: /* i386 inc %esi */
5168 case 0x47: /* i386 inc %edi */
5169 case 0x48: /* i386 dec %eax */
5170 case 0x49: /* i386 dec %ecx */
5171 case 0x4a: /* i386 dec %edx */
5172 case 0x4b: /* i386 dec %ebx */
5173 case 0x4c: /* i386 dec %esp */
5174 case 0x4d: /* i386 dec %ebp */
5175 case 0x4e: /* i386 dec %esi */
5176 case 0x4f: /* i386 dec %edi */
5177 if (ir
.regmap
[X86_RECORD_R8_REGNUM
]) /* 64 bit target */
5180 rex_w
= (opcode8
>> 3) & 1;
5181 rex_r
= (opcode8
& 0x4) << 1;
5182 ir
.rex_x
= (opcode8
& 0x2) << 2;
5183 ir
.rex_b
= (opcode8
& 0x1) << 3;
5185 else /* 32 bit target */
5188 case 0xc4: /* 3-byte VEX prefixes (for AVX/AVX2 instructions). */
5190 /* The first byte just identifies the VEX prefix. Data is stored
5191 on the following 2 bytes. */
5193 if (record_read_memory (gdbarch
, ir
.addr
, &byte
, 1))
5197 rex_r
= !((byte
>> 7) & 0x1);
5198 ir
.rex_x
= !((byte
>> 6) & 0x1);
5199 ir
.rex_b
= !((byte
>> 5) & 0x1);
5200 ir
.map_select
= byte
& 0x1f;
5201 /* Collect the last byte of the prefix. */
5202 if (record_read_memory (gdbarch
, ir
.addr
, &byte
, 1))
5205 rex_w
= (byte
>> 7) & 0x1;
5206 ir
.vvvv
= (~(byte
>> 3) & 0xf);
5207 ir
.l
= (byte
>> 2) & 0x1;
5213 case 0xc5: /* 2-byte VEX prefix for AVX/AVX2 instructions. */
5215 /* The first byte just identifies the VEX prefix. Data is stored
5216 on the following 2 bytes. */
5218 if (record_read_memory (gdbarch
, ir
.addr
, &byte
, 1))
5222 /* On the 2-byte versions, these are pre-defined. */
5228 rex_r
= !((byte
>> 7) & 0x1);
5229 ir
.vvvv
= (~(byte
>> 3) & 0xf);
5230 ir
.l
= (byte
>> 2) & 0x1;
5241 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && rex_w
== 1)
5247 if (prefixes
& PREFIX_DATA
)
5250 if (prefixes
& PREFIX_ADDR
)
5252 else if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5255 /* Now check op code. */
5256 opcode
= (uint32_t) opcode8
;
5259 /* If we found the VEX prefix, i386 will either record or warn that
5260 the instruction isn't supported, so we can return the VEX result. */
5261 return i386_record_vex (&ir
, rex_w
, rex_r
, opcode
, gdbarch
);
5267 if (record_read_memory (gdbarch
, ir
.addr
, &opcode8
, 1))
5270 opcode
= (uint32_t) opcode8
| 0x0f00;
5274 case 0x00: /* arith & logic */
5322 if (((opcode
>> 3) & 7) != OP_CMPL
)
5324 if ((opcode
& 1) == 0)
5327 ir
.ot
= ir
.dflag
+ OT_WORD
;
5329 switch ((opcode
>> 1) & 3)
5331 case 0: /* OP Ev, Gv */
5332 if (i386_record_modrm (&ir
))
5336 if (i386_record_lea_modrm (&ir
))
5342 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5344 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
5347 case 1: /* OP Gv, Ev */
5348 if (i386_record_modrm (&ir
))
5351 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5353 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5355 case 2: /* OP A, Iv */
5356 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5360 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5363 case 0x80: /* GRP1 */
5367 if (i386_record_modrm (&ir
))
5370 if (ir
.reg
!= OP_CMPL
)
5372 if ((opcode
& 1) == 0)
5375 ir
.ot
= ir
.dflag
+ OT_WORD
;
5382 ir
.rip_offset
= (ir
.ot
> OT_LONG
) ? 4 : (1 << ir
.ot
);
5383 if (i386_record_lea_modrm (&ir
))
5387 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
5389 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5392 case 0x40: /* inc */
5401 case 0x48: /* dec */
5410 I386_RECORD_FULL_ARCH_LIST_ADD_REG (opcode
& 7);
5411 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5414 case 0xf6: /* GRP3 */
5416 if ((opcode
& 1) == 0)
5419 ir
.ot
= ir
.dflag
+ OT_WORD
;
5420 if (i386_record_modrm (&ir
))
5423 if (ir
.mod
!= 3 && ir
.reg
== 0)
5424 ir
.rip_offset
= (ir
.ot
> OT_LONG
) ? 4 : (1 << ir
.ot
);
5429 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
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 if (ir
.reg
== 3) /* neg */
5446 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5452 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5453 if (ir
.ot
!= OT_BYTE
)
5454 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
5455 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5459 opcode
= opcode
<< 8 | ir
.modrm
;
5465 case 0xfe: /* GRP4 */
5466 case 0xff: /* GRP5 */
5467 if (i386_record_modrm (&ir
))
5469 if (ir
.reg
>= 2 && opcode
== 0xfe)
5472 opcode
= opcode
<< 8 | ir
.modrm
;
5479 if ((opcode
& 1) == 0)
5482 ir
.ot
= ir
.dflag
+ OT_WORD
;
5485 if (i386_record_lea_modrm (&ir
))
5491 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5493 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
5495 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5498 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && ir
.dflag
)
5500 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5502 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5505 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM
);
5506 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5508 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5512 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5515 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && ir
.dflag
)
5517 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5522 opcode
= opcode
<< 8 | ir
.modrm
;
5528 case 0x84: /* test */
5532 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5535 case 0x98: /* CWDE/CBW */
5536 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5539 case 0x99: /* CDQ/CWD */
5540 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5541 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
5544 case 0x0faf: /* imul */
5547 ir
.ot
= ir
.dflag
+ OT_WORD
;
5548 if (i386_record_modrm (&ir
))
5551 ir
.rip_offset
= (ir
.ot
> OT_LONG
) ? 4 : (1 << ir
.ot
);
5552 else if (opcode
== 0x6b)
5555 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5557 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5558 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5561 case 0x0fc0: /* xadd */
5563 if ((opcode
& 1) == 0)
5566 ir
.ot
= ir
.dflag
+ OT_WORD
;
5567 if (i386_record_modrm (&ir
))
5572 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5574 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5575 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5577 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
5581 if (i386_record_lea_modrm (&ir
))
5583 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5585 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5587 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5590 case 0x0fb0: /* cmpxchg */
5592 if ((opcode
& 1) == 0)
5595 ir
.ot
= ir
.dflag
+ OT_WORD
;
5596 if (i386_record_modrm (&ir
))
5601 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5602 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5604 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5608 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5609 if (i386_record_lea_modrm (&ir
))
5612 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5615 case 0x0fc7: /* cmpxchg8b / rdrand / rdseed */
5616 if (i386_record_modrm (&ir
))
5620 /* rdrand and rdseed use the 3 bits of the REG field of ModR/M as
5621 an extended opcode. rdrand has bits 110 (/6) and rdseed
5622 has bits 111 (/7). */
5623 if (ir
.reg
== 6 || ir
.reg
== 7)
5625 /* The storage register is described by the 3 R/M bits, but the
5626 REX.B prefix may be used to give access to registers
5627 R8~R15. In this case ir.rex_b + R/M will give us the register
5628 in the range R8~R15.
5630 REX.W may also be used to access 64-bit registers, but we
5631 already record entire registers and not just partial bits
5633 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rex_b
+ ir
.rm
);
5634 /* These instructions also set conditional bits. */
5635 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5640 /* We don't handle this particular instruction yet. */
5642 opcode
= opcode
<< 8 | ir
.modrm
;
5646 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5647 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
5648 if (i386_record_lea_modrm (&ir
))
5650 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5653 case 0x50: /* push */
5663 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && ir
.dflag
)
5665 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5669 case 0x06: /* push es */
5670 case 0x0e: /* push cs */
5671 case 0x16: /* push ss */
5672 case 0x1e: /* push ds */
5673 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5678 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5682 case 0x0fa0: /* push fs */
5683 case 0x0fa8: /* push gs */
5684 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5689 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5693 case 0x60: /* pusha */
5694 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5699 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 4)))
5703 case 0x58: /* pop */
5711 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5712 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode
& 0x7) | ir
.rex_b
);
5715 case 0x61: /* popa */
5716 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5721 for (regnum
= X86_RECORD_REAX_REGNUM
;
5722 regnum
<= X86_RECORD_REDI_REGNUM
;
5724 I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum
);
5727 case 0x8f: /* pop */
5728 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5729 ir
.ot
= ir
.dflag
? OT_QUAD
: OT_WORD
;
5731 ir
.ot
= ir
.dflag
+ OT_WORD
;
5732 if (i386_record_modrm (&ir
))
5735 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
5738 ir
.popl_esp_hack
= 1 << ir
.ot
;
5739 if (i386_record_lea_modrm (&ir
))
5742 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5745 case 0xc8: /* enter */
5746 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM
);
5747 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && ir
.dflag
)
5749 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
5753 case 0xc9: /* leave */
5754 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5755 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM
);
5758 case 0x07: /* pop es */
5759 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5764 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5765 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_ES_REGNUM
);
5766 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5769 case 0x17: /* pop ss */
5770 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5775 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5776 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_SS_REGNUM
);
5777 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5780 case 0x1f: /* pop ds */
5781 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
5786 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5787 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_DS_REGNUM
);
5788 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5791 case 0x0fa1: /* pop fs */
5792 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5793 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_FS_REGNUM
);
5794 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5797 case 0x0fa9: /* pop gs */
5798 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
5799 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_GS_REGNUM
);
5800 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5803 case 0x88: /* mov */
5807 if ((opcode
& 1) == 0)
5810 ir
.ot
= ir
.dflag
+ OT_WORD
;
5812 if (i386_record_modrm (&ir
))
5817 if (opcode
== 0xc6 || opcode
== 0xc7)
5818 ir
.rip_offset
= (ir
.ot
> OT_LONG
) ? 4 : (1 << ir
.ot
);
5819 if (i386_record_lea_modrm (&ir
))
5824 if (opcode
== 0xc6 || opcode
== 0xc7)
5826 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5828 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
5832 case 0x8a: /* mov */
5834 if ((opcode
& 1) == 0)
5837 ir
.ot
= ir
.dflag
+ OT_WORD
;
5838 if (i386_record_modrm (&ir
))
5841 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5843 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5846 case 0x8c: /* mov seg */
5847 if (i386_record_modrm (&ir
))
5852 opcode
= opcode
<< 8 | ir
.modrm
;
5857 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
5861 if (i386_record_lea_modrm (&ir
))
5866 case 0x8e: /* mov seg */
5867 if (i386_record_modrm (&ir
))
5872 regnum
= X86_RECORD_ES_REGNUM
;
5875 regnum
= X86_RECORD_SS_REGNUM
;
5878 regnum
= X86_RECORD_DS_REGNUM
;
5881 regnum
= X86_RECORD_FS_REGNUM
;
5884 regnum
= X86_RECORD_GS_REGNUM
;
5888 opcode
= opcode
<< 8 | ir
.modrm
;
5892 I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum
);
5893 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
5896 case 0x0fb6: /* movzbS */
5897 case 0x0fb7: /* movzwS */
5898 case 0x0fbe: /* movsbS */
5899 case 0x0fbf: /* movswS */
5900 if (i386_record_modrm (&ir
))
5902 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
| rex_r
);
5905 case 0x8d: /* lea */
5906 if (i386_record_modrm (&ir
))
5911 opcode
= opcode
<< 8 | ir
.modrm
;
5916 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
5918 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
5921 case 0xa0: /* mov EAX */
5924 case 0xd7: /* xlat */
5925 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
5928 case 0xa2: /* mov EAX */
5930 if (ir
.override
>= 0)
5932 if (record_full_memory_query
)
5935 Process record ignores the memory change of instruction at address %s\n\
5936 because it can't get the value of the segment register.\n\
5937 Do you want to stop the program?"),
5938 paddress (gdbarch
, ir
.orig_addr
)))
5944 if ((opcode
& 1) == 0)
5947 ir
.ot
= ir
.dflag
+ OT_WORD
;
5950 if (record_read_memory (gdbarch
, ir
.addr
, buf
, 8))
5953 addr
= extract_unsigned_integer (buf
, 8, byte_order
);
5957 if (record_read_memory (gdbarch
, ir
.addr
, buf
, 4))
5960 addr
= extract_unsigned_integer (buf
, 4, byte_order
);
5964 if (record_read_memory (gdbarch
, ir
.addr
, buf
, 2))
5967 addr
= extract_unsigned_integer (buf
, 2, byte_order
);
5969 if (record_full_arch_list_add_mem (addr
, 1 << ir
.ot
))
5974 case 0xb0: /* mov R, Ib */
5982 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((ir
.regmap
[X86_RECORD_R8_REGNUM
])
5983 ? ((opcode
& 0x7) | ir
.rex_b
)
5984 : ((opcode
& 0x7) & 0x3));
5987 case 0xb8: /* mov R, Iv */
5995 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode
& 0x7) | ir
.rex_b
);
5998 case 0x91: /* xchg R, EAX */
6005 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
6006 I386_RECORD_FULL_ARCH_LIST_ADD_REG (opcode
& 0x7);
6009 case 0x86: /* xchg Ev, Gv */
6011 if ((opcode
& 1) == 0)
6014 ir
.ot
= ir
.dflag
+ OT_WORD
;
6015 if (i386_record_modrm (&ir
))
6020 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
6022 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
6026 if (i386_record_lea_modrm (&ir
))
6030 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
6032 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
6035 case 0xc4: /* les Gv */
6036 case 0xc5: /* lds Gv */
6037 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
6043 case 0x0fb2: /* lss Gv */
6044 case 0x0fb4: /* lfs Gv */
6045 case 0x0fb5: /* lgs Gv */
6046 if (i386_record_modrm (&ir
))
6054 opcode
= opcode
<< 8 | ir
.modrm
;
6059 case 0xc4: /* les Gv */
6060 regnum
= X86_RECORD_ES_REGNUM
;
6062 case 0xc5: /* lds Gv */
6063 regnum
= X86_RECORD_DS_REGNUM
;
6065 case 0x0fb2: /* lss Gv */
6066 regnum
= X86_RECORD_SS_REGNUM
;
6068 case 0x0fb4: /* lfs Gv */
6069 regnum
= X86_RECORD_FS_REGNUM
;
6071 case 0x0fb5: /* lgs Gv */
6072 regnum
= X86_RECORD_GS_REGNUM
;
6075 I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum
);
6076 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
| rex_r
);
6077 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6080 case 0xc0: /* shifts */
6086 if ((opcode
& 1) == 0)
6089 ir
.ot
= ir
.dflag
+ OT_WORD
;
6090 if (i386_record_modrm (&ir
))
6092 if (ir
.mod
!= 3 && (opcode
== 0xd2 || opcode
== 0xd3))
6094 if (i386_record_lea_modrm (&ir
))
6100 if (ir
.ot
== OT_BYTE
&& !ir
.regmap
[X86_RECORD_R8_REGNUM
])
6102 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
);
6104 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6111 if (i386_record_modrm (&ir
))
6115 if (record_full_arch_list_add_reg (ir
.regcache
, ir
.rm
))
6120 if (i386_record_lea_modrm (&ir
))
6125 case 0xd8: /* Floats. */
6133 if (i386_record_modrm (&ir
))
6135 ir
.reg
|= ((opcode
& 7) << 3);
6141 if (i386_record_lea_modrm_addr (&ir
, &addr64
))
6149 /* For fcom, ficom nothing to do. */
6155 /* For fcomp, ficomp pop FPU stack, store all. */
6156 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6183 /* For fadd, fmul, fsub, fsubr, fdiv, fdivr, fiadd, fimul,
6184 fisub, fisubr, fidiv, fidivr, modR/M.reg is an extension
6185 of code, always affects st(0) register. */
6186 if (i386_record_floats (gdbarch
, &ir
, I387_ST0_REGNUM (tdep
)))
6210 /* Handling fld, fild. */
6211 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6215 switch (ir
.reg
>> 4)
6218 if (record_full_arch_list_add_mem (addr64
, 4))
6222 if (record_full_arch_list_add_mem (addr64
, 8))
6228 if (record_full_arch_list_add_mem (addr64
, 2))
6234 switch (ir
.reg
>> 4)
6237 if (record_full_arch_list_add_mem (addr64
, 4))
6239 if (3 == (ir
.reg
& 7))
6241 /* For fstp m32fp. */
6242 if (i386_record_floats (gdbarch
, &ir
,
6243 I386_SAVE_FPU_REGS
))
6248 if (record_full_arch_list_add_mem (addr64
, 4))
6250 if ((3 == (ir
.reg
& 7))
6251 || (5 == (ir
.reg
& 7))
6252 || (7 == (ir
.reg
& 7)))
6254 /* For fstp insn. */
6255 if (i386_record_floats (gdbarch
, &ir
,
6256 I386_SAVE_FPU_REGS
))
6261 if (record_full_arch_list_add_mem (addr64
, 8))
6263 if (3 == (ir
.reg
& 7))
6265 /* For fstp m64fp. */
6266 if (i386_record_floats (gdbarch
, &ir
,
6267 I386_SAVE_FPU_REGS
))
6272 if ((3 <= (ir
.reg
& 7)) && (6 <= (ir
.reg
& 7)))
6274 /* For fistp, fbld, fild, fbstp. */
6275 if (i386_record_floats (gdbarch
, &ir
,
6276 I386_SAVE_FPU_REGS
))
6281 if (record_full_arch_list_add_mem (addr64
, 2))
6290 if (i386_record_floats (gdbarch
, &ir
,
6291 I386_SAVE_FPU_ENV_REG_STACK
))
6296 if (i386_record_floats (gdbarch
, &ir
, I387_FCTRL_REGNUM (tdep
)))
6301 if (i386_record_floats (gdbarch
, &ir
,
6302 I386_SAVE_FPU_ENV_REG_STACK
))
6308 if (record_full_arch_list_add_mem (addr64
, 28))
6313 if (record_full_arch_list_add_mem (addr64
, 14))
6319 if (record_full_arch_list_add_mem (addr64
, 2))
6321 /* Insn fstp, fbstp. */
6322 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6327 if (record_full_arch_list_add_mem (addr64
, 10))
6333 if (record_full_arch_list_add_mem (addr64
, 28))
6339 if (record_full_arch_list_add_mem (addr64
, 14))
6343 if (record_full_arch_list_add_mem (addr64
, 80))
6346 if (i386_record_floats (gdbarch
, &ir
,
6347 I386_SAVE_FPU_ENV_REG_STACK
))
6351 if (record_full_arch_list_add_mem (addr64
, 8))
6354 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6359 opcode
= opcode
<< 8 | ir
.modrm
;
6364 /* Opcode is an extension of modR/M byte. */
6370 if (i386_record_floats (gdbarch
, &ir
, I387_ST0_REGNUM (tdep
)))
6374 if (0x0c == (ir
.modrm
>> 4))
6376 if ((ir
.modrm
& 0x0f) <= 7)
6378 if (i386_record_floats (gdbarch
, &ir
,
6379 I386_SAVE_FPU_REGS
))
6384 if (i386_record_floats (gdbarch
, &ir
,
6385 I387_ST0_REGNUM (tdep
)))
6387 /* If only st(0) is changing, then we have already
6389 if ((ir
.modrm
& 0x0f) - 0x08)
6391 if (i386_record_floats (gdbarch
, &ir
,
6392 I387_ST0_REGNUM (tdep
) +
6393 ((ir
.modrm
& 0x0f) - 0x08)))
6411 if (i386_record_floats (gdbarch
, &ir
,
6412 I387_ST0_REGNUM (tdep
)))
6430 if (i386_record_floats (gdbarch
, &ir
,
6431 I386_SAVE_FPU_REGS
))
6435 if (i386_record_floats (gdbarch
, &ir
,
6436 I387_ST0_REGNUM (tdep
)))
6438 if (i386_record_floats (gdbarch
, &ir
,
6439 I387_ST0_REGNUM (tdep
) + 1))
6446 if (0xe9 == ir
.modrm
)
6448 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6451 else if ((0x0c == ir
.modrm
>> 4) || (0x0d == ir
.modrm
>> 4))
6453 if (i386_record_floats (gdbarch
, &ir
,
6454 I387_ST0_REGNUM (tdep
)))
6456 if (((ir
.modrm
& 0x0f) > 0) && ((ir
.modrm
& 0x0f) <= 7))
6458 if (i386_record_floats (gdbarch
, &ir
,
6459 I387_ST0_REGNUM (tdep
) +
6463 else if ((ir
.modrm
& 0x0f) - 0x08)
6465 if (i386_record_floats (gdbarch
, &ir
,
6466 I387_ST0_REGNUM (tdep
) +
6467 ((ir
.modrm
& 0x0f) - 0x08)))
6473 if (0xe3 == ir
.modrm
)
6475 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_ENV
))
6478 else if ((0x0c == ir
.modrm
>> 4) || (0x0d == ir
.modrm
>> 4))
6480 if (i386_record_floats (gdbarch
, &ir
,
6481 I387_ST0_REGNUM (tdep
)))
6483 if (((ir
.modrm
& 0x0f) > 0) && ((ir
.modrm
& 0x0f) <= 7))
6485 if (i386_record_floats (gdbarch
, &ir
,
6486 I387_ST0_REGNUM (tdep
) +
6490 else if ((ir
.modrm
& 0x0f) - 0x08)
6492 if (i386_record_floats (gdbarch
, &ir
,
6493 I387_ST0_REGNUM (tdep
) +
6494 ((ir
.modrm
& 0x0f) - 0x08)))
6500 if ((0x0c == ir
.modrm
>> 4)
6501 || (0x0d == ir
.modrm
>> 4)
6502 || (0x0f == ir
.modrm
>> 4))
6504 if ((ir
.modrm
& 0x0f) <= 7)
6506 if (i386_record_floats (gdbarch
, &ir
,
6507 I387_ST0_REGNUM (tdep
) +
6513 if (i386_record_floats (gdbarch
, &ir
,
6514 I387_ST0_REGNUM (tdep
) +
6515 ((ir
.modrm
& 0x0f) - 0x08)))
6521 if (0x0c == ir
.modrm
>> 4)
6523 if (i386_record_floats (gdbarch
, &ir
,
6524 I387_FTAG_REGNUM (tdep
)))
6527 else if ((0x0d == ir
.modrm
>> 4) || (0x0e == ir
.modrm
>> 4))
6529 if ((ir
.modrm
& 0x0f) <= 7)
6531 if (i386_record_floats (gdbarch
, &ir
,
6532 I387_ST0_REGNUM (tdep
) +
6538 if (i386_record_floats (gdbarch
, &ir
,
6539 I386_SAVE_FPU_REGS
))
6545 if ((0x0c == ir
.modrm
>> 4)
6546 || (0x0e == ir
.modrm
>> 4)
6547 || (0x0f == ir
.modrm
>> 4)
6548 || (0xd9 == ir
.modrm
))
6550 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6555 if (0xe0 == ir
.modrm
)
6557 if (record_full_arch_list_add_reg (ir
.regcache
,
6561 else if ((0x0f == ir
.modrm
>> 4) || (0x0e == ir
.modrm
>> 4))
6563 if (i386_record_floats (gdbarch
, &ir
, I386_SAVE_FPU_REGS
))
6571 case 0xa4: /* movsS */
6573 case 0xaa: /* stosS */
6575 case 0x6c: /* insS */
6577 regcache_raw_read_unsigned (ir
.regcache
,
6578 ir
.regmap
[X86_RECORD_RECX_REGNUM
],
6584 if ((opcode
& 1) == 0)
6587 ir
.ot
= ir
.dflag
+ OT_WORD
;
6588 regcache_raw_read_unsigned (ir
.regcache
,
6589 ir
.regmap
[X86_RECORD_REDI_REGNUM
],
6592 regcache_raw_read_unsigned (ir
.regcache
,
6593 ir
.regmap
[X86_RECORD_ES_REGNUM
],
6595 regcache_raw_read_unsigned (ir
.regcache
,
6596 ir
.regmap
[X86_RECORD_DS_REGNUM
],
6598 if (ir
.aflag
&& (es
!= ds
))
6600 /* addr += ((uint32_t) read_register (I386_ES_REGNUM)) << 4; */
6601 if (record_full_memory_query
)
6604 Process record ignores the memory change of instruction at address %s\n\
6605 because it can't get the value of the segment register.\n\
6606 Do you want to stop the program?"),
6607 paddress (gdbarch
, ir
.orig_addr
)))
6613 if (record_full_arch_list_add_mem (addr
, 1 << ir
.ot
))
6617 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
))
6618 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
6619 if (opcode
== 0xa4 || opcode
== 0xa5)
6620 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM
);
6621 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM
);
6622 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6626 case 0xa6: /* cmpsS */
6628 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM
);
6629 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM
);
6630 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
))
6631 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
6632 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6635 case 0xac: /* lodsS */
6637 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
6638 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM
);
6639 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
))
6640 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
6641 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6644 case 0xae: /* scasS */
6646 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM
);
6647 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
))
6648 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
6649 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6652 case 0x6e: /* outsS */
6654 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM
);
6655 if (prefixes
& (PREFIX_REPZ
| PREFIX_REPNZ
))
6656 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
6657 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6660 case 0xe4: /* port I/O */
6664 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6665 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
6675 case 0xc2: /* ret im */
6676 case 0xc3: /* ret */
6677 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
6678 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6681 case 0xca: /* lret im */
6682 case 0xcb: /* lret */
6683 case 0xcf: /* iret */
6684 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM
);
6685 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
6686 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6689 case 0xe8: /* call im */
6690 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && ir
.dflag
)
6692 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
6696 case 0x9a: /* lcall im */
6697 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
6702 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM
);
6703 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
6707 case 0xe9: /* jmp im */
6708 case 0xea: /* ljmp im */
6709 case 0xeb: /* jmp Jb */
6710 case 0x70: /* jcc Jb */
6726 case 0x0f80: /* jcc Jv */
6744 case 0x0f90: /* setcc Gv */
6760 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6762 if (i386_record_modrm (&ir
))
6765 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rex_b
? (ir
.rm
| ir
.rex_b
)
6769 if (i386_record_lea_modrm (&ir
))
6774 case 0x0f40: /* cmov Gv, Ev */
6790 if (i386_record_modrm (&ir
))
6793 if (ir
.dflag
== OT_BYTE
)
6795 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
6799 case 0x9c: /* pushf */
6800 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6801 if (ir
.regmap
[X86_RECORD_R8_REGNUM
] && ir
.dflag
)
6803 if (i386_record_push (&ir
, 1 << (ir
.dflag
+ 1)))
6807 case 0x9d: /* popf */
6808 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
6809 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6812 case 0x9e: /* sahf */
6813 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
6819 case 0xf5: /* cmc */
6820 case 0xf8: /* clc */
6821 case 0xf9: /* stc */
6822 case 0xfc: /* cld */
6823 case 0xfd: /* std */
6824 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6827 case 0x9f: /* lahf */
6828 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
6833 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6834 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
6837 /* bit operations */
6838 case 0x0fba: /* bt/bts/btr/btc Gv, im */
6839 ir
.ot
= ir
.dflag
+ OT_WORD
;
6840 if (i386_record_modrm (&ir
))
6845 opcode
= opcode
<< 8 | ir
.modrm
;
6851 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
6854 if (i386_record_lea_modrm (&ir
))
6858 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6861 case 0x0fa3: /* bt Gv, Ev */
6862 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6865 case 0x0fab: /* bts */
6866 case 0x0fb3: /* btr */
6867 case 0x0fbb: /* btc */
6868 ir
.ot
= ir
.dflag
+ OT_WORD
;
6869 if (i386_record_modrm (&ir
))
6872 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
6876 if (i386_record_lea_modrm_addr (&ir
, &addr64
))
6878 regcache_raw_read_unsigned (ir
.regcache
,
6879 ir
.regmap
[ir
.reg
| rex_r
],
6884 addr64
+= ((int16_t) addr
>> 4) << 4;
6887 addr64
+= ((int32_t) addr
>> 5) << 5;
6890 addr64
+= ((int64_t) addr
>> 6) << 6;
6893 if (record_full_arch_list_add_mem (addr64
, 1 << ir
.ot
))
6895 if (i386_record_lea_modrm (&ir
))
6898 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6901 case 0x0fbc: /* bsf */
6902 case 0x0fbd: /* bsr */
6903 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
| rex_r
);
6904 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6908 case 0x27: /* daa */
6909 case 0x2f: /* das */
6910 case 0x37: /* aaa */
6911 case 0x3f: /* aas */
6912 case 0xd4: /* aam */
6913 case 0xd5: /* aad */
6914 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
6919 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
6920 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
6924 case 0x90: /* nop */
6925 if (prefixes
& PREFIX_LOCK
)
6932 case 0x9b: /* fwait */
6933 if (record_read_memory (gdbarch
, ir
.addr
, &opcode8
, 1))
6935 opcode
= (uint32_t) opcode8
;
6941 case 0xcc: /* int3 */
6942 gdb_printf (gdb_stderr
,
6943 _("Process record does not support instruction "
6950 case 0xcd: /* int */
6954 if (record_read_memory (gdbarch
, ir
.addr
, &interrupt
, 1))
6957 if (interrupt
!= 0x80
6958 || tdep
->i386_intx80_record
== NULL
)
6960 gdb_printf (gdb_stderr
,
6961 _("Process record does not support "
6962 "instruction int 0x%02x.\n"),
6967 ret
= tdep
->i386_intx80_record (ir
.regcache
);
6974 case 0xce: /* into */
6975 gdb_printf (gdb_stderr
,
6976 _("Process record does not support "
6977 "instruction into.\n"));
6982 case 0xfa: /* cli */
6983 case 0xfb: /* sti */
6986 case 0x62: /* bound */
6987 gdb_printf (gdb_stderr
,
6988 _("Process record does not support "
6989 "instruction bound.\n"));
6994 case 0x0fc8: /* bswap reg */
7002 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode
& 7) | ir
.rex_b
);
7005 case 0xd6: /* salc */
7006 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
7011 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
7012 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7015 case 0xe0: /* loopnz */
7016 case 0xe1: /* loopz */
7017 case 0xe2: /* loop */
7018 case 0xe3: /* jecxz */
7019 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
7020 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7023 case 0x0f30: /* wrmsr */
7024 gdb_printf (gdb_stderr
,
7025 _("Process record does not support "
7026 "instruction wrmsr.\n"));
7031 case 0x0f32: /* rdmsr */
7032 gdb_printf (gdb_stderr
,
7033 _("Process record does not support "
7034 "instruction rdmsr.\n"));
7039 case 0x0f01f9: /* rdtscp */
7040 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
7042 case 0x0f31: /* rdtsc */
7043 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
7044 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
7047 case 0x0f34: /* sysenter */
7050 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
7055 if (tdep
->i386_sysenter_record
== NULL
)
7057 gdb_printf (gdb_stderr
,
7058 _("Process record does not support "
7059 "instruction sysenter.\n"));
7063 ret
= tdep
->i386_sysenter_record (ir
.regcache
);
7069 case 0x0f35: /* sysexit */
7070 gdb_printf (gdb_stderr
,
7071 _("Process record does not support "
7072 "instruction sysexit.\n"));
7077 case 0x0f05: /* syscall */
7080 if (tdep
->i386_syscall_record
== NULL
)
7082 gdb_printf (gdb_stderr
,
7083 _("Process record does not support "
7084 "instruction syscall.\n"));
7088 ret
= tdep
->i386_syscall_record (ir
.regcache
);
7094 case 0x0f07: /* sysret */
7095 gdb_printf (gdb_stderr
,
7096 _("Process record does not support "
7097 "instruction sysret.\n"));
7102 case 0x0fa2: /* cpuid */
7103 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
7104 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
7105 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
7106 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBX_REGNUM
);
7109 case 0xf4: /* hlt */
7110 gdb_printf (gdb_stderr
,
7111 _("Process record does not support "
7112 "instruction hlt.\n"));
7118 if (i386_record_modrm (&ir
))
7125 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
7129 if (i386_record_lea_modrm (&ir
))
7138 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7142 opcode
= opcode
<< 8 | ir
.modrm
;
7149 if (i386_record_modrm (&ir
))
7151 if (ir
.modrm
== 0xf9)
7153 opcode
= (opcode
<< 8) | 0xf9;
7165 opcode
= opcode
<< 8 | ir
.modrm
;
7168 if (ir
.override
>= 0)
7170 if (record_full_memory_query
)
7173 Process record ignores the memory change of instruction at address %s\n\
7174 because it can't get the value of the segment register.\n\
7175 Do you want to stop the program?"),
7176 paddress (gdbarch
, ir
.orig_addr
)))
7182 if (i386_record_lea_modrm_addr (&ir
, &addr64
))
7184 if (record_full_arch_list_add_mem (addr64
, 2))
7187 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
7189 if (record_full_arch_list_add_mem (addr64
, 8))
7194 if (record_full_arch_list_add_mem (addr64
, 4))
7205 case 0: /* monitor */
7208 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7212 opcode
= opcode
<< 8 | ir
.modrm
;
7220 if (ir
.override
>= 0)
7222 if (record_full_memory_query
)
7225 Process record ignores the memory change of instruction at address %s\n\
7226 because it can't get the value of the segment register.\n\
7227 Do you want to stop the program?"),
7228 paddress (gdbarch
, ir
.orig_addr
)))
7236 if (i386_record_lea_modrm_addr (&ir
, &addr64
))
7238 if (record_full_arch_list_add_mem (addr64
, 2))
7241 if (ir
.regmap
[X86_RECORD_R8_REGNUM
])
7243 if (record_full_arch_list_add_mem (addr64
, 8))
7248 if (record_full_arch_list_add_mem (addr64
, 4))
7260 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
7261 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
7265 else if (ir
.rm
== 1)
7273 opcode
= opcode
<< 8 | ir
.modrm
;
7280 if (record_full_arch_list_add_reg (ir
.regcache
, ir
.rm
| ir
.rex_b
))
7286 if (i386_record_lea_modrm (&ir
))
7289 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7292 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7294 case 7: /* invlpg */
7297 if (ir
.rm
== 0 && ir
.regmap
[X86_RECORD_R8_REGNUM
])
7298 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_GS_REGNUM
);
7302 opcode
= opcode
<< 8 | ir
.modrm
;
7307 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7311 opcode
= opcode
<< 8 | ir
.modrm
;
7317 case 0x0f08: /* invd */
7318 case 0x0f09: /* wbinvd */
7321 case 0x63: /* arpl */
7322 if (i386_record_modrm (&ir
))
7324 if (ir
.mod
== 3 || ir
.regmap
[X86_RECORD_R8_REGNUM
])
7326 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.regmap
[X86_RECORD_R8_REGNUM
]
7327 ? (ir
.reg
| rex_r
) : ir
.rm
);
7331 ir
.ot
= ir
.dflag
? OT_LONG
: OT_WORD
;
7332 if (i386_record_lea_modrm (&ir
))
7335 if (!ir
.regmap
[X86_RECORD_R8_REGNUM
])
7336 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7339 case 0x0f02: /* lar */
7340 case 0x0f03: /* lsl */
7341 if (i386_record_modrm (&ir
))
7343 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
| rex_r
);
7344 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7348 if (i386_record_modrm (&ir
))
7350 if (ir
.mod
== 3 && ir
.reg
== 3)
7353 opcode
= opcode
<< 8 | ir
.modrm
;
7365 /* nop (multi byte) */
7368 case 0x0f20: /* mov reg, crN */
7369 case 0x0f22: /* mov crN, reg */
7370 if (i386_record_modrm (&ir
))
7372 if ((ir
.modrm
& 0xc0) != 0xc0)
7375 opcode
= opcode
<< 8 | ir
.modrm
;
7386 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7388 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
7392 opcode
= opcode
<< 8 | ir
.modrm
;
7398 case 0x0f21: /* mov reg, drN */
7399 case 0x0f23: /* mov drN, reg */
7400 if (i386_record_modrm (&ir
))
7402 if ((ir
.modrm
& 0xc0) != 0xc0 || ir
.reg
== 4
7403 || ir
.reg
== 5 || ir
.reg
>= 8)
7406 opcode
= opcode
<< 8 | ir
.modrm
;
7410 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7412 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
7415 case 0x0f06: /* clts */
7416 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7419 /* MMX 3DNow! SSE SSE2 SSE3 SSSE3 SSE4 */
7421 case 0x0f0d: /* 3DNow! prefetch */
7424 case 0x0f0e: /* 3DNow! femms */
7425 case 0x0f77: /* emms */
7426 if (i386_fpc_regnum_p (gdbarch
, I387_FTAG_REGNUM(tdep
)))
7428 record_full_arch_list_add_reg (ir
.regcache
, I387_FTAG_REGNUM(tdep
));
7431 case 0x0f0f: /* 3DNow! data */
7432 if (i386_record_modrm (&ir
))
7434 if (record_read_memory (gdbarch
, ir
.addr
, &opcode8
, 1))
7439 case 0x0c: /* 3DNow! pi2fw */
7440 case 0x0d: /* 3DNow! pi2fd */
7441 case 0x1c: /* 3DNow! pf2iw */
7442 case 0x1d: /* 3DNow! pf2id */
7443 case 0x8a: /* 3DNow! pfnacc */
7444 case 0x8e: /* 3DNow! pfpnacc */
7445 case 0x90: /* 3DNow! pfcmpge */
7446 case 0x94: /* 3DNow! pfmin */
7447 case 0x96: /* 3DNow! pfrcp */
7448 case 0x97: /* 3DNow! pfrsqrt */
7449 case 0x9a: /* 3DNow! pfsub */
7450 case 0x9e: /* 3DNow! pfadd */
7451 case 0xa0: /* 3DNow! pfcmpgt */
7452 case 0xa4: /* 3DNow! pfmax */
7453 case 0xa6: /* 3DNow! pfrcpit1 */
7454 case 0xa7: /* 3DNow! pfrsqit1 */
7455 case 0xaa: /* 3DNow! pfsubr */
7456 case 0xae: /* 3DNow! pfacc */
7457 case 0xb0: /* 3DNow! pfcmpeq */
7458 case 0xb4: /* 3DNow! pfmul */
7459 case 0xb6: /* 3DNow! pfrcpit2 */
7460 case 0xb7: /* 3DNow! pmulhrw */
7461 case 0xbb: /* 3DNow! pswapd */
7462 case 0xbf: /* 3DNow! pavgusb */
7463 if (!i386_mmx_regnum_p (gdbarch
, I387_MM0_REGNUM (tdep
) + ir
.reg
))
7464 goto no_support_3dnow_data
;
7465 record_full_arch_list_add_reg (ir
.regcache
, ir
.reg
);
7469 no_support_3dnow_data
:
7470 opcode
= (opcode
<< 8) | opcode8
;
7476 case 0x0faa: /* rsm */
7477 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7478 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM
);
7479 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM
);
7480 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM
);
7481 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBX_REGNUM
);
7482 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM
);
7483 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM
);
7484 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM
);
7485 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM
);
7489 if (i386_record_modrm (&ir
))
7493 case 0: /* fxsave */
7497 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7498 if (i386_record_lea_modrm_addr (&ir
, &tmpu64
))
7500 if (record_full_arch_list_add_mem (tmpu64
, 512))
7505 case 1: /* fxrstor */
7509 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7511 for (i
= I387_MM0_REGNUM (tdep
);
7512 i386_mmx_regnum_p (gdbarch
, i
); i
++)
7513 record_full_arch_list_add_reg (ir
.regcache
, i
);
7515 for (i
= I387_XMM0_REGNUM (tdep
);
7516 i386_xmm_regnum_p (gdbarch
, i
); i
++)
7517 record_full_arch_list_add_reg (ir
.regcache
, i
);
7519 if (i386_mxcsr_regnum_p (gdbarch
, I387_MXCSR_REGNUM(tdep
)))
7520 record_full_arch_list_add_reg (ir
.regcache
,
7521 I387_MXCSR_REGNUM(tdep
));
7523 for (i
= I387_ST0_REGNUM (tdep
);
7524 i386_fp_regnum_p (gdbarch
, i
); i
++)
7525 record_full_arch_list_add_reg (ir
.regcache
, i
);
7527 for (i
= I387_FCTRL_REGNUM (tdep
);
7528 i386_fpc_regnum_p (gdbarch
, i
); i
++)
7529 record_full_arch_list_add_reg (ir
.regcache
, i
);
7533 case 2: /* ldmxcsr */
7534 if (!i386_mxcsr_regnum_p (gdbarch
, I387_MXCSR_REGNUM(tdep
)))
7536 record_full_arch_list_add_reg (ir
.regcache
, I387_MXCSR_REGNUM(tdep
));
7539 case 3: /* stmxcsr */
7541 if (i386_record_lea_modrm (&ir
))
7545 case 5: /* lfence */
7546 case 6: /* mfence */
7547 case 7: /* sfence clflush */
7551 opcode
= (opcode
<< 8) | ir
.modrm
;
7557 case 0x0fc3: /* movnti */
7558 ir
.ot
= (ir
.dflag
== 2) ? OT_QUAD
: OT_LONG
;
7559 if (i386_record_modrm (&ir
))
7564 if (i386_record_lea_modrm (&ir
))
7568 /* Add prefix to opcode. */
7683 /* Mask out PREFIX_ADDR. */
7684 switch ((prefixes
& ~PREFIX_ADDR
))
7696 reswitch_prefix_add
:
7704 if (record_read_memory (gdbarch
, ir
.addr
, &opcode8
, 1))
7707 opcode
= (uint32_t) opcode8
| opcode
<< 8;
7708 goto reswitch_prefix_add
;
7711 case 0x0f10: /* movups */
7712 case 0x660f10: /* movupd */
7713 case 0xf30f10: /* movss */
7714 case 0xf20f10: /* movsd */
7715 case 0x0f12: /* movlps */
7716 case 0x660f12: /* movlpd */
7717 case 0xf30f12: /* movsldup */
7718 case 0xf20f12: /* movddup */
7719 case 0x0f14: /* unpcklps */
7720 case 0x660f14: /* unpcklpd */
7721 case 0x0f15: /* unpckhps */
7722 case 0x660f15: /* unpckhpd */
7723 case 0x0f16: /* movhps */
7724 case 0x660f16: /* movhpd */
7725 case 0xf30f16: /* movshdup */
7726 case 0x0f28: /* movaps */
7727 case 0x660f28: /* movapd */
7728 case 0x0f2a: /* cvtpi2ps */
7729 case 0x660f2a: /* cvtpi2pd */
7730 case 0xf30f2a: /* cvtsi2ss */
7731 case 0xf20f2a: /* cvtsi2sd */
7732 case 0x0f2c: /* cvttps2pi */
7733 case 0x660f2c: /* cvttpd2pi */
7734 case 0x0f2d: /* cvtps2pi */
7735 case 0x660f2d: /* cvtpd2pi */
7736 case 0x660f3800: /* pshufb */
7737 case 0x660f3801: /* phaddw */
7738 case 0x660f3802: /* phaddd */
7739 case 0x660f3803: /* phaddsw */
7740 case 0x660f3804: /* pmaddubsw */
7741 case 0x660f3805: /* phsubw */
7742 case 0x660f3806: /* phsubd */
7743 case 0x660f3807: /* phsubsw */
7744 case 0x660f3808: /* psignb */
7745 case 0x660f3809: /* psignw */
7746 case 0x660f380a: /* psignd */
7747 case 0x660f380b: /* pmulhrsw */
7748 case 0x660f3810: /* pblendvb */
7749 case 0x660f3814: /* blendvps */
7750 case 0x660f3815: /* blendvpd */
7751 case 0x660f381c: /* pabsb */
7752 case 0x660f381d: /* pabsw */
7753 case 0x660f381e: /* pabsd */
7754 case 0x660f3820: /* pmovsxbw */
7755 case 0x660f3821: /* pmovsxbd */
7756 case 0x660f3822: /* pmovsxbq */
7757 case 0x660f3823: /* pmovsxwd */
7758 case 0x660f3824: /* pmovsxwq */
7759 case 0x660f3825: /* pmovsxdq */
7760 case 0x660f3828: /* pmuldq */
7761 case 0x660f3829: /* pcmpeqq */
7762 case 0x660f382a: /* movntdqa */
7763 case 0x660f3a08: /* roundps */
7764 case 0x660f3a09: /* roundpd */
7765 case 0x660f3a0a: /* roundss */
7766 case 0x660f3a0b: /* roundsd */
7767 case 0x660f3a0c: /* blendps */
7768 case 0x660f3a0d: /* blendpd */
7769 case 0x660f3a0e: /* pblendw */
7770 case 0x660f3a0f: /* palignr */
7771 case 0x660f3a20: /* pinsrb */
7772 case 0x660f3a21: /* insertps */
7773 case 0x660f3a22: /* pinsrd pinsrq */
7774 case 0x660f3a40: /* dpps */
7775 case 0x660f3a41: /* dppd */
7776 case 0x660f3a42: /* mpsadbw */
7777 case 0x660f3a60: /* pcmpestrm */
7778 case 0x660f3a61: /* pcmpestri */
7779 case 0x660f3a62: /* pcmpistrm */
7780 case 0x660f3a63: /* pcmpistri */
7781 case 0x0f51: /* sqrtps */
7782 case 0x660f51: /* sqrtpd */
7783 case 0xf20f51: /* sqrtsd */
7784 case 0xf30f51: /* sqrtss */
7785 case 0x0f52: /* rsqrtps */
7786 case 0xf30f52: /* rsqrtss */
7787 case 0x0f53: /* rcpps */
7788 case 0xf30f53: /* rcpss */
7789 case 0x0f54: /* andps */
7790 case 0x660f54: /* andpd */
7791 case 0x0f55: /* andnps */
7792 case 0x660f55: /* andnpd */
7793 case 0x0f56: /* orps */
7794 case 0x660f56: /* orpd */
7795 case 0x0f57: /* xorps */
7796 case 0x660f57: /* xorpd */
7797 case 0x0f58: /* addps */
7798 case 0x660f58: /* addpd */
7799 case 0xf20f58: /* addsd */
7800 case 0xf30f58: /* addss */
7801 case 0x0f59: /* mulps */
7802 case 0x660f59: /* mulpd */
7803 case 0xf20f59: /* mulsd */
7804 case 0xf30f59: /* mulss */
7805 case 0x0f5a: /* cvtps2pd */
7806 case 0x660f5a: /* cvtpd2ps */
7807 case 0xf20f5a: /* cvtsd2ss */
7808 case 0xf30f5a: /* cvtss2sd */
7809 case 0x0f5b: /* cvtdq2ps */
7810 case 0x660f5b: /* cvtps2dq */
7811 case 0xf30f5b: /* cvttps2dq */
7812 case 0x0f5c: /* subps */
7813 case 0x660f5c: /* subpd */
7814 case 0xf20f5c: /* subsd */
7815 case 0xf30f5c: /* subss */
7816 case 0x0f5d: /* minps */
7817 case 0x660f5d: /* minpd */
7818 case 0xf20f5d: /* minsd */
7819 case 0xf30f5d: /* minss */
7820 case 0x0f5e: /* divps */
7821 case 0x660f5e: /* divpd */
7822 case 0xf20f5e: /* divsd */
7823 case 0xf30f5e: /* divss */
7824 case 0x0f5f: /* maxps */
7825 case 0x660f5f: /* maxpd */
7826 case 0xf20f5f: /* maxsd */
7827 case 0xf30f5f: /* maxss */
7828 case 0x660f60: /* punpcklbw */
7829 case 0x660f61: /* punpcklwd */
7830 case 0x660f62: /* punpckldq */
7831 case 0x660f63: /* packsswb */
7832 case 0x660f64: /* pcmpgtb */
7833 case 0x660f65: /* pcmpgtw */
7834 case 0x660f66: /* pcmpgtd */
7835 case 0x660f67: /* packuswb */
7836 case 0x660f68: /* punpckhbw */
7837 case 0x660f69: /* punpckhwd */
7838 case 0x660f6a: /* punpckhdq */
7839 case 0x660f6b: /* packssdw */
7840 case 0x660f6c: /* punpcklqdq */
7841 case 0x660f6d: /* punpckhqdq */
7842 case 0x660f6e: /* movd */
7843 case 0x660f6f: /* movdqa */
7844 case 0xf30f6f: /* movdqu */
7845 case 0x660f70: /* pshufd */
7846 case 0xf20f70: /* pshuflw */
7847 case 0xf30f70: /* pshufhw */
7848 case 0x660f74: /* pcmpeqb */
7849 case 0x660f75: /* pcmpeqw */
7850 case 0x660f76: /* pcmpeqd */
7851 case 0x660f7c: /* haddpd */
7852 case 0xf20f7c: /* haddps */
7853 case 0x660f7d: /* hsubpd */
7854 case 0xf20f7d: /* hsubps */
7855 case 0xf30f7e: /* movq */
7856 case 0x0fc2: /* cmpps */
7857 case 0x660fc2: /* cmppd */
7858 case 0xf20fc2: /* cmpsd */
7859 case 0xf30fc2: /* cmpss */
7860 case 0x660fc4: /* pinsrw */
7861 case 0x0fc6: /* shufps */
7862 case 0x660fc6: /* shufpd */
7863 case 0x660fd0: /* addsubpd */
7864 case 0xf20fd0: /* addsubps */
7865 case 0x660fd1: /* psrlw */
7866 case 0x660fd2: /* psrld */
7867 case 0x660fd3: /* psrlq */
7868 case 0x660fd4: /* paddq */
7869 case 0x660fd5: /* pmullw */
7870 case 0xf30fd6: /* movq2dq */
7871 case 0x660fd8: /* psubusb */
7872 case 0x660fd9: /* psubusw */
7873 case 0x660fda: /* pminub */
7874 case 0x660fdb: /* pand */
7875 case 0x660fdc: /* paddusb */
7876 case 0x660fdd: /* paddusw */
7877 case 0x660fde: /* pmaxub */
7878 case 0x660fdf: /* pandn */
7879 case 0x660fe0: /* pavgb */
7880 case 0x660fe1: /* psraw */
7881 case 0x660fe2: /* psrad */
7882 case 0x660fe3: /* pavgw */
7883 case 0x660fe4: /* pmulhuw */
7884 case 0x660fe5: /* pmulhw */
7885 case 0x660fe6: /* cvttpd2dq */
7886 case 0xf20fe6: /* cvtpd2dq */
7887 case 0xf30fe6: /* cvtdq2pd */
7888 case 0x660fe8: /* psubsb */
7889 case 0x660fe9: /* psubsw */
7890 case 0x660fea: /* pminsw */
7891 case 0x660feb: /* por */
7892 case 0x660fec: /* paddsb */
7893 case 0x660fed: /* paddsw */
7894 case 0x660fee: /* pmaxsw */
7895 case 0x660fef: /* pxor */
7896 case 0xf20ff0: /* lddqu */
7897 case 0x660ff1: /* psllw */
7898 case 0x660ff2: /* pslld */
7899 case 0x660ff3: /* psllq */
7900 case 0x660ff4: /* pmuludq */
7901 case 0x660ff5: /* pmaddwd */
7902 case 0x660ff6: /* psadbw */
7903 case 0x660ff8: /* psubb */
7904 case 0x660ff9: /* psubw */
7905 case 0x660ffa: /* psubd */
7906 case 0x660ffb: /* psubq */
7907 case 0x660ffc: /* paddb */
7908 case 0x660ffd: /* paddw */
7909 case 0x660ffe: /* paddd */
7910 if (i386_record_modrm (&ir
))
7913 if (!i386_xmm_regnum_p (gdbarch
, I387_XMM0_REGNUM (tdep
) + ir
.reg
))
7915 record_full_arch_list_add_reg (ir
.regcache
,
7916 I387_XMM0_REGNUM (tdep
) + ir
.reg
);
7917 if ((opcode
& 0xfffffffc) == 0x660f3a60)
7918 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
7921 case 0x0f11: /* movups */
7922 case 0x660f11: /* movupd */
7923 case 0xf30f11: /* movss */
7924 case 0xf20f11: /* movsd */
7925 case 0x0f13: /* movlps */
7926 case 0x660f13: /* movlpd */
7927 case 0x0f17: /* movhps */
7928 case 0x660f17: /* movhpd */
7929 case 0x0f29: /* movaps */
7930 case 0x660f29: /* movapd */
7931 case 0x660f3a14: /* pextrb */
7932 case 0x660f3a15: /* pextrw */
7933 case 0x660f3a16: /* pextrd pextrq */
7934 case 0x660f3a17: /* extractps */
7935 case 0x660f7f: /* movdqa */
7936 case 0xf30f7f: /* movdqu */
7937 if (i386_record_modrm (&ir
))
7941 if (opcode
== 0x0f13 || opcode
== 0x660f13
7942 || opcode
== 0x0f17 || opcode
== 0x660f17)
7945 if (!i386_xmm_regnum_p (gdbarch
,
7946 I387_XMM0_REGNUM (tdep
) + ir
.rm
))
7948 record_full_arch_list_add_reg (ir
.regcache
,
7949 I387_XMM0_REGNUM (tdep
) + ir
.rm
);
7971 if (i386_record_lea_modrm (&ir
))
7976 case 0x0f2b: /* movntps */
7977 case 0x660f2b: /* movntpd */
7978 case 0x0fe7: /* movntq */
7979 case 0x660fe7: /* movntdq */
7982 if (opcode
== 0x0fe7)
7986 if (i386_record_lea_modrm (&ir
))
7990 case 0xf30f2c: /* cvttss2si */
7991 case 0xf20f2c: /* cvttsd2si */
7992 case 0xf30f2d: /* cvtss2si */
7993 case 0xf20f2d: /* cvtsd2si */
7994 case 0xf20f38f0: /* crc32 */
7995 case 0xf20f38f1: /* crc32 */
7996 case 0x0f50: /* movmskps */
7997 case 0x660f50: /* movmskpd */
7998 case 0x0fc5: /* pextrw */
7999 case 0x660fc5: /* pextrw */
8000 case 0x0fd7: /* pmovmskb */
8001 case 0x660fd7: /* pmovmskb */
8002 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
| rex_r
);
8005 case 0x0f3800: /* pshufb */
8006 case 0x0f3801: /* phaddw */
8007 case 0x0f3802: /* phaddd */
8008 case 0x0f3803: /* phaddsw */
8009 case 0x0f3804: /* pmaddubsw */
8010 case 0x0f3805: /* phsubw */
8011 case 0x0f3806: /* phsubd */
8012 case 0x0f3807: /* phsubsw */
8013 case 0x0f3808: /* psignb */
8014 case 0x0f3809: /* psignw */
8015 case 0x0f380a: /* psignd */
8016 case 0x0f380b: /* pmulhrsw */
8017 case 0x0f381c: /* pabsb */
8018 case 0x0f381d: /* pabsw */
8019 case 0x0f381e: /* pabsd */
8020 case 0x0f382b: /* packusdw */
8021 case 0x0f3830: /* pmovzxbw */
8022 case 0x0f3831: /* pmovzxbd */
8023 case 0x0f3832: /* pmovzxbq */
8024 case 0x0f3833: /* pmovzxwd */
8025 case 0x0f3834: /* pmovzxwq */
8026 case 0x0f3835: /* pmovzxdq */
8027 case 0x0f3837: /* pcmpgtq */
8028 case 0x0f3838: /* pminsb */
8029 case 0x0f3839: /* pminsd */
8030 case 0x0f383a: /* pminuw */
8031 case 0x0f383b: /* pminud */
8032 case 0x0f383c: /* pmaxsb */
8033 case 0x0f383d: /* pmaxsd */
8034 case 0x0f383e: /* pmaxuw */
8035 case 0x0f383f: /* pmaxud */
8036 case 0x0f3840: /* pmulld */
8037 case 0x0f3841: /* phminposuw */
8038 case 0x0f3a0f: /* palignr */
8039 case 0x0f60: /* punpcklbw */
8040 case 0x0f61: /* punpcklwd */
8041 case 0x0f62: /* punpckldq */
8042 case 0x0f63: /* packsswb */
8043 case 0x0f64: /* pcmpgtb */
8044 case 0x0f65: /* pcmpgtw */
8045 case 0x0f66: /* pcmpgtd */
8046 case 0x0f67: /* packuswb */
8047 case 0x0f68: /* punpckhbw */
8048 case 0x0f69: /* punpckhwd */
8049 case 0x0f6a: /* punpckhdq */
8050 case 0x0f6b: /* packssdw */
8051 case 0x0f6e: /* movd */
8052 case 0x0f6f: /* movq */
8053 case 0x0f70: /* pshufw */
8054 case 0x0f74: /* pcmpeqb */
8055 case 0x0f75: /* pcmpeqw */
8056 case 0x0f76: /* pcmpeqd */
8057 case 0x0fc4: /* pinsrw */
8058 case 0x0fd1: /* psrlw */
8059 case 0x0fd2: /* psrld */
8060 case 0x0fd3: /* psrlq */
8061 case 0x0fd4: /* paddq */
8062 case 0x0fd5: /* pmullw */
8063 case 0xf20fd6: /* movdq2q */
8064 case 0x0fd8: /* psubusb */
8065 case 0x0fd9: /* psubusw */
8066 case 0x0fda: /* pminub */
8067 case 0x0fdb: /* pand */
8068 case 0x0fdc: /* paddusb */
8069 case 0x0fdd: /* paddusw */
8070 case 0x0fde: /* pmaxub */
8071 case 0x0fdf: /* pandn */
8072 case 0x0fe0: /* pavgb */
8073 case 0x0fe1: /* psraw */
8074 case 0x0fe2: /* psrad */
8075 case 0x0fe3: /* pavgw */
8076 case 0x0fe4: /* pmulhuw */
8077 case 0x0fe5: /* pmulhw */
8078 case 0x0fe8: /* psubsb */
8079 case 0x0fe9: /* psubsw */
8080 case 0x0fea: /* pminsw */
8081 case 0x0feb: /* por */
8082 case 0x0fec: /* paddsb */
8083 case 0x0fed: /* paddsw */
8084 case 0x0fee: /* pmaxsw */
8085 case 0x0fef: /* pxor */
8086 case 0x0ff1: /* psllw */
8087 case 0x0ff2: /* pslld */
8088 case 0x0ff3: /* psllq */
8089 case 0x0ff4: /* pmuludq */
8090 case 0x0ff5: /* pmaddwd */
8091 case 0x0ff6: /* psadbw */
8092 case 0x0ff8: /* psubb */
8093 case 0x0ff9: /* psubw */
8094 case 0x0ffa: /* psubd */
8095 case 0x0ffb: /* psubq */
8096 case 0x0ffc: /* paddb */
8097 case 0x0ffd: /* paddw */
8098 case 0x0ffe: /* paddd */
8099 if (i386_record_modrm (&ir
))
8101 if (!i386_mmx_regnum_p (gdbarch
, I387_MM0_REGNUM (tdep
) + ir
.reg
))
8103 record_full_arch_list_add_reg (ir
.regcache
,
8104 I387_MM0_REGNUM (tdep
) + ir
.reg
);
8107 case 0x0f71: /* psllw */
8108 case 0x0f72: /* pslld */
8109 case 0x0f73: /* psllq */
8110 if (i386_record_modrm (&ir
))
8112 if (!i386_mmx_regnum_p (gdbarch
, I387_MM0_REGNUM (tdep
) + ir
.rm
))
8114 record_full_arch_list_add_reg (ir
.regcache
,
8115 I387_MM0_REGNUM (tdep
) + ir
.rm
);
8118 case 0x660f71: /* psllw */
8119 case 0x660f72: /* pslld */
8120 case 0x660f73: /* psllq */
8121 if (i386_record_modrm (&ir
))
8124 if (!i386_xmm_regnum_p (gdbarch
, I387_XMM0_REGNUM (tdep
) + ir
.rm
))
8126 record_full_arch_list_add_reg (ir
.regcache
,
8127 I387_XMM0_REGNUM (tdep
) + ir
.rm
);
8130 case 0x0f7e: /* movd */
8131 case 0x660f7e: /* movd */
8132 if (i386_record_modrm (&ir
))
8135 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.rm
| ir
.rex_b
);
8142 if (i386_record_lea_modrm (&ir
))
8147 case 0x0f7f: /* movq */
8148 if (i386_record_modrm (&ir
))
8152 if (!i386_mmx_regnum_p (gdbarch
, I387_MM0_REGNUM (tdep
) + ir
.rm
))
8154 record_full_arch_list_add_reg (ir
.regcache
,
8155 I387_MM0_REGNUM (tdep
) + ir
.rm
);
8160 if (i386_record_lea_modrm (&ir
))
8165 case 0xf30fb8: /* popcnt */
8166 if (i386_record_modrm (&ir
))
8168 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir
.reg
);
8169 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
8172 case 0x660fd6: /* movq */
8173 if (i386_record_modrm (&ir
))
8178 if (!i386_xmm_regnum_p (gdbarch
,
8179 I387_XMM0_REGNUM (tdep
) + ir
.rm
))
8181 record_full_arch_list_add_reg (ir
.regcache
,
8182 I387_XMM0_REGNUM (tdep
) + ir
.rm
);
8187 if (i386_record_lea_modrm (&ir
))
8192 case 0x660f3817: /* ptest */
8193 case 0x0f2e: /* ucomiss */
8194 case 0x660f2e: /* ucomisd */
8195 case 0x0f2f: /* comiss */
8196 case 0x660f2f: /* comisd */
8197 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM
);
8200 case 0x0ff7: /* maskmovq */
8201 regcache_raw_read_unsigned (ir
.regcache
,
8202 ir
.regmap
[X86_RECORD_REDI_REGNUM
],
8204 if (record_full_arch_list_add_mem (addr
, 64))
8208 case 0x660ff7: /* maskmovdqu */
8209 regcache_raw_read_unsigned (ir
.regcache
,
8210 ir
.regmap
[X86_RECORD_REDI_REGNUM
],
8212 if (record_full_arch_list_add_mem (addr
, 128))
8227 /* In the future, maybe still need to deal with need_dasm. */
8228 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REIP_REGNUM
);
8229 if (record_full_arch_list_add_end ())
8235 gdb_printf (gdb_stderr
,
8236 _("Process record does not support instruction 0x%02x "
8237 "at address %s.\n"),
8238 (unsigned int) (opcode
),
8239 paddress (gdbarch
, ir
.orig_addr
));
8243 static const int i386_record_regmap
[] =
8245 I386_EAX_REGNUM
, I386_ECX_REGNUM
, I386_EDX_REGNUM
, I386_EBX_REGNUM
,
8246 I386_ESP_REGNUM
, I386_EBP_REGNUM
, I386_ESI_REGNUM
, I386_EDI_REGNUM
,
8249 I386_EIP_REGNUM
, I386_EFLAGS_REGNUM
, I386_CS_REGNUM
, I386_SS_REGNUM
,
8250 I386_DS_REGNUM
, I386_ES_REGNUM
, I386_FS_REGNUM
, I386_GS_REGNUM
,
8254 /* Check that the given address appears suitable for a fast
8255 tracepoint, which on x86-64 means that we need an instruction of at
8256 least 5 bytes, so that we can overwrite it with a 4-byte-offset
8257 jump and not have to worry about program jumps to an address in the
8258 middle of the tracepoint jump. On x86, it may be possible to use
8259 4-byte jumps with a 2-byte offset to a trampoline located in the
8260 bottom 64 KiB of memory. Returns 1 if OK, and writes a size
8261 of instruction to replace, and 0 if not, plus an explanatory
8265 i386_fast_tracepoint_valid_at (struct gdbarch
*gdbarch
, CORE_ADDR addr
,
8270 /* Ask the target for the minimum instruction length supported. */
8271 jumplen
= target_get_min_fast_tracepoint_insn_len ();
8275 /* If the target does not support the get_min_fast_tracepoint_insn_len
8276 operation, assume that fast tracepoints will always be implemented
8277 using 4-byte relative jumps on both x86 and x86-64. */
8280 else if (jumplen
== 0)
8282 /* If the target does support get_min_fast_tracepoint_insn_len but
8283 returns zero, then the IPA has not loaded yet. In this case,
8284 we optimistically assume that truncated 2-byte relative jumps
8285 will be available on x86, and compensate later if this assumption
8286 turns out to be incorrect. On x86-64 architectures, 4-byte relative
8287 jumps will always be used. */
8288 jumplen
= (register_size (gdbarch
, 0) == 8) ? 5 : 4;
8291 /* Check for fit. */
8292 len
= gdb_insn_length (gdbarch
, addr
);
8296 /* Return a bit of target-specific detail to add to the caller's
8297 generic failure message. */
8299 *msg
= string_printf (_("; instruction is only %d bytes long, "
8300 "need at least %d bytes for the jump"),
8312 /* Return a floating-point format for a floating-point variable of
8313 length LEN in bits. If non-NULL, NAME is the name of its type.
8314 If no suitable type is found, return NULL. */
8316 static const struct floatformat
**
8317 i386_floatformat_for_type (struct gdbarch
*gdbarch
,
8318 const char *name
, int len
)
8320 if (len
== 128 && name
)
8321 if (strcmp (name
, "__float128") == 0
8322 || strcmp (name
, "_Float128") == 0
8323 || strcmp (name
, "complex _Float128") == 0
8324 || strcmp (name
, "complex(kind=16)") == 0
8325 || strcmp (name
, "COMPLEX(16)") == 0
8326 || strcmp (name
, "complex*32") == 0
8327 || strcmp (name
, "COMPLEX*32") == 0
8328 || strcmp (name
, "quad complex") == 0
8329 || strcmp (name
, "real(kind=16)") == 0
8330 || strcmp (name
, "real*16") == 0
8331 || strcmp (name
, "REAL*16") == 0
8332 || strcmp (name
, "REAL(16)") == 0)
8333 return floatformats_ieee_quad
;
8335 return default_floatformat_for_type (gdbarch
, name
, len
);
8338 /* Compute an XCR0 mask based on a target description. */
8341 i386_xcr0_from_tdesc (const struct target_desc
*tdesc
)
8343 if (! tdesc_has_registers (tdesc
))
8346 const struct tdesc_feature
*feature_core
;
8348 const struct tdesc_feature
*feature_sse
, *feature_avx
,
8349 *feature_avx512
, *feature_pkeys
;
8351 /* Get core registers. */
8352 feature_core
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.core");
8353 if (feature_core
== NULL
)
8356 /* Get SSE registers. */
8357 feature_sse
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.sse");
8359 /* Try AVX registers. */
8360 feature_avx
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.avx");
8362 /* Try AVX512 registers. */
8363 feature_avx512
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.avx512");
8366 feature_pkeys
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.pkeys");
8368 /* The XCR0 bits. */
8369 uint64_t xcr0
= X86_XSTATE_X87
;
8372 xcr0
|= X86_XSTATE_SSE
;
8376 /* AVX register description requires SSE register description. */
8380 xcr0
|= X86_XSTATE_AVX
;
8385 /* AVX512 register description requires AVX register description. */
8389 xcr0
|= X86_XSTATE_AVX512
;
8393 xcr0
|= X86_XSTATE_PKRU
;
8399 i386_validate_tdesc_p (i386_gdbarch_tdep
*tdep
,
8400 struct tdesc_arch_data
*tdesc_data
)
8402 const struct target_desc
*tdesc
= tdep
->tdesc
;
8403 const struct tdesc_feature
*feature_core
;
8405 const struct tdesc_feature
*feature_sse
, *feature_avx
, *feature_avx512
,
8406 *feature_pkeys
, *feature_segments
;
8407 int i
, num_regs
, valid_p
;
8409 if (! tdesc_has_registers (tdesc
))
8412 /* Get core registers. */
8413 feature_core
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.core");
8414 if (feature_core
== NULL
)
8417 /* Get SSE registers. */
8418 feature_sse
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.sse");
8420 /* Try AVX registers. */
8421 feature_avx
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.avx");
8423 /* Try AVX512 registers. */
8424 feature_avx512
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.avx512");
8426 /* Try segment base registers. */
8427 feature_segments
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.segments");
8430 feature_pkeys
= tdesc_find_feature (tdesc
, "org.gnu.gdb.i386.pkeys");
8434 /* The XCR0 bits. */
8437 /* AVX512 register description requires AVX register description. */
8441 tdep
->xcr0
= X86_XSTATE_AVX_AVX512_MASK
;
8443 /* It may have been set by OSABI initialization function. */
8444 if (tdep
->k0_regnum
< 0)
8446 tdep
->k_register_names
= i386_k_names
;
8447 tdep
->k0_regnum
= I386_K0_REGNUM
;
8450 for (i
= 0; i
< I387_NUM_K_REGS
; i
++)
8451 valid_p
&= tdesc_numbered_register (feature_avx512
, tdesc_data
,
8452 tdep
->k0_regnum
+ i
,
8455 if (tdep
->num_zmm_regs
== 0)
8457 tdep
->zmmh_register_names
= i386_zmmh_names
;
8458 tdep
->num_zmm_regs
= 8;
8459 tdep
->zmm0h_regnum
= I386_ZMM0H_REGNUM
;
8462 for (i
= 0; i
< tdep
->num_zmm_regs
; i
++)
8463 valid_p
&= tdesc_numbered_register (feature_avx512
, tdesc_data
,
8464 tdep
->zmm0h_regnum
+ i
,
8465 tdep
->zmmh_register_names
[i
]);
8467 for (i
= 0; i
< tdep
->num_xmm_avx512_regs
; i
++)
8468 valid_p
&= tdesc_numbered_register (feature_avx512
, tdesc_data
,
8469 tdep
->xmm16_regnum
+ i
,
8470 tdep
->xmm_avx512_register_names
[i
]);
8472 for (i
= 0; i
< tdep
->num_ymm_avx512_regs
; i
++)
8473 valid_p
&= tdesc_numbered_register (feature_avx512
, tdesc_data
,
8474 tdep
->ymm16h_regnum
+ i
,
8475 tdep
->ymm16h_register_names
[i
]);
8479 /* AVX register description requires SSE register description. */
8483 if (!feature_avx512
)
8484 tdep
->xcr0
= X86_XSTATE_AVX_MASK
;
8486 /* It may have been set by OSABI initialization function. */
8487 if (tdep
->num_ymm_regs
== 0)
8489 tdep
->ymmh_register_names
= i386_ymmh_names
;
8490 tdep
->num_ymm_regs
= 8;
8491 tdep
->ymm0h_regnum
= I386_YMM0H_REGNUM
;
8494 for (i
= 0; i
< tdep
->num_ymm_regs
; i
++)
8495 valid_p
&= tdesc_numbered_register (feature_avx
, tdesc_data
,
8496 tdep
->ymm0h_regnum
+ i
,
8497 tdep
->ymmh_register_names
[i
]);
8499 else if (feature_sse
)
8500 tdep
->xcr0
= X86_XSTATE_SSE_MASK
;
8503 tdep
->xcr0
= X86_XSTATE_X87_MASK
;
8504 tdep
->num_xmm_regs
= 0;
8507 num_regs
= tdep
->num_core_regs
;
8508 for (i
= 0; i
< num_regs
; i
++)
8509 valid_p
&= tdesc_numbered_register (feature_core
, tdesc_data
, i
,
8510 tdep
->register_names
[i
]);
8514 /* Need to include %mxcsr, so add one. */
8515 num_regs
+= tdep
->num_xmm_regs
+ 1;
8516 for (; i
< num_regs
; i
++)
8517 valid_p
&= tdesc_numbered_register (feature_sse
, tdesc_data
, i
,
8518 tdep
->register_names
[i
]);
8521 if (feature_segments
)
8523 if (tdep
->fsbase_regnum
< 0)
8524 tdep
->fsbase_regnum
= I386_FSBASE_REGNUM
;
8525 valid_p
&= tdesc_numbered_register (feature_segments
, tdesc_data
,
8526 tdep
->fsbase_regnum
, "fs_base");
8527 valid_p
&= tdesc_numbered_register (feature_segments
, tdesc_data
,
8528 tdep
->fsbase_regnum
+ 1, "gs_base");
8533 tdep
->xcr0
|= X86_XSTATE_PKRU
;
8534 if (tdep
->pkru_regnum
< 0)
8536 tdep
->pkeys_register_names
= i386_pkeys_names
;
8537 tdep
->pkru_regnum
= I386_PKRU_REGNUM
;
8538 tdep
->num_pkeys_regs
= 1;
8541 for (i
= 0; i
< I387_NUM_PKEYS_REGS
; i
++)
8542 valid_p
&= tdesc_numbered_register (feature_pkeys
, tdesc_data
,
8543 I387_PKRU_REGNUM (tdep
) + i
,
8544 tdep
->pkeys_register_names
[i
]);
8552 /* Implement the type_align gdbarch function. */
8555 i386_type_align (struct gdbarch
*gdbarch
, struct type
*type
)
8557 type
= check_typedef (type
);
8559 if (gdbarch_ptr_bit (gdbarch
) == 32)
8561 if ((type
->code () == TYPE_CODE_INT
8562 || type
->code () == TYPE_CODE_FLT
)
8563 && type
->length () > 4)
8566 /* Handle x86's funny long double. */
8567 if (type
->code () == TYPE_CODE_FLT
8568 && gdbarch_long_double_bit (gdbarch
) == type
->length () * 8)
8576 /* Note: This is called for both i386 and amd64. */
8578 static struct gdbarch
*
8579 i386_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
8581 const struct target_desc
*tdesc
;
8585 x86_xsave_layout xsave_layout
= target_fetch_x86_xsave_layout ();
8587 /* If the target did not provide an XSAVE layout but the target
8588 description includes registers from the XSAVE extended region,
8589 use a fallback XSAVE layout. Specifically, this fallback layout
8590 is used when writing out a local core dump for a remote
8592 if (xsave_layout
.sizeof_xsave
== 0)
8594 = i387_fallback_xsave_layout (i386_xcr0_from_tdesc (info
.target_desc
));
8596 /* If there is already a candidate, use it. */
8597 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
8599 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
8601 /* Check that the XSAVE layout of ARCHES matches the layout for
8602 the current target. */
8603 i386_gdbarch_tdep
*other_tdep
8604 = gdbarch_tdep
<i386_gdbarch_tdep
> (arches
->gdbarch
);
8606 if (other_tdep
->xsave_layout
== xsave_layout
)
8607 return arches
->gdbarch
;
8610 /* Allocate space for the new architecture. Assume i386 for now. */
8612 = gdbarch_alloc (&info
, gdbarch_tdep_up (new i386_gdbarch_tdep
));
8613 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
8615 /* General-purpose registers. */
8616 tdep
->gregset_reg_offset
= NULL
;
8617 tdep
->gregset_num_regs
= I386_NUM_GREGS
;
8618 tdep
->sizeof_gregset
= 0;
8620 /* Floating-point registers. */
8621 tdep
->sizeof_fpregset
= I387_SIZEOF_FSAVE
;
8622 tdep
->fpregset
= &i386_fpregset
;
8624 /* The default settings include the FPU registers, the MMX registers
8625 and the SSE registers. This can be overridden for a specific ABI
8626 by adjusting the members `st0_regnum', `mm0_regnum' and
8627 `num_xmm_regs' of `struct gdbarch_tdep', otherwise the registers
8628 will show up in the output of "info all-registers". */
8630 tdep
->st0_regnum
= I386_ST0_REGNUM
;
8632 /* I386_NUM_XREGS includes %mxcsr, so subtract one. */
8633 tdep
->num_xmm_regs
= I386_NUM_XREGS
- 1;
8635 tdep
->jb_pc_offset
= -1;
8636 tdep
->struct_return
= pcc_struct_return
;
8637 tdep
->sigtramp_start
= 0;
8638 tdep
->sigtramp_end
= 0;
8639 tdep
->sigtramp_p
= i386_sigtramp_p
;
8640 tdep
->sigcontext_addr
= NULL
;
8641 tdep
->sc_reg_offset
= NULL
;
8642 tdep
->sc_pc_offset
= -1;
8643 tdep
->sc_sp_offset
= -1;
8645 tdep
->xsave_xcr0_offset
= -1;
8647 tdep
->record_regmap
= i386_record_regmap
;
8649 set_gdbarch_type_align (gdbarch
, i386_type_align
);
8651 /* The format used for `long double' on almost all i386 targets is
8652 the i387 extended floating-point format. In fact, of all targets
8653 in the GCC 2.95 tree, only OSF/1 does it different, and insists
8654 on having a `long double' that's not `long' at all. */
8655 set_gdbarch_long_double_format (gdbarch
, floatformats_i387_ext
);
8657 /* Although the i387 extended floating-point has only 80 significant
8658 bits, a `long double' actually takes up 96, probably to enforce
8660 set_gdbarch_long_double_bit (gdbarch
, 96);
8662 /* Support of bfloat16 format. */
8663 set_gdbarch_bfloat16_format (gdbarch
, floatformats_bfloat16
);
8665 /* Support for floating-point data type variants. */
8666 set_gdbarch_floatformat_for_type (gdbarch
, i386_floatformat_for_type
);
8668 /* Register numbers of various important registers. */
8669 set_gdbarch_sp_regnum (gdbarch
, I386_ESP_REGNUM
); /* %esp */
8670 set_gdbarch_pc_regnum (gdbarch
, I386_EIP_REGNUM
); /* %eip */
8671 set_gdbarch_ps_regnum (gdbarch
, I386_EFLAGS_REGNUM
); /* %eflags */
8672 set_gdbarch_fp0_regnum (gdbarch
, I386_ST0_REGNUM
); /* %st(0) */
8674 /* NOTE: kettenis/20040418: GCC does have two possible register
8675 numbering schemes on the i386: dbx and SVR4. These schemes
8676 differ in how they number %ebp, %esp, %eflags, and the
8677 floating-point registers, and are implemented by the arrays
8678 dbx_register_map[] and svr4_dbx_register_map in
8679 gcc/config/i386.c. GCC also defines a third numbering scheme in
8680 gcc/config/i386.c, which it designates as the "default" register
8681 map used in 64bit mode. This last register numbering scheme is
8682 implemented in dbx64_register_map, and is used for AMD64; see
8685 Currently, each GCC i386 target always uses the same register
8686 numbering scheme across all its supported debugging formats
8687 i.e. SDB (COFF), stabs and DWARF 2. This is because
8688 gcc/sdbout.c, gcc/dbxout.c and gcc/dwarf2out.c all use the
8689 DBX_REGISTER_NUMBER macro which is defined by each target's
8690 respective config header in a manner independent of the requested
8691 output debugging format.
8693 This does not match the arrangement below, which presumes that
8694 the SDB and stabs numbering schemes differ from the DWARF and
8695 DWARF 2 ones. The reason for this arrangement is that it is
8696 likely to get the numbering scheme for the target's
8697 default/native debug format right. For targets where GCC is the
8698 native compiler (FreeBSD, NetBSD, OpenBSD, GNU/Linux) or for
8699 targets where the native toolchain uses a different numbering
8700 scheme for a particular debug format (stabs-in-ELF on Solaris)
8701 the defaults below will have to be overridden, like
8702 i386_elf_init_abi() does. */
8704 /* Use the dbx register numbering scheme for stabs and COFF. */
8705 set_gdbarch_stab_reg_to_regnum (gdbarch
, i386_dbx_reg_to_regnum
);
8706 set_gdbarch_sdb_reg_to_regnum (gdbarch
, i386_dbx_reg_to_regnum
);
8708 /* Use the SVR4 register numbering scheme for DWARF 2. */
8709 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, i386_svr4_dwarf_reg_to_regnum
);
8711 /* We don't set gdbarch_stab_reg_to_regnum, since ECOFF doesn't seem to
8712 be in use on any of the supported i386 targets. */
8714 set_gdbarch_print_float_info (gdbarch
, i387_print_float_info
);
8716 set_gdbarch_get_longjmp_target (gdbarch
, i386_get_longjmp_target
);
8718 /* Call dummy code. */
8719 set_gdbarch_call_dummy_location (gdbarch
, ON_STACK
);
8720 set_gdbarch_push_dummy_code (gdbarch
, i386_push_dummy_code
);
8721 set_gdbarch_push_dummy_call (gdbarch
, i386_push_dummy_call
);
8722 set_gdbarch_frame_align (gdbarch
, i386_frame_align
);
8724 set_gdbarch_convert_register_p (gdbarch
, i386_convert_register_p
);
8725 set_gdbarch_register_to_value (gdbarch
, i386_register_to_value
);
8726 set_gdbarch_value_to_register (gdbarch
, i386_value_to_register
);
8728 set_gdbarch_return_value_as_value (gdbarch
, i386_return_value
);
8730 set_gdbarch_skip_prologue (gdbarch
, i386_skip_prologue
);
8732 /* Stack grows downward. */
8733 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
8735 set_gdbarch_breakpoint_kind_from_pc (gdbarch
, i386_breakpoint::kind_from_pc
);
8736 set_gdbarch_sw_breakpoint_from_kind (gdbarch
, i386_breakpoint::bp_from_kind
);
8738 set_gdbarch_decr_pc_after_break (gdbarch
, 1);
8739 set_gdbarch_max_insn_length (gdbarch
, I386_MAX_INSN_LEN
);
8741 set_gdbarch_frame_args_skip (gdbarch
, 8);
8743 set_gdbarch_print_insn (gdbarch
, i386_print_insn
);
8745 set_gdbarch_dummy_id (gdbarch
, i386_dummy_id
);
8747 set_gdbarch_unwind_pc (gdbarch
, i386_unwind_pc
);
8749 /* Add the i386 register groups. */
8750 i386_add_reggroups (gdbarch
);
8751 tdep
->register_reggroup_p
= i386_register_reggroup_p
;
8753 /* Helper for function argument information. */
8754 set_gdbarch_fetch_pointer_argument (gdbarch
, i386_fetch_pointer_argument
);
8756 /* Hook the function epilogue frame unwinder. This unwinder is
8757 appended to the list first, so that it supersedes the DWARF
8758 unwinder in function epilogues (where the DWARF unwinder
8759 currently fails). */
8760 if (info
.bfd_arch_info
->bits_per_word
== 32)
8761 frame_unwind_append_unwinder (gdbarch
, &i386_epilogue_override_frame_unwind
);
8763 /* Hook in the DWARF CFI frame unwinder. This unwinder is appended
8764 to the list before the prologue-based unwinders, so that DWARF
8765 CFI info will be used if it is available. */
8766 dwarf2_append_unwinders (gdbarch
);
8768 if (info
.bfd_arch_info
->bits_per_word
== 32)
8769 frame_unwind_append_unwinder (gdbarch
, &i386_epilogue_frame_unwind
);
8771 frame_base_set_default (gdbarch
, &i386_frame_base
);
8773 /* Pseudo registers may be changed by amd64_init_abi. */
8774 set_gdbarch_pseudo_register_read_value (gdbarch
,
8775 i386_pseudo_register_read_value
);
8776 set_gdbarch_pseudo_register_write (gdbarch
, i386_pseudo_register_write
);
8777 set_gdbarch_ax_pseudo_register_collect (gdbarch
,
8778 i386_ax_pseudo_register_collect
);
8780 set_tdesc_pseudo_register_type (gdbarch
, i386_pseudo_register_type
);
8781 set_tdesc_pseudo_register_name (gdbarch
, i386_pseudo_register_name
);
8783 /* Override the normal target description method to make the AVX
8784 upper halves anonymous. */
8785 set_gdbarch_register_name (gdbarch
, i386_register_name
);
8787 /* Even though the default ABI only includes general-purpose registers,
8788 floating-point registers and the SSE registers, we have to leave a
8789 gap for the upper AVX, (deprecated) MPX and AVX512 registers. */
8790 set_gdbarch_num_regs (gdbarch
, I386_NUM_REGS
);
8792 set_gdbarch_gnu_triplet_regexp (gdbarch
, i386_gnu_triplet_regexp
);
8794 /* Get the x86 target description from INFO. */
8795 tdesc
= info
.target_desc
;
8796 if (! tdesc_has_registers (tdesc
))
8797 tdesc
= i386_target_description (X86_XSTATE_SSE_MASK
, false);
8798 tdep
->tdesc
= tdesc
;
8800 tdep
->num_core_regs
= I386_NUM_GREGS
+ I387_NUM_REGS
;
8801 tdep
->register_names
= i386_register_names
;
8803 /* No upper YMM registers. */
8804 tdep
->ymmh_register_names
= NULL
;
8805 tdep
->ymm0h_regnum
= -1;
8807 /* No upper ZMM registers. */
8808 tdep
->zmmh_register_names
= NULL
;
8809 tdep
->zmm0h_regnum
= -1;
8811 /* No high XMM registers. */
8812 tdep
->xmm_avx512_register_names
= NULL
;
8813 tdep
->xmm16_regnum
= -1;
8815 /* No upper YMM16-31 registers. */
8816 tdep
->ymm16h_register_names
= NULL
;
8817 tdep
->ymm16h_regnum
= -1;
8819 tdep
->num_byte_regs
= 8;
8820 tdep
->num_word_regs
= 8;
8821 tdep
->num_dword_regs
= 0;
8822 tdep
->num_mmx_regs
= 8;
8823 tdep
->num_ymm_regs
= 0;
8825 /* No AVX512 registers. */
8826 tdep
->k0_regnum
= -1;
8827 tdep
->num_zmm_regs
= 0;
8828 tdep
->num_ymm_avx512_regs
= 0;
8829 tdep
->num_xmm_avx512_regs
= 0;
8831 /* No PKEYS registers */
8832 tdep
->pkru_regnum
= -1;
8833 tdep
->num_pkeys_regs
= 0;
8835 /* No segment base registers. */
8836 tdep
->fsbase_regnum
= -1;
8838 tdesc_arch_data_up tdesc_data
= tdesc_data_alloc ();
8840 set_gdbarch_relocate_instruction (gdbarch
, i386_relocate_instruction
);
8842 set_gdbarch_gen_return_address (gdbarch
, i386_gen_return_address
);
8844 set_gdbarch_insn_is_call (gdbarch
, i386_insn_is_call
);
8845 set_gdbarch_insn_is_ret (gdbarch
, i386_insn_is_ret
);
8846 set_gdbarch_insn_is_jump (gdbarch
, i386_insn_is_jump
);
8848 /* Hook in ABI-specific overrides, if they have been registered.
8849 Note: If INFO specifies a 64 bit arch, this is where we turn
8850 a 32-bit i386 into a 64-bit amd64. */
8851 info
.tdesc_data
= tdesc_data
.get ();
8852 gdbarch_init_osabi (info
, gdbarch
);
8854 if (!i386_validate_tdesc_p (tdep
, tdesc_data
.get ()))
8856 gdbarch_free (gdbarch
);
8859 tdep
->xsave_layout
= xsave_layout
;
8861 /* Wire in pseudo registers. Number of pseudo registers may be
8863 set_gdbarch_num_pseudo_regs (gdbarch
, (tdep
->num_byte_regs
8864 + tdep
->num_word_regs
8865 + tdep
->num_dword_regs
8866 + tdep
->num_mmx_regs
8867 + tdep
->num_ymm_regs
8868 + tdep
->num_ymm_avx512_regs
8869 + tdep
->num_zmm_regs
));
8871 /* Target description may be changed. */
8872 tdesc
= tdep
->tdesc
;
8874 tdesc_use_registers (gdbarch
, tdesc
, std::move (tdesc_data
));
8876 /* Override gdbarch_register_reggroup_p set in tdesc_use_registers. */
8877 set_gdbarch_register_reggroup_p (gdbarch
, tdep
->register_reggroup_p
);
8879 /* Make %al the first pseudo-register. */
8880 tdep
->al_regnum
= gdbarch_num_regs (gdbarch
);
8881 tdep
->ax_regnum
= tdep
->al_regnum
+ tdep
->num_byte_regs
;
8883 ymm0_regnum
= tdep
->ax_regnum
+ tdep
->num_word_regs
;
8884 if (tdep
->num_dword_regs
)
8886 /* Support dword pseudo-register if it hasn't been disabled. */
8887 tdep
->eax_regnum
= ymm0_regnum
;
8888 ymm0_regnum
+= tdep
->num_dword_regs
;
8891 tdep
->eax_regnum
= -1;
8893 mm0_regnum
= ymm0_regnum
;
8894 if (tdep
->num_ymm_regs
)
8896 /* Support YMM pseudo-register if it is available. */
8897 tdep
->ymm0_regnum
= ymm0_regnum
;
8898 mm0_regnum
+= tdep
->num_ymm_regs
;
8901 tdep
->ymm0_regnum
= -1;
8903 if (tdep
->num_ymm_avx512_regs
)
8905 /* Support YMM16-31 pseudo registers if available. */
8906 tdep
->ymm16_regnum
= mm0_regnum
;
8907 mm0_regnum
+= tdep
->num_ymm_avx512_regs
;
8910 tdep
->ymm16_regnum
= -1;
8912 if (tdep
->num_zmm_regs
)
8914 /* Support ZMM pseudo-register if it is available. */
8915 tdep
->zmm0_regnum
= mm0_regnum
;
8916 mm0_regnum
+= tdep
->num_zmm_regs
;
8919 tdep
->zmm0_regnum
= -1;
8921 if (tdep
->num_mmx_regs
!= 0)
8923 /* Support MMX pseudo-register if MMX hasn't been disabled. */
8924 tdep
->mm0_regnum
= mm0_regnum
;
8927 tdep
->mm0_regnum
= -1;
8929 /* Hook in the legacy prologue-based unwinders last (fallback). */
8930 if (info
.bfd_arch_info
->bits_per_word
== 32)
8932 frame_unwind_append_unwinder (gdbarch
, &i386_stack_tramp_frame_unwind
);
8933 frame_unwind_append_unwinder (gdbarch
, &i386_sigtramp_frame_unwind
);
8934 frame_unwind_append_unwinder (gdbarch
, &i386_frame_unwind
);
8937 /* If we have a register mapping, enable the generic core file
8938 support, unless it has already been enabled. */
8939 if (tdep
->gregset_reg_offset
8940 && !gdbarch_iterate_over_regset_sections_p (gdbarch
))
8941 set_gdbarch_iterate_over_regset_sections
8942 (gdbarch
, i386_iterate_over_regset_sections
);
8944 set_gdbarch_fast_tracepoint_valid_at (gdbarch
,
8945 i386_fast_tracepoint_valid_at
);
8952 /* Return the target description for a specified XSAVE feature mask. */
8954 const struct target_desc
*
8955 i386_target_description (uint64_t xcr0
, bool segments
)
8957 static target_desc
*i386_tdescs \
8958 [2/*SSE*/][2/*AVX*/][2/*AVX512*/][2/*PKRU*/][2/*segments*/] = {};
8959 target_desc
**tdesc
;
8961 tdesc
= &i386_tdescs
[(xcr0
& X86_XSTATE_SSE
) ? 1 : 0]
8962 [(xcr0
& X86_XSTATE_AVX
) ? 1 : 0]
8963 [(xcr0
& X86_XSTATE_AVX512
) ? 1 : 0]
8964 [(xcr0
& X86_XSTATE_PKRU
) ? 1 : 0]
8968 *tdesc
= i386_create_target_description (xcr0
, false, segments
);
8973 void _initialize_i386_tdep ();
8975 _initialize_i386_tdep ()
8977 gdbarch_register (bfd_arch_i386
, i386_gdbarch_init
);
8979 /* Add the variable that controls the disassembly flavor. */
8980 add_setshow_enum_cmd ("disassembly-flavor", no_class
, valid_flavors
,
8981 &disassembly_flavor
, _("\
8982 Set the disassembly flavor."), _("\
8983 Show the disassembly flavor."), _("\
8984 The valid values are \"att\" and \"intel\", and the default value is \"att\"."),
8986 NULL
, /* FIXME: i18n: */
8987 &setlist
, &showlist
);
8989 /* Add the variable that controls the convention for returning
8991 add_setshow_enum_cmd ("struct-convention", no_class
, valid_conventions
,
8992 &struct_convention
, _("\
8993 Set the convention for returning small structs."), _("\
8994 Show the convention for returning small structs."), _("\
8995 Valid values are \"default\", \"pcc\" and \"reg\", and the default value\n\
8998 NULL
, /* FIXME: i18n: */
8999 &setlist
, &showlist
);
9001 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_SVR4
,
9002 i386_svr4_init_abi
);
9004 /* Initialize the i386-specific register groups. */
9005 i386_init_reggroups ();
9007 /* Tell remote stub that we support XML target description. */
9008 register_remote_support_xml ("i386");