1 /* tc-i386.c -- Assemble code for the Intel 80386
2 Copyright (C) 1989-2023 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.
22 Written by Eliot Dresselhaus (eliot@mgm.mit.edu).
23 x86_64 support by Jan Hubicka (jh@suse.cz)
24 VIA PadLock support by Michal Ludvig (mludvig@suse.cz)
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 "gen-sframe.h"
35 #include "elf/x86-64.h"
36 #include "opcodes/i386-init.h"
37 #include "opcodes/i386-mnem.h"
40 #ifndef INFER_ADDR_PREFIX
41 #define INFER_ADDR_PREFIX 1
45 #define DEFAULT_ARCH "i386"
50 #define INLINE __inline__
56 /* Prefixes will be emitted in the order defined below.
57 WAIT_PREFIX must be the first prefix since FWAIT is really is an
58 instruction, and so must come before any prefixes.
59 The preferred prefix order is SEG_PREFIX, ADDR_PREFIX, DATA_PREFIX,
60 REP_PREFIX/HLE_PREFIX, LOCK_PREFIX. */
66 #define HLE_PREFIX REP_PREFIX
67 #define BND_PREFIX REP_PREFIX
69 #define REX_PREFIX 6 /* must come last. */
70 #define MAX_PREFIXES 7 /* max prefixes per opcode */
72 /* we define the syntax here (modulo base,index,scale syntax) */
73 #define REGISTER_PREFIX '%'
74 #define IMMEDIATE_PREFIX '$'
75 #define ABSOLUTE_PREFIX '*'
77 /* these are the instruction mnemonic suffixes in AT&T syntax or
78 memory operand size in Intel syntax. */
79 #define WORD_MNEM_SUFFIX 'w'
80 #define BYTE_MNEM_SUFFIX 'b'
81 #define SHORT_MNEM_SUFFIX 's'
82 #define LONG_MNEM_SUFFIX 'l'
83 #define QWORD_MNEM_SUFFIX 'q'
85 #define END_OF_INSN '\0'
87 #define OPERAND_TYPE_NONE { .bitfield = { .class = ClassNone } }
89 /* This matches the C -> StaticRounding alias in the opcode table. */
90 #define commutative staticrounding
93 'templates' is for grouping together 'template' structures for opcodes
94 of the same name. This is only used for storing the insns in the grand
95 ole hash table of insns.
96 The templates themselves start at START and range up to (but not including)
101 const insn_template
*start
;
102 const insn_template
*end
;
106 /* 386 operand encoding bytes: see 386 book for details of this. */
109 unsigned int regmem
; /* codes register or memory operand */
110 unsigned int reg
; /* codes register operand (or extended opcode) */
111 unsigned int mode
; /* how to interpret regmem & reg */
115 /* x86-64 extension prefix. */
116 typedef int rex_byte
;
118 /* 386 opcode byte to code indirect addressing. */
127 /* x86 arch names, types and features */
130 const char *name
; /* arch name */
131 unsigned int len
:8; /* arch string length */
132 bool skip
:1; /* show_arch should skip this. */
133 enum processor_type type
; /* arch type */
134 i386_cpu_flags enable
; /* cpu feature enable flags */
135 i386_cpu_flags disable
; /* cpu feature disable flags */
139 static void update_code_flag (int, int);
140 static void s_insn (int);
141 static void set_code_flag (int);
142 static void set_16bit_gcc_code_flag (int);
143 static void set_intel_syntax (int);
144 static void set_intel_mnemonic (int);
145 static void set_allow_index_reg (int);
146 static void set_check (int);
147 static void set_cpu_arch (int);
149 static void pe_directive_secrel (int);
150 static void pe_directive_secidx (int);
152 static void signed_cons (int);
153 static char *output_invalid (int c
);
154 static int i386_finalize_immediate (segT
, expressionS
*, i386_operand_type
,
156 static int i386_finalize_displacement (segT
, expressionS
*, i386_operand_type
,
158 static int i386_att_operand (char *);
159 static int i386_intel_operand (char *, int);
160 static int i386_intel_simplify (expressionS
*);
161 static int i386_intel_parse_name (const char *, expressionS
*);
162 static const reg_entry
*parse_register (const char *, char **);
163 static const char *parse_insn (const char *, char *, bool);
164 static char *parse_operands (char *, const char *);
165 static void swap_operands (void);
166 static void swap_2_operands (unsigned int, unsigned int);
167 static enum flag_code
i386_addressing_mode (void);
168 static void optimize_imm (void);
169 static bool optimize_disp (const insn_template
*t
);
170 static const insn_template
*match_template (char);
171 static int check_string (void);
172 static int process_suffix (void);
173 static int check_byte_reg (void);
174 static int check_long_reg (void);
175 static int check_qword_reg (void);
176 static int check_word_reg (void);
177 static int finalize_imm (void);
178 static int process_operands (void);
179 static const reg_entry
*build_modrm_byte (void);
180 static void output_insn (void);
181 static void output_imm (fragS
*, offsetT
);
182 static void output_disp (fragS
*, offsetT
);
184 static void s_bss (int);
186 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
187 static void handle_large_common (int small ATTRIBUTE_UNUSED
);
189 /* GNU_PROPERTY_X86_ISA_1_USED. */
190 static unsigned int x86_isa_1_used
;
191 /* GNU_PROPERTY_X86_FEATURE_2_USED. */
192 static unsigned int x86_feature_2_used
;
193 /* Generate x86 used ISA and feature properties. */
194 static unsigned int x86_used_note
= DEFAULT_X86_USED_NOTE
;
197 static const char *default_arch
= DEFAULT_ARCH
;
199 /* parse_register() returns this when a register alias cannot be used. */
200 static const reg_entry bad_reg
= { "<bad>", OPERAND_TYPE_NONE
, 0, 0,
201 { Dw2Inval
, Dw2Inval
} };
203 static const reg_entry
*reg_eax
;
204 static const reg_entry
*reg_ds
;
205 static const reg_entry
*reg_es
;
206 static const reg_entry
*reg_ss
;
207 static const reg_entry
*reg_st0
;
208 static const reg_entry
*reg_k0
;
213 /* VEX prefix is either 2 byte or 3 byte. EVEX is 4 byte. */
214 unsigned char bytes
[4];
216 /* Destination or source register specifier. */
217 const reg_entry
*register_specifier
;
220 /* 'md_assemble ()' gathers together information and puts it into a
227 const reg_entry
*regs
;
232 no_error
, /* Must be first. */
233 operand_size_mismatch
,
234 operand_type_mismatch
,
235 register_type_mismatch
,
236 number_of_operands_mismatch
,
237 invalid_instruction_suffix
,
239 unsupported_with_intel_mnemonic
,
245 invalid_vsib_address
,
246 invalid_vector_register_set
,
247 invalid_tmm_register_set
,
248 invalid_dest_and_src_register_set
,
249 unsupported_vector_index_register
,
250 unsupported_broadcast
,
253 mask_not_on_destination
,
256 invalid_register_operand
,
261 /* TM holds the template for the insn were currently assembling. */
264 /* SUFFIX holds the instruction size suffix for byte, word, dword
265 or qword, if given. */
268 /* OPCODE_LENGTH holds the number of base opcode bytes. */
269 unsigned char opcode_length
;
271 /* OPERANDS gives the number of given operands. */
272 unsigned int operands
;
274 /* REG_OPERANDS, DISP_OPERANDS, MEM_OPERANDS, IMM_OPERANDS give the number
275 of given register, displacement, memory operands and immediate
277 unsigned int reg_operands
, disp_operands
, mem_operands
, imm_operands
;
279 /* TYPES [i] is the type (see above #defines) which tells us how to
280 use OP[i] for the corresponding operand. */
281 i386_operand_type types
[MAX_OPERANDS
];
283 /* Displacement expression, immediate expression, or register for each
285 union i386_op op
[MAX_OPERANDS
];
287 /* Flags for operands. */
288 unsigned int flags
[MAX_OPERANDS
];
289 #define Operand_PCrel 1
290 #define Operand_Mem 2
291 #define Operand_Signed 4 /* .insn only */
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 /* PREFIX holds all the given prefix opcodes (usually null).
307 PREFIXES is the number of prefix opcodes. */
308 unsigned int prefixes
;
309 unsigned char prefix
[MAX_PREFIXES
];
311 /* .insn allows for reserved opcode spaces. */
312 unsigned char insn_opcode_space
;
314 /* .insn also allows (requires) specifying immediate size. */
315 unsigned char imm_bits
[MAX_OPERANDS
];
317 /* Register is in low 3 bits of opcode. */
320 /* The operand to a branch insn indicates an absolute branch. */
323 /* The operand to a branch insn indicates a far branch. */
326 /* There is a memory operand of (%dx) which should be only used
327 with input/output instructions. */
328 bool input_output_operand
;
330 /* Extended states. */
338 xstate_ymm
= 1 << 2 | xstate_xmm
,
340 xstate_zmm
= 1 << 3 | xstate_ymm
,
343 /* Use MASK state. */
347 /* Has GOTPC or TLS relocation. */
348 bool has_gotpc_tls_reloc
;
350 /* RM and SIB are the modrm byte and the sib byte where the
351 addressing modes of this insn are encoded. */
358 /* Masking attributes.
360 The struct describes masking, applied to OPERAND in the instruction.
361 REG is a pointer to the corresponding mask register. ZEROING tells
362 whether merging or zeroing mask is used. */
363 struct Mask_Operation
365 const reg_entry
*reg
;
366 unsigned int zeroing
;
367 /* The operand where this operation is associated. */
368 unsigned int operand
;
371 /* Rounding control and SAE attributes. */
383 /* In Intel syntax the operand modifier form is supposed to be used, but
384 we continue to accept the immediate forms as well. */
388 /* Broadcasting attributes.
390 The struct describes broadcasting, applied to OPERAND. TYPE is
391 expresses the broadcast factor. */
392 struct Broadcast_Operation
394 /* Type of broadcast: {1to2}, {1to4}, {1to8}, {1to16} or {1to32}. */
397 /* Index of broadcasted operand. */
398 unsigned int operand
;
400 /* Number of bytes to broadcast. */
404 /* Compressed disp8*N attribute. */
405 unsigned int memshift
;
407 /* Prefer load or store in encoding. */
410 dir_encoding_default
= 0,
416 /* Prefer 8bit, 16bit, 32bit displacement in encoding. */
419 disp_encoding_default
= 0,
425 /* Prefer the REX byte in encoding. */
428 /* Disable instruction size optimization. */
431 /* How to encode vector instructions. */
434 vex_encoding_default
= 0,
442 const char *rep_prefix
;
445 const char *hle_prefix
;
447 /* Have BND prefix. */
448 const char *bnd_prefix
;
450 /* Have NOTRACK prefix. */
451 const char *notrack_prefix
;
454 enum i386_error error
;
457 typedef struct _i386_insn i386_insn
;
459 /* Link RC type with corresponding string, that'll be looked for in
468 static const struct RC_name RC_NamesTable
[] =
470 { rne
, STRING_COMMA_LEN ("rn-sae") },
471 { rd
, STRING_COMMA_LEN ("rd-sae") },
472 { ru
, STRING_COMMA_LEN ("ru-sae") },
473 { rz
, STRING_COMMA_LEN ("rz-sae") },
474 { saeonly
, STRING_COMMA_LEN ("sae") },
477 /* To be indexed by segment register number. */
478 static const unsigned char i386_seg_prefixes
[] = {
487 /* List of chars besides those in app.c:symbol_chars that can start an
488 operand. Used to prevent the scrubber eating vital white-space. */
489 const char extra_symbol_chars
[] = "*%-([{}"
498 #if ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) \
499 && !defined (TE_GNU) \
500 && !defined (TE_LINUX) \
501 && !defined (TE_Haiku) \
502 && !defined (TE_FreeBSD) \
503 && !defined (TE_DragonFly) \
504 && !defined (TE_NetBSD))
505 /* This array holds the chars that always start a comment. If the
506 pre-processor is disabled, these aren't very useful. The option
507 --divide will remove '/' from this list. */
508 const char *i386_comment_chars
= "#/";
509 #define SVR4_COMMENT_CHARS 1
510 #define PREFIX_SEPARATOR '\\'
513 const char *i386_comment_chars
= "#";
514 #define PREFIX_SEPARATOR '/'
517 /* This array holds the chars that only start a comment at the beginning of
518 a line. If the line seems to have the form '# 123 filename'
519 .line and .file directives will appear in the pre-processed output.
520 Note that input_file.c hand checks for '#' at the beginning of the
521 first line of the input file. This is because the compiler outputs
522 #NO_APP at the beginning of its output.
523 Also note that comments started like this one will always work if
524 '/' isn't otherwise defined. */
525 const char line_comment_chars
[] = "#/";
527 const char line_separator_chars
[] = ";";
529 /* Chars that can be used to separate mant from exp in floating point
531 const char EXP_CHARS
[] = "eE";
533 /* Chars that mean this number is a floating point constant
536 const char FLT_CHARS
[] = "fFdDxXhHbB";
538 /* Tables for lexical analysis. */
539 static char mnemonic_chars
[256];
540 static char register_chars
[256];
541 static char operand_chars
[256];
543 /* Lexical macros. */
544 #define is_operand_char(x) (operand_chars[(unsigned char) x])
545 #define is_register_char(x) (register_chars[(unsigned char) x])
546 #define is_space_char(x) ((x) == ' ')
548 /* All non-digit non-letter characters that may occur in an operand and
549 which aren't already in extra_symbol_chars[]. */
550 static const char operand_special_chars
[] = "$+,)._~/<>|&^!=:@]";
552 /* md_assemble() always leaves the strings it's passed unaltered. To
553 effect this we maintain a stack of saved characters that we've smashed
554 with '\0's (indicating end of strings for various sub-fields of the
555 assembler instruction). */
556 static char save_stack
[32];
557 static char *save_stack_p
;
558 #define END_STRING_AND_SAVE(s) \
559 do { *save_stack_p++ = *(s); *(s) = '\0'; } while (0)
560 #define RESTORE_END_STRING(s) \
561 do { *(s) = *--save_stack_p; } while (0)
563 /* The instruction we're assembling. */
566 /* Possible templates for current insn. */
567 static const templates
*current_templates
;
569 /* Per instruction expressionS buffers: max displacements & immediates. */
570 static expressionS disp_expressions
[MAX_MEMORY_OPERANDS
];
571 static expressionS im_expressions
[MAX_IMMEDIATE_OPERANDS
];
573 /* Current operand we are working on. */
574 static int this_operand
= -1;
576 /* Are we processing a .insn directive? */
577 #define dot_insn() (i.tm.mnem_off == MN__insn)
579 /* We support four different modes. FLAG_CODE variable is used to distinguish
587 static enum flag_code flag_code
;
588 static unsigned int object_64bit
;
589 static unsigned int disallow_64bit_reloc
;
590 static int use_rela_relocations
= 0;
591 /* __tls_get_addr/___tls_get_addr symbol for TLS. */
592 static const char *tls_get_addr
;
594 #if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \
595 || defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \
596 || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O))
598 /* The ELF ABI to use. */
606 static enum x86_elf_abi x86_elf_abi
= I386_ABI
;
609 #if defined (TE_PE) || defined (TE_PEP)
610 /* Use big object file format. */
611 static int use_big_obj
= 0;
614 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
615 /* 1 if generating code for a shared library. */
616 static int shared
= 0;
618 unsigned int x86_sframe_cfa_sp_reg
;
619 /* The other CFA base register for SFrame stack trace info. */
620 unsigned int x86_sframe_cfa_fp_reg
;
621 unsigned int x86_sframe_cfa_ra_reg
;
625 /* 1 for intel syntax,
627 static int intel_syntax
= 0;
629 static enum x86_64_isa
631 amd64
= 1, /* AMD64 ISA. */
632 intel64
/* Intel64 ISA. */
635 /* 1 for intel mnemonic,
636 0 if att mnemonic. */
637 static int intel_mnemonic
= !SYSV386_COMPAT
;
639 /* 1 if pseudo registers are permitted. */
640 static int allow_pseudo_reg
= 0;
642 /* 1 if register prefix % not required. */
643 static int allow_naked_reg
= 0;
645 /* 1 if the assembler should add BND prefix for all control-transferring
646 instructions supporting it, even if this prefix wasn't specified
648 static int add_bnd_prefix
= 0;
650 /* 1 if pseudo index register, eiz/riz, is allowed . */
651 static int allow_index_reg
= 0;
653 /* 1 if the assembler should ignore LOCK prefix, even if it was
654 specified explicitly. */
655 static int omit_lock_prefix
= 0;
657 /* 1 if the assembler should encode lfence, mfence, and sfence as
658 "lock addl $0, (%{re}sp)". */
659 static int avoid_fence
= 0;
661 /* 1 if lfence should be inserted after every load. */
662 static int lfence_after_load
= 0;
664 /* Non-zero if lfence should be inserted before indirect branch. */
665 static enum lfence_before_indirect_branch_kind
667 lfence_branch_none
= 0,
668 lfence_branch_register
,
669 lfence_branch_memory
,
672 lfence_before_indirect_branch
;
674 /* Non-zero if lfence should be inserted before ret. */
675 static enum lfence_before_ret_kind
677 lfence_before_ret_none
= 0,
678 lfence_before_ret_not
,
679 lfence_before_ret_or
,
680 lfence_before_ret_shl
684 /* Types of previous instruction is .byte or prefix. */
699 /* 1 if the assembler should generate relax relocations. */
701 static int generate_relax_relocations
702 = DEFAULT_GENERATE_X86_RELAX_RELOCATIONS
;
704 static enum check_kind
710 sse_check
, operand_check
= check_warning
;
712 /* Non-zero if branches should be aligned within power of 2 boundary. */
713 static int align_branch_power
= 0;
715 /* Types of branches to align. */
716 enum align_branch_kind
718 align_branch_none
= 0,
719 align_branch_jcc
= 1,
720 align_branch_fused
= 2,
721 align_branch_jmp
= 3,
722 align_branch_call
= 4,
723 align_branch_indirect
= 5,
727 /* Type bits of branches to align. */
728 enum align_branch_bit
730 align_branch_jcc_bit
= 1 << align_branch_jcc
,
731 align_branch_fused_bit
= 1 << align_branch_fused
,
732 align_branch_jmp_bit
= 1 << align_branch_jmp
,
733 align_branch_call_bit
= 1 << align_branch_call
,
734 align_branch_indirect_bit
= 1 << align_branch_indirect
,
735 align_branch_ret_bit
= 1 << align_branch_ret
738 static unsigned int align_branch
= (align_branch_jcc_bit
739 | align_branch_fused_bit
740 | align_branch_jmp_bit
);
742 /* Types of condition jump used by macro-fusion. */
745 mf_jcc_jo
= 0, /* base opcode 0x70 */
746 mf_jcc_jc
, /* base opcode 0x72 */
747 mf_jcc_je
, /* base opcode 0x74 */
748 mf_jcc_jna
, /* base opcode 0x76 */
749 mf_jcc_js
, /* base opcode 0x78 */
750 mf_jcc_jp
, /* base opcode 0x7a */
751 mf_jcc_jl
, /* base opcode 0x7c */
752 mf_jcc_jle
, /* base opcode 0x7e */
755 /* Types of compare flag-modifying insntructions used by macro-fusion. */
758 mf_cmp_test_and
, /* test/cmp */
759 mf_cmp_alu_cmp
, /* add/sub/cmp */
760 mf_cmp_incdec
/* inc/dec */
763 /* The maximum padding size for fused jcc. CMP like instruction can
764 be 9 bytes and jcc can be 6 bytes. Leave room just in case for
766 #define MAX_FUSED_JCC_PADDING_SIZE 20
768 /* The maximum number of prefixes added for an instruction. */
769 static unsigned int align_branch_prefix_size
= 5;
772 1. Clear the REX_W bit with register operand if possible.
773 2. Above plus use 128bit vector instruction to clear the full vector
776 static int optimize
= 0;
779 1. Clear the REX_W bit with register operand if possible.
780 2. Above plus use 128bit vector instruction to clear the full vector
782 3. Above plus optimize "test{q,l,w} $imm8,%r{64,32,16}" to
785 static int optimize_for_space
= 0;
787 /* Register prefix used for error message. */
788 static const char *register_prefix
= "%";
790 /* Used in 16 bit gcc mode to add an l suffix to call, ret, enter,
791 leave, push, and pop instructions so that gcc has the same stack
792 frame as in 32 bit mode. */
793 static char stackop_size
= '\0';
795 /* Non-zero to optimize code alignment. */
796 int optimize_align_code
= 1;
798 /* Non-zero to quieten some warnings. */
799 static int quiet_warnings
= 0;
801 /* Guard to avoid repeated warnings about non-16-bit code on 16-bit CPUs. */
802 static bool pre_386_16bit_warned
;
805 static const char *cpu_arch_name
= NULL
;
806 static char *cpu_sub_arch_name
= NULL
;
808 /* CPU feature flags. */
809 static i386_cpu_flags cpu_arch_flags
= CPU_UNKNOWN_FLAGS
;
811 /* If we have selected a cpu we are generating instructions for. */
812 static int cpu_arch_tune_set
= 0;
814 /* Cpu we are generating instructions for. */
815 enum processor_type cpu_arch_tune
= PROCESSOR_UNKNOWN
;
817 /* CPU feature flags of cpu we are generating instructions for. */
818 static i386_cpu_flags cpu_arch_tune_flags
;
820 /* CPU instruction set architecture used. */
821 enum processor_type cpu_arch_isa
= PROCESSOR_UNKNOWN
;
823 /* CPU feature flags of instruction set architecture used. */
824 i386_cpu_flags cpu_arch_isa_flags
;
826 /* If set, conditional jumps are not automatically promoted to handle
827 larger than a byte offset. */
828 static bool no_cond_jump_promotion
= false;
830 /* This will be set from an expression parser hook if there's any
831 applicable operator involved in an expression. */
834 expr_operator_present
,
838 /* Encode SSE instructions with VEX prefix. */
839 static unsigned int sse2avx
;
841 /* Encode aligned vector move as unaligned vector move. */
842 static unsigned int use_unaligned_vector_move
;
844 /* Encode scalar AVX instructions with specific vector length. */
851 /* Encode VEX WIG instructions with specific vex.w. */
858 /* Encode scalar EVEX LIG instructions with specific vector length. */
866 /* Encode EVEX WIG instructions with specific evex.w. */
873 /* Value to encode in EVEX RC bits, for SAE-only instructions. */
874 static enum rc_type evexrcig
= rne
;
876 /* Pre-defined "_GLOBAL_OFFSET_TABLE_". */
877 static symbolS
*GOT_symbol
;
879 /* The dwarf2 return column, adjusted for 32 or 64 bit. */
880 unsigned int x86_dwarf2_return_column
;
882 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
883 int x86_cie_data_alignment
;
885 /* Interface to relax_segment.
886 There are 3 major relax states for 386 jump insns because the
887 different types of jumps add different sizes to frags when we're
888 figuring out what sort of jump to choose to reach a given label.
890 BRANCH_PADDING, BRANCH_PREFIX and FUSED_JCC_PADDING are used to align
891 branches which are handled by md_estimate_size_before_relax() and
892 i386_generic_table_relax_frag(). */
895 #define UNCOND_JUMP 0
897 #define COND_JUMP86 2
898 #define BRANCH_PADDING 3
899 #define BRANCH_PREFIX 4
900 #define FUSED_JCC_PADDING 5
905 #define SMALL16 (SMALL | CODE16)
907 #define BIG16 (BIG | CODE16)
911 #define INLINE __inline__
917 #define ENCODE_RELAX_STATE(type, size) \
918 ((relax_substateT) (((type) << 2) | (size)))
919 #define TYPE_FROM_RELAX_STATE(s) \
921 #define DISP_SIZE_FROM_RELAX_STATE(s) \
922 ((((s) & 3) == BIG ? 4 : (((s) & 3) == BIG16 ? 2 : 1)))
924 /* This table is used by relax_frag to promote short jumps to long
925 ones where necessary. SMALL (short) jumps may be promoted to BIG
926 (32 bit long) ones, and SMALL16 jumps to BIG16 (16 bit long). We
927 don't allow a short jump in a 32 bit code segment to be promoted to
928 a 16 bit offset jump because it's slower (requires data size
929 prefix), and doesn't work, unless the destination is in the bottom
930 64k of the code segment (The top 16 bits of eip are zeroed). */
932 const relax_typeS md_relax_table
[] =
935 1) most positive reach of this state,
936 2) most negative reach of this state,
937 3) how many bytes this mode will have in the variable part of the frag
938 4) which index into the table to try if we can't fit into this one. */
940 /* UNCOND_JUMP states. */
941 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (UNCOND_JUMP
, BIG
)},
942 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (UNCOND_JUMP
, BIG16
)},
943 /* dword jmp adds 4 bytes to frag:
944 0 extra opcode bytes, 4 displacement bytes. */
946 /* word jmp adds 2 byte2 to frag:
947 0 extra opcode bytes, 2 displacement bytes. */
950 /* COND_JUMP states. */
951 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP
, BIG
)},
952 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP
, BIG16
)},
953 /* dword conditionals adds 5 bytes to frag:
954 1 extra opcode byte, 4 displacement bytes. */
956 /* word conditionals add 3 bytes to frag:
957 1 extra opcode byte, 2 displacement bytes. */
960 /* COND_JUMP86 states. */
961 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP86
, BIG
)},
962 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP86
, BIG16
)},
963 /* dword conditionals adds 5 bytes to frag:
964 1 extra opcode byte, 4 displacement bytes. */
966 /* word conditionals add 4 bytes to frag:
967 1 displacement byte and a 3 byte long branch insn. */
971 #define ARCH(n, t, f, s) \
972 { STRING_COMMA_LEN (#n), s, PROCESSOR_ ## t, CPU_ ## f ## _FLAGS, \
974 #define SUBARCH(n, e, d, s) \
975 { STRING_COMMA_LEN (#n), s, PROCESSOR_NONE, CPU_ ## e ## _FLAGS, \
976 CPU_ ## d ## _FLAGS }
978 static const arch_entry cpu_arch
[] =
980 /* Do not replace the first two entries - i386_target_format() and
981 set_cpu_arch() rely on them being there in this order. */
982 ARCH (generic32
, GENERIC32
, GENERIC32
, false),
983 ARCH (generic64
, GENERIC64
, GENERIC64
, false),
984 ARCH (i8086
, UNKNOWN
, NONE
, false),
985 ARCH (i186
, UNKNOWN
, 186, false),
986 ARCH (i286
, UNKNOWN
, 286, false),
987 ARCH (i386
, I386
, 386, false),
988 ARCH (i486
, I486
, 486, false),
989 ARCH (i586
, PENTIUM
, 586, false),
990 ARCH (i686
, PENTIUMPRO
, 686, false),
991 ARCH (pentium
, PENTIUM
, 586, false),
992 ARCH (pentiumpro
, PENTIUMPRO
, PENTIUMPRO
, false),
993 ARCH (pentiumii
, PENTIUMPRO
, P2
, false),
994 ARCH (pentiumiii
, PENTIUMPRO
, P3
, false),
995 ARCH (pentium4
, PENTIUM4
, P4
, false),
996 ARCH (prescott
, NOCONA
, CORE
, false),
997 ARCH (nocona
, NOCONA
, NOCONA
, false),
998 ARCH (yonah
, CORE
, CORE
, true),
999 ARCH (core
, CORE
, CORE
, false),
1000 ARCH (merom
, CORE2
, CORE2
, true),
1001 ARCH (core2
, CORE2
, CORE2
, false),
1002 ARCH (corei7
, COREI7
, COREI7
, false),
1003 ARCH (iamcu
, IAMCU
, IAMCU
, false),
1004 ARCH (k6
, K6
, K6
, false),
1005 ARCH (k6_2
, K6
, K6_2
, false),
1006 ARCH (athlon
, ATHLON
, ATHLON
, false),
1007 ARCH (sledgehammer
, K8
, K8
, true),
1008 ARCH (opteron
, K8
, K8
, false),
1009 ARCH (k8
, K8
, K8
, false),
1010 ARCH (amdfam10
, AMDFAM10
, AMDFAM10
, false),
1011 ARCH (bdver1
, BD
, BDVER1
, false),
1012 ARCH (bdver2
, BD
, BDVER2
, false),
1013 ARCH (bdver3
, BD
, BDVER3
, false),
1014 ARCH (bdver4
, BD
, BDVER4
, false),
1015 ARCH (znver1
, ZNVER
, ZNVER1
, false),
1016 ARCH (znver2
, ZNVER
, ZNVER2
, false),
1017 ARCH (znver3
, ZNVER
, ZNVER3
, false),
1018 ARCH (znver4
, ZNVER
, ZNVER4
, false),
1019 ARCH (btver1
, BT
, BTVER1
, false),
1020 ARCH (btver2
, BT
, BTVER2
, false),
1022 SUBARCH (8087, 8087, ANY_8087
, false),
1023 SUBARCH (87, NONE
, ANY_8087
, false), /* Disable only! */
1024 SUBARCH (287, 287, ANY_287
, false),
1025 SUBARCH (387, 387, ANY_387
, false),
1026 SUBARCH (687, 687, ANY_687
, false),
1027 SUBARCH (cmov
, CMOV
, CMOV
, false),
1028 SUBARCH (fxsr
, FXSR
, ANY_FXSR
, false),
1029 SUBARCH (mmx
, MMX
, ANY_MMX
, false),
1030 SUBARCH (sse
, SSE
, ANY_SSE
, false),
1031 SUBARCH (sse2
, SSE2
, ANY_SSE2
, false),
1032 SUBARCH (sse3
, SSE3
, ANY_SSE3
, false),
1033 SUBARCH (sse4a
, SSE4A
, ANY_SSE4A
, false),
1034 SUBARCH (ssse3
, SSSE3
, ANY_SSSE3
, false),
1035 SUBARCH (sse4
.1
, SSE4_1
, ANY_SSE4_1
, false),
1036 SUBARCH (sse4
.2
, SSE4_2
, ANY_SSE4_2
, false),
1037 SUBARCH (sse4
, SSE4_2
, ANY_SSE4_1
, false),
1038 SUBARCH (avx
, AVX
, ANY_AVX
, false),
1039 SUBARCH (avx2
, AVX2
, ANY_AVX2
, false),
1040 SUBARCH (avx512f
, AVX512F
, ANY_AVX512F
, false),
1041 SUBARCH (avx512cd
, AVX512CD
, ANY_AVX512CD
, false),
1042 SUBARCH (avx512er
, AVX512ER
, ANY_AVX512ER
, false),
1043 SUBARCH (avx512pf
, AVX512PF
, ANY_AVX512PF
, false),
1044 SUBARCH (avx512dq
, AVX512DQ
, ANY_AVX512DQ
, false),
1045 SUBARCH (avx512bw
, AVX512BW
, ANY_AVX512BW
, false),
1046 SUBARCH (avx512vl
, AVX512VL
, ANY_AVX512VL
, false),
1047 SUBARCH (monitor
, MONITOR
, MONITOR
, false),
1048 SUBARCH (vmx
, VMX
, ANY_VMX
, false),
1049 SUBARCH (vmfunc
, VMFUNC
, ANY_VMFUNC
, false),
1050 SUBARCH (smx
, SMX
, SMX
, false),
1051 SUBARCH (xsave
, XSAVE
, ANY_XSAVE
, false),
1052 SUBARCH (xsaveopt
, XSAVEOPT
, ANY_XSAVEOPT
, false),
1053 SUBARCH (xsavec
, XSAVEC
, ANY_XSAVEC
, false),
1054 SUBARCH (xsaves
, XSAVES
, ANY_XSAVES
, false),
1055 SUBARCH (aes
, AES
, ANY_AES
, false),
1056 SUBARCH (pclmul
, PCLMUL
, ANY_PCLMUL
, false),
1057 SUBARCH (clmul
, PCLMUL
, ANY_PCLMUL
, true),
1058 SUBARCH (fsgsbase
, FSGSBASE
, FSGSBASE
, false),
1059 SUBARCH (rdrnd
, RDRND
, RDRND
, false),
1060 SUBARCH (f16c
, F16C
, ANY_F16C
, false),
1061 SUBARCH (bmi2
, BMI2
, BMI2
, false),
1062 SUBARCH (fma
, FMA
, ANY_FMA
, false),
1063 SUBARCH (fma4
, FMA4
, ANY_FMA4
, false),
1064 SUBARCH (xop
, XOP
, ANY_XOP
, false),
1065 SUBARCH (lwp
, LWP
, ANY_LWP
, false),
1066 SUBARCH (movbe
, MOVBE
, MOVBE
, false),
1067 SUBARCH (cx16
, CX16
, CX16
, false),
1068 SUBARCH (lahf_sahf
, LAHF_SAHF
, LAHF_SAHF
, false),
1069 SUBARCH (ept
, EPT
, ANY_EPT
, false),
1070 SUBARCH (lzcnt
, LZCNT
, LZCNT
, false),
1071 SUBARCH (popcnt
, POPCNT
, POPCNT
, false),
1072 SUBARCH (hle
, HLE
, HLE
, false),
1073 SUBARCH (rtm
, RTM
, ANY_RTM
, false),
1074 SUBARCH (tsx
, TSX
, TSX
, false),
1075 SUBARCH (invpcid
, INVPCID
, INVPCID
, false),
1076 SUBARCH (clflush
, CLFLUSH
, CLFLUSH
, false),
1077 SUBARCH (nop
, NOP
, NOP
, false),
1078 SUBARCH (syscall
, SYSCALL
, SYSCALL
, false),
1079 SUBARCH (rdtscp
, RDTSCP
, RDTSCP
, false),
1080 SUBARCH (3dnow
, 3DNOW
, ANY_3DNOW
, false),
1081 SUBARCH (3dnowa
, 3DNOWA
, ANY_3DNOWA
, false),
1082 SUBARCH (padlock
, PADLOCK
, PADLOCK
, false),
1083 SUBARCH (pacifica
, SVME
, ANY_SVME
, true),
1084 SUBARCH (svme
, SVME
, ANY_SVME
, false),
1085 SUBARCH (abm
, ABM
, ABM
, false),
1086 SUBARCH (bmi
, BMI
, BMI
, false),
1087 SUBARCH (tbm
, TBM
, TBM
, false),
1088 SUBARCH (adx
, ADX
, ADX
, false),
1089 SUBARCH (rdseed
, RDSEED
, RDSEED
, false),
1090 SUBARCH (prfchw
, PRFCHW
, PRFCHW
, false),
1091 SUBARCH (smap
, SMAP
, SMAP
, false),
1092 SUBARCH (mpx
, MPX
, ANY_MPX
, false),
1093 SUBARCH (sha
, SHA
, ANY_SHA
, false),
1094 SUBARCH (clflushopt
, CLFLUSHOPT
, CLFLUSHOPT
, false),
1095 SUBARCH (prefetchwt1
, PREFETCHWT1
, PREFETCHWT1
, false),
1096 SUBARCH (se1
, SE1
, SE1
, false),
1097 SUBARCH (clwb
, CLWB
, CLWB
, false),
1098 SUBARCH (avx512ifma
, AVX512IFMA
, ANY_AVX512IFMA
, false),
1099 SUBARCH (avx512vbmi
, AVX512VBMI
, ANY_AVX512VBMI
, false),
1100 SUBARCH (avx512_4fmaps
, AVX512_4FMAPS
, ANY_AVX512_4FMAPS
, false),
1101 SUBARCH (avx512_4vnniw
, AVX512_4VNNIW
, ANY_AVX512_4VNNIW
, false),
1102 SUBARCH (avx512_vpopcntdq
, AVX512_VPOPCNTDQ
, ANY_AVX512_VPOPCNTDQ
, false),
1103 SUBARCH (avx512_vbmi2
, AVX512_VBMI2
, ANY_AVX512_VBMI2
, false),
1104 SUBARCH (avx512_vnni
, AVX512_VNNI
, ANY_AVX512_VNNI
, false),
1105 SUBARCH (avx512_bitalg
, AVX512_BITALG
, ANY_AVX512_BITALG
, false),
1106 SUBARCH (avx_vnni
, AVX_VNNI
, ANY_AVX_VNNI
, false),
1107 SUBARCH (clzero
, CLZERO
, CLZERO
, false),
1108 SUBARCH (mwaitx
, MWAITX
, MWAITX
, false),
1109 SUBARCH (ospke
, OSPKE
, ANY_OSPKE
, false),
1110 SUBARCH (rdpid
, RDPID
, RDPID
, false),
1111 SUBARCH (ptwrite
, PTWRITE
, PTWRITE
, false),
1112 SUBARCH (ibt
, IBT
, IBT
, false),
1113 SUBARCH (shstk
, SHSTK
, SHSTK
, false),
1114 SUBARCH (gfni
, GFNI
, ANY_GFNI
, false),
1115 SUBARCH (vaes
, VAES
, ANY_VAES
, false),
1116 SUBARCH (vpclmulqdq
, VPCLMULQDQ
, ANY_VPCLMULQDQ
, false),
1117 SUBARCH (wbnoinvd
, WBNOINVD
, WBNOINVD
, false),
1118 SUBARCH (pconfig
, PCONFIG
, PCONFIG
, false),
1119 SUBARCH (waitpkg
, WAITPKG
, WAITPKG
, false),
1120 SUBARCH (cldemote
, CLDEMOTE
, CLDEMOTE
, false),
1121 SUBARCH (amx_int8
, AMX_INT8
, ANY_AMX_INT8
, false),
1122 SUBARCH (amx_bf16
, AMX_BF16
, ANY_AMX_BF16
, false),
1123 SUBARCH (amx_fp16
, AMX_FP16
, ANY_AMX_FP16
, false),
1124 SUBARCH (amx_complex
, AMX_COMPLEX
, ANY_AMX_COMPLEX
, false),
1125 SUBARCH (amx_tile
, AMX_TILE
, ANY_AMX_TILE
, false),
1126 SUBARCH (movdiri
, MOVDIRI
, MOVDIRI
, false),
1127 SUBARCH (movdir64b
, MOVDIR64B
, MOVDIR64B
, false),
1128 SUBARCH (avx512_bf16
, AVX512_BF16
, ANY_AVX512_BF16
, false),
1129 SUBARCH (avx512_vp2intersect
, AVX512_VP2INTERSECT
,
1130 ANY_AVX512_VP2INTERSECT
, false),
1131 SUBARCH (tdx
, TDX
, TDX
, false),
1132 SUBARCH (enqcmd
, ENQCMD
, ENQCMD
, false),
1133 SUBARCH (serialize
, SERIALIZE
, SERIALIZE
, false),
1134 SUBARCH (rdpru
, RDPRU
, RDPRU
, false),
1135 SUBARCH (mcommit
, MCOMMIT
, MCOMMIT
, false),
1136 SUBARCH (sev_es
, SEV_ES
, ANY_SEV_ES
, false),
1137 SUBARCH (tsxldtrk
, TSXLDTRK
, ANY_TSXLDTRK
, false),
1138 SUBARCH (kl
, KL
, ANY_KL
, false),
1139 SUBARCH (widekl
, WIDEKL
, ANY_WIDEKL
, false),
1140 SUBARCH (uintr
, UINTR
, UINTR
, false),
1141 SUBARCH (hreset
, HRESET
, HRESET
, false),
1142 SUBARCH (avx512_fp16
, AVX512_FP16
, ANY_AVX512_FP16
, false),
1143 SUBARCH (prefetchi
, PREFETCHI
, PREFETCHI
, false),
1144 SUBARCH (avx_ifma
, AVX_IFMA
, ANY_AVX_IFMA
, false),
1145 SUBARCH (avx_vnni_int8
, AVX_VNNI_INT8
, ANY_AVX_VNNI_INT8
, false),
1146 SUBARCH (cmpccxadd
, CMPCCXADD
, CMPCCXADD
, false),
1147 SUBARCH (wrmsrns
, WRMSRNS
, WRMSRNS
, false),
1148 SUBARCH (msrlist
, MSRLIST
, MSRLIST
, false),
1149 SUBARCH (avx_ne_convert
, AVX_NE_CONVERT
, ANY_AVX_NE_CONVERT
, false),
1150 SUBARCH (rao_int
, RAO_INT
, RAO_INT
, false),
1151 SUBARCH (rmpquery
, RMPQUERY
, ANY_RMPQUERY
, false),
1152 SUBARCH (fred
, FRED
, ANY_FRED
, false),
1153 SUBARCH (lkgs
, LKGS
, ANY_LKGS
, false),
1160 /* Like s_lcomm_internal in gas/read.c but the alignment string
1161 is allowed to be optional. */
1164 pe_lcomm_internal (int needs_align
, symbolS
*symbolP
, addressT size
)
1171 && *input_line_pointer
== ',')
1173 align
= parse_align (needs_align
- 1);
1175 if (align
== (addressT
) -1)
1190 bss_alloc (symbolP
, size
, align
);
1195 pe_lcomm (int needs_align
)
1197 s_comm_internal (needs_align
* 2, pe_lcomm_internal
);
1201 const pseudo_typeS md_pseudo_table
[] =
1203 #if !defined(OBJ_AOUT) && !defined(USE_ALIGN_PTWO)
1204 {"align", s_align_bytes
, 0},
1206 {"align", s_align_ptwo
, 0},
1208 {"arch", set_cpu_arch
, 0},
1212 {"lcomm", pe_lcomm
, 1},
1214 {"ffloat", float_cons
, 'f'},
1215 {"dfloat", float_cons
, 'd'},
1216 {"tfloat", float_cons
, 'x'},
1217 {"hfloat", float_cons
, 'h'},
1218 {"bfloat16", float_cons
, 'b'},
1220 {"slong", signed_cons
, 4},
1221 {"insn", s_insn
, 0},
1222 {"noopt", s_ignore
, 0},
1223 {"optim", s_ignore
, 0},
1224 {"code16gcc", set_16bit_gcc_code_flag
, CODE_16BIT
},
1225 {"code16", set_code_flag
, CODE_16BIT
},
1226 {"code32", set_code_flag
, CODE_32BIT
},
1228 {"code64", set_code_flag
, CODE_64BIT
},
1230 {"intel_syntax", set_intel_syntax
, 1},
1231 {"att_syntax", set_intel_syntax
, 0},
1232 {"intel_mnemonic", set_intel_mnemonic
, 1},
1233 {"att_mnemonic", set_intel_mnemonic
, 0},
1234 {"allow_index_reg", set_allow_index_reg
, 1},
1235 {"disallow_index_reg", set_allow_index_reg
, 0},
1236 {"sse_check", set_check
, 0},
1237 {"operand_check", set_check
, 1},
1238 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
1239 {"largecomm", handle_large_common
, 0},
1241 {"file", dwarf2_directive_file
, 0},
1242 {"loc", dwarf2_directive_loc
, 0},
1243 {"loc_mark_labels", dwarf2_directive_loc_mark_labels
, 0},
1246 {"secrel32", pe_directive_secrel
, 0},
1247 {"secidx", pe_directive_secidx
, 0},
1252 /* For interface with expression (). */
1253 extern char *input_line_pointer
;
1255 /* Hash table for instruction mnemonic lookup. */
1256 static htab_t op_hash
;
1258 /* Hash table for register lookup. */
1259 static htab_t reg_hash
;
1261 /* Various efficient no-op patterns for aligning code labels.
1262 Note: Don't try to assemble the instructions in the comments.
1263 0L and 0w are not legal. */
1264 static const unsigned char f32_1
[] =
1266 static const unsigned char f32_2
[] =
1267 {0x66,0x90}; /* xchg %ax,%ax */
1268 static const unsigned char f32_3
[] =
1269 {0x8d,0x76,0x00}; /* leal 0(%esi),%esi */
1270 static const unsigned char f32_4
[] =
1271 {0x8d,0x74,0x26,0x00}; /* leal 0(%esi,1),%esi */
1272 static const unsigned char f32_6
[] =
1273 {0x8d,0xb6,0x00,0x00,0x00,0x00}; /* leal 0L(%esi),%esi */
1274 static const unsigned char f32_7
[] =
1275 {0x8d,0xb4,0x26,0x00,0x00,0x00,0x00}; /* leal 0L(%esi,1),%esi */
1276 static const unsigned char f16_3
[] =
1277 {0x8d,0x74,0x00}; /* lea 0(%si),%si */
1278 static const unsigned char f16_4
[] =
1279 {0x8d,0xb4,0x00,0x00}; /* lea 0W(%si),%si */
1280 static const unsigned char jump_disp8
[] =
1281 {0xeb}; /* jmp disp8 */
1282 static const unsigned char jump32_disp32
[] =
1283 {0xe9}; /* jmp disp32 */
1284 static const unsigned char jump16_disp32
[] =
1285 {0x66,0xe9}; /* jmp disp32 */
1286 /* 32-bit NOPs patterns. */
1287 static const unsigned char *const f32_patt
[] = {
1288 f32_1
, f32_2
, f32_3
, f32_4
, NULL
, f32_6
, f32_7
1290 /* 16-bit NOPs patterns. */
1291 static const unsigned char *const f16_patt
[] = {
1292 f32_1
, f32_2
, f16_3
, f16_4
1294 /* nopl (%[re]ax) */
1295 static const unsigned char alt_3
[] =
1297 /* nopl 0(%[re]ax) */
1298 static const unsigned char alt_4
[] =
1299 {0x0f,0x1f,0x40,0x00};
1300 /* nopl 0(%[re]ax,%[re]ax,1) */
1301 static const unsigned char alt_5
[] =
1302 {0x0f,0x1f,0x44,0x00,0x00};
1303 /* nopw 0(%[re]ax,%[re]ax,1) */
1304 static const unsigned char alt_6
[] =
1305 {0x66,0x0f,0x1f,0x44,0x00,0x00};
1306 /* nopl 0L(%[re]ax) */
1307 static const unsigned char alt_7
[] =
1308 {0x0f,0x1f,0x80,0x00,0x00,0x00,0x00};
1309 /* nopl 0L(%[re]ax,%[re]ax,1) */
1310 static const unsigned char alt_8
[] =
1311 {0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
1312 /* nopw 0L(%[re]ax,%[re]ax,1) */
1313 static const unsigned char alt_9
[] =
1314 {0x66,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
1315 /* nopw %cs:0L(%[re]ax,%[re]ax,1) */
1316 static const unsigned char alt_10
[] =
1317 {0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
1318 /* data16 nopw %cs:0L(%eax,%eax,1) */
1319 static const unsigned char alt_11
[] =
1320 {0x66,0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
1321 /* 32-bit and 64-bit NOPs patterns. */
1322 static const unsigned char *const alt_patt
[] = {
1323 f32_1
, f32_2
, alt_3
, alt_4
, alt_5
, alt_6
, alt_7
, alt_8
,
1324 alt_9
, alt_10
, alt_11
1327 /* Genenerate COUNT bytes of NOPs to WHERE from PATT with the maximum
1328 size of a single NOP instruction MAX_SINGLE_NOP_SIZE. */
1331 i386_output_nops (char *where
, const unsigned char *const *patt
,
1332 int count
, int max_single_nop_size
)
1335 /* Place the longer NOP first. */
1338 const unsigned char *nops
;
1340 if (max_single_nop_size
< 1)
1342 as_fatal (_("i386_output_nops called to generate nops of at most %d bytes!"),
1343 max_single_nop_size
);
1347 nops
= patt
[max_single_nop_size
- 1];
1349 /* Use the smaller one if the requsted one isn't available. */
1352 max_single_nop_size
--;
1353 nops
= patt
[max_single_nop_size
- 1];
1356 last
= count
% max_single_nop_size
;
1359 for (offset
= 0; offset
< count
; offset
+= max_single_nop_size
)
1360 memcpy (where
+ offset
, nops
, max_single_nop_size
);
1364 nops
= patt
[last
- 1];
1367 /* Use the smaller one plus one-byte NOP if the needed one
1370 nops
= patt
[last
- 1];
1371 memcpy (where
+ offset
, nops
, last
);
1372 where
[offset
+ last
] = *patt
[0];
1375 memcpy (where
+ offset
, nops
, last
);
1380 fits_in_imm7 (offsetT num
)
1382 return (num
& 0x7f) == num
;
1386 fits_in_imm31 (offsetT num
)
1388 return (num
& 0x7fffffff) == num
;
1391 /* Genenerate COUNT bytes of NOPs to WHERE with the maximum size of a
1392 single NOP instruction LIMIT. */
1395 i386_generate_nops (fragS
*fragP
, char *where
, offsetT count
, int limit
)
1397 const unsigned char *const *patt
= NULL
;
1398 int max_single_nop_size
;
1399 /* Maximum number of NOPs before switching to jump over NOPs. */
1400 int max_number_of_nops
;
1402 switch (fragP
->fr_type
)
1407 case rs_machine_dependent
:
1408 /* Allow NOP padding for jumps and calls. */
1409 if (TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) == BRANCH_PADDING
1410 || TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) == FUSED_JCC_PADDING
)
1417 /* We need to decide which NOP sequence to use for 32bit and
1418 64bit. When -mtune= is used:
1420 1. For PROCESSOR_I386, PROCESSOR_I486, PROCESSOR_PENTIUM and
1421 PROCESSOR_GENERIC32, f32_patt will be used.
1422 2. For the rest, alt_patt will be used.
1424 When -mtune= isn't used, alt_patt will be used if
1425 cpu_arch_isa_flags has CpuNop. Otherwise, f32_patt will
1428 When -march= or .arch is used, we can't use anything beyond
1429 cpu_arch_isa_flags. */
1431 if (flag_code
== CODE_16BIT
)
1434 max_single_nop_size
= sizeof (f16_patt
) / sizeof (f16_patt
[0]);
1435 /* Limit number of NOPs to 2 in 16-bit mode. */
1436 max_number_of_nops
= 2;
1440 if (fragP
->tc_frag_data
.isa
== PROCESSOR_UNKNOWN
)
1442 /* PROCESSOR_UNKNOWN means that all ISAs may be used. */
1443 switch (cpu_arch_tune
)
1445 case PROCESSOR_UNKNOWN
:
1446 /* We use cpu_arch_isa_flags to check if we SHOULD
1447 optimize with nops. */
1448 if (fragP
->tc_frag_data
.isa_flags
.bitfield
.cpunop
)
1453 case PROCESSOR_PENTIUM4
:
1454 case PROCESSOR_NOCONA
:
1455 case PROCESSOR_CORE
:
1456 case PROCESSOR_CORE2
:
1457 case PROCESSOR_COREI7
:
1458 case PROCESSOR_GENERIC64
:
1460 case PROCESSOR_ATHLON
:
1462 case PROCESSOR_AMDFAM10
:
1464 case PROCESSOR_ZNVER
:
1468 case PROCESSOR_I386
:
1469 case PROCESSOR_I486
:
1470 case PROCESSOR_PENTIUM
:
1471 case PROCESSOR_PENTIUMPRO
:
1472 case PROCESSOR_IAMCU
:
1473 case PROCESSOR_GENERIC32
:
1476 case PROCESSOR_NONE
:
1482 switch (fragP
->tc_frag_data
.tune
)
1484 case PROCESSOR_UNKNOWN
:
1485 /* When cpu_arch_isa is set, cpu_arch_tune shouldn't be
1486 PROCESSOR_UNKNOWN. */
1490 case PROCESSOR_I386
:
1491 case PROCESSOR_I486
:
1492 case PROCESSOR_PENTIUM
:
1493 case PROCESSOR_IAMCU
:
1495 case PROCESSOR_ATHLON
:
1497 case PROCESSOR_AMDFAM10
:
1499 case PROCESSOR_ZNVER
:
1501 case PROCESSOR_GENERIC32
:
1502 /* We use cpu_arch_isa_flags to check if we CAN optimize
1504 if (fragP
->tc_frag_data
.isa_flags
.bitfield
.cpunop
)
1509 case PROCESSOR_PENTIUMPRO
:
1510 case PROCESSOR_PENTIUM4
:
1511 case PROCESSOR_NOCONA
:
1512 case PROCESSOR_CORE
:
1513 case PROCESSOR_CORE2
:
1514 case PROCESSOR_COREI7
:
1515 if (fragP
->tc_frag_data
.isa_flags
.bitfield
.cpunop
)
1520 case PROCESSOR_GENERIC64
:
1523 case PROCESSOR_NONE
:
1528 if (patt
== f32_patt
)
1530 max_single_nop_size
= sizeof (f32_patt
) / sizeof (f32_patt
[0]);
1531 /* Limit number of NOPs to 2 for older processors. */
1532 max_number_of_nops
= 2;
1536 max_single_nop_size
= sizeof (alt_patt
) / sizeof (alt_patt
[0]);
1537 /* Limit number of NOPs to 7 for newer processors. */
1538 max_number_of_nops
= 7;
1543 limit
= max_single_nop_size
;
1545 if (fragP
->fr_type
== rs_fill_nop
)
1547 /* Output NOPs for .nop directive. */
1548 if (limit
> max_single_nop_size
)
1550 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
1551 _("invalid single nop size: %d "
1552 "(expect within [0, %d])"),
1553 limit
, max_single_nop_size
);
1557 else if (fragP
->fr_type
!= rs_machine_dependent
)
1558 fragP
->fr_var
= count
;
1560 if ((count
/ max_single_nop_size
) > max_number_of_nops
)
1562 /* Generate jump over NOPs. */
1563 offsetT disp
= count
- 2;
1564 if (fits_in_imm7 (disp
))
1566 /* Use "jmp disp8" if possible. */
1568 where
[0] = jump_disp8
[0];
1574 unsigned int size_of_jump
;
1576 if (flag_code
== CODE_16BIT
)
1578 where
[0] = jump16_disp32
[0];
1579 where
[1] = jump16_disp32
[1];
1584 where
[0] = jump32_disp32
[0];
1588 count
-= size_of_jump
+ 4;
1589 if (!fits_in_imm31 (count
))
1591 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
1592 _("jump over nop padding out of range"));
1596 md_number_to_chars (where
+ size_of_jump
, count
, 4);
1597 where
+= size_of_jump
+ 4;
1601 /* Generate multiple NOPs. */
1602 i386_output_nops (where
, patt
, count
, limit
);
1606 operand_type_all_zero (const union i386_operand_type
*x
)
1608 switch (ARRAY_SIZE(x
->array
))
1619 return !x
->array
[0];
1626 operand_type_set (union i386_operand_type
*x
, unsigned int v
)
1628 switch (ARRAY_SIZE(x
->array
))
1644 x
->bitfield
.class = ClassNone
;
1645 x
->bitfield
.instance
= InstanceNone
;
1649 operand_type_equal (const union i386_operand_type
*x
,
1650 const union i386_operand_type
*y
)
1652 switch (ARRAY_SIZE(x
->array
))
1655 if (x
->array
[2] != y
->array
[2])
1659 if (x
->array
[1] != y
->array
[1])
1663 return x
->array
[0] == y
->array
[0];
1671 cpu_flags_all_zero (const union i386_cpu_flags
*x
)
1673 switch (ARRAY_SIZE(x
->array
))
1692 return !x
->array
[0];
1699 cpu_flags_equal (const union i386_cpu_flags
*x
,
1700 const union i386_cpu_flags
*y
)
1702 switch (ARRAY_SIZE(x
->array
))
1705 if (x
->array
[4] != y
->array
[4])
1709 if (x
->array
[3] != y
->array
[3])
1713 if (x
->array
[2] != y
->array
[2])
1717 if (x
->array
[1] != y
->array
[1])
1721 return x
->array
[0] == y
->array
[0];
1729 cpu_flags_check_cpu64 (i386_cpu_flags f
)
1731 return !((flag_code
== CODE_64BIT
&& f
.bitfield
.cpuno64
)
1732 || (flag_code
!= CODE_64BIT
&& f
.bitfield
.cpu64
));
1735 static INLINE i386_cpu_flags
1736 cpu_flags_and (i386_cpu_flags x
, i386_cpu_flags y
)
1738 switch (ARRAY_SIZE (x
.array
))
1741 x
.array
[4] &= y
.array
[4];
1744 x
.array
[3] &= y
.array
[3];
1747 x
.array
[2] &= y
.array
[2];
1750 x
.array
[1] &= y
.array
[1];
1753 x
.array
[0] &= y
.array
[0];
1761 static INLINE i386_cpu_flags
1762 cpu_flags_or (i386_cpu_flags x
, i386_cpu_flags y
)
1764 switch (ARRAY_SIZE (x
.array
))
1767 x
.array
[4] |= y
.array
[4];
1770 x
.array
[3] |= y
.array
[3];
1773 x
.array
[2] |= y
.array
[2];
1776 x
.array
[1] |= y
.array
[1];
1779 x
.array
[0] |= y
.array
[0];
1787 static INLINE i386_cpu_flags
1788 cpu_flags_and_not (i386_cpu_flags x
, i386_cpu_flags y
)
1790 switch (ARRAY_SIZE (x
.array
))
1793 x
.array
[4] &= ~y
.array
[4];
1796 x
.array
[3] &= ~y
.array
[3];
1799 x
.array
[2] &= ~y
.array
[2];
1802 x
.array
[1] &= ~y
.array
[1];
1805 x
.array
[0] &= ~y
.array
[0];
1813 static const i386_cpu_flags avx512
= CPU_ANY_AVX512F_FLAGS
;
1815 #define CPU_FLAGS_ARCH_MATCH 0x1
1816 #define CPU_FLAGS_64BIT_MATCH 0x2
1818 #define CPU_FLAGS_PERFECT_MATCH \
1819 (CPU_FLAGS_ARCH_MATCH | CPU_FLAGS_64BIT_MATCH)
1821 /* Return CPU flags match bits. */
1824 cpu_flags_match (const insn_template
*t
)
1826 i386_cpu_flags x
= t
->cpu_flags
;
1827 int match
= cpu_flags_check_cpu64 (x
) ? CPU_FLAGS_64BIT_MATCH
: 0;
1829 x
.bitfield
.cpu64
= 0;
1830 x
.bitfield
.cpuno64
= 0;
1832 if (cpu_flags_all_zero (&x
))
1834 /* This instruction is available on all archs. */
1835 match
|= CPU_FLAGS_ARCH_MATCH
;
1839 /* This instruction is available only on some archs. */
1840 i386_cpu_flags cpu
= cpu_arch_flags
;
1842 /* AVX512VL is no standalone feature - match it and then strip it. */
1843 if (x
.bitfield
.cpuavx512vl
&& !cpu
.bitfield
.cpuavx512vl
)
1845 x
.bitfield
.cpuavx512vl
= 0;
1847 /* AVX and AVX2 present at the same time express an operand size
1848 dependency - strip AVX2 for the purposes here. The operand size
1849 dependent check occurs in check_vecOperands(). */
1850 if (x
.bitfield
.cpuavx
&& x
.bitfield
.cpuavx2
)
1851 x
.bitfield
.cpuavx2
= 0;
1853 cpu
= cpu_flags_and (x
, cpu
);
1854 if (!cpu_flags_all_zero (&cpu
))
1856 if (x
.bitfield
.cpuavx
)
1858 /* We need to check a few extra flags with AVX. */
1859 if (cpu
.bitfield
.cpuavx
1860 && (!t
->opcode_modifier
.sse2avx
1861 || (sse2avx
&& !i
.prefix
[DATA_PREFIX
]))
1862 && (!x
.bitfield
.cpuaes
|| cpu
.bitfield
.cpuaes
)
1863 && (!x
.bitfield
.cpugfni
|| cpu
.bitfield
.cpugfni
)
1864 && (!x
.bitfield
.cpupclmul
|| cpu
.bitfield
.cpupclmul
))
1865 match
|= CPU_FLAGS_ARCH_MATCH
;
1867 else if (x
.bitfield
.cpuavx512f
)
1869 /* We need to check a few extra flags with AVX512F. */
1870 if (cpu
.bitfield
.cpuavx512f
1871 && (!x
.bitfield
.cpugfni
|| cpu
.bitfield
.cpugfni
)
1872 && (!x
.bitfield
.cpuvaes
|| cpu
.bitfield
.cpuvaes
)
1873 && (!x
.bitfield
.cpuvpclmulqdq
|| cpu
.bitfield
.cpuvpclmulqdq
))
1874 match
|= CPU_FLAGS_ARCH_MATCH
;
1877 match
|= CPU_FLAGS_ARCH_MATCH
;
1883 static INLINE i386_operand_type
1884 operand_type_and (i386_operand_type x
, i386_operand_type y
)
1886 if (x
.bitfield
.class != y
.bitfield
.class)
1887 x
.bitfield
.class = ClassNone
;
1888 if (x
.bitfield
.instance
!= y
.bitfield
.instance
)
1889 x
.bitfield
.instance
= InstanceNone
;
1891 switch (ARRAY_SIZE (x
.array
))
1894 x
.array
[2] &= y
.array
[2];
1897 x
.array
[1] &= y
.array
[1];
1900 x
.array
[0] &= y
.array
[0];
1908 static INLINE i386_operand_type
1909 operand_type_and_not (i386_operand_type x
, i386_operand_type y
)
1911 gas_assert (y
.bitfield
.class == ClassNone
);
1912 gas_assert (y
.bitfield
.instance
== InstanceNone
);
1914 switch (ARRAY_SIZE (x
.array
))
1917 x
.array
[2] &= ~y
.array
[2];
1920 x
.array
[1] &= ~y
.array
[1];
1923 x
.array
[0] &= ~y
.array
[0];
1931 static INLINE i386_operand_type
1932 operand_type_or (i386_operand_type x
, i386_operand_type y
)
1934 gas_assert (x
.bitfield
.class == ClassNone
||
1935 y
.bitfield
.class == ClassNone
||
1936 x
.bitfield
.class == y
.bitfield
.class);
1937 gas_assert (x
.bitfield
.instance
== InstanceNone
||
1938 y
.bitfield
.instance
== InstanceNone
||
1939 x
.bitfield
.instance
== y
.bitfield
.instance
);
1941 switch (ARRAY_SIZE (x
.array
))
1944 x
.array
[2] |= y
.array
[2];
1947 x
.array
[1] |= y
.array
[1];
1950 x
.array
[0] |= y
.array
[0];
1958 static INLINE i386_operand_type
1959 operand_type_xor (i386_operand_type x
, i386_operand_type y
)
1961 gas_assert (y
.bitfield
.class == ClassNone
);
1962 gas_assert (y
.bitfield
.instance
== InstanceNone
);
1964 switch (ARRAY_SIZE (x
.array
))
1967 x
.array
[2] ^= y
.array
[2];
1970 x
.array
[1] ^= y
.array
[1];
1973 x
.array
[0] ^= y
.array
[0];
1981 static const i386_operand_type anydisp
= {
1982 .bitfield
= { .disp8
= 1, .disp16
= 1, .disp32
= 1, .disp64
= 1 }
1994 operand_type_check (i386_operand_type t
, enum operand_type c
)
1999 return t
.bitfield
.class == Reg
;
2002 return (t
.bitfield
.imm8
2006 || t
.bitfield
.imm32s
2007 || t
.bitfield
.imm64
);
2010 return (t
.bitfield
.disp8
2011 || t
.bitfield
.disp16
2012 || t
.bitfield
.disp32
2013 || t
.bitfield
.disp64
);
2016 return (t
.bitfield
.disp8
2017 || t
.bitfield
.disp16
2018 || t
.bitfield
.disp32
2019 || t
.bitfield
.disp64
2020 || t
.bitfield
.baseindex
);
2029 /* Return 1 if there is no conflict in 8bit/16bit/32bit/64bit/80bit size
2030 between operand GIVEN and opeand WANTED for instruction template T. */
2033 match_operand_size (const insn_template
*t
, unsigned int wanted
,
2036 return !((i
.types
[given
].bitfield
.byte
2037 && !t
->operand_types
[wanted
].bitfield
.byte
)
2038 || (i
.types
[given
].bitfield
.word
2039 && !t
->operand_types
[wanted
].bitfield
.word
)
2040 || (i
.types
[given
].bitfield
.dword
2041 && !t
->operand_types
[wanted
].bitfield
.dword
)
2042 || (i
.types
[given
].bitfield
.qword
2043 && (!t
->operand_types
[wanted
].bitfield
.qword
2044 /* Don't allow 64-bit (memory) operands outside of 64-bit
2045 mode, when they're used where a 64-bit GPR could also
2046 be used. Checking is needed for Intel Syntax only. */
2048 && flag_code
!= CODE_64BIT
2049 && (t
->operand_types
[wanted
].bitfield
.class == Reg
2050 || t
->operand_types
[wanted
].bitfield
.class == Accum
2051 || t
->opcode_modifier
.isstring
))))
2052 || (i
.types
[given
].bitfield
.tbyte
2053 && !t
->operand_types
[wanted
].bitfield
.tbyte
));
2056 /* Return 1 if there is no conflict in SIMD register between operand
2057 GIVEN and opeand WANTED for instruction template T. */
2060 match_simd_size (const insn_template
*t
, unsigned int wanted
,
2063 return !((i
.types
[given
].bitfield
.xmmword
2064 && !t
->operand_types
[wanted
].bitfield
.xmmword
)
2065 || (i
.types
[given
].bitfield
.ymmword
2066 && !t
->operand_types
[wanted
].bitfield
.ymmword
)
2067 || (i
.types
[given
].bitfield
.zmmword
2068 && !t
->operand_types
[wanted
].bitfield
.zmmword
)
2069 || (i
.types
[given
].bitfield
.tmmword
2070 && !t
->operand_types
[wanted
].bitfield
.tmmword
));
2073 /* Return 1 if there is no conflict in any size between operand GIVEN
2074 and opeand WANTED for instruction template T. */
2077 match_mem_size (const insn_template
*t
, unsigned int wanted
,
2080 return (match_operand_size (t
, wanted
, given
)
2081 && !((i
.types
[given
].bitfield
.unspecified
2082 && !i
.broadcast
.type
2083 && !i
.broadcast
.bytes
2084 && !t
->operand_types
[wanted
].bitfield
.unspecified
)
2085 || (i
.types
[given
].bitfield
.fword
2086 && !t
->operand_types
[wanted
].bitfield
.fword
)
2087 /* For scalar opcode templates to allow register and memory
2088 operands at the same time, some special casing is needed
2089 here. Also for v{,p}broadcast*, {,v}pmov{s,z}*, and
2090 down-conversion vpmov*. */
2091 || ((t
->operand_types
[wanted
].bitfield
.class == RegSIMD
2092 && t
->operand_types
[wanted
].bitfield
.byte
2093 + t
->operand_types
[wanted
].bitfield
.word
2094 + t
->operand_types
[wanted
].bitfield
.dword
2095 + t
->operand_types
[wanted
].bitfield
.qword
2096 > !!t
->opcode_modifier
.broadcast
)
2097 ? (i
.types
[given
].bitfield
.xmmword
2098 || i
.types
[given
].bitfield
.ymmword
2099 || i
.types
[given
].bitfield
.zmmword
)
2100 : !match_simd_size(t
, wanted
, given
))));
2103 /* Return value has MATCH_STRAIGHT set if there is no size conflict on any
2104 operands for instruction template T, and it has MATCH_REVERSE set if there
2105 is no size conflict on any operands for the template with operands reversed
2106 (and the template allows for reversing in the first place). */
2108 #define MATCH_STRAIGHT 1
2109 #define MATCH_REVERSE 2
2111 static INLINE
unsigned int
2112 operand_size_match (const insn_template
*t
)
2114 unsigned int j
, match
= MATCH_STRAIGHT
;
2116 /* Don't check non-absolute jump instructions. */
2117 if (t
->opcode_modifier
.jump
2118 && t
->opcode_modifier
.jump
!= JUMP_ABSOLUTE
)
2121 /* Check memory and accumulator operand size. */
2122 for (j
= 0; j
< i
.operands
; j
++)
2124 if (i
.types
[j
].bitfield
.class != Reg
2125 && i
.types
[j
].bitfield
.class != RegSIMD
2126 && t
->opcode_modifier
.operandconstraint
== ANY_SIZE
)
2129 if (t
->operand_types
[j
].bitfield
.class == Reg
2130 && !match_operand_size (t
, j
, j
))
2136 if (t
->operand_types
[j
].bitfield
.class == RegSIMD
2137 && !match_simd_size (t
, j
, j
))
2143 if (t
->operand_types
[j
].bitfield
.instance
== Accum
2144 && (!match_operand_size (t
, j
, j
) || !match_simd_size (t
, j
, j
)))
2150 if ((i
.flags
[j
] & Operand_Mem
) && !match_mem_size (t
, j
, j
))
2157 if (!t
->opcode_modifier
.d
)
2160 /* Check reverse. */
2161 gas_assert (i
.operands
>= 2);
2163 for (j
= 0; j
< i
.operands
; j
++)
2165 unsigned int given
= i
.operands
- j
- 1;
2167 /* For FMA4 and XOP insns VEX.W controls just the first two
2168 register operands. */
2169 if (t
->cpu_flags
.bitfield
.cpufma4
|| t
->cpu_flags
.bitfield
.cpuxop
)
2170 given
= j
< 2 ? 1 - j
: j
;
2172 if (t
->operand_types
[j
].bitfield
.class == Reg
2173 && !match_operand_size (t
, j
, given
))
2176 if (t
->operand_types
[j
].bitfield
.class == RegSIMD
2177 && !match_simd_size (t
, j
, given
))
2180 if (t
->operand_types
[j
].bitfield
.instance
== Accum
2181 && (!match_operand_size (t
, j
, given
)
2182 || !match_simd_size (t
, j
, given
)))
2185 if ((i
.flags
[given
] & Operand_Mem
) && !match_mem_size (t
, j
, given
))
2189 return match
| MATCH_REVERSE
;
2193 operand_type_match (i386_operand_type overlap
,
2194 i386_operand_type given
)
2196 i386_operand_type temp
= overlap
;
2198 temp
.bitfield
.unspecified
= 0;
2199 temp
.bitfield
.byte
= 0;
2200 temp
.bitfield
.word
= 0;
2201 temp
.bitfield
.dword
= 0;
2202 temp
.bitfield
.fword
= 0;
2203 temp
.bitfield
.qword
= 0;
2204 temp
.bitfield
.tbyte
= 0;
2205 temp
.bitfield
.xmmword
= 0;
2206 temp
.bitfield
.ymmword
= 0;
2207 temp
.bitfield
.zmmword
= 0;
2208 temp
.bitfield
.tmmword
= 0;
2209 if (operand_type_all_zero (&temp
))
2212 if (given
.bitfield
.baseindex
== overlap
.bitfield
.baseindex
)
2216 i
.error
= operand_type_mismatch
;
2220 /* If given types g0 and g1 are registers they must be of the same type
2221 unless the expected operand type register overlap is null.
2222 Intel syntax sized memory operands are also checked here. */
2225 operand_type_register_match (i386_operand_type g0
,
2226 i386_operand_type t0
,
2227 i386_operand_type g1
,
2228 i386_operand_type t1
)
2230 if (g0
.bitfield
.class != Reg
2231 && g0
.bitfield
.class != RegSIMD
2232 && (g0
.bitfield
.unspecified
2233 || !operand_type_check (g0
, anymem
)))
2236 if (g1
.bitfield
.class != Reg
2237 && g1
.bitfield
.class != RegSIMD
2238 && (g1
.bitfield
.unspecified
2239 || !operand_type_check (g1
, anymem
)))
2242 if (g0
.bitfield
.byte
== g1
.bitfield
.byte
2243 && g0
.bitfield
.word
== g1
.bitfield
.word
2244 && g0
.bitfield
.dword
== g1
.bitfield
.dword
2245 && g0
.bitfield
.qword
== g1
.bitfield
.qword
2246 && g0
.bitfield
.xmmword
== g1
.bitfield
.xmmword
2247 && g0
.bitfield
.ymmword
== g1
.bitfield
.ymmword
2248 && g0
.bitfield
.zmmword
== g1
.bitfield
.zmmword
)
2251 /* If expectations overlap in no more than a single size, all is fine. */
2252 g0
= operand_type_and (t0
, t1
);
2253 if (g0
.bitfield
.byte
2257 + g0
.bitfield
.xmmword
2258 + g0
.bitfield
.ymmword
2259 + g0
.bitfield
.zmmword
<= 1)
2262 i
.error
= register_type_mismatch
;
2267 static INLINE
unsigned int
2268 register_number (const reg_entry
*r
)
2270 unsigned int nr
= r
->reg_num
;
2272 if (r
->reg_flags
& RegRex
)
2275 if (r
->reg_flags
& RegVRex
)
2281 static INLINE
unsigned int
2282 mode_from_disp_size (i386_operand_type t
)
2284 if (t
.bitfield
.disp8
)
2286 else if (t
.bitfield
.disp16
2287 || t
.bitfield
.disp32
)
2294 fits_in_signed_byte (addressT num
)
2296 return num
+ 0x80 <= 0xff;
2300 fits_in_unsigned_byte (addressT num
)
2306 fits_in_unsigned_word (addressT num
)
2308 return num
<= 0xffff;
2312 fits_in_signed_word (addressT num
)
2314 return num
+ 0x8000 <= 0xffff;
2318 fits_in_signed_long (addressT num ATTRIBUTE_UNUSED
)
2323 return num
+ 0x80000000 <= 0xffffffff;
2325 } /* fits_in_signed_long() */
2328 fits_in_unsigned_long (addressT num ATTRIBUTE_UNUSED
)
2333 return num
<= 0xffffffff;
2335 } /* fits_in_unsigned_long() */
2337 static INLINE valueT
extend_to_32bit_address (addressT num
)
2340 if (fits_in_unsigned_long(num
))
2341 return (num
^ ((addressT
) 1 << 31)) - ((addressT
) 1 << 31);
2343 if (!fits_in_signed_long (num
))
2344 return num
& 0xffffffff;
2351 fits_in_disp8 (offsetT num
)
2353 int shift
= i
.memshift
;
2359 mask
= (1 << shift
) - 1;
2361 /* Return 0 if NUM isn't properly aligned. */
2365 /* Check if NUM will fit in 8bit after shift. */
2366 return fits_in_signed_byte (num
>> shift
);
2370 fits_in_imm4 (offsetT num
)
2372 /* Despite the name, check for imm3 if we're dealing with EVEX. */
2373 return (num
& (i
.vec_encoding
!= vex_encoding_evex
? 0xf : 7)) == num
;
2376 static i386_operand_type
2377 smallest_imm_type (offsetT num
)
2379 i386_operand_type t
;
2381 operand_type_set (&t
, 0);
2382 t
.bitfield
.imm64
= 1;
2384 if (cpu_arch_tune
!= PROCESSOR_I486
&& num
== 1)
2386 /* This code is disabled on the 486 because all the Imm1 forms
2387 in the opcode table are slower on the i486. They're the
2388 versions with the implicitly specified single-position
2389 displacement, which has another syntax if you really want to
2391 t
.bitfield
.imm1
= 1;
2392 t
.bitfield
.imm8
= 1;
2393 t
.bitfield
.imm8s
= 1;
2394 t
.bitfield
.imm16
= 1;
2395 t
.bitfield
.imm32
= 1;
2396 t
.bitfield
.imm32s
= 1;
2398 else if (fits_in_signed_byte (num
))
2400 if (fits_in_unsigned_byte (num
))
2401 t
.bitfield
.imm8
= 1;
2402 t
.bitfield
.imm8s
= 1;
2403 t
.bitfield
.imm16
= 1;
2404 t
.bitfield
.imm32
= 1;
2405 t
.bitfield
.imm32s
= 1;
2407 else if (fits_in_unsigned_byte (num
))
2409 t
.bitfield
.imm8
= 1;
2410 t
.bitfield
.imm16
= 1;
2411 t
.bitfield
.imm32
= 1;
2412 t
.bitfield
.imm32s
= 1;
2414 else if (fits_in_signed_word (num
) || fits_in_unsigned_word (num
))
2416 t
.bitfield
.imm16
= 1;
2417 t
.bitfield
.imm32
= 1;
2418 t
.bitfield
.imm32s
= 1;
2420 else if (fits_in_signed_long (num
))
2422 t
.bitfield
.imm32
= 1;
2423 t
.bitfield
.imm32s
= 1;
2425 else if (fits_in_unsigned_long (num
))
2426 t
.bitfield
.imm32
= 1;
2432 offset_in_range (offsetT val
, int size
)
2438 case 1: mask
= ((addressT
) 1 << 8) - 1; break;
2439 case 2: mask
= ((addressT
) 1 << 16) - 1; break;
2441 case 4: mask
= ((addressT
) 1 << 32) - 1; break;
2443 case sizeof (val
): return val
;
2447 if ((val
& ~mask
) != 0 && (-val
& ~mask
) != 0)
2448 as_warn (_("0x%" PRIx64
" shortened to 0x%" PRIx64
),
2449 (uint64_t) val
, (uint64_t) (val
& mask
));
2454 static INLINE
const char *insn_name (const insn_template
*t
)
2456 return &i386_mnemonics
[t
->mnem_off
];
2469 a. PREFIX_EXIST if attempting to add a prefix where one from the
2470 same class already exists.
2471 b. PREFIX_LOCK if lock prefix is added.
2472 c. PREFIX_REP if rep/repne prefix is added.
2473 d. PREFIX_DS if ds prefix is added.
2474 e. PREFIX_OTHER if other prefix is added.
2477 static enum PREFIX_GROUP
2478 add_prefix (unsigned int prefix
)
2480 enum PREFIX_GROUP ret
= PREFIX_OTHER
;
2483 if (prefix
>= REX_OPCODE
&& prefix
< REX_OPCODE
+ 16
2484 && flag_code
== CODE_64BIT
)
2486 if ((i
.prefix
[REX_PREFIX
] & prefix
& REX_W
)
2487 || (i
.prefix
[REX_PREFIX
] & prefix
& REX_R
)
2488 || (i
.prefix
[REX_PREFIX
] & prefix
& REX_X
)
2489 || (i
.prefix
[REX_PREFIX
] & prefix
& REX_B
))
2500 case DS_PREFIX_OPCODE
:
2503 case CS_PREFIX_OPCODE
:
2504 case ES_PREFIX_OPCODE
:
2505 case FS_PREFIX_OPCODE
:
2506 case GS_PREFIX_OPCODE
:
2507 case SS_PREFIX_OPCODE
:
2511 case REPNE_PREFIX_OPCODE
:
2512 case REPE_PREFIX_OPCODE
:
2517 case LOCK_PREFIX_OPCODE
:
2526 case ADDR_PREFIX_OPCODE
:
2530 case DATA_PREFIX_OPCODE
:
2534 if (i
.prefix
[q
] != 0)
2542 i
.prefix
[q
] |= prefix
;
2545 as_bad (_("same type of prefix used twice"));
2551 update_code_flag (int value
, int check
)
2553 PRINTF_LIKE ((*as_error
));
2555 flag_code
= (enum flag_code
) value
;
2556 if (flag_code
== CODE_64BIT
)
2558 cpu_arch_flags
.bitfield
.cpu64
= 1;
2559 cpu_arch_flags
.bitfield
.cpuno64
= 0;
2563 cpu_arch_flags
.bitfield
.cpu64
= 0;
2564 cpu_arch_flags
.bitfield
.cpuno64
= 1;
2566 if (value
== CODE_64BIT
&& !cpu_arch_flags
.bitfield
.cpulm
)
2569 as_error
= as_fatal
;
2572 (*as_error
) (_("64bit mode not supported on `%s'."),
2573 cpu_arch_name
? cpu_arch_name
: default_arch
);
2575 if (value
== CODE_32BIT
&& !cpu_arch_flags
.bitfield
.cpui386
)
2578 as_error
= as_fatal
;
2581 (*as_error
) (_("32bit mode not supported on `%s'."),
2582 cpu_arch_name
? cpu_arch_name
: default_arch
);
2584 stackop_size
= '\0';
2588 set_code_flag (int value
)
2590 update_code_flag (value
, 0);
2594 set_16bit_gcc_code_flag (int new_code_flag
)
2596 flag_code
= (enum flag_code
) new_code_flag
;
2597 if (flag_code
!= CODE_16BIT
)
2599 cpu_arch_flags
.bitfield
.cpu64
= 0;
2600 cpu_arch_flags
.bitfield
.cpuno64
= 1;
2601 stackop_size
= LONG_MNEM_SUFFIX
;
2605 set_intel_syntax (int syntax_flag
)
2607 /* Find out if register prefixing is specified. */
2608 int ask_naked_reg
= 0;
2611 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2614 int e
= get_symbol_name (&string
);
2616 if (strcmp (string
, "prefix") == 0)
2618 else if (strcmp (string
, "noprefix") == 0)
2621 as_bad (_("bad argument to syntax directive."));
2622 (void) restore_line_pointer (e
);
2624 demand_empty_rest_of_line ();
2626 intel_syntax
= syntax_flag
;
2628 if (ask_naked_reg
== 0)
2629 allow_naked_reg
= (intel_syntax
2630 && (bfd_get_symbol_leading_char (stdoutput
) != '\0'));
2632 allow_naked_reg
= (ask_naked_reg
< 0);
2634 expr_set_rank (O_full_ptr
, syntax_flag
? 10 : 0);
2636 register_prefix
= allow_naked_reg
? "" : "%";
2640 set_intel_mnemonic (int mnemonic_flag
)
2642 intel_mnemonic
= mnemonic_flag
;
2646 set_allow_index_reg (int flag
)
2648 allow_index_reg
= flag
;
2652 set_check (int what
)
2654 enum check_kind
*kind
;
2659 kind
= &operand_check
;
2670 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2673 int e
= get_symbol_name (&string
);
2675 if (strcmp (string
, "none") == 0)
2677 else if (strcmp (string
, "warning") == 0)
2678 *kind
= check_warning
;
2679 else if (strcmp (string
, "error") == 0)
2680 *kind
= check_error
;
2682 as_bad (_("bad argument to %s_check directive."), str
);
2683 (void) restore_line_pointer (e
);
2686 as_bad (_("missing argument for %s_check directive"), str
);
2688 demand_empty_rest_of_line ();
2692 check_cpu_arch_compatible (const char *name ATTRIBUTE_UNUSED
,
2693 i386_cpu_flags new_flag ATTRIBUTE_UNUSED
)
2695 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
2696 static const char *arch
;
2698 /* Intel MCU is only supported on ELF. */
2704 /* Use cpu_arch_name if it is set in md_parse_option. Otherwise
2705 use default_arch. */
2706 arch
= cpu_arch_name
;
2708 arch
= default_arch
;
2711 /* If we are targeting Intel MCU, we must enable it. */
2712 if ((get_elf_backend_data (stdoutput
)->elf_machine_code
== EM_IAMCU
)
2713 == new_flag
.bitfield
.cpuiamcu
)
2716 as_bad (_("`%s' is not supported on `%s'"), name
, arch
);
2721 extend_cpu_sub_arch_name (const char *name
)
2723 if (cpu_sub_arch_name
)
2724 cpu_sub_arch_name
= reconcat (cpu_sub_arch_name
, cpu_sub_arch_name
,
2725 ".", name
, (const char *) NULL
);
2727 cpu_sub_arch_name
= concat (".", name
, (const char *) NULL
);
2731 set_cpu_arch (int dummy ATTRIBUTE_UNUSED
)
2733 typedef struct arch_stack_entry
2735 const struct arch_stack_entry
*prev
;
2738 i386_cpu_flags flags
;
2739 i386_cpu_flags isa_flags
;
2740 enum processor_type isa
;
2741 enum flag_code flag_code
;
2743 bool no_cond_jump_promotion
;
2745 static const arch_stack_entry
*arch_stack_top
;
2749 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2752 int e
= get_symbol_name (&s
);
2753 const char *string
= s
;
2755 i386_cpu_flags flags
;
2757 if (strcmp (string
, "default") == 0)
2759 if (strcmp (default_arch
, "iamcu") == 0)
2760 string
= default_arch
;
2763 static const i386_cpu_flags cpu_unknown_flags
= CPU_UNKNOWN_FLAGS
;
2765 cpu_arch_name
= NULL
;
2766 free (cpu_sub_arch_name
);
2767 cpu_sub_arch_name
= NULL
;
2768 cpu_arch_flags
= cpu_unknown_flags
;
2769 if (flag_code
== CODE_64BIT
)
2771 cpu_arch_flags
.bitfield
.cpu64
= 1;
2772 cpu_arch_flags
.bitfield
.cpuno64
= 0;
2776 cpu_arch_flags
.bitfield
.cpu64
= 0;
2777 cpu_arch_flags
.bitfield
.cpuno64
= 1;
2779 cpu_arch_isa
= PROCESSOR_UNKNOWN
;
2780 cpu_arch_isa_flags
= cpu_arch
[flag_code
== CODE_64BIT
].enable
;
2781 if (!cpu_arch_tune_set
)
2783 cpu_arch_tune
= cpu_arch_isa
;
2784 cpu_arch_tune_flags
= cpu_arch_isa_flags
;
2787 j
= ARRAY_SIZE (cpu_arch
) + 1;
2790 else if (strcmp (string
, "push") == 0)
2792 arch_stack_entry
*top
= XNEW (arch_stack_entry
);
2794 top
->name
= cpu_arch_name
;
2795 if (cpu_sub_arch_name
)
2796 top
->sub_name
= xstrdup (cpu_sub_arch_name
);
2798 top
->sub_name
= NULL
;
2799 top
->flags
= cpu_arch_flags
;
2800 top
->isa
= cpu_arch_isa
;
2801 top
->isa_flags
= cpu_arch_isa_flags
;
2802 top
->flag_code
= flag_code
;
2803 top
->stackop_size
= stackop_size
;
2804 top
->no_cond_jump_promotion
= no_cond_jump_promotion
;
2806 top
->prev
= arch_stack_top
;
2807 arch_stack_top
= top
;
2809 (void) restore_line_pointer (e
);
2810 demand_empty_rest_of_line ();
2813 else if (strcmp (string
, "pop") == 0)
2815 const arch_stack_entry
*top
= arch_stack_top
;
2818 as_bad (_(".arch stack is empty"));
2819 else if (top
->flag_code
!= flag_code
2820 || top
->stackop_size
!= stackop_size
)
2822 static const unsigned int bits
[] = {
2828 as_bad (_("this `.arch pop' requires `.code%u%s' to be in effect"),
2829 bits
[top
->flag_code
],
2830 top
->stackop_size
== LONG_MNEM_SUFFIX
? "gcc" : "");
2834 arch_stack_top
= top
->prev
;
2836 cpu_arch_name
= top
->name
;
2837 free (cpu_sub_arch_name
);
2838 cpu_sub_arch_name
= top
->sub_name
;
2839 cpu_arch_flags
= top
->flags
;
2840 cpu_arch_isa
= top
->isa
;
2841 cpu_arch_isa_flags
= top
->isa_flags
;
2842 no_cond_jump_promotion
= top
->no_cond_jump_promotion
;
2847 (void) restore_line_pointer (e
);
2848 demand_empty_rest_of_line ();
2852 for (; j
< ARRAY_SIZE (cpu_arch
); j
++)
2854 if (strcmp (string
+ (*string
== '.'), cpu_arch
[j
].name
) == 0
2855 && (*string
== '.') == (cpu_arch
[j
].type
== PROCESSOR_NONE
))
2859 check_cpu_arch_compatible (string
, cpu_arch
[j
].enable
);
2861 cpu_arch_name
= cpu_arch
[j
].name
;
2862 free (cpu_sub_arch_name
);
2863 cpu_sub_arch_name
= NULL
;
2864 cpu_arch_flags
= cpu_arch
[j
].enable
;
2865 if (flag_code
== CODE_64BIT
)
2867 cpu_arch_flags
.bitfield
.cpu64
= 1;
2868 cpu_arch_flags
.bitfield
.cpuno64
= 0;
2872 cpu_arch_flags
.bitfield
.cpu64
= 0;
2873 cpu_arch_flags
.bitfield
.cpuno64
= 1;
2875 cpu_arch_isa
= cpu_arch
[j
].type
;
2876 cpu_arch_isa_flags
= cpu_arch
[j
].enable
;
2877 if (!cpu_arch_tune_set
)
2879 cpu_arch_tune
= cpu_arch_isa
;
2880 cpu_arch_tune_flags
= cpu_arch_isa_flags
;
2882 pre_386_16bit_warned
= false;
2886 if (cpu_flags_all_zero (&cpu_arch
[j
].enable
))
2889 flags
= cpu_flags_or (cpu_arch_flags
,
2890 cpu_arch
[j
].enable
);
2892 if (!cpu_flags_equal (&flags
, &cpu_arch_flags
))
2894 extend_cpu_sub_arch_name (string
+ 1);
2895 cpu_arch_flags
= flags
;
2896 cpu_arch_isa_flags
= flags
;
2900 = cpu_flags_or (cpu_arch_isa_flags
,
2901 cpu_arch
[j
].enable
);
2902 (void) restore_line_pointer (e
);
2903 demand_empty_rest_of_line ();
2908 if (startswith (string
, ".no") && j
>= ARRAY_SIZE (cpu_arch
))
2910 /* Disable an ISA extension. */
2911 for (j
= 0; j
< ARRAY_SIZE (cpu_arch
); j
++)
2912 if (cpu_arch
[j
].type
== PROCESSOR_NONE
2913 && strcmp (string
+ 3, cpu_arch
[j
].name
) == 0)
2915 flags
= cpu_flags_and_not (cpu_arch_flags
,
2916 cpu_arch
[j
].disable
);
2917 if (!cpu_flags_equal (&flags
, &cpu_arch_flags
))
2919 extend_cpu_sub_arch_name (string
+ 1);
2920 cpu_arch_flags
= flags
;
2921 cpu_arch_isa_flags
= flags
;
2923 (void) restore_line_pointer (e
);
2924 demand_empty_rest_of_line ();
2929 if (j
== ARRAY_SIZE (cpu_arch
))
2930 as_bad (_("no such architecture: `%s'"), string
);
2932 *input_line_pointer
= e
;
2935 as_bad (_("missing cpu architecture"));
2937 no_cond_jump_promotion
= 0;
2938 if (*input_line_pointer
== ','
2939 && !is_end_of_line
[(unsigned char) input_line_pointer
[1]])
2944 ++input_line_pointer
;
2945 e
= get_symbol_name (&string
);
2947 if (strcmp (string
, "nojumps") == 0)
2948 no_cond_jump_promotion
= 1;
2949 else if (strcmp (string
, "jumps") == 0)
2952 as_bad (_("no such architecture modifier: `%s'"), string
);
2954 (void) restore_line_pointer (e
);
2957 demand_empty_rest_of_line ();
2960 enum bfd_architecture
2963 if (cpu_arch_isa
== PROCESSOR_IAMCU
)
2965 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
2966 || flag_code
== CODE_64BIT
)
2967 as_fatal (_("Intel MCU is 32bit ELF only"));
2968 return bfd_arch_iamcu
;
2971 return bfd_arch_i386
;
2977 if (startswith (default_arch
, "x86_64"))
2979 if (default_arch
[6] == '\0')
2980 return bfd_mach_x86_64
;
2982 return bfd_mach_x64_32
;
2984 else if (!strcmp (default_arch
, "i386")
2985 || !strcmp (default_arch
, "iamcu"))
2987 if (cpu_arch_isa
== PROCESSOR_IAMCU
)
2989 if (OUTPUT_FLAVOR
!= bfd_target_elf_flavour
)
2990 as_fatal (_("Intel MCU is 32bit ELF only"));
2991 return bfd_mach_i386_iamcu
;
2994 return bfd_mach_i386_i386
;
2997 as_fatal (_("unknown architecture"));
3000 #include "opcodes/i386-tbl.h"
3005 /* Support pseudo prefixes like {disp32}. */
3006 lex_type
['{'] = LEX_BEGIN_NAME
;
3008 /* Initialize op_hash hash table. */
3009 op_hash
= str_htab_create ();
3012 const insn_template
*const *sets
= i386_op_sets
;
3013 const insn_template
*const *end
= sets
+ ARRAY_SIZE (i386_op_sets
) - 1;
3015 /* Type checks to compensate for the conversion through void * which
3016 occurs during hash table insertion / lookup. */
3017 (void) sizeof (sets
== ¤t_templates
->start
);
3018 (void) sizeof (end
== ¤t_templates
->end
);
3019 for (; sets
< end
; ++sets
)
3020 if (str_hash_insert (op_hash
, insn_name (*sets
), sets
, 0))
3021 as_fatal (_("duplicate %s"), insn_name (*sets
));
3024 /* Initialize reg_hash hash table. */
3025 reg_hash
= str_htab_create ();
3027 const reg_entry
*regtab
;
3028 unsigned int regtab_size
= i386_regtab_size
;
3030 for (regtab
= i386_regtab
; regtab_size
--; regtab
++)
3032 switch (regtab
->reg_type
.bitfield
.class)
3035 if (regtab
->reg_type
.bitfield
.dword
)
3037 if (regtab
->reg_type
.bitfield
.instance
== Accum
)
3040 else if (regtab
->reg_type
.bitfield
.tbyte
)
3042 /* There's no point inserting st(<N>) in the hash table, as
3043 parentheses aren't included in register_chars[] anyway. */
3044 if (regtab
->reg_type
.bitfield
.instance
!= Accum
)
3051 switch (regtab
->reg_num
)
3053 case 0: reg_es
= regtab
; break;
3054 case 2: reg_ss
= regtab
; break;
3055 case 3: reg_ds
= regtab
; break;
3060 if (!regtab
->reg_num
)
3065 if (str_hash_insert (reg_hash
, regtab
->reg_name
, regtab
, 0) != NULL
)
3066 as_fatal (_("duplicate %s"), regtab
->reg_name
);
3070 /* Fill in lexical tables: mnemonic_chars, operand_chars. */
3075 for (c
= 0; c
< 256; c
++)
3077 if (ISDIGIT (c
) || ISLOWER (c
))
3079 mnemonic_chars
[c
] = c
;
3080 register_chars
[c
] = c
;
3081 operand_chars
[c
] = c
;
3083 else if (ISUPPER (c
))
3085 mnemonic_chars
[c
] = TOLOWER (c
);
3086 register_chars
[c
] = mnemonic_chars
[c
];
3087 operand_chars
[c
] = c
;
3089 #ifdef SVR4_COMMENT_CHARS
3090 else if (c
== '\\' && strchr (i386_comment_chars
, '/'))
3091 operand_chars
[c
] = c
;
3095 operand_chars
[c
] = c
;
3098 mnemonic_chars
['_'] = '_';
3099 mnemonic_chars
['-'] = '-';
3100 mnemonic_chars
['.'] = '.';
3102 for (p
= extra_symbol_chars
; *p
!= '\0'; p
++)
3103 operand_chars
[(unsigned char) *p
] = *p
;
3104 for (p
= operand_special_chars
; *p
!= '\0'; p
++)
3105 operand_chars
[(unsigned char) *p
] = *p
;
3108 if (flag_code
== CODE_64BIT
)
3110 #if defined (OBJ_COFF) && defined (TE_PE)
3111 x86_dwarf2_return_column
= (OUTPUT_FLAVOR
== bfd_target_coff_flavour
3114 x86_dwarf2_return_column
= 16;
3116 x86_cie_data_alignment
= -8;
3117 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3118 x86_sframe_cfa_sp_reg
= 7;
3119 x86_sframe_cfa_fp_reg
= 6;
3124 x86_dwarf2_return_column
= 8;
3125 x86_cie_data_alignment
= -4;
3128 /* NB: FUSED_JCC_PADDING frag must have sufficient room so that it
3129 can be turned into BRANCH_PREFIX frag. */
3130 if (align_branch_prefix_size
> MAX_FUSED_JCC_PADDING_SIZE
)
3135 i386_print_statistics (FILE *file
)
3137 htab_print_statistics (file
, "i386 opcode", op_hash
);
3138 htab_print_statistics (file
, "i386 register", reg_hash
);
3144 htab_delete (op_hash
);
3145 htab_delete (reg_hash
);
3150 /* Debugging routines for md_assemble. */
3151 static void pte (insn_template
*);
3152 static void pt (i386_operand_type
);
3153 static void pe (expressionS
*);
3154 static void ps (symbolS
*);
3157 pi (const char *line
, i386_insn
*x
)
3161 fprintf (stdout
, "%s: template ", line
);
3163 fprintf (stdout
, " address: base %s index %s scale %x\n",
3164 x
->base_reg
? x
->base_reg
->reg_name
: "none",
3165 x
->index_reg
? x
->index_reg
->reg_name
: "none",
3166 x
->log2_scale_factor
);
3167 fprintf (stdout
, " modrm: mode %x reg %x reg/mem %x\n",
3168 x
->rm
.mode
, x
->rm
.reg
, x
->rm
.regmem
);
3169 fprintf (stdout
, " sib: base %x index %x scale %x\n",
3170 x
->sib
.base
, x
->sib
.index
, x
->sib
.scale
);
3171 fprintf (stdout
, " rex: 64bit %x extX %x extY %x extZ %x\n",
3172 (x
->rex
& REX_W
) != 0,
3173 (x
->rex
& REX_R
) != 0,
3174 (x
->rex
& REX_X
) != 0,
3175 (x
->rex
& REX_B
) != 0);
3176 for (j
= 0; j
< x
->operands
; j
++)
3178 fprintf (stdout
, " #%d: ", j
+ 1);
3180 fprintf (stdout
, "\n");
3181 if (x
->types
[j
].bitfield
.class == Reg
3182 || x
->types
[j
].bitfield
.class == RegMMX
3183 || x
->types
[j
].bitfield
.class == RegSIMD
3184 || x
->types
[j
].bitfield
.class == RegMask
3185 || x
->types
[j
].bitfield
.class == SReg
3186 || x
->types
[j
].bitfield
.class == RegCR
3187 || x
->types
[j
].bitfield
.class == RegDR
3188 || x
->types
[j
].bitfield
.class == RegTR
3189 || x
->types
[j
].bitfield
.class == RegBND
)
3190 fprintf (stdout
, "%s\n", x
->op
[j
].regs
->reg_name
);
3191 if (operand_type_check (x
->types
[j
], imm
))
3193 if (operand_type_check (x
->types
[j
], disp
))
3194 pe (x
->op
[j
].disps
);
3199 pte (insn_template
*t
)
3201 static const unsigned char opc_pfx
[] = { 0, 0x66, 0xf3, 0xf2 };
3202 static const char *const opc_spc
[] = {
3203 NULL
, "0f", "0f38", "0f3a", NULL
, "evexmap5", "evexmap6", NULL
,
3204 "XOP08", "XOP09", "XOP0A",
3208 fprintf (stdout
, " %d operands ", t
->operands
);
3209 if (opc_pfx
[t
->opcode_modifier
.opcodeprefix
])
3210 fprintf (stdout
, "pfx %x ", opc_pfx
[t
->opcode_modifier
.opcodeprefix
]);
3211 if (opc_spc
[t
->opcode_space
])
3212 fprintf (stdout
, "space %s ", opc_spc
[t
->opcode_space
]);
3213 fprintf (stdout
, "opcode %x ", t
->base_opcode
);
3214 if (t
->extension_opcode
!= None
)
3215 fprintf (stdout
, "ext %x ", t
->extension_opcode
);
3216 if (t
->opcode_modifier
.d
)
3217 fprintf (stdout
, "D");
3218 if (t
->opcode_modifier
.w
)
3219 fprintf (stdout
, "W");
3220 fprintf (stdout
, "\n");
3221 for (j
= 0; j
< t
->operands
; j
++)
3223 fprintf (stdout
, " #%d type ", j
+ 1);
3224 pt (t
->operand_types
[j
]);
3225 fprintf (stdout
, "\n");
3232 fprintf (stdout
, " operation %d\n", e
->X_op
);
3233 fprintf (stdout
, " add_number %" PRId64
" (%" PRIx64
")\n",
3234 (int64_t) e
->X_add_number
, (uint64_t) (valueT
) e
->X_add_number
);
3235 if (e
->X_add_symbol
)
3237 fprintf (stdout
, " add_symbol ");
3238 ps (e
->X_add_symbol
);
3239 fprintf (stdout
, "\n");
3243 fprintf (stdout
, " op_symbol ");
3244 ps (e
->X_op_symbol
);
3245 fprintf (stdout
, "\n");
3252 fprintf (stdout
, "%s type %s%s",
3254 S_IS_EXTERNAL (s
) ? "EXTERNAL " : "",
3255 segment_name (S_GET_SEGMENT (s
)));
3258 static struct type_name
3260 i386_operand_type mask
;
3263 const type_names
[] =
3265 { { .bitfield
= { .class = Reg
, .byte
= 1 } }, "r8" },
3266 { { .bitfield
= { .class = Reg
, .word
= 1 } }, "r16" },
3267 { { .bitfield
= { .class = Reg
, .dword
= 1 } }, "r32" },
3268 { { .bitfield
= { .class = Reg
, .qword
= 1 } }, "r64" },
3269 { { .bitfield
= { .instance
= Accum
, .byte
= 1 } }, "acc8" },
3270 { { .bitfield
= { .instance
= Accum
, .word
= 1 } }, "acc16" },
3271 { { .bitfield
= { .instance
= Accum
, .dword
= 1 } }, "acc32" },
3272 { { .bitfield
= { .instance
= Accum
, .qword
= 1 } }, "acc64" },
3273 { { .bitfield
= { .imm8
= 1 } }, "i8" },
3274 { { .bitfield
= { .imm8s
= 1 } }, "i8s" },
3275 { { .bitfield
= { .imm16
= 1 } }, "i16" },
3276 { { .bitfield
= { .imm32
= 1 } }, "i32" },
3277 { { .bitfield
= { .imm32s
= 1 } }, "i32s" },
3278 { { .bitfield
= { .imm64
= 1 } }, "i64" },
3279 { { .bitfield
= { .imm1
= 1 } }, "i1" },
3280 { { .bitfield
= { .baseindex
= 1 } }, "BaseIndex" },
3281 { { .bitfield
= { .disp8
= 1 } }, "d8" },
3282 { { .bitfield
= { .disp16
= 1 } }, "d16" },
3283 { { .bitfield
= { .disp32
= 1 } }, "d32" },
3284 { { .bitfield
= { .disp64
= 1 } }, "d64" },
3285 { { .bitfield
= { .instance
= RegD
, .word
= 1 } }, "InOutPortReg" },
3286 { { .bitfield
= { .instance
= RegC
, .byte
= 1 } }, "ShiftCount" },
3287 { { .bitfield
= { .class = RegCR
} }, "control reg" },
3288 { { .bitfield
= { .class = RegTR
} }, "test reg" },
3289 { { .bitfield
= { .class = RegDR
} }, "debug reg" },
3290 { { .bitfield
= { .class = Reg
, .tbyte
= 1 } }, "FReg" },
3291 { { .bitfield
= { .instance
= Accum
, .tbyte
= 1 } }, "FAcc" },
3292 { { .bitfield
= { .class = SReg
} }, "SReg" },
3293 { { .bitfield
= { .class = RegMMX
} }, "rMMX" },
3294 { { .bitfield
= { .class = RegSIMD
, .xmmword
= 1 } }, "rXMM" },
3295 { { .bitfield
= { .class = RegSIMD
, .ymmword
= 1 } }, "rYMM" },
3296 { { .bitfield
= { .class = RegSIMD
, .zmmword
= 1 } }, "rZMM" },
3297 { { .bitfield
= { .class = RegSIMD
, .tmmword
= 1 } }, "rTMM" },
3298 { { .bitfield
= { .class = RegMask
} }, "Mask reg" },
3302 pt (i386_operand_type t
)
3305 i386_operand_type a
;
3307 for (j
= 0; j
< ARRAY_SIZE (type_names
); j
++)
3309 a
= operand_type_and (t
, type_names
[j
].mask
);
3310 if (operand_type_equal (&a
, &type_names
[j
].mask
))
3311 fprintf (stdout
, "%s, ", type_names
[j
].name
);
3316 #endif /* DEBUG386 */
3318 static bfd_reloc_code_real_type
3319 reloc (unsigned int size
,
3322 bfd_reloc_code_real_type other
)
3324 if (other
!= NO_RELOC
)
3326 reloc_howto_type
*rel
;
3331 case BFD_RELOC_X86_64_GOT32
:
3332 return BFD_RELOC_X86_64_GOT64
;
3334 case BFD_RELOC_X86_64_GOTPLT64
:
3335 return BFD_RELOC_X86_64_GOTPLT64
;
3337 case BFD_RELOC_X86_64_PLTOFF64
:
3338 return BFD_RELOC_X86_64_PLTOFF64
;
3340 case BFD_RELOC_X86_64_GOTPC32
:
3341 other
= BFD_RELOC_X86_64_GOTPC64
;
3343 case BFD_RELOC_X86_64_GOTPCREL
:
3344 other
= BFD_RELOC_X86_64_GOTPCREL64
;
3346 case BFD_RELOC_X86_64_TPOFF32
:
3347 other
= BFD_RELOC_X86_64_TPOFF64
;
3349 case BFD_RELOC_X86_64_DTPOFF32
:
3350 other
= BFD_RELOC_X86_64_DTPOFF64
;
3356 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3357 if (other
== BFD_RELOC_SIZE32
)
3360 other
= BFD_RELOC_SIZE64
;
3363 as_bad (_("there are no pc-relative size relocations"));
3369 /* Sign-checking 4-byte relocations in 16-/32-bit code is pointless. */
3370 if (size
== 4 && (flag_code
!= CODE_64BIT
|| disallow_64bit_reloc
))
3373 rel
= bfd_reloc_type_lookup (stdoutput
, other
);
3375 as_bad (_("unknown relocation (%u)"), other
);
3376 else if (size
!= bfd_get_reloc_size (rel
))
3377 as_bad (_("%u-byte relocation cannot be applied to %u-byte field"),
3378 bfd_get_reloc_size (rel
),
3380 else if (pcrel
&& !rel
->pc_relative
)
3381 as_bad (_("non-pc-relative relocation for pc-relative field"));
3382 else if ((rel
->complain_on_overflow
== complain_overflow_signed
3384 || (rel
->complain_on_overflow
== complain_overflow_unsigned
3386 as_bad (_("relocated field and relocation type differ in signedness"));
3395 as_bad (_("there are no unsigned pc-relative relocations"));
3398 case 1: return BFD_RELOC_8_PCREL
;
3399 case 2: return BFD_RELOC_16_PCREL
;
3400 case 4: return BFD_RELOC_32_PCREL
;
3401 case 8: return BFD_RELOC_64_PCREL
;
3403 as_bad (_("cannot do %u byte pc-relative relocation"), size
);
3410 case 4: return BFD_RELOC_X86_64_32S
;
3415 case 1: return BFD_RELOC_8
;
3416 case 2: return BFD_RELOC_16
;
3417 case 4: return BFD_RELOC_32
;
3418 case 8: return BFD_RELOC_64
;
3420 as_bad (_("cannot do %s %u byte relocation"),
3421 sign
> 0 ? "signed" : "unsigned", size
);
3427 /* Here we decide which fixups can be adjusted to make them relative to
3428 the beginning of the section instead of the symbol. Basically we need
3429 to make sure that the dynamic relocations are done correctly, so in
3430 some cases we force the original symbol to be used. */
3433 tc_i386_fix_adjustable (fixS
*fixP ATTRIBUTE_UNUSED
)
3435 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3439 /* Don't adjust pc-relative references to merge sections in 64-bit
3441 if (use_rela_relocations
3442 && (S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0
3446 /* The x86_64 GOTPCREL are represented as 32bit PCrel relocations
3447 and changed later by validate_fix. */
3448 if (GOT_symbol
&& fixP
->fx_subsy
== GOT_symbol
3449 && fixP
->fx_r_type
== BFD_RELOC_32_PCREL
)
3452 /* Adjust_reloc_syms doesn't know about the GOT. Need to keep symbol
3453 for size relocations. */
3454 if (fixP
->fx_r_type
== BFD_RELOC_SIZE32
3455 || fixP
->fx_r_type
== BFD_RELOC_SIZE64
3456 || fixP
->fx_r_type
== BFD_RELOC_386_GOTOFF
3457 || fixP
->fx_r_type
== BFD_RELOC_386_GOT32
3458 || fixP
->fx_r_type
== BFD_RELOC_386_GOT32X
3459 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_GD
3460 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_LDM
3461 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_LDO_32
3462 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_IE_32
3463 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_IE
3464 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_GOTIE
3465 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_LE_32
3466 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_LE
3467 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_GOTDESC
3468 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_DESC_CALL
3469 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOT32
3470 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOTPCREL
3471 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOTPCRELX
3472 || fixP
->fx_r_type
== BFD_RELOC_X86_64_REX_GOTPCRELX
3473 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TLSGD
3474 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TLSLD
3475 || fixP
->fx_r_type
== BFD_RELOC_X86_64_DTPOFF32
3476 || fixP
->fx_r_type
== BFD_RELOC_X86_64_DTPOFF64
3477 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOTTPOFF
3478 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TPOFF32
3479 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TPOFF64
3480 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOTOFF64
3481 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOTPC32_TLSDESC
3482 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TLSDESC_CALL
3483 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
3484 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
3491 want_disp32 (const insn_template
*t
)
3493 return flag_code
!= CODE_64BIT
3494 || i
.prefix
[ADDR_PREFIX
]
3495 || (t
->mnem_off
== MN_lea
3496 && (!i
.types
[1].bitfield
.qword
3497 || t
->opcode_modifier
.size
== SIZE32
));
3501 intel_float_operand (const char *mnemonic
)
3503 /* Note that the value returned is meaningful only for opcodes with (memory)
3504 operands, hence the code here is free to improperly handle opcodes that
3505 have no operands (for better performance and smaller code). */
3507 if (mnemonic
[0] != 'f')
3508 return 0; /* non-math */
3510 switch (mnemonic
[1])
3512 /* fclex, fdecstp, fdisi, femms, feni, fincstp, finit, fsetpm, and
3513 the fs segment override prefix not currently handled because no
3514 call path can make opcodes without operands get here */
3516 return 2 /* integer op */;
3518 if (mnemonic
[2] == 'd' && (mnemonic
[3] == 'c' || mnemonic
[3] == 'e'))
3519 return 3; /* fldcw/fldenv */
3522 if (mnemonic
[2] != 'o' /* fnop */)
3523 return 3; /* non-waiting control op */
3526 if (mnemonic
[2] == 's')
3527 return 3; /* frstor/frstpm */
3530 if (mnemonic
[2] == 'a')
3531 return 3; /* fsave */
3532 if (mnemonic
[2] == 't')
3534 switch (mnemonic
[3])
3536 case 'c': /* fstcw */
3537 case 'd': /* fstdw */
3538 case 'e': /* fstenv */
3539 case 's': /* fsts[gw] */
3545 if (mnemonic
[2] == 'r' || mnemonic
[2] == 's')
3546 return 0; /* fxsave/fxrstor are not really math ops */
3554 install_template (const insn_template
*t
)
3560 /* Note that for pseudo prefixes this produces a length of 1. But for them
3561 the length isn't interesting at all. */
3562 for (l
= 1; l
< 4; ++l
)
3563 if (!(t
->base_opcode
>> (8 * l
)))
3566 i
.opcode_length
= l
;
3569 /* Build the VEX prefix. */
3572 build_vex_prefix (const insn_template
*t
)
3574 unsigned int register_specifier
;
3575 unsigned int vector_length
;
3578 /* Check register specifier. */
3579 if (i
.vex
.register_specifier
)
3581 register_specifier
=
3582 ~register_number (i
.vex
.register_specifier
) & 0xf;
3583 gas_assert ((i
.vex
.register_specifier
->reg_flags
& RegVRex
) == 0);
3586 register_specifier
= 0xf;
3588 /* Use 2-byte VEX prefix by swapping destination and source operand
3589 if there are more than 1 register operand. */
3590 if (i
.reg_operands
> 1
3591 && i
.vec_encoding
!= vex_encoding_vex3
3592 && i
.dir_encoding
== dir_encoding_default
3593 && i
.operands
== i
.reg_operands
3594 && operand_type_equal (&i
.types
[0], &i
.types
[i
.operands
- 1])
3595 && i
.tm
.opcode_space
== SPACE_0F
3596 && (i
.tm
.opcode_modifier
.load
|| i
.tm
.opcode_modifier
.d
)
3601 swap_2_operands (0, i
.operands
- 1);
3603 gas_assert (i
.rm
.mode
== 3);
3607 i
.rm
.regmem
= i
.rm
.reg
;
3610 if (i
.tm
.opcode_modifier
.d
)
3611 i
.tm
.base_opcode
^= (i
.tm
.base_opcode
& 0xee) != 0x6e
3612 ? Opcode_ExtD
: Opcode_SIMD_IntD
;
3613 else /* Use the next insn. */
3614 install_template (&t
[1]);
3617 /* Use 2-byte VEX prefix by swapping commutative source operands if there
3618 are no memory operands and at least 3 register ones. */
3619 if (i
.reg_operands
>= 3
3620 && i
.vec_encoding
!= vex_encoding_vex3
3621 && i
.reg_operands
== i
.operands
- i
.imm_operands
3622 && i
.tm
.opcode_modifier
.vex
3623 && i
.tm
.opcode_modifier
.commutative
3624 && (i
.tm
.opcode_modifier
.sse2avx
3625 || (optimize
> 1 && !i
.no_optimize
))
3627 && i
.vex
.register_specifier
3628 && !(i
.vex
.register_specifier
->reg_flags
& RegRex
))
3630 unsigned int xchg
= i
.operands
- i
.reg_operands
;
3632 gas_assert (i
.tm
.opcode_space
== SPACE_0F
);
3633 gas_assert (!i
.tm
.opcode_modifier
.sae
);
3634 gas_assert (operand_type_equal (&i
.types
[i
.operands
- 2],
3635 &i
.types
[i
.operands
- 3]));
3636 gas_assert (i
.rm
.mode
== 3);
3638 swap_2_operands (xchg
, xchg
+ 1);
3641 xchg
= i
.rm
.regmem
| 8;
3642 i
.rm
.regmem
= ~register_specifier
& 0xf;
3643 gas_assert (!(i
.rm
.regmem
& 8));
3644 i
.vex
.register_specifier
+= xchg
- i
.rm
.regmem
;
3645 register_specifier
= ~xchg
& 0xf;
3648 if (i
.tm
.opcode_modifier
.vex
== VEXScalar
)
3649 vector_length
= avxscalar
;
3650 else if (i
.tm
.opcode_modifier
.vex
== VEX256
)
3652 else if (dot_insn () && i
.tm
.opcode_modifier
.vex
== VEX128
)
3658 /* Determine vector length from the last multi-length vector
3661 for (op
= t
->operands
; op
--;)
3662 if (t
->operand_types
[op
].bitfield
.xmmword
3663 && t
->operand_types
[op
].bitfield
.ymmword
3664 && i
.types
[op
].bitfield
.ymmword
)
3671 /* Check the REX.W bit and VEXW. */
3672 if (i
.tm
.opcode_modifier
.vexw
== VEXWIG
)
3673 w
= (vexwig
== vexw1
|| (i
.rex
& REX_W
)) ? 1 : 0;
3674 else if (i
.tm
.opcode_modifier
.vexw
)
3675 w
= i
.tm
.opcode_modifier
.vexw
== VEXW1
? 1 : 0;
3677 w
= (flag_code
== CODE_64BIT
? i
.rex
& REX_W
: vexwig
== vexw1
) ? 1 : 0;
3679 /* Use 2-byte VEX prefix if possible. */
3681 && i
.vec_encoding
!= vex_encoding_vex3
3682 && i
.tm
.opcode_space
== SPACE_0F
3683 && (i
.rex
& (REX_W
| REX_X
| REX_B
)) == 0)
3685 /* 2-byte VEX prefix. */
3689 i
.vex
.bytes
[0] = 0xc5;
3691 /* Check the REX.R bit. */
3692 r
= (i
.rex
& REX_R
) ? 0 : 1;
3693 i
.vex
.bytes
[1] = (r
<< 7
3694 | register_specifier
<< 3
3695 | vector_length
<< 2
3696 | i
.tm
.opcode_modifier
.opcodeprefix
);
3700 /* 3-byte VEX prefix. */
3703 switch (i
.tm
.opcode_space
)
3708 i
.vex
.bytes
[0] = 0xc4;
3713 i
.vex
.bytes
[0] = 0x8f;
3719 /* The high 3 bits of the second VEX byte are 1's compliment
3720 of RXB bits from REX. */
3721 i
.vex
.bytes
[1] = ((~i
.rex
& 7) << 5)
3722 | (!dot_insn () ? i
.tm
.opcode_space
3723 : i
.insn_opcode_space
);
3725 i
.vex
.bytes
[2] = (w
<< 7
3726 | register_specifier
<< 3
3727 | vector_length
<< 2
3728 | i
.tm
.opcode_modifier
.opcodeprefix
);
3733 is_evex_encoding (const insn_template
*t
)
3735 return t
->opcode_modifier
.evex
|| t
->opcode_modifier
.disp8memshift
3736 || t
->opcode_modifier
.broadcast
|| t
->opcode_modifier
.masking
3737 || t
->opcode_modifier
.sae
;
3741 is_any_vex_encoding (const insn_template
*t
)
3743 return t
->opcode_modifier
.vex
|| is_evex_encoding (t
);
3747 get_broadcast_bytes (const insn_template
*t
, bool diag
)
3749 unsigned int op
, bytes
;
3750 const i386_operand_type
*types
;
3752 if (i
.broadcast
.type
)
3753 return (1 << (t
->opcode_modifier
.broadcast
- 1)) * i
.broadcast
.type
;
3755 gas_assert (intel_syntax
);
3757 for (op
= 0; op
< t
->operands
; ++op
)
3758 if (t
->operand_types
[op
].bitfield
.baseindex
)
3761 gas_assert (op
< t
->operands
);
3763 if (t
->opcode_modifier
.evex
3764 && t
->opcode_modifier
.evex
!= EVEXDYN
)
3765 switch (i
.broadcast
.bytes
)
3768 if (t
->operand_types
[op
].bitfield
.word
)
3772 if (t
->operand_types
[op
].bitfield
.dword
)
3776 if (t
->operand_types
[op
].bitfield
.qword
)
3780 if (t
->operand_types
[op
].bitfield
.xmmword
)
3782 if (t
->operand_types
[op
].bitfield
.ymmword
)
3784 if (t
->operand_types
[op
].bitfield
.zmmword
)
3791 gas_assert (op
+ 1 < t
->operands
);
3793 if (t
->operand_types
[op
+ 1].bitfield
.xmmword
3794 + t
->operand_types
[op
+ 1].bitfield
.ymmword
3795 + t
->operand_types
[op
+ 1].bitfield
.zmmword
> 1)
3797 types
= &i
.types
[op
+ 1];
3800 else /* Ambiguous - guess with a preference to non-AVX512VL forms. */
3801 types
= &t
->operand_types
[op
];
3803 if (types
->bitfield
.zmmword
)
3805 else if (types
->bitfield
.ymmword
)
3811 as_warn (_("ambiguous broadcast for `%s', using %u-bit form"),
3812 insn_name (t
), bytes
* 8);
3817 /* Build the EVEX prefix. */
3820 build_evex_prefix (void)
3822 unsigned int register_specifier
, w
;
3823 rex_byte vrex_used
= 0;
3825 /* Check register specifier. */
3826 if (i
.vex
.register_specifier
)
3828 gas_assert ((i
.vrex
& REX_X
) == 0);
3830 register_specifier
= i
.vex
.register_specifier
->reg_num
;
3831 if ((i
.vex
.register_specifier
->reg_flags
& RegRex
))
3832 register_specifier
+= 8;
3833 /* The upper 16 registers are encoded in the fourth byte of the
3835 if (!(i
.vex
.register_specifier
->reg_flags
& RegVRex
))
3836 i
.vex
.bytes
[3] = 0x8;
3837 register_specifier
= ~register_specifier
& 0xf;
3841 register_specifier
= 0xf;
3843 /* Encode upper 16 vector index register in the fourth byte of
3845 if (!(i
.vrex
& REX_X
))
3846 i
.vex
.bytes
[3] = 0x8;
3851 /* 4 byte EVEX prefix. */
3853 i
.vex
.bytes
[0] = 0x62;
3855 /* The high 3 bits of the second EVEX byte are 1's compliment of RXB
3857 gas_assert (i
.tm
.opcode_space
>= SPACE_0F
);
3858 gas_assert (i
.tm
.opcode_space
<= SPACE_EVEXMAP6
);
3859 i
.vex
.bytes
[1] = ((~i
.rex
& 7) << 5)
3860 | (!dot_insn () ? i
.tm
.opcode_space
3861 : i
.insn_opcode_space
);
3863 /* The fifth bit of the second EVEX byte is 1's compliment of the
3864 REX_R bit in VREX. */
3865 if (!(i
.vrex
& REX_R
))
3866 i
.vex
.bytes
[1] |= 0x10;
3870 if ((i
.reg_operands
+ i
.imm_operands
) == i
.operands
)
3872 /* When all operands are registers, the REX_X bit in REX is not
3873 used. We reuse it to encode the upper 16 registers, which is
3874 indicated by the REX_B bit in VREX. The REX_X bit is encoded
3875 as 1's compliment. */
3876 if ((i
.vrex
& REX_B
))
3879 i
.vex
.bytes
[1] &= ~0x40;
3883 /* EVEX instructions shouldn't need the REX prefix. */
3884 i
.vrex
&= ~vrex_used
;
3885 gas_assert (i
.vrex
== 0);
3887 /* Check the REX.W bit and VEXW. */
3888 if (i
.tm
.opcode_modifier
.vexw
== VEXWIG
)
3889 w
= (evexwig
== evexw1
|| (i
.rex
& REX_W
)) ? 1 : 0;
3890 else if (i
.tm
.opcode_modifier
.vexw
)
3891 w
= i
.tm
.opcode_modifier
.vexw
== VEXW1
? 1 : 0;
3893 w
= (flag_code
== CODE_64BIT
? i
.rex
& REX_W
: evexwig
== evexw1
) ? 1 : 0;
3895 /* The third byte of the EVEX prefix. */
3896 i
.vex
.bytes
[2] = ((w
<< 7)
3897 | (register_specifier
<< 3)
3898 | 4 /* Encode the U bit. */
3899 | i
.tm
.opcode_modifier
.opcodeprefix
);
3901 /* The fourth byte of the EVEX prefix. */
3902 /* The zeroing-masking bit. */
3903 if (i
.mask
.reg
&& i
.mask
.zeroing
)
3904 i
.vex
.bytes
[3] |= 0x80;
3906 /* Don't always set the broadcast bit if there is no RC. */
3907 if (i
.rounding
.type
== rc_none
)
3909 /* Encode the vector length. */
3910 unsigned int vec_length
;
3912 if (!i
.tm
.opcode_modifier
.evex
3913 || i
.tm
.opcode_modifier
.evex
== EVEXDYN
)
3917 /* Determine vector length from the last multi-length vector
3919 for (op
= i
.operands
; op
--;)
3920 if (i
.tm
.operand_types
[op
].bitfield
.xmmword
3921 + i
.tm
.operand_types
[op
].bitfield
.ymmword
3922 + i
.tm
.operand_types
[op
].bitfield
.zmmword
> 1)
3924 if (i
.types
[op
].bitfield
.zmmword
)
3926 i
.tm
.opcode_modifier
.evex
= EVEX512
;
3929 else if (i
.types
[op
].bitfield
.ymmword
)
3931 i
.tm
.opcode_modifier
.evex
= EVEX256
;
3934 else if (i
.types
[op
].bitfield
.xmmword
)
3936 i
.tm
.opcode_modifier
.evex
= EVEX128
;
3939 else if ((i
.broadcast
.type
|| i
.broadcast
.bytes
)
3940 && op
== i
.broadcast
.operand
)
3942 switch (get_broadcast_bytes (&i
.tm
, true))
3945 i
.tm
.opcode_modifier
.evex
= EVEX512
;
3948 i
.tm
.opcode_modifier
.evex
= EVEX256
;
3951 i
.tm
.opcode_modifier
.evex
= EVEX128
;
3960 if (op
>= MAX_OPERANDS
)
3964 switch (i
.tm
.opcode_modifier
.evex
)
3966 case EVEXLIG
: /* LL' is ignored */
3967 vec_length
= evexlig
<< 5;
3970 vec_length
= 0 << 5;
3973 vec_length
= 1 << 5;
3976 vec_length
= 2 << 5;
3981 vec_length
= 3 << 5;
3989 i
.vex
.bytes
[3] |= vec_length
;
3990 /* Encode the broadcast bit. */
3991 if (i
.broadcast
.type
|| i
.broadcast
.bytes
)
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
].bitfield
.imm8
= 1;
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 insn_name (&i
.tm
), 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'"), insn_name (&i
.tm
));
4069 /* Encode aligned vector move as unaligned vector move. */
4072 encode_with_unaligned_vector_move (void)
4074 switch (i
.tm
.base_opcode
)
4076 case 0x28: /* Load instructions. */
4077 case 0x29: /* Store instructions. */
4078 /* movaps/movapd/vmovaps/vmovapd. */
4079 if (i
.tm
.opcode_space
== SPACE_0F
4080 && i
.tm
.opcode_modifier
.opcodeprefix
<= PREFIX_0X66
)
4081 i
.tm
.base_opcode
= 0x10 | (i
.tm
.base_opcode
& 1);
4083 case 0x6f: /* Load instructions. */
4084 case 0x7f: /* Store instructions. */
4085 /* movdqa/vmovdqa/vmovdqa64/vmovdqa32. */
4086 if (i
.tm
.opcode_space
== SPACE_0F
4087 && i
.tm
.opcode_modifier
.opcodeprefix
== PREFIX_0X66
)
4088 i
.tm
.opcode_modifier
.opcodeprefix
= PREFIX_0XF3
;
4095 /* Try the shortest encoding by shortening operand size. */
4098 optimize_encoding (void)
4102 if (i
.tm
.mnem_off
== MN_lea
)
4105 lea symbol, %rN -> mov $symbol, %rN
4106 lea (%rM), %rN -> mov %rM, %rN
4107 lea (,%rM,1), %rN -> mov %rM, %rN
4109 and in 32-bit mode for 16-bit addressing
4111 lea (%rM), %rN -> movzx %rM, %rN
4113 and in 64-bit mode zap 32-bit addressing in favor of using a
4114 32-bit (or less) destination.
4116 if (flag_code
== CODE_64BIT
&& i
.prefix
[ADDR_PREFIX
])
4118 if (!i
.op
[1].regs
->reg_type
.bitfield
.word
)
4119 i
.tm
.opcode_modifier
.size
= SIZE32
;
4120 i
.prefix
[ADDR_PREFIX
] = 0;
4123 if (!i
.index_reg
&& !i
.base_reg
)
4126 lea symbol, %rN -> mov $symbol, %rN
4128 if (flag_code
== CODE_64BIT
)
4130 /* Don't transform a relocation to a 16-bit one. */
4132 && i
.op
[0].disps
->X_op
!= O_constant
4133 && i
.op
[1].regs
->reg_type
.bitfield
.word
)
4136 if (!i
.op
[1].regs
->reg_type
.bitfield
.qword
4137 || i
.tm
.opcode_modifier
.size
== SIZE32
)
4139 i
.tm
.base_opcode
= 0xb8;
4140 i
.tm
.opcode_modifier
.modrm
= 0;
4141 if (!i
.op
[1].regs
->reg_type
.bitfield
.word
)
4142 i
.types
[0].bitfield
.imm32
= 1;
4145 i
.tm
.opcode_modifier
.size
= SIZE16
;
4146 i
.types
[0].bitfield
.imm16
= 1;
4151 /* Subject to further optimization below. */
4152 i
.tm
.base_opcode
= 0xc7;
4153 i
.tm
.extension_opcode
= 0;
4154 i
.types
[0].bitfield
.imm32s
= 1;
4155 i
.types
[0].bitfield
.baseindex
= 0;
4158 /* Outside of 64-bit mode address and operand sizes have to match if
4159 a relocation is involved, as otherwise we wouldn't (currently) or
4160 even couldn't express the relocation correctly. */
4161 else if (i
.op
[0].disps
4162 && i
.op
[0].disps
->X_op
!= O_constant
4163 && ((!i
.prefix
[ADDR_PREFIX
])
4164 != (flag_code
== CODE_32BIT
4165 ? i
.op
[1].regs
->reg_type
.bitfield
.dword
4166 : i
.op
[1].regs
->reg_type
.bitfield
.word
)))
4168 /* In 16-bit mode converting LEA with 16-bit addressing and a 32-bit
4169 destination is going to grow encoding size. */
4170 else if (flag_code
== CODE_16BIT
4171 && (optimize
<= 1 || optimize_for_space
)
4172 && !i
.prefix
[ADDR_PREFIX
]
4173 && i
.op
[1].regs
->reg_type
.bitfield
.dword
)
4177 i
.tm
.base_opcode
= 0xb8;
4178 i
.tm
.opcode_modifier
.modrm
= 0;
4179 if (i
.op
[1].regs
->reg_type
.bitfield
.dword
)
4180 i
.types
[0].bitfield
.imm32
= 1;
4182 i
.types
[0].bitfield
.imm16
= 1;
4185 && i
.op
[0].disps
->X_op
== O_constant
4186 && i
.op
[1].regs
->reg_type
.bitfield
.dword
4187 /* NB: Add () to !i.prefix[ADDR_PREFIX] to silence
4189 && (!i
.prefix
[ADDR_PREFIX
]) != (flag_code
== CODE_32BIT
))
4190 i
.op
[0].disps
->X_add_number
&= 0xffff;
4193 i
.tm
.operand_types
[0] = i
.types
[0];
4197 i
.op
[0].imms
= &im_expressions
[0];
4198 i
.op
[0].imms
->X_op
= O_absent
;
4201 else if (i
.op
[0].disps
4202 && (i
.op
[0].disps
->X_op
!= O_constant
4203 || i
.op
[0].disps
->X_add_number
))
4208 lea (%rM), %rN -> mov %rM, %rN
4209 lea (,%rM,1), %rN -> mov %rM, %rN
4210 lea (%rM), %rN -> movzx %rM, %rN
4212 const reg_entry
*addr_reg
;
4214 if (!i
.index_reg
&& i
.base_reg
->reg_num
!= RegIP
)
4215 addr_reg
= i
.base_reg
;
4216 else if (!i
.base_reg
4217 && i
.index_reg
->reg_num
!= RegIZ
4218 && !i
.log2_scale_factor
)
4219 addr_reg
= i
.index_reg
;
4223 if (addr_reg
->reg_type
.bitfield
.word
4224 && i
.op
[1].regs
->reg_type
.bitfield
.dword
)
4226 if (flag_code
!= CODE_32BIT
)
4228 i
.tm
.opcode_space
= SPACE_0F
;
4229 i
.tm
.base_opcode
= 0xb7;
4232 i
.tm
.base_opcode
= 0x8b;
4234 if (addr_reg
->reg_type
.bitfield
.dword
4235 && i
.op
[1].regs
->reg_type
.bitfield
.qword
)
4236 i
.tm
.opcode_modifier
.size
= SIZE32
;
4238 i
.op
[0].regs
= addr_reg
;
4243 i
.disp_operands
= 0;
4244 i
.prefix
[ADDR_PREFIX
] = 0;
4245 i
.prefix
[SEG_PREFIX
] = 0;
4249 if (optimize_for_space
4250 && i
.tm
.mnem_off
== MN_test
4251 && i
.reg_operands
== 1
4252 && i
.imm_operands
== 1
4253 && !i
.types
[1].bitfield
.byte
4254 && i
.op
[0].imms
->X_op
== O_constant
4255 && fits_in_imm7 (i
.op
[0].imms
->X_add_number
))
4258 test $imm7, %r64/%r32/%r16 -> test $imm7, %r8
4260 unsigned int base_regnum
= i
.op
[1].regs
->reg_num
;
4261 if (flag_code
== CODE_64BIT
|| base_regnum
< 4)
4263 i
.types
[1].bitfield
.byte
= 1;
4264 /* Ignore the suffix. */
4266 /* Convert to byte registers. */
4267 if (i
.types
[1].bitfield
.word
)
4269 else if (i
.types
[1].bitfield
.dword
)
4273 if (!(i
.op
[1].regs
->reg_flags
& RegRex
) && base_regnum
< 4)
4278 else if (flag_code
== CODE_64BIT
4279 && i
.tm
.opcode_space
== SPACE_BASE
4280 && ((i
.types
[1].bitfield
.qword
4281 && i
.reg_operands
== 1
4282 && i
.imm_operands
== 1
4283 && i
.op
[0].imms
->X_op
== O_constant
4284 && ((i
.tm
.base_opcode
== 0xb8
4285 && i
.tm
.extension_opcode
== None
4286 && fits_in_unsigned_long (i
.op
[0].imms
->X_add_number
))
4287 || (fits_in_imm31 (i
.op
[0].imms
->X_add_number
)
4288 && (i
.tm
.base_opcode
== 0x24
4289 || (i
.tm
.base_opcode
== 0x80
4290 && i
.tm
.extension_opcode
== 0x4)
4291 || i
.tm
.mnem_off
== MN_test
4292 || ((i
.tm
.base_opcode
| 1) == 0xc7
4293 && i
.tm
.extension_opcode
== 0x0)))
4294 || (fits_in_imm7 (i
.op
[0].imms
->X_add_number
)
4295 && i
.tm
.base_opcode
== 0x83
4296 && i
.tm
.extension_opcode
== 0x4)))
4297 || (i
.types
[0].bitfield
.qword
4298 && ((i
.reg_operands
== 2
4299 && i
.op
[0].regs
== i
.op
[1].regs
4300 && (i
.tm
.mnem_off
== MN_xor
4301 || i
.tm
.mnem_off
== MN_sub
))
4302 || i
.tm
.mnem_off
== MN_clr
))))
4305 andq $imm31, %r64 -> andl $imm31, %r32
4306 andq $imm7, %r64 -> andl $imm7, %r32
4307 testq $imm31, %r64 -> testl $imm31, %r32
4308 xorq %r64, %r64 -> xorl %r32, %r32
4309 subq %r64, %r64 -> subl %r32, %r32
4310 movq $imm31, %r64 -> movl $imm31, %r32
4311 movq $imm32, %r64 -> movl $imm32, %r32
4313 i
.tm
.opcode_modifier
.size
= SIZE32
;
4316 i
.types
[0].bitfield
.imm32
= 1;
4317 i
.types
[0].bitfield
.imm32s
= 0;
4318 i
.types
[0].bitfield
.imm64
= 0;
4322 i
.types
[0].bitfield
.dword
= 1;
4323 i
.types
[0].bitfield
.qword
= 0;
4325 i
.types
[1].bitfield
.dword
= 1;
4326 i
.types
[1].bitfield
.qword
= 0;
4327 if (i
.tm
.mnem_off
== MN_mov
|| i
.tm
.mnem_off
== MN_lea
)
4330 movq $imm31, %r64 -> movl $imm31, %r32
4331 movq $imm32, %r64 -> movl $imm32, %r32
4333 i
.tm
.operand_types
[0].bitfield
.imm32
= 1;
4334 i
.tm
.operand_types
[0].bitfield
.imm32s
= 0;
4335 i
.tm
.operand_types
[0].bitfield
.imm64
= 0;
4336 if ((i
.tm
.base_opcode
| 1) == 0xc7)
4339 movq $imm31, %r64 -> movl $imm31, %r32
4341 i
.tm
.base_opcode
= 0xb8;
4342 i
.tm
.extension_opcode
= None
;
4343 i
.tm
.opcode_modifier
.w
= 0;
4344 i
.tm
.opcode_modifier
.modrm
= 0;
4348 else if (optimize
> 1
4349 && !optimize_for_space
4350 && i
.reg_operands
== 2
4351 && i
.op
[0].regs
== i
.op
[1].regs
4352 && (i
.tm
.mnem_off
== MN_and
|| i
.tm
.mnem_off
== MN_or
)
4353 && (flag_code
!= CODE_64BIT
|| !i
.types
[0].bitfield
.dword
))
4356 andb %rN, %rN -> testb %rN, %rN
4357 andw %rN, %rN -> testw %rN, %rN
4358 andq %rN, %rN -> testq %rN, %rN
4359 orb %rN, %rN -> testb %rN, %rN
4360 orw %rN, %rN -> testw %rN, %rN
4361 orq %rN, %rN -> testq %rN, %rN
4363 and outside of 64-bit mode
4365 andl %rN, %rN -> testl %rN, %rN
4366 orl %rN, %rN -> testl %rN, %rN
4368 i
.tm
.base_opcode
= 0x84 | (i
.tm
.base_opcode
& 1);
4370 else if (i
.tm
.base_opcode
== 0xba
4371 && i
.tm
.opcode_space
== SPACE_0F
4372 && i
.reg_operands
== 1
4373 && i
.op
[0].imms
->X_op
== O_constant
4374 && i
.op
[0].imms
->X_add_number
>= 0)
4377 btw $n, %rN -> btl $n, %rN (outside of 16-bit mode, n < 16)
4378 btq $n, %rN -> btl $n, %rN (in 64-bit mode, n < 32, N < 8)
4379 btl $n, %rN -> btw $n, %rN (in 16-bit mode, n < 16)
4381 With <BT> one of bts, btr, and bts also:
4382 <BT>w $n, %rN -> btl $n, %rN (in 32-bit mode, n < 16)
4383 <BT>l $n, %rN -> btw $n, %rN (in 16-bit mode, n < 16)
4388 if (i
.tm
.extension_opcode
!= 4)
4390 if (i
.types
[1].bitfield
.qword
4391 && i
.op
[0].imms
->X_add_number
< 32
4392 && !(i
.op
[1].regs
->reg_flags
& RegRex
))
4393 i
.tm
.opcode_modifier
.size
= SIZE32
;
4396 if (i
.types
[1].bitfield
.word
4397 && i
.op
[0].imms
->X_add_number
< 16)
4398 i
.tm
.opcode_modifier
.size
= SIZE32
;
4401 if (i
.op
[0].imms
->X_add_number
< 16)
4402 i
.tm
.opcode_modifier
.size
= SIZE16
;
4406 else if (i
.reg_operands
== 3
4407 && i
.op
[0].regs
== i
.op
[1].regs
4408 && !i
.types
[2].bitfield
.xmmword
4409 && (i
.tm
.opcode_modifier
.vex
4410 || ((!i
.mask
.reg
|| i
.mask
.zeroing
)
4411 && is_evex_encoding (&i
.tm
)
4412 && (i
.vec_encoding
!= vex_encoding_evex
4413 || cpu_arch_isa_flags
.bitfield
.cpuavx512vl
4414 || i
.tm
.cpu_flags
.bitfield
.cpuavx512vl
4415 || (i
.tm
.operand_types
[2].bitfield
.zmmword
4416 && i
.types
[2].bitfield
.ymmword
))))
4417 && i
.tm
.opcode_space
== SPACE_0F
4418 && ((i
.tm
.base_opcode
| 2) == 0x57
4419 || i
.tm
.base_opcode
== 0xdf
4420 || i
.tm
.base_opcode
== 0xef
4421 || (i
.tm
.base_opcode
| 3) == 0xfb
4422 || i
.tm
.base_opcode
== 0x42
4423 || i
.tm
.base_opcode
== 0x47))
4426 VOP, one of vandnps, vandnpd, vxorps, vxorpd, vpsubb, vpsubd,
4428 EVEX VOP %zmmM, %zmmM, %zmmN
4429 -> VEX VOP %xmmM, %xmmM, %xmmN (M and N < 16)
4430 -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2)
4431 EVEX VOP %ymmM, %ymmM, %ymmN
4432 -> VEX VOP %xmmM, %xmmM, %xmmN (M and N < 16)
4433 -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2)
4434 VEX VOP %ymmM, %ymmM, %ymmN
4435 -> VEX VOP %xmmM, %xmmM, %xmmN
4436 VOP, one of vpandn and vpxor:
4437 VEX VOP %ymmM, %ymmM, %ymmN
4438 -> VEX VOP %xmmM, %xmmM, %xmmN
4439 VOP, one of vpandnd and vpandnq:
4440 EVEX VOP %zmmM, %zmmM, %zmmN
4441 -> VEX vpandn %xmmM, %xmmM, %xmmN (M and N < 16)
4442 -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2)
4443 EVEX VOP %ymmM, %ymmM, %ymmN
4444 -> VEX vpandn %xmmM, %xmmM, %xmmN (M and N < 16)
4445 -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2)
4446 VOP, one of vpxord and vpxorq:
4447 EVEX VOP %zmmM, %zmmM, %zmmN
4448 -> VEX vpxor %xmmM, %xmmM, %xmmN (M and N < 16)
4449 -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2)
4450 EVEX VOP %ymmM, %ymmM, %ymmN
4451 -> VEX vpxor %xmmM, %xmmM, %xmmN (M and N < 16)
4452 -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2)
4453 VOP, one of kxord and kxorq:
4454 VEX VOP %kM, %kM, %kN
4455 -> VEX kxorw %kM, %kM, %kN
4456 VOP, one of kandnd and kandnq:
4457 VEX VOP %kM, %kM, %kN
4458 -> VEX kandnw %kM, %kM, %kN
4460 if (is_evex_encoding (&i
.tm
))
4462 if (i
.vec_encoding
!= vex_encoding_evex
)
4464 i
.tm
.opcode_modifier
.vex
= VEX128
;
4465 i
.tm
.opcode_modifier
.vexw
= VEXW0
;
4466 i
.tm
.opcode_modifier
.evex
= 0;
4468 else if (optimize
> 1)
4469 i
.tm
.opcode_modifier
.evex
= EVEX128
;
4473 else if (i
.tm
.operand_types
[0].bitfield
.class == RegMask
)
4475 i
.tm
.opcode_modifier
.opcodeprefix
= PREFIX_NONE
;
4476 i
.tm
.opcode_modifier
.vexw
= VEXW0
;
4479 i
.tm
.opcode_modifier
.vex
= VEX128
;
4481 if (i
.tm
.opcode_modifier
.vex
)
4482 for (j
= 0; j
< 3; j
++)
4484 i
.types
[j
].bitfield
.xmmword
= 1;
4485 i
.types
[j
].bitfield
.ymmword
= 0;
4488 else if (i
.vec_encoding
!= vex_encoding_evex
4489 && !i
.types
[0].bitfield
.zmmword
4490 && !i
.types
[1].bitfield
.zmmword
4492 && !i
.broadcast
.type
4493 && !i
.broadcast
.bytes
4494 && is_evex_encoding (&i
.tm
)
4495 && ((i
.tm
.base_opcode
& ~Opcode_SIMD_IntD
) == 0x6f
4496 || (i
.tm
.base_opcode
& ~4) == 0xdb
4497 || (i
.tm
.base_opcode
& ~4) == 0xeb)
4498 && i
.tm
.extension_opcode
== None
)
4501 VOP, one of vmovdqa32, vmovdqa64, vmovdqu8, vmovdqu16,
4502 vmovdqu32 and vmovdqu64:
4503 EVEX VOP %xmmM, %xmmN
4504 -> VEX vmovdqa|vmovdqu %xmmM, %xmmN (M and N < 16)
4505 EVEX VOP %ymmM, %ymmN
4506 -> VEX vmovdqa|vmovdqu %ymmM, %ymmN (M and N < 16)
4508 -> VEX vmovdqa|vmovdqu %xmmM, mem (M < 16)
4510 -> VEX vmovdqa|vmovdqu %ymmM, mem (M < 16)
4512 -> VEX mvmovdqa|vmovdquem, %xmmN (N < 16)
4514 -> VEX vmovdqa|vmovdqu mem, %ymmN (N < 16)
4515 VOP, one of vpand, vpandn, vpor, vpxor:
4516 EVEX VOP{d,q} %xmmL, %xmmM, %xmmN
4517 -> VEX VOP %xmmL, %xmmM, %xmmN (L, M, and N < 16)
4518 EVEX VOP{d,q} %ymmL, %ymmM, %ymmN
4519 -> VEX VOP %ymmL, %ymmM, %ymmN (L, M, and N < 16)
4520 EVEX VOP{d,q} mem, %xmmM, %xmmN
4521 -> VEX VOP mem, %xmmM, %xmmN (M and N < 16)
4522 EVEX VOP{d,q} mem, %ymmM, %ymmN
4523 -> VEX VOP mem, %ymmM, %ymmN (M and N < 16)
4525 for (j
= 0; j
< i
.operands
; j
++)
4526 if (operand_type_check (i
.types
[j
], disp
)
4527 && i
.op
[j
].disps
->X_op
== O_constant
)
4529 /* Since the VEX prefix has 2 or 3 bytes, the EVEX prefix
4530 has 4 bytes, EVEX Disp8 has 1 byte and VEX Disp32 has 4
4531 bytes, we choose EVEX Disp8 over VEX Disp32. */
4532 int evex_disp8
, vex_disp8
;
4533 unsigned int memshift
= i
.memshift
;
4534 offsetT n
= i
.op
[j
].disps
->X_add_number
;
4536 evex_disp8
= fits_in_disp8 (n
);
4538 vex_disp8
= fits_in_disp8 (n
);
4539 if (evex_disp8
!= vex_disp8
)
4541 i
.memshift
= memshift
;
4545 i
.types
[j
].bitfield
.disp8
= vex_disp8
;
4548 if ((i
.tm
.base_opcode
& ~Opcode_SIMD_IntD
) == 0x6f
4549 && i
.tm
.opcode_modifier
.opcodeprefix
== PREFIX_0XF2
)
4550 i
.tm
.opcode_modifier
.opcodeprefix
= PREFIX_0XF3
;
4551 i
.tm
.opcode_modifier
.vex
4552 = i
.types
[0].bitfield
.ymmword
? VEX256
: VEX128
;
4553 i
.tm
.opcode_modifier
.vexw
= VEXW0
;
4554 /* VPAND, VPOR, and VPXOR are commutative. */
4555 if (i
.reg_operands
== 3 && i
.tm
.base_opcode
!= 0xdf)
4556 i
.tm
.opcode_modifier
.commutative
= 1;
4557 i
.tm
.opcode_modifier
.evex
= 0;
4558 i
.tm
.opcode_modifier
.masking
= 0;
4559 i
.tm
.opcode_modifier
.broadcast
= 0;
4560 i
.tm
.opcode_modifier
.disp8memshift
= 0;
4563 i
.types
[j
].bitfield
.disp8
4564 = fits_in_disp8 (i
.op
[j
].disps
->X_add_number
);
4568 /* Return non-zero for load instruction. */
4574 int any_vex_p
= is_any_vex_encoding (&i
.tm
);
4575 unsigned int base_opcode
= i
.tm
.base_opcode
| 1;
4579 /* Anysize insns: lea, invlpg, clflush, prefetch*, bndmk, bndcl, bndcu,
4580 bndcn, bndstx, bndldx, clflushopt, clwb, cldemote. */
4581 if (i
.tm
.opcode_modifier
.operandconstraint
== ANY_SIZE
)
4585 if (i
.tm
.mnem_off
== MN_pop
)
4589 if (i
.tm
.opcode_space
== SPACE_BASE
)
4592 if (i
.tm
.base_opcode
== 0x9d
4593 || i
.tm
.base_opcode
== 0x61)
4596 /* movs, cmps, lods, scas. */
4597 if ((i
.tm
.base_opcode
| 0xb) == 0xaf)
4601 if (base_opcode
== 0x6f
4602 || i
.tm
.base_opcode
== 0xd7)
4604 /* NB: For AMD-specific insns with implicit memory operands,
4605 they're intentionally not covered. */
4608 /* No memory operand. */
4609 if (!i
.mem_operands
)
4614 if (i
.tm
.mnem_off
== MN_vldmxcsr
)
4617 else if (i
.tm
.opcode_space
== SPACE_BASE
)
4619 /* test, not, neg, mul, imul, div, idiv. */
4620 if (base_opcode
== 0xf7 && i
.tm
.extension_opcode
!= 1)
4624 if (base_opcode
== 0xff && i
.tm
.extension_opcode
<= 1)
4627 /* add, or, adc, sbb, and, sub, xor, cmp. */
4628 if (i
.tm
.base_opcode
>= 0x80 && i
.tm
.base_opcode
<= 0x83)
4631 /* rol, ror, rcl, rcr, shl/sal, shr, sar. */
4632 if ((base_opcode
== 0xc1 || (base_opcode
| 2) == 0xd3)
4633 && i
.tm
.extension_opcode
!= 6)
4636 /* Check for x87 instructions. */
4637 if ((base_opcode
| 6) == 0xdf)
4639 /* Skip fst, fstp, fstenv, fstcw. */
4640 if (i
.tm
.base_opcode
== 0xd9
4641 && (i
.tm
.extension_opcode
== 2
4642 || i
.tm
.extension_opcode
== 3
4643 || i
.tm
.extension_opcode
== 6
4644 || i
.tm
.extension_opcode
== 7))
4647 /* Skip fisttp, fist, fistp, fstp. */
4648 if (i
.tm
.base_opcode
== 0xdb
4649 && (i
.tm
.extension_opcode
== 1
4650 || i
.tm
.extension_opcode
== 2
4651 || i
.tm
.extension_opcode
== 3
4652 || i
.tm
.extension_opcode
== 7))
4655 /* Skip fisttp, fst, fstp, fsave, fstsw. */
4656 if (i
.tm
.base_opcode
== 0xdd
4657 && (i
.tm
.extension_opcode
== 1
4658 || i
.tm
.extension_opcode
== 2
4659 || i
.tm
.extension_opcode
== 3
4660 || i
.tm
.extension_opcode
== 6
4661 || i
.tm
.extension_opcode
== 7))
4664 /* Skip fisttp, fist, fistp, fbstp, fistp. */
4665 if (i
.tm
.base_opcode
== 0xdf
4666 && (i
.tm
.extension_opcode
== 1
4667 || i
.tm
.extension_opcode
== 2
4668 || i
.tm
.extension_opcode
== 3
4669 || i
.tm
.extension_opcode
== 6
4670 || i
.tm
.extension_opcode
== 7))
4676 else if (i
.tm
.opcode_space
== SPACE_0F
)
4678 /* bt, bts, btr, btc. */
4679 if (i
.tm
.base_opcode
== 0xba
4680 && (i
.tm
.extension_opcode
| 3) == 7)
4683 /* cmpxchg8b, cmpxchg16b, xrstors, vmptrld. */
4684 if (i
.tm
.base_opcode
== 0xc7
4685 && i
.tm
.opcode_modifier
.opcodeprefix
== PREFIX_NONE
4686 && (i
.tm
.extension_opcode
== 1 || i
.tm
.extension_opcode
== 3
4687 || i
.tm
.extension_opcode
== 6))
4690 /* fxrstor, ldmxcsr, xrstor. */
4691 if (i
.tm
.base_opcode
== 0xae
4692 && (i
.tm
.extension_opcode
== 1
4693 || i
.tm
.extension_opcode
== 2
4694 || i
.tm
.extension_opcode
== 5))
4697 /* lgdt, lidt, lmsw. */
4698 if (i
.tm
.base_opcode
== 0x01
4699 && (i
.tm
.extension_opcode
== 2
4700 || i
.tm
.extension_opcode
== 3
4701 || i
.tm
.extension_opcode
== 6))
4705 dest
= i
.operands
- 1;
4707 /* Check fake imm8 operand and 3 source operands. */
4708 if ((i
.tm
.opcode_modifier
.immext
4709 || i
.reg_operands
+ i
.mem_operands
== 4)
4710 && i
.types
[dest
].bitfield
.imm8
)
4713 /* add, or, adc, sbb, and, sub, xor, cmp, test, xchg. */
4714 if (i
.tm
.opcode_space
== SPACE_BASE
4715 && ((base_opcode
| 0x38) == 0x39
4716 || (base_opcode
| 2) == 0x87))
4719 if (i
.tm
.mnem_off
== MN_xadd
)
4722 /* Check for load instruction. */
4723 return (i
.types
[dest
].bitfield
.class != ClassNone
4724 || i
.types
[dest
].bitfield
.instance
== Accum
);
4727 /* Output lfence, 0xfaee8, after instruction. */
4730 insert_lfence_after (void)
4732 if (lfence_after_load
&& load_insn_p ())
4734 /* There are also two REP string instructions that require
4735 special treatment. Specifically, the compare string (CMPS)
4736 and scan string (SCAS) instructions set EFLAGS in a manner
4737 that depends on the data being compared/scanned. When used
4738 with a REP prefix, the number of iterations may therefore
4739 vary depending on this data. If the data is a program secret
4740 chosen by the adversary using an LVI method,
4741 then this data-dependent behavior may leak some aspect
4743 if (((i
.tm
.base_opcode
| 0x9) == 0xaf)
4744 && i
.prefix
[REP_PREFIX
])
4746 as_warn (_("`%s` changes flags which would affect control flow behavior"),
4749 char *p
= frag_more (3);
4756 /* Output lfence, 0xfaee8, before instruction. */
4759 insert_lfence_before (void)
4763 if (i
.tm
.opcode_space
!= SPACE_BASE
)
4766 if (i
.tm
.base_opcode
== 0xff
4767 && (i
.tm
.extension_opcode
== 2 || i
.tm
.extension_opcode
== 4))
4769 /* Insert lfence before indirect branch if needed. */
4771 if (lfence_before_indirect_branch
== lfence_branch_none
)
4774 if (i
.operands
!= 1)
4777 if (i
.reg_operands
== 1)
4779 /* Indirect branch via register. Don't insert lfence with
4780 -mlfence-after-load=yes. */
4781 if (lfence_after_load
4782 || lfence_before_indirect_branch
== lfence_branch_memory
)
4785 else if (i
.mem_operands
== 1
4786 && lfence_before_indirect_branch
!= lfence_branch_register
)
4788 as_warn (_("indirect `%s` with memory operand should be avoided"),
4795 if (last_insn
.kind
!= last_insn_other
4796 && last_insn
.seg
== now_seg
)
4798 as_warn_where (last_insn
.file
, last_insn
.line
,
4799 _("`%s` skips -mlfence-before-indirect-branch on `%s`"),
4800 last_insn
.name
, insn_name (&i
.tm
));
4811 /* Output or/not/shl and lfence before near ret. */
4812 if (lfence_before_ret
!= lfence_before_ret_none
4813 && (i
.tm
.base_opcode
| 1) == 0xc3)
4815 if (last_insn
.kind
!= last_insn_other
4816 && last_insn
.seg
== now_seg
)
4818 as_warn_where (last_insn
.file
, last_insn
.line
,
4819 _("`%s` skips -mlfence-before-ret on `%s`"),
4820 last_insn
.name
, insn_name (&i
.tm
));
4824 /* Near ret ingore operand size override under CPU64. */
4825 char prefix
= flag_code
== CODE_64BIT
4827 : i
.prefix
[DATA_PREFIX
] ? 0x66 : 0x0;
4829 if (lfence_before_ret
== lfence_before_ret_not
)
4831 /* not: 0xf71424, may add prefix
4832 for operand size override or 64-bit code. */
4833 p
= frag_more ((prefix
? 2 : 0) + 6 + 3);
4847 p
= frag_more ((prefix
? 1 : 0) + 4 + 3);
4850 if (lfence_before_ret
== lfence_before_ret_or
)
4852 /* or: 0x830c2400, may add prefix
4853 for operand size override or 64-bit code. */
4859 /* shl: 0xc1242400, may add prefix
4860 for operand size override or 64-bit code. */
4875 /* Shared helper for md_assemble() and s_insn(). */
4876 static void init_globals (void)
4880 memset (&i
, '\0', sizeof (i
));
4881 i
.rounding
.type
= rc_none
;
4882 for (j
= 0; j
< MAX_OPERANDS
; j
++)
4883 i
.reloc
[j
] = NO_RELOC
;
4884 memset (disp_expressions
, '\0', sizeof (disp_expressions
));
4885 memset (im_expressions
, '\0', sizeof (im_expressions
));
4886 save_stack_p
= save_stack
;
4889 /* Helper for md_assemble() to decide whether to prepare for a possible 2nd
4890 parsing pass. Instead of introducing a rarely use new insn attribute this
4891 utilizes a common pattern between affected templates. It is deemed
4892 acceptable that this will lead to unnecessary pass 2 preparations in a
4893 limited set of cases. */
4894 static INLINE
bool may_need_pass2 (const insn_template
*t
)
4896 return t
->opcode_modifier
.sse2avx
4897 /* Note that all SSE2AVX templates have at least one operand. */
4898 ? t
->operand_types
[t
->operands
- 1].bitfield
.class == RegSIMD
4899 : (t
->opcode_space
== SPACE_0F
4900 && (t
->base_opcode
| 1) == 0xbf)
4901 || (t
->opcode_space
== SPACE_BASE
4902 && t
->base_opcode
== 0x63);
4905 /* This is the guts of the machine-dependent assembler. LINE points to a
4906 machine dependent instruction. This function is supposed to emit
4907 the frags/bytes it assembles to. */
4910 md_assemble (char *line
)
4913 char mnemonic
[MAX_MNEM_SIZE
], mnem_suffix
= 0, *copy
= NULL
;
4914 const char *end
, *pass1_mnem
= NULL
;
4915 enum i386_error pass1_err
= 0;
4916 const insn_template
*t
;
4918 /* Initialize globals. */
4919 current_templates
= NULL
;
4923 /* First parse an instruction mnemonic & call i386_operand for the operands.
4924 We assume that the scrubber has arranged it so that line[0] is the valid
4925 start of a (possibly prefixed) mnemonic. */
4927 end
= parse_insn (line
, mnemonic
, false);
4930 if (pass1_mnem
!= NULL
)
4932 if (i
.error
!= no_error
)
4934 gas_assert (current_templates
!= NULL
);
4935 if (may_need_pass2 (current_templates
->start
) && !i
.suffix
)
4937 /* No point in trying a 2nd pass - it'll only find the same suffix
4939 mnem_suffix
= i
.suffix
;
4944 t
= current_templates
->start
;
4945 if (may_need_pass2 (t
))
4947 /* Make a copy of the full line in case we need to retry. */
4948 copy
= xstrdup (line
);
4951 mnem_suffix
= i
.suffix
;
4953 line
= parse_operands (line
, mnemonic
);
4961 /* Now we've parsed the mnemonic into a set of templates, and have the
4962 operands at hand. */
4964 /* All Intel opcodes have reversed operands except for "bound", "enter",
4965 "invlpg*", "monitor*", "mwait*", "tpause", "umwait", "pvalidate",
4966 "rmpadjust", "rmpupdate", and "rmpquery". We also don't reverse
4967 intersegment "jmp" and "call" instructions with 2 immediate operands so
4968 that the immediate segment precedes the offset consistently in Intel and
4972 && (t
->mnem_off
!= MN_bound
)
4973 && !startswith (mnemonic
, "invlpg")
4974 && !startswith (mnemonic
, "monitor")
4975 && !startswith (mnemonic
, "mwait")
4976 && (t
->mnem_off
!= MN_pvalidate
)
4977 && !startswith (mnemonic
, "rmp")
4978 && (t
->mnem_off
!= MN_tpause
)
4979 && (t
->mnem_off
!= MN_umwait
)
4980 && !(i
.operands
== 2
4981 && operand_type_check (i
.types
[0], imm
)
4982 && operand_type_check (i
.types
[1], imm
)))
4985 /* The order of the immediates should be reversed
4986 for 2 immediates extrq and insertq instructions */
4987 if (i
.imm_operands
== 2
4988 && (t
->mnem_off
== MN_extrq
|| t
->mnem_off
== MN_insertq
))
4989 swap_2_operands (0, 1);
4994 if (i
.disp_operands
&& !optimize_disp (t
))
4997 /* Next, we find a template that matches the given insn,
4998 making sure the overlap of the given operands types is consistent
4999 with the template operand types. */
5001 if (!(t
= match_template (mnem_suffix
)))
5003 const char *err_msg
;
5005 if (copy
&& !mnem_suffix
)
5010 pass1_err
= i
.error
;
5011 pass1_mnem
= insn_name (current_templates
->start
);
5015 /* If a non-/only-64bit template (group) was found in pass 1, and if
5016 _some_ template (group) was found in pass 2, squash pass 1's
5018 if (pass1_err
== unsupported_64bit
)
5024 switch (pass1_mnem
? pass1_err
: i
.error
)
5028 case operand_size_mismatch
:
5029 err_msg
= _("operand size mismatch");
5031 case operand_type_mismatch
:
5032 err_msg
= _("operand type mismatch");
5034 case register_type_mismatch
:
5035 err_msg
= _("register type mismatch");
5037 case number_of_operands_mismatch
:
5038 err_msg
= _("number of operands mismatch");
5040 case invalid_instruction_suffix
:
5041 err_msg
= _("invalid instruction suffix");
5044 err_msg
= _("constant doesn't fit in 4 bits");
5046 case unsupported_with_intel_mnemonic
:
5047 err_msg
= _("unsupported with Intel mnemonic");
5049 case unsupported_syntax
:
5050 err_msg
= _("unsupported syntax");
5053 as_bad (_("unsupported instruction `%s'"),
5054 pass1_mnem
? pass1_mnem
: insn_name (current_templates
->start
));
5056 case unsupported_on_arch
:
5057 as_bad (_("`%s' is not supported on `%s%s'"),
5058 pass1_mnem
? pass1_mnem
: insn_name (current_templates
->start
),
5059 cpu_arch_name
? cpu_arch_name
: default_arch
,
5060 cpu_sub_arch_name
? cpu_sub_arch_name
: "");
5062 case unsupported_64bit
:
5063 if (ISLOWER (mnem_suffix
))
5065 if (flag_code
== CODE_64BIT
)
5066 as_bad (_("`%s%c' is not supported in 64-bit mode"),
5067 pass1_mnem
? pass1_mnem
: insn_name (current_templates
->start
),
5070 as_bad (_("`%s%c' is only supported in 64-bit mode"),
5071 pass1_mnem
? pass1_mnem
: insn_name (current_templates
->start
),
5076 if (flag_code
== CODE_64BIT
)
5077 as_bad (_("`%s' is not supported in 64-bit mode"),
5078 pass1_mnem
? pass1_mnem
: insn_name (current_templates
->start
));
5080 as_bad (_("`%s' is only supported in 64-bit mode"),
5081 pass1_mnem
? pass1_mnem
: insn_name (current_templates
->start
));
5084 case invalid_sib_address
:
5085 err_msg
= _("invalid SIB address");
5087 case invalid_vsib_address
:
5088 err_msg
= _("invalid VSIB address");
5090 case invalid_vector_register_set
:
5091 err_msg
= _("mask, index, and destination registers must be distinct");
5093 case invalid_tmm_register_set
:
5094 err_msg
= _("all tmm registers must be distinct");
5096 case invalid_dest_and_src_register_set
:
5097 err_msg
= _("destination and source registers must be distinct");
5099 case unsupported_vector_index_register
:
5100 err_msg
= _("unsupported vector index register");
5102 case unsupported_broadcast
:
5103 err_msg
= _("unsupported broadcast");
5105 case broadcast_needed
:
5106 err_msg
= _("broadcast is needed for operand of such type");
5108 case unsupported_masking
:
5109 err_msg
= _("unsupported masking");
5111 case mask_not_on_destination
:
5112 err_msg
= _("mask not on destination operand");
5114 case no_default_mask
:
5115 err_msg
= _("default mask isn't allowed");
5117 case unsupported_rc_sae
:
5118 err_msg
= _("unsupported static rounding/sae");
5120 case invalid_register_operand
:
5121 err_msg
= _("invalid register operand");
5124 as_bad (_("%s for `%s'"), err_msg
,
5125 pass1_mnem
? pass1_mnem
: insn_name (current_templates
->start
));
5131 if (sse_check
!= check_none
5132 /* The opcode space check isn't strictly needed; it's there only to
5133 bypass the logic below when easily possible. */
5134 && t
->opcode_space
>= SPACE_0F
5135 && t
->opcode_space
<= SPACE_0F3A
5136 && !i
.tm
.cpu_flags
.bitfield
.cpusse4a
5137 && !is_any_vex_encoding (t
))
5141 for (j
= 0; j
< t
->operands
; ++j
)
5143 if (t
->operand_types
[j
].bitfield
.class == RegMMX
)
5145 if (t
->operand_types
[j
].bitfield
.class == RegSIMD
)
5149 if (j
>= t
->operands
&& simd
)
5150 (sse_check
== check_warning
5152 : as_bad
) (_("SSE instruction `%s' is used"), insn_name (&i
.tm
));
5155 if (i
.tm
.opcode_modifier
.fwait
)
5156 if (!add_prefix (FWAIT_OPCODE
))
5159 /* Check if REP prefix is OK. */
5160 if (i
.rep_prefix
&& i
.tm
.opcode_modifier
.prefixok
!= PrefixRep
)
5162 as_bad (_("invalid instruction `%s' after `%s'"),
5163 insn_name (&i
.tm
), i
.rep_prefix
);
5167 /* Check for lock without a lockable instruction. Destination operand
5168 must be memory unless it is xchg (0x86). */
5169 if (i
.prefix
[LOCK_PREFIX
])
5171 if (i
.tm
.opcode_modifier
.prefixok
< PrefixLock
5172 || i
.mem_operands
== 0
5173 || (i
.tm
.base_opcode
!= 0x86
5174 && !(i
.flags
[i
.operands
- 1] & Operand_Mem
)))
5176 as_bad (_("expecting lockable instruction after `lock'"));
5180 /* Zap the redundant prefix from XCHG when optimizing. */
5181 if (i
.tm
.base_opcode
== 0x86 && optimize
&& !i
.no_optimize
)
5182 i
.prefix
[LOCK_PREFIX
] = 0;
5185 if (is_any_vex_encoding (&i
.tm
)
5186 || i
.tm
.operand_types
[i
.imm_operands
].bitfield
.class >= RegMMX
5187 || i
.tm
.operand_types
[i
.imm_operands
+ 1].bitfield
.class >= RegMMX
)
5189 /* Check for data size prefix on VEX/XOP/EVEX encoded and SIMD insns. */
5190 if (i
.prefix
[DATA_PREFIX
])
5192 as_bad (_("data size prefix invalid with `%s'"), insn_name (&i
.tm
));
5196 /* Don't allow e.g. KMOV in TLS code sequences. */
5197 for (j
= i
.imm_operands
; j
< i
.operands
; ++j
)
5200 case BFD_RELOC_386_TLS_GOTIE
:
5201 case BFD_RELOC_386_TLS_LE_32
:
5202 case BFD_RELOC_X86_64_GOTTPOFF
:
5203 case BFD_RELOC_X86_64_TLSLD
:
5204 as_bad (_("TLS relocation cannot be used with `%s'"), insn_name (&i
.tm
));
5211 /* Check if HLE prefix is OK. */
5212 if (i
.hle_prefix
&& !check_hle ())
5215 /* Check BND prefix. */
5216 if (i
.bnd_prefix
&& !i
.tm
.opcode_modifier
.bndprefixok
)
5217 as_bad (_("expecting valid branch instruction after `bnd'"));
5219 /* Check NOTRACK prefix. */
5220 if (i
.notrack_prefix
&& i
.tm
.opcode_modifier
.prefixok
!= PrefixNoTrack
)
5221 as_bad (_("expecting indirect branch instruction after `notrack'"));
5223 if (i
.tm
.cpu_flags
.bitfield
.cpumpx
)
5225 if (flag_code
== CODE_64BIT
&& i
.prefix
[ADDR_PREFIX
])
5226 as_bad (_("32-bit address isn't allowed in 64-bit MPX instructions."));
5227 else if (flag_code
!= CODE_16BIT
5228 ? i
.prefix
[ADDR_PREFIX
]
5229 : i
.mem_operands
&& !i
.prefix
[ADDR_PREFIX
])
5230 as_bad (_("16-bit address isn't allowed in MPX instructions"));
5233 /* Insert BND prefix. */
5234 if (add_bnd_prefix
&& i
.tm
.opcode_modifier
.bndprefixok
)
5236 if (!i
.prefix
[BND_PREFIX
])
5237 add_prefix (BND_PREFIX_OPCODE
);
5238 else if (i
.prefix
[BND_PREFIX
] != BND_PREFIX_OPCODE
)
5240 as_warn (_("replacing `rep'/`repe' prefix by `bnd'"));
5241 i
.prefix
[BND_PREFIX
] = BND_PREFIX_OPCODE
;
5245 /* Check string instruction segment overrides. */
5246 if (i
.tm
.opcode_modifier
.isstring
>= IS_STRING_ES_OP0
)
5248 gas_assert (i
.mem_operands
);
5249 if (!check_string ())
5251 i
.disp_operands
= 0;
5254 /* The memory operand of (%dx) should be only used with input/output
5255 instructions (base opcodes: 0x6c, 0x6e, 0xec, 0xee). */
5256 if (i
.input_output_operand
5257 && ((i
.tm
.base_opcode
| 0x82) != 0xee
5258 || i
.tm
.opcode_space
!= SPACE_BASE
))
5260 as_bad (_("input/output port address isn't allowed with `%s'"),
5265 if (optimize
&& !i
.no_optimize
&& i
.tm
.opcode_modifier
.optimize
)
5266 optimize_encoding ();
5268 if (use_unaligned_vector_move
)
5269 encode_with_unaligned_vector_move ();
5271 if (!process_suffix ())
5274 /* Check if IP-relative addressing requirements can be satisfied. */
5275 if (i
.tm
.cpu_flags
.bitfield
.cpuprefetchi
5276 && !(i
.base_reg
&& i
.base_reg
->reg_num
== RegIP
))
5277 as_warn (_("'%s' only supports RIP-relative address"), insn_name (&i
.tm
));
5279 /* Update operand types and check extended states. */
5280 for (j
= 0; j
< i
.operands
; j
++)
5282 i
.types
[j
] = operand_type_and (i
.types
[j
], i
.tm
.operand_types
[j
]);
5283 switch (i
.tm
.operand_types
[j
].bitfield
.class)
5288 i
.xstate
|= xstate_mmx
;
5291 i
.xstate
|= xstate_mask
;
5294 if (i
.tm
.operand_types
[j
].bitfield
.tmmword
)
5295 i
.xstate
|= xstate_tmm
;
5296 else if (i
.tm
.operand_types
[j
].bitfield
.zmmword
)
5297 i
.xstate
|= xstate_zmm
;
5298 else if (i
.tm
.operand_types
[j
].bitfield
.ymmword
)
5299 i
.xstate
|= xstate_ymm
;
5300 else if (i
.tm
.operand_types
[j
].bitfield
.xmmword
)
5301 i
.xstate
|= xstate_xmm
;
5306 /* Make still unresolved immediate matches conform to size of immediate
5307 given in i.suffix. */
5308 if (!finalize_imm ())
5311 if (i
.types
[0].bitfield
.imm1
)
5312 i
.imm_operands
= 0; /* kludge for shift insns. */
5314 /* For insns with operands there are more diddles to do to the opcode. */
5317 if (!process_operands ())
5320 else if (!quiet_warnings
&& i
.tm
.opcode_modifier
.operandconstraint
== UGH
)
5322 /* UnixWare fsub no args is alias for fsubp, fadd -> faddp, etc. */
5323 as_warn (_("translating to `%sp'"), insn_name (&i
.tm
));
5326 if (is_any_vex_encoding (&i
.tm
))
5328 if (!cpu_arch_flags
.bitfield
.cpui286
)
5330 as_bad (_("instruction `%s' isn't supported outside of protected mode."),
5335 /* Check for explicit REX prefix. */
5336 if (i
.prefix
[REX_PREFIX
] || i
.rex_encoding
)
5338 as_bad (_("REX prefix invalid with `%s'"), insn_name (&i
.tm
));
5342 if (i
.tm
.opcode_modifier
.vex
)
5343 build_vex_prefix (t
);
5345 build_evex_prefix ();
5347 /* The individual REX.RXBW bits got consumed. */
5348 i
.rex
&= REX_OPCODE
;
5351 /* Handle conversion of 'int $3' --> special int3 insn. */
5352 if (i
.tm
.mnem_off
== MN_int
5353 && i
.op
[0].imms
->X_add_number
== 3)
5355 i
.tm
.base_opcode
= INT3_OPCODE
;
5359 if ((i
.tm
.opcode_modifier
.jump
== JUMP
5360 || i
.tm
.opcode_modifier
.jump
== JUMP_BYTE
5361 || i
.tm
.opcode_modifier
.jump
== JUMP_DWORD
)
5362 && i
.op
[0].disps
->X_op
== O_constant
)
5364 /* Convert "jmp constant" (and "call constant") to a jump (call) to
5365 the absolute address given by the constant. Since ix86 jumps and
5366 calls are pc relative, we need to generate a reloc. */
5367 i
.op
[0].disps
->X_add_symbol
= &abs_symbol
;
5368 i
.op
[0].disps
->X_op
= O_symbol
;
5371 /* For 8 bit registers we need an empty rex prefix. Also if the
5372 instruction already has a prefix, we need to convert old
5373 registers to new ones. */
5375 if ((i
.types
[0].bitfield
.class == Reg
&& i
.types
[0].bitfield
.byte
5376 && (i
.op
[0].regs
->reg_flags
& RegRex64
) != 0)
5377 || (i
.types
[1].bitfield
.class == Reg
&& i
.types
[1].bitfield
.byte
5378 && (i
.op
[1].regs
->reg_flags
& RegRex64
) != 0)
5379 || (((i
.types
[0].bitfield
.class == Reg
&& i
.types
[0].bitfield
.byte
)
5380 || (i
.types
[1].bitfield
.class == Reg
&& i
.types
[1].bitfield
.byte
))
5385 i
.rex
|= REX_OPCODE
;
5386 for (x
= 0; x
< 2; x
++)
5388 /* Look for 8 bit operand that uses old registers. */
5389 if (i
.types
[x
].bitfield
.class == Reg
&& i
.types
[x
].bitfield
.byte
5390 && (i
.op
[x
].regs
->reg_flags
& RegRex64
) == 0)
5392 gas_assert (!(i
.op
[x
].regs
->reg_flags
& RegRex
));
5393 /* In case it is "hi" register, give up. */
5394 if (i
.op
[x
].regs
->reg_num
> 3)
5395 as_bad (_("can't encode register '%s%s' in an "
5396 "instruction requiring REX prefix."),
5397 register_prefix
, i
.op
[x
].regs
->reg_name
);
5399 /* Otherwise it is equivalent to the extended register.
5400 Since the encoding doesn't change this is merely
5401 cosmetic cleanup for debug output. */
5403 i
.op
[x
].regs
= i
.op
[x
].regs
+ 8;
5408 if (i
.rex
== 0 && i
.rex_encoding
)
5410 /* Check if we can add a REX_OPCODE byte. Look for 8 bit operand
5411 that uses legacy register. If it is "hi" register, don't add
5412 the REX_OPCODE byte. */
5414 for (x
= 0; x
< 2; x
++)
5415 if (i
.types
[x
].bitfield
.class == Reg
5416 && i
.types
[x
].bitfield
.byte
5417 && (i
.op
[x
].regs
->reg_flags
& RegRex64
) == 0
5418 && i
.op
[x
].regs
->reg_num
> 3)
5420 gas_assert (!(i
.op
[x
].regs
->reg_flags
& RegRex
));
5421 i
.rex_encoding
= false;
5430 add_prefix (REX_OPCODE
| i
.rex
);
5432 insert_lfence_before ();
5434 /* We are ready to output the insn. */
5437 insert_lfence_after ();
5439 last_insn
.seg
= now_seg
;
5441 if (i
.tm
.opcode_modifier
.isprefix
)
5443 last_insn
.kind
= last_insn_prefix
;
5444 last_insn
.name
= insn_name (&i
.tm
);
5445 last_insn
.file
= as_where (&last_insn
.line
);
5448 last_insn
.kind
= last_insn_other
;
5451 /* The Q suffix is generally valid only in 64-bit mode, with very few
5452 exceptions: fild, fistp, fisttp, and cmpxchg8b. Note that for fild
5453 and fisttp only one of their two templates is matched below: That's
5454 sufficient since other relevant attributes are the same between both
5455 respective templates. */
5456 static INLINE
bool q_suffix_allowed(const insn_template
*t
)
5458 return flag_code
== CODE_64BIT
5459 || (t
->opcode_space
== SPACE_BASE
5460 && t
->base_opcode
== 0xdf
5461 && (t
->extension_opcode
& 1)) /* fild / fistp / fisttp */
5462 || t
->mnem_off
== MN_cmpxchg8b
;
5466 parse_insn (const char *line
, char *mnemonic
, bool prefix_only
)
5468 const char *l
= line
, *token_start
= l
;
5470 bool pass1
= !current_templates
;
5472 const insn_template
*t
;
5478 /* Pseudo-prefixes start with an opening figure brace. */
5479 if ((*mnem_p
= *l
) == '{')
5484 while ((*mnem_p
= mnemonic_chars
[(unsigned char) *l
]) != 0)
5489 if (mnem_p
>= mnemonic
+ MAX_MNEM_SIZE
)
5492 as_bad (_("no such instruction: `%s'"), token_start
);
5497 /* Pseudo-prefixes end with a closing figure brace. */
5498 if (*mnemonic
== '{' && *l
== '}')
5501 if (mnem_p
>= mnemonic
+ MAX_MNEM_SIZE
)
5505 /* Point l at the closing brace if there's no other separator. */
5506 if (*l
!= END_OF_INSN
&& !is_space_char (*l
)
5507 && *l
!= PREFIX_SEPARATOR
)
5510 else if (!is_space_char (*l
)
5511 && *l
!= END_OF_INSN
5513 || (*l
!= PREFIX_SEPARATOR
&& *l
!= ',')))
5517 as_bad (_("invalid character %s in mnemonic"),
5518 output_invalid (*l
));
5521 if (token_start
== l
)
5523 if (!intel_syntax
&& *l
== PREFIX_SEPARATOR
)
5524 as_bad (_("expecting prefix; got nothing"));
5526 as_bad (_("expecting mnemonic; got nothing"));
5530 /* Look up instruction (or prefix) via hash table. */
5531 current_templates
= (const templates
*) str_hash_find (op_hash
, mnemonic
);
5533 if (*l
!= END_OF_INSN
5534 && (!is_space_char (*l
) || l
[1] != END_OF_INSN
)
5535 && current_templates
5536 && current_templates
->start
->opcode_modifier
.isprefix
)
5538 if (!cpu_flags_check_cpu64 (current_templates
->start
->cpu_flags
))
5540 as_bad ((flag_code
!= CODE_64BIT
5541 ? _("`%s' is only supported in 64-bit mode")
5542 : _("`%s' is not supported in 64-bit mode")),
5543 insn_name (current_templates
->start
));
5546 /* If we are in 16-bit mode, do not allow addr16 or data16.
5547 Similarly, in 32-bit mode, do not allow addr32 or data32. */
5548 if ((current_templates
->start
->opcode_modifier
.size
== SIZE16
5549 || current_templates
->start
->opcode_modifier
.size
== SIZE32
)
5550 && flag_code
!= CODE_64BIT
5551 && ((current_templates
->start
->opcode_modifier
.size
== SIZE32
)
5552 ^ (flag_code
== CODE_16BIT
)))
5554 as_bad (_("redundant %s prefix"),
5555 insn_name (current_templates
->start
));
5559 if (current_templates
->start
->base_opcode
== PSEUDO_PREFIX
)
5561 /* Handle pseudo prefixes. */
5562 switch (current_templates
->start
->extension_opcode
)
5566 i
.disp_encoding
= disp_encoding_8bit
;
5570 i
.disp_encoding
= disp_encoding_16bit
;
5574 i
.disp_encoding
= disp_encoding_32bit
;
5578 i
.dir_encoding
= dir_encoding_load
;
5582 i
.dir_encoding
= dir_encoding_store
;
5586 i
.vec_encoding
= vex_encoding_vex
;
5590 i
.vec_encoding
= vex_encoding_vex3
;
5594 i
.vec_encoding
= vex_encoding_evex
;
5598 i
.rex_encoding
= true;
5600 case Prefix_NoOptimize
:
5602 i
.no_optimize
= true;
5610 /* Add prefix, checking for repeated prefixes. */
5611 switch (add_prefix (current_templates
->start
->base_opcode
))
5616 if (current_templates
->start
->cpu_flags
.bitfield
.cpuibt
)
5617 i
.notrack_prefix
= insn_name (current_templates
->start
);
5620 if (current_templates
->start
->cpu_flags
.bitfield
.cpuhle
)
5621 i
.hle_prefix
= insn_name (current_templates
->start
);
5622 else if (current_templates
->start
->cpu_flags
.bitfield
.cpumpx
)
5623 i
.bnd_prefix
= insn_name (current_templates
->start
);
5625 i
.rep_prefix
= insn_name (current_templates
->start
);
5631 /* Skip past PREFIX_SEPARATOR and reset token_start. */
5641 if (!current_templates
)
5643 /* Deprecated functionality (new code should use pseudo-prefixes instead):
5644 Check if we should swap operand or force 32bit displacement in
5646 if (mnem_p
- 2 == dot_p
&& dot_p
[1] == 's')
5647 i
.dir_encoding
= dir_encoding_swap
;
5648 else if (mnem_p
- 3 == dot_p
5651 i
.disp_encoding
= disp_encoding_8bit
;
5652 else if (mnem_p
- 4 == dot_p
5656 i
.disp_encoding
= disp_encoding_32bit
;
5661 current_templates
= (const templates
*) str_hash_find (op_hash
, mnemonic
);
5664 if (!current_templates
|| !pass1
)
5666 current_templates
= NULL
;
5669 if (mnem_p
> mnemonic
)
5671 /* See if we can get a match by trimming off a suffix. */
5674 case WORD_MNEM_SUFFIX
:
5675 if (intel_syntax
&& (intel_float_operand (mnemonic
) & 2))
5676 i
.suffix
= SHORT_MNEM_SUFFIX
;
5679 case BYTE_MNEM_SUFFIX
:
5680 case QWORD_MNEM_SUFFIX
:
5681 i
.suffix
= mnem_p
[-1];
5684 = (const templates
*) str_hash_find (op_hash
, mnemonic
);
5686 case SHORT_MNEM_SUFFIX
:
5687 case LONG_MNEM_SUFFIX
:
5690 i
.suffix
= mnem_p
[-1];
5693 = (const templates
*) str_hash_find (op_hash
, mnemonic
);
5701 if (intel_float_operand (mnemonic
) == 1)
5702 i
.suffix
= SHORT_MNEM_SUFFIX
;
5704 i
.suffix
= LONG_MNEM_SUFFIX
;
5707 = (const templates
*) str_hash_find (op_hash
, mnemonic
);
5709 /* For compatibility reasons accept MOVSD and CMPSD without
5710 operands even in AT&T mode. */
5711 else if (*l
== END_OF_INSN
5712 || (is_space_char (*l
) && l
[1] == END_OF_INSN
))
5716 = (const templates
*) str_hash_find (op_hash
, mnemonic
);
5717 if (current_templates
!= NULL
5719 && (current_templates
->start
->base_opcode
| 2) == 0xa6
5720 && current_templates
->start
->opcode_space
5722 && mnem_p
[-2] == 's')
5724 as_warn (_("found `%sd'; assuming `%sl' was meant"),
5725 mnemonic
, mnemonic
);
5726 i
.suffix
= LONG_MNEM_SUFFIX
;
5730 current_templates
= NULL
;
5738 if (!current_templates
)
5741 as_bad (_("no such instruction: `%s'"), token_start
);
5746 if (current_templates
->start
->opcode_modifier
.jump
== JUMP
5747 || current_templates
->start
->opcode_modifier
.jump
== JUMP_BYTE
)
5749 /* Check for a branch hint. We allow ",pt" and ",pn" for
5750 predict taken and predict not taken respectively.
5751 I'm not sure that branch hints actually do anything on loop
5752 and jcxz insns (JumpByte) for current Pentium4 chips. They
5753 may work in the future and it doesn't hurt to accept them
5755 if (l
[0] == ',' && l
[1] == 'p')
5759 if (!add_prefix (DS_PREFIX_OPCODE
))
5763 else if (l
[2] == 'n')
5765 if (!add_prefix (CS_PREFIX_OPCODE
))
5771 /* Any other comma loses. */
5774 as_bad (_("invalid character %s in mnemonic"),
5775 output_invalid (*l
));
5779 /* Check if instruction is supported on specified architecture. */
5781 for (t
= current_templates
->start
; t
< current_templates
->end
; ++t
)
5783 supported
|= cpu_flags_match (t
);
5785 if (i
.suffix
== QWORD_MNEM_SUFFIX
&& !q_suffix_allowed (t
))
5786 supported
&= ~CPU_FLAGS_64BIT_MATCH
;
5788 if (supported
== CPU_FLAGS_PERFECT_MATCH
)
5794 if (supported
& CPU_FLAGS_64BIT_MATCH
)
5795 i
.error
= unsupported_on_arch
;
5797 i
.error
= unsupported_64bit
;
5804 parse_operands (char *l
, const char *mnemonic
)
5808 /* 1 if operand is pending after ','. */
5809 unsigned int expecting_operand
= 0;
5811 while (*l
!= END_OF_INSN
)
5813 /* Non-zero if operand parens not balanced. */
5814 unsigned int paren_not_balanced
= 0;
5815 /* True if inside double quotes. */
5816 bool in_quotes
= false;
5818 /* Skip optional white space before operand. */
5819 if (is_space_char (*l
))
5821 if (!is_operand_char (*l
) && *l
!= END_OF_INSN
&& *l
!= '"')
5823 as_bad (_("invalid character %s before operand %d"),
5824 output_invalid (*l
),
5828 token_start
= l
; /* After white space. */
5829 while (in_quotes
|| paren_not_balanced
|| *l
!= ',')
5831 if (*l
== END_OF_INSN
)
5835 as_bad (_("unbalanced double quotes in operand %d."),
5839 if (paren_not_balanced
)
5841 know (!intel_syntax
);
5842 as_bad (_("unbalanced parenthesis in operand %d."),
5847 break; /* we are done */
5849 else if (*l
== '\\' && l
[1] == '"')
5852 in_quotes
= !in_quotes
;
5853 else if (!in_quotes
&& !is_operand_char (*l
) && !is_space_char (*l
))
5855 as_bad (_("invalid character %s in operand %d"),
5856 output_invalid (*l
),
5860 if (!intel_syntax
&& !in_quotes
)
5863 ++paren_not_balanced
;
5865 --paren_not_balanced
;
5869 if (l
!= token_start
)
5870 { /* Yes, we've read in another operand. */
5871 unsigned int operand_ok
;
5872 this_operand
= i
.operands
++;
5873 if (i
.operands
> MAX_OPERANDS
)
5875 as_bad (_("spurious operands; (%d operands/instruction max)"),
5879 i
.types
[this_operand
].bitfield
.unspecified
= 1;
5880 /* Now parse operand adding info to 'i' as we go along. */
5881 END_STRING_AND_SAVE (l
);
5883 if (i
.mem_operands
> 1)
5885 as_bad (_("too many memory references for `%s'"),
5892 i386_intel_operand (token_start
,
5893 intel_float_operand (mnemonic
));
5895 operand_ok
= i386_att_operand (token_start
);
5897 RESTORE_END_STRING (l
);
5903 if (expecting_operand
)
5905 expecting_operand_after_comma
:
5906 as_bad (_("expecting operand after ','; got nothing"));
5911 as_bad (_("expecting operand before ','; got nothing"));
5916 /* Now *l must be either ',' or END_OF_INSN. */
5919 if (*++l
== END_OF_INSN
)
5921 /* Just skip it, if it's \n complain. */
5922 goto expecting_operand_after_comma
;
5924 expecting_operand
= 1;
5931 swap_2_operands (unsigned int xchg1
, unsigned int xchg2
)
5933 union i386_op temp_op
;
5934 i386_operand_type temp_type
;
5935 unsigned int temp_flags
;
5936 enum bfd_reloc_code_real temp_reloc
;
5938 temp_type
= i
.types
[xchg2
];
5939 i
.types
[xchg2
] = i
.types
[xchg1
];
5940 i
.types
[xchg1
] = temp_type
;
5942 temp_flags
= i
.flags
[xchg2
];
5943 i
.flags
[xchg2
] = i
.flags
[xchg1
];
5944 i
.flags
[xchg1
] = temp_flags
;
5946 temp_op
= i
.op
[xchg2
];
5947 i
.op
[xchg2
] = i
.op
[xchg1
];
5948 i
.op
[xchg1
] = temp_op
;
5950 temp_reloc
= i
.reloc
[xchg2
];
5951 i
.reloc
[xchg2
] = i
.reloc
[xchg1
];
5952 i
.reloc
[xchg1
] = temp_reloc
;
5954 temp_flags
= i
.imm_bits
[xchg2
];
5955 i
.imm_bits
[xchg2
] = i
.imm_bits
[xchg1
];
5956 i
.imm_bits
[xchg1
] = temp_flags
;
5960 if (i
.mask
.operand
== xchg1
)
5961 i
.mask
.operand
= xchg2
;
5962 else if (i
.mask
.operand
== xchg2
)
5963 i
.mask
.operand
= xchg1
;
5965 if (i
.broadcast
.type
|| i
.broadcast
.bytes
)
5967 if (i
.broadcast
.operand
== xchg1
)
5968 i
.broadcast
.operand
= xchg2
;
5969 else if (i
.broadcast
.operand
== xchg2
)
5970 i
.broadcast
.operand
= xchg1
;
5975 swap_operands (void)
5981 swap_2_operands (1, i
.operands
- 2);
5985 swap_2_operands (0, i
.operands
- 1);
5991 if (i
.mem_operands
== 2)
5993 const reg_entry
*temp_seg
;
5994 temp_seg
= i
.seg
[0];
5995 i
.seg
[0] = i
.seg
[1];
5996 i
.seg
[1] = temp_seg
;
6000 /* Try to ensure constant immediates are represented in the smallest
6005 char guess_suffix
= 0;
6009 guess_suffix
= i
.suffix
;
6010 else if (i
.reg_operands
)
6012 /* Figure out a suffix from the last register operand specified.
6013 We can't do this properly yet, i.e. excluding special register
6014 instances, but the following works for instructions with
6015 immediates. In any case, we can't set i.suffix yet. */
6016 for (op
= i
.operands
; --op
>= 0;)
6017 if (i
.types
[op
].bitfield
.class != Reg
)
6019 else if (i
.types
[op
].bitfield
.byte
)
6021 guess_suffix
= BYTE_MNEM_SUFFIX
;
6024 else if (i
.types
[op
].bitfield
.word
)
6026 guess_suffix
= WORD_MNEM_SUFFIX
;
6029 else if (i
.types
[op
].bitfield
.dword
)
6031 guess_suffix
= LONG_MNEM_SUFFIX
;
6034 else if (i
.types
[op
].bitfield
.qword
)
6036 guess_suffix
= QWORD_MNEM_SUFFIX
;
6040 else if ((flag_code
== CODE_16BIT
) ^ (i
.prefix
[DATA_PREFIX
] != 0))
6041 guess_suffix
= WORD_MNEM_SUFFIX
;
6042 else if (flag_code
!= CODE_64BIT
|| !(i
.prefix
[REX_PREFIX
] & REX_W
))
6043 guess_suffix
= LONG_MNEM_SUFFIX
;
6045 for (op
= i
.operands
; --op
>= 0;)
6046 if (operand_type_check (i
.types
[op
], imm
))
6048 switch (i
.op
[op
].imms
->X_op
)
6051 /* If a suffix is given, this operand may be shortened. */
6052 switch (guess_suffix
)
6054 case LONG_MNEM_SUFFIX
:
6055 i
.types
[op
].bitfield
.imm32
= 1;
6056 i
.types
[op
].bitfield
.imm64
= 1;
6058 case WORD_MNEM_SUFFIX
:
6059 i
.types
[op
].bitfield
.imm16
= 1;
6060 i
.types
[op
].bitfield
.imm32
= 1;
6061 i
.types
[op
].bitfield
.imm32s
= 1;
6062 i
.types
[op
].bitfield
.imm64
= 1;
6064 case BYTE_MNEM_SUFFIX
:
6065 i
.types
[op
].bitfield
.imm8
= 1;
6066 i
.types
[op
].bitfield
.imm8s
= 1;
6067 i
.types
[op
].bitfield
.imm16
= 1;
6068 i
.types
[op
].bitfield
.imm32
= 1;
6069 i
.types
[op
].bitfield
.imm32s
= 1;
6070 i
.types
[op
].bitfield
.imm64
= 1;
6074 /* If this operand is at most 16 bits, convert it
6075 to a signed 16 bit number before trying to see
6076 whether it will fit in an even smaller size.
6077 This allows a 16-bit operand such as $0xffe0 to
6078 be recognised as within Imm8S range. */
6079 if ((i
.types
[op
].bitfield
.imm16
)
6080 && fits_in_unsigned_word (i
.op
[op
].imms
->X_add_number
))
6082 i
.op
[op
].imms
->X_add_number
= ((i
.op
[op
].imms
->X_add_number
6083 ^ 0x8000) - 0x8000);
6086 /* Store 32-bit immediate in 64-bit for 64-bit BFD. */
6087 if ((i
.types
[op
].bitfield
.imm32
)
6088 && fits_in_unsigned_long (i
.op
[op
].imms
->X_add_number
))
6090 i
.op
[op
].imms
->X_add_number
= ((i
.op
[op
].imms
->X_add_number
6091 ^ ((offsetT
) 1 << 31))
6092 - ((offsetT
) 1 << 31));
6096 = operand_type_or (i
.types
[op
],
6097 smallest_imm_type (i
.op
[op
].imms
->X_add_number
));
6099 /* We must avoid matching of Imm32 templates when 64bit
6100 only immediate is available. */
6101 if (guess_suffix
== QWORD_MNEM_SUFFIX
)
6102 i
.types
[op
].bitfield
.imm32
= 0;
6109 /* Symbols and expressions. */
6111 /* Convert symbolic operand to proper sizes for matching, but don't
6112 prevent matching a set of insns that only supports sizes other
6113 than those matching the insn suffix. */
6115 i386_operand_type mask
, allowed
;
6116 const insn_template
*t
= current_templates
->start
;
6118 operand_type_set (&mask
, 0);
6119 switch (guess_suffix
)
6121 case QWORD_MNEM_SUFFIX
:
6122 mask
.bitfield
.imm64
= 1;
6123 mask
.bitfield
.imm32s
= 1;
6125 case LONG_MNEM_SUFFIX
:
6126 mask
.bitfield
.imm32
= 1;
6128 case WORD_MNEM_SUFFIX
:
6129 mask
.bitfield
.imm16
= 1;
6131 case BYTE_MNEM_SUFFIX
:
6132 mask
.bitfield
.imm8
= 1;
6138 allowed
= operand_type_and (t
->operand_types
[op
], mask
);
6139 while (++t
< current_templates
->end
)
6141 allowed
= operand_type_or (allowed
, t
->operand_types
[op
]);
6142 allowed
= operand_type_and (allowed
, mask
);
6145 if (!operand_type_all_zero (&allowed
))
6146 i
.types
[op
] = operand_type_and (i
.types
[op
], mask
);
6153 /* Try to use the smallest displacement type too. */
6155 optimize_disp (const insn_template
*t
)
6159 if (!want_disp32 (t
)
6160 && (!t
->opcode_modifier
.jump
6161 || i
.jumpabsolute
|| i
.types
[0].bitfield
.baseindex
))
6163 for (op
= 0; op
< i
.operands
; ++op
)
6165 const expressionS
*exp
= i
.op
[op
].disps
;
6167 if (!operand_type_check (i
.types
[op
], disp
))
6170 if (exp
->X_op
!= O_constant
)
6173 /* Since displacement is signed extended to 64bit, don't allow
6174 disp32 if it is out of range. */
6175 if (fits_in_signed_long (exp
->X_add_number
))
6178 i
.types
[op
].bitfield
.disp32
= 0;
6179 if (i
.types
[op
].bitfield
.baseindex
)
6181 as_bad (_("0x%" PRIx64
" out of range of signed 32bit displacement"),
6182 (uint64_t) exp
->X_add_number
);
6188 /* Don't optimize displacement for movabs since it only takes 64bit
6190 if (i
.disp_encoding
> disp_encoding_8bit
6191 || (flag_code
== CODE_64BIT
&& t
->mnem_off
== MN_movabs
))
6194 for (op
= i
.operands
; op
-- > 0;)
6195 if (operand_type_check (i
.types
[op
], disp
))
6197 if (i
.op
[op
].disps
->X_op
== O_constant
)
6199 offsetT op_disp
= i
.op
[op
].disps
->X_add_number
;
6201 if (!op_disp
&& i
.types
[op
].bitfield
.baseindex
)
6203 i
.types
[op
] = operand_type_and_not (i
.types
[op
], anydisp
);
6204 i
.op
[op
].disps
= NULL
;
6209 if (i
.types
[op
].bitfield
.disp16
6210 && fits_in_unsigned_word (op_disp
))
6212 /* If this operand is at most 16 bits, convert
6213 to a signed 16 bit number and don't use 64bit
6215 op_disp
= ((op_disp
^ 0x8000) - 0x8000);
6216 i
.types
[op
].bitfield
.disp64
= 0;
6220 /* Optimize 64-bit displacement to 32-bit for 64-bit BFD. */
6221 if ((flag_code
!= CODE_64BIT
6222 ? i
.types
[op
].bitfield
.disp32
6224 && (!t
->opcode_modifier
.jump
6225 || i
.jumpabsolute
|| i
.types
[op
].bitfield
.baseindex
))
6226 && fits_in_unsigned_long (op_disp
))
6228 /* If this operand is at most 32 bits, convert
6229 to a signed 32 bit number and don't use 64bit
6231 op_disp
= (op_disp
^ ((offsetT
) 1 << 31)) - ((addressT
) 1 << 31);
6232 i
.types
[op
].bitfield
.disp64
= 0;
6233 i
.types
[op
].bitfield
.disp32
= 1;
6236 if (flag_code
== CODE_64BIT
&& fits_in_signed_long (op_disp
))
6238 i
.types
[op
].bitfield
.disp64
= 0;
6239 i
.types
[op
].bitfield
.disp32
= 1;
6242 if ((i
.types
[op
].bitfield
.disp32
6243 || i
.types
[op
].bitfield
.disp16
)
6244 && fits_in_disp8 (op_disp
))
6245 i
.types
[op
].bitfield
.disp8
= 1;
6247 i
.op
[op
].disps
->X_add_number
= op_disp
;
6249 else if (i
.reloc
[op
] == BFD_RELOC_386_TLS_DESC_CALL
6250 || i
.reloc
[op
] == BFD_RELOC_X86_64_TLSDESC_CALL
)
6252 fix_new_exp (frag_now
, frag_more (0) - frag_now
->fr_literal
, 0,
6253 i
.op
[op
].disps
, 0, i
.reloc
[op
]);
6254 i
.types
[op
] = operand_type_and_not (i
.types
[op
], anydisp
);
6257 /* We only support 64bit displacement on constants. */
6258 i
.types
[op
].bitfield
.disp64
= 0;
6264 /* Return 1 if there is a match in broadcast bytes between operand
6265 GIVEN and instruction template T. */
6268 match_broadcast_size (const insn_template
*t
, unsigned int given
)
6270 return ((t
->opcode_modifier
.broadcast
== BYTE_BROADCAST
6271 && i
.types
[given
].bitfield
.byte
)
6272 || (t
->opcode_modifier
.broadcast
== WORD_BROADCAST
6273 && i
.types
[given
].bitfield
.word
)
6274 || (t
->opcode_modifier
.broadcast
== DWORD_BROADCAST
6275 && i
.types
[given
].bitfield
.dword
)
6276 || (t
->opcode_modifier
.broadcast
== QWORD_BROADCAST
6277 && i
.types
[given
].bitfield
.qword
));
6280 /* Check if operands are valid for the instruction. */
6283 check_VecOperands (const insn_template
*t
)
6288 /* Templates allowing for ZMMword as well as YMMword and/or XMMword for
6289 any one operand are implicity requiring AVX512VL support if the actual
6290 operand size is YMMword or XMMword. Since this function runs after
6291 template matching, there's no need to check for YMMword/XMMword in
6293 cpu
= cpu_flags_and (t
->cpu_flags
, avx512
);
6294 if (!cpu_flags_all_zero (&cpu
)
6295 && !t
->cpu_flags
.bitfield
.cpuavx512vl
6296 && !cpu_arch_flags
.bitfield
.cpuavx512vl
)
6298 for (op
= 0; op
< t
->operands
; ++op
)
6300 if (t
->operand_types
[op
].bitfield
.zmmword
6301 && (i
.types
[op
].bitfield
.ymmword
6302 || i
.types
[op
].bitfield
.xmmword
))
6304 i
.error
= unsupported
;
6310 /* Somewhat similarly, templates specifying both AVX and AVX2 are
6311 requiring AVX2 support if the actual operand size is YMMword. */
6312 if (t
->cpu_flags
.bitfield
.cpuavx
6313 && t
->cpu_flags
.bitfield
.cpuavx2
6314 && !cpu_arch_flags
.bitfield
.cpuavx2
)
6316 for (op
= 0; op
< t
->operands
; ++op
)
6318 if (t
->operand_types
[op
].bitfield
.xmmword
6319 && i
.types
[op
].bitfield
.ymmword
)
6321 i
.error
= unsupported
;
6327 /* Without VSIB byte, we can't have a vector register for index. */
6328 if (!t
->opcode_modifier
.sib
6330 && (i
.index_reg
->reg_type
.bitfield
.xmmword
6331 || i
.index_reg
->reg_type
.bitfield
.ymmword
6332 || i
.index_reg
->reg_type
.bitfield
.zmmword
))
6334 i
.error
= unsupported_vector_index_register
;
6338 /* Check if default mask is allowed. */
6339 if (t
->opcode_modifier
.operandconstraint
== NO_DEFAULT_MASK
6340 && (!i
.mask
.reg
|| i
.mask
.reg
->reg_num
== 0))
6342 i
.error
= no_default_mask
;
6346 /* For VSIB byte, we need a vector register for index, and all vector
6347 registers must be distinct. */
6348 if (t
->opcode_modifier
.sib
&& t
->opcode_modifier
.sib
!= SIBMEM
)
6351 || !((t
->opcode_modifier
.sib
== VECSIB128
6352 && i
.index_reg
->reg_type
.bitfield
.xmmword
)
6353 || (t
->opcode_modifier
.sib
== VECSIB256
6354 && i
.index_reg
->reg_type
.bitfield
.ymmword
)
6355 || (t
->opcode_modifier
.sib
== VECSIB512
6356 && i
.index_reg
->reg_type
.bitfield
.zmmword
)))
6358 i
.error
= invalid_vsib_address
;
6362 gas_assert (i
.reg_operands
== 2 || i
.mask
.reg
);
6363 if (i
.reg_operands
== 2 && !i
.mask
.reg
)
6365 gas_assert (i
.types
[0].bitfield
.class == RegSIMD
);
6366 gas_assert (i
.types
[0].bitfield
.xmmword
6367 || i
.types
[0].bitfield
.ymmword
);
6368 gas_assert (i
.types
[2].bitfield
.class == RegSIMD
);
6369 gas_assert (i
.types
[2].bitfield
.xmmword
6370 || i
.types
[2].bitfield
.ymmword
);
6371 if (operand_check
== check_none
)
6373 if (register_number (i
.op
[0].regs
)
6374 != register_number (i
.index_reg
)
6375 && register_number (i
.op
[2].regs
)
6376 != register_number (i
.index_reg
)
6377 && register_number (i
.op
[0].regs
)
6378 != register_number (i
.op
[2].regs
))
6380 if (operand_check
== check_error
)
6382 i
.error
= invalid_vector_register_set
;
6385 as_warn (_("mask, index, and destination registers should be distinct"));
6387 else if (i
.reg_operands
== 1 && i
.mask
.reg
)
6389 if (i
.types
[1].bitfield
.class == RegSIMD
6390 && (i
.types
[1].bitfield
.xmmword
6391 || i
.types
[1].bitfield
.ymmword
6392 || i
.types
[1].bitfield
.zmmword
)
6393 && (register_number (i
.op
[1].regs
)
6394 == register_number (i
.index_reg
)))
6396 if (operand_check
== check_error
)
6398 i
.error
= invalid_vector_register_set
;
6401 if (operand_check
!= check_none
)
6402 as_warn (_("index and destination registers should be distinct"));
6407 /* For AMX instructions with 3 TMM register operands, all operands
6408 must be distinct. */
6409 if (i
.reg_operands
== 3
6410 && t
->operand_types
[0].bitfield
.tmmword
6411 && (i
.op
[0].regs
== i
.op
[1].regs
6412 || i
.op
[0].regs
== i
.op
[2].regs
6413 || i
.op
[1].regs
== i
.op
[2].regs
))
6415 i
.error
= invalid_tmm_register_set
;
6419 /* For some special instructions require that destination must be distinct
6420 from source registers. */
6421 if (t
->opcode_modifier
.operandconstraint
== DISTINCT_DEST
)
6423 unsigned int dest_reg
= i
.operands
- 1;
6425 know (i
.operands
>= 3);
6427 /* #UD if dest_reg == src1_reg or dest_reg == src2_reg. */
6428 if (i
.op
[dest_reg
- 1].regs
== i
.op
[dest_reg
].regs
6429 || (i
.reg_operands
> 2
6430 && i
.op
[dest_reg
- 2].regs
== i
.op
[dest_reg
].regs
))
6432 i
.error
= invalid_dest_and_src_register_set
;
6437 /* Check if broadcast is supported by the instruction and is applied
6438 to the memory operand. */
6439 if (i
.broadcast
.type
|| i
.broadcast
.bytes
)
6441 i386_operand_type type
, overlap
;
6443 /* Check if specified broadcast is supported in this instruction,
6444 and its broadcast bytes match the memory operand. */
6445 op
= i
.broadcast
.operand
;
6446 if (!t
->opcode_modifier
.broadcast
6447 || !(i
.flags
[op
] & Operand_Mem
)
6448 || (!i
.types
[op
].bitfield
.unspecified
6449 && !match_broadcast_size (t
, op
)))
6452 i
.error
= unsupported_broadcast
;
6456 operand_type_set (&type
, 0);
6457 switch (get_broadcast_bytes (t
, false))
6460 type
.bitfield
.word
= 1;
6463 type
.bitfield
.dword
= 1;
6466 type
.bitfield
.qword
= 1;
6469 type
.bitfield
.xmmword
= 1;
6472 type
.bitfield
.ymmword
= 1;
6475 type
.bitfield
.zmmword
= 1;
6481 overlap
= operand_type_and (type
, t
->operand_types
[op
]);
6482 if (t
->operand_types
[op
].bitfield
.class == RegSIMD
6483 && t
->operand_types
[op
].bitfield
.byte
6484 + t
->operand_types
[op
].bitfield
.word
6485 + t
->operand_types
[op
].bitfield
.dword
6486 + t
->operand_types
[op
].bitfield
.qword
> 1)
6488 overlap
.bitfield
.xmmword
= 0;
6489 overlap
.bitfield
.ymmword
= 0;
6490 overlap
.bitfield
.zmmword
= 0;
6492 if (operand_type_all_zero (&overlap
))
6495 if (t
->opcode_modifier
.checkoperandsize
)
6499 type
.bitfield
.baseindex
= 1;
6500 for (j
= 0; j
< i
.operands
; ++j
)
6503 && !operand_type_register_match(i
.types
[j
],
6504 t
->operand_types
[j
],
6506 t
->operand_types
[op
]))
6511 /* If broadcast is supported in this instruction, we need to check if
6512 operand of one-element size isn't specified without broadcast. */
6513 else if (t
->opcode_modifier
.broadcast
&& i
.mem_operands
)
6515 /* Find memory operand. */
6516 for (op
= 0; op
< i
.operands
; op
++)
6517 if (i
.flags
[op
] & Operand_Mem
)
6519 gas_assert (op
< i
.operands
);
6520 /* Check size of the memory operand. */
6521 if (match_broadcast_size (t
, op
))
6523 i
.error
= broadcast_needed
;
6528 op
= MAX_OPERANDS
- 1; /* Avoid uninitialized variable warning. */
6530 /* Check if requested masking is supported. */
6533 if (!t
->opcode_modifier
.masking
)
6535 i
.error
= unsupported_masking
;
6539 /* Common rules for masking:
6540 - mask register destinations permit only zeroing-masking, without
6541 that actually being expressed by a {z} operand suffix or EVEX.z,
6542 - memory destinations allow only merging-masking,
6543 - scatter/gather insns (i.e. ones using vSIB) only allow merging-
6546 && (t
->operand_types
[t
->operands
- 1].bitfield
.class == RegMask
6547 || (i
.flags
[t
->operands
- 1] & Operand_Mem
)
6548 || t
->opcode_modifier
.sib
))
6550 i
.error
= unsupported_masking
;
6555 /* Check if masking is applied to dest operand. */
6556 if (i
.mask
.reg
&& (i
.mask
.operand
!= i
.operands
- 1))
6558 i
.error
= mask_not_on_destination
;
6563 if (i
.rounding
.type
!= rc_none
)
6565 if (!t
->opcode_modifier
.sae
6566 || ((i
.rounding
.type
!= saeonly
) != t
->opcode_modifier
.staticrounding
)
6569 i
.error
= unsupported_rc_sae
;
6573 /* Non-EVEX.LIG forms need to have a ZMM register as at least one
6575 if (t
->opcode_modifier
.evex
!= EVEXLIG
)
6577 for (op
= 0; op
< t
->operands
; ++op
)
6578 if (i
.types
[op
].bitfield
.zmmword
)
6580 if (op
>= t
->operands
)
6582 i
.error
= operand_size_mismatch
;
6588 /* Check the special Imm4 cases; must be the first operand. */
6589 if (t
->cpu_flags
.bitfield
.cpuxop
&& t
->operands
== 5)
6591 if (i
.op
[0].imms
->X_op
!= O_constant
6592 || !fits_in_imm4 (i
.op
[0].imms
->X_add_number
))
6598 /* Turn off Imm<N> so that update_imm won't complain. */
6599 operand_type_set (&i
.types
[0], 0);
6602 /* Check vector Disp8 operand. */
6603 if (t
->opcode_modifier
.disp8memshift
6604 && i
.disp_encoding
<= disp_encoding_8bit
)
6606 if (i
.broadcast
.type
|| i
.broadcast
.bytes
)
6607 i
.memshift
= t
->opcode_modifier
.broadcast
- 1;
6608 else if (t
->opcode_modifier
.disp8memshift
!= DISP8_SHIFT_VL
)
6609 i
.memshift
= t
->opcode_modifier
.disp8memshift
;
6612 const i386_operand_type
*type
= NULL
, *fallback
= NULL
;
6615 for (op
= 0; op
< i
.operands
; op
++)
6616 if (i
.flags
[op
] & Operand_Mem
)
6618 if (t
->opcode_modifier
.evex
== EVEXLIG
)
6619 i
.memshift
= 2 + (i
.suffix
== QWORD_MNEM_SUFFIX
);
6620 else if (t
->operand_types
[op
].bitfield
.xmmword
6621 + t
->operand_types
[op
].bitfield
.ymmword
6622 + t
->operand_types
[op
].bitfield
.zmmword
<= 1)
6623 type
= &t
->operand_types
[op
];
6624 else if (!i
.types
[op
].bitfield
.unspecified
)
6625 type
= &i
.types
[op
];
6626 else /* Ambiguities get resolved elsewhere. */
6627 fallback
= &t
->operand_types
[op
];
6629 else if (i
.types
[op
].bitfield
.class == RegSIMD
6630 && t
->opcode_modifier
.evex
!= EVEXLIG
)
6632 if (i
.types
[op
].bitfield
.zmmword
)
6634 else if (i
.types
[op
].bitfield
.ymmword
&& i
.memshift
< 5)
6636 else if (i
.types
[op
].bitfield
.xmmword
&& i
.memshift
< 4)
6640 if (!type
&& !i
.memshift
)
6644 if (type
->bitfield
.zmmword
)
6646 else if (type
->bitfield
.ymmword
)
6648 else if (type
->bitfield
.xmmword
)
6652 /* For the check in fits_in_disp8(). */
6653 if (i
.memshift
== 0)
6657 for (op
= 0; op
< i
.operands
; op
++)
6658 if (operand_type_check (i
.types
[op
], disp
)
6659 && i
.op
[op
].disps
->X_op
== O_constant
)
6661 if (fits_in_disp8 (i
.op
[op
].disps
->X_add_number
))
6663 i
.types
[op
].bitfield
.disp8
= 1;
6666 i
.types
[op
].bitfield
.disp8
= 0;
6675 /* Check if encoding requirements are met by the instruction. */
6678 VEX_check_encoding (const insn_template
*t
)
6680 if (i
.vec_encoding
== vex_encoding_error
)
6682 i
.error
= unsupported
;
6686 if (i
.vec_encoding
== vex_encoding_evex
)
6688 /* This instruction must be encoded with EVEX prefix. */
6689 if (!is_evex_encoding (t
))
6691 i
.error
= unsupported
;
6697 if (!t
->opcode_modifier
.vex
)
6699 /* This instruction template doesn't have VEX prefix. */
6700 if (i
.vec_encoding
!= vex_encoding_default
)
6702 i
.error
= unsupported
;
6711 /* Helper function for the progress() macro in match_template(). */
6712 static INLINE
enum i386_error
progress (enum i386_error
new,
6713 enum i386_error last
,
6714 unsigned int line
, unsigned int *line_p
)
6716 if (line
<= *line_p
)
6722 static const insn_template
*
6723 match_template (char mnem_suffix
)
6725 /* Points to template once we've found it. */
6726 const insn_template
*t
;
6727 i386_operand_type overlap0
, overlap1
, overlap2
, overlap3
;
6728 i386_operand_type overlap4
;
6729 unsigned int found_reverse_match
;
6730 i386_operand_type operand_types
[MAX_OPERANDS
];
6731 int addr_prefix_disp
;
6732 unsigned int j
, size_match
, check_register
, errline
= __LINE__
;
6733 enum i386_error specific_error
= number_of_operands_mismatch
;
6734 #define progress(err) progress (err, specific_error, __LINE__, &errline)
6736 #if MAX_OPERANDS != 5
6737 # error "MAX_OPERANDS must be 5."
6740 found_reverse_match
= 0;
6741 addr_prefix_disp
= -1;
6743 for (t
= current_templates
->start
; t
< current_templates
->end
; t
++)
6745 addr_prefix_disp
= -1;
6746 found_reverse_match
= 0;
6748 /* Must have right number of operands. */
6749 if (i
.operands
!= t
->operands
)
6752 /* Check processor support. */
6753 specific_error
= progress (unsupported
);
6754 if (cpu_flags_match (t
) != CPU_FLAGS_PERFECT_MATCH
)
6757 /* Check AT&T mnemonic. */
6758 specific_error
= progress (unsupported_with_intel_mnemonic
);
6759 if (intel_mnemonic
&& t
->opcode_modifier
.attmnemonic
)
6762 /* Check AT&T/Intel syntax. */
6763 specific_error
= progress (unsupported_syntax
);
6764 if ((intel_syntax
&& t
->opcode_modifier
.attsyntax
)
6765 || (!intel_syntax
&& t
->opcode_modifier
.intelsyntax
))
6768 /* Check Intel64/AMD64 ISA. */
6772 /* Default: Don't accept Intel64. */
6773 if (t
->opcode_modifier
.isa64
== INTEL64
)
6777 /* -mamd64: Don't accept Intel64 and Intel64 only. */
6778 if (t
->opcode_modifier
.isa64
>= INTEL64
)
6782 /* -mintel64: Don't accept AMD64. */
6783 if (t
->opcode_modifier
.isa64
== AMD64
&& flag_code
== CODE_64BIT
)
6788 /* Check the suffix. */
6789 specific_error
= progress (invalid_instruction_suffix
);
6790 if ((t
->opcode_modifier
.no_bsuf
&& mnem_suffix
== BYTE_MNEM_SUFFIX
)
6791 || (t
->opcode_modifier
.no_wsuf
&& mnem_suffix
== WORD_MNEM_SUFFIX
)
6792 || (t
->opcode_modifier
.no_lsuf
&& mnem_suffix
== LONG_MNEM_SUFFIX
)
6793 || (t
->opcode_modifier
.no_ssuf
&& mnem_suffix
== SHORT_MNEM_SUFFIX
)
6794 || (t
->opcode_modifier
.no_qsuf
&& mnem_suffix
== QWORD_MNEM_SUFFIX
))
6797 specific_error
= progress (operand_size_mismatch
);
6798 size_match
= operand_size_match (t
);
6802 /* This is intentionally not
6804 if (i.jumpabsolute != (t->opcode_modifier.jump == JUMP_ABSOLUTE))
6806 as the case of a missing * on the operand is accepted (perhaps with
6807 a warning, issued further down). */
6808 specific_error
= progress (operand_type_mismatch
);
6809 if (i
.jumpabsolute
&& t
->opcode_modifier
.jump
!= JUMP_ABSOLUTE
)
6812 /* In Intel syntax, normally we can check for memory operand size when
6813 there is no mnemonic suffix. But jmp and call have 2 different
6814 encodings with Dword memory operand size. Skip the "near" one
6815 (permitting a register operand) when "far" was requested. */
6817 && t
->opcode_modifier
.jump
== JUMP_ABSOLUTE
6818 && t
->operand_types
[0].bitfield
.class == Reg
)
6821 for (j
= 0; j
< MAX_OPERANDS
; j
++)
6822 operand_types
[j
] = t
->operand_types
[j
];
6824 /* In general, don't allow 32-bit operands on pre-386. */
6825 specific_error
= progress (mnem_suffix
? invalid_instruction_suffix
6826 : operand_size_mismatch
);
6827 j
= i
.imm_operands
+ (t
->operands
> i
.imm_operands
+ 1);
6828 if (i
.suffix
== LONG_MNEM_SUFFIX
6829 && !cpu_arch_flags
.bitfield
.cpui386
6831 ? (t
->opcode_modifier
.mnemonicsize
!= IGNORESIZE
6832 && !intel_float_operand (insn_name (t
)))
6833 : intel_float_operand (insn_name (t
)) != 2)
6834 && (t
->operands
== i
.imm_operands
6835 || (operand_types
[i
.imm_operands
].bitfield
.class != RegMMX
6836 && operand_types
[i
.imm_operands
].bitfield
.class != RegSIMD
6837 && operand_types
[i
.imm_operands
].bitfield
.class != RegMask
)
6838 || (operand_types
[j
].bitfield
.class != RegMMX
6839 && operand_types
[j
].bitfield
.class != RegSIMD
6840 && operand_types
[j
].bitfield
.class != RegMask
))
6841 && !t
->opcode_modifier
.sib
)
6844 /* Do not verify operands when there are none. */
6847 if (VEX_check_encoding (t
))
6849 specific_error
= progress (i
.error
);
6853 /* We've found a match; break out of loop. */
6857 if (!t
->opcode_modifier
.jump
6858 || t
->opcode_modifier
.jump
== JUMP_ABSOLUTE
)
6860 /* There should be only one Disp operand. */
6861 for (j
= 0; j
< MAX_OPERANDS
; j
++)
6862 if (operand_type_check (operand_types
[j
], disp
))
6864 if (j
< MAX_OPERANDS
)
6866 bool override
= (i
.prefix
[ADDR_PREFIX
] != 0);
6868 addr_prefix_disp
= j
;
6870 /* Address size prefix will turn Disp64 operand into Disp32 and
6871 Disp32/Disp16 one into Disp16/Disp32 respectively. */
6875 override
= !override
;
6878 if (operand_types
[j
].bitfield
.disp32
6879 && operand_types
[j
].bitfield
.disp16
)
6881 operand_types
[j
].bitfield
.disp16
= override
;
6882 operand_types
[j
].bitfield
.disp32
= !override
;
6884 gas_assert (!operand_types
[j
].bitfield
.disp64
);
6888 if (operand_types
[j
].bitfield
.disp64
)
6890 gas_assert (!operand_types
[j
].bitfield
.disp32
);
6891 operand_types
[j
].bitfield
.disp32
= override
;
6892 operand_types
[j
].bitfield
.disp64
= !override
;
6894 operand_types
[j
].bitfield
.disp16
= 0;
6900 /* We check register size if needed. */
6901 if (t
->opcode_modifier
.checkoperandsize
)
6903 check_register
= (1 << t
->operands
) - 1;
6904 if (i
.broadcast
.type
|| i
.broadcast
.bytes
)
6905 check_register
&= ~(1 << i
.broadcast
.operand
);
6910 overlap0
= operand_type_and (i
.types
[0], operand_types
[0]);
6911 switch (t
->operands
)
6914 if (!operand_type_match (overlap0
, i
.types
[0]))
6917 /* Allow the ModR/M encoding to be requested by using the {load} or
6918 {store} pseudo prefix on an applicable insn. */
6919 if (!t
->opcode_modifier
.modrm
6920 && i
.reg_operands
== 1
6921 && ((i
.dir_encoding
== dir_encoding_load
6922 && t
->mnem_off
!= MN_pop
)
6923 || (i
.dir_encoding
== dir_encoding_store
6924 && t
->mnem_off
!= MN_push
))
6926 && t
->mnem_off
!= MN_bswap
)
6931 /* xchg %eax, %eax is a special case. It is an alias for nop
6932 only in 32bit mode and we can use opcode 0x90. In 64bit
6933 mode, we can't use 0x90 for xchg %eax, %eax since it should
6934 zero-extend %eax to %rax. */
6935 if (t
->base_opcode
== 0x90
6936 && t
->opcode_space
== SPACE_BASE
)
6938 if (flag_code
== CODE_64BIT
6939 && i
.types
[0].bitfield
.instance
== Accum
6940 && i
.types
[0].bitfield
.dword
6941 && i
.types
[1].bitfield
.instance
== Accum
)
6944 /* Allow the ModR/M encoding to be requested by using the
6945 {load} or {store} pseudo prefix. */
6946 if (i
.dir_encoding
== dir_encoding_load
6947 || i
.dir_encoding
== dir_encoding_store
)
6951 if (t
->base_opcode
== MOV_AX_DISP32
6952 && t
->opcode_space
== SPACE_BASE
6953 && t
->mnem_off
!= MN_movabs
)
6955 /* Force 0x8b encoding for "mov foo@GOT, %eax". */
6956 if (i
.reloc
[0] == BFD_RELOC_386_GOT32
)
6959 /* xrelease mov %eax, <disp> is another special case. It must not
6960 match the accumulator-only encoding of mov. */
6964 /* Allow the ModR/M encoding to be requested by using a suitable
6965 {load} or {store} pseudo prefix. */
6966 if (i
.dir_encoding
== (i
.types
[0].bitfield
.instance
== Accum
6967 ? dir_encoding_store
6968 : dir_encoding_load
)
6969 && !i
.types
[0].bitfield
.disp64
6970 && !i
.types
[1].bitfield
.disp64
)
6974 /* Allow the ModR/M encoding to be requested by using the {load} or
6975 {store} pseudo prefix on an applicable insn. */
6976 if (!t
->opcode_modifier
.modrm
6977 && i
.reg_operands
== 1
6978 && i
.imm_operands
== 1
6979 && (i
.dir_encoding
== dir_encoding_load
6980 || i
.dir_encoding
== dir_encoding_store
)
6981 && t
->opcode_space
== SPACE_BASE
)
6983 if (t
->base_opcode
== 0xb0 /* mov $imm, %reg */
6984 && i
.dir_encoding
== dir_encoding_store
)
6987 if ((t
->base_opcode
| 0x38) == 0x3c /* <alu> $imm, %acc */
6988 && (t
->base_opcode
!= 0x3c /* cmp $imm, %acc */
6989 || i
.dir_encoding
== dir_encoding_load
))
6992 if (t
->base_opcode
== 0xa8 /* test $imm, %acc */
6993 && i
.dir_encoding
== dir_encoding_load
)
6999 if (!(size_match
& MATCH_STRAIGHT
))
7001 /* Reverse direction of operands if swapping is possible in the first
7002 place (operands need to be symmetric) and
7003 - the load form is requested, and the template is a store form,
7004 - the store form is requested, and the template is a load form,
7005 - the non-default (swapped) form is requested. */
7006 overlap1
= operand_type_and (operand_types
[0], operand_types
[1]);
7007 if (t
->opcode_modifier
.d
&& i
.reg_operands
== i
.operands
7008 && !operand_type_all_zero (&overlap1
))
7009 switch (i
.dir_encoding
)
7011 case dir_encoding_load
:
7012 if (operand_type_check (operand_types
[i
.operands
- 1], anymem
)
7013 || t
->opcode_modifier
.regmem
)
7017 case dir_encoding_store
:
7018 if (!operand_type_check (operand_types
[i
.operands
- 1], anymem
)
7019 && !t
->opcode_modifier
.regmem
)
7023 case dir_encoding_swap
:
7026 case dir_encoding_default
:
7029 /* If we want store form, we skip the current load. */
7030 if ((i
.dir_encoding
== dir_encoding_store
7031 || i
.dir_encoding
== dir_encoding_swap
)
7032 && i
.mem_operands
== 0
7033 && t
->opcode_modifier
.load
)
7038 overlap1
= operand_type_and (i
.types
[1], operand_types
[1]);
7039 if (!operand_type_match (overlap0
, i
.types
[0])
7040 || !operand_type_match (overlap1
, i
.types
[1])
7041 || ((check_register
& 3) == 3
7042 && !operand_type_register_match (i
.types
[0],
7047 specific_error
= progress (i
.error
);
7049 /* Check if other direction is valid ... */
7050 if (!t
->opcode_modifier
.d
)
7054 if (!(size_match
& MATCH_REVERSE
))
7056 /* Try reversing direction of operands. */
7057 j
= t
->cpu_flags
.bitfield
.cpufma4
7058 || t
->cpu_flags
.bitfield
.cpuxop
? 1 : i
.operands
- 1;
7059 overlap0
= operand_type_and (i
.types
[0], operand_types
[j
]);
7060 overlap1
= operand_type_and (i
.types
[j
], operand_types
[0]);
7061 overlap2
= operand_type_and (i
.types
[1], operand_types
[1]);
7062 gas_assert (t
->operands
!= 3 || !check_register
);
7063 if (!operand_type_match (overlap0
, i
.types
[0])
7064 || !operand_type_match (overlap1
, i
.types
[j
])
7065 || (t
->operands
== 3
7066 && !operand_type_match (overlap2
, i
.types
[1]))
7068 && !operand_type_register_match (i
.types
[0],
7073 /* Does not match either direction. */
7074 specific_error
= progress (i
.error
);
7077 /* found_reverse_match holds which variant of D
7079 if (!t
->opcode_modifier
.d
)
7080 found_reverse_match
= 0;
7081 else if (operand_types
[0].bitfield
.tbyte
)
7083 if (t
->opcode_modifier
.operandconstraint
!= UGH
)
7084 found_reverse_match
= Opcode_FloatD
;
7086 found_reverse_match
= ~0;
7087 /* FSUB{,R} and FDIV{,R} may need a 2nd bit flipped. */
7088 if ((t
->extension_opcode
& 4)
7089 && (intel_syntax
|| intel_mnemonic
))
7090 found_reverse_match
|= Opcode_FloatR
;
7092 else if (t
->cpu_flags
.bitfield
.cpufma4
7093 || t
->cpu_flags
.bitfield
.cpuxop
)
7095 found_reverse_match
= Opcode_VexW
;
7096 goto check_operands_345
;
7098 else if (t
->opcode_space
!= SPACE_BASE
7099 && (t
->opcode_space
!= SPACE_0F
7100 /* MOV to/from CR/DR/TR, as an exception, follow
7101 the base opcode space encoding model. */
7102 || (t
->base_opcode
| 7) != 0x27))
7103 found_reverse_match
= (t
->base_opcode
& 0xee) != 0x6e
7104 ? Opcode_ExtD
: Opcode_SIMD_IntD
;
7105 else if (!t
->opcode_modifier
.commutative
)
7106 found_reverse_match
= Opcode_D
;
7108 found_reverse_match
= ~0;
7112 /* Found a forward 2 operand match here. */
7114 switch (t
->operands
)
7117 overlap4
= operand_type_and (i
.types
[4], operand_types
[4]);
7118 if (!operand_type_match (overlap4
, i
.types
[4])
7119 || !operand_type_register_match (i
.types
[3],
7124 specific_error
= progress (i
.error
);
7129 overlap3
= operand_type_and (i
.types
[3], operand_types
[3]);
7130 if (!operand_type_match (overlap3
, i
.types
[3])
7131 || ((check_register
& 0xa) == 0xa
7132 && !operand_type_register_match (i
.types
[1],
7136 || ((check_register
& 0xc) == 0xc
7137 && !operand_type_register_match (i
.types
[2],
7142 specific_error
= progress (i
.error
);
7147 overlap2
= operand_type_and (i
.types
[2], operand_types
[2]);
7148 if (!operand_type_match (overlap2
, i
.types
[2])
7149 || ((check_register
& 5) == 5
7150 && !operand_type_register_match (i
.types
[0],
7154 || ((check_register
& 6) == 6
7155 && !operand_type_register_match (i
.types
[1],
7160 specific_error
= progress (i
.error
);
7166 /* Found either forward/reverse 2, 3 or 4 operand match here:
7167 slip through to break. */
7170 /* Check if VEX/EVEX encoding requirements can be satisfied. */
7171 if (VEX_check_encoding (t
))
7173 specific_error
= progress (i
.error
);
7177 /* Check if vector operands are valid. */
7178 if (check_VecOperands (t
))
7180 specific_error
= progress (i
.error
);
7184 /* We've found a match; break out of loop. */
7190 if (t
== current_templates
->end
)
7192 /* We found no match. */
7193 i
.error
= specific_error
;
7197 if (!quiet_warnings
)
7200 && (i
.jumpabsolute
!= (t
->opcode_modifier
.jump
== JUMP_ABSOLUTE
)))
7201 as_warn (_("indirect %s without `*'"), insn_name (t
));
7203 if (t
->opcode_modifier
.isprefix
7204 && t
->opcode_modifier
.mnemonicsize
== IGNORESIZE
)
7206 /* Warn them that a data or address size prefix doesn't
7207 affect assembly of the next line of code. */
7208 as_warn (_("stand-alone `%s' prefix"), insn_name (t
));
7212 /* Copy the template we found. */
7213 install_template (t
);
7215 if (addr_prefix_disp
!= -1)
7216 i
.tm
.operand_types
[addr_prefix_disp
]
7217 = operand_types
[addr_prefix_disp
];
7219 switch (found_reverse_match
)
7225 case Opcode_FloatR
| Opcode_FloatD
:
7226 i
.tm
.extension_opcode
^= Opcode_FloatR
>> 3;
7227 found_reverse_match
&= Opcode_FloatD
;
7231 /* If we found a reverse match we must alter the opcode direction
7232 bit and clear/flip the regmem modifier one. found_reverse_match
7233 holds bits to change (different for int & float insns). */
7235 i
.tm
.base_opcode
^= found_reverse_match
;
7237 /* Certain SIMD insns have their load forms specified in the opcode
7238 table, and hence we need to _set_ RegMem instead of clearing it.
7239 We need to avoid setting the bit though on insns like KMOVW. */
7240 i
.tm
.opcode_modifier
.regmem
7241 = i
.tm
.opcode_modifier
.modrm
&& i
.tm
.opcode_modifier
.d
7242 && i
.tm
.operands
> 2U - i
.tm
.opcode_modifier
.sse2avx
7243 && !i
.tm
.opcode_modifier
.regmem
;
7247 i
.tm
.operand_types
[0] = operand_types
[i
.operands
- 1];
7248 i
.tm
.operand_types
[i
.operands
- 1] = operand_types
[0];
7252 /* Only the first two register operands need reversing, alongside
7254 i
.tm
.opcode_modifier
.vexw
^= VEXW0
^ VEXW1
;
7256 j
= i
.tm
.operand_types
[0].bitfield
.imm8
;
7257 i
.tm
.operand_types
[j
] = operand_types
[j
+ 1];
7258 i
.tm
.operand_types
[j
+ 1] = operand_types
[j
];
7268 unsigned int es_op
= i
.tm
.opcode_modifier
.isstring
- IS_STRING_ES_OP0
;
7269 unsigned int op
= i
.tm
.operand_types
[0].bitfield
.baseindex
? es_op
: 0;
7271 if (i
.seg
[op
] != NULL
&& i
.seg
[op
] != reg_es
)
7273 as_bad (_("`%s' operand %u must use `%ses' segment"),
7275 intel_syntax
? i
.tm
.operands
- es_op
: es_op
+ 1,
7280 /* There's only ever one segment override allowed per instruction.
7281 This instruction possibly has a legal segment override on the
7282 second operand, so copy the segment to where non-string
7283 instructions store it, allowing common code. */
7284 i
.seg
[op
] = i
.seg
[1];
7290 process_suffix (void)
7292 bool is_movx
= false;
7294 /* If matched instruction specifies an explicit instruction mnemonic
7296 if (i
.tm
.opcode_modifier
.size
== SIZE16
)
7297 i
.suffix
= WORD_MNEM_SUFFIX
;
7298 else if (i
.tm
.opcode_modifier
.size
== SIZE32
)
7299 i
.suffix
= LONG_MNEM_SUFFIX
;
7300 else if (i
.tm
.opcode_modifier
.size
== SIZE64
)
7301 i
.suffix
= QWORD_MNEM_SUFFIX
;
7302 else if (i
.reg_operands
7303 && (i
.operands
> 1 || i
.types
[0].bitfield
.class == Reg
)
7304 && i
.tm
.opcode_modifier
.operandconstraint
!= ADDR_PREFIX_OP_REG
)
7306 unsigned int numop
= i
.operands
;
7309 is_movx
= (i
.tm
.opcode_space
== SPACE_0F
7310 && (i
.tm
.base_opcode
| 8) == 0xbe)
7311 || (i
.tm
.opcode_space
== SPACE_BASE
7312 && i
.tm
.base_opcode
== 0x63
7313 && i
.tm
.cpu_flags
.bitfield
.cpu64
);
7315 /* movsx/movzx want only their source operand considered here, for the
7316 ambiguity checking below. The suffix will be replaced afterwards
7317 to represent the destination (register). */
7318 if (is_movx
&& (i
.tm
.opcode_modifier
.w
|| i
.tm
.base_opcode
== 0x63))
7321 /* crc32 needs REX.W set regardless of suffix / source operand size. */
7322 if (i
.tm
.mnem_off
== MN_crc32
&& i
.tm
.operand_types
[1].bitfield
.qword
)
7325 /* If there's no instruction mnemonic suffix we try to invent one
7326 based on GPR operands. */
7329 /* We take i.suffix from the last register operand specified,
7330 Destination register type is more significant than source
7331 register type. crc32 in SSE4.2 prefers source register
7333 unsigned int op
= i
.tm
.mnem_off
== MN_crc32
? 1 : i
.operands
;
7336 if (i
.tm
.operand_types
[op
].bitfield
.instance
== InstanceNone
7337 || i
.tm
.operand_types
[op
].bitfield
.instance
== Accum
)
7339 if (i
.types
[op
].bitfield
.class != Reg
)
7341 if (i
.types
[op
].bitfield
.byte
)
7342 i
.suffix
= BYTE_MNEM_SUFFIX
;
7343 else if (i
.types
[op
].bitfield
.word
)
7344 i
.suffix
= WORD_MNEM_SUFFIX
;
7345 else if (i
.types
[op
].bitfield
.dword
)
7346 i
.suffix
= LONG_MNEM_SUFFIX
;
7347 else if (i
.types
[op
].bitfield
.qword
)
7348 i
.suffix
= QWORD_MNEM_SUFFIX
;
7354 /* As an exception, movsx/movzx silently default to a byte source
7356 if (is_movx
&& i
.tm
.opcode_modifier
.w
&& !i
.suffix
&& !intel_syntax
)
7357 i
.suffix
= BYTE_MNEM_SUFFIX
;
7359 else if (i
.suffix
== BYTE_MNEM_SUFFIX
)
7361 if (!check_byte_reg ())
7364 else if (i
.suffix
== LONG_MNEM_SUFFIX
)
7366 if (!check_long_reg ())
7369 else if (i
.suffix
== QWORD_MNEM_SUFFIX
)
7371 if (!check_qword_reg ())
7374 else if (i
.suffix
== WORD_MNEM_SUFFIX
)
7376 if (!check_word_reg ())
7379 else if (intel_syntax
7380 && i
.tm
.opcode_modifier
.mnemonicsize
== IGNORESIZE
)
7381 /* Do nothing if the instruction is going to ignore the prefix. */
7386 /* Undo the movsx/movzx change done above. */
7389 else if (i
.tm
.opcode_modifier
.mnemonicsize
== DEFAULTSIZE
7392 i
.suffix
= stackop_size
;
7393 if (stackop_size
== LONG_MNEM_SUFFIX
)
7395 /* stackop_size is set to LONG_MNEM_SUFFIX for the
7396 .code16gcc directive to support 16-bit mode with
7397 32-bit address. For IRET without a suffix, generate
7398 16-bit IRET (opcode 0xcf) to return from an interrupt
7400 if (i
.tm
.base_opcode
== 0xcf)
7402 i
.suffix
= WORD_MNEM_SUFFIX
;
7403 as_warn (_("generating 16-bit `iret' for .code16gcc directive"));
7405 /* Warn about changed behavior for segment register push/pop. */
7406 else if ((i
.tm
.base_opcode
| 1) == 0x07)
7407 as_warn (_("generating 32-bit `%s', unlike earlier gas versions"),
7412 && (i
.tm
.opcode_modifier
.jump
== JUMP_ABSOLUTE
7413 || i
.tm
.opcode_modifier
.jump
== JUMP_BYTE
7414 || i
.tm
.opcode_modifier
.jump
== JUMP_INTERSEGMENT
7415 || (i
.tm
.opcode_space
== SPACE_0F
7416 && i
.tm
.base_opcode
== 0x01 /* [ls][gi]dt */
7417 && i
.tm
.extension_opcode
<= 3)))
7422 if (!i
.tm
.opcode_modifier
.no_qsuf
)
7424 if (i
.tm
.opcode_modifier
.jump
== JUMP_BYTE
7425 || i
.tm
.opcode_modifier
.no_lsuf
)
7426 i
.suffix
= QWORD_MNEM_SUFFIX
;
7431 if (!i
.tm
.opcode_modifier
.no_lsuf
)
7432 i
.suffix
= LONG_MNEM_SUFFIX
;
7435 if (!i
.tm
.opcode_modifier
.no_wsuf
)
7436 i
.suffix
= WORD_MNEM_SUFFIX
;
7442 && (i
.tm
.opcode_modifier
.mnemonicsize
!= DEFAULTSIZE
7443 /* Also cover lret/retf/iret in 64-bit mode. */
7444 || (flag_code
== CODE_64BIT
7445 && !i
.tm
.opcode_modifier
.no_lsuf
7446 && !i
.tm
.opcode_modifier
.no_qsuf
))
7447 && i
.tm
.opcode_modifier
.mnemonicsize
!= IGNORESIZE
7448 /* Explicit sizing prefixes are assumed to disambiguate insns. */
7449 && !i
.prefix
[DATA_PREFIX
] && !(i
.prefix
[REX_PREFIX
] & REX_W
)
7450 /* Accept FLDENV et al without suffix. */
7451 && (i
.tm
.opcode_modifier
.no_ssuf
|| i
.tm
.opcode_modifier
.floatmf
))
7453 unsigned int suffixes
, evex
= 0;
7455 suffixes
= !i
.tm
.opcode_modifier
.no_bsuf
;
7456 if (!i
.tm
.opcode_modifier
.no_wsuf
)
7458 if (!i
.tm
.opcode_modifier
.no_lsuf
)
7460 if (!i
.tm
.opcode_modifier
.no_ssuf
)
7462 if (flag_code
== CODE_64BIT
&& !i
.tm
.opcode_modifier
.no_qsuf
)
7465 /* For [XYZ]MMWORD operands inspect operand sizes. While generally
7466 also suitable for AT&T syntax mode, it was requested that this be
7467 restricted to just Intel syntax. */
7468 if (intel_syntax
&& is_any_vex_encoding (&i
.tm
)
7469 && !i
.broadcast
.type
&& !i
.broadcast
.bytes
)
7473 for (op
= 0; op
< i
.tm
.operands
; ++op
)
7475 if (is_evex_encoding (&i
.tm
)
7476 && !cpu_arch_flags
.bitfield
.cpuavx512vl
)
7478 if (i
.tm
.operand_types
[op
].bitfield
.ymmword
)
7479 i
.tm
.operand_types
[op
].bitfield
.xmmword
= 0;
7480 if (i
.tm
.operand_types
[op
].bitfield
.zmmword
)
7481 i
.tm
.operand_types
[op
].bitfield
.ymmword
= 0;
7482 if (!i
.tm
.opcode_modifier
.evex
7483 || i
.tm
.opcode_modifier
.evex
== EVEXDYN
)
7484 i
.tm
.opcode_modifier
.evex
= EVEX512
;
7487 if (i
.tm
.operand_types
[op
].bitfield
.xmmword
7488 + i
.tm
.operand_types
[op
].bitfield
.ymmword
7489 + i
.tm
.operand_types
[op
].bitfield
.zmmword
< 2)
7492 /* Any properly sized operand disambiguates the insn. */
7493 if (i
.types
[op
].bitfield
.xmmword
7494 || i
.types
[op
].bitfield
.ymmword
7495 || i
.types
[op
].bitfield
.zmmword
)
7497 suffixes
&= ~(7 << 6);
7502 if ((i
.flags
[op
] & Operand_Mem
)
7503 && i
.tm
.operand_types
[op
].bitfield
.unspecified
)
7505 if (i
.tm
.operand_types
[op
].bitfield
.xmmword
)
7507 if (i
.tm
.operand_types
[op
].bitfield
.ymmword
)
7509 if (i
.tm
.operand_types
[op
].bitfield
.zmmword
)
7511 if (is_evex_encoding (&i
.tm
))
7517 /* Are multiple suffixes / operand sizes allowed? */
7518 if (suffixes
& (suffixes
- 1))
7521 && (i
.tm
.opcode_modifier
.mnemonicsize
!= DEFAULTSIZE
7522 || operand_check
== check_error
))
7524 as_bad (_("ambiguous operand size for `%s'"), insn_name (&i
.tm
));
7527 if (operand_check
== check_error
)
7529 as_bad (_("no instruction mnemonic suffix given and "
7530 "no register operands; can't size `%s'"), insn_name (&i
.tm
));
7533 if (operand_check
== check_warning
)
7534 as_warn (_("%s; using default for `%s'"),
7536 ? _("ambiguous operand size")
7537 : _("no instruction mnemonic suffix given and "
7538 "no register operands"),
7541 if (i
.tm
.opcode_modifier
.floatmf
)
7542 i
.suffix
= SHORT_MNEM_SUFFIX
;
7544 /* handled below */;
7546 i
.tm
.opcode_modifier
.evex
= evex
;
7547 else if (flag_code
== CODE_16BIT
)
7548 i
.suffix
= WORD_MNEM_SUFFIX
;
7549 else if (!i
.tm
.opcode_modifier
.no_lsuf
)
7550 i
.suffix
= LONG_MNEM_SUFFIX
;
7552 i
.suffix
= QWORD_MNEM_SUFFIX
;
7558 /* In Intel syntax, movsx/movzx must have a "suffix" (checked above).
7559 In AT&T syntax, if there is no suffix (warned about above), the default
7560 will be byte extension. */
7561 if (i
.tm
.opcode_modifier
.w
&& i
.suffix
&& i
.suffix
!= BYTE_MNEM_SUFFIX
)
7562 i
.tm
.base_opcode
|= 1;
7564 /* For further processing, the suffix should represent the destination
7565 (register). This is already the case when one was used with
7566 mov[sz][bw]*, but we need to replace it for mov[sz]x, or if there was
7567 no suffix to begin with. */
7568 if (i
.tm
.opcode_modifier
.w
|| i
.tm
.base_opcode
== 0x63 || !i
.suffix
)
7570 if (i
.types
[1].bitfield
.word
)
7571 i
.suffix
= WORD_MNEM_SUFFIX
;
7572 else if (i
.types
[1].bitfield
.qword
)
7573 i
.suffix
= QWORD_MNEM_SUFFIX
;
7575 i
.suffix
= LONG_MNEM_SUFFIX
;
7577 i
.tm
.opcode_modifier
.w
= 0;
7581 if (!i
.tm
.opcode_modifier
.modrm
&& i
.reg_operands
&& i
.tm
.operands
< 3)
7582 i
.short_form
= (i
.tm
.operand_types
[0].bitfield
.class == Reg
)
7583 != (i
.tm
.operand_types
[1].bitfield
.class == Reg
);
7585 /* Change the opcode based on the operand size given by i.suffix. */
7588 /* Size floating point instruction. */
7589 case LONG_MNEM_SUFFIX
:
7590 if (i
.tm
.opcode_modifier
.floatmf
)
7592 i
.tm
.base_opcode
^= 4;
7596 case WORD_MNEM_SUFFIX
:
7597 case QWORD_MNEM_SUFFIX
:
7598 /* It's not a byte, select word/dword operation. */
7599 if (i
.tm
.opcode_modifier
.w
)
7602 i
.tm
.base_opcode
|= 8;
7604 i
.tm
.base_opcode
|= 1;
7607 case SHORT_MNEM_SUFFIX
:
7608 /* Now select between word & dword operations via the operand
7609 size prefix, except for instructions that will ignore this
7611 if (i
.suffix
!= QWORD_MNEM_SUFFIX
7612 && i
.tm
.opcode_modifier
.mnemonicsize
!= IGNORESIZE
7613 && !i
.tm
.opcode_modifier
.floatmf
7614 && !is_any_vex_encoding (&i
.tm
)
7615 && ((i
.suffix
== LONG_MNEM_SUFFIX
) == (flag_code
== CODE_16BIT
)
7616 || (flag_code
== CODE_64BIT
7617 && i
.tm
.opcode_modifier
.jump
== JUMP_BYTE
)))
7619 unsigned int prefix
= DATA_PREFIX_OPCODE
;
7621 if (i
.tm
.opcode_modifier
.jump
== JUMP_BYTE
) /* jcxz, loop */
7622 prefix
= ADDR_PREFIX_OPCODE
;
7624 if (!add_prefix (prefix
))
7628 /* Set mode64 for an operand. */
7629 if (i
.suffix
== QWORD_MNEM_SUFFIX
7630 && flag_code
== CODE_64BIT
7631 && !i
.tm
.opcode_modifier
.norex64
7632 && !i
.tm
.opcode_modifier
.vexw
7633 /* Special case for xchg %rax,%rax. It is NOP and doesn't
7635 && ! (i
.operands
== 2
7636 && i
.tm
.base_opcode
== 0x90
7637 && i
.tm
.opcode_space
== SPACE_BASE
7638 && i
.types
[0].bitfield
.instance
== Accum
7639 && i
.types
[0].bitfield
.qword
7640 && i
.types
[1].bitfield
.instance
== Accum
))
7646 /* Select word/dword/qword operation with explicit data sizing prefix
7647 when there are no suitable register operands. */
7648 if (i
.tm
.opcode_modifier
.w
7649 && (i
.prefix
[DATA_PREFIX
] || (i
.prefix
[REX_PREFIX
] & REX_W
))
7651 || (i
.reg_operands
== 1
7653 && (i
.tm
.operand_types
[0].bitfield
.instance
== RegC
7655 || i
.tm
.operand_types
[0].bitfield
.instance
== RegD
7656 || i
.tm
.operand_types
[1].bitfield
.instance
== RegD
7657 || i
.tm
.mnem_off
== MN_crc32
))))
7658 i
.tm
.base_opcode
|= 1;
7662 if (i
.tm
.opcode_modifier
.operandconstraint
== ADDR_PREFIX_OP_REG
)
7664 gas_assert (!i
.suffix
);
7665 gas_assert (i
.reg_operands
);
7667 if (i
.tm
.operand_types
[0].bitfield
.instance
== Accum
7670 /* The address size override prefix changes the size of the
7672 if (flag_code
== CODE_64BIT
7673 && i
.op
[0].regs
->reg_type
.bitfield
.word
)
7675 as_bad (_("16-bit addressing unavailable for `%s'"),
7680 if ((flag_code
== CODE_32BIT
7681 ? i
.op
[0].regs
->reg_type
.bitfield
.word
7682 : i
.op
[0].regs
->reg_type
.bitfield
.dword
)
7683 && !add_prefix (ADDR_PREFIX_OPCODE
))
7688 /* Check invalid register operand when the address size override
7689 prefix changes the size of register operands. */
7691 enum { need_word
, need_dword
, need_qword
} need
;
7693 /* Check the register operand for the address size prefix if
7694 the memory operand has no real registers, like symbol, DISP
7695 or bogus (x32-only) symbol(%rip) when symbol(%eip) is meant. */
7696 if (i
.mem_operands
== 1
7697 && i
.reg_operands
== 1
7699 && i
.types
[1].bitfield
.class == Reg
7700 && (flag_code
== CODE_32BIT
7701 ? i
.op
[1].regs
->reg_type
.bitfield
.word
7702 : i
.op
[1].regs
->reg_type
.bitfield
.dword
)
7703 && ((i
.base_reg
== NULL
&& i
.index_reg
== NULL
)
7704 #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF)
7705 || (x86_elf_abi
== X86_64_X32_ABI
7707 && i
.base_reg
->reg_num
== RegIP
7708 && i
.base_reg
->reg_type
.bitfield
.qword
))
7712 && !add_prefix (ADDR_PREFIX_OPCODE
))
7715 if (flag_code
== CODE_32BIT
)
7716 need
= i
.prefix
[ADDR_PREFIX
] ? need_word
: need_dword
;
7717 else if (i
.prefix
[ADDR_PREFIX
])
7720 need
= flag_code
== CODE_64BIT
? need_qword
: need_word
;
7722 for (op
= 0; op
< i
.operands
; op
++)
7724 if (i
.types
[op
].bitfield
.class != Reg
)
7730 if (i
.op
[op
].regs
->reg_type
.bitfield
.word
)
7734 if (i
.op
[op
].regs
->reg_type
.bitfield
.dword
)
7738 if (i
.op
[op
].regs
->reg_type
.bitfield
.qword
)
7743 as_bad (_("invalid register operand size for `%s'"),
7754 check_byte_reg (void)
7758 for (op
= i
.operands
; --op
>= 0;)
7760 /* Skip non-register operands. */
7761 if (i
.types
[op
].bitfield
.class != Reg
)
7764 /* If this is an eight bit register, it's OK. If it's the 16 or
7765 32 bit version of an eight bit register, we will just use the
7766 low portion, and that's OK too. */
7767 if (i
.types
[op
].bitfield
.byte
)
7770 /* I/O port address operands are OK too. */
7771 if (i
.tm
.operand_types
[op
].bitfield
.instance
== RegD
7772 && i
.tm
.operand_types
[op
].bitfield
.word
)
7775 /* crc32 only wants its source operand checked here. */
7776 if (i
.tm
.mnem_off
== MN_crc32
&& op
!= 0)
7779 /* Any other register is bad. */
7780 as_bad (_("`%s%s' not allowed with `%s%c'"),
7781 register_prefix
, i
.op
[op
].regs
->reg_name
,
7782 insn_name (&i
.tm
), i
.suffix
);
7789 check_long_reg (void)
7793 for (op
= i
.operands
; --op
>= 0;)
7794 /* Skip non-register operands. */
7795 if (i
.types
[op
].bitfield
.class != Reg
)
7797 /* Reject eight bit registers, except where the template requires
7798 them. (eg. movzb) */
7799 else if (i
.types
[op
].bitfield
.byte
7800 && (i
.tm
.operand_types
[op
].bitfield
.class == Reg
7801 || i
.tm
.operand_types
[op
].bitfield
.instance
== Accum
)
7802 && (i
.tm
.operand_types
[op
].bitfield
.word
7803 || i
.tm
.operand_types
[op
].bitfield
.dword
))
7805 as_bad (_("`%s%s' not allowed with `%s%c'"),
7807 i
.op
[op
].regs
->reg_name
,
7812 /* Error if the e prefix on a general reg is missing. */
7813 else if (i
.types
[op
].bitfield
.word
7814 && (i
.tm
.operand_types
[op
].bitfield
.class == Reg
7815 || i
.tm
.operand_types
[op
].bitfield
.instance
== Accum
)
7816 && i
.tm
.operand_types
[op
].bitfield
.dword
)
7818 as_bad (_("incorrect register `%s%s' used with `%c' suffix"),
7819 register_prefix
, i
.op
[op
].regs
->reg_name
,
7823 /* Warn if the r prefix on a general reg is present. */
7824 else if (i
.types
[op
].bitfield
.qword
7825 && (i
.tm
.operand_types
[op
].bitfield
.class == Reg
7826 || i
.tm
.operand_types
[op
].bitfield
.instance
== Accum
)
7827 && i
.tm
.operand_types
[op
].bitfield
.dword
)
7829 as_bad (_("incorrect register `%s%s' used with `%c' suffix"),
7830 register_prefix
, i
.op
[op
].regs
->reg_name
, i
.suffix
);
7837 check_qword_reg (void)
7841 for (op
= i
.operands
; --op
>= 0; )
7842 /* Skip non-register operands. */
7843 if (i
.types
[op
].bitfield
.class != Reg
)
7845 /* Reject eight bit registers, except where the template requires
7846 them. (eg. movzb) */
7847 else if (i
.types
[op
].bitfield
.byte
7848 && (i
.tm
.operand_types
[op
].bitfield
.class == Reg
7849 || i
.tm
.operand_types
[op
].bitfield
.instance
== Accum
)
7850 && (i
.tm
.operand_types
[op
].bitfield
.word
7851 || i
.tm
.operand_types
[op
].bitfield
.dword
))
7853 as_bad (_("`%s%s' not allowed with `%s%c'"),
7855 i
.op
[op
].regs
->reg_name
,
7860 /* Warn if the r prefix on a general reg is missing. */
7861 else if ((i
.types
[op
].bitfield
.word
7862 || i
.types
[op
].bitfield
.dword
)
7863 && (i
.tm
.operand_types
[op
].bitfield
.class == Reg
7864 || i
.tm
.operand_types
[op
].bitfield
.instance
== Accum
)
7865 && i
.tm
.operand_types
[op
].bitfield
.qword
)
7867 /* Prohibit these changes in the 64bit mode, since the
7868 lowering is more complicated. */
7869 as_bad (_("incorrect register `%s%s' used with `%c' suffix"),
7870 register_prefix
, i
.op
[op
].regs
->reg_name
, i
.suffix
);
7877 check_word_reg (void)
7880 for (op
= i
.operands
; --op
>= 0;)
7881 /* Skip non-register operands. */
7882 if (i
.types
[op
].bitfield
.class != Reg
)
7884 /* Reject eight bit registers, except where the template requires
7885 them. (eg. movzb) */
7886 else if (i
.types
[op
].bitfield
.byte
7887 && (i
.tm
.operand_types
[op
].bitfield
.class == Reg
7888 || i
.tm
.operand_types
[op
].bitfield
.instance
== Accum
)
7889 && (i
.tm
.operand_types
[op
].bitfield
.word
7890 || i
.tm
.operand_types
[op
].bitfield
.dword
))
7892 as_bad (_("`%s%s' not allowed with `%s%c'"),
7894 i
.op
[op
].regs
->reg_name
,
7899 /* Error if the e or r prefix on a general reg is present. */
7900 else if ((i
.types
[op
].bitfield
.dword
7901 || i
.types
[op
].bitfield
.qword
)
7902 && (i
.tm
.operand_types
[op
].bitfield
.class == Reg
7903 || i
.tm
.operand_types
[op
].bitfield
.instance
== Accum
)
7904 && i
.tm
.operand_types
[op
].bitfield
.word
)
7906 as_bad (_("incorrect register `%s%s' used with `%c' suffix"),
7907 register_prefix
, i
.op
[op
].regs
->reg_name
,
7915 update_imm (unsigned int j
)
7917 i386_operand_type overlap
= i
.types
[j
];
7919 if (i
.tm
.operand_types
[j
].bitfield
.imm8
7920 && i
.tm
.operand_types
[j
].bitfield
.imm8s
7921 && overlap
.bitfield
.imm8
&& overlap
.bitfield
.imm8s
)
7923 /* This combination is used on 8-bit immediates where e.g. $~0 is
7924 desirable to permit. We're past operand type matching, so simply
7925 put things back in the shape they were before introducing the
7926 distinction between Imm8, Imm8S, and Imm8|Imm8S. */
7927 overlap
.bitfield
.imm8s
= 0;
7930 if (overlap
.bitfield
.imm8
7931 + overlap
.bitfield
.imm8s
7932 + overlap
.bitfield
.imm16
7933 + overlap
.bitfield
.imm32
7934 + overlap
.bitfield
.imm32s
7935 + overlap
.bitfield
.imm64
> 1)
7937 static const i386_operand_type imm16
= { .bitfield
= { .imm16
= 1 } };
7938 static const i386_operand_type imm32
= { .bitfield
= { .imm32
= 1 } };
7939 static const i386_operand_type imm32s
= { .bitfield
= { .imm32s
= 1 } };
7940 static const i386_operand_type imm16_32
= { .bitfield
=
7941 { .imm16
= 1, .imm32
= 1 }
7943 static const i386_operand_type imm16_32s
= { .bitfield
=
7944 { .imm16
= 1, .imm32s
= 1 }
7946 static const i386_operand_type imm16_32_32s
= { .bitfield
=
7947 { .imm16
= 1, .imm32
= 1, .imm32s
= 1 }
7952 i386_operand_type temp
;
7954 operand_type_set (&temp
, 0);
7955 if (i
.suffix
== BYTE_MNEM_SUFFIX
)
7957 temp
.bitfield
.imm8
= overlap
.bitfield
.imm8
;
7958 temp
.bitfield
.imm8s
= overlap
.bitfield
.imm8s
;
7960 else if (i
.suffix
== WORD_MNEM_SUFFIX
)
7961 temp
.bitfield
.imm16
= overlap
.bitfield
.imm16
;
7962 else if (i
.suffix
== QWORD_MNEM_SUFFIX
)
7964 temp
.bitfield
.imm64
= overlap
.bitfield
.imm64
;
7965 temp
.bitfield
.imm32s
= overlap
.bitfield
.imm32s
;
7968 temp
.bitfield
.imm32
= overlap
.bitfield
.imm32
;
7971 else if (operand_type_equal (&overlap
, &imm16_32_32s
)
7972 || operand_type_equal (&overlap
, &imm16_32
)
7973 || operand_type_equal (&overlap
, &imm16_32s
))
7975 if ((flag_code
== CODE_16BIT
) ^ (i
.prefix
[DATA_PREFIX
] != 0))
7980 else if (i
.prefix
[REX_PREFIX
] & REX_W
)
7981 overlap
= operand_type_and (overlap
, imm32s
);
7982 else if (i
.prefix
[DATA_PREFIX
])
7983 overlap
= operand_type_and (overlap
,
7984 flag_code
!= CODE_16BIT
? imm16
: imm32
);
7985 if (overlap
.bitfield
.imm8
7986 + overlap
.bitfield
.imm8s
7987 + overlap
.bitfield
.imm16
7988 + overlap
.bitfield
.imm32
7989 + overlap
.bitfield
.imm32s
7990 + overlap
.bitfield
.imm64
!= 1)
7992 as_bad (_("no instruction mnemonic suffix given; "
7993 "can't determine immediate size"));
7997 i
.types
[j
] = overlap
;
8007 /* Update the first 2 immediate operands. */
8008 n
= i
.operands
> 2 ? 2 : i
.operands
;
8011 for (j
= 0; j
< n
; j
++)
8012 if (update_imm (j
) == 0)
8015 /* The 3rd operand can't be immediate operand. */
8016 gas_assert (operand_type_check (i
.types
[2], imm
) == 0);
8022 static INLINE
void set_rex_vrex (const reg_entry
*r
, unsigned int rex_bit
,
8025 if (r
->reg_flags
& RegRex
)
8027 if (i
.rex
& rex_bit
)
8028 as_bad (_("same type of prefix used twice"));
8031 else if (do_sse2avx
&& (i
.rex
& rex_bit
) && i
.vex
.register_specifier
)
8033 gas_assert (i
.vex
.register_specifier
== r
);
8034 i
.vex
.register_specifier
+= 8;
8037 if (r
->reg_flags
& RegVRex
)
8042 process_operands (void)
8044 /* Default segment register this instruction will use for memory
8045 accesses. 0 means unknown. This is only for optimizing out
8046 unnecessary segment overrides. */
8047 const reg_entry
*default_seg
= NULL
;
8049 /* We only need to check those implicit registers for instructions
8050 with 3 operands or less. */
8051 if (i
.operands
<= 3)
8052 for (unsigned int j
= 0; j
< i
.operands
; j
++)
8053 if (i
.types
[j
].bitfield
.instance
!= InstanceNone
)
8056 if (i
.tm
.opcode_modifier
.sse2avx
)
8058 /* Legacy encoded insns allow explicit REX prefixes, so these prefixes
8060 i
.rex
|= i
.prefix
[REX_PREFIX
] & (REX_W
| REX_R
| REX_X
| REX_B
);
8061 i
.prefix
[REX_PREFIX
] = 0;
8064 /* ImmExt should be processed after SSE2AVX. */
8065 else if (i
.tm
.opcode_modifier
.immext
)
8068 /* TILEZERO is unusual in that it has a single operand encoded in ModR/M.reg,
8069 not ModR/M.rm. To avoid special casing this in build_modrm_byte(), fake a
8070 new destination operand here, while converting the source one to register
8072 if (i
.tm
.mnem_off
== MN_tilezero
)
8074 i
.op
[1].regs
= i
.op
[0].regs
;
8075 i
.op
[0].regs
-= i
.op
[0].regs
->reg_num
;
8076 i
.types
[1] = i
.types
[0];
8077 i
.tm
.operand_types
[1] = i
.tm
.operand_types
[0];
8078 i
.flags
[1] = i
.flags
[0];
8084 if (i
.tm
.opcode_modifier
.sse2avx
&& i
.tm
.opcode_modifier
.vexvvvv
)
8086 static const i386_operand_type regxmm
= {
8087 .bitfield
= { .class = RegSIMD
, .xmmword
= 1 }
8089 unsigned int dupl
= i
.operands
;
8090 unsigned int dest
= dupl
- 1;
8093 /* The destination must be an xmm register. */
8094 gas_assert (i
.reg_operands
8095 && MAX_OPERANDS
> dupl
8096 && operand_type_equal (&i
.types
[dest
], ®xmm
));
8098 if (i
.tm
.operand_types
[0].bitfield
.instance
== Accum
8099 && i
.tm
.operand_types
[0].bitfield
.xmmword
)
8101 /* Keep xmm0 for instructions with VEX prefix and 3
8103 i
.tm
.operand_types
[0].bitfield
.instance
= InstanceNone
;
8104 i
.tm
.operand_types
[0].bitfield
.class = RegSIMD
;
8109 if (i
.tm
.opcode_modifier
.operandconstraint
== IMPLICIT_1ST_XMM0
)
8111 gas_assert ((MAX_OPERANDS
- 1) > dupl
);
8113 /* Add the implicit xmm0 for instructions with VEX prefix
8115 for (j
= i
.operands
; j
> 0; j
--)
8117 i
.op
[j
] = i
.op
[j
- 1];
8118 i
.types
[j
] = i
.types
[j
- 1];
8119 i
.tm
.operand_types
[j
] = i
.tm
.operand_types
[j
- 1];
8120 i
.flags
[j
] = i
.flags
[j
- 1];
8123 = (const reg_entry
*) str_hash_find (reg_hash
, "xmm0");
8124 i
.types
[0] = regxmm
;
8125 i
.tm
.operand_types
[0] = regxmm
;
8128 i
.reg_operands
+= 2;
8133 i
.op
[dupl
] = i
.op
[dest
];
8134 i
.types
[dupl
] = i
.types
[dest
];
8135 i
.tm
.operand_types
[dupl
] = i
.tm
.operand_types
[dest
];
8136 i
.flags
[dupl
] = i
.flags
[dest
];
8145 i
.op
[dupl
] = i
.op
[dest
];
8146 i
.types
[dupl
] = i
.types
[dest
];
8147 i
.tm
.operand_types
[dupl
] = i
.tm
.operand_types
[dest
];
8148 i
.flags
[dupl
] = i
.flags
[dest
];
8151 if (i
.tm
.opcode_modifier
.immext
)
8154 else if (i
.tm
.operand_types
[0].bitfield
.instance
== Accum
8155 && i
.tm
.opcode_modifier
.modrm
)
8159 for (j
= 1; j
< i
.operands
; j
++)
8161 i
.op
[j
- 1] = i
.op
[j
];
8162 i
.types
[j
- 1] = i
.types
[j
];
8164 /* We need to adjust fields in i.tm since they are used by
8165 build_modrm_byte. */
8166 i
.tm
.operand_types
[j
- 1] = i
.tm
.operand_types
[j
];
8168 i
.flags
[j
- 1] = i
.flags
[j
];
8171 /* No adjustment to i.reg_operands: This was already done at the top
8176 else if (i
.tm
.opcode_modifier
.operandconstraint
== IMPLICIT_QUAD_GROUP
)
8178 unsigned int regnum
, first_reg_in_group
, last_reg_in_group
;
8180 /* The second operand must be {x,y,z}mmN, where N is a multiple of 4. */
8181 gas_assert (i
.operands
>= 2 && i
.types
[1].bitfield
.class == RegSIMD
);
8182 regnum
= register_number (i
.op
[1].regs
);
8183 first_reg_in_group
= regnum
& ~3;
8184 last_reg_in_group
= first_reg_in_group
+ 3;
8185 if (regnum
!= first_reg_in_group
)
8186 as_warn (_("source register `%s%s' implicitly denotes"
8187 " `%s%.3s%u' to `%s%.3s%u' source group in `%s'"),
8188 register_prefix
, i
.op
[1].regs
->reg_name
,
8189 register_prefix
, i
.op
[1].regs
->reg_name
, first_reg_in_group
,
8190 register_prefix
, i
.op
[1].regs
->reg_name
, last_reg_in_group
,
8193 else if (i
.tm
.opcode_modifier
.operandconstraint
== REG_KLUDGE
)
8195 /* The imul $imm, %reg instruction is converted into
8196 imul $imm, %reg, %reg, and the clr %reg instruction
8197 is converted into xor %reg, %reg. */
8199 unsigned int first_reg_op
;
8201 if (operand_type_check (i
.types
[0], reg
))
8205 /* Pretend we saw the extra register operand. */
8206 gas_assert (i
.reg_operands
== 1
8207 && i
.op
[first_reg_op
+ 1].regs
== 0);
8208 i
.op
[first_reg_op
+ 1].regs
= i
.op
[first_reg_op
].regs
;
8209 i
.types
[first_reg_op
+ 1] = i
.types
[first_reg_op
];
8214 if (i
.tm
.opcode_modifier
.modrm
)
8216 /* The opcode is completed (modulo i.tm.extension_opcode which
8217 must be put into the modrm byte). Now, we make the modrm and
8218 index base bytes based on all the info we've collected. */
8220 default_seg
= build_modrm_byte ();
8222 if (!quiet_warnings
&& i
.tm
.opcode_modifier
.operandconstraint
== UGH
)
8224 /* Warn about some common errors, but press on regardless. */
8225 if (i
.operands
== 2)
8227 /* Reversed arguments on faddp or fmulp. */
8228 as_warn (_("translating to `%s %s%s,%s%s'"), insn_name (&i
.tm
),
8229 register_prefix
, i
.op
[!intel_syntax
].regs
->reg_name
,
8230 register_prefix
, i
.op
[intel_syntax
].regs
->reg_name
);
8232 else if (i
.tm
.opcode_modifier
.mnemonicsize
== IGNORESIZE
)
8234 /* Extraneous `l' suffix on fp insn. */
8235 as_warn (_("translating to `%s %s%s'"), insn_name (&i
.tm
),
8236 register_prefix
, i
.op
[0].regs
->reg_name
);
8240 else if (i
.types
[0].bitfield
.class == SReg
&& !dot_insn ())
8242 if (flag_code
!= CODE_64BIT
8243 ? i
.tm
.base_opcode
== POP_SEG_SHORT
8244 && i
.op
[0].regs
->reg_num
== 1
8245 : (i
.tm
.base_opcode
| 1) == (POP_SEG386_SHORT
& 0xff)
8246 && i
.op
[0].regs
->reg_num
< 4)
8248 as_bad (_("you can't `%s %s%s'"),
8249 insn_name (&i
.tm
), register_prefix
, i
.op
[0].regs
->reg_name
);
8252 if (i
.op
[0].regs
->reg_num
> 3
8253 && i
.tm
.opcode_space
== SPACE_BASE
)
8255 i
.tm
.base_opcode
^= (POP_SEG_SHORT
^ POP_SEG386_SHORT
) & 0xff;
8256 i
.tm
.opcode_space
= SPACE_0F
;
8258 i
.tm
.base_opcode
|= (i
.op
[0].regs
->reg_num
<< 3);
8260 else if (i
.tm
.opcode_space
== SPACE_BASE
8261 && (i
.tm
.base_opcode
& ~3) == MOV_AX_DISP32
)
8263 default_seg
= reg_ds
;
8265 else if (i
.tm
.opcode_modifier
.isstring
)
8267 /* For the string instructions that allow a segment override
8268 on one of their operands, the default segment is ds. */
8269 default_seg
= reg_ds
;
8271 else if (i
.short_form
)
8273 /* The register operand is in the 1st or 2nd non-immediate operand. */
8274 const reg_entry
*r
= i
.op
[i
.imm_operands
].regs
;
8277 && r
->reg_type
.bitfield
.instance
== Accum
8278 && i
.op
[i
.imm_operands
+ 1].regs
)
8279 r
= i
.op
[i
.imm_operands
+ 1].regs
;
8280 /* Register goes in low 3 bits of opcode. */
8281 i
.tm
.base_opcode
|= r
->reg_num
;
8282 set_rex_vrex (r
, REX_B
, false);
8284 if (dot_insn () && i
.reg_operands
== 2)
8286 gas_assert (is_any_vex_encoding (&i
.tm
)
8287 || i
.vec_encoding
!= vex_encoding_default
);
8288 i
.vex
.register_specifier
= i
.op
[i
.operands
- 1].regs
;
8291 else if (i
.reg_operands
== 1
8292 && !i
.flags
[i
.operands
- 1]
8293 && i
.tm
.operand_types
[i
.operands
- 1].bitfield
.instance
8296 gas_assert (is_any_vex_encoding (&i
.tm
)
8297 || i
.vec_encoding
!= vex_encoding_default
);
8298 i
.vex
.register_specifier
= i
.op
[i
.operands
- 1].regs
;
8301 if ((i
.seg
[0] || i
.prefix
[SEG_PREFIX
])
8302 && i
.tm
.mnem_off
== MN_lea
)
8304 if (!quiet_warnings
)
8305 as_warn (_("segment override on `%s' is ineffectual"), insn_name (&i
.tm
));
8306 if (optimize
&& !i
.no_optimize
)
8309 i
.prefix
[SEG_PREFIX
] = 0;
8313 /* If a segment was explicitly specified, and the specified segment
8314 is neither the default nor the one already recorded from a prefix,
8315 use an opcode prefix to select it. If we never figured out what
8316 the default segment is, then default_seg will be zero at this
8317 point, and the specified segment prefix will always be used. */
8319 && i
.seg
[0] != default_seg
8320 && i386_seg_prefixes
[i
.seg
[0]->reg_num
] != i
.prefix
[SEG_PREFIX
])
8322 if (!add_prefix (i386_seg_prefixes
[i
.seg
[0]->reg_num
]))
8328 static const reg_entry
*
8329 build_modrm_byte (void)
8331 const reg_entry
*default_seg
= NULL
;
8332 unsigned int source
= i
.imm_operands
- i
.tm
.opcode_modifier
.immext
8333 /* Compensate for kludge in md_assemble(). */
8334 + i
.tm
.operand_types
[0].bitfield
.imm1
;
8335 unsigned int dest
= i
.operands
- 1 - i
.tm
.opcode_modifier
.immext
;
8336 unsigned int v
, op
, reg_slot
= ~0;
8338 /* Accumulator (in particular %st), shift count (%cl), and alike need
8339 to be skipped just like immediate operands do. */
8340 if (i
.tm
.operand_types
[source
].bitfield
.instance
)
8342 while (i
.tm
.operand_types
[dest
].bitfield
.instance
)
8345 for (op
= source
; op
< i
.operands
; ++op
)
8346 if (i
.tm
.operand_types
[op
].bitfield
.baseindex
)
8349 if (i
.reg_operands
+ i
.mem_operands
+ (i
.tm
.extension_opcode
!= None
) == 4)
8353 /* There are 2 kinds of instructions:
8354 1. 5 operands: 4 register operands or 3 register operands
8355 plus 1 memory operand plus one Imm4 operand, VexXDS, and
8356 VexW0 or VexW1. The destination must be either XMM, YMM or
8358 2. 4 operands: 4 register operands or 3 register operands
8359 plus 1 memory operand, with VexXDS.
8360 3. Other equivalent combinations when coming from s_insn(). */
8361 gas_assert (i
.tm
.opcode_modifier
.vexvvvv
8362 && i
.tm
.opcode_modifier
.vexw
);
8363 gas_assert (dot_insn ()
8364 || i
.tm
.operand_types
[dest
].bitfield
.class == RegSIMD
);
8366 /* Of the first two non-immediate operands the one with the template
8367 not allowing for a memory one is encoded in the immediate operand. */
8369 reg_slot
= source
+ 1;
8371 reg_slot
= source
++;
8375 gas_assert (i
.tm
.operand_types
[reg_slot
].bitfield
.class == RegSIMD
);
8376 gas_assert (!(i
.op
[reg_slot
].regs
->reg_flags
& RegVRex
));
8379 gas_assert (i
.tm
.operand_types
[reg_slot
].bitfield
.class != ClassNone
);
8381 if (i
.imm_operands
== 0)
8383 /* When there is no immediate operand, generate an 8bit
8384 immediate operand to encode the first operand. */
8385 exp
= &im_expressions
[i
.imm_operands
++];
8386 i
.op
[i
.operands
].imms
= exp
;
8387 i
.types
[i
.operands
].bitfield
.imm8
= 1;
8390 exp
->X_op
= O_constant
;
8394 gas_assert (i
.imm_operands
== 1);
8395 gas_assert (fits_in_imm4 (i
.op
[0].imms
->X_add_number
));
8396 gas_assert (!i
.tm
.opcode_modifier
.immext
);
8398 /* Turn on Imm8 again so that output_imm will generate it. */
8399 i
.types
[0].bitfield
.imm8
= 1;
8403 exp
->X_add_number
|= register_number (i
.op
[reg_slot
].regs
)
8404 << (3 + !(is_evex_encoding (&i
.tm
)
8405 || i
.vec_encoding
== vex_encoding_evex
));
8408 for (v
= source
+ 1; v
< dest
; ++v
)
8413 if (i
.tm
.extension_opcode
!= None
)
8419 gas_assert (source
< dest
);
8420 if (i
.tm
.opcode_modifier
.operandconstraint
== SWAP_SOURCES
8423 unsigned int tmp
= source
;
8429 if (v
< MAX_OPERANDS
)
8431 gas_assert (i
.tm
.opcode_modifier
.vexvvvv
);
8432 i
.vex
.register_specifier
= i
.op
[v
].regs
;
8435 if (op
< i
.operands
)
8439 unsigned int fake_zero_displacement
= 0;
8441 gas_assert (i
.flags
[op
] & Operand_Mem
);
8443 if (i
.tm
.opcode_modifier
.sib
)
8445 /* The index register of VSIB shouldn't be RegIZ. */
8446 if (i
.tm
.opcode_modifier
.sib
!= SIBMEM
8447 && i
.index_reg
->reg_num
== RegIZ
)
8450 i
.rm
.regmem
= ESCAPE_TO_TWO_BYTE_ADDRESSING
;
8453 i
.sib
.base
= NO_BASE_REGISTER
;
8454 i
.sib
.scale
= i
.log2_scale_factor
;
8455 i
.types
[op
] = operand_type_and_not (i
.types
[op
], anydisp
);
8456 i
.types
[op
].bitfield
.disp32
= 1;
8459 /* Since the mandatory SIB always has index register, so
8460 the code logic remains unchanged. The non-mandatory SIB
8461 without index register is allowed and will be handled
8465 if (i
.index_reg
->reg_num
== RegIZ
)
8466 i
.sib
.index
= NO_INDEX_REGISTER
;
8468 i
.sib
.index
= i
.index_reg
->reg_num
;
8469 set_rex_vrex (i
.index_reg
, REX_X
, false);
8473 default_seg
= reg_ds
;
8475 if (i
.base_reg
== 0)
8478 if (!i
.disp_operands
)
8479 fake_zero_displacement
= 1;
8480 if (i
.index_reg
== 0)
8482 /* Both check for VSIB and mandatory non-vector SIB. */
8483 gas_assert (!i
.tm
.opcode_modifier
.sib
8484 || i
.tm
.opcode_modifier
.sib
== SIBMEM
);
8485 /* Operand is just <disp> */
8486 i
.types
[op
] = operand_type_and_not (i
.types
[op
], anydisp
);
8487 if (flag_code
== CODE_64BIT
)
8489 /* 64bit mode overwrites the 32bit absolute
8490 addressing by RIP relative addressing and
8491 absolute addressing is encoded by one of the
8492 redundant SIB forms. */
8493 i
.rm
.regmem
= ESCAPE_TO_TWO_BYTE_ADDRESSING
;
8494 i
.sib
.base
= NO_BASE_REGISTER
;
8495 i
.sib
.index
= NO_INDEX_REGISTER
;
8496 i
.types
[op
].bitfield
.disp32
= 1;
8498 else if ((flag_code
== CODE_16BIT
)
8499 ^ (i
.prefix
[ADDR_PREFIX
] != 0))
8501 i
.rm
.regmem
= NO_BASE_REGISTER_16
;
8502 i
.types
[op
].bitfield
.disp16
= 1;
8506 i
.rm
.regmem
= NO_BASE_REGISTER
;
8507 i
.types
[op
].bitfield
.disp32
= 1;
8510 else if (!i
.tm
.opcode_modifier
.sib
)
8512 /* !i.base_reg && i.index_reg */
8513 if (i
.index_reg
->reg_num
== RegIZ
)
8514 i
.sib
.index
= NO_INDEX_REGISTER
;
8516 i
.sib
.index
= i
.index_reg
->reg_num
;
8517 i
.sib
.base
= NO_BASE_REGISTER
;
8518 i
.sib
.scale
= i
.log2_scale_factor
;
8519 i
.rm
.regmem
= ESCAPE_TO_TWO_BYTE_ADDRESSING
;
8520 i
.types
[op
] = operand_type_and_not (i
.types
[op
], anydisp
);
8521 i
.types
[op
].bitfield
.disp32
= 1;
8522 if ((i
.index_reg
->reg_flags
& RegRex
) != 0)
8526 /* RIP addressing for 64bit mode. */
8527 else if (i
.base_reg
->reg_num
== RegIP
)
8529 gas_assert (!i
.tm
.opcode_modifier
.sib
);
8530 i
.rm
.regmem
= NO_BASE_REGISTER
;
8531 i
.types
[op
].bitfield
.disp8
= 0;
8532 i
.types
[op
].bitfield
.disp16
= 0;
8533 i
.types
[op
].bitfield
.disp32
= 1;
8534 i
.types
[op
].bitfield
.disp64
= 0;
8535 i
.flags
[op
] |= Operand_PCrel
;
8536 if (! i
.disp_operands
)
8537 fake_zero_displacement
= 1;
8539 else if (i
.base_reg
->reg_type
.bitfield
.word
)
8541 gas_assert (!i
.tm
.opcode_modifier
.sib
);
8542 switch (i
.base_reg
->reg_num
)
8545 if (i
.index_reg
== 0)
8547 else /* (%bx,%si) -> 0, or (%bx,%di) -> 1 */
8548 i
.rm
.regmem
= i
.index_reg
->reg_num
- 6;
8551 default_seg
= reg_ss
;
8552 if (i
.index_reg
== 0)
8555 if (operand_type_check (i
.types
[op
], disp
) == 0)
8557 /* fake (%bp) into 0(%bp) */
8558 if (i
.disp_encoding
== disp_encoding_16bit
)
8559 i
.types
[op
].bitfield
.disp16
= 1;
8561 i
.types
[op
].bitfield
.disp8
= 1;
8562 fake_zero_displacement
= 1;
8565 else /* (%bp,%si) -> 2, or (%bp,%di) -> 3 */
8566 i
.rm
.regmem
= i
.index_reg
->reg_num
- 6 + 2;
8568 default: /* (%si) -> 4 or (%di) -> 5 */
8569 i
.rm
.regmem
= i
.base_reg
->reg_num
- 6 + 4;
8571 if (!fake_zero_displacement
8575 fake_zero_displacement
= 1;
8576 if (i
.disp_encoding
== disp_encoding_8bit
)
8577 i
.types
[op
].bitfield
.disp8
= 1;
8579 i
.types
[op
].bitfield
.disp16
= 1;
8581 i
.rm
.mode
= mode_from_disp_size (i
.types
[op
]);
8583 else /* i.base_reg and 32/64 bit mode */
8585 if (operand_type_check (i
.types
[op
], disp
))
8587 i
.types
[op
].bitfield
.disp16
= 0;
8588 i
.types
[op
].bitfield
.disp64
= 0;
8589 i
.types
[op
].bitfield
.disp32
= 1;
8592 if (!i
.tm
.opcode_modifier
.sib
)
8593 i
.rm
.regmem
= i
.base_reg
->reg_num
;
8594 if ((i
.base_reg
->reg_flags
& RegRex
) != 0)
8596 i
.sib
.base
= i
.base_reg
->reg_num
;
8597 /* x86-64 ignores REX prefix bit here to avoid decoder
8599 if (!(i
.base_reg
->reg_flags
& RegRex
)
8600 && (i
.base_reg
->reg_num
== EBP_REG_NUM
8601 || i
.base_reg
->reg_num
== ESP_REG_NUM
))
8602 default_seg
= reg_ss
;
8603 if (i
.base_reg
->reg_num
== 5 && i
.disp_operands
== 0)
8605 fake_zero_displacement
= 1;
8606 if (i
.disp_encoding
== disp_encoding_32bit
)
8607 i
.types
[op
].bitfield
.disp32
= 1;
8609 i
.types
[op
].bitfield
.disp8
= 1;
8611 i
.sib
.scale
= i
.log2_scale_factor
;
8612 if (i
.index_reg
== 0)
8614 /* Only check for VSIB. */
8615 gas_assert (i
.tm
.opcode_modifier
.sib
!= VECSIB128
8616 && i
.tm
.opcode_modifier
.sib
!= VECSIB256
8617 && i
.tm
.opcode_modifier
.sib
!= VECSIB512
);
8619 /* <disp>(%esp) becomes two byte modrm with no index
8620 register. We've already stored the code for esp
8621 in i.rm.regmem ie. ESCAPE_TO_TWO_BYTE_ADDRESSING.
8622 Any base register besides %esp will not use the
8623 extra modrm byte. */
8624 i
.sib
.index
= NO_INDEX_REGISTER
;
8626 else if (!i
.tm
.opcode_modifier
.sib
)
8628 if (i
.index_reg
->reg_num
== RegIZ
)
8629 i
.sib
.index
= NO_INDEX_REGISTER
;
8631 i
.sib
.index
= i
.index_reg
->reg_num
;
8632 i
.rm
.regmem
= ESCAPE_TO_TWO_BYTE_ADDRESSING
;
8633 if ((i
.index_reg
->reg_flags
& RegRex
) != 0)
8638 && (i
.reloc
[op
] == BFD_RELOC_386_TLS_DESC_CALL
8639 || i
.reloc
[op
] == BFD_RELOC_X86_64_TLSDESC_CALL
))
8643 if (!fake_zero_displacement
8647 fake_zero_displacement
= 1;
8648 if (i
.disp_encoding
== disp_encoding_8bit
)
8649 i
.types
[op
].bitfield
.disp8
= 1;
8651 i
.types
[op
].bitfield
.disp32
= 1;
8653 i
.rm
.mode
= mode_from_disp_size (i
.types
[op
]);
8657 if (fake_zero_displacement
)
8659 /* Fakes a zero displacement assuming that i.types[op]
8660 holds the correct displacement size. */
8663 gas_assert (i
.op
[op
].disps
== 0);
8664 exp
= &disp_expressions
[i
.disp_operands
++];
8665 i
.op
[op
].disps
= exp
;
8666 exp
->X_op
= O_constant
;
8667 exp
->X_add_number
= 0;
8668 exp
->X_add_symbol
= (symbolS
*) 0;
8669 exp
->X_op_symbol
= (symbolS
*) 0;
8675 i
.rm
.regmem
= i
.op
[op
].regs
->reg_num
;
8676 set_rex_vrex (i
.op
[op
].regs
, REX_B
, false);
8687 if (!i
.tm
.opcode_modifier
.regmem
)
8689 gas_assert (source
< MAX_OPERANDS
);
8690 i
.rm
.regmem
= i
.op
[source
].regs
->reg_num
;
8691 set_rex_vrex (i
.op
[source
].regs
, REX_B
,
8692 dest
>= MAX_OPERANDS
&& i
.tm
.opcode_modifier
.sse2avx
);
8697 gas_assert (dest
< MAX_OPERANDS
);
8698 i
.rm
.regmem
= i
.op
[dest
].regs
->reg_num
;
8699 set_rex_vrex (i
.op
[dest
].regs
, REX_B
, i
.tm
.opcode_modifier
.sse2avx
);
8704 /* Fill in i.rm.reg field with extension opcode (if any) or the
8705 appropriate register. */
8706 if (i
.tm
.extension_opcode
!= None
)
8707 i
.rm
.reg
= i
.tm
.extension_opcode
;
8708 else if (!i
.tm
.opcode_modifier
.regmem
&& dest
< MAX_OPERANDS
)
8710 i
.rm
.reg
= i
.op
[dest
].regs
->reg_num
;
8711 set_rex_vrex (i
.op
[dest
].regs
, REX_R
, i
.tm
.opcode_modifier
.sse2avx
);
8715 gas_assert (source
< MAX_OPERANDS
);
8716 i
.rm
.reg
= i
.op
[source
].regs
->reg_num
;
8717 set_rex_vrex (i
.op
[source
].regs
, REX_R
, false);
8720 if (flag_code
!= CODE_64BIT
&& (i
.rex
& REX_R
))
8722 gas_assert (i
.types
[!i
.tm
.opcode_modifier
.regmem
].bitfield
.class == RegCR
);
8724 add_prefix (LOCK_PREFIX_OPCODE
);
8731 frag_opcode_byte (unsigned char byte
)
8733 if (now_seg
!= absolute_section
)
8734 FRAG_APPEND_1_CHAR (byte
);
8736 ++abs_section_offset
;
8740 flip_code16 (unsigned int code16
)
8742 gas_assert (i
.tm
.operands
== 1);
8744 return !(i
.prefix
[REX_PREFIX
] & REX_W
)
8745 && (code16
? i
.tm
.operand_types
[0].bitfield
.disp32
8746 : i
.tm
.operand_types
[0].bitfield
.disp16
)
8751 output_branch (void)
8757 relax_substateT subtype
;
8761 if (now_seg
== absolute_section
)
8763 as_bad (_("relaxable branches not supported in absolute section"));
8767 code16
= flag_code
== CODE_16BIT
? CODE16
: 0;
8768 size
= i
.disp_encoding
> disp_encoding_8bit
? BIG
: SMALL
;
8771 if (i
.prefix
[DATA_PREFIX
] != 0)
8775 code16
^= flip_code16(code16
);
8777 /* Pentium4 branch hints. */
8778 if (i
.prefix
[SEG_PREFIX
] == CS_PREFIX_OPCODE
/* not taken */
8779 || i
.prefix
[SEG_PREFIX
] == DS_PREFIX_OPCODE
/* taken */)
8784 if (i
.prefix
[REX_PREFIX
] != 0)
8790 /* BND prefixed jump. */
8791 if (i
.prefix
[BND_PREFIX
] != 0)
8797 if (i
.prefixes
!= 0)
8798 as_warn (_("skipping prefixes on `%s'"), insn_name (&i
.tm
));
8800 /* It's always a symbol; End frag & setup for relax.
8801 Make sure there is enough room in this frag for the largest
8802 instruction we may generate in md_convert_frag. This is 2
8803 bytes for the opcode and room for the prefix and largest
8805 frag_grow (prefix
+ 2 + 4);
8806 /* Prefix and 1 opcode byte go in fr_fix. */
8807 p
= frag_more (prefix
+ 1);
8808 if (i
.prefix
[DATA_PREFIX
] != 0)
8809 *p
++ = DATA_PREFIX_OPCODE
;
8810 if (i
.prefix
[SEG_PREFIX
] == CS_PREFIX_OPCODE
8811 || i
.prefix
[SEG_PREFIX
] == DS_PREFIX_OPCODE
)
8812 *p
++ = i
.prefix
[SEG_PREFIX
];
8813 if (i
.prefix
[BND_PREFIX
] != 0)
8814 *p
++ = BND_PREFIX_OPCODE
;
8815 if (i
.prefix
[REX_PREFIX
] != 0)
8816 *p
++ = i
.prefix
[REX_PREFIX
];
8817 *p
= i
.tm
.base_opcode
;
8819 if ((unsigned char) *p
== JUMP_PC_RELATIVE
)
8820 subtype
= ENCODE_RELAX_STATE (UNCOND_JUMP
, size
);
8821 else if (cpu_arch_flags
.bitfield
.cpui386
)
8822 subtype
= ENCODE_RELAX_STATE (COND_JUMP
, size
);
8824 subtype
= ENCODE_RELAX_STATE (COND_JUMP86
, size
);
8827 sym
= i
.op
[0].disps
->X_add_symbol
;
8828 off
= i
.op
[0].disps
->X_add_number
;
8830 if (i
.op
[0].disps
->X_op
!= O_constant
8831 && i
.op
[0].disps
->X_op
!= O_symbol
)
8833 /* Handle complex expressions. */
8834 sym
= make_expr_symbol (i
.op
[0].disps
);
8838 frag_now
->tc_frag_data
.code64
= flag_code
== CODE_64BIT
;
8840 /* 1 possible extra opcode + 4 byte displacement go in var part.
8841 Pass reloc in fr_var. */
8842 frag_var (rs_machine_dependent
, 5, i
.reloc
[0], subtype
, sym
, off
, p
);
8845 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
8846 /* Return TRUE iff PLT32 relocation should be used for branching to
8850 need_plt32_p (symbolS
*s
)
8852 /* PLT32 relocation is ELF only. */
8857 /* Don't emit PLT32 relocation on Solaris: neither native linker nor
8858 krtld support it. */
8862 /* Since there is no need to prepare for PLT branch on x86-64, we
8863 can generate R_X86_64_PLT32, instead of R_X86_64_PC32, which can
8864 be used as a marker for 32-bit PC-relative branches. */
8871 /* Weak or undefined symbol need PLT32 relocation. */
8872 if (S_IS_WEAK (s
) || !S_IS_DEFINED (s
))
8875 /* Non-global symbol doesn't need PLT32 relocation. */
8876 if (! S_IS_EXTERNAL (s
))
8879 /* Other global symbols need PLT32 relocation. NB: Symbol with
8880 non-default visibilities are treated as normal global symbol
8881 so that PLT32 relocation can be used as a marker for 32-bit
8882 PC-relative branches. It is useful for linker relaxation. */
8893 bfd_reloc_code_real_type jump_reloc
= i
.reloc
[0];
8895 if (i
.tm
.opcode_modifier
.jump
== JUMP_BYTE
)
8897 /* This is a loop or jecxz type instruction. */
8899 if (i
.prefix
[ADDR_PREFIX
] != 0)
8901 frag_opcode_byte (ADDR_PREFIX_OPCODE
);
8904 /* Pentium4 branch hints. */
8905 if (i
.prefix
[SEG_PREFIX
] == CS_PREFIX_OPCODE
/* not taken */
8906 || i
.prefix
[SEG_PREFIX
] == DS_PREFIX_OPCODE
/* taken */)
8908 frag_opcode_byte (i
.prefix
[SEG_PREFIX
]);
8917 if (flag_code
== CODE_16BIT
)
8920 if (i
.prefix
[DATA_PREFIX
] != 0)
8922 frag_opcode_byte (DATA_PREFIX_OPCODE
);
8924 code16
^= flip_code16(code16
);
8932 /* BND prefixed jump. */
8933 if (i
.prefix
[BND_PREFIX
] != 0)
8935 frag_opcode_byte (i
.prefix
[BND_PREFIX
]);
8939 if (i
.prefix
[REX_PREFIX
] != 0)
8941 frag_opcode_byte (i
.prefix
[REX_PREFIX
]);
8945 if (i
.prefixes
!= 0)
8946 as_warn (_("skipping prefixes on `%s'"), insn_name (&i
.tm
));
8948 if (now_seg
== absolute_section
)
8950 abs_section_offset
+= i
.opcode_length
+ size
;
8954 p
= frag_more (i
.opcode_length
+ size
);
8955 switch (i
.opcode_length
)
8958 *p
++ = i
.tm
.base_opcode
>> 8;
8961 *p
++ = i
.tm
.base_opcode
;
8967 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
8968 if (flag_code
== CODE_64BIT
&& size
== 4
8969 && jump_reloc
== NO_RELOC
&& i
.op
[0].disps
->X_add_number
== 0
8970 && need_plt32_p (i
.op
[0].disps
->X_add_symbol
))
8971 jump_reloc
= BFD_RELOC_X86_64_PLT32
;
8974 jump_reloc
= reloc (size
, 1, 1, jump_reloc
);
8976 fixP
= fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, size
,
8977 i
.op
[0].disps
, 1, jump_reloc
);
8979 /* All jumps handled here are signed, but don't unconditionally use a
8980 signed limit check for 32 and 16 bit jumps as we want to allow wrap
8981 around at 4G (outside of 64-bit mode) and 64k (except for XBEGIN)
8986 fixP
->fx_signed
= 1;
8990 if (i
.tm
.mnem_off
== MN_xbegin
)
8991 fixP
->fx_signed
= 1;
8995 if (flag_code
== CODE_64BIT
)
8996 fixP
->fx_signed
= 1;
9002 output_interseg_jump (void)
9010 if (flag_code
== CODE_16BIT
)
9014 if (i
.prefix
[DATA_PREFIX
] != 0)
9021 gas_assert (!i
.prefix
[REX_PREFIX
]);
9027 if (i
.prefixes
!= 0)
9028 as_warn (_("skipping prefixes on `%s'"), insn_name (&i
.tm
));
9030 if (now_seg
== absolute_section
)
9032 abs_section_offset
+= prefix
+ 1 + 2 + size
;
9036 /* 1 opcode; 2 segment; offset */
9037 p
= frag_more (prefix
+ 1 + 2 + size
);
9039 if (i
.prefix
[DATA_PREFIX
] != 0)
9040 *p
++ = DATA_PREFIX_OPCODE
;
9042 if (i
.prefix
[REX_PREFIX
] != 0)
9043 *p
++ = i
.prefix
[REX_PREFIX
];
9045 *p
++ = i
.tm
.base_opcode
;
9046 if (i
.op
[1].imms
->X_op
== O_constant
)
9048 offsetT n
= i
.op
[1].imms
->X_add_number
;
9051 && !fits_in_unsigned_word (n
)
9052 && !fits_in_signed_word (n
))
9054 as_bad (_("16-bit jump out of range"));
9057 md_number_to_chars (p
, n
, size
);
9060 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, size
,
9061 i
.op
[1].imms
, 0, reloc (size
, 0, 0, i
.reloc
[1]));
9064 if (i
.op
[0].imms
->X_op
== O_constant
)
9065 md_number_to_chars (p
, (valueT
) i
.op
[0].imms
->X_add_number
, 2);
9067 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, 2,
9068 i
.op
[0].imms
, 0, reloc (2, 0, 0, i
.reloc
[0]));
9071 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
9076 asection
*seg
= now_seg
;
9077 subsegT subseg
= now_subseg
;
9079 unsigned int alignment
, align_size_1
;
9080 unsigned int isa_1_descsz
, feature_2_descsz
, descsz
;
9081 unsigned int isa_1_descsz_raw
, feature_2_descsz_raw
;
9082 unsigned int padding
;
9084 if (!IS_ELF
|| !x86_used_note
)
9087 x86_feature_2_used
|= GNU_PROPERTY_X86_FEATURE_2_X86
;
9089 /* The .note.gnu.property section layout:
9091 Field Length Contents
9094 n_descsz 4 The note descriptor size
9095 n_type 4 NT_GNU_PROPERTY_TYPE_0
9097 n_desc n_descsz The program property array
9101 /* Create the .note.gnu.property section. */
9102 sec
= subseg_new (NOTE_GNU_PROPERTY_SECTION_NAME
, 0);
9103 bfd_set_section_flags (sec
,
9110 if (get_elf_backend_data (stdoutput
)->s
->elfclass
== ELFCLASS64
)
9121 bfd_set_section_alignment (sec
, alignment
);
9122 elf_section_type (sec
) = SHT_NOTE
;
9124 /* GNU_PROPERTY_X86_ISA_1_USED: 4-byte type + 4-byte data size
9126 isa_1_descsz_raw
= 4 + 4 + 4;
9127 /* Align GNU_PROPERTY_X86_ISA_1_USED. */
9128 isa_1_descsz
= (isa_1_descsz_raw
+ align_size_1
) & ~align_size_1
;
9130 feature_2_descsz_raw
= isa_1_descsz
;
9131 /* GNU_PROPERTY_X86_FEATURE_2_USED: 4-byte type + 4-byte data size
9133 feature_2_descsz_raw
+= 4 + 4 + 4;
9134 /* Align GNU_PROPERTY_X86_FEATURE_2_USED. */
9135 feature_2_descsz
= ((feature_2_descsz_raw
+ align_size_1
)
9138 descsz
= feature_2_descsz
;
9139 /* Section size: n_namsz + n_descsz + n_type + n_name + n_descsz. */
9140 p
= frag_more (4 + 4 + 4 + 4 + descsz
);
9142 /* Write n_namsz. */
9143 md_number_to_chars (p
, (valueT
) 4, 4);
9145 /* Write n_descsz. */
9146 md_number_to_chars (p
+ 4, (valueT
) descsz
, 4);
9149 md_number_to_chars (p
+ 4 * 2, (valueT
) NT_GNU_PROPERTY_TYPE_0
, 4);
9152 memcpy (p
+ 4 * 3, "GNU", 4);
9154 /* Write 4-byte type. */
9155 md_number_to_chars (p
+ 4 * 4,
9156 (valueT
) GNU_PROPERTY_X86_ISA_1_USED
, 4);
9158 /* Write 4-byte data size. */
9159 md_number_to_chars (p
+ 4 * 5, (valueT
) 4, 4);
9161 /* Write 4-byte data. */
9162 md_number_to_chars (p
+ 4 * 6, (valueT
) x86_isa_1_used
, 4);
9164 /* Zero out paddings. */
9165 padding
= isa_1_descsz
- isa_1_descsz_raw
;
9167 memset (p
+ 4 * 7, 0, padding
);
9169 /* Write 4-byte type. */
9170 md_number_to_chars (p
+ isa_1_descsz
+ 4 * 4,
9171 (valueT
) GNU_PROPERTY_X86_FEATURE_2_USED
, 4);
9173 /* Write 4-byte data size. */
9174 md_number_to_chars (p
+ isa_1_descsz
+ 4 * 5, (valueT
) 4, 4);
9176 /* Write 4-byte data. */
9177 md_number_to_chars (p
+ isa_1_descsz
+ 4 * 6,
9178 (valueT
) x86_feature_2_used
, 4);
9180 /* Zero out paddings. */
9181 padding
= feature_2_descsz
- feature_2_descsz_raw
;
9183 memset (p
+ isa_1_descsz
+ 4 * 7, 0, padding
);
9185 /* We probably can't restore the current segment, for there likely
9188 subseg_set (seg
, subseg
);
9192 x86_support_sframe_p (void)
9194 /* At this time, SFrame stack trace is supported for AMD64 ABI only. */
9195 return (x86_elf_abi
== X86_64_ABI
);
9199 x86_sframe_ra_tracking_p (void)
9201 /* In AMD64, return address is always stored on the stack at a fixed offset
9202 from the CFA (provided via x86_sframe_cfa_ra_offset ()).
9203 Do not track explicitly via an SFrame Frame Row Entry. */
9208 x86_sframe_cfa_ra_offset (void)
9210 gas_assert (x86_elf_abi
== X86_64_ABI
);
9211 return (offsetT
) -8;
9215 x86_sframe_get_abi_arch (void)
9217 unsigned char sframe_abi_arch
= 0;
9219 if (x86_support_sframe_p ())
9221 gas_assert (!target_big_endian
);
9222 sframe_abi_arch
= SFRAME_ABI_AMD64_ENDIAN_LITTLE
;
9225 return sframe_abi_arch
;
9231 encoding_length (const fragS
*start_frag
, offsetT start_off
,
9232 const char *frag_now_ptr
)
9234 unsigned int len
= 0;
9236 if (start_frag
!= frag_now
)
9238 const fragS
*fr
= start_frag
;
9243 } while (fr
&& fr
!= frag_now
);
9246 return len
- start_off
+ (frag_now_ptr
- frag_now
->fr_literal
);
9249 /* Return 1 for test, and, cmp, add, sub, inc and dec which may
9250 be macro-fused with conditional jumps.
9251 NB: If TEST/AND/CMP/ADD/SUB/INC/DEC is of RIP relative address,
9252 or is one of the following format:
9265 maybe_fused_with_jcc_p (enum mf_cmp_kind
* mf_cmp_p
)
9267 /* No RIP address. */
9268 if (i
.base_reg
&& i
.base_reg
->reg_num
== RegIP
)
9271 /* No opcodes outside of base encoding space. */
9272 if (i
.tm
.opcode_space
!= SPACE_BASE
)
9275 /* add, sub without add/sub m, imm. */
9276 if (i
.tm
.base_opcode
<= 5
9277 || (i
.tm
.base_opcode
>= 0x28 && i
.tm
.base_opcode
<= 0x2d)
9278 || ((i
.tm
.base_opcode
| 3) == 0x83
9279 && (i
.tm
.extension_opcode
== 0x5
9280 || i
.tm
.extension_opcode
== 0x0)))
9282 *mf_cmp_p
= mf_cmp_alu_cmp
;
9283 return !(i
.mem_operands
&& i
.imm_operands
);
9286 /* and without and m, imm. */
9287 if ((i
.tm
.base_opcode
>= 0x20 && i
.tm
.base_opcode
<= 0x25)
9288 || ((i
.tm
.base_opcode
| 3) == 0x83
9289 && i
.tm
.extension_opcode
== 0x4))
9291 *mf_cmp_p
= mf_cmp_test_and
;
9292 return !(i
.mem_operands
&& i
.imm_operands
);
9295 /* test without test m imm. */
9296 if ((i
.tm
.base_opcode
| 1) == 0x85
9297 || (i
.tm
.base_opcode
| 1) == 0xa9
9298 || ((i
.tm
.base_opcode
| 1) == 0xf7
9299 && i
.tm
.extension_opcode
== 0))
9301 *mf_cmp_p
= mf_cmp_test_and
;
9302 return !(i
.mem_operands
&& i
.imm_operands
);
9305 /* cmp without cmp m, imm. */
9306 if ((i
.tm
.base_opcode
>= 0x38 && i
.tm
.base_opcode
<= 0x3d)
9307 || ((i
.tm
.base_opcode
| 3) == 0x83
9308 && (i
.tm
.extension_opcode
== 0x7)))
9310 *mf_cmp_p
= mf_cmp_alu_cmp
;
9311 return !(i
.mem_operands
&& i
.imm_operands
);
9314 /* inc, dec without inc/dec m. */
9315 if ((i
.tm
.cpu_flags
.bitfield
.cpuno64
9316 && (i
.tm
.base_opcode
| 0xf) == 0x4f)
9317 || ((i
.tm
.base_opcode
| 1) == 0xff
9318 && i
.tm
.extension_opcode
<= 0x1))
9320 *mf_cmp_p
= mf_cmp_incdec
;
9321 return !i
.mem_operands
;
9327 /* Return 1 if a FUSED_JCC_PADDING frag should be generated. */
9330 add_fused_jcc_padding_frag_p (enum mf_cmp_kind
* mf_cmp_p
)
9332 /* NB: Don't work with COND_JUMP86 without i386. */
9333 if (!align_branch_power
9334 || now_seg
== absolute_section
9335 || !cpu_arch_flags
.bitfield
.cpui386
9336 || !(align_branch
& align_branch_fused_bit
))
9339 if (maybe_fused_with_jcc_p (mf_cmp_p
))
9341 if (last_insn
.kind
== last_insn_other
9342 || last_insn
.seg
!= now_seg
)
9345 as_warn_where (last_insn
.file
, last_insn
.line
,
9346 _("`%s` skips -malign-branch-boundary on `%s`"),
9347 last_insn
.name
, insn_name (&i
.tm
));
9353 /* Return 1 if a BRANCH_PREFIX frag should be generated. */
9356 add_branch_prefix_frag_p (void)
9358 /* NB: Don't work with COND_JUMP86 without i386. Don't add prefix
9359 to PadLock instructions since they include prefixes in opcode. */
9360 if (!align_branch_power
9361 || !align_branch_prefix_size
9362 || now_seg
== absolute_section
9363 || i
.tm
.cpu_flags
.bitfield
.cpupadlock
9364 || !cpu_arch_flags
.bitfield
.cpui386
)
9367 /* Don't add prefix if it is a prefix or there is no operand in case
9368 that segment prefix is special. */
9369 if (!i
.operands
|| i
.tm
.opcode_modifier
.isprefix
)
9372 if (last_insn
.kind
== last_insn_other
9373 || last_insn
.seg
!= now_seg
)
9377 as_warn_where (last_insn
.file
, last_insn
.line
,
9378 _("`%s` skips -malign-branch-boundary on `%s`"),
9379 last_insn
.name
, insn_name (&i
.tm
));
9384 /* Return 1 if a BRANCH_PADDING frag should be generated. */
9387 add_branch_padding_frag_p (enum align_branch_kind
*branch_p
,
9388 enum mf_jcc_kind
*mf_jcc_p
)
9392 /* NB: Don't work with COND_JUMP86 without i386. */
9393 if (!align_branch_power
9394 || now_seg
== absolute_section
9395 || !cpu_arch_flags
.bitfield
.cpui386
9396 || i
.tm
.opcode_space
!= SPACE_BASE
)
9401 /* Check for jcc and direct jmp. */
9402 if (i
.tm
.opcode_modifier
.jump
== JUMP
)
9404 if (i
.tm
.base_opcode
== JUMP_PC_RELATIVE
)
9406 *branch_p
= align_branch_jmp
;
9407 add_padding
= align_branch
& align_branch_jmp_bit
;
9411 /* Because J<cc> and JN<cc> share same group in macro-fusible table,
9412 igore the lowest bit. */
9413 *mf_jcc_p
= (i
.tm
.base_opcode
& 0x0e) >> 1;
9414 *branch_p
= align_branch_jcc
;
9415 if ((align_branch
& align_branch_jcc_bit
))
9419 else if ((i
.tm
.base_opcode
| 1) == 0xc3)
9422 *branch_p
= align_branch_ret
;
9423 if ((align_branch
& align_branch_ret_bit
))
9428 /* Check for indirect jmp, direct and indirect calls. */
9429 if (i
.tm
.base_opcode
== 0xe8)
9432 *branch_p
= align_branch_call
;
9433 if ((align_branch
& align_branch_call_bit
))
9436 else if (i
.tm
.base_opcode
== 0xff
9437 && (i
.tm
.extension_opcode
== 2
9438 || i
.tm
.extension_opcode
== 4))
9440 /* Indirect call and jmp. */
9441 *branch_p
= align_branch_indirect
;
9442 if ((align_branch
& align_branch_indirect_bit
))
9449 && (i
.op
[0].disps
->X_op
== O_symbol
9450 || (i
.op
[0].disps
->X_op
== O_subtract
9451 && i
.op
[0].disps
->X_op_symbol
== GOT_symbol
)))
9453 symbolS
*s
= i
.op
[0].disps
->X_add_symbol
;
9454 /* No padding to call to global or undefined tls_get_addr. */
9455 if ((S_IS_EXTERNAL (s
) || !S_IS_DEFINED (s
))
9456 && strcmp (S_GET_NAME (s
), tls_get_addr
) == 0)
9462 && last_insn
.kind
!= last_insn_other
9463 && last_insn
.seg
== now_seg
)
9466 as_warn_where (last_insn
.file
, last_insn
.line
,
9467 _("`%s` skips -malign-branch-boundary on `%s`"),
9468 last_insn
.name
, insn_name (&i
.tm
));
9478 fragS
*insn_start_frag
;
9479 offsetT insn_start_off
;
9480 fragS
*fragP
= NULL
;
9481 enum align_branch_kind branch
= align_branch_none
;
9482 /* The initializer is arbitrary just to avoid uninitialized error.
9483 it's actually either assigned in add_branch_padding_frag_p
9484 or never be used. */
9485 enum mf_jcc_kind mf_jcc
= mf_jcc_jo
;
9487 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
9488 if (IS_ELF
&& x86_used_note
&& now_seg
!= absolute_section
)
9490 if ((i
.xstate
& xstate_tmm
) == xstate_tmm
9491 || i
.tm
.cpu_flags
.bitfield
.cpuamx_tile
)
9492 x86_feature_2_used
|= GNU_PROPERTY_X86_FEATURE_2_TMM
;
9494 if (i
.tm
.cpu_flags
.bitfield
.cpu8087
9495 || i
.tm
.cpu_flags
.bitfield
.cpu287
9496 || i
.tm
.cpu_flags
.bitfield
.cpu387
9497 || i
.tm
.cpu_flags
.bitfield
.cpu687
9498 || i
.tm
.cpu_flags
.bitfield
.cpufisttp
)
9499 x86_feature_2_used
|= GNU_PROPERTY_X86_FEATURE_2_X87
;
9501 if ((i
.xstate
& xstate_mmx
)
9502 || i
.tm
.mnem_off
== MN_emms
9503 || i
.tm
.mnem_off
== MN_femms
)
9504 x86_feature_2_used
|= GNU_PROPERTY_X86_FEATURE_2_MMX
;
9508 if (i
.index_reg
->reg_type
.bitfield
.zmmword
)
9509 i
.xstate
|= xstate_zmm
;
9510 else if (i
.index_reg
->reg_type
.bitfield
.ymmword
)
9511 i
.xstate
|= xstate_ymm
;
9512 else if (i
.index_reg
->reg_type
.bitfield
.xmmword
)
9513 i
.xstate
|= xstate_xmm
;
9516 /* vzeroall / vzeroupper */
9517 if (i
.tm
.base_opcode
== 0x77 && i
.tm
.cpu_flags
.bitfield
.cpuavx
)
9518 i
.xstate
|= xstate_ymm
;
9520 if ((i
.xstate
& xstate_xmm
)
9521 /* ldmxcsr / stmxcsr / vldmxcsr / vstmxcsr */
9522 || (i
.tm
.base_opcode
== 0xae
9523 && (i
.tm
.cpu_flags
.bitfield
.cpusse
9524 || i
.tm
.cpu_flags
.bitfield
.cpuavx
))
9525 || i
.tm
.cpu_flags
.bitfield
.cpuwidekl
9526 || i
.tm
.cpu_flags
.bitfield
.cpukl
)
9527 x86_feature_2_used
|= GNU_PROPERTY_X86_FEATURE_2_XMM
;
9529 if ((i
.xstate
& xstate_ymm
) == xstate_ymm
)
9530 x86_feature_2_used
|= GNU_PROPERTY_X86_FEATURE_2_YMM
;
9531 if ((i
.xstate
& xstate_zmm
) == xstate_zmm
)
9532 x86_feature_2_used
|= GNU_PROPERTY_X86_FEATURE_2_ZMM
;
9533 if (i
.mask
.reg
|| (i
.xstate
& xstate_mask
) == xstate_mask
)
9534 x86_feature_2_used
|= GNU_PROPERTY_X86_FEATURE_2_MASK
;
9535 if (i
.tm
.cpu_flags
.bitfield
.cpufxsr
)
9536 x86_feature_2_used
|= GNU_PROPERTY_X86_FEATURE_2_FXSR
;
9537 if (i
.tm
.cpu_flags
.bitfield
.cpuxsave
)
9538 x86_feature_2_used
|= GNU_PROPERTY_X86_FEATURE_2_XSAVE
;
9539 if (i
.tm
.cpu_flags
.bitfield
.cpuxsaveopt
)
9540 x86_feature_2_used
|= GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
;
9541 if (i
.tm
.cpu_flags
.bitfield
.cpuxsavec
)
9542 x86_feature_2_used
|= GNU_PROPERTY_X86_FEATURE_2_XSAVEC
;
9544 if (x86_feature_2_used
9545 || i
.tm
.cpu_flags
.bitfield
.cpucmov
9546 || i
.tm
.cpu_flags
.bitfield
.cpusyscall
9547 || i
.tm
.mnem_off
== MN_cmpxchg8b
)
9548 x86_isa_1_used
|= GNU_PROPERTY_X86_ISA_1_BASELINE
;
9549 if (i
.tm
.cpu_flags
.bitfield
.cpusse3
9550 || i
.tm
.cpu_flags
.bitfield
.cpussse3
9551 || i
.tm
.cpu_flags
.bitfield
.cpusse4_1
9552 || i
.tm
.cpu_flags
.bitfield
.cpusse4_2
9553 || i
.tm
.cpu_flags
.bitfield
.cpucx16
9554 || i
.tm
.cpu_flags
.bitfield
.cpupopcnt
9555 /* LAHF-SAHF insns in 64-bit mode. */
9556 || (flag_code
== CODE_64BIT
9557 && (i
.tm
.base_opcode
| 1) == 0x9f
9558 && i
.tm
.opcode_space
== SPACE_BASE
))
9559 x86_isa_1_used
|= GNU_PROPERTY_X86_ISA_1_V2
;
9560 if (i
.tm
.cpu_flags
.bitfield
.cpuavx
9561 || i
.tm
.cpu_flags
.bitfield
.cpuavx2
9562 /* Any VEX encoded insns execpt for AVX512F, AVX512BW, AVX512DQ,
9563 XOP, FMA4, LPW, TBM, and AMX. */
9564 || (i
.tm
.opcode_modifier
.vex
9565 && !i
.tm
.cpu_flags
.bitfield
.cpuavx512f
9566 && !i
.tm
.cpu_flags
.bitfield
.cpuavx512bw
9567 && !i
.tm
.cpu_flags
.bitfield
.cpuavx512dq
9568 && !i
.tm
.cpu_flags
.bitfield
.cpuxop
9569 && !i
.tm
.cpu_flags
.bitfield
.cpufma4
9570 && !i
.tm
.cpu_flags
.bitfield
.cpulwp
9571 && !i
.tm
.cpu_flags
.bitfield
.cputbm
9572 && !(x86_feature_2_used
& GNU_PROPERTY_X86_FEATURE_2_TMM
))
9573 || i
.tm
.cpu_flags
.bitfield
.cpuf16c
9574 || i
.tm
.cpu_flags
.bitfield
.cpufma
9575 || i
.tm
.cpu_flags
.bitfield
.cpulzcnt
9576 || i
.tm
.cpu_flags
.bitfield
.cpumovbe
9577 || i
.tm
.cpu_flags
.bitfield
.cpuxsaves
9578 || (x86_feature_2_used
9579 & (GNU_PROPERTY_X86_FEATURE_2_XSAVE
9580 | GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT
9581 | GNU_PROPERTY_X86_FEATURE_2_XSAVEC
)) != 0)
9582 x86_isa_1_used
|= GNU_PROPERTY_X86_ISA_1_V3
;
9583 if (i
.tm
.cpu_flags
.bitfield
.cpuavx512f
9584 || i
.tm
.cpu_flags
.bitfield
.cpuavx512bw
9585 || i
.tm
.cpu_flags
.bitfield
.cpuavx512dq
9586 || i
.tm
.cpu_flags
.bitfield
.cpuavx512vl
9587 /* Any EVEX encoded insns except for AVX512ER, AVX512PF,
9588 AVX512-4FMAPS, and AVX512-4VNNIW. */
9589 || (i
.tm
.opcode_modifier
.evex
9590 && !i
.tm
.cpu_flags
.bitfield
.cpuavx512er
9591 && !i
.tm
.cpu_flags
.bitfield
.cpuavx512pf
9592 && !i
.tm
.cpu_flags
.bitfield
.cpuavx512_4fmaps
9593 && !i
.tm
.cpu_flags
.bitfield
.cpuavx512_4vnniw
))
9594 x86_isa_1_used
|= GNU_PROPERTY_X86_ISA_1_V4
;
9598 /* Tie dwarf2 debug info to the address at the start of the insn.
9599 We can't do this after the insn has been output as the current
9600 frag may have been closed off. eg. by frag_var. */
9601 dwarf2_emit_insn (0);
9603 insn_start_frag
= frag_now
;
9604 insn_start_off
= frag_now_fix ();
9606 if (add_branch_padding_frag_p (&branch
, &mf_jcc
))
9609 /* Branch can be 8 bytes. Leave some room for prefixes. */
9610 unsigned int max_branch_padding_size
= 14;
9612 /* Align section to boundary. */
9613 record_alignment (now_seg
, align_branch_power
);
9615 /* Make room for padding. */
9616 frag_grow (max_branch_padding_size
);
9618 /* Start of the padding. */
9623 frag_var (rs_machine_dependent
, max_branch_padding_size
, 0,
9624 ENCODE_RELAX_STATE (BRANCH_PADDING
, 0),
9627 fragP
->tc_frag_data
.mf_type
= mf_jcc
;
9628 fragP
->tc_frag_data
.branch_type
= branch
;
9629 fragP
->tc_frag_data
.max_bytes
= max_branch_padding_size
;
9632 if (!cpu_arch_flags
.bitfield
.cpui386
&& (flag_code
!= CODE_16BIT
)
9633 && !pre_386_16bit_warned
)
9635 as_warn (_("use .code16 to ensure correct addressing mode"));
9636 pre_386_16bit_warned
= true;
9640 if (i
.tm
.opcode_modifier
.jump
== JUMP
)
9642 else if (i
.tm
.opcode_modifier
.jump
== JUMP_BYTE
9643 || i
.tm
.opcode_modifier
.jump
== JUMP_DWORD
)
9645 else if (i
.tm
.opcode_modifier
.jump
== JUMP_INTERSEGMENT
)
9646 output_interseg_jump ();
9649 /* Output normal instructions here. */
9653 enum mf_cmp_kind mf_cmp
;
9656 && (i
.tm
.base_opcode
== 0xaee8
9657 || i
.tm
.base_opcode
== 0xaef0
9658 || i
.tm
.base_opcode
== 0xaef8))
9660 /* Encode lfence, mfence, and sfence as
9661 f0 83 04 24 00 lock addl $0x0, (%{re}sp). */
9662 if (flag_code
== CODE_16BIT
)
9663 as_bad (_("Cannot convert `%s' in 16-bit mode"), insn_name (&i
.tm
));
9664 else if (omit_lock_prefix
)
9665 as_bad (_("Cannot convert `%s' with `-momit-lock-prefix=yes' in effect"),
9667 else if (now_seg
!= absolute_section
)
9669 offsetT val
= 0x240483f0ULL
;
9672 md_number_to_chars (p
, val
, 5);
9675 abs_section_offset
+= 5;
9679 /* Some processors fail on LOCK prefix. This options makes
9680 assembler ignore LOCK prefix and serves as a workaround. */
9681 if (omit_lock_prefix
)
9683 if (i
.tm
.base_opcode
== LOCK_PREFIX_OPCODE
9684 && i
.tm
.opcode_modifier
.isprefix
)
9686 i
.prefix
[LOCK_PREFIX
] = 0;
9690 /* Skip if this is a branch. */
9692 else if (add_fused_jcc_padding_frag_p (&mf_cmp
))
9694 /* Make room for padding. */
9695 frag_grow (MAX_FUSED_JCC_PADDING_SIZE
);
9700 frag_var (rs_machine_dependent
, MAX_FUSED_JCC_PADDING_SIZE
, 0,
9701 ENCODE_RELAX_STATE (FUSED_JCC_PADDING
, 0),
9704 fragP
->tc_frag_data
.mf_type
= mf_cmp
;
9705 fragP
->tc_frag_data
.branch_type
= align_branch_fused
;
9706 fragP
->tc_frag_data
.max_bytes
= MAX_FUSED_JCC_PADDING_SIZE
;
9708 else if (add_branch_prefix_frag_p ())
9710 unsigned int max_prefix_size
= align_branch_prefix_size
;
9712 /* Make room for padding. */
9713 frag_grow (max_prefix_size
);
9718 frag_var (rs_machine_dependent
, max_prefix_size
, 0,
9719 ENCODE_RELAX_STATE (BRANCH_PREFIX
, 0),
9722 fragP
->tc_frag_data
.max_bytes
= max_prefix_size
;
9725 /* Since the VEX/EVEX prefix contains the implicit prefix, we
9726 don't need the explicit prefix. */
9727 if (!is_any_vex_encoding (&i
.tm
))
9729 switch (i
.tm
.opcode_modifier
.opcodeprefix
)
9738 if (!i
.tm
.cpu_flags
.bitfield
.cpupadlock
9739 || (i
.prefix
[REP_PREFIX
] != 0xf3))
9743 switch (i
.opcode_length
)
9748 /* Check for pseudo prefixes. */
9749 if (!i
.tm
.opcode_modifier
.isprefix
|| i
.tm
.base_opcode
)
9751 as_bad_where (insn_start_frag
->fr_file
,
9752 insn_start_frag
->fr_line
,
9753 _("pseudo prefix without instruction"));
9763 #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF)
9764 /* For x32, add a dummy REX_OPCODE prefix for mov/add with
9765 R_X86_64_GOTTPOFF relocation so that linker can safely
9766 perform IE->LE optimization. A dummy REX_OPCODE prefix
9767 is also needed for lea with R_X86_64_GOTPC32_TLSDESC
9768 relocation for GDesc -> IE/LE optimization. */
9769 if (x86_elf_abi
== X86_64_X32_ABI
9771 && (i
.reloc
[0] == BFD_RELOC_X86_64_GOTTPOFF
9772 || i
.reloc
[0] == BFD_RELOC_X86_64_GOTPC32_TLSDESC
)
9773 && i
.prefix
[REX_PREFIX
] == 0)
9774 add_prefix (REX_OPCODE
);
9777 /* The prefix bytes. */
9778 for (j
= ARRAY_SIZE (i
.prefix
), q
= i
.prefix
; j
> 0; j
--, q
++)
9780 frag_opcode_byte (*q
);
9784 for (j
= 0, q
= i
.prefix
; j
< ARRAY_SIZE (i
.prefix
); j
++, q
++)
9790 frag_opcode_byte (*q
);
9793 /* There should be no other prefixes for instructions
9798 /* For EVEX instructions i.vrex should become 0 after
9799 build_evex_prefix. For VEX instructions upper 16 registers
9800 aren't available, so VREX should be 0. */
9803 /* Now the VEX prefix. */
9804 if (now_seg
!= absolute_section
)
9806 p
= frag_more (i
.vex
.length
);
9807 for (j
= 0; j
< i
.vex
.length
; j
++)
9808 p
[j
] = i
.vex
.bytes
[j
];
9811 abs_section_offset
+= i
.vex
.length
;
9814 /* Now the opcode; be careful about word order here! */
9815 j
= i
.opcode_length
;
9817 switch (i
.tm
.opcode_space
)
9832 if (now_seg
== absolute_section
)
9833 abs_section_offset
+= j
;
9836 FRAG_APPEND_1_CHAR (i
.tm
.base_opcode
);
9842 && i
.tm
.opcode_space
!= SPACE_BASE
)
9845 if (i
.tm
.opcode_space
!= SPACE_0F
)
9846 *p
++ = i
.tm
.opcode_space
== SPACE_0F38
9850 switch (i
.opcode_length
)
9853 /* Put out high byte first: can't use md_number_to_chars! */
9854 *p
++ = (i
.tm
.base_opcode
>> 8) & 0xff;
9857 *p
= i
.tm
.base_opcode
& 0xff;
9866 /* Now the modrm byte and sib byte (if present). */
9867 if (i
.tm
.opcode_modifier
.modrm
)
9869 frag_opcode_byte ((i
.rm
.regmem
<< 0)
9871 | (i
.rm
.mode
<< 6));
9872 /* If i.rm.regmem == ESP (4)
9873 && i.rm.mode != (Register mode)
9875 ==> need second modrm byte. */
9876 if (i
.rm
.regmem
== ESCAPE_TO_TWO_BYTE_ADDRESSING
9878 && !(i
.base_reg
&& i
.base_reg
->reg_type
.bitfield
.word
))
9879 frag_opcode_byte ((i
.sib
.base
<< 0)
9880 | (i
.sib
.index
<< 3)
9881 | (i
.sib
.scale
<< 6));
9884 if (i
.disp_operands
)
9885 output_disp (insn_start_frag
, insn_start_off
);
9888 output_imm (insn_start_frag
, insn_start_off
);
9891 * frag_now_fix () returning plain abs_section_offset when we're in the
9892 * absolute section, and abs_section_offset not getting updated as data
9893 * gets added to the frag breaks the logic below.
9895 if (now_seg
!= absolute_section
)
9897 j
= encoding_length (insn_start_frag
, insn_start_off
, frag_more (0));
9899 as_warn (_("instruction length of %u bytes exceeds the limit of 15"),
9903 /* NB: Don't add prefix with GOTPC relocation since
9904 output_disp() above depends on the fixed encoding
9905 length. Can't add prefix with TLS relocation since
9906 it breaks TLS linker optimization. */
9907 unsigned int max
= i
.has_gotpc_tls_reloc
? 0 : 15 - j
;
9908 /* Prefix count on the current instruction. */
9909 unsigned int count
= i
.vex
.length
;
9911 for (k
= 0; k
< ARRAY_SIZE (i
.prefix
); k
++)
9912 /* REX byte is encoded in VEX/EVEX prefix. */
9913 if (i
.prefix
[k
] && (k
!= REX_PREFIX
|| !i
.vex
.length
))
9916 /* Count prefixes for extended opcode maps. */
9918 switch (i
.tm
.opcode_space
)
9933 if (TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
)
9936 /* Set the maximum prefix size in BRANCH_PREFIX
9938 if (fragP
->tc_frag_data
.max_bytes
> max
)
9939 fragP
->tc_frag_data
.max_bytes
= max
;
9940 if (fragP
->tc_frag_data
.max_bytes
> count
)
9941 fragP
->tc_frag_data
.max_bytes
-= count
;
9943 fragP
->tc_frag_data
.max_bytes
= 0;
9947 /* Remember the maximum prefix size in FUSED_JCC_PADDING
9949 unsigned int max_prefix_size
;
9950 if (align_branch_prefix_size
> max
)
9951 max_prefix_size
= max
;
9953 max_prefix_size
= align_branch_prefix_size
;
9954 if (max_prefix_size
> count
)
9955 fragP
->tc_frag_data
.max_prefix_length
9956 = max_prefix_size
- count
;
9959 /* Use existing segment prefix if possible. Use CS
9960 segment prefix in 64-bit mode. In 32-bit mode, use SS
9961 segment prefix with ESP/EBP base register and use DS
9962 segment prefix without ESP/EBP base register. */
9963 if (i
.prefix
[SEG_PREFIX
])
9964 fragP
->tc_frag_data
.default_prefix
= i
.prefix
[SEG_PREFIX
];
9965 else if (flag_code
== CODE_64BIT
)
9966 fragP
->tc_frag_data
.default_prefix
= CS_PREFIX_OPCODE
;
9968 && (i
.base_reg
->reg_num
== 4
9969 || i
.base_reg
->reg_num
== 5))
9970 fragP
->tc_frag_data
.default_prefix
= SS_PREFIX_OPCODE
;
9972 fragP
->tc_frag_data
.default_prefix
= DS_PREFIX_OPCODE
;
9977 /* NB: Don't work with COND_JUMP86 without i386. */
9978 if (align_branch_power
9979 && now_seg
!= absolute_section
9980 && cpu_arch_flags
.bitfield
.cpui386
)
9982 /* Terminate each frag so that we can add prefix and check for
9984 frag_wane (frag_now
);
9991 pi ("" /*line*/, &i
);
9993 #endif /* DEBUG386 */
9996 /* Return the size of the displacement operand N. */
9999 disp_size (unsigned int n
)
10003 if (i
.types
[n
].bitfield
.disp64
)
10005 else if (i
.types
[n
].bitfield
.disp8
)
10007 else if (i
.types
[n
].bitfield
.disp16
)
10012 /* Return the size of the immediate operand N. */
10015 imm_size (unsigned int n
)
10018 if (i
.types
[n
].bitfield
.imm64
)
10020 else if (i
.types
[n
].bitfield
.imm8
|| i
.types
[n
].bitfield
.imm8s
)
10022 else if (i
.types
[n
].bitfield
.imm16
)
10028 output_disp (fragS
*insn_start_frag
, offsetT insn_start_off
)
10033 for (n
= 0; n
< i
.operands
; n
++)
10035 if (operand_type_check (i
.types
[n
], disp
))
10037 int size
= disp_size (n
);
10039 if (now_seg
== absolute_section
)
10040 abs_section_offset
+= size
;
10041 else if (i
.op
[n
].disps
->X_op
== O_constant
)
10043 offsetT val
= i
.op
[n
].disps
->X_add_number
;
10045 val
= offset_in_range (val
>> (size
== 1 ? i
.memshift
: 0),
10047 p
= frag_more (size
);
10048 md_number_to_chars (p
, val
, size
);
10052 enum bfd_reloc_code_real reloc_type
;
10053 bool pcrel
= (i
.flags
[n
] & Operand_PCrel
) != 0;
10054 bool sign
= (flag_code
== CODE_64BIT
&& size
== 4
10055 && (!want_disp32 (&i
.tm
)
10056 || (i
.tm
.opcode_modifier
.jump
&& !i
.jumpabsolute
10057 && !i
.types
[n
].bitfield
.baseindex
)))
10061 /* We can't have 8 bit displacement here. */
10062 gas_assert (!i
.types
[n
].bitfield
.disp8
);
10064 /* The PC relative address is computed relative
10065 to the instruction boundary, so in case immediate
10066 fields follows, we need to adjust the value. */
10067 if (pcrel
&& i
.imm_operands
)
10072 for (n1
= 0; n1
< i
.operands
; n1
++)
10073 if (operand_type_check (i
.types
[n1
], imm
))
10075 /* Only one immediate is allowed for PC
10076 relative address, except with .insn. */
10077 gas_assert (sz
== 0 || dot_insn ());
10078 sz
+= imm_size (n1
);
10080 /* We should find at least one immediate. */
10081 gas_assert (sz
!= 0);
10082 i
.op
[n
].disps
->X_add_number
-= sz
;
10085 p
= frag_more (size
);
10086 reloc_type
= reloc (size
, pcrel
, sign
, i
.reloc
[n
]);
10088 && GOT_symbol
== i
.op
[n
].disps
->X_add_symbol
10089 && (((reloc_type
== BFD_RELOC_32
10090 || reloc_type
== BFD_RELOC_X86_64_32S
10091 || (reloc_type
== BFD_RELOC_64
10093 && (i
.op
[n
].disps
->X_op
== O_symbol
10094 || (i
.op
[n
].disps
->X_op
== O_add
10095 && ((symbol_get_value_expression
10096 (i
.op
[n
].disps
->X_op_symbol
)->X_op
)
10098 || reloc_type
== BFD_RELOC_32_PCREL
))
10102 reloc_type
= BFD_RELOC_386_GOTPC
;
10103 i
.has_gotpc_tls_reloc
= true;
10104 i
.op
[n
].disps
->X_add_number
+=
10105 encoding_length (insn_start_frag
, insn_start_off
, p
);
10107 else if (reloc_type
== BFD_RELOC_64
)
10108 reloc_type
= BFD_RELOC_X86_64_GOTPC64
;
10110 /* Don't do the adjustment for x86-64, as there
10111 the pcrel addressing is relative to the _next_
10112 insn, and that is taken care of in other code. */
10113 reloc_type
= BFD_RELOC_X86_64_GOTPC32
;
10115 else if (align_branch_power
)
10117 switch (reloc_type
)
10119 case BFD_RELOC_386_TLS_GD
:
10120 case BFD_RELOC_386_TLS_LDM
:
10121 case BFD_RELOC_386_TLS_IE
:
10122 case BFD_RELOC_386_TLS_IE_32
:
10123 case BFD_RELOC_386_TLS_GOTIE
:
10124 case BFD_RELOC_386_TLS_GOTDESC
:
10125 case BFD_RELOC_386_TLS_DESC_CALL
:
10126 case BFD_RELOC_X86_64_TLSGD
:
10127 case BFD_RELOC_X86_64_TLSLD
:
10128 case BFD_RELOC_X86_64_GOTTPOFF
:
10129 case BFD_RELOC_X86_64_GOTPC32_TLSDESC
:
10130 case BFD_RELOC_X86_64_TLSDESC_CALL
:
10131 i
.has_gotpc_tls_reloc
= true;
10136 fixP
= fix_new_exp (frag_now
, p
- frag_now
->fr_literal
,
10137 size
, i
.op
[n
].disps
, pcrel
,
10140 if (flag_code
== CODE_64BIT
&& size
== 4 && pcrel
10141 && !i
.prefix
[ADDR_PREFIX
])
10142 fixP
->fx_signed
= 1;
10144 /* Check for "call/jmp *mem", "mov mem, %reg",
10145 "test %reg, mem" and "binop mem, %reg" where binop
10146 is one of adc, add, and, cmp, or, sbb, sub, xor
10147 instructions without data prefix. Always generate
10148 R_386_GOT32X for "sym*GOT" operand in 32-bit mode. */
10149 if (i
.prefix
[DATA_PREFIX
] == 0
10150 && (generate_relax_relocations
10153 && i
.rm
.regmem
== 5))
10155 || (i
.rm
.mode
== 0 && i
.rm
.regmem
== 5))
10156 && i
.tm
.opcode_space
== SPACE_BASE
10157 && ((i
.operands
== 1
10158 && i
.tm
.base_opcode
== 0xff
10159 && (i
.rm
.reg
== 2 || i
.rm
.reg
== 4))
10160 || (i
.operands
== 2
10161 && (i
.tm
.base_opcode
== 0x8b
10162 || i
.tm
.base_opcode
== 0x85
10163 || (i
.tm
.base_opcode
& ~0x38) == 0x03))))
10167 fixP
->fx_tcbit
= i
.rex
!= 0;
10169 && (i
.base_reg
->reg_num
== RegIP
))
10170 fixP
->fx_tcbit2
= 1;
10173 fixP
->fx_tcbit2
= 1;
10181 output_imm (fragS
*insn_start_frag
, offsetT insn_start_off
)
10186 for (n
= 0; n
< i
.operands
; n
++)
10188 if (operand_type_check (i
.types
[n
], imm
))
10190 int size
= imm_size (n
);
10192 if (now_seg
== absolute_section
)
10193 abs_section_offset
+= size
;
10194 else if (i
.op
[n
].imms
->X_op
== O_constant
)
10198 val
= offset_in_range (i
.op
[n
].imms
->X_add_number
,
10200 p
= frag_more (size
);
10201 md_number_to_chars (p
, val
, size
);
10205 /* Not absolute_section.
10206 Need a 32-bit fixup (don't support 8bit
10207 non-absolute imms). Try to support other
10209 enum bfd_reloc_code_real reloc_type
;
10212 if (i
.types
[n
].bitfield
.imm32s
10213 && (i
.suffix
== QWORD_MNEM_SUFFIX
10214 || (!i
.suffix
&& i
.tm
.opcode_modifier
.no_lsuf
)
10220 p
= frag_more (size
);
10221 reloc_type
= reloc (size
, 0, sign
, i
.reloc
[n
]);
10223 /* This is tough to explain. We end up with this one if we
10224 * have operands that look like
10225 * "_GLOBAL_OFFSET_TABLE_+[.-.L284]". The goal here is to
10226 * obtain the absolute address of the GOT, and it is strongly
10227 * preferable from a performance point of view to avoid using
10228 * a runtime relocation for this. The actual sequence of
10229 * instructions often look something like:
10234 * addl $_GLOBAL_OFFSET_TABLE_+[.-.L66],%ebx
10236 * The call and pop essentially return the absolute address
10237 * of the label .L66 and store it in %ebx. The linker itself
10238 * will ultimately change the first operand of the addl so
10239 * that %ebx points to the GOT, but to keep things simple, the
10240 * .o file must have this operand set so that it generates not
10241 * the absolute address of .L66, but the absolute address of
10242 * itself. This allows the linker itself simply treat a GOTPC
10243 * relocation as asking for a pcrel offset to the GOT to be
10244 * added in, and the addend of the relocation is stored in the
10245 * operand field for the instruction itself.
10247 * Our job here is to fix the operand so that it would add
10248 * the correct offset so that %ebx would point to itself. The
10249 * thing that is tricky is that .-.L66 will point to the
10250 * beginning of the instruction, so we need to further modify
10251 * the operand so that it will point to itself. There are
10252 * other cases where you have something like:
10254 * .long $_GLOBAL_OFFSET_TABLE_+[.-.L66]
10256 * and here no correction would be required. Internally in
10257 * the assembler we treat operands of this form as not being
10258 * pcrel since the '.' is explicitly mentioned, and I wonder
10259 * whether it would simplify matters to do it this way. Who
10260 * knows. In earlier versions of the PIC patches, the
10261 * pcrel_adjust field was used to store the correction, but
10262 * since the expression is not pcrel, I felt it would be
10263 * confusing to do it this way. */
10265 if ((reloc_type
== BFD_RELOC_32
10266 || reloc_type
== BFD_RELOC_X86_64_32S
10267 || reloc_type
== BFD_RELOC_64
)
10269 && GOT_symbol
== i
.op
[n
].imms
->X_add_symbol
10270 && (i
.op
[n
].imms
->X_op
== O_symbol
10271 || (i
.op
[n
].imms
->X_op
== O_add
10272 && ((symbol_get_value_expression
10273 (i
.op
[n
].imms
->X_op_symbol
)->X_op
)
10277 reloc_type
= BFD_RELOC_386_GOTPC
;
10278 else if (size
== 4)
10279 reloc_type
= BFD_RELOC_X86_64_GOTPC32
;
10280 else if (size
== 8)
10281 reloc_type
= BFD_RELOC_X86_64_GOTPC64
;
10282 i
.has_gotpc_tls_reloc
= true;
10283 i
.op
[n
].imms
->X_add_number
+=
10284 encoding_length (insn_start_frag
, insn_start_off
, p
);
10286 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, size
,
10287 i
.op
[n
].imms
, 0, reloc_type
);
10293 /* x86_cons_fix_new is called via the expression parsing code when a
10294 reloc is needed. We use this hook to get the correct .got reloc. */
10295 static int cons_sign
= -1;
10298 x86_cons_fix_new (fragS
*frag
, unsigned int off
, unsigned int len
,
10299 expressionS
*exp
, bfd_reloc_code_real_type r
)
10301 r
= reloc (len
, 0, cons_sign
, r
);
10304 if (exp
->X_op
== O_secrel
)
10306 exp
->X_op
= O_symbol
;
10307 r
= BFD_RELOC_32_SECREL
;
10309 else if (exp
->X_op
== O_secidx
)
10310 r
= BFD_RELOC_16_SECIDX
;
10313 fix_new_exp (frag
, off
, len
, exp
, 0, r
);
10316 /* Export the ABI address size for use by TC_ADDRESS_BYTES for the
10317 purpose of the `.dc.a' internal pseudo-op. */
10320 x86_address_bytes (void)
10322 if ((stdoutput
->arch_info
->mach
& bfd_mach_x64_32
))
10324 return stdoutput
->arch_info
->bits_per_address
/ 8;
10327 #if (!(defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) || defined (OBJ_MACH_O)) \
10328 || defined (LEX_AT)) && !defined (TE_PE)
10329 # define lex_got(reloc, adjust, types) NULL
10331 /* Parse operands of the form
10332 <symbol>@GOTOFF+<nnn>
10333 and similar .plt or .got references.
10335 If we find one, set up the correct relocation in RELOC and copy the
10336 input string, minus the `@GOTOFF' into a malloc'd buffer for
10337 parsing by the calling routine. Return this buffer, and if ADJUST
10338 is non-null set it to the length of the string we removed from the
10339 input line. Otherwise return NULL. */
10341 lex_got (enum bfd_reloc_code_real
*rel
,
10343 i386_operand_type
*types
)
10345 /* Some of the relocations depend on the size of what field is to
10346 be relocated. But in our callers i386_immediate and i386_displacement
10347 we don't yet know the operand size (this will be set by insn
10348 matching). Hence we record the word32 relocation here,
10349 and adjust the reloc according to the real size in reloc(). */
10350 static const struct
10354 const enum bfd_reloc_code_real rel
[2];
10355 const i386_operand_type types64
;
10356 bool need_GOT_symbol
;
10361 #define OPERAND_TYPE_IMM32_32S_DISP32 { .bitfield = \
10362 { .imm32 = 1, .imm32s = 1, .disp32 = 1 } }
10363 #define OPERAND_TYPE_IMM32_32S_64_DISP32 { .bitfield = \
10364 { .imm32 = 1, .imm32s = 1, .imm64 = 1, .disp32 = 1 } }
10365 #define OPERAND_TYPE_IMM32_32S_64_DISP32_64 { .bitfield = \
10366 { .imm32 = 1, .imm32s = 1, .imm64 = 1, .disp32 = 1, .disp64 = 1 } }
10367 #define OPERAND_TYPE_IMM64_DISP64 { .bitfield = \
10368 { .imm64 = 1, .disp64 = 1 } }
10371 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
10372 { STRING_COMMA_LEN ("SIZE"), { BFD_RELOC_SIZE32
,
10373 BFD_RELOC_SIZE32
},
10374 { .bitfield
= { .imm32
= 1, .imm64
= 1 } }, false },
10376 { STRING_COMMA_LEN ("PLTOFF"), { _dummy_first_bfd_reloc_code_real
,
10377 BFD_RELOC_X86_64_PLTOFF64
},
10378 { .bitfield
= { .imm64
= 1 } }, true },
10379 { STRING_COMMA_LEN ("PLT"), { BFD_RELOC_386_PLT32
,
10380 BFD_RELOC_X86_64_PLT32
},
10381 OPERAND_TYPE_IMM32_32S_DISP32
, false },
10382 { STRING_COMMA_LEN ("GOTPLT"), { _dummy_first_bfd_reloc_code_real
,
10383 BFD_RELOC_X86_64_GOTPLT64
},
10384 OPERAND_TYPE_IMM64_DISP64
, true },
10385 { STRING_COMMA_LEN ("GOTOFF"), { BFD_RELOC_386_GOTOFF
,
10386 BFD_RELOC_X86_64_GOTOFF64
},
10387 OPERAND_TYPE_IMM64_DISP64
, true },
10388 { STRING_COMMA_LEN ("GOTPCREL"), { _dummy_first_bfd_reloc_code_real
,
10389 BFD_RELOC_X86_64_GOTPCREL
},
10390 OPERAND_TYPE_IMM32_32S_DISP32
, true },
10391 { STRING_COMMA_LEN ("TLSGD"), { BFD_RELOC_386_TLS_GD
,
10392 BFD_RELOC_X86_64_TLSGD
},
10393 OPERAND_TYPE_IMM32_32S_DISP32
, true },
10394 { STRING_COMMA_LEN ("TLSLDM"), { BFD_RELOC_386_TLS_LDM
,
10395 _dummy_first_bfd_reloc_code_real
},
10396 OPERAND_TYPE_NONE
, true },
10397 { STRING_COMMA_LEN ("TLSLD"), { _dummy_first_bfd_reloc_code_real
,
10398 BFD_RELOC_X86_64_TLSLD
},
10399 OPERAND_TYPE_IMM32_32S_DISP32
, true },
10400 { STRING_COMMA_LEN ("GOTTPOFF"), { BFD_RELOC_386_TLS_IE_32
,
10401 BFD_RELOC_X86_64_GOTTPOFF
},
10402 OPERAND_TYPE_IMM32_32S_DISP32
, true },
10403 { STRING_COMMA_LEN ("TPOFF"), { BFD_RELOC_386_TLS_LE_32
,
10404 BFD_RELOC_X86_64_TPOFF32
},
10405 OPERAND_TYPE_IMM32_32S_64_DISP32_64
, true },
10406 { STRING_COMMA_LEN ("NTPOFF"), { BFD_RELOC_386_TLS_LE
,
10407 _dummy_first_bfd_reloc_code_real
},
10408 OPERAND_TYPE_NONE
, true },
10409 { STRING_COMMA_LEN ("DTPOFF"), { BFD_RELOC_386_TLS_LDO_32
,
10410 BFD_RELOC_X86_64_DTPOFF32
},
10411 OPERAND_TYPE_IMM32_32S_64_DISP32_64
, true },
10412 { STRING_COMMA_LEN ("GOTNTPOFF"),{ BFD_RELOC_386_TLS_GOTIE
,
10413 _dummy_first_bfd_reloc_code_real
},
10414 OPERAND_TYPE_NONE
, true },
10415 { STRING_COMMA_LEN ("INDNTPOFF"),{ BFD_RELOC_386_TLS_IE
,
10416 _dummy_first_bfd_reloc_code_real
},
10417 OPERAND_TYPE_NONE
, true },
10418 { STRING_COMMA_LEN ("GOT"), { BFD_RELOC_386_GOT32
,
10419 BFD_RELOC_X86_64_GOT32
},
10420 OPERAND_TYPE_IMM32_32S_64_DISP32
, true },
10421 { STRING_COMMA_LEN ("TLSDESC"), { BFD_RELOC_386_TLS_GOTDESC
,
10422 BFD_RELOC_X86_64_GOTPC32_TLSDESC
},
10423 OPERAND_TYPE_IMM32_32S_DISP32
, true },
10424 { STRING_COMMA_LEN ("TLSCALL"), { BFD_RELOC_386_TLS_DESC_CALL
,
10425 BFD_RELOC_X86_64_TLSDESC_CALL
},
10426 OPERAND_TYPE_IMM32_32S_DISP32
, true },
10428 { STRING_COMMA_LEN ("SECREL32"), { BFD_RELOC_32_SECREL
,
10429 BFD_RELOC_32_SECREL
},
10430 OPERAND_TYPE_IMM32_32S_64_DISP32_64
, false },
10433 #undef OPERAND_TYPE_IMM32_32S_DISP32
10434 #undef OPERAND_TYPE_IMM32_32S_64_DISP32
10435 #undef OPERAND_TYPE_IMM32_32S_64_DISP32_64
10436 #undef OPERAND_TYPE_IMM64_DISP64
10442 #if defined (OBJ_MAYBE_ELF) && !defined (TE_PE)
10447 for (cp
= input_line_pointer
; *cp
!= '@'; cp
++)
10448 if (is_end_of_line
[(unsigned char) *cp
] || *cp
== ',')
10451 for (j
= 0; j
< ARRAY_SIZE (gotrel
); j
++)
10453 int len
= gotrel
[j
].len
;
10454 if (strncasecmp (cp
+ 1, gotrel
[j
].str
, len
) == 0)
10456 if (gotrel
[j
].rel
[object_64bit
] != 0)
10459 char *tmpbuf
, *past_reloc
;
10461 *rel
= gotrel
[j
].rel
[object_64bit
];
10465 if (flag_code
!= CODE_64BIT
)
10467 types
->bitfield
.imm32
= 1;
10468 types
->bitfield
.disp32
= 1;
10471 *types
= gotrel
[j
].types64
;
10474 if (gotrel
[j
].need_GOT_symbol
&& GOT_symbol
== NULL
)
10475 GOT_symbol
= symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME
);
10477 /* The length of the first part of our input line. */
10478 first
= cp
- input_line_pointer
;
10480 /* The second part goes from after the reloc token until
10481 (and including) an end_of_line char or comma. */
10482 past_reloc
= cp
+ 1 + len
;
10484 while (!is_end_of_line
[(unsigned char) *cp
] && *cp
!= ',')
10486 second
= cp
+ 1 - past_reloc
;
10488 /* Allocate and copy string. The trailing NUL shouldn't
10489 be necessary, but be safe. */
10490 tmpbuf
= XNEWVEC (char, first
+ second
+ 2);
10491 memcpy (tmpbuf
, input_line_pointer
, first
);
10492 if (second
!= 0 && *past_reloc
!= ' ')
10493 /* Replace the relocation token with ' ', so that
10494 errors like foo@GOTOFF1 will be detected. */
10495 tmpbuf
[first
++] = ' ';
10497 /* Increment length by 1 if the relocation token is
10502 memcpy (tmpbuf
+ first
, past_reloc
, second
);
10503 tmpbuf
[first
+ second
] = '\0';
10507 as_bad (_("@%s reloc is not supported with %d-bit output format"),
10508 gotrel
[j
].str
, 1 << (5 + object_64bit
));
10513 /* Might be a symbol version string. Don't as_bad here. */
10518 bfd_reloc_code_real_type
10519 x86_cons (expressionS
*exp
, int size
)
10521 bfd_reloc_code_real_type got_reloc
= NO_RELOC
;
10523 intel_syntax
= -intel_syntax
;
10525 expr_mode
= expr_operator_none
;
10527 #if ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) \
10528 && !defined (LEX_AT)) \
10530 if (size
== 4 || (object_64bit
&& size
== 8))
10532 /* Handle @GOTOFF and the like in an expression. */
10534 char *gotfree_input_line
;
10537 save
= input_line_pointer
;
10538 gotfree_input_line
= lex_got (&got_reloc
, &adjust
, NULL
);
10539 if (gotfree_input_line
)
10540 input_line_pointer
= gotfree_input_line
;
10544 if (gotfree_input_line
)
10546 /* expression () has merrily parsed up to the end of line,
10547 or a comma - in the wrong buffer. Transfer how far
10548 input_line_pointer has moved to the right buffer. */
10549 input_line_pointer
= (save
10550 + (input_line_pointer
- gotfree_input_line
)
10552 free (gotfree_input_line
);
10553 if (exp
->X_op
== O_constant
10554 || exp
->X_op
== O_absent
10555 || exp
->X_op
== O_illegal
10556 || exp
->X_op
== O_register
10557 || exp
->X_op
== O_big
)
10559 char c
= *input_line_pointer
;
10560 *input_line_pointer
= 0;
10561 as_bad (_("missing or invalid expression `%s'"), save
);
10562 *input_line_pointer
= c
;
10564 else if ((got_reloc
== BFD_RELOC_386_PLT32
10565 || got_reloc
== BFD_RELOC_X86_64_PLT32
)
10566 && exp
->X_op
!= O_symbol
)
10568 char c
= *input_line_pointer
;
10569 *input_line_pointer
= 0;
10570 as_bad (_("invalid PLT expression `%s'"), save
);
10571 *input_line_pointer
= c
;
10579 intel_syntax
= -intel_syntax
;
10582 i386_intel_simplify (exp
);
10584 /* If not 64bit, massage value, to account for wraparound when !BFD64. */
10585 if (size
<= 4 && expr_mode
== expr_operator_present
10586 && exp
->X_op
== O_constant
&& !object_64bit
)
10587 exp
->X_add_number
= extend_to_32bit_address (exp
->X_add_number
);
10593 signed_cons (int size
)
10602 s_insn (int dummy ATTRIBUTE_UNUSED
)
10604 char mnemonic
[MAX_MNEM_SIZE
], *line
= input_line_pointer
, *ptr
;
10605 char *saved_ilp
= find_end_of_line (line
, false), saved_char
;
10609 bool vex
= false, xop
= false, evex
= false;
10610 static const templates tt
= { &i
.tm
, &i
.tm
+ 1 };
10614 saved_char
= *saved_ilp
;
10617 end
= parse_insn (line
, mnemonic
, true);
10621 *saved_ilp
= saved_char
;
10622 ignore_rest_of_line ();
10626 line
+= end
- line
;
10628 current_templates
= &tt
;
10629 i
.tm
.mnem_off
= MN__insn
;
10630 i
.tm
.extension_opcode
= None
;
10632 if (startswith (line
, "VEX")
10633 && (line
[3] == '.' || is_space_char (line
[3])))
10638 else if (startswith (line
, "XOP") && ISDIGIT (line
[3]))
10641 unsigned long n
= strtoul (line
+ 3, &e
, 16);
10643 if (e
== line
+ 5 && n
>= 0x08 && n
<= 0x1f
10644 && (*e
== '.' || is_space_char (*e
)))
10647 /* Arrange for build_vex_prefix() to emit 0x8f. */
10648 i
.tm
.opcode_space
= SPACE_XOP08
;
10649 i
.insn_opcode_space
= n
;
10653 else if (startswith (line
, "EVEX")
10654 && (line
[4] == '.' || is_space_char (line
[4])))
10661 ? i
.vec_encoding
== vex_encoding_evex
10663 ? i
.vec_encoding
== vex_encoding_vex
10664 || i
.vec_encoding
== vex_encoding_vex3
10665 : i
.vec_encoding
!= vex_encoding_default
)
10667 as_bad (_("pseudo-prefix conflicts with encoding specifier"));
10671 if (line
> end
&& i
.vec_encoding
== vex_encoding_default
)
10672 i
.vec_encoding
= evex
? vex_encoding_evex
: vex_encoding_vex
;
10674 if (line
> end
&& *line
== '.')
10676 /* Length specifier (VEX.L, XOP.L, EVEX.L'L). */
10684 i
.tm
.opcode_modifier
.evex
= EVEX128
;
10686 i
.tm
.opcode_modifier
.vex
= VEX128
;
10691 i
.tm
.opcode_modifier
.evex
= EVEX256
;
10693 i
.tm
.opcode_modifier
.vex
= VEX256
;
10698 i
.tm
.opcode_modifier
.evex
= EVEX512
;
10703 i
.tm
.opcode_modifier
.evex
= EVEX_L3
;
10707 if (line
[3] == 'G')
10710 i
.tm
.opcode_modifier
.evex
= EVEXLIG
;
10712 i
.tm
.opcode_modifier
.vex
= VEXScalar
; /* LIG */
10718 if (i
.tm
.opcode_modifier
.vex
|| i
.tm
.opcode_modifier
.evex
)
10723 if (line
[2] == '2' && line
[3] == '8')
10726 i
.tm
.opcode_modifier
.evex
= EVEX128
;
10728 i
.tm
.opcode_modifier
.vex
= VEX128
;
10734 if (line
[2] == '5' && line
[3] == '6')
10737 i
.tm
.opcode_modifier
.evex
= EVEX256
;
10739 i
.tm
.opcode_modifier
.vex
= VEX256
;
10745 if (evex
&& line
[2] == '1' && line
[3] == '2')
10747 i
.tm
.opcode_modifier
.evex
= EVEX512
;
10754 if (line
> end
&& *line
== '.')
10756 /* embedded prefix (VEX.pp, XOP.pp, EVEX.pp). */
10760 if (line
[2] == 'P')
10765 if (line
[2] == '6')
10767 i
.tm
.opcode_modifier
.opcodeprefix
= PREFIX_0X66
;
10772 case 'F': case 'f':
10773 if (line
[2] == '3')
10775 i
.tm
.opcode_modifier
.opcodeprefix
= PREFIX_0XF3
;
10778 else if (line
[2] == '2')
10780 i
.tm
.opcode_modifier
.opcodeprefix
= PREFIX_0XF2
;
10787 if (line
> end
&& !xop
&& *line
== '.')
10789 /* Encoding space (VEX.mmmmm, EVEX.mmmm). */
10793 if (TOUPPER (line
[2]) != 'F')
10795 if (line
[3] == '.' || is_space_char (line
[3]))
10797 i
.insn_opcode_space
= SPACE_0F
;
10800 else if (line
[3] == '3'
10801 && (line
[4] == '8' || TOUPPER (line
[4]) == 'A')
10802 && (line
[5] == '.' || is_space_char (line
[5])))
10804 i
.insn_opcode_space
= line
[4] == '8' ? SPACE_0F38
: SPACE_0F3A
;
10810 if (ISDIGIT (line
[2]) && line
[2] != '0')
10813 unsigned long n
= strtoul (line
+ 2, &e
, 10);
10815 if (n
<= (evex
? 15 : 31)
10816 && (*e
== '.' || is_space_char (*e
)))
10818 i
.insn_opcode_space
= n
;
10826 if (line
> end
&& *line
== '.' && line
[1] == 'W')
10828 /* VEX.W, XOP.W, EVEX.W */
10832 i
.tm
.opcode_modifier
.vexw
= VEXW0
;
10836 i
.tm
.opcode_modifier
.vexw
= VEXW1
;
10840 if (line
[3] == 'G')
10842 i
.tm
.opcode_modifier
.vexw
= VEXWIG
;
10848 if (i
.tm
.opcode_modifier
.vexw
)
10852 if (line
> end
&& *line
&& !is_space_char (*line
))
10854 /* Improve diagnostic a little. */
10855 if (*line
== '.' && line
[1] && !is_space_char (line
[1]))
10860 /* Before processing the opcode expression, find trailing "+r" or
10861 "/<digit>" specifiers. */
10862 for (ptr
= line
; ; ++ptr
)
10867 ptr
= strpbrk (ptr
, "+/,");
10868 if (ptr
== NULL
|| *ptr
== ',')
10871 if (*ptr
== '+' && ptr
[1] == 'r'
10872 && (ptr
[2] == ',' || (is_space_char (ptr
[2]) && ptr
[3] == ',')))
10876 i
.short_form
= true;
10880 if (*ptr
== '/' && ISDIGIT (ptr
[1])
10881 && (n
= strtoul (ptr
+ 1, &e
, 8)) < 8
10883 && (ptr
[2] == ',' || (is_space_char (ptr
[2]) && ptr
[3] == ',')))
10887 i
.tm
.extension_opcode
= n
;
10888 i
.tm
.opcode_modifier
.modrm
= 1;
10893 input_line_pointer
= line
;
10894 val
= get_absolute_expression ();
10895 line
= input_line_pointer
;
10897 if (i
.short_form
&& (val
& 7))
10898 as_warn ("`+r' assumes low three opcode bits to be clear");
10900 for (j
= 1; j
< sizeof(val
); ++j
)
10901 if (!(val
>> (j
* 8)))
10904 /* Trim off a prefix if present. */
10905 if (j
> 1 && !vex
&& !xop
&& !evex
)
10907 uint8_t byte
= val
>> ((j
- 1) * 8);
10911 case DATA_PREFIX_OPCODE
:
10912 case REPE_PREFIX_OPCODE
:
10913 case REPNE_PREFIX_OPCODE
:
10914 if (!add_prefix (byte
))
10916 val
&= ((uint64_t)1 << (--j
* 8)) - 1;
10921 /* Trim off encoding space. */
10922 if (j
> 1 && !i
.insn_opcode_space
&& (val
>> ((j
- 1) * 8)) == 0x0f)
10924 uint8_t byte
= val
>> ((--j
- 1) * 8);
10926 i
.insn_opcode_space
= SPACE_0F
;
10927 switch (byte
& -(j
> 1))
10930 i
.insn_opcode_space
= SPACE_0F38
;
10934 i
.insn_opcode_space
= SPACE_0F3A
;
10938 i
.tm
.opcode_space
= i
.insn_opcode_space
;
10939 val
&= ((uint64_t)1 << (j
* 8)) - 1;
10941 if (!i
.tm
.opcode_space
&& (vex
|| evex
))
10942 /* Arrange for build_vex_prefix() to properly emit 0xC4/0xC5.
10943 Also avoid hitting abort() there or in build_evex_prefix(). */
10944 i
.tm
.opcode_space
= i
.insn_opcode_space
== SPACE_0F
? SPACE_0F
10949 as_bad (_("opcode residual (%#"PRIx64
") too wide"), (uint64_t) val
);
10952 i
.opcode_length
= j
;
10954 /* Handle operands, if any. */
10957 i386_operand_type combined
;
10958 expressionS
*disp_exp
= NULL
;
10963 ptr
= parse_operands (line
+ 1, &i386_mnemonics
[MN__insn
]);
10971 as_bad (_("expecting operand after ','; got nothing"));
10975 if (i
.mem_operands
> 1)
10977 as_bad (_("too many memory references for `%s'"),
10978 &i386_mnemonics
[MN__insn
]);
10982 /* Are we to emit ModR/M encoding? */
10985 || i
.reg_operands
> (i
.vec_encoding
!= vex_encoding_default
)
10986 || i
.tm
.extension_opcode
!= None
))
10987 i
.tm
.opcode_modifier
.modrm
= 1;
10989 if (!i
.tm
.opcode_modifier
.modrm
10991 > i
.short_form
+ 0U + (i
.vec_encoding
!= vex_encoding_default
)
10992 || i
.mem_operands
))
10994 as_bad (_("too many register/memory operands"));
10998 /* Enforce certain constraints on operands. */
10999 switch (i
.reg_operands
+ i
.mem_operands
11000 + (i
.tm
.extension_opcode
!= None
))
11005 as_bad (_("too few register/memory operands"));
11008 /* Fall through. */
11010 if (i
.tm
.opcode_modifier
.modrm
)
11012 as_bad (_("too few register/memory operands"));
11022 && (i
.op
[0].imms
->X_op
!= O_constant
11023 || !fits_in_imm4 (i
.op
[0].imms
->X_add_number
)))
11025 as_bad (_("constant doesn't fit in %d bits"), evex
? 3 : 4);
11028 /* Fall through. */
11030 if (i
.vec_encoding
!= vex_encoding_default
)
11032 i
.tm
.opcode_modifier
.vexvvvv
= 1;
11035 /* Fall through. */
11037 as_bad (_("too many register/memory operands"));
11041 /* Bring operands into canonical order (imm, mem, reg). */
11046 for (j
= 1; j
< i
.operands
; ++j
)
11048 if ((!operand_type_check (i
.types
[j
- 1], imm
)
11049 && operand_type_check (i
.types
[j
], imm
))
11050 || (i
.types
[j
- 1].bitfield
.class != ClassNone
11051 && i
.types
[j
].bitfield
.class == ClassNone
))
11053 swap_2_operands (j
- 1, j
);
11060 /* For Intel syntax swap the order of register operands. */
11062 switch (i
.reg_operands
)
11069 swap_2_operands (i
.imm_operands
+ i
.mem_operands
+ 1, i
.operands
- 2);
11070 /* Fall through. */
11073 swap_2_operands (i
.imm_operands
+ i
.mem_operands
, i
.operands
- 1);
11080 /* Enforce constraints when using VSIB. */
11082 && (i
.index_reg
->reg_type
.bitfield
.xmmword
11083 || i
.index_reg
->reg_type
.bitfield
.ymmword
11084 || i
.index_reg
->reg_type
.bitfield
.zmmword
))
11086 if (i
.vec_encoding
== vex_encoding_default
)
11088 as_bad (_("VSIB unavailable with legacy encoding"));
11092 if (i
.vec_encoding
== vex_encoding_evex
11093 && i
.reg_operands
> 1)
11095 /* We could allow two register operands, encoding the 2nd one in
11096 an 8-bit immediate like for 4-register-operand insns, but that
11097 would require ugly fiddling with process_operands() and/or
11098 build_modrm_byte(). */
11099 as_bad (_("too many register operands with VSIB"));
11103 i
.tm
.opcode_modifier
.sib
= 1;
11106 /* Establish operand size encoding. */
11107 operand_type_set (&combined
, 0);
11109 for (j
= i
.imm_operands
; j
< i
.operands
; ++j
)
11111 i
.types
[j
].bitfield
.instance
= InstanceNone
;
11113 if (operand_type_check (i
.types
[j
], disp
))
11115 i
.types
[j
].bitfield
.baseindex
= 1;
11116 disp_exp
= i
.op
[j
].disps
;
11119 if (evex
&& i
.types
[j
].bitfield
.baseindex
)
11121 unsigned int n
= i
.memshift
;
11123 if (i
.types
[j
].bitfield
.byte
)
11125 else if (i
.types
[j
].bitfield
.word
)
11127 else if (i
.types
[j
].bitfield
.dword
)
11129 else if (i
.types
[j
].bitfield
.qword
)
11131 else if (i
.types
[j
].bitfield
.xmmword
)
11133 else if (i
.types
[j
].bitfield
.ymmword
)
11135 else if (i
.types
[j
].bitfield
.zmmword
)
11138 if (i
.memshift
< 32 && n
!= i
.memshift
)
11139 as_warn ("conflicting memory operand size specifiers");
11143 if ((i
.broadcast
.type
|| i
.broadcast
.bytes
)
11144 && j
== i
.broadcast
.operand
)
11147 combined
= operand_type_or (combined
, i
.types
[j
]);
11148 combined
.bitfield
.class = ClassNone
;
11151 switch ((i
.broadcast
.type
? i
.broadcast
.type
: 1)
11152 << (i
.memshift
< 32 ? i
.memshift
: 0))
11154 case 64: combined
.bitfield
.zmmword
= 1; break;
11155 case 32: combined
.bitfield
.ymmword
= 1; break;
11156 case 16: combined
.bitfield
.xmmword
= 1; break;
11157 case 8: combined
.bitfield
.qword
= 1; break;
11158 case 4: combined
.bitfield
.dword
= 1; break;
11161 if (i
.vec_encoding
== vex_encoding_default
)
11163 if (flag_code
== CODE_64BIT
&& combined
.bitfield
.qword
)
11165 else if ((flag_code
== CODE_16BIT
? combined
.bitfield
.dword
11166 : combined
.bitfield
.word
)
11167 && !add_prefix (DATA_PREFIX_OPCODE
))
11170 else if (!i
.tm
.opcode_modifier
.vexw
)
11172 if (flag_code
== CODE_64BIT
)
11174 if (combined
.bitfield
.qword
)
11175 i
.tm
.opcode_modifier
.vexw
= VEXW1
;
11176 else if (combined
.bitfield
.dword
)
11177 i
.tm
.opcode_modifier
.vexw
= VEXW0
;
11180 if (!i
.tm
.opcode_modifier
.vexw
)
11181 i
.tm
.opcode_modifier
.vexw
= VEXWIG
;
11186 if (!i
.tm
.opcode_modifier
.vex
)
11188 if (combined
.bitfield
.ymmword
)
11189 i
.tm
.opcode_modifier
.vex
= VEX256
;
11190 else if (combined
.bitfield
.xmmword
)
11191 i
.tm
.opcode_modifier
.vex
= VEX128
;
11196 if (!i
.tm
.opcode_modifier
.evex
)
11198 /* Do _not_ consider AVX512VL here. */
11199 if (i
.rounding
.type
!= rc_none
|| combined
.bitfield
.zmmword
)
11200 i
.tm
.opcode_modifier
.evex
= EVEX512
;
11201 else if (combined
.bitfield
.ymmword
)
11202 i
.tm
.opcode_modifier
.evex
= EVEX256
;
11203 else if (combined
.bitfield
.xmmword
)
11204 i
.tm
.opcode_modifier
.evex
= EVEX128
;
11207 if (i
.memshift
>= 32)
11209 unsigned int n
= 0;
11211 switch (i
.tm
.opcode_modifier
.evex
)
11213 case EVEX512
: n
= 64; break;
11214 case EVEX256
: n
= 32; break;
11215 case EVEX128
: n
= 16; break;
11218 if (i
.broadcast
.type
)
11219 n
/= i
.broadcast
.type
;
11222 for (i
.memshift
= 0; !(n
& 1); n
>>= 1)
11224 else if (disp_exp
!= NULL
&& disp_exp
->X_op
== O_constant
11225 && disp_exp
->X_add_number
!= 0
11226 && i
.disp_encoding
!= disp_encoding_32bit
)
11228 if (!quiet_warnings
)
11229 as_warn ("cannot determine memory operand size");
11230 i
.disp_encoding
= disp_encoding_32bit
;
11235 if (i
.memshift
>= 32)
11238 i
.vec_encoding
= vex_encoding_error
;
11240 if (i
.disp_operands
&& !optimize_disp (&i
.tm
))
11243 /* Establish size for immediate operands. */
11244 for (j
= 0; j
< i
.imm_operands
; ++j
)
11246 expressionS
*expP
= i
.op
[j
].imms
;
11248 gas_assert (operand_type_check (i
.types
[j
], imm
));
11249 operand_type_set (&i
.types
[j
], 0);
11251 if (i
.imm_bits
[j
] > 32)
11252 i
.types
[j
].bitfield
.imm64
= 1;
11253 else if (i
.imm_bits
[j
] > 16)
11255 if (flag_code
== CODE_64BIT
&& (i
.flags
[j
] & Operand_Signed
))
11256 i
.types
[j
].bitfield
.imm32s
= 1;
11258 i
.types
[j
].bitfield
.imm32
= 1;
11260 else if (i
.imm_bits
[j
] > 8)
11261 i
.types
[j
].bitfield
.imm16
= 1;
11262 else if (i
.imm_bits
[j
] > 0)
11264 if (i
.flags
[j
] & Operand_Signed
)
11265 i
.types
[j
].bitfield
.imm8s
= 1;
11267 i
.types
[j
].bitfield
.imm8
= 1;
11269 else if (expP
->X_op
== O_constant
)
11271 i
.types
[j
] = smallest_imm_type (expP
->X_add_number
);
11272 i
.types
[j
].bitfield
.imm1
= 0;
11273 /* Oddly enough imm_size() checks imm64 first, so the bit needs
11274 zapping since smallest_imm_type() sets it unconditionally. */
11275 if (flag_code
!= CODE_64BIT
)
11277 i
.types
[j
].bitfield
.imm64
= 0;
11278 i
.types
[j
].bitfield
.imm32s
= 0;
11279 i
.types
[j
].bitfield
.imm32
= 1;
11281 else if (i
.types
[j
].bitfield
.imm32
|| i
.types
[j
].bitfield
.imm32s
)
11282 i
.types
[j
].bitfield
.imm64
= 0;
11285 /* Non-constant expressions are sized heuristically. */
11288 case CODE_64BIT
: i
.types
[j
].bitfield
.imm32s
= 1; break;
11289 case CODE_32BIT
: i
.types
[j
].bitfield
.imm32
= 1; break;
11290 case CODE_16BIT
: i
.types
[j
].bitfield
.imm16
= 1; break;
11294 for (j
= 0; j
< i
.operands
; ++j
)
11295 i
.tm
.operand_types
[j
] = i
.types
[j
];
11297 process_operands ();
11300 /* Don't set opcode until after processing operands, to avoid any
11301 potential special casing there. */
11302 i
.tm
.base_opcode
|= val
;
11304 if (i
.vec_encoding
== vex_encoding_error
11305 || (i
.vec_encoding
!= vex_encoding_evex
11306 ? i
.broadcast
.type
|| i
.broadcast
.bytes
11307 || i
.rounding
.type
!= rc_none
11309 : (i
.broadcast
.type
|| i
.broadcast
.bytes
)
11310 && i
.rounding
.type
!= rc_none
))
11312 as_bad (_("conflicting .insn operands"));
11318 if (!i
.tm
.opcode_modifier
.vex
)
11319 i
.tm
.opcode_modifier
.vex
= VEXScalar
; /* LIG */
11321 build_vex_prefix (NULL
);
11322 i
.rex
&= REX_OPCODE
;
11326 if (!i
.tm
.opcode_modifier
.evex
)
11327 i
.tm
.opcode_modifier
.evex
= EVEXLIG
;
11329 build_evex_prefix ();
11330 i
.rex
&= REX_OPCODE
;
11332 else if (i
.rex
!= 0)
11333 add_prefix (REX_OPCODE
| i
.rex
);
11338 *saved_ilp
= saved_char
;
11339 input_line_pointer
= line
;
11341 demand_empty_rest_of_line ();
11343 /* Make sure dot_insn() won't yield "true" anymore. */
11349 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED
)
11356 if (exp
.X_op
== O_symbol
)
11357 exp
.X_op
= O_secrel
;
11359 emit_expr (&exp
, 4);
11361 while (*input_line_pointer
++ == ',');
11363 input_line_pointer
--;
11364 demand_empty_rest_of_line ();
11368 pe_directive_secidx (int dummy ATTRIBUTE_UNUSED
)
11375 if (exp
.X_op
== O_symbol
)
11376 exp
.X_op
= O_secidx
;
11378 emit_expr (&exp
, 2);
11380 while (*input_line_pointer
++ == ',');
11382 input_line_pointer
--;
11383 demand_empty_rest_of_line ();
11387 /* Handle Rounding Control / SAE specifiers. */
11390 RC_SAE_specifier (const char *pstr
)
11394 for (j
= 0; j
< ARRAY_SIZE (RC_NamesTable
); j
++)
11396 if (!strncmp (pstr
, RC_NamesTable
[j
].name
, RC_NamesTable
[j
].len
))
11398 if (i
.rounding
.type
!= rc_none
)
11400 as_bad (_("duplicated `{%s}'"), RC_NamesTable
[j
].name
);
11404 i
.rounding
.type
= RC_NamesTable
[j
].type
;
11406 return (char *)(pstr
+ RC_NamesTable
[j
].len
);
11413 /* Handle Vector operations. */
11416 check_VecOperations (char *op_string
)
11418 const reg_entry
*mask
;
11425 if (*op_string
== '{')
11429 /* Check broadcasts. */
11430 if (startswith (op_string
, "1to"))
11432 unsigned int bcst_type
;
11434 if (i
.broadcast
.type
)
11435 goto duplicated_vec_op
;
11438 if (*op_string
== '8')
11440 else if (*op_string
== '4')
11442 else if (*op_string
== '2')
11444 else if (*op_string
== '1'
11445 && *(op_string
+1) == '6')
11450 else if (*op_string
== '3'
11451 && *(op_string
+1) == '2')
11458 as_bad (_("Unsupported broadcast: `%s'"), saved
);
11463 i
.broadcast
.type
= bcst_type
;
11464 i
.broadcast
.operand
= this_operand
;
11466 /* For .insn a data size specifier may be appended. */
11467 if (dot_insn () && *op_string
== ':')
11468 goto dot_insn_modifier
;
11470 /* Check .insn special cases. */
11471 else if (dot_insn () && *op_string
== ':')
11474 switch (op_string
[1])
11479 if (i
.memshift
< 32)
11480 goto duplicated_vec_op
;
11482 n
= strtoul (op_string
+ 2, &end_op
, 0);
11484 for (i
.memshift
= 0; !(n
& 1); n
>>= 1)
11486 if (i
.memshift
< 32 && n
== 1)
11487 op_string
= end_op
;
11490 case 's': case 'u':
11491 /* This isn't really a "vector" operation, but a sign/size
11492 specifier for immediate operands of .insn. Note that AT&T
11493 syntax handles the same in i386_immediate(). */
11497 if (i
.imm_bits
[this_operand
])
11498 goto duplicated_vec_op
;
11500 n
= strtoul (op_string
+ 2, &end_op
, 0);
11501 if (n
&& n
<= (flag_code
== CODE_64BIT
? 64 : 32))
11503 i
.imm_bits
[this_operand
] = n
;
11504 if (op_string
[1] == 's')
11505 i
.flags
[this_operand
] |= Operand_Signed
;
11506 op_string
= end_op
;
11511 /* Check masking operation. */
11512 else if ((mask
= parse_register (op_string
, &end_op
)) != NULL
)
11514 if (mask
== &bad_reg
)
11517 /* k0 can't be used for write mask. */
11518 if (mask
->reg_type
.bitfield
.class != RegMask
|| !mask
->reg_num
)
11520 as_bad (_("`%s%s' can't be used for write mask"),
11521 register_prefix
, mask
->reg_name
);
11528 i
.mask
.operand
= this_operand
;
11530 else if (i
.mask
.reg
->reg_num
)
11531 goto duplicated_vec_op
;
11536 /* Only "{z}" is allowed here. No need to check
11537 zeroing mask explicitly. */
11538 if (i
.mask
.operand
!= (unsigned int) this_operand
)
11540 as_bad (_("invalid write mask `%s'"), saved
);
11545 op_string
= end_op
;
11547 /* Check zeroing-flag for masking operation. */
11548 else if (*op_string
== 'z')
11552 i
.mask
.reg
= reg_k0
;
11553 i
.mask
.zeroing
= 1;
11554 i
.mask
.operand
= this_operand
;
11558 if (i
.mask
.zeroing
)
11561 as_bad (_("duplicated `%s'"), saved
);
11565 i
.mask
.zeroing
= 1;
11567 /* Only "{%k}" is allowed here. No need to check mask
11568 register explicitly. */
11569 if (i
.mask
.operand
!= (unsigned int) this_operand
)
11571 as_bad (_("invalid zeroing-masking `%s'"),
11579 else if (intel_syntax
11580 && (op_string
= RC_SAE_specifier (op_string
)) != NULL
)
11581 i
.rounding
.modifier
= true;
11583 goto unknown_vec_op
;
11585 if (*op_string
!= '}')
11587 as_bad (_("missing `}' in `%s'"), saved
);
11592 /* Strip whitespace since the addition of pseudo prefixes
11593 changed how the scrubber treats '{'. */
11594 if (is_space_char (*op_string
))
11600 /* We don't know this one. */
11601 as_bad (_("unknown vector operation: `%s'"), saved
);
11605 if (i
.mask
.reg
&& i
.mask
.zeroing
&& !i
.mask
.reg
->reg_num
)
11607 as_bad (_("zeroing-masking only allowed with write mask"));
11615 i386_immediate (char *imm_start
)
11617 char *save_input_line_pointer
;
11618 char *gotfree_input_line
;
11621 i386_operand_type types
;
11623 operand_type_set (&types
, ~0);
11625 if (i
.imm_operands
== MAX_IMMEDIATE_OPERANDS
)
11627 as_bad (_("at most %d immediate operands are allowed"),
11628 MAX_IMMEDIATE_OPERANDS
);
11632 exp
= &im_expressions
[i
.imm_operands
++];
11633 i
.op
[this_operand
].imms
= exp
;
11635 if (is_space_char (*imm_start
))
11638 save_input_line_pointer
= input_line_pointer
;
11639 input_line_pointer
= imm_start
;
11641 gotfree_input_line
= lex_got (&i
.reloc
[this_operand
], NULL
, &types
);
11642 if (gotfree_input_line
)
11643 input_line_pointer
= gotfree_input_line
;
11645 expr_mode
= expr_operator_none
;
11646 exp_seg
= expression (exp
);
11648 /* For .insn immediates there may be a size specifier. */
11649 if (dot_insn () && *input_line_pointer
== '{' && input_line_pointer
[1] == ':'
11650 && (input_line_pointer
[2] == 's' || input_line_pointer
[2] == 'u'))
11653 unsigned long n
= strtoul (input_line_pointer
+ 3, &e
, 0);
11655 if (*e
== '}' && n
&& n
<= (flag_code
== CODE_64BIT
? 64 : 32))
11657 i
.imm_bits
[this_operand
] = n
;
11658 if (input_line_pointer
[2] == 's')
11659 i
.flags
[this_operand
] |= Operand_Signed
;
11660 input_line_pointer
= e
+ 1;
11664 SKIP_WHITESPACE ();
11665 if (*input_line_pointer
)
11666 as_bad (_("junk `%s' after expression"), input_line_pointer
);
11668 input_line_pointer
= save_input_line_pointer
;
11669 if (gotfree_input_line
)
11671 free (gotfree_input_line
);
11673 if (exp
->X_op
== O_constant
)
11674 exp
->X_op
= O_illegal
;
11677 if (exp_seg
== reg_section
)
11679 as_bad (_("illegal immediate register operand %s"), imm_start
);
11683 return i386_finalize_immediate (exp_seg
, exp
, types
, imm_start
);
11687 i386_finalize_immediate (segT exp_seg ATTRIBUTE_UNUSED
, expressionS
*exp
,
11688 i386_operand_type types
, const char *imm_start
)
11690 if (exp
->X_op
== O_absent
|| exp
->X_op
== O_illegal
|| exp
->X_op
== O_big
)
11693 as_bad (_("missing or invalid immediate expression `%s'"),
11697 else if (exp
->X_op
== O_constant
)
11699 /* Size it properly later. */
11700 i
.types
[this_operand
].bitfield
.imm64
= 1;
11702 /* If not 64bit, sign/zero extend val, to account for wraparound
11704 if (expr_mode
== expr_operator_present
11705 && flag_code
!= CODE_64BIT
&& !object_64bit
)
11706 exp
->X_add_number
= extend_to_32bit_address (exp
->X_add_number
);
11708 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
11709 else if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
11710 && exp_seg
!= absolute_section
11711 && exp_seg
!= text_section
11712 && exp_seg
!= data_section
11713 && exp_seg
!= bss_section
11714 && exp_seg
!= undefined_section
11715 && !bfd_is_com_section (exp_seg
))
11717 as_bad (_("unimplemented segment %s in operand"), exp_seg
->name
);
11723 /* This is an address. The size of the address will be
11724 determined later, depending on destination register,
11725 suffix, or the default for the section. */
11726 i
.types
[this_operand
].bitfield
.imm8
= 1;
11727 i
.types
[this_operand
].bitfield
.imm16
= 1;
11728 i
.types
[this_operand
].bitfield
.imm32
= 1;
11729 i
.types
[this_operand
].bitfield
.imm32s
= 1;
11730 i
.types
[this_operand
].bitfield
.imm64
= 1;
11731 i
.types
[this_operand
] = operand_type_and (i
.types
[this_operand
],
11739 i386_scale (char *scale
)
11742 char *save
= input_line_pointer
;
11744 input_line_pointer
= scale
;
11745 val
= get_absolute_expression ();
11750 i
.log2_scale_factor
= 0;
11753 i
.log2_scale_factor
= 1;
11756 i
.log2_scale_factor
= 2;
11759 i
.log2_scale_factor
= 3;
11763 char sep
= *input_line_pointer
;
11765 *input_line_pointer
= '\0';
11766 as_bad (_("expecting scale factor of 1, 2, 4, or 8: got `%s'"),
11768 *input_line_pointer
= sep
;
11769 input_line_pointer
= save
;
11773 if (i
.log2_scale_factor
!= 0 && i
.index_reg
== 0)
11775 as_warn (_("scale factor of %d without an index register"),
11776 1 << i
.log2_scale_factor
);
11777 i
.log2_scale_factor
= 0;
11779 scale
= input_line_pointer
;
11780 input_line_pointer
= save
;
11785 i386_displacement (char *disp_start
, char *disp_end
)
11789 char *save_input_line_pointer
;
11790 char *gotfree_input_line
;
11792 i386_operand_type bigdisp
, types
= anydisp
;
11795 if (i
.disp_operands
== MAX_MEMORY_OPERANDS
)
11797 as_bad (_("at most %d displacement operands are allowed"),
11798 MAX_MEMORY_OPERANDS
);
11802 operand_type_set (&bigdisp
, 0);
11804 || i
.types
[this_operand
].bitfield
.baseindex
11805 || (current_templates
->start
->opcode_modifier
.jump
!= JUMP
11806 && current_templates
->start
->opcode_modifier
.jump
!= JUMP_DWORD
))
11808 i386_addressing_mode ();
11809 override
= (i
.prefix
[ADDR_PREFIX
] != 0);
11810 if (flag_code
== CODE_64BIT
)
11812 bigdisp
.bitfield
.disp32
= 1;
11814 bigdisp
.bitfield
.disp64
= 1;
11816 else if ((flag_code
== CODE_16BIT
) ^ override
)
11817 bigdisp
.bitfield
.disp16
= 1;
11819 bigdisp
.bitfield
.disp32
= 1;
11823 /* For PC-relative branches, the width of the displacement may be
11824 dependent upon data size, but is never dependent upon address size.
11825 Also make sure to not unintentionally match against a non-PC-relative
11826 branch template. */
11827 static templates aux_templates
;
11828 const insn_template
*t
= current_templates
->start
;
11829 bool has_intel64
= false;
11831 aux_templates
.start
= t
;
11832 while (++t
< current_templates
->end
)
11834 if (t
->opcode_modifier
.jump
11835 != current_templates
->start
->opcode_modifier
.jump
)
11837 if ((t
->opcode_modifier
.isa64
>= INTEL64
))
11838 has_intel64
= true;
11840 if (t
< current_templates
->end
)
11842 aux_templates
.end
= t
;
11843 current_templates
= &aux_templates
;
11846 override
= (i
.prefix
[DATA_PREFIX
] != 0);
11847 if (flag_code
== CODE_64BIT
)
11849 if ((override
|| i
.suffix
== WORD_MNEM_SUFFIX
)
11850 && (!intel64
|| !has_intel64
))
11851 bigdisp
.bitfield
.disp16
= 1;
11853 bigdisp
.bitfield
.disp32
= 1;
11858 override
= (i
.suffix
== (flag_code
!= CODE_16BIT
11860 : LONG_MNEM_SUFFIX
));
11861 bigdisp
.bitfield
.disp32
= 1;
11862 if ((flag_code
== CODE_16BIT
) ^ override
)
11864 bigdisp
.bitfield
.disp32
= 0;
11865 bigdisp
.bitfield
.disp16
= 1;
11869 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
11872 exp
= &disp_expressions
[i
.disp_operands
];
11873 i
.op
[this_operand
].disps
= exp
;
11875 save_input_line_pointer
= input_line_pointer
;
11876 input_line_pointer
= disp_start
;
11877 END_STRING_AND_SAVE (disp_end
);
11879 #ifndef GCC_ASM_O_HACK
11880 #define GCC_ASM_O_HACK 0
11883 END_STRING_AND_SAVE (disp_end
+ 1);
11884 if (i
.types
[this_operand
].bitfield
.baseIndex
11885 && displacement_string_end
[-1] == '+')
11887 /* This hack is to avoid a warning when using the "o"
11888 constraint within gcc asm statements.
11891 #define _set_tssldt_desc(n,addr,limit,type) \
11892 __asm__ __volatile__ ( \
11893 "movw %w2,%0\n\t" \
11894 "movw %w1,2+%0\n\t" \
11895 "rorl $16,%1\n\t" \
11896 "movb %b1,4+%0\n\t" \
11897 "movb %4,5+%0\n\t" \
11898 "movb $0,6+%0\n\t" \
11899 "movb %h1,7+%0\n\t" \
11901 : "=o"(*(n)) : "q" (addr), "ri"(limit), "i"(type))
11903 This works great except that the output assembler ends
11904 up looking a bit weird if it turns out that there is
11905 no offset. You end up producing code that looks like:
11918 So here we provide the missing zero. */
11920 *displacement_string_end
= '0';
11923 gotfree_input_line
= lex_got (&i
.reloc
[this_operand
], NULL
, &types
);
11924 if (gotfree_input_line
)
11925 input_line_pointer
= gotfree_input_line
;
11927 expr_mode
= expr_operator_none
;
11928 exp_seg
= expression (exp
);
11930 SKIP_WHITESPACE ();
11931 if (*input_line_pointer
)
11932 as_bad (_("junk `%s' after expression"), input_line_pointer
);
11934 RESTORE_END_STRING (disp_end
+ 1);
11936 input_line_pointer
= save_input_line_pointer
;
11937 if (gotfree_input_line
)
11939 free (gotfree_input_line
);
11941 if (exp
->X_op
== O_constant
|| exp
->X_op
== O_register
)
11942 exp
->X_op
= O_illegal
;
11945 ret
= i386_finalize_displacement (exp_seg
, exp
, types
, disp_start
);
11947 RESTORE_END_STRING (disp_end
);
11953 i386_finalize_displacement (segT exp_seg ATTRIBUTE_UNUSED
, expressionS
*exp
,
11954 i386_operand_type types
, const char *disp_start
)
11958 /* We do this to make sure that the section symbol is in
11959 the symbol table. We will ultimately change the relocation
11960 to be relative to the beginning of the section. */
11961 if (i
.reloc
[this_operand
] == BFD_RELOC_386_GOTOFF
11962 || i
.reloc
[this_operand
] == BFD_RELOC_X86_64_GOTPCREL
11963 || i
.reloc
[this_operand
] == BFD_RELOC_X86_64_GOTOFF64
)
11965 if (exp
->X_op
!= O_symbol
)
11968 if (S_IS_LOCAL (exp
->X_add_symbol
)
11969 && S_GET_SEGMENT (exp
->X_add_symbol
) != undefined_section
11970 && S_GET_SEGMENT (exp
->X_add_symbol
) != expr_section
)
11971 section_symbol (S_GET_SEGMENT (exp
->X_add_symbol
));
11972 exp
->X_op
= O_subtract
;
11973 exp
->X_op_symbol
= GOT_symbol
;
11974 if (i
.reloc
[this_operand
] == BFD_RELOC_X86_64_GOTPCREL
)
11975 i
.reloc
[this_operand
] = BFD_RELOC_32_PCREL
;
11976 else if (i
.reloc
[this_operand
] == BFD_RELOC_X86_64_GOTOFF64
)
11977 i
.reloc
[this_operand
] = BFD_RELOC_64
;
11979 i
.reloc
[this_operand
] = BFD_RELOC_32
;
11982 else if (exp
->X_op
== O_absent
11983 || exp
->X_op
== O_illegal
11984 || exp
->X_op
== O_big
)
11987 as_bad (_("missing or invalid displacement expression `%s'"),
11992 else if (exp
->X_op
== O_constant
)
11994 /* Sizing gets taken care of by optimize_disp().
11996 If not 64bit, sign/zero extend val, to account for wraparound
11998 if (expr_mode
== expr_operator_present
11999 && flag_code
!= CODE_64BIT
&& !object_64bit
)
12000 exp
->X_add_number
= extend_to_32bit_address (exp
->X_add_number
);
12003 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
12004 else if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
12005 && exp_seg
!= absolute_section
12006 && exp_seg
!= text_section
12007 && exp_seg
!= data_section
12008 && exp_seg
!= bss_section
12009 && exp_seg
!= undefined_section
12010 && !bfd_is_com_section (exp_seg
))
12012 as_bad (_("unimplemented segment %s in operand"), exp_seg
->name
);
12017 else if (current_templates
->start
->opcode_modifier
.jump
== JUMP_BYTE
)
12018 i
.types
[this_operand
].bitfield
.disp8
= 1;
12020 /* Check if this is a displacement only operand. */
12021 if (!i
.types
[this_operand
].bitfield
.baseindex
)
12022 i
.types
[this_operand
] =
12023 operand_type_or (operand_type_and_not (i
.types
[this_operand
], anydisp
),
12024 operand_type_and (i
.types
[this_operand
], types
));
12029 /* Return the active addressing mode, taking address override and
12030 registers forming the address into consideration. Update the
12031 address override prefix if necessary. */
12033 static enum flag_code
12034 i386_addressing_mode (void)
12036 enum flag_code addr_mode
;
12038 if (i
.prefix
[ADDR_PREFIX
])
12039 addr_mode
= flag_code
== CODE_32BIT
? CODE_16BIT
: CODE_32BIT
;
12040 else if (flag_code
== CODE_16BIT
12041 && current_templates
->start
->cpu_flags
.bitfield
.cpumpx
12042 /* Avoid replacing the "16-bit addressing not allowed" diagnostic
12043 from md_assemble() by "is not a valid base/index expression"
12044 when there is a base and/or index. */
12045 && !i
.types
[this_operand
].bitfield
.baseindex
)
12047 /* MPX insn memory operands with neither base nor index must be forced
12048 to use 32-bit addressing in 16-bit mode. */
12049 addr_mode
= CODE_32BIT
;
12050 i
.prefix
[ADDR_PREFIX
] = ADDR_PREFIX_OPCODE
;
12052 gas_assert (!i
.types
[this_operand
].bitfield
.disp16
);
12053 gas_assert (!i
.types
[this_operand
].bitfield
.disp32
);
12057 addr_mode
= flag_code
;
12059 #if INFER_ADDR_PREFIX
12060 if (i
.mem_operands
== 0)
12062 /* Infer address prefix from the first memory operand. */
12063 const reg_entry
*addr_reg
= i
.base_reg
;
12065 if (addr_reg
== NULL
)
12066 addr_reg
= i
.index_reg
;
12070 if (addr_reg
->reg_type
.bitfield
.dword
)
12071 addr_mode
= CODE_32BIT
;
12072 else if (flag_code
!= CODE_64BIT
12073 && addr_reg
->reg_type
.bitfield
.word
)
12074 addr_mode
= CODE_16BIT
;
12076 if (addr_mode
!= flag_code
)
12078 i
.prefix
[ADDR_PREFIX
] = ADDR_PREFIX_OPCODE
;
12080 /* Change the size of any displacement too. At most one
12081 of Disp16 or Disp32 is set.
12082 FIXME. There doesn't seem to be any real need for
12083 separate Disp16 and Disp32 flags. The same goes for
12084 Imm16 and Imm32. Removing them would probably clean
12085 up the code quite a lot. */
12086 if (flag_code
!= CODE_64BIT
12087 && (i
.types
[this_operand
].bitfield
.disp16
12088 || i
.types
[this_operand
].bitfield
.disp32
))
12090 static const i386_operand_type disp16_32
= {
12091 .bitfield
= { .disp16
= 1, .disp32
= 1 }
12094 i
.types
[this_operand
]
12095 = operand_type_xor (i
.types
[this_operand
], disp16_32
);
12106 /* Make sure the memory operand we've been dealt is valid.
12107 Return 1 on success, 0 on a failure. */
12110 i386_index_check (const char *operand_string
)
12112 const char *kind
= "base/index";
12113 enum flag_code addr_mode
= i386_addressing_mode ();
12114 const insn_template
*t
= current_templates
->end
- 1;
12116 if (t
->opcode_modifier
.isstring
)
12118 /* Memory operands of string insns are special in that they only allow
12119 a single register (rDI, rSI, or rBX) as their memory address. */
12120 const reg_entry
*expected_reg
;
12121 static const char *di_si
[][2] =
12127 static const char *bx
[] = { "ebx", "bx", "rbx" };
12129 kind
= "string address";
12131 if (t
->opcode_modifier
.prefixok
== PrefixRep
)
12133 int es_op
= t
->opcode_modifier
.isstring
- IS_STRING_ES_OP0
;
12136 if (!t
->operand_types
[0].bitfield
.baseindex
12137 || ((!i
.mem_operands
!= !intel_syntax
)
12138 && t
->operand_types
[1].bitfield
.baseindex
))
12141 = (const reg_entry
*) str_hash_find (reg_hash
,
12142 di_si
[addr_mode
][op
== es_op
]);
12146 = (const reg_entry
*)str_hash_find (reg_hash
, bx
[addr_mode
]);
12148 if (i
.base_reg
!= expected_reg
12150 || operand_type_check (i
.types
[this_operand
], disp
))
12152 /* The second memory operand must have the same size as
12156 && !((addr_mode
== CODE_64BIT
12157 && i
.base_reg
->reg_type
.bitfield
.qword
)
12158 || (addr_mode
== CODE_32BIT
12159 ? i
.base_reg
->reg_type
.bitfield
.dword
12160 : i
.base_reg
->reg_type
.bitfield
.word
)))
12163 as_warn (_("`%s' is not valid here (expected `%c%s%s%c')"),
12165 intel_syntax
? '[' : '(',
12167 expected_reg
->reg_name
,
12168 intel_syntax
? ']' : ')');
12175 as_bad (_("`%s' is not a valid %s expression"),
12176 operand_string
, kind
);
12181 t
= current_templates
->start
;
12183 if (addr_mode
!= CODE_16BIT
)
12185 /* 32-bit/64-bit checks. */
12186 if (i
.disp_encoding
== disp_encoding_16bit
)
12189 as_bad (_("invalid `%s' prefix"),
12190 addr_mode
== CODE_16BIT
? "{disp32}" : "{disp16}");
12195 && ((addr_mode
== CODE_64BIT
12196 ? !i
.base_reg
->reg_type
.bitfield
.qword
12197 : !i
.base_reg
->reg_type
.bitfield
.dword
)
12198 || (i
.index_reg
&& i
.base_reg
->reg_num
== RegIP
)
12199 || i
.base_reg
->reg_num
== RegIZ
))
12201 && !i
.index_reg
->reg_type
.bitfield
.xmmword
12202 && !i
.index_reg
->reg_type
.bitfield
.ymmword
12203 && !i
.index_reg
->reg_type
.bitfield
.zmmword
12204 && ((addr_mode
== CODE_64BIT
12205 ? !i
.index_reg
->reg_type
.bitfield
.qword
12206 : !i
.index_reg
->reg_type
.bitfield
.dword
)
12207 || !i
.index_reg
->reg_type
.bitfield
.baseindex
)))
12210 /* bndmk, bndldx, bndstx and mandatory non-vector SIB have special restrictions. */
12211 if (t
->mnem_off
== MN_bndmk
12212 || t
->mnem_off
== MN_bndldx
12213 || t
->mnem_off
== MN_bndstx
12214 || t
->opcode_modifier
.sib
== SIBMEM
)
12216 /* They cannot use RIP-relative addressing. */
12217 if (i
.base_reg
&& i
.base_reg
->reg_num
== RegIP
)
12219 as_bad (_("`%s' cannot be used here"), operand_string
);
12223 /* bndldx and bndstx ignore their scale factor. */
12224 if ((t
->mnem_off
== MN_bndldx
|| t
->mnem_off
== MN_bndstx
)
12225 && i
.log2_scale_factor
)
12226 as_warn (_("register scaling is being ignored here"));
12231 /* 16-bit checks. */
12232 if (i
.disp_encoding
== disp_encoding_32bit
)
12236 && (!i
.base_reg
->reg_type
.bitfield
.word
12237 || !i
.base_reg
->reg_type
.bitfield
.baseindex
))
12239 && (!i
.index_reg
->reg_type
.bitfield
.word
12240 || !i
.index_reg
->reg_type
.bitfield
.baseindex
12242 && i
.base_reg
->reg_num
< 6
12243 && i
.index_reg
->reg_num
>= 6
12244 && i
.log2_scale_factor
== 0))))
12251 /* Handle vector immediates. */
12254 RC_SAE_immediate (const char *imm_start
)
12256 const char *pstr
= imm_start
;
12261 pstr
= RC_SAE_specifier (pstr
+ 1);
12265 if (*pstr
++ != '}')
12267 as_bad (_("Missing '}': '%s'"), imm_start
);
12270 /* RC/SAE immediate string should contain nothing more. */;
12273 as_bad (_("Junk after '}': '%s'"), imm_start
);
12277 /* Internally this doesn't count as an operand. */
12283 static INLINE
bool starts_memory_operand (char c
)
12286 || is_name_beginner (c
)
12287 || strchr ("([\"+-!~", c
);
12290 /* Parse OPERAND_STRING into the i386_insn structure I. Returns zero
12294 i386_att_operand (char *operand_string
)
12296 const reg_entry
*r
;
12298 char *op_string
= operand_string
;
12300 if (is_space_char (*op_string
))
12303 /* We check for an absolute prefix (differentiating,
12304 for example, 'jmp pc_relative_label' from 'jmp *absolute_label'. */
12305 if (*op_string
== ABSOLUTE_PREFIX
12306 && current_templates
->start
->opcode_modifier
.jump
)
12309 if (is_space_char (*op_string
))
12311 i
.jumpabsolute
= true;
12314 /* Check if operand is a register. */
12315 if ((r
= parse_register (op_string
, &end_op
)) != NULL
)
12317 i386_operand_type temp
;
12322 /* Check for a segment override by searching for ':' after a
12323 segment register. */
12324 op_string
= end_op
;
12325 if (is_space_char (*op_string
))
12327 if (*op_string
== ':' && r
->reg_type
.bitfield
.class == SReg
)
12329 i
.seg
[i
.mem_operands
] = r
;
12331 /* Skip the ':' and whitespace. */
12333 if (is_space_char (*op_string
))
12336 /* Handle case of %es:*foo. */
12337 if (!i
.jumpabsolute
&& *op_string
== ABSOLUTE_PREFIX
12338 && current_templates
->start
->opcode_modifier
.jump
)
12341 if (is_space_char (*op_string
))
12343 i
.jumpabsolute
= true;
12346 if (!starts_memory_operand (*op_string
))
12348 as_bad (_("bad memory operand `%s'"), op_string
);
12351 goto do_memory_reference
;
12354 /* Handle vector operations. */
12355 if (*op_string
== '{')
12357 op_string
= check_VecOperations (op_string
);
12358 if (op_string
== NULL
)
12364 as_bad (_("junk `%s' after register"), op_string
);
12368 /* Reject pseudo registers for .insn. */
12369 if (dot_insn () && r
->reg_type
.bitfield
.class == ClassNone
)
12371 as_bad (_("`%s%s' cannot be used here"),
12372 register_prefix
, r
->reg_name
);
12376 temp
= r
->reg_type
;
12377 temp
.bitfield
.baseindex
= 0;
12378 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
12380 i
.types
[this_operand
].bitfield
.unspecified
= 0;
12381 i
.op
[this_operand
].regs
= r
;
12384 /* A GPR may follow an RC or SAE immediate only if a (vector) register
12385 operand was also present earlier on. */
12386 if (i
.rounding
.type
!= rc_none
&& temp
.bitfield
.class == Reg
12387 && i
.reg_operands
== 1)
12391 for (j
= 0; j
< ARRAY_SIZE (RC_NamesTable
); ++j
)
12392 if (i
.rounding
.type
== RC_NamesTable
[j
].type
)
12394 as_bad (_("`%s': misplaced `{%s}'"),
12395 insn_name (current_templates
->start
), RC_NamesTable
[j
].name
);
12399 else if (*op_string
== REGISTER_PREFIX
)
12401 as_bad (_("bad register name `%s'"), op_string
);
12404 else if (*op_string
== IMMEDIATE_PREFIX
)
12407 if (i
.jumpabsolute
)
12409 as_bad (_("immediate operand illegal with absolute jump"));
12412 if (!i386_immediate (op_string
))
12414 if (i
.rounding
.type
!= rc_none
)
12416 as_bad (_("`%s': RC/SAE operand must follow immediate operands"),
12417 insn_name (current_templates
->start
));
12421 else if (RC_SAE_immediate (operand_string
))
12423 /* If it is a RC or SAE immediate, do the necessary placement check:
12424 Only another immediate or a GPR may precede it. */
12425 if (i
.mem_operands
|| i
.reg_operands
+ i
.imm_operands
> 1
12426 || (i
.reg_operands
== 1
12427 && i
.op
[0].regs
->reg_type
.bitfield
.class != Reg
))
12429 as_bad (_("`%s': misplaced `%s'"),
12430 insn_name (current_templates
->start
), operand_string
);
12434 else if (starts_memory_operand (*op_string
))
12436 /* This is a memory reference of some sort. */
12439 /* Start and end of displacement string expression (if found). */
12440 char *displacement_string_start
;
12441 char *displacement_string_end
;
12443 do_memory_reference
:
12444 /* Check for base index form. We detect the base index form by
12445 looking for an ')' at the end of the operand, searching
12446 for the '(' matching it, and finding a REGISTER_PREFIX or ','
12448 base_string
= op_string
+ strlen (op_string
);
12450 /* Handle vector operations. */
12452 if (is_space_char (*base_string
))
12455 if (*base_string
== '}')
12457 char *vop_start
= NULL
;
12459 while (base_string
-- > op_string
)
12461 if (*base_string
== '"')
12463 if (*base_string
!= '{')
12466 vop_start
= base_string
;
12469 if (is_space_char (*base_string
))
12472 if (*base_string
!= '}')
12480 as_bad (_("unbalanced figure braces"));
12484 if (check_VecOperations (vop_start
) == NULL
)
12488 /* If we only have a displacement, set-up for it to be parsed later. */
12489 displacement_string_start
= op_string
;
12490 displacement_string_end
= base_string
+ 1;
12492 if (*base_string
== ')')
12495 unsigned int parens_not_balanced
= 0;
12496 bool in_quotes
= false;
12498 /* We've already checked that the number of left & right ()'s are
12499 equal, and that there's a matching set of double quotes. */
12500 end_op
= base_string
;
12501 for (temp_string
= op_string
; temp_string
< end_op
; temp_string
++)
12503 if (*temp_string
== '\\' && temp_string
[1] == '"')
12505 else if (*temp_string
== '"')
12506 in_quotes
= !in_quotes
;
12507 else if (!in_quotes
)
12509 if (*temp_string
== '(' && !parens_not_balanced
++)
12510 base_string
= temp_string
;
12511 if (*temp_string
== ')')
12512 --parens_not_balanced
;
12516 temp_string
= base_string
;
12518 /* Skip past '(' and whitespace. */
12519 gas_assert (*base_string
== '(');
12521 if (is_space_char (*base_string
))
12524 if (*base_string
== ','
12525 || ((i
.base_reg
= parse_register (base_string
, &end_op
))
12528 displacement_string_end
= temp_string
;
12530 i
.types
[this_operand
].bitfield
.baseindex
= 1;
12534 if (i
.base_reg
== &bad_reg
)
12536 base_string
= end_op
;
12537 if (is_space_char (*base_string
))
12541 /* There may be an index reg or scale factor here. */
12542 if (*base_string
== ',')
12545 if (is_space_char (*base_string
))
12548 if ((i
.index_reg
= parse_register (base_string
, &end_op
))
12551 if (i
.index_reg
== &bad_reg
)
12553 base_string
= end_op
;
12554 if (is_space_char (*base_string
))
12556 if (*base_string
== ',')
12559 if (is_space_char (*base_string
))
12562 else if (*base_string
!= ')')
12564 as_bad (_("expecting `,' or `)' "
12565 "after index register in `%s'"),
12570 else if (*base_string
== REGISTER_PREFIX
)
12572 end_op
= strchr (base_string
, ',');
12575 as_bad (_("bad register name `%s'"), base_string
);
12579 /* Check for scale factor. */
12580 if (*base_string
!= ')')
12582 char *end_scale
= i386_scale (base_string
);
12587 base_string
= end_scale
;
12588 if (is_space_char (*base_string
))
12590 if (*base_string
!= ')')
12592 as_bad (_("expecting `)' "
12593 "after scale factor in `%s'"),
12598 else if (!i
.index_reg
)
12600 as_bad (_("expecting index register or scale factor "
12601 "after `,'; got '%c'"),
12606 else if (*base_string
!= ')')
12608 as_bad (_("expecting `,' or `)' "
12609 "after base register in `%s'"),
12614 else if (*base_string
== REGISTER_PREFIX
)
12616 end_op
= strchr (base_string
, ',');
12619 as_bad (_("bad register name `%s'"), base_string
);
12624 /* If there's an expression beginning the operand, parse it,
12625 assuming displacement_string_start and
12626 displacement_string_end are meaningful. */
12627 if (displacement_string_start
!= displacement_string_end
)
12629 if (!i386_displacement (displacement_string_start
,
12630 displacement_string_end
))
12634 /* Special case for (%dx) while doing input/output op. */
12636 && i
.base_reg
->reg_type
.bitfield
.instance
== RegD
12637 && i
.base_reg
->reg_type
.bitfield
.word
12638 && i
.index_reg
== 0
12639 && i
.log2_scale_factor
== 0
12640 && i
.seg
[i
.mem_operands
] == 0
12641 && !operand_type_check (i
.types
[this_operand
], disp
))
12643 i
.types
[this_operand
] = i
.base_reg
->reg_type
;
12644 i
.input_output_operand
= true;
12648 if (i386_index_check (operand_string
) == 0)
12650 i
.flags
[this_operand
] |= Operand_Mem
;
12655 /* It's not a memory operand; argh! */
12656 as_bad (_("invalid char %s beginning operand %d `%s'"),
12657 output_invalid (*op_string
),
12662 return 1; /* Normal return. */
12665 /* Calculate the maximum variable size (i.e., excluding fr_fix)
12666 that an rs_machine_dependent frag may reach. */
12669 i386_frag_max_var (fragS
*frag
)
12671 /* The only relaxable frags are for jumps.
12672 Unconditional jumps can grow by 4 bytes and others by 5 bytes. */
12673 gas_assert (frag
->fr_type
== rs_machine_dependent
);
12674 return TYPE_FROM_RELAX_STATE (frag
->fr_subtype
) == UNCOND_JUMP
? 4 : 5;
12677 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
12679 elf_symbol_resolved_in_segment_p (symbolS
*fr_symbol
, offsetT fr_var
)
12681 /* STT_GNU_IFUNC symbol must go through PLT. */
12682 if ((symbol_get_bfdsym (fr_symbol
)->flags
12683 & BSF_GNU_INDIRECT_FUNCTION
) != 0)
12686 if (!S_IS_EXTERNAL (fr_symbol
))
12687 /* Symbol may be weak or local. */
12688 return !S_IS_WEAK (fr_symbol
);
12690 /* Global symbols with non-default visibility can't be preempted. */
12691 if (ELF_ST_VISIBILITY (S_GET_OTHER (fr_symbol
)) != STV_DEFAULT
)
12694 if (fr_var
!= NO_RELOC
)
12695 switch ((enum bfd_reloc_code_real
) fr_var
)
12697 case BFD_RELOC_386_PLT32
:
12698 case BFD_RELOC_X86_64_PLT32
:
12699 /* Symbol with PLT relocation may be preempted. */
12705 /* Global symbols with default visibility in a shared library may be
12706 preempted by another definition. */
12711 /* Table 3-2. Macro-Fusible Instructions in Haswell Microarchitecture
12712 Note also work for Skylake and Cascadelake.
12713 ---------------------------------------------------------------------
12714 | JCC | ADD/SUB/CMP | INC/DEC | TEST/AND |
12715 | ------ | ----------- | ------- | -------- |
12717 | Jno | N | N | Y |
12718 | Jc/Jb | Y | N | Y |
12719 | Jae/Jnb | Y | N | Y |
12720 | Je/Jz | Y | Y | Y |
12721 | Jne/Jnz | Y | Y | Y |
12722 | Jna/Jbe | Y | N | Y |
12723 | Ja/Jnbe | Y | N | Y |
12725 | Jns | N | N | Y |
12726 | Jp/Jpe | N | N | Y |
12727 | Jnp/Jpo | N | N | Y |
12728 | Jl/Jnge | Y | Y | Y |
12729 | Jge/Jnl | Y | Y | Y |
12730 | Jle/Jng | Y | Y | Y |
12731 | Jg/Jnle | Y | Y | Y |
12732 --------------------------------------------------------------------- */
12734 i386_macro_fusible_p (enum mf_cmp_kind mf_cmp
, enum mf_jcc_kind mf_jcc
)
12736 if (mf_cmp
== mf_cmp_alu_cmp
)
12737 return ((mf_jcc
>= mf_jcc_jc
&& mf_jcc
<= mf_jcc_jna
)
12738 || mf_jcc
== mf_jcc_jl
|| mf_jcc
== mf_jcc_jle
);
12739 if (mf_cmp
== mf_cmp_incdec
)
12740 return (mf_jcc
== mf_jcc_je
|| mf_jcc
== mf_jcc_jl
12741 || mf_jcc
== mf_jcc_jle
);
12742 if (mf_cmp
== mf_cmp_test_and
)
12747 /* Return the next non-empty frag. */
12750 i386_next_non_empty_frag (fragS
*fragP
)
12752 /* There may be a frag with a ".fill 0" when there is no room in
12753 the current frag for frag_grow in output_insn. */
12754 for (fragP
= fragP
->fr_next
;
12756 && fragP
->fr_type
== rs_fill
12757 && fragP
->fr_fix
== 0);
12758 fragP
= fragP
->fr_next
)
12763 /* Return the next jcc frag after BRANCH_PADDING. */
12766 i386_next_fusible_jcc_frag (fragS
*maybe_cmp_fragP
, fragS
*pad_fragP
)
12768 fragS
*branch_fragP
;
12772 if (pad_fragP
->fr_type
== rs_machine_dependent
12773 && (TYPE_FROM_RELAX_STATE (pad_fragP
->fr_subtype
)
12774 == BRANCH_PADDING
))
12776 branch_fragP
= i386_next_non_empty_frag (pad_fragP
);
12777 if (branch_fragP
->fr_type
!= rs_machine_dependent
)
12779 if (TYPE_FROM_RELAX_STATE (branch_fragP
->fr_subtype
) == COND_JUMP
12780 && i386_macro_fusible_p (maybe_cmp_fragP
->tc_frag_data
.mf_type
,
12781 pad_fragP
->tc_frag_data
.mf_type
))
12782 return branch_fragP
;
12788 /* Classify BRANCH_PADDING, BRANCH_PREFIX and FUSED_JCC_PADDING frags. */
12791 i386_classify_machine_dependent_frag (fragS
*fragP
)
12795 fragS
*branch_fragP
;
12797 unsigned int max_prefix_length
;
12799 if (fragP
->tc_frag_data
.classified
)
12802 /* First scan for BRANCH_PADDING and FUSED_JCC_PADDING. Convert
12803 FUSED_JCC_PADDING and merge BRANCH_PADDING. */
12804 for (next_fragP
= fragP
;
12805 next_fragP
!= NULL
;
12806 next_fragP
= next_fragP
->fr_next
)
12808 next_fragP
->tc_frag_data
.classified
= 1;
12809 if (next_fragP
->fr_type
== rs_machine_dependent
)
12810 switch (TYPE_FROM_RELAX_STATE (next_fragP
->fr_subtype
))
12812 case BRANCH_PADDING
:
12813 /* The BRANCH_PADDING frag must be followed by a branch
12815 branch_fragP
= i386_next_non_empty_frag (next_fragP
);
12816 next_fragP
->tc_frag_data
.u
.branch_fragP
= branch_fragP
;
12818 case FUSED_JCC_PADDING
:
12819 /* Check if this is a fused jcc:
12821 CMP like instruction
12825 cmp_fragP
= i386_next_non_empty_frag (next_fragP
);
12826 pad_fragP
= i386_next_non_empty_frag (cmp_fragP
);
12827 branch_fragP
= i386_next_fusible_jcc_frag (next_fragP
, pad_fragP
);
12830 /* The BRANCH_PADDING frag is merged with the
12831 FUSED_JCC_PADDING frag. */
12832 next_fragP
->tc_frag_data
.u
.branch_fragP
= branch_fragP
;
12833 /* CMP like instruction size. */
12834 next_fragP
->tc_frag_data
.cmp_size
= cmp_fragP
->fr_fix
;
12835 frag_wane (pad_fragP
);
12836 /* Skip to branch_fragP. */
12837 next_fragP
= branch_fragP
;
12839 else if (next_fragP
->tc_frag_data
.max_prefix_length
)
12841 /* Turn FUSED_JCC_PADDING into BRANCH_PREFIX if it isn't
12843 next_fragP
->fr_subtype
12844 = ENCODE_RELAX_STATE (BRANCH_PREFIX
, 0);
12845 next_fragP
->tc_frag_data
.max_bytes
12846 = next_fragP
->tc_frag_data
.max_prefix_length
;
12847 /* This will be updated in the BRANCH_PREFIX scan. */
12848 next_fragP
->tc_frag_data
.max_prefix_length
= 0;
12851 frag_wane (next_fragP
);
12856 /* Stop if there is no BRANCH_PREFIX. */
12857 if (!align_branch_prefix_size
)
12860 /* Scan for BRANCH_PREFIX. */
12861 for (; fragP
!= NULL
; fragP
= fragP
->fr_next
)
12863 if (fragP
->fr_type
!= rs_machine_dependent
12864 || (TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
)
12868 /* Count all BRANCH_PREFIX frags before BRANCH_PADDING and
12869 COND_JUMP_PREFIX. */
12870 max_prefix_length
= 0;
12871 for (next_fragP
= fragP
;
12872 next_fragP
!= NULL
;
12873 next_fragP
= next_fragP
->fr_next
)
12875 if (next_fragP
->fr_type
== rs_fill
)
12876 /* Skip rs_fill frags. */
12878 else if (next_fragP
->fr_type
!= rs_machine_dependent
)
12879 /* Stop for all other frags. */
12882 /* rs_machine_dependent frags. */
12883 if (TYPE_FROM_RELAX_STATE (next_fragP
->fr_subtype
)
12886 /* Count BRANCH_PREFIX frags. */
12887 if (max_prefix_length
>= MAX_FUSED_JCC_PADDING_SIZE
)
12889 max_prefix_length
= MAX_FUSED_JCC_PADDING_SIZE
;
12890 frag_wane (next_fragP
);
12894 += next_fragP
->tc_frag_data
.max_bytes
;
12896 else if ((TYPE_FROM_RELAX_STATE (next_fragP
->fr_subtype
)
12898 || (TYPE_FROM_RELAX_STATE (next_fragP
->fr_subtype
)
12899 == FUSED_JCC_PADDING
))
12901 /* Stop at BRANCH_PADDING and FUSED_JCC_PADDING. */
12902 fragP
->tc_frag_data
.u
.padding_fragP
= next_fragP
;
12906 /* Stop for other rs_machine_dependent frags. */
12910 fragP
->tc_frag_data
.max_prefix_length
= max_prefix_length
;
12912 /* Skip to the next frag. */
12913 fragP
= next_fragP
;
12917 /* Compute padding size for
12920 CMP like instruction
12922 COND_JUMP/UNCOND_JUMP
12927 COND_JUMP/UNCOND_JUMP
12931 i386_branch_padding_size (fragS
*fragP
, offsetT address
)
12933 unsigned int offset
, size
, padding_size
;
12934 fragS
*branch_fragP
= fragP
->tc_frag_data
.u
.branch_fragP
;
12936 /* The start address of the BRANCH_PADDING or FUSED_JCC_PADDING frag. */
12938 address
= fragP
->fr_address
;
12939 address
+= fragP
->fr_fix
;
12941 /* CMP like instrunction size. */
12942 size
= fragP
->tc_frag_data
.cmp_size
;
12944 /* The base size of the branch frag. */
12945 size
+= branch_fragP
->fr_fix
;
12947 /* Add opcode and displacement bytes for the rs_machine_dependent
12949 if (branch_fragP
->fr_type
== rs_machine_dependent
)
12950 size
+= md_relax_table
[branch_fragP
->fr_subtype
].rlx_length
;
12952 /* Check if branch is within boundary and doesn't end at the last
12954 offset
= address
& ((1U << align_branch_power
) - 1);
12955 if ((offset
+ size
) >= (1U << align_branch_power
))
12956 /* Padding needed to avoid crossing boundary. */
12957 padding_size
= (1U << align_branch_power
) - offset
;
12959 /* No padding needed. */
12962 /* The return value may be saved in tc_frag_data.length which is
12964 if (!fits_in_unsigned_byte (padding_size
))
12967 return padding_size
;
12970 /* i386_generic_table_relax_frag()
12972 Handle BRANCH_PADDING, BRANCH_PREFIX and FUSED_JCC_PADDING frags to
12973 grow/shrink padding to align branch frags. Hand others to
12977 i386_generic_table_relax_frag (segT segment
, fragS
*fragP
, long stretch
)
12979 if (TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) == BRANCH_PADDING
12980 || TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) == FUSED_JCC_PADDING
)
12982 long padding_size
= i386_branch_padding_size (fragP
, 0);
12983 long grow
= padding_size
- fragP
->tc_frag_data
.length
;
12985 /* When the BRANCH_PREFIX frag is used, the computed address
12986 must match the actual address and there should be no padding. */
12987 if (fragP
->tc_frag_data
.padding_address
12988 && (fragP
->tc_frag_data
.padding_address
!= fragP
->fr_address
12992 /* Update the padding size. */
12994 fragP
->tc_frag_data
.length
= padding_size
;
12998 else if (TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) == BRANCH_PREFIX
)
13000 fragS
*padding_fragP
, *next_fragP
;
13001 long padding_size
, left_size
, last_size
;
13003 padding_fragP
= fragP
->tc_frag_data
.u
.padding_fragP
;
13004 if (!padding_fragP
)
13005 /* Use the padding set by the leading BRANCH_PREFIX frag. */
13006 return (fragP
->tc_frag_data
.length
13007 - fragP
->tc_frag_data
.last_length
);
13009 /* Compute the relative address of the padding frag in the very
13010 first time where the BRANCH_PREFIX frag sizes are zero. */
13011 if (!fragP
->tc_frag_data
.padding_address
)
13012 fragP
->tc_frag_data
.padding_address
13013 = padding_fragP
->fr_address
- (fragP
->fr_address
- stretch
);
13015 /* First update the last length from the previous interation. */
13016 left_size
= fragP
->tc_frag_data
.prefix_length
;
13017 for (next_fragP
= fragP
;
13018 next_fragP
!= padding_fragP
;
13019 next_fragP
= next_fragP
->fr_next
)
13020 if (next_fragP
->fr_type
== rs_machine_dependent
13021 && (TYPE_FROM_RELAX_STATE (next_fragP
->fr_subtype
)
13026 int max
= next_fragP
->tc_frag_data
.max_bytes
;
13030 if (max
> left_size
)
13035 next_fragP
->tc_frag_data
.last_length
= size
;
13039 next_fragP
->tc_frag_data
.last_length
= 0;
13042 /* Check the padding size for the padding frag. */
13043 padding_size
= i386_branch_padding_size
13044 (padding_fragP
, (fragP
->fr_address
13045 + fragP
->tc_frag_data
.padding_address
));
13047 last_size
= fragP
->tc_frag_data
.prefix_length
;
13048 /* Check if there is change from the last interation. */
13049 if (padding_size
== last_size
)
13051 /* Update the expected address of the padding frag. */
13052 padding_fragP
->tc_frag_data
.padding_address
13053 = (fragP
->fr_address
+ padding_size
13054 + fragP
->tc_frag_data
.padding_address
);
13058 if (padding_size
> fragP
->tc_frag_data
.max_prefix_length
)
13060 /* No padding if there is no sufficient room. Clear the
13061 expected address of the padding frag. */
13062 padding_fragP
->tc_frag_data
.padding_address
= 0;
13066 /* Store the expected address of the padding frag. */
13067 padding_fragP
->tc_frag_data
.padding_address
13068 = (fragP
->fr_address
+ padding_size
13069 + fragP
->tc_frag_data
.padding_address
);
13071 fragP
->tc_frag_data
.prefix_length
= padding_size
;
13073 /* Update the length for the current interation. */
13074 left_size
= padding_size
;
13075 for (next_fragP
= fragP
;
13076 next_fragP
!= padding_fragP
;
13077 next_fragP
= next_fragP
->fr_next
)
13078 if (next_fragP
->fr_type
== rs_machine_dependent
13079 && (TYPE_FROM_RELAX_STATE (next_fragP
->fr_subtype
)
13084 int max
= next_fragP
->tc_frag_data
.max_bytes
;
13088 if (max
> left_size
)
13093 next_fragP
->tc_frag_data
.length
= size
;
13097 next_fragP
->tc_frag_data
.length
= 0;
13100 return (fragP
->tc_frag_data
.length
13101 - fragP
->tc_frag_data
.last_length
);
13103 return relax_frag (segment
, fragP
, stretch
);
13106 /* md_estimate_size_before_relax()
13108 Called just before relax() for rs_machine_dependent frags. The x86
13109 assembler uses these frags to handle variable size jump
13112 Any symbol that is now undefined will not become defined.
13113 Return the correct fr_subtype in the frag.
13114 Return the initial "guess for variable size of frag" to caller.
13115 The guess is actually the growth beyond the fixed part. Whatever
13116 we do to grow the fixed or variable part contributes to our
13120 md_estimate_size_before_relax (fragS
*fragP
, segT segment
)
13122 if (TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) == BRANCH_PADDING
13123 || TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) == BRANCH_PREFIX
13124 || TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) == FUSED_JCC_PADDING
)
13126 i386_classify_machine_dependent_frag (fragP
);
13127 return fragP
->tc_frag_data
.length
;
13130 /* We've already got fragP->fr_subtype right; all we have to do is
13131 check for un-relaxable symbols. On an ELF system, we can't relax
13132 an externally visible symbol, because it may be overridden by a
13134 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment
13135 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13137 && !elf_symbol_resolved_in_segment_p (fragP
->fr_symbol
,
13140 #if defined (OBJ_COFF) && defined (TE_PE)
13141 || (OUTPUT_FLAVOR
== bfd_target_coff_flavour
13142 && S_IS_WEAK (fragP
->fr_symbol
))
13146 /* Symbol is undefined in this segment, or we need to keep a
13147 reloc so that weak symbols can be overridden. */
13148 int size
= (fragP
->fr_subtype
& CODE16
) ? 2 : 4;
13149 enum bfd_reloc_code_real reloc_type
;
13150 unsigned char *opcode
;
13154 if (fragP
->fr_var
!= NO_RELOC
)
13155 reloc_type
= (enum bfd_reloc_code_real
) fragP
->fr_var
;
13156 else if (size
== 2)
13157 reloc_type
= BFD_RELOC_16_PCREL
;
13158 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13159 else if (fragP
->tc_frag_data
.code64
&& fragP
->fr_offset
== 0
13160 && need_plt32_p (fragP
->fr_symbol
))
13161 reloc_type
= BFD_RELOC_X86_64_PLT32
;
13164 reloc_type
= BFD_RELOC_32_PCREL
;
13166 old_fr_fix
= fragP
->fr_fix
;
13167 opcode
= (unsigned char *) fragP
->fr_opcode
;
13169 switch (TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
))
13172 /* Make jmp (0xeb) a (d)word displacement jump. */
13174 fragP
->fr_fix
+= size
;
13175 fixP
= fix_new (fragP
, old_fr_fix
, size
,
13177 fragP
->fr_offset
, 1,
13183 && (!no_cond_jump_promotion
|| fragP
->fr_var
!= NO_RELOC
))
13185 /* Negate the condition, and branch past an
13186 unconditional jump. */
13189 /* Insert an unconditional jump. */
13191 /* We added two extra opcode bytes, and have a two byte
13193 fragP
->fr_fix
+= 2 + 2;
13194 fix_new (fragP
, old_fr_fix
+ 2, 2,
13196 fragP
->fr_offset
, 1,
13200 /* Fall through. */
13203 if (no_cond_jump_promotion
&& fragP
->fr_var
== NO_RELOC
)
13205 fragP
->fr_fix
+= 1;
13206 fixP
= fix_new (fragP
, old_fr_fix
, 1,
13208 fragP
->fr_offset
, 1,
13209 BFD_RELOC_8_PCREL
);
13210 fixP
->fx_signed
= 1;
13214 /* This changes the byte-displacement jump 0x7N
13215 to the (d)word-displacement jump 0x0f,0x8N. */
13216 opcode
[1] = opcode
[0] + 0x10;
13217 opcode
[0] = TWO_BYTE_OPCODE_ESCAPE
;
13218 /* We've added an opcode byte. */
13219 fragP
->fr_fix
+= 1 + size
;
13220 fixP
= fix_new (fragP
, old_fr_fix
+ 1, size
,
13222 fragP
->fr_offset
, 1,
13227 BAD_CASE (fragP
->fr_subtype
);
13231 /* All jumps handled here are signed, but don't unconditionally use a
13232 signed limit check for 32 and 16 bit jumps as we want to allow wrap
13233 around at 4G (outside of 64-bit mode) and 64k. */
13234 if (size
== 4 && flag_code
== CODE_64BIT
)
13235 fixP
->fx_signed
= 1;
13238 return fragP
->fr_fix
- old_fr_fix
;
13241 /* Guess size depending on current relax state. Initially the relax
13242 state will correspond to a short jump and we return 1, because
13243 the variable part of the frag (the branch offset) is one byte
13244 long. However, we can relax a section more than once and in that
13245 case we must either set fr_subtype back to the unrelaxed state,
13246 or return the value for the appropriate branch. */
13247 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
13250 /* Called after relax() is finished.
13252 In: Address of frag.
13253 fr_type == rs_machine_dependent.
13254 fr_subtype is what the address relaxed to.
13256 Out: Any fixSs and constants are set up.
13257 Caller will turn frag into a ".space 0". */
13260 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, segT sec ATTRIBUTE_UNUSED
,
13263 unsigned char *opcode
;
13264 unsigned char *where_to_put_displacement
= NULL
;
13265 offsetT target_address
;
13266 offsetT opcode_address
;
13267 unsigned int extension
= 0;
13268 offsetT displacement_from_opcode_start
;
13270 if (TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) == BRANCH_PADDING
13271 || TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) == FUSED_JCC_PADDING
13272 || TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) == BRANCH_PREFIX
)
13274 /* Generate nop padding. */
13275 unsigned int size
= fragP
->tc_frag_data
.length
;
13278 if (size
> fragP
->tc_frag_data
.max_bytes
)
13284 const char *branch
= "branch";
13285 const char *prefix
= "";
13286 fragS
*padding_fragP
;
13287 if (TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
)
13290 padding_fragP
= fragP
->tc_frag_data
.u
.padding_fragP
;
13291 switch (fragP
->tc_frag_data
.default_prefix
)
13296 case CS_PREFIX_OPCODE
:
13299 case DS_PREFIX_OPCODE
:
13302 case ES_PREFIX_OPCODE
:
13305 case FS_PREFIX_OPCODE
:
13308 case GS_PREFIX_OPCODE
:
13311 case SS_PREFIX_OPCODE
:
13316 msg
= _("%s:%u: add %d%s at 0x%llx to align "
13317 "%s within %d-byte boundary\n");
13319 msg
= _("%s:%u: add additional %d%s at 0x%llx to "
13320 "align %s within %d-byte boundary\n");
13324 padding_fragP
= fragP
;
13325 msg
= _("%s:%u: add %d%s-byte nop at 0x%llx to align "
13326 "%s within %d-byte boundary\n");
13330 switch (padding_fragP
->tc_frag_data
.branch_type
)
13332 case align_branch_jcc
:
13335 case align_branch_fused
:
13336 branch
= "fused jcc";
13338 case align_branch_jmp
:
13341 case align_branch_call
:
13344 case align_branch_indirect
:
13345 branch
= "indiret branch";
13347 case align_branch_ret
:
13354 fprintf (stdout
, msg
,
13355 fragP
->fr_file
, fragP
->fr_line
, size
, prefix
,
13356 (long long) fragP
->fr_address
, branch
,
13357 1 << align_branch_power
);
13359 if (TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) == BRANCH_PREFIX
)
13360 memset (fragP
->fr_opcode
,
13361 fragP
->tc_frag_data
.default_prefix
, size
);
13363 i386_generate_nops (fragP
, (char *) fragP
->fr_opcode
,
13365 fragP
->fr_fix
+= size
;
13370 opcode
= (unsigned char *) fragP
->fr_opcode
;
13372 /* Address we want to reach in file space. */
13373 target_address
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
13375 /* Address opcode resides at in file space. */
13376 opcode_address
= fragP
->fr_address
+ fragP
->fr_fix
;
13378 /* Displacement from opcode start to fill into instruction. */
13379 displacement_from_opcode_start
= target_address
- opcode_address
;
13381 if ((fragP
->fr_subtype
& BIG
) == 0)
13383 /* Don't have to change opcode. */
13384 extension
= 1; /* 1 opcode + 1 displacement */
13385 where_to_put_displacement
= &opcode
[1];
13389 if (no_cond_jump_promotion
13390 && TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) != UNCOND_JUMP
)
13391 as_warn_where (fragP
->fr_file
, fragP
->fr_line
,
13392 _("long jump required"));
13394 switch (fragP
->fr_subtype
)
13396 case ENCODE_RELAX_STATE (UNCOND_JUMP
, BIG
):
13397 extension
= 4; /* 1 opcode + 4 displacement */
13399 where_to_put_displacement
= &opcode
[1];
13402 case ENCODE_RELAX_STATE (UNCOND_JUMP
, BIG16
):
13403 extension
= 2; /* 1 opcode + 2 displacement */
13405 where_to_put_displacement
= &opcode
[1];
13408 case ENCODE_RELAX_STATE (COND_JUMP
, BIG
):
13409 case ENCODE_RELAX_STATE (COND_JUMP86
, BIG
):
13410 extension
= 5; /* 2 opcode + 4 displacement */
13411 opcode
[1] = opcode
[0] + 0x10;
13412 opcode
[0] = TWO_BYTE_OPCODE_ESCAPE
;
13413 where_to_put_displacement
= &opcode
[2];
13416 case ENCODE_RELAX_STATE (COND_JUMP
, BIG16
):
13417 extension
= 3; /* 2 opcode + 2 displacement */
13418 opcode
[1] = opcode
[0] + 0x10;
13419 opcode
[0] = TWO_BYTE_OPCODE_ESCAPE
;
13420 where_to_put_displacement
= &opcode
[2];
13423 case ENCODE_RELAX_STATE (COND_JUMP86
, BIG16
):
13428 where_to_put_displacement
= &opcode
[3];
13432 BAD_CASE (fragP
->fr_subtype
);
13437 /* If size if less then four we are sure that the operand fits,
13438 but if it's 4, then it could be that the displacement is larger
13440 if (DISP_SIZE_FROM_RELAX_STATE (fragP
->fr_subtype
) == 4
13442 && ((addressT
) (displacement_from_opcode_start
- extension
13443 + ((addressT
) 1 << 31))
13444 > (((addressT
) 2 << 31) - 1)))
13446 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
13447 _("jump target out of range"));
13448 /* Make us emit 0. */
13449 displacement_from_opcode_start
= extension
;
13451 /* Now put displacement after opcode. */
13452 md_number_to_chars ((char *) where_to_put_displacement
,
13453 (valueT
) (displacement_from_opcode_start
- extension
),
13454 DISP_SIZE_FROM_RELAX_STATE (fragP
->fr_subtype
));
13455 fragP
->fr_fix
+= extension
;
13458 /* Apply a fixup (fixP) to segment data, once it has been determined
13459 by our caller that we have all the info we need to fix it up.
13461 Parameter valP is the pointer to the value of the bits.
13463 On the 386, immediates, displacements, and data pointers are all in
13464 the same (little-endian) format, so we don't need to care about which
13465 we are handling. */
13468 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
13470 char *p
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
13471 valueT value
= *valP
;
13473 #if !defined (TE_Mach)
13474 if (fixP
->fx_pcrel
)
13476 switch (fixP
->fx_r_type
)
13482 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
13485 case BFD_RELOC_X86_64_32S
:
13486 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
13489 fixP
->fx_r_type
= BFD_RELOC_16_PCREL
;
13492 fixP
->fx_r_type
= BFD_RELOC_8_PCREL
;
13497 if (fixP
->fx_addsy
!= NULL
13498 && (fixP
->fx_r_type
== BFD_RELOC_32_PCREL
13499 || fixP
->fx_r_type
== BFD_RELOC_64_PCREL
13500 || fixP
->fx_r_type
== BFD_RELOC_16_PCREL
13501 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
)
13502 && !use_rela_relocations
)
13504 /* This is a hack. There should be a better way to handle this.
13505 This covers for the fact that bfd_install_relocation will
13506 subtract the current location (for partial_inplace, PC relative
13507 relocations); see more below. */
13511 || OUTPUT_FLAVOR
== bfd_target_coff_flavour
13514 value
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
13516 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13519 segT sym_seg
= S_GET_SEGMENT (fixP
->fx_addsy
);
13521 if ((sym_seg
== seg
13522 || (symbol_section_p (fixP
->fx_addsy
)
13523 && sym_seg
!= absolute_section
))
13524 && !generic_force_reloc (fixP
))
13526 /* Yes, we add the values in twice. This is because
13527 bfd_install_relocation subtracts them out again. I think
13528 bfd_install_relocation is broken, but I don't dare change
13530 value
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
13534 #if defined (OBJ_COFF) && defined (TE_PE)
13535 /* For some reason, the PE format does not store a
13536 section address offset for a PC relative symbol. */
13537 if (S_GET_SEGMENT (fixP
->fx_addsy
) != seg
13538 || S_IS_WEAK (fixP
->fx_addsy
))
13539 value
+= md_pcrel_from (fixP
);
13542 #if defined (OBJ_COFF) && defined (TE_PE)
13543 if (fixP
->fx_addsy
!= NULL
13544 && S_IS_WEAK (fixP
->fx_addsy
)
13545 /* PR 16858: Do not modify weak function references. */
13546 && ! fixP
->fx_pcrel
)
13548 #if !defined (TE_PEP)
13549 /* For x86 PE weak function symbols are neither PC-relative
13550 nor do they set S_IS_FUNCTION. So the only reliable way
13551 to detect them is to check the flags of their containing
13553 if (S_GET_SEGMENT (fixP
->fx_addsy
) != NULL
13554 && S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_CODE
)
13558 value
-= S_GET_VALUE (fixP
->fx_addsy
);
13562 /* Fix a few things - the dynamic linker expects certain values here,
13563 and we must not disappoint it. */
13564 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13565 if (IS_ELF
&& fixP
->fx_addsy
)
13566 switch (fixP
->fx_r_type
)
13568 case BFD_RELOC_386_PLT32
:
13569 case BFD_RELOC_X86_64_PLT32
:
13570 /* Make the jump instruction point to the address of the operand.
13571 At runtime we merely add the offset to the actual PLT entry.
13572 NB: Subtract the offset size only for jump instructions. */
13573 if (fixP
->fx_pcrel
)
13577 case BFD_RELOC_386_TLS_GD
:
13578 case BFD_RELOC_386_TLS_LDM
:
13579 case BFD_RELOC_386_TLS_IE_32
:
13580 case BFD_RELOC_386_TLS_IE
:
13581 case BFD_RELOC_386_TLS_GOTIE
:
13582 case BFD_RELOC_386_TLS_GOTDESC
:
13583 case BFD_RELOC_X86_64_TLSGD
:
13584 case BFD_RELOC_X86_64_TLSLD
:
13585 case BFD_RELOC_X86_64_GOTTPOFF
:
13586 case BFD_RELOC_X86_64_GOTPC32_TLSDESC
:
13587 value
= 0; /* Fully resolved at runtime. No addend. */
13589 case BFD_RELOC_386_TLS_LE
:
13590 case BFD_RELOC_386_TLS_LDO_32
:
13591 case BFD_RELOC_386_TLS_LE_32
:
13592 case BFD_RELOC_X86_64_DTPOFF32
:
13593 case BFD_RELOC_X86_64_DTPOFF64
:
13594 case BFD_RELOC_X86_64_TPOFF32
:
13595 case BFD_RELOC_X86_64_TPOFF64
:
13596 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
13599 case BFD_RELOC_386_TLS_DESC_CALL
:
13600 case BFD_RELOC_X86_64_TLSDESC_CALL
:
13601 value
= 0; /* Fully resolved at runtime. No addend. */
13602 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
13606 case BFD_RELOC_VTABLE_INHERIT
:
13607 case BFD_RELOC_VTABLE_ENTRY
:
13614 #endif /* defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) */
13616 /* If not 64bit, massage value, to account for wraparound when !BFD64. */
13618 value
= extend_to_32bit_address (value
);
13621 #endif /* !defined (TE_Mach) */
13623 /* Are we finished with this relocation now? */
13624 if (fixP
->fx_addsy
== NULL
)
13627 switch (fixP
->fx_r_type
)
13629 case BFD_RELOC_X86_64_32S
:
13630 fixP
->fx_signed
= 1;
13637 #if defined (OBJ_COFF) && defined (TE_PE)
13638 else if (fixP
->fx_addsy
!= NULL
&& S_IS_WEAK (fixP
->fx_addsy
))
13641 /* Remember value for tc_gen_reloc. */
13642 fixP
->fx_addnumber
= value
;
13643 /* Clear out the frag for now. */
13647 else if (use_rela_relocations
)
13649 if (!disallow_64bit_reloc
|| fixP
->fx_r_type
== NO_RELOC
)
13650 fixP
->fx_no_overflow
= 1;
13651 /* Remember value for tc_gen_reloc. */
13652 fixP
->fx_addnumber
= value
;
13656 md_number_to_chars (p
, value
, fixP
->fx_size
);
13660 md_atof (int type
, char *litP
, int *sizeP
)
13662 /* This outputs the LITTLENUMs in REVERSE order;
13663 in accord with the bigendian 386. */
13664 return ieee_md_atof (type
, litP
, sizeP
, false);
13667 static char output_invalid_buf
[sizeof (unsigned char) * 2 + 6];
13670 output_invalid (int c
)
13673 snprintf (output_invalid_buf
, sizeof (output_invalid_buf
),
13676 snprintf (output_invalid_buf
, sizeof (output_invalid_buf
),
13677 "(0x%x)", (unsigned char) c
);
13678 return output_invalid_buf
;
13681 /* Verify that @r can be used in the current context. */
13683 static bool check_register (const reg_entry
*r
)
13685 if (allow_pseudo_reg
)
13688 if (operand_type_all_zero (&r
->reg_type
))
13691 if ((r
->reg_type
.bitfield
.dword
13692 || (r
->reg_type
.bitfield
.class == SReg
&& r
->reg_num
> 3)
13693 || r
->reg_type
.bitfield
.class == RegCR
13694 || r
->reg_type
.bitfield
.class == RegDR
)
13695 && !cpu_arch_flags
.bitfield
.cpui386
)
13698 if (r
->reg_type
.bitfield
.class == RegTR
13699 && (flag_code
== CODE_64BIT
13700 || !cpu_arch_flags
.bitfield
.cpui386
13701 || cpu_arch_isa_flags
.bitfield
.cpui586
13702 || cpu_arch_isa_flags
.bitfield
.cpui686
))
13705 if (r
->reg_type
.bitfield
.class == RegMMX
&& !cpu_arch_flags
.bitfield
.cpummx
)
13708 if (!cpu_arch_flags
.bitfield
.cpuavx512f
)
13710 if (r
->reg_type
.bitfield
.zmmword
13711 || r
->reg_type
.bitfield
.class == RegMask
)
13714 if (!cpu_arch_flags
.bitfield
.cpuavx
)
13716 if (r
->reg_type
.bitfield
.ymmword
)
13719 if (!cpu_arch_flags
.bitfield
.cpusse
&& r
->reg_type
.bitfield
.xmmword
)
13724 if (r
->reg_type
.bitfield
.tmmword
13725 && (!cpu_arch_flags
.bitfield
.cpuamx_tile
13726 || flag_code
!= CODE_64BIT
))
13729 if (r
->reg_type
.bitfield
.class == RegBND
&& !cpu_arch_flags
.bitfield
.cpumpx
)
13732 /* Don't allow fake index register unless allow_index_reg isn't 0. */
13733 if (!allow_index_reg
&& r
->reg_num
== RegIZ
)
13736 /* Upper 16 vector registers are only available with VREX in 64bit
13737 mode, and require EVEX encoding. */
13738 if (r
->reg_flags
& RegVRex
)
13740 if (!cpu_arch_flags
.bitfield
.cpuavx512f
13741 || flag_code
!= CODE_64BIT
)
13744 if (i
.vec_encoding
== vex_encoding_default
)
13745 i
.vec_encoding
= vex_encoding_evex
;
13746 else if (i
.vec_encoding
!= vex_encoding_evex
)
13747 i
.vec_encoding
= vex_encoding_error
;
13750 if (((r
->reg_flags
& (RegRex64
| RegRex
)) || r
->reg_type
.bitfield
.qword
)
13751 && (!cpu_arch_flags
.bitfield
.cpulm
13752 || r
->reg_type
.bitfield
.class != RegCR
13754 && flag_code
!= CODE_64BIT
)
13757 if (r
->reg_type
.bitfield
.class == SReg
&& r
->reg_num
== RegFlat
13764 /* REG_STRING starts *before* REGISTER_PREFIX. */
13766 static const reg_entry
*
13767 parse_real_register (const char *reg_string
, char **end_op
)
13769 const char *s
= reg_string
;
13771 char reg_name_given
[MAX_REG_NAME_SIZE
+ 1];
13772 const reg_entry
*r
;
13774 /* Skip possible REGISTER_PREFIX and possible whitespace. */
13775 if (*s
== REGISTER_PREFIX
)
13778 if (is_space_char (*s
))
13781 p
= reg_name_given
;
13782 while ((*p
++ = register_chars
[(unsigned char) *s
]) != '\0')
13784 if (p
>= reg_name_given
+ MAX_REG_NAME_SIZE
)
13785 return (const reg_entry
*) NULL
;
13789 if (is_part_of_name (*s
))
13790 return (const reg_entry
*) NULL
;
13792 *end_op
= (char *) s
;
13794 r
= (const reg_entry
*) str_hash_find (reg_hash
, reg_name_given
);
13796 /* Handle floating point regs, allowing spaces in the (i) part. */
13799 if (!cpu_arch_flags
.bitfield
.cpu8087
13800 && !cpu_arch_flags
.bitfield
.cpu287
13801 && !cpu_arch_flags
.bitfield
.cpu387
13802 && !allow_pseudo_reg
)
13803 return (const reg_entry
*) NULL
;
13805 if (is_space_char (*s
))
13810 if (is_space_char (*s
))
13812 if (*s
>= '0' && *s
<= '7')
13814 int fpr
= *s
- '0';
13816 if (is_space_char (*s
))
13820 *end_op
= (char *) s
+ 1;
13821 know (r
[fpr
].reg_num
== fpr
);
13825 /* We have "%st(" then garbage. */
13826 return (const reg_entry
*) NULL
;
13830 return r
&& check_register (r
) ? r
: NULL
;
13833 /* REG_STRING starts *before* REGISTER_PREFIX. */
13835 static const reg_entry
*
13836 parse_register (const char *reg_string
, char **end_op
)
13838 const reg_entry
*r
;
13840 if (*reg_string
== REGISTER_PREFIX
|| allow_naked_reg
)
13841 r
= parse_real_register (reg_string
, end_op
);
13846 char *save
= input_line_pointer
;
13847 char *buf
= xstrdup (reg_string
), *name
;
13850 input_line_pointer
= buf
;
13851 get_symbol_name (&name
);
13852 symbolP
= symbol_find (name
);
13853 while (symbolP
&& symbol_equated_p (symbolP
))
13855 const expressionS
*e
= symbol_get_value_expression(symbolP
);
13857 if (e
->X_add_number
)
13859 symbolP
= e
->X_add_symbol
;
13861 if (symbolP
&& S_GET_SEGMENT (symbolP
) == reg_section
)
13863 const expressionS
*e
= symbol_get_value_expression (symbolP
);
13865 if (e
->X_op
== O_register
)
13867 know (e
->X_add_number
>= 0
13868 && (valueT
) e
->X_add_number
< i386_regtab_size
);
13869 r
= i386_regtab
+ e
->X_add_number
;
13870 *end_op
= (char *) reg_string
+ (input_line_pointer
- buf
);
13872 if (r
&& !check_register (r
))
13874 as_bad (_("register '%s%s' cannot be used here"),
13875 register_prefix
, r
->reg_name
);
13879 input_line_pointer
= save
;
13886 i386_parse_name (char *name
, expressionS
*e
, char *nextcharP
)
13888 const reg_entry
*r
= NULL
;
13889 char *end
= input_line_pointer
;
13891 /* We only know the terminating character here. It being double quote could
13892 be the closing one of a quoted symbol name, or an opening one from a
13893 following string (or another quoted symbol name). Since the latter can't
13894 be valid syntax for anything, bailing in either case is good enough. */
13895 if (*nextcharP
== '"')
13899 if (*name
== REGISTER_PREFIX
|| allow_naked_reg
)
13900 r
= parse_real_register (name
, &input_line_pointer
);
13901 if (r
&& end
<= input_line_pointer
)
13903 *nextcharP
= *input_line_pointer
;
13904 *input_line_pointer
= 0;
13905 e
->X_op
= O_register
;
13906 e
->X_add_number
= r
- i386_regtab
;
13909 input_line_pointer
= end
;
13911 return intel_syntax
? i386_intel_parse_name (name
, e
) : 0;
13915 md_operand (expressionS
*e
)
13918 const reg_entry
*r
;
13920 switch (*input_line_pointer
)
13922 case REGISTER_PREFIX
:
13923 r
= parse_real_register (input_line_pointer
, &end
);
13926 e
->X_op
= O_register
;
13927 e
->X_add_number
= r
- i386_regtab
;
13928 input_line_pointer
= end
;
13933 gas_assert (intel_syntax
);
13934 end
= input_line_pointer
++;
13936 if (*input_line_pointer
== ']')
13938 ++input_line_pointer
;
13939 e
->X_op_symbol
= make_expr_symbol (e
);
13940 e
->X_add_symbol
= NULL
;
13941 e
->X_add_number
= 0;
13946 e
->X_op
= O_absent
;
13947 input_line_pointer
= end
;
13954 /* To maintain consistency with !BFD64 builds of gas record, whether any
13955 (binary) operator was involved in an expression. As expressions are
13956 evaluated in only 32 bits when !BFD64, we use this to decide whether to
13957 truncate results. */
13958 bool i386_record_operator (operatorT op
,
13959 const expressionS
*left
,
13960 const expressionS
*right
)
13962 if (op
== O_absent
)
13967 /* Since the expression parser applies unary operators fine to bignum
13968 operands, we don't need to be concerned of respective operands not
13969 fitting in 32 bits. */
13970 if (right
->X_op
== O_constant
&& right
->X_unsigned
13971 && !fits_in_unsigned_long (right
->X_add_number
))
13974 /* This isn't entirely right: The pattern can also result when constant
13975 expressions are folded (e.g. 0xffffffff + 1). */
13976 else if ((left
->X_op
== O_constant
&& left
->X_unsigned
13977 && !fits_in_unsigned_long (left
->X_add_number
))
13978 || (right
->X_op
== O_constant
&& right
->X_unsigned
13979 && !fits_in_unsigned_long (right
->X_add_number
)))
13980 expr_mode
= expr_large_value
;
13982 if (expr_mode
!= expr_large_value
)
13983 expr_mode
= expr_operator_present
;
13989 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
13990 const char *md_shortopts
= "kVQ:sqnO::";
13992 const char *md_shortopts
= "qnO::";
13995 #define OPTION_32 (OPTION_MD_BASE + 0)
13996 #define OPTION_64 (OPTION_MD_BASE + 1)
13997 #define OPTION_DIVIDE (OPTION_MD_BASE + 2)
13998 #define OPTION_MARCH (OPTION_MD_BASE + 3)
13999 #define OPTION_MTUNE (OPTION_MD_BASE + 4)
14000 #define OPTION_MMNEMONIC (OPTION_MD_BASE + 5)
14001 #define OPTION_MSYNTAX (OPTION_MD_BASE + 6)
14002 #define OPTION_MINDEX_REG (OPTION_MD_BASE + 7)
14003 #define OPTION_MNAKED_REG (OPTION_MD_BASE + 8)
14004 #define OPTION_MRELAX_RELOCATIONS (OPTION_MD_BASE + 9)
14005 #define OPTION_MSSE2AVX (OPTION_MD_BASE + 10)
14006 #define OPTION_MSSE_CHECK (OPTION_MD_BASE + 11)
14007 #define OPTION_MOPERAND_CHECK (OPTION_MD_BASE + 12)
14008 #define OPTION_MAVXSCALAR (OPTION_MD_BASE + 13)
14009 #define OPTION_X32 (OPTION_MD_BASE + 14)
14010 #define OPTION_MADD_BND_PREFIX (OPTION_MD_BASE + 15)
14011 #define OPTION_MEVEXLIG (OPTION_MD_BASE + 16)
14012 #define OPTION_MEVEXWIG (OPTION_MD_BASE + 17)
14013 #define OPTION_MBIG_OBJ (OPTION_MD_BASE + 18)
14014 #define OPTION_MOMIT_LOCK_PREFIX (OPTION_MD_BASE + 19)
14015 #define OPTION_MEVEXRCIG (OPTION_MD_BASE + 20)
14016 #define OPTION_MSHARED (OPTION_MD_BASE + 21)
14017 #define OPTION_MAMD64 (OPTION_MD_BASE + 22)
14018 #define OPTION_MINTEL64 (OPTION_MD_BASE + 23)
14019 #define OPTION_MFENCE_AS_LOCK_ADD (OPTION_MD_BASE + 24)
14020 #define OPTION_X86_USED_NOTE (OPTION_MD_BASE + 25)
14021 #define OPTION_MVEXWIG (OPTION_MD_BASE + 26)
14022 #define OPTION_MALIGN_BRANCH_BOUNDARY (OPTION_MD_BASE + 27)
14023 #define OPTION_MALIGN_BRANCH_PREFIX_SIZE (OPTION_MD_BASE + 28)
14024 #define OPTION_MALIGN_BRANCH (OPTION_MD_BASE + 29)
14025 #define OPTION_MBRANCHES_WITH_32B_BOUNDARIES (OPTION_MD_BASE + 30)
14026 #define OPTION_MLFENCE_AFTER_LOAD (OPTION_MD_BASE + 31)
14027 #define OPTION_MLFENCE_BEFORE_INDIRECT_BRANCH (OPTION_MD_BASE + 32)
14028 #define OPTION_MLFENCE_BEFORE_RET (OPTION_MD_BASE + 33)
14029 #define OPTION_MUSE_UNALIGNED_VECTOR_MOVE (OPTION_MD_BASE + 34)
14031 struct option md_longopts
[] =
14033 {"32", no_argument
, NULL
, OPTION_32
},
14034 #if (defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \
14035 || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O))
14036 {"64", no_argument
, NULL
, OPTION_64
},
14038 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14039 {"x32", no_argument
, NULL
, OPTION_X32
},
14040 {"mshared", no_argument
, NULL
, OPTION_MSHARED
},
14041 {"mx86-used-note", required_argument
, NULL
, OPTION_X86_USED_NOTE
},
14043 {"divide", no_argument
, NULL
, OPTION_DIVIDE
},
14044 {"march", required_argument
, NULL
, OPTION_MARCH
},
14045 {"mtune", required_argument
, NULL
, OPTION_MTUNE
},
14046 {"mmnemonic", required_argument
, NULL
, OPTION_MMNEMONIC
},
14047 {"msyntax", required_argument
, NULL
, OPTION_MSYNTAX
},
14048 {"mindex-reg", no_argument
, NULL
, OPTION_MINDEX_REG
},
14049 {"mnaked-reg", no_argument
, NULL
, OPTION_MNAKED_REG
},
14050 {"msse2avx", no_argument
, NULL
, OPTION_MSSE2AVX
},
14051 {"muse-unaligned-vector-move", no_argument
, NULL
, OPTION_MUSE_UNALIGNED_VECTOR_MOVE
},
14052 {"msse-check", required_argument
, NULL
, OPTION_MSSE_CHECK
},
14053 {"moperand-check", required_argument
, NULL
, OPTION_MOPERAND_CHECK
},
14054 {"mavxscalar", required_argument
, NULL
, OPTION_MAVXSCALAR
},
14055 {"mvexwig", required_argument
, NULL
, OPTION_MVEXWIG
},
14056 {"madd-bnd-prefix", no_argument
, NULL
, OPTION_MADD_BND_PREFIX
},
14057 {"mevexlig", required_argument
, NULL
, OPTION_MEVEXLIG
},
14058 {"mevexwig", required_argument
, NULL
, OPTION_MEVEXWIG
},
14059 # if defined (TE_PE) || defined (TE_PEP)
14060 {"mbig-obj", no_argument
, NULL
, OPTION_MBIG_OBJ
},
14062 {"momit-lock-prefix", required_argument
, NULL
, OPTION_MOMIT_LOCK_PREFIX
},
14063 {"mfence-as-lock-add", required_argument
, NULL
, OPTION_MFENCE_AS_LOCK_ADD
},
14064 {"mrelax-relocations", required_argument
, NULL
, OPTION_MRELAX_RELOCATIONS
},
14065 {"mevexrcig", required_argument
, NULL
, OPTION_MEVEXRCIG
},
14066 {"malign-branch-boundary", required_argument
, NULL
, OPTION_MALIGN_BRANCH_BOUNDARY
},
14067 {"malign-branch-prefix-size", required_argument
, NULL
, OPTION_MALIGN_BRANCH_PREFIX_SIZE
},
14068 {"malign-branch", required_argument
, NULL
, OPTION_MALIGN_BRANCH
},
14069 {"mbranches-within-32B-boundaries", no_argument
, NULL
, OPTION_MBRANCHES_WITH_32B_BOUNDARIES
},
14070 {"mlfence-after-load", required_argument
, NULL
, OPTION_MLFENCE_AFTER_LOAD
},
14071 {"mlfence-before-indirect-branch", required_argument
, NULL
,
14072 OPTION_MLFENCE_BEFORE_INDIRECT_BRANCH
},
14073 {"mlfence-before-ret", required_argument
, NULL
, OPTION_MLFENCE_BEFORE_RET
},
14074 {"mamd64", no_argument
, NULL
, OPTION_MAMD64
},
14075 {"mintel64", no_argument
, NULL
, OPTION_MINTEL64
},
14076 {NULL
, no_argument
, NULL
, 0}
14078 size_t md_longopts_size
= sizeof (md_longopts
);
14081 md_parse_option (int c
, const char *arg
)
14084 char *arch
, *next
, *saved
, *type
;
14089 optimize_align_code
= 0;
14093 quiet_warnings
= 1;
14096 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14097 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
14098 should be emitted or not. FIXME: Not implemented. */
14100 if ((arg
[0] != 'y' && arg
[0] != 'n') || arg
[1])
14104 /* -V: SVR4 argument to print version ID. */
14106 print_version_id ();
14109 /* -k: Ignore for FreeBSD compatibility. */
14114 /* -s: On i386 Solaris, this tells the native assembler to use
14115 .stab instead of .stab.excl. We always use .stab anyhow. */
14118 case OPTION_MSHARED
:
14122 case OPTION_X86_USED_NOTE
:
14123 if (strcasecmp (arg
, "yes") == 0)
14125 else if (strcasecmp (arg
, "no") == 0)
14128 as_fatal (_("invalid -mx86-used-note= option: `%s'"), arg
);
14133 #if (defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \
14134 || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O))
14137 const char **list
, **l
;
14139 list
= bfd_target_list ();
14140 for (l
= list
; *l
!= NULL
; l
++)
14141 if (startswith (*l
, "elf64-x86-64")
14142 || strcmp (*l
, "coff-x86-64") == 0
14143 || strcmp (*l
, "pe-x86-64") == 0
14144 || strcmp (*l
, "pei-x86-64") == 0
14145 || strcmp (*l
, "mach-o-x86-64") == 0)
14147 default_arch
= "x86_64";
14151 as_fatal (_("no compiled in support for x86_64"));
14157 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14161 const char **list
, **l
;
14163 list
= bfd_target_list ();
14164 for (l
= list
; *l
!= NULL
; l
++)
14165 if (startswith (*l
, "elf32-x86-64"))
14167 default_arch
= "x86_64:32";
14171 as_fatal (_("no compiled in support for 32bit x86_64"));
14175 as_fatal (_("32bit x86_64 is only supported for ELF"));
14181 const char **list
, **l
;
14183 list
= bfd_target_list ();
14184 for (l
= list
; *l
!= NULL
; l
++)
14185 if (strstr (*l
, "-i386")
14186 || strstr (*l
, "-go32"))
14188 default_arch
= "i386";
14192 as_fatal (_("no compiled in support for ix86"));
14197 case OPTION_DIVIDE
:
14198 #ifdef SVR4_COMMENT_CHARS
14203 n
= XNEWVEC (char, strlen (i386_comment_chars
) + 1);
14205 for (s
= i386_comment_chars
; *s
!= '\0'; s
++)
14209 i386_comment_chars
= n
;
14215 saved
= xstrdup (arg
);
14217 /* Allow -march=+nosse. */
14223 as_fatal (_("invalid -march= option: `%s'"), arg
);
14224 next
= strchr (arch
, '+');
14227 for (j
= 0; j
< ARRAY_SIZE (cpu_arch
); j
++)
14229 if (arch
== saved
&& cpu_arch
[j
].type
!= PROCESSOR_NONE
14230 && strcmp (arch
, cpu_arch
[j
].name
) == 0)
14233 if (! cpu_arch
[j
].enable
.bitfield
.cpui386
)
14236 cpu_arch_name
= cpu_arch
[j
].name
;
14237 free (cpu_sub_arch_name
);
14238 cpu_sub_arch_name
= NULL
;
14239 cpu_arch_flags
= cpu_arch
[j
].enable
;
14240 cpu_arch_isa
= cpu_arch
[j
].type
;
14241 cpu_arch_isa_flags
= cpu_arch
[j
].enable
;
14242 if (!cpu_arch_tune_set
)
14244 cpu_arch_tune
= cpu_arch_isa
;
14245 cpu_arch_tune_flags
= cpu_arch_isa_flags
;
14249 else if (cpu_arch
[j
].type
== PROCESSOR_NONE
14250 && strcmp (arch
, cpu_arch
[j
].name
) == 0
14251 && !cpu_flags_all_zero (&cpu_arch
[j
].enable
))
14253 /* ISA extension. */
14254 i386_cpu_flags flags
;
14256 flags
= cpu_flags_or (cpu_arch_flags
,
14257 cpu_arch
[j
].enable
);
14259 if (!cpu_flags_equal (&flags
, &cpu_arch_flags
))
14261 extend_cpu_sub_arch_name (arch
);
14262 cpu_arch_flags
= flags
;
14263 cpu_arch_isa_flags
= flags
;
14267 = cpu_flags_or (cpu_arch_isa_flags
,
14268 cpu_arch
[j
].enable
);
14273 if (j
>= ARRAY_SIZE (cpu_arch
) && startswith (arch
, "no"))
14275 /* Disable an ISA extension. */
14276 for (j
= 0; j
< ARRAY_SIZE (cpu_arch
); j
++)
14277 if (cpu_arch
[j
].type
== PROCESSOR_NONE
14278 && strcmp (arch
+ 2, cpu_arch
[j
].name
) == 0)
14280 i386_cpu_flags flags
;
14282 flags
= cpu_flags_and_not (cpu_arch_flags
,
14283 cpu_arch
[j
].disable
);
14284 if (!cpu_flags_equal (&flags
, &cpu_arch_flags
))
14286 extend_cpu_sub_arch_name (arch
);
14287 cpu_arch_flags
= flags
;
14288 cpu_arch_isa_flags
= flags
;
14294 if (j
>= ARRAY_SIZE (cpu_arch
))
14295 as_fatal (_("invalid -march= option: `%s'"), arg
);
14299 while (next
!= NULL
);
14305 as_fatal (_("invalid -mtune= option: `%s'"), arg
);
14306 for (j
= 0; j
< ARRAY_SIZE (cpu_arch
); j
++)
14308 if (cpu_arch
[j
].type
!= PROCESSOR_NONE
14309 && strcmp (arg
, cpu_arch
[j
].name
) == 0)
14311 cpu_arch_tune_set
= 1;
14312 cpu_arch_tune
= cpu_arch
[j
].type
;
14313 cpu_arch_tune_flags
= cpu_arch
[j
].enable
;
14317 if (j
>= ARRAY_SIZE (cpu_arch
))
14318 as_fatal (_("invalid -mtune= option: `%s'"), arg
);
14321 case OPTION_MMNEMONIC
:
14322 if (strcasecmp (arg
, "att") == 0)
14323 intel_mnemonic
= 0;
14324 else if (strcasecmp (arg
, "intel") == 0)
14325 intel_mnemonic
= 1;
14327 as_fatal (_("invalid -mmnemonic= option: `%s'"), arg
);
14330 case OPTION_MSYNTAX
:
14331 if (strcasecmp (arg
, "att") == 0)
14333 else if (strcasecmp (arg
, "intel") == 0)
14336 as_fatal (_("invalid -msyntax= option: `%s'"), arg
);
14339 case OPTION_MINDEX_REG
:
14340 allow_index_reg
= 1;
14343 case OPTION_MNAKED_REG
:
14344 allow_naked_reg
= 1;
14347 case OPTION_MSSE2AVX
:
14351 case OPTION_MUSE_UNALIGNED_VECTOR_MOVE
:
14352 use_unaligned_vector_move
= 1;
14355 case OPTION_MSSE_CHECK
:
14356 if (strcasecmp (arg
, "error") == 0)
14357 sse_check
= check_error
;
14358 else if (strcasecmp (arg
, "warning") == 0)
14359 sse_check
= check_warning
;
14360 else if (strcasecmp (arg
, "none") == 0)
14361 sse_check
= check_none
;
14363 as_fatal (_("invalid -msse-check= option: `%s'"), arg
);
14366 case OPTION_MOPERAND_CHECK
:
14367 if (strcasecmp (arg
, "error") == 0)
14368 operand_check
= check_error
;
14369 else if (strcasecmp (arg
, "warning") == 0)
14370 operand_check
= check_warning
;
14371 else if (strcasecmp (arg
, "none") == 0)
14372 operand_check
= check_none
;
14374 as_fatal (_("invalid -moperand-check= option: `%s'"), arg
);
14377 case OPTION_MAVXSCALAR
:
14378 if (strcasecmp (arg
, "128") == 0)
14379 avxscalar
= vex128
;
14380 else if (strcasecmp (arg
, "256") == 0)
14381 avxscalar
= vex256
;
14383 as_fatal (_("invalid -mavxscalar= option: `%s'"), arg
);
14386 case OPTION_MVEXWIG
:
14387 if (strcmp (arg
, "0") == 0)
14389 else if (strcmp (arg
, "1") == 0)
14392 as_fatal (_("invalid -mvexwig= option: `%s'"), arg
);
14395 case OPTION_MADD_BND_PREFIX
:
14396 add_bnd_prefix
= 1;
14399 case OPTION_MEVEXLIG
:
14400 if (strcmp (arg
, "128") == 0)
14401 evexlig
= evexl128
;
14402 else if (strcmp (arg
, "256") == 0)
14403 evexlig
= evexl256
;
14404 else if (strcmp (arg
, "512") == 0)
14405 evexlig
= evexl512
;
14407 as_fatal (_("invalid -mevexlig= option: `%s'"), arg
);
14410 case OPTION_MEVEXRCIG
:
14411 if (strcmp (arg
, "rne") == 0)
14413 else if (strcmp (arg
, "rd") == 0)
14415 else if (strcmp (arg
, "ru") == 0)
14417 else if (strcmp (arg
, "rz") == 0)
14420 as_fatal (_("invalid -mevexrcig= option: `%s'"), arg
);
14423 case OPTION_MEVEXWIG
:
14424 if (strcmp (arg
, "0") == 0)
14426 else if (strcmp (arg
, "1") == 0)
14429 as_fatal (_("invalid -mevexwig= option: `%s'"), arg
);
14432 # if defined (TE_PE) || defined (TE_PEP)
14433 case OPTION_MBIG_OBJ
:
14438 case OPTION_MOMIT_LOCK_PREFIX
:
14439 if (strcasecmp (arg
, "yes") == 0)
14440 omit_lock_prefix
= 1;
14441 else if (strcasecmp (arg
, "no") == 0)
14442 omit_lock_prefix
= 0;
14444 as_fatal (_("invalid -momit-lock-prefix= option: `%s'"), arg
);
14447 case OPTION_MFENCE_AS_LOCK_ADD
:
14448 if (strcasecmp (arg
, "yes") == 0)
14450 else if (strcasecmp (arg
, "no") == 0)
14453 as_fatal (_("invalid -mfence-as-lock-add= option: `%s'"), arg
);
14456 case OPTION_MLFENCE_AFTER_LOAD
:
14457 if (strcasecmp (arg
, "yes") == 0)
14458 lfence_after_load
= 1;
14459 else if (strcasecmp (arg
, "no") == 0)
14460 lfence_after_load
= 0;
14462 as_fatal (_("invalid -mlfence-after-load= option: `%s'"), arg
);
14465 case OPTION_MLFENCE_BEFORE_INDIRECT_BRANCH
:
14466 if (strcasecmp (arg
, "all") == 0)
14468 lfence_before_indirect_branch
= lfence_branch_all
;
14469 if (lfence_before_ret
== lfence_before_ret_none
)
14470 lfence_before_ret
= lfence_before_ret_shl
;
14472 else if (strcasecmp (arg
, "memory") == 0)
14473 lfence_before_indirect_branch
= lfence_branch_memory
;
14474 else if (strcasecmp (arg
, "register") == 0)
14475 lfence_before_indirect_branch
= lfence_branch_register
;
14476 else if (strcasecmp (arg
, "none") == 0)
14477 lfence_before_indirect_branch
= lfence_branch_none
;
14479 as_fatal (_("invalid -mlfence-before-indirect-branch= option: `%s'"),
14483 case OPTION_MLFENCE_BEFORE_RET
:
14484 if (strcasecmp (arg
, "or") == 0)
14485 lfence_before_ret
= lfence_before_ret_or
;
14486 else if (strcasecmp (arg
, "not") == 0)
14487 lfence_before_ret
= lfence_before_ret_not
;
14488 else if (strcasecmp (arg
, "shl") == 0 || strcasecmp (arg
, "yes") == 0)
14489 lfence_before_ret
= lfence_before_ret_shl
;
14490 else if (strcasecmp (arg
, "none") == 0)
14491 lfence_before_ret
= lfence_before_ret_none
;
14493 as_fatal (_("invalid -mlfence-before-ret= option: `%s'"),
14497 case OPTION_MRELAX_RELOCATIONS
:
14498 if (strcasecmp (arg
, "yes") == 0)
14499 generate_relax_relocations
= 1;
14500 else if (strcasecmp (arg
, "no") == 0)
14501 generate_relax_relocations
= 0;
14503 as_fatal (_("invalid -mrelax-relocations= option: `%s'"), arg
);
14506 case OPTION_MALIGN_BRANCH_BOUNDARY
:
14509 long int align
= strtoul (arg
, &end
, 0);
14514 align_branch_power
= 0;
14517 else if (align
>= 16)
14520 for (align_power
= 0;
14522 align
>>= 1, align_power
++)
14524 /* Limit alignment power to 31. */
14525 if (align
== 1 && align_power
< 32)
14527 align_branch_power
= align_power
;
14532 as_fatal (_("invalid -malign-branch-boundary= value: %s"), arg
);
14536 case OPTION_MALIGN_BRANCH_PREFIX_SIZE
:
14539 int align
= strtoul (arg
, &end
, 0);
14540 /* Some processors only support 5 prefixes. */
14541 if (*end
== '\0' && align
>= 0 && align
< 6)
14543 align_branch_prefix_size
= align
;
14546 as_fatal (_("invalid -malign-branch-prefix-size= value: %s"),
14551 case OPTION_MALIGN_BRANCH
:
14553 saved
= xstrdup (arg
);
14557 next
= strchr (type
, '+');
14560 if (strcasecmp (type
, "jcc") == 0)
14561 align_branch
|= align_branch_jcc_bit
;
14562 else if (strcasecmp (type
, "fused") == 0)
14563 align_branch
|= align_branch_fused_bit
;
14564 else if (strcasecmp (type
, "jmp") == 0)
14565 align_branch
|= align_branch_jmp_bit
;
14566 else if (strcasecmp (type
, "call") == 0)
14567 align_branch
|= align_branch_call_bit
;
14568 else if (strcasecmp (type
, "ret") == 0)
14569 align_branch
|= align_branch_ret_bit
;
14570 else if (strcasecmp (type
, "indirect") == 0)
14571 align_branch
|= align_branch_indirect_bit
;
14573 as_fatal (_("invalid -malign-branch= option: `%s'"), arg
);
14576 while (next
!= NULL
);
14580 case OPTION_MBRANCHES_WITH_32B_BOUNDARIES
:
14581 align_branch_power
= 5;
14582 align_branch_prefix_size
= 5;
14583 align_branch
= (align_branch_jcc_bit
14584 | align_branch_fused_bit
14585 | align_branch_jmp_bit
);
14588 case OPTION_MAMD64
:
14592 case OPTION_MINTEL64
:
14600 /* Turn off -Os. */
14601 optimize_for_space
= 0;
14603 else if (*arg
== 's')
14605 optimize_for_space
= 1;
14606 /* Turn on all encoding optimizations. */
14607 optimize
= INT_MAX
;
14611 optimize
= atoi (arg
);
14612 /* Turn off -Os. */
14613 optimize_for_space
= 0;
14623 #define MESSAGE_TEMPLATE \
14627 output_message (FILE *stream
, char *p
, char *message
, char *start
,
14628 int *left_p
, const char *name
, int len
)
14630 int size
= sizeof (MESSAGE_TEMPLATE
);
14631 int left
= *left_p
;
14633 /* Reserve 2 spaces for ", " or ",\0" */
14636 /* Check if there is any room. */
14644 p
= mempcpy (p
, name
, len
);
14648 /* Output the current message now and start a new one. */
14651 fprintf (stream
, "%s\n", message
);
14653 left
= size
- (start
- message
) - len
- 2;
14655 gas_assert (left
>= 0);
14657 p
= mempcpy (p
, name
, len
);
14665 show_arch (FILE *stream
, int ext
, int check
)
14667 static char message
[] = MESSAGE_TEMPLATE
;
14668 char *start
= message
+ 27;
14670 int size
= sizeof (MESSAGE_TEMPLATE
);
14677 left
= size
- (start
- message
);
14681 p
= output_message (stream
, p
, message
, start
, &left
,
14682 STRING_COMMA_LEN ("default"));
14683 p
= output_message (stream
, p
, message
, start
, &left
,
14684 STRING_COMMA_LEN ("push"));
14685 p
= output_message (stream
, p
, message
, start
, &left
,
14686 STRING_COMMA_LEN ("pop"));
14689 for (j
= 0; j
< ARRAY_SIZE (cpu_arch
); j
++)
14691 /* Should it be skipped? */
14692 if (cpu_arch
[j
].skip
)
14695 name
= cpu_arch
[j
].name
;
14696 len
= cpu_arch
[j
].len
;
14697 if (cpu_arch
[j
].type
== PROCESSOR_NONE
)
14699 /* It is an extension. Skip if we aren't asked to show it. */
14700 if (!ext
|| cpu_flags_all_zero (&cpu_arch
[j
].enable
))
14705 /* It is an processor. Skip if we show only extension. */
14708 else if (check
&& ! cpu_arch
[j
].enable
.bitfield
.cpui386
)
14710 /* It is an impossible processor - skip. */
14714 p
= output_message (stream
, p
, message
, start
, &left
, name
, len
);
14717 /* Display disabled extensions. */
14719 for (j
= 0; j
< ARRAY_SIZE (cpu_arch
); j
++)
14723 if (cpu_arch
[j
].type
!= PROCESSOR_NONE
14724 || !cpu_flags_all_zero (&cpu_arch
[j
].enable
))
14726 str
= xasprintf ("no%s", cpu_arch
[j
].name
);
14727 p
= output_message (stream
, p
, message
, start
, &left
, str
,
14733 fprintf (stream
, "%s\n", message
);
14737 md_show_usage (FILE *stream
)
14739 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14740 fprintf (stream
, _("\
14741 -Qy, -Qn ignored\n\
14742 -V print assembler version number\n\
14745 fprintf (stream
, _("\
14746 -n do not optimize code alignment\n\
14747 -O{012s} attempt some code optimizations\n\
14748 -q quieten some warnings\n"));
14749 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14750 fprintf (stream
, _("\
14754 # if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14755 fprintf (stream
, _("\
14756 --32/--64/--x32 generate 32bit/64bit/x32 object\n"));
14757 # elif defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O)
14758 fprintf (stream
, _("\
14759 --32/--64 generate 32bit/64bit object\n"));
14762 #ifdef SVR4_COMMENT_CHARS
14763 fprintf (stream
, _("\
14764 --divide do not treat `/' as a comment character\n"));
14766 fprintf (stream
, _("\
14767 --divide ignored\n"));
14769 fprintf (stream
, _("\
14770 -march=CPU[,+EXTENSION...]\n\
14771 generate code for CPU and EXTENSION, CPU is one of:\n"));
14772 show_arch (stream
, 0, 1);
14773 fprintf (stream
, _("\
14774 EXTENSION is combination of (possibly \"no\"-prefixed):\n"));
14775 show_arch (stream
, 1, 0);
14776 fprintf (stream
, _("\
14777 -mtune=CPU optimize for CPU, CPU is one of:\n"));
14778 show_arch (stream
, 0, 0);
14779 fprintf (stream
, _("\
14780 -msse2avx encode SSE instructions with VEX prefix\n"));
14781 fprintf (stream
, _("\
14782 -muse-unaligned-vector-move\n\
14783 encode aligned vector move as unaligned vector move\n"));
14784 fprintf (stream
, _("\
14785 -msse-check=[none|error|warning] (default: warning)\n\
14786 check SSE instructions\n"));
14787 fprintf (stream
, _("\
14788 -moperand-check=[none|error|warning] (default: warning)\n\
14789 check operand combinations for validity\n"));
14790 fprintf (stream
, _("\
14791 -mavxscalar=[128|256] (default: 128)\n\
14792 encode scalar AVX instructions with specific vector\n\
14794 fprintf (stream
, _("\
14795 -mvexwig=[0|1] (default: 0)\n\
14796 encode VEX instructions with specific VEX.W value\n\
14797 for VEX.W bit ignored instructions\n"));
14798 fprintf (stream
, _("\
14799 -mevexlig=[128|256|512] (default: 128)\n\
14800 encode scalar EVEX instructions with specific vector\n\
14802 fprintf (stream
, _("\
14803 -mevexwig=[0|1] (default: 0)\n\
14804 encode EVEX instructions with specific EVEX.W value\n\
14805 for EVEX.W bit ignored instructions\n"));
14806 fprintf (stream
, _("\
14807 -mevexrcig=[rne|rd|ru|rz] (default: rne)\n\
14808 encode EVEX instructions with specific EVEX.RC value\n\
14809 for SAE-only ignored instructions\n"));
14810 fprintf (stream
, _("\
14811 -mmnemonic=[att|intel] "));
14812 if (SYSV386_COMPAT
)
14813 fprintf (stream
, _("(default: att)\n"));
14815 fprintf (stream
, _("(default: intel)\n"));
14816 fprintf (stream
, _("\
14817 use AT&T/Intel mnemonic\n"));
14818 fprintf (stream
, _("\
14819 -msyntax=[att|intel] (default: att)\n\
14820 use AT&T/Intel syntax\n"));
14821 fprintf (stream
, _("\
14822 -mindex-reg support pseudo index registers\n"));
14823 fprintf (stream
, _("\
14824 -mnaked-reg don't require `%%' prefix for registers\n"));
14825 fprintf (stream
, _("\
14826 -madd-bnd-prefix add BND prefix for all valid branches\n"));
14827 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
14828 fprintf (stream
, _("\
14829 -mshared disable branch optimization for shared code\n"));
14830 fprintf (stream
, _("\
14831 -mx86-used-note=[no|yes] "));
14832 if (DEFAULT_X86_USED_NOTE
)
14833 fprintf (stream
, _("(default: yes)\n"));
14835 fprintf (stream
, _("(default: no)\n"));
14836 fprintf (stream
, _("\
14837 generate x86 used ISA and feature properties\n"));
14839 #if defined (TE_PE) || defined (TE_PEP)
14840 fprintf (stream
, _("\
14841 -mbig-obj generate big object files\n"));
14843 fprintf (stream
, _("\
14844 -momit-lock-prefix=[no|yes] (default: no)\n\
14845 strip all lock prefixes\n"));
14846 fprintf (stream
, _("\
14847 -mfence-as-lock-add=[no|yes] (default: no)\n\
14848 encode lfence, mfence and sfence as\n\
14849 lock addl $0x0, (%%{re}sp)\n"));
14850 fprintf (stream
, _("\
14851 -mrelax-relocations=[no|yes] "));
14852 if (DEFAULT_GENERATE_X86_RELAX_RELOCATIONS
)
14853 fprintf (stream
, _("(default: yes)\n"));
14855 fprintf (stream
, _("(default: no)\n"));
14856 fprintf (stream
, _("\
14857 generate relax relocations\n"));
14858 fprintf (stream
, _("\
14859 -malign-branch-boundary=NUM (default: 0)\n\
14860 align branches within NUM byte boundary\n"));
14861 fprintf (stream
, _("\
14862 -malign-branch=TYPE[+TYPE...] (default: jcc+fused+jmp)\n\
14863 TYPE is combination of jcc, fused, jmp, call, ret,\n\
14865 specify types of branches to align\n"));
14866 fprintf (stream
, _("\
14867 -malign-branch-prefix-size=NUM (default: 5)\n\
14868 align branches with NUM prefixes per instruction\n"));
14869 fprintf (stream
, _("\
14870 -mbranches-within-32B-boundaries\n\
14871 align branches within 32 byte boundary\n"));
14872 fprintf (stream
, _("\
14873 -mlfence-after-load=[no|yes] (default: no)\n\
14874 generate lfence after load\n"));
14875 fprintf (stream
, _("\
14876 -mlfence-before-indirect-branch=[none|all|register|memory] (default: none)\n\
14877 generate lfence before indirect near branch\n"));
14878 fprintf (stream
, _("\
14879 -mlfence-before-ret=[none|or|not|shl|yes] (default: none)\n\
14880 generate lfence before ret\n"));
14881 fprintf (stream
, _("\
14882 -mamd64 accept only AMD64 ISA [default]\n"));
14883 fprintf (stream
, _("\
14884 -mintel64 accept only Intel64 ISA\n"));
14887 #if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \
14888 || defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \
14889 || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O))
14891 /* Pick the target format to use. */
14894 i386_target_format (void)
14896 if (startswith (default_arch
, "x86_64"))
14898 update_code_flag (CODE_64BIT
, 1);
14899 if (default_arch
[6] == '\0')
14900 x86_elf_abi
= X86_64_ABI
;
14902 x86_elf_abi
= X86_64_X32_ABI
;
14904 else if (!strcmp (default_arch
, "i386"))
14905 update_code_flag (CODE_32BIT
, 1);
14906 else if (!strcmp (default_arch
, "iamcu"))
14908 update_code_flag (CODE_32BIT
, 1);
14909 if (cpu_arch_isa
== PROCESSOR_UNKNOWN
)
14911 static const i386_cpu_flags iamcu_flags
= CPU_IAMCU_FLAGS
;
14912 cpu_arch_name
= "iamcu";
14913 free (cpu_sub_arch_name
);
14914 cpu_sub_arch_name
= NULL
;
14915 cpu_arch_flags
= iamcu_flags
;
14916 cpu_arch_isa
= PROCESSOR_IAMCU
;
14917 cpu_arch_isa_flags
= iamcu_flags
;
14918 if (!cpu_arch_tune_set
)
14920 cpu_arch_tune
= cpu_arch_isa
;
14921 cpu_arch_tune_flags
= cpu_arch_isa_flags
;
14924 else if (cpu_arch_isa
!= PROCESSOR_IAMCU
)
14925 as_fatal (_("Intel MCU doesn't support `%s' architecture"),
14929 as_fatal (_("unknown architecture"));
14931 if (cpu_flags_all_zero (&cpu_arch_isa_flags
))
14932 cpu_arch_isa_flags
= cpu_arch
[flag_code
== CODE_64BIT
].enable
;
14933 if (cpu_flags_all_zero (&cpu_arch_tune_flags
))
14934 cpu_arch_tune_flags
= cpu_arch
[flag_code
== CODE_64BIT
].enable
;
14936 switch (OUTPUT_FLAVOR
)
14938 #if defined (OBJ_MAYBE_AOUT) || defined (OBJ_AOUT)
14939 case bfd_target_aout_flavour
:
14940 return AOUT_TARGET_FORMAT
;
14942 #if defined (OBJ_MAYBE_COFF) || defined (OBJ_COFF)
14943 # if defined (TE_PE) || defined (TE_PEP)
14944 case bfd_target_coff_flavour
:
14945 if (flag_code
== CODE_64BIT
)
14948 return use_big_obj
? "pe-bigobj-x86-64" : "pe-x86-64";
14950 return use_big_obj
? "pe-bigobj-i386" : "pe-i386";
14951 # elif defined (TE_GO32)
14952 case bfd_target_coff_flavour
:
14953 return "coff-go32";
14955 case bfd_target_coff_flavour
:
14956 return "coff-i386";
14959 #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF)
14960 case bfd_target_elf_flavour
:
14962 const char *format
;
14964 switch (x86_elf_abi
)
14967 format
= ELF_TARGET_FORMAT
;
14969 tls_get_addr
= "___tls_get_addr";
14973 use_rela_relocations
= 1;
14976 tls_get_addr
= "__tls_get_addr";
14978 format
= ELF_TARGET_FORMAT64
;
14980 case X86_64_X32_ABI
:
14981 use_rela_relocations
= 1;
14984 tls_get_addr
= "__tls_get_addr";
14986 disallow_64bit_reloc
= 1;
14987 format
= ELF_TARGET_FORMAT32
;
14990 if (cpu_arch_isa
== PROCESSOR_IAMCU
)
14992 if (x86_elf_abi
!= I386_ABI
)
14993 as_fatal (_("Intel MCU is 32bit only"));
14994 return ELF_TARGET_IAMCU_FORMAT
;
15000 #if defined (OBJ_MACH_O)
15001 case bfd_target_mach_o_flavour
:
15002 if (flag_code
== CODE_64BIT
)
15004 use_rela_relocations
= 1;
15006 return "mach-o-x86-64";
15009 return "mach-o-i386";
15017 #endif /* OBJ_MAYBE_ more than one */
15020 md_undefined_symbol (char *name
)
15022 if (name
[0] == GLOBAL_OFFSET_TABLE_NAME
[0]
15023 && name
[1] == GLOBAL_OFFSET_TABLE_NAME
[1]
15024 && name
[2] == GLOBAL_OFFSET_TABLE_NAME
[2]
15025 && strcmp (name
, GLOBAL_OFFSET_TABLE_NAME
) == 0)
15029 if (symbol_find (name
))
15030 as_bad (_("GOT already in symbol table"));
15031 GOT_symbol
= symbol_new (name
, undefined_section
,
15032 &zero_address_frag
, 0);
15039 /* Round up a section size to the appropriate boundary. */
15042 md_section_align (segT segment ATTRIBUTE_UNUSED
, valueT size
)
15044 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
15045 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
15047 /* For a.out, force the section size to be aligned. If we don't do
15048 this, BFD will align it for us, but it will not write out the
15049 final bytes of the section. This may be a bug in BFD, but it is
15050 easier to fix it here since that is how the other a.out targets
15054 align
= bfd_section_alignment (segment
);
15055 size
= ((size
+ (1 << align
) - 1) & (-((valueT
) 1 << align
)));
15062 /* On the i386, PC-relative offsets are relative to the start of the
15063 next instruction. That is, the address of the offset, plus its
15064 size, since the offset is always the last part of the insn. */
15067 md_pcrel_from (fixS
*fixP
)
15069 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
15075 s_bss (int ignore ATTRIBUTE_UNUSED
)
15079 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
15081 obj_elf_section_change_hook ();
15083 temp
= get_absolute_expression ();
15084 subseg_set (bss_section
, (subsegT
) temp
);
15085 demand_empty_rest_of_line ();
15090 /* Remember constant directive. */
15093 i386_cons_align (int ignore ATTRIBUTE_UNUSED
)
15095 if (last_insn
.kind
!= last_insn_directive
15096 && (bfd_section_flags (now_seg
) & SEC_CODE
))
15098 last_insn
.seg
= now_seg
;
15099 last_insn
.kind
= last_insn_directive
;
15100 last_insn
.name
= "constant directive";
15101 last_insn
.file
= as_where (&last_insn
.line
);
15102 if (lfence_before_ret
!= lfence_before_ret_none
)
15104 if (lfence_before_indirect_branch
!= lfence_branch_none
)
15105 as_warn (_("constant directive skips -mlfence-before-ret "
15106 "and -mlfence-before-indirect-branch"));
15108 as_warn (_("constant directive skips -mlfence-before-ret"));
15110 else if (lfence_before_indirect_branch
!= lfence_branch_none
)
15111 as_warn (_("constant directive skips -mlfence-before-indirect-branch"));
15116 i386_validate_fix (fixS
*fixp
)
15118 if (fixp
->fx_addsy
&& S_GET_SEGMENT(fixp
->fx_addsy
) == reg_section
)
15120 reloc_howto_type
*howto
;
15122 howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
15123 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
15124 _("invalid %s relocation against register"),
15125 howto
? howto
->name
: "<unknown>");
15129 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
15130 if (fixp
->fx_r_type
== BFD_RELOC_SIZE32
15131 || fixp
->fx_r_type
== BFD_RELOC_SIZE64
)
15132 return IS_ELF
&& fixp
->fx_addsy
15133 && (!S_IS_DEFINED (fixp
->fx_addsy
)
15134 || S_IS_EXTERNAL (fixp
->fx_addsy
));
15137 if (fixp
->fx_subsy
)
15139 if (fixp
->fx_subsy
== GOT_symbol
)
15141 if (fixp
->fx_r_type
== BFD_RELOC_32_PCREL
)
15145 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
15146 if (fixp
->fx_tcbit2
)
15147 fixp
->fx_r_type
= (fixp
->fx_tcbit
15148 ? BFD_RELOC_X86_64_REX_GOTPCRELX
15149 : BFD_RELOC_X86_64_GOTPCRELX
);
15152 fixp
->fx_r_type
= BFD_RELOC_X86_64_GOTPCREL
;
15157 fixp
->fx_r_type
= BFD_RELOC_386_GOTOFF
;
15159 fixp
->fx_r_type
= BFD_RELOC_X86_64_GOTOFF64
;
15161 fixp
->fx_subsy
= 0;
15164 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
15167 /* NB: Commit 292676c1 resolved PLT32 reloc aganst local symbol
15168 to section. Since PLT32 relocation must be against symbols,
15169 turn such PLT32 relocation into PC32 relocation. */
15171 && (fixp
->fx_r_type
== BFD_RELOC_386_PLT32
15172 || fixp
->fx_r_type
== BFD_RELOC_X86_64_PLT32
)
15173 && symbol_section_p (fixp
->fx_addsy
))
15174 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
15177 if (fixp
->fx_r_type
== BFD_RELOC_386_GOT32
15178 && fixp
->fx_tcbit2
)
15179 fixp
->fx_r_type
= BFD_RELOC_386_GOT32X
;
15188 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
15191 bfd_reloc_code_real_type code
;
15193 switch (fixp
->fx_r_type
)
15195 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
15198 case BFD_RELOC_SIZE32
:
15199 case BFD_RELOC_SIZE64
:
15201 && !bfd_is_abs_section (S_GET_SEGMENT (fixp
->fx_addsy
))
15202 && (!fixp
->fx_subsy
15203 || bfd_is_abs_section (S_GET_SEGMENT (fixp
->fx_subsy
))))
15204 sym
= fixp
->fx_addsy
;
15205 else if (fixp
->fx_subsy
15206 && !bfd_is_abs_section (S_GET_SEGMENT (fixp
->fx_subsy
))
15207 && (!fixp
->fx_addsy
15208 || bfd_is_abs_section (S_GET_SEGMENT (fixp
->fx_addsy
))))
15209 sym
= fixp
->fx_subsy
;
15212 if (IS_ELF
&& sym
&& S_IS_DEFINED (sym
) && !S_IS_EXTERNAL (sym
))
15214 /* Resolve size relocation against local symbol to size of
15215 the symbol plus addend. */
15216 valueT value
= S_GET_SIZE (sym
);
15218 if (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
)
15219 value
= bfd_section_size (S_GET_SEGMENT (sym
));
15220 if (sym
== fixp
->fx_subsy
)
15223 if (fixp
->fx_addsy
)
15224 value
+= S_GET_VALUE (fixp
->fx_addsy
);
15226 else if (fixp
->fx_subsy
)
15227 value
-= S_GET_VALUE (fixp
->fx_subsy
);
15228 value
+= fixp
->fx_offset
;
15229 if (fixp
->fx_r_type
== BFD_RELOC_SIZE32
15231 && !fits_in_unsigned_long (value
))
15232 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
15233 _("symbol size computation overflow"));
15234 fixp
->fx_addsy
= NULL
;
15235 fixp
->fx_subsy
= NULL
;
15236 md_apply_fix (fixp
, (valueT
*) &value
, NULL
);
15239 if (!fixp
->fx_addsy
|| fixp
->fx_subsy
)
15241 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
15242 "unsupported expression involving @size");
15246 /* Fall through. */
15248 case BFD_RELOC_X86_64_PLT32
:
15249 case BFD_RELOC_X86_64_GOT32
:
15250 case BFD_RELOC_X86_64_GOTPCREL
:
15251 case BFD_RELOC_X86_64_GOTPCRELX
:
15252 case BFD_RELOC_X86_64_REX_GOTPCRELX
:
15253 case BFD_RELOC_386_PLT32
:
15254 case BFD_RELOC_386_GOT32
:
15255 case BFD_RELOC_386_GOT32X
:
15256 case BFD_RELOC_386_GOTOFF
:
15257 case BFD_RELOC_386_GOTPC
:
15258 case BFD_RELOC_386_TLS_GD
:
15259 case BFD_RELOC_386_TLS_LDM
:
15260 case BFD_RELOC_386_TLS_LDO_32
:
15261 case BFD_RELOC_386_TLS_IE_32
:
15262 case BFD_RELOC_386_TLS_IE
:
15263 case BFD_RELOC_386_TLS_GOTIE
:
15264 case BFD_RELOC_386_TLS_LE_32
:
15265 case BFD_RELOC_386_TLS_LE
:
15266 case BFD_RELOC_386_TLS_GOTDESC
:
15267 case BFD_RELOC_386_TLS_DESC_CALL
:
15268 case BFD_RELOC_X86_64_TLSGD
:
15269 case BFD_RELOC_X86_64_TLSLD
:
15270 case BFD_RELOC_X86_64_DTPOFF32
:
15271 case BFD_RELOC_X86_64_DTPOFF64
:
15272 case BFD_RELOC_X86_64_GOTTPOFF
:
15273 case BFD_RELOC_X86_64_TPOFF32
:
15274 case BFD_RELOC_X86_64_TPOFF64
:
15275 case BFD_RELOC_X86_64_GOTOFF64
:
15276 case BFD_RELOC_X86_64_GOTPC32
:
15277 case BFD_RELOC_X86_64_GOT64
:
15278 case BFD_RELOC_X86_64_GOTPCREL64
:
15279 case BFD_RELOC_X86_64_GOTPC64
:
15280 case BFD_RELOC_X86_64_GOTPLT64
:
15281 case BFD_RELOC_X86_64_PLTOFF64
:
15282 case BFD_RELOC_X86_64_GOTPC32_TLSDESC
:
15283 case BFD_RELOC_X86_64_TLSDESC_CALL
:
15284 case BFD_RELOC_RVA
:
15285 case BFD_RELOC_VTABLE_ENTRY
:
15286 case BFD_RELOC_VTABLE_INHERIT
:
15288 case BFD_RELOC_32_SECREL
:
15289 case BFD_RELOC_16_SECIDX
:
15291 code
= fixp
->fx_r_type
;
15293 case BFD_RELOC_X86_64_32S
:
15294 if (!fixp
->fx_pcrel
)
15296 /* Don't turn BFD_RELOC_X86_64_32S into BFD_RELOC_32. */
15297 code
= fixp
->fx_r_type
;
15300 /* Fall through. */
15302 if (fixp
->fx_pcrel
)
15304 switch (fixp
->fx_size
)
15307 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
15308 _("can not do %d byte pc-relative relocation"),
15310 code
= BFD_RELOC_32_PCREL
;
15312 case 1: code
= BFD_RELOC_8_PCREL
; break;
15313 case 2: code
= BFD_RELOC_16_PCREL
; break;
15314 case 4: code
= BFD_RELOC_32_PCREL
; break;
15316 case 8: code
= BFD_RELOC_64_PCREL
; break;
15322 switch (fixp
->fx_size
)
15325 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
15326 _("can not do %d byte relocation"),
15328 code
= BFD_RELOC_32
;
15330 case 1: code
= BFD_RELOC_8
; break;
15331 case 2: code
= BFD_RELOC_16
; break;
15332 case 4: code
= BFD_RELOC_32
; break;
15334 case 8: code
= BFD_RELOC_64
; break;
15341 if ((code
== BFD_RELOC_32
15342 || code
== BFD_RELOC_32_PCREL
15343 || code
== BFD_RELOC_X86_64_32S
)
15345 && fixp
->fx_addsy
== GOT_symbol
)
15348 code
= BFD_RELOC_386_GOTPC
;
15350 code
= BFD_RELOC_X86_64_GOTPC32
;
15352 if ((code
== BFD_RELOC_64
|| code
== BFD_RELOC_64_PCREL
)
15354 && fixp
->fx_addsy
== GOT_symbol
)
15356 code
= BFD_RELOC_X86_64_GOTPC64
;
15359 rel
= XNEW (arelent
);
15360 rel
->sym_ptr_ptr
= XNEW (asymbol
*);
15361 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
15363 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
15365 if (!use_rela_relocations
)
15367 /* HACK: Since i386 ELF uses Rel instead of Rela, encode the
15368 vtable entry to be used in the relocation's section offset. */
15369 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
15370 rel
->address
= fixp
->fx_offset
;
15371 #if defined (OBJ_COFF) && defined (TE_PE)
15372 else if (fixp
->fx_addsy
&& S_IS_WEAK (fixp
->fx_addsy
))
15373 rel
->addend
= fixp
->fx_addnumber
- (S_GET_VALUE (fixp
->fx_addsy
) * 2);
15378 /* Use the rela in 64bit mode. */
15381 if (disallow_64bit_reloc
)
15384 case BFD_RELOC_X86_64_DTPOFF64
:
15385 case BFD_RELOC_X86_64_TPOFF64
:
15386 case BFD_RELOC_64_PCREL
:
15387 case BFD_RELOC_X86_64_GOTOFF64
:
15388 case BFD_RELOC_X86_64_GOT64
:
15389 case BFD_RELOC_X86_64_GOTPCREL64
:
15390 case BFD_RELOC_X86_64_GOTPC64
:
15391 case BFD_RELOC_X86_64_GOTPLT64
:
15392 case BFD_RELOC_X86_64_PLTOFF64
:
15393 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
15394 _("cannot represent relocation type %s in x32 mode"),
15395 bfd_get_reloc_code_name (code
));
15401 if (!fixp
->fx_pcrel
)
15402 rel
->addend
= fixp
->fx_offset
;
15406 case BFD_RELOC_X86_64_PLT32
:
15407 case BFD_RELOC_X86_64_GOT32
:
15408 case BFD_RELOC_X86_64_GOTPCREL
:
15409 case BFD_RELOC_X86_64_GOTPCRELX
:
15410 case BFD_RELOC_X86_64_REX_GOTPCRELX
:
15411 case BFD_RELOC_X86_64_TLSGD
:
15412 case BFD_RELOC_X86_64_TLSLD
:
15413 case BFD_RELOC_X86_64_GOTTPOFF
:
15414 case BFD_RELOC_X86_64_GOTPC32_TLSDESC
:
15415 case BFD_RELOC_X86_64_TLSDESC_CALL
:
15416 rel
->addend
= fixp
->fx_offset
- fixp
->fx_size
;
15419 rel
->addend
= (section
->vma
15421 + fixp
->fx_addnumber
15422 + md_pcrel_from (fixp
));
15427 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
15428 if (rel
->howto
== NULL
)
15430 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
15431 _("cannot represent relocation type %s"),
15432 bfd_get_reloc_code_name (code
));
15433 /* Set howto to a garbage value so that we can keep going. */
15434 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
15435 gas_assert (rel
->howto
!= NULL
);
15441 #include "tc-i386-intel.c"
15444 tc_x86_parse_to_dw2regnum (expressionS
*exp
)
15446 int saved_naked_reg
;
15447 char saved_register_dot
;
15449 saved_naked_reg
= allow_naked_reg
;
15450 allow_naked_reg
= 1;
15451 saved_register_dot
= register_chars
['.'];
15452 register_chars
['.'] = '.';
15453 allow_pseudo_reg
= 1;
15454 expression_and_evaluate (exp
);
15455 allow_pseudo_reg
= 0;
15456 register_chars
['.'] = saved_register_dot
;
15457 allow_naked_reg
= saved_naked_reg
;
15459 if (exp
->X_op
== O_register
&& exp
->X_add_number
>= 0)
15461 if ((addressT
) exp
->X_add_number
< i386_regtab_size
)
15463 exp
->X_op
= O_constant
;
15464 exp
->X_add_number
= i386_regtab
[exp
->X_add_number
]
15465 .dw2_regnum
[flag_code
>> 1];
15468 exp
->X_op
= O_illegal
;
15473 tc_x86_frame_initial_instructions (void)
15475 static unsigned int sp_regno
[2];
15477 if (!sp_regno
[flag_code
>> 1])
15479 char *saved_input
= input_line_pointer
;
15480 char sp
[][4] = {"esp", "rsp"};
15483 input_line_pointer
= sp
[flag_code
>> 1];
15484 tc_x86_parse_to_dw2regnum (&exp
);
15485 gas_assert (exp
.X_op
== O_constant
);
15486 sp_regno
[flag_code
>> 1] = exp
.X_add_number
;
15487 input_line_pointer
= saved_input
;
15490 cfi_add_CFA_def_cfa (sp_regno
[flag_code
>> 1], -x86_cie_data_alignment
);
15491 cfi_add_CFA_offset (x86_dwarf2_return_column
, x86_cie_data_alignment
);
15495 x86_dwarf2_addr_size (void)
15497 #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF)
15498 if (x86_elf_abi
== X86_64_X32_ABI
)
15501 return bfd_arch_bits_per_address (stdoutput
) / 8;
15505 i386_elf_section_type (const char *str
, size_t len
)
15507 if (flag_code
== CODE_64BIT
15508 && len
== sizeof ("unwind") - 1
15509 && startswith (str
, "unwind"))
15510 return SHT_X86_64_UNWIND
;
15517 i386_solaris_fix_up_eh_frame (segT sec
)
15519 if (flag_code
== CODE_64BIT
)
15520 elf_section_type (sec
) = SHT_X86_64_UNWIND
;
15526 tc_pe_dwarf2_emit_offset (symbolS
*symbol
, unsigned int size
)
15530 exp
.X_op
= O_secrel
;
15531 exp
.X_add_symbol
= symbol
;
15532 exp
.X_add_number
= 0;
15533 emit_expr (&exp
, size
);
15537 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
15538 /* For ELF on x86-64, add support for SHF_X86_64_LARGE. */
15541 x86_64_section_letter (int letter
, const char **ptr_msg
)
15543 if (flag_code
== CODE_64BIT
)
15546 return SHF_X86_64_LARGE
;
15548 *ptr_msg
= _("bad .section directive: want a,l,w,x,M,S,G,T in string");
15551 *ptr_msg
= _("bad .section directive: want a,w,x,M,S,G,T in string");
15556 x86_64_section_word (char *str
, size_t len
)
15558 if (len
== 5 && flag_code
== CODE_64BIT
&& startswith (str
, "large"))
15559 return SHF_X86_64_LARGE
;
15565 handle_large_common (int small ATTRIBUTE_UNUSED
)
15567 if (flag_code
!= CODE_64BIT
)
15569 s_comm_internal (0, elf_common_parse
);
15570 as_warn (_(".largecomm supported only in 64bit mode, producing .comm"));
15574 static segT lbss_section
;
15575 asection
*saved_com_section_ptr
= elf_com_section_ptr
;
15576 asection
*saved_bss_section
= bss_section
;
15578 if (lbss_section
== NULL
)
15580 flagword applicable
;
15581 segT seg
= now_seg
;
15582 subsegT subseg
= now_subseg
;
15584 /* The .lbss section is for local .largecomm symbols. */
15585 lbss_section
= subseg_new (".lbss", 0);
15586 applicable
= bfd_applicable_section_flags (stdoutput
);
15587 bfd_set_section_flags (lbss_section
, applicable
& SEC_ALLOC
);
15588 seg_info (lbss_section
)->bss
= 1;
15590 subseg_set (seg
, subseg
);
15593 elf_com_section_ptr
= &_bfd_elf_large_com_section
;
15594 bss_section
= lbss_section
;
15596 s_comm_internal (0, elf_common_parse
);
15598 elf_com_section_ptr
= saved_com_section_ptr
;
15599 bss_section
= saved_bss_section
;
15602 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */