1 /* tc-i386.c -- Assemble code for the Intel 80386
2 Copyright 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 /* Intel 80386 machine specific gas.
24 Written by Eliot Dresselhaus (eliot@mgm.mit.edu).
25 x86_64 support by Jan Hubicka (jh@suse.cz)
26 VIA PadLock support by Michal Ludvig (mludvig@suse.cz)
27 Bugs & suggestions are completely welcome. This is free software.
28 Please help us make it better. */
31 #include "safe-ctype.h"
33 #include "dwarf2dbg.h"
34 #include "dw2gencfi.h"
35 #include "elf/x86-64.h"
36 #include "opcodes/i386-init.h"
38 #ifndef REGISTER_WARNINGS
39 #define REGISTER_WARNINGS 1
42 #ifndef INFER_ADDR_PREFIX
43 #define INFER_ADDR_PREFIX 1
47 #define DEFAULT_ARCH "i386"
52 #define INLINE __inline__
58 /* Prefixes will be emitted in the order defined below.
59 WAIT_PREFIX must be the first prefix since FWAIT is really is an
60 instruction, and so must come before any prefixes.
61 The preferred prefix order is SEG_PREFIX, ADDR_PREFIX, DATA_PREFIX,
67 #define LOCKREP_PREFIX 4
68 #define REX_PREFIX 5 /* must come last. */
69 #define MAX_PREFIXES 6 /* max prefixes per opcode */
71 /* we define the syntax here (modulo base,index,scale syntax) */
72 #define REGISTER_PREFIX '%'
73 #define IMMEDIATE_PREFIX '$'
74 #define ABSOLUTE_PREFIX '*'
76 /* these are the instruction mnemonic suffixes in AT&T syntax or
77 memory operand size in Intel syntax. */
78 #define WORD_MNEM_SUFFIX 'w'
79 #define BYTE_MNEM_SUFFIX 'b'
80 #define SHORT_MNEM_SUFFIX 's'
81 #define LONG_MNEM_SUFFIX 'l'
82 #define QWORD_MNEM_SUFFIX 'q'
83 #define XMMWORD_MNEM_SUFFIX 'x'
84 #define YMMWORD_MNEM_SUFFIX 'y'
85 /* Intel Syntax. Use a non-ascii letter since since it never appears
87 #define LONG_DOUBLE_MNEM_SUFFIX '\1'
89 #define END_OF_INSN '\0'
92 'templates' is for grouping together 'template' structures for opcodes
93 of the same name. This is only used for storing the insns in the grand
94 ole hash table of insns.
95 The templates themselves start at START and range up to (but not including)
100 const template *start
;
105 /* 386 operand encoding bytes: see 386 book for details of this. */
108 unsigned int regmem
; /* codes register or memory operand */
109 unsigned int reg
; /* codes register operand (or extended opcode) */
110 unsigned int mode
; /* how to interpret regmem & reg */
114 /* x86-64 extension prefix. */
115 typedef int rex_byte
;
117 /* The SSE5 instructions have a two bit instruction modifier (OC) that
118 is stored in two separate bytes in the instruction. Pick apart OC
119 into the 2 separate bits for instruction. */
120 #define DREX_OC0(x) (((x) & 1) != 0)
121 #define DREX_OC1(x) (((x) & 2) != 0)
123 #define DREX_OC0_MASK (1 << 3) /* set OC0 in byte 4 */
124 #define DREX_OC1_MASK (1 << 2) /* set OC1 in byte 3 */
127 #define DREX_XMEM_X1_X2_X2 0 /* 4 op insn, dest = src3, src1 = reg/mem */
128 #define DREX_X1_XMEM_X2_X2 1 /* 4 op insn, dest = src3, src2 = reg/mem */
129 #define DREX_X1_XMEM_X2_X1 2 /* 4 op insn, dest = src1, src2 = reg/mem */
130 #define DREX_X1_X2_XMEM_X1 3 /* 4 op insn, dest = src1, src3 = reg/mem */
132 #define DREX_XMEM_X1_X2 0 /* 3 op insn, src1 = reg/mem */
133 #define DREX_X1_XMEM_X2 1 /* 3 op insn, src1 = reg/mem */
135 /* Information needed to create the DREX byte in SSE5 instructions. */
138 unsigned int reg
; /* register */
139 unsigned int rex
; /* REX flags */
140 unsigned int modrm_reg
; /* which arg goes in the modrm.reg field */
141 unsigned int modrm_regmem
; /* which arg goes in the modrm.regmem field */
144 /* 386 opcode byte to code indirect addressing. */
159 PROCESSOR_PENTIUMPRO
,
172 /* x86 arch names, types and features */
175 const char *name
; /* arch name */
176 enum processor_type type
; /* arch type */
177 i386_cpu_flags flags
; /* cpu feature flags */
181 static void set_code_flag (int);
182 static void set_16bit_gcc_code_flag (int);
183 static void set_intel_syntax (int);
184 static void set_intel_mnemonic (int);
185 static void set_allow_index_reg (int);
186 static void set_cpu_arch (int);
188 static void pe_directive_secrel (int);
190 static void signed_cons (int);
191 static char *output_invalid (int c
);
192 static int i386_att_operand (char *);
193 static int i386_intel_operand (char *, int);
194 static const reg_entry
*parse_register (char *, char **);
195 static char *parse_insn (char *, char *);
196 static char *parse_operands (char *, const char *);
197 static void swap_operands (void);
198 static void swap_2_operands (int, int);
199 static void optimize_imm (void);
200 static void optimize_disp (void);
201 static int match_template (void);
202 static int check_string (void);
203 static int process_suffix (void);
204 static int check_byte_reg (void);
205 static int check_long_reg (void);
206 static int check_qword_reg (void);
207 static int check_word_reg (void);
208 static int finalize_imm (void);
209 static void process_drex (void);
210 static int process_operands (void);
211 static const seg_entry
*build_modrm_byte (void);
212 static void output_insn (void);
213 static void output_imm (fragS
*, offsetT
);
214 static void output_disp (fragS
*, offsetT
);
216 static void s_bss (int);
218 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
219 static void handle_large_common (int small ATTRIBUTE_UNUSED
);
222 static const char *default_arch
= DEFAULT_ARCH
;
227 /* VEX prefix is either 2 byte or 3 byte. */
228 unsigned char bytes
[3];
230 /* Destination or source register specifier. */
231 const reg_entry
*register_specifier
;
234 /* 'md_assemble ()' gathers together information and puts it into a
241 const reg_entry
*regs
;
246 /* TM holds the template for the insn were currently assembling. */
249 /* SUFFIX holds the instruction size suffix for byte, word, dword
250 or qword, if given. */
253 /* OPERANDS gives the number of given operands. */
254 unsigned int operands
;
256 /* REG_OPERANDS, DISP_OPERANDS, MEM_OPERANDS, IMM_OPERANDS give the number
257 of given register, displacement, memory operands and immediate
259 unsigned int reg_operands
, disp_operands
, mem_operands
, imm_operands
;
261 /* TYPES [i] is the type (see above #defines) which tells us how to
262 use OP[i] for the corresponding operand. */
263 i386_operand_type types
[MAX_OPERANDS
];
265 /* Displacement expression, immediate expression, or register for each
267 union i386_op op
[MAX_OPERANDS
];
269 /* Flags for operands. */
270 unsigned int flags
[MAX_OPERANDS
];
271 #define Operand_PCrel 1
273 /* Relocation type for operand */
274 enum bfd_reloc_code_real reloc
[MAX_OPERANDS
];
276 /* BASE_REG, INDEX_REG, and LOG2_SCALE_FACTOR are used to encode
277 the base index byte below. */
278 const reg_entry
*base_reg
;
279 const reg_entry
*index_reg
;
280 unsigned int log2_scale_factor
;
282 /* SEG gives the seg_entries of this insn. They are zero unless
283 explicit segment overrides are given. */
284 const seg_entry
*seg
[2];
286 /* PREFIX holds all the given prefix opcodes (usually null).
287 PREFIXES is the number of prefix opcodes. */
288 unsigned int prefixes
;
289 unsigned char prefix
[MAX_PREFIXES
];
291 /* RM and SIB are the modrm byte and the sib byte where the
292 addressing modes of this insn are encoded. DREX is the byte
293 added by the SSE5 instructions. */
302 typedef struct _i386_insn i386_insn
;
304 /* List of chars besides those in app.c:symbol_chars that can start an
305 operand. Used to prevent the scrubber eating vital white-space. */
306 const char extra_symbol_chars
[] = "*%-(["
315 #if (defined (TE_I386AIX) \
316 || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) \
317 && !defined (TE_GNU) \
318 && !defined (TE_LINUX) \
319 && !defined (TE_NETWARE) \
320 && !defined (TE_FreeBSD) \
321 && !defined (TE_NetBSD)))
322 /* This array holds the chars that always start a comment. If the
323 pre-processor is disabled, these aren't very useful. The option
324 --divide will remove '/' from this list. */
325 const char *i386_comment_chars
= "#/";
326 #define SVR4_COMMENT_CHARS 1
327 #define PREFIX_SEPARATOR '\\'
330 const char *i386_comment_chars
= "#";
331 #define PREFIX_SEPARATOR '/'
334 /* This array holds the chars that only start a comment at the beginning of
335 a line. If the line seems to have the form '# 123 filename'
336 .line and .file directives will appear in the pre-processed output.
337 Note that input_file.c hand checks for '#' at the beginning of the
338 first line of the input file. This is because the compiler outputs
339 #NO_APP at the beginning of its output.
340 Also note that comments started like this one will always work if
341 '/' isn't otherwise defined. */
342 const char line_comment_chars
[] = "#/";
344 const char line_separator_chars
[] = ";";
346 /* Chars that can be used to separate mant from exp in floating point
348 const char EXP_CHARS
[] = "eE";
350 /* Chars that mean this number is a floating point constant
353 const char FLT_CHARS
[] = "fFdDxX";
355 /* Tables for lexical analysis. */
356 static char mnemonic_chars
[256];
357 static char register_chars
[256];
358 static char operand_chars
[256];
359 static char identifier_chars
[256];
360 static char digit_chars
[256];
362 /* Lexical macros. */
363 #define is_mnemonic_char(x) (mnemonic_chars[(unsigned char) x])
364 #define is_operand_char(x) (operand_chars[(unsigned char) x])
365 #define is_register_char(x) (register_chars[(unsigned char) x])
366 #define is_space_char(x) ((x) == ' ')
367 #define is_identifier_char(x) (identifier_chars[(unsigned char) x])
368 #define is_digit_char(x) (digit_chars[(unsigned char) x])
370 /* All non-digit non-letter characters that may occur in an operand. */
371 static char operand_special_chars
[] = "%$-+(,)*._~/<>|&^!:[@]";
373 /* md_assemble() always leaves the strings it's passed unaltered. To
374 effect this we maintain a stack of saved characters that we've smashed
375 with '\0's (indicating end of strings for various sub-fields of the
376 assembler instruction). */
377 static char save_stack
[32];
378 static char *save_stack_p
;
379 #define END_STRING_AND_SAVE(s) \
380 do { *save_stack_p++ = *(s); *(s) = '\0'; } while (0)
381 #define RESTORE_END_STRING(s) \
382 do { *(s) = *--save_stack_p; } while (0)
384 /* The instruction we're assembling. */
387 /* Possible templates for current insn. */
388 static const templates
*current_templates
;
390 /* Per instruction expressionS buffers: max displacements & immediates. */
391 static expressionS disp_expressions
[MAX_MEMORY_OPERANDS
];
392 static expressionS im_expressions
[MAX_IMMEDIATE_OPERANDS
];
394 /* Current operand we are working on. */
395 static int this_operand
;
397 /* We support four different modes. FLAG_CODE variable is used to distinguish
405 static enum flag_code flag_code
;
406 static unsigned int object_64bit
;
407 static int use_rela_relocations
= 0;
409 /* The names used to print error messages. */
410 static const char *flag_code_names
[] =
417 /* 1 for intel syntax,
419 static int intel_syntax
= 0;
421 /* 1 for intel mnemonic,
422 0 if att mnemonic. */
423 static int intel_mnemonic
= !SYSV386_COMPAT
;
425 /* 1 if support old (<= 2.8.1) versions of gcc. */
426 static int old_gcc
= OLDGCC_COMPAT
;
428 /* 1 if pseudo registers are permitted. */
429 static int allow_pseudo_reg
= 0;
431 /* 1 if register prefix % not required. */
432 static int allow_naked_reg
= 0;
434 /* 1 if pseudo index register, eiz/riz, is allowed . */
435 static int allow_index_reg
= 0;
437 /* Register prefix used for error message. */
438 static const char *register_prefix
= "%";
440 /* Used in 16 bit gcc mode to add an l suffix to call, ret, enter,
441 leave, push, and pop instructions so that gcc has the same stack
442 frame as in 32 bit mode. */
443 static char stackop_size
= '\0';
445 /* Non-zero to optimize code alignment. */
446 int optimize_align_code
= 1;
448 /* Non-zero to quieten some warnings. */
449 static int quiet_warnings
= 0;
452 static const char *cpu_arch_name
= NULL
;
453 static char *cpu_sub_arch_name
= NULL
;
455 /* CPU feature flags. */
456 static i386_cpu_flags cpu_arch_flags
= CPU_UNKNOWN_FLAGS
;
458 /* If we have selected a cpu we are generating instructions for. */
459 static int cpu_arch_tune_set
= 0;
461 /* Cpu we are generating instructions for. */
462 static enum processor_type cpu_arch_tune
= PROCESSOR_UNKNOWN
;
464 /* CPU feature flags of cpu we are generating instructions for. */
465 static i386_cpu_flags cpu_arch_tune_flags
;
467 /* CPU instruction set architecture used. */
468 static enum processor_type cpu_arch_isa
= PROCESSOR_UNKNOWN
;
470 /* CPU feature flags of instruction set architecture used. */
471 static i386_cpu_flags cpu_arch_isa_flags
;
473 /* If set, conditional jumps are not automatically promoted to handle
474 larger than a byte offset. */
475 static unsigned int no_cond_jump_promotion
= 0;
477 /* Encode SSE instructions with VEX prefix. */
478 static unsigned int sse2avx
;
480 /* Pre-defined "_GLOBAL_OFFSET_TABLE_". */
481 static symbolS
*GOT_symbol
;
483 /* The dwarf2 return column, adjusted for 32 or 64 bit. */
484 unsigned int x86_dwarf2_return_column
;
486 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
487 int x86_cie_data_alignment
;
489 /* Interface to relax_segment.
490 There are 3 major relax states for 386 jump insns because the
491 different types of jumps add different sizes to frags when we're
492 figuring out what sort of jump to choose to reach a given label. */
495 #define UNCOND_JUMP 0
497 #define COND_JUMP86 2
502 #define SMALL16 (SMALL | CODE16)
504 #define BIG16 (BIG | CODE16)
508 #define INLINE __inline__
514 #define ENCODE_RELAX_STATE(type, size) \
515 ((relax_substateT) (((type) << 2) | (size)))
516 #define TYPE_FROM_RELAX_STATE(s) \
518 #define DISP_SIZE_FROM_RELAX_STATE(s) \
519 ((((s) & 3) == BIG ? 4 : (((s) & 3) == BIG16 ? 2 : 1)))
521 /* This table is used by relax_frag to promote short jumps to long
522 ones where necessary. SMALL (short) jumps may be promoted to BIG
523 (32 bit long) ones, and SMALL16 jumps to BIG16 (16 bit long). We
524 don't allow a short jump in a 32 bit code segment to be promoted to
525 a 16 bit offset jump because it's slower (requires data size
526 prefix), and doesn't work, unless the destination is in the bottom
527 64k of the code segment (The top 16 bits of eip are zeroed). */
529 const relax_typeS md_relax_table
[] =
532 1) most positive reach of this state,
533 2) most negative reach of this state,
534 3) how many bytes this mode will have in the variable part of the frag
535 4) which index into the table to try if we can't fit into this one. */
537 /* UNCOND_JUMP states. */
538 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (UNCOND_JUMP
, BIG
)},
539 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (UNCOND_JUMP
, BIG16
)},
540 /* dword jmp adds 4 bytes to frag:
541 0 extra opcode bytes, 4 displacement bytes. */
543 /* word jmp adds 2 byte2 to frag:
544 0 extra opcode bytes, 2 displacement bytes. */
547 /* COND_JUMP states. */
548 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP
, BIG
)},
549 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP
, BIG16
)},
550 /* dword conditionals adds 5 bytes to frag:
551 1 extra opcode byte, 4 displacement bytes. */
553 /* word conditionals add 3 bytes to frag:
554 1 extra opcode byte, 2 displacement bytes. */
557 /* COND_JUMP86 states. */
558 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP86
, BIG
)},
559 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP86
, BIG16
)},
560 /* dword conditionals adds 5 bytes to frag:
561 1 extra opcode byte, 4 displacement bytes. */
563 /* word conditionals add 4 bytes to frag:
564 1 displacement byte and a 3 byte long branch insn. */
568 static const arch_entry cpu_arch
[] =
570 { "generic32", PROCESSOR_GENERIC32
,
571 CPU_GENERIC32_FLAGS
},
572 { "generic64", PROCESSOR_GENERIC64
,
573 CPU_GENERIC64_FLAGS
},
574 { "i8086", PROCESSOR_UNKNOWN
,
576 { "i186", PROCESSOR_UNKNOWN
,
578 { "i286", PROCESSOR_UNKNOWN
,
580 { "i386", PROCESSOR_I386
,
582 { "i486", PROCESSOR_I486
,
584 { "i586", PROCESSOR_PENTIUM
,
586 { "i686", PROCESSOR_PENTIUMPRO
,
588 { "pentium", PROCESSOR_PENTIUM
,
590 { "pentiumpro", PROCESSOR_PENTIUMPRO
,
592 { "pentiumii", PROCESSOR_PENTIUMPRO
,
594 { "pentiumiii",PROCESSOR_PENTIUMPRO
,
596 { "pentium4", PROCESSOR_PENTIUM4
,
598 { "prescott", PROCESSOR_NOCONA
,
600 { "nocona", PROCESSOR_NOCONA
,
602 { "yonah", PROCESSOR_CORE
,
604 { "core", PROCESSOR_CORE
,
606 { "merom", PROCESSOR_CORE2
,
608 { "core2", PROCESSOR_CORE2
,
610 { "k6", PROCESSOR_K6
,
612 { "k6_2", PROCESSOR_K6
,
614 { "athlon", PROCESSOR_ATHLON
,
616 { "sledgehammer", PROCESSOR_K8
,
618 { "opteron", PROCESSOR_K8
,
620 { "k8", PROCESSOR_K8
,
622 { "amdfam10", PROCESSOR_AMDFAM10
,
623 CPU_AMDFAM10_FLAGS
},
624 { ".mmx", PROCESSOR_UNKNOWN
,
626 { ".sse", PROCESSOR_UNKNOWN
,
628 { ".sse2", PROCESSOR_UNKNOWN
,
630 { ".sse3", PROCESSOR_UNKNOWN
,
632 { ".ssse3", PROCESSOR_UNKNOWN
,
634 { ".sse4.1", PROCESSOR_UNKNOWN
,
636 { ".sse4.2", PROCESSOR_UNKNOWN
,
638 { ".sse4", PROCESSOR_UNKNOWN
,
640 { ".avx", PROCESSOR_UNKNOWN
,
642 { ".vmx", PROCESSOR_UNKNOWN
,
644 { ".smx", PROCESSOR_UNKNOWN
,
646 { ".xsave", PROCESSOR_UNKNOWN
,
648 { ".aes", PROCESSOR_UNKNOWN
,
650 { ".clmul", PROCESSOR_UNKNOWN
,
652 { ".fma", PROCESSOR_UNKNOWN
,
654 { ".3dnow", PROCESSOR_UNKNOWN
,
656 { ".3dnowa", PROCESSOR_UNKNOWN
,
658 { ".padlock", PROCESSOR_UNKNOWN
,
660 { ".pacifica", PROCESSOR_UNKNOWN
,
662 { ".svme", PROCESSOR_UNKNOWN
,
664 { ".sse4a", PROCESSOR_UNKNOWN
,
666 { ".abm", PROCESSOR_UNKNOWN
,
668 { ".sse5", PROCESSOR_UNKNOWN
,
672 const pseudo_typeS md_pseudo_table
[] =
674 #if !defined(OBJ_AOUT) && !defined(USE_ALIGN_PTWO)
675 {"align", s_align_bytes
, 0},
677 {"align", s_align_ptwo
, 0},
679 {"arch", set_cpu_arch
, 0},
683 {"ffloat", float_cons
, 'f'},
684 {"dfloat", float_cons
, 'd'},
685 {"tfloat", float_cons
, 'x'},
687 {"slong", signed_cons
, 4},
688 {"noopt", s_ignore
, 0},
689 {"optim", s_ignore
, 0},
690 {"code16gcc", set_16bit_gcc_code_flag
, CODE_16BIT
},
691 {"code16", set_code_flag
, CODE_16BIT
},
692 {"code32", set_code_flag
, CODE_32BIT
},
693 {"code64", set_code_flag
, CODE_64BIT
},
694 {"intel_syntax", set_intel_syntax
, 1},
695 {"att_syntax", set_intel_syntax
, 0},
696 {"intel_mnemonic", set_intel_mnemonic
, 1},
697 {"att_mnemonic", set_intel_mnemonic
, 0},
698 {"allow_index_reg", set_allow_index_reg
, 1},
699 {"disallow_index_reg", set_allow_index_reg
, 0},
700 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
701 {"largecomm", handle_large_common
, 0},
703 {"file", (void (*) (int)) dwarf2_directive_file
, 0},
704 {"loc", dwarf2_directive_loc
, 0},
705 {"loc_mark_labels", dwarf2_directive_loc_mark_labels
, 0},
708 {"secrel32", pe_directive_secrel
, 0},
713 /* For interface with expression (). */
714 extern char *input_line_pointer
;
716 /* Hash table for instruction mnemonic lookup. */
717 static struct hash_control
*op_hash
;
719 /* Hash table for register lookup. */
720 static struct hash_control
*reg_hash
;
723 i386_align_code (fragS
*fragP
, int count
)
725 /* Various efficient no-op patterns for aligning code labels.
726 Note: Don't try to assemble the instructions in the comments.
727 0L and 0w are not legal. */
728 static const char f32_1
[] =
730 static const char f32_2
[] =
731 {0x66,0x90}; /* xchg %ax,%ax */
732 static const char f32_3
[] =
733 {0x8d,0x76,0x00}; /* leal 0(%esi),%esi */
734 static const char f32_4
[] =
735 {0x8d,0x74,0x26,0x00}; /* leal 0(%esi,1),%esi */
736 static const char f32_5
[] =
738 0x8d,0x74,0x26,0x00}; /* leal 0(%esi,1),%esi */
739 static const char f32_6
[] =
740 {0x8d,0xb6,0x00,0x00,0x00,0x00}; /* leal 0L(%esi),%esi */
741 static const char f32_7
[] =
742 {0x8d,0xb4,0x26,0x00,0x00,0x00,0x00}; /* leal 0L(%esi,1),%esi */
743 static const char f32_8
[] =
745 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00}; /* leal 0L(%esi,1),%esi */
746 static const char f32_9
[] =
747 {0x89,0xf6, /* movl %esi,%esi */
748 0x8d,0xbc,0x27,0x00,0x00,0x00,0x00}; /* leal 0L(%edi,1),%edi */
749 static const char f32_10
[] =
750 {0x8d,0x76,0x00, /* leal 0(%esi),%esi */
751 0x8d,0xbc,0x27,0x00,0x00,0x00,0x00}; /* leal 0L(%edi,1),%edi */
752 static const char f32_11
[] =
753 {0x8d,0x74,0x26,0x00, /* leal 0(%esi,1),%esi */
754 0x8d,0xbc,0x27,0x00,0x00,0x00,0x00}; /* leal 0L(%edi,1),%edi */
755 static const char f32_12
[] =
756 {0x8d,0xb6,0x00,0x00,0x00,0x00, /* leal 0L(%esi),%esi */
757 0x8d,0xbf,0x00,0x00,0x00,0x00}; /* leal 0L(%edi),%edi */
758 static const char f32_13
[] =
759 {0x8d,0xb6,0x00,0x00,0x00,0x00, /* leal 0L(%esi),%esi */
760 0x8d,0xbc,0x27,0x00,0x00,0x00,0x00}; /* leal 0L(%edi,1),%edi */
761 static const char f32_14
[] =
762 {0x8d,0xb4,0x26,0x00,0x00,0x00,0x00, /* leal 0L(%esi,1),%esi */
763 0x8d,0xbc,0x27,0x00,0x00,0x00,0x00}; /* leal 0L(%edi,1),%edi */
764 static const char f16_3
[] =
765 {0x8d,0x74,0x00}; /* lea 0(%esi),%esi */
766 static const char f16_4
[] =
767 {0x8d,0xb4,0x00,0x00}; /* lea 0w(%si),%si */
768 static const char f16_5
[] =
770 0x8d,0xb4,0x00,0x00}; /* lea 0w(%si),%si */
771 static const char f16_6
[] =
772 {0x89,0xf6, /* mov %si,%si */
773 0x8d,0xbd,0x00,0x00}; /* lea 0w(%di),%di */
774 static const char f16_7
[] =
775 {0x8d,0x74,0x00, /* lea 0(%si),%si */
776 0x8d,0xbd,0x00,0x00}; /* lea 0w(%di),%di */
777 static const char f16_8
[] =
778 {0x8d,0xb4,0x00,0x00, /* lea 0w(%si),%si */
779 0x8d,0xbd,0x00,0x00}; /* lea 0w(%di),%di */
780 static const char jump_31
[] =
781 {0xeb,0x1d,0x90,0x90,0x90,0x90,0x90, /* jmp .+31; lotsa nops */
782 0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,
783 0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,
784 0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90};
785 static const char *const f32_patt
[] = {
786 f32_1
, f32_2
, f32_3
, f32_4
, f32_5
, f32_6
, f32_7
, f32_8
,
787 f32_9
, f32_10
, f32_11
, f32_12
, f32_13
, f32_14
789 static const char *const f16_patt
[] = {
790 f32_1
, f32_2
, f16_3
, f16_4
, f16_5
, f16_6
, f16_7
, f16_8
793 static const char alt_3
[] =
795 /* nopl 0(%[re]ax) */
796 static const char alt_4
[] =
797 {0x0f,0x1f,0x40,0x00};
798 /* nopl 0(%[re]ax,%[re]ax,1) */
799 static const char alt_5
[] =
800 {0x0f,0x1f,0x44,0x00,0x00};
801 /* nopw 0(%[re]ax,%[re]ax,1) */
802 static const char alt_6
[] =
803 {0x66,0x0f,0x1f,0x44,0x00,0x00};
804 /* nopl 0L(%[re]ax) */
805 static const char alt_7
[] =
806 {0x0f,0x1f,0x80,0x00,0x00,0x00,0x00};
807 /* nopl 0L(%[re]ax,%[re]ax,1) */
808 static const char alt_8
[] =
809 {0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
810 /* nopw 0L(%[re]ax,%[re]ax,1) */
811 static const char alt_9
[] =
812 {0x66,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
813 /* nopw %cs:0L(%[re]ax,%[re]ax,1) */
814 static const char alt_10
[] =
815 {0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
817 nopw %cs:0L(%[re]ax,%[re]ax,1) */
818 static const char alt_long_11
[] =
820 0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
823 nopw %cs:0L(%[re]ax,%[re]ax,1) */
824 static const char alt_long_12
[] =
827 0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
831 nopw %cs:0L(%[re]ax,%[re]ax,1) */
832 static const char alt_long_13
[] =
836 0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
841 nopw %cs:0L(%[re]ax,%[re]ax,1) */
842 static const char alt_long_14
[] =
847 0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
853 nopw %cs:0L(%[re]ax,%[re]ax,1) */
854 static const char alt_long_15
[] =
860 0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
861 /* nopl 0(%[re]ax,%[re]ax,1)
862 nopw 0(%[re]ax,%[re]ax,1) */
863 static const char alt_short_11
[] =
864 {0x0f,0x1f,0x44,0x00,0x00,
865 0x66,0x0f,0x1f,0x44,0x00,0x00};
866 /* nopw 0(%[re]ax,%[re]ax,1)
867 nopw 0(%[re]ax,%[re]ax,1) */
868 static const char alt_short_12
[] =
869 {0x66,0x0f,0x1f,0x44,0x00,0x00,
870 0x66,0x0f,0x1f,0x44,0x00,0x00};
871 /* nopw 0(%[re]ax,%[re]ax,1)
873 static const char alt_short_13
[] =
874 {0x66,0x0f,0x1f,0x44,0x00,0x00,
875 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00};
878 static const char alt_short_14
[] =
879 {0x0f,0x1f,0x80,0x00,0x00,0x00,0x00,
880 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00};
882 nopl 0L(%[re]ax,%[re]ax,1) */
883 static const char alt_short_15
[] =
884 {0x0f,0x1f,0x80,0x00,0x00,0x00,0x00,
885 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
886 static const char *const alt_short_patt
[] = {
887 f32_1
, f32_2
, alt_3
, alt_4
, alt_5
, alt_6
, alt_7
, alt_8
,
888 alt_9
, alt_10
, alt_short_11
, alt_short_12
, alt_short_13
,
889 alt_short_14
, alt_short_15
891 static const char *const alt_long_patt
[] = {
892 f32_1
, f32_2
, alt_3
, alt_4
, alt_5
, alt_6
, alt_7
, alt_8
,
893 alt_9
, alt_10
, alt_long_11
, alt_long_12
, alt_long_13
,
894 alt_long_14
, alt_long_15
897 /* Only align for at least a positive non-zero boundary. */
898 if (count
<= 0 || count
> MAX_MEM_FOR_RS_ALIGN_CODE
)
901 /* We need to decide which NOP sequence to use for 32bit and
902 64bit. When -mtune= is used:
904 1. For PROCESSOR_I386, PROCESSOR_I486, PROCESSOR_PENTIUM and
905 PROCESSOR_GENERIC32, f32_patt will be used.
906 2. For PROCESSOR_PENTIUMPRO, PROCESSOR_PENTIUM4, PROCESSOR_NOCONA,
907 PROCESSOR_CORE, PROCESSOR_CORE2, and PROCESSOR_GENERIC64,
908 alt_long_patt will be used.
909 3. For PROCESSOR_ATHLON, PROCESSOR_K6, PROCESSOR_K8 and
910 PROCESSOR_AMDFAM10, alt_short_patt will be used.
912 When -mtune= isn't used, alt_long_patt will be used if
913 cpu_arch_isa_flags has Cpu686. Otherwise, f32_patt will
916 When -march= or .arch is used, we can't use anything beyond
917 cpu_arch_isa_flags. */
919 if (flag_code
== CODE_16BIT
)
923 memcpy (fragP
->fr_literal
+ fragP
->fr_fix
,
925 /* Adjust jump offset. */
926 fragP
->fr_literal
[fragP
->fr_fix
+ 1] = count
- 2;
929 memcpy (fragP
->fr_literal
+ fragP
->fr_fix
,
930 f16_patt
[count
- 1], count
);
934 const char *const *patt
= NULL
;
936 if (cpu_arch_isa
== PROCESSOR_UNKNOWN
)
938 /* PROCESSOR_UNKNOWN means that all ISAs may be used. */
939 switch (cpu_arch_tune
)
941 case PROCESSOR_UNKNOWN
:
942 /* We use cpu_arch_isa_flags to check if we SHOULD
943 optimize for Cpu686. */
944 if (cpu_arch_isa_flags
.bitfield
.cpui686
)
945 patt
= alt_long_patt
;
949 case PROCESSOR_PENTIUMPRO
:
950 case PROCESSOR_PENTIUM4
:
951 case PROCESSOR_NOCONA
:
953 case PROCESSOR_CORE2
:
954 case PROCESSOR_GENERIC64
:
955 patt
= alt_long_patt
;
958 case PROCESSOR_ATHLON
:
960 case PROCESSOR_AMDFAM10
:
961 patt
= alt_short_patt
;
965 case PROCESSOR_PENTIUM
:
966 case PROCESSOR_GENERIC32
:
973 switch (cpu_arch_tune
)
975 case PROCESSOR_UNKNOWN
:
976 /* When cpu_arch_isa is net, cpu_arch_tune shouldn't be
977 PROCESSOR_UNKNOWN. */
983 case PROCESSOR_PENTIUM
:
985 case PROCESSOR_ATHLON
:
987 case PROCESSOR_AMDFAM10
:
988 case PROCESSOR_GENERIC32
:
989 /* We use cpu_arch_isa_flags to check if we CAN optimize
991 if (cpu_arch_isa_flags
.bitfield
.cpui686
)
992 patt
= alt_short_patt
;
996 case PROCESSOR_PENTIUMPRO
:
997 case PROCESSOR_PENTIUM4
:
998 case PROCESSOR_NOCONA
:
1000 case PROCESSOR_CORE2
:
1001 if (cpu_arch_isa_flags
.bitfield
.cpui686
)
1002 patt
= alt_long_patt
;
1006 case PROCESSOR_GENERIC64
:
1007 patt
= alt_long_patt
;
1012 if (patt
== f32_patt
)
1014 /* If the padding is less than 15 bytes, we use the normal
1015 ones. Otherwise, we use a jump instruction and adjust
1018 memcpy (fragP
->fr_literal
+ fragP
->fr_fix
,
1019 patt
[count
- 1], count
);
1022 memcpy (fragP
->fr_literal
+ fragP
->fr_fix
,
1024 /* Adjust jump offset. */
1025 fragP
->fr_literal
[fragP
->fr_fix
+ 1] = count
- 2;
1030 /* Maximum length of an instruction is 15 byte. If the
1031 padding is greater than 15 bytes and we don't use jump,
1032 we have to break it into smaller pieces. */
1033 int padding
= count
;
1034 while (padding
> 15)
1037 memcpy (fragP
->fr_literal
+ fragP
->fr_fix
+ padding
,
1042 memcpy (fragP
->fr_literal
+ fragP
->fr_fix
,
1043 patt
[padding
- 1], padding
);
1046 fragP
->fr_var
= count
;
1050 operand_type_all_zero (const union i386_operand_type
*x
)
1052 switch (ARRAY_SIZE(x
->array
))
1061 return !x
->array
[0];
1068 operand_type_set (union i386_operand_type
*x
, unsigned int v
)
1070 switch (ARRAY_SIZE(x
->array
))
1085 operand_type_equal (const union i386_operand_type
*x
,
1086 const union i386_operand_type
*y
)
1088 switch (ARRAY_SIZE(x
->array
))
1091 if (x
->array
[2] != y
->array
[2])
1094 if (x
->array
[1] != y
->array
[1])
1097 return x
->array
[0] == y
->array
[0];
1105 cpu_flags_all_zero (const union i386_cpu_flags
*x
)
1107 switch (ARRAY_SIZE(x
->array
))
1116 return !x
->array
[0];
1123 cpu_flags_set (union i386_cpu_flags
*x
, unsigned int v
)
1125 switch (ARRAY_SIZE(x
->array
))
1140 cpu_flags_equal (const union i386_cpu_flags
*x
,
1141 const union i386_cpu_flags
*y
)
1143 switch (ARRAY_SIZE(x
->array
))
1146 if (x
->array
[2] != y
->array
[2])
1149 if (x
->array
[1] != y
->array
[1])
1152 return x
->array
[0] == y
->array
[0];
1160 cpu_flags_check_cpu64 (i386_cpu_flags f
)
1162 return !((flag_code
== CODE_64BIT
&& f
.bitfield
.cpuno64
)
1163 || (flag_code
!= CODE_64BIT
&& f
.bitfield
.cpu64
));
1166 static INLINE i386_cpu_flags
1167 cpu_flags_and (i386_cpu_flags x
, i386_cpu_flags y
)
1169 switch (ARRAY_SIZE (x
.array
))
1172 x
.array
[2] &= y
.array
[2];
1174 x
.array
[1] &= y
.array
[1];
1176 x
.array
[0] &= y
.array
[0];
1184 static INLINE i386_cpu_flags
1185 cpu_flags_or (i386_cpu_flags x
, i386_cpu_flags y
)
1187 switch (ARRAY_SIZE (x
.array
))
1190 x
.array
[2] |= y
.array
[2];
1192 x
.array
[1] |= y
.array
[1];
1194 x
.array
[0] |= y
.array
[0];
1202 #define CPU_FLAGS_ARCH_MATCH 0x1
1203 #define CPU_FLAGS_64BIT_MATCH 0x2
1205 #define CPU_FLAGS_32BIT_MATCH CPU_FLAGS_ARCH_MATCH
1206 #define CPU_FLAGS_PERFECT_MATCH \
1207 (CPU_FLAGS_32BIT_MATCH | CPU_FLAGS_64BIT_MATCH)
1209 /* Return CPU flags match bits. */
1212 cpu_flags_match (const template *t
)
1214 i386_cpu_flags x
= t
->cpu_flags
;
1215 int match
= cpu_flags_check_cpu64 (x
) ? CPU_FLAGS_64BIT_MATCH
: 0;
1217 x
.bitfield
.cpu64
= 0;
1218 x
.bitfield
.cpuno64
= 0;
1220 if (cpu_flags_all_zero (&x
))
1222 /* This instruction is available on all archs. */
1223 match
|= CPU_FLAGS_32BIT_MATCH
;
1227 /* This instruction is available only on some archs. */
1228 i386_cpu_flags cpu
= cpu_arch_flags
;
1230 cpu
.bitfield
.cpu64
= 0;
1231 cpu
.bitfield
.cpuno64
= 0;
1232 cpu
= cpu_flags_and (x
, cpu
);
1233 if (!cpu_flags_all_zero (&cpu
))
1236 if (!t
->opcode_modifier
.sse2avx
|| sse2avx
)
1237 match
|= CPU_FLAGS_32BIT_MATCH
;
1243 static INLINE i386_operand_type
1244 operand_type_and (i386_operand_type x
, i386_operand_type y
)
1246 switch (ARRAY_SIZE (x
.array
))
1249 x
.array
[2] &= y
.array
[2];
1251 x
.array
[1] &= y
.array
[1];
1253 x
.array
[0] &= y
.array
[0];
1261 static INLINE i386_operand_type
1262 operand_type_or (i386_operand_type x
, i386_operand_type y
)
1264 switch (ARRAY_SIZE (x
.array
))
1267 x
.array
[2] |= y
.array
[2];
1269 x
.array
[1] |= y
.array
[1];
1271 x
.array
[0] |= y
.array
[0];
1279 static INLINE i386_operand_type
1280 operand_type_xor (i386_operand_type x
, i386_operand_type y
)
1282 switch (ARRAY_SIZE (x
.array
))
1285 x
.array
[2] ^= y
.array
[2];
1287 x
.array
[1] ^= y
.array
[1];
1289 x
.array
[0] ^= y
.array
[0];
1297 static const i386_operand_type acc32
= OPERAND_TYPE_ACC32
;
1298 static const i386_operand_type acc64
= OPERAND_TYPE_ACC64
;
1299 static const i386_operand_type control
= OPERAND_TYPE_CONTROL
;
1300 static const i386_operand_type inoutportreg
1301 = OPERAND_TYPE_INOUTPORTREG
;
1302 static const i386_operand_type reg16_inoutportreg
1303 = OPERAND_TYPE_REG16_INOUTPORTREG
;
1304 static const i386_operand_type disp16
= OPERAND_TYPE_DISP16
;
1305 static const i386_operand_type disp32
= OPERAND_TYPE_DISP32
;
1306 static const i386_operand_type disp32s
= OPERAND_TYPE_DISP32S
;
1307 static const i386_operand_type disp16_32
= OPERAND_TYPE_DISP16_32
;
1308 static const i386_operand_type anydisp
1309 = OPERAND_TYPE_ANYDISP
;
1310 static const i386_operand_type regxmm
= OPERAND_TYPE_REGXMM
;
1311 static const i386_operand_type regymm
= OPERAND_TYPE_REGYMM
;
1312 static const i386_operand_type imm8
= OPERAND_TYPE_IMM8
;
1313 static const i386_operand_type imm8s
= OPERAND_TYPE_IMM8S
;
1314 static const i386_operand_type imm16
= OPERAND_TYPE_IMM16
;
1315 static const i386_operand_type imm32
= OPERAND_TYPE_IMM32
;
1316 static const i386_operand_type imm32s
= OPERAND_TYPE_IMM32S
;
1317 static const i386_operand_type imm64
= OPERAND_TYPE_IMM64
;
1318 static const i386_operand_type imm16_32
= OPERAND_TYPE_IMM16_32
;
1319 static const i386_operand_type imm16_32s
= OPERAND_TYPE_IMM16_32S
;
1320 static const i386_operand_type imm16_32_32s
= OPERAND_TYPE_IMM16_32_32S
;
1321 static const i386_operand_type vex_imm4
= OPERAND_TYPE_VEX_IMM4
;
1332 operand_type_check (i386_operand_type t
, enum operand_type c
)
1337 return (t
.bitfield
.reg8
1340 || t
.bitfield
.reg64
);
1343 return (t
.bitfield
.imm8
1347 || t
.bitfield
.imm32s
1348 || t
.bitfield
.imm64
);
1351 return (t
.bitfield
.disp8
1352 || t
.bitfield
.disp16
1353 || t
.bitfield
.disp32
1354 || t
.bitfield
.disp32s
1355 || t
.bitfield
.disp64
);
1358 return (t
.bitfield
.disp8
1359 || t
.bitfield
.disp16
1360 || t
.bitfield
.disp32
1361 || t
.bitfield
.disp32s
1362 || t
.bitfield
.disp64
1363 || t
.bitfield
.baseindex
);
1370 /* Return 1 if there is no conflict in 8bit/16bit/32bit/64bit on
1371 operand J for instruction template T. */
1374 match_reg_size (const template *t
, unsigned int j
)
1376 return !((i
.types
[j
].bitfield
.byte
1377 && !t
->operand_types
[j
].bitfield
.byte
)
1378 || (i
.types
[j
].bitfield
.word
1379 && !t
->operand_types
[j
].bitfield
.word
)
1380 || (i
.types
[j
].bitfield
.dword
1381 && !t
->operand_types
[j
].bitfield
.dword
)
1382 || (i
.types
[j
].bitfield
.qword
1383 && !t
->operand_types
[j
].bitfield
.qword
));
1386 /* Return 1 if there is no conflict in any size on operand J for
1387 instruction template T. */
1390 match_mem_size (const template *t
, unsigned int j
)
1392 return (match_reg_size (t
, j
)
1393 && !((i
.types
[j
].bitfield
.unspecified
1394 && !t
->operand_types
[j
].bitfield
.unspecified
)
1395 || (i
.types
[j
].bitfield
.fword
1396 && !t
->operand_types
[j
].bitfield
.fword
)
1397 || (i
.types
[j
].bitfield
.tbyte
1398 && !t
->operand_types
[j
].bitfield
.tbyte
)
1399 || (i
.types
[j
].bitfield
.xmmword
1400 && !t
->operand_types
[j
].bitfield
.xmmword
)
1401 || (i
.types
[j
].bitfield
.ymmword
1402 && !t
->operand_types
[j
].bitfield
.ymmword
)));
1405 /* Return 1 if there is no size conflict on any operands for
1406 instruction template T. */
1409 operand_size_match (const template *t
)
1414 /* Don't check jump instructions. */
1415 if (t
->opcode_modifier
.jump
1416 || t
->opcode_modifier
.jumpbyte
1417 || t
->opcode_modifier
.jumpdword
1418 || t
->opcode_modifier
.jumpintersegment
)
1421 /* Check memory and accumulator operand size. */
1422 for (j
= 0; j
< i
.operands
; j
++)
1424 if (t
->operand_types
[j
].bitfield
.anysize
)
1427 if (t
->operand_types
[j
].bitfield
.acc
&& !match_reg_size (t
, j
))
1433 if (i
.types
[j
].bitfield
.mem
&& !match_mem_size (t
, j
))
1441 || (!t
->opcode_modifier
.d
&& !t
->opcode_modifier
.floatd
))
1444 /* Check reverse. */
1445 assert (i
.operands
== 2);
1448 for (j
= 0; j
< 2; j
++)
1450 if (t
->operand_types
[j
].bitfield
.acc
1451 && !match_reg_size (t
, j
? 0 : 1))
1457 if (i
.types
[j
].bitfield
.mem
1458 && !match_mem_size (t
, j
? 0 : 1))
1469 operand_type_match (i386_operand_type overlap
,
1470 i386_operand_type given
)
1472 i386_operand_type temp
= overlap
;
1474 temp
.bitfield
.jumpabsolute
= 0;
1475 temp
.bitfield
.unspecified
= 0;
1476 temp
.bitfield
.byte
= 0;
1477 temp
.bitfield
.word
= 0;
1478 temp
.bitfield
.dword
= 0;
1479 temp
.bitfield
.fword
= 0;
1480 temp
.bitfield
.qword
= 0;
1481 temp
.bitfield
.tbyte
= 0;
1482 temp
.bitfield
.xmmword
= 0;
1483 temp
.bitfield
.ymmword
= 0;
1484 if (operand_type_all_zero (&temp
))
1487 return (given
.bitfield
.baseindex
== overlap
.bitfield
.baseindex
1488 && given
.bitfield
.jumpabsolute
== overlap
.bitfield
.jumpabsolute
);
1491 /* If given types g0 and g1 are registers they must be of the same type
1492 unless the expected operand type register overlap is null.
1493 Note that Acc in a template matches every size of reg. */
1496 operand_type_register_match (i386_operand_type m0
,
1497 i386_operand_type g0
,
1498 i386_operand_type t0
,
1499 i386_operand_type m1
,
1500 i386_operand_type g1
,
1501 i386_operand_type t1
)
1503 if (!operand_type_check (g0
, reg
))
1506 if (!operand_type_check (g1
, reg
))
1509 if (g0
.bitfield
.reg8
== g1
.bitfield
.reg8
1510 && g0
.bitfield
.reg16
== g1
.bitfield
.reg16
1511 && g0
.bitfield
.reg32
== g1
.bitfield
.reg32
1512 && g0
.bitfield
.reg64
== g1
.bitfield
.reg64
)
1515 if (m0
.bitfield
.acc
)
1517 t0
.bitfield
.reg8
= 1;
1518 t0
.bitfield
.reg16
= 1;
1519 t0
.bitfield
.reg32
= 1;
1520 t0
.bitfield
.reg64
= 1;
1523 if (m1
.bitfield
.acc
)
1525 t1
.bitfield
.reg8
= 1;
1526 t1
.bitfield
.reg16
= 1;
1527 t1
.bitfield
.reg32
= 1;
1528 t1
.bitfield
.reg64
= 1;
1531 return (!(t0
.bitfield
.reg8
& t1
.bitfield
.reg8
)
1532 && !(t0
.bitfield
.reg16
& t1
.bitfield
.reg16
)
1533 && !(t0
.bitfield
.reg32
& t1
.bitfield
.reg32
)
1534 && !(t0
.bitfield
.reg64
& t1
.bitfield
.reg64
));
1537 static INLINE
unsigned int
1538 mode_from_disp_size (i386_operand_type t
)
1540 if (t
.bitfield
.disp8
)
1542 else if (t
.bitfield
.disp16
1543 || t
.bitfield
.disp32
1544 || t
.bitfield
.disp32s
)
1551 fits_in_signed_byte (offsetT num
)
1553 return (num
>= -128) && (num
<= 127);
1557 fits_in_unsigned_byte (offsetT num
)
1559 return (num
& 0xff) == num
;
1563 fits_in_unsigned_word (offsetT num
)
1565 return (num
& 0xffff) == num
;
1569 fits_in_signed_word (offsetT num
)
1571 return (-32768 <= num
) && (num
<= 32767);
1575 fits_in_signed_long (offsetT num ATTRIBUTE_UNUSED
)
1580 return (!(((offsetT
) -1 << 31) & num
)
1581 || (((offsetT
) -1 << 31) & num
) == ((offsetT
) -1 << 31));
1583 } /* fits_in_signed_long() */
1586 fits_in_unsigned_long (offsetT num ATTRIBUTE_UNUSED
)
1591 return (num
& (((offsetT
) 2 << 31) - 1)) == num
;
1593 } /* fits_in_unsigned_long() */
1596 fits_in_imm4 (offsetT num
)
1598 return (num
& 0xf) == num
;
1601 static i386_operand_type
1602 smallest_imm_type (offsetT num
)
1604 i386_operand_type t
;
1606 operand_type_set (&t
, 0);
1607 t
.bitfield
.imm64
= 1;
1609 if (cpu_arch_tune
!= PROCESSOR_I486
&& num
== 1)
1611 /* This code is disabled on the 486 because all the Imm1 forms
1612 in the opcode table are slower on the i486. They're the
1613 versions with the implicitly specified single-position
1614 displacement, which has another syntax if you really want to
1616 t
.bitfield
.imm1
= 1;
1617 t
.bitfield
.imm8
= 1;
1618 t
.bitfield
.imm8s
= 1;
1619 t
.bitfield
.imm16
= 1;
1620 t
.bitfield
.imm32
= 1;
1621 t
.bitfield
.imm32s
= 1;
1623 else if (fits_in_signed_byte (num
))
1625 t
.bitfield
.imm8
= 1;
1626 t
.bitfield
.imm8s
= 1;
1627 t
.bitfield
.imm16
= 1;
1628 t
.bitfield
.imm32
= 1;
1629 t
.bitfield
.imm32s
= 1;
1631 else if (fits_in_unsigned_byte (num
))
1633 t
.bitfield
.imm8
= 1;
1634 t
.bitfield
.imm16
= 1;
1635 t
.bitfield
.imm32
= 1;
1636 t
.bitfield
.imm32s
= 1;
1638 else if (fits_in_signed_word (num
) || fits_in_unsigned_word (num
))
1640 t
.bitfield
.imm16
= 1;
1641 t
.bitfield
.imm32
= 1;
1642 t
.bitfield
.imm32s
= 1;
1644 else if (fits_in_signed_long (num
))
1646 t
.bitfield
.imm32
= 1;
1647 t
.bitfield
.imm32s
= 1;
1649 else if (fits_in_unsigned_long (num
))
1650 t
.bitfield
.imm32
= 1;
1656 offset_in_range (offsetT val
, int size
)
1662 case 1: mask
= ((addressT
) 1 << 8) - 1; break;
1663 case 2: mask
= ((addressT
) 1 << 16) - 1; break;
1664 case 4: mask
= ((addressT
) 2 << 31) - 1; break;
1666 case 8: mask
= ((addressT
) 2 << 63) - 1; break;
1671 /* If BFD64, sign extend val. */
1672 if (!use_rela_relocations
)
1673 if ((val
& ~(((addressT
) 2 << 31) - 1)) == 0)
1674 val
= (val
^ ((addressT
) 1 << 31)) - ((addressT
) 1 << 31);
1676 if ((val
& ~mask
) != 0 && (val
& ~mask
) != ~mask
)
1678 char buf1
[40], buf2
[40];
1680 sprint_value (buf1
, val
);
1681 sprint_value (buf2
, val
& mask
);
1682 as_warn (_("%s shortened to %s"), buf1
, buf2
);
1687 /* Returns 0 if attempting to add a prefix where one from the same
1688 class already exists, 1 if non rep/repne added, 2 if rep/repne
1691 add_prefix (unsigned int prefix
)
1696 if (prefix
>= REX_OPCODE
&& prefix
< REX_OPCODE
+ 16
1697 && flag_code
== CODE_64BIT
)
1699 if ((i
.prefix
[REX_PREFIX
] & prefix
& REX_W
)
1700 || ((i
.prefix
[REX_PREFIX
] & (REX_R
| REX_X
| REX_B
))
1701 && (prefix
& (REX_R
| REX_X
| REX_B
))))
1712 case CS_PREFIX_OPCODE
:
1713 case DS_PREFIX_OPCODE
:
1714 case ES_PREFIX_OPCODE
:
1715 case FS_PREFIX_OPCODE
:
1716 case GS_PREFIX_OPCODE
:
1717 case SS_PREFIX_OPCODE
:
1721 case REPNE_PREFIX_OPCODE
:
1722 case REPE_PREFIX_OPCODE
:
1725 case LOCK_PREFIX_OPCODE
:
1733 case ADDR_PREFIX_OPCODE
:
1737 case DATA_PREFIX_OPCODE
:
1741 if (i
.prefix
[q
] != 0)
1749 i
.prefix
[q
] |= prefix
;
1752 as_bad (_("same type of prefix used twice"));
1758 set_code_flag (int value
)
1761 if (flag_code
== CODE_64BIT
)
1763 cpu_arch_flags
.bitfield
.cpu64
= 1;
1764 cpu_arch_flags
.bitfield
.cpuno64
= 0;
1768 cpu_arch_flags
.bitfield
.cpu64
= 0;
1769 cpu_arch_flags
.bitfield
.cpuno64
= 1;
1771 if (value
== CODE_64BIT
&& !cpu_arch_flags
.bitfield
.cpulm
)
1773 as_bad (_("64bit mode not supported on this CPU."));
1775 if (value
== CODE_32BIT
&& !cpu_arch_flags
.bitfield
.cpui386
)
1777 as_bad (_("32bit mode not supported on this CPU."));
1779 stackop_size
= '\0';
1783 set_16bit_gcc_code_flag (int new_code_flag
)
1785 flag_code
= new_code_flag
;
1786 if (flag_code
!= CODE_16BIT
)
1788 cpu_arch_flags
.bitfield
.cpu64
= 0;
1789 cpu_arch_flags
.bitfield
.cpuno64
= 1;
1790 stackop_size
= LONG_MNEM_SUFFIX
;
1794 set_intel_syntax (int syntax_flag
)
1796 /* Find out if register prefixing is specified. */
1797 int ask_naked_reg
= 0;
1800 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1802 char *string
= input_line_pointer
;
1803 int e
= get_symbol_end ();
1805 if (strcmp (string
, "prefix") == 0)
1807 else if (strcmp (string
, "noprefix") == 0)
1810 as_bad (_("bad argument to syntax directive."));
1811 *input_line_pointer
= e
;
1813 demand_empty_rest_of_line ();
1815 intel_syntax
= syntax_flag
;
1817 if (ask_naked_reg
== 0)
1818 allow_naked_reg
= (intel_syntax
1819 && (bfd_get_symbol_leading_char (stdoutput
) != '\0'));
1821 allow_naked_reg
= (ask_naked_reg
< 0);
1823 identifier_chars
['%'] = intel_syntax
&& allow_naked_reg
? '%' : 0;
1824 identifier_chars
['$'] = intel_syntax
? '$' : 0;
1825 register_prefix
= allow_naked_reg
? "" : "%";
1829 set_intel_mnemonic (int mnemonic_flag
)
1831 intel_mnemonic
= mnemonic_flag
;
1835 set_allow_index_reg (int flag
)
1837 allow_index_reg
= flag
;
1841 set_cpu_arch (int dummy ATTRIBUTE_UNUSED
)
1845 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1847 char *string
= input_line_pointer
;
1848 int e
= get_symbol_end ();
1850 i386_cpu_flags flags
;
1852 for (i
= 0; i
< ARRAY_SIZE (cpu_arch
); i
++)
1854 if (strcmp (string
, cpu_arch
[i
].name
) == 0)
1858 cpu_arch_name
= cpu_arch
[i
].name
;
1859 cpu_sub_arch_name
= NULL
;
1860 cpu_arch_flags
= cpu_arch
[i
].flags
;
1861 if (flag_code
== CODE_64BIT
)
1863 cpu_arch_flags
.bitfield
.cpu64
= 1;
1864 cpu_arch_flags
.bitfield
.cpuno64
= 0;
1868 cpu_arch_flags
.bitfield
.cpu64
= 0;
1869 cpu_arch_flags
.bitfield
.cpuno64
= 1;
1871 cpu_arch_isa
= cpu_arch
[i
].type
;
1872 cpu_arch_isa_flags
= cpu_arch
[i
].flags
;
1873 if (!cpu_arch_tune_set
)
1875 cpu_arch_tune
= cpu_arch_isa
;
1876 cpu_arch_tune_flags
= cpu_arch_isa_flags
;
1881 flags
= cpu_flags_or (cpu_arch_flags
,
1883 if (!cpu_flags_equal (&flags
, &cpu_arch_flags
))
1885 if (cpu_sub_arch_name
)
1887 char *name
= cpu_sub_arch_name
;
1888 cpu_sub_arch_name
= concat (name
,
1890 (const char *) NULL
);
1894 cpu_sub_arch_name
= xstrdup (cpu_arch
[i
].name
);
1895 cpu_arch_flags
= flags
;
1897 *input_line_pointer
= e
;
1898 demand_empty_rest_of_line ();
1902 if (i
>= ARRAY_SIZE (cpu_arch
))
1903 as_bad (_("no such architecture: `%s'"), string
);
1905 *input_line_pointer
= e
;
1908 as_bad (_("missing cpu architecture"));
1910 no_cond_jump_promotion
= 0;
1911 if (*input_line_pointer
== ','
1912 && !is_end_of_line
[(unsigned char) input_line_pointer
[1]])
1914 char *string
= ++input_line_pointer
;
1915 int e
= get_symbol_end ();
1917 if (strcmp (string
, "nojumps") == 0)
1918 no_cond_jump_promotion
= 1;
1919 else if (strcmp (string
, "jumps") == 0)
1922 as_bad (_("no such architecture modifier: `%s'"), string
);
1924 *input_line_pointer
= e
;
1927 demand_empty_rest_of_line ();
1933 if (!strcmp (default_arch
, "x86_64"))
1934 return bfd_mach_x86_64
;
1935 else if (!strcmp (default_arch
, "i386"))
1936 return bfd_mach_i386_i386
;
1938 as_fatal (_("Unknown architecture"));
1944 const char *hash_err
;
1946 /* Initialize op_hash hash table. */
1947 op_hash
= hash_new ();
1950 const template *optab
;
1951 templates
*core_optab
;
1953 /* Setup for loop. */
1955 core_optab
= (templates
*) xmalloc (sizeof (templates
));
1956 core_optab
->start
= optab
;
1961 if (optab
->name
== NULL
1962 || strcmp (optab
->name
, (optab
- 1)->name
) != 0)
1964 /* different name --> ship out current template list;
1965 add to hash table; & begin anew. */
1966 core_optab
->end
= optab
;
1967 hash_err
= hash_insert (op_hash
,
1972 as_fatal (_("Internal Error: Can't hash %s: %s"),
1976 if (optab
->name
== NULL
)
1978 core_optab
= (templates
*) xmalloc (sizeof (templates
));
1979 core_optab
->start
= optab
;
1984 /* Initialize reg_hash hash table. */
1985 reg_hash
= hash_new ();
1987 const reg_entry
*regtab
;
1988 unsigned int regtab_size
= i386_regtab_size
;
1990 for (regtab
= i386_regtab
; regtab_size
--; regtab
++)
1992 hash_err
= hash_insert (reg_hash
, regtab
->reg_name
, (PTR
) regtab
);
1994 as_fatal (_("Internal Error: Can't hash %s: %s"),
2000 /* Fill in lexical tables: mnemonic_chars, operand_chars. */
2005 for (c
= 0; c
< 256; c
++)
2010 mnemonic_chars
[c
] = c
;
2011 register_chars
[c
] = c
;
2012 operand_chars
[c
] = c
;
2014 else if (ISLOWER (c
))
2016 mnemonic_chars
[c
] = c
;
2017 register_chars
[c
] = c
;
2018 operand_chars
[c
] = c
;
2020 else if (ISUPPER (c
))
2022 mnemonic_chars
[c
] = TOLOWER (c
);
2023 register_chars
[c
] = mnemonic_chars
[c
];
2024 operand_chars
[c
] = c
;
2027 if (ISALPHA (c
) || ISDIGIT (c
))
2028 identifier_chars
[c
] = c
;
2031 identifier_chars
[c
] = c
;
2032 operand_chars
[c
] = c
;
2037 identifier_chars
['@'] = '@';
2040 identifier_chars
['?'] = '?';
2041 operand_chars
['?'] = '?';
2043 digit_chars
['-'] = '-';
2044 mnemonic_chars
['_'] = '_';
2045 mnemonic_chars
['-'] = '-';
2046 mnemonic_chars
['.'] = '.';
2047 identifier_chars
['_'] = '_';
2048 identifier_chars
['.'] = '.';
2050 for (p
= operand_special_chars
; *p
!= '\0'; p
++)
2051 operand_chars
[(unsigned char) *p
] = *p
;
2054 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
2057 record_alignment (text_section
, 2);
2058 record_alignment (data_section
, 2);
2059 record_alignment (bss_section
, 2);
2063 if (flag_code
== CODE_64BIT
)
2065 x86_dwarf2_return_column
= 16;
2066 x86_cie_data_alignment
= -8;
2070 x86_dwarf2_return_column
= 8;
2071 x86_cie_data_alignment
= -4;
2076 i386_print_statistics (FILE *file
)
2078 hash_print_statistics (file
, "i386 opcode", op_hash
);
2079 hash_print_statistics (file
, "i386 register", reg_hash
);
2084 /* Debugging routines for md_assemble. */
2085 static void pte (template *);
2086 static void pt (i386_operand_type
);
2087 static void pe (expressionS
*);
2088 static void ps (symbolS
*);
2091 pi (char *line
, i386_insn
*x
)
2095 fprintf (stdout
, "%s: template ", line
);
2097 fprintf (stdout
, " address: base %s index %s scale %x\n",
2098 x
->base_reg
? x
->base_reg
->reg_name
: "none",
2099 x
->index_reg
? x
->index_reg
->reg_name
: "none",
2100 x
->log2_scale_factor
);
2101 fprintf (stdout
, " modrm: mode %x reg %x reg/mem %x\n",
2102 x
->rm
.mode
, x
->rm
.reg
, x
->rm
.regmem
);
2103 fprintf (stdout
, " sib: base %x index %x scale %x\n",
2104 x
->sib
.base
, x
->sib
.index
, x
->sib
.scale
);
2105 fprintf (stdout
, " rex: 64bit %x extX %x extY %x extZ %x\n",
2106 (x
->rex
& REX_W
) != 0,
2107 (x
->rex
& REX_R
) != 0,
2108 (x
->rex
& REX_X
) != 0,
2109 (x
->rex
& REX_B
) != 0);
2110 fprintf (stdout
, " drex: reg %d rex 0x%x\n",
2111 x
->drex
.reg
, x
->drex
.rex
);
2112 for (i
= 0; i
< x
->operands
; i
++)
2114 fprintf (stdout
, " #%d: ", i
+ 1);
2116 fprintf (stdout
, "\n");
2117 if (x
->types
[i
].bitfield
.reg8
2118 || x
->types
[i
].bitfield
.reg16
2119 || x
->types
[i
].bitfield
.reg32
2120 || x
->types
[i
].bitfield
.reg64
2121 || x
->types
[i
].bitfield
.regmmx
2122 || x
->types
[i
].bitfield
.regxmm
2123 || x
->types
[i
].bitfield
.regymm
2124 || x
->types
[i
].bitfield
.sreg2
2125 || x
->types
[i
].bitfield
.sreg3
2126 || x
->types
[i
].bitfield
.control
2127 || x
->types
[i
].bitfield
.debug
2128 || x
->types
[i
].bitfield
.test
)
2129 fprintf (stdout
, "%s\n", x
->op
[i
].regs
->reg_name
);
2130 if (operand_type_check (x
->types
[i
], imm
))
2132 if (operand_type_check (x
->types
[i
], disp
))
2133 pe (x
->op
[i
].disps
);
2141 fprintf (stdout
, " %d operands ", t
->operands
);
2142 fprintf (stdout
, "opcode %x ", t
->base_opcode
);
2143 if (t
->extension_opcode
!= None
)
2144 fprintf (stdout
, "ext %x ", t
->extension_opcode
);
2145 if (t
->opcode_modifier
.d
)
2146 fprintf (stdout
, "D");
2147 if (t
->opcode_modifier
.w
)
2148 fprintf (stdout
, "W");
2149 fprintf (stdout
, "\n");
2150 for (i
= 0; i
< t
->operands
; i
++)
2152 fprintf (stdout
, " #%d type ", i
+ 1);
2153 pt (t
->operand_types
[i
]);
2154 fprintf (stdout
, "\n");
2161 fprintf (stdout
, " operation %d\n", e
->X_op
);
2162 fprintf (stdout
, " add_number %ld (%lx)\n",
2163 (long) e
->X_add_number
, (long) e
->X_add_number
);
2164 if (e
->X_add_symbol
)
2166 fprintf (stdout
, " add_symbol ");
2167 ps (e
->X_add_symbol
);
2168 fprintf (stdout
, "\n");
2172 fprintf (stdout
, " op_symbol ");
2173 ps (e
->X_op_symbol
);
2174 fprintf (stdout
, "\n");
2181 fprintf (stdout
, "%s type %s%s",
2183 S_IS_EXTERNAL (s
) ? "EXTERNAL " : "",
2184 segment_name (S_GET_SEGMENT (s
)));
2187 static struct type_name
2189 i386_operand_type mask
;
2192 const type_names
[] =
2194 { OPERAND_TYPE_REG8
, "r8" },
2195 { OPERAND_TYPE_REG16
, "r16" },
2196 { OPERAND_TYPE_REG32
, "r32" },
2197 { OPERAND_TYPE_REG64
, "r64" },
2198 { OPERAND_TYPE_IMM8
, "i8" },
2199 { OPERAND_TYPE_IMM8
, "i8s" },
2200 { OPERAND_TYPE_IMM16
, "i16" },
2201 { OPERAND_TYPE_IMM32
, "i32" },
2202 { OPERAND_TYPE_IMM32S
, "i32s" },
2203 { OPERAND_TYPE_IMM64
, "i64" },
2204 { OPERAND_TYPE_IMM1
, "i1" },
2205 { OPERAND_TYPE_BASEINDEX
, "BaseIndex" },
2206 { OPERAND_TYPE_DISP8
, "d8" },
2207 { OPERAND_TYPE_DISP16
, "d16" },
2208 { OPERAND_TYPE_DISP32
, "d32" },
2209 { OPERAND_TYPE_DISP32S
, "d32s" },
2210 { OPERAND_TYPE_DISP64
, "d64" },
2211 { OPERAND_TYPE_INOUTPORTREG
, "InOutPortReg" },
2212 { OPERAND_TYPE_SHIFTCOUNT
, "ShiftCount" },
2213 { OPERAND_TYPE_CONTROL
, "control reg" },
2214 { OPERAND_TYPE_TEST
, "test reg" },
2215 { OPERAND_TYPE_DEBUG
, "debug reg" },
2216 { OPERAND_TYPE_FLOATREG
, "FReg" },
2217 { OPERAND_TYPE_FLOATACC
, "FAcc" },
2218 { OPERAND_TYPE_SREG2
, "SReg2" },
2219 { OPERAND_TYPE_SREG3
, "SReg3" },
2220 { OPERAND_TYPE_ACC
, "Acc" },
2221 { OPERAND_TYPE_JUMPABSOLUTE
, "Jump Absolute" },
2222 { OPERAND_TYPE_REGMMX
, "rMMX" },
2223 { OPERAND_TYPE_REGXMM
, "rXMM" },
2224 { OPERAND_TYPE_ESSEG
, "es" },
2225 { OPERAND_TYPE_VEX_IMM4
, "VEX i4" },
2229 pt (i386_operand_type t
)
2232 i386_operand_type a
;
2234 for (j
= 0; j
< ARRAY_SIZE (type_names
); j
++)
2236 a
= operand_type_and (t
, type_names
[j
].mask
);
2237 if (!UINTS_ALL_ZERO (a
))
2238 fprintf (stdout
, "%s, ", type_names
[j
].name
);
2243 #endif /* DEBUG386 */
2245 static bfd_reloc_code_real_type
2246 reloc (unsigned int size
,
2249 bfd_reloc_code_real_type other
)
2251 if (other
!= NO_RELOC
)
2253 reloc_howto_type
*reloc
;
2258 case BFD_RELOC_X86_64_GOT32
:
2259 return BFD_RELOC_X86_64_GOT64
;
2261 case BFD_RELOC_X86_64_PLTOFF64
:
2262 return BFD_RELOC_X86_64_PLTOFF64
;
2264 case BFD_RELOC_X86_64_GOTPC32
:
2265 other
= BFD_RELOC_X86_64_GOTPC64
;
2267 case BFD_RELOC_X86_64_GOTPCREL
:
2268 other
= BFD_RELOC_X86_64_GOTPCREL64
;
2270 case BFD_RELOC_X86_64_TPOFF32
:
2271 other
= BFD_RELOC_X86_64_TPOFF64
;
2273 case BFD_RELOC_X86_64_DTPOFF32
:
2274 other
= BFD_RELOC_X86_64_DTPOFF64
;
2280 /* Sign-checking 4-byte relocations in 16-/32-bit code is pointless. */
2281 if (size
== 4 && flag_code
!= CODE_64BIT
)
2284 reloc
= bfd_reloc_type_lookup (stdoutput
, other
);
2286 as_bad (_("unknown relocation (%u)"), other
);
2287 else if (size
!= bfd_get_reloc_size (reloc
))
2288 as_bad (_("%u-byte relocation cannot be applied to %u-byte field"),
2289 bfd_get_reloc_size (reloc
),
2291 else if (pcrel
&& !reloc
->pc_relative
)
2292 as_bad (_("non-pc-relative relocation for pc-relative field"));
2293 else if ((reloc
->complain_on_overflow
== complain_overflow_signed
2295 || (reloc
->complain_on_overflow
== complain_overflow_unsigned
2297 as_bad (_("relocated field and relocation type differ in signedness"));
2306 as_bad (_("there are no unsigned pc-relative relocations"));
2309 case 1: return BFD_RELOC_8_PCREL
;
2310 case 2: return BFD_RELOC_16_PCREL
;
2311 case 4: return BFD_RELOC_32_PCREL
;
2312 case 8: return BFD_RELOC_64_PCREL
;
2314 as_bad (_("cannot do %u byte pc-relative relocation"), size
);
2321 case 4: return BFD_RELOC_X86_64_32S
;
2326 case 1: return BFD_RELOC_8
;
2327 case 2: return BFD_RELOC_16
;
2328 case 4: return BFD_RELOC_32
;
2329 case 8: return BFD_RELOC_64
;
2331 as_bad (_("cannot do %s %u byte relocation"),
2332 sign
> 0 ? "signed" : "unsigned", size
);
2336 return BFD_RELOC_NONE
;
2339 /* Here we decide which fixups can be adjusted to make them relative to
2340 the beginning of the section instead of the symbol. Basically we need
2341 to make sure that the dynamic relocations are done correctly, so in
2342 some cases we force the original symbol to be used. */
2345 tc_i386_fix_adjustable (fixS
*fixP ATTRIBUTE_UNUSED
)
2347 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
2351 /* Don't adjust pc-relative references to merge sections in 64-bit
2353 if (use_rela_relocations
2354 && (S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0
2358 /* The x86_64 GOTPCREL are represented as 32bit PCrel relocations
2359 and changed later by validate_fix. */
2360 if (GOT_symbol
&& fixP
->fx_subsy
== GOT_symbol
2361 && fixP
->fx_r_type
== BFD_RELOC_32_PCREL
)
2364 /* adjust_reloc_syms doesn't know about the GOT. */
2365 if (fixP
->fx_r_type
== BFD_RELOC_386_GOTOFF
2366 || fixP
->fx_r_type
== BFD_RELOC_386_PLT32
2367 || fixP
->fx_r_type
== BFD_RELOC_386_GOT32
2368 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_GD
2369 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_LDM
2370 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_LDO_32
2371 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_IE_32
2372 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_IE
2373 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_GOTIE
2374 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_LE_32
2375 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_LE
2376 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_GOTDESC
2377 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_DESC_CALL
2378 || fixP
->fx_r_type
== BFD_RELOC_X86_64_PLT32
2379 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOT32
2380 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOTPCREL
2381 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TLSGD
2382 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TLSLD
2383 || fixP
->fx_r_type
== BFD_RELOC_X86_64_DTPOFF32
2384 || fixP
->fx_r_type
== BFD_RELOC_X86_64_DTPOFF64
2385 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOTTPOFF
2386 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TPOFF32
2387 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TPOFF64
2388 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOTOFF64
2389 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOTPC32_TLSDESC
2390 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TLSDESC_CALL
2391 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2392 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2399 intel_float_operand (const char *mnemonic
)
2401 /* Note that the value returned is meaningful only for opcodes with (memory)
2402 operands, hence the code here is free to improperly handle opcodes that
2403 have no operands (for better performance and smaller code). */
2405 if (mnemonic
[0] != 'f')
2406 return 0; /* non-math */
2408 switch (mnemonic
[1])
2410 /* fclex, fdecstp, fdisi, femms, feni, fincstp, finit, fsetpm, and
2411 the fs segment override prefix not currently handled because no
2412 call path can make opcodes without operands get here */
2414 return 2 /* integer op */;
2416 if (mnemonic
[2] == 'd' && (mnemonic
[3] == 'c' || mnemonic
[3] == 'e'))
2417 return 3; /* fldcw/fldenv */
2420 if (mnemonic
[2] != 'o' /* fnop */)
2421 return 3; /* non-waiting control op */
2424 if (mnemonic
[2] == 's')
2425 return 3; /* frstor/frstpm */
2428 if (mnemonic
[2] == 'a')
2429 return 3; /* fsave */
2430 if (mnemonic
[2] == 't')
2432 switch (mnemonic
[3])
2434 case 'c': /* fstcw */
2435 case 'd': /* fstdw */
2436 case 'e': /* fstenv */
2437 case 's': /* fsts[gw] */
2443 if (mnemonic
[2] == 'r' || mnemonic
[2] == 's')
2444 return 0; /* fxsave/fxrstor are not really math ops */
2451 /* Build the VEX prefix. */
2454 build_vex_prefix (void)
2456 unsigned int register_specifier
;
2457 unsigned int implied_prefix
;
2458 unsigned int vector_length
;
2460 /* Check register specifier. */
2461 if (i
.vex
.register_specifier
)
2463 register_specifier
= i
.vex
.register_specifier
->reg_num
;
2464 if ((i
.vex
.register_specifier
->reg_flags
& RegRex
))
2465 register_specifier
+= 8;
2466 register_specifier
= ~register_specifier
& 0xf;
2469 register_specifier
= 0xf;
2471 vector_length
= i
.tm
.opcode_modifier
.vex256
? 1 : 0;
2473 switch ((i
.tm
.base_opcode
>> 8) & 0xff)
2478 case DATA_PREFIX_OPCODE
:
2481 case REPE_PREFIX_OPCODE
:
2484 case REPNE_PREFIX_OPCODE
:
2491 /* Use 2-byte VEX prefix if possible. */
2492 if (i
.tm
.opcode_modifier
.vex0f
2493 && (i
.rex
& (REX_W
| REX_X
| REX_B
)) == 0)
2495 /* 2-byte VEX prefix. */
2499 i
.vex
.bytes
[0] = 0xc5;
2501 /* Check the REX.R bit. */
2502 r
= (i
.rex
& REX_R
) ? 0 : 1;
2503 i
.vex
.bytes
[1] = (r
<< 7
2504 | register_specifier
<< 3
2505 | vector_length
<< 2
2510 /* 3-byte VEX prefix. */
2513 if (i
.tm
.opcode_modifier
.vex0f
)
2515 else if (i
.tm
.opcode_modifier
.vex0f38
)
2517 else if (i
.tm
.opcode_modifier
.vex0f3a
)
2523 i
.vex
.bytes
[0] = 0xc4;
2525 /* The high 3 bits of the second VEX byte are 1's compliment
2526 of RXB bits from REX. */
2527 i
.vex
.bytes
[1] = (~i
.rex
& 0x7) << 5 | m
;
2529 /* Check the REX.W bit. */
2530 w
= (i
.rex
& REX_W
) ? 1 : 0;
2531 if (i
.tm
.opcode_modifier
.vexw0
|| i
.tm
.opcode_modifier
.vexw1
)
2536 if (i
.tm
.opcode_modifier
.vexw1
)
2540 i
.vex
.bytes
[2] = (w
<< 7
2541 | register_specifier
<< 3
2542 | vector_length
<< 2
2548 process_immext (void)
2552 if (i
.tm
.cpu_flags
.bitfield
.cpusse3
&& i
.operands
> 0)
2554 /* SSE3 Instructions have the fixed operands with an opcode
2555 suffix which is coded in the same place as an 8-bit immediate
2556 field would be. Here we check those operands and remove them
2560 for (x
= 0; x
< i
.operands
; x
++)
2561 if (i
.op
[x
].regs
->reg_num
!= x
)
2562 as_bad (_("can't use register '%s%s' as operand %d in '%s'."),
2563 register_prefix
, i
.op
[x
].regs
->reg_name
, x
+ 1,
2569 /* These AMD 3DNow! and SSE2 instructions have an opcode suffix
2570 which is coded in the same place as an 8-bit immediate field
2571 would be. Here we fake an 8-bit immediate operand from the
2572 opcode suffix stored in tm.extension_opcode.
2574 SSE5 and AVX instructions also use this encoding, for some of
2575 3 argument instructions. */
2577 assert (i
.imm_operands
== 0
2579 || (i
.tm
.cpu_flags
.bitfield
.cpusse5
2581 || (i
.tm
.opcode_modifier
.vex
2582 && i
.operands
<= 4)));
2584 exp
= &im_expressions
[i
.imm_operands
++];
2585 i
.op
[i
.operands
].imms
= exp
;
2586 i
.types
[i
.operands
] = imm8
;
2588 exp
->X_op
= O_constant
;
2589 exp
->X_add_number
= i
.tm
.extension_opcode
;
2590 i
.tm
.extension_opcode
= None
;
2593 /* This is the guts of the machine-dependent assembler. LINE points to a
2594 machine dependent instruction. This function is supposed to emit
2595 the frags/bytes it assembles to. */
2598 md_assemble (char *line
)
2601 char mnemonic
[MAX_MNEM_SIZE
];
2603 /* Initialize globals. */
2604 memset (&i
, '\0', sizeof (i
));
2605 for (j
= 0; j
< MAX_OPERANDS
; j
++)
2606 i
.reloc
[j
] = NO_RELOC
;
2607 memset (disp_expressions
, '\0', sizeof (disp_expressions
));
2608 memset (im_expressions
, '\0', sizeof (im_expressions
));
2609 save_stack_p
= save_stack
;
2611 /* First parse an instruction mnemonic & call i386_operand for the operands.
2612 We assume that the scrubber has arranged it so that line[0] is the valid
2613 start of a (possibly prefixed) mnemonic. */
2615 line
= parse_insn (line
, mnemonic
);
2619 line
= parse_operands (line
, mnemonic
);
2623 /* Now we've parsed the mnemonic into a set of templates, and have the
2624 operands at hand. */
2626 /* All intel opcodes have reversed operands except for "bound" and
2627 "enter". We also don't reverse intersegment "jmp" and "call"
2628 instructions with 2 immediate operands so that the immediate segment
2629 precedes the offset, as it does when in AT&T mode. */
2632 && (strcmp (mnemonic
, "bound") != 0)
2633 && (strcmp (mnemonic
, "invlpga") != 0)
2634 && !(operand_type_check (i
.types
[0], imm
)
2635 && operand_type_check (i
.types
[1], imm
)))
2638 /* The order of the immediates should be reversed
2639 for 2 immediates extrq and insertq instructions */
2640 if (i
.imm_operands
== 2
2641 && (strcmp (mnemonic
, "extrq") == 0
2642 || strcmp (mnemonic
, "insertq") == 0))
2643 swap_2_operands (0, 1);
2648 /* Don't optimize displacement for movabs since it only takes 64bit
2651 && (flag_code
!= CODE_64BIT
2652 || strcmp (mnemonic
, "movabs") != 0))
2655 /* Next, we find a template that matches the given insn,
2656 making sure the overlap of the given operands types is consistent
2657 with the template operand types. */
2659 if (!match_template ())
2662 /* Zap movzx and movsx suffix. The suffix has been set from
2663 "word ptr" or "byte ptr" on the source operand in Intel syntax
2664 or extracted from mnemonic in AT&T syntax. But we'll use
2665 the destination register to choose the suffix for encoding. */
2666 if ((i
.tm
.base_opcode
& ~9) == 0x0fb6)
2668 /* In Intel syntax, there must be a suffix. In AT&T syntax, if
2669 there is no suffix, the default will be byte extension. */
2670 if (i
.reg_operands
!= 2
2673 as_bad (_("ambiguous operand size for `%s'"), i
.tm
.name
);
2678 if (i
.tm
.opcode_modifier
.fwait
)
2679 if (!add_prefix (FWAIT_OPCODE
))
2682 /* Check string instruction segment overrides. */
2683 if (i
.tm
.opcode_modifier
.isstring
&& i
.mem_operands
!= 0)
2685 if (!check_string ())
2689 if (!process_suffix ())
2692 /* Make still unresolved immediate matches conform to size of immediate
2693 given in i.suffix. */
2694 if (!finalize_imm ())
2697 if (i
.types
[0].bitfield
.imm1
)
2698 i
.imm_operands
= 0; /* kludge for shift insns. */
2700 for (j
= 0; j
< 3; j
++)
2701 if (i
.types
[j
].bitfield
.inoutportreg
2702 || i
.types
[j
].bitfield
.shiftcount
2703 || i
.types
[j
].bitfield
.acc
2704 || i
.types
[j
].bitfield
.floatacc
)
2707 /* ImmExt should be processed after SSE2AVX. */
2708 if (!i
.tm
.opcode_modifier
.sse2avx
2709 && i
.tm
.opcode_modifier
.immext
)
2712 /* For insns with operands there are more diddles to do to the opcode. */
2715 if (!process_operands ())
2718 else if (!quiet_warnings
&& i
.tm
.opcode_modifier
.ugh
)
2720 /* UnixWare fsub no args is alias for fsubp, fadd -> faddp, etc. */
2721 as_warn (_("translating to `%sp'"), i
.tm
.name
);
2724 if (i
.tm
.opcode_modifier
.vex
)
2725 build_vex_prefix ();
2727 /* Handle conversion of 'int $3' --> special int3 insn. */
2728 if (i
.tm
.base_opcode
== INT_OPCODE
&& i
.op
[0].imms
->X_add_number
== 3)
2730 i
.tm
.base_opcode
= INT3_OPCODE
;
2734 if ((i
.tm
.opcode_modifier
.jump
2735 || i
.tm
.opcode_modifier
.jumpbyte
2736 || i
.tm
.opcode_modifier
.jumpdword
)
2737 && i
.op
[0].disps
->X_op
== O_constant
)
2739 /* Convert "jmp constant" (and "call constant") to a jump (call) to
2740 the absolute address given by the constant. Since ix86 jumps and
2741 calls are pc relative, we need to generate a reloc. */
2742 i
.op
[0].disps
->X_add_symbol
= &abs_symbol
;
2743 i
.op
[0].disps
->X_op
= O_symbol
;
2746 if (i
.tm
.opcode_modifier
.rex64
)
2749 /* For 8 bit registers we need an empty rex prefix. Also if the
2750 instruction already has a prefix, we need to convert old
2751 registers to new ones. */
2753 if ((i
.types
[0].bitfield
.reg8
2754 && (i
.op
[0].regs
->reg_flags
& RegRex64
) != 0)
2755 || (i
.types
[1].bitfield
.reg8
2756 && (i
.op
[1].regs
->reg_flags
& RegRex64
) != 0)
2757 || ((i
.types
[0].bitfield
.reg8
2758 || i
.types
[1].bitfield
.reg8
)
2763 i
.rex
|= REX_OPCODE
;
2764 for (x
= 0; x
< 2; x
++)
2766 /* Look for 8 bit operand that uses old registers. */
2767 if (i
.types
[x
].bitfield
.reg8
2768 && (i
.op
[x
].regs
->reg_flags
& RegRex64
) == 0)
2770 /* In case it is "hi" register, give up. */
2771 if (i
.op
[x
].regs
->reg_num
> 3)
2772 as_bad (_("can't encode register '%s%s' in an "
2773 "instruction requiring REX prefix."),
2774 register_prefix
, i
.op
[x
].regs
->reg_name
);
2776 /* Otherwise it is equivalent to the extended register.
2777 Since the encoding doesn't change this is merely
2778 cosmetic cleanup for debug output. */
2780 i
.op
[x
].regs
= i
.op
[x
].regs
+ 8;
2785 /* If the instruction has the DREX attribute (aka SSE5), don't emit a
2787 if (i
.tm
.opcode_modifier
.drex
|| i
.tm
.opcode_modifier
.drexc
)
2792 else if (i
.rex
!= 0)
2793 add_prefix (REX_OPCODE
| i
.rex
);
2795 /* We are ready to output the insn. */
2800 parse_insn (char *line
, char *mnemonic
)
2803 char *token_start
= l
;
2808 /* Non-zero if we found a prefix only acceptable with string insns. */
2809 const char *expecting_string_instruction
= NULL
;
2814 while ((*mnem_p
= mnemonic_chars
[(unsigned char) *l
]) != 0)
2817 if (mnem_p
>= mnemonic
+ MAX_MNEM_SIZE
)
2819 as_bad (_("no such instruction: `%s'"), token_start
);
2824 if (!is_space_char (*l
)
2825 && *l
!= END_OF_INSN
2827 || (*l
!= PREFIX_SEPARATOR
2830 as_bad (_("invalid character %s in mnemonic"),
2831 output_invalid (*l
));
2834 if (token_start
== l
)
2836 if (!intel_syntax
&& *l
== PREFIX_SEPARATOR
)
2837 as_bad (_("expecting prefix; got nothing"));
2839 as_bad (_("expecting mnemonic; got nothing"));
2843 /* Look up instruction (or prefix) via hash table. */
2844 current_templates
= hash_find (op_hash
, mnemonic
);
2846 if (*l
!= END_OF_INSN
2847 && (!is_space_char (*l
) || l
[1] != END_OF_INSN
)
2848 && current_templates
2849 && current_templates
->start
->opcode_modifier
.isprefix
)
2851 if (!cpu_flags_check_cpu64 (current_templates
->start
->cpu_flags
))
2853 as_bad ((flag_code
!= CODE_64BIT
2854 ? _("`%s' is only supported in 64-bit mode")
2855 : _("`%s' is not supported in 64-bit mode")),
2856 current_templates
->start
->name
);
2859 /* If we are in 16-bit mode, do not allow addr16 or data16.
2860 Similarly, in 32-bit mode, do not allow addr32 or data32. */
2861 if ((current_templates
->start
->opcode_modifier
.size16
2862 || current_templates
->start
->opcode_modifier
.size32
)
2863 && flag_code
!= CODE_64BIT
2864 && (current_templates
->start
->opcode_modifier
.size32
2865 ^ (flag_code
== CODE_16BIT
)))
2867 as_bad (_("redundant %s prefix"),
2868 current_templates
->start
->name
);
2871 /* Add prefix, checking for repeated prefixes. */
2872 switch (add_prefix (current_templates
->start
->base_opcode
))
2877 expecting_string_instruction
= current_templates
->start
->name
;
2880 /* Skip past PREFIX_SEPARATOR and reset token_start. */
2887 if (!current_templates
)
2889 /* See if we can get a match by trimming off a suffix. */
2892 case WORD_MNEM_SUFFIX
:
2893 if (intel_syntax
&& (intel_float_operand (mnemonic
) & 2))
2894 i
.suffix
= SHORT_MNEM_SUFFIX
;
2896 case BYTE_MNEM_SUFFIX
:
2897 case QWORD_MNEM_SUFFIX
:
2898 i
.suffix
= mnem_p
[-1];
2900 current_templates
= hash_find (op_hash
, mnemonic
);
2902 case SHORT_MNEM_SUFFIX
:
2903 case LONG_MNEM_SUFFIX
:
2906 i
.suffix
= mnem_p
[-1];
2908 current_templates
= hash_find (op_hash
, mnemonic
);
2916 if (intel_float_operand (mnemonic
) == 1)
2917 i
.suffix
= SHORT_MNEM_SUFFIX
;
2919 i
.suffix
= LONG_MNEM_SUFFIX
;
2921 current_templates
= hash_find (op_hash
, mnemonic
);
2925 if (!current_templates
)
2927 as_bad (_("no such instruction: `%s'"), token_start
);
2932 if (current_templates
->start
->opcode_modifier
.jump
2933 || current_templates
->start
->opcode_modifier
.jumpbyte
)
2935 /* Check for a branch hint. We allow ",pt" and ",pn" for
2936 predict taken and predict not taken respectively.
2937 I'm not sure that branch hints actually do anything on loop
2938 and jcxz insns (JumpByte) for current Pentium4 chips. They
2939 may work in the future and it doesn't hurt to accept them
2941 if (l
[0] == ',' && l
[1] == 'p')
2945 if (!add_prefix (DS_PREFIX_OPCODE
))
2949 else if (l
[2] == 'n')
2951 if (!add_prefix (CS_PREFIX_OPCODE
))
2957 /* Any other comma loses. */
2960 as_bad (_("invalid character %s in mnemonic"),
2961 output_invalid (*l
));
2965 /* Check if instruction is supported on specified architecture. */
2967 for (t
= current_templates
->start
; t
< current_templates
->end
; ++t
)
2969 supported
|= cpu_flags_match (t
);
2970 if (supported
== CPU_FLAGS_PERFECT_MATCH
)
2974 if (!(supported
& CPU_FLAGS_64BIT_MATCH
))
2976 as_bad (flag_code
== CODE_64BIT
2977 ? _("`%s' is not supported in 64-bit mode")
2978 : _("`%s' is only supported in 64-bit mode"),
2979 current_templates
->start
->name
);
2982 if (supported
!= CPU_FLAGS_PERFECT_MATCH
)
2984 as_bad (_("`%s' is not supported on `%s%s'"),
2985 current_templates
->start
->name
, cpu_arch_name
,
2986 cpu_sub_arch_name
? cpu_sub_arch_name
: "");
2991 if (!cpu_arch_flags
.bitfield
.cpui386
2992 && (flag_code
!= CODE_16BIT
))
2994 as_warn (_("use .code16 to ensure correct addressing mode"));
2997 /* Check for rep/repne without a string instruction. */
2998 if (expecting_string_instruction
)
3000 static templates override
;
3002 for (t
= current_templates
->start
; t
< current_templates
->end
; ++t
)
3003 if (t
->opcode_modifier
.isstring
)
3005 if (t
>= current_templates
->end
)
3007 as_bad (_("expecting string instruction after `%s'"),
3008 expecting_string_instruction
);
3011 for (override
.start
= t
; t
< current_templates
->end
; ++t
)
3012 if (!t
->opcode_modifier
.isstring
)
3015 current_templates
= &override
;
3022 parse_operands (char *l
, const char *mnemonic
)
3026 /* 1 if operand is pending after ','. */
3027 unsigned int expecting_operand
= 0;
3029 /* Non-zero if operand parens not balanced. */
3030 unsigned int paren_not_balanced
;
3032 while (*l
!= END_OF_INSN
)
3034 /* Skip optional white space before operand. */
3035 if (is_space_char (*l
))
3037 if (!is_operand_char (*l
) && *l
!= END_OF_INSN
)
3039 as_bad (_("invalid character %s before operand %d"),
3040 output_invalid (*l
),
3044 token_start
= l
; /* after white space */
3045 paren_not_balanced
= 0;
3046 while (paren_not_balanced
|| *l
!= ',')
3048 if (*l
== END_OF_INSN
)
3050 if (paren_not_balanced
)
3053 as_bad (_("unbalanced parenthesis in operand %d."),
3056 as_bad (_("unbalanced brackets in operand %d."),
3061 break; /* we are done */
3063 else if (!is_operand_char (*l
) && !is_space_char (*l
))
3065 as_bad (_("invalid character %s in operand %d"),
3066 output_invalid (*l
),
3073 ++paren_not_balanced
;
3075 --paren_not_balanced
;
3080 ++paren_not_balanced
;
3082 --paren_not_balanced
;
3086 if (l
!= token_start
)
3087 { /* Yes, we've read in another operand. */
3088 unsigned int operand_ok
;
3089 this_operand
= i
.operands
++;
3090 i
.types
[this_operand
].bitfield
.unspecified
= 1;
3091 if (i
.operands
> MAX_OPERANDS
)
3093 as_bad (_("spurious operands; (%d operands/instruction max)"),
3097 /* Now parse operand adding info to 'i' as we go along. */
3098 END_STRING_AND_SAVE (l
);
3102 i386_intel_operand (token_start
,
3103 intel_float_operand (mnemonic
));
3105 operand_ok
= i386_att_operand (token_start
);
3107 RESTORE_END_STRING (l
);
3113 if (expecting_operand
)
3115 expecting_operand_after_comma
:
3116 as_bad (_("expecting operand after ','; got nothing"));
3121 as_bad (_("expecting operand before ','; got nothing"));
3126 /* Now *l must be either ',' or END_OF_INSN. */
3129 if (*++l
== END_OF_INSN
)
3131 /* Just skip it, if it's \n complain. */
3132 goto expecting_operand_after_comma
;
3134 expecting_operand
= 1;
3141 swap_2_operands (int xchg1
, int xchg2
)
3143 union i386_op temp_op
;
3144 i386_operand_type temp_type
;
3145 enum bfd_reloc_code_real temp_reloc
;
3147 temp_type
= i
.types
[xchg2
];
3148 i
.types
[xchg2
] = i
.types
[xchg1
];
3149 i
.types
[xchg1
] = temp_type
;
3150 temp_op
= i
.op
[xchg2
];
3151 i
.op
[xchg2
] = i
.op
[xchg1
];
3152 i
.op
[xchg1
] = temp_op
;
3153 temp_reloc
= i
.reloc
[xchg2
];
3154 i
.reloc
[xchg2
] = i
.reloc
[xchg1
];
3155 i
.reloc
[xchg1
] = temp_reloc
;
3159 swap_operands (void)
3165 swap_2_operands (1, i
.operands
- 2);
3168 swap_2_operands (0, i
.operands
- 1);
3174 if (i
.mem_operands
== 2)
3176 const seg_entry
*temp_seg
;
3177 temp_seg
= i
.seg
[0];
3178 i
.seg
[0] = i
.seg
[1];
3179 i
.seg
[1] = temp_seg
;
3183 /* Try to ensure constant immediates are represented in the smallest
3188 char guess_suffix
= 0;
3192 guess_suffix
= i
.suffix
;
3193 else if (i
.reg_operands
)
3195 /* Figure out a suffix from the last register operand specified.
3196 We can't do this properly yet, ie. excluding InOutPortReg,
3197 but the following works for instructions with immediates.
3198 In any case, we can't set i.suffix yet. */
3199 for (op
= i
.operands
; --op
>= 0;)
3200 if (i
.types
[op
].bitfield
.reg8
)
3202 guess_suffix
= BYTE_MNEM_SUFFIX
;
3205 else if (i
.types
[op
].bitfield
.reg16
)
3207 guess_suffix
= WORD_MNEM_SUFFIX
;
3210 else if (i
.types
[op
].bitfield
.reg32
)
3212 guess_suffix
= LONG_MNEM_SUFFIX
;
3215 else if (i
.types
[op
].bitfield
.reg64
)
3217 guess_suffix
= QWORD_MNEM_SUFFIX
;
3221 else if ((flag_code
== CODE_16BIT
) ^ (i
.prefix
[DATA_PREFIX
] != 0))
3222 guess_suffix
= WORD_MNEM_SUFFIX
;
3224 for (op
= i
.operands
; --op
>= 0;)
3225 if (operand_type_check (i
.types
[op
], imm
))
3227 switch (i
.op
[op
].imms
->X_op
)
3230 /* If a suffix is given, this operand may be shortened. */
3231 switch (guess_suffix
)
3233 case LONG_MNEM_SUFFIX
:
3234 i
.types
[op
].bitfield
.imm32
= 1;
3235 i
.types
[op
].bitfield
.imm64
= 1;
3237 case WORD_MNEM_SUFFIX
:
3238 i
.types
[op
].bitfield
.imm16
= 1;
3239 i
.types
[op
].bitfield
.imm32
= 1;
3240 i
.types
[op
].bitfield
.imm32s
= 1;
3241 i
.types
[op
].bitfield
.imm64
= 1;
3243 case BYTE_MNEM_SUFFIX
:
3244 i
.types
[op
].bitfield
.imm8
= 1;
3245 i
.types
[op
].bitfield
.imm8s
= 1;
3246 i
.types
[op
].bitfield
.imm16
= 1;
3247 i
.types
[op
].bitfield
.imm32
= 1;
3248 i
.types
[op
].bitfield
.imm32s
= 1;
3249 i
.types
[op
].bitfield
.imm64
= 1;
3253 /* If this operand is at most 16 bits, convert it
3254 to a signed 16 bit number before trying to see
3255 whether it will fit in an even smaller size.
3256 This allows a 16-bit operand such as $0xffe0 to
3257 be recognised as within Imm8S range. */
3258 if ((i
.types
[op
].bitfield
.imm16
)
3259 && (i
.op
[op
].imms
->X_add_number
& ~(offsetT
) 0xffff) == 0)
3261 i
.op
[op
].imms
->X_add_number
=
3262 (((i
.op
[op
].imms
->X_add_number
& 0xffff) ^ 0x8000) - 0x8000);
3264 if ((i
.types
[op
].bitfield
.imm32
)
3265 && ((i
.op
[op
].imms
->X_add_number
& ~(((offsetT
) 2 << 31) - 1))
3268 i
.op
[op
].imms
->X_add_number
= ((i
.op
[op
].imms
->X_add_number
3269 ^ ((offsetT
) 1 << 31))
3270 - ((offsetT
) 1 << 31));
3273 = operand_type_or (i
.types
[op
],
3274 smallest_imm_type (i
.op
[op
].imms
->X_add_number
));
3276 /* We must avoid matching of Imm32 templates when 64bit
3277 only immediate is available. */
3278 if (guess_suffix
== QWORD_MNEM_SUFFIX
)
3279 i
.types
[op
].bitfield
.imm32
= 0;
3286 /* Symbols and expressions. */
3288 /* Convert symbolic operand to proper sizes for matching, but don't
3289 prevent matching a set of insns that only supports sizes other
3290 than those matching the insn suffix. */
3292 i386_operand_type mask
, allowed
;
3295 operand_type_set (&mask
, 0);
3296 operand_type_set (&allowed
, 0);
3298 for (t
= current_templates
->start
;
3299 t
< current_templates
->end
;
3301 allowed
= operand_type_or (allowed
,
3302 t
->operand_types
[op
]);
3303 switch (guess_suffix
)
3305 case QWORD_MNEM_SUFFIX
:
3306 mask
.bitfield
.imm64
= 1;
3307 mask
.bitfield
.imm32s
= 1;
3309 case LONG_MNEM_SUFFIX
:
3310 mask
.bitfield
.imm32
= 1;
3312 case WORD_MNEM_SUFFIX
:
3313 mask
.bitfield
.imm16
= 1;
3315 case BYTE_MNEM_SUFFIX
:
3316 mask
.bitfield
.imm8
= 1;
3321 allowed
= operand_type_and (mask
, allowed
);
3322 if (!operand_type_all_zero (&allowed
))
3323 i
.types
[op
] = operand_type_and (i
.types
[op
], mask
);
3330 /* Try to use the smallest displacement type too. */
3332 optimize_disp (void)
3336 for (op
= i
.operands
; --op
>= 0;)
3337 if (operand_type_check (i
.types
[op
], disp
))
3339 if (i
.op
[op
].disps
->X_op
== O_constant
)
3341 offsetT disp
= i
.op
[op
].disps
->X_add_number
;
3343 if (i
.types
[op
].bitfield
.disp16
3344 && (disp
& ~(offsetT
) 0xffff) == 0)
3346 /* If this operand is at most 16 bits, convert
3347 to a signed 16 bit number and don't use 64bit
3349 disp
= (((disp
& 0xffff) ^ 0x8000) - 0x8000);
3350 i
.types
[op
].bitfield
.disp64
= 0;
3352 if (i
.types
[op
].bitfield
.disp32
3353 && (disp
& ~(((offsetT
) 2 << 31) - 1)) == 0)
3355 /* If this operand is at most 32 bits, convert
3356 to a signed 32 bit number and don't use 64bit
3358 disp
&= (((offsetT
) 2 << 31) - 1);
3359 disp
= (disp
^ ((offsetT
) 1 << 31)) - ((addressT
) 1 << 31);
3360 i
.types
[op
].bitfield
.disp64
= 0;
3362 if (!disp
&& i
.types
[op
].bitfield
.baseindex
)
3364 i
.types
[op
].bitfield
.disp8
= 0;
3365 i
.types
[op
].bitfield
.disp16
= 0;
3366 i
.types
[op
].bitfield
.disp32
= 0;
3367 i
.types
[op
].bitfield
.disp32s
= 0;
3368 i
.types
[op
].bitfield
.disp64
= 0;
3372 else if (flag_code
== CODE_64BIT
)
3374 if (fits_in_signed_long (disp
))
3376 i
.types
[op
].bitfield
.disp64
= 0;
3377 i
.types
[op
].bitfield
.disp32s
= 1;
3379 if (fits_in_unsigned_long (disp
))
3380 i
.types
[op
].bitfield
.disp32
= 1;
3382 if ((i
.types
[op
].bitfield
.disp32
3383 || i
.types
[op
].bitfield
.disp32s
3384 || i
.types
[op
].bitfield
.disp16
)
3385 && fits_in_signed_byte (disp
))
3386 i
.types
[op
].bitfield
.disp8
= 1;
3388 else if (i
.reloc
[op
] == BFD_RELOC_386_TLS_DESC_CALL
3389 || i
.reloc
[op
] == BFD_RELOC_X86_64_TLSDESC_CALL
)
3391 fix_new_exp (frag_now
, frag_more (0) - frag_now
->fr_literal
, 0,
3392 i
.op
[op
].disps
, 0, i
.reloc
[op
]);
3393 i
.types
[op
].bitfield
.disp8
= 0;
3394 i
.types
[op
].bitfield
.disp16
= 0;
3395 i
.types
[op
].bitfield
.disp32
= 0;
3396 i
.types
[op
].bitfield
.disp32s
= 0;
3397 i
.types
[op
].bitfield
.disp64
= 0;
3400 /* We only support 64bit displacement on constants. */
3401 i
.types
[op
].bitfield
.disp64
= 0;
3405 /* Check if operands are valid for the instrucrtion. Update VEX
3409 VEX_check_operands (const template *t
)
3411 if (!t
->opcode_modifier
.vex
)
3414 /* Only check VEX_Imm4, which must be the first operand. */
3415 if (t
->operand_types
[0].bitfield
.vex_imm4
)
3417 if (i
.op
[0].imms
->X_op
!= O_constant
3418 || !fits_in_imm4 (i
.op
[0].imms
->X_add_number
))
3421 /* Turn off Imm8 so that update_imm won't complain. */
3422 i
.types
[0] = vex_imm4
;
3429 match_template (void)
3431 /* Points to template once we've found it. */
3433 i386_operand_type overlap0
, overlap1
, overlap2
, overlap3
;
3434 i386_operand_type overlap4
;
3435 unsigned int found_reverse_match
;
3436 i386_opcode_modifier suffix_check
;
3437 i386_operand_type operand_types
[MAX_OPERANDS
];
3438 int addr_prefix_disp
;
3440 unsigned int found_cpu_match
;
3441 unsigned int check_register
;
3443 #if MAX_OPERANDS != 5
3444 # error "MAX_OPERANDS must be 5."
3447 found_reverse_match
= 0;
3448 addr_prefix_disp
= -1;
3450 memset (&suffix_check
, 0, sizeof (suffix_check
));
3451 if (i
.suffix
== BYTE_MNEM_SUFFIX
)
3452 suffix_check
.no_bsuf
= 1;
3453 else if (i
.suffix
== WORD_MNEM_SUFFIX
)
3454 suffix_check
.no_wsuf
= 1;
3455 else if (i
.suffix
== SHORT_MNEM_SUFFIX
)
3456 suffix_check
.no_ssuf
= 1;
3457 else if (i
.suffix
== LONG_MNEM_SUFFIX
)
3458 suffix_check
.no_lsuf
= 1;
3459 else if (i
.suffix
== QWORD_MNEM_SUFFIX
)
3460 suffix_check
.no_qsuf
= 1;
3461 else if (i
.suffix
== LONG_DOUBLE_MNEM_SUFFIX
)
3462 suffix_check
.no_ldsuf
= 1;
3464 for (t
= current_templates
->start
; t
< current_templates
->end
; t
++)
3466 addr_prefix_disp
= -1;
3468 /* Must have right number of operands. */
3469 if (i
.operands
!= t
->operands
)
3472 /* Check processor support. */
3473 found_cpu_match
= (cpu_flags_match (t
)
3474 == CPU_FLAGS_PERFECT_MATCH
);
3475 if (!found_cpu_match
)
3478 /* Check old gcc support. */
3479 if (!old_gcc
&& t
->opcode_modifier
.oldgcc
)
3482 /* Check AT&T mnemonic. */
3483 if (intel_mnemonic
&& t
->opcode_modifier
.attmnemonic
)
3486 /* Check AT&T syntax Intel syntax. */
3487 if ((intel_syntax
&& t
->opcode_modifier
.attsyntax
)
3488 || (!intel_syntax
&& t
->opcode_modifier
.intelsyntax
))
3491 /* Check the suffix, except for some instructions in intel mode. */
3492 if ((!intel_syntax
|| !t
->opcode_modifier
.ignoresize
)
3493 && ((t
->opcode_modifier
.no_bsuf
&& suffix_check
.no_bsuf
)
3494 || (t
->opcode_modifier
.no_wsuf
&& suffix_check
.no_wsuf
)
3495 || (t
->opcode_modifier
.no_lsuf
&& suffix_check
.no_lsuf
)
3496 || (t
->opcode_modifier
.no_ssuf
&& suffix_check
.no_ssuf
)
3497 || (t
->opcode_modifier
.no_qsuf
&& suffix_check
.no_qsuf
)
3498 || (t
->opcode_modifier
.no_ldsuf
&& suffix_check
.no_ldsuf
)))
3501 if (!operand_size_match (t
))
3504 for (j
= 0; j
< MAX_OPERANDS
; j
++)
3505 operand_types
[j
] = t
->operand_types
[j
];
3507 /* In general, don't allow 64-bit operands in 32-bit mode. */
3508 if (i
.suffix
== QWORD_MNEM_SUFFIX
3509 && flag_code
!= CODE_64BIT
3511 ? (!t
->opcode_modifier
.ignoresize
3512 && !intel_float_operand (t
->name
))
3513 : intel_float_operand (t
->name
) != 2)
3514 && ((!operand_types
[0].bitfield
.regmmx
3515 && !operand_types
[0].bitfield
.regxmm
3516 && !operand_types
[0].bitfield
.regymm
)
3517 || (!operand_types
[t
->operands
> 1].bitfield
.regmmx
3518 && !!operand_types
[t
->operands
> 1].bitfield
.regxmm
3519 && !!operand_types
[t
->operands
> 1].bitfield
.regymm
))
3520 && (t
->base_opcode
!= 0x0fc7
3521 || t
->extension_opcode
!= 1 /* cmpxchg8b */))
3524 /* In general, don't allow 32-bit operands on pre-386. */
3525 else if (i
.suffix
== LONG_MNEM_SUFFIX
3526 && !cpu_arch_flags
.bitfield
.cpui386
3528 ? (!t
->opcode_modifier
.ignoresize
3529 && !intel_float_operand (t
->name
))
3530 : intel_float_operand (t
->name
) != 2)
3531 && ((!operand_types
[0].bitfield
.regmmx
3532 && !operand_types
[0].bitfield
.regxmm
)
3533 || (!operand_types
[t
->operands
> 1].bitfield
.regmmx
3534 && !!operand_types
[t
->operands
> 1].bitfield
.regxmm
)))
3537 /* Do not verify operands when there are none. */
3541 /* We've found a match; break out of loop. */
3545 /* Address size prefix will turn Disp64/Disp32/Disp16 operand
3546 into Disp32/Disp16/Disp32 operand. */
3547 if (i
.prefix
[ADDR_PREFIX
] != 0)
3549 /* There should be only one Disp operand. */
3553 for (j
= 0; j
< MAX_OPERANDS
; j
++)
3555 if (operand_types
[j
].bitfield
.disp16
)
3557 addr_prefix_disp
= j
;
3558 operand_types
[j
].bitfield
.disp32
= 1;
3559 operand_types
[j
].bitfield
.disp16
= 0;
3565 for (j
= 0; j
< MAX_OPERANDS
; j
++)
3567 if (operand_types
[j
].bitfield
.disp32
)
3569 addr_prefix_disp
= j
;
3570 operand_types
[j
].bitfield
.disp32
= 0;
3571 operand_types
[j
].bitfield
.disp16
= 1;
3577 for (j
= 0; j
< MAX_OPERANDS
; j
++)
3579 if (operand_types
[j
].bitfield
.disp64
)
3581 addr_prefix_disp
= j
;
3582 operand_types
[j
].bitfield
.disp64
= 0;
3583 operand_types
[j
].bitfield
.disp32
= 1;
3591 /* We check register size only if size of operands can be
3592 encoded the canonical way. */
3593 check_register
= t
->opcode_modifier
.w
;
3594 overlap0
= operand_type_and (i
.types
[0], operand_types
[0]);
3595 switch (t
->operands
)
3598 if (!operand_type_match (overlap0
, i
.types
[0]))
3602 /* xchg %eax, %eax is a special case. It is an aliase for nop
3603 only in 32bit mode and we can use opcode 0x90. In 64bit
3604 mode, we can't use 0x90 for xchg %eax, %eax since it should
3605 zero-extend %eax to %rax. */
3606 if (flag_code
== CODE_64BIT
3607 && t
->base_opcode
== 0x90
3608 && operand_type_equal (&i
.types
[0], &acc32
)
3609 && operand_type_equal (&i
.types
[1], &acc32
))
3614 overlap1
= operand_type_and (i
.types
[1], operand_types
[1]);
3615 if (!operand_type_match (overlap0
, i
.types
[0])
3616 || !operand_type_match (overlap1
, i
.types
[1])
3618 && !operand_type_register_match (overlap0
, i
.types
[0],
3620 overlap1
, i
.types
[1],
3623 /* Check if other direction is valid ... */
3624 if (!t
->opcode_modifier
.d
&& !t
->opcode_modifier
.floatd
)
3627 /* Try reversing direction of operands. */
3628 overlap0
= operand_type_and (i
.types
[0], operand_types
[1]);
3629 overlap1
= operand_type_and (i
.types
[1], operand_types
[0]);
3630 if (!operand_type_match (overlap0
, i
.types
[0])
3631 || !operand_type_match (overlap1
, i
.types
[1])
3633 && !operand_type_register_match (overlap0
,
3640 /* Does not match either direction. */
3643 /* found_reverse_match holds which of D or FloatDR
3645 if (t
->opcode_modifier
.d
)
3646 found_reverse_match
= Opcode_D
;
3647 else if (t
->opcode_modifier
.floatd
)
3648 found_reverse_match
= Opcode_FloatD
;
3650 found_reverse_match
= 0;
3651 if (t
->opcode_modifier
.floatr
)
3652 found_reverse_match
|= Opcode_FloatR
;
3656 /* Found a forward 2 operand match here. */
3657 switch (t
->operands
)
3660 overlap4
= operand_type_and (i
.types
[4],
3663 overlap3
= operand_type_and (i
.types
[3],
3666 overlap2
= operand_type_and (i
.types
[2],
3671 switch (t
->operands
)
3674 if (!operand_type_match (overlap4
, i
.types
[4])
3675 || !operand_type_register_match (overlap3
,
3683 if (!operand_type_match (overlap3
, i
.types
[3])
3685 && !operand_type_register_match (overlap2
,
3693 /* Here we make use of the fact that there are no
3694 reverse match 3 operand instructions, and all 3
3695 operand instructions only need to be checked for
3696 register consistency between operands 2 and 3. */
3697 if (!operand_type_match (overlap2
, i
.types
[2])
3699 && !operand_type_register_match (overlap1
,
3709 /* Found either forward/reverse 2, 3 or 4 operand match here:
3710 slip through to break. */
3712 if (!found_cpu_match
)
3714 found_reverse_match
= 0;
3718 /* Check if VEX operands are valid. */
3719 if (VEX_check_operands (t
))
3722 /* We've found a match; break out of loop. */
3726 if (t
== current_templates
->end
)
3728 /* We found no match. */
3729 as_bad (_("suffix or operands invalid for `%s'"),
3730 current_templates
->start
->name
);
3734 if (!quiet_warnings
)
3737 && (i
.types
[0].bitfield
.jumpabsolute
3738 != operand_types
[0].bitfield
.jumpabsolute
))
3740 as_warn (_("indirect %s without `*'"), t
->name
);
3743 if (t
->opcode_modifier
.isprefix
3744 && t
->opcode_modifier
.ignoresize
)
3746 /* Warn them that a data or address size prefix doesn't
3747 affect assembly of the next line of code. */
3748 as_warn (_("stand-alone `%s' prefix"), t
->name
);
3752 /* Copy the template we found. */
3755 if (addr_prefix_disp
!= -1)
3756 i
.tm
.operand_types
[addr_prefix_disp
]
3757 = operand_types
[addr_prefix_disp
];
3759 if (found_reverse_match
)
3761 /* If we found a reverse match we must alter the opcode
3762 direction bit. found_reverse_match holds bits to change
3763 (different for int & float insns). */
3765 i
.tm
.base_opcode
^= found_reverse_match
;
3767 i
.tm
.operand_types
[0] = operand_types
[1];
3768 i
.tm
.operand_types
[1] = operand_types
[0];
3777 int mem_op
= operand_type_check (i
.types
[0], anymem
) ? 0 : 1;
3778 if (i
.tm
.operand_types
[mem_op
].bitfield
.esseg
)
3780 if (i
.seg
[0] != NULL
&& i
.seg
[0] != &es
)
3782 as_bad (_("`%s' operand %d must use `%%es' segment"),
3787 /* There's only ever one segment override allowed per instruction.
3788 This instruction possibly has a legal segment override on the
3789 second operand, so copy the segment to where non-string
3790 instructions store it, allowing common code. */
3791 i
.seg
[0] = i
.seg
[1];
3793 else if (i
.tm
.operand_types
[mem_op
+ 1].bitfield
.esseg
)
3795 if (i
.seg
[1] != NULL
&& i
.seg
[1] != &es
)
3797 as_bad (_("`%s' operand %d must use `%%es' segment"),
3807 process_suffix (void)
3809 /* If matched instruction specifies an explicit instruction mnemonic
3811 if (i
.tm
.opcode_modifier
.size16
)
3812 i
.suffix
= WORD_MNEM_SUFFIX
;
3813 else if (i
.tm
.opcode_modifier
.size32
)
3814 i
.suffix
= LONG_MNEM_SUFFIX
;
3815 else if (i
.tm
.opcode_modifier
.size64
)
3816 i
.suffix
= QWORD_MNEM_SUFFIX
;
3817 else if (i
.reg_operands
)
3819 /* If there's no instruction mnemonic suffix we try to invent one
3820 based on register operands. */
3823 /* We take i.suffix from the last register operand specified,
3824 Destination register type is more significant than source
3825 register type. crc32 in SSE4.2 prefers source register
3827 if (i
.tm
.base_opcode
== 0xf20f38f1)
3829 if (i
.types
[0].bitfield
.reg16
)
3830 i
.suffix
= WORD_MNEM_SUFFIX
;
3831 else if (i
.types
[0].bitfield
.reg32
)
3832 i
.suffix
= LONG_MNEM_SUFFIX
;
3833 else if (i
.types
[0].bitfield
.reg64
)
3834 i
.suffix
= QWORD_MNEM_SUFFIX
;
3836 else if (i
.tm
.base_opcode
== 0xf20f38f0)
3838 if (i
.types
[0].bitfield
.reg8
)
3839 i
.suffix
= BYTE_MNEM_SUFFIX
;
3846 if (i
.tm
.base_opcode
== 0xf20f38f1
3847 || i
.tm
.base_opcode
== 0xf20f38f0)
3849 /* We have to know the operand size for crc32. */
3850 as_bad (_("ambiguous memory operand size for `%s`"),
3855 for (op
= i
.operands
; --op
>= 0;)
3856 if (!i
.tm
.operand_types
[op
].bitfield
.inoutportreg
)
3858 if (i
.types
[op
].bitfield
.reg8
)
3860 i
.suffix
= BYTE_MNEM_SUFFIX
;
3863 else if (i
.types
[op
].bitfield
.reg16
)
3865 i
.suffix
= WORD_MNEM_SUFFIX
;
3868 else if (i
.types
[op
].bitfield
.reg32
)
3870 i
.suffix
= LONG_MNEM_SUFFIX
;
3873 else if (i
.types
[op
].bitfield
.reg64
)
3875 i
.suffix
= QWORD_MNEM_SUFFIX
;
3881 else if (i
.suffix
== BYTE_MNEM_SUFFIX
)
3883 if (!check_byte_reg ())
3886 else if (i
.suffix
== LONG_MNEM_SUFFIX
)
3888 if (!check_long_reg ())
3891 else if (i
.suffix
== QWORD_MNEM_SUFFIX
)
3894 && i
.tm
.opcode_modifier
.ignoresize
3895 && i
.tm
.opcode_modifier
.no_qsuf
)
3897 else if (!check_qword_reg ())
3900 else if (i
.suffix
== WORD_MNEM_SUFFIX
)
3902 if (!check_word_reg ())
3905 else if (i
.suffix
== XMMWORD_MNEM_SUFFIX
3906 || i
.suffix
== YMMWORD_MNEM_SUFFIX
)
3908 /* Skip if the instruction has x/y suffix. match_template
3909 should check if it is a valid suffix. */
3911 else if (intel_syntax
&& i
.tm
.opcode_modifier
.ignoresize
)
3912 /* Do nothing if the instruction is going to ignore the prefix. */
3917 else if (i
.tm
.opcode_modifier
.defaultsize
3919 /* exclude fldenv/frstor/fsave/fstenv */
3920 && i
.tm
.opcode_modifier
.no_ssuf
)
3922 i
.suffix
= stackop_size
;
3924 else if (intel_syntax
3926 && (i
.tm
.operand_types
[0].bitfield
.jumpabsolute
3927 || i
.tm
.opcode_modifier
.jumpbyte
3928 || i
.tm
.opcode_modifier
.jumpintersegment
3929 || (i
.tm
.base_opcode
== 0x0f01 /* [ls][gi]dt */
3930 && i
.tm
.extension_opcode
<= 3)))
3935 if (!i
.tm
.opcode_modifier
.no_qsuf
)
3937 i
.suffix
= QWORD_MNEM_SUFFIX
;
3941 if (!i
.tm
.opcode_modifier
.no_lsuf
)
3942 i
.suffix
= LONG_MNEM_SUFFIX
;
3945 if (!i
.tm
.opcode_modifier
.no_wsuf
)
3946 i
.suffix
= WORD_MNEM_SUFFIX
;
3955 if (i
.tm
.opcode_modifier
.w
)
3957 as_bad (_("no instruction mnemonic suffix given and "
3958 "no register operands; can't size instruction"));
3964 unsigned int suffixes
;
3966 suffixes
= !i
.tm
.opcode_modifier
.no_bsuf
;
3967 if (!i
.tm
.opcode_modifier
.no_wsuf
)
3969 if (!i
.tm
.opcode_modifier
.no_lsuf
)
3971 if (!i
.tm
.opcode_modifier
.no_ldsuf
)
3973 if (!i
.tm
.opcode_modifier
.no_ssuf
)
3975 if (!i
.tm
.opcode_modifier
.no_qsuf
)
3978 /* There are more than suffix matches. */
3979 if (i
.tm
.opcode_modifier
.w
3980 || ((suffixes
& (suffixes
- 1))
3981 && !i
.tm
.opcode_modifier
.defaultsize
3982 && !i
.tm
.opcode_modifier
.ignoresize
))
3984 as_bad (_("ambiguous operand size for `%s'"), i
.tm
.name
);
3990 /* Change the opcode based on the operand size given by i.suffix;
3991 We don't need to change things for byte insns. */
3994 && i
.suffix
!= BYTE_MNEM_SUFFIX
3995 && i
.suffix
!= XMMWORD_MNEM_SUFFIX
3996 && i
.suffix
!= YMMWORD_MNEM_SUFFIX
)
3998 /* It's not a byte, select word/dword operation. */
3999 if (i
.tm
.opcode_modifier
.w
)
4001 if (i
.tm
.opcode_modifier
.shortform
)
4002 i
.tm
.base_opcode
|= 8;
4004 i
.tm
.base_opcode
|= 1;
4007 /* Now select between word & dword operations via the operand
4008 size prefix, except for instructions that will ignore this
4010 if (i
.tm
.opcode_modifier
.addrprefixop0
)
4012 /* The address size override prefix changes the size of the
4014 if ((flag_code
== CODE_32BIT
4015 && i
.op
->regs
[0].reg_type
.bitfield
.reg16
)
4016 || (flag_code
!= CODE_32BIT
4017 && i
.op
->regs
[0].reg_type
.bitfield
.reg32
))
4018 if (!add_prefix (ADDR_PREFIX_OPCODE
))
4021 else if (i
.suffix
!= QWORD_MNEM_SUFFIX
4022 && i
.suffix
!= LONG_DOUBLE_MNEM_SUFFIX
4023 && !i
.tm
.opcode_modifier
.ignoresize
4024 && !i
.tm
.opcode_modifier
.floatmf
4025 && ((i
.suffix
== LONG_MNEM_SUFFIX
) == (flag_code
== CODE_16BIT
)
4026 || (flag_code
== CODE_64BIT
4027 && i
.tm
.opcode_modifier
.jumpbyte
)))
4029 unsigned int prefix
= DATA_PREFIX_OPCODE
;
4031 if (i
.tm
.opcode_modifier
.jumpbyte
) /* jcxz, loop */
4032 prefix
= ADDR_PREFIX_OPCODE
;
4034 if (!add_prefix (prefix
))
4038 /* Set mode64 for an operand. */
4039 if (i
.suffix
== QWORD_MNEM_SUFFIX
4040 && flag_code
== CODE_64BIT
4041 && !i
.tm
.opcode_modifier
.norex64
)
4043 /* Special case for xchg %rax,%rax. It is NOP and doesn't
4044 need rex64. cmpxchg8b is also a special case. */
4045 if (! (i
.operands
== 2
4046 && i
.tm
.base_opcode
== 0x90
4047 && i
.tm
.extension_opcode
== None
4048 && operand_type_equal (&i
.types
[0], &acc64
)
4049 && operand_type_equal (&i
.types
[1], &acc64
))
4050 && ! (i
.operands
== 1
4051 && i
.tm
.base_opcode
== 0xfc7
4052 && i
.tm
.extension_opcode
== 1
4053 && !operand_type_check (i
.types
[0], reg
)
4054 && operand_type_check (i
.types
[0], anymem
)))
4058 /* Size floating point instruction. */
4059 if (i
.suffix
== LONG_MNEM_SUFFIX
)
4060 if (i
.tm
.opcode_modifier
.floatmf
)
4061 i
.tm
.base_opcode
^= 4;
4068 check_byte_reg (void)
4072 for (op
= i
.operands
; --op
>= 0;)
4074 /* If this is an eight bit register, it's OK. If it's the 16 or
4075 32 bit version of an eight bit register, we will just use the
4076 low portion, and that's OK too. */
4077 if (i
.types
[op
].bitfield
.reg8
)
4080 /* Don't generate this warning if not needed. */
4081 if (intel_syntax
&& i
.tm
.opcode_modifier
.byteokintel
)
4084 /* crc32 doesn't generate this warning. */
4085 if (i
.tm
.base_opcode
== 0xf20f38f0)
4088 if ((i
.types
[op
].bitfield
.reg16
4089 || i
.types
[op
].bitfield
.reg32
4090 || i
.types
[op
].bitfield
.reg64
)
4091 && i
.op
[op
].regs
->reg_num
< 4)
4093 /* Prohibit these changes in the 64bit mode, since the
4094 lowering is more complicated. */
4095 if (flag_code
== CODE_64BIT
4096 && !i
.tm
.operand_types
[op
].bitfield
.inoutportreg
)
4098 as_bad (_("Incorrect register `%s%s' used with `%c' suffix"),
4099 register_prefix
, i
.op
[op
].regs
->reg_name
,
4103 #if REGISTER_WARNINGS
4105 && !i
.tm
.operand_types
[op
].bitfield
.inoutportreg
)
4106 as_warn (_("using `%s%s' instead of `%s%s' due to `%c' suffix"),
4108 (i
.op
[op
].regs
+ (i
.types
[op
].bitfield
.reg16
4109 ? REGNAM_AL
- REGNAM_AX
4110 : REGNAM_AL
- REGNAM_EAX
))->reg_name
,
4112 i
.op
[op
].regs
->reg_name
,
4117 /* Any other register is bad. */
4118 if (i
.types
[op
].bitfield
.reg16
4119 || i
.types
[op
].bitfield
.reg32
4120 || i
.types
[op
].bitfield
.reg64
4121 || i
.types
[op
].bitfield
.regmmx
4122 || i
.types
[op
].bitfield
.regxmm
4123 || i
.types
[op
].bitfield
.regymm
4124 || i
.types
[op
].bitfield
.sreg2
4125 || i
.types
[op
].bitfield
.sreg3
4126 || i
.types
[op
].bitfield
.control
4127 || i
.types
[op
].bitfield
.debug
4128 || i
.types
[op
].bitfield
.test
4129 || i
.types
[op
].bitfield
.floatreg
4130 || i
.types
[op
].bitfield
.floatacc
)
4132 as_bad (_("`%s%s' not allowed with `%s%c'"),
4134 i
.op
[op
].regs
->reg_name
,
4144 check_long_reg (void)
4148 for (op
= i
.operands
; --op
>= 0;)
4149 /* Reject eight bit registers, except where the template requires
4150 them. (eg. movzb) */
4151 if (i
.types
[op
].bitfield
.reg8
4152 && (i
.tm
.operand_types
[op
].bitfield
.reg16
4153 || i
.tm
.operand_types
[op
].bitfield
.reg32
4154 || i
.tm
.operand_types
[op
].bitfield
.acc
))
4156 as_bad (_("`%s%s' not allowed with `%s%c'"),
4158 i
.op
[op
].regs
->reg_name
,
4163 /* Warn if the e prefix on a general reg is missing. */
4164 else if ((!quiet_warnings
|| flag_code
== CODE_64BIT
)
4165 && i
.types
[op
].bitfield
.reg16
4166 && (i
.tm
.operand_types
[op
].bitfield
.reg32
4167 || i
.tm
.operand_types
[op
].bitfield
.acc
))
4169 /* Prohibit these changes in the 64bit mode, since the
4170 lowering is more complicated. */
4171 if (flag_code
== CODE_64BIT
)
4173 as_bad (_("Incorrect register `%s%s' used with `%c' suffix"),
4174 register_prefix
, i
.op
[op
].regs
->reg_name
,
4178 #if REGISTER_WARNINGS
4180 as_warn (_("using `%s%s' instead of `%s%s' due to `%c' suffix"),
4182 (i
.op
[op
].regs
+ REGNAM_EAX
- REGNAM_AX
)->reg_name
,
4184 i
.op
[op
].regs
->reg_name
,
4188 /* Warn if the r prefix on a general reg is missing. */
4189 else if (i
.types
[op
].bitfield
.reg64
4190 && (i
.tm
.operand_types
[op
].bitfield
.reg32
4191 || i
.tm
.operand_types
[op
].bitfield
.acc
))
4194 && i
.tm
.opcode_modifier
.toqword
4195 && !i
.types
[0].bitfield
.regxmm
)
4197 /* Convert to QWORD. We want REX byte. */
4198 i
.suffix
= QWORD_MNEM_SUFFIX
;
4202 as_bad (_("Incorrect register `%s%s' used with `%c' suffix"),
4203 register_prefix
, i
.op
[op
].regs
->reg_name
,
4212 check_qword_reg (void)
4216 for (op
= i
.operands
; --op
>= 0; )
4217 /* Reject eight bit registers, except where the template requires
4218 them. (eg. movzb) */
4219 if (i
.types
[op
].bitfield
.reg8
4220 && (i
.tm
.operand_types
[op
].bitfield
.reg16
4221 || i
.tm
.operand_types
[op
].bitfield
.reg32
4222 || i
.tm
.operand_types
[op
].bitfield
.acc
))
4224 as_bad (_("`%s%s' not allowed with `%s%c'"),
4226 i
.op
[op
].regs
->reg_name
,
4231 /* Warn if the e prefix on a general reg is missing. */
4232 else if ((i
.types
[op
].bitfield
.reg16
4233 || i
.types
[op
].bitfield
.reg32
)
4234 && (i
.tm
.operand_types
[op
].bitfield
.reg32
4235 || i
.tm
.operand_types
[op
].bitfield
.acc
))
4237 /* Prohibit these changes in the 64bit mode, since the
4238 lowering is more complicated. */
4240 && i
.tm
.opcode_modifier
.todword
4241 && !i
.types
[0].bitfield
.regxmm
)
4243 /* Convert to DWORD. We don't want REX byte. */
4244 i
.suffix
= LONG_MNEM_SUFFIX
;
4248 as_bad (_("Incorrect register `%s%s' used with `%c' suffix"),
4249 register_prefix
, i
.op
[op
].regs
->reg_name
,
4258 check_word_reg (void)
4261 for (op
= i
.operands
; --op
>= 0;)
4262 /* Reject eight bit registers, except where the template requires
4263 them. (eg. movzb) */
4264 if (i
.types
[op
].bitfield
.reg8
4265 && (i
.tm
.operand_types
[op
].bitfield
.reg16
4266 || i
.tm
.operand_types
[op
].bitfield
.reg32
4267 || i
.tm
.operand_types
[op
].bitfield
.acc
))
4269 as_bad (_("`%s%s' not allowed with `%s%c'"),
4271 i
.op
[op
].regs
->reg_name
,
4276 /* Warn if the e prefix on a general reg is present. */
4277 else if ((!quiet_warnings
|| flag_code
== CODE_64BIT
)
4278 && i
.types
[op
].bitfield
.reg32
4279 && (i
.tm
.operand_types
[op
].bitfield
.reg16
4280 || i
.tm
.operand_types
[op
].bitfield
.acc
))
4282 /* Prohibit these changes in the 64bit mode, since the
4283 lowering is more complicated. */
4284 if (flag_code
== CODE_64BIT
)
4286 as_bad (_("Incorrect register `%s%s' used with `%c' suffix"),
4287 register_prefix
, i
.op
[op
].regs
->reg_name
,
4292 #if REGISTER_WARNINGS
4293 as_warn (_("using `%s%s' instead of `%s%s' due to `%c' suffix"),
4295 (i
.op
[op
].regs
+ REGNAM_AX
- REGNAM_EAX
)->reg_name
,
4297 i
.op
[op
].regs
->reg_name
,
4305 update_imm (unsigned int j
)
4307 i386_operand_type overlap
;
4309 overlap
= operand_type_and (i
.types
[j
], i
.tm
.operand_types
[j
]);
4310 if ((overlap
.bitfield
.imm8
4311 || overlap
.bitfield
.imm8s
4312 || overlap
.bitfield
.imm16
4313 || overlap
.bitfield
.imm32
4314 || overlap
.bitfield
.imm32s
4315 || overlap
.bitfield
.imm64
)
4316 && !operand_type_equal (&overlap
, &imm8
)
4317 && !operand_type_equal (&overlap
, &imm8s
)
4318 && !operand_type_equal (&overlap
, &imm16
)
4319 && !operand_type_equal (&overlap
, &imm32
)
4320 && !operand_type_equal (&overlap
, &imm32s
)
4321 && !operand_type_equal (&overlap
, &imm64
))
4325 i386_operand_type temp
;
4327 operand_type_set (&temp
, 0);
4328 if (i
.suffix
== BYTE_MNEM_SUFFIX
)
4330 temp
.bitfield
.imm8
= overlap
.bitfield
.imm8
;
4331 temp
.bitfield
.imm8s
= overlap
.bitfield
.imm8s
;
4333 else if (i
.suffix
== WORD_MNEM_SUFFIX
)
4334 temp
.bitfield
.imm16
= overlap
.bitfield
.imm16
;
4335 else if (i
.suffix
== QWORD_MNEM_SUFFIX
)
4337 temp
.bitfield
.imm64
= overlap
.bitfield
.imm64
;
4338 temp
.bitfield
.imm32s
= overlap
.bitfield
.imm32s
;
4341 temp
.bitfield
.imm32
= overlap
.bitfield
.imm32
;
4344 else if (operand_type_equal (&overlap
, &imm16_32_32s
)
4345 || operand_type_equal (&overlap
, &imm16_32
)
4346 || operand_type_equal (&overlap
, &imm16_32s
))
4348 if ((flag_code
== CODE_16BIT
) ^ (i
.prefix
[DATA_PREFIX
] != 0))
4353 if (!operand_type_equal (&overlap
, &imm8
)
4354 && !operand_type_equal (&overlap
, &imm8s
)
4355 && !operand_type_equal (&overlap
, &imm16
)
4356 && !operand_type_equal (&overlap
, &imm32
)
4357 && !operand_type_equal (&overlap
, &imm32s
)
4358 && !operand_type_equal (&overlap
, &imm64
))
4360 as_bad (_("no instruction mnemonic suffix given; "
4361 "can't determine immediate size"));
4365 i
.types
[j
] = overlap
;
4375 for (j
= 0; j
< 2; j
++)
4376 if (update_imm (j
) == 0)
4379 i
.types
[2] = operand_type_and (i
.types
[2], i
.tm
.operand_types
[2]);
4380 assert (operand_type_check (i
.types
[2], imm
) == 0);
4388 i
.drex
.modrm_reg
= 0;
4389 i
.drex
.modrm_regmem
= 0;
4391 /* SSE5 4 operand instructions must have the destination the same as
4392 one of the inputs. Figure out the destination register and cache
4393 it away in the drex field, and remember which fields to use for
4395 if (i
.tm
.opcode_modifier
.drex
4396 && i
.tm
.opcode_modifier
.drexv
4399 i
.tm
.extension_opcode
= None
;
4401 /* Case 1: 4 operand insn, dest = src1, src3 = register. */
4402 if (i
.types
[0].bitfield
.regxmm
!= 0
4403 && i
.types
[1].bitfield
.regxmm
!= 0
4404 && i
.types
[2].bitfield
.regxmm
!= 0
4405 && i
.types
[3].bitfield
.regxmm
!= 0
4406 && i
.op
[0].regs
->reg_num
== i
.op
[3].regs
->reg_num
4407 && i
.op
[0].regs
->reg_flags
== i
.op
[3].regs
->reg_flags
)
4409 /* Clear the arguments that are stored in drex. */
4410 operand_type_set (&i
.types
[0], 0);
4411 operand_type_set (&i
.types
[3], 0);
4412 i
.reg_operands
-= 2;
4414 /* There are two different ways to encode a 4 operand
4415 instruction with all registers that uses OC1 set to
4416 0 or 1. Favor setting OC1 to 0 since this mimics the
4417 actions of other SSE5 assemblers. Use modrm encoding 2
4418 for register/register. Include the high order bit that
4419 is normally stored in the REX byte in the register
4421 i
.tm
.extension_opcode
= DREX_X1_XMEM_X2_X1
;
4422 i
.drex
.modrm_reg
= 2;
4423 i
.drex
.modrm_regmem
= 1;
4424 i
.drex
.reg
= (i
.op
[3].regs
->reg_num
4425 + ((i
.op
[3].regs
->reg_flags
& RegRex
) ? 8 : 0));
4428 /* Case 2: 4 operand insn, dest = src1, src3 = memory. */
4429 else if (i
.types
[0].bitfield
.regxmm
!= 0
4430 && i
.types
[1].bitfield
.regxmm
!= 0
4431 && (i
.types
[2].bitfield
.regxmm
4432 || operand_type_check (i
.types
[2], anymem
))
4433 && i
.types
[3].bitfield
.regxmm
!= 0
4434 && i
.op
[0].regs
->reg_num
== i
.op
[3].regs
->reg_num
4435 && i
.op
[0].regs
->reg_flags
== i
.op
[3].regs
->reg_flags
)
4437 /* clear the arguments that are stored in drex */
4438 operand_type_set (&i
.types
[0], 0);
4439 operand_type_set (&i
.types
[3], 0);
4440 i
.reg_operands
-= 2;
4442 /* Specify the modrm encoding for memory addressing. Include
4443 the high order bit that is normally stored in the REX byte
4444 in the register field. */
4445 i
.tm
.extension_opcode
= DREX_X1_X2_XMEM_X1
;
4446 i
.drex
.modrm_reg
= 1;
4447 i
.drex
.modrm_regmem
= 2;
4448 i
.drex
.reg
= (i
.op
[3].regs
->reg_num
4449 + ((i
.op
[3].regs
->reg_flags
& RegRex
) ? 8 : 0));
4452 /* Case 3: 4 operand insn, dest = src1, src2 = memory. */
4453 else if (i
.types
[0].bitfield
.regxmm
!= 0
4454 && operand_type_check (i
.types
[1], anymem
) != 0
4455 && i
.types
[2].bitfield
.regxmm
!= 0
4456 && i
.types
[3].bitfield
.regxmm
!= 0
4457 && i
.op
[0].regs
->reg_num
== i
.op
[3].regs
->reg_num
4458 && i
.op
[0].regs
->reg_flags
== i
.op
[3].regs
->reg_flags
)
4460 /* Clear the arguments that are stored in drex. */
4461 operand_type_set (&i
.types
[0], 0);
4462 operand_type_set (&i
.types
[3], 0);
4463 i
.reg_operands
-= 2;
4465 /* Specify the modrm encoding for memory addressing. Include
4466 the high order bit that is normally stored in the REX byte
4467 in the register field. */
4468 i
.tm
.extension_opcode
= DREX_X1_XMEM_X2_X1
;
4469 i
.drex
.modrm_reg
= 2;
4470 i
.drex
.modrm_regmem
= 1;
4471 i
.drex
.reg
= (i
.op
[3].regs
->reg_num
4472 + ((i
.op
[3].regs
->reg_flags
& RegRex
) ? 8 : 0));
4475 /* Case 4: 4 operand insn, dest = src3, src2 = register. */
4476 else if (i
.types
[0].bitfield
.regxmm
!= 0
4477 && i
.types
[1].bitfield
.regxmm
!= 0
4478 && i
.types
[2].bitfield
.regxmm
!= 0
4479 && i
.types
[3].bitfield
.regxmm
!= 0
4480 && i
.op
[2].regs
->reg_num
== i
.op
[3].regs
->reg_num
4481 && i
.op
[2].regs
->reg_flags
== i
.op
[3].regs
->reg_flags
)
4483 /* clear the arguments that are stored in drex */
4484 operand_type_set (&i
.types
[2], 0);
4485 operand_type_set (&i
.types
[3], 0);
4486 i
.reg_operands
-= 2;
4488 /* There are two different ways to encode a 4 operand
4489 instruction with all registers that uses OC1 set to
4490 0 or 1. Favor setting OC1 to 0 since this mimics the
4491 actions of other SSE5 assemblers. Use modrm encoding
4492 2 for register/register. Include the high order bit that
4493 is normally stored in the REX byte in the register
4495 i
.tm
.extension_opcode
= DREX_XMEM_X1_X2_X2
;
4496 i
.drex
.modrm_reg
= 1;
4497 i
.drex
.modrm_regmem
= 0;
4499 /* Remember the register, including the upper bits */
4500 i
.drex
.reg
= (i
.op
[3].regs
->reg_num
4501 + ((i
.op
[3].regs
->reg_flags
& RegRex
) ? 8 : 0));
4504 /* Case 5: 4 operand insn, dest = src3, src2 = memory. */
4505 else if (i
.types
[0].bitfield
.regxmm
!= 0
4506 && (i
.types
[1].bitfield
.regxmm
4507 || operand_type_check (i
.types
[1], anymem
))
4508 && i
.types
[2].bitfield
.regxmm
!= 0
4509 && i
.types
[3].bitfield
.regxmm
!= 0
4510 && i
.op
[2].regs
->reg_num
== i
.op
[3].regs
->reg_num
4511 && i
.op
[2].regs
->reg_flags
== i
.op
[3].regs
->reg_flags
)
4513 /* Clear the arguments that are stored in drex. */
4514 operand_type_set (&i
.types
[2], 0);
4515 operand_type_set (&i
.types
[3], 0);
4516 i
.reg_operands
-= 2;
4518 /* Specify the modrm encoding and remember the register
4519 including the bits normally stored in the REX byte. */
4520 i
.tm
.extension_opcode
= DREX_X1_XMEM_X2_X2
;
4521 i
.drex
.modrm_reg
= 0;
4522 i
.drex
.modrm_regmem
= 1;
4523 i
.drex
.reg
= (i
.op
[3].regs
->reg_num
4524 + ((i
.op
[3].regs
->reg_flags
& RegRex
) ? 8 : 0));
4527 /* Case 6: 4 operand insn, dest = src3, src1 = memory. */
4528 else if (operand_type_check (i
.types
[0], anymem
) != 0
4529 && i
.types
[1].bitfield
.regxmm
!= 0
4530 && i
.types
[2].bitfield
.regxmm
!= 0
4531 && i
.types
[3].bitfield
.regxmm
!= 0
4532 && i
.op
[2].regs
->reg_num
== i
.op
[3].regs
->reg_num
4533 && i
.op
[2].regs
->reg_flags
== i
.op
[3].regs
->reg_flags
)
4535 /* clear the arguments that are stored in drex */
4536 operand_type_set (&i
.types
[2], 0);
4537 operand_type_set (&i
.types
[3], 0);
4538 i
.reg_operands
-= 2;
4540 /* Specify the modrm encoding and remember the register
4541 including the bits normally stored in the REX byte. */
4542 i
.tm
.extension_opcode
= DREX_XMEM_X1_X2_X2
;
4543 i
.drex
.modrm_reg
= 1;
4544 i
.drex
.modrm_regmem
= 0;
4545 i
.drex
.reg
= (i
.op
[3].regs
->reg_num
4546 + ((i
.op
[3].regs
->reg_flags
& RegRex
) ? 8 : 0));
4550 as_bad (_("Incorrect operands for the '%s' instruction"),
4554 /* SSE5 instructions with the DREX byte where the only memory operand
4555 is in the 2nd argument, and the first and last xmm register must
4556 match, and is encoded in the DREX byte. */
4557 else if (i
.tm
.opcode_modifier
.drex
4558 && !i
.tm
.opcode_modifier
.drexv
4561 /* Case 1: 4 operand insn, dest = src1, src3 = reg/mem. */
4562 if (i
.types
[0].bitfield
.regxmm
!= 0
4563 && (i
.types
[1].bitfield
.regxmm
4564 || operand_type_check(i
.types
[1], anymem
))
4565 && i
.types
[2].bitfield
.regxmm
!= 0
4566 && i
.types
[3].bitfield
.regxmm
!= 0
4567 && i
.op
[0].regs
->reg_num
== i
.op
[3].regs
->reg_num
4568 && i
.op
[0].regs
->reg_flags
== i
.op
[3].regs
->reg_flags
)
4570 /* clear the arguments that are stored in drex */
4571 operand_type_set (&i
.types
[0], 0);
4572 operand_type_set (&i
.types
[3], 0);
4573 i
.reg_operands
-= 2;
4575 /* Specify the modrm encoding and remember the register
4576 including the high bit normally stored in the REX
4578 i
.drex
.modrm_reg
= 2;
4579 i
.drex
.modrm_regmem
= 1;
4580 i
.drex
.reg
= (i
.op
[3].regs
->reg_num
4581 + ((i
.op
[3].regs
->reg_flags
& RegRex
) ? 8 : 0));
4585 as_bad (_("Incorrect operands for the '%s' instruction"),
4589 /* SSE5 3 operand instructions that the result is a register, being
4590 either operand can be a memory operand, using OC0 to note which
4591 one is the memory. */
4592 else if (i
.tm
.opcode_modifier
.drex
4593 && i
.tm
.opcode_modifier
.drexv
4596 i
.tm
.extension_opcode
= None
;
4598 /* Case 1: 3 operand insn, src1 = register. */
4599 if (i
.types
[0].bitfield
.regxmm
!= 0
4600 && i
.types
[1].bitfield
.regxmm
!= 0
4601 && i
.types
[2].bitfield
.regxmm
!= 0)
4603 /* Clear the arguments that are stored in drex. */
4604 operand_type_set (&i
.types
[2], 0);
4607 /* Specify the modrm encoding and remember the register
4608 including the high bit normally stored in the REX byte. */
4609 i
.tm
.extension_opcode
= DREX_XMEM_X1_X2
;
4610 i
.drex
.modrm_reg
= 1;
4611 i
.drex
.modrm_regmem
= 0;
4612 i
.drex
.reg
= (i
.op
[2].regs
->reg_num
4613 + ((i
.op
[2].regs
->reg_flags
& RegRex
) ? 8 : 0));
4616 /* Case 2: 3 operand insn, src1 = memory. */
4617 else if (operand_type_check (i
.types
[0], anymem
) != 0
4618 && i
.types
[1].bitfield
.regxmm
!= 0
4619 && i
.types
[2].bitfield
.regxmm
!= 0)
4621 /* Clear the arguments that are stored in drex. */
4622 operand_type_set (&i
.types
[2], 0);
4625 /* Specify the modrm encoding and remember the register
4626 including the high bit normally stored in the REX
4628 i
.tm
.extension_opcode
= DREX_XMEM_X1_X2
;
4629 i
.drex
.modrm_reg
= 1;
4630 i
.drex
.modrm_regmem
= 0;
4631 i
.drex
.reg
= (i
.op
[2].regs
->reg_num
4632 + ((i
.op
[2].regs
->reg_flags
& RegRex
) ? 8 : 0));
4635 /* Case 3: 3 operand insn, src2 = memory. */
4636 else if (i
.types
[0].bitfield
.regxmm
!= 0
4637 && operand_type_check (i
.types
[1], anymem
) != 0
4638 && i
.types
[2].bitfield
.regxmm
!= 0)
4640 /* Clear the arguments that are stored in drex. */
4641 operand_type_set (&i
.types
[2], 0);
4644 /* Specify the modrm encoding and remember the register
4645 including the high bit normally stored in the REX byte. */
4646 i
.tm
.extension_opcode
= DREX_X1_XMEM_X2
;
4647 i
.drex
.modrm_reg
= 0;
4648 i
.drex
.modrm_regmem
= 1;
4649 i
.drex
.reg
= (i
.op
[2].regs
->reg_num
4650 + ((i
.op
[2].regs
->reg_flags
& RegRex
) ? 8 : 0));
4654 as_bad (_("Incorrect operands for the '%s' instruction"),
4658 /* SSE5 4 operand instructions that are the comparison instructions
4659 where the first operand is the immediate value of the comparison
4661 else if (i
.tm
.opcode_modifier
.drexc
!= 0 && i
.operands
== 4)
4663 /* Case 1: 4 operand insn, src1 = reg/memory. */
4664 if (operand_type_check (i
.types
[0], imm
) != 0
4665 && (i
.types
[1].bitfield
.regxmm
4666 || operand_type_check (i
.types
[1], anymem
))
4667 && i
.types
[2].bitfield
.regxmm
!= 0
4668 && i
.types
[3].bitfield
.regxmm
!= 0)
4670 /* clear the arguments that are stored in drex */
4671 operand_type_set (&i
.types
[3], 0);
4674 /* Specify the modrm encoding and remember the register
4675 including the high bit normally stored in the REX byte. */
4676 i
.drex
.modrm_reg
= 2;
4677 i
.drex
.modrm_regmem
= 1;
4678 i
.drex
.reg
= (i
.op
[3].regs
->reg_num
4679 + ((i
.op
[3].regs
->reg_flags
& RegRex
) ? 8 : 0));
4682 /* Case 2: 3 operand insn with ImmExt that places the
4683 opcode_extension as an immediate argument. This is used for
4684 all of the varients of comparison that supplies the appropriate
4685 value as part of the instruction. */
4686 else if ((i
.types
[0].bitfield
.regxmm
4687 || operand_type_check (i
.types
[0], anymem
))
4688 && i
.types
[1].bitfield
.regxmm
!= 0
4689 && i
.types
[2].bitfield
.regxmm
!= 0
4690 && operand_type_check (i
.types
[3], imm
) != 0)
4692 /* clear the arguments that are stored in drex */
4693 operand_type_set (&i
.types
[2], 0);
4696 /* Specify the modrm encoding and remember the register
4697 including the high bit normally stored in the REX byte. */
4698 i
.drex
.modrm_reg
= 1;
4699 i
.drex
.modrm_regmem
= 0;
4700 i
.drex
.reg
= (i
.op
[2].regs
->reg_num
4701 + ((i
.op
[2].regs
->reg_flags
& RegRex
) ? 8 : 0));
4705 as_bad (_("Incorrect operands for the '%s' instruction"),
4709 else if (i
.tm
.opcode_modifier
.drex
4710 || i
.tm
.opcode_modifier
.drexv
4711 || i
.tm
.opcode_modifier
.drexc
)
4712 as_bad (_("Internal error for the '%s' instruction"), i
.tm
.name
);
4716 bad_implicit_operand (int xmm
)
4718 const char *reg
= xmm
? "xmm0" : "ymm0";
4720 as_bad (_("the last operand of `%s' must be `%s%s'"),
4721 i
.tm
.name
, register_prefix
, reg
);
4723 as_bad (_("the first operand of `%s' must be `%s%s'"),
4724 i
.tm
.name
, register_prefix
, reg
);
4729 process_operands (void)
4731 /* Default segment register this instruction will use for memory
4732 accesses. 0 means unknown. This is only for optimizing out
4733 unnecessary segment overrides. */
4734 const seg_entry
*default_seg
= 0;
4736 /* Handle all of the DREX munging that SSE5 needs. */
4737 if (i
.tm
.opcode_modifier
.drex
4738 || i
.tm
.opcode_modifier
.drexv
4739 || i
.tm
.opcode_modifier
.drexc
)
4742 if (i
.tm
.opcode_modifier
.sse2avx
4743 && (i
.tm
.opcode_modifier
.vexnds
4744 || i
.tm
.opcode_modifier
.vexndd
))
4746 unsigned int dup
= i
.operands
;
4747 unsigned int dest
= dup
- 1;
4750 /* The destination must be an xmm register. */
4751 assert (i
.reg_operands
4752 && MAX_OPERANDS
> dup
4753 && operand_type_equal (&i
.types
[dest
], ®xmm
));
4755 if (i
.tm
.opcode_modifier
.firstxmm0
)
4757 /* The first operand is implicit and must be xmm0. */
4758 assert (operand_type_equal (&i
.types
[0], ®xmm
));
4759 if (i
.op
[0].regs
->reg_num
!= 0)
4760 return bad_implicit_operand (1);
4762 if (i
.tm
.opcode_modifier
.vex3sources
)
4764 /* Keep xmm0 for instructions with VEX prefix and 3
4770 /* We remove the first xmm0 and keep the number of
4771 operands unchanged, which in fact duplicates the
4773 for (j
= 1; j
< i
.operands
; j
++)
4775 i
.op
[j
- 1] = i
.op
[j
];
4776 i
.types
[j
- 1] = i
.types
[j
];
4777 i
.tm
.operand_types
[j
- 1] = i
.tm
.operand_types
[j
];
4781 else if (i
.tm
.opcode_modifier
.implicit1stxmm0
)
4783 assert ((MAX_OPERANDS
- 1) > dup
4784 && i
.tm
.opcode_modifier
.vex3sources
);
4786 /* Add the implicit xmm0 for instructions with VEX prefix
4788 for (j
= i
.operands
; j
> 0; j
--)
4790 i
.op
[j
] = i
.op
[j
- 1];
4791 i
.types
[j
] = i
.types
[j
- 1];
4792 i
.tm
.operand_types
[j
] = i
.tm
.operand_types
[j
- 1];
4795 = (const reg_entry
*) hash_find (reg_hash
, "xmm0");
4796 i
.types
[0] = regxmm
;
4797 i
.tm
.operand_types
[0] = regxmm
;
4800 i
.reg_operands
+= 2;
4805 i
.op
[dup
] = i
.op
[dest
];
4806 i
.types
[dup
] = i
.types
[dest
];
4807 i
.tm
.operand_types
[dup
] = i
.tm
.operand_types
[dest
];
4816 i
.op
[dup
] = i
.op
[dest
];
4817 i
.types
[dup
] = i
.types
[dest
];
4818 i
.tm
.operand_types
[dup
] = i
.tm
.operand_types
[dest
];
4821 if (i
.tm
.opcode_modifier
.immext
)
4824 else if (i
.tm
.opcode_modifier
.firstxmm0
)
4828 /* The first operand is implicit and must be xmm0/ymm0. */
4829 assert (i
.reg_operands
4830 && (operand_type_equal (&i
.types
[0], ®xmm
)
4831 || operand_type_equal (&i
.types
[0], ®ymm
)));
4832 if (i
.op
[0].regs
->reg_num
!= 0)
4833 return bad_implicit_operand (i
.types
[0].bitfield
.regxmm
);
4835 for (j
= 1; j
< i
.operands
; j
++)
4837 i
.op
[j
- 1] = i
.op
[j
];
4838 i
.types
[j
- 1] = i
.types
[j
];
4840 /* We need to adjust fields in i.tm since they are used by
4841 build_modrm_byte. */
4842 i
.tm
.operand_types
[j
- 1] = i
.tm
.operand_types
[j
];
4849 else if (i
.tm
.opcode_modifier
.regkludge
)
4851 /* The imul $imm, %reg instruction is converted into
4852 imul $imm, %reg, %reg, and the clr %reg instruction
4853 is converted into xor %reg, %reg. */
4855 unsigned int first_reg_op
;
4857 if (operand_type_check (i
.types
[0], reg
))
4861 /* Pretend we saw the extra register operand. */
4862 assert (i
.reg_operands
== 1
4863 && i
.op
[first_reg_op
+ 1].regs
== 0);
4864 i
.op
[first_reg_op
+ 1].regs
= i
.op
[first_reg_op
].regs
;
4865 i
.types
[first_reg_op
+ 1] = i
.types
[first_reg_op
];
4870 if (i
.tm
.opcode_modifier
.shortform
)
4872 if (i
.types
[0].bitfield
.sreg2
4873 || i
.types
[0].bitfield
.sreg3
)
4875 if (i
.tm
.base_opcode
== POP_SEG_SHORT
4876 && i
.op
[0].regs
->reg_num
== 1)
4878 as_bad (_("you can't `pop %%cs'"));
4881 i
.tm
.base_opcode
|= (i
.op
[0].regs
->reg_num
<< 3);
4882 if ((i
.op
[0].regs
->reg_flags
& RegRex
) != 0)
4887 /* The register or float register operand is in operand
4891 if (i
.types
[0].bitfield
.floatreg
4892 || operand_type_check (i
.types
[0], reg
))
4896 /* Register goes in low 3 bits of opcode. */
4897 i
.tm
.base_opcode
|= i
.op
[op
].regs
->reg_num
;
4898 if ((i
.op
[op
].regs
->reg_flags
& RegRex
) != 0)
4900 if (!quiet_warnings
&& i
.tm
.opcode_modifier
.ugh
)
4902 /* Warn about some common errors, but press on regardless.
4903 The first case can be generated by gcc (<= 2.8.1). */
4904 if (i
.operands
== 2)
4906 /* Reversed arguments on faddp, fsubp, etc. */
4907 as_warn (_("translating to `%s %s%s,%s%s'"), i
.tm
.name
,
4908 register_prefix
, i
.op
[1].regs
->reg_name
,
4909 register_prefix
, i
.op
[0].regs
->reg_name
);
4913 /* Extraneous `l' suffix on fp insn. */
4914 as_warn (_("translating to `%s %s%s'"), i
.tm
.name
,
4915 register_prefix
, i
.op
[0].regs
->reg_name
);
4920 else if (i
.tm
.opcode_modifier
.modrm
)
4922 /* The opcode is completed (modulo i.tm.extension_opcode which
4923 must be put into the modrm byte). Now, we make the modrm and
4924 index base bytes based on all the info we've collected. */
4926 default_seg
= build_modrm_byte ();
4928 else if ((i
.tm
.base_opcode
& ~0x3) == MOV_AX_DISP32
)
4932 else if (i
.tm
.opcode_modifier
.isstring
)
4934 /* For the string instructions that allow a segment override
4935 on one of their operands, the default segment is ds. */
4939 if (i
.tm
.base_opcode
== 0x8d /* lea */
4942 as_warn (_("segment override on `%s' is ineffectual"), i
.tm
.name
);
4944 /* If a segment was explicitly specified, and the specified segment
4945 is not the default, use an opcode prefix to select it. If we
4946 never figured out what the default segment is, then default_seg
4947 will be zero at this point, and the specified segment prefix will
4949 if ((i
.seg
[0]) && (i
.seg
[0] != default_seg
))
4951 if (!add_prefix (i
.seg
[0]->seg_prefix
))
4957 static const seg_entry
*
4958 build_modrm_byte (void)
4960 const seg_entry
*default_seg
= 0;
4961 unsigned int source
, dest
;
4964 /* The first operand of instructions with VEX prefix and 3 sources
4965 must be VEX_Imm4. */
4966 vex_3_sources
= i
.tm
.opcode_modifier
.vex3sources
;
4969 unsigned int nds
, reg
;
4971 if (i
.tm
.opcode_modifier
.veximmext
4972 && i
.tm
.opcode_modifier
.immext
)
4974 dest
= i
.operands
- 2;
4978 dest
= i
.operands
- 1;
4981 /* There are 2 kinds of instructions:
4982 1. 5 operands: one immediate operand and 4 register
4983 operands or 3 register operands plus 1 memory operand.
4984 It must have VexNDS and VexW0 or VexW1. The destination
4985 must be either XMM or YMM register.
4986 2. 4 operands: 4 register operands or 3 register operands
4987 plus 1 memory operand. It must have VexNDS and VexImmExt. */
4988 if (!((i
.reg_operands
== 4
4989 || (i
.reg_operands
== 3 && i
.mem_operands
== 1))
4990 && i
.tm
.opcode_modifier
.vexnds
4991 && (operand_type_equal (&i
.tm
.operand_types
[dest
], ®xmm
)
4992 || operand_type_equal (&i
.tm
.operand_types
[dest
], ®ymm
))
4993 && (operand_type_equal (&i
.tm
.operand_types
[nds
], ®xmm
)
4994 || operand_type_equal (&i
.tm
.operand_types
[nds
], ®ymm
))
4996 && i
.imm_operands
== 1
4997 && i
.types
[0].bitfield
.vex_imm4
4998 && (i
.tm
.opcode_modifier
.vexw0
4999 || i
.tm
.opcode_modifier
.vexw1
))
5001 && (i
.imm_operands
== 0
5002 || (i
.imm_operands
== 1
5003 && i
.tm
.opcode_modifier
.immext
))
5004 && i
.tm
.opcode_modifier
.veximmext
))))
5007 i
.vex
.register_specifier
= i
.op
[nds
].regs
;
5009 if (i
.imm_operands
== 0)
5011 /* When there is no immediate operand, generate an 8bit
5012 immediate operand to encode the first operand. */
5013 expressionS
*exp
= &im_expressions
[i
.imm_operands
++];
5014 i
.op
[i
.operands
].imms
= exp
;
5015 i
.types
[i
.operands
] = imm8
;
5017 /* If VexW1 is set, the first operand is the source and
5018 the second operand is encoded in the immediate operand. */
5019 if (i
.tm
.opcode_modifier
.vexw1
)
5029 assert (operand_type_equal (&i
.tm
.operand_types
[reg
], ®xmm
)
5030 || operand_type_equal (&i
.tm
.operand_types
[reg
],
5032 exp
->X_op
= O_constant
;
5034 = ((i
.op
[reg
].regs
->reg_num
5035 + ((i
.op
[reg
].regs
->reg_flags
& RegRex
) ? 8 : 0)) << 4);
5041 if (i
.tm
.opcode_modifier
.vexw0
)
5043 /* If VexW0 is set, the third operand is the source and
5044 the second operand is encoded in the immediate
5051 /* VexW1 is set, the second operand is the source and
5052 the third operand is encoded in the immediate
5058 if (i
.tm
.opcode_modifier
.immext
)
5060 /* When ImmExt is set, the immdiate byte is the last
5062 imm
= i
.operands
- 1;
5070 /* Turn on Imm8 so that output_imm will generate it. */
5071 i
.types
[imm
].bitfield
.imm8
= 1;
5074 assert (operand_type_equal (&i
.tm
.operand_types
[reg
], ®xmm
)
5075 || operand_type_equal (&i
.tm
.operand_types
[reg
],
5077 i
.op
[imm
].imms
->X_add_number
5078 |= ((i
.op
[reg
].regs
->reg_num
5079 + ((i
.op
[reg
].regs
->reg_flags
& RegRex
) ? 8 : 0)) << 4);
5085 /* SSE5 4 operand instructions are encoded in such a way that one of
5086 the inputs must match the destination register. Process_drex hides
5087 the 3rd argument in the drex field, so that by the time we get
5088 here, it looks to GAS as if this is a 2 operand instruction. */
5089 if ((i
.tm
.opcode_modifier
.drex
5090 || i
.tm
.opcode_modifier
.drexv
5091 || i
.tm
.opcode_modifier
.drexc
)
5092 && i
.reg_operands
== 2)
5094 const reg_entry
*reg
= i
.op
[i
.drex
.modrm_reg
].regs
;
5095 const reg_entry
*regmem
= i
.op
[i
.drex
.modrm_regmem
].regs
;
5097 i
.rm
.reg
= reg
->reg_num
;
5098 i
.rm
.regmem
= regmem
->reg_num
;
5100 if ((reg
->reg_flags
& RegRex
) != 0)
5102 if ((regmem
->reg_flags
& RegRex
) != 0)
5106 /* i.reg_operands MUST be the number of real register operands;
5107 implicit registers do not count. If there are 3 register
5108 operands, it must be a instruction with VexNDS. For a
5109 instruction with VexNDD, the destination register is encoded
5110 in VEX prefix. If there are 4 register operands, it must be
5111 a instruction with VEX prefix and 3 sources. */
5112 else if (i
.mem_operands
== 0
5113 && ((i
.reg_operands
== 2
5114 && !i
.tm
.opcode_modifier
.vexndd
)
5115 || (i
.reg_operands
== 3
5116 && i
.tm
.opcode_modifier
.vexnds
)
5117 || (i
.reg_operands
== 4 && vex_3_sources
)))
5125 /* When there are 3 operands, one of them may be immediate,
5126 which may be the first or the last operand. Otherwise,
5127 the first operand must be shift count register (cl) or it
5128 is an instruction with VexNDS. */
5129 assert (i
.imm_operands
== 1
5130 || (i
.imm_operands
== 0
5131 && (i
.tm
.opcode_modifier
.vexnds
5132 || i
.types
[0].bitfield
.shiftcount
)));
5133 if (operand_type_check (i
.types
[0], imm
)
5134 || i
.types
[0].bitfield
.shiftcount
)
5140 /* When there are 4 operands, the first two must be 8bit
5141 immediate operands. The source operand will be the 3rd
5144 For instructions with VexNDS, if the first operand
5145 an imm8, the source operand is the 2nd one. If the last
5146 operand is imm8, the source operand is the first one. */
5147 assert ((i
.imm_operands
== 2
5148 && i
.types
[0].bitfield
.imm8
5149 && i
.types
[1].bitfield
.imm8
)
5150 || (i
.tm
.opcode_modifier
.vexnds
5151 && i
.imm_operands
== 1
5152 && (i
.types
[0].bitfield
.imm8
5153 || i
.types
[i
.operands
- 1].bitfield
.imm8
)));
5154 if (i
.tm
.opcode_modifier
.vexnds
)
5156 if (i
.types
[0].bitfield
.imm8
)
5174 if (i
.tm
.opcode_modifier
.vexnds
)
5176 /* For instructions with VexNDS, the register-only
5177 source operand must be XMM or YMM register. It is
5178 encoded in VEX prefix. */
5179 if ((dest
+ 1) >= i
.operands
5180 || (!operand_type_equal (&i
.tm
.operand_types
[dest
],
5182 && !operand_type_equal (&i
.tm
.operand_types
[dest
],
5185 i
.vex
.register_specifier
= i
.op
[dest
].regs
;
5191 /* One of the register operands will be encoded in the i.tm.reg
5192 field, the other in the combined i.tm.mode and i.tm.regmem
5193 fields. If no form of this instruction supports a memory
5194 destination operand, then we assume the source operand may
5195 sometimes be a memory operand and so we need to store the
5196 destination in the i.rm.reg field. */
5197 if (!i
.tm
.operand_types
[dest
].bitfield
.regmem
5198 && operand_type_check (i
.tm
.operand_types
[dest
], anymem
) == 0)
5200 i
.rm
.reg
= i
.op
[dest
].regs
->reg_num
;
5201 i
.rm
.regmem
= i
.op
[source
].regs
->reg_num
;
5202 if ((i
.op
[dest
].regs
->reg_flags
& RegRex
) != 0)
5204 if ((i
.op
[source
].regs
->reg_flags
& RegRex
) != 0)
5209 i
.rm
.reg
= i
.op
[source
].regs
->reg_num
;
5210 i
.rm
.regmem
= i
.op
[dest
].regs
->reg_num
;
5211 if ((i
.op
[dest
].regs
->reg_flags
& RegRex
) != 0)
5213 if ((i
.op
[source
].regs
->reg_flags
& RegRex
) != 0)
5216 if (flag_code
!= CODE_64BIT
&& (i
.rex
& (REX_R
| REX_B
)))
5218 if (!i
.types
[0].bitfield
.control
5219 && !i
.types
[1].bitfield
.control
)
5221 i
.rex
&= ~(REX_R
| REX_B
);
5222 add_prefix (LOCK_PREFIX_OPCODE
);
5226 { /* If it's not 2 reg operands... */
5231 unsigned int fake_zero_displacement
= 0;
5234 /* This has been precalculated for SSE5 instructions
5235 that have a DREX field earlier in process_drex. */
5236 if (i
.tm
.opcode_modifier
.drex
5237 || i
.tm
.opcode_modifier
.drexv
5238 || i
.tm
.opcode_modifier
.drexc
)
5239 op
= i
.drex
.modrm_regmem
;
5242 for (op
= 0; op
< i
.operands
; op
++)
5243 if (operand_type_check (i
.types
[op
], anymem
))
5245 assert (op
< i
.operands
);
5250 if (i
.base_reg
== 0)
5253 if (!i
.disp_operands
)
5254 fake_zero_displacement
= 1;
5255 if (i
.index_reg
== 0)
5257 /* Operand is just <disp> */
5258 if (flag_code
== CODE_64BIT
)
5260 /* 64bit mode overwrites the 32bit absolute
5261 addressing by RIP relative addressing and
5262 absolute addressing is encoded by one of the
5263 redundant SIB forms. */
5264 i
.rm
.regmem
= ESCAPE_TO_TWO_BYTE_ADDRESSING
;
5265 i
.sib
.base
= NO_BASE_REGISTER
;
5266 i
.sib
.index
= NO_INDEX_REGISTER
;
5267 i
.types
[op
] = ((i
.prefix
[ADDR_PREFIX
] == 0)
5268 ? disp32s
: disp32
);
5270 else if ((flag_code
== CODE_16BIT
)
5271 ^ (i
.prefix
[ADDR_PREFIX
] != 0))
5273 i
.rm
.regmem
= NO_BASE_REGISTER_16
;
5274 i
.types
[op
] = disp16
;
5278 i
.rm
.regmem
= NO_BASE_REGISTER
;
5279 i
.types
[op
] = disp32
;
5282 else /* !i.base_reg && i.index_reg */
5284 if (i
.index_reg
->reg_num
== RegEiz
5285 || i
.index_reg
->reg_num
== RegRiz
)
5286 i
.sib
.index
= NO_INDEX_REGISTER
;
5288 i
.sib
.index
= i
.index_reg
->reg_num
;
5289 i
.sib
.base
= NO_BASE_REGISTER
;
5290 i
.sib
.scale
= i
.log2_scale_factor
;
5291 i
.rm
.regmem
= ESCAPE_TO_TWO_BYTE_ADDRESSING
;
5292 i
.types
[op
].bitfield
.disp8
= 0;
5293 i
.types
[op
].bitfield
.disp16
= 0;
5294 i
.types
[op
].bitfield
.disp64
= 0;
5295 if (flag_code
!= CODE_64BIT
)
5297 /* Must be 32 bit */
5298 i
.types
[op
].bitfield
.disp32
= 1;
5299 i
.types
[op
].bitfield
.disp32s
= 0;
5303 i
.types
[op
].bitfield
.disp32
= 0;
5304 i
.types
[op
].bitfield
.disp32s
= 1;
5306 if ((i
.index_reg
->reg_flags
& RegRex
) != 0)
5310 /* RIP addressing for 64bit mode. */
5311 else if (i
.base_reg
->reg_num
== RegRip
||
5312 i
.base_reg
->reg_num
== RegEip
)
5314 i
.rm
.regmem
= NO_BASE_REGISTER
;
5315 i
.types
[op
].bitfield
.disp8
= 0;
5316 i
.types
[op
].bitfield
.disp16
= 0;
5317 i
.types
[op
].bitfield
.disp32
= 0;
5318 i
.types
[op
].bitfield
.disp32s
= 1;
5319 i
.types
[op
].bitfield
.disp64
= 0;
5320 i
.flags
[op
] |= Operand_PCrel
;
5321 if (! i
.disp_operands
)
5322 fake_zero_displacement
= 1;
5324 else if (i
.base_reg
->reg_type
.bitfield
.reg16
)
5326 switch (i
.base_reg
->reg_num
)
5329 if (i
.index_reg
== 0)
5331 else /* (%bx,%si) -> 0, or (%bx,%di) -> 1 */
5332 i
.rm
.regmem
= i
.index_reg
->reg_num
- 6;
5336 if (i
.index_reg
== 0)
5339 if (operand_type_check (i
.types
[op
], disp
) == 0)
5341 /* fake (%bp) into 0(%bp) */
5342 i
.types
[op
].bitfield
.disp8
= 1;
5343 fake_zero_displacement
= 1;
5346 else /* (%bp,%si) -> 2, or (%bp,%di) -> 3 */
5347 i
.rm
.regmem
= i
.index_reg
->reg_num
- 6 + 2;
5349 default: /* (%si) -> 4 or (%di) -> 5 */
5350 i
.rm
.regmem
= i
.base_reg
->reg_num
- 6 + 4;
5352 i
.rm
.mode
= mode_from_disp_size (i
.types
[op
]);
5354 else /* i.base_reg and 32/64 bit mode */
5356 if (flag_code
== CODE_64BIT
5357 && operand_type_check (i
.types
[op
], disp
))
5359 i386_operand_type temp
;
5360 operand_type_set (&temp
, 0);
5361 temp
.bitfield
.disp8
= i
.types
[op
].bitfield
.disp8
;
5363 if (i
.prefix
[ADDR_PREFIX
] == 0)
5364 i
.types
[op
].bitfield
.disp32s
= 1;
5366 i
.types
[op
].bitfield
.disp32
= 1;
5369 i
.rm
.regmem
= i
.base_reg
->reg_num
;
5370 if ((i
.base_reg
->reg_flags
& RegRex
) != 0)
5372 i
.sib
.base
= i
.base_reg
->reg_num
;
5373 /* x86-64 ignores REX prefix bit here to avoid decoder
5375 if ((i
.base_reg
->reg_num
& 7) == EBP_REG_NUM
)
5378 if (i
.disp_operands
== 0)
5380 fake_zero_displacement
= 1;
5381 i
.types
[op
].bitfield
.disp8
= 1;
5384 else if (i
.base_reg
->reg_num
== ESP_REG_NUM
)
5388 i
.sib
.scale
= i
.log2_scale_factor
;
5389 if (i
.index_reg
== 0)
5391 /* <disp>(%esp) becomes two byte modrm with no index
5392 register. We've already stored the code for esp
5393 in i.rm.regmem ie. ESCAPE_TO_TWO_BYTE_ADDRESSING.
5394 Any base register besides %esp will not use the
5395 extra modrm byte. */
5396 i
.sib
.index
= NO_INDEX_REGISTER
;
5400 if (i
.index_reg
->reg_num
== RegEiz
5401 || i
.index_reg
->reg_num
== RegRiz
)
5402 i
.sib
.index
= NO_INDEX_REGISTER
;
5404 i
.sib
.index
= i
.index_reg
->reg_num
;
5405 i
.rm
.regmem
= ESCAPE_TO_TWO_BYTE_ADDRESSING
;
5406 if ((i
.index_reg
->reg_flags
& RegRex
) != 0)
5411 && (i
.reloc
[op
] == BFD_RELOC_386_TLS_DESC_CALL
5412 || i
.reloc
[op
] == BFD_RELOC_X86_64_TLSDESC_CALL
))
5415 i
.rm
.mode
= mode_from_disp_size (i
.types
[op
]);
5418 if (fake_zero_displacement
)
5420 /* Fakes a zero displacement assuming that i.types[op]
5421 holds the correct displacement size. */
5424 assert (i
.op
[op
].disps
== 0);
5425 exp
= &disp_expressions
[i
.disp_operands
++];
5426 i
.op
[op
].disps
= exp
;
5427 exp
->X_op
= O_constant
;
5428 exp
->X_add_number
= 0;
5429 exp
->X_add_symbol
= (symbolS
*) 0;
5430 exp
->X_op_symbol
= (symbolS
*) 0;
5438 /* Fill in i.rm.reg or i.rm.regmem field with register operand
5439 (if any) based on i.tm.extension_opcode. Again, we must be
5440 careful to make sure that segment/control/debug/test/MMX
5441 registers are coded into the i.rm.reg field. */
5446 /* This has been precalculated for SSE5 instructions
5447 that have a DREX field earlier in process_drex. */
5448 if (i
.tm
.opcode_modifier
.drex
5449 || i
.tm
.opcode_modifier
.drexv
5450 || i
.tm
.opcode_modifier
.drexc
)
5452 op
= i
.drex
.modrm_reg
;
5453 i
.rm
.reg
= i
.op
[op
].regs
->reg_num
;
5454 if ((i
.op
[op
].regs
->reg_flags
& RegRex
) != 0)
5459 unsigned int vex_reg
= ~0;
5461 for (op
= 0; op
< i
.operands
; op
++)
5462 if (i
.types
[op
].bitfield
.reg8
5463 || i
.types
[op
].bitfield
.reg16
5464 || i
.types
[op
].bitfield
.reg32
5465 || i
.types
[op
].bitfield
.reg64
5466 || i
.types
[op
].bitfield
.regmmx
5467 || i
.types
[op
].bitfield
.regxmm
5468 || i
.types
[op
].bitfield
.regymm
5469 || i
.types
[op
].bitfield
.sreg2
5470 || i
.types
[op
].bitfield
.sreg3
5471 || i
.types
[op
].bitfield
.control
5472 || i
.types
[op
].bitfield
.debug
5473 || i
.types
[op
].bitfield
.test
)
5478 else if (i
.tm
.opcode_modifier
.vexnds
)
5480 /* For instructions with VexNDS, the register-only
5481 source operand is encoded in VEX prefix. */
5482 assert (mem
!= (unsigned int) ~0);
5487 assert (op
< i
.operands
);
5492 assert (vex_reg
< i
.operands
);
5495 else if (i
.tm
.opcode_modifier
.vexndd
)
5497 /* For instructions with VexNDD, there should be
5498 no memory operand and the register destination
5499 is encoded in VEX prefix. */
5500 assert (i
.mem_operands
== 0
5501 && (op
+ 2) == i
.operands
);
5505 assert (op
< i
.operands
);
5507 if (vex_reg
!= (unsigned int) ~0)
5509 assert (i
.reg_operands
== 2);
5511 if (!operand_type_equal (&i
.tm
.operand_types
[vex_reg
],
5513 && !operand_type_equal (&i
.tm
.operand_types
[vex_reg
],
5516 i
.vex
.register_specifier
= i
.op
[vex_reg
].regs
;
5519 /* If there is an extension opcode to put here, the
5520 register number must be put into the regmem field. */
5521 if (i
.tm
.extension_opcode
!= None
)
5523 i
.rm
.regmem
= i
.op
[op
].regs
->reg_num
;
5524 if ((i
.op
[op
].regs
->reg_flags
& RegRex
) != 0)
5529 i
.rm
.reg
= i
.op
[op
].regs
->reg_num
;
5530 if ((i
.op
[op
].regs
->reg_flags
& RegRex
) != 0)
5535 /* Now, if no memory operand has set i.rm.mode = 0, 1, 2 we
5536 must set it to 3 to indicate this is a register operand
5537 in the regmem field. */
5538 if (!i
.mem_operands
)
5542 /* Fill in i.rm.reg field with extension opcode (if any). */
5543 if (i
.tm
.extension_opcode
!= None
5544 && !(i
.tm
.opcode_modifier
.drex
5545 || i
.tm
.opcode_modifier
.drexv
5546 || i
.tm
.opcode_modifier
.drexc
))
5547 i
.rm
.reg
= i
.tm
.extension_opcode
;
5553 output_branch (void)
5558 relax_substateT subtype
;
5563 if (flag_code
== CODE_16BIT
)
5567 if (i
.prefix
[DATA_PREFIX
] != 0)
5573 /* Pentium4 branch hints. */
5574 if (i
.prefix
[SEG_PREFIX
] == CS_PREFIX_OPCODE
/* not taken */
5575 || i
.prefix
[SEG_PREFIX
] == DS_PREFIX_OPCODE
/* taken */)
5580 if (i
.prefix
[REX_PREFIX
] != 0)
5586 if (i
.prefixes
!= 0 && !intel_syntax
)
5587 as_warn (_("skipping prefixes on this instruction"));
5589 /* It's always a symbol; End frag & setup for relax.
5590 Make sure there is enough room in this frag for the largest
5591 instruction we may generate in md_convert_frag. This is 2
5592 bytes for the opcode and room for the prefix and largest
5594 frag_grow (prefix
+ 2 + 4);
5595 /* Prefix and 1 opcode byte go in fr_fix. */
5596 p
= frag_more (prefix
+ 1);
5597 if (i
.prefix
[DATA_PREFIX
] != 0)
5598 *p
++ = DATA_PREFIX_OPCODE
;
5599 if (i
.prefix
[SEG_PREFIX
] == CS_PREFIX_OPCODE
5600 || i
.prefix
[SEG_PREFIX
] == DS_PREFIX_OPCODE
)
5601 *p
++ = i
.prefix
[SEG_PREFIX
];
5602 if (i
.prefix
[REX_PREFIX
] != 0)
5603 *p
++ = i
.prefix
[REX_PREFIX
];
5604 *p
= i
.tm
.base_opcode
;
5606 if ((unsigned char) *p
== JUMP_PC_RELATIVE
)
5607 subtype
= ENCODE_RELAX_STATE (UNCOND_JUMP
, SMALL
);
5608 else if (cpu_arch_flags
.bitfield
.cpui386
)
5609 subtype
= ENCODE_RELAX_STATE (COND_JUMP
, SMALL
);
5611 subtype
= ENCODE_RELAX_STATE (COND_JUMP86
, SMALL
);
5614 sym
= i
.op
[0].disps
->X_add_symbol
;
5615 off
= i
.op
[0].disps
->X_add_number
;
5617 if (i
.op
[0].disps
->X_op
!= O_constant
5618 && i
.op
[0].disps
->X_op
!= O_symbol
)
5620 /* Handle complex expressions. */
5621 sym
= make_expr_symbol (i
.op
[0].disps
);
5625 /* 1 possible extra opcode + 4 byte displacement go in var part.
5626 Pass reloc in fr_var. */
5627 frag_var (rs_machine_dependent
, 5, i
.reloc
[0], subtype
, sym
, off
, p
);
5637 if (i
.tm
.opcode_modifier
.jumpbyte
)
5639 /* This is a loop or jecxz type instruction. */
5641 if (i
.prefix
[ADDR_PREFIX
] != 0)
5643 FRAG_APPEND_1_CHAR (ADDR_PREFIX_OPCODE
);
5646 /* Pentium4 branch hints. */
5647 if (i
.prefix
[SEG_PREFIX
] == CS_PREFIX_OPCODE
/* not taken */
5648 || i
.prefix
[SEG_PREFIX
] == DS_PREFIX_OPCODE
/* taken */)
5650 FRAG_APPEND_1_CHAR (i
.prefix
[SEG_PREFIX
]);
5659 if (flag_code
== CODE_16BIT
)
5662 if (i
.prefix
[DATA_PREFIX
] != 0)
5664 FRAG_APPEND_1_CHAR (DATA_PREFIX_OPCODE
);
5674 if (i
.prefix
[REX_PREFIX
] != 0)
5676 FRAG_APPEND_1_CHAR (i
.prefix
[REX_PREFIX
]);
5680 if (i
.prefixes
!= 0 && !intel_syntax
)
5681 as_warn (_("skipping prefixes on this instruction"));
5683 p
= frag_more (1 + size
);
5684 *p
++ = i
.tm
.base_opcode
;
5686 fixP
= fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, size
,
5687 i
.op
[0].disps
, 1, reloc (size
, 1, 1, i
.reloc
[0]));
5689 /* All jumps handled here are signed, but don't use a signed limit
5690 check for 32 and 16 bit jumps as we want to allow wrap around at
5691 4G and 64k respectively. */
5693 fixP
->fx_signed
= 1;
5697 output_interseg_jump (void)
5705 if (flag_code
== CODE_16BIT
)
5709 if (i
.prefix
[DATA_PREFIX
] != 0)
5715 if (i
.prefix
[REX_PREFIX
] != 0)
5725 if (i
.prefixes
!= 0 && !intel_syntax
)
5726 as_warn (_("skipping prefixes on this instruction"));
5728 /* 1 opcode; 2 segment; offset */
5729 p
= frag_more (prefix
+ 1 + 2 + size
);
5731 if (i
.prefix
[DATA_PREFIX
] != 0)
5732 *p
++ = DATA_PREFIX_OPCODE
;
5734 if (i
.prefix
[REX_PREFIX
] != 0)
5735 *p
++ = i
.prefix
[REX_PREFIX
];
5737 *p
++ = i
.tm
.base_opcode
;
5738 if (i
.op
[1].imms
->X_op
== O_constant
)
5740 offsetT n
= i
.op
[1].imms
->X_add_number
;
5743 && !fits_in_unsigned_word (n
)
5744 && !fits_in_signed_word (n
))
5746 as_bad (_("16-bit jump out of range"));
5749 md_number_to_chars (p
, n
, size
);
5752 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, size
,
5753 i
.op
[1].imms
, 0, reloc (size
, 0, 0, i
.reloc
[1]));
5754 if (i
.op
[0].imms
->X_op
!= O_constant
)
5755 as_bad (_("can't handle non absolute segment in `%s'"),
5757 md_number_to_chars (p
+ size
, (valueT
) i
.op
[0].imms
->X_add_number
, 2);
5763 fragS
*insn_start_frag
;
5764 offsetT insn_start_off
;
5766 /* Tie dwarf2 debug info to the address at the start of the insn.
5767 We can't do this after the insn has been output as the current
5768 frag may have been closed off. eg. by frag_var. */
5769 dwarf2_emit_insn (0);
5771 insn_start_frag
= frag_now
;
5772 insn_start_off
= frag_now_fix ();
5775 if (i
.tm
.opcode_modifier
.jump
)
5777 else if (i
.tm
.opcode_modifier
.jumpbyte
5778 || i
.tm
.opcode_modifier
.jumpdword
)
5780 else if (i
.tm
.opcode_modifier
.jumpintersegment
)
5781 output_interseg_jump ();
5784 /* Output normal instructions here. */
5788 unsigned int prefix
;
5790 /* Since the VEX prefix contains the implicit prefix, we don't
5791 need the explicit prefix. */
5792 if (!i
.tm
.opcode_modifier
.vex
)
5794 switch (i
.tm
.opcode_length
)
5797 if (i
.tm
.base_opcode
& 0xff000000)
5799 prefix
= (i
.tm
.base_opcode
>> 24) & 0xff;
5804 if ((i
.tm
.base_opcode
& 0xff0000) != 0)
5806 prefix
= (i
.tm
.base_opcode
>> 16) & 0xff;
5807 if (i
.tm
.cpu_flags
.bitfield
.cpupadlock
)
5810 if (prefix
!= REPE_PREFIX_OPCODE
5811 || (i
.prefix
[LOCKREP_PREFIX
]
5812 != REPE_PREFIX_OPCODE
))
5813 add_prefix (prefix
);
5816 add_prefix (prefix
);
5825 /* The prefix bytes. */
5826 for (j
= ARRAY_SIZE (i
.prefix
), q
= i
.prefix
; j
> 0; j
--, q
++)
5828 FRAG_APPEND_1_CHAR (*q
);
5831 if (i
.tm
.opcode_modifier
.vex
)
5833 for (j
= 0, q
= i
.prefix
; j
< ARRAY_SIZE (i
.prefix
); j
++, q
++)
5838 /* REX byte is encoded in VEX prefix. */
5842 FRAG_APPEND_1_CHAR (*q
);
5845 /* There should be no other prefixes for instructions
5850 /* Now the VEX prefix. */
5851 p
= frag_more (i
.vex
.length
);
5852 for (j
= 0; j
< i
.vex
.length
; j
++)
5853 p
[j
] = i
.vex
.bytes
[j
];
5856 /* Now the opcode; be careful about word order here! */
5857 if (i
.tm
.opcode_length
== 1)
5859 FRAG_APPEND_1_CHAR (i
.tm
.base_opcode
);
5863 switch (i
.tm
.opcode_length
)
5867 *p
++ = (i
.tm
.base_opcode
>> 16) & 0xff;
5877 /* Put out high byte first: can't use md_number_to_chars! */
5878 *p
++ = (i
.tm
.base_opcode
>> 8) & 0xff;
5879 *p
= i
.tm
.base_opcode
& 0xff;
5881 /* On SSE5, encode the OC1 bit in the DREX field if this
5882 encoding has multiple formats. */
5883 if (i
.tm
.opcode_modifier
.drex
5884 && i
.tm
.opcode_modifier
.drexv
5885 && DREX_OC1 (i
.tm
.extension_opcode
))
5886 *p
|= DREX_OC1_MASK
;
5889 /* Now the modrm byte and sib byte (if present). */
5890 if (i
.tm
.opcode_modifier
.modrm
)
5892 FRAG_APPEND_1_CHAR ((i
.rm
.regmem
<< 0
5895 /* If i.rm.regmem == ESP (4)
5896 && i.rm.mode != (Register mode)
5898 ==> need second modrm byte. */
5899 if (i
.rm
.regmem
== ESCAPE_TO_TWO_BYTE_ADDRESSING
5901 && !(i
.base_reg
&& i
.base_reg
->reg_type
.bitfield
.reg16
))
5902 FRAG_APPEND_1_CHAR ((i
.sib
.base
<< 0
5904 | i
.sib
.scale
<< 6));
5907 /* Write the DREX byte if needed. */
5908 if (i
.tm
.opcode_modifier
.drex
|| i
.tm
.opcode_modifier
.drexc
)
5911 *p
= (((i
.drex
.reg
& 0xf) << 4) | (i
.drex
.rex
& 0x7));
5913 /* Encode the OC0 bit if this encoding has multiple
5915 if ((i
.tm
.opcode_modifier
.drex
5916 || i
.tm
.opcode_modifier
.drexv
)
5917 && DREX_OC0 (i
.tm
.extension_opcode
))
5918 *p
|= DREX_OC0_MASK
;
5921 if (i
.disp_operands
)
5922 output_disp (insn_start_frag
, insn_start_off
);
5925 output_imm (insn_start_frag
, insn_start_off
);
5931 pi ("" /*line*/, &i
);
5933 #endif /* DEBUG386 */
5936 /* Return the size of the displacement operand N. */
5939 disp_size (unsigned int n
)
5942 if (i
.types
[n
].bitfield
.disp64
)
5944 else if (i
.types
[n
].bitfield
.disp8
)
5946 else if (i
.types
[n
].bitfield
.disp16
)
5951 /* Return the size of the immediate operand N. */
5954 imm_size (unsigned int n
)
5957 if (i
.types
[n
].bitfield
.imm64
)
5959 else if (i
.types
[n
].bitfield
.imm8
|| i
.types
[n
].bitfield
.imm8s
)
5961 else if (i
.types
[n
].bitfield
.imm16
)
5967 output_disp (fragS
*insn_start_frag
, offsetT insn_start_off
)
5972 for (n
= 0; n
< i
.operands
; n
++)
5974 if (operand_type_check (i
.types
[n
], disp
))
5976 if (i
.op
[n
].disps
->X_op
== O_constant
)
5978 int size
= disp_size (n
);
5981 val
= offset_in_range (i
.op
[n
].disps
->X_add_number
,
5983 p
= frag_more (size
);
5984 md_number_to_chars (p
, val
, size
);
5988 enum bfd_reloc_code_real reloc_type
;
5989 int size
= disp_size (n
);
5990 int sign
= i
.types
[n
].bitfield
.disp32s
;
5991 int pcrel
= (i
.flags
[n
] & Operand_PCrel
) != 0;
5993 /* We can't have 8 bit displacement here. */
5994 assert (!i
.types
[n
].bitfield
.disp8
);
5996 /* The PC relative address is computed relative
5997 to the instruction boundary, so in case immediate
5998 fields follows, we need to adjust the value. */
5999 if (pcrel
&& i
.imm_operands
)
6004 for (n1
= 0; n1
< i
.operands
; n1
++)
6005 if (operand_type_check (i
.types
[n1
], imm
))
6007 /* Only one immediate is allowed for PC
6008 relative address. */
6011 i
.op
[n
].disps
->X_add_number
-= sz
;
6013 /* We should find the immediate. */
6017 p
= frag_more (size
);
6018 reloc_type
= reloc (size
, pcrel
, sign
, i
.reloc
[n
]);
6020 && GOT_symbol
== i
.op
[n
].disps
->X_add_symbol
6021 && (((reloc_type
== BFD_RELOC_32
6022 || reloc_type
== BFD_RELOC_X86_64_32S
6023 || (reloc_type
== BFD_RELOC_64
6025 && (i
.op
[n
].disps
->X_op
== O_symbol
6026 || (i
.op
[n
].disps
->X_op
== O_add
6027 && ((symbol_get_value_expression
6028 (i
.op
[n
].disps
->X_op_symbol
)->X_op
)
6030 || reloc_type
== BFD_RELOC_32_PCREL
))
6034 if (insn_start_frag
== frag_now
)
6035 add
= (p
- frag_now
->fr_literal
) - insn_start_off
;
6040 add
= insn_start_frag
->fr_fix
- insn_start_off
;
6041 for (fr
= insn_start_frag
->fr_next
;
6042 fr
&& fr
!= frag_now
; fr
= fr
->fr_next
)
6044 add
+= p
- frag_now
->fr_literal
;
6049 reloc_type
= BFD_RELOC_386_GOTPC
;
6050 i
.op
[n
].imms
->X_add_number
+= add
;
6052 else if (reloc_type
== BFD_RELOC_64
)
6053 reloc_type
= BFD_RELOC_X86_64_GOTPC64
;
6055 /* Don't do the adjustment for x86-64, as there
6056 the pcrel addressing is relative to the _next_
6057 insn, and that is taken care of in other code. */
6058 reloc_type
= BFD_RELOC_X86_64_GOTPC32
;
6060 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, size
,
6061 i
.op
[n
].disps
, pcrel
, reloc_type
);
6068 output_imm (fragS
*insn_start_frag
, offsetT insn_start_off
)
6073 for (n
= 0; n
< i
.operands
; n
++)
6075 if (operand_type_check (i
.types
[n
], imm
))
6077 if (i
.op
[n
].imms
->X_op
== O_constant
)
6079 int size
= imm_size (n
);
6082 val
= offset_in_range (i
.op
[n
].imms
->X_add_number
,
6084 p
= frag_more (size
);
6085 md_number_to_chars (p
, val
, size
);
6089 /* Not absolute_section.
6090 Need a 32-bit fixup (don't support 8bit
6091 non-absolute imms). Try to support other
6093 enum bfd_reloc_code_real reloc_type
;
6094 int size
= imm_size (n
);
6097 if (i
.types
[n
].bitfield
.imm32s
6098 && (i
.suffix
== QWORD_MNEM_SUFFIX
6099 || (!i
.suffix
&& i
.tm
.opcode_modifier
.no_lsuf
)))
6104 p
= frag_more (size
);
6105 reloc_type
= reloc (size
, 0, sign
, i
.reloc
[n
]);
6107 /* This is tough to explain. We end up with this one if we
6108 * have operands that look like
6109 * "_GLOBAL_OFFSET_TABLE_+[.-.L284]". The goal here is to
6110 * obtain the absolute address of the GOT, and it is strongly
6111 * preferable from a performance point of view to avoid using
6112 * a runtime relocation for this. The actual sequence of
6113 * instructions often look something like:
6118 * addl $_GLOBAL_OFFSET_TABLE_+[.-.L66],%ebx
6120 * The call and pop essentially return the absolute address
6121 * of the label .L66 and store it in %ebx. The linker itself
6122 * will ultimately change the first operand of the addl so
6123 * that %ebx points to the GOT, but to keep things simple, the
6124 * .o file must have this operand set so that it generates not
6125 * the absolute address of .L66, but the absolute address of
6126 * itself. This allows the linker itself simply treat a GOTPC
6127 * relocation as asking for a pcrel offset to the GOT to be
6128 * added in, and the addend of the relocation is stored in the
6129 * operand field for the instruction itself.
6131 * Our job here is to fix the operand so that it would add
6132 * the correct offset so that %ebx would point to itself. The
6133 * thing that is tricky is that .-.L66 will point to the
6134 * beginning of the instruction, so we need to further modify
6135 * the operand so that it will point to itself. There are
6136 * other cases where you have something like:
6138 * .long $_GLOBAL_OFFSET_TABLE_+[.-.L66]
6140 * and here no correction would be required. Internally in
6141 * the assembler we treat operands of this form as not being
6142 * pcrel since the '.' is explicitly mentioned, and I wonder
6143 * whether it would simplify matters to do it this way. Who
6144 * knows. In earlier versions of the PIC patches, the
6145 * pcrel_adjust field was used to store the correction, but
6146 * since the expression is not pcrel, I felt it would be
6147 * confusing to do it this way. */
6149 if ((reloc_type
== BFD_RELOC_32
6150 || reloc_type
== BFD_RELOC_X86_64_32S
6151 || reloc_type
== BFD_RELOC_64
)
6153 && GOT_symbol
== i
.op
[n
].imms
->X_add_symbol
6154 && (i
.op
[n
].imms
->X_op
== O_symbol
6155 || (i
.op
[n
].imms
->X_op
== O_add
6156 && ((symbol_get_value_expression
6157 (i
.op
[n
].imms
->X_op_symbol
)->X_op
)
6162 if (insn_start_frag
== frag_now
)
6163 add
= (p
- frag_now
->fr_literal
) - insn_start_off
;
6168 add
= insn_start_frag
->fr_fix
- insn_start_off
;
6169 for (fr
= insn_start_frag
->fr_next
;
6170 fr
&& fr
!= frag_now
; fr
= fr
->fr_next
)
6172 add
+= p
- frag_now
->fr_literal
;
6176 reloc_type
= BFD_RELOC_386_GOTPC
;
6178 reloc_type
= BFD_RELOC_X86_64_GOTPC32
;
6180 reloc_type
= BFD_RELOC_X86_64_GOTPC64
;
6181 i
.op
[n
].imms
->X_add_number
+= add
;
6183 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, size
,
6184 i
.op
[n
].imms
, 0, reloc_type
);
6190 /* x86_cons_fix_new is called via the expression parsing code when a
6191 reloc is needed. We use this hook to get the correct .got reloc. */
6192 static enum bfd_reloc_code_real got_reloc
= NO_RELOC
;
6193 static int cons_sign
= -1;
6196 x86_cons_fix_new (fragS
*frag
, unsigned int off
, unsigned int len
,
6199 enum bfd_reloc_code_real r
= reloc (len
, 0, cons_sign
, got_reloc
);
6201 got_reloc
= NO_RELOC
;
6204 if (exp
->X_op
== O_secrel
)
6206 exp
->X_op
= O_symbol
;
6207 r
= BFD_RELOC_32_SECREL
;
6211 fix_new_exp (frag
, off
, len
, exp
, 0, r
);
6214 #if (!defined (OBJ_ELF) && !defined (OBJ_MAYBE_ELF)) || defined (LEX_AT)
6215 # define lex_got(reloc, adjust, types) NULL
6217 /* Parse operands of the form
6218 <symbol>@GOTOFF+<nnn>
6219 and similar .plt or .got references.
6221 If we find one, set up the correct relocation in RELOC and copy the
6222 input string, minus the `@GOTOFF' into a malloc'd buffer for
6223 parsing by the calling routine. Return this buffer, and if ADJUST
6224 is non-null set it to the length of the string we removed from the
6225 input line. Otherwise return NULL. */
6227 lex_got (enum bfd_reloc_code_real
*reloc
,
6229 i386_operand_type
*types
)
6231 /* Some of the relocations depend on the size of what field is to
6232 be relocated. But in our callers i386_immediate and i386_displacement
6233 we don't yet know the operand size (this will be set by insn
6234 matching). Hence we record the word32 relocation here,
6235 and adjust the reloc according to the real size in reloc(). */
6236 static const struct {
6238 const enum bfd_reloc_code_real rel
[2];
6239 const i386_operand_type types64
;
6242 BFD_RELOC_X86_64_PLTOFF64
},
6243 OPERAND_TYPE_IMM64
},
6244 { "PLT", { BFD_RELOC_386_PLT32
,
6245 BFD_RELOC_X86_64_PLT32
},
6246 OPERAND_TYPE_IMM32_32S_DISP32
},
6248 BFD_RELOC_X86_64_GOTPLT64
},
6249 OPERAND_TYPE_IMM64_DISP64
},
6250 { "GOTOFF", { BFD_RELOC_386_GOTOFF
,
6251 BFD_RELOC_X86_64_GOTOFF64
},
6252 OPERAND_TYPE_IMM64_DISP64
},
6254 BFD_RELOC_X86_64_GOTPCREL
},
6255 OPERAND_TYPE_IMM32_32S_DISP32
},
6256 { "TLSGD", { BFD_RELOC_386_TLS_GD
,
6257 BFD_RELOC_X86_64_TLSGD
},
6258 OPERAND_TYPE_IMM32_32S_DISP32
},
6259 { "TLSLDM", { BFD_RELOC_386_TLS_LDM
,
6261 OPERAND_TYPE_NONE
},
6263 BFD_RELOC_X86_64_TLSLD
},
6264 OPERAND_TYPE_IMM32_32S_DISP32
},
6265 { "GOTTPOFF", { BFD_RELOC_386_TLS_IE_32
,
6266 BFD_RELOC_X86_64_GOTTPOFF
},
6267 OPERAND_TYPE_IMM32_32S_DISP32
},
6268 { "TPOFF", { BFD_RELOC_386_TLS_LE_32
,
6269 BFD_RELOC_X86_64_TPOFF32
},
6270 OPERAND_TYPE_IMM32_32S_64_DISP32_64
},
6271 { "NTPOFF", { BFD_RELOC_386_TLS_LE
,
6273 OPERAND_TYPE_NONE
},
6274 { "DTPOFF", { BFD_RELOC_386_TLS_LDO_32
,
6275 BFD_RELOC_X86_64_DTPOFF32
},
6277 OPERAND_TYPE_IMM32_32S_64_DISP32_64
},
6278 { "GOTNTPOFF",{ BFD_RELOC_386_TLS_GOTIE
,
6280 OPERAND_TYPE_NONE
},
6281 { "INDNTPOFF",{ BFD_RELOC_386_TLS_IE
,
6283 OPERAND_TYPE_NONE
},
6284 { "GOT", { BFD_RELOC_386_GOT32
,
6285 BFD_RELOC_X86_64_GOT32
},
6286 OPERAND_TYPE_IMM32_32S_64_DISP32
},
6287 { "TLSDESC", { BFD_RELOC_386_TLS_GOTDESC
,
6288 BFD_RELOC_X86_64_GOTPC32_TLSDESC
},
6289 OPERAND_TYPE_IMM32_32S_DISP32
},
6290 { "TLSCALL", { BFD_RELOC_386_TLS_DESC_CALL
,
6291 BFD_RELOC_X86_64_TLSDESC_CALL
},
6292 OPERAND_TYPE_IMM32_32S_DISP32
},
6300 for (cp
= input_line_pointer
; *cp
!= '@'; cp
++)
6301 if (is_end_of_line
[(unsigned char) *cp
] || *cp
== ',')
6304 for (j
= 0; j
< ARRAY_SIZE (gotrel
); j
++)
6308 len
= strlen (gotrel
[j
].str
);
6309 if (strncasecmp (cp
+ 1, gotrel
[j
].str
, len
) == 0)
6311 if (gotrel
[j
].rel
[object_64bit
] != 0)
6314 char *tmpbuf
, *past_reloc
;
6316 *reloc
= gotrel
[j
].rel
[object_64bit
];
6322 if (flag_code
!= CODE_64BIT
)
6324 types
->bitfield
.imm32
= 1;
6325 types
->bitfield
.disp32
= 1;
6328 *types
= gotrel
[j
].types64
;
6331 if (GOT_symbol
== NULL
)
6332 GOT_symbol
= symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME
);
6334 /* The length of the first part of our input line. */
6335 first
= cp
- input_line_pointer
;
6337 /* The second part goes from after the reloc token until
6338 (and including) an end_of_line char or comma. */
6339 past_reloc
= cp
+ 1 + len
;
6341 while (!is_end_of_line
[(unsigned char) *cp
] && *cp
!= ',')
6343 second
= cp
+ 1 - past_reloc
;
6345 /* Allocate and copy string. The trailing NUL shouldn't
6346 be necessary, but be safe. */
6347 tmpbuf
= xmalloc (first
+ second
+ 2);
6348 memcpy (tmpbuf
, input_line_pointer
, first
);
6349 if (second
!= 0 && *past_reloc
!= ' ')
6350 /* Replace the relocation token with ' ', so that
6351 errors like foo@GOTOFF1 will be detected. */
6352 tmpbuf
[first
++] = ' ';
6353 memcpy (tmpbuf
+ first
, past_reloc
, second
);
6354 tmpbuf
[first
+ second
] = '\0';
6358 as_bad (_("@%s reloc is not supported with %d-bit output format"),
6359 gotrel
[j
].str
, 1 << (5 + object_64bit
));
6364 /* Might be a symbol version string. Don't as_bad here. */
6369 x86_cons (expressionS
*exp
, int size
)
6371 if (size
== 4 || (object_64bit
&& size
== 8))
6373 /* Handle @GOTOFF and the like in an expression. */
6375 char *gotfree_input_line
;
6378 save
= input_line_pointer
;
6379 gotfree_input_line
= lex_got (&got_reloc
, &adjust
, NULL
);
6380 if (gotfree_input_line
)
6381 input_line_pointer
= gotfree_input_line
;
6385 if (gotfree_input_line
)
6387 /* expression () has merrily parsed up to the end of line,
6388 or a comma - in the wrong buffer. Transfer how far
6389 input_line_pointer has moved to the right buffer. */
6390 input_line_pointer
= (save
6391 + (input_line_pointer
- gotfree_input_line
)
6393 free (gotfree_input_line
);
6394 if (exp
->X_op
== O_constant
6395 || exp
->X_op
== O_absent
6396 || exp
->X_op
== O_illegal
6397 || exp
->X_op
== O_register
6398 || exp
->X_op
== O_big
)
6400 char c
= *input_line_pointer
;
6401 *input_line_pointer
= 0;
6402 as_bad (_("missing or invalid expression `%s'"), save
);
6403 *input_line_pointer
= c
;
6412 static void signed_cons (int size
)
6414 if (flag_code
== CODE_64BIT
)
6422 pe_directive_secrel (dummy
)
6423 int dummy ATTRIBUTE_UNUSED
;
6430 if (exp
.X_op
== O_symbol
)
6431 exp
.X_op
= O_secrel
;
6433 emit_expr (&exp
, 4);
6435 while (*input_line_pointer
++ == ',');
6437 input_line_pointer
--;
6438 demand_empty_rest_of_line ();
6443 i386_immediate (char *imm_start
)
6445 char *save_input_line_pointer
;
6446 char *gotfree_input_line
;
6449 i386_operand_type types
;
6451 operand_type_set (&types
, ~0);
6453 if (i
.imm_operands
== MAX_IMMEDIATE_OPERANDS
)
6455 as_bad (_("at most %d immediate operands are allowed"),
6456 MAX_IMMEDIATE_OPERANDS
);
6460 exp
= &im_expressions
[i
.imm_operands
++];
6461 i
.op
[this_operand
].imms
= exp
;
6463 if (is_space_char (*imm_start
))
6466 save_input_line_pointer
= input_line_pointer
;
6467 input_line_pointer
= imm_start
;
6469 gotfree_input_line
= lex_got (&i
.reloc
[this_operand
], NULL
, &types
);
6470 if (gotfree_input_line
)
6471 input_line_pointer
= gotfree_input_line
;
6473 exp_seg
= expression (exp
);
6476 if (*input_line_pointer
)
6477 as_bad (_("junk `%s' after expression"), input_line_pointer
);
6479 input_line_pointer
= save_input_line_pointer
;
6480 if (gotfree_input_line
)
6481 free (gotfree_input_line
);
6483 if (exp
->X_op
== O_absent
6484 || exp
->X_op
== O_illegal
6485 || exp
->X_op
== O_big
6486 || (gotfree_input_line
6487 && (exp
->X_op
== O_constant
6488 || exp
->X_op
== O_register
)))
6490 as_bad (_("missing or invalid immediate expression `%s'"),
6494 else if (exp
->X_op
== O_constant
)
6496 /* Size it properly later. */
6497 i
.types
[this_operand
].bitfield
.imm64
= 1;
6498 /* If BFD64, sign extend val. */
6499 if (!use_rela_relocations
6500 && (exp
->X_add_number
& ~(((addressT
) 2 << 31) - 1)) == 0)
6502 = (exp
->X_add_number
^ ((addressT
) 1 << 31)) - ((addressT
) 1 << 31);
6504 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
6505 else if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
6506 && exp_seg
!= absolute_section
6507 && exp_seg
!= text_section
6508 && exp_seg
!= data_section
6509 && exp_seg
!= bss_section
6510 && exp_seg
!= undefined_section
6511 && !bfd_is_com_section (exp_seg
))
6513 as_bad (_("unimplemented segment %s in operand"), exp_seg
->name
);
6517 else if (!intel_syntax
&& exp
->X_op
== O_register
)
6519 as_bad (_("illegal immediate register operand %s"), imm_start
);
6524 /* This is an address. The size of the address will be
6525 determined later, depending on destination register,
6526 suffix, or the default for the section. */
6527 i
.types
[this_operand
].bitfield
.imm8
= 1;
6528 i
.types
[this_operand
].bitfield
.imm16
= 1;
6529 i
.types
[this_operand
].bitfield
.imm32
= 1;
6530 i
.types
[this_operand
].bitfield
.imm32s
= 1;
6531 i
.types
[this_operand
].bitfield
.imm64
= 1;
6532 i
.types
[this_operand
] = operand_type_and (i
.types
[this_operand
],
6540 i386_scale (char *scale
)
6543 char *save
= input_line_pointer
;
6545 input_line_pointer
= scale
;
6546 val
= get_absolute_expression ();
6551 i
.log2_scale_factor
= 0;
6554 i
.log2_scale_factor
= 1;
6557 i
.log2_scale_factor
= 2;
6560 i
.log2_scale_factor
= 3;
6564 char sep
= *input_line_pointer
;
6566 *input_line_pointer
= '\0';
6567 as_bad (_("expecting scale factor of 1, 2, 4, or 8: got `%s'"),
6569 *input_line_pointer
= sep
;
6570 input_line_pointer
= save
;
6574 if (i
.log2_scale_factor
!= 0 && i
.index_reg
== 0)
6576 as_warn (_("scale factor of %d without an index register"),
6577 1 << i
.log2_scale_factor
);
6578 i
.log2_scale_factor
= 0;
6580 scale
= input_line_pointer
;
6581 input_line_pointer
= save
;
6586 i386_displacement (char *disp_start
, char *disp_end
)
6590 char *save_input_line_pointer
;
6591 char *gotfree_input_line
;
6593 i386_operand_type bigdisp
, types
= anydisp
;
6596 if (i
.disp_operands
== MAX_MEMORY_OPERANDS
)
6598 as_bad (_("at most %d displacement operands are allowed"),
6599 MAX_MEMORY_OPERANDS
);
6603 operand_type_set (&bigdisp
, 0);
6604 if ((i
.types
[this_operand
].bitfield
.jumpabsolute
)
6605 || (!current_templates
->start
->opcode_modifier
.jump
6606 && !current_templates
->start
->opcode_modifier
.jumpdword
))
6608 bigdisp
.bitfield
.disp32
= 1;
6609 override
= (i
.prefix
[ADDR_PREFIX
] != 0);
6610 if (flag_code
== CODE_64BIT
)
6614 bigdisp
.bitfield
.disp32s
= 1;
6615 bigdisp
.bitfield
.disp64
= 1;
6618 else if ((flag_code
== CODE_16BIT
) ^ override
)
6620 bigdisp
.bitfield
.disp32
= 0;
6621 bigdisp
.bitfield
.disp16
= 1;
6626 /* For PC-relative branches, the width of the displacement
6627 is dependent upon data size, not address size. */
6628 override
= (i
.prefix
[DATA_PREFIX
] != 0);
6629 if (flag_code
== CODE_64BIT
)
6631 if (override
|| i
.suffix
== WORD_MNEM_SUFFIX
)
6632 bigdisp
.bitfield
.disp16
= 1;
6635 bigdisp
.bitfield
.disp32
= 1;
6636 bigdisp
.bitfield
.disp32s
= 1;
6642 override
= (i
.suffix
== (flag_code
!= CODE_16BIT
6644 : LONG_MNEM_SUFFIX
));
6645 bigdisp
.bitfield
.disp32
= 1;
6646 if ((flag_code
== CODE_16BIT
) ^ override
)
6648 bigdisp
.bitfield
.disp32
= 0;
6649 bigdisp
.bitfield
.disp16
= 1;
6653 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
6656 exp
= &disp_expressions
[i
.disp_operands
];
6657 i
.op
[this_operand
].disps
= exp
;
6659 save_input_line_pointer
= input_line_pointer
;
6660 input_line_pointer
= disp_start
;
6661 END_STRING_AND_SAVE (disp_end
);
6663 #ifndef GCC_ASM_O_HACK
6664 #define GCC_ASM_O_HACK 0
6667 END_STRING_AND_SAVE (disp_end
+ 1);
6668 if (i
.types
[this_operand
].bitfield
.baseIndex
6669 && displacement_string_end
[-1] == '+')
6671 /* This hack is to avoid a warning when using the "o"
6672 constraint within gcc asm statements.
6675 #define _set_tssldt_desc(n,addr,limit,type) \
6676 __asm__ __volatile__ ( \
6678 "movw %w1,2+%0\n\t" \
6680 "movb %b1,4+%0\n\t" \
6681 "movb %4,5+%0\n\t" \
6682 "movb $0,6+%0\n\t" \
6683 "movb %h1,7+%0\n\t" \
6685 : "=o"(*(n)) : "q" (addr), "ri"(limit), "i"(type))
6687 This works great except that the output assembler ends
6688 up looking a bit weird if it turns out that there is
6689 no offset. You end up producing code that looks like:
6702 So here we provide the missing zero. */
6704 *displacement_string_end
= '0';
6707 gotfree_input_line
= lex_got (&i
.reloc
[this_operand
], NULL
, &types
);
6708 if (gotfree_input_line
)
6709 input_line_pointer
= gotfree_input_line
;
6711 exp_seg
= expression (exp
);
6714 if (*input_line_pointer
)
6715 as_bad (_("junk `%s' after expression"), input_line_pointer
);
6717 RESTORE_END_STRING (disp_end
+ 1);
6719 input_line_pointer
= save_input_line_pointer
;
6720 if (gotfree_input_line
)
6721 free (gotfree_input_line
);
6724 /* We do this to make sure that the section symbol is in
6725 the symbol table. We will ultimately change the relocation
6726 to be relative to the beginning of the section. */
6727 if (i
.reloc
[this_operand
] == BFD_RELOC_386_GOTOFF
6728 || i
.reloc
[this_operand
] == BFD_RELOC_X86_64_GOTPCREL
6729 || i
.reloc
[this_operand
] == BFD_RELOC_X86_64_GOTOFF64
)
6731 if (exp
->X_op
!= O_symbol
)
6734 if (S_IS_LOCAL (exp
->X_add_symbol
)
6735 && S_GET_SEGMENT (exp
->X_add_symbol
) != undefined_section
)
6736 section_symbol (S_GET_SEGMENT (exp
->X_add_symbol
));
6737 exp
->X_op
= O_subtract
;
6738 exp
->X_op_symbol
= GOT_symbol
;
6739 if (i
.reloc
[this_operand
] == BFD_RELOC_X86_64_GOTPCREL
)
6740 i
.reloc
[this_operand
] = BFD_RELOC_32_PCREL
;
6741 else if (i
.reloc
[this_operand
] == BFD_RELOC_X86_64_GOTOFF64
)
6742 i
.reloc
[this_operand
] = BFD_RELOC_64
;
6744 i
.reloc
[this_operand
] = BFD_RELOC_32
;
6747 else if (exp
->X_op
== O_absent
6748 || exp
->X_op
== O_illegal
6749 || exp
->X_op
== O_big
6750 || (gotfree_input_line
6751 && (exp
->X_op
== O_constant
6752 || exp
->X_op
== O_register
)))
6755 as_bad (_("missing or invalid displacement expression `%s'"),
6760 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
6761 else if (exp
->X_op
!= O_constant
6762 && OUTPUT_FLAVOR
== bfd_target_aout_flavour
6763 && exp_seg
!= absolute_section
6764 && exp_seg
!= text_section
6765 && exp_seg
!= data_section
6766 && exp_seg
!= bss_section
6767 && exp_seg
!= undefined_section
6768 && !bfd_is_com_section (exp_seg
))
6770 as_bad (_("unimplemented segment %s in operand"), exp_seg
->name
);
6775 RESTORE_END_STRING (disp_end
);
6777 /* Check if this is a displacement only operand. */
6778 bigdisp
= i
.types
[this_operand
];
6779 bigdisp
.bitfield
.disp8
= 0;
6780 bigdisp
.bitfield
.disp16
= 0;
6781 bigdisp
.bitfield
.disp32
= 0;
6782 bigdisp
.bitfield
.disp32s
= 0;
6783 bigdisp
.bitfield
.disp64
= 0;
6784 if (operand_type_all_zero (&bigdisp
))
6785 i
.types
[this_operand
] = operand_type_and (i
.types
[this_operand
],
6791 /* Make sure the memory operand we've been dealt is valid.
6792 Return 1 on success, 0 on a failure. */
6795 i386_index_check (const char *operand_string
)
6798 #if INFER_ADDR_PREFIX
6804 if (flag_code
== CODE_64BIT
)
6807 && ((i
.prefix
[ADDR_PREFIX
] == 0
6808 && !i
.base_reg
->reg_type
.bitfield
.reg64
)
6809 || (i
.prefix
[ADDR_PREFIX
]
6810 && !i
.base_reg
->reg_type
.bitfield
.reg32
))
6812 || i
.base_reg
->reg_num
!=
6813 (i
.prefix
[ADDR_PREFIX
] == 0 ? RegRip
: RegEip
)))
6815 && (!i
.index_reg
->reg_type
.bitfield
.baseindex
6816 || (i
.prefix
[ADDR_PREFIX
] == 0
6817 && i
.index_reg
->reg_num
!= RegRiz
6818 && !i
.index_reg
->reg_type
.bitfield
.reg64
6820 || (i
.prefix
[ADDR_PREFIX
]
6821 && i
.index_reg
->reg_num
!= RegEiz
6822 && !i
.index_reg
->reg_type
.bitfield
.reg32
))))
6827 if ((flag_code
== CODE_16BIT
) ^ (i
.prefix
[ADDR_PREFIX
] != 0))
6831 && (!i
.base_reg
->reg_type
.bitfield
.reg16
6832 || !i
.base_reg
->reg_type
.bitfield
.baseindex
))
6834 && (!i
.index_reg
->reg_type
.bitfield
.reg16
6835 || !i
.index_reg
->reg_type
.bitfield
.baseindex
6837 && i
.base_reg
->reg_num
< 6
6838 && i
.index_reg
->reg_num
>= 6
6839 && i
.log2_scale_factor
== 0))))
6846 && !i
.base_reg
->reg_type
.bitfield
.reg32
)
6848 && ((!i
.index_reg
->reg_type
.bitfield
.reg32
6849 && i
.index_reg
->reg_num
!= RegEiz
)
6850 || !i
.index_reg
->reg_type
.bitfield
.baseindex
)))
6856 #if INFER_ADDR_PREFIX
6857 if (i
.prefix
[ADDR_PREFIX
] == 0)
6859 i
.prefix
[ADDR_PREFIX
] = ADDR_PREFIX_OPCODE
;
6861 /* Change the size of any displacement too. At most one of
6862 Disp16 or Disp32 is set.
6863 FIXME. There doesn't seem to be any real need for separate
6864 Disp16 and Disp32 flags. The same goes for Imm16 and Imm32.
6865 Removing them would probably clean up the code quite a lot. */
6866 if (flag_code
!= CODE_64BIT
6867 && (i
.types
[this_operand
].bitfield
.disp16
6868 || i
.types
[this_operand
].bitfield
.disp32
))
6869 i
.types
[this_operand
]
6870 = operand_type_xor (i
.types
[this_operand
], disp16_32
);
6875 as_bad (_("`%s' is not a valid base/index expression"),
6879 as_bad (_("`%s' is not a valid %s bit base/index expression"),
6881 flag_code_names
[flag_code
]);
6886 /* Parse OPERAND_STRING into the i386_insn structure I. Returns non-zero
6890 i386_att_operand (char *operand_string
)
6894 char *op_string
= operand_string
;
6896 if (is_space_char (*op_string
))
6899 /* We check for an absolute prefix (differentiating,
6900 for example, 'jmp pc_relative_label' from 'jmp *absolute_label'. */
6901 if (*op_string
== ABSOLUTE_PREFIX
)
6904 if (is_space_char (*op_string
))
6906 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
6909 /* Check if operand is a register. */
6910 if ((r
= parse_register (op_string
, &end_op
)) != NULL
)
6912 i386_operand_type temp
;
6914 /* Check for a segment override by searching for ':' after a
6915 segment register. */
6917 if (is_space_char (*op_string
))
6919 if (*op_string
== ':'
6920 && (r
->reg_type
.bitfield
.sreg2
6921 || r
->reg_type
.bitfield
.sreg3
))
6926 i
.seg
[i
.mem_operands
] = &es
;
6929 i
.seg
[i
.mem_operands
] = &cs
;
6932 i
.seg
[i
.mem_operands
] = &ss
;
6935 i
.seg
[i
.mem_operands
] = &ds
;
6938 i
.seg
[i
.mem_operands
] = &fs
;
6941 i
.seg
[i
.mem_operands
] = &gs
;
6945 /* Skip the ':' and whitespace. */
6947 if (is_space_char (*op_string
))
6950 if (!is_digit_char (*op_string
)
6951 && !is_identifier_char (*op_string
)
6952 && *op_string
!= '('
6953 && *op_string
!= ABSOLUTE_PREFIX
)
6955 as_bad (_("bad memory operand `%s'"), op_string
);
6958 /* Handle case of %es:*foo. */
6959 if (*op_string
== ABSOLUTE_PREFIX
)
6962 if (is_space_char (*op_string
))
6964 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
6966 goto do_memory_reference
;
6970 as_bad (_("junk `%s' after register"), op_string
);
6974 temp
.bitfield
.baseindex
= 0;
6975 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
6977 i
.types
[this_operand
].bitfield
.unspecified
= 0;
6978 i
.op
[this_operand
].regs
= r
;
6981 else if (*op_string
== REGISTER_PREFIX
)
6983 as_bad (_("bad register name `%s'"), op_string
);
6986 else if (*op_string
== IMMEDIATE_PREFIX
)
6989 if (i
.types
[this_operand
].bitfield
.jumpabsolute
)
6991 as_bad (_("immediate operand illegal with absolute jump"));
6994 if (!i386_immediate (op_string
))
6997 else if (is_digit_char (*op_string
)
6998 || is_identifier_char (*op_string
)
6999 || *op_string
== '(')
7001 /* This is a memory reference of some sort. */
7004 /* Start and end of displacement string expression (if found). */
7005 char *displacement_string_start
;
7006 char *displacement_string_end
;
7008 do_memory_reference
:
7009 if ((i
.mem_operands
== 1
7010 && !current_templates
->start
->opcode_modifier
.isstring
)
7011 || i
.mem_operands
== 2)
7013 as_bad (_("too many memory references for `%s'"),
7014 current_templates
->start
->name
);
7018 /* Check for base index form. We detect the base index form by
7019 looking for an ')' at the end of the operand, searching
7020 for the '(' matching it, and finding a REGISTER_PREFIX or ','
7022 base_string
= op_string
+ strlen (op_string
);
7025 if (is_space_char (*base_string
))
7028 /* If we only have a displacement, set-up for it to be parsed later. */
7029 displacement_string_start
= op_string
;
7030 displacement_string_end
= base_string
+ 1;
7032 if (*base_string
== ')')
7035 unsigned int parens_balanced
= 1;
7036 /* We've already checked that the number of left & right ()'s are
7037 equal, so this loop will not be infinite. */
7041 if (*base_string
== ')')
7043 if (*base_string
== '(')
7046 while (parens_balanced
);
7048 temp_string
= base_string
;
7050 /* Skip past '(' and whitespace. */
7052 if (is_space_char (*base_string
))
7055 if (*base_string
== ','
7056 || ((i
.base_reg
= parse_register (base_string
, &end_op
))
7059 displacement_string_end
= temp_string
;
7061 i
.types
[this_operand
].bitfield
.baseindex
= 1;
7065 base_string
= end_op
;
7066 if (is_space_char (*base_string
))
7070 /* There may be an index reg or scale factor here. */
7071 if (*base_string
== ',')
7074 if (is_space_char (*base_string
))
7077 if ((i
.index_reg
= parse_register (base_string
, &end_op
))
7080 base_string
= end_op
;
7081 if (is_space_char (*base_string
))
7083 if (*base_string
== ',')
7086 if (is_space_char (*base_string
))
7089 else if (*base_string
!= ')')
7091 as_bad (_("expecting `,' or `)' "
7092 "after index register in `%s'"),
7097 else if (*base_string
== REGISTER_PREFIX
)
7099 as_bad (_("bad register name `%s'"), base_string
);
7103 /* Check for scale factor. */
7104 if (*base_string
!= ')')
7106 char *end_scale
= i386_scale (base_string
);
7111 base_string
= end_scale
;
7112 if (is_space_char (*base_string
))
7114 if (*base_string
!= ')')
7116 as_bad (_("expecting `)' "
7117 "after scale factor in `%s'"),
7122 else if (!i
.index_reg
)
7124 as_bad (_("expecting index register or scale factor "
7125 "after `,'; got '%c'"),
7130 else if (*base_string
!= ')')
7132 as_bad (_("expecting `,' or `)' "
7133 "after base register in `%s'"),
7138 else if (*base_string
== REGISTER_PREFIX
)
7140 as_bad (_("bad register name `%s'"), base_string
);
7145 /* If there's an expression beginning the operand, parse it,
7146 assuming displacement_string_start and
7147 displacement_string_end are meaningful. */
7148 if (displacement_string_start
!= displacement_string_end
)
7150 if (!i386_displacement (displacement_string_start
,
7151 displacement_string_end
))
7155 /* Special case for (%dx) while doing input/output op. */
7157 && operand_type_equal (&i
.base_reg
->reg_type
,
7158 ®16_inoutportreg
)
7160 && i
.log2_scale_factor
== 0
7161 && i
.seg
[i
.mem_operands
] == 0
7162 && !operand_type_check (i
.types
[this_operand
], disp
))
7164 i
.types
[this_operand
] = inoutportreg
;
7168 if (i386_index_check (operand_string
) == 0)
7170 i
.types
[this_operand
].bitfield
.mem
= 1;
7175 /* It's not a memory operand; argh! */
7176 as_bad (_("invalid char %s beginning operand %d `%s'"),
7177 output_invalid (*op_string
),
7182 return 1; /* Normal return. */
7185 /* md_estimate_size_before_relax()
7187 Called just before relax() for rs_machine_dependent frags. The x86
7188 assembler uses these frags to handle variable size jump
7191 Any symbol that is now undefined will not become defined.
7192 Return the correct fr_subtype in the frag.
7193 Return the initial "guess for variable size of frag" to caller.
7194 The guess is actually the growth beyond the fixed part. Whatever
7195 we do to grow the fixed or variable part contributes to our
7199 md_estimate_size_before_relax (fragP
, segment
)
7203 /* We've already got fragP->fr_subtype right; all we have to do is
7204 check for un-relaxable symbols. On an ELF system, we can't relax
7205 an externally visible symbol, because it may be overridden by a
7207 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment
7208 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
7210 && (S_IS_EXTERNAL (fragP
->fr_symbol
)
7211 || S_IS_WEAK (fragP
->fr_symbol
)))
7215 /* Symbol is undefined in this segment, or we need to keep a
7216 reloc so that weak symbols can be overridden. */
7217 int size
= (fragP
->fr_subtype
& CODE16
) ? 2 : 4;
7218 enum bfd_reloc_code_real reloc_type
;
7219 unsigned char *opcode
;
7222 if (fragP
->fr_var
!= NO_RELOC
)
7223 reloc_type
= fragP
->fr_var
;
7225 reloc_type
= BFD_RELOC_16_PCREL
;
7227 reloc_type
= BFD_RELOC_32_PCREL
;
7229 old_fr_fix
= fragP
->fr_fix
;
7230 opcode
= (unsigned char *) fragP
->fr_opcode
;
7232 switch (TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
))
7235 /* Make jmp (0xeb) a (d)word displacement jump. */
7237 fragP
->fr_fix
+= size
;
7238 fix_new (fragP
, old_fr_fix
, size
,
7240 fragP
->fr_offset
, 1,
7246 && (!no_cond_jump_promotion
|| fragP
->fr_var
!= NO_RELOC
))
7248 /* Negate the condition, and branch past an
7249 unconditional jump. */
7252 /* Insert an unconditional jump. */
7254 /* We added two extra opcode bytes, and have a two byte
7256 fragP
->fr_fix
+= 2 + 2;
7257 fix_new (fragP
, old_fr_fix
+ 2, 2,
7259 fragP
->fr_offset
, 1,
7266 if (no_cond_jump_promotion
&& fragP
->fr_var
== NO_RELOC
)
7271 fixP
= fix_new (fragP
, old_fr_fix
, 1,
7273 fragP
->fr_offset
, 1,
7275 fixP
->fx_signed
= 1;
7279 /* This changes the byte-displacement jump 0x7N
7280 to the (d)word-displacement jump 0x0f,0x8N. */
7281 opcode
[1] = opcode
[0] + 0x10;
7282 opcode
[0] = TWO_BYTE_OPCODE_ESCAPE
;
7283 /* We've added an opcode byte. */
7284 fragP
->fr_fix
+= 1 + size
;
7285 fix_new (fragP
, old_fr_fix
+ 1, size
,
7287 fragP
->fr_offset
, 1,
7292 BAD_CASE (fragP
->fr_subtype
);
7296 return fragP
->fr_fix
- old_fr_fix
;
7299 /* Guess size depending on current relax state. Initially the relax
7300 state will correspond to a short jump and we return 1, because
7301 the variable part of the frag (the branch offset) is one byte
7302 long. However, we can relax a section more than once and in that
7303 case we must either set fr_subtype back to the unrelaxed state,
7304 or return the value for the appropriate branch. */
7305 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
7308 /* Called after relax() is finished.
7310 In: Address of frag.
7311 fr_type == rs_machine_dependent.
7312 fr_subtype is what the address relaxed to.
7314 Out: Any fixSs and constants are set up.
7315 Caller will turn frag into a ".space 0". */
7318 md_convert_frag (abfd
, sec
, fragP
)
7319 bfd
*abfd ATTRIBUTE_UNUSED
;
7320 segT sec ATTRIBUTE_UNUSED
;
7323 unsigned char *opcode
;
7324 unsigned char *where_to_put_displacement
= NULL
;
7325 offsetT target_address
;
7326 offsetT opcode_address
;
7327 unsigned int extension
= 0;
7328 offsetT displacement_from_opcode_start
;
7330 opcode
= (unsigned char *) fragP
->fr_opcode
;
7332 /* Address we want to reach in file space. */
7333 target_address
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
7335 /* Address opcode resides at in file space. */
7336 opcode_address
= fragP
->fr_address
+ fragP
->fr_fix
;
7338 /* Displacement from opcode start to fill into instruction. */
7339 displacement_from_opcode_start
= target_address
- opcode_address
;
7341 if ((fragP
->fr_subtype
& BIG
) == 0)
7343 /* Don't have to change opcode. */
7344 extension
= 1; /* 1 opcode + 1 displacement */
7345 where_to_put_displacement
= &opcode
[1];
7349 if (no_cond_jump_promotion
7350 && TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) != UNCOND_JUMP
)
7351 as_warn_where (fragP
->fr_file
, fragP
->fr_line
,
7352 _("long jump required"));
7354 switch (fragP
->fr_subtype
)
7356 case ENCODE_RELAX_STATE (UNCOND_JUMP
, BIG
):
7357 extension
= 4; /* 1 opcode + 4 displacement */
7359 where_to_put_displacement
= &opcode
[1];
7362 case ENCODE_RELAX_STATE (UNCOND_JUMP
, BIG16
):
7363 extension
= 2; /* 1 opcode + 2 displacement */
7365 where_to_put_displacement
= &opcode
[1];
7368 case ENCODE_RELAX_STATE (COND_JUMP
, BIG
):
7369 case ENCODE_RELAX_STATE (COND_JUMP86
, BIG
):
7370 extension
= 5; /* 2 opcode + 4 displacement */
7371 opcode
[1] = opcode
[0] + 0x10;
7372 opcode
[0] = TWO_BYTE_OPCODE_ESCAPE
;
7373 where_to_put_displacement
= &opcode
[2];
7376 case ENCODE_RELAX_STATE (COND_JUMP
, BIG16
):
7377 extension
= 3; /* 2 opcode + 2 displacement */
7378 opcode
[1] = opcode
[0] + 0x10;
7379 opcode
[0] = TWO_BYTE_OPCODE_ESCAPE
;
7380 where_to_put_displacement
= &opcode
[2];
7383 case ENCODE_RELAX_STATE (COND_JUMP86
, BIG16
):
7388 where_to_put_displacement
= &opcode
[3];
7392 BAD_CASE (fragP
->fr_subtype
);
7397 /* If size if less then four we are sure that the operand fits,
7398 but if it's 4, then it could be that the displacement is larger
7400 if (DISP_SIZE_FROM_RELAX_STATE (fragP
->fr_subtype
) == 4
7402 && ((addressT
) (displacement_from_opcode_start
- extension
7403 + ((addressT
) 1 << 31))
7404 > (((addressT
) 2 << 31) - 1)))
7406 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
7407 _("jump target out of range"));
7408 /* Make us emit 0. */
7409 displacement_from_opcode_start
= extension
;
7411 /* Now put displacement after opcode. */
7412 md_number_to_chars ((char *) where_to_put_displacement
,
7413 (valueT
) (displacement_from_opcode_start
- extension
),
7414 DISP_SIZE_FROM_RELAX_STATE (fragP
->fr_subtype
));
7415 fragP
->fr_fix
+= extension
;
7418 /* Apply a fixup (fixS) to segment data, once it has been determined
7419 by our caller that we have all the info we need to fix it up.
7421 On the 386, immediates, displacements, and data pointers are all in
7422 the same (little-endian) format, so we don't need to care about which
7426 md_apply_fix (fixP
, valP
, seg
)
7427 /* The fix we're to put in. */
7429 /* Pointer to the value of the bits. */
7431 /* Segment fix is from. */
7432 segT seg ATTRIBUTE_UNUSED
;
7434 char *p
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
7435 valueT value
= *valP
;
7437 #if !defined (TE_Mach)
7440 switch (fixP
->fx_r_type
)
7446 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
7449 case BFD_RELOC_X86_64_32S
:
7450 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
7453 fixP
->fx_r_type
= BFD_RELOC_16_PCREL
;
7456 fixP
->fx_r_type
= BFD_RELOC_8_PCREL
;
7461 if (fixP
->fx_addsy
!= NULL
7462 && (fixP
->fx_r_type
== BFD_RELOC_32_PCREL
7463 || fixP
->fx_r_type
== BFD_RELOC_64_PCREL
7464 || fixP
->fx_r_type
== BFD_RELOC_16_PCREL
7465 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
)
7466 && !use_rela_relocations
)
7468 /* This is a hack. There should be a better way to handle this.
7469 This covers for the fact that bfd_install_relocation will
7470 subtract the current location (for partial_inplace, PC relative
7471 relocations); see more below. */
7475 || OUTPUT_FLAVOR
== bfd_target_coff_flavour
7478 value
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
7480 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
7483 segT sym_seg
= S_GET_SEGMENT (fixP
->fx_addsy
);
7486 || (symbol_section_p (fixP
->fx_addsy
)
7487 && sym_seg
!= absolute_section
))
7488 && !generic_force_reloc (fixP
))
7490 /* Yes, we add the values in twice. This is because
7491 bfd_install_relocation subtracts them out again. I think
7492 bfd_install_relocation is broken, but I don't dare change
7494 value
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
7498 #if defined (OBJ_COFF) && defined (TE_PE)
7499 /* For some reason, the PE format does not store a
7500 section address offset for a PC relative symbol. */
7501 if (S_GET_SEGMENT (fixP
->fx_addsy
) != seg
7502 || S_IS_WEAK (fixP
->fx_addsy
))
7503 value
+= md_pcrel_from (fixP
);
7507 /* Fix a few things - the dynamic linker expects certain values here,
7508 and we must not disappoint it. */
7509 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
7510 if (IS_ELF
&& fixP
->fx_addsy
)
7511 switch (fixP
->fx_r_type
)
7513 case BFD_RELOC_386_PLT32
:
7514 case BFD_RELOC_X86_64_PLT32
:
7515 /* Make the jump instruction point to the address of the operand. At
7516 runtime we merely add the offset to the actual PLT entry. */
7520 case BFD_RELOC_386_TLS_GD
:
7521 case BFD_RELOC_386_TLS_LDM
:
7522 case BFD_RELOC_386_TLS_IE_32
:
7523 case BFD_RELOC_386_TLS_IE
:
7524 case BFD_RELOC_386_TLS_GOTIE
:
7525 case BFD_RELOC_386_TLS_GOTDESC
:
7526 case BFD_RELOC_X86_64_TLSGD
:
7527 case BFD_RELOC_X86_64_TLSLD
:
7528 case BFD_RELOC_X86_64_GOTTPOFF
:
7529 case BFD_RELOC_X86_64_GOTPC32_TLSDESC
:
7530 value
= 0; /* Fully resolved at runtime. No addend. */
7532 case BFD_RELOC_386_TLS_LE
:
7533 case BFD_RELOC_386_TLS_LDO_32
:
7534 case BFD_RELOC_386_TLS_LE_32
:
7535 case BFD_RELOC_X86_64_DTPOFF32
:
7536 case BFD_RELOC_X86_64_DTPOFF64
:
7537 case BFD_RELOC_X86_64_TPOFF32
:
7538 case BFD_RELOC_X86_64_TPOFF64
:
7539 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
7542 case BFD_RELOC_386_TLS_DESC_CALL
:
7543 case BFD_RELOC_X86_64_TLSDESC_CALL
:
7544 value
= 0; /* Fully resolved at runtime. No addend. */
7545 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
7549 case BFD_RELOC_386_GOT32
:
7550 case BFD_RELOC_X86_64_GOT32
:
7551 value
= 0; /* Fully resolved at runtime. No addend. */
7554 case BFD_RELOC_VTABLE_INHERIT
:
7555 case BFD_RELOC_VTABLE_ENTRY
:
7562 #endif /* defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) */
7564 #endif /* !defined (TE_Mach) */
7566 /* Are we finished with this relocation now? */
7567 if (fixP
->fx_addsy
== NULL
)
7569 else if (use_rela_relocations
)
7571 fixP
->fx_no_overflow
= 1;
7572 /* Remember value for tc_gen_reloc. */
7573 fixP
->fx_addnumber
= value
;
7577 md_number_to_chars (p
, value
, fixP
->fx_size
);
7581 md_atof (int type
, char *litP
, int *sizeP
)
7583 /* This outputs the LITTLENUMs in REVERSE order;
7584 in accord with the bigendian 386. */
7585 return ieee_md_atof (type
, litP
, sizeP
, FALSE
);
7588 static char output_invalid_buf
[sizeof (unsigned char) * 2 + 6];
7591 output_invalid (int c
)
7594 snprintf (output_invalid_buf
, sizeof (output_invalid_buf
),
7597 snprintf (output_invalid_buf
, sizeof (output_invalid_buf
),
7598 "(0x%x)", (unsigned char) c
);
7599 return output_invalid_buf
;
7602 /* REG_STRING starts *before* REGISTER_PREFIX. */
7604 static const reg_entry
*
7605 parse_real_register (char *reg_string
, char **end_op
)
7607 char *s
= reg_string
;
7609 char reg_name_given
[MAX_REG_NAME_SIZE
+ 1];
7612 /* Skip possible REGISTER_PREFIX and possible whitespace. */
7613 if (*s
== REGISTER_PREFIX
)
7616 if (is_space_char (*s
))
7620 while ((*p
++ = register_chars
[(unsigned char) *s
]) != '\0')
7622 if (p
>= reg_name_given
+ MAX_REG_NAME_SIZE
)
7623 return (const reg_entry
*) NULL
;
7627 /* For naked regs, make sure that we are not dealing with an identifier.
7628 This prevents confusing an identifier like `eax_var' with register
7630 if (allow_naked_reg
&& identifier_chars
[(unsigned char) *s
])
7631 return (const reg_entry
*) NULL
;
7635 r
= (const reg_entry
*) hash_find (reg_hash
, reg_name_given
);
7637 /* Handle floating point regs, allowing spaces in the (i) part. */
7638 if (r
== i386_regtab
/* %st is first entry of table */)
7640 if (is_space_char (*s
))
7645 if (is_space_char (*s
))
7647 if (*s
>= '0' && *s
<= '7')
7651 if (is_space_char (*s
))
7656 r
= hash_find (reg_hash
, "st(0)");
7661 /* We have "%st(" then garbage. */
7662 return (const reg_entry
*) NULL
;
7666 if (r
== NULL
|| allow_pseudo_reg
)
7669 if (operand_type_all_zero (&r
->reg_type
))
7670 return (const reg_entry
*) NULL
;
7672 if ((r
->reg_type
.bitfield
.reg32
7673 || r
->reg_type
.bitfield
.sreg3
7674 || r
->reg_type
.bitfield
.control
7675 || r
->reg_type
.bitfield
.debug
7676 || r
->reg_type
.bitfield
.test
)
7677 && !cpu_arch_flags
.bitfield
.cpui386
)
7678 return (const reg_entry
*) NULL
;
7680 if (r
->reg_type
.bitfield
.regmmx
&& !cpu_arch_flags
.bitfield
.cpummx
)
7681 return (const reg_entry
*) NULL
;
7683 if (r
->reg_type
.bitfield
.regxmm
&& !cpu_arch_flags
.bitfield
.cpusse
)
7684 return (const reg_entry
*) NULL
;
7686 /* Don't allow fake index register unless allow_index_reg isn't 0. */
7687 if (!allow_index_reg
7688 && (r
->reg_num
== RegEiz
|| r
->reg_num
== RegRiz
))
7689 return (const reg_entry
*) NULL
;
7691 if (((r
->reg_flags
& (RegRex64
| RegRex
))
7692 || r
->reg_type
.bitfield
.reg64
)
7693 && (!cpu_arch_flags
.bitfield
.cpulm
7694 || !operand_type_equal (&r
->reg_type
, &control
))
7695 && flag_code
!= CODE_64BIT
)
7696 return (const reg_entry
*) NULL
;
7698 if (r
->reg_type
.bitfield
.sreg3
&& r
->reg_num
== RegFlat
&& !intel_syntax
)
7699 return (const reg_entry
*) NULL
;
7704 /* REG_STRING starts *before* REGISTER_PREFIX. */
7706 static const reg_entry
*
7707 parse_register (char *reg_string
, char **end_op
)
7711 if (*reg_string
== REGISTER_PREFIX
|| allow_naked_reg
)
7712 r
= parse_real_register (reg_string
, end_op
);
7717 char *save
= input_line_pointer
;
7721 input_line_pointer
= reg_string
;
7722 c
= get_symbol_end ();
7723 symbolP
= symbol_find (reg_string
);
7724 if (symbolP
&& S_GET_SEGMENT (symbolP
) == reg_section
)
7726 const expressionS
*e
= symbol_get_value_expression (symbolP
);
7728 know (e
->X_op
== O_register
);
7729 know (e
->X_add_number
>= 0
7730 && (valueT
) e
->X_add_number
< i386_regtab_size
);
7731 r
= i386_regtab
+ e
->X_add_number
;
7732 *end_op
= input_line_pointer
;
7734 *input_line_pointer
= c
;
7735 input_line_pointer
= save
;
7741 i386_parse_name (char *name
, expressionS
*e
, char *nextcharP
)
7744 char *end
= input_line_pointer
;
7747 r
= parse_register (name
, &input_line_pointer
);
7748 if (r
&& end
<= input_line_pointer
)
7750 *nextcharP
= *input_line_pointer
;
7751 *input_line_pointer
= 0;
7752 e
->X_op
= O_register
;
7753 e
->X_add_number
= r
- i386_regtab
;
7756 input_line_pointer
= end
;
7762 md_operand (expressionS
*e
)
7764 if (*input_line_pointer
== REGISTER_PREFIX
)
7767 const reg_entry
*r
= parse_real_register (input_line_pointer
, &end
);
7771 e
->X_op
= O_register
;
7772 e
->X_add_number
= r
- i386_regtab
;
7773 input_line_pointer
= end
;
7779 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
7780 const char *md_shortopts
= "kVQ:sqn";
7782 const char *md_shortopts
= "qn";
7785 #define OPTION_32 (OPTION_MD_BASE + 0)
7786 #define OPTION_64 (OPTION_MD_BASE + 1)
7787 #define OPTION_DIVIDE (OPTION_MD_BASE + 2)
7788 #define OPTION_MARCH (OPTION_MD_BASE + 3)
7789 #define OPTION_MTUNE (OPTION_MD_BASE + 4)
7790 #define OPTION_MMNEMONIC (OPTION_MD_BASE + 5)
7791 #define OPTION_MSYNTAX (OPTION_MD_BASE + 6)
7792 #define OPTION_MINDEX_REG (OPTION_MD_BASE + 7)
7793 #define OPTION_MNAKED_REG (OPTION_MD_BASE + 8)
7794 #define OPTION_MOLD_GCC (OPTION_MD_BASE + 9)
7795 #define OPTION_MSSE2AVX (OPTION_MD_BASE + 10)
7797 struct option md_longopts
[] =
7799 {"32", no_argument
, NULL
, OPTION_32
},
7800 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) || defined(TE_PEP)
7801 {"64", no_argument
, NULL
, OPTION_64
},
7803 {"divide", no_argument
, NULL
, OPTION_DIVIDE
},
7804 {"march", required_argument
, NULL
, OPTION_MARCH
},
7805 {"mtune", required_argument
, NULL
, OPTION_MTUNE
},
7806 {"mmnemonic", required_argument
, NULL
, OPTION_MMNEMONIC
},
7807 {"msyntax", required_argument
, NULL
, OPTION_MSYNTAX
},
7808 {"mindex-reg", no_argument
, NULL
, OPTION_MINDEX_REG
},
7809 {"mnaked-reg", no_argument
, NULL
, OPTION_MNAKED_REG
},
7810 {"mold-gcc", no_argument
, NULL
, OPTION_MOLD_GCC
},
7811 {"msse2avx", no_argument
, NULL
, OPTION_MSSE2AVX
},
7812 {NULL
, no_argument
, NULL
, 0}
7814 size_t md_longopts_size
= sizeof (md_longopts
);
7817 md_parse_option (int c
, char *arg
)
7825 optimize_align_code
= 0;
7832 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
7833 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
7834 should be emitted or not. FIXME: Not implemented. */
7838 /* -V: SVR4 argument to print version ID. */
7840 print_version_id ();
7843 /* -k: Ignore for FreeBSD compatibility. */
7848 /* -s: On i386 Solaris, this tells the native assembler to use
7849 .stab instead of .stab.excl. We always use .stab anyhow. */
7852 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) || defined(TE_PEP)
7855 const char **list
, **l
;
7857 list
= bfd_target_list ();
7858 for (l
= list
; *l
!= NULL
; l
++)
7859 if (CONST_STRNEQ (*l
, "elf64-x86-64")
7860 || strcmp (*l
, "coff-x86-64") == 0
7861 || strcmp (*l
, "pe-x86-64") == 0
7862 || strcmp (*l
, "pei-x86-64") == 0)
7864 default_arch
= "x86_64";
7868 as_fatal (_("No compiled in support for x86_64"));
7875 default_arch
= "i386";
7879 #ifdef SVR4_COMMENT_CHARS
7884 n
= (char *) xmalloc (strlen (i386_comment_chars
) + 1);
7886 for (s
= i386_comment_chars
; *s
!= '\0'; s
++)
7890 i386_comment_chars
= n
;
7896 arch
= xstrdup (arg
);
7900 as_fatal (_("Invalid -march= option: `%s'"), arg
);
7901 next
= strchr (arch
, '+');
7904 for (i
= 0; i
< ARRAY_SIZE (cpu_arch
); i
++)
7906 if (strcmp (arch
, cpu_arch
[i
].name
) == 0)
7909 cpu_arch_name
= cpu_arch
[i
].name
;
7910 cpu_sub_arch_name
= NULL
;
7911 cpu_arch_flags
= cpu_arch
[i
].flags
;
7912 cpu_arch_isa
= cpu_arch
[i
].type
;
7913 cpu_arch_isa_flags
= cpu_arch
[i
].flags
;
7914 if (!cpu_arch_tune_set
)
7916 cpu_arch_tune
= cpu_arch_isa
;
7917 cpu_arch_tune_flags
= cpu_arch_isa_flags
;
7921 else if (*cpu_arch
[i
].name
== '.'
7922 && strcmp (arch
, cpu_arch
[i
].name
+ 1) == 0)
7924 /* ISA entension. */
7925 i386_cpu_flags flags
;
7926 flags
= cpu_flags_or (cpu_arch_flags
,
7928 if (!cpu_flags_equal (&flags
, &cpu_arch_flags
))
7930 if (cpu_sub_arch_name
)
7932 char *name
= cpu_sub_arch_name
;
7933 cpu_sub_arch_name
= concat (name
,
7935 (const char *) NULL
);
7939 cpu_sub_arch_name
= xstrdup (cpu_arch
[i
].name
);
7940 cpu_arch_flags
= flags
;
7946 if (i
>= ARRAY_SIZE (cpu_arch
))
7947 as_fatal (_("Invalid -march= option: `%s'"), arg
);
7951 while (next
!= NULL
);
7956 as_fatal (_("Invalid -mtune= option: `%s'"), arg
);
7957 for (i
= 0; i
< ARRAY_SIZE (cpu_arch
); i
++)
7959 if (strcmp (arg
, cpu_arch
[i
].name
) == 0)
7961 cpu_arch_tune_set
= 1;
7962 cpu_arch_tune
= cpu_arch
[i
].type
;
7963 cpu_arch_tune_flags
= cpu_arch
[i
].flags
;
7967 if (i
>= ARRAY_SIZE (cpu_arch
))
7968 as_fatal (_("Invalid -mtune= option: `%s'"), arg
);
7971 case OPTION_MMNEMONIC
:
7972 if (strcasecmp (arg
, "att") == 0)
7974 else if (strcasecmp (arg
, "intel") == 0)
7977 as_fatal (_("Invalid -mmnemonic= option: `%s'"), arg
);
7980 case OPTION_MSYNTAX
:
7981 if (strcasecmp (arg
, "att") == 0)
7983 else if (strcasecmp (arg
, "intel") == 0)
7986 as_fatal (_("Invalid -msyntax= option: `%s'"), arg
);
7989 case OPTION_MINDEX_REG
:
7990 allow_index_reg
= 1;
7993 case OPTION_MNAKED_REG
:
7994 allow_naked_reg
= 1;
7997 case OPTION_MOLD_GCC
:
8001 case OPTION_MSSE2AVX
:
8012 md_show_usage (stream
)
8015 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
8016 fprintf (stream
, _("\
8018 -V print assembler version number\n\
8021 fprintf (stream
, _("\
8022 -n Do not optimize code alignment\n\
8023 -q quieten some warnings\n"));
8024 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
8025 fprintf (stream
, _("\
8028 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) || defined(TE_PEP)
8029 fprintf (stream
, _("\
8030 --32/--64 generate 32bit/64bit code\n"));
8032 #ifdef SVR4_COMMENT_CHARS
8033 fprintf (stream
, _("\
8034 --divide do not treat `/' as a comment character\n"));
8036 fprintf (stream
, _("\
8037 --divide ignored\n"));
8039 fprintf (stream
, _("\
8040 -march=CPU[,+EXTENSION...]\n\
8041 generate code for CPU and EXTENSION, CPU is one of:\n\
8042 i8086, i186, i286, i386, i486, pentium, pentiumpro,\n\
8043 pentiumii, pentiumiii, pentium4, prescott, nocona,\n\
8044 core, core2, k6, k6_2, athlon, k8, amdfam10,\n\
8045 generic32, generic64\n\
8046 EXTENSION is combination of:\n\
8047 mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, sse4,\n\
8048 avx, vmx, smx, xsave, aes, clmul, fma, 3dnow,\n\
8049 3dnowa, sse4a, sse5, svme, abm, padlock\n"));
8050 fprintf (stream
, _("\
8051 -mtune=CPU optimize for CPU, CPU is one of:\n\
8052 i8086, i186, i286, i386, i486, pentium, pentiumpro,\n\
8053 pentiumii, pentiumiii, pentium4, prescott, nocona,\n\
8054 core, core2, k6, k6_2, athlon, k8, amdfam10,\n\
8055 generic32, generic64\n"));
8056 fprintf (stream
, _("\
8057 -msse2avx encode SSE instructions with VEX prefix\n"));
8058 fprintf (stream
, _("\
8059 -mmnemonic=[att|intel] use AT&T/Intel mnemonic\n"));
8060 fprintf (stream
, _("\
8061 -msyntax=[att|intel] use AT&T/Intel syntax\n"));
8062 fprintf (stream
, _("\
8063 -mindex-reg support pseudo index registers\n"));
8064 fprintf (stream
, _("\
8065 -mnaked-reg don't require `%%' prefix for registers\n"));
8066 fprintf (stream
, _("\
8067 -mold-gcc support old (<= 2.8.1) versions of gcc\n"));
8070 #if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \
8071 || defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) || defined (TE_PEP))
8073 /* Pick the target format to use. */
8076 i386_target_format (void)
8078 if (!strcmp (default_arch
, "x86_64"))
8080 set_code_flag (CODE_64BIT
);
8081 if (cpu_flags_all_zero (&cpu_arch_isa_flags
))
8083 cpu_arch_isa_flags
.bitfield
.cpui186
= 1;
8084 cpu_arch_isa_flags
.bitfield
.cpui286
= 1;
8085 cpu_arch_isa_flags
.bitfield
.cpui386
= 1;
8086 cpu_arch_isa_flags
.bitfield
.cpui486
= 1;
8087 cpu_arch_isa_flags
.bitfield
.cpui586
= 1;
8088 cpu_arch_isa_flags
.bitfield
.cpui686
= 1;
8089 cpu_arch_isa_flags
.bitfield
.cpup4
= 1;
8090 cpu_arch_isa_flags
.bitfield
.cpummx
= 1;
8091 cpu_arch_isa_flags
.bitfield
.cpusse
= 1;
8092 cpu_arch_isa_flags
.bitfield
.cpusse2
= 1;
8094 if (cpu_flags_all_zero (&cpu_arch_tune_flags
))
8096 cpu_arch_tune_flags
.bitfield
.cpui186
= 1;
8097 cpu_arch_tune_flags
.bitfield
.cpui286
= 1;
8098 cpu_arch_tune_flags
.bitfield
.cpui386
= 1;
8099 cpu_arch_tune_flags
.bitfield
.cpui486
= 1;
8100 cpu_arch_tune_flags
.bitfield
.cpui586
= 1;
8101 cpu_arch_tune_flags
.bitfield
.cpui686
= 1;
8102 cpu_arch_tune_flags
.bitfield
.cpup4
= 1;
8103 cpu_arch_tune_flags
.bitfield
.cpummx
= 1;
8104 cpu_arch_tune_flags
.bitfield
.cpusse
= 1;
8105 cpu_arch_tune_flags
.bitfield
.cpusse2
= 1;
8108 else if (!strcmp (default_arch
, "i386"))
8110 set_code_flag (CODE_32BIT
);
8111 if (cpu_flags_all_zero (&cpu_arch_isa_flags
))
8113 cpu_arch_isa_flags
.bitfield
.cpui186
= 1;
8114 cpu_arch_isa_flags
.bitfield
.cpui286
= 1;
8115 cpu_arch_isa_flags
.bitfield
.cpui386
= 1;
8117 if (cpu_flags_all_zero (&cpu_arch_tune_flags
))
8119 cpu_arch_tune_flags
.bitfield
.cpui186
= 1;
8120 cpu_arch_tune_flags
.bitfield
.cpui286
= 1;
8121 cpu_arch_tune_flags
.bitfield
.cpui386
= 1;
8125 as_fatal (_("Unknown architecture"));
8126 switch (OUTPUT_FLAVOR
)
8129 case bfd_target_coff_flavour
:
8130 return flag_code
== CODE_64BIT
? COFF_TARGET_FORMAT
: "coff-i386";
8133 #ifdef OBJ_MAYBE_AOUT
8134 case bfd_target_aout_flavour
:
8135 return AOUT_TARGET_FORMAT
;
8137 #ifdef OBJ_MAYBE_COFF
8138 case bfd_target_coff_flavour
:
8141 #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF)
8142 case bfd_target_elf_flavour
:
8144 if (flag_code
== CODE_64BIT
)
8147 use_rela_relocations
= 1;
8149 return flag_code
== CODE_64BIT
? ELF_TARGET_FORMAT64
: ELF_TARGET_FORMAT
;
8158 #endif /* OBJ_MAYBE_ more than one */
8160 #if (defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF))
8162 i386_elf_emit_arch_note (void)
8164 if (IS_ELF
&& cpu_arch_name
!= NULL
)
8167 asection
*seg
= now_seg
;
8168 subsegT subseg
= now_subseg
;
8169 Elf_Internal_Note i_note
;
8170 Elf_External_Note e_note
;
8171 asection
*note_secp
;
8174 /* Create the .note section. */
8175 note_secp
= subseg_new (".note", 0);
8176 bfd_set_section_flags (stdoutput
,
8178 SEC_HAS_CONTENTS
| SEC_READONLY
);
8180 /* Process the arch string. */
8181 len
= strlen (cpu_arch_name
);
8183 i_note
.namesz
= len
+ 1;
8185 i_note
.type
= NT_ARCH
;
8186 p
= frag_more (sizeof (e_note
.namesz
));
8187 md_number_to_chars (p
, (valueT
) i_note
.namesz
, sizeof (e_note
.namesz
));
8188 p
= frag_more (sizeof (e_note
.descsz
));
8189 md_number_to_chars (p
, (valueT
) i_note
.descsz
, sizeof (e_note
.descsz
));
8190 p
= frag_more (sizeof (e_note
.type
));
8191 md_number_to_chars (p
, (valueT
) i_note
.type
, sizeof (e_note
.type
));
8192 p
= frag_more (len
+ 1);
8193 strcpy (p
, cpu_arch_name
);
8195 frag_align (2, 0, 0);
8197 subseg_set (seg
, subseg
);
8203 md_undefined_symbol (name
)
8206 if (name
[0] == GLOBAL_OFFSET_TABLE_NAME
[0]
8207 && name
[1] == GLOBAL_OFFSET_TABLE_NAME
[1]
8208 && name
[2] == GLOBAL_OFFSET_TABLE_NAME
[2]
8209 && strcmp (name
, GLOBAL_OFFSET_TABLE_NAME
) == 0)
8213 if (symbol_find (name
))
8214 as_bad (_("GOT already in symbol table"));
8215 GOT_symbol
= symbol_new (name
, undefined_section
,
8216 (valueT
) 0, &zero_address_frag
);
8223 /* Round up a section size to the appropriate boundary. */
8226 md_section_align (segment
, size
)
8227 segT segment ATTRIBUTE_UNUSED
;
8230 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
8231 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
8233 /* For a.out, force the section size to be aligned. If we don't do
8234 this, BFD will align it for us, but it will not write out the
8235 final bytes of the section. This may be a bug in BFD, but it is
8236 easier to fix it here since that is how the other a.out targets
8240 align
= bfd_get_section_alignment (stdoutput
, segment
);
8241 size
= ((size
+ (1 << align
) - 1) & ((valueT
) -1 << align
));
8248 /* On the i386, PC-relative offsets are relative to the start of the
8249 next instruction. That is, the address of the offset, plus its
8250 size, since the offset is always the last part of the insn. */
8253 md_pcrel_from (fixS
*fixP
)
8255 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
8261 s_bss (int ignore ATTRIBUTE_UNUSED
)
8265 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
8267 obj_elf_section_change_hook ();
8269 temp
= get_absolute_expression ();
8270 subseg_set (bss_section
, (subsegT
) temp
);
8271 demand_empty_rest_of_line ();
8277 i386_validate_fix (fixS
*fixp
)
8279 if (fixp
->fx_subsy
&& fixp
->fx_subsy
== GOT_symbol
)
8281 if (fixp
->fx_r_type
== BFD_RELOC_32_PCREL
)
8285 fixp
->fx_r_type
= BFD_RELOC_X86_64_GOTPCREL
;
8290 fixp
->fx_r_type
= BFD_RELOC_386_GOTOFF
;
8292 fixp
->fx_r_type
= BFD_RELOC_X86_64_GOTOFF64
;
8299 tc_gen_reloc (section
, fixp
)
8300 asection
*section ATTRIBUTE_UNUSED
;
8304 bfd_reloc_code_real_type code
;
8306 switch (fixp
->fx_r_type
)
8308 case BFD_RELOC_X86_64_PLT32
:
8309 case BFD_RELOC_X86_64_GOT32
:
8310 case BFD_RELOC_X86_64_GOTPCREL
:
8311 case BFD_RELOC_386_PLT32
:
8312 case BFD_RELOC_386_GOT32
:
8313 case BFD_RELOC_386_GOTOFF
:
8314 case BFD_RELOC_386_GOTPC
:
8315 case BFD_RELOC_386_TLS_GD
:
8316 case BFD_RELOC_386_TLS_LDM
:
8317 case BFD_RELOC_386_TLS_LDO_32
:
8318 case BFD_RELOC_386_TLS_IE_32
:
8319 case BFD_RELOC_386_TLS_IE
:
8320 case BFD_RELOC_386_TLS_GOTIE
:
8321 case BFD_RELOC_386_TLS_LE_32
:
8322 case BFD_RELOC_386_TLS_LE
:
8323 case BFD_RELOC_386_TLS_GOTDESC
:
8324 case BFD_RELOC_386_TLS_DESC_CALL
:
8325 case BFD_RELOC_X86_64_TLSGD
:
8326 case BFD_RELOC_X86_64_TLSLD
:
8327 case BFD_RELOC_X86_64_DTPOFF32
:
8328 case BFD_RELOC_X86_64_DTPOFF64
:
8329 case BFD_RELOC_X86_64_GOTTPOFF
:
8330 case BFD_RELOC_X86_64_TPOFF32
:
8331 case BFD_RELOC_X86_64_TPOFF64
:
8332 case BFD_RELOC_X86_64_GOTOFF64
:
8333 case BFD_RELOC_X86_64_GOTPC32
:
8334 case BFD_RELOC_X86_64_GOT64
:
8335 case BFD_RELOC_X86_64_GOTPCREL64
:
8336 case BFD_RELOC_X86_64_GOTPC64
:
8337 case BFD_RELOC_X86_64_GOTPLT64
:
8338 case BFD_RELOC_X86_64_PLTOFF64
:
8339 case BFD_RELOC_X86_64_GOTPC32_TLSDESC
:
8340 case BFD_RELOC_X86_64_TLSDESC_CALL
:
8342 case BFD_RELOC_VTABLE_ENTRY
:
8343 case BFD_RELOC_VTABLE_INHERIT
:
8345 case BFD_RELOC_32_SECREL
:
8347 code
= fixp
->fx_r_type
;
8349 case BFD_RELOC_X86_64_32S
:
8350 if (!fixp
->fx_pcrel
)
8352 /* Don't turn BFD_RELOC_X86_64_32S into BFD_RELOC_32. */
8353 code
= fixp
->fx_r_type
;
8359 switch (fixp
->fx_size
)
8362 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
8363 _("can not do %d byte pc-relative relocation"),
8365 code
= BFD_RELOC_32_PCREL
;
8367 case 1: code
= BFD_RELOC_8_PCREL
; break;
8368 case 2: code
= BFD_RELOC_16_PCREL
; break;
8369 case 4: code
= BFD_RELOC_32_PCREL
; break;
8371 case 8: code
= BFD_RELOC_64_PCREL
; break;
8377 switch (fixp
->fx_size
)
8380 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
8381 _("can not do %d byte relocation"),
8383 code
= BFD_RELOC_32
;
8385 case 1: code
= BFD_RELOC_8
; break;
8386 case 2: code
= BFD_RELOC_16
; break;
8387 case 4: code
= BFD_RELOC_32
; break;
8389 case 8: code
= BFD_RELOC_64
; break;
8396 if ((code
== BFD_RELOC_32
8397 || code
== BFD_RELOC_32_PCREL
8398 || code
== BFD_RELOC_X86_64_32S
)
8400 && fixp
->fx_addsy
== GOT_symbol
)
8403 code
= BFD_RELOC_386_GOTPC
;
8405 code
= BFD_RELOC_X86_64_GOTPC32
;
8407 if ((code
== BFD_RELOC_64
|| code
== BFD_RELOC_64_PCREL
)
8409 && fixp
->fx_addsy
== GOT_symbol
)
8411 code
= BFD_RELOC_X86_64_GOTPC64
;
8414 rel
= (arelent
*) xmalloc (sizeof (arelent
));
8415 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
8416 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
8418 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
8420 if (!use_rela_relocations
)
8422 /* HACK: Since i386 ELF uses Rel instead of Rela, encode the
8423 vtable entry to be used in the relocation's section offset. */
8424 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
8425 rel
->address
= fixp
->fx_offset
;
8429 /* Use the rela in 64bit mode. */
8432 if (!fixp
->fx_pcrel
)
8433 rel
->addend
= fixp
->fx_offset
;
8437 case BFD_RELOC_X86_64_PLT32
:
8438 case BFD_RELOC_X86_64_GOT32
:
8439 case BFD_RELOC_X86_64_GOTPCREL
:
8440 case BFD_RELOC_X86_64_TLSGD
:
8441 case BFD_RELOC_X86_64_TLSLD
:
8442 case BFD_RELOC_X86_64_GOTTPOFF
:
8443 case BFD_RELOC_X86_64_GOTPC32_TLSDESC
:
8444 case BFD_RELOC_X86_64_TLSDESC_CALL
:
8445 rel
->addend
= fixp
->fx_offset
- fixp
->fx_size
;
8448 rel
->addend
= (section
->vma
8450 + fixp
->fx_addnumber
8451 + md_pcrel_from (fixp
));
8456 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
8457 if (rel
->howto
== NULL
)
8459 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
8460 _("cannot represent relocation type %s"),
8461 bfd_get_reloc_code_name (code
));
8462 /* Set howto to a garbage value so that we can keep going. */
8463 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
8464 assert (rel
->howto
!= NULL
);
8471 /* Parse operands using Intel syntax. This implements a recursive descent
8472 parser based on the BNF grammar published in Appendix B of the MASM 6.1
8475 FIXME: We do not recognize the full operand grammar defined in the MASM
8476 documentation. In particular, all the structure/union and
8477 high-level macro operands are missing.
8479 Uppercase words are terminals, lower case words are non-terminals.
8480 Objects surrounded by double brackets '[[' ']]' are optional. Vertical
8481 bars '|' denote choices. Most grammar productions are implemented in
8482 functions called 'intel_<production>'.
8484 Initial production is 'expr'.
8490 binOp & | AND | \| | OR | ^ | XOR
8492 byteRegister AL | AH | BL | BH | CL | CH | DL | DH
8494 constant digits [[ radixOverride ]]
8496 dataType BYTE | WORD | DWORD | FWORD | QWORD | TBYTE | OWORD | XMMWORD | YMMWORD
8534 => expr expr cmpOp e04
8537 gpRegister AX | EAX | BX | EBX | CX | ECX | DX | EDX
8538 | BP | EBP | SP | ESP | DI | EDI | SI | ESI
8540 hexdigit a | b | c | d | e | f
8541 | A | B | C | D | E | F
8547 mulOp * | / | % | MOD | << | SHL | >> | SHR
8551 register specialRegister
8555 segmentRegister CS | DS | ES | FS | GS | SS
8557 specialRegister CR0 | CR2 | CR3 | CR4
8558 | DR0 | DR1 | DR2 | DR3 | DR6 | DR7
8559 | TR3 | TR4 | TR5 | TR6 | TR7
8561 We simplify the grammar in obvious places (e.g., register parsing is
8562 done by calling parse_register) and eliminate immediate left recursion
8563 to implement a recursive-descent parser.
8567 expr' cmpOp e04 expr'
8619 /* Parsing structure for the intel syntax parser. Used to implement the
8620 semantic actions for the operand grammar. */
8621 struct intel_parser_s
8623 char *op_string
; /* The string being parsed. */
8624 int got_a_float
; /* Whether the operand is a float. */
8625 int op_modifier
; /* Operand modifier. */
8626 int is_mem
; /* 1 if operand is memory reference. */
8627 int in_offset
; /* >=1 if parsing operand of offset. */
8628 int in_bracket
; /* >=1 if parsing operand in brackets. */
8629 const reg_entry
*reg
; /* Last register reference found. */
8630 char *disp
; /* Displacement string being built. */
8631 char *next_operand
; /* Resume point when splitting operands. */
8634 static struct intel_parser_s intel_parser
;
8636 /* Token structure for parsing intel syntax. */
8639 int code
; /* Token code. */
8640 const reg_entry
*reg
; /* Register entry for register tokens. */
8641 char *str
; /* String representation. */
8644 static struct intel_token cur_token
, prev_token
;
8646 /* Token codes for the intel parser. Since T_SHORT is already used
8647 by COFF, undefine it first to prevent a warning. */
8665 #define T_YMMWORD 16
8667 /* Prototypes for intel parser functions. */
8668 static int intel_match_token (int);
8669 static void intel_putback_token (void);
8670 static void intel_get_token (void);
8671 static int intel_expr (void);
8672 static int intel_e04 (void);
8673 static int intel_e05 (void);
8674 static int intel_e06 (void);
8675 static int intel_e09 (void);
8676 static int intel_e10 (void);
8677 static int intel_e11 (void);
8680 i386_intel_operand (char *operand_string
, int got_a_float
)
8685 p
= intel_parser
.op_string
= xstrdup (operand_string
);
8686 intel_parser
.disp
= (char *) xmalloc (strlen (operand_string
) + 1);
8690 /* Initialize token holders. */
8691 cur_token
.code
= prev_token
.code
= T_NIL
;
8692 cur_token
.reg
= prev_token
.reg
= NULL
;
8693 cur_token
.str
= prev_token
.str
= NULL
;
8695 /* Initialize parser structure. */
8696 intel_parser
.got_a_float
= got_a_float
;
8697 intel_parser
.op_modifier
= 0;
8698 intel_parser
.is_mem
= 0;
8699 intel_parser
.in_offset
= 0;
8700 intel_parser
.in_bracket
= 0;
8701 intel_parser
.reg
= NULL
;
8702 intel_parser
.disp
[0] = '\0';
8703 intel_parser
.next_operand
= NULL
;
8705 /* Read the first token and start the parser. */
8707 ret
= intel_expr ();
8712 if (cur_token
.code
!= T_NIL
)
8714 as_bad (_("invalid operand for '%s' ('%s' unexpected)"),
8715 current_templates
->start
->name
, cur_token
.str
);
8718 /* If we found a memory reference, hand it over to i386_displacement
8719 to fill in the rest of the operand fields. */
8720 else if (intel_parser
.is_mem
)
8722 if ((i
.mem_operands
== 1
8723 && !current_templates
->start
->opcode_modifier
.isstring
)
8724 || i
.mem_operands
== 2)
8726 as_bad (_("too many memory references for '%s'"),
8727 current_templates
->start
->name
);
8732 char *s
= intel_parser
.disp
;
8733 i
.types
[this_operand
].bitfield
.mem
= 1;
8736 if (!quiet_warnings
&& intel_parser
.is_mem
< 0)
8737 /* See the comments in intel_bracket_expr. */
8738 as_warn (_("Treating `%s' as memory reference"), operand_string
);
8740 /* Add the displacement expression. */
8742 ret
= i386_displacement (s
, s
+ strlen (s
));
8745 /* Swap base and index in 16-bit memory operands like
8746 [si+bx]. Since i386_index_check is also used in AT&T
8747 mode we have to do that here. */
8750 && i
.base_reg
->reg_type
.bitfield
.reg16
8751 && i
.index_reg
->reg_type
.bitfield
.reg16
8752 && i
.base_reg
->reg_num
>= 6
8753 && i
.index_reg
->reg_num
< 6)
8755 const reg_entry
*base
= i
.index_reg
;
8757 i
.index_reg
= i
.base_reg
;
8760 ret
= i386_index_check (operand_string
);
8765 /* Constant and OFFSET expressions are handled by i386_immediate. */
8766 else if ((intel_parser
.op_modifier
& (1 << T_OFFSET
))
8767 || intel_parser
.reg
== NULL
)
8769 if (i
.mem_operands
< 2 && i
.seg
[i
.mem_operands
])
8771 if (!(intel_parser
.op_modifier
& (1 << T_OFFSET
)))
8772 as_warn (_("Segment override ignored"));
8773 i
.seg
[i
.mem_operands
] = NULL
;
8775 ret
= i386_immediate (intel_parser
.disp
);
8778 if (intel_parser
.next_operand
&& this_operand
>= MAX_OPERANDS
- 1)
8780 if (!ret
|| !intel_parser
.next_operand
)
8782 intel_parser
.op_string
= intel_parser
.next_operand
;
8783 this_operand
= i
.operands
++;
8784 i
.types
[this_operand
].bitfield
.unspecified
= 1;
8788 free (intel_parser
.disp
);
8793 #define NUM_ADDRESS_REGS (!!i.base_reg + !!i.index_reg)
8797 expr' cmpOp e04 expr'
8802 /* XXX Implement the comparison operators. */
8803 return intel_e04 ();
8820 if (nregs
>= 0 && NUM_ADDRESS_REGS
> nregs
)
8821 i
.base_reg
= i386_regtab
+ REGNAM_AL
; /* al is invalid as base */
8823 if (cur_token
.code
== '+')
8825 else if (cur_token
.code
== '-')
8826 nregs
= NUM_ADDRESS_REGS
;
8830 strcat (intel_parser
.disp
, cur_token
.str
);
8831 intel_match_token (cur_token
.code
);
8842 int nregs
= ~NUM_ADDRESS_REGS
;
8849 if (cur_token
.code
== '&'
8850 || cur_token
.code
== '|'
8851 || cur_token
.code
== '^')
8855 str
[0] = cur_token
.code
;
8857 strcat (intel_parser
.disp
, str
);
8862 intel_match_token (cur_token
.code
);
8867 if (nregs
>= 0 && NUM_ADDRESS_REGS
> nregs
)
8868 i
.base_reg
= i386_regtab
+ REGNAM_AL
+ 1; /* cl is invalid as base */
8879 int nregs
= ~NUM_ADDRESS_REGS
;
8886 if (cur_token
.code
== '*'
8887 || cur_token
.code
== '/'
8888 || cur_token
.code
== '%')
8892 str
[0] = cur_token
.code
;
8894 strcat (intel_parser
.disp
, str
);
8896 else if (cur_token
.code
== T_SHL
)
8897 strcat (intel_parser
.disp
, "<<");
8898 else if (cur_token
.code
== T_SHR
)
8899 strcat (intel_parser
.disp
, ">>");
8903 intel_match_token (cur_token
.code
);
8908 if (nregs
>= 0 && NUM_ADDRESS_REGS
> nregs
)
8909 i
.base_reg
= i386_regtab
+ REGNAM_AL
+ 2; /* dl is invalid as base */
8927 int nregs
= ~NUM_ADDRESS_REGS
;
8932 /* Don't consume constants here. */
8933 if (cur_token
.code
== '+' || cur_token
.code
== '-')
8935 /* Need to look one token ahead - if the next token
8936 is a constant, the current token is its sign. */
8939 intel_match_token (cur_token
.code
);
8940 next_code
= cur_token
.code
;
8941 intel_putback_token ();
8942 if (next_code
== T_CONST
)
8946 /* e09 OFFSET e09 */
8947 if (cur_token
.code
== T_OFFSET
)
8950 ++intel_parser
.in_offset
;
8954 else if (cur_token
.code
== T_SHORT
)
8955 intel_parser
.op_modifier
|= 1 << T_SHORT
;
8958 else if (cur_token
.code
== '+')
8959 strcat (intel_parser
.disp
, "+");
8964 else if (cur_token
.code
== '-' || cur_token
.code
== '~')
8970 str
[0] = cur_token
.code
;
8972 strcat (intel_parser
.disp
, str
);
8979 intel_match_token (cur_token
.code
);
8987 /* e09' PTR e10 e09' */
8988 if (cur_token
.code
== T_PTR
)
8992 if (prev_token
.code
== T_BYTE
)
8994 suffix
= BYTE_MNEM_SUFFIX
;
8995 i
.types
[this_operand
].bitfield
.byte
= 1;
8998 else if (prev_token
.code
== T_WORD
)
9000 if ((current_templates
->start
->name
[0] == 'l'
9001 && current_templates
->start
->name
[2] == 's'
9002 && current_templates
->start
->name
[3] == 0)
9003 || current_templates
->start
->base_opcode
== 0x62 /* bound */)
9004 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
9005 else if (intel_parser
.got_a_float
== 2) /* "fi..." */
9006 suffix
= SHORT_MNEM_SUFFIX
;
9008 suffix
= WORD_MNEM_SUFFIX
;
9009 i
.types
[this_operand
].bitfield
.word
= 1;
9012 else if (prev_token
.code
== T_DWORD
)
9014 if ((current_templates
->start
->name
[0] == 'l'
9015 && current_templates
->start
->name
[2] == 's'
9016 && current_templates
->start
->name
[3] == 0)
9017 || current_templates
->start
->base_opcode
== 0x62 /* bound */)
9018 suffix
= WORD_MNEM_SUFFIX
;
9019 else if (flag_code
== CODE_16BIT
9020 && (current_templates
->start
->opcode_modifier
.jump
9021 || current_templates
->start
->opcode_modifier
.jumpdword
))
9022 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
9023 else if (intel_parser
.got_a_float
== 1) /* "f..." */
9024 suffix
= SHORT_MNEM_SUFFIX
;
9026 suffix
= LONG_MNEM_SUFFIX
;
9027 i
.types
[this_operand
].bitfield
.dword
= 1;
9030 else if (prev_token
.code
== T_FWORD
)
9032 if (current_templates
->start
->name
[0] == 'l'
9033 && current_templates
->start
->name
[2] == 's'
9034 && current_templates
->start
->name
[3] == 0)
9035 suffix
= LONG_MNEM_SUFFIX
;
9036 else if (!intel_parser
.got_a_float
)
9038 if (flag_code
== CODE_16BIT
)
9039 add_prefix (DATA_PREFIX_OPCODE
);
9040 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
9043 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
9044 i
.types
[this_operand
].bitfield
.fword
= 1;
9047 else if (prev_token
.code
== T_QWORD
)
9049 if (current_templates
->start
->base_opcode
== 0x62 /* bound */
9050 || intel_parser
.got_a_float
== 1) /* "f..." */
9051 suffix
= LONG_MNEM_SUFFIX
;
9053 suffix
= QWORD_MNEM_SUFFIX
;
9054 i
.types
[this_operand
].bitfield
.qword
= 1;
9057 else if (prev_token
.code
== T_TBYTE
)
9059 if (intel_parser
.got_a_float
== 1)
9060 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
9062 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
9065 else if (prev_token
.code
== T_XMMWORD
)
9067 suffix
= XMMWORD_MNEM_SUFFIX
;
9068 i
.types
[this_operand
].bitfield
.xmmword
= 1;
9071 else if (prev_token
.code
== T_YMMWORD
)
9073 suffix
= YMMWORD_MNEM_SUFFIX
;
9074 i
.types
[this_operand
].bitfield
.ymmword
= 1;
9079 as_bad (_("Unknown operand modifier `%s'"), prev_token
.str
);
9083 i
.types
[this_operand
].bitfield
.unspecified
= 0;
9085 /* Operands for jump/call using 'ptr' notation denote absolute
9087 if (current_templates
->start
->opcode_modifier
.jump
9088 || current_templates
->start
->opcode_modifier
.jumpdword
)
9089 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
9091 if (current_templates
->start
->base_opcode
== 0x8d /* lea */)
9095 else if (i
.suffix
!= suffix
)
9097 as_bad (_("Conflicting operand modifiers"));
9103 /* e09' : e10 e09' */
9104 else if (cur_token
.code
== ':')
9106 if (prev_token
.code
!= T_REG
)
9108 /* While {call,jmp} SSSS:OOOO is MASM syntax only when SSSS is a
9109 segment/group identifier (which we don't have), using comma
9110 as the operand separator there is even less consistent, since
9111 there all branches only have a single operand. */
9112 if (this_operand
!= 0
9113 || intel_parser
.in_offset
9114 || intel_parser
.in_bracket
9115 || (!current_templates
->start
->opcode_modifier
.jump
9116 && !current_templates
->start
->opcode_modifier
.jumpdword
9117 && !current_templates
->start
->opcode_modifier
.jumpintersegment
9118 && !current_templates
->start
->operand_types
[0].bitfield
.jumpabsolute
))
9119 return intel_match_token (T_NIL
);
9120 /* Remember the start of the 2nd operand and terminate 1st
9122 XXX This isn't right, yet (when SSSS:OOOO is right operand of
9123 another expression), but it gets at least the simplest case
9124 (a plain number or symbol on the left side) right. */
9125 intel_parser
.next_operand
= intel_parser
.op_string
;
9126 *--intel_parser
.op_string
= '\0';
9127 return intel_match_token (':');
9135 intel_match_token (cur_token
.code
);
9141 --intel_parser
.in_offset
;
9144 if (NUM_ADDRESS_REGS
> nregs
)
9146 as_bad (_("Invalid operand to `OFFSET'"));
9149 intel_parser
.op_modifier
|= 1 << T_OFFSET
;
9152 if (nregs
>= 0 && NUM_ADDRESS_REGS
> nregs
)
9153 i
.base_reg
= i386_regtab
+ REGNAM_AL
+ 3; /* bl is invalid as base */
9158 intel_bracket_expr (void)
9160 int was_offset
= intel_parser
.op_modifier
& (1 << T_OFFSET
);
9161 const char *start
= intel_parser
.op_string
;
9164 if (i
.op
[this_operand
].regs
)
9165 return intel_match_token (T_NIL
);
9167 intel_match_token ('[');
9169 /* Mark as a memory operand only if it's not already known to be an
9170 offset expression. If it's an offset expression, we need to keep
9172 if (!intel_parser
.in_offset
)
9174 ++intel_parser
.in_bracket
;
9176 /* Operands for jump/call inside brackets denote absolute addresses. */
9177 if (current_templates
->start
->opcode_modifier
.jump
9178 || current_templates
->start
->opcode_modifier
.jumpdword
)
9179 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
9181 /* Unfortunately gas always diverged from MASM in a respect that can't
9182 be easily fixed without risking to break code sequences likely to be
9183 encountered (the testsuite even check for this): MASM doesn't consider
9184 an expression inside brackets unconditionally as a memory reference.
9185 When that is e.g. a constant, an offset expression, or the sum of the
9186 two, this is still taken as a constant load. gas, however, always
9187 treated these as memory references. As a compromise, we'll try to make
9188 offset expressions inside brackets work the MASM way (since that's
9189 less likely to be found in real world code), but make constants alone
9190 continue to work the traditional gas way. In either case, issue a
9192 intel_parser
.op_modifier
&= ~was_offset
;
9195 strcat (intel_parser
.disp
, "[");
9197 /* Add a '+' to the displacement string if necessary. */
9198 if (*intel_parser
.disp
!= '\0'
9199 && *(intel_parser
.disp
+ strlen (intel_parser
.disp
) - 1) != '+')
9200 strcat (intel_parser
.disp
, "+");
9203 && (len
= intel_parser
.op_string
- start
- 1,
9204 intel_match_token (']')))
9206 /* Preserve brackets when the operand is an offset expression. */
9207 if (intel_parser
.in_offset
)
9208 strcat (intel_parser
.disp
, "]");
9211 --intel_parser
.in_bracket
;
9212 if (i
.base_reg
|| i
.index_reg
)
9213 intel_parser
.is_mem
= 1;
9214 if (!intel_parser
.is_mem
)
9216 if (!(intel_parser
.op_modifier
& (1 << T_OFFSET
)))
9217 /* Defer the warning until all of the operand was parsed. */
9218 intel_parser
.is_mem
= -1;
9219 else if (!quiet_warnings
)
9220 as_warn (_("`[%.*s]' taken to mean just `%.*s'"),
9221 len
, start
, len
, start
);
9224 intel_parser
.op_modifier
|= was_offset
;
9241 while (cur_token
.code
== '[')
9243 if (!intel_bracket_expr ())
9269 switch (cur_token
.code
)
9273 intel_match_token ('(');
9274 strcat (intel_parser
.disp
, "(");
9276 if (intel_expr () && intel_match_token (')'))
9278 strcat (intel_parser
.disp
, ")");
9285 return intel_bracket_expr ();
9290 strcat (intel_parser
.disp
, cur_token
.str
);
9291 intel_match_token (cur_token
.code
);
9293 /* Mark as a memory operand only if it's not already known to be an
9294 offset expression. */
9295 if (!intel_parser
.in_offset
)
9296 intel_parser
.is_mem
= 1;
9303 const reg_entry
*reg
= intel_parser
.reg
= cur_token
.reg
;
9305 intel_match_token (T_REG
);
9307 /* Check for segment change. */
9308 if (cur_token
.code
== ':')
9310 if (!reg
->reg_type
.bitfield
.sreg2
9311 && !reg
->reg_type
.bitfield
.sreg3
)
9313 as_bad (_("`%s' is not a valid segment register"),
9317 else if (i
.mem_operands
>= 2)
9318 as_warn (_("Segment override ignored"));
9319 else if (i
.seg
[i
.mem_operands
])
9320 as_warn (_("Extra segment override ignored"));
9323 if (!intel_parser
.in_offset
)
9324 intel_parser
.is_mem
= 1;
9325 switch (reg
->reg_num
)
9328 i
.seg
[i
.mem_operands
] = &es
;
9331 i
.seg
[i
.mem_operands
] = &cs
;
9334 i
.seg
[i
.mem_operands
] = &ss
;
9337 i
.seg
[i
.mem_operands
] = &ds
;
9340 i
.seg
[i
.mem_operands
] = &fs
;
9343 i
.seg
[i
.mem_operands
] = &gs
;
9349 else if (reg
->reg_type
.bitfield
.sreg3
&& reg
->reg_num
== RegFlat
)
9351 as_bad (_("cannot use `FLAT' here"));
9355 /* Not a segment register. Check for register scaling. */
9356 else if (cur_token
.code
== '*')
9358 if (!intel_parser
.in_bracket
)
9360 as_bad (_("Register scaling only allowed in memory operands"));
9364 if (reg
->reg_type
.bitfield
.reg16
) /* Disallow things like [si*1]. */
9365 reg
= i386_regtab
+ REGNAM_AX
+ 4; /* sp is invalid as index */
9366 else if (i
.index_reg
)
9367 reg
= i386_regtab
+ REGNAM_EAX
+ 4; /* esp is invalid as index */
9369 /* What follows must be a valid scale. */
9370 intel_match_token ('*');
9372 i
.types
[this_operand
].bitfield
.baseindex
= 1;
9374 /* Set the scale after setting the register (otherwise,
9375 i386_scale will complain) */
9376 if (cur_token
.code
== '+' || cur_token
.code
== '-')
9378 char *str
, sign
= cur_token
.code
;
9379 intel_match_token (cur_token
.code
);
9380 if (cur_token
.code
!= T_CONST
)
9382 as_bad (_("Syntax error: Expecting a constant, got `%s'"),
9386 str
= (char *) xmalloc (strlen (cur_token
.str
) + 2);
9387 strcpy (str
+ 1, cur_token
.str
);
9389 if (!i386_scale (str
))
9393 else if (!i386_scale (cur_token
.str
))
9395 intel_match_token (cur_token
.code
);
9398 /* No scaling. If this is a memory operand, the register is either a
9399 base register (first occurrence) or an index register (second
9401 else if (intel_parser
.in_bracket
)
9406 else if (!i
.index_reg
)
9410 as_bad (_("Too many register references in memory operand"));
9414 i
.types
[this_operand
].bitfield
.baseindex
= 1;
9417 /* It's neither base nor index. */
9418 else if (!intel_parser
.in_offset
&& !intel_parser
.is_mem
)
9420 i386_operand_type temp
= reg
->reg_type
;
9421 temp
.bitfield
.baseindex
= 0;
9422 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
9424 i
.types
[this_operand
].bitfield
.unspecified
= 0;
9425 i
.op
[this_operand
].regs
= reg
;
9430 as_bad (_("Invalid use of register"));
9434 /* Since registers are not part of the displacement string (except
9435 when we're parsing offset operands), we may need to remove any
9436 preceding '+' from the displacement string. */
9437 if (*intel_parser
.disp
!= '\0'
9438 && !intel_parser
.in_offset
)
9440 char *s
= intel_parser
.disp
;
9441 s
+= strlen (s
) - 1;
9466 intel_match_token (cur_token
.code
);
9468 if (cur_token
.code
== T_PTR
)
9471 /* It must have been an identifier. */
9472 intel_putback_token ();
9473 cur_token
.code
= T_ID
;
9479 if (!intel_parser
.in_offset
&& intel_parser
.is_mem
<= 0)
9483 /* The identifier represents a memory reference only if it's not
9484 preceded by an offset modifier and if it's not an equate. */
9485 symbolP
= symbol_find(cur_token
.str
);
9486 if (!symbolP
|| S_GET_SEGMENT(symbolP
) != absolute_section
)
9487 intel_parser
.is_mem
= 1;
9495 char *save_str
, sign
= 0;
9497 /* Allow constants that start with `+' or `-'. */
9498 if (cur_token
.code
== '-' || cur_token
.code
== '+')
9500 sign
= cur_token
.code
;
9501 intel_match_token (cur_token
.code
);
9502 if (cur_token
.code
!= T_CONST
)
9504 as_bad (_("Syntax error: Expecting a constant, got `%s'"),
9510 save_str
= (char *) xmalloc (strlen (cur_token
.str
) + 2);
9511 strcpy (save_str
+ !!sign
, cur_token
.str
);
9515 /* Get the next token to check for register scaling. */
9516 intel_match_token (cur_token
.code
);
9518 /* Check if this constant is a scaling factor for an
9520 if (cur_token
.code
== '*')
9522 if (intel_match_token ('*') && cur_token
.code
== T_REG
)
9524 const reg_entry
*reg
= cur_token
.reg
;
9526 if (!intel_parser
.in_bracket
)
9528 as_bad (_("Register scaling only allowed "
9529 "in memory operands"));
9533 /* Disallow things like [1*si].
9534 sp and esp are invalid as index. */
9535 if (reg
->reg_type
.bitfield
.reg16
)
9536 reg
= i386_regtab
+ REGNAM_AX
+ 4;
9537 else if (i
.index_reg
)
9538 reg
= i386_regtab
+ REGNAM_EAX
+ 4;
9540 /* The constant is followed by `* reg', so it must be
9543 i
.types
[this_operand
].bitfield
.baseindex
= 1;
9545 /* Set the scale after setting the register (otherwise,
9546 i386_scale will complain) */
9547 if (!i386_scale (save_str
))
9549 intel_match_token (T_REG
);
9551 /* Since registers are not part of the displacement
9552 string, we may need to remove any preceding '+' from
9553 the displacement string. */
9554 if (*intel_parser
.disp
!= '\0')
9556 char *s
= intel_parser
.disp
;
9557 s
+= strlen (s
) - 1;
9567 /* The constant was not used for register scaling. Since we have
9568 already consumed the token following `*' we now need to put it
9569 back in the stream. */
9570 intel_putback_token ();
9573 /* Add the constant to the displacement string. */
9574 strcat (intel_parser
.disp
, save_str
);
9581 as_bad (_("Unrecognized token '%s'"), cur_token
.str
);
9585 /* Match the given token against cur_token. If they match, read the next
9586 token from the operand string. */
9588 intel_match_token (int code
)
9590 if (cur_token
.code
== code
)
9597 as_bad (_("Unexpected token `%s'"), cur_token
.str
);
9602 /* Read a new token from intel_parser.op_string and store it in cur_token. */
9604 intel_get_token (void)
9607 const reg_entry
*reg
;
9608 struct intel_token new_token
;
9610 new_token
.code
= T_NIL
;
9611 new_token
.reg
= NULL
;
9612 new_token
.str
= NULL
;
9614 /* Free the memory allocated to the previous token and move
9615 cur_token to prev_token. */
9617 free (prev_token
.str
);
9619 prev_token
= cur_token
;
9621 /* Skip whitespace. */
9622 while (is_space_char (*intel_parser
.op_string
))
9623 intel_parser
.op_string
++;
9625 /* Return an empty token if we find nothing else on the line. */
9626 if (*intel_parser
.op_string
== '\0')
9628 cur_token
= new_token
;
9632 /* The new token cannot be larger than the remainder of the operand
9634 new_token
.str
= (char *) xmalloc (strlen (intel_parser
.op_string
) + 1);
9635 new_token
.str
[0] = '\0';
9637 if (strchr ("0123456789", *intel_parser
.op_string
))
9639 char *p
= new_token
.str
;
9640 char *q
= intel_parser
.op_string
;
9641 new_token
.code
= T_CONST
;
9643 /* Allow any kind of identifier char to encompass floating point and
9644 hexadecimal numbers. */
9645 while (is_identifier_char (*q
))
9649 /* Recognize special symbol names [0-9][bf]. */
9650 if (strlen (intel_parser
.op_string
) == 2
9651 && (intel_parser
.op_string
[1] == 'b'
9652 || intel_parser
.op_string
[1] == 'f'))
9653 new_token
.code
= T_ID
;
9656 else if ((reg
= parse_register (intel_parser
.op_string
, &end_op
)) != NULL
)
9658 size_t len
= end_op
- intel_parser
.op_string
;
9660 new_token
.code
= T_REG
;
9661 new_token
.reg
= reg
;
9663 memcpy (new_token
.str
, intel_parser
.op_string
, len
);
9664 new_token
.str
[len
] = '\0';
9667 else if (is_identifier_char (*intel_parser
.op_string
))
9669 char *p
= new_token
.str
;
9670 char *q
= intel_parser
.op_string
;
9672 /* A '.' or '$' followed by an identifier char is an identifier.
9673 Otherwise, it's operator '.' followed by an expression. */
9674 if ((*q
== '.' || *q
== '$') && !is_identifier_char (*(q
+ 1)))
9676 new_token
.code
= '.';
9677 new_token
.str
[0] = '.';
9678 new_token
.str
[1] = '\0';
9682 while (is_identifier_char (*q
) || *q
== '@')
9686 if (strcasecmp (new_token
.str
, "NOT") == 0)
9687 new_token
.code
= '~';
9689 else if (strcasecmp (new_token
.str
, "MOD") == 0)
9690 new_token
.code
= '%';
9692 else if (strcasecmp (new_token
.str
, "AND") == 0)
9693 new_token
.code
= '&';
9695 else if (strcasecmp (new_token
.str
, "OR") == 0)
9696 new_token
.code
= '|';
9698 else if (strcasecmp (new_token
.str
, "XOR") == 0)
9699 new_token
.code
= '^';
9701 else if (strcasecmp (new_token
.str
, "SHL") == 0)
9702 new_token
.code
= T_SHL
;
9704 else if (strcasecmp (new_token
.str
, "SHR") == 0)
9705 new_token
.code
= T_SHR
;
9707 else if (strcasecmp (new_token
.str
, "BYTE") == 0)
9708 new_token
.code
= T_BYTE
;
9710 else if (strcasecmp (new_token
.str
, "WORD") == 0)
9711 new_token
.code
= T_WORD
;
9713 else if (strcasecmp (new_token
.str
, "DWORD") == 0)
9714 new_token
.code
= T_DWORD
;
9716 else if (strcasecmp (new_token
.str
, "FWORD") == 0)
9717 new_token
.code
= T_FWORD
;
9719 else if (strcasecmp (new_token
.str
, "QWORD") == 0)
9720 new_token
.code
= T_QWORD
;
9722 else if (strcasecmp (new_token
.str
, "TBYTE") == 0
9723 /* XXX remove (gcc still uses it) */
9724 || strcasecmp (new_token
.str
, "XWORD") == 0)
9725 new_token
.code
= T_TBYTE
;
9727 else if (strcasecmp (new_token
.str
, "XMMWORD") == 0
9728 || strcasecmp (new_token
.str
, "OWORD") == 0)
9729 new_token
.code
= T_XMMWORD
;
9731 else if (strcasecmp (new_token
.str
, "YMMWORD") == 0)
9732 new_token
.code
= T_YMMWORD
;
9734 else if (strcasecmp (new_token
.str
, "PTR") == 0)
9735 new_token
.code
= T_PTR
;
9737 else if (strcasecmp (new_token
.str
, "SHORT") == 0)
9738 new_token
.code
= T_SHORT
;
9740 else if (strcasecmp (new_token
.str
, "OFFSET") == 0)
9742 new_token
.code
= T_OFFSET
;
9744 /* ??? This is not mentioned in the MASM grammar but gcc
9745 makes use of it with -mintel-syntax. OFFSET may be
9746 followed by FLAT: */
9747 if (strncasecmp (q
, " FLAT:", 6) == 0)
9748 strcat (new_token
.str
, " FLAT:");
9752 new_token
.code
= T_ID
;
9756 else if (strchr ("+-/*%|&^:[]()~", *intel_parser
.op_string
))
9758 new_token
.code
= *intel_parser
.op_string
;
9759 new_token
.str
[0] = *intel_parser
.op_string
;
9760 new_token
.str
[1] = '\0';
9763 else if (strchr ("<>", *intel_parser
.op_string
)
9764 && *intel_parser
.op_string
== *(intel_parser
.op_string
+ 1))
9766 new_token
.code
= *intel_parser
.op_string
== '<' ? T_SHL
: T_SHR
;
9767 new_token
.str
[0] = *intel_parser
.op_string
;
9768 new_token
.str
[1] = *intel_parser
.op_string
;
9769 new_token
.str
[2] = '\0';
9773 as_bad (_("Unrecognized token `%s'"), intel_parser
.op_string
);
9775 intel_parser
.op_string
+= strlen (new_token
.str
);
9776 cur_token
= new_token
;
9779 /* Put cur_token back into the token stream and make cur_token point to
9782 intel_putback_token (void)
9784 if (cur_token
.code
!= T_NIL
)
9786 intel_parser
.op_string
-= strlen (cur_token
.str
);
9787 free (cur_token
.str
);
9789 cur_token
= prev_token
;
9791 /* Forget prev_token. */
9792 prev_token
.code
= T_NIL
;
9793 prev_token
.reg
= NULL
;
9794 prev_token
.str
= NULL
;
9798 tc_x86_parse_to_dw2regnum (expressionS
*exp
)
9800 int saved_naked_reg
;
9801 char saved_register_dot
;
9803 saved_naked_reg
= allow_naked_reg
;
9804 allow_naked_reg
= 1;
9805 saved_register_dot
= register_chars
['.'];
9806 register_chars
['.'] = '.';
9807 allow_pseudo_reg
= 1;
9808 expression_and_evaluate (exp
);
9809 allow_pseudo_reg
= 0;
9810 register_chars
['.'] = saved_register_dot
;
9811 allow_naked_reg
= saved_naked_reg
;
9813 if (exp
->X_op
== O_register
&& exp
->X_add_number
>= 0)
9815 if ((addressT
) exp
->X_add_number
< i386_regtab_size
)
9817 exp
->X_op
= O_constant
;
9818 exp
->X_add_number
= i386_regtab
[exp
->X_add_number
]
9819 .dw2_regnum
[flag_code
>> 1];
9822 exp
->X_op
= O_illegal
;
9827 tc_x86_frame_initial_instructions (void)
9829 static unsigned int sp_regno
[2];
9831 if (!sp_regno
[flag_code
>> 1])
9833 char *saved_input
= input_line_pointer
;
9834 char sp
[][4] = {"esp", "rsp"};
9837 input_line_pointer
= sp
[flag_code
>> 1];
9838 tc_x86_parse_to_dw2regnum (&exp
);
9839 assert (exp
.X_op
== O_constant
);
9840 sp_regno
[flag_code
>> 1] = exp
.X_add_number
;
9841 input_line_pointer
= saved_input
;
9844 cfi_add_CFA_def_cfa (sp_regno
[flag_code
>> 1], -x86_cie_data_alignment
);
9845 cfi_add_CFA_offset (x86_dwarf2_return_column
, x86_cie_data_alignment
);
9849 i386_elf_section_type (const char *str
, size_t len
)
9851 if (flag_code
== CODE_64BIT
9852 && len
== sizeof ("unwind") - 1
9853 && strncmp (str
, "unwind", 6) == 0)
9854 return SHT_X86_64_UNWIND
;
9861 tc_pe_dwarf2_emit_offset (symbolS
*symbol
, unsigned int size
)
9865 expr
.X_op
= O_secrel
;
9866 expr
.X_add_symbol
= symbol
;
9867 expr
.X_add_number
= 0;
9868 emit_expr (&expr
, size
);
9872 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
9873 /* For ELF on x86-64, add support for SHF_X86_64_LARGE. */
9876 x86_64_section_letter (int letter
, char **ptr_msg
)
9878 if (flag_code
== CODE_64BIT
)
9881 return SHF_X86_64_LARGE
;
9883 *ptr_msg
= _("Bad .section directive: want a,l,w,x,M,S,G,T in string");
9886 *ptr_msg
= _("Bad .section directive: want a,w,x,M,S,G,T in string");
9891 x86_64_section_word (char *str
, size_t len
)
9893 if (len
== 5 && flag_code
== CODE_64BIT
&& CONST_STRNEQ (str
, "large"))
9894 return SHF_X86_64_LARGE
;
9900 handle_large_common (int small ATTRIBUTE_UNUSED
)
9902 if (flag_code
!= CODE_64BIT
)
9904 s_comm_internal (0, elf_common_parse
);
9905 as_warn (_(".largecomm supported only in 64bit mode, producing .comm"));
9909 static segT lbss_section
;
9910 asection
*saved_com_section_ptr
= elf_com_section_ptr
;
9911 asection
*saved_bss_section
= bss_section
;
9913 if (lbss_section
== NULL
)
9915 flagword applicable
;
9917 subsegT subseg
= now_subseg
;
9919 /* The .lbss section is for local .largecomm symbols. */
9920 lbss_section
= subseg_new (".lbss", 0);
9921 applicable
= bfd_applicable_section_flags (stdoutput
);
9922 bfd_set_section_flags (stdoutput
, lbss_section
,
9923 applicable
& SEC_ALLOC
);
9924 seg_info (lbss_section
)->bss
= 1;
9926 subseg_set (seg
, subseg
);
9929 elf_com_section_ptr
= &_bfd_elf_large_com_section
;
9930 bss_section
= lbss_section
;
9932 s_comm_internal (0, elf_common_parse
);
9934 elf_com_section_ptr
= saved_com_section_ptr
;
9935 bss_section
= saved_bss_section
;
9938 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */