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
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"
37 #ifndef REGISTER_WARNINGS
38 #define REGISTER_WARNINGS 1
41 #ifndef INFER_ADDR_PREFIX
42 #define INFER_ADDR_PREFIX 1
45 #ifndef SCALE1_WHEN_NO_INDEX
46 /* Specifying a scale factor besides 1 when there is no index is
47 futile. eg. `mov (%ebx,2),%al' does exactly the same as
48 `mov (%ebx),%al'. To slavishly follow what the programmer
49 specified, set SCALE1_WHEN_NO_INDEX to 0. */
50 #define SCALE1_WHEN_NO_INDEX 1
54 #define DEFAULT_ARCH "i386"
59 #define INLINE __inline__
65 static void set_code_flag (int);
66 static void set_16bit_gcc_code_flag (int);
67 static void set_intel_syntax (int);
68 static void set_cpu_arch (int);
70 static void pe_directive_secrel (int);
72 static void signed_cons (int);
73 static char *output_invalid (int c
);
74 static int i386_operand (char *);
75 static int i386_intel_operand (char *, int);
76 static const reg_entry
*parse_register (char *, char **);
77 static char *parse_insn (char *, char *);
78 static char *parse_operands (char *, const char *);
79 static void swap_operands (void);
80 static void swap_2_operands (int, int);
81 static void optimize_imm (void);
82 static void optimize_disp (void);
83 static int match_template (void);
84 static int check_string (void);
85 static int process_suffix (void);
86 static int check_byte_reg (void);
87 static int check_long_reg (void);
88 static int check_qword_reg (void);
89 static int check_word_reg (void);
90 static int finalize_imm (void);
91 static int process_operands (void);
92 static const seg_entry
*build_modrm_byte (void);
93 static void output_insn (void);
94 static void output_imm (fragS
*, offsetT
);
95 static void output_disp (fragS
*, offsetT
);
97 static void s_bss (int);
99 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
100 static void handle_large_common (int small ATTRIBUTE_UNUSED
);
102 static void nativeclient_symbol_init (void);
104 static const char *default_arch
= DEFAULT_ARCH
;
106 /* 'md_assemble ()' gathers together information and puts it into a
113 const reg_entry
*regs
;
118 /* TM holds the template for the insn were currently assembling. */
121 /* SUFFIX holds the instruction mnemonic suffix if given.
122 (e.g. 'l' for 'movl') */
125 /* OPERANDS gives the number of given operands. */
126 unsigned int operands
;
128 /* REG_OPERANDS, DISP_OPERANDS, MEM_OPERANDS, IMM_OPERANDS give the number
129 of given register, displacement, memory operands and immediate
131 unsigned int reg_operands
, disp_operands
, mem_operands
, imm_operands
;
133 /* TYPES [i] is the type (see above #defines) which tells us how to
134 use OP[i] for the corresponding operand. */
135 unsigned int types
[MAX_OPERANDS
];
137 /* Displacement expression, immediate expression, or register for each
139 union i386_op op
[MAX_OPERANDS
];
141 /* Flags for operands. */
142 unsigned int flags
[MAX_OPERANDS
];
143 #define Operand_PCrel 1
145 /* Relocation type for operand */
146 enum bfd_reloc_code_real reloc
[MAX_OPERANDS
];
148 /* BASE_REG, INDEX_REG, and LOG2_SCALE_FACTOR are used to encode
149 the base index byte below. */
150 const reg_entry
*base_reg
;
151 const reg_entry
*index_reg
;
152 unsigned int log2_scale_factor
;
154 /* SEG gives the seg_entries of this insn. They are zero unless
155 explicit segment overrides are given. */
156 const seg_entry
*seg
[2];
158 /* PREFIX holds all the given prefix opcodes (usually null).
159 PREFIXES is the number of prefix opcodes. */
160 unsigned int prefixes
;
161 unsigned char prefix
[MAX_PREFIXES
];
163 /* RM and SIB are the modrm byte and the sib byte where the
164 addressing modes of this insn are encoded. */
171 typedef struct _i386_insn i386_insn
;
173 /* List of chars besides those in app.c:symbol_chars that can start an
174 operand. Used to prevent the scrubber eating vital white-space. */
175 const char extra_symbol_chars
[] = "*%-(["
184 #if (defined (TE_I386AIX) \
185 || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) \
186 && !defined (TE_GNU) \
187 && !defined (TE_LINUX) \
188 && !defined (TE_NETWARE) \
189 && !defined (TE_FreeBSD) \
190 && !defined (TE_NetBSD)))
191 /* This array holds the chars that always start a comment. If the
192 pre-processor is disabled, these aren't very useful. The option
193 --divide will remove '/' from this list. */
194 const char *i386_comment_chars
= "#/";
195 #define SVR4_COMMENT_CHARS 1
196 #define PREFIX_SEPARATOR '\\'
199 const char *i386_comment_chars
= "#";
200 #define PREFIX_SEPARATOR '/'
203 /* This array holds the chars that only start a comment at the beginning of
204 a line. If the line seems to have the form '# 123 filename'
205 .line and .file directives will appear in the pre-processed output.
206 Note that input_file.c hand checks for '#' at the beginning of the
207 first line of the input file. This is because the compiler outputs
208 #NO_APP at the beginning of its output.
209 Also note that comments started like this one will always work if
210 '/' isn't otherwise defined. */
211 const char line_comment_chars
[] = "#/";
213 const char line_separator_chars
[] = ";";
215 /* Chars that can be used to separate mant from exp in floating point
217 const char EXP_CHARS
[] = "eE";
219 /* Chars that mean this number is a floating point constant
222 const char FLT_CHARS
[] = "fFdDxX";
224 /* Tables for lexical analysis. */
225 static char mnemonic_chars
[256];
226 static char register_chars
[256];
227 static char operand_chars
[256];
228 static char identifier_chars
[256];
229 static char digit_chars
[256];
231 /* Lexical macros. */
232 #define is_mnemonic_char(x) (mnemonic_chars[(unsigned char) x])
233 #define is_operand_char(x) (operand_chars[(unsigned char) x])
234 #define is_register_char(x) (register_chars[(unsigned char) x])
235 #define is_space_char(x) ((x) == ' ')
236 #define is_identifier_char(x) (identifier_chars[(unsigned char) x])
237 #define is_digit_char(x) (digit_chars[(unsigned char) x])
239 /* All non-digit non-letter characters that may occur in an operand. */
240 static char operand_special_chars
[] = "%$-+(,)*._~/<>|&^!:[@]";
242 /* md_assemble() always leaves the strings it's passed unaltered. To
243 effect this we maintain a stack of saved characters that we've smashed
244 with '\0's (indicating end of strings for various sub-fields of the
245 assembler instruction). */
246 static char save_stack
[32];
247 static char *save_stack_p
;
248 #define END_STRING_AND_SAVE(s) \
249 do { *save_stack_p++ = *(s); *(s) = '\0'; } while (0)
250 #define RESTORE_END_STRING(s) \
251 do { *(s) = *--save_stack_p; } while (0)
253 /* The instruction we're assembling. */
256 /* Possible templates for current insn. */
257 static const templates
*current_templates
;
259 /* Per instruction expressionS buffers: max displacements & immediates. */
260 static expressionS disp_expressions
[MAX_MEMORY_OPERANDS
];
261 static expressionS im_expressions
[MAX_IMMEDIATE_OPERANDS
];
263 /* Current operand we are working on. */
264 static int this_operand
;
266 /* We support four different modes. FLAG_CODE variable is used to distinguish
273 #define NUM_FLAG_CODE ((int) CODE_64BIT + 1)
275 static enum flag_code flag_code
;
276 static unsigned int object_64bit
;
277 static int use_rela_relocations
= 0;
279 /* The names used to print error messages. */
280 static const char *flag_code_names
[] =
287 /* 1 for intel syntax,
289 static int intel_syntax
= 0;
291 /* 1 if register prefix % not required. */
292 static int allow_naked_reg
= 0;
294 /* Register prefix used for error message. */
295 static const char *register_prefix
= "%";
297 /* Used in 16 bit gcc mode to add an l suffix to call, ret, enter,
298 leave, push, and pop instructions so that gcc has the same stack
299 frame as in 32 bit mode. */
300 static char stackop_size
= '\0';
302 /* Non-zero to optimize code alignment. */
303 int optimize_align_code
= 1;
305 /* Non-zero to quieten some warnings. */
306 static int quiet_warnings
= 0;
309 static const char *cpu_arch_name
= NULL
;
310 static const char *cpu_sub_arch_name
= NULL
;
312 /* CPU feature flags. */
313 static unsigned int cpu_arch_flags
= CpuUnknownFlags
| CpuNo64
;
315 /* If we have selected a cpu we are generating instructions for. */
316 static int cpu_arch_tune_set
= 0;
318 /* Cpu we are generating instructions for. */
319 static enum processor_type cpu_arch_tune
= PROCESSOR_UNKNOWN
;
321 /* CPU feature flags of cpu we are generating instructions for. */
322 static unsigned int cpu_arch_tune_flags
= 0;
324 /* CPU instruction set architecture used. */
325 static enum processor_type cpu_arch_isa
= PROCESSOR_UNKNOWN
;
327 /* CPU feature flags of instruction set architecture used. */
328 static unsigned int cpu_arch_isa_flags
= 0;
330 /* If set, conditional jumps are not automatically promoted to handle
331 larger than a byte offset. */
332 static unsigned int no_cond_jump_promotion
= 0;
334 /* Pre-defined "_GLOBAL_OFFSET_TABLE_". */
335 static symbolS
*GOT_symbol
;
337 /* The dwarf2 return column, adjusted for 32 or 64 bit. */
338 unsigned int x86_dwarf2_return_column
;
340 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
341 int x86_cie_data_alignment
;
343 /* NativeClient support */
345 /* Default alignment. 0=OFF */
346 int nacl_alignment
= NACL_ALIGN_POW2
;
348 /* Use library mode. 0=OFF */
349 int nacl_library_mode
= 0;
351 /* Interface to relax_segment.
352 There are 3 major relax states for 386 jump insns because the
353 different types of jumps add different sizes to frags when we're
354 figuring out what sort of jump to choose to reach a given label. */
357 #define UNCOND_JUMP 0
359 #define COND_JUMP86 2
364 #define SMALL16 (SMALL | CODE16)
366 #define BIG16 (BIG | CODE16)
370 #define INLINE __inline__
376 #define ENCODE_RELAX_STATE(type, size) \
377 ((relax_substateT) (((type) << 2) | (size)))
378 #define TYPE_FROM_RELAX_STATE(s) \
380 #define DISP_SIZE_FROM_RELAX_STATE(s) \
381 ((((s) & 3) == BIG ? 4 : (((s) & 3) == BIG16 ? 2 : 1)))
383 /* This table is used by relax_frag to promote short jumps to long
384 ones where necessary. SMALL (short) jumps may be promoted to BIG
385 (32 bit long) ones, and SMALL16 jumps to BIG16 (16 bit long). We
386 don't allow a short jump in a 32 bit code segment to be promoted to
387 a 16 bit offset jump because it's slower (requires data size
388 prefix), and doesn't work, unless the destination is in the bottom
389 64k of the code segment (The top 16 bits of eip are zeroed). */
391 const relax_typeS md_relax_table
[] =
394 1) most positive reach of this state,
395 2) most negative reach of this state,
396 3) how many bytes this mode will have in the variable part of the frag
397 4) which index into the table to try if we can't fit into this one. */
399 /* UNCOND_JUMP states. */
400 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (UNCOND_JUMP
, BIG
)},
401 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (UNCOND_JUMP
, BIG16
)},
402 /* dword jmp adds 4 bytes to frag:
403 0 extra opcode bytes, 4 displacement bytes. */
405 /* word jmp adds 2 byte2 to frag:
406 0 extra opcode bytes, 2 displacement bytes. */
409 /* COND_JUMP states. */
410 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP
, BIG
)},
411 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP
, BIG16
)},
412 /* dword conditionals adds 5 bytes to frag:
413 1 extra opcode byte, 4 displacement bytes. */
415 /* word conditionals add 3 bytes to frag:
416 1 extra opcode byte, 2 displacement bytes. */
419 /* COND_JUMP86 states. */
420 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP86
, BIG
)},
421 {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP86
, BIG16
)},
422 /* dword conditionals adds 5 bytes to frag:
423 1 extra opcode byte, 4 displacement bytes. */
425 /* word conditionals add 4 bytes to frag:
426 1 displacement byte and a 3 byte long branch insn. */
430 static const arch_entry cpu_arch
[] =
432 {"generic32", PROCESSOR_GENERIC32
,
433 Cpu186
|Cpu286
|Cpu386
},
434 {"generic64", PROCESSOR_GENERIC64
,
435 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuP4
|CpuMMX
436 |CpuMMX2
|CpuSSE
|CpuSSE2
},
437 {"i8086", PROCESSOR_UNKNOWN
,
439 {"i186", PROCESSOR_UNKNOWN
,
441 {"i286", PROCESSOR_UNKNOWN
,
443 {"i386", PROCESSOR_I386
,
444 Cpu186
|Cpu286
|Cpu386
},
445 {"i486", PROCESSOR_I486
,
446 Cpu186
|Cpu286
|Cpu386
|Cpu486
},
447 {"i586", PROCESSOR_PENTIUM
,
448 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
},
449 {"i686", PROCESSOR_PENTIUMPRO
,
450 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
},
451 {"pentium", PROCESSOR_PENTIUM
,
452 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
},
453 {"pentiumpro",PROCESSOR_PENTIUMPRO
,
454 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
},
455 {"pentiumii", PROCESSOR_PENTIUMPRO
,
456 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuMMX
},
457 {"pentiumiii",PROCESSOR_PENTIUMPRO
,
458 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuMMX
|CpuMMX2
|CpuSSE
},
459 {"pentium4", PROCESSOR_PENTIUM4
,
460 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuP4
|CpuMMX
461 |CpuMMX2
|CpuSSE
|CpuSSE2
},
462 {"prescott", PROCESSOR_NOCONA
,
463 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuP4
|CpuMMX
464 |CpuMMX2
|CpuSSE
|CpuSSE2
|CpuSSE3
},
465 {"nocona", PROCESSOR_NOCONA
,
466 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuP4
|CpuMMX
467 |CpuMMX2
|CpuSSE
|CpuSSE2
|CpuSSE3
},
468 {"yonah", PROCESSOR_CORE
,
469 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuP4
|CpuMMX
470 |CpuMMX2
|CpuSSE
|CpuSSE2
|CpuSSE3
},
471 {"core", PROCESSOR_CORE
,
472 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuP4
|CpuMMX
473 |CpuMMX2
|CpuSSE
|CpuSSE2
|CpuSSE3
},
474 {"merom", PROCESSOR_CORE2
,
475 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuP4
|CpuMMX
476 |CpuMMX2
|CpuSSE
|CpuSSE2
|CpuSSE3
|CpuSSSE3
},
477 {"core2", PROCESSOR_CORE2
,
478 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuP4
|CpuMMX
479 |CpuMMX2
|CpuSSE
|CpuSSE2
|CpuSSE3
|CpuSSSE3
},
481 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|CpuK6
|CpuMMX
},
482 {"k6_2", PROCESSOR_K6
,
483 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|CpuK6
|CpuMMX
|Cpu3dnow
},
484 {"athlon", PROCESSOR_ATHLON
,
485 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuK6
486 |CpuMMX
|CpuMMX2
|Cpu3dnow
|Cpu3dnowA
},
487 {"sledgehammer", PROCESSOR_K8
,
488 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuK6
489 |CpuSledgehammer
|CpuMMX
|CpuMMX2
|Cpu3dnow
|Cpu3dnowA
|CpuSSE
|CpuSSE2
},
490 {"opteron", PROCESSOR_K8
,
491 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuK6
492 |CpuSledgehammer
|CpuMMX
|CpuMMX2
|Cpu3dnow
|Cpu3dnowA
|CpuSSE
|CpuSSE2
},
494 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuK6
495 |CpuSledgehammer
|CpuMMX
|CpuMMX2
|Cpu3dnow
|Cpu3dnowA
|CpuSSE
|CpuSSE2
},
496 {"amdfam10", PROCESSOR_AMDFAM10
,
497 Cpu186
|Cpu286
|Cpu386
|Cpu486
|Cpu586
|Cpu686
|CpuK6
|CpuSledgehammer
498 |CpuMMX
|CpuMMX2
|Cpu3dnow
|Cpu3dnowA
|CpuSSE
|CpuSSE2
|CpuSSE3
|CpuSSE4a
500 {".mmx", PROCESSOR_UNKNOWN
,
502 {".sse", PROCESSOR_UNKNOWN
,
503 CpuMMX
|CpuMMX2
|CpuSSE
},
504 {".sse2", PROCESSOR_UNKNOWN
,
505 CpuMMX
|CpuMMX2
|CpuSSE
|CpuSSE2
},
506 {".sse3", PROCESSOR_UNKNOWN
,
507 CpuMMX
|CpuMMX2
|CpuSSE
|CpuSSE2
|CpuSSE3
},
508 {".ssse3", PROCESSOR_UNKNOWN
,
509 CpuMMX
|CpuMMX2
|CpuSSE
|CpuSSE2
|CpuSSE3
|CpuSSSE3
},
510 {".sse4.1", PROCESSOR_UNKNOWN
,
511 CpuMMX
|CpuMMX2
|CpuSSE
|CpuSSE2
|CpuSSE3
|CpuSSSE3
|CpuSSE4_1
},
512 {".sse4.2", PROCESSOR_UNKNOWN
,
513 CpuMMX
|CpuMMX2
|CpuSSE
|CpuSSE2
|CpuSSE3
|CpuSSSE3
|CpuSSE4
},
514 {".sse4", PROCESSOR_UNKNOWN
,
515 CpuMMX
|CpuMMX2
|CpuSSE
|CpuSSE2
|CpuSSE3
|CpuSSSE3
|CpuSSE4
},
516 {".3dnow", PROCESSOR_UNKNOWN
,
518 {".3dnowa", PROCESSOR_UNKNOWN
,
519 CpuMMX
|CpuMMX2
|Cpu3dnow
|Cpu3dnowA
},
520 {".padlock", PROCESSOR_UNKNOWN
,
522 {".pacifica", PROCESSOR_UNKNOWN
,
524 {".svme", PROCESSOR_UNKNOWN
,
526 {".sse4a", PROCESSOR_UNKNOWN
,
527 CpuMMX
|CpuMMX2
|CpuSSE
|CpuSSE2
|CpuSSE3
|CpuSSE4a
},
528 {".abm", PROCESSOR_UNKNOWN
,
532 const pseudo_typeS md_pseudo_table
[] =
534 #if !defined(OBJ_AOUT) && !defined(USE_ALIGN_PTWO)
535 {"align", s_align_bytes
, 0},
537 {"align", s_align_ptwo
, 0},
539 {"arch", set_cpu_arch
, 0},
543 {"ffloat", float_cons
, 'f'},
544 {"dfloat", float_cons
, 'd'},
545 {"tfloat", float_cons
, 'x'},
547 {"slong", signed_cons
, 4},
548 {"noopt", s_ignore
, 0},
549 {"optim", s_ignore
, 0},
550 {"code16gcc", set_16bit_gcc_code_flag
, CODE_16BIT
},
551 {"code16", set_code_flag
, CODE_16BIT
},
552 {"code32", set_code_flag
, CODE_32BIT
},
553 {"code64", set_code_flag
, CODE_64BIT
},
554 {"intel_syntax", set_intel_syntax
, 1},
555 {"att_syntax", set_intel_syntax
, 0},
556 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
557 {"largecomm", handle_large_common
, 0},
559 {"file", (void (*) (int)) dwarf2_directive_file
, 0},
560 {"loc", dwarf2_directive_loc
, 0},
561 {"loc_mark_labels", dwarf2_directive_loc_mark_labels
, 0},
564 {"secrel32", pe_directive_secrel
, 0},
569 /* For interface with expression (). */
570 extern char *input_line_pointer
;
572 /* Hash table for instruction mnemonic lookup. */
573 static struct hash_control
*op_hash
;
575 /* Hash table for register lookup. */
576 static struct hash_control
*reg_hash
;
579 i386_align_code (fragS
*fragP
, int count
)
581 /* Various efficient no-op patterns for aligning code labels.
582 Note: Don't try to assemble the instructions in the comments.
583 0L and 0w are not legal. */
584 static const char f32_1
[] =
586 static const char f32_2
[] =
587 {0x66,0x90}; /* xchg %ax,%ax */
588 static const char f32_3
[] =
589 {0x8d,0x76,0x00}; /* leal 0(%esi),%esi */
590 static const char f32_4
[] =
591 {0x8d,0x74,0x26,0x00}; /* leal 0(%esi,1),%esi */
592 static const char f32_5
[] =
594 0x8d,0x74,0x26,0x00}; /* leal 0(%esi,1),%esi */
595 static const char f32_6
[] =
596 {0x8d,0xb6,0x00,0x00,0x00,0x00}; /* leal 0L(%esi),%esi */
597 static const char f32_7
[] =
598 {0x8d,0xb4,0x26,0x00,0x00,0x00,0x00}; /* leal 0L(%esi,1),%esi */
599 static const char f32_8
[] =
601 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00}; /* leal 0L(%esi,1),%esi */
602 static const char f32_9
[] =
603 {0x89,0xf6, /* movl %esi,%esi */
604 0x8d,0xbc,0x27,0x00,0x00,0x00,0x00}; /* leal 0L(%edi,1),%edi */
605 static const char f32_10
[] =
606 {0x8d,0x76,0x00, /* leal 0(%esi),%esi */
607 0x8d,0xbc,0x27,0x00,0x00,0x00,0x00}; /* leal 0L(%edi,1),%edi */
608 static const char f32_11
[] =
609 {0x8d,0x74,0x26,0x00, /* leal 0(%esi,1),%esi */
610 0x8d,0xbc,0x27,0x00,0x00,0x00,0x00}; /* leal 0L(%edi,1),%edi */
611 static const char f32_12
[] =
612 {0x8d,0xb6,0x00,0x00,0x00,0x00, /* leal 0L(%esi),%esi */
613 0x8d,0xbf,0x00,0x00,0x00,0x00}; /* leal 0L(%edi),%edi */
614 static const char f32_13
[] =
615 {0x8d,0xb6,0x00,0x00,0x00,0x00, /* leal 0L(%esi),%esi */
616 0x8d,0xbc,0x27,0x00,0x00,0x00,0x00}; /* leal 0L(%edi,1),%edi */
617 static const char f32_14
[] =
618 {0x8d,0xb4,0x26,0x00,0x00,0x00,0x00, /* leal 0L(%esi,1),%esi */
619 0x8d,0xbc,0x27,0x00,0x00,0x00,0x00}; /* leal 0L(%edi,1),%edi */
620 static const char f16_3
[] =
621 {0x8d,0x74,0x00}; /* lea 0(%esi),%esi */
622 static const char f16_4
[] =
623 {0x8d,0xb4,0x00,0x00}; /* lea 0w(%si),%si */
624 static const char f16_5
[] =
626 0x8d,0xb4,0x00,0x00}; /* lea 0w(%si),%si */
627 static const char f16_6
[] =
628 {0x89,0xf6, /* mov %si,%si */
629 0x8d,0xbd,0x00,0x00}; /* lea 0w(%di),%di */
630 static const char f16_7
[] =
631 {0x8d,0x74,0x00, /* lea 0(%si),%si */
632 0x8d,0xbd,0x00,0x00}; /* lea 0w(%di),%di */
633 static const char f16_8
[] =
634 {0x8d,0xb4,0x00,0x00, /* lea 0w(%si),%si */
635 0x8d,0xbd,0x00,0x00}; /* lea 0w(%di),%di */
636 static const char jump_31
[] =
637 {0xeb,0x1d,0x90,0x90,0x90,0x90,0x90, /* jmp .+31; lotsa nops */
638 0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,
639 0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90,
640 0x90,0x90,0x90,0x90,0x90,0x90,0x90,0x90};
641 static const char *const f32_patt
[] = {
642 f32_1
, f32_2
, f32_3
, f32_4
, f32_5
, f32_6
, f32_7
, f32_8
,
643 f32_9
, f32_10
, f32_11
, f32_12
, f32_13
, f32_14
645 static const char *const f16_patt
[] = {
646 f32_1
, f32_2
, f16_3
, f16_4
, f16_5
, f16_6
, f16_7
, f16_8
649 static const char alt_3
[] =
651 /* nopl 0(%[re]ax) */
652 static const char alt_4
[] =
653 {0x0f,0x1f,0x40,0x00};
654 /* nopl 0(%[re]ax,%[re]ax,1) */
655 static const char alt_5
[] =
656 {0x0f,0x1f,0x44,0x00,0x00};
657 /* nopw 0(%[re]ax,%[re]ax,1) */
658 static const char alt_6
[] =
659 {0x66,0x0f,0x1f,0x44,0x00,0x00};
660 /* nopl 0L(%[re]ax) */
661 static const char alt_7
[] =
662 {0x0f,0x1f,0x80,0x00,0x00,0x00,0x00};
663 /* nopl 0L(%[re]ax,%[re]ax,1) */
664 static const char alt_8
[] =
665 {0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
666 /* nopw 0L(%[re]ax,%[re]ax,1) */
667 static const char alt_9
[] =
668 {0x66,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
669 /* nopw %cs:0L(%[re]ax,%[re]ax,1) */
670 static const char alt_10
[] =
671 {0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
673 nopw %cs:0L(%[re]ax,%[re]ax,1) */
674 static const char alt_long_11
[] =
676 0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
679 nopw %cs:0L(%[re]ax,%[re]ax,1) */
680 static const char alt_long_12
[] =
683 0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
687 nopw %cs:0L(%[re]ax,%[re]ax,1) */
688 static const char alt_long_13
[] =
692 0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
697 nopw %cs:0L(%[re]ax,%[re]ax,1) */
698 static const char alt_long_14
[] =
703 0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
709 nopw %cs:0L(%[re]ax,%[re]ax,1) */
710 static const char alt_long_15
[] =
716 0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
717 /* nopl 0(%[re]ax,%[re]ax,1)
718 nopw 0(%[re]ax,%[re]ax,1) */
719 static const char alt_short_11
[] =
720 {0x0f,0x1f,0x44,0x00,0x00,
721 0x66,0x0f,0x1f,0x44,0x00,0x00};
722 /* nopw 0(%[re]ax,%[re]ax,1)
723 nopw 0(%[re]ax,%[re]ax,1) */
724 static const char alt_short_12
[] =
725 {0x66,0x0f,0x1f,0x44,0x00,0x00,
726 0x66,0x0f,0x1f,0x44,0x00,0x00};
727 /* nopw 0(%[re]ax,%[re]ax,1)
729 static const char alt_short_13
[] =
730 {0x66,0x0f,0x1f,0x44,0x00,0x00,
731 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00};
734 static const char alt_short_14
[] =
735 {0x0f,0x1f,0x80,0x00,0x00,0x00,0x00,
736 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00};
738 nopl 0L(%[re]ax,%[re]ax,1) */
739 static const char alt_short_15
[] =
740 {0x0f,0x1f,0x80,0x00,0x00,0x00,0x00,
741 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00};
742 static const char *const alt_short_patt
[] = {
743 f32_1
, f32_2
, alt_3
, alt_4
, alt_5
, alt_6
, alt_7
, alt_8
,
744 alt_9
, alt_10
, alt_short_11
, alt_short_12
, alt_short_13
,
745 alt_short_14
, alt_short_15
747 static const char *const alt_long_patt
[] = {
748 f32_1
, f32_2
, alt_3
, alt_4
, alt_5
, alt_6
, alt_7
, alt_8
,
749 alt_9
, alt_10
, alt_long_11
, alt_long_12
, alt_long_13
,
750 alt_long_14
, alt_long_15
753 /* Only align for at least a positive non-zero boundary. */
754 if (count
<= 0 || count
> MAX_MEM_FOR_RS_ALIGN_CODE
)
757 /* We need to decide which NOP sequence to use for 32bit and
758 64bit. When -mtune= is used:
760 1. For PROCESSOR_I386, PROCESSOR_I486, PROCESSOR_PENTIUM and
761 PROCESSOR_GENERIC32, f32_patt will be used.
762 2. For PROCESSOR_PENTIUMPRO, PROCESSOR_PENTIUM4, PROCESSOR_NOCONA,
763 PROCESSOR_CORE, PROCESSOR_CORE2, and PROCESSOR_GENERIC64,
764 alt_long_patt will be used.
765 3. For PROCESSOR_ATHLON, PROCESSOR_K6, PROCESSOR_K8 and
766 PROCESSOR_AMDFAM10, alt_short_patt will be used.
768 When -mtune= isn't used, alt_long_patt will be used if
769 cpu_arch_isa_flags has Cpu686. Otherwise, f32_patt will
772 When -march= or .arch is used, we can't use anything beyond
773 cpu_arch_isa_flags. */
775 if (flag_code
== CODE_16BIT
)
779 memcpy (fragP
->fr_literal
+ fragP
->fr_fix
,
781 /* Adjust jump offset. */
782 fragP
->fr_literal
[fragP
->fr_fix
+ 1] = count
- 2;
785 memcpy (fragP
->fr_literal
+ fragP
->fr_fix
,
786 f16_patt
[count
- 1], count
);
790 const char *const *patt
= NULL
;
792 if (cpu_arch_isa
== PROCESSOR_UNKNOWN
)
794 /* PROCESSOR_UNKNOWN means that all ISAs may be used. */
795 switch (cpu_arch_tune
)
797 case PROCESSOR_UNKNOWN
:
798 /* We use cpu_arch_isa_flags to check if we SHOULD
799 optimize for Cpu686. */
800 if ((cpu_arch_isa_flags
& Cpu686
) != 0)
801 patt
= alt_long_patt
;
805 case PROCESSOR_PENTIUMPRO
:
806 case PROCESSOR_PENTIUM4
:
807 case PROCESSOR_NOCONA
:
809 case PROCESSOR_CORE2
:
810 case PROCESSOR_GENERIC64
:
811 patt
= alt_long_patt
;
814 case PROCESSOR_ATHLON
:
816 case PROCESSOR_AMDFAM10
:
817 patt
= alt_short_patt
;
821 case PROCESSOR_PENTIUM
:
822 case PROCESSOR_GENERIC32
:
829 switch (cpu_arch_tune
)
831 case PROCESSOR_UNKNOWN
:
832 /* When cpu_arch_isa is net, cpu_arch_tune shouldn't be
833 PROCESSOR_UNKNOWN. */
839 case PROCESSOR_PENTIUM
:
841 case PROCESSOR_ATHLON
:
843 case PROCESSOR_AMDFAM10
:
844 case PROCESSOR_GENERIC32
:
845 /* We use cpu_arch_isa_flags to check if we CAN optimize
847 if ((cpu_arch_isa_flags
& Cpu686
) != 0)
848 patt
= alt_short_patt
;
852 case PROCESSOR_PENTIUMPRO
:
853 case PROCESSOR_PENTIUM4
:
854 case PROCESSOR_NOCONA
:
856 case PROCESSOR_CORE2
:
857 if ((cpu_arch_isa_flags
& Cpu686
) != 0)
858 patt
= alt_long_patt
;
862 case PROCESSOR_GENERIC64
:
863 patt
= alt_long_patt
;
868 if (patt
== f32_patt
)
870 /* If the padding is less than 15 bytes, we use the normal
871 ones. Otherwise, we use a jump instruction and adjust
874 memcpy (fragP
->fr_literal
+ fragP
->fr_fix
,
875 patt
[count
- 1], count
);
878 memcpy (fragP
->fr_literal
+ fragP
->fr_fix
,
880 /* Adjust jump offset. */
881 fragP
->fr_literal
[fragP
->fr_fix
+ 1] = count
- 2;
886 /* Maximum length of an instruction is 15 byte. If the
887 padding is greater than 15 bytes and we don't use jump,
888 we have to break it into smaller pieces. */
893 memcpy (fragP
->fr_literal
+ fragP
->fr_fix
+ padding
,
898 memcpy (fragP
->fr_literal
+ fragP
->fr_fix
,
899 patt
[padding
- 1], padding
);
902 fragP
->fr_var
= count
;
905 static INLINE
unsigned int
906 mode_from_disp_size (unsigned int t
)
908 return (t
& Disp8
) ? 1 : (t
& (Disp16
| Disp32
| Disp32S
)) ? 2 : 0;
912 fits_in_signed_byte (offsetT num
)
914 return (num
>= -128) && (num
<= 127);
918 fits_in_unsigned_byte (offsetT num
)
920 return (num
& 0xff) == num
;
924 fits_in_unsigned_word (offsetT num
)
926 return (num
& 0xffff) == num
;
930 fits_in_signed_word (offsetT num
)
932 return (-32768 <= num
) && (num
<= 32767);
936 fits_in_signed_long (offsetT num ATTRIBUTE_UNUSED
)
941 return (!(((offsetT
) -1 << 31) & num
)
942 || (((offsetT
) -1 << 31) & num
) == ((offsetT
) -1 << 31));
944 } /* fits_in_signed_long() */
947 fits_in_unsigned_long (offsetT num ATTRIBUTE_UNUSED
)
952 return (num
& (((offsetT
) 2 << 31) - 1)) == num
;
954 } /* fits_in_unsigned_long() */
957 smallest_imm_type (offsetT num
)
959 if (cpu_arch_flags
!= (Cpu186
| Cpu286
| Cpu386
| Cpu486
| CpuNo64
))
961 /* This code is disabled on the 486 because all the Imm1 forms
962 in the opcode table are slower on the i486. They're the
963 versions with the implicitly specified single-position
964 displacement, which has another syntax if you really want to
967 return Imm1
| Imm8
| Imm8S
| Imm16
| Imm32
| Imm32S
| Imm64
;
969 return (fits_in_signed_byte (num
)
970 ? (Imm8S
| Imm8
| Imm16
| Imm32
| Imm32S
| Imm64
)
971 : fits_in_unsigned_byte (num
)
972 ? (Imm8
| Imm16
| Imm32
| Imm32S
| Imm64
)
973 : (fits_in_signed_word (num
) || fits_in_unsigned_word (num
))
974 ? (Imm16
| Imm32
| Imm32S
| Imm64
)
975 : fits_in_signed_long (num
)
976 ? (Imm32
| Imm32S
| Imm64
)
977 : fits_in_unsigned_long (num
)
983 offset_in_range (offsetT val
, int size
)
989 case 1: mask
= ((addressT
) 1 << 8) - 1; break;
990 case 2: mask
= ((addressT
) 1 << 16) - 1; break;
991 case 4: mask
= ((addressT
) 2 << 31) - 1; break;
993 case 8: mask
= ((addressT
) 2 << 63) - 1; break;
998 /* If BFD64, sign extend val. */
999 if (!use_rela_relocations
)
1000 if ((val
& ~(((addressT
) 2 << 31) - 1)) == 0)
1001 val
= (val
^ ((addressT
) 1 << 31)) - ((addressT
) 1 << 31);
1003 if ((val
& ~mask
) != 0 && (val
& ~mask
) != ~mask
)
1005 char buf1
[40], buf2
[40];
1007 sprint_value (buf1
, val
);
1008 sprint_value (buf2
, val
& mask
);
1009 as_warn (_("%s shortened to %s"), buf1
, buf2
);
1014 /* Returns 0 if attempting to add a prefix where one from the same
1015 class already exists, 1 if non rep/repne added, 2 if rep/repne
1018 add_prefix (unsigned int prefix
)
1023 if (prefix
>= REX_OPCODE
&& prefix
< REX_OPCODE
+ 16
1024 && flag_code
== CODE_64BIT
)
1026 if ((i
.prefix
[REX_PREFIX
] & prefix
& REX_W
)
1027 || ((i
.prefix
[REX_PREFIX
] & (REX_R
| REX_X
| REX_B
))
1028 && (prefix
& (REX_R
| REX_X
| REX_B
))))
1039 case CS_PREFIX_OPCODE
:
1040 case DS_PREFIX_OPCODE
:
1041 case ES_PREFIX_OPCODE
:
1042 case FS_PREFIX_OPCODE
:
1043 case GS_PREFIX_OPCODE
:
1044 case SS_PREFIX_OPCODE
:
1048 case REPNE_PREFIX_OPCODE
:
1049 case REPE_PREFIX_OPCODE
:
1052 case LOCK_PREFIX_OPCODE
:
1060 case ADDR_PREFIX_OPCODE
:
1064 case DATA_PREFIX_OPCODE
:
1068 if (i
.prefix
[q
] != 0)
1076 i
.prefix
[q
] |= prefix
;
1079 as_bad (_("same type of prefix used twice"));
1085 set_code_flag (int value
)
1088 cpu_arch_flags
&= ~(Cpu64
| CpuNo64
);
1089 cpu_arch_flags
|= (flag_code
== CODE_64BIT
? Cpu64
: CpuNo64
);
1090 if (value
== CODE_64BIT
&& !(cpu_arch_flags
& CpuSledgehammer
))
1092 as_bad (_("64bit mode not supported on this CPU."));
1094 if (value
== CODE_32BIT
&& !(cpu_arch_flags
& Cpu386
))
1096 as_bad (_("32bit mode not supported on this CPU."));
1098 stackop_size
= '\0';
1102 set_16bit_gcc_code_flag (int new_code_flag
)
1104 flag_code
= new_code_flag
;
1105 cpu_arch_flags
&= ~(Cpu64
| CpuNo64
);
1106 cpu_arch_flags
|= (flag_code
== CODE_64BIT
? Cpu64
: CpuNo64
);
1107 stackop_size
= LONG_MNEM_SUFFIX
;
1111 set_intel_syntax (int syntax_flag
)
1113 /* Find out if register prefixing is specified. */
1114 int ask_naked_reg
= 0;
1117 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1119 char *string
= input_line_pointer
;
1120 int e
= get_symbol_end ();
1122 if (strcmp (string
, "prefix") == 0)
1124 else if (strcmp (string
, "noprefix") == 0)
1127 as_bad (_("bad argument to syntax directive."));
1128 *input_line_pointer
= e
;
1130 demand_empty_rest_of_line ();
1132 intel_syntax
= syntax_flag
;
1134 if (ask_naked_reg
== 0)
1135 allow_naked_reg
= (intel_syntax
1136 && (bfd_get_symbol_leading_char (stdoutput
) != '\0'));
1138 allow_naked_reg
= (ask_naked_reg
< 0);
1140 identifier_chars
['%'] = intel_syntax
&& allow_naked_reg
? '%' : 0;
1141 identifier_chars
['$'] = intel_syntax
? '$' : 0;
1142 register_prefix
= allow_naked_reg
? "" : "%";
1146 set_cpu_arch (int dummy ATTRIBUTE_UNUSED
)
1150 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1152 char *string
= input_line_pointer
;
1153 int e
= get_symbol_end ();
1156 for (i
= 0; i
< ARRAY_SIZE (cpu_arch
); i
++)
1158 if (strcmp (string
, cpu_arch
[i
].name
) == 0)
1162 cpu_arch_name
= cpu_arch
[i
].name
;
1163 cpu_sub_arch_name
= NULL
;
1164 cpu_arch_flags
= (cpu_arch
[i
].flags
1165 | (flag_code
== CODE_64BIT
1166 ? Cpu64
: CpuNo64
));
1167 cpu_arch_isa
= cpu_arch
[i
].type
;
1168 cpu_arch_isa_flags
= cpu_arch
[i
].flags
;
1169 if (!cpu_arch_tune_set
)
1171 cpu_arch_tune
= cpu_arch_isa
;
1172 cpu_arch_tune_flags
= cpu_arch_isa_flags
;
1176 if ((cpu_arch_flags
| cpu_arch
[i
].flags
) != cpu_arch_flags
)
1178 cpu_sub_arch_name
= cpu_arch
[i
].name
;
1179 cpu_arch_flags
|= cpu_arch
[i
].flags
;
1181 *input_line_pointer
= e
;
1182 demand_empty_rest_of_line ();
1186 if (i
>= ARRAY_SIZE (cpu_arch
))
1187 as_bad (_("no such architecture: `%s'"), string
);
1189 *input_line_pointer
= e
;
1192 as_bad (_("missing cpu architecture"));
1194 no_cond_jump_promotion
= 0;
1195 if (*input_line_pointer
== ','
1196 && !is_end_of_line
[(unsigned char) input_line_pointer
[1]])
1198 char *string
= ++input_line_pointer
;
1199 int e
= get_symbol_end ();
1201 if (strcmp (string
, "nojumps") == 0)
1202 no_cond_jump_promotion
= 1;
1203 else if (strcmp (string
, "jumps") == 0)
1206 as_bad (_("no such architecture modifier: `%s'"), string
);
1208 *input_line_pointer
= e
;
1211 demand_empty_rest_of_line ();
1217 if (!strcmp (default_arch
, "x86_64"))
1218 return bfd_mach_x86_64
;
1219 else if (!strcmp (default_arch
, "i386"))
1220 return bfd_mach_i386_i386
;
1222 as_fatal (_("Unknown architecture"));
1226 nativeclient_symbol_init ()
1232 * A symbol conveying the setting of nacl_alignment to assembler writers.
1234 symbolP
= symbol_new ("NACLALIGN", absolute_section
,
1235 (valueT
) nacl_alignment
, &zero_address_frag
);
1236 symbol_table_insert (symbolP
);
1239 * A symbol conveying the function entry alignment. This differs from
1240 * NACLALIGN in library mode.
1242 if (nacl_library_mode
) {
1246 entry_align
= nacl_alignment
;
1248 symbolP
= symbol_new ("NACLENTRYALIGN", absolute_section
,
1249 (valueT
) entry_align
, &zero_address_frag
);
1250 symbol_table_insert (symbolP
);
1256 const char *hash_err
;
1258 /* Initialize op_hash hash table. */
1259 op_hash
= hash_new ();
1262 const template *optab
;
1263 templates
*core_optab
;
1265 /* Setup for loop. */
1267 core_optab
= (templates
*) xmalloc (sizeof (templates
));
1268 core_optab
->start
= optab
;
1273 if (optab
->name
== NULL
1274 || strcmp (optab
->name
, (optab
- 1)->name
) != 0)
1276 /* different name --> ship out current template list;
1277 add to hash table; & begin anew. */
1278 core_optab
->end
= optab
;
1279 hash_err
= hash_insert (op_hash
,
1284 as_fatal (_("Internal Error: Can't hash %s: %s"),
1288 if (optab
->name
== NULL
)
1290 core_optab
= (templates
*) xmalloc (sizeof (templates
));
1291 core_optab
->start
= optab
;
1296 /* Initialize reg_hash hash table. */
1297 reg_hash
= hash_new ();
1299 const reg_entry
*regtab
;
1300 unsigned int regtab_size
= i386_regtab_size
;
1302 for (regtab
= i386_regtab
; regtab_size
--; regtab
++)
1304 hash_err
= hash_insert (reg_hash
, regtab
->reg_name
, (PTR
) regtab
);
1306 as_fatal (_("Internal Error: Can't hash %s: %s"),
1312 /* Fill in lexical tables: mnemonic_chars, operand_chars. */
1317 for (c
= 0; c
< 256; c
++)
1322 mnemonic_chars
[c
] = c
;
1323 register_chars
[c
] = c
;
1324 operand_chars
[c
] = c
;
1326 else if (ISLOWER (c
))
1328 mnemonic_chars
[c
] = c
;
1329 register_chars
[c
] = c
;
1330 operand_chars
[c
] = c
;
1332 else if (ISUPPER (c
))
1334 mnemonic_chars
[c
] = TOLOWER (c
);
1335 register_chars
[c
] = mnemonic_chars
[c
];
1336 operand_chars
[c
] = c
;
1339 if (ISALPHA (c
) || ISDIGIT (c
))
1340 identifier_chars
[c
] = c
;
1343 identifier_chars
[c
] = c
;
1344 operand_chars
[c
] = c
;
1349 identifier_chars
['@'] = '@';
1352 identifier_chars
['?'] = '?';
1353 operand_chars
['?'] = '?';
1355 digit_chars
['-'] = '-';
1356 mnemonic_chars
['-'] = '-';
1357 mnemonic_chars
['.'] = '.';
1358 identifier_chars
['_'] = '_';
1359 identifier_chars
['.'] = '.';
1361 for (p
= operand_special_chars
; *p
!= '\0'; p
++)
1362 operand_chars
[(unsigned char) *p
] = *p
;
1365 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
1368 record_alignment (text_section
, 2);
1369 record_alignment (data_section
, 2);
1370 record_alignment (bss_section
, 2);
1374 if (flag_code
== CODE_64BIT
)
1376 x86_dwarf2_return_column
= 16;
1377 x86_cie_data_alignment
= -8;
1381 x86_dwarf2_return_column
= 8;
1382 x86_cie_data_alignment
= -4;
1385 nativeclient_symbol_init();
1389 i386_print_statistics (FILE *file
)
1391 hash_print_statistics (file
, "i386 opcode", op_hash
);
1392 hash_print_statistics (file
, "i386 register", reg_hash
);
1397 /* Debugging routines for md_assemble. */
1398 static void pte (template *);
1399 static void pt (unsigned int);
1400 static void pe (expressionS
*);
1401 static void ps (symbolS
*);
1404 pi (char *line
, i386_insn
*x
)
1408 fprintf (stdout
, "%s: template ", line
);
1410 fprintf (stdout
, " address: base %s index %s scale %x\n",
1411 x
->base_reg
? x
->base_reg
->reg_name
: "none",
1412 x
->index_reg
? x
->index_reg
->reg_name
: "none",
1413 x
->log2_scale_factor
);
1414 fprintf (stdout
, " modrm: mode %x reg %x reg/mem %x\n",
1415 x
->rm
.mode
, x
->rm
.reg
, x
->rm
.regmem
);
1416 fprintf (stdout
, " sib: base %x index %x scale %x\n",
1417 x
->sib
.base
, x
->sib
.index
, x
->sib
.scale
);
1418 fprintf (stdout
, " rex: 64bit %x extX %x extY %x extZ %x\n",
1419 (x
->rex
& REX_W
) != 0,
1420 (x
->rex
& REX_R
) != 0,
1421 (x
->rex
& REX_X
) != 0,
1422 (x
->rex
& REX_B
) != 0);
1423 for (i
= 0; i
< x
->operands
; i
++)
1425 fprintf (stdout
, " #%d: ", i
+ 1);
1427 fprintf (stdout
, "\n");
1429 & (Reg
| SReg2
| SReg3
| Control
| Debug
| Test
| RegMMX
| RegXMM
))
1430 fprintf (stdout
, "%s\n", x
->op
[i
].regs
->reg_name
);
1431 if (x
->types
[i
] & Imm
)
1433 if (x
->types
[i
] & Disp
)
1434 pe (x
->op
[i
].disps
);
1442 fprintf (stdout
, " %d operands ", t
->operands
);
1443 fprintf (stdout
, "opcode %x ", t
->base_opcode
);
1444 if (t
->extension_opcode
!= None
)
1445 fprintf (stdout
, "ext %x ", t
->extension_opcode
);
1446 if (t
->opcode_modifier
& D
)
1447 fprintf (stdout
, "D");
1448 if (t
->opcode_modifier
& W
)
1449 fprintf (stdout
, "W");
1450 fprintf (stdout
, "\n");
1451 for (i
= 0; i
< t
->operands
; i
++)
1453 fprintf (stdout
, " #%d type ", i
+ 1);
1454 pt (t
->operand_types
[i
]);
1455 fprintf (stdout
, "\n");
1462 fprintf (stdout
, " operation %d\n", e
->X_op
);
1463 fprintf (stdout
, " add_number %ld (%lx)\n",
1464 (long) e
->X_add_number
, (long) e
->X_add_number
);
1465 if (e
->X_add_symbol
)
1467 fprintf (stdout
, " add_symbol ");
1468 ps (e
->X_add_symbol
);
1469 fprintf (stdout
, "\n");
1473 fprintf (stdout
, " op_symbol ");
1474 ps (e
->X_op_symbol
);
1475 fprintf (stdout
, "\n");
1482 fprintf (stdout
, "%s type %s%s",
1484 S_IS_EXTERNAL (s
) ? "EXTERNAL " : "",
1485 segment_name (S_GET_SEGMENT (s
)));
1488 static struct type_name
1493 const type_names
[] =
1506 { BaseIndex
, "BaseIndex" },
1510 { Disp32S
, "d32s" },
1512 { InOutPortReg
, "InOutPortReg" },
1513 { ShiftCount
, "ShiftCount" },
1514 { Control
, "control reg" },
1515 { Test
, "test reg" },
1516 { Debug
, "debug reg" },
1517 { FloatReg
, "FReg" },
1518 { FloatAcc
, "FAcc" },
1522 { JumpAbsolute
, "Jump Absolute" },
1533 const struct type_name
*ty
;
1535 for (ty
= type_names
; ty
->mask
; ty
++)
1537 fprintf (stdout
, "%s, ", ty
->tname
);
1541 #endif /* DEBUG386 */
1543 static bfd_reloc_code_real_type
1544 reloc (unsigned int size
,
1547 bfd_reloc_code_real_type other
)
1549 if (other
!= NO_RELOC
)
1551 reloc_howto_type
*reloc
;
1556 case BFD_RELOC_X86_64_GOT32
:
1557 return BFD_RELOC_X86_64_GOT64
;
1559 case BFD_RELOC_X86_64_PLTOFF64
:
1560 return BFD_RELOC_X86_64_PLTOFF64
;
1562 case BFD_RELOC_X86_64_GOTPC32
:
1563 other
= BFD_RELOC_X86_64_GOTPC64
;
1565 case BFD_RELOC_X86_64_GOTPCREL
:
1566 other
= BFD_RELOC_X86_64_GOTPCREL64
;
1568 case BFD_RELOC_X86_64_TPOFF32
:
1569 other
= BFD_RELOC_X86_64_TPOFF64
;
1571 case BFD_RELOC_X86_64_DTPOFF32
:
1572 other
= BFD_RELOC_X86_64_DTPOFF64
;
1578 /* Sign-checking 4-byte relocations in 16-/32-bit code is pointless. */
1579 if (size
== 4 && flag_code
!= CODE_64BIT
)
1582 reloc
= bfd_reloc_type_lookup (stdoutput
, other
);
1584 as_bad (_("unknown relocation (%u)"), other
);
1585 else if (size
!= bfd_get_reloc_size (reloc
))
1586 as_bad (_("%u-byte relocation cannot be applied to %u-byte field"),
1587 bfd_get_reloc_size (reloc
),
1589 else if (pcrel
&& !reloc
->pc_relative
)
1590 as_bad (_("non-pc-relative relocation for pc-relative field"));
1591 else if ((reloc
->complain_on_overflow
== complain_overflow_signed
1593 || (reloc
->complain_on_overflow
== complain_overflow_unsigned
1595 as_bad (_("relocated field and relocation type differ in signedness"));
1604 as_bad (_("there are no unsigned pc-relative relocations"));
1607 case 1: return BFD_RELOC_8_PCREL
;
1608 case 2: return BFD_RELOC_16_PCREL
;
1609 case 4: return BFD_RELOC_32_PCREL
;
1610 case 8: return BFD_RELOC_64_PCREL
;
1612 as_bad (_("cannot do %u byte pc-relative relocation"), size
);
1619 case 4: return BFD_RELOC_X86_64_32S
;
1624 case 1: return BFD_RELOC_8
;
1625 case 2: return BFD_RELOC_16
;
1626 case 4: return BFD_RELOC_32
;
1627 case 8: return BFD_RELOC_64
;
1629 as_bad (_("cannot do %s %u byte relocation"),
1630 sign
> 0 ? "signed" : "unsigned", size
);
1634 return BFD_RELOC_NONE
;
1637 /* Here we decide which fixups can be adjusted to make them relative to
1638 the beginning of the section instead of the symbol. Basically we need
1639 to make sure that the dynamic relocations are done correctly, so in
1640 some cases we force the original symbol to be used. */
1643 tc_i386_fix_adjustable (fixS
*fixP ATTRIBUTE_UNUSED
)
1645 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
1649 /* Don't adjust pc-relative references to merge sections in 64-bit
1651 if (use_rela_relocations
1652 && (S_GET_SEGMENT (fixP
->fx_addsy
)->flags
& SEC_MERGE
) != 0
1656 /* The x86_64 GOTPCREL are represented as 32bit PCrel relocations
1657 and changed later by validate_fix. */
1658 if (GOT_symbol
&& fixP
->fx_subsy
== GOT_symbol
1659 && fixP
->fx_r_type
== BFD_RELOC_32_PCREL
)
1662 /* adjust_reloc_syms doesn't know about the GOT. */
1663 if (fixP
->fx_r_type
== BFD_RELOC_386_GOTOFF
1664 || fixP
->fx_r_type
== BFD_RELOC_386_PLT32
1665 || fixP
->fx_r_type
== BFD_RELOC_386_GOT32
1666 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_GD
1667 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_LDM
1668 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_LDO_32
1669 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_IE_32
1670 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_IE
1671 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_GOTIE
1672 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_LE_32
1673 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_LE
1674 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_GOTDESC
1675 || fixP
->fx_r_type
== BFD_RELOC_386_TLS_DESC_CALL
1676 || fixP
->fx_r_type
== BFD_RELOC_X86_64_PLT32
1677 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOT32
1678 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOTPCREL
1679 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TLSGD
1680 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TLSLD
1681 || fixP
->fx_r_type
== BFD_RELOC_X86_64_DTPOFF32
1682 || fixP
->fx_r_type
== BFD_RELOC_X86_64_DTPOFF64
1683 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOTTPOFF
1684 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TPOFF32
1685 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TPOFF64
1686 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOTOFF64
1687 || fixP
->fx_r_type
== BFD_RELOC_X86_64_GOTPC32_TLSDESC
1688 || fixP
->fx_r_type
== BFD_RELOC_X86_64_TLSDESC_CALL
1689 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
1690 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1697 intel_float_operand (const char *mnemonic
)
1699 /* Note that the value returned is meaningful only for opcodes with (memory)
1700 operands, hence the code here is free to improperly handle opcodes that
1701 have no operands (for better performance and smaller code). */
1703 if (mnemonic
[0] != 'f')
1704 return 0; /* non-math */
1706 switch (mnemonic
[1])
1708 /* fclex, fdecstp, fdisi, femms, feni, fincstp, finit, fsetpm, and
1709 the fs segment override prefix not currently handled because no
1710 call path can make opcodes without operands get here */
1712 return 2 /* integer op */;
1714 if (mnemonic
[2] == 'd' && (mnemonic
[3] == 'c' || mnemonic
[3] == 'e'))
1715 return 3; /* fldcw/fldenv */
1718 if (mnemonic
[2] != 'o' /* fnop */)
1719 return 3; /* non-waiting control op */
1722 if (mnemonic
[2] == 's')
1723 return 3; /* frstor/frstpm */
1726 if (mnemonic
[2] == 'a')
1727 return 3; /* fsave */
1728 if (mnemonic
[2] == 't')
1730 switch (mnemonic
[3])
1732 case 'c': /* fstcw */
1733 case 'd': /* fstdw */
1734 case 'e': /* fstenv */
1735 case 's': /* fsts[gw] */
1741 if (mnemonic
[2] == 'r' || mnemonic
[2] == 's')
1742 return 0; /* fxsave/fxrstor are not really math ops */
1749 /* This is the guts of the machine-dependent assembler. LINE points to a
1750 machine dependent instruction. This function is supposed to emit
1751 the frags/bytes it assembles to. */
1758 char mnemonic
[MAX_MNEM_SIZE
];
1760 /* Initialize globals. */
1761 memset (&i
, '\0', sizeof (i
));
1762 for (j
= 0; j
< MAX_OPERANDS
; j
++)
1763 i
.reloc
[j
] = NO_RELOC
;
1764 memset (disp_expressions
, '\0', sizeof (disp_expressions
));
1765 memset (im_expressions
, '\0', sizeof (im_expressions
));
1766 save_stack_p
= save_stack
;
1768 /* First parse an instruction mnemonic & call i386_operand for the operands.
1769 We assume that the scrubber has arranged it so that line[0] is the valid
1770 start of a (possibly prefixed) mnemonic. */
1772 line
= parse_insn (line
, mnemonic
);
1776 line
= parse_operands (line
, mnemonic
);
1780 /* The order of the immediates should be reversed
1781 for 2 immediates extrq and insertq instructions */
1782 if ((i
.imm_operands
== 2)
1783 && ((strcmp (mnemonic
, "extrq") == 0)
1784 || (strcmp (mnemonic
, "insertq") == 0)))
1786 swap_2_operands (0, 1);
1787 /* "extrq" and insertq" are the only two instructions whose operands
1788 have to be reversed even though they have two immediate operands.
1794 /* Now we've parsed the mnemonic into a set of templates, and have the
1795 operands at hand. */
1797 /* All intel opcodes have reversed operands except for "bound" and
1798 "enter". We also don't reverse intersegment "jmp" and "call"
1799 instructions with 2 immediate operands so that the immediate segment
1800 precedes the offset, as it does when in AT&T mode. */
1803 && (strcmp (mnemonic
, "bound") != 0)
1804 && (strcmp (mnemonic
, "invlpga") != 0)
1805 && !((i
.types
[0] & Imm
) && (i
.types
[1] & Imm
)))
1811 /* Don't optimize displacement for movabs since it only takes 64bit
1814 && (flag_code
!= CODE_64BIT
1815 || strcmp (mnemonic
, "movabs") != 0))
1818 /* Next, we find a template that matches the given insn,
1819 making sure the overlap of the given operands types is consistent
1820 with the template operand types. */
1822 if (!match_template ())
1827 /* Undo SYSV386_COMPAT brokenness when in Intel mode. See i386.h */
1829 && (i
.tm
.base_opcode
& 0xfffffde0) == 0xdce0)
1830 i
.tm
.base_opcode
^= Opcode_FloatR
;
1832 /* Zap movzx and movsx suffix. The suffix may have been set from
1833 "word ptr" or "byte ptr" on the source operand, but we'll use
1834 the suffix later to choose the destination register. */
1835 if ((i
.tm
.base_opcode
& ~9) == 0x0fb6)
1837 if (i
.reg_operands
< 2
1839 && (~i
.tm
.opcode_modifier
1846 as_bad (_("ambiguous operand size for `%s'"), i
.tm
.name
);
1852 if (i
.tm
.opcode_modifier
& FWait
)
1853 if (!add_prefix (FWAIT_OPCODE
))
1856 /* Check string instruction segment overrides. */
1857 if ((i
.tm
.opcode_modifier
& IsString
) != 0 && i
.mem_operands
!= 0)
1859 if (!check_string ())
1863 if (!process_suffix ())
1866 /* Make still unresolved immediate matches conform to size of immediate
1867 given in i.suffix. */
1868 if (!finalize_imm ())
1871 if (i
.types
[0] & Imm1
)
1872 i
.imm_operands
= 0; /* kludge for shift insns. */
1873 if (i
.types
[0] & ImplicitRegister
)
1875 if (i
.types
[1] & ImplicitRegister
)
1877 if (i
.types
[2] & ImplicitRegister
)
1880 if (i
.tm
.opcode_modifier
& ImmExt
)
1884 if ((i
.tm
.cpu_flags
& CpuSSE3
) && i
.operands
> 0)
1886 /* Streaming SIMD extensions 3 Instructions have the fixed
1887 operands with an opcode suffix which is coded in the same
1888 place as an 8-bit immediate field would be. Here we check
1889 those operands and remove them afterwards. */
1892 for (x
= 0; x
< i
.operands
; x
++)
1893 if (i
.op
[x
].regs
->reg_num
!= x
)
1894 as_bad (_("can't use register '%s%s' as operand %d in '%s'."),
1896 i
.op
[x
].regs
->reg_name
,
1902 /* These AMD 3DNow! and Intel Katmai New Instructions have an
1903 opcode suffix which is coded in the same place as an 8-bit
1904 immediate field would be. Here we fake an 8-bit immediate
1905 operand from the opcode suffix stored in tm.extension_opcode. */
1907 assert (i
.imm_operands
== 0 && i
.operands
<= 2 && 2 < MAX_OPERANDS
);
1909 exp
= &im_expressions
[i
.imm_operands
++];
1910 i
.op
[i
.operands
].imms
= exp
;
1911 i
.types
[i
.operands
++] = Imm8
;
1912 exp
->X_op
= O_constant
;
1913 exp
->X_add_number
= i
.tm
.extension_opcode
;
1914 i
.tm
.extension_opcode
= None
;
1917 /* For insns with operands there are more diddles to do to the opcode. */
1920 if (!process_operands ())
1923 else if (!quiet_warnings
&& (i
.tm
.opcode_modifier
& Ugh
) != 0)
1925 /* UnixWare fsub no args is alias for fsubp, fadd -> faddp, etc. */
1926 as_warn (_("translating to `%sp'"), i
.tm
.name
);
1929 /* Handle conversion of 'int $3' --> special int3 insn. */
1930 if (i
.tm
.base_opcode
== INT_OPCODE
&& i
.op
[0].imms
->X_add_number
== 3)
1932 i
.tm
.base_opcode
= INT3_OPCODE
;
1936 if ((i
.tm
.opcode_modifier
& (Jump
| JumpByte
| JumpDword
))
1937 && i
.op
[0].disps
->X_op
== O_constant
)
1939 /* Convert "jmp constant" (and "call constant") to a jump (call) to
1940 the absolute address given by the constant. Since ix86 jumps and
1941 calls are pc relative, we need to generate a reloc. */
1942 i
.op
[0].disps
->X_add_symbol
= &abs_symbol
;
1943 i
.op
[0].disps
->X_op
= O_symbol
;
1946 if ((i
.tm
.opcode_modifier
& Rex64
) != 0)
1949 /* For 8 bit registers we need an empty rex prefix. Also if the
1950 instruction already has a prefix, we need to convert old
1951 registers to new ones. */
1953 if (((i
.types
[0] & Reg8
) != 0
1954 && (i
.op
[0].regs
->reg_flags
& RegRex64
) != 0)
1955 || ((i
.types
[1] & Reg8
) != 0
1956 && (i
.op
[1].regs
->reg_flags
& RegRex64
) != 0)
1957 || (((i
.types
[0] & Reg8
) != 0 || (i
.types
[1] & Reg8
) != 0)
1962 i
.rex
|= REX_OPCODE
;
1963 for (x
= 0; x
< 2; x
++)
1965 /* Look for 8 bit operand that uses old registers. */
1966 if ((i
.types
[x
] & Reg8
) != 0
1967 && (i
.op
[x
].regs
->reg_flags
& RegRex64
) == 0)
1969 /* In case it is "hi" register, give up. */
1970 if (i
.op
[x
].regs
->reg_num
> 3)
1971 as_bad (_("can't encode register '%s%s' in an "
1972 "instruction requiring REX prefix."),
1973 register_prefix
, i
.op
[x
].regs
->reg_name
);
1975 /* Otherwise it is equivalent to the extended register.
1976 Since the encoding doesn't change this is merely
1977 cosmetic cleanup for debug output. */
1979 i
.op
[x
].regs
= i
.op
[x
].regs
+ 8;
1985 add_prefix (REX_OPCODE
| i
.rex
);
1987 /* We are ready to output the insn. */
1992 parse_insn (char *line
, char *mnemonic
)
1995 char *token_start
= l
;
2000 /* Non-zero if we found a prefix only acceptable with string insns. */
2001 const char *expecting_string_instruction
= NULL
;
2006 while ((*mnem_p
= mnemonic_chars
[(unsigned char) *l
]) != 0)
2009 if (mnem_p
>= mnemonic
+ MAX_MNEM_SIZE
)
2011 as_bad (_("no such instruction: `%s'"), token_start
);
2016 if (!is_space_char (*l
)
2017 && *l
!= END_OF_INSN
2019 || (*l
!= PREFIX_SEPARATOR
2022 as_bad (_("invalid character %s in mnemonic"),
2023 output_invalid (*l
));
2026 if (token_start
== l
)
2028 if (!intel_syntax
&& *l
== PREFIX_SEPARATOR
)
2029 as_bad (_("expecting prefix; got nothing"));
2031 as_bad (_("expecting mnemonic; got nothing"));
2035 /* Look up instruction (or prefix) via hash table. */
2036 current_templates
= hash_find (op_hash
, mnemonic
);
2038 if (*l
!= END_OF_INSN
2039 && (!is_space_char (*l
) || l
[1] != END_OF_INSN
)
2040 && current_templates
2041 && (current_templates
->start
->opcode_modifier
& IsPrefix
))
2043 if (current_templates
->start
->cpu_flags
2044 & (flag_code
!= CODE_64BIT
? Cpu64
: CpuNo64
))
2046 as_bad ((flag_code
!= CODE_64BIT
2047 ? _("`%s' is only supported in 64-bit mode")
2048 : _("`%s' is not supported in 64-bit mode")),
2049 current_templates
->start
->name
);
2052 /* If we are in 16-bit mode, do not allow addr16 or data16.
2053 Similarly, in 32-bit mode, do not allow addr32 or data32. */
2054 if ((current_templates
->start
->opcode_modifier
& (Size16
| Size32
))
2055 && flag_code
!= CODE_64BIT
2056 && (((current_templates
->start
->opcode_modifier
& Size32
) != 0)
2057 ^ (flag_code
== CODE_16BIT
)))
2059 as_bad (_("redundant %s prefix"),
2060 current_templates
->start
->name
);
2063 /* Add prefix, checking for repeated prefixes. */
2064 switch (add_prefix (current_templates
->start
->base_opcode
))
2069 expecting_string_instruction
= current_templates
->start
->name
;
2072 /* Skip past PREFIX_SEPARATOR and reset token_start. */
2079 if (!current_templates
)
2081 /* See if we can get a match by trimming off a suffix. */
2084 case WORD_MNEM_SUFFIX
:
2085 if (intel_syntax
&& (intel_float_operand (mnemonic
) & 2))
2086 i
.suffix
= SHORT_MNEM_SUFFIX
;
2088 case BYTE_MNEM_SUFFIX
:
2089 case QWORD_MNEM_SUFFIX
:
2090 i
.suffix
= mnem_p
[-1];
2092 current_templates
= hash_find (op_hash
, mnemonic
);
2094 case SHORT_MNEM_SUFFIX
:
2095 case LONG_MNEM_SUFFIX
:
2098 i
.suffix
= mnem_p
[-1];
2100 current_templates
= hash_find (op_hash
, mnemonic
);
2108 if (intel_float_operand (mnemonic
) == 1)
2109 i
.suffix
= SHORT_MNEM_SUFFIX
;
2111 i
.suffix
= LONG_MNEM_SUFFIX
;
2113 current_templates
= hash_find (op_hash
, mnemonic
);
2117 if (!current_templates
)
2119 as_bad (_("no such instruction: `%s'"), token_start
);
2124 if (current_templates
->start
->opcode_modifier
& (Jump
| JumpByte
))
2126 /* Check for a branch hint. We allow ",pt" and ",pn" for
2127 predict taken and predict not taken respectively.
2128 I'm not sure that branch hints actually do anything on loop
2129 and jcxz insns (JumpByte) for current Pentium4 chips. They
2130 may work in the future and it doesn't hurt to accept them
2132 if (l
[0] == ',' && l
[1] == 'p')
2136 if (!add_prefix (DS_PREFIX_OPCODE
))
2140 else if (l
[2] == 'n')
2142 if (!add_prefix (CS_PREFIX_OPCODE
))
2148 /* Any other comma loses. */
2151 as_bad (_("invalid character %s in mnemonic"),
2152 output_invalid (*l
));
2156 /* Check if instruction is supported on specified architecture. */
2158 for (t
= current_templates
->start
; t
< current_templates
->end
; ++t
)
2160 if (!((t
->cpu_flags
& ~(Cpu64
| CpuNo64
))
2161 & ~(cpu_arch_flags
& ~(Cpu64
| CpuNo64
))))
2163 if (!(t
->cpu_flags
& (flag_code
== CODE_64BIT
? CpuNo64
: Cpu64
)))
2166 if (!(supported
& 2))
2168 as_bad (flag_code
== CODE_64BIT
2169 ? _("`%s' is not supported in 64-bit mode")
2170 : _("`%s' is only supported in 64-bit mode"),
2171 current_templates
->start
->name
);
2174 if (!(supported
& 1))
2176 as_warn (_("`%s' is not supported on `%s%s'"),
2177 current_templates
->start
->name
,
2179 cpu_sub_arch_name
? cpu_sub_arch_name
: "");
2181 else if ((Cpu386
& ~cpu_arch_flags
) && (flag_code
!= CODE_16BIT
))
2183 as_warn (_("use .code16 to ensure correct addressing mode"));
2186 /* Check for rep/repne without a string instruction. */
2187 if (expecting_string_instruction
)
2189 static templates override
;
2191 for (t
= current_templates
->start
; t
< current_templates
->end
; ++t
)
2192 if (t
->opcode_modifier
& IsString
)
2194 if (t
>= current_templates
->end
)
2196 as_bad (_("expecting string instruction after `%s'"),
2197 expecting_string_instruction
);
2200 for (override
.start
= t
; t
< current_templates
->end
; ++t
)
2201 if (!(t
->opcode_modifier
& IsString
))
2204 current_templates
= &override
;
2211 parse_operands (char *l
, const char *mnemonic
)
2215 /* 1 if operand is pending after ','. */
2216 unsigned int expecting_operand
= 0;
2218 /* Non-zero if operand parens not balanced. */
2219 unsigned int paren_not_balanced
;
2221 while (*l
!= END_OF_INSN
)
2223 /* Skip optional white space before operand. */
2224 if (is_space_char (*l
))
2226 if (!is_operand_char (*l
) && *l
!= END_OF_INSN
)
2228 as_bad (_("invalid character %s before operand %d"),
2229 output_invalid (*l
),
2233 token_start
= l
; /* after white space */
2234 paren_not_balanced
= 0;
2235 while (paren_not_balanced
|| *l
!= ',')
2237 if (*l
== END_OF_INSN
)
2239 if (paren_not_balanced
)
2242 as_bad (_("unbalanced parenthesis in operand %d."),
2245 as_bad (_("unbalanced brackets in operand %d."),
2250 break; /* we are done */
2252 else if (!is_operand_char (*l
) && !is_space_char (*l
))
2254 as_bad (_("invalid character %s in operand %d"),
2255 output_invalid (*l
),
2262 ++paren_not_balanced
;
2264 --paren_not_balanced
;
2269 ++paren_not_balanced
;
2271 --paren_not_balanced
;
2275 if (l
!= token_start
)
2276 { /* Yes, we've read in another operand. */
2277 unsigned int operand_ok
;
2278 this_operand
= i
.operands
++;
2279 if (i
.operands
> MAX_OPERANDS
)
2281 as_bad (_("spurious operands; (%d operands/instruction max)"),
2285 /* Now parse operand adding info to 'i' as we go along. */
2286 END_STRING_AND_SAVE (l
);
2290 i386_intel_operand (token_start
,
2291 intel_float_operand (mnemonic
));
2293 operand_ok
= i386_operand (token_start
);
2295 RESTORE_END_STRING (l
);
2301 if (expecting_operand
)
2303 expecting_operand_after_comma
:
2304 as_bad (_("expecting operand after ','; got nothing"));
2309 as_bad (_("expecting operand before ','; got nothing"));
2314 /* Now *l must be either ',' or END_OF_INSN. */
2317 if (*++l
== END_OF_INSN
)
2319 /* Just skip it, if it's \n complain. */
2320 goto expecting_operand_after_comma
;
2322 expecting_operand
= 1;
2329 swap_2_operands (int xchg1
, int xchg2
)
2331 union i386_op temp_op
;
2332 unsigned int temp_type
;
2333 enum bfd_reloc_code_real temp_reloc
;
2335 temp_type
= i
.types
[xchg2
];
2336 i
.types
[xchg2
] = i
.types
[xchg1
];
2337 i
.types
[xchg1
] = temp_type
;
2338 temp_op
= i
.op
[xchg2
];
2339 i
.op
[xchg2
] = i
.op
[xchg1
];
2340 i
.op
[xchg1
] = temp_op
;
2341 temp_reloc
= i
.reloc
[xchg2
];
2342 i
.reloc
[xchg2
] = i
.reloc
[xchg1
];
2343 i
.reloc
[xchg1
] = temp_reloc
;
2347 swap_operands (void)
2352 swap_2_operands (1, i
.operands
- 2);
2355 swap_2_operands (0, i
.operands
- 1);
2361 if (i
.mem_operands
== 2)
2363 const seg_entry
*temp_seg
;
2364 temp_seg
= i
.seg
[0];
2365 i
.seg
[0] = i
.seg
[1];
2366 i
.seg
[1] = temp_seg
;
2370 /* Try to ensure constant immediates are represented in the smallest
2375 char guess_suffix
= 0;
2379 guess_suffix
= i
.suffix
;
2380 else if (i
.reg_operands
)
2382 /* Figure out a suffix from the last register operand specified.
2383 We can't do this properly yet, ie. excluding InOutPortReg,
2384 but the following works for instructions with immediates.
2385 In any case, we can't set i.suffix yet. */
2386 for (op
= i
.operands
; --op
>= 0;)
2387 if (i
.types
[op
] & Reg
)
2389 if (i
.types
[op
] & Reg8
)
2390 guess_suffix
= BYTE_MNEM_SUFFIX
;
2391 else if (i
.types
[op
] & Reg16
)
2392 guess_suffix
= WORD_MNEM_SUFFIX
;
2393 else if (i
.types
[op
] & Reg32
)
2394 guess_suffix
= LONG_MNEM_SUFFIX
;
2395 else if (i
.types
[op
] & Reg64
)
2396 guess_suffix
= QWORD_MNEM_SUFFIX
;
2400 else if ((flag_code
== CODE_16BIT
) ^ (i
.prefix
[DATA_PREFIX
] != 0))
2401 guess_suffix
= WORD_MNEM_SUFFIX
;
2403 for (op
= i
.operands
; --op
>= 0;)
2404 if (i
.types
[op
] & Imm
)
2406 switch (i
.op
[op
].imms
->X_op
)
2409 /* If a suffix is given, this operand may be shortened. */
2410 switch (guess_suffix
)
2412 case LONG_MNEM_SUFFIX
:
2413 i
.types
[op
] |= Imm32
| Imm64
;
2415 case WORD_MNEM_SUFFIX
:
2416 i
.types
[op
] |= Imm16
| Imm32S
| Imm32
| Imm64
;
2418 case BYTE_MNEM_SUFFIX
:
2419 i
.types
[op
] |= Imm16
| Imm8
| Imm8S
| Imm32S
| Imm32
| Imm64
;
2423 /* If this operand is at most 16 bits, convert it
2424 to a signed 16 bit number before trying to see
2425 whether it will fit in an even smaller size.
2426 This allows a 16-bit operand such as $0xffe0 to
2427 be recognised as within Imm8S range. */
2428 if ((i
.types
[op
] & Imm16
)
2429 && (i
.op
[op
].imms
->X_add_number
& ~(offsetT
) 0xffff) == 0)
2431 i
.op
[op
].imms
->X_add_number
=
2432 (((i
.op
[op
].imms
->X_add_number
& 0xffff) ^ 0x8000) - 0x8000);
2434 if ((i
.types
[op
] & Imm32
)
2435 && ((i
.op
[op
].imms
->X_add_number
& ~(((offsetT
) 2 << 31) - 1))
2438 i
.op
[op
].imms
->X_add_number
= ((i
.op
[op
].imms
->X_add_number
2439 ^ ((offsetT
) 1 << 31))
2440 - ((offsetT
) 1 << 31));
2442 i
.types
[op
] |= smallest_imm_type (i
.op
[op
].imms
->X_add_number
);
2444 /* We must avoid matching of Imm32 templates when 64bit
2445 only immediate is available. */
2446 if (guess_suffix
== QWORD_MNEM_SUFFIX
)
2447 i
.types
[op
] &= ~Imm32
;
2454 /* Symbols and expressions. */
2456 /* Convert symbolic operand to proper sizes for matching, but don't
2457 prevent matching a set of insns that only supports sizes other
2458 than those matching the insn suffix. */
2460 unsigned int mask
, allowed
= 0;
2463 for (t
= current_templates
->start
;
2464 t
< current_templates
->end
;
2466 allowed
|= t
->operand_types
[op
];
2467 switch (guess_suffix
)
2469 case QWORD_MNEM_SUFFIX
:
2470 mask
= Imm64
| Imm32S
;
2472 case LONG_MNEM_SUFFIX
:
2475 case WORD_MNEM_SUFFIX
:
2478 case BYTE_MNEM_SUFFIX
:
2486 i
.types
[op
] &= mask
;
2493 /* Try to use the smallest displacement type too. */
2495 optimize_disp (void)
2499 for (op
= i
.operands
; --op
>= 0;)
2500 if (i
.types
[op
] & Disp
)
2502 if (i
.op
[op
].disps
->X_op
== O_constant
)
2504 offsetT disp
= i
.op
[op
].disps
->X_add_number
;
2506 if ((i
.types
[op
] & Disp16
)
2507 && (disp
& ~(offsetT
) 0xffff) == 0)
2509 /* If this operand is at most 16 bits, convert
2510 to a signed 16 bit number and don't use 64bit
2512 disp
= (((disp
& 0xffff) ^ 0x8000) - 0x8000);
2513 i
.types
[op
] &= ~Disp64
;
2515 if ((i
.types
[op
] & Disp32
)
2516 && (disp
& ~(((offsetT
) 2 << 31) - 1)) == 0)
2518 /* If this operand is at most 32 bits, convert
2519 to a signed 32 bit number and don't use 64bit
2521 disp
&= (((offsetT
) 2 << 31) - 1);
2522 disp
= (disp
^ ((offsetT
) 1 << 31)) - ((addressT
) 1 << 31);
2523 i
.types
[op
] &= ~Disp64
;
2525 if (!disp
&& (i
.types
[op
] & BaseIndex
))
2527 i
.types
[op
] &= ~Disp
;
2531 else if (flag_code
== CODE_64BIT
)
2533 if (fits_in_signed_long (disp
))
2535 i
.types
[op
] &= ~Disp64
;
2536 i
.types
[op
] |= Disp32S
;
2538 if (fits_in_unsigned_long (disp
))
2539 i
.types
[op
] |= Disp32
;
2541 if ((i
.types
[op
] & (Disp32
| Disp32S
| Disp16
))
2542 && fits_in_signed_byte (disp
))
2543 i
.types
[op
] |= Disp8
;
2545 else if (i
.reloc
[op
] == BFD_RELOC_386_TLS_DESC_CALL
2546 || i
.reloc
[op
] == BFD_RELOC_X86_64_TLSDESC_CALL
)
2548 fix_new_exp (frag_now
, frag_more (0) - frag_now
->fr_literal
, 0,
2549 i
.op
[op
].disps
, 0, i
.reloc
[op
]);
2550 i
.types
[op
] &= ~Disp
;
2553 /* We only support 64bit displacement on constants. */
2554 i
.types
[op
] &= ~Disp64
;
2559 match_template (void)
2561 /* Points to template once we've found it. */
2563 unsigned int overlap0
, overlap1
, overlap2
, overlap3
;
2564 unsigned int found_reverse_match
;
2566 unsigned int operand_types
[MAX_OPERANDS
];
2567 int addr_prefix_disp
;
2570 #if MAX_OPERANDS != 4
2571 # error "MAX_OPERANDS must be 4."
2574 #define MATCH(overlap, given, template) \
2575 ((overlap & ~JumpAbsolute) \
2576 && (((given) & (BaseIndex | JumpAbsolute)) \
2577 == ((overlap) & (BaseIndex | JumpAbsolute))))
2579 /* If given types r0 and r1 are registers they must be of the same type
2580 unless the expected operand type register overlap is null.
2581 Note that Acc in a template matches every size of reg. */
2582 #define CONSISTENT_REGISTER_MATCH(m0, g0, t0, m1, g1, t1) \
2583 (((g0) & Reg) == 0 || ((g1) & Reg) == 0 \
2584 || ((g0) & Reg) == ((g1) & Reg) \
2585 || ((((m0) & Acc) ? Reg : (t0)) & (((m1) & Acc) ? Reg : (t1)) & Reg) == 0 )
2591 found_reverse_match
= 0;
2592 for (j
= 0; j
< MAX_OPERANDS
; j
++)
2593 operand_types
[j
] = 0;
2594 addr_prefix_disp
= -1;
2595 suffix_check
= (i
.suffix
== BYTE_MNEM_SUFFIX
2597 : (i
.suffix
== WORD_MNEM_SUFFIX
2599 : (i
.suffix
== SHORT_MNEM_SUFFIX
2601 : (i
.suffix
== LONG_MNEM_SUFFIX
2603 : (i
.suffix
== QWORD_MNEM_SUFFIX
2605 : (i
.suffix
== LONG_DOUBLE_MNEM_SUFFIX
2606 ? No_xSuf
: 0))))));
2608 for (t
= current_templates
->start
; t
< current_templates
->end
; t
++)
2610 addr_prefix_disp
= -1;
2612 /* Must have right number of operands. */
2613 if (i
.operands
!= t
->operands
)
2616 /* Check the suffix, except for some instructions in intel mode. */
2617 if ((t
->opcode_modifier
& suffix_check
)
2619 && (t
->opcode_modifier
& IgnoreSize
)))
2622 for (j
= 0; j
< MAX_OPERANDS
; j
++)
2623 operand_types
[j
] = t
->operand_types
[j
];
2625 /* In general, don't allow 64-bit operands in 32-bit mode. */
2626 if (i
.suffix
== QWORD_MNEM_SUFFIX
2627 && flag_code
!= CODE_64BIT
2629 ? (!(t
->opcode_modifier
& IgnoreSize
)
2630 && !intel_float_operand (t
->name
))
2631 : intel_float_operand (t
->name
) != 2)
2632 && (!(operand_types
[0] & (RegMMX
| RegXMM
))
2633 || !(operand_types
[t
->operands
> 1] & (RegMMX
| RegXMM
)))
2634 && (t
->base_opcode
!= 0x0fc7
2635 || t
->extension_opcode
!= 1 /* cmpxchg8b */))
2638 /* Do not verify operands when there are none. */
2639 else if (!t
->operands
)
2641 if (t
->cpu_flags
& ~cpu_arch_flags
)
2643 /* We've found a match; break out of loop. */
2647 /* Address size prefix will turn Disp64/Disp32/Disp16 operand
2648 into Disp32/Disp16/Disp32 operand. */
2649 if (i
.prefix
[ADDR_PREFIX
] != 0)
2651 unsigned int DispOn
= 0, DispOff
= 0;
2669 for (j
= 0; j
< MAX_OPERANDS
; j
++)
2671 /* There should be only one Disp operand. */
2672 if ((operand_types
[j
] & DispOff
))
2674 addr_prefix_disp
= j
;
2675 operand_types
[j
] |= DispOn
;
2676 operand_types
[j
] &= ~DispOff
;
2682 overlap0
= i
.types
[0] & operand_types
[0];
2683 switch (t
->operands
)
2686 if (!MATCH (overlap0
, i
.types
[0], operand_types
[0]))
2690 /* xchg %eax, %eax is a special case. It is an aliase for nop
2691 only in 32bit mode and we can use opcode 0x90. In 64bit
2692 mode, we can't use 0x90 for xchg %eax, %eax since it should
2693 zero-extend %eax to %rax. */
2694 if (flag_code
== CODE_64BIT
2695 && t
->base_opcode
== 0x90
2696 && i
.types
[0] == (Acc
| Reg32
)
2697 && i
.types
[1] == (Acc
| Reg32
))
2701 overlap1
= i
.types
[1] & operand_types
[1];
2702 if (!MATCH (overlap0
, i
.types
[0], operand_types
[0])
2703 || !MATCH (overlap1
, i
.types
[1], operand_types
[1])
2704 /* monitor in SSE3 is a very special case. The first
2705 register and the second register may have different
2706 sizes. The same applies to crc32 in SSE4.2. */
2707 || !((t
->base_opcode
== 0x0f01
2708 && t
->extension_opcode
== 0xc8)
2709 || t
->base_opcode
== 0xf20f38f1
2710 || CONSISTENT_REGISTER_MATCH (overlap0
, i
.types
[0],
2712 overlap1
, i
.types
[1],
2715 /* Check if other direction is valid ... */
2716 if ((t
->opcode_modifier
& (D
| FloatD
)) == 0)
2719 /* Try reversing direction of operands. */
2720 overlap0
= i
.types
[0] & operand_types
[1];
2721 overlap1
= i
.types
[1] & operand_types
[0];
2722 if (!MATCH (overlap0
, i
.types
[0], operand_types
[1])
2723 || !MATCH (overlap1
, i
.types
[1], operand_types
[0])
2724 || !CONSISTENT_REGISTER_MATCH (overlap0
, i
.types
[0],
2726 overlap1
, i
.types
[1],
2729 /* Does not match either direction. */
2732 /* found_reverse_match holds which of D or FloatDR
2734 if ((t
->opcode_modifier
& D
))
2735 found_reverse_match
= Opcode_D
;
2736 else if ((t
->opcode_modifier
& FloatD
))
2737 found_reverse_match
= Opcode_FloatD
;
2739 found_reverse_match
= 0;
2740 if ((t
->opcode_modifier
& FloatR
))
2741 found_reverse_match
|= Opcode_FloatR
;
2745 /* Found a forward 2 operand match here. */
2746 switch (t
->operands
)
2749 overlap3
= i
.types
[3] & operand_types
[3];
2751 overlap2
= i
.types
[2] & operand_types
[2];
2755 switch (t
->operands
)
2758 if (!MATCH (overlap3
, i
.types
[3], operand_types
[3])
2759 || !CONSISTENT_REGISTER_MATCH (overlap2
,
2767 /* Here we make use of the fact that there are no
2768 reverse match 3 operand instructions, and all 3
2769 operand instructions only need to be checked for
2770 register consistency between operands 2 and 3. */
2771 if (!MATCH (overlap2
, i
.types
[2], operand_types
[2])
2772 || !CONSISTENT_REGISTER_MATCH (overlap1
,
2782 /* Found either forward/reverse 2, 3 or 4 operand match here:
2783 slip through to break. */
2785 if (t
->cpu_flags
& ~cpu_arch_flags
)
2787 found_reverse_match
= 0;
2790 /* We've found a match; break out of loop. */
2794 if (t
== current_templates
->end
)
2796 /* We found no match. */
2797 as_bad (_("suffix or operands invalid for `%s'"),
2798 current_templates
->start
->name
);
2802 if (!quiet_warnings
)
2805 && ((i
.types
[0] & JumpAbsolute
)
2806 != (operand_types
[0] & JumpAbsolute
)))
2808 as_warn (_("indirect %s without `*'"), t
->name
);
2811 if ((t
->opcode_modifier
& (IsPrefix
| IgnoreSize
))
2812 == (IsPrefix
| IgnoreSize
))
2814 /* Warn them that a data or address size prefix doesn't
2815 affect assembly of the next line of code. */
2816 as_warn (_("stand-alone `%s' prefix"), t
->name
);
2820 /* Copy the template we found. */
2823 if (addr_prefix_disp
!= -1)
2824 i
.tm
.operand_types
[addr_prefix_disp
]
2825 = operand_types
[addr_prefix_disp
];
2827 if (found_reverse_match
)
2829 /* If we found a reverse match we must alter the opcode
2830 direction bit. found_reverse_match holds bits to change
2831 (different for int & float insns). */
2833 i
.tm
.base_opcode
^= found_reverse_match
;
2835 i
.tm
.operand_types
[0] = operand_types
[1];
2836 i
.tm
.operand_types
[1] = operand_types
[0];
2845 int mem_op
= (i
.types
[0] & AnyMem
) ? 0 : 1;
2846 if ((i
.tm
.operand_types
[mem_op
] & EsSeg
) != 0)
2848 if (i
.seg
[0] != NULL
&& i
.seg
[0] != &es
)
2850 as_bad (_("`%s' operand %d must use `%%es' segment"),
2855 /* There's only ever one segment override allowed per instruction.
2856 This instruction possibly has a legal segment override on the
2857 second operand, so copy the segment to where non-string
2858 instructions store it, allowing common code. */
2859 i
.seg
[0] = i
.seg
[1];
2861 else if ((i
.tm
.operand_types
[mem_op
+ 1] & EsSeg
) != 0)
2863 if (i
.seg
[1] != NULL
&& i
.seg
[1] != &es
)
2865 as_bad (_("`%s' operand %d must use `%%es' segment"),
2875 process_suffix (void)
2877 /* If matched instruction specifies an explicit instruction mnemonic
2879 if (i
.tm
.opcode_modifier
& (Size16
| Size32
| Size64
))
2881 if (i
.tm
.opcode_modifier
& Size16
)
2882 i
.suffix
= WORD_MNEM_SUFFIX
;
2883 else if (i
.tm
.opcode_modifier
& Size64
)
2884 i
.suffix
= QWORD_MNEM_SUFFIX
;
2886 i
.suffix
= LONG_MNEM_SUFFIX
;
2888 else if (i
.reg_operands
)
2890 /* If there's no instruction mnemonic suffix we try to invent one
2891 based on register operands. */
2894 /* We take i.suffix from the last register operand specified,
2895 Destination register type is more significant than source
2896 register type. crc32 in SSE4.2 prefers source register
2898 if (i
.tm
.base_opcode
== 0xf20f38f1)
2900 if ((i
.types
[0] & Reg
))
2901 i
.suffix
= ((i
.types
[0] & Reg16
) ? WORD_MNEM_SUFFIX
:
2904 else if (i
.tm
.base_opcode
== 0xf20f38f0)
2906 if ((i
.types
[0] & Reg8
))
2907 i
.suffix
= BYTE_MNEM_SUFFIX
;
2914 if (i
.tm
.base_opcode
== 0xf20f38f1
2915 || i
.tm
.base_opcode
== 0xf20f38f0)
2917 /* We have to know the operand size for crc32. */
2918 as_bad (_("ambiguous memory operand size for `%s`"),
2923 for (op
= i
.operands
; --op
>= 0;)
2924 if ((i
.types
[op
] & Reg
)
2925 && !(i
.tm
.operand_types
[op
] & InOutPortReg
))
2927 i
.suffix
= ((i
.types
[op
] & Reg8
) ? BYTE_MNEM_SUFFIX
:
2928 (i
.types
[op
] & Reg16
) ? WORD_MNEM_SUFFIX
:
2929 (i
.types
[op
] & Reg64
) ? QWORD_MNEM_SUFFIX
:
2935 else if (i
.suffix
== BYTE_MNEM_SUFFIX
)
2937 if (!check_byte_reg ())
2940 else if (i
.suffix
== LONG_MNEM_SUFFIX
)
2942 if (!check_long_reg ())
2945 else if (i
.suffix
== QWORD_MNEM_SUFFIX
)
2947 if (!check_qword_reg ())
2950 else if (i
.suffix
== WORD_MNEM_SUFFIX
)
2952 if (!check_word_reg ())
2955 else if (intel_syntax
&& (i
.tm
.opcode_modifier
& IgnoreSize
))
2956 /* Do nothing if the instruction is going to ignore the prefix. */
2961 else if ((i
.tm
.opcode_modifier
& DefaultSize
)
2963 /* exclude fldenv/frstor/fsave/fstenv */
2964 && (i
.tm
.opcode_modifier
& No_sSuf
))
2966 i
.suffix
= stackop_size
;
2968 else if (intel_syntax
2970 && ((i
.tm
.operand_types
[0] & JumpAbsolute
)
2971 || (i
.tm
.opcode_modifier
& (JumpByte
|JumpInterSegment
))
2972 || (i
.tm
.base_opcode
== 0x0f01 /* [ls][gi]dt */
2973 && i
.tm
.extension_opcode
<= 3)))
2978 if (!(i
.tm
.opcode_modifier
& No_qSuf
))
2980 i
.suffix
= QWORD_MNEM_SUFFIX
;
2984 if (!(i
.tm
.opcode_modifier
& No_lSuf
))
2985 i
.suffix
= LONG_MNEM_SUFFIX
;
2988 if (!(i
.tm
.opcode_modifier
& No_wSuf
))
2989 i
.suffix
= WORD_MNEM_SUFFIX
;
2998 if (i
.tm
.opcode_modifier
& W
)
3000 as_bad (_("no instruction mnemonic suffix given and "
3001 "no register operands; can't size instruction"));
3007 unsigned int suffixes
= (~i
.tm
.opcode_modifier
3015 if ((i
.tm
.opcode_modifier
& W
)
3016 || ((suffixes
& (suffixes
- 1))
3017 && !(i
.tm
.opcode_modifier
& (DefaultSize
| IgnoreSize
))))
3019 as_bad (_("ambiguous operand size for `%s'"), i
.tm
.name
);
3025 /* Change the opcode based on the operand size given by i.suffix;
3026 We don't need to change things for byte insns. */
3028 if (i
.suffix
&& i
.suffix
!= BYTE_MNEM_SUFFIX
)
3030 /* It's not a byte, select word/dword operation. */
3031 if (i
.tm
.opcode_modifier
& W
)
3033 if (i
.tm
.opcode_modifier
& ShortForm
)
3034 i
.tm
.base_opcode
|= 8;
3036 i
.tm
.base_opcode
|= 1;
3039 /* Now select between word & dword operations via the operand
3040 size prefix, except for instructions that will ignore this
3042 if (i
.tm
.base_opcode
== 0x0f01 && i
.tm
.extension_opcode
== 0xc8)
3044 /* monitor in SSE3 is a very special case. The default size
3045 of AX is the size of mode. The address size override
3046 prefix will change the size of AX. */
3047 if (i
.op
->regs
[0].reg_type
&
3048 (flag_code
== CODE_32BIT
? Reg16
: Reg32
))
3049 if (!add_prefix (ADDR_PREFIX_OPCODE
))
3052 else if (i
.suffix
!= QWORD_MNEM_SUFFIX
3053 && i
.suffix
!= LONG_DOUBLE_MNEM_SUFFIX
3054 && !(i
.tm
.opcode_modifier
& (IgnoreSize
| FloatMF
))
3055 && ((i
.suffix
== LONG_MNEM_SUFFIX
) == (flag_code
== CODE_16BIT
)
3056 || (flag_code
== CODE_64BIT
3057 && (i
.tm
.opcode_modifier
& JumpByte
))))
3059 unsigned int prefix
= DATA_PREFIX_OPCODE
;
3061 if (i
.tm
.opcode_modifier
& JumpByte
) /* jcxz, loop */
3062 prefix
= ADDR_PREFIX_OPCODE
;
3064 if (!add_prefix (prefix
))
3068 /* Set mode64 for an operand. */
3069 if (i
.suffix
== QWORD_MNEM_SUFFIX
3070 && flag_code
== CODE_64BIT
3071 && (i
.tm
.opcode_modifier
& NoRex64
) == 0)
3073 /* Special case for xchg %rax,%rax. It is NOP and doesn't
3076 || i
.types
[0] != (Acc
| Reg64
)
3077 || i
.types
[1] != (Acc
| Reg64
)
3078 || i
.tm
.base_opcode
!= 0x90)
3082 /* Size floating point instruction. */
3083 if (i
.suffix
== LONG_MNEM_SUFFIX
)
3084 if (i
.tm
.opcode_modifier
& FloatMF
)
3085 i
.tm
.base_opcode
^= 4;
3092 check_byte_reg (void)
3096 for (op
= i
.operands
; --op
>= 0;)
3098 /* If this is an eight bit register, it's OK. If it's the 16 or
3099 32 bit version of an eight bit register, we will just use the
3100 low portion, and that's OK too. */
3101 if (i
.types
[op
] & Reg8
)
3104 /* movzx, movsx, pextrb and pinsrb should not generate this
3107 && (i
.tm
.base_opcode
== 0xfb7
3108 || i
.tm
.base_opcode
== 0xfb6
3109 || i
.tm
.base_opcode
== 0x63
3110 || i
.tm
.base_opcode
== 0xfbe
3111 || i
.tm
.base_opcode
== 0xfbf
3112 || i
.tm
.base_opcode
== 0x660f3a14
3113 || i
.tm
.base_opcode
== 0x660f3a20))
3116 /* crc32 doesn't generate this warning. */
3117 if (i
.tm
.base_opcode
== 0xf20f38f0)
3120 if ((i
.types
[op
] & WordReg
) && i
.op
[op
].regs
->reg_num
< 4)
3122 /* Prohibit these changes in the 64bit mode, since the
3123 lowering is more complicated. */
3124 if (flag_code
== CODE_64BIT
3125 && (i
.tm
.operand_types
[op
] & InOutPortReg
) == 0)
3127 as_bad (_("Incorrect register `%s%s' used with `%c' suffix"),
3128 register_prefix
, i
.op
[op
].regs
->reg_name
,
3132 #if REGISTER_WARNINGS
3134 && (i
.tm
.operand_types
[op
] & InOutPortReg
) == 0)
3135 as_warn (_("using `%s%s' instead of `%s%s' due to `%c' suffix"),
3137 (i
.op
[op
].regs
+ (i
.types
[op
] & Reg16
3138 ? REGNAM_AL
- REGNAM_AX
3139 : REGNAM_AL
- REGNAM_EAX
))->reg_name
,
3141 i
.op
[op
].regs
->reg_name
,
3146 /* Any other register is bad. */
3147 if (i
.types
[op
] & (Reg
| RegMMX
| RegXMM
3149 | Control
| Debug
| Test
3150 | FloatReg
| FloatAcc
))
3152 as_bad (_("`%s%s' not allowed with `%s%c'"),
3154 i
.op
[op
].regs
->reg_name
,
3164 check_long_reg (void)
3168 for (op
= i
.operands
; --op
>= 0;)
3169 /* Reject eight bit registers, except where the template requires
3170 them. (eg. movzb) */
3171 if ((i
.types
[op
] & Reg8
) != 0
3172 && (i
.tm
.operand_types
[op
] & (Reg16
| Reg32
| Acc
)) != 0)
3174 as_bad (_("`%s%s' not allowed with `%s%c'"),
3176 i
.op
[op
].regs
->reg_name
,
3181 /* Warn if the e prefix on a general reg is missing. */
3182 else if ((!quiet_warnings
|| flag_code
== CODE_64BIT
)
3183 && (i
.types
[op
] & Reg16
) != 0
3184 && (i
.tm
.operand_types
[op
] & (Reg32
| Acc
)) != 0)
3186 /* Prohibit these changes in the 64bit mode, since the
3187 lowering is more complicated. */
3188 if (flag_code
== CODE_64BIT
)
3190 as_bad (_("Incorrect register `%s%s' used with `%c' suffix"),
3191 register_prefix
, i
.op
[op
].regs
->reg_name
,
3195 #if REGISTER_WARNINGS
3197 as_warn (_("using `%s%s' instead of `%s%s' due to `%c' suffix"),
3199 (i
.op
[op
].regs
+ REGNAM_EAX
- REGNAM_AX
)->reg_name
,
3201 i
.op
[op
].regs
->reg_name
,
3205 /* Warn if the r prefix on a general reg is missing. */
3206 else if ((i
.types
[op
] & Reg64
) != 0
3207 && (i
.tm
.operand_types
[op
] & (Reg32
| Acc
)) != 0)
3210 && i
.tm
.base_opcode
== 0xf30f2d
3211 && (i
.types
[0] & RegXMM
) == 0)
3213 /* cvtss2si converts DWORD memory to Reg64. We want
3215 i
.suffix
= QWORD_MNEM_SUFFIX
;
3219 as_bad (_("Incorrect register `%s%s' used with `%c' suffix"),
3220 register_prefix
, i
.op
[op
].regs
->reg_name
,
3229 check_qword_reg (void)
3233 for (op
= i
.operands
; --op
>= 0; )
3234 /* Reject eight bit registers, except where the template requires
3235 them. (eg. movzb) */
3236 if ((i
.types
[op
] & Reg8
) != 0
3237 && (i
.tm
.operand_types
[op
] & (Reg16
| Reg32
| Acc
)) != 0)
3239 as_bad (_("`%s%s' not allowed with `%s%c'"),
3241 i
.op
[op
].regs
->reg_name
,
3246 /* Warn if the e prefix on a general reg is missing. */
3247 else if ((i
.types
[op
] & (Reg16
| Reg32
)) != 0
3248 && (i
.tm
.operand_types
[op
] & (Reg32
| Acc
)) != 0)
3250 /* Prohibit these changes in the 64bit mode, since the
3251 lowering is more complicated. */
3253 && i
.tm
.base_opcode
== 0xf20f2d
3254 && (i
.types
[0] & RegXMM
) == 0)
3256 /* cvtsd2si converts QWORD memory to Reg32. We don't want
3258 i
.suffix
= LONG_MNEM_SUFFIX
;
3262 as_bad (_("Incorrect register `%s%s' used with `%c' suffix"),
3263 register_prefix
, i
.op
[op
].regs
->reg_name
,
3272 check_word_reg (void)
3275 for (op
= i
.operands
; --op
>= 0;)
3276 /* Reject eight bit registers, except where the template requires
3277 them. (eg. movzb) */
3278 if ((i
.types
[op
] & Reg8
) != 0
3279 && (i
.tm
.operand_types
[op
] & (Reg16
| Reg32
| Acc
)) != 0)
3281 as_bad (_("`%s%s' not allowed with `%s%c'"),
3283 i
.op
[op
].regs
->reg_name
,
3288 /* Warn if the e prefix on a general reg is present. */
3289 else if ((!quiet_warnings
|| flag_code
== CODE_64BIT
)
3290 && (i
.types
[op
] & Reg32
) != 0
3291 && (i
.tm
.operand_types
[op
] & (Reg16
| Acc
)) != 0)
3293 /* Prohibit these changes in the 64bit mode, since the
3294 lowering is more complicated. */
3295 if (flag_code
== CODE_64BIT
)
3297 as_bad (_("Incorrect register `%s%s' used with `%c' suffix"),
3298 register_prefix
, i
.op
[op
].regs
->reg_name
,
3303 #if REGISTER_WARNINGS
3304 as_warn (_("using `%s%s' instead of `%s%s' due to `%c' suffix"),
3306 (i
.op
[op
].regs
+ REGNAM_AX
- REGNAM_EAX
)->reg_name
,
3308 i
.op
[op
].regs
->reg_name
,
3318 unsigned int overlap0
, overlap1
, overlap2
;
3320 overlap0
= i
.types
[0] & i
.tm
.operand_types
[0];
3321 if ((overlap0
& (Imm8
| Imm8S
| Imm16
| Imm32
| Imm32S
| Imm64
))
3322 && overlap0
!= Imm8
&& overlap0
!= Imm8S
3323 && overlap0
!= Imm16
&& overlap0
!= Imm32S
3324 && overlap0
!= Imm32
&& overlap0
!= Imm64
)
3328 overlap0
&= (i
.suffix
== BYTE_MNEM_SUFFIX
3330 : (i
.suffix
== WORD_MNEM_SUFFIX
3332 : (i
.suffix
== QWORD_MNEM_SUFFIX
3336 else if (overlap0
== (Imm16
| Imm32S
| Imm32
)
3337 || overlap0
== (Imm16
| Imm32
)
3338 || overlap0
== (Imm16
| Imm32S
))
3340 overlap0
= ((flag_code
== CODE_16BIT
) ^ (i
.prefix
[DATA_PREFIX
] != 0)
3343 if (overlap0
!= Imm8
&& overlap0
!= Imm8S
3344 && overlap0
!= Imm16
&& overlap0
!= Imm32S
3345 && overlap0
!= Imm32
&& overlap0
!= Imm64
)
3347 as_bad (_("no instruction mnemonic suffix given; "
3348 "can't determine immediate size"));
3352 i
.types
[0] = overlap0
;
3354 overlap1
= i
.types
[1] & i
.tm
.operand_types
[1];
3355 if ((overlap1
& (Imm8
| Imm8S
| Imm16
| Imm32S
| Imm32
| Imm64
))
3356 && overlap1
!= Imm8
&& overlap1
!= Imm8S
3357 && overlap1
!= Imm16
&& overlap1
!= Imm32S
3358 && overlap1
!= Imm32
&& overlap1
!= Imm64
)
3362 overlap1
&= (i
.suffix
== BYTE_MNEM_SUFFIX
3364 : (i
.suffix
== WORD_MNEM_SUFFIX
3366 : (i
.suffix
== QWORD_MNEM_SUFFIX
3370 else if (overlap1
== (Imm16
| Imm32
| Imm32S
)
3371 || overlap1
== (Imm16
| Imm32
)
3372 || overlap1
== (Imm16
| Imm32S
))
3374 overlap1
= ((flag_code
== CODE_16BIT
) ^ (i
.prefix
[DATA_PREFIX
] != 0)
3377 if (overlap1
!= Imm8
&& overlap1
!= Imm8S
3378 && overlap1
!= Imm16
&& overlap1
!= Imm32S
3379 && overlap1
!= Imm32
&& overlap1
!= Imm64
)
3381 as_bad (_("no instruction mnemonic suffix given; "
3382 "can't determine immediate size %x %c"),
3383 overlap1
, i
.suffix
);
3387 i
.types
[1] = overlap1
;
3389 overlap2
= i
.types
[2] & i
.tm
.operand_types
[2];
3390 assert ((overlap2
& Imm
) == 0);
3391 i
.types
[2] = overlap2
;
3397 process_operands (void)
3399 /* Default segment register this instruction will use for memory
3400 accesses. 0 means unknown. This is only for optimizing out
3401 unnecessary segment overrides. */
3402 const seg_entry
*default_seg
= 0;
3404 /* The imul $imm, %reg instruction is converted into
3405 imul $imm, %reg, %reg, and the clr %reg instruction
3406 is converted into xor %reg, %reg. */
3407 if (i
.tm
.opcode_modifier
& RegKludge
)
3409 if ((i
.tm
.cpu_flags
& CpuSSE4_1
))
3411 /* The first operand in instruction blendvpd, blendvps and
3412 pblendvb in SSE4.1 is implicit and must be xmm0. */
3413 assert (i
.operands
== 3
3414 && i
.reg_operands
>= 2
3415 && i
.types
[0] == RegXMM
);
3416 if (i
.op
[0].regs
->reg_num
!= 0)
3419 as_bad (_("the last operand of `%s' must be `%sxmm0'"),
3420 i
.tm
.name
, register_prefix
);
3422 as_bad (_("the first operand of `%s' must be `%sxmm0'"),
3423 i
.tm
.name
, register_prefix
);
3428 i
.types
[0] = i
.types
[1];
3429 i
.types
[1] = i
.types
[2];
3433 /* We need to adjust fields in i.tm since they are used by
3434 build_modrm_byte. */
3435 i
.tm
.operand_types
[0] = i
.tm
.operand_types
[1];
3436 i
.tm
.operand_types
[1] = i
.tm
.operand_types
[2];
3441 unsigned int first_reg_op
= (i
.types
[0] & Reg
) ? 0 : 1;
3442 /* Pretend we saw the extra register operand. */
3443 assert (i
.reg_operands
== 1
3444 && i
.op
[first_reg_op
+ 1].regs
== 0);
3445 i
.op
[first_reg_op
+ 1].regs
= i
.op
[first_reg_op
].regs
;
3446 i
.types
[first_reg_op
+ 1] = i
.types
[first_reg_op
];
3452 if (i
.tm
.opcode_modifier
& ShortForm
)
3454 if (i
.types
[0] & (SReg2
| SReg3
))
3456 if (i
.tm
.base_opcode
== POP_SEG_SHORT
3457 && i
.op
[0].regs
->reg_num
== 1)
3459 as_bad (_("you can't `pop %%cs'"));
3462 i
.tm
.base_opcode
|= (i
.op
[0].regs
->reg_num
<< 3);
3463 if ((i
.op
[0].regs
->reg_flags
& RegRex
) != 0)
3468 /* The register or float register operand is in operand 0 or 1. */
3469 unsigned int op
= (i
.types
[0] & (Reg
| FloatReg
)) ? 0 : 1;
3470 /* Register goes in low 3 bits of opcode. */
3471 i
.tm
.base_opcode
|= i
.op
[op
].regs
->reg_num
;
3472 if ((i
.op
[op
].regs
->reg_flags
& RegRex
) != 0)
3474 if (!quiet_warnings
&& (i
.tm
.opcode_modifier
& Ugh
) != 0)
3476 /* Warn about some common errors, but press on regardless.
3477 The first case can be generated by gcc (<= 2.8.1). */
3478 if (i
.operands
== 2)
3480 /* Reversed arguments on faddp, fsubp, etc. */
3481 as_warn (_("translating to `%s %s%s,%s%s'"), i
.tm
.name
,
3482 register_prefix
, i
.op
[1].regs
->reg_name
,
3483 register_prefix
, i
.op
[0].regs
->reg_name
);
3487 /* Extraneous `l' suffix on fp insn. */
3488 as_warn (_("translating to `%s %s%s'"), i
.tm
.name
,
3489 register_prefix
, i
.op
[0].regs
->reg_name
);
3494 else if (i
.tm
.opcode_modifier
& Modrm
)
3496 /* The opcode is completed (modulo i.tm.extension_opcode which
3497 must be put into the modrm byte). Now, we make the modrm and
3498 index base bytes based on all the info we've collected. */
3500 default_seg
= build_modrm_byte ();
3502 else if ((i
.tm
.base_opcode
& ~0x3) == MOV_AX_DISP32
)
3506 else if ((i
.tm
.opcode_modifier
& IsString
) != 0)
3508 /* For the string instructions that allow a segment override
3509 on one of their operands, the default segment is ds. */
3513 if ((i
.tm
.base_opcode
== 0x8d /* lea */
3514 || (i
.tm
.cpu_flags
& CpuSVME
))
3515 && i
.seg
[0] && !quiet_warnings
)
3516 as_warn (_("segment override on `%s' is ineffectual"), i
.tm
.name
);
3518 /* If a segment was explicitly specified, and the specified segment
3519 is not the default, use an opcode prefix to select it. If we
3520 never figured out what the default segment is, then default_seg
3521 will be zero at this point, and the specified segment prefix will
3523 if ((i
.seg
[0]) && (i
.seg
[0] != default_seg
))
3525 if (!add_prefix (i
.seg
[0]->seg_prefix
))
3531 static const seg_entry
*
3532 build_modrm_byte (void)
3534 const seg_entry
*default_seg
= 0;
3536 /* i.reg_operands MUST be the number of real register operands;
3537 implicit registers do not count. */
3538 if (i
.reg_operands
== 2)
3540 unsigned int source
, dest
;
3548 /* When there are 3 operands, one of them may be immediate,
3549 which may be the first or the last operand. Otherwise,
3550 the first operand must be shift count register (cl). */
3551 assert (i
.imm_operands
== 1
3552 || (i
.imm_operands
== 0
3553 && (i
.types
[0] & ShiftCount
)));
3554 source
= (i
.types
[0] & (Imm
| ShiftCount
)) ? 1 : 0;
3557 /* When there are 4 operands, the first two must be immediate
3558 operands. The source operand will be the 3rd one. */
3559 assert (i
.imm_operands
== 2
3560 && (i
.types
[0] & Imm
)
3561 && (i
.types
[1] & Imm
));
3571 /* One of the register operands will be encoded in the i.tm.reg
3572 field, the other in the combined i.tm.mode and i.tm.regmem
3573 fields. If no form of this instruction supports a memory
3574 destination operand, then we assume the source operand may
3575 sometimes be a memory operand and so we need to store the
3576 destination in the i.rm.reg field. */
3577 if ((i
.tm
.operand_types
[dest
] & (AnyMem
| RegMem
)) == 0)
3579 i
.rm
.reg
= i
.op
[dest
].regs
->reg_num
;
3580 i
.rm
.regmem
= i
.op
[source
].regs
->reg_num
;
3581 if ((i
.op
[dest
].regs
->reg_flags
& RegRex
) != 0)
3583 if ((i
.op
[source
].regs
->reg_flags
& RegRex
) != 0)
3588 i
.rm
.reg
= i
.op
[source
].regs
->reg_num
;
3589 i
.rm
.regmem
= i
.op
[dest
].regs
->reg_num
;
3590 if ((i
.op
[dest
].regs
->reg_flags
& RegRex
) != 0)
3592 if ((i
.op
[source
].regs
->reg_flags
& RegRex
) != 0)
3595 if (flag_code
!= CODE_64BIT
&& (i
.rex
& (REX_R
| REX_B
)))
3597 if (!((i
.types
[0] | i
.types
[1]) & Control
))
3599 i
.rex
&= ~(REX_R
| REX_B
);
3600 add_prefix (LOCK_PREFIX_OPCODE
);
3604 { /* If it's not 2 reg operands... */
3607 unsigned int fake_zero_displacement
= 0;
3610 for (op
= 0; op
< i
.operands
; op
++)
3611 if ((i
.types
[op
] & AnyMem
))
3613 assert (op
< i
.operands
);
3617 if (i
.base_reg
== 0)
3620 if (!i
.disp_operands
)
3621 fake_zero_displacement
= 1;
3622 if (i
.index_reg
== 0)
3624 /* Operand is just <disp> */
3625 if (flag_code
== CODE_64BIT
)
3627 /* 64bit mode overwrites the 32bit absolute
3628 addressing by RIP relative addressing and
3629 absolute addressing is encoded by one of the
3630 redundant SIB forms. */
3631 i
.rm
.regmem
= ESCAPE_TO_TWO_BYTE_ADDRESSING
;
3632 i
.sib
.base
= NO_BASE_REGISTER
;
3633 i
.sib
.index
= NO_INDEX_REGISTER
;
3634 i
.types
[op
] = ((i
.prefix
[ADDR_PREFIX
] == 0)
3635 ? Disp32S
: Disp32
);
3637 else if ((flag_code
== CODE_16BIT
)
3638 ^ (i
.prefix
[ADDR_PREFIX
] != 0))
3640 i
.rm
.regmem
= NO_BASE_REGISTER_16
;
3641 i
.types
[op
] = Disp16
;
3645 i
.rm
.regmem
= NO_BASE_REGISTER
;
3646 i
.types
[op
] = Disp32
;
3649 else /* !i.base_reg && i.index_reg */
3651 i
.sib
.index
= i
.index_reg
->reg_num
;
3652 i
.sib
.base
= NO_BASE_REGISTER
;
3653 i
.sib
.scale
= i
.log2_scale_factor
;
3654 i
.rm
.regmem
= ESCAPE_TO_TWO_BYTE_ADDRESSING
;
3655 i
.types
[op
] &= ~Disp
;
3656 if (flag_code
!= CODE_64BIT
)
3657 i
.types
[op
] |= Disp32
; /* Must be 32 bit */
3659 i
.types
[op
] |= Disp32S
;
3660 if ((i
.index_reg
->reg_flags
& RegRex
) != 0)
3664 /* RIP addressing for 64bit mode. */
3665 else if (i
.base_reg
->reg_type
== BaseIndex
)
3667 i
.rm
.regmem
= NO_BASE_REGISTER
;
3668 i
.types
[op
] &= ~ Disp
;
3669 i
.types
[op
] |= Disp32S
;
3670 i
.flags
[op
] |= Operand_PCrel
;
3671 if (! i
.disp_operands
)
3672 fake_zero_displacement
= 1;
3674 else if (i
.base_reg
->reg_type
& Reg16
)
3676 switch (i
.base_reg
->reg_num
)
3679 if (i
.index_reg
== 0)
3681 else /* (%bx,%si) -> 0, or (%bx,%di) -> 1 */
3682 i
.rm
.regmem
= i
.index_reg
->reg_num
- 6;
3686 if (i
.index_reg
== 0)
3689 if ((i
.types
[op
] & Disp
) == 0)
3691 /* fake (%bp) into 0(%bp) */
3692 i
.types
[op
] |= Disp8
;
3693 fake_zero_displacement
= 1;
3696 else /* (%bp,%si) -> 2, or (%bp,%di) -> 3 */
3697 i
.rm
.regmem
= i
.index_reg
->reg_num
- 6 + 2;
3699 default: /* (%si) -> 4 or (%di) -> 5 */
3700 i
.rm
.regmem
= i
.base_reg
->reg_num
- 6 + 4;
3702 i
.rm
.mode
= mode_from_disp_size (i
.types
[op
]);
3704 else /* i.base_reg and 32/64 bit mode */
3706 if (flag_code
== CODE_64BIT
3707 && (i
.types
[op
] & Disp
))
3708 i
.types
[op
] = ((i
.types
[op
] & Disp8
)
3709 | (i
.prefix
[ADDR_PREFIX
] == 0
3710 ? Disp32S
: Disp32
));
3712 i
.rm
.regmem
= i
.base_reg
->reg_num
;
3713 if ((i
.base_reg
->reg_flags
& RegRex
) != 0)
3715 i
.sib
.base
= i
.base_reg
->reg_num
;
3716 /* x86-64 ignores REX prefix bit here to avoid decoder
3718 if ((i
.base_reg
->reg_num
& 7) == EBP_REG_NUM
)
3721 if (i
.disp_operands
== 0)
3723 fake_zero_displacement
= 1;
3724 i
.types
[op
] |= Disp8
;
3727 else if (i
.base_reg
->reg_num
== ESP_REG_NUM
)
3731 i
.sib
.scale
= i
.log2_scale_factor
;
3732 if (i
.index_reg
== 0)
3734 /* <disp>(%esp) becomes two byte modrm with no index
3735 register. We've already stored the code for esp
3736 in i.rm.regmem ie. ESCAPE_TO_TWO_BYTE_ADDRESSING.
3737 Any base register besides %esp will not use the
3738 extra modrm byte. */
3739 i
.sib
.index
= NO_INDEX_REGISTER
;
3740 #if !SCALE1_WHEN_NO_INDEX
3741 /* Another case where we force the second modrm byte. */
3742 if (i
.log2_scale_factor
)
3743 i
.rm
.regmem
= ESCAPE_TO_TWO_BYTE_ADDRESSING
;
3748 i
.sib
.index
= i
.index_reg
->reg_num
;
3749 i
.rm
.regmem
= ESCAPE_TO_TWO_BYTE_ADDRESSING
;
3750 if ((i
.index_reg
->reg_flags
& RegRex
) != 0)
3755 && (i
.reloc
[op
] == BFD_RELOC_386_TLS_DESC_CALL
3756 || i
.reloc
[op
] == BFD_RELOC_X86_64_TLSDESC_CALL
))
3759 i
.rm
.mode
= mode_from_disp_size (i
.types
[op
]);
3762 if (fake_zero_displacement
)
3764 /* Fakes a zero displacement assuming that i.types[op]
3765 holds the correct displacement size. */
3768 assert (i
.op
[op
].disps
== 0);
3769 exp
= &disp_expressions
[i
.disp_operands
++];
3770 i
.op
[op
].disps
= exp
;
3771 exp
->X_op
= O_constant
;
3772 exp
->X_add_number
= 0;
3773 exp
->X_add_symbol
= (symbolS
*) 0;
3774 exp
->X_op_symbol
= (symbolS
*) 0;
3778 /* Fill in i.rm.reg or i.rm.regmem field with register operand
3779 (if any) based on i.tm.extension_opcode. Again, we must be
3780 careful to make sure that segment/control/debug/test/MMX
3781 registers are coded into the i.rm.reg field. */
3786 for (op
= 0; op
< i
.operands
; op
++)
3787 if ((i
.types
[op
] & (Reg
| RegMMX
| RegXMM
3789 | Control
| Debug
| Test
)))
3791 assert (op
< i
.operands
);
3793 /* If there is an extension opcode to put here, the register
3794 number must be put into the regmem field. */
3795 if (i
.tm
.extension_opcode
!= None
)
3797 i
.rm
.regmem
= i
.op
[op
].regs
->reg_num
;
3798 if ((i
.op
[op
].regs
->reg_flags
& RegRex
) != 0)
3803 i
.rm
.reg
= i
.op
[op
].regs
->reg_num
;
3804 if ((i
.op
[op
].regs
->reg_flags
& RegRex
) != 0)
3808 /* Now, if no memory operand has set i.rm.mode = 0, 1, 2 we
3809 must set it to 3 to indicate this is a register operand
3810 in the regmem field. */
3811 if (!i
.mem_operands
)
3815 /* Fill in i.rm.reg field with extension opcode (if any). */
3816 if (i
.tm
.extension_opcode
!= None
)
3817 i
.rm
.reg
= i
.tm
.extension_opcode
;
3823 output_branch (void)
3828 relax_substateT subtype
;
3833 if (flag_code
== CODE_16BIT
)
3837 if (i
.prefix
[DATA_PREFIX
] != 0)
3843 /* Pentium4 branch hints. */
3844 if (i
.prefix
[SEG_PREFIX
] == CS_PREFIX_OPCODE
/* not taken */
3845 || i
.prefix
[SEG_PREFIX
] == DS_PREFIX_OPCODE
/* taken */)
3850 if (i
.prefix
[REX_PREFIX
] != 0)
3856 if (i
.prefixes
!= 0 && !intel_syntax
)
3857 as_warn (_("skipping prefixes on this instruction"));
3859 /* It's always a symbol; End frag & setup for relax.
3860 Make sure there is enough room in this frag for the largest
3861 instruction we may generate in md_convert_frag. This is 2
3862 bytes for the opcode and room for the prefix and largest
3864 frag_grow (prefix
+ 2 + 4);
3865 /* Prefix and 1 opcode byte go in fr_fix. */
3866 p
= frag_more (prefix
+ 1);
3867 if (i
.prefix
[DATA_PREFIX
] != 0)
3868 *p
++ = DATA_PREFIX_OPCODE
;
3869 if (i
.prefix
[SEG_PREFIX
] == CS_PREFIX_OPCODE
3870 || i
.prefix
[SEG_PREFIX
] == DS_PREFIX_OPCODE
)
3871 *p
++ = i
.prefix
[SEG_PREFIX
];
3872 if (i
.prefix
[REX_PREFIX
] != 0)
3873 *p
++ = i
.prefix
[REX_PREFIX
];
3874 *p
= i
.tm
.base_opcode
;
3876 if ((unsigned char) *p
== JUMP_PC_RELATIVE
)
3877 subtype
= ENCODE_RELAX_STATE (UNCOND_JUMP
, SMALL
);
3878 else if ((cpu_arch_flags
& Cpu386
) != 0)
3879 subtype
= ENCODE_RELAX_STATE (COND_JUMP
, SMALL
);
3881 subtype
= ENCODE_RELAX_STATE (COND_JUMP86
, SMALL
);
3884 sym
= i
.op
[0].disps
->X_add_symbol
;
3885 off
= i
.op
[0].disps
->X_add_number
;
3887 if (i
.op
[0].disps
->X_op
!= O_constant
3888 && i
.op
[0].disps
->X_op
!= O_symbol
)
3890 /* Handle complex expressions. */
3891 sym
= make_expr_symbol (i
.op
[0].disps
);
3895 /* 1 possible extra opcode + 4 byte displacement go in var part.
3896 Pass reloc in fr_var. */
3897 frag_var (rs_machine_dependent
, 5, i
.reloc
[0], subtype
, sym
, off
, p
);
3907 if (i
.tm
.opcode_modifier
& JumpByte
)
3909 /* This is a loop or jecxz type instruction. */
3911 if (i
.prefix
[ADDR_PREFIX
] != 0)
3913 FRAG_APPEND_1_CHAR (ADDR_PREFIX_OPCODE
);
3916 /* Pentium4 branch hints. */
3917 if (i
.prefix
[SEG_PREFIX
] == CS_PREFIX_OPCODE
/* not taken */
3918 || i
.prefix
[SEG_PREFIX
] == DS_PREFIX_OPCODE
/* taken */)
3920 FRAG_APPEND_1_CHAR (i
.prefix
[SEG_PREFIX
]);
3929 if (flag_code
== CODE_16BIT
)
3932 if (i
.prefix
[DATA_PREFIX
] != 0)
3934 FRAG_APPEND_1_CHAR (DATA_PREFIX_OPCODE
);
3944 if (i
.prefix
[REX_PREFIX
] != 0)
3946 FRAG_APPEND_1_CHAR (i
.prefix
[REX_PREFIX
]);
3950 if (i
.prefixes
!= 0 && !intel_syntax
)
3951 as_warn (_("skipping prefixes on this instruction"));
3953 p
= frag_more (1 + size
);
3954 *p
++ = i
.tm
.base_opcode
;
3956 fixP
= fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, size
,
3957 i
.op
[0].disps
, 1, reloc (size
, 1, 1, i
.reloc
[0]));
3959 /* All jumps handled here are signed, but don't use a signed limit
3960 check for 32 and 16 bit jumps as we want to allow wrap around at
3961 4G and 64k respectively. */
3963 fixP
->fx_signed
= 1;
3967 output_interseg_jump (void)
3975 if (flag_code
== CODE_16BIT
)
3979 if (i
.prefix
[DATA_PREFIX
] != 0)
3985 if (i
.prefix
[REX_PREFIX
] != 0)
3995 if (i
.prefixes
!= 0 && !intel_syntax
)
3996 as_warn (_("skipping prefixes on this instruction"));
3998 /* 1 opcode; 2 segment; offset */
3999 p
= frag_more (prefix
+ 1 + 2 + size
);
4001 if (i
.prefix
[DATA_PREFIX
] != 0)
4002 *p
++ = DATA_PREFIX_OPCODE
;
4004 if (i
.prefix
[REX_PREFIX
] != 0)
4005 *p
++ = i
.prefix
[REX_PREFIX
];
4007 *p
++ = i
.tm
.base_opcode
;
4008 if (i
.op
[1].imms
->X_op
== O_constant
)
4010 offsetT n
= i
.op
[1].imms
->X_add_number
;
4013 && !fits_in_unsigned_word (n
)
4014 && !fits_in_signed_word (n
))
4016 as_bad (_("16-bit jump out of range"));
4019 md_number_to_chars (p
, n
, size
);
4022 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, size
,
4023 i
.op
[1].imms
, 0, reloc (size
, 0, 0, i
.reloc
[1]));
4024 if (i
.op
[0].imms
->X_op
!= O_constant
)
4025 as_bad (_("can't handle non absolute segment in `%s'"),
4027 md_number_to_chars (p
+ size
, (valueT
) i
.op
[0].imms
->X_add_number
, 2);
4031 insert_sandbox_code (void)
4034 int align_mask
= (1 << nacl_alignment
) - 1;
4036 if (getenv("NACL_DEBUG_ALIGN")) {
4038 p
[0] = 0xF7; p
[1] = 0xC0 + i
.rm
.regmem
;
4039 p
[2] = align_mask
; p
[3] = p
[4] = p
[5] = 0x00; // TEST reg, align_mask
4040 p
[6] = 0x74; p
[7] = 0x04; // JZ +4
4041 p
[8] = 0xCC; // INT3
4042 p
[9] = 0x0F; p
[10] = 0x1F; p
[11] = 0x00; // NOP
4046 p
[0] = 0x83; // AND instruction.
4047 p
[1] = (0xe0 + i
.rm
.regmem
); // mod = 11, reg = 100, rm = i.rm.regmem;
4048 // p[2] = 0xff & ~align_mask;
4055 frag_is_a_call (void)
4057 if (i
.tm
.base_opcode
== 0xe8) {
4061 else if (i
.tm
.base_opcode
== 0xff) {
4062 // possibly indirect calls
4063 return (i
.rm
.mode
== 3) && (i
.rm
.reg
== 2);
4074 fragS
*insn_start_frag
;
4075 offsetT insn_start_off
;
4077 // DCS -- New code for NativeClient.
4078 // Frag_align_code sets the alignment on the current fragment and may
4079 // create a new one. Because of this we remember the current fragment
4080 // before calling frag_align_code.
4081 insn_start_frag
= frag_now
;
4083 if (nacl_alignment
> 0) {
4084 frag_align_code(0, 0);
4086 // TODO: this code seems unnecessary. Remove it.
4087 // Really ugly stuff to avoid splitting call and its subsequent alignment
4088 // across two fragments.
4089 if (frag_is_a_call() &&
4090 obstack_room(&frchain_now
->frch_obstack
) < (unsigned)((1<<(nacl_alignment
+1))-1)) {
4091 fragS
*temp_frag
= frag_now
;
4092 frag_align_code(nacl_alignment
+ 1, 0);
4093 temp_frag
->fr_offset
= 0;
4094 temp_frag
->fr_subtype
= 0;
4099 /* Tie dwarf2 debug info to the address at the start of the insn.
4100 We can't do this after the insn has been output as the current
4101 frag may have been closed off. eg. by frag_var. */
4102 dwarf2_emit_insn (0);
4104 insn_start_off
= frag_now_fix ();
4106 if (nacl_alignment
> 0) {
4107 if (!strcmp(i
.tm
.name
, "naclcall")) {
4108 insert_sandbox_code();
4110 else if (!strcmp(i
.tm
.name
, "nacljmp")) {
4111 insert_sandbox_code();
4113 else if (!strcmp(i
.tm
.name
, "naclret")) {
4114 insert_sandbox_code();
4119 if (i
.tm
.opcode_modifier
& Jump
)
4121 else if (i
.tm
.opcode_modifier
& (JumpByte
| JumpDword
))
4123 else if (i
.tm
.opcode_modifier
& JumpInterSegment
)
4124 output_interseg_jump ();
4127 /* Output normal instructions here. */
4130 unsigned int prefix
;
4132 /* All opcodes on i386 have either 1 or 2 bytes. SSSE3 and
4133 SSE4 instructions have 3 bytes. We may use one more higher
4134 byte to specify a prefix the instruction requires. Exclude
4135 instructions which are in both SSE4 and ABM. */
4136 if ((i
.tm
.cpu_flags
& (CpuSSSE3
| CpuSSE4
)) != 0
4137 && (i
.tm
.cpu_flags
& CpuABM
) == 0)
4139 if (i
.tm
.base_opcode
& 0xff000000)
4141 prefix
= (i
.tm
.base_opcode
>> 24) & 0xff;
4145 else if ((i
.tm
.base_opcode
& 0xff0000) != 0)
4147 prefix
= (i
.tm
.base_opcode
>> 16) & 0xff;
4148 if ((i
.tm
.cpu_flags
& CpuPadLock
) != 0)
4151 if (prefix
!= REPE_PREFIX_OPCODE
4152 || i
.prefix
[LOCKREP_PREFIX
] != REPE_PREFIX_OPCODE
)
4153 add_prefix (prefix
);
4156 add_prefix (prefix
);
4159 /* The prefix bytes. */
4161 q
< i
.prefix
+ sizeof (i
.prefix
) / sizeof (i
.prefix
[0]);
4167 md_number_to_chars (p
, (valueT
) *q
, 1);
4171 /* Now the opcode; be careful about word order here! */
4172 if (fits_in_unsigned_byte (i
.tm
.base_opcode
))
4174 FRAG_APPEND_1_CHAR (i
.tm
.base_opcode
);
4178 if ((i
.tm
.cpu_flags
& (CpuSSSE3
| CpuSSE4
)) != 0
4179 && (i
.tm
.cpu_flags
& CpuABM
) == 0)
4182 *p
++ = (i
.tm
.base_opcode
>> 16) & 0xff;
4187 /* Put out high byte first: can't use md_number_to_chars! */
4188 *p
++ = (i
.tm
.base_opcode
>> 8) & 0xff;
4189 *p
= i
.tm
.base_opcode
& 0xff;
4192 /* Now the modrm byte and sib byte (if present). */
4193 if (i
.tm
.opcode_modifier
& Modrm
)
4196 md_number_to_chars (p
,
4197 (valueT
) (i
.rm
.regmem
<< 0
4201 /* If i.rm.regmem == ESP (4)
4202 && i.rm.mode != (Register mode)
4204 ==> need second modrm byte. */
4205 if (i
.rm
.regmem
== ESCAPE_TO_TWO_BYTE_ADDRESSING
4207 && !(i
.base_reg
&& (i
.base_reg
->reg_type
& Reg16
) != 0))
4210 md_number_to_chars (p
,
4211 (valueT
) (i
.sib
.base
<< 0
4213 | i
.sib
.scale
<< 6),
4218 if (i
.disp_operands
)
4219 output_disp (insn_start_frag
, insn_start_off
);
4222 output_imm (insn_start_frag
, insn_start_off
);
4228 pi ("" /*line*/, &i
);
4230 #endif /* DEBUG386 */
4232 * We want to make sure no instruction straddles a (1 << nacl_alignment)
4233 * boundary. We do this by setting the fragment alignment to
4234 * (1 << nacl_alignment), but allowing no more than the size of the
4235 * instruction as fill.
4237 if (nacl_alignment
> 0) {
4240 int instrsize
= (int) frag_now_fix();
4243 * "library mode" enables compatible library builds for either 16 or
4244 * 32 byte alignment. Using the strictest alignment requirement for
4245 * instructions makes them 0mod16 aligned. Calls need to end a 32 byte
4248 if (nacl_library_mode
) {
4253 align_base
= nacl_alignment
;
4254 call_align
= nacl_alignment
;
4257 switch (instrsize
) {
4259 // We get zero size for jump instructions. Go to their biggest.
4260 insn_start_frag
->fr_offset
= align_base
;
4261 insn_start_frag
->fr_subtype
= 5;
4265 if ((i
.tm
.base_opcode
== 0xf3) || (i
.tm
.base_opcode
== 0xf2) ||
4266 (i
.tm
.base_opcode
== 0xf0)) {
4267 // rep and lock refixes are treated as separate instructions.
4268 // I don't know any other patch but to force an alignment to 0,
4269 // i.e., waste as many bytes as it takes.
4270 insn_start_frag
->fr_offset
= align_base
;
4271 insn_start_frag
->fr_subtype
= 0;
4274 // Don't align other one-byte instructions.
4275 insn_start_frag
->fr_offset
= 0;
4276 insn_start_frag
->fr_subtype
= 0;
4281 // Don't use more than size-1 bytes to pad.
4282 insn_start_frag
->fr_offset
= align_base
;
4283 insn_start_frag
->fr_subtype
= instrsize
-1;
4289 * Calls need to fall at the end of a (1 << call_align) region. We
4290 * make sure there are no instructions after the call until the next
4291 * alignment. During writing of the object we swap the nops before the
4294 if (frag_is_a_call()) {
4295 frag_now
->is_call
= 1;
4296 frag_align_code(call_align
,0);
4301 /* Return the size of the displacement operand N. */
4304 disp_size (unsigned int n
)
4307 if (i
.types
[n
] & (Disp8
| Disp16
| Disp64
))
4310 if (i
.types
[n
] & Disp8
)
4312 if (i
.types
[n
] & Disp64
)
4318 /* Return the size of the immediate operand N. */
4321 imm_size (unsigned int n
)
4324 if (i
.types
[n
] & (Imm8
| Imm8S
| Imm16
| Imm64
))
4327 if (i
.types
[n
] & (Imm8
| Imm8S
))
4329 if (i
.types
[n
] & Imm64
)
4336 output_disp (fragS
*insn_start_frag
, offsetT insn_start_off
)
4341 for (n
= 0; n
< i
.operands
; n
++)
4343 if (i
.types
[n
] & Disp
)
4345 if (i
.op
[n
].disps
->X_op
== O_constant
)
4347 int size
= disp_size (n
);
4350 val
= offset_in_range (i
.op
[n
].disps
->X_add_number
,
4352 p
= frag_more (size
);
4353 md_number_to_chars (p
, val
, size
);
4357 enum bfd_reloc_code_real reloc_type
;
4358 int size
= disp_size (n
);
4359 int sign
= (i
.types
[n
] & Disp32S
) != 0;
4360 int pcrel
= (i
.flags
[n
] & Operand_PCrel
) != 0;
4362 /* We can't have 8 bit displacement here. */
4363 assert ((i
.types
[n
] & Disp8
) == 0);
4365 /* The PC relative address is computed relative
4366 to the instruction boundary, so in case immediate
4367 fields follows, we need to adjust the value. */
4368 if (pcrel
&& i
.imm_operands
)
4373 for (n1
= 0; n1
< i
.operands
; n1
++)
4374 if (i
.types
[n1
] & Imm
)
4376 /* Only one immediate is allowed for PC
4377 relative address. */
4380 i
.op
[n
].disps
->X_add_number
-= sz
;
4382 /* We should find the immediate. */
4386 p
= frag_more (size
);
4387 reloc_type
= reloc (size
, pcrel
, sign
, i
.reloc
[n
]);
4389 && GOT_symbol
== i
.op
[n
].disps
->X_add_symbol
4390 && (((reloc_type
== BFD_RELOC_32
4391 || reloc_type
== BFD_RELOC_X86_64_32S
4392 || (reloc_type
== BFD_RELOC_64
4394 && (i
.op
[n
].disps
->X_op
== O_symbol
4395 || (i
.op
[n
].disps
->X_op
== O_add
4396 && ((symbol_get_value_expression
4397 (i
.op
[n
].disps
->X_op_symbol
)->X_op
)
4399 || reloc_type
== BFD_RELOC_32_PCREL
))
4403 if (insn_start_frag
== frag_now
)
4404 add
= (p
- frag_now
->fr_literal
) - insn_start_off
;
4409 add
= insn_start_frag
->fr_fix
- insn_start_off
;
4410 for (fr
= insn_start_frag
->fr_next
;
4411 fr
&& fr
!= frag_now
; fr
= fr
->fr_next
)
4413 add
+= p
- frag_now
->fr_literal
;
4418 reloc_type
= BFD_RELOC_386_GOTPC
;
4419 i
.op
[n
].imms
->X_add_number
+= add
;
4421 else if (reloc_type
== BFD_RELOC_64
)
4422 reloc_type
= BFD_RELOC_X86_64_GOTPC64
;
4424 /* Don't do the adjustment for x86-64, as there
4425 the pcrel addressing is relative to the _next_
4426 insn, and that is taken care of in other code. */
4427 reloc_type
= BFD_RELOC_X86_64_GOTPC32
;
4429 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, size
,
4430 i
.op
[n
].disps
, pcrel
, reloc_type
);
4437 output_imm (fragS
*insn_start_frag
, offsetT insn_start_off
)
4442 for (n
= 0; n
< i
.operands
; n
++)
4444 if (i
.types
[n
] & Imm
)
4446 if (i
.op
[n
].imms
->X_op
== O_constant
)
4448 int size
= imm_size (n
);
4451 val
= offset_in_range (i
.op
[n
].imms
->X_add_number
,
4453 p
= frag_more (size
);
4454 md_number_to_chars (p
, val
, size
);
4458 /* Not absolute_section.
4459 Need a 32-bit fixup (don't support 8bit
4460 non-absolute imms). Try to support other
4462 enum bfd_reloc_code_real reloc_type
;
4463 int size
= imm_size (n
);
4466 if ((i
.types
[n
] & (Imm32S
))
4467 && (i
.suffix
== QWORD_MNEM_SUFFIX
4468 || (!i
.suffix
&& (i
.tm
.opcode_modifier
& No_lSuf
))))
4473 p
= frag_more (size
);
4474 reloc_type
= reloc (size
, 0, sign
, i
.reloc
[n
]);
4476 /* This is tough to explain. We end up with this one if we
4477 * have operands that look like
4478 * "_GLOBAL_OFFSET_TABLE_+[.-.L284]". The goal here is to
4479 * obtain the absolute address of the GOT, and it is strongly
4480 * preferable from a performance point of view to avoid using
4481 * a runtime relocation for this. The actual sequence of
4482 * instructions often look something like:
4487 * addl $_GLOBAL_OFFSET_TABLE_+[.-.L66],%ebx
4489 * The call and pop essentially return the absolute address
4490 * of the label .L66 and store it in %ebx. The linker itself
4491 * will ultimately change the first operand of the addl so
4492 * that %ebx points to the GOT, but to keep things simple, the
4493 * .o file must have this operand set so that it generates not
4494 * the absolute address of .L66, but the absolute address of
4495 * itself. This allows the linker itself simply treat a GOTPC
4496 * relocation as asking for a pcrel offset to the GOT to be
4497 * added in, and the addend of the relocation is stored in the
4498 * operand field for the instruction itself.
4500 * Our job here is to fix the operand so that it would add
4501 * the correct offset so that %ebx would point to itself. The
4502 * thing that is tricky is that .-.L66 will point to the
4503 * beginning of the instruction, so we need to further modify
4504 * the operand so that it will point to itself. There are
4505 * other cases where you have something like:
4507 * .long $_GLOBAL_OFFSET_TABLE_+[.-.L66]
4509 * and here no correction would be required. Internally in
4510 * the assembler we treat operands of this form as not being
4511 * pcrel since the '.' is explicitly mentioned, and I wonder
4512 * whether it would simplify matters to do it this way. Who
4513 * knows. In earlier versions of the PIC patches, the
4514 * pcrel_adjust field was used to store the correction, but
4515 * since the expression is not pcrel, I felt it would be
4516 * confusing to do it this way. */
4518 if ((reloc_type
== BFD_RELOC_32
4519 || reloc_type
== BFD_RELOC_X86_64_32S
4520 || reloc_type
== BFD_RELOC_64
)
4522 && GOT_symbol
== i
.op
[n
].imms
->X_add_symbol
4523 && (i
.op
[n
].imms
->X_op
== O_symbol
4524 || (i
.op
[n
].imms
->X_op
== O_add
4525 && ((symbol_get_value_expression
4526 (i
.op
[n
].imms
->X_op_symbol
)->X_op
)
4531 if (insn_start_frag
== frag_now
)
4532 add
= (p
- frag_now
->fr_literal
) - insn_start_off
;
4537 add
= insn_start_frag
->fr_fix
- insn_start_off
;
4538 for (fr
= insn_start_frag
->fr_next
;
4539 fr
&& fr
!= frag_now
; fr
= fr
->fr_next
)
4541 add
+= p
- frag_now
->fr_literal
;
4545 reloc_type
= BFD_RELOC_386_GOTPC
;
4547 reloc_type
= BFD_RELOC_X86_64_GOTPC32
;
4549 reloc_type
= BFD_RELOC_X86_64_GOTPC64
;
4550 i
.op
[n
].imms
->X_add_number
+= add
;
4552 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, size
,
4553 i
.op
[n
].imms
, 0, reloc_type
);
4559 /* x86_cons_fix_new is called via the expression parsing code when a
4560 reloc is needed. We use this hook to get the correct .got reloc. */
4561 static enum bfd_reloc_code_real got_reloc
= NO_RELOC
;
4562 static int cons_sign
= -1;
4565 x86_cons_fix_new (fragS
*frag
, unsigned int off
, unsigned int len
,
4568 enum bfd_reloc_code_real r
= reloc (len
, 0, cons_sign
, got_reloc
);
4570 got_reloc
= NO_RELOC
;
4573 if (exp
->X_op
== O_secrel
)
4575 exp
->X_op
= O_symbol
;
4576 r
= BFD_RELOC_32_SECREL
;
4580 fix_new_exp (frag
, off
, len
, exp
, 0, r
);
4583 #if (!defined (OBJ_ELF) && !defined (OBJ_MAYBE_ELF)) || defined (LEX_AT)
4584 # define lex_got(reloc, adjust, types) NULL
4586 /* Parse operands of the form
4587 <symbol>@GOTOFF+<nnn>
4588 and similar .plt or .got references.
4590 If we find one, set up the correct relocation in RELOC and copy the
4591 input string, minus the `@GOTOFF' into a malloc'd buffer for
4592 parsing by the calling routine. Return this buffer, and if ADJUST
4593 is non-null set it to the length of the string we removed from the
4594 input line. Otherwise return NULL. */
4596 lex_got (enum bfd_reloc_code_real
*reloc
,
4598 unsigned int *types
)
4600 /* Some of the relocations depend on the size of what field is to
4601 be relocated. But in our callers i386_immediate and i386_displacement
4602 we don't yet know the operand size (this will be set by insn
4603 matching). Hence we record the word32 relocation here,
4604 and adjust the reloc according to the real size in reloc(). */
4605 static const struct {
4607 const enum bfd_reloc_code_real rel
[2];
4608 const unsigned int types64
;
4611 BFD_RELOC_X86_64_PLTOFF64
},
4613 { "PLT", { BFD_RELOC_386_PLT32
,
4614 BFD_RELOC_X86_64_PLT32
},
4615 Imm32
| Imm32S
| Disp32
},
4617 BFD_RELOC_X86_64_GOTPLT64
},
4619 { "GOTOFF", { BFD_RELOC_386_GOTOFF
,
4620 BFD_RELOC_X86_64_GOTOFF64
},
4623 BFD_RELOC_X86_64_GOTPCREL
},
4624 Imm32
| Imm32S
| Disp32
},
4625 { "TLSGD", { BFD_RELOC_386_TLS_GD
,
4626 BFD_RELOC_X86_64_TLSGD
},
4627 Imm32
| Imm32S
| Disp32
},
4628 { "TLSLDM", { BFD_RELOC_386_TLS_LDM
,
4632 BFD_RELOC_X86_64_TLSLD
},
4633 Imm32
| Imm32S
| Disp32
},
4634 { "GOTTPOFF", { BFD_RELOC_386_TLS_IE_32
,
4635 BFD_RELOC_X86_64_GOTTPOFF
},
4636 Imm32
| Imm32S
| Disp32
},
4637 { "TPOFF", { BFD_RELOC_386_TLS_LE_32
,
4638 BFD_RELOC_X86_64_TPOFF32
},
4639 Imm32
| Imm32S
| Imm64
| Disp32
| Disp64
},
4640 { "NTPOFF", { BFD_RELOC_386_TLS_LE
,
4643 { "DTPOFF", { BFD_RELOC_386_TLS_LDO_32
,
4644 BFD_RELOC_X86_64_DTPOFF32
},
4645 Imm32
| Imm32S
| Imm64
| Disp32
| Disp64
},
4646 { "GOTNTPOFF",{ BFD_RELOC_386_TLS_GOTIE
,
4649 { "INDNTPOFF",{ BFD_RELOC_386_TLS_IE
,
4652 { "GOT", { BFD_RELOC_386_GOT32
,
4653 BFD_RELOC_X86_64_GOT32
},
4654 Imm32
| Imm32S
| Disp32
| Imm64
},
4655 { "TLSDESC", { BFD_RELOC_386_TLS_GOTDESC
,
4656 BFD_RELOC_X86_64_GOTPC32_TLSDESC
},
4657 Imm32
| Imm32S
| Disp32
},
4658 { "TLSCALL", { BFD_RELOC_386_TLS_DESC_CALL
,
4659 BFD_RELOC_X86_64_TLSDESC_CALL
},
4660 Imm32
| Imm32S
| Disp32
}
4668 for (cp
= input_line_pointer
; *cp
!= '@'; cp
++)
4669 if (is_end_of_line
[(unsigned char) *cp
] || *cp
== ',')
4672 for (j
= 0; j
< sizeof (gotrel
) / sizeof (gotrel
[0]); j
++)
4676 len
= strlen (gotrel
[j
].str
);
4677 if (strncasecmp (cp
+ 1, gotrel
[j
].str
, len
) == 0)
4679 if (gotrel
[j
].rel
[object_64bit
] != 0)
4682 char *tmpbuf
, *past_reloc
;
4684 *reloc
= gotrel
[j
].rel
[object_64bit
];
4690 if (flag_code
!= CODE_64BIT
)
4691 *types
= Imm32
| Disp32
;
4693 *types
= gotrel
[j
].types64
;
4696 if (GOT_symbol
== NULL
)
4697 GOT_symbol
= symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME
);
4699 /* The length of the first part of our input line. */
4700 first
= cp
- input_line_pointer
;
4702 /* The second part goes from after the reloc token until
4703 (and including) an end_of_line char or comma. */
4704 past_reloc
= cp
+ 1 + len
;
4706 while (!is_end_of_line
[(unsigned char) *cp
] && *cp
!= ',')
4708 second
= cp
+ 1 - past_reloc
;
4710 /* Allocate and copy string. The trailing NUL shouldn't
4711 be necessary, but be safe. */
4712 tmpbuf
= xmalloc (first
+ second
+ 2);
4713 memcpy (tmpbuf
, input_line_pointer
, first
);
4714 if (second
!= 0 && *past_reloc
!= ' ')
4715 /* Replace the relocation token with ' ', so that
4716 errors like foo@GOTOFF1 will be detected. */
4717 tmpbuf
[first
++] = ' ';
4718 memcpy (tmpbuf
+ first
, past_reloc
, second
);
4719 tmpbuf
[first
+ second
] = '\0';
4723 as_bad (_("@%s reloc is not supported with %d-bit output format"),
4724 gotrel
[j
].str
, 1 << (5 + object_64bit
));
4729 /* Might be a symbol version string. Don't as_bad here. */
4734 x86_cons (expressionS
*exp
, int size
)
4736 if (size
== 4 || (object_64bit
&& size
== 8))
4738 /* Handle @GOTOFF and the like in an expression. */
4740 char *gotfree_input_line
;
4743 save
= input_line_pointer
;
4744 gotfree_input_line
= lex_got (&got_reloc
, &adjust
, NULL
);
4745 if (gotfree_input_line
)
4746 input_line_pointer
= gotfree_input_line
;
4750 if (gotfree_input_line
)
4752 /* expression () has merrily parsed up to the end of line,
4753 or a comma - in the wrong buffer. Transfer how far
4754 input_line_pointer has moved to the right buffer. */
4755 input_line_pointer
= (save
4756 + (input_line_pointer
- gotfree_input_line
)
4758 free (gotfree_input_line
);
4766 static void signed_cons (int size
)
4768 if (flag_code
== CODE_64BIT
)
4776 pe_directive_secrel (dummy
)
4777 int dummy ATTRIBUTE_UNUSED
;
4784 if (exp
.X_op
== O_symbol
)
4785 exp
.X_op
= O_secrel
;
4787 emit_expr (&exp
, 4);
4789 while (*input_line_pointer
++ == ',');
4791 input_line_pointer
--;
4792 demand_empty_rest_of_line ();
4797 i386_immediate (char *imm_start
)
4799 char *save_input_line_pointer
;
4800 char *gotfree_input_line
;
4803 unsigned int types
= ~0U;
4805 if (i
.imm_operands
== MAX_IMMEDIATE_OPERANDS
)
4807 as_bad (_("at most %d immediate operands are allowed"),
4808 MAX_IMMEDIATE_OPERANDS
);
4812 exp
= &im_expressions
[i
.imm_operands
++];
4813 i
.op
[this_operand
].imms
= exp
;
4815 if (is_space_char (*imm_start
))
4818 save_input_line_pointer
= input_line_pointer
;
4819 input_line_pointer
= imm_start
;
4821 gotfree_input_line
= lex_got (&i
.reloc
[this_operand
], NULL
, &types
);
4822 if (gotfree_input_line
)
4823 input_line_pointer
= gotfree_input_line
;
4825 exp_seg
= expression (exp
);
4828 if (*input_line_pointer
)
4829 as_bad (_("junk `%s' after expression"), input_line_pointer
);
4831 input_line_pointer
= save_input_line_pointer
;
4832 if (gotfree_input_line
)
4833 free (gotfree_input_line
);
4835 if (exp
->X_op
== O_absent
|| exp
->X_op
== O_big
)
4837 /* Missing or bad expr becomes absolute 0. */
4838 as_bad (_("missing or invalid immediate expression `%s' taken as 0"),
4840 exp
->X_op
= O_constant
;
4841 exp
->X_add_number
= 0;
4842 exp
->X_add_symbol
= (symbolS
*) 0;
4843 exp
->X_op_symbol
= (symbolS
*) 0;
4845 else if (exp
->X_op
== O_constant
)
4847 /* Size it properly later. */
4848 i
.types
[this_operand
] |= Imm64
;
4849 /* If BFD64, sign extend val. */
4850 if (!use_rela_relocations
4851 && (exp
->X_add_number
& ~(((addressT
) 2 << 31) - 1)) == 0)
4853 = (exp
->X_add_number
^ ((addressT
) 1 << 31)) - ((addressT
) 1 << 31);
4855 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
4856 else if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
4857 && exp_seg
!= absolute_section
4858 && exp_seg
!= text_section
4859 && exp_seg
!= data_section
4860 && exp_seg
!= bss_section
4861 && exp_seg
!= undefined_section
4862 && !bfd_is_com_section (exp_seg
))
4864 as_bad (_("unimplemented segment %s in operand"), exp_seg
->name
);
4868 else if (!intel_syntax
&& exp
->X_op
== O_register
)
4870 as_bad (_("illegal immediate register operand %s"), imm_start
);
4875 /* This is an address. The size of the address will be
4876 determined later, depending on destination register,
4877 suffix, or the default for the section. */
4878 i
.types
[this_operand
] |= Imm8
| Imm16
| Imm32
| Imm32S
| Imm64
;
4879 i
.types
[this_operand
] &= types
;
4886 i386_scale (char *scale
)
4889 char *save
= input_line_pointer
;
4891 input_line_pointer
= scale
;
4892 val
= get_absolute_expression ();
4897 i
.log2_scale_factor
= 0;
4900 i
.log2_scale_factor
= 1;
4903 i
.log2_scale_factor
= 2;
4906 i
.log2_scale_factor
= 3;
4910 char sep
= *input_line_pointer
;
4912 *input_line_pointer
= '\0';
4913 as_bad (_("expecting scale factor of 1, 2, 4, or 8: got `%s'"),
4915 *input_line_pointer
= sep
;
4916 input_line_pointer
= save
;
4920 if (i
.log2_scale_factor
!= 0 && i
.index_reg
== 0)
4922 as_warn (_("scale factor of %d without an index register"),
4923 1 << i
.log2_scale_factor
);
4924 #if SCALE1_WHEN_NO_INDEX
4925 i
.log2_scale_factor
= 0;
4928 scale
= input_line_pointer
;
4929 input_line_pointer
= save
;
4934 i386_displacement (char *disp_start
, char *disp_end
)
4938 char *save_input_line_pointer
;
4939 char *gotfree_input_line
;
4940 int bigdisp
, override
;
4941 unsigned int types
= Disp
;
4943 if (i
.disp_operands
== MAX_MEMORY_OPERANDS
)
4945 as_bad (_("at most %d displacement operands are allowed"),
4946 MAX_MEMORY_OPERANDS
);
4950 if ((i
.types
[this_operand
] & JumpAbsolute
)
4951 || !(current_templates
->start
->opcode_modifier
& (Jump
| JumpDword
)))
4954 override
= (i
.prefix
[ADDR_PREFIX
] != 0);
4958 /* For PC-relative branches, the width of the displacement
4959 is dependent upon data size, not address size. */
4961 override
= (i
.prefix
[DATA_PREFIX
] != 0);
4963 if (flag_code
== CODE_64BIT
)
4966 bigdisp
= ((override
|| i
.suffix
== WORD_MNEM_SUFFIX
)
4968 : Disp32S
| Disp32
);
4970 bigdisp
= Disp64
| Disp32S
| Disp32
;
4977 override
= (i
.suffix
== (flag_code
!= CODE_16BIT
4979 : LONG_MNEM_SUFFIX
));
4982 if ((flag_code
== CODE_16BIT
) ^ override
)
4985 i
.types
[this_operand
] |= bigdisp
;
4987 exp
= &disp_expressions
[i
.disp_operands
];
4988 i
.op
[this_operand
].disps
= exp
;
4990 save_input_line_pointer
= input_line_pointer
;
4991 input_line_pointer
= disp_start
;
4992 END_STRING_AND_SAVE (disp_end
);
4994 #ifndef GCC_ASM_O_HACK
4995 #define GCC_ASM_O_HACK 0
4998 END_STRING_AND_SAVE (disp_end
+ 1);
4999 if ((i
.types
[this_operand
] & BaseIndex
) != 0
5000 && displacement_string_end
[-1] == '+')
5002 /* This hack is to avoid a warning when using the "o"
5003 constraint within gcc asm statements.
5006 #define _set_tssldt_desc(n,addr,limit,type) \
5007 __asm__ __volatile__ ( \
5009 "movw %w1,2+%0\n\t" \
5011 "movb %b1,4+%0\n\t" \
5012 "movb %4,5+%0\n\t" \
5013 "movb $0,6+%0\n\t" \
5014 "movb %h1,7+%0\n\t" \
5016 : "=o"(*(n)) : "q" (addr), "ri"(limit), "i"(type))
5018 This works great except that the output assembler ends
5019 up looking a bit weird if it turns out that there is
5020 no offset. You end up producing code that looks like:
5033 So here we provide the missing zero. */
5035 *displacement_string_end
= '0';
5038 gotfree_input_line
= lex_got (&i
.reloc
[this_operand
], NULL
, &types
);
5039 if (gotfree_input_line
)
5040 input_line_pointer
= gotfree_input_line
;
5042 exp_seg
= expression (exp
);
5045 if (*input_line_pointer
)
5046 as_bad (_("junk `%s' after expression"), input_line_pointer
);
5048 RESTORE_END_STRING (disp_end
+ 1);
5050 RESTORE_END_STRING (disp_end
);
5051 input_line_pointer
= save_input_line_pointer
;
5052 if (gotfree_input_line
)
5053 free (gotfree_input_line
);
5055 /* We do this to make sure that the section symbol is in
5056 the symbol table. We will ultimately change the relocation
5057 to be relative to the beginning of the section. */
5058 if (i
.reloc
[this_operand
] == BFD_RELOC_386_GOTOFF
5059 || i
.reloc
[this_operand
] == BFD_RELOC_X86_64_GOTPCREL
5060 || i
.reloc
[this_operand
] == BFD_RELOC_X86_64_GOTOFF64
)
5062 if (exp
->X_op
!= O_symbol
)
5064 as_bad (_("bad expression used with @%s"),
5065 (i
.reloc
[this_operand
] == BFD_RELOC_X86_64_GOTPCREL
5071 if (S_IS_LOCAL (exp
->X_add_symbol
)
5072 && S_GET_SEGMENT (exp
->X_add_symbol
) != undefined_section
)
5073 section_symbol (S_GET_SEGMENT (exp
->X_add_symbol
));
5074 exp
->X_op
= O_subtract
;
5075 exp
->X_op_symbol
= GOT_symbol
;
5076 if (i
.reloc
[this_operand
] == BFD_RELOC_X86_64_GOTPCREL
)
5077 i
.reloc
[this_operand
] = BFD_RELOC_32_PCREL
;
5078 else if (i
.reloc
[this_operand
] == BFD_RELOC_X86_64_GOTOFF64
)
5079 i
.reloc
[this_operand
] = BFD_RELOC_64
;
5081 i
.reloc
[this_operand
] = BFD_RELOC_32
;
5084 if (exp
->X_op
== O_absent
|| exp
->X_op
== O_big
)
5086 /* Missing or bad expr becomes absolute 0. */
5087 as_bad (_("missing or invalid displacement expression `%s' taken as 0"),
5089 exp
->X_op
= O_constant
;
5090 exp
->X_add_number
= 0;
5091 exp
->X_add_symbol
= (symbolS
*) 0;
5092 exp
->X_op_symbol
= (symbolS
*) 0;
5095 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
5096 if (exp
->X_op
!= O_constant
5097 && OUTPUT_FLAVOR
== bfd_target_aout_flavour
5098 && exp_seg
!= absolute_section
5099 && exp_seg
!= text_section
5100 && exp_seg
!= data_section
5101 && exp_seg
!= bss_section
5102 && exp_seg
!= undefined_section
5103 && !bfd_is_com_section (exp_seg
))
5105 as_bad (_("unimplemented segment %s in operand"), exp_seg
->name
);
5110 if (!(i
.types
[this_operand
] & ~Disp
))
5111 i
.types
[this_operand
] &= types
;
5116 /* Make sure the memory operand we've been dealt is valid.
5117 Return 1 on success, 0 on a failure. */
5120 i386_index_check (const char *operand_string
)
5123 #if INFER_ADDR_PREFIX
5129 if ((current_templates
->start
->cpu_flags
& CpuSVME
)
5130 && current_templates
->end
[-1].operand_types
[0] == AnyMem
)
5132 /* Memory operands of SVME insns are special in that they only allow
5133 rAX as their memory address and ignore any segment override. */
5136 /* SKINIT is even more restrictive: it always requires EAX. */
5137 if (strcmp (current_templates
->start
->name
, "skinit") == 0)
5139 else if (flag_code
== CODE_64BIT
)
5140 RegXX
= i
.prefix
[ADDR_PREFIX
] == 0 ? Reg64
: Reg32
;
5142 RegXX
= ((flag_code
== CODE_16BIT
) ^ (i
.prefix
[ADDR_PREFIX
] != 0)
5146 || !(i
.base_reg
->reg_type
& Acc
)
5147 || !(i
.base_reg
->reg_type
& RegXX
)
5149 || (i
.types
[0] & Disp
))
5152 else if (flag_code
== CODE_64BIT
)
5154 unsigned RegXX
= (i
.prefix
[ADDR_PREFIX
] == 0 ? Reg64
: Reg32
);
5157 && ((i
.base_reg
->reg_type
& RegXX
) == 0)
5158 && (i
.base_reg
->reg_type
!= BaseIndex
5161 && ((i
.index_reg
->reg_type
& (RegXX
| BaseIndex
))
5162 != (RegXX
| BaseIndex
))))
5167 if ((flag_code
== CODE_16BIT
) ^ (i
.prefix
[ADDR_PREFIX
] != 0))
5171 && ((i
.base_reg
->reg_type
& (Reg16
| BaseIndex
| RegRex
))
5172 != (Reg16
| BaseIndex
)))
5174 && (((i
.index_reg
->reg_type
& (Reg16
| BaseIndex
))
5175 != (Reg16
| BaseIndex
))
5177 && i
.base_reg
->reg_num
< 6
5178 && i
.index_reg
->reg_num
>= 6
5179 && i
.log2_scale_factor
== 0))))
5186 && (i
.base_reg
->reg_type
& (Reg32
| RegRex
)) != Reg32
)
5188 && ((i
.index_reg
->reg_type
& (Reg32
| BaseIndex
| RegRex
))
5189 != (Reg32
| BaseIndex
))))
5195 #if INFER_ADDR_PREFIX
5196 if (i
.prefix
[ADDR_PREFIX
] == 0)
5198 i
.prefix
[ADDR_PREFIX
] = ADDR_PREFIX_OPCODE
;
5200 /* Change the size of any displacement too. At most one of
5201 Disp16 or Disp32 is set.
5202 FIXME. There doesn't seem to be any real need for separate
5203 Disp16 and Disp32 flags. The same goes for Imm16 and Imm32.
5204 Removing them would probably clean up the code quite a lot. */
5205 if (flag_code
!= CODE_64BIT
5206 && (i
.types
[this_operand
] & (Disp16
| Disp32
)))
5207 i
.types
[this_operand
] ^= (Disp16
| Disp32
);
5212 as_bad (_("`%s' is not a valid base/index expression"),
5216 as_bad (_("`%s' is not a valid %s bit base/index expression"),
5218 flag_code_names
[flag_code
]);
5223 /* Parse OPERAND_STRING into the i386_insn structure I. Returns non-zero
5227 i386_operand (char *operand_string
)
5231 char *op_string
= operand_string
;
5233 if (is_space_char (*op_string
))
5236 /* We check for an absolute prefix (differentiating,
5237 for example, 'jmp pc_relative_label' from 'jmp *absolute_label'. */
5238 if (*op_string
== ABSOLUTE_PREFIX
)
5241 if (is_space_char (*op_string
))
5243 i
.types
[this_operand
] |= JumpAbsolute
;
5246 /* Check if operand is a register. */
5247 if ((r
= parse_register (op_string
, &end_op
)) != NULL
)
5249 /* Check for a segment override by searching for ':' after a
5250 segment register. */
5252 if (is_space_char (*op_string
))
5254 if (*op_string
== ':' && (r
->reg_type
& (SReg2
| SReg3
)))
5259 i
.seg
[i
.mem_operands
] = &es
;
5262 i
.seg
[i
.mem_operands
] = &cs
;
5265 i
.seg
[i
.mem_operands
] = &ss
;
5268 i
.seg
[i
.mem_operands
] = &ds
;
5271 i
.seg
[i
.mem_operands
] = &fs
;
5274 i
.seg
[i
.mem_operands
] = &gs
;
5278 /* Skip the ':' and whitespace. */
5280 if (is_space_char (*op_string
))
5283 if (!is_digit_char (*op_string
)
5284 && !is_identifier_char (*op_string
)
5285 && *op_string
!= '('
5286 && *op_string
!= ABSOLUTE_PREFIX
)
5288 as_bad (_("bad memory operand `%s'"), op_string
);
5291 /* Handle case of %es:*foo. */
5292 if (*op_string
== ABSOLUTE_PREFIX
)
5295 if (is_space_char (*op_string
))
5297 i
.types
[this_operand
] |= JumpAbsolute
;
5299 goto do_memory_reference
;
5303 as_bad (_("junk `%s' after register"), op_string
);
5306 i
.types
[this_operand
] |= r
->reg_type
& ~BaseIndex
;
5307 i
.op
[this_operand
].regs
= r
;
5310 else if (*op_string
== REGISTER_PREFIX
)
5312 as_bad (_("bad register name `%s'"), op_string
);
5315 else if (*op_string
== IMMEDIATE_PREFIX
)
5318 if (i
.types
[this_operand
] & JumpAbsolute
)
5320 as_bad (_("immediate operand illegal with absolute jump"));
5323 if (!i386_immediate (op_string
))
5326 else if (is_digit_char (*op_string
)
5327 || is_identifier_char (*op_string
)
5328 || *op_string
== '(')
5330 /* This is a memory reference of some sort. */
5333 /* Start and end of displacement string expression (if found). */
5334 char *displacement_string_start
;
5335 char *displacement_string_end
;
5337 do_memory_reference
:
5338 if ((i
.mem_operands
== 1
5339 && (current_templates
->start
->opcode_modifier
& IsString
) == 0)
5340 || i
.mem_operands
== 2)
5342 as_bad (_("too many memory references for `%s'"),
5343 current_templates
->start
->name
);
5347 /* Check for base index form. We detect the base index form by
5348 looking for an ')' at the end of the operand, searching
5349 for the '(' matching it, and finding a REGISTER_PREFIX or ','
5351 base_string
= op_string
+ strlen (op_string
);
5354 if (is_space_char (*base_string
))
5357 /* If we only have a displacement, set-up for it to be parsed later. */
5358 displacement_string_start
= op_string
;
5359 displacement_string_end
= base_string
+ 1;
5361 if (*base_string
== ')')
5364 unsigned int parens_balanced
= 1;
5365 /* We've already checked that the number of left & right ()'s are
5366 equal, so this loop will not be infinite. */
5370 if (*base_string
== ')')
5372 if (*base_string
== '(')
5375 while (parens_balanced
);
5377 temp_string
= base_string
;
5379 /* Skip past '(' and whitespace. */
5381 if (is_space_char (*base_string
))
5384 if (*base_string
== ','
5385 || ((i
.base_reg
= parse_register (base_string
, &end_op
))
5388 displacement_string_end
= temp_string
;
5390 i
.types
[this_operand
] |= BaseIndex
;
5394 base_string
= end_op
;
5395 if (is_space_char (*base_string
))
5399 /* There may be an index reg or scale factor here. */
5400 if (*base_string
== ',')
5403 if (is_space_char (*base_string
))
5406 if ((i
.index_reg
= parse_register (base_string
, &end_op
))
5409 base_string
= end_op
;
5410 if (is_space_char (*base_string
))
5412 if (*base_string
== ',')
5415 if (is_space_char (*base_string
))
5418 else if (*base_string
!= ')')
5420 as_bad (_("expecting `,' or `)' "
5421 "after index register in `%s'"),
5426 else if (*base_string
== REGISTER_PREFIX
)
5428 as_bad (_("bad register name `%s'"), base_string
);
5432 /* Check for scale factor. */
5433 if (*base_string
!= ')')
5435 char *end_scale
= i386_scale (base_string
);
5440 base_string
= end_scale
;
5441 if (is_space_char (*base_string
))
5443 if (*base_string
!= ')')
5445 as_bad (_("expecting `)' "
5446 "after scale factor in `%s'"),
5451 else if (!i
.index_reg
)
5453 as_bad (_("expecting index register or scale factor "
5454 "after `,'; got '%c'"),
5459 else if (*base_string
!= ')')
5461 as_bad (_("expecting `,' or `)' "
5462 "after base register in `%s'"),
5467 else if (*base_string
== REGISTER_PREFIX
)
5469 as_bad (_("bad register name `%s'"), base_string
);
5474 /* If there's an expression beginning the operand, parse it,
5475 assuming displacement_string_start and
5476 displacement_string_end are meaningful. */
5477 if (displacement_string_start
!= displacement_string_end
)
5479 if (!i386_displacement (displacement_string_start
,
5480 displacement_string_end
))
5484 /* Special case for (%dx) while doing input/output op. */
5486 && i
.base_reg
->reg_type
== (Reg16
| InOutPortReg
)
5488 && i
.log2_scale_factor
== 0
5489 && i
.seg
[i
.mem_operands
] == 0
5490 && (i
.types
[this_operand
] & Disp
) == 0)
5492 i
.types
[this_operand
] = InOutPortReg
;
5496 if (i386_index_check (operand_string
) == 0)
5502 /* It's not a memory operand; argh! */
5503 as_bad (_("invalid char %s beginning operand %d `%s'"),
5504 output_invalid (*op_string
),
5509 return 1; /* Normal return. */
5512 /* md_estimate_size_before_relax()
5514 Called just before relax() for rs_machine_dependent frags. The x86
5515 assembler uses these frags to handle variable size jump
5518 Any symbol that is now undefined will not become defined.
5519 Return the correct fr_subtype in the frag.
5520 Return the initial "guess for variable size of frag" to caller.
5521 The guess is actually the growth beyond the fixed part. Whatever
5522 we do to grow the fixed or variable part contributes to our
5526 md_estimate_size_before_relax (fragP
, segment
)
5530 /* We've already got fragP->fr_subtype right; all we have to do is
5531 check for un-relaxable symbols. On an ELF system, we can't relax
5532 an externally visible symbol, because it may be overridden by a
5534 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment
5535 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
5537 && (S_IS_EXTERNAL (fragP
->fr_symbol
)
5538 || S_IS_WEAK (fragP
->fr_symbol
)))
5542 /* Symbol is undefined in this segment, or we need to keep a
5543 reloc so that weak symbols can be overridden. */
5544 int size
= (fragP
->fr_subtype
& CODE16
) ? 2 : 4;
5545 enum bfd_reloc_code_real reloc_type
;
5546 unsigned char *opcode
;
5549 if (fragP
->fr_var
!= NO_RELOC
)
5550 reloc_type
= fragP
->fr_var
;
5552 reloc_type
= BFD_RELOC_16_PCREL
;
5554 reloc_type
= BFD_RELOC_32_PCREL
;
5556 old_fr_fix
= fragP
->fr_fix
;
5557 opcode
= (unsigned char *) fragP
->fr_opcode
;
5559 switch (TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
))
5562 /* Make jmp (0xeb) a (d)word displacement jump. */
5564 fragP
->fr_fix
+= size
;
5565 fix_new (fragP
, old_fr_fix
, size
,
5567 fragP
->fr_offset
, 1,
5573 && (!no_cond_jump_promotion
|| fragP
->fr_var
!= NO_RELOC
))
5575 /* Negate the condition, and branch past an
5576 unconditional jump. */
5579 /* Insert an unconditional jump. */
5581 /* We added two extra opcode bytes, and have a two byte
5583 fragP
->fr_fix
+= 2 + 2;
5584 fix_new (fragP
, old_fr_fix
+ 2, 2,
5586 fragP
->fr_offset
, 1,
5593 if (no_cond_jump_promotion
&& fragP
->fr_var
== NO_RELOC
)
5598 fixP
= fix_new (fragP
, old_fr_fix
, 1,
5600 fragP
->fr_offset
, 1,
5602 fixP
->fx_signed
= 1;
5606 /* This changes the byte-displacement jump 0x7N
5607 to the (d)word-displacement jump 0x0f,0x8N. */
5608 opcode
[1] = opcode
[0] + 0x10;
5609 opcode
[0] = TWO_BYTE_OPCODE_ESCAPE
;
5610 /* We've added an opcode byte. */
5611 fragP
->fr_fix
+= 1 + size
;
5612 fix_new (fragP
, old_fr_fix
+ 1, size
,
5614 fragP
->fr_offset
, 1,
5619 BAD_CASE (fragP
->fr_subtype
);
5623 return fragP
->fr_fix
- old_fr_fix
;
5626 /* Guess size depending on current relax state. Initially the relax
5627 state will correspond to a short jump and we return 1, because
5628 the variable part of the frag (the branch offset) is one byte
5629 long. However, we can relax a section more than once and in that
5630 case we must either set fr_subtype back to the unrelaxed state,
5631 or return the value for the appropriate branch. */
5632 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
5635 /* Called after relax() is finished.
5637 In: Address of frag.
5638 fr_type == rs_machine_dependent.
5639 fr_subtype is what the address relaxed to.
5641 Out: Any fixSs and constants are set up.
5642 Caller will turn frag into a ".space 0". */
5645 md_convert_frag (abfd
, sec
, fragP
)
5646 bfd
*abfd ATTRIBUTE_UNUSED
;
5647 segT sec ATTRIBUTE_UNUSED
;
5650 unsigned char *opcode
;
5651 unsigned char *where_to_put_displacement
= NULL
;
5652 offsetT target_address
;
5653 offsetT opcode_address
;
5654 unsigned int extension
= 0;
5655 offsetT displacement_from_opcode_start
;
5657 opcode
= (unsigned char *) fragP
->fr_opcode
;
5659 /* Address we want to reach in file space. */
5660 target_address
= S_GET_VALUE (fragP
->fr_symbol
) + fragP
->fr_offset
;
5662 /* Address opcode resides at in file space. */
5663 opcode_address
= fragP
->fr_address
+ fragP
->fr_fix
;
5665 /* Displacement from opcode start to fill into instruction. */
5666 displacement_from_opcode_start
= target_address
- opcode_address
;
5668 if ((fragP
->fr_subtype
& BIG
) == 0)
5670 /* Don't have to change opcode. */
5671 extension
= 1; /* 1 opcode + 1 displacement */
5672 where_to_put_displacement
= &opcode
[1];
5676 if (no_cond_jump_promotion
5677 && TYPE_FROM_RELAX_STATE (fragP
->fr_subtype
) != UNCOND_JUMP
)
5678 as_warn_where (fragP
->fr_file
, fragP
->fr_line
,
5679 _("long jump required"));
5681 switch (fragP
->fr_subtype
)
5683 case ENCODE_RELAX_STATE (UNCOND_JUMP
, BIG
):
5684 extension
= 4; /* 1 opcode + 4 displacement */
5686 where_to_put_displacement
= &opcode
[1];
5689 case ENCODE_RELAX_STATE (UNCOND_JUMP
, BIG16
):
5690 extension
= 2; /* 1 opcode + 2 displacement */
5692 where_to_put_displacement
= &opcode
[1];
5695 case ENCODE_RELAX_STATE (COND_JUMP
, BIG
):
5696 case ENCODE_RELAX_STATE (COND_JUMP86
, BIG
):
5697 extension
= 5; /* 2 opcode + 4 displacement */
5698 opcode
[1] = opcode
[0] + 0x10;
5699 opcode
[0] = TWO_BYTE_OPCODE_ESCAPE
;
5700 where_to_put_displacement
= &opcode
[2];
5703 case ENCODE_RELAX_STATE (COND_JUMP
, BIG16
):
5704 extension
= 3; /* 2 opcode + 2 displacement */
5705 opcode
[1] = opcode
[0] + 0x10;
5706 opcode
[0] = TWO_BYTE_OPCODE_ESCAPE
;
5707 where_to_put_displacement
= &opcode
[2];
5710 case ENCODE_RELAX_STATE (COND_JUMP86
, BIG16
):
5715 where_to_put_displacement
= &opcode
[3];
5719 BAD_CASE (fragP
->fr_subtype
);
5724 /* If size if less then four we are sure that the operand fits,
5725 but if it's 4, then it could be that the displacement is larger
5727 if (DISP_SIZE_FROM_RELAX_STATE (fragP
->fr_subtype
) == 4
5729 && ((addressT
) (displacement_from_opcode_start
- extension
5730 + ((addressT
) 1 << 31))
5731 > (((addressT
) 2 << 31) - 1)))
5733 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
5734 _("jump target out of range"));
5735 /* Make us emit 0. */
5736 displacement_from_opcode_start
= extension
;
5738 /* Now put displacement after opcode. */
5739 md_number_to_chars ((char *) where_to_put_displacement
,
5740 (valueT
) (displacement_from_opcode_start
- extension
),
5741 DISP_SIZE_FROM_RELAX_STATE (fragP
->fr_subtype
));
5742 fragP
->fr_fix
+= extension
;
5745 /* Size of byte displacement jmp. */
5746 int md_short_jump_size
= 2;
5748 /* Size of dword displacement jmp. */
5749 int md_long_jump_size
= 5;
5752 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
5754 addressT from_addr
, to_addr
;
5755 fragS
*frag ATTRIBUTE_UNUSED
;
5756 symbolS
*to_symbol ATTRIBUTE_UNUSED
;
5760 offset
= to_addr
- (from_addr
+ 2);
5761 /* Opcode for byte-disp jump. */
5762 md_number_to_chars (ptr
, (valueT
) 0xeb, 1);
5763 md_number_to_chars (ptr
+ 1, (valueT
) offset
, 1);
5767 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
5769 addressT from_addr
, to_addr
;
5770 fragS
*frag ATTRIBUTE_UNUSED
;
5771 symbolS
*to_symbol ATTRIBUTE_UNUSED
;
5775 offset
= to_addr
- (from_addr
+ 5);
5776 md_number_to_chars (ptr
, (valueT
) 0xe9, 1);
5777 md_number_to_chars (ptr
+ 1, (valueT
) offset
, 4);
5780 /* Apply a fixup (fixS) to segment data, once it has been determined
5781 by our caller that we have all the info we need to fix it up.
5783 On the 386, immediates, displacements, and data pointers are all in
5784 the same (little-endian) format, so we don't need to care about which
5788 md_apply_fix (fixP
, valP
, seg
)
5789 /* The fix we're to put in. */
5791 /* Pointer to the value of the bits. */
5793 /* Segment fix is from. */
5794 segT seg ATTRIBUTE_UNUSED
;
5796 char *p
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
5797 valueT value
= *valP
;
5799 #if !defined (TE_Mach)
5802 switch (fixP
->fx_r_type
)
5808 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
5811 case BFD_RELOC_X86_64_32S
:
5812 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
5815 fixP
->fx_r_type
= BFD_RELOC_16_PCREL
;
5818 fixP
->fx_r_type
= BFD_RELOC_8_PCREL
;
5823 if (fixP
->fx_addsy
!= NULL
5824 && (fixP
->fx_r_type
== BFD_RELOC_32_PCREL
5825 || fixP
->fx_r_type
== BFD_RELOC_64_PCREL
5826 || fixP
->fx_r_type
== BFD_RELOC_16_PCREL
5827 || fixP
->fx_r_type
== BFD_RELOC_8_PCREL
)
5828 && !use_rela_relocations
)
5830 /* This is a hack. There should be a better way to handle this.
5831 This covers for the fact that bfd_install_relocation will
5832 subtract the current location (for partial_inplace, PC relative
5833 relocations); see more below. */
5837 || OUTPUT_FLAVOR
== bfd_target_coff_flavour
5840 value
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
5842 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
5845 segT sym_seg
= S_GET_SEGMENT (fixP
->fx_addsy
);
5848 || (symbol_section_p (fixP
->fx_addsy
)
5849 && sym_seg
!= absolute_section
))
5850 && !generic_force_reloc (fixP
))
5852 /* Yes, we add the values in twice. This is because
5853 bfd_install_relocation subtracts them out again. I think
5854 bfd_install_relocation is broken, but I don't dare change
5856 value
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
5860 #if defined (OBJ_COFF) && defined (TE_PE)
5861 /* For some reason, the PE format does not store a
5862 section address offset for a PC relative symbol. */
5863 if (S_GET_SEGMENT (fixP
->fx_addsy
) != seg
5864 || S_IS_WEAK (fixP
->fx_addsy
))
5865 value
+= md_pcrel_from (fixP
);
5869 /* Fix a few things - the dynamic linker expects certain values here,
5870 and we must not disappoint it. */
5871 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
5872 if (IS_ELF
&& fixP
->fx_addsy
)
5873 switch (fixP
->fx_r_type
)
5875 case BFD_RELOC_386_PLT32
:
5876 case BFD_RELOC_X86_64_PLT32
:
5877 /* Make the jump instruction point to the address of the operand. At
5878 runtime we merely add the offset to the actual PLT entry. */
5882 case BFD_RELOC_386_TLS_GD
:
5883 case BFD_RELOC_386_TLS_LDM
:
5884 case BFD_RELOC_386_TLS_IE_32
:
5885 case BFD_RELOC_386_TLS_IE
:
5886 case BFD_RELOC_386_TLS_GOTIE
:
5887 case BFD_RELOC_386_TLS_GOTDESC
:
5888 case BFD_RELOC_X86_64_TLSGD
:
5889 case BFD_RELOC_X86_64_TLSLD
:
5890 case BFD_RELOC_X86_64_GOTTPOFF
:
5891 case BFD_RELOC_X86_64_GOTPC32_TLSDESC
:
5892 value
= 0; /* Fully resolved at runtime. No addend. */
5894 case BFD_RELOC_386_TLS_LE
:
5895 case BFD_RELOC_386_TLS_LDO_32
:
5896 case BFD_RELOC_386_TLS_LE_32
:
5897 case BFD_RELOC_X86_64_DTPOFF32
:
5898 case BFD_RELOC_X86_64_DTPOFF64
:
5899 case BFD_RELOC_X86_64_TPOFF32
:
5900 case BFD_RELOC_X86_64_TPOFF64
:
5901 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
5904 case BFD_RELOC_386_TLS_DESC_CALL
:
5905 case BFD_RELOC_X86_64_TLSDESC_CALL
:
5906 value
= 0; /* Fully resolved at runtime. No addend. */
5907 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
5911 case BFD_RELOC_386_GOT32
:
5912 case BFD_RELOC_X86_64_GOT32
:
5913 value
= 0; /* Fully resolved at runtime. No addend. */
5916 case BFD_RELOC_VTABLE_INHERIT
:
5917 case BFD_RELOC_VTABLE_ENTRY
:
5924 #endif /* defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) */
5926 #endif /* !defined (TE_Mach) */
5928 /* Are we finished with this relocation now? */
5929 if (fixP
->fx_addsy
== NULL
)
5931 else if (use_rela_relocations
)
5933 fixP
->fx_no_overflow
= 1;
5934 /* Remember value for tc_gen_reloc. */
5935 fixP
->fx_addnumber
= value
;
5939 md_number_to_chars (p
, value
, fixP
->fx_size
);
5942 #define MAX_LITTLENUMS 6
5944 /* Turn the string pointed to by litP into a floating point constant
5945 of type TYPE, and emit the appropriate bytes. The number of
5946 LITTLENUMS emitted is stored in *SIZEP. An error message is
5947 returned, or NULL on OK. */
5950 md_atof (type
, litP
, sizeP
)
5956 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
5957 LITTLENUM_TYPE
*wordP
;
5979 return _("Bad call to md_atof ()");
5981 t
= atof_ieee (input_line_pointer
, type
, words
);
5983 input_line_pointer
= t
;
5985 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
5986 /* This loops outputs the LITTLENUMs in REVERSE order; in accord with
5987 the bigendian 386. */
5988 for (wordP
= words
+ prec
- 1; prec
--;)
5990 md_number_to_chars (litP
, (valueT
) (*wordP
--), sizeof (LITTLENUM_TYPE
));
5991 litP
+= sizeof (LITTLENUM_TYPE
);
5996 static char output_invalid_buf
[sizeof (unsigned char) * 2 + 6];
5999 output_invalid (int c
)
6002 snprintf (output_invalid_buf
, sizeof (output_invalid_buf
),
6005 snprintf (output_invalid_buf
, sizeof (output_invalid_buf
),
6006 "(0x%x)", (unsigned char) c
);
6007 return output_invalid_buf
;
6010 /* REG_STRING starts *before* REGISTER_PREFIX. */
6012 static const reg_entry
*
6013 parse_real_register (char *reg_string
, char **end_op
)
6015 char *s
= reg_string
;
6017 char reg_name_given
[MAX_REG_NAME_SIZE
+ 1];
6020 /* Skip possible REGISTER_PREFIX and possible whitespace. */
6021 if (*s
== REGISTER_PREFIX
)
6024 if (is_space_char (*s
))
6028 while ((*p
++ = register_chars
[(unsigned char) *s
]) != '\0')
6030 if (p
>= reg_name_given
+ MAX_REG_NAME_SIZE
)
6031 return (const reg_entry
*) NULL
;
6035 /* For naked regs, make sure that we are not dealing with an identifier.
6036 This prevents confusing an identifier like `eax_var' with register
6038 if (allow_naked_reg
&& identifier_chars
[(unsigned char) *s
])
6039 return (const reg_entry
*) NULL
;
6043 r
= (const reg_entry
*) hash_find (reg_hash
, reg_name_given
);
6045 /* Handle floating point regs, allowing spaces in the (i) part. */
6046 if (r
== i386_regtab
/* %st is first entry of table */)
6048 if (is_space_char (*s
))
6053 if (is_space_char (*s
))
6055 if (*s
>= '0' && *s
<= '7')
6059 if (is_space_char (*s
))
6064 r
= hash_find (reg_hash
, "st(0)");
6069 /* We have "%st(" then garbage. */
6070 return (const reg_entry
*) NULL
;
6075 && ((r
->reg_flags
& (RegRex64
| RegRex
)) | (r
->reg_type
& Reg64
)) != 0
6076 && (r
->reg_type
!= Control
|| !(cpu_arch_flags
& CpuSledgehammer
))
6077 && flag_code
!= CODE_64BIT
)
6078 return (const reg_entry
*) NULL
;
6083 /* REG_STRING starts *before* REGISTER_PREFIX. */
6085 static const reg_entry
*
6086 parse_register (char *reg_string
, char **end_op
)
6090 if (*reg_string
== REGISTER_PREFIX
|| allow_naked_reg
)
6091 r
= parse_real_register (reg_string
, end_op
);
6096 char *save
= input_line_pointer
;
6100 input_line_pointer
= reg_string
;
6101 c
= get_symbol_end ();
6102 symbolP
= symbol_find (reg_string
);
6103 if (symbolP
&& S_GET_SEGMENT (symbolP
) == reg_section
)
6105 const expressionS
*e
= symbol_get_value_expression (symbolP
);
6107 know (e
->X_op
== O_register
);
6108 know (e
->X_add_number
>= 0
6109 && (valueT
) e
->X_add_number
< i386_regtab_size
);
6110 r
= i386_regtab
+ e
->X_add_number
;
6111 *end_op
= input_line_pointer
;
6113 *input_line_pointer
= c
;
6114 input_line_pointer
= save
;
6120 i386_parse_name (char *name
, expressionS
*e
, char *nextcharP
)
6123 char *end
= input_line_pointer
;
6126 r
= parse_register (name
, &input_line_pointer
);
6127 if (r
&& end
<= input_line_pointer
)
6129 *nextcharP
= *input_line_pointer
;
6130 *input_line_pointer
= 0;
6131 e
->X_op
= O_register
;
6132 e
->X_add_number
= r
- i386_regtab
;
6135 input_line_pointer
= end
;
6141 md_operand (expressionS
*e
)
6143 if (*input_line_pointer
== REGISTER_PREFIX
)
6146 const reg_entry
*r
= parse_real_register (input_line_pointer
, &end
);
6150 e
->X_op
= O_register
;
6151 e
->X_add_number
= r
- i386_regtab
;
6152 input_line_pointer
= end
;
6158 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
6159 const char *md_shortopts
= "kVQ:sqn";
6161 const char *md_shortopts
= "qn";
6164 #define OPTION_32 (OPTION_MD_BASE + 0)
6165 #define OPTION_64 (OPTION_MD_BASE + 1)
6166 #define OPTION_DIVIDE (OPTION_MD_BASE + 2)
6167 #define OPTION_MARCH (OPTION_MD_BASE + 3)
6168 #define OPTION_MTUNE (OPTION_MD_BASE + 4)
6169 #define OPTION_NACL_ALIGN (OPTION_MD_BASE + 5)
6170 #define OPTION_NACL_LIBRARY_MODE (OPTION_MD_BASE + 6)
6173 struct option md_longopts
[] =
6175 {"32", no_argument
, NULL
, OPTION_32
},
6176 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) || defined(TE_PEP)
6177 {"64", no_argument
, NULL
, OPTION_64
},
6179 {"divide", no_argument
, NULL
, OPTION_DIVIDE
},
6180 {"march", required_argument
, NULL
, OPTION_MARCH
},
6181 {"mtune", required_argument
, NULL
, OPTION_MTUNE
},
6182 {"nacl-align", required_argument
, NULL
, OPTION_NACL_ALIGN
},
6183 {"nacl-library-mode", no_argument
, NULL
, OPTION_NACL_LIBRARY_MODE
},
6184 {NULL
, no_argument
, NULL
, 0}
6186 size_t md_longopts_size
= sizeof (md_longopts
);
6189 md_parse_option (int c
, char *arg
)
6196 optimize_align_code
= 0;
6203 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
6204 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
6205 should be emitted or not. FIXME: Not implemented. */
6209 /* -V: SVR4 argument to print version ID. */
6211 print_version_id ();
6214 /* -k: Ignore for FreeBSD compatibility. */
6219 /* -s: On i386 Solaris, this tells the native assembler to use
6220 .stab instead of .stab.excl. We always use .stab anyhow. */
6223 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) || defined(TE_PEP)
6226 const char **list
, **l
;
6228 list
= bfd_target_list ();
6229 for (l
= list
; *l
!= NULL
; l
++)
6230 if (CONST_STRNEQ (*l
, "elf64-x86-64")
6231 || strcmp (*l
, "coff-x86-64") == 0
6232 || strcmp (*l
, "pe-x86-64") == 0
6233 || strcmp (*l
, "pei-x86-64") == 0)
6235 default_arch
= "x86_64";
6239 as_fatal (_("No compiled in support for x86_64"));
6246 default_arch
= "i386";
6250 #ifdef SVR4_COMMENT_CHARS
6255 n
= (char *) xmalloc (strlen (i386_comment_chars
) + 1);
6257 for (s
= i386_comment_chars
; *s
!= '\0'; s
++)
6261 i386_comment_chars
= n
;
6268 as_fatal (_("Invalid -march= option: `%s'"), arg
);
6269 for (i
= 0; i
< ARRAY_SIZE (cpu_arch
); i
++)
6271 if (strcmp (arg
, cpu_arch
[i
].name
) == 0)
6273 cpu_arch_isa
= cpu_arch
[i
].type
;
6274 cpu_arch_isa_flags
= cpu_arch
[i
].flags
;
6275 if (!cpu_arch_tune_set
)
6277 cpu_arch_tune
= cpu_arch_isa
;
6278 cpu_arch_tune_flags
= cpu_arch_isa_flags
;
6283 if (i
>= ARRAY_SIZE (cpu_arch
))
6284 as_fatal (_("Invalid -march= option: `%s'"), arg
);
6289 as_fatal (_("Invalid -mtune= option: `%s'"), arg
);
6290 for (i
= 0; i
< ARRAY_SIZE (cpu_arch
); i
++)
6292 if (strcmp (arg
, cpu_arch
[i
].name
) == 0)
6294 cpu_arch_tune_set
= 1;
6295 cpu_arch_tune
= cpu_arch
[i
].type
;
6296 cpu_arch_tune_flags
= cpu_arch
[i
].flags
;
6300 if (i
>= ARRAY_SIZE (cpu_arch
))
6301 as_fatal (_("Invalid -mtune= option: `%s'"), arg
);
6304 case OPTION_NACL_ALIGN
:
6306 nacl_alignment
= atoi (optarg
);
6307 if (nacl_alignment
< 0)
6308 as_fatal (_("--nacl-align needs a non-negative argument"));
6312 case OPTION_NACL_LIBRARY_MODE
:
6314 nacl_library_mode
= 1;
6325 md_show_usage (stream
)
6328 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
6329 fprintf (stream
, _("\
6331 -V print assembler version number\n\
6334 fprintf (stream
, _("\
6335 -n Do not optimize code alignment\n\
6336 -q quieten some warnings\n"));
6337 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
6338 fprintf (stream
, _("\
6341 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) || defined(TE_PEP)
6342 fprintf (stream
, _("\
6343 --32/--64 generate 32bit/64bit code\n"));
6345 #ifdef SVR4_COMMENT_CHARS
6346 fprintf (stream
, _("\
6347 --divide do not treat `/' as a comment character\n"));
6349 fprintf (stream
, _("\
6350 --divide ignored\n"));
6352 fprintf (stream
, _("\
6353 -march=CPU/-mtune=CPU generate code/optimize for CPU, where CPU is one of:\n\
6354 i386, i486, pentium, pentiumpro, pentium4, nocona,\n\
6355 core, core2, k6, athlon, k8, generic32, generic64\n"));
6359 #if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \
6360 || defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) || defined (TE_PEP))
6362 /* Pick the target format to use. */
6365 i386_target_format (void)
6367 if (!strcmp (default_arch
, "x86_64"))
6369 set_code_flag (CODE_64BIT
);
6370 if (cpu_arch_isa_flags
== 0)
6371 cpu_arch_isa_flags
= Cpu186
|Cpu286
|Cpu386
|Cpu486
6372 |Cpu586
|Cpu686
|CpuP4
|CpuMMX
|CpuMMX2
6374 if (cpu_arch_tune_flags
== 0)
6375 cpu_arch_tune_flags
= Cpu186
|Cpu286
|Cpu386
|Cpu486
6376 |Cpu586
|Cpu686
|CpuP4
|CpuMMX
|CpuMMX2
6379 else if (!strcmp (default_arch
, "i386"))
6381 set_code_flag (CODE_32BIT
);
6382 if (cpu_arch_isa_flags
== 0)
6383 cpu_arch_isa_flags
= Cpu186
|Cpu286
|Cpu386
;
6384 if (cpu_arch_tune_flags
== 0)
6385 cpu_arch_tune_flags
= Cpu186
|Cpu286
|Cpu386
;
6388 as_fatal (_("Unknown architecture"));
6389 switch (OUTPUT_FLAVOR
)
6392 case bfd_target_coff_flavour
:
6393 return flag_code
== CODE_64BIT
? COFF_TARGET_FORMAT
: "coff-i386";
6396 #ifdef OBJ_MAYBE_AOUT
6397 case bfd_target_aout_flavour
:
6398 return AOUT_TARGET_FORMAT
;
6400 #ifdef OBJ_MAYBE_COFF
6401 case bfd_target_coff_flavour
:
6404 #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF)
6405 case bfd_target_elf_flavour
:
6407 if (flag_code
== CODE_64BIT
)
6410 use_rela_relocations
= 1;
6412 return flag_code
== CODE_64BIT
? ELF_TARGET_FORMAT64
: ELF_TARGET_FORMAT
;
6421 #endif /* OBJ_MAYBE_ more than one */
6423 #if (defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF))
6425 i386_elf_emit_arch_note (void)
6427 if (IS_ELF
&& cpu_arch_name
!= NULL
)
6430 asection
*seg
= now_seg
;
6431 subsegT subseg
= now_subseg
;
6432 Elf_Internal_Note i_note
;
6433 Elf_External_Note e_note
;
6434 asection
*note_secp
;
6437 /* Create the .note section. */
6438 note_secp
= subseg_new (".note", 0);
6439 bfd_set_section_flags (stdoutput
,
6441 SEC_HAS_CONTENTS
| SEC_READONLY
);
6443 /* Process the arch string. */
6444 len
= strlen (cpu_arch_name
);
6446 i_note
.namesz
= len
+ 1;
6448 i_note
.type
= NT_ARCH
;
6449 p
= frag_more (sizeof (e_note
.namesz
));
6450 md_number_to_chars (p
, (valueT
) i_note
.namesz
, sizeof (e_note
.namesz
));
6451 p
= frag_more (sizeof (e_note
.descsz
));
6452 md_number_to_chars (p
, (valueT
) i_note
.descsz
, sizeof (e_note
.descsz
));
6453 p
= frag_more (sizeof (e_note
.type
));
6454 md_number_to_chars (p
, (valueT
) i_note
.type
, sizeof (e_note
.type
));
6455 p
= frag_more (len
+ 1);
6456 strcpy (p
, cpu_arch_name
);
6458 frag_align (2, 0, 0);
6460 subseg_set (seg
, subseg
);
6466 md_undefined_symbol (name
)
6469 if (name
[0] == GLOBAL_OFFSET_TABLE_NAME
[0]
6470 && name
[1] == GLOBAL_OFFSET_TABLE_NAME
[1]
6471 && name
[2] == GLOBAL_OFFSET_TABLE_NAME
[2]
6472 && strcmp (name
, GLOBAL_OFFSET_TABLE_NAME
) == 0)
6476 if (symbol_find (name
))
6477 as_bad (_("GOT already in symbol table"));
6478 GOT_symbol
= symbol_new (name
, undefined_section
,
6479 (valueT
) 0, &zero_address_frag
);
6486 /* Round up a section size to the appropriate boundary. */
6489 md_section_align (segment
, size
)
6490 segT segment ATTRIBUTE_UNUSED
;
6493 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
6494 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
)
6496 /* For a.out, force the section size to be aligned. If we don't do
6497 this, BFD will align it for us, but it will not write out the
6498 final bytes of the section. This may be a bug in BFD, but it is
6499 easier to fix it here since that is how the other a.out targets
6503 align
= bfd_get_section_alignment (stdoutput
, segment
);
6504 size
= ((size
+ (1 << align
) - 1) & ((valueT
) -1 << align
));
6511 /* On the i386, PC-relative offsets are relative to the start of the
6512 next instruction. That is, the address of the offset, plus its
6513 size, since the offset is always the last part of the insn. */
6516 md_pcrel_from (fixS
*fixP
)
6518 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
6524 s_bss (int ignore ATTRIBUTE_UNUSED
)
6528 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
6530 obj_elf_section_change_hook ();
6532 temp
= get_absolute_expression ();
6533 subseg_set (bss_section
, (subsegT
) temp
);
6534 demand_empty_rest_of_line ();
6540 i386_validate_fix (fixS
*fixp
)
6542 if (fixp
->fx_subsy
&& fixp
->fx_subsy
== GOT_symbol
)
6544 if (fixp
->fx_r_type
== BFD_RELOC_32_PCREL
)
6548 fixp
->fx_r_type
= BFD_RELOC_X86_64_GOTPCREL
;
6553 fixp
->fx_r_type
= BFD_RELOC_386_GOTOFF
;
6555 fixp
->fx_r_type
= BFD_RELOC_X86_64_GOTOFF64
;
6562 tc_gen_reloc (section
, fixp
)
6563 asection
*section ATTRIBUTE_UNUSED
;
6567 bfd_reloc_code_real_type code
;
6569 switch (fixp
->fx_r_type
)
6571 case BFD_RELOC_X86_64_PLT32
:
6572 case BFD_RELOC_X86_64_GOT32
:
6573 case BFD_RELOC_X86_64_GOTPCREL
:
6574 case BFD_RELOC_386_PLT32
:
6575 case BFD_RELOC_386_GOT32
:
6576 case BFD_RELOC_386_GOTOFF
:
6577 case BFD_RELOC_386_GOTPC
:
6578 case BFD_RELOC_386_TLS_GD
:
6579 case BFD_RELOC_386_TLS_LDM
:
6580 case BFD_RELOC_386_TLS_LDO_32
:
6581 case BFD_RELOC_386_TLS_IE_32
:
6582 case BFD_RELOC_386_TLS_IE
:
6583 case BFD_RELOC_386_TLS_GOTIE
:
6584 case BFD_RELOC_386_TLS_LE_32
:
6585 case BFD_RELOC_386_TLS_LE
:
6586 case BFD_RELOC_386_TLS_GOTDESC
:
6587 case BFD_RELOC_386_TLS_DESC_CALL
:
6588 case BFD_RELOC_X86_64_TLSGD
:
6589 case BFD_RELOC_X86_64_TLSLD
:
6590 case BFD_RELOC_X86_64_DTPOFF32
:
6591 case BFD_RELOC_X86_64_DTPOFF64
:
6592 case BFD_RELOC_X86_64_GOTTPOFF
:
6593 case BFD_RELOC_X86_64_TPOFF32
:
6594 case BFD_RELOC_X86_64_TPOFF64
:
6595 case BFD_RELOC_X86_64_GOTOFF64
:
6596 case BFD_RELOC_X86_64_GOTPC32
:
6597 case BFD_RELOC_X86_64_GOT64
:
6598 case BFD_RELOC_X86_64_GOTPCREL64
:
6599 case BFD_RELOC_X86_64_GOTPC64
:
6600 case BFD_RELOC_X86_64_GOTPLT64
:
6601 case BFD_RELOC_X86_64_PLTOFF64
:
6602 case BFD_RELOC_X86_64_GOTPC32_TLSDESC
:
6603 case BFD_RELOC_X86_64_TLSDESC_CALL
:
6605 case BFD_RELOC_VTABLE_ENTRY
:
6606 case BFD_RELOC_VTABLE_INHERIT
:
6608 case BFD_RELOC_32_SECREL
:
6610 code
= fixp
->fx_r_type
;
6612 case BFD_RELOC_X86_64_32S
:
6613 if (!fixp
->fx_pcrel
)
6615 /* Don't turn BFD_RELOC_X86_64_32S into BFD_RELOC_32. */
6616 code
= fixp
->fx_r_type
;
6622 switch (fixp
->fx_size
)
6625 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6626 _("can not do %d byte pc-relative relocation"),
6628 code
= BFD_RELOC_32_PCREL
;
6630 case 1: code
= BFD_RELOC_8_PCREL
; break;
6631 case 2: code
= BFD_RELOC_16_PCREL
; break;
6632 case 4: code
= BFD_RELOC_32_PCREL
; break;
6634 case 8: code
= BFD_RELOC_64_PCREL
; break;
6640 switch (fixp
->fx_size
)
6643 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6644 _("can not do %d byte relocation"),
6646 code
= BFD_RELOC_32
;
6648 case 1: code
= BFD_RELOC_8
; break;
6649 case 2: code
= BFD_RELOC_16
; break;
6650 case 4: code
= BFD_RELOC_32
; break;
6652 case 8: code
= BFD_RELOC_64
; break;
6659 if ((code
== BFD_RELOC_32
6660 || code
== BFD_RELOC_32_PCREL
6661 || code
== BFD_RELOC_X86_64_32S
)
6663 && fixp
->fx_addsy
== GOT_symbol
)
6666 code
= BFD_RELOC_386_GOTPC
;
6668 code
= BFD_RELOC_X86_64_GOTPC32
;
6670 if ((code
== BFD_RELOC_64
|| code
== BFD_RELOC_64_PCREL
)
6672 && fixp
->fx_addsy
== GOT_symbol
)
6674 code
= BFD_RELOC_X86_64_GOTPC64
;
6677 rel
= (arelent
*) xmalloc (sizeof (arelent
));
6678 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
6679 *rel
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
6681 rel
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
6683 if (!use_rela_relocations
)
6685 /* HACK: Since i386 ELF uses Rel instead of Rela, encode the
6686 vtable entry to be used in the relocation's section offset. */
6687 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
6688 rel
->address
= fixp
->fx_offset
;
6692 /* Use the rela in 64bit mode. */
6695 if (!fixp
->fx_pcrel
)
6696 rel
->addend
= fixp
->fx_offset
;
6700 case BFD_RELOC_X86_64_PLT32
:
6701 case BFD_RELOC_X86_64_GOT32
:
6702 case BFD_RELOC_X86_64_GOTPCREL
:
6703 case BFD_RELOC_X86_64_TLSGD
:
6704 case BFD_RELOC_X86_64_TLSLD
:
6705 case BFD_RELOC_X86_64_GOTTPOFF
:
6706 case BFD_RELOC_X86_64_GOTPC32_TLSDESC
:
6707 case BFD_RELOC_X86_64_TLSDESC_CALL
:
6708 rel
->addend
= fixp
->fx_offset
- fixp
->fx_size
;
6711 rel
->addend
= (section
->vma
6713 + fixp
->fx_addnumber
6714 + md_pcrel_from (fixp
));
6719 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
6720 if (rel
->howto
== NULL
)
6722 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6723 _("cannot represent relocation type %s"),
6724 bfd_get_reloc_code_name (code
));
6725 /* Set howto to a garbage value so that we can keep going. */
6726 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, BFD_RELOC_32
);
6727 assert (rel
->howto
!= NULL
);
6734 /* Parse operands using Intel syntax. This implements a recursive descent
6735 parser based on the BNF grammar published in Appendix B of the MASM 6.1
6738 FIXME: We do not recognize the full operand grammar defined in the MASM
6739 documentation. In particular, all the structure/union and
6740 high-level macro operands are missing.
6742 Uppercase words are terminals, lower case words are non-terminals.
6743 Objects surrounded by double brackets '[[' ']]' are optional. Vertical
6744 bars '|' denote choices. Most grammar productions are implemented in
6745 functions called 'intel_<production>'.
6747 Initial production is 'expr'.
6753 binOp & | AND | \| | OR | ^ | XOR
6755 byteRegister AL | AH | BL | BH | CL | CH | DL | DH
6757 constant digits [[ radixOverride ]]
6759 dataType BYTE | WORD | DWORD | FWORD | QWORD | TBYTE | OWORD | XMMWORD
6797 => expr expr cmpOp e04
6800 gpRegister AX | EAX | BX | EBX | CX | ECX | DX | EDX
6801 | BP | EBP | SP | ESP | DI | EDI | SI | ESI
6803 hexdigit a | b | c | d | e | f
6804 | A | B | C | D | E | F
6810 mulOp * | / | % | MOD | << | SHL | >> | SHR
6814 register specialRegister
6818 segmentRegister CS | DS | ES | FS | GS | SS
6820 specialRegister CR0 | CR2 | CR3 | CR4
6821 | DR0 | DR1 | DR2 | DR3 | DR6 | DR7
6822 | TR3 | TR4 | TR5 | TR6 | TR7
6824 We simplify the grammar in obvious places (e.g., register parsing is
6825 done by calling parse_register) and eliminate immediate left recursion
6826 to implement a recursive-descent parser.
6830 expr' cmpOp e04 expr'
6881 /* Parsing structure for the intel syntax parser. Used to implement the
6882 semantic actions for the operand grammar. */
6883 struct intel_parser_s
6885 char *op_string
; /* The string being parsed. */
6886 int got_a_float
; /* Whether the operand is a float. */
6887 int op_modifier
; /* Operand modifier. */
6888 int is_mem
; /* 1 if operand is memory reference. */
6889 int in_offset
; /* >=1 if parsing operand of offset. */
6890 int in_bracket
; /* >=1 if parsing operand in brackets. */
6891 const reg_entry
*reg
; /* Last register reference found. */
6892 char *disp
; /* Displacement string being built. */
6893 char *next_operand
; /* Resume point when splitting operands. */
6896 static struct intel_parser_s intel_parser
;
6898 /* Token structure for parsing intel syntax. */
6901 int code
; /* Token code. */
6902 const reg_entry
*reg
; /* Register entry for register tokens. */
6903 char *str
; /* String representation. */
6906 static struct intel_token cur_token
, prev_token
;
6908 /* Token codes for the intel parser. Since T_SHORT is already used
6909 by COFF, undefine it first to prevent a warning. */
6928 /* Prototypes for intel parser functions. */
6929 static int intel_match_token (int);
6930 static void intel_putback_token (void);
6931 static void intel_get_token (void);
6932 static int intel_expr (void);
6933 static int intel_e04 (void);
6934 static int intel_e05 (void);
6935 static int intel_e06 (void);
6936 static int intel_e09 (void);
6937 static int intel_e10 (void);
6938 static int intel_e11 (void);
6941 i386_intel_operand (char *operand_string
, int got_a_float
)
6946 p
= intel_parser
.op_string
= xstrdup (operand_string
);
6947 intel_parser
.disp
= (char *) xmalloc (strlen (operand_string
) + 1);
6951 /* Initialize token holders. */
6952 cur_token
.code
= prev_token
.code
= T_NIL
;
6953 cur_token
.reg
= prev_token
.reg
= NULL
;
6954 cur_token
.str
= prev_token
.str
= NULL
;
6956 /* Initialize parser structure. */
6957 intel_parser
.got_a_float
= got_a_float
;
6958 intel_parser
.op_modifier
= 0;
6959 intel_parser
.is_mem
= 0;
6960 intel_parser
.in_offset
= 0;
6961 intel_parser
.in_bracket
= 0;
6962 intel_parser
.reg
= NULL
;
6963 intel_parser
.disp
[0] = '\0';
6964 intel_parser
.next_operand
= NULL
;
6966 /* Read the first token and start the parser. */
6968 ret
= intel_expr ();
6973 if (cur_token
.code
!= T_NIL
)
6975 as_bad (_("invalid operand for '%s' ('%s' unexpected)"),
6976 current_templates
->start
->name
, cur_token
.str
);
6979 /* If we found a memory reference, hand it over to i386_displacement
6980 to fill in the rest of the operand fields. */
6981 else if (intel_parser
.is_mem
)
6983 if ((i
.mem_operands
== 1
6984 && (current_templates
->start
->opcode_modifier
& IsString
) == 0)
6985 || i
.mem_operands
== 2)
6987 as_bad (_("too many memory references for '%s'"),
6988 current_templates
->start
->name
);
6993 char *s
= intel_parser
.disp
;
6996 if (!quiet_warnings
&& intel_parser
.is_mem
< 0)
6997 /* See the comments in intel_bracket_expr. */
6998 as_warn (_("Treating `%s' as memory reference"), operand_string
);
7000 /* Add the displacement expression. */
7002 ret
= i386_displacement (s
, s
+ strlen (s
));
7005 /* Swap base and index in 16-bit memory operands like
7006 [si+bx]. Since i386_index_check is also used in AT&T
7007 mode we have to do that here. */
7010 && (i
.base_reg
->reg_type
& Reg16
)
7011 && (i
.index_reg
->reg_type
& Reg16
)
7012 && i
.base_reg
->reg_num
>= 6
7013 && i
.index_reg
->reg_num
< 6)
7015 const reg_entry
*base
= i
.index_reg
;
7017 i
.index_reg
= i
.base_reg
;
7020 ret
= i386_index_check (operand_string
);
7025 /* Constant and OFFSET expressions are handled by i386_immediate. */
7026 else if ((intel_parser
.op_modifier
& (1 << T_OFFSET
))
7027 || intel_parser
.reg
== NULL
)
7028 ret
= i386_immediate (intel_parser
.disp
);
7030 if (intel_parser
.next_operand
&& this_operand
>= MAX_OPERANDS
- 1)
7032 if (!ret
|| !intel_parser
.next_operand
)
7034 intel_parser
.op_string
= intel_parser
.next_operand
;
7035 this_operand
= i
.operands
++;
7039 free (intel_parser
.disp
);
7044 #define NUM_ADDRESS_REGS (!!i.base_reg + !!i.index_reg)
7048 expr' cmpOp e04 expr'
7053 /* XXX Implement the comparison operators. */
7054 return intel_e04 ();
7071 if (nregs
>= 0 && NUM_ADDRESS_REGS
> nregs
)
7072 i
.base_reg
= i386_regtab
+ REGNAM_AL
; /* al is invalid as base */
7074 if (cur_token
.code
== '+')
7076 else if (cur_token
.code
== '-')
7077 nregs
= NUM_ADDRESS_REGS
;
7081 strcat (intel_parser
.disp
, cur_token
.str
);
7082 intel_match_token (cur_token
.code
);
7093 int nregs
= ~NUM_ADDRESS_REGS
;
7100 if (cur_token
.code
== '&'
7101 || cur_token
.code
== '|'
7102 || cur_token
.code
== '^')
7106 str
[0] = cur_token
.code
;
7108 strcat (intel_parser
.disp
, str
);
7113 intel_match_token (cur_token
.code
);
7118 if (nregs
>= 0 && NUM_ADDRESS_REGS
> nregs
)
7119 i
.base_reg
= i386_regtab
+ REGNAM_AL
+ 1; /* cl is invalid as base */
7130 int nregs
= ~NUM_ADDRESS_REGS
;
7137 if (cur_token
.code
== '*'
7138 || cur_token
.code
== '/'
7139 || cur_token
.code
== '%')
7143 str
[0] = cur_token
.code
;
7145 strcat (intel_parser
.disp
, str
);
7147 else if (cur_token
.code
== T_SHL
)
7148 strcat (intel_parser
.disp
, "<<");
7149 else if (cur_token
.code
== T_SHR
)
7150 strcat (intel_parser
.disp
, ">>");
7154 intel_match_token (cur_token
.code
);
7159 if (nregs
>= 0 && NUM_ADDRESS_REGS
> nregs
)
7160 i
.base_reg
= i386_regtab
+ REGNAM_AL
+ 2; /* dl is invalid as base */
7178 int nregs
= ~NUM_ADDRESS_REGS
;
7183 /* Don't consume constants here. */
7184 if (cur_token
.code
== '+' || cur_token
.code
== '-')
7186 /* Need to look one token ahead - if the next token
7187 is a constant, the current token is its sign. */
7190 intel_match_token (cur_token
.code
);
7191 next_code
= cur_token
.code
;
7192 intel_putback_token ();
7193 if (next_code
== T_CONST
)
7197 /* e09 OFFSET e09 */
7198 if (cur_token
.code
== T_OFFSET
)
7201 ++intel_parser
.in_offset
;
7205 else if (cur_token
.code
== T_SHORT
)
7206 intel_parser
.op_modifier
|= 1 << T_SHORT
;
7209 else if (cur_token
.code
== '+')
7210 strcat (intel_parser
.disp
, "+");
7215 else if (cur_token
.code
== '-' || cur_token
.code
== '~')
7221 str
[0] = cur_token
.code
;
7223 strcat (intel_parser
.disp
, str
);
7230 intel_match_token (cur_token
.code
);
7238 /* e09' PTR e10 e09' */
7239 if (cur_token
.code
== T_PTR
)
7243 if (prev_token
.code
== T_BYTE
)
7244 suffix
= BYTE_MNEM_SUFFIX
;
7246 else if (prev_token
.code
== T_WORD
)
7248 if (current_templates
->start
->name
[0] == 'l'
7249 && current_templates
->start
->name
[2] == 's'
7250 && current_templates
->start
->name
[3] == 0)
7251 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
7252 else if (intel_parser
.got_a_float
== 2) /* "fi..." */
7253 suffix
= SHORT_MNEM_SUFFIX
;
7255 suffix
= WORD_MNEM_SUFFIX
;
7258 else if (prev_token
.code
== T_DWORD
)
7260 if (current_templates
->start
->name
[0] == 'l'
7261 && current_templates
->start
->name
[2] == 's'
7262 && current_templates
->start
->name
[3] == 0)
7263 suffix
= WORD_MNEM_SUFFIX
;
7264 else if (flag_code
== CODE_16BIT
7265 && (current_templates
->start
->opcode_modifier
7266 & (Jump
| JumpDword
)))
7267 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
7268 else if (intel_parser
.got_a_float
== 1) /* "f..." */
7269 suffix
= SHORT_MNEM_SUFFIX
;
7271 suffix
= LONG_MNEM_SUFFIX
;
7274 else if (prev_token
.code
== T_FWORD
)
7276 if (current_templates
->start
->name
[0] == 'l'
7277 && current_templates
->start
->name
[2] == 's'
7278 && current_templates
->start
->name
[3] == 0)
7279 suffix
= LONG_MNEM_SUFFIX
;
7280 else if (!intel_parser
.got_a_float
)
7282 if (flag_code
== CODE_16BIT
)
7283 add_prefix (DATA_PREFIX_OPCODE
);
7284 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
7287 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
7290 else if (prev_token
.code
== T_QWORD
)
7292 if (intel_parser
.got_a_float
== 1) /* "f..." */
7293 suffix
= LONG_MNEM_SUFFIX
;
7295 suffix
= QWORD_MNEM_SUFFIX
;
7298 else if (prev_token
.code
== T_TBYTE
)
7300 if (intel_parser
.got_a_float
== 1)
7301 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
7303 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
7306 else if (prev_token
.code
== T_XMMWORD
)
7308 /* XXX ignored for now, but accepted since gcc uses it */
7314 as_bad (_("Unknown operand modifier `%s'"), prev_token
.str
);
7318 /* Operands for jump/call using 'ptr' notation denote absolute
7320 if (current_templates
->start
->opcode_modifier
& (Jump
| JumpDword
))
7321 i
.types
[this_operand
] |= JumpAbsolute
;
7323 if (current_templates
->start
->base_opcode
== 0x8d /* lea */)
7327 else if (i
.suffix
!= suffix
)
7329 as_bad (_("Conflicting operand modifiers"));
7335 /* e09' : e10 e09' */
7336 else if (cur_token
.code
== ':')
7338 if (prev_token
.code
!= T_REG
)
7340 /* While {call,jmp} SSSS:OOOO is MASM syntax only when SSSS is a
7341 segment/group identifier (which we don't have), using comma
7342 as the operand separator there is even less consistent, since
7343 there all branches only have a single operand. */
7344 if (this_operand
!= 0
7345 || intel_parser
.in_offset
7346 || intel_parser
.in_bracket
7347 || (!(current_templates
->start
->opcode_modifier
7348 & (Jump
|JumpDword
|JumpInterSegment
))
7349 && !(current_templates
->start
->operand_types
[0]
7351 return intel_match_token (T_NIL
);
7352 /* Remember the start of the 2nd operand and terminate 1st
7354 XXX This isn't right, yet (when SSSS:OOOO is right operand of
7355 another expression), but it gets at least the simplest case
7356 (a plain number or symbol on the left side) right. */
7357 intel_parser
.next_operand
= intel_parser
.op_string
;
7358 *--intel_parser
.op_string
= '\0';
7359 return intel_match_token (':');
7367 intel_match_token (cur_token
.code
);
7373 --intel_parser
.in_offset
;
7376 if (NUM_ADDRESS_REGS
> nregs
)
7378 as_bad (_("Invalid operand to `OFFSET'"));
7381 intel_parser
.op_modifier
|= 1 << T_OFFSET
;
7384 if (nregs
>= 0 && NUM_ADDRESS_REGS
> nregs
)
7385 i
.base_reg
= i386_regtab
+ REGNAM_AL
+ 3; /* bl is invalid as base */
7390 intel_bracket_expr (void)
7392 int was_offset
= intel_parser
.op_modifier
& (1 << T_OFFSET
);
7393 const char *start
= intel_parser
.op_string
;
7396 if (i
.op
[this_operand
].regs
)
7397 return intel_match_token (T_NIL
);
7399 intel_match_token ('[');
7401 /* Mark as a memory operand only if it's not already known to be an
7402 offset expression. If it's an offset expression, we need to keep
7404 if (!intel_parser
.in_offset
)
7406 ++intel_parser
.in_bracket
;
7408 /* Operands for jump/call inside brackets denote absolute addresses. */
7409 if (current_templates
->start
->opcode_modifier
& (Jump
| JumpDword
))
7410 i
.types
[this_operand
] |= JumpAbsolute
;
7412 /* Unfortunately gas always diverged from MASM in a respect that can't
7413 be easily fixed without risking to break code sequences likely to be
7414 encountered (the testsuite even check for this): MASM doesn't consider
7415 an expression inside brackets unconditionally as a memory reference.
7416 When that is e.g. a constant, an offset expression, or the sum of the
7417 two, this is still taken as a constant load. gas, however, always
7418 treated these as memory references. As a compromise, we'll try to make
7419 offset expressions inside brackets work the MASM way (since that's
7420 less likely to be found in real world code), but make constants alone
7421 continue to work the traditional gas way. In either case, issue a
7423 intel_parser
.op_modifier
&= ~was_offset
;
7426 strcat (intel_parser
.disp
, "[");
7428 /* Add a '+' to the displacement string if necessary. */
7429 if (*intel_parser
.disp
!= '\0'
7430 && *(intel_parser
.disp
+ strlen (intel_parser
.disp
) - 1) != '+')
7431 strcat (intel_parser
.disp
, "+");
7434 && (len
= intel_parser
.op_string
- start
- 1,
7435 intel_match_token (']')))
7437 /* Preserve brackets when the operand is an offset expression. */
7438 if (intel_parser
.in_offset
)
7439 strcat (intel_parser
.disp
, "]");
7442 --intel_parser
.in_bracket
;
7443 if (i
.base_reg
|| i
.index_reg
)
7444 intel_parser
.is_mem
= 1;
7445 if (!intel_parser
.is_mem
)
7447 if (!(intel_parser
.op_modifier
& (1 << T_OFFSET
)))
7448 /* Defer the warning until all of the operand was parsed. */
7449 intel_parser
.is_mem
= -1;
7450 else if (!quiet_warnings
)
7451 as_warn (_("`[%.*s]' taken to mean just `%.*s'"),
7452 len
, start
, len
, start
);
7455 intel_parser
.op_modifier
|= was_offset
;
7472 while (cur_token
.code
== '[')
7474 if (!intel_bracket_expr ())
7499 switch (cur_token
.code
)
7503 intel_match_token ('(');
7504 strcat (intel_parser
.disp
, "(");
7506 if (intel_expr () && intel_match_token (')'))
7508 strcat (intel_parser
.disp
, ")");
7515 return intel_bracket_expr ();
7520 strcat (intel_parser
.disp
, cur_token
.str
);
7521 intel_match_token (cur_token
.code
);
7523 /* Mark as a memory operand only if it's not already known to be an
7524 offset expression. */
7525 if (!intel_parser
.in_offset
)
7526 intel_parser
.is_mem
= 1;
7533 const reg_entry
*reg
= intel_parser
.reg
= cur_token
.reg
;
7535 intel_match_token (T_REG
);
7537 /* Check for segment change. */
7538 if (cur_token
.code
== ':')
7540 if (!(reg
->reg_type
& (SReg2
| SReg3
)))
7542 as_bad (_("`%s' is not a valid segment register"),
7546 else if (i
.seg
[i
.mem_operands
])
7547 as_warn (_("Extra segment override ignored"));
7550 if (!intel_parser
.in_offset
)
7551 intel_parser
.is_mem
= 1;
7552 switch (reg
->reg_num
)
7555 i
.seg
[i
.mem_operands
] = &es
;
7558 i
.seg
[i
.mem_operands
] = &cs
;
7561 i
.seg
[i
.mem_operands
] = &ss
;
7564 i
.seg
[i
.mem_operands
] = &ds
;
7567 i
.seg
[i
.mem_operands
] = &fs
;
7570 i
.seg
[i
.mem_operands
] = &gs
;
7576 /* Not a segment register. Check for register scaling. */
7577 else if (cur_token
.code
== '*')
7579 if (!intel_parser
.in_bracket
)
7581 as_bad (_("Register scaling only allowed in memory operands"));
7585 if (reg
->reg_type
& Reg16
) /* Disallow things like [si*1]. */
7586 reg
= i386_regtab
+ REGNAM_AX
+ 4; /* sp is invalid as index */
7587 else if (i
.index_reg
)
7588 reg
= i386_regtab
+ REGNAM_EAX
+ 4; /* esp is invalid as index */
7590 /* What follows must be a valid scale. */
7591 intel_match_token ('*');
7593 i
.types
[this_operand
] |= BaseIndex
;
7595 /* Set the scale after setting the register (otherwise,
7596 i386_scale will complain) */
7597 if (cur_token
.code
== '+' || cur_token
.code
== '-')
7599 char *str
, sign
= cur_token
.code
;
7600 intel_match_token (cur_token
.code
);
7601 if (cur_token
.code
!= T_CONST
)
7603 as_bad (_("Syntax error: Expecting a constant, got `%s'"),
7607 str
= (char *) xmalloc (strlen (cur_token
.str
) + 2);
7608 strcpy (str
+ 1, cur_token
.str
);
7610 if (!i386_scale (str
))
7614 else if (!i386_scale (cur_token
.str
))
7616 intel_match_token (cur_token
.code
);
7619 /* No scaling. If this is a memory operand, the register is either a
7620 base register (first occurrence) or an index register (second
7622 else if (intel_parser
.in_bracket
)
7627 else if (!i
.index_reg
)
7631 as_bad (_("Too many register references in memory operand"));
7635 i
.types
[this_operand
] |= BaseIndex
;
7638 /* It's neither base nor index. */
7639 else if (!intel_parser
.in_offset
&& !intel_parser
.is_mem
)
7641 i
.types
[this_operand
] |= reg
->reg_type
& ~BaseIndex
;
7642 i
.op
[this_operand
].regs
= reg
;
7647 as_bad (_("Invalid use of register"));
7651 /* Since registers are not part of the displacement string (except
7652 when we're parsing offset operands), we may need to remove any
7653 preceding '+' from the displacement string. */
7654 if (*intel_parser
.disp
!= '\0'
7655 && !intel_parser
.in_offset
)
7657 char *s
= intel_parser
.disp
;
7658 s
+= strlen (s
) - 1;
7681 intel_match_token (cur_token
.code
);
7683 if (cur_token
.code
== T_PTR
)
7686 /* It must have been an identifier. */
7687 intel_putback_token ();
7688 cur_token
.code
= T_ID
;
7694 if (!intel_parser
.in_offset
&& intel_parser
.is_mem
<= 0)
7698 /* The identifier represents a memory reference only if it's not
7699 preceded by an offset modifier and if it's not an equate. */
7700 symbolP
= symbol_find(cur_token
.str
);
7701 if (!symbolP
|| S_GET_SEGMENT(symbolP
) != absolute_section
)
7702 intel_parser
.is_mem
= 1;
7710 char *save_str
, sign
= 0;
7712 /* Allow constants that start with `+' or `-'. */
7713 if (cur_token
.code
== '-' || cur_token
.code
== '+')
7715 sign
= cur_token
.code
;
7716 intel_match_token (cur_token
.code
);
7717 if (cur_token
.code
!= T_CONST
)
7719 as_bad (_("Syntax error: Expecting a constant, got `%s'"),
7725 save_str
= (char *) xmalloc (strlen (cur_token
.str
) + 2);
7726 strcpy (save_str
+ !!sign
, cur_token
.str
);
7730 /* Get the next token to check for register scaling. */
7731 intel_match_token (cur_token
.code
);
7733 /* Check if this constant is a scaling factor for an
7735 if (cur_token
.code
== '*')
7737 if (intel_match_token ('*') && cur_token
.code
== T_REG
)
7739 const reg_entry
*reg
= cur_token
.reg
;
7741 if (!intel_parser
.in_bracket
)
7743 as_bad (_("Register scaling only allowed "
7744 "in memory operands"));
7748 /* Disallow things like [1*si].
7749 sp and esp are invalid as index. */
7750 if (reg
->reg_type
& Reg16
)
7751 reg
= i386_regtab
+ REGNAM_AX
+ 4;
7752 else if (i
.index_reg
)
7753 reg
= i386_regtab
+ REGNAM_EAX
+ 4;
7755 /* The constant is followed by `* reg', so it must be
7758 i
.types
[this_operand
] |= BaseIndex
;
7760 /* Set the scale after setting the register (otherwise,
7761 i386_scale will complain) */
7762 if (!i386_scale (save_str
))
7764 intel_match_token (T_REG
);
7766 /* Since registers are not part of the displacement
7767 string, we may need to remove any preceding '+' from
7768 the displacement string. */
7769 if (*intel_parser
.disp
!= '\0')
7771 char *s
= intel_parser
.disp
;
7772 s
+= strlen (s
) - 1;
7782 /* The constant was not used for register scaling. Since we have
7783 already consumed the token following `*' we now need to put it
7784 back in the stream. */
7785 intel_putback_token ();
7788 /* Add the constant to the displacement string. */
7789 strcat (intel_parser
.disp
, save_str
);
7796 as_bad (_("Unrecognized token '%s'"), cur_token
.str
);
7800 /* Match the given token against cur_token. If they match, read the next
7801 token from the operand string. */
7803 intel_match_token (int code
)
7805 if (cur_token
.code
== code
)
7812 as_bad (_("Unexpected token `%s'"), cur_token
.str
);
7817 /* Read a new token from intel_parser.op_string and store it in cur_token. */
7819 intel_get_token (void)
7822 const reg_entry
*reg
;
7823 struct intel_token new_token
;
7825 new_token
.code
= T_NIL
;
7826 new_token
.reg
= NULL
;
7827 new_token
.str
= NULL
;
7829 /* Free the memory allocated to the previous token and move
7830 cur_token to prev_token. */
7832 free (prev_token
.str
);
7834 prev_token
= cur_token
;
7836 /* Skip whitespace. */
7837 while (is_space_char (*intel_parser
.op_string
))
7838 intel_parser
.op_string
++;
7840 /* Return an empty token if we find nothing else on the line. */
7841 if (*intel_parser
.op_string
== '\0')
7843 cur_token
= new_token
;
7847 /* The new token cannot be larger than the remainder of the operand
7849 new_token
.str
= (char *) xmalloc (strlen (intel_parser
.op_string
) + 1);
7850 new_token
.str
[0] = '\0';
7852 if (strchr ("0123456789", *intel_parser
.op_string
))
7854 char *p
= new_token
.str
;
7855 char *q
= intel_parser
.op_string
;
7856 new_token
.code
= T_CONST
;
7858 /* Allow any kind of identifier char to encompass floating point and
7859 hexadecimal numbers. */
7860 while (is_identifier_char (*q
))
7864 /* Recognize special symbol names [0-9][bf]. */
7865 if (strlen (intel_parser
.op_string
) == 2
7866 && (intel_parser
.op_string
[1] == 'b'
7867 || intel_parser
.op_string
[1] == 'f'))
7868 new_token
.code
= T_ID
;
7871 else if ((reg
= parse_register (intel_parser
.op_string
, &end_op
)) != NULL
)
7873 size_t len
= end_op
- intel_parser
.op_string
;
7875 new_token
.code
= T_REG
;
7876 new_token
.reg
= reg
;
7878 memcpy (new_token
.str
, intel_parser
.op_string
, len
);
7879 new_token
.str
[len
] = '\0';
7882 else if (is_identifier_char (*intel_parser
.op_string
))
7884 char *p
= new_token
.str
;
7885 char *q
= intel_parser
.op_string
;
7887 /* A '.' or '$' followed by an identifier char is an identifier.
7888 Otherwise, it's operator '.' followed by an expression. */
7889 if ((*q
== '.' || *q
== '$') && !is_identifier_char (*(q
+ 1)))
7891 new_token
.code
= '.';
7892 new_token
.str
[0] = '.';
7893 new_token
.str
[1] = '\0';
7897 while (is_identifier_char (*q
) || *q
== '@')
7901 if (strcasecmp (new_token
.str
, "NOT") == 0)
7902 new_token
.code
= '~';
7904 else if (strcasecmp (new_token
.str
, "MOD") == 0)
7905 new_token
.code
= '%';
7907 else if (strcasecmp (new_token
.str
, "AND") == 0)
7908 new_token
.code
= '&';
7910 else if (strcasecmp (new_token
.str
, "OR") == 0)
7911 new_token
.code
= '|';
7913 else if (strcasecmp (new_token
.str
, "XOR") == 0)
7914 new_token
.code
= '^';
7916 else if (strcasecmp (new_token
.str
, "SHL") == 0)
7917 new_token
.code
= T_SHL
;
7919 else if (strcasecmp (new_token
.str
, "SHR") == 0)
7920 new_token
.code
= T_SHR
;
7922 else if (strcasecmp (new_token
.str
, "BYTE") == 0)
7923 new_token
.code
= T_BYTE
;
7925 else if (strcasecmp (new_token
.str
, "WORD") == 0)
7926 new_token
.code
= T_WORD
;
7928 else if (strcasecmp (new_token
.str
, "DWORD") == 0)
7929 new_token
.code
= T_DWORD
;
7931 else if (strcasecmp (new_token
.str
, "FWORD") == 0)
7932 new_token
.code
= T_FWORD
;
7934 else if (strcasecmp (new_token
.str
, "QWORD") == 0)
7935 new_token
.code
= T_QWORD
;
7937 else if (strcasecmp (new_token
.str
, "TBYTE") == 0
7938 /* XXX remove (gcc still uses it) */
7939 || strcasecmp (new_token
.str
, "XWORD") == 0)
7940 new_token
.code
= T_TBYTE
;
7942 else if (strcasecmp (new_token
.str
, "XMMWORD") == 0
7943 || strcasecmp (new_token
.str
, "OWORD") == 0)
7944 new_token
.code
= T_XMMWORD
;
7946 else if (strcasecmp (new_token
.str
, "PTR") == 0)
7947 new_token
.code
= T_PTR
;
7949 else if (strcasecmp (new_token
.str
, "SHORT") == 0)
7950 new_token
.code
= T_SHORT
;
7952 else if (strcasecmp (new_token
.str
, "OFFSET") == 0)
7954 new_token
.code
= T_OFFSET
;
7956 /* ??? This is not mentioned in the MASM grammar but gcc
7957 makes use of it with -mintel-syntax. OFFSET may be
7958 followed by FLAT: */
7959 if (strncasecmp (q
, " FLAT:", 6) == 0)
7960 strcat (new_token
.str
, " FLAT:");
7963 /* ??? This is not mentioned in the MASM grammar. */
7964 else if (strcasecmp (new_token
.str
, "FLAT") == 0)
7966 new_token
.code
= T_OFFSET
;
7968 strcat (new_token
.str
, ":");
7970 as_bad (_("`:' expected"));
7974 new_token
.code
= T_ID
;
7978 else if (strchr ("+-/*%|&^:[]()~", *intel_parser
.op_string
))
7980 new_token
.code
= *intel_parser
.op_string
;
7981 new_token
.str
[0] = *intel_parser
.op_string
;
7982 new_token
.str
[1] = '\0';
7985 else if (strchr ("<>", *intel_parser
.op_string
)
7986 && *intel_parser
.op_string
== *(intel_parser
.op_string
+ 1))
7988 new_token
.code
= *intel_parser
.op_string
== '<' ? T_SHL
: T_SHR
;
7989 new_token
.str
[0] = *intel_parser
.op_string
;
7990 new_token
.str
[1] = *intel_parser
.op_string
;
7991 new_token
.str
[2] = '\0';
7995 as_bad (_("Unrecognized token `%s'"), intel_parser
.op_string
);
7997 intel_parser
.op_string
+= strlen (new_token
.str
);
7998 cur_token
= new_token
;
8001 /* Put cur_token back into the token stream and make cur_token point to
8004 intel_putback_token (void)
8006 if (cur_token
.code
!= T_NIL
)
8008 intel_parser
.op_string
-= strlen (cur_token
.str
);
8009 free (cur_token
.str
);
8011 cur_token
= prev_token
;
8013 /* Forget prev_token. */
8014 prev_token
.code
= T_NIL
;
8015 prev_token
.reg
= NULL
;
8016 prev_token
.str
= NULL
;
8020 tc_x86_regname_to_dw2regnum (char *regname
)
8022 unsigned int regnum
;
8023 unsigned int regnames_count
;
8024 static const char *const regnames_32
[] =
8026 "eax", "ecx", "edx", "ebx",
8027 "esp", "ebp", "esi", "edi",
8028 "eip", "eflags", NULL
,
8029 "st0", "st1", "st2", "st3",
8030 "st4", "st5", "st6", "st7",
8032 "xmm0", "xmm1", "xmm2", "xmm3",
8033 "xmm4", "xmm5", "xmm6", "xmm7",
8034 "mm0", "mm1", "mm2", "mm3",
8035 "mm4", "mm5", "mm6", "mm7",
8036 "fcw", "fsw", "mxcsr",
8037 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8040 static const char *const regnames_64
[] =
8042 "rax", "rdx", "rcx", "rbx",
8043 "rsi", "rdi", "rbp", "rsp",
8044 "r8", "r9", "r10", "r11",
8045 "r12", "r13", "r14", "r15",
8047 "xmm0", "xmm1", "xmm2", "xmm3",
8048 "xmm4", "xmm5", "xmm6", "xmm7",
8049 "xmm8", "xmm9", "xmm10", "xmm11",
8050 "xmm12", "xmm13", "xmm14", "xmm15",
8051 "st0", "st1", "st2", "st3",
8052 "st4", "st5", "st6", "st7",
8053 "mm0", "mm1", "mm2", "mm3",
8054 "mm4", "mm5", "mm6", "mm7",
8056 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8057 "fs.base", "gs.base", NULL
, NULL
,
8059 "mxcsr", "fcw", "fsw"
8061 const char *const *regnames
;
8063 if (flag_code
== CODE_64BIT
)
8065 regnames
= regnames_64
;
8066 regnames_count
= ARRAY_SIZE (regnames_64
);
8070 regnames
= regnames_32
;
8071 regnames_count
= ARRAY_SIZE (regnames_32
);
8074 for (regnum
= 0; regnum
< regnames_count
; regnum
++)
8075 if (regnames
[regnum
] != NULL
8076 && strcmp (regname
, regnames
[regnum
]) == 0)
8083 tc_x86_frame_initial_instructions (void)
8085 static unsigned int sp_regno
;
8088 sp_regno
= tc_x86_regname_to_dw2regnum (flag_code
== CODE_64BIT
8091 cfi_add_CFA_def_cfa (sp_regno
, -x86_cie_data_alignment
);
8092 cfi_add_CFA_offset (x86_dwarf2_return_column
, x86_cie_data_alignment
);
8096 i386_elf_section_type (const char *str
, size_t len
)
8098 if (flag_code
== CODE_64BIT
8099 && len
== sizeof ("unwind") - 1
8100 && strncmp (str
, "unwind", 6) == 0)
8101 return SHT_X86_64_UNWIND
;
8108 tc_pe_dwarf2_emit_offset (symbolS
*symbol
, unsigned int size
)
8112 expr
.X_op
= O_secrel
;
8113 expr
.X_add_symbol
= symbol
;
8114 expr
.X_add_number
= 0;
8115 emit_expr (&expr
, size
);
8119 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
8120 /* For ELF on x86-64, add support for SHF_X86_64_LARGE. */
8123 x86_64_section_letter (int letter
, char **ptr_msg
)
8125 if (flag_code
== CODE_64BIT
)
8128 return SHF_X86_64_LARGE
;
8130 *ptr_msg
= _("Bad .section directive: want a,l,w,x,M,S,G,T in string");
8133 *ptr_msg
= _("Bad .section directive: want a,w,x,M,S,G,T in string");
8138 x86_64_section_word (char *str
, size_t len
)
8140 if (len
== 5 && flag_code
== CODE_64BIT
&& CONST_STRNEQ (str
, "large"))
8141 return SHF_X86_64_LARGE
;
8147 handle_large_common (int small ATTRIBUTE_UNUSED
)
8149 if (flag_code
!= CODE_64BIT
)
8151 s_comm_internal (0, elf_common_parse
);
8152 as_warn (_(".largecomm supported only in 64bit mode, producing .comm"));
8156 static segT lbss_section
;
8157 asection
*saved_com_section_ptr
= elf_com_section_ptr
;
8158 asection
*saved_bss_section
= bss_section
;
8160 if (lbss_section
== NULL
)
8162 flagword applicable
;
8164 subsegT subseg
= now_subseg
;
8166 /* The .lbss section is for local .largecomm symbols. */
8167 lbss_section
= subseg_new (".lbss", 0);
8168 applicable
= bfd_applicable_section_flags (stdoutput
);
8169 bfd_set_section_flags (stdoutput
, lbss_section
,
8170 applicable
& SEC_ALLOC
);
8171 seg_info (lbss_section
)->bss
= 1;
8173 subseg_set (seg
, subseg
);
8176 elf_com_section_ptr
= &_bfd_elf_large_com_section
;
8177 bss_section
= lbss_section
;
8179 s_comm_internal (0, elf_common_parse
);
8181 elf_com_section_ptr
= saved_com_section_ptr
;
8182 bss_section
= saved_bss_section
;
8185 #endif /* OBJ_ELF || OBJ_MAYBE_ELF */