More updated translations
[binutils-gdb.git] / gdb / i386-tdep.c
blob1d6d5925de4e8b6ab8bd920f14c533e03e4dea8b
1 /* Intel 386 target-dependent stuff.
3 Copyright (C) 1988-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "extract-store-integer.h"
21 #include "opcode/i386.h"
22 #include "arch-utils.h"
23 #include "command.h"
24 #include "dummy-frame.h"
25 #include "dwarf2/frame.h"
26 #include "frame.h"
27 #include "frame-base.h"
28 #include "frame-unwind.h"
29 #include "inferior.h"
30 #include "infrun.h"
31 #include "cli/cli-cmds.h"
32 #include "gdbcore.h"
33 #include "gdbtypes.h"
34 #include "objfiles.h"
35 #include "osabi.h"
36 #include "regcache.h"
37 #include "reggroups.h"
38 #include "regset.h"
39 #include "symfile.h"
40 #include "symtab.h"
41 #include "target.h"
42 #include "target-float.h"
43 #include "value.h"
44 #include "dis-asm.h"
45 #include "disasm.h"
46 #include "remote.h"
47 #include "i386-tdep.h"
48 #include "i387-tdep.h"
49 #include "gdbsupport/x86-xstate.h"
50 #include "x86-tdep.h"
51 #include "expop.h"
53 #include "record.h"
54 #include "record-full.h"
55 #include "target-descriptions.h"
56 #include "arch/i386.h"
58 #include "ax.h"
59 #include "ax-gdb.h"
61 #include "stap-probe.h"
62 #include "user-regs.h"
63 #include "cli/cli-utils.h"
64 #include "expression.h"
65 #include "parser-defs.h"
66 #include <ctype.h>
67 #include <algorithm>
68 #include <unordered_set>
69 #include "producer.h"
70 #include "infcall.h"
71 #include "maint.h"
73 /* Register names. */
75 static const char * const i386_register_names[] =
77 "eax", "ecx", "edx", "ebx",
78 "esp", "ebp", "esi", "edi",
79 "eip", "eflags", "cs", "ss",
80 "ds", "es", "fs", "gs",
81 "st0", "st1", "st2", "st3",
82 "st4", "st5", "st6", "st7",
83 "fctrl", "fstat", "ftag", "fiseg",
84 "fioff", "foseg", "fooff", "fop",
85 "xmm0", "xmm1", "xmm2", "xmm3",
86 "xmm4", "xmm5", "xmm6", "xmm7",
87 "mxcsr"
90 static const char * const i386_zmm_names[] =
92 "zmm0", "zmm1", "zmm2", "zmm3",
93 "zmm4", "zmm5", "zmm6", "zmm7"
96 static const char * const i386_zmmh_names[] =
98 "zmm0h", "zmm1h", "zmm2h", "zmm3h",
99 "zmm4h", "zmm5h", "zmm6h", "zmm7h"
102 static const char * const i386_k_names[] =
104 "k0", "k1", "k2", "k3",
105 "k4", "k5", "k6", "k7"
108 static const char * const i386_ymm_names[] =
110 "ymm0", "ymm1", "ymm2", "ymm3",
111 "ymm4", "ymm5", "ymm6", "ymm7",
114 static const char * const i386_ymmh_names[] =
116 "ymm0h", "ymm1h", "ymm2h", "ymm3h",
117 "ymm4h", "ymm5h", "ymm6h", "ymm7h",
121 static const char * const i386_pkeys_names[] =
123 "pkru"
126 /* Register names for MMX pseudo-registers. */
128 static const char * const i386_mmx_names[] =
130 "mm0", "mm1", "mm2", "mm3",
131 "mm4", "mm5", "mm6", "mm7"
134 /* Register names for byte pseudo-registers. */
136 static const char * const i386_byte_names[] =
138 "al", "cl", "dl", "bl",
139 "ah", "ch", "dh", "bh"
142 /* Register names for word pseudo-registers. */
144 static const char * const i386_word_names[] =
146 "ax", "cx", "dx", "bx",
147 "", "bp", "si", "di"
150 /* Constant used for reading/writing pseudo registers. In 64-bit mode, we have
151 16 lower ZMM regs that extend corresponding xmm/ymm registers. In addition,
152 we have 16 upper ZMM regs that have to be handled differently. */
154 const int num_lower_zmm_regs = 16;
156 /* MMX register? */
158 static int
159 i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
161 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
162 int mm0_regnum = tdep->mm0_regnum;
164 if (mm0_regnum < 0)
165 return 0;
167 regnum -= mm0_regnum;
168 return regnum >= 0 && regnum < tdep->num_mmx_regs;
171 /* Byte register? */
174 i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
176 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
178 regnum -= tdep->al_regnum;
179 return regnum >= 0 && regnum < tdep->num_byte_regs;
182 /* Word register? */
185 i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
187 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
189 regnum -= tdep->ax_regnum;
190 return regnum >= 0 && regnum < tdep->num_word_regs;
193 /* Dword register? */
196 i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
198 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
199 int eax_regnum = tdep->eax_regnum;
201 if (eax_regnum < 0)
202 return 0;
204 regnum -= eax_regnum;
205 return regnum >= 0 && regnum < tdep->num_dword_regs;
208 /* AVX512 register? */
211 i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
213 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
214 int zmm0h_regnum = tdep->zmm0h_regnum;
216 if (zmm0h_regnum < 0)
217 return 0;
219 regnum -= zmm0h_regnum;
220 return regnum >= 0 && regnum < tdep->num_zmm_regs;
224 i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
226 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
227 int zmm0_regnum = tdep->zmm0_regnum;
229 if (zmm0_regnum < 0)
230 return 0;
232 regnum -= zmm0_regnum;
233 return regnum >= 0 && regnum < tdep->num_zmm_regs;
237 i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
239 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
240 int k0_regnum = tdep->k0_regnum;
242 if (k0_regnum < 0)
243 return 0;
245 regnum -= k0_regnum;
246 return regnum >= 0 && regnum < I387_NUM_K_REGS;
249 static int
250 i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
252 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
253 int ymm0h_regnum = tdep->ymm0h_regnum;
255 if (ymm0h_regnum < 0)
256 return 0;
258 regnum -= ymm0h_regnum;
259 return regnum >= 0 && regnum < tdep->num_ymm_regs;
262 /* AVX register? */
265 i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
267 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
268 int ymm0_regnum = tdep->ymm0_regnum;
270 if (ymm0_regnum < 0)
271 return 0;
273 regnum -= ymm0_regnum;
274 return regnum >= 0 && regnum < tdep->num_ymm_regs;
277 static int
278 i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
280 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
281 int ymm16h_regnum = tdep->ymm16h_regnum;
283 if (ymm16h_regnum < 0)
284 return 0;
286 regnum -= ymm16h_regnum;
287 return regnum >= 0 && regnum < tdep->num_ymm_avx512_regs;
291 i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
293 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
294 int ymm16_regnum = tdep->ymm16_regnum;
296 if (ymm16_regnum < 0)
297 return 0;
299 regnum -= ymm16_regnum;
300 return regnum >= 0 && regnum < tdep->num_ymm_avx512_regs;
303 /* SSE register? */
306 i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
308 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
309 int num_xmm_regs = I387_NUM_XMM_REGS (tdep);
311 if (num_xmm_regs == 0)
312 return 0;
314 regnum -= I387_XMM0_REGNUM (tdep);
315 return regnum >= 0 && regnum < num_xmm_regs;
318 /* XMM_512 register? */
321 i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
323 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
324 int num_xmm_avx512_regs = I387_NUM_XMM_AVX512_REGS (tdep);
326 if (num_xmm_avx512_regs == 0)
327 return 0;
329 regnum -= I387_XMM16_REGNUM (tdep);
330 return regnum >= 0 && regnum < num_xmm_avx512_regs;
333 static int
334 i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
336 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
338 if (I387_NUM_XMM_REGS (tdep) == 0)
339 return 0;
341 return (regnum == I387_MXCSR_REGNUM (tdep));
344 /* FP register? */
347 i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
349 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
351 if (I387_ST0_REGNUM (tdep) < 0)
352 return 0;
354 return (I387_ST0_REGNUM (tdep) <= regnum
355 && regnum < I387_FCTRL_REGNUM (tdep));
359 i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
361 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
363 if (I387_ST0_REGNUM (tdep) < 0)
364 return 0;
366 return (I387_FCTRL_REGNUM (tdep) <= regnum
367 && regnum < I387_XMM0_REGNUM (tdep));
370 /* PKRU register? */
372 bool
373 i386_pkru_regnum_p (struct gdbarch *gdbarch, int regnum)
375 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
376 int pkru_regnum = tdep->pkru_regnum;
378 if (pkru_regnum < 0)
379 return false;
381 regnum -= pkru_regnum;
382 return regnum >= 0 && regnum < I387_NUM_PKEYS_REGS;
385 /* Return the name of register REGNUM, or the empty string if it is
386 an anonymous register. */
388 static const char *
389 i386_register_name (struct gdbarch *gdbarch, int regnum)
391 /* Hide the upper YMM registers. */
392 if (i386_ymmh_regnum_p (gdbarch, regnum))
393 return "";
395 /* Hide the upper YMM16-31 registers. */
396 if (i386_ymmh_avx512_regnum_p (gdbarch, regnum))
397 return "";
399 /* Hide the upper ZMM registers. */
400 if (i386_zmmh_regnum_p (gdbarch, regnum))
401 return "";
403 return tdesc_register_name (gdbarch, regnum);
406 /* Return the name of register REGNUM. */
408 const char *
409 i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
411 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
412 if (i386_mmx_regnum_p (gdbarch, regnum))
413 return i386_mmx_names[regnum - I387_MM0_REGNUM (tdep)];
414 else if (i386_ymm_regnum_p (gdbarch, regnum))
415 return i386_ymm_names[regnum - tdep->ymm0_regnum];
416 else if (i386_zmm_regnum_p (gdbarch, regnum))
417 return i386_zmm_names[regnum - tdep->zmm0_regnum];
418 else if (i386_byte_regnum_p (gdbarch, regnum))
419 return i386_byte_names[regnum - tdep->al_regnum];
420 else if (i386_word_regnum_p (gdbarch, regnum))
421 return i386_word_names[regnum - tdep->ax_regnum];
423 internal_error (_("invalid regnum"));
426 /* Convert a dbx register number REG to the appropriate register
427 number used by GDB. */
429 static int
430 i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
432 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
434 /* This implements what GCC calls the "default" register map
435 (dbx_register_map[]). */
437 if (reg >= 0 && reg <= 7)
439 /* General-purpose registers. The debug info calls %ebp
440 register 4, and %esp register 5. */
441 if (reg == 4)
442 return 5;
443 else if (reg == 5)
444 return 4;
445 else return reg;
447 else if (reg >= 12 && reg <= 19)
449 /* Floating-point registers. */
450 return reg - 12 + I387_ST0_REGNUM (tdep);
452 else if (reg >= 21 && reg <= 28)
454 /* SSE registers. */
455 int ymm0_regnum = tdep->ymm0_regnum;
457 if (ymm0_regnum >= 0
458 && i386_xmm_regnum_p (gdbarch, reg))
459 return reg - 21 + ymm0_regnum;
460 else
461 return reg - 21 + I387_XMM0_REGNUM (tdep);
463 else if (reg >= 29 && reg <= 36)
465 /* MMX registers. */
466 return reg - 29 + I387_MM0_REGNUM (tdep);
469 /* This will hopefully provoke a warning. */
470 return gdbarch_num_cooked_regs (gdbarch);
473 /* Convert SVR4 DWARF register number REG to the appropriate register number
474 used by GDB. */
476 static int
477 i386_svr4_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
479 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
481 /* This implements the GCC register map that tries to be compatible
482 with the SVR4 C compiler for DWARF (svr4_dbx_register_map[]). */
484 /* The SVR4 register numbering includes %eip and %eflags, and
485 numbers the floating point registers differently. */
486 if (reg >= 0 && reg <= 9)
488 /* General-purpose registers. */
489 return reg;
491 else if (reg >= 11 && reg <= 18)
493 /* Floating-point registers. */
494 return reg - 11 + I387_ST0_REGNUM (tdep);
496 else if (reg >= 21 && reg <= 36)
498 /* The SSE and MMX registers have the same numbers as with dbx. */
499 return i386_dbx_reg_to_regnum (gdbarch, reg);
502 switch (reg)
504 case 37: return I387_FCTRL_REGNUM (tdep);
505 case 38: return I387_FSTAT_REGNUM (tdep);
506 case 39: return I387_MXCSR_REGNUM (tdep);
507 case 40: return I386_ES_REGNUM;
508 case 41: return I386_CS_REGNUM;
509 case 42: return I386_SS_REGNUM;
510 case 43: return I386_DS_REGNUM;
511 case 44: return I386_FS_REGNUM;
512 case 45: return I386_GS_REGNUM;
515 return -1;
518 /* Wrapper on i386_svr4_dwarf_reg_to_regnum to return
519 num_regs + num_pseudo_regs for other debug formats. */
522 i386_svr4_reg_to_regnum (struct gdbarch *gdbarch, int reg)
524 int regnum = i386_svr4_dwarf_reg_to_regnum (gdbarch, reg);
526 if (regnum == -1)
527 return gdbarch_num_cooked_regs (gdbarch);
528 return regnum;
533 /* This is the variable that is set with "set disassembly-flavor", and
534 its legitimate values. */
535 static const char att_flavor[] = "att";
536 static const char intel_flavor[] = "intel";
537 static const char *const valid_flavors[] =
539 att_flavor,
540 intel_flavor,
541 NULL
543 static const char *disassembly_flavor = att_flavor;
546 /* Use the program counter to determine the contents and size of a
547 breakpoint instruction. Return a pointer to a string of bytes that
548 encode a breakpoint instruction, store the length of the string in
549 *LEN and optionally adjust *PC to point to the correct memory
550 location for inserting the breakpoint.
552 On the i386 we have a single breakpoint that fits in a single byte
553 and can be inserted anywhere.
555 This function is 64-bit safe. */
557 constexpr gdb_byte i386_break_insn[] = { 0xcc }; /* int 3 */
559 typedef BP_MANIPULATION (i386_break_insn) i386_breakpoint;
562 /* Displaced instruction handling. */
564 /* Skip the legacy instruction prefixes in INSN.
565 Not all prefixes are valid for any particular insn
566 but we needn't care, the insn will fault if it's invalid.
567 The result is a pointer to the first opcode byte,
568 or NULL if we run off the end of the buffer. */
570 static gdb_byte *
571 i386_skip_prefixes (gdb_byte *insn, size_t max_len)
573 gdb_byte *end = insn + max_len;
575 while (insn < end)
577 switch (*insn)
579 case DATA_PREFIX_OPCODE:
580 case ADDR_PREFIX_OPCODE:
581 case CS_PREFIX_OPCODE:
582 case DS_PREFIX_OPCODE:
583 case ES_PREFIX_OPCODE:
584 case FS_PREFIX_OPCODE:
585 case GS_PREFIX_OPCODE:
586 case SS_PREFIX_OPCODE:
587 case LOCK_PREFIX_OPCODE:
588 case REPE_PREFIX_OPCODE:
589 case REPNE_PREFIX_OPCODE:
590 ++insn;
591 continue;
592 default:
593 return insn;
597 return NULL;
600 static int
601 i386_absolute_jmp_p (const gdb_byte *insn)
603 /* jmp far (absolute address in operand). */
604 if (insn[0] == 0xea)
605 return 1;
607 if (insn[0] == 0xff)
609 /* jump near, absolute indirect (/4). */
610 if ((insn[1] & 0x38) == 0x20)
611 return 1;
613 /* jump far, absolute indirect (/5). */
614 if ((insn[1] & 0x38) == 0x28)
615 return 1;
618 return 0;
621 /* Return non-zero if INSN is a jump, zero otherwise. */
623 static int
624 i386_jmp_p (const gdb_byte *insn)
626 /* jump short, relative. */
627 if (insn[0] == 0xeb)
628 return 1;
630 /* jump near, relative. */
631 if (insn[0] == 0xe9)
632 return 1;
634 return i386_absolute_jmp_p (insn);
637 static int
638 i386_absolute_call_p (const gdb_byte *insn)
640 /* call far, absolute. */
641 if (insn[0] == 0x9a)
642 return 1;
644 if (insn[0] == 0xff)
646 /* Call near, absolute indirect (/2). */
647 if ((insn[1] & 0x38) == 0x10)
648 return 1;
650 /* Call far, absolute indirect (/3). */
651 if ((insn[1] & 0x38) == 0x18)
652 return 1;
655 return 0;
658 static int
659 i386_ret_p (const gdb_byte *insn)
661 switch (insn[0])
663 case 0xc2: /* ret near, pop N bytes. */
664 case 0xc3: /* ret near */
665 case 0xca: /* ret far, pop N bytes. */
666 case 0xcb: /* ret far */
667 case 0xcf: /* iret */
668 return 1;
670 default:
671 return 0;
675 static int
676 i386_call_p (const gdb_byte *insn)
678 if (i386_absolute_call_p (insn))
679 return 1;
681 /* call near, relative. */
682 if (insn[0] == 0xe8)
683 return 1;
685 return 0;
688 /* Return non-zero if INSN is a system call, and set *LENGTHP to its
689 length in bytes. Otherwise, return zero. */
691 static int
692 i386_syscall_p (const gdb_byte *insn, int *lengthp)
694 /* Is it 'int $0x80'? */
695 if ((insn[0] == 0xcd && insn[1] == 0x80)
696 /* Or is it 'sysenter'? */
697 || (insn[0] == 0x0f && insn[1] == 0x34)
698 /* Or is it 'syscall'? */
699 || (insn[0] == 0x0f && insn[1] == 0x05))
701 *lengthp = 2;
702 return 1;
705 return 0;
708 /* The gdbarch insn_is_call method. */
710 static int
711 i386_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
713 gdb_byte buf[I386_MAX_INSN_LEN], *insn;
715 read_code (addr, buf, I386_MAX_INSN_LEN);
716 insn = i386_skip_prefixes (buf, I386_MAX_INSN_LEN);
718 return i386_call_p (insn);
721 /* The gdbarch insn_is_ret method. */
723 static int
724 i386_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
726 gdb_byte buf[I386_MAX_INSN_LEN], *insn;
728 read_code (addr, buf, I386_MAX_INSN_LEN);
729 insn = i386_skip_prefixes (buf, I386_MAX_INSN_LEN);
731 return i386_ret_p (insn);
734 /* The gdbarch insn_is_jump method. */
736 static int
737 i386_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
739 gdb_byte buf[I386_MAX_INSN_LEN], *insn;
741 read_code (addr, buf, I386_MAX_INSN_LEN);
742 insn = i386_skip_prefixes (buf, I386_MAX_INSN_LEN);
744 return i386_jmp_p (insn);
747 /* Some kernels may run one past a syscall insn, so we have to cope. */
749 displaced_step_copy_insn_closure_up
750 i386_displaced_step_copy_insn (struct gdbarch *gdbarch,
751 CORE_ADDR from, CORE_ADDR to,
752 struct regcache *regs)
754 size_t len = gdbarch_max_insn_length (gdbarch);
755 std::unique_ptr<i386_displaced_step_copy_insn_closure> closure
756 (new i386_displaced_step_copy_insn_closure (len));
757 gdb_byte *buf = closure->buf.data ();
759 read_memory (from, buf, len);
761 /* GDB may get control back after the insn after the syscall.
762 Presumably this is a kernel bug.
763 If this is a syscall, make sure there's a nop afterwards. */
765 int syscall_length;
766 gdb_byte *insn;
768 insn = i386_skip_prefixes (buf, len);
769 if (insn != NULL && i386_syscall_p (insn, &syscall_length))
770 insn[syscall_length] = NOP_OPCODE;
773 write_memory (to, buf, len);
775 displaced_debug_printf ("%s->%s: %s",
776 paddress (gdbarch, from), paddress (gdbarch, to),
777 bytes_to_string (buf, len).c_str ());
779 /* This is a work around for a problem with g++ 4.8. */
780 return displaced_step_copy_insn_closure_up (closure.release ());
783 /* Fix up the state of registers and memory after having single-stepped
784 a displaced instruction. */
786 void
787 i386_displaced_step_fixup (struct gdbarch *gdbarch,
788 struct displaced_step_copy_insn_closure *closure_,
789 CORE_ADDR from, CORE_ADDR to,
790 struct regcache *regs, bool completed_p)
792 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
794 /* The offset we applied to the instruction's address.
795 This could well be negative (when viewed as a signed 32-bit
796 value), but ULONGEST won't reflect that, so take care when
797 applying it. */
798 ULONGEST insn_offset = to - from;
800 i386_displaced_step_copy_insn_closure *closure
801 = (i386_displaced_step_copy_insn_closure *) closure_;
802 gdb_byte *insn = closure->buf.data ();
803 /* The start of the insn, needed in case we see some prefixes. */
804 gdb_byte *insn_start = insn;
806 displaced_debug_printf ("fixup (%s, %s), insn = 0x%02x 0x%02x ...",
807 paddress (gdbarch, from), paddress (gdbarch, to),
808 insn[0], insn[1]);
810 /* The list of issues to contend with here is taken from
811 resume_execution in arch/i386/kernel/kprobes.c, Linux 2.6.20.
812 Yay for Free Software! */
814 /* Relocate the %eip, if necessary. */
816 /* The instruction recognizers we use assume any leading prefixes
817 have been skipped. */
819 /* This is the size of the buffer in closure. */
820 size_t max_insn_len = gdbarch_max_insn_length (gdbarch);
821 gdb_byte *opcode = i386_skip_prefixes (insn, max_insn_len);
822 /* If there are too many prefixes, just ignore the insn.
823 It will fault when run. */
824 if (opcode != NULL)
825 insn = opcode;
828 /* Except in the case of absolute or indirect jump or call
829 instructions, or a return instruction, the new eip is relative to
830 the displaced instruction; make it relative. Well, signal
831 handler returns don't need relocation either, but we use the
832 value of %eip to recognize those; see below. */
833 if (!completed_p
834 || (!i386_absolute_jmp_p (insn)
835 && !i386_absolute_call_p (insn)
836 && !i386_ret_p (insn)))
838 int insn_len;
840 CORE_ADDR pc = regcache_read_pc (regs);
842 /* A signal trampoline system call changes the %eip, resuming
843 execution of the main program after the signal handler has
844 returned. That makes them like 'return' instructions; we
845 shouldn't relocate %eip.
847 But most system calls don't, and we do need to relocate %eip.
849 Our heuristic for distinguishing these cases: if stepping
850 over the system call instruction left control directly after
851 the instruction, the we relocate --- control almost certainly
852 doesn't belong in the displaced copy. Otherwise, we assume
853 the instruction has put control where it belongs, and leave
854 it unrelocated. Goodness help us if there are PC-relative
855 system calls. */
856 if (i386_syscall_p (insn, &insn_len)
857 && pc != to + (insn - insn_start) + insn_len
858 /* GDB can get control back after the insn after the syscall.
859 Presumably this is a kernel bug.
860 i386_displaced_step_copy_insn ensures it's a nop,
861 we add one to the length for it. */
862 && pc != to + (insn - insn_start) + insn_len + 1)
863 displaced_debug_printf ("syscall changed %%eip; not relocating");
864 else
866 ULONGEST eip = (pc - insn_offset) & 0xffffffffUL;
868 /* If we just stepped over a breakpoint insn, we don't backup
869 the pc on purpose; this is to match behavior without
870 stepping. */
872 regcache_write_pc (regs, eip);
874 displaced_debug_printf ("relocated %%eip from %s to %s",
875 paddress (gdbarch, pc),
876 paddress (gdbarch, eip));
880 /* If the instruction was PUSHFL, then the TF bit will be set in the
881 pushed value, and should be cleared. We'll leave this for later,
882 since GDB already messes up the TF flag when stepping over a
883 pushfl. */
885 /* If the instruction was a call, the return address now atop the
886 stack is the address following the copied instruction. We need
887 to make it the address following the original instruction. */
888 if (completed_p && i386_call_p (insn))
890 ULONGEST esp;
891 ULONGEST retaddr;
892 const ULONGEST retaddr_len = 4;
894 regcache_cooked_read_unsigned (regs, I386_ESP_REGNUM, &esp);
895 retaddr = read_memory_unsigned_integer (esp, retaddr_len, byte_order);
896 retaddr = (retaddr - insn_offset) & 0xffffffffUL;
897 write_memory_unsigned_integer (esp, retaddr_len, byte_order, retaddr);
899 displaced_debug_printf ("relocated return addr at %s to %s",
900 paddress (gdbarch, esp),
901 paddress (gdbarch, retaddr));
905 static void
906 append_insns (CORE_ADDR *to, ULONGEST len, const gdb_byte *buf)
908 target_write_memory (*to, buf, len);
909 *to += len;
912 static void
913 i386_relocate_instruction (struct gdbarch *gdbarch,
914 CORE_ADDR *to, CORE_ADDR oldloc)
916 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
917 gdb_byte buf[I386_MAX_INSN_LEN];
918 int offset = 0, rel32, newrel;
919 int insn_length;
920 gdb_byte *insn = buf;
922 read_memory (oldloc, buf, I386_MAX_INSN_LEN);
924 insn_length = gdb_buffered_insn_length (gdbarch, insn,
925 I386_MAX_INSN_LEN, oldloc);
927 /* Get past the prefixes. */
928 insn = i386_skip_prefixes (insn, I386_MAX_INSN_LEN);
930 /* Adjust calls with 32-bit relative addresses as push/jump, with
931 the address pushed being the location where the original call in
932 the user program would return to. */
933 if (insn[0] == 0xe8)
935 gdb_byte push_buf[16];
936 unsigned int ret_addr;
938 /* Where "ret" in the original code will return to. */
939 ret_addr = oldloc + insn_length;
940 push_buf[0] = 0x68; /* pushq $... */
941 store_unsigned_integer (&push_buf[1], 4, byte_order, ret_addr);
942 /* Push the push. */
943 append_insns (to, 5, push_buf);
945 /* Convert the relative call to a relative jump. */
946 insn[0] = 0xe9;
948 /* Adjust the destination offset. */
949 rel32 = extract_signed_integer (insn + 1, 4, byte_order);
950 newrel = (oldloc - *to) + rel32;
951 store_signed_integer (insn + 1, 4, byte_order, newrel);
953 displaced_debug_printf ("adjusted insn rel32=%s at %s to rel32=%s at %s",
954 hex_string (rel32), paddress (gdbarch, oldloc),
955 hex_string (newrel), paddress (gdbarch, *to));
957 /* Write the adjusted jump into its displaced location. */
958 append_insns (to, 5, insn);
959 return;
962 /* Adjust jumps with 32-bit relative addresses. Calls are already
963 handled above. */
964 if (insn[0] == 0xe9)
965 offset = 1;
966 /* Adjust conditional jumps. */
967 else if (insn[0] == 0x0f && (insn[1] & 0xf0) == 0x80)
968 offset = 2;
970 if (offset)
972 rel32 = extract_signed_integer (insn + offset, 4, byte_order);
973 newrel = (oldloc - *to) + rel32;
974 store_signed_integer (insn + offset, 4, byte_order, newrel);
975 displaced_debug_printf ("adjusted insn rel32=%s at %s to rel32=%s at %s",
976 hex_string (rel32), paddress (gdbarch, oldloc),
977 hex_string (newrel), paddress (gdbarch, *to));
980 /* Write the adjusted instructions into their displaced
981 location. */
982 append_insns (to, insn_length, buf);
986 #ifdef I386_REGNO_TO_SYMMETRY
987 #error "The Sequent Symmetry is no longer supported."
988 #endif
990 /* According to the System V ABI, the registers %ebp, %ebx, %edi, %esi
991 and %esp "belong" to the calling function. Therefore these
992 registers should be saved if they're going to be modified. */
994 /* The maximum number of saved registers. This should include all
995 registers mentioned above, and %eip. */
996 #define I386_NUM_SAVED_REGS I386_NUM_GREGS
998 struct i386_frame_cache
1000 /* Base address. */
1001 CORE_ADDR base;
1002 int base_p;
1003 LONGEST sp_offset;
1004 CORE_ADDR pc;
1006 /* Saved registers. */
1007 CORE_ADDR saved_regs[I386_NUM_SAVED_REGS];
1008 CORE_ADDR saved_sp;
1009 int saved_sp_reg;
1010 int pc_in_eax;
1012 /* Stack space reserved for local variables. */
1013 long locals;
1016 /* Allocate and initialize a frame cache. */
1018 static struct i386_frame_cache *
1019 i386_alloc_frame_cache (void)
1021 struct i386_frame_cache *cache;
1022 int i;
1024 cache = FRAME_OBSTACK_ZALLOC (struct i386_frame_cache);
1026 /* Base address. */
1027 cache->base_p = 0;
1028 cache->base = 0;
1029 cache->sp_offset = -4;
1030 cache->pc = 0;
1032 /* Saved registers. We initialize these to -1 since zero is a valid
1033 offset (that's where %ebp is supposed to be stored). */
1034 for (i = 0; i < I386_NUM_SAVED_REGS; i++)
1035 cache->saved_regs[i] = -1;
1036 cache->saved_sp = 0;
1037 cache->saved_sp_reg = -1;
1038 cache->pc_in_eax = 0;
1040 /* Frameless until proven otherwise. */
1041 cache->locals = -1;
1043 return cache;
1046 /* If the instruction at PC is a jump, return the address of its
1047 target. Otherwise, return PC. */
1049 static CORE_ADDR
1050 i386_follow_jump (struct gdbarch *gdbarch, CORE_ADDR pc)
1052 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1053 gdb_byte op;
1054 long delta = 0;
1055 int data16 = 0;
1057 if (target_read_code (pc, &op, 1))
1058 return pc;
1060 if (op == 0x66)
1062 data16 = 1;
1064 op = read_code_unsigned_integer (pc + 1, 1, byte_order);
1067 switch (op)
1069 case 0xe9:
1070 /* Relative jump: if data16 == 0, disp32, else disp16. */
1071 if (data16)
1073 delta = read_memory_integer (pc + 2, 2, byte_order);
1075 /* Include the size of the jmp instruction (including the
1076 0x66 prefix). */
1077 delta += 4;
1079 else
1081 delta = read_memory_integer (pc + 1, 4, byte_order);
1083 /* Include the size of the jmp instruction. */
1084 delta += 5;
1086 break;
1087 case 0xeb:
1088 /* Relative jump, disp8 (ignore data16). */
1089 delta = read_memory_integer (pc + data16 + 1, 1, byte_order);
1091 delta += data16 + 2;
1092 break;
1095 return pc + delta;
1098 /* Check whether PC points at a prologue for a function returning a
1099 structure or union. If so, it updates CACHE and returns the
1100 address of the first instruction after the code sequence that
1101 removes the "hidden" argument from the stack or CURRENT_PC,
1102 whichever is smaller. Otherwise, return PC. */
1104 static CORE_ADDR
1105 i386_analyze_struct_return (CORE_ADDR pc, CORE_ADDR current_pc,
1106 struct i386_frame_cache *cache)
1108 /* Functions that return a structure or union start with:
1110 popl %eax 0x58
1111 xchgl %eax, (%esp) 0x87 0x04 0x24
1112 or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
1114 (the System V compiler puts out the second `xchg' instruction,
1115 and the assembler doesn't try to optimize it, so the 'sib' form
1116 gets generated). This sequence is used to get the address of the
1117 return buffer for a function that returns a structure. */
1118 static gdb_byte proto1[3] = { 0x87, 0x04, 0x24 };
1119 static gdb_byte proto2[4] = { 0x87, 0x44, 0x24, 0x00 };
1120 gdb_byte buf[4];
1121 gdb_byte op;
1123 if (current_pc <= pc)
1124 return pc;
1126 if (target_read_code (pc, &op, 1))
1127 return pc;
1129 if (op != 0x58) /* popl %eax */
1130 return pc;
1132 if (target_read_code (pc + 1, buf, 4))
1133 return pc;
1135 if (memcmp (buf, proto1, 3) != 0 && memcmp (buf, proto2, 4) != 0)
1136 return pc;
1138 if (current_pc == pc)
1140 cache->sp_offset += 4;
1141 return current_pc;
1144 if (current_pc == pc + 1)
1146 cache->pc_in_eax = 1;
1147 return current_pc;
1150 if (buf[1] == proto1[1])
1151 return pc + 4;
1152 else
1153 return pc + 5;
1156 static CORE_ADDR
1157 i386_skip_probe (CORE_ADDR pc)
1159 /* A function may start with
1161 pushl constant
1162 call _probe
1163 addl $4, %esp
1165 followed by
1167 pushl %ebp
1169 etc. */
1170 gdb_byte buf[8];
1171 gdb_byte op;
1173 if (target_read_code (pc, &op, 1))
1174 return pc;
1176 if (op == 0x68 || op == 0x6a)
1178 int delta;
1180 /* Skip past the `pushl' instruction; it has either a one-byte or a
1181 four-byte operand, depending on the opcode. */
1182 if (op == 0x68)
1183 delta = 5;
1184 else
1185 delta = 2;
1187 /* Read the following 8 bytes, which should be `call _probe' (6
1188 bytes) followed by `addl $4,%esp' (2 bytes). */
1189 read_memory (pc + delta, buf, sizeof (buf));
1190 if (buf[0] == 0xe8 && buf[6] == 0xc4 && buf[7] == 0x4)
1191 pc += delta + sizeof (buf);
1194 return pc;
1197 /* GCC 4.1 and later, can put code in the prologue to realign the
1198 stack pointer. Check whether PC points to such code, and update
1199 CACHE accordingly. Return the first instruction after the code
1200 sequence or CURRENT_PC, whichever is smaller. If we don't
1201 recognize the code, return PC. */
1203 static CORE_ADDR
1204 i386_analyze_stack_align (CORE_ADDR pc, CORE_ADDR current_pc,
1205 struct i386_frame_cache *cache)
1207 /* There are 2 code sequences to re-align stack before the frame
1208 gets set up:
1210 1. Use a caller-saved saved register:
1212 leal 4(%esp), %reg
1213 andl $-XXX, %esp
1214 pushl -4(%reg)
1216 2. Use a callee-saved saved register:
1218 pushl %reg
1219 leal 8(%esp), %reg
1220 andl $-XXX, %esp
1221 pushl -4(%reg)
1223 "andl $-XXX, %esp" can be either 3 bytes or 6 bytes:
1225 0x83 0xe4 0xf0 andl $-16, %esp
1226 0x81 0xe4 0x00 0xff 0xff 0xff andl $-256, %esp
1229 gdb_byte buf[14];
1230 int reg;
1231 int offset, offset_and;
1232 static int regnums[8] = {
1233 I386_EAX_REGNUM, /* %eax */
1234 I386_ECX_REGNUM, /* %ecx */
1235 I386_EDX_REGNUM, /* %edx */
1236 I386_EBX_REGNUM, /* %ebx */
1237 I386_ESP_REGNUM, /* %esp */
1238 I386_EBP_REGNUM, /* %ebp */
1239 I386_ESI_REGNUM, /* %esi */
1240 I386_EDI_REGNUM /* %edi */
1243 if (target_read_code (pc, buf, sizeof buf))
1244 return pc;
1246 /* Check caller-saved saved register. The first instruction has
1247 to be "leal 4(%esp), %reg". */
1248 if (buf[0] == 0x8d && buf[2] == 0x24 && buf[3] == 0x4)
1250 /* MOD must be binary 10 and R/M must be binary 100. */
1251 if ((buf[1] & 0xc7) != 0x44)
1252 return pc;
1254 /* REG has register number. */
1255 reg = (buf[1] >> 3) & 7;
1256 offset = 4;
1258 else
1260 /* Check callee-saved saved register. The first instruction
1261 has to be "pushl %reg". */
1262 if ((buf[0] & 0xf8) != 0x50)
1263 return pc;
1265 /* Get register. */
1266 reg = buf[0] & 0x7;
1268 /* The next instruction has to be "leal 8(%esp), %reg". */
1269 if (buf[1] != 0x8d || buf[3] != 0x24 || buf[4] != 0x8)
1270 return pc;
1272 /* MOD must be binary 10 and R/M must be binary 100. */
1273 if ((buf[2] & 0xc7) != 0x44)
1274 return pc;
1276 /* REG has register number. Registers in pushl and leal have to
1277 be the same. */
1278 if (reg != ((buf[2] >> 3) & 7))
1279 return pc;
1281 offset = 5;
1284 /* Rigister can't be %esp nor %ebp. */
1285 if (reg == 4 || reg == 5)
1286 return pc;
1288 /* The next instruction has to be "andl $-XXX, %esp". */
1289 if (buf[offset + 1] != 0xe4
1290 || (buf[offset] != 0x81 && buf[offset] != 0x83))
1291 return pc;
1293 offset_and = offset;
1294 offset += buf[offset] == 0x81 ? 6 : 3;
1296 /* The next instruction has to be "pushl -4(%reg)". 8bit -4 is
1297 0xfc. REG must be binary 110 and MOD must be binary 01. */
1298 if (buf[offset] != 0xff
1299 || buf[offset + 2] != 0xfc
1300 || (buf[offset + 1] & 0xf8) != 0x70)
1301 return pc;
1303 /* R/M has register. Registers in leal and pushl have to be the
1304 same. */
1305 if (reg != (buf[offset + 1] & 7))
1306 return pc;
1308 if (current_pc > pc + offset_and)
1309 cache->saved_sp_reg = regnums[reg];
1311 return std::min (pc + offset + 3, current_pc);
1314 /* Maximum instruction length we need to handle. */
1315 #define I386_MAX_MATCHED_INSN_LEN 6
1317 /* Instruction description. */
1318 struct i386_insn
1320 size_t len;
1321 gdb_byte insn[I386_MAX_MATCHED_INSN_LEN];
1322 gdb_byte mask[I386_MAX_MATCHED_INSN_LEN];
1325 /* Return whether instruction at PC matches PATTERN. */
1327 static int
1328 i386_match_pattern (CORE_ADDR pc, struct i386_insn pattern)
1330 gdb_byte op;
1332 if (target_read_code (pc, &op, 1))
1333 return 0;
1335 if ((op & pattern.mask[0]) == pattern.insn[0])
1337 gdb_byte buf[I386_MAX_MATCHED_INSN_LEN - 1];
1338 int insn_matched = 1;
1339 size_t i;
1341 gdb_assert (pattern.len > 1);
1342 gdb_assert (pattern.len <= I386_MAX_MATCHED_INSN_LEN);
1344 if (target_read_code (pc + 1, buf, pattern.len - 1))
1345 return 0;
1347 for (i = 1; i < pattern.len; i++)
1349 if ((buf[i - 1] & pattern.mask[i]) != pattern.insn[i])
1350 insn_matched = 0;
1352 return insn_matched;
1354 return 0;
1357 /* Search for the instruction at PC in the list INSN_PATTERNS. Return
1358 the first instruction description that matches. Otherwise, return
1359 NULL. */
1361 static struct i386_insn *
1362 i386_match_insn (CORE_ADDR pc, struct i386_insn *insn_patterns)
1364 struct i386_insn *pattern;
1366 for (pattern = insn_patterns; pattern->len > 0; pattern++)
1368 if (i386_match_pattern (pc, *pattern))
1369 return pattern;
1372 return NULL;
1375 /* Return whether PC points inside a sequence of instructions that
1376 matches INSN_PATTERNS. */
1378 static int
1379 i386_match_insn_block (CORE_ADDR pc, struct i386_insn *insn_patterns)
1381 CORE_ADDR current_pc;
1382 int ix, i;
1383 struct i386_insn *insn;
1385 insn = i386_match_insn (pc, insn_patterns);
1386 if (insn == NULL)
1387 return 0;
1389 current_pc = pc;
1390 ix = insn - insn_patterns;
1391 for (i = ix - 1; i >= 0; i--)
1393 current_pc -= insn_patterns[i].len;
1395 if (!i386_match_pattern (current_pc, insn_patterns[i]))
1396 return 0;
1399 current_pc = pc + insn->len;
1400 for (insn = insn_patterns + ix + 1; insn->len > 0; insn++)
1402 if (!i386_match_pattern (current_pc, *insn))
1403 return 0;
1405 current_pc += insn->len;
1408 return 1;
1411 /* Some special instructions that might be migrated by GCC into the
1412 part of the prologue that sets up the new stack frame. Because the
1413 stack frame hasn't been setup yet, no registers have been saved
1414 yet, and only the scratch registers %eax, %ecx and %edx can be
1415 touched. */
1417 static i386_insn i386_frame_setup_skip_insns[] =
1419 /* Check for `movb imm8, r' and `movl imm32, r'.
1421 ??? Should we handle 16-bit operand-sizes here? */
1423 /* `movb imm8, %al' and `movb imm8, %ah' */
1424 /* `movb imm8, %cl' and `movb imm8, %ch' */
1425 { 2, { 0xb0, 0x00 }, { 0xfa, 0x00 } },
1426 /* `movb imm8, %dl' and `movb imm8, %dh' */
1427 { 2, { 0xb2, 0x00 }, { 0xfb, 0x00 } },
1428 /* `movl imm32, %eax' and `movl imm32, %ecx' */
1429 { 5, { 0xb8 }, { 0xfe } },
1430 /* `movl imm32, %edx' */
1431 { 5, { 0xba }, { 0xff } },
1433 /* Check for `mov imm32, r32'. Note that there is an alternative
1434 encoding for `mov m32, %eax'.
1436 ??? Should we handle SIB addressing here?
1437 ??? Should we handle 16-bit operand-sizes here? */
1439 /* `movl m32, %eax' */
1440 { 5, { 0xa1 }, { 0xff } },
1441 /* `movl m32, %eax' and `mov; m32, %ecx' */
1442 { 6, { 0x89, 0x05 }, {0xff, 0xf7 } },
1443 /* `movl m32, %edx' */
1444 { 6, { 0x89, 0x15 }, {0xff, 0xff } },
1446 /* Check for `xorl r32, r32' and the equivalent `subl r32, r32'.
1447 Because of the symmetry, there are actually two ways to encode
1448 these instructions; opcode bytes 0x29 and 0x2b for `subl' and
1449 opcode bytes 0x31 and 0x33 for `xorl'. */
1451 /* `subl %eax, %eax' */
1452 { 2, { 0x29, 0xc0 }, { 0xfd, 0xff } },
1453 /* `subl %ecx, %ecx' */
1454 { 2, { 0x29, 0xc9 }, { 0xfd, 0xff } },
1455 /* `subl %edx, %edx' */
1456 { 2, { 0x29, 0xd2 }, { 0xfd, 0xff } },
1457 /* `xorl %eax, %eax' */
1458 { 2, { 0x31, 0xc0 }, { 0xfd, 0xff } },
1459 /* `xorl %ecx, %ecx' */
1460 { 2, { 0x31, 0xc9 }, { 0xfd, 0xff } },
1461 /* `xorl %edx, %edx' */
1462 { 2, { 0x31, 0xd2 }, { 0xfd, 0xff } },
1463 { 0 }
1466 /* Check whether PC points to an endbr32 instruction. */
1467 static CORE_ADDR
1468 i386_skip_endbr (CORE_ADDR pc)
1470 static const gdb_byte endbr32[] = { 0xf3, 0x0f, 0x1e, 0xfb };
1472 gdb_byte buf[sizeof (endbr32)];
1474 /* Stop there if we can't read the code */
1475 if (target_read_code (pc, buf, sizeof (endbr32)))
1476 return pc;
1478 /* If the instruction isn't an endbr32, stop */
1479 if (memcmp (buf, endbr32, sizeof (endbr32)) != 0)
1480 return pc;
1482 return pc + sizeof (endbr32);
1485 /* Check whether PC points to a no-op instruction. */
1486 static CORE_ADDR
1487 i386_skip_noop (CORE_ADDR pc)
1489 gdb_byte op;
1490 int check = 1;
1492 if (target_read_code (pc, &op, 1))
1493 return pc;
1495 while (check)
1497 check = 0;
1498 /* Ignore `nop' instruction. */
1499 if (op == 0x90)
1501 pc += 1;
1502 if (target_read_code (pc, &op, 1))
1503 return pc;
1504 check = 1;
1506 /* Ignore no-op instruction `mov %edi, %edi'.
1507 Microsoft system dlls often start with
1508 a `mov %edi,%edi' instruction.
1509 The 5 bytes before the function start are
1510 filled with `nop' instructions.
1511 This pattern can be used for hot-patching:
1512 The `mov %edi, %edi' instruction can be replaced by a
1513 near jump to the location of the 5 `nop' instructions
1514 which can be replaced by a 32-bit jump to anywhere
1515 in the 32-bit address space. */
1517 else if (op == 0x8b)
1519 if (target_read_code (pc + 1, &op, 1))
1520 return pc;
1522 if (op == 0xff)
1524 pc += 2;
1525 if (target_read_code (pc, &op, 1))
1526 return pc;
1528 check = 1;
1532 return pc;
1535 /* Check whether PC points at a code that sets up a new stack frame.
1536 If so, it updates CACHE and returns the address of the first
1537 instruction after the sequence that sets up the frame or LIMIT,
1538 whichever is smaller. If we don't recognize the code, return PC. */
1540 static CORE_ADDR
1541 i386_analyze_frame_setup (struct gdbarch *gdbarch,
1542 CORE_ADDR pc, CORE_ADDR limit,
1543 struct i386_frame_cache *cache)
1545 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1546 struct i386_insn *insn;
1547 gdb_byte op;
1548 int skip = 0;
1550 if (limit <= pc)
1551 return limit;
1553 if (target_read_code (pc, &op, 1))
1554 return pc;
1556 if (op == 0x55) /* pushl %ebp */
1558 /* Take into account that we've executed the `pushl %ebp' that
1559 starts this instruction sequence. */
1560 cache->saved_regs[I386_EBP_REGNUM] = 0;
1561 cache->sp_offset += 4;
1562 pc++;
1564 /* If that's all, return now. */
1565 if (limit <= pc)
1566 return limit;
1568 /* Check for some special instructions that might be migrated by
1569 GCC into the prologue and skip them. At this point in the
1570 prologue, code should only touch the scratch registers %eax,
1571 %ecx and %edx, so while the number of possibilities is sheer,
1572 it is limited.
1574 Make sure we only skip these instructions if we later see the
1575 `movl %esp, %ebp' that actually sets up the frame. */
1576 while (pc + skip < limit)
1578 insn = i386_match_insn (pc + skip, i386_frame_setup_skip_insns);
1579 if (insn == NULL)
1580 break;
1582 skip += insn->len;
1585 /* If that's all, return now. */
1586 if (limit <= pc + skip)
1587 return limit;
1589 if (target_read_code (pc + skip, &op, 1))
1590 return pc + skip;
1592 /* The i386 prologue looks like
1594 push %ebp
1595 mov %esp,%ebp
1596 sub $0x10,%esp
1598 and a different prologue can be generated for atom.
1600 push %ebp
1601 lea (%esp),%ebp
1602 lea -0x10(%esp),%esp
1604 We handle both of them here. */
1606 switch (op)
1608 /* Check for `movl %esp, %ebp' -- can be written in two ways. */
1609 case 0x8b:
1610 if (read_code_unsigned_integer (pc + skip + 1, 1, byte_order)
1611 != 0xec)
1612 return pc;
1613 pc += (skip + 2);
1614 break;
1615 case 0x89:
1616 if (read_code_unsigned_integer (pc + skip + 1, 1, byte_order)
1617 != 0xe5)
1618 return pc;
1619 pc += (skip + 2);
1620 break;
1621 case 0x8d: /* Check for 'lea (%ebp), %ebp'. */
1622 if (read_code_unsigned_integer (pc + skip + 1, 2, byte_order)
1623 != 0x242c)
1624 return pc;
1625 pc += (skip + 3);
1626 break;
1627 default:
1628 return pc;
1631 /* OK, we actually have a frame. We just don't know how large
1632 it is yet. Set its size to zero. We'll adjust it if
1633 necessary. We also now commit to skipping the special
1634 instructions mentioned before. */
1635 cache->locals = 0;
1637 /* If that's all, return now. */
1638 if (limit <= pc)
1639 return limit;
1641 /* Check for stack adjustment
1643 subl $XXX, %esp
1645 lea -XXX(%esp),%esp
1647 NOTE: You can't subtract a 16-bit immediate from a 32-bit
1648 reg, so we don't have to worry about a data16 prefix. */
1649 if (target_read_code (pc, &op, 1))
1650 return pc;
1651 if (op == 0x83)
1653 /* `subl' with 8-bit immediate. */
1654 if (read_code_unsigned_integer (pc + 1, 1, byte_order) != 0xec)
1655 /* Some instruction starting with 0x83 other than `subl'. */
1656 return pc;
1658 /* `subl' with signed 8-bit immediate (though it wouldn't
1659 make sense to be negative). */
1660 cache->locals = read_code_integer (pc + 2, 1, byte_order);
1661 return pc + 3;
1663 else if (op == 0x81)
1665 /* Maybe it is `subl' with a 32-bit immediate. */
1666 if (read_code_unsigned_integer (pc + 1, 1, byte_order) != 0xec)
1667 /* Some instruction starting with 0x81 other than `subl'. */
1668 return pc;
1670 /* It is `subl' with a 32-bit immediate. */
1671 cache->locals = read_code_integer (pc + 2, 4, byte_order);
1672 return pc + 6;
1674 else if (op == 0x8d)
1676 /* The ModR/M byte is 0x64. */
1677 if (read_code_unsigned_integer (pc + 1, 1, byte_order) != 0x64)
1678 return pc;
1679 /* 'lea' with 8-bit displacement. */
1680 cache->locals = -1 * read_code_integer (pc + 3, 1, byte_order);
1681 return pc + 4;
1683 else
1685 /* Some instruction other than `subl' nor 'lea'. */
1686 return pc;
1689 else if (op == 0xc8) /* enter */
1691 cache->locals = read_code_unsigned_integer (pc + 1, 2, byte_order);
1692 return pc + 4;
1695 return pc;
1698 /* Check whether PC points at code that saves registers on the stack.
1699 If so, it updates CACHE and returns the address of the first
1700 instruction after the register saves or CURRENT_PC, whichever is
1701 smaller. Otherwise, return PC. */
1703 static CORE_ADDR
1704 i386_analyze_register_saves (CORE_ADDR pc, CORE_ADDR current_pc,
1705 struct i386_frame_cache *cache)
1707 CORE_ADDR offset = 0;
1708 gdb_byte op;
1709 int i;
1711 if (cache->locals > 0)
1712 offset -= cache->locals;
1713 for (i = 0; i < 8 && pc < current_pc; i++)
1715 if (target_read_code (pc, &op, 1))
1716 return pc;
1717 if (op < 0x50 || op > 0x57)
1718 break;
1720 offset -= 4;
1721 cache->saved_regs[op - 0x50] = offset;
1722 cache->sp_offset += 4;
1723 pc++;
1726 return pc;
1729 /* Do a full analysis of the prologue at PC and update CACHE
1730 accordingly. Bail out early if CURRENT_PC is reached. Return the
1731 address where the analysis stopped.
1733 We handle these cases:
1735 The startup sequence can be at the start of the function, or the
1736 function can start with a branch to startup code at the end.
1738 %ebp can be set up with either the 'enter' instruction, or "pushl
1739 %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was
1740 once used in the System V compiler).
1742 Local space is allocated just below the saved %ebp by either the
1743 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a
1744 16-bit unsigned argument for space to allocate, and the 'addl'
1745 instruction could have either a signed byte, or 32-bit immediate.
1747 Next, the registers used by this function are pushed. With the
1748 System V compiler they will always be in the order: %edi, %esi,
1749 %ebx (and sometimes a harmless bug causes it to also save but not
1750 restore %eax); however, the code below is willing to see the pushes
1751 in any order, and will handle up to 8 of them.
1753 If the setup sequence is at the end of the function, then the next
1754 instruction will be a branch back to the start. */
1756 static CORE_ADDR
1757 i386_analyze_prologue (struct gdbarch *gdbarch,
1758 CORE_ADDR pc, CORE_ADDR current_pc,
1759 struct i386_frame_cache *cache)
1761 pc = i386_skip_endbr (pc);
1762 pc = i386_skip_noop (pc);
1763 pc = i386_follow_jump (gdbarch, pc);
1764 pc = i386_analyze_struct_return (pc, current_pc, cache);
1765 pc = i386_skip_probe (pc);
1766 pc = i386_analyze_stack_align (pc, current_pc, cache);
1767 pc = i386_analyze_frame_setup (gdbarch, pc, current_pc, cache);
1768 return i386_analyze_register_saves (pc, current_pc, cache);
1771 /* Return PC of first real instruction. */
1773 static CORE_ADDR
1774 i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
1776 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1778 static gdb_byte pic_pat[6] =
1780 0xe8, 0, 0, 0, 0, /* call 0x0 */
1781 0x5b, /* popl %ebx */
1783 struct i386_frame_cache cache;
1784 CORE_ADDR pc;
1785 gdb_byte op;
1786 int i;
1787 CORE_ADDR func_addr;
1789 if (find_pc_partial_function (start_pc, NULL, &func_addr, NULL))
1791 CORE_ADDR post_prologue_pc
1792 = skip_prologue_using_sal (gdbarch, func_addr);
1793 struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
1795 /* LLVM backend (Clang/Flang) always emits a line note before the
1796 prologue and another one after. We trust clang and newer Intel
1797 compilers to emit usable line notes. */
1798 if (post_prologue_pc
1799 && (cust != NULL
1800 && cust->producer () != NULL
1801 && (producer_is_llvm (cust->producer ())
1802 || producer_is_icc_ge_19 (cust->producer ()))))
1803 return std::max (start_pc, post_prologue_pc);
1806 cache.locals = -1;
1807 pc = i386_analyze_prologue (gdbarch, start_pc, 0xffffffff, &cache);
1808 if (cache.locals < 0)
1809 return start_pc;
1811 /* Found valid frame setup. */
1813 /* The native cc on SVR4 in -K PIC mode inserts the following code
1814 to get the address of the global offset table (GOT) into register
1815 %ebx:
1817 call 0x0
1818 popl %ebx
1819 movl %ebx,x(%ebp) (optional)
1820 addl y,%ebx
1822 This code is with the rest of the prologue (at the end of the
1823 function), so we have to skip it to get to the first real
1824 instruction at the start of the function. */
1826 for (i = 0; i < 6; i++)
1828 if (target_read_code (pc + i, &op, 1))
1829 return pc;
1831 if (pic_pat[i] != op)
1832 break;
1834 if (i == 6)
1836 int delta = 6;
1838 if (target_read_code (pc + delta, &op, 1))
1839 return pc;
1841 if (op == 0x89) /* movl %ebx, x(%ebp) */
1843 op = read_code_unsigned_integer (pc + delta + 1, 1, byte_order);
1845 if (op == 0x5d) /* One byte offset from %ebp. */
1846 delta += 3;
1847 else if (op == 0x9d) /* Four byte offset from %ebp. */
1848 delta += 6;
1849 else /* Unexpected instruction. */
1850 delta = 0;
1852 if (target_read_code (pc + delta, &op, 1))
1853 return pc;
1856 /* addl y,%ebx */
1857 if (delta > 0 && op == 0x81
1858 && read_code_unsigned_integer (pc + delta + 1, 1, byte_order)
1859 == 0xc3)
1861 pc += delta + 6;
1865 /* If the function starts with a branch (to startup code at the end)
1866 the last instruction should bring us back to the first
1867 instruction of the real code. */
1868 if (i386_follow_jump (gdbarch, start_pc) != start_pc)
1869 pc = i386_follow_jump (gdbarch, pc);
1871 return pc;
1874 /* Check that the code pointed to by PC corresponds to a call to
1875 __main, skip it if so. Return PC otherwise. */
1877 CORE_ADDR
1878 i386_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
1880 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1881 gdb_byte op;
1883 if (target_read_code (pc, &op, 1))
1884 return pc;
1885 if (op == 0xe8)
1887 gdb_byte buf[4];
1889 if (target_read_code (pc + 1, buf, sizeof buf) == 0)
1891 /* Make sure address is computed correctly as a 32bit
1892 integer even if CORE_ADDR is 64 bit wide. */
1893 CORE_ADDR call_dest;
1895 call_dest = pc + 5 + extract_signed_integer (buf, 4, byte_order);
1896 call_dest = call_dest & 0xffffffffU;
1897 bound_minimal_symbol s = lookup_minimal_symbol_by_pc (call_dest);
1898 if (s.minsym != NULL
1899 && s.minsym->linkage_name () != NULL
1900 && strcmp (s.minsym->linkage_name (), "__main") == 0)
1901 pc += 5;
1905 return pc;
1908 /* This function is 64-bit safe. */
1910 static CORE_ADDR
1911 i386_unwind_pc (struct gdbarch *gdbarch, const frame_info_ptr &next_frame)
1913 gdb_byte buf[8];
1915 frame_unwind_register (next_frame, gdbarch_pc_regnum (gdbarch), buf);
1916 return extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
1920 /* Normal frames. */
1922 static void
1923 i386_frame_cache_1 (const frame_info_ptr &this_frame,
1924 struct i386_frame_cache *cache)
1926 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1927 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1928 gdb_byte buf[4];
1929 int i;
1931 cache->pc = get_frame_func (this_frame);
1933 /* In principle, for normal frames, %ebp holds the frame pointer,
1934 which holds the base address for the current stack frame.
1935 However, for functions that don't need it, the frame pointer is
1936 optional. For these "frameless" functions the frame pointer is
1937 actually the frame pointer of the calling frame. Signal
1938 trampolines are just a special case of a "frameless" function.
1939 They (usually) share their frame pointer with the frame that was
1940 in progress when the signal occurred. */
1942 get_frame_register (this_frame, I386_EBP_REGNUM, buf);
1943 cache->base = extract_unsigned_integer (buf, 4, byte_order);
1944 if (cache->base == 0)
1946 cache->base_p = 1;
1947 return;
1950 /* For normal frames, %eip is stored at 4(%ebp). */
1951 cache->saved_regs[I386_EIP_REGNUM] = 4;
1953 if (cache->pc != 0)
1954 i386_analyze_prologue (gdbarch, cache->pc, get_frame_pc (this_frame),
1955 cache);
1957 if (cache->locals < 0)
1959 /* We didn't find a valid frame, which means that CACHE->base
1960 currently holds the frame pointer for our calling frame. If
1961 we're at the start of a function, or somewhere half-way its
1962 prologue, the function's frame probably hasn't been fully
1963 setup yet. Try to reconstruct the base address for the stack
1964 frame by looking at the stack pointer. For truly "frameless"
1965 functions this might work too. */
1967 if (cache->saved_sp_reg != -1)
1969 /* Saved stack pointer has been saved. */
1970 get_frame_register (this_frame, cache->saved_sp_reg, buf);
1971 cache->saved_sp = extract_unsigned_integer (buf, 4, byte_order);
1973 /* We're halfway aligning the stack. */
1974 cache->base = ((cache->saved_sp - 4) & 0xfffffff0) - 4;
1975 cache->saved_regs[I386_EIP_REGNUM] = cache->saved_sp - 4;
1977 /* This will be added back below. */
1978 cache->saved_regs[I386_EIP_REGNUM] -= cache->base;
1980 else if (cache->pc != 0
1981 || target_read_code (get_frame_pc (this_frame), buf, 1))
1983 /* We're in a known function, but did not find a frame
1984 setup. Assume that the function does not use %ebp.
1985 Alternatively, we may have jumped to an invalid
1986 address; in that case there is definitely no new
1987 frame in %ebp. */
1988 get_frame_register (this_frame, I386_ESP_REGNUM, buf);
1989 cache->base = extract_unsigned_integer (buf, 4, byte_order)
1990 + cache->sp_offset;
1992 else
1993 /* We're in an unknown function. We could not find the start
1994 of the function to analyze the prologue; our best option is
1995 to assume a typical frame layout with the caller's %ebp
1996 saved. */
1997 cache->saved_regs[I386_EBP_REGNUM] = 0;
2000 if (cache->saved_sp_reg != -1)
2002 /* Saved stack pointer has been saved (but the SAVED_SP_REG
2003 register may be unavailable). */
2004 if (cache->saved_sp == 0
2005 && deprecated_frame_register_read (this_frame,
2006 cache->saved_sp_reg, buf))
2007 cache->saved_sp = extract_unsigned_integer (buf, 4, byte_order);
2009 /* Now that we have the base address for the stack frame we can
2010 calculate the value of %esp in the calling frame. */
2011 else if (cache->saved_sp == 0)
2012 cache->saved_sp = cache->base + 8;
2014 /* Adjust all the saved registers such that they contain addresses
2015 instead of offsets. */
2016 for (i = 0; i < I386_NUM_SAVED_REGS; i++)
2017 if (cache->saved_regs[i] != -1)
2018 cache->saved_regs[i] += cache->base;
2020 cache->base_p = 1;
2023 static struct i386_frame_cache *
2024 i386_frame_cache (const frame_info_ptr &this_frame, void **this_cache)
2026 struct i386_frame_cache *cache;
2028 if (*this_cache)
2029 return (struct i386_frame_cache *) *this_cache;
2031 cache = i386_alloc_frame_cache ();
2032 *this_cache = cache;
2036 i386_frame_cache_1 (this_frame, cache);
2038 catch (const gdb_exception_error &ex)
2040 if (ex.error != NOT_AVAILABLE_ERROR)
2041 throw;
2044 return cache;
2047 static void
2048 i386_frame_this_id (const frame_info_ptr &this_frame, void **this_cache,
2049 struct frame_id *this_id)
2051 struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
2053 if (!cache->base_p)
2054 (*this_id) = frame_id_build_unavailable_stack (cache->pc);
2055 else if (cache->base == 0)
2057 /* This marks the outermost frame. */
2059 else
2061 /* See the end of i386_push_dummy_call. */
2062 (*this_id) = frame_id_build (cache->base + 8, cache->pc);
2066 static enum unwind_stop_reason
2067 i386_frame_unwind_stop_reason (const frame_info_ptr &this_frame,
2068 void **this_cache)
2070 struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
2072 if (!cache->base_p)
2073 return UNWIND_UNAVAILABLE;
2075 /* This marks the outermost frame. */
2076 if (cache->base == 0)
2077 return UNWIND_OUTERMOST;
2079 return UNWIND_NO_REASON;
2082 static struct value *
2083 i386_frame_prev_register (const frame_info_ptr &this_frame, void **this_cache,
2084 int regnum)
2086 struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
2088 gdb_assert (regnum >= 0);
2090 /* The System V ABI says that:
2092 "The flags register contains the system flags, such as the
2093 direction flag and the carry flag. The direction flag must be
2094 set to the forward (that is, zero) direction before entry and
2095 upon exit from a function. Other user flags have no specified
2096 role in the standard calling sequence and are not preserved."
2098 To guarantee the "upon exit" part of that statement we fake a
2099 saved flags register that has its direction flag cleared.
2101 Note that GCC doesn't seem to rely on the fact that the direction
2102 flag is cleared after a function return; it always explicitly
2103 clears the flag before operations where it matters.
2105 FIXME: kettenis/20030316: I'm not quite sure whether this is the
2106 right thing to do. The way we fake the flags register here makes
2107 it impossible to change it. */
2109 if (regnum == I386_EFLAGS_REGNUM)
2111 ULONGEST val;
2113 val = get_frame_register_unsigned (this_frame, regnum);
2114 val &= ~(1 << 10);
2115 return frame_unwind_got_constant (this_frame, regnum, val);
2118 if (regnum == I386_EIP_REGNUM && cache->pc_in_eax)
2119 return frame_unwind_got_register (this_frame, regnum, I386_EAX_REGNUM);
2121 if (regnum == I386_ESP_REGNUM
2122 && (cache->saved_sp != 0 || cache->saved_sp_reg != -1))
2124 /* If the SP has been saved, but we don't know where, then this
2125 means that SAVED_SP_REG register was found unavailable back
2126 when we built the cache. */
2127 if (cache->saved_sp == 0)
2128 return frame_unwind_got_register (this_frame, regnum,
2129 cache->saved_sp_reg);
2130 else
2131 return frame_unwind_got_constant (this_frame, regnum,
2132 cache->saved_sp);
2135 if (regnum < I386_NUM_SAVED_REGS && cache->saved_regs[regnum] != -1)
2136 return frame_unwind_got_memory (this_frame, regnum,
2137 cache->saved_regs[regnum]);
2139 return frame_unwind_got_register (this_frame, regnum, regnum);
2142 static const struct frame_unwind_legacy i386_frame_unwind (
2143 "i386 prologue",
2144 NORMAL_FRAME,
2145 FRAME_UNWIND_ARCH,
2146 i386_frame_unwind_stop_reason,
2147 i386_frame_this_id,
2148 i386_frame_prev_register,
2149 NULL,
2150 default_frame_sniffer
2153 /* Normal frames, but in a function epilogue. */
2155 /* Implement the stack_frame_destroyed_p gdbarch method.
2157 The epilogue is defined here as the 'ret' instruction, which will
2158 follow any instruction such as 'leave' or 'pop %ebp' that destroys
2159 the function's stack frame. */
2161 static int
2162 i386_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
2164 gdb_byte insn;
2165 if (target_read_memory (pc, &insn, 1))
2166 return 0; /* Can't read memory at pc. */
2168 if (insn != 0xc3) /* 'ret' instruction. */
2169 return 0;
2171 return 1;
2174 static int
2175 i386_epilogue_frame_sniffer_1 (const struct frame_unwind *self,
2176 const frame_info_ptr &this_frame,
2177 void **this_prologue_cache, bool override_p)
2179 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2180 CORE_ADDR pc = get_frame_pc (this_frame);
2182 if (frame_relative_level (this_frame) != 0)
2183 /* We're not in the inner frame, so assume we're not in an epilogue. */
2184 return 0;
2186 bool unwind_valid_p
2187 = compunit_epilogue_unwind_valid (find_pc_compunit_symtab (pc));
2188 if (override_p)
2190 if (unwind_valid_p)
2191 /* Don't override the symtab unwinders, skip
2192 "i386 epilogue override". */
2193 return 0;
2195 else
2197 if (!unwind_valid_p)
2198 /* "i386 epilogue override" unwinder already ran, skip
2199 "i386 epilogue". */
2200 return 0;
2203 /* Check whether we're in an epilogue. */
2204 return i386_stack_frame_destroyed_p (gdbarch, pc);
2207 static int
2208 i386_epilogue_override_frame_sniffer (const struct frame_unwind *self,
2209 const frame_info_ptr &this_frame,
2210 void **this_prologue_cache)
2212 return i386_epilogue_frame_sniffer_1 (self, this_frame, this_prologue_cache,
2213 true);
2216 static int
2217 i386_epilogue_frame_sniffer (const struct frame_unwind *self,
2218 const frame_info_ptr &this_frame,
2219 void **this_prologue_cache)
2221 return i386_epilogue_frame_sniffer_1 (self, this_frame, this_prologue_cache,
2222 false);
2225 static struct i386_frame_cache *
2226 i386_epilogue_frame_cache (const frame_info_ptr &this_frame, void **this_cache)
2228 struct i386_frame_cache *cache;
2229 CORE_ADDR sp;
2231 if (*this_cache)
2232 return (struct i386_frame_cache *) *this_cache;
2234 cache = i386_alloc_frame_cache ();
2235 *this_cache = cache;
2239 cache->pc = get_frame_func (this_frame);
2241 /* At this point the stack looks as if we just entered the
2242 function, with the return address at the top of the
2243 stack. */
2244 sp = get_frame_register_unsigned (this_frame, I386_ESP_REGNUM);
2245 cache->base = sp + cache->sp_offset;
2246 cache->saved_sp = cache->base + 8;
2247 cache->saved_regs[I386_EIP_REGNUM] = cache->base + 4;
2249 cache->base_p = 1;
2251 catch (const gdb_exception_error &ex)
2253 if (ex.error != NOT_AVAILABLE_ERROR)
2254 throw;
2257 return cache;
2260 static enum unwind_stop_reason
2261 i386_epilogue_frame_unwind_stop_reason (const frame_info_ptr &this_frame,
2262 void **this_cache)
2264 struct i386_frame_cache *cache =
2265 i386_epilogue_frame_cache (this_frame, this_cache);
2267 if (!cache->base_p)
2268 return UNWIND_UNAVAILABLE;
2270 return UNWIND_NO_REASON;
2273 static void
2274 i386_epilogue_frame_this_id (const frame_info_ptr &this_frame,
2275 void **this_cache,
2276 struct frame_id *this_id)
2278 struct i386_frame_cache *cache =
2279 i386_epilogue_frame_cache (this_frame, this_cache);
2281 if (!cache->base_p)
2282 (*this_id) = frame_id_build_unavailable_stack (cache->pc);
2283 else
2284 (*this_id) = frame_id_build (cache->base + 8, cache->pc);
2287 static struct value *
2288 i386_epilogue_frame_prev_register (const frame_info_ptr &this_frame,
2289 void **this_cache, int regnum)
2291 /* Make sure we've initialized the cache. */
2292 i386_epilogue_frame_cache (this_frame, this_cache);
2294 return i386_frame_prev_register (this_frame, this_cache, regnum);
2297 static const struct frame_unwind_legacy i386_epilogue_override_frame_unwind (
2298 "i386 epilogue override",
2299 NORMAL_FRAME,
2300 FRAME_UNWIND_ARCH,
2301 i386_epilogue_frame_unwind_stop_reason,
2302 i386_epilogue_frame_this_id,
2303 i386_epilogue_frame_prev_register,
2304 NULL,
2305 i386_epilogue_override_frame_sniffer
2308 static const struct frame_unwind_legacy i386_epilogue_frame_unwind (
2309 "i386 epilogue",
2310 NORMAL_FRAME,
2311 FRAME_UNWIND_ARCH,
2312 i386_epilogue_frame_unwind_stop_reason,
2313 i386_epilogue_frame_this_id,
2314 i386_epilogue_frame_prev_register,
2315 NULL,
2316 i386_epilogue_frame_sniffer
2320 /* Stack-based trampolines. */
2322 /* These trampolines are used on cross x86 targets, when taking the
2323 address of a nested function. When executing these trampolines,
2324 no stack frame is set up, so we are in a similar situation as in
2325 epilogues and i386_epilogue_frame_this_id can be re-used. */
2327 /* Static chain passed in register. */
2329 static i386_insn i386_tramp_chain_in_reg_insns[] =
2331 /* `movl imm32, %eax' and `movl imm32, %ecx' */
2332 { 5, { 0xb8 }, { 0xfe } },
2334 /* `jmp imm32' */
2335 { 5, { 0xe9 }, { 0xff } },
2340 /* Static chain passed on stack (when regparm=3). */
2342 static i386_insn i386_tramp_chain_on_stack_insns[] =
2344 /* `push imm32' */
2345 { 5, { 0x68 }, { 0xff } },
2347 /* `jmp imm32' */
2348 { 5, { 0xe9 }, { 0xff } },
2353 /* Return whether PC points inside a stack trampoline. */
2355 static int
2356 i386_in_stack_tramp_p (CORE_ADDR pc)
2358 gdb_byte insn;
2359 const char *name;
2361 /* A stack trampoline is detected if no name is associated
2362 to the current pc and if it points inside a trampoline
2363 sequence. */
2365 find_pc_partial_function (pc, &name, NULL, NULL);
2366 if (name)
2367 return 0;
2369 if (target_read_memory (pc, &insn, 1))
2370 return 0;
2372 if (!i386_match_insn_block (pc, i386_tramp_chain_in_reg_insns)
2373 && !i386_match_insn_block (pc, i386_tramp_chain_on_stack_insns))
2374 return 0;
2376 return 1;
2379 static int
2380 i386_stack_tramp_frame_sniffer (const struct frame_unwind *self,
2381 const frame_info_ptr &this_frame,
2382 void **this_cache)
2384 if (frame_relative_level (this_frame) == 0)
2385 return i386_in_stack_tramp_p (get_frame_pc (this_frame));
2386 else
2387 return 0;
2390 static const struct frame_unwind_legacy i386_stack_tramp_frame_unwind (
2391 "i386 stack tramp",
2392 NORMAL_FRAME,
2393 FRAME_UNWIND_ARCH,
2394 i386_epilogue_frame_unwind_stop_reason,
2395 i386_epilogue_frame_this_id,
2396 i386_epilogue_frame_prev_register,
2397 NULL,
2398 i386_stack_tramp_frame_sniffer
2401 /* Generate a bytecode expression to get the value of the saved PC. */
2403 static void
2404 i386_gen_return_address (struct gdbarch *gdbarch,
2405 struct agent_expr *ax, struct axs_value *value,
2406 CORE_ADDR scope)
2408 /* The following sequence assumes the traditional use of the base
2409 register. */
2410 ax_reg (ax, I386_EBP_REGNUM);
2411 ax_const_l (ax, 4);
2412 ax_simple (ax, aop_add);
2413 value->type = register_type (gdbarch, I386_EIP_REGNUM);
2414 value->kind = axs_lvalue_memory;
2418 /* Signal trampolines. */
2420 static struct i386_frame_cache *
2421 i386_sigtramp_frame_cache (const frame_info_ptr &this_frame, void **this_cache)
2423 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2424 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
2425 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2426 struct i386_frame_cache *cache;
2427 CORE_ADDR addr;
2428 gdb_byte buf[4];
2430 if (*this_cache)
2431 return (struct i386_frame_cache *) *this_cache;
2433 cache = i386_alloc_frame_cache ();
2437 get_frame_register (this_frame, I386_ESP_REGNUM, buf);
2438 cache->base = extract_unsigned_integer (buf, 4, byte_order) - 4;
2440 addr = tdep->sigcontext_addr (this_frame);
2441 if (tdep->sc_reg_offset)
2443 int i;
2445 gdb_assert (tdep->sc_num_regs <= I386_NUM_SAVED_REGS);
2447 for (i = 0; i < tdep->sc_num_regs; i++)
2448 if (tdep->sc_reg_offset[i] != -1)
2449 cache->saved_regs[i] = addr + tdep->sc_reg_offset[i];
2451 else
2453 cache->saved_regs[I386_EIP_REGNUM] = addr + tdep->sc_pc_offset;
2454 cache->saved_regs[I386_ESP_REGNUM] = addr + tdep->sc_sp_offset;
2457 cache->base_p = 1;
2459 catch (const gdb_exception_error &ex)
2461 if (ex.error != NOT_AVAILABLE_ERROR)
2462 throw;
2465 *this_cache = cache;
2466 return cache;
2469 static enum unwind_stop_reason
2470 i386_sigtramp_frame_unwind_stop_reason (const frame_info_ptr &this_frame,
2471 void **this_cache)
2473 struct i386_frame_cache *cache =
2474 i386_sigtramp_frame_cache (this_frame, this_cache);
2476 if (!cache->base_p)
2477 return UNWIND_UNAVAILABLE;
2479 return UNWIND_NO_REASON;
2482 static void
2483 i386_sigtramp_frame_this_id (const frame_info_ptr &this_frame, void **this_cache,
2484 struct frame_id *this_id)
2486 struct i386_frame_cache *cache =
2487 i386_sigtramp_frame_cache (this_frame, this_cache);
2489 if (!cache->base_p)
2490 (*this_id) = frame_id_build_unavailable_stack (get_frame_pc (this_frame));
2491 else
2493 /* See the end of i386_push_dummy_call. */
2494 (*this_id) = frame_id_build (cache->base + 8, get_frame_pc (this_frame));
2498 static struct value *
2499 i386_sigtramp_frame_prev_register (const frame_info_ptr &this_frame,
2500 void **this_cache, int regnum)
2502 /* Make sure we've initialized the cache. */
2503 i386_sigtramp_frame_cache (this_frame, this_cache);
2505 return i386_frame_prev_register (this_frame, this_cache, regnum);
2508 static int
2509 i386_sigtramp_frame_sniffer (const struct frame_unwind *self,
2510 const frame_info_ptr &this_frame,
2511 void **this_prologue_cache)
2513 gdbarch *arch = get_frame_arch (this_frame);
2514 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
2516 /* We shouldn't even bother if we don't have a sigcontext_addr
2517 handler. */
2518 if (tdep->sigcontext_addr == NULL)
2519 return 0;
2521 if (tdep->sigtramp_p != NULL)
2523 if (tdep->sigtramp_p (this_frame))
2524 return 1;
2527 if (tdep->sigtramp_start != 0)
2529 CORE_ADDR pc = get_frame_pc (this_frame);
2531 gdb_assert (tdep->sigtramp_end != 0);
2532 if (pc >= tdep->sigtramp_start && pc < tdep->sigtramp_end)
2533 return 1;
2536 return 0;
2539 static const struct frame_unwind_legacy i386_sigtramp_frame_unwind (
2540 "i386 sigtramp",
2541 SIGTRAMP_FRAME,
2542 FRAME_UNWIND_ARCH,
2543 i386_sigtramp_frame_unwind_stop_reason,
2544 i386_sigtramp_frame_this_id,
2545 i386_sigtramp_frame_prev_register,
2546 NULL,
2547 i386_sigtramp_frame_sniffer
2551 static CORE_ADDR
2552 i386_frame_base_address (const frame_info_ptr &this_frame, void **this_cache)
2554 struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
2556 return cache->base;
2559 static const struct frame_base i386_frame_base =
2561 &i386_frame_unwind,
2562 i386_frame_base_address,
2563 i386_frame_base_address,
2564 i386_frame_base_address
2567 static struct frame_id
2568 i386_dummy_id (struct gdbarch *gdbarch, const frame_info_ptr &this_frame)
2570 CORE_ADDR fp;
2572 fp = get_frame_register_unsigned (this_frame, I386_EBP_REGNUM);
2574 /* See the end of i386_push_dummy_call. */
2575 return frame_id_build (fp + 8, get_frame_pc (this_frame));
2578 /* _Decimal128 function return values need 16-byte alignment on the
2579 stack. */
2581 static CORE_ADDR
2582 i386_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
2584 return sp & -(CORE_ADDR)16;
2588 /* Figure out where the longjmp will land. Slurp the args out of the
2589 stack. We expect the first arg to be a pointer to the jmp_buf
2590 structure from which we extract the address that we will land at.
2591 This address is copied into PC. This routine returns non-zero on
2592 success. */
2594 static int
2595 i386_get_longjmp_target (const frame_info_ptr &frame, CORE_ADDR *pc)
2597 gdb_byte buf[4];
2598 CORE_ADDR sp, jb_addr;
2599 struct gdbarch *gdbarch = get_frame_arch (frame);
2600 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2601 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
2602 int jb_pc_offset = tdep->jb_pc_offset;
2604 /* If JB_PC_OFFSET is -1, we have no way to find out where the
2605 longjmp will land. */
2606 if (jb_pc_offset == -1)
2607 return 0;
2609 get_frame_register (frame, I386_ESP_REGNUM, buf);
2610 sp = extract_unsigned_integer (buf, 4, byte_order);
2611 if (target_read_memory (sp + 4, buf, 4))
2612 return 0;
2614 jb_addr = extract_unsigned_integer (buf, 4, byte_order);
2615 if (target_read_memory (jb_addr + jb_pc_offset, buf, 4))
2616 return 0;
2618 *pc = extract_unsigned_integer (buf, 4, byte_order);
2619 return 1;
2623 /* Check whether TYPE must be 16-byte-aligned when passed as a
2624 function argument. 16-byte vectors, _Decimal128 and structures or
2625 unions containing such types must be 16-byte-aligned; other
2626 arguments are 4-byte-aligned. */
2628 static int
2629 i386_16_byte_align_p (struct type *type)
2631 type = check_typedef (type);
2632 if ((type->code () == TYPE_CODE_DECFLOAT
2633 || (type->code () == TYPE_CODE_ARRAY && type->is_vector ()))
2634 && type->length () == 16)
2635 return 1;
2636 if (type->code () == TYPE_CODE_ARRAY)
2637 return i386_16_byte_align_p (type->target_type ());
2638 if (type->code () == TYPE_CODE_STRUCT
2639 || type->code () == TYPE_CODE_UNION)
2641 int i;
2642 for (i = 0; i < type->num_fields (); i++)
2644 if (type->field (i).is_static ())
2645 continue;
2646 if (i386_16_byte_align_p (type->field (i).type ()))
2647 return 1;
2650 return 0;
2653 /* Implementation for set_gdbarch_push_dummy_code. */
2655 static CORE_ADDR
2656 i386_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, CORE_ADDR funaddr,
2657 struct value **args, int nargs, struct type *value_type,
2658 CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
2659 struct regcache *regcache)
2661 /* Use 0xcc breakpoint - 1 byte. */
2662 *bp_addr = sp - 1;
2663 *real_pc = funaddr;
2665 /* Keep the stack aligned. */
2666 return sp - 16;
2669 /* The "push_dummy_call" gdbarch method, optionally with the thiscall
2670 calling convention. */
2672 CORE_ADDR
2673 i386_thiscall_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
2674 struct regcache *regcache, CORE_ADDR bp_addr,
2675 int nargs, struct value **args, CORE_ADDR sp,
2676 function_call_return_method return_method,
2677 CORE_ADDR struct_addr, bool thiscall)
2679 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2680 gdb_byte buf[4];
2681 int i;
2682 int write_pass;
2683 int args_space = 0;
2685 /* Determine the total space required for arguments and struct
2686 return address in a first pass (allowing for 16-byte-aligned
2687 arguments), then push arguments in a second pass. */
2689 for (write_pass = 0; write_pass < 2; write_pass++)
2691 int args_space_used = 0;
2693 if (return_method == return_method_struct)
2695 if (write_pass)
2697 /* Push value address. */
2698 store_unsigned_integer (buf, 4, byte_order, struct_addr);
2699 write_memory (sp, buf, 4);
2700 args_space_used += 4;
2702 else
2703 args_space += 4;
2706 for (i = thiscall ? 1 : 0; i < nargs; i++)
2708 int len = args[i]->enclosing_type ()->length ();
2710 if (write_pass)
2712 if (i386_16_byte_align_p (args[i]->enclosing_type ()))
2713 args_space_used = align_up (args_space_used, 16);
2715 write_memory (sp + args_space_used,
2716 args[i]->contents_all ().data (), len);
2717 /* The System V ABI says that:
2719 "An argument's size is increased, if necessary, to make it a
2720 multiple of [32-bit] words. This may require tail padding,
2721 depending on the size of the argument."
2723 This makes sure the stack stays word-aligned. */
2724 args_space_used += align_up (len, 4);
2726 else
2728 if (i386_16_byte_align_p (args[i]->enclosing_type ()))
2729 args_space = align_up (args_space, 16);
2730 args_space += align_up (len, 4);
2734 if (!write_pass)
2736 sp -= args_space;
2738 /* The original System V ABI only requires word alignment,
2739 but modern incarnations need 16-byte alignment in order
2740 to support SSE. Since wasting a few bytes here isn't
2741 harmful we unconditionally enforce 16-byte alignment. */
2742 sp &= ~0xf;
2746 /* Store return address. */
2747 sp -= 4;
2748 store_unsigned_integer (buf, 4, byte_order, bp_addr);
2749 write_memory (sp, buf, 4);
2751 /* Finally, update the stack pointer... */
2752 store_unsigned_integer (buf, 4, byte_order, sp);
2753 regcache->cooked_write (I386_ESP_REGNUM, buf);
2755 /* ...and fake a frame pointer. */
2756 regcache->cooked_write (I386_EBP_REGNUM, buf);
2758 /* The 'this' pointer needs to be in ECX. */
2759 if (thiscall)
2760 regcache->cooked_write (I386_ECX_REGNUM,
2761 args[0]->contents_all ().data ());
2763 /* If the PLT is position-independent, the SYSTEM V ABI requires %ebx to be
2764 set to the address of the GOT when doing a call to a PLT address.
2765 Note that we do not try to determine whether the PLT is
2766 position-independent, we just set the register regardless. */
2767 CORE_ADDR func_addr = find_function_addr (function, nullptr, nullptr);
2768 if (in_plt_section (func_addr))
2770 struct objfile *objf = nullptr;
2771 asection *asect = nullptr;
2772 obj_section *osect = nullptr;
2774 /* Get object file containing func_addr. */
2775 obj_section *func_section = find_pc_section (func_addr);
2776 if (func_section != nullptr)
2777 objf = func_section->objfile;
2779 if (objf != nullptr)
2781 /* Get corresponding .got.plt or .got section. */
2782 asect = bfd_get_section_by_name (objf->obfd.get (), ".got.plt");
2783 if (asect == nullptr)
2784 asect = bfd_get_section_by_name (objf->obfd.get (), ".got");
2787 if (asect != nullptr)
2788 /* Translate asection to obj_section. */
2789 osect = maint_obj_section_from_bfd_section (objf->obfd.get (),
2790 asect, objf);
2792 if (osect != nullptr)
2794 /* Store the section address in %ebx. */
2795 store_unsigned_integer (buf, 4, byte_order, osect->addr ());
2796 regcache->cooked_write (I386_EBX_REGNUM, buf);
2798 else
2800 /* If we would only do this for a position-independent PLT, it would
2801 make sense to issue a warning here. */
2805 /* MarkK wrote: This "+ 8" is all over the place:
2806 (i386_frame_this_id, i386_sigtramp_frame_this_id,
2807 i386_dummy_id). It's there, since all frame unwinders for
2808 a given target have to agree (within a certain margin) on the
2809 definition of the stack address of a frame. Otherwise frame id
2810 comparison might not work correctly. Since DWARF2/GCC uses the
2811 stack address *before* the function call as a frame's CFA. On
2812 the i386, when %ebp is used as a frame pointer, the offset
2813 between the contents %ebp and the CFA as defined by GCC. */
2814 return sp + 8;
2817 /* Implement the "push_dummy_call" gdbarch method. */
2819 static CORE_ADDR
2820 i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
2821 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
2822 struct value **args, CORE_ADDR sp,
2823 function_call_return_method return_method,
2824 CORE_ADDR struct_addr)
2826 return i386_thiscall_push_dummy_call (gdbarch, function, regcache, bp_addr,
2827 nargs, args, sp, return_method,
2828 struct_addr, false);
2831 /* These registers are used for returning integers (and on some
2832 targets also for returning `struct' and `union' values when their
2833 size and alignment match an integer type). */
2834 #define LOW_RETURN_REGNUM I386_EAX_REGNUM /* %eax */
2835 #define HIGH_RETURN_REGNUM I386_EDX_REGNUM /* %edx */
2837 /* Read, for architecture GDBARCH, a function return value of TYPE
2838 from REGCACHE, and copy that into VALBUF. */
2840 static void
2841 i386_extract_return_value (struct gdbarch *gdbarch, struct type *type,
2842 struct regcache *regcache, gdb_byte *valbuf)
2844 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
2845 int len = type->length ();
2846 gdb_byte buf[I386_MAX_REGISTER_SIZE];
2848 /* _Float16 and _Float16 _Complex values are returned via xmm0. */
2849 if (((type->code () == TYPE_CODE_FLT) && len == 2)
2850 || ((type->code () == TYPE_CODE_COMPLEX) && len == 4))
2852 regcache->raw_read (I387_XMM0_REGNUM (tdep), valbuf);
2853 return;
2855 else if (type->code () == TYPE_CODE_FLT)
2857 if (tdep->st0_regnum < 0)
2859 warning (_("Cannot find floating-point return value."));
2860 memset (valbuf, 0, len);
2861 return;
2864 /* Floating-point return values can be found in %st(0). Convert
2865 its contents to the desired type. This is probably not
2866 exactly how it would happen on the target itself, but it is
2867 the best we can do. */
2868 regcache->raw_read (I386_ST0_REGNUM, buf);
2869 target_float_convert (buf, i387_ext_type (gdbarch), valbuf, type);
2871 else
2873 int low_size = register_size (gdbarch, LOW_RETURN_REGNUM);
2874 int high_size = register_size (gdbarch, HIGH_RETURN_REGNUM);
2876 if (len <= low_size)
2878 regcache->raw_read (LOW_RETURN_REGNUM, buf);
2879 memcpy (valbuf, buf, len);
2881 else if (len <= (low_size + high_size))
2883 regcache->raw_read (LOW_RETURN_REGNUM, buf);
2884 memcpy (valbuf, buf, low_size);
2885 regcache->raw_read (HIGH_RETURN_REGNUM, buf);
2886 memcpy (valbuf + low_size, buf, len - low_size);
2888 else
2889 internal_error (_("Cannot extract return value of %d bytes long."),
2890 len);
2894 /* Write, for architecture GDBARCH, a function return value of TYPE
2895 from VALBUF into REGCACHE. */
2897 static void
2898 i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
2899 struct regcache *regcache, const gdb_byte *valbuf)
2901 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
2902 int len = type->length ();
2904 if (type->code () == TYPE_CODE_FLT)
2906 ULONGEST fstat;
2907 gdb_byte buf[I386_MAX_REGISTER_SIZE];
2909 if (tdep->st0_regnum < 0)
2911 warning (_("Cannot set floating-point return value."));
2912 return;
2915 /* Returning floating-point values is a bit tricky. Apart from
2916 storing the return value in %st(0), we have to simulate the
2917 state of the FPU at function return point. */
2919 /* Convert the value found in VALBUF to the extended
2920 floating-point format used by the FPU. This is probably
2921 not exactly how it would happen on the target itself, but
2922 it is the best we can do. */
2923 target_float_convert (valbuf, type, buf, i387_ext_type (gdbarch));
2924 regcache->raw_write (I386_ST0_REGNUM, buf);
2926 /* Set the top of the floating-point register stack to 7. The
2927 actual value doesn't really matter, but 7 is what a normal
2928 function return would end up with if the program started out
2929 with a freshly initialized FPU. */
2930 regcache_raw_read_unsigned (regcache, I387_FSTAT_REGNUM (tdep), &fstat);
2931 fstat |= (7 << 11);
2932 regcache_raw_write_unsigned (regcache, I387_FSTAT_REGNUM (tdep), fstat);
2934 /* Mark %st(1) through %st(7) as empty. Since we set the top of
2935 the floating-point register stack to 7, the appropriate value
2936 for the tag word is 0x3fff. */
2937 regcache_raw_write_unsigned (regcache, I387_FTAG_REGNUM (tdep), 0x3fff);
2939 else
2941 int low_size = register_size (gdbarch, LOW_RETURN_REGNUM);
2942 int high_size = register_size (gdbarch, HIGH_RETURN_REGNUM);
2944 if (len <= low_size)
2945 regcache->raw_write_part (LOW_RETURN_REGNUM, 0, len, valbuf);
2946 else if (len <= (low_size + high_size))
2948 regcache->raw_write (LOW_RETURN_REGNUM, valbuf);
2949 regcache->raw_write_part (HIGH_RETURN_REGNUM, 0, len - low_size,
2950 valbuf + low_size);
2952 else
2953 internal_error (_("Cannot store return value of %d bytes long."), len);
2958 /* This is the variable that is set with "set struct-convention", and
2959 its legitimate values. */
2960 static const char default_struct_convention[] = "default";
2961 static const char pcc_struct_convention[] = "pcc";
2962 static const char reg_struct_convention[] = "reg";
2963 static const char *const valid_conventions[] =
2965 default_struct_convention,
2966 pcc_struct_convention,
2967 reg_struct_convention,
2968 NULL
2970 static const char *struct_convention = default_struct_convention;
2972 /* Return non-zero if TYPE, which is assumed to be a structure,
2973 a union type, or an array type, should be returned in registers
2974 for architecture GDBARCH. */
2976 static int
2977 i386_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
2979 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
2980 enum type_code code = type->code ();
2981 int len = type->length ();
2983 gdb_assert (code == TYPE_CODE_STRUCT
2984 || code == TYPE_CODE_UNION
2985 || code == TYPE_CODE_ARRAY);
2987 if (struct_convention == pcc_struct_convention
2988 || (struct_convention == default_struct_convention
2989 && tdep->struct_return == pcc_struct_return)
2990 || TYPE_HAS_DYNAMIC_LENGTH (type))
2991 return 0;
2993 /* Structures consisting of a single `float', `double' or 'long
2994 double' member are returned in %st(0). */
2995 if (code == TYPE_CODE_STRUCT && type->num_fields () == 1)
2997 type = check_typedef (type->field (0).type ());
2998 if (type->code () == TYPE_CODE_FLT)
2999 return (len == 4 || len == 8 || len == 12);
3002 return (len == 1 || len == 2 || len == 4 || len == 8);
3005 /* Determine, for architecture GDBARCH, how a return value of TYPE
3006 should be returned. If it is supposed to be returned in registers,
3007 and READBUF is non-zero, read the appropriate value from REGCACHE,
3008 and copy it into READBUF. If WRITEBUF is non-zero, write the value
3009 from WRITEBUF into REGCACHE. */
3011 static enum return_value_convention
3012 i386_return_value (struct gdbarch *gdbarch, struct value *function,
3013 struct type *type, struct regcache *regcache,
3014 struct value **read_value, const gdb_byte *writebuf)
3016 enum type_code code = type->code ();
3018 if (((code == TYPE_CODE_STRUCT
3019 || code == TYPE_CODE_UNION
3020 || code == TYPE_CODE_ARRAY)
3021 && !i386_reg_struct_return_p (gdbarch, type))
3022 /* Complex double and long double uses the struct return convention. */
3023 || (code == TYPE_CODE_COMPLEX && type->length () == 16)
3024 || (code == TYPE_CODE_COMPLEX && type->length () == 24)
3025 /* 128-bit decimal float uses the struct return convention. */
3026 || (code == TYPE_CODE_DECFLOAT && type->length () == 16))
3028 /* The System V ABI says that:
3030 "A function that returns a structure or union also sets %eax
3031 to the value of the original address of the caller's area
3032 before it returns. Thus when the caller receives control
3033 again, the address of the returned object resides in register
3034 %eax and can be used to access the object."
3036 So the ABI guarantees that we can always find the return
3037 value just after the function has returned. */
3039 /* Note that the ABI doesn't mention functions returning arrays,
3040 which is something possible in certain languages such as Ada.
3041 In this case, the value is returned as if it was wrapped in
3042 a record, so the convention applied to records also applies
3043 to arrays. */
3045 if (read_value != nullptr)
3047 ULONGEST addr;
3049 regcache_raw_read_unsigned (regcache, I386_EAX_REGNUM, &addr);
3050 *read_value = value_at_non_lval (type, addr);
3053 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
3056 /* This special case is for structures consisting of a single
3057 `float', `double' or 'long double' member. These structures are
3058 returned in %st(0). For these structures, we call ourselves
3059 recursively, changing TYPE into the type of the first member of
3060 the structure. Since that should work for all structures that
3061 have only one member, we don't bother to check the member's type
3062 here. */
3063 if (code == TYPE_CODE_STRUCT && type->num_fields () == 1)
3065 struct type *inner_type = check_typedef (type->field (0).type ());
3066 enum return_value_convention result
3067 = i386_return_value (gdbarch, function, inner_type, regcache,
3068 read_value, writebuf);
3069 if (read_value != nullptr)
3070 (*read_value)->deprecated_set_type (type);
3071 return result;
3074 if (read_value != nullptr)
3076 *read_value = value::allocate (type);
3077 i386_extract_return_value (gdbarch, type, regcache,
3078 (*read_value)->contents_raw ().data ());
3080 if (writebuf)
3081 i386_store_return_value (gdbarch, type, regcache, writebuf);
3083 return RETURN_VALUE_REGISTER_CONVENTION;
3087 struct type *
3088 i387_ext_type (struct gdbarch *gdbarch)
3090 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
3092 if (!tdep->i387_ext_type)
3094 tdep->i387_ext_type = tdesc_find_type (gdbarch, "i387_ext");
3095 gdb_assert (tdep->i387_ext_type != NULL);
3098 return tdep->i387_ext_type;
3101 /* Construct vector type for pseudo ZMM registers. We can't use
3102 tdesc_find_type since ZMM isn't described in target description. */
3104 static struct type *
3105 i386_zmm_type (struct gdbarch *gdbarch)
3107 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
3109 if (!tdep->i386_zmm_type)
3111 const struct builtin_type *bt = builtin_type (gdbarch);
3113 /* The type we're building is this: */
3114 #if 0
3115 union __gdb_builtin_type_vec512i
3117 int128_t v4_int128[4];
3118 int64_t v8_int64[8];
3119 int32_t v16_int32[16];
3120 int16_t v32_int16[32];
3121 int8_t v64_int8[64];
3122 double v8_double[8];
3123 float v16_float[16];
3124 float16_t v32_half[32];
3125 bfloat16_t v32_bfloat16[32];
3127 #endif
3129 struct type *t;
3131 t = arch_composite_type (gdbarch,
3132 "__gdb_builtin_type_vec512i", TYPE_CODE_UNION);
3133 append_composite_type_field (t, "v32_bfloat16",
3134 init_vector_type (bt->builtin_bfloat16, 32));
3135 append_composite_type_field (t, "v32_half",
3136 init_vector_type (bt->builtin_half, 32));
3137 append_composite_type_field (t, "v16_float",
3138 init_vector_type (bt->builtin_float, 16));
3139 append_composite_type_field (t, "v8_double",
3140 init_vector_type (bt->builtin_double, 8));
3141 append_composite_type_field (t, "v64_int8",
3142 init_vector_type (bt->builtin_int8, 64));
3143 append_composite_type_field (t, "v32_int16",
3144 init_vector_type (bt->builtin_int16, 32));
3145 append_composite_type_field (t, "v16_int32",
3146 init_vector_type (bt->builtin_int32, 16));
3147 append_composite_type_field (t, "v8_int64",
3148 init_vector_type (bt->builtin_int64, 8));
3149 append_composite_type_field (t, "v4_int128",
3150 init_vector_type (bt->builtin_int128, 4));
3152 t->set_is_vector (true);
3153 t->set_name ("builtin_type_vec512i");
3154 tdep->i386_zmm_type = t;
3157 return tdep->i386_zmm_type;
3160 /* Construct vector type for pseudo YMM registers. We can't use
3161 tdesc_find_type since YMM isn't described in target description. */
3163 static struct type *
3164 i386_ymm_type (struct gdbarch *gdbarch)
3166 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
3168 if (!tdep->i386_ymm_type)
3170 const struct builtin_type *bt = builtin_type (gdbarch);
3172 /* The type we're building is this: */
3173 #if 0
3174 union __gdb_builtin_type_vec256i
3176 int128_t v2_int128[2];
3177 int64_t v4_int64[4];
3178 int32_t v8_int32[8];
3179 int16_t v16_int16[16];
3180 int8_t v32_int8[32];
3181 double v4_double[4];
3182 float v8_float[8];
3183 float16_t v16_half[16];
3184 bfloat16_t v16_bfloat16[16];
3186 #endif
3188 struct type *t;
3190 t = arch_composite_type (gdbarch,
3191 "__gdb_builtin_type_vec256i", TYPE_CODE_UNION);
3192 append_composite_type_field (t, "v16_bfloat16",
3193 init_vector_type (bt->builtin_bfloat16, 16));
3194 append_composite_type_field (t, "v16_half",
3195 init_vector_type (bt->builtin_half, 16));
3196 append_composite_type_field (t, "v8_float",
3197 init_vector_type (bt->builtin_float, 8));
3198 append_composite_type_field (t, "v4_double",
3199 init_vector_type (bt->builtin_double, 4));
3200 append_composite_type_field (t, "v32_int8",
3201 init_vector_type (bt->builtin_int8, 32));
3202 append_composite_type_field (t, "v16_int16",
3203 init_vector_type (bt->builtin_int16, 16));
3204 append_composite_type_field (t, "v8_int32",
3205 init_vector_type (bt->builtin_int32, 8));
3206 append_composite_type_field (t, "v4_int64",
3207 init_vector_type (bt->builtin_int64, 4));
3208 append_composite_type_field (t, "v2_int128",
3209 init_vector_type (bt->builtin_int128, 2));
3211 t->set_is_vector (true);
3212 t->set_name ("builtin_type_vec256i");
3213 tdep->i386_ymm_type = t;
3216 return tdep->i386_ymm_type;
3219 /* Construct vector type for MMX registers. */
3220 static struct type *
3221 i386_mmx_type (struct gdbarch *gdbarch)
3223 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
3225 if (!tdep->i386_mmx_type)
3227 const struct builtin_type *bt = builtin_type (gdbarch);
3229 /* The type we're building is this: */
3230 #if 0
3231 union __gdb_builtin_type_vec64i
3233 int64_t uint64;
3234 int32_t v2_int32[2];
3235 int16_t v4_int16[4];
3236 int8_t v8_int8[8];
3238 #endif
3240 struct type *t;
3242 t = arch_composite_type (gdbarch,
3243 "__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
3245 append_composite_type_field (t, "uint64", bt->builtin_int64);
3246 append_composite_type_field (t, "v2_int32",
3247 init_vector_type (bt->builtin_int32, 2));
3248 append_composite_type_field (t, "v4_int16",
3249 init_vector_type (bt->builtin_int16, 4));
3250 append_composite_type_field (t, "v8_int8",
3251 init_vector_type (bt->builtin_int8, 8));
3253 t->set_is_vector (true);
3254 t->set_name ("builtin_type_vec64i");
3255 tdep->i386_mmx_type = t;
3258 return tdep->i386_mmx_type;
3261 /* Return the GDB type object for the "standard" data type of data in
3262 register REGNUM. */
3264 struct type *
3265 i386_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
3267 if (i386_mmx_regnum_p (gdbarch, regnum))
3268 return i386_mmx_type (gdbarch);
3269 else if (i386_ymm_regnum_p (gdbarch, regnum))
3270 return i386_ymm_type (gdbarch);
3271 else if (i386_ymm_avx512_regnum_p (gdbarch, regnum))
3272 return i386_ymm_type (gdbarch);
3273 else if (i386_zmm_regnum_p (gdbarch, regnum))
3274 return i386_zmm_type (gdbarch);
3275 else
3277 const struct builtin_type *bt = builtin_type (gdbarch);
3278 if (i386_byte_regnum_p (gdbarch, regnum))
3279 return bt->builtin_int8;
3280 else if (i386_word_regnum_p (gdbarch, regnum))
3281 return bt->builtin_int16;
3282 else if (i386_dword_regnum_p (gdbarch, regnum))
3283 return bt->builtin_int32;
3284 else if (i386_k_regnum_p (gdbarch, regnum))
3285 return bt->builtin_int64;
3288 internal_error (_("invalid regnum"));
3291 /* Map a cooked register onto a raw register or memory. For the i386,
3292 the MMX registers need to be mapped onto floating point registers. */
3294 static int
3295 i386_mmx_regnum_to_fp_regnum (const frame_info_ptr &next_frame, int regnum)
3297 gdbarch *arch = frame_unwind_arch (next_frame);
3298 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (arch);
3299 ULONGEST fstat
3300 = frame_unwind_register_unsigned (next_frame, I387_FSTAT_REGNUM (tdep));
3301 int tos = (fstat >> 11) & 0x7;
3302 int mmxreg = regnum - tdep->mm0_regnum;
3303 int fpreg = (mmxreg + tos) % 8;
3305 return (I387_ST0_REGNUM (tdep) + fpreg);
3308 /* A helper function for us by i386_pseudo_register_read_value and
3309 amd64_pseudo_register_read_value. It does all the work but reads
3310 the data into an already-allocated value. */
3312 value *
3313 i386_pseudo_register_read_value (gdbarch *gdbarch, const frame_info_ptr &next_frame,
3314 const int pseudo_reg_num)
3316 if (i386_mmx_regnum_p (gdbarch, pseudo_reg_num))
3318 int fpnum = i386_mmx_regnum_to_fp_regnum (next_frame, pseudo_reg_num);
3320 /* Extract (always little endian). */
3321 return pseudo_from_raw_part (next_frame, pseudo_reg_num, fpnum, 0);
3323 else
3325 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
3326 if (i386_zmm_regnum_p (gdbarch, pseudo_reg_num))
3328 /* Which register is it, relative to zmm0. */
3329 int i_0 = pseudo_reg_num - tdep->zmm0_regnum;
3331 if (i_0 < num_lower_zmm_regs)
3332 return pseudo_from_concat_raw (next_frame, pseudo_reg_num,
3333 I387_XMM0_REGNUM (tdep) + i_0,
3334 tdep->ymm0h_regnum + i_0,
3335 tdep->zmm0h_regnum + i_0);
3336 else
3338 /* Which register is it, relative to zmm16. */
3339 int i_16 = i_0 - num_lower_zmm_regs;
3341 return pseudo_from_concat_raw (next_frame, pseudo_reg_num,
3342 I387_XMM16_REGNUM (tdep) + i_16,
3343 I387_YMM16H_REGNUM (tdep) + i_16,
3344 tdep->zmm0h_regnum + i_0);
3347 else if (i386_ymm_regnum_p (gdbarch, pseudo_reg_num))
3349 int i = pseudo_reg_num - tdep->ymm0_regnum;
3351 return pseudo_from_concat_raw (next_frame, pseudo_reg_num,
3352 I387_XMM0_REGNUM (tdep) + i,
3353 tdep->ymm0h_regnum + i);
3355 else if (i386_ymm_avx512_regnum_p (gdbarch, pseudo_reg_num))
3357 int i = pseudo_reg_num - tdep->ymm16_regnum;
3359 return pseudo_from_concat_raw (next_frame, pseudo_reg_num,
3360 I387_XMM16_REGNUM (tdep) + i,
3361 tdep->ymm16h_regnum + i);
3363 else if (i386_word_regnum_p (gdbarch, pseudo_reg_num))
3365 int gpnum = pseudo_reg_num - tdep->ax_regnum;
3367 /* Extract (always little endian). */
3368 return pseudo_from_raw_part (next_frame, pseudo_reg_num, gpnum, 0);
3370 else if (i386_byte_regnum_p (gdbarch, pseudo_reg_num))
3372 int gpnum = pseudo_reg_num - tdep->al_regnum;
3374 /* Extract (always little endian). We read both lower and
3375 upper registers. */
3376 return pseudo_from_raw_part (next_frame, pseudo_reg_num, gpnum % 4,
3377 gpnum >= 4 ? 1 : 0);
3379 else
3380 internal_error (_("invalid regnum"));
3384 void
3385 i386_pseudo_register_write (gdbarch *gdbarch, const frame_info_ptr &next_frame,
3386 const int pseudo_reg_num,
3387 gdb::array_view<const gdb_byte> buf)
3389 if (i386_mmx_regnum_p (gdbarch, pseudo_reg_num))
3391 int fpnum = i386_mmx_regnum_to_fp_regnum (next_frame, pseudo_reg_num);
3393 pseudo_to_raw_part (next_frame, buf, fpnum, 0);
3395 else
3397 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
3399 if (i386_zmm_regnum_p (gdbarch, pseudo_reg_num))
3401 /* Which register is it, relative to zmm0. */
3402 int reg_index_0 = pseudo_reg_num - tdep->zmm0_regnum;
3404 if (reg_index_0 < num_lower_zmm_regs)
3405 pseudo_to_concat_raw (next_frame, buf,
3406 I387_XMM0_REGNUM (tdep) + reg_index_0,
3407 I387_YMM0_REGNUM (tdep) + reg_index_0,
3408 tdep->zmm0h_regnum + reg_index_0);
3409 else
3411 /* Which register is it, relative to zmm16. */
3412 int reg_index_16 = reg_index_0 - num_lower_zmm_regs;
3414 pseudo_to_concat_raw (next_frame, buf,
3415 I387_XMM16_REGNUM (tdep) + reg_index_16,
3416 I387_YMM16H_REGNUM (tdep) + reg_index_16,
3417 tdep->zmm0h_regnum + +reg_index_0);
3420 else if (i386_ymm_regnum_p (gdbarch, pseudo_reg_num))
3422 int i = pseudo_reg_num - tdep->ymm0_regnum;
3424 pseudo_to_concat_raw (next_frame, buf, I387_XMM0_REGNUM (tdep) + i,
3425 tdep->ymm0h_regnum + i);
3427 else if (i386_ymm_avx512_regnum_p (gdbarch, pseudo_reg_num))
3429 int i = pseudo_reg_num - tdep->ymm16_regnum;
3431 pseudo_to_concat_raw (next_frame, buf, I387_XMM16_REGNUM (tdep) + i,
3432 tdep->ymm16h_regnum + i);
3434 else if (i386_word_regnum_p (gdbarch, pseudo_reg_num))
3436 int gpnum = pseudo_reg_num - tdep->ax_regnum;
3438 pseudo_to_raw_part (next_frame, buf, gpnum, 0);
3440 else if (i386_byte_regnum_p (gdbarch, pseudo_reg_num))
3442 int gpnum = pseudo_reg_num - tdep->al_regnum;
3444 pseudo_to_raw_part (next_frame, buf, gpnum % 4, gpnum >= 4 ? 1 : 0);
3446 else
3447 internal_error (_("invalid regnum"));
3451 /* Implement the 'ax_pseudo_register_collect' gdbarch method. */
3454 i386_ax_pseudo_register_collect (struct gdbarch *gdbarch,
3455 struct agent_expr *ax, int regnum)
3457 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
3459 if (i386_mmx_regnum_p (gdbarch, regnum))
3461 /* MMX to FPU register mapping depends on current TOS. Let's just
3462 not care and collect everything... */
3463 int i;
3465 ax_reg_mask (ax, I387_FSTAT_REGNUM (tdep));
3466 for (i = 0; i < 8; i++)
3467 ax_reg_mask (ax, I387_ST0_REGNUM (tdep) + i);
3468 return 0;
3470 else if (i386_zmm_regnum_p (gdbarch, regnum))
3472 regnum -= tdep->zmm0_regnum;
3473 if (regnum < num_lower_zmm_regs)
3475 ax_reg_mask (ax, I387_XMM0_REGNUM (tdep) + regnum);
3476 ax_reg_mask (ax, tdep->ymm0h_regnum + regnum);
3478 else
3480 ax_reg_mask (ax, I387_XMM16_REGNUM (tdep) + regnum
3481 - num_lower_zmm_regs);
3482 ax_reg_mask (ax, I387_YMM16H_REGNUM (tdep) + regnum
3483 - num_lower_zmm_regs);
3485 ax_reg_mask (ax, tdep->zmm0h_regnum + regnum);
3486 return 0;
3488 else if (i386_ymm_regnum_p (gdbarch, regnum))
3490 regnum -= tdep->ymm0_regnum;
3491 ax_reg_mask (ax, I387_XMM0_REGNUM (tdep) + regnum);
3492 ax_reg_mask (ax, tdep->ymm0h_regnum + regnum);
3493 return 0;
3495 else if (i386_ymm_avx512_regnum_p (gdbarch, regnum))
3497 regnum -= tdep->ymm16_regnum;
3498 ax_reg_mask (ax, I387_XMM16_REGNUM (tdep) + regnum);
3499 ax_reg_mask (ax, tdep->ymm16h_regnum + regnum);
3500 return 0;
3502 else if (i386_word_regnum_p (gdbarch, regnum))
3504 int gpnum = regnum - tdep->ax_regnum;
3506 ax_reg_mask (ax, gpnum);
3507 return 0;
3509 else if (i386_byte_regnum_p (gdbarch, regnum))
3511 int gpnum = regnum - tdep->al_regnum;
3513 ax_reg_mask (ax, gpnum % 4);
3514 return 0;
3516 else
3517 internal_error (_("invalid regnum"));
3518 return 1;
3522 /* Return the register number of the register allocated by GCC after
3523 REGNUM, or -1 if there is no such register. */
3525 static int
3526 i386_next_regnum (int regnum)
3528 /* GCC allocates the registers in the order:
3530 %eax, %edx, %ecx, %ebx, %esi, %edi, %ebp, %esp, ...
3532 Since storing a variable in %esp doesn't make any sense we return
3533 -1 for %ebp and for %esp itself. */
3534 static int next_regnum[] =
3536 I386_EDX_REGNUM, /* Slot for %eax. */
3537 I386_EBX_REGNUM, /* Slot for %ecx. */
3538 I386_ECX_REGNUM, /* Slot for %edx. */
3539 I386_ESI_REGNUM, /* Slot for %ebx. */
3540 -1, -1, /* Slots for %esp and %ebp. */
3541 I386_EDI_REGNUM, /* Slot for %esi. */
3542 I386_EBP_REGNUM /* Slot for %edi. */
3545 if (regnum >= 0 && regnum < sizeof (next_regnum) / sizeof (next_regnum[0]))
3546 return next_regnum[regnum];
3548 return -1;
3551 /* Return nonzero if a value of type TYPE stored in register REGNUM
3552 needs any special handling. */
3554 static int
3555 i386_convert_register_p (struct gdbarch *gdbarch,
3556 int regnum, struct type *type)
3558 int len = type->length ();
3560 /* Values may be spread across multiple registers. Most debugging
3561 formats aren't expressive enough to specify the locations, so
3562 some heuristics is involved. Right now we only handle types that
3563 have a length that is a multiple of the word size, since GCC
3564 doesn't seem to put any other types into registers. */
3565 if (len > 4 && len % 4 == 0)
3567 int last_regnum = regnum;
3569 while (len > 4)
3571 last_regnum = i386_next_regnum (last_regnum);
3572 len -= 4;
3575 if (last_regnum != -1)
3576 return 1;
3579 return i387_convert_register_p (gdbarch, regnum, type);
3582 /* Read a value of type TYPE from register REGNUM in frame FRAME, and
3583 return its contents in TO. */
3585 static int
3586 i386_register_to_value (const frame_info_ptr &frame, int regnum,
3587 struct type *type, gdb_byte *to,
3588 int *optimizedp, int *unavailablep)
3590 struct gdbarch *gdbarch = get_frame_arch (frame);
3591 int len = type->length ();
3593 if (i386_fp_regnum_p (gdbarch, regnum))
3594 return i387_register_to_value (frame, regnum, type, to,
3595 optimizedp, unavailablep);
3597 /* Read a value spread across multiple registers. */
3599 gdb_assert (len > 4 && len % 4 == 0);
3601 while (len > 0)
3603 gdb_assert (regnum != -1);
3604 gdb_assert (register_size (gdbarch, regnum) == 4);
3606 auto to_view
3607 = gdb::make_array_view (to, register_size (gdbarch, regnum));
3608 frame_info_ptr next_frame = get_next_frame_sentinel_okay (frame);
3609 if (!get_frame_register_bytes (next_frame, regnum, 0, to_view,
3610 optimizedp, unavailablep))
3611 return 0;
3613 regnum = i386_next_regnum (regnum);
3614 len -= 4;
3615 to += 4;
3618 *optimizedp = *unavailablep = 0;
3619 return 1;
3622 /* Write the contents FROM of a value of type TYPE into register
3623 REGNUM in frame FRAME. */
3625 static void
3626 i386_value_to_register (const frame_info_ptr &frame, int regnum,
3627 struct type *type, const gdb_byte *from)
3629 int len = type->length ();
3631 if (i386_fp_regnum_p (get_frame_arch (frame), regnum))
3633 i387_value_to_register (frame, regnum, type, from);
3634 return;
3637 /* Write a value spread across multiple registers. */
3639 gdb_assert (len > 4 && len % 4 == 0);
3641 while (len > 0)
3643 gdb_assert (regnum != -1);
3644 gdb_assert (register_size (get_frame_arch (frame), regnum) == 4);
3646 auto from_view = gdb::make_array_view (from, 4);
3647 put_frame_register (get_next_frame_sentinel_okay (frame), regnum,
3648 from_view);
3649 regnum = i386_next_regnum (regnum);
3650 len -= 4;
3651 from += 4;
3655 /* Supply register REGNUM from the buffer specified by GREGS and LEN
3656 in the general-purpose register set REGSET to register cache
3657 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
3659 void
3660 i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
3661 int regnum, const void *gregs, size_t len)
3663 struct gdbarch *gdbarch = regcache->arch ();
3664 const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
3665 const gdb_byte *regs = (const gdb_byte *) gregs;
3666 int i;
3668 gdb_assert (len >= tdep->sizeof_gregset);
3670 for (i = 0; i < tdep->gregset_num_regs; i++)
3672 if ((regnum == i || regnum == -1)
3673 && tdep->gregset_reg_offset[i] != -1)
3674 regcache->raw_supply (i, regs + tdep->gregset_reg_offset[i]);
3678 /* Collect register REGNUM from the register cache REGCACHE and store
3679 it in the buffer specified by GREGS and LEN as described by the
3680 general-purpose register set REGSET. If REGNUM is -1, do this for
3681 all registers in REGSET. */
3683 static void
3684 i386_collect_gregset (const struct regset *regset,
3685 const struct regcache *regcache,
3686 int regnum, void *gregs, size_t len)
3688 struct gdbarch *gdbarch = regcache->arch ();
3689 const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
3690 gdb_byte *regs = (gdb_byte *) gregs;
3691 int i;
3693 gdb_assert (len >= tdep->sizeof_gregset);
3695 for (i = 0; i < tdep->gregset_num_regs; i++)
3697 if ((regnum == i || regnum == -1)
3698 && tdep->gregset_reg_offset[i] != -1)
3699 regcache->raw_collect (i, regs + tdep->gregset_reg_offset[i]);
3703 /* Supply register REGNUM from the buffer specified by FPREGS and LEN
3704 in the floating-point register set REGSET to register cache
3705 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
3707 static void
3708 i386_supply_fpregset (const struct regset *regset, struct regcache *regcache,
3709 int regnum, const void *fpregs, size_t len)
3711 struct gdbarch *gdbarch = regcache->arch ();
3712 const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
3714 if (len == I387_SIZEOF_FXSAVE)
3716 i387_supply_fxsave (regcache, regnum, fpregs);
3717 return;
3720 gdb_assert (len >= tdep->sizeof_fpregset);
3721 i387_supply_fsave (regcache, regnum, fpregs);
3724 /* Collect register REGNUM from the register cache REGCACHE and store
3725 it in the buffer specified by FPREGS and LEN as described by the
3726 floating-point register set REGSET. If REGNUM is -1, do this for
3727 all registers in REGSET. */
3729 static void
3730 i386_collect_fpregset (const struct regset *regset,
3731 const struct regcache *regcache,
3732 int regnum, void *fpregs, size_t len)
3734 struct gdbarch *gdbarch = regcache->arch ();
3735 const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
3737 if (len == I387_SIZEOF_FXSAVE)
3739 i387_collect_fxsave (regcache, regnum, fpregs);
3740 return;
3743 gdb_assert (len >= tdep->sizeof_fpregset);
3744 i387_collect_fsave (regcache, regnum, fpregs);
3747 /* Register set definitions. */
3749 const struct regset i386_gregset =
3751 NULL, i386_supply_gregset, i386_collect_gregset
3754 const struct regset i386_fpregset =
3756 NULL, i386_supply_fpregset, i386_collect_fpregset
3759 /* Default iterator over core file register note sections. */
3761 void
3762 i386_iterate_over_regset_sections (struct gdbarch *gdbarch,
3763 iterate_over_regset_sections_cb *cb,
3764 void *cb_data,
3765 const struct regcache *regcache)
3767 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
3769 cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, &i386_gregset, NULL,
3770 cb_data);
3771 if (tdep->sizeof_fpregset)
3772 cb (".reg2", tdep->sizeof_fpregset, tdep->sizeof_fpregset, tdep->fpregset,
3773 NULL, cb_data);
3777 /* Stuff for WIN32 PE style DLL's but is pretty generic really. */
3779 CORE_ADDR
3780 i386_pe_skip_trampoline_code (const frame_info_ptr &frame,
3781 CORE_ADDR pc, char *name)
3783 struct gdbarch *gdbarch = get_frame_arch (frame);
3784 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3786 /* jmp *(dest) */
3787 if (pc && read_memory_unsigned_integer (pc, 2, byte_order) == 0x25ff)
3789 unsigned long indirect =
3790 read_memory_unsigned_integer (pc + 2, 4, byte_order);
3791 struct minimal_symbol *indsym =
3792 indirect ? lookup_minimal_symbol_by_pc (indirect).minsym : 0;
3793 const char *symname = indsym ? indsym->linkage_name () : 0;
3795 if (symname)
3797 if (startswith (symname, "__imp_")
3798 || startswith (symname, "_imp_"))
3799 return name ? 1 :
3800 read_memory_unsigned_integer (indirect, 4, byte_order);
3803 return 0; /* Not a trampoline. */
3807 /* Return whether the THIS_FRAME corresponds to a sigtramp
3808 routine. */
3811 i386_sigtramp_p (const frame_info_ptr &this_frame)
3813 CORE_ADDR pc = get_frame_pc (this_frame);
3814 const char *name;
3816 find_pc_partial_function (pc, &name, NULL, NULL);
3817 return (name && strcmp ("_sigtramp", name) == 0);
3821 /* We have two flavours of disassembly. The machinery on this page
3822 deals with switching between those. */
3824 static int
3825 i386_print_insn (bfd_vma pc, struct disassemble_info *info)
3827 gdb_assert (disassembly_flavor == att_flavor
3828 || disassembly_flavor == intel_flavor);
3830 info->disassembler_options = disassembly_flavor;
3832 return default_print_insn (pc, info);
3836 /* There are a few i386 architecture variants that differ only
3837 slightly from the generic i386 target. For now, we don't give them
3838 their own source file, but include them here. As a consequence,
3839 they'll always be included. */
3841 /* System V Release 4 (SVR4). */
3843 /* Return whether THIS_FRAME corresponds to a SVR4 sigtramp
3844 routine. */
3846 static int
3847 i386_svr4_sigtramp_p (const frame_info_ptr &this_frame)
3849 CORE_ADDR pc = get_frame_pc (this_frame);
3850 const char *name;
3852 /* The origin of these symbols is currently unknown. */
3853 find_pc_partial_function (pc, &name, NULL, NULL);
3854 return (name && (strcmp ("_sigreturn", name) == 0
3855 || strcmp ("sigvechandler", name) == 0));
3858 /* Assuming THIS_FRAME is for a SVR4 sigtramp routine, return the
3859 address of the associated sigcontext (ucontext) structure. */
3861 static CORE_ADDR
3862 i386_svr4_sigcontext_addr (const frame_info_ptr &this_frame)
3864 struct gdbarch *gdbarch = get_frame_arch (this_frame);
3865 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3866 gdb_byte buf[4];
3867 CORE_ADDR sp;
3869 get_frame_register (this_frame, I386_ESP_REGNUM, buf);
3870 sp = extract_unsigned_integer (buf, 4, byte_order);
3872 return read_memory_unsigned_integer (sp + 8, 4, byte_order);
3877 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
3878 gdbarch.h. */
3881 i386_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
3883 return (*s == '$' /* Literal number. */
3884 || (isdigit (*s) && s[1] == '(' && s[2] == '%') /* Displacement. */
3885 || (*s == '(' && s[1] == '%') /* Register indirection. */
3886 || (*s == '%' && isalpha (s[1]))); /* Register access. */
3889 /* Helper function for i386_stap_parse_special_token.
3891 This function parses operands of the form `-8+3+1(%rbp)', which
3892 must be interpreted as `*(-8 + 3 - 1 + (void *) $eax)'.
3894 Return true if the operand was parsed successfully, false
3895 otherwise. */
3897 static expr::operation_up
3898 i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
3899 struct stap_parse_info *p)
3901 const char *s = p->arg;
3903 if (isdigit (*s) || *s == '-' || *s == '+')
3905 bool got_minus[3];
3906 int i;
3907 long displacements[3];
3908 const char *start;
3909 int len;
3910 char *endp;
3912 got_minus[0] = false;
3913 if (*s == '+')
3914 ++s;
3915 else if (*s == '-')
3917 ++s;
3918 got_minus[0] = true;
3921 if (!isdigit ((unsigned char) *s))
3922 return {};
3924 displacements[0] = strtol (s, &endp, 10);
3925 s = endp;
3927 if (*s != '+' && *s != '-')
3929 /* We are not dealing with a triplet. */
3930 return {};
3933 got_minus[1] = false;
3934 if (*s == '+')
3935 ++s;
3936 else
3938 ++s;
3939 got_minus[1] = true;
3942 if (!isdigit ((unsigned char) *s))
3943 return {};
3945 displacements[1] = strtol (s, &endp, 10);
3946 s = endp;
3948 if (*s != '+' && *s != '-')
3950 /* We are not dealing with a triplet. */
3951 return {};
3954 got_minus[2] = false;
3955 if (*s == '+')
3956 ++s;
3957 else
3959 ++s;
3960 got_minus[2] = true;
3963 if (!isdigit ((unsigned char) *s))
3964 return {};
3966 displacements[2] = strtol (s, &endp, 10);
3967 s = endp;
3969 if (*s != '(' || s[1] != '%')
3970 return {};
3972 s += 2;
3973 start = s;
3975 while (isalnum (*s))
3976 ++s;
3978 if (*s++ != ')')
3979 return {};
3981 len = s - start - 1;
3982 std::string regname (start, len);
3984 if (user_reg_map_name_to_regnum (gdbarch, regname.c_str (), len) == -1)
3985 error (_("Invalid register name `%s' on expression `%s'."),
3986 regname.c_str (), p->saved_arg);
3988 LONGEST value = 0;
3989 for (i = 0; i < 3; i++)
3991 LONGEST this_val = displacements[i];
3992 if (got_minus[i])
3993 this_val = -this_val;
3994 value += this_val;
3997 p->arg = s;
3999 using namespace expr;
4001 struct type *long_type = builtin_type (gdbarch)->builtin_long;
4002 operation_up offset
4003 = make_operation<long_const_operation> (long_type, value);
4005 operation_up reg
4006 = make_operation<register_operation> (std::move (regname));
4007 struct type *void_ptr = builtin_type (gdbarch)->builtin_data_ptr;
4008 reg = make_operation<unop_cast_operation> (std::move (reg), void_ptr);
4010 operation_up sum
4011 = make_operation<add_operation> (std::move (reg), std::move (offset));
4012 struct type *arg_ptr_type = lookup_pointer_type (p->arg_type);
4013 sum = make_operation<unop_cast_operation> (std::move (sum),
4014 arg_ptr_type);
4015 return make_operation<unop_ind_operation> (std::move (sum));
4018 return {};
4021 /* Helper function for i386_stap_parse_special_token.
4023 This function parses operands of the form `register base +
4024 (register index * size) + offset', as represented in
4025 `(%rcx,%rax,8)', or `[OFFSET](BASE_REG,INDEX_REG[,SIZE])'.
4027 Return true if the operand was parsed successfully, false
4028 otherwise. */
4030 static expr::operation_up
4031 i386_stap_parse_special_token_three_arg_disp (struct gdbarch *gdbarch,
4032 struct stap_parse_info *p)
4034 const char *s = p->arg;
4036 if (isdigit (*s) || *s == '(' || *s == '-' || *s == '+')
4038 bool offset_minus = false;
4039 long offset = 0;
4040 bool size_minus = false;
4041 long size = 0;
4042 const char *start;
4043 int len_base;
4044 int len_index;
4046 if (*s == '+')
4047 ++s;
4048 else if (*s == '-')
4050 ++s;
4051 offset_minus = true;
4054 if (offset_minus && !isdigit (*s))
4055 return {};
4057 if (isdigit (*s))
4059 char *endp;
4061 offset = strtol (s, &endp, 10);
4062 s = endp;
4065 if (*s != '(' || s[1] != '%')
4066 return {};
4068 s += 2;
4069 start = s;
4071 while (isalnum (*s))
4072 ++s;
4074 if (*s != ',' || s[1] != '%')
4075 return {};
4077 len_base = s - start;
4078 std::string base (start, len_base);
4080 if (user_reg_map_name_to_regnum (gdbarch, base.c_str (), len_base) == -1)
4081 error (_("Invalid register name `%s' on expression `%s'."),
4082 base.c_str (), p->saved_arg);
4084 s += 2;
4085 start = s;
4087 while (isalnum (*s))
4088 ++s;
4090 len_index = s - start;
4091 std::string index (start, len_index);
4093 if (user_reg_map_name_to_regnum (gdbarch, index.c_str (),
4094 len_index) == -1)
4095 error (_("Invalid register name `%s' on expression `%s'."),
4096 index.c_str (), p->saved_arg);
4098 if (*s != ',' && *s != ')')
4099 return {};
4101 if (*s == ',')
4103 char *endp;
4105 ++s;
4106 if (*s == '+')
4107 ++s;
4108 else if (*s == '-')
4110 ++s;
4111 size_minus = true;
4114 size = strtol (s, &endp, 10);
4115 s = endp;
4117 if (*s != ')')
4118 return {};
4121 ++s;
4122 p->arg = s;
4124 using namespace expr;
4126 struct type *long_type = builtin_type (gdbarch)->builtin_long;
4127 operation_up reg = make_operation<register_operation> (std::move (base));
4129 if (offset != 0)
4131 if (offset_minus)
4132 offset = -offset;
4133 operation_up value
4134 = make_operation<long_const_operation> (long_type, offset);
4135 reg = make_operation<add_operation> (std::move (reg),
4136 std::move (value));
4139 operation_up ind_reg
4140 = make_operation<register_operation> (std::move (index));
4142 if (size != 0)
4144 if (size_minus)
4145 size = -size;
4146 operation_up value
4147 = make_operation<long_const_operation> (long_type, size);
4148 ind_reg = make_operation<mul_operation> (std::move (ind_reg),
4149 std::move (value));
4152 operation_up sum
4153 = make_operation<add_operation> (std::move (reg),
4154 std::move (ind_reg));
4156 struct type *arg_ptr_type = lookup_pointer_type (p->arg_type);
4157 sum = make_operation<unop_cast_operation> (std::move (sum),
4158 arg_ptr_type);
4159 return make_operation<unop_ind_operation> (std::move (sum));
4162 return {};
4165 /* Implementation of `gdbarch_stap_parse_special_token', as defined in
4166 gdbarch.h. */
4168 expr::operation_up
4169 i386_stap_parse_special_token (struct gdbarch *gdbarch,
4170 struct stap_parse_info *p)
4172 /* The special tokens to be parsed here are:
4174 - `register base + (register index * size) + offset', as represented
4175 in `(%rcx,%rax,8)', or `[OFFSET](BASE_REG,INDEX_REG[,SIZE])'.
4177 - Operands of the form `-8+3+1(%rbp)', which must be interpreted as
4178 `*(-8 + 3 - 1 + (void *) $eax)'. */
4180 expr::operation_up result
4181 = i386_stap_parse_special_token_triplet (gdbarch, p);
4183 if (result == nullptr)
4184 result = i386_stap_parse_special_token_three_arg_disp (gdbarch, p);
4186 return result;
4189 /* Implementation of 'gdbarch_stap_adjust_register', as defined in
4190 gdbarch.h. */
4192 static std::string
4193 i386_stap_adjust_register (struct gdbarch *gdbarch, struct stap_parse_info *p,
4194 const std::string &regname, int regnum)
4196 static const std::unordered_set<std::string> reg_assoc
4197 = { "ax", "bx", "cx", "dx",
4198 "si", "di", "bp", "sp" };
4200 /* If we are dealing with a register whose size is less than the size
4201 specified by the "[-]N@" prefix, and it is one of the registers that
4202 we know has an extended variant available, then use the extended
4203 version of the register instead. */
4204 if (register_size (gdbarch, regnum) < p->arg_type->length ()
4205 && reg_assoc.find (regname) != reg_assoc.end ())
4206 return "e" + regname;
4208 /* Otherwise, just use the requested register. */
4209 return regname;
4214 /* gdbarch gnu_triplet_regexp method. Both arches are acceptable as GDB always
4215 also supplies -m64 or -m32 by gdbarch_gcc_target_options. */
4217 static const char *
4218 i386_gnu_triplet_regexp (struct gdbarch *gdbarch)
4220 return "(x86_64|i.86)";
4225 /* Implement the "in_indirect_branch_thunk" gdbarch function. */
4227 static bool
4228 i386_in_indirect_branch_thunk (struct gdbarch *gdbarch, CORE_ADDR pc)
4230 return x86_in_indirect_branch_thunk (pc, i386_register_names,
4231 I386_EAX_REGNUM, I386_EIP_REGNUM);
4234 /* Generic ELF. */
4236 void
4237 i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
4239 static const char *const stap_integer_prefixes[] = { "$", NULL };
4240 static const char *const stap_register_prefixes[] = { "%", NULL };
4241 static const char *const stap_register_indirection_prefixes[] = { "(",
4242 NULL };
4243 static const char *const stap_register_indirection_suffixes[] = { ")",
4244 NULL };
4246 /* We typically use stabs-in-ELF with the SVR4 register numbering. */
4247 set_gdbarch_stab_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);
4249 /* Registering SystemTap handlers. */
4250 set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
4251 set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
4252 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
4253 stap_register_indirection_prefixes);
4254 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
4255 stap_register_indirection_suffixes);
4256 set_gdbarch_stap_is_single_operand (gdbarch,
4257 i386_stap_is_single_operand);
4258 set_gdbarch_stap_parse_special_token (gdbarch,
4259 i386_stap_parse_special_token);
4260 set_gdbarch_stap_adjust_register (gdbarch,
4261 i386_stap_adjust_register);
4263 set_gdbarch_in_indirect_branch_thunk (gdbarch,
4264 i386_in_indirect_branch_thunk);
4267 /* System V Release 4 (SVR4). */
4269 void
4270 i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
4272 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
4274 /* System V Release 4 uses ELF. */
4275 i386_elf_init_abi (info, gdbarch);
4277 /* System V Release 4 has shared libraries. */
4278 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
4280 tdep->sigtramp_p = i386_svr4_sigtramp_p;
4281 tdep->sigcontext_addr = i386_svr4_sigcontext_addr;
4282 tdep->sc_pc_offset = 36 + 14 * 4;
4283 tdep->sc_sp_offset = 36 + 17 * 4;
4285 tdep->jb_pc_offset = 20;
4290 /* i386 register groups. In addition to the normal groups, add "mmx"
4291 and "sse". */
4293 static const reggroup *i386_sse_reggroup;
4294 static const reggroup *i386_mmx_reggroup;
4296 static void
4297 i386_init_reggroups (void)
4299 i386_sse_reggroup = reggroup_new ("sse", USER_REGGROUP);
4300 i386_mmx_reggroup = reggroup_new ("mmx", USER_REGGROUP);
4303 static void
4304 i386_add_reggroups (struct gdbarch *gdbarch)
4306 reggroup_add (gdbarch, i386_sse_reggroup);
4307 reggroup_add (gdbarch, i386_mmx_reggroup);
4311 i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
4312 const struct reggroup *group)
4314 const i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
4315 int fp_regnum_p, mmx_regnum_p, xmm_regnum_p, mxcsr_regnum_p,
4316 ymm_regnum_p, ymmh_regnum_p, ymm_avx512_regnum_p, ymmh_avx512_regnum_p,
4317 zmm_regnum_p, zmmh_regnum_p, xmm_avx512_regnum_p, avx512_p, avx_p,
4318 sse_p, pkru_regnum_p;
4320 /* Don't include pseudo registers, except for MMX, in any register
4321 groups. */
4322 if (i386_byte_regnum_p (gdbarch, regnum))
4323 return 0;
4325 if (i386_word_regnum_p (gdbarch, regnum))
4326 return 0;
4328 if (i386_dword_regnum_p (gdbarch, regnum))
4329 return 0;
4331 mmx_regnum_p = i386_mmx_regnum_p (gdbarch, regnum);
4332 if (group == i386_mmx_reggroup)
4333 return mmx_regnum_p;
4335 pkru_regnum_p = i386_pkru_regnum_p(gdbarch, regnum);
4336 xmm_regnum_p = i386_xmm_regnum_p (gdbarch, regnum);
4337 xmm_avx512_regnum_p = i386_xmm_avx512_regnum_p (gdbarch, regnum);
4338 mxcsr_regnum_p = i386_mxcsr_regnum_p (gdbarch, regnum);
4339 if (group == i386_sse_reggroup)
4340 return xmm_regnum_p || xmm_avx512_regnum_p || mxcsr_regnum_p;
4342 ymm_regnum_p = i386_ymm_regnum_p (gdbarch, regnum);
4343 ymm_avx512_regnum_p = i386_ymm_avx512_regnum_p (gdbarch, regnum);
4344 zmm_regnum_p = i386_zmm_regnum_p (gdbarch, regnum);
4346 avx512_p = ((tdep->xcr0 & X86_XSTATE_AVX_AVX512_MASK)
4347 == X86_XSTATE_AVX_AVX512_MASK);
4348 avx_p = ((tdep->xcr0 & X86_XSTATE_AVX_AVX512_MASK)
4349 == X86_XSTATE_AVX_MASK) && !avx512_p;
4350 sse_p = ((tdep->xcr0 & X86_XSTATE_AVX_AVX512_MASK)
4351 == X86_XSTATE_SSE_MASK) && !avx512_p && ! avx_p;
4353 if (group == vector_reggroup)
4354 return (mmx_regnum_p
4355 || (zmm_regnum_p && avx512_p)
4356 || ((ymm_regnum_p || ymm_avx512_regnum_p) && avx_p)
4357 || ((xmm_regnum_p || xmm_avx512_regnum_p) && sse_p)
4358 || mxcsr_regnum_p);
4360 fp_regnum_p = (i386_fp_regnum_p (gdbarch, regnum)
4361 || i386_fpc_regnum_p (gdbarch, regnum));
4362 if (group == float_reggroup)
4363 return fp_regnum_p;
4365 /* For "info reg all", don't include upper YMM registers nor XMM
4366 registers when AVX is supported. */
4367 ymmh_regnum_p = i386_ymmh_regnum_p (gdbarch, regnum);
4368 ymmh_avx512_regnum_p = i386_ymmh_avx512_regnum_p (gdbarch, regnum);
4369 zmmh_regnum_p = i386_zmmh_regnum_p (gdbarch, regnum);
4370 if (group == all_reggroup
4371 && (((xmm_regnum_p || xmm_avx512_regnum_p) && !sse_p)
4372 || ((ymm_regnum_p || ymm_avx512_regnum_p) && !avx_p)
4373 || ymmh_regnum_p
4374 || ymmh_avx512_regnum_p
4375 || zmmh_regnum_p))
4376 return 0;
4378 if (group == general_reggroup)
4379 return (!fp_regnum_p
4380 && !mmx_regnum_p
4381 && !mxcsr_regnum_p
4382 && !xmm_regnum_p
4383 && !xmm_avx512_regnum_p
4384 && !ymm_regnum_p
4385 && !ymmh_regnum_p
4386 && !ymm_avx512_regnum_p
4387 && !ymmh_avx512_regnum_p
4388 && !zmm_regnum_p
4389 && !zmmh_regnum_p
4390 && !pkru_regnum_p);
4392 return default_register_reggroup_p (gdbarch, regnum, group);
4396 /* Get the ARGIth function argument for the current function. */
4398 static CORE_ADDR
4399 i386_fetch_pointer_argument (const frame_info_ptr &frame, int argi,
4400 struct type *type)
4402 struct gdbarch *gdbarch = get_frame_arch (frame);
4403 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4404 CORE_ADDR sp = get_frame_register_unsigned (frame, I386_ESP_REGNUM);
4405 return read_memory_unsigned_integer (sp + (4 * (argi + 1)), 4, byte_order);
4408 #define PREFIX_REPZ 0x01
4409 #define PREFIX_REPNZ 0x02
4410 #define PREFIX_LOCK 0x04
4411 #define PREFIX_DATA 0x08
4412 #define PREFIX_ADDR 0x10
4414 /* operand size */
4415 enum
4417 OT_BYTE = 0,
4418 OT_WORD,
4419 OT_LONG,
4420 OT_QUAD,
4421 OT_DQUAD,
4424 /* i386 arith/logic operations */
4425 enum
4427 OP_ADDL,
4428 OP_ORL,
4429 OP_ADCL,
4430 OP_SBBL,
4431 OP_ANDL,
4432 OP_SUBL,
4433 OP_XORL,
4434 OP_CMPL,
4437 struct i386_record_s
4439 struct gdbarch *gdbarch;
4440 struct regcache *regcache;
4441 CORE_ADDR orig_addr;
4442 CORE_ADDR addr;
4443 int aflag;
4444 int dflag;
4445 int override;
4446 uint8_t modrm;
4447 uint8_t mod, reg, rm;
4448 int ot;
4449 uint8_t rex_x;
4450 uint8_t rex_b;
4451 int rip_offset;
4452 int popl_esp_hack;
4453 const int *regmap;
4455 /* These are used by VEX and XOP prefixes. */
4456 uint8_t map_select;
4457 uint8_t vvvv;
4458 uint8_t pp;
4459 uint8_t l;
4462 /* Parse the "modrm" part of the memory address irp->addr points at.
4463 Returns -1 if something goes wrong, 0 otherwise. */
4465 static int
4466 i386_record_modrm (struct i386_record_s *irp)
4468 struct gdbarch *gdbarch = irp->gdbarch;
4470 if (record_read_memory (gdbarch, irp->addr, &irp->modrm, 1))
4471 return -1;
4473 irp->addr++;
4474 irp->mod = (irp->modrm >> 6) & 3;
4475 irp->reg = (irp->modrm >> 3) & 7;
4476 irp->rm = irp->modrm & 7;
4478 return 0;
4481 /* Extract the memory address that the current instruction writes to,
4482 and return it in *ADDR. Return -1 if something goes wrong. */
4484 static int
4485 i386_record_lea_modrm_addr (struct i386_record_s *irp, uint64_t *addr)
4487 struct gdbarch *gdbarch = irp->gdbarch;
4488 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
4489 gdb_byte buf[4];
4490 ULONGEST offset64;
4492 *addr = 0;
4493 if (irp->aflag || irp->regmap[X86_RECORD_R8_REGNUM])
4495 /* 32/64 bits */
4496 int havesib = 0;
4497 uint8_t scale = 0;
4498 uint8_t byte;
4499 uint8_t index = 0;
4500 uint8_t base = irp->rm;
4502 if (base == 4)
4504 havesib = 1;
4505 if (record_read_memory (gdbarch, irp->addr, &byte, 1))
4506 return -1;
4507 irp->addr++;
4508 scale = (byte >> 6) & 3;
4509 index = ((byte >> 3) & 7) | irp->rex_x;
4510 base = (byte & 7);
4512 base |= irp->rex_b;
4514 switch (irp->mod)
4516 case 0:
4517 if ((base & 7) == 5)
4519 base = 0xff;
4520 if (record_read_memory (gdbarch, irp->addr, buf, 4))
4521 return -1;
4522 irp->addr += 4;
4523 *addr = extract_signed_integer (buf, 4, byte_order);
4524 if (irp->regmap[X86_RECORD_R8_REGNUM] && !havesib)
4525 *addr += irp->addr + irp->rip_offset;
4527 break;
4528 case 1:
4529 if (record_read_memory (gdbarch, irp->addr, buf, 1))
4530 return -1;
4531 irp->addr++;
4532 *addr = (int8_t) buf[0];
4533 break;
4534 case 2:
4535 if (record_read_memory (gdbarch, irp->addr, buf, 4))
4536 return -1;
4537 *addr = extract_signed_integer (buf, 4, byte_order);
4538 irp->addr += 4;
4539 break;
4542 offset64 = 0;
4543 if (base != 0xff)
4545 if (base == 4 && irp->popl_esp_hack)
4546 *addr += irp->popl_esp_hack;
4547 regcache_raw_read_unsigned (irp->regcache, irp->regmap[base],
4548 &offset64);
4550 if (irp->aflag == 2)
4552 *addr += offset64;
4554 else
4555 *addr = (uint32_t) (offset64 + *addr);
4557 if (havesib && (index != 4 || scale != 0))
4559 regcache_raw_read_unsigned (irp->regcache, irp->regmap[index],
4560 &offset64);
4561 if (irp->aflag == 2)
4562 *addr += offset64 << scale;
4563 else
4564 *addr = (uint32_t) (*addr + (offset64 << scale));
4567 if (!irp->aflag)
4569 /* Since we are in 64-bit mode with ADDR32 prefix, zero-extend
4570 address from 32-bit to 64-bit. */
4571 *addr = (uint32_t) *addr;
4574 else
4576 /* 16 bits */
4577 switch (irp->mod)
4579 case 0:
4580 if (irp->rm == 6)
4582 if (record_read_memory (gdbarch, irp->addr, buf, 2))
4583 return -1;
4584 irp->addr += 2;
4585 *addr = extract_signed_integer (buf, 2, byte_order);
4586 irp->rm = 0;
4587 goto no_rm;
4589 break;
4590 case 1:
4591 if (record_read_memory (gdbarch, irp->addr, buf, 1))
4592 return -1;
4593 irp->addr++;
4594 *addr = (int8_t) buf[0];
4595 break;
4596 case 2:
4597 if (record_read_memory (gdbarch, irp->addr, buf, 2))
4598 return -1;
4599 irp->addr += 2;
4600 *addr = extract_signed_integer (buf, 2, byte_order);
4601 break;
4604 switch (irp->rm)
4606 case 0:
4607 regcache_raw_read_unsigned (irp->regcache,
4608 irp->regmap[X86_RECORD_REBX_REGNUM],
4609 &offset64);
4610 *addr = (uint32_t) (*addr + offset64);
4611 regcache_raw_read_unsigned (irp->regcache,
4612 irp->regmap[X86_RECORD_RESI_REGNUM],
4613 &offset64);
4614 *addr = (uint32_t) (*addr + offset64);
4615 break;
4616 case 1:
4617 regcache_raw_read_unsigned (irp->regcache,
4618 irp->regmap[X86_RECORD_REBX_REGNUM],
4619 &offset64);
4620 *addr = (uint32_t) (*addr + offset64);
4621 regcache_raw_read_unsigned (irp->regcache,
4622 irp->regmap[X86_RECORD_REDI_REGNUM],
4623 &offset64);
4624 *addr = (uint32_t) (*addr + offset64);
4625 break;
4626 case 2:
4627 regcache_raw_read_unsigned (irp->regcache,
4628 irp->regmap[X86_RECORD_REBP_REGNUM],
4629 &offset64);
4630 *addr = (uint32_t) (*addr + offset64);
4631 regcache_raw_read_unsigned (irp->regcache,
4632 irp->regmap[X86_RECORD_RESI_REGNUM],
4633 &offset64);
4634 *addr = (uint32_t) (*addr + offset64);
4635 break;
4636 case 3:
4637 regcache_raw_read_unsigned (irp->regcache,
4638 irp->regmap[X86_RECORD_REBP_REGNUM],
4639 &offset64);
4640 *addr = (uint32_t) (*addr + offset64);
4641 regcache_raw_read_unsigned (irp->regcache,
4642 irp->regmap[X86_RECORD_REDI_REGNUM],
4643 &offset64);
4644 *addr = (uint32_t) (*addr + offset64);
4645 break;
4646 case 4:
4647 regcache_raw_read_unsigned (irp->regcache,
4648 irp->regmap[X86_RECORD_RESI_REGNUM],
4649 &offset64);
4650 *addr = (uint32_t) (*addr + offset64);
4651 break;
4652 case 5:
4653 regcache_raw_read_unsigned (irp->regcache,
4654 irp->regmap[X86_RECORD_REDI_REGNUM],
4655 &offset64);
4656 *addr = (uint32_t) (*addr + offset64);
4657 break;
4658 case 6:
4659 regcache_raw_read_unsigned (irp->regcache,
4660 irp->regmap[X86_RECORD_REBP_REGNUM],
4661 &offset64);
4662 *addr = (uint32_t) (*addr + offset64);
4663 break;
4664 case 7:
4665 regcache_raw_read_unsigned (irp->regcache,
4666 irp->regmap[X86_RECORD_REBX_REGNUM],
4667 &offset64);
4668 *addr = (uint32_t) (*addr + offset64);
4669 break;
4671 *addr &= 0xffff;
4674 no_rm:
4675 return 0;
4678 /* Record the address and contents of the memory that will be changed
4679 by the current instruction. Return -1 if something goes wrong, 0
4680 otherwise. */
4682 static int
4683 i386_record_lea_modrm (struct i386_record_s *irp)
4685 struct gdbarch *gdbarch = irp->gdbarch;
4686 uint64_t addr;
4688 if (irp->override >= 0)
4690 if (record_full_memory_query)
4692 if (yquery (_("\
4693 Process record ignores the memory change of instruction at address %s\n\
4694 because it can't get the value of the segment register.\n\
4695 Do you want to stop the program?"),
4696 paddress (gdbarch, irp->orig_addr)))
4697 return -1;
4700 return 0;
4703 if (i386_record_lea_modrm_addr (irp, &addr))
4704 return -1;
4706 if (record_full_arch_list_add_mem (addr, 1 << irp->ot))
4707 return -1;
4709 return 0;
4712 /* Record the effects of a push operation. Return -1 if something
4713 goes wrong, 0 otherwise. */
4715 static int
4716 i386_record_push (struct i386_record_s *irp, int size)
4718 ULONGEST addr;
4720 if (record_full_arch_list_add_reg (irp->regcache,
4721 irp->regmap[X86_RECORD_RESP_REGNUM]))
4722 return -1;
4723 regcache_raw_read_unsigned (irp->regcache,
4724 irp->regmap[X86_RECORD_RESP_REGNUM],
4725 &addr);
4726 if (record_full_arch_list_add_mem ((CORE_ADDR) addr - size, size))
4727 return -1;
4729 return 0;
4733 /* Defines contents to record. */
4734 #define I386_SAVE_FPU_REGS 0xfffd
4735 #define I386_SAVE_FPU_ENV 0xfffe
4736 #define I386_SAVE_FPU_ENV_REG_STACK 0xffff
4738 /* Record the values of the floating point registers which will be
4739 changed by the current instruction. Returns -1 if something is
4740 wrong, 0 otherwise. */
4742 static int i386_record_floats (struct gdbarch *gdbarch,
4743 struct i386_record_s *ir,
4744 uint32_t iregnum)
4746 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
4747 int i;
4749 /* Oza: Because of floating point insn push/pop of fpu stack is going to
4750 happen. Currently we store st0-st7 registers, but we need not store all
4751 registers all the time, in future we use ftag register and record only
4752 those who are not marked as an empty. */
4754 if (I386_SAVE_FPU_REGS == iregnum)
4756 for (i = I387_ST0_REGNUM (tdep); i <= I387_ST0_REGNUM (tdep) + 7; i++)
4758 if (record_full_arch_list_add_reg (ir->regcache, i))
4759 return -1;
4762 else if (I386_SAVE_FPU_ENV == iregnum)
4764 for (i = I387_FCTRL_REGNUM (tdep); i <= I387_FOP_REGNUM (tdep); i++)
4766 if (record_full_arch_list_add_reg (ir->regcache, i))
4767 return -1;
4770 else if (I386_SAVE_FPU_ENV_REG_STACK == iregnum)
4772 for (i = I387_ST0_REGNUM (tdep); i <= I387_FOP_REGNUM (tdep); i++)
4773 if (record_full_arch_list_add_reg (ir->regcache, i))
4774 return -1;
4776 else if ((iregnum >= I387_ST0_REGNUM (tdep)) &&
4777 (iregnum <= I387_FOP_REGNUM (tdep)))
4779 if (record_full_arch_list_add_reg (ir->regcache,iregnum))
4780 return -1;
4782 else
4784 /* Parameter error. */
4785 return -1;
4787 if(I386_SAVE_FPU_ENV != iregnum)
4789 for (i = I387_FCTRL_REGNUM (tdep); i <= I387_FOP_REGNUM (tdep); i++)
4791 if (record_full_arch_list_add_reg (ir->regcache, i))
4792 return -1;
4795 return 0;
4798 /* i386_process_record helper to deal with instructions that start
4799 with VEX prefix. */
4801 static int
4802 i386_record_vex (struct i386_record_s *ir, uint8_t vex_w, uint8_t vex_r,
4803 int opcode, struct gdbarch *gdbarch)
4805 /* We need this to find YMM (and once AVX-512 is supported, ZMM) registers.
4806 We should always save the largest available register, since an
4807 instruction that handles a smaller reg may zero out the higher bits,
4808 so we must have them saved. */
4809 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
4811 /* Since we are reading pseudo registers, we need to tell GDB that it is
4812 safe to do so, by saying we aren't _really_ running the inferior right
4813 now. */
4814 SCOPE_EXIT { inferior_thread ()->set_executing (true); };
4815 inferior_thread () -> set_executing (false);
4817 switch (opcode)
4819 case 0x10: /* VMOVS[S|D] XMM, mem. */
4820 /* VMOVUP[S|D] XMM, mem. */
4821 case 0x28: /* VMOVAP[S|D] XMM, mem. */
4822 /* Moving from memory region or XMM registers into an XMM register. */
4823 i386_record_modrm (ir);
4824 record_full_arch_list_add_reg (ir->regcache,
4825 ir->regmap[X86_RECORD_XMM0_REGNUM]
4826 + ir->reg + vex_r * 8);
4827 break;
4828 case 0x11: /* VMOVS[S|D] mem, XMM. */
4829 /* VMOVUP[S|D] mem, XMM. */
4830 case 0x29: /* VMOVAP[S|D] mem, XMM. */
4831 /* Moving from memory region into an XMM register. */
4832 /* This can also be used for XMM -> XMM in some scenarios. */
4833 i386_record_modrm (ir);
4834 if (ir->mod == 3)
4836 /* In this case the destination register is encoded differently
4837 to any other AVX instruction I've seen so far. In this one,
4838 VEX.B is the most important bit of the destination. */
4839 record_full_arch_list_add_reg (ir->regcache,
4840 ir->regmap[X86_RECORD_XMM0_REGNUM]
4841 + ir->rm + ir->rex_b * 8);
4843 else
4845 /* Opcode 0x29 is trivial, the size of memory written is defined by
4846 VEX.L. Opcode 0x11 can refer to vmovs[s|d] or vmovup[s|d]; they
4847 are differentiated by the most significant bit of VEX.pp, and the
4848 latter works exactly like 0x29, but the former encodes the size
4849 on VEX.pp itself. */
4850 if (opcode == 0x11 && (ir->pp & 2) != 0)
4851 ir->ot = ir->pp;
4852 else
4853 ir->ot = 4 + ir->l;
4854 i386_record_lea_modrm (ir);
4856 break;
4857 case 0x14: /* VUNPCKL[PS|PD]. */
4858 case 0x15: /* VUNPCKH [PS|PD]. */
4859 i386_record_modrm (ir);
4860 record_full_arch_list_add_reg (ir->regcache,
4861 tdep->ymm0_regnum + ir->reg + vex_r * 8);
4862 break;
4863 case 0x6e: /* VMOVD XMM, reg/mem */
4864 /* This is moving from a regular register or memory region into an
4865 XMM register. */
4866 i386_record_modrm (ir);
4867 /* ModR/M only has the 3 least significant bits of the destination
4868 register, the last one is indicated by VEX.R (stored inverted). */
4869 record_full_arch_list_add_reg (ir->regcache,
4870 tdep->ymm0_regnum
4871 + ir->reg + vex_r * 8);
4872 break;
4873 case 0x7e: /* VMOV(D/Q) */
4874 i386_record_modrm (ir);
4875 /* Both the intel and AMD manual are wrong about this. According to
4876 it, the only difference between vmovq and vmovd should be the rex_w
4877 bit, but in empirical testing, it seems that they share this opcode,
4878 and the way to differentiate it here is looking at VEX.PP. */
4879 if (ir->pp == 2)
4881 /* This is vmovq moving from a regular register or memory
4882 into an XMM register. As above, VEX.R is the final bit for
4883 destination register. */
4884 record_full_arch_list_add_reg (ir->regcache,
4885 tdep->ymm0_regnum
4886 + ir->reg + vex_r * 8);
4888 else if (ir->pp == 1)
4890 /* This is the vmovd version that stores into a regular register
4891 or memory region. */
4892 /* If ModRM.mod is 11 we are saving into a register. */
4893 if (ir->mod == 3)
4894 record_full_arch_list_add_reg (ir->regcache, ir->regmap[ir->rm]);
4895 else
4897 /* Calculate the size of memory that will be modified
4898 and store it in the form of 1 << ir->ot, since that
4899 is how the function uses it. In theory, VEX.W is supposed
4900 to indicate the size of the memory. In practice, I only
4901 ever seen it set to 0, and for 16 bytes, 0xD6 opcode
4902 is used. */
4903 if (vex_w)
4904 ir->ot = 4;
4905 else
4906 ir->ot = 3;
4908 i386_record_lea_modrm (ir);
4911 else
4913 gdb_printf ("Unrecognized VEX.PP value %d at address %s.",
4914 ir->pp, paddress(gdbarch, ir->orig_addr));
4915 return -1;
4917 break;
4918 case 0xd6: /* VMOVQ reg/mem XMM */
4919 i386_record_modrm (ir);
4920 /* This is the vmovq version that stores into a regular register
4921 or memory region. */
4922 /* If ModRM.mod is 11 we are saving into a register. */
4923 if (ir->mod == 3)
4924 record_full_arch_list_add_reg (ir->regcache, ir->regmap[ir->rm]);
4925 else
4927 /* We know that this operation is always 64 bits. */
4928 ir->ot = 4;
4929 i386_record_lea_modrm (ir);
4931 break;
4933 case 0x6f: /* VMOVDQ (U|A) */
4934 case 0x7f: /* VMOVDQ (U|A) */
4935 /* vmovdq instructions have information about source/destination
4936 spread over many places, so this code ended up messier than
4937 I'd like. */
4938 /* The VEX.pp bits identify if the move is aligned or not, but this
4939 doesn't influence the recording so we can ignore it. */
4940 i386_record_modrm (ir);
4941 /* The first bit of modrm identifies if both operands of the instruction
4942 are registers (bit = 1) or if one of the operands is memory. */
4943 if (ir->mod & 2)
4945 if (opcode == 0x6f)
4947 /* vex_r will identify the high bit of the destination
4948 register. Source is identified by ir->rex_b, but that
4949 doesn't matter for recording. */
4950 record_full_arch_list_add_reg (ir->regcache,
4951 tdep->ymm0_regnum + 8*vex_r + ir->reg);
4953 else
4955 /* The origin operand is >7 and destination operand is <= 7.
4956 This is special cased because in this one vex_r is used to
4957 identify the high bit of the SOURCE operand, not destination
4958 which would mess the previous expression. */
4959 record_full_arch_list_add_reg (ir->regcache,
4960 tdep->ymm0_regnum + ir->rm);
4963 else
4965 /* This is the easy branch. We just need to check the opcode
4966 to see if the source or destination is memory. */
4967 if (opcode == 0x6f)
4969 record_full_arch_list_add_reg (ir->regcache,
4970 tdep->ymm0_regnum
4971 + ir->reg + vex_r * 8);
4973 else
4975 /* We're writing 256 bits, so 1<<8. */
4976 ir->ot = 8;
4977 i386_record_lea_modrm (ir);
4980 break;
4982 case 0x60: /* VPUNPCKLBW */
4983 case 0x61: /* VPUNPCKLWD */
4984 case 0x62: /* VPUNPCKLDQ */
4985 case 0x6c: /* VPUNPCKLQDQ */
4986 case 0x68: /* VPUNPCKHBW */
4987 case 0x69: /* VPUNPCKHWD */
4988 case 0x6a: /* VPUNPCKHDQ */
4989 case 0x6d: /* VPUNPCKHQDQ */
4991 i386_record_modrm (ir);
4992 int reg_offset = ir->reg + vex_r * 8;
4993 record_full_arch_list_add_reg (ir->regcache,
4994 tdep->ymm0_regnum + reg_offset);
4996 break;
4998 case 0x74: /* VPCMPEQB */
4999 case 0x75: /* VPCMPEQB */
5000 case 0x76: /* VPCMPEQB */
5002 i386_record_modrm (ir);
5003 int reg_offset = ir->reg + vex_r * 8;
5004 record_full_arch_list_add_reg (ir->regcache,
5005 tdep->ymm0_regnum + reg_offset);
5007 break;
5009 case 0x78: /* VPBROADCASTB */
5010 case 0x79: /* VPBROADCASTW */
5011 case 0x58: /* VPBROADCASTD and VADD[P|S][S|D] */
5012 case 0x59: /* VPBROADCASTQ and VMUL[P|S][S|D] */
5013 case 0x5c: /* VSUB[P|S][S|D] */
5014 case 0x5d: /* VMIN[P|S][S|D] */
5015 case 0x5e: /* VDIV[P|S][S|D] */
5016 case 0x5f: /* VMAX[P|S][S|D] */
5018 /* vpbroadcast and arithmethic operations are differentiated
5019 by map_select, but it doesn't change the recording mechanics. */
5020 i386_record_modrm (ir);
5021 int reg_offset = ir->reg + vex_r * 8;
5022 gdb_assert (tdep->num_ymm_regs > reg_offset);
5023 record_full_arch_list_add_reg (ir->regcache,
5024 tdep->ymm0_regnum + reg_offset);
5026 break;
5028 case 0x77:/* VZEROUPPER */
5030 int num_regs = tdep->num_ymm_regs;
5031 /* This instruction only works on ymm0..15, even if 16..31 are
5032 available. */
5033 if (num_regs > 16)
5034 num_regs = 16;
5035 for (int i = 0; i < num_regs; i++)
5037 /* We only need to record ymm_h, because the low bits
5038 are not touched. */
5039 record_full_arch_list_add_reg (ir->regcache,
5040 tdep->ymm0h_regnum + i);
5042 break;
5045 case 0xd7: /* VPMOVMSKB */
5047 i386_record_modrm (ir);
5048 record_full_arch_list_add_reg (ir->regcache,
5049 ir->regmap[X86_RECORD_REAX_REGNUM
5050 + ir->reg + 8 * vex_r]);
5052 break;
5054 case 0xef: /* VPXOR */
5055 case 0xeb: /* VPOR */
5057 i386_record_modrm (ir);
5058 int reg_offset = ir->reg + vex_r * 8;
5059 record_full_arch_list_add_reg (ir->regcache,
5060 tdep->ymm0_regnum + reg_offset);
5061 break;
5064 default:
5065 gdb_printf (gdb_stderr,
5066 _("Process record does not support VEX instruction 0x%02x "
5067 "at address %s.\n"),
5068 (unsigned int) (opcode),
5069 paddress (gdbarch, ir->orig_addr));
5070 return -1;
5073 record_full_arch_list_add_reg (ir->regcache, ir->regmap[X86_RECORD_REIP_REGNUM]);
5074 if (record_full_arch_list_add_end ())
5075 return -1;
5077 return 0;
5080 /* Parse the current instruction, and record the values of the
5081 registers and memory that will be changed by the current
5082 instruction. Returns -1 if something goes wrong, 0 otherwise. */
5084 #define I386_RECORD_FULL_ARCH_LIST_ADD_REG(regnum) \
5085 record_full_arch_list_add_reg (ir.regcache, ir.regmap[(regnum)])
5088 i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
5089 CORE_ADDR input_addr)
5091 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
5092 int prefixes = 0;
5093 int regnum = 0;
5094 uint32_t opcode;
5095 uint8_t opcode8;
5096 ULONGEST addr;
5097 gdb_byte buf[I386_MAX_REGISTER_SIZE];
5098 struct i386_record_s ir;
5099 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
5100 uint8_t rex_w = -1;
5101 uint8_t rex_r = 0;
5102 bool vex_prefix = false;
5104 memset (&ir, 0, sizeof (struct i386_record_s));
5105 ir.regcache = regcache;
5106 ir.addr = input_addr;
5107 ir.orig_addr = input_addr;
5108 ir.aflag = 1;
5109 ir.dflag = 1;
5110 ir.override = -1;
5111 ir.popl_esp_hack = 0;
5112 ir.regmap = tdep->record_regmap;
5113 ir.gdbarch = gdbarch;
5115 if (record_debug > 1)
5116 gdb_printf (gdb_stdlog, "Process record: i386_process_record "
5117 "addr = %s\n",
5118 paddress (gdbarch, ir.addr));
5120 /* prefixes */
5121 while (1)
5123 if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
5124 return -1;
5125 ir.addr++;
5126 switch (opcode8) /* Instruction prefixes */
5128 case REPE_PREFIX_OPCODE:
5129 prefixes |= PREFIX_REPZ;
5130 break;
5131 case REPNE_PREFIX_OPCODE:
5132 prefixes |= PREFIX_REPNZ;
5133 break;
5134 case LOCK_PREFIX_OPCODE:
5135 prefixes |= PREFIX_LOCK;
5136 break;
5137 case CS_PREFIX_OPCODE:
5138 ir.override = X86_RECORD_CS_REGNUM;
5139 break;
5140 case SS_PREFIX_OPCODE:
5141 ir.override = X86_RECORD_SS_REGNUM;
5142 break;
5143 case DS_PREFIX_OPCODE:
5144 ir.override = X86_RECORD_DS_REGNUM;
5145 break;
5146 case ES_PREFIX_OPCODE:
5147 ir.override = X86_RECORD_ES_REGNUM;
5148 break;
5149 case FS_PREFIX_OPCODE:
5150 ir.override = X86_RECORD_FS_REGNUM;
5151 break;
5152 case GS_PREFIX_OPCODE:
5153 ir.override = X86_RECORD_GS_REGNUM;
5154 break;
5155 case DATA_PREFIX_OPCODE:
5156 prefixes |= PREFIX_DATA;
5157 break;
5158 case ADDR_PREFIX_OPCODE:
5159 prefixes |= PREFIX_ADDR;
5160 break;
5161 case 0x40: /* i386 inc %eax */
5162 case 0x41: /* i386 inc %ecx */
5163 case 0x42: /* i386 inc %edx */
5164 case 0x43: /* i386 inc %ebx */
5165 case 0x44: /* i386 inc %esp */
5166 case 0x45: /* i386 inc %ebp */
5167 case 0x46: /* i386 inc %esi */
5168 case 0x47: /* i386 inc %edi */
5169 case 0x48: /* i386 dec %eax */
5170 case 0x49: /* i386 dec %ecx */
5171 case 0x4a: /* i386 dec %edx */
5172 case 0x4b: /* i386 dec %ebx */
5173 case 0x4c: /* i386 dec %esp */
5174 case 0x4d: /* i386 dec %ebp */
5175 case 0x4e: /* i386 dec %esi */
5176 case 0x4f: /* i386 dec %edi */
5177 if (ir.regmap[X86_RECORD_R8_REGNUM]) /* 64 bit target */
5179 /* REX */
5180 rex_w = (opcode8 >> 3) & 1;
5181 rex_r = (opcode8 & 0x4) << 1;
5182 ir.rex_x = (opcode8 & 0x2) << 2;
5183 ir.rex_b = (opcode8 & 0x1) << 3;
5185 else /* 32 bit target */
5186 goto out_prefixes;
5187 break;
5188 case 0xc4: /* 3-byte VEX prefixes (for AVX/AVX2 instructions). */
5190 /* The first byte just identifies the VEX prefix. Data is stored
5191 on the following 2 bytes. */
5192 uint8_t byte;
5193 if (record_read_memory (gdbarch, ir.addr, &byte, 1))
5194 return -1;
5195 ir.addr++;
5197 rex_r = !((byte >> 7) & 0x1);
5198 ir.rex_x = !((byte >> 6) & 0x1);
5199 ir.rex_b = !((byte >> 5) & 0x1);
5200 ir.map_select = byte & 0x1f;
5201 /* Collect the last byte of the prefix. */
5202 if (record_read_memory (gdbarch, ir.addr, &byte, 1))
5203 return -1;
5204 ir.addr++;
5205 rex_w = (byte >> 7) & 0x1;
5206 ir.vvvv = (~(byte >> 3) & 0xf);
5207 ir.l = (byte >> 2) & 0x1;
5208 ir.pp = byte & 0x3;
5209 vex_prefix = true;
5211 break;
5213 case 0xc5: /* 2-byte VEX prefix for AVX/AVX2 instructions. */
5215 /* The first byte just identifies the VEX prefix. Data is stored
5216 on the following 2 bytes. */
5217 uint8_t byte;
5218 if (record_read_memory (gdbarch, ir.addr, &byte, 1))
5219 return -1;
5220 ir.addr++;
5222 /* On the 2-byte versions, these are pre-defined. */
5223 ir.rex_x = 0;
5224 ir.rex_b = 0;
5225 rex_w = 0;
5226 ir.map_select = 1;
5228 rex_r = !((byte >> 7) & 0x1);
5229 ir.vvvv = (~(byte >> 3) & 0xf);
5230 ir.l = (byte >> 2) & 0x1;
5231 ir.pp = byte & 0x3;
5232 vex_prefix = true;
5233 break;
5235 default:
5236 goto out_prefixes;
5237 break;
5240 out_prefixes:
5241 if (ir.regmap[X86_RECORD_R8_REGNUM] && rex_w == 1)
5243 ir.dflag = 2;
5245 else
5247 if (prefixes & PREFIX_DATA)
5248 ir.dflag ^= 1;
5250 if (prefixes & PREFIX_ADDR)
5251 ir.aflag ^= 1;
5252 else if (ir.regmap[X86_RECORD_R8_REGNUM])
5253 ir.aflag = 2;
5255 /* Now check op code. */
5256 opcode = (uint32_t) opcode8;
5257 if (vex_prefix)
5259 /* If we found the VEX prefix, i386 will either record or warn that
5260 the instruction isn't supported, so we can return the VEX result. */
5261 return i386_record_vex (&ir, rex_w, rex_r, opcode, gdbarch);
5263 reswitch:
5264 switch (opcode)
5266 case 0x0f:
5267 if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
5268 return -1;
5269 ir.addr++;
5270 opcode = (uint32_t) opcode8 | 0x0f00;
5271 goto reswitch;
5272 break;
5274 case 0x00: /* arith & logic */
5275 case 0x01:
5276 case 0x02:
5277 case 0x03:
5278 case 0x04:
5279 case 0x05:
5280 case 0x08:
5281 case 0x09:
5282 case 0x0a:
5283 case 0x0b:
5284 case 0x0c:
5285 case 0x0d:
5286 case 0x10:
5287 case 0x11:
5288 case 0x12:
5289 case 0x13:
5290 case 0x14:
5291 case 0x15:
5292 case 0x18:
5293 case 0x19:
5294 case 0x1a:
5295 case 0x1b:
5296 case 0x1c:
5297 case 0x1d:
5298 case 0x20:
5299 case 0x21:
5300 case 0x22:
5301 case 0x23:
5302 case 0x24:
5303 case 0x25:
5304 case 0x28:
5305 case 0x29:
5306 case 0x2a:
5307 case 0x2b:
5308 case 0x2c:
5309 case 0x2d:
5310 case 0x30:
5311 case 0x31:
5312 case 0x32:
5313 case 0x33:
5314 case 0x34:
5315 case 0x35:
5316 case 0x38:
5317 case 0x39:
5318 case 0x3a:
5319 case 0x3b:
5320 case 0x3c:
5321 case 0x3d:
5322 if (((opcode >> 3) & 7) != OP_CMPL)
5324 if ((opcode & 1) == 0)
5325 ir.ot = OT_BYTE;
5326 else
5327 ir.ot = ir.dflag + OT_WORD;
5329 switch ((opcode >> 1) & 3)
5331 case 0: /* OP Ev, Gv */
5332 if (i386_record_modrm (&ir))
5333 return -1;
5334 if (ir.mod != 3)
5336 if (i386_record_lea_modrm (&ir))
5337 return -1;
5339 else
5341 ir.rm |= ir.rex_b;
5342 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5343 ir.rm &= 0x3;
5344 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5346 break;
5347 case 1: /* OP Gv, Ev */
5348 if (i386_record_modrm (&ir))
5349 return -1;
5350 ir.reg |= rex_r;
5351 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5352 ir.reg &= 0x3;
5353 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5354 break;
5355 case 2: /* OP A, Iv */
5356 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5357 break;
5360 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5361 break;
5363 case 0x80: /* GRP1 */
5364 case 0x81:
5365 case 0x82:
5366 case 0x83:
5367 if (i386_record_modrm (&ir))
5368 return -1;
5370 if (ir.reg != OP_CMPL)
5372 if ((opcode & 1) == 0)
5373 ir.ot = OT_BYTE;
5374 else
5375 ir.ot = ir.dflag + OT_WORD;
5377 if (ir.mod != 3)
5379 if (opcode == 0x83)
5380 ir.rip_offset = 1;
5381 else
5382 ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
5383 if (i386_record_lea_modrm (&ir))
5384 return -1;
5386 else
5387 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
5389 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5390 break;
5392 case 0x40: /* inc */
5393 case 0x41:
5394 case 0x42:
5395 case 0x43:
5396 case 0x44:
5397 case 0x45:
5398 case 0x46:
5399 case 0x47:
5401 case 0x48: /* dec */
5402 case 0x49:
5403 case 0x4a:
5404 case 0x4b:
5405 case 0x4c:
5406 case 0x4d:
5407 case 0x4e:
5408 case 0x4f:
5410 I386_RECORD_FULL_ARCH_LIST_ADD_REG (opcode & 7);
5411 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5412 break;
5414 case 0xf6: /* GRP3 */
5415 case 0xf7:
5416 if ((opcode & 1) == 0)
5417 ir.ot = OT_BYTE;
5418 else
5419 ir.ot = ir.dflag + OT_WORD;
5420 if (i386_record_modrm (&ir))
5421 return -1;
5423 if (ir.mod != 3 && ir.reg == 0)
5424 ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
5426 switch (ir.reg)
5428 case 0: /* test */
5429 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5430 break;
5431 case 2: /* not */
5432 case 3: /* neg */
5433 if (ir.mod != 3)
5435 if (i386_record_lea_modrm (&ir))
5436 return -1;
5438 else
5440 ir.rm |= ir.rex_b;
5441 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5442 ir.rm &= 0x3;
5443 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5445 if (ir.reg == 3) /* neg */
5446 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5447 break;
5448 case 4: /* mul */
5449 case 5: /* imul */
5450 case 6: /* div */
5451 case 7: /* idiv */
5452 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5453 if (ir.ot != OT_BYTE)
5454 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
5455 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5456 break;
5457 default:
5458 ir.addr -= 2;
5459 opcode = opcode << 8 | ir.modrm;
5460 goto no_support;
5461 break;
5463 break;
5465 case 0xfe: /* GRP4 */
5466 case 0xff: /* GRP5 */
5467 if (i386_record_modrm (&ir))
5468 return -1;
5469 if (ir.reg >= 2 && opcode == 0xfe)
5471 ir.addr -= 2;
5472 opcode = opcode << 8 | ir.modrm;
5473 goto no_support;
5475 switch (ir.reg)
5477 case 0: /* inc */
5478 case 1: /* dec */
5479 if ((opcode & 1) == 0)
5480 ir.ot = OT_BYTE;
5481 else
5482 ir.ot = ir.dflag + OT_WORD;
5483 if (ir.mod != 3)
5485 if (i386_record_lea_modrm (&ir))
5486 return -1;
5488 else
5490 ir.rm |= ir.rex_b;
5491 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5492 ir.rm &= 0x3;
5493 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5495 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5496 break;
5497 case 2: /* call */
5498 if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
5499 ir.dflag = 2;
5500 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5501 return -1;
5502 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5503 break;
5504 case 3: /* lcall */
5505 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM);
5506 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5507 return -1;
5508 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5509 break;
5510 case 4: /* jmp */
5511 case 5: /* ljmp */
5512 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5513 break;
5514 case 6: /* push */
5515 if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
5516 ir.dflag = 2;
5517 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5518 return -1;
5519 break;
5520 default:
5521 ir.addr -= 2;
5522 opcode = opcode << 8 | ir.modrm;
5523 goto no_support;
5524 break;
5526 break;
5528 case 0x84: /* test */
5529 case 0x85:
5530 case 0xa8:
5531 case 0xa9:
5532 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5533 break;
5535 case 0x98: /* CWDE/CBW */
5536 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5537 break;
5539 case 0x99: /* CDQ/CWD */
5540 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5541 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
5542 break;
5544 case 0x0faf: /* imul */
5545 case 0x69:
5546 case 0x6b:
5547 ir.ot = ir.dflag + OT_WORD;
5548 if (i386_record_modrm (&ir))
5549 return -1;
5550 if (opcode == 0x69)
5551 ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
5552 else if (opcode == 0x6b)
5553 ir.rip_offset = 1;
5554 ir.reg |= rex_r;
5555 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5556 ir.reg &= 0x3;
5557 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5558 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5559 break;
5561 case 0x0fc0: /* xadd */
5562 case 0x0fc1:
5563 if ((opcode & 1) == 0)
5564 ir.ot = OT_BYTE;
5565 else
5566 ir.ot = ir.dflag + OT_WORD;
5567 if (i386_record_modrm (&ir))
5568 return -1;
5569 ir.reg |= rex_r;
5570 if (ir.mod == 3)
5572 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5573 ir.reg &= 0x3;
5574 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5575 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5576 ir.rm &= 0x3;
5577 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5579 else
5581 if (i386_record_lea_modrm (&ir))
5582 return -1;
5583 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5584 ir.reg &= 0x3;
5585 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5587 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5588 break;
5590 case 0x0fb0: /* cmpxchg */
5591 case 0x0fb1:
5592 if ((opcode & 1) == 0)
5593 ir.ot = OT_BYTE;
5594 else
5595 ir.ot = ir.dflag + OT_WORD;
5596 if (i386_record_modrm (&ir))
5597 return -1;
5598 if (ir.mod == 3)
5600 ir.reg |= rex_r;
5601 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5602 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5603 ir.reg &= 0x3;
5604 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5606 else
5608 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5609 if (i386_record_lea_modrm (&ir))
5610 return -1;
5612 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5613 break;
5615 case 0x0fc7: /* cmpxchg8b / rdrand / rdseed */
5616 if (i386_record_modrm (&ir))
5617 return -1;
5618 if (ir.mod == 3)
5620 /* rdrand and rdseed use the 3 bits of the REG field of ModR/M as
5621 an extended opcode. rdrand has bits 110 (/6) and rdseed
5622 has bits 111 (/7). */
5623 if (ir.reg == 6 || ir.reg == 7)
5625 /* The storage register is described by the 3 R/M bits, but the
5626 REX.B prefix may be used to give access to registers
5627 R8~R15. In this case ir.rex_b + R/M will give us the register
5628 in the range R8~R15.
5630 REX.W may also be used to access 64-bit registers, but we
5631 already record entire registers and not just partial bits
5632 of them. */
5633 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rex_b + ir.rm);
5634 /* These instructions also set conditional bits. */
5635 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5636 break;
5638 else
5640 /* We don't handle this particular instruction yet. */
5641 ir.addr -= 2;
5642 opcode = opcode << 8 | ir.modrm;
5643 goto no_support;
5646 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5647 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
5648 if (i386_record_lea_modrm (&ir))
5649 return -1;
5650 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5651 break;
5653 case 0x50: /* push */
5654 case 0x51:
5655 case 0x52:
5656 case 0x53:
5657 case 0x54:
5658 case 0x55:
5659 case 0x56:
5660 case 0x57:
5661 case 0x68:
5662 case 0x6a:
5663 if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
5664 ir.dflag = 2;
5665 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5666 return -1;
5667 break;
5669 case 0x06: /* push es */
5670 case 0x0e: /* push cs */
5671 case 0x16: /* push ss */
5672 case 0x1e: /* push ds */
5673 if (ir.regmap[X86_RECORD_R8_REGNUM])
5675 ir.addr -= 1;
5676 goto no_support;
5678 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5679 return -1;
5680 break;
5682 case 0x0fa0: /* push fs */
5683 case 0x0fa8: /* push gs */
5684 if (ir.regmap[X86_RECORD_R8_REGNUM])
5686 ir.addr -= 2;
5687 goto no_support;
5689 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5690 return -1;
5691 break;
5693 case 0x60: /* pusha */
5694 if (ir.regmap[X86_RECORD_R8_REGNUM])
5696 ir.addr -= 1;
5697 goto no_support;
5699 if (i386_record_push (&ir, 1 << (ir.dflag + 4)))
5700 return -1;
5701 break;
5703 case 0x58: /* pop */
5704 case 0x59:
5705 case 0x5a:
5706 case 0x5b:
5707 case 0x5c:
5708 case 0x5d:
5709 case 0x5e:
5710 case 0x5f:
5711 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5712 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode & 0x7) | ir.rex_b);
5713 break;
5715 case 0x61: /* popa */
5716 if (ir.regmap[X86_RECORD_R8_REGNUM])
5718 ir.addr -= 1;
5719 goto no_support;
5721 for (regnum = X86_RECORD_REAX_REGNUM;
5722 regnum <= X86_RECORD_REDI_REGNUM;
5723 regnum++)
5724 I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum);
5725 break;
5727 case 0x8f: /* pop */
5728 if (ir.regmap[X86_RECORD_R8_REGNUM])
5729 ir.ot = ir.dflag ? OT_QUAD : OT_WORD;
5730 else
5731 ir.ot = ir.dflag + OT_WORD;
5732 if (i386_record_modrm (&ir))
5733 return -1;
5734 if (ir.mod == 3)
5735 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
5736 else
5738 ir.popl_esp_hack = 1 << ir.ot;
5739 if (i386_record_lea_modrm (&ir))
5740 return -1;
5742 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5743 break;
5745 case 0xc8: /* enter */
5746 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM);
5747 if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
5748 ir.dflag = 2;
5749 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
5750 return -1;
5751 break;
5753 case 0xc9: /* leave */
5754 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5755 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM);
5756 break;
5758 case 0x07: /* pop es */
5759 if (ir.regmap[X86_RECORD_R8_REGNUM])
5761 ir.addr -= 1;
5762 goto no_support;
5764 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5765 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_ES_REGNUM);
5766 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5767 break;
5769 case 0x17: /* pop ss */
5770 if (ir.regmap[X86_RECORD_R8_REGNUM])
5772 ir.addr -= 1;
5773 goto no_support;
5775 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5776 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_SS_REGNUM);
5777 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5778 break;
5780 case 0x1f: /* pop ds */
5781 if (ir.regmap[X86_RECORD_R8_REGNUM])
5783 ir.addr -= 1;
5784 goto no_support;
5786 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5787 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_DS_REGNUM);
5788 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5789 break;
5791 case 0x0fa1: /* pop fs */
5792 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5793 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_FS_REGNUM);
5794 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5795 break;
5797 case 0x0fa9: /* pop gs */
5798 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
5799 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_GS_REGNUM);
5800 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5801 break;
5803 case 0x88: /* mov */
5804 case 0x89:
5805 case 0xc6:
5806 case 0xc7:
5807 if ((opcode & 1) == 0)
5808 ir.ot = OT_BYTE;
5809 else
5810 ir.ot = ir.dflag + OT_WORD;
5812 if (i386_record_modrm (&ir))
5813 return -1;
5815 if (ir.mod != 3)
5817 if (opcode == 0xc6 || opcode == 0xc7)
5818 ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
5819 if (i386_record_lea_modrm (&ir))
5820 return -1;
5822 else
5824 if (opcode == 0xc6 || opcode == 0xc7)
5825 ir.rm |= ir.rex_b;
5826 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5827 ir.rm &= 0x3;
5828 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5830 break;
5832 case 0x8a: /* mov */
5833 case 0x8b:
5834 if ((opcode & 1) == 0)
5835 ir.ot = OT_BYTE;
5836 else
5837 ir.ot = ir.dflag + OT_WORD;
5838 if (i386_record_modrm (&ir))
5839 return -1;
5840 ir.reg |= rex_r;
5841 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5842 ir.reg &= 0x3;
5843 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5844 break;
5846 case 0x8c: /* mov seg */
5847 if (i386_record_modrm (&ir))
5848 return -1;
5849 if (ir.reg > 5)
5851 ir.addr -= 2;
5852 opcode = opcode << 8 | ir.modrm;
5853 goto no_support;
5856 if (ir.mod == 3)
5857 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
5858 else
5860 ir.ot = OT_WORD;
5861 if (i386_record_lea_modrm (&ir))
5862 return -1;
5864 break;
5866 case 0x8e: /* mov seg */
5867 if (i386_record_modrm (&ir))
5868 return -1;
5869 switch (ir.reg)
5871 case 0:
5872 regnum = X86_RECORD_ES_REGNUM;
5873 break;
5874 case 2:
5875 regnum = X86_RECORD_SS_REGNUM;
5876 break;
5877 case 3:
5878 regnum = X86_RECORD_DS_REGNUM;
5879 break;
5880 case 4:
5881 regnum = X86_RECORD_FS_REGNUM;
5882 break;
5883 case 5:
5884 regnum = X86_RECORD_GS_REGNUM;
5885 break;
5886 default:
5887 ir.addr -= 2;
5888 opcode = opcode << 8 | ir.modrm;
5889 goto no_support;
5890 break;
5892 I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum);
5893 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
5894 break;
5896 case 0x0fb6: /* movzbS */
5897 case 0x0fb7: /* movzwS */
5898 case 0x0fbe: /* movsbS */
5899 case 0x0fbf: /* movswS */
5900 if (i386_record_modrm (&ir))
5901 return -1;
5902 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
5903 break;
5905 case 0x8d: /* lea */
5906 if (i386_record_modrm (&ir))
5907 return -1;
5908 if (ir.mod == 3)
5910 ir.addr -= 2;
5911 opcode = opcode << 8 | ir.modrm;
5912 goto no_support;
5914 ir.ot = ir.dflag;
5915 ir.reg |= rex_r;
5916 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
5917 ir.reg &= 0x3;
5918 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
5919 break;
5921 case 0xa0: /* mov EAX */
5922 case 0xa1:
5924 case 0xd7: /* xlat */
5925 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
5926 break;
5928 case 0xa2: /* mov EAX */
5929 case 0xa3:
5930 if (ir.override >= 0)
5932 if (record_full_memory_query)
5934 if (yquery (_("\
5935 Process record ignores the memory change of instruction at address %s\n\
5936 because it can't get the value of the segment register.\n\
5937 Do you want to stop the program?"),
5938 paddress (gdbarch, ir.orig_addr)))
5939 return -1;
5942 else
5944 if ((opcode & 1) == 0)
5945 ir.ot = OT_BYTE;
5946 else
5947 ir.ot = ir.dflag + OT_WORD;
5948 if (ir.aflag == 2)
5950 if (record_read_memory (gdbarch, ir.addr, buf, 8))
5951 return -1;
5952 ir.addr += 8;
5953 addr = extract_unsigned_integer (buf, 8, byte_order);
5955 else if (ir.aflag)
5957 if (record_read_memory (gdbarch, ir.addr, buf, 4))
5958 return -1;
5959 ir.addr += 4;
5960 addr = extract_unsigned_integer (buf, 4, byte_order);
5962 else
5964 if (record_read_memory (gdbarch, ir.addr, buf, 2))
5965 return -1;
5966 ir.addr += 2;
5967 addr = extract_unsigned_integer (buf, 2, byte_order);
5969 if (record_full_arch_list_add_mem (addr, 1 << ir.ot))
5970 return -1;
5972 break;
5974 case 0xb0: /* mov R, Ib */
5975 case 0xb1:
5976 case 0xb2:
5977 case 0xb3:
5978 case 0xb4:
5979 case 0xb5:
5980 case 0xb6:
5981 case 0xb7:
5982 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((ir.regmap[X86_RECORD_R8_REGNUM])
5983 ? ((opcode & 0x7) | ir.rex_b)
5984 : ((opcode & 0x7) & 0x3));
5985 break;
5987 case 0xb8: /* mov R, Iv */
5988 case 0xb9:
5989 case 0xba:
5990 case 0xbb:
5991 case 0xbc:
5992 case 0xbd:
5993 case 0xbe:
5994 case 0xbf:
5995 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode & 0x7) | ir.rex_b);
5996 break;
5998 case 0x91: /* xchg R, EAX */
5999 case 0x92:
6000 case 0x93:
6001 case 0x94:
6002 case 0x95:
6003 case 0x96:
6004 case 0x97:
6005 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
6006 I386_RECORD_FULL_ARCH_LIST_ADD_REG (opcode & 0x7);
6007 break;
6009 case 0x86: /* xchg Ev, Gv */
6010 case 0x87:
6011 if ((opcode & 1) == 0)
6012 ir.ot = OT_BYTE;
6013 else
6014 ir.ot = ir.dflag + OT_WORD;
6015 if (i386_record_modrm (&ir))
6016 return -1;
6017 if (ir.mod == 3)
6019 ir.rm |= ir.rex_b;
6020 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
6021 ir.rm &= 0x3;
6022 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
6024 else
6026 if (i386_record_lea_modrm (&ir))
6027 return -1;
6029 ir.reg |= rex_r;
6030 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
6031 ir.reg &= 0x3;
6032 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
6033 break;
6035 case 0xc4: /* les Gv */
6036 case 0xc5: /* lds Gv */
6037 if (ir.regmap[X86_RECORD_R8_REGNUM])
6039 ir.addr -= 1;
6040 goto no_support;
6042 [[fallthrough]];
6043 case 0x0fb2: /* lss Gv */
6044 case 0x0fb4: /* lfs Gv */
6045 case 0x0fb5: /* lgs Gv */
6046 if (i386_record_modrm (&ir))
6047 return -1;
6048 if (ir.mod == 3)
6050 if (opcode > 0xff)
6051 ir.addr -= 3;
6052 else
6053 ir.addr -= 2;
6054 opcode = opcode << 8 | ir.modrm;
6055 goto no_support;
6057 switch (opcode)
6059 case 0xc4: /* les Gv */
6060 regnum = X86_RECORD_ES_REGNUM;
6061 break;
6062 case 0xc5: /* lds Gv */
6063 regnum = X86_RECORD_DS_REGNUM;
6064 break;
6065 case 0x0fb2: /* lss Gv */
6066 regnum = X86_RECORD_SS_REGNUM;
6067 break;
6068 case 0x0fb4: /* lfs Gv */
6069 regnum = X86_RECORD_FS_REGNUM;
6070 break;
6071 case 0x0fb5: /* lgs Gv */
6072 regnum = X86_RECORD_GS_REGNUM;
6073 break;
6075 I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum);
6076 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
6077 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6078 break;
6080 case 0xc0: /* shifts */
6081 case 0xc1:
6082 case 0xd0:
6083 case 0xd1:
6084 case 0xd2:
6085 case 0xd3:
6086 if ((opcode & 1) == 0)
6087 ir.ot = OT_BYTE;
6088 else
6089 ir.ot = ir.dflag + OT_WORD;
6090 if (i386_record_modrm (&ir))
6091 return -1;
6092 if (ir.mod != 3 && (opcode == 0xd2 || opcode == 0xd3))
6094 if (i386_record_lea_modrm (&ir))
6095 return -1;
6097 else
6099 ir.rm |= ir.rex_b;
6100 if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
6101 ir.rm &= 0x3;
6102 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
6104 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6105 break;
6107 case 0x0fa4:
6108 case 0x0fa5:
6109 case 0x0fac:
6110 case 0x0fad:
6111 if (i386_record_modrm (&ir))
6112 return -1;
6113 if (ir.mod == 3)
6115 if (record_full_arch_list_add_reg (ir.regcache, ir.rm))
6116 return -1;
6118 else
6120 if (i386_record_lea_modrm (&ir))
6121 return -1;
6123 break;
6125 case 0xd8: /* Floats. */
6126 case 0xd9:
6127 case 0xda:
6128 case 0xdb:
6129 case 0xdc:
6130 case 0xdd:
6131 case 0xde:
6132 case 0xdf:
6133 if (i386_record_modrm (&ir))
6134 return -1;
6135 ir.reg |= ((opcode & 7) << 3);
6136 if (ir.mod != 3)
6138 /* Memory. */
6139 uint64_t addr64;
6141 if (i386_record_lea_modrm_addr (&ir, &addr64))
6142 return -1;
6143 switch (ir.reg)
6145 case 0x02:
6146 case 0x12:
6147 case 0x22:
6148 case 0x32:
6149 /* For fcom, ficom nothing to do. */
6150 break;
6151 case 0x03:
6152 case 0x13:
6153 case 0x23:
6154 case 0x33:
6155 /* For fcomp, ficomp pop FPU stack, store all. */
6156 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
6157 return -1;
6158 break;
6159 case 0x00:
6160 case 0x01:
6161 case 0x04:
6162 case 0x05:
6163 case 0x06:
6164 case 0x07:
6165 case 0x10:
6166 case 0x11:
6167 case 0x14:
6168 case 0x15:
6169 case 0x16:
6170 case 0x17:
6171 case 0x20:
6172 case 0x21:
6173 case 0x24:
6174 case 0x25:
6175 case 0x26:
6176 case 0x27:
6177 case 0x30:
6178 case 0x31:
6179 case 0x34:
6180 case 0x35:
6181 case 0x36:
6182 case 0x37:
6183 /* For fadd, fmul, fsub, fsubr, fdiv, fdivr, fiadd, fimul,
6184 fisub, fisubr, fidiv, fidivr, modR/M.reg is an extension
6185 of code, always affects st(0) register. */
6186 if (i386_record_floats (gdbarch, &ir, I387_ST0_REGNUM (tdep)))
6187 return -1;
6188 break;
6189 case 0x08:
6190 case 0x0a:
6191 case 0x0b:
6192 case 0x18:
6193 case 0x19:
6194 case 0x1a:
6195 case 0x1b:
6196 case 0x1d:
6197 case 0x28:
6198 case 0x29:
6199 case 0x2a:
6200 case 0x2b:
6201 case 0x38:
6202 case 0x39:
6203 case 0x3a:
6204 case 0x3b:
6205 case 0x3c:
6206 case 0x3d:
6207 switch (ir.reg & 7)
6209 case 0:
6210 /* Handling fld, fild. */
6211 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
6212 return -1;
6213 break;
6214 case 1:
6215 switch (ir.reg >> 4)
6217 case 0:
6218 if (record_full_arch_list_add_mem (addr64, 4))
6219 return -1;
6220 break;
6221 case 2:
6222 if (record_full_arch_list_add_mem (addr64, 8))
6223 return -1;
6224 break;
6225 case 3:
6226 break;
6227 default:
6228 if (record_full_arch_list_add_mem (addr64, 2))
6229 return -1;
6230 break;
6232 break;
6233 default:
6234 switch (ir.reg >> 4)
6236 case 0:
6237 if (record_full_arch_list_add_mem (addr64, 4))
6238 return -1;
6239 if (3 == (ir.reg & 7))
6241 /* For fstp m32fp. */
6242 if (i386_record_floats (gdbarch, &ir,
6243 I386_SAVE_FPU_REGS))
6244 return -1;
6246 break;
6247 case 1:
6248 if (record_full_arch_list_add_mem (addr64, 4))
6249 return -1;
6250 if ((3 == (ir.reg & 7))
6251 || (5 == (ir.reg & 7))
6252 || (7 == (ir.reg & 7)))
6254 /* For fstp insn. */
6255 if (i386_record_floats (gdbarch, &ir,
6256 I386_SAVE_FPU_REGS))
6257 return -1;
6259 break;
6260 case 2:
6261 if (record_full_arch_list_add_mem (addr64, 8))
6262 return -1;
6263 if (3 == (ir.reg & 7))
6265 /* For fstp m64fp. */
6266 if (i386_record_floats (gdbarch, &ir,
6267 I386_SAVE_FPU_REGS))
6268 return -1;
6270 break;
6271 case 3:
6272 if ((3 <= (ir.reg & 7)) && (6 <= (ir.reg & 7)))
6274 /* For fistp, fbld, fild, fbstp. */
6275 if (i386_record_floats (gdbarch, &ir,
6276 I386_SAVE_FPU_REGS))
6277 return -1;
6279 [[fallthrough]];
6280 default:
6281 if (record_full_arch_list_add_mem (addr64, 2))
6282 return -1;
6283 break;
6285 break;
6287 break;
6288 case 0x0c:
6289 /* Insn fldenv. */
6290 if (i386_record_floats (gdbarch, &ir,
6291 I386_SAVE_FPU_ENV_REG_STACK))
6292 return -1;
6293 break;
6294 case 0x0d:
6295 /* Insn fldcw. */
6296 if (i386_record_floats (gdbarch, &ir, I387_FCTRL_REGNUM (tdep)))
6297 return -1;
6298 break;
6299 case 0x2c:
6300 /* Insn frstor. */
6301 if (i386_record_floats (gdbarch, &ir,
6302 I386_SAVE_FPU_ENV_REG_STACK))
6303 return -1;
6304 break;
6305 case 0x0e:
6306 if (ir.dflag)
6308 if (record_full_arch_list_add_mem (addr64, 28))
6309 return -1;
6311 else
6313 if (record_full_arch_list_add_mem (addr64, 14))
6314 return -1;
6316 break;
6317 case 0x0f:
6318 case 0x2f:
6319 if (record_full_arch_list_add_mem (addr64, 2))
6320 return -1;
6321 /* Insn fstp, fbstp. */
6322 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
6323 return -1;
6324 break;
6325 case 0x1f:
6326 case 0x3e:
6327 if (record_full_arch_list_add_mem (addr64, 10))
6328 return -1;
6329 break;
6330 case 0x2e:
6331 if (ir.dflag)
6333 if (record_full_arch_list_add_mem (addr64, 28))
6334 return -1;
6335 addr64 += 28;
6337 else
6339 if (record_full_arch_list_add_mem (addr64, 14))
6340 return -1;
6341 addr64 += 14;
6343 if (record_full_arch_list_add_mem (addr64, 80))
6344 return -1;
6345 /* Insn fsave. */
6346 if (i386_record_floats (gdbarch, &ir,
6347 I386_SAVE_FPU_ENV_REG_STACK))
6348 return -1;
6349 break;
6350 case 0x3f:
6351 if (record_full_arch_list_add_mem (addr64, 8))
6352 return -1;
6353 /* Insn fistp. */
6354 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
6355 return -1;
6356 break;
6357 default:
6358 ir.addr -= 2;
6359 opcode = opcode << 8 | ir.modrm;
6360 goto no_support;
6361 break;
6364 /* Opcode is an extension of modR/M byte. */
6365 else
6367 switch (opcode)
6369 case 0xd8:
6370 if (i386_record_floats (gdbarch, &ir, I387_ST0_REGNUM (tdep)))
6371 return -1;
6372 break;
6373 case 0xd9:
6374 if (0x0c == (ir.modrm >> 4))
6376 if ((ir.modrm & 0x0f) <= 7)
6378 if (i386_record_floats (gdbarch, &ir,
6379 I386_SAVE_FPU_REGS))
6380 return -1;
6382 else
6384 if (i386_record_floats (gdbarch, &ir,
6385 I387_ST0_REGNUM (tdep)))
6386 return -1;
6387 /* If only st(0) is changing, then we have already
6388 recorded. */
6389 if ((ir.modrm & 0x0f) - 0x08)
6391 if (i386_record_floats (gdbarch, &ir,
6392 I387_ST0_REGNUM (tdep) +
6393 ((ir.modrm & 0x0f) - 0x08)))
6394 return -1;
6398 else
6400 switch (ir.modrm)
6402 case 0xe0:
6403 case 0xe1:
6404 case 0xf0:
6405 case 0xf5:
6406 case 0xf8:
6407 case 0xfa:
6408 case 0xfc:
6409 case 0xfe:
6410 case 0xff:
6411 if (i386_record_floats (gdbarch, &ir,
6412 I387_ST0_REGNUM (tdep)))
6413 return -1;
6414 break;
6415 case 0xf1:
6416 case 0xf2:
6417 case 0xf3:
6418 case 0xf4:
6419 case 0xf6:
6420 case 0xf7:
6421 case 0xe8:
6422 case 0xe9:
6423 case 0xea:
6424 case 0xeb:
6425 case 0xec:
6426 case 0xed:
6427 case 0xee:
6428 case 0xf9:
6429 case 0xfb:
6430 if (i386_record_floats (gdbarch, &ir,
6431 I386_SAVE_FPU_REGS))
6432 return -1;
6433 break;
6434 case 0xfd:
6435 if (i386_record_floats (gdbarch, &ir,
6436 I387_ST0_REGNUM (tdep)))
6437 return -1;
6438 if (i386_record_floats (gdbarch, &ir,
6439 I387_ST0_REGNUM (tdep) + 1))
6440 return -1;
6441 break;
6444 break;
6445 case 0xda:
6446 if (0xe9 == ir.modrm)
6448 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
6449 return -1;
6451 else if ((0x0c == ir.modrm >> 4) || (0x0d == ir.modrm >> 4))
6453 if (i386_record_floats (gdbarch, &ir,
6454 I387_ST0_REGNUM (tdep)))
6455 return -1;
6456 if (((ir.modrm & 0x0f) > 0) && ((ir.modrm & 0x0f) <= 7))
6458 if (i386_record_floats (gdbarch, &ir,
6459 I387_ST0_REGNUM (tdep) +
6460 (ir.modrm & 0x0f)))
6461 return -1;
6463 else if ((ir.modrm & 0x0f) - 0x08)
6465 if (i386_record_floats (gdbarch, &ir,
6466 I387_ST0_REGNUM (tdep) +
6467 ((ir.modrm & 0x0f) - 0x08)))
6468 return -1;
6471 break;
6472 case 0xdb:
6473 if (0xe3 == ir.modrm)
6475 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_ENV))
6476 return -1;
6478 else if ((0x0c == ir.modrm >> 4) || (0x0d == ir.modrm >> 4))
6480 if (i386_record_floats (gdbarch, &ir,
6481 I387_ST0_REGNUM (tdep)))
6482 return -1;
6483 if (((ir.modrm & 0x0f) > 0) && ((ir.modrm & 0x0f) <= 7))
6485 if (i386_record_floats (gdbarch, &ir,
6486 I387_ST0_REGNUM (tdep) +
6487 (ir.modrm & 0x0f)))
6488 return -1;
6490 else if ((ir.modrm & 0x0f) - 0x08)
6492 if (i386_record_floats (gdbarch, &ir,
6493 I387_ST0_REGNUM (tdep) +
6494 ((ir.modrm & 0x0f) - 0x08)))
6495 return -1;
6498 break;
6499 case 0xdc:
6500 if ((0x0c == ir.modrm >> 4)
6501 || (0x0d == ir.modrm >> 4)
6502 || (0x0f == ir.modrm >> 4))
6504 if ((ir.modrm & 0x0f) <= 7)
6506 if (i386_record_floats (gdbarch, &ir,
6507 I387_ST0_REGNUM (tdep) +
6508 (ir.modrm & 0x0f)))
6509 return -1;
6511 else
6513 if (i386_record_floats (gdbarch, &ir,
6514 I387_ST0_REGNUM (tdep) +
6515 ((ir.modrm & 0x0f) - 0x08)))
6516 return -1;
6519 break;
6520 case 0xdd:
6521 if (0x0c == ir.modrm >> 4)
6523 if (i386_record_floats (gdbarch, &ir,
6524 I387_FTAG_REGNUM (tdep)))
6525 return -1;
6527 else if ((0x0d == ir.modrm >> 4) || (0x0e == ir.modrm >> 4))
6529 if ((ir.modrm & 0x0f) <= 7)
6531 if (i386_record_floats (gdbarch, &ir,
6532 I387_ST0_REGNUM (tdep) +
6533 (ir.modrm & 0x0f)))
6534 return -1;
6536 else
6538 if (i386_record_floats (gdbarch, &ir,
6539 I386_SAVE_FPU_REGS))
6540 return -1;
6543 break;
6544 case 0xde:
6545 if ((0x0c == ir.modrm >> 4)
6546 || (0x0e == ir.modrm >> 4)
6547 || (0x0f == ir.modrm >> 4)
6548 || (0xd9 == ir.modrm))
6550 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
6551 return -1;
6553 break;
6554 case 0xdf:
6555 if (0xe0 == ir.modrm)
6557 if (record_full_arch_list_add_reg (ir.regcache,
6558 I386_EAX_REGNUM))
6559 return -1;
6561 else if ((0x0f == ir.modrm >> 4) || (0x0e == ir.modrm >> 4))
6563 if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
6564 return -1;
6566 break;
6569 break;
6570 /* string ops */
6571 case 0xa4: /* movsS */
6572 case 0xa5:
6573 case 0xaa: /* stosS */
6574 case 0xab:
6575 case 0x6c: /* insS */
6576 case 0x6d:
6577 regcache_raw_read_unsigned (ir.regcache,
6578 ir.regmap[X86_RECORD_RECX_REGNUM],
6579 &addr);
6580 if (addr)
6582 ULONGEST es, ds;
6584 if ((opcode & 1) == 0)
6585 ir.ot = OT_BYTE;
6586 else
6587 ir.ot = ir.dflag + OT_WORD;
6588 regcache_raw_read_unsigned (ir.regcache,
6589 ir.regmap[X86_RECORD_REDI_REGNUM],
6590 &addr);
6592 regcache_raw_read_unsigned (ir.regcache,
6593 ir.regmap[X86_RECORD_ES_REGNUM],
6594 &es);
6595 regcache_raw_read_unsigned (ir.regcache,
6596 ir.regmap[X86_RECORD_DS_REGNUM],
6597 &ds);
6598 if (ir.aflag && (es != ds))
6600 /* addr += ((uint32_t) read_register (I386_ES_REGNUM)) << 4; */
6601 if (record_full_memory_query)
6603 if (yquery (_("\
6604 Process record ignores the memory change of instruction at address %s\n\
6605 because it can't get the value of the segment register.\n\
6606 Do you want to stop the program?"),
6607 paddress (gdbarch, ir.orig_addr)))
6608 return -1;
6611 else
6613 if (record_full_arch_list_add_mem (addr, 1 << ir.ot))
6614 return -1;
6617 if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
6618 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
6619 if (opcode == 0xa4 || opcode == 0xa5)
6620 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
6621 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
6622 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6624 break;
6626 case 0xa6: /* cmpsS */
6627 case 0xa7:
6628 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
6629 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
6630 if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
6631 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
6632 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6633 break;
6635 case 0xac: /* lodsS */
6636 case 0xad:
6637 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
6638 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
6639 if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
6640 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
6641 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6642 break;
6644 case 0xae: /* scasS */
6645 case 0xaf:
6646 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
6647 if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
6648 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
6649 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6650 break;
6652 case 0x6e: /* outsS */
6653 case 0x6f:
6654 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
6655 if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
6656 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
6657 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6658 break;
6660 case 0xe4: /* port I/O */
6661 case 0xe5:
6662 case 0xec:
6663 case 0xed:
6664 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6665 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
6666 break;
6668 case 0xe6:
6669 case 0xe7:
6670 case 0xee:
6671 case 0xef:
6672 break;
6674 /* control */
6675 case 0xc2: /* ret im */
6676 case 0xc3: /* ret */
6677 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
6678 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6679 break;
6681 case 0xca: /* lret im */
6682 case 0xcb: /* lret */
6683 case 0xcf: /* iret */
6684 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM);
6685 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
6686 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6687 break;
6689 case 0xe8: /* call im */
6690 if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
6691 ir.dflag = 2;
6692 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
6693 return -1;
6694 break;
6696 case 0x9a: /* lcall im */
6697 if (ir.regmap[X86_RECORD_R8_REGNUM])
6699 ir.addr -= 1;
6700 goto no_support;
6702 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM);
6703 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
6704 return -1;
6705 break;
6707 case 0xe9: /* jmp im */
6708 case 0xea: /* ljmp im */
6709 case 0xeb: /* jmp Jb */
6710 case 0x70: /* jcc Jb */
6711 case 0x71:
6712 case 0x72:
6713 case 0x73:
6714 case 0x74:
6715 case 0x75:
6716 case 0x76:
6717 case 0x77:
6718 case 0x78:
6719 case 0x79:
6720 case 0x7a:
6721 case 0x7b:
6722 case 0x7c:
6723 case 0x7d:
6724 case 0x7e:
6725 case 0x7f:
6726 case 0x0f80: /* jcc Jv */
6727 case 0x0f81:
6728 case 0x0f82:
6729 case 0x0f83:
6730 case 0x0f84:
6731 case 0x0f85:
6732 case 0x0f86:
6733 case 0x0f87:
6734 case 0x0f88:
6735 case 0x0f89:
6736 case 0x0f8a:
6737 case 0x0f8b:
6738 case 0x0f8c:
6739 case 0x0f8d:
6740 case 0x0f8e:
6741 case 0x0f8f:
6742 break;
6744 case 0x0f90: /* setcc Gv */
6745 case 0x0f91:
6746 case 0x0f92:
6747 case 0x0f93:
6748 case 0x0f94:
6749 case 0x0f95:
6750 case 0x0f96:
6751 case 0x0f97:
6752 case 0x0f98:
6753 case 0x0f99:
6754 case 0x0f9a:
6755 case 0x0f9b:
6756 case 0x0f9c:
6757 case 0x0f9d:
6758 case 0x0f9e:
6759 case 0x0f9f:
6760 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6761 ir.ot = OT_BYTE;
6762 if (i386_record_modrm (&ir))
6763 return -1;
6764 if (ir.mod == 3)
6765 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rex_b ? (ir.rm | ir.rex_b)
6766 : (ir.rm & 0x3));
6767 else
6769 if (i386_record_lea_modrm (&ir))
6770 return -1;
6772 break;
6774 case 0x0f40: /* cmov Gv, Ev */
6775 case 0x0f41:
6776 case 0x0f42:
6777 case 0x0f43:
6778 case 0x0f44:
6779 case 0x0f45:
6780 case 0x0f46:
6781 case 0x0f47:
6782 case 0x0f48:
6783 case 0x0f49:
6784 case 0x0f4a:
6785 case 0x0f4b:
6786 case 0x0f4c:
6787 case 0x0f4d:
6788 case 0x0f4e:
6789 case 0x0f4f:
6790 if (i386_record_modrm (&ir))
6791 return -1;
6792 ir.reg |= rex_r;
6793 if (ir.dflag == OT_BYTE)
6794 ir.reg &= 0x3;
6795 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
6796 break;
6798 /* flags */
6799 case 0x9c: /* pushf */
6800 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6801 if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
6802 ir.dflag = 2;
6803 if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
6804 return -1;
6805 break;
6807 case 0x9d: /* popf */
6808 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
6809 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6810 break;
6812 case 0x9e: /* sahf */
6813 if (ir.regmap[X86_RECORD_R8_REGNUM])
6815 ir.addr -= 1;
6816 goto no_support;
6818 [[fallthrough]];
6819 case 0xf5: /* cmc */
6820 case 0xf8: /* clc */
6821 case 0xf9: /* stc */
6822 case 0xfc: /* cld */
6823 case 0xfd: /* std */
6824 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6825 break;
6827 case 0x9f: /* lahf */
6828 if (ir.regmap[X86_RECORD_R8_REGNUM])
6830 ir.addr -= 1;
6831 goto no_support;
6833 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6834 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
6835 break;
6837 /* bit operations */
6838 case 0x0fba: /* bt/bts/btr/btc Gv, im */
6839 ir.ot = ir.dflag + OT_WORD;
6840 if (i386_record_modrm (&ir))
6841 return -1;
6842 if (ir.reg < 4)
6844 ir.addr -= 2;
6845 opcode = opcode << 8 | ir.modrm;
6846 goto no_support;
6848 if (ir.reg != 4)
6850 if (ir.mod == 3)
6851 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
6852 else
6854 if (i386_record_lea_modrm (&ir))
6855 return -1;
6858 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6859 break;
6861 case 0x0fa3: /* bt Gv, Ev */
6862 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6863 break;
6865 case 0x0fab: /* bts */
6866 case 0x0fb3: /* btr */
6867 case 0x0fbb: /* btc */
6868 ir.ot = ir.dflag + OT_WORD;
6869 if (i386_record_modrm (&ir))
6870 return -1;
6871 if (ir.mod == 3)
6872 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
6873 else
6875 uint64_t addr64;
6876 if (i386_record_lea_modrm_addr (&ir, &addr64))
6877 return -1;
6878 regcache_raw_read_unsigned (ir.regcache,
6879 ir.regmap[ir.reg | rex_r],
6880 &addr);
6881 switch (ir.dflag)
6883 case 0:
6884 addr64 += ((int16_t) addr >> 4) << 4;
6885 break;
6886 case 1:
6887 addr64 += ((int32_t) addr >> 5) << 5;
6888 break;
6889 case 2:
6890 addr64 += ((int64_t) addr >> 6) << 6;
6891 break;
6893 if (record_full_arch_list_add_mem (addr64, 1 << ir.ot))
6894 return -1;
6895 if (i386_record_lea_modrm (&ir))
6896 return -1;
6898 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6899 break;
6901 case 0x0fbc: /* bsf */
6902 case 0x0fbd: /* bsr */
6903 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
6904 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6905 break;
6907 /* bcd */
6908 case 0x27: /* daa */
6909 case 0x2f: /* das */
6910 case 0x37: /* aaa */
6911 case 0x3f: /* aas */
6912 case 0xd4: /* aam */
6913 case 0xd5: /* aad */
6914 if (ir.regmap[X86_RECORD_R8_REGNUM])
6916 ir.addr -= 1;
6917 goto no_support;
6919 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
6920 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
6921 break;
6923 /* misc */
6924 case 0x90: /* nop */
6925 if (prefixes & PREFIX_LOCK)
6927 ir.addr -= 1;
6928 goto no_support;
6930 break;
6932 case 0x9b: /* fwait */
6933 if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
6934 return -1;
6935 opcode = (uint32_t) opcode8;
6936 ir.addr++;
6937 goto reswitch;
6938 break;
6940 /* XXX */
6941 case 0xcc: /* int3 */
6942 gdb_printf (gdb_stderr,
6943 _("Process record does not support instruction "
6944 "int3.\n"));
6945 ir.addr -= 1;
6946 goto no_support;
6947 break;
6949 /* XXX */
6950 case 0xcd: /* int */
6952 int ret;
6953 uint8_t interrupt;
6954 if (record_read_memory (gdbarch, ir.addr, &interrupt, 1))
6955 return -1;
6956 ir.addr++;
6957 if (interrupt != 0x80
6958 || tdep->i386_intx80_record == NULL)
6960 gdb_printf (gdb_stderr,
6961 _("Process record does not support "
6962 "instruction int 0x%02x.\n"),
6963 interrupt);
6964 ir.addr -= 2;
6965 goto no_support;
6967 ret = tdep->i386_intx80_record (ir.regcache);
6968 if (ret)
6969 return ret;
6971 break;
6973 /* XXX */
6974 case 0xce: /* into */
6975 gdb_printf (gdb_stderr,
6976 _("Process record does not support "
6977 "instruction into.\n"));
6978 ir.addr -= 1;
6979 goto no_support;
6980 break;
6982 case 0xfa: /* cli */
6983 case 0xfb: /* sti */
6984 break;
6986 case 0x62: /* bound */
6987 gdb_printf (gdb_stderr,
6988 _("Process record does not support "
6989 "instruction bound.\n"));
6990 ir.addr -= 1;
6991 goto no_support;
6992 break;
6994 case 0x0fc8: /* bswap reg */
6995 case 0x0fc9:
6996 case 0x0fca:
6997 case 0x0fcb:
6998 case 0x0fcc:
6999 case 0x0fcd:
7000 case 0x0fce:
7001 case 0x0fcf:
7002 I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode & 7) | ir.rex_b);
7003 break;
7005 case 0xd6: /* salc */
7006 if (ir.regmap[X86_RECORD_R8_REGNUM])
7008 ir.addr -= 1;
7009 goto no_support;
7011 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
7012 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7013 break;
7015 case 0xe0: /* loopnz */
7016 case 0xe1: /* loopz */
7017 case 0xe2: /* loop */
7018 case 0xe3: /* jecxz */
7019 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
7020 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7021 break;
7023 case 0x0f30: /* wrmsr */
7024 gdb_printf (gdb_stderr,
7025 _("Process record does not support "
7026 "instruction wrmsr.\n"));
7027 ir.addr -= 2;
7028 goto no_support;
7029 break;
7031 case 0x0f32: /* rdmsr */
7032 gdb_printf (gdb_stderr,
7033 _("Process record does not support "
7034 "instruction rdmsr.\n"));
7035 ir.addr -= 2;
7036 goto no_support;
7037 break;
7039 case 0x0f01f9: /* rdtscp */
7040 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
7041 [[fallthrough]];
7042 case 0x0f31: /* rdtsc */
7043 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
7044 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
7045 break;
7047 case 0x0f34: /* sysenter */
7049 int ret;
7050 if (ir.regmap[X86_RECORD_R8_REGNUM])
7052 ir.addr -= 2;
7053 goto no_support;
7055 if (tdep->i386_sysenter_record == NULL)
7057 gdb_printf (gdb_stderr,
7058 _("Process record does not support "
7059 "instruction sysenter.\n"));
7060 ir.addr -= 2;
7061 goto no_support;
7063 ret = tdep->i386_sysenter_record (ir.regcache);
7064 if (ret)
7065 return ret;
7067 break;
7069 case 0x0f35: /* sysexit */
7070 gdb_printf (gdb_stderr,
7071 _("Process record does not support "
7072 "instruction sysexit.\n"));
7073 ir.addr -= 2;
7074 goto no_support;
7075 break;
7077 case 0x0f05: /* syscall */
7079 int ret;
7080 if (tdep->i386_syscall_record == NULL)
7082 gdb_printf (gdb_stderr,
7083 _("Process record does not support "
7084 "instruction syscall.\n"));
7085 ir.addr -= 2;
7086 goto no_support;
7088 ret = tdep->i386_syscall_record (ir.regcache);
7089 if (ret)
7090 return ret;
7092 break;
7094 case 0x0f07: /* sysret */
7095 gdb_printf (gdb_stderr,
7096 _("Process record does not support "
7097 "instruction sysret.\n"));
7098 ir.addr -= 2;
7099 goto no_support;
7100 break;
7102 case 0x0fa2: /* cpuid */
7103 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
7104 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
7105 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
7106 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBX_REGNUM);
7107 break;
7109 case 0xf4: /* hlt */
7110 gdb_printf (gdb_stderr,
7111 _("Process record does not support "
7112 "instruction hlt.\n"));
7113 ir.addr -= 1;
7114 goto no_support;
7115 break;
7117 case 0x0f00:
7118 if (i386_record_modrm (&ir))
7119 return -1;
7120 switch (ir.reg)
7122 case 0: /* sldt */
7123 case 1: /* str */
7124 if (ir.mod == 3)
7125 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
7126 else
7128 ir.ot = OT_WORD;
7129 if (i386_record_lea_modrm (&ir))
7130 return -1;
7132 break;
7133 case 2: /* lldt */
7134 case 3: /* ltr */
7135 break;
7136 case 4: /* verr */
7137 case 5: /* verw */
7138 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7139 break;
7140 default:
7141 ir.addr -= 3;
7142 opcode = opcode << 8 | ir.modrm;
7143 goto no_support;
7144 break;
7146 break;
7148 case 0x0f01:
7149 if (i386_record_modrm (&ir))
7150 return -1;
7151 if (ir.modrm == 0xf9)
7153 opcode = (opcode << 8) | 0xf9;
7154 goto reswitch;
7156 switch (ir.reg)
7158 case 0: /* sgdt */
7160 uint64_t addr64;
7162 if (ir.mod == 3)
7164 ir.addr -= 3;
7165 opcode = opcode << 8 | ir.modrm;
7166 goto no_support;
7168 if (ir.override >= 0)
7170 if (record_full_memory_query)
7172 if (yquery (_("\
7173 Process record ignores the memory change of instruction at address %s\n\
7174 because it can't get the value of the segment register.\n\
7175 Do you want to stop the program?"),
7176 paddress (gdbarch, ir.orig_addr)))
7177 return -1;
7180 else
7182 if (i386_record_lea_modrm_addr (&ir, &addr64))
7183 return -1;
7184 if (record_full_arch_list_add_mem (addr64, 2))
7185 return -1;
7186 addr64 += 2;
7187 if (ir.regmap[X86_RECORD_R8_REGNUM])
7189 if (record_full_arch_list_add_mem (addr64, 8))
7190 return -1;
7192 else
7194 if (record_full_arch_list_add_mem (addr64, 4))
7195 return -1;
7199 break;
7200 case 1:
7201 if (ir.mod == 3)
7203 switch (ir.rm)
7205 case 0: /* monitor */
7206 break;
7207 case 1: /* mwait */
7208 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7209 break;
7210 default:
7211 ir.addr -= 3;
7212 opcode = opcode << 8 | ir.modrm;
7213 goto no_support;
7214 break;
7217 else
7219 /* sidt */
7220 if (ir.override >= 0)
7222 if (record_full_memory_query)
7224 if (yquery (_("\
7225 Process record ignores the memory change of instruction at address %s\n\
7226 because it can't get the value of the segment register.\n\
7227 Do you want to stop the program?"),
7228 paddress (gdbarch, ir.orig_addr)))
7229 return -1;
7232 else
7234 uint64_t addr64;
7236 if (i386_record_lea_modrm_addr (&ir, &addr64))
7237 return -1;
7238 if (record_full_arch_list_add_mem (addr64, 2))
7239 return -1;
7240 addr64 += 2;
7241 if (ir.regmap[X86_RECORD_R8_REGNUM])
7243 if (record_full_arch_list_add_mem (addr64, 8))
7244 return -1;
7246 else
7248 if (record_full_arch_list_add_mem (addr64, 4))
7249 return -1;
7253 break;
7254 case 2: /* lgdt */
7255 if (ir.mod == 3)
7257 /* xgetbv */
7258 if (ir.rm == 0)
7260 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
7261 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
7262 break;
7264 /* xsetbv */
7265 else if (ir.rm == 1)
7266 break;
7268 [[fallthrough]];
7269 case 3: /* lidt */
7270 if (ir.mod == 3)
7272 ir.addr -= 3;
7273 opcode = opcode << 8 | ir.modrm;
7274 goto no_support;
7276 break;
7277 case 4: /* smsw */
7278 if (ir.mod == 3)
7280 if (record_full_arch_list_add_reg (ir.regcache, ir.rm | ir.rex_b))
7281 return -1;
7283 else
7285 ir.ot = OT_WORD;
7286 if (i386_record_lea_modrm (&ir))
7287 return -1;
7289 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7290 break;
7291 case 6: /* lmsw */
7292 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7293 break;
7294 case 7: /* invlpg */
7295 if (ir.mod == 3)
7297 if (ir.rm == 0 && ir.regmap[X86_RECORD_R8_REGNUM])
7298 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_GS_REGNUM);
7299 else
7301 ir.addr -= 3;
7302 opcode = opcode << 8 | ir.modrm;
7303 goto no_support;
7306 else
7307 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7308 break;
7309 default:
7310 ir.addr -= 3;
7311 opcode = opcode << 8 | ir.modrm;
7312 goto no_support;
7313 break;
7315 break;
7317 case 0x0f08: /* invd */
7318 case 0x0f09: /* wbinvd */
7319 break;
7321 case 0x63: /* arpl */
7322 if (i386_record_modrm (&ir))
7323 return -1;
7324 if (ir.mod == 3 || ir.regmap[X86_RECORD_R8_REGNUM])
7326 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.regmap[X86_RECORD_R8_REGNUM]
7327 ? (ir.reg | rex_r) : ir.rm);
7329 else
7331 ir.ot = ir.dflag ? OT_LONG : OT_WORD;
7332 if (i386_record_lea_modrm (&ir))
7333 return -1;
7335 if (!ir.regmap[X86_RECORD_R8_REGNUM])
7336 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7337 break;
7339 case 0x0f02: /* lar */
7340 case 0x0f03: /* lsl */
7341 if (i386_record_modrm (&ir))
7342 return -1;
7343 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
7344 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7345 break;
7347 case 0x0f18:
7348 if (i386_record_modrm (&ir))
7349 return -1;
7350 if (ir.mod == 3 && ir.reg == 3)
7352 ir.addr -= 3;
7353 opcode = opcode << 8 | ir.modrm;
7354 goto no_support;
7356 break;
7358 case 0x0f19:
7359 case 0x0f1a:
7360 case 0x0f1b:
7361 case 0x0f1c:
7362 case 0x0f1d:
7363 case 0x0f1e:
7364 case 0x0f1f:
7365 /* nop (multi byte) */
7366 break;
7368 case 0x0f20: /* mov reg, crN */
7369 case 0x0f22: /* mov crN, reg */
7370 if (i386_record_modrm (&ir))
7371 return -1;
7372 if ((ir.modrm & 0xc0) != 0xc0)
7374 ir.addr -= 3;
7375 opcode = opcode << 8 | ir.modrm;
7376 goto no_support;
7378 switch (ir.reg)
7380 case 0:
7381 case 2:
7382 case 3:
7383 case 4:
7384 case 8:
7385 if (opcode & 2)
7386 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7387 else
7388 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
7389 break;
7390 default:
7391 ir.addr -= 3;
7392 opcode = opcode << 8 | ir.modrm;
7393 goto no_support;
7394 break;
7396 break;
7398 case 0x0f21: /* mov reg, drN */
7399 case 0x0f23: /* mov drN, reg */
7400 if (i386_record_modrm (&ir))
7401 return -1;
7402 if ((ir.modrm & 0xc0) != 0xc0 || ir.reg == 4
7403 || ir.reg == 5 || ir.reg >= 8)
7405 ir.addr -= 3;
7406 opcode = opcode << 8 | ir.modrm;
7407 goto no_support;
7409 if (opcode & 2)
7410 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7411 else
7412 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
7413 break;
7415 case 0x0f06: /* clts */
7416 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7417 break;
7419 /* MMX 3DNow! SSE SSE2 SSE3 SSSE3 SSE4 */
7421 case 0x0f0d: /* 3DNow! prefetch */
7422 break;
7424 case 0x0f0e: /* 3DNow! femms */
7425 case 0x0f77: /* emms */
7426 if (i386_fpc_regnum_p (gdbarch, I387_FTAG_REGNUM(tdep)))
7427 goto no_support;
7428 record_full_arch_list_add_reg (ir.regcache, I387_FTAG_REGNUM(tdep));
7429 break;
7431 case 0x0f0f: /* 3DNow! data */
7432 if (i386_record_modrm (&ir))
7433 return -1;
7434 if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
7435 return -1;
7436 ir.addr++;
7437 switch (opcode8)
7439 case 0x0c: /* 3DNow! pi2fw */
7440 case 0x0d: /* 3DNow! pi2fd */
7441 case 0x1c: /* 3DNow! pf2iw */
7442 case 0x1d: /* 3DNow! pf2id */
7443 case 0x8a: /* 3DNow! pfnacc */
7444 case 0x8e: /* 3DNow! pfpnacc */
7445 case 0x90: /* 3DNow! pfcmpge */
7446 case 0x94: /* 3DNow! pfmin */
7447 case 0x96: /* 3DNow! pfrcp */
7448 case 0x97: /* 3DNow! pfrsqrt */
7449 case 0x9a: /* 3DNow! pfsub */
7450 case 0x9e: /* 3DNow! pfadd */
7451 case 0xa0: /* 3DNow! pfcmpgt */
7452 case 0xa4: /* 3DNow! pfmax */
7453 case 0xa6: /* 3DNow! pfrcpit1 */
7454 case 0xa7: /* 3DNow! pfrsqit1 */
7455 case 0xaa: /* 3DNow! pfsubr */
7456 case 0xae: /* 3DNow! pfacc */
7457 case 0xb0: /* 3DNow! pfcmpeq */
7458 case 0xb4: /* 3DNow! pfmul */
7459 case 0xb6: /* 3DNow! pfrcpit2 */
7460 case 0xb7: /* 3DNow! pmulhrw */
7461 case 0xbb: /* 3DNow! pswapd */
7462 case 0xbf: /* 3DNow! pavgusb */
7463 if (!i386_mmx_regnum_p (gdbarch, I387_MM0_REGNUM (tdep) + ir.reg))
7464 goto no_support_3dnow_data;
7465 record_full_arch_list_add_reg (ir.regcache, ir.reg);
7466 break;
7468 default:
7469 no_support_3dnow_data:
7470 opcode = (opcode << 8) | opcode8;
7471 goto no_support;
7472 break;
7474 break;
7476 case 0x0faa: /* rsm */
7477 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7478 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
7479 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
7480 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
7481 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBX_REGNUM);
7482 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
7483 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM);
7484 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
7485 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
7486 break;
7488 case 0x0fae:
7489 if (i386_record_modrm (&ir))
7490 return -1;
7491 switch(ir.reg)
7493 case 0: /* fxsave */
7495 uint64_t tmpu64;
7497 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7498 if (i386_record_lea_modrm_addr (&ir, &tmpu64))
7499 return -1;
7500 if (record_full_arch_list_add_mem (tmpu64, 512))
7501 return -1;
7503 break;
7505 case 1: /* fxrstor */
7507 int i;
7509 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7511 for (i = I387_MM0_REGNUM (tdep);
7512 i386_mmx_regnum_p (gdbarch, i); i++)
7513 record_full_arch_list_add_reg (ir.regcache, i);
7515 for (i = I387_XMM0_REGNUM (tdep);
7516 i386_xmm_regnum_p (gdbarch, i); i++)
7517 record_full_arch_list_add_reg (ir.regcache, i);
7519 if (i386_mxcsr_regnum_p (gdbarch, I387_MXCSR_REGNUM(tdep)))
7520 record_full_arch_list_add_reg (ir.regcache,
7521 I387_MXCSR_REGNUM(tdep));
7523 for (i = I387_ST0_REGNUM (tdep);
7524 i386_fp_regnum_p (gdbarch, i); i++)
7525 record_full_arch_list_add_reg (ir.regcache, i);
7527 for (i = I387_FCTRL_REGNUM (tdep);
7528 i386_fpc_regnum_p (gdbarch, i); i++)
7529 record_full_arch_list_add_reg (ir.regcache, i);
7531 break;
7533 case 2: /* ldmxcsr */
7534 if (!i386_mxcsr_regnum_p (gdbarch, I387_MXCSR_REGNUM(tdep)))
7535 goto no_support;
7536 record_full_arch_list_add_reg (ir.regcache, I387_MXCSR_REGNUM(tdep));
7537 break;
7539 case 3: /* stmxcsr */
7540 ir.ot = OT_LONG;
7541 if (i386_record_lea_modrm (&ir))
7542 return -1;
7543 break;
7545 case 5: /* lfence */
7546 case 6: /* mfence */
7547 case 7: /* sfence clflush */
7548 break;
7550 default:
7551 opcode = (opcode << 8) | ir.modrm;
7552 goto no_support;
7553 break;
7555 break;
7557 case 0x0fc3: /* movnti */
7558 ir.ot = (ir.dflag == 2) ? OT_QUAD : OT_LONG;
7559 if (i386_record_modrm (&ir))
7560 return -1;
7561 if (ir.mod == 3)
7562 goto no_support;
7563 ir.reg |= rex_r;
7564 if (i386_record_lea_modrm (&ir))
7565 return -1;
7566 break;
7568 /* Add prefix to opcode. */
7569 case 0x0f10:
7570 case 0x0f11:
7571 case 0x0f12:
7572 case 0x0f13:
7573 case 0x0f14:
7574 case 0x0f15:
7575 case 0x0f16:
7576 case 0x0f17:
7577 case 0x0f28:
7578 case 0x0f29:
7579 case 0x0f2a:
7580 case 0x0f2b:
7581 case 0x0f2c:
7582 case 0x0f2d:
7583 case 0x0f2e:
7584 case 0x0f2f:
7585 case 0x0f38:
7586 case 0x0f39:
7587 case 0x0f3a:
7588 case 0x0f50:
7589 case 0x0f51:
7590 case 0x0f52:
7591 case 0x0f53:
7592 case 0x0f54:
7593 case 0x0f55:
7594 case 0x0f56:
7595 case 0x0f57:
7596 case 0x0f58:
7597 case 0x0f59:
7598 case 0x0f5a:
7599 case 0x0f5b:
7600 case 0x0f5c:
7601 case 0x0f5d:
7602 case 0x0f5e:
7603 case 0x0f5f:
7604 case 0x0f60:
7605 case 0x0f61:
7606 case 0x0f62:
7607 case 0x0f63:
7608 case 0x0f64:
7609 case 0x0f65:
7610 case 0x0f66:
7611 case 0x0f67:
7612 case 0x0f68:
7613 case 0x0f69:
7614 case 0x0f6a:
7615 case 0x0f6b:
7616 case 0x0f6c:
7617 case 0x0f6d:
7618 case 0x0f6e:
7619 case 0x0f6f:
7620 case 0x0f70:
7621 case 0x0f71:
7622 case 0x0f72:
7623 case 0x0f73:
7624 case 0x0f74:
7625 case 0x0f75:
7626 case 0x0f76:
7627 case 0x0f7c:
7628 case 0x0f7d:
7629 case 0x0f7e:
7630 case 0x0f7f:
7631 case 0x0fb8:
7632 case 0x0fc2:
7633 case 0x0fc4:
7634 case 0x0fc5:
7635 case 0x0fc6:
7636 case 0x0fd0:
7637 case 0x0fd1:
7638 case 0x0fd2:
7639 case 0x0fd3:
7640 case 0x0fd4:
7641 case 0x0fd5:
7642 case 0x0fd6:
7643 case 0x0fd7:
7644 case 0x0fd8:
7645 case 0x0fd9:
7646 case 0x0fda:
7647 case 0x0fdb:
7648 case 0x0fdc:
7649 case 0x0fdd:
7650 case 0x0fde:
7651 case 0x0fdf:
7652 case 0x0fe0:
7653 case 0x0fe1:
7654 case 0x0fe2:
7655 case 0x0fe3:
7656 case 0x0fe4:
7657 case 0x0fe5:
7658 case 0x0fe6:
7659 case 0x0fe7:
7660 case 0x0fe8:
7661 case 0x0fe9:
7662 case 0x0fea:
7663 case 0x0feb:
7664 case 0x0fec:
7665 case 0x0fed:
7666 case 0x0fee:
7667 case 0x0fef:
7668 case 0x0ff0:
7669 case 0x0ff1:
7670 case 0x0ff2:
7671 case 0x0ff3:
7672 case 0x0ff4:
7673 case 0x0ff5:
7674 case 0x0ff6:
7675 case 0x0ff7:
7676 case 0x0ff8:
7677 case 0x0ff9:
7678 case 0x0ffa:
7679 case 0x0ffb:
7680 case 0x0ffc:
7681 case 0x0ffd:
7682 case 0x0ffe:
7683 /* Mask out PREFIX_ADDR. */
7684 switch ((prefixes & ~PREFIX_ADDR))
7686 case PREFIX_REPNZ:
7687 opcode |= 0xf20000;
7688 break;
7689 case PREFIX_DATA:
7690 opcode |= 0x660000;
7691 break;
7692 case PREFIX_REPZ:
7693 opcode |= 0xf30000;
7694 break;
7696 reswitch_prefix_add:
7697 switch (opcode)
7699 case 0x0f38:
7700 case 0x660f38:
7701 case 0xf20f38:
7702 case 0x0f3a:
7703 case 0x660f3a:
7704 if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
7705 return -1;
7706 ir.addr++;
7707 opcode = (uint32_t) opcode8 | opcode << 8;
7708 goto reswitch_prefix_add;
7709 break;
7711 case 0x0f10: /* movups */
7712 case 0x660f10: /* movupd */
7713 case 0xf30f10: /* movss */
7714 case 0xf20f10: /* movsd */
7715 case 0x0f12: /* movlps */
7716 case 0x660f12: /* movlpd */
7717 case 0xf30f12: /* movsldup */
7718 case 0xf20f12: /* movddup */
7719 case 0x0f14: /* unpcklps */
7720 case 0x660f14: /* unpcklpd */
7721 case 0x0f15: /* unpckhps */
7722 case 0x660f15: /* unpckhpd */
7723 case 0x0f16: /* movhps */
7724 case 0x660f16: /* movhpd */
7725 case 0xf30f16: /* movshdup */
7726 case 0x0f28: /* movaps */
7727 case 0x660f28: /* movapd */
7728 case 0x0f2a: /* cvtpi2ps */
7729 case 0x660f2a: /* cvtpi2pd */
7730 case 0xf30f2a: /* cvtsi2ss */
7731 case 0xf20f2a: /* cvtsi2sd */
7732 case 0x0f2c: /* cvttps2pi */
7733 case 0x660f2c: /* cvttpd2pi */
7734 case 0x0f2d: /* cvtps2pi */
7735 case 0x660f2d: /* cvtpd2pi */
7736 case 0x660f3800: /* pshufb */
7737 case 0x660f3801: /* phaddw */
7738 case 0x660f3802: /* phaddd */
7739 case 0x660f3803: /* phaddsw */
7740 case 0x660f3804: /* pmaddubsw */
7741 case 0x660f3805: /* phsubw */
7742 case 0x660f3806: /* phsubd */
7743 case 0x660f3807: /* phsubsw */
7744 case 0x660f3808: /* psignb */
7745 case 0x660f3809: /* psignw */
7746 case 0x660f380a: /* psignd */
7747 case 0x660f380b: /* pmulhrsw */
7748 case 0x660f3810: /* pblendvb */
7749 case 0x660f3814: /* blendvps */
7750 case 0x660f3815: /* blendvpd */
7751 case 0x660f381c: /* pabsb */
7752 case 0x660f381d: /* pabsw */
7753 case 0x660f381e: /* pabsd */
7754 case 0x660f3820: /* pmovsxbw */
7755 case 0x660f3821: /* pmovsxbd */
7756 case 0x660f3822: /* pmovsxbq */
7757 case 0x660f3823: /* pmovsxwd */
7758 case 0x660f3824: /* pmovsxwq */
7759 case 0x660f3825: /* pmovsxdq */
7760 case 0x660f3828: /* pmuldq */
7761 case 0x660f3829: /* pcmpeqq */
7762 case 0x660f382a: /* movntdqa */
7763 case 0x660f3a08: /* roundps */
7764 case 0x660f3a09: /* roundpd */
7765 case 0x660f3a0a: /* roundss */
7766 case 0x660f3a0b: /* roundsd */
7767 case 0x660f3a0c: /* blendps */
7768 case 0x660f3a0d: /* blendpd */
7769 case 0x660f3a0e: /* pblendw */
7770 case 0x660f3a0f: /* palignr */
7771 case 0x660f3a20: /* pinsrb */
7772 case 0x660f3a21: /* insertps */
7773 case 0x660f3a22: /* pinsrd pinsrq */
7774 case 0x660f3a40: /* dpps */
7775 case 0x660f3a41: /* dppd */
7776 case 0x660f3a42: /* mpsadbw */
7777 case 0x660f3a60: /* pcmpestrm */
7778 case 0x660f3a61: /* pcmpestri */
7779 case 0x660f3a62: /* pcmpistrm */
7780 case 0x660f3a63: /* pcmpistri */
7781 case 0x0f51: /* sqrtps */
7782 case 0x660f51: /* sqrtpd */
7783 case 0xf20f51: /* sqrtsd */
7784 case 0xf30f51: /* sqrtss */
7785 case 0x0f52: /* rsqrtps */
7786 case 0xf30f52: /* rsqrtss */
7787 case 0x0f53: /* rcpps */
7788 case 0xf30f53: /* rcpss */
7789 case 0x0f54: /* andps */
7790 case 0x660f54: /* andpd */
7791 case 0x0f55: /* andnps */
7792 case 0x660f55: /* andnpd */
7793 case 0x0f56: /* orps */
7794 case 0x660f56: /* orpd */
7795 case 0x0f57: /* xorps */
7796 case 0x660f57: /* xorpd */
7797 case 0x0f58: /* addps */
7798 case 0x660f58: /* addpd */
7799 case 0xf20f58: /* addsd */
7800 case 0xf30f58: /* addss */
7801 case 0x0f59: /* mulps */
7802 case 0x660f59: /* mulpd */
7803 case 0xf20f59: /* mulsd */
7804 case 0xf30f59: /* mulss */
7805 case 0x0f5a: /* cvtps2pd */
7806 case 0x660f5a: /* cvtpd2ps */
7807 case 0xf20f5a: /* cvtsd2ss */
7808 case 0xf30f5a: /* cvtss2sd */
7809 case 0x0f5b: /* cvtdq2ps */
7810 case 0x660f5b: /* cvtps2dq */
7811 case 0xf30f5b: /* cvttps2dq */
7812 case 0x0f5c: /* subps */
7813 case 0x660f5c: /* subpd */
7814 case 0xf20f5c: /* subsd */
7815 case 0xf30f5c: /* subss */
7816 case 0x0f5d: /* minps */
7817 case 0x660f5d: /* minpd */
7818 case 0xf20f5d: /* minsd */
7819 case 0xf30f5d: /* minss */
7820 case 0x0f5e: /* divps */
7821 case 0x660f5e: /* divpd */
7822 case 0xf20f5e: /* divsd */
7823 case 0xf30f5e: /* divss */
7824 case 0x0f5f: /* maxps */
7825 case 0x660f5f: /* maxpd */
7826 case 0xf20f5f: /* maxsd */
7827 case 0xf30f5f: /* maxss */
7828 case 0x660f60: /* punpcklbw */
7829 case 0x660f61: /* punpcklwd */
7830 case 0x660f62: /* punpckldq */
7831 case 0x660f63: /* packsswb */
7832 case 0x660f64: /* pcmpgtb */
7833 case 0x660f65: /* pcmpgtw */
7834 case 0x660f66: /* pcmpgtd */
7835 case 0x660f67: /* packuswb */
7836 case 0x660f68: /* punpckhbw */
7837 case 0x660f69: /* punpckhwd */
7838 case 0x660f6a: /* punpckhdq */
7839 case 0x660f6b: /* packssdw */
7840 case 0x660f6c: /* punpcklqdq */
7841 case 0x660f6d: /* punpckhqdq */
7842 case 0x660f6e: /* movd */
7843 case 0x660f6f: /* movdqa */
7844 case 0xf30f6f: /* movdqu */
7845 case 0x660f70: /* pshufd */
7846 case 0xf20f70: /* pshuflw */
7847 case 0xf30f70: /* pshufhw */
7848 case 0x660f74: /* pcmpeqb */
7849 case 0x660f75: /* pcmpeqw */
7850 case 0x660f76: /* pcmpeqd */
7851 case 0x660f7c: /* haddpd */
7852 case 0xf20f7c: /* haddps */
7853 case 0x660f7d: /* hsubpd */
7854 case 0xf20f7d: /* hsubps */
7855 case 0xf30f7e: /* movq */
7856 case 0x0fc2: /* cmpps */
7857 case 0x660fc2: /* cmppd */
7858 case 0xf20fc2: /* cmpsd */
7859 case 0xf30fc2: /* cmpss */
7860 case 0x660fc4: /* pinsrw */
7861 case 0x0fc6: /* shufps */
7862 case 0x660fc6: /* shufpd */
7863 case 0x660fd0: /* addsubpd */
7864 case 0xf20fd0: /* addsubps */
7865 case 0x660fd1: /* psrlw */
7866 case 0x660fd2: /* psrld */
7867 case 0x660fd3: /* psrlq */
7868 case 0x660fd4: /* paddq */
7869 case 0x660fd5: /* pmullw */
7870 case 0xf30fd6: /* movq2dq */
7871 case 0x660fd8: /* psubusb */
7872 case 0x660fd9: /* psubusw */
7873 case 0x660fda: /* pminub */
7874 case 0x660fdb: /* pand */
7875 case 0x660fdc: /* paddusb */
7876 case 0x660fdd: /* paddusw */
7877 case 0x660fde: /* pmaxub */
7878 case 0x660fdf: /* pandn */
7879 case 0x660fe0: /* pavgb */
7880 case 0x660fe1: /* psraw */
7881 case 0x660fe2: /* psrad */
7882 case 0x660fe3: /* pavgw */
7883 case 0x660fe4: /* pmulhuw */
7884 case 0x660fe5: /* pmulhw */
7885 case 0x660fe6: /* cvttpd2dq */
7886 case 0xf20fe6: /* cvtpd2dq */
7887 case 0xf30fe6: /* cvtdq2pd */
7888 case 0x660fe8: /* psubsb */
7889 case 0x660fe9: /* psubsw */
7890 case 0x660fea: /* pminsw */
7891 case 0x660feb: /* por */
7892 case 0x660fec: /* paddsb */
7893 case 0x660fed: /* paddsw */
7894 case 0x660fee: /* pmaxsw */
7895 case 0x660fef: /* pxor */
7896 case 0xf20ff0: /* lddqu */
7897 case 0x660ff1: /* psllw */
7898 case 0x660ff2: /* pslld */
7899 case 0x660ff3: /* psllq */
7900 case 0x660ff4: /* pmuludq */
7901 case 0x660ff5: /* pmaddwd */
7902 case 0x660ff6: /* psadbw */
7903 case 0x660ff8: /* psubb */
7904 case 0x660ff9: /* psubw */
7905 case 0x660ffa: /* psubd */
7906 case 0x660ffb: /* psubq */
7907 case 0x660ffc: /* paddb */
7908 case 0x660ffd: /* paddw */
7909 case 0x660ffe: /* paddd */
7910 if (i386_record_modrm (&ir))
7911 return -1;
7912 ir.reg |= rex_r;
7913 if (!i386_xmm_regnum_p (gdbarch, I387_XMM0_REGNUM (tdep) + ir.reg))
7914 goto no_support;
7915 record_full_arch_list_add_reg (ir.regcache,
7916 I387_XMM0_REGNUM (tdep) + ir.reg);
7917 if ((opcode & 0xfffffffc) == 0x660f3a60)
7918 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
7919 break;
7921 case 0x0f11: /* movups */
7922 case 0x660f11: /* movupd */
7923 case 0xf30f11: /* movss */
7924 case 0xf20f11: /* movsd */
7925 case 0x0f13: /* movlps */
7926 case 0x660f13: /* movlpd */
7927 case 0x0f17: /* movhps */
7928 case 0x660f17: /* movhpd */
7929 case 0x0f29: /* movaps */
7930 case 0x660f29: /* movapd */
7931 case 0x660f3a14: /* pextrb */
7932 case 0x660f3a15: /* pextrw */
7933 case 0x660f3a16: /* pextrd pextrq */
7934 case 0x660f3a17: /* extractps */
7935 case 0x660f7f: /* movdqa */
7936 case 0xf30f7f: /* movdqu */
7937 if (i386_record_modrm (&ir))
7938 return -1;
7939 if (ir.mod == 3)
7941 if (opcode == 0x0f13 || opcode == 0x660f13
7942 || opcode == 0x0f17 || opcode == 0x660f17)
7943 goto no_support;
7944 ir.rm |= ir.rex_b;
7945 if (!i386_xmm_regnum_p (gdbarch,
7946 I387_XMM0_REGNUM (tdep) + ir.rm))
7947 goto no_support;
7948 record_full_arch_list_add_reg (ir.regcache,
7949 I387_XMM0_REGNUM (tdep) + ir.rm);
7951 else
7953 switch (opcode)
7955 case 0x660f3a14:
7956 ir.ot = OT_BYTE;
7957 break;
7958 case 0x660f3a15:
7959 ir.ot = OT_WORD;
7960 break;
7961 case 0x660f3a16:
7962 ir.ot = OT_LONG;
7963 break;
7964 case 0x660f3a17:
7965 ir.ot = OT_QUAD;
7966 break;
7967 default:
7968 ir.ot = OT_DQUAD;
7969 break;
7971 if (i386_record_lea_modrm (&ir))
7972 return -1;
7974 break;
7976 case 0x0f2b: /* movntps */
7977 case 0x660f2b: /* movntpd */
7978 case 0x0fe7: /* movntq */
7979 case 0x660fe7: /* movntdq */
7980 if (ir.mod == 3)
7981 goto no_support;
7982 if (opcode == 0x0fe7)
7983 ir.ot = OT_QUAD;
7984 else
7985 ir.ot = OT_DQUAD;
7986 if (i386_record_lea_modrm (&ir))
7987 return -1;
7988 break;
7990 case 0xf30f2c: /* cvttss2si */
7991 case 0xf20f2c: /* cvttsd2si */
7992 case 0xf30f2d: /* cvtss2si */
7993 case 0xf20f2d: /* cvtsd2si */
7994 case 0xf20f38f0: /* crc32 */
7995 case 0xf20f38f1: /* crc32 */
7996 case 0x0f50: /* movmskps */
7997 case 0x660f50: /* movmskpd */
7998 case 0x0fc5: /* pextrw */
7999 case 0x660fc5: /* pextrw */
8000 case 0x0fd7: /* pmovmskb */
8001 case 0x660fd7: /* pmovmskb */
8002 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
8003 break;
8005 case 0x0f3800: /* pshufb */
8006 case 0x0f3801: /* phaddw */
8007 case 0x0f3802: /* phaddd */
8008 case 0x0f3803: /* phaddsw */
8009 case 0x0f3804: /* pmaddubsw */
8010 case 0x0f3805: /* phsubw */
8011 case 0x0f3806: /* phsubd */
8012 case 0x0f3807: /* phsubsw */
8013 case 0x0f3808: /* psignb */
8014 case 0x0f3809: /* psignw */
8015 case 0x0f380a: /* psignd */
8016 case 0x0f380b: /* pmulhrsw */
8017 case 0x0f381c: /* pabsb */
8018 case 0x0f381d: /* pabsw */
8019 case 0x0f381e: /* pabsd */
8020 case 0x0f382b: /* packusdw */
8021 case 0x0f3830: /* pmovzxbw */
8022 case 0x0f3831: /* pmovzxbd */
8023 case 0x0f3832: /* pmovzxbq */
8024 case 0x0f3833: /* pmovzxwd */
8025 case 0x0f3834: /* pmovzxwq */
8026 case 0x0f3835: /* pmovzxdq */
8027 case 0x0f3837: /* pcmpgtq */
8028 case 0x0f3838: /* pminsb */
8029 case 0x0f3839: /* pminsd */
8030 case 0x0f383a: /* pminuw */
8031 case 0x0f383b: /* pminud */
8032 case 0x0f383c: /* pmaxsb */
8033 case 0x0f383d: /* pmaxsd */
8034 case 0x0f383e: /* pmaxuw */
8035 case 0x0f383f: /* pmaxud */
8036 case 0x0f3840: /* pmulld */
8037 case 0x0f3841: /* phminposuw */
8038 case 0x0f3a0f: /* palignr */
8039 case 0x0f60: /* punpcklbw */
8040 case 0x0f61: /* punpcklwd */
8041 case 0x0f62: /* punpckldq */
8042 case 0x0f63: /* packsswb */
8043 case 0x0f64: /* pcmpgtb */
8044 case 0x0f65: /* pcmpgtw */
8045 case 0x0f66: /* pcmpgtd */
8046 case 0x0f67: /* packuswb */
8047 case 0x0f68: /* punpckhbw */
8048 case 0x0f69: /* punpckhwd */
8049 case 0x0f6a: /* punpckhdq */
8050 case 0x0f6b: /* packssdw */
8051 case 0x0f6e: /* movd */
8052 case 0x0f6f: /* movq */
8053 case 0x0f70: /* pshufw */
8054 case 0x0f74: /* pcmpeqb */
8055 case 0x0f75: /* pcmpeqw */
8056 case 0x0f76: /* pcmpeqd */
8057 case 0x0fc4: /* pinsrw */
8058 case 0x0fd1: /* psrlw */
8059 case 0x0fd2: /* psrld */
8060 case 0x0fd3: /* psrlq */
8061 case 0x0fd4: /* paddq */
8062 case 0x0fd5: /* pmullw */
8063 case 0xf20fd6: /* movdq2q */
8064 case 0x0fd8: /* psubusb */
8065 case 0x0fd9: /* psubusw */
8066 case 0x0fda: /* pminub */
8067 case 0x0fdb: /* pand */
8068 case 0x0fdc: /* paddusb */
8069 case 0x0fdd: /* paddusw */
8070 case 0x0fde: /* pmaxub */
8071 case 0x0fdf: /* pandn */
8072 case 0x0fe0: /* pavgb */
8073 case 0x0fe1: /* psraw */
8074 case 0x0fe2: /* psrad */
8075 case 0x0fe3: /* pavgw */
8076 case 0x0fe4: /* pmulhuw */
8077 case 0x0fe5: /* pmulhw */
8078 case 0x0fe8: /* psubsb */
8079 case 0x0fe9: /* psubsw */
8080 case 0x0fea: /* pminsw */
8081 case 0x0feb: /* por */
8082 case 0x0fec: /* paddsb */
8083 case 0x0fed: /* paddsw */
8084 case 0x0fee: /* pmaxsw */
8085 case 0x0fef: /* pxor */
8086 case 0x0ff1: /* psllw */
8087 case 0x0ff2: /* pslld */
8088 case 0x0ff3: /* psllq */
8089 case 0x0ff4: /* pmuludq */
8090 case 0x0ff5: /* pmaddwd */
8091 case 0x0ff6: /* psadbw */
8092 case 0x0ff8: /* psubb */
8093 case 0x0ff9: /* psubw */
8094 case 0x0ffa: /* psubd */
8095 case 0x0ffb: /* psubq */
8096 case 0x0ffc: /* paddb */
8097 case 0x0ffd: /* paddw */
8098 case 0x0ffe: /* paddd */
8099 if (i386_record_modrm (&ir))
8100 return -1;
8101 if (!i386_mmx_regnum_p (gdbarch, I387_MM0_REGNUM (tdep) + ir.reg))
8102 goto no_support;
8103 record_full_arch_list_add_reg (ir.regcache,
8104 I387_MM0_REGNUM (tdep) + ir.reg);
8105 break;
8107 case 0x0f71: /* psllw */
8108 case 0x0f72: /* pslld */
8109 case 0x0f73: /* psllq */
8110 if (i386_record_modrm (&ir))
8111 return -1;
8112 if (!i386_mmx_regnum_p (gdbarch, I387_MM0_REGNUM (tdep) + ir.rm))
8113 goto no_support;
8114 record_full_arch_list_add_reg (ir.regcache,
8115 I387_MM0_REGNUM (tdep) + ir.rm);
8116 break;
8118 case 0x660f71: /* psllw */
8119 case 0x660f72: /* pslld */
8120 case 0x660f73: /* psllq */
8121 if (i386_record_modrm (&ir))
8122 return -1;
8123 ir.rm |= ir.rex_b;
8124 if (!i386_xmm_regnum_p (gdbarch, I387_XMM0_REGNUM (tdep) + ir.rm))
8125 goto no_support;
8126 record_full_arch_list_add_reg (ir.regcache,
8127 I387_XMM0_REGNUM (tdep) + ir.rm);
8128 break;
8130 case 0x0f7e: /* movd */
8131 case 0x660f7e: /* movd */
8132 if (i386_record_modrm (&ir))
8133 return -1;
8134 if (ir.mod == 3)
8135 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
8136 else
8138 if (ir.dflag == 2)
8139 ir.ot = OT_QUAD;
8140 else
8141 ir.ot = OT_LONG;
8142 if (i386_record_lea_modrm (&ir))
8143 return -1;
8145 break;
8147 case 0x0f7f: /* movq */
8148 if (i386_record_modrm (&ir))
8149 return -1;
8150 if (ir.mod == 3)
8152 if (!i386_mmx_regnum_p (gdbarch, I387_MM0_REGNUM (tdep) + ir.rm))
8153 goto no_support;
8154 record_full_arch_list_add_reg (ir.regcache,
8155 I387_MM0_REGNUM (tdep) + ir.rm);
8157 else
8159 ir.ot = OT_QUAD;
8160 if (i386_record_lea_modrm (&ir))
8161 return -1;
8163 break;
8165 case 0xf30fb8: /* popcnt */
8166 if (i386_record_modrm (&ir))
8167 return -1;
8168 I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
8169 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
8170 break;
8172 case 0x660fd6: /* movq */
8173 if (i386_record_modrm (&ir))
8174 return -1;
8175 if (ir.mod == 3)
8177 ir.rm |= ir.rex_b;
8178 if (!i386_xmm_regnum_p (gdbarch,
8179 I387_XMM0_REGNUM (tdep) + ir.rm))
8180 goto no_support;
8181 record_full_arch_list_add_reg (ir.regcache,
8182 I387_XMM0_REGNUM (tdep) + ir.rm);
8184 else
8186 ir.ot = OT_QUAD;
8187 if (i386_record_lea_modrm (&ir))
8188 return -1;
8190 break;
8192 case 0x660f3817: /* ptest */
8193 case 0x0f2e: /* ucomiss */
8194 case 0x660f2e: /* ucomisd */
8195 case 0x0f2f: /* comiss */
8196 case 0x660f2f: /* comisd */
8197 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
8198 break;
8200 case 0x0ff7: /* maskmovq */
8201 regcache_raw_read_unsigned (ir.regcache,
8202 ir.regmap[X86_RECORD_REDI_REGNUM],
8203 &addr);
8204 if (record_full_arch_list_add_mem (addr, 64))
8205 return -1;
8206 break;
8208 case 0x660ff7: /* maskmovdqu */
8209 regcache_raw_read_unsigned (ir.regcache,
8210 ir.regmap[X86_RECORD_REDI_REGNUM],
8211 &addr);
8212 if (record_full_arch_list_add_mem (addr, 128))
8213 return -1;
8214 break;
8216 default:
8217 goto no_support;
8218 break;
8220 break;
8222 default:
8223 goto no_support;
8224 break;
8227 /* In the future, maybe still need to deal with need_dasm. */
8228 I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REIP_REGNUM);
8229 if (record_full_arch_list_add_end ())
8230 return -1;
8232 return 0;
8234 no_support:
8235 gdb_printf (gdb_stderr,
8236 _("Process record does not support instruction 0x%02x "
8237 "at address %s.\n"),
8238 (unsigned int) (opcode),
8239 paddress (gdbarch, ir.orig_addr));
8240 return -1;
8243 static const int i386_record_regmap[] =
8245 I386_EAX_REGNUM, I386_ECX_REGNUM, I386_EDX_REGNUM, I386_EBX_REGNUM,
8246 I386_ESP_REGNUM, I386_EBP_REGNUM, I386_ESI_REGNUM, I386_EDI_REGNUM,
8247 0, 0, 0, 0,
8248 0, 0, 0, 0,
8249 I386_EIP_REGNUM, I386_EFLAGS_REGNUM, I386_CS_REGNUM, I386_SS_REGNUM,
8250 I386_DS_REGNUM, I386_ES_REGNUM, I386_FS_REGNUM, I386_GS_REGNUM,
8251 /* xmm0_regnum */ 0
8254 /* Check that the given address appears suitable for a fast
8255 tracepoint, which on x86-64 means that we need an instruction of at
8256 least 5 bytes, so that we can overwrite it with a 4-byte-offset
8257 jump and not have to worry about program jumps to an address in the
8258 middle of the tracepoint jump. On x86, it may be possible to use
8259 4-byte jumps with a 2-byte offset to a trampoline located in the
8260 bottom 64 KiB of memory. Returns 1 if OK, and writes a size
8261 of instruction to replace, and 0 if not, plus an explanatory
8262 string. */
8264 static int
8265 i386_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
8266 std::string *msg)
8268 int len, jumplen;
8270 /* Ask the target for the minimum instruction length supported. */
8271 jumplen = target_get_min_fast_tracepoint_insn_len ();
8273 if (jumplen < 0)
8275 /* If the target does not support the get_min_fast_tracepoint_insn_len
8276 operation, assume that fast tracepoints will always be implemented
8277 using 4-byte relative jumps on both x86 and x86-64. */
8278 jumplen = 5;
8280 else if (jumplen == 0)
8282 /* If the target does support get_min_fast_tracepoint_insn_len but
8283 returns zero, then the IPA has not loaded yet. In this case,
8284 we optimistically assume that truncated 2-byte relative jumps
8285 will be available on x86, and compensate later if this assumption
8286 turns out to be incorrect. On x86-64 architectures, 4-byte relative
8287 jumps will always be used. */
8288 jumplen = (register_size (gdbarch, 0) == 8) ? 5 : 4;
8291 /* Check for fit. */
8292 len = gdb_insn_length (gdbarch, addr);
8294 if (len < jumplen)
8296 /* Return a bit of target-specific detail to add to the caller's
8297 generic failure message. */
8298 if (msg)
8299 *msg = string_printf (_("; instruction is only %d bytes long, "
8300 "need at least %d bytes for the jump"),
8301 len, jumplen);
8302 return 0;
8304 else
8306 if (msg)
8307 msg->clear ();
8308 return 1;
8312 /* Return a floating-point format for a floating-point variable of
8313 length LEN in bits. If non-NULL, NAME is the name of its type.
8314 If no suitable type is found, return NULL. */
8316 static const struct floatformat **
8317 i386_floatformat_for_type (struct gdbarch *gdbarch,
8318 const char *name, int len)
8320 if (len == 128 && name)
8321 if (strcmp (name, "__float128") == 0
8322 || strcmp (name, "_Float128") == 0
8323 || strcmp (name, "complex _Float128") == 0
8324 || strcmp (name, "complex(kind=16)") == 0
8325 || strcmp (name, "COMPLEX(16)") == 0
8326 || strcmp (name, "complex*32") == 0
8327 || strcmp (name, "COMPLEX*32") == 0
8328 || strcmp (name, "quad complex") == 0
8329 || strcmp (name, "real(kind=16)") == 0
8330 || strcmp (name, "real*16") == 0
8331 || strcmp (name, "REAL*16") == 0
8332 || strcmp (name, "REAL(16)") == 0)
8333 return floatformats_ieee_quad;
8335 return default_floatformat_for_type (gdbarch, name, len);
8338 /* Compute an XCR0 mask based on a target description. */
8340 static uint64_t
8341 i386_xcr0_from_tdesc (const struct target_desc *tdesc)
8343 if (! tdesc_has_registers (tdesc))
8344 return 0;
8346 const struct tdesc_feature *feature_core;
8348 const struct tdesc_feature *feature_sse, *feature_avx,
8349 *feature_avx512, *feature_pkeys;
8351 /* Get core registers. */
8352 feature_core = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.core");
8353 if (feature_core == NULL)
8354 return 0;
8356 /* Get SSE registers. */
8357 feature_sse = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.sse");
8359 /* Try AVX registers. */
8360 feature_avx = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx");
8362 /* Try AVX512 registers. */
8363 feature_avx512 = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx512");
8365 /* Try PKEYS */
8366 feature_pkeys = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.pkeys");
8368 /* The XCR0 bits. */
8369 uint64_t xcr0 = X86_XSTATE_X87;
8371 if (feature_sse)
8372 xcr0 |= X86_XSTATE_SSE;
8374 if (feature_avx)
8376 /* AVX register description requires SSE register description. */
8377 if (!feature_sse)
8378 return 0;
8380 xcr0 |= X86_XSTATE_AVX;
8383 if (feature_avx512)
8385 /* AVX512 register description requires AVX register description. */
8386 if (!feature_avx)
8387 return 0;
8389 xcr0 |= X86_XSTATE_AVX512;
8392 if (feature_pkeys)
8393 xcr0 |= X86_XSTATE_PKRU;
8395 return xcr0;
8398 static int
8399 i386_validate_tdesc_p (i386_gdbarch_tdep *tdep,
8400 struct tdesc_arch_data *tdesc_data)
8402 const struct target_desc *tdesc = tdep->tdesc;
8403 const struct tdesc_feature *feature_core;
8405 const struct tdesc_feature *feature_sse, *feature_avx, *feature_avx512,
8406 *feature_pkeys, *feature_segments;
8407 int i, num_regs, valid_p;
8409 if (! tdesc_has_registers (tdesc))
8410 return 0;
8412 /* Get core registers. */
8413 feature_core = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.core");
8414 if (feature_core == NULL)
8415 return 0;
8417 /* Get SSE registers. */
8418 feature_sse = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.sse");
8420 /* Try AVX registers. */
8421 feature_avx = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx");
8423 /* Try AVX512 registers. */
8424 feature_avx512 = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx512");
8426 /* Try segment base registers. */
8427 feature_segments = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.segments");
8429 /* Try PKEYS */
8430 feature_pkeys = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.pkeys");
8432 valid_p = 1;
8434 /* The XCR0 bits. */
8435 if (feature_avx512)
8437 /* AVX512 register description requires AVX register description. */
8438 if (!feature_avx)
8439 return 0;
8441 tdep->xcr0 = X86_XSTATE_AVX_AVX512_MASK;
8443 /* It may have been set by OSABI initialization function. */
8444 if (tdep->k0_regnum < 0)
8446 tdep->k_register_names = i386_k_names;
8447 tdep->k0_regnum = I386_K0_REGNUM;
8450 for (i = 0; i < I387_NUM_K_REGS; i++)
8451 valid_p &= tdesc_numbered_register (feature_avx512, tdesc_data,
8452 tdep->k0_regnum + i,
8453 i386_k_names[i]);
8455 if (tdep->num_zmm_regs == 0)
8457 tdep->zmmh_register_names = i386_zmmh_names;
8458 tdep->num_zmm_regs = 8;
8459 tdep->zmm0h_regnum = I386_ZMM0H_REGNUM;
8462 for (i = 0; i < tdep->num_zmm_regs; i++)
8463 valid_p &= tdesc_numbered_register (feature_avx512, tdesc_data,
8464 tdep->zmm0h_regnum + i,
8465 tdep->zmmh_register_names[i]);
8467 for (i = 0; i < tdep->num_xmm_avx512_regs; i++)
8468 valid_p &= tdesc_numbered_register (feature_avx512, tdesc_data,
8469 tdep->xmm16_regnum + i,
8470 tdep->xmm_avx512_register_names[i]);
8472 for (i = 0; i < tdep->num_ymm_avx512_regs; i++)
8473 valid_p &= tdesc_numbered_register (feature_avx512, tdesc_data,
8474 tdep->ymm16h_regnum + i,
8475 tdep->ymm16h_register_names[i]);
8477 if (feature_avx)
8479 /* AVX register description requires SSE register description. */
8480 if (!feature_sse)
8481 return 0;
8483 if (!feature_avx512)
8484 tdep->xcr0 = X86_XSTATE_AVX_MASK;
8486 /* It may have been set by OSABI initialization function. */
8487 if (tdep->num_ymm_regs == 0)
8489 tdep->ymmh_register_names = i386_ymmh_names;
8490 tdep->num_ymm_regs = 8;
8491 tdep->ymm0h_regnum = I386_YMM0H_REGNUM;
8494 for (i = 0; i < tdep->num_ymm_regs; i++)
8495 valid_p &= tdesc_numbered_register (feature_avx, tdesc_data,
8496 tdep->ymm0h_regnum + i,
8497 tdep->ymmh_register_names[i]);
8499 else if (feature_sse)
8500 tdep->xcr0 = X86_XSTATE_SSE_MASK;
8501 else
8503 tdep->xcr0 = X86_XSTATE_X87_MASK;
8504 tdep->num_xmm_regs = 0;
8507 num_regs = tdep->num_core_regs;
8508 for (i = 0; i < num_regs; i++)
8509 valid_p &= tdesc_numbered_register (feature_core, tdesc_data, i,
8510 tdep->register_names[i]);
8512 if (feature_sse)
8514 /* Need to include %mxcsr, so add one. */
8515 num_regs += tdep->num_xmm_regs + 1;
8516 for (; i < num_regs; i++)
8517 valid_p &= tdesc_numbered_register (feature_sse, tdesc_data, i,
8518 tdep->register_names[i]);
8521 if (feature_segments)
8523 if (tdep->fsbase_regnum < 0)
8524 tdep->fsbase_regnum = I386_FSBASE_REGNUM;
8525 valid_p &= tdesc_numbered_register (feature_segments, tdesc_data,
8526 tdep->fsbase_regnum, "fs_base");
8527 valid_p &= tdesc_numbered_register (feature_segments, tdesc_data,
8528 tdep->fsbase_regnum + 1, "gs_base");
8531 if (feature_pkeys)
8533 tdep->xcr0 |= X86_XSTATE_PKRU;
8534 if (tdep->pkru_regnum < 0)
8536 tdep->pkeys_register_names = i386_pkeys_names;
8537 tdep->pkru_regnum = I386_PKRU_REGNUM;
8538 tdep->num_pkeys_regs = 1;
8541 for (i = 0; i < I387_NUM_PKEYS_REGS; i++)
8542 valid_p &= tdesc_numbered_register (feature_pkeys, tdesc_data,
8543 I387_PKRU_REGNUM (tdep) + i,
8544 tdep->pkeys_register_names[i]);
8547 return valid_p;
8552 /* Implement the type_align gdbarch function. */
8554 static ULONGEST
8555 i386_type_align (struct gdbarch *gdbarch, struct type *type)
8557 type = check_typedef (type);
8559 if (gdbarch_ptr_bit (gdbarch) == 32)
8561 if ((type->code () == TYPE_CODE_INT
8562 || type->code () == TYPE_CODE_FLT)
8563 && type->length () > 4)
8564 return 4;
8566 /* Handle x86's funny long double. */
8567 if (type->code () == TYPE_CODE_FLT
8568 && gdbarch_long_double_bit (gdbarch) == type->length () * 8)
8569 return 4;
8572 return 0;
8576 /* Note: This is called for both i386 and amd64. */
8578 static struct gdbarch *
8579 i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
8581 const struct target_desc *tdesc;
8582 int mm0_regnum;
8583 int ymm0_regnum;
8585 x86_xsave_layout xsave_layout = target_fetch_x86_xsave_layout ();
8587 /* If the target did not provide an XSAVE layout but the target
8588 description includes registers from the XSAVE extended region,
8589 use a fallback XSAVE layout. Specifically, this fallback layout
8590 is used when writing out a local core dump for a remote
8591 target. */
8592 if (xsave_layout.sizeof_xsave == 0)
8593 xsave_layout
8594 = i387_fallback_xsave_layout (i386_xcr0_from_tdesc (info.target_desc));
8596 /* If there is already a candidate, use it. */
8597 for (arches = gdbarch_list_lookup_by_info (arches, &info);
8598 arches != NULL;
8599 arches = gdbarch_list_lookup_by_info (arches->next, &info))
8601 /* Check that the XSAVE layout of ARCHES matches the layout for
8602 the current target. */
8603 i386_gdbarch_tdep *other_tdep
8604 = gdbarch_tdep<i386_gdbarch_tdep> (arches->gdbarch);
8606 if (other_tdep->xsave_layout == xsave_layout)
8607 return arches->gdbarch;
8610 /* Allocate space for the new architecture. Assume i386 for now. */
8611 gdbarch *gdbarch
8612 = gdbarch_alloc (&info, gdbarch_tdep_up (new i386_gdbarch_tdep));
8613 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
8615 /* General-purpose registers. */
8616 tdep->gregset_reg_offset = NULL;
8617 tdep->gregset_num_regs = I386_NUM_GREGS;
8618 tdep->sizeof_gregset = 0;
8620 /* Floating-point registers. */
8621 tdep->sizeof_fpregset = I387_SIZEOF_FSAVE;
8622 tdep->fpregset = &i386_fpregset;
8624 /* The default settings include the FPU registers, the MMX registers
8625 and the SSE registers. This can be overridden for a specific ABI
8626 by adjusting the members `st0_regnum', `mm0_regnum' and
8627 `num_xmm_regs' of `struct gdbarch_tdep', otherwise the registers
8628 will show up in the output of "info all-registers". */
8630 tdep->st0_regnum = I386_ST0_REGNUM;
8632 /* I386_NUM_XREGS includes %mxcsr, so subtract one. */
8633 tdep->num_xmm_regs = I386_NUM_XREGS - 1;
8635 tdep->jb_pc_offset = -1;
8636 tdep->struct_return = pcc_struct_return;
8637 tdep->sigtramp_start = 0;
8638 tdep->sigtramp_end = 0;
8639 tdep->sigtramp_p = i386_sigtramp_p;
8640 tdep->sigcontext_addr = NULL;
8641 tdep->sc_reg_offset = NULL;
8642 tdep->sc_pc_offset = -1;
8643 tdep->sc_sp_offset = -1;
8645 tdep->xsave_xcr0_offset = -1;
8647 tdep->record_regmap = i386_record_regmap;
8649 set_gdbarch_type_align (gdbarch, i386_type_align);
8651 /* The format used for `long double' on almost all i386 targets is
8652 the i387 extended floating-point format. In fact, of all targets
8653 in the GCC 2.95 tree, only OSF/1 does it different, and insists
8654 on having a `long double' that's not `long' at all. */
8655 set_gdbarch_long_double_format (gdbarch, floatformats_i387_ext);
8657 /* Although the i387 extended floating-point has only 80 significant
8658 bits, a `long double' actually takes up 96, probably to enforce
8659 alignment. */
8660 set_gdbarch_long_double_bit (gdbarch, 96);
8662 /* Support of bfloat16 format. */
8663 set_gdbarch_bfloat16_format (gdbarch, floatformats_bfloat16);
8665 /* Support for floating-point data type variants. */
8666 set_gdbarch_floatformat_for_type (gdbarch, i386_floatformat_for_type);
8668 /* Register numbers of various important registers. */
8669 set_gdbarch_sp_regnum (gdbarch, I386_ESP_REGNUM); /* %esp */
8670 set_gdbarch_pc_regnum (gdbarch, I386_EIP_REGNUM); /* %eip */
8671 set_gdbarch_ps_regnum (gdbarch, I386_EFLAGS_REGNUM); /* %eflags */
8672 set_gdbarch_fp0_regnum (gdbarch, I386_ST0_REGNUM); /* %st(0) */
8674 /* NOTE: kettenis/20040418: GCC does have two possible register
8675 numbering schemes on the i386: dbx and SVR4. These schemes
8676 differ in how they number %ebp, %esp, %eflags, and the
8677 floating-point registers, and are implemented by the arrays
8678 dbx_register_map[] and svr4_dbx_register_map in
8679 gcc/config/i386.c. GCC also defines a third numbering scheme in
8680 gcc/config/i386.c, which it designates as the "default" register
8681 map used in 64bit mode. This last register numbering scheme is
8682 implemented in dbx64_register_map, and is used for AMD64; see
8683 amd64-tdep.c.
8685 Currently, each GCC i386 target always uses the same register
8686 numbering scheme across all its supported debugging formats
8687 i.e. SDB (COFF), stabs and DWARF 2. This is because
8688 gcc/sdbout.c, gcc/dbxout.c and gcc/dwarf2out.c all use the
8689 DBX_REGISTER_NUMBER macro which is defined by each target's
8690 respective config header in a manner independent of the requested
8691 output debugging format.
8693 This does not match the arrangement below, which presumes that
8694 the SDB and stabs numbering schemes differ from the DWARF and
8695 DWARF 2 ones. The reason for this arrangement is that it is
8696 likely to get the numbering scheme for the target's
8697 default/native debug format right. For targets where GCC is the
8698 native compiler (FreeBSD, NetBSD, OpenBSD, GNU/Linux) or for
8699 targets where the native toolchain uses a different numbering
8700 scheme for a particular debug format (stabs-in-ELF on Solaris)
8701 the defaults below will have to be overridden, like
8702 i386_elf_init_abi() does. */
8704 /* Use the dbx register numbering scheme for stabs and COFF. */
8705 set_gdbarch_stab_reg_to_regnum (gdbarch, i386_dbx_reg_to_regnum);
8706 set_gdbarch_sdb_reg_to_regnum (gdbarch, i386_dbx_reg_to_regnum);
8708 /* Use the SVR4 register numbering scheme for DWARF 2. */
8709 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, i386_svr4_dwarf_reg_to_regnum);
8711 /* We don't set gdbarch_stab_reg_to_regnum, since ECOFF doesn't seem to
8712 be in use on any of the supported i386 targets. */
8714 set_gdbarch_print_float_info (gdbarch, i387_print_float_info);
8716 set_gdbarch_get_longjmp_target (gdbarch, i386_get_longjmp_target);
8718 /* Call dummy code. */
8719 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
8720 set_gdbarch_push_dummy_code (gdbarch, i386_push_dummy_code);
8721 set_gdbarch_push_dummy_call (gdbarch, i386_push_dummy_call);
8722 set_gdbarch_frame_align (gdbarch, i386_frame_align);
8724 set_gdbarch_convert_register_p (gdbarch, i386_convert_register_p);
8725 set_gdbarch_register_to_value (gdbarch, i386_register_to_value);
8726 set_gdbarch_value_to_register (gdbarch, i386_value_to_register);
8728 set_gdbarch_return_value_as_value (gdbarch, i386_return_value);
8730 set_gdbarch_skip_prologue (gdbarch, i386_skip_prologue);
8732 /* Stack grows downward. */
8733 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
8735 set_gdbarch_breakpoint_kind_from_pc (gdbarch, i386_breakpoint::kind_from_pc);
8736 set_gdbarch_sw_breakpoint_from_kind (gdbarch, i386_breakpoint::bp_from_kind);
8738 set_gdbarch_decr_pc_after_break (gdbarch, 1);
8739 set_gdbarch_max_insn_length (gdbarch, I386_MAX_INSN_LEN);
8741 set_gdbarch_frame_args_skip (gdbarch, 8);
8743 set_gdbarch_print_insn (gdbarch, i386_print_insn);
8745 set_gdbarch_dummy_id (gdbarch, i386_dummy_id);
8747 set_gdbarch_unwind_pc (gdbarch, i386_unwind_pc);
8749 /* Add the i386 register groups. */
8750 i386_add_reggroups (gdbarch);
8751 tdep->register_reggroup_p = i386_register_reggroup_p;
8753 /* Helper for function argument information. */
8754 set_gdbarch_fetch_pointer_argument (gdbarch, i386_fetch_pointer_argument);
8756 /* Hook the function epilogue frame unwinder. This unwinder is
8757 appended to the list first, so that it supersedes the DWARF
8758 unwinder in function epilogues (where the DWARF unwinder
8759 currently fails). */
8760 if (info.bfd_arch_info->bits_per_word == 32)
8761 frame_unwind_append_unwinder (gdbarch, &i386_epilogue_override_frame_unwind);
8763 /* Hook in the DWARF CFI frame unwinder. This unwinder is appended
8764 to the list before the prologue-based unwinders, so that DWARF
8765 CFI info will be used if it is available. */
8766 dwarf2_append_unwinders (gdbarch);
8768 if (info.bfd_arch_info->bits_per_word == 32)
8769 frame_unwind_append_unwinder (gdbarch, &i386_epilogue_frame_unwind);
8771 frame_base_set_default (gdbarch, &i386_frame_base);
8773 /* Pseudo registers may be changed by amd64_init_abi. */
8774 set_gdbarch_pseudo_register_read_value (gdbarch,
8775 i386_pseudo_register_read_value);
8776 set_gdbarch_pseudo_register_write (gdbarch, i386_pseudo_register_write);
8777 set_gdbarch_ax_pseudo_register_collect (gdbarch,
8778 i386_ax_pseudo_register_collect);
8780 set_tdesc_pseudo_register_type (gdbarch, i386_pseudo_register_type);
8781 set_tdesc_pseudo_register_name (gdbarch, i386_pseudo_register_name);
8783 /* Override the normal target description method to make the AVX
8784 upper halves anonymous. */
8785 set_gdbarch_register_name (gdbarch, i386_register_name);
8787 /* Even though the default ABI only includes general-purpose registers,
8788 floating-point registers and the SSE registers, we have to leave a
8789 gap for the upper AVX, (deprecated) MPX and AVX512 registers. */
8790 set_gdbarch_num_regs (gdbarch, I386_NUM_REGS);
8792 set_gdbarch_gnu_triplet_regexp (gdbarch, i386_gnu_triplet_regexp);
8794 /* Get the x86 target description from INFO. */
8795 tdesc = info.target_desc;
8796 if (! tdesc_has_registers (tdesc))
8797 tdesc = i386_target_description (X86_XSTATE_SSE_MASK, false);
8798 tdep->tdesc = tdesc;
8800 tdep->num_core_regs = I386_NUM_GREGS + I387_NUM_REGS;
8801 tdep->register_names = i386_register_names;
8803 /* No upper YMM registers. */
8804 tdep->ymmh_register_names = NULL;
8805 tdep->ymm0h_regnum = -1;
8807 /* No upper ZMM registers. */
8808 tdep->zmmh_register_names = NULL;
8809 tdep->zmm0h_regnum = -1;
8811 /* No high XMM registers. */
8812 tdep->xmm_avx512_register_names = NULL;
8813 tdep->xmm16_regnum = -1;
8815 /* No upper YMM16-31 registers. */
8816 tdep->ymm16h_register_names = NULL;
8817 tdep->ymm16h_regnum = -1;
8819 tdep->num_byte_regs = 8;
8820 tdep->num_word_regs = 8;
8821 tdep->num_dword_regs = 0;
8822 tdep->num_mmx_regs = 8;
8823 tdep->num_ymm_regs = 0;
8825 /* No AVX512 registers. */
8826 tdep->k0_regnum = -1;
8827 tdep->num_zmm_regs = 0;
8828 tdep->num_ymm_avx512_regs = 0;
8829 tdep->num_xmm_avx512_regs = 0;
8831 /* No PKEYS registers */
8832 tdep->pkru_regnum = -1;
8833 tdep->num_pkeys_regs = 0;
8835 /* No segment base registers. */
8836 tdep->fsbase_regnum = -1;
8838 tdesc_arch_data_up tdesc_data = tdesc_data_alloc ();
8840 set_gdbarch_relocate_instruction (gdbarch, i386_relocate_instruction);
8842 set_gdbarch_gen_return_address (gdbarch, i386_gen_return_address);
8844 set_gdbarch_insn_is_call (gdbarch, i386_insn_is_call);
8845 set_gdbarch_insn_is_ret (gdbarch, i386_insn_is_ret);
8846 set_gdbarch_insn_is_jump (gdbarch, i386_insn_is_jump);
8848 /* Hook in ABI-specific overrides, if they have been registered.
8849 Note: If INFO specifies a 64 bit arch, this is where we turn
8850 a 32-bit i386 into a 64-bit amd64. */
8851 info.tdesc_data = tdesc_data.get ();
8852 gdbarch_init_osabi (info, gdbarch);
8854 if (!i386_validate_tdesc_p (tdep, tdesc_data.get ()))
8856 gdbarch_free (gdbarch);
8857 return NULL;
8859 tdep->xsave_layout = xsave_layout;
8861 /* Wire in pseudo registers. Number of pseudo registers may be
8862 changed. */
8863 set_gdbarch_num_pseudo_regs (gdbarch, (tdep->num_byte_regs
8864 + tdep->num_word_regs
8865 + tdep->num_dword_regs
8866 + tdep->num_mmx_regs
8867 + tdep->num_ymm_regs
8868 + tdep->num_ymm_avx512_regs
8869 + tdep->num_zmm_regs));
8871 /* Target description may be changed. */
8872 tdesc = tdep->tdesc;
8874 tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data));
8876 /* Override gdbarch_register_reggroup_p set in tdesc_use_registers. */
8877 set_gdbarch_register_reggroup_p (gdbarch, tdep->register_reggroup_p);
8879 /* Make %al the first pseudo-register. */
8880 tdep->al_regnum = gdbarch_num_regs (gdbarch);
8881 tdep->ax_regnum = tdep->al_regnum + tdep->num_byte_regs;
8883 ymm0_regnum = tdep->ax_regnum + tdep->num_word_regs;
8884 if (tdep->num_dword_regs)
8886 /* Support dword pseudo-register if it hasn't been disabled. */
8887 tdep->eax_regnum = ymm0_regnum;
8888 ymm0_regnum += tdep->num_dword_regs;
8890 else
8891 tdep->eax_regnum = -1;
8893 mm0_regnum = ymm0_regnum;
8894 if (tdep->num_ymm_regs)
8896 /* Support YMM pseudo-register if it is available. */
8897 tdep->ymm0_regnum = ymm0_regnum;
8898 mm0_regnum += tdep->num_ymm_regs;
8900 else
8901 tdep->ymm0_regnum = -1;
8903 if (tdep->num_ymm_avx512_regs)
8905 /* Support YMM16-31 pseudo registers if available. */
8906 tdep->ymm16_regnum = mm0_regnum;
8907 mm0_regnum += tdep->num_ymm_avx512_regs;
8909 else
8910 tdep->ymm16_regnum = -1;
8912 if (tdep->num_zmm_regs)
8914 /* Support ZMM pseudo-register if it is available. */
8915 tdep->zmm0_regnum = mm0_regnum;
8916 mm0_regnum += tdep->num_zmm_regs;
8918 else
8919 tdep->zmm0_regnum = -1;
8921 if (tdep->num_mmx_regs != 0)
8923 /* Support MMX pseudo-register if MMX hasn't been disabled. */
8924 tdep->mm0_regnum = mm0_regnum;
8926 else
8927 tdep->mm0_regnum = -1;
8929 /* Hook in the legacy prologue-based unwinders last (fallback). */
8930 if (info.bfd_arch_info->bits_per_word == 32)
8932 frame_unwind_append_unwinder (gdbarch, &i386_stack_tramp_frame_unwind);
8933 frame_unwind_append_unwinder (gdbarch, &i386_sigtramp_frame_unwind);
8934 frame_unwind_append_unwinder (gdbarch, &i386_frame_unwind);
8937 /* If we have a register mapping, enable the generic core file
8938 support, unless it has already been enabled. */
8939 if (tdep->gregset_reg_offset
8940 && !gdbarch_iterate_over_regset_sections_p (gdbarch))
8941 set_gdbarch_iterate_over_regset_sections
8942 (gdbarch, i386_iterate_over_regset_sections);
8944 set_gdbarch_fast_tracepoint_valid_at (gdbarch,
8945 i386_fast_tracepoint_valid_at);
8947 return gdbarch;
8952 /* Return the target description for a specified XSAVE feature mask. */
8954 const struct target_desc *
8955 i386_target_description (uint64_t xcr0, bool segments)
8957 static target_desc *i386_tdescs \
8958 [2/*SSE*/][2/*AVX*/][2/*AVX512*/][2/*PKRU*/][2/*segments*/] = {};
8959 target_desc **tdesc;
8961 tdesc = &i386_tdescs[(xcr0 & X86_XSTATE_SSE) ? 1 : 0]
8962 [(xcr0 & X86_XSTATE_AVX) ? 1 : 0]
8963 [(xcr0 & X86_XSTATE_AVX512) ? 1 : 0]
8964 [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0]
8965 [segments ? 1 : 0];
8967 if (*tdesc == NULL)
8968 *tdesc = i386_create_target_description (xcr0, false, segments);
8970 return *tdesc;
8973 void _initialize_i386_tdep ();
8974 void
8975 _initialize_i386_tdep ()
8977 gdbarch_register (bfd_arch_i386, i386_gdbarch_init);
8979 /* Add the variable that controls the disassembly flavor. */
8980 add_setshow_enum_cmd ("disassembly-flavor", no_class, valid_flavors,
8981 &disassembly_flavor, _("\
8982 Set the disassembly flavor."), _("\
8983 Show the disassembly flavor."), _("\
8984 The valid values are \"att\" and \"intel\", and the default value is \"att\"."),
8985 NULL,
8986 NULL, /* FIXME: i18n: */
8987 &setlist, &showlist);
8989 /* Add the variable that controls the convention for returning
8990 structs. */
8991 add_setshow_enum_cmd ("struct-convention", no_class, valid_conventions,
8992 &struct_convention, _("\
8993 Set the convention for returning small structs."), _("\
8994 Show the convention for returning small structs."), _("\
8995 Valid values are \"default\", \"pcc\" and \"reg\", and the default value\n\
8996 is \"default\"."),
8997 NULL,
8998 NULL, /* FIXME: i18n: */
8999 &setlist, &showlist);
9001 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_SVR4,
9002 i386_svr4_init_abi);
9004 /* Initialize the i386-specific register groups. */
9005 i386_init_reggroups ();
9007 /* Tell remote stub that we support XML target description. */
9008 register_remote_support_xml ("i386");