1 /* Intel 386 target-dependent stuff.
3 Copyright (C) 1988-2014 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/>. */
21 #include "opcode/i386.h"
22 #include "arch-utils.h"
24 #include "dummy-frame.h"
25 #include "dwarf2-frame.h"
28 #include "frame-base.h"
29 #include "frame-unwind.h"
38 #include "reggroups.h"
47 #include "exceptions.h"
48 #include "gdb_assert.h"
51 #include "i386-tdep.h"
52 #include "i387-tdep.h"
53 #include "i386-xstate.h"
56 #include "record-full.h"
59 #include "features/i386/i386.c"
60 #include "features/i386/i386-avx.c"
61 #include "features/i386/i386-mpx.c"
62 #include "features/i386/i386-avx512.c"
63 #include "features/i386/i386-mmx.c"
68 #include "stap-probe.h"
69 #include "user-regs.h"
70 #include "cli/cli-utils.h"
71 #include "expression.h"
72 #include "parser-defs.h"
77 static const char *i386_register_names[] =
79 "eax", "ecx", "edx", "ebx",
80 "esp", "ebp", "esi", "edi",
81 "eip", "eflags", "cs", "ss",
82 "ds", "es", "fs", "gs",
83 "st0", "st1", "st2", "st3",
84 "st4", "st5", "st6", "st7",
85 "fctrl", "fstat", "ftag", "fiseg",
86 "fioff", "foseg", "fooff", "fop",
87 "xmm0", "xmm1", "xmm2", "xmm3",
88 "xmm4", "xmm5", "xmm6", "xmm7",
92 static const char *i386_zmm_names[] =
94 "zmm0", "zmm1", "zmm2", "zmm3",
95 "zmm4", "zmm5", "zmm6", "zmm7"
98 static const char *i386_zmmh_names[] =
100 "zmm0h", "zmm1h", "zmm2h", "zmm3h",
101 "zmm4h", "zmm5h", "zmm6h", "zmm7h"
104 static const char *i386_k_names[] =
106 "k0", "k1", "k2", "k3",
107 "k4", "k5", "k6", "k7"
110 static const char *i386_ymm_names[] =
112 "ymm0", "ymm1", "ymm2", "ymm3",
113 "ymm4", "ymm5", "ymm6", "ymm7",
116 static const char *i386_ymmh_names[] =
118 "ymm0h", "ymm1h", "ymm2h", "ymm3h",
119 "ymm4h", "ymm5h", "ymm6h", "ymm7h",
122 static const char *i386_mpx_names[] =
124 "bnd0raw", "bnd1raw", "bnd2raw", "bnd3raw", "bndcfgu", "bndstatus"
127 /* Register names for MPX pseudo-registers. */
129 static const char *i386_bnd_names[] =
131 "bnd0", "bnd1", "bnd2", "bnd3"
134 /* Register names for MMX pseudo-registers. */
136 static const char *i386_mmx_names[] =
138 "mm0", "mm1", "mm2", "mm3",
139 "mm4", "mm5", "mm6", "mm7"
142 /* Register names for byte pseudo-registers. */
144 static const char *i386_byte_names[] =
146 "al", "cl", "dl", "bl",
147 "ah", "ch", "dh", "bh"
150 /* Register names for word pseudo-registers. */
152 static const char *i386_word_names[] =
154 "ax", "cx", "dx", "bx",
158 /* Constant used for reading/writing pseudo registers. In 64-bit mode, we have
159 16 lower ZMM regs that extend corresponding xmm/ymm registers. In addition,
160 we have 16 upper ZMM regs that have to be handled differently. */
162 const int num_lower_zmm_regs = 16;
167 i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
169 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
170 int mm0_regnum = tdep->mm0_regnum;
175 regnum -= mm0_regnum;
176 return regnum >= 0 && regnum < tdep->num_mmx_regs;
182 i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
184 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
186 regnum -= tdep->al_regnum;
187 return regnum >= 0 && regnum < tdep->num_byte_regs;
193 i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
195 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
197 regnum -= tdep->ax_regnum;
198 return regnum >= 0 && regnum < tdep->num_word_regs;
201 /* Dword register? */
204 i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
206 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
207 int eax_regnum = tdep->eax_regnum;
212 regnum -= eax_regnum;
213 return regnum >= 0 && regnum < tdep->num_dword_regs;
216 /* AVX512 register? */
219 i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
221 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
222 int zmm0h_regnum = tdep->zmm0h_regnum;
224 if (zmm0h_regnum < 0)
227 regnum -= zmm0h_regnum;
228 return regnum >= 0 && regnum < tdep->num_zmm_regs;
232 i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
234 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
235 int zmm0_regnum = tdep->zmm0_regnum;
240 regnum -= zmm0_regnum;
241 return regnum >= 0 && regnum < tdep->num_zmm_regs;
245 i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
247 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
248 int k0_regnum = tdep->k0_regnum;
254 return regnum >= 0 && regnum < I387_NUM_K_REGS;
258 i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
260 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
261 int ymm0h_regnum = tdep->ymm0h_regnum;
263 if (ymm0h_regnum < 0)
266 regnum -= ymm0h_regnum;
267 return regnum >= 0 && regnum < tdep->num_ymm_regs;
273 i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
275 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
276 int ymm0_regnum = tdep->ymm0_regnum;
281 regnum -= ymm0_regnum;
282 return regnum >= 0 && regnum < tdep->num_ymm_regs;
286 i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
288 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
289 int ymm16h_regnum = tdep->ymm16h_regnum;
291 if (ymm16h_regnum < 0)
294 regnum -= ymm16h_regnum;
295 return regnum >= 0 && regnum < tdep->num_ymm_avx512_regs;
299 i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
301 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
302 int ymm16_regnum = tdep->ymm16_regnum;
304 if (ymm16_regnum < 0)
307 regnum -= ymm16_regnum;
308 return regnum >= 0 && regnum < tdep->num_ymm_avx512_regs;
314 i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
316 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
317 int bnd0_regnum = tdep->bnd0_regnum;
322 regnum -= bnd0_regnum;
323 return regnum >= 0 && regnum < I387_NUM_BND_REGS;
329 i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
331 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
332 int num_xmm_regs = I387_NUM_XMM_REGS (tdep);
334 if (num_xmm_regs == 0)
337 regnum -= I387_XMM0_REGNUM (tdep);
338 return regnum >= 0 && regnum < num_xmm_regs;
341 /* XMM_512 register? */
344 i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
346 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
347 int num_xmm_avx512_regs = I387_NUM_XMM_AVX512_REGS (tdep);
349 if (num_xmm_avx512_regs == 0)
352 regnum -= I387_XMM16_REGNUM (tdep);
353 return regnum >= 0 && regnum < num_xmm_avx512_regs;
357 i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
359 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
361 if (I387_NUM_XMM_REGS (tdep) == 0)
364 return (regnum == I387_MXCSR_REGNUM (tdep));
370 i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
372 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
374 if (I387_ST0_REGNUM (tdep) < 0)
377 return (I387_ST0_REGNUM (tdep) <= regnum
378 && regnum < I387_FCTRL_REGNUM (tdep));
382 i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
384 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
386 if (I387_ST0_REGNUM (tdep) < 0)
389 return (I387_FCTRL_REGNUM (tdep) <= regnum
390 && regnum < I387_XMM0_REGNUM (tdep));
393 /* BNDr (raw) register? */
396 i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
398 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
400 if (I387_BND0R_REGNUM (tdep) < 0)
403 regnum -= tdep->bnd0r_regnum;
404 return regnum >= 0 && regnum < I387_NUM_BND_REGS;
407 /* BND control register? */
410 i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
412 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
414 if (I387_BNDCFGU_REGNUM (tdep) < 0)
417 regnum -= I387_BNDCFGU_REGNUM (tdep);
418 return regnum >= 0 && regnum < I387_NUM_MPX_CTRL_REGS;
421 /* Return the name of register REGNUM, or the empty string if it is
422 an anonymous register. */
425 i386_register_name (struct gdbarch *gdbarch, int regnum)
427 /* Hide the upper YMM registers. */
428 if (i386_ymmh_regnum_p (gdbarch, regnum))
431 /* Hide the upper YMM16-31 registers. */
432 if (i386_ymmh_avx512_regnum_p (gdbarch, regnum))
435 /* Hide the upper ZMM registers. */
436 if (i386_zmmh_regnum_p (gdbarch, regnum))
439 return tdesc_register_name (gdbarch, regnum);
442 /* Return the name of register REGNUM. */
445 i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
447 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
448 if (i386_bnd_regnum_p (gdbarch, regnum))
449 return i386_bnd_names[regnum - tdep->bnd0_regnum];
450 if (i386_mmx_regnum_p (gdbarch, regnum))
451 return i386_mmx_names[regnum - I387_MM0_REGNUM (tdep)];
452 else if (i386_ymm_regnum_p (gdbarch, regnum))
453 return i386_ymm_names[regnum - tdep->ymm0_regnum];
454 else if (i386_zmm_regnum_p (gdbarch, regnum))
455 return i386_zmm_names[regnum - tdep->zmm0_regnum];
456 else if (i386_byte_regnum_p (gdbarch, regnum))
457 return i386_byte_names[regnum - tdep->al_regnum];
458 else if (i386_word_regnum_p (gdbarch, regnum))
459 return i386_word_names[regnum - tdep->ax_regnum];
461 internal_error (__FILE__, __LINE__, _("invalid regnum"));
464 /* Convert a dbx register number REG to the appropriate register
465 number used by GDB. */
468 i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
470 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
472 /* This implements what GCC calls the "default" register map
473 (dbx_register_map[]). */
475 if (reg >= 0 && reg <= 7)
477 /* General-purpose registers. The debug info calls %ebp
478 register 4, and %esp register 5. */
485 else if (reg >= 12 && reg <= 19)
487 /* Floating-point registers. */
488 return reg - 12 + I387_ST0_REGNUM (tdep);
490 else if (reg >= 21 && reg <= 28)
493 int ymm0_regnum = tdep->ymm0_regnum;
496 && i386_xmm_regnum_p (gdbarch, reg))
497 return reg - 21 + ymm0_regnum;
499 return reg - 21 + I387_XMM0_REGNUM (tdep);
501 else if (reg >= 29 && reg <= 36)
504 return reg - 29 + I387_MM0_REGNUM (tdep);
507 /* This will hopefully provoke a warning. */
508 return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
511 /* Convert SVR4 register number REG to the appropriate register number
515 i386_svr4_reg_to_regnum (struct gdbarch *gdbarch, int reg)
517 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
519 /* This implements the GCC register map that tries to be compatible
520 with the SVR4 C compiler for DWARF (svr4_dbx_register_map[]). */
522 /* The SVR4 register numbering includes %eip and %eflags, and
523 numbers the floating point registers differently. */
524 if (reg >= 0 && reg <= 9)
526 /* General-purpose registers. */
529 else if (reg >= 11 && reg <= 18)
531 /* Floating-point registers. */
532 return reg - 11 + I387_ST0_REGNUM (tdep);
534 else if (reg >= 21 && reg <= 36)
536 /* The SSE and MMX registers have the same numbers as with dbx. */
537 return i386_dbx_reg_to_regnum (gdbarch, reg);
542 case 37: return I387_FCTRL_REGNUM (tdep);
543 case 38: return I387_FSTAT_REGNUM (tdep);
544 case 39: return I387_MXCSR_REGNUM (tdep);
545 case 40: return I386_ES_REGNUM;
546 case 41: return I386_CS_REGNUM;
547 case 42: return I386_SS_REGNUM;
548 case 43: return I386_DS_REGNUM;
549 case 44: return I386_FS_REGNUM;
550 case 45: return I386_GS_REGNUM;
553 /* This will hopefully provoke a warning. */
554 return gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
559 /* This is the variable that is set with "set disassembly-flavor", and
560 its legitimate values. */
561 static const char att_flavor[] = "att";
562 static const char intel_flavor[] = "intel";
563 static const char *const valid_flavors[] =
569 static const char *disassembly_flavor = att_flavor;
572 /* Use the program counter to determine the contents and size of a
573 breakpoint instruction. Return a pointer to a string of bytes that
574 encode a breakpoint instruction, store the length of the string in
575 *LEN and optionally adjust *PC to point to the correct memory
576 location for inserting the breakpoint.
578 On the i386 we have a single breakpoint that fits in a single byte
579 and can be inserted anywhere.
581 This function is 64-bit safe. */
583 static const gdb_byte *
584 i386_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len)
586 static gdb_byte break_insn[] = { 0xcc }; /* int 3 */
588 *len = sizeof (break_insn);
592 /* Displaced instruction handling. */
594 /* Skip the legacy instruction prefixes in INSN.
595 Not all prefixes are valid for any particular insn
596 but we needn't care, the insn will fault if it's invalid.
597 The result is a pointer to the first opcode byte,
598 or NULL if we run off the end of the buffer. */
601 i386_skip_prefixes (gdb_byte *insn, size_t max_len)
603 gdb_byte *end = insn + max_len;
609 case DATA_PREFIX_OPCODE:
610 case ADDR_PREFIX_OPCODE:
611 case CS_PREFIX_OPCODE:
612 case DS_PREFIX_OPCODE:
613 case ES_PREFIX_OPCODE:
614 case FS_PREFIX_OPCODE:
615 case GS_PREFIX_OPCODE:
616 case SS_PREFIX_OPCODE:
617 case LOCK_PREFIX_OPCODE:
618 case REPE_PREFIX_OPCODE:
619 case REPNE_PREFIX_OPCODE:
631 i386_absolute_jmp_p (const gdb_byte *insn)
633 /* jmp far (absolute address in operand). */
639 /* jump near, absolute indirect (/4). */
640 if ((insn[1] & 0x38) == 0x20)
643 /* jump far, absolute indirect (/5). */
644 if ((insn[1] & 0x38) == 0x28)
651 /* Return non-zero if INSN is a jump, zero otherwise. */
654 i386_jmp_p (const gdb_byte *insn)
656 /* jump short, relative. */
660 /* jump near, relative. */
664 return i386_absolute_jmp_p (insn);
668 i386_absolute_call_p (const gdb_byte *insn)
670 /* call far, absolute. */
676 /* Call near, absolute indirect (/2). */
677 if ((insn[1] & 0x38) == 0x10)
680 /* Call far, absolute indirect (/3). */
681 if ((insn[1] & 0x38) == 0x18)
689 i386_ret_p (const gdb_byte *insn)
693 case 0xc2: /* ret near, pop N bytes. */
694 case 0xc3: /* ret near */
695 case 0xca: /* ret far, pop N bytes. */
696 case 0xcb: /* ret far */
697 case 0xcf: /* iret */
706 i386_call_p (const gdb_byte *insn)
708 if (i386_absolute_call_p (insn))
711 /* call near, relative. */
718 /* Return non-zero if INSN is a system call, and set *LENGTHP to its
719 length in bytes. Otherwise, return zero. */
722 i386_syscall_p (const gdb_byte *insn, int *lengthp)
724 /* Is it 'int $0x80'? */
725 if ((insn[0] == 0xcd && insn[1] == 0x80)
726 /* Or is it 'sysenter'? */
727 || (insn[0] == 0x0f && insn[1] == 0x34)
728 /* Or is it 'syscall'? */
729 || (insn[0] == 0x0f && insn[1] == 0x05))
738 /* The gdbarch insn_is_call method. */
741 i386_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
743 gdb_byte buf[I386_MAX_INSN_LEN], *insn;
745 read_code (addr, buf, I386_MAX_INSN_LEN);
746 insn = i386_skip_prefixes (buf, I386_MAX_INSN_LEN);
748 return i386_call_p (insn);
751 /* The gdbarch insn_is_ret method. */
754 i386_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
756 gdb_byte buf[I386_MAX_INSN_LEN], *insn;
758 read_code (addr, buf, I386_MAX_INSN_LEN);
759 insn = i386_skip_prefixes (buf, I386_MAX_INSN_LEN);
761 return i386_ret_p (insn);
764 /* The gdbarch insn_is_jump method. */
767 i386_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
769 gdb_byte buf[I386_MAX_INSN_LEN], *insn;
771 read_code (addr, buf, I386_MAX_INSN_LEN);
772 insn = i386_skip_prefixes (buf, I386_MAX_INSN_LEN);
774 return i386_jmp_p (insn);
777 /* Some kernels may run one past a syscall insn, so we have to cope.
778 Otherwise this is just simple_displaced_step_copy_insn. */
780 struct displaced_step_closure *
781 i386_displaced_step_copy_insn (struct gdbarch *gdbarch,
782 CORE_ADDR from, CORE_ADDR to,
783 struct regcache *regs)
785 size_t len = gdbarch_max_insn_length (gdbarch);
786 gdb_byte *buf = xmalloc (len);
788 read_memory (from, buf, len);
790 /* GDB may get control back after the insn after the syscall.
791 Presumably this is a kernel bug.
792 If this is a syscall, make sure there's a nop afterwards. */
797 insn = i386_skip_prefixes (buf, len);
798 if (insn != NULL && i386_syscall_p (insn, &syscall_length))
799 insn[syscall_length] = NOP_OPCODE;
802 write_memory (to, buf, len);
806 fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ",
807 paddress (gdbarch, from), paddress (gdbarch, to));
808 displaced_step_dump_bytes (gdb_stdlog, buf, len);
811 return (struct displaced_step_closure *) buf;
814 /* Fix up the state of registers and memory after having single-stepped
815 a displaced instruction. */
818 i386_displaced_step_fixup (struct gdbarch *gdbarch,
819 struct displaced_step_closure *closure,
820 CORE_ADDR from, CORE_ADDR to,
821 struct regcache *regs)
823 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
825 /* The offset we applied to the instruction's address.
826 This could well be negative (when viewed as a signed 32-bit
827 value), but ULONGEST won't reflect that, so take care when
829 ULONGEST insn_offset = to - from;
831 /* Since we use simple_displaced_step_copy_insn, our closure is a
832 copy of the instruction. */
833 gdb_byte *insn = (gdb_byte *) closure;
834 /* The start of the insn, needed in case we see some prefixes. */
835 gdb_byte *insn_start = insn;
838 fprintf_unfiltered (gdb_stdlog,
839 "displaced: fixup (%s, %s), "
840 "insn = 0x%02x 0x%02x ...\n",
841 paddress (gdbarch, from), paddress (gdbarch, to),
844 /* The list of issues to contend with here is taken from
845 resume_execution in arch/i386/kernel/kprobes.c, Linux 2.6.20.
846 Yay for Free Software! */
848 /* Relocate the %eip, if necessary. */
850 /* The instruction recognizers we use assume any leading prefixes
851 have been skipped. */
853 /* This is the size of the buffer in closure. */
854 size_t max_insn_len = gdbarch_max_insn_length (gdbarch);
855 gdb_byte *opcode = i386_skip_prefixes (insn, max_insn_len);
856 /* If there are too many prefixes, just ignore the insn.
857 It will fault when run. */
862 /* Except in the case of absolute or indirect jump or call
863 instructions, or a return instruction, the new eip is relative to
864 the displaced instruction; make it relative. Well, signal
865 handler returns don't need relocation either, but we use the
866 value of %eip to recognize those; see below. */
867 if (! i386_absolute_jmp_p (insn)
868 && ! i386_absolute_call_p (insn)
869 && ! i386_ret_p (insn))
874 regcache_cooked_read_unsigned (regs, I386_EIP_REGNUM, &orig_eip);
876 /* A signal trampoline system call changes the %eip, resuming
877 execution of the main program after the signal handler has
878 returned. That makes them like 'return' instructions; we
879 shouldn't relocate %eip.
881 But most system calls don't, and we do need to relocate %eip.
883 Our heuristic for distinguishing these cases: if stepping
884 over the system call instruction left control directly after
885 the instruction, the we relocate --- control almost certainly
886 doesn't belong in the displaced copy. Otherwise, we assume
887 the instruction has put control where it belongs, and leave
888 it unrelocated. Goodness help us if there are PC-relative
890 if (i386_syscall_p (insn, &insn_len)
891 && orig_eip != to + (insn - insn_start) + insn_len
892 /* GDB can get control back after the insn after the syscall.
893 Presumably this is a kernel bug.
894 i386_displaced_step_copy_insn ensures its a nop,
895 we add one to the length for it. */
896 && orig_eip != to + (insn - insn_start) + insn_len + 1)
899 fprintf_unfiltered (gdb_stdlog,
900 "displaced: syscall changed %%eip; "
905 ULONGEST eip = (orig_eip - insn_offset) & 0xffffffffUL;
907 /* If we just stepped over a breakpoint insn, we don't backup
908 the pc on purpose; this is to match behaviour without
911 regcache_cooked_write_unsigned (regs, I386_EIP_REGNUM, eip);
914 fprintf_unfiltered (gdb_stdlog,
916 "relocated %%eip from %s to %s\n",
917 paddress (gdbarch, orig_eip),
918 paddress (gdbarch, eip));
922 /* If the instruction was PUSHFL, then the TF bit will be set in the
923 pushed value, and should be cleared. We'll leave this for later,
924 since GDB already messes up the TF flag when stepping over a
927 /* If the instruction was a call, the return address now atop the
928 stack is the address following the copied instruction. We need
929 to make it the address following the original instruction. */
930 if (i386_call_p (insn))
934 const ULONGEST retaddr_len = 4;
936 regcache_cooked_read_unsigned (regs, I386_ESP_REGNUM, &esp);
937 retaddr = read_memory_unsigned_integer (esp, retaddr_len, byte_order);
938 retaddr = (retaddr - insn_offset) & 0xffffffffUL;
939 write_memory_unsigned_integer (esp, retaddr_len, byte_order, retaddr);
942 fprintf_unfiltered (gdb_stdlog,
943 "displaced: relocated return addr at %s to %s\n",
944 paddress (gdbarch, esp),
945 paddress (gdbarch, retaddr));
950 append_insns (CORE_ADDR *to, ULONGEST len, const gdb_byte *buf)
952 target_write_memory (*to, buf, len);
957 i386_relocate_instruction (struct gdbarch *gdbarch,
958 CORE_ADDR *to, CORE_ADDR oldloc)
960 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
961 gdb_byte buf[I386_MAX_INSN_LEN];
962 int offset = 0, rel32, newrel;
964 gdb_byte *insn = buf;
966 read_memory (oldloc, buf, I386_MAX_INSN_LEN);
968 insn_length = gdb_buffered_insn_length (gdbarch, insn,
969 I386_MAX_INSN_LEN, oldloc);
971 /* Get past the prefixes. */
972 insn = i386_skip_prefixes (insn, I386_MAX_INSN_LEN);
974 /* Adjust calls with 32-bit relative addresses as push/jump, with
975 the address pushed being the location where the original call in
976 the user program would return to. */
979 gdb_byte push_buf[16];
980 unsigned int ret_addr;
982 /* Where "ret" in the original code will return to. */
983 ret_addr = oldloc + insn_length;
984 push_buf[0] = 0x68; /* pushq $... */
985 store_unsigned_integer (&push_buf[1], 4, byte_order, ret_addr);
987 append_insns (to, 5, push_buf);
989 /* Convert the relative call to a relative jump. */
992 /* Adjust the destination offset. */
993 rel32 = extract_signed_integer (insn + 1, 4, byte_order);
994 newrel = (oldloc - *to) + rel32;
995 store_signed_integer (insn + 1, 4, byte_order, newrel);
998 fprintf_unfiltered (gdb_stdlog,
999 "Adjusted insn rel32=%s at %s to"
1000 " rel32=%s at %s\n",
1001 hex_string (rel32), paddress (gdbarch, oldloc),
1002 hex_string (newrel), paddress (gdbarch, *to));
1004 /* Write the adjusted jump into its displaced location. */
1005 append_insns (to, 5, insn);
1009 /* Adjust jumps with 32-bit relative addresses. Calls are already
1011 if (insn[0] == 0xe9)
1013 /* Adjust conditional jumps. */
1014 else if (insn[0] == 0x0f && (insn[1] & 0xf0) == 0x80)
1019 rel32 = extract_signed_integer (insn + offset, 4, byte_order);
1020 newrel = (oldloc - *to) + rel32;
1021 store_signed_integer (insn + offset, 4, byte_order, newrel);
1022 if (debug_displaced)
1023 fprintf_unfiltered (gdb_stdlog,
1024 "Adjusted insn rel32=%s at %s to"
1025 " rel32=%s at %s\n",
1026 hex_string (rel32), paddress (gdbarch, oldloc),
1027 hex_string (newrel), paddress (gdbarch, *to));
1030 /* Write the adjusted instructions into their displaced
1032 append_insns (to, insn_length, buf);
1036 #ifdef I386_REGNO_TO_SYMMETRY
1037 #error "The Sequent Symmetry is no longer supported."
1040 /* According to the System V ABI, the registers %ebp, %ebx, %edi, %esi
1041 and %esp "belong" to the calling function. Therefore these
1042 registers should be saved if they're going to be modified. */
1044 /* The maximum number of saved registers. This should include all
1045 registers mentioned above, and %eip. */
1046 #define I386_NUM_SAVED_REGS I386_NUM_GREGS
1048 struct i386_frame_cache
1056 /* Saved registers. */
1057 CORE_ADDR saved_regs[I386_NUM_SAVED_REGS];
1062 /* Stack space reserved for local variables. */
1066 /* Allocate and initialize a frame cache. */
1068 static struct i386_frame_cache *
1069 i386_alloc_frame_cache (void)
1071 struct i386_frame_cache *cache;
1074 cache = FRAME_OBSTACK_ZALLOC (struct i386_frame_cache);
1079 cache->sp_offset = -4;
1082 /* Saved registers. We initialize these to -1 since zero is a valid
1083 offset (that's where %ebp is supposed to be stored). */
1084 for (i = 0; i < I386_NUM_SAVED_REGS; i++)
1085 cache->saved_regs[i] = -1;
1086 cache->saved_sp = 0;
1087 cache->saved_sp_reg = -1;
1088 cache->pc_in_eax = 0;
1090 /* Frameless until proven otherwise. */
1096 /* If the instruction at PC is a jump, return the address of its
1097 target. Otherwise, return PC. */
1100 i386_follow_jump (struct gdbarch *gdbarch, CORE_ADDR pc)
1102 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1107 if (target_read_code (pc, &op, 1))
1114 op = read_code_unsigned_integer (pc + 1, 1, byte_order);
1120 /* Relative jump: if data16 == 0, disp32, else disp16. */
1123 delta = read_memory_integer (pc + 2, 2, byte_order);
1125 /* Include the size of the jmp instruction (including the
1131 delta = read_memory_integer (pc + 1, 4, byte_order);
1133 /* Include the size of the jmp instruction. */
1138 /* Relative jump, disp8 (ignore data16). */
1139 delta = read_memory_integer (pc + data16 + 1, 1, byte_order);
1141 delta += data16 + 2;
1148 /* Check whether PC points at a prologue for a function returning a
1149 structure or union. If so, it updates CACHE and returns the
1150 address of the first instruction after the code sequence that
1151 removes the "hidden" argument from the stack or CURRENT_PC,
1152 whichever is smaller. Otherwise, return PC. */
1155 i386_analyze_struct_return (CORE_ADDR pc, CORE_ADDR current_pc,
1156 struct i386_frame_cache *cache)
1158 /* Functions that return a structure or union start with:
1161 xchgl %eax, (%esp) 0x87 0x04 0x24
1162 or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
1164 (the System V compiler puts out the second `xchg' instruction,
1165 and the assembler doesn't try to optimize it, so the 'sib' form
1166 gets generated). This sequence is used to get the address of the
1167 return buffer for a function that returns a structure. */
1168 static gdb_byte proto1[3] = { 0x87, 0x04, 0x24 };
1169 static gdb_byte proto2[4] = { 0x87, 0x44, 0x24, 0x00 };
1173 if (current_pc <= pc)
1176 if (target_read_code (pc, &op, 1))
1179 if (op != 0x58) /* popl %eax */
1182 if (target_read_code (pc + 1, buf, 4))
1185 if (memcmp (buf, proto1, 3) != 0 && memcmp (buf, proto2, 4) != 0)
1188 if (current_pc == pc)
1190 cache->sp_offset += 4;
1194 if (current_pc == pc + 1)
1196 cache->pc_in_eax = 1;
1200 if (buf[1] == proto1[1])
1207 i386_skip_probe (CORE_ADDR pc)
1209 /* A function may start with
1223 if (target_read_code (pc, &op, 1))
1226 if (op == 0x68 || op == 0x6a)
1230 /* Skip past the `pushl' instruction; it has either a one-byte or a
1231 four-byte operand, depending on the opcode. */
1237 /* Read the following 8 bytes, which should be `call _probe' (6
1238 bytes) followed by `addl $4,%esp' (2 bytes). */
1239 read_memory (pc + delta, buf, sizeof (buf));
1240 if (buf[0] == 0xe8 && buf[6] == 0xc4 && buf[7] == 0x4)
1241 pc += delta + sizeof (buf);
1247 /* GCC 4.1 and later, can put code in the prologue to realign the
1248 stack pointer. Check whether PC points to such code, and update
1249 CACHE accordingly. Return the first instruction after the code
1250 sequence or CURRENT_PC, whichever is smaller. If we don't
1251 recognize the code, return PC. */
1254 i386_analyze_stack_align (CORE_ADDR pc, CORE_ADDR current_pc,
1255 struct i386_frame_cache *cache)
1257 /* There are 2 code sequences to re-align stack before the frame
1260 1. Use a caller-saved saved register:
1266 2. Use a callee-saved saved register:
1273 "andl $-XXX, %esp" can be either 3 bytes or 6 bytes:
1275 0x83 0xe4 0xf0 andl $-16, %esp
1276 0x81 0xe4 0x00 0xff 0xff 0xff andl $-256, %esp
1281 int offset, offset_and;
1282 static int regnums[8] = {
1283 I386_EAX_REGNUM, /* %eax */
1284 I386_ECX_REGNUM, /* %ecx */
1285 I386_EDX_REGNUM, /* %edx */
1286 I386_EBX_REGNUM, /* %ebx */
1287 I386_ESP_REGNUM, /* %esp */
1288 I386_EBP_REGNUM, /* %ebp */
1289 I386_ESI_REGNUM, /* %esi */
1290 I386_EDI_REGNUM /* %edi */
1293 if (target_read_code (pc, buf, sizeof buf))
1296 /* Check caller-saved saved register. The first instruction has
1297 to be "leal 4(%esp), %reg". */
1298 if (buf[0] == 0x8d && buf[2] == 0x24 && buf[3] == 0x4)
1300 /* MOD must be binary 10 and R/M must be binary 100. */
1301 if ((buf[1] & 0xc7) != 0x44)
1304 /* REG has register number. */
1305 reg = (buf[1] >> 3) & 7;
1310 /* Check callee-saved saved register. The first instruction
1311 has to be "pushl %reg". */
1312 if ((buf[0] & 0xf8) != 0x50)
1318 /* The next instruction has to be "leal 8(%esp), %reg". */
1319 if (buf[1] != 0x8d || buf[3] != 0x24 || buf[4] != 0x8)
1322 /* MOD must be binary 10 and R/M must be binary 100. */
1323 if ((buf[2] & 0xc7) != 0x44)
1326 /* REG has register number. Registers in pushl and leal have to
1328 if (reg != ((buf[2] >> 3) & 7))
1334 /* Rigister can't be %esp nor %ebp. */
1335 if (reg == 4 || reg == 5)
1338 /* The next instruction has to be "andl $-XXX, %esp". */
1339 if (buf[offset + 1] != 0xe4
1340 || (buf[offset] != 0x81 && buf[offset] != 0x83))
1343 offset_and = offset;
1344 offset += buf[offset] == 0x81 ? 6 : 3;
1346 /* The next instruction has to be "pushl -4(%reg)". 8bit -4 is
1347 0xfc. REG must be binary 110 and MOD must be binary 01. */
1348 if (buf[offset] != 0xff
1349 || buf[offset + 2] != 0xfc
1350 || (buf[offset + 1] & 0xf8) != 0x70)
1353 /* R/M has register. Registers in leal and pushl have to be the
1355 if (reg != (buf[offset + 1] & 7))
1358 if (current_pc > pc + offset_and)
1359 cache->saved_sp_reg = regnums[reg];
1361 return min (pc + offset + 3, current_pc);
1364 /* Maximum instruction length we need to handle. */
1365 #define I386_MAX_MATCHED_INSN_LEN 6
1367 /* Instruction description. */
1371 gdb_byte insn[I386_MAX_MATCHED_INSN_LEN];
1372 gdb_byte mask[I386_MAX_MATCHED_INSN_LEN];
1375 /* Return whether instruction at PC matches PATTERN. */
1378 i386_match_pattern (CORE_ADDR pc, struct i386_insn pattern)
1382 if (target_read_code (pc, &op, 1))
1385 if ((op & pattern.mask[0]) == pattern.insn[0])
1387 gdb_byte buf[I386_MAX_MATCHED_INSN_LEN - 1];
1388 int insn_matched = 1;
1391 gdb_assert (pattern.len > 1);
1392 gdb_assert (pattern.len <= I386_MAX_MATCHED_INSN_LEN);
1394 if (target_read_code (pc + 1, buf, pattern.len - 1))
1397 for (i = 1; i < pattern.len; i++)
1399 if ((buf[i - 1] & pattern.mask[i]) != pattern.insn[i])
1402 return insn_matched;
1407 /* Search for the instruction at PC in the list INSN_PATTERNS. Return
1408 the first instruction description that matches. Otherwise, return
1411 static struct i386_insn *
1412 i386_match_insn (CORE_ADDR pc, struct i386_insn *insn_patterns)
1414 struct i386_insn *pattern;
1416 for (pattern = insn_patterns; pattern->len > 0; pattern++)
1418 if (i386_match_pattern (pc, *pattern))
1425 /* Return whether PC points inside a sequence of instructions that
1426 matches INSN_PATTERNS. */
1429 i386_match_insn_block (CORE_ADDR pc, struct i386_insn *insn_patterns)
1431 CORE_ADDR current_pc;
1433 struct i386_insn *insn;
1435 insn = i386_match_insn (pc, insn_patterns);
1440 ix = insn - insn_patterns;
1441 for (i = ix - 1; i >= 0; i--)
1443 current_pc -= insn_patterns[i].len;
1445 if (!i386_match_pattern (current_pc, insn_patterns[i]))
1449 current_pc = pc + insn->len;
1450 for (insn = insn_patterns + ix + 1; insn->len > 0; insn++)
1452 if (!i386_match_pattern (current_pc, *insn))
1455 current_pc += insn->len;
1461 /* Some special instructions that might be migrated by GCC into the
1462 part of the prologue that sets up the new stack frame. Because the
1463 stack frame hasn't been setup yet, no registers have been saved
1464 yet, and only the scratch registers %eax, %ecx and %edx can be
1467 struct i386_insn i386_frame_setup_skip_insns[] =
1469 /* Check for `movb imm8, r' and `movl imm32, r'.
1471 ??? Should we handle 16-bit operand-sizes here? */
1473 /* `movb imm8, %al' and `movb imm8, %ah' */
1474 /* `movb imm8, %cl' and `movb imm8, %ch' */
1475 { 2, { 0xb0, 0x00 }, { 0xfa, 0x00 } },
1476 /* `movb imm8, %dl' and `movb imm8, %dh' */
1477 { 2, { 0xb2, 0x00 }, { 0xfb, 0x00 } },
1478 /* `movl imm32, %eax' and `movl imm32, %ecx' */
1479 { 5, { 0xb8 }, { 0xfe } },
1480 /* `movl imm32, %edx' */
1481 { 5, { 0xba }, { 0xff } },
1483 /* Check for `mov imm32, r32'. Note that there is an alternative
1484 encoding for `mov m32, %eax'.
1486 ??? Should we handle SIB adressing here?
1487 ??? Should we handle 16-bit operand-sizes here? */
1489 /* `movl m32, %eax' */
1490 { 5, { 0xa1 }, { 0xff } },
1491 /* `movl m32, %eax' and `mov; m32, %ecx' */
1492 { 6, { 0x89, 0x05 }, {0xff, 0xf7 } },
1493 /* `movl m32, %edx' */
1494 { 6, { 0x89, 0x15 }, {0xff, 0xff } },
1496 /* Check for `xorl r32, r32' and the equivalent `subl r32, r32'.
1497 Because of the symmetry, there are actually two ways to encode
1498 these instructions; opcode bytes 0x29 and 0x2b for `subl' and
1499 opcode bytes 0x31 and 0x33 for `xorl'. */
1501 /* `subl %eax, %eax' */
1502 { 2, { 0x29, 0xc0 }, { 0xfd, 0xff } },
1503 /* `subl %ecx, %ecx' */
1504 { 2, { 0x29, 0xc9 }, { 0xfd, 0xff } },
1505 /* `subl %edx, %edx' */
1506 { 2, { 0x29, 0xd2 }, { 0xfd, 0xff } },
1507 /* `xorl %eax, %eax' */
1508 { 2, { 0x31, 0xc0 }, { 0xfd, 0xff } },
1509 /* `xorl %ecx, %ecx' */
1510 { 2, { 0x31, 0xc9 }, { 0xfd, 0xff } },
1511 /* `xorl %edx, %edx' */
1512 { 2, { 0x31, 0xd2 }, { 0xfd, 0xff } },
1517 /* Check whether PC points to a no-op instruction. */
1519 i386_skip_noop (CORE_ADDR pc)
1524 if (target_read_code (pc, &op, 1))
1530 /* Ignore `nop' instruction. */
1534 if (target_read_code (pc, &op, 1))
1538 /* Ignore no-op instruction `mov %edi, %edi'.
1539 Microsoft system dlls often start with
1540 a `mov %edi,%edi' instruction.
1541 The 5 bytes before the function start are
1542 filled with `nop' instructions.
1543 This pattern can be used for hot-patching:
1544 The `mov %edi, %edi' instruction can be replaced by a
1545 near jump to the location of the 5 `nop' instructions
1546 which can be replaced by a 32-bit jump to anywhere
1547 in the 32-bit address space. */
1549 else if (op == 0x8b)
1551 if (target_read_code (pc + 1, &op, 1))
1557 if (target_read_code (pc, &op, 1))
1567 /* Check whether PC points at a code that sets up a new stack frame.
1568 If so, it updates CACHE and returns the address of the first
1569 instruction after the sequence that sets up the frame or LIMIT,
1570 whichever is smaller. If we don't recognize the code, return PC. */
1573 i386_analyze_frame_setup (struct gdbarch *gdbarch,
1574 CORE_ADDR pc, CORE_ADDR limit,
1575 struct i386_frame_cache *cache)
1577 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1578 struct i386_insn *insn;
1585 if (target_read_code (pc, &op, 1))
1588 if (op == 0x55) /* pushl %ebp */
1590 /* Take into account that we've executed the `pushl %ebp' that
1591 starts this instruction sequence. */
1592 cache->saved_regs[I386_EBP_REGNUM] = 0;
1593 cache->sp_offset += 4;
1596 /* If that's all, return now. */
1600 /* Check for some special instructions that might be migrated by
1601 GCC into the prologue and skip them. At this point in the
1602 prologue, code should only touch the scratch registers %eax,
1603 %ecx and %edx, so while the number of posibilities is sheer,
1606 Make sure we only skip these instructions if we later see the
1607 `movl %esp, %ebp' that actually sets up the frame. */
1608 while (pc + skip < limit)
1610 insn = i386_match_insn (pc + skip, i386_frame_setup_skip_insns);
1617 /* If that's all, return now. */
1618 if (limit <= pc + skip)
1621 if (target_read_code (pc + skip, &op, 1))
1624 /* The i386 prologue looks like
1630 and a different prologue can be generated for atom.
1634 lea -0x10(%esp),%esp
1636 We handle both of them here. */
1640 /* Check for `movl %esp, %ebp' -- can be written in two ways. */
1642 if (read_code_unsigned_integer (pc + skip + 1, 1, byte_order)
1648 if (read_code_unsigned_integer (pc + skip + 1, 1, byte_order)
1653 case 0x8d: /* Check for 'lea (%ebp), %ebp'. */
1654 if (read_code_unsigned_integer (pc + skip + 1, 2, byte_order)
1663 /* OK, we actually have a frame. We just don't know how large
1664 it is yet. Set its size to zero. We'll adjust it if
1665 necessary. We also now commit to skipping the special
1666 instructions mentioned before. */
1669 /* If that's all, return now. */
1673 /* Check for stack adjustment
1679 NOTE: You can't subtract a 16-bit immediate from a 32-bit
1680 reg, so we don't have to worry about a data16 prefix. */
1681 if (target_read_code (pc, &op, 1))
1685 /* `subl' with 8-bit immediate. */
1686 if (read_code_unsigned_integer (pc + 1, 1, byte_order) != 0xec)
1687 /* Some instruction starting with 0x83 other than `subl'. */
1690 /* `subl' with signed 8-bit immediate (though it wouldn't
1691 make sense to be negative). */
1692 cache->locals = read_code_integer (pc + 2, 1, byte_order);
1695 else if (op == 0x81)
1697 /* Maybe it is `subl' with a 32-bit immediate. */
1698 if (read_code_unsigned_integer (pc + 1, 1, byte_order) != 0xec)
1699 /* Some instruction starting with 0x81 other than `subl'. */
1702 /* It is `subl' with a 32-bit immediate. */
1703 cache->locals = read_code_integer (pc + 2, 4, byte_order);
1706 else if (op == 0x8d)
1708 /* The ModR/M byte is 0x64. */
1709 if (read_code_unsigned_integer (pc + 1, 1, byte_order) != 0x64)
1711 /* 'lea' with 8-bit displacement. */
1712 cache->locals = -1 * read_code_integer (pc + 3, 1, byte_order);
1717 /* Some instruction other than `subl' nor 'lea'. */
1721 else if (op == 0xc8) /* enter */
1723 cache->locals = read_code_unsigned_integer (pc + 1, 2, byte_order);
1730 /* Check whether PC points at code that saves registers on the stack.
1731 If so, it updates CACHE and returns the address of the first
1732 instruction after the register saves or CURRENT_PC, whichever is
1733 smaller. Otherwise, return PC. */
1736 i386_analyze_register_saves (CORE_ADDR pc, CORE_ADDR current_pc,
1737 struct i386_frame_cache *cache)
1739 CORE_ADDR offset = 0;
1743 if (cache->locals > 0)
1744 offset -= cache->locals;
1745 for (i = 0; i < 8 && pc < current_pc; i++)
1747 if (target_read_code (pc, &op, 1))
1749 if (op < 0x50 || op > 0x57)
1753 cache->saved_regs[op - 0x50] = offset;
1754 cache->sp_offset += 4;
1761 /* Do a full analysis of the prologue at PC and update CACHE
1762 accordingly. Bail out early if CURRENT_PC is reached. Return the
1763 address where the analysis stopped.
1765 We handle these cases:
1767 The startup sequence can be at the start of the function, or the
1768 function can start with a branch to startup code at the end.
1770 %ebp can be set up with either the 'enter' instruction, or "pushl
1771 %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was
1772 once used in the System V compiler).
1774 Local space is allocated just below the saved %ebp by either the
1775 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a
1776 16-bit unsigned argument for space to allocate, and the 'addl'
1777 instruction could have either a signed byte, or 32-bit immediate.
1779 Next, the registers used by this function are pushed. With the
1780 System V compiler they will always be in the order: %edi, %esi,
1781 %ebx (and sometimes a harmless bug causes it to also save but not
1782 restore %eax); however, the code below is willing to see the pushes
1783 in any order, and will handle up to 8 of them.
1785 If the setup sequence is at the end of the function, then the next
1786 instruction will be a branch back to the start. */
1789 i386_analyze_prologue (struct gdbarch *gdbarch,
1790 CORE_ADDR pc, CORE_ADDR current_pc,
1791 struct i386_frame_cache *cache)
1793 pc = i386_skip_noop (pc);
1794 pc = i386_follow_jump (gdbarch, pc);
1795 pc = i386_analyze_struct_return (pc, current_pc, cache);
1796 pc = i386_skip_probe (pc);
1797 pc = i386_analyze_stack_align (pc, current_pc, cache);
1798 pc = i386_analyze_frame_setup (gdbarch, pc, current_pc, cache);
1799 return i386_analyze_register_saves (pc, current_pc, cache);
1802 /* Return PC of first real instruction. */
1805 i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
1807 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1809 static gdb_byte pic_pat[6] =
1811 0xe8, 0, 0, 0, 0, /* call 0x0 */
1812 0x5b, /* popl %ebx */
1814 struct i386_frame_cache cache;
1818 CORE_ADDR func_addr;
1820 if (find_pc_partial_function (start_pc, NULL, &func_addr, NULL))
1822 CORE_ADDR post_prologue_pc
1823 = skip_prologue_using_sal (gdbarch, func_addr);
1824 struct symtab *s = find_pc_symtab (func_addr);
1826 /* Clang always emits a line note before the prologue and another
1827 one after. We trust clang to emit usable line notes. */
1828 if (post_prologue_pc
1830 && s->producer != NULL
1831 && strncmp (s->producer, "clang ", sizeof ("clang ") - 1) == 0))
1832 return max (start_pc, post_prologue_pc);
1836 pc = i386_analyze_prologue (gdbarch, start_pc, 0xffffffff, &cache);
1837 if (cache.locals < 0)
1840 /* Found valid frame setup. */
1842 /* The native cc on SVR4 in -K PIC mode inserts the following code
1843 to get the address of the global offset table (GOT) into register
1848 movl %ebx,x(%ebp) (optional)
1851 This code is with the rest of the prologue (at the end of the
1852 function), so we have to skip it to get to the first real
1853 instruction at the start of the function. */
1855 for (i = 0; i < 6; i++)
1857 if (target_read_code (pc + i, &op, 1))
1860 if (pic_pat[i] != op)
1867 if (target_read_code (pc + delta, &op, 1))
1870 if (op == 0x89) /* movl %ebx, x(%ebp) */
1872 op = read_code_unsigned_integer (pc + delta + 1, 1, byte_order);
1874 if (op == 0x5d) /* One byte offset from %ebp. */
1876 else if (op == 0x9d) /* Four byte offset from %ebp. */
1878 else /* Unexpected instruction. */
1881 if (target_read_code (pc + delta, &op, 1))
1886 if (delta > 0 && op == 0x81
1887 && read_code_unsigned_integer (pc + delta + 1, 1, byte_order)
1894 /* If the function starts with a branch (to startup code at the end)
1895 the last instruction should bring us back to the first
1896 instruction of the real code. */
1897 if (i386_follow_jump (gdbarch, start_pc) != start_pc)
1898 pc = i386_follow_jump (gdbarch, pc);
1903 /* Check that the code pointed to by PC corresponds to a call to
1904 __main, skip it if so. Return PC otherwise. */
1907 i386_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
1909 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1912 if (target_read_code (pc, &op, 1))
1918 if (target_read_code (pc + 1, buf, sizeof buf) == 0)
1920 /* Make sure address is computed correctly as a 32bit
1921 integer even if CORE_ADDR is 64 bit wide. */
1922 struct bound_minimal_symbol s;
1923 CORE_ADDR call_dest;
1925 call_dest = pc + 5 + extract_signed_integer (buf, 4, byte_order);
1926 call_dest = call_dest & 0xffffffffU;
1927 s = lookup_minimal_symbol_by_pc (call_dest);
1928 if (s.minsym != NULL
1929 && MSYMBOL_LINKAGE_NAME (s.minsym) != NULL
1930 && strcmp (MSYMBOL_LINKAGE_NAME (s.minsym), "__main") == 0)
1938 /* This function is 64-bit safe. */
1941 i386_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1945 frame_unwind_register (next_frame, gdbarch_pc_regnum (gdbarch), buf);
1946 return extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
1950 /* Normal frames. */
1953 i386_frame_cache_1 (struct frame_info *this_frame,
1954 struct i386_frame_cache *cache)
1956 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1957 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1961 cache->pc = get_frame_func (this_frame);
1963 /* In principle, for normal frames, %ebp holds the frame pointer,
1964 which holds the base address for the current stack frame.
1965 However, for functions that don't need it, the frame pointer is
1966 optional. For these "frameless" functions the frame pointer is
1967 actually the frame pointer of the calling frame. Signal
1968 trampolines are just a special case of a "frameless" function.
1969 They (usually) share their frame pointer with the frame that was
1970 in progress when the signal occurred. */
1972 get_frame_register (this_frame, I386_EBP_REGNUM, buf);
1973 cache->base = extract_unsigned_integer (buf, 4, byte_order);
1974 if (cache->base == 0)
1980 /* For normal frames, %eip is stored at 4(%ebp). */
1981 cache->saved_regs[I386_EIP_REGNUM] = 4;
1984 i386_analyze_prologue (gdbarch, cache->pc, get_frame_pc (this_frame),
1987 if (cache->locals < 0)
1989 /* We didn't find a valid frame, which means that CACHE->base
1990 currently holds the frame pointer for our calling frame. If
1991 we're at the start of a function, or somewhere half-way its
1992 prologue, the function's frame probably hasn't been fully
1993 setup yet. Try to reconstruct the base address for the stack
1994 frame by looking at the stack pointer. For truly "frameless"
1995 functions this might work too. */
1997 if (cache->saved_sp_reg != -1)
1999 /* Saved stack pointer has been saved. */
2000 get_frame_register (this_frame, cache->saved_sp_reg, buf);
2001 cache->saved_sp = extract_unsigned_integer (buf, 4, byte_order);
2003 /* We're halfway aligning the stack. */
2004 cache->base = ((cache->saved_sp - 4) & 0xfffffff0) - 4;
2005 cache->saved_regs[I386_EIP_REGNUM] = cache->saved_sp - 4;
2007 /* This will be added back below. */
2008 cache->saved_regs[I386_EIP_REGNUM] -= cache->base;
2010 else if (cache->pc != 0
2011 || target_read_code (get_frame_pc (this_frame), buf, 1))
2013 /* We're in a known function, but did not find a frame
2014 setup. Assume that the function does not use %ebp.
2015 Alternatively, we may have jumped to an invalid
2016 address; in that case there is definitely no new
2018 get_frame_register (this_frame, I386_ESP_REGNUM, buf);
2019 cache->base = extract_unsigned_integer (buf, 4, byte_order)
2023 /* We're in an unknown function. We could not find the start
2024 of the function to analyze the prologue; our best option is
2025 to assume a typical frame layout with the caller's %ebp
2027 cache->saved_regs[I386_EBP_REGNUM] = 0;
2030 if (cache->saved_sp_reg != -1)
2032 /* Saved stack pointer has been saved (but the SAVED_SP_REG
2033 register may be unavailable). */
2034 if (cache->saved_sp == 0
2035 && deprecated_frame_register_read (this_frame,
2036 cache->saved_sp_reg, buf))
2037 cache->saved_sp = extract_unsigned_integer (buf, 4, byte_order);
2039 /* Now that we have the base address for the stack frame we can
2040 calculate the value of %esp in the calling frame. */
2041 else if (cache->saved_sp == 0)
2042 cache->saved_sp = cache->base + 8;
2044 /* Adjust all the saved registers such that they contain addresses
2045 instead of offsets. */
2046 for (i = 0; i < I386_NUM_SAVED_REGS; i++)
2047 if (cache->saved_regs[i] != -1)
2048 cache->saved_regs[i] += cache->base;
2053 static struct i386_frame_cache *
2054 i386_frame_cache (struct frame_info *this_frame, void **this_cache)
2056 volatile struct gdb_exception ex;
2057 struct i386_frame_cache *cache;
2062 cache = i386_alloc_frame_cache ();
2063 *this_cache = cache;
2065 TRY_CATCH (ex, RETURN_MASK_ERROR)
2067 i386_frame_cache_1 (this_frame, cache);
2069 if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
2070 throw_exception (ex);
2076 i386_frame_this_id (struct frame_info *this_frame, void **this_cache,
2077 struct frame_id *this_id)
2079 struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
2082 (*this_id) = frame_id_build_unavailable_stack (cache->pc);
2083 else if (cache->base == 0)
2085 /* This marks the outermost frame. */
2089 /* See the end of i386_push_dummy_call. */
2090 (*this_id) = frame_id_build (cache->base + 8, cache->pc);
2094 static enum unwind_stop_reason
2095 i386_frame_unwind_stop_reason (struct frame_info *this_frame,
2098 struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
2101 return UNWIND_UNAVAILABLE;
2103 /* This marks the outermost frame. */
2104 if (cache->base == 0)
2105 return UNWIND_OUTERMOST;
2107 return UNWIND_NO_REASON;
2110 static struct value *
2111 i386_frame_prev_register (struct frame_info *this_frame, void **this_cache,
2114 struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
2116 gdb_assert (regnum >= 0);
2118 /* The System V ABI says that:
2120 "The flags register contains the system flags, such as the
2121 direction flag and the carry flag. The direction flag must be
2122 set to the forward (that is, zero) direction before entry and
2123 upon exit from a function. Other user flags have no specified
2124 role in the standard calling sequence and are not preserved."
2126 To guarantee the "upon exit" part of that statement we fake a
2127 saved flags register that has its direction flag cleared.
2129 Note that GCC doesn't seem to rely on the fact that the direction
2130 flag is cleared after a function return; it always explicitly
2131 clears the flag before operations where it matters.
2133 FIXME: kettenis/20030316: I'm not quite sure whether this is the
2134 right thing to do. The way we fake the flags register here makes
2135 it impossible to change it. */
2137 if (regnum == I386_EFLAGS_REGNUM)
2141 val = get_frame_register_unsigned (this_frame, regnum);
2143 return frame_unwind_got_constant (this_frame, regnum, val);
2146 if (regnum == I386_EIP_REGNUM && cache->pc_in_eax)
2147 return frame_unwind_got_register (this_frame, regnum, I386_EAX_REGNUM);
2149 if (regnum == I386_ESP_REGNUM
2150 && (cache->saved_sp != 0 || cache->saved_sp_reg != -1))
2152 /* If the SP has been saved, but we don't know where, then this
2153 means that SAVED_SP_REG register was found unavailable back
2154 when we built the cache. */
2155 if (cache->saved_sp == 0)
2156 return frame_unwind_got_register (this_frame, regnum,
2157 cache->saved_sp_reg);
2159 return frame_unwind_got_constant (this_frame, regnum,
2163 if (regnum < I386_NUM_SAVED_REGS && cache->saved_regs[regnum] != -1)
2164 return frame_unwind_got_memory (this_frame, regnum,
2165 cache->saved_regs[regnum]);
2167 return frame_unwind_got_register (this_frame, regnum, regnum);
2170 static const struct frame_unwind i386_frame_unwind =
2173 i386_frame_unwind_stop_reason,
2175 i386_frame_prev_register,
2177 default_frame_sniffer
2180 /* Normal frames, but in a function epilogue. */
2182 /* The epilogue is defined here as the 'ret' instruction, which will
2183 follow any instruction such as 'leave' or 'pop %ebp' that destroys
2184 the function's stack frame. */
2187 i386_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
2190 struct symtab *symtab;
2192 symtab = find_pc_symtab (pc);
2193 if (symtab && symtab->epilogue_unwind_valid)
2196 if (target_read_memory (pc, &insn, 1))
2197 return 0; /* Can't read memory at pc. */
2199 if (insn != 0xc3) /* 'ret' instruction. */
2206 i386_epilogue_frame_sniffer (const struct frame_unwind *self,
2207 struct frame_info *this_frame,
2208 void **this_prologue_cache)
2210 if (frame_relative_level (this_frame) == 0)
2211 return i386_in_function_epilogue_p (get_frame_arch (this_frame),
2212 get_frame_pc (this_frame));
2217 static struct i386_frame_cache *
2218 i386_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
2220 volatile struct gdb_exception ex;
2221 struct i386_frame_cache *cache;
2227 cache = i386_alloc_frame_cache ();
2228 *this_cache = cache;
2230 TRY_CATCH (ex, RETURN_MASK_ERROR)
2232 cache->pc = get_frame_func (this_frame);
2234 /* At this point the stack looks as if we just entered the
2235 function, with the return address at the top of the
2237 sp = get_frame_register_unsigned (this_frame, I386_ESP_REGNUM);
2238 cache->base = sp + cache->sp_offset;
2239 cache->saved_sp = cache->base + 8;
2240 cache->saved_regs[I386_EIP_REGNUM] = cache->base + 4;
2244 if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
2245 throw_exception (ex);
2250 static enum unwind_stop_reason
2251 i386_epilogue_frame_unwind_stop_reason (struct frame_info *this_frame,
2254 struct i386_frame_cache *cache =
2255 i386_epilogue_frame_cache (this_frame, this_cache);
2258 return UNWIND_UNAVAILABLE;
2260 return UNWIND_NO_REASON;
2264 i386_epilogue_frame_this_id (struct frame_info *this_frame,
2266 struct frame_id *this_id)
2268 struct i386_frame_cache *cache =
2269 i386_epilogue_frame_cache (this_frame, this_cache);
2272 (*this_id) = frame_id_build_unavailable_stack (cache->pc);
2274 (*this_id) = frame_id_build (cache->base + 8, cache->pc);
2277 static struct value *
2278 i386_epilogue_frame_prev_register (struct frame_info *this_frame,
2279 void **this_cache, int regnum)
2281 /* Make sure we've initialized the cache. */
2282 i386_epilogue_frame_cache (this_frame, this_cache);
2284 return i386_frame_prev_register (this_frame, this_cache, regnum);
2287 static const struct frame_unwind i386_epilogue_frame_unwind =
2290 i386_epilogue_frame_unwind_stop_reason,
2291 i386_epilogue_frame_this_id,
2292 i386_epilogue_frame_prev_register,
2294 i386_epilogue_frame_sniffer
2298 /* Stack-based trampolines. */
2300 /* These trampolines are used on cross x86 targets, when taking the
2301 address of a nested function. When executing these trampolines,
2302 no stack frame is set up, so we are in a similar situation as in
2303 epilogues and i386_epilogue_frame_this_id can be re-used. */
2305 /* Static chain passed in register. */
2307 struct i386_insn i386_tramp_chain_in_reg_insns[] =
2309 /* `movl imm32, %eax' and `movl imm32, %ecx' */
2310 { 5, { 0xb8 }, { 0xfe } },
2313 { 5, { 0xe9 }, { 0xff } },
2318 /* Static chain passed on stack (when regparm=3). */
2320 struct i386_insn i386_tramp_chain_on_stack_insns[] =
2323 { 5, { 0x68 }, { 0xff } },
2326 { 5, { 0xe9 }, { 0xff } },
2331 /* Return whether PC points inside a stack trampoline. */
2334 i386_in_stack_tramp_p (CORE_ADDR pc)
2339 /* A stack trampoline is detected if no name is associated
2340 to the current pc and if it points inside a trampoline
2343 find_pc_partial_function (pc, &name, NULL, NULL);
2347 if (target_read_memory (pc, &insn, 1))
2350 if (!i386_match_insn_block (pc, i386_tramp_chain_in_reg_insns)
2351 && !i386_match_insn_block (pc, i386_tramp_chain_on_stack_insns))
2358 i386_stack_tramp_frame_sniffer (const struct frame_unwind *self,
2359 struct frame_info *this_frame,
2362 if (frame_relative_level (this_frame) == 0)
2363 return i386_in_stack_tramp_p (get_frame_pc (this_frame));
2368 static const struct frame_unwind i386_stack_tramp_frame_unwind =
2371 i386_epilogue_frame_unwind_stop_reason,
2372 i386_epilogue_frame_this_id,
2373 i386_epilogue_frame_prev_register,
2375 i386_stack_tramp_frame_sniffer
2378 /* Generate a bytecode expression to get the value of the saved PC. */
2381 i386_gen_return_address (struct gdbarch *gdbarch,
2382 struct agent_expr *ax, struct axs_value *value,
2385 /* The following sequence assumes the traditional use of the base
2387 ax_reg (ax, I386_EBP_REGNUM);
2389 ax_simple (ax, aop_add);
2390 value->type = register_type (gdbarch, I386_EIP_REGNUM);
2391 value->kind = axs_lvalue_memory;
2395 /* Signal trampolines. */
2397 static struct i386_frame_cache *
2398 i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
2400 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2401 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2402 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2403 volatile struct gdb_exception ex;
2404 struct i386_frame_cache *cache;
2411 cache = i386_alloc_frame_cache ();
2413 TRY_CATCH (ex, RETURN_MASK_ERROR)
2415 get_frame_register (this_frame, I386_ESP_REGNUM, buf);
2416 cache->base = extract_unsigned_integer (buf, 4, byte_order) - 4;
2418 addr = tdep->sigcontext_addr (this_frame);
2419 if (tdep->sc_reg_offset)
2423 gdb_assert (tdep->sc_num_regs <= I386_NUM_SAVED_REGS);
2425 for (i = 0; i < tdep->sc_num_regs; i++)
2426 if (tdep->sc_reg_offset[i] != -1)
2427 cache->saved_regs[i] = addr + tdep->sc_reg_offset[i];
2431 cache->saved_regs[I386_EIP_REGNUM] = addr + tdep->sc_pc_offset;
2432 cache->saved_regs[I386_ESP_REGNUM] = addr + tdep->sc_sp_offset;
2437 if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
2438 throw_exception (ex);
2440 *this_cache = cache;
2444 static enum unwind_stop_reason
2445 i386_sigtramp_frame_unwind_stop_reason (struct frame_info *this_frame,
2448 struct i386_frame_cache *cache =
2449 i386_sigtramp_frame_cache (this_frame, this_cache);
2452 return UNWIND_UNAVAILABLE;
2454 return UNWIND_NO_REASON;
2458 i386_sigtramp_frame_this_id (struct frame_info *this_frame, void **this_cache,
2459 struct frame_id *this_id)
2461 struct i386_frame_cache *cache =
2462 i386_sigtramp_frame_cache (this_frame, this_cache);
2465 (*this_id) = frame_id_build_unavailable_stack (get_frame_pc (this_frame));
2468 /* See the end of i386_push_dummy_call. */
2469 (*this_id) = frame_id_build (cache->base + 8, get_frame_pc (this_frame));
2473 static struct value *
2474 i386_sigtramp_frame_prev_register (struct frame_info *this_frame,
2475 void **this_cache, int regnum)
2477 /* Make sure we've initialized the cache. */
2478 i386_sigtramp_frame_cache (this_frame, this_cache);
2480 return i386_frame_prev_register (this_frame, this_cache, regnum);
2484 i386_sigtramp_frame_sniffer (const struct frame_unwind *self,
2485 struct frame_info *this_frame,
2486 void **this_prologue_cache)
2488 struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame));
2490 /* We shouldn't even bother if we don't have a sigcontext_addr
2492 if (tdep->sigcontext_addr == NULL)
2495 if (tdep->sigtramp_p != NULL)
2497 if (tdep->sigtramp_p (this_frame))
2501 if (tdep->sigtramp_start != 0)
2503 CORE_ADDR pc = get_frame_pc (this_frame);
2505 gdb_assert (tdep->sigtramp_end != 0);
2506 if (pc >= tdep->sigtramp_start && pc < tdep->sigtramp_end)
2513 static const struct frame_unwind i386_sigtramp_frame_unwind =
2516 i386_sigtramp_frame_unwind_stop_reason,
2517 i386_sigtramp_frame_this_id,
2518 i386_sigtramp_frame_prev_register,
2520 i386_sigtramp_frame_sniffer
2525 i386_frame_base_address (struct frame_info *this_frame, void **this_cache)
2527 struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
2532 static const struct frame_base i386_frame_base =
2535 i386_frame_base_address,
2536 i386_frame_base_address,
2537 i386_frame_base_address
2540 static struct frame_id
2541 i386_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
2545 fp = get_frame_register_unsigned (this_frame, I386_EBP_REGNUM);
2547 /* See the end of i386_push_dummy_call. */
2548 return frame_id_build (fp + 8, get_frame_pc (this_frame));
2551 /* _Decimal128 function return values need 16-byte alignment on the
2555 i386_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
2557 return sp & -(CORE_ADDR)16;
2561 /* Figure out where the longjmp will land. Slurp the args out of the
2562 stack. We expect the first arg to be a pointer to the jmp_buf
2563 structure from which we extract the address that we will land at.
2564 This address is copied into PC. This routine returns non-zero on
2568 i386_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
2571 CORE_ADDR sp, jb_addr;
2572 struct gdbarch *gdbarch = get_frame_arch (frame);
2573 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2574 int jb_pc_offset = gdbarch_tdep (gdbarch)->jb_pc_offset;
2576 /* If JB_PC_OFFSET is -1, we have no way to find out where the
2577 longjmp will land. */
2578 if (jb_pc_offset == -1)
2581 get_frame_register (frame, I386_ESP_REGNUM, buf);
2582 sp = extract_unsigned_integer (buf, 4, byte_order);
2583 if (target_read_memory (sp + 4, buf, 4))
2586 jb_addr = extract_unsigned_integer (buf, 4, byte_order);
2587 if (target_read_memory (jb_addr + jb_pc_offset, buf, 4))
2590 *pc = extract_unsigned_integer (buf, 4, byte_order);
2595 /* Check whether TYPE must be 16-byte-aligned when passed as a
2596 function argument. 16-byte vectors, _Decimal128 and structures or
2597 unions containing such types must be 16-byte-aligned; other
2598 arguments are 4-byte-aligned. */
2601 i386_16_byte_align_p (struct type *type)
2603 type = check_typedef (type);
2604 if ((TYPE_CODE (type) == TYPE_CODE_DECFLOAT
2605 || (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type)))
2606 && TYPE_LENGTH (type) == 16)
2608 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
2609 return i386_16_byte_align_p (TYPE_TARGET_TYPE (type));
2610 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
2611 || TYPE_CODE (type) == TYPE_CODE_UNION)
2614 for (i = 0; i < TYPE_NFIELDS (type); i++)
2616 if (i386_16_byte_align_p (TYPE_FIELD_TYPE (type, i)))
2623 /* Implementation for set_gdbarch_push_dummy_code. */
2626 i386_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, CORE_ADDR funaddr,
2627 struct value **args, int nargs, struct type *value_type,
2628 CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
2629 struct regcache *regcache)
2631 /* Use 0xcc breakpoint - 1 byte. */
2635 /* Keep the stack aligned. */
2640 i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
2641 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
2642 struct value **args, CORE_ADDR sp, int struct_return,
2643 CORE_ADDR struct_addr)
2645 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2651 /* Determine the total space required for arguments and struct
2652 return address in a first pass (allowing for 16-byte-aligned
2653 arguments), then push arguments in a second pass. */
2655 for (write_pass = 0; write_pass < 2; write_pass++)
2657 int args_space_used = 0;
2663 /* Push value address. */
2664 store_unsigned_integer (buf, 4, byte_order, struct_addr);
2665 write_memory (sp, buf, 4);
2666 args_space_used += 4;
2672 for (i = 0; i < nargs; i++)
2674 int len = TYPE_LENGTH (value_enclosing_type (args[i]));
2678 if (i386_16_byte_align_p (value_enclosing_type (args[i])))
2679 args_space_used = align_up (args_space_used, 16);
2681 write_memory (sp + args_space_used,
2682 value_contents_all (args[i]), len);
2683 /* The System V ABI says that:
2685 "An argument's size is increased, if necessary, to make it a
2686 multiple of [32-bit] words. This may require tail padding,
2687 depending on the size of the argument."
2689 This makes sure the stack stays word-aligned. */
2690 args_space_used += align_up (len, 4);
2694 if (i386_16_byte_align_p (value_enclosing_type (args[i])))
2695 args_space = align_up (args_space, 16);
2696 args_space += align_up (len, 4);
2704 /* The original System V ABI only requires word alignment,
2705 but modern incarnations need 16-byte alignment in order
2706 to support SSE. Since wasting a few bytes here isn't
2707 harmful we unconditionally enforce 16-byte alignment. */
2712 /* Store return address. */
2714 store_unsigned_integer (buf, 4, byte_order, bp_addr);
2715 write_memory (sp, buf, 4);
2717 /* Finally, update the stack pointer... */
2718 store_unsigned_integer (buf, 4, byte_order, sp);
2719 regcache_cooked_write (regcache, I386_ESP_REGNUM, buf);
2721 /* ...and fake a frame pointer. */
2722 regcache_cooked_write (regcache, I386_EBP_REGNUM, buf);
2724 /* MarkK wrote: This "+ 8" is all over the place:
2725 (i386_frame_this_id, i386_sigtramp_frame_this_id,
2726 i386_dummy_id). It's there, since all frame unwinders for
2727 a given target have to agree (within a certain margin) on the
2728 definition of the stack address of a frame. Otherwise frame id
2729 comparison might not work correctly. Since DWARF2/GCC uses the
2730 stack address *before* the function call as a frame's CFA. On
2731 the i386, when %ebp is used as a frame pointer, the offset
2732 between the contents %ebp and the CFA as defined by GCC. */
2736 /* These registers are used for returning integers (and on some
2737 targets also for returning `struct' and `union' values when their
2738 size and alignment match an integer type). */
2739 #define LOW_RETURN_REGNUM I386_EAX_REGNUM /* %eax */
2740 #define HIGH_RETURN_REGNUM I386_EDX_REGNUM /* %edx */
2742 /* Read, for architecture GDBARCH, a function return value of TYPE
2743 from REGCACHE, and copy that into VALBUF. */
2746 i386_extract_return_value (struct gdbarch *gdbarch, struct type *type,
2747 struct regcache *regcache, gdb_byte *valbuf)
2749 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2750 int len = TYPE_LENGTH (type);
2751 gdb_byte buf[I386_MAX_REGISTER_SIZE];
2753 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2755 if (tdep->st0_regnum < 0)
2757 warning (_("Cannot find floating-point return value."));
2758 memset (valbuf, 0, len);
2762 /* Floating-point return values can be found in %st(0). Convert
2763 its contents to the desired type. This is probably not
2764 exactly how it would happen on the target itself, but it is
2765 the best we can do. */
2766 regcache_raw_read (regcache, I386_ST0_REGNUM, buf);
2767 convert_typed_floating (buf, i387_ext_type (gdbarch), valbuf, type);
2771 int low_size = register_size (gdbarch, LOW_RETURN_REGNUM);
2772 int high_size = register_size (gdbarch, HIGH_RETURN_REGNUM);
2774 if (len <= low_size)
2776 regcache_raw_read (regcache, LOW_RETURN_REGNUM, buf);
2777 memcpy (valbuf, buf, len);
2779 else if (len <= (low_size + high_size))
2781 regcache_raw_read (regcache, LOW_RETURN_REGNUM, buf);
2782 memcpy (valbuf, buf, low_size);
2783 regcache_raw_read (regcache, HIGH_RETURN_REGNUM, buf);
2784 memcpy (valbuf + low_size, buf, len - low_size);
2787 internal_error (__FILE__, __LINE__,
2788 _("Cannot extract return value of %d bytes long."),
2793 /* Write, for architecture GDBARCH, a function return value of TYPE
2794 from VALBUF into REGCACHE. */
2797 i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
2798 struct regcache *regcache, const gdb_byte *valbuf)
2800 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2801 int len = TYPE_LENGTH (type);
2803 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2806 gdb_byte buf[I386_MAX_REGISTER_SIZE];
2808 if (tdep->st0_regnum < 0)
2810 warning (_("Cannot set floating-point return value."));
2814 /* Returning floating-point values is a bit tricky. Apart from
2815 storing the return value in %st(0), we have to simulate the
2816 state of the FPU at function return point. */
2818 /* Convert the value found in VALBUF to the extended
2819 floating-point format used by the FPU. This is probably
2820 not exactly how it would happen on the target itself, but
2821 it is the best we can do. */
2822 convert_typed_floating (valbuf, type, buf, i387_ext_type (gdbarch));
2823 regcache_raw_write (regcache, I386_ST0_REGNUM, buf);
2825 /* Set the top of the floating-point register stack to 7. The
2826 actual value doesn't really matter, but 7 is what a normal
2827 function return would end up with if the program started out
2828 with a freshly initialized FPU. */
2829 regcache_raw_read_unsigned (regcache, I387_FSTAT_REGNUM (tdep), &fstat);
2831 regcache_raw_write_unsigned (regcache, I387_FSTAT_REGNUM (tdep), fstat);
2833 /* Mark %st(1) through %st(7) as empty. Since we set the top of
2834 the floating-point register stack to 7, the appropriate value
2835 for the tag word is 0x3fff. */
2836 regcache_raw_write_unsigned (regcache, I387_FTAG_REGNUM (tdep), 0x3fff);
2840 int low_size = register_size (gdbarch, LOW_RETURN_REGNUM);
2841 int high_size = register_size (gdbarch, HIGH_RETURN_REGNUM);
2843 if (len <= low_size)
2844 regcache_raw_write_part (regcache, LOW_RETURN_REGNUM, 0, len, valbuf);
2845 else if (len <= (low_size + high_size))
2847 regcache_raw_write (regcache, LOW_RETURN_REGNUM, valbuf);
2848 regcache_raw_write_part (regcache, HIGH_RETURN_REGNUM, 0,
2849 len - low_size, valbuf + low_size);
2852 internal_error (__FILE__, __LINE__,
2853 _("Cannot store return value of %d bytes long."), len);
2858 /* This is the variable that is set with "set struct-convention", and
2859 its legitimate values. */
2860 static const char default_struct_convention[] = "default";
2861 static const char pcc_struct_convention[] = "pcc";
2862 static const char reg_struct_convention[] = "reg";
2863 static const char *const valid_conventions[] =
2865 default_struct_convention,
2866 pcc_struct_convention,
2867 reg_struct_convention,
2870 static const char *struct_convention = default_struct_convention;
2872 /* Return non-zero if TYPE, which is assumed to be a structure,
2873 a union type, or an array type, should be returned in registers
2874 for architecture GDBARCH. */
2877 i386_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
2879 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2880 enum type_code code = TYPE_CODE (type);
2881 int len = TYPE_LENGTH (type);
2883 gdb_assert (code == TYPE_CODE_STRUCT
2884 || code == TYPE_CODE_UNION
2885 || code == TYPE_CODE_ARRAY);
2887 if (struct_convention == pcc_struct_convention
2888 || (struct_convention == default_struct_convention
2889 && tdep->struct_return == pcc_struct_return))
2892 /* Structures consisting of a single `float', `double' or 'long
2893 double' member are returned in %st(0). */
2894 if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
2896 type = check_typedef (TYPE_FIELD_TYPE (type, 0));
2897 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2898 return (len == 4 || len == 8 || len == 12);
2901 return (len == 1 || len == 2 || len == 4 || len == 8);
2904 /* Determine, for architecture GDBARCH, how a return value of TYPE
2905 should be returned. If it is supposed to be returned in registers,
2906 and READBUF is non-zero, read the appropriate value from REGCACHE,
2907 and copy it into READBUF. If WRITEBUF is non-zero, write the value
2908 from WRITEBUF into REGCACHE. */
2910 static enum return_value_convention
2911 i386_return_value (struct gdbarch *gdbarch, struct value *function,
2912 struct type *type, struct regcache *regcache,
2913 gdb_byte *readbuf, const gdb_byte *writebuf)
2915 enum type_code code = TYPE_CODE (type);
2917 if (((code == TYPE_CODE_STRUCT
2918 || code == TYPE_CODE_UNION
2919 || code == TYPE_CODE_ARRAY)
2920 && !i386_reg_struct_return_p (gdbarch, type))
2921 /* Complex double and long double uses the struct return covention. */
2922 || (code == TYPE_CODE_COMPLEX && TYPE_LENGTH (type) == 16)
2923 || (code == TYPE_CODE_COMPLEX && TYPE_LENGTH (type) == 24)
2924 /* 128-bit decimal float uses the struct return convention. */
2925 || (code == TYPE_CODE_DECFLOAT && TYPE_LENGTH (type) == 16))
2927 /* The System V ABI says that:
2929 "A function that returns a structure or union also sets %eax
2930 to the value of the original address of the caller's area
2931 before it returns. Thus when the caller receives control
2932 again, the address of the returned object resides in register
2933 %eax and can be used to access the object."
2935 So the ABI guarantees that we can always find the return
2936 value just after the function has returned. */
2938 /* Note that the ABI doesn't mention functions returning arrays,
2939 which is something possible in certain languages such as Ada.
2940 In this case, the value is returned as if it was wrapped in
2941 a record, so the convention applied to records also applies
2948 regcache_raw_read_unsigned (regcache, I386_EAX_REGNUM, &addr);
2949 read_memory (addr, readbuf, TYPE_LENGTH (type));
2952 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
2955 /* This special case is for structures consisting of a single
2956 `float', `double' or 'long double' member. These structures are
2957 returned in %st(0). For these structures, we call ourselves
2958 recursively, changing TYPE into the type of the first member of
2959 the structure. Since that should work for all structures that
2960 have only one member, we don't bother to check the member's type
2962 if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
2964 type = check_typedef (TYPE_FIELD_TYPE (type, 0));
2965 return i386_return_value (gdbarch, function, type, regcache,
2970 i386_extract_return_value (gdbarch, type, regcache, readbuf);
2972 i386_store_return_value (gdbarch, type, regcache, writebuf);
2974 return RETURN_VALUE_REGISTER_CONVENTION;
2979 i387_ext_type (struct gdbarch *gdbarch)
2981 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2983 if (!tdep->i387_ext_type)
2985 tdep->i387_ext_type = tdesc_find_type (gdbarch, "i387_ext");
2986 gdb_assert (tdep->i387_ext_type != NULL);
2989 return tdep->i387_ext_type;
2992 /* Construct type for pseudo BND registers. We can't use
2993 tdesc_find_type since a complement of one value has to be used
2994 to describe the upper bound. */
2996 static struct type *
2997 i386_bnd_type (struct gdbarch *gdbarch)
2999 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3002 if (!tdep->i386_bnd_type)
3004 struct type *t, *bound_t;
3005 const struct builtin_type *bt = builtin_type (gdbarch);
3007 /* The type we're building is described bellow: */
3012 void *ubound; /* One complement of raw ubound field. */
3016 t = arch_composite_type (gdbarch,
3017 "__gdb_builtin_type_bound128", TYPE_CODE_STRUCT);
3019 append_composite_type_field (t, "lbound", bt->builtin_data_ptr);
3020 append_composite_type_field (t, "ubound", bt->builtin_data_ptr);
3022 TYPE_NAME (t) = "builtin_type_bound128";
3023 tdep->i386_bnd_type = t;
3026 return tdep->i386_bnd_type;
3029 /* Construct vector type for pseudo ZMM registers. We can't use
3030 tdesc_find_type since ZMM isn't described in target description. */
3032 static struct type *
3033 i386_zmm_type (struct gdbarch *gdbarch)
3035 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3037 if (!tdep->i386_zmm_type)
3039 const struct builtin_type *bt = builtin_type (gdbarch);
3041 /* The type we're building is this: */
3043 union __gdb_builtin_type_vec512i
3045 int128_t uint128[4];
3046 int64_t v4_int64[8];
3047 int32_t v8_int32[16];
3048 int16_t v16_int16[32];
3049 int8_t v32_int8[64];
3050 double v4_double[8];
3057 t = arch_composite_type (gdbarch,
3058 "__gdb_builtin_type_vec512i", TYPE_CODE_UNION);
3059 append_composite_type_field (t, "v16_float",
3060 init_vector_type (bt->builtin_float, 16));
3061 append_composite_type_field (t, "v8_double",
3062 init_vector_type (bt->builtin_double, 8));
3063 append_composite_type_field (t, "v64_int8",
3064 init_vector_type (bt->builtin_int8, 64));
3065 append_composite_type_field (t, "v32_int16",
3066 init_vector_type (bt->builtin_int16, 32));
3067 append_composite_type_field (t, "v16_int32",
3068 init_vector_type (bt->builtin_int32, 16));
3069 append_composite_type_field (t, "v8_int64",
3070 init_vector_type (bt->builtin_int64, 8));
3071 append_composite_type_field (t, "v4_int128",
3072 init_vector_type (bt->builtin_int128, 4));
3074 TYPE_VECTOR (t) = 1;
3075 TYPE_NAME (t) = "builtin_type_vec512i";
3076 tdep->i386_zmm_type = t;
3079 return tdep->i386_zmm_type;
3082 /* Construct vector type for pseudo YMM registers. We can't use
3083 tdesc_find_type since YMM isn't described in target description. */
3085 static struct type *
3086 i386_ymm_type (struct gdbarch *gdbarch)
3088 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3090 if (!tdep->i386_ymm_type)
3092 const struct builtin_type *bt = builtin_type (gdbarch);
3094 /* The type we're building is this: */
3096 union __gdb_builtin_type_vec256i
3098 int128_t uint128[2];
3099 int64_t v2_int64[4];
3100 int32_t v4_int32[8];
3101 int16_t v8_int16[16];
3102 int8_t v16_int8[32];
3103 double v2_double[4];
3110 t = arch_composite_type (gdbarch,
3111 "__gdb_builtin_type_vec256i", TYPE_CODE_UNION);
3112 append_composite_type_field (t, "v8_float",
3113 init_vector_type (bt->builtin_float, 8));
3114 append_composite_type_field (t, "v4_double",
3115 init_vector_type (bt->builtin_double, 4));
3116 append_composite_type_field (t, "v32_int8",
3117 init_vector_type (bt->builtin_int8, 32));
3118 append_composite_type_field (t, "v16_int16",
3119 init_vector_type (bt->builtin_int16, 16));
3120 append_composite_type_field (t, "v8_int32",
3121 init_vector_type (bt->builtin_int32, 8));
3122 append_composite_type_field (t, "v4_int64",
3123 init_vector_type (bt->builtin_int64, 4));
3124 append_composite_type_field (t, "v2_int128",
3125 init_vector_type (bt->builtin_int128, 2));
3127 TYPE_VECTOR (t) = 1;
3128 TYPE_NAME (t) = "builtin_type_vec256i";
3129 tdep->i386_ymm_type = t;
3132 return tdep->i386_ymm_type;
3135 /* Construct vector type for MMX registers. */
3136 static struct type *
3137 i386_mmx_type (struct gdbarch *gdbarch)
3139 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3141 if (!tdep->i386_mmx_type)
3143 const struct builtin_type *bt = builtin_type (gdbarch);
3145 /* The type we're building is this: */
3147 union __gdb_builtin_type_vec64i
3150 int32_t v2_int32[2];
3151 int16_t v4_int16[4];
3158 t = arch_composite_type (gdbarch,
3159 "__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
3161 append_composite_type_field (t, "uint64", bt->builtin_int64);
3162 append_composite_type_field (t, "v2_int32",
3163 init_vector_type (bt->builtin_int32, 2));
3164 append_composite_type_field (t, "v4_int16",
3165 init_vector_type (bt->builtin_int16, 4));
3166 append_composite_type_field (t, "v8_int8",
3167 init_vector_type (bt->builtin_int8, 8));
3169 TYPE_VECTOR (t) = 1;
3170 TYPE_NAME (t) = "builtin_type_vec64i";
3171 tdep->i386_mmx_type = t;
3174 return tdep->i386_mmx_type;
3177 /* Return the GDB type object for the "standard" data type of data in
3181 i386_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
3183 if (i386_bnd_regnum_p (gdbarch, regnum))
3184 return i386_bnd_type (gdbarch);
3185 if (i386_mmx_regnum_p (gdbarch, regnum))
3186 return i386_mmx_type (gdbarch);
3187 else if (i386_ymm_regnum_p (gdbarch, regnum))
3188 return i386_ymm_type (gdbarch);
3189 else if (i386_ymm_avx512_regnum_p (gdbarch, regnum))
3190 return i386_ymm_type (gdbarch);
3191 else if (i386_zmm_regnum_p (gdbarch, regnum))
3192 return i386_zmm_type (gdbarch);
3195 const struct builtin_type *bt = builtin_type (gdbarch);
3196 if (i386_byte_regnum_p (gdbarch, regnum))
3197 return bt->builtin_int8;
3198 else if (i386_word_regnum_p (gdbarch, regnum))
3199 return bt->builtin_int16;
3200 else if (i386_dword_regnum_p (gdbarch, regnum))
3201 return bt->builtin_int32;
3202 else if (i386_k_regnum_p (gdbarch, regnum))
3203 return bt->builtin_int64;
3206 internal_error (__FILE__, __LINE__, _("invalid regnum"));
3209 /* Map a cooked register onto a raw register or memory. For the i386,
3210 the MMX registers need to be mapped onto floating point registers. */
3213 i386_mmx_regnum_to_fp_regnum (struct regcache *regcache, int regnum)
3215 struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache));
3220 mmxreg = regnum - tdep->mm0_regnum;
3221 regcache_raw_read_unsigned (regcache, I387_FSTAT_REGNUM (tdep), &fstat);
3222 tos = (fstat >> 11) & 0x7;
3223 fpreg = (mmxreg + tos) % 8;
3225 return (I387_ST0_REGNUM (tdep) + fpreg);
3228 /* A helper function for us by i386_pseudo_register_read_value and
3229 amd64_pseudo_register_read_value. It does all the work but reads
3230 the data into an already-allocated value. */
3233 i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
3234 struct regcache *regcache,
3236 struct value *result_value)
3238 gdb_byte raw_buf[MAX_REGISTER_SIZE];
3239 enum register_status status;
3240 gdb_byte *buf = value_contents_raw (result_value);
3242 if (i386_mmx_regnum_p (gdbarch, regnum))
3244 int fpnum = i386_mmx_regnum_to_fp_regnum (regcache, regnum);
3246 /* Extract (always little endian). */
3247 status = regcache_raw_read (regcache, fpnum, raw_buf);
3248 if (status != REG_VALID)
3249 mark_value_bytes_unavailable (result_value, 0,
3250 TYPE_LENGTH (value_type (result_value)));
3252 memcpy (buf, raw_buf, register_size (gdbarch, regnum));
3256 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3257 if (i386_bnd_regnum_p (gdbarch, regnum))
3259 regnum -= tdep->bnd0_regnum;
3261 /* Extract (always little endian). Read lower 128bits. */
3262 status = regcache_raw_read (regcache,
3263 I387_BND0R_REGNUM (tdep) + regnum,
3265 if (status != REG_VALID)
3266 mark_value_bytes_unavailable (result_value, 0, 16);
3269 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
3270 LONGEST upper, lower;
3271 int size = TYPE_LENGTH (builtin_type (gdbarch)->builtin_data_ptr);
3273 lower = extract_unsigned_integer (raw_buf, 8, byte_order);
3274 upper = extract_unsigned_integer (raw_buf + 8, 8, byte_order);
3277 memcpy (buf, &lower, size);
3278 memcpy (buf + size, &upper, size);
3281 else if (i386_k_regnum_p (gdbarch, regnum))
3283 regnum -= tdep->k0_regnum;
3285 /* Extract (always little endian). */
3286 status = regcache_raw_read (regcache,
3287 tdep->k0_regnum + regnum,
3289 if (status != REG_VALID)
3290 mark_value_bytes_unavailable (result_value, 0, 8);
3292 memcpy (buf, raw_buf, 8);
3294 else if (i386_zmm_regnum_p (gdbarch, regnum))
3296 regnum -= tdep->zmm0_regnum;
3298 if (regnum < num_lower_zmm_regs)
3300 /* Extract (always little endian). Read lower 128bits. */
3301 status = regcache_raw_read (regcache,
3302 I387_XMM0_REGNUM (tdep) + regnum,
3304 if (status != REG_VALID)
3305 mark_value_bytes_unavailable (result_value, 0, 16);
3307 memcpy (buf, raw_buf, 16);
3309 /* Extract (always little endian). Read upper 128bits. */
3310 status = regcache_raw_read (regcache,
3311 tdep->ymm0h_regnum + regnum,
3313 if (status != REG_VALID)
3314 mark_value_bytes_unavailable (result_value, 16, 16);
3316 memcpy (buf + 16, raw_buf, 16);
3320 /* Extract (always little endian). Read lower 128bits. */
3321 status = regcache_raw_read (regcache,
3322 I387_XMM16_REGNUM (tdep) + regnum
3323 - num_lower_zmm_regs,
3325 if (status != REG_VALID)
3326 mark_value_bytes_unavailable (result_value, 0, 16);
3328 memcpy (buf, raw_buf, 16);
3330 /* Extract (always little endian). Read upper 128bits. */
3331 status = regcache_raw_read (regcache,
3332 I387_YMM16H_REGNUM (tdep) + regnum
3333 - num_lower_zmm_regs,
3335 if (status != REG_VALID)
3336 mark_value_bytes_unavailable (result_value, 16, 16);
3338 memcpy (buf + 16, raw_buf, 16);
3341 /* Read upper 256bits. */
3342 status = regcache_raw_read (regcache,
3343 tdep->zmm0h_regnum + regnum,
3345 if (status != REG_VALID)
3346 mark_value_bytes_unavailable (result_value, 32, 32);
3348 memcpy (buf + 32, raw_buf, 32);
3350 else if (i386_ymm_regnum_p (gdbarch, regnum))
3352 regnum -= tdep->ymm0_regnum;
3354 /* Extract (always little endian). Read lower 128bits. */
3355 status = regcache_raw_read (regcache,
3356 I387_XMM0_REGNUM (tdep) + regnum,
3358 if (status != REG_VALID)
3359 mark_value_bytes_unavailable (result_value, 0, 16);
3361 memcpy (buf, raw_buf, 16);
3362 /* Read upper 128bits. */
3363 status = regcache_raw_read (regcache,
3364 tdep->ymm0h_regnum + regnum,
3366 if (status != REG_VALID)
3367 mark_value_bytes_unavailable (result_value, 16, 32);
3369 memcpy (buf + 16, raw_buf, 16);
3371 else if (i386_ymm_avx512_regnum_p (gdbarch, regnum))
3373 regnum -= tdep->ymm16_regnum;
3374 /* Extract (always little endian). Read lower 128bits. */
3375 status = regcache_raw_read (regcache,
3376 I387_XMM16_REGNUM (tdep) + regnum,
3378 if (status != REG_VALID)
3379 mark_value_bytes_unavailable (result_value, 0, 16);
3381 memcpy (buf, raw_buf, 16);
3382 /* Read upper 128bits. */
3383 status = regcache_raw_read (regcache,
3384 tdep->ymm16h_regnum + regnum,
3386 if (status != REG_VALID)
3387 mark_value_bytes_unavailable (result_value, 16, 16);
3389 memcpy (buf + 16, raw_buf, 16);
3391 else if (i386_word_regnum_p (gdbarch, regnum))
3393 int gpnum = regnum - tdep->ax_regnum;
3395 /* Extract (always little endian). */
3396 status = regcache_raw_read (regcache, gpnum, raw_buf);
3397 if (status != REG_VALID)
3398 mark_value_bytes_unavailable (result_value, 0,
3399 TYPE_LENGTH (value_type (result_value)));
3401 memcpy (buf, raw_buf, 2);
3403 else if (i386_byte_regnum_p (gdbarch, regnum))
3405 /* Check byte pseudo registers last since this function will
3406 be called from amd64_pseudo_register_read, which handles
3407 byte pseudo registers differently. */
3408 int gpnum = regnum - tdep->al_regnum;
3410 /* Extract (always little endian). We read both lower and
3412 status = regcache_raw_read (regcache, gpnum % 4, raw_buf);
3413 if (status != REG_VALID)
3414 mark_value_bytes_unavailable (result_value, 0,
3415 TYPE_LENGTH (value_type (result_value)));
3416 else if (gpnum >= 4)
3417 memcpy (buf, raw_buf + 1, 1);
3419 memcpy (buf, raw_buf, 1);
3422 internal_error (__FILE__, __LINE__, _("invalid regnum"));
3426 static struct value *
3427 i386_pseudo_register_read_value (struct gdbarch *gdbarch,
3428 struct regcache *regcache,
3431 struct value *result;
3433 result = allocate_value (register_type (gdbarch, regnum));
3434 VALUE_LVAL (result) = lval_register;
3435 VALUE_REGNUM (result) = regnum;
3437 i386_pseudo_register_read_into_value (gdbarch, regcache, regnum, result);
3443 i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
3444 int regnum, const gdb_byte *buf)
3446 gdb_byte raw_buf[MAX_REGISTER_SIZE];
3448 if (i386_mmx_regnum_p (gdbarch, regnum))
3450 int fpnum = i386_mmx_regnum_to_fp_regnum (regcache, regnum);
3453 regcache_raw_read (regcache, fpnum, raw_buf);
3454 /* ... Modify ... (always little endian). */
3455 memcpy (raw_buf, buf, register_size (gdbarch, regnum));
3457 regcache_raw_write (regcache, fpnum, raw_buf);
3461 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3463 if (i386_bnd_regnum_p (gdbarch, regnum))
3465 ULONGEST upper, lower;
3466 int size = TYPE_LENGTH (builtin_type (gdbarch)->builtin_data_ptr);
3467 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
3469 /* New values from input value. */
3470 regnum -= tdep->bnd0_regnum;
3471 lower = extract_unsigned_integer (buf, size, byte_order);
3472 upper = extract_unsigned_integer (buf + size, size, byte_order);
3474 /* Fetching register buffer. */
3475 regcache_raw_read (regcache,
3476 I387_BND0R_REGNUM (tdep) + regnum,
3481 /* Set register bits. */
3482 memcpy (raw_buf, &lower, 8);
3483 memcpy (raw_buf + 8, &upper, 8);
3486 regcache_raw_write (regcache,
3487 I387_BND0R_REGNUM (tdep) + regnum,
3490 else if (i386_k_regnum_p (gdbarch, regnum))
3492 regnum -= tdep->k0_regnum;
3494 regcache_raw_write (regcache,
3495 tdep->k0_regnum + regnum,
3498 else if (i386_zmm_regnum_p (gdbarch, regnum))
3500 regnum -= tdep->zmm0_regnum;
3502 if (regnum < num_lower_zmm_regs)
3504 /* Write lower 128bits. */
3505 regcache_raw_write (regcache,
3506 I387_XMM0_REGNUM (tdep) + regnum,
3508 /* Write upper 128bits. */
3509 regcache_raw_write (regcache,
3510 I387_YMM0_REGNUM (tdep) + regnum,
3515 /* Write lower 128bits. */
3516 regcache_raw_write (regcache,
3517 I387_XMM16_REGNUM (tdep) + regnum
3518 - num_lower_zmm_regs,
3520 /* Write upper 128bits. */
3521 regcache_raw_write (regcache,
3522 I387_YMM16H_REGNUM (tdep) + regnum
3523 - num_lower_zmm_regs,
3526 /* Write upper 256bits. */
3527 regcache_raw_write (regcache,
3528 tdep->zmm0h_regnum + regnum,
3531 else if (i386_ymm_regnum_p (gdbarch, regnum))
3533 regnum -= tdep->ymm0_regnum;
3535 /* ... Write lower 128bits. */
3536 regcache_raw_write (regcache,
3537 I387_XMM0_REGNUM (tdep) + regnum,
3539 /* ... Write upper 128bits. */
3540 regcache_raw_write (regcache,
3541 tdep->ymm0h_regnum + regnum,
3544 else if (i386_ymm_avx512_regnum_p (gdbarch, regnum))
3546 regnum -= tdep->ymm16_regnum;
3548 /* ... Write lower 128bits. */
3549 regcache_raw_write (regcache,
3550 I387_XMM16_REGNUM (tdep) + regnum,
3552 /* ... Write upper 128bits. */
3553 regcache_raw_write (regcache,
3554 tdep->ymm16h_regnum + regnum,
3557 else if (i386_word_regnum_p (gdbarch, regnum))
3559 int gpnum = regnum - tdep->ax_regnum;
3562 regcache_raw_read (regcache, gpnum, raw_buf);
3563 /* ... Modify ... (always little endian). */
3564 memcpy (raw_buf, buf, 2);
3566 regcache_raw_write (regcache, gpnum, raw_buf);
3568 else if (i386_byte_regnum_p (gdbarch, regnum))
3570 /* Check byte pseudo registers last since this function will
3571 be called from amd64_pseudo_register_read, which handles
3572 byte pseudo registers differently. */
3573 int gpnum = regnum - tdep->al_regnum;
3575 /* Read ... We read both lower and upper registers. */
3576 regcache_raw_read (regcache, gpnum % 4, raw_buf);
3577 /* ... Modify ... (always little endian). */
3579 memcpy (raw_buf + 1, buf, 1);
3581 memcpy (raw_buf, buf, 1);
3583 regcache_raw_write (regcache, gpnum % 4, raw_buf);
3586 internal_error (__FILE__, __LINE__, _("invalid regnum"));
3591 /* Return the register number of the register allocated by GCC after
3592 REGNUM, or -1 if there is no such register. */
3595 i386_next_regnum (int regnum)
3597 /* GCC allocates the registers in the order:
3599 %eax, %edx, %ecx, %ebx, %esi, %edi, %ebp, %esp, ...
3601 Since storing a variable in %esp doesn't make any sense we return
3602 -1 for %ebp and for %esp itself. */
3603 static int next_regnum[] =
3605 I386_EDX_REGNUM, /* Slot for %eax. */
3606 I386_EBX_REGNUM, /* Slot for %ecx. */
3607 I386_ECX_REGNUM, /* Slot for %edx. */
3608 I386_ESI_REGNUM, /* Slot for %ebx. */
3609 -1, -1, /* Slots for %esp and %ebp. */
3610 I386_EDI_REGNUM, /* Slot for %esi. */
3611 I386_EBP_REGNUM /* Slot for %edi. */
3614 if (regnum >= 0 && regnum < sizeof (next_regnum) / sizeof (next_regnum[0]))
3615 return next_regnum[regnum];
3620 /* Return nonzero if a value of type TYPE stored in register REGNUM
3621 needs any special handling. */
3624 i386_convert_register_p (struct gdbarch *gdbarch,
3625 int regnum, struct type *type)
3627 int len = TYPE_LENGTH (type);
3629 /* Values may be spread across multiple registers. Most debugging
3630 formats aren't expressive enough to specify the locations, so
3631 some heuristics is involved. Right now we only handle types that
3632 have a length that is a multiple of the word size, since GCC
3633 doesn't seem to put any other types into registers. */
3634 if (len > 4 && len % 4 == 0)
3636 int last_regnum = regnum;
3640 last_regnum = i386_next_regnum (last_regnum);
3644 if (last_regnum != -1)
3648 return i387_convert_register_p (gdbarch, regnum, type);
3651 /* Read a value of type TYPE from register REGNUM in frame FRAME, and
3652 return its contents in TO. */
3655 i386_register_to_value (struct frame_info *frame, int regnum,
3656 struct type *type, gdb_byte *to,
3657 int *optimizedp, int *unavailablep)
3659 struct gdbarch *gdbarch = get_frame_arch (frame);
3660 int len = TYPE_LENGTH (type);
3662 if (i386_fp_regnum_p (gdbarch, regnum))
3663 return i387_register_to_value (frame, regnum, type, to,
3664 optimizedp, unavailablep);
3666 /* Read a value spread across multiple registers. */
3668 gdb_assert (len > 4 && len % 4 == 0);
3672 gdb_assert (regnum != -1);
3673 gdb_assert (register_size (gdbarch, regnum) == 4);
3675 if (!get_frame_register_bytes (frame, regnum, 0,
3676 register_size (gdbarch, regnum),
3677 to, optimizedp, unavailablep))
3680 regnum = i386_next_regnum (regnum);
3685 *optimizedp = *unavailablep = 0;
3689 /* Write the contents FROM of a value of type TYPE into register
3690 REGNUM in frame FRAME. */
3693 i386_value_to_register (struct frame_info *frame, int regnum,
3694 struct type *type, const gdb_byte *from)
3696 int len = TYPE_LENGTH (type);
3698 if (i386_fp_regnum_p (get_frame_arch (frame), regnum))
3700 i387_value_to_register (frame, regnum, type, from);
3704 /* Write a value spread across multiple registers. */
3706 gdb_assert (len > 4 && len % 4 == 0);
3710 gdb_assert (regnum != -1);
3711 gdb_assert (register_size (get_frame_arch (frame), regnum) == 4);
3713 put_frame_register (frame, regnum, from);
3714 regnum = i386_next_regnum (regnum);
3720 /* Supply register REGNUM from the buffer specified by GREGS and LEN
3721 in the general-purpose register set REGSET to register cache
3722 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
3725 i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
3726 int regnum, const void *gregs, size_t len)
3728 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3729 const struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3730 const gdb_byte *regs = gregs;
3733 gdb_assert (len == tdep->sizeof_gregset);
3735 for (i = 0; i < tdep->gregset_num_regs; i++)
3737 if ((regnum == i || regnum == -1)
3738 && tdep->gregset_reg_offset[i] != -1)
3739 regcache_raw_supply (regcache, i, regs + tdep->gregset_reg_offset[i]);
3743 /* Collect register REGNUM from the register cache REGCACHE and store
3744 it in the buffer specified by GREGS and LEN as described by the
3745 general-purpose register set REGSET. If REGNUM is -1, do this for
3746 all registers in REGSET. */
3749 i386_collect_gregset (const struct regset *regset,
3750 const struct regcache *regcache,
3751 int regnum, void *gregs, size_t len)
3753 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3754 const struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3755 gdb_byte *regs = gregs;
3758 gdb_assert (len == tdep->sizeof_gregset);
3760 for (i = 0; i < tdep->gregset_num_regs; i++)
3762 if ((regnum == i || regnum == -1)
3763 && tdep->gregset_reg_offset[i] != -1)
3764 regcache_raw_collect (regcache, i, regs + tdep->gregset_reg_offset[i]);
3768 /* Supply register REGNUM from the buffer specified by FPREGS and LEN
3769 in the floating-point register set REGSET to register cache
3770 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
3773 i386_supply_fpregset (const struct regset *regset, struct regcache *regcache,
3774 int regnum, const void *fpregs, size_t len)
3776 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3777 const struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3779 if (len == I387_SIZEOF_FXSAVE)
3781 i387_supply_fxsave (regcache, regnum, fpregs);
3785 gdb_assert (len == tdep->sizeof_fpregset);
3786 i387_supply_fsave (regcache, regnum, fpregs);
3789 /* Collect register REGNUM from the register cache REGCACHE and store
3790 it in the buffer specified by FPREGS and LEN as described by the
3791 floating-point register set REGSET. If REGNUM is -1, do this for
3792 all registers in REGSET. */
3795 i386_collect_fpregset (const struct regset *regset,
3796 const struct regcache *regcache,
3797 int regnum, void *fpregs, size_t len)
3799 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3800 const struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3802 if (len == I387_SIZEOF_FXSAVE)
3804 i387_collect_fxsave (regcache, regnum, fpregs);
3808 gdb_assert (len == tdep->sizeof_fpregset);
3809 i387_collect_fsave (regcache, regnum, fpregs);
3812 /* Similar to i386_supply_fpregset, but use XSAVE extended state. */
3815 i386_supply_xstateregset (const struct regset *regset,
3816 struct regcache *regcache, int regnum,
3817 const void *xstateregs, size_t len)
3819 i387_supply_xsave (regcache, regnum, xstateregs);
3822 /* Similar to i386_collect_fpregset , but use XSAVE extended state. */
3825 i386_collect_xstateregset (const struct regset *regset,
3826 const struct regcache *regcache,
3827 int regnum, void *xstateregs, size_t len)
3829 i387_collect_xsave (regcache, regnum, xstateregs, 1);
3832 /* Register set definitions. */
3834 const struct regset i386_gregset =
3836 NULL, i386_supply_gregset, i386_collect_gregset
3839 static const struct regset i386_fpregset =
3841 NULL, i386_supply_fpregset, i386_collect_fpregset
3844 static const struct regset i386_xstateregset =
3846 NULL, i386_supply_xstateregset, i386_collect_xstateregset
3849 /* Return the appropriate register set for the core section identified
3850 by SECT_NAME and SECT_SIZE. */
3852 const struct regset *
3853 i386_regset_from_core_section (struct gdbarch *gdbarch,
3854 const char *sect_name, size_t sect_size)
3856 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3858 if (strcmp (sect_name, ".reg") == 0 && sect_size == tdep->sizeof_gregset)
3859 return &i386_gregset;
3861 if ((strcmp (sect_name, ".reg2") == 0 && sect_size == tdep->sizeof_fpregset)
3862 || (strcmp (sect_name, ".reg-xfp") == 0
3863 && sect_size == I387_SIZEOF_FXSAVE))
3864 return &i386_fpregset;
3866 if (strcmp (sect_name, ".reg-xstate") == 0)
3867 return &i386_xstateregset;
3873 /* Stuff for WIN32 PE style DLL's but is pretty generic really. */
3876 i386_pe_skip_trampoline_code (struct frame_info *frame,
3877 CORE_ADDR pc, char *name)
3879 struct gdbarch *gdbarch = get_frame_arch (frame);
3880 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3883 if (pc && read_memory_unsigned_integer (pc, 2, byte_order) == 0x25ff)
3885 unsigned long indirect =
3886 read_memory_unsigned_integer (pc + 2, 4, byte_order);
3887 struct minimal_symbol *indsym =
3888 indirect ? lookup_minimal_symbol_by_pc (indirect).minsym : 0;
3889 const char *symname = indsym ? MSYMBOL_LINKAGE_NAME (indsym) : 0;
3893 if (strncmp (symname, "__imp_", 6) == 0
3894 || strncmp (symname, "_imp_", 5) == 0)
3896 read_memory_unsigned_integer (indirect, 4, byte_order);
3899 return 0; /* Not a trampoline. */
3903 /* Return whether the THIS_FRAME corresponds to a sigtramp
3907 i386_sigtramp_p (struct frame_info *this_frame)
3909 CORE_ADDR pc = get_frame_pc (this_frame);
3912 find_pc_partial_function (pc, &name, NULL, NULL);
3913 return (name && strcmp ("_sigtramp", name) == 0);
3917 /* We have two flavours of disassembly. The machinery on this page
3918 deals with switching between those. */
3921 i386_print_insn (bfd_vma pc, struct disassemble_info *info)
3923 gdb_assert (disassembly_flavor == att_flavor
3924 || disassembly_flavor == intel_flavor);
3926 /* FIXME: kettenis/20020915: Until disassembler_options is properly
3927 constified, cast to prevent a compiler warning. */
3928 info->disassembler_options = (char *) disassembly_flavor;
3930 return print_insn_i386 (pc, info);
3934 /* There are a few i386 architecture variants that differ only
3935 slightly from the generic i386 target. For now, we don't give them
3936 their own source file, but include them here. As a consequence,
3937 they'll always be included. */
3939 /* System V Release 4 (SVR4). */
3941 /* Return whether THIS_FRAME corresponds to a SVR4 sigtramp
3945 i386_svr4_sigtramp_p (struct frame_info *this_frame)
3947 CORE_ADDR pc = get_frame_pc (this_frame);
3950 /* The origin of these symbols is currently unknown. */
3951 find_pc_partial_function (pc, &name, NULL, NULL);
3952 return (name && (strcmp ("_sigreturn", name) == 0
3953 || strcmp ("sigvechandler", name) == 0));
3956 /* Assuming THIS_FRAME is for a SVR4 sigtramp routine, return the
3957 address of the associated sigcontext (ucontext) structure. */
3960 i386_svr4_sigcontext_addr (struct frame_info *this_frame)
3962 struct gdbarch *gdbarch = get_frame_arch (this_frame);
3963 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3967 get_frame_register (this_frame, I386_ESP_REGNUM, buf);
3968 sp = extract_unsigned_integer (buf, 4, byte_order);
3970 return read_memory_unsigned_integer (sp + 8, 4, byte_order);
3975 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
3979 i386_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
3981 return (*s == '$' /* Literal number. */
3982 || (isdigit (*s) && s[1] == '(' && s[2] == '%') /* Displacement. */
3983 || (*s == '(' && s[1] == '%') /* Register indirection. */
3984 || (*s == '%' && isalpha (s[1]))); /* Register access. */
3987 /* Helper function for i386_stap_parse_special_token.
3989 This function parses operands of the form `-8+3+1(%rbp)', which
3990 must be interpreted as `*(-8 + 3 - 1 + (void *) $eax)'.
3992 Return 1 if the operand was parsed successfully, zero
3996 i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
3997 struct stap_parse_info *p)
3999 const char *s = p->arg;
4001 if (isdigit (*s) || *s == '-' || *s == '+')
4005 long displacements[3];
4021 if (!isdigit ((unsigned char) *s))
4024 displacements[0] = strtol (s, &endp, 10);
4027 if (*s != '+' && *s != '-')
4029 /* We are not dealing with a triplet. */
4042 if (!isdigit ((unsigned char) *s))
4045 displacements[1] = strtol (s, &endp, 10);
4048 if (*s != '+' && *s != '-')
4050 /* We are not dealing with a triplet. */
4063 if (!isdigit ((unsigned char) *s))
4066 displacements[2] = strtol (s, &endp, 10);
4069 if (*s != '(' || s[1] != '%')
4075 while (isalnum (*s))
4081 len = s - start - 1;
4082 regname = alloca (len + 1);
4084 strncpy (regname, start, len);
4085 regname[len] = '\0';
4087 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
4088 error (_("Invalid register name `%s' on expression `%s'."),
4089 regname, p->saved_arg);
4091 for (i = 0; i < 3; i++)
4093 write_exp_elt_opcode (&p->pstate, OP_LONG);
4095 (&p->pstate, builtin_type (gdbarch)->builtin_long);
4096 write_exp_elt_longcst (&p->pstate, displacements[i]);
4097 write_exp_elt_opcode (&p->pstate, OP_LONG);
4099 write_exp_elt_opcode (&p->pstate, UNOP_NEG);
4102 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
4105 write_exp_string (&p->pstate, str);
4106 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
4108 write_exp_elt_opcode (&p->pstate, UNOP_CAST);
4109 write_exp_elt_type (&p->pstate,
4110 builtin_type (gdbarch)->builtin_data_ptr);
4111 write_exp_elt_opcode (&p->pstate, UNOP_CAST);
4113 write_exp_elt_opcode (&p->pstate, BINOP_ADD);
4114 write_exp_elt_opcode (&p->pstate, BINOP_ADD);
4115 write_exp_elt_opcode (&p->pstate, BINOP_ADD);
4117 write_exp_elt_opcode (&p->pstate, UNOP_CAST);
4118 write_exp_elt_type (&p->pstate,
4119 lookup_pointer_type (p->arg_type));
4120 write_exp_elt_opcode (&p->pstate, UNOP_CAST);
4122 write_exp_elt_opcode (&p->pstate, UNOP_IND);
4132 /* Helper function for i386_stap_parse_special_token.
4134 This function parses operands of the form `register base +
4135 (register index * size) + offset', as represented in
4136 `(%rcx,%rax,8)', or `[OFFSET](BASE_REG,INDEX_REG[,SIZE])'.
4138 Return 1 if the operand was parsed successfully, zero
4142 i386_stap_parse_special_token_three_arg_disp (struct gdbarch *gdbarch,
4143 struct stap_parse_info *p)
4145 const char *s = p->arg;
4147 if (isdigit (*s) || *s == '(' || *s == '-' || *s == '+')
4149 int offset_minus = 0;
4158 struct stoken base_token, index_token;
4168 if (offset_minus && !isdigit (*s))
4175 offset = strtol (s, &endp, 10);
4179 if (*s != '(' || s[1] != '%')
4185 while (isalnum (*s))
4188 if (*s != ',' || s[1] != '%')
4191 len_base = s - start;
4192 base = alloca (len_base + 1);
4193 strncpy (base, start, len_base);
4194 base[len_base] = '\0';
4196 if (user_reg_map_name_to_regnum (gdbarch, base, len_base) == -1)
4197 error (_("Invalid register name `%s' on expression `%s'."),
4198 base, p->saved_arg);
4203 while (isalnum (*s))
4206 len_index = s - start;
4207 index = alloca (len_index + 1);
4208 strncpy (index, start, len_index);
4209 index[len_index] = '\0';
4211 if (user_reg_map_name_to_regnum (gdbarch, index, len_index) == -1)
4212 error (_("Invalid register name `%s' on expression `%s'."),
4213 index, p->saved_arg);
4215 if (*s != ',' && *s != ')')
4231 size = strtol (s, &endp, 10);
4242 write_exp_elt_opcode (&p->pstate, OP_LONG);
4243 write_exp_elt_type (&p->pstate,
4244 builtin_type (gdbarch)->builtin_long);
4245 write_exp_elt_longcst (&p->pstate, offset);
4246 write_exp_elt_opcode (&p->pstate, OP_LONG);
4248 write_exp_elt_opcode (&p->pstate, UNOP_NEG);
4251 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
4252 base_token.ptr = base;
4253 base_token.length = len_base;
4254 write_exp_string (&p->pstate, base_token);
4255 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
4258 write_exp_elt_opcode (&p->pstate, BINOP_ADD);
4260 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
4261 index_token.ptr = index;
4262 index_token.length = len_index;
4263 write_exp_string (&p->pstate, index_token);
4264 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
4268 write_exp_elt_opcode (&p->pstate, OP_LONG);
4269 write_exp_elt_type (&p->pstate,
4270 builtin_type (gdbarch)->builtin_long);
4271 write_exp_elt_longcst (&p->pstate, size);
4272 write_exp_elt_opcode (&p->pstate, OP_LONG);
4274 write_exp_elt_opcode (&p->pstate, UNOP_NEG);
4275 write_exp_elt_opcode (&p->pstate, BINOP_MUL);
4278 write_exp_elt_opcode (&p->pstate, BINOP_ADD);
4280 write_exp_elt_opcode (&p->pstate, UNOP_CAST);
4281 write_exp_elt_type (&p->pstate,
4282 lookup_pointer_type (p->arg_type));
4283 write_exp_elt_opcode (&p->pstate, UNOP_CAST);
4285 write_exp_elt_opcode (&p->pstate, UNOP_IND);
4295 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
4299 i386_stap_parse_special_token (struct gdbarch *gdbarch,
4300 struct stap_parse_info *p)
4302 /* In order to parse special tokens, we use a state-machine that go
4303 through every known token and try to get a match. */
4307 THREE_ARG_DISPLACEMENT,
4311 current_state = TRIPLET;
4313 /* The special tokens to be parsed here are:
4315 - `register base + (register index * size) + offset', as represented
4316 in `(%rcx,%rax,8)', or `[OFFSET](BASE_REG,INDEX_REG[,SIZE])'.
4318 - Operands of the form `-8+3+1(%rbp)', which must be interpreted as
4319 `*(-8 + 3 - 1 + (void *) $eax)'. */
4321 while (current_state != DONE)
4323 switch (current_state)
4326 if (i386_stap_parse_special_token_triplet (gdbarch, p))
4330 case THREE_ARG_DISPLACEMENT:
4331 if (i386_stap_parse_special_token_three_arg_disp (gdbarch, p))
4336 /* Advancing to the next state. */
4348 i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
4350 static const char *const stap_integer_prefixes[] = { "$", NULL };
4351 static const char *const stap_register_prefixes[] = { "%", NULL };
4352 static const char *const stap_register_indirection_prefixes[] = { "(",
4354 static const char *const stap_register_indirection_suffixes[] = { ")",
4357 /* We typically use stabs-in-ELF with the SVR4 register numbering. */
4358 set_gdbarch_stab_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);
4360 /* Registering SystemTap handlers. */
4361 set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
4362 set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
4363 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
4364 stap_register_indirection_prefixes);
4365 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
4366 stap_register_indirection_suffixes);
4367 set_gdbarch_stap_is_single_operand (gdbarch,
4368 i386_stap_is_single_operand);
4369 set_gdbarch_stap_parse_special_token (gdbarch,
4370 i386_stap_parse_special_token);
4373 /* System V Release 4 (SVR4). */
4376 i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
4378 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4380 /* System V Release 4 uses ELF. */
4381 i386_elf_init_abi (info, gdbarch);
4383 /* System V Release 4 has shared libraries. */
4384 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
4386 tdep->sigtramp_p = i386_svr4_sigtramp_p;
4387 tdep->sigcontext_addr = i386_svr4_sigcontext_addr;
4388 tdep->sc_pc_offset = 36 + 14 * 4;
4389 tdep->sc_sp_offset = 36 + 17 * 4;
4391 tdep->jb_pc_offset = 20;
4397 i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
4399 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4401 /* DJGPP doesn't have any special frames for signal handlers. */
4402 tdep->sigtramp_p = NULL;
4404 tdep->jb_pc_offset = 36;
4406 /* DJGPP does not support the SSE registers. */
4407 if (! tdesc_has_registers (info.target_desc))
4408 tdep->tdesc = tdesc_i386_mmx;
4410 /* Native compiler is GCC, which uses the SVR4 register numbering
4411 even in COFF and STABS. See the comment in i386_gdbarch_init,
4412 before the calls to set_gdbarch_stab_reg_to_regnum and
4413 set_gdbarch_sdb_reg_to_regnum. */
4414 set_gdbarch_stab_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);
4415 set_gdbarch_sdb_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);
4417 set_gdbarch_has_dos_based_file_system (gdbarch, 1);
4421 /* i386 register groups. In addition to the normal groups, add "mmx"
4424 static struct reggroup *i386_sse_reggroup;
4425 static struct reggroup *i386_mmx_reggroup;
4428 i386_init_reggroups (void)
4430 i386_sse_reggroup = reggroup_new ("sse", USER_REGGROUP);
4431 i386_mmx_reggroup = reggroup_new ("mmx", USER_REGGROUP);
4435 i386_add_reggroups (struct gdbarch *gdbarch)
4437 reggroup_add (gdbarch, i386_sse_reggroup);
4438 reggroup_add (gdbarch, i386_mmx_reggroup);
4439 reggroup_add (gdbarch, general_reggroup);
4440 reggroup_add (gdbarch, float_reggroup);
4441 reggroup_add (gdbarch, all_reggroup);
4442 reggroup_add (gdbarch, save_reggroup);
4443 reggroup_add (gdbarch, restore_reggroup);
4444 reggroup_add (gdbarch, vector_reggroup);
4445 reggroup_add (gdbarch, system_reggroup);
4449 i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
4450 struct reggroup *group)
4452 const struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4453 int fp_regnum_p, mmx_regnum_p, xmm_regnum_p, mxcsr_regnum_p,
4454 ymm_regnum_p, ymmh_regnum_p, ymm_avx512_regnum_p, ymmh_avx512_regnum_p,
4455 bndr_regnum_p, bnd_regnum_p, k_regnum_p, zmm_regnum_p, zmmh_regnum_p,
4456 zmm_avx512_regnum_p, mpx_ctrl_regnum_p, xmm_avx512_regnum_p,
4457 avx512_p, avx_p, sse_p;
4459 /* Don't include pseudo registers, except for MMX, in any register
4461 if (i386_byte_regnum_p (gdbarch, regnum))
4464 if (i386_word_regnum_p (gdbarch, regnum))
4467 if (i386_dword_regnum_p (gdbarch, regnum))
4470 mmx_regnum_p = i386_mmx_regnum_p (gdbarch, regnum);
4471 if (group == i386_mmx_reggroup)
4472 return mmx_regnum_p;
4474 xmm_regnum_p = i386_xmm_regnum_p (gdbarch, regnum);
4475 xmm_avx512_regnum_p = i386_xmm_avx512_regnum_p (gdbarch, regnum);
4476 mxcsr_regnum_p = i386_mxcsr_regnum_p (gdbarch, regnum);
4477 if (group == i386_sse_reggroup)
4478 return xmm_regnum_p || xmm_avx512_regnum_p || mxcsr_regnum_p;
4480 ymm_regnum_p = i386_ymm_regnum_p (gdbarch, regnum);
4481 ymm_avx512_regnum_p = i386_ymm_avx512_regnum_p (gdbarch, regnum);
4482 zmm_regnum_p = i386_zmm_regnum_p (gdbarch, regnum);
4484 avx512_p = ((tdep->xcr0 & I386_XSTATE_AVX512_MASK)
4485 == I386_XSTATE_AVX512_MASK);
4486 avx_p = ((tdep->xcr0 & I386_XSTATE_AVX512_MASK)
4487 == I386_XSTATE_AVX_MASK) && !avx512_p;
4488 sse_p = ((tdep->xcr0 & I386_XSTATE_AVX512_MASK)
4489 == I386_XSTATE_SSE_MASK) && !avx512_p && ! avx_p;
4491 if (group == vector_reggroup)
4492 return (mmx_regnum_p
4493 || (zmm_regnum_p && avx512_p)
4494 || ((ymm_regnum_p || ymm_avx512_regnum_p) && avx_p)
4495 || ((xmm_regnum_p || xmm_avx512_regnum_p) && sse_p)
4498 fp_regnum_p = (i386_fp_regnum_p (gdbarch, regnum)
4499 || i386_fpc_regnum_p (gdbarch, regnum));
4500 if (group == float_reggroup)
4503 /* For "info reg all", don't include upper YMM registers nor XMM
4504 registers when AVX is supported. */
4505 ymmh_regnum_p = i386_ymmh_regnum_p (gdbarch, regnum);
4506 ymmh_avx512_regnum_p = i386_ymmh_avx512_regnum_p (gdbarch, regnum);
4507 zmmh_regnum_p = i386_zmmh_regnum_p (gdbarch, regnum);
4508 if (group == all_reggroup
4509 && (((xmm_regnum_p || xmm_avx512_regnum_p) && !sse_p)
4510 || ((ymm_regnum_p || ymm_avx512_regnum_p) && !avx_p)
4512 || ymmh_avx512_regnum_p
4516 bnd_regnum_p = i386_bnd_regnum_p (gdbarch, regnum);
4517 if (group == all_reggroup
4518 && ((bnd_regnum_p && (tdep->xcr0 & I386_XSTATE_MPX_MASK))))
4519 return bnd_regnum_p;
4521 bndr_regnum_p = i386_bndr_regnum_p (gdbarch, regnum);
4522 if (group == all_reggroup
4523 && ((bndr_regnum_p && (tdep->xcr0 & I386_XSTATE_MPX_MASK))))
4526 mpx_ctrl_regnum_p = i386_mpx_ctrl_regnum_p (gdbarch, regnum);
4527 if (group == all_reggroup
4528 && ((mpx_ctrl_regnum_p && (tdep->xcr0 & I386_XSTATE_MPX_MASK))))
4529 return mpx_ctrl_regnum_p;
4531 if (group == general_reggroup)
4532 return (!fp_regnum_p
4536 && !xmm_avx512_regnum_p
4539 && !ymm_avx512_regnum_p
4540 && !ymmh_avx512_regnum_p
4543 && !mpx_ctrl_regnum_p
4547 return default_register_reggroup_p (gdbarch, regnum, group);
4551 /* Get the ARGIth function argument for the current function. */
4554 i386_fetch_pointer_argument (struct frame_info *frame, int argi,
4557 struct gdbarch *gdbarch = get_frame_arch (frame);
4558 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4559 CORE_ADDR sp = get_frame_register_unsigned (frame, I386_ESP_REGNUM);
4560 return read_memory_unsigned_integer (sp + (4 * (argi + 1)), 4, byte_order);
4564 i386_skip_permanent_breakpoint (struct regcache *regcache)
4566 CORE_ADDR current_pc = regcache_read_pc (regcache);
4568 /* On i386, breakpoint is exactly 1 byte long, so we just
4569 adjust the PC in the regcache. */
4571 regcache_write_pc (regcache, current_pc);
4575 #define PREFIX_REPZ 0x01
4576 #define PREFIX_REPNZ 0x02
4577 #define PREFIX_LOCK 0x04
4578 #define PREFIX_DATA 0x08
4579 #define PREFIX_ADDR 0x10
4591 /* i386 arith/logic operations */
4604 struct i386_record_s
4606 struct gdbarch *gdbarch;
4607 struct regcache *regcache;
4608 CORE_ADDR orig_addr;
4614 uint8_t mod, reg, rm;
4623 /* Parse the "modrm" part of the memory address irp->addr points at.
4624 Returns -1 if something goes wrong, 0 otherwise. */
4627 i386_record_modrm (struct i386_record_s *irp)
4629 struct gdbarch *gdbarch = irp->gdbarch;
4631 if (record_read_memory (gdbarch, irp->addr, &irp->modrm, 1))
4635 irp->mod = (irp->modrm >> 6) & 3;
4636 irp->reg = (irp->modrm >> 3) & 7;
4637 irp->rm = irp->modrm & 7;
4642 /* Extract the memory address that the current instruction writes to,
4643 and return it in *ADDR. Return -1 if something goes wrong. */
4646 i386_record_lea_modrm_addr (struct i386_record_s *irp, uint64_t *addr)
4648 struct gdbarch *gdbarch = irp->gdbarch;
4649 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4654 if (irp->aflag || irp->regmap[X86_RECORD_R8_REGNUM])
4661 uint8_t base = irp->rm;
4666 if (record_read_memory (gdbarch, irp->addr, &byte, 1))
4669 scale = (byte >> 6) & 3;
4670 index = ((byte >> 3) & 7) | irp->rex_x;
4678 if ((base & 7) == 5)
4681 if (record_read_memory (gdbarch, irp->addr, buf, 4))
4684 *addr = extract_signed_integer (buf, 4, byte_order);
4685 if (irp->regmap[X86_RECORD_R8_REGNUM] && !havesib)
4686 *addr += irp->addr + irp->rip_offset;
4690 if (record_read_memory (gdbarch, irp->addr, buf, 1))
4693 *addr = (int8_t) buf[0];
4696 if (record_read_memory (gdbarch, irp->addr, buf, 4))
4698 *addr = extract_signed_integer (buf, 4, byte_order);
4706 if (base == 4 && irp->popl_esp_hack)
4707 *addr += irp->popl_esp_hack;
4708 regcache_raw_read_unsigned (irp->regcache, irp->regmap[base],
4711 if (irp->aflag == 2)
4716 *addr = (uint32_t) (offset64 + *addr);
4718 if (havesib && (index != 4 || scale != 0))
4720 regcache_raw_read_unsigned (irp->regcache, irp->regmap[index],
4722 if (irp->aflag == 2)
4723 *addr += offset64 << scale;
4725 *addr = (uint32_t) (*addr + (offset64 << scale));
4730 /* Since we are in 64-bit mode with ADDR32 prefix, zero-extend
4731 address from 32-bit to 64-bit. */
4732 *addr = (uint32_t) *addr;
4743 if (record_read_memory (gdbarch, irp->addr, buf, 2))
4746 *addr = extract_signed_integer (buf, 2, byte_order);
4752 if (record_read_memory (gdbarch, irp->addr, buf, 1))
4755 *addr = (int8_t) buf[0];
4758 if (record_read_memory (gdbarch, irp->addr, buf, 2))
4761 *addr = extract_signed_integer (buf, 2, byte_order);
4768 regcache_raw_read_unsigned (irp->regcache,
4769 irp->regmap[X86_RECORD_REBX_REGNUM],
4771 *addr = (uint32_t) (*addr + offset64);
4772 regcache_raw_read_unsigned (irp->regcache,
4773 irp->regmap[X86_RECORD_RESI_REGNUM],
4775 *addr = (uint32_t) (*addr + offset64);
4778 regcache_raw_read_unsigned (irp->regcache,
4779 irp->regmap[X86_RECORD_REBX_REGNUM],
4781 *addr = (uint32_t) (*addr + offset64);
4782 regcache_raw_read_unsigned (irp->regcache,
4783 irp->regmap[X86_RECORD_REDI_REGNUM],
4785 *addr = (uint32_t) (*addr + offset64);
4788 regcache_raw_read_unsigned (irp->regcache,
4789 irp->regmap[X86_RECORD_REBP_REGNUM],
4791 *addr = (uint32_t) (*addr + offset64);
4792 regcache_raw_read_unsigned (irp->regcache,
4793 irp->regmap[X86_RECORD_RESI_REGNUM],
4795 *addr = (uint32_t) (*addr + offset64);
4798 regcache_raw_read_unsigned (irp->regcache,
4799 irp->regmap[X86_RECORD_REBP_REGNUM],
4801 *addr = (uint32_t) (*addr + offset64);
4802 regcache_raw_read_unsigned (irp->regcache,
4803 irp->regmap[X86_RECORD_REDI_REGNUM],
4805 *addr = (uint32_t) (*addr + offset64);
4808 regcache_raw_read_unsigned (irp->regcache,
4809 irp->regmap[X86_RECORD_RESI_REGNUM],
4811 *addr = (uint32_t) (*addr + offset64);
4814 regcache_raw_read_unsigned (irp->regcache,
4815 irp->regmap[X86_RECORD_REDI_REGNUM],
4817 *addr = (uint32_t) (*addr + offset64);
4820 regcache_raw_read_unsigned (irp->regcache,
4821 irp->regmap[X86_RECORD_REBP_REGNUM],
4823 *addr = (uint32_t) (*addr + offset64);
4826 regcache_raw_read_unsigned (irp->regcache,
4827 irp->regmap[X86_RECORD_REBX_REGNUM],
4829 *addr = (uint32_t) (*addr + offset64);
4839 /* Record the address and contents of the memory that will be changed
4840 by the current instruction. Return -1 if something goes wrong, 0
4844 i386_record_lea_modrm (struct i386_record_s *irp)
4846 struct gdbarch *gdbarch = irp->gdbarch;
4849 if (irp->override >= 0)
4851 if (record_full_memory_query)
4855 target_terminal_ours ();
4857 Process record ignores the memory change of instruction at address %s\n\
4858 because it can't get the value of the segment register.\n\
4859 Do you want to stop the program?"),
4860 paddress (gdbarch, irp->orig_addr));
4861 target_terminal_inferior ();
4869 if (i386_record_lea_modrm_addr (irp, &addr))
4872 if (record_full_arch_list_add_mem (addr, 1 << irp->ot))
4878 /* Record the effects of a push operation. Return -1 if something
4879 goes wrong, 0 otherwise. */
4882 i386_record_push (struct i386_record_s *irp, int size)
4886 if (record_full_arch_list_add_reg (irp->regcache,
4887 irp->regmap[X86_RECORD_RESP_REGNUM]))
4889 regcache_raw_read_unsigned (irp->regcache,
4890 irp->regmap[X86_RECORD_RESP_REGNUM],
4892 if (record_full_arch_list_add_mem ((CORE_ADDR) addr - size, size))
4899 /* Defines contents to record. */
4900 #define I386_SAVE_FPU_REGS 0xfffd
4901 #define I386_SAVE_FPU_ENV 0xfffe
4902 #define I386_SAVE_FPU_ENV_REG_STACK 0xffff
4904 /* Record the values of the floating point registers which will be
4905 changed by the current instruction. Returns -1 if something is
4906 wrong, 0 otherwise. */
4908 static int i386_record_floats (struct gdbarch *gdbarch,
4909 struct i386_record_s *ir,
4912 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4915 /* Oza: Because of floating point insn push/pop of fpu stack is going to
4916 happen. Currently we store st0-st7 registers, but we need not store all
4917 registers all the time, in future we use ftag register and record only
4918 those who are not marked as an empty. */
4920 if (I386_SAVE_FPU_REGS == iregnum)
4922 for (i = I387_ST0_REGNUM (tdep); i <= I387_ST0_REGNUM (tdep) + 7; i++)
4924 if (record_full_arch_list_add_reg (ir->regcache, i))
4928 else if (I386_SAVE_FPU_ENV == iregnum)
4930 for (i = I387_FCTRL_REGNUM (tdep); i <= I387_FOP_REGNUM (tdep); i++)
4932 if (record_full_arch_list_add_reg (ir->regcache, i))
4936 else if (I386_SAVE_FPU_ENV_REG_STACK == iregnum)
4938 for (i = I387_ST0_REGNUM (tdep); i <= I387_FOP_REGNUM (tdep); i++)
4940 if (record_full_arch_list_add_reg (ir->regcache, i))
4944 else if ((iregnum >= I387_ST0_REGNUM (tdep)) &&
4945 (iregnum <= I387_FOP_REGNUM (tdep)))
4947 if (record_full_arch_list_add_reg (ir->regcache,iregnum))
4952 /* Parameter error. */
4955 if(I386_SAVE_FPU_ENV != iregnum)
4957 for (i = I387_FCTRL_REGNUM (tdep); i <= I387_FOP_REGNUM (tdep); i++)
4959 if (record_full_arch_list_add_reg (ir->regcache, i))
4966 /* Parse the current instruction, and record the values of the
4967 registers and memory that will be changed by the current
4968 instruction. Returns -1 if something goes wrong, 0 otherwise. */
4970 #define I386_RECORD_FULL_ARCH_LIST_ADD_REG(regnum) \
4971 record_full_arch_list_add_reg (ir.regcache, ir.regmap[(regnum)])
4974 i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
4975 CORE_ADDR input_addr)
4977 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4983 gdb_byte buf[MAX_REGISTER_SIZE];
4984 struct i386_record_s ir;
4985 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
4989 memset (&ir, 0, sizeof (struct i386_record_s));
4990 ir.regcache = regcache;
4991 ir.addr = input_addr;
4992 ir.orig_addr = input_addr;
4996 ir.popl_esp_hack = 0;
4997 ir.regmap = tdep->record_regmap;
4998 ir.gdbarch = gdbarch;
5000 if (record_debug > 1)
5001 fprintf_unfiltered (gdb_stdlog, "Process record: i386_process_record "
5003 paddress (gdbarch, ir.addr));
5008 if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
5011 switch (opcode8) /* Instruction prefixes */
5013 case REPE_PREFIX_OPCODE:
5014 prefixes |= PREFIX_REPZ;
5016 case REPNE_PREFIX_OPCODE:
5017 prefixes |= PREFIX_REPNZ;
5019 case LOCK_PREFIX_OPCODE:
5020 prefixes |= PREFIX_LOCK;
5022 case CS_PREFIX_OPCODE:
5023 ir.override = X86_RECORD_CS_REGNUM;
5025 case SS_PREFIX_OPCODE:
5026 ir.override = X86_RECORD_SS_REGNUM;
5028 case DS_PREFIX_OPCODE:
5029 ir.override = X86_RECORD_DS_REGNUM;
5031 case ES_PREFIX_OPCODE:
5032 ir.override = X86_RECORD_ES_REGNUM;
5034 case FS_PREFIX_OPCODE:
5035 ir.override = X86_RECORD_FS_REGNUM;
5037 case GS_PREFIX_OPCODE:
5038 ir.override = X86_RECORD_GS_REGNUM;
5040 case DATA_PREFIX_OPCODE:
5041 prefixes |= PREFIX_DATA;
5043 case ADDR_PREFIX_OPCODE:
5044 prefixes |= PREFIX_ADDR;
5046 case 0x40: /* i386 inc %eax */
5047 case 0x41: /* i386 inc %ecx */
5048 case 0x42: /* i386 inc %edx */
5049 case 0x43: /* i386 inc %ebx */
5050 case 0x44: /* i386 inc %esp */
5051 case 0x45: /* i386 inc %ebp */
5052 case 0x46: /* i386 inc %esi */
5053 case 0x47: /* i386 inc %edi */
5054 case 0x48: /* i386 dec %eax */
5055 case 0x49: /* i386 dec %ecx */
5056 case 0x4a: /* i386 dec %edx */
5057 case 0x4b: /* i386 dec %ebx */
5058 case 0x4c: /* i386 dec %esp */
5059 case 0x4d: /* i386 dec %ebp */
5060 case 0x4e: /* i386 dec %esi */
5061 case 0x4f: /* i386 dec %edi */
5062 if (ir.regmap[X86_RECORD_R8_REGNUM]) /* 64 bit target */
5065 rex_w = (opcode8 >> 3) & 1;
5066 rex_r = (opcode8 & 0x4) << 1;
5067 ir.rex_x = (opcode8 & 0x2) << 2;
5068 ir.rex_b = (opcode8 & 0x1) << 3;
5070 else /* 32 bit target */
5079 if (ir.regmap[X86_RECORD_R8_REGNUM] && rex_w == 1)
5085 if (prefixes & PREFIX_DATA)
5088 if (prefixes & PREFIX_ADDR)
5090 else if (ir.regmap[X86_RECORD_R8_REGNUM])
5093 /* Now check op code. */
5094 opcode = (uint32_t) opcode8;
5099 if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
5102 opcode = (uint32_t) opcode8 | 0x0f00;
5106 case 0x00: /* arith & logic */
5154 if (((opcode >> 3) & 7) != OP_CMPL)
5156 if ((opcode & 1) == 0)
5159 ir.ot = ir.dflag + OT_WORD;
5161 switch ((opcode >> 1) & 3)
5163 case 0: /* OP Ev, Gv */
5164 if (i386_record_modrm (&ir))
5168 if (i386_record_lea_modrm (&ir))
5174 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5176 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5179 case 1: /* OP Gv, Ev */
5180 if (i386_record_modrm (&ir))
5183 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5185 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5187 case 2: /* OP A, Iv */
5188 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5192 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5195 case 0x80: /* GRP1 */
5199 if (i386_record_modrm (&ir))
5202 if (ir.reg != OP_CMPL)
5204 if ((opcode & 1) == 0)
5207 ir.ot = ir.dflag + OT_WORD;
5214 ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
5215 if (i386_record_lea_modrm (&ir))
5219 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
5221 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5224 case 0x40: /* inc */
5233 case 0x48: /* dec */
5242 I386_RECORD_FULL_ARCH_LIST_ADD_REG (opcode & 7);
5243 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5246 case 0xf6: /* GRP3 */
5248 if ((opcode & 1) == 0)
5251 ir.ot = ir.dflag + OT_WORD;
5252 if (i386_record_modrm (&ir))
5255 if (ir.mod != 3 && ir.reg == 0)
5256 ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
5261 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5267 if (i386_record_lea_modrm (&ir))
5273 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5275 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5277 if (ir.reg == 3) /* neg */
5278 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5284 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5285 if (ir.ot != OT_BYTE)
5286 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
5287 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5291 opcode = opcode << 8 | ir.modrm;
5297 case 0xfe: /* GRP4 */
5298 case 0xff: /* GRP5 */
5299 if (i386_record_modrm (&ir))
5301 if (ir.reg >= 2 && opcode == 0xfe)
5304 opcode = opcode << 8 | ir.modrm;
5311 if ((opcode & 1) == 0)
5314 ir.ot = ir.dflag + OT_WORD;
5317 if (i386_record_lea_modrm (&ir))
5323 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5325 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5327 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5330 if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
5332 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5334 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5337 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM);
5338 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5340 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5344 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5347 if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
5349 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5354 opcode = opcode << 8 | ir.modrm;
5360 case 0x84: /* test */
5364 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5367 case 0x98: /* CWDE/CBW */
5368 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5371 case 0x99: /* CDQ/CWD */
5372 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5373 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
5376 case 0x0faf: /* imul */
5379 ir.ot = ir.dflag + OT_WORD;
5380 if (i386_record_modrm (&ir))
5383 ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
5384 else if (opcode == 0x6b)
5387 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5389 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5390 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5393 case 0x0fc0: /* xadd */
5395 if ((opcode & 1) == 0)
5398 ir.ot = ir.dflag + OT_WORD;
5399 if (i386_record_modrm (&ir))
5404 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5406 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5407 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5409 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5413 if (i386_record_lea_modrm (&ir))
5415 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5417 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5419 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5422 case 0x0fb0: /* cmpxchg */
5424 if ((opcode & 1) == 0)
5427 ir.ot = ir.dflag + OT_WORD;
5428 if (i386_record_modrm (&ir))
5433 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5434 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5436 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5440 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5441 if (i386_record_lea_modrm (&ir))
5444 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5447 case 0x0fc7: /* cmpxchg8b */
5448 if (i386_record_modrm (&ir))
5453 opcode = opcode << 8 | ir.modrm;
5456 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5457 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
5458 if (i386_record_lea_modrm (&ir))
5460 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5463 case 0x50: /* push */
5473 if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
5475 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5479 case 0x06: /* push es */
5480 case 0x0e: /* push cs */
5481 case 0x16: /* push ss */
5482 case 0x1e: /* push ds */
5483 if (ir.regmap[X86_RECORD_R8_REGNUM])
5488 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5492 case 0x0fa0: /* push fs */
5493 case 0x0fa8: /* push gs */
5494 if (ir.regmap[X86_RECORD_R8_REGNUM])
5499 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5503 case 0x60: /* pusha */
5504 if (ir.regmap[X86_RECORD_R8_REGNUM])
5509 if (i386_record_push (&ir, 1 << (ir.dflag + 4)))
5513 case 0x58: /* pop */
5521 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5522 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode & 0x7) | ir.rex_b);
5525 case 0x61: /* popa */
5526 if (ir.regmap[X86_RECORD_R8_REGNUM])
5531 for (regnum = X86_RECORD_REAX_REGNUM;
5532 regnum <= X86_RECORD_REDI_REGNUM;
5534 I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum);
5537 case 0x8f: /* pop */
5538 if (ir.regmap[X86_RECORD_R8_REGNUM])
5539 ir.ot = ir.dflag ? OT_QUAD : OT_WORD;
5541 ir.ot = ir.dflag + OT_WORD;
5542 if (i386_record_modrm (&ir))
5545 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
5548 ir.popl_esp_hack = 1 << ir.ot;
5549 if (i386_record_lea_modrm (&ir))
5552 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5555 case 0xc8: /* enter */
5556 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM);
5557 if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
5559 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5563 case 0xc9: /* leave */
5564 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5565 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM);
5568 case 0x07: /* pop es */
5569 if (ir.regmap[X86_RECORD_R8_REGNUM])
5574 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5575 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_ES_REGNUM);
5576 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5579 case 0x17: /* pop ss */
5580 if (ir.regmap[X86_RECORD_R8_REGNUM])
5585 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5586 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_SS_REGNUM);
5587 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5590 case 0x1f: /* pop ds */
5591 if (ir.regmap[X86_RECORD_R8_REGNUM])
5596 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5597 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_DS_REGNUM);
5598 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5601 case 0x0fa1: /* pop fs */
5602 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5603 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_FS_REGNUM);
5604 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5607 case 0x0fa9: /* pop gs */
5608 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5609 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_GS_REGNUM);
5610 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5613 case 0x88: /* mov */
5617 if ((opcode & 1) == 0)
5620 ir.ot = ir.dflag + OT_WORD;
5622 if (i386_record_modrm (&ir))
5627 if (opcode == 0xc6 || opcode == 0xc7)
5628 ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
5629 if (i386_record_lea_modrm (&ir))
5634 if (opcode == 0xc6 || opcode == 0xc7)
5636 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5638 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5642 case 0x8a: /* mov */
5644 if ((opcode & 1) == 0)
5647 ir.ot = ir.dflag + OT_WORD;
5648 if (i386_record_modrm (&ir))
5651 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5653 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5656 case 0x8c: /* mov seg */
5657 if (i386_record_modrm (&ir))
5662 opcode = opcode << 8 | ir.modrm;
5667 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5671 if (i386_record_lea_modrm (&ir))
5676 case 0x8e: /* mov seg */
5677 if (i386_record_modrm (&ir))
5682 regnum = X86_RECORD_ES_REGNUM;
5685 regnum = X86_RECORD_SS_REGNUM;
5688 regnum = X86_RECORD_DS_REGNUM;
5691 regnum = X86_RECORD_FS_REGNUM;
5694 regnum = X86_RECORD_GS_REGNUM;
5698 opcode = opcode << 8 | ir.modrm;
5702 I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum);
5703 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5706 case 0x0fb6: /* movzbS */
5707 case 0x0fb7: /* movzwS */
5708 case 0x0fbe: /* movsbS */
5709 case 0x0fbf: /* movswS */
5710 if (i386_record_modrm (&ir))
5712 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
5715 case 0x8d: /* lea */
5716 if (i386_record_modrm (&ir))
5721 opcode = opcode << 8 | ir.modrm;
5726 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5728 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5731 case 0xa0: /* mov EAX */
5734 case 0xd7: /* xlat */
5735 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5738 case 0xa2: /* mov EAX */
5740 if (ir.override >= 0)
5742 if (record_full_memory_query)
5746 target_terminal_ours ();
5748 Process record ignores the memory change of instruction at address %s\n\
5749 because it can't get the value of the segment register.\n\
5750 Do you want to stop the program?"),
5751 paddress (gdbarch, ir.orig_addr));
5752 target_terminal_inferior ();
5759 if ((opcode & 1) == 0)
5762 ir.ot = ir.dflag + OT_WORD;
5765 if (record_read_memory (gdbarch, ir.addr, buf, 8))
5768 addr = extract_unsigned_integer (buf, 8, byte_order);
5772 if (record_read_memory (gdbarch, ir.addr, buf, 4))
5775 addr = extract_unsigned_integer (buf, 4, byte_order);
5779 if (record_read_memory (gdbarch, ir.addr, buf, 2))
5782 addr = extract_unsigned_integer (buf, 2, byte_order);
5784 if (record_full_arch_list_add_mem (addr, 1 << ir.ot))
5789 case 0xb0: /* mov R, Ib */
5797 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((ir.regmap[X86_RECORD_R8_REGNUM])
5798 ? ((opcode & 0x7) | ir.rex_b)
5799 : ((opcode & 0x7) & 0x3));
5802 case 0xb8: /* mov R, Iv */
5810 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode & 0x7) | ir.rex_b);
5813 case 0x91: /* xchg R, EAX */
5820 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5821 I386_RECORD_FULL_ARCH_LIST_ADD_REG (opcode & 0x7);
5824 case 0x86: /* xchg Ev, Gv */
5826 if ((opcode & 1) == 0)
5829 ir.ot = ir.dflag + OT_WORD;
5830 if (i386_record_modrm (&ir))
5835 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5837 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5841 if (i386_record_lea_modrm (&ir))
5845 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5847 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5850 case 0xc4: /* les Gv */
5851 case 0xc5: /* lds Gv */
5852 if (ir.regmap[X86_RECORD_R8_REGNUM])
5858 case 0x0fb2: /* lss Gv */
5859 case 0x0fb4: /* lfs Gv */
5860 case 0x0fb5: /* lgs Gv */
5861 if (i386_record_modrm (&ir))
5869 opcode = opcode << 8 | ir.modrm;
5874 case 0xc4: /* les Gv */
5875 regnum = X86_RECORD_ES_REGNUM;
5877 case 0xc5: /* lds Gv */
5878 regnum = X86_RECORD_DS_REGNUM;
5880 case 0x0fb2: /* lss Gv */
5881 regnum = X86_RECORD_SS_REGNUM;
5883 case 0x0fb4: /* lfs Gv */
5884 regnum = X86_RECORD_FS_REGNUM;
5886 case 0x0fb5: /* lgs Gv */
5887 regnum = X86_RECORD_GS_REGNUM;
5890 I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum);
5891 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
5892 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5895 case 0xc0: /* shifts */
5901 if ((opcode & 1) == 0)
5904 ir.ot = ir.dflag + OT_WORD;
5905 if (i386_record_modrm (&ir))
5907 if (ir.mod != 3 && (opcode == 0xd2 || opcode == 0xd3))
5909 if (i386_record_lea_modrm (&ir))
5915 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5917 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5919 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5926 if (i386_record_modrm (&ir))
5930 if (record_full_arch_list_add_reg (ir.regcache, ir.rm))
5935 if (i386_record_lea_modrm (&ir))
5940 case 0xd8: /* Floats. */
5948 if (i386_record_modrm (&ir))
5950 ir.reg |= ((opcode & 7) << 3);
5956 if (i386_record_lea_modrm_addr (&ir, &addr64))
5964 /* For fcom, ficom nothing to do. */
5970 /* For fcomp, ficomp pop FPU stack, store all. */
5971 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
5998 /* For fadd, fmul, fsub, fsubr, fdiv, fdivr, fiadd, fimul,
5999 fisub, fisubr, fidiv, fidivr, modR/M.reg is an extension
6000 of code, always affects st(0) register. */
6001 if (i386_record_floats (gdbarch, &ir, I387_ST0_REGNUM (tdep)))
6025 /* Handling fld, fild. */
6026 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
6030 switch (ir.reg >> 4)
6033 if (record_full_arch_list_add_mem (addr64, 4))
6037 if (record_full_arch_list_add_mem (addr64, 8))
6043 if (record_full_arch_list_add_mem (addr64, 2))
6049 switch (ir.reg >> 4)
6052 if (record_full_arch_list_add_mem (addr64, 4))
6054 if (3 == (ir.reg & 7))
6056 /* For fstp m32fp. */
6057 if (i386_record_floats (gdbarch, &ir,
6058 I386_SAVE_FPU_REGS))
6063 if (record_full_arch_list_add_mem (addr64, 4))
6065 if ((3 == (ir.reg & 7))
6066 || (5 == (ir.reg & 7))
6067 || (7 == (ir.reg & 7)))
6069 /* For fstp insn. */
6070 if (i386_record_floats (gdbarch, &ir,
6071 I386_SAVE_FPU_REGS))
6076 if (record_full_arch_list_add_mem (addr64, 8))
6078 if (3 == (ir.reg & 7))
6080 /* For fstp m64fp. */
6081 if (i386_record_floats (gdbarch, &ir,
6082 I386_SAVE_FPU_REGS))
6087 if ((3 <= (ir.reg & 7)) && (6 <= (ir.reg & 7)))
6089 /* For fistp, fbld, fild, fbstp. */
6090 if (i386_record_floats (gdbarch, &ir,
6091 I386_SAVE_FPU_REGS))
6096 if (record_full_arch_list_add_mem (addr64, 2))
6105 if (i386_record_floats (gdbarch, &ir,
6106 I386_SAVE_FPU_ENV_REG_STACK))
6111 if (i386_record_floats (gdbarch, &ir, I387_FCTRL_REGNUM (tdep)))
6116 if (i386_record_floats (gdbarch, &ir,
6117 I386_SAVE_FPU_ENV_REG_STACK))
6123 if (record_full_arch_list_add_mem (addr64, 28))
6128 if (record_full_arch_list_add_mem (addr64, 14))
6134 if (record_full_arch_list_add_mem (addr64, 2))
6136 /* Insn fstp, fbstp. */
6137 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
6142 if (record_full_arch_list_add_mem (addr64, 10))
6148 if (record_full_arch_list_add_mem (addr64, 28))
6154 if (record_full_arch_list_add_mem (addr64, 14))
6158 if (record_full_arch_list_add_mem (addr64, 80))
6161 if (i386_record_floats (gdbarch, &ir,
6162 I386_SAVE_FPU_ENV_REG_STACK))
6166 if (record_full_arch_list_add_mem (addr64, 8))
6169 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
6174 opcode = opcode << 8 | ir.modrm;
6179 /* Opcode is an extension of modR/M byte. */
6185 if (i386_record_floats (gdbarch, &ir, I387_ST0_REGNUM (tdep)))
6189 if (0x0c == (ir.modrm >> 4))
6191 if ((ir.modrm & 0x0f) <= 7)
6193 if (i386_record_floats (gdbarch, &ir,
6194 I386_SAVE_FPU_REGS))
6199 if (i386_record_floats (gdbarch, &ir,
6200 I387_ST0_REGNUM (tdep)))
6202 /* If only st(0) is changing, then we have already
6204 if ((ir.modrm & 0x0f) - 0x08)
6206 if (i386_record_floats (gdbarch, &ir,
6207 I387_ST0_REGNUM (tdep) +
6208 ((ir.modrm & 0x0f) - 0x08)))
6226 if (i386_record_floats (gdbarch, &ir,
6227 I387_ST0_REGNUM (tdep)))
6245 if (i386_record_floats (gdbarch, &ir,
6246 I386_SAVE_FPU_REGS))
6250 if (i386_record_floats (gdbarch, &ir,
6251 I387_ST0_REGNUM (tdep)))
6253 if (i386_record_floats (gdbarch, &ir,
6254 I387_ST0_REGNUM (tdep) + 1))
6261 if (0xe9 == ir.modrm)
6263 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
6266 else if ((0x0c == ir.modrm >> 4) || (0x0d == ir.modrm >> 4))
6268 if (i386_record_floats (gdbarch, &ir,
6269 I387_ST0_REGNUM (tdep)))
6271 if (((ir.modrm & 0x0f) > 0) && ((ir.modrm & 0x0f) <= 7))
6273 if (i386_record_floats (gdbarch, &ir,
6274 I387_ST0_REGNUM (tdep) +
6278 else if ((ir.modrm & 0x0f) - 0x08)
6280 if (i386_record_floats (gdbarch, &ir,
6281 I387_ST0_REGNUM (tdep) +
6282 ((ir.modrm & 0x0f) - 0x08)))
6288 if (0xe3 == ir.modrm)
6290 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_ENV))
6293 else if ((0x0c == ir.modrm >> 4) || (0x0d == ir.modrm >> 4))
6295 if (i386_record_floats (gdbarch, &ir,
6296 I387_ST0_REGNUM (tdep)))
6298 if (((ir.modrm & 0x0f) > 0) && ((ir.modrm & 0x0f) <= 7))
6300 if (i386_record_floats (gdbarch, &ir,
6301 I387_ST0_REGNUM (tdep) +
6305 else if ((ir.modrm & 0x0f) - 0x08)
6307 if (i386_record_floats (gdbarch, &ir,
6308 I387_ST0_REGNUM (tdep) +
6309 ((ir.modrm & 0x0f) - 0x08)))
6315 if ((0x0c == ir.modrm >> 4)
6316 || (0x0d == ir.modrm >> 4)
6317 || (0x0f == ir.modrm >> 4))
6319 if ((ir.modrm & 0x0f) <= 7)
6321 if (i386_record_floats (gdbarch, &ir,
6322 I387_ST0_REGNUM (tdep) +
6328 if (i386_record_floats (gdbarch, &ir,
6329 I387_ST0_REGNUM (tdep) +
6330 ((ir.modrm & 0x0f) - 0x08)))
6336 if (0x0c == ir.modrm >> 4)
6338 if (i386_record_floats (gdbarch, &ir,
6339 I387_FTAG_REGNUM (tdep)))
6342 else if ((0x0d == ir.modrm >> 4) || (0x0e == ir.modrm >> 4))
6344 if ((ir.modrm & 0x0f) <= 7)
6346 if (i386_record_floats (gdbarch, &ir,
6347 I387_ST0_REGNUM (tdep) +
6353 if (i386_record_floats (gdbarch, &ir,
6354 I386_SAVE_FPU_REGS))
6360 if ((0x0c == ir.modrm >> 4)
6361 || (0x0e == ir.modrm >> 4)
6362 || (0x0f == ir.modrm >> 4)
6363 || (0xd9 == ir.modrm))
6365 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
6370 if (0xe0 == ir.modrm)
6372 if (record_full_arch_list_add_reg (ir.regcache,
6376 else if ((0x0f == ir.modrm >> 4) || (0x0e == ir.modrm >> 4))
6378 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
6386 case 0xa4: /* movsS */
6388 case 0xaa: /* stosS */
6390 case 0x6c: /* insS */
6392 regcache_raw_read_unsigned (ir.regcache,
6393 ir.regmap[X86_RECORD_RECX_REGNUM],
6399 if ((opcode & 1) == 0)
6402 ir.ot = ir.dflag + OT_WORD;
6403 regcache_raw_read_unsigned (ir.regcache,
6404 ir.regmap[X86_RECORD_REDI_REGNUM],
6407 regcache_raw_read_unsigned (ir.regcache,
6408 ir.regmap[X86_RECORD_ES_REGNUM],
6410 regcache_raw_read_unsigned (ir.regcache,
6411 ir.regmap[X86_RECORD_DS_REGNUM],
6413 if (ir.aflag && (es != ds))
6415 /* addr += ((uint32_t) read_register (I386_ES_REGNUM)) << 4; */
6416 if (record_full_memory_query)
6420 target_terminal_ours ();
6422 Process record ignores the memory change of instruction at address %s\n\
6423 because it can't get the value of the segment register.\n\
6424 Do you want to stop the program?"),
6425 paddress (gdbarch, ir.orig_addr));
6426 target_terminal_inferior ();
6433 if (record_full_arch_list_add_mem (addr, 1 << ir.ot))
6437 if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
6438 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
6439 if (opcode == 0xa4 || opcode == 0xa5)
6440 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
6441 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
6442 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6446 case 0xa6: /* cmpsS */
6448 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
6449 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
6450 if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
6451 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
6452 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6455 case 0xac: /* lodsS */
6457 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
6458 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
6459 if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
6460 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
6461 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6464 case 0xae: /* scasS */
6466 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
6467 if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
6468 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
6469 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6472 case 0x6e: /* outsS */
6474 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
6475 if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
6476 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
6477 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6480 case 0xe4: /* port I/O */
6484 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6485 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
6495 case 0xc2: /* ret im */
6496 case 0xc3: /* ret */
6497 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
6498 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6501 case 0xca: /* lret im */
6502 case 0xcb: /* lret */
6503 case 0xcf: /* iret */
6504 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM);
6505 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
6506 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6509 case 0xe8: /* call im */
6510 if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
6512 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
6516 case 0x9a: /* lcall im */
6517 if (ir.regmap[X86_RECORD_R8_REGNUM])
6522 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM);
6523 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
6527 case 0xe9: /* jmp im */
6528 case 0xea: /* ljmp im */
6529 case 0xeb: /* jmp Jb */
6530 case 0x70: /* jcc Jb */
6546 case 0x0f80: /* jcc Jv */
6564 case 0x0f90: /* setcc Gv */
6580 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6582 if (i386_record_modrm (&ir))
6585 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rex_b ? (ir.rm | ir.rex_b)
6589 if (i386_record_lea_modrm (&ir))
6594 case 0x0f40: /* cmov Gv, Ev */
6610 if (i386_record_modrm (&ir))
6613 if (ir.dflag == OT_BYTE)
6615 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
6619 case 0x9c: /* pushf */
6620 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6621 if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
6623 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
6627 case 0x9d: /* popf */
6628 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
6629 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6632 case 0x9e: /* sahf */
6633 if (ir.regmap[X86_RECORD_R8_REGNUM])
6639 case 0xf5: /* cmc */
6640 case 0xf8: /* clc */
6641 case 0xf9: /* stc */
6642 case 0xfc: /* cld */
6643 case 0xfd: /* std */
6644 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6647 case 0x9f: /* lahf */
6648 if (ir.regmap[X86_RECORD_R8_REGNUM])
6653 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6654 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
6657 /* bit operations */
6658 case 0x0fba: /* bt/bts/btr/btc Gv, im */
6659 ir.ot = ir.dflag + OT_WORD;
6660 if (i386_record_modrm (&ir))
6665 opcode = opcode << 8 | ir.modrm;
6671 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
6674 if (i386_record_lea_modrm (&ir))
6678 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6681 case 0x0fa3: /* bt Gv, Ev */
6682 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6685 case 0x0fab: /* bts */
6686 case 0x0fb3: /* btr */
6687 case 0x0fbb: /* btc */
6688 ir.ot = ir.dflag + OT_WORD;
6689 if (i386_record_modrm (&ir))
6692 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
6696 if (i386_record_lea_modrm_addr (&ir, &addr64))
6698 regcache_raw_read_unsigned (ir.regcache,
6699 ir.regmap[ir.reg | rex_r],
6704 addr64 += ((int16_t) addr >> 4) << 4;
6707 addr64 += ((int32_t) addr >> 5) << 5;
6710 addr64 += ((int64_t) addr >> 6) << 6;
6713 if (record_full_arch_list_add_mem (addr64, 1 << ir.ot))
6715 if (i386_record_lea_modrm (&ir))
6718 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6721 case 0x0fbc: /* bsf */
6722 case 0x0fbd: /* bsr */
6723 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
6724 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6728 case 0x27: /* daa */
6729 case 0x2f: /* das */
6730 case 0x37: /* aaa */
6731 case 0x3f: /* aas */
6732 case 0xd4: /* aam */
6733 case 0xd5: /* aad */
6734 if (ir.regmap[X86_RECORD_R8_REGNUM])
6739 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
6740 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6744 case 0x90: /* nop */
6745 if (prefixes & PREFIX_LOCK)
6752 case 0x9b: /* fwait */
6753 if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
6755 opcode = (uint32_t) opcode8;
6761 case 0xcc: /* int3 */
6762 printf_unfiltered (_("Process record does not support instruction "
6769 case 0xcd: /* int */
6773 if (record_read_memory (gdbarch, ir.addr, &interrupt, 1))
6776 if (interrupt != 0x80
6777 || tdep->i386_intx80_record == NULL)
6779 printf_unfiltered (_("Process record does not support "
6780 "instruction int 0x%02x.\n"),
6785 ret = tdep->i386_intx80_record (ir.regcache);
6792 case 0xce: /* into */
6793 printf_unfiltered (_("Process record does not support "
6794 "instruction into.\n"));
6799 case 0xfa: /* cli */
6800 case 0xfb: /* sti */
6803 case 0x62: /* bound */
6804 printf_unfiltered (_("Process record does not support "
6805 "instruction bound.\n"));
6810 case 0x0fc8: /* bswap reg */
6818 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode & 7) | ir.rex_b);
6821 case 0xd6: /* salc */
6822 if (ir.regmap[X86_RECORD_R8_REGNUM])
6827 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
6828 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6831 case 0xe0: /* loopnz */
6832 case 0xe1: /* loopz */
6833 case 0xe2: /* loop */
6834 case 0xe3: /* jecxz */
6835 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
6836 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6839 case 0x0f30: /* wrmsr */
6840 printf_unfiltered (_("Process record does not support "
6841 "instruction wrmsr.\n"));
6846 case 0x0f32: /* rdmsr */
6847 printf_unfiltered (_("Process record does not support "
6848 "instruction rdmsr.\n"));
6853 case 0x0f31: /* rdtsc */
6854 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
6855 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
6858 case 0x0f34: /* sysenter */
6861 if (ir.regmap[X86_RECORD_R8_REGNUM])
6866 if (tdep->i386_sysenter_record == NULL)
6868 printf_unfiltered (_("Process record does not support "
6869 "instruction sysenter.\n"));
6873 ret = tdep->i386_sysenter_record (ir.regcache);
6879 case 0x0f35: /* sysexit */
6880 printf_unfiltered (_("Process record does not support "
6881 "instruction sysexit.\n"));
6886 case 0x0f05: /* syscall */
6889 if (tdep->i386_syscall_record == NULL)
6891 printf_unfiltered (_("Process record does not support "
6892 "instruction syscall.\n"));
6896 ret = tdep->i386_syscall_record (ir.regcache);
6902 case 0x0f07: /* sysret */
6903 printf_unfiltered (_("Process record does not support "
6904 "instruction sysret.\n"));
6909 case 0x0fa2: /* cpuid */
6910 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
6911 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
6912 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
6913 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBX_REGNUM);
6916 case 0xf4: /* hlt */
6917 printf_unfiltered (_("Process record does not support "
6918 "instruction hlt.\n"));
6924 if (i386_record_modrm (&ir))
6931 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
6935 if (i386_record_lea_modrm (&ir))
6944 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6948 opcode = opcode << 8 | ir.modrm;
6955 if (i386_record_modrm (&ir))
6966 opcode = opcode << 8 | ir.modrm;
6969 if (ir.override >= 0)
6971 if (record_full_memory_query)
6975 target_terminal_ours ();
6977 Process record ignores the memory change of instruction at address %s\n\
6978 because it can't get the value of the segment register.\n\
6979 Do you want to stop the program?"),
6980 paddress (gdbarch, ir.orig_addr));
6981 target_terminal_inferior ();
6988 if (i386_record_lea_modrm_addr (&ir, &addr64))
6990 if (record_full_arch_list_add_mem (addr64, 2))
6993 if (ir.regmap[X86_RECORD_R8_REGNUM])
6995 if (record_full_arch_list_add_mem (addr64, 8))
7000 if (record_full_arch_list_add_mem (addr64, 4))
7011 case 0: /* monitor */
7014 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7018 opcode = opcode << 8 | ir.modrm;
7026 if (ir.override >= 0)
7028 if (record_full_memory_query)
7032 target_terminal_ours ();
7034 Process record ignores the memory change of instruction at address %s\n\
7035 because it can't get the value of the segment register.\n\
7036 Do you want to stop the program?"),
7037 paddress (gdbarch, ir.orig_addr));
7038 target_terminal_inferior ();
7047 if (i386_record_lea_modrm_addr (&ir, &addr64))
7049 if (record_full_arch_list_add_mem (addr64, 2))
7052 if (ir.regmap[X86_RECORD_R8_REGNUM])
7054 if (record_full_arch_list_add_mem (addr64, 8))
7059 if (record_full_arch_list_add_mem (addr64, 4))
7071 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
7072 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
7076 else if (ir.rm == 1)
7083 opcode = opcode << 8 | ir.modrm;
7090 if (record_full_arch_list_add_reg (ir.regcache, ir.rm | ir.rex_b))
7096 if (i386_record_lea_modrm (&ir))
7099 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7102 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7104 case 7: /* invlpg */
7107 if (ir.rm == 0 && ir.regmap[X86_RECORD_R8_REGNUM])
7108 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_GS_REGNUM);
7112 opcode = opcode << 8 | ir.modrm;
7117 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7121 opcode = opcode << 8 | ir.modrm;
7127 case 0x0f08: /* invd */
7128 case 0x0f09: /* wbinvd */
7131 case 0x63: /* arpl */
7132 if (i386_record_modrm (&ir))
7134 if (ir.mod == 3 || ir.regmap[X86_RECORD_R8_REGNUM])
7136 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.regmap[X86_RECORD_R8_REGNUM]
7137 ? (ir.reg | rex_r) : ir.rm);
7141 ir.ot = ir.dflag ? OT_LONG : OT_WORD;
7142 if (i386_record_lea_modrm (&ir))
7145 if (!ir.regmap[X86_RECORD_R8_REGNUM])
7146 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7149 case 0x0f02: /* lar */
7150 case 0x0f03: /* lsl */
7151 if (i386_record_modrm (&ir))
7153 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
7154 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7158 if (i386_record_modrm (&ir))
7160 if (ir.mod == 3 && ir.reg == 3)
7163 opcode = opcode << 8 | ir.modrm;
7175 /* nop (multi byte) */
7178 case 0x0f20: /* mov reg, crN */
7179 case 0x0f22: /* mov crN, reg */
7180 if (i386_record_modrm (&ir))
7182 if ((ir.modrm & 0xc0) != 0xc0)
7185 opcode = opcode << 8 | ir.modrm;
7196 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7198 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
7202 opcode = opcode << 8 | ir.modrm;
7208 case 0x0f21: /* mov reg, drN */
7209 case 0x0f23: /* mov drN, reg */
7210 if (i386_record_modrm (&ir))
7212 if ((ir.modrm & 0xc0) != 0xc0 || ir.reg == 4
7213 || ir.reg == 5 || ir.reg >= 8)
7216 opcode = opcode << 8 | ir.modrm;
7220 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7222 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
7225 case 0x0f06: /* clts */
7226 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7229 /* MMX 3DNow! SSE SSE2 SSE3 SSSE3 SSE4 */
7231 case 0x0f0d: /* 3DNow! prefetch */
7234 case 0x0f0e: /* 3DNow! femms */
7235 case 0x0f77: /* emms */
7236 if (i386_fpc_regnum_p (gdbarch, I387_FTAG_REGNUM(tdep)))
7238 record_full_arch_list_add_reg (ir.regcache, I387_FTAG_REGNUM(tdep));
7241 case 0x0f0f: /* 3DNow! data */
7242 if (i386_record_modrm (&ir))
7244 if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
7249 case 0x0c: /* 3DNow! pi2fw */
7250 case 0x0d: /* 3DNow! pi2fd */
7251 case 0x1c: /* 3DNow! pf2iw */
7252 case 0x1d: /* 3DNow! pf2id */
7253 case 0x8a: /* 3DNow! pfnacc */
7254 case 0x8e: /* 3DNow! pfpnacc */
7255 case 0x90: /* 3DNow! pfcmpge */
7256 case 0x94: /* 3DNow! pfmin */
7257 case 0x96: /* 3DNow! pfrcp */
7258 case 0x97: /* 3DNow! pfrsqrt */
7259 case 0x9a: /* 3DNow! pfsub */
7260 case 0x9e: /* 3DNow! pfadd */
7261 case 0xa0: /* 3DNow! pfcmpgt */
7262 case 0xa4: /* 3DNow! pfmax */
7263 case 0xa6: /* 3DNow! pfrcpit1 */
7264 case 0xa7: /* 3DNow! pfrsqit1 */
7265 case 0xaa: /* 3DNow! pfsubr */
7266 case 0xae: /* 3DNow! pfacc */
7267 case 0xb0: /* 3DNow! pfcmpeq */
7268 case 0xb4: /* 3DNow! pfmul */
7269 case 0xb6: /* 3DNow! pfrcpit2 */
7270 case 0xb7: /* 3DNow! pmulhrw */
7271 case 0xbb: /* 3DNow! pswapd */
7272 case 0xbf: /* 3DNow! pavgusb */
7273 if (!i386_mmx_regnum_p (gdbarch, I387_MM0_REGNUM (tdep) + ir.reg))
7274 goto no_support_3dnow_data;
7275 record_full_arch_list_add_reg (ir.regcache, ir.reg);
7279 no_support_3dnow_data:
7280 opcode = (opcode << 8) | opcode8;
7286 case 0x0faa: /* rsm */
7287 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7288 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
7289 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
7290 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
7291 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBX_REGNUM);
7292 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
7293 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM);
7294 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
7295 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
7299 if (i386_record_modrm (&ir))
7303 case 0: /* fxsave */
7307 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7308 if (i386_record_lea_modrm_addr (&ir, &tmpu64))
7310 if (record_full_arch_list_add_mem (tmpu64, 512))
7315 case 1: /* fxrstor */
7319 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7321 for (i = I387_MM0_REGNUM (tdep);
7322 i386_mmx_regnum_p (gdbarch, i); i++)
7323 record_full_arch_list_add_reg (ir.regcache, i);
7325 for (i = I387_XMM0_REGNUM (tdep);
7326 i386_xmm_regnum_p (gdbarch, i); i++)
7327 record_full_arch_list_add_reg (ir.regcache, i);
7329 if (i386_mxcsr_regnum_p (gdbarch, I387_MXCSR_REGNUM(tdep)))
7330 record_full_arch_list_add_reg (ir.regcache,
7331 I387_MXCSR_REGNUM(tdep));
7333 for (i = I387_ST0_REGNUM (tdep);
7334 i386_fp_regnum_p (gdbarch, i); i++)
7335 record_full_arch_list_add_reg (ir.regcache, i);
7337 for (i = I387_FCTRL_REGNUM (tdep);
7338 i386_fpc_regnum_p (gdbarch, i); i++)
7339 record_full_arch_list_add_reg (ir.regcache, i);
7343 case 2: /* ldmxcsr */
7344 if (!i386_mxcsr_regnum_p (gdbarch, I387_MXCSR_REGNUM(tdep)))
7346 record_full_arch_list_add_reg (ir.regcache, I387_MXCSR_REGNUM(tdep));
7349 case 3: /* stmxcsr */
7351 if (i386_record_lea_modrm (&ir))
7355 case 5: /* lfence */
7356 case 6: /* mfence */
7357 case 7: /* sfence clflush */
7361 opcode = (opcode << 8) | ir.modrm;
7367 case 0x0fc3: /* movnti */
7368 ir.ot = (ir.dflag == 2) ? OT_QUAD : OT_LONG;
7369 if (i386_record_modrm (&ir))
7374 if (i386_record_lea_modrm (&ir))
7378 /* Add prefix to opcode. */
7493 /* Mask out PREFIX_ADDR. */
7494 switch ((prefixes & ~PREFIX_ADDR))
7506 reswitch_prefix_add:
7514 if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
7517 opcode = (uint32_t) opcode8 | opcode << 8;
7518 goto reswitch_prefix_add;
7521 case 0x0f10: /* movups */
7522 case 0x660f10: /* movupd */
7523 case 0xf30f10: /* movss */
7524 case 0xf20f10: /* movsd */
7525 case 0x0f12: /* movlps */
7526 case 0x660f12: /* movlpd */
7527 case 0xf30f12: /* movsldup */
7528 case 0xf20f12: /* movddup */
7529 case 0x0f14: /* unpcklps */
7530 case 0x660f14: /* unpcklpd */
7531 case 0x0f15: /* unpckhps */
7532 case 0x660f15: /* unpckhpd */
7533 case 0x0f16: /* movhps */
7534 case 0x660f16: /* movhpd */
7535 case 0xf30f16: /* movshdup */
7536 case 0x0f28: /* movaps */
7537 case 0x660f28: /* movapd */
7538 case 0x0f2a: /* cvtpi2ps */
7539 case 0x660f2a: /* cvtpi2pd */
7540 case 0xf30f2a: /* cvtsi2ss */
7541 case 0xf20f2a: /* cvtsi2sd */
7542 case 0x0f2c: /* cvttps2pi */
7543 case 0x660f2c: /* cvttpd2pi */
7544 case 0x0f2d: /* cvtps2pi */
7545 case 0x660f2d: /* cvtpd2pi */
7546 case 0x660f3800: /* pshufb */
7547 case 0x660f3801: /* phaddw */
7548 case 0x660f3802: /* phaddd */
7549 case 0x660f3803: /* phaddsw */
7550 case 0x660f3804: /* pmaddubsw */
7551 case 0x660f3805: /* phsubw */
7552 case 0x660f3806: /* phsubd */
7553 case 0x660f3807: /* phsubsw */
7554 case 0x660f3808: /* psignb */
7555 case 0x660f3809: /* psignw */
7556 case 0x660f380a: /* psignd */
7557 case 0x660f380b: /* pmulhrsw */
7558 case 0x660f3810: /* pblendvb */
7559 case 0x660f3814: /* blendvps */
7560 case 0x660f3815: /* blendvpd */
7561 case 0x660f381c: /* pabsb */
7562 case 0x660f381d: /* pabsw */
7563 case 0x660f381e: /* pabsd */
7564 case 0x660f3820: /* pmovsxbw */
7565 case 0x660f3821: /* pmovsxbd */
7566 case 0x660f3822: /* pmovsxbq */
7567 case 0x660f3823: /* pmovsxwd */
7568 case 0x660f3824: /* pmovsxwq */
7569 case 0x660f3825: /* pmovsxdq */
7570 case 0x660f3828: /* pmuldq */
7571 case 0x660f3829: /* pcmpeqq */
7572 case 0x660f382a: /* movntdqa */
7573 case 0x660f3a08: /* roundps */
7574 case 0x660f3a09: /* roundpd */
7575 case 0x660f3a0a: /* roundss */
7576 case 0x660f3a0b: /* roundsd */
7577 case 0x660f3a0c: /* blendps */
7578 case 0x660f3a0d: /* blendpd */
7579 case 0x660f3a0e: /* pblendw */
7580 case 0x660f3a0f: /* palignr */
7581 case 0x660f3a20: /* pinsrb */
7582 case 0x660f3a21: /* insertps */
7583 case 0x660f3a22: /* pinsrd pinsrq */
7584 case 0x660f3a40: /* dpps */
7585 case 0x660f3a41: /* dppd */
7586 case 0x660f3a42: /* mpsadbw */
7587 case 0x660f3a60: /* pcmpestrm */
7588 case 0x660f3a61: /* pcmpestri */
7589 case 0x660f3a62: /* pcmpistrm */
7590 case 0x660f3a63: /* pcmpistri */
7591 case 0x0f51: /* sqrtps */
7592 case 0x660f51: /* sqrtpd */
7593 case 0xf20f51: /* sqrtsd */
7594 case 0xf30f51: /* sqrtss */
7595 case 0x0f52: /* rsqrtps */
7596 case 0xf30f52: /* rsqrtss */
7597 case 0x0f53: /* rcpps */
7598 case 0xf30f53: /* rcpss */
7599 case 0x0f54: /* andps */
7600 case 0x660f54: /* andpd */
7601 case 0x0f55: /* andnps */
7602 case 0x660f55: /* andnpd */
7603 case 0x0f56: /* orps */
7604 case 0x660f56: /* orpd */
7605 case 0x0f57: /* xorps */
7606 case 0x660f57: /* xorpd */
7607 case 0x0f58: /* addps */
7608 case 0x660f58: /* addpd */
7609 case 0xf20f58: /* addsd */
7610 case 0xf30f58: /* addss */
7611 case 0x0f59: /* mulps */
7612 case 0x660f59: /* mulpd */
7613 case 0xf20f59: /* mulsd */
7614 case 0xf30f59: /* mulss */
7615 case 0x0f5a: /* cvtps2pd */
7616 case 0x660f5a: /* cvtpd2ps */
7617 case 0xf20f5a: /* cvtsd2ss */
7618 case 0xf30f5a: /* cvtss2sd */
7619 case 0x0f5b: /* cvtdq2ps */
7620 case 0x660f5b: /* cvtps2dq */
7621 case 0xf30f5b: /* cvttps2dq */
7622 case 0x0f5c: /* subps */
7623 case 0x660f5c: /* subpd */
7624 case 0xf20f5c: /* subsd */
7625 case 0xf30f5c: /* subss */
7626 case 0x0f5d: /* minps */
7627 case 0x660f5d: /* minpd */
7628 case 0xf20f5d: /* minsd */
7629 case 0xf30f5d: /* minss */
7630 case 0x0f5e: /* divps */
7631 case 0x660f5e: /* divpd */
7632 case 0xf20f5e: /* divsd */
7633 case 0xf30f5e: /* divss */
7634 case 0x0f5f: /* maxps */
7635 case 0x660f5f: /* maxpd */
7636 case 0xf20f5f: /* maxsd */
7637 case 0xf30f5f: /* maxss */
7638 case 0x660f60: /* punpcklbw */
7639 case 0x660f61: /* punpcklwd */
7640 case 0x660f62: /* punpckldq */
7641 case 0x660f63: /* packsswb */
7642 case 0x660f64: /* pcmpgtb */
7643 case 0x660f65: /* pcmpgtw */
7644 case 0x660f66: /* pcmpgtd */
7645 case 0x660f67: /* packuswb */
7646 case 0x660f68: /* punpckhbw */
7647 case 0x660f69: /* punpckhwd */
7648 case 0x660f6a: /* punpckhdq */
7649 case 0x660f6b: /* packssdw */
7650 case 0x660f6c: /* punpcklqdq */
7651 case 0x660f6d: /* punpckhqdq */
7652 case 0x660f6e: /* movd */
7653 case 0x660f6f: /* movdqa */
7654 case 0xf30f6f: /* movdqu */
7655 case 0x660f70: /* pshufd */
7656 case 0xf20f70: /* pshuflw */
7657 case 0xf30f70: /* pshufhw */
7658 case 0x660f74: /* pcmpeqb */
7659 case 0x660f75: /* pcmpeqw */
7660 case 0x660f76: /* pcmpeqd */
7661 case 0x660f7c: /* haddpd */
7662 case 0xf20f7c: /* haddps */
7663 case 0x660f7d: /* hsubpd */
7664 case 0xf20f7d: /* hsubps */
7665 case 0xf30f7e: /* movq */
7666 case 0x0fc2: /* cmpps */
7667 case 0x660fc2: /* cmppd */
7668 case 0xf20fc2: /* cmpsd */
7669 case 0xf30fc2: /* cmpss */
7670 case 0x660fc4: /* pinsrw */
7671 case 0x0fc6: /* shufps */
7672 case 0x660fc6: /* shufpd */
7673 case 0x660fd0: /* addsubpd */
7674 case 0xf20fd0: /* addsubps */
7675 case 0x660fd1: /* psrlw */
7676 case 0x660fd2: /* psrld */
7677 case 0x660fd3: /* psrlq */
7678 case 0x660fd4: /* paddq */
7679 case 0x660fd5: /* pmullw */
7680 case 0xf30fd6: /* movq2dq */
7681 case 0x660fd8: /* psubusb */
7682 case 0x660fd9: /* psubusw */
7683 case 0x660fda: /* pminub */
7684 case 0x660fdb: /* pand */
7685 case 0x660fdc: /* paddusb */
7686 case 0x660fdd: /* paddusw */
7687 case 0x660fde: /* pmaxub */
7688 case 0x660fdf: /* pandn */
7689 case 0x660fe0: /* pavgb */
7690 case 0x660fe1: /* psraw */
7691 case 0x660fe2: /* psrad */
7692 case 0x660fe3: /* pavgw */
7693 case 0x660fe4: /* pmulhuw */
7694 case 0x660fe5: /* pmulhw */
7695 case 0x660fe6: /* cvttpd2dq */
7696 case 0xf20fe6: /* cvtpd2dq */
7697 case 0xf30fe6: /* cvtdq2pd */
7698 case 0x660fe8: /* psubsb */
7699 case 0x660fe9: /* psubsw */
7700 case 0x660fea: /* pminsw */
7701 case 0x660feb: /* por */
7702 case 0x660fec: /* paddsb */
7703 case 0x660fed: /* paddsw */
7704 case 0x660fee: /* pmaxsw */
7705 case 0x660fef: /* pxor */
7706 case 0xf20ff0: /* lddqu */
7707 case 0x660ff1: /* psllw */
7708 case 0x660ff2: /* pslld */
7709 case 0x660ff3: /* psllq */
7710 case 0x660ff4: /* pmuludq */
7711 case 0x660ff5: /* pmaddwd */
7712 case 0x660ff6: /* psadbw */
7713 case 0x660ff8: /* psubb */
7714 case 0x660ff9: /* psubw */
7715 case 0x660ffa: /* psubd */
7716 case 0x660ffb: /* psubq */
7717 case 0x660ffc: /* paddb */
7718 case 0x660ffd: /* paddw */
7719 case 0x660ffe: /* paddd */
7720 if (i386_record_modrm (&ir))
7723 if (!i386_xmm_regnum_p (gdbarch, I387_XMM0_REGNUM (tdep) + ir.reg))
7725 record_full_arch_list_add_reg (ir.regcache,
7726 I387_XMM0_REGNUM (tdep) + ir.reg);
7727 if ((opcode & 0xfffffffc) == 0x660f3a60)
7728 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7731 case 0x0f11: /* movups */
7732 case 0x660f11: /* movupd */
7733 case 0xf30f11: /* movss */
7734 case 0xf20f11: /* movsd */
7735 case 0x0f13: /* movlps */
7736 case 0x660f13: /* movlpd */
7737 case 0x0f17: /* movhps */
7738 case 0x660f17: /* movhpd */
7739 case 0x0f29: /* movaps */
7740 case 0x660f29: /* movapd */
7741 case 0x660f3a14: /* pextrb */
7742 case 0x660f3a15: /* pextrw */
7743 case 0x660f3a16: /* pextrd pextrq */
7744 case 0x660f3a17: /* extractps */
7745 case 0x660f7f: /* movdqa */
7746 case 0xf30f7f: /* movdqu */
7747 if (i386_record_modrm (&ir))
7751 if (opcode == 0x0f13 || opcode == 0x660f13
7752 || opcode == 0x0f17 || opcode == 0x660f17)
7755 if (!i386_xmm_regnum_p (gdbarch,
7756 I387_XMM0_REGNUM (tdep) + ir.rm))
7758 record_full_arch_list_add_reg (ir.regcache,
7759 I387_XMM0_REGNUM (tdep) + ir.rm);
7781 if (i386_record_lea_modrm (&ir))
7786 case 0x0f2b: /* movntps */
7787 case 0x660f2b: /* movntpd */
7788 case 0x0fe7: /* movntq */
7789 case 0x660fe7: /* movntdq */
7792 if (opcode == 0x0fe7)
7796 if (i386_record_lea_modrm (&ir))
7800 case 0xf30f2c: /* cvttss2si */
7801 case 0xf20f2c: /* cvttsd2si */
7802 case 0xf30f2d: /* cvtss2si */
7803 case 0xf20f2d: /* cvtsd2si */
7804 case 0xf20f38f0: /* crc32 */
7805 case 0xf20f38f1: /* crc32 */
7806 case 0x0f50: /* movmskps */
7807 case 0x660f50: /* movmskpd */
7808 case 0x0fc5: /* pextrw */
7809 case 0x660fc5: /* pextrw */
7810 case 0x0fd7: /* pmovmskb */
7811 case 0x660fd7: /* pmovmskb */
7812 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
7815 case 0x0f3800: /* pshufb */
7816 case 0x0f3801: /* phaddw */
7817 case 0x0f3802: /* phaddd */
7818 case 0x0f3803: /* phaddsw */
7819 case 0x0f3804: /* pmaddubsw */
7820 case 0x0f3805: /* phsubw */
7821 case 0x0f3806: /* phsubd */
7822 case 0x0f3807: /* phsubsw */
7823 case 0x0f3808: /* psignb */
7824 case 0x0f3809: /* psignw */
7825 case 0x0f380a: /* psignd */
7826 case 0x0f380b: /* pmulhrsw */
7827 case 0x0f381c: /* pabsb */
7828 case 0x0f381d: /* pabsw */
7829 case 0x0f381e: /* pabsd */
7830 case 0x0f382b: /* packusdw */
7831 case 0x0f3830: /* pmovzxbw */
7832 case 0x0f3831: /* pmovzxbd */
7833 case 0x0f3832: /* pmovzxbq */
7834 case 0x0f3833: /* pmovzxwd */
7835 case 0x0f3834: /* pmovzxwq */
7836 case 0x0f3835: /* pmovzxdq */
7837 case 0x0f3837: /* pcmpgtq */
7838 case 0x0f3838: /* pminsb */
7839 case 0x0f3839: /* pminsd */
7840 case 0x0f383a: /* pminuw */
7841 case 0x0f383b: /* pminud */
7842 case 0x0f383c: /* pmaxsb */
7843 case 0x0f383d: /* pmaxsd */
7844 case 0x0f383e: /* pmaxuw */
7845 case 0x0f383f: /* pmaxud */
7846 case 0x0f3840: /* pmulld */
7847 case 0x0f3841: /* phminposuw */
7848 case 0x0f3a0f: /* palignr */
7849 case 0x0f60: /* punpcklbw */
7850 case 0x0f61: /* punpcklwd */
7851 case 0x0f62: /* punpckldq */
7852 case 0x0f63: /* packsswb */
7853 case 0x0f64: /* pcmpgtb */
7854 case 0x0f65: /* pcmpgtw */
7855 case 0x0f66: /* pcmpgtd */
7856 case 0x0f67: /* packuswb */
7857 case 0x0f68: /* punpckhbw */
7858 case 0x0f69: /* punpckhwd */
7859 case 0x0f6a: /* punpckhdq */
7860 case 0x0f6b: /* packssdw */
7861 case 0x0f6e: /* movd */
7862 case 0x0f6f: /* movq */
7863 case 0x0f70: /* pshufw */
7864 case 0x0f74: /* pcmpeqb */
7865 case 0x0f75: /* pcmpeqw */
7866 case 0x0f76: /* pcmpeqd */
7867 case 0x0fc4: /* pinsrw */
7868 case 0x0fd1: /* psrlw */
7869 case 0x0fd2: /* psrld */
7870 case 0x0fd3: /* psrlq */
7871 case 0x0fd4: /* paddq */
7872 case 0x0fd5: /* pmullw */
7873 case 0xf20fd6: /* movdq2q */
7874 case 0x0fd8: /* psubusb */
7875 case 0x0fd9: /* psubusw */
7876 case 0x0fda: /* pminub */
7877 case 0x0fdb: /* pand */
7878 case 0x0fdc: /* paddusb */
7879 case 0x0fdd: /* paddusw */
7880 case 0x0fde: /* pmaxub */
7881 case 0x0fdf: /* pandn */
7882 case 0x0fe0: /* pavgb */
7883 case 0x0fe1: /* psraw */
7884 case 0x0fe2: /* psrad */
7885 case 0x0fe3: /* pavgw */
7886 case 0x0fe4: /* pmulhuw */
7887 case 0x0fe5: /* pmulhw */
7888 case 0x0fe8: /* psubsb */
7889 case 0x0fe9: /* psubsw */
7890 case 0x0fea: /* pminsw */
7891 case 0x0feb: /* por */
7892 case 0x0fec: /* paddsb */
7893 case 0x0fed: /* paddsw */
7894 case 0x0fee: /* pmaxsw */
7895 case 0x0fef: /* pxor */
7896 case 0x0ff1: /* psllw */
7897 case 0x0ff2: /* pslld */
7898 case 0x0ff3: /* psllq */
7899 case 0x0ff4: /* pmuludq */
7900 case 0x0ff5: /* pmaddwd */
7901 case 0x0ff6: /* psadbw */
7902 case 0x0ff8: /* psubb */
7903 case 0x0ff9: /* psubw */
7904 case 0x0ffa: /* psubd */
7905 case 0x0ffb: /* psubq */
7906 case 0x0ffc: /* paddb */
7907 case 0x0ffd: /* paddw */
7908 case 0x0ffe: /* paddd */
7909 if (i386_record_modrm (&ir))
7911 if (!i386_mmx_regnum_p (gdbarch, I387_MM0_REGNUM (tdep) + ir.reg))
7913 record_full_arch_list_add_reg (ir.regcache,
7914 I387_MM0_REGNUM (tdep) + ir.reg);
7917 case 0x0f71: /* psllw */
7918 case 0x0f72: /* pslld */
7919 case 0x0f73: /* psllq */
7920 if (i386_record_modrm (&ir))
7922 if (!i386_mmx_regnum_p (gdbarch, I387_MM0_REGNUM (tdep) + ir.rm))
7924 record_full_arch_list_add_reg (ir.regcache,
7925 I387_MM0_REGNUM (tdep) + ir.rm);
7928 case 0x660f71: /* psllw */
7929 case 0x660f72: /* pslld */
7930 case 0x660f73: /* psllq */
7931 if (i386_record_modrm (&ir))
7934 if (!i386_xmm_regnum_p (gdbarch, I387_XMM0_REGNUM (tdep) + ir.rm))
7936 record_full_arch_list_add_reg (ir.regcache,
7937 I387_XMM0_REGNUM (tdep) + ir.rm);
7940 case 0x0f7e: /* movd */
7941 case 0x660f7e: /* movd */
7942 if (i386_record_modrm (&ir))
7945 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
7952 if (i386_record_lea_modrm (&ir))
7957 case 0x0f7f: /* movq */
7958 if (i386_record_modrm (&ir))
7962 if (!i386_mmx_regnum_p (gdbarch, I387_MM0_REGNUM (tdep) + ir.rm))
7964 record_full_arch_list_add_reg (ir.regcache,
7965 I387_MM0_REGNUM (tdep) + ir.rm);
7970 if (i386_record_lea_modrm (&ir))
7975 case 0xf30fb8: /* popcnt */
7976 if (i386_record_modrm (&ir))
7978 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
7979 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7982 case 0x660fd6: /* movq */
7983 if (i386_record_modrm (&ir))
7988 if (!i386_xmm_regnum_p (gdbarch,
7989 I387_XMM0_REGNUM (tdep) + ir.rm))
7991 record_full_arch_list_add_reg (ir.regcache,
7992 I387_XMM0_REGNUM (tdep) + ir.rm);
7997 if (i386_record_lea_modrm (&ir))
8002 case 0x660f3817: /* ptest */
8003 case 0x0f2e: /* ucomiss */
8004 case 0x660f2e: /* ucomisd */
8005 case 0x0f2f: /* comiss */
8006 case 0x660f2f: /* comisd */
8007 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
8010 case 0x0ff7: /* maskmovq */
8011 regcache_raw_read_unsigned (ir.regcache,
8012 ir.regmap[X86_RECORD_REDI_REGNUM],
8014 if (record_full_arch_list_add_mem (addr, 64))
8018 case 0x660ff7: /* maskmovdqu */
8019 regcache_raw_read_unsigned (ir.regcache,
8020 ir.regmap[X86_RECORD_REDI_REGNUM],
8022 if (record_full_arch_list_add_mem (addr, 128))
8037 /* In the future, maybe still need to deal with need_dasm. */
8038 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REIP_REGNUM);
8039 if (record_full_arch_list_add_end ())
8045 printf_unfiltered (_("Process record does not support instruction 0x%02x "
8046 "at address %s.\n"),
8047 (unsigned int) (opcode),
8048 paddress (gdbarch, ir.orig_addr));
8052 static const int i386_record_regmap[] =
8054 I386_EAX_REGNUM, I386_ECX_REGNUM, I386_EDX_REGNUM, I386_EBX_REGNUM,
8055 I386_ESP_REGNUM, I386_EBP_REGNUM, I386_ESI_REGNUM, I386_EDI_REGNUM,
8056 0, 0, 0, 0, 0, 0, 0, 0,
8057 I386_EIP_REGNUM, I386_EFLAGS_REGNUM, I386_CS_REGNUM, I386_SS_REGNUM,
8058 I386_DS_REGNUM, I386_ES_REGNUM, I386_FS_REGNUM, I386_GS_REGNUM
8061 /* Check that the given address appears suitable for a fast
8062 tracepoint, which on x86-64 means that we need an instruction of at
8063 least 5 bytes, so that we can overwrite it with a 4-byte-offset
8064 jump and not have to worry about program jumps to an address in the
8065 middle of the tracepoint jump. On x86, it may be possible to use
8066 4-byte jumps with a 2-byte offset to a trampoline located in the
8067 bottom 64 KiB of memory. Returns 1 if OK, and writes a size
8068 of instruction to replace, and 0 if not, plus an explanatory
8072 i386_fast_tracepoint_valid_at (struct gdbarch *gdbarch,
8073 CORE_ADDR addr, int *isize, char **msg)
8076 static struct ui_file *gdb_null = NULL;
8078 /* Ask the target for the minimum instruction length supported. */
8079 jumplen = target_get_min_fast_tracepoint_insn_len ();
8083 /* If the target does not support the get_min_fast_tracepoint_insn_len
8084 operation, assume that fast tracepoints will always be implemented
8085 using 4-byte relative jumps on both x86 and x86-64. */
8088 else if (jumplen == 0)
8090 /* If the target does support get_min_fast_tracepoint_insn_len but
8091 returns zero, then the IPA has not loaded yet. In this case,
8092 we optimistically assume that truncated 2-byte relative jumps
8093 will be available on x86, and compensate later if this assumption
8094 turns out to be incorrect. On x86-64 architectures, 4-byte relative
8095 jumps will always be used. */
8096 jumplen = (register_size (gdbarch, 0) == 8) ? 5 : 4;
8099 /* Dummy file descriptor for the disassembler. */
8101 gdb_null = ui_file_new ();
8103 /* Check for fit. */
8104 len = gdb_print_insn (gdbarch, addr, gdb_null, NULL);
8110 /* Return a bit of target-specific detail to add to the caller's
8111 generic failure message. */
8113 *msg = xstrprintf (_("; instruction is only %d bytes long, "
8114 "need at least %d bytes for the jump"),
8127 i386_validate_tdesc_p (struct gdbarch_tdep *tdep,
8128 struct tdesc_arch_data *tdesc_data)
8130 const struct target_desc *tdesc = tdep->tdesc;
8131 const struct tdesc_feature *feature_core;
8133 const struct tdesc_feature *feature_sse, *feature_avx, *feature_mpx,
8135 int i, num_regs, valid_p;
8137 if (! tdesc_has_registers (tdesc))
8140 /* Get core registers. */
8141 feature_core = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.core");
8142 if (feature_core == NULL)
8145 /* Get SSE registers. */
8146 feature_sse = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.sse");
8148 /* Try AVX registers. */
8149 feature_avx = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx");
8151 /* Try MPX registers. */
8152 feature_mpx = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.mpx");
8154 /* Try AVX512 registers. */
8155 feature_avx512 = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx512");
8159 /* The XCR0 bits. */
8162 /* AVX512 register description requires AVX register description. */
8166 tdep->xcr0 = I386_XSTATE_MPX_AVX512_MASK;
8168 /* It may have been set by OSABI initialization function. */
8169 if (tdep->k0_regnum < 0)
8171 tdep->k_register_names = i386_k_names;
8172 tdep->k0_regnum = I386_K0_REGNUM;
8175 for (i = 0; i < I387_NUM_K_REGS; i++)
8176 valid_p &= tdesc_numbered_register (feature_avx512, tdesc_data,
8177 tdep->k0_regnum + i,
8180 if (tdep->num_zmm_regs == 0)
8182 tdep->zmmh_register_names = i386_zmmh_names;
8183 tdep->num_zmm_regs = 8;
8184 tdep->zmm0h_regnum = I386_ZMM0H_REGNUM;
8187 for (i = 0; i < tdep->num_zmm_regs; i++)
8188 valid_p &= tdesc_numbered_register (feature_avx512, tdesc_data,
8189 tdep->zmm0h_regnum + i,
8190 tdep->zmmh_register_names[i]);
8192 for (i = 0; i < tdep->num_xmm_avx512_regs; i++)
8193 valid_p &= tdesc_numbered_register (feature_avx512, tdesc_data,
8194 tdep->xmm16_regnum + i,
8195 tdep->xmm_avx512_register_names[i]);
8197 for (i = 0; i < tdep->num_ymm_avx512_regs; i++)
8198 valid_p &= tdesc_numbered_register (feature_avx512, tdesc_data,
8199 tdep->ymm16h_regnum + i,
8200 tdep->ymm16h_register_names[i]);
8204 /* AVX register description requires SSE register description. */
8208 if (!feature_avx512)
8209 tdep->xcr0 = I386_XSTATE_AVX_MASK;
8211 /* It may have been set by OSABI initialization function. */
8212 if (tdep->num_ymm_regs == 0)
8214 tdep->ymmh_register_names = i386_ymmh_names;
8215 tdep->num_ymm_regs = 8;
8216 tdep->ymm0h_regnum = I386_YMM0H_REGNUM;
8219 for (i = 0; i < tdep->num_ymm_regs; i++)
8220 valid_p &= tdesc_numbered_register (feature_avx, tdesc_data,
8221 tdep->ymm0h_regnum + i,
8222 tdep->ymmh_register_names[i]);
8224 else if (feature_sse)
8225 tdep->xcr0 = I386_XSTATE_SSE_MASK;
8228 tdep->xcr0 = I386_XSTATE_X87_MASK;
8229 tdep->num_xmm_regs = 0;
8232 num_regs = tdep->num_core_regs;
8233 for (i = 0; i < num_regs; i++)
8234 valid_p &= tdesc_numbered_register (feature_core, tdesc_data, i,
8235 tdep->register_names[i]);
8239 /* Need to include %mxcsr, so add one. */
8240 num_regs += tdep->num_xmm_regs + 1;
8241 for (; i < num_regs; i++)
8242 valid_p &= tdesc_numbered_register (feature_sse, tdesc_data, i,
8243 tdep->register_names[i]);
8248 tdep->xcr0 |= I386_XSTATE_MPX_MASK;
8250 if (tdep->bnd0r_regnum < 0)
8252 tdep->mpx_register_names = i386_mpx_names;
8253 tdep->bnd0r_regnum = I386_BND0R_REGNUM;
8254 tdep->bndcfgu_regnum = I386_BNDCFGU_REGNUM;
8257 for (i = 0; i < I387_NUM_MPX_REGS; i++)
8258 valid_p &= tdesc_numbered_register (feature_mpx, tdesc_data,
8259 I387_BND0R_REGNUM (tdep) + i,
8260 tdep->mpx_register_names[i]);
8267 static struct gdbarch *
8268 i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
8270 struct gdbarch_tdep *tdep;
8271 struct gdbarch *gdbarch;
8272 struct tdesc_arch_data *tdesc_data;
8273 const struct target_desc *tdesc;
8281 /* If there is already a candidate, use it. */
8282 arches = gdbarch_list_lookup_by_info (arches, &info);
8284 return arches->gdbarch;
8286 /* Allocate space for the new architecture. */
8287 tdep = XCNEW (struct gdbarch_tdep);
8288 gdbarch = gdbarch_alloc (&info, tdep);
8290 /* General-purpose registers. */
8291 tdep->gregset_reg_offset = NULL;
8292 tdep->gregset_num_regs = I386_NUM_GREGS;
8293 tdep->sizeof_gregset = 0;
8295 /* Floating-point registers. */
8296 tdep->sizeof_fpregset = I387_SIZEOF_FSAVE;
8298 /* The default settings include the FPU registers, the MMX registers
8299 and the SSE registers. This can be overridden for a specific ABI
8300 by adjusting the members `st0_regnum', `mm0_regnum' and
8301 `num_xmm_regs' of `struct gdbarch_tdep', otherwise the registers
8302 will show up in the output of "info all-registers". */
8304 tdep->st0_regnum = I386_ST0_REGNUM;
8306 /* I386_NUM_XREGS includes %mxcsr, so substract one. */
8307 tdep->num_xmm_regs = I386_NUM_XREGS - 1;
8309 tdep->jb_pc_offset = -1;
8310 tdep->struct_return = pcc_struct_return;
8311 tdep->sigtramp_start = 0;
8312 tdep->sigtramp_end = 0;
8313 tdep->sigtramp_p = i386_sigtramp_p;
8314 tdep->sigcontext_addr = NULL;
8315 tdep->sc_reg_offset = NULL;
8316 tdep->sc_pc_offset = -1;
8317 tdep->sc_sp_offset = -1;
8319 tdep->xsave_xcr0_offset = -1;
8321 tdep->record_regmap = i386_record_regmap;
8323 set_gdbarch_long_long_align_bit (gdbarch, 32);
8325 /* The format used for `long double' on almost all i386 targets is
8326 the i387 extended floating-point format. In fact, of all targets
8327 in the GCC 2.95 tree, only OSF/1 does it different, and insists
8328 on having a `long double' that's not `long' at all. */
8329 set_gdbarch_long_double_format (gdbarch, floatformats_i387_ext);
8331 /* Although the i387 extended floating-point has only 80 significant
8332 bits, a `long double' actually takes up 96, probably to enforce
8334 set_gdbarch_long_double_bit (gdbarch, 96);
8336 /* Register numbers of various important registers. */
8337 set_gdbarch_sp_regnum (gdbarch, I386_ESP_REGNUM); /* %esp */
8338 set_gdbarch_pc_regnum (gdbarch, I386_EIP_REGNUM); /* %eip */
8339 set_gdbarch_ps_regnum (gdbarch, I386_EFLAGS_REGNUM); /* %eflags */
8340 set_gdbarch_fp0_regnum (gdbarch, I386_ST0_REGNUM); /* %st(0) */
8342 /* NOTE: kettenis/20040418: GCC does have two possible register
8343 numbering schemes on the i386: dbx and SVR4. These schemes
8344 differ in how they number %ebp, %esp, %eflags, and the
8345 floating-point registers, and are implemented by the arrays
8346 dbx_register_map[] and svr4_dbx_register_map in
8347 gcc/config/i386.c. GCC also defines a third numbering scheme in
8348 gcc/config/i386.c, which it designates as the "default" register
8349 map used in 64bit mode. This last register numbering scheme is
8350 implemented in dbx64_register_map, and is used for AMD64; see
8353 Currently, each GCC i386 target always uses the same register
8354 numbering scheme across all its supported debugging formats
8355 i.e. SDB (COFF), stabs and DWARF 2. This is because
8356 gcc/sdbout.c, gcc/dbxout.c and gcc/dwarf2out.c all use the
8357 DBX_REGISTER_NUMBER macro which is defined by each target's
8358 respective config header in a manner independent of the requested
8359 output debugging format.
8361 This does not match the arrangement below, which presumes that
8362 the SDB and stabs numbering schemes differ from the DWARF and
8363 DWARF 2 ones. The reason for this arrangement is that it is
8364 likely to get the numbering scheme for the target's
8365 default/native debug format right. For targets where GCC is the
8366 native compiler (FreeBSD, NetBSD, OpenBSD, GNU/Linux) or for
8367 targets where the native toolchain uses a different numbering
8368 scheme for a particular debug format (stabs-in-ELF on Solaris)
8369 the defaults below will have to be overridden, like
8370 i386_elf_init_abi() does. */
8372 /* Use the dbx register numbering scheme for stabs and COFF. */
8373 set_gdbarch_stab_reg_to_regnum (gdbarch, i386_dbx_reg_to_regnum);
8374 set_gdbarch_sdb_reg_to_regnum (gdbarch, i386_dbx_reg_to_regnum);
8376 /* Use the SVR4 register numbering scheme for DWARF 2. */
8377 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);
8379 /* We don't set gdbarch_stab_reg_to_regnum, since ECOFF doesn't seem to
8380 be in use on any of the supported i386 targets. */
8382 set_gdbarch_print_float_info (gdbarch, i387_print_float_info);
8384 set_gdbarch_get_longjmp_target (gdbarch, i386_get_longjmp_target);
8386 /* Call dummy code. */
8387 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
8388 set_gdbarch_push_dummy_code (gdbarch, i386_push_dummy_code);
8389 set_gdbarch_push_dummy_call (gdbarch, i386_push_dummy_call);
8390 set_gdbarch_frame_align (gdbarch, i386_frame_align);
8392 set_gdbarch_convert_register_p (gdbarch, i386_convert_register_p);
8393 set_gdbarch_register_to_value (gdbarch, i386_register_to_value);
8394 set_gdbarch_value_to_register (gdbarch, i386_value_to_register);
8396 set_gdbarch_return_value (gdbarch, i386_return_value);
8398 set_gdbarch_skip_prologue (gdbarch, i386_skip_prologue);
8400 /* Stack grows downward. */
8401 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
8403 set_gdbarch_breakpoint_from_pc (gdbarch, i386_breakpoint_from_pc);
8404 set_gdbarch_decr_pc_after_break (gdbarch, 1);
8405 set_gdbarch_max_insn_length (gdbarch, I386_MAX_INSN_LEN);
8407 set_gdbarch_frame_args_skip (gdbarch, 8);
8409 set_gdbarch_print_insn (gdbarch, i386_print_insn);
8411 set_gdbarch_dummy_id (gdbarch, i386_dummy_id);
8413 set_gdbarch_unwind_pc (gdbarch, i386_unwind_pc);
8415 /* Add the i386 register groups. */
8416 i386_add_reggroups (gdbarch);
8417 tdep->register_reggroup_p = i386_register_reggroup_p;
8419 /* Helper for function argument information. */
8420 set_gdbarch_fetch_pointer_argument (gdbarch, i386_fetch_pointer_argument);
8422 /* Hook the function epilogue frame unwinder. This unwinder is
8423 appended to the list first, so that it supercedes the DWARF
8424 unwinder in function epilogues (where the DWARF unwinder
8425 currently fails). */
8426 frame_unwind_append_unwinder (gdbarch, &i386_epilogue_frame_unwind);
8428 /* Hook in the DWARF CFI frame unwinder. This unwinder is appended
8429 to the list before the prologue-based unwinders, so that DWARF
8430 CFI info will be used if it is available. */
8431 dwarf2_append_unwinders (gdbarch);
8433 frame_base_set_default (gdbarch, &i386_frame_base);
8435 /* Pseudo registers may be changed by amd64_init_abi. */
8436 set_gdbarch_pseudo_register_read_value (gdbarch,
8437 i386_pseudo_register_read_value);
8438 set_gdbarch_pseudo_register_write (gdbarch, i386_pseudo_register_write);
8440 set_tdesc_pseudo_register_type (gdbarch, i386_pseudo_register_type);
8441 set_tdesc_pseudo_register_name (gdbarch, i386_pseudo_register_name);
8443 /* Override the normal target description method to make the AVX
8444 upper halves anonymous. */
8445 set_gdbarch_register_name (gdbarch, i386_register_name);
8447 /* Even though the default ABI only includes general-purpose registers,
8448 floating-point registers and the SSE registers, we have to leave a
8449 gap for the upper AVX, MPX and AVX512 registers. */
8450 set_gdbarch_num_regs (gdbarch, I386_AVX512_NUM_REGS);
8452 /* Get the x86 target description from INFO. */
8453 tdesc = info.target_desc;
8454 if (! tdesc_has_registers (tdesc))
8456 tdep->tdesc = tdesc;
8458 tdep->num_core_regs = I386_NUM_GREGS + I387_NUM_REGS;
8459 tdep->register_names = i386_register_names;
8461 /* No upper YMM registers. */
8462 tdep->ymmh_register_names = NULL;
8463 tdep->ymm0h_regnum = -1;
8465 /* No upper ZMM registers. */
8466 tdep->zmmh_register_names = NULL;
8467 tdep->zmm0h_regnum = -1;
8469 /* No high XMM registers. */
8470 tdep->xmm_avx512_register_names = NULL;
8471 tdep->xmm16_regnum = -1;
8473 /* No upper YMM16-31 registers. */
8474 tdep->ymm16h_register_names = NULL;
8475 tdep->ymm16h_regnum = -1;
8477 tdep->num_byte_regs = 8;
8478 tdep->num_word_regs = 8;
8479 tdep->num_dword_regs = 0;
8480 tdep->num_mmx_regs = 8;
8481 tdep->num_ymm_regs = 0;
8483 /* No MPX registers. */
8484 tdep->bnd0r_regnum = -1;
8485 tdep->bndcfgu_regnum = -1;
8487 /* No AVX512 registers. */
8488 tdep->k0_regnum = -1;
8489 tdep->num_zmm_regs = 0;
8490 tdep->num_ymm_avx512_regs = 0;
8491 tdep->num_xmm_avx512_regs = 0;
8493 tdesc_data = tdesc_data_alloc ();
8495 set_gdbarch_relocate_instruction (gdbarch, i386_relocate_instruction);
8497 set_gdbarch_gen_return_address (gdbarch, i386_gen_return_address);
8499 set_gdbarch_insn_is_call (gdbarch, i386_insn_is_call);
8500 set_gdbarch_insn_is_ret (gdbarch, i386_insn_is_ret);
8501 set_gdbarch_insn_is_jump (gdbarch, i386_insn_is_jump);
8503 /* Hook in ABI-specific overrides, if they have been registered. */
8504 info.tdep_info = (void *) tdesc_data;
8505 gdbarch_init_osabi (info, gdbarch);
8507 if (!i386_validate_tdesc_p (tdep, tdesc_data))
8509 tdesc_data_cleanup (tdesc_data);
8511 gdbarch_free (gdbarch);
8515 num_bnd_cooked = (tdep->bnd0r_regnum > 0 ? I387_NUM_BND_REGS : 0);
8517 /* Wire in pseudo registers. Number of pseudo registers may be
8519 set_gdbarch_num_pseudo_regs (gdbarch, (tdep->num_byte_regs
8520 + tdep->num_word_regs
8521 + tdep->num_dword_regs
8522 + tdep->num_mmx_regs
8523 + tdep->num_ymm_regs
8525 + tdep->num_ymm_avx512_regs
8526 + tdep->num_zmm_regs));
8528 /* Target description may be changed. */
8529 tdesc = tdep->tdesc;
8531 tdesc_use_registers (gdbarch, tdesc, tdesc_data);
8533 /* Override gdbarch_register_reggroup_p set in tdesc_use_registers. */
8534 set_gdbarch_register_reggroup_p (gdbarch, tdep->register_reggroup_p);
8536 /* Make %al the first pseudo-register. */
8537 tdep->al_regnum = gdbarch_num_regs (gdbarch);
8538 tdep->ax_regnum = tdep->al_regnum + tdep->num_byte_regs;
8540 ymm0_regnum = tdep->ax_regnum + tdep->num_word_regs;
8541 if (tdep->num_dword_regs)
8543 /* Support dword pseudo-register if it hasn't been disabled. */
8544 tdep->eax_regnum = ymm0_regnum;
8545 ymm0_regnum += tdep->num_dword_regs;
8548 tdep->eax_regnum = -1;
8550 mm0_regnum = ymm0_regnum;
8551 if (tdep->num_ymm_regs)
8553 /* Support YMM pseudo-register if it is available. */
8554 tdep->ymm0_regnum = ymm0_regnum;
8555 mm0_regnum += tdep->num_ymm_regs;
8558 tdep->ymm0_regnum = -1;
8560 if (tdep->num_ymm_avx512_regs)
8562 /* Support YMM16-31 pseudo registers if available. */
8563 tdep->ymm16_regnum = mm0_regnum;
8564 mm0_regnum += tdep->num_ymm_avx512_regs;
8567 tdep->ymm16_regnum = -1;
8569 if (tdep->num_zmm_regs)
8571 /* Support ZMM pseudo-register if it is available. */
8572 tdep->zmm0_regnum = mm0_regnum;
8573 mm0_regnum += tdep->num_zmm_regs;
8576 tdep->zmm0_regnum = -1;
8578 bnd0_regnum = mm0_regnum;
8579 if (tdep->num_mmx_regs != 0)
8581 /* Support MMX pseudo-register if MMX hasn't been disabled. */
8582 tdep->mm0_regnum = mm0_regnum;
8583 bnd0_regnum += tdep->num_mmx_regs;
8586 tdep->mm0_regnum = -1;
8588 if (tdep->bnd0r_regnum > 0)
8589 tdep->bnd0_regnum = bnd0_regnum;
8591 tdep-> bnd0_regnum = -1;
8593 /* Hook in the legacy prologue-based unwinders last (fallback). */
8594 frame_unwind_append_unwinder (gdbarch, &i386_stack_tramp_frame_unwind);
8595 frame_unwind_append_unwinder (gdbarch, &i386_sigtramp_frame_unwind);
8596 frame_unwind_append_unwinder (gdbarch, &i386_frame_unwind);
8598 /* If we have a register mapping, enable the generic core file
8599 support, unless it has already been enabled. */
8600 if (tdep->gregset_reg_offset
8601 && !gdbarch_regset_from_core_section_p (gdbarch))
8602 set_gdbarch_regset_from_core_section (gdbarch,
8603 i386_regset_from_core_section);
8605 set_gdbarch_skip_permanent_breakpoint (gdbarch,
8606 i386_skip_permanent_breakpoint);
8608 set_gdbarch_fast_tracepoint_valid_at (gdbarch,
8609 i386_fast_tracepoint_valid_at);
8614 static enum gdb_osabi
8615 i386_coff_osabi_sniffer (bfd *abfd)
8617 if (strcmp (bfd_get_target (abfd), "coff-go32-exe") == 0
8618 || strcmp (bfd_get_target (abfd), "coff-go32") == 0)
8619 return GDB_OSABI_GO32;
8621 return GDB_OSABI_UNKNOWN;
8625 /* Provide a prototype to silence -Wmissing-prototypes. */
8626 void _initialize_i386_tdep (void);
8629 _initialize_i386_tdep (void)
8631 register_gdbarch_init (bfd_arch_i386, i386_gdbarch_init);
8633 /* Add the variable that controls the disassembly flavor. */
8634 add_setshow_enum_cmd ("disassembly-flavor", no_class, valid_flavors,
8635 &disassembly_flavor, _("\
8636 Set the disassembly flavor."), _("\
8637 Show the disassembly flavor."), _("\
8638 The valid values are \"att\" and \"intel\", and the default value is \"att\"."),
8640 NULL, /* FIXME: i18n: */
8641 &setlist, &showlist);
8643 /* Add the variable that controls the convention for returning
8645 add_setshow_enum_cmd ("struct-convention", no_class, valid_conventions,
8646 &struct_convention, _("\
8647 Set the convention for returning small structs."), _("\
8648 Show the convention for returning small structs."), _("\
8649 Valid values are \"default\", \"pcc\" and \"reg\", and the default value\n\
8652 NULL, /* FIXME: i18n: */
8653 &setlist, &showlist);
8655 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour,
8656 i386_coff_osabi_sniffer);
8658 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_SVR4,
8659 i386_svr4_init_abi);
8660 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_GO32,
8661 i386_go32_init_abi);
8663 /* Initialize the i386-specific register groups. */
8664 i386_init_reggroups ();
8666 /* Initialize the standard target descriptions. */
8667 initialize_tdesc_i386 ();
8668 initialize_tdesc_i386_mmx ();
8669 initialize_tdesc_i386_avx ();
8670 initialize_tdesc_i386_mpx ();
8671 initialize_tdesc_i386_avx512 ();
8673 /* Tell remote stub that we support XML target description. */
8674 register_remote_support_xml ("i386");