1 /* tc-i386.c -- Assemble code for the Intel 80386
2 Copyright (C) 1989-2021 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 /* Intel 80386 machine specific gas.
25 Bugs & suggestions are completely welcome. This is free software.
26 Please help us make it better. */
29 #include "safe-ctype.h"
31 #include "dwarf2dbg.h"
32 #include "dw2gencfi.h"
33 #include "elf/x86-64.h"
34 #include "opcodes/i386-init.h"
37 #ifndef INFER_ADDR_PREFIX
38 #define INFER_ADDR_PREFIX 1
42 #define DEFAULT_ARCH "i386"
47 #define INLINE __inline__
53 /* Prefixes will be emitted in the order defined below.
54 WAIT_PREFIX must be the first prefix since FWAIT is really is an
55 instruction, and so must come before any prefixes.
56 The preferred prefix order is SEG_PREFIX, ADDR_PREFIX, DATA_PREFIX,
57 REP_PREFIX/HLE_PREFIX, LOCK_PREFIX. */
63 #define HLE_PREFIX REP_PREFIX
64 #define BND_PREFIX REP_PREFIX
66 #define REX_PREFIX 6 /* must come last. */
67 #define MAX_PREFIXES 7 /* max prefixes per opcode */
69 /* we define the syntax here (modulo base,index,scale syntax) */
70 #define REGISTER_PREFIX '%'
71 #define IMMEDIATE_PREFIX '$'
72 #define ABSOLUTE_PREFIX '*'
74 /* these are the instruction mnemonic suffixes in AT&T syntax or
75 memory operand size in Intel syntax. */
76 #define WORD_MNEM_SUFFIX 'w'
77 #define BYTE_MNEM_SUFFIX 'b'
78 #define SHORT_MNEM_SUFFIX 's'
79 #define LONG_MNEM_SUFFIX 'l'
80 #define QWORD_MNEM_SUFFIX 'q'
81 /* Intel Syntax. Use a non-ascii letter since since it never appears
83 #define LONG_DOUBLE_MNEM_SUFFIX '\1'
85 #define END_OF_INSN '\0'
87 /* This matches the C -> StaticRounding alias in the opcode table. */
88 #define commutative staticrounding
91 'templates' is for grouping together 'template' structures for opcodes
92 of the same name. This is only used for storing the insns in the grand
93 ole hash table of insns.
94 The templates themselves start at START and range up to (but not including)
99 const insn_template *start;
100 const insn_template *end;
104 /* 386 operand encoding bytes: see 386 book for details of this. */
107 unsigned int regmem; /* codes register or memory operand */
108 unsigned int reg; /* codes register operand (or extended opcode) */
109 unsigned int mode; /* how to interpret regmem & reg */
113 /* x86-64 extension prefix. */
114 typedef int rex_byte;
116 /* 386 opcode byte to code indirect addressing. */
125 /* x86 arch names, types and features */
128 const char *name; /* arch name */
129 unsigned int len; /* arch string length */
130 enum processor_type type; /* arch type */
131 i386_cpu_flags flags; /* cpu feature flags */
132 unsigned int skip; /* show_arch should skip this. */
136 /* Used to turn off indicated flags. */
139 const char *name; /* arch name */
140 unsigned int len; /* arch string length */
141 i386_cpu_flags flags; /* cpu feature flags */
145 static void update_code_flag (int, int);
146 static void set_code_flag (int);
147 static void set_16bit_gcc_code_flag (int);
148 static void set_intel_syntax (int);
149 static void set_intel_mnemonic (int);
150 static void set_allow_index_reg (int);
151 static void set_check (int);
152 static void set_cpu_arch (int);
154 static void pe_directive_secrel (int);
156 static void signed_cons (int);
157 static char *output_invalid (int c);
158 static int i386_finalize_immediate (segT, expressionS *, i386_operand_type,
160 static int i386_finalize_displacement (segT, expressionS *, i386_operand_type,
162 static int i386_att_operand (char *);
163 static int i386_intel_operand (char *, int);
164 static int i386_intel_simplify (expressionS *);
165 static int i386_intel_parse_name (const char *, expressionS *);
166 static const reg_entry *parse_register (char *, char **);
167 static char *parse_insn (char *, char *);
168 static char *parse_operands (char *, const char *);
169 static void swap_operands (void);
170 static void swap_2_operands (unsigned int, unsigned int);
171 static enum flag_code i386_addressing_mode (void);
172 static void optimize_imm (void);
173 static void optimize_disp (void);
174 static const insn_template *match_template (char);
175 static int check_string (void);
176 static int process_suffix (void);
177 static int check_byte_reg (void);
178 static int check_long_reg (void);
179 static int check_qword_reg (void);
180 static int check_word_reg (void);
181 static int finalize_imm (void);
182 static int process_operands (void);
183 static const reg_entry *build_modrm_byte (void);
184 static void output_insn (void);
185 static void output_imm (fragS *, offsetT);
186 static void output_disp (fragS *, offsetT);
188 static void s_bss (int);
190 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
191 static void handle_large_common (int small ATTRIBUTE_UNUSED);
193 /* GNU_PROPERTY_X86_ISA_1_USED. */
194 static unsigned int x86_isa_1_used;
195 /* GNU_PROPERTY_X86_FEATURE_2_USED. */
196 static unsigned int x86_feature_2_used;
197 /* Generate x86 used ISA and feature properties. */
198 static unsigned int x86_used_note = DEFAULT_X86_USED_NOTE;
201 static const char *default_arch = DEFAULT_ARCH;
203 /* parse_register() returns this when a register alias cannot be used. */
204 static const reg_entry bad_reg = { "<bad>", OPERAND_TYPE_NONE, 0, 0,
205 { Dw2Inval, Dw2Inval } };
207 static const reg_entry *reg_eax;
208 static const reg_entry *reg_ds;
209 static const reg_entry *reg_es;
210 static const reg_entry *reg_ss;
211 static const reg_entry *reg_st0;
212 static const reg_entry *reg_k0;
217 /* VEX prefix is either 2 byte or 3 byte. EVEX is 4 byte. */
218 unsigned char bytes[4];
220 /* Destination or source register specifier. */
221 const reg_entry *register_specifier;
224 /* 'md_assemble ()' gathers together information and puts it into a
231 const reg_entry *regs;
236 operand_size_mismatch,
237 operand_type_mismatch,
238 register_type_mismatch,
239 number_of_operands_mismatch,
240 invalid_instruction_suffix,
242 unsupported_with_intel_mnemonic,
246 invalid_vsib_address,
247 invalid_vector_register_set,
248 invalid_tmm_register_set,
249 unsupported_vector_index_register,
250 unsupported_broadcast,
253 mask_not_on_destination,
256 rc_sae_operand_not_last_imm,
257 invalid_register_operand,
262 /* TM holds the template for the insn were currently assembling. */
265 /* SUFFIX holds the instruction size suffix for byte, word, dword
266 or qword, if given. */
269 /* OPCODE_LENGTH holds the number of base opcode bytes. */
270 unsigned char opcode_length;
272 /* OPERANDS gives the number of given operands. */
273 unsigned int operands;
275 /* REG_OPERANDS, DISP_OPERANDS, MEM_OPERANDS, IMM_OPERANDS give the number
276 of given register, displacement, memory operands and immediate
278 unsigned int reg_operands, disp_operands, mem_operands, imm_operands;
280 /* TYPES [i] is the type (see above #defines) which tells us how to
281 use OP[i] for the corresponding operand. */
282 i386_operand_type types[MAX_OPERANDS];
284 /* Displacement expression, immediate expression, or register for each
286 union i386_op op[MAX_OPERANDS];
288 /* Flags for operands. */
289 unsigned int flags[MAX_OPERANDS];
290 #define Operand_PCrel 1
291 #define Operand_Mem 2
293 /* Relocation type for operand */
294 enum bfd_reloc_code_real reloc[MAX_OPERANDS];
296 /* BASE_REG, INDEX_REG, and LOG2_SCALE_FACTOR are used to encode
297 the base index byte below. */
298 const reg_entry *base_reg;
299 const reg_entry *index_reg;
300 unsigned int log2_scale_factor;
302 /* SEG gives the seg_entries of this insn. They are zero unless
303 explicit segment overrides are given. */
304 const reg_entry *seg[2];
306 /* Copied first memory operand string, for re-checking. */
309 /* PREFIX holds all the given prefix opcodes (usually null).
310 PREFIXES is the number of prefix opcodes. */
311 unsigned int prefixes;
312 unsigned char prefix[MAX_PREFIXES];
314 /* Register is in low 3 bits of opcode. */
317 /* The operand to a branch insn indicates an absolute branch. */
320 /* Extended states. */
328 xstate_ymm = 1 << 2 | xstate_xmm,
330 xstate_zmm = 1 << 3 | xstate_ymm,
333 /* Use MASK state. */
337 /* Has GOTPC or TLS relocation. */
338 bool has_gotpc_tls_reloc;
340 /* RM and SIB are the modrm byte and the sib byte where the
341 addressing modes of this insn are encoded. */
348 /* Masking attributes.
350 The struct describes masking, applied to OPERAND in the instruction.
351 REG is a pointer to the corresponding mask register. ZEROING tells
352 whether merging or zeroing mask is used. */
353 struct Mask_Operation
355 const reg_entry *reg;
356 unsigned int zeroing;
357 /* The operand where this operation is associated. */
358 unsigned int operand;
361 /* Rounding control and SAE attributes. */
374 unsigned int operand;
377 /* Broadcasting attributes.
379 The struct describes broadcasting, applied to OPERAND. TYPE is
380 expresses the broadcast factor. */
381 struct Broadcast_Operation
383 /* Type of broadcast: {1to2}, {1to4}, {1to8}, or {1to16}. */
386 /* Index of broadcasted operand. */
387 unsigned int operand;
389 /* Number of bytes to broadcast. */
393 /* Compressed disp8*N attribute. */
394 unsigned int memshift;
396 /* Prefer load or store in encoding. */
399 dir_encoding_default = 0,
405 /* Prefer 8bit, 16bit, 32bit displacement in encoding. */
408 disp_encoding_default = 0,
414 /* Prefer the REX byte in encoding. */
417 /* Disable instruction size optimization. */
420 /* How to encode vector instructions. */
423 vex_encoding_default = 0,
431 const char *rep_prefix;
434 const char *hle_prefix;
436 /* Have BND prefix. */
437 const char *bnd_prefix;
439 /* Have NOTRACK prefix. */
440 const char *notrack_prefix;
443 enum i386_error error;
446 typedef struct _i386_insn i386_insn;
448 /* Link RC type with corresponding string, that'll be looked for in
457 static const struct RC_name RC_NamesTable[] =
459 { rne, STRING_COMMA_LEN ("rn-sae") },
460 { rd, STRING_COMMA_LEN ("rd-sae") },
461 { ru, STRING_COMMA_LEN ("ru-sae") },
462 { rz, STRING_COMMA_LEN ("rz-sae") },
463 { saeonly, STRING_COMMA_LEN ("sae") },
466 /* List of chars besides those in app.c:symbol_chars that can start an
467 operand. Used to prevent the scrubber eating vital white-space. */
468 const char extra_symbol_chars[] = "*%-([{}"
477 #if ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) \
478 && !defined (TE_GNU) \
479 && !defined (TE_LINUX) \
480 && !defined (TE_FreeBSD) \
481 && !defined (TE_DragonFly) \
482 && !defined (TE_NetBSD))
483 /* This array holds the chars that always start a comment. If the
484 pre-processor is disabled, these aren't very useful. The option
485 --divide will remove '/' from this list. */
486 const char *i386_comment_chars = "#/";
487 #define SVR4_COMMENT_CHARS 1
488 #define PREFIX_SEPARATOR '\\'
491 const char *i386_comment_chars = "#";
492 #define PREFIX_SEPARATOR '/'
495 /* This array holds the chars that only start a comment at the beginning of
496 a line. If the line seems to have the form '# 123 filename'
497 .line and .file directives will appear in the pre-processed output.
498 Note that input_file.c hand checks for '#' at the beginning of the
499 first line of the input file. This is because the compiler outputs
500 #NO_APP at the beginning of its output.
501 Also note that comments started like this one will always work if
502 '/' isn't otherwise defined. */
503 const char line_comment_chars[] = "#/";
505 const char line_separator_chars[] = ";";
507 /* Chars that can be used to separate mant from exp in floating point
509 const char EXP_CHARS[] = "eE";
511 /* Chars that mean this number is a floating point constant
514 const char FLT_CHARS[] = "fFdDxX";
516 /* Tables for lexical analysis. */
517 static char mnemonic_chars[256];
518 static char register_chars[256];
519 static char operand_chars[256];
520 static char identifier_chars[256];
522 /* Lexical macros. */
523 #define is_mnemonic_char(x) (mnemonic_chars[(unsigned char) x])
524 #define is_operand_char(x) (operand_chars[(unsigned char) x])
525 #define is_register_char(x) (register_chars[(unsigned char) x])
526 #define is_space_char(x) ((x) == ' ')
527 #define is_identifier_char(x) (identifier_chars[(unsigned char) x])
529 /* All non-digit non-letter characters that may occur in an operand. */
530 static char operand_special_chars[] = "%$-+(,)*._~/<>|&^!:[@]";
532 /* md_assemble() always leaves the strings it's passed unaltered. To
533 effect this we maintain a stack of saved characters that we've smashed
534 with '\0's (indicating end of strings for various sub-fields of the
535 assembler instruction). */
536 static char save_stack[32];
537 static char *save_stack_p;
538 #define END_STRING_AND_SAVE(s) \
539 do { *save_stack_p++ = *(s); *(s) = '\0'; } while (0)
540 #define RESTORE_END_STRING(s) \
541 do { *(s) = *--save_stack_p; } while (0)
543 /* The instruction we're assembling. */
546 /* Possible templates for current insn. */
547 static const templates *current_templates;
549 /* Per instruction expressionS buffers: max displacements & immediates. */
550 static expressionS disp_expressions[MAX_MEMORY_OPERANDS];
551 static expressionS im_expressions[MAX_IMMEDIATE_OPERANDS];
553 /* Current operand we are working on. */
554 static int this_operand = -1;
556 /* We support four different modes. FLAG_CODE variable is used to distinguish
564 static enum flag_code flag_code;
565 static unsigned int object_64bit;
566 static unsigned int disallow_64bit_reloc;
567 static int use_rela_relocations = 0;
568 /* __tls_get_addr/___tls_get_addr symbol for TLS. */
569 static const char *tls_get_addr;
571 #if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \
572 || defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \
573 || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O))
575 /* The ELF ABI to use. */
583 static enum x86_elf_abi x86_elf_abi = I386_ABI;
586 #if defined (TE_PE) || defined (TE_PEP)
587 /* Use big object file format. */
588 static int use_big_obj = 0;
591 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
592 /* 1 if generating code for a shared library. */
593 static int shared = 0;
596 /* 1 for intel syntax,
598 static int intel_syntax = 0;
600 static enum x86_64_isa
602 amd64 = 1, /* AMD64 ISA. */
603 intel64 /* Intel64 ISA. */
606 /* 1 for intel mnemonic,
607 0 if att mnemonic. */
608 static int intel_mnemonic = !SYSV386_COMPAT;
610 /* 1 if pseudo registers are permitted. */
611 static int allow_pseudo_reg = 0;
613 /* 1 if register prefix % not required. */
614 static int allow_naked_reg = 0;
616 /* 1 if the assembler should add BND prefix for all control-transferring
617 instructions supporting it, even if this prefix wasn't specified
619 static int add_bnd_prefix = 0;
621 /* 1 if pseudo index register, eiz/riz, is allowed . */
622 static int allow_index_reg = 0;
624 /* 1 if the assembler should ignore LOCK prefix, even if it was
625 specified explicitly. */
626 static int omit_lock_prefix = 0;
628 /* 1 if the assembler should encode lfence, mfence, and sfence as
629 "lock addl $0, (%{re}sp)". */
630 static int avoid_fence = 0;
632 /* 1 if lfence should be inserted after every load. */
633 static int lfence_after_load = 0;
635 /* Non-zero if lfence should be inserted before indirect branch. */
636 static enum lfence_before_indirect_branch_kind
638 lfence_branch_none = 0,
639 lfence_branch_register,
640 lfence_branch_memory,
643 lfence_before_indirect_branch;
645 /* Non-zero if lfence should be inserted before ret. */
646 static enum lfence_before_ret_kind
648 lfence_before_ret_none = 0,
649 lfence_before_ret_not,
650 lfence_before_ret_or,
651 lfence_before_ret_shl
655 /* Types of previous instruction is .byte or prefix. */
670 /* 1 if the assembler should generate relax relocations. */
672 static int generate_relax_relocations
673 = DEFAULT_GENERATE_X86_RELAX_RELOCATIONS;
675 static enum check_kind
681 sse_check, operand_check = check_warning;
683 /* Non-zero if branches should be aligned within power of 2 boundary. */
684 static int align_branch_power = 0;
686 /* Types of branches to align. */
687 enum align_branch_kind
689 align_branch_none = 0,
690 align_branch_jcc = 1,
691 align_branch_fused = 2,
692 align_branch_jmp = 3,
693 align_branch_call = 4,
694 align_branch_indirect = 5,
698 /* Type bits of branches to align. */
699 enum align_branch_bit
701 align_branch_jcc_bit = 1 << align_branch_jcc,
702 align_branch_fused_bit = 1 << align_branch_fused,
703 align_branch_jmp_bit = 1 << align_branch_jmp,
704 align_branch_call_bit = 1 << align_branch_call,
705 align_branch_indirect_bit = 1 << align_branch_indirect,
706 align_branch_ret_bit = 1 << align_branch_ret
709 static unsigned int align_branch = (align_branch_jcc_bit
710 | align_branch_fused_bit
711 | align_branch_jmp_bit);
713 /* Types of condition jump used by macro-fusion. */
716 mf_jcc_jo = 0, /* base opcode 0x70 */
717 mf_jcc_jc, /* base opcode 0x72 */
718 mf_jcc_je, /* base opcode 0x74 */
719 mf_jcc_jna, /* base opcode 0x76 */
720 mf_jcc_js, /* base opcode 0x78 */
721 mf_jcc_jp, /* base opcode 0x7a */
722 mf_jcc_jl, /* base opcode 0x7c */
723 mf_jcc_jle, /* base opcode 0x7e */
726 /* Types of compare flag-modifying insntructions used by macro-fusion. */
729 mf_cmp_test_and, /* test/cmp */
730 mf_cmp_alu_cmp, /* add/sub/cmp */
731 mf_cmp_incdec /* inc/dec */
734 /* The maximum padding size for fused jcc. CMP like instruction can
735 be 9 bytes and jcc can be 6 bytes. Leave room just in case for
737 #define MAX_FUSED_JCC_PADDING_SIZE 20
739 /* The maximum number of prefixes added for an instruction. */
740 static unsigned int align_branch_prefix_size = 5;
743 1. Clear the REX_W bit with register operand if possible.
744 2. Above plus use 128bit vector instruction to clear the full vector
747 static int optimize = 0;
750 1. Clear the REX_W bit with register operand if possible.
751 2. Above plus use 128bit vector instruction to clear the full vector
753 3. Above plus optimize "test{q,l,w} $imm8,%r{64,32,16}" to
756 static int optimize_for_space = 0;
758 /* Register prefix used for error message. */
759 static const char *register_prefix = "%";
761 /* Used in 16 bit gcc mode to add an l suffix to call, ret, enter,
762 leave, push, and pop instructions so that gcc has the same stack
763 frame as in 32 bit mode. */
764 static char stackop_size = '\0';
766 /* Non-zero to optimize code alignment. */
767 int optimize_align_code = 1;
769 /* Non-zero to quieten some warnings. */
770 static int quiet_warnings = 0;
773 static const char *cpu_arch_name = NULL;
774 static char *cpu_sub_arch_name = NULL;
776 /* CPU feature flags. */
777 static i386_cpu_flags cpu_arch_flags = CPU_UNKNOWN_FLAGS;
779 /* If we have selected a cpu we are generating instructions for. */
780 static int cpu_arch_tune_set = 0;
782 /* Cpu we are generating instructions for. */
783 enum processor_type cpu_arch_tune = PROCESSOR_UNKNOWN;
785 /* CPU feature flags of cpu we are generating instructions for. */
786 static i386_cpu_flags cpu_arch_tune_flags;
788 /* CPU instruction set architecture used. */
789 enum processor_type cpu_arch_isa = PROCESSOR_UNKNOWN;
791 /* CPU feature flags of instruction set architecture used. */
792 i386_cpu_flags cpu_arch_isa_flags;
794 /* If set, conditional jumps are not automatically promoted to handle
795 larger than a byte offset. */
796 static unsigned int no_cond_jump_promotion = 0;
798 /* Encode SSE instructions with VEX prefix. */
799 static unsigned int sse2avx;
801 /* Encode scalar AVX instructions with specific vector length. */
808 /* Encode VEX WIG instructions with specific vex.w. */
815 /* Encode scalar EVEX LIG instructions with specific vector length. */
823 /* Encode EVEX WIG instructions with specific evex.w. */
830 /* Value to encode in EVEX RC bits, for SAE-only instructions. */
831 static enum rc_type evexrcig = rne;
833 /* Pre-defined "_GLOBAL_OFFSET_TABLE_". */
834 static symbolS *GOT_symbol;
836 /* The dwarf2 return column, adjusted for 32 or 64 bit. */
837 unsigned int x86_dwarf2_return_column;
839 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
840 int x86_cie_data_alignment;
842 /* Interface to relax_segment.
843 There are 3 major relax states for 386 jump insns because the
844 different types of jumps add different sizes to frags when we're
845 figuring out what sort of jump to choose to reach a given label.
847 BRANCH_PADDING, BRANCH_PREFIX and FUSED_JCC_PADDING are used to align
848 branches which are handled by md_estimate_size_before_relax() and
849 i386_generic_table_relax_frag(). */
852 #define UNCOND_JUMP 0
854 #define COND_JUMP86 2
855 #define BRANCH_PADDING 3
856 #define BRANCH_PREFIX 4
857 #define FUSED_JCC_PADDING 5
862 #define SMALL16 (SMALL | CODE16)
864 #define BIG16 (BIG | CODE16)
868 #define INLINE __inline__
874 #define ENCODE_RELAX_STATE(type, size) \
875 ((relax_substateT) (((type) << 2) | (size)))
876 #define TYPE_FROM_RELAX_STATE(s) \
878 #define DISP_SIZE_FROM_RELAX_STATE(s) \
879 ((((s) & 3) == BIG ? 4 : (((s) & 3) == BIG16 ? 2 : 1)))
881 /* This table is used by relax_frag to promote short jumps to long
882 ones where necessary. SMALL (short) jumps may be promoted to BIG
883 (32 bit long) ones, and SMALL16 jumps to BIG16 (16 bit long). We
884 don't allow a short jump in a 32 bit code segment to be promoted to
885 a 16 bit offset jump because it's slower (requires data size
886 prefix), and doesn't work, unless the destination is in the bottom
887 64k of the code segment (The top 16 bits of eip are zeroed). */
889 const relax_typeS md_relax_table[] =
892 1) most positive reach of this state,
893 2) most negative reach of this state,
894 3) how many bytes this mode will have in the variable part of the frag
895 4) which index into the table to try if we can't fit into this one. */
897 /* UNCOND_JUMP states. */
898 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (UNCOND_JUMP, BIG)},
899 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (UNCOND_JUMP, BIG16)},
900 /* dword jmp adds 4 bytes to frag:
901 0 extra opcode bytes, 4 displacement bytes. */
903 /* word jmp adds 2 byte2 to frag:
904 0 extra opcode bytes, 2 displacement bytes. */
907 /* COND_JUMP states. */
908 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP, BIG)},
909 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP, BIG16)},
910 /* dword conditionals adds 5 bytes to frag:
911 1 extra opcode byte, 4 displacement bytes. */
913 /* word conditionals add 3 bytes to frag:
914 1 extra opcode byte, 2 displacement bytes. */
917 /* COND_JUMP86 states. */
918 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP86, BIG)},
919 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP86, BIG16)},
920 /* dword conditionals adds 5 bytes to frag:
921 1 extra opcode byte, 4 displacement bytes. */
923 /* word conditionals add 4 bytes to frag:
924 1 displacement byte and a 3 byte long branch insn. */
928 static const arch_entry cpu_arch[] =
930 /* Do not replace the first two entries - i386_target_format()
931 relies on them being there in this order. */
932 { STRING_COMMA_LEN ("generic32"), PROCESSOR_GENERIC32,
933 CPU_GENERIC32_FLAGS, 0 },
934 { STRING_COMMA_LEN ("generic64"), PROCESSOR_GENERIC64,
935 CPU_GENERIC64_FLAGS, 0 },
936 { STRING_COMMA_LEN ("i8086"), PROCESSOR_UNKNOWN,
938 { STRING_COMMA_LEN ("i186"), PROCESSOR_UNKNOWN,
940 { STRING_COMMA_LEN ("i286"), PROCESSOR_UNKNOWN,
942 { STRING_COMMA_LEN ("i386"), PROCESSOR_I386,
944 { STRING_COMMA_LEN ("i486"), PROCESSOR_I486,
946 { STRING_COMMA_LEN ("i586"), PROCESSOR_PENTIUM,
948 { STRING_COMMA_LEN ("i686"), PROCESSOR_PENTIUMPRO,
950 { STRING_COMMA_LEN ("pentium"), PROCESSOR_PENTIUM,
952 { STRING_COMMA_LEN ("pentiumpro"), PROCESSOR_PENTIUMPRO,
953 CPU_PENTIUMPRO_FLAGS, 0 },
954 { STRING_COMMA_LEN ("pentiumii"), PROCESSOR_PENTIUMPRO,
956 { STRING_COMMA_LEN ("pentiumiii"),PROCESSOR_PENTIUMPRO,
958 { STRING_COMMA_LEN ("pentium4"), PROCESSOR_PENTIUM4,
960 { STRING_COMMA_LEN ("prescott"), PROCESSOR_NOCONA,
962 { STRING_COMMA_LEN ("nocona"), PROCESSOR_NOCONA,
963 CPU_NOCONA_FLAGS, 0 },
964 { STRING_COMMA_LEN ("yonah"), PROCESSOR_CORE,
966 { STRING_COMMA_LEN ("core"), PROCESSOR_CORE,
968 { STRING_COMMA_LEN ("merom"), PROCESSOR_CORE2,
969 CPU_CORE2_FLAGS, 1 },
970 { STRING_COMMA_LEN ("core2"), PROCESSOR_CORE2,
971 CPU_CORE2_FLAGS, 0 },
972 { STRING_COMMA_LEN ("corei7"), PROCESSOR_COREI7,
973 CPU_COREI7_FLAGS, 0 },
974 { STRING_COMMA_LEN ("l1om"), PROCESSOR_L1OM,
976 { STRING_COMMA_LEN ("k1om"), PROCESSOR_K1OM,
978 { STRING_COMMA_LEN ("iamcu"), PROCESSOR_IAMCU,
979 CPU_IAMCU_FLAGS, 0 },
980 { STRING_COMMA_LEN ("k6"), PROCESSOR_K6,
982 { STRING_COMMA_LEN ("k6_2"), PROCESSOR_K6,
984 { STRING_COMMA_LEN ("athlon"), PROCESSOR_ATHLON,
985 CPU_ATHLON_FLAGS, 0 },
986 { STRING_COMMA_LEN ("sledgehammer"), PROCESSOR_K8,
988 { STRING_COMMA_LEN ("opteron"), PROCESSOR_K8,
990 { STRING_COMMA_LEN ("k8"), PROCESSOR_K8,
992 { STRING_COMMA_LEN ("amdfam10"), PROCESSOR_AMDFAM10,
993 CPU_AMDFAM10_FLAGS, 0 },
994 { STRING_COMMA_LEN ("bdver1"), PROCESSOR_BD,
995 CPU_BDVER1_FLAGS, 0 },
996 { STRING_COMMA_LEN ("bdver2"), PROCESSOR_BD,
997 CPU_BDVER2_FLAGS, 0 },
998 { STRING_COMMA_LEN ("bdver3"), PROCESSOR_BD,
999 CPU_BDVER3_FLAGS, 0 },
1000 { STRING_COMMA_LEN ("bdver4"), PROCESSOR_BD,
1001 CPU_BDVER4_FLAGS, 0 },
1002 { STRING_COMMA_LEN ("znver1"), PROCESSOR_ZNVER,
1003 CPU_ZNVER1_FLAGS, 0 },
1004 { STRING_COMMA_LEN ("znver2"), PROCESSOR_ZNVER,
1005 CPU_ZNVER2_FLAGS, 0 },
1006 { STRING_COMMA_LEN ("znver3"), PROCESSOR_ZNVER,
1007 CPU_ZNVER3_FLAGS, 0 },
1008 { STRING_COMMA_LEN ("btver1"), PROCESSOR_BT,
1009 CPU_BTVER1_FLAGS, 0 },
1010 { STRING_COMMA_LEN ("btver2"), PROCESSOR_BT,
1011 CPU_BTVER2_FLAGS, 0 },
1012 { STRING_COMMA_LEN (".8087"), PROCESSOR_UNKNOWN,
1013 CPU_8087_FLAGS, 0 },
1014 { STRING_COMMA_LEN (".287"), PROCESSOR_UNKNOWN,
1016 { STRING_COMMA_LEN (".387"), PROCESSOR_UNKNOWN,
1018 { STRING_COMMA_LEN (".687"), PROCESSOR_UNKNOWN,
1020 { STRING_COMMA_LEN (".cmov"), PROCESSOR_UNKNOWN,
1021 CPU_CMOV_FLAGS, 0 },
1022 { STRING_COMMA_LEN (".fxsr"), PROCESSOR_UNKNOWN,
1023 CPU_FXSR_FLAGS, 0 },
1024 { STRING_COMMA_LEN (".mmx"), PROCESSOR_UNKNOWN,
1026 { STRING_COMMA_LEN (".sse"), PROCESSOR_UNKNOWN,
1028 { STRING_COMMA_LEN (".sse2"), PROCESSOR_UNKNOWN,
1029 CPU_SSE2_FLAGS, 0 },
1030 { STRING_COMMA_LEN (".sse3"), PROCESSOR_UNKNOWN,
1031 CPU_SSE3_FLAGS, 0 },
1032 { STRING_COMMA_LEN (".sse4a"), PROCESSOR_UNKNOWN,
1033 CPU_SSE4A_FLAGS, 0 },
1034 { STRING_COMMA_LEN (".ssse3"), PROCESSOR_UNKNOWN,
1035 CPU_SSSE3_FLAGS, 0 },
1036 { STRING_COMMA_LEN (".sse4.1"), PROCESSOR_UNKNOWN,
1037 CPU_SSE4_1_FLAGS, 0 },
1038 { STRING_COMMA_LEN (".sse4.2"), PROCESSOR_UNKNOWN,
1039 CPU_SSE4_2_FLAGS, 0 },
1040 { STRING_COMMA_LEN (".sse4"), PROCESSOR_UNKNOWN,
1041 CPU_SSE4_2_FLAGS, 0 },
1042 { STRING_COMMA_LEN (".avx"), PROCESSOR_UNKNOWN,
1044 { STRING_COMMA_LEN (".avx2"), PROCESSOR_UNKNOWN,
1045 CPU_AVX2_FLAGS, 0 },
1046 { STRING_COMMA_LEN (".avx512f"), PROCESSOR_UNKNOWN,
1047 CPU_AVX512F_FLAGS, 0 },
1048 { STRING_COMMA_LEN (".avx512cd"), PROCESSOR_UNKNOWN,
1049 CPU_AVX512CD_FLAGS, 0 },
1050 { STRING_COMMA_LEN (".avx512er"), PROCESSOR_UNKNOWN,
1051 CPU_AVX512ER_FLAGS, 0 },
1052 { STRING_COMMA_LEN (".avx512pf"), PROCESSOR_UNKNOWN,
1053 CPU_AVX512PF_FLAGS, 0 },
1054 { STRING_COMMA_LEN (".avx512dq"), PROCESSOR_UNKNOWN,
1055 CPU_AVX512DQ_FLAGS, 0 },
1056 { STRING_COMMA_LEN (".avx512bw"), PROCESSOR_UNKNOWN,
1057 CPU_AVX512BW_FLAGS, 0 },
1058 { STRING_COMMA_LEN (".avx512vl"), PROCESSOR_UNKNOWN,
1059 CPU_AVX512VL_FLAGS, 0 },
1060 { STRING_COMMA_LEN (".vmx"), PROCESSOR_UNKNOWN,
1062 { STRING_COMMA_LEN (".vmfunc"), PROCESSOR_UNKNOWN,
1063 CPU_VMFUNC_FLAGS, 0 },
1064 { STRING_COMMA_LEN (".smx"), PROCESSOR_UNKNOWN,
1066 { STRING_COMMA_LEN (".xsave"), PROCESSOR_UNKNOWN,
1067 CPU_XSAVE_FLAGS, 0 },
1068 { STRING_COMMA_LEN (".xsaveopt"), PROCESSOR_UNKNOWN,
1069 CPU_XSAVEOPT_FLAGS, 0 },
1070 { STRING_COMMA_LEN (".xsavec"), PROCESSOR_UNKNOWN,
1071 CPU_XSAVEC_FLAGS, 0 },
1072 { STRING_COMMA_LEN (".xsaves"), PROCESSOR_UNKNOWN,
1073 CPU_XSAVES_FLAGS, 0 },
1074 { STRING_COMMA_LEN (".aes"), PROCESSOR_UNKNOWN,
1076 { STRING_COMMA_LEN (".pclmul"), PROCESSOR_UNKNOWN,
1077 CPU_PCLMUL_FLAGS, 0 },
1078 { STRING_COMMA_LEN (".clmul"), PROCESSOR_UNKNOWN,
1079 CPU_PCLMUL_FLAGS, 1 },
1080 { STRING_COMMA_LEN (".fsgsbase"), PROCESSOR_UNKNOWN,
1081 CPU_FSGSBASE_FLAGS, 0 },
1082 { STRING_COMMA_LEN (".rdrnd"), PROCESSOR_UNKNOWN,
1083 CPU_RDRND_FLAGS, 0 },
1084 { STRING_COMMA_LEN (".f16c"), PROCESSOR_UNKNOWN,
1085 CPU_F16C_FLAGS, 0 },
1086 { STRING_COMMA_LEN (".bmi2"), PROCESSOR_UNKNOWN,
1087 CPU_BMI2_FLAGS, 0 },
1088 { STRING_COMMA_LEN (".fma"), PROCESSOR_UNKNOWN,
1090 { STRING_COMMA_LEN (".fma4"), PROCESSOR_UNKNOWN,
1091 CPU_FMA4_FLAGS, 0 },
1092 { STRING_COMMA_LEN (".xop"), PROCESSOR_UNKNOWN,
1094 { STRING_COMMA_LEN (".lwp"), PROCESSOR_UNKNOWN,
1096 { STRING_COMMA_LEN (".movbe"), PROCESSOR_UNKNOWN,
1097 CPU_MOVBE_FLAGS, 0 },
1098 { STRING_COMMA_LEN (".cx16"), PROCESSOR_UNKNOWN,
1099 CPU_CX16_FLAGS, 0 },
1100 { STRING_COMMA_LEN (".ept"), PROCESSOR_UNKNOWN,
1102 { STRING_COMMA_LEN (".lzcnt"), PROCESSOR_UNKNOWN,
1103 CPU_LZCNT_FLAGS, 0 },
1104 { STRING_COMMA_LEN (".popcnt"), PROCESSOR_UNKNOWN,
1105 CPU_POPCNT_FLAGS, 0 },
1106 { STRING_COMMA_LEN (".hle"), PROCESSOR_UNKNOWN,
1108 { STRING_COMMA_LEN (".rtm"), PROCESSOR_UNKNOWN,
1110 { STRING_COMMA_LEN (".invpcid"), PROCESSOR_UNKNOWN,
1111 CPU_INVPCID_FLAGS, 0 },
1112 { STRING_COMMA_LEN (".clflush"), PROCESSOR_UNKNOWN,
1113 CPU_CLFLUSH_FLAGS, 0 },
1114 { STRING_COMMA_LEN (".nop"), PROCESSOR_UNKNOWN,
1116 { STRING_COMMA_LEN (".syscall"), PROCESSOR_UNKNOWN,
1117 CPU_SYSCALL_FLAGS, 0 },
1118 { STRING_COMMA_LEN (".rdtscp"), PROCESSOR_UNKNOWN,
1119 CPU_RDTSCP_FLAGS, 0 },
1120 { STRING_COMMA_LEN (".3dnow"), PROCESSOR_UNKNOWN,
1121 CPU_3DNOW_FLAGS, 0 },
1122 { STRING_COMMA_LEN (".3dnowa"), PROCESSOR_UNKNOWN,
1123 CPU_3DNOWA_FLAGS, 0 },
1124 { STRING_COMMA_LEN (".padlock"), PROCESSOR_UNKNOWN,
1125 CPU_PADLOCK_FLAGS, 0 },
1126 { STRING_COMMA_LEN (".pacifica"), PROCESSOR_UNKNOWN,
1127 CPU_SVME_FLAGS, 1 },
1128 { STRING_COMMA_LEN (".svme"), PROCESSOR_UNKNOWN,
1129 CPU_SVME_FLAGS, 0 },
1130 { STRING_COMMA_LEN (".sse4a"), PROCESSOR_UNKNOWN,
1131 CPU_SSE4A_FLAGS, 0 },
1132 { STRING_COMMA_LEN (".abm"), PROCESSOR_UNKNOWN,
1134 { STRING_COMMA_LEN (".bmi"), PROCESSOR_UNKNOWN,
1136 { STRING_COMMA_LEN (".tbm"), PROCESSOR_UNKNOWN,
1138 { STRING_COMMA_LEN (".adx"), PROCESSOR_UNKNOWN,
1140 { STRING_COMMA_LEN (".rdseed"), PROCESSOR_UNKNOWN,
1141 CPU_RDSEED_FLAGS, 0 },
1142 { STRING_COMMA_LEN (".prfchw"), PROCESSOR_UNKNOWN,
1143 CPU_PRFCHW_FLAGS, 0 },
1144 { STRING_COMMA_LEN (".smap"), PROCESSOR_UNKNOWN,
1145 CPU_SMAP_FLAGS, 0 },
1146 { STRING_COMMA_LEN (".mpx"), PROCESSOR_UNKNOWN,
1148 { STRING_COMMA_LEN (".sha"), PROCESSOR_UNKNOWN,
1150 { STRING_COMMA_LEN (".clflushopt"), PROCESSOR_UNKNOWN,
1151 CPU_CLFLUSHOPT_FLAGS, 0 },
1152 { STRING_COMMA_LEN (".prefetchwt1"), PROCESSOR_UNKNOWN,
1153 CPU_PREFETCHWT1_FLAGS, 0 },
1154 { STRING_COMMA_LEN (".se1"), PROCESSOR_UNKNOWN,
1156 { STRING_COMMA_LEN (".clwb"), PROCESSOR_UNKNOWN,
1157 CPU_CLWB_FLAGS, 0 },
1158 { STRING_COMMA_LEN (".avx512ifma"), PROCESSOR_UNKNOWN,
1159 CPU_AVX512IFMA_FLAGS, 0 },
1160 { STRING_COMMA_LEN (".avx512vbmi"), PROCESSOR_UNKNOWN,
1161 CPU_AVX512VBMI_FLAGS, 0 },
1162 { STRING_COMMA_LEN (".avx512_4fmaps"), PROCESSOR_UNKNOWN,
1163 CPU_AVX512_4FMAPS_FLAGS, 0 },
1164 { STRING_COMMA_LEN (".avx512_4vnniw"), PROCESSOR_UNKNOWN,
1165 CPU_AVX512_4VNNIW_FLAGS, 0 },
1166 { STRING_COMMA_LEN (".avx512_vpopcntdq"), PROCESSOR_UNKNOWN,
1167 CPU_AVX512_VPOPCNTDQ_FLAGS, 0 },
1168 { STRING_COMMA_LEN (".avx512_vbmi2"), PROCESSOR_UNKNOWN,
1169 CPU_AVX512_VBMI2_FLAGS, 0 },
1170 { STRING_COMMA_LEN (".avx512_vnni"), PROCESSOR_UNKNOWN,
1171 CPU_AVX512_VNNI_FLAGS, 0 },
1172 { STRING_COMMA_LEN (".avx512_bitalg"), PROCESSOR_UNKNOWN,
1173 CPU_AVX512_BITALG_FLAGS, 0 },
1174 { STRING_COMMA_LEN (".avx_vnni"), PROCESSOR_UNKNOWN,
1175 CPU_AVX_VNNI_FLAGS, 0 },
1176 { STRING_COMMA_LEN (".clzero"), PROCESSOR_UNKNOWN,
1177 CPU_CLZERO_FLAGS, 0 },
1178 { STRING_COMMA_LEN (".mwaitx"), PROCESSOR_UNKNOWN,
1179 CPU_MWAITX_FLAGS, 0 },
1180 { STRING_COMMA_LEN (".ospke"), PROCESSOR_UNKNOWN,
1181 CPU_OSPKE_FLAGS, 0 },
1182 { STRING_COMMA_LEN (".rdpid"), PROCESSOR_UNKNOWN,
1183 CPU_RDPID_FLAGS, 0 },
1184 { STRING_COMMA_LEN (".ptwrite"), PROCESSOR_UNKNOWN,
1185 CPU_PTWRITE_FLAGS, 0 },
1186 { STRING_COMMA_LEN (".ibt"), PROCESSOR_UNKNOWN,
1188 { STRING_COMMA_LEN (".shstk"), PROCESSOR_UNKNOWN,
1189 CPU_SHSTK_FLAGS, 0 },
1190 { STRING_COMMA_LEN (".gfni"), PROCESSOR_UNKNOWN,
1191 CPU_GFNI_FLAGS, 0 },
1192 { STRING_COMMA_LEN (".vaes"), PROCESSOR_UNKNOWN,
1193 CPU_VAES_FLAGS, 0 },
1194 { STRING_COMMA_LEN (".vpclmulqdq"), PROCESSOR_UNKNOWN,
1195 CPU_VPCLMULQDQ_FLAGS, 0 },
1196 { STRING_COMMA_LEN (".wbnoinvd"), PROCESSOR_UNKNOWN,
1197 CPU_WBNOINVD_FLAGS, 0 },
1198 { STRING_COMMA_LEN (".pconfig"), PROCESSOR_UNKNOWN,
1199 CPU_PCONFIG_FLAGS, 0 },
1200 { STRING_COMMA_LEN (".waitpkg"), PROCESSOR_UNKNOWN,
1201 CPU_WAITPKG_FLAGS, 0 },
1202 { STRING_COMMA_LEN (".cldemote"), PROCESSOR_UNKNOWN,
1203 CPU_CLDEMOTE_FLAGS, 0 },
1204 { STRING_COMMA_LEN (".amx_int8"), PROCESSOR_UNKNOWN,
1205 CPU_AMX_INT8_FLAGS, 0 },
1206 { STRING_COMMA_LEN (".amx_bf16"), PROCESSOR_UNKNOWN,
1207 CPU_AMX_BF16_FLAGS, 0 },
1208 { STRING_COMMA_LEN (".amx_tile"), PROCESSOR_UNKNOWN,
1209 CPU_AMX_TILE_FLAGS, 0 },
1210 { STRING_COMMA_LEN (".movdiri"), PROCESSOR_UNKNOWN,
1211 CPU_MOVDIRI_FLAGS, 0 },
1212 { STRING_COMMA_LEN (".movdir64b"), PROCESSOR_UNKNOWN,
1213 CPU_MOVDIR64B_FLAGS, 0 },
1214 { STRING_COMMA_LEN (".avx512_bf16"), PROCESSOR_UNKNOWN,
1215 CPU_AVX512_BF16_FLAGS, 0 },
1216 { STRING_COMMA_LEN (".avx512_vp2intersect"), PROCESSOR_UNKNOWN,
1217 CPU_AVX512_VP2INTERSECT_FLAGS, 0 },
1218 { STRING_COMMA_LEN (".tdx"), PROCESSOR_UNKNOWN,
1220 { STRING_COMMA_LEN (".enqcmd"), PROCESSOR_UNKNOWN,
1221 CPU_ENQCMD_FLAGS, 0 },
1222 { STRING_COMMA_LEN (".serialize"), PROCESSOR_UNKNOWN,
1223 CPU_SERIALIZE_FLAGS, 0 },
1224 { STRING_COMMA_LEN (".rdpru"), PROCESSOR_UNKNOWN,
1225 CPU_RDPRU_FLAGS, 0 },
1226 { STRING_COMMA_LEN (".mcommit"), PROCESSOR_UNKNOWN,
1227 CPU_MCOMMIT_FLAGS, 0 },
1228 { STRING_COMMA_LEN (".sev_es"), PROCESSOR_UNKNOWN,
1229 CPU_SEV_ES_FLAGS, 0 },
1230 { STRING_COMMA_LEN (".tsxldtrk"), PROCESSOR_UNKNOWN,
1231 CPU_TSXLDTRK_FLAGS, 0 },
1232 { STRING_COMMA_LEN (".kl"), PROCESSOR_UNKNOWN,
1234 { STRING_COMMA_LEN (".widekl"), PROCESSOR_UNKNOWN,
1235 CPU_WIDEKL_FLAGS, 0 },
1236 { STRING_COMMA_LEN (".uintr"), PROCESSOR_UNKNOWN,
1237 CPU_UINTR_FLAGS, 0 },
1238 { STRING_COMMA_LEN (".hreset"), PROCESSOR_UNKNOWN,
1239 CPU_HRESET_FLAGS, 0 },
1242 static const noarch_entry cpu_noarch[] =
1244 { STRING_COMMA_LEN ("no87"), CPU_ANY_X87_FLAGS },
1245 { STRING_COMMA_LEN ("no287"), CPU_ANY_287_FLAGS },
1246 { STRING_COMMA_LEN ("no387"), CPU_ANY_387_FLAGS },
1247 { STRING_COMMA_LEN ("no687"), CPU_ANY_687_FLAGS },
1248 { STRING_COMMA_LEN ("nocmov"), CPU_ANY_CMOV_FLAGS },
1249 { STRING_COMMA_LEN ("nofxsr"), CPU_ANY_FXSR_FLAGS },
1250 { STRING_COMMA_LEN ("nommx"), CPU_ANY_MMX_FLAGS },
1251 { STRING_COMMA_LEN ("nosse"), CPU_ANY_SSE_FLAGS },
1252 { STRING_COMMA_LEN ("nosse2"), CPU_ANY_SSE2_FLAGS },
1253 { STRING_COMMA_LEN ("nosse3"), CPU_ANY_SSE3_FLAGS },
1254 { STRING_COMMA_LEN ("nosse4a"), CPU_ANY_SSE4A_FLAGS },
1255 { STRING_COMMA_LEN ("nossse3"), CPU_ANY_SSSE3_FLAGS },
1256 { STRING_COMMA_LEN ("nosse4.1"), CPU_ANY_SSE4_1_FLAGS },
1257 { STRING_COMMA_LEN ("nosse4.2"), CPU_ANY_SSE4_2_FLAGS },
1258 { STRING_COMMA_LEN ("nosse4"), CPU_ANY_SSE4_1_FLAGS },
1259 { STRING_COMMA_LEN ("noavx"), CPU_ANY_AVX_FLAGS },
1260 { STRING_COMMA_LEN ("noavx2"), CPU_ANY_AVX2_FLAGS },
1261 { STRING_COMMA_LEN ("noavx512f"), CPU_ANY_AVX512F_FLAGS },
1262 { STRING_COMMA_LEN ("noavx512cd"), CPU_ANY_AVX512CD_FLAGS },
1263 { STRING_COMMA_LEN ("noavx512er"), CPU_ANY_AVX512ER_FLAGS },
1264 { STRING_COMMA_LEN ("noavx512pf"), CPU_ANY_AVX512PF_FLAGS },
1265 { STRING_COMMA_LEN ("noavx512dq"), CPU_ANY_AVX512DQ_FLAGS },
1266 { STRING_COMMA_LEN ("noavx512bw"), CPU_ANY_AVX512BW_FLAGS },
1267 { STRING_COMMA_LEN ("noavx512vl"), CPU_ANY_AVX512VL_FLAGS },
1268 { STRING_COMMA_LEN ("noavx512ifma"), CPU_ANY_AVX512IFMA_FLAGS },
1269 { STRING_COMMA_LEN ("noavx512vbmi"), CPU_ANY_AVX512VBMI_FLAGS },
1270 { STRING_COMMA_LEN ("noavx512_4fmaps"), CPU_ANY_AVX512_4FMAPS_FLAGS },
1271 { STRING_COMMA_LEN ("noavx512_4vnniw"), CPU_ANY_AVX512_4VNNIW_FLAGS },
1272 { STRING_COMMA_LEN ("noavx512_vpopcntdq"), CPU_ANY_AVX512_VPOPCNTDQ_FLAGS },
1273 { STRING_COMMA_LEN ("noavx512_vbmi2"), CPU_ANY_AVX512_VBMI2_FLAGS },
1274 { STRING_COMMA_LEN ("noavx512_vnni"), CPU_ANY_AVX512_VNNI_FLAGS },
1275 { STRING_COMMA_LEN ("noavx512_bitalg"), CPU_ANY_AVX512_BITALG_FLAGS },
1276 { STRING_COMMA_LEN ("noavx_vnni"), CPU_ANY_AVX_VNNI_FLAGS },
1277 { STRING_COMMA_LEN ("noibt"), CPU_ANY_IBT_FLAGS },
1278 { STRING_COMMA_LEN ("noshstk"), CPU_ANY_SHSTK_FLAGS },
1279 { STRING_COMMA_LEN ("noamx_int8"), CPU_ANY_AMX_INT8_FLAGS },
1280 { STRING_COMMA_LEN ("noamx_bf16"), CPU_ANY_AMX_BF16_FLAGS },
1281 { STRING_COMMA_LEN ("noamx_tile"), CPU_ANY_AMX_TILE_FLAGS },
1282 { STRING_COMMA_LEN ("nomovdiri"), CPU_ANY_MOVDIRI_FLAGS },
1283 { STRING_COMMA_LEN ("nomovdir64b"), CPU_ANY_MOVDIR64B_FLAGS },
1284 { STRING_COMMA_LEN ("noavx512_bf16"), CPU_ANY_AVX512_BF16_FLAGS },
1285 { STRING_COMMA_LEN ("noavx512_vp2intersect"),
1286 CPU_ANY_AVX512_VP2INTERSECT_FLAGS },
1287 { STRING_COMMA_LEN ("notdx"), CPU_ANY_TDX_FLAGS },
1288 { STRING_COMMA_LEN ("noenqcmd"), CPU_ANY_ENQCMD_FLAGS },
1289 { STRING_COMMA_LEN ("noserialize"), CPU_ANY_SERIALIZE_FLAGS },
1290 { STRING_COMMA_LEN ("notsxldtrk"), CPU_ANY_TSXLDTRK_FLAGS },
1291 { STRING_COMMA_LEN ("nokl"), CPU_ANY_KL_FLAGS },
1292 { STRING_COMMA_LEN ("nowidekl"), CPU_ANY_WIDEKL_FLAGS },
1293 { STRING_COMMA_LEN ("nouintr"), CPU_ANY_UINTR_FLAGS },
1294 { STRING_COMMA_LEN ("nohreset"), CPU_ANY_HRESET_FLAGS },
1298 /* Like s_lcomm_internal in gas/read.c but the alignment string
1299 is allowed to be optional. */
1302 pe_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
1309 && *input_line_pointer == ',')
1311 align = parse_align (needs_align - 1);
1313 if (align == (addressT) -1)
1328 bss_alloc (symbolP, size, align);
1333 pe_lcomm (int needs_align)
1335 s_comm_internal (needs_align * 2, pe_lcomm_internal);
1339 const pseudo_typeS md_pseudo_table[] =
1341 #if !defined(OBJ_AOUT) && !defined(USE_ALIGN_PTWO)
1342 {"align", s_align_bytes, 0},
1344 {"align", s_align_ptwo, 0},
1346 {"arch", set_cpu_arch, 0},
1350 {"lcomm", pe_lcomm, 1},
1352 {"ffloat", float_cons, 'f'},
1353 {"dfloat", float_cons, 'd'},
1354 {"tfloat", float_cons, 'x'},
1356 {"slong", signed_cons, 4},
1357 {"noopt", s_ignore, 0},
1358 {"optim", s_ignore, 0},
1359 {"code16gcc", set_16bit_gcc_code_flag, CODE_16BIT},
1360 {"code16", set_code_flag, CODE_16BIT},
1361 {"code32", set_code_flag, CODE_32BIT},
1363 {"code64", set_code_flag, CODE_64BIT},
1365 {"intel_syntax", set_intel_syntax, 1},
1366 {"att_syntax", set_intel_syntax, 0},
1367 {"intel_mnemonic", set_intel_mnemonic, 1},
1368 {"att_mnemonic", set_intel_mnemonic, 0},
1369 {"allow_index_reg", set_allow_index_reg, 1},
1370 {"disallow_index_reg", set_allow_index_reg, 0},
1371 {"sse_check", set_check, 0},
1372 {"operand_check", set_check, 1},
1373 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
1374 {"largecomm", handle_large_common, 0},
1376 {"file", dwarf2_directive_file, 0},
1377 {"loc", dwarf2_directive_loc, 0},
1378 {"loc_mark_labels", dwarf2_directive_loc_mark_labels, 0},
1381 {"secrel32", pe_directive_secrel, 0},
1386 /* For interface with expression (). */
1387 extern char *input_line_pointer;
1389 /* Hash table for instruction mnemonic lookup. */
1390 static htab_t op_hash;
1392 /* Hash table for register lookup. */
1393 static htab_t reg_hash;
1395 /* Various efficient no-op patterns for aligning code labels.
1396 Note: Don't try to assemble the instructions in the comments.
1397 0L and 0w are not legal. */
1398 static const unsigned char f32_1[] =
1400 static const unsigned char f32_2[] =
1401 {0x66,0x90}; /* xchg %ax,%ax */
1402 static const unsigned char f32_3[] =
1403 {0x8d,0x76,0x00}; /* leal 0(%esi),%esi */
1404 static const unsigned char f32_4[] =
1405 {0x8d,0x74,0x26,0x00}; /* leal 0(%esi,1),%esi */
1406 static const unsigned char f32_6[] =
1407 {0x8d,0xb6,0x00,0x00,0x00,0x00}; /* leal 0L(%esi),%esi */
1408 static const unsigned char f32_7[] =
1409 {0x8d,0xb4,0x26,0x00,0x00,0x00,0x00}; /* leal 0L(%esi,1),%esi */
1410 static const unsigned char f16_3[] =
1411 {0x8d,0x74,0x00}; /* lea 0(%si),%si */
1412 static const unsigned char f16_4[] =
1413 {0x8d,0xb4,0x00,0x00}; /* lea 0W(%si),%si */
1414 static const unsigned char jump_disp8[] =
1415 {0xeb}; /* jmp disp8 */
1416 static const unsigned char jump32_disp32[] =
1417 {0xe9}; /* jmp disp32 */
1418 static const unsigned char jump16_disp32[] =
1419 {0x66,0xe9}; /* jmp disp32 */
1420 /* 32-bit NOPs patterns. */
1421 static const unsigned char *const f32_patt[] = {
1422 f32_1, f32_2, f32_3, f32_4, NULL, f32_6, f32_7
1424 /* 16-bit NOPs patterns. */
1425 static const unsigned char *const f16_patt[] = {
1426 f32_1, f32_2, f16_3, f16_4
1428 /* nopl (%[re]ax) */
1429 static const unsigned char alt_3[] =
1431 /* nopl 0(%[re]ax) */
1432 static const unsigned char alt_4[] =
1433 {0x0f,0x1f,0x40,0x00};
1434 /* nopl 0(%[re]ax,%[re]ax,1) */
1435 static const unsigned char alt_5[] =
1436 {0x0f,0x1f,0x44,0x00,0x00};
1437 /* nopw 0(%[re]ax,%[re]ax,1) */
1438 static const unsigned char alt_6[] =
1439 {0x66,0x0f,0x1f,0x44,0x00,0x00};
1440 /* nopl 0L(%[re]ax) */
1441 static const unsigned char alt_7[] =
1442 {0x0f,0x1f,0x80,0x00,0x00,0x00,0x00};
1443 /* nopl 0L(%[re]ax,%[re]ax,1) */
1444 static const unsigned char alt_8[] =
1445 {0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
1446 /* nopw 0L(%[re]ax,%[re]ax,1) */
1447 static const unsigned char alt_9[] =
1448 {0x66,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
1449 /* nopw %cs:0L(%[re]ax,%[re]ax,1) */
1450 static const unsigned char alt_10[] =
1451 {0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
1452 /* data16 nopw %cs:0L(%eax,%eax,1) */
1453 static const unsigned char alt_11[] =
1454 {0x66,0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
1455 /* 32-bit and 64-bit NOPs patterns. */
1456 static const unsigned char *const alt_patt[] = {
1457 f32_1, f32_2, alt_3, alt_4, alt_5, alt_6, alt_7, alt_8,
1458 alt_9, alt_10, alt_11
1461 /* Genenerate COUNT bytes of NOPs to WHERE from PATT with the maximum
1462 size of a single NOP instruction MAX_SINGLE_NOP_SIZE. */
1465 i386_output_nops (char *where, const unsigned char *const *patt,
1466 int count, int max_single_nop_size)
1469 /* Place the longer NOP first. */
1472 const unsigned char *nops;
1474 if (max_single_nop_size < 1)
1476 as_fatal (_("i386_output_nops called to generate nops of at most %d bytes!"),
1477 max_single_nop_size);
1481 nops = patt[max_single_nop_size - 1];
1483 /* Use the smaller one if the requsted one isn't available. */
1486 max_single_nop_size--;
1487 nops = patt[max_single_nop_size - 1];
1490 last = count % max_single_nop_size;
1493 for (offset = 0; offset < count; offset += max_single_nop_size)
1494 memcpy (where + offset, nops, max_single_nop_size);
1498 nops = patt[last - 1];
1501 /* Use the smaller one plus one-byte NOP if the needed one
1504 nops = patt[last - 1];
1505 memcpy (where + offset, nops, last);
1506 where[offset + last] = *patt[0];
1509 memcpy (where + offset, nops, last);
1514 fits_in_imm7 (offsetT num)
1516 return (num & 0x7f) == num;
1520 fits_in_imm31 (offsetT num)
1522 return (num & 0x7fffffff) == num;
1525 /* Genenerate COUNT bytes of NOPs to WHERE with the maximum size of a
1526 single NOP instruction LIMIT. */
1529 i386_generate_nops (fragS *fragP, char *where, offsetT count, int limit)
1531 const unsigned char *const *patt = NULL;
1532 int max_single_nop_size;
1533 /* Maximum number of NOPs before switching to jump over NOPs. */
1534 int max_number_of_nops;
1536 switch (fragP->fr_type)
1541 case rs_machine_dependent:
1542 /* Allow NOP padding for jumps and calls. */
1543 if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PADDING
1544 || TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == FUSED_JCC_PADDING)
1551 /* We need to decide which NOP sequence to use for 32bit and
1552 64bit. When -mtune= is used:
1554 1. For PROCESSOR_I386, PROCESSOR_I486, PROCESSOR_PENTIUM and
1555 PROCESSOR_GENERIC32, f32_patt will be used.
1556 2. For the rest, alt_patt will be used.
1558 When -mtune= isn't used, alt_patt will be used if
1559 cpu_arch_isa_flags has CpuNop. Otherwise, f32_patt will
1562 When -march= or .arch is used, we can't use anything beyond
1563 cpu_arch_isa_flags. */
1565 if (flag_code == CODE_16BIT)
1568 max_single_nop_size = sizeof (f16_patt) / sizeof (f16_patt[0]);
1569 /* Limit number of NOPs to 2 in 16-bit mode. */
1570 max_number_of_nops = 2;
1574 if (fragP->tc_frag_data.isa == PROCESSOR_UNKNOWN)
1576 /* PROCESSOR_UNKNOWN means that all ISAs may be used. */
1577 switch (cpu_arch_tune)
1579 case PROCESSOR_UNKNOWN:
1580 /* We use cpu_arch_isa_flags to check if we SHOULD
1581 optimize with nops. */
1582 if (fragP->tc_frag_data.isa_flags.bitfield.cpunop)
1587 case PROCESSOR_PENTIUM4:
1588 case PROCESSOR_NOCONA:
1589 case PROCESSOR_CORE:
1590 case PROCESSOR_CORE2:
1591 case PROCESSOR_COREI7:
1592 case PROCESSOR_L1OM:
1593 case PROCESSOR_K1OM:
1594 case PROCESSOR_GENERIC64:
1596 case PROCESSOR_ATHLON:
1598 case PROCESSOR_AMDFAM10:
1600 case PROCESSOR_ZNVER:
1604 case PROCESSOR_I386:
1605 case PROCESSOR_I486:
1606 case PROCESSOR_PENTIUM:
1607 case PROCESSOR_PENTIUMPRO:
1608 case PROCESSOR_IAMCU:
1609 case PROCESSOR_GENERIC32:
1616 switch (fragP->tc_frag_data.tune)
1618 case PROCESSOR_UNKNOWN:
1619 /* When cpu_arch_isa is set, cpu_arch_tune shouldn't be
1620 PROCESSOR_UNKNOWN. */
1624 case PROCESSOR_I386:
1625 case PROCESSOR_I486:
1626 case PROCESSOR_PENTIUM:
1627 case PROCESSOR_IAMCU:
1629 case PROCESSOR_ATHLON:
1631 case PROCESSOR_AMDFAM10:
1633 case PROCESSOR_ZNVER:
1635 case PROCESSOR_GENERIC32:
1636 /* We use cpu_arch_isa_flags to check if we CAN optimize
1638 if (fragP->tc_frag_data.isa_flags.bitfield.cpunop)
1643 case PROCESSOR_PENTIUMPRO:
1644 case PROCESSOR_PENTIUM4:
1645 case PROCESSOR_NOCONA:
1646 case PROCESSOR_CORE:
1647 case PROCESSOR_CORE2:
1648 case PROCESSOR_COREI7:
1649 case PROCESSOR_L1OM:
1650 case PROCESSOR_K1OM:
1651 if (fragP->tc_frag_data.isa_flags.bitfield.cpunop)
1656 case PROCESSOR_GENERIC64:
1662 if (patt == f32_patt)
1664 max_single_nop_size = sizeof (f32_patt) / sizeof (f32_patt[0]);
1665 /* Limit number of NOPs to 2 for older processors. */
1666 max_number_of_nops = 2;
1670 max_single_nop_size = sizeof (alt_patt) / sizeof (alt_patt[0]);
1671 /* Limit number of NOPs to 7 for newer processors. */
1672 max_number_of_nops = 7;
1677 limit = max_single_nop_size;
1679 if (fragP->fr_type == rs_fill_nop)
1681 /* Output NOPs for .nop directive. */
1682 if (limit > max_single_nop_size)
1684 as_bad_where (fragP->fr_file, fragP->fr_line,
1685 _("invalid single nop size: %d "
1686 "(expect within [0, %d])"),
1687 limit, max_single_nop_size);
1691 else if (fragP->fr_type != rs_machine_dependent)
1692 fragP->fr_var = count;
1694 if ((count / max_single_nop_size) > max_number_of_nops)
1696 /* Generate jump over NOPs. */
1697 offsetT disp = count - 2;
1698 if (fits_in_imm7 (disp))
1700 /* Use "jmp disp8" if possible. */
1702 where[0] = jump_disp8[0];
1708 unsigned int size_of_jump;
1710 if (flag_code == CODE_16BIT)
1712 where[0] = jump16_disp32[0];
1713 where[1] = jump16_disp32[1];
1718 where[0] = jump32_disp32[0];
1722 count -= size_of_jump + 4;
1723 if (!fits_in_imm31 (count))
1725 as_bad_where (fragP->fr_file, fragP->fr_line,
1726 _("jump over nop padding out of range"));
1730 md_number_to_chars (where + size_of_jump, count, 4);
1731 where += size_of_jump + 4;
1735 /* Generate multiple NOPs. */
1736 i386_output_nops (where, patt, count, limit);
1740 operand_type_all_zero (const union i386_operand_type *x)
1742 switch (ARRAY_SIZE(x->array))
1753 return !x->array[0];
1760 operand_type_set (union i386_operand_type *x, unsigned int v)
1762 switch (ARRAY_SIZE(x->array))
1778 x->bitfield.class = ClassNone;
1779 x->bitfield.instance = InstanceNone;
1783 operand_type_equal (const union i386_operand_type *x,
1784 const union i386_operand_type *y)
1786 switch (ARRAY_SIZE(x->array))
1789 if (x->array[2] != y->array[2])
1793 if (x->array[1] != y->array[1])
1797 return x->array[0] == y->array[0];
1805 cpu_flags_all_zero (const union i386_cpu_flags *x)
1807 switch (ARRAY_SIZE(x->array))
1822 return !x->array[0];
1829 cpu_flags_equal (const union i386_cpu_flags *x,
1830 const union i386_cpu_flags *y)
1832 switch (ARRAY_SIZE(x->array))
1835 if (x->array[3] != y->array[3])
1839 if (x->array[2] != y->array[2])
1843 if (x->array[1] != y->array[1])
1847 return x->array[0] == y->array[0];
1855 cpu_flags_check_cpu64 (i386_cpu_flags f)
1857 return !((flag_code == CODE_64BIT && f.bitfield.cpuno64)
1858 || (flag_code != CODE_64BIT && f.bitfield.cpu64));
1861 static INLINE i386_cpu_flags
1862 cpu_flags_and (i386_cpu_flags x, i386_cpu_flags y)
1864 switch (ARRAY_SIZE (x.array))
1867 x.array [3] &= y.array [3];
1870 x.array [2] &= y.array [2];
1873 x.array [1] &= y.array [1];
1876 x.array [0] &= y.array [0];
1884 static INLINE i386_cpu_flags
1885 cpu_flags_or (i386_cpu_flags x, i386_cpu_flags y)
1887 switch (ARRAY_SIZE (x.array))
1890 x.array [3] |= y.array [3];
1893 x.array [2] |= y.array [2];
1896 x.array [1] |= y.array [1];
1899 x.array [0] |= y.array [0];
1907 static INLINE i386_cpu_flags
1908 cpu_flags_and_not (i386_cpu_flags x, i386_cpu_flags y)
1910 switch (ARRAY_SIZE (x.array))
1913 x.array [3] &= ~y.array [3];
1916 x.array [2] &= ~y.array [2];
1919 x.array [1] &= ~y.array [1];
1922 x.array [0] &= ~y.array [0];
1930 static const i386_cpu_flags avx512 = CPU_ANY_AVX512F_FLAGS;
1932 #define CPU_FLAGS_ARCH_MATCH 0x1
1933 #define CPU_FLAGS_64BIT_MATCH 0x2
1935 #define CPU_FLAGS_PERFECT_MATCH \
1936 (CPU_FLAGS_ARCH_MATCH | CPU_FLAGS_64BIT_MATCH)
1938 /* Return CPU flags match bits. */
1941 cpu_flags_match (const insn_template *t)
1943 i386_cpu_flags x = t->cpu_flags;
1944 int match = cpu_flags_check_cpu64 (x) ? CPU_FLAGS_64BIT_MATCH : 0;
1946 x.bitfield.cpu64 = 0;
1947 x.bitfield.cpuno64 = 0;
1949 if (cpu_flags_all_zero (&x))
1951 /* This instruction is available on all archs. */
1952 match |= CPU_FLAGS_ARCH_MATCH;
1956 /* This instruction is available only on some archs. */
1957 i386_cpu_flags cpu = cpu_arch_flags;
1959 /* AVX512VL is no standalone feature - match it and then strip it. */
1960 if (x.bitfield.cpuavx512vl && !cpu.bitfield.cpuavx512vl)
1962 x.bitfield.cpuavx512vl = 0;
1964 cpu = cpu_flags_and (x, cpu);
1965 if (!cpu_flags_all_zero (&cpu))
1967 if (x.bitfield.cpuavx)
1969 /* We need to check a few extra flags with AVX. */
1970 if (cpu.bitfield.cpuavx
1971 && (!t->opcode_modifier.sse2avx
1972 || (sse2avx && !i.prefix[DATA_PREFIX]))
1973 && (!x.bitfield.cpuaes || cpu.bitfield.cpuaes)
1974 && (!x.bitfield.cpugfni || cpu.bitfield.cpugfni)
1975 && (!x.bitfield.cpupclmul || cpu.bitfield.cpupclmul))
1976 match |= CPU_FLAGS_ARCH_MATCH;
1978 else if (x.bitfield.cpuavx512f)
1980 /* We need to check a few extra flags with AVX512F. */
1981 if (cpu.bitfield.cpuavx512f
1982 && (!x.bitfield.cpugfni || cpu.bitfield.cpugfni)
1983 && (!x.bitfield.cpuvaes || cpu.bitfield.cpuvaes)
1984 && (!x.bitfield.cpuvpclmulqdq || cpu.bitfield.cpuvpclmulqdq))
1985 match |= CPU_FLAGS_ARCH_MATCH;
1988 match |= CPU_FLAGS_ARCH_MATCH;
1994 static INLINE i386_operand_type
1995 operand_type_and (i386_operand_type x, i386_operand_type y)
1997 if (x.bitfield.class != y.bitfield.class)
1998 x.bitfield.class = ClassNone;
1999 if (x.bitfield.instance != y.bitfield.instance)
2000 x.bitfield.instance = InstanceNone;
2002 switch (ARRAY_SIZE (x.array))
2005 x.array [2] &= y.array [2];
2008 x.array [1] &= y.array [1];
2011 x.array [0] &= y.array [0];
2019 static INLINE i386_operand_type
2020 operand_type_and_not (i386_operand_type x, i386_operand_type y)
2022 gas_assert (y.bitfield.class == ClassNone);
2023 gas_assert (y.bitfield.instance == InstanceNone);
2025 switch (ARRAY_SIZE (x.array))
2028 x.array [2] &= ~y.array [2];
2031 x.array [1] &= ~y.array [1];
2034 x.array [0] &= ~y.array [0];
2042 static INLINE i386_operand_type
2043 operand_type_or (i386_operand_type x, i386_operand_type y)
2045 gas_assert (x.bitfield.class == ClassNone ||
2046 y.bitfield.class == ClassNone ||
2047 x.bitfield.class == y.bitfield.class);
2048 gas_assert (x.bitfield.instance == InstanceNone ||
2049 y.bitfield.instance == InstanceNone ||
2050 x.bitfield.instance == y.bitfield.instance);
2052 switch (ARRAY_SIZE (x.array))
2055 x.array [2] |= y.array [2];
2058 x.array [1] |= y.array [1];
2061 x.array [0] |= y.array [0];
2069 static INLINE i386_operand_type
2070 operand_type_xor (i386_operand_type x, i386_operand_type y)
2072 gas_assert (y.bitfield.class == ClassNone);
2073 gas_assert (y.bitfield.instance == InstanceNone);
2075 switch (ARRAY_SIZE (x.array))
2078 x.array [2] ^= y.array [2];
2081 x.array [1] ^= y.array [1];
2084 x.array [0] ^= y.array [0];
2092 static const i386_operand_type disp16 = OPERAND_TYPE_DISP16;
2093 static const i386_operand_type disp32 = OPERAND_TYPE_DISP32;
2094 static const i386_operand_type disp32s = OPERAND_TYPE_DISP32S;
2095 static const i386_operand_type disp16_32 = OPERAND_TYPE_DISP16_32;
2096 static const i386_operand_type anydisp = OPERAND_TYPE_ANYDISP;
2097 static const i386_operand_type anyimm = OPERAND_TYPE_ANYIMM;
2098 static const i386_operand_type regxmm = OPERAND_TYPE_REGXMM;
2099 static const i386_operand_type regmask = OPERAND_TYPE_REGMASK;
2100 static const i386_operand_type imm8 = OPERAND_TYPE_IMM8;
2101 static const i386_operand_type imm8s = OPERAND_TYPE_IMM8S;
2102 static const i386_operand_type imm16 = OPERAND_TYPE_IMM16;
2103 static const i386_operand_type imm32 = OPERAND_TYPE_IMM32;
2104 static const i386_operand_type imm32s = OPERAND_TYPE_IMM32S;
2105 static const i386_operand_type imm64 = OPERAND_TYPE_IMM64;
2106 static const i386_operand_type imm16_32 = OPERAND_TYPE_IMM16_32;
2107 static const i386_operand_type imm16_32s = OPERAND_TYPE_IMM16_32S;
2108 static const i386_operand_type imm16_32_32s = OPERAND_TYPE_IMM16_32_32S;
2119 operand_type_check (i386_operand_type t, enum operand_type c)
2124 return t.bitfield.class == Reg;
2127 return (t.bitfield.imm8
2131 || t.bitfield.imm32s
2132 || t.bitfield.imm64);
2135 return (t.bitfield.disp8
2136 || t.bitfield.disp16
2137 || t.bitfield.disp32
2138 || t.bitfield.disp32s
2139 || t.bitfield.disp64);
2142 return (t.bitfield.disp8
2143 || t.bitfield.disp16
2144 || t.bitfield.disp32
2145 || t.bitfield.disp32s
2146 || t.bitfield.disp64
2147 || t.bitfield.baseindex);
2156 /* Return 1 if there is no conflict in 8bit/16bit/32bit/64bit/80bit size
2157 between operand GIVEN and opeand WANTED for instruction template T. */
2160 match_operand_size (const insn_template *t, unsigned int wanted,
2163 return !((i.types[given].bitfield.byte
2164 && !t->operand_types[wanted].bitfield.byte)
2165 || (i.types[given].bitfield.word
2166 && !t->operand_types[wanted].bitfield.word)
2167 || (i.types[given].bitfield.dword
2168 && !t->operand_types[wanted].bitfield.dword)
2169 || (i.types[given].bitfield.qword
2170 && !t->operand_types[wanted].bitfield.qword)
2171 || (i.types[given].bitfield.tbyte
2172 && !t->operand_types[wanted].bitfield.tbyte));
2175 /* Return 1 if there is no conflict in SIMD register between operand
2176 GIVEN and opeand WANTED for instruction template T. */
2179 match_simd_size (const insn_template *t, unsigned int wanted,
2182 return !((i.types[given].bitfield.xmmword
2183 && !t->operand_types[wanted].bitfield.xmmword)
2184 || (i.types[given].bitfield.ymmword
2185 && !t->operand_types[wanted].bitfield.ymmword)
2186 || (i.types[given].bitfield.zmmword
2187 && !t->operand_types[wanted].bitfield.zmmword)
2188 || (i.types[given].bitfield.tmmword
2189 && !t->operand_types[wanted].bitfield.tmmword));
2192 /* Return 1 if there is no conflict in any size between operand GIVEN
2193 and opeand WANTED for instruction template T. */
2196 match_mem_size (const insn_template *t, unsigned int wanted,
2199 return (match_operand_size (t, wanted, given)
2200 && !((i.types[given].bitfield.unspecified
2201 && !i.broadcast.type
2202 && !t->operand_types[wanted].bitfield.unspecified)
2203 || (i.types[given].bitfield.fword
2204 && !t->operand_types[wanted].bitfield.fword)
2205 /* For scalar opcode templates to allow register and memory
2206 operands at the same time, some special casing is needed
2207 here. Also for v{,p}broadcast*, {,v}pmov{s,z}*, and
2208 down-conversion vpmov*. */
2209 || ((t->operand_types[wanted].bitfield.class == RegSIMD
2210 && t->operand_types[wanted].bitfield.byte
2211 + t->operand_types[wanted].bitfield.word
2212 + t->operand_types[wanted].bitfield.dword
2213 + t->operand_types[wanted].bitfield.qword
2214 > !!t->opcode_modifier.broadcast)
2215 ? (i.types[given].bitfield.xmmword
2216 || i.types[given].bitfield.ymmword
2217 || i.types[given].bitfield.zmmword)
2218 : !match_simd_size(t, wanted, given))));
2221 /* Return value has MATCH_STRAIGHT set if there is no size conflict on any
2222 operands for instruction template T, and it has MATCH_REVERSE set if there
2223 is no size conflict on any operands for the template with operands reversed
2224 (and the template allows for reversing in the first place). */
2226 #define MATCH_STRAIGHT 1
2227 #define MATCH_REVERSE 2
2229 static INLINE unsigned int
2230 operand_size_match (const insn_template *t)
2232 unsigned int j, match = MATCH_STRAIGHT;
2234 /* Don't check non-absolute jump instructions. */
2235 if (t->opcode_modifier.jump
2236 && t->opcode_modifier.jump != JUMP_ABSOLUTE)
2239 /* Check memory and accumulator operand size. */
2240 for (j = 0; j < i.operands; j++)
2242 if (i.types[j].bitfield.class != Reg
2243 && i.types[j].bitfield.class != RegSIMD
2244 && t->opcode_modifier.anysize)
2247 if (t->operand_types[j].bitfield.class == Reg
2248 && !match_operand_size (t, j, j))
2254 if (t->operand_types[j].bitfield.class == RegSIMD
2255 && !match_simd_size (t, j, j))
2261 if (t->operand_types[j].bitfield.instance == Accum
2262 && (!match_operand_size (t, j, j) || !match_simd_size (t, j, j)))
2268 if ((i.flags[j] & Operand_Mem) && !match_mem_size (t, j, j))
2275 if (!t->opcode_modifier.d)
2279 i.error = operand_size_mismatch;
2283 /* Check reverse. */
2284 gas_assert (i.operands >= 2 && i.operands <= 3);
2286 for (j = 0; j < i.operands; j++)
2288 unsigned int given = i.operands - j - 1;
2290 if (t->operand_types[j].bitfield.class == Reg
2291 && !match_operand_size (t, j, given))
2294 if (t->operand_types[j].bitfield.class == RegSIMD
2295 && !match_simd_size (t, j, given))
2298 if (t->operand_types[j].bitfield.instance == Accum
2299 && (!match_operand_size (t, j, given)
2300 || !match_simd_size (t, j, given)))
2303 if ((i.flags[given] & Operand_Mem) && !match_mem_size (t, j, given))
2307 return match | MATCH_REVERSE;
2311 operand_type_match (i386_operand_type overlap,
2312 i386_operand_type given)
2314 i386_operand_type temp = overlap;
2316 temp.bitfield.unspecified = 0;
2317 temp.bitfield.byte = 0;
2318 temp.bitfield.word = 0;
2319 temp.bitfield.dword = 0;
2320 temp.bitfield.fword = 0;
2321 temp.bitfield.qword = 0;
2322 temp.bitfield.tbyte = 0;
2323 temp.bitfield.xmmword = 0;
2324 temp.bitfield.ymmword = 0;
2325 temp.bitfield.zmmword = 0;
2326 temp.bitfield.tmmword = 0;
2327 if (operand_type_all_zero (&temp))
2330 if (given.bitfield.baseindex == overlap.bitfield.baseindex)
2334 i.error = operand_type_mismatch;
2338 /* If given types g0 and g1 are registers they must be of the same type
2339 unless the expected operand type register overlap is null.
2340 Some Intel syntax memory operand size checking also happens here. */
2343 operand_type_register_match (i386_operand_type g0,
2344 i386_operand_type t0,
2345 i386_operand_type g1,
2346 i386_operand_type t1)
2348 if (g0.bitfield.class != Reg
2349 && g0.bitfield.class != RegSIMD
2350 && (!operand_type_check (g0, anymem)
2351 || g0.bitfield.unspecified
2352 || (t0.bitfield.class != Reg
2353 && t0.bitfield.class != RegSIMD)))
2356 if (g1.bitfield.class != Reg
2357 && g1.bitfield.class != RegSIMD
2358 && (!operand_type_check (g1, anymem)
2359 || g1.bitfield.unspecified
2360 || (t1.bitfield.class != Reg
2361 && t1.bitfield.class != RegSIMD)))
2364 if (g0.bitfield.byte == g1.bitfield.byte
2365 && g0.bitfield.word == g1.bitfield.word
2366 && g0.bitfield.dword == g1.bitfield.dword
2367 && g0.bitfield.qword == g1.bitfield.qword
2368 && g0.bitfield.xmmword == g1.bitfield.xmmword
2369 && g0.bitfield.ymmword == g1.bitfield.ymmword
2370 && g0.bitfield.zmmword == g1.bitfield.zmmword)
2373 if (!(t0.bitfield.byte & t1.bitfield.byte)
2374 && !(t0.bitfield.word & t1.bitfield.word)
2375 && !(t0.bitfield.dword & t1.bitfield.dword)
2376 && !(t0.bitfield.qword & t1.bitfield.qword)
2377 && !(t0.bitfield.xmmword & t1.bitfield.xmmword)
2378 && !(t0.bitfield.ymmword & t1.bitfield.ymmword)
2379 && !(t0.bitfield.zmmword & t1.bitfield.zmmword))
2382 i.error = register_type_mismatch;
2387 static INLINE unsigned int
2388 register_number (const reg_entry *r)
2390 unsigned int nr = r->reg_num;
2392 if (r->reg_flags & RegRex)
2395 if (r->reg_flags & RegVRex)
2401 static INLINE unsigned int
2402 mode_from_disp_size (i386_operand_type t)
2404 if (t.bitfield.disp8)
2406 else if (t.bitfield.disp16
2407 || t.bitfield.disp32
2408 || t.bitfield.disp32s)
2415 fits_in_signed_byte (addressT num)
2417 return num + 0x80 <= 0xff;
2421 fits_in_unsigned_byte (addressT num)
2427 fits_in_unsigned_word (addressT num)
2429 return num <= 0xffff;
2433 fits_in_signed_word (addressT num)
2435 return num + 0x8000 <= 0xffff;
2439 fits_in_signed_long (addressT num ATTRIBUTE_UNUSED)
2444 return num + 0x80000000 <= 0xffffffff;
2446 } /* fits_in_signed_long() */
2449 fits_in_unsigned_long (addressT num ATTRIBUTE_UNUSED)
2454 return num <= 0xffffffff;
2456 } /* fits_in_unsigned_long() */
2458 static INLINE valueT extend_to_32bit_address (addressT num)
2461 if (fits_in_unsigned_long(num))
2462 return (num ^ ((addressT) 1 << 31)) - ((addressT) 1 << 31);
2464 if (!fits_in_signed_long (num))
2465 return num & 0xffffffff;
2472 fits_in_disp8 (offsetT num)
2474 int shift = i.memshift;
2480 mask = (1 << shift) - 1;
2482 /* Return 0 if NUM isn't properly aligned. */
2486 /* Check if NUM will fit in 8bit after shift. */
2487 return fits_in_signed_byte (num >> shift);
2491 fits_in_imm4 (offsetT num)
2493 return (num & 0xf) == num;
2496 static i386_operand_type
2497 smallest_imm_type (offsetT num)
2499 i386_operand_type t;
2501 operand_type_set (&t, 0);
2502 t.bitfield.imm64 = 1;
2504 if (cpu_arch_tune != PROCESSOR_I486 && num == 1)
2506 /* This code is disabled on the 486 because all the Imm1 forms
2507 in the opcode table are slower on the i486. They're the
2508 versions with the implicitly specified single-position
2509 displacement, which has another syntax if you really want to
2511 t.bitfield.imm1 = 1;
2512 t.bitfield.imm8 = 1;
2513 t.bitfield.imm8s = 1;
2514 t.bitfield.imm16 = 1;
2515 t.bitfield.imm32 = 1;
2516 t.bitfield.imm32s = 1;
2518 else if (fits_in_signed_byte (num))
2520 t.bitfield.imm8 = 1;
2521 t.bitfield.imm8s = 1;
2522 t.bitfield.imm16 = 1;
2523 t.bitfield.imm32 = 1;
2524 t.bitfield.imm32s = 1;
2526 else if (fits_in_unsigned_byte (num))
2528 t.bitfield.imm8 = 1;
2529 t.bitfield.imm16 = 1;
2530 t.bitfield.imm32 = 1;
2531 t.bitfield.imm32s = 1;
2533 else if (fits_in_signed_word (num) || fits_in_unsigned_word (num))
2535 t.bitfield.imm16 = 1;
2536 t.bitfield.imm32 = 1;
2537 t.bitfield.imm32s = 1;
2539 else if (fits_in_signed_long (num))
2541 t.bitfield.imm32 = 1;
2542 t.bitfield.imm32s = 1;
2544 else if (fits_in_unsigned_long (num))
2545 t.bitfield.imm32 = 1;
2551 offset_in_range (offsetT val, int size)
2557 case 1: mask = ((addressT) 1 << 8) - 1; break;
2558 case 2: mask = ((addressT) 1 << 16) - 1; break;
2559 case 4: mask = ((addressT) 2 << 31) - 1; break;
2561 case 8: mask = ((addressT) 2 << 63) - 1; break;
2566 if ((val & ~mask) != 0 && (val & ~mask) != ~mask)
2568 char buf1[40], buf2[40];
2570 bfd_sprintf_vma (stdoutput, buf1, val);
2571 bfd_sprintf_vma (stdoutput, buf2, val & mask);
2572 as_warn (_("%s shortened to %s"), buf1, buf2);
2587 a. PREFIX_EXIST if attempting to add a prefix where one from the
2588 same class already exists.
2589 b. PREFIX_LOCK if lock prefix is added.
2590 c. PREFIX_REP if rep/repne prefix is added.
2591 d. PREFIX_DS if ds prefix is added.
2592 e. PREFIX_OTHER if other prefix is added.
2595 static enum PREFIX_GROUP
2596 add_prefix (unsigned int prefix)
2598 enum PREFIX_GROUP ret = PREFIX_OTHER;
2601 if (prefix >= REX_OPCODE && prefix < REX_OPCODE + 16
2602 && flag_code == CODE_64BIT)
2604 if ((i.prefix[REX_PREFIX] & prefix & REX_W)
2605 || (i.prefix[REX_PREFIX] & prefix & REX_R)
2606 || (i.prefix[REX_PREFIX] & prefix & REX_X)
2607 || (i.prefix[REX_PREFIX] & prefix & REX_B))
2618 case DS_PREFIX_OPCODE:
2621 case CS_PREFIX_OPCODE:
2622 case ES_PREFIX_OPCODE:
2623 case FS_PREFIX_OPCODE:
2624 case GS_PREFIX_OPCODE:
2625 case SS_PREFIX_OPCODE:
2629 case REPNE_PREFIX_OPCODE:
2630 case REPE_PREFIX_OPCODE:
2635 case LOCK_PREFIX_OPCODE:
2644 case ADDR_PREFIX_OPCODE:
2648 case DATA_PREFIX_OPCODE:
2652 if (i.prefix[q] != 0)
2660 i.prefix[q] |= prefix;
2663 as_bad (_("same type of prefix used twice"));
2669 update_code_flag (int value, int check)
2671 PRINTF_LIKE ((*as_error));
2673 flag_code = (enum flag_code) value;
2674 if (flag_code == CODE_64BIT)
2676 cpu_arch_flags.bitfield.cpu64 = 1;
2677 cpu_arch_flags.bitfield.cpuno64 = 0;
2681 cpu_arch_flags.bitfield.cpu64 = 0;
2682 cpu_arch_flags.bitfield.cpuno64 = 1;
2684 if (value == CODE_64BIT && !cpu_arch_flags.bitfield.cpulm )
2687 as_error = as_fatal;
2690 (*as_error) (_("64bit mode not supported on `%s'."),
2691 cpu_arch_name ? cpu_arch_name : default_arch);
2693 if (value == CODE_32BIT && !cpu_arch_flags.bitfield.cpui386)
2696 as_error = as_fatal;
2699 (*as_error) (_("32bit mode not supported on `%s'."),
2700 cpu_arch_name ? cpu_arch_name : default_arch);
2702 stackop_size = '\0';
2706 set_code_flag (int value)
2708 update_code_flag (value, 0);
2712 set_16bit_gcc_code_flag (int new_code_flag)
2714 flag_code = (enum flag_code) new_code_flag;
2715 if (flag_code != CODE_16BIT)
2717 cpu_arch_flags.bitfield.cpu64 = 0;
2718 cpu_arch_flags.bitfield.cpuno64 = 1;
2719 stackop_size = LONG_MNEM_SUFFIX;
2723 set_intel_syntax (int syntax_flag)
2725 /* Find out if register prefixing is specified. */
2726 int ask_naked_reg = 0;
2729 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2732 int e = get_symbol_name (&string);
2734 if (strcmp (string, "prefix") == 0)
2736 else if (strcmp (string, "noprefix") == 0)
2739 as_bad (_("bad argument to syntax directive."));
2740 (void) restore_line_pointer (e);
2742 demand_empty_rest_of_line ();
2744 intel_syntax = syntax_flag;
2746 if (ask_naked_reg == 0)
2747 allow_naked_reg = (intel_syntax
2748 && (bfd_get_symbol_leading_char (stdoutput) != '\0'));
2750 allow_naked_reg = (ask_naked_reg < 0);
2752 expr_set_rank (O_full_ptr, syntax_flag ? 10 : 0);
2754 identifier_chars['%'] = intel_syntax && allow_naked_reg ? '%' : 0;
2755 identifier_chars['$'] = intel_syntax ? '$' : 0;
2756 register_prefix = allow_naked_reg ? "" : "%";
2760 set_intel_mnemonic (int mnemonic_flag)
2762 intel_mnemonic = mnemonic_flag;
2766 set_allow_index_reg (int flag)
2768 allow_index_reg = flag;
2772 set_check (int what)
2774 enum check_kind *kind;
2779 kind = &operand_check;
2790 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2793 int e = get_symbol_name (&string);
2795 if (strcmp (string, "none") == 0)
2797 else if (strcmp (string, "warning") == 0)
2798 *kind = check_warning;
2799 else if (strcmp (string, "error") == 0)
2800 *kind = check_error;
2802 as_bad (_("bad argument to %s_check directive."), str);
2803 (void) restore_line_pointer (e);
2806 as_bad (_("missing argument for %s_check directive"), str);
2808 demand_empty_rest_of_line ();
2812 check_cpu_arch_compatible (const char *name ATTRIBUTE_UNUSED,
2813 i386_cpu_flags new_flag ATTRIBUTE_UNUSED)
2815 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
2816 static const char *arch;
2818 /* Intel LIOM is only supported on ELF. */
2824 /* Use cpu_arch_name if it is set in md_parse_option. Otherwise
2825 use default_arch. */
2826 arch = cpu_arch_name;
2828 arch = default_arch;
2831 /* If we are targeting Intel MCU, we must enable it. */
2832 if (get_elf_backend_data (stdoutput)->elf_machine_code != EM_IAMCU
2833 || new_flag.bitfield.cpuiamcu)
2836 /* If we are targeting Intel L1OM, we must enable it. */
2837 if (get_elf_backend_data (stdoutput)->elf_machine_code != EM_L1OM
2838 || new_flag.bitfield.cpul1om)
2841 /* If we are targeting Intel K1OM, we must enable it. */
2842 if (get_elf_backend_data (stdoutput)->elf_machine_code != EM_K1OM
2843 || new_flag.bitfield.cpuk1om)
2846 as_bad (_("`%s' is not supported on `%s'"), name, arch);
2851 set_cpu_arch (int dummy ATTRIBUTE_UNUSED)
2855 if (!is_end_of_line[(unsigned char) *input_line_pointer])
2858 int e = get_symbol_name (&string);
2860 i386_cpu_flags flags;
2862 for (j = 0; j < ARRAY_SIZE (cpu_arch); j++)
2864 if (strcmp (string, cpu_arch[j].name) == 0)
2866 check_cpu_arch_compatible (string, cpu_arch[j].flags);
2870 cpu_arch_name = cpu_arch[j].name;
2871 cpu_sub_arch_name = NULL;
2872 cpu_arch_flags = cpu_arch[j].flags;
2873 if (flag_code == CODE_64BIT)
2875 cpu_arch_flags.bitfield.cpu64 = 1;
2876 cpu_arch_flags.bitfield.cpuno64 = 0;
2880 cpu_arch_flags.bitfield.cpu64 = 0;
2881 cpu_arch_flags.bitfield.cpuno64 = 1;
2883 cpu_arch_isa = cpu_arch[j].type;
2884 cpu_arch_isa_flags = cpu_arch[j].flags;
2885 if (!cpu_arch_tune_set)
2887 cpu_arch_tune = cpu_arch_isa;
2888 cpu_arch_tune_flags = cpu_arch_isa_flags;
2893 flags = cpu_flags_or (cpu_arch_flags,
2896 if (!cpu_flags_equal (&flags, &cpu_arch_flags))
2898 if (cpu_sub_arch_name)
2900 char *name = cpu_sub_arch_name;
2901 cpu_sub_arch_name = concat (name,
2903 (const char *) NULL);
2907 cpu_sub_arch_name = xstrdup (cpu_arch[j].name);
2908 cpu_arch_flags = flags;
2909 cpu_arch_isa_flags = flags;
2913 = cpu_flags_or (cpu_arch_isa_flags,
2915 (void) restore_line_pointer (e);
2916 demand_empty_rest_of_line ();
2921 if (*string == '.' && j >= ARRAY_SIZE (cpu_arch))
2923 /* Disable an ISA extension. */
2924 for (j = 0; j < ARRAY_SIZE (cpu_noarch); j++)
2925 if (strcmp (string + 1, cpu_noarch [j].name) == 0)
2927 flags = cpu_flags_and_not (cpu_arch_flags,
2928 cpu_noarch[j].flags);
2929 if (!cpu_flags_equal (&flags, &cpu_arch_flags))
2931 if (cpu_sub_arch_name)
2933 char *name = cpu_sub_arch_name;
2934 cpu_sub_arch_name = concat (name, string,
2935 (const char *) NULL);
2939 cpu_sub_arch_name = xstrdup (string);
2940 cpu_arch_flags = flags;
2941 cpu_arch_isa_flags = flags;
2943 (void) restore_line_pointer (e);
2944 demand_empty_rest_of_line ();
2948 j = ARRAY_SIZE (cpu_arch);
2951 if (j >= ARRAY_SIZE (cpu_arch))
2952 as_bad (_("no such architecture: `%s'"), string);
2954 *input_line_pointer = e;
2957 as_bad (_("missing cpu architecture"));
2959 no_cond_jump_promotion = 0;
2960 if (*input_line_pointer == ','
2961 && !is_end_of_line[(unsigned char) input_line_pointer[1]])
2966 ++input_line_pointer;
2967 e = get_symbol_name (&string);
2969 if (strcmp (string, "nojumps") == 0)
2970 no_cond_jump_promotion = 1;
2971 else if (strcmp (string, "jumps") == 0)
2974 as_bad (_("no such architecture modifier: `%s'"), string);
2976 (void) restore_line_pointer (e);
2979 demand_empty_rest_of_line ();
2982 enum bfd_architecture
2985 if (cpu_arch_isa == PROCESSOR_L1OM)
2987 if (OUTPUT_FLAVOR != bfd_target_elf_flavour
2988 || flag_code != CODE_64BIT)
2989 as_fatal (_("Intel L1OM is 64bit ELF only"));
2990 return bfd_arch_l1om;
2992 else if (cpu_arch_isa == PROCESSOR_K1OM)
2994 if (OUTPUT_FLAVOR != bfd_target_elf_flavour
2995 || flag_code != CODE_64BIT)
2996 as_fatal (_("Intel K1OM is 64bit ELF only"));
2997 return bfd_arch_k1om;
2999 else if (cpu_arch_isa == PROCESSOR_IAMCU)
3001 if (OUTPUT_FLAVOR != bfd_target_elf_flavour
3002 || flag_code == CODE_64BIT)
3003 as_fatal (_("Intel MCU is 32bit ELF only"));
3004 return bfd_arch_iamcu;
3007 return bfd_arch_i386;
3013 if (startswith (default_arch, "x86_64"))
3015 if (cpu_arch_isa == PROCESSOR_L1OM)
3017 if (OUTPUT_FLAVOR != bfd_target_elf_flavour
3018 || default_arch[6] != '\0')
3019 as_fatal (_("Intel L1OM is 64bit ELF only"));
3020 return bfd_mach_l1om;
3022 else if (cpu_arch_isa == PROCESSOR_K1OM)
3024 if (OUTPUT_FLAVOR != bfd_target_elf_flavour
3025 || default_arch[6] != '\0')
3026 as_fatal (_("Intel K1OM is 64bit ELF only"));
3027 return bfd_mach_k1om;
3029 else if (default_arch[6] == '\0')
3030 return bfd_mach_x86_64;
3032 return bfd_mach_x64_32;
3034 else if (!strcmp (default_arch, "i386")
3035 || !strcmp (default_arch, "iamcu"))
3037 if (cpu_arch_isa == PROCESSOR_IAMCU)
3039 if (OUTPUT_FLAVOR != bfd_target_elf_flavour)
3040 as_fatal (_("Intel MCU is 32bit ELF only"));
3041 return bfd_mach_i386_iamcu;
3044 return bfd_mach_i386_i386;
3047 as_fatal (_("unknown architecture"));
3053 /* Support pseudo prefixes like {disp32}. */
3054 lex_type ['{'] = LEX_BEGIN_NAME;
3056 /* Initialize op_hash hash table. */
3057 op_hash = str_htab_create ();
3060 const insn_template *optab;
3061 templates *core_optab;
3063 /* Setup for loop. */
3065 core_optab = XNEW (templates);
3066 core_optab->start = optab;
3071 if (optab->name == NULL
3072 || strcmp (optab->name, (optab - 1)->name) != 0)
3074 /* different name --> ship out current template list;
3075 add to hash table; & begin anew. */
3076 core_optab->end = optab;
3077 if (str_hash_insert (op_hash, (optab - 1)->name, core_optab, 0))
3078 as_fatal (_("duplicate %s"), (optab - 1)->name);
3080 if (optab->name == NULL)
3082 core_optab = XNEW (templates);
3083 core_optab->start = optab;
3088 /* Initialize reg_hash hash table. */
3089 reg_hash = str_htab_create ();
3091 const reg_entry *regtab;
3092 unsigned int regtab_size = i386_regtab_size;
3094 for (regtab = i386_regtab; regtab_size--; regtab++)
3096 switch (regtab->reg_type.bitfield.class)
3099 if (regtab->reg_type.bitfield.dword)
3101 if (regtab->reg_type.bitfield.instance == Accum)
3104 else if (regtab->reg_type.bitfield.tbyte)
3106 /* There's no point inserting st(<N>) in the hash table, as
3107 parentheses aren't included in register_chars[] anyway. */
3108 if (regtab->reg_type.bitfield.instance != Accum)
3115 switch (regtab->reg_num)
3117 case 0: reg_es = regtab; break;
3118 case 2: reg_ss = regtab; break;
3119 case 3: reg_ds = regtab; break;
3124 if (!regtab->reg_num)
3129 if (str_hash_insert (reg_hash, regtab->reg_name, regtab, 0) != NULL)
3130 as_fatal (_("duplicate %s"), regtab->reg_name);
3134 /* Fill in lexical tables: mnemonic_chars, operand_chars. */
3139 for (c = 0; c < 256; c++)
3141 if (ISDIGIT (c) || ISLOWER (c))
3143 mnemonic_chars[c] = c;
3144 register_chars[c] = c;
3145 operand_chars[c] = c;
3147 else if (ISUPPER (c))
3149 mnemonic_chars[c] = TOLOWER (c);
3150 register_chars[c] = mnemonic_chars[c];
3151 operand_chars[c] = c;
3153 else if (c == '{' || c == '}')
3155 mnemonic_chars[c] = c;
3156 operand_chars[c] = c;
3158 #ifdef SVR4_COMMENT_CHARS
3159 else if (c == '\\' && strchr (i386_comment_chars, '/'))
3160 operand_chars[c] = c;
3163 if (ISALPHA (c) || ISDIGIT (c))
3164 identifier_chars[c] = c;
3167 identifier_chars[c] = c;
3168 operand_chars[c] = c;
3173 identifier_chars['@'] = '@';
3176 identifier_chars['?'] = '?';
3177 operand_chars['?'] = '?';
3179 mnemonic_chars['_'] = '_';
3180 mnemonic_chars['-'] = '-';
3181 mnemonic_chars['.'] = '.';
3182 identifier_chars['_'] = '_';
3183 identifier_chars['.'] = '.';
3185 for (p = operand_special_chars; *p != '\0'; p++)
3186 operand_chars[(unsigned char) *p] = *p;
3189 if (flag_code == CODE_64BIT)
3191 #if defined (OBJ_COFF) && defined (TE_PE)
3192 x86_dwarf2_return_column = (OUTPUT_FLAVOR == bfd_target_coff_flavour
3195 x86_dwarf2_return_column = 16;
3197 x86_cie_data_alignment = -8;
3201 x86_dwarf2_return_column = 8;
3202 x86_cie_data_alignment = -4;
3205 /* NB: FUSED_JCC_PADDING frag must have sufficient room so that it
3206 can be turned into BRANCH_PREFIX frag. */
3207 if (align_branch_prefix_size > MAX_FUSED_JCC_PADDING_SIZE)
3212 i386_print_statistics (FILE *file)
3214 htab_print_statistics (file, "i386 opcode", op_hash);
3215 htab_print_statistics (file, "i386 register", reg_hash);
3220 /* Debugging routines for md_assemble. */
3221 static void pte (insn_template *);
3222 static void pt (i386_operand_type);
3223 static void pe (expressionS *);
3224 static void ps (symbolS *);
3227 pi (const char *line, i386_insn *x)
3231 fprintf (stdout, "%s: template ", line);
3233 fprintf (stdout, " address: base %s index %s scale %x\n",
3234 x->base_reg ? x->base_reg->reg_name : "none",
3235 x->index_reg ? x->index_reg->reg_name : "none",
3236 x->log2_scale_factor);
3237 fprintf (stdout, " modrm: mode %x reg %x reg/mem %x\n",
3238 x->rm.mode, x->rm.reg, x->rm.regmem);
3239 fprintf (stdout, " sib: base %x index %x scale %x\n",
3240 x->sib.base, x->sib.index, x->sib.scale);
3241 fprintf (stdout, " rex: 64bit %x extX %x extY %x extZ %x\n",
3242 (x->rex & REX_W) != 0,
3243 (x->rex & REX_R) != 0,
3244 (x->rex & REX_X) != 0,
3245 (x->rex & REX_B) != 0);
3246 for (j = 0; j < x->operands; j++)
3248 fprintf (stdout, " #%d: ", j + 1);
3250 fprintf (stdout, "\n");
3251 if (x->types[j].bitfield.class == Reg
3252 || x->types[j].bitfield.class == RegMMX
3253 || x->types[j].bitfield.class == RegSIMD
3254 || x->types[j].bitfield.class == RegMask
3255 || x->types[j].bitfield.class == SReg
3256 || x->types[j].bitfield.class == RegCR
3257 || x->types[j].bitfield.class == RegDR
3258 || x->types[j].bitfield.class == RegTR
3259 || x->types[j].bitfield.class == RegBND)
3260 fprintf (stdout, "%s\n", x->op[j].regs->reg_name);
3261 if (operand_type_check (x->types[j], imm))
3263 if (operand_type_check (x->types[j], disp))
3264 pe (x->op[j].disps);
3269 pte (insn_template *t)
3271 static const unsigned char opc_pfx[] = { 0, 0x66, 0xf3, 0xf2 };
3272 static const char *const opc_spc[] = {
3273 NULL, "0f", "0f38", "0f3a", NULL, NULL, NULL, NULL,
3274 "XOP08", "XOP09", "XOP0A",
3278 fprintf (stdout, " %d operands ", t->operands);
3279 if (opc_pfx[t->opcode_modifier.opcodeprefix])
3280 fprintf (stdout, "pfx %x ", opc_pfx[t->opcode_modifier.opcodeprefix]);
3281 if (opc_spc[t->opcode_modifier.opcodespace])
3282 fprintf (stdout, "space %s ", opc_spc[t->opcode_modifier.opcodespace]);
3283 fprintf (stdout, "opcode %x ", t->base_opcode);
3284 if (t->extension_opcode != None)
3285 fprintf (stdout, "ext %x ", t->extension_opcode);
3286 if (t->opcode_modifier.d)
3287 fprintf (stdout, "D");
3288 if (t->opcode_modifier.w)
3289 fprintf (stdout, "W");
3290 fprintf (stdout, "\n");
3291 for (j = 0; j < t->operands; j++)
3293 fprintf (stdout, " #%d type ", j + 1);
3294 pt (t->operand_types[j]);
3295 fprintf (stdout, "\n");
3302 fprintf (stdout, " operation %d\n", e->X_op);
3303 fprintf (stdout, " add_number %" BFD_VMA_FMT "d (%" BFD_VMA_FMT "x)\n",
3304 e->X_add_number, e->X_add_number);
3305 if (e->X_add_symbol)
3307 fprintf (stdout, " add_symbol ");
3308 ps (e->X_add_symbol);
3309 fprintf (stdout, "\n");
3313 fprintf (stdout, " op_symbol ");
3314 ps (e->X_op_symbol);
3315 fprintf (stdout, "\n");
3322 fprintf (stdout, "%s type %s%s",
3324 S_IS_EXTERNAL (s) ? "EXTERNAL " : "",
3325 segment_name (S_GET_SEGMENT (s)));
3328 static struct type_name
3330 i386_operand_type mask;
3333 const type_names[] =
3335 { OPERAND_TYPE_REG8, "r8" },
3336 { OPERAND_TYPE_REG16, "r16" },
3337 { OPERAND_TYPE_REG32, "r32" },
3338 { OPERAND_TYPE_REG64, "r64" },
3339 { OPERAND_TYPE_ACC8, "acc8" },
3340 { OPERAND_TYPE_ACC16, "acc16" },
3341 { OPERAND_TYPE_ACC32, "acc32" },
3342 { OPERAND_TYPE_ACC64, "acc64" },
3343 { OPERAND_TYPE_IMM8, "i8" },
3344 { OPERAND_TYPE_IMM8, "i8s" },
3345 { OPERAND_TYPE_IMM16, "i16" },
3346 { OPERAND_TYPE_IMM32, "i32" },
3347 { OPERAND_TYPE_IMM32S, "i32s" },
3348 { OPERAND_TYPE_IMM64, "i64" },
3349 { OPERAND_TYPE_IMM1, "i1" },
3350 { OPERAND_TYPE_BASEINDEX, "BaseIndex" },
3351 { OPERAND_TYPE_DISP8, "d8" },
3352 { OPERAND_TYPE_DISP16, "d16" },
3353 { OPERAND_TYPE_DISP32, "d32" },
3354 { OPERAND_TYPE_DISP32S, "d32s" },
3355 { OPERAND_TYPE_DISP64, "d64" },
3356 { OPERAND_TYPE_INOUTPORTREG, "InOutPortReg" },
3357 { OPERAND_TYPE_SHIFTCOUNT, "ShiftCount" },
3358 { OPERAND_TYPE_CONTROL, "control reg" },
3359 { OPERAND_TYPE_TEST, "test reg" },
3360 { OPERAND_TYPE_DEBUG, "debug reg" },
3361 { OPERAND_TYPE_FLOATREG, "FReg" },
3362 { OPERAND_TYPE_FLOATACC, "FAcc" },
3363 { OPERAND_TYPE_SREG, "SReg" },
3364 { OPERAND_TYPE_REGMMX, "rMMX" },
3365 { OPERAND_TYPE_REGXMM, "rXMM" },
3366 { OPERAND_TYPE_REGYMM, "rYMM" },
3367 { OPERAND_TYPE_REGZMM, "rZMM" },
3368 { OPERAND_TYPE_REGTMM, "rTMM" },
3369 { OPERAND_TYPE_REGMASK, "Mask reg" },
3373 pt (i386_operand_type t)
3376 i386_operand_type a;
3378 for (j = 0; j < ARRAY_SIZE (type_names); j++)
3380 a = operand_type_and (t, type_names[j].mask);
3381 if (operand_type_equal (&a, &type_names[j].mask))
3382 fprintf (stdout, "%s, ", type_names[j].name);
3387 #endif /* DEBUG386 */
3389 static bfd_reloc_code_real_type
3390 reloc (unsigned int size,
3393 bfd_reloc_code_real_type other)
3395 if (other != NO_RELOC)
3397 reloc_howto_type *rel;
3402 case BFD_RELOC_X86_64_GOT32:
3403 return BFD_RELOC_X86_64_GOT64;
3405 case BFD_RELOC_X86_64_GOTPLT64:
3406 return BFD_RELOC_X86_64_GOTPLT64;
3408 case BFD_RELOC_X86_64_PLTOFF64:
3409 return BFD_RELOC_X86_64_PLTOFF64;
3411 case BFD_RELOC_X86_64_GOTPC32:
3412 other = BFD_RELOC_X86_64_GOTPC64;
3414 case BFD_RELOC_X86_64_GOTPCREL:
3415 other = BFD_RELOC_X86_64_GOTPCREL64;
3417 case BFD_RELOC_X86_64_TPOFF32:
3418 other = BFD_RELOC_X86_64_TPOFF64;
3420 case BFD_RELOC_X86_64_DTPOFF32:
3421 other = BFD_RELOC_X86_64_DTPOFF64;
3427 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3428 if (other == BFD_RELOC_SIZE32)
3431 other = BFD_RELOC_SIZE64;
3434 as_bad (_("there are no pc-relative size relocations"));
3440 /* Sign-checking 4-byte relocations in 16-/32-bit code is pointless. */
3441 if (size == 4 && (flag_code != CODE_64BIT || disallow_64bit_reloc))
3444 rel = bfd_reloc_type_lookup (stdoutput, other);
3446 as_bad (_("unknown relocation (%u)"), other);
3447 else if (size != bfd_get_reloc_size (rel))
3448 as_bad (_("%u-byte relocation cannot be applied to %u-byte field"),
3449 bfd_get_reloc_size (rel),
3451 else if (pcrel && !rel->pc_relative)
3452 as_bad (_("non-pc-relative relocation for pc-relative field"));
3453 else if ((rel->complain_on_overflow == complain_overflow_signed
3455 || (rel->complain_on_overflow == complain_overflow_unsigned
3457 as_bad (_("relocated field and relocation type differ in signedness"));
3466 as_bad (_("there are no unsigned pc-relative relocations"));
3469 case 1: return BFD_RELOC_8_PCREL;
3470 case 2: return BFD_RELOC_16_PCREL;
3471 case 4: return BFD_RELOC_32_PCREL;
3472 case 8: return BFD_RELOC_64_PCREL;
3474 as_bad (_("cannot do %u byte pc-relative relocation"), size);
3481 case 4: return BFD_RELOC_X86_64_32S;
3486 case 1: return BFD_RELOC_8;
3487 case 2: return BFD_RELOC_16;
3488 case 4: return BFD_RELOC_32;
3489 case 8: return BFD_RELOC_64;
3491 as_bad (_("cannot do %s %u byte relocation"),
3492 sign > 0 ? "signed" : "unsigned", size);
3498 /* Here we decide which fixups can be adjusted to make them relative to
3499 the beginning of the section instead of the symbol. Basically we need
3500 to make sure that the dynamic relocations are done correctly, so in
3501 some cases we force the original symbol to be used. */
3504 tc_i386_fix_adjustable (fixS *fixP ATTRIBUTE_UNUSED)
3506 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3510 /* Don't adjust pc-relative references to merge sections in 64-bit
3512 if (use_rela_relocations
3513 && (S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0
3517 /* The x86_64 GOTPCREL are represented as 32bit PCrel relocations
3518 and changed later by validate_fix. */
3519 if (GOT_symbol && fixP->fx_subsy == GOT_symbol
3520 && fixP->fx_r_type == BFD_RELOC_32_PCREL)
3523 /* Adjust_reloc_syms doesn't know about the GOT. Need to keep symbol
3524 for size relocations. */
3525 if (fixP->fx_r_type == BFD_RELOC_SIZE32
3526 || fixP->fx_r_type == BFD_RELOC_SIZE64
3527 || fixP->fx_r_type == BFD_RELOC_386_GOTOFF
3528 || fixP->fx_r_type == BFD_RELOC_386_GOT32
3529 || fixP->fx_r_type == BFD_RELOC_386_GOT32X
3530 || fixP->fx_r_type == BFD_RELOC_386_TLS_GD
3531 || fixP->fx_r_type == BFD_RELOC_386_TLS_LDM
3532 || fixP->fx_r_type == BFD_RELOC_386_TLS_LDO_32
3533 || fixP->fx_r_type == BFD_RELOC_386_TLS_IE_32
3534 || fixP->fx_r_type == BFD_RELOC_386_TLS_IE
3535 || fixP->fx_r_type == BFD_RELOC_386_TLS_GOTIE
3536 || fixP->fx_r_type == BFD_RELOC_386_TLS_LE_32
3537 || fixP->fx_r_type == BFD_RELOC_386_TLS_LE
3538 || fixP->fx_r_type == BFD_RELOC_386_TLS_GOTDESC
3539 || fixP->fx_r_type == BFD_RELOC_386_TLS_DESC_CALL
3540 || fixP->fx_r_type == BFD_RELOC_X86_64_GOT32
3541 || fixP->fx_r_type == BFD_RELOC_X86_64_GOTPCREL
3542 || fixP->fx_r_type == BFD_RELOC_X86_64_GOTPCRELX
3543 || fixP->fx_r_type == BFD_RELOC_X86_64_REX_GOTPCRELX
3544 || fixP->fx_r_type == BFD_RELOC_X86_64_TLSGD
3545 || fixP->fx_r_type == BFD_RELOC_X86_64_TLSLD
3546 || fixP->fx_r_type == BFD_RELOC_X86_64_DTPOFF32
3547 || fixP->fx_r_type == BFD_RELOC_X86_64_DTPOFF64
3548 || fixP->fx_r_type == BFD_RELOC_X86_64_GOTTPOFF
3549 || fixP->fx_r_type == BFD_RELOC_X86_64_TPOFF32
3550 || fixP->fx_r_type == BFD_RELOC_X86_64_TPOFF64
3551 || fixP->fx_r_type == BFD_RELOC_X86_64_GOTOFF64
3552 || fixP->fx_r_type == BFD_RELOC_X86_64_GOTPC32_TLSDESC
3553 || fixP->fx_r_type == BFD_RELOC_X86_64_TLSDESC_CALL
3554 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
3555 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
3562 want_disp32 (const insn_template *t)
3564 return flag_code != CODE_64BIT
3565 || i.prefix[ADDR_PREFIX]
3566 || (t->base_opcode == 0x8d
3567 && t->opcode_modifier.opcodespace == SPACE_BASE
3568 && (!i.types[1].bitfield.qword
3569 || t->opcode_modifier.size == SIZE32));
3573 intel_float_operand (const char *mnemonic)
3575 /* Note that the value returned is meaningful only for opcodes with (memory)
3576 operands, hence the code here is free to improperly handle opcodes that
3577 have no operands (for better performance and smaller code). */
3579 if (mnemonic[0] != 'f')
3580 return 0; /* non-math */
3582 switch (mnemonic[1])
3584 /* fclex, fdecstp, fdisi, femms, feni, fincstp, finit, fsetpm, and
3585 the fs segment override prefix not currently handled because no
3586 call path can make opcodes without operands get here */
3588 return 2 /* integer op */;
3590 if (mnemonic[2] == 'd' && (mnemonic[3] == 'c' || mnemonic[3] == 'e'))
3591 return 3; /* fldcw/fldenv */
3594 if (mnemonic[2] != 'o' /* fnop */)
3595 return 3; /* non-waiting control op */
3598 if (mnemonic[2] == 's')
3599 return 3; /* frstor/frstpm */
3602 if (mnemonic[2] == 'a')
3603 return 3; /* fsave */
3604 if (mnemonic[2] == 't')
3606 switch (mnemonic[3])
3608 case 'c': /* fstcw */
3609 case 'd': /* fstdw */
3610 case 'e': /* fstenv */
3611 case 's': /* fsts[gw] */
3617 if (mnemonic[2] == 'r' || mnemonic[2] == 's')
3618 return 0; /* fxsave/fxrstor are not really math ops */
3626 install_template (const insn_template *t)
3632 /* Note that for pseudo prefixes this produces a length of 1. But for them
3633 the length isn't interesting at all. */
3634 for (l = 1; l < 4; ++l)
3635 if (!(t->base_opcode >> (8 * l)))
3638 i.opcode_length = l;
3641 /* Build the VEX prefix. */
3644 build_vex_prefix (const insn_template *t)
3646 unsigned int register_specifier;
3647 unsigned int vector_length;
3650 /* Check register specifier. */
3651 if (i.vex.register_specifier)
3653 register_specifier =
3654 ~register_number (i.vex.register_specifier) & 0xf;
3655 gas_assert ((i.vex.register_specifier->reg_flags & RegVRex) == 0);
3658 register_specifier = 0xf;
3660 /* Use 2-byte VEX prefix by swapping destination and source operand
3661 if there are more than 1 register operand. */
3662 if (i.reg_operands > 1
3663 && i.vec_encoding != vex_encoding_vex3
3664 && i.dir_encoding == dir_encoding_default
3665 && i.operands == i.reg_operands
3666 && operand_type_equal (&i.types[0], &i.types[i.operands - 1])
3667 && i.tm.opcode_modifier.opcodespace == SPACE_0F
3668 && (i.tm.opcode_modifier.load || i.tm.opcode_modifier.d)
3671 unsigned int xchg = i.operands - 1;
3672 union i386_op temp_op;
3673 i386_operand_type temp_type;
3675 temp_type = i.types[xchg];
3676 i.types[xchg] = i.types[0];
3677 i.types[0] = temp_type;
3678 temp_op = i.op[xchg];
3679 i.op[xchg] = i.op[0];
3682 gas_assert (i.rm.mode == 3);
3686 i.rm.regmem = i.rm.reg;
3689 if (i.tm.opcode_modifier.d)
3690 i.tm.base_opcode ^= (i.tm.base_opcode & 0xee) != 0x6e
3691 ? Opcode_SIMD_FloatD : Opcode_SIMD_IntD;
3692 else /* Use the next insn. */
3693 install_template (&t[1]);
3696 /* Use 2-byte VEX prefix by swapping commutative source operands if there
3697 are no memory operands and at least 3 register ones. */
3698 if (i.reg_operands >= 3
3699 && i.vec_encoding != vex_encoding_vex3
3700 && i.reg_operands == i.operands - i.imm_operands
3701 && i.tm.opcode_modifier.vex
3702 && i.tm.opcode_modifier.commutative
3703 && (i.tm.opcode_modifier.sse2avx || optimize > 1)
3705 && i.vex.register_specifier
3706 && !(i.vex.register_specifier->reg_flags & RegRex))
3708 unsigned int xchg = i.operands - i.reg_operands;
3709 union i386_op temp_op;
3710 i386_operand_type temp_type;
3712 gas_assert (i.tm.opcode_modifier.opcodespace == SPACE_0F);
3713 gas_assert (!i.tm.opcode_modifier.sae);
3714 gas_assert (operand_type_equal (&i.types[i.operands - 2],
3715 &i.types[i.operands - 3]));
3716 gas_assert (i.rm.mode == 3);
3718 temp_type = i.types[xchg];
3719 i.types[xchg] = i.types[xchg + 1];
3720 i.types[xchg + 1] = temp_type;
3721 temp_op = i.op[xchg];
3722 i.op[xchg] = i.op[xchg + 1];
3723 i.op[xchg + 1] = temp_op;
3726 xchg = i.rm.regmem | 8;
3727 i.rm.regmem = ~register_specifier & 0xf;
3728 gas_assert (!(i.rm.regmem & 8));
3729 i.vex.register_specifier += xchg - i.rm.regmem;
3730 register_specifier = ~xchg & 0xf;
3733 if (i.tm.opcode_modifier.vex == VEXScalar)
3734 vector_length = avxscalar;
3735 else if (i.tm.opcode_modifier.vex == VEX256)
3741 /* Determine vector length from the last multi-length vector
3744 for (op = t->operands; op--;)
3745 if (t->operand_types[op].bitfield.xmmword
3746 && t->operand_types[op].bitfield.ymmword
3747 && i.types[op].bitfield.ymmword)
3754 /* Check the REX.W bit and VEXW. */
3755 if (i.tm.opcode_modifier.vexw == VEXWIG)
3756 w = (vexwig == vexw1 || (i.rex & REX_W)) ? 1 : 0;
3757 else if (i.tm.opcode_modifier.vexw)
3758 w = i.tm.opcode_modifier.vexw == VEXW1 ? 1 : 0;
3760 w = (flag_code == CODE_64BIT ? i.rex & REX_W : vexwig == vexw1) ? 1 : 0;
3762 /* Use 2-byte VEX prefix if possible. */
3764 && i.vec_encoding != vex_encoding_vex3
3765 && i.tm.opcode_modifier.opcodespace == SPACE_0F
3766 && (i.rex & (REX_W | REX_X | REX_B)) == 0)
3768 /* 2-byte VEX prefix. */
3772 i.vex.bytes[0] = 0xc5;
3774 /* Check the REX.R bit. */
3775 r = (i.rex & REX_R) ? 0 : 1;
3776 i.vex.bytes[1] = (r << 7
3777 | register_specifier << 3
3778 | vector_length << 2
3779 | i.tm.opcode_modifier.opcodeprefix);
3783 /* 3-byte VEX prefix. */
3786 switch (i.tm.opcode_modifier.opcodespace)
3791 i.vex.bytes[0] = 0xc4;
3796 i.vex.bytes[0] = 0x8f;
3802 /* The high 3 bits of the second VEX byte are 1's compliment
3803 of RXB bits from REX. */
3804 i.vex.bytes[1] = (~i.rex & 0x7) << 5 | i.tm.opcode_modifier.opcodespace;
3806 i.vex.bytes[2] = (w << 7
3807 | register_specifier << 3
3808 | vector_length << 2
3809 | i.tm.opcode_modifier.opcodeprefix);
3814 is_evex_encoding (const insn_template *t)
3816 return t->opcode_modifier.evex || t->opcode_modifier.disp8memshift
3817 || t->opcode_modifier.broadcast || t->opcode_modifier.masking
3818 || t->opcode_modifier.sae;
3822 is_any_vex_encoding (const insn_template *t)
3824 return t->opcode_modifier.vex || is_evex_encoding (t);
3827 /* Build the EVEX prefix. */
3830 build_evex_prefix (void)
3832 unsigned int register_specifier, w;
3833 rex_byte vrex_used = 0;
3835 /* Check register specifier. */
3836 if (i.vex.register_specifier)
3838 gas_assert ((i.vrex & REX_X) == 0);
3840 register_specifier = i.vex.register_specifier->reg_num;
3841 if ((i.vex.register_specifier->reg_flags & RegRex))
3842 register_specifier += 8;
3843 /* The upper 16 registers are encoded in the fourth byte of the
3845 if (!(i.vex.register_specifier->reg_flags & RegVRex))
3846 i.vex.bytes[3] = 0x8;
3847 register_specifier = ~register_specifier & 0xf;
3851 register_specifier = 0xf;
3853 /* Encode upper 16 vector index register in the fourth byte of
3855 if (!(i.vrex & REX_X))
3856 i.vex.bytes[3] = 0x8;
3861 /* 4 byte EVEX prefix. */
3863 i.vex.bytes[0] = 0x62;
3865 /* The high 3 bits of the second EVEX byte are 1's compliment of RXB
3867 gas_assert (i.tm.opcode_modifier.opcodespace >= SPACE_0F);
3868 gas_assert (i.tm.opcode_modifier.opcodespace <= SPACE_0F3A);
3869 i.vex.bytes[1] = (~i.rex & 0x7) << 5 | i.tm.opcode_modifier.opcodespace;
3871 /* The fifth bit of the second EVEX byte is 1's compliment of the
3872 REX_R bit in VREX. */
3873 if (!(i.vrex & REX_R))
3874 i.vex.bytes[1] |= 0x10;
3878 if ((i.reg_operands + i.imm_operands) == i.operands)
3880 /* When all operands are registers, the REX_X bit in REX is not
3881 used. We reuse it to encode the upper 16 registers, which is
3882 indicated by the REX_B bit in VREX. The REX_X bit is encoded
3883 as 1's compliment. */
3884 if ((i.vrex & REX_B))
3887 i.vex.bytes[1] &= ~0x40;
3891 /* EVEX instructions shouldn't need the REX prefix. */
3892 i.vrex &= ~vrex_used;
3893 gas_assert (i.vrex == 0);
3895 /* Check the REX.W bit and VEXW. */
3896 if (i.tm.opcode_modifier.vexw == VEXWIG)
3897 w = (evexwig == evexw1 || (i.rex & REX_W)) ? 1 : 0;
3898 else if (i.tm.opcode_modifier.vexw)
3899 w = i.tm.opcode_modifier.vexw == VEXW1 ? 1 : 0;
3901 w = (flag_code == CODE_64BIT ? i.rex & REX_W : evexwig == evexw1) ? 1 : 0;
3903 /* The third byte of the EVEX prefix. */
3904 i.vex.bytes[2] = ((w << 7)
3905 | (register_specifier << 3)
3906 | 4 /* Encode the U bit. */
3907 | i.tm.opcode_modifier.opcodeprefix);
3909 /* The fourth byte of the EVEX prefix. */
3910 /* The zeroing-masking bit. */
3911 if (i.mask.reg && i.mask.zeroing)
3912 i.vex.bytes[3] |= 0x80;
3914 /* Don't always set the broadcast bit if there is no RC. */
3915 if (i.rounding.type == rc_none)
3917 /* Encode the vector length. */
3918 unsigned int vec_length;
3920 if (!i.tm.opcode_modifier.evex
3921 || i.tm.opcode_modifier.evex == EVEXDYN)
3925 /* Determine vector length from the last multi-length vector
3927 for (op = i.operands; op--;)
3928 if (i.tm.operand_types[op].bitfield.xmmword
3929 + i.tm.operand_types[op].bitfield.ymmword
3930 + i.tm.operand_types[op].bitfield.zmmword > 1)
3932 if (i.types[op].bitfield.zmmword)
3934 i.tm.opcode_modifier.evex = EVEX512;
3937 else if (i.types[op].bitfield.ymmword)
3939 i.tm.opcode_modifier.evex = EVEX256;
3942 else if (i.types[op].bitfield.xmmword)
3944 i.tm.opcode_modifier.evex = EVEX128;
3947 else if (i.broadcast.type && op == i.broadcast.operand)
3949 switch (i.broadcast.bytes)
3952 i.tm.opcode_modifier.evex = EVEX512;
3955 i.tm.opcode_modifier.evex = EVEX256;
3958 i.tm.opcode_modifier.evex = EVEX128;
3967 if (op >= MAX_OPERANDS)
3971 switch (i.tm.opcode_modifier.evex)
3973 case EVEXLIG: /* LL' is ignored */
3974 vec_length = evexlig << 5;
3977 vec_length = 0 << 5;
3980 vec_length = 1 << 5;
3983 vec_length = 2 << 5;
3989 i.vex.bytes[3] |= vec_length;
3990 /* Encode the broadcast bit. */
3991 if (i.broadcast.type)
3992 i.vex.bytes[3] |= 0x10;
3994 else if (i.rounding.type != saeonly)
3995 i.vex.bytes[3] |= 0x10 | (i.rounding.type << 5);
3997 i.vex.bytes[3] |= 0x10 | (evexrcig << 5);
4000 i.vex.bytes[3] |= i.mask.reg->reg_num;
4004 process_immext (void)
4008 /* These AMD 3DNow! and SSE2 instructions have an opcode suffix
4009 which is coded in the same place as an 8-bit immediate field
4010 would be. Here we fake an 8-bit immediate operand from the
4011 opcode suffix stored in tm.extension_opcode.
4013 AVX instructions also use this encoding, for some of
4014 3 argument instructions. */
4016 gas_assert (i.imm_operands <= 1
4018 || (is_any_vex_encoding (&i.tm)
4019 && i.operands <= 4)));
4021 exp = &im_expressions[i.imm_operands++];
4022 i.op[i.operands].imms = exp;
4023 i.types[i.operands] = imm8;
4025 exp->X_op = O_constant;
4026 exp->X_add_number = i.tm.extension_opcode;
4027 i.tm.extension_opcode = None;
4034 switch (i.tm.opcode_modifier.prefixok)
4042 as_bad (_("invalid instruction `%s' after `%s'"),
4043 i.tm.name, i.hle_prefix);
4046 if (i.prefix[LOCK_PREFIX])
4048 as_bad (_("missing `lock' with `%s'"), i.hle_prefix);
4052 case PrefixHLERelease:
4053 if (i.prefix[HLE_PREFIX] != XRELEASE_PREFIX_OPCODE)
4055 as_bad (_("instruction `%s' after `xacquire' not allowed"),
4059 if (i.mem_operands == 0 || !(i.flags[i.operands - 1] & Operand_Mem))
4061 as_bad (_("memory destination needed for instruction `%s'"
4062 " after `xrelease'"), i.tm.name);
4069 /* Try the shortest encoding by shortening operand size. */
4072 optimize_encoding (void)
4076 if (i.tm.opcode_modifier.opcodespace == SPACE_BASE
4077 && i.tm.base_opcode == 0x8d)
4080 lea symbol, %rN -> mov $symbol, %rN
4081 lea (%rM), %rN -> mov %rM, %rN
4082 lea (,%rM,1), %rN -> mov %rM, %rN
4084 and in 32-bit mode for 16-bit addressing
4086 lea (%rM), %rN -> movzx %rM, %rN
4088 and in 64-bit mode zap 32-bit addressing in favor of using a
4089 32-bit (or less) destination.
4091 if (flag_code == CODE_64BIT && i.prefix[ADDR_PREFIX])
4093 if (!i.op[1].regs->reg_type.bitfield.word)
4094 i.tm.opcode_modifier.size = SIZE32;
4095 i.prefix[ADDR_PREFIX] = 0;
4098 if (!i.index_reg && !i.base_reg)
4101 lea symbol, %rN -> mov $symbol, %rN
4103 if (flag_code == CODE_64BIT)
4105 /* Don't transform a relocation to a 16-bit one. */
4107 && i.op[0].disps->X_op != O_constant
4108 && i.op[1].regs->reg_type.bitfield.word)
4111 if (!i.op[1].regs->reg_type.bitfield.qword
4112 || i.tm.opcode_modifier.size == SIZE32)
4114 i.tm.base_opcode = 0xb8;
4115 i.tm.opcode_modifier.modrm = 0;
4116 if (!i.op[1].regs->reg_type.bitfield.word)
4117 i.types[0].bitfield.imm32 = 1;
4120 i.tm.opcode_modifier.size = SIZE16;
4121 i.types[0].bitfield.imm16 = 1;
4126 /* Subject to further optimization below. */
4127 i.tm.base_opcode = 0xc7;
4128 i.tm.extension_opcode = 0;
4129 i.types[0].bitfield.imm32s = 1;
4130 i.types[0].bitfield.baseindex = 0;
4133 /* Outside of 64-bit mode address and operand sizes have to match if
4134 a relocation is involved, as otherwise we wouldn't (currently) or
4135 even couldn't express the relocation correctly. */
4136 else if (i.op[0].disps
4137 && i.op[0].disps->X_op != O_constant
4138 && ((!i.prefix[ADDR_PREFIX])
4139 != (flag_code == CODE_32BIT
4140 ? i.op[1].regs->reg_type.bitfield.dword
4141 : i.op[1].regs->reg_type.bitfield.word)))
4143 /* In 16-bit mode converting LEA with 16-bit addressing and a 32-bit
4144 destination is going to grow encoding size. */
4145 else if (flag_code == CODE_16BIT
4146 && (optimize <= 1 || optimize_for_space)
4147 && !i.prefix[ADDR_PREFIX]
4148 && i.op[1].regs->reg_type.bitfield.dword)
4152 i.tm.base_opcode = 0xb8;
4153 i.tm.opcode_modifier.modrm = 0;
4154 if (i.op[1].regs->reg_type.bitfield.dword)
4155 i.types[0].bitfield.imm32 = 1;
4157 i.types[0].bitfield.imm16 = 1;
4160 && i.op[0].disps->X_op == O_constant
4161 && i.op[1].regs->reg_type.bitfield.dword
4162 /* NB: Add () to !i.prefix[ADDR_PREFIX] to silence
4164 && (!i.prefix[ADDR_PREFIX]) != (flag_code == CODE_32BIT))
4165 i.op[0].disps->X_add_number &= 0xffff;
4168 i.tm.operand_types[0] = i.types[0];
4172 i.op[0].imms = &im_expressions[0];
4173 i.op[0].imms->X_op = O_absent;
4176 else if (i.op[0].disps
4177 && (i.op[0].disps->X_op != O_constant
4178 || i.op[0].disps->X_add_number))
4183 lea (%rM), %rN -> mov %rM, %rN
4184 lea (,%rM,1), %rN -> mov %rM, %rN
4185 lea (%rM), %rN -> movzx %rM, %rN
4187 const reg_entry *addr_reg;
4189 if (!i.index_reg && i.base_reg->reg_num != RegIP)
4190 addr_reg = i.base_reg;
4191 else if (!i.base_reg
4192 && i.index_reg->reg_num != RegIZ
4193 && !i.log2_scale_factor)
4194 addr_reg = i.index_reg;
4198 if (addr_reg->reg_type.bitfield.word
4199 && i.op[1].regs->reg_type.bitfield.dword)
4201 if (flag_code != CODE_32BIT)
4203 i.tm.opcode_modifier.opcodespace = SPACE_0F;
4204 i.tm.base_opcode = 0xb7;
4207 i.tm.base_opcode = 0x8b;
4209 if (addr_reg->reg_type.bitfield.dword
4210 && i.op[1].regs->reg_type.bitfield.qword)
4211 i.tm.opcode_modifier.size = SIZE32;
4213 i.op[0].regs = addr_reg;
4218 i.disp_operands = 0;
4219 i.prefix[ADDR_PREFIX] = 0;
4220 i.prefix[SEG_PREFIX] = 0;
4224 if (optimize_for_space
4225 && i.tm.opcode_modifier.opcodespace == SPACE_BASE
4226 && i.reg_operands == 1
4227 && i.imm_operands == 1
4228 && !i.types[1].bitfield.byte
4229 && i.op[0].imms->X_op == O_constant
4230 && fits_in_imm7 (i.op[0].imms->X_add_number)
4231 && (i.tm.base_opcode == 0xa8
4232 || (i.tm.base_opcode == 0xf6
4233 && i.tm.extension_opcode == 0x0)))
4236 test $imm7, %r64/%r32/%r16 -> test $imm7, %r8
4238 unsigned int base_regnum = i.op[1].regs->reg_num;
4239 if (flag_code == CODE_64BIT || base_regnum < 4)
4241 i.types[1].bitfield.byte = 1;
4242 /* Ignore the suffix. */
4244 /* Convert to byte registers. */
4245 if (i.types[1].bitfield.word)
4247 else if (i.types[1].bitfield.dword)
4251 if (!(i.op[1].regs->reg_flags & RegRex) && base_regnum < 4)
4256 else if (flag_code == CODE_64BIT
4257 && i.tm.opcode_modifier.opcodespace == SPACE_BASE
4258 && ((i.types[1].bitfield.qword
4259 && i.reg_operands == 1
4260 && i.imm_operands == 1
4261 && i.op[0].imms->X_op == O_constant
4262 && ((i.tm.base_opcode == 0xb8
4263 && i.tm.extension_opcode == None
4264 && fits_in_unsigned_long (i.op[0].imms->X_add_number))
4265 || (fits_in_imm31 (i.op[0].imms->X_add_number)
4266 && ((i.tm.base_opcode == 0x24
4267 || i.tm.base_opcode == 0xa8)
4268 || (i.tm.base_opcode == 0x80
4269 && i.tm.extension_opcode == 0x4)
4270 || ((i.tm.base_opcode == 0xf6
4271 || (i.tm.base_opcode | 1) == 0xc7)
4272 && i.tm.extension_opcode == 0x0)))
4273 || (fits_in_imm7 (i.op[0].imms->X_add_number)
4274 && i.tm.base_opcode == 0x83
4275 && i.tm.extension_opcode == 0x4)))
4276 || (i.types[0].bitfield.qword
4277 && ((i.reg_operands == 2
4278 && i.op[0].regs == i.op[1].regs
4279 && (i.tm.base_opcode == 0x30
4280 || i.tm.base_opcode == 0x28))
4281 || (i.reg_operands == 1
4283 && i.tm.base_opcode == 0x30)))))
4286 andq $imm31, %r64 -> andl $imm31, %r32
4287 andq $imm7, %r64 -> andl $imm7, %r32
4288 testq $imm31, %r64 -> testl $imm31, %r32
4289 xorq %r64, %r64 -> xorl %r32, %r32
4290 subq %r64, %r64 -> subl %r32, %r32
4291 movq $imm31, %r64 -> movl $imm31, %r32
4292 movq $imm32, %r64 -> movl $imm32, %r32
4294 i.tm.opcode_modifier.norex64 = 1;
4295 if (i.tm.base_opcode == 0xb8 || (i.tm.base_opcode | 1) == 0xc7)
4298 movq $imm31, %r64 -> movl $imm31, %r32
4299 movq $imm32, %r64 -> movl $imm32, %r32
4301 i.tm.operand_types[0].bitfield.imm32 = 1;
4302 i.tm.operand_types[0].bitfield.imm32s = 0;
4303 i.tm.operand_types[0].bitfield.imm64 = 0;
4304 i.types[0].bitfield.imm32 = 1;
4305 i.types[0].bitfield.imm32s = 0;
4306 i.types[0].bitfield.imm64 = 0;
4307 i.types[1].bitfield.dword = 1;
4308 i.types[1].bitfield.qword = 0;
4309 if ((i.tm.base_opcode | 1) == 0xc7)
4312 movq $imm31, %r64 -> movl $imm31, %r32
4314 i.tm.base_opcode = 0xb8;
4315 i.tm.extension_opcode = None;
4316 i.tm.opcode_modifier.w = 0;
4317 i.tm.opcode_modifier.modrm = 0;
4321 else if (optimize > 1
4322 && !optimize_for_space
4323 && i.tm.opcode_modifier.opcodespace == SPACE_BASE
4324 && i.reg_operands == 2
4325 && i.op[0].regs == i.op[1].regs
4326 && ((i.tm.base_opcode & ~(Opcode_D | 1)) == 0x8
4327 || (i.tm.base_opcode & ~(Opcode_D | 1)) == 0x20)
4328 && (flag_code != CODE_64BIT || !i.types[0].bitfield.dword))
4331 andb %rN, %rN -> testb %rN, %rN
4332 andw %rN, %rN -> testw %rN, %rN
4333 andq %rN, %rN -> testq %rN, %rN
4334 orb %rN, %rN -> testb %rN, %rN
4335 orw %rN, %rN -> testw %rN, %rN
4336 orq %rN, %rN -> testq %rN, %rN
4338 and outside of 64-bit mode
4340 andl %rN, %rN -> testl %rN, %rN
4341 orl %rN, %rN -> testl %rN, %rN
4343 i.tm.base_opcode = 0x84 | (i.tm.base_opcode & 1);
4345 else if (i.reg_operands == 3
4346 && i.op[0].regs == i.op[1].regs
4347 && !i.types[2].bitfield.xmmword
4348 && (i.tm.opcode_modifier.vex
4349 || ((!i.mask.reg || i.mask.zeroing)
4350 && i.rounding.type == rc_none
4351 && is_evex_encoding (&i.tm)
4352 && (i.vec_encoding != vex_encoding_evex
4353 || cpu_arch_isa_flags.bitfield.cpuavx512vl
4354 || i.tm.cpu_flags.bitfield.cpuavx512vl
4355 || (i.tm.operand_types[2].bitfield.zmmword
4356 && i.types[2].bitfield.ymmword))))
4357 && ((i.tm.base_opcode == 0x55
4358 || i.tm.base_opcode == 0x57
4359 || i.tm.base_opcode == 0xdf
4360 || i.tm.base_opcode == 0xef
4361 || i.tm.base_opcode == 0xf8
4362 || i.tm.base_opcode == 0xf9
4363 || i.tm.base_opcode == 0xfa
4364 || i.tm.base_opcode == 0xfb
4365 || i.tm.base_opcode == 0x42
4366 || i.tm.base_opcode == 0x47)
4367 && i.tm.extension_opcode == None))
4370 VOP, one of vandnps, vandnpd, vxorps, vxorpd, vpsubb, vpsubd,
4372 EVEX VOP %zmmM, %zmmM, %zmmN
4373 -> VEX VOP %xmmM, %xmmM, %xmmN (M and N < 16)
4374 -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2)
4375 EVEX VOP %ymmM, %ymmM, %ymmN
4376 -> VEX VOP %xmmM, %xmmM, %xmmN (M and N < 16)
4377 -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2)
4378 VEX VOP %ymmM, %ymmM, %ymmN
4379 -> VEX VOP %xmmM, %xmmM, %xmmN
4380 VOP, one of vpandn and vpxor:
4381 VEX VOP %ymmM, %ymmM, %ymmN
4382 -> VEX VOP %xmmM, %xmmM, %xmmN
4383 VOP, one of vpandnd and vpandnq:
4384 EVEX VOP %zmmM, %zmmM, %zmmN
4385 -> VEX vpandn %xmmM, %xmmM, %xmmN (M and N < 16)
4386 -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2)
4387 EVEX VOP %ymmM, %ymmM, %ymmN
4388 -> VEX vpandn %xmmM, %xmmM, %xmmN (M and N < 16)
4389 -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2)
4390 VOP, one of vpxord and vpxorq:
4391 EVEX VOP %zmmM, %zmmM, %zmmN
4392 -> VEX vpxor %xmmM, %xmmM, %xmmN (M and N < 16)
4393 -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2)
4394 EVEX VOP %ymmM, %ymmM, %ymmN
4395 -> VEX vpxor %xmmM, %xmmM, %xmmN (M and N < 16)
4396 -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2)
4397 VOP, one of kxord and kxorq:
4398 VEX VOP %kM, %kM, %kN
4399 -> VEX kxorw %kM, %kM, %kN
4400 VOP, one of kandnd and kandnq:
4401 VEX VOP %kM, %kM, %kN
4402 -> VEX kandnw %kM, %kM, %kN
4404 if (is_evex_encoding (&i.tm))
4406 if (i.vec_encoding != vex_encoding_evex)
4408 i.tm.opcode_modifier.vex = VEX128;
4409 i.tm.opcode_modifier.vexw = VEXW0;
4410 i.tm.opcode_modifier.evex = 0;
4412 else if (optimize > 1)
4413 i.tm.opcode_modifier.evex = EVEX128;
4417 else if (i.tm.operand_types[0].bitfield.class == RegMask)
4419 i.tm.opcode_modifier.opcodeprefix = PREFIX_NONE;
4420 i.tm.opcode_modifier.vexw = VEXW0;
4423 i.tm.opcode_modifier.vex = VEX128;
4425 if (i.tm.opcode_modifier.vex)
4426 for (j = 0; j < 3; j++)
4428 i.types[j].bitfield.xmmword = 1;
4429 i.types[j].bitfield.ymmword = 0;
4432 else if (i.vec_encoding != vex_encoding_evex
4433 && !i.types[0].bitfield.zmmword
4434 && !i.types[1].bitfield.zmmword
4436 && !i.broadcast.type
4437 && is_evex_encoding (&i.tm)
4438 && ((i.tm.base_opcode & ~Opcode_SIMD_IntD) == 0x6f
4439 || (i.tm.base_opcode & ~4) == 0xdb
4440 || (i.tm.base_opcode & ~4) == 0xeb)
4441 && i.tm.extension_opcode == None)
4444 VOP, one of vmovdqa32, vmovdqa64, vmovdqu8, vmovdqu16,
4445 vmovdqu32 and vmovdqu64:
4446 EVEX VOP %xmmM, %xmmN
4447 -> VEX vmovdqa|vmovdqu %xmmM, %xmmN (M and N < 16)
4448 EVEX VOP %ymmM, %ymmN
4449 -> VEX vmovdqa|vmovdqu %ymmM, %ymmN (M and N < 16)
4451 -> VEX vmovdqa|vmovdqu %xmmM, mem (M < 16)
4453 -> VEX vmovdqa|vmovdqu %ymmM, mem (M < 16)
4455 -> VEX mvmovdqa|vmovdquem, %xmmN (N < 16)
4457 -> VEX vmovdqa|vmovdqu mem, %ymmN (N < 16)
4458 VOP, one of vpand, vpandn, vpor, vpxor:
4459 EVEX VOP{d,q} %xmmL, %xmmM, %xmmN
4460 -> VEX VOP %xmmL, %xmmM, %xmmN (L, M, and N < 16)
4461 EVEX VOP{d,q} %ymmL, %ymmM, %ymmN
4462 -> VEX VOP %ymmL, %ymmM, %ymmN (L, M, and N < 16)
4463 EVEX VOP{d,q} mem, %xmmM, %xmmN
4464 -> VEX VOP mem, %xmmM, %xmmN (M and N < 16)
4465 EVEX VOP{d,q} mem, %ymmM, %ymmN
4466 -> VEX VOP mem, %ymmM, %ymmN (M and N < 16)
4468 for (j = 0; j < i.operands; j++)
4469 if (operand_type_check (i.types[j], disp)
4470 && i.op[j].disps->X_op == O_constant)
4472 /* Since the VEX prefix has 2 or 3 bytes, the EVEX prefix
4473 has 4 bytes, EVEX Disp8 has 1 byte and VEX Disp32 has 4
4474 bytes, we choose EVEX Disp8 over VEX Disp32. */
4475 int evex_disp8, vex_disp8;
4476 unsigned int memshift = i.memshift;
4477 offsetT n = i.op[j].disps->X_add_number;
4479 evex_disp8 = fits_in_disp8 (n);
4481 vex_disp8 = fits_in_disp8 (n);
4482 if (evex_disp8 != vex_disp8)
4484 i.memshift = memshift;
4488 i.types[j].bitfield.disp8 = vex_disp8;
4491 if ((i.tm.base_opcode & ~Opcode_SIMD_IntD) == 0x6f
4492 && i.tm.opcode_modifier.opcodeprefix == PREFIX_0XF2)
4493 i.tm.opcode_modifier.opcodeprefix = PREFIX_0XF3;
4494 i.tm.opcode_modifier.vex
4495 = i.types[0].bitfield.ymmword ? VEX256 : VEX128;
4496 i.tm.opcode_modifier.vexw = VEXW0;
4497 /* VPAND, VPOR, and VPXOR are commutative. */
4498 if (i.reg_operands == 3 && i.tm.base_opcode != 0xdf)
4499 i.tm.opcode_modifier.commutative = 1;
4500 i.tm.opcode_modifier.evex = 0;
4501 i.tm.opcode_modifier.masking = 0;
4502 i.tm.opcode_modifier.broadcast = 0;
4503 i.tm.opcode_modifier.disp8memshift = 0;
4506 i.types[j].bitfield.disp8
4507 = fits_in_disp8 (i.op[j].disps->X_add_number);
4511 /* Return non-zero for load instruction. */
4517 int any_vex_p = is_any_vex_encoding (&i.tm);
4518 unsigned int base_opcode = i.tm.base_opcode | 1;
4522 /* Anysize insns: lea, invlpg, clflush, prefetchnta, prefetcht0,
4523 prefetcht1, prefetcht2, prefetchtw, bndmk, bndcl, bndcu, bndcn,
4524 bndstx, bndldx, prefetchwt1, clflushopt, clwb, cldemote. */
4525 if (i.tm.opcode_modifier.anysize)
4529 if (strcmp (i.tm.name, "pop") == 0)
4533 if (i.tm.opcode_modifier.opcodespace == SPACE_BASE)
4536 if (i.tm.base_opcode == 0x9d
4537 || i.tm.base_opcode == 0x61)
4540 /* movs, cmps, lods, scas. */
4541 if ((i.tm.base_opcode | 0xb) == 0xaf)
4545 if (base_opcode == 0x6f
4546 || i.tm.base_opcode == 0xd7)
4548 /* NB: For AMD-specific insns with implicit memory operands,
4549 they're intentionally not covered. */
4552 /* No memory operand. */
4553 if (!i.mem_operands)
4559 if (i.tm.base_opcode == 0xae
4560 && i.tm.opcode_modifier.vex
4561 && i.tm.opcode_modifier.opcodespace == SPACE_0F
4562 && i.tm.opcode_modifier.opcodeprefix == PREFIX_NONE
4563 && i.tm.extension_opcode == 2)
4566 else if (i.tm.opcode_modifier.opcodespace == SPACE_BASE)
4568 /* test, not, neg, mul, imul, div, idiv. */
4569 if ((i.tm.base_opcode == 0xf6 || i.tm.base_opcode == 0xf7)
4570 && i.tm.extension_opcode != 1)
4574 if (base_opcode == 0xff && i.tm.extension_opcode <= 1)
4577 /* add, or, adc, sbb, and, sub, xor, cmp. */
4578 if (i.tm.base_opcode >= 0x80 && i.tm.base_opcode <= 0x83)
4581 /* rol, ror, rcl, rcr, shl/sal, shr, sar. */
4582 if ((base_opcode == 0xc1
4583 || (i.tm.base_opcode >= 0xd0 && i.tm.base_opcode <= 0xd3))
4584 && i.tm.extension_opcode != 6)
4587 /* Check for x87 instructions. */
4588 if (base_opcode >= 0xd8 && base_opcode <= 0xdf)
4590 /* Skip fst, fstp, fstenv, fstcw. */
4591 if (i.tm.base_opcode == 0xd9
4592 && (i.tm.extension_opcode == 2
4593 || i.tm.extension_opcode == 3
4594 || i.tm.extension_opcode == 6
4595 || i.tm.extension_opcode == 7))
4598 /* Skip fisttp, fist, fistp, fstp. */
4599 if (i.tm.base_opcode == 0xdb
4600 && (i.tm.extension_opcode == 1
4601 || i.tm.extension_opcode == 2
4602 || i.tm.extension_opcode == 3
4603 || i.tm.extension_opcode == 7))
4606 /* Skip fisttp, fst, fstp, fsave, fstsw. */
4607 if (i.tm.base_opcode == 0xdd
4608 && (i.tm.extension_opcode == 1
4609 || i.tm.extension_opcode == 2
4610 || i.tm.extension_opcode == 3
4611 || i.tm.extension_opcode == 6
4612 || i.tm.extension_opcode == 7))
4615 /* Skip fisttp, fist, fistp, fbstp, fistp. */
4616 if (i.tm.base_opcode == 0xdf
4617 && (i.tm.extension_opcode == 1
4618 || i.tm.extension_opcode == 2
4619 || i.tm.extension_opcode == 3
4620 || i.tm.extension_opcode == 6
4621 || i.tm.extension_opcode == 7))
4627 else if (i.tm.opcode_modifier.opcodespace == SPACE_0F)
4629 /* bt, bts, btr, btc. */
4630 if (i.tm.base_opcode == 0xba
4631 && (i.tm.extension_opcode >= 4 && i.tm.extension_opcode <= 7))
4634 /* cmpxchg8b, cmpxchg16b, xrstors, vmptrld. */
4635 if (i.tm.base_opcode == 0xc7
4636 && i.tm.opcode_modifier.opcodeprefix == PREFIX_NONE
4637 && (i.tm.extension_opcode == 1 || i.tm.extension_opcode == 3
4638 || i.tm.extension_opcode == 6))
4641 /* fxrstor, ldmxcsr, xrstor. */
4642 if (i.tm.base_opcode == 0xae
4643 && (i.tm.extension_opcode == 1
4644 || i.tm.extension_opcode == 2
4645 || i.tm.extension_opcode == 5))
4648 /* lgdt, lidt, lmsw. */
4649 if (i.tm.base_opcode == 0x01
4650 && (i.tm.extension_opcode == 2
4651 || i.tm.extension_opcode == 3
4652 || i.tm.extension_opcode == 6))
4656 dest = i.operands - 1;
4658 /* Check fake imm8 operand and 3 source operands. */
4659 if ((i.tm.opcode_modifier.immext
4660 || i.tm.opcode_modifier.vexsources == VEX3SOURCES)
4661 && i.types[dest].bitfield.imm8)
4664 /* add, or, adc, sbb, and, sub, xor, cmp, test, xchg. */
4665 if (i.tm.opcode_modifier.opcodespace == SPACE_BASE
4666 && (base_opcode == 0x1
4667 || base_opcode == 0x9
4668 || base_opcode == 0x11
4669 || base_opcode == 0x19
4670 || base_opcode == 0x21
4671 || base_opcode == 0x29
4672 || base_opcode == 0x31
4673 || base_opcode == 0x39
4674 || (base_opcode | 2) == 0x87))
4678 if (i.tm.opcode_modifier.opcodespace == SPACE_0F
4679 && base_opcode == 0xc1)
4682 /* Check for load instruction. */
4683 return (i.types[dest].bitfield.class != ClassNone
4684 || i.types[dest].bitfield.instance == Accum);
4687 /* Output lfence, 0xfaee8, after instruction. */
4690 insert_lfence_after (void)
4692 if (lfence_after_load && load_insn_p ())
4694 /* There are also two REP string instructions that require
4695 special treatment. Specifically, the compare string (CMPS)
4696 and scan string (SCAS) instructions set EFLAGS in a manner
4697 that depends on the data being compared/scanned. When used
4698 with a REP prefix, the number of iterations may therefore
4699 vary depending on this data. If the data is a program secret
4700 chosen by the adversary using an LVI method,
4701 then this data-dependent behavior may leak some aspect
4703 if (((i.tm.base_opcode | 0x1) == 0xa7
4704 || (i.tm.base_opcode | 0x1) == 0xaf)
4705 && i.prefix[REP_PREFIX])
4707 as_warn (_("`%s` changes flags which would affect control flow behavior"),
4710 char *p = frag_more (3);
4717 /* Output lfence, 0xfaee8, before instruction. */
4720 insert_lfence_before (void)
4724 if (i.tm.opcode_modifier.opcodespace != SPACE_BASE)
4727 if (i.tm.base_opcode == 0xff
4728 && (i.tm.extension_opcode == 2 || i.tm.extension_opcode == 4))
4730 /* Insert lfence before indirect branch if needed. */
4732 if (lfence_before_indirect_branch == lfence_branch_none)
4735 if (i.operands != 1)
4738 if (i.reg_operands == 1)
4740 /* Indirect branch via register. Don't insert lfence with
4741 -mlfence-after-load=yes. */
4742 if (lfence_after_load
4743 || lfence_before_indirect_branch == lfence_branch_memory)
4746 else if (i.mem_operands == 1
4747 && lfence_before_indirect_branch != lfence_branch_register)
4749 as_warn (_("indirect `%s` with memory operand should be avoided"),
4756 if (last_insn.kind != last_insn_other
4757 && last_insn.seg == now_seg)
4759 as_warn_where (last_insn.file, last_insn.line,
4760 _("`%s` skips -mlfence-before-indirect-branch on `%s`"),
4761 last_insn.name, i.tm.name);
4772 /* Output or/not/shl and lfence before near ret. */
4773 if (lfence_before_ret != lfence_before_ret_none
4774 && (i.tm.base_opcode == 0xc2
4775 || i.tm.base_opcode == 0xc3))
4777 if (last_insn.kind != last_insn_other
4778 && last_insn.seg == now_seg)
4780 as_warn_where (last_insn.file, last_insn.line,
4781 _("`%s` skips -mlfence-before-ret on `%s`"),
4782 last_insn.name, i.tm.name);
4786 /* Near ret ingore operand size override under CPU64. */
4787 char prefix = flag_code == CODE_64BIT
4789 : i.prefix[DATA_PREFIX] ? 0x66 : 0x0;
4791 if (lfence_before_ret == lfence_before_ret_not)
4793 /* not: 0xf71424, may add prefix
4794 for operand size override or 64-bit code. */
4795 p = frag_more ((prefix ? 2 : 0) + 6 + 3);
4809 p = frag_more ((prefix ? 1 : 0) + 4 + 3);
4812 if (lfence_before_ret == lfence_before_ret_or)
4814 /* or: 0x830c2400, may add prefix
4815 for operand size override or 64-bit code. */
4821 /* shl: 0xc1242400, may add prefix
4822 for operand size override or 64-bit code. */
4837 /* This is the guts of the machine-dependent assembler. LINE points to a
4838 machine dependent instruction. This function is supposed to emit
4839 the frags/bytes it assembles to. */
4842 md_assemble (char *line)
4845 char mnemonic[MAX_MNEM_SIZE], mnem_suffix;
4846 const insn_template *t;
4848 /* Initialize globals. */
4849 memset (&i, '\0', sizeof (i));
4850 i.rounding.type = rc_none;
4851 for (j = 0; j < MAX_OPERANDS; j++)
4852 i.reloc[j] = NO_RELOC;
4853 memset (disp_expressions, '\0', sizeof (disp_expressions));
4854 memset (im_expressions, '\0', sizeof (im_expressions));
4855 save_stack_p = save_stack;
4857 /* First parse an instruction mnemonic & call i386_operand for the operands.
4858 We assume that the scrubber has arranged it so that line[0] is the valid
4859 start of a (possibly prefixed) mnemonic. */
4861 line = parse_insn (line, mnemonic);
4864 mnem_suffix = i.suffix;
4866 line = parse_operands (line, mnemonic);
4868 xfree (i.memop1_string);
4869 i.memop1_string = NULL;
4873 /* Now we've parsed the mnemonic into a set of templates, and have the
4874 operands at hand. */
4876 /* All Intel opcodes have reversed operands except for "bound", "enter",
4877 "invlpg*", "monitor*", "mwait*", "tpause", "umwait", "pvalidate",
4878 "rmpadjust", and "rmpupdate". We also don't reverse intersegment "jmp"
4879 and "call" instructions with 2 immediate operands so that the immediate
4880 segment precedes the offset consistently in Intel and AT&T modes. */
4883 && (strcmp (mnemonic, "bound") != 0)
4884 && (strncmp (mnemonic, "invlpg", 6) != 0)
4885 && !startswith (mnemonic, "monitor")
4886 && !startswith (mnemonic, "mwait")
4887 && (strcmp (mnemonic, "pvalidate") != 0)
4888 && !startswith (mnemonic, "rmp")
4889 && (strcmp (mnemonic, "tpause") != 0)
4890 && (strcmp (mnemonic, "umwait") != 0)
4891 && !(operand_type_check (i.types[0], imm)
4892 && operand_type_check (i.types[1], imm)))
4895 /* The order of the immediates should be reversed
4896 for 2 immediates extrq and insertq instructions */
4897 if (i.imm_operands == 2
4898 && (strcmp (mnemonic, "extrq") == 0
4899 || strcmp (mnemonic, "insertq") == 0))
4900 swap_2_operands (0, 1);
4905 if (i.disp_operands && !want_disp32 (current_templates->start))
4907 for (j = 0; j < i.operands; ++j)
4909 const expressionS *exp = i.op[j].disps;
4911 if (!operand_type_check (i.types[j], disp))
4914 if (exp->X_op != O_constant)
4917 /* Since displacement is signed extended to 64bit, don't allow
4918 disp32 and turn off disp32s if they are out of range. */
4919 i.types[j].bitfield.disp32 = 0;
4920 if (fits_in_signed_long (exp->X_add_number))
4923 i.types[j].bitfield.disp32s = 0;
4924 if (i.types[j].bitfield.baseindex)
4926 as_bad (_("0x%" BFD_VMA_FMT "x out of range of signed 32bit displacement"),
4933 /* Don't optimize displacement for movabs since it only takes 64bit
4936 && i.disp_encoding != disp_encoding_32bit
4937 && (flag_code != CODE_64BIT
4938 || strcmp (mnemonic, "movabs") != 0))
4941 /* Next, we find a template that matches the given insn,
4942 making sure the overlap of the given operands types is consistent
4943 with the template operand types. */
4945 if (!(t = match_template (mnem_suffix)))
4948 if (sse_check != check_none
4949 && !i.tm.opcode_modifier.noavx
4950 && !i.tm.cpu_flags.bitfield.cpuavx
4951 && !i.tm.cpu_flags.bitfield.cpuavx512f
4952 && (i.tm.cpu_flags.bitfield.cpusse
4953 || i.tm.cpu_flags.bitfield.cpusse2
4954 || i.tm.cpu_flags.bitfield.cpusse3
4955 || i.tm.cpu_flags.bitfield.cpussse3
4956 || i.tm.cpu_flags.bitfield.cpusse4_1
4957 || i.tm.cpu_flags.bitfield.cpusse4_2
4958 || i.tm.cpu_flags.bitfield.cpupclmul
4959 || i.tm.cpu_flags.bitfield.cpuaes
4960 || i.tm.cpu_flags.bitfield.cpusha
4961 || i.tm.cpu_flags.bitfield.cpugfni))
4963 (sse_check == check_warning
4965 : as_bad) (_("SSE instruction `%s' is used"), i.tm.name);
4968 if (i.tm.opcode_modifier.fwait)
4969 if (!add_prefix (FWAIT_OPCODE))
4972 /* Check if REP prefix is OK. */
4973 if (i.rep_prefix && i.tm.opcode_modifier.prefixok != PrefixRep)
4975 as_bad (_("invalid instruction `%s' after `%s'"),
4976 i.tm.name, i.rep_prefix);
4980 /* Check for lock without a lockable instruction. Destination operand
4981 must be memory unless it is xchg (0x86). */
4982 if (i.prefix[LOCK_PREFIX]
4983 && (i.tm.opcode_modifier.prefixok < PrefixLock
4984 || i.mem_operands == 0
4985 || (i.tm.base_opcode != 0x86
4986 && !(i.flags[i.operands - 1] & Operand_Mem))))
4988 as_bad (_("expecting lockable instruction after `lock'"));
4992 /* Check for data size prefix on VEX/XOP/EVEX encoded and SIMD insns. */
4993 if (i.prefix[DATA_PREFIX]
4994 && (is_any_vex_encoding (&i.tm)
4995 || i.tm.operand_types[i.imm_operands].bitfield.class >= RegMMX
4996 || i.tm.operand_types[i.imm_operands + 1].bitfield.class >= RegMMX))
4998 as_bad (_("data size prefix invalid with `%s'"), i.tm.name);
5002 /* Check if HLE prefix is OK. */
5003 if (i.hle_prefix && !check_hle ())
5006 /* Check BND prefix. */
5007 if (i.bnd_prefix && !i.tm.opcode_modifier.bndprefixok)
5008 as_bad (_("expecting valid branch instruction after `bnd'"));
5010 /* Check NOTRACK prefix. */
5011 if (i.notrack_prefix && i.tm.opcode_modifier.prefixok != PrefixNoTrack)
5012 as_bad (_("expecting indirect branch instruction after `notrack'"));
5014 if (i.tm.cpu_flags.bitfield.cpumpx)
5016 if (flag_code == CODE_64BIT && i.prefix[ADDR_PREFIX])
5017 as_bad (_("32-bit address isn't allowed in 64-bit MPX instructions."));
5018 else if (flag_code != CODE_16BIT
5019 ? i.prefix[ADDR_PREFIX]
5020 : i.mem_operands && !i.prefix[ADDR_PREFIX])
5021 as_bad (_("16-bit address isn't allowed in MPX instructions"));
5024 /* Insert BND prefix. */
5025 if (add_bnd_prefix && i.tm.opcode_modifier.bndprefixok)
5027 if (!i.prefix[BND_PREFIX])
5028 add_prefix (BND_PREFIX_OPCODE);
5029 else if (i.prefix[BND_PREFIX] != BND_PREFIX_OPCODE)
5031 as_warn (_("replacing `rep'/`repe' prefix by `bnd'"));
5032 i.prefix[BND_PREFIX] = BND_PREFIX_OPCODE;
5036 /* Check string instruction segment overrides. */
5037 if (i.tm.opcode_modifier.isstring >= IS_STRING_ES_OP0)
5039 gas_assert (i.mem_operands);
5040 if (!check_string ())
5042 i.disp_operands = 0;
5045 if (optimize && !i.no_optimize && i.tm.opcode_modifier.optimize)
5046 optimize_encoding ();
5048 if (!process_suffix ())
5051 /* Update operand types and check extended states. */
5052 for (j = 0; j < i.operands; j++)
5054 i.types[j] = operand_type_and (i.types[j], i.tm.operand_types[j]);
5055 switch (i.tm.operand_types[j].bitfield.class)
5060 i.xstate |= xstate_mmx;
5063 i.xstate |= xstate_mask;
5066 if (i.tm.operand_types[j].bitfield.tmmword)
5067 i.xstate |= xstate_tmm;
5068 else if (i.tm.operand_types[j].bitfield.zmmword)
5069 i.xstate |= xstate_zmm;
5070 else if (i.tm.operand_types[j].bitfield.ymmword)
5071 i.xstate |= xstate_ymm;
5072 else if (i.tm.operand_types[j].bitfield.xmmword)
5073 i.xstate |= xstate_xmm;
5078 /* Make still unresolved immediate matches conform to size of immediate
5079 given in i.suffix. */
5080 if (!finalize_imm ())
5083 if (i.types[0].bitfield.imm1)
5084 i.imm_operands = 0; /* kludge for shift insns. */
5086 /* We only need to check those implicit registers for instructions
5087 with 3 operands or less. */
5088 if (i.operands <= 3)
5089 for (j = 0; j < i.operands; j++)
5090 if (i.types[j].bitfield.instance != InstanceNone
5091 && !i.types[j].bitfield.xmmword)
5094 /* For insns with operands there are more diddles to do to the opcode. */
5097 if (!process_operands ())
5100 else if (!quiet_warnings && i.tm.opcode_modifier.ugh)
5102 /* UnixWare fsub no args is alias for fsubp, fadd -> faddp, etc. */
5103 as_warn (_("translating to `%sp'"), i.tm.name);
5106 if (is_any_vex_encoding (&i.tm))
5108 if (!cpu_arch_flags.bitfield.cpui286)
5110 as_bad (_("instruction `%s' isn't supported outside of protected mode."),
5115 /* Check for explicit REX prefix. */
5116 if (i.prefix[REX_PREFIX] || i.rex_encoding)
5118 as_bad (_("REX prefix invalid with `%s'"), i.tm.name);
5122 if (i.tm.opcode_modifier.vex)
5123 build_vex_prefix (t);
5125 build_evex_prefix ();
5127 /* The individual REX.RXBW bits got consumed. */
5128 i.rex &= REX_OPCODE;
5131 /* Handle conversion of 'int $3' --> special int3 insn. XOP or FMA4
5132 instructions may define INT_OPCODE as well, so avoid this corner
5133 case for those instructions that use MODRM. */
5134 if (i.tm.opcode_modifier.opcodespace == SPACE_BASE
5135 && i.tm.base_opcode == INT_OPCODE
5136 && !i.tm.opcode_modifier.modrm
5137 && i.op[0].imms->X_add_number == 3)
5139 i.tm.base_opcode = INT3_OPCODE;
5143 if ((i.tm.opcode_modifier.jump == JUMP
5144 || i.tm.opcode_modifier.jump == JUMP_BYTE
5145 || i.tm.opcode_modifier.jump == JUMP_DWORD)
5146 && i.op[0].disps->X_op == O_constant)
5148 /* Convert "jmp constant" (and "call constant") to a jump (call) to
5149 the absolute address given by the constant. Since ix86 jumps and
5150 calls are pc relative, we need to generate a reloc. */
5151 i.op[0].disps->X_add_symbol = &abs_symbol;
5152 i.op[0].disps->X_op = O_symbol;
5155 /* For 8 bit registers we need an empty rex prefix. Also if the
5156 instruction already has a prefix, we need to convert old
5157 registers to new ones. */
5159 if ((i.types[0].bitfield.class == Reg && i.types[0].bitfield.byte
5160 && (i.op[0].regs->reg_flags & RegRex64) != 0)
5161 || (i.types[1].bitfield.class == Reg && i.types[1].bitfield.byte
5162 && (i.op[1].regs->reg_flags & RegRex64) != 0)
5163 || (((i.types[0].bitfield.class == Reg && i.types[0].bitfield.byte)
5164 || (i.types[1].bitfield.class == Reg && i.types[1].bitfield.byte))
5169 i.rex |= REX_OPCODE;
5170 for (x = 0; x < 2; x++)
5172 /* Look for 8 bit operand that uses old registers. */
5173 if (i.types[x].bitfield.class == Reg && i.types[x].bitfield.byte
5174 && (i.op[x].regs->reg_flags & RegRex64) == 0)
5176 gas_assert (!(i.op[x].regs->reg_flags & RegRex));
5177 /* In case it is "hi" register, give up. */
5178 if (i.op[x].regs->reg_num > 3)
5179 as_bad (_("can't encode register '%s%s' in an "
5180 "instruction requiring REX prefix."),
5181 register_prefix, i.op[x].regs->reg_name);
5183 /* Otherwise it is equivalent to the extended register.
5184 Since the encoding doesn't change this is merely
5185 cosmetic cleanup for debug output. */
5187 i.op[x].regs = i.op[x].regs + 8;
5192 if (i.rex == 0 && i.rex_encoding)
5194 /* Check if we can add a REX_OPCODE byte. Look for 8 bit operand
5195 that uses legacy register. If it is "hi" register, don't add
5196 the REX_OPCODE byte. */
5198 for (x = 0; x < 2; x++)
5199 if (i.types[x].bitfield.class == Reg
5200 && i.types[x].bitfield.byte
5201 && (i.op[x].regs->reg_flags & RegRex64) == 0
5202 && i.op[x].regs->reg_num > 3)
5204 gas_assert (!(i.op[x].regs->reg_flags & RegRex));
5205 i.rex_encoding = false;
5214 add_prefix (REX_OPCODE | i.rex);
5216 insert_lfence_before ();
5218 /* We are ready to output the insn. */
5221 insert_lfence_after ();
5223 last_insn.seg = now_seg;
5225 if (i.tm.opcode_modifier.isprefix)
5227 last_insn.kind = last_insn_prefix;
5228 last_insn.name = i.tm.name;
5229 last_insn.file = as_where (&last_insn.line);
5232 last_insn.kind = last_insn_other;
5236 parse_insn (char *line, char *mnemonic)
5239 char *token_start = l;
5242 const insn_template *t;
5248 while ((*mnem_p = mnemonic_chars[(unsigned char) *l]) != 0)
5253 if (mnem_p >= mnemonic + MAX_MNEM_SIZE)
5255 as_bad (_("no such instruction: `%s'"), token_start);
5260 if (!is_space_char (*l)
5261 && *l != END_OF_INSN
5263 || (*l != PREFIX_SEPARATOR
5266 as_bad (_("invalid character %s in mnemonic"),
5267 output_invalid (*l));
5270 if (token_start == l)
5272 if (!intel_syntax && *l == PREFIX_SEPARATOR)
5273 as_bad (_("expecting prefix; got nothing"));
5275 as_bad (_("expecting mnemonic; got nothing"));
5279 /* Look up instruction (or prefix) via hash table. */
5280 current_templates = (const templates *) str_hash_find (op_hash, mnemonic);
5282 if (*l != END_OF_INSN
5283 && (!is_space_char (*l) || l[1] != END_OF_INSN)
5284 && current_templates
5285 && current_templates->start->opcode_modifier.isprefix)
5287 if (!cpu_flags_check_cpu64 (current_templates->start->cpu_flags))
5289 as_bad ((flag_code != CODE_64BIT
5290 ? _("`%s' is only supported in 64-bit mode")
5291 : _("`%s' is not supported in 64-bit mode")),
5292 current_templates->start->name);
5295 /* If we are in 16-bit mode, do not allow addr16 or data16.
5296 Similarly, in 32-bit mode, do not allow addr32 or data32. */
5297 if ((current_templates->start->opcode_modifier.size == SIZE16
5298 || current_templates->start->opcode_modifier.size == SIZE32)
5299 && flag_code != CODE_64BIT
5300 && ((current_templates->start->opcode_modifier.size == SIZE32)
5301 ^ (flag_code == CODE_16BIT)))
5303 as_bad (_("redundant %s prefix"),
5304 current_templates->start->name);
5308 if (current_templates->start->base_opcode == PSEUDO_PREFIX)
5310 /* Handle pseudo prefixes. */
5311 switch (current_templates->start->extension_opcode)
5315 i.disp_encoding = disp_encoding_8bit;
5319 i.disp_encoding = disp_encoding_16bit;
5323 i.disp_encoding = disp_encoding_32bit;
5327 i.dir_encoding = dir_encoding_load;
5331 i.dir_encoding = dir_encoding_store;
5335 i.vec_encoding = vex_encoding_vex;
5339 i.vec_encoding = vex_encoding_vex3;
5343 i.vec_encoding = vex_encoding_evex;
5347 i.rex_encoding = true;
5349 case Prefix_NoOptimize:
5351 i.no_optimize = true;
5359 /* Add prefix, checking for repeated prefixes. */
5360 switch (add_prefix (current_templates->start->base_opcode))
5365 if (current_templates->start->cpu_flags.bitfield.cpuibt)
5366 i.notrack_prefix = current_templates->start->name;
5369 if (current_templates->start->cpu_flags.bitfield.cpuhle)
5370 i.hle_prefix = current_templates->start->name;
5371 else if (current_templates->start->cpu_flags.bitfield.cpumpx)
5372 i.bnd_prefix = current_templates->start->name;
5374 i.rep_prefix = current_templates->start->name;
5380 /* Skip past PREFIX_SEPARATOR and reset token_start. */
5387 if (!current_templates)
5389 /* Deprecated functionality (new code should use pseudo-prefixes instead):
5390 Check if we should swap operand or force 32bit displacement in
5392 if (mnem_p - 2 == dot_p && dot_p[1] == 's')
5393 i.dir_encoding = dir_encoding_swap;
5394 else if (mnem_p - 3 == dot_p
5397 i.disp_encoding = disp_encoding_8bit;
5398 else if (mnem_p - 4 == dot_p
5402 i.disp_encoding = disp_encoding_32bit;
5407 current_templates = (const templates *) str_hash_find (op_hash, mnemonic);
5410 if (!current_templates)
5413 if (mnem_p > mnemonic)
5415 /* See if we can get a match by trimming off a suffix. */
5418 case WORD_MNEM_SUFFIX:
5419 if (intel_syntax && (intel_float_operand (mnemonic) & 2))
5420 i.suffix = SHORT_MNEM_SUFFIX;
5423 case BYTE_MNEM_SUFFIX:
5424 case QWORD_MNEM_SUFFIX:
5425 i.suffix = mnem_p[-1];
5428 = (const templates *) str_hash_find (op_hash, mnemonic);
5430 case SHORT_MNEM_SUFFIX:
5431 case LONG_MNEM_SUFFIX:
5434 i.suffix = mnem_p[-1];
5437 = (const templates *) str_hash_find (op_hash, mnemonic);
5445 if (intel_float_operand (mnemonic) == 1)
5446 i.suffix = SHORT_MNEM_SUFFIX;
5448 i.suffix = LONG_MNEM_SUFFIX;
5451 = (const templates *) str_hash_find (op_hash, mnemonic);
5457 if (!current_templates)
5459 as_bad (_("no such instruction: `%s'"), token_start);
5464 if (current_templates->start->opcode_modifier.jump == JUMP
5465 || current_templates->start->opcode_modifier.jump == JUMP_BYTE)
5467 /* Check for a branch hint. We allow ",pt" and ",pn" for
5468 predict taken and predict not taken respectively.
5469 I'm not sure that branch hints actually do anything on loop
5470 and jcxz insns (JumpByte) for current Pentium4 chips. They
5471 may work in the future and it doesn't hurt to accept them
5473 if (l[0] == ',' && l[1] == 'p')
5477 if (!add_prefix (DS_PREFIX_OPCODE))
5481 else if (l[2] == 'n')
5483 if (!add_prefix (CS_PREFIX_OPCODE))
5489 /* Any other comma loses. */
5492 as_bad (_("invalid character %s in mnemonic"),
5493 output_invalid (*l));
5497 /* Check if instruction is supported on specified architecture. */
5499 for (t = current_templates->start; t < current_templates->end; ++t)
5501 supported |= cpu_flags_match (t);
5502 if (supported == CPU_FLAGS_PERFECT_MATCH)
5504 if (!cpu_arch_flags.bitfield.cpui386 && (flag_code != CODE_16BIT))
5505 as_warn (_("use .code16 to ensure correct addressing mode"));
5511 if (!(supported & CPU_FLAGS_64BIT_MATCH))
5512 as_bad (flag_code == CODE_64BIT
5513 ? _("`%s' is not supported in 64-bit mode")
5514 : _("`%s' is only supported in 64-bit mode"),
5515 current_templates->start->name);
5517 as_bad (_("`%s' is not supported on `%s%s'"),
5518 current_templates->start->name,
5519 cpu_arch_name ? cpu_arch_name : default_arch,
5520 cpu_sub_arch_name ? cpu_sub_arch_name : "");
5526 parse_operands (char *l, const char *mnemonic)
5530 /* 1 if operand is pending after ','. */
5531 unsigned int expecting_operand = 0;
5533 while (*l != END_OF_INSN)
5535 /* Non-zero if operand parens not balanced. */
5536 unsigned int paren_not_balanced = 0;
5537 /* True if inside double quotes. */
5538 bool in_quotes = false;
5540 /* Skip optional white space before operand. */
5541 if (is_space_char (*l))
5543 if (!is_operand_char (*l) && *l != END_OF_INSN && *l != '"')
5545 as_bad (_("invalid character %s before operand %d"),
5546 output_invalid (*l),
5550 token_start = l; /* After white space. */
5551 while (in_quotes || paren_not_balanced || *l != ',')
5553 if (*l == END_OF_INSN)
5557 as_bad (_("unbalanced double quotes in operand %d."),
5561 if (paren_not_balanced)
5563 know (!intel_syntax);
5564 as_bad (_("unbalanced parenthesis in operand %d."),
5569 break; /* we are done */
5571 else if (*l == '\\' && l[1] == '"')
5574 in_quotes = !in_quotes;
5575 else if (!in_quotes && !is_operand_char (*l) && !is_space_char (*l))
5577 as_bad (_("invalid character %s in operand %d"),
5578 output_invalid (*l),
5582 if (!intel_syntax && !in_quotes)
5585 ++paren_not_balanced;
5587 --paren_not_balanced;
5591 if (l != token_start)
5592 { /* Yes, we've read in another operand. */
5593 unsigned int operand_ok;
5594 this_operand = i.operands++;
5595 if (i.operands > MAX_OPERANDS)
5597 as_bad (_("spurious operands; (%d operands/instruction max)"),
5601 i.types[this_operand].bitfield.unspecified = 1;
5602 /* Now parse operand adding info to 'i' as we go along. */
5603 END_STRING_AND_SAVE (l);
5605 if (i.mem_operands > 1)
5607 as_bad (_("too many memory references for `%s'"),
5614 i386_intel_operand (token_start,
5615 intel_float_operand (mnemonic));
5617 operand_ok = i386_att_operand (token_start);
5619 RESTORE_END_STRING (l);
5625 if (expecting_operand)
5627 expecting_operand_after_comma:
5628 as_bad (_("expecting operand after ','; got nothing"));
5633 as_bad (_("expecting operand before ','; got nothing"));
5638 /* Now *l must be either ',' or END_OF_INSN. */
5641 if (*++l == END_OF_INSN)
5643 /* Just skip it, if it's \n complain. */
5644 goto expecting_operand_after_comma;
5646 expecting_operand = 1;
5653 swap_2_operands (unsigned int xchg1, unsigned int xchg2)
5655 union i386_op temp_op;
5656 i386_operand_type temp_type;
5657 unsigned int temp_flags;
5658 enum bfd_reloc_code_real temp_reloc;
5660 temp_type = i.types[xchg2];
5661 i.types[xchg2] = i.types[xchg1];
5662 i.types[xchg1] = temp_type;
5664 temp_flags = i.flags[xchg2];
5665 i.flags[xchg2] = i.flags[xchg1];
5666 i.flags[xchg1] = temp_flags;
5668 temp_op = i.op[xchg2];
5669 i.op[xchg2] = i.op[xchg1];
5670 i.op[xchg1] = temp_op;
5672 temp_reloc = i.reloc[xchg2];
5673 i.reloc[xchg2] = i.reloc[xchg1];
5674 i.reloc[xchg1] = temp_reloc;
5678 if (i.mask.operand == xchg1)
5679 i.mask.operand = xchg2;
5680 else if (i.mask.operand == xchg2)
5681 i.mask.operand = xchg1;
5683 if (i.broadcast.type)
5685 if (i.broadcast.operand == xchg1)
5686 i.broadcast.operand = xchg2;
5687 else if (i.broadcast.operand == xchg2)
5688 i.broadcast.operand = xchg1;
5690 if (i.rounding.type != rc_none)
5692 if (i.rounding.operand == xchg1)
5693 i.rounding.operand = xchg2;
5694 else if (i.rounding.operand == xchg2)
5695 i.rounding.operand = xchg1;
5700 swap_operands (void)
5706 swap_2_operands (1, i.operands - 2);
5710 swap_2_operands (0, i.operands - 1);
5716 if (i.mem_operands == 2)
5718 const reg_entry *temp_seg;
5719 temp_seg = i.seg[0];
5720 i.seg[0] = i.seg[1];
5721 i.seg[1] = temp_seg;
5725 /* Try to ensure constant immediates are represented in the smallest
5730 char guess_suffix = 0;
5734 guess_suffix = i.suffix;
5735 else if (i.reg_operands)
5737 /* Figure out a suffix from the last register operand specified.
5738 We can't do this properly yet, i.e. excluding special register
5739 instances, but the following works for instructions with
5740 immediates. In any case, we can't set i.suffix yet. */
5741 for (op = i.operands; --op >= 0;)
5742 if (i.types[op].bitfield.class != Reg)
5744 else if (i.types[op].bitfield.byte)
5746 guess_suffix = BYTE_MNEM_SUFFIX;
5749 else if (i.types[op].bitfield.word)
5751 guess_suffix = WORD_MNEM_SUFFIX;
5754 else if (i.types[op].bitfield.dword)
5756 guess_suffix = LONG_MNEM_SUFFIX;
5759 else if (i.types[op].bitfield.qword)
5761 guess_suffix = QWORD_MNEM_SUFFIX;
5765 else if ((flag_code == CODE_16BIT) ^ (i.prefix[DATA_PREFIX] != 0))
5766 guess_suffix = WORD_MNEM_SUFFIX;
5768 for (op = i.operands; --op >= 0;)
5769 if (operand_type_check (i.types[op], imm))
5771 switch (i.op[op].imms->X_op)
5774 /* If a suffix is given, this operand may be shortened. */
5775 switch (guess_suffix)
5777 case LONG_MNEM_SUFFIX:
5778 i.types[op].bitfield.imm32 = 1;
5779 i.types[op].bitfield.imm64 = 1;
5781 case WORD_MNEM_SUFFIX:
5782 i.types[op].bitfield.imm16 = 1;
5783 i.types[op].bitfield.imm32 = 1;
5784 i.types[op].bitfield.imm32s = 1;
5785 i.types[op].bitfield.imm64 = 1;
5787 case BYTE_MNEM_SUFFIX:
5788 i.types[op].bitfield.imm8 = 1;
5789 i.types[op].bitfield.imm8s = 1;
5790 i.types[op].bitfield.imm16 = 1;
5791 i.types[op].bitfield.imm32 = 1;
5792 i.types[op].bitfield.imm32s = 1;
5793 i.types[op].bitfield.imm64 = 1;
5797 /* If this operand is at most 16 bits, convert it
5798 to a signed 16 bit number before trying to see
5799 whether it will fit in an even smaller size.
5800 This allows a 16-bit operand such as $0xffe0 to
5801 be recognised as within Imm8S range. */
5802 if ((i.types[op].bitfield.imm16)
5803 && fits_in_unsigned_word (i.op[op].imms->X_add_number))
5805 i.op[op].imms->X_add_number = ((i.op[op].imms->X_add_number
5806 ^ 0x8000) - 0x8000);
5809 /* Store 32-bit immediate in 64-bit for 64-bit BFD. */
5810 if ((i.types[op].bitfield.imm32)
5811 && fits_in_unsigned_long (i.op[op].imms->X_add_number))
5813 i.op[op].imms->X_add_number = ((i.op[op].imms->X_add_number
5814 ^ ((offsetT) 1 << 31))
5815 - ((offsetT) 1 << 31));
5819 = operand_type_or (i.types[op],
5820 smallest_imm_type (i.op[op].imms->X_add_number));
5822 /* We must avoid matching of Imm32 templates when 64bit
5823 only immediate is available. */
5824 if (guess_suffix == QWORD_MNEM_SUFFIX)
5825 i.types[op].bitfield.imm32 = 0;
5832 /* Symbols and expressions. */
5834 /* Convert symbolic operand to proper sizes for matching, but don't
5835 prevent matching a set of insns that only supports sizes other
5836 than those matching the insn suffix. */
5838 i386_operand_type mask, allowed;
5839 const insn_template *t = current_templates->start;
5841 operand_type_set (&mask, 0);
5842 allowed = t->operand_types[op];
5844 while (++t < current_templates->end)
5846 allowed = operand_type_and (allowed, anyimm);
5847 allowed = operand_type_or (allowed, t->operand_types[op]);
5849 switch (guess_suffix)
5851 case QWORD_MNEM_SUFFIX:
5852 mask.bitfield.imm64 = 1;
5853 mask.bitfield.imm32s = 1;
5855 case LONG_MNEM_SUFFIX:
5856 mask.bitfield.imm32 = 1;
5858 case WORD_MNEM_SUFFIX:
5859 mask.bitfield.imm16 = 1;
5861 case BYTE_MNEM_SUFFIX:
5862 mask.bitfield.imm8 = 1;
5867 allowed = operand_type_and (mask, allowed);
5868 if (!operand_type_all_zero (&allowed))
5869 i.types[op] = operand_type_and (i.types[op], mask);
5876 /* Try to use the smallest displacement type too. */
5878 optimize_disp (void)
5882 for (op = i.operands; --op >= 0;)
5883 if (operand_type_check (i.types[op], disp))
5885 if (i.op[op].disps->X_op == O_constant)
5887 offsetT op_disp = i.op[op].disps->X_add_number;
5889 if (!op_disp && i.types[op].bitfield.baseindex)
5891 i.types[op].bitfield.disp8 = 0;
5892 i.types[op].bitfield.disp16 = 0;
5893 i.types[op].bitfield.disp32 = 0;
5894 i.types[op].bitfield.disp32s = 0;
5895 i.types[op].bitfield.disp64 = 0;
5901 if (i.types[op].bitfield.disp16
5902 && fits_in_unsigned_word (op_disp))
5904 /* If this operand is at most 16 bits, convert
5905 to a signed 16 bit number and don't use 64bit
5907 op_disp = ((op_disp ^ 0x8000) - 0x8000);
5908 i.types[op].bitfield.disp64 = 0;
5912 if (flag_code == CODE_64BIT)
5914 /* Optimize 64-bit displacement to 32-bit for 64-bit BFD. */
5915 if ((i.types[op].bitfield.disp32
5916 || want_disp32 (current_templates->start))
5917 && fits_in_unsigned_long (op_disp))
5919 /* If this operand is at most 32 bits, convert
5920 to a signed 32 bit number and don't use 64bit
5922 op_disp = (op_disp ^ ((offsetT) 1 << 31)) - ((addressT) 1 << 31);
5923 i.types[op].bitfield.disp64 = 0;
5924 i.types[op].bitfield.disp32 = 1;
5927 if (fits_in_signed_long (op_disp))
5929 i.types[op].bitfield.disp64 = 0;
5930 i.types[op].bitfield.disp32s = 1;
5934 if ((i.types[op].bitfield.disp32
5935 || i.types[op].bitfield.disp32s
5936 || i.types[op].bitfield.disp16)
5937 && fits_in_disp8 (op_disp))
5938 i.types[op].bitfield.disp8 = 1;
5940 i.op[op].disps->X_add_number = op_disp;
5942 else if (i.reloc[op] == BFD_RELOC_386_TLS_DESC_CALL
5943 || i.reloc[op] == BFD_RELOC_X86_64_TLSDESC_CALL)
5945 fix_new_exp (frag_now, frag_more (0) - frag_now->fr_literal, 0,
5946 i.op[op].disps, 0, i.reloc[op]);
5947 i.types[op].bitfield.disp8 = 0;
5948 i.types[op].bitfield.disp16 = 0;
5949 i.types[op].bitfield.disp32 = 0;
5950 i.types[op].bitfield.disp32s = 0;
5951 i.types[op].bitfield.disp64 = 0;
5954 /* We only support 64bit displacement on constants. */
5955 i.types[op].bitfield.disp64 = 0;
5959 /* Return 1 if there is a match in broadcast bytes between operand
5960 GIVEN and instruction template T. */
5963 match_broadcast_size (const insn_template *t, unsigned int given)
5965 return ((t->opcode_modifier.broadcast == BYTE_BROADCAST
5966 && i.types[given].bitfield.byte)
5967 || (t->opcode_modifier.broadcast == WORD_BROADCAST
5968 && i.types[given].bitfield.word)
5969 || (t->opcode_modifier.broadcast == DWORD_BROADCAST
5970 && i.types[given].bitfield.dword)
5971 || (t->opcode_modifier.broadcast == QWORD_BROADCAST
5972 && i.types[given].bitfield.qword));
5975 /* Check if operands are valid for the instruction. */
5978 check_VecOperands (const insn_template *t)
5983 /* Templates allowing for ZMMword as well as YMMword and/or XMMword for
5984 any one operand are implicity requiring AVX512VL support if the actual
5985 operand size is YMMword or XMMword. Since this function runs after
5986 template matching, there's no need to check for YMMword/XMMword in
5988 cpu = cpu_flags_and (t->cpu_flags, avx512);
5989 if (!cpu_flags_all_zero (&cpu)
5990 && !t->cpu_flags.bitfield.cpuavx512vl
5991 && !cpu_arch_flags.bitfield.cpuavx512vl)
5993 for (op = 0; op < t->operands; ++op)
5995 if (t->operand_types[op].bitfield.zmmword
5996 && (i.types[op].bitfield.ymmword
5997 || i.types[op].bitfield.xmmword))
5999 i.error = unsupported;
6005 /* Without VSIB byte, we can't have a vector register for index. */
6006 if (!t->opcode_modifier.sib
6008 && (i.index_reg->reg_type.bitfield.xmmword
6009 || i.index_reg->reg_type.bitfield.ymmword
6010 || i.index_reg->reg_type.bitfield.zmmword))
6012 i.error = unsupported_vector_index_register;
6016 /* Check if default mask is allowed. */
6017 if (t->opcode_modifier.nodefmask
6018 && (!i.mask.reg || i.mask.reg->reg_num == 0))
6020 i.error = no_default_mask;
6024 /* For VSIB byte, we need a vector register for index, and all vector
6025 registers must be distinct. */
6026 if (t->opcode_modifier.sib && t->opcode_modifier.sib != SIBMEM)
6029 || !((t->opcode_modifier.sib == VECSIB128
6030 && i.index_reg->reg_type.bitfield.xmmword)
6031 || (t->opcode_modifier.sib == VECSIB256
6032 && i.index_reg->reg_type.bitfield.ymmword)
6033 || (t->opcode_modifier.sib == VECSIB512
6034 && i.index_reg->reg_type.bitfield.zmmword)))
6036 i.error = invalid_vsib_address;
6040 gas_assert (i.reg_operands == 2 || i.mask.reg);
6041 if (i.reg_operands == 2 && !i.mask.reg)
6043 gas_assert (i.types[0].bitfield.class == RegSIMD);
6044 gas_assert (i.types[0].bitfield.xmmword
6045 || i.types[0].bitfield.ymmword);
6046 gas_assert (i.types[2].bitfield.class == RegSIMD);
6047 gas_assert (i.types[2].bitfield.xmmword
6048 || i.types[2].bitfield.ymmword);
6049 if (operand_check == check_none)
6051 if (register_number (i.op[0].regs)
6052 != register_number (i.index_reg)
6053 && register_number (i.op[2].regs)
6054 != register_number (i.index_reg)
6055 && register_number (i.op[0].regs)
6056 != register_number (i.op[2].regs))
6058 if (operand_check == check_error)
6060 i.error = invalid_vector_register_set;
6063 as_warn (_("mask, index, and destination registers should be distinct"));
6065 else if (i.reg_operands == 1 && i.mask.reg)
6067 if (i.types[1].bitfield.class == RegSIMD
6068 && (i.types[1].bitfield.xmmword
6069 || i.types[1].bitfield.ymmword
6070 || i.types[1].bitfield.zmmword)
6071 && (register_number (i.op[1].regs)
6072 == register_number (i.index_reg)))
6074 if (operand_check == check_error)
6076 i.error = invalid_vector_register_set;
6079 if (operand_check != check_none)
6080 as_warn (_("index and destination registers should be distinct"));
6085 /* For AMX instructions with three tmmword operands, all tmmword operand must be
6087 if (t->operand_types[0].bitfield.tmmword
6088 && i.reg_operands == 3)
6090 if (register_number (i.op[0].regs)
6091 == register_number (i.op[1].regs)
6092 || register_number (i.op[0].regs)
6093 == register_number (i.op[2].regs)
6094 || register_number (i.op[1].regs)
6095 == register_number (i.op[2].regs))
6097 i.error = invalid_tmm_register_set;
6102 /* Check if broadcast is supported by the instruction and is applied
6103 to the memory operand. */
6104 if (i.broadcast.type)
6106 i386_operand_type type, overlap;
6108 /* Check if specified broadcast is supported in this instruction,
6109 and its broadcast bytes match the memory operand. */
6110 op = i.broadcast.operand;
6111 if (!t->opcode_modifier.broadcast
6112 || !(i.flags[op] & Operand_Mem)
6113 || (!i.types[op].bitfield.unspecified
6114 && !match_broadcast_size (t, op)))
6117 i.error = unsupported_broadcast;
6121 i.broadcast.bytes = ((1 << (t->opcode_modifier.broadcast - 1))
6122 * i.broadcast.type);
6123 operand_type_set (&type, 0);
6124 switch (i.broadcast.bytes)
6127 type.bitfield.word = 1;
6130 type.bitfield.dword = 1;
6133 type.bitfield.qword = 1;
6136 type.bitfield.xmmword = 1;
6139 type.bitfield.ymmword = 1;
6142 type.bitfield.zmmword = 1;
6148 overlap = operand_type_and (type, t->operand_types[op]);
6149 if (t->operand_types[op].bitfield.class == RegSIMD
6150 && t->operand_types[op].bitfield.byte
6151 + t->operand_types[op].bitfield.word
6152 + t->operand_types[op].bitfield.dword
6153 + t->operand_types[op].bitfield.qword > 1)
6155 overlap.bitfield.xmmword = 0;
6156 overlap.bitfield.ymmword = 0;
6157 overlap.bitfield.zmmword = 0;
6159 if (operand_type_all_zero (&overlap))
6162 if (t->opcode_modifier.checkregsize)
6166 type.bitfield.baseindex = 1;
6167 for (j = 0; j < i.operands; ++j)
6170 && !operand_type_register_match(i.types[j],
6171 t->operand_types[j],
6173 t->operand_types[op]))
6178 /* If broadcast is supported in this instruction, we need to check if
6179 operand of one-element size isn't specified without broadcast. */
6180 else if (t->opcode_modifier.broadcast && i.mem_operands)
6182 /* Find memory operand. */
6183 for (op = 0; op < i.operands; op++)
6184 if (i.flags[op] & Operand_Mem)
6186 gas_assert (op < i.operands);
6187 /* Check size of the memory operand. */
6188 if (match_broadcast_size (t, op))
6190 i.error = broadcast_needed;
6195 op = MAX_OPERANDS - 1; /* Avoid uninitialized variable warning. */
6197 /* Check if requested masking is supported. */
6200 switch (t->opcode_modifier.masking)
6204 case MERGING_MASKING:
6208 i.error = unsupported_masking;
6212 case DYNAMIC_MASKING:
6213 /* Memory destinations allow only merging masking. */
6214 if (i.mask.zeroing && i.mem_operands)
6216 /* Find memory operand. */
6217 for (op = 0; op < i.operands; op++)
6218 if (i.flags[op] & Operand_Mem)
6220 gas_assert (op < i.operands);
6221 if (op == i.operands - 1)
6223 i.error = unsupported_masking;
6233 /* Check if masking is applied to dest operand. */
6234 if (i.mask.reg && (i.mask.operand != i.operands - 1))
6236 i.error = mask_not_on_destination;
6241 if (i.rounding.type != rc_none)
6243 if (!t->opcode_modifier.sae
6244 || (i.rounding.type != saeonly && !t->opcode_modifier.staticrounding))
6246 i.error = unsupported_rc_sae;
6249 /* If the instruction has several immediate operands and one of
6250 them is rounding, the rounding operand should be the last
6251 immediate operand. */
6252 if (i.imm_operands > 1
6253 && i.rounding.operand != i.imm_operands - 1)
6255 i.error = rc_sae_operand_not_last_imm;
6260 /* Check the special Imm4 cases; must be the first operand. */
6261 if (t->cpu_flags.bitfield.cpuxop && t->operands == 5)
6263 if (i.op[0].imms->X_op != O_constant
6264 || !fits_in_imm4 (i.op[0].imms->X_add_number))
6270 /* Turn off Imm<N> so that update_imm won't complain. */
6271 operand_type_set (&i.types[0], 0);
6274 /* Check vector Disp8 operand. */
6275 if (t->opcode_modifier.disp8memshift
6276 && i.disp_encoding != disp_encoding_32bit)
6278 if (i.broadcast.type)
6279 i.memshift = t->opcode_modifier.broadcast - 1;
6280 else if (t->opcode_modifier.disp8memshift != DISP8_SHIFT_VL)
6281 i.memshift = t->opcode_modifier.disp8memshift;
6284 const i386_operand_type *type = NULL;
6287 for (op = 0; op < i.operands; op++)
6288 if (i.flags[op] & Operand_Mem)
6290 if (t->opcode_modifier.evex == EVEXLIG)
6291 i.memshift = 2 + (i.suffix == QWORD_MNEM_SUFFIX);
6292 else if (t->operand_types[op].bitfield.xmmword
6293 + t->operand_types[op].bitfield.ymmword
6294 + t->operand_types[op].bitfield.zmmword <= 1)
6295 type = &t->operand_types[op];
6296 else if (!i.types[op].bitfield.unspecified)
6297 type = &i.types[op];
6299 else if (i.types[op].bitfield.class == RegSIMD
6300 && t->opcode_modifier.evex != EVEXLIG)
6302 if (i.types[op].bitfield.zmmword)
6304 else if (i.types[op].bitfield.ymmword && i.memshift < 5)
6306 else if (i.types[op].bitfield.xmmword && i.memshift < 4)
6312 if (type->bitfield.zmmword)
6314 else if (type->bitfield.ymmword)
6316 else if (type->bitfield.xmmword)
6320 /* For the check in fits_in_disp8(). */
6321 if (i.memshift == 0)
6325 for (op = 0; op < i.operands; op++)
6326 if (operand_type_check (i.types[op], disp)
6327 && i.op[op].disps->X_op == O_constant)
6329 if (fits_in_disp8 (i.op[op].disps->X_add_number))
6331 i.types[op].bitfield.disp8 = 1;
6334 i.types[op].bitfield.disp8 = 0;
6343 /* Check if encoding requirements are met by the instruction. */
6346 VEX_check_encoding (const insn_template *t)
6348 if (i.vec_encoding == vex_encoding_error)
6350 i.error = unsupported;
6354 if (i.vec_encoding == vex_encoding_evex)
6356 /* This instruction must be encoded with EVEX prefix. */
6357 if (!is_evex_encoding (t))
6359 i.error = unsupported;
6365 if (!t->opcode_modifier.vex)
6367 /* This instruction template doesn't have VEX prefix. */
6368 if (i.vec_encoding != vex_encoding_default)
6370 i.error = unsupported;
6379 static const insn_template *
6380 match_template (char mnem_suffix)
6382 /* Points to template once we've found it. */
6383 const insn_template *t;
6384 i386_operand_type overlap0, overlap1, overlap2, overlap3;
6385 i386_operand_type overlap4;
6386 unsigned int found_reverse_match;
6387 i386_opcode_modifier suffix_check;
6388 i386_operand_type operand_types [MAX_OPERANDS];
6389 int addr_prefix_disp;
6390 unsigned int j, size_match, check_register;
6391 enum i386_error specific_error = 0;
6393 #if MAX_OPERANDS != 5
6394 # error "MAX_OPERANDS must be 5."
6397 found_reverse_match = 0;
6398 addr_prefix_disp = -1;
6400 /* Prepare for mnemonic suffix check. */
6401 memset (&suffix_check, 0, sizeof (suffix_check));
6402 switch (mnem_suffix)
6404 case BYTE_MNEM_SUFFIX:
6405 suffix_check.no_bsuf = 1;
6407 case WORD_MNEM_SUFFIX:
6408 suffix_check.no_wsuf = 1;
6410 case SHORT_MNEM_SUFFIX:
6411 suffix_check.no_ssuf = 1;
6413 case LONG_MNEM_SUFFIX:
6414 suffix_check.no_lsuf = 1;
6416 case QWORD_MNEM_SUFFIX:
6417 suffix_check.no_qsuf = 1;
6420 /* NB: In Intel syntax, normally we can check for memory operand
6421 size when there is no mnemonic suffix. But jmp and call have
6422 2 different encodings with Dword memory operand size, one with
6423 No_ldSuf and the other without. i.suffix is set to
6424 LONG_DOUBLE_MNEM_SUFFIX to skip the one with No_ldSuf. */
6425 if (i.suffix == LONG_DOUBLE_MNEM_SUFFIX)
6426 suffix_check.no_ldsuf = 1;
6429 /* Must have right number of operands. */
6430 i.error = number_of_operands_mismatch;
6432 for (t = current_templates->start; t < current_templates->end; t++)
6434 addr_prefix_disp = -1;
6435 found_reverse_match = 0;
6437 if (i.operands != t->operands)
6440 /* Check processor support. */
6441 i.error = unsupported;
6442 if (cpu_flags_match (t) != CPU_FLAGS_PERFECT_MATCH)
6445 /* Check Pseudo Prefix. */
6446 i.error = unsupported;
6447 if (t->opcode_modifier.pseudovexprefix
6448 && !(i.vec_encoding == vex_encoding_vex
6449 || i.vec_encoding == vex_encoding_vex3))
6452 /* Check AT&T mnemonic. */
6453 i.error = unsupported_with_intel_mnemonic;
6454 if (intel_mnemonic && t->opcode_modifier.attmnemonic)
6457 /* Check AT&T/Intel syntax. */
6458 i.error = unsupported_syntax;
6459 if ((intel_syntax && t->opcode_modifier.attsyntax)
6460 || (!intel_syntax && t->opcode_modifier.intelsyntax))
6463 /* Check Intel64/AMD64 ISA. */
6467 /* Default: Don't accept Intel64. */
6468 if (t->opcode_modifier.isa64 == INTEL64)
6472 /* -mamd64: Don't accept Intel64 and Intel64 only. */
6473 if (t->opcode_modifier.isa64 >= INTEL64)
6477 /* -mintel64: Don't accept AMD64. */
6478 if (t->opcode_modifier.isa64 == AMD64 && flag_code == CODE_64BIT)
6483 /* Check the suffix. */
6484 i.error = invalid_instruction_suffix;
6485 if ((t->opcode_modifier.no_bsuf && suffix_check.no_bsuf)
6486 || (t->opcode_modifier.no_wsuf && suffix_check.no_wsuf)
6487 || (t->opcode_modifier.no_lsuf && suffix_check.no_lsuf)
6488 || (t->opcode_modifier.no_ssuf && suffix_check.no_ssuf)
6489 || (t->opcode_modifier.no_qsuf && suffix_check.no_qsuf)
6490 || (t->opcode_modifier.no_ldsuf && suffix_check.no_ldsuf))
6493 size_match = operand_size_match (t);
6497 /* This is intentionally not
6499 if (i.jumpabsolute != (t->opcode_modifier.jump == JUMP_ABSOLUTE))
6501 as the case of a missing * on the operand is accepted (perhaps with
6502 a warning, issued further down). */
6503 if (i.jumpabsolute && t->opcode_modifier.jump != JUMP_ABSOLUTE)
6505 i.error = operand_type_mismatch;
6509 for (j = 0; j < MAX_OPERANDS; j++)
6510 operand_types[j] = t->operand_types[j];
6512 /* In general, don't allow
6513 - 64-bit operands outside of 64-bit mode,
6514 - 32-bit operands on pre-386. */
6515 j = i.imm_operands + (t->operands > i.imm_operands + 1);
6516 if (((i.suffix == QWORD_MNEM_SUFFIX
6517 && flag_code != CODE_64BIT
6518 && !(t->opcode_modifier.opcodespace == SPACE_0F
6519 && t->base_opcode == 0xc7
6520 && t->opcode_modifier.opcodeprefix == PREFIX_NONE
6521 && t->extension_opcode == 1) /* cmpxchg8b */)
6522 || (i.suffix == LONG_MNEM_SUFFIX
6523 && !cpu_arch_flags.bitfield.cpui386))
6525 ? (t->opcode_modifier.mnemonicsize != IGNORESIZE
6526 && !intel_float_operand (t->name))
6527 : intel_float_operand (t->name) != 2)
6528 && (t->operands == i.imm_operands
6529 || (operand_types[i.imm_operands].bitfield.class != RegMMX
6530 && operand_types[i.imm_operands].bitfield.class != RegSIMD
6531 && operand_types[i.imm_operands].bitfield.class != RegMask)
6532 || (operand_types[j].bitfield.class != RegMMX
6533 && operand_types[j].bitfield.class != RegSIMD
6534 && operand_types[j].bitfield.class != RegMask))
6535 && !t->opcode_modifier.sib)
6538 /* Do not verify operands when there are none. */
6541 if (VEX_check_encoding (t))
6543 specific_error = i.error;
6547 /* We've found a match; break out of loop. */
6551 if (!t->opcode_modifier.jump
6552 || t->opcode_modifier.jump == JUMP_ABSOLUTE)
6554 /* There should be only one Disp operand. */
6555 for (j = 0; j < MAX_OPERANDS; j++)
6556 if (operand_type_check (operand_types[j], disp))
6558 if (j < MAX_OPERANDS)
6560 bool override = (i.prefix[ADDR_PREFIX] != 0);
6562 addr_prefix_disp = j;
6564 /* Address size prefix will turn Disp64/Disp32S/Disp32/Disp16
6565 operand into Disp32/Disp32/Disp16/Disp32 operand. */
6569 override = !override;
6572 if (operand_types[j].bitfield.disp32
6573 && operand_types[j].bitfield.disp16)
6575 operand_types[j].bitfield.disp16 = override;
6576 operand_types[j].bitfield.disp32 = !override;
6578 operand_types[j].bitfield.disp32s = 0;
6579 operand_types[j].bitfield.disp64 = 0;
6583 if (operand_types[j].bitfield.disp32s
6584 || operand_types[j].bitfield.disp64)
6586 operand_types[j].bitfield.disp64 &= !override;
6587 operand_types[j].bitfield.disp32s &= !override;
6588 operand_types[j].bitfield.disp32 = override;
6590 operand_types[j].bitfield.disp16 = 0;
6596 /* Force 0x8b encoding for "mov foo@GOT, %eax". */
6597 if (i.reloc[0] == BFD_RELOC_386_GOT32
6598 && t->base_opcode == 0xa0
6599 && t->opcode_modifier.opcodespace == SPACE_BASE)
6602 /* We check register size if needed. */
6603 if (t->opcode_modifier.checkregsize)
6605 check_register = (1 << t->operands) - 1;
6606 if (i.broadcast.type)
6607 check_register &= ~(1 << i.broadcast.operand);
6612 overlap0 = operand_type_and (i.types[0], operand_types[0]);
6613 switch (t->operands)
6616 if (!operand_type_match (overlap0, i.types[0]))
6620 /* xchg %eax, %eax is a special case. It is an alias for nop
6621 only in 32bit mode and we can use opcode 0x90. In 64bit
6622 mode, we can't use 0x90 for xchg %eax, %eax since it should
6623 zero-extend %eax to %rax. */
6624 if (flag_code == CODE_64BIT
6625 && t->base_opcode == 0x90
6626 && t->opcode_modifier.opcodespace == SPACE_BASE
6627 && i.types[0].bitfield.instance == Accum
6628 && i.types[0].bitfield.dword
6629 && i.types[1].bitfield.instance == Accum
6630 && i.types[1].bitfield.dword)
6632 /* xrelease mov %eax, <disp> is another special case. It must not
6633 match the accumulator-only encoding of mov. */
6634 if (flag_code != CODE_64BIT
6636 && t->base_opcode == 0xa0
6637 && t->opcode_modifier.opcodespace == SPACE_BASE
6638 && i.types[0].bitfield.instance == Accum
6639 && (i.flags[1] & Operand_Mem))
6644 if (!(size_match & MATCH_STRAIGHT))
6646 /* Reverse direction of operands if swapping is possible in the first
6647 place (operands need to be symmetric) and
6648 - the load form is requested, and the template is a store form,
6649 - the store form is requested, and the template is a load form,
6650 - the non-default (swapped) form is requested. */
6651 overlap1 = operand_type_and (operand_types[0], operand_types[1]);
6652 if (t->opcode_modifier.d && i.reg_operands == i.operands
6653 && !operand_type_all_zero (&overlap1))
6654 switch (i.dir_encoding)
6656 case dir_encoding_load:
6657 if (operand_type_check (operand_types[i.operands - 1], anymem)
6658 || t->opcode_modifier.regmem)
6662 case dir_encoding_store:
6663 if (!operand_type_check (operand_types[i.operands - 1], anymem)
6664 && !t->opcode_modifier.regmem)
6668 case dir_encoding_swap:
6671 case dir_encoding_default:
6674 /* If we want store form, we skip the current load. */
6675 if ((i.dir_encoding == dir_encoding_store
6676 || i.dir_encoding == dir_encoding_swap)
6677 && i.mem_operands == 0
6678 && t->opcode_modifier.load)
6683 overlap1 = operand_type_and (i.types[1], operand_types[1]);
6684 if (!operand_type_match (overlap0, i.types[0])
6685 || !operand_type_match (overlap1, i.types[1])
6686 || ((check_register & 3) == 3
6687 && !operand_type_register_match (i.types[0],
6692 /* Check if other direction is valid ... */
6693 if (!t->opcode_modifier.d)
6697 if (!(size_match & MATCH_REVERSE))
6699 /* Try reversing direction of operands. */
6700 overlap0 = operand_type_and (i.types[0], operand_types[i.operands - 1]);
6701 overlap1 = operand_type_and (i.types[i.operands - 1], operand_types[0]);
6702 if (!operand_type_match (overlap0, i.types[0])
6703 || !operand_type_match (overlap1, i.types[i.operands - 1])
6705 && !operand_type_register_match (i.types[0],
6706 operand_types[i.operands - 1],
6707 i.types[i.operands - 1],
6710 /* Does not match either direction. */
6713 /* found_reverse_match holds which of D or FloatR
6715 if (!t->opcode_modifier.d)
6716 found_reverse_match = 0;
6717 else if (operand_types[0].bitfield.tbyte)
6718 found_reverse_match = Opcode_FloatD;
6719 else if (operand_types[0].bitfield.xmmword
6720 || operand_types[i.operands - 1].bitfield.xmmword
6721 || operand_types[0].bitfield.class == RegMMX
6722 || operand_types[i.operands - 1].bitfield.class == RegMMX
6723 || is_any_vex_encoding(t))
6724 found_reverse_match = (t->base_opcode & 0xee) != 0x6e
6725 ? Opcode_SIMD_FloatD : Opcode_SIMD_IntD;
6727 found_reverse_match = Opcode_D;
6728 if (t->opcode_modifier.floatr)
6729 found_reverse_match |= Opcode_FloatR;
6733 /* Found a forward 2 operand match here. */
6734 switch (t->operands)
6737 overlap4 = operand_type_and (i.types[4],
6741 overlap3 = operand_type_and (i.types[3],
6745 overlap2 = operand_type_and (i.types[2],
6750 switch (t->operands)
6753 if (!operand_type_match (overlap4, i.types[4])
6754 || !operand_type_register_match (i.types[3],
6761 if (!operand_type_match (overlap3, i.types[3])
6762 || ((check_register & 0xa) == 0xa
6763 && !operand_type_register_match (i.types[1],
6767 || ((check_register & 0xc) == 0xc
6768 && !operand_type_register_match (i.types[2],
6775 /* Here we make use of the fact that there are no
6776 reverse match 3 operand instructions. */
6777 if (!operand_type_match (overlap2, i.types[2])
6778 || ((check_register & 5) == 5
6779 && !operand_type_register_match (i.types[0],
6783 || ((check_register & 6) == 6
6784 && !operand_type_register_match (i.types[1],
6792 /* Found either forward/reverse 2, 3 or 4 operand match here:
6793 slip through to break. */
6796 /* Check if vector operands are valid. */
6797 if (check_VecOperands (t))
6799 specific_error = i.error;
6803 /* Check if VEX/EVEX encoding requirements can be satisfied. */
6804 if (VEX_check_encoding (t))
6806 specific_error = i.error;
6810 /* We've found a match; break out of loop. */
6814 if (t == current_templates->end)
6816 /* We found no match. */
6817 const char *err_msg;
6818 switch (specific_error ? specific_error : i.error)
6822 case operand_size_mismatch:
6823 err_msg = _("operand size mismatch");
6825 case operand_type_mismatch:
6826 err_msg = _("operand type mismatch");
6828 case register_type_mismatch:
6829 err_msg = _("register type mismatch");
6831 case number_of_operands_mismatch:
6832 err_msg = _("number of operands mismatch");
6834 case invalid_instruction_suffix:
6835 err_msg = _("invalid instruction suffix");
6838 err_msg = _("constant doesn't fit in 4 bits");
6840 case unsupported_with_intel_mnemonic:
6841 err_msg = _("unsupported with Intel mnemonic");
6843 case unsupported_syntax:
6844 err_msg = _("unsupported syntax");
6847 as_bad (_("unsupported instruction `%s'"),
6848 current_templates->start->name);
6850 case invalid_sib_address:
6851 err_msg = _("invalid SIB address");
6853 case invalid_vsib_address:
6854 err_msg = _("invalid VSIB address");
6856 case invalid_vector_register_set:
6857 err_msg = _("mask, index, and destination registers must be distinct");
6859 case invalid_tmm_register_set:
6860 err_msg = _("all tmm registers must be distinct");
6862 case unsupported_vector_index_register:
6863 err_msg = _("unsupported vector index register");
6865 case unsupported_broadcast:
6866 err_msg = _("unsupported broadcast");
6868 case broadcast_needed:
6869 err_msg = _("broadcast is needed for operand of such type");
6871 case unsupported_masking:
6872 err_msg = _("unsupported masking");
6874 case mask_not_on_destination:
6875 err_msg = _("mask not on destination operand");
6877 case no_default_mask:
6878 err_msg = _("default mask isn't allowed");
6880 case unsupported_rc_sae:
6881 err_msg = _("unsupported static rounding/sae");
6883 case rc_sae_operand_not_last_imm:
6885 err_msg = _("RC/SAE operand must precede immediate operands");
6887 err_msg = _("RC/SAE operand must follow immediate operands");
6889 case invalid_register_operand:
6890 err_msg = _("invalid register operand");
6893 as_bad (_("%s for `%s'"), err_msg,
6894 current_templates->start->name);
6898 if (!quiet_warnings)
6901 && (i.jumpabsolute != (t->opcode_modifier.jump == JUMP_ABSOLUTE)))
6902 as_warn (_("indirect %s without `*'"), t->name);
6904 if (t->opcode_modifier.isprefix
6905 && t->opcode_modifier.mnemonicsize == IGNORESIZE)
6907 /* Warn them that a data or address size prefix doesn't
6908 affect assembly of the next line of code. */
6909 as_warn (_("stand-alone `%s' prefix"), t->name);
6913 /* Copy the template we found. */
6914 install_template (t);
6916 if (addr_prefix_disp != -1)
6917 i.tm.operand_types[addr_prefix_disp]
6918 = operand_types[addr_prefix_disp];
6920 if (found_reverse_match)
6922 /* If we found a reverse match we must alter the opcode direction
6923 bit and clear/flip the regmem modifier one. found_reverse_match
6924 holds bits to change (different for int & float insns). */
6926 i.tm.base_opcode ^= found_reverse_match;
6928 i.tm.operand_types[0] = operand_types[i.operands - 1];
6929 i.tm.operand_types[i.operands - 1] = operand_types[0];
6931 /* Certain SIMD insns have their load forms specified in the opcode
6932 table, and hence we need to _set_ RegMem instead of clearing it.
6933 We need to avoid setting the bit though on insns like KMOVW. */
6934 i.tm.opcode_modifier.regmem
6935 = i.tm.opcode_modifier.modrm && i.tm.opcode_modifier.d
6936 && i.tm.operands > 2U - i.tm.opcode_modifier.sse2avx
6937 && !i.tm.opcode_modifier.regmem;
6946 unsigned int es_op = i.tm.opcode_modifier.isstring - IS_STRING_ES_OP0;
6947 unsigned int op = i.tm.operand_types[0].bitfield.baseindex ? es_op : 0;
6949 if (i.seg[op] != NULL && i.seg[op] != reg_es)
6951 as_bad (_("`%s' operand %u must use `%ses' segment"),
6953 intel_syntax ? i.tm.operands - es_op : es_op + 1,
6958 /* There's only ever one segment override allowed per instruction.
6959 This instruction possibly has a legal segment override on the
6960 second operand, so copy the segment to where non-string
6961 instructions store it, allowing common code. */
6962 i.seg[op] = i.seg[1];
6968 process_suffix (void)
6970 bool is_crc32 = false, is_movx = false;
6972 /* If matched instruction specifies an explicit instruction mnemonic
6974 if (i.tm.opcode_modifier.size == SIZE16)
6975 i.suffix = WORD_MNEM_SUFFIX;
6976 else if (i.tm.opcode_modifier.size == SIZE32)
6977 i.suffix = LONG_MNEM_SUFFIX;
6978 else if (i.tm.opcode_modifier.size == SIZE64)
6979 i.suffix = QWORD_MNEM_SUFFIX;
6980 else if (i.reg_operands
6981 && (i.operands > 1 || i.types[0].bitfield.class == Reg)
6982 && !i.tm.opcode_modifier.addrprefixopreg)
6984 unsigned int numop = i.operands;
6987 is_movx = (i.tm.opcode_modifier.opcodespace == SPACE_0F
6988 && (i.tm.base_opcode | 8) == 0xbe)
6989 || (i.tm.opcode_modifier.opcodespace == SPACE_BASE
6990 && i.tm.base_opcode == 0x63
6991 && i.tm.cpu_flags.bitfield.cpu64);
6994 is_crc32 = (i.tm.base_opcode == 0xf0
6995 && i.tm.opcode_modifier.opcodespace == SPACE_0F38
6996 && i.tm.opcode_modifier.opcodeprefix == PREFIX_0XF2);
6998 /* movsx/movzx want only their source operand considered here, for the
6999 ambiguity checking below. The suffix will be replaced afterwards
7000 to represent the destination (register). */
7001 if (is_movx && (i.tm.opcode_modifier.w || i.tm.base_opcode == 0x63))
7004 /* crc32 needs REX.W set regardless of suffix / source operand size. */
7005 if (is_crc32 && i.tm.operand_types[1].bitfield.qword)
7008 /* If there's no instruction mnemonic suffix we try to invent one
7009 based on GPR operands. */
7012 /* We take i.suffix from the last register operand specified,
7013 Destination register type is more significant than source
7014 register type. crc32 in SSE4.2 prefers source register
7016 unsigned int op = is_crc32 ? 1 : i.operands;
7019 if (i.tm.operand_types[op].bitfield.instance == InstanceNone
7020 || i.tm.operand_types[op].bitfield.instance == Accum)
7022 if (i.types[op].bitfield.class != Reg)
7024 if (i.types[op].bitfield.byte)
7025 i.suffix = BYTE_MNEM_SUFFIX;
7026 else if (i.types[op].bitfield.word)
7027 i.suffix = WORD_MNEM_SUFFIX;
7028 else if (i.types[op].bitfield.dword)
7029 i.suffix = LONG_MNEM_SUFFIX;
7030 else if (i.types[op].bitfield.qword)
7031 i.suffix = QWORD_MNEM_SUFFIX;
7037 /* As an exception, movsx/movzx silently default to a byte source
7039 if (is_movx && i.tm.opcode_modifier.w && !i.suffix && !intel_syntax)
7040 i.suffix = BYTE_MNEM_SUFFIX;
7042 else if (i.suffix == BYTE_MNEM_SUFFIX)
7045 && i.tm.opcode_modifier.mnemonicsize == IGNORESIZE
7046 && i.tm.opcode_modifier.no_bsuf)
7048 else if (!check_byte_reg ())
7051 else if (i.suffix == LONG_MNEM_SUFFIX)
7054 && i.tm.opcode_modifier.mnemonicsize == IGNORESIZE
7055 && i.tm.opcode_modifier.no_lsuf
7056 && !i.tm.opcode_modifier.todword
7057 && !i.tm.opcode_modifier.toqword)
7059 else if (!check_long_reg ())
7062 else if (i.suffix == QWORD_MNEM_SUFFIX)
7065 && i.tm.opcode_modifier.mnemonicsize == IGNORESIZE
7066 && i.tm.opcode_modifier.no_qsuf
7067 && !i.tm.opcode_modifier.todword
7068 && !i.tm.opcode_modifier.toqword)
7070 else if (!check_qword_reg ())
7073 else if (i.suffix == WORD_MNEM_SUFFIX)
7076 && i.tm.opcode_modifier.mnemonicsize == IGNORESIZE
7077 && i.tm.opcode_modifier.no_wsuf)
7079 else if (!check_word_reg ())
7082 else if (intel_syntax
7083 && i.tm.opcode_modifier.mnemonicsize == IGNORESIZE)
7084 /* Do nothing if the instruction is going to ignore the prefix. */
7089 /* Undo the movsx/movzx change done above. */
7092 else if (i.tm.opcode_modifier.mnemonicsize == DEFAULTSIZE
7095 i.suffix = stackop_size;
7096 if (stackop_size == LONG_MNEM_SUFFIX)
7098 /* stackop_size is set to LONG_MNEM_SUFFIX for the
7099 .code16gcc directive to support 16-bit mode with
7100 32-bit address. For IRET without a suffix, generate
7101 16-bit IRET (opcode 0xcf) to return from an interrupt
7103 if (i.tm.base_opcode == 0xcf)
7105 i.suffix = WORD_MNEM_SUFFIX;
7106 as_warn (_("generating 16-bit `iret' for .code16gcc directive"));
7108 /* Warn about changed behavior for segment register push/pop. */
7109 else if ((i.tm.base_opcode | 1) == 0x07)
7110 as_warn (_("generating 32-bit `%s', unlike earlier gas versions"),
7115 && (i.tm.opcode_modifier.jump == JUMP_ABSOLUTE
7116 || i.tm.opcode_modifier.jump == JUMP_BYTE
7117 || i.tm.opcode_modifier.jump == JUMP_INTERSEGMENT
7118 || (i.tm.opcode_modifier.opcodespace == SPACE_0F
7119 && i.tm.base_opcode == 0x01 /* [ls][gi]dt */
7120 && i.tm.extension_opcode <= 3)))
7125 if (!i.tm.opcode_modifier.no_qsuf)
7127 if (i.tm.opcode_modifier.jump == JUMP_BYTE
7128 || i.tm.opcode_modifier.no_lsuf)
7129 i.suffix = QWORD_MNEM_SUFFIX;
7134 if (!i.tm.opcode_modifier.no_lsuf)
7135 i.suffix = LONG_MNEM_SUFFIX;
7138 if (!i.tm.opcode_modifier.no_wsuf)
7139 i.suffix = WORD_MNEM_SUFFIX;
7145 && (i.tm.opcode_modifier.mnemonicsize != DEFAULTSIZE
7146 /* Also cover lret/retf/iret in 64-bit mode. */
7147 || (flag_code == CODE_64BIT
7148 && !i.tm.opcode_modifier.no_lsuf
7149 && !i.tm.opcode_modifier.no_qsuf))
7150 && i.tm.opcode_modifier.mnemonicsize != IGNORESIZE
7151 /* Explicit sizing prefixes are assumed to disambiguate insns. */
7152 && !i.prefix[DATA_PREFIX] && !(i.prefix[REX_PREFIX] & REX_W)
7153 /* Accept FLDENV et al without suffix. */
7154 && (i.tm.opcode_modifier.no_ssuf || i.tm.opcode_modifier.floatmf))
7156 unsigned int suffixes, evex = 0;
7158 suffixes = !i.tm.opcode_modifier.no_bsuf;
7159 if (!i.tm.opcode_modifier.no_wsuf)
7161 if (!i.tm.opcode_modifier.no_lsuf)
7163 if (!i.tm.opcode_modifier.no_ldsuf)
7165 if (!i.tm.opcode_modifier.no_ssuf)
7167 if (flag_code == CODE_64BIT && !i.tm.opcode_modifier.no_qsuf)
7170 /* For [XYZ]MMWORD operands inspect operand sizes. While generally
7171 also suitable for AT&T syntax mode, it was requested that this be
7172 restricted to just Intel syntax. */
7173 if (intel_syntax && is_any_vex_encoding (&i.tm) && !i.broadcast.type)
7177 for (op = 0; op < i.tm.operands; ++op)
7179 if (is_evex_encoding (&i.tm)
7180 && !cpu_arch_flags.bitfield.cpuavx512vl)
7182 if (i.tm.operand_types[op].bitfield.ymmword)
7183 i.tm.operand_types[op].bitfield.xmmword = 0;
7184 if (i.tm.operand_types[op].bitfield.zmmword)
7185 i.tm.operand_types[op].bitfield.ymmword = 0;
7186 if (!i.tm.opcode_modifier.evex
7187 || i.tm.opcode_modifier.evex == EVEXDYN)
7188 i.tm.opcode_modifier.evex = EVEX512;
7191 if (i.tm.operand_types[op].bitfield.xmmword
7192 + i.tm.operand_types[op].bitfield.ymmword
7193 + i.tm.operand_types[op].bitfield.zmmword < 2)
7196 /* Any properly sized operand disambiguates the insn. */
7197 if (i.types[op].bitfield.xmmword
7198 || i.types[op].bitfield.ymmword
7199 || i.types[op].bitfield.zmmword)
7201 suffixes &= ~(7 << 6);
7206 if ((i.flags[op] & Operand_Mem)
7207 && i.tm.operand_types[op].bitfield.unspecified)
7209 if (i.tm.operand_types[op].bitfield.xmmword)
7211 if (i.tm.operand_types[op].bitfield.ymmword)
7213 if (i.tm.operand_types[op].bitfield.zmmword)
7215 if (is_evex_encoding (&i.tm))
7221 /* Are multiple suffixes / operand sizes allowed? */
7222 if (suffixes & (suffixes - 1))
7225 && (i.tm.opcode_modifier.mnemonicsize != DEFAULTSIZE
7226 || operand_check == check_error))
7228 as_bad (_("ambiguous operand size for `%s'"), i.tm.name);
7231 if (operand_check == check_error)
7233 as_bad (_("no instruction mnemonic suffix given and "
7234 "no register operands; can't size `%s'"), i.tm.name);
7237 if (operand_check == check_warning)
7238 as_warn (_("%s; using default for `%s'"),
7240 ? _("ambiguous operand size")
7241 : _("no instruction mnemonic suffix given and "
7242 "no register operands"),
7245 if (i.tm.opcode_modifier.floatmf)
7246 i.suffix = SHORT_MNEM_SUFFIX;
7248 /* handled below */;
7250 i.tm.opcode_modifier.evex = evex;
7251 else if (flag_code == CODE_16BIT)
7252 i.suffix = WORD_MNEM_SUFFIX;
7253 else if (!i.tm.opcode_modifier.no_lsuf)
7254 i.suffix = LONG_MNEM_SUFFIX;
7256 i.suffix = QWORD_MNEM_SUFFIX;
7262 /* In Intel syntax, movsx/movzx must have a "suffix" (checked above).
7263 In AT&T syntax, if there is no suffix (warned about above), the default
7264 will be byte extension. */
7265 if (i.tm.opcode_modifier.w && i.suffix && i.suffix != BYTE_MNEM_SUFFIX)
7266 i.tm.base_opcode |= 1;
7268 /* For further processing, the suffix should represent the destination
7269 (register). This is already the case when one was used with
7270 mov[sz][bw]*, but we need to replace it for mov[sz]x, or if there was
7271 no suffix to begin with. */
7272 if (i.tm.opcode_modifier.w || i.tm.base_opcode == 0x63 || !i.suffix)
7274 if (i.types[1].bitfield.word)
7275 i.suffix = WORD_MNEM_SUFFIX;
7276 else if (i.types[1].bitfield.qword)
7277 i.suffix = QWORD_MNEM_SUFFIX;
7279 i.suffix = LONG_MNEM_SUFFIX;
7281 i.tm.opcode_modifier.w = 0;
7285 if (!i.tm.opcode_modifier.modrm && i.reg_operands && i.tm.operands < 3)
7286 i.short_form = (i.tm.operand_types[0].bitfield.class == Reg)
7287 != (i.tm.operand_types[1].bitfield.class == Reg);
7289 /* Change the opcode based on the operand size given by i.suffix. */
7292 /* Size floating point instruction. */
7293 case LONG_MNEM_SUFFIX:
7294 if (i.tm.opcode_modifier.floatmf)
7296 i.tm.base_opcode ^= 4;
7300 case WORD_MNEM_SUFFIX:
7301 case QWORD_MNEM_SUFFIX:
7302 /* It's not a byte, select word/dword operation. */
7303 if (i.tm.opcode_modifier.w)
7306 i.tm.base_opcode |= 8;
7308 i.tm.base_opcode |= 1;
7311 case SHORT_MNEM_SUFFIX:
7312 /* Now select between word & dword operations via the operand
7313 size prefix, except for instructions that will ignore this
7315 if (i.suffix != QWORD_MNEM_SUFFIX
7316 && i.tm.opcode_modifier.mnemonicsize != IGNORESIZE
7317 && !i.tm.opcode_modifier.floatmf
7318 && !is_any_vex_encoding (&i.tm)
7319 && ((i.suffix == LONG_MNEM_SUFFIX) == (flag_code == CODE_16BIT)
7320 || (flag_code == CODE_64BIT
7321 && i.tm.opcode_modifier.jump == JUMP_BYTE)))
7323 unsigned int prefix = DATA_PREFIX_OPCODE;
7325 if (i.tm.opcode_modifier.jump == JUMP_BYTE) /* jcxz, loop */
7326 prefix = ADDR_PREFIX_OPCODE;
7328 if (!add_prefix (prefix))
7332 /* Set mode64 for an operand. */
7333 if (i.suffix == QWORD_MNEM_SUFFIX
7334 && flag_code == CODE_64BIT
7335 && !i.tm.opcode_modifier.norex64
7336 && !i.tm.opcode_modifier.vexw
7337 /* Special case for xchg %rax,%rax. It is NOP and doesn't
7339 && ! (i.operands == 2
7340 && i.tm.base_opcode == 0x90
7341 && i.tm.extension_opcode == None
7342 && i.types[0].bitfield.instance == Accum
7343 && i.types[0].bitfield.qword
7344 && i.types[1].bitfield.instance == Accum
7345 && i.types[1].bitfield.qword))
7351 /* Select word/dword/qword operation with explicit data sizing prefix
7352 when there are no suitable register operands. */
7353 if (i.tm.opcode_modifier.w
7354 && (i.prefix[DATA_PREFIX] || (i.prefix[REX_PREFIX] & REX_W))
7356 || (i.reg_operands == 1
7358 && (i.tm.operand_types[0].bitfield.instance == RegC
7360 || i.tm.operand_types[0].bitfield.instance == RegD
7361 || i.tm.operand_types[1].bitfield.instance == RegD
7364 i.tm.base_opcode |= 1;
7368 if (i.tm.opcode_modifier.addrprefixopreg)
7370 gas_assert (!i.suffix);
7371 gas_assert (i.reg_operands);
7373 if (i.tm.operand_types[0].bitfield.instance == Accum
7376 /* The address size override prefix changes the size of the
7378 if (flag_code == CODE_64BIT
7379 && i.op[0].regs->reg_type.bitfield.word)
7381 as_bad (_("16-bit addressing unavailable for `%s'"),
7386 if ((flag_code == CODE_32BIT
7387 ? i.op[0].regs->reg_type.bitfield.word
7388 : i.op[0].regs->reg_type.bitfield.dword)
7389 && !add_prefix (ADDR_PREFIX_OPCODE))
7394 /* Check invalid register operand when the address size override
7395 prefix changes the size of register operands. */
7397 enum { need_word, need_dword, need_qword } need;
7399 /* Check the register operand for the address size prefix if
7400 the memory operand has no real registers, like symbol, DISP
7401 or bogus (x32-only) symbol(%rip) when symbol(%eip) is meant. */
7402 if (i.mem_operands == 1
7403 && i.reg_operands == 1
7405 && i.types[1].bitfield.class == Reg
7406 && (flag_code == CODE_32BIT
7407 ? i.op[1].regs->reg_type.bitfield.word
7408 : i.op[1].regs->reg_type.bitfield.dword)
7409 && ((i.base_reg == NULL && i.index_reg == NULL)
7410 #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF)
7411 || (x86_elf_abi == X86_64_X32_ABI
7413 && i.base_reg->reg_num == RegIP
7414 && i.base_reg->reg_type.bitfield.qword))
7418 && !add_prefix (ADDR_PREFIX_OPCODE))
7421 if (flag_code == CODE_32BIT)
7422 need = i.prefix[ADDR_PREFIX] ? need_word : need_dword;
7423 else if (i.prefix[ADDR_PREFIX])
7426 need = flag_code == CODE_64BIT ? need_qword : need_word;
7428 for (op = 0; op < i.operands; op++)
7430 if (i.types[op].bitfield.class != Reg)
7436 if (i.op[op].regs->reg_type.bitfield.word)
7440 if (i.op[op].regs->reg_type.bitfield.dword)
7444 if (i.op[op].regs->reg_type.bitfield.qword)
7449 as_bad (_("invalid register operand size for `%s'"),
7460 check_byte_reg (void)
7464 for (op = i.operands; --op >= 0;)
7466 /* Skip non-register operands. */
7467 if (i.types[op].bitfield.class != Reg)
7470 /* If this is an eight bit register, it's OK. If it's the 16 or
7471 32 bit version of an eight bit register, we will just use the
7472 low portion, and that's OK too. */
7473 if (i.types[op].bitfield.byte)
7476 /* I/O port address operands are OK too. */
7477 if (i.tm.operand_types[op].bitfield.instance == RegD
7478 && i.tm.operand_types[op].bitfield.word)
7481 /* crc32 only wants its source operand checked here. */
7482 if (i.tm.base_opcode == 0xf0
7483 && i.tm.opcode_modifier.opcodespace == SPACE_0F38
7484 && i.tm.opcode_modifier.opcodeprefix == PREFIX_0XF2
7488 /* Any other register is bad. */
7489 as_bad (_("`%s%s' not allowed with `%s%c'"),
7490 register_prefix, i.op[op].regs->reg_name,
7491 i.tm.name, i.suffix);
7498 check_long_reg (void)
7502 for (op = i.operands; --op >= 0;)
7503 /* Skip non-register operands. */
7504 if (i.types[op].bitfield.class != Reg)
7506 /* Reject eight bit registers, except where the template requires
7507 them. (eg. movzb) */
7508 else if (i.types[op].bitfield.byte
7509 && (i.tm.operand_types[op].bitfield.class == Reg
7510 || i.tm.operand_types[op].bitfield.instance == Accum)
7511 && (i.tm.operand_types[op].bitfield.word
7512 || i.tm.operand_types[op].bitfield.dword))
7514 as_bad (_("`%s%s' not allowed with `%s%c'"),
7516 i.op[op].regs->reg_name,
7521 /* Error if the e prefix on a general reg is missing. */
7522 else if (i.types[op].bitfield.word
7523 && (i.tm.operand_types[op].bitfield.class == Reg
7524 || i.tm.operand_types[op].bitfield.instance == Accum)
7525 && i.tm.operand_types[op].bitfield.dword)
7527 as_bad (_("incorrect register `%s%s' used with `%c' suffix"),
7528 register_prefix, i.op[op].regs->reg_name,
7532 /* Warn if the r prefix on a general reg is present. */
7533 else if (i.types[op].bitfield.qword
7534 && (i.tm.operand_types[op].bitfield.class == Reg
7535 || i.tm.operand_types[op].bitfield.instance == Accum)
7536 && i.tm.operand_types[op].bitfield.dword)
7539 && i.tm.opcode_modifier.toqword
7540 && i.types[0].bitfield.class != RegSIMD)
7542 /* Convert to QWORD. We want REX byte. */
7543 i.suffix = QWORD_MNEM_SUFFIX;
7547 as_bad (_("incorrect register `%s%s' used with `%c' suffix"),
7548 register_prefix, i.op[op].regs->reg_name,
7557 check_qword_reg (void)
7561 for (op = i.operands; --op >= 0; )
7562 /* Skip non-register operands. */
7563 if (i.types[op].bitfield.class != Reg)
7565 /* Reject eight bit registers, except where the template requires
7566 them. (eg. movzb) */
7567 else if (i.types[op].bitfield.byte
7568 && (i.tm.operand_types[op].bitfield.class == Reg
7569 || i.tm.operand_types[op].bitfield.instance == Accum)
7570 && (i.tm.operand_types[op].bitfield.word
7571 || i.tm.operand_types[op].bitfield.dword))
7573 as_bad (_("`%s%s' not allowed with `%s%c'"),
7575 i.op[op].regs->reg_name,
7580 /* Warn if the r prefix on a general reg is missing. */
7581 else if ((i.types[op].bitfield.word
7582 || i.types[op].bitfield.dword)
7583 && (i.tm.operand_types[op].bitfield.class == Reg
7584 || i.tm.operand_types[op].bitfield.instance == Accum)
7585 && i.tm.operand_types[op].bitfield.qword)
7587 /* Prohibit these changes in the 64bit mode, since the
7588 lowering is more complicated. */
7590 && i.tm.opcode_modifier.todword
7591 && i.types[0].bitfield.class != RegSIMD)
7593 /* Convert to DWORD. We don't want REX byte. */
7594 i.suffix = LONG_MNEM_SUFFIX;
7598 as_bad (_("incorrect register `%s%s' used with `%c' suffix"),
7599 register_prefix, i.op[op].regs->reg_name,
7608 check_word_reg (void)
7611 for (op = i.operands; --op >= 0;)
7612 /* Skip non-register operands. */
7613 if (i.types[op].bitfield.class != Reg)
7615 /* Reject eight bit registers, except where the template requires
7616 them. (eg. movzb) */
7617 else if (i.types[op].bitfield.byte
7618 && (i.tm.operand_types[op].bitfield.class == Reg
7619 || i.tm.operand_types[op].bitfield.instance == Accum)
7620 && (i.tm.operand_types[op].bitfield.word
7621 || i.tm.operand_types[op].bitfield.dword))
7623 as_bad (_("`%s%s' not allowed with `%s%c'"),
7625 i.op[op].regs->reg_name,
7630 /* Error if the e or r prefix on a general reg is present. */
7631 else if ((i.types[op].bitfield.dword
7632 || i.types[op].bitfield.qword)
7633 && (i.tm.operand_types[op].bitfield.class == Reg
7634 || i.tm.operand_types[op].bitfield.instance == Accum)
7635 && i.tm.operand_types[op].bitfield.word)
7637 as_bad (_("incorrect register `%s%s' used with `%c' suffix"),
7638 register_prefix, i.op[op].regs->reg_name,
7646 update_imm (unsigned int j)
7648 i386_operand_type overlap = i.types[j];
7649 if ((overlap.bitfield.imm8
7650 || overlap.bitfield.imm8s
7651 || overlap.bitfield.imm16
7652 || overlap.bitfield.imm32
7653 || overlap.bitfield.imm32s
7654 || overlap.bitfield.imm64)
7655 && !operand_type_equal (&overlap, &imm8)
7656 && !operand_type_equal (&overlap, &imm8s)
7657 && !operand_type_equal (&overlap, &imm16)
7658 && !operand_type_equal (&overlap, &imm32)
7659 && !operand_type_equal (&overlap, &imm32s)
7660 && !operand_type_equal (&overlap, &imm64))
7664 i386_operand_type temp;
7666 operand_type_set (&temp, 0);
7667 if (i.suffix == BYTE_MNEM_SUFFIX)
7669 temp.bitfield.imm8 = overlap.bitfield.imm8;
7670 temp.bitfield.imm8s = overlap.bitfield.imm8s;
7672 else if (i.suffix == WORD_MNEM_SUFFIX)
7673 temp.bitfield.imm16 = overlap.bitfield.imm16;
7674 else if (i.suffix == QWORD_MNEM_SUFFIX)
7676 temp.bitfield.imm64 = overlap.bitfield.imm64;
7677 temp.bitfield.imm32s = overlap.bitfield.imm32s;
7680 temp.bitfield.imm32 = overlap.bitfield.imm32;
7683 else if (operand_type_equal (&overlap, &imm16_32_32s)
7684 || operand_type_equal (&overlap, &imm16_32)
7685 || operand_type_equal (&overlap, &imm16_32s))
7687 if ((flag_code == CODE_16BIT) ^ (i.prefix[DATA_PREFIX] != 0))
7692 else if (i.prefix[REX_PREFIX] & REX_W)
7693 overlap = operand_type_and (overlap, imm32s);
7694 else if (i.prefix[DATA_PREFIX])
7695 overlap = operand_type_and (overlap,
7696 flag_code != CODE_16BIT ? imm16 : imm32);
7697 if (!operand_type_equal (&overlap, &imm8)
7698 && !operand_type_equal (&overlap, &imm8s)
7699 && !operand_type_equal (&overlap, &imm16)
7700 && !operand_type_equal (&overlap, &imm32)
7701 && !operand_type_equal (&overlap, &imm32s)
7702 && !operand_type_equal (&overlap, &imm64))
7704 as_bad (_("no instruction mnemonic suffix given; "
7705 "can't determine immediate size"));
7709 i.types[j] = overlap;
7719 /* Update the first 2 immediate operands. */
7720 n = i.operands > 2 ? 2 : i.operands;
7723 for (j = 0; j < n; j++)
7724 if (update_imm (j) == 0)
7727 /* The 3rd operand can't be immediate operand. */
7728 gas_assert (operand_type_check (i.types[2], imm) == 0);
7735 process_operands (void)
7737 /* Default segment register this instruction will use for memory
7738 accesses. 0 means unknown. This is only for optimizing out
7739 unnecessary segment overrides. */
7740 const reg_entry *default_seg = NULL;
7742 if (i.tm.opcode_modifier.sse2avx)
7744 /* Legacy encoded insns allow explicit REX prefixes, so these prefixes
7746 i.rex |= i.prefix[REX_PREFIX] & (REX_W | REX_R | REX_X | REX_B);
7747 i.prefix[REX_PREFIX] = 0;
7750 /* ImmExt should be processed after SSE2AVX. */
7751 else if (i.tm.opcode_modifier.immext)
7754 if (i.tm.opcode_modifier.sse2avx && i.tm.opcode_modifier.vexvvvv)
7756 unsigned int dupl = i.operands;
7757 unsigned int dest = dupl - 1;
7760 /* The destination must be an xmm register. */
7761 gas_assert (i.reg_operands
7762 && MAX_OPERANDS > dupl
7763 && operand_type_equal (&i.types[dest], ®xmm));
7765 if (i.tm.operand_types[0].bitfield.instance == Accum
7766 && i.tm.operand_types[0].bitfield.xmmword)
7768 if (i.tm.opcode_modifier.vexsources == VEX3SOURCES)
7770 /* Keep xmm0 for instructions with VEX prefix and 3
7772 i.tm.operand_types[0].bitfield.instance = InstanceNone;
7773 i.tm.operand_types[0].bitfield.class = RegSIMD;
7778 /* We remove the first xmm0 and keep the number of
7779 operands unchanged, which in fact duplicates the
7781 for (j = 1; j < i.operands; j++)
7783 i.op[j - 1] = i.op[j];
7784 i.types[j - 1] = i.types[j];
7785 i.tm.operand_types[j - 1] = i.tm.operand_types[j];
7786 i.flags[j - 1] = i.flags[j];
7790 else if (i.tm.opcode_modifier.implicit1stxmm0)
7792 gas_assert ((MAX_OPERANDS - 1) > dupl
7793 && (i.tm.opcode_modifier.vexsources
7796 /* Add the implicit xmm0 for instructions with VEX prefix
7798 for (j = i.operands; j > 0; j--)
7800 i.op[j] = i.op[j - 1];
7801 i.types[j] = i.types[j - 1];
7802 i.tm.operand_types[j] = i.tm.operand_types[j - 1];
7803 i.flags[j] = i.flags[j - 1];
7806 = (const reg_entry *) str_hash_find (reg_hash, "xmm0");
7807 i.types[0] = regxmm;
7808 i.tm.operand_types[0] = regxmm;
7811 i.reg_operands += 2;
7816 i.op[dupl] = i.op[dest];
7817 i.types[dupl] = i.types[dest];
7818 i.tm.operand_types[dupl] = i.tm.operand_types[dest];
7819 i.flags[dupl] = i.flags[dest];
7828 i.op[dupl] = i.op[dest];
7829 i.types[dupl] = i.types[dest];
7830 i.tm.operand_types[dupl] = i.tm.operand_types[dest];
7831 i.flags[dupl] = i.flags[dest];
7834 if (i.tm.opcode_modifier.immext)
7837 else if (i.tm.operand_types[0].bitfield.instance == Accum
7838 && i.tm.operand_types[0].bitfield.xmmword)
7842 for (j = 1; j < i.operands; j++)
7844 i.op[j - 1] = i.op[j];
7845 i.types[j - 1] = i.types[j];
7847 /* We need to adjust fields in i.tm since they are used by
7848 build_modrm_byte. */
7849 i.tm.operand_types [j - 1] = i.tm.operand_types [j];
7851 i.flags[j - 1] = i.flags[j];
7858 else if (i.tm.opcode_modifier.implicitquadgroup)
7860 unsigned int regnum, first_reg_in_group, last_reg_in_group;
7862 /* The second operand must be {x,y,z}mmN, where N is a multiple of 4. */
7863 gas_assert (i.operands >= 2 && i.types[1].bitfield.class == RegSIMD);
7864 regnum = register_number (i.op[1].regs);
7865 first_reg_in_group = regnum & ~3;
7866 last_reg_in_group = first_reg_in_group + 3;
7867 if (regnum != first_reg_in_group)
7868 as_warn (_("source register `%s%s' implicitly denotes"
7869 " `%s%.3s%u' to `%s%.3s%u' source group in `%s'"),
7870 register_prefix, i.op[1].regs->reg_name,
7871 register_prefix, i.op[1].regs->reg_name, first_reg_in_group,
7872 register_prefix, i.op[1].regs->reg_name, last_reg_in_group,
7875 else if (i.tm.opcode_modifier.regkludge)
7877 /* The imul $imm, %reg instruction is converted into
7878 imul $imm, %reg, %reg, and the clr %reg instruction
7879 is converted into xor %reg, %reg. */
7881 unsigned int first_reg_op;
7883 if (operand_type_check (i.types[0], reg))
7887 /* Pretend we saw the extra register operand. */
7888 gas_assert (i.reg_operands == 1
7889 && i.op[first_reg_op + 1].regs == 0);
7890 i.op[first_reg_op + 1].regs = i.op[first_reg_op].regs;
7891 i.types[first_reg_op + 1] = i.types[first_reg_op];
7896 if (i.tm.opcode_modifier.modrm)
7898 /* The opcode is completed (modulo i.tm.extension_opcode which
7899 must be put into the modrm byte). Now, we make the modrm and
7900 index base bytes based on all the info we've collected. */
7902 default_seg = build_modrm_byte ();
7904 else if (i.types[0].bitfield.class == SReg)
7906 if (flag_code != CODE_64BIT
7907 ? i.tm.base_opcode == POP_SEG_SHORT
7908 && i.op[0].regs->reg_num == 1
7909 : (i.tm.base_opcode | 1) == (POP_SEG386_SHORT & 0xff)
7910 && i.op[0].regs->reg_num < 4)
7912 as_bad (_("you can't `%s %s%s'"),
7913 i.tm.name, register_prefix, i.op[0].regs->reg_name);
7916 if (i.op[0].regs->reg_num > 3
7917 && i.tm.opcode_modifier.opcodespace == SPACE_BASE )
7919 i.tm.base_opcode ^= (POP_SEG_SHORT ^ POP_SEG386_SHORT) & 0xff;
7920 i.tm.opcode_modifier.opcodespace = SPACE_0F;
7922 i.tm.base_opcode |= (i.op[0].regs->reg_num << 3);
7924 else if (i.tm.opcode_modifier.opcodespace == SPACE_BASE
7925 && (i.tm.base_opcode & ~3) == MOV_AX_DISP32)
7927 default_seg = reg_ds;
7929 else if (i.tm.opcode_modifier.isstring)
7931 /* For the string instructions that allow a segment override
7932 on one of their operands, the default segment is ds. */
7933 default_seg = reg_ds;
7935 else if (i.short_form)
7937 /* The register or float register operand is in operand
7939 unsigned int op = i.tm.operand_types[0].bitfield.class != Reg;
7941 /* Register goes in low 3 bits of opcode. */
7942 i.tm.base_opcode |= i.op[op].regs->reg_num;
7943 if ((i.op[op].regs->reg_flags & RegRex) != 0)
7945 if (!quiet_warnings && i.tm.opcode_modifier.ugh)
7947 /* Warn about some common errors, but press on regardless.
7948 The first case can be generated by gcc (<= 2.8.1). */
7949 if (i.operands == 2)
7951 /* Reversed arguments on faddp, fsubp, etc. */
7952 as_warn (_("translating to `%s %s%s,%s%s'"), i.tm.name,
7953 register_prefix, i.op[!intel_syntax].regs->reg_name,
7954 register_prefix, i.op[intel_syntax].regs->reg_name);
7958 /* Extraneous `l' suffix on fp insn. */
7959 as_warn (_("translating to `%s %s%s'"), i.tm.name,
7960 register_prefix, i.op[0].regs->reg_name);
7965 if ((i.seg[0] || i.prefix[SEG_PREFIX])
7966 && i.tm.base_opcode == 0x8d /* lea */
7967 && i.tm.opcode_modifier.opcodespace == SPACE_BASE
7968 && !is_any_vex_encoding(&i.tm))
7970 if (!quiet_warnings)
7971 as_warn (_("segment override on `%s' is ineffectual"), i.tm.name);
7975 i.prefix[SEG_PREFIX] = 0;
7979 /* If a segment was explicitly specified, and the specified segment
7980 is neither the default nor the one already recorded from a prefix,
7981 use an opcode prefix to select it. If we never figured out what
7982 the default segment is, then default_seg will be zero at this
7983 point, and the specified segment prefix will always be used. */
7985 && i.seg[0] != default_seg
7986 && i386_seg_prefixes[i.seg[0]->reg_num] != i.prefix[SEG_PREFIX])
7988 if (!add_prefix (i386_seg_prefixes[i.seg[0]->reg_num]))
7994 static INLINE void set_rex_vrex (const reg_entry *r, unsigned int rex_bit,
7997 if (r->reg_flags & RegRex)
7999 if (i.rex & rex_bit)
8000 as_bad (_("same type of prefix used twice"));
8003 else if (do_sse2avx && (i.rex & rex_bit) && i.vex.register_specifier)
8005 gas_assert (i.vex.register_specifier == r);
8006 i.vex.register_specifier += 8;
8009 if (r->reg_flags & RegVRex)
8013 static const reg_entry *
8014 build_modrm_byte (void)
8016 const reg_entry *default_seg = NULL;
8017 unsigned int source, dest;
8020 vex_3_sources = i.tm.opcode_modifier.vexsources == VEX3SOURCES;
8023 unsigned int nds, reg_slot;
8026 dest = i.operands - 1;
8029 /* There are 2 kinds of instructions:
8030 1. 5 operands: 4 register operands or 3 register operands
8031 plus 1 memory operand plus one Imm4 operand, VexXDS, and
8032 VexW0 or VexW1. The destination must be either XMM, YMM or
8034 2. 4 operands: 4 register operands or 3 register operands
8035 plus 1 memory operand, with VexXDS. */
8036 gas_assert ((i.reg_operands == 4
8037 || (i.reg_operands == 3 && i.mem_operands == 1))
8038 && i.tm.opcode_modifier.vexvvvv == VEXXDS
8039 && i.tm.opcode_modifier.vexw
8040 && i.tm.operand_types[dest].bitfield.class == RegSIMD);
8042 /* If VexW1 is set, the first non-immediate operand is the source and
8043 the second non-immediate one is encoded in the immediate operand. */
8044 if (i.tm.opcode_modifier.vexw == VEXW1)
8046 source = i.imm_operands;
8047 reg_slot = i.imm_operands + 1;
8051 source = i.imm_operands + 1;
8052 reg_slot = i.imm_operands;
8055 if (i.imm_operands == 0)
8057 /* When there is no immediate operand, generate an 8bit
8058 immediate operand to encode the first operand. */
8059 exp = &im_expressions[i.imm_operands++];
8060 i.op[i.operands].imms = exp;
8061 i.types[i.operands] = imm8;
8064 gas_assert (i.tm.operand_types[reg_slot].bitfield.class == RegSIMD);
8065 exp->X_op = O_constant;
8066 exp->X_add_number = register_number (i.op[reg_slot].regs) << 4;
8067 gas_assert ((i.op[reg_slot].regs->reg_flags & RegVRex) == 0);
8071 gas_assert (i.imm_operands == 1);
8072 gas_assert (fits_in_imm4 (i.op[0].imms->X_add_number));
8073 gas_assert (!i.tm.opcode_modifier.immext);
8075 /* Turn on Imm8 again so that output_imm will generate it. */
8076 i.types[0].bitfield.imm8 = 1;
8078 gas_assert (i.tm.operand_types[reg_slot].bitfield.class == RegSIMD);
8079 i.op[0].imms->X_add_number
8080 |= register_number (i.op[reg_slot].regs) << 4;
8081 gas_assert ((i.op[reg_slot].regs->reg_flags & RegVRex) == 0);
8084 gas_assert (i.tm.operand_types[nds].bitfield.class == RegSIMD);
8085 i.vex.register_specifier = i.op[nds].regs;
8090 /* i.reg_operands MUST be the number of real register operands;
8091 implicit registers do not count. If there are 3 register
8092 operands, it must be a instruction with VexNDS. For a
8093 instruction with VexNDD, the destination register is encoded
8094 in VEX prefix. If there are 4 register operands, it must be
8095 a instruction with VEX prefix and 3 sources. */
8096 if (i.mem_operands == 0
8097 && ((i.reg_operands == 2
8098 && i.tm.opcode_modifier.vexvvvv <= VEXXDS)
8099 || (i.reg_operands == 3
8100 && i.tm.opcode_modifier.vexvvvv == VEXXDS)
8101 || (i.reg_operands == 4 && vex_3_sources)))
8109 /* When there are 3 operands, one of them may be immediate,
8110 which may be the first or the last operand. Otherwise,
8111 the first operand must be shift count register (cl) or it
8112 is an instruction with VexNDS. */
8113 gas_assert (i.imm_operands == 1
8114 || (i.imm_operands == 0
8115 && (i.tm.opcode_modifier.vexvvvv == VEXXDS
8116 || (i.types[0].bitfield.instance == RegC
8117 && i.types[0].bitfield.byte))));
8118 if (operand_type_check (i.types[0], imm)
8119 || (i.types[0].bitfield.instance == RegC
8120 && i.types[0].bitfield.byte))
8126 /* When there are 4 operands, the first two must be 8bit
8127 immediate operands. The source operand will be the 3rd
8130 For instructions with VexNDS, if the first operand
8131 an imm8, the source operand is the 2nd one. If the last
8132 operand is imm8, the source operand is the first one. */
8133 gas_assert ((i.imm_operands == 2
8134 && i.types[0].bitfield.imm8
8135 && i.types[1].bitfield.imm8)
8136 || (i.tm.opcode_modifier.vexvvvv == VEXXDS
8137 && i.imm_operands == 1
8138 && (i.types[0].bitfield.imm8
8139 || i.types[i.operands - 1].bitfield.imm8
8140 || i.rounding.type != rc_none)));
8141 if (i.imm_operands == 2)
8145 if (i.types[0].bitfield.imm8)
8152 if (is_evex_encoding (&i.tm))
8154 /* For EVEX instructions, when there are 5 operands, the
8155 first one must be immediate operand. If the second one
8156 is immediate operand, the source operand is the 3th
8157 one. If the last one is immediate operand, the source
8158 operand is the 2nd one. */
8159 gas_assert (i.imm_operands == 2
8160 && i.tm.opcode_modifier.sae
8161 && operand_type_check (i.types[0], imm));
8162 if (operand_type_check (i.types[1], imm))
8164 else if (operand_type_check (i.types[4], imm))
8178 /* RC/SAE operand could be between DEST and SRC. That happens
8179 when one operand is GPR and the other one is XMM/YMM/ZMM
8181 if (i.rounding.type != rc_none && i.rounding.operand == dest)
8184 if (i.tm.opcode_modifier.vexvvvv == VEXXDS)
8186 /* For instructions with VexNDS, the register-only source
8187 operand must be a 32/64bit integer, XMM, YMM, ZMM, or mask
8188 register. It is encoded in VEX prefix. */
8190 i386_operand_type op;
8193 /* Swap two source operands if needed. */
8194 if (i.tm.opcode_modifier.swapsources)
8202 op = i.tm.operand_types[vvvv];
8203 if ((dest + 1) >= i.operands
8204 || ((op.bitfield.class != Reg
8205 || (!op.bitfield.dword && !op.bitfield.qword))
8206 && op.bitfield.class != RegSIMD
8207 && !operand_type_equal (&op, ®mask)))
8209 i.vex.register_specifier = i.op[vvvv].regs;
8215 /* One of the register operands will be encoded in the i.rm.reg
8216 field, the other in the combined i.rm.mode and i.rm.regmem
8217 fields. If no form of this instruction supports a memory
8218 destination operand, then we assume the source operand may
8219 sometimes be a memory operand and so we need to store the
8220 destination in the i.rm.reg field. */
8221 if (!i.tm.opcode_modifier.regmem
8222 && operand_type_check (i.tm.operand_types[dest], anymem) == 0)
8224 i.rm.reg = i.op[dest].regs->reg_num;
8225 i.rm.regmem = i.op[source].regs->reg_num;
8226 set_rex_vrex (i.op[dest].regs, REX_R, i.tm.opcode_modifier.sse2avx);
8227 set_rex_vrex (i.op[source].regs, REX_B, false);
8231 i.rm.reg = i.op[source].regs->reg_num;
8232 i.rm.regmem = i.op[dest].regs->reg_num;
8233 set_rex_vrex (i.op[dest].regs, REX_B, i.tm.opcode_modifier.sse2avx);
8234 set_rex_vrex (i.op[source].regs, REX_R, false);
8236 if (flag_code != CODE_64BIT && (i.rex & REX_R))
8238 if (i.types[!i.tm.opcode_modifier.regmem].bitfield.class != RegCR)
8241 add_prefix (LOCK_PREFIX_OPCODE);
8245 { /* If it's not 2 reg operands... */
8250 unsigned int fake_zero_displacement = 0;
8253 for (op = 0; op < i.operands; op++)
8254 if (i.flags[op] & Operand_Mem)
8256 gas_assert (op < i.operands);
8258 if (i.tm.opcode_modifier.sib)
8260 /* The index register of VSIB shouldn't be RegIZ. */
8261 if (i.tm.opcode_modifier.sib != SIBMEM
8262 && i.index_reg->reg_num == RegIZ)
8265 i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING;
8268 i.sib.base = NO_BASE_REGISTER;
8269 i.sib.scale = i.log2_scale_factor;
8270 i.types[op].bitfield.disp8 = 0;
8271 i.types[op].bitfield.disp16 = 0;
8272 i.types[op].bitfield.disp64 = 0;
8273 if (want_disp32 (&i.tm))
8275 /* Must be 32 bit */
8276 i.types[op].bitfield.disp32 = 1;
8277 i.types[op].bitfield.disp32s = 0;
8281 i.types[op].bitfield.disp32 = 0;
8282 i.types[op].bitfield.disp32s = 1;
8286 /* Since the mandatory SIB always has index register, so
8287 the code logic remains unchanged. The non-mandatory SIB
8288 without index register is allowed and will be handled
8292 if (i.index_reg->reg_num == RegIZ)
8293 i.sib.index = NO_INDEX_REGISTER;
8295 i.sib.index = i.index_reg->reg_num;
8296 set_rex_vrex (i.index_reg, REX_X, false);
8300 default_seg = reg_ds;
8302 if (i.base_reg == 0)
8305 if (!i.disp_operands)
8306 fake_zero_displacement = 1;
8307 if (i.index_reg == 0)
8309 i386_operand_type newdisp;
8311 /* Both check for VSIB and mandatory non-vector SIB. */
8312 gas_assert (!i.tm.opcode_modifier.sib
8313 || i.tm.opcode_modifier.sib == SIBMEM);
8314 /* Operand is just <disp> */
8315 if (flag_code == CODE_64BIT)
8317 /* 64bit mode overwrites the 32bit absolute
8318 addressing by RIP relative addressing and
8319 absolute addressing is encoded by one of the
8320 redundant SIB forms. */
8321 i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING;
8322 i.sib.base = NO_BASE_REGISTER;
8323 i.sib.index = NO_INDEX_REGISTER;
8324 newdisp = (want_disp32(&i.tm) ? disp32 : disp32s);
8326 else if ((flag_code == CODE_16BIT)
8327 ^ (i.prefix[ADDR_PREFIX] != 0))
8329 i.rm.regmem = NO_BASE_REGISTER_16;
8334 i.rm.regmem = NO_BASE_REGISTER;
8337 i.types[op] = operand_type_and_not (i.types[op], anydisp);
8338 i.types[op] = operand_type_or (i.types[op], newdisp);
8340 else if (!i.tm.opcode_modifier.sib)
8342 /* !i.base_reg && i.index_reg */
8343 if (i.index_reg->reg_num == RegIZ)
8344 i.sib.index = NO_INDEX_REGISTER;
8346 i.sib.index = i.index_reg->reg_num;
8347 i.sib.base = NO_BASE_REGISTER;
8348 i.sib.scale = i.log2_scale_factor;
8349 i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING;
8350 i.types[op].bitfield.disp8 = 0;
8351 i.types[op].bitfield.disp16 = 0;
8352 i.types[op].bitfield.disp64 = 0;
8353 if (want_disp32 (&i.tm))
8355 /* Must be 32 bit */
8356 i.types[op].bitfield.disp32 = 1;
8357 i.types[op].bitfield.disp32s = 0;
8361 i.types[op].bitfield.disp32 = 0;
8362 i.types[op].bitfield.disp32s = 1;
8364 if ((i.index_reg->reg_flags & RegRex) != 0)
8368 /* RIP addressing for 64bit mode. */
8369 else if (i.base_reg->reg_num == RegIP)
8371 gas_assert (!i.tm.opcode_modifier.sib);
8372 i.rm.regmem = NO_BASE_REGISTER;
8373 i.types[op].bitfield.disp8 = 0;
8374 i.types[op].bitfield.disp16 = 0;
8375 i.types[op].bitfield.disp32 = 0;
8376 i.types[op].bitfield.disp32s = 1;
8377 i.types[op].bitfield.disp64 = 0;
8378 i.flags[op] |= Operand_PCrel;
8379 if (! i.disp_operands)
8380 fake_zero_displacement = 1;
8382 else if (i.base_reg->reg_type.bitfield.word)
8384 gas_assert (!i.tm.opcode_modifier.sib);
8385 switch (i.base_reg->reg_num)
8388 if (i.index_reg == 0)
8390 else /* (%bx,%si) -> 0, or (%bx,%di) -> 1 */
8391 i.rm.regmem = i.index_reg->reg_num - 6;
8394 default_seg = reg_ss;
8395 if (i.index_reg == 0)
8398 if (operand_type_check (i.types[op], disp) == 0)
8400 /* fake (%bp) into 0(%bp) */
8401 if (i.disp_encoding == disp_encoding_16bit)
8402 i.types[op].bitfield.disp16 = 1;
8404 i.types[op].bitfield.disp8 = 1;
8405 fake_zero_displacement = 1;
8408 else /* (%bp,%si) -> 2, or (%bp,%di) -> 3 */
8409 i.rm.regmem = i.index_reg->reg_num - 6 + 2;
8411 default: /* (%si) -> 4 or (%di) -> 5 */
8412 i.rm.regmem = i.base_reg->reg_num - 6 + 4;
8414 if (!fake_zero_displacement
8418 fake_zero_displacement = 1;
8419 if (i.disp_encoding == disp_encoding_8bit)
8420 i.types[op].bitfield.disp8 = 1;
8422 i.types[op].bitfield.disp16 = 1;
8424 i.rm.mode = mode_from_disp_size (i.types[op]);
8426 else /* i.base_reg and 32/64 bit mode */
8428 if (operand_type_check (i.types[op], disp))
8430 i.types[op].bitfield.disp16 = 0;
8431 i.types[op].bitfield.disp64 = 0;
8432 if (!want_disp32 (&i.tm))
8434 i.types[op].bitfield.disp32 = 0;
8435 i.types[op].bitfield.disp32s = 1;
8439 i.types[op].bitfield.disp32 = 1;
8440 i.types[op].bitfield.disp32s = 0;
8444 if (!i.tm.opcode_modifier.sib)
8445 i.rm.regmem = i.base_reg->reg_num;
8446 if ((i.base_reg->reg_flags & RegRex) != 0)
8448 i.sib.base = i.base_reg->reg_num;
8449 /* x86-64 ignores REX prefix bit here to avoid decoder
8451 if (!(i.base_reg->reg_flags & RegRex)
8452 && (i.base_reg->reg_num == EBP_REG_NUM
8453 || i.base_reg->reg_num == ESP_REG_NUM))
8454 default_seg = reg_ss;
8455 if (i.base_reg->reg_num == 5 && i.disp_operands == 0)
8457 fake_zero_displacement = 1;
8458 if (i.disp_encoding == disp_encoding_32bit)
8459 i.types[op].bitfield.disp32 = 1;
8461 i.types[op].bitfield.disp8 = 1;
8463 i.sib.scale = i.log2_scale_factor;
8464 if (i.index_reg == 0)
8466 /* Only check for VSIB. */
8467 gas_assert (i.tm.opcode_modifier.sib != VECSIB128
8468 && i.tm.opcode_modifier.sib != VECSIB256
8469 && i.tm.opcode_modifier.sib != VECSIB512);
8471 /* <disp>(%esp) becomes two byte modrm with no index
8472 register. We've already stored the code for esp
8473 in i.rm.regmem ie. ESCAPE_TO_TWO_BYTE_ADDRESSING.
8474 Any base register besides %esp will not use the
8475 extra modrm byte. */
8476 i.sib.index = NO_INDEX_REGISTER;
8478 else if (!i.tm.opcode_modifier.sib)
8480 if (i.index_reg->reg_num == RegIZ)
8481 i.sib.index = NO_INDEX_REGISTER;
8483 i.sib.index = i.index_reg->reg_num;
8484 i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING;
8485 if ((i.index_reg->reg_flags & RegRex) != 0)
8490 && (i.reloc[op] == BFD_RELOC_386_TLS_DESC_CALL
8491 || i.reloc[op] == BFD_RELOC_X86_64_TLSDESC_CALL))
8495 if (!fake_zero_displacement
8499 fake_zero_displacement = 1;
8500 if (i.disp_encoding == disp_encoding_8bit)
8501 i.types[op].bitfield.disp8 = 1;
8503 i.types[op].bitfield.disp32 = 1;
8505 i.rm.mode = mode_from_disp_size (i.types[op]);
8509 if (fake_zero_displacement)
8511 /* Fakes a zero displacement assuming that i.types[op]
8512 holds the correct displacement size. */
8515 gas_assert (i.op[op].disps == 0);
8516 exp = &disp_expressions[i.disp_operands++];
8517 i.op[op].disps = exp;
8518 exp->X_op = O_constant;
8519 exp->X_add_number = 0;
8520 exp->X_add_symbol = (symbolS *) 0;
8521 exp->X_op_symbol = (symbolS *) 0;
8529 if (i.tm.opcode_modifier.vexsources == XOP2SOURCES)
8531 if (operand_type_check (i.types[0], imm))
8532 i.vex.register_specifier = NULL;
8535 /* VEX.vvvv encodes one of the sources when the first
8536 operand is not an immediate. */
8537 if (i.tm.opcode_modifier.vexw == VEXW0)
8538 i.vex.register_specifier = i.op[0].regs;
8540 i.vex.register_specifier = i.op[1].regs;
8543 /* Destination is a XMM register encoded in the ModRM.reg
8545 i.rm.reg = i.op[2].regs->reg_num;
8546 if ((i.op[2].regs->reg_flags & RegRex) != 0)
8549 /* ModRM.rm and VEX.B encodes the other source. */
8550 if (!i.mem_operands)
8554 if (i.tm.opcode_modifier.vexw == VEXW0)
8555 i.rm.regmem = i.op[1].regs->reg_num;
8557 i.rm.regmem = i.op[0].regs->reg_num;
8559 if ((i.op[1].regs->reg_flags & RegRex) != 0)
8563 else if (i.tm.opcode_modifier.vexvvvv == VEXLWP)
8565 i.vex.register_specifier = i.op[2].regs;
8566 if (!i.mem_operands)
8569 i.rm.regmem = i.op[1].regs->reg_num;
8570 if ((i.op[1].regs->reg_flags & RegRex) != 0)
8574 /* Fill in i.rm.reg or i.rm.regmem field with register operand
8575 (if any) based on i.tm.extension_opcode. Again, we must be
8576 careful to make sure that segment/control/debug/test/MMX
8577 registers are coded into the i.rm.reg field. */
8578 else if (i.reg_operands)
8581 unsigned int vex_reg = ~0;
8583 for (op = 0; op < i.operands; op++)
8584 if (i.types[op].bitfield.class == Reg
8585 || i.types[op].bitfield.class == RegBND
8586 || i.types[op].bitfield.class == RegMask
8587 || i.types[op].bitfield.class == SReg
8588 || i.types[op].bitfield.class == RegCR
8589 || i.types[op].bitfield.class == RegDR
8590 || i.types[op].bitfield.class == RegTR
8591 || i.types[op].bitfield.class == RegSIMD
8592 || i.types[op].bitfield.class == RegMMX)
8597 else if (i.tm.opcode_modifier.vexvvvv == VEXXDS)
8599 /* For instructions with VexNDS, the register-only
8600 source operand is encoded in VEX prefix. */
8601 gas_assert (mem != (unsigned int) ~0);
8606 gas_assert (op < i.operands);
8610 /* Check register-only source operand when two source
8611 operands are swapped. */
8612 if (!i.tm.operand_types[op].bitfield.baseindex
8613 && i.tm.operand_types[op + 1].bitfield.baseindex)
8617 gas_assert (mem == (vex_reg + 1)
8618 && op < i.operands);
8623 gas_assert (vex_reg < i.operands);
8627 else if (i.tm.opcode_modifier.vexvvvv == VEXNDD)
8629 /* For instructions with VexNDD, the register destination
8630 is encoded in VEX prefix. */
8631 if (i.mem_operands == 0)
8633 /* There is no memory operand. */
8634 gas_assert ((op + 2) == i.operands);
8639 /* There are only 2 non-immediate operands. */
8640 gas_assert (op < i.imm_operands + 2
8641 && i.operands == i.imm_operands + 2);
8642 vex_reg = i.imm_operands + 1;
8646 gas_assert (op < i.operands);
8648 if (vex_reg != (unsigned int) ~0)
8650 i386_operand_type *type = &i.tm.operand_types[vex_reg];
8652 if ((type->bitfield.class != Reg
8653 || (!type->bitfield.dword && !type->bitfield.qword))
8654 && type->bitfield.class != RegSIMD
8655 && !operand_type_equal (type, ®mask))
8658 i.vex.register_specifier = i.op[vex_reg].regs;
8661 /* Don't set OP operand twice. */
8664 /* If there is an extension opcode to put here, the
8665 register number must be put into the regmem field. */
8666 if (i.tm.extension_opcode != None)
8668 i.rm.regmem = i.op[op].regs->reg_num;
8669 set_rex_vrex (i.op[op].regs, REX_B,
8670 i.tm.opcode_modifier.sse2avx);
8674 i.rm.reg = i.op[op].regs->reg_num;
8675 set_rex_vrex (i.op[op].regs, REX_R,
8676 i.tm.opcode_modifier.sse2avx);
8680 /* Now, if no memory operand has set i.rm.mode = 0, 1, 2 we
8681 must set it to 3 to indicate this is a register operand
8682 in the regmem field. */
8683 if (!i.mem_operands)
8687 /* Fill in i.rm.reg field with extension opcode (if any). */
8688 if (i.tm.extension_opcode != None)
8689 i.rm.reg = i.tm.extension_opcode;
8695 frag_opcode_byte (unsigned char byte)
8697 if (now_seg != absolute_section)
8698 FRAG_APPEND_1_CHAR (byte);
8700 ++abs_section_offset;
8704 flip_code16 (unsigned int code16)
8706 gas_assert (i.tm.operands == 1);
8708 return !(i.prefix[REX_PREFIX] & REX_W)
8709 && (code16 ? i.tm.operand_types[0].bitfield.disp32
8710 || i.tm.operand_types[0].bitfield.disp32s
8711 : i.tm.operand_types[0].bitfield.disp16)
8716 output_branch (void)
8722 relax_substateT subtype;
8726 if (now_seg == absolute_section)
8728 as_bad (_("relaxable branches not supported in absolute section"));
8732 code16 = flag_code == CODE_16BIT ? CODE16 : 0;
8733 size = i.disp_encoding == disp_encoding_32bit ? BIG : SMALL;
8736 if (i.prefix[DATA_PREFIX] != 0)
8740 code16 ^= flip_code16(code16);
8742 /* Pentium4 branch hints. */
8743 if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE /* not taken */
8744 || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE /* taken */)
8749 if (i.prefix[REX_PREFIX] != 0)
8755 /* BND prefixed jump. */
8756 if (i.prefix[BND_PREFIX] != 0)
8762 if (i.prefixes != 0)
8763 as_warn (_("skipping prefixes on `%s'"), i.tm.name);
8765 /* It's always a symbol; End frag & setup for relax.
8766 Make sure there is enough room in this frag for the largest
8767 instruction we may generate in md_convert_frag. This is 2
8768 bytes for the opcode and room for the prefix and largest
8770 frag_grow (prefix + 2 + 4);
8771 /* Prefix and 1 opcode byte go in fr_fix. */
8772 p = frag_more (prefix + 1);
8773 if (i.prefix[DATA_PREFIX] != 0)
8774 *p++ = DATA_PREFIX_OPCODE;
8775 if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE
8776 || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE)
8777 *p++ = i.prefix[SEG_PREFIX];
8778 if (i.prefix[BND_PREFIX] != 0)
8779 *p++ = BND_PREFIX_OPCODE;
8780 if (i.prefix[REX_PREFIX] != 0)
8781 *p++ = i.prefix[REX_PREFIX];
8782 *p = i.tm.base_opcode;
8784 if ((unsigned char) *p == JUMP_PC_RELATIVE)
8785 subtype = ENCODE_RELAX_STATE (UNCOND_JUMP, size);
8786 else if (cpu_arch_flags.bitfield.cpui386)
8787 subtype = ENCODE_RELAX_STATE (COND_JUMP, size);
8789 subtype = ENCODE_RELAX_STATE (COND_JUMP86, size);
8792 sym = i.op[0].disps->X_add_symbol;
8793 off = i.op[0].disps->X_add_number;
8795 if (i.op[0].disps->X_op != O_constant
8796 && i.op[0].disps->X_op != O_symbol)
8798 /* Handle complex expressions. */
8799 sym = make_expr_symbol (i.op[0].disps);
8803 /* 1 possible extra opcode + 4 byte displacement go in var part.
8804 Pass reloc in fr_var. */
8805 frag_var (rs_machine_dependent, 5, i.reloc[0], subtype, sym, off, p);
8808 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
8809 /* Return TRUE iff PLT32 relocation should be used for branching to
8813 need_plt32_p (symbolS *s)
8815 /* PLT32 relocation is ELF only. */
8820 /* Don't emit PLT32 relocation on Solaris: neither native linker nor
8821 krtld support it. */
8825 /* Since there is no need to prepare for PLT branch on x86-64, we
8826 can generate R_X86_64_PLT32, instead of R_X86_64_PC32, which can
8827 be used as a marker for 32-bit PC-relative branches. */
8834 /* Weak or undefined symbol need PLT32 relocation. */
8835 if (S_IS_WEAK (s) || !S_IS_DEFINED (s))
8838 /* Non-global symbol doesn't need PLT32 relocation. */
8839 if (! S_IS_EXTERNAL (s))
8842 /* Other global symbols need PLT32 relocation. NB: Symbol with
8843 non-default visibilities are treated as normal global symbol
8844 so that PLT32 relocation can be used as a marker for 32-bit
8845 PC-relative branches. It is useful for linker relaxation. */
8856 bfd_reloc_code_real_type jump_reloc = i.reloc[0];
8858 if (i.tm.opcode_modifier.jump == JUMP_BYTE)
8860 /* This is a loop or jecxz type instruction. */
8862 if (i.prefix[ADDR_PREFIX] != 0)
8864 frag_opcode_byte (ADDR_PREFIX_OPCODE);
8867 /* Pentium4 branch hints. */
8868 if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE /* not taken */
8869 || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE /* taken */)
8871 frag_opcode_byte (i.prefix[SEG_PREFIX]);
8880 if (flag_code == CODE_16BIT)
8883 if (i.prefix[DATA_PREFIX] != 0)
8885 frag_opcode_byte (DATA_PREFIX_OPCODE);
8887 code16 ^= flip_code16(code16);
8895 /* BND prefixed jump. */
8896 if (i.prefix[BND_PREFIX] != 0)
8898 frag_opcode_byte (i.prefix[BND_PREFIX]);
8902 if (i.prefix[REX_PREFIX] != 0)
8904 frag_opcode_byte (i.prefix[REX_PREFIX]);
8908 if (i.prefixes != 0)
8909 as_warn (_("skipping prefixes on `%s'"), i.tm.name);
8911 if (now_seg == absolute_section)
8913 abs_section_offset += i.opcode_length + size;
8917 p = frag_more (i.opcode_length + size);
8918 switch (i.opcode_length)
8921 *p++ = i.tm.base_opcode >> 8;
8924 *p++ = i.tm.base_opcode;
8930 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
8932 && jump_reloc == NO_RELOC
8933 && need_plt32_p (i.op[0].disps->X_add_symbol))
8934 jump_reloc = BFD_RELOC_X86_64_PLT32;
8937 jump_reloc = reloc (size, 1, 1, jump_reloc);
8939 fixP = fix_new_exp (frag_now, p - frag_now->fr_literal, size,
8940 i.op[0].disps, 1, jump_reloc);
8942 /* All jumps handled here are signed, but don't unconditionally use a
8943 signed limit check for 32 and 16 bit jumps as we want to allow wrap
8944 around at 4G (outside of 64-bit mode) and 64k (except for XBEGIN)
8949 fixP->fx_signed = 1;
8953 if (i.tm.base_opcode == 0xc7f8)
8954 fixP->fx_signed = 1;
8958 if (flag_code == CODE_64BIT)
8959 fixP->fx_signed = 1;
8965 output_interseg_jump (void)
8973 if (flag_code == CODE_16BIT)
8977 if (i.prefix[DATA_PREFIX] != 0)
8984 gas_assert (!i.prefix[REX_PREFIX]);
8990 if (i.prefixes != 0)
8991 as_warn (_("skipping prefixes on `%s'"), i.tm.name);
8993 if (now_seg == absolute_section)
8995 abs_section_offset += prefix + 1 + 2 + size;
8999 /* 1 opcode; 2 segment; offset */
9000 p = frag_more (prefix + 1 + 2 + size);
9002 if (i.prefix[DATA_PREFIX] != 0)
9003 *p++ = DATA_PREFIX_OPCODE;
9005 if (i.prefix[REX_PREFIX] != 0)
9006 *p++ = i.prefix[REX_PREFIX];
9008 *p++ = i.tm.base_opcode;
9009 if (i.op[1].imms->X_op == O_constant)
9011 offsetT n = i.op[1].imms->X_add_number;
9014 && !fits_in_unsigned_word (n)
9015 && !fits_in_signed_word (n))
9017 as_bad (_("16-bit jump out of range"));
9020 md_number_to_chars (p, n, size);
9023 fix_new_exp (frag_now, p - frag_now->fr_literal, size,
9024 i.op[1].imms, 0, reloc (size, 0, 0, i.reloc[1]));
9027 if (i.op[0].imms->X_op == O_constant)
9028 md_number_to_chars (p, (valueT) i.op[0].imms->X_add_number, 2);
9030 fix_new_exp (frag_now, p - frag_now->fr_literal, 2,
9031 i.op[0].imms, 0, reloc (2, 0, 0, i.reloc[0]));
9034 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
9039 asection *seg = now_seg;
9040 subsegT subseg = now_subseg;
9042 unsigned int alignment, align_size_1;
9043 unsigned int isa_1_descsz, feature_2_descsz, descsz;
9044 unsigned int isa_1_descsz_raw, feature_2_descsz_raw;
9045 unsigned int padding;
9047 if (!IS_ELF || !x86_used_note)
9050 x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_X86;
9052 /* The .note.gnu.property section layout:
9054 Field Length Contents
9057 n_descsz 4 The note descriptor size
9058 n_type 4 NT_GNU_PROPERTY_TYPE_0
9060 n_desc n_descsz The program property array
9064 /* Create the .note.gnu.property section. */
9065 sec = subseg_new (NOTE_GNU_PROPERTY_SECTION_NAME, 0);
9066 bfd_set_section_flags (sec,
9073 if (get_elf_backend_data (stdoutput)->s->elfclass == ELFCLASS64)
9084 bfd_set_section_alignment (sec, alignment);
9085 elf_section_type (sec) = SHT_NOTE;
9087 /* GNU_PROPERTY_X86_ISA_1_USED: 4-byte type + 4-byte data size
9089 isa_1_descsz_raw = 4 + 4 + 4;
9090 /* Align GNU_PROPERTY_X86_ISA_1_USED. */
9091 isa_1_descsz = (isa_1_descsz_raw + align_size_1) & ~align_size_1;
9093 feature_2_descsz_raw = isa_1_descsz;
9094 /* GNU_PROPERTY_X86_FEATURE_2_USED: 4-byte type + 4-byte data size
9096 feature_2_descsz_raw += 4 + 4 + 4;
9097 /* Align GNU_PROPERTY_X86_FEATURE_2_USED. */
9098 feature_2_descsz = ((feature_2_descsz_raw + align_size_1)
9101 descsz = feature_2_descsz;
9102 /* Section size: n_namsz + n_descsz + n_type + n_name + n_descsz. */
9103 p = frag_more (4 + 4 + 4 + 4 + descsz);
9105 /* Write n_namsz. */
9106 md_number_to_chars (p, (valueT) 4, 4);
9108 /* Write n_descsz. */
9109 md_number_to_chars (p + 4, (valueT) descsz, 4);
9112 md_number_to_chars (p + 4 * 2, (valueT) NT_GNU_PROPERTY_TYPE_0, 4);
9115 memcpy (p + 4 * 3, "GNU", 4);
9117 /* Write 4-byte type. */
9118 md_number_to_chars (p + 4 * 4,
9119 (valueT) GNU_PROPERTY_X86_ISA_1_USED, 4);
9121 /* Write 4-byte data size. */
9122 md_number_to_chars (p + 4 * 5, (valueT) 4, 4);
9124 /* Write 4-byte data. */
9125 md_number_to_chars (p + 4 * 6, (valueT) x86_isa_1_used, 4);
9127 /* Zero out paddings. */
9128 padding = isa_1_descsz - isa_1_descsz_raw;
9130 memset (p + 4 * 7, 0, padding);
9132 /* Write 4-byte type. */
9133 md_number_to_chars (p + isa_1_descsz + 4 * 4,
9134 (valueT) GNU_PROPERTY_X86_FEATURE_2_USED, 4);
9136 /* Write 4-byte data size. */
9137 md_number_to_chars (p + isa_1_descsz + 4 * 5, (valueT) 4, 4);
9139 /* Write 4-byte data. */
9140 md_number_to_chars (p + isa_1_descsz + 4 * 6,
9141 (valueT) x86_feature_2_used, 4);
9143 /* Zero out paddings. */
9144 padding = feature_2_descsz - feature_2_descsz_raw;
9146 memset (p + isa_1_descsz + 4 * 7, 0, padding);
9148 /* We probably can't restore the current segment, for there likely
9151 subseg_set (seg, subseg);
9156 encoding_length (const fragS *start_frag, offsetT start_off,
9157 const char *frag_now_ptr)
9159 unsigned int len = 0;
9161 if (start_frag != frag_now)
9163 const fragS *fr = start_frag;
9168 } while (fr && fr != frag_now);
9171 return len - start_off + (frag_now_ptr - frag_now->fr_literal);
9174 /* Return 1 for test, and, cmp, add, sub, inc and dec which may
9175 be macro-fused with conditional jumps.
9176 NB: If TEST/AND/CMP/ADD/SUB/INC/DEC is of RIP relative address,
9177 or is one of the following format:
9190 maybe_fused_with_jcc_p (enum mf_cmp_kind* mf_cmp_p)
9192 /* No RIP address. */
9193 if (i.base_reg && i.base_reg->reg_num == RegIP)
9196 /* No opcodes outside of base encoding space. */
9197 if (i.tm.opcode_modifier.opcodespace != SPACE_BASE)
9200 /* add, sub without add/sub m, imm. */
9201 if (i.tm.base_opcode <= 5
9202 || (i.tm.base_opcode >= 0x28 && i.tm.base_opcode <= 0x2d)
9203 || ((i.tm.base_opcode | 3) == 0x83
9204 && (i.tm.extension_opcode == 0x5
9205 || i.tm.extension_opcode == 0x0)))
9207 *mf_cmp_p = mf_cmp_alu_cmp;
9208 return !(i.mem_operands && i.imm_operands);
9211 /* and without and m, imm. */
9212 if ((i.tm.base_opcode >= 0x20 && i.tm.base_opcode <= 0x25)
9213 || ((i.tm.base_opcode | 3) == 0x83
9214 && i.tm.extension_opcode == 0x4))
9216 *mf_cmp_p = mf_cmp_test_and;
9217 return !(i.mem_operands && i.imm_operands);
9220 /* test without test m imm. */
9221 if ((i.tm.base_opcode | 1) == 0x85
9222 || (i.tm.base_opcode | 1) == 0xa9
9223 || ((i.tm.base_opcode | 1) == 0xf7
9224 && i.tm.extension_opcode == 0))
9226 *mf_cmp_p = mf_cmp_test_and;
9227 return !(i.mem_operands && i.imm_operands);
9230 /* cmp without cmp m, imm. */
9231 if ((i.tm.base_opcode >= 0x38 && i.tm.base_opcode <= 0x3d)
9232 || ((i.tm.base_opcode | 3) == 0x83
9233 && (i.tm.extension_opcode == 0x7)))
9235 *mf_cmp_p = mf_cmp_alu_cmp;
9236 return !(i.mem_operands && i.imm_operands);
9239 /* inc, dec without inc/dec m. */
9240 if ((i.tm.cpu_flags.bitfield.cpuno64
9241 && (i.tm.base_opcode | 0xf) == 0x4f)
9242 || ((i.tm.base_opcode | 1) == 0xff
9243 && i.tm.extension_opcode <= 0x1))
9245 *mf_cmp_p = mf_cmp_incdec;
9246 return !i.mem_operands;
9252 /* Return 1 if a FUSED_JCC_PADDING frag should be generated. */
9255 add_fused_jcc_padding_frag_p (enum mf_cmp_kind* mf_cmp_p)
9257 /* NB: Don't work with COND_JUMP86 without i386. */
9258 if (!align_branch_power
9259 || now_seg == absolute_section
9260 || !cpu_arch_flags.bitfield.cpui386
9261 || !(align_branch & align_branch_fused_bit))
9264 if (maybe_fused_with_jcc_p (mf_cmp_p))
9266 if (last_insn.kind == last_insn_other
9267 || last_insn.seg != now_seg)
9270 as_warn_where (last_insn.file, last_insn.line,
9271 _("`%s` skips -malign-branch-boundary on `%s`"),
9272 last_insn.name, i.tm.name);
9278 /* Return 1 if a BRANCH_PREFIX frag should be generated. */
9281 add_branch_prefix_frag_p (void)
9283 /* NB: Don't work with COND_JUMP86 without i386. Don't add prefix
9284 to PadLock instructions since they include prefixes in opcode. */
9285 if (!align_branch_power
9286 || !align_branch_prefix_size
9287 || now_seg == absolute_section
9288 || i.tm.cpu_flags.bitfield.cpupadlock
9289 || !cpu_arch_flags.bitfield.cpui386)
9292 /* Don't add prefix if it is a prefix or there is no operand in case
9293 that segment prefix is special. */
9294 if (!i.operands || i.tm.opcode_modifier.isprefix)
9297 if (last_insn.kind == last_insn_other
9298 || last_insn.seg != now_seg)
9302 as_warn_where (last_insn.file, last_insn.line,
9303 _("`%s` skips -malign-branch-boundary on `%s`"),
9304 last_insn.name, i.tm.name);
9309 /* Return 1 if a BRANCH_PADDING frag should be generated. */
9312 add_branch_padding_frag_p (enum align_branch_kind *branch_p,
9313 enum mf_jcc_kind *mf_jcc_p)
9317 /* NB: Don't work with COND_JUMP86 without i386. */
9318 if (!align_branch_power
9319 || now_seg == absolute_section
9320 || !cpu_arch_flags.bitfield.cpui386
9321 || i.tm.opcode_modifier.opcodespace != SPACE_BASE)
9326 /* Check for jcc and direct jmp. */
9327 if (i.tm.opcode_modifier.jump == JUMP)
9329 if (i.tm.base_opcode == JUMP_PC_RELATIVE)
9331 *branch_p = align_branch_jmp;
9332 add_padding = align_branch & align_branch_jmp_bit;
9336 /* Because J<cc> and JN<cc> share same group in macro-fusible table,
9337 igore the lowest bit. */
9338 *mf_jcc_p = (i.tm.base_opcode & 0x0e) >> 1;
9339 *branch_p = align_branch_jcc;
9340 if ((align_branch & align_branch_jcc_bit))
9344 else if ((i.tm.base_opcode | 1) == 0xc3)
9347 *branch_p = align_branch_ret;
9348 if ((align_branch & align_branch_ret_bit))
9353 /* Check for indirect jmp, direct and indirect calls. */
9354 if (i.tm.base_opcode == 0xe8)
9357 *branch_p = align_branch_call;
9358 if ((align_branch & align_branch_call_bit))
9361 else if (i.tm.base_opcode == 0xff
9362 && (i.tm.extension_opcode == 2
9363 || i.tm.extension_opcode == 4))
9365 /* Indirect call and jmp. */
9366 *branch_p = align_branch_indirect;
9367 if ((align_branch & align_branch_indirect_bit))
9374 && (i.op[0].disps->X_op == O_symbol
9375 || (i.op[0].disps->X_op == O_subtract
9376 && i.op[0].disps->X_op_symbol == GOT_symbol)))
9378 symbolS *s = i.op[0].disps->X_add_symbol;
9379 /* No padding to call to global or undefined tls_get_addr. */
9380 if ((S_IS_EXTERNAL (s) || !S_IS_DEFINED (s))
9381 && strcmp (S_GET_NAME (s), tls_get_addr) == 0)
9387 && last_insn.kind != last_insn_other
9388 && last_insn.seg == now_seg)
9391 as_warn_where (last_insn.file, last_insn.line,
9392 _("`%s` skips -malign-branch-boundary on `%s`"),
9393 last_insn.name, i.tm.name);
9403 fragS *insn_start_frag;
9404 offsetT insn_start_off;
9405 fragS *fragP = NULL;
9406 enum align_branch_kind branch = align_branch_none;
9407 /* The initializer is arbitrary just to avoid uninitialized error.
9408 it's actually either assigned in add_branch_padding_frag_p
9409 or never be used. */
9410 enum mf_jcc_kind mf_jcc = mf_jcc_jo;
9412 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
9413 if (IS_ELF && x86_used_note && now_seg != absolute_section)
9415 if ((i.xstate & xstate_tmm) == xstate_tmm
9416 || i.tm.cpu_flags.bitfield.cpuamx_tile)
9417 x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_TMM;
9419 if (i.tm.cpu_flags.bitfield.cpu8087
9420 || i.tm.cpu_flags.bitfield.cpu287
9421 || i.tm.cpu_flags.bitfield.cpu387
9422 || i.tm.cpu_flags.bitfield.cpu687
9423 || i.tm.cpu_flags.bitfield.cpufisttp)
9424 x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_X87;
9426 if ((i.xstate & xstate_mmx)
9427 || (i.tm.opcode_modifier.opcodespace == SPACE_0F
9428 && !is_any_vex_encoding (&i.tm)
9429 && (i.tm.base_opcode == 0x77 /* emms */
9430 || i.tm.base_opcode == 0x0e /* femms */)))
9431 x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_MMX;
9435 if (i.index_reg->reg_type.bitfield.zmmword)
9436 i.xstate |= xstate_zmm;
9437 else if (i.index_reg->reg_type.bitfield.ymmword)
9438 i.xstate |= xstate_ymm;
9439 else if (i.index_reg->reg_type.bitfield.xmmword)
9440 i.xstate |= xstate_xmm;
9443 /* vzeroall / vzeroupper */
9444 if (i.tm.base_opcode == 0x77 && i.tm.cpu_flags.bitfield.cpuavx)
9445 i.xstate |= xstate_ymm;
9447 if ((i.xstate & xstate_xmm)
9448 /* ldmxcsr / stmxcsr / vldmxcsr / vstmxcsr */
9449 || (i.tm.base_opcode == 0xae
9450 && (i.tm.cpu_flags.bitfield.cpusse
9451 || i.tm.cpu_flags.bitfield.cpuavx))
9452 || i.tm.cpu_flags.bitfield.cpuwidekl
9453 || i.tm.cpu_flags.bitfield.cpukl)
9454 x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_XMM;
9456 if ((i.xstate & xstate_ymm) == xstate_ymm)
9457 x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_YMM;
9458 if ((i.xstate & xstate_zmm) == xstate_zmm)
9459 x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_ZMM;
9460 if (i.mask.reg || (i.xstate & xstate_mask) == xstate_mask)
9461 x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_MASK;
9462 if (i.tm.cpu_flags.bitfield.cpufxsr)
9463 x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_FXSR;
9464 if (i.tm.cpu_flags.bitfield.cpuxsave)
9465 x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_XSAVE;
9466 if (i.tm.cpu_flags.bitfield.cpuxsaveopt)
9467 x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT;
9468 if (i.tm.cpu_flags.bitfield.cpuxsavec)
9469 x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_XSAVEC;
9471 if (x86_feature_2_used
9472 || i.tm.cpu_flags.bitfield.cpucmov
9473 || i.tm.cpu_flags.bitfield.cpusyscall
9474 || (i.tm.opcode_modifier.opcodespace == SPACE_0F
9475 && i.tm.base_opcode == 0xc7
9476 && i.tm.opcode_modifier.opcodeprefix == PREFIX_NONE
9477 && i.tm.extension_opcode == 1) /* cmpxchg8b */)
9478 x86_isa_1_used |= GNU_PROPERTY_X86_ISA_1_BASELINE;
9479 if (i.tm.cpu_flags.bitfield.cpusse3
9480 || i.tm.cpu_flags.bitfield.cpussse3
9481 || i.tm.cpu_flags.bitfield.cpusse4_1
9482 || i.tm.cpu_flags.bitfield.cpusse4_2
9483 || i.tm.cpu_flags.bitfield.cpucx16
9484 || i.tm.cpu_flags.bitfield.cpupopcnt
9485 /* LAHF-SAHF insns in 64-bit mode. */
9486 || (flag_code == CODE_64BIT
9487 && (i.tm.base_opcode | 1) == 0x9f
9488 && i.tm.opcode_modifier.opcodespace == SPACE_BASE))
9489 x86_isa_1_used |= GNU_PROPERTY_X86_ISA_1_V2;
9490 if (i.tm.cpu_flags.bitfield.cpuavx
9491 || i.tm.cpu_flags.bitfield.cpuavx2
9492 /* Any VEX encoded insns execpt for CpuAVX512F, CpuAVX512BW,
9493 CpuAVX512DQ, LPW, TBM and AMX. */
9494 || (i.tm.opcode_modifier.vex
9495 && !i.tm.cpu_flags.bitfield.cpuavx512f
9496 && !i.tm.cpu_flags.bitfield.cpuavx512bw
9497 && !i.tm.cpu_flags.bitfield.cpuavx512dq
9498 && !i.tm.cpu_flags.bitfield.cpulwp
9499 && !i.tm.cpu_flags.bitfield.cputbm
9500 && !(x86_feature_2_used & GNU_PROPERTY_X86_FEATURE_2_TMM))
9501 || i.tm.cpu_flags.bitfield.cpuf16c
9502 || i.tm.cpu_flags.bitfield.cpufma
9503 || i.tm.cpu_flags.bitfield.cpulzcnt
9504 || i.tm.cpu_flags.bitfield.cpumovbe
9505 || i.tm.cpu_flags.bitfield.cpuxsaves
9506 || (x86_feature_2_used
9507 & (GNU_PROPERTY_X86_FEATURE_2_XSAVE
9508 | GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
9509 | GNU_PROPERTY_X86_FEATURE_2_XSAVEC)) != 0)
9510 x86_isa_1_used |= GNU_PROPERTY_X86_ISA_1_V3;
9511 if (i.tm.cpu_flags.bitfield.cpuavx512f
9512 || i.tm.cpu_flags.bitfield.cpuavx512bw
9513 || i.tm.cpu_flags.bitfield.cpuavx512dq
9514 || i.tm.cpu_flags.bitfield.cpuavx512vl
9515 /* Any EVEX encoded insns except for AVX512ER, AVX512PF and
9517 || (i.tm.opcode_modifier.evex
9518 && !i.tm.cpu_flags.bitfield.cpuavx512er
9519 && !i.tm.cpu_flags.bitfield.cpuavx512pf
9520 && !i.tm.cpu_flags.bitfield.cpuavx512_4vnniw))
9521 x86_isa_1_used |= GNU_PROPERTY_X86_ISA_1_V4;
9525 /* Tie dwarf2 debug info to the address at the start of the insn.
9526 We can't do this after the insn has been output as the current
9527 frag may have been closed off. eg. by frag_var. */
9528 dwarf2_emit_insn (0);
9530 insn_start_frag = frag_now;
9531 insn_start_off = frag_now_fix ();
9533 if (add_branch_padding_frag_p (&branch, &mf_jcc))
9536 /* Branch can be 8 bytes. Leave some room for prefixes. */
9537 unsigned int max_branch_padding_size = 14;
9539 /* Align section to boundary. */
9540 record_alignment (now_seg, align_branch_power);
9542 /* Make room for padding. */
9543 frag_grow (max_branch_padding_size);
9545 /* Start of the padding. */
9550 frag_var (rs_machine_dependent, max_branch_padding_size, 0,
9551 ENCODE_RELAX_STATE (BRANCH_PADDING, 0),
9554 fragP->tc_frag_data.mf_type = mf_jcc;
9555 fragP->tc_frag_data.branch_type = branch;
9556 fragP->tc_frag_data.max_bytes = max_branch_padding_size;
9560 if (i.tm.opcode_modifier.jump == JUMP)
9562 else if (i.tm.opcode_modifier.jump == JUMP_BYTE
9563 || i.tm.opcode_modifier.jump == JUMP_DWORD)
9565 else if (i.tm.opcode_modifier.jump == JUMP_INTERSEGMENT)
9566 output_interseg_jump ();
9569 /* Output normal instructions here. */
9573 enum mf_cmp_kind mf_cmp;
9576 && (i.tm.base_opcode == 0xaee8
9577 || i.tm.base_opcode == 0xaef0
9578 || i.tm.base_opcode == 0xaef8))
9580 /* Encode lfence, mfence, and sfence as
9581 f0 83 04 24 00 lock addl $0x0, (%{re}sp). */
9582 if (now_seg != absolute_section)
9584 offsetT val = 0x240483f0ULL;
9587 md_number_to_chars (p, val, 5);
9590 abs_section_offset += 5;
9594 /* Some processors fail on LOCK prefix. This options makes
9595 assembler ignore LOCK prefix and serves as a workaround. */
9596 if (omit_lock_prefix)
9598 if (i.tm.base_opcode == LOCK_PREFIX_OPCODE
9599 && i.tm.opcode_modifier.isprefix)
9601 i.prefix[LOCK_PREFIX] = 0;
9605 /* Skip if this is a branch. */
9607 else if (add_fused_jcc_padding_frag_p (&mf_cmp))
9609 /* Make room for padding. */
9610 frag_grow (MAX_FUSED_JCC_PADDING_SIZE);
9615 frag_var (rs_machine_dependent, MAX_FUSED_JCC_PADDING_SIZE, 0,
9616 ENCODE_RELAX_STATE (FUSED_JCC_PADDING, 0),
9619 fragP->tc_frag_data.mf_type = mf_cmp;
9620 fragP->tc_frag_data.branch_type = align_branch_fused;
9621 fragP->tc_frag_data.max_bytes = MAX_FUSED_JCC_PADDING_SIZE;
9623 else if (add_branch_prefix_frag_p ())
9625 unsigned int max_prefix_size = align_branch_prefix_size;
9627 /* Make room for padding. */
9628 frag_grow (max_prefix_size);
9633 frag_var (rs_machine_dependent, max_prefix_size, 0,
9634 ENCODE_RELAX_STATE (BRANCH_PREFIX, 0),
9637 fragP->tc_frag_data.max_bytes = max_prefix_size;
9640 /* Since the VEX/EVEX prefix contains the implicit prefix, we
9641 don't need the explicit prefix. */
9642 if (!i.tm.opcode_modifier.vex && !i.tm.opcode_modifier.evex)
9644 switch (i.tm.opcode_modifier.opcodeprefix)
9653 if (!i.tm.cpu_flags.bitfield.cpupadlock
9654 || (i.prefix[REP_PREFIX] != 0xf3))
9658 switch (i.opcode_length)
9663 /* Check for pseudo prefixes. */
9664 if (!i.tm.opcode_modifier.isprefix || i.tm.base_opcode)
9666 as_bad_where (insn_start_frag->fr_file,
9667 insn_start_frag->fr_line,
9668 _("pseudo prefix without instruction"));
9678 #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF)
9679 /* For x32, add a dummy REX_OPCODE prefix for mov/add with
9680 R_X86_64_GOTTPOFF relocation so that linker can safely
9681 perform IE->LE optimization. A dummy REX_OPCODE prefix
9682 is also needed for lea with R_X86_64_GOTPC32_TLSDESC
9683 relocation for GDesc -> IE/LE optimization. */
9684 if (x86_elf_abi == X86_64_X32_ABI
9686 && (i.reloc[0] == BFD_RELOC_X86_64_GOTTPOFF
9687 || i.reloc[0] == BFD_RELOC_X86_64_GOTPC32_TLSDESC)
9688 && i.prefix[REX_PREFIX] == 0)
9689 add_prefix (REX_OPCODE);
9692 /* The prefix bytes. */
9693 for (j = ARRAY_SIZE (i.prefix), q = i.prefix; j > 0; j--, q++)
9695 frag_opcode_byte (*q);
9699 for (j = 0, q = i.prefix; j < ARRAY_SIZE (i.prefix); j++, q++)
9705 frag_opcode_byte (*q);
9708 /* There should be no other prefixes for instructions
9713 /* For EVEX instructions i.vrex should become 0 after
9714 build_evex_prefix. For VEX instructions upper 16 registers
9715 aren't available, so VREX should be 0. */
9718 /* Now the VEX prefix. */
9719 if (now_seg != absolute_section)
9721 p = frag_more (i.vex.length);
9722 for (j = 0; j < i.vex.length; j++)
9723 p[j] = i.vex.bytes[j];
9726 abs_section_offset += i.vex.length;
9729 /* Now the opcode; be careful about word order here! */
9730 j = i.opcode_length;
9732 switch (i.tm.opcode_modifier.opcodespace)
9747 if (now_seg == absolute_section)
9748 abs_section_offset += j;
9751 FRAG_APPEND_1_CHAR (i.tm.base_opcode);
9757 && i.tm.opcode_modifier.opcodespace != SPACE_BASE)
9760 if (i.tm.opcode_modifier.opcodespace != SPACE_0F)
9761 *p++ = i.tm.opcode_modifier.opcodespace == SPACE_0F38
9765 switch (i.opcode_length)
9768 /* Put out high byte first: can't use md_number_to_chars! */
9769 *p++ = (i.tm.base_opcode >> 8) & 0xff;
9772 *p = i.tm.base_opcode & 0xff;
9781 /* Now the modrm byte and sib byte (if present). */
9782 if (i.tm.opcode_modifier.modrm)
9784 frag_opcode_byte ((i.rm.regmem << 0)
9786 | (i.rm.mode << 6));
9787 /* If i.rm.regmem == ESP (4)
9788 && i.rm.mode != (Register mode)
9790 ==> need second modrm byte. */
9791 if (i.rm.regmem == ESCAPE_TO_TWO_BYTE_ADDRESSING
9793 && !(i.base_reg && i.base_reg->reg_type.bitfield.word))
9794 frag_opcode_byte ((i.sib.base << 0)
9795 | (i.sib.index << 3)
9796 | (i.sib.scale << 6));
9799 if (i.disp_operands)
9800 output_disp (insn_start_frag, insn_start_off);
9803 output_imm (insn_start_frag, insn_start_off);
9806 * frag_now_fix () returning plain abs_section_offset when we're in the
9807 * absolute section, and abs_section_offset not getting updated as data
9808 * gets added to the frag breaks the logic below.
9810 if (now_seg != absolute_section)
9812 j = encoding_length (insn_start_frag, insn_start_off, frag_more (0));
9814 as_warn (_("instruction length of %u bytes exceeds the limit of 15"),
9818 /* NB: Don't add prefix with GOTPC relocation since
9819 output_disp() above depends on the fixed encoding
9820 length. Can't add prefix with TLS relocation since
9821 it breaks TLS linker optimization. */
9822 unsigned int max = i.has_gotpc_tls_reloc ? 0 : 15 - j;
9823 /* Prefix count on the current instruction. */
9824 unsigned int count = i.vex.length;
9826 for (k = 0; k < ARRAY_SIZE (i.prefix); k++)
9827 /* REX byte is encoded in VEX/EVEX prefix. */
9828 if (i.prefix[k] && (k != REX_PREFIX || !i.vex.length))
9831 /* Count prefixes for extended opcode maps. */
9833 switch (i.tm.opcode_modifier.opcodespace)
9848 if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype)
9851 /* Set the maximum prefix size in BRANCH_PREFIX
9853 if (fragP->tc_frag_data.max_bytes > max)
9854 fragP->tc_frag_data.max_bytes = max;
9855 if (fragP->tc_frag_data.max_bytes > count)
9856 fragP->tc_frag_data.max_bytes -= count;
9858 fragP->tc_frag_data.max_bytes = 0;
9862 /* Remember the maximum prefix size in FUSED_JCC_PADDING
9864 unsigned int max_prefix_size;
9865 if (align_branch_prefix_size > max)
9866 max_prefix_size = max;
9868 max_prefix_size = align_branch_prefix_size;
9869 if (max_prefix_size > count)
9870 fragP->tc_frag_data.max_prefix_length
9871 = max_prefix_size - count;
9874 /* Use existing segment prefix if possible. Use CS
9875 segment prefix in 64-bit mode. In 32-bit mode, use SS
9876 segment prefix with ESP/EBP base register and use DS
9877 segment prefix without ESP/EBP base register. */
9878 if (i.prefix[SEG_PREFIX])
9879 fragP->tc_frag_data.default_prefix = i.prefix[SEG_PREFIX];
9880 else if (flag_code == CODE_64BIT)
9881 fragP->tc_frag_data.default_prefix = CS_PREFIX_OPCODE;
9883 && (i.base_reg->reg_num == 4
9884 || i.base_reg->reg_num == 5))
9885 fragP->tc_frag_data.default_prefix = SS_PREFIX_OPCODE;
9887 fragP->tc_frag_data.default_prefix = DS_PREFIX_OPCODE;
9892 /* NB: Don't work with COND_JUMP86 without i386. */
9893 if (align_branch_power
9894 && now_seg != absolute_section
9895 && cpu_arch_flags.bitfield.cpui386)
9897 /* Terminate each frag so that we can add prefix and check for
9899 frag_wane (frag_now);
9906 pi ("" /*line*/, &i);
9908 #endif /* DEBUG386 */
9911 /* Return the size of the displacement operand N. */
9914 disp_size (unsigned int n)
9918 if (i.types[n].bitfield.disp64)
9920 else if (i.types[n].bitfield.disp8)
9922 else if (i.types[n].bitfield.disp16)
9927 /* Return the size of the immediate operand N. */
9930 imm_size (unsigned int n)
9933 if (i.types[n].bitfield.imm64)
9935 else if (i.types[n].bitfield.imm8 || i.types[n].bitfield.imm8s)
9937 else if (i.types[n].bitfield.imm16)
9943 output_disp (fragS *insn_start_frag, offsetT insn_start_off)
9948 for (n = 0; n < i.operands; n++)
9950 if (operand_type_check (i.types[n], disp))
9952 int size = disp_size (n);
9954 if (now_seg == absolute_section)
9955 abs_section_offset += size;
9956 else if (i.op[n].disps->X_op == O_constant)
9958 offsetT val = i.op[n].disps->X_add_number;
9960 val = offset_in_range (val >> (size == 1 ? i.memshift : 0),
9962 p = frag_more (size);
9963 md_number_to_chars (p, val, size);
9967 enum bfd_reloc_code_real reloc_type;
9968 int sign = i.types[n].bitfield.disp32s;
9969 int pcrel = (i.flags[n] & Operand_PCrel) != 0;
9972 /* We can't have 8 bit displacement here. */
9973 gas_assert (!i.types[n].bitfield.disp8);
9975 /* The PC relative address is computed relative
9976 to the instruction boundary, so in case immediate
9977 fields follows, we need to adjust the value. */
9978 if (pcrel && i.imm_operands)
9983 for (n1 = 0; n1 < i.operands; n1++)
9984 if (operand_type_check (i.types[n1], imm))
9986 /* Only one immediate is allowed for PC
9987 relative address. */
9988 gas_assert (sz == 0);
9990 i.op[n].disps->X_add_number -= sz;
9992 /* We should find the immediate. */
9993 gas_assert (sz != 0);
9996 p = frag_more (size);
9997 reloc_type = reloc (size, pcrel, sign, i.reloc[n]);
9999 && GOT_symbol == i.op[n].disps->X_add_symbol
10000 && (((reloc_type == BFD_RELOC_32
10001 || reloc_type == BFD_RELOC_X86_64_32S
10002 || (reloc_type == BFD_RELOC_64
10004 && (i.op[n].disps->X_op == O_symbol
10005 || (i.op[n].disps->X_op == O_add
10006 && ((symbol_get_value_expression
10007 (i.op[n].disps->X_op_symbol)->X_op)
10009 || reloc_type == BFD_RELOC_32_PCREL))
10013 reloc_type = BFD_RELOC_386_GOTPC;
10014 i.has_gotpc_tls_reloc = true;
10015 i.op[n].disps->X_add_number +=
10016 encoding_length (insn_start_frag, insn_start_off, p);
10018 else if (reloc_type == BFD_RELOC_64)
10019 reloc_type = BFD_RELOC_X86_64_GOTPC64;
10021 /* Don't do the adjustment for x86-64, as there
10022 the pcrel addressing is relative to the _next_
10023 insn, and that is taken care of in other code. */
10024 reloc_type = BFD_RELOC_X86_64_GOTPC32;
10026 else if (align_branch_power)
10028 switch (reloc_type)
10030 case BFD_RELOC_386_TLS_GD:
10031 case BFD_RELOC_386_TLS_LDM:
10032 case BFD_RELOC_386_TLS_IE:
10033 case BFD_RELOC_386_TLS_IE_32:
10034 case BFD_RELOC_386_TLS_GOTIE:
10035 case BFD_RELOC_386_TLS_GOTDESC:
10036 case BFD_RELOC_386_TLS_DESC_CALL:
10037 case BFD_RELOC_X86_64_TLSGD:
10038 case BFD_RELOC_X86_64_TLSLD:
10039 case BFD_RELOC_X86_64_GOTTPOFF:
10040 case BFD_RELOC_X86_64_GOTPC32_TLSDESC:
10041 case BFD_RELOC_X86_64_TLSDESC_CALL:
10042 i.has_gotpc_tls_reloc = true;
10047 fixP = fix_new_exp (frag_now, p - frag_now->fr_literal,
10048 size, i.op[n].disps, pcrel,
10051 if (flag_code == CODE_64BIT && size == 4 && pcrel
10052 && !i.prefix[ADDR_PREFIX])
10053 fixP->fx_signed = 1;
10055 /* Check for "call/jmp *mem", "mov mem, %reg",
10056 "test %reg, mem" and "binop mem, %reg" where binop
10057 is one of adc, add, and, cmp, or, sbb, sub, xor
10058 instructions without data prefix. Always generate
10059 R_386_GOT32X for "sym*GOT" operand in 32-bit mode. */
10060 if (i.prefix[DATA_PREFIX] == 0
10061 && (generate_relax_relocations
10064 && i.rm.regmem == 5))
10066 || (i.rm.mode == 0 && i.rm.regmem == 5))
10067 && i.tm.opcode_modifier.opcodespace == SPACE_BASE
10068 && ((i.operands == 1
10069 && i.tm.base_opcode == 0xff
10070 && (i.rm.reg == 2 || i.rm.reg == 4))
10071 || (i.operands == 2
10072 && (i.tm.base_opcode == 0x8b
10073 || i.tm.base_opcode == 0x85
10074 || (i.tm.base_opcode & ~0x38) == 0x03))))
10078 fixP->fx_tcbit = i.rex != 0;
10080 && (i.base_reg->reg_num == RegIP))
10081 fixP->fx_tcbit2 = 1;
10084 fixP->fx_tcbit2 = 1;
10092 output_imm (fragS *insn_start_frag, offsetT insn_start_off)
10097 for (n = 0; n < i.operands; n++)
10099 /* Skip SAE/RC Imm operand in EVEX. They are already handled. */
10100 if (i.rounding.type != rc_none && n == i.rounding.operand)
10103 if (operand_type_check (i.types[n], imm))
10105 int size = imm_size (n);
10107 if (now_seg == absolute_section)
10108 abs_section_offset += size;
10109 else if (i.op[n].imms->X_op == O_constant)
10113 val = offset_in_range (i.op[n].imms->X_add_number,
10115 p = frag_more (size);
10116 md_number_to_chars (p, val, size);
10120 /* Not absolute_section.
10121 Need a 32-bit fixup (don't support 8bit
10122 non-absolute imms). Try to support other
10124 enum bfd_reloc_code_real reloc_type;
10127 if (i.types[n].bitfield.imm32s
10128 && (i.suffix == QWORD_MNEM_SUFFIX
10129 || (!i.suffix && i.tm.opcode_modifier.no_lsuf)))
10134 p = frag_more (size);
10135 reloc_type = reloc (size, 0, sign, i.reloc[n]);
10137 /* This is tough to explain. We end up with this one if we
10138 * have operands that look like
10139 * "_GLOBAL_OFFSET_TABLE_+[.-.L284]". The goal here is to
10140 * obtain the absolute address of the GOT, and it is strongly
10141 * preferable from a performance point of view to avoid using
10142 * a runtime relocation for this. The actual sequence of
10143 * instructions often look something like:
10148 * addl $_GLOBAL_OFFSET_TABLE_+[.-.L66],%ebx
10150 * The call and pop essentially return the absolute address
10151 * of the label .L66 and store it in %ebx. The linker itself
10152 * will ultimately change the first operand of the addl so
10153 * that %ebx points to the GOT, but to keep things simple, the
10154 * .o file must have this operand set so that it generates not
10155 * the absolute address of .L66, but the absolute address of
10156 * itself. This allows the linker itself simply treat a GOTPC
10157 * relocation as asking for a pcrel offset to the GOT to be
10158 * added in, and the addend of the relocation is stored in the
10159 * operand field for the instruction itself.
10161 * Our job here is to fix the operand so that it would add
10162 * the correct offset so that %ebx would point to itself. The
10163 * thing that is tricky is that .-.L66 will point to the
10164 * beginning of the instruction, so we need to further modify
10165 * the operand so that it will point to itself. There are
10166 * other cases where you have something like:
10168 * .long $_GLOBAL_OFFSET_TABLE_+[.-.L66]
10170 * and here no correction would be required. Internally in
10171 * the assembler we treat operands of this form as not being
10172 * pcrel since the '.' is explicitly mentioned, and I wonder
10173 * whether it would simplify matters to do it this way. Who
10174 * knows. In earlier versions of the PIC patches, the
10175 * pcrel_adjust field was used to store the correction, but
10176 * since the expression is not pcrel, I felt it would be
10177 * confusing to do it this way. */
10179 if ((reloc_type == BFD_RELOC_32
10180 || reloc_type == BFD_RELOC_X86_64_32S
10181 || reloc_type == BFD_RELOC_64)
10183 && GOT_symbol == i.op[n].imms->X_add_symbol
10184 && (i.op[n].imms->X_op == O_symbol
10185 || (i.op[n].imms->X_op == O_add
10186 && ((symbol_get_value_expression
10187 (i.op[n].imms->X_op_symbol)->X_op)
10191 reloc_type = BFD_RELOC_386_GOTPC;
10192 else if (size == 4)
10193 reloc_type = BFD_RELOC_X86_64_GOTPC32;
10194 else if (size == 8)
10195 reloc_type = BFD_RELOC_X86_64_GOTPC64;
10196 i.has_gotpc_tls_reloc = true;
10197 i.op[n].imms->X_add_number +=
10198 encoding_length (insn_start_frag, insn_start_off, p);
10200 fix_new_exp (frag_now, p - frag_now->fr_literal, size,
10201 i.op[n].imms, 0, reloc_type);
10207 /* x86_cons_fix_new is called via the expression parsing code when a
10208 reloc is needed. We use this hook to get the correct .got reloc. */
10209 static int cons_sign = -1;
10212 x86_cons_fix_new (fragS *frag, unsigned int off, unsigned int len,
10213 expressionS *exp, bfd_reloc_code_real_type r)
10215 r = reloc (len, 0, cons_sign, r);
10218 if (exp->X_op == O_secrel)
10220 exp->X_op = O_symbol;
10221 r = BFD_RELOC_32_SECREL;
10225 fix_new_exp (frag, off, len, exp, 0, r);
10228 /* Export the ABI address size for use by TC_ADDRESS_BYTES for the
10229 purpose of the `.dc.a' internal pseudo-op. */
10232 x86_address_bytes (void)
10234 if ((stdoutput->arch_info->mach & bfd_mach_x64_32))
10236 return stdoutput->arch_info->bits_per_address / 8;
10239 #if (!(defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) || defined (OBJ_MACH_O)) \
10240 || defined (LEX_AT)) && !defined (TE_PE)
10241 # define lex_got(reloc, adjust, types) NULL
10243 /* Parse operands of the form
10244 <symbol>@GOTOFF+<nnn>
10245 and similar .plt or .got references.
10247 If we find one, set up the correct relocation in RELOC and copy the
10248 input string, minus the `@GOTOFF' into a malloc'd buffer for
10249 parsing by the calling routine. Return this buffer, and if ADJUST
10250 is non-null set it to the length of the string we removed from the
10251 input line. Otherwise return NULL. */
10253 lex_got (enum bfd_reloc_code_real *rel,
10255 i386_operand_type *types)
10257 /* Some of the relocations depend on the size of what field is to
10258 be relocated. But in our callers i386_immediate and i386_displacement
10259 we don't yet know the operand size (this will be set by insn
10260 matching). Hence we record the word32 relocation here,
10261 and adjust the reloc according to the real size in reloc(). */
10262 static const struct {
10265 const enum bfd_reloc_code_real rel[2];
10266 const i386_operand_type types64;
10267 bool need_GOT_symbol;
10270 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
10271 { STRING_COMMA_LEN ("SIZE"), { BFD_RELOC_SIZE32,
10272 BFD_RELOC_SIZE32 },
10273 OPERAND_TYPE_IMM32_64, false },
10275 { STRING_COMMA_LEN ("PLTOFF"), { _dummy_first_bfd_reloc_code_real,
10276 BFD_RELOC_X86_64_PLTOFF64 },
10277 OPERAND_TYPE_IMM64, true },
10278 { STRING_COMMA_LEN ("PLT"), { BFD_RELOC_386_PLT32,
10279 BFD_RELOC_X86_64_PLT32 },
10280 OPERAND_TYPE_IMM32_32S_DISP32, false },
10281 { STRING_COMMA_LEN ("GOTPLT"), { _dummy_first_bfd_reloc_code_real,
10282 BFD_RELOC_X86_64_GOTPLT64 },
10283 OPERAND_TYPE_IMM64_DISP64, true },
10284 { STRING_COMMA_LEN ("GOTOFF"), { BFD_RELOC_386_GOTOFF,
10285 BFD_RELOC_X86_64_GOTOFF64 },
10286 OPERAND_TYPE_IMM64_DISP64, true },
10287 { STRING_COMMA_LEN ("GOTPCREL"), { _dummy_first_bfd_reloc_code_real,
10288 BFD_RELOC_X86_64_GOTPCREL },
10289 OPERAND_TYPE_IMM32_32S_DISP32, true },
10290 { STRING_COMMA_LEN ("TLSGD"), { BFD_RELOC_386_TLS_GD,
10291 BFD_RELOC_X86_64_TLSGD },
10292 OPERAND_TYPE_IMM32_32S_DISP32, true },
10293 { STRING_COMMA_LEN ("TLSLDM"), { BFD_RELOC_386_TLS_LDM,
10294 _dummy_first_bfd_reloc_code_real },
10295 OPERAND_TYPE_NONE, true },
10296 { STRING_COMMA_LEN ("TLSLD"), { _dummy_first_bfd_reloc_code_real,
10297 BFD_RELOC_X86_64_TLSLD },
10298 OPERAND_TYPE_IMM32_32S_DISP32, true },
10299 { STRING_COMMA_LEN ("GOTTPOFF"), { BFD_RELOC_386_TLS_IE_32,
10300 BFD_RELOC_X86_64_GOTTPOFF },
10301 OPERAND_TYPE_IMM32_32S_DISP32, true },
10302 { STRING_COMMA_LEN ("TPOFF"), { BFD_RELOC_386_TLS_LE_32,
10303 BFD_RELOC_X86_64_TPOFF32 },
10304 OPERAND_TYPE_IMM32_32S_64_DISP32_64, true },
10305 { STRING_COMMA_LEN ("NTPOFF"), { BFD_RELOC_386_TLS_LE,
10306 _dummy_first_bfd_reloc_code_real },
10307 OPERAND_TYPE_NONE, true },
10308 { STRING_COMMA_LEN ("DTPOFF"), { BFD_RELOC_386_TLS_LDO_32,
10309 BFD_RELOC_X86_64_DTPOFF32 },
10310 OPERAND_TYPE_IMM32_32S_64_DISP32_64, true },
10311 { STRING_COMMA_LEN ("GOTNTPOFF"),{ BFD_RELOC_386_TLS_GOTIE,
10312 _dummy_first_bfd_reloc_code_real },
10313 OPERAND_TYPE_NONE, true },
10314 { STRING_COMMA_LEN ("INDNTPOFF"),{ BFD_RELOC_386_TLS_IE,
10315 _dummy_first_bfd_reloc_code_real },
10316 OPERAND_TYPE_NONE, true },
10317 { STRING_COMMA_LEN ("GOT"), { BFD_RELOC_386_GOT32,
10318 BFD_RELOC_X86_64_GOT32 },
10319 OPERAND_TYPE_IMM32_32S_64_DISP32, true },
10320 { STRING_COMMA_LEN ("TLSDESC"), { BFD_RELOC_386_TLS_GOTDESC,
10321 BFD_RELOC_X86_64_GOTPC32_TLSDESC },
10322 OPERAND_TYPE_IMM32_32S_DISP32, true },
10323 { STRING_COMMA_LEN ("TLSCALL"), { BFD_RELOC_386_TLS_DESC_CALL,
10324 BFD_RELOC_X86_64_TLSDESC_CALL },
10325 OPERAND_TYPE_IMM32_32S_DISP32, true },
10327 { STRING_COMMA_LEN ("SECREL32"), { BFD_RELOC_32_SECREL,
10328 BFD_RELOC_32_SECREL },
10329 OPERAND_TYPE_IMM32_32S_64_DISP32_64, false },
10335 #if defined (OBJ_MAYBE_ELF) && !defined (TE_PE)
10340 for (cp = input_line_pointer; *cp != '@'; cp++)
10341 if (is_end_of_line[(unsigned char) *cp] || *cp == ',')
10344 for (j = 0; j < ARRAY_SIZE (gotrel); j++)
10346 int len = gotrel[j].len;
10347 if (strncasecmp (cp + 1, gotrel[j].str, len) == 0)
10349 if (gotrel[j].rel[object_64bit] != 0)
10352 char *tmpbuf, *past_reloc;
10354 *rel = gotrel[j].rel[object_64bit];
10358 if (flag_code != CODE_64BIT)
10360 types->bitfield.imm32 = 1;
10361 types->bitfield.disp32 = 1;
10364 *types = gotrel[j].types64;
10367 if (gotrel[j].need_GOT_symbol && GOT_symbol == NULL)
10368 GOT_symbol = symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME);
10370 /* The length of the first part of our input line. */
10371 first = cp - input_line_pointer;
10373 /* The second part goes from after the reloc token until
10374 (and including) an end_of_line char or comma. */
10375 past_reloc = cp + 1 + len;
10377 while (!is_end_of_line[(unsigned char) *cp] && *cp != ',')
10379 second = cp + 1 - past_reloc;
10381 /* Allocate and copy string. The trailing NUL shouldn't
10382 be necessary, but be safe. */
10383 tmpbuf = XNEWVEC (char, first + second + 2);
10384 memcpy (tmpbuf, input_line_pointer, first);
10385 if (second != 0 && *past_reloc != ' ')
10386 /* Replace the relocation token with ' ', so that
10387 errors like foo@GOTOFF1 will be detected. */
10388 tmpbuf[first++] = ' ';
10390 /* Increment length by 1 if the relocation token is
10395 memcpy (tmpbuf + first, past_reloc, second);
10396 tmpbuf[first + second] = '\0';
10400 as_bad (_("@%s reloc is not supported with %d-bit output format"),
10401 gotrel[j].str, 1 << (5 + object_64bit));
10406 /* Might be a symbol version string. Don't as_bad here. */
10411 bfd_reloc_code_real_type
10412 x86_cons (expressionS *exp, int size)
10414 bfd_reloc_code_real_type got_reloc = NO_RELOC;
10416 #if ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) \
10417 && !defined (LEX_AT)) \
10419 intel_syntax = -intel_syntax;
10422 if (size == 4 || (object_64bit && size == 8))
10424 /* Handle @GOTOFF and the like in an expression. */
10426 char *gotfree_input_line;
10429 save = input_line_pointer;
10430 gotfree_input_line = lex_got (&got_reloc, &adjust, NULL);
10431 if (gotfree_input_line)
10432 input_line_pointer = gotfree_input_line;
10436 if (gotfree_input_line)
10438 /* expression () has merrily parsed up to the end of line,
10439 or a comma - in the wrong buffer. Transfer how far
10440 input_line_pointer has moved to the right buffer. */
10441 input_line_pointer = (save
10442 + (input_line_pointer - gotfree_input_line)
10444 free (gotfree_input_line);
10445 if (exp->X_op == O_constant
10446 || exp->X_op == O_absent
10447 || exp->X_op == O_illegal
10448 || exp->X_op == O_register
10449 || exp->X_op == O_big)
10451 char c = *input_line_pointer;
10452 *input_line_pointer = 0;
10453 as_bad (_("missing or invalid expression `%s'"), save);
10454 *input_line_pointer = c;
10456 else if ((got_reloc == BFD_RELOC_386_PLT32
10457 || got_reloc == BFD_RELOC_X86_64_PLT32)
10458 && exp->X_op != O_symbol)
10460 char c = *input_line_pointer;
10461 *input_line_pointer = 0;
10462 as_bad (_("invalid PLT expression `%s'"), save);
10463 *input_line_pointer = c;
10470 intel_syntax = -intel_syntax;
10473 i386_intel_simplify (exp);
10478 /* If not 64bit, massage value, to account for wraparound when !BFD64. */
10479 if (size == 4 && exp->X_op == O_constant && !object_64bit)
10480 exp->X_add_number = extend_to_32bit_address (exp->X_add_number);
10486 signed_cons (int size)
10496 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
10503 if (exp.X_op == O_symbol)
10504 exp.X_op = O_secrel;
10506 emit_expr (&exp, 4);
10508 while (*input_line_pointer++ == ',');
10510 input_line_pointer--;
10511 demand_empty_rest_of_line ();
10515 /* Handle Vector operations. */
10518 check_VecOperations (char *op_string)
10520 const reg_entry *mask;
10527 if (*op_string == '{')
10531 /* Check broadcasts. */
10532 if (startswith (op_string, "1to"))
10534 unsigned int bcst_type;
10536 if (i.broadcast.type)
10537 goto duplicated_vec_op;
10540 if (*op_string == '8')
10542 else if (*op_string == '4')
10544 else if (*op_string == '2')
10546 else if (*op_string == '1'
10547 && *(op_string+1) == '6')
10554 as_bad (_("Unsupported broadcast: `%s'"), saved);
10559 i.broadcast.type = bcst_type;
10560 i.broadcast.operand = this_operand;
10562 /* Check masking operation. */
10563 else if ((mask = parse_register (op_string, &end_op)) != NULL)
10565 if (mask == &bad_reg)
10568 /* k0 can't be used for write mask. */
10569 if (mask->reg_type.bitfield.class != RegMask || !mask->reg_num)
10571 as_bad (_("`%s%s' can't be used for write mask"),
10572 register_prefix, mask->reg_name);
10579 i.mask.operand = this_operand;
10581 else if (i.mask.reg->reg_num)
10582 goto duplicated_vec_op;
10587 /* Only "{z}" is allowed here. No need to check
10588 zeroing mask explicitly. */
10589 if (i.mask.operand != (unsigned int) this_operand)
10591 as_bad (_("invalid write mask `%s'"), saved);
10596 op_string = end_op;
10598 /* Check zeroing-flag for masking operation. */
10599 else if (*op_string == 'z')
10603 i.mask.reg = reg_k0;
10604 i.mask.zeroing = 1;
10605 i.mask.operand = this_operand;
10609 if (i.mask.zeroing)
10612 as_bad (_("duplicated `%s'"), saved);
10616 i.mask.zeroing = 1;
10618 /* Only "{%k}" is allowed here. No need to check mask
10619 register explicitly. */
10620 if (i.mask.operand != (unsigned int) this_operand)
10622 as_bad (_("invalid zeroing-masking `%s'"),
10631 goto unknown_vec_op;
10633 if (*op_string != '}')
10635 as_bad (_("missing `}' in `%s'"), saved);
10640 /* Strip whitespace since the addition of pseudo prefixes
10641 changed how the scrubber treats '{'. */
10642 if (is_space_char (*op_string))
10648 /* We don't know this one. */
10649 as_bad (_("unknown vector operation: `%s'"), saved);
10653 if (i.mask.reg && i.mask.zeroing && !i.mask.reg->reg_num)
10655 as_bad (_("zeroing-masking only allowed with write mask"));
10663 i386_immediate (char *imm_start)
10665 char *save_input_line_pointer;
10666 char *gotfree_input_line;
10669 i386_operand_type types;
10671 operand_type_set (&types, ~0);
10673 if (i.imm_operands == MAX_IMMEDIATE_OPERANDS)
10675 as_bad (_("at most %d immediate operands are allowed"),
10676 MAX_IMMEDIATE_OPERANDS);
10680 exp = &im_expressions[i.imm_operands++];
10681 i.op[this_operand].imms = exp;
10683 if (is_space_char (*imm_start))
10686 save_input_line_pointer = input_line_pointer;
10687 input_line_pointer = imm_start;
10689 gotfree_input_line = lex_got (&i.reloc[this_operand], NULL, &types);
10690 if (gotfree_input_line)
10691 input_line_pointer = gotfree_input_line;
10693 exp_seg = expression (exp);
10695 SKIP_WHITESPACE ();
10696 if (*input_line_pointer)
10697 as_bad (_("junk `%s' after expression"), input_line_pointer);
10699 input_line_pointer = save_input_line_pointer;
10700 if (gotfree_input_line)
10702 free (gotfree_input_line);
10704 if (exp->X_op == O_constant)
10705 exp->X_op = O_illegal;
10708 if (exp_seg == reg_section)
10710 as_bad (_("illegal immediate register operand %s"), imm_start);
10714 return i386_finalize_immediate (exp_seg, exp, types, imm_start);
10718 i386_finalize_immediate (segT exp_seg ATTRIBUTE_UNUSED, expressionS *exp,
10719 i386_operand_type types, const char *imm_start)
10721 if (exp->X_op == O_absent || exp->X_op == O_illegal || exp->X_op == O_big)
10724 as_bad (_("missing or invalid immediate expression `%s'"),
10728 else if (exp->X_op == O_constant)
10730 /* Size it properly later. */
10731 i.types[this_operand].bitfield.imm64 = 1;
10733 /* If not 64bit, sign/zero extend val, to account for wraparound
10735 if (flag_code != CODE_64BIT)
10736 exp->X_add_number = extend_to_32bit_address (exp->X_add_number);
10738 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
10739 else if (OUTPUT_FLAVOR == bfd_target_aout_flavour
10740 && exp_seg != absolute_section
10741 && exp_seg != text_section
10742 && exp_seg != data_section
10743 && exp_seg != bss_section
10744 && exp_seg != undefined_section
10745 && !bfd_is_com_section (exp_seg))
10747 as_bad (_("unimplemented segment %s in operand"), exp_seg->name);
10753 /* This is an address. The size of the address will be
10754 determined later, depending on destination register,
10755 suffix, or the default for the section. */
10756 i.types[this_operand].bitfield.imm8 = 1;
10757 i.types[this_operand].bitfield.imm16 = 1;
10758 i.types[this_operand].bitfield.imm32 = 1;
10759 i.types[this_operand].bitfield.imm32s = 1;
10760 i.types[this_operand].bitfield.imm64 = 1;
10761 i.types[this_operand] = operand_type_and (i.types[this_operand],
10769 i386_scale (char *scale)
10772 char *save = input_line_pointer;
10774 input_line_pointer = scale;
10775 val = get_absolute_expression ();
10780 i.log2_scale_factor = 0;
10783 i.log2_scale_factor = 1;
10786 i.log2_scale_factor = 2;
10789 i.log2_scale_factor = 3;
10793 char sep = *input_line_pointer;
10795 *input_line_pointer = '\0';
10796 as_bad (_("expecting scale factor of 1, 2, 4, or 8: got `%s'"),
10798 *input_line_pointer = sep;
10799 input_line_pointer = save;
10803 if (i.log2_scale_factor != 0 && i.index_reg == 0)
10805 as_warn (_("scale factor of %d without an index register"),
10806 1 << i.log2_scale_factor);
10807 i.log2_scale_factor = 0;
10809 scale = input_line_pointer;
10810 input_line_pointer = save;
10815 i386_displacement (char *disp_start, char *disp_end)
10819 char *save_input_line_pointer;
10820 char *gotfree_input_line;
10822 i386_operand_type bigdisp, types = anydisp;
10825 if (i.disp_operands == MAX_MEMORY_OPERANDS)
10827 as_bad (_("at most %d displacement operands are allowed"),
10828 MAX_MEMORY_OPERANDS);
10832 operand_type_set (&bigdisp, 0);
10834 || i.types[this_operand].bitfield.baseindex
10835 || (current_templates->start->opcode_modifier.jump != JUMP
10836 && current_templates->start->opcode_modifier.jump != JUMP_DWORD))
10838 i386_addressing_mode ();
10839 override = (i.prefix[ADDR_PREFIX] != 0);
10840 if (flag_code == CODE_64BIT)
10844 bigdisp.bitfield.disp32s = 1;
10845 bigdisp.bitfield.disp64 = 1;
10848 bigdisp.bitfield.disp32 = 1;
10850 else if ((flag_code == CODE_16BIT) ^ override)
10851 bigdisp.bitfield.disp16 = 1;
10853 bigdisp.bitfield.disp32 = 1;
10857 /* For PC-relative branches, the width of the displacement may be
10858 dependent upon data size, but is never dependent upon address size.
10859 Also make sure to not unintentionally match against a non-PC-relative
10860 branch template. */
10861 static templates aux_templates;
10862 const insn_template *t = current_templates->start;
10863 bool has_intel64 = false;
10865 aux_templates.start = t;
10866 while (++t < current_templates->end)
10868 if (t->opcode_modifier.jump
10869 != current_templates->start->opcode_modifier.jump)
10871 if ((t->opcode_modifier.isa64 >= INTEL64))
10872 has_intel64 = true;
10874 if (t < current_templates->end)
10876 aux_templates.end = t;
10877 current_templates = &aux_templates;
10880 override = (i.prefix[DATA_PREFIX] != 0);
10881 if (flag_code == CODE_64BIT)
10883 if ((override || i.suffix == WORD_MNEM_SUFFIX)
10884 && (!intel64 || !has_intel64))
10885 bigdisp.bitfield.disp16 = 1;
10887 bigdisp.bitfield.disp32s = 1;
10892 override = (i.suffix == (flag_code != CODE_16BIT
10894 : LONG_MNEM_SUFFIX));
10895 bigdisp.bitfield.disp32 = 1;
10896 if ((flag_code == CODE_16BIT) ^ override)
10898 bigdisp.bitfield.disp32 = 0;
10899 bigdisp.bitfield.disp16 = 1;
10903 i.types[this_operand] = operand_type_or (i.types[this_operand],
10906 exp = &disp_expressions[i.disp_operands];
10907 i.op[this_operand].disps = exp;
10909 save_input_line_pointer = input_line_pointer;
10910 input_line_pointer = disp_start;
10911 END_STRING_AND_SAVE (disp_end);
10913 #ifndef GCC_ASM_O_HACK
10914 #define GCC_ASM_O_HACK 0
10917 END_STRING_AND_SAVE (disp_end + 1);
10918 if (i.types[this_operand].bitfield.baseIndex
10919 && displacement_string_end[-1] == '+')
10921 /* This hack is to avoid a warning when using the "o"
10922 constraint within gcc asm statements.
10925 #define _set_tssldt_desc(n,addr,limit,type) \
10926 __asm__ __volatile__ ( \
10927 "movw %w2,%0\n\t" \
10928 "movw %w1,2+%0\n\t" \
10929 "rorl $16,%1\n\t" \
10930 "movb %b1,4+%0\n\t" \
10931 "movb %4,5+%0\n\t" \
10932 "movb $0,6+%0\n\t" \
10933 "movb %h1,7+%0\n\t" \
10935 : "=o"(*(n)) : "q" (addr), "ri"(limit), "i"(type))
10937 This works great except that the output assembler ends
10938 up looking a bit weird if it turns out that there is
10939 no offset. You end up producing code that looks like:
10952 So here we provide the missing zero. */
10954 *displacement_string_end = '0';
10957 gotfree_input_line = lex_got (&i.reloc[this_operand], NULL, &types);
10958 if (gotfree_input_line)
10959 input_line_pointer = gotfree_input_line;
10961 exp_seg = expression (exp);
10963 SKIP_WHITESPACE ();
10964 if (*input_line_pointer)
10965 as_bad (_("junk `%s' after expression"), input_line_pointer);
10967 RESTORE_END_STRING (disp_end + 1);
10969 input_line_pointer = save_input_line_pointer;
10970 if (gotfree_input_line)
10972 free (gotfree_input_line);
10974 if (exp->X_op == O_constant || exp->X_op == O_register)
10975 exp->X_op = O_illegal;
10978 ret = i386_finalize_displacement (exp_seg, exp, types, disp_start);
10980 RESTORE_END_STRING (disp_end);
10986 i386_finalize_displacement (segT exp_seg ATTRIBUTE_UNUSED, expressionS *exp,
10987 i386_operand_type types, const char *disp_start)
10989 i386_operand_type bigdisp;
10992 /* We do this to make sure that the section symbol is in
10993 the symbol table. We will ultimately change the relocation
10994 to be relative to the beginning of the section. */
10995 if (i.reloc[this_operand] == BFD_RELOC_386_GOTOFF
10996 || i.reloc[this_operand] == BFD_RELOC_X86_64_GOTPCREL
10997 || i.reloc[this_operand] == BFD_RELOC_X86_64_GOTOFF64)
10999 if (exp->X_op != O_symbol)
11002 if (S_IS_LOCAL (exp->X_add_symbol)
11003 && S_GET_SEGMENT (exp->X_add_symbol) != undefined_section
11004 && S_GET_SEGMENT (exp->X_add_symbol) != expr_section)
11005 section_symbol (S_GET_SEGMENT (exp->X_add_symbol));
11006 exp->X_op = O_subtract;
11007 exp->X_op_symbol = GOT_symbol;
11008 if (i.reloc[this_operand] == BFD_RELOC_X86_64_GOTPCREL)
11009 i.reloc[this_operand] = BFD_RELOC_32_PCREL;
11010 else if (i.reloc[this_operand] == BFD_RELOC_X86_64_GOTOFF64)
11011 i.reloc[this_operand] = BFD_RELOC_64;
11013 i.reloc[this_operand] = BFD_RELOC_32;
11016 else if (exp->X_op == O_absent
11017 || exp->X_op == O_illegal
11018 || exp->X_op == O_big)
11021 as_bad (_("missing or invalid displacement expression `%s'"),
11026 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
11027 else if (exp->X_op != O_constant
11028 && OUTPUT_FLAVOR == bfd_target_aout_flavour
11029 && exp_seg != absolute_section
11030 && exp_seg != text_section
11031 && exp_seg != data_section
11032 && exp_seg != bss_section
11033 && exp_seg != undefined_section
11034 && !bfd_is_com_section (exp_seg))
11036 as_bad (_("unimplemented segment %s in operand"), exp_seg->name);
11041 if (current_templates->start->opcode_modifier.jump == JUMP_BYTE
11042 /* Constants get taken care of by optimize_disp(). */
11043 && exp->X_op != O_constant)
11044 i.types[this_operand].bitfield.disp8 = 1;
11046 /* Check if this is a displacement only operand. */
11047 bigdisp = i.types[this_operand];
11048 bigdisp.bitfield.disp8 = 0;
11049 bigdisp.bitfield.disp16 = 0;
11050 bigdisp.bitfield.disp32 = 0;
11051 bigdisp.bitfield.disp32s = 0;
11052 bigdisp.bitfield.disp64 = 0;
11053 if (operand_type_all_zero (&bigdisp))
11054 i.types[this_operand] = operand_type_and (i.types[this_operand],
11060 /* Return the active addressing mode, taking address override and
11061 registers forming the address into consideration. Update the
11062 address override prefix if necessary. */
11064 static enum flag_code
11065 i386_addressing_mode (void)
11067 enum flag_code addr_mode;
11069 if (i.prefix[ADDR_PREFIX])
11070 addr_mode = flag_code == CODE_32BIT ? CODE_16BIT : CODE_32BIT;
11071 else if (flag_code == CODE_16BIT
11072 && current_templates->start->cpu_flags.bitfield.cpumpx
11073 /* Avoid replacing the "16-bit addressing not allowed" diagnostic
11074 from md_assemble() by "is not a valid base/index expression"
11075 when there is a base and/or index. */
11076 && !i.types[this_operand].bitfield.baseindex)
11078 /* MPX insn memory operands with neither base nor index must be forced
11079 to use 32-bit addressing in 16-bit mode. */
11080 addr_mode = CODE_32BIT;
11081 i.prefix[ADDR_PREFIX] = ADDR_PREFIX_OPCODE;
11083 gas_assert (!i.types[this_operand].bitfield.disp16);
11084 gas_assert (!i.types[this_operand].bitfield.disp32);
11088 addr_mode = flag_code;
11090 #if INFER_ADDR_PREFIX
11091 if (i.mem_operands == 0)
11093 /* Infer address prefix from the first memory operand. */
11094 const reg_entry *addr_reg = i.base_reg;
11096 if (addr_reg == NULL)
11097 addr_reg = i.index_reg;
11101 if (addr_reg->reg_type.bitfield.dword)
11102 addr_mode = CODE_32BIT;
11103 else if (flag_code != CODE_64BIT
11104 && addr_reg->reg_type.bitfield.word)
11105 addr_mode = CODE_16BIT;
11107 if (addr_mode != flag_code)
11109 i.prefix[ADDR_PREFIX] = ADDR_PREFIX_OPCODE;
11111 /* Change the size of any displacement too. At most one
11112 of Disp16 or Disp32 is set.
11113 FIXME. There doesn't seem to be any real need for
11114 separate Disp16 and Disp32 flags. The same goes for
11115 Imm16 and Imm32. Removing them would probably clean
11116 up the code quite a lot. */
11117 if (flag_code != CODE_64BIT
11118 && (i.types[this_operand].bitfield.disp16
11119 || i.types[this_operand].bitfield.disp32))
11120 i.types[this_operand]
11121 = operand_type_xor (i.types[this_operand], disp16_32);
11131 /* Make sure the memory operand we've been dealt is valid.
11132 Return 1 on success, 0 on a failure. */
11135 i386_index_check (const char *operand_string)
11137 const char *kind = "base/index";
11138 enum flag_code addr_mode = i386_addressing_mode ();
11139 const insn_template *t = current_templates->start;
11141 if (t->opcode_modifier.isstring
11142 && !t->cpu_flags.bitfield.cpupadlock
11143 && (current_templates->end[-1].opcode_modifier.isstring
11144 || i.mem_operands))
11146 /* Memory operands of string insns are special in that they only allow
11147 a single register (rDI, rSI, or rBX) as their memory address. */
11148 const reg_entry *expected_reg;
11149 static const char *di_si[][2] =
11155 static const char *bx[] = { "ebx", "bx", "rbx" };
11157 kind = "string address";
11159 if (t->opcode_modifier.prefixok == PrefixRep)
11161 int es_op = current_templates->end[-1].opcode_modifier.isstring
11162 - IS_STRING_ES_OP0;
11165 if (!current_templates->end[-1].operand_types[0].bitfield.baseindex
11166 || ((!i.mem_operands != !intel_syntax)
11167 && current_templates->end[-1].operand_types[1]
11168 .bitfield.baseindex))
11171 = (const reg_entry *) str_hash_find (reg_hash,
11172 di_si[addr_mode][op == es_op]);
11176 = (const reg_entry *)str_hash_find (reg_hash, bx[addr_mode]);
11178 if (i.base_reg != expected_reg
11180 || operand_type_check (i.types[this_operand], disp))
11182 /* The second memory operand must have the same size as
11186 && !((addr_mode == CODE_64BIT
11187 && i.base_reg->reg_type.bitfield.qword)
11188 || (addr_mode == CODE_32BIT
11189 ? i.base_reg->reg_type.bitfield.dword
11190 : i.base_reg->reg_type.bitfield.word)))
11193 as_warn (_("`%s' is not valid here (expected `%c%s%s%c')"),
11195 intel_syntax ? '[' : '(',
11197 expected_reg->reg_name,
11198 intel_syntax ? ']' : ')');
11205 as_bad (_("`%s' is not a valid %s expression"),
11206 operand_string, kind);
11211 if (addr_mode != CODE_16BIT)
11213 /* 32-bit/64-bit checks. */
11214 if (i.disp_encoding == disp_encoding_16bit)
11217 as_bad (_("invalid `%s' prefix"),
11218 addr_mode == CODE_16BIT ? "{disp32}" : "{disp16}");
11223 && ((addr_mode == CODE_64BIT
11224 ? !i.base_reg->reg_type.bitfield.qword
11225 : !i.base_reg->reg_type.bitfield.dword)
11226 || (i.index_reg && i.base_reg->reg_num == RegIP)
11227 || i.base_reg->reg_num == RegIZ))
11229 && !i.index_reg->reg_type.bitfield.xmmword
11230 && !i.index_reg->reg_type.bitfield.ymmword
11231 && !i.index_reg->reg_type.bitfield.zmmword
11232 && ((addr_mode == CODE_64BIT
11233 ? !i.index_reg->reg_type.bitfield.qword
11234 : !i.index_reg->reg_type.bitfield.dword)
11235 || !i.index_reg->reg_type.bitfield.baseindex)))
11238 /* bndmk, bndldx, bndstx and mandatory non-vector SIB have special restrictions. */
11239 if ((t->opcode_modifier.opcodeprefix == PREFIX_0XF3
11240 && t->opcode_modifier.opcodespace == SPACE_0F
11241 && t->base_opcode == 0x1b)
11242 || (t->opcode_modifier.opcodeprefix == PREFIX_NONE
11243 && t->opcode_modifier.opcodespace == SPACE_0F
11244 && (t->base_opcode & ~1) == 0x1a)
11245 || t->opcode_modifier.sib == SIBMEM)
11247 /* They cannot use RIP-relative addressing. */
11248 if (i.base_reg && i.base_reg->reg_num == RegIP)
11250 as_bad (_("`%s' cannot be used here"), operand_string);
11254 /* bndldx and bndstx ignore their scale factor. */
11255 if (t->opcode_modifier.opcodeprefix == PREFIX_NONE
11256 && t->opcode_modifier.opcodespace == SPACE_0F
11257 && (t->base_opcode & ~1) == 0x1a
11258 && i.log2_scale_factor)
11259 as_warn (_("register scaling is being ignored here"));
11264 /* 16-bit checks. */
11265 if (i.disp_encoding == disp_encoding_32bit)
11269 && (!i.base_reg->reg_type.bitfield.word
11270 || !i.base_reg->reg_type.bitfield.baseindex))
11272 && (!i.index_reg->reg_type.bitfield.word
11273 || !i.index_reg->reg_type.bitfield.baseindex
11275 && i.base_reg->reg_num < 6
11276 && i.index_reg->reg_num >= 6
11277 && i.log2_scale_factor == 0))))
11284 /* Handle vector immediates. */
11287 RC_SAE_immediate (const char *imm_start)
11289 unsigned int match_found, j;
11290 const char *pstr = imm_start;
11298 for (j = 0; j < ARRAY_SIZE (RC_NamesTable); j++)
11300 if (!strncmp (pstr, RC_NamesTable[j].name, RC_NamesTable[j].len))
11302 if (i.rounding.type != rc_none)
11304 as_bad (_("duplicated `%s'"), imm_start);
11308 i.rounding.type = RC_NamesTable[j].type;
11309 i.rounding.operand = this_operand;
11311 pstr += RC_NamesTable[j].len;
11319 if (*pstr++ != '}')
11321 as_bad (_("Missing '}': '%s'"), imm_start);
11324 /* RC/SAE immediate string should contain nothing more. */;
11327 as_bad (_("Junk after '}': '%s'"), imm_start);
11331 exp = &im_expressions[i.imm_operands++];
11332 i.op[this_operand].imms = exp;
11334 exp->X_op = O_constant;
11335 exp->X_add_number = 0;
11336 exp->X_add_symbol = (symbolS *) 0;
11337 exp->X_op_symbol = (symbolS *) 0;
11339 i.types[this_operand].bitfield.imm8 = 1;
11343 /* Only string instructions can have a second memory operand, so
11344 reduce current_templates to just those if it contains any. */
11346 maybe_adjust_templates (void)
11348 const insn_template *t;
11350 gas_assert (i.mem_operands == 1);
11352 for (t = current_templates->start; t < current_templates->end; ++t)
11353 if (t->opcode_modifier.isstring)
11356 if (t < current_templates->end)
11358 static templates aux_templates;
11361 aux_templates.start = t;
11362 for (; t < current_templates->end; ++t)
11363 if (!t->opcode_modifier.isstring)
11365 aux_templates.end = t;
11367 /* Determine whether to re-check the first memory operand. */
11368 recheck = (aux_templates.start != current_templates->start
11369 || t != current_templates->end);
11371 current_templates = &aux_templates;
11375 i.mem_operands = 0;
11376 if (i.memop1_string != NULL
11377 && i386_index_check (i.memop1_string) == 0)
11379 i.mem_operands = 1;
11386 static INLINE bool starts_memory_operand (char c)
11389 || is_identifier_char (c)
11390 || strchr ("([\"+-!~", c);
11393 /* Parse OPERAND_STRING into the i386_insn structure I. Returns zero
11397 i386_att_operand (char *operand_string)
11399 const reg_entry *r;
11401 char *op_string = operand_string;
11403 if (is_space_char (*op_string))
11406 /* We check for an absolute prefix (differentiating,
11407 for example, 'jmp pc_relative_label' from 'jmp *absolute_label'. */
11408 if (*op_string == ABSOLUTE_PREFIX)
11411 if (is_space_char (*op_string))
11413 i.jumpabsolute = true;
11416 /* Check if operand is a register. */
11417 if ((r = parse_register (op_string, &end_op)) != NULL)
11419 i386_operand_type temp;
11424 /* Check for a segment override by searching for ':' after a
11425 segment register. */
11426 op_string = end_op;
11427 if (is_space_char (*op_string))
11429 if (*op_string == ':' && r->reg_type.bitfield.class == SReg)
11431 i.seg[i.mem_operands] = r;
11433 /* Skip the ':' and whitespace. */
11435 if (is_space_char (*op_string))
11438 /* Handle case of %es:*foo. */
11439 if (!i.jumpabsolute && *op_string == ABSOLUTE_PREFIX)
11442 if (is_space_char (*op_string))
11444 i.jumpabsolute = true;
11447 if (!starts_memory_operand (*op_string))
11449 as_bad (_("bad memory operand `%s'"), op_string);
11452 goto do_memory_reference;
11455 /* Handle vector operations. */
11456 if (*op_string == '{')
11458 op_string = check_VecOperations (op_string);
11459 if (op_string == NULL)
11465 as_bad (_("junk `%s' after register"), op_string);
11468 temp = r->reg_type;
11469 temp.bitfield.baseindex = 0;
11470 i.types[this_operand] = operand_type_or (i.types[this_operand],
11472 i.types[this_operand].bitfield.unspecified = 0;
11473 i.op[this_operand].regs = r;
11476 else if (*op_string == REGISTER_PREFIX)
11478 as_bad (_("bad register name `%s'"), op_string);
11481 else if (*op_string == IMMEDIATE_PREFIX)
11484 if (i.jumpabsolute)
11486 as_bad (_("immediate operand illegal with absolute jump"));
11489 if (!i386_immediate (op_string))
11492 else if (RC_SAE_immediate (operand_string))
11494 /* If it is a RC or SAE immediate, do nothing. */
11497 else if (starts_memory_operand (*op_string))
11499 /* This is a memory reference of some sort. */
11502 /* Start and end of displacement string expression (if found). */
11503 char *displacement_string_start;
11504 char *displacement_string_end;
11506 do_memory_reference:
11507 if (i.mem_operands == 1 && !maybe_adjust_templates ())
11509 if ((i.mem_operands == 1
11510 && !current_templates->start->opcode_modifier.isstring)
11511 || i.mem_operands == 2)
11513 as_bad (_("too many memory references for `%s'"),
11514 current_templates->start->name);
11518 /* Check for base index form. We detect the base index form by
11519 looking for an ')' at the end of the operand, searching
11520 for the '(' matching it, and finding a REGISTER_PREFIX or ','
11522 base_string = op_string + strlen (op_string);
11524 /* Handle vector operations. */
11526 if (is_space_char (*base_string))
11529 if (*base_string == '}')
11531 char *vop_start = NULL;
11533 while (base_string-- > op_string)
11535 if (*base_string == '"')
11537 if (*base_string != '{')
11540 vop_start = base_string;
11543 if (is_space_char (*base_string))
11546 if (*base_string != '}')
11554 as_bad (_("unbalanced figure braces"));
11558 if (check_VecOperations (vop_start) == NULL)
11562 /* If we only have a displacement, set-up for it to be parsed later. */
11563 displacement_string_start = op_string;
11564 displacement_string_end = base_string + 1;
11566 if (*base_string == ')')
11570 /* We've already checked that the number of left & right ()'s are
11571 equal, so this loop will not be infinite. */
11576 while (*base_string != '(' && *base_string != ')'
11577 && *base_string != '"');
11579 temp_string = base_string;
11581 /* Skip past '(' and whitespace. */
11582 if (*base_string == '(')
11584 if (is_space_char (*base_string))
11587 if (*base_string == ','
11588 || ((i.base_reg = parse_register (base_string, &end_op))
11591 displacement_string_end = temp_string;
11593 i.types[this_operand].bitfield.baseindex = 1;
11597 if (i.base_reg == &bad_reg)
11599 base_string = end_op;
11600 if (is_space_char (*base_string))
11604 /* There may be an index reg or scale factor here. */
11605 if (*base_string == ',')
11608 if (is_space_char (*base_string))
11611 if ((i.index_reg = parse_register (base_string, &end_op))
11614 if (i.index_reg == &bad_reg)
11616 base_string = end_op;
11617 if (is_space_char (*base_string))
11619 if (*base_string == ',')
11622 if (is_space_char (*base_string))
11625 else if (*base_string != ')')
11627 as_bad (_("expecting `,' or `)' "
11628 "after index register in `%s'"),
11633 else if (*base_string == REGISTER_PREFIX)
11635 end_op = strchr (base_string, ',');
11638 as_bad (_("bad register name `%s'"), base_string);
11642 /* Check for scale factor. */
11643 if (*base_string != ')')
11645 char *end_scale = i386_scale (base_string);
11650 base_string = end_scale;
11651 if (is_space_char (*base_string))
11653 if (*base_string != ')')
11655 as_bad (_("expecting `)' "
11656 "after scale factor in `%s'"),
11661 else if (!i.index_reg)
11663 as_bad (_("expecting index register or scale factor "
11664 "after `,'; got '%c'"),
11669 else if (*base_string != ')')
11671 as_bad (_("expecting `,' or `)' "
11672 "after base register in `%s'"),
11677 else if (*base_string == REGISTER_PREFIX)
11679 end_op = strchr (base_string, ',');
11682 as_bad (_("bad register name `%s'"), base_string);
11687 /* If there's an expression beginning the operand, parse it,
11688 assuming displacement_string_start and
11689 displacement_string_end are meaningful. */
11690 if (displacement_string_start != displacement_string_end)
11692 if (!i386_displacement (displacement_string_start,
11693 displacement_string_end))
11697 /* Special case for (%dx) while doing input/output op. */
11699 && i.base_reg->reg_type.bitfield.instance == RegD
11700 && i.base_reg->reg_type.bitfield.word
11701 && i.index_reg == 0
11702 && i.log2_scale_factor == 0
11703 && i.seg[i.mem_operands] == 0
11704 && !operand_type_check (i.types[this_operand], disp))
11706 i.types[this_operand] = i.base_reg->reg_type;
11710 if (i386_index_check (operand_string) == 0)
11712 i.flags[this_operand] |= Operand_Mem;
11713 if (i.mem_operands == 0)
11714 i.memop1_string = xstrdup (operand_string);
11719 /* It's not a memory operand; argh! */
11720 as_bad (_("invalid char %s beginning operand %d `%s'"),
11721 output_invalid (*op_string),
11726 return 1; /* Normal return. */
11729 /* Calculate the maximum variable size (i.e., excluding fr_fix)
11730 that an rs_machine_dependent frag may reach. */
11733 i386_frag_max_var (fragS *frag)
11735 /* The only relaxable frags are for jumps.
11736 Unconditional jumps can grow by 4 bytes and others by 5 bytes. */
11737 gas_assert (frag->fr_type == rs_machine_dependent);
11738 return TYPE_FROM_RELAX_STATE (frag->fr_subtype) == UNCOND_JUMP ? 4 : 5;
11741 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
11743 elf_symbol_resolved_in_segment_p (symbolS *fr_symbol, offsetT fr_var)
11745 /* STT_GNU_IFUNC symbol must go through PLT. */
11746 if ((symbol_get_bfdsym (fr_symbol)->flags
11747 & BSF_GNU_INDIRECT_FUNCTION) != 0)
11750 if (!S_IS_EXTERNAL (fr_symbol))
11751 /* Symbol may be weak or local. */
11752 return !S_IS_WEAK (fr_symbol);
11754 /* Global symbols with non-default visibility can't be preempted. */
11755 if (ELF_ST_VISIBILITY (S_GET_OTHER (fr_symbol)) != STV_DEFAULT)
11758 if (fr_var != NO_RELOC)
11759 switch ((enum bfd_reloc_code_real) fr_var)
11761 case BFD_RELOC_386_PLT32:
11762 case BFD_RELOC_X86_64_PLT32:
11763 /* Symbol with PLT relocation may be preempted. */
11769 /* Global symbols with default visibility in a shared library may be
11770 preempted by another definition. */
11775 /* Table 3-2. Macro-Fusible Instructions in Haswell Microarchitecture
11776 Note also work for Skylake and Cascadelake.
11777 ---------------------------------------------------------------------
11778 | JCC | ADD/SUB/CMP | INC/DEC | TEST/AND |
11779 | ------ | ----------- | ------- | -------- |
11781 | Jno | N | N | Y |
11782 | Jc/Jb | Y | N | Y |
11783 | Jae/Jnb | Y | N | Y |
11784 | Je/Jz | Y | Y | Y |
11785 | Jne/Jnz | Y | Y | Y |
11786 | Jna/Jbe | Y | N | Y |
11787 | Ja/Jnbe | Y | N | Y |
11789 | Jns | N | N | Y |
11790 | Jp/Jpe | N | N | Y |
11791 | Jnp/Jpo | N | N | Y |
11792 | Jl/Jnge | Y | Y | Y |
11793 | Jge/Jnl | Y | Y | Y |
11794 | Jle/Jng | Y | Y | Y |
11795 | Jg/Jnle | Y | Y | Y |
11796 --------------------------------------------------------------------- */
11798 i386_macro_fusible_p (enum mf_cmp_kind mf_cmp, enum mf_jcc_kind mf_jcc)
11800 if (mf_cmp == mf_cmp_alu_cmp)
11801 return ((mf_jcc >= mf_jcc_jc && mf_jcc <= mf_jcc_jna)
11802 || mf_jcc == mf_jcc_jl || mf_jcc == mf_jcc_jle);
11803 if (mf_cmp == mf_cmp_incdec)
11804 return (mf_jcc == mf_jcc_je || mf_jcc == mf_jcc_jl
11805 || mf_jcc == mf_jcc_jle);
11806 if (mf_cmp == mf_cmp_test_and)
11811 /* Return the next non-empty frag. */
11814 i386_next_non_empty_frag (fragS *fragP)
11816 /* There may be a frag with a ".fill 0" when there is no room in
11817 the current frag for frag_grow in output_insn. */
11818 for (fragP = fragP->fr_next;
11820 && fragP->fr_type == rs_fill
11821 && fragP->fr_fix == 0);
11822 fragP = fragP->fr_next)
11827 /* Return the next jcc frag after BRANCH_PADDING. */
11830 i386_next_fusible_jcc_frag (fragS *maybe_cmp_fragP, fragS *pad_fragP)
11832 fragS *branch_fragP;
11836 if (pad_fragP->fr_type == rs_machine_dependent
11837 && (TYPE_FROM_RELAX_STATE (pad_fragP->fr_subtype)
11838 == BRANCH_PADDING))
11840 branch_fragP = i386_next_non_empty_frag (pad_fragP);
11841 if (branch_fragP->fr_type != rs_machine_dependent)
11843 if (TYPE_FROM_RELAX_STATE (branch_fragP->fr_subtype) == COND_JUMP
11844 && i386_macro_fusible_p (maybe_cmp_fragP->tc_frag_data.mf_type,
11845 pad_fragP->tc_frag_data.mf_type))
11846 return branch_fragP;
11852 /* Classify BRANCH_PADDING, BRANCH_PREFIX and FUSED_JCC_PADDING frags. */
11855 i386_classify_machine_dependent_frag (fragS *fragP)
11859 fragS *branch_fragP;
11861 unsigned int max_prefix_length;
11863 if (fragP->tc_frag_data.classified)
11866 /* First scan for BRANCH_PADDING and FUSED_JCC_PADDING. Convert
11867 FUSED_JCC_PADDING and merge BRANCH_PADDING. */
11868 for (next_fragP = fragP;
11869 next_fragP != NULL;
11870 next_fragP = next_fragP->fr_next)
11872 next_fragP->tc_frag_data.classified = 1;
11873 if (next_fragP->fr_type == rs_machine_dependent)
11874 switch (TYPE_FROM_RELAX_STATE (next_fragP->fr_subtype))
11876 case BRANCH_PADDING:
11877 /* The BRANCH_PADDING frag must be followed by a branch
11879 branch_fragP = i386_next_non_empty_frag (next_fragP);
11880 next_fragP->tc_frag_data.u.branch_fragP = branch_fragP;
11882 case FUSED_JCC_PADDING:
11883 /* Check if this is a fused jcc:
11885 CMP like instruction
11889 cmp_fragP = i386_next_non_empty_frag (next_fragP);
11890 pad_fragP = i386_next_non_empty_frag (cmp_fragP);
11891 branch_fragP = i386_next_fusible_jcc_frag (next_fragP, pad_fragP);
11894 /* The BRANCH_PADDING frag is merged with the
11895 FUSED_JCC_PADDING frag. */
11896 next_fragP->tc_frag_data.u.branch_fragP = branch_fragP;
11897 /* CMP like instruction size. */
11898 next_fragP->tc_frag_data.cmp_size = cmp_fragP->fr_fix;
11899 frag_wane (pad_fragP);
11900 /* Skip to branch_fragP. */
11901 next_fragP = branch_fragP;
11903 else if (next_fragP->tc_frag_data.max_prefix_length)
11905 /* Turn FUSED_JCC_PADDING into BRANCH_PREFIX if it isn't
11907 next_fragP->fr_subtype
11908 = ENCODE_RELAX_STATE (BRANCH_PREFIX, 0);
11909 next_fragP->tc_frag_data.max_bytes
11910 = next_fragP->tc_frag_data.max_prefix_length;
11911 /* This will be updated in the BRANCH_PREFIX scan. */
11912 next_fragP->tc_frag_data.max_prefix_length = 0;
11915 frag_wane (next_fragP);
11920 /* Stop if there is no BRANCH_PREFIX. */
11921 if (!align_branch_prefix_size)
11924 /* Scan for BRANCH_PREFIX. */
11925 for (; fragP != NULL; fragP = fragP->fr_next)
11927 if (fragP->fr_type != rs_machine_dependent
11928 || (TYPE_FROM_RELAX_STATE (fragP->fr_subtype)
11932 /* Count all BRANCH_PREFIX frags before BRANCH_PADDING and
11933 COND_JUMP_PREFIX. */
11934 max_prefix_length = 0;
11935 for (next_fragP = fragP;
11936 next_fragP != NULL;
11937 next_fragP = next_fragP->fr_next)
11939 if (next_fragP->fr_type == rs_fill)
11940 /* Skip rs_fill frags. */
11942 else if (next_fragP->fr_type != rs_machine_dependent)
11943 /* Stop for all other frags. */
11946 /* rs_machine_dependent frags. */
11947 if (TYPE_FROM_RELAX_STATE (next_fragP->fr_subtype)
11950 /* Count BRANCH_PREFIX frags. */
11951 if (max_prefix_length >= MAX_FUSED_JCC_PADDING_SIZE)
11953 max_prefix_length = MAX_FUSED_JCC_PADDING_SIZE;
11954 frag_wane (next_fragP);
11958 += next_fragP->tc_frag_data.max_bytes;
11960 else if ((TYPE_FROM_RELAX_STATE (next_fragP->fr_subtype)
11962 || (TYPE_FROM_RELAX_STATE (next_fragP->fr_subtype)
11963 == FUSED_JCC_PADDING))
11965 /* Stop at BRANCH_PADDING and FUSED_JCC_PADDING. */
11966 fragP->tc_frag_data.u.padding_fragP = next_fragP;
11970 /* Stop for other rs_machine_dependent frags. */
11974 fragP->tc_frag_data.max_prefix_length = max_prefix_length;
11976 /* Skip to the next frag. */
11977 fragP = next_fragP;
11981 /* Compute padding size for
11984 CMP like instruction
11986 COND_JUMP/UNCOND_JUMP
11991 COND_JUMP/UNCOND_JUMP
11995 i386_branch_padding_size (fragS *fragP, offsetT address)
11997 unsigned int offset, size, padding_size;
11998 fragS *branch_fragP = fragP->tc_frag_data.u.branch_fragP;
12000 /* The start address of the BRANCH_PADDING or FUSED_JCC_PADDING frag. */
12002 address = fragP->fr_address;
12003 address += fragP->fr_fix;
12005 /* CMP like instrunction size. */
12006 size = fragP->tc_frag_data.cmp_size;
12008 /* The base size of the branch frag. */
12009 size += branch_fragP->fr_fix;
12011 /* Add opcode and displacement bytes for the rs_machine_dependent
12013 if (branch_fragP->fr_type == rs_machine_dependent)
12014 size += md_relax_table[branch_fragP->fr_subtype].rlx_length;
12016 /* Check if branch is within boundary and doesn't end at the last
12018 offset = address & ((1U << align_branch_power) - 1);
12019 if ((offset + size) >= (1U << align_branch_power))
12020 /* Padding needed to avoid crossing boundary. */
12021 padding_size = (1U << align_branch_power) - offset;
12023 /* No padding needed. */
12026 /* The return value may be saved in tc_frag_data.length which is
12028 if (!fits_in_unsigned_byte (padding_size))
12031 return padding_size;
12034 /* i386_generic_table_relax_frag()
12036 Handle BRANCH_PADDING, BRANCH_PREFIX and FUSED_JCC_PADDING frags to
12037 grow/shrink padding to align branch frags. Hand others to
12041 i386_generic_table_relax_frag (segT segment, fragS *fragP, long stretch)
12043 if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PADDING
12044 || TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == FUSED_JCC_PADDING)
12046 long padding_size = i386_branch_padding_size (fragP, 0);
12047 long grow = padding_size - fragP->tc_frag_data.length;
12049 /* When the BRANCH_PREFIX frag is used, the computed address
12050 must match the actual address and there should be no padding. */
12051 if (fragP->tc_frag_data.padding_address
12052 && (fragP->tc_frag_data.padding_address != fragP->fr_address
12056 /* Update the padding size. */
12058 fragP->tc_frag_data.length = padding_size;
12062 else if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PREFIX)
12064 fragS *padding_fragP, *next_fragP;
12065 long padding_size, left_size, last_size;
12067 padding_fragP = fragP->tc_frag_data.u.padding_fragP;
12068 if (!padding_fragP)
12069 /* Use the padding set by the leading BRANCH_PREFIX frag. */
12070 return (fragP->tc_frag_data.length
12071 - fragP->tc_frag_data.last_length);
12073 /* Compute the relative address of the padding frag in the very
12074 first time where the BRANCH_PREFIX frag sizes are zero. */
12075 if (!fragP->tc_frag_data.padding_address)
12076 fragP->tc_frag_data.padding_address
12077 = padding_fragP->fr_address - (fragP->fr_address - stretch);
12079 /* First update the last length from the previous interation. */
12080 left_size = fragP->tc_frag_data.prefix_length;
12081 for (next_fragP = fragP;
12082 next_fragP != padding_fragP;
12083 next_fragP = next_fragP->fr_next)
12084 if (next_fragP->fr_type == rs_machine_dependent
12085 && (TYPE_FROM_RELAX_STATE (next_fragP->fr_subtype)
12090 int max = next_fragP->tc_frag_data.max_bytes;
12094 if (max > left_size)
12099 next_fragP->tc_frag_data.last_length = size;
12103 next_fragP->tc_frag_data.last_length = 0;
12106 /* Check the padding size for the padding frag. */
12107 padding_size = i386_branch_padding_size
12108 (padding_fragP, (fragP->fr_address
12109 + fragP->tc_frag_data.padding_address));
12111 last_size = fragP->tc_frag_data.prefix_length;
12112 /* Check if there is change from the last interation. */
12113 if (padding_size == last_size)
12115 /* Update the expected address of the padding frag. */
12116 padding_fragP->tc_frag_data.padding_address
12117 = (fragP->fr_address + padding_size
12118 + fragP->tc_frag_data.padding_address);
12122 if (padding_size > fragP->tc_frag_data.max_prefix_length)
12124 /* No padding if there is no sufficient room. Clear the
12125 expected address of the padding frag. */
12126 padding_fragP->tc_frag_data.padding_address = 0;
12130 /* Store the expected address of the padding frag. */
12131 padding_fragP->tc_frag_data.padding_address
12132 = (fragP->fr_address + padding_size
12133 + fragP->tc_frag_data.padding_address);
12135 fragP->tc_frag_data.prefix_length = padding_size;
12137 /* Update the length for the current interation. */
12138 left_size = padding_size;
12139 for (next_fragP = fragP;
12140 next_fragP != padding_fragP;
12141 next_fragP = next_fragP->fr_next)
12142 if (next_fragP->fr_type == rs_machine_dependent
12143 && (TYPE_FROM_RELAX_STATE (next_fragP->fr_subtype)
12148 int max = next_fragP->tc_frag_data.max_bytes;
12152 if (max > left_size)
12157 next_fragP->tc_frag_data.length = size;
12161 next_fragP->tc_frag_data.length = 0;
12164 return (fragP->tc_frag_data.length
12165 - fragP->tc_frag_data.last_length);
12167 return relax_frag (segment, fragP, stretch);
12170 /* md_estimate_size_before_relax()
12172 Called just before relax() for rs_machine_dependent frags. The x86
12173 assembler uses these frags to handle variable size jump
12176 Any symbol that is now undefined will not become defined.
12177 Return the correct fr_subtype in the frag.
12178 Return the initial "guess for variable size of frag" to caller.
12179 The guess is actually the growth beyond the fixed part. Whatever
12180 we do to grow the fixed or variable part contributes to our
12184 md_estimate_size_before_relax (fragS *fragP, segT segment)
12186 if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PADDING
12187 || TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PREFIX
12188 || TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == FUSED_JCC_PADDING)
12190 i386_classify_machine_dependent_frag (fragP);
12191 return fragP->tc_frag_data.length;
12194 /* We've already got fragP->fr_subtype right; all we have to do is
12195 check for un-relaxable symbols. On an ELF system, we can't relax
12196 an externally visible symbol, because it may be overridden by a
12198 if (S_GET_SEGMENT (fragP->fr_symbol) != segment
12199 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
12201 && !elf_symbol_resolved_in_segment_p (fragP->fr_symbol,
12204 #if defined (OBJ_COFF) && defined (TE_PE)
12205 || (OUTPUT_FLAVOR == bfd_target_coff_flavour
12206 && S_IS_WEAK (fragP->fr_symbol))
12210 /* Symbol is undefined in this segment, or we need to keep a
12211 reloc so that weak symbols can be overridden. */
12212 int size = (fragP->fr_subtype & CODE16) ? 2 : 4;
12213 enum bfd_reloc_code_real reloc_type;
12214 unsigned char *opcode;
12218 if (fragP->fr_var != NO_RELOC)
12219 reloc_type = (enum bfd_reloc_code_real) fragP->fr_var;
12220 else if (size == 2)
12221 reloc_type = BFD_RELOC_16_PCREL;
12222 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
12223 else if (need_plt32_p (fragP->fr_symbol))
12224 reloc_type = BFD_RELOC_X86_64_PLT32;
12227 reloc_type = BFD_RELOC_32_PCREL;
12229 old_fr_fix = fragP->fr_fix;
12230 opcode = (unsigned char *) fragP->fr_opcode;
12232 switch (TYPE_FROM_RELAX_STATE (fragP->fr_subtype))
12235 /* Make jmp (0xeb) a (d)word displacement jump. */
12237 fragP->fr_fix += size;
12238 fixP = fix_new (fragP, old_fr_fix, size,
12240 fragP->fr_offset, 1,
12246 && (!no_cond_jump_promotion || fragP->fr_var != NO_RELOC))
12248 /* Negate the condition, and branch past an
12249 unconditional jump. */
12252 /* Insert an unconditional jump. */
12254 /* We added two extra opcode bytes, and have a two byte
12256 fragP->fr_fix += 2 + 2;
12257 fix_new (fragP, old_fr_fix + 2, 2,
12259 fragP->fr_offset, 1,
12263 /* Fall through. */
12266 if (no_cond_jump_promotion && fragP->fr_var == NO_RELOC)
12268 fragP->fr_fix += 1;
12269 fixP = fix_new (fragP, old_fr_fix, 1,
12271 fragP->fr_offset, 1,
12272 BFD_RELOC_8_PCREL);
12273 fixP->fx_signed = 1;
12277 /* This changes the byte-displacement jump 0x7N
12278 to the (d)word-displacement jump 0x0f,0x8N. */
12279 opcode[1] = opcode[0] + 0x10;
12280 opcode[0] = TWO_BYTE_OPCODE_ESCAPE;
12281 /* We've added an opcode byte. */
12282 fragP->fr_fix += 1 + size;
12283 fixP = fix_new (fragP, old_fr_fix + 1, size,
12285 fragP->fr_offset, 1,
12290 BAD_CASE (fragP->fr_subtype);
12294 /* All jumps handled here are signed, but don't unconditionally use a
12295 signed limit check for 32 and 16 bit jumps as we want to allow wrap
12296 around at 4G (outside of 64-bit mode) and 64k. */
12297 if (size == 4 && flag_code == CODE_64BIT)
12298 fixP->fx_signed = 1;
12301 return fragP->fr_fix - old_fr_fix;
12304 /* Guess size depending on current relax state. Initially the relax
12305 state will correspond to a short jump and we return 1, because
12306 the variable part of the frag (the branch offset) is one byte
12307 long. However, we can relax a section more than once and in that
12308 case we must either set fr_subtype back to the unrelaxed state,
12309 or return the value for the appropriate branch. */
12310 return md_relax_table[fragP->fr_subtype].rlx_length;
12313 /* Called after relax() is finished.
12315 In: Address of frag.
12316 fr_type == rs_machine_dependent.
12317 fr_subtype is what the address relaxed to.
12319 Out: Any fixSs and constants are set up.
12320 Caller will turn frag into a ".space 0". */
12323 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED,
12326 unsigned char *opcode;
12327 unsigned char *where_to_put_displacement = NULL;
12328 offsetT target_address;
12329 offsetT opcode_address;
12330 unsigned int extension = 0;
12331 offsetT displacement_from_opcode_start;
12333 if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PADDING
12334 || TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == FUSED_JCC_PADDING
12335 || TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PREFIX)
12337 /* Generate nop padding. */
12338 unsigned int size = fragP->tc_frag_data.length;
12341 if (size > fragP->tc_frag_data.max_bytes)
12347 const char *branch = "branch";
12348 const char *prefix = "";
12349 fragS *padding_fragP;
12350 if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype)
12353 padding_fragP = fragP->tc_frag_data.u.padding_fragP;
12354 switch (fragP->tc_frag_data.default_prefix)
12359 case CS_PREFIX_OPCODE:
12362 case DS_PREFIX_OPCODE:
12365 case ES_PREFIX_OPCODE:
12368 case FS_PREFIX_OPCODE:
12371 case GS_PREFIX_OPCODE:
12374 case SS_PREFIX_OPCODE:
12379 msg = _("%s:%u: add %d%s at 0x%llx to align "
12380 "%s within %d-byte boundary\n");
12382 msg = _("%s:%u: add additional %d%s at 0x%llx to "
12383 "align %s within %d-byte boundary\n");
12387 padding_fragP = fragP;
12388 msg = _("%s:%u: add %d%s-byte nop at 0x%llx to align "
12389 "%s within %d-byte boundary\n");
12393 switch (padding_fragP->tc_frag_data.branch_type)
12395 case align_branch_jcc:
12398 case align_branch_fused:
12399 branch = "fused jcc";
12401 case align_branch_jmp:
12404 case align_branch_call:
12407 case align_branch_indirect:
12408 branch = "indiret branch";
12410 case align_branch_ret:
12417 fprintf (stdout, msg,
12418 fragP->fr_file, fragP->fr_line, size, prefix,
12419 (long long) fragP->fr_address, branch,
12420 1 << align_branch_power);
12422 if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PREFIX)
12423 memset (fragP->fr_opcode,
12424 fragP->tc_frag_data.default_prefix, size);
12426 i386_generate_nops (fragP, (char *) fragP->fr_opcode,
12428 fragP->fr_fix += size;
12433 opcode = (unsigned char *) fragP->fr_opcode;
12435 /* Address we want to reach in file space. */
12436 target_address = S_GET_VALUE (fragP->fr_symbol) + fragP->fr_offset;
12438 /* Address opcode resides at in file space. */
12439 opcode_address = fragP->fr_address + fragP->fr_fix;
12441 /* Displacement from opcode start to fill into instruction. */
12442 displacement_from_opcode_start = target_address - opcode_address;
12444 if ((fragP->fr_subtype & BIG) == 0)
12446 /* Don't have to change opcode. */
12447 extension = 1; /* 1 opcode + 1 displacement */
12448 where_to_put_displacement = &opcode[1];
12452 if (no_cond_jump_promotion
12453 && TYPE_FROM_RELAX_STATE (fragP->fr_subtype) != UNCOND_JUMP)
12454 as_warn_where (fragP->fr_file, fragP->fr_line,
12455 _("long jump required"));
12457 switch (fragP->fr_subtype)
12459 case ENCODE_RELAX_STATE (UNCOND_JUMP, BIG):
12460 extension = 4; /* 1 opcode + 4 displacement */
12462 where_to_put_displacement = &opcode[1];
12465 case ENCODE_RELAX_STATE (UNCOND_JUMP, BIG16):
12466 extension = 2; /* 1 opcode + 2 displacement */
12468 where_to_put_displacement = &opcode[1];
12471 case ENCODE_RELAX_STATE (COND_JUMP, BIG):
12472 case ENCODE_RELAX_STATE (COND_JUMP86, BIG):
12473 extension = 5; /* 2 opcode + 4 displacement */
12474 opcode[1] = opcode[0] + 0x10;
12475 opcode[0] = TWO_BYTE_OPCODE_ESCAPE;
12476 where_to_put_displacement = &opcode[2];
12479 case ENCODE_RELAX_STATE (COND_JUMP, BIG16):
12480 extension = 3; /* 2 opcode + 2 displacement */
12481 opcode[1] = opcode[0] + 0x10;
12482 opcode[0] = TWO_BYTE_OPCODE_ESCAPE;
12483 where_to_put_displacement = &opcode[2];
12486 case ENCODE_RELAX_STATE (COND_JUMP86, BIG16):
12491 where_to_put_displacement = &opcode[3];
12495 BAD_CASE (fragP->fr_subtype);
12500 /* If size if less then four we are sure that the operand fits,
12501 but if it's 4, then it could be that the displacement is larger
12503 if (DISP_SIZE_FROM_RELAX_STATE (fragP->fr_subtype) == 4
12505 && ((addressT) (displacement_from_opcode_start - extension
12506 + ((addressT) 1 << 31))
12507 > (((addressT) 2 << 31) - 1)))
12509 as_bad_where (fragP->fr_file, fragP->fr_line,
12510 _("jump target out of range"));
12511 /* Make us emit 0. */
12512 displacement_from_opcode_start = extension;
12514 /* Now put displacement after opcode. */
12515 md_number_to_chars ((char *) where_to_put_displacement,
12516 (valueT) (displacement_from_opcode_start - extension),
12517 DISP_SIZE_FROM_RELAX_STATE (fragP->fr_subtype));
12518 fragP->fr_fix += extension;
12521 /* Apply a fixup (fixP) to segment data, once it has been determined
12522 by our caller that we have all the info we need to fix it up.
12524 Parameter valP is the pointer to the value of the bits.
12526 On the 386, immediates, displacements, and data pointers are all in
12527 the same (little-endian) format, so we don't need to care about which
12528 we are handling. */
12531 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
12533 char *p = fixP->fx_where + fixP->fx_frag->fr_literal;
12534 valueT value = *valP;
12536 #if !defined (TE_Mach)
12537 if (fixP->fx_pcrel)
12539 switch (fixP->fx_r_type)
12545 fixP->fx_r_type = BFD_RELOC_64_PCREL;
12548 case BFD_RELOC_X86_64_32S:
12549 fixP->fx_r_type = BFD_RELOC_32_PCREL;
12552 fixP->fx_r_type = BFD_RELOC_16_PCREL;
12555 fixP->fx_r_type = BFD_RELOC_8_PCREL;
12560 if (fixP->fx_addsy != NULL
12561 && (fixP->fx_r_type == BFD_RELOC_32_PCREL
12562 || fixP->fx_r_type == BFD_RELOC_64_PCREL
12563 || fixP->fx_r_type == BFD_RELOC_16_PCREL
12564 || fixP->fx_r_type == BFD_RELOC_8_PCREL)
12565 && !use_rela_relocations)
12567 /* This is a hack. There should be a better way to handle this.
12568 This covers for the fact that bfd_install_relocation will
12569 subtract the current location (for partial_inplace, PC relative
12570 relocations); see more below. */
12574 || OUTPUT_FLAVOR == bfd_target_coff_flavour
12577 value += fixP->fx_where + fixP->fx_frag->fr_address;
12579 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
12582 segT sym_seg = S_GET_SEGMENT (fixP->fx_addsy);
12584 if ((sym_seg == seg
12585 || (symbol_section_p (fixP->fx_addsy)
12586 && sym_seg != absolute_section))
12587 && !generic_force_reloc (fixP))
12589 /* Yes, we add the values in twice. This is because
12590 bfd_install_relocation subtracts them out again. I think
12591 bfd_install_relocation is broken, but I don't dare change
12593 value += fixP->fx_where + fixP->fx_frag->fr_address;
12597 #if defined (OBJ_COFF) && defined (TE_PE)
12598 /* For some reason, the PE format does not store a
12599 section address offset for a PC relative symbol. */
12600 if (S_GET_SEGMENT (fixP->fx_addsy) != seg
12601 || S_IS_WEAK (fixP->fx_addsy))
12602 value += md_pcrel_from (fixP);
12605 #if defined (OBJ_COFF) && defined (TE_PE)
12606 if (fixP->fx_addsy != NULL
12607 && S_IS_WEAK (fixP->fx_addsy)
12608 /* PR 16858: Do not modify weak function references. */
12609 && ! fixP->fx_pcrel)
12611 #if !defined (TE_PEP)
12612 /* For x86 PE weak function symbols are neither PC-relative
12613 nor do they set S_IS_FUNCTION. So the only reliable way
12614 to detect them is to check the flags of their containing
12616 if (S_GET_SEGMENT (fixP->fx_addsy) != NULL
12617 && S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_CODE)
12621 value -= S_GET_VALUE (fixP->fx_addsy);
12625 /* Fix a few things - the dynamic linker expects certain values here,
12626 and we must not disappoint it. */
12627 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
12628 if (IS_ELF && fixP->fx_addsy)
12629 switch (fixP->fx_r_type)
12631 case BFD_RELOC_386_PLT32:
12632 case BFD_RELOC_X86_64_PLT32:
12633 /* Make the jump instruction point to the address of the operand.
12634 At runtime we merely add the offset to the actual PLT entry.
12635 NB: Subtract the offset size only for jump instructions. */
12636 if (fixP->fx_pcrel)
12640 case BFD_RELOC_386_TLS_GD:
12641 case BFD_RELOC_386_TLS_LDM:
12642 case BFD_RELOC_386_TLS_IE_32:
12643 case BFD_RELOC_386_TLS_IE:
12644 case BFD_RELOC_386_TLS_GOTIE:
12645 case BFD_RELOC_386_TLS_GOTDESC:
12646 case BFD_RELOC_X86_64_TLSGD:
12647 case BFD_RELOC_X86_64_TLSLD:
12648 case BFD_RELOC_X86_64_GOTTPOFF:
12649 case BFD_RELOC_X86_64_GOTPC32_TLSDESC:
12650 value = 0; /* Fully resolved at runtime. No addend. */
12652 case BFD_RELOC_386_TLS_LE:
12653 case BFD_RELOC_386_TLS_LDO_32:
12654 case BFD_RELOC_386_TLS_LE_32:
12655 case BFD_RELOC_X86_64_DTPOFF32:
12656 case BFD_RELOC_X86_64_DTPOFF64:
12657 case BFD_RELOC_X86_64_TPOFF32:
12658 case BFD_RELOC_X86_64_TPOFF64:
12659 S_SET_THREAD_LOCAL (fixP->fx_addsy);
12662 case BFD_RELOC_386_TLS_DESC_CALL:
12663 case BFD_RELOC_X86_64_TLSDESC_CALL:
12664 value = 0; /* Fully resolved at runtime. No addend. */
12665 S_SET_THREAD_LOCAL (fixP->fx_addsy);
12669 case BFD_RELOC_VTABLE_INHERIT:
12670 case BFD_RELOC_VTABLE_ENTRY:
12677 #endif /* defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) */
12679 /* If not 64bit, massage value, to account for wraparound when !BFD64. */
12681 value = extend_to_32bit_address (value);
12684 #endif /* !defined (TE_Mach) */
12686 /* Are we finished with this relocation now? */
12687 if (fixP->fx_addsy == NULL)
12690 switch (fixP->fx_r_type)
12692 case BFD_RELOC_X86_64_32S:
12693 fixP->fx_signed = 1;
12700 #if defined (OBJ_COFF) && defined (TE_PE)
12701 else if (fixP->fx_addsy != NULL && S_IS_WEAK (fixP->fx_addsy))
12704 /* Remember value for tc_gen_reloc. */
12705 fixP->fx_addnumber = value;
12706 /* Clear out the frag for now. */
12710 else if (use_rela_relocations)
12712 fixP->fx_no_overflow = 1;
12713 /* Remember value for tc_gen_reloc. */
12714 fixP->fx_addnumber = value;
12718 md_number_to_chars (p, value, fixP->fx_size);
12722 md_atof (int type, char *litP, int *sizeP)
12724 /* This outputs the LITTLENUMs in REVERSE order;
12725 in accord with the bigendian 386. */
12726 return ieee_md_atof (type, litP, sizeP, false);
12729 static char output_invalid_buf[sizeof (unsigned char) * 2 + 6];
12732 output_invalid (int c)
12735 snprintf (output_invalid_buf, sizeof (output_invalid_buf),
12738 snprintf (output_invalid_buf, sizeof (output_invalid_buf),
12739 "(0x%x)", (unsigned char) c);
12740 return output_invalid_buf;
12743 /* Verify that @r can be used in the current context. */
12745 static bool check_register (const reg_entry *r)
12747 if (allow_pseudo_reg)
12750 if (operand_type_all_zero (&r->reg_type))
12753 if ((r->reg_type.bitfield.dword
12754 || (r->reg_type.bitfield.class == SReg && r->reg_num > 3)
12755 || r->reg_type.bitfield.class == RegCR
12756 || r->reg_type.bitfield.class == RegDR)
12757 && !cpu_arch_flags.bitfield.cpui386)
12760 if (r->reg_type.bitfield.class == RegTR
12761 && (flag_code == CODE_64BIT
12762 || !cpu_arch_flags.bitfield.cpui386
12763 || cpu_arch_isa_flags.bitfield.cpui586
12764 || cpu_arch_isa_flags.bitfield.cpui686))
12767 if (r->reg_type.bitfield.class == RegMMX && !cpu_arch_flags.bitfield.cpummx)
12770 if (!cpu_arch_flags.bitfield.cpuavx512f)
12772 if (r->reg_type.bitfield.zmmword
12773 || r->reg_type.bitfield.class == RegMask)
12776 if (!cpu_arch_flags.bitfield.cpuavx)
12778 if (r->reg_type.bitfield.ymmword)
12781 if (!cpu_arch_flags.bitfield.cpusse && r->reg_type.bitfield.xmmword)
12786 if (r->reg_type.bitfield.tmmword
12787 && (!cpu_arch_flags.bitfield.cpuamx_tile
12788 || flag_code != CODE_64BIT))
12791 if (r->reg_type.bitfield.class == RegBND && !cpu_arch_flags.bitfield.cpumpx)
12794 /* Don't allow fake index register unless allow_index_reg isn't 0. */
12795 if (!allow_index_reg && r->reg_num == RegIZ)
12798 /* Upper 16 vector registers are only available with VREX in 64bit
12799 mode, and require EVEX encoding. */
12800 if (r->reg_flags & RegVRex)
12802 if (!cpu_arch_flags.bitfield.cpuavx512f
12803 || flag_code != CODE_64BIT)
12806 if (i.vec_encoding == vex_encoding_default)
12807 i.vec_encoding = vex_encoding_evex;
12808 else if (i.vec_encoding != vex_encoding_evex)
12809 i.vec_encoding = vex_encoding_error;
12812 if (((r->reg_flags & (RegRex64 | RegRex)) || r->reg_type.bitfield.qword)
12813 && (!cpu_arch_flags.bitfield.cpulm || r->reg_type.bitfield.class != RegCR)
12814 && flag_code != CODE_64BIT)
12817 if (r->reg_type.bitfield.class == SReg && r->reg_num == RegFlat
12824 /* REG_STRING starts *before* REGISTER_PREFIX. */
12826 static const reg_entry *
12827 parse_real_register (char *reg_string, char **end_op)
12829 char *s = reg_string;
12831 char reg_name_given[MAX_REG_NAME_SIZE + 1];
12832 const reg_entry *r;
12834 /* Skip possible REGISTER_PREFIX and possible whitespace. */
12835 if (*s == REGISTER_PREFIX)
12838 if (is_space_char (*s))
12841 p = reg_name_given;
12842 while ((*p++ = register_chars[(unsigned char) *s]) != '\0')
12844 if (p >= reg_name_given + MAX_REG_NAME_SIZE)
12845 return (const reg_entry *) NULL;
12849 /* For naked regs, make sure that we are not dealing with an identifier.
12850 This prevents confusing an identifier like `eax_var' with register
12852 if (allow_naked_reg && identifier_chars[(unsigned char) *s])
12853 return (const reg_entry *) NULL;
12857 r = (const reg_entry *) str_hash_find (reg_hash, reg_name_given);
12859 /* Handle floating point regs, allowing spaces in the (i) part. */
12862 if (!cpu_arch_flags.bitfield.cpu8087
12863 && !cpu_arch_flags.bitfield.cpu287
12864 && !cpu_arch_flags.bitfield.cpu387
12865 && !allow_pseudo_reg)
12866 return (const reg_entry *) NULL;
12868 if (is_space_char (*s))
12873 if (is_space_char (*s))
12875 if (*s >= '0' && *s <= '7')
12877 int fpr = *s - '0';
12879 if (is_space_char (*s))
12884 know (r[fpr].reg_num == fpr);
12888 /* We have "%st(" then garbage. */
12889 return (const reg_entry *) NULL;
12893 return r && check_register (r) ? r : NULL;
12896 /* REG_STRING starts *before* REGISTER_PREFIX. */
12898 static const reg_entry *
12899 parse_register (char *reg_string, char **end_op)
12901 const reg_entry *r;
12903 if (*reg_string == REGISTER_PREFIX || allow_naked_reg)
12904 r = parse_real_register (reg_string, end_op);
12909 char *save = input_line_pointer;
12913 input_line_pointer = reg_string;
12914 c = get_symbol_name (®_string);
12915 symbolP = symbol_find (reg_string);
12916 if (symbolP && S_GET_SEGMENT (symbolP) == reg_section)
12918 const expressionS *e = symbol_get_value_expression (symbolP);
12920 know (e->X_op == O_register);
12921 know (e->X_add_number >= 0
12922 && (valueT) e->X_add_number < i386_regtab_size);
12923 r = i386_regtab + e->X_add_number;
12924 if (!check_register (r))
12926 as_bad (_("register '%s%s' cannot be used here"),
12927 register_prefix, r->reg_name);
12930 *end_op = input_line_pointer;
12932 *input_line_pointer = c;
12933 input_line_pointer = save;
12939 i386_parse_name (char *name, expressionS *e, char *nextcharP)
12941 const reg_entry *r;
12942 char *end = input_line_pointer;
12945 r = parse_register (name, &input_line_pointer);
12946 if (r && end <= input_line_pointer)
12948 *nextcharP = *input_line_pointer;
12949 *input_line_pointer = 0;
12952 e->X_op = O_register;
12953 e->X_add_number = r - i386_regtab;
12956 e->X_op = O_illegal;
12959 input_line_pointer = end;
12961 return intel_syntax ? i386_intel_parse_name (name, e) : 0;
12965 md_operand (expressionS *e)
12968 const reg_entry *r;
12970 switch (*input_line_pointer)
12972 case REGISTER_PREFIX:
12973 r = parse_real_register (input_line_pointer, &end);
12976 e->X_op = O_register;
12977 e->X_add_number = r - i386_regtab;
12978 input_line_pointer = end;
12983 gas_assert (intel_syntax);
12984 end = input_line_pointer++;
12986 if (*input_line_pointer == ']')
12988 ++input_line_pointer;
12989 e->X_op_symbol = make_expr_symbol (e);
12990 e->X_add_symbol = NULL;
12991 e->X_add_number = 0;
12996 e->X_op = O_absent;
12997 input_line_pointer = end;
13004 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13005 const char *md_shortopts = "kVQ:sqnO::";
13007 const char *md_shortopts = "qnO::";
13010 #define OPTION_32 (OPTION_MD_BASE + 0)
13011 #define OPTION_64 (OPTION_MD_BASE + 1)
13012 #define OPTION_DIVIDE (OPTION_MD_BASE + 2)
13013 #define OPTION_MARCH (OPTION_MD_BASE + 3)
13014 #define OPTION_MTUNE (OPTION_MD_BASE + 4)
13015 #define OPTION_MMNEMONIC (OPTION_MD_BASE + 5)
13016 #define OPTION_MSYNTAX (OPTION_MD_BASE + 6)
13017 #define OPTION_MINDEX_REG (OPTION_MD_BASE + 7)
13018 #define OPTION_MNAKED_REG (OPTION_MD_BASE + 8)
13019 #define OPTION_MRELAX_RELOCATIONS (OPTION_MD_BASE + 9)
13020 #define OPTION_MSSE2AVX (OPTION_MD_BASE + 10)
13021 #define OPTION_MSSE_CHECK (OPTION_MD_BASE + 11)
13022 #define OPTION_MOPERAND_CHECK (OPTION_MD_BASE + 12)
13023 #define OPTION_MAVXSCALAR (OPTION_MD_BASE + 13)
13024 #define OPTION_X32 (OPTION_MD_BASE + 14)
13025 #define OPTION_MADD_BND_PREFIX (OPTION_MD_BASE + 15)
13026 #define OPTION_MEVEXLIG (OPTION_MD_BASE + 16)
13027 #define OPTION_MEVEXWIG (OPTION_MD_BASE + 17)
13028 #define OPTION_MBIG_OBJ (OPTION_MD_BASE + 18)
13029 #define OPTION_MOMIT_LOCK_PREFIX (OPTION_MD_BASE + 19)
13030 #define OPTION_MEVEXRCIG (OPTION_MD_BASE + 20)
13031 #define OPTION_MSHARED (OPTION_MD_BASE + 21)
13032 #define OPTION_MAMD64 (OPTION_MD_BASE + 22)
13033 #define OPTION_MINTEL64 (OPTION_MD_BASE + 23)
13034 #define OPTION_MFENCE_AS_LOCK_ADD (OPTION_MD_BASE + 24)
13035 #define OPTION_X86_USED_NOTE (OPTION_MD_BASE + 25)
13036 #define OPTION_MVEXWIG (OPTION_MD_BASE + 26)
13037 #define OPTION_MALIGN_BRANCH_BOUNDARY (OPTION_MD_BASE + 27)
13038 #define OPTION_MALIGN_BRANCH_PREFIX_SIZE (OPTION_MD_BASE + 28)
13039 #define OPTION_MALIGN_BRANCH (OPTION_MD_BASE + 29)
13040 #define OPTION_MBRANCHES_WITH_32B_BOUNDARIES (OPTION_MD_BASE + 30)
13041 #define OPTION_MLFENCE_AFTER_LOAD (OPTION_MD_BASE + 31)
13042 #define OPTION_MLFENCE_BEFORE_INDIRECT_BRANCH (OPTION_MD_BASE + 32)
13043 #define OPTION_MLFENCE_BEFORE_RET (OPTION_MD_BASE + 33)
13045 struct option md_longopts[] =
13047 {"32", no_argument, NULL, OPTION_32},
13048 #if (defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \
13049 || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O))
13050 {"64", no_argument, NULL, OPTION_64},
13052 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13053 {"x32", no_argument, NULL, OPTION_X32},
13054 {"mshared", no_argument, NULL, OPTION_MSHARED},
13055 {"mx86-used-note", required_argument, NULL, OPTION_X86_USED_NOTE},
13057 {"divide", no_argument, NULL, OPTION_DIVIDE},
13058 {"march", required_argument, NULL, OPTION_MARCH},
13059 {"mtune", required_argument, NULL, OPTION_MTUNE},
13060 {"mmnemonic", required_argument, NULL, OPTION_MMNEMONIC},
13061 {"msyntax", required_argument, NULL, OPTION_MSYNTAX},
13062 {"mindex-reg", no_argument, NULL, OPTION_MINDEX_REG},
13063 {"mnaked-reg", no_argument, NULL, OPTION_MNAKED_REG},
13064 {"msse2avx", no_argument, NULL, OPTION_MSSE2AVX},
13065 {"msse-check", required_argument, NULL, OPTION_MSSE_CHECK},
13066 {"moperand-check", required_argument, NULL, OPTION_MOPERAND_CHECK},
13067 {"mavxscalar", required_argument, NULL, OPTION_MAVXSCALAR},
13068 {"mvexwig", required_argument, NULL, OPTION_MVEXWIG},
13069 {"madd-bnd-prefix", no_argument, NULL, OPTION_MADD_BND_PREFIX},
13070 {"mevexlig", required_argument, NULL, OPTION_MEVEXLIG},
13071 {"mevexwig", required_argument, NULL, OPTION_MEVEXWIG},
13072 # if defined (TE_PE) || defined (TE_PEP)
13073 {"mbig-obj", no_argument, NULL, OPTION_MBIG_OBJ},
13075 {"momit-lock-prefix", required_argument, NULL, OPTION_MOMIT_LOCK_PREFIX},
13076 {"mfence-as-lock-add", required_argument, NULL, OPTION_MFENCE_AS_LOCK_ADD},
13077 {"mrelax-relocations", required_argument, NULL, OPTION_MRELAX_RELOCATIONS},
13078 {"mevexrcig", required_argument, NULL, OPTION_MEVEXRCIG},
13079 {"malign-branch-boundary", required_argument, NULL, OPTION_MALIGN_BRANCH_BOUNDARY},
13080 {"malign-branch-prefix-size", required_argument, NULL, OPTION_MALIGN_BRANCH_PREFIX_SIZE},
13081 {"malign-branch", required_argument, NULL, OPTION_MALIGN_BRANCH},
13082 {"mbranches-within-32B-boundaries", no_argument, NULL, OPTION_MBRANCHES_WITH_32B_BOUNDARIES},
13083 {"mlfence-after-load", required_argument, NULL, OPTION_MLFENCE_AFTER_LOAD},
13084 {"mlfence-before-indirect-branch", required_argument, NULL,
13085 OPTION_MLFENCE_BEFORE_INDIRECT_BRANCH},
13086 {"mlfence-before-ret", required_argument, NULL, OPTION_MLFENCE_BEFORE_RET},
13087 {"mamd64", no_argument, NULL, OPTION_MAMD64},
13088 {"mintel64", no_argument, NULL, OPTION_MINTEL64},
13089 {NULL, no_argument, NULL, 0}
13091 size_t md_longopts_size = sizeof (md_longopts);
13094 md_parse_option (int c, const char *arg)
13097 char *arch, *next, *saved, *type;
13102 optimize_align_code = 0;
13106 quiet_warnings = 1;
13109 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13110 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
13111 should be emitted or not. FIXME: Not implemented. */
13113 if ((arg[0] != 'y' && arg[0] != 'n') || arg[1])
13117 /* -V: SVR4 argument to print version ID. */
13119 print_version_id ();
13122 /* -k: Ignore for FreeBSD compatibility. */
13127 /* -s: On i386 Solaris, this tells the native assembler to use
13128 .stab instead of .stab.excl. We always use .stab anyhow. */
13131 case OPTION_MSHARED:
13135 case OPTION_X86_USED_NOTE:
13136 if (strcasecmp (arg, "yes") == 0)
13138 else if (strcasecmp (arg, "no") == 0)
13141 as_fatal (_("invalid -mx86-used-note= option: `%s'"), arg);
13146 #if (defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \
13147 || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O))
13150 const char **list, **l;
13152 list = bfd_target_list ();
13153 for (l = list; *l != NULL; l++)
13154 if (startswith (*l, "elf64-x86-64")
13155 || strcmp (*l, "coff-x86-64") == 0
13156 || strcmp (*l, "pe-x86-64") == 0
13157 || strcmp (*l, "pei-x86-64") == 0
13158 || strcmp (*l, "mach-o-x86-64") == 0)
13160 default_arch = "x86_64";
13164 as_fatal (_("no compiled in support for x86_64"));
13170 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13174 const char **list, **l;
13176 list = bfd_target_list ();
13177 for (l = list; *l != NULL; l++)
13178 if (startswith (*l, "elf32-x86-64"))
13180 default_arch = "x86_64:32";
13184 as_fatal (_("no compiled in support for 32bit x86_64"));
13188 as_fatal (_("32bit x86_64 is only supported for ELF"));
13193 default_arch = "i386";
13196 case OPTION_DIVIDE:
13197 #ifdef SVR4_COMMENT_CHARS
13202 n = XNEWVEC (char, strlen (i386_comment_chars) + 1);
13204 for (s = i386_comment_chars; *s != '\0'; s++)
13208 i386_comment_chars = n;
13214 saved = xstrdup (arg);
13216 /* Allow -march=+nosse. */
13222 as_fatal (_("invalid -march= option: `%s'"), arg);
13223 next = strchr (arch, '+');
13226 for (j = 0; j < ARRAY_SIZE (cpu_arch); j++)
13228 if (strcmp (arch, cpu_arch [j].name) == 0)
13231 if (! cpu_arch[j].flags.bitfield.cpui386)
13234 cpu_arch_name = cpu_arch[j].name;
13235 cpu_sub_arch_name = NULL;
13236 cpu_arch_flags = cpu_arch[j].flags;
13237 cpu_arch_isa = cpu_arch[j].type;
13238 cpu_arch_isa_flags = cpu_arch[j].flags;
13239 if (!cpu_arch_tune_set)
13241 cpu_arch_tune = cpu_arch_isa;
13242 cpu_arch_tune_flags = cpu_arch_isa_flags;
13246 else if (*cpu_arch [j].name == '.'
13247 && strcmp (arch, cpu_arch [j].name + 1) == 0)
13249 /* ISA extension. */
13250 i386_cpu_flags flags;
13252 flags = cpu_flags_or (cpu_arch_flags,
13253 cpu_arch[j].flags);
13255 if (!cpu_flags_equal (&flags, &cpu_arch_flags))
13257 if (cpu_sub_arch_name)
13259 char *name = cpu_sub_arch_name;
13260 cpu_sub_arch_name = concat (name,
13262 (const char *) NULL);
13266 cpu_sub_arch_name = xstrdup (cpu_arch[j].name);
13267 cpu_arch_flags = flags;
13268 cpu_arch_isa_flags = flags;
13272 = cpu_flags_or (cpu_arch_isa_flags,
13273 cpu_arch[j].flags);
13278 if (j >= ARRAY_SIZE (cpu_arch))
13280 /* Disable an ISA extension. */
13281 for (j = 0; j < ARRAY_SIZE (cpu_noarch); j++)
13282 if (strcmp (arch, cpu_noarch [j].name) == 0)
13284 i386_cpu_flags flags;
13286 flags = cpu_flags_and_not (cpu_arch_flags,
13287 cpu_noarch[j].flags);
13288 if (!cpu_flags_equal (&flags, &cpu_arch_flags))
13290 if (cpu_sub_arch_name)
13292 char *name = cpu_sub_arch_name;
13293 cpu_sub_arch_name = concat (arch,
13294 (const char *) NULL);
13298 cpu_sub_arch_name = xstrdup (arch);
13299 cpu_arch_flags = flags;
13300 cpu_arch_isa_flags = flags;
13305 if (j >= ARRAY_SIZE (cpu_noarch))
13306 j = ARRAY_SIZE (cpu_arch);
13309 if (j >= ARRAY_SIZE (cpu_arch))
13310 as_fatal (_("invalid -march= option: `%s'"), arg);
13314 while (next != NULL);
13320 as_fatal (_("invalid -mtune= option: `%s'"), arg);
13321 for (j = 0; j < ARRAY_SIZE (cpu_arch); j++)
13323 if (strcmp (arg, cpu_arch [j].name) == 0)
13325 cpu_arch_tune_set = 1;
13326 cpu_arch_tune = cpu_arch [j].type;
13327 cpu_arch_tune_flags = cpu_arch[j].flags;
13331 if (j >= ARRAY_SIZE (cpu_arch))
13332 as_fatal (_("invalid -mtune= option: `%s'"), arg);
13335 case OPTION_MMNEMONIC:
13336 if (strcasecmp (arg, "att") == 0)
13337 intel_mnemonic = 0;
13338 else if (strcasecmp (arg, "intel") == 0)
13339 intel_mnemonic = 1;
13341 as_fatal (_("invalid -mmnemonic= option: `%s'"), arg);
13344 case OPTION_MSYNTAX:
13345 if (strcasecmp (arg, "att") == 0)
13347 else if (strcasecmp (arg, "intel") == 0)
13350 as_fatal (_("invalid -msyntax= option: `%s'"), arg);
13353 case OPTION_MINDEX_REG:
13354 allow_index_reg = 1;
13357 case OPTION_MNAKED_REG:
13358 allow_naked_reg = 1;
13361 case OPTION_MSSE2AVX:
13365 case OPTION_MSSE_CHECK:
13366 if (strcasecmp (arg, "error") == 0)
13367 sse_check = check_error;
13368 else if (strcasecmp (arg, "warning") == 0)
13369 sse_check = check_warning;
13370 else if (strcasecmp (arg, "none") == 0)
13371 sse_check = check_none;
13373 as_fatal (_("invalid -msse-check= option: `%s'"), arg);
13376 case OPTION_MOPERAND_CHECK:
13377 if (strcasecmp (arg, "error") == 0)
13378 operand_check = check_error;
13379 else if (strcasecmp (arg, "warning") == 0)
13380 operand_check = check_warning;
13381 else if (strcasecmp (arg, "none") == 0)
13382 operand_check = check_none;
13384 as_fatal (_("invalid -moperand-check= option: `%s'"), arg);
13387 case OPTION_MAVXSCALAR:
13388 if (strcasecmp (arg, "128") == 0)
13389 avxscalar = vex128;
13390 else if (strcasecmp (arg, "256") == 0)
13391 avxscalar = vex256;
13393 as_fatal (_("invalid -mavxscalar= option: `%s'"), arg);
13396 case OPTION_MVEXWIG:
13397 if (strcmp (arg, "0") == 0)
13399 else if (strcmp (arg, "1") == 0)
13402 as_fatal (_("invalid -mvexwig= option: `%s'"), arg);
13405 case OPTION_MADD_BND_PREFIX:
13406 add_bnd_prefix = 1;
13409 case OPTION_MEVEXLIG:
13410 if (strcmp (arg, "128") == 0)
13411 evexlig = evexl128;
13412 else if (strcmp (arg, "256") == 0)
13413 evexlig = evexl256;
13414 else if (strcmp (arg, "512") == 0)
13415 evexlig = evexl512;
13417 as_fatal (_("invalid -mevexlig= option: `%s'"), arg);
13420 case OPTION_MEVEXRCIG:
13421 if (strcmp (arg, "rne") == 0)
13423 else if (strcmp (arg, "rd") == 0)
13425 else if (strcmp (arg, "ru") == 0)
13427 else if (strcmp (arg, "rz") == 0)
13430 as_fatal (_("invalid -mevexrcig= option: `%s'"), arg);
13433 case OPTION_MEVEXWIG:
13434 if (strcmp (arg, "0") == 0)
13436 else if (strcmp (arg, "1") == 0)
13439 as_fatal (_("invalid -mevexwig= option: `%s'"), arg);
13442 # if defined (TE_PE) || defined (TE_PEP)
13443 case OPTION_MBIG_OBJ:
13448 case OPTION_MOMIT_LOCK_PREFIX:
13449 if (strcasecmp (arg, "yes") == 0)
13450 omit_lock_prefix = 1;
13451 else if (strcasecmp (arg, "no") == 0)
13452 omit_lock_prefix = 0;
13454 as_fatal (_("invalid -momit-lock-prefix= option: `%s'"), arg);
13457 case OPTION_MFENCE_AS_LOCK_ADD:
13458 if (strcasecmp (arg, "yes") == 0)
13460 else if (strcasecmp (arg, "no") == 0)
13463 as_fatal (_("invalid -mfence-as-lock-add= option: `%s'"), arg);
13466 case OPTION_MLFENCE_AFTER_LOAD:
13467 if (strcasecmp (arg, "yes") == 0)
13468 lfence_after_load = 1;
13469 else if (strcasecmp (arg, "no") == 0)
13470 lfence_after_load = 0;
13472 as_fatal (_("invalid -mlfence-after-load= option: `%s'"), arg);
13475 case OPTION_MLFENCE_BEFORE_INDIRECT_BRANCH:
13476 if (strcasecmp (arg, "all") == 0)
13478 lfence_before_indirect_branch = lfence_branch_all;
13479 if (lfence_before_ret == lfence_before_ret_none)
13480 lfence_before_ret = lfence_before_ret_shl;
13482 else if (strcasecmp (arg, "memory") == 0)
13483 lfence_before_indirect_branch = lfence_branch_memory;
13484 else if (strcasecmp (arg, "register") == 0)
13485 lfence_before_indirect_branch = lfence_branch_register;
13486 else if (strcasecmp (arg, "none") == 0)
13487 lfence_before_indirect_branch = lfence_branch_none;
13489 as_fatal (_("invalid -mlfence-before-indirect-branch= option: `%s'"),
13493 case OPTION_MLFENCE_BEFORE_RET:
13494 if (strcasecmp (arg, "or") == 0)
13495 lfence_before_ret = lfence_before_ret_or;
13496 else if (strcasecmp (arg, "not") == 0)
13497 lfence_before_ret = lfence_before_ret_not;
13498 else if (strcasecmp (arg, "shl") == 0 || strcasecmp (arg, "yes") == 0)
13499 lfence_before_ret = lfence_before_ret_shl;
13500 else if (strcasecmp (arg, "none") == 0)
13501 lfence_before_ret = lfence_before_ret_none;
13503 as_fatal (_("invalid -mlfence-before-ret= option: `%s'"),
13507 case OPTION_MRELAX_RELOCATIONS:
13508 if (strcasecmp (arg, "yes") == 0)
13509 generate_relax_relocations = 1;
13510 else if (strcasecmp (arg, "no") == 0)
13511 generate_relax_relocations = 0;
13513 as_fatal (_("invalid -mrelax-relocations= option: `%s'"), arg);
13516 case OPTION_MALIGN_BRANCH_BOUNDARY:
13519 long int align = strtoul (arg, &end, 0);
13524 align_branch_power = 0;
13527 else if (align >= 16)
13530 for (align_power = 0;
13532 align >>= 1, align_power++)
13534 /* Limit alignment power to 31. */
13535 if (align == 1 && align_power < 32)
13537 align_branch_power = align_power;
13542 as_fatal (_("invalid -malign-branch-boundary= value: %s"), arg);
13546 case OPTION_MALIGN_BRANCH_PREFIX_SIZE:
13549 int align = strtoul (arg, &end, 0);
13550 /* Some processors only support 5 prefixes. */
13551 if (*end == '\0' && align >= 0 && align < 6)
13553 align_branch_prefix_size = align;
13556 as_fatal (_("invalid -malign-branch-prefix-size= value: %s"),
13561 case OPTION_MALIGN_BRANCH:
13563 saved = xstrdup (arg);
13567 next = strchr (type, '+');
13570 if (strcasecmp (type, "jcc") == 0)
13571 align_branch |= align_branch_jcc_bit;
13572 else if (strcasecmp (type, "fused") == 0)
13573 align_branch |= align_branch_fused_bit;
13574 else if (strcasecmp (type, "jmp") == 0)
13575 align_branch |= align_branch_jmp_bit;
13576 else if (strcasecmp (type, "call") == 0)
13577 align_branch |= align_branch_call_bit;
13578 else if (strcasecmp (type, "ret") == 0)
13579 align_branch |= align_branch_ret_bit;
13580 else if (strcasecmp (type, "indirect") == 0)
13581 align_branch |= align_branch_indirect_bit;
13583 as_fatal (_("invalid -malign-branch= option: `%s'"), arg);
13586 while (next != NULL);
13590 case OPTION_MBRANCHES_WITH_32B_BOUNDARIES:
13591 align_branch_power = 5;
13592 align_branch_prefix_size = 5;
13593 align_branch = (align_branch_jcc_bit
13594 | align_branch_fused_bit
13595 | align_branch_jmp_bit);
13598 case OPTION_MAMD64:
13602 case OPTION_MINTEL64:
13610 /* Turn off -Os. */
13611 optimize_for_space = 0;
13613 else if (*arg == 's')
13615 optimize_for_space = 1;
13616 /* Turn on all encoding optimizations. */
13617 optimize = INT_MAX;
13621 optimize = atoi (arg);
13622 /* Turn off -Os. */
13623 optimize_for_space = 0;
13633 #define MESSAGE_TEMPLATE \
13637 output_message (FILE *stream, char *p, char *message, char *start,
13638 int *left_p, const char *name, int len)
13640 int size = sizeof (MESSAGE_TEMPLATE);
13641 int left = *left_p;
13643 /* Reserve 2 spaces for ", " or ",\0" */
13646 /* Check if there is any room. */
13654 p = mempcpy (p, name, len);
13658 /* Output the current message now and start a new one. */
13661 fprintf (stream, "%s\n", message);
13663 left = size - (start - message) - len - 2;
13665 gas_assert (left >= 0);
13667 p = mempcpy (p, name, len);
13675 show_arch (FILE *stream, int ext, int check)
13677 static char message[] = MESSAGE_TEMPLATE;
13678 char *start = message + 27;
13680 int size = sizeof (MESSAGE_TEMPLATE);
13687 left = size - (start - message);
13688 for (j = 0; j < ARRAY_SIZE (cpu_arch); j++)
13690 /* Should it be skipped? */
13691 if (cpu_arch [j].skip)
13694 name = cpu_arch [j].name;
13695 len = cpu_arch [j].len;
13698 /* It is an extension. Skip if we aren't asked to show it. */
13709 /* It is an processor. Skip if we show only extension. */
13712 else if (check && ! cpu_arch[j].flags.bitfield.cpui386)
13714 /* It is an impossible processor - skip. */
13718 p = output_message (stream, p, message, start, &left, name, len);
13721 /* Display disabled extensions. */
13723 for (j = 0; j < ARRAY_SIZE (cpu_noarch); j++)
13725 name = cpu_noarch [j].name;
13726 len = cpu_noarch [j].len;
13727 p = output_message (stream, p, message, start, &left, name,
13732 fprintf (stream, "%s\n", message);
13736 md_show_usage (FILE *stream)
13738 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13739 fprintf (stream, _("\
13740 -Qy, -Qn ignored\n\
13741 -V print assembler version number\n\
13744 fprintf (stream, _("\
13745 -n Do not optimize code alignment\n\
13746 -q quieten some warnings\n"));
13747 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13748 fprintf (stream, _("\
13751 #if defined BFD64 && (defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \
13752 || defined (TE_PE) || defined (TE_PEP))
13753 fprintf (stream, _("\
13754 --32/--64/--x32 generate 32bit/64bit/x32 code\n"));
13756 #ifdef SVR4_COMMENT_CHARS
13757 fprintf (stream, _("\
13758 --divide do not treat `/' as a comment character\n"));
13760 fprintf (stream, _("\
13761 --divide ignored\n"));
13763 fprintf (stream, _("\
13764 -march=CPU[,+EXTENSION...]\n\
13765 generate code for CPU and EXTENSION, CPU is one of:\n"));
13766 show_arch (stream, 0, 1);
13767 fprintf (stream, _("\
13768 EXTENSION is combination of:\n"));
13769 show_arch (stream, 1, 0);
13770 fprintf (stream, _("\
13771 -mtune=CPU optimize for CPU, CPU is one of:\n"));
13772 show_arch (stream, 0, 0);
13773 fprintf (stream, _("\
13774 -msse2avx encode SSE instructions with VEX prefix\n"));
13775 fprintf (stream, _("\
13776 -msse-check=[none|error|warning] (default: warning)\n\
13777 check SSE instructions\n"));
13778 fprintf (stream, _("\
13779 -moperand-check=[none|error|warning] (default: warning)\n\
13780 check operand combinations for validity\n"));
13781 fprintf (stream, _("\
13782 -mavxscalar=[128|256] (default: 128)\n\
13783 encode scalar AVX instructions with specific vector\n\
13785 fprintf (stream, _("\
13786 -mvexwig=[0|1] (default: 0)\n\
13787 encode VEX instructions with specific VEX.W value\n\
13788 for VEX.W bit ignored instructions\n"));
13789 fprintf (stream, _("\
13790 -mevexlig=[128|256|512] (default: 128)\n\
13791 encode scalar EVEX instructions with specific vector\n\
13793 fprintf (stream, _("\
13794 -mevexwig=[0|1] (default: 0)\n\
13795 encode EVEX instructions with specific EVEX.W value\n\
13796 for EVEX.W bit ignored instructions\n"));
13797 fprintf (stream, _("\
13798 -mevexrcig=[rne|rd|ru|rz] (default: rne)\n\
13799 encode EVEX instructions with specific EVEX.RC value\n\
13800 for SAE-only ignored instructions\n"));
13801 fprintf (stream, _("\
13802 -mmnemonic=[att|intel] "));
13803 if (SYSV386_COMPAT)
13804 fprintf (stream, _("(default: att)\n"));
13806 fprintf (stream, _("(default: intel)\n"));
13807 fprintf (stream, _("\
13808 use AT&T/Intel mnemonic\n"));
13809 fprintf (stream, _("\
13810 -msyntax=[att|intel] (default: att)\n\
13811 use AT&T/Intel syntax\n"));
13812 fprintf (stream, _("\
13813 -mindex-reg support pseudo index registers\n"));
13814 fprintf (stream, _("\
13815 -mnaked-reg don't require `%%' prefix for registers\n"));
13816 fprintf (stream, _("\
13817 -madd-bnd-prefix add BND prefix for all valid branches\n"));
13818 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13819 fprintf (stream, _("\
13820 -mshared disable branch optimization for shared code\n"));
13821 fprintf (stream, _("\
13822 -mx86-used-note=[no|yes] "));
13823 if (DEFAULT_X86_USED_NOTE)
13824 fprintf (stream, _("(default: yes)\n"));
13826 fprintf (stream, _("(default: no)\n"));
13827 fprintf (stream, _("\
13828 generate x86 used ISA and feature properties\n"));
13830 #if defined (TE_PE) || defined (TE_PEP)
13831 fprintf (stream, _("\
13832 -mbig-obj generate big object files\n"));
13834 fprintf (stream, _("\
13835 -momit-lock-prefix=[no|yes] (default: no)\n\
13836 strip all lock prefixes\n"));
13837 fprintf (stream, _("\
13838 -mfence-as-lock-add=[no|yes] (default: no)\n\
13839 encode lfence, mfence and sfence as\n\
13840 lock addl $0x0, (%%{re}sp)\n"));
13841 fprintf (stream, _("\
13842 -mrelax-relocations=[no|yes] "));
13843 if (DEFAULT_GENERATE_X86_RELAX_RELOCATIONS)
13844 fprintf (stream, _("(default: yes)\n"));
13846 fprintf (stream, _("(default: no)\n"));
13847 fprintf (stream, _("\
13848 generate relax relocations\n"));
13849 fprintf (stream, _("\
13850 -malign-branch-boundary=NUM (default: 0)\n\
13851 align branches within NUM byte boundary\n"));
13852 fprintf (stream, _("\
13853 -malign-branch=TYPE[+TYPE...] (default: jcc+fused+jmp)\n\
13854 TYPE is combination of jcc, fused, jmp, call, ret,\n\
13856 specify types of branches to align\n"));
13857 fprintf (stream, _("\
13858 -malign-branch-prefix-size=NUM (default: 5)\n\
13859 align branches with NUM prefixes per instruction\n"));
13860 fprintf (stream, _("\
13861 -mbranches-within-32B-boundaries\n\
13862 align branches within 32 byte boundary\n"));
13863 fprintf (stream, _("\
13864 -mlfence-after-load=[no|yes] (default: no)\n\
13865 generate lfence after load\n"));
13866 fprintf (stream, _("\
13867 -mlfence-before-indirect-branch=[none|all|register|memory] (default: none)\n\
13868 generate lfence before indirect near branch\n"));
13869 fprintf (stream, _("\
13870 -mlfence-before-ret=[none|or|not|shl|yes] (default: none)\n\
13871 generate lfence before ret\n"));
13872 fprintf (stream, _("\
13873 -mamd64 accept only AMD64 ISA [default]\n"));
13874 fprintf (stream, _("\
13875 -mintel64 accept only Intel64 ISA\n"));
13878 #if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \
13879 || defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \
13880 || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O))
13882 /* Pick the target format to use. */
13885 i386_target_format (void)
13887 if (startswith (default_arch, "x86_64"))
13889 update_code_flag (CODE_64BIT, 1);
13890 if (default_arch[6] == '\0')
13891 x86_elf_abi = X86_64_ABI;
13893 x86_elf_abi = X86_64_X32_ABI;
13895 else if (!strcmp (default_arch, "i386"))
13896 update_code_flag (CODE_32BIT, 1);
13897 else if (!strcmp (default_arch, "iamcu"))
13899 update_code_flag (CODE_32BIT, 1);
13900 if (cpu_arch_isa == PROCESSOR_UNKNOWN)
13902 static const i386_cpu_flags iamcu_flags = CPU_IAMCU_FLAGS;
13903 cpu_arch_name = "iamcu";
13904 cpu_sub_arch_name = NULL;
13905 cpu_arch_flags = iamcu_flags;
13906 cpu_arch_isa = PROCESSOR_IAMCU;
13907 cpu_arch_isa_flags = iamcu_flags;
13908 if (!cpu_arch_tune_set)
13910 cpu_arch_tune = cpu_arch_isa;
13911 cpu_arch_tune_flags = cpu_arch_isa_flags;
13914 else if (cpu_arch_isa != PROCESSOR_IAMCU)
13915 as_fatal (_("Intel MCU doesn't support `%s' architecture"),
13919 as_fatal (_("unknown architecture"));
13921 if (cpu_flags_all_zero (&cpu_arch_isa_flags))
13922 cpu_arch_isa_flags = cpu_arch[flag_code == CODE_64BIT].flags;
13923 if (cpu_flags_all_zero (&cpu_arch_tune_flags))
13924 cpu_arch_tune_flags = cpu_arch[flag_code == CODE_64BIT].flags;
13926 switch (OUTPUT_FLAVOR)
13928 #if defined (OBJ_MAYBE_AOUT) || defined (OBJ_AOUT)
13929 case bfd_target_aout_flavour:
13930 return AOUT_TARGET_FORMAT;
13932 #if defined (OBJ_MAYBE_COFF) || defined (OBJ_COFF)
13933 # if defined (TE_PE) || defined (TE_PEP)
13934 case bfd_target_coff_flavour:
13935 if (flag_code == CODE_64BIT)
13938 return use_big_obj ? "pe-bigobj-x86-64" : "pe-x86-64";
13940 return use_big_obj ? "pe-bigobj-i386" : "pe-i386";
13941 # elif defined (TE_GO32)
13942 case bfd_target_coff_flavour:
13943 return "coff-go32";
13945 case bfd_target_coff_flavour:
13946 return "coff-i386";
13949 #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF)
13950 case bfd_target_elf_flavour:
13952 const char *format;
13954 switch (x86_elf_abi)
13957 format = ELF_TARGET_FORMAT;
13959 tls_get_addr = "___tls_get_addr";
13963 use_rela_relocations = 1;
13966 tls_get_addr = "__tls_get_addr";
13968 format = ELF_TARGET_FORMAT64;
13970 case X86_64_X32_ABI:
13971 use_rela_relocations = 1;
13974 tls_get_addr = "__tls_get_addr";
13976 disallow_64bit_reloc = 1;
13977 format = ELF_TARGET_FORMAT32;
13980 if (cpu_arch_isa == PROCESSOR_L1OM)
13982 if (x86_elf_abi != X86_64_ABI)
13983 as_fatal (_("Intel L1OM is 64bit only"));
13984 return ELF_TARGET_L1OM_FORMAT;
13986 else if (cpu_arch_isa == PROCESSOR_K1OM)
13988 if (x86_elf_abi != X86_64_ABI)
13989 as_fatal (_("Intel K1OM is 64bit only"));
13990 return ELF_TARGET_K1OM_FORMAT;
13992 else if (cpu_arch_isa == PROCESSOR_IAMCU)
13994 if (x86_elf_abi != I386_ABI)
13995 as_fatal (_("Intel MCU is 32bit only"));
13996 return ELF_TARGET_IAMCU_FORMAT;
14002 #if defined (OBJ_MACH_O)
14003 case bfd_target_mach_o_flavour:
14004 if (flag_code == CODE_64BIT)
14006 use_rela_relocations = 1;
14008 return "mach-o-x86-64";
14011 return "mach-o-i386";
14019 #endif /* OBJ_MAYBE_ more than one */
14022 md_undefined_symbol (char *name)
14024 if (name[0] == GLOBAL_OFFSET_TABLE_NAME[0]
14025 && name[1] == GLOBAL_OFFSET_TABLE_NAME[1]
14026 && name[2] == GLOBAL_OFFSET_TABLE_NAME[2]
14027 && strcmp (name, GLOBAL_OFFSET_TABLE_NAME) == 0)
14031 if (symbol_find (name))
14032 as_bad (_("GOT already in symbol table"));
14033 GOT_symbol = symbol_new (name, undefined_section,
14034 &zero_address_frag, 0);
14041 /* Round up a section size to the appropriate boundary. */
14044 md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
14046 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
14047 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
14049 /* For a.out, force the section size to be aligned. If we don't do
14050 this, BFD will align it for us, but it will not write out the
14051 final bytes of the section. This may be a bug in BFD, but it is
14052 easier to fix it here since that is how the other a.out targets
14056 align = bfd_section_alignment (segment);
14057 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
14064 /* On the i386, PC-relative offsets are relative to the start of the
14065 next instruction. That is, the address of the offset, plus its
14066 size, since the offset is always the last part of the insn. */
14069 md_pcrel_from (fixS *fixP)
14071 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
14077 s_bss (int ignore ATTRIBUTE_UNUSED)
14081 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14083 obj_elf_section_change_hook ();
14085 temp = get_absolute_expression ();
14086 subseg_set (bss_section, (subsegT) temp);
14087 demand_empty_rest_of_line ();
14092 /* Remember constant directive. */
14095 i386_cons_align (int ignore ATTRIBUTE_UNUSED)
14097 if (last_insn.kind != last_insn_directive
14098 && (bfd_section_flags (now_seg) & SEC_CODE))
14100 last_insn.seg = now_seg;
14101 last_insn.kind = last_insn_directive;
14102 last_insn.name = "constant directive";
14103 last_insn.file = as_where (&last_insn.line);
14104 if (lfence_before_ret != lfence_before_ret_none)
14106 if (lfence_before_indirect_branch != lfence_branch_none)
14107 as_warn (_("constant directive skips -mlfence-before-ret "
14108 "and -mlfence-before-indirect-branch"));
14110 as_warn (_("constant directive skips -mlfence-before-ret"));
14112 else if (lfence_before_indirect_branch != lfence_branch_none)
14113 as_warn (_("constant directive skips -mlfence-before-indirect-branch"));
14118 i386_validate_fix (fixS *fixp)
14120 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14121 if (fixp->fx_r_type == BFD_RELOC_SIZE32
14122 || fixp->fx_r_type == BFD_RELOC_SIZE64)
14123 return IS_ELF && fixp->fx_addsy
14124 && (!S_IS_DEFINED (fixp->fx_addsy)
14125 || S_IS_EXTERNAL (fixp->fx_addsy));
14128 if (fixp->fx_subsy)
14130 if (fixp->fx_subsy == GOT_symbol)
14132 if (fixp->fx_r_type == BFD_RELOC_32_PCREL)
14136 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14137 if (fixp->fx_tcbit2)
14138 fixp->fx_r_type = (fixp->fx_tcbit
14139 ? BFD_RELOC_X86_64_REX_GOTPCRELX
14140 : BFD_RELOC_X86_64_GOTPCRELX);
14143 fixp->fx_r_type = BFD_RELOC_X86_64_GOTPCREL;
14148 fixp->fx_r_type = BFD_RELOC_386_GOTOFF;
14150 fixp->fx_r_type = BFD_RELOC_X86_64_GOTOFF64;
14152 fixp->fx_subsy = 0;
14155 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14158 /* NB: Commit 292676c1 resolved PLT32 reloc aganst local symbol
14159 to section. Since PLT32 relocation must be against symbols,
14160 turn such PLT32 relocation into PC32 relocation. */
14162 && (fixp->fx_r_type == BFD_RELOC_386_PLT32
14163 || fixp->fx_r_type == BFD_RELOC_X86_64_PLT32)
14164 && symbol_section_p (fixp->fx_addsy))
14165 fixp->fx_r_type = BFD_RELOC_32_PCREL;
14168 if (fixp->fx_r_type == BFD_RELOC_386_GOT32
14169 && fixp->fx_tcbit2)
14170 fixp->fx_r_type = BFD_RELOC_386_GOT32X;
14179 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
14182 bfd_reloc_code_real_type code;
14184 switch (fixp->fx_r_type)
14186 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14189 case BFD_RELOC_SIZE32:
14190 case BFD_RELOC_SIZE64:
14192 && !bfd_is_abs_section (S_GET_SEGMENT (fixp->fx_addsy))
14193 && (!fixp->fx_subsy
14194 || bfd_is_abs_section (S_GET_SEGMENT (fixp->fx_subsy))))
14195 sym = fixp->fx_addsy;
14196 else if (fixp->fx_subsy
14197 && !bfd_is_abs_section (S_GET_SEGMENT (fixp->fx_subsy))
14198 && (!fixp->fx_addsy
14199 || bfd_is_abs_section (S_GET_SEGMENT (fixp->fx_addsy))))
14200 sym = fixp->fx_subsy;
14203 if (IS_ELF && sym && S_IS_DEFINED (sym) && !S_IS_EXTERNAL (sym))
14205 /* Resolve size relocation against local symbol to size of
14206 the symbol plus addend. */
14207 valueT value = S_GET_SIZE (sym);
14209 if (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM)
14210 value = bfd_section_size (S_GET_SEGMENT (sym));
14211 if (sym == fixp->fx_subsy)
14214 if (fixp->fx_addsy)
14215 value += S_GET_VALUE (fixp->fx_addsy);
14217 else if (fixp->fx_subsy)
14218 value -= S_GET_VALUE (fixp->fx_subsy);
14219 value += fixp->fx_offset;
14220 if (fixp->fx_r_type == BFD_RELOC_SIZE32
14222 && !fits_in_unsigned_long (value))
14223 as_bad_where (fixp->fx_file, fixp->fx_line,
14224 _("symbol size computation overflow"));
14225 fixp->fx_addsy = NULL;
14226 fixp->fx_subsy = NULL;
14227 md_apply_fix (fixp, (valueT *) &value, NULL);
14230 if (!fixp->fx_addsy || fixp->fx_subsy)
14232 as_bad_where (fixp->fx_file, fixp->fx_line,
14233 "unsupported expression involving @size");
14237 /* Fall through. */
14239 case BFD_RELOC_X86_64_PLT32:
14240 case BFD_RELOC_X86_64_GOT32:
14241 case BFD_RELOC_X86_64_GOTPCREL:
14242 case BFD_RELOC_X86_64_GOTPCRELX:
14243 case BFD_RELOC_X86_64_REX_GOTPCRELX:
14244 case BFD_RELOC_386_PLT32:
14245 case BFD_RELOC_386_GOT32:
14246 case BFD_RELOC_386_GOT32X:
14247 case BFD_RELOC_386_GOTOFF:
14248 case BFD_RELOC_386_GOTPC:
14249 case BFD_RELOC_386_TLS_GD:
14250 case BFD_RELOC_386_TLS_LDM:
14251 case BFD_RELOC_386_TLS_LDO_32:
14252 case BFD_RELOC_386_TLS_IE_32:
14253 case BFD_RELOC_386_TLS_IE:
14254 case BFD_RELOC_386_TLS_GOTIE:
14255 case BFD_RELOC_386_TLS_LE_32:
14256 case BFD_RELOC_386_TLS_LE:
14257 case BFD_RELOC_386_TLS_GOTDESC:
14258 case BFD_RELOC_386_TLS_DESC_CALL:
14259 case BFD_RELOC_X86_64_TLSGD:
14260 case BFD_RELOC_X86_64_TLSLD:
14261 case BFD_RELOC_X86_64_DTPOFF32:
14262 case BFD_RELOC_X86_64_DTPOFF64:
14263 case BFD_RELOC_X86_64_GOTTPOFF:
14264 case BFD_RELOC_X86_64_TPOFF32:
14265 case BFD_RELOC_X86_64_TPOFF64:
14266 case BFD_RELOC_X86_64_GOTOFF64:
14267 case BFD_RELOC_X86_64_GOTPC32:
14268 case BFD_RELOC_X86_64_GOT64:
14269 case BFD_RELOC_X86_64_GOTPCREL64:
14270 case BFD_RELOC_X86_64_GOTPC64:
14271 case BFD_RELOC_X86_64_GOTPLT64:
14272 case BFD_RELOC_X86_64_PLTOFF64:
14273 case BFD_RELOC_X86_64_GOTPC32_TLSDESC:
14274 case BFD_RELOC_X86_64_TLSDESC_CALL:
14275 case BFD_RELOC_RVA:
14276 case BFD_RELOC_VTABLE_ENTRY:
14277 case BFD_RELOC_VTABLE_INHERIT:
14279 case BFD_RELOC_32_SECREL:
14281 code = fixp->fx_r_type;
14283 case BFD_RELOC_X86_64_32S:
14284 if (!fixp->fx_pcrel)
14286 /* Don't turn BFD_RELOC_X86_64_32S into BFD_RELOC_32. */
14287 code = fixp->fx_r_type;
14290 /* Fall through. */
14292 if (fixp->fx_pcrel)
14294 switch (fixp->fx_size)
14297 as_bad_where (fixp->fx_file, fixp->fx_line,
14298 _("can not do %d byte pc-relative relocation"),
14300 code = BFD_RELOC_32_PCREL;
14302 case 1: code = BFD_RELOC_8_PCREL; break;
14303 case 2: code = BFD_RELOC_16_PCREL; break;
14304 case 4: code = BFD_RELOC_32_PCREL; break;
14306 case 8: code = BFD_RELOC_64_PCREL; break;
14312 switch (fixp->fx_size)
14315 as_bad_where (fixp->fx_file, fixp->fx_line,
14316 _("can not do %d byte relocation"),
14318 code = BFD_RELOC_32;
14320 case 1: code = BFD_RELOC_8; break;
14321 case 2: code = BFD_RELOC_16; break;
14322 case 4: code = BFD_RELOC_32; break;
14324 case 8: code = BFD_RELOC_64; break;
14331 if ((code == BFD_RELOC_32
14332 || code == BFD_RELOC_32_PCREL
14333 || code == BFD_RELOC_X86_64_32S)
14335 && fixp->fx_addsy == GOT_symbol)
14338 code = BFD_RELOC_386_GOTPC;
14340 code = BFD_RELOC_X86_64_GOTPC32;
14342 if ((code == BFD_RELOC_64 || code == BFD_RELOC_64_PCREL)
14344 && fixp->fx_addsy == GOT_symbol)
14346 code = BFD_RELOC_X86_64_GOTPC64;
14349 rel = XNEW (arelent);
14350 rel->sym_ptr_ptr = XNEW (asymbol *);
14351 *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
14353 rel->address = fixp->fx_frag->fr_address + fixp->fx_where;
14355 if (!use_rela_relocations)
14357 /* HACK: Since i386 ELF uses Rel instead of Rela, encode the
14358 vtable entry to be used in the relocation's section offset. */
14359 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
14360 rel->address = fixp->fx_offset;
14361 #if defined (OBJ_COFF) && defined (TE_PE)
14362 else if (fixp->fx_addsy && S_IS_WEAK (fixp->fx_addsy))
14363 rel->addend = fixp->fx_addnumber - (S_GET_VALUE (fixp->fx_addsy) * 2);
14368 /* Use the rela in 64bit mode. */
14371 if (disallow_64bit_reloc)
14374 case BFD_RELOC_X86_64_DTPOFF64:
14375 case BFD_RELOC_X86_64_TPOFF64:
14376 case BFD_RELOC_64_PCREL:
14377 case BFD_RELOC_X86_64_GOTOFF64:
14378 case BFD_RELOC_X86_64_GOT64:
14379 case BFD_RELOC_X86_64_GOTPCREL64:
14380 case BFD_RELOC_X86_64_GOTPC64:
14381 case BFD_RELOC_X86_64_GOTPLT64:
14382 case BFD_RELOC_X86_64_PLTOFF64:
14383 as_bad_where (fixp->fx_file, fixp->fx_line,
14384 _("cannot represent relocation type %s in x32 mode"),
14385 bfd_get_reloc_code_name (code));
14391 if (!fixp->fx_pcrel)
14392 rel->addend = fixp->fx_offset;
14396 case BFD_RELOC_X86_64_PLT32:
14397 case BFD_RELOC_X86_64_GOT32:
14398 case BFD_RELOC_X86_64_GOTPCREL:
14399 case BFD_RELOC_X86_64_GOTPCRELX:
14400 case BFD_RELOC_X86_64_REX_GOTPCRELX:
14401 case BFD_RELOC_X86_64_TLSGD:
14402 case BFD_RELOC_X86_64_TLSLD:
14403 case BFD_RELOC_X86_64_GOTTPOFF:
14404 case BFD_RELOC_X86_64_GOTPC32_TLSDESC:
14405 case BFD_RELOC_X86_64_TLSDESC_CALL:
14406 rel->addend = fixp->fx_offset - fixp->fx_size;
14409 rel->addend = (section->vma
14411 + fixp->fx_addnumber
14412 + md_pcrel_from (fixp));
14417 rel->howto = bfd_reloc_type_lookup (stdoutput, code);
14418 if (rel->howto == NULL)
14420 as_bad_where (fixp->fx_file, fixp->fx_line,
14421 _("cannot represent relocation type %s"),
14422 bfd_get_reloc_code_name (code));
14423 /* Set howto to a garbage value so that we can keep going. */
14424 rel->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
14425 gas_assert (rel->howto != NULL);
14431 #include "tc-i386-intel.c"
14434 tc_x86_parse_to_dw2regnum (expressionS *exp)
14436 int saved_naked_reg;
14437 char saved_register_dot;
14439 saved_naked_reg = allow_naked_reg;
14440 allow_naked_reg = 1;
14441 saved_register_dot = register_chars['.'];
14442 register_chars['.'] = '.';
14443 allow_pseudo_reg = 1;
14444 expression_and_evaluate (exp);
14445 allow_pseudo_reg = 0;
14446 register_chars['.'] = saved_register_dot;
14447 allow_naked_reg = saved_naked_reg;
14449 if (exp->X_op == O_register && exp->X_add_number >= 0)
14451 if ((addressT) exp->X_add_number < i386_regtab_size)
14453 exp->X_op = O_constant;
14454 exp->X_add_number = i386_regtab[exp->X_add_number]
14455 .dw2_regnum[flag_code >> 1];
14458 exp->X_op = O_illegal;
14463 tc_x86_frame_initial_instructions (void)
14465 static unsigned int sp_regno[2];
14467 if (!sp_regno[flag_code >> 1])
14469 char *saved_input = input_line_pointer;
14470 char sp[][4] = {"esp", "rsp"};
14473 input_line_pointer = sp[flag_code >> 1];
14474 tc_x86_parse_to_dw2regnum (&exp);
14475 gas_assert (exp.X_op == O_constant);
14476 sp_regno[flag_code >> 1] = exp.X_add_number;
14477 input_line_pointer = saved_input;
14480 cfi_add_CFA_def_cfa (sp_regno[flag_code >> 1], -x86_cie_data_alignment);
14481 cfi_add_CFA_offset (x86_dwarf2_return_column, x86_cie_data_alignment);
14485 x86_dwarf2_addr_size (void)
14487 #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF)
14488 if (x86_elf_abi == X86_64_X32_ABI)
14491 return bfd_arch_bits_per_address (stdoutput) / 8;
14495 i386_elf_section_type (const char *str, size_t len)
14497 if (flag_code == CODE_64BIT
14498 && len == sizeof ("unwind") - 1
14499 && startswith (str, "unwind"))
14500 return SHT_X86_64_UNWIND;
14507 i386_solaris_fix_up_eh_frame (segT sec)
14509 if (flag_code == CODE_64BIT)
14510 elf_section_type (sec) = SHT_X86_64_UNWIND;
14516 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
14520 exp.X_op = O_secrel;
14521 exp.X_add_symbol = symbol;
14522 exp.X_add_number = 0;
14523 emit_expr (&exp, size);
14527 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14528 /* For ELF on x86-64, add support for SHF_X86_64_LARGE. */
14531 x86_64_section_letter (int letter, const char **ptr_msg)
14533 if (flag_code == CODE_64BIT)
14536 return SHF_X86_64_LARGE;
14538 *ptr_msg = _("bad .section directive: want a,l,w,x,M,S,G,T in string");
14541 *ptr_msg = _("bad .section directive: want a,w,x,M,S,G,T in string");
14546 x86_64_section_word (char *str, size_t len)
14548 if (len == 5 && flag_code == CODE_64BIT && startswith (str, "large"))
14549 return SHF_X86_64_LARGE;
14555 handle_large_common (int small ATTRIBUTE_UNUSED)
14557 if (flag_code != CODE_64BIT)
14559 s_comm_internal (0, elf_common_parse);
14560 as_warn (_(".largecomm supported only in 64bit mode, producing .comm"));
14564 static segT lbss_section;
14565 asection *saved_com_section_ptr = elf_com_section_ptr;
14566 asection *saved_bss_section = bss_section;
14568 if (lbss_section == NULL)
14570 flagword applicable;
14571 segT seg = now_seg;
14572 subsegT subseg = now_subseg;
14574 /* The .lbss section is for local .largecomm symbols. */
14575 lbss_section = subseg_new (".lbss", 0);
14576 applicable = bfd_applicable_section_flags (stdoutput);
14577 bfd_set_section_flags (lbss_section, applicable & SEC_ALLOC);
14578 seg_info (lbss_section)->bss = 1;
14580 subseg_set (seg, subseg);
14583 elf_com_section_ptr = &_bfd_elf_large_com_section;
14584 bss_section = lbss_section;
14586 s_comm_internal (0, elf_common_parse);
14588 elf_com_section_ptr = saved_com_section_ptr;
14589 bss_section = saved_bss_section;
14592 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */