/src/binutils-gdb/gas/config/tc-i386.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* tc-i386.c -- Assemble code for the Intel 80386 |
2 | | Copyright (C) 1989-2023 Free Software Foundation, Inc. |
3 | | |
4 | | This file is part of GAS, the GNU Assembler. |
5 | | |
6 | | GAS is free software; you can redistribute it and/or modify |
7 | | it under the terms of the GNU General Public License as published by |
8 | | the Free Software Foundation; either version 3, or (at your option) |
9 | | any later version. |
10 | | |
11 | | GAS is distributed in the hope that it will be useful, |
12 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | GNU General Public License for more details. |
15 | | |
16 | | You should have received a copy of the GNU General Public License |
17 | | along with GAS; see the file COPYING. If not, write to the Free |
18 | | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
19 | | 02110-1301, USA. */ |
20 | | |
21 | | /* Intel 80386 machine specific gas. |
22 | | Written by Eliot Dresselhaus (eliot@mgm.mit.edu). |
23 | | x86_64 support by Jan Hubicka (jh@suse.cz) |
24 | | VIA PadLock support by Michal Ludvig (mludvig@suse.cz) |
25 | | Bugs & suggestions are completely welcome. This is free software. |
26 | | Please help us make it better. */ |
27 | | |
28 | | #include "as.h" |
29 | | #include "safe-ctype.h" |
30 | | #include "subsegs.h" |
31 | | #include "dwarf2dbg.h" |
32 | | #include "dw2gencfi.h" |
33 | | #include "gen-sframe.h" |
34 | | #include "sframe.h" |
35 | | #include "elf/x86-64.h" |
36 | | #include "opcodes/i386-init.h" |
37 | | #include "opcodes/i386-mnem.h" |
38 | | #include <limits.h> |
39 | | |
40 | | #ifndef INFER_ADDR_PREFIX |
41 | | #define INFER_ADDR_PREFIX 1 |
42 | | #endif |
43 | | |
44 | | #ifndef DEFAULT_ARCH |
45 | | #define DEFAULT_ARCH "i386" |
46 | | #endif |
47 | | |
48 | | #ifndef INLINE |
49 | | #if __GNUC__ >= 2 |
50 | | #define INLINE __inline__ |
51 | | #else |
52 | | #define INLINE |
53 | | #endif |
54 | | #endif |
55 | | |
56 | | /* Prefixes will be emitted in the order defined below. |
57 | | WAIT_PREFIX must be the first prefix since FWAIT is really is an |
58 | | instruction, and so must come before any prefixes. |
59 | | The preferred prefix order is SEG_PREFIX, ADDR_PREFIX, DATA_PREFIX, |
60 | | REP_PREFIX/HLE_PREFIX, LOCK_PREFIX. */ |
61 | 1.86k | #define WAIT_PREFIX 0 |
62 | 213k | #define SEG_PREFIX 1 |
63 | 1.05M | #define ADDR_PREFIX 2 |
64 | 952k | #define DATA_PREFIX 3 |
65 | 41.7k | #define REP_PREFIX 4 |
66 | 0 | #define HLE_PREFIX REP_PREFIX |
67 | 41.0k | #define BND_PREFIX REP_PREFIX |
68 | 772k | #define LOCK_PREFIX 5 |
69 | 843k | #define REX_PREFIX 6 /* must come last. */ |
70 | | #define MAX_PREFIXES 7 /* max prefixes per opcode */ |
71 | | |
72 | | /* we define the syntax here (modulo base,index,scale syntax) */ |
73 | 2.19M | #define REGISTER_PREFIX '%' |
74 | 420k | #define IMMEDIATE_PREFIX '$' |
75 | 842k | #define ABSOLUTE_PREFIX '*' |
76 | | |
77 | | /* these are the instruction mnemonic suffixes in AT&T syntax or |
78 | | memory operand size in Intel syntax. */ |
79 | 980k | #define WORD_MNEM_SUFFIX 'w' |
80 | 913k | #define BYTE_MNEM_SUFFIX 'b' |
81 | 1.17M | #define SHORT_MNEM_SUFFIX 's' |
82 | 2.87M | #define LONG_MNEM_SUFFIX 'l' |
83 | 3.32M | #define QWORD_MNEM_SUFFIX 'q' |
84 | | |
85 | 15.5M | #define END_OF_INSN '\0' |
86 | | |
87 | 1.73M | #define OPERAND_TYPE_NONE { .bitfield = { .class = ClassNone } } |
88 | | |
89 | | /* This matches the C -> StaticRounding alias in the opcode table. */ |
90 | 12 | #define commutative staticrounding |
91 | | |
92 | | /* |
93 | | 'templates' is for grouping together 'template' structures for opcodes |
94 | | of the same name. This is only used for storing the insns in the grand |
95 | | ole hash table of insns. |
96 | | The templates themselves start at START and range up to (but not including) |
97 | | END. |
98 | | */ |
99 | | typedef struct |
100 | | { |
101 | | const insn_template *start; |
102 | | const insn_template *end; |
103 | | } |
104 | | templates; |
105 | | |
106 | | /* 386 operand encoding bytes: see 386 book for details of this. */ |
107 | | typedef struct |
108 | | { |
109 | | unsigned int regmem; /* codes register or memory operand */ |
110 | | unsigned int reg; /* codes register operand (or extended opcode) */ |
111 | | unsigned int mode; /* how to interpret regmem & reg */ |
112 | | } |
113 | | modrm_byte; |
114 | | |
115 | | /* x86-64 extension prefix. */ |
116 | | typedef int rex_byte; |
117 | | |
118 | | /* 386 opcode byte to code indirect addressing. */ |
119 | | typedef struct |
120 | | { |
121 | | unsigned base; |
122 | | unsigned index; |
123 | | unsigned scale; |
124 | | } |
125 | | sib_byte; |
126 | | |
127 | | /* x86 arch names, types and features */ |
128 | | typedef struct |
129 | | { |
130 | | const char *name; /* arch name */ |
131 | | unsigned int len:8; /* arch string length */ |
132 | | bool skip:1; /* show_arch should skip this. */ |
133 | | enum processor_type type; /* arch type */ |
134 | | i386_cpu_flags enable; /* cpu feature enable flags */ |
135 | | i386_cpu_flags disable; /* cpu feature disable flags */ |
136 | | } |
137 | | arch_entry; |
138 | | |
139 | | static void update_code_flag (int, int); |
140 | | static void s_insn (int); |
141 | | static void set_code_flag (int); |
142 | | static void set_16bit_gcc_code_flag (int); |
143 | | static void set_intel_syntax (int); |
144 | | static void set_intel_mnemonic (int); |
145 | | static void set_allow_index_reg (int); |
146 | | static void set_check (int); |
147 | | static void set_cpu_arch (int); |
148 | | #ifdef TE_PE |
149 | | static void pe_directive_secrel (int); |
150 | | static void pe_directive_secidx (int); |
151 | | #endif |
152 | | static void signed_cons (int); |
153 | | static char *output_invalid (int c); |
154 | | static int i386_finalize_immediate (segT, expressionS *, i386_operand_type, |
155 | | const char *); |
156 | | static int i386_finalize_displacement (segT, expressionS *, i386_operand_type, |
157 | | const char *); |
158 | | static int i386_att_operand (char *); |
159 | | static int i386_intel_operand (char *, int); |
160 | | static int i386_intel_simplify (expressionS *); |
161 | | static int i386_intel_parse_name (const char *, expressionS *); |
162 | | static const reg_entry *parse_register (const char *, char **); |
163 | | static const char *parse_insn (const char *, char *, bool); |
164 | | static char *parse_operands (char *, const char *); |
165 | | static void swap_operands (void); |
166 | | static void swap_2_operands (unsigned int, unsigned int); |
167 | | static enum flag_code i386_addressing_mode (void); |
168 | | static void optimize_imm (void); |
169 | | static bool optimize_disp (const insn_template *t); |
170 | | static const insn_template *match_template (char); |
171 | | static int check_string (void); |
172 | | static int process_suffix (void); |
173 | | static int check_byte_reg (void); |
174 | | static int check_long_reg (void); |
175 | | static int check_qword_reg (void); |
176 | | static int check_word_reg (void); |
177 | | static int finalize_imm (void); |
178 | | static int process_operands (void); |
179 | | static const reg_entry *build_modrm_byte (void); |
180 | | static void output_insn (void); |
181 | | static void output_imm (fragS *, offsetT); |
182 | | static void output_disp (fragS *, offsetT); |
183 | | #ifndef I386COFF |
184 | | static void s_bss (int); |
185 | | #endif |
186 | | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
187 | | static void handle_large_common (int small ATTRIBUTE_UNUSED); |
188 | | |
189 | | /* GNU_PROPERTY_X86_ISA_1_USED. */ |
190 | | static unsigned int x86_isa_1_used; |
191 | | /* GNU_PROPERTY_X86_FEATURE_2_USED. */ |
192 | | static unsigned int x86_feature_2_used; |
193 | | /* Generate x86 used ISA and feature properties. */ |
194 | | static unsigned int x86_used_note = DEFAULT_X86_USED_NOTE; |
195 | | #endif |
196 | | |
197 | | static const char *default_arch = DEFAULT_ARCH; |
198 | | |
199 | | /* parse_register() returns this when a register alias cannot be used. */ |
200 | | static const reg_entry bad_reg = { "<bad>", OPERAND_TYPE_NONE, 0, 0, |
201 | | { Dw2Inval, Dw2Inval } }; |
202 | | |
203 | | static const reg_entry *reg_eax; |
204 | | static const reg_entry *reg_ds; |
205 | | static const reg_entry *reg_es; |
206 | | static const reg_entry *reg_ss; |
207 | | static const reg_entry *reg_st0; |
208 | | static const reg_entry *reg_k0; |
209 | | |
210 | | /* VEX prefix. */ |
211 | | typedef struct |
212 | | { |
213 | | /* VEX prefix is either 2 byte or 3 byte. EVEX is 4 byte. */ |
214 | | unsigned char bytes[4]; |
215 | | unsigned int length; |
216 | | /* Destination or source register specifier. */ |
217 | | const reg_entry *register_specifier; |
218 | | } vex_prefix; |
219 | | |
220 | | /* 'md_assemble ()' gathers together information and puts it into a |
221 | | i386_insn. */ |
222 | | |
223 | | union i386_op |
224 | | { |
225 | | expressionS *disps; |
226 | | expressionS *imms; |
227 | | const reg_entry *regs; |
228 | | }; |
229 | | |
230 | | enum i386_error |
231 | | { |
232 | | no_error, /* Must be first. */ |
233 | | operand_size_mismatch, |
234 | | operand_type_mismatch, |
235 | | register_type_mismatch, |
236 | | number_of_operands_mismatch, |
237 | | invalid_instruction_suffix, |
238 | | bad_imm4, |
239 | | unsupported_with_intel_mnemonic, |
240 | | unsupported_syntax, |
241 | | unsupported, |
242 | | unsupported_on_arch, |
243 | | unsupported_64bit, |
244 | | invalid_sib_address, |
245 | | invalid_vsib_address, |
246 | | invalid_vector_register_set, |
247 | | invalid_tmm_register_set, |
248 | | invalid_dest_and_src_register_set, |
249 | | unsupported_vector_index_register, |
250 | | unsupported_broadcast, |
251 | | broadcast_needed, |
252 | | unsupported_masking, |
253 | | mask_not_on_destination, |
254 | | no_default_mask, |
255 | | unsupported_rc_sae, |
256 | | invalid_register_operand, |
257 | | }; |
258 | | |
259 | | struct _i386_insn |
260 | | { |
261 | | /* TM holds the template for the insn were currently assembling. */ |
262 | | insn_template tm; |
263 | | |
264 | | /* SUFFIX holds the instruction size suffix for byte, word, dword |
265 | | or qword, if given. */ |
266 | | char suffix; |
267 | | |
268 | | /* OPCODE_LENGTH holds the number of base opcode bytes. */ |
269 | | unsigned char opcode_length; |
270 | | |
271 | | /* OPERANDS gives the number of given operands. */ |
272 | | unsigned int operands; |
273 | | |
274 | | /* REG_OPERANDS, DISP_OPERANDS, MEM_OPERANDS, IMM_OPERANDS give the number |
275 | | of given register, displacement, memory operands and immediate |
276 | | operands. */ |
277 | | unsigned int reg_operands, disp_operands, mem_operands, imm_operands; |
278 | | |
279 | | /* TYPES [i] is the type (see above #defines) which tells us how to |
280 | | use OP[i] for the corresponding operand. */ |
281 | | i386_operand_type types[MAX_OPERANDS]; |
282 | | |
283 | | /* Displacement expression, immediate expression, or register for each |
284 | | operand. */ |
285 | | union i386_op op[MAX_OPERANDS]; |
286 | | |
287 | | /* Flags for operands. */ |
288 | | unsigned int flags[MAX_OPERANDS]; |
289 | 11.6k | #define Operand_PCrel 1 |
290 | 952k | #define Operand_Mem 2 |
291 | 0 | #define Operand_Signed 4 /* .insn only */ |
292 | | |
293 | | /* Relocation type for operand */ |
294 | | enum bfd_reloc_code_real reloc[MAX_OPERANDS]; |
295 | | |
296 | | /* BASE_REG, INDEX_REG, and LOG2_SCALE_FACTOR are used to encode |
297 | | the base index byte below. */ |
298 | | const reg_entry *base_reg; |
299 | | const reg_entry *index_reg; |
300 | | unsigned int log2_scale_factor; |
301 | | |
302 | | /* SEG gives the seg_entries of this insn. They are zero unless |
303 | | explicit segment overrides are given. */ |
304 | | const reg_entry *seg[2]; |
305 | | |
306 | | /* PREFIX holds all the given prefix opcodes (usually null). |
307 | | PREFIXES is the number of prefix opcodes. */ |
308 | | unsigned int prefixes; |
309 | | unsigned char prefix[MAX_PREFIXES]; |
310 | | |
311 | | /* .insn allows for reserved opcode spaces. */ |
312 | | unsigned char insn_opcode_space; |
313 | | |
314 | | /* .insn also allows (requires) specifying immediate size. */ |
315 | | unsigned char imm_bits[MAX_OPERANDS]; |
316 | | |
317 | | /* Register is in low 3 bits of opcode. */ |
318 | | bool short_form; |
319 | | |
320 | | /* The operand to a branch insn indicates an absolute branch. */ |
321 | | bool jumpabsolute; |
322 | | |
323 | | /* The operand to a branch insn indicates a far branch. */ |
324 | | bool far_branch; |
325 | | |
326 | | /* There is a memory operand of (%dx) which should be only used |
327 | | with input/output instructions. */ |
328 | | bool input_output_operand; |
329 | | |
330 | | /* Extended states. */ |
331 | | enum |
332 | | { |
333 | | /* Use MMX state. */ |
334 | | xstate_mmx = 1 << 0, |
335 | | /* Use XMM state. */ |
336 | | xstate_xmm = 1 << 1, |
337 | | /* Use YMM state. */ |
338 | | xstate_ymm = 1 << 2 | xstate_xmm, |
339 | | /* Use ZMM state. */ |
340 | | xstate_zmm = 1 << 3 | xstate_ymm, |
341 | | /* Use TMM state. */ |
342 | | xstate_tmm = 1 << 4, |
343 | | /* Use MASK state. */ |
344 | | xstate_mask = 1 << 5 |
345 | | } xstate; |
346 | | |
347 | | /* Has GOTPC or TLS relocation. */ |
348 | | bool has_gotpc_tls_reloc; |
349 | | |
350 | | /* RM and SIB are the modrm byte and the sib byte where the |
351 | | addressing modes of this insn are encoded. */ |
352 | | modrm_byte rm; |
353 | | rex_byte rex; |
354 | | rex_byte vrex; |
355 | | sib_byte sib; |
356 | | vex_prefix vex; |
357 | | |
358 | | /* Masking attributes. |
359 | | |
360 | | The struct describes masking, applied to OPERAND in the instruction. |
361 | | REG is a pointer to the corresponding mask register. ZEROING tells |
362 | | whether merging or zeroing mask is used. */ |
363 | | struct Mask_Operation |
364 | | { |
365 | | const reg_entry *reg; |
366 | | unsigned int zeroing; |
367 | | /* The operand where this operation is associated. */ |
368 | | unsigned int operand; |
369 | | } mask; |
370 | | |
371 | | /* Rounding control and SAE attributes. */ |
372 | | struct RC_Operation |
373 | | { |
374 | | enum rc_type |
375 | | { |
376 | | rc_none = -1, |
377 | | rne, |
378 | | rd, |
379 | | ru, |
380 | | rz, |
381 | | saeonly |
382 | | } type; |
383 | | /* In Intel syntax the operand modifier form is supposed to be used, but |
384 | | we continue to accept the immediate forms as well. */ |
385 | | bool modifier; |
386 | | } rounding; |
387 | | |
388 | | /* Broadcasting attributes. |
389 | | |
390 | | The struct describes broadcasting, applied to OPERAND. TYPE is |
391 | | expresses the broadcast factor. */ |
392 | | struct Broadcast_Operation |
393 | | { |
394 | | /* Type of broadcast: {1to2}, {1to4}, {1to8}, {1to16} or {1to32}. */ |
395 | | unsigned int type; |
396 | | |
397 | | /* Index of broadcasted operand. */ |
398 | | unsigned int operand; |
399 | | |
400 | | /* Number of bytes to broadcast. */ |
401 | | unsigned int bytes; |
402 | | } broadcast; |
403 | | |
404 | | /* Compressed disp8*N attribute. */ |
405 | | unsigned int memshift; |
406 | | |
407 | | /* Prefer load or store in encoding. */ |
408 | | enum |
409 | | { |
410 | | dir_encoding_default = 0, |
411 | | dir_encoding_load, |
412 | | dir_encoding_store, |
413 | | dir_encoding_swap |
414 | | } dir_encoding; |
415 | | |
416 | | /* Prefer 8bit, 16bit, 32bit displacement in encoding. */ |
417 | | enum |
418 | | { |
419 | | disp_encoding_default = 0, |
420 | | disp_encoding_8bit, |
421 | | disp_encoding_16bit, |
422 | | disp_encoding_32bit |
423 | | } disp_encoding; |
424 | | |
425 | | /* Prefer the REX byte in encoding. */ |
426 | | bool rex_encoding; |
427 | | |
428 | | /* Disable instruction size optimization. */ |
429 | | bool no_optimize; |
430 | | |
431 | | /* How to encode vector instructions. */ |
432 | | enum |
433 | | { |
434 | | vex_encoding_default = 0, |
435 | | vex_encoding_vex, |
436 | | vex_encoding_vex3, |
437 | | vex_encoding_evex, |
438 | | vex_encoding_error |
439 | | } vec_encoding; |
440 | | |
441 | | /* REP prefix. */ |
442 | | const char *rep_prefix; |
443 | | |
444 | | /* HLE prefix. */ |
445 | | const char *hle_prefix; |
446 | | |
447 | | /* Have BND prefix. */ |
448 | | const char *bnd_prefix; |
449 | | |
450 | | /* Have NOTRACK prefix. */ |
451 | | const char *notrack_prefix; |
452 | | |
453 | | /* Error message. */ |
454 | | enum i386_error error; |
455 | | }; |
456 | | |
457 | | typedef struct _i386_insn i386_insn; |
458 | | |
459 | | /* Link RC type with corresponding string, that'll be looked for in |
460 | | asm. */ |
461 | | struct RC_name |
462 | | { |
463 | | enum rc_type type; |
464 | | const char *name; |
465 | | unsigned int len; |
466 | | }; |
467 | | |
468 | | static const struct RC_name RC_NamesTable[] = |
469 | | { |
470 | | { rne, STRING_COMMA_LEN ("rn-sae") }, |
471 | | { rd, STRING_COMMA_LEN ("rd-sae") }, |
472 | | { ru, STRING_COMMA_LEN ("ru-sae") }, |
473 | | { rz, STRING_COMMA_LEN ("rz-sae") }, |
474 | | { saeonly, STRING_COMMA_LEN ("sae") }, |
475 | | }; |
476 | | |
477 | | /* To be indexed by segment register number. */ |
478 | | static const unsigned char i386_seg_prefixes[] = { |
479 | | ES_PREFIX_OPCODE, |
480 | | CS_PREFIX_OPCODE, |
481 | | SS_PREFIX_OPCODE, |
482 | | DS_PREFIX_OPCODE, |
483 | | FS_PREFIX_OPCODE, |
484 | | GS_PREFIX_OPCODE |
485 | | }; |
486 | | |
487 | | /* List of chars besides those in app.c:symbol_chars that can start an |
488 | | operand. Used to prevent the scrubber eating vital white-space. */ |
489 | | const char extra_symbol_chars[] = "*%-([{}" |
490 | | #ifdef LEX_AT |
491 | | "@" |
492 | | #endif |
493 | | #ifdef LEX_QM |
494 | | "?" |
495 | | #endif |
496 | | ; |
497 | | |
498 | | #if ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) \ |
499 | | && !defined (TE_GNU) \ |
500 | | && !defined (TE_LINUX) \ |
501 | | && !defined (TE_Haiku) \ |
502 | | && !defined (TE_FreeBSD) \ |
503 | | && !defined (TE_DragonFly) \ |
504 | | && !defined (TE_NetBSD)) |
505 | | /* This array holds the chars that always start a comment. If the |
506 | | pre-processor is disabled, these aren't very useful. The option |
507 | | --divide will remove '/' from this list. */ |
508 | | const char *i386_comment_chars = "#/"; |
509 | | #define SVR4_COMMENT_CHARS 1 |
510 | | #define PREFIX_SEPARATOR '\\' |
511 | | |
512 | | #else |
513 | | const char *i386_comment_chars = "#"; |
514 | 1.53M | #define PREFIX_SEPARATOR '/' |
515 | | #endif |
516 | | |
517 | | /* This array holds the chars that only start a comment at the beginning of |
518 | | a line. If the line seems to have the form '# 123 filename' |
519 | | .line and .file directives will appear in the pre-processed output. |
520 | | Note that input_file.c hand checks for '#' at the beginning of the |
521 | | first line of the input file. This is because the compiler outputs |
522 | | #NO_APP at the beginning of its output. |
523 | | Also note that comments started like this one will always work if |
524 | | '/' isn't otherwise defined. */ |
525 | | const char line_comment_chars[] = "#/"; |
526 | | |
527 | | const char line_separator_chars[] = ";"; |
528 | | |
529 | | /* Chars that can be used to separate mant from exp in floating point |
530 | | nums. */ |
531 | | const char EXP_CHARS[] = "eE"; |
532 | | |
533 | | /* Chars that mean this number is a floating point constant |
534 | | As in 0f12.456 |
535 | | or 0d1.2345e12. */ |
536 | | const char FLT_CHARS[] = "fFdDxXhHbB"; |
537 | | |
538 | | /* Tables for lexical analysis. */ |
539 | | static char mnemonic_chars[256]; |
540 | | static char register_chars[256]; |
541 | | static char operand_chars[256]; |
542 | | |
543 | | /* Lexical macros. */ |
544 | 9.45M | #define is_operand_char(x) (operand_chars[(unsigned char) x]) |
545 | | #define is_register_char(x) (register_chars[(unsigned char) x]) |
546 | 6.99M | #define is_space_char(x) ((x) == ' ') |
547 | | |
548 | | /* All non-digit non-letter characters that may occur in an operand and |
549 | | which aren't already in extra_symbol_chars[]. */ |
550 | | static const char operand_special_chars[] = "$+,)._~/<>|&^!=:@]"; |
551 | | |
552 | | /* md_assemble() always leaves the strings it's passed unaltered. To |
553 | | effect this we maintain a stack of saved characters that we've smashed |
554 | | with '\0's (indicating end of strings for various sub-fields of the |
555 | | assembler instruction). */ |
556 | | static char save_stack[32]; |
557 | | static char *save_stack_p; |
558 | | #define END_STRING_AND_SAVE(s) \ |
559 | 662k | do { *save_stack_p++ = *(s); *(s) = '\0'; } while (0) |
560 | | #define RESTORE_END_STRING(s) \ |
561 | 660k | do { *(s) = *--save_stack_p; } while (0) |
562 | | |
563 | | /* The instruction we're assembling. */ |
564 | | static i386_insn i; |
565 | | |
566 | | /* Possible templates for current insn. */ |
567 | | static const templates *current_templates; |
568 | | |
569 | | /* Per instruction expressionS buffers: max displacements & immediates. */ |
570 | | static expressionS disp_expressions[MAX_MEMORY_OPERANDS]; |
571 | | static expressionS im_expressions[MAX_IMMEDIATE_OPERANDS]; |
572 | | |
573 | | /* Current operand we are working on. */ |
574 | | static int this_operand = -1; |
575 | | |
576 | | /* Are we processing a .insn directive? */ |
577 | 358k | #define dot_insn() (i.tm.mnem_off == MN__insn) |
578 | | |
579 | | /* We support four different modes. FLAG_CODE variable is used to distinguish |
580 | | these. */ |
581 | | |
582 | | enum flag_code { |
583 | | CODE_32BIT, |
584 | | CODE_16BIT, |
585 | | CODE_64BIT }; |
586 | | |
587 | | static enum flag_code flag_code; |
588 | | static unsigned int object_64bit; |
589 | | static unsigned int disallow_64bit_reloc; |
590 | | static int use_rela_relocations = 0; |
591 | | /* __tls_get_addr/___tls_get_addr symbol for TLS. */ |
592 | | static const char *tls_get_addr; |
593 | | |
594 | | #if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \ |
595 | | || defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \ |
596 | | || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O)) |
597 | | |
598 | | /* The ELF ABI to use. */ |
599 | | enum x86_elf_abi |
600 | | { |
601 | | I386_ABI, |
602 | | X86_64_ABI, |
603 | | X86_64_X32_ABI |
604 | | }; |
605 | | |
606 | | static enum x86_elf_abi x86_elf_abi = I386_ABI; |
607 | | #endif |
608 | | |
609 | | #if defined (TE_PE) || defined (TE_PEP) |
610 | | /* Use big object file format. */ |
611 | | static int use_big_obj = 0; |
612 | | #endif |
613 | | |
614 | | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
615 | | /* 1 if generating code for a shared library. */ |
616 | | static int shared = 0; |
617 | | |
618 | | unsigned int x86_sframe_cfa_sp_reg; |
619 | | /* The other CFA base register for SFrame stack trace info. */ |
620 | | unsigned int x86_sframe_cfa_fp_reg; |
621 | | unsigned int x86_sframe_cfa_ra_reg; |
622 | | |
623 | | #endif |
624 | | |
625 | | /* 1 for intel syntax, |
626 | | 0 if att syntax. */ |
627 | | static int intel_syntax = 0; |
628 | | |
629 | | static enum x86_64_isa |
630 | | { |
631 | | amd64 = 1, /* AMD64 ISA. */ |
632 | | intel64 /* Intel64 ISA. */ |
633 | | } isa64; |
634 | | |
635 | | /* 1 for intel mnemonic, |
636 | | 0 if att mnemonic. */ |
637 | | static int intel_mnemonic = !SYSV386_COMPAT; |
638 | | |
639 | | /* 1 if pseudo registers are permitted. */ |
640 | | static int allow_pseudo_reg = 0; |
641 | | |
642 | | /* 1 if register prefix % not required. */ |
643 | | static int allow_naked_reg = 0; |
644 | | |
645 | | /* 1 if the assembler should add BND prefix for all control-transferring |
646 | | instructions supporting it, even if this prefix wasn't specified |
647 | | explicitly. */ |
648 | | static int add_bnd_prefix = 0; |
649 | | |
650 | | /* 1 if pseudo index register, eiz/riz, is allowed . */ |
651 | | static int allow_index_reg = 0; |
652 | | |
653 | | /* 1 if the assembler should ignore LOCK prefix, even if it was |
654 | | specified explicitly. */ |
655 | | static int omit_lock_prefix = 0; |
656 | | |
657 | | /* 1 if the assembler should encode lfence, mfence, and sfence as |
658 | | "lock addl $0, (%{re}sp)". */ |
659 | | static int avoid_fence = 0; |
660 | | |
661 | | /* 1 if lfence should be inserted after every load. */ |
662 | | static int lfence_after_load = 0; |
663 | | |
664 | | /* Non-zero if lfence should be inserted before indirect branch. */ |
665 | | static enum lfence_before_indirect_branch_kind |
666 | | { |
667 | | lfence_branch_none = 0, |
668 | | lfence_branch_register, |
669 | | lfence_branch_memory, |
670 | | lfence_branch_all |
671 | | } |
672 | | lfence_before_indirect_branch; |
673 | | |
674 | | /* Non-zero if lfence should be inserted before ret. */ |
675 | | static enum lfence_before_ret_kind |
676 | | { |
677 | | lfence_before_ret_none = 0, |
678 | | lfence_before_ret_not, |
679 | | lfence_before_ret_or, |
680 | | lfence_before_ret_shl |
681 | | } |
682 | | lfence_before_ret; |
683 | | |
684 | | /* Types of previous instruction is .byte or prefix. */ |
685 | | static struct |
686 | | { |
687 | | segT seg; |
688 | | const char *file; |
689 | | const char *name; |
690 | | unsigned int line; |
691 | | enum last_insn_kind |
692 | | { |
693 | | last_insn_other = 0, |
694 | | last_insn_directive, |
695 | | last_insn_prefix |
696 | | } kind; |
697 | | } last_insn; |
698 | | |
699 | | /* 1 if the assembler should generate relax relocations. */ |
700 | | |
701 | | static int generate_relax_relocations |
702 | | = DEFAULT_GENERATE_X86_RELAX_RELOCATIONS; |
703 | | |
704 | | static enum check_kind |
705 | | { |
706 | | check_none = 0, |
707 | | check_warning, |
708 | | check_error |
709 | | } |
710 | | sse_check, operand_check = check_warning; |
711 | | |
712 | | /* Non-zero if branches should be aligned within power of 2 boundary. */ |
713 | | static int align_branch_power = 0; |
714 | | |
715 | | /* Types of branches to align. */ |
716 | | enum align_branch_kind |
717 | | { |
718 | | align_branch_none = 0, |
719 | | align_branch_jcc = 1, |
720 | | align_branch_fused = 2, |
721 | | align_branch_jmp = 3, |
722 | | align_branch_call = 4, |
723 | | align_branch_indirect = 5, |
724 | | align_branch_ret = 6 |
725 | | }; |
726 | | |
727 | | /* Type bits of branches to align. */ |
728 | | enum align_branch_bit |
729 | | { |
730 | | align_branch_jcc_bit = 1 << align_branch_jcc, |
731 | | align_branch_fused_bit = 1 << align_branch_fused, |
732 | | align_branch_jmp_bit = 1 << align_branch_jmp, |
733 | | align_branch_call_bit = 1 << align_branch_call, |
734 | | align_branch_indirect_bit = 1 << align_branch_indirect, |
735 | | align_branch_ret_bit = 1 << align_branch_ret |
736 | | }; |
737 | | |
738 | | static unsigned int align_branch = (align_branch_jcc_bit |
739 | | | align_branch_fused_bit |
740 | | | align_branch_jmp_bit); |
741 | | |
742 | | /* Types of condition jump used by macro-fusion. */ |
743 | | enum mf_jcc_kind |
744 | | { |
745 | | mf_jcc_jo = 0, /* base opcode 0x70 */ |
746 | | mf_jcc_jc, /* base opcode 0x72 */ |
747 | | mf_jcc_je, /* base opcode 0x74 */ |
748 | | mf_jcc_jna, /* base opcode 0x76 */ |
749 | | mf_jcc_js, /* base opcode 0x78 */ |
750 | | mf_jcc_jp, /* base opcode 0x7a */ |
751 | | mf_jcc_jl, /* base opcode 0x7c */ |
752 | | mf_jcc_jle, /* base opcode 0x7e */ |
753 | | }; |
754 | | |
755 | | /* Types of compare flag-modifying insntructions used by macro-fusion. */ |
756 | | enum mf_cmp_kind |
757 | | { |
758 | | mf_cmp_test_and, /* test/cmp */ |
759 | | mf_cmp_alu_cmp, /* add/sub/cmp */ |
760 | | mf_cmp_incdec /* inc/dec */ |
761 | | }; |
762 | | |
763 | | /* The maximum padding size for fused jcc. CMP like instruction can |
764 | | be 9 bytes and jcc can be 6 bytes. Leave room just in case for |
765 | | prefixes. */ |
766 | 1.15k | #define MAX_FUSED_JCC_PADDING_SIZE 20 |
767 | | |
768 | | /* The maximum number of prefixes added for an instruction. */ |
769 | | static unsigned int align_branch_prefix_size = 5; |
770 | | |
771 | | /* Optimization: |
772 | | 1. Clear the REX_W bit with register operand if possible. |
773 | | 2. Above plus use 128bit vector instruction to clear the full vector |
774 | | register. |
775 | | */ |
776 | | static int optimize = 0; |
777 | | |
778 | | /* Optimization: |
779 | | 1. Clear the REX_W bit with register operand if possible. |
780 | | 2. Above plus use 128bit vector instruction to clear the full vector |
781 | | register. |
782 | | 3. Above plus optimize "test{q,l,w} $imm8,%r{64,32,16}" to |
783 | | "testb $imm7,%r8". |
784 | | */ |
785 | | static int optimize_for_space = 0; |
786 | | |
787 | | /* Register prefix used for error message. */ |
788 | | static const char *register_prefix = "%"; |
789 | | |
790 | | /* Used in 16 bit gcc mode to add an l suffix to call, ret, enter, |
791 | | leave, push, and pop instructions so that gcc has the same stack |
792 | | frame as in 32 bit mode. */ |
793 | | static char stackop_size = '\0'; |
794 | | |
795 | | /* Non-zero to optimize code alignment. */ |
796 | | int optimize_align_code = 1; |
797 | | |
798 | | /* Non-zero to quieten some warnings. */ |
799 | | static int quiet_warnings = 0; |
800 | | |
801 | | /* Guard to avoid repeated warnings about non-16-bit code on 16-bit CPUs. */ |
802 | | static bool pre_386_16bit_warned; |
803 | | |
804 | | /* CPU name. */ |
805 | | static const char *cpu_arch_name = NULL; |
806 | | static char *cpu_sub_arch_name = NULL; |
807 | | |
808 | | /* CPU feature flags. */ |
809 | | static i386_cpu_flags cpu_arch_flags = CPU_UNKNOWN_FLAGS; |
810 | | |
811 | | /* If we have selected a cpu we are generating instructions for. */ |
812 | | static int cpu_arch_tune_set = 0; |
813 | | |
814 | | /* Cpu we are generating instructions for. */ |
815 | | enum processor_type cpu_arch_tune = PROCESSOR_UNKNOWN; |
816 | | |
817 | | /* CPU feature flags of cpu we are generating instructions for. */ |
818 | | static i386_cpu_flags cpu_arch_tune_flags; |
819 | | |
820 | | /* CPU instruction set architecture used. */ |
821 | | enum processor_type cpu_arch_isa = PROCESSOR_UNKNOWN; |
822 | | |
823 | | /* CPU feature flags of instruction set architecture used. */ |
824 | | i386_cpu_flags cpu_arch_isa_flags; |
825 | | |
826 | | /* If set, conditional jumps are not automatically promoted to handle |
827 | | larger than a byte offset. */ |
828 | | static bool no_cond_jump_promotion = false; |
829 | | |
830 | | /* This will be set from an expression parser hook if there's any |
831 | | applicable operator involved in an expression. */ |
832 | | static enum { |
833 | | expr_operator_none, |
834 | | expr_operator_present, |
835 | | expr_large_value, |
836 | | } expr_mode; |
837 | | |
838 | | /* Encode SSE instructions with VEX prefix. */ |
839 | | static unsigned int sse2avx; |
840 | | |
841 | | /* Encode aligned vector move as unaligned vector move. */ |
842 | | static unsigned int use_unaligned_vector_move; |
843 | | |
844 | | /* Encode scalar AVX instructions with specific vector length. */ |
845 | | static enum |
846 | | { |
847 | | vex128 = 0, |
848 | | vex256 |
849 | | } avxscalar; |
850 | | |
851 | | /* Encode VEX WIG instructions with specific vex.w. */ |
852 | | static enum |
853 | | { |
854 | | vexw0 = 0, |
855 | | vexw1 |
856 | | } vexwig; |
857 | | |
858 | | /* Encode scalar EVEX LIG instructions with specific vector length. */ |
859 | | static enum |
860 | | { |
861 | | evexl128 = 0, |
862 | | evexl256, |
863 | | evexl512 |
864 | | } evexlig; |
865 | | |
866 | | /* Encode EVEX WIG instructions with specific evex.w. */ |
867 | | static enum |
868 | | { |
869 | | evexw0 = 0, |
870 | | evexw1 |
871 | | } evexwig; |
872 | | |
873 | | /* Value to encode in EVEX RC bits, for SAE-only instructions. */ |
874 | | static enum rc_type evexrcig = rne; |
875 | | |
876 | | /* Pre-defined "_GLOBAL_OFFSET_TABLE_". */ |
877 | | static symbolS *GOT_symbol; |
878 | | |
879 | | /* The dwarf2 return column, adjusted for 32 or 64 bit. */ |
880 | | unsigned int x86_dwarf2_return_column; |
881 | | |
882 | | /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */ |
883 | | int x86_cie_data_alignment; |
884 | | |
885 | | /* Interface to relax_segment. |
886 | | There are 3 major relax states for 386 jump insns because the |
887 | | different types of jumps add different sizes to frags when we're |
888 | | figuring out what sort of jump to choose to reach a given label. |
889 | | |
890 | | BRANCH_PADDING, BRANCH_PREFIX and FUSED_JCC_PADDING are used to align |
891 | | branches which are handled by md_estimate_size_before_relax() and |
892 | | i386_generic_table_relax_frag(). */ |
893 | | |
894 | | /* Types. */ |
895 | 0 | #define UNCOND_JUMP 0 |
896 | 0 | #define COND_JUMP 1 |
897 | 0 | #define COND_JUMP86 2 |
898 | 0 | #define BRANCH_PADDING 3 |
899 | 0 | #define BRANCH_PREFIX 4 |
900 | 0 | #define FUSED_JCC_PADDING 5 |
901 | | |
902 | | /* Sizes. */ |
903 | 8.77k | #define CODE16 1 |
904 | 39.9k | #define SMALL 0 |
905 | | #define SMALL16 (SMALL | CODE16) |
906 | 0 | #define BIG 2 |
907 | 0 | #define BIG16 (BIG | CODE16) |
908 | | |
909 | | #ifndef INLINE |
910 | | #ifdef __GNUC__ |
911 | | #define INLINE __inline__ |
912 | | #else |
913 | | #define INLINE |
914 | | #endif |
915 | | #endif |
916 | | |
917 | | #define ENCODE_RELAX_STATE(type, size) \ |
918 | 19.9k | ((relax_substateT) (((type) << 2) | (size))) |
919 | | #define TYPE_FROM_RELAX_STATE(s) \ |
920 | 0 | ((s) >> 2) |
921 | | #define DISP_SIZE_FROM_RELAX_STATE(s) \ |
922 | 0 | ((((s) & 3) == BIG ? 4 : (((s) & 3) == BIG16 ? 2 : 1))) |
923 | | |
924 | | /* This table is used by relax_frag to promote short jumps to long |
925 | | ones where necessary. SMALL (short) jumps may be promoted to BIG |
926 | | (32 bit long) ones, and SMALL16 jumps to BIG16 (16 bit long). We |
927 | | don't allow a short jump in a 32 bit code segment to be promoted to |
928 | | a 16 bit offset jump because it's slower (requires data size |
929 | | prefix), and doesn't work, unless the destination is in the bottom |
930 | | 64k of the code segment (The top 16 bits of eip are zeroed). */ |
931 | | |
932 | | const relax_typeS md_relax_table[] = |
933 | | { |
934 | | /* The fields are: |
935 | | 1) most positive reach of this state, |
936 | | 2) most negative reach of this state, |
937 | | 3) how many bytes this mode will have in the variable part of the frag |
938 | | 4) which index into the table to try if we can't fit into this one. */ |
939 | | |
940 | | /* UNCOND_JUMP states. */ |
941 | | {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (UNCOND_JUMP, BIG)}, |
942 | | {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (UNCOND_JUMP, BIG16)}, |
943 | | /* dword jmp adds 4 bytes to frag: |
944 | | 0 extra opcode bytes, 4 displacement bytes. */ |
945 | | {0, 0, 4, 0}, |
946 | | /* word jmp adds 2 byte2 to frag: |
947 | | 0 extra opcode bytes, 2 displacement bytes. */ |
948 | | {0, 0, 2, 0}, |
949 | | |
950 | | /* COND_JUMP states. */ |
951 | | {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP, BIG)}, |
952 | | {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP, BIG16)}, |
953 | | /* dword conditionals adds 5 bytes to frag: |
954 | | 1 extra opcode byte, 4 displacement bytes. */ |
955 | | {0, 0, 5, 0}, |
956 | | /* word conditionals add 3 bytes to frag: |
957 | | 1 extra opcode byte, 2 displacement bytes. */ |
958 | | {0, 0, 3, 0}, |
959 | | |
960 | | /* COND_JUMP86 states. */ |
961 | | {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP86, BIG)}, |
962 | | {127 + 1, -128 + 1, 1, ENCODE_RELAX_STATE (COND_JUMP86, BIG16)}, |
963 | | /* dword conditionals adds 5 bytes to frag: |
964 | | 1 extra opcode byte, 4 displacement bytes. */ |
965 | | {0, 0, 5, 0}, |
966 | | /* word conditionals add 4 bytes to frag: |
967 | | 1 displacement byte and a 3 byte long branch insn. */ |
968 | | {0, 0, 4, 0} |
969 | | }; |
970 | | |
971 | | #define ARCH(n, t, f, s) \ |
972 | | { STRING_COMMA_LEN (#n), s, PROCESSOR_ ## t, CPU_ ## f ## _FLAGS, \ |
973 | | CPU_NONE_FLAGS } |
974 | | #define SUBARCH(n, e, d, s) \ |
975 | | { STRING_COMMA_LEN (#n), s, PROCESSOR_NONE, CPU_ ## e ## _FLAGS, \ |
976 | | CPU_ ## d ## _FLAGS } |
977 | | |
978 | | static const arch_entry cpu_arch[] = |
979 | | { |
980 | | /* Do not replace the first two entries - i386_target_format() and |
981 | | set_cpu_arch() rely on them being there in this order. */ |
982 | | ARCH (generic32, GENERIC32, GENERIC32, false), |
983 | | ARCH (generic64, GENERIC64, GENERIC64, false), |
984 | | ARCH (i8086, UNKNOWN, NONE, false), |
985 | | ARCH (i186, UNKNOWN, 186, false), |
986 | | ARCH (i286, UNKNOWN, 286, false), |
987 | | ARCH (i386, I386, 386, false), |
988 | | ARCH (i486, I486, 486, false), |
989 | | ARCH (i586, PENTIUM, 586, false), |
990 | | ARCH (i686, PENTIUMPRO, 686, false), |
991 | | ARCH (pentium, PENTIUM, 586, false), |
992 | | ARCH (pentiumpro, PENTIUMPRO, PENTIUMPRO, false), |
993 | | ARCH (pentiumii, PENTIUMPRO, P2, false), |
994 | | ARCH (pentiumiii, PENTIUMPRO, P3, false), |
995 | | ARCH (pentium4, PENTIUM4, P4, false), |
996 | | ARCH (prescott, NOCONA, CORE, false), |
997 | | ARCH (nocona, NOCONA, NOCONA, false), |
998 | | ARCH (yonah, CORE, CORE, true), |
999 | | ARCH (core, CORE, CORE, false), |
1000 | | ARCH (merom, CORE2, CORE2, true), |
1001 | | ARCH (core2, CORE2, CORE2, false), |
1002 | | ARCH (corei7, COREI7, COREI7, false), |
1003 | | ARCH (iamcu, IAMCU, IAMCU, false), |
1004 | | ARCH (k6, K6, K6, false), |
1005 | | ARCH (k6_2, K6, K6_2, false), |
1006 | | ARCH (athlon, ATHLON, ATHLON, false), |
1007 | | ARCH (sledgehammer, K8, K8, true), |
1008 | | ARCH (opteron, K8, K8, false), |
1009 | | ARCH (k8, K8, K8, false), |
1010 | | ARCH (amdfam10, AMDFAM10, AMDFAM10, false), |
1011 | | ARCH (bdver1, BD, BDVER1, false), |
1012 | | ARCH (bdver2, BD, BDVER2, false), |
1013 | | ARCH (bdver3, BD, BDVER3, false), |
1014 | | ARCH (bdver4, BD, BDVER4, false), |
1015 | | ARCH (znver1, ZNVER, ZNVER1, false), |
1016 | | ARCH (znver2, ZNVER, ZNVER2, false), |
1017 | | ARCH (znver3, ZNVER, ZNVER3, false), |
1018 | | ARCH (znver4, ZNVER, ZNVER4, false), |
1019 | | ARCH (btver1, BT, BTVER1, false), |
1020 | | ARCH (btver2, BT, BTVER2, false), |
1021 | | |
1022 | | SUBARCH (8087, 8087, ANY_8087, false), |
1023 | | SUBARCH (87, NONE, ANY_8087, false), /* Disable only! */ |
1024 | | SUBARCH (287, 287, ANY_287, false), |
1025 | | SUBARCH (387, 387, ANY_387, false), |
1026 | | SUBARCH (687, 687, ANY_687, false), |
1027 | | SUBARCH (cmov, CMOV, CMOV, false), |
1028 | | SUBARCH (fxsr, FXSR, ANY_FXSR, false), |
1029 | | SUBARCH (mmx, MMX, ANY_MMX, false), |
1030 | | SUBARCH (sse, SSE, ANY_SSE, false), |
1031 | | SUBARCH (sse2, SSE2, ANY_SSE2, false), |
1032 | | SUBARCH (sse3, SSE3, ANY_SSE3, false), |
1033 | | SUBARCH (sse4a, SSE4A, ANY_SSE4A, false), |
1034 | | SUBARCH (ssse3, SSSE3, ANY_SSSE3, false), |
1035 | | SUBARCH (sse4.1, SSE4_1, ANY_SSE4_1, false), |
1036 | | SUBARCH (sse4.2, SSE4_2, ANY_SSE4_2, false), |
1037 | | SUBARCH (sse4, SSE4_2, ANY_SSE4_1, false), |
1038 | | SUBARCH (avx, AVX, ANY_AVX, false), |
1039 | | SUBARCH (avx2, AVX2, ANY_AVX2, false), |
1040 | | SUBARCH (avx512f, AVX512F, ANY_AVX512F, false), |
1041 | | SUBARCH (avx512cd, AVX512CD, ANY_AVX512CD, false), |
1042 | | SUBARCH (avx512er, AVX512ER, ANY_AVX512ER, false), |
1043 | | SUBARCH (avx512pf, AVX512PF, ANY_AVX512PF, false), |
1044 | | SUBARCH (avx512dq, AVX512DQ, ANY_AVX512DQ, false), |
1045 | | SUBARCH (avx512bw, AVX512BW, ANY_AVX512BW, false), |
1046 | | SUBARCH (avx512vl, AVX512VL, ANY_AVX512VL, false), |
1047 | | SUBARCH (monitor, MONITOR, MONITOR, false), |
1048 | | SUBARCH (vmx, VMX, ANY_VMX, false), |
1049 | | SUBARCH (vmfunc, VMFUNC, ANY_VMFUNC, false), |
1050 | | SUBARCH (smx, SMX, SMX, false), |
1051 | | SUBARCH (xsave, XSAVE, ANY_XSAVE, false), |
1052 | | SUBARCH (xsaveopt, XSAVEOPT, ANY_XSAVEOPT, false), |
1053 | | SUBARCH (xsavec, XSAVEC, ANY_XSAVEC, false), |
1054 | | SUBARCH (xsaves, XSAVES, ANY_XSAVES, false), |
1055 | | SUBARCH (aes, AES, ANY_AES, false), |
1056 | | SUBARCH (pclmul, PCLMUL, ANY_PCLMUL, false), |
1057 | | SUBARCH (clmul, PCLMUL, ANY_PCLMUL, true), |
1058 | | SUBARCH (fsgsbase, FSGSBASE, FSGSBASE, false), |
1059 | | SUBARCH (rdrnd, RDRND, RDRND, false), |
1060 | | SUBARCH (f16c, F16C, ANY_F16C, false), |
1061 | | SUBARCH (bmi2, BMI2, BMI2, false), |
1062 | | SUBARCH (fma, FMA, ANY_FMA, false), |
1063 | | SUBARCH (fma4, FMA4, ANY_FMA4, false), |
1064 | | SUBARCH (xop, XOP, ANY_XOP, false), |
1065 | | SUBARCH (lwp, LWP, ANY_LWP, false), |
1066 | | SUBARCH (movbe, MOVBE, MOVBE, false), |
1067 | | SUBARCH (cx16, CX16, CX16, false), |
1068 | | SUBARCH (lahf_sahf, LAHF_SAHF, LAHF_SAHF, false), |
1069 | | SUBARCH (ept, EPT, ANY_EPT, false), |
1070 | | SUBARCH (lzcnt, LZCNT, LZCNT, false), |
1071 | | SUBARCH (popcnt, POPCNT, POPCNT, false), |
1072 | | SUBARCH (hle, HLE, HLE, false), |
1073 | | SUBARCH (rtm, RTM, ANY_RTM, false), |
1074 | | SUBARCH (tsx, TSX, TSX, false), |
1075 | | SUBARCH (invpcid, INVPCID, INVPCID, false), |
1076 | | SUBARCH (clflush, CLFLUSH, CLFLUSH, false), |
1077 | | SUBARCH (nop, NOP, NOP, false), |
1078 | | SUBARCH (syscall, SYSCALL, SYSCALL, false), |
1079 | | SUBARCH (rdtscp, RDTSCP, RDTSCP, false), |
1080 | | SUBARCH (3dnow, 3DNOW, ANY_3DNOW, false), |
1081 | | SUBARCH (3dnowa, 3DNOWA, ANY_3DNOWA, false), |
1082 | | SUBARCH (padlock, PADLOCK, PADLOCK, false), |
1083 | | SUBARCH (pacifica, SVME, ANY_SVME, true), |
1084 | | SUBARCH (svme, SVME, ANY_SVME, false), |
1085 | | SUBARCH (abm, ABM, ABM, false), |
1086 | | SUBARCH (bmi, BMI, BMI, false), |
1087 | | SUBARCH (tbm, TBM, TBM, false), |
1088 | | SUBARCH (adx, ADX, ADX, false), |
1089 | | SUBARCH (rdseed, RDSEED, RDSEED, false), |
1090 | | SUBARCH (prfchw, PRFCHW, PRFCHW, false), |
1091 | | SUBARCH (smap, SMAP, SMAP, false), |
1092 | | SUBARCH (mpx, MPX, ANY_MPX, false), |
1093 | | SUBARCH (sha, SHA, ANY_SHA, false), |
1094 | | SUBARCH (clflushopt, CLFLUSHOPT, CLFLUSHOPT, false), |
1095 | | SUBARCH (prefetchwt1, PREFETCHWT1, PREFETCHWT1, false), |
1096 | | SUBARCH (se1, SE1, SE1, false), |
1097 | | SUBARCH (clwb, CLWB, CLWB, false), |
1098 | | SUBARCH (avx512ifma, AVX512IFMA, ANY_AVX512IFMA, false), |
1099 | | SUBARCH (avx512vbmi, AVX512VBMI, ANY_AVX512VBMI, false), |
1100 | | SUBARCH (avx512_4fmaps, AVX512_4FMAPS, ANY_AVX512_4FMAPS, false), |
1101 | | SUBARCH (avx512_4vnniw, AVX512_4VNNIW, ANY_AVX512_4VNNIW, false), |
1102 | | SUBARCH (avx512_vpopcntdq, AVX512_VPOPCNTDQ, ANY_AVX512_VPOPCNTDQ, false), |
1103 | | SUBARCH (avx512_vbmi2, AVX512_VBMI2, ANY_AVX512_VBMI2, false), |
1104 | | SUBARCH (avx512_vnni, AVX512_VNNI, ANY_AVX512_VNNI, false), |
1105 | | SUBARCH (avx512_bitalg, AVX512_BITALG, ANY_AVX512_BITALG, false), |
1106 | | SUBARCH (avx_vnni, AVX_VNNI, ANY_AVX_VNNI, false), |
1107 | | SUBARCH (clzero, CLZERO, CLZERO, false), |
1108 | | SUBARCH (mwaitx, MWAITX, MWAITX, false), |
1109 | | SUBARCH (ospke, OSPKE, ANY_OSPKE, false), |
1110 | | SUBARCH (rdpid, RDPID, RDPID, false), |
1111 | | SUBARCH (ptwrite, PTWRITE, PTWRITE, false), |
1112 | | SUBARCH (ibt, IBT, IBT, false), |
1113 | | SUBARCH (shstk, SHSTK, SHSTK, false), |
1114 | | SUBARCH (gfni, GFNI, ANY_GFNI, false), |
1115 | | SUBARCH (vaes, VAES, ANY_VAES, false), |
1116 | | SUBARCH (vpclmulqdq, VPCLMULQDQ, ANY_VPCLMULQDQ, false), |
1117 | | SUBARCH (wbnoinvd, WBNOINVD, WBNOINVD, false), |
1118 | | SUBARCH (pconfig, PCONFIG, PCONFIG, false), |
1119 | | SUBARCH (waitpkg, WAITPKG, WAITPKG, false), |
1120 | | SUBARCH (cldemote, CLDEMOTE, CLDEMOTE, false), |
1121 | | SUBARCH (amx_int8, AMX_INT8, ANY_AMX_INT8, false), |
1122 | | SUBARCH (amx_bf16, AMX_BF16, ANY_AMX_BF16, false), |
1123 | | SUBARCH (amx_fp16, AMX_FP16, ANY_AMX_FP16, false), |
1124 | | SUBARCH (amx_complex, AMX_COMPLEX, ANY_AMX_COMPLEX, false), |
1125 | | SUBARCH (amx_tile, AMX_TILE, ANY_AMX_TILE, false), |
1126 | | SUBARCH (movdiri, MOVDIRI, MOVDIRI, false), |
1127 | | SUBARCH (movdir64b, MOVDIR64B, MOVDIR64B, false), |
1128 | | SUBARCH (avx512_bf16, AVX512_BF16, ANY_AVX512_BF16, false), |
1129 | | SUBARCH (avx512_vp2intersect, AVX512_VP2INTERSECT, |
1130 | | ANY_AVX512_VP2INTERSECT, false), |
1131 | | SUBARCH (tdx, TDX, TDX, false), |
1132 | | SUBARCH (enqcmd, ENQCMD, ENQCMD, false), |
1133 | | SUBARCH (serialize, SERIALIZE, SERIALIZE, false), |
1134 | | SUBARCH (rdpru, RDPRU, RDPRU, false), |
1135 | | SUBARCH (mcommit, MCOMMIT, MCOMMIT, false), |
1136 | | SUBARCH (sev_es, SEV_ES, ANY_SEV_ES, false), |
1137 | | SUBARCH (tsxldtrk, TSXLDTRK, ANY_TSXLDTRK, false), |
1138 | | SUBARCH (kl, KL, ANY_KL, false), |
1139 | | SUBARCH (widekl, WIDEKL, ANY_WIDEKL, false), |
1140 | | SUBARCH (uintr, UINTR, UINTR, false), |
1141 | | SUBARCH (hreset, HRESET, HRESET, false), |
1142 | | SUBARCH (avx512_fp16, AVX512_FP16, ANY_AVX512_FP16, false), |
1143 | | SUBARCH (prefetchi, PREFETCHI, PREFETCHI, false), |
1144 | | SUBARCH (avx_ifma, AVX_IFMA, ANY_AVX_IFMA, false), |
1145 | | SUBARCH (avx_vnni_int8, AVX_VNNI_INT8, ANY_AVX_VNNI_INT8, false), |
1146 | | SUBARCH (cmpccxadd, CMPCCXADD, CMPCCXADD, false), |
1147 | | SUBARCH (wrmsrns, WRMSRNS, WRMSRNS, false), |
1148 | | SUBARCH (msrlist, MSRLIST, MSRLIST, false), |
1149 | | SUBARCH (avx_ne_convert, AVX_NE_CONVERT, ANY_AVX_NE_CONVERT, false), |
1150 | | SUBARCH (rao_int, RAO_INT, RAO_INT, false), |
1151 | | SUBARCH (rmpquery, RMPQUERY, ANY_RMPQUERY, false), |
1152 | | SUBARCH (fred, FRED, ANY_FRED, false), |
1153 | | SUBARCH (lkgs, LKGS, ANY_LKGS, false), |
1154 | | SUBARCH (avx_vnni_int16, AVX_VNNI_INT16, ANY_AVX_VNNI_INT16, false), |
1155 | | SUBARCH (sha512, SHA512, ANY_SHA512, false), |
1156 | | SUBARCH (sm3, SM3, ANY_SM3, false), |
1157 | | SUBARCH (sm4, SM4, ANY_SM4, false), |
1158 | | SUBARCH (pbndkb, PBNDKB, PBNDKB, false), |
1159 | | }; |
1160 | | |
1161 | | #undef SUBARCH |
1162 | | #undef ARCH |
1163 | | |
1164 | | #ifdef I386COFF |
1165 | | /* Like s_lcomm_internal in gas/read.c but the alignment string |
1166 | | is allowed to be optional. */ |
1167 | | |
1168 | | static symbolS * |
1169 | | pe_lcomm_internal (int needs_align, symbolS *symbolP, addressT size) |
1170 | | { |
1171 | | addressT align = 0; |
1172 | | |
1173 | | SKIP_WHITESPACE (); |
1174 | | |
1175 | | if (needs_align |
1176 | | && *input_line_pointer == ',') |
1177 | | { |
1178 | | align = parse_align (needs_align - 1); |
1179 | | |
1180 | | if (align == (addressT) -1) |
1181 | | return NULL; |
1182 | | } |
1183 | | else |
1184 | | { |
1185 | | if (size >= 8) |
1186 | | align = 3; |
1187 | | else if (size >= 4) |
1188 | | align = 2; |
1189 | | else if (size >= 2) |
1190 | | align = 1; |
1191 | | else |
1192 | | align = 0; |
1193 | | } |
1194 | | |
1195 | | bss_alloc (symbolP, size, align); |
1196 | | return symbolP; |
1197 | | } |
1198 | | |
1199 | | static void |
1200 | | pe_lcomm (int needs_align) |
1201 | | { |
1202 | | s_comm_internal (needs_align * 2, pe_lcomm_internal); |
1203 | | } |
1204 | | #endif |
1205 | | |
1206 | | const pseudo_typeS md_pseudo_table[] = |
1207 | | { |
1208 | | #if !defined(OBJ_AOUT) && !defined(USE_ALIGN_PTWO) |
1209 | | {"align", s_align_bytes, 0}, |
1210 | | #else |
1211 | | {"align", s_align_ptwo, 0}, |
1212 | | #endif |
1213 | | {"arch", set_cpu_arch, 0}, |
1214 | | #ifndef I386COFF |
1215 | | {"bss", s_bss, 0}, |
1216 | | #else |
1217 | | {"lcomm", pe_lcomm, 1}, |
1218 | | #endif |
1219 | | {"ffloat", float_cons, 'f'}, |
1220 | | {"dfloat", float_cons, 'd'}, |
1221 | | {"tfloat", float_cons, 'x'}, |
1222 | | {"hfloat", float_cons, 'h'}, |
1223 | | {"bfloat16", float_cons, 'b'}, |
1224 | | {"value", cons, 2}, |
1225 | | {"slong", signed_cons, 4}, |
1226 | | {"insn", s_insn, 0}, |
1227 | | {"noopt", s_ignore, 0}, |
1228 | | {"optim", s_ignore, 0}, |
1229 | | {"code16gcc", set_16bit_gcc_code_flag, CODE_16BIT}, |
1230 | | {"code16", set_code_flag, CODE_16BIT}, |
1231 | | {"code32", set_code_flag, CODE_32BIT}, |
1232 | | #ifdef BFD64 |
1233 | | {"code64", set_code_flag, CODE_64BIT}, |
1234 | | #endif |
1235 | | {"intel_syntax", set_intel_syntax, 1}, |
1236 | | {"att_syntax", set_intel_syntax, 0}, |
1237 | | {"intel_mnemonic", set_intel_mnemonic, 1}, |
1238 | | {"att_mnemonic", set_intel_mnemonic, 0}, |
1239 | | {"allow_index_reg", set_allow_index_reg, 1}, |
1240 | | {"disallow_index_reg", set_allow_index_reg, 0}, |
1241 | | {"sse_check", set_check, 0}, |
1242 | | {"operand_check", set_check, 1}, |
1243 | | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
1244 | | {"largecomm", handle_large_common, 0}, |
1245 | | #else |
1246 | | {"file", dwarf2_directive_file, 0}, |
1247 | | {"loc", dwarf2_directive_loc, 0}, |
1248 | | {"loc_mark_labels", dwarf2_directive_loc_mark_labels, 0}, |
1249 | | #endif |
1250 | | #ifdef TE_PE |
1251 | | {"secrel32", pe_directive_secrel, 0}, |
1252 | | {"secidx", pe_directive_secidx, 0}, |
1253 | | #endif |
1254 | | {0, 0, 0} |
1255 | | }; |
1256 | | |
1257 | | /* For interface with expression (). */ |
1258 | | extern char *input_line_pointer; |
1259 | | |
1260 | | /* Hash table for instruction mnemonic lookup. */ |
1261 | | static htab_t op_hash; |
1262 | | |
1263 | | /* Hash table for register lookup. */ |
1264 | | static htab_t reg_hash; |
1265 | | |
1266 | | /* Various efficient no-op patterns for aligning code labels. |
1267 | | Note: Don't try to assemble the instructions in the comments. |
1268 | | 0L and 0w are not legal. */ |
1269 | | static const unsigned char f32_1[] = |
1270 | | {0x90}; /* nop */ |
1271 | | static const unsigned char f32_2[] = |
1272 | | {0x66,0x90}; /* xchg %ax,%ax */ |
1273 | | static const unsigned char f32_3[] = |
1274 | | {0x8d,0x76,0x00}; /* leal 0(%esi),%esi */ |
1275 | | static const unsigned char f32_4[] = |
1276 | | {0x8d,0x74,0x26,0x00}; /* leal 0(%esi,1),%esi */ |
1277 | | static const unsigned char f32_6[] = |
1278 | | {0x8d,0xb6,0x00,0x00,0x00,0x00}; /* leal 0L(%esi),%esi */ |
1279 | | static const unsigned char f32_7[] = |
1280 | | {0x8d,0xb4,0x26,0x00,0x00,0x00,0x00}; /* leal 0L(%esi,1),%esi */ |
1281 | | static const unsigned char f16_3[] = |
1282 | | {0x8d,0x74,0x00}; /* lea 0(%si),%si */ |
1283 | | static const unsigned char f16_4[] = |
1284 | | {0x8d,0xb4,0x00,0x00}; /* lea 0W(%si),%si */ |
1285 | | static const unsigned char jump_disp8[] = |
1286 | | {0xeb}; /* jmp disp8 */ |
1287 | | static const unsigned char jump32_disp32[] = |
1288 | | {0xe9}; /* jmp disp32 */ |
1289 | | static const unsigned char jump16_disp32[] = |
1290 | | {0x66,0xe9}; /* jmp disp32 */ |
1291 | | /* 32-bit NOPs patterns. */ |
1292 | | static const unsigned char *const f32_patt[] = { |
1293 | | f32_1, f32_2, f32_3, f32_4, NULL, f32_6, f32_7 |
1294 | | }; |
1295 | | /* 16-bit NOPs patterns. */ |
1296 | | static const unsigned char *const f16_patt[] = { |
1297 | | f32_1, f32_2, f16_3, f16_4 |
1298 | | }; |
1299 | | /* nopl (%[re]ax) */ |
1300 | | static const unsigned char alt_3[] = |
1301 | | {0x0f,0x1f,0x00}; |
1302 | | /* nopl 0(%[re]ax) */ |
1303 | | static const unsigned char alt_4[] = |
1304 | | {0x0f,0x1f,0x40,0x00}; |
1305 | | /* nopl 0(%[re]ax,%[re]ax,1) */ |
1306 | | static const unsigned char alt_5[] = |
1307 | | {0x0f,0x1f,0x44,0x00,0x00}; |
1308 | | /* nopw 0(%[re]ax,%[re]ax,1) */ |
1309 | | static const unsigned char alt_6[] = |
1310 | | {0x66,0x0f,0x1f,0x44,0x00,0x00}; |
1311 | | /* nopl 0L(%[re]ax) */ |
1312 | | static const unsigned char alt_7[] = |
1313 | | {0x0f,0x1f,0x80,0x00,0x00,0x00,0x00}; |
1314 | | /* nopl 0L(%[re]ax,%[re]ax,1) */ |
1315 | | static const unsigned char alt_8[] = |
1316 | | {0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00}; |
1317 | | /* nopw 0L(%[re]ax,%[re]ax,1) */ |
1318 | | static const unsigned char alt_9[] = |
1319 | | {0x66,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00}; |
1320 | | /* nopw %cs:0L(%[re]ax,%[re]ax,1) */ |
1321 | | static const unsigned char alt_10[] = |
1322 | | {0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00}; |
1323 | | /* data16 nopw %cs:0L(%eax,%eax,1) */ |
1324 | | static const unsigned char alt_11[] = |
1325 | | {0x66,0x66,0x2e,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00}; |
1326 | | /* 32-bit and 64-bit NOPs patterns. */ |
1327 | | static const unsigned char *const alt_patt[] = { |
1328 | | f32_1, f32_2, alt_3, alt_4, alt_5, alt_6, alt_7, alt_8, |
1329 | | alt_9, alt_10, alt_11 |
1330 | | }; |
1331 | | |
1332 | | /* Genenerate COUNT bytes of NOPs to WHERE from PATT with the maximum |
1333 | | size of a single NOP instruction MAX_SINGLE_NOP_SIZE. */ |
1334 | | |
1335 | | static void |
1336 | | i386_output_nops (char *where, const unsigned char *const *patt, |
1337 | | int count, int max_single_nop_size) |
1338 | | |
1339 | 0 | { |
1340 | | /* Place the longer NOP first. */ |
1341 | 0 | int last; |
1342 | 0 | int offset; |
1343 | 0 | const unsigned char *nops; |
1344 | |
|
1345 | 0 | if (max_single_nop_size < 1) |
1346 | 0 | { |
1347 | 0 | as_fatal (_("i386_output_nops called to generate nops of at most %d bytes!"), |
1348 | 0 | max_single_nop_size); |
1349 | 0 | return; |
1350 | 0 | } |
1351 | | |
1352 | 0 | nops = patt[max_single_nop_size - 1]; |
1353 | | |
1354 | | /* Use the smaller one if the requsted one isn't available. */ |
1355 | 0 | if (nops == NULL) |
1356 | 0 | { |
1357 | 0 | max_single_nop_size--; |
1358 | 0 | nops = patt[max_single_nop_size - 1]; |
1359 | 0 | } |
1360 | |
|
1361 | 0 | last = count % max_single_nop_size; |
1362 | |
|
1363 | 0 | count -= last; |
1364 | 0 | for (offset = 0; offset < count; offset += max_single_nop_size) |
1365 | 0 | memcpy (where + offset, nops, max_single_nop_size); |
1366 | |
|
1367 | 0 | if (last) |
1368 | 0 | { |
1369 | 0 | nops = patt[last - 1]; |
1370 | 0 | if (nops == NULL) |
1371 | 0 | { |
1372 | | /* Use the smaller one plus one-byte NOP if the needed one |
1373 | | isn't available. */ |
1374 | 0 | last--; |
1375 | 0 | nops = patt[last - 1]; |
1376 | 0 | memcpy (where + offset, nops, last); |
1377 | 0 | where[offset + last] = *patt[0]; |
1378 | 0 | } |
1379 | 0 | else |
1380 | 0 | memcpy (where + offset, nops, last); |
1381 | 0 | } |
1382 | 0 | } |
1383 | | |
1384 | | static INLINE int |
1385 | | fits_in_imm7 (offsetT num) |
1386 | 0 | { |
1387 | 0 | return (num & 0x7f) == num; |
1388 | 0 | } |
1389 | | |
1390 | | static INLINE int |
1391 | | fits_in_imm31 (offsetT num) |
1392 | 0 | { |
1393 | 0 | return (num & 0x7fffffff) == num; |
1394 | 0 | } |
1395 | | |
1396 | | /* Genenerate COUNT bytes of NOPs to WHERE with the maximum size of a |
1397 | | single NOP instruction LIMIT. */ |
1398 | | |
1399 | | void |
1400 | | i386_generate_nops (fragS *fragP, char *where, offsetT count, int limit) |
1401 | 0 | { |
1402 | 0 | const unsigned char *const *patt = NULL; |
1403 | 0 | int max_single_nop_size; |
1404 | | /* Maximum number of NOPs before switching to jump over NOPs. */ |
1405 | 0 | int max_number_of_nops; |
1406 | |
|
1407 | 0 | switch (fragP->fr_type) |
1408 | 0 | { |
1409 | 0 | case rs_fill_nop: |
1410 | 0 | case rs_align_code: |
1411 | 0 | break; |
1412 | 0 | case rs_machine_dependent: |
1413 | | /* Allow NOP padding for jumps and calls. */ |
1414 | 0 | if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PADDING |
1415 | 0 | || TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == FUSED_JCC_PADDING) |
1416 | 0 | break; |
1417 | | /* Fall through. */ |
1418 | 0 | default: |
1419 | 0 | return; |
1420 | 0 | } |
1421 | | |
1422 | | /* We need to decide which NOP sequence to use for 32bit and |
1423 | | 64bit. When -mtune= is used: |
1424 | | |
1425 | | 1. For PROCESSOR_I386, PROCESSOR_I486, PROCESSOR_PENTIUM and |
1426 | | PROCESSOR_GENERIC32, f32_patt will be used. |
1427 | | 2. For the rest, alt_patt will be used. |
1428 | | |
1429 | | When -mtune= isn't used, alt_patt will be used if |
1430 | | cpu_arch_isa_flags has CpuNop. Otherwise, f32_patt will |
1431 | | be used. |
1432 | | |
1433 | | When -march= or .arch is used, we can't use anything beyond |
1434 | | cpu_arch_isa_flags. */ |
1435 | | |
1436 | 0 | if (flag_code == CODE_16BIT) |
1437 | 0 | { |
1438 | 0 | patt = f16_patt; |
1439 | 0 | max_single_nop_size = sizeof (f16_patt) / sizeof (f16_patt[0]); |
1440 | | /* Limit number of NOPs to 2 in 16-bit mode. */ |
1441 | 0 | max_number_of_nops = 2; |
1442 | 0 | } |
1443 | 0 | else |
1444 | 0 | { |
1445 | 0 | if (fragP->tc_frag_data.isa == PROCESSOR_UNKNOWN) |
1446 | 0 | { |
1447 | | /* PROCESSOR_UNKNOWN means that all ISAs may be used. */ |
1448 | 0 | switch (cpu_arch_tune) |
1449 | 0 | { |
1450 | 0 | case PROCESSOR_UNKNOWN: |
1451 | | /* We use cpu_arch_isa_flags to check if we SHOULD |
1452 | | optimize with nops. */ |
1453 | 0 | if (fragP->tc_frag_data.isa_flags.bitfield.cpunop) |
1454 | 0 | patt = alt_patt; |
1455 | 0 | else |
1456 | 0 | patt = f32_patt; |
1457 | 0 | break; |
1458 | 0 | case PROCESSOR_PENTIUM4: |
1459 | 0 | case PROCESSOR_NOCONA: |
1460 | 0 | case PROCESSOR_CORE: |
1461 | 0 | case PROCESSOR_CORE2: |
1462 | 0 | case PROCESSOR_COREI7: |
1463 | 0 | case PROCESSOR_GENERIC64: |
1464 | 0 | case PROCESSOR_K6: |
1465 | 0 | case PROCESSOR_ATHLON: |
1466 | 0 | case PROCESSOR_K8: |
1467 | 0 | case PROCESSOR_AMDFAM10: |
1468 | 0 | case PROCESSOR_BD: |
1469 | 0 | case PROCESSOR_ZNVER: |
1470 | 0 | case PROCESSOR_BT: |
1471 | 0 | patt = alt_patt; |
1472 | 0 | break; |
1473 | 0 | case PROCESSOR_I386: |
1474 | 0 | case PROCESSOR_I486: |
1475 | 0 | case PROCESSOR_PENTIUM: |
1476 | 0 | case PROCESSOR_PENTIUMPRO: |
1477 | 0 | case PROCESSOR_IAMCU: |
1478 | 0 | case PROCESSOR_GENERIC32: |
1479 | 0 | patt = f32_patt; |
1480 | 0 | break; |
1481 | 0 | case PROCESSOR_NONE: |
1482 | 0 | abort (); |
1483 | 0 | } |
1484 | 0 | } |
1485 | 0 | else |
1486 | 0 | { |
1487 | 0 | switch (fragP->tc_frag_data.tune) |
1488 | 0 | { |
1489 | 0 | case PROCESSOR_UNKNOWN: |
1490 | | /* When cpu_arch_isa is set, cpu_arch_tune shouldn't be |
1491 | | PROCESSOR_UNKNOWN. */ |
1492 | 0 | abort (); |
1493 | 0 | break; |
1494 | | |
1495 | 0 | case PROCESSOR_I386: |
1496 | 0 | case PROCESSOR_I486: |
1497 | 0 | case PROCESSOR_PENTIUM: |
1498 | 0 | case PROCESSOR_IAMCU: |
1499 | 0 | case PROCESSOR_K6: |
1500 | 0 | case PROCESSOR_ATHLON: |
1501 | 0 | case PROCESSOR_K8: |
1502 | 0 | case PROCESSOR_AMDFAM10: |
1503 | 0 | case PROCESSOR_BD: |
1504 | 0 | case PROCESSOR_ZNVER: |
1505 | 0 | case PROCESSOR_BT: |
1506 | 0 | case PROCESSOR_GENERIC32: |
1507 | | /* We use cpu_arch_isa_flags to check if we CAN optimize |
1508 | | with nops. */ |
1509 | 0 | if (fragP->tc_frag_data.isa_flags.bitfield.cpunop) |
1510 | 0 | patt = alt_patt; |
1511 | 0 | else |
1512 | 0 | patt = f32_patt; |
1513 | 0 | break; |
1514 | 0 | case PROCESSOR_PENTIUMPRO: |
1515 | 0 | case PROCESSOR_PENTIUM4: |
1516 | 0 | case PROCESSOR_NOCONA: |
1517 | 0 | case PROCESSOR_CORE: |
1518 | 0 | case PROCESSOR_CORE2: |
1519 | 0 | case PROCESSOR_COREI7: |
1520 | 0 | if (fragP->tc_frag_data.isa_flags.bitfield.cpunop) |
1521 | 0 | patt = alt_patt; |
1522 | 0 | else |
1523 | 0 | patt = f32_patt; |
1524 | 0 | break; |
1525 | 0 | case PROCESSOR_GENERIC64: |
1526 | 0 | patt = alt_patt; |
1527 | 0 | break; |
1528 | 0 | case PROCESSOR_NONE: |
1529 | 0 | abort (); |
1530 | 0 | } |
1531 | 0 | } |
1532 | | |
1533 | 0 | if (patt == f32_patt) |
1534 | 0 | { |
1535 | 0 | max_single_nop_size = sizeof (f32_patt) / sizeof (f32_patt[0]); |
1536 | | /* Limit number of NOPs to 2 for older processors. */ |
1537 | 0 | max_number_of_nops = 2; |
1538 | 0 | } |
1539 | 0 | else |
1540 | 0 | { |
1541 | 0 | max_single_nop_size = sizeof (alt_patt) / sizeof (alt_patt[0]); |
1542 | | /* Limit number of NOPs to 7 for newer processors. */ |
1543 | 0 | max_number_of_nops = 7; |
1544 | 0 | } |
1545 | 0 | } |
1546 | | |
1547 | 0 | if (limit == 0) |
1548 | 0 | limit = max_single_nop_size; |
1549 | |
|
1550 | 0 | if (fragP->fr_type == rs_fill_nop) |
1551 | 0 | { |
1552 | | /* Output NOPs for .nop directive. */ |
1553 | 0 | if (limit > max_single_nop_size) |
1554 | 0 | { |
1555 | 0 | as_bad_where (fragP->fr_file, fragP->fr_line, |
1556 | 0 | _("invalid single nop size: %d " |
1557 | 0 | "(expect within [0, %d])"), |
1558 | 0 | limit, max_single_nop_size); |
1559 | 0 | return; |
1560 | 0 | } |
1561 | 0 | } |
1562 | 0 | else if (fragP->fr_type != rs_machine_dependent) |
1563 | 0 | fragP->fr_var = count; |
1564 | | |
1565 | 0 | if ((count / max_single_nop_size) > max_number_of_nops) |
1566 | 0 | { |
1567 | | /* Generate jump over NOPs. */ |
1568 | 0 | offsetT disp = count - 2; |
1569 | 0 | if (fits_in_imm7 (disp)) |
1570 | 0 | { |
1571 | | /* Use "jmp disp8" if possible. */ |
1572 | 0 | count = disp; |
1573 | 0 | where[0] = jump_disp8[0]; |
1574 | 0 | where[1] = count; |
1575 | 0 | where += 2; |
1576 | 0 | } |
1577 | 0 | else |
1578 | 0 | { |
1579 | 0 | unsigned int size_of_jump; |
1580 | |
|
1581 | 0 | if (flag_code == CODE_16BIT) |
1582 | 0 | { |
1583 | 0 | where[0] = jump16_disp32[0]; |
1584 | 0 | where[1] = jump16_disp32[1]; |
1585 | 0 | size_of_jump = 2; |
1586 | 0 | } |
1587 | 0 | else |
1588 | 0 | { |
1589 | 0 | where[0] = jump32_disp32[0]; |
1590 | 0 | size_of_jump = 1; |
1591 | 0 | } |
1592 | |
|
1593 | 0 | count -= size_of_jump + 4; |
1594 | 0 | if (!fits_in_imm31 (count)) |
1595 | 0 | { |
1596 | 0 | as_bad_where (fragP->fr_file, fragP->fr_line, |
1597 | 0 | _("jump over nop padding out of range")); |
1598 | 0 | return; |
1599 | 0 | } |
1600 | | |
1601 | 0 | md_number_to_chars (where + size_of_jump, count, 4); |
1602 | 0 | where += size_of_jump + 4; |
1603 | 0 | } |
1604 | 0 | } |
1605 | | |
1606 | | /* Generate multiple NOPs. */ |
1607 | 0 | i386_output_nops (where, patt, count, limit); |
1608 | 0 | } |
1609 | | |
1610 | | static INLINE int |
1611 | | operand_type_all_zero (const union i386_operand_type *x) |
1612 | 373k | { |
1613 | 373k | switch (ARRAY_SIZE(x->array)) |
1614 | 373k | { |
1615 | 0 | case 3: |
1616 | 0 | if (x->array[2]) |
1617 | 0 | return 0; |
1618 | | /* Fall through. */ |
1619 | 0 | case 2: |
1620 | 0 | if (x->array[1]) |
1621 | 0 | return 0; |
1622 | | /* Fall through. */ |
1623 | 373k | case 1: |
1624 | 373k | return !x->array[0]; |
1625 | 0 | default: |
1626 | 0 | abort (); |
1627 | 373k | } |
1628 | 373k | } |
1629 | | |
1630 | | static INLINE void |
1631 | | operand_type_set (union i386_operand_type *x, unsigned int v) |
1632 | 530k | { |
1633 | 530k | switch (ARRAY_SIZE(x->array)) |
1634 | 530k | { |
1635 | 0 | case 3: |
1636 | 0 | x->array[2] = v; |
1637 | | /* Fall through. */ |
1638 | 0 | case 2: |
1639 | 0 | x->array[1] = v; |
1640 | | /* Fall through. */ |
1641 | 530k | case 1: |
1642 | 530k | x->array[0] = v; |
1643 | | /* Fall through. */ |
1644 | 530k | break; |
1645 | 0 | default: |
1646 | 0 | abort (); |
1647 | 530k | } |
1648 | | |
1649 | 530k | x->bitfield.class = ClassNone; |
1650 | 530k | x->bitfield.instance = InstanceNone; |
1651 | 530k | } |
1652 | | |
1653 | | static INLINE int |
1654 | | operand_type_equal (const union i386_operand_type *x, |
1655 | | const union i386_operand_type *y) |
1656 | 0 | { |
1657 | 0 | switch (ARRAY_SIZE(x->array)) |
1658 | 0 | { |
1659 | 0 | case 3: |
1660 | 0 | if (x->array[2] != y->array[2]) |
1661 | 0 | return 0; |
1662 | | /* Fall through. */ |
1663 | 0 | case 2: |
1664 | 0 | if (x->array[1] != y->array[1]) |
1665 | 0 | return 0; |
1666 | | /* Fall through. */ |
1667 | 0 | case 1: |
1668 | 0 | return x->array[0] == y->array[0]; |
1669 | 0 | break; |
1670 | 0 | default: |
1671 | 0 | abort (); |
1672 | 0 | } |
1673 | 0 | } |
1674 | | |
1675 | | static INLINE bool |
1676 | | is_cpu (const insn_template *t, enum i386_cpu cpu) |
1677 | 12.4M | { |
1678 | 12.4M | switch (cpu) |
1679 | 12.4M | { |
1680 | 344k | case Cpu287: return t->cpu.bitfield.cpu287; |
1681 | 344k | case Cpu387: return t->cpu.bitfield.cpu387; |
1682 | 0 | case Cpu3dnow: return t->cpu.bitfield.cpu3dnow; |
1683 | 0 | case Cpu3dnowA: return t->cpu.bitfield.cpu3dnowa; |
1684 | 474k | case CpuAVX: return t->cpu.bitfield.cpuavx; |
1685 | 661 | case CpuHLE: return t->cpu.bitfield.cpuhle; |
1686 | 347k | case CpuAVX512F: return t->cpu.bitfield.cpuavx512f; |
1687 | 347k | case CpuAVX512VL: return t->cpu.bitfield.cpuavx512vl; |
1688 | 0 | case Cpu64: return t->cpu.bitfield.cpu64; |
1689 | 0 | case CpuNo64: return t->cpu.bitfield.cpuno64; |
1690 | 10.5M | default: |
1691 | 10.5M | gas_assert (cpu < CpuAttrEnums); |
1692 | 12.4M | } |
1693 | 10.5M | return t->cpu.bitfield.isa == cpu + 1u; |
1694 | 12.4M | } |
1695 | | |
1696 | | static i386_cpu_flags cpu_flags_from_attr (i386_cpu_attr a) |
1697 | 2.12M | { |
1698 | 2.12M | const unsigned int bps = sizeof (a.array[0]) * CHAR_BIT; |
1699 | 2.12M | i386_cpu_flags f = { .array[0] = 0 }; |
1700 | | |
1701 | 2.12M | switch (ARRAY_SIZE(a.array)) |
1702 | 2.12M | { |
1703 | 2.12M | case 1: |
1704 | 2.12M | f.array[CpuAttrEnums / bps] |
1705 | 2.12M | |= (a.array[0] >> CpuIsaBits) << (CpuAttrEnums % bps); |
1706 | 2.12M | if (CpuAttrEnums % bps > CpuIsaBits) |
1707 | 0 | f.array[CpuAttrEnums / bps + 1] |
1708 | 0 | = (a.array[0] >> CpuIsaBits) >> (bps - CpuAttrEnums % bps); |
1709 | 2.12M | break; |
1710 | 0 | default: |
1711 | 0 | abort (); |
1712 | 2.12M | } |
1713 | | |
1714 | 2.12M | if (a.bitfield.isa) |
1715 | 700k | f.array[(a.bitfield.isa - 1) / bps] |= 1u << ((a.bitfield.isa - 1) % bps); |
1716 | | |
1717 | 2.12M | return f; |
1718 | 2.12M | } |
1719 | | |
1720 | | static INLINE int |
1721 | | cpu_flags_all_zero (const union i386_cpu_flags *x) |
1722 | 2.83M | { |
1723 | 2.83M | switch (ARRAY_SIZE(x->array)) |
1724 | 2.83M | { |
1725 | 2.83M | case 5: |
1726 | 2.83M | if (x->array[4]) |
1727 | 43.8k | return 0; |
1728 | | /* Fall through. */ |
1729 | 2.79M | case 4: |
1730 | 2.79M | if (x->array[3]) |
1731 | 1.25k | return 0; |
1732 | | /* Fall through. */ |
1733 | 2.78M | case 3: |
1734 | 2.78M | if (x->array[2]) |
1735 | 2.04k | return 0; |
1736 | | /* Fall through. */ |
1737 | 2.78M | case 2: |
1738 | 2.78M | if (x->array[1]) |
1739 | 4.72k | return 0; |
1740 | | /* Fall through. */ |
1741 | 2.78M | case 1: |
1742 | 2.78M | return !x->array[0]; |
1743 | 0 | default: |
1744 | 0 | abort (); |
1745 | 2.83M | } |
1746 | 2.83M | } |
1747 | | |
1748 | | static INLINE int |
1749 | | cpu_flags_equal (const union i386_cpu_flags *x, |
1750 | | const union i386_cpu_flags *y) |
1751 | 452 | { |
1752 | 452 | switch (ARRAY_SIZE(x->array)) |
1753 | 452 | { |
1754 | 452 | case 5: |
1755 | 452 | if (x->array[4] != y->array[4]) |
1756 | 0 | return 0; |
1757 | | /* Fall through. */ |
1758 | 452 | case 4: |
1759 | 452 | if (x->array[3] != y->array[3]) |
1760 | 2 | return 0; |
1761 | | /* Fall through. */ |
1762 | 450 | case 3: |
1763 | 450 | if (x->array[2] != y->array[2]) |
1764 | 0 | return 0; |
1765 | | /* Fall through. */ |
1766 | 450 | case 2: |
1767 | 450 | if (x->array[1] != y->array[1]) |
1768 | 0 | return 0; |
1769 | | /* Fall through. */ |
1770 | 450 | case 1: |
1771 | 450 | return x->array[0] == y->array[0]; |
1772 | 0 | break; |
1773 | 0 | default: |
1774 | 0 | abort (); |
1775 | 452 | } |
1776 | 452 | } |
1777 | | |
1778 | | static INLINE int |
1779 | | cpu_flags_check_cpu64 (i386_cpu_attr a) |
1780 | 2.00M | { |
1781 | 2.00M | return !((flag_code == CODE_64BIT && a.bitfield.cpuno64) |
1782 | 2.00M | || (flag_code != CODE_64BIT && a.bitfield.cpu64)); |
1783 | 2.00M | } |
1784 | | |
1785 | | static INLINE i386_cpu_flags |
1786 | | cpu_flags_and (i386_cpu_flags x, i386_cpu_flags y) |
1787 | 836k | { |
1788 | 836k | switch (ARRAY_SIZE (x.array)) |
1789 | 836k | { |
1790 | 836k | case 5: |
1791 | 836k | x.array [4] &= y.array [4]; |
1792 | | /* Fall through. */ |
1793 | 836k | case 4: |
1794 | 836k | x.array [3] &= y.array [3]; |
1795 | | /* Fall through. */ |
1796 | 836k | case 3: |
1797 | 836k | x.array [2] &= y.array [2]; |
1798 | | /* Fall through. */ |
1799 | 836k | case 2: |
1800 | 836k | x.array [1] &= y.array [1]; |
1801 | | /* Fall through. */ |
1802 | 836k | case 1: |
1803 | 836k | x.array [0] &= y.array [0]; |
1804 | 836k | break; |
1805 | 0 | default: |
1806 | 0 | abort (); |
1807 | 836k | } |
1808 | 836k | return x; |
1809 | 836k | } |
1810 | | |
1811 | | static INLINE i386_cpu_flags |
1812 | | cpu_flags_or (i386_cpu_flags x, i386_cpu_flags y) |
1813 | 902 | { |
1814 | 902 | switch (ARRAY_SIZE (x.array)) |
1815 | 902 | { |
1816 | 902 | case 5: |
1817 | 902 | x.array [4] |= y.array [4]; |
1818 | | /* Fall through. */ |
1819 | 902 | case 4: |
1820 | 902 | x.array [3] |= y.array [3]; |
1821 | | /* Fall through. */ |
1822 | 902 | case 3: |
1823 | 902 | x.array [2] |= y.array [2]; |
1824 | | /* Fall through. */ |
1825 | 902 | case 2: |
1826 | 902 | x.array [1] |= y.array [1]; |
1827 | | /* Fall through. */ |
1828 | 902 | case 1: |
1829 | 902 | x.array [0] |= y.array [0]; |
1830 | 902 | break; |
1831 | 0 | default: |
1832 | 0 | abort (); |
1833 | 902 | } |
1834 | 902 | return x; |
1835 | 902 | } |
1836 | | |
1837 | | static INLINE i386_cpu_flags |
1838 | | cpu_flags_and_not (i386_cpu_flags x, i386_cpu_flags y) |
1839 | 0 | { |
1840 | 0 | switch (ARRAY_SIZE (x.array)) |
1841 | 0 | { |
1842 | 0 | case 5: |
1843 | 0 | x.array [4] &= ~y.array [4]; |
1844 | | /* Fall through. */ |
1845 | 0 | case 4: |
1846 | 0 | x.array [3] &= ~y.array [3]; |
1847 | | /* Fall through. */ |
1848 | 0 | case 3: |
1849 | 0 | x.array [2] &= ~y.array [2]; |
1850 | | /* Fall through. */ |
1851 | 0 | case 2: |
1852 | 0 | x.array [1] &= ~y.array [1]; |
1853 | | /* Fall through. */ |
1854 | 0 | case 1: |
1855 | 0 | x.array [0] &= ~y.array [0]; |
1856 | 0 | break; |
1857 | 0 | default: |
1858 | 0 | abort (); |
1859 | 0 | } |
1860 | 0 | return x; |
1861 | 0 | } |
1862 | | |
1863 | | static const i386_cpu_flags avx512 = CPU_ANY_AVX512F_FLAGS; |
1864 | | |
1865 | 3.97M | #define CPU_FLAGS_ARCH_MATCH 0x1 |
1866 | 3.96M | #define CPU_FLAGS_64BIT_MATCH 0x2 |
1867 | | |
1868 | | #define CPU_FLAGS_PERFECT_MATCH \ |
1869 | 1.99M | (CPU_FLAGS_ARCH_MATCH | CPU_FLAGS_64BIT_MATCH) |
1870 | | |
1871 | | /* Return CPU flags match bits. */ |
1872 | | |
1873 | | static int |
1874 | | cpu_flags_match (const insn_template *t) |
1875 | 1.99M | { |
1876 | 1.99M | i386_cpu_flags x = cpu_flags_from_attr (t->cpu); |
1877 | 1.99M | int match = cpu_flags_check_cpu64 (t->cpu) ? CPU_FLAGS_64BIT_MATCH : 0; |
1878 | | |
1879 | 1.99M | x.bitfield.cpu64 = 0; |
1880 | 1.99M | x.bitfield.cpuno64 = 0; |
1881 | | |
1882 | 1.99M | if (cpu_flags_all_zero (&x)) |
1883 | 1.28M | { |
1884 | | /* This instruction is available on all archs. */ |
1885 | 1.28M | match |= CPU_FLAGS_ARCH_MATCH; |
1886 | 1.28M | } |
1887 | 709k | else |
1888 | 709k | { |
1889 | | /* This instruction is available only on some archs. */ |
1890 | 709k | i386_cpu_flags cpu = cpu_arch_flags; |
1891 | | |
1892 | | /* AVX512VL is no standalone feature - match it and then strip it. */ |
1893 | 709k | if (x.bitfield.cpuavx512vl && !cpu.bitfield.cpuavx512vl) |
1894 | 0 | return match; |
1895 | 709k | x.bitfield.cpuavx512vl = 0; |
1896 | | |
1897 | | /* AVX and AVX2 present at the same time express an operand size |
1898 | | dependency - strip AVX2 for the purposes here. The operand size |
1899 | | dependent check occurs in check_vecOperands(). */ |
1900 | 709k | if (x.bitfield.cpuavx && x.bitfield.cpuavx2) |
1901 | 101 | x.bitfield.cpuavx2 = 0; |
1902 | | |
1903 | 709k | cpu = cpu_flags_and (x, cpu); |
1904 | 709k | if (!cpu_flags_all_zero (&cpu)) |
1905 | 705k | { |
1906 | 705k | if (x.bitfield.cpuavx) |
1907 | 11.3k | { |
1908 | | /* We need to check a few extra flags with AVX. */ |
1909 | 11.3k | if (cpu.bitfield.cpuavx |
1910 | 11.3k | && (!t->opcode_modifier.sse2avx |
1911 | 11.3k | || (sse2avx && !i.prefix[DATA_PREFIX])) |
1912 | 11.3k | && (!x.bitfield.cpuaes || cpu.bitfield.cpuaes) |
1913 | 11.3k | && (!x.bitfield.cpugfni || cpu.bitfield.cpugfni) |
1914 | 11.3k | && (!x.bitfield.cpupclmul || cpu.bitfield.cpupclmul)) |
1915 | 1.73k | match |= CPU_FLAGS_ARCH_MATCH; |
1916 | 11.3k | } |
1917 | 693k | else if (x.bitfield.cpuavx512f) |
1918 | 395 | { |
1919 | | /* We need to check a few extra flags with AVX512F. */ |
1920 | 395 | if (cpu.bitfield.cpuavx512f |
1921 | 395 | && (!x.bitfield.cpugfni || cpu.bitfield.cpugfni) |
1922 | 395 | && (!x.bitfield.cpuvaes || cpu.bitfield.cpuvaes) |
1923 | 395 | && (!x.bitfield.cpuvpclmulqdq || cpu.bitfield.cpuvpclmulqdq)) |
1924 | 395 | match |= CPU_FLAGS_ARCH_MATCH; |
1925 | 395 | } |
1926 | 693k | else |
1927 | 693k | match |= CPU_FLAGS_ARCH_MATCH; |
1928 | 705k | } |
1929 | 709k | } |
1930 | 1.99M | return match; |
1931 | 1.99M | } |
1932 | | |
1933 | | static INLINE i386_operand_type |
1934 | | operand_type_and (i386_operand_type x, i386_operand_type y) |
1935 | 1.27M | { |
1936 | 1.27M | if (x.bitfield.class != y.bitfield.class) |
1937 | 574k | x.bitfield.class = ClassNone; |
1938 | 1.27M | if (x.bitfield.instance != y.bitfield.instance) |
1939 | 18.7k | x.bitfield.instance = InstanceNone; |
1940 | | |
1941 | 1.27M | switch (ARRAY_SIZE (x.array)) |
1942 | 1.27M | { |
1943 | 0 | case 3: |
1944 | 0 | x.array [2] &= y.array [2]; |
1945 | | /* Fall through. */ |
1946 | 0 | case 2: |
1947 | 0 | x.array [1] &= y.array [1]; |
1948 | | /* Fall through. */ |
1949 | 1.27M | case 1: |
1950 | 1.27M | x.array [0] &= y.array [0]; |
1951 | 1.27M | break; |
1952 | 0 | default: |
1953 | 0 | abort (); |
1954 | 1.27M | } |
1955 | 1.27M | return x; |
1956 | 1.27M | } |
1957 | | |
1958 | | static INLINE i386_operand_type |
1959 | | operand_type_and_not (i386_operand_type x, i386_operand_type y) |
1960 | 338k | { |
1961 | 338k | gas_assert (y.bitfield.class == ClassNone); |
1962 | 338k | gas_assert (y.bitfield.instance == InstanceNone); |
1963 | | |
1964 | 338k | switch (ARRAY_SIZE (x.array)) |
1965 | 338k | { |
1966 | 0 | case 3: |
1967 | 0 | x.array [2] &= ~y.array [2]; |
1968 | | /* Fall through. */ |
1969 | 0 | case 2: |
1970 | 0 | x.array [1] &= ~y.array [1]; |
1971 | | /* Fall through. */ |
1972 | 338k | case 1: |
1973 | 338k | x.array [0] &= ~y.array [0]; |
1974 | 338k | break; |
1975 | 0 | default: |
1976 | 0 | abort (); |
1977 | 338k | } |
1978 | 338k | return x; |
1979 | 338k | } |
1980 | | |
1981 | | static INLINE i386_operand_type |
1982 | | operand_type_or (i386_operand_type x, i386_operand_type y) |
1983 | 680k | { |
1984 | 680k | gas_assert (x.bitfield.class == ClassNone || |
1985 | 680k | y.bitfield.class == ClassNone || |
1986 | 680k | x.bitfield.class == y.bitfield.class); |
1987 | 680k | gas_assert (x.bitfield.instance == InstanceNone || |
1988 | 680k | y.bitfield.instance == InstanceNone || |
1989 | 680k | x.bitfield.instance == y.bitfield.instance); |
1990 | | |
1991 | 680k | switch (ARRAY_SIZE (x.array)) |
1992 | 680k | { |
1993 | 0 | case 3: |
1994 | 0 | x.array [2] |= y.array [2]; |
1995 | | /* Fall through. */ |
1996 | 0 | case 2: |
1997 | 0 | x.array [1] |= y.array [1]; |
1998 | | /* Fall through. */ |
1999 | 680k | case 1: |
2000 | 680k | x.array [0] |= y.array [0]; |
2001 | 680k | break; |
2002 | 0 | default: |
2003 | 0 | abort (); |
2004 | 680k | } |
2005 | 680k | return x; |
2006 | 680k | } |
2007 | | |
2008 | | static INLINE i386_operand_type |
2009 | | operand_type_xor (i386_operand_type x, i386_operand_type y) |
2010 | 0 | { |
2011 | 0 | gas_assert (y.bitfield.class == ClassNone); |
2012 | 0 | gas_assert (y.bitfield.instance == InstanceNone); |
2013 | | |
2014 | 0 | switch (ARRAY_SIZE (x.array)) |
2015 | 0 | { |
2016 | 0 | case 3: |
2017 | 0 | x.array [2] ^= y.array [2]; |
2018 | | /* Fall through. */ |
2019 | 0 | case 2: |
2020 | 0 | x.array [1] ^= y.array [1]; |
2021 | | /* Fall through. */ |
2022 | 0 | case 1: |
2023 | 0 | x.array [0] ^= y.array [0]; |
2024 | 0 | break; |
2025 | 0 | default: |
2026 | 0 | abort (); |
2027 | 0 | } |
2028 | 0 | return x; |
2029 | 0 | } |
2030 | | |
2031 | | static const i386_operand_type anydisp = { |
2032 | | .bitfield = { .disp8 = 1, .disp16 = 1, .disp32 = 1, .disp64 = 1 } |
2033 | | }; |
2034 | | |
2035 | | enum operand_type |
2036 | | { |
2037 | | reg, |
2038 | | imm, |
2039 | | disp, |
2040 | | anymem |
2041 | | }; |
2042 | | |
2043 | | static INLINE int |
2044 | | operand_type_check (i386_operand_type t, enum operand_type c) |
2045 | 1.53M | { |
2046 | 1.53M | switch (c) |
2047 | 1.53M | { |
2048 | 0 | case reg: |
2049 | 0 | return t.bitfield.class == Reg; |
2050 | | |
2051 | 526k | case imm: |
2052 | 526k | return (t.bitfield.imm8 |
2053 | 526k | || t.bitfield.imm8s |
2054 | 526k | || t.bitfield.imm16 |
2055 | 526k | || t.bitfield.imm32 |
2056 | 526k | || t.bitfield.imm32s |
2057 | 526k | || t.bitfield.imm64); |
2058 | | |
2059 | 1.01M | case disp: |
2060 | 1.01M | return (t.bitfield.disp8 |
2061 | 1.01M | || t.bitfield.disp16 |
2062 | 1.01M | || t.bitfield.disp32 |
2063 | 1.01M | || t.bitfield.disp64); |
2064 | | |
2065 | 0 | case anymem: |
2066 | 0 | return (t.bitfield.disp8 |
2067 | 0 | || t.bitfield.disp16 |
2068 | 0 | || t.bitfield.disp32 |
2069 | 0 | || t.bitfield.disp64 |
2070 | 0 | || t.bitfield.baseindex); |
2071 | | |
2072 | 0 | default: |
2073 | 0 | abort (); |
2074 | 1.53M | } |
2075 | | |
2076 | 0 | return 0; |
2077 | 1.53M | } |
2078 | | |
2079 | | /* Return 1 if there is no conflict in 8bit/16bit/32bit/64bit/80bit size |
2080 | | between operand GIVEN and opeand WANTED for instruction template T. */ |
2081 | | |
2082 | | static INLINE int |
2083 | | match_operand_size (const insn_template *t, unsigned int wanted, |
2084 | | unsigned int given) |
2085 | 933k | { |
2086 | 933k | return !((i.types[given].bitfield.byte |
2087 | 933k | && !t->operand_types[wanted].bitfield.byte) |
2088 | 933k | || (i.types[given].bitfield.word |
2089 | 933k | && !t->operand_types[wanted].bitfield.word) |
2090 | 933k | || (i.types[given].bitfield.dword |
2091 | 933k | && !t->operand_types[wanted].bitfield.dword) |
2092 | 933k | || (i.types[given].bitfield.qword |
2093 | 933k | && (!t->operand_types[wanted].bitfield.qword |
2094 | | /* Don't allow 64-bit (memory) operands outside of 64-bit |
2095 | | mode, when they're used where a 64-bit GPR could also |
2096 | | be used. Checking is needed for Intel Syntax only. */ |
2097 | 0 | || (intel_syntax |
2098 | 0 | && flag_code != CODE_64BIT |
2099 | 0 | && (t->operand_types[wanted].bitfield.class == Reg |
2100 | 0 | || t->operand_types[wanted].bitfield.class == Accum |
2101 | 0 | || t->opcode_modifier.isstring)))) |
2102 | 933k | || (i.types[given].bitfield.tbyte |
2103 | 933k | && !t->operand_types[wanted].bitfield.tbyte)); |
2104 | 933k | } |
2105 | | |
2106 | | /* Return 1 if there is no conflict in SIMD register between operand |
2107 | | GIVEN and opeand WANTED for instruction template T. */ |
2108 | | |
2109 | | static INLINE int |
2110 | | match_simd_size (const insn_template *t, unsigned int wanted, |
2111 | | unsigned int given) |
2112 | 254k | { |
2113 | 254k | return !((i.types[given].bitfield.xmmword |
2114 | 254k | && !t->operand_types[wanted].bitfield.xmmword) |
2115 | 254k | || (i.types[given].bitfield.ymmword |
2116 | 254k | && !t->operand_types[wanted].bitfield.ymmword) |
2117 | 254k | || (i.types[given].bitfield.zmmword |
2118 | 254k | && !t->operand_types[wanted].bitfield.zmmword) |
2119 | 254k | || (i.types[given].bitfield.tmmword |
2120 | 254k | && !t->operand_types[wanted].bitfield.tmmword)); |
2121 | 254k | } |
2122 | | |
2123 | | /* Return 1 if there is no conflict in any size between operand GIVEN |
2124 | | and opeand WANTED for instruction template T. */ |
2125 | | |
2126 | | static INLINE int |
2127 | | match_mem_size (const insn_template *t, unsigned int wanted, |
2128 | | unsigned int given) |
2129 | 477k | { |
2130 | 477k | return (match_operand_size (t, wanted, given) |
2131 | 477k | && !((i.types[given].bitfield.unspecified |
2132 | 477k | && !i.broadcast.type |
2133 | 477k | && !i.broadcast.bytes |
2134 | 477k | && !t->operand_types[wanted].bitfield.unspecified) |
2135 | 477k | || (i.types[given].bitfield.fword |
2136 | 224k | && !t->operand_types[wanted].bitfield.fword) |
2137 | | /* For scalar opcode templates to allow register and memory |
2138 | | operands at the same time, some special casing is needed |
2139 | | here. Also for v{,p}broadcast*, {,v}pmov{s,z}*, and |
2140 | | down-conversion vpmov*. */ |
2141 | 477k | || ((t->operand_types[wanted].bitfield.class == RegSIMD |
2142 | 224k | && t->operand_types[wanted].bitfield.byte |
2143 | 425 | + t->operand_types[wanted].bitfield.word |
2144 | 425 | + t->operand_types[wanted].bitfield.dword |
2145 | 425 | + t->operand_types[wanted].bitfield.qword |
2146 | 425 | > !!t->opcode_modifier.broadcast) |
2147 | 224k | ? (i.types[given].bitfield.xmmword |
2148 | 25 | || i.types[given].bitfield.ymmword |
2149 | 25 | || i.types[given].bitfield.zmmword) |
2150 | 224k | : !match_simd_size(t, wanted, given)))); |
2151 | 477k | } |
2152 | | |
2153 | | /* Return value has MATCH_STRAIGHT set if there is no size conflict on any |
2154 | | operands for instruction template T, and it has MATCH_REVERSE set if there |
2155 | | is no size conflict on any operands for the template with operands reversed |
2156 | | (and the template allows for reversing in the first place). */ |
2157 | | |
2158 | 1.20M | #define MATCH_STRAIGHT 1 |
2159 | 113k | #define MATCH_REVERSE 2 |
2160 | | |
2161 | | static INLINE unsigned int |
2162 | | operand_size_match (const insn_template *t) |
2163 | 998k | { |
2164 | 998k | unsigned int j, match = MATCH_STRAIGHT; |
2165 | | |
2166 | | /* Don't check non-absolute jump instructions. */ |
2167 | 998k | if (t->opcode_modifier.jump |
2168 | 998k | && t->opcode_modifier.jump != JUMP_ABSOLUTE) |
2169 | 22.5k | return match; |
2170 | | |
2171 | | /* Check memory and accumulator operand size. */ |
2172 | 1.40M | for (j = 0; j < i.operands; j++) |
2173 | 549k | { |
2174 | 549k | if (i.types[j].bitfield.class != Reg |
2175 | 549k | && i.types[j].bitfield.class != RegSIMD |
2176 | 549k | && t->opcode_modifier.operandconstraint == ANY_SIZE) |
2177 | 466 | continue; |
2178 | | |
2179 | 548k | if (t->operand_types[j].bitfield.class == Reg |
2180 | 548k | && !match_operand_size (t, j, j)) |
2181 | 0 | { |
2182 | 0 | match = 0; |
2183 | 0 | break; |
2184 | 0 | } |
2185 | | |
2186 | 548k | if (t->operand_types[j].bitfield.class == RegSIMD |
2187 | 548k | && !match_simd_size (t, j, j)) |
2188 | 0 | { |
2189 | 0 | match = 0; |
2190 | 0 | break; |
2191 | 0 | } |
2192 | | |
2193 | 548k | if (t->operand_types[j].bitfield.instance == Accum |
2194 | 548k | && (!match_operand_size (t, j, j) || !match_simd_size (t, j, j))) |
2195 | 0 | { |
2196 | 0 | match = 0; |
2197 | 0 | break; |
2198 | 0 | } |
2199 | | |
2200 | 548k | if ((i.flags[j] & Operand_Mem) && !match_mem_size (t, j, j)) |
2201 | 122k | { |
2202 | 122k | match = 0; |
2203 | 122k | break; |
2204 | 122k | } |
2205 | 548k | } |
2206 | | |
2207 | 976k | if (!t->opcode_modifier.d) |
2208 | 836k | return match; |
2209 | | |
2210 | | /* Check reverse. */ |
2211 | 139k | gas_assert (i.operands >= 2); |
2212 | | |
2213 | 173k | for (j = 0; j < i.operands; j++) |
2214 | 164k | { |
2215 | 164k | unsigned int given = i.operands - j - 1; |
2216 | | |
2217 | | /* For FMA4 and XOP insns VEX.W controls just the first two |
2218 | | register operands. */ |
2219 | 164k | if (is_cpu (t, CpuFMA4) || is_cpu (t, CpuXOP)) |
2220 | 0 | given = j < 2 ? 1 - j : j; |
2221 | | |
2222 | 164k | if (t->operand_types[j].bitfield.class == Reg |
2223 | 164k | && !match_operand_size (t, j, given)) |
2224 | 0 | return match; |
2225 | | |
2226 | 164k | if (t->operand_types[j].bitfield.class == RegSIMD |
2227 | 164k | && !match_simd_size (t, j, given)) |
2228 | 0 | return match; |
2229 | | |
2230 | 164k | if (t->operand_types[j].bitfield.instance == Accum |
2231 | 164k | && (!match_operand_size (t, j, given) |
2232 | 8.22k | || !match_simd_size (t, j, given))) |
2233 | 0 | return match; |
2234 | | |
2235 | 164k | if ((i.flags[given] & Operand_Mem) && !match_mem_size (t, j, given)) |
2236 | 130k | return match; |
2237 | 164k | } |
2238 | | |
2239 | 9.04k | return match | MATCH_REVERSE; |
2240 | 139k | } |
2241 | | |
2242 | | static INLINE int |
2243 | | operand_type_match (i386_operand_type overlap, |
2244 | | i386_operand_type given) |
2245 | 346k | { |
2246 | 346k | i386_operand_type temp = overlap; |
2247 | | |
2248 | 346k | temp.bitfield.unspecified = 0; |
2249 | 346k | temp.bitfield.byte = 0; |
2250 | 346k | temp.bitfield.word = 0; |
2251 | 346k | temp.bitfield.dword = 0; |
2252 | 346k | temp.bitfield.fword = 0; |
2253 | 346k | temp.bitfield.qword = 0; |
2254 | 346k | temp.bitfield.tbyte = 0; |
2255 | 346k | temp.bitfield.xmmword = 0; |
2256 | 346k | temp.bitfield.ymmword = 0; |
2257 | 346k | temp.bitfield.zmmword = 0; |
2258 | 346k | temp.bitfield.tmmword = 0; |
2259 | 346k | if (operand_type_all_zero (&temp)) |
2260 | 112k | goto mismatch; |
2261 | | |
2262 | 233k | if (given.bitfield.baseindex == overlap.bitfield.baseindex) |
2263 | 233k | return 1; |
2264 | | |
2265 | 112k | mismatch: |
2266 | 112k | i.error = operand_type_mismatch; |
2267 | 112k | return 0; |
2268 | 233k | } |
2269 | | |
2270 | | /* If given types g0 and g1 are registers they must be of the same type |
2271 | | unless the expected operand type register overlap is null. |
2272 | | Intel syntax sized memory operands are also checked here. */ |
2273 | | |
2274 | | static INLINE int |
2275 | | operand_type_register_match (i386_operand_type g0, |
2276 | | i386_operand_type t0, |
2277 | | i386_operand_type g1, |
2278 | | i386_operand_type t1) |
2279 | 6 | { |
2280 | 6 | if (g0.bitfield.class != Reg |
2281 | 6 | && g0.bitfield.class != RegSIMD |
2282 | 6 | && (g0.bitfield.unspecified |
2283 | 6 | || !operand_type_check (g0, anymem))) |
2284 | 6 | return 1; |
2285 | | |
2286 | 0 | if (g1.bitfield.class != Reg |
2287 | 0 | && g1.bitfield.class != RegSIMD |
2288 | 0 | && (g1.bitfield.unspecified |
2289 | 0 | || !operand_type_check (g1, anymem))) |
2290 | 0 | return 1; |
2291 | | |
2292 | 0 | if (g0.bitfield.byte == g1.bitfield.byte |
2293 | 0 | && g0.bitfield.word == g1.bitfield.word |
2294 | 0 | && g0.bitfield.dword == g1.bitfield.dword |
2295 | 0 | && g0.bitfield.qword == g1.bitfield.qword |
2296 | 0 | && g0.bitfield.xmmword == g1.bitfield.xmmword |
2297 | 0 | && g0.bitfield.ymmword == g1.bitfield.ymmword |
2298 | 0 | && g0.bitfield.zmmword == g1.bitfield.zmmword) |
2299 | 0 | return 1; |
2300 | | |
2301 | | /* If expectations overlap in no more than a single size, all is fine. */ |
2302 | 0 | g0 = operand_type_and (t0, t1); |
2303 | 0 | if (g0.bitfield.byte |
2304 | 0 | + g0.bitfield.word |
2305 | 0 | + g0.bitfield.dword |
2306 | 0 | + g0.bitfield.qword |
2307 | 0 | + g0.bitfield.xmmword |
2308 | 0 | + g0.bitfield.ymmword |
2309 | 0 | + g0.bitfield.zmmword <= 1) |
2310 | 0 | return 1; |
2311 | | |
2312 | 0 | i.error = register_type_mismatch; |
2313 | |
|
2314 | 0 | return 0; |
2315 | 0 | } |
2316 | | |
2317 | | static INLINE unsigned int |
2318 | | register_number (const reg_entry *r) |
2319 | 0 | { |
2320 | 0 | unsigned int nr = r->reg_num; |
2321 | |
|
2322 | 0 | if (r->reg_flags & RegRex) |
2323 | 0 | nr += 8; |
2324 | |
|
2325 | 0 | if (r->reg_flags & RegVRex) |
2326 | 0 | nr += 16; |
2327 | |
|
2328 | 0 | return nr; |
2329 | 0 | } |
2330 | | |
2331 | | static INLINE unsigned int |
2332 | | mode_from_disp_size (i386_operand_type t) |
2333 | 0 | { |
2334 | 0 | if (t.bitfield.disp8) |
2335 | 0 | return 1; |
2336 | 0 | else if (t.bitfield.disp16 |
2337 | 0 | || t.bitfield.disp32) |
2338 | 0 | return 2; |
2339 | 0 | else |
2340 | 0 | return 0; |
2341 | 0 | } |
2342 | | |
2343 | | static INLINE int |
2344 | | fits_in_signed_byte (addressT num) |
2345 | 205k | { |
2346 | 205k | return num + 0x80 <= 0xff; |
2347 | 205k | } |
2348 | | |
2349 | | static INLINE int |
2350 | | fits_in_unsigned_byte (addressT num) |
2351 | 86.3k | { |
2352 | 86.3k | return num <= 0xff; |
2353 | 86.3k | } |
2354 | | |
2355 | | static INLINE int |
2356 | | fits_in_unsigned_word (addressT num) |
2357 | 113k | { |
2358 | 113k | return num <= 0xffff; |
2359 | 113k | } |
2360 | | |
2361 | | static INLINE int |
2362 | | fits_in_signed_word (addressT num) |
2363 | 5.80k | { |
2364 | 5.80k | return num + 0x8000 <= 0xffff; |
2365 | 5.80k | } |
2366 | | |
2367 | | static INLINE int |
2368 | | fits_in_signed_long (addressT num ATTRIBUTE_UNUSED) |
2369 | 77.1k | { |
2370 | | #ifndef BFD64 |
2371 | | return 1; |
2372 | | #else |
2373 | 77.1k | return num + 0x80000000 <= 0xffffffff; |
2374 | 77.1k | #endif |
2375 | 77.1k | } /* fits_in_signed_long() */ |
2376 | | |
2377 | | static INLINE int |
2378 | | fits_in_unsigned_long (addressT num ATTRIBUTE_UNUSED) |
2379 | 930k | { |
2380 | | #ifndef BFD64 |
2381 | | return 1; |
2382 | | #else |
2383 | 930k | return num <= 0xffffffff; |
2384 | 930k | #endif |
2385 | 930k | } /* fits_in_unsigned_long() */ |
2386 | | |
2387 | | static INLINE valueT extend_to_32bit_address (addressT num) |
2388 | 0 | { |
2389 | 0 | #ifdef BFD64 |
2390 | 0 | if (fits_in_unsigned_long(num)) |
2391 | 0 | return (num ^ ((addressT) 1 << 31)) - ((addressT) 1 << 31); |
2392 | | |
2393 | 0 | if (!fits_in_signed_long (num)) |
2394 | 0 | return num & 0xffffffff; |
2395 | 0 | #endif |
2396 | | |
2397 | 0 | return num; |
2398 | 0 | } |
2399 | | |
2400 | | static INLINE int |
2401 | | fits_in_disp8 (offsetT num) |
2402 | 119k | { |
2403 | 119k | int shift = i.memshift; |
2404 | 119k | unsigned int mask; |
2405 | | |
2406 | 119k | if (shift == -1) |
2407 | 0 | abort (); |
2408 | | |
2409 | 119k | mask = (1 << shift) - 1; |
2410 | | |
2411 | | /* Return 0 if NUM isn't properly aligned. */ |
2412 | 119k | if ((num & mask)) |
2413 | 0 | return 0; |
2414 | | |
2415 | | /* Check if NUM will fit in 8bit after shift. */ |
2416 | 119k | return fits_in_signed_byte (num >> shift); |
2417 | 119k | } |
2418 | | |
2419 | | static INLINE int |
2420 | | fits_in_imm4 (offsetT num) |
2421 | 0 | { |
2422 | | /* Despite the name, check for imm3 if we're dealing with EVEX. */ |
2423 | 0 | return (num & (i.vec_encoding != vex_encoding_evex ? 0xf : 7)) == num; |
2424 | 0 | } |
2425 | | |
2426 | | static i386_operand_type |
2427 | | smallest_imm_type (offsetT num) |
2428 | 94.7k | { |
2429 | 94.7k | i386_operand_type t; |
2430 | | |
2431 | 94.7k | operand_type_set (&t, 0); |
2432 | 94.7k | t.bitfield.imm64 = 1; |
2433 | | |
2434 | 94.7k | if (cpu_arch_tune != PROCESSOR_I486 && num == 1) |
2435 | 8.41k | { |
2436 | | /* This code is disabled on the 486 because all the Imm1 forms |
2437 | | in the opcode table are slower on the i486. They're the |
2438 | | versions with the implicitly specified single-position |
2439 | | displacement, which has another syntax if you really want to |
2440 | | use that form. */ |
2441 | 8.41k | t.bitfield.imm1 = 1; |
2442 | 8.41k | t.bitfield.imm8 = 1; |
2443 | 8.41k | t.bitfield.imm8s = 1; |
2444 | 8.41k | t.bitfield.imm16 = 1; |
2445 | 8.41k | t.bitfield.imm32 = 1; |
2446 | 8.41k | t.bitfield.imm32s = 1; |
2447 | 8.41k | } |
2448 | 86.3k | else if (fits_in_signed_byte (num)) |
2449 | 79.9k | { |
2450 | 79.9k | if (fits_in_unsigned_byte (num)) |
2451 | 77.7k | t.bitfield.imm8 = 1; |
2452 | 79.9k | t.bitfield.imm8s = 1; |
2453 | 79.9k | t.bitfield.imm16 = 1; |
2454 | 79.9k | t.bitfield.imm32 = 1; |
2455 | 79.9k | t.bitfield.imm32s = 1; |
2456 | 79.9k | } |
2457 | 6.38k | else if (fits_in_unsigned_byte (num)) |
2458 | 587 | { |
2459 | 587 | t.bitfield.imm8 = 1; |
2460 | 587 | t.bitfield.imm16 = 1; |
2461 | 587 | t.bitfield.imm32 = 1; |
2462 | 587 | t.bitfield.imm32s = 1; |
2463 | 587 | } |
2464 | 5.80k | else if (fits_in_signed_word (num) || fits_in_unsigned_word (num)) |
2465 | 813 | { |
2466 | 813 | t.bitfield.imm16 = 1; |
2467 | 813 | t.bitfield.imm32 = 1; |
2468 | 813 | t.bitfield.imm32s = 1; |
2469 | 813 | } |
2470 | 4.98k | else if (fits_in_signed_long (num)) |
2471 | 4.14k | { |
2472 | 4.14k | t.bitfield.imm32 = 1; |
2473 | 4.14k | t.bitfield.imm32s = 1; |
2474 | 4.14k | } |
2475 | 847 | else if (fits_in_unsigned_long (num)) |
2476 | 0 | t.bitfield.imm32 = 1; |
2477 | | |
2478 | 94.7k | return t; |
2479 | 94.7k | } |
2480 | | |
2481 | | static offsetT |
2482 | | offset_in_range (offsetT val, int size) |
2483 | 167k | { |
2484 | 167k | addressT mask; |
2485 | | |
2486 | 167k | switch (size) |
2487 | 167k | { |
2488 | 82.2k | case 1: mask = ((addressT) 1 << 8) - 1; break; |
2489 | 43.0k | case 2: mask = ((addressT) 1 << 16) - 1; break; |
2490 | 0 | #ifdef BFD64 |
2491 | 42.0k | case 4: mask = ((addressT) 1 << 32) - 1; break; |
2492 | 0 | #endif |
2493 | 0 | case sizeof (val): return val; |
2494 | 0 | default: abort (); |
2495 | 167k | } |
2496 | | |
2497 | 167k | if ((val & ~mask) != 0 && (-val & ~mask) != 0) |
2498 | 2.07k | as_warn (_("0x%" PRIx64 " shortened to 0x%" PRIx64), |
2499 | 2.07k | (uint64_t) val, (uint64_t) (val & mask)); |
2500 | | |
2501 | 167k | return val & mask; |
2502 | 167k | } |
2503 | | |
2504 | | static INLINE const char *insn_name (const insn_template *t) |
2505 | 2.90M | { |
2506 | 2.90M | return &i386_mnemonics[t->mnem_off]; |
2507 | 2.90M | } |
2508 | | |
2509 | | enum PREFIX_GROUP |
2510 | | { |
2511 | | PREFIX_EXIST = 0, |
2512 | | PREFIX_LOCK, |
2513 | | PREFIX_REP, |
2514 | | PREFIX_DS, |
2515 | | PREFIX_OTHER |
2516 | | }; |
2517 | | |
2518 | | /* Returns |
2519 | | a. PREFIX_EXIST if attempting to add a prefix where one from the |
2520 | | same class already exists. |
2521 | | b. PREFIX_LOCK if lock prefix is added. |
2522 | | c. PREFIX_REP if rep/repne prefix is added. |
2523 | | d. PREFIX_DS if ds prefix is added. |
2524 | | e. PREFIX_OTHER if other prefix is added. |
2525 | | */ |
2526 | | |
2527 | | static enum PREFIX_GROUP |
2528 | | add_prefix (unsigned int prefix) |
2529 | 8.80k | { |
2530 | 8.80k | enum PREFIX_GROUP ret = PREFIX_OTHER; |
2531 | 8.80k | unsigned int q; |
2532 | | |
2533 | 8.80k | if (prefix >= REX_OPCODE && prefix < REX_OPCODE + 16 |
2534 | 8.80k | && flag_code == CODE_64BIT) |
2535 | 842 | { |
2536 | 842 | if ((i.prefix[REX_PREFIX] & prefix & REX_W) |
2537 | 842 | || (i.prefix[REX_PREFIX] & prefix & REX_R) |
2538 | 842 | || (i.prefix[REX_PREFIX] & prefix & REX_X) |
2539 | 842 | || (i.prefix[REX_PREFIX] & prefix & REX_B)) |
2540 | 0 | ret = PREFIX_EXIST; |
2541 | 842 | q = REX_PREFIX; |
2542 | 842 | } |
2543 | 7.96k | else |
2544 | 7.96k | { |
2545 | 7.96k | switch (prefix) |
2546 | 7.96k | { |
2547 | 0 | default: |
2548 | 0 | abort (); |
2549 | | |
2550 | 114 | case DS_PREFIX_OPCODE: |
2551 | 114 | ret = PREFIX_DS; |
2552 | | /* Fall through. */ |
2553 | 2.35k | case CS_PREFIX_OPCODE: |
2554 | 2.44k | case ES_PREFIX_OPCODE: |
2555 | 5.06k | case FS_PREFIX_OPCODE: |
2556 | 5.08k | case GS_PREFIX_OPCODE: |
2557 | 5.14k | case SS_PREFIX_OPCODE: |
2558 | 5.14k | q = SEG_PREFIX; |
2559 | 5.14k | break; |
2560 | | |
2561 | 484 | case REPNE_PREFIX_OPCODE: |
2562 | 687 | case REPE_PREFIX_OPCODE: |
2563 | 687 | q = REP_PREFIX; |
2564 | 687 | ret = PREFIX_REP; |
2565 | 687 | break; |
2566 | | |
2567 | 0 | case LOCK_PREFIX_OPCODE: |
2568 | 0 | q = LOCK_PREFIX; |
2569 | 0 | ret = PREFIX_LOCK; |
2570 | 0 | break; |
2571 | | |
2572 | 1.86k | case FWAIT_OPCODE: |
2573 | 1.86k | q = WAIT_PREFIX; |
2574 | 1.86k | break; |
2575 | | |
2576 | 190 | case ADDR_PREFIX_OPCODE: |
2577 | 190 | q = ADDR_PREFIX; |
2578 | 190 | break; |
2579 | | |
2580 | 78 | case DATA_PREFIX_OPCODE: |
2581 | 78 | q = DATA_PREFIX; |
2582 | 78 | break; |
2583 | 7.96k | } |
2584 | 7.96k | if (i.prefix[q] != 0) |
2585 | 700 | ret = PREFIX_EXIST; |
2586 | 7.96k | } |
2587 | | |
2588 | 8.80k | if (ret) |
2589 | 8.10k | { |
2590 | 8.10k | if (!i.prefix[q]) |
2591 | 8.10k | ++i.prefixes; |
2592 | 8.10k | i.prefix[q] |= prefix; |
2593 | 8.10k | } |
2594 | 700 | else |
2595 | 700 | as_bad (_("same type of prefix used twice")); |
2596 | | |
2597 | 8.80k | return ret; |
2598 | 8.80k | } |
2599 | | |
2600 | | static void |
2601 | | update_code_flag (int value, int check) |
2602 | 8.99k | { |
2603 | 8.99k | PRINTF_LIKE ((*as_error)); |
2604 | | |
2605 | 8.99k | flag_code = (enum flag_code) value; |
2606 | 8.99k | if (flag_code == CODE_64BIT) |
2607 | 1.16k | { |
2608 | 1.16k | cpu_arch_flags.bitfield.cpu64 = 1; |
2609 | 1.16k | cpu_arch_flags.bitfield.cpuno64 = 0; |
2610 | 1.16k | } |
2611 | 7.82k | else |
2612 | 7.82k | { |
2613 | 7.82k | cpu_arch_flags.bitfield.cpu64 = 0; |
2614 | 7.82k | cpu_arch_flags.bitfield.cpuno64 = 1; |
2615 | 7.82k | } |
2616 | 8.99k | if (value == CODE_64BIT && !cpu_arch_flags.bitfield.cpulm ) |
2617 | 0 | { |
2618 | 0 | if (check) |
2619 | 0 | as_error = as_fatal; |
2620 | 0 | else |
2621 | 0 | as_error = as_bad; |
2622 | 0 | (*as_error) (_("64bit mode not supported on `%s'."), |
2623 | 0 | cpu_arch_name ? cpu_arch_name : default_arch); |
2624 | 0 | } |
2625 | 8.99k | if (value == CODE_32BIT && !cpu_arch_flags.bitfield.cpui386) |
2626 | 0 | { |
2627 | 0 | if (check) |
2628 | 0 | as_error = as_fatal; |
2629 | 0 | else |
2630 | 0 | as_error = as_bad; |
2631 | 0 | (*as_error) (_("32bit mode not supported on `%s'."), |
2632 | 0 | cpu_arch_name ? cpu_arch_name : default_arch); |
2633 | 0 | } |
2634 | 8.99k | stackop_size = '\0'; |
2635 | 8.99k | } |
2636 | | |
2637 | | static void |
2638 | | set_code_flag (int value) |
2639 | 7.83k | { |
2640 | 7.83k | update_code_flag (value, 0); |
2641 | 7.83k | } |
2642 | | |
2643 | | static void |
2644 | | set_16bit_gcc_code_flag (int new_code_flag) |
2645 | 0 | { |
2646 | 0 | flag_code = (enum flag_code) new_code_flag; |
2647 | 0 | if (flag_code != CODE_16BIT) |
2648 | 0 | abort (); |
2649 | 0 | cpu_arch_flags.bitfield.cpu64 = 0; |
2650 | 0 | cpu_arch_flags.bitfield.cpuno64 = 1; |
2651 | 0 | stackop_size = LONG_MNEM_SUFFIX; |
2652 | 0 | } |
2653 | | |
2654 | | static void |
2655 | | set_intel_syntax (int syntax_flag) |
2656 | 0 | { |
2657 | | /* Find out if register prefixing is specified. */ |
2658 | 0 | int ask_naked_reg = 0; |
2659 | |
|
2660 | 0 | SKIP_WHITESPACE (); |
2661 | 0 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) |
2662 | 0 | { |
2663 | 0 | char *string; |
2664 | 0 | int e = get_symbol_name (&string); |
2665 | |
|
2666 | 0 | if (strcmp (string, "prefix") == 0) |
2667 | 0 | ask_naked_reg = 1; |
2668 | 0 | else if (strcmp (string, "noprefix") == 0) |
2669 | 0 | ask_naked_reg = -1; |
2670 | 0 | else |
2671 | 0 | as_bad (_("bad argument to syntax directive.")); |
2672 | 0 | (void) restore_line_pointer (e); |
2673 | 0 | } |
2674 | 0 | demand_empty_rest_of_line (); |
2675 | |
|
2676 | 0 | intel_syntax = syntax_flag; |
2677 | |
|
2678 | 0 | if (ask_naked_reg == 0) |
2679 | 0 | allow_naked_reg = (intel_syntax |
2680 | 0 | && (bfd_get_symbol_leading_char (stdoutput) != '\0')); |
2681 | 0 | else |
2682 | 0 | allow_naked_reg = (ask_naked_reg < 0); |
2683 | |
|
2684 | 0 | expr_set_rank (O_full_ptr, syntax_flag ? 10 : 0); |
2685 | |
|
2686 | 0 | register_prefix = allow_naked_reg ? "" : "%"; |
2687 | 0 | } |
2688 | | |
2689 | | static void |
2690 | | set_intel_mnemonic (int mnemonic_flag) |
2691 | 0 | { |
2692 | 0 | intel_mnemonic = mnemonic_flag; |
2693 | 0 | } |
2694 | | |
2695 | | static void |
2696 | | set_allow_index_reg (int flag) |
2697 | 10 | { |
2698 | 10 | allow_index_reg = flag; |
2699 | 10 | } |
2700 | | |
2701 | | static void |
2702 | | set_check (int what) |
2703 | 0 | { |
2704 | 0 | enum check_kind *kind; |
2705 | 0 | const char *str; |
2706 | |
|
2707 | 0 | if (what) |
2708 | 0 | { |
2709 | 0 | kind = &operand_check; |
2710 | 0 | str = "operand"; |
2711 | 0 | } |
2712 | 0 | else |
2713 | 0 | { |
2714 | 0 | kind = &sse_check; |
2715 | 0 | str = "sse"; |
2716 | 0 | } |
2717 | |
|
2718 | 0 | SKIP_WHITESPACE (); |
2719 | |
|
2720 | 0 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) |
2721 | 0 | { |
2722 | 0 | char *string; |
2723 | 0 | int e = get_symbol_name (&string); |
2724 | |
|
2725 | 0 | if (strcmp (string, "none") == 0) |
2726 | 0 | *kind = check_none; |
2727 | 0 | else if (strcmp (string, "warning") == 0) |
2728 | 0 | *kind = check_warning; |
2729 | 0 | else if (strcmp (string, "error") == 0) |
2730 | 0 | *kind = check_error; |
2731 | 0 | else |
2732 | 0 | as_bad (_("bad argument to %s_check directive."), str); |
2733 | 0 | (void) restore_line_pointer (e); |
2734 | 0 | } |
2735 | 0 | else |
2736 | 0 | as_bad (_("missing argument for %s_check directive"), str); |
2737 | |
|
2738 | 0 | demand_empty_rest_of_line (); |
2739 | 0 | } |
2740 | | |
2741 | | static void |
2742 | | check_cpu_arch_compatible (const char *name ATTRIBUTE_UNUSED, |
2743 | | i386_cpu_flags new_flag ATTRIBUTE_UNUSED) |
2744 | 18 | { |
2745 | 18 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
2746 | 18 | static const char *arch; |
2747 | | |
2748 | | /* Intel MCU is only supported on ELF. */ |
2749 | 18 | if (!IS_ELF) |
2750 | 0 | return; |
2751 | | |
2752 | 18 | if (!arch) |
2753 | 1 | { |
2754 | | /* Use cpu_arch_name if it is set in md_parse_option. Otherwise |
2755 | | use default_arch. */ |
2756 | 1 | arch = cpu_arch_name; |
2757 | 1 | if (!arch) |
2758 | 1 | arch = default_arch; |
2759 | 1 | } |
2760 | | |
2761 | | /* If we are targeting Intel MCU, we must enable it. */ |
2762 | 18 | if ((get_elf_backend_data (stdoutput)->elf_machine_code == EM_IAMCU) |
2763 | 18 | == new_flag.bitfield.cpuiamcu) |
2764 | 18 | return; |
2765 | | |
2766 | 0 | as_bad (_("`%s' is not supported on `%s'"), name, arch); |
2767 | 0 | #endif |
2768 | 0 | } |
2769 | | |
2770 | | static void |
2771 | | extend_cpu_sub_arch_name (const char *name) |
2772 | 2 | { |
2773 | 2 | if (cpu_sub_arch_name) |
2774 | 0 | cpu_sub_arch_name = reconcat (cpu_sub_arch_name, cpu_sub_arch_name, |
2775 | 0 | ".", name, (const char *) NULL); |
2776 | 2 | else |
2777 | 2 | cpu_sub_arch_name = concat (".", name, (const char *) NULL); |
2778 | 2 | } |
2779 | | |
2780 | | static void |
2781 | | set_cpu_arch (int dummy ATTRIBUTE_UNUSED) |
2782 | 4.12k | { |
2783 | 4.12k | typedef struct arch_stack_entry |
2784 | 4.12k | { |
2785 | 4.12k | const struct arch_stack_entry *prev; |
2786 | 4.12k | const char *name; |
2787 | 4.12k | char *sub_name; |
2788 | 4.12k | i386_cpu_flags flags; |
2789 | 4.12k | i386_cpu_flags isa_flags; |
2790 | 4.12k | enum processor_type isa; |
2791 | 4.12k | enum flag_code flag_code; |
2792 | 4.12k | char stackop_size; |
2793 | 4.12k | bool no_cond_jump_promotion; |
2794 | 4.12k | } arch_stack_entry; |
2795 | 4.12k | static const arch_stack_entry *arch_stack_top; |
2796 | | |
2797 | 4.12k | SKIP_WHITESPACE (); |
2798 | | |
2799 | 4.12k | if (!is_end_of_line[(unsigned char) *input_line_pointer]) |
2800 | 2.71k | { |
2801 | 2.71k | char *s; |
2802 | 2.71k | int e = get_symbol_name (&s); |
2803 | 2.71k | const char *string = s; |
2804 | 2.71k | unsigned int j = 0; |
2805 | 2.71k | i386_cpu_flags flags; |
2806 | | |
2807 | 2.71k | if (strcmp (string, "default") == 0) |
2808 | 0 | { |
2809 | 0 | if (strcmp (default_arch, "iamcu") == 0) |
2810 | 0 | string = default_arch; |
2811 | 0 | else |
2812 | 0 | { |
2813 | 0 | static const i386_cpu_flags cpu_unknown_flags = CPU_UNKNOWN_FLAGS; |
2814 | |
|
2815 | 0 | cpu_arch_name = NULL; |
2816 | 0 | free (cpu_sub_arch_name); |
2817 | 0 | cpu_sub_arch_name = NULL; |
2818 | 0 | cpu_arch_flags = cpu_unknown_flags; |
2819 | 0 | if (flag_code == CODE_64BIT) |
2820 | 0 | { |
2821 | 0 | cpu_arch_flags.bitfield.cpu64 = 1; |
2822 | 0 | cpu_arch_flags.bitfield.cpuno64 = 0; |
2823 | 0 | } |
2824 | 0 | else |
2825 | 0 | { |
2826 | 0 | cpu_arch_flags.bitfield.cpu64 = 0; |
2827 | 0 | cpu_arch_flags.bitfield.cpuno64 = 1; |
2828 | 0 | } |
2829 | 0 | cpu_arch_isa = PROCESSOR_UNKNOWN; |
2830 | 0 | cpu_arch_isa_flags = cpu_arch[flag_code == CODE_64BIT].enable; |
2831 | 0 | if (!cpu_arch_tune_set) |
2832 | 0 | { |
2833 | 0 | cpu_arch_tune = cpu_arch_isa; |
2834 | 0 | cpu_arch_tune_flags = cpu_arch_isa_flags; |
2835 | 0 | } |
2836 | |
|
2837 | 0 | j = ARRAY_SIZE (cpu_arch) + 1; |
2838 | 0 | } |
2839 | 0 | } |
2840 | 2.71k | else if (strcmp (string, "push") == 0) |
2841 | 0 | { |
2842 | 0 | arch_stack_entry *top = XNEW (arch_stack_entry); |
2843 | |
|
2844 | 0 | top->name = cpu_arch_name; |
2845 | 0 | if (cpu_sub_arch_name) |
2846 | 0 | top->sub_name = xstrdup (cpu_sub_arch_name); |
2847 | 0 | else |
2848 | 0 | top->sub_name = NULL; |
2849 | 0 | top->flags = cpu_arch_flags; |
2850 | 0 | top->isa = cpu_arch_isa; |
2851 | 0 | top->isa_flags = cpu_arch_isa_flags; |
2852 | 0 | top->flag_code = flag_code; |
2853 | 0 | top->stackop_size = stackop_size; |
2854 | 0 | top->no_cond_jump_promotion = no_cond_jump_promotion; |
2855 | |
|
2856 | 0 | top->prev = arch_stack_top; |
2857 | 0 | arch_stack_top = top; |
2858 | |
|
2859 | 0 | (void) restore_line_pointer (e); |
2860 | 0 | demand_empty_rest_of_line (); |
2861 | 0 | return; |
2862 | 0 | } |
2863 | 2.71k | else if (strcmp (string, "pop") == 0) |
2864 | 0 | { |
2865 | 0 | const arch_stack_entry *top = arch_stack_top; |
2866 | |
|
2867 | 0 | if (!top) |
2868 | 0 | as_bad (_(".arch stack is empty")); |
2869 | 0 | else if (top->flag_code != flag_code |
2870 | 0 | || top->stackop_size != stackop_size) |
2871 | 0 | { |
2872 | 0 | static const unsigned int bits[] = { |
2873 | 0 | [CODE_16BIT] = 16, |
2874 | 0 | [CODE_32BIT] = 32, |
2875 | 0 | [CODE_64BIT] = 64, |
2876 | 0 | }; |
2877 | |
|
2878 | 0 | as_bad (_("this `.arch pop' requires `.code%u%s' to be in effect"), |
2879 | 0 | bits[top->flag_code], |
2880 | 0 | top->stackop_size == LONG_MNEM_SUFFIX ? "gcc" : ""); |
2881 | 0 | } |
2882 | 0 | else |
2883 | 0 | { |
2884 | 0 | arch_stack_top = top->prev; |
2885 | |
|
2886 | 0 | cpu_arch_name = top->name; |
2887 | 0 | free (cpu_sub_arch_name); |
2888 | 0 | cpu_sub_arch_name = top->sub_name; |
2889 | 0 | cpu_arch_flags = top->flags; |
2890 | 0 | cpu_arch_isa = top->isa; |
2891 | 0 | cpu_arch_isa_flags = top->isa_flags; |
2892 | 0 | no_cond_jump_promotion = top->no_cond_jump_promotion; |
2893 | |
|
2894 | 0 | XDELETE (top); |
2895 | 0 | } |
2896 | |
|
2897 | 0 | (void) restore_line_pointer (e); |
2898 | 0 | demand_empty_rest_of_line (); |
2899 | 0 | return; |
2900 | 0 | } |
2901 | | |
2902 | 458k | for (; j < ARRAY_SIZE (cpu_arch); j++) |
2903 | 456k | { |
2904 | 456k | if (strcmp (string + (*string == '.'), cpu_arch[j].name) == 0 |
2905 | 456k | && (*string == '.') == (cpu_arch[j].type == PROCESSOR_NONE)) |
2906 | 470 | { |
2907 | 470 | if (*string != '.') |
2908 | 18 | { |
2909 | 18 | check_cpu_arch_compatible (string, cpu_arch[j].enable); |
2910 | | |
2911 | 18 | cpu_arch_name = cpu_arch[j].name; |
2912 | 18 | free (cpu_sub_arch_name); |
2913 | 18 | cpu_sub_arch_name = NULL; |
2914 | 18 | cpu_arch_flags = cpu_arch[j].enable; |
2915 | 18 | if (flag_code == CODE_64BIT) |
2916 | 0 | { |
2917 | 0 | cpu_arch_flags.bitfield.cpu64 = 1; |
2918 | 0 | cpu_arch_flags.bitfield.cpuno64 = 0; |
2919 | 0 | } |
2920 | 18 | else |
2921 | 18 | { |
2922 | 18 | cpu_arch_flags.bitfield.cpu64 = 0; |
2923 | 18 | cpu_arch_flags.bitfield.cpuno64 = 1; |
2924 | 18 | } |
2925 | 18 | cpu_arch_isa = cpu_arch[j].type; |
2926 | 18 | cpu_arch_isa_flags = cpu_arch[j].enable; |
2927 | 18 | if (!cpu_arch_tune_set) |
2928 | 18 | { |
2929 | 18 | cpu_arch_tune = cpu_arch_isa; |
2930 | 18 | cpu_arch_tune_flags = cpu_arch_isa_flags; |
2931 | 18 | } |
2932 | 18 | pre_386_16bit_warned = false; |
2933 | 18 | break; |
2934 | 18 | } |
2935 | | |
2936 | 452 | if (cpu_flags_all_zero (&cpu_arch[j].enable)) |
2937 | 0 | continue; |
2938 | | |
2939 | 452 | flags = cpu_flags_or (cpu_arch_flags, |
2940 | 452 | cpu_arch[j].enable); |
2941 | | |
2942 | 452 | if (!cpu_flags_equal (&flags, &cpu_arch_flags)) |
2943 | 2 | { |
2944 | 2 | extend_cpu_sub_arch_name (string + 1); |
2945 | 2 | cpu_arch_flags = flags; |
2946 | 2 | cpu_arch_isa_flags = flags; |
2947 | 2 | } |
2948 | 450 | else |
2949 | 450 | cpu_arch_isa_flags |
2950 | 450 | = cpu_flags_or (cpu_arch_isa_flags, |
2951 | 450 | cpu_arch[j].enable); |
2952 | 452 | (void) restore_line_pointer (e); |
2953 | 452 | demand_empty_rest_of_line (); |
2954 | 452 | return; |
2955 | 452 | } |
2956 | 456k | } |
2957 | | |
2958 | 2.26k | if (startswith (string, ".no") && j >= ARRAY_SIZE (cpu_arch)) |
2959 | 286 | { |
2960 | | /* Disable an ISA extension. */ |
2961 | 50.3k | for (j = 0; j < ARRAY_SIZE (cpu_arch); j++) |
2962 | 50.0k | if (cpu_arch[j].type == PROCESSOR_NONE |
2963 | 50.0k | && strcmp (string + 3, cpu_arch[j].name) == 0) |
2964 | 0 | { |
2965 | 0 | flags = cpu_flags_and_not (cpu_arch_flags, |
2966 | 0 | cpu_arch[j].disable); |
2967 | 0 | if (!cpu_flags_equal (&flags, &cpu_arch_flags)) |
2968 | 0 | { |
2969 | 0 | extend_cpu_sub_arch_name (string + 1); |
2970 | 0 | cpu_arch_flags = flags; |
2971 | 0 | cpu_arch_isa_flags = flags; |
2972 | 0 | } |
2973 | 0 | (void) restore_line_pointer (e); |
2974 | 0 | demand_empty_rest_of_line (); |
2975 | 0 | return; |
2976 | 0 | } |
2977 | 286 | } |
2978 | | |
2979 | 2.26k | if (j == ARRAY_SIZE (cpu_arch)) |
2980 | 2.24k | as_bad (_("no such architecture: `%s'"), string); |
2981 | | |
2982 | 2.26k | *input_line_pointer = e; |
2983 | 2.26k | } |
2984 | 1.40k | else |
2985 | 1.40k | as_bad (_("missing cpu architecture")); |
2986 | | |
2987 | 3.67k | no_cond_jump_promotion = 0; |
2988 | 3.67k | if (*input_line_pointer == ',' |
2989 | 3.67k | && !is_end_of_line[(unsigned char) input_line_pointer[1]]) |
2990 | 336 | { |
2991 | 336 | char *string; |
2992 | 336 | char e; |
2993 | | |
2994 | 336 | ++input_line_pointer; |
2995 | 336 | e = get_symbol_name (&string); |
2996 | | |
2997 | 336 | if (strcmp (string, "nojumps") == 0) |
2998 | 0 | no_cond_jump_promotion = 1; |
2999 | 336 | else if (strcmp (string, "jumps") == 0) |
3000 | 0 | ; |
3001 | 336 | else |
3002 | 336 | as_bad (_("no such architecture modifier: `%s'"), string); |
3003 | | |
3004 | 336 | (void) restore_line_pointer (e); |
3005 | 336 | } |
3006 | | |
3007 | 3.67k | demand_empty_rest_of_line (); |
3008 | 3.67k | } |
3009 | | |
3010 | | enum bfd_architecture |
3011 | | i386_arch (void) |
3012 | 1.15k | { |
3013 | 1.15k | if (cpu_arch_isa == PROCESSOR_IAMCU) |
3014 | 0 | { |
3015 | 0 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour |
3016 | 0 | || flag_code == CODE_64BIT) |
3017 | 0 | as_fatal (_("Intel MCU is 32bit ELF only")); |
3018 | 0 | return bfd_arch_iamcu; |
3019 | 0 | } |
3020 | 1.15k | else |
3021 | 1.15k | return bfd_arch_i386; |
3022 | 1.15k | } |
3023 | | |
3024 | | unsigned long |
3025 | | i386_mach (void) |
3026 | 1.15k | { |
3027 | 1.15k | if (startswith (default_arch, "x86_64")) |
3028 | 1.15k | { |
3029 | 1.15k | if (default_arch[6] == '\0') |
3030 | 1.15k | return bfd_mach_x86_64; |
3031 | 0 | else |
3032 | 0 | return bfd_mach_x64_32; |
3033 | 1.15k | } |
3034 | 0 | else if (!strcmp (default_arch, "i386") |
3035 | 0 | || !strcmp (default_arch, "iamcu")) |
3036 | 0 | { |
3037 | 0 | if (cpu_arch_isa == PROCESSOR_IAMCU) |
3038 | 0 | { |
3039 | 0 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour) |
3040 | 0 | as_fatal (_("Intel MCU is 32bit ELF only")); |
3041 | 0 | return bfd_mach_i386_iamcu; |
3042 | 0 | } |
3043 | 0 | else |
3044 | 0 | return bfd_mach_i386_i386; |
3045 | 0 | } |
3046 | 0 | else |
3047 | 0 | as_fatal (_("unknown architecture")); |
3048 | 1.15k | } |
3049 | | |
3050 | | #include "opcodes/i386-tbl.h" |
3051 | | |
3052 | | void |
3053 | | md_begin (void) |
3054 | 1.15k | { |
3055 | | /* Support pseudo prefixes like {disp32}. */ |
3056 | 1.15k | lex_type ['{'] = LEX_BEGIN_NAME; |
3057 | | |
3058 | | /* Initialize op_hash hash table. */ |
3059 | 1.15k | op_hash = str_htab_create (); |
3060 | | |
3061 | 1.15k | { |
3062 | 1.15k | const insn_template *const *sets = i386_op_sets; |
3063 | 1.15k | const insn_template *const *end = sets + ARRAY_SIZE (i386_op_sets) - 1; |
3064 | | |
3065 | | /* Type checks to compensate for the conversion through void * which |
3066 | | occurs during hash table insertion / lookup. */ |
3067 | 1.15k | (void) sizeof (sets == ¤t_templates->start); |
3068 | 1.15k | (void) sizeof (end == ¤t_templates->end); |
3069 | 2.69M | for (; sets < end; ++sets) |
3070 | 2.69M | if (str_hash_insert (op_hash, insn_name (*sets), sets, 0)) |
3071 | 0 | as_fatal (_("duplicate %s"), insn_name (*sets)); |
3072 | 1.15k | } |
3073 | | |
3074 | | /* Initialize reg_hash hash table. */ |
3075 | 1.15k | reg_hash = str_htab_create (); |
3076 | 1.15k | { |
3077 | 1.15k | const reg_entry *regtab; |
3078 | 1.15k | unsigned int regtab_size = i386_regtab_size; |
3079 | | |
3080 | 333k | for (regtab = i386_regtab; regtab_size--; regtab++) |
3081 | 332k | { |
3082 | 332k | switch (regtab->reg_type.bitfield.class) |
3083 | 332k | { |
3084 | 92.2k | case Reg: |
3085 | 92.2k | if (regtab->reg_type.bitfield.dword) |
3086 | 18.4k | { |
3087 | 18.4k | if (regtab->reg_type.bitfield.instance == Accum) |
3088 | 1.15k | reg_eax = regtab; |
3089 | 18.4k | } |
3090 | 73.7k | else if (regtab->reg_type.bitfield.tbyte) |
3091 | 9.22k | { |
3092 | | /* There's no point inserting st(<N>) in the hash table, as |
3093 | | parentheses aren't included in register_chars[] anyway. */ |
3094 | 9.22k | if (regtab->reg_type.bitfield.instance != Accum) |
3095 | 8.07k | continue; |
3096 | 1.15k | reg_st0 = regtab; |
3097 | 1.15k | } |
3098 | 84.1k | break; |
3099 | | |
3100 | 84.1k | case SReg: |
3101 | 8.07k | switch (regtab->reg_num) |
3102 | 8.07k | { |
3103 | 1.15k | case 0: reg_es = regtab; break; |
3104 | 1.15k | case 2: reg_ss = regtab; break; |
3105 | 1.15k | case 3: reg_ds = regtab; break; |
3106 | 8.07k | } |
3107 | 8.07k | break; |
3108 | | |
3109 | 9.22k | case RegMask: |
3110 | 9.22k | if (!regtab->reg_num) |
3111 | 1.15k | reg_k0 = regtab; |
3112 | 9.22k | break; |
3113 | 332k | } |
3114 | | |
3115 | 323k | if (str_hash_insert (reg_hash, regtab->reg_name, regtab, 0) != NULL) |
3116 | 0 | as_fatal (_("duplicate %s"), regtab->reg_name); |
3117 | 323k | } |
3118 | 1.15k | } |
3119 | | |
3120 | | /* Fill in lexical tables: mnemonic_chars, operand_chars. */ |
3121 | 1.15k | { |
3122 | 1.15k | int c; |
3123 | 1.15k | const char *p; |
3124 | | |
3125 | 296k | for (c = 0; c < 256; c++) |
3126 | 295k | { |
3127 | 295k | if (ISDIGIT (c) || ISLOWER (c)) |
3128 | 41.5k | { |
3129 | 41.5k | mnemonic_chars[c] = c; |
3130 | 41.5k | register_chars[c] = c; |
3131 | 41.5k | operand_chars[c] = c; |
3132 | 41.5k | } |
3133 | 253k | else if (ISUPPER (c)) |
3134 | 29.9k | { |
3135 | 29.9k | mnemonic_chars[c] = TOLOWER (c); |
3136 | 29.9k | register_chars[c] = mnemonic_chars[c]; |
3137 | 29.9k | operand_chars[c] = c; |
3138 | 29.9k | } |
3139 | | #ifdef SVR4_COMMENT_CHARS |
3140 | | else if (c == '\\' && strchr (i386_comment_chars, '/')) |
3141 | | operand_chars[c] = c; |
3142 | | #endif |
3143 | | |
3144 | 295k | if (c >= 128) |
3145 | 147k | operand_chars[c] = c; |
3146 | 295k | } |
3147 | | |
3148 | 1.15k | mnemonic_chars['_'] = '_'; |
3149 | 1.15k | mnemonic_chars['-'] = '-'; |
3150 | 1.15k | mnemonic_chars['.'] = '.'; |
3151 | | |
3152 | 9.22k | for (p = extra_symbol_chars; *p != '\0'; p++) |
3153 | 8.07k | operand_chars[(unsigned char) *p] = *p; |
3154 | 21.9k | for (p = operand_special_chars; *p != '\0'; p++) |
3155 | 20.7k | operand_chars[(unsigned char) *p] = *p; |
3156 | 1.15k | } |
3157 | | |
3158 | 1.15k | if (flag_code == CODE_64BIT) |
3159 | 1.15k | { |
3160 | | #if defined (OBJ_COFF) && defined (TE_PE) |
3161 | | x86_dwarf2_return_column = (OUTPUT_FLAVOR == bfd_target_coff_flavour |
3162 | | ? 32 : 16); |
3163 | | #else |
3164 | 1.15k | x86_dwarf2_return_column = 16; |
3165 | 1.15k | #endif |
3166 | 1.15k | x86_cie_data_alignment = -8; |
3167 | 1.15k | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
3168 | 1.15k | x86_sframe_cfa_sp_reg = 7; |
3169 | 1.15k | x86_sframe_cfa_fp_reg = 6; |
3170 | 1.15k | #endif |
3171 | 1.15k | } |
3172 | 0 | else |
3173 | 0 | { |
3174 | 0 | x86_dwarf2_return_column = 8; |
3175 | 0 | x86_cie_data_alignment = -4; |
3176 | 0 | } |
3177 | | |
3178 | | /* NB: FUSED_JCC_PADDING frag must have sufficient room so that it |
3179 | | can be turned into BRANCH_PREFIX frag. */ |
3180 | 1.15k | if (align_branch_prefix_size > MAX_FUSED_JCC_PADDING_SIZE) |
3181 | 0 | abort (); |
3182 | 1.15k | } |
3183 | | |
3184 | | void |
3185 | | i386_print_statistics (FILE *file) |
3186 | 0 | { |
3187 | 0 | htab_print_statistics (file, "i386 opcode", op_hash); |
3188 | 0 | htab_print_statistics (file, "i386 register", reg_hash); |
3189 | 0 | } |
3190 | | |
3191 | | void |
3192 | | i386_md_end (void) |
3193 | 1.15k | { |
3194 | 1.15k | htab_delete (op_hash); |
3195 | 1.15k | htab_delete (reg_hash); |
3196 | 1.15k | } |
3197 | | |
3198 | | #ifdef DEBUG386 |
3199 | | |
3200 | | /* Debugging routines for md_assemble. */ |
3201 | | static void pte (insn_template *); |
3202 | | static void pt (i386_operand_type); |
3203 | | static void pe (expressionS *); |
3204 | | static void ps (symbolS *); |
3205 | | |
3206 | | static void |
3207 | | pi (const char *line, i386_insn *x) |
3208 | | { |
3209 | | unsigned int j; |
3210 | | |
3211 | | fprintf (stdout, "%s: template ", line); |
3212 | | pte (&x->tm); |
3213 | | fprintf (stdout, " address: base %s index %s scale %x\n", |
3214 | | x->base_reg ? x->base_reg->reg_name : "none", |
3215 | | x->index_reg ? x->index_reg->reg_name : "none", |
3216 | | x->log2_scale_factor); |
3217 | | fprintf (stdout, " modrm: mode %x reg %x reg/mem %x\n", |
3218 | | x->rm.mode, x->rm.reg, x->rm.regmem); |
3219 | | fprintf (stdout, " sib: base %x index %x scale %x\n", |
3220 | | x->sib.base, x->sib.index, x->sib.scale); |
3221 | | fprintf (stdout, " rex: 64bit %x extX %x extY %x extZ %x\n", |
3222 | | (x->rex & REX_W) != 0, |
3223 | | (x->rex & REX_R) != 0, |
3224 | | (x->rex & REX_X) != 0, |
3225 | | (x->rex & REX_B) != 0); |
3226 | | for (j = 0; j < x->operands; j++) |
3227 | | { |
3228 | | fprintf (stdout, " #%d: ", j + 1); |
3229 | | pt (x->types[j]); |
3230 | | fprintf (stdout, "\n"); |
3231 | | if (x->types[j].bitfield.class == Reg |
3232 | | || x->types[j].bitfield.class == RegMMX |
3233 | | || x->types[j].bitfield.class == RegSIMD |
3234 | | || x->types[j].bitfield.class == RegMask |
3235 | | || x->types[j].bitfield.class == SReg |
3236 | | || x->types[j].bitfield.class == RegCR |
3237 | | || x->types[j].bitfield.class == RegDR |
3238 | | || x->types[j].bitfield.class == RegTR |
3239 | | || x->types[j].bitfield.class == RegBND) |
3240 | | fprintf (stdout, "%s\n", x->op[j].regs->reg_name); |
3241 | | if (operand_type_check (x->types[j], imm)) |
3242 | | pe (x->op[j].imms); |
3243 | | if (operand_type_check (x->types[j], disp)) |
3244 | | pe (x->op[j].disps); |
3245 | | } |
3246 | | } |
3247 | | |
3248 | | static void |
3249 | | pte (insn_template *t) |
3250 | | { |
3251 | | static const unsigned char opc_pfx[] = { 0, 0x66, 0xf3, 0xf2 }; |
3252 | | static const char *const opc_spc[] = { |
3253 | | NULL, "0f", "0f38", "0f3a", NULL, "evexmap5", "evexmap6", NULL, |
3254 | | "XOP08", "XOP09", "XOP0A", |
3255 | | }; |
3256 | | unsigned int j; |
3257 | | |
3258 | | fprintf (stdout, " %d operands ", t->operands); |
3259 | | if (opc_pfx[t->opcode_modifier.opcodeprefix]) |
3260 | | fprintf (stdout, "pfx %x ", opc_pfx[t->opcode_modifier.opcodeprefix]); |
3261 | | if (opc_spc[t->opcode_space]) |
3262 | | fprintf (stdout, "space %s ", opc_spc[t->opcode_space]); |
3263 | | fprintf (stdout, "opcode %x ", t->base_opcode); |
3264 | | if (t->extension_opcode != None) |
3265 | | fprintf (stdout, "ext %x ", t->extension_opcode); |
3266 | | if (t->opcode_modifier.d) |
3267 | | fprintf (stdout, "D"); |
3268 | | if (t->opcode_modifier.w) |
3269 | | fprintf (stdout, "W"); |
3270 | | fprintf (stdout, "\n"); |
3271 | | for (j = 0; j < t->operands; j++) |
3272 | | { |
3273 | | fprintf (stdout, " #%d type ", j + 1); |
3274 | | pt (t->operand_types[j]); |
3275 | | fprintf (stdout, "\n"); |
3276 | | } |
3277 | | } |
3278 | | |
3279 | | static void |
3280 | | pe (expressionS *e) |
3281 | | { |
3282 | | fprintf (stdout, " operation %d\n", e->X_op); |
3283 | | fprintf (stdout, " add_number %" PRId64 " (%" PRIx64 ")\n", |
3284 | | (int64_t) e->X_add_number, (uint64_t) (valueT) e->X_add_number); |
3285 | | if (e->X_add_symbol) |
3286 | | { |
3287 | | fprintf (stdout, " add_symbol "); |
3288 | | ps (e->X_add_symbol); |
3289 | | fprintf (stdout, "\n"); |
3290 | | } |
3291 | | if (e->X_op_symbol) |
3292 | | { |
3293 | | fprintf (stdout, " op_symbol "); |
3294 | | ps (e->X_op_symbol); |
3295 | | fprintf (stdout, "\n"); |
3296 | | } |
3297 | | } |
3298 | | |
3299 | | static void |
3300 | | ps (symbolS *s) |
3301 | | { |
3302 | | fprintf (stdout, "%s type %s%s", |
3303 | | S_GET_NAME (s), |
3304 | | S_IS_EXTERNAL (s) ? "EXTERNAL " : "", |
3305 | | segment_name (S_GET_SEGMENT (s))); |
3306 | | } |
3307 | | |
3308 | | static struct type_name |
3309 | | { |
3310 | | i386_operand_type mask; |
3311 | | const char *name; |
3312 | | } |
3313 | | const type_names[] = |
3314 | | { |
3315 | | { { .bitfield = { .class = Reg, .byte = 1 } }, "r8" }, |
3316 | | { { .bitfield = { .class = Reg, .word = 1 } }, "r16" }, |
3317 | | { { .bitfield = { .class = Reg, .dword = 1 } }, "r32" }, |
3318 | | { { .bitfield = { .class = Reg, .qword = 1 } }, "r64" }, |
3319 | | { { .bitfield = { .instance = Accum, .byte = 1 } }, "acc8" }, |
3320 | | { { .bitfield = { .instance = Accum, .word = 1 } }, "acc16" }, |
3321 | | { { .bitfield = { .instance = Accum, .dword = 1 } }, "acc32" }, |
3322 | | { { .bitfield = { .instance = Accum, .qword = 1 } }, "acc64" }, |
3323 | | { { .bitfield = { .imm8 = 1 } }, "i8" }, |
3324 | | { { .bitfield = { .imm8s = 1 } }, "i8s" }, |
3325 | | { { .bitfield = { .imm16 = 1 } }, "i16" }, |
3326 | | { { .bitfield = { .imm32 = 1 } }, "i32" }, |
3327 | | { { .bitfield = { .imm32s = 1 } }, "i32s" }, |
3328 | | { { .bitfield = { .imm64 = 1 } }, "i64" }, |
3329 | | { { .bitfield = { .imm1 = 1 } }, "i1" }, |
3330 | | { { .bitfield = { .baseindex = 1 } }, "BaseIndex" }, |
3331 | | { { .bitfield = { .disp8 = 1 } }, "d8" }, |
3332 | | { { .bitfield = { .disp16 = 1 } }, "d16" }, |
3333 | | { { .bitfield = { .disp32 = 1 } }, "d32" }, |
3334 | | { { .bitfield = { .disp64 = 1 } }, "d64" }, |
3335 | | { { .bitfield = { .instance = RegD, .word = 1 } }, "InOutPortReg" }, |
3336 | | { { .bitfield = { .instance = RegC, .byte = 1 } }, "ShiftCount" }, |
3337 | | { { .bitfield = { .class = RegCR } }, "control reg" }, |
3338 | | { { .bitfield = { .class = RegTR } }, "test reg" }, |
3339 | | { { .bitfield = { .class = RegDR } }, "debug reg" }, |
3340 | | { { .bitfield = { .class = Reg, .tbyte = 1 } }, "FReg" }, |
3341 | | { { .bitfield = { .instance = Accum, .tbyte = 1 } }, "FAcc" }, |
3342 | | { { .bitfield = { .class = SReg } }, "SReg" }, |
3343 | | { { .bitfield = { .class = RegMMX } }, "rMMX" }, |
3344 | | { { .bitfield = { .class = RegSIMD, .xmmword = 1 } }, "rXMM" }, |
3345 | | { { .bitfield = { .class = RegSIMD, .ymmword = 1 } }, "rYMM" }, |
3346 | | { { .bitfield = { .class = RegSIMD, .zmmword = 1 } }, "rZMM" }, |
3347 | | { { .bitfield = { .class = RegSIMD, .tmmword = 1 } }, "rTMM" }, |
3348 | | { { .bitfield = { .class = RegMask } }, "Mask reg" }, |
3349 | | }; |
3350 | | |
3351 | | static void |
3352 | | pt (i386_operand_type t) |
3353 | | { |
3354 | | unsigned int j; |
3355 | | i386_operand_type a; |
3356 | | |
3357 | | for (j = 0; j < ARRAY_SIZE (type_names); j++) |
3358 | | { |
3359 | | a = operand_type_and (t, type_names[j].mask); |
3360 | | if (operand_type_equal (&a, &type_names[j].mask)) |
3361 | | fprintf (stdout, "%s, ", type_names[j].name); |
3362 | | } |
3363 | | fflush (stdout); |
3364 | | } |
3365 | | |
3366 | | #endif /* DEBUG386 */ |
3367 | | |
3368 | | static bfd_reloc_code_real_type |
3369 | | reloc (unsigned int size, |
3370 | | int pcrel, |
3371 | | int sign, |
3372 | | bfd_reloc_code_real_type other) |
3373 | 94.8k | { |
3374 | 94.8k | if (other != NO_RELOC) |
3375 | 1.02k | { |
3376 | 1.02k | reloc_howto_type *rel; |
3377 | | |
3378 | 1.02k | if (size == 8) |
3379 | 0 | switch (other) |
3380 | 0 | { |
3381 | 0 | case BFD_RELOC_X86_64_GOT32: |
3382 | 0 | return BFD_RELOC_X86_64_GOT64; |
3383 | 0 | break; |
3384 | 0 | case BFD_RELOC_X86_64_GOTPLT64: |
3385 | 0 | return BFD_RELOC_X86_64_GOTPLT64; |
3386 | 0 | break; |
3387 | 0 | case BFD_RELOC_X86_64_PLTOFF64: |
3388 | 0 | return BFD_RELOC_X86_64_PLTOFF64; |
3389 | 0 | break; |
3390 | 0 | case BFD_RELOC_X86_64_GOTPC32: |
3391 | 0 | other = BFD_RELOC_X86_64_GOTPC64; |
3392 | 0 | break; |
3393 | 0 | case BFD_RELOC_X86_64_GOTPCREL: |
3394 | 0 | other = BFD_RELOC_X86_64_GOTPCREL64; |
3395 | 0 | break; |
3396 | 0 | case BFD_RELOC_X86_64_TPOFF32: |
3397 | 0 | other = BFD_RELOC_X86_64_TPOFF64; |
3398 | 0 | break; |
3399 | 0 | case BFD_RELOC_X86_64_DTPOFF32: |
3400 | 0 | other = BFD_RELOC_X86_64_DTPOFF64; |
3401 | 0 | break; |
3402 | 0 | default: |
3403 | 0 | break; |
3404 | 0 | } |
3405 | | |
3406 | 1.02k | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
3407 | 1.02k | if (other == BFD_RELOC_SIZE32) |
3408 | 207 | { |
3409 | 207 | if (size == 8) |
3410 | 0 | other = BFD_RELOC_SIZE64; |
3411 | 207 | if (pcrel) |
3412 | 0 | { |
3413 | 0 | as_bad (_("there are no pc-relative size relocations")); |
3414 | 0 | return NO_RELOC; |
3415 | 0 | } |
3416 | 207 | } |
3417 | 1.02k | #endif |
3418 | | |
3419 | | /* Sign-checking 4-byte relocations in 16-/32-bit code is pointless. */ |
3420 | 1.02k | if (size == 4 && (flag_code != CODE_64BIT || disallow_64bit_reloc)) |
3421 | 308 | sign = -1; |
3422 | | |
3423 | 1.02k | rel = bfd_reloc_type_lookup (stdoutput, other); |
3424 | 1.02k | if (!rel) |
3425 | 0 | as_bad (_("unknown relocation (%u)"), other); |
3426 | 1.02k | else if (size != bfd_get_reloc_size (rel)) |
3427 | 309 | as_bad (_("%u-byte relocation cannot be applied to %u-byte field"), |
3428 | 309 | bfd_get_reloc_size (rel), |
3429 | 309 | size); |
3430 | 715 | else if (pcrel && !rel->pc_relative) |
3431 | 0 | as_bad (_("non-pc-relative relocation for pc-relative field")); |
3432 | 715 | else if ((rel->complain_on_overflow == complain_overflow_signed |
3433 | 715 | && !sign) |
3434 | 715 | || (rel->complain_on_overflow == complain_overflow_unsigned |
3435 | 715 | && sign > 0)) |
3436 | 0 | as_bad (_("relocated field and relocation type differ in signedness")); |
3437 | 715 | else |
3438 | 715 | return other; |
3439 | 309 | return NO_RELOC; |
3440 | 1.02k | } |
3441 | | |
3442 | 93.8k | if (pcrel) |
3443 | 304 | { |
3444 | 304 | if (!sign) |
3445 | 0 | as_bad (_("there are no unsigned pc-relative relocations")); |
3446 | 304 | switch (size) |
3447 | 304 | { |
3448 | 87 | case 1: return BFD_RELOC_8_PCREL; |
3449 | 36 | case 2: return BFD_RELOC_16_PCREL; |
3450 | 181 | case 4: return BFD_RELOC_32_PCREL; |
3451 | 0 | case 8: return BFD_RELOC_64_PCREL; |
3452 | 304 | } |
3453 | 0 | as_bad (_("cannot do %u byte pc-relative relocation"), size); |
3454 | 0 | } |
3455 | 93.5k | else |
3456 | 93.5k | { |
3457 | 93.5k | if (sign > 0) |
3458 | 4.93k | switch (size) |
3459 | 4.93k | { |
3460 | 4.93k | case 4: return BFD_RELOC_X86_64_32S; |
3461 | 4.93k | } |
3462 | 88.5k | else |
3463 | 88.5k | switch (size) |
3464 | 88.5k | { |
3465 | 12.2k | case 1: return BFD_RELOC_8; |
3466 | 9.93k | case 2: return BFD_RELOC_16; |
3467 | 38.8k | case 4: return BFD_RELOC_32; |
3468 | 20.9k | case 8: return BFD_RELOC_64; |
3469 | 88.5k | } |
3470 | 6.57k | as_bad (_("cannot do %s %u byte relocation"), |
3471 | 6.57k | sign > 0 ? "signed" : "unsigned", size); |
3472 | 6.57k | } |
3473 | | |
3474 | 6.57k | return NO_RELOC; |
3475 | 93.8k | } |
3476 | | |
3477 | | /* Here we decide which fixups can be adjusted to make them relative to |
3478 | | the beginning of the section instead of the symbol. Basically we need |
3479 | | to make sure that the dynamic relocations are done correctly, so in |
3480 | | some cases we force the original symbol to be used. */ |
3481 | | |
3482 | | int |
3483 | | tc_i386_fix_adjustable (fixS *fixP ATTRIBUTE_UNUSED) |
3484 | 0 | { |
3485 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
3486 | 0 | if (!IS_ELF) |
3487 | 0 | return 1; |
3488 | | |
3489 | | /* Don't adjust pc-relative references to merge sections in 64-bit |
3490 | | mode. */ |
3491 | 0 | if (use_rela_relocations |
3492 | 0 | && (S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0 |
3493 | 0 | && fixP->fx_pcrel) |
3494 | 0 | return 0; |
3495 | | |
3496 | | /* The x86_64 GOTPCREL are represented as 32bit PCrel relocations |
3497 | | and changed later by validate_fix. */ |
3498 | 0 | if (GOT_symbol && fixP->fx_subsy == GOT_symbol |
3499 | 0 | && fixP->fx_r_type == BFD_RELOC_32_PCREL) |
3500 | 0 | return 0; |
3501 | | |
3502 | | /* Adjust_reloc_syms doesn't know about the GOT. Need to keep symbol |
3503 | | for size relocations. */ |
3504 | 0 | if (fixP->fx_r_type == BFD_RELOC_SIZE32 |
3505 | 0 | || fixP->fx_r_type == BFD_RELOC_SIZE64 |
3506 | 0 | || fixP->fx_r_type == BFD_RELOC_386_GOTOFF |
3507 | 0 | || fixP->fx_r_type == BFD_RELOC_386_GOT32 |
3508 | 0 | || fixP->fx_r_type == BFD_RELOC_386_GOT32X |
3509 | 0 | || fixP->fx_r_type == BFD_RELOC_386_TLS_GD |
3510 | 0 | || fixP->fx_r_type == BFD_RELOC_386_TLS_LDM |
3511 | 0 | || fixP->fx_r_type == BFD_RELOC_386_TLS_LDO_32 |
3512 | 0 | || fixP->fx_r_type == BFD_RELOC_386_TLS_IE_32 |
3513 | 0 | || fixP->fx_r_type == BFD_RELOC_386_TLS_IE |
3514 | 0 | || fixP->fx_r_type == BFD_RELOC_386_TLS_GOTIE |
3515 | 0 | || fixP->fx_r_type == BFD_RELOC_386_TLS_LE_32 |
3516 | 0 | || fixP->fx_r_type == BFD_RELOC_386_TLS_LE |
3517 | 0 | || fixP->fx_r_type == BFD_RELOC_386_TLS_GOTDESC |
3518 | 0 | || fixP->fx_r_type == BFD_RELOC_386_TLS_DESC_CALL |
3519 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_GOT32 |
3520 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_GOTPCREL |
3521 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_GOTPCRELX |
3522 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_REX_GOTPCRELX |
3523 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_TLSGD |
3524 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_TLSLD |
3525 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_DTPOFF32 |
3526 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_DTPOFF64 |
3527 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_GOTTPOFF |
3528 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_TPOFF32 |
3529 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_TPOFF64 |
3530 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_GOTOFF64 |
3531 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_GOTPC32_TLSDESC |
3532 | 0 | || fixP->fx_r_type == BFD_RELOC_X86_64_TLSDESC_CALL |
3533 | 0 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
3534 | 0 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) |
3535 | 0 | return 0; |
3536 | 0 | #endif |
3537 | 0 | return 1; |
3538 | 0 | } |
3539 | | |
3540 | | static INLINE bool |
3541 | | want_disp32 (const insn_template *t) |
3542 | 222k | { |
3543 | 222k | return flag_code != CODE_64BIT |
3544 | 222k | || i.prefix[ADDR_PREFIX] |
3545 | 222k | || (t->mnem_off == MN_lea |
3546 | 108k | && (!i.types[1].bitfield.qword |
3547 | 304 | || t->opcode_modifier.size == SIZE32)); |
3548 | 222k | } |
3549 | | |
3550 | | static int |
3551 | | intel_float_operand (const char *mnemonic) |
3552 | 0 | { |
3553 | | /* Note that the value returned is meaningful only for opcodes with (memory) |
3554 | | operands, hence the code here is free to improperly handle opcodes that |
3555 | | have no operands (for better performance and smaller code). */ |
3556 | |
|
3557 | 0 | if (mnemonic[0] != 'f') |
3558 | 0 | return 0; /* non-math */ |
3559 | | |
3560 | 0 | switch (mnemonic[1]) |
3561 | 0 | { |
3562 | | /* fclex, fdecstp, fdisi, femms, feni, fincstp, finit, fsetpm, and |
3563 | | the fs segment override prefix not currently handled because no |
3564 | | call path can make opcodes without operands get here */ |
3565 | 0 | case 'i': |
3566 | 0 | return 2 /* integer op */; |
3567 | 0 | case 'l': |
3568 | 0 | if (mnemonic[2] == 'd' && (mnemonic[3] == 'c' || mnemonic[3] == 'e')) |
3569 | 0 | return 3; /* fldcw/fldenv */ |
3570 | 0 | break; |
3571 | 0 | case 'n': |
3572 | 0 | if (mnemonic[2] != 'o' /* fnop */) |
3573 | 0 | return 3; /* non-waiting control op */ |
3574 | 0 | break; |
3575 | 0 | case 'r': |
3576 | 0 | if (mnemonic[2] == 's') |
3577 | 0 | return 3; /* frstor/frstpm */ |
3578 | 0 | break; |
3579 | 0 | case 's': |
3580 | 0 | if (mnemonic[2] == 'a') |
3581 | 0 | return 3; /* fsave */ |
3582 | 0 | if (mnemonic[2] == 't') |
3583 | 0 | { |
3584 | 0 | switch (mnemonic[3]) |
3585 | 0 | { |
3586 | 0 | case 'c': /* fstcw */ |
3587 | 0 | case 'd': /* fstdw */ |
3588 | 0 | case 'e': /* fstenv */ |
3589 | 0 | case 's': /* fsts[gw] */ |
3590 | 0 | return 3; |
3591 | 0 | } |
3592 | 0 | } |
3593 | 0 | break; |
3594 | 0 | case 'x': |
3595 | 0 | if (mnemonic[2] == 'r' || mnemonic[2] == 's') |
3596 | 0 | return 0; /* fxsave/fxrstor are not really math ops */ |
3597 | 0 | break; |
3598 | 0 | } |
3599 | | |
3600 | 0 | return 1; |
3601 | 0 | } |
3602 | | |
3603 | | static INLINE void |
3604 | | install_template (const insn_template *t) |
3605 | 772k | { |
3606 | 772k | unsigned int l; |
3607 | | |
3608 | 772k | i.tm = *t; |
3609 | | |
3610 | | /* Note that for pseudo prefixes this produces a length of 1. But for them |
3611 | | the length isn't interesting at all. */ |
3612 | 772k | for (l = 1; l < 4; ++l) |
3613 | 772k | if (!(t->base_opcode >> (8 * l))) |
3614 | 772k | break; |
3615 | | |
3616 | 772k | i.opcode_length = l; |
3617 | 772k | } |
3618 | | |
3619 | | /* Build the VEX prefix. */ |
3620 | | |
3621 | | static void |
3622 | | build_vex_prefix (const insn_template *t) |
3623 | 6 | { |
3624 | 6 | unsigned int register_specifier; |
3625 | 6 | unsigned int vector_length; |
3626 | 6 | unsigned int w; |
3627 | | |
3628 | | /* Check register specifier. */ |
3629 | 6 | if (i.vex.register_specifier) |
3630 | 0 | { |
3631 | 0 | register_specifier = |
3632 | 0 | ~register_number (i.vex.register_specifier) & 0xf; |
3633 | 0 | gas_assert ((i.vex.register_specifier->reg_flags & RegVRex) == 0); |
3634 | 0 | } |
3635 | 6 | else |
3636 | 6 | register_specifier = 0xf; |
3637 | | |
3638 | | /* Use 2-byte VEX prefix by swapping destination and source operand |
3639 | | if there are more than 1 register operand. */ |
3640 | 6 | if (i.reg_operands > 1 |
3641 | 6 | && i.vec_encoding != vex_encoding_vex3 |
3642 | 6 | && i.dir_encoding == dir_encoding_default |
3643 | 6 | && i.operands == i.reg_operands |
3644 | 6 | && operand_type_equal (&i.types[0], &i.types[i.operands - 1]) |
3645 | 6 | && i.tm.opcode_space == SPACE_0F |
3646 | 6 | && (i.tm.opcode_modifier.load || i.tm.opcode_modifier.d) |
3647 | 6 | && i.rex == REX_B) |
3648 | 0 | { |
3649 | 0 | unsigned int xchg; |
3650 | |
|
3651 | 0 | swap_2_operands (0, i.operands - 1); |
3652 | |
|
3653 | 0 | gas_assert (i.rm.mode == 3); |
3654 | | |
3655 | 0 | i.rex = REX_R; |
3656 | 0 | xchg = i.rm.regmem; |
3657 | 0 | i.rm.regmem = i.rm.reg; |
3658 | 0 | i.rm.reg = xchg; |
3659 | |
|
3660 | 0 | if (i.tm.opcode_modifier.d) |
3661 | 0 | i.tm.base_opcode ^= (i.tm.base_opcode & 0xee) != 0x6e |
3662 | 0 | ? Opcode_ExtD : Opcode_SIMD_IntD; |
3663 | 0 | else /* Use the next insn. */ |
3664 | 0 | install_template (&t[1]); |
3665 | 0 | } |
3666 | | |
3667 | | /* Use 2-byte VEX prefix by swapping commutative source operands if there |
3668 | | are no memory operands and at least 3 register ones. */ |
3669 | 6 | if (i.reg_operands >= 3 |
3670 | 6 | && i.vec_encoding != vex_encoding_vex3 |
3671 | 6 | && i.reg_operands == i.operands - i.imm_operands |
3672 | 6 | && i.tm.opcode_modifier.vex |
3673 | 6 | && i.tm.opcode_modifier.commutative |
3674 | 6 | && (i.tm.opcode_modifier.sse2avx |
3675 | 0 | || (optimize > 1 && !i.no_optimize)) |
3676 | 6 | && i.rex == REX_B |
3677 | 6 | && i.vex.register_specifier |
3678 | 6 | && !(i.vex.register_specifier->reg_flags & RegRex)) |
3679 | 0 | { |
3680 | 0 | unsigned int xchg = i.operands - i.reg_operands; |
3681 | |
|
3682 | 0 | gas_assert (i.tm.opcode_space == SPACE_0F); |
3683 | 0 | gas_assert (!i.tm.opcode_modifier.sae); |
3684 | 0 | gas_assert (operand_type_equal (&i.types[i.operands - 2], |
3685 | 0 | &i.types[i.operands - 3])); |
3686 | 0 | gas_assert (i.rm.mode == 3); |
3687 | | |
3688 | 0 | swap_2_operands (xchg, xchg + 1); |
3689 | |
|
3690 | 0 | i.rex = 0; |
3691 | 0 | xchg = i.rm.regmem | 8; |
3692 | 0 | i.rm.regmem = ~register_specifier & 0xf; |
3693 | 0 | gas_assert (!(i.rm.regmem & 8)); |
3694 | 0 | i.vex.register_specifier += xchg - i.rm.regmem; |
3695 | 0 | register_specifier = ~xchg & 0xf; |
3696 | 0 | } |
3697 | | |
3698 | 6 | if (i.tm.opcode_modifier.vex == VEXScalar) |
3699 | 0 | vector_length = avxscalar; |
3700 | 6 | else if (i.tm.opcode_modifier.vex == VEX256) |
3701 | 0 | vector_length = 1; |
3702 | 6 | else if (dot_insn () && i.tm.opcode_modifier.vex == VEX128) |
3703 | 0 | vector_length = 0; |
3704 | 6 | else |
3705 | 6 | { |
3706 | 6 | unsigned int op; |
3707 | | |
3708 | | /* Determine vector length from the last multi-length vector |
3709 | | operand. */ |
3710 | 6 | vector_length = 0; |
3711 | 6 | for (op = t->operands; op--;) |
3712 | 0 | if (t->operand_types[op].bitfield.xmmword |
3713 | 0 | && t->operand_types[op].bitfield.ymmword |
3714 | 0 | && i.types[op].bitfield.ymmword) |
3715 | 0 | { |
3716 | 0 | vector_length = 1; |
3717 | 0 | break; |
3718 | 0 | } |
3719 | 6 | } |
3720 | | |
3721 | | /* Check the REX.W bit and VEXW. */ |
3722 | 6 | if (i.tm.opcode_modifier.vexw == VEXWIG) |
3723 | 0 | w = (vexwig == vexw1 || (i.rex & REX_W)) ? 1 : 0; |
3724 | 6 | else if (i.tm.opcode_modifier.vexw) |
3725 | 6 | w = i.tm.opcode_modifier.vexw == VEXW1 ? 1 : 0; |
3726 | 0 | else |
3727 | 0 | w = (flag_code == CODE_64BIT ? i.rex & REX_W : vexwig == vexw1) ? 1 : 0; |
3728 | | |
3729 | | /* Use 2-byte VEX prefix if possible. */ |
3730 | 6 | if (w == 0 |
3731 | 6 | && i.vec_encoding != vex_encoding_vex3 |
3732 | 6 | && i.tm.opcode_space == SPACE_0F |
3733 | 6 | && (i.rex & (REX_W | REX_X | REX_B)) == 0) |
3734 | 0 | { |
3735 | | /* 2-byte VEX prefix. */ |
3736 | 0 | unsigned int r; |
3737 | |
|
3738 | 0 | i.vex.length = 2; |
3739 | 0 | i.vex.bytes[0] = 0xc5; |
3740 | | |
3741 | | /* Check the REX.R bit. */ |
3742 | 0 | r = (i.rex & REX_R) ? 0 : 1; |
3743 | 0 | i.vex.bytes[1] = (r << 7 |
3744 | 0 | | register_specifier << 3 |
3745 | 0 | | vector_length << 2 |
3746 | 0 | | i.tm.opcode_modifier.opcodeprefix); |
3747 | 0 | } |
3748 | 6 | else |
3749 | 6 | { |
3750 | | /* 3-byte VEX prefix. */ |
3751 | 6 | i.vex.length = 3; |
3752 | | |
3753 | 6 | switch (i.tm.opcode_space) |
3754 | 6 | { |
3755 | 0 | case SPACE_0F: |
3756 | 6 | case SPACE_0F38: |
3757 | 6 | case SPACE_0F3A: |
3758 | 6 | i.vex.bytes[0] = 0xc4; |
3759 | 6 | break; |
3760 | 0 | case SPACE_XOP08: |
3761 | 0 | case SPACE_XOP09: |
3762 | 0 | case SPACE_XOP0A: |
3763 | 0 | i.vex.bytes[0] = 0x8f; |
3764 | 0 | break; |
3765 | 0 | default: |
3766 | 0 | abort (); |
3767 | 6 | } |
3768 | | |
3769 | | /* The high 3 bits of the second VEX byte are 1's compliment |
3770 | | of RXB bits from REX. */ |
3771 | 6 | i.vex.bytes[1] = ((~i.rex & 7) << 5) |
3772 | 6 | | (!dot_insn () ? i.tm.opcode_space |
3773 | 6 | : i.insn_opcode_space); |
3774 | | |
3775 | 6 | i.vex.bytes[2] = (w << 7 |
3776 | 6 | | register_specifier << 3 |
3777 | 6 | | vector_length << 2 |
3778 | 6 | | i.tm.opcode_modifier.opcodeprefix); |
3779 | 6 | } |
3780 | 6 | } |
3781 | | |
3782 | | static INLINE bool |
3783 | | is_evex_encoding (const insn_template *t) |
3784 | 2.39M | { |
3785 | 2.39M | return t->opcode_modifier.evex || t->opcode_modifier.disp8memshift |
3786 | 2.39M | || t->opcode_modifier.broadcast || t->opcode_modifier.masking |
3787 | 2.39M | || t->opcode_modifier.sae; |
3788 | 2.39M | } |
3789 | | |
3790 | | static INLINE bool |
3791 | | is_any_vex_encoding (const insn_template *t) |
3792 | 2.39M | { |
3793 | 2.39M | return t->opcode_modifier.vex || is_evex_encoding (t); |
3794 | 2.39M | } |
3795 | | |
3796 | | static unsigned int |
3797 | | get_broadcast_bytes (const insn_template *t, bool diag) |
3798 | 0 | { |
3799 | 0 | unsigned int op, bytes; |
3800 | 0 | const i386_operand_type *types; |
3801 | |
|
3802 | 0 | if (i.broadcast.type) |
3803 | 0 | return (1 << (t->opcode_modifier.broadcast - 1)) * i.broadcast.type; |
3804 | | |
3805 | 0 | gas_assert (intel_syntax); |
3806 | | |
3807 | 0 | for (op = 0; op < t->operands; ++op) |
3808 | 0 | if (t->operand_types[op].bitfield.baseindex) |
3809 | 0 | break; |
3810 | |
|
3811 | 0 | gas_assert (op < t->operands); |
3812 | | |
3813 | 0 | if (t->opcode_modifier.evex |
3814 | 0 | && t->opcode_modifier.evex != EVEXDYN) |
3815 | 0 | switch (i.broadcast.bytes) |
3816 | 0 | { |
3817 | 0 | case 1: |
3818 | 0 | if (t->operand_types[op].bitfield.word) |
3819 | 0 | return 2; |
3820 | | /* Fall through. */ |
3821 | 0 | case 2: |
3822 | 0 | if (t->operand_types[op].bitfield.dword) |
3823 | 0 | return 4; |
3824 | | /* Fall through. */ |
3825 | 0 | case 4: |
3826 | 0 | if (t->operand_types[op].bitfield.qword) |
3827 | 0 | return 8; |
3828 | | /* Fall through. */ |
3829 | 0 | case 8: |
3830 | 0 | if (t->operand_types[op].bitfield.xmmword) |
3831 | 0 | return 16; |
3832 | 0 | if (t->operand_types[op].bitfield.ymmword) |
3833 | 0 | return 32; |
3834 | 0 | if (t->operand_types[op].bitfield.zmmword) |
3835 | 0 | return 64; |
3836 | | /* Fall through. */ |
3837 | 0 | default: |
3838 | 0 | abort (); |
3839 | 0 | } |
3840 | | |
3841 | 0 | gas_assert (op + 1 < t->operands); |
3842 | | |
3843 | 0 | if (t->operand_types[op + 1].bitfield.xmmword |
3844 | 0 | + t->operand_types[op + 1].bitfield.ymmword |
3845 | 0 | + t->operand_types[op + 1].bitfield.zmmword > 1) |
3846 | 0 | { |
3847 | 0 | types = &i.types[op + 1]; |
3848 | 0 | diag = false; |
3849 | 0 | } |
3850 | 0 | else /* Ambiguous - guess with a preference to non-AVX512VL forms. */ |
3851 | 0 | types = &t->operand_types[op]; |
3852 | |
|
3853 | 0 | if (types->bitfield.zmmword) |
3854 | 0 | bytes = 64; |
3855 | 0 | else if (types->bitfield.ymmword) |
3856 | 0 | bytes = 32; |
3857 | 0 | else |
3858 | 0 | bytes = 16; |
3859 | |
|
3860 | 0 | if (diag) |
3861 | 0 | as_warn (_("ambiguous broadcast for `%s', using %u-bit form"), |
3862 | 0 | insn_name (t), bytes * 8); |
3863 | |
|
3864 | 0 | return bytes; |
3865 | 0 | } |
3866 | | |
3867 | | /* Build the EVEX prefix. */ |
3868 | | |
3869 | | static void |
3870 | | build_evex_prefix (void) |
3871 | 0 | { |
3872 | 0 | unsigned int register_specifier, w; |
3873 | 0 | rex_byte vrex_used = 0; |
3874 | | |
3875 | | /* Check register specifier. */ |
3876 | 0 | if (i.vex.register_specifier) |
3877 | 0 | { |
3878 | 0 | gas_assert ((i.vrex & REX_X) == 0); |
3879 | | |
3880 | 0 | register_specifier = i.vex.register_specifier->reg_num; |
3881 | 0 | if ((i.vex.register_specifier->reg_flags & RegRex)) |
3882 | 0 | register_specifier += 8; |
3883 | | /* The upper 16 registers are encoded in the fourth byte of the |
3884 | | EVEX prefix. */ |
3885 | 0 | if (!(i.vex.register_specifier->reg_flags & RegVRex)) |
3886 | 0 | i.vex.bytes[3] = 0x8; |
3887 | 0 | register_specifier = ~register_specifier & 0xf; |
3888 | 0 | } |
3889 | 0 | else |
3890 | 0 | { |
3891 | 0 | register_specifier = 0xf; |
3892 | | |
3893 | | /* Encode upper 16 vector index register in the fourth byte of |
3894 | | the EVEX prefix. */ |
3895 | 0 | if (!(i.vrex & REX_X)) |
3896 | 0 | i.vex.bytes[3] = 0x8; |
3897 | 0 | else |
3898 | 0 | vrex_used |= REX_X; |
3899 | 0 | } |
3900 | | |
3901 | | /* 4 byte EVEX prefix. */ |
3902 | 0 | i.vex.length = 4; |
3903 | 0 | i.vex.bytes[0] = 0x62; |
3904 | | |
3905 | | /* The high 3 bits of the second EVEX byte are 1's compliment of RXB |
3906 | | bits from REX. */ |
3907 | 0 | gas_assert (i.tm.opcode_space >= SPACE_0F); |
3908 | 0 | gas_assert (i.tm.opcode_space <= SPACE_EVEXMAP6); |
3909 | 0 | i.vex.bytes[1] = ((~i.rex & 7) << 5) |
3910 | 0 | | (!dot_insn () ? i.tm.opcode_space |
3911 | 0 | : i.insn_opcode_space); |
3912 | | |
3913 | | /* The fifth bit of the second EVEX byte is 1's compliment of the |
3914 | | REX_R bit in VREX. */ |
3915 | 0 | if (!(i.vrex & REX_R)) |
3916 | 0 | i.vex.bytes[1] |= 0x10; |
3917 | 0 | else |
3918 | 0 | vrex_used |= REX_R; |
3919 | |
|
3920 | 0 | if ((i.reg_operands + i.imm_operands) == i.operands) |
3921 | 0 | { |
3922 | | /* When all operands are registers, the REX_X bit in REX is not |
3923 | | used. We reuse it to encode the upper 16 registers, which is |
3924 | | indicated by the REX_B bit in VREX. The REX_X bit is encoded |
3925 | | as 1's compliment. */ |
3926 | 0 | if ((i.vrex & REX_B)) |
3927 | 0 | { |
3928 | 0 | vrex_used |= REX_B; |
3929 | 0 | i.vex.bytes[1] &= ~0x40; |
3930 | 0 | } |
3931 | 0 | } |
3932 | | |
3933 | | /* EVEX instructions shouldn't need the REX prefix. */ |
3934 | 0 | i.vrex &= ~vrex_used; |
3935 | 0 | gas_assert (i.vrex == 0); |
3936 | | |
3937 | | /* Check the REX.W bit and VEXW. */ |
3938 | 0 | if (i.tm.opcode_modifier.vexw == VEXWIG) |
3939 | 0 | w = (evexwig == evexw1 || (i.rex & REX_W)) ? 1 : 0; |
3940 | 0 | else if (i.tm.opcode_modifier.vexw) |
3941 | 0 | w = i.tm.opcode_modifier.vexw == VEXW1 ? 1 : 0; |
3942 | 0 | else |
3943 | 0 | w = (flag_code == CODE_64BIT ? i.rex & REX_W : evexwig == evexw1) ? 1 : 0; |
3944 | | |
3945 | | /* The third byte of the EVEX prefix. */ |
3946 | 0 | i.vex.bytes[2] = ((w << 7) |
3947 | 0 | | (register_specifier << 3) |
3948 | 0 | | 4 /* Encode the U bit. */ |
3949 | 0 | | i.tm.opcode_modifier.opcodeprefix); |
3950 | | |
3951 | | /* The fourth byte of the EVEX prefix. */ |
3952 | | /* The zeroing-masking bit. */ |
3953 | 0 | if (i.mask.reg && i.mask.zeroing) |
3954 | 0 | i.vex.bytes[3] |= 0x80; |
3955 | | |
3956 | | /* Don't always set the broadcast bit if there is no RC. */ |
3957 | 0 | if (i.rounding.type == rc_none) |
3958 | 0 | { |
3959 | | /* Encode the vector length. */ |
3960 | 0 | unsigned int vec_length; |
3961 | |
|
3962 | 0 | if (!i.tm.opcode_modifier.evex |
3963 | 0 | || i.tm.opcode_modifier.evex == EVEXDYN) |
3964 | 0 | { |
3965 | 0 | unsigned int op; |
3966 | | |
3967 | | /* Determine vector length from the last multi-length vector |
3968 | | operand. */ |
3969 | 0 | for (op = i.operands; op--;) |
3970 | 0 | if (i.tm.operand_types[op].bitfield.xmmword |
3971 | 0 | + i.tm.operand_types[op].bitfield.ymmword |
3972 | 0 | + i.tm.operand_types[op].bitfield.zmmword > 1) |
3973 | 0 | { |
3974 | 0 | if (i.types[op].bitfield.zmmword) |
3975 | 0 | { |
3976 | 0 | i.tm.opcode_modifier.evex = EVEX512; |
3977 | 0 | break; |
3978 | 0 | } |
3979 | 0 | else if (i.types[op].bitfield.ymmword) |
3980 | 0 | { |
3981 | 0 | i.tm.opcode_modifier.evex = EVEX256; |
3982 | 0 | break; |
3983 | 0 | } |
3984 | 0 | else if (i.types[op].bitfield.xmmword) |
3985 | 0 | { |
3986 | 0 | i.tm.opcode_modifier.evex = EVEX128; |
3987 | 0 | break; |
3988 | 0 | } |
3989 | 0 | else if ((i.broadcast.type || i.broadcast.bytes) |
3990 | 0 | && op == i.broadcast.operand) |
3991 | 0 | { |
3992 | 0 | switch (get_broadcast_bytes (&i.tm, true)) |
3993 | 0 | { |
3994 | 0 | case 64: |
3995 | 0 | i.tm.opcode_modifier.evex = EVEX512; |
3996 | 0 | break; |
3997 | 0 | case 32: |
3998 | 0 | i.tm.opcode_modifier.evex = EVEX256; |
3999 | 0 | break; |
4000 | 0 | case 16: |
4001 | 0 | i.tm.opcode_modifier.evex = EVEX128; |
4002 | 0 | break; |
4003 | 0 | default: |
4004 | 0 | abort (); |
4005 | 0 | } |
4006 | 0 | break; |
4007 | 0 | } |
4008 | 0 | } |
4009 | | |
4010 | 0 | if (op >= MAX_OPERANDS) |
4011 | 0 | abort (); |
4012 | 0 | } |
4013 | | |
4014 | 0 | switch (i.tm.opcode_modifier.evex) |
4015 | 0 | { |
4016 | 0 | case EVEXLIG: /* LL' is ignored */ |
4017 | 0 | vec_length = evexlig << 5; |
4018 | 0 | break; |
4019 | 0 | case EVEX128: |
4020 | 0 | vec_length = 0 << 5; |
4021 | 0 | break; |
4022 | 0 | case EVEX256: |
4023 | 0 | vec_length = 1 << 5; |
4024 | 0 | break; |
4025 | 0 | case EVEX512: |
4026 | 0 | vec_length = 2 << 5; |
4027 | 0 | break; |
4028 | 0 | case EVEX_L3: |
4029 | 0 | if (dot_insn ()) |
4030 | 0 | { |
4031 | 0 | vec_length = 3 << 5; |
4032 | 0 | break; |
4033 | 0 | } |
4034 | | /* Fall through. */ |
4035 | 0 | default: |
4036 | 0 | abort (); |
4037 | 0 | break; |
4038 | 0 | } |
4039 | 0 | i.vex.bytes[3] |= vec_length; |
4040 | | /* Encode the broadcast bit. */ |
4041 | 0 | if (i.broadcast.type || i.broadcast.bytes) |
4042 | 0 | i.vex.bytes[3] |= 0x10; |
4043 | 0 | } |
4044 | 0 | else if (i.rounding.type != saeonly) |
4045 | 0 | i.vex.bytes[3] |= 0x10 | (i.rounding.type << 5); |
4046 | 0 | else |
4047 | 0 | i.vex.bytes[3] |= 0x10 | (evexrcig << 5); |
4048 | | |
4049 | 0 | if (i.mask.reg) |
4050 | 0 | i.vex.bytes[3] |= i.mask.reg->reg_num; |
4051 | 0 | } |
4052 | | |
4053 | | static void |
4054 | | process_immext (void) |
4055 | 0 | { |
4056 | 0 | expressionS *exp; |
4057 | | |
4058 | | /* These AMD 3DNow! and SSE2 instructions have an opcode suffix |
4059 | | which is coded in the same place as an 8-bit immediate field |
4060 | | would be. Here we fake an 8-bit immediate operand from the |
4061 | | opcode suffix stored in tm.extension_opcode. |
4062 | | |
4063 | | AVX instructions also use this encoding, for some of |
4064 | | 3 argument instructions. */ |
4065 | |
|
4066 | 0 | gas_assert (i.imm_operands <= 1 |
4067 | 0 | && (i.operands <= 2 |
4068 | 0 | || (is_any_vex_encoding (&i.tm) |
4069 | 0 | && i.operands <= 4))); |
4070 | | |
4071 | 0 | exp = &im_expressions[i.imm_operands++]; |
4072 | 0 | i.op[i.operands].imms = exp; |
4073 | 0 | i.types[i.operands].bitfield.imm8 = 1; |
4074 | 0 | i.operands++; |
4075 | 0 | exp->X_op = O_constant; |
4076 | 0 | exp->X_add_number = i.tm.extension_opcode; |
4077 | 0 | i.tm.extension_opcode = None; |
4078 | 0 | } |
4079 | | |
4080 | | |
4081 | | static int |
4082 | | check_hle (void) |
4083 | 0 | { |
4084 | 0 | switch (i.tm.opcode_modifier.prefixok) |
4085 | 0 | { |
4086 | 0 | default: |
4087 | 0 | abort (); |
4088 | 0 | case PrefixLock: |
4089 | 0 | case PrefixNone: |
4090 | 0 | case PrefixNoTrack: |
4091 | 0 | case PrefixRep: |
4092 | 0 | as_bad (_("invalid instruction `%s' after `%s'"), |
4093 | 0 | insn_name (&i.tm), i.hle_prefix); |
4094 | 0 | return 0; |
4095 | 0 | case PrefixHLELock: |
4096 | 0 | if (i.prefix[LOCK_PREFIX]) |
4097 | 0 | return 1; |
4098 | 0 | as_bad (_("missing `lock' with `%s'"), i.hle_prefix); |
4099 | 0 | return 0; |
4100 | 0 | case PrefixHLEAny: |
4101 | 0 | return 1; |
4102 | 0 | case PrefixHLERelease: |
4103 | 0 | if (i.prefix[HLE_PREFIX] != XRELEASE_PREFIX_OPCODE) |
4104 | 0 | { |
4105 | 0 | as_bad (_("instruction `%s' after `xacquire' not allowed"), |
4106 | 0 | insn_name (&i.tm)); |
4107 | 0 | return 0; |
4108 | 0 | } |
4109 | 0 | if (i.mem_operands == 0 || !(i.flags[i.operands - 1] & Operand_Mem)) |
4110 | 0 | { |
4111 | 0 | as_bad (_("memory destination needed for instruction `%s'" |
4112 | 0 | " after `xrelease'"), insn_name (&i.tm)); |
4113 | 0 | return 0; |
4114 | 0 | } |
4115 | 0 | return 1; |
4116 | 0 | } |
4117 | 0 | } |
4118 | | |
4119 | | /* Encode aligned vector move as unaligned vector move. */ |
4120 | | |
4121 | | static void |
4122 | | encode_with_unaligned_vector_move (void) |
4123 | 0 | { |
4124 | 0 | switch (i.tm.base_opcode) |
4125 | 0 | { |
4126 | 0 | case 0x28: /* Load instructions. */ |
4127 | 0 | case 0x29: /* Store instructions. */ |
4128 | | /* movaps/movapd/vmovaps/vmovapd. */ |
4129 | 0 | if (i.tm.opcode_space == SPACE_0F |
4130 | 0 | && i.tm.opcode_modifier.opcodeprefix <= PREFIX_0X66) |
4131 | 0 | i.tm.base_opcode = 0x10 | (i.tm.base_opcode & 1); |
4132 | 0 | break; |
4133 | 0 | case 0x6f: /* Load instructions. */ |
4134 | 0 | case 0x7f: /* Store instructions. */ |
4135 | | /* movdqa/vmovdqa/vmovdqa64/vmovdqa32. */ |
4136 | 0 | if (i.tm.opcode_space == SPACE_0F |
4137 | 0 | && i.tm.opcode_modifier.opcodeprefix == PREFIX_0X66) |
4138 | 0 | i.tm.opcode_modifier.opcodeprefix = PREFIX_0XF3; |
4139 | 0 | break; |
4140 | 0 | default: |
4141 | 0 | break; |
4142 | 0 | } |
4143 | 0 | } |
4144 | | |
4145 | | /* Try the shortest encoding by shortening operand size. */ |
4146 | | |
4147 | | static void |
4148 | | optimize_encoding (void) |
4149 | 0 | { |
4150 | 0 | unsigned int j; |
4151 | |
|
4152 | 0 | if (i.tm.mnem_off == MN_lea) |
4153 | 0 | { |
4154 | | /* Optimize: -O: |
4155 | | lea symbol, %rN -> mov $symbol, %rN |
4156 | | lea (%rM), %rN -> mov %rM, %rN |
4157 | | lea (,%rM,1), %rN -> mov %rM, %rN |
4158 | | |
4159 | | and in 32-bit mode for 16-bit addressing |
4160 | | |
4161 | | lea (%rM), %rN -> movzx %rM, %rN |
4162 | | |
4163 | | and in 64-bit mode zap 32-bit addressing in favor of using a |
4164 | | 32-bit (or less) destination. |
4165 | | */ |
4166 | 0 | if (flag_code == CODE_64BIT && i.prefix[ADDR_PREFIX]) |
4167 | 0 | { |
4168 | 0 | if (!i.op[1].regs->reg_type.bitfield.word) |
4169 | 0 | i.tm.opcode_modifier.size = SIZE32; |
4170 | 0 | i.prefix[ADDR_PREFIX] = 0; |
4171 | 0 | } |
4172 | |
|
4173 | 0 | if (!i.index_reg && !i.base_reg) |
4174 | 0 | { |
4175 | | /* Handle: |
4176 | | lea symbol, %rN -> mov $symbol, %rN |
4177 | | */ |
4178 | 0 | if (flag_code == CODE_64BIT) |
4179 | 0 | { |
4180 | | /* Don't transform a relocation to a 16-bit one. */ |
4181 | 0 | if (i.op[0].disps |
4182 | 0 | && i.op[0].disps->X_op != O_constant |
4183 | 0 | && i.op[1].regs->reg_type.bitfield.word) |
4184 | 0 | return; |
4185 | | |
4186 | 0 | if (!i.op[1].regs->reg_type.bitfield.qword |
4187 | 0 | || i.tm.opcode_modifier.size == SIZE32) |
4188 | 0 | { |
4189 | 0 | i.tm.base_opcode = 0xb8; |
4190 | 0 | i.tm.opcode_modifier.modrm = 0; |
4191 | 0 | if (!i.op[1].regs->reg_type.bitfield.word) |
4192 | 0 | i.types[0].bitfield.imm32 = 1; |
4193 | 0 | else |
4194 | 0 | { |
4195 | 0 | i.tm.opcode_modifier.size = SIZE16; |
4196 | 0 | i.types[0].bitfield.imm16 = 1; |
4197 | 0 | } |
4198 | 0 | } |
4199 | 0 | else |
4200 | 0 | { |
4201 | | /* Subject to further optimization below. */ |
4202 | 0 | i.tm.base_opcode = 0xc7; |
4203 | 0 | i.tm.extension_opcode = 0; |
4204 | 0 | i.types[0].bitfield.imm32s = 1; |
4205 | 0 | i.types[0].bitfield.baseindex = 0; |
4206 | 0 | } |
4207 | 0 | } |
4208 | | /* Outside of 64-bit mode address and operand sizes have to match if |
4209 | | a relocation is involved, as otherwise we wouldn't (currently) or |
4210 | | even couldn't express the relocation correctly. */ |
4211 | 0 | else if (i.op[0].disps |
4212 | 0 | && i.op[0].disps->X_op != O_constant |
4213 | 0 | && ((!i.prefix[ADDR_PREFIX]) |
4214 | 0 | != (flag_code == CODE_32BIT |
4215 | 0 | ? i.op[1].regs->reg_type.bitfield.dword |
4216 | 0 | : i.op[1].regs->reg_type.bitfield.word))) |
4217 | 0 | return; |
4218 | | /* In 16-bit mode converting LEA with 16-bit addressing and a 32-bit |
4219 | | destination is going to grow encoding size. */ |
4220 | 0 | else if (flag_code == CODE_16BIT |
4221 | 0 | && (optimize <= 1 || optimize_for_space) |
4222 | 0 | && !i.prefix[ADDR_PREFIX] |
4223 | 0 | && i.op[1].regs->reg_type.bitfield.dword) |
4224 | 0 | return; |
4225 | 0 | else |
4226 | 0 | { |
4227 | 0 | i.tm.base_opcode = 0xb8; |
4228 | 0 | i.tm.opcode_modifier.modrm = 0; |
4229 | 0 | if (i.op[1].regs->reg_type.bitfield.dword) |
4230 | 0 | i.types[0].bitfield.imm32 = 1; |
4231 | 0 | else |
4232 | 0 | i.types[0].bitfield.imm16 = 1; |
4233 | |
|
4234 | 0 | if (i.op[0].disps |
4235 | 0 | && i.op[0].disps->X_op == O_constant |
4236 | 0 | && i.op[1].regs->reg_type.bitfield.dword |
4237 | | /* NB: Add () to !i.prefix[ADDR_PREFIX] to silence |
4238 | | GCC 5. */ |
4239 | 0 | && (!i.prefix[ADDR_PREFIX]) != (flag_code == CODE_32BIT)) |
4240 | 0 | i.op[0].disps->X_add_number &= 0xffff; |
4241 | 0 | } |
4242 | | |
4243 | 0 | i.tm.operand_types[0] = i.types[0]; |
4244 | 0 | i.imm_operands = 1; |
4245 | 0 | if (!i.op[0].imms) |
4246 | 0 | { |
4247 | 0 | i.op[0].imms = &im_expressions[0]; |
4248 | 0 | i.op[0].imms->X_op = O_absent; |
4249 | 0 | } |
4250 | 0 | } |
4251 | 0 | else if (i.op[0].disps |
4252 | 0 | && (i.op[0].disps->X_op != O_constant |
4253 | 0 | || i.op[0].disps->X_add_number)) |
4254 | 0 | return; |
4255 | 0 | else |
4256 | 0 | { |
4257 | | /* Handle: |
4258 | | lea (%rM), %rN -> mov %rM, %rN |
4259 | | lea (,%rM,1), %rN -> mov %rM, %rN |
4260 | | lea (%rM), %rN -> movzx %rM, %rN |
4261 | | */ |
4262 | 0 | const reg_entry *addr_reg; |
4263 | |
|
4264 | 0 | if (!i.index_reg && i.base_reg->reg_num != RegIP) |
4265 | 0 | addr_reg = i.base_reg; |
4266 | 0 | else if (!i.base_reg |
4267 | 0 | && i.index_reg->reg_num != RegIZ |
4268 | 0 | && !i.log2_scale_factor) |
4269 | 0 | addr_reg = i.index_reg; |
4270 | 0 | else |
4271 | 0 | return; |
4272 | | |
4273 | 0 | if (addr_reg->reg_type.bitfield.word |
4274 | 0 | && i.op[1].regs->reg_type.bitfield.dword) |
4275 | 0 | { |
4276 | 0 | if (flag_code != CODE_32BIT) |
4277 | 0 | return; |
4278 | 0 | i.tm.opcode_space = SPACE_0F; |
4279 | 0 | i.tm.base_opcode = 0xb7; |
4280 | 0 | } |
4281 | 0 | else |
4282 | 0 | i.tm.base_opcode = 0x8b; |
4283 | | |
4284 | 0 | if (addr_reg->reg_type.bitfield.dword |
4285 | 0 | && i.op[1].regs->reg_type.bitfield.qword) |
4286 | 0 | i.tm.opcode_modifier.size = SIZE32; |
4287 | |
|
4288 | 0 | i.op[0].regs = addr_reg; |
4289 | 0 | i.reg_operands = 2; |
4290 | 0 | } |
4291 | | |
4292 | 0 | i.mem_operands = 0; |
4293 | 0 | i.disp_operands = 0; |
4294 | 0 | i.prefix[ADDR_PREFIX] = 0; |
4295 | 0 | i.prefix[SEG_PREFIX] = 0; |
4296 | 0 | i.seg[0] = NULL; |
4297 | 0 | } |
4298 | | |
4299 | 0 | if (optimize_for_space |
4300 | 0 | && i.tm.mnem_off == MN_test |
4301 | 0 | && i.reg_operands == 1 |
4302 | 0 | && i.imm_operands == 1 |
4303 | 0 | && !i.types[1].bitfield.byte |
4304 | 0 | && i.op[0].imms->X_op == O_constant |
4305 | 0 | && fits_in_imm7 (i.op[0].imms->X_add_number)) |
4306 | 0 | { |
4307 | | /* Optimize: -Os: |
4308 | | test $imm7, %r64/%r32/%r16 -> test $imm7, %r8 |
4309 | | */ |
4310 | 0 | unsigned int base_regnum = i.op[1].regs->reg_num; |
4311 | 0 | if (flag_code == CODE_64BIT || base_regnum < 4) |
4312 | 0 | { |
4313 | 0 | i.types[1].bitfield.byte = 1; |
4314 | | /* Ignore the suffix. */ |
4315 | 0 | i.suffix = 0; |
4316 | | /* Convert to byte registers. */ |
4317 | 0 | if (i.types[1].bitfield.word) |
4318 | 0 | j = 16; |
4319 | 0 | else if (i.types[1].bitfield.dword) |
4320 | 0 | j = 32; |
4321 | 0 | else |
4322 | 0 | j = 48; |
4323 | 0 | if (!(i.op[1].regs->reg_flags & RegRex) && base_regnum < 4) |
4324 | 0 | j += 8; |
4325 | 0 | i.op[1].regs -= j; |
4326 | 0 | } |
4327 | 0 | } |
4328 | 0 | else if (flag_code == CODE_64BIT |
4329 | 0 | && i.tm.opcode_space == SPACE_BASE |
4330 | 0 | && ((i.types[1].bitfield.qword |
4331 | 0 | && i.reg_operands == 1 |
4332 | 0 | && i.imm_operands == 1 |
4333 | 0 | && i.op[0].imms->X_op == O_constant |
4334 | 0 | && ((i.tm.base_opcode == 0xb8 |
4335 | 0 | && i.tm.extension_opcode == None |
4336 | 0 | && fits_in_unsigned_long (i.op[0].imms->X_add_number)) |
4337 | 0 | || (fits_in_imm31 (i.op[0].imms->X_add_number) |
4338 | 0 | && (i.tm.base_opcode == 0x24 |
4339 | 0 | || (i.tm.base_opcode == 0x80 |
4340 | 0 | && i.tm.extension_opcode == 0x4) |
4341 | 0 | || i.tm.mnem_off == MN_test |
4342 | 0 | || ((i.tm.base_opcode | 1) == 0xc7 |
4343 | 0 | && i.tm.extension_opcode == 0x0))) |
4344 | 0 | || (fits_in_imm7 (i.op[0].imms->X_add_number) |
4345 | 0 | && i.tm.base_opcode == 0x83 |
4346 | 0 | && i.tm.extension_opcode == 0x4))) |
4347 | 0 | || (i.types[0].bitfield.qword |
4348 | 0 | && ((i.reg_operands == 2 |
4349 | 0 | && i.op[0].regs == i.op[1].regs |
4350 | 0 | && (i.tm.mnem_off == MN_xor |
4351 | 0 | || i.tm.mnem_off == MN_sub)) |
4352 | 0 | || i.tm.mnem_off == MN_clr)))) |
4353 | 0 | { |
4354 | | /* Optimize: -O: |
4355 | | andq $imm31, %r64 -> andl $imm31, %r32 |
4356 | | andq $imm7, %r64 -> andl $imm7, %r32 |
4357 | | testq $imm31, %r64 -> testl $imm31, %r32 |
4358 | | xorq %r64, %r64 -> xorl %r32, %r32 |
4359 | | subq %r64, %r64 -> subl %r32, %r32 |
4360 | | movq $imm31, %r64 -> movl $imm31, %r32 |
4361 | | movq $imm32, %r64 -> movl $imm32, %r32 |
4362 | | */ |
4363 | 0 | i.tm.opcode_modifier.size = SIZE32; |
4364 | 0 | if (i.imm_operands) |
4365 | 0 | { |
4366 | 0 | i.types[0].bitfield.imm32 = 1; |
4367 | 0 | i.types[0].bitfield.imm32s = 0; |
4368 | 0 | i.types[0].bitfield.imm64 = 0; |
4369 | 0 | } |
4370 | 0 | else |
4371 | 0 | { |
4372 | 0 | i.types[0].bitfield.dword = 1; |
4373 | 0 | i.types[0].bitfield.qword = 0; |
4374 | 0 | } |
4375 | 0 | i.types[1].bitfield.dword = 1; |
4376 | 0 | i.types[1].bitfield.qword = 0; |
4377 | 0 | if (i.tm.mnem_off == MN_mov || i.tm.mnem_off == MN_lea) |
4378 | 0 | { |
4379 | | /* Handle |
4380 | | movq $imm31, %r64 -> movl $imm31, %r32 |
4381 | | movq $imm32, %r64 -> movl $imm32, %r32 |
4382 | | */ |
4383 | 0 | i.tm.operand_types[0].bitfield.imm32 = 1; |
4384 | 0 | i.tm.operand_types[0].bitfield.imm32s = 0; |
4385 | 0 | i.tm.operand_types[0].bitfield.imm64 = 0; |
4386 | 0 | if ((i.tm.base_opcode | 1) == 0xc7) |
4387 | 0 | { |
4388 | | /* Handle |
4389 | | movq $imm31, %r64 -> movl $imm31, %r32 |
4390 | | */ |
4391 | 0 | i.tm.base_opcode = 0xb8; |
4392 | 0 | i.tm.extension_opcode = None; |
4393 | 0 | i.tm.opcode_modifier.w = 0; |
4394 | 0 | i.tm.opcode_modifier.modrm = 0; |
4395 | 0 | } |
4396 | 0 | } |
4397 | 0 | } |
4398 | 0 | else if (optimize > 1 |
4399 | 0 | && !optimize_for_space |
4400 | 0 | && i.reg_operands == 2 |
4401 | 0 | && i.op[0].regs == i.op[1].regs |
4402 | 0 | && (i.tm.mnem_off == MN_and || i.tm.mnem_off == MN_or) |
4403 | 0 | && (flag_code != CODE_64BIT || !i.types[0].bitfield.dword)) |
4404 | 0 | { |
4405 | | /* Optimize: -O2: |
4406 | | andb %rN, %rN -> testb %rN, %rN |
4407 | | andw %rN, %rN -> testw %rN, %rN |
4408 | | andq %rN, %rN -> testq %rN, %rN |
4409 | | orb %rN, %rN -> testb %rN, %rN |
4410 | | orw %rN, %rN -> testw %rN, %rN |
4411 | | orq %rN, %rN -> testq %rN, %rN |
4412 | | |
4413 | | and outside of 64-bit mode |
4414 | | |
4415 | | andl %rN, %rN -> testl %rN, %rN |
4416 | | orl %rN, %rN -> testl %rN, %rN |
4417 | | */ |
4418 | 0 | i.tm.base_opcode = 0x84 | (i.tm.base_opcode & 1); |
4419 | 0 | } |
4420 | 0 | else if (i.tm.base_opcode == 0xba |
4421 | 0 | && i.tm.opcode_space == SPACE_0F |
4422 | 0 | && i.reg_operands == 1 |
4423 | 0 | && i.op[0].imms->X_op == O_constant |
4424 | 0 | && i.op[0].imms->X_add_number >= 0) |
4425 | 0 | { |
4426 | | /* Optimize: -O: |
4427 | | btw $n, %rN -> btl $n, %rN (outside of 16-bit mode, n < 16) |
4428 | | btq $n, %rN -> btl $n, %rN (in 64-bit mode, n < 32, N < 8) |
4429 | | btl $n, %rN -> btw $n, %rN (in 16-bit mode, n < 16) |
4430 | | |
4431 | | With <BT> one of bts, btr, and bts also: |
4432 | | <BT>w $n, %rN -> btl $n, %rN (in 32-bit mode, n < 16) |
4433 | | <BT>l $n, %rN -> btw $n, %rN (in 16-bit mode, n < 16) |
4434 | | */ |
4435 | 0 | switch (flag_code) |
4436 | 0 | { |
4437 | 0 | case CODE_64BIT: |
4438 | 0 | if (i.tm.extension_opcode != 4) |
4439 | 0 | break; |
4440 | 0 | if (i.types[1].bitfield.qword |
4441 | 0 | && i.op[0].imms->X_add_number < 32 |
4442 | 0 | && !(i.op[1].regs->reg_flags & RegRex)) |
4443 | 0 | i.tm.opcode_modifier.size = SIZE32; |
4444 | | /* Fall through. */ |
4445 | 0 | case CODE_32BIT: |
4446 | 0 | if (i.types[1].bitfield.word |
4447 | 0 | && i.op[0].imms->X_add_number < 16) |
4448 | 0 | i.tm.opcode_modifier.size = SIZE32; |
4449 | 0 | break; |
4450 | 0 | case CODE_16BIT: |
4451 | 0 | if (i.op[0].imms->X_add_number < 16) |
4452 | 0 | i.tm.opcode_modifier.size = SIZE16; |
4453 | 0 | break; |
4454 | 0 | } |
4455 | 0 | } |
4456 | 0 | else if (i.reg_operands == 3 |
4457 | 0 | && i.op[0].regs == i.op[1].regs |
4458 | 0 | && !i.types[2].bitfield.xmmword |
4459 | 0 | && (i.tm.opcode_modifier.vex |
4460 | 0 | || ((!i.mask.reg || i.mask.zeroing) |
4461 | 0 | && is_evex_encoding (&i.tm) |
4462 | 0 | && (i.vec_encoding != vex_encoding_evex |
4463 | 0 | || cpu_arch_isa_flags.bitfield.cpuavx512vl |
4464 | 0 | || is_cpu (&i.tm, CpuAVX512VL) |
4465 | 0 | || (i.tm.operand_types[2].bitfield.zmmword |
4466 | 0 | && i.types[2].bitfield.ymmword)))) |
4467 | 0 | && i.tm.opcode_space == SPACE_0F |
4468 | 0 | && ((i.tm.base_opcode | 2) == 0x57 |
4469 | 0 | || i.tm.base_opcode == 0xdf |
4470 | 0 | || i.tm.base_opcode == 0xef |
4471 | 0 | || (i.tm.base_opcode | 3) == 0xfb |
4472 | 0 | || i.tm.base_opcode == 0x42 |
4473 | 0 | || i.tm.base_opcode == 0x47)) |
4474 | 0 | { |
4475 | | /* Optimize: -O1: |
4476 | | VOP, one of vandnps, vandnpd, vxorps, vxorpd, vpsubb, vpsubd, |
4477 | | vpsubq and vpsubw: |
4478 | | EVEX VOP %zmmM, %zmmM, %zmmN |
4479 | | -> VEX VOP %xmmM, %xmmM, %xmmN (M and N < 16) |
4480 | | -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2) |
4481 | | EVEX VOP %ymmM, %ymmM, %ymmN |
4482 | | -> VEX VOP %xmmM, %xmmM, %xmmN (M and N < 16) |
4483 | | -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2) |
4484 | | VEX VOP %ymmM, %ymmM, %ymmN |
4485 | | -> VEX VOP %xmmM, %xmmM, %xmmN |
4486 | | VOP, one of vpandn and vpxor: |
4487 | | VEX VOP %ymmM, %ymmM, %ymmN |
4488 | | -> VEX VOP %xmmM, %xmmM, %xmmN |
4489 | | VOP, one of vpandnd and vpandnq: |
4490 | | EVEX VOP %zmmM, %zmmM, %zmmN |
4491 | | -> VEX vpandn %xmmM, %xmmM, %xmmN (M and N < 16) |
4492 | | -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2) |
4493 | | EVEX VOP %ymmM, %ymmM, %ymmN |
4494 | | -> VEX vpandn %xmmM, %xmmM, %xmmN (M and N < 16) |
4495 | | -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2) |
4496 | | VOP, one of vpxord and vpxorq: |
4497 | | EVEX VOP %zmmM, %zmmM, %zmmN |
4498 | | -> VEX vpxor %xmmM, %xmmM, %xmmN (M and N < 16) |
4499 | | -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2) |
4500 | | EVEX VOP %ymmM, %ymmM, %ymmN |
4501 | | -> VEX vpxor %xmmM, %xmmM, %xmmN (M and N < 16) |
4502 | | -> EVEX VOP %xmmM, %xmmM, %xmmN (M || N >= 16) (-O2) |
4503 | | VOP, one of kxord and kxorq: |
4504 | | VEX VOP %kM, %kM, %kN |
4505 | | -> VEX kxorw %kM, %kM, %kN |
4506 | | VOP, one of kandnd and kandnq: |
4507 | | VEX VOP %kM, %kM, %kN |
4508 | | -> VEX kandnw %kM, %kM, %kN |
4509 | | */ |
4510 | 0 | if (is_evex_encoding (&i.tm)) |
4511 | 0 | { |
4512 | 0 | if (i.vec_encoding != vex_encoding_evex) |
4513 | 0 | { |
4514 | 0 | i.tm.opcode_modifier.vex = VEX128; |
4515 | 0 | i.tm.opcode_modifier.vexw = VEXW0; |
4516 | 0 | i.tm.opcode_modifier.evex = 0; |
4517 | 0 | } |
4518 | 0 | else if (optimize > 1) |
4519 | 0 | i.tm.opcode_modifier.evex = EVEX128; |
4520 | 0 | else |
4521 | 0 | return; |
4522 | 0 | } |
4523 | 0 | else if (i.tm.operand_types[0].bitfield.class == RegMask) |
4524 | 0 | { |
4525 | 0 | i.tm.opcode_modifier.opcodeprefix = PREFIX_NONE; |
4526 | 0 | i.tm.opcode_modifier.vexw = VEXW0; |
4527 | 0 | } |
4528 | 0 | else |
4529 | 0 | i.tm.opcode_modifier.vex = VEX128; |
4530 | | |
4531 | 0 | if (i.tm.opcode_modifier.vex) |
4532 | 0 | for (j = 0; j < 3; j++) |
4533 | 0 | { |
4534 | 0 | i.types[j].bitfield.xmmword = 1; |
4535 | 0 | i.types[j].bitfield.ymmword = 0; |
4536 | 0 | } |
4537 | 0 | } |
4538 | 0 | else if (i.vec_encoding != vex_encoding_evex |
4539 | 0 | && !i.types[0].bitfield.zmmword |
4540 | 0 | && !i.types[1].bitfield.zmmword |
4541 | 0 | && !i.mask.reg |
4542 | 0 | && !i.broadcast.type |
4543 | 0 | && !i.broadcast.bytes |
4544 | 0 | && is_evex_encoding (&i.tm) |
4545 | 0 | && ((i.tm.base_opcode & ~Opcode_SIMD_IntD) == 0x6f |
4546 | 0 | || (i.tm.base_opcode & ~4) == 0xdb |
4547 | 0 | || (i.tm.base_opcode & ~4) == 0xeb) |
4548 | 0 | && i.tm.extension_opcode == None) |
4549 | 0 | { |
4550 | | /* Optimize: -O1: |
4551 | | VOP, one of vmovdqa32, vmovdqa64, vmovdqu8, vmovdqu16, |
4552 | | vmovdqu32 and vmovdqu64: |
4553 | | EVEX VOP %xmmM, %xmmN |
4554 | | -> VEX vmovdqa|vmovdqu %xmmM, %xmmN (M and N < 16) |
4555 | | EVEX VOP %ymmM, %ymmN |
4556 | | -> VEX vmovdqa|vmovdqu %ymmM, %ymmN (M and N < 16) |
4557 | | EVEX VOP %xmmM, mem |
4558 | | -> VEX vmovdqa|vmovdqu %xmmM, mem (M < 16) |
4559 | | EVEX VOP %ymmM, mem |
4560 | | -> VEX vmovdqa|vmovdqu %ymmM, mem (M < 16) |
4561 | | EVEX VOP mem, %xmmN |
4562 | | -> VEX mvmovdqa|vmovdquem, %xmmN (N < 16) |
4563 | | EVEX VOP mem, %ymmN |
4564 | | -> VEX vmovdqa|vmovdqu mem, %ymmN (N < 16) |
4565 | | VOP, one of vpand, vpandn, vpor, vpxor: |
4566 | | EVEX VOP{d,q} %xmmL, %xmmM, %xmmN |
4567 | | -> VEX VOP %xmmL, %xmmM, %xmmN (L, M, and N < 16) |
4568 | | EVEX VOP{d,q} %ymmL, %ymmM, %ymmN |
4569 | | -> VEX VOP %ymmL, %ymmM, %ymmN (L, M, and N < 16) |
4570 | | EVEX VOP{d,q} mem, %xmmM, %xmmN |
4571 | | -> VEX VOP mem, %xmmM, %xmmN (M and N < 16) |
4572 | | EVEX VOP{d,q} mem, %ymmM, %ymmN |
4573 | | -> VEX VOP mem, %ymmM, %ymmN (M and N < 16) |
4574 | | */ |
4575 | 0 | for (j = 0; j < i.operands; j++) |
4576 | 0 | if (operand_type_check (i.types[j], disp) |
4577 | 0 | && i.op[j].disps->X_op == O_constant) |
4578 | 0 | { |
4579 | | /* Since the VEX prefix has 2 or 3 bytes, the EVEX prefix |
4580 | | has 4 bytes, EVEX Disp8 has 1 byte and VEX Disp32 has 4 |
4581 | | bytes, we choose EVEX Disp8 over VEX Disp32. */ |
4582 | 0 | int evex_disp8, vex_disp8; |
4583 | 0 | unsigned int memshift = i.memshift; |
4584 | 0 | offsetT n = i.op[j].disps->X_add_number; |
4585 | |
|
4586 | 0 | evex_disp8 = fits_in_disp8 (n); |
4587 | 0 | i.memshift = 0; |
4588 | 0 | vex_disp8 = fits_in_disp8 (n); |
4589 | 0 | if (evex_disp8 != vex_disp8) |
4590 | 0 | { |
4591 | 0 | i.memshift = memshift; |
4592 | 0 | return; |
4593 | 0 | } |
4594 | | |
4595 | 0 | i.types[j].bitfield.disp8 = vex_disp8; |
4596 | 0 | break; |
4597 | 0 | } |
4598 | 0 | if ((i.tm.base_opcode & ~Opcode_SIMD_IntD) == 0x6f |
4599 | 0 | && i.tm.opcode_modifier.opcodeprefix == PREFIX_0XF2) |
4600 | 0 | i.tm.opcode_modifier.opcodeprefix = PREFIX_0XF3; |
4601 | 0 | i.tm.opcode_modifier.vex |
4602 | 0 | = i.types[0].bitfield.ymmword ? VEX256 : VEX128; |
4603 | 0 | i.tm.opcode_modifier.vexw = VEXW0; |
4604 | | /* VPAND, VPOR, and VPXOR are commutative. */ |
4605 | 0 | if (i.reg_operands == 3 && i.tm.base_opcode != 0xdf) |
4606 | 0 | i.tm.opcode_modifier.commutative = 1; |
4607 | 0 | i.tm.opcode_modifier.evex = 0; |
4608 | 0 | i.tm.opcode_modifier.masking = 0; |
4609 | 0 | i.tm.opcode_modifier.broadcast = 0; |
4610 | 0 | i.tm.opcode_modifier.disp8memshift = 0; |
4611 | 0 | i.memshift = 0; |
4612 | 0 | if (j < i.operands) |
4613 | 0 | i.types[j].bitfield.disp8 |
4614 | 0 | = fits_in_disp8 (i.op[j].disps->X_add_number); |
4615 | 0 | } |
4616 | 0 | else if (optimize_for_space |
4617 | 0 | && i.tm.base_opcode == 0x29 |
4618 | 0 | && i.tm.opcode_space == SPACE_0F38 |
4619 | 0 | && i.operands == i.reg_operands |
4620 | 0 | && i.op[0].regs == i.op[1].regs |
4621 | 0 | && (!i.tm.opcode_modifier.vex |
4622 | 0 | || !(i.op[0].regs->reg_flags & RegRex)) |
4623 | 0 | && !is_evex_encoding (&i.tm)) |
4624 | 0 | { |
4625 | | /* Optimize: -Os: |
4626 | | pcmpeqq %xmmN, %xmmN -> pcmpeqd %xmmN, %xmmN |
4627 | | vpcmpeqq %xmmN, %xmmN, %xmmM -> vpcmpeqd %xmmN, %xmmN, %xmmM (N < 8) |
4628 | | vpcmpeqq %ymmN, %ymmN, %ymmM -> vpcmpeqd %ymmN, %ymmN, %ymmM (N < 8) |
4629 | | */ |
4630 | 0 | i.tm.opcode_space = SPACE_0F; |
4631 | 0 | i.tm.base_opcode = 0x76; |
4632 | 0 | } |
4633 | 0 | else if (((i.tm.base_opcode >= 0x64 |
4634 | 0 | && i.tm.base_opcode <= 0x66 |
4635 | 0 | && i.tm.opcode_space == SPACE_0F) |
4636 | 0 | || (i.tm.base_opcode == 0x37 |
4637 | 0 | && i.tm.opcode_space == SPACE_0F38)) |
4638 | 0 | && i.operands == i.reg_operands |
4639 | 0 | && i.op[0].regs == i.op[1].regs |
4640 | 0 | && !is_evex_encoding (&i.tm)) |
4641 | 0 | { |
4642 | | /* Optimize: -O: |
4643 | | pcmpgt[bwd] %mmN, %mmN -> pxor %mmN, %mmN |
4644 | | pcmpgt[bwdq] %xmmN, %xmmN -> pxor %xmmN, %xmmN |
4645 | | vpcmpgt[bwdq] %xmmN, %xmmN, %xmmM -> vpxor %xmmN, %xmmN, %xmmM (N < 8) |
4646 | | vpcmpgt[bwdq] %xmmN, %xmmN, %xmmM -> vpxor %xmm0, %xmm0, %xmmM (N > 7) |
4647 | | vpcmpgt[bwdq] %ymmN, %ymmN, %ymmM -> vpxor %ymmN, %ymmN, %ymmM (N < 8) |
4648 | | vpcmpgt[bwdq] %ymmN, %ymmN, %ymmM -> vpxor %ymm0, %ymm0, %ymmM (N > 7) |
4649 | | */ |
4650 | 0 | i.tm.opcode_space = SPACE_0F; |
4651 | 0 | i.tm.base_opcode = 0xef; |
4652 | 0 | if (i.tm.opcode_modifier.vex && (i.op[0].regs->reg_flags & RegRex)) |
4653 | 0 | { |
4654 | 0 | if (i.operands == 2) |
4655 | 0 | { |
4656 | 0 | gas_assert (i.tm.opcode_modifier.sse2avx); |
4657 | | |
4658 | 0 | i.operands = 3; |
4659 | 0 | i.reg_operands = 3; |
4660 | 0 | i.tm.operands = 3; |
4661 | |
|
4662 | 0 | i.op[2].regs = i.op[0].regs; |
4663 | 0 | i.types[2] = i.types[0]; |
4664 | 0 | i.flags[2] = i.flags[0]; |
4665 | 0 | i.tm.operand_types[2] = i.tm.operand_types[0]; |
4666 | |
|
4667 | 0 | i.tm.opcode_modifier.sse2avx = 0; |
4668 | 0 | } |
4669 | 0 | i.op[0].regs -= i.op[0].regs->reg_num + 8; |
4670 | 0 | i.op[1].regs = i.op[0].regs; |
4671 | 0 | } |
4672 | 0 | } |
4673 | 0 | else if (optimize_for_space |
4674 | 0 | && i.tm.base_opcode == 0x59 |
4675 | 0 | && i.tm.opcode_space == SPACE_0F38 |
4676 | 0 | && i.operands == i.reg_operands |
4677 | 0 | && i.tm.opcode_modifier.vex |
4678 | 0 | && !(i.op[0].regs->reg_flags & RegRex) |
4679 | 0 | && i.op[0].regs->reg_type.bitfield.xmmword |
4680 | 0 | && i.vec_encoding != vex_encoding_vex3) |
4681 | 0 | { |
4682 | | /* Optimize: -Os: |
4683 | | vpbroadcastq %xmmN, %xmmM -> vpunpcklqdq %xmmN, %xmmN, %xmmM (N < 8) |
4684 | | */ |
4685 | 0 | i.tm.opcode_space = SPACE_0F; |
4686 | 0 | i.tm.base_opcode = 0x6c; |
4687 | 0 | i.tm.opcode_modifier.vexvvvv = 1; |
4688 | |
|
4689 | 0 | ++i.operands; |
4690 | 0 | ++i.reg_operands; |
4691 | 0 | ++i.tm.operands; |
4692 | |
|
4693 | 0 | i.op[2].regs = i.op[0].regs; |
4694 | 0 | i.types[2] = i.types[0]; |
4695 | 0 | i.flags[2] = i.flags[0]; |
4696 | 0 | i.tm.operand_types[2] = i.tm.operand_types[0]; |
4697 | |
|
4698 | 0 | swap_2_operands (1, 2); |
4699 | 0 | } |
4700 | 0 | } |
4701 | | |
4702 | | /* Return non-zero for load instruction. */ |
4703 | | |
4704 | | static int |
4705 | | load_insn_p (void) |
4706 | 0 | { |
4707 | 0 | unsigned int dest; |
4708 | 0 | int any_vex_p = is_any_vex_encoding (&i.tm); |
4709 | 0 | unsigned int base_opcode = i.tm.base_opcode | 1; |
4710 | |
|
4711 | 0 | if (!any_vex_p) |
4712 | 0 | { |
4713 | | /* Anysize insns: lea, invlpg, clflush, prefetch*, bndmk, bndcl, bndcu, |
4714 | | bndcn, bndstx, bndldx, clflushopt, clwb, cldemote. */ |
4715 | 0 | if (i.tm.opcode_modifier.operandconstraint == ANY_SIZE) |
4716 | 0 | return 0; |
4717 | | |
4718 | | /* pop. */ |
4719 | 0 | if (i.tm.mnem_off == MN_pop) |
4720 | 0 | return 1; |
4721 | 0 | } |
4722 | | |
4723 | 0 | if (i.tm.opcode_space == SPACE_BASE) |
4724 | 0 | { |
4725 | | /* popf, popa. */ |
4726 | 0 | if (i.tm.base_opcode == 0x9d |
4727 | 0 | || i.tm.base_opcode == 0x61) |
4728 | 0 | return 1; |
4729 | | |
4730 | | /* movs, cmps, lods, scas. */ |
4731 | 0 | if ((i.tm.base_opcode | 0xb) == 0xaf) |
4732 | 0 | return 1; |
4733 | | |
4734 | | /* outs, xlatb. */ |
4735 | 0 | if (base_opcode == 0x6f |
4736 | 0 | || i.tm.base_opcode == 0xd7) |
4737 | 0 | return 1; |
4738 | | /* NB: For AMD-specific insns with implicit memory operands, |
4739 | | they're intentionally not covered. */ |
4740 | 0 | } |
4741 | | |
4742 | | /* No memory operand. */ |
4743 | 0 | if (!i.mem_operands) |
4744 | 0 | return 0; |
4745 | | |
4746 | 0 | if (any_vex_p) |
4747 | 0 | { |
4748 | 0 | if (i.tm.mnem_off == MN_vldmxcsr) |
4749 | 0 | return 1; |
4750 | 0 | } |
4751 | 0 | else if (i.tm.opcode_space == SPACE_BASE) |
4752 | 0 | { |
4753 | | /* test, not, neg, mul, imul, div, idiv. */ |
4754 | 0 | if (base_opcode == 0xf7 && i.tm.extension_opcode != 1) |
4755 | 0 | return 1; |
4756 | | |
4757 | | /* inc, dec. */ |
4758 | 0 | if (base_opcode == 0xff && i.tm.extension_opcode <= 1) |
4759 | 0 | return 1; |
4760 | | |
4761 | | /* add, or, adc, sbb, and, sub, xor, cmp. */ |
4762 | 0 | if (i.tm.base_opcode >= 0x80 && i.tm.base_opcode <= 0x83) |
4763 | 0 | return 1; |
4764 | | |
4765 | | /* rol, ror, rcl, rcr, shl/sal, shr, sar. */ |
4766 | 0 | if ((base_opcode == 0xc1 || (base_opcode | 2) == 0xd3) |
4767 | 0 | && i.tm.extension_opcode != 6) |
4768 | 0 | return 1; |
4769 | | |
4770 | | /* Check for x87 instructions. */ |
4771 | 0 | if ((base_opcode | 6) == 0xdf) |
4772 | 0 | { |
4773 | | /* Skip fst, fstp, fstenv, fstcw. */ |
4774 | 0 | if (i.tm.base_opcode == 0xd9 |
4775 | 0 | && (i.tm.extension_opcode == 2 |
4776 | 0 | || i.tm.extension_opcode == 3 |
4777 | 0 | || i.tm.extension_opcode == 6 |
4778 | 0 | || i.tm.extension_opcode == 7)) |
4779 | 0 | return 0; |
4780 | | |
4781 | | /* Skip fisttp, fist, fistp, fstp. */ |
4782 | 0 | if (i.tm.base_opcode == 0xdb |
4783 | 0 | && (i.tm.extension_opcode == 1 |
4784 | 0 | || i.tm.extension_opcode == 2 |
4785 | 0 | || i.tm.extension_opcode == 3 |
4786 | 0 | || i.tm.extension_opcode == 7)) |
4787 | 0 | return 0; |
4788 | | |
4789 | | /* Skip fisttp, fst, fstp, fsave, fstsw. */ |
4790 | 0 | if (i.tm.base_opcode == 0xdd |
4791 | 0 | && (i.tm.extension_opcode == 1 |
4792 | 0 | || i.tm.extension_opcode == 2 |
4793 | 0 | || i.tm.extension_opcode == 3 |
4794 | 0 | || i.tm.extension_opcode == 6 |
4795 | 0 | || i.tm.extension_opcode == 7)) |
4796 | 0 | return 0; |
4797 | | |
4798 | | /* Skip fisttp, fist, fistp, fbstp, fistp. */ |
4799 | 0 | if (i.tm.base_opcode == 0xdf |
4800 | 0 | && (i.tm.extension_opcode == 1 |
4801 | 0 | || i.tm.extension_opcode == 2 |
4802 | 0 | || i.tm.extension_opcode == 3 |
4803 | 0 | || i.tm.extension_opcode == 6 |
4804 | 0 | || i.tm.extension_opcode == 7)) |
4805 | 0 | return 0; |
4806 | | |
4807 | 0 | return 1; |
4808 | 0 | } |
4809 | 0 | } |
4810 | 0 | else if (i.tm.opcode_space == SPACE_0F) |
4811 | 0 | { |
4812 | | /* bt, bts, btr, btc. */ |
4813 | 0 | if (i.tm.base_opcode == 0xba |
4814 | 0 | && (i.tm.extension_opcode | 3) == 7) |
4815 | 0 | return 1; |
4816 | | |
4817 | | /* cmpxchg8b, cmpxchg16b, xrstors, vmptrld. */ |
4818 | 0 | if (i.tm.base_opcode == 0xc7 |
4819 | 0 | && i.tm.opcode_modifier.opcodeprefix == PREFIX_NONE |
4820 | 0 | && (i.tm.extension_opcode == 1 || i.tm.extension_opcode == 3 |
4821 | 0 | || i.tm.extension_opcode == 6)) |
4822 | 0 | return 1; |
4823 | | |
4824 | | /* fxrstor, ldmxcsr, xrstor. */ |
4825 | 0 | if (i.tm.base_opcode == 0xae |
4826 | 0 | && (i.tm.extension_opcode == 1 |
4827 | 0 | || i.tm.extension_opcode == 2 |
4828 | 0 | || i.tm.extension_opcode == 5)) |
4829 | 0 | return 1; |
4830 | | |
4831 | | /* lgdt, lidt, lmsw. */ |
4832 | 0 | if (i.tm.base_opcode == 0x01 |
4833 | 0 | && (i.tm.extension_opcode == 2 |
4834 | 0 | || i.tm.extension_opcode == 3 |
4835 | 0 | || i.tm.extension_opcode == 6)) |
4836 | 0 | return 1; |
4837 | 0 | } |
4838 | | |
4839 | 0 | dest = i.operands - 1; |
4840 | | |
4841 | | /* Check fake imm8 operand and 3 source operands. */ |
4842 | 0 | if ((i.tm.opcode_modifier.immext |
4843 | 0 | || i.reg_operands + i.mem_operands == 4) |
4844 | 0 | && i.types[dest].bitfield.imm8) |
4845 | 0 | dest--; |
4846 | | |
4847 | | /* add, or, adc, sbb, and, sub, xor, cmp, test, xchg. */ |
4848 | 0 | if (i.tm.opcode_space == SPACE_BASE |
4849 | 0 | && ((base_opcode | 0x38) == 0x39 |
4850 | 0 | || (base_opcode | 2) == 0x87)) |
4851 | 0 | return 1; |
4852 | | |
4853 | 0 | if (i.tm.mnem_off == MN_xadd) |
4854 | 0 | return 1; |
4855 | | |
4856 | | /* Check for load instruction. */ |
4857 | 0 | return (i.types[dest].bitfield.class != ClassNone |
4858 | 0 | || i.types[dest].bitfield.instance == Accum); |
4859 | 0 | } |
4860 | | |
4861 | | /* Output lfence, 0xfaee8, after instruction. */ |
4862 | | |
4863 | | static void |
4864 | | insert_lfence_after (void) |
4865 | 772k | { |
4866 | 772k | if (lfence_after_load && load_insn_p ()) |
4867 | 0 | { |
4868 | | /* There are also two REP string instructions that require |
4869 | | special treatment. Specifically, the compare string (CMPS) |
4870 | | and scan string (SCAS) instructions set EFLAGS in a manner |
4871 | | that depends on the data being compared/scanned. When used |
4872 | | with a REP prefix, the number of iterations may therefore |
4873 | | vary depending on this data. If the data is a program secret |
4874 | | chosen by the adversary using an LVI method, |
4875 | | then this data-dependent behavior may leak some aspect |
4876 | | of the secret. */ |
4877 | 0 | if (((i.tm.base_opcode | 0x9) == 0xaf) |
4878 | 0 | && i.prefix[REP_PREFIX]) |
4879 | 0 | { |
4880 | 0 | as_warn (_("`%s` changes flags which would affect control flow behavior"), |
4881 | 0 | insn_name (&i.tm)); |
4882 | 0 | } |
4883 | 0 | char *p = frag_more (3); |
4884 | 0 | *p++ = 0xf; |
4885 | 0 | *p++ = 0xae; |
4886 | 0 | *p = 0xe8; |
4887 | 0 | } |
4888 | 772k | } |
4889 | | |
4890 | | /* Output lfence, 0xfaee8, before instruction. */ |
4891 | | |
4892 | | static void |
4893 | | insert_lfence_before (void) |
4894 | 772k | { |
4895 | 772k | char *p; |
4896 | | |
4897 | 772k | if (i.tm.opcode_space != SPACE_BASE) |
4898 | 5.91k | return; |
4899 | | |
4900 | 766k | if (i.tm.base_opcode == 0xff |
4901 | 766k | && (i.tm.extension_opcode == 2 || i.tm.extension_opcode == 4)) |
4902 | 90 | { |
4903 | | /* Insert lfence before indirect branch if needed. */ |
4904 | | |
4905 | 90 | if (lfence_before_indirect_branch == lfence_branch_none) |
4906 | 90 | return; |
4907 | | |
4908 | 0 | if (i.operands != 1) |
4909 | 0 | abort (); |
4910 | | |
4911 | 0 | if (i.reg_operands == 1) |
4912 | 0 | { |
4913 | | /* Indirect branch via register. Don't insert lfence with |
4914 | | -mlfence-after-load=yes. */ |
4915 | 0 | if (lfence_after_load |
4916 | 0 | || lfence_before_indirect_branch == lfence_branch_memory) |
4917 | 0 | return; |
4918 | 0 | } |
4919 | 0 | else if (i.mem_operands == 1 |
4920 | 0 | && lfence_before_indirect_branch != lfence_branch_register) |
4921 | 0 | { |
4922 | 0 | as_warn (_("indirect `%s` with memory operand should be avoided"), |
4923 | 0 | insn_name (&i.tm)); |
4924 | 0 | return; |
4925 | 0 | } |
4926 | 0 | else |
4927 | 0 | return; |
4928 | | |
4929 | 0 | if (last_insn.kind != last_insn_other |
4930 | 0 | && last_insn.seg == now_seg) |
4931 | 0 | { |
4932 | 0 | as_warn_where (last_insn.file, last_insn.line, |
4933 | 0 | _("`%s` skips -mlfence-before-indirect-branch on `%s`"), |
4934 | 0 | last_insn.name, insn_name (&i.tm)); |
4935 | 0 | return; |
4936 | 0 | } |
4937 | | |
4938 | 0 | p = frag_more (3); |
4939 | 0 | *p++ = 0xf; |
4940 | 0 | *p++ = 0xae; |
4941 | 0 | *p = 0xe8; |
4942 | 0 | return; |
4943 | 0 | } |
4944 | | |
4945 | | /* Output or/not/shl and lfence before near ret. */ |
4946 | 766k | if (lfence_before_ret != lfence_before_ret_none |
4947 | 766k | && (i.tm.base_opcode | 1) == 0xc3) |
4948 | 0 | { |
4949 | 0 | if (last_insn.kind != last_insn_other |
4950 | 0 | && last_insn.seg == now_seg) |
4951 | 0 | { |
4952 | 0 | as_warn_where (last_insn.file, last_insn.line, |
4953 | 0 | _("`%s` skips -mlfence-before-ret on `%s`"), |
4954 | 0 | last_insn.name, insn_name (&i.tm)); |
4955 | 0 | return; |
4956 | 0 | } |
4957 | | |
4958 | | /* Near ret ingore operand size override under CPU64. */ |
4959 | 0 | char prefix = flag_code == CODE_64BIT |
4960 | 0 | ? 0x48 |
4961 | 0 | : i.prefix[DATA_PREFIX] ? 0x66 : 0x0; |
4962 | |
|
4963 | 0 | if (lfence_before_ret == lfence_before_ret_not) |
4964 | 0 | { |
4965 | | /* not: 0xf71424, may add prefix |
4966 | | for operand size override or 64-bit code. */ |
4967 | 0 | p = frag_more ((prefix ? 2 : 0) + 6 + 3); |
4968 | 0 | if (prefix) |
4969 | 0 | *p++ = prefix; |
4970 | 0 | *p++ = 0xf7; |
4971 | 0 | *p++ = 0x14; |
4972 | 0 | *p++ = 0x24; |
4973 | 0 | if (prefix) |
4974 | 0 | *p++ = prefix; |
4975 | 0 | *p++ = 0xf7; |
4976 | 0 | *p++ = 0x14; |
4977 | 0 | *p++ = 0x24; |
4978 | 0 | } |
4979 | 0 | else |
4980 | 0 | { |
4981 | 0 | p = frag_more ((prefix ? 1 : 0) + 4 + 3); |
4982 | 0 | if (prefix) |
4983 | 0 | *p++ = prefix; |
4984 | 0 | if (lfence_before_ret == lfence_before_ret_or) |
4985 | 0 | { |
4986 | | /* or: 0x830c2400, may add prefix |
4987 | | for operand size override or 64-bit code. */ |
4988 | 0 | *p++ = 0x83; |
4989 | 0 | *p++ = 0x0c; |
4990 | 0 | } |
4991 | 0 | else |
4992 | 0 | { |
4993 | | /* shl: 0xc1242400, may add prefix |
4994 | | for operand size override or 64-bit code. */ |
4995 | 0 | *p++ = 0xc1; |
4996 | 0 | *p++ = 0x24; |
4997 | 0 | } |
4998 | |
|
4999 | 0 | *p++ = 0x24; |
5000 | 0 | *p++ = 0x0; |
5001 | 0 | } |
5002 | |
|
5003 | 0 | *p++ = 0xf; |
5004 | 0 | *p++ = 0xae; |
5005 | 0 | *p = 0xe8; |
5006 | 0 | } |
5007 | 766k | } |
5008 | | |
5009 | | /* Shared helper for md_assemble() and s_insn(). */ |
5010 | | static void init_globals (void) |
5011 | 2.38M | { |
5012 | 2.38M | unsigned int j; |
5013 | | |
5014 | 2.38M | memset (&i, '\0', sizeof (i)); |
5015 | 2.38M | i.rounding.type = rc_none; |
5016 | 14.3M | for (j = 0; j < MAX_OPERANDS; j++) |
5017 | 11.9M | i.reloc[j] = NO_RELOC; |
5018 | 2.38M | memset (disp_expressions, '\0', sizeof (disp_expressions)); |
5019 | 2.38M | memset (im_expressions, '\0', sizeof (im_expressions)); |
5020 | 2.38M | save_stack_p = save_stack; |
5021 | 2.38M | } |
5022 | | |
5023 | | /* Helper for md_assemble() to decide whether to prepare for a possible 2nd |
5024 | | parsing pass. Instead of introducing a rarely use new insn attribute this |
5025 | | utilizes a common pattern between affected templates. It is deemed |
5026 | | acceptable that this will lead to unnecessary pass 2 preparations in a |
5027 | | limited set of cases. */ |
5028 | | static INLINE bool may_need_pass2 (const insn_template *t) |
5029 | 949k | { |
5030 | 949k | return t->opcode_modifier.sse2avx |
5031 | | /* Note that all SSE2AVX templates have at least one operand. */ |
5032 | 949k | ? t->operand_types[t->operands - 1].bitfield.class == RegSIMD |
5033 | 949k | : (t->opcode_space == SPACE_0F |
5034 | 943k | && (t->base_opcode | 1) == 0xbf) |
5035 | 943k | || (t->opcode_space == SPACE_BASE |
5036 | 943k | && t->base_opcode == 0x63); |
5037 | 949k | } |
5038 | | |
5039 | | /* This is the guts of the machine-dependent assembler. LINE points to a |
5040 | | machine dependent instruction. This function is supposed to emit |
5041 | | the frags/bytes it assembles to. */ |
5042 | | |
5043 | | void |
5044 | | md_assemble (char *line) |
5045 | 2.38M | { |
5046 | 2.38M | unsigned int j; |
5047 | 2.38M | char mnemonic[MAX_MNEM_SIZE], mnem_suffix = 0, *copy = NULL; |
5048 | 2.38M | const char *end, *pass1_mnem = NULL; |
5049 | 2.38M | enum i386_error pass1_err = 0; |
5050 | 2.38M | const insn_template *t; |
5051 | | |
5052 | | /* Initialize globals. */ |
5053 | 2.38M | current_templates = NULL; |
5054 | 2.38M | retry: |
5055 | 2.38M | init_globals (); |
5056 | | |
5057 | | /* First parse an instruction mnemonic & call i386_operand for the operands. |
5058 | | We assume that the scrubber has arranged it so that line[0] is the valid |
5059 | | start of a (possibly prefixed) mnemonic. */ |
5060 | | |
5061 | 2.38M | end = parse_insn (line, mnemonic, false); |
5062 | 2.38M | if (end == NULL) |
5063 | 1.44M | { |
5064 | 1.44M | if (pass1_mnem != NULL) |
5065 | 5.32k | goto match_error; |
5066 | 1.44M | if (i.error != no_error) |
5067 | 7.31k | { |
5068 | 7.31k | gas_assert (current_templates != NULL); |
5069 | 7.31k | if (may_need_pass2 (current_templates->start) && !i.suffix) |
5070 | 217 | goto no_match; |
5071 | | /* No point in trying a 2nd pass - it'll only find the same suffix |
5072 | | again. */ |
5073 | 7.09k | mnem_suffix = i.suffix; |
5074 | 7.09k | goto match_error; |
5075 | 7.31k | } |
5076 | 1.43M | return; |
5077 | 1.44M | } |
5078 | 941k | t = current_templates->start; |
5079 | 941k | if (may_need_pass2 (t)) |
5080 | 5.49k | { |
5081 | | /* Make a copy of the full line in case we need to retry. */ |
5082 | 5.49k | copy = xstrdup (line); |
5083 | 5.49k | } |
5084 | 941k | line += end - line; |
5085 | 941k | mnem_suffix = i.suffix; |
5086 | | |
5087 | 941k | line = parse_operands (line, mnemonic); |
5088 | 941k | this_operand = -1; |
5089 | 941k | if (line == NULL) |
5090 | 89.1k | { |
5091 | 89.1k | free (copy); |
5092 | 89.1k | return; |
5093 | 89.1k | } |
5094 | | |
5095 | | /* Now we've parsed the mnemonic into a set of templates, and have the |
5096 | | operands at hand. */ |
5097 | | |
5098 | | /* All Intel opcodes have reversed operands except for "bound", "enter", |
5099 | | "invlpg*", "monitor*", "mwait*", "tpause", "umwait", "pvalidate", |
5100 | | "rmpadjust", "rmpupdate", and "rmpquery". We also don't reverse |
5101 | | intersegment "jmp" and "call" instructions with 2 immediate operands so |
5102 | | that the immediate segment precedes the offset consistently in Intel and |
5103 | | AT&T modes. */ |
5104 | 852k | if (intel_syntax |
5105 | 852k | && i.operands > 1 |
5106 | 852k | && (t->mnem_off != MN_bound) |
5107 | 852k | && !startswith (mnemonic, "invlpg") |
5108 | 852k | && !startswith (mnemonic, "monitor") |
5109 | 852k | && !startswith (mnemonic, "mwait") |
5110 | 852k | && (t->mnem_off != MN_pvalidate) |
5111 | 852k | && !startswith (mnemonic, "rmp") |
5112 | 852k | && (t->mnem_off != MN_tpause) |
5113 | 852k | && (t->mnem_off != MN_umwait) |
5114 | 852k | && !(i.operands == 2 |
5115 | 0 | && operand_type_check (i.types[0], imm) |
5116 | 0 | && operand_type_check (i.types[1], imm))) |
5117 | 0 | swap_operands (); |
5118 | | |
5119 | | /* The order of the immediates should be reversed |
5120 | | for 2 immediates extrq and insertq instructions */ |
5121 | 852k | if (i.imm_operands == 2 |
5122 | 852k | && (t->mnem_off == MN_extrq || t->mnem_off == MN_insertq)) |
5123 | 0 | swap_2_operands (0, 1); |
5124 | | |
5125 | 852k | if (i.imm_operands) |
5126 | 111k | optimize_imm (); |
5127 | | |
5128 | 852k | if (i.disp_operands && !optimize_disp (t)) |
5129 | 0 | return; |
5130 | | |
5131 | | /* Next, we find a template that matches the given insn, |
5132 | | making sure the overlap of the given operands types is consistent |
5133 | | with the template operand types. */ |
5134 | | |
5135 | 852k | if (!(t = match_template (mnem_suffix))) |
5136 | 80.4k | { |
5137 | 80.4k | const char *err_msg; |
5138 | | |
5139 | 80.4k | if (copy && !mnem_suffix) |
5140 | 5.10k | { |
5141 | 5.10k | line = copy; |
5142 | 5.10k | copy = NULL; |
5143 | 5.32k | no_match: |
5144 | 5.32k | pass1_err = i.error; |
5145 | 5.32k | pass1_mnem = insn_name (current_templates->start); |
5146 | 5.32k | goto retry; |
5147 | 5.10k | } |
5148 | | |
5149 | | /* If a non-/only-64bit template (group) was found in pass 1, and if |
5150 | | _some_ template (group) was found in pass 2, squash pass 1's |
5151 | | error. */ |
5152 | 75.3k | if (pass1_err == unsupported_64bit) |
5153 | 0 | pass1_mnem = NULL; |
5154 | | |
5155 | 87.7k | match_error: |
5156 | 87.7k | free (copy); |
5157 | | |
5158 | 87.7k | switch (pass1_mnem ? pass1_err : i.error) |
5159 | 87.7k | { |
5160 | 0 | default: |
5161 | 0 | abort (); |
5162 | 19.8k | case operand_size_mismatch: |
5163 | 19.8k | err_msg = _("operand size mismatch"); |
5164 | 19.8k | break; |
5165 | 3.93k | case operand_type_mismatch: |
5166 | 3.93k | err_msg = _("operand type mismatch"); |
5167 | 3.93k | break; |
5168 | 0 | case register_type_mismatch: |
5169 | 0 | err_msg = _("register type mismatch"); |
5170 | 0 | break; |
5171 | 52.3k | case number_of_operands_mismatch: |
5172 | 52.3k | err_msg = _("number of operands mismatch"); |
5173 | 52.3k | break; |
5174 | 4.20k | case invalid_instruction_suffix: |
5175 | 4.20k | err_msg = _("invalid instruction suffix"); |
5176 | 4.20k | break; |
5177 | 0 | case bad_imm4: |
5178 | 0 | err_msg = _("constant doesn't fit in 4 bits"); |
5179 | 0 | break; |
5180 | 0 | case unsupported_with_intel_mnemonic: |
5181 | 0 | err_msg = _("unsupported with Intel mnemonic"); |
5182 | 0 | break; |
5183 | 0 | case unsupported_syntax: |
5184 | 0 | err_msg = _("unsupported syntax"); |
5185 | 0 | break; |
5186 | 102 | case unsupported: |
5187 | 102 | as_bad (_("unsupported instruction `%s'"), |
5188 | 102 | pass1_mnem ? pass1_mnem : insn_name (current_templates->start)); |
5189 | 102 | return; |
5190 | 3.93k | case unsupported_on_arch: |
5191 | 3.93k | as_bad (_("`%s' is not supported on `%s%s'"), |
5192 | 3.93k | pass1_mnem ? pass1_mnem : insn_name (current_templates->start), |
5193 | 3.93k | cpu_arch_name ? cpu_arch_name : default_arch, |
5194 | 3.93k | cpu_sub_arch_name ? cpu_sub_arch_name : ""); |
5195 | 3.93k | return; |
5196 | 3.37k | case unsupported_64bit: |
5197 | 3.37k | if (ISLOWER (mnem_suffix)) |
5198 | 1.38k | { |
5199 | 1.38k | if (flag_code == CODE_64BIT) |
5200 | 210 | as_bad (_("`%s%c' is not supported in 64-bit mode"), |
5201 | 210 | pass1_mnem ? pass1_mnem : insn_name (current_templates->start), |
5202 | 210 | mnem_suffix); |
5203 | 1.17k | else |
5204 | 1.17k | as_bad (_("`%s%c' is only supported in 64-bit mode"), |
5205 | 1.17k | pass1_mnem ? pass1_mnem : insn_name (current_templates->start), |
5206 | 1.17k | mnem_suffix); |
5207 | 1.38k | } |
5208 | 1.99k | else |
5209 | 1.99k | { |
5210 | 1.99k | if (flag_code == CODE_64BIT) |
5211 | 289 | as_bad (_("`%s' is not supported in 64-bit mode"), |
5212 | 289 | pass1_mnem ? pass1_mnem : insn_name (current_templates->start)); |
5213 | 1.70k | else |
5214 | 1.70k | as_bad (_("`%s' is only supported in 64-bit mode"), |
5215 | 1.70k | pass1_mnem ? pass1_mnem : insn_name (current_templates->start)); |
5216 | 1.99k | } |
5217 | 3.37k | return; |
5218 | 0 | case invalid_sib_address: |
5219 | 0 | err_msg = _("invalid SIB address"); |
5220 | 0 | break; |
5221 | 0 | case invalid_vsib_address: |
5222 | 0 | err_msg = _("invalid VSIB address"); |
5223 | 0 | break; |
5224 | 0 | case invalid_vector_register_set: |
5225 | 0 | err_msg = _("mask, index, and destination registers must be distinct"); |
5226 | 0 | break; |
5227 | 0 | case invalid_tmm_register_set: |
5228 | 0 | err_msg = _("all tmm registers must be distinct"); |
5229 | 0 | break; |
5230 | 0 | case invalid_dest_and_src_register_set: |
5231 | 0 | err_msg = _("destination and source registers must be distinct"); |
5232 | 0 | break; |
5233 | 0 | case unsupported_vector_index_register: |
5234 | 0 | err_msg = _("unsupported vector index register"); |
5235 | 0 | break; |
5236 | 0 | case unsupported_broadcast: |
5237 | 0 | err_msg = _("unsupported broadcast"); |
5238 | 0 | break; |
5239 | 0 | case broadcast_needed: |
5240 | 0 | err_msg = _("broadcast is needed for operand of such type"); |
5241 | 0 | break; |
5242 | 0 | case unsupported_masking: |
5243 | 0 | err_msg = _("unsupported masking"); |
5244 | 0 | break; |
5245 | 0 | case mask_not_on_destination: |
5246 | 0 | err_msg = _("mask not on destination operand"); |
5247 | 0 | break; |
5248 | 0 | case no_default_mask: |
5249 | 0 | err_msg = _("default mask isn't allowed"); |
5250 | 0 | break; |
5251 | 8 | case unsupported_rc_sae: |
5252 | 8 | err_msg = _("unsupported static rounding/sae"); |
5253 | 8 | break; |
5254 | 0 | case invalid_register_operand: |
5255 | 0 | err_msg = _("invalid register operand"); |
5256 | 0 | break; |
5257 | 87.7k | } |
5258 | 80.3k | as_bad (_("%s for `%s'"), err_msg, |
5259 | 80.3k | pass1_mnem ? pass1_mnem : insn_name (current_templates->start)); |
5260 | 80.3k | return; |
5261 | 87.7k | } |
5262 | | |
5263 | 772k | free (copy); |
5264 | | |
5265 | 772k | if (sse_check != check_none |
5266 | | /* The opcode space check isn't strictly needed; it's there only to |
5267 | | bypass the logic below when easily possible. */ |
5268 | 772k | && t->opcode_space >= SPACE_0F |
5269 | 772k | && t->opcode_space <= SPACE_0F3A |
5270 | 772k | && !is_cpu (&i.tm, CpuSSE4a) |
5271 | 772k | && !is_any_vex_encoding (t)) |
5272 | 0 | { |
5273 | 0 | bool simd = false; |
5274 | |
|
5275 | 0 | for (j = 0; j < t->operands; ++j) |
5276 | 0 | { |
5277 | 0 | if (t->operand_types[j].bitfield.class == RegMMX) |
5278 | 0 | break; |
5279 | 0 | if (t->operand_types[j].bitfield.class == RegSIMD) |
5280 | 0 | simd = true; |
5281 | 0 | } |
5282 | |
|
5283 | 0 | if (j >= t->operands && simd) |
5284 | 0 | (sse_check == check_warning |
5285 | 0 | ? as_warn |
5286 | 0 | : as_bad) (_("SSE instruction `%s' is used"), insn_name (&i.tm)); |
5287 | 0 | } |
5288 | | |
5289 | 772k | if (i.tm.opcode_modifier.fwait) |
5290 | 1.86k | if (!add_prefix (FWAIT_OPCODE)) |
5291 | 0 | return; |
5292 | | |
5293 | | /* Check if REP prefix is OK. */ |
5294 | 772k | if (i.rep_prefix && i.tm.opcode_modifier.prefixok != PrefixRep) |
5295 | 0 | { |
5296 | 0 | as_bad (_("invalid instruction `%s' after `%s'"), |
5297 | 0 | insn_name (&i.tm), i.rep_prefix); |
5298 | 0 | return; |
5299 | 0 | } |
5300 | | |
5301 | | /* Check for lock without a lockable instruction. Destination operand |
5302 | | must be memory unless it is xchg (0x86). */ |
5303 | 772k | if (i.prefix[LOCK_PREFIX]) |
5304 | 0 | { |
5305 | 0 | if (i.tm.opcode_modifier.prefixok < PrefixLock |
5306 | 0 | || i.mem_operands == 0 |
5307 | 0 | || (i.tm.base_opcode != 0x86 |
5308 | 0 | && !(i.flags[i.operands - 1] & Operand_Mem))) |
5309 | 0 | { |
5310 | 0 | as_bad (_("expecting lockable instruction after `lock'")); |
5311 | 0 | return; |
5312 | 0 | } |
5313 | | |
5314 | | /* Zap the redundant prefix from XCHG when optimizing. */ |
5315 | 0 | if (i.tm.base_opcode == 0x86 && optimize && !i.no_optimize) |
5316 | 0 | i.prefix[LOCK_PREFIX] = 0; |
5317 | 0 | } |
5318 | | |
5319 | 772k | if (is_any_vex_encoding (&i.tm) |
5320 | 772k | || i.tm.operand_types[i.imm_operands].bitfield.class >= RegMMX |
5321 | 772k | || i.tm.operand_types[i.imm_operands + 1].bitfield.class >= RegMMX) |
5322 | 6 | { |
5323 | | /* Check for data size prefix on VEX/XOP/EVEX encoded and SIMD insns. */ |
5324 | 6 | if (i.prefix[DATA_PREFIX]) |
5325 | 0 | { |
5326 | 0 | as_bad (_("data size prefix invalid with `%s'"), insn_name (&i.tm)); |
5327 | 0 | return; |
5328 | 0 | } |
5329 | | |
5330 | | /* Don't allow e.g. KMOV in TLS code sequences. */ |
5331 | 6 | for (j = i.imm_operands; j < i.operands; ++j) |
5332 | 0 | switch (i.reloc[j]) |
5333 | 0 | { |
5334 | 0 | case BFD_RELOC_386_TLS_GOTIE: |
5335 | 0 | case BFD_RELOC_386_TLS_LE_32: |
5336 | 0 | case BFD_RELOC_X86_64_GOTTPOFF: |
5337 | 0 | case BFD_RELOC_X86_64_TLSLD: |
5338 | 0 | as_bad (_("TLS relocation cannot be used with `%s'"), insn_name (&i.tm)); |
5339 | 0 | return; |
5340 | 0 | default: |
5341 | 0 | break; |
5342 | 0 | } |
5343 | 6 | } |
5344 | | |
5345 | | /* Check if HLE prefix is OK. */ |
5346 | 772k | if (i.hle_prefix && !check_hle ()) |
5347 | 0 | return; |
5348 | | |
5349 | | /* Check BND prefix. */ |
5350 | 772k | if (i.bnd_prefix && !i.tm.opcode_modifier.bndprefixok) |
5351 | 2 | as_bad (_("expecting valid branch instruction after `bnd'")); |
5352 | | |
5353 | | /* Check NOTRACK prefix. */ |
5354 | 772k | if (i.notrack_prefix && i.tm.opcode_modifier.prefixok != PrefixNoTrack) |
5355 | 0 | as_bad (_("expecting indirect branch instruction after `notrack'")); |
5356 | | |
5357 | 772k | if (is_cpu (&i.tm, CpuMPX)) |
5358 | 125 | { |
5359 | 125 | if (flag_code == CODE_64BIT && i.prefix[ADDR_PREFIX]) |
5360 | 0 | as_bad (_("32-bit address isn't allowed in 64-bit MPX instructions.")); |
5361 | 125 | else if (flag_code != CODE_16BIT |
5362 | 125 | ? i.prefix[ADDR_PREFIX] |
5363 | 125 | : i.mem_operands && !i.prefix[ADDR_PREFIX]) |
5364 | 0 | as_bad (_("16-bit address isn't allowed in MPX instructions")); |
5365 | 125 | } |
5366 | | |
5367 | | /* Insert BND prefix. */ |
5368 | 772k | if (add_bnd_prefix && i.tm.opcode_modifier.bndprefixok) |
5369 | 0 | { |
5370 | 0 | if (!i.prefix[BND_PREFIX]) |
5371 | 0 | add_prefix (BND_PREFIX_OPCODE); |
5372 | 0 | else if (i.prefix[BND_PREFIX] != BND_PREFIX_OPCODE) |
5373 | 0 | { |
5374 | 0 | as_warn (_("replacing `rep'/`repe' prefix by `bnd'")); |
5375 | 0 | i.prefix[BND_PREFIX] = BND_PREFIX_OPCODE; |
5376 | 0 | } |
5377 | 0 | } |
5378 | | |
5379 | | /* Check string instruction segment overrides. */ |
5380 | 772k | if (i.tm.opcode_modifier.isstring >= IS_STRING_ES_OP0) |
5381 | 4.52k | { |
5382 | 4.52k | gas_assert (i.mem_operands); |
5383 | 4.52k | if (!check_string ()) |
5384 | 0 | return; |
5385 | 4.52k | i.disp_operands = 0; |
5386 | 4.52k | } |
5387 | | |
5388 | | /* The memory operand of (%dx) should be only used with input/output |
5389 | | instructions (base opcodes: 0x6c, 0x6e, 0xec, 0xee). */ |
5390 | 772k | if (i.input_output_operand |
5391 | 772k | && ((i.tm.base_opcode | 0x82) != 0xee |
5392 | 0 | || i.tm.opcode_space != SPACE_BASE)) |
5393 | 0 | { |
5394 | 0 | as_bad (_("input/output port address isn't allowed with `%s'"), |
5395 | 0 | insn_name (&i.tm)); |
5396 | 0 | return; |
5397 | 0 | } |
5398 | | |
5399 | 772k | if (optimize && !i.no_optimize && i.tm.opcode_modifier.optimize) |
5400 | 0 | optimize_encoding (); |
5401 | | |
5402 | 772k | if (use_unaligned_vector_move) |
5403 | 0 | encode_with_unaligned_vector_move (); |
5404 | | |
5405 | 772k | if (!process_suffix ()) |
5406 | 0 | return; |
5407 | | |
5408 | | /* Check if IP-relative addressing requirements can be satisfied. */ |
5409 | 772k | if (is_cpu (&i.tm, CpuPREFETCHI) |
5410 | 772k | && !(i.base_reg && i.base_reg->reg_num == RegIP)) |
5411 | 0 | as_warn (_("'%s' only supports RIP-relative address"), insn_name (&i.tm)); |
5412 | | |
5413 | | /* Update operand types and check extended states. */ |
5414 | 995k | for (j = 0; j < i.operands; j++) |
5415 | 223k | { |
5416 | 223k | i.types[j] = operand_type_and (i.types[j], i.tm.operand_types[j]); |
5417 | 223k | switch (i.tm.operand_types[j].bitfield.class) |
5418 | 223k | { |
5419 | 223k | default: |
5420 | 223k | break; |
5421 | 223k | case RegMMX: |
5422 | 0 | i.xstate |= xstate_mmx; |
5423 | 0 | break; |
5424 | 0 | case RegMask: |
5425 | 0 | i.xstate |= xstate_mask; |
5426 | 0 | break; |
5427 | 0 | case RegSIMD: |
5428 | 0 | if (i.tm.operand_types[j].bitfield.tmmword) |
5429 | 0 | i.xstate |= xstate_tmm; |
5430 | 0 | else if (i.tm.operand_types[j].bitfield.zmmword) |
5431 | 0 | i.xstate |= xstate_zmm; |
5432 | 0 | else if (i.tm.operand_types[j].bitfield.ymmword) |
5433 | 0 | i.xstate |= xstate_ymm; |
5434 | 0 | else if (i.tm.operand_types[j].bitfield.xmmword) |
5435 | 0 | i.xstate |= xstate_xmm; |
5436 | 0 | break; |
5437 | 223k | } |
5438 | 223k | } |
5439 | | |
5440 | | /* Make still unresolved immediate matches conform to size of immediate |
5441 | | given in i.suffix. */ |
5442 | 772k | if (!finalize_imm ()) |
5443 | 0 | return; |
5444 | | |
5445 | 772k | if (i.types[0].bitfield.imm1) |
5446 | 14 | i.imm_operands = 0; /* kludge for shift insns. */ |
5447 | | |
5448 | | /* For insns with operands there are more diddles to do to the opcode. */ |
5449 | 772k | if (i.operands) |
5450 | 127k | { |
5451 | 127k | if (!process_operands ()) |
5452 | 0 | return; |
5453 | 127k | } |
5454 | 645k | else if (!quiet_warnings && i.tm.opcode_modifier.operandconstraint == UGH) |
5455 | 36 | { |
5456 | | /* UnixWare fsub no args is alias for fsubp, fadd -> faddp, etc. */ |
5457 | 36 | as_warn (_("translating to `%sp'"), insn_name (&i.tm)); |
5458 | 36 | } |
5459 | | |
5460 | 772k | if (is_any_vex_encoding (&i.tm)) |
5461 | 6 | { |
5462 | 6 | if (!cpu_arch_flags.bitfield.cpui286) |
5463 | 0 | { |
5464 | 0 | as_bad (_("instruction `%s' isn't supported outside of protected mode."), |
5465 | 0 | insn_name (&i.tm)); |
5466 | 0 | return; |
5467 | 0 | } |
5468 | | |
5469 | | /* Check for explicit REX prefix. */ |
5470 | 6 | if (i.prefix[REX_PREFIX] || i.rex_encoding) |
5471 | 0 | { |
5472 | 0 | as_bad (_("REX prefix invalid with `%s'"), insn_name (&i.tm)); |
5473 | 0 | return; |
5474 | 0 | } |
5475 | | |
5476 | 6 | if (i.tm.opcode_modifier.vex) |
5477 | 6 | build_vex_prefix (t); |
5478 | 0 | else |
5479 | 0 | build_evex_prefix (); |
5480 | | |
5481 | | /* The individual REX.RXBW bits got consumed. */ |
5482 | 6 | i.rex &= REX_OPCODE; |
5483 | 6 | } |
5484 | | |
5485 | | /* Handle conversion of 'int $3' --> special int3 insn. */ |
5486 | 772k | if (i.tm.mnem_off == MN_int |
5487 | 772k | && i.op[0].imms->X_add_number == 3) |
5488 | 0 | { |
5489 | 0 | i.tm.base_opcode = INT3_OPCODE; |
5490 | 0 | i.imm_operands = 0; |
5491 | 0 | } |
5492 | | |
5493 | 772k | if ((i.tm.opcode_modifier.jump == JUMP |
5494 | 772k | || i.tm.opcode_modifier.jump == JUMP_BYTE |
5495 | 772k | || i.tm.opcode_modifier.jump == JUMP_DWORD) |
5496 | 772k | && i.op[0].disps->X_op == O_constant) |
5497 | 4.58k | { |
5498 | | /* Convert "jmp constant" (and "call constant") to a jump (call) to |
5499 | | the absolute address given by the constant. Since ix86 jumps and |
5500 | | calls are pc relative, we need to generate a reloc. */ |
5501 | 4.58k | i.op[0].disps->X_add_symbol = &abs_symbol; |
5502 | 4.58k | i.op[0].disps->X_op = O_symbol; |
5503 | 4.58k | } |
5504 | | |
5505 | | /* For 8 bit registers we need an empty rex prefix. Also if the |
5506 | | instruction already has a prefix, we need to convert old |
5507 | | registers to new ones. */ |
5508 | | |
5509 | 772k | if ((i.types[0].bitfield.class == Reg && i.types[0].bitfield.byte |
5510 | 772k | && (i.op[0].regs->reg_flags & RegRex64) != 0) |
5511 | 772k | || (i.types[1].bitfield.class == Reg && i.types[1].bitfield.byte |
5512 | 772k | && (i.op[1].regs->reg_flags & RegRex64) != 0) |
5513 | 772k | || (((i.types[0].bitfield.class == Reg && i.types[0].bitfield.byte) |
5514 | 772k | || (i.types[1].bitfield.class == Reg && i.types[1].bitfield.byte)) |
5515 | 772k | && i.rex != 0)) |
5516 | 0 | { |
5517 | 0 | int x; |
5518 | |
|
5519 | 0 | i.rex |= REX_OPCODE; |
5520 | 0 | for (x = 0; x < 2; x++) |
5521 | 0 | { |
5522 | | /* Look for 8 bit operand that uses old registers. */ |
5523 | 0 | if (i.types[x].bitfield.class == Reg && i.types[x].bitfield.byte |
5524 | 0 | && (i.op[x].regs->reg_flags & RegRex64) == 0) |
5525 | 0 | { |
5526 | 0 | gas_assert (!(i.op[x].regs->reg_flags & RegRex)); |
5527 | | /* In case it is "hi" register, give up. */ |
5528 | 0 | if (i.op[x].regs->reg_num > 3) |
5529 | 0 | as_bad (_("can't encode register '%s%s' in an " |
5530 | 0 | "instruction requiring REX prefix."), |
5531 | 0 | register_prefix, i.op[x].regs->reg_name); |
5532 | | |
5533 | | /* Otherwise it is equivalent to the extended register. |
5534 | | Since the encoding doesn't change this is merely |
5535 | | cosmetic cleanup for debug output. */ |
5536 | |
|
5537 | 0 | i.op[x].regs = i.op[x].regs + 8; |
5538 | 0 | } |
5539 | 0 | } |
5540 | 0 | } |
5541 | | |
5542 | 772k | if (i.rex == 0 && i.rex_encoding) |
5543 | 0 | { |
5544 | | /* Check if we can add a REX_OPCODE byte. Look for 8 bit operand |
5545 | | that uses legacy register. If it is "hi" register, don't add |
5546 | | the REX_OPCODE byte. */ |
5547 | 0 | int x; |
5548 | 0 | for (x = 0; x < 2; x++) |
5549 | 0 | if (i.types[x].bitfield.class == Reg |
5550 | 0 | && i.types[x].bitfield.byte |
5551 | 0 | && (i.op[x].regs->reg_flags & RegRex64) == 0 |
5552 | 0 | && i.op[x].regs->reg_num > 3) |
5553 | 0 | { |
5554 | 0 | gas_assert (!(i.op[x].regs->reg_flags & RegRex)); |
5555 | 0 | i.rex_encoding = false; |
5556 | 0 | break; |
5557 | 0 | } |
5558 | |
|
5559 | 0 | if (i.rex_encoding) |
5560 | 0 | i.rex = REX_OPCODE; |
5561 | 0 | } |
5562 | | |
5563 | 772k | if (i.rex != 0) |
5564 | 842 | add_prefix (REX_OPCODE | i.rex); |
5565 | | |
5566 | 772k | insert_lfence_before (); |
5567 | | |
5568 | | /* We are ready to output the insn. */ |
5569 | 772k | output_insn (); |
5570 | | |
5571 | 772k | insert_lfence_after (); |
5572 | | |
5573 | 772k | last_insn.seg = now_seg; |
5574 | | |
5575 | 772k | if (i.tm.opcode_modifier.isprefix) |
5576 | 19.6k | { |
5577 | 19.6k | last_insn.kind = last_insn_prefix; |
5578 | 19.6k | last_insn.name = insn_name (&i.tm); |
5579 | 19.6k | last_insn.file = as_where (&last_insn.line); |
5580 | 19.6k | } |
5581 | 752k | else |
5582 | 752k | last_insn.kind = last_insn_other; |
5583 | 772k | } |
5584 | | |
5585 | | /* The Q suffix is generally valid only in 64-bit mode, with very few |
5586 | | exceptions: fild, fistp, fisttp, and cmpxchg8b. Note that for fild |
5587 | | and fisttp only one of their two templates is matched below: That's |
5588 | | sufficient since other relevant attributes are the same between both |
5589 | | respective templates. */ |
5590 | | static INLINE bool q_suffix_allowed(const insn_template *t) |
5591 | 2.10k | { |
5592 | 2.10k | return flag_code == CODE_64BIT |
5593 | 2.10k | || (t->opcode_space == SPACE_BASE |
5594 | 1.52k | && t->base_opcode == 0xdf |
5595 | 1.52k | && (t->extension_opcode & 1)) /* fild / fistp / fisttp */ |
5596 | 2.10k | || t->mnem_off == MN_cmpxchg8b; |
5597 | 2.10k | } |
5598 | | |
5599 | | static const char * |
5600 | | parse_insn (const char *line, char *mnemonic, bool prefix_only) |
5601 | 2.38M | { |
5602 | 2.38M | const char *l = line, *token_start = l; |
5603 | 2.38M | char *mnem_p; |
5604 | 2.38M | bool pass1 = !current_templates; |
5605 | 2.38M | int supported; |
5606 | 2.38M | const insn_template *t; |
5607 | 2.38M | char *dot_p = NULL; |
5608 | | |
5609 | 2.39M | while (1) |
5610 | 2.39M | { |
5611 | 2.39M | mnem_p = mnemonic; |
5612 | | /* Pseudo-prefixes start with an opening figure brace. */ |
5613 | 2.39M | if ((*mnem_p = *l) == '{') |
5614 | 8.44k | { |
5615 | 8.44k | ++mnem_p; |
5616 | 8.44k | ++l; |
5617 | 8.44k | } |
5618 | 10.1M | while ((*mnem_p = mnemonic_chars[(unsigned char) *l]) != 0) |
5619 | 7.88M | { |
5620 | 7.88M | if (*mnem_p == '.') |
5621 | 33.3k | dot_p = mnem_p; |
5622 | 7.88M | mnem_p++; |
5623 | 7.88M | if (mnem_p >= mnemonic + MAX_MNEM_SIZE) |
5624 | 148k | { |
5625 | 148k | too_long: |
5626 | 148k | as_bad (_("no such instruction: `%s'"), token_start); |
5627 | 148k | return NULL; |
5628 | 148k | } |
5629 | 7.73M | l++; |
5630 | 7.73M | } |
5631 | | /* Pseudo-prefixes end with a closing figure brace. */ |
5632 | 2.25M | if (*mnemonic == '{' && *l == '}') |
5633 | 3.78k | { |
5634 | 3.78k | *mnem_p++ = *l++; |
5635 | 3.78k | if (mnem_p >= mnemonic + MAX_MNEM_SIZE) |
5636 | 0 | goto too_long; |
5637 | 3.78k | *mnem_p = '\0'; |
5638 | | |
5639 | | /* Point l at the closing brace if there's no other separator. */ |
5640 | 3.78k | if (*l != END_OF_INSN && !is_space_char (*l) |
5641 | 3.78k | && *l != PREFIX_SEPARATOR) |
5642 | 1.03k | --l; |
5643 | 3.78k | } |
5644 | 2.24M | else if (!is_space_char (*l) |
5645 | 2.24M | && *l != END_OF_INSN |
5646 | 2.24M | && (intel_syntax |
5647 | 766k | || (*l != PREFIX_SEPARATOR && *l != ','))) |
5648 | 738k | { |
5649 | 738k | if (prefix_only) |
5650 | 32 | break; |
5651 | 738k | as_bad (_("invalid character %s in mnemonic"), |
5652 | 738k | output_invalid (*l)); |
5653 | 738k | return NULL; |
5654 | 738k | } |
5655 | 1.51M | if (token_start == l) |
5656 | 6.02k | { |
5657 | 6.02k | if (!intel_syntax && *l == PREFIX_SEPARATOR) |
5658 | 3.71k | as_bad (_("expecting prefix; got nothing")); |
5659 | 2.30k | else |
5660 | 2.30k | as_bad (_("expecting mnemonic; got nothing")); |
5661 | 6.02k | return NULL; |
5662 | 6.02k | } |
5663 | | |
5664 | | /* Look up instruction (or prefix) via hash table. */ |
5665 | 1.50M | current_templates = (const templates *) str_hash_find (op_hash, mnemonic); |
5666 | | |
5667 | 1.50M | if (*l != END_OF_INSN |
5668 | 1.50M | && (!is_space_char (*l) || l[1] != END_OF_INSN) |
5669 | 1.50M | && current_templates |
5670 | 1.50M | && current_templates->start->opcode_modifier.isprefix) |
5671 | 9.75k | { |
5672 | 9.75k | if (!cpu_flags_check_cpu64 (current_templates->start->cpu)) |
5673 | 40 | { |
5674 | 40 | as_bad ((flag_code != CODE_64BIT |
5675 | 40 | ? _("`%s' is only supported in 64-bit mode") |
5676 | 40 | : _("`%s' is not supported in 64-bit mode")), |
5677 | 40 | insn_name (current_templates->start)); |
5678 | 40 | return NULL; |
5679 | 40 | } |
5680 | | /* If we are in 16-bit mode, do not allow addr16 or data16. |
5681 | | Similarly, in 32-bit mode, do not allow addr32 or data32. */ |
5682 | 9.71k | if ((current_templates->start->opcode_modifier.size == SIZE16 |
5683 | 9.71k | || current_templates->start->opcode_modifier.size == SIZE32) |
5684 | 9.71k | && flag_code != CODE_64BIT |
5685 | 9.71k | && ((current_templates->start->opcode_modifier.size == SIZE32) |
5686 | 163 | ^ (flag_code == CODE_16BIT))) |
5687 | 15 | { |
5688 | 15 | as_bad (_("redundant %s prefix"), |
5689 | 15 | insn_name (current_templates->start)); |
5690 | 15 | return NULL; |
5691 | 15 | } |
5692 | | |
5693 | 9.70k | if (current_templates->start->base_opcode == PSEUDO_PREFIX) |
5694 | 3.70k | { |
5695 | | /* Handle pseudo prefixes. */ |
5696 | 3.70k | switch (current_templates->start->extension_opcode) |
5697 | 3.70k | { |
5698 | 0 | case Prefix_Disp8: |
5699 | | /* {disp8} */ |
5700 | 0 | i.disp_encoding = disp_encoding_8bit; |
5701 | 0 | break; |
5702 | 586 | case Prefix_Disp16: |
5703 | | /* {disp16} */ |
5704 | 586 | i.disp_encoding = disp_encoding_16bit; |
5705 | 586 | break; |
5706 | 711 | case Prefix_Disp32: |
5707 | | /* {disp32} */ |
5708 | 711 | i.disp_encoding = disp_encoding_32bit; |
5709 | 711 | break; |
5710 | 0 | case Prefix_Load: |
5711 | | /* {load} */ |
5712 | 0 | i.dir_encoding = dir_encoding_load; |
5713 | 0 | break; |
5714 | 2.35k | case Prefix_Store: |
5715 | | /* {store} */ |
5716 | 2.35k | i.dir_encoding = dir_encoding_store; |
5717 | 2.35k | break; |
5718 | 0 | case Prefix_VEX: |
5719 | | /* {vex} */ |
5720 | 0 | i.vec_encoding = vex_encoding_vex; |
5721 | 0 | break; |
5722 | 33 | case Prefix_VEX3: |
5723 | | /* {vex3} */ |
5724 | 33 | i.vec_encoding = vex_encoding_vex3; |
5725 | 33 | break; |
5726 | 0 | case Prefix_EVEX: |
5727 | | /* {evex} */ |
5728 | 0 | i.vec_encoding = vex_encoding_evex; |
5729 | 0 | break; |
5730 | 2 | case Prefix_REX: |
5731 | | /* {rex} */ |
5732 | 2 | i.rex_encoding = true; |
5733 | 2 | break; |
5734 | 25 | case Prefix_NoOptimize: |
5735 | | /* {nooptimize} */ |
5736 | 25 | i.no_optimize = true; |
5737 | 25 | break; |
5738 | 0 | default: |
5739 | 0 | abort (); |
5740 | 3.70k | } |
5741 | 3.70k | } |
5742 | 5.99k | else |
5743 | 5.99k | { |
5744 | | /* Add prefix, checking for repeated prefixes. */ |
5745 | 5.99k | switch (add_prefix (current_templates->start->base_opcode)) |
5746 | 5.99k | { |
5747 | 700 | case PREFIX_EXIST: |
5748 | 700 | return NULL; |
5749 | 114 | case PREFIX_DS: |
5750 | 114 | if (is_cpu (current_templates->start, CpuIBT)) |
5751 | 0 | i.notrack_prefix = insn_name (current_templates->start); |
5752 | 114 | break; |
5753 | 661 | case PREFIX_REP: |
5754 | 661 | if (is_cpu (current_templates->start, CpuHLE)) |
5755 | 0 | i.hle_prefix = insn_name (current_templates->start); |
5756 | 661 | else if (is_cpu (current_templates->start, CpuMPX)) |
5757 | 484 | i.bnd_prefix = insn_name (current_templates->start); |
5758 | 177 | else |
5759 | 177 | i.rep_prefix = insn_name (current_templates->start); |
5760 | 661 | break; |
5761 | 4.51k | default: |
5762 | 4.51k | break; |
5763 | 5.99k | } |
5764 | 5.99k | } |
5765 | | /* Skip past PREFIX_SEPARATOR and reset token_start. */ |
5766 | 9.00k | token_start = ++l; |
5767 | 9.00k | } |
5768 | 1.49M | else |
5769 | 1.49M | break; |
5770 | 1.50M | } |
5771 | | |
5772 | 1.49M | if (prefix_only) |
5773 | 32 | return token_start; |
5774 | | |
5775 | 1.49M | if (!current_templates) |
5776 | 553k | { |
5777 | | /* Deprecated functionality (new code should use pseudo-prefixes instead): |
5778 | | Check if we should swap operand or force 32bit displacement in |
5779 | | encoding. */ |
5780 | 553k | if (mnem_p - 2 == dot_p && dot_p[1] == 's') |
5781 | 1.90k | i.dir_encoding = dir_encoding_swap; |
5782 | 551k | else if (mnem_p - 3 == dot_p |
5783 | 551k | && dot_p[1] == 'd' |
5784 | 551k | && dot_p[2] == '8') |
5785 | 110 | i.disp_encoding = disp_encoding_8bit; |
5786 | 551k | else if (mnem_p - 4 == dot_p |
5787 | 551k | && dot_p[1] == 'd' |
5788 | 551k | && dot_p[2] == '3' |
5789 | 551k | && dot_p[3] == '2') |
5790 | 0 | i.disp_encoding = disp_encoding_32bit; |
5791 | 551k | else |
5792 | 551k | goto check_suffix; |
5793 | 2.01k | mnem_p = dot_p; |
5794 | 2.01k | *dot_p = '\0'; |
5795 | 2.01k | current_templates = (const templates *) str_hash_find (op_hash, mnemonic); |
5796 | 2.01k | } |
5797 | | |
5798 | 945k | if (!current_templates || !pass1) |
5799 | 7.07k | { |
5800 | 7.07k | current_templates = NULL; |
5801 | | |
5802 | 558k | check_suffix: |
5803 | 558k | if (mnem_p > mnemonic) |
5804 | 558k | { |
5805 | | /* See if we can get a match by trimming off a suffix. */ |
5806 | 558k | switch (mnem_p[-1]) |
5807 | 558k | { |
5808 | 10.3k | case WORD_MNEM_SUFFIX: |
5809 | 10.3k | if (intel_syntax && (intel_float_operand (mnemonic) & 2)) |
5810 | 0 | i.suffix = SHORT_MNEM_SUFFIX; |
5811 | 10.3k | else |
5812 | | /* Fall through. */ |
5813 | 83.1k | case BYTE_MNEM_SUFFIX: |
5814 | 86.0k | case QWORD_MNEM_SUFFIX: |
5815 | 86.0k | i.suffix = mnem_p[-1]; |
5816 | 86.0k | mnem_p[-1] = '\0'; |
5817 | 86.0k | current_templates |
5818 | 86.0k | = (const templates *) str_hash_find (op_hash, mnemonic); |
5819 | 86.0k | break; |
5820 | 75.0k | case SHORT_MNEM_SUFFIX: |
5821 | 87.8k | case LONG_MNEM_SUFFIX: |
5822 | 87.8k | if (!intel_syntax) |
5823 | 87.8k | { |
5824 | 87.8k | i.suffix = mnem_p[-1]; |
5825 | 87.8k | mnem_p[-1] = '\0'; |
5826 | 87.8k | current_templates |
5827 | 87.8k | = (const templates *) str_hash_find (op_hash, mnemonic); |
5828 | 87.8k | } |
5829 | 87.8k | break; |
5830 | | |
5831 | | /* Intel Syntax. */ |
5832 | 11.4k | case 'd': |
5833 | 11.4k | if (intel_syntax) |
5834 | 0 | { |
5835 | 0 | if (intel_float_operand (mnemonic) == 1) |
5836 | 0 | i.suffix = SHORT_MNEM_SUFFIX; |
5837 | 0 | else |
5838 | 0 | i.suffix = LONG_MNEM_SUFFIX; |
5839 | 0 | mnem_p[-1] = '\0'; |
5840 | 0 | current_templates |
5841 | 0 | = (const templates *) str_hash_find (op_hash, mnemonic); |
5842 | 0 | } |
5843 | | /* For compatibility reasons accept MOVSD and CMPSD without |
5844 | | operands even in AT&T mode. */ |
5845 | 11.4k | else if (*l == END_OF_INSN |
5846 | 11.4k | || (is_space_char (*l) && l[1] == END_OF_INSN)) |
5847 | 7.03k | { |
5848 | 7.03k | mnem_p[-1] = '\0'; |
5849 | 7.03k | current_templates |
5850 | 7.03k | = (const templates *) str_hash_find (op_hash, mnemonic); |
5851 | 7.03k | if (current_templates != NULL |
5852 | | /* MOVS or CMPS */ |
5853 | 7.03k | && (current_templates->start->base_opcode | 2) == 0xa6 |
5854 | 7.03k | && current_templates->start->opcode_space |
5855 | 1 | == SPACE_BASE |
5856 | 7.03k | && mnem_p[-2] == 's') |
5857 | 1 | { |
5858 | 1 | as_warn (_("found `%sd'; assuming `%sl' was meant"), |
5859 | 1 | mnemonic, mnemonic); |
5860 | 1 | i.suffix = LONG_MNEM_SUFFIX; |
5861 | 1 | } |
5862 | 7.03k | else |
5863 | 7.03k | { |
5864 | 7.03k | current_templates = NULL; |
5865 | 7.03k | mnem_p[-1] = 'd'; |
5866 | 7.03k | } |
5867 | 7.03k | } |
5868 | 11.4k | break; |
5869 | 558k | } |
5870 | 558k | } |
5871 | | |
5872 | 558k | if (!current_templates) |
5873 | 544k | { |
5874 | 544k | if (pass1) |
5875 | 539k | as_bad (_("no such instruction: `%s'"), token_start); |
5876 | 544k | return NULL; |
5877 | 544k | } |
5878 | 558k | } |
5879 | | |
5880 | 951k | if (current_templates->start->opcode_modifier.jump == JUMP |
5881 | 951k | || current_templates->start->opcode_modifier.jump == JUMP_BYTE) |
5882 | 31.2k | { |
5883 | | /* Check for a branch hint. We allow ",pt" and ",pn" for |
5884 | | predict taken and predict not taken respectively. |
5885 | | I'm not sure that branch hints actually do anything on loop |
5886 | | and jcxz insns (JumpByte) for current Pentium4 chips. They |
5887 | | may work in the future and it doesn't hurt to accept them |
5888 | | now. */ |
5889 | 31.2k | if (l[0] == ',' && l[1] == 'p') |
5890 | 0 | { |
5891 | 0 | if (l[2] == 't') |
5892 | 0 | { |
5893 | 0 | if (!add_prefix (DS_PREFIX_OPCODE)) |
5894 | 0 | return NULL; |
5895 | 0 | l += 3; |
5896 | 0 | } |
5897 | 0 | else if (l[2] == 'n') |
5898 | 0 | { |
5899 | 0 | if (!add_prefix (CS_PREFIX_OPCODE)) |
5900 | 0 | return NULL; |
5901 | 0 | l += 3; |
5902 | 0 | } |
5903 | 0 | } |
5904 | 31.2k | } |
5905 | | /* Any other comma loses. */ |
5906 | 951k | if (*l == ',') |
5907 | 2.78k | { |
5908 | 2.78k | as_bad (_("invalid character %s in mnemonic"), |
5909 | 2.78k | output_invalid (*l)); |
5910 | 2.78k | return NULL; |
5911 | 2.78k | } |
5912 | | |
5913 | | /* Check if instruction is supported on specified architecture. */ |
5914 | 949k | supported = 0; |
5915 | 967k | for (t = current_templates->start; t < current_templates->end; ++t) |
5916 | 960k | { |
5917 | 960k | supported |= cpu_flags_match (t); |
5918 | | |
5919 | 960k | if (i.suffix == QWORD_MNEM_SUFFIX && !q_suffix_allowed (t)) |
5920 | 1.52k | supported &= ~CPU_FLAGS_64BIT_MATCH; |
5921 | | |
5922 | 960k | if (supported == CPU_FLAGS_PERFECT_MATCH) |
5923 | 941k | return l; |
5924 | 960k | } |
5925 | | |
5926 | 7.34k | if (pass1) |
5927 | 7.31k | { |
5928 | 7.31k | if (supported & CPU_FLAGS_64BIT_MATCH) |
5929 | 3.93k | i.error = unsupported_on_arch; |
5930 | 3.37k | else |
5931 | 3.37k | i.error = unsupported_64bit; |
5932 | 7.31k | } |
5933 | | |
5934 | 7.34k | return NULL; |
5935 | 949k | } |
5936 | | |
5937 | | static char * |
5938 | | parse_operands (char *l, const char *mnemonic) |
5939 | 941k | { |
5940 | 941k | char *token_start; |
5941 | | |
5942 | | /* 1 if operand is pending after ','. */ |
5943 | 941k | unsigned int expecting_operand = 0; |
5944 | | |
5945 | 1.34M | while (*l != END_OF_INSN) |
5946 | 494k | { |
5947 | | /* Non-zero if operand parens not balanced. */ |
5948 | 494k | unsigned int paren_not_balanced = 0; |
5949 | | /* True if inside double quotes. */ |
5950 | 494k | bool in_quotes = false; |
5951 | | |
5952 | | /* Skip optional white space before operand. */ |
5953 | 494k | if (is_space_char (*l)) |
5954 | 289k | ++l; |
5955 | 494k | if (!is_operand_char (*l) && *l != END_OF_INSN && *l != '"') |
5956 | 9.40k | { |
5957 | 9.40k | as_bad (_("invalid character %s before operand %d"), |
5958 | 9.40k | output_invalid (*l), |
5959 | 9.40k | i.operands + 1); |
5960 | 9.40k | return NULL; |
5961 | 9.40k | } |
5962 | 485k | token_start = l; /* After white space. */ |
5963 | 6.15M | while (in_quotes || paren_not_balanced || *l != ',') |
5964 | 5.93M | { |
5965 | 5.93M | if (*l == END_OF_INSN) |
5966 | 242k | { |
5967 | 242k | if (in_quotes) |
5968 | 29.4k | { |
5969 | 29.4k | as_bad (_("unbalanced double quotes in operand %d."), |
5970 | 29.4k | i.operands + 1); |
5971 | 29.4k | return NULL; |
5972 | 29.4k | } |
5973 | 213k | if (paren_not_balanced) |
5974 | 3.50k | { |
5975 | 3.50k | know (!intel_syntax); |
5976 | 3.50k | as_bad (_("unbalanced parenthesis in operand %d."), |
5977 | 3.50k | i.operands + 1); |
5978 | 3.50k | return NULL; |
5979 | 3.50k | } |
5980 | 210k | else |
5981 | 210k | break; /* we are done */ |
5982 | 213k | } |
5983 | 5.68M | else if (*l == '\\' && l[1] == '"') |
5984 | 0 | ++l; |
5985 | 5.68M | else if (*l == '"') |
5986 | 89.6k | in_quotes = !in_quotes; |
5987 | 5.59M | else if (!in_quotes && !is_operand_char (*l) && !is_space_char (*l)) |
5988 | 19.2k | { |
5989 | 19.2k | as_bad (_("invalid character %s in operand %d"), |
5990 | 19.2k | output_invalid (*l), |
5991 | 19.2k | i.operands + 1); |
5992 | 19.2k | return NULL; |
5993 | 19.2k | } |
5994 | 5.66M | if (!intel_syntax && !in_quotes) |
5995 | 2.87M | { |
5996 | 2.87M | if (*l == '(') |
5997 | 5.86k | ++paren_not_balanced; |
5998 | 2.87M | if (*l == ')') |
5999 | 5.05k | --paren_not_balanced; |
6000 | 2.87M | } |
6001 | 5.66M | l++; |
6002 | 5.66M | } |
6003 | 432k | if (l != token_start) |
6004 | 423k | { /* Yes, we've read in another operand. */ |
6005 | 423k | unsigned int operand_ok; |
6006 | 423k | this_operand = i.operands++; |
6007 | 423k | if (i.operands > MAX_OPERANDS) |
6008 | 0 | { |
6009 | 0 | as_bad (_("spurious operands; (%d operands/instruction max)"), |
6010 | 0 | MAX_OPERANDS); |
6011 | 0 | return NULL; |
6012 | 0 | } |
6013 | 423k | i.types[this_operand].bitfield.unspecified = 1; |
6014 | | /* Now parse operand adding info to 'i' as we go along. */ |
6015 | 423k | END_STRING_AND_SAVE (l); |
6016 | | |
6017 | 423k | if (i.mem_operands > 1) |
6018 | 2.15k | { |
6019 | 2.15k | as_bad (_("too many memory references for `%s'"), |
6020 | 2.15k | mnemonic); |
6021 | 2.15k | return 0; |
6022 | 2.15k | } |
6023 | | |
6024 | 421k | if (intel_syntax) |
6025 | 0 | operand_ok = |
6026 | 0 | i386_intel_operand (token_start, |
6027 | 0 | intel_float_operand (mnemonic)); |
6028 | 421k | else |
6029 | 421k | operand_ok = i386_att_operand (token_start); |
6030 | | |
6031 | 421k | RESTORE_END_STRING (l); |
6032 | 421k | if (!operand_ok) |
6033 | 22.6k | return NULL; |
6034 | 421k | } |
6035 | 9.71k | else |
6036 | 9.71k | { |
6037 | 9.71k | if (expecting_operand) |
6038 | 383 | { |
6039 | 2.62k | expecting_operand_after_comma: |
6040 | 2.62k | as_bad (_("expecting operand after ','; got nothing")); |
6041 | 2.62k | return NULL; |
6042 | 383 | } |
6043 | 9.33k | if (*l == ',') |
6044 | 85 | { |
6045 | 85 | as_bad (_("expecting operand before ','; got nothing")); |
6046 | 85 | return NULL; |
6047 | 85 | } |
6048 | 9.33k | } |
6049 | | |
6050 | | /* Now *l must be either ',' or END_OF_INSN. */ |
6051 | 407k | if (*l == ',') |
6052 | 207k | { |
6053 | 207k | if (*++l == END_OF_INSN) |
6054 | 2.24k | { |
6055 | | /* Just skip it, if it's \n complain. */ |
6056 | 2.24k | goto expecting_operand_after_comma; |
6057 | 2.24k | } |
6058 | 205k | expecting_operand = 1; |
6059 | 205k | } |
6060 | 407k | } |
6061 | 852k | return l; |
6062 | 941k | } |
6063 | | |
6064 | | static void |
6065 | | swap_2_operands (unsigned int xchg1, unsigned int xchg2) |
6066 | 0 | { |
6067 | 0 | union i386_op temp_op; |
6068 | 0 | i386_operand_type temp_type; |
6069 | 0 | unsigned int temp_flags; |
6070 | 0 | enum bfd_reloc_code_real temp_reloc; |
6071 | |
|
6072 | 0 | temp_type = i.types[xchg2]; |
6073 | 0 | i.types[xchg2] = i.types[xchg1]; |
6074 | 0 | i.types[xchg1] = temp_type; |
6075 | |
|
6076 | 0 | temp_flags = i.flags[xchg2]; |
6077 | 0 | i.flags[xchg2] = i.flags[xchg1]; |
6078 | 0 | i.flags[xchg1] = temp_flags; |
6079 | |
|
6080 | 0 | temp_op = i.op[xchg2]; |
6081 | 0 | i.op[xchg2] = i.op[xchg1]; |
6082 | 0 | i.op[xchg1] = temp_op; |
6083 | |
|
6084 | 0 | temp_reloc = i.reloc[xchg2]; |
6085 | 0 | i.reloc[xchg2] = i.reloc[xchg1]; |
6086 | 0 | i.reloc[xchg1] = temp_reloc; |
6087 | |
|
6088 | 0 | temp_flags = i.imm_bits[xchg2]; |
6089 | 0 | i.imm_bits[xchg2] = i.imm_bits[xchg1]; |
6090 | 0 | i.imm_bits[xchg1] = temp_flags; |
6091 | |
|
6092 | 0 | if (i.mask.reg) |
6093 | 0 | { |
6094 | 0 | if (i.mask.operand == xchg1) |
6095 | 0 | i.mask.operand = xchg2; |
6096 | 0 | else if (i.mask.operand == xchg2) |
6097 | 0 | i.mask.operand = xchg1; |
6098 | 0 | } |
6099 | 0 | if (i.broadcast.type || i.broadcast.bytes) |
6100 | 0 | { |
6101 | 0 | if (i.broadcast.operand == xchg1) |
6102 | 0 | i.broadcast.operand = xchg2; |
6103 | 0 | else if (i.broadcast.operand == xchg2) |
6104 | 0 | i.broadcast.operand = xchg1; |
6105 | 0 | } |
6106 | 0 | } |
6107 | | |
6108 | | static void |
6109 | | swap_operands (void) |
6110 | 0 | { |
6111 | 0 | switch (i.operands) |
6112 | 0 | { |
6113 | 0 | case 5: |
6114 | 0 | case 4: |
6115 | 0 | swap_2_operands (1, i.operands - 2); |
6116 | | /* Fall through. */ |
6117 | 0 | case 3: |
6118 | 0 | case 2: |
6119 | 0 | swap_2_operands (0, i.operands - 1); |
6120 | 0 | break; |
6121 | 0 | default: |
6122 | 0 | abort (); |
6123 | 0 | } |
6124 | | |
6125 | 0 | if (i.mem_operands == 2) |
6126 | 0 | { |
6127 | 0 | const reg_entry *temp_seg; |
6128 | 0 | temp_seg = i.seg[0]; |
6129 | 0 | i.seg[0] = i.seg[1]; |
6130 | 0 | i.seg[1] = temp_seg; |
6131 | 0 | } |
6132 | 0 | } |
6133 | | |
6134 | | /* Try to ensure constant immediates are represented in the smallest |
6135 | | opcode possible. */ |
6136 | | static void |
6137 | | optimize_imm (void) |
6138 | 111k | { |
6139 | 111k | char guess_suffix = 0; |
6140 | 111k | int op; |
6141 | | |
6142 | 111k | if (i.suffix) |
6143 | 2.46k | guess_suffix = i.suffix; |
6144 | 108k | else if (i.reg_operands) |
6145 | 0 | { |
6146 | | /* Figure out a suffix from the last register operand specified. |
6147 | | We can't do this properly yet, i.e. excluding special register |
6148 | | instances, but the following works for instructions with |
6149 | | immediates. In any case, we can't set i.suffix yet. */ |
6150 | 0 | for (op = i.operands; --op >= 0;) |
6151 | 0 | if (i.types[op].bitfield.class != Reg) |
6152 | 0 | continue; |
6153 | 0 | else if (i.types[op].bitfield.byte) |
6154 | 0 | { |
6155 | 0 | guess_suffix = BYTE_MNEM_SUFFIX; |
6156 | 0 | break; |
6157 | 0 | } |
6158 | 0 | else if (i.types[op].bitfield.word) |
6159 | 0 | { |
6160 | 0 | guess_suffix = WORD_MNEM_SUFFIX; |
6161 | 0 | break; |
6162 | 0 | } |
6163 | 0 | else if (i.types[op].bitfield.dword) |
6164 | 0 | { |
6165 | 0 | guess_suffix = LONG_MNEM_SUFFIX; |
6166 | 0 | break; |
6167 | 0 | } |
6168 | 0 | else if (i.types[op].bitfield.qword) |
6169 | 0 | { |
6170 | 0 | guess_suffix = QWORD_MNEM_SUFFIX; |
6171 | 0 | break; |
6172 | 0 | } |
6173 | 0 | } |
6174 | 108k | else if ((flag_code == CODE_16BIT) ^ (i.prefix[DATA_PREFIX] != 0)) |
6175 | 52.4k | guess_suffix = WORD_MNEM_SUFFIX; |
6176 | 56.4k | else if (flag_code != CODE_64BIT || !(i.prefix[REX_PREFIX] & REX_W)) |
6177 | 56.4k | guess_suffix = LONG_MNEM_SUFFIX; |
6178 | | |
6179 | 326k | for (op = i.operands; --op >= 0;) |
6180 | 214k | if (operand_type_check (i.types[op], imm)) |
6181 | 111k | { |
6182 | 111k | switch (i.op[op].imms->X_op) |
6183 | 111k | { |
6184 | 94.7k | case O_constant: |
6185 | | /* If a suffix is given, this operand may be shortened. */ |
6186 | 94.7k | switch (guess_suffix) |
6187 | 94.7k | { |
6188 | 48.9k | case LONG_MNEM_SUFFIX: |
6189 | 48.9k | i.types[op].bitfield.imm32 = 1; |
6190 | 48.9k | i.types[op].bitfield.imm64 = 1; |
6191 | 48.9k | break; |
6192 | 44.2k | case WORD_MNEM_SUFFIX: |
6193 | 44.2k | i.types[op].bitfield.imm16 = 1; |
6194 | 44.2k | i.types[op].bitfield.imm32 = 1; |
6195 | 44.2k | i.types[op].bitfield.imm32s = 1; |
6196 | 44.2k | i.types[op].bitfield.imm64 = 1; |
6197 | 44.2k | break; |
6198 | 1.53k | case BYTE_MNEM_SUFFIX: |
6199 | 1.53k | i.types[op].bitfield.imm8 = 1; |
6200 | 1.53k | i.types[op].bitfield.imm8s = 1; |
6201 | 1.53k | i.types[op].bitfield.imm16 = 1; |
6202 | 1.53k | i.types[op].bitfield.imm32 = 1; |
6203 | 1.53k | i.types[op].bitfield.imm32s = 1; |
6204 | 1.53k | i.types[op].bitfield.imm64 = 1; |
6205 | 1.53k | break; |
6206 | 94.7k | } |
6207 | | |
6208 | | /* If this operand is at most 16 bits, convert it |
6209 | | to a signed 16 bit number before trying to see |
6210 | | whether it will fit in an even smaller size. |
6211 | | This allows a 16-bit operand such as $0xffe0 to |
6212 | | be recognised as within Imm8S range. */ |
6213 | 94.7k | if ((i.types[op].bitfield.imm16) |
6214 | 94.7k | && fits_in_unsigned_word (i.op[op].imms->X_add_number)) |
6215 | 41.9k | { |
6216 | 41.9k | i.op[op].imms->X_add_number = ((i.op[op].imms->X_add_number |
6217 | 41.9k | ^ 0x8000) - 0x8000); |
6218 | 41.9k | } |
6219 | 94.7k | #ifdef BFD64 |
6220 | | /* Store 32-bit immediate in 64-bit for 64-bit BFD. */ |
6221 | 94.7k | if ((i.types[op].bitfield.imm32) |
6222 | 94.7k | && fits_in_unsigned_long (i.op[op].imms->X_add_number)) |
6223 | 87.7k | { |
6224 | 87.7k | i.op[op].imms->X_add_number = ((i.op[op].imms->X_add_number |
6225 | 87.7k | ^ ((offsetT) 1 << 31)) |
6226 | 87.7k | - ((offsetT) 1 << 31)); |
6227 | 87.7k | } |
6228 | 94.7k | #endif |
6229 | 94.7k | i.types[op] |
6230 | 94.7k | = operand_type_or (i.types[op], |
6231 | 94.7k | smallest_imm_type (i.op[op].imms->X_add_number)); |
6232 | | |
6233 | | /* We must avoid matching of Imm32 templates when 64bit |
6234 | | only immediate is available. */ |
6235 | 94.7k | if (guess_suffix == QWORD_MNEM_SUFFIX) |
6236 | 0 | i.types[op].bitfield.imm32 = 0; |
6237 | 94.7k | break; |
6238 | | |
6239 | 0 | case O_absent: |
6240 | 0 | case O_register: |
6241 | 0 | abort (); |
6242 | | |
6243 | | /* Symbols and expressions. */ |
6244 | 16.9k | default: |
6245 | | /* Convert symbolic operand to proper sizes for matching, but don't |
6246 | | prevent matching a set of insns that only supports sizes other |
6247 | | than those matching the insn suffix. */ |
6248 | 16.9k | { |
6249 | 16.9k | i386_operand_type mask, allowed; |
6250 | 16.9k | const insn_template *t = current_templates->start; |
6251 | | |
6252 | 16.9k | operand_type_set (&mask, 0); |
6253 | 16.9k | switch (guess_suffix) |
6254 | 16.9k | { |
6255 | 32 | case QWORD_MNEM_SUFFIX: |
6256 | 32 | mask.bitfield.imm64 = 1; |
6257 | 32 | mask.bitfield.imm32s = 1; |
6258 | 32 | break; |
6259 | 8.11k | case LONG_MNEM_SUFFIX: |
6260 | 8.11k | mask.bitfield.imm32 = 1; |
6261 | 8.11k | break; |
6262 | 8.44k | case WORD_MNEM_SUFFIX: |
6263 | 8.44k | mask.bitfield.imm16 = 1; |
6264 | 8.44k | break; |
6265 | 335 | case BYTE_MNEM_SUFFIX: |
6266 | 335 | mask.bitfield.imm8 = 1; |
6267 | 335 | break; |
6268 | 0 | default: |
6269 | 0 | break; |
6270 | 16.9k | } |
6271 | | |
6272 | 16.9k | allowed = operand_type_and (t->operand_types[op], mask); |
6273 | 123k | while (++t < current_templates->end) |
6274 | 106k | { |
6275 | 106k | allowed = operand_type_or (allowed, t->operand_types[op]); |
6276 | 106k | allowed = operand_type_and (allowed, mask); |
6277 | 106k | } |
6278 | | |
6279 | 16.9k | if (!operand_type_all_zero (&allowed)) |
6280 | 10.1k | i.types[op] = operand_type_and (i.types[op], mask); |
6281 | 16.9k | } |
6282 | 0 | break; |
6283 | 111k | } |
6284 | 111k | } |
6285 | 111k | } |
6286 | | |
6287 | | /* Try to use the smallest displacement type too. */ |
6288 | | static bool |
6289 | | optimize_disp (const insn_template *t) |
6290 | 180k | { |
6291 | 180k | unsigned int op; |
6292 | | |
6293 | 180k | if (!want_disp32 (t) |
6294 | 180k | && (!t->opcode_modifier.jump |
6295 | 65.6k | || i.jumpabsolute || i.types[0].bitfield.baseindex)) |
6296 | 53.3k | { |
6297 | 144k | for (op = 0; op < i.operands; ++op) |
6298 | 91.5k | { |
6299 | 91.5k | const expressionS *exp = i.op[op].disps; |
6300 | | |
6301 | 91.5k | if (!operand_type_check (i.types[op], disp)) |
6302 | 31.1k | continue; |
6303 | | |
6304 | 60.3k | if (exp->X_op != O_constant) |
6305 | 25.4k | continue; |
6306 | | |
6307 | | /* Since displacement is signed extended to 64bit, don't allow |
6308 | | disp32 if it is out of range. */ |
6309 | 34.8k | if (fits_in_signed_long (exp->X_add_number)) |
6310 | 34.7k | continue; |
6311 | | |
6312 | 137 | i.types[op].bitfield.disp32 = 0; |
6313 | 137 | if (i.types[op].bitfield.baseindex) |
6314 | 0 | { |
6315 | 0 | as_bad (_("0x%" PRIx64 " out of range of signed 32bit displacement"), |
6316 | 0 | (uint64_t) exp->X_add_number); |
6317 | 0 | return false; |
6318 | 0 | } |
6319 | 137 | } |
6320 | 53.3k | } |
6321 | | |
6322 | | /* Don't optimize displacement for movabs since it only takes 64bit |
6323 | | displacement. */ |
6324 | 180k | if (i.disp_encoding > disp_encoding_8bit |
6325 | 180k | || (flag_code == CODE_64BIT && t->mnem_off == MN_movabs)) |
6326 | 178 | return true; |
6327 | | |
6328 | 482k | for (op = i.operands; op-- > 0;) |
6329 | 302k | if (operand_type_check (i.types[op], disp)) |
6330 | 202k | { |
6331 | 202k | if (i.op[op].disps->X_op == O_constant) |
6332 | 119k | { |
6333 | 119k | offsetT op_disp = i.op[op].disps->X_add_number; |
6334 | | |
6335 | 119k | if (!op_disp && i.types[op].bitfield.baseindex) |
6336 | 0 | { |
6337 | 0 | i.types[op] = operand_type_and_not (i.types[op], anydisp); |
6338 | 0 | i.op[op].disps = NULL; |
6339 | 0 | i.disp_operands--; |
6340 | 0 | continue; |
6341 | 0 | } |
6342 | | |
6343 | 119k | if (i.types[op].bitfield.disp16 |
6344 | 119k | && fits_in_unsigned_word (op_disp)) |
6345 | 28.8k | { |
6346 | | /* If this operand is at most 16 bits, convert |
6347 | | to a signed 16 bit number and don't use 64bit |
6348 | | displacement. */ |
6349 | 28.8k | op_disp = ((op_disp ^ 0x8000) - 0x8000); |
6350 | 28.8k | i.types[op].bitfield.disp64 = 0; |
6351 | 28.8k | } |
6352 | | |
6353 | 119k | #ifdef BFD64 |
6354 | | /* Optimize 64-bit displacement to 32-bit for 64-bit BFD. */ |
6355 | 119k | if ((flag_code != CODE_64BIT |
6356 | 119k | ? i.types[op].bitfield.disp32 |
6357 | 119k | : want_disp32 (t) |
6358 | 37.2k | && (!t->opcode_modifier.jump |
6359 | 152 | || i.jumpabsolute || i.types[op].bitfield.baseindex)) |
6360 | 119k | && fits_in_unsigned_long (op_disp)) |
6361 | 16.3k | { |
6362 | | /* If this operand is at most 32 bits, convert |
6363 | | to a signed 32 bit number and don't use 64bit |
6364 | | displacement. */ |
6365 | 16.3k | op_disp = (op_disp ^ ((offsetT) 1 << 31)) - ((addressT) 1 << 31); |
6366 | 16.3k | i.types[op].bitfield.disp64 = 0; |
6367 | 16.3k | i.types[op].bitfield.disp32 = 1; |
6368 | 16.3k | } |
6369 | | |
6370 | 119k | if (flag_code == CODE_64BIT && fits_in_signed_long (op_disp)) |
6371 | 36.9k | { |
6372 | 36.9k | i.types[op].bitfield.disp64 = 0; |
6373 | 36.9k | i.types[op].bitfield.disp32 = 1; |
6374 | 36.9k | } |
6375 | 119k | #endif |
6376 | 119k | if ((i.types[op].bitfield.disp32 |
6377 | 119k | || i.types[op].bitfield.disp16) |
6378 | 119k | && fits_in_disp8 (op_disp)) |
6379 | 104k | i.types[op].bitfield.disp8 = 1; |
6380 | | |
6381 | 119k | i.op[op].disps->X_add_number = op_disp; |
6382 | 119k | } |
6383 | 82.4k | else if (i.reloc[op] == BFD_RELOC_386_TLS_DESC_CALL |
6384 | 82.4k | || i.reloc[op] == BFD_RELOC_X86_64_TLSDESC_CALL) |
6385 | 0 | { |
6386 | 0 | fix_new_exp (frag_now, frag_more (0) - frag_now->fr_literal, 0, |
6387 | 0 | i.op[op].disps, 0, i.reloc[op]); |
6388 | 0 | i.types[op] = operand_type_and_not (i.types[op], anydisp); |
6389 | 0 | } |
6390 | 82.4k | else |
6391 | | /* We only support 64bit displacement on constants. */ |
6392 | 82.4k | i.types[op].bitfield.disp64 = 0; |
6393 | 202k | } |
6394 | | |
6395 | 179k | return true; |
6396 | 180k | } |
6397 | | |
6398 | | /* Return 1 if there is a match in broadcast bytes between operand |
6399 | | GIVEN and instruction template T. */ |
6400 | | |
6401 | | static INLINE int |
6402 | | match_broadcast_size (const insn_template *t, unsigned int given) |
6403 | 0 | { |
6404 | 0 | return ((t->opcode_modifier.broadcast == BYTE_BROADCAST |
6405 | 0 | && i.types[given].bitfield.byte) |
6406 | 0 | || (t->opcode_modifier.broadcast == WORD_BROADCAST |
6407 | 0 | && i.types[given].bitfield.word) |
6408 | 0 | || (t->opcode_modifier.broadcast == DWORD_BROADCAST |
6409 | 0 | && i.types[given].bitfield.dword) |
6410 | 0 | || (t->opcode_modifier.broadcast == QWORD_BROADCAST |
6411 | 0 | && i.types[given].bitfield.qword)); |
6412 | 0 | } |
6413 | | |
6414 | | /* Check if operands are valid for the instruction. */ |
6415 | | |
6416 | | static int |
6417 | | check_VecOperands (const insn_template *t) |
6418 | 127k | { |
6419 | 127k | unsigned int op; |
6420 | 127k | i386_cpu_flags cpu; |
6421 | | |
6422 | | /* Templates allowing for ZMMword as well as YMMword and/or XMMword for |
6423 | | any one operand are implicity requiring AVX512VL support if the actual |
6424 | | operand size is YMMword or XMMword. Since this function runs after |
6425 | | template matching, there's no need to check for YMMword/XMMword in |
6426 | | the template. */ |
6427 | 127k | cpu = cpu_flags_and (cpu_flags_from_attr (t->cpu), avx512); |
6428 | 127k | if (!cpu_flags_all_zero (&cpu) |
6429 | 127k | && !is_cpu (t, CpuAVX512VL) |
6430 | 127k | && !cpu_arch_flags.bitfield.cpuavx512vl) |
6431 | 0 | { |
6432 | 0 | for (op = 0; op < t->operands; ++op) |
6433 | 0 | { |
6434 | 0 | if (t->operand_types[op].bitfield.zmmword |
6435 | 0 | && (i.types[op].bitfield.ymmword |
6436 | 0 | || i.types[op].bitfield.xmmword)) |
6437 | 0 | { |
6438 | 0 | i.error = unsupported; |
6439 | 0 | return 1; |
6440 | 0 | } |
6441 | 0 | } |
6442 | 0 | } |
6443 | | |
6444 | | /* Somewhat similarly, templates specifying both AVX and AVX2 are |
6445 | | requiring AVX2 support if the actual operand size is YMMword. */ |
6446 | 127k | if (is_cpu (t, CpuAVX) && is_cpu (t, CpuAVX2) |
6447 | 127k | && !cpu_arch_flags.bitfield.cpuavx2) |
6448 | 0 | { |
6449 | 0 | for (op = 0; op < t->operands; ++op) |
6450 | 0 | { |
6451 | 0 | if (t->operand_types[op].bitfield.xmmword |
6452 | 0 | && i.types[op].bitfield.ymmword) |
6453 | 0 | { |
6454 | 0 | i.error = unsupported; |
6455 | 0 | return 1; |
6456 | 0 | } |
6457 | 0 | } |
6458 | 0 | } |
6459 | | |
6460 | | /* Without VSIB byte, we can't have a vector register for index. */ |
6461 | 127k | if (!t->opcode_modifier.sib |
6462 | 127k | && i.index_reg |
6463 | 127k | && (i.index_reg->reg_type.bitfield.xmmword |
6464 | 0 | || i.index_reg->reg_type.bitfield.ymmword |
6465 | 0 | || i.index_reg->reg_type.bitfield.zmmword)) |
6466 | 0 | { |
6467 | 0 | i.error = unsupported_vector_index_register; |
6468 | 0 | return 1; |
6469 | 0 | } |
6470 | | |
6471 | | /* Check if default mask is allowed. */ |
6472 | 127k | if (t->opcode_modifier.operandconstraint == NO_DEFAULT_MASK |
6473 | 127k | && (!i.mask.reg || i.mask.reg->reg_num == 0)) |
6474 | 0 | { |
6475 | 0 | i.error = no_default_mask; |
6476 | 0 | return 1; |
6477 | 0 | } |
6478 | | |
6479 | | /* For VSIB byte, we need a vector register for index, and all vector |
6480 | | registers must be distinct. */ |
6481 | 127k | if (t->opcode_modifier.sib && t->opcode_modifier.sib != SIBMEM) |
6482 | 0 | { |
6483 | 0 | if (!i.index_reg |
6484 | 0 | || !((t->opcode_modifier.sib == VECSIB128 |
6485 | 0 | && i.index_reg->reg_type.bitfield.xmmword) |
6486 | 0 | || (t->opcode_modifier.sib == VECSIB256 |
6487 | 0 | && i.index_reg->reg_type.bitfield.ymmword) |
6488 | 0 | || (t->opcode_modifier.sib == VECSIB512 |
6489 | 0 | && i.index_reg->reg_type.bitfield.zmmword))) |
6490 | 0 | { |
6491 | 0 | i.error = invalid_vsib_address; |
6492 | 0 | return 1; |
6493 | 0 | } |
6494 | | |
6495 | 0 | gas_assert (i.reg_operands == 2 || i.mask.reg); |
6496 | 0 | if (i.reg_operands == 2 && !i.mask.reg) |
6497 | 0 | { |
6498 | 0 | gas_assert (i.types[0].bitfield.class == RegSIMD); |
6499 | 0 | gas_assert (i.types[0].bitfield.xmmword |
6500 | 0 | || i.types[0].bitfield.ymmword); |
6501 | 0 | gas_assert (i.types[2].bitfield.class == RegSIMD); |
6502 | 0 | gas_assert (i.types[2].bitfield.xmmword |
6503 | 0 | || i.types[2].bitfield.ymmword); |
6504 | 0 | if (operand_check == check_none) |
6505 | 0 | return 0; |
6506 | 0 | if (register_number (i.op[0].regs) |
6507 | 0 | != register_number (i.index_reg) |
6508 | 0 | && register_number (i.op[2].regs) |
6509 | 0 | != register_number (i.index_reg) |
6510 | 0 | && register_number (i.op[0].regs) |
6511 | 0 | != register_number (i.op[2].regs)) |
6512 | 0 | return 0; |
6513 | 0 | if (operand_check == check_error) |
6514 | 0 | { |
6515 | 0 | i.error = invalid_vector_register_set; |
6516 | 0 | return 1; |
6517 | 0 | } |
6518 | 0 | as_warn (_("mask, index, and destination registers should be distinct")); |
6519 | 0 | } |
6520 | 0 | else if (i.reg_operands == 1 && i.mask.reg) |
6521 | 0 | { |
6522 | 0 | if (i.types[1].bitfield.class == RegSIMD |
6523 | 0 | && (i.types[1].bitfield.xmmword |
6524 | 0 | || i.types[1].bitfield.ymmword |
6525 | 0 | || i.types[1].bitfield.zmmword) |
6526 | 0 | && (register_number (i.op[1].regs) |
6527 | 0 | == register_number (i.index_reg))) |
6528 | 0 | { |
6529 | 0 | if (operand_check == check_error) |
6530 | 0 | { |
6531 | 0 | i.error = invalid_vector_register_set; |
6532 | 0 | return 1; |
6533 | 0 | } |
6534 | 0 | if (operand_check != check_none) |
6535 | 0 | as_warn (_("index and destination registers should be distinct")); |
6536 | 0 | } |
6537 | 0 | } |
6538 | 0 | } |
6539 | | |
6540 | | /* For AMX instructions with 3 TMM register operands, all operands |
6541 | | must be distinct. */ |
6542 | 127k | if (i.reg_operands == 3 |
6543 | 127k | && t->operand_types[0].bitfield.tmmword |
6544 | 127k | && (i.op[0].regs == i.op[1].regs |
6545 | 0 | || i.op[0].regs == i.op[2].regs |
6546 | 0 | || i.op[1].regs == i.op[2].regs)) |
6547 | 0 | { |
6548 | 0 | i.error = invalid_tmm_register_set; |
6549 | 0 | return 1; |
6550 | 0 | } |
6551 | | |
6552 | | /* For some special instructions require that destination must be distinct |
6553 | | from source registers. */ |
6554 | 127k | if (t->opcode_modifier.operandconstraint == DISTINCT_DEST) |
6555 | 0 | { |
6556 | 0 | unsigned int dest_reg = i.operands - 1; |
6557 | |
|
6558 | 0 | know (i.operands >= 3); |
6559 | | |
6560 | | /* #UD if dest_reg == src1_reg or dest_reg == src2_reg. */ |
6561 | 0 | if (i.op[dest_reg - 1].regs == i.op[dest_reg].regs |
6562 | 0 | || (i.reg_operands > 2 |
6563 | 0 | && i.op[dest_reg - 2].regs == i.op[dest_reg].regs)) |
6564 | 0 | { |
6565 | 0 | i.error = invalid_dest_and_src_register_set; |
6566 | 0 | return 1; |
6567 | 0 | } |
6568 | 0 | } |
6569 | | |
6570 | | /* Check if broadcast is supported by the instruction and is applied |
6571 | | to the memory operand. */ |
6572 | 127k | if (i.broadcast.type || i.broadcast.bytes) |
6573 | 0 | { |
6574 | 0 | i386_operand_type type, overlap; |
6575 | | |
6576 | | /* Check if specified broadcast is supported in this instruction, |
6577 | | and its broadcast bytes match the memory operand. */ |
6578 | 0 | op = i.broadcast.operand; |
6579 | 0 | if (!t->opcode_modifier.broadcast |
6580 | 0 | || !(i.flags[op] & Operand_Mem) |
6581 | 0 | || (!i.types[op].bitfield.unspecified |
6582 | 0 | && !match_broadcast_size (t, op))) |
6583 | 0 | { |
6584 | 0 | bad_broadcast: |
6585 | 0 | i.error = unsupported_broadcast; |
6586 | 0 | return 1; |
6587 | 0 | } |
6588 | | |
6589 | 0 | operand_type_set (&type, 0); |
6590 | 0 | switch (get_broadcast_bytes (t, false)) |
6591 | 0 | { |
6592 | 0 | case 2: |
6593 | 0 | type.bitfield.word = 1; |
6594 | 0 | break; |
6595 | 0 | case 4: |
6596 | 0 | type.bitfield.dword = 1; |
6597 | 0 | break; |
6598 | 0 | case 8: |
6599 | 0 | type.bitfield.qword = 1; |
6600 | 0 | break; |
6601 | 0 | case 16: |
6602 | 0 | type.bitfield.xmmword = 1; |
6603 | 0 | break; |
6604 | 0 | case 32: |
6605 | 0 | type.bitfield.ymmword = 1; |
6606 | 0 | break; |
6607 | 0 | case 64: |
6608 | 0 | type.bitfield.zmmword = 1; |
6609 | 0 | break; |
6610 | 0 | default: |
6611 | 0 | goto bad_broadcast; |
6612 | 0 | } |
6613 | | |
6614 | 0 | overlap = operand_type_and (type, t->operand_types[op]); |
6615 | 0 | if (t->operand_types[op].bitfield.class == RegSIMD |
6616 | 0 | && t->operand_types[op].bitfield.byte |
6617 | 0 | + t->operand_types[op].bitfield.word |
6618 | 0 | + t->operand_types[op].bitfield.dword |
6619 | 0 | + t->operand_types[op].bitfield.qword > 1) |
6620 | 0 | { |
6621 | 0 | overlap.bitfield.xmmword = 0; |
6622 | 0 | overlap.bitfield.ymmword = 0; |
6623 | 0 | overlap.bitfield.zmmword = 0; |
6624 | 0 | } |
6625 | 0 | if (operand_type_all_zero (&overlap)) |
6626 | 0 | goto bad_broadcast; |
6627 | | |
6628 | 0 | if (t->opcode_modifier.checkoperandsize) |
6629 | 0 | { |
6630 | 0 | unsigned int j; |
6631 | |
|
6632 | 0 | type.bitfield.baseindex = 1; |
6633 | 0 | for (j = 0; j < i.operands; ++j) |
6634 | 0 | { |
6635 | 0 | if (j != op |
6636 | 0 | && !operand_type_register_match(i.types[j], |
6637 | 0 | t->operand_types[j], |
6638 | 0 | type, |
6639 | 0 | t->operand_types[op])) |
6640 | 0 | goto bad_broadcast; |
6641 | 0 | } |
6642 | 0 | } |
6643 | 0 | } |
6644 | | /* If broadcast is supported in this instruction, we need to check if |
6645 | | operand of one-element size isn't specified without broadcast. */ |
6646 | 127k | else if (t->opcode_modifier.broadcast && i.mem_operands) |
6647 | 0 | { |
6648 | | /* Find memory operand. */ |
6649 | 0 | for (op = 0; op < i.operands; op++) |
6650 | 0 | if (i.flags[op] & Operand_Mem) |
6651 | 0 | break; |
6652 | 0 | gas_assert (op < i.operands); |
6653 | | /* Check size of the memory operand. */ |
6654 | 0 | if (match_broadcast_size (t, op)) |
6655 | 0 | { |
6656 | 0 | i.error = broadcast_needed; |
6657 | 0 | return 1; |
6658 | 0 | } |
6659 | 0 | } |
6660 | 127k | else |
6661 | 127k | op = MAX_OPERANDS - 1; /* Avoid uninitialized variable warning. */ |
6662 | | |
6663 | | /* Check if requested masking is supported. */ |
6664 | 127k | if (i.mask.reg) |
6665 | 0 | { |
6666 | 0 | if (!t->opcode_modifier.masking) |
6667 | 0 | { |
6668 | 0 | i.error = unsupported_masking; |
6669 | 0 | return 1; |
6670 | 0 | } |
6671 | | |
6672 | | /* Common rules for masking: |
6673 | | - mask register destinations permit only zeroing-masking, without |
6674 | | that actually being expressed by a {z} operand suffix or EVEX.z, |
6675 | | - memory destinations allow only merging-masking, |
6676 | | - scatter/gather insns (i.e. ones using vSIB) only allow merging- |
6677 | | masking. */ |
6678 | 0 | if (i.mask.zeroing |
6679 | 0 | && (t->operand_types[t->operands - 1].bitfield.class == RegMask |
6680 | 0 | || (i.flags[t->operands - 1] & Operand_Mem) |
6681 | 0 | || t->opcode_modifier.sib)) |
6682 | 0 | { |
6683 | 0 | i.error = unsupported_masking; |
6684 | 0 | return 1; |
6685 | 0 | } |
6686 | 0 | } |
6687 | | |
6688 | | /* Check if masking is applied to dest operand. */ |
6689 | 127k | if (i.mask.reg && (i.mask.operand != i.operands - 1)) |
6690 | 0 | { |
6691 | 0 | i.error = mask_not_on_destination; |
6692 | 0 | return 1; |
6693 | 0 | } |
6694 | | |
6695 | | /* Check RC/SAE. */ |
6696 | 127k | if (i.rounding.type != rc_none) |
6697 | 16 | { |
6698 | 16 | if (!t->opcode_modifier.sae |
6699 | 16 | || ((i.rounding.type != saeonly) != t->opcode_modifier.staticrounding) |
6700 | 16 | || i.mem_operands) |
6701 | 16 | { |
6702 | 16 | i.error = unsupported_rc_sae; |
6703 | 16 | return 1; |
6704 | 16 | } |
6705 | | |
6706 | | /* Non-EVEX.LIG forms need to have a ZMM register as at least one |
6707 | | operand. */ |
6708 | 0 | if (t->opcode_modifier.evex != EVEXLIG) |
6709 | 0 | { |
6710 | 0 | for (op = 0; op < t->operands; ++op) |
6711 | 0 | if (i.types[op].bitfield.zmmword) |
6712 | 0 | break; |
6713 | 0 | if (op >= t->operands) |
6714 | 0 | { |
6715 | 0 | i.error = operand_size_mismatch; |
6716 | 0 | return 1; |
6717 | 0 | } |
6718 | 0 | } |
6719 | 0 | } |
6720 | | |
6721 | | /* Check the special Imm4 cases; must be the first operand. */ |
6722 | 127k | if (is_cpu (t, CpuXOP) && t->operands == 5) |
6723 | 0 | { |
6724 | 0 | if (i.op[0].imms->X_op != O_constant |
6725 | 0 | || !fits_in_imm4 (i.op[0].imms->X_add_number)) |
6726 | 0 | { |
6727 | 0 | i.error = bad_imm4; |
6728 | 0 | return 1; |
6729 | 0 | } |
6730 | | |
6731 | | /* Turn off Imm<N> so that update_imm won't complain. */ |
6732 | 0 | operand_type_set (&i.types[0], 0); |
6733 | 0 | } |
6734 | | |
6735 | | /* Check vector Disp8 operand. */ |
6736 | 127k | if (t->opcode_modifier.disp8memshift |
6737 | 127k | && i.disp_encoding <= disp_encoding_8bit) |
6738 | 0 | { |
6739 | 0 | if (i.broadcast.type || i.broadcast.bytes) |
6740 | 0 | i.memshift = t->opcode_modifier.broadcast - 1; |
6741 | 0 | else if (t->opcode_modifier.disp8memshift != DISP8_SHIFT_VL) |
6742 | 0 | i.memshift = t->opcode_modifier.disp8memshift; |
6743 | 0 | else |
6744 | 0 | { |
6745 | 0 | const i386_operand_type *type = NULL, *fallback = NULL; |
6746 | |
|
6747 | 0 | i.memshift = 0; |
6748 | 0 | for (op = 0; op < i.operands; op++) |
6749 | 0 | if (i.flags[op] & Operand_Mem) |
6750 | 0 | { |
6751 | 0 | if (t->opcode_modifier.evex == EVEXLIG) |
6752 | 0 | i.memshift = 2 + (i.suffix == QWORD_MNEM_SUFFIX); |
6753 | 0 | else if (t->operand_types[op].bitfield.xmmword |
6754 | 0 | + t->operand_types[op].bitfield.ymmword |
6755 | 0 | + t->operand_types[op].bitfield.zmmword <= 1) |
6756 | 0 | type = &t->operand_types[op]; |
6757 | 0 | else if (!i.types[op].bitfield.unspecified) |
6758 | 0 | type = &i.types[op]; |
6759 | 0 | else /* Ambiguities get resolved elsewhere. */ |
6760 | 0 | fallback = &t->operand_types[op]; |
6761 | 0 | } |
6762 | 0 | else if (i.types[op].bitfield.class == RegSIMD |
6763 | 0 | && t->opcode_modifier.evex != EVEXLIG) |
6764 | 0 | { |
6765 | 0 | if (i.types[op].bitfield.zmmword) |
6766 | 0 | i.memshift = 6; |
6767 | 0 | else if (i.types[op].bitfield.ymmword && i.memshift < 5) |
6768 | 0 | i.memshift = 5; |
6769 | 0 | else if (i.types[op].bitfield.xmmword && i.memshift < 4) |
6770 | 0 | i.memshift = 4; |
6771 | 0 | } |
6772 | |
|
6773 | 0 | if (!type && !i.memshift) |
6774 | 0 | type = fallback; |
6775 | 0 | if (type) |
6776 | 0 | { |
6777 | 0 | if (type->bitfield.zmmword) |
6778 | 0 | i.memshift = 6; |
6779 | 0 | else if (type->bitfield.ymmword) |
6780 | 0 | i.memshift = 5; |
6781 | 0 | else if (type->bitfield.xmmword) |
6782 | 0 | i.memshift = 4; |
6783 | 0 | } |
6784 | | |
6785 | | /* For the check in fits_in_disp8(). */ |
6786 | 0 | if (i.memshift == 0) |
6787 | 0 | i.memshift = -1; |
6788 | 0 | } |
6789 | |
|
6790 | 0 | for (op = 0; op < i.operands; op++) |
6791 | 0 | if (operand_type_check (i.types[op], disp) |
6792 | 0 | && i.op[op].disps->X_op == O_constant) |
6793 | 0 | { |
6794 | 0 | if (fits_in_disp8 (i.op[op].disps->X_add_number)) |
6795 | 0 | { |
6796 | 0 | i.types[op].bitfield.disp8 = 1; |
6797 | 0 | return 0; |
6798 | 0 | } |
6799 | 0 | i.types[op].bitfield.disp8 = 0; |
6800 | 0 | } |
6801 | 0 | } |
6802 | | |
6803 | 127k | i.memshift = 0; |
6804 | | |
6805 | 127k | return 0; |
6806 | 127k | } |
6807 | | |
6808 | | /* Check if encoding requirements are met by the instruction. */ |
6809 | | |
6810 | | static int |
6811 | | VEX_check_encoding (const insn_template *t) |
6812 | 772k | { |
6813 | 772k | if (i.vec_encoding == vex_encoding_error) |
6814 | 0 | { |
6815 | 0 | i.error = unsupported; |
6816 | 0 | return 1; |
6817 | 0 | } |
6818 | | |
6819 | 772k | if (i.vec_encoding == vex_encoding_evex) |
6820 | 0 | { |
6821 | | /* This instruction must be encoded with EVEX prefix. */ |
6822 | 0 | if (!is_evex_encoding (t)) |
6823 | 0 | { |
6824 | 0 | i.error = unsupported; |
6825 | 0 | return 1; |
6826 | 0 | } |
6827 | 0 | return 0; |
6828 | 0 | } |
6829 | | |
6830 | 772k | if (!t->opcode_modifier.vex) |
6831 | 772k | { |
6832 | | /* This instruction template doesn't have VEX prefix. */ |
6833 | 772k | if (i.vec_encoding != vex_encoding_default) |
6834 | 0 | { |
6835 | 0 | i.error = unsupported; |
6836 | 0 | return 1; |
6837 | 0 | } |
6838 | 772k | return 0; |
6839 | 772k | } |
6840 | | |
6841 | 6 | return 0; |
6842 | 772k | } |
6843 | | |
6844 | | /* Helper function for the progress() macro in match_template(). */ |
6845 | | static INLINE enum i386_error progress (enum i386_error new, |
6846 | | enum i386_error last, |
6847 | | unsigned int line, unsigned int *line_p) |
6848 | 6.92M | { |
6849 | 6.92M | if (line <= *line_p) |
6850 | 1.27M | return last; |
6851 | 5.65M | *line_p = line; |
6852 | 5.65M | return new; |
6853 | 6.92M | } |
6854 | | |
6855 | | static const insn_template * |
6856 | | match_template (char mnem_suffix) |
6857 | 852k | { |
6858 | | /* Points to template once we've found it. */ |
6859 | 852k | const insn_template *t; |
6860 | 852k | i386_operand_type overlap0, overlap1, overlap2, overlap3; |
6861 | 852k | i386_operand_type overlap4; |
6862 | 852k | unsigned int found_reverse_match; |
6863 | 852k | i386_operand_type operand_types [MAX_OPERANDS]; |
6864 | 852k | int addr_prefix_disp; |
6865 | 852k | unsigned int j, size_match, check_register, errline = __LINE__; |
6866 | 852k | enum i386_error specific_error = number_of_operands_mismatch; |
6867 | 6.92M | #define progress(err) progress (err, specific_error, __LINE__, &errline) |
6868 | | |
6869 | | #if MAX_OPERANDS != 5 |
6870 | | # error "MAX_OPERANDS must be 5." |
6871 | | #endif |
6872 | | |
6873 | 852k | found_reverse_match = 0; |
6874 | 852k | addr_prefix_disp = -1; |
6875 | | |
6876 | 1.98M | for (t = current_templates->start; t < current_templates->end; t++) |
6877 | 1.90M | { |
6878 | 1.90M | addr_prefix_disp = -1; |
6879 | 1.90M | found_reverse_match = 0; |
6880 | | |
6881 | | /* Must have right number of operands. */ |
6882 | 1.90M | if (i.operands != t->operands) |
6883 | 867k | continue; |
6884 | | |
6885 | | /* Check processor support. */ |
6886 | 1.03M | specific_error = progress (unsupported); |
6887 | 1.03M | if (cpu_flags_match (t) != CPU_FLAGS_PERFECT_MATCH) |
6888 | 32.2k | continue; |
6889 | | |
6890 | | /* Check AT&T mnemonic. */ |
6891 | 1.00M | specific_error = progress (unsupported_with_intel_mnemonic); |
6892 | 1.00M | if (intel_mnemonic && t->opcode_modifier.attmnemonic) |
6893 | 0 | continue; |
6894 | | |
6895 | | /* Check AT&T/Intel syntax. */ |
6896 | 1.00M | specific_error = progress (unsupported_syntax); |
6897 | 1.00M | if ((intel_syntax && t->opcode_modifier.attsyntax) |
6898 | 1.00M | || (!intel_syntax && t->opcode_modifier.intelsyntax)) |
6899 | 0 | continue; |
6900 | | |
6901 | | /* Check Intel64/AMD64 ISA. */ |
6902 | 1.00M | switch (isa64) |
6903 | 1.00M | { |
6904 | 1.00M | default: |
6905 | | /* Default: Don't accept Intel64. */ |
6906 | 1.00M | if (t->opcode_modifier.isa64 == INTEL64) |
6907 | 372 | continue; |
6908 | 1.00M | break; |
6909 | 1.00M | case amd64: |
6910 | | /* -mamd64: Don't accept Intel64 and Intel64 only. */ |
6911 | 0 | if (t->opcode_modifier.isa64 >= INTEL64) |
6912 | 0 | continue; |
6913 | 0 | break; |
6914 | 0 | case intel64: |
6915 | | /* -mintel64: Don't accept AMD64. */ |
6916 | 0 | if (t->opcode_modifier.isa64 == AMD64 && flag_code == CODE_64BIT) |
6917 | 0 | continue; |
6918 | 0 | break; |
6919 | 1.00M | } |
6920 | | |
6921 | | /* Check the suffix. */ |
6922 | 1.00M | specific_error = progress (invalid_instruction_suffix); |
6923 | 1.00M | if ((t->opcode_modifier.no_bsuf && mnem_suffix == BYTE_MNEM_SUFFIX) |
6924 | 1.00M | || (t->opcode_modifier.no_wsuf && mnem_suffix == WORD_MNEM_SUFFIX) |
6925 | 1.00M | || (t->opcode_modifier.no_lsuf && mnem_suffix == LONG_MNEM_SUFFIX) |
6926 | 1.00M | || (t->opcode_modifier.no_ssuf && mnem_suffix == SHORT_MNEM_SUFFIX) |
6927 | 1.00M | || (t->opcode_modifier.no_qsuf && mnem_suffix == QWORD_MNEM_SUFFIX)) |
6928 | 3.87k | continue; |
6929 | | |
6930 | 998k | specific_error = progress (operand_size_mismatch); |
6931 | 998k | size_match = operand_size_match (t); |
6932 | 998k | if (!size_match) |
6933 | 113k | continue; |
6934 | | |
6935 | | /* This is intentionally not |
6936 | | |
6937 | | if (i.jumpabsolute != (t->opcode_modifier.jump == JUMP_ABSOLUTE)) |
6938 | | |
6939 | | as the case of a missing * on the operand is accepted (perhaps with |
6940 | | a warning, issued further down). */ |
6941 | 885k | specific_error = progress (operand_type_mismatch); |
6942 | 885k | if (i.jumpabsolute && t->opcode_modifier.jump != JUMP_ABSOLUTE) |
6943 | 442 | continue; |
6944 | | |
6945 | | /* In Intel syntax, normally we can check for memory operand size when |
6946 | | there is no mnemonic suffix. But jmp and call have 2 different |
6947 | | encodings with Dword memory operand size. Skip the "near" one |
6948 | | (permitting a register operand) when "far" was requested. */ |
6949 | 884k | if (i.far_branch |
6950 | 884k | && t->opcode_modifier.jump == JUMP_ABSOLUTE |
6951 | 884k | && t->operand_types[0].bitfield.class == Reg) |
6952 | 0 | continue; |
6953 | | |
6954 | 5.30M | for (j = 0; j < MAX_OPERANDS; j++) |
6955 | 4.42M | operand_types[j] = t->operand_types[j]; |
6956 | | |
6957 | | /* In general, don't allow 32-bit operands on pre-386. */ |
6958 | 884k | specific_error = progress (mnem_suffix ? invalid_instruction_suffix |
6959 | 884k | : operand_size_mismatch); |
6960 | 884k | j = i.imm_operands + (t->operands > i.imm_operands + 1); |
6961 | 884k | if (i.suffix == LONG_MNEM_SUFFIX |
6962 | 884k | && !cpu_arch_flags.bitfield.cpui386 |
6963 | 884k | && (intel_syntax |
6964 | 0 | ? (t->opcode_modifier.mnemonicsize != IGNORESIZE |
6965 | 0 | && !intel_float_operand (insn_name (t))) |
6966 | 0 | : intel_float_operand (insn_name (t)) != 2) |
6967 | 884k | && (t->operands == i.imm_operands |
6968 | 0 | || (operand_types[i.imm_operands].bitfield.class != RegMMX |
6969 | 0 | && operand_types[i.imm_operands].bitfield.class != RegSIMD |
6970 | 0 | && operand_types[i.imm_operands].bitfield.class != RegMask) |
6971 | 0 | || (operand_types[j].bitfield.class != RegMMX |
6972 | 0 | && operand_types[j].bitfield.class != RegSIMD |
6973 | 0 | && operand_types[j].bitfield.class != RegMask)) |
6974 | 884k | && !t->opcode_modifier.sib) |
6975 | 0 | continue; |
6976 | | |
6977 | | /* Do not verify operands when there are none. */ |
6978 | 884k | if (!t->operands) |
6979 | 645k | { |
6980 | 645k | if (VEX_check_encoding (t)) |
6981 | 0 | { |
6982 | 0 | specific_error = progress (i.error); |
6983 | 0 | continue; |
6984 | 0 | } |
6985 | | |
6986 | | /* We've found a match; break out of loop. */ |
6987 | 645k | break; |
6988 | 645k | } |
6989 | | |
6990 | 239k | if (!t->opcode_modifier.jump |
6991 | 239k | || t->opcode_modifier.jump == JUMP_ABSOLUTE) |
6992 | 217k | { |
6993 | | /* There should be only one Disp operand. */ |
6994 | 429k | for (j = 0; j < MAX_OPERANDS; j++) |
6995 | 426k | if (operand_type_check (operand_types[j], disp)) |
6996 | 214k | break; |
6997 | 217k | if (j < MAX_OPERANDS) |
6998 | 214k | { |
6999 | 214k | bool override = (i.prefix[ADDR_PREFIX] != 0); |
7000 | | |
7001 | 214k | addr_prefix_disp = j; |
7002 | | |
7003 | | /* Address size prefix will turn Disp64 operand into Disp32 and |
7004 | | Disp32/Disp16 one into Disp16/Disp32 respectively. */ |
7005 | 214k | switch (flag_code) |
7006 | 214k | { |
7007 | 102k | case CODE_16BIT: |
7008 | 102k | override = !override; |
7009 | | /* Fall through. */ |
7010 | 147k | case CODE_32BIT: |
7011 | 147k | if (operand_types[j].bitfield.disp32 |
7012 | 147k | && operand_types[j].bitfield.disp16) |
7013 | 147k | { |
7014 | 147k | operand_types[j].bitfield.disp16 = override; |
7015 | 147k | operand_types[j].bitfield.disp32 = !override; |
7016 | 147k | } |
7017 | 147k | gas_assert (!operand_types[j].bitfield.disp64); |
7018 | 0 | break; |
7019 | | |
7020 | 66.8k | case CODE_64BIT: |
7021 | 66.8k | if (operand_types[j].bitfield.disp64) |
7022 | 640 | { |
7023 | 640 | gas_assert (!operand_types[j].bitfield.disp32); |
7024 | 0 | operand_types[j].bitfield.disp32 = override; |
7025 | 640 | operand_types[j].bitfield.disp64 = !override; |
7026 | 640 | } |
7027 | 0 | operand_types[j].bitfield.disp16 = 0; |
7028 | 66.8k | break; |
7029 | 214k | } |
7030 | 214k | } |
7031 | 217k | } |
7032 | | |
7033 | | /* We check register size if needed. */ |
7034 | 239k | if (t->opcode_modifier.checkoperandsize) |
7035 | 100k | { |
7036 | 100k | check_register = (1 << t->operands) - 1; |
7037 | 100k | if (i.broadcast.type || i.broadcast.bytes) |
7038 | 0 | check_register &= ~(1 << i.broadcast.operand); |
7039 | 100k | } |
7040 | 139k | else |
7041 | 139k | check_register = 0; |
7042 | | |
7043 | 239k | overlap0 = operand_type_and (i.types[0], operand_types[0]); |
7044 | 239k | switch (t->operands) |
7045 | 239k | { |
7046 | 32.3k | case 1: |
7047 | 32.3k | if (!operand_type_match (overlap0, i.types[0])) |
7048 | 1.35k | continue; |
7049 | | |
7050 | | /* Allow the ModR/M encoding to be requested by using the {load} or |
7051 | | {store} pseudo prefix on an applicable insn. */ |
7052 | 31.0k | if (!t->opcode_modifier.modrm |
7053 | 31.0k | && i.reg_operands == 1 |
7054 | 31.0k | && ((i.dir_encoding == dir_encoding_load |
7055 | 0 | && t->mnem_off != MN_pop) |
7056 | 0 | || (i.dir_encoding == dir_encoding_store |
7057 | 0 | && t->mnem_off != MN_push)) |
7058 | | /* Avoid BSWAP. */ |
7059 | 31.0k | && t->mnem_off != MN_bswap) |
7060 | 0 | continue; |
7061 | 31.0k | break; |
7062 | | |
7063 | 207k | case 2: |
7064 | | /* xchg %eax, %eax is a special case. It is an alias for nop |
7065 | | only in 32bit mode and we can use opcode 0x90. In 64bit |
7066 | | mode, we can't use 0x90 for xchg %eax, %eax since it should |
7067 | | zero-extend %eax to %rax. */ |
7068 | 207k | if (t->base_opcode == 0x90 |
7069 | 207k | && t->opcode_space == SPACE_BASE) |
7070 | 0 | { |
7071 | 0 | if (flag_code == CODE_64BIT |
7072 | 0 | && i.types[0].bitfield.instance == Accum |
7073 | 0 | && i.types[0].bitfield.dword |
7074 | 0 | && i.types[1].bitfield.instance == Accum) |
7075 | 0 | continue; |
7076 | | |
7077 | | /* Allow the ModR/M encoding to be requested by using the |
7078 | | {load} or {store} pseudo prefix. */ |
7079 | 0 | if (i.dir_encoding == dir_encoding_load |
7080 | 0 | || i.dir_encoding == dir_encoding_store) |
7081 | 0 | continue; |
7082 | 0 | } |
7083 | | |
7084 | 207k | if (t->base_opcode == MOV_AX_DISP32 |
7085 | 207k | && t->opcode_space == SPACE_BASE |
7086 | 207k | && t->mnem_off != MN_movabs) |
7087 | 5.47k | { |
7088 | | /* Force 0x8b encoding for "mov foo@GOT, %eax". */ |
7089 | 5.47k | if (i.reloc[0] == BFD_RELOC_386_GOT32) |
7090 | 0 | continue; |
7091 | | |
7092 | | /* xrelease mov %eax, <disp> is another special case. It must not |
7093 | | match the accumulator-only encoding of mov. */ |
7094 | 5.47k | if (i.hle_prefix) |
7095 | 0 | continue; |
7096 | | |
7097 | | /* Allow the ModR/M encoding to be requested by using a suitable |
7098 | | {load} or {store} pseudo prefix. */ |
7099 | 5.47k | if (i.dir_encoding == (i.types[0].bitfield.instance == Accum |
7100 | 5.47k | ? dir_encoding_store |
7101 | 5.47k | : dir_encoding_load) |
7102 | 5.47k | && !i.types[0].bitfield.disp64 |
7103 | 5.47k | && !i.types[1].bitfield.disp64) |
7104 | 0 | continue; |
7105 | 5.47k | } |
7106 | | |
7107 | | /* Allow the ModR/M encoding to be requested by using the {load} or |
7108 | | {store} pseudo prefix on an applicable insn. */ |
7109 | 207k | if (!t->opcode_modifier.modrm |
7110 | 207k | && i.reg_operands == 1 |
7111 | 207k | && i.imm_operands == 1 |
7112 | 207k | && (i.dir_encoding == dir_encoding_load |
7113 | 0 | || i.dir_encoding == dir_encoding_store) |
7114 | 207k | && t->opcode_space == SPACE_BASE) |
7115 | 0 | { |
7116 | 0 | if (t->base_opcode == 0xb0 /* mov $imm, %reg */ |
7117 | 0 | && i.dir_encoding == dir_encoding_store) |
7118 | 0 | continue; |
7119 | | |
7120 | 0 | if ((t->base_opcode | 0x38) == 0x3c /* <alu> $imm, %acc */ |
7121 | 0 | && (t->base_opcode != 0x3c /* cmp $imm, %acc */ |
7122 | 0 | || i.dir_encoding == dir_encoding_load)) |
7123 | 0 | continue; |
7124 | | |
7125 | 0 | if (t->base_opcode == 0xa8 /* test $imm, %acc */ |
7126 | 0 | && i.dir_encoding == dir_encoding_load) |
7127 | 0 | continue; |
7128 | 0 | } |
7129 | | /* Fall through. */ |
7130 | | |
7131 | 207k | case 3: |
7132 | 207k | if (!(size_match & MATCH_STRAIGHT)) |
7133 | 8.89k | goto check_reverse; |
7134 | | /* Reverse direction of operands if swapping is possible in the first |
7135 | | place (operands need to be symmetric) and |
7136 | | - the load form is requested, and the template is a store form, |
7137 | | - the store form is requested, and the template is a load form, |
7138 | | - the non-default (swapped) form is requested. */ |
7139 | 198k | overlap1 = operand_type_and (operand_types[0], operand_types[1]); |
7140 | 198k | if (t->opcode_modifier.d && i.reg_operands == i.operands |
7141 | 198k | && !operand_type_all_zero (&overlap1)) |
7142 | 0 | switch (i.dir_encoding) |
7143 | 0 | { |
7144 | 0 | case dir_encoding_load: |
7145 | 0 | if (operand_type_check (operand_types[i.operands - 1], anymem) |
7146 | 0 | || t->opcode_modifier.regmem) |
7147 | 0 | goto check_reverse; |
7148 | 0 | break; |
7149 | | |
7150 | 0 | case dir_encoding_store: |
7151 | 0 | if (!operand_type_check (operand_types[i.operands - 1], anymem) |
7152 | 0 | && !t->opcode_modifier.regmem) |
7153 | 0 | goto check_reverse; |
7154 | 0 | break; |
7155 | | |
7156 | 0 | case dir_encoding_swap: |
7157 | 0 | goto check_reverse; |
7158 | | |
7159 | 0 | case dir_encoding_default: |
7160 | 0 | break; |
7161 | 0 | } |
7162 | | /* If we want store form, we skip the current load. */ |
7163 | 198k | if ((i.dir_encoding == dir_encoding_store |
7164 | 198k | || i.dir_encoding == dir_encoding_swap) |
7165 | 198k | && i.mem_operands == 0 |
7166 | 198k | && t->opcode_modifier.load) |
7167 | 0 | continue; |
7168 | | /* Fall through. */ |
7169 | 198k | case 4: |
7170 | 198k | case 5: |
7171 | 198k | overlap1 = operand_type_and (i.types[1], operand_types[1]); |
7172 | 198k | if (!operand_type_match (overlap0, i.types[0]) |
7173 | 198k | || !operand_type_match (overlap1, i.types[1]) |
7174 | 198k | || ((check_register & 3) == 3 |
7175 | 96.1k | && !operand_type_register_match (i.types[0], |
7176 | 0 | operand_types[0], |
7177 | 0 | i.types[1], |
7178 | 0 | operand_types[1]))) |
7179 | 102k | { |
7180 | 102k | specific_error = progress (i.error); |
7181 | | |
7182 | | /* Check if other direction is valid ... */ |
7183 | 102k | if (!t->opcode_modifier.d) |
7184 | 7.15k | continue; |
7185 | | |
7186 | 104k | check_reverse: |
7187 | 104k | if (!(size_match & MATCH_REVERSE)) |
7188 | 95.0k | continue; |
7189 | | /* Try reversing direction of operands. */ |
7190 | 9.04k | j = is_cpu (t, CpuFMA4) |
7191 | 9.04k | || is_cpu (t, CpuXOP) ? 1 : i.operands - 1; |
7192 | 9.04k | overlap0 = operand_type_and (i.types[0], operand_types[j]); |
7193 | 9.04k | overlap1 = operand_type_and (i.types[j], operand_types[0]); |
7194 | 9.04k | overlap2 = operand_type_and (i.types[1], operand_types[1]); |
7195 | 9.04k | gas_assert (t->operands != 3 || !check_register); |
7196 | 9.04k | if (!operand_type_match (overlap0, i.types[0]) |
7197 | 9.04k | || !operand_type_match (overlap1, i.types[j]) |
7198 | 9.04k | || (t->operands == 3 |
7199 | 6 | && !operand_type_match (overlap2, i.types[1])) |
7200 | 9.04k | || (check_register |
7201 | 6 | && !operand_type_register_match (i.types[0], |
7202 | 6 | operand_types[j], |
7203 | 6 | i.types[j], |
7204 | 6 | operand_types[0]))) |
7205 | 9.03k | { |
7206 | | /* Does not match either direction. */ |
7207 | 9.03k | specific_error = progress (i.error); |
7208 | 9.03k | continue; |
7209 | 9.03k | } |
7210 | | /* found_reverse_match holds which variant of D |
7211 | | we've found. */ |
7212 | 6 | if (!t->opcode_modifier.d) |
7213 | 0 | found_reverse_match = 0; |
7214 | 6 | else if (operand_types[0].bitfield.tbyte) |
7215 | 0 | { |
7216 | 0 | if (t->opcode_modifier.operandconstraint != UGH) |
7217 | 0 | found_reverse_match = Opcode_FloatD; |
7218 | 0 | else |
7219 | 0 | found_reverse_match = ~0; |
7220 | | /* FSUB{,R} and FDIV{,R} may need a 2nd bit flipped. */ |
7221 | 0 | if ((t->extension_opcode & 4) |
7222 | 0 | && (intel_syntax || intel_mnemonic)) |
7223 | 0 | found_reverse_match |= Opcode_FloatR; |
7224 | 0 | } |
7225 | 6 | else if (is_cpu (t, CpuFMA4) || is_cpu (t, CpuXOP)) |
7226 | 0 | { |
7227 | 0 | found_reverse_match = Opcode_VexW; |
7228 | 0 | goto check_operands_345; |
7229 | 0 | } |
7230 | 6 | else if (t->opcode_space != SPACE_BASE |
7231 | 6 | && (t->opcode_space != SPACE_0F |
7232 | | /* MOV to/from CR/DR/TR, as an exception, follow |
7233 | | the base opcode space encoding model. */ |
7234 | 0 | || (t->base_opcode | 7) != 0x27)) |
7235 | 0 | found_reverse_match = (t->base_opcode & 0xee) != 0x6e |
7236 | 0 | ? Opcode_ExtD : Opcode_SIMD_IntD; |
7237 | 6 | else if (!t->opcode_modifier.commutative) |
7238 | 6 | found_reverse_match = Opcode_D; |
7239 | 0 | else |
7240 | 0 | found_reverse_match = ~0; |
7241 | 6 | } |
7242 | 96.1k | else |
7243 | 96.1k | { |
7244 | | /* Found a forward 2 operand match here. */ |
7245 | 96.1k | check_operands_345: |
7246 | 96.1k | switch (t->operands) |
7247 | 96.1k | { |
7248 | 0 | case 5: |
7249 | 0 | overlap4 = operand_type_and (i.types[4], operand_types[4]); |
7250 | 0 | if (!operand_type_match (overlap4, i.types[4]) |
7251 | 0 | || !operand_type_register_match (i.types[3], |
7252 | 0 | operand_types[3], |
7253 | 0 | i.types[4], |
7254 | 0 | operand_types[4])) |
7255 | 0 | { |
7256 | 0 | specific_error = progress (i.error); |
7257 | 0 | continue; |
7258 | 0 | } |
7259 | | /* Fall through. */ |
7260 | 0 | case 4: |
7261 | 0 | overlap3 = operand_type_and (i.types[3], operand_types[3]); |
7262 | 0 | if (!operand_type_match (overlap3, i.types[3]) |
7263 | 0 | || ((check_register & 0xa) == 0xa |
7264 | 0 | && !operand_type_register_match (i.types[1], |
7265 | 0 | operand_types[1], |
7266 | 0 | i.types[3], |
7267 | 0 | operand_types[3])) |
7268 | 0 | || ((check_register & 0xc) == 0xc |
7269 | 0 | && !operand_type_register_match (i.types[2], |
7270 | 0 | operand_types[2], |
7271 | 0 | i.types[3], |
7272 | 0 | operand_types[3]))) |
7273 | 0 | { |
7274 | 0 | specific_error = progress (i.error); |
7275 | 0 | continue; |
7276 | 0 | } |
7277 | | /* Fall through. */ |
7278 | 0 | case 3: |
7279 | 0 | overlap2 = operand_type_and (i.types[2], operand_types[2]); |
7280 | 0 | if (!operand_type_match (overlap2, i.types[2]) |
7281 | 0 | || ((check_register & 5) == 5 |
7282 | 0 | && !operand_type_register_match (i.types[0], |
7283 | 0 | operand_types[0], |
7284 | 0 | i.types[2], |
7285 | 0 | operand_types[2])) |
7286 | 0 | || ((check_register & 6) == 6 |
7287 | 0 | && !operand_type_register_match (i.types[1], |
7288 | 0 | operand_types[1], |
7289 | 0 | i.types[2], |
7290 | 0 | operand_types[2]))) |
7291 | 0 | { |
7292 | 0 | specific_error = progress (i.error); |
7293 | 0 | continue; |
7294 | 0 | } |
7295 | 0 | break; |
7296 | 96.1k | } |
7297 | 96.1k | } |
7298 | | /* Found either forward/reverse 2, 3 or 4 operand match here: |
7299 | | slip through to break. */ |
7300 | 239k | } |
7301 | | |
7302 | | /* Check if VEX/EVEX encoding requirements can be satisfied. */ |
7303 | 127k | if (VEX_check_encoding (t)) |
7304 | 0 | { |
7305 | 0 | specific_error = progress (i.error); |
7306 | 0 | continue; |
7307 | 0 | } |
7308 | | |
7309 | | /* Check if vector operands are valid. */ |
7310 | 127k | if (check_VecOperands (t)) |
7311 | 16 | { |
7312 | 16 | specific_error = progress (i.error); |
7313 | 16 | continue; |
7314 | 16 | } |
7315 | | |
7316 | | /* We've found a match; break out of loop. */ |
7317 | 127k | break; |
7318 | 127k | } |
7319 | | |
7320 | 852k | #undef progress |
7321 | | |
7322 | 852k | if (t == current_templates->end) |
7323 | 80.4k | { |
7324 | | /* We found no match. */ |
7325 | 80.4k | i.error = specific_error; |
7326 | 80.4k | return NULL; |
7327 | 80.4k | } |
7328 | | |
7329 | 772k | if (!quiet_warnings) |
7330 | 772k | { |
7331 | 772k | if (!intel_syntax |
7332 | 772k | && (i.jumpabsolute != (t->opcode_modifier.jump == JUMP_ABSOLUTE))) |
7333 | 0 | as_warn (_("indirect %s without `*'"), insn_name (t)); |
7334 | | |
7335 | 772k | if (t->opcode_modifier.isprefix |
7336 | 772k | && t->opcode_modifier.mnemonicsize == IGNORESIZE) |
7337 | 304 | { |
7338 | | /* Warn them that a data or address size prefix doesn't |
7339 | | affect assembly of the next line of code. */ |
7340 | 304 | as_warn (_("stand-alone `%s' prefix"), insn_name (t)); |
7341 | 304 | } |
7342 | 772k | } |
7343 | | |
7344 | | /* Copy the template we found. */ |
7345 | 772k | install_template (t); |
7346 | | |
7347 | 772k | if (addr_prefix_disp != -1) |
7348 | 103k | i.tm.operand_types[addr_prefix_disp] |
7349 | 103k | = operand_types[addr_prefix_disp]; |
7350 | | |
7351 | 772k | switch (found_reverse_match) |
7352 | 772k | { |
7353 | 772k | case 0: |
7354 | 772k | break; |
7355 | | |
7356 | 0 | case Opcode_FloatR: |
7357 | 0 | case Opcode_FloatR | Opcode_FloatD: |
7358 | 0 | i.tm.extension_opcode ^= Opcode_FloatR >> 3; |
7359 | 0 | found_reverse_match &= Opcode_FloatD; |
7360 | | |
7361 | | /* Fall through. */ |
7362 | 6 | default: |
7363 | | /* If we found a reverse match we must alter the opcode direction |
7364 | | bit and clear/flip the regmem modifier one. found_reverse_match |
7365 | | holds bits to change (different for int & float insns). */ |
7366 | | |
7367 | 6 | i.tm.base_opcode ^= found_reverse_match; |
7368 | | |
7369 | | /* Certain SIMD insns have their load forms specified in the opcode |
7370 | | table, and hence we need to _set_ RegMem instead of clearing it. |
7371 | | We need to avoid setting the bit though on insns like KMOVW. */ |
7372 | 6 | i.tm.opcode_modifier.regmem |
7373 | 6 | = i.tm.opcode_modifier.modrm && i.tm.opcode_modifier.d |
7374 | 6 | && i.tm.operands > 2U - i.tm.opcode_modifier.sse2avx |
7375 | 6 | && !i.tm.opcode_modifier.regmem; |
7376 | | |
7377 | | /* Fall through. */ |
7378 | 6 | case ~0: |
7379 | 6 | i.tm.operand_types[0] = operand_types[i.operands - 1]; |
7380 | 6 | i.tm.operand_types[i.operands - 1] = operand_types[0]; |
7381 | 6 | break; |
7382 | | |
7383 | 0 | case Opcode_VexW: |
7384 | | /* Only the first two register operands need reversing, alongside |
7385 | | flipping VEX.W. */ |
7386 | 0 | i.tm.opcode_modifier.vexw ^= VEXW0 ^ VEXW1; |
7387 | |
|
7388 | 0 | j = i.tm.operand_types[0].bitfield.imm8; |
7389 | 0 | i.tm.operand_types[j] = operand_types[j + 1]; |
7390 | 0 | i.tm.operand_types[j + 1] = operand_types[j]; |
7391 | 0 | break; |
7392 | 772k | } |
7393 | | |
7394 | 772k | return t; |
7395 | 772k | } |
7396 | | |
7397 | | static int |
7398 | | check_string (void) |
7399 | 4.52k | { |
7400 | 4.52k | unsigned int es_op = i.tm.opcode_modifier.isstring - IS_STRING_ES_OP0; |
7401 | 4.52k | unsigned int op = i.tm.operand_types[0].bitfield.baseindex ? es_op : 0; |
7402 | | |
7403 | 4.52k | if (i.seg[op] != NULL && i.seg[op] != reg_es) |
7404 | 0 | { |
7405 | 0 | as_bad (_("`%s' operand %u must use `%ses' segment"), |
7406 | 0 | insn_name (&i.tm), |
7407 | 0 | intel_syntax ? i.tm.operands - es_op : es_op + 1, |
7408 | 0 | register_prefix); |
7409 | 0 | return 0; |
7410 | 0 | } |
7411 | | |
7412 | | /* There's only ever one segment override allowed per instruction. |
7413 | | This instruction possibly has a legal segment override on the |
7414 | | second operand, so copy the segment to where non-string |
7415 | | instructions store it, allowing common code. */ |
7416 | 4.52k | i.seg[op] = i.seg[1]; |
7417 | | |
7418 | 4.52k | return 1; |
7419 | 4.52k | } |
7420 | | |
7421 | | static int |
7422 | | process_suffix (void) |
7423 | 772k | { |
7424 | 772k | bool is_movx = false; |
7425 | | |
7426 | | /* If matched instruction specifies an explicit instruction mnemonic |
7427 | | suffix, use it. */ |
7428 | 772k | if (i.tm.opcode_modifier.size == SIZE16) |
7429 | 5 | i.suffix = WORD_MNEM_SUFFIX; |
7430 | 772k | else if (i.tm.opcode_modifier.size == SIZE32) |
7431 | 315 | i.suffix = LONG_MNEM_SUFFIX; |
7432 | 771k | else if (i.tm.opcode_modifier.size == SIZE64) |
7433 | 508 | i.suffix = QWORD_MNEM_SUFFIX; |
7434 | 771k | else if (i.reg_operands |
7435 | 771k | && (i.operands > 1 || i.types[0].bitfield.class == Reg) |
7436 | 771k | && i.tm.opcode_modifier.operandconstraint != ADDR_PREFIX_OP_REG) |
7437 | 6 | { |
7438 | 6 | unsigned int numop = i.operands; |
7439 | | |
7440 | | /* MOVSX/MOVZX */ |
7441 | 6 | is_movx = (i.tm.opcode_space == SPACE_0F |
7442 | 6 | && (i.tm.base_opcode | 8) == 0xbe) |
7443 | 6 | || (i.tm.opcode_space == SPACE_BASE |
7444 | 6 | && i.tm.base_opcode == 0x63 |
7445 | 6 | && is_cpu (&i.tm, Cpu64)); |
7446 | | |
7447 | | /* movsx/movzx want only their source operand considered here, for the |
7448 | | ambiguity checking below. The suffix will be replaced afterwards |
7449 | | to represent the destination (register). */ |
7450 | 6 | if (is_movx && (i.tm.opcode_modifier.w || i.tm.base_opcode == 0x63)) |
7451 | 0 | --i.operands; |
7452 | | |
7453 | | /* crc32 needs REX.W set regardless of suffix / source operand size. */ |
7454 | 6 | if (i.tm.mnem_off == MN_crc32 && i.tm.operand_types[1].bitfield.qword) |
7455 | 0 | i.rex |= REX_W; |
7456 | | |
7457 | | /* If there's no instruction mnemonic suffix we try to invent one |
7458 | | based on GPR operands. */ |
7459 | 6 | if (!i.suffix) |
7460 | 6 | { |
7461 | | /* We take i.suffix from the last register operand specified, |
7462 | | Destination register type is more significant than source |
7463 | | register type. crc32 in SSE4.2 prefers source register |
7464 | | type. */ |
7465 | 6 | unsigned int op = i.tm.mnem_off == MN_crc32 ? 1 : i.operands; |
7466 | | |
7467 | 6 | while (op--) |
7468 | 6 | if (i.tm.operand_types[op].bitfield.instance == InstanceNone |
7469 | 6 | || i.tm.operand_types[op].bitfield.instance == Accum) |
7470 | 6 | { |
7471 | 6 | if (i.types[op].bitfield.class != Reg) |
7472 | 0 | continue; |
7473 | 6 | if (i.types[op].bitfield.byte) |
7474 | 0 | i.suffix = BYTE_MNEM_SUFFIX; |
7475 | 6 | else if (i.types[op].bitfield.word) |
7476 | 6 | i.suffix = WORD_MNEM_SUFFIX; |
7477 | 0 | else if (i.types[op].bitfield.dword) |
7478 | 0 | i.suffix = LONG_MNEM_SUFFIX; |
7479 | 0 | else if (i.types[op].bitfield.qword) |
7480 | 0 | i.suffix = QWORD_MNEM_SUFFIX; |
7481 | 0 | else |
7482 | 0 | continue; |
7483 | 6 | break; |
7484 | 6 | } |
7485 | | |
7486 | | /* As an exception, movsx/movzx silently default to a byte source |
7487 | | in AT&T mode. */ |
7488 | 6 | if (is_movx && i.tm.opcode_modifier.w && !i.suffix && !intel_syntax) |
7489 | 0 | i.suffix = BYTE_MNEM_SUFFIX; |
7490 | 6 | } |
7491 | 0 | else if (i.suffix == BYTE_MNEM_SUFFIX) |
7492 | 0 | { |
7493 | 0 | if (!check_byte_reg ()) |
7494 | 0 | return 0; |
7495 | 0 | } |
7496 | 0 | else if (i.suffix == LONG_MNEM_SUFFIX) |
7497 | 0 | { |
7498 | 0 | if (!check_long_reg ()) |
7499 | 0 | return 0; |
7500 | 0 | } |
7501 | 0 | else if (i.suffix == QWORD_MNEM_SUFFIX) |
7502 | 0 | { |
7503 | 0 | if (!check_qword_reg ()) |
7504 | 0 | return 0; |
7505 | 0 | } |
7506 | 0 | else if (i.suffix == WORD_MNEM_SUFFIX) |
7507 | 0 | { |
7508 | 0 | if (!check_word_reg ()) |
7509 | 0 | return 0; |
7510 | 0 | } |
7511 | 0 | else if (intel_syntax |
7512 | 0 | && i.tm.opcode_modifier.mnemonicsize == IGNORESIZE) |
7513 | | /* Do nothing if the instruction is going to ignore the prefix. */ |
7514 | 0 | ; |
7515 | 0 | else |
7516 | 0 | abort (); |
7517 | | |
7518 | | /* Undo the movsx/movzx change done above. */ |
7519 | 6 | i.operands = numop; |
7520 | 6 | } |
7521 | 771k | else if (i.tm.opcode_modifier.mnemonicsize == DEFAULTSIZE |
7522 | 771k | && !i.suffix) |
7523 | 518 | { |
7524 | 518 | i.suffix = stackop_size; |
7525 | 518 | if (stackop_size == LONG_MNEM_SUFFIX) |
7526 | 0 | { |
7527 | | /* stackop_size is set to LONG_MNEM_SUFFIX for the |
7528 | | .code16gcc directive to support 16-bit mode with |
7529 | | 32-bit address. For IRET without a suffix, generate |
7530 | | 16-bit IRET (opcode 0xcf) to return from an interrupt |
7531 | | handler. */ |
7532 | 0 | if (i.tm.base_opcode == 0xcf) |
7533 | 0 | { |
7534 | 0 | i.suffix = WORD_MNEM_SUFFIX; |
7535 | 0 | as_warn (_("generating 16-bit `iret' for .code16gcc directive")); |
7536 | 0 | } |
7537 | | /* Warn about changed behavior for segment register push/pop. */ |
7538 | 0 | else if ((i.tm.base_opcode | 1) == 0x07) |
7539 | 0 | as_warn (_("generating 32-bit `%s', unlike earlier gas versions"), |
7540 | 0 | insn_name (&i.tm)); |
7541 | 0 | } |
7542 | 518 | } |
7543 | 770k | else if (!i.suffix |
7544 | 770k | && (i.tm.opcode_modifier.jump == JUMP_ABSOLUTE |
7545 | 768k | || i.tm.opcode_modifier.jump == JUMP_BYTE |
7546 | 768k | || i.tm.opcode_modifier.jump == JUMP_INTERSEGMENT |
7547 | 768k | || (i.tm.opcode_space == SPACE_0F |
7548 | 767k | && i.tm.base_opcode == 0x01 /* [ls][gi]dt */ |
7549 | 767k | && i.tm.extension_opcode <= 3))) |
7550 | 832 | { |
7551 | 832 | switch (flag_code) |
7552 | 832 | { |
7553 | 330 | case CODE_64BIT: |
7554 | 330 | if (!i.tm.opcode_modifier.no_qsuf) |
7555 | 328 | { |
7556 | 328 | if (i.tm.opcode_modifier.jump == JUMP_BYTE |
7557 | 328 | || i.tm.opcode_modifier.no_lsuf) |
7558 | 328 | i.suffix = QWORD_MNEM_SUFFIX; |
7559 | 328 | break; |
7560 | 328 | } |
7561 | | /* Fall through. */ |
7562 | 216 | case CODE_32BIT: |
7563 | 216 | if (!i.tm.opcode_modifier.no_lsuf) |
7564 | 216 | i.suffix = LONG_MNEM_SUFFIX; |
7565 | 216 | break; |
7566 | 288 | case CODE_16BIT: |
7567 | 288 | if (!i.tm.opcode_modifier.no_wsuf) |
7568 | 288 | i.suffix = WORD_MNEM_SUFFIX; |
7569 | 288 | break; |
7570 | 832 | } |
7571 | 832 | } |
7572 | | |
7573 | 772k | if (!i.suffix |
7574 | 772k | && (i.tm.opcode_modifier.mnemonicsize != DEFAULTSIZE |
7575 | | /* Also cover lret/retf/iret in 64-bit mode. */ |
7576 | 768k | || (flag_code == CODE_64BIT |
7577 | 518 | && !i.tm.opcode_modifier.no_lsuf |
7578 | 518 | && !i.tm.opcode_modifier.no_qsuf)) |
7579 | 772k | && i.tm.opcode_modifier.mnemonicsize != IGNORESIZE |
7580 | | /* Explicit sizing prefixes are assumed to disambiguate insns. */ |
7581 | 772k | && !i.prefix[DATA_PREFIX] && !(i.prefix[REX_PREFIX] & REX_W) |
7582 | | /* Accept FLDENV et al without suffix. */ |
7583 | 772k | && (i.tm.opcode_modifier.no_ssuf || i.tm.opcode_modifier.floatmf)) |
7584 | 763k | { |
7585 | 763k | unsigned int suffixes, evex = 0; |
7586 | | |
7587 | 763k | suffixes = !i.tm.opcode_modifier.no_bsuf; |
7588 | 763k | if (!i.tm.opcode_modifier.no_wsuf) |
7589 | 97.7k | suffixes |= 1 << 1; |
7590 | 763k | if (!i.tm.opcode_modifier.no_lsuf) |
7591 | 98.2k | suffixes |= 1 << 2; |
7592 | 763k | if (!i.tm.opcode_modifier.no_ssuf) |
7593 | 524 | suffixes |= 1 << 4; |
7594 | 763k | if (flag_code == CODE_64BIT && !i.tm.opcode_modifier.no_qsuf) |
7595 | 32.6k | suffixes |= 1 << 5; |
7596 | | |
7597 | | /* For [XYZ]MMWORD operands inspect operand sizes. While generally |
7598 | | also suitable for AT&T syntax mode, it was requested that this be |
7599 | | restricted to just Intel syntax. */ |
7600 | 763k | if (intel_syntax && is_any_vex_encoding (&i.tm) |
7601 | 763k | && !i.broadcast.type && !i.broadcast.bytes) |
7602 | 0 | { |
7603 | 0 | unsigned int op; |
7604 | |
|
7605 | 0 | for (op = 0; op < i.tm.operands; ++op) |
7606 | 0 | { |
7607 | 0 | if (is_evex_encoding (&i.tm) |
7608 | 0 | && !cpu_arch_flags.bitfield.cpuavx512vl) |
7609 | 0 | { |
7610 | 0 | if (i.tm.operand_types[op].bitfield.ymmword) |
7611 | 0 | i.tm.operand_types[op].bitfield.xmmword = 0; |
7612 | 0 | if (i.tm.operand_types[op].bitfield.zmmword) |
7613 | 0 | i.tm.operand_types[op].bitfield.ymmword = 0; |
7614 | 0 | if (!i.tm.opcode_modifier.evex |
7615 | 0 | || i.tm.opcode_modifier.evex == EVEXDYN) |
7616 | 0 | i.tm.opcode_modifier.evex = EVEX512; |
7617 | 0 | } |
7618 | |
|
7619 | 0 | if (i.tm.operand_types[op].bitfield.xmmword |
7620 | 0 | + i.tm.operand_types[op].bitfield.ymmword |
7621 | 0 | + i.tm.operand_types[op].bitfield.zmmword < 2) |
7622 | 0 | continue; |
7623 | | |
7624 | | /* Any properly sized operand disambiguates the insn. */ |
7625 | 0 | if (i.types[op].bitfield.xmmword |
7626 | 0 | || i.types[op].bitfield.ymmword |
7627 | 0 | || i.types[op].bitfield.zmmword) |
7628 | 0 | { |
7629 | 0 | suffixes &= ~(7 << 6); |
7630 | 0 | evex = 0; |
7631 | 0 | break; |
7632 | 0 | } |
7633 | | |
7634 | 0 | if ((i.flags[op] & Operand_Mem) |
7635 | 0 | && i.tm.operand_types[op].bitfield.unspecified) |
7636 | 0 | { |
7637 | 0 | if (i.tm.operand_types[op].bitfield.xmmword) |
7638 | 0 | suffixes |= 1 << 6; |
7639 | 0 | if (i.tm.operand_types[op].bitfield.ymmword) |
7640 | 0 | suffixes |= 1 << 7; |
7641 | 0 | if (i.tm.operand_types[op].bitfield.zmmword) |
7642 | 0 | suffixes |= 1 << 8; |
7643 | 0 | if (is_evex_encoding (&i.tm)) |
7644 | 0 | evex = EVEX512; |
7645 | 0 | } |
7646 | 0 | } |
7647 | 0 | } |
7648 | | |
7649 | | /* Are multiple suffixes / operand sizes allowed? */ |
7650 | 763k | if (suffixes & (suffixes - 1)) |
7651 | 98.2k | { |
7652 | 98.2k | if (intel_syntax |
7653 | 98.2k | && (i.tm.opcode_modifier.mnemonicsize != DEFAULTSIZE |
7654 | 0 | || operand_check == check_error)) |
7655 | 0 | { |
7656 | 0 | as_bad (_("ambiguous operand size for `%s'"), insn_name (&i.tm)); |
7657 | 0 | return 0; |
7658 | 0 | } |
7659 | 98.2k | if (operand_check == check_error) |
7660 | 0 | { |
7661 | 0 | as_bad (_("no instruction mnemonic suffix given and " |
7662 | 0 | "no register operands; can't size `%s'"), insn_name (&i.tm)); |
7663 | 0 | return 0; |
7664 | 0 | } |
7665 | 98.2k | if (operand_check == check_warning) |
7666 | 98.2k | as_warn (_("%s; using default for `%s'"), |
7667 | 98.2k | intel_syntax |
7668 | 98.2k | ? _("ambiguous operand size") |
7669 | 98.2k | : _("no instruction mnemonic suffix given and " |
7670 | 98.2k | "no register operands"), |
7671 | 98.2k | insn_name (&i.tm)); |
7672 | | |
7673 | 98.2k | if (i.tm.opcode_modifier.floatmf) |
7674 | 524 | i.suffix = SHORT_MNEM_SUFFIX; |
7675 | 97.7k | else if (is_movx) |
7676 | 0 | /* handled below */; |
7677 | 97.7k | else if (evex) |
7678 | 0 | i.tm.opcode_modifier.evex = evex; |
7679 | 97.7k | else if (flag_code == CODE_16BIT) |
7680 | 48.0k | i.suffix = WORD_MNEM_SUFFIX; |
7681 | 49.6k | else if (!i.tm.opcode_modifier.no_lsuf) |
7682 | 49.6k | i.suffix = LONG_MNEM_SUFFIX; |
7683 | 0 | else |
7684 | 0 | i.suffix = QWORD_MNEM_SUFFIX; |
7685 | 98.2k | } |
7686 | 763k | } |
7687 | | |
7688 | 772k | if (is_movx) |
7689 | 0 | { |
7690 | | /* In Intel syntax, movsx/movzx must have a "suffix" (checked above). |
7691 | | In AT&T syntax, if there is no suffix (warned about above), the default |
7692 | | will be byte extension. */ |
7693 | 0 | if (i.tm.opcode_modifier.w && i.suffix && i.suffix != BYTE_MNEM_SUFFIX) |
7694 | 0 | i.tm.base_opcode |= 1; |
7695 | | |
7696 | | /* For further processing, the suffix should represent the destination |
7697 | | (register). This is already the case when one was used with |
7698 | | mov[sz][bw]*, but we need to replace it for mov[sz]x, or if there was |
7699 | | no suffix to begin with. */ |
7700 | 0 | if (i.tm.opcode_modifier.w || i.tm.base_opcode == 0x63 || !i.suffix) |
7701 | 0 | { |
7702 | 0 | if (i.types[1].bitfield.word) |
7703 | 0 | i.suffix = WORD_MNEM_SUFFIX; |
7704 | 0 | else if (i.types[1].bitfield.qword) |
7705 | 0 | i.suffix = QWORD_MNEM_SUFFIX; |
7706 | 0 | else |
7707 | 0 | i.suffix = LONG_MNEM_SUFFIX; |
7708 | |
|
7709 | 0 | i.tm.opcode_modifier.w = 0; |
7710 | 0 | } |
7711 | 0 | } |
7712 | | |
7713 | 772k | if (!i.tm.opcode_modifier.modrm && i.reg_operands && i.tm.operands < 3) |
7714 | 0 | i.short_form = (i.tm.operand_types[0].bitfield.class == Reg) |
7715 | 0 | != (i.tm.operand_types[1].bitfield.class == Reg); |
7716 | | |
7717 | | /* Change the opcode based on the operand size given by i.suffix. */ |
7718 | 772k | switch (i.suffix) |
7719 | 772k | { |
7720 | | /* Size floating point instruction. */ |
7721 | 50.1k | case LONG_MNEM_SUFFIX: |
7722 | 50.1k | if (i.tm.opcode_modifier.floatmf) |
7723 | 0 | { |
7724 | 0 | i.tm.base_opcode ^= 4; |
7725 | 0 | break; |
7726 | 0 | } |
7727 | | /* fall through */ |
7728 | 98.6k | case WORD_MNEM_SUFFIX: |
7729 | 99.7k | case QWORD_MNEM_SUFFIX: |
7730 | | /* It's not a byte, select word/dword operation. */ |
7731 | 99.7k | if (i.tm.opcode_modifier.w) |
7732 | 14.8k | { |
7733 | 14.8k | if (i.short_form) |
7734 | 0 | i.tm.base_opcode |= 8; |
7735 | 14.8k | else |
7736 | 14.8k | i.tm.base_opcode |= 1; |
7737 | 14.8k | } |
7738 | | /* fall through */ |
7739 | 100k | case SHORT_MNEM_SUFFIX: |
7740 | | /* Now select between word & dword operations via the operand |
7741 | | size prefix, except for instructions that will ignore this |
7742 | | prefix anyway. */ |
7743 | 100k | if (i.suffix != QWORD_MNEM_SUFFIX |
7744 | 100k | && i.tm.opcode_modifier.mnemonicsize != IGNORESIZE |
7745 | 100k | && !i.tm.opcode_modifier.floatmf |
7746 | 100k | && !is_any_vex_encoding (&i.tm) |
7747 | 100k | && ((i.suffix == LONG_MNEM_SUFFIX) == (flag_code == CODE_16BIT) |
7748 | 98.3k | || (flag_code == CODE_64BIT |
7749 | 98.2k | && i.tm.opcode_modifier.jump == JUMP_BYTE))) |
7750 | 54 | { |
7751 | 54 | unsigned int prefix = DATA_PREFIX_OPCODE; |
7752 | | |
7753 | 54 | if (i.tm.opcode_modifier.jump == JUMP_BYTE) /* jcxz, loop */ |
7754 | 0 | prefix = ADDR_PREFIX_OPCODE; |
7755 | | |
7756 | 54 | if (!add_prefix (prefix)) |
7757 | 0 | return 0; |
7758 | 54 | } |
7759 | | |
7760 | | /* Set mode64 for an operand. */ |
7761 | 100k | if (i.suffix == QWORD_MNEM_SUFFIX |
7762 | 100k | && flag_code == CODE_64BIT |
7763 | 100k | && !i.tm.opcode_modifier.norex64 |
7764 | 100k | && !i.tm.opcode_modifier.vexw |
7765 | | /* Special case for xchg %rax,%rax. It is NOP and doesn't |
7766 | | need rex64. */ |
7767 | 100k | && ! (i.operands == 2 |
7768 | 842 | && i.tm.base_opcode == 0x90 |
7769 | 842 | && i.tm.opcode_space == SPACE_BASE |
7770 | 842 | && i.types[0].bitfield.instance == Accum |
7771 | 842 | && i.types[0].bitfield.qword |
7772 | 842 | && i.types[1].bitfield.instance == Accum)) |
7773 | 842 | i.rex |= REX_W; |
7774 | | |
7775 | 100k | break; |
7776 | | |
7777 | 670k | case 0: |
7778 | | /* Select word/dword/qword operation with explicit data sizing prefix |
7779 | | when there are no suitable register operands. */ |
7780 | 670k | if (i.tm.opcode_modifier.w |
7781 | 670k | && (i.prefix[DATA_PREFIX] || (i.prefix[REX_PREFIX] & REX_W)) |
7782 | 670k | && (!i.reg_operands |
7783 | 0 | || (i.reg_operands == 1 |
7784 | | /* ShiftCount */ |
7785 | 0 | && (i.tm.operand_types[0].bitfield.instance == RegC |
7786 | | /* InOutPortReg */ |
7787 | 0 | || i.tm.operand_types[0].bitfield.instance == RegD |
7788 | 0 | || i.tm.operand_types[1].bitfield.instance == RegD |
7789 | 0 | || i.tm.mnem_off == MN_crc32)))) |
7790 | 0 | i.tm.base_opcode |= 1; |
7791 | 670k | break; |
7792 | 772k | } |
7793 | | |
7794 | 772k | if (i.tm.opcode_modifier.operandconstraint == ADDR_PREFIX_OP_REG) |
7795 | 0 | { |
7796 | 0 | gas_assert (!i.suffix); |
7797 | 0 | gas_assert (i.reg_operands); |
7798 | | |
7799 | 0 | if (i.tm.operand_types[0].bitfield.instance == Accum |
7800 | 0 | || i.operands == 1) |
7801 | 0 | { |
7802 | | /* The address size override prefix changes the size of the |
7803 | | first operand. */ |
7804 | 0 | if (flag_code == CODE_64BIT |
7805 | 0 | && i.op[0].regs->reg_type.bitfield.word) |
7806 | 0 | { |
7807 | 0 | as_bad (_("16-bit addressing unavailable for `%s'"), |
7808 | 0 | insn_name (&i.tm)); |
7809 | 0 | return 0; |
7810 | 0 | } |
7811 | | |
7812 | 0 | if ((flag_code == CODE_32BIT |
7813 | 0 | ? i.op[0].regs->reg_type.bitfield.word |
7814 | 0 | : i.op[0].regs->reg_type.bitfield.dword) |
7815 | 0 | && !add_prefix (ADDR_PREFIX_OPCODE)) |
7816 | 0 | return 0; |
7817 | 0 | } |
7818 | 0 | else |
7819 | 0 | { |
7820 | | /* Check invalid register operand when the address size override |
7821 | | prefix changes the size of register operands. */ |
7822 | 0 | unsigned int op; |
7823 | 0 | enum { need_word, need_dword, need_qword } need; |
7824 | | |
7825 | | /* Check the register operand for the address size prefix if |
7826 | | the memory operand has no real registers, like symbol, DISP |
7827 | | or bogus (x32-only) symbol(%rip) when symbol(%eip) is meant. */ |
7828 | 0 | if (i.mem_operands == 1 |
7829 | 0 | && i.reg_operands == 1 |
7830 | 0 | && i.operands == 2 |
7831 | 0 | && i.types[1].bitfield.class == Reg |
7832 | 0 | && (flag_code == CODE_32BIT |
7833 | 0 | ? i.op[1].regs->reg_type.bitfield.word |
7834 | 0 | : i.op[1].regs->reg_type.bitfield.dword) |
7835 | 0 | && ((i.base_reg == NULL && i.index_reg == NULL) |
7836 | 0 | #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF) |
7837 | 0 | || (x86_elf_abi == X86_64_X32_ABI |
7838 | 0 | && i.base_reg |
7839 | 0 | && i.base_reg->reg_num == RegIP |
7840 | 0 | && i.base_reg->reg_type.bitfield.qword)) |
7841 | | #else |
7842 | | || 0) |
7843 | | #endif |
7844 | 0 | && !add_prefix (ADDR_PREFIX_OPCODE)) |
7845 | 0 | return 0; |
7846 | | |
7847 | 0 | if (flag_code == CODE_32BIT) |
7848 | 0 | need = i.prefix[ADDR_PREFIX] ? need_word : need_dword; |
7849 | 0 | else if (i.prefix[ADDR_PREFIX]) |
7850 | 0 | need = need_dword; |
7851 | 0 | else |
7852 | 0 | need = flag_code == CODE_64BIT ? need_qword : need_word; |
7853 | |
|
7854 | 0 | for (op = 0; op < i.operands; op++) |
7855 | 0 | { |
7856 | 0 | if (i.types[op].bitfield.class != Reg) |
7857 | 0 | continue; |
7858 | | |
7859 | 0 | switch (need) |
7860 | 0 | { |
7861 | 0 | case need_word: |
7862 | 0 | if (i.op[op].regs->reg_type.bitfield.word) |
7863 | 0 | continue; |
7864 | 0 | break; |
7865 | 0 | case need_dword: |
7866 | 0 | if (i.op[op].regs->reg_type.bitfield.dword) |
7867 | 0 | continue; |
7868 | 0 | break; |
7869 | 0 | case need_qword: |
7870 | 0 | if (i.op[op].regs->reg_type.bitfield.qword) |
7871 | 0 | continue; |
7872 | 0 | break; |
7873 | 0 | } |
7874 | | |
7875 | 0 | as_bad (_("invalid register operand size for `%s'"), |
7876 | 0 | insn_name (&i.tm)); |
7877 | 0 | return 0; |
7878 | 0 | } |
7879 | 0 | } |
7880 | 0 | } |
7881 | | |
7882 | 772k | return 1; |
7883 | 772k | } |
7884 | | |
7885 | | static int |
7886 | | check_byte_reg (void) |
7887 | 0 | { |
7888 | 0 | int op; |
7889 | |
|
7890 | 0 | for (op = i.operands; --op >= 0;) |
7891 | 0 | { |
7892 | | /* Skip non-register operands. */ |
7893 | 0 | if (i.types[op].bitfield.class != Reg) |
7894 | 0 | continue; |
7895 | | |
7896 | | /* If this is an eight bit register, it's OK. If it's the 16 or |
7897 | | 32 bit version of an eight bit register, we will just use the |
7898 | | low portion, and that's OK too. */ |
7899 | 0 | if (i.types[op].bitfield.byte) |
7900 | 0 | continue; |
7901 | | |
7902 | | /* I/O port address operands are OK too. */ |
7903 | 0 | if (i.tm.operand_types[op].bitfield.instance == RegD |
7904 | 0 | && i.tm.operand_types[op].bitfield.word) |
7905 | 0 | continue; |
7906 | | |
7907 | | /* crc32 only wants its source operand checked here. */ |
7908 | 0 | if (i.tm.mnem_off == MN_crc32 && op != 0) |
7909 | 0 | continue; |
7910 | | |
7911 | | /* Any other register is bad. */ |
7912 | 0 | as_bad (_("`%s%s' not allowed with `%s%c'"), |
7913 | 0 | register_prefix, i.op[op].regs->reg_name, |
7914 | 0 | insn_name (&i.tm), i.suffix); |
7915 | 0 | return 0; |
7916 | 0 | } |
7917 | 0 | return 1; |
7918 | 0 | } |
7919 | | |
7920 | | static int |
7921 | | check_long_reg (void) |
7922 | 0 | { |
7923 | 0 | int op; |
7924 | |
|
7925 | 0 | for (op = i.operands; --op >= 0;) |
7926 | | /* Skip non-register operands. */ |
7927 | 0 | if (i.types[op].bitfield.class != Reg) |
7928 | 0 | continue; |
7929 | | /* Reject eight bit registers, except where the template requires |
7930 | | them. (eg. movzb) */ |
7931 | 0 | else if (i.types[op].bitfield.byte |
7932 | 0 | && (i.tm.operand_types[op].bitfield.class == Reg |
7933 | 0 | || i.tm.operand_types[op].bitfield.instance == Accum) |
7934 | 0 | && (i.tm.operand_types[op].bitfield.word |
7935 | 0 | || i.tm.operand_types[op].bitfield.dword)) |
7936 | 0 | { |
7937 | 0 | as_bad (_("`%s%s' not allowed with `%s%c'"), |
7938 | 0 | register_prefix, |
7939 | 0 | i.op[op].regs->reg_name, |
7940 | 0 | insn_name (&i.tm), |
7941 | 0 | i.suffix); |
7942 | 0 | return 0; |
7943 | 0 | } |
7944 | | /* Error if the e prefix on a general reg is missing. */ |
7945 | 0 | else if (i.types[op].bitfield.word |
7946 | 0 | && (i.tm.operand_types[op].bitfield.class == Reg |
7947 | 0 | || i.tm.operand_types[op].bitfield.instance == Accum) |
7948 | 0 | && i.tm.operand_types[op].bitfield.dword) |
7949 | 0 | { |
7950 | 0 | as_bad (_("incorrect register `%s%s' used with `%c' suffix"), |
7951 | 0 | register_prefix, i.op[op].regs->reg_name, |
7952 | 0 | i.suffix); |
7953 | 0 | return 0; |
7954 | 0 | } |
7955 | | /* Warn if the r prefix on a general reg is present. */ |
7956 | 0 | else if (i.types[op].bitfield.qword |
7957 | 0 | && (i.tm.operand_types[op].bitfield.class == Reg |
7958 | 0 | || i.tm.operand_types[op].bitfield.instance == Accum) |
7959 | 0 | && i.tm.operand_types[op].bitfield.dword) |
7960 | 0 | { |
7961 | 0 | as_bad (_("incorrect register `%s%s' used with `%c' suffix"), |
7962 | 0 | register_prefix, i.op[op].regs->reg_name, i.suffix); |
7963 | 0 | return 0; |
7964 | 0 | } |
7965 | 0 | return 1; |
7966 | 0 | } |
7967 | | |
7968 | | static int |
7969 | | check_qword_reg (void) |
7970 | 0 | { |
7971 | 0 | int op; |
7972 | |
|
7973 | 0 | for (op = i.operands; --op >= 0; ) |
7974 | | /* Skip non-register operands. */ |
7975 | 0 | if (i.types[op].bitfield.class != Reg) |
7976 | 0 | continue; |
7977 | | /* Reject eight bit registers, except where the template requires |
7978 | | them. (eg. movzb) */ |
7979 | 0 | else if (i.types[op].bitfield.byte |
7980 | 0 | && (i.tm.operand_types[op].bitfield.class == Reg |
7981 | 0 | || i.tm.operand_types[op].bitfield.instance == Accum) |
7982 | 0 | && (i.tm.operand_types[op].bitfield.word |
7983 | 0 | || i.tm.operand_types[op].bitfield.dword)) |
7984 | 0 | { |
7985 | 0 | as_bad (_("`%s%s' not allowed with `%s%c'"), |
7986 | 0 | register_prefix, |
7987 | 0 | i.op[op].regs->reg_name, |
7988 | 0 | insn_name (&i.tm), |
7989 | 0 | i.suffix); |
7990 | 0 | return 0; |
7991 | 0 | } |
7992 | | /* Warn if the r prefix on a general reg is missing. */ |
7993 | 0 | else if ((i.types[op].bitfield.word |
7994 | 0 | || i.types[op].bitfield.dword) |
7995 | 0 | && (i.tm.operand_types[op].bitfield.class == Reg |
7996 | 0 | || i.tm.operand_types[op].bitfield.instance == Accum) |
7997 | 0 | && i.tm.operand_types[op].bitfield.qword) |
7998 | 0 | { |
7999 | | /* Prohibit these changes in the 64bit mode, since the |
8000 | | lowering is more complicated. */ |
8001 | 0 | as_bad (_("incorrect register `%s%s' used with `%c' suffix"), |
8002 | 0 | register_prefix, i.op[op].regs->reg_name, i.suffix); |
8003 | 0 | return 0; |
8004 | 0 | } |
8005 | 0 | return 1; |
8006 | 0 | } |
8007 | | |
8008 | | static int |
8009 | | check_word_reg (void) |
8010 | 0 | { |
8011 | 0 | int op; |
8012 | 0 | for (op = i.operands; --op >= 0;) |
8013 | | /* Skip non-register operands. */ |
8014 | 0 | if (i.types[op].bitfield.class != Reg) |
8015 | 0 | continue; |
8016 | | /* Reject eight bit registers, except where the template requires |
8017 | | them. (eg. movzb) */ |
8018 | 0 | else if (i.types[op].bitfield.byte |
8019 | 0 | && (i.tm.operand_types[op].bitfield.class == Reg |
8020 | 0 | || i.tm.operand_types[op].bitfield.instance == Accum) |
8021 | 0 | && (i.tm.operand_types[op].bitfield.word |
8022 | 0 | || i.tm.operand_types[op].bitfield.dword)) |
8023 | 0 | { |
8024 | 0 | as_bad (_("`%s%s' not allowed with `%s%c'"), |
8025 | 0 | register_prefix, |
8026 | 0 | i.op[op].regs->reg_name, |
8027 | 0 | insn_name (&i.tm), |
8028 | 0 | i.suffix); |
8029 | 0 | return 0; |
8030 | 0 | } |
8031 | | /* Error if the e or r prefix on a general reg is present. */ |
8032 | 0 | else if ((i.types[op].bitfield.dword |
8033 | 0 | || i.types[op].bitfield.qword) |
8034 | 0 | && (i.tm.operand_types[op].bitfield.class == Reg |
8035 | 0 | || i.tm.operand_types[op].bitfield.instance == Accum) |
8036 | 0 | && i.tm.operand_types[op].bitfield.word) |
8037 | 0 | { |
8038 | 0 | as_bad (_("incorrect register `%s%s' used with `%c' suffix"), |
8039 | 0 | register_prefix, i.op[op].regs->reg_name, |
8040 | 0 | i.suffix); |
8041 | 0 | return 0; |
8042 | 0 | } |
8043 | 0 | return 1; |
8044 | 0 | } |
8045 | | |
8046 | | static int |
8047 | | update_imm (unsigned int j) |
8048 | 223k | { |
8049 | 223k | i386_operand_type overlap = i.types[j]; |
8050 | | |
8051 | 223k | if (i.tm.operand_types[j].bitfield.imm8 |
8052 | 223k | && i.tm.operand_types[j].bitfield.imm8s |
8053 | 223k | && overlap.bitfield.imm8 && overlap.bitfield.imm8s) |
8054 | 0 | { |
8055 | | /* This combination is used on 8-bit immediates where e.g. $~0 is |
8056 | | desirable to permit. We're past operand type matching, so simply |
8057 | | put things back in the shape they were before introducing the |
8058 | | distinction between Imm8, Imm8S, and Imm8|Imm8S. */ |
8059 | 0 | overlap.bitfield.imm8s = 0; |
8060 | 0 | } |
8061 | | |
8062 | 223k | if (overlap.bitfield.imm8 |
8063 | 223k | + overlap.bitfield.imm8s |
8064 | 223k | + overlap.bitfield.imm16 |
8065 | 223k | + overlap.bitfield.imm32 |
8066 | 223k | + overlap.bitfield.imm32s |
8067 | 223k | + overlap.bitfield.imm64 > 1) |
8068 | 384 | { |
8069 | 384 | static const i386_operand_type imm16 = { .bitfield = { .imm16 = 1 } }; |
8070 | 384 | static const i386_operand_type imm32 = { .bitfield = { .imm32 = 1 } }; |
8071 | 384 | static const i386_operand_type imm32s = { .bitfield = { .imm32s = 1 } }; |
8072 | 384 | static const i386_operand_type imm16_32 = { .bitfield = |
8073 | 384 | { .imm16 = 1, .imm32 = 1 } |
8074 | 384 | }; |
8075 | 384 | static const i386_operand_type imm16_32s = { .bitfield = |
8076 | 384 | { .imm16 = 1, .imm32s = 1 } |
8077 | 384 | }; |
8078 | 384 | static const i386_operand_type imm16_32_32s = { .bitfield = |
8079 | 384 | { .imm16 = 1, .imm32 = 1, .imm32s = 1 } |
8080 | 384 | }; |
8081 | | |
8082 | 384 | if (i.suffix) |
8083 | 384 | { |
8084 | 384 | i386_operand_type temp; |
8085 | | |
8086 | 384 | operand_type_set (&temp, 0); |
8087 | 384 | if (i.suffix == BYTE_MNEM_SUFFIX) |
8088 | 0 | { |
8089 | 0 | temp.bitfield.imm8 = overlap.bitfield.imm8; |
8090 | 0 | temp.bitfield.imm8s = overlap.bitfield.imm8s; |
8091 | 0 | } |
8092 | 384 | else if (i.suffix == WORD_MNEM_SUFFIX) |
8093 | 288 | temp.bitfield.imm16 = overlap.bitfield.imm16; |
8094 | 96 | else if (i.suffix == QWORD_MNEM_SUFFIX) |
8095 | 0 | { |
8096 | 0 | temp.bitfield.imm64 = overlap.bitfield.imm64; |
8097 | 0 | temp.bitfield.imm32s = overlap.bitfield.imm32s; |
8098 | 0 | } |
8099 | 96 | else |
8100 | 96 | temp.bitfield.imm32 = overlap.bitfield.imm32; |
8101 | 384 | overlap = temp; |
8102 | 384 | } |
8103 | 0 | else if (operand_type_equal (&overlap, &imm16_32_32s) |
8104 | 0 | || operand_type_equal (&overlap, &imm16_32) |
8105 | 0 | || operand_type_equal (&overlap, &imm16_32s)) |
8106 | 0 | { |
8107 | 0 | if ((flag_code == CODE_16BIT) ^ (i.prefix[DATA_PREFIX] != 0)) |
8108 | 0 | overlap = imm16; |
8109 | 0 | else |
8110 | 0 | overlap = imm32s; |
8111 | 0 | } |
8112 | 0 | else if (i.prefix[REX_PREFIX] & REX_W) |
8113 | 0 | overlap = operand_type_and (overlap, imm32s); |
8114 | 0 | else if (i.prefix[DATA_PREFIX]) |
8115 | 0 | overlap = operand_type_and (overlap, |
8116 | 0 | flag_code != CODE_16BIT ? imm16 : imm32); |
8117 | 384 | if (overlap.bitfield.imm8 |
8118 | 384 | + overlap.bitfield.imm8s |
8119 | 384 | + overlap.bitfield.imm16 |
8120 | 384 | + overlap.bitfield.imm32 |
8121 | 384 | + overlap.bitfield.imm32s |
8122 | 384 | + overlap.bitfield.imm64 != 1) |
8123 | 0 | { |
8124 | 0 | as_bad (_("no instruction mnemonic suffix given; " |
8125 | 0 | "can't determine immediate size")); |
8126 | 0 | return 0; |
8127 | 0 | } |
8128 | 384 | } |
8129 | 223k | i.types[j] = overlap; |
8130 | | |
8131 | 223k | return 1; |
8132 | 223k | } |
8133 | | |
8134 | | static int |
8135 | | finalize_imm (void) |
8136 | 772k | { |
8137 | 772k | unsigned int j, n; |
8138 | | |
8139 | | /* Update the first 2 immediate operands. */ |
8140 | 772k | n = i.operands > 2 ? 2 : i.operands; |
8141 | 772k | if (n) |
8142 | 127k | { |
8143 | 350k | for (j = 0; j < n; j++) |
8144 | 223k | if (update_imm (j) == 0) |
8145 | 0 | return 0; |
8146 | | |
8147 | | /* The 3rd operand can't be immediate operand. */ |
8148 | 127k | gas_assert (operand_type_check (i.types[2], imm) == 0); |
8149 | 127k | } |
8150 | | |
8151 | 772k | return 1; |
8152 | 772k | } |
8153 | | |
8154 | | static INLINE void set_rex_vrex (const reg_entry *r, unsigned int rex_bit, |
8155 | | bool do_sse2avx) |
8156 | 6 | { |
8157 | 6 | if (r->reg_flags & RegRex) |
8158 | 0 | { |
8159 | 0 | if (i.rex & rex_bit) |
8160 | 0 | as_bad (_("same type of prefix used twice")); |
8161 | 0 | i.rex |= rex_bit; |
8162 | 0 | } |
8163 | 6 | else if (do_sse2avx && (i.rex & rex_bit) && i.vex.register_specifier) |
8164 | 0 | { |
8165 | 0 | gas_assert (i.vex.register_specifier == r); |
8166 | 0 | i.vex.register_specifier += 8; |
8167 | 0 | } |
8168 | | |
8169 | 6 | if (r->reg_flags & RegVRex) |
8170 | 0 | i.vrex |= rex_bit; |
8171 | 6 | } |
8172 | | |
8173 | | static int |
8174 | | process_operands (void) |
8175 | 127k | { |
8176 | | /* Default segment register this instruction will use for memory |
8177 | | accesses. 0 means unknown. This is only for optimizing out |
8178 | | unnecessary segment overrides. */ |
8179 | 127k | const reg_entry *default_seg = NULL; |
8180 | | |
8181 | | /* We only need to check those implicit registers for instructions |
8182 | | with 3 operands or less. */ |
8183 | 127k | if (i.operands <= 3) |
8184 | 350k | for (unsigned int j = 0; j < i.operands; j++) |
8185 | 223k | if (i.types[j].bitfield.instance != InstanceNone) |
8186 | 0 | i.reg_operands--; |
8187 | | |
8188 | 127k | if (i.tm.opcode_modifier.sse2avx) |
8189 | 0 | { |
8190 | | /* Legacy encoded insns allow explicit REX prefixes, so these prefixes |
8191 | | need converting. */ |
8192 | 0 | i.rex |= i.prefix[REX_PREFIX] & (REX_W | REX_R | REX_X | REX_B); |
8193 | 0 | i.prefix[REX_PREFIX] = 0; |
8194 | 0 | i.rex_encoding = 0; |
8195 | 0 | } |
8196 | | /* ImmExt should be processed after SSE2AVX. */ |
8197 | 127k | else if (i.tm.opcode_modifier.immext) |
8198 | 0 | process_immext (); |
8199 | | |
8200 | | /* TILEZERO is unusual in that it has a single operand encoded in ModR/M.reg, |
8201 | | not ModR/M.rm. To avoid special casing this in build_modrm_byte(), fake a |
8202 | | new destination operand here, while converting the source one to register |
8203 | | number 0. */ |
8204 | 127k | if (i.tm.mnem_off == MN_tilezero) |
8205 | 0 | { |
8206 | 0 | i.op[1].regs = i.op[0].regs; |
8207 | 0 | i.op[0].regs -= i.op[0].regs->reg_num; |
8208 | 0 | i.types[1] = i.types[0]; |
8209 | 0 | i.tm.operand_types[1] = i.tm.operand_types[0]; |
8210 | 0 | i.flags[1] = i.flags[0]; |
8211 | 0 | i.operands++; |
8212 | 0 | i.reg_operands++; |
8213 | 0 | i.tm.operands++; |
8214 | 0 | } |
8215 | | |
8216 | 127k | if (i.tm.opcode_modifier.sse2avx && i.tm.opcode_modifier.vexvvvv) |
8217 | 0 | { |
8218 | 0 | static const i386_operand_type regxmm = { |
8219 | 0 | .bitfield = { .class = RegSIMD, .xmmword = 1 } |
8220 | 0 | }; |
8221 | 0 | unsigned int dupl = i.operands; |
8222 | 0 | unsigned int dest = dupl - 1; |
8223 | 0 | unsigned int j; |
8224 | | |
8225 | | /* The destination must be an xmm register. */ |
8226 | 0 | gas_assert (i.reg_operands |
8227 | 0 | && MAX_OPERANDS > dupl |
8228 | 0 | && operand_type_equal (&i.types[dest], ®xmm)); |
8229 | | |
8230 | 0 | if (i.tm.operand_types[0].bitfield.instance == Accum |
8231 | 0 | && i.tm.operand_types[0].bitfield.xmmword) |
8232 | 0 | { |
8233 | | /* Keep xmm0 for instructions with VEX prefix and 3 |
8234 | | sources. */ |
8235 | 0 | i.tm.operand_types[0].bitfield.instance = InstanceNone; |
8236 | 0 | i.tm.operand_types[0].bitfield.class = RegSIMD; |
8237 | 0 | i.reg_operands++; |
8238 | 0 | goto duplicate; |
8239 | 0 | } |
8240 | | |
8241 | 0 | if (i.tm.opcode_modifier.operandconstraint == IMPLICIT_1ST_XMM0) |
8242 | 0 | { |
8243 | 0 | gas_assert ((MAX_OPERANDS - 1) > dupl); |
8244 | | |
8245 | | /* Add the implicit xmm0 for instructions with VEX prefix |
8246 | | and 3 sources. */ |
8247 | 0 | for (j = i.operands; j > 0; j--) |
8248 | 0 | { |
8249 | 0 | i.op[j] = i.op[j - 1]; |
8250 | 0 | i.types[j] = i.types[j - 1]; |
8251 | 0 | i.tm.operand_types[j] = i.tm.operand_types[j - 1]; |
8252 | 0 | i.flags[j] = i.flags[j - 1]; |
8253 | 0 | } |
8254 | 0 | i.op[0].regs |
8255 | 0 | = (const reg_entry *) str_hash_find (reg_hash, "xmm0"); |
8256 | 0 | i.types[0] = regxmm; |
8257 | 0 | i.tm.operand_types[0] = regxmm; |
8258 | |
|
8259 | 0 | i.operands += 2; |
8260 | 0 | i.reg_operands += 2; |
8261 | 0 | i.tm.operands += 2; |
8262 | |
|
8263 | 0 | dupl++; |
8264 | 0 | dest++; |
8265 | 0 | i.op[dupl] = i.op[dest]; |
8266 | 0 | i.types[dupl] = i.types[dest]; |
8267 | 0 | i.tm.operand_types[dupl] = i.tm.operand_types[dest]; |
8268 | 0 | i.flags[dupl] = i.flags[dest]; |
8269 | 0 | } |
8270 | 0 | else |
8271 | 0 | { |
8272 | 0 | duplicate: |
8273 | 0 | i.operands++; |
8274 | 0 | i.reg_operands++; |
8275 | 0 | i.tm.operands++; |
8276 | |
|
8277 | 0 | i.op[dupl] = i.op[dest]; |
8278 | 0 | i.types[dupl] = i.types[dest]; |
8279 | 0 | i.tm.operand_types[dupl] = i.tm.operand_types[dest]; |
8280 | 0 | i.flags[dupl] = i.flags[dest]; |
8281 | 0 | } |
8282 | | |
8283 | 0 | if (i.tm.opcode_modifier.immext) |
8284 | 0 | process_immext (); |
8285 | 0 | } |
8286 | 127k | else if (i.tm.operand_types[0].bitfield.instance == Accum |
8287 | 127k | && i.tm.opcode_modifier.modrm) |
8288 | 0 | { |
8289 | 0 | unsigned int j; |
8290 | |
|
8291 | 0 | for (j = 1; j < i.operands; j++) |
8292 | 0 | { |
8293 | 0 | i.op[j - 1] = i.op[j]; |
8294 | 0 | i.types[j - 1] = i.types[j]; |
8295 | | |
8296 | | /* We need to adjust fields in i.tm since they are used by |
8297 | | build_modrm_byte. */ |
8298 | 0 | i.tm.operand_types [j - 1] = i.tm.operand_types [j]; |
8299 | |
|
8300 | 0 | i.flags[j - 1] = i.flags[j]; |
8301 | 0 | } |
8302 | | |
8303 | | /* No adjustment to i.reg_operands: This was already done at the top |
8304 | | of the function. */ |
8305 | 0 | i.operands--; |
8306 | 0 | i.tm.operands--; |
8307 | 0 | } |
8308 | 127k | else if (i.tm.opcode_modifier.operandconstraint == IMPLICIT_QUAD_GROUP) |
8309 | 0 | { |
8310 | 0 | unsigned int regnum, first_reg_in_group, last_reg_in_group; |
8311 | | |
8312 | | /* The second operand must be {x,y,z}mmN, where N is a multiple of 4. */ |
8313 | 0 | gas_assert (i.operands >= 2 && i.types[1].bitfield.class == RegSIMD); |
8314 | 0 | regnum = register_number (i.op[1].regs); |
8315 | 0 | first_reg_in_group = regnum & ~3; |
8316 | 0 | last_reg_in_group = first_reg_in_group + 3; |
8317 | 0 | if (regnum != first_reg_in_group) |
8318 | 0 | as_warn (_("source register `%s%s' implicitly denotes" |
8319 | 0 | " `%s%.3s%u' to `%s%.3s%u' source group in `%s'"), |
8320 | 0 | register_prefix, i.op[1].regs->reg_name, |
8321 | 0 | register_prefix, i.op[1].regs->reg_name, first_reg_in_group, |
8322 | 0 | register_prefix, i.op[1].regs->reg_name, last_reg_in_group, |
8323 | 0 | insn_name (&i.tm)); |
8324 | 0 | } |
8325 | 127k | else if (i.tm.opcode_modifier.operandconstraint == REG_KLUDGE) |
8326 | 0 | { |
8327 | | /* The imul $imm, %reg instruction is converted into |
8328 | | imul $imm, %reg, %reg, and the clr %reg instruction |
8329 | | is converted into xor %reg, %reg. */ |
8330 | |
|
8331 | 0 | unsigned int first_reg_op; |
8332 | |
|
8333 | 0 | if (operand_type_check (i.types[0], reg)) |
8334 | 0 | first_reg_op = 0; |
8335 | 0 | else |
8336 | 0 | first_reg_op = 1; |
8337 | | /* Pretend we saw the extra register operand. */ |
8338 | 0 | gas_assert (i.reg_operands == 1 |
8339 | 0 | && i.op[first_reg_op + 1].regs == 0); |
8340 | 0 | i.op[first_reg_op + 1].regs = i.op[first_reg_op].regs; |
8341 | 0 | i.types[first_reg_op + 1] = i.types[first_reg_op]; |
8342 | 0 | i.operands++; |
8343 | 0 | i.reg_operands++; |
8344 | 0 | } |
8345 | | |
8346 | 127k | if (i.tm.opcode_modifier.modrm) |
8347 | 98.7k | { |
8348 | | /* The opcode is completed (modulo i.tm.extension_opcode which |
8349 | | must be put into the modrm byte). Now, we make the modrm and |
8350 | | index base bytes based on all the info we've collected. */ |
8351 | | |
8352 | 98.7k | default_seg = build_modrm_byte (); |
8353 | | |
8354 | 98.7k | if (!quiet_warnings && i.tm.opcode_modifier.operandconstraint == UGH) |
8355 | 0 | { |
8356 | | /* Warn about some common errors, but press on regardless. */ |
8357 | 0 | if (i.operands == 2) |
8358 | 0 | { |
8359 | | /* Reversed arguments on faddp or fmulp. */ |
8360 | 0 | as_warn (_("translating to `%s %s%s,%s%s'"), insn_name (&i.tm), |
8361 | 0 | register_prefix, i.op[!intel_syntax].regs->reg_name, |
8362 | 0 | register_prefix, i.op[intel_syntax].regs->reg_name); |
8363 | 0 | } |
8364 | 0 | else if (i.tm.opcode_modifier.mnemonicsize == IGNORESIZE) |
8365 | 0 | { |
8366 | | /* Extraneous `l' suffix on fp insn. */ |
8367 | 0 | as_warn (_("translating to `%s %s%s'"), insn_name (&i.tm), |
8368 | 0 | register_prefix, i.op[0].regs->reg_name); |
8369 | 0 | } |
8370 | 0 | } |
8371 | 98.7k | } |
8372 | 28.3k | else if (i.types[0].bitfield.class == SReg && !dot_insn ()) |
8373 | 0 | { |
8374 | 0 | if (flag_code != CODE_64BIT |
8375 | 0 | ? i.tm.base_opcode == POP_SEG_SHORT |
8376 | 0 | && i.op[0].regs->reg_num == 1 |
8377 | 0 | : (i.tm.base_opcode | 1) == (POP_SEG386_SHORT & 0xff) |
8378 | 0 | && i.op[0].regs->reg_num < 4) |
8379 | 0 | { |
8380 | 0 | as_bad (_("you can't `%s %s%s'"), |
8381 | 0 | insn_name (&i.tm), register_prefix, i.op[0].regs->reg_name); |
8382 | 0 | return 0; |
8383 | 0 | } |
8384 | 0 | if (i.op[0].regs->reg_num > 3 |
8385 | 0 | && i.tm.opcode_space == SPACE_BASE ) |
8386 | 0 | { |
8387 | 0 | i.tm.base_opcode ^= (POP_SEG_SHORT ^ POP_SEG386_SHORT) & 0xff; |
8388 | 0 | i.tm.opcode_space = SPACE_0F; |
8389 | 0 | } |
8390 | 0 | i.tm.base_opcode |= (i.op[0].regs->reg_num << 3); |
8391 | 0 | } |
8392 | 28.3k | else if (i.tm.opcode_space == SPACE_BASE |
8393 | 28.3k | && (i.tm.base_opcode & ~3) == MOV_AX_DISP32) |
8394 | 0 | { |
8395 | 0 | default_seg = reg_ds; |
8396 | 0 | } |
8397 | 28.3k | else if (i.tm.opcode_modifier.isstring) |
8398 | 4.52k | { |
8399 | | /* For the string instructions that allow a segment override |
8400 | | on one of their operands, the default segment is ds. */ |
8401 | 4.52k | default_seg = reg_ds; |
8402 | 4.52k | } |
8403 | 23.8k | else if (i.short_form) |
8404 | 0 | { |
8405 | | /* The register operand is in the 1st or 2nd non-immediate operand. */ |
8406 | 0 | const reg_entry *r = i.op[i.imm_operands].regs; |
8407 | |
|
8408 | 0 | if (!dot_insn () |
8409 | 0 | && r->reg_type.bitfield.instance == Accum |
8410 | 0 | && i.op[i.imm_operands + 1].regs) |
8411 | 0 | r = i.op[i.imm_operands + 1].regs; |
8412 | | /* Register goes in low 3 bits of opcode. */ |
8413 | 0 | i.tm.base_opcode |= r->reg_num; |
8414 | 0 | set_rex_vrex (r, REX_B, false); |
8415 | |
|
8416 | 0 | if (dot_insn () && i.reg_operands == 2) |
8417 | 0 | { |
8418 | 0 | gas_assert (is_any_vex_encoding (&i.tm) |
8419 | 0 | || i.vec_encoding != vex_encoding_default); |
8420 | 0 | i.vex.register_specifier = i.op[i.operands - 1].regs; |
8421 | 0 | } |
8422 | 0 | } |
8423 | 23.8k | else if (i.reg_operands == 1 |
8424 | 23.8k | && !i.flags[i.operands - 1] |
8425 | 23.8k | && i.tm.operand_types[i.operands - 1].bitfield.instance |
8426 | 0 | == InstanceNone) |
8427 | 0 | { |
8428 | 0 | gas_assert (is_any_vex_encoding (&i.tm) |
8429 | 0 | || i.vec_encoding != vex_encoding_default); |
8430 | 0 | i.vex.register_specifier = i.op[i.operands - 1].regs; |
8431 | 0 | } |
8432 | | |
8433 | 127k | if ((i.seg[0] || i.prefix[SEG_PREFIX]) |
8434 | 127k | && i.tm.mnem_off == MN_lea) |
8435 | 0 | { |
8436 | 0 | if (!quiet_warnings) |
8437 | 0 | as_warn (_("segment override on `%s' is ineffectual"), insn_name (&i.tm)); |
8438 | 0 | if (optimize && !i.no_optimize) |
8439 | 0 | { |
8440 | 0 | i.seg[0] = NULL; |
8441 | 0 | i.prefix[SEG_PREFIX] = 0; |
8442 | 0 | } |
8443 | 0 | } |
8444 | | |
8445 | | /* If a segment was explicitly specified, and the specified segment |
8446 | | is neither the default nor the one already recorded from a prefix, |
8447 | | use an opcode prefix to select it. If we never figured out what |
8448 | | the default segment is, then default_seg will be zero at this |
8449 | | point, and the specified segment prefix will always be used. */ |
8450 | 127k | if (i.seg[0] |
8451 | 127k | && i.seg[0] != default_seg |
8452 | 127k | && i386_seg_prefixes[i.seg[0]->reg_num] != i.prefix[SEG_PREFIX]) |
8453 | 0 | { |
8454 | 0 | if (!add_prefix (i386_seg_prefixes[i.seg[0]->reg_num])) |
8455 | 0 | return 0; |
8456 | 0 | } |
8457 | 127k | return 1; |
8458 | 127k | } |
8459 | | |
8460 | | static const reg_entry * |
8461 | | build_modrm_byte (void) |
8462 | 98.7k | { |
8463 | 98.7k | const reg_entry *default_seg = NULL; |
8464 | 98.7k | unsigned int source = i.imm_operands - i.tm.opcode_modifier.immext |
8465 | | /* Compensate for kludge in md_assemble(). */ |
8466 | 98.7k | + i.tm.operand_types[0].bitfield.imm1; |
8467 | 98.7k | unsigned int dest = i.operands - 1 - i.tm.opcode_modifier.immext; |
8468 | 98.7k | unsigned int v, op, reg_slot = ~0; |
8469 | | |
8470 | | /* Accumulator (in particular %st), shift count (%cl), and alike need |
8471 | | to be skipped just like immediate operands do. */ |
8472 | 98.7k | if (i.tm.operand_types[source].bitfield.instance) |
8473 | 0 | ++source; |
8474 | 98.7k | while (i.tm.operand_types[dest].bitfield.instance) |
8475 | 0 | --dest; |
8476 | | |
8477 | 98.7k | for (op = source; op < i.operands; ++op) |
8478 | 98.7k | if (i.tm.operand_types[op].bitfield.baseindex) |
8479 | 98.7k | break; |
8480 | | |
8481 | 98.7k | if (i.reg_operands + i.mem_operands + (i.tm.extension_opcode != None) == 4) |
8482 | 0 | { |
8483 | 0 | expressionS *exp; |
8484 | | |
8485 | | /* There are 2 kinds of instructions: |
8486 | | 1. 5 operands: 4 register operands or 3 register operands |
8487 | | plus 1 memory operand plus one Imm4 operand, VexXDS, and |
8488 | | VexW0 or VexW1. The destination must be either XMM, YMM or |
8489 | | ZMM register. |
8490 | | 2. 4 operands: 4 register operands or 3 register operands |
8491 | | plus 1 memory operand, with VexXDS. |
8492 | | 3. Other equivalent combinations when coming from s_insn(). */ |
8493 | 0 | gas_assert (i.tm.opcode_modifier.vexvvvv |
8494 | 0 | && i.tm.opcode_modifier.vexw); |
8495 | 0 | gas_assert (dot_insn () |
8496 | 0 | || i.tm.operand_types[dest].bitfield.class == RegSIMD); |
8497 | | |
8498 | | /* Of the first two non-immediate operands the one with the template |
8499 | | not allowing for a memory one is encoded in the immediate operand. */ |
8500 | 0 | if (source == op) |
8501 | 0 | reg_slot = source + 1; |
8502 | 0 | else |
8503 | 0 | reg_slot = source++; |
8504 | |
|
8505 | 0 | if (!dot_insn ()) |
8506 | 0 | { |
8507 | 0 | gas_assert (i.tm.operand_types[reg_slot].bitfield.class == RegSIMD); |
8508 | 0 | gas_assert (!(i.op[reg_slot].regs->reg_flags & RegVRex)); |
8509 | 0 | } |
8510 | 0 | else |
8511 | 0 | gas_assert (i.tm.operand_types[reg_slot].bitfield.class != ClassNone); |
8512 | | |
8513 | 0 | if (i.imm_operands == 0) |
8514 | 0 | { |
8515 | | /* When there is no immediate operand, generate an 8bit |
8516 | | immediate operand to encode the first operand. */ |
8517 | 0 | exp = &im_expressions[i.imm_operands++]; |
8518 | 0 | i.op[i.operands].imms = exp; |
8519 | 0 | i.types[i.operands].bitfield.imm8 = 1; |
8520 | 0 | i.operands++; |
8521 | |
|
8522 | 0 | exp->X_op = O_constant; |
8523 | 0 | } |
8524 | 0 | else |
8525 | 0 | { |
8526 | 0 | gas_assert (i.imm_operands == 1); |
8527 | 0 | gas_assert (fits_in_imm4 (i.op[0].imms->X_add_number)); |
8528 | 0 | gas_assert (!i.tm.opcode_modifier.immext); |
8529 | | |
8530 | | /* Turn on Imm8 again so that output_imm will generate it. */ |
8531 | 0 | i.types[0].bitfield.imm8 = 1; |
8532 | |
|
8533 | 0 | exp = i.op[0].imms; |
8534 | 0 | } |
8535 | 0 | exp->X_add_number |= register_number (i.op[reg_slot].regs) |
8536 | 0 | << (3 + !(is_evex_encoding (&i.tm) |
8537 | 0 | || i.vec_encoding == vex_encoding_evex)); |
8538 | 0 | } |
8539 | | |
8540 | 98.7k | for (v = source + 1; v < dest; ++v) |
8541 | 0 | if (v != reg_slot) |
8542 | 0 | break; |
8543 | 98.7k | if (v >= dest) |
8544 | 98.7k | v = ~0; |
8545 | 98.7k | if (i.tm.extension_opcode != None) |
8546 | 98.7k | { |
8547 | 98.7k | if (dest != source) |
8548 | 0 | v = dest; |
8549 | 98.7k | dest = ~0; |
8550 | 98.7k | } |
8551 | 98.7k | gas_assert (source < dest); |
8552 | 98.7k | if (i.tm.opcode_modifier.operandconstraint == SWAP_SOURCES |
8553 | 98.7k | && source != op) |
8554 | 0 | { |
8555 | 0 | unsigned int tmp = source; |
8556 | |
|
8557 | 0 | source = v; |
8558 | 0 | v = tmp; |
8559 | 0 | } |
8560 | | |
8561 | 98.7k | if (v < MAX_OPERANDS) |
8562 | 0 | { |
8563 | 0 | gas_assert (i.tm.opcode_modifier.vexvvvv); |
8564 | 0 | i.vex.register_specifier = i.op[v].regs; |
8565 | 0 | } |
8566 | | |
8567 | 98.7k | if (op < i.operands) |
8568 | 98.7k | { |
8569 | 98.7k | if (i.mem_operands) |
8570 | 98.7k | { |
8571 | 98.7k | unsigned int fake_zero_displacement = 0; |
8572 | | |
8573 | 98.7k | gas_assert (i.flags[op] & Operand_Mem); |
8574 | | |
8575 | 98.7k | if (i.tm.opcode_modifier.sib) |
8576 | 0 | { |
8577 | | /* The index register of VSIB shouldn't be RegIZ. */ |
8578 | 0 | if (i.tm.opcode_modifier.sib != SIBMEM |
8579 | 0 | && i.index_reg->reg_num == RegIZ) |
8580 | 0 | abort (); |
8581 | | |
8582 | 0 | i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; |
8583 | 0 | if (!i.base_reg) |
8584 | 0 | { |
8585 | 0 | i.sib.base = NO_BASE_REGISTER; |
8586 | 0 | i.sib.scale = i.log2_scale_factor; |
8587 | 0 | i.types[op] = operand_type_and_not (i.types[op], anydisp); |
8588 | 0 | i.types[op].bitfield.disp32 = 1; |
8589 | 0 | } |
8590 | | |
8591 | | /* Since the mandatory SIB always has index register, so |
8592 | | the code logic remains unchanged. The non-mandatory SIB |
8593 | | without index register is allowed and will be handled |
8594 | | later. */ |
8595 | 0 | if (i.index_reg) |
8596 | 0 | { |
8597 | 0 | if (i.index_reg->reg_num == RegIZ) |
8598 | 0 | i.sib.index = NO_INDEX_REGISTER; |
8599 | 0 | else |
8600 | 0 | i.sib.index = i.index_reg->reg_num; |
8601 | 0 | set_rex_vrex (i.index_reg, REX_X, false); |
8602 | 0 | } |
8603 | 0 | } |
8604 | | |
8605 | 98.7k | default_seg = reg_ds; |
8606 | | |
8607 | 98.7k | if (i.base_reg == 0) |
8608 | 98.7k | { |
8609 | 98.7k | i.rm.mode = 0; |
8610 | 98.7k | if (!i.disp_operands) |
8611 | 0 | fake_zero_displacement = 1; |
8612 | 98.7k | if (i.index_reg == 0) |
8613 | 98.7k | { |
8614 | | /* Both check for VSIB and mandatory non-vector SIB. */ |
8615 | 98.7k | gas_assert (!i.tm.opcode_modifier.sib |
8616 | 98.7k | || i.tm.opcode_modifier.sib == SIBMEM); |
8617 | | /* Operand is just <disp> */ |
8618 | 0 | i.types[op] = operand_type_and_not (i.types[op], anydisp); |
8619 | 98.7k | if (flag_code == CODE_64BIT) |
8620 | 32.5k | { |
8621 | | /* 64bit mode overwrites the 32bit absolute |
8622 | | addressing by RIP relative addressing and |
8623 | | absolute addressing is encoded by one of the |
8624 | | redundant SIB forms. */ |
8625 | 32.5k | i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; |
8626 | 32.5k | i.sib.base = NO_BASE_REGISTER; |
8627 | 32.5k | i.sib.index = NO_INDEX_REGISTER; |
8628 | 32.5k | i.types[op].bitfield.disp32 = 1; |
8629 | 32.5k | } |
8630 | 66.1k | else if ((flag_code == CODE_16BIT) |
8631 | 66.1k | ^ (i.prefix[ADDR_PREFIX] != 0)) |
8632 | 47.6k | { |
8633 | 47.6k | i.rm.regmem = NO_BASE_REGISTER_16; |
8634 | 47.6k | i.types[op].bitfield.disp16 = 1; |
8635 | 47.6k | } |
8636 | 18.4k | else |
8637 | 18.4k | { |
8638 | 18.4k | i.rm.regmem = NO_BASE_REGISTER; |
8639 | 18.4k | i.types[op].bitfield.disp32 = 1; |
8640 | 18.4k | } |
8641 | 98.7k | } |
8642 | 0 | else if (!i.tm.opcode_modifier.sib) |
8643 | 0 | { |
8644 | | /* !i.base_reg && i.index_reg */ |
8645 | 0 | if (i.index_reg->reg_num == RegIZ) |
8646 | 0 | i.sib.index = NO_INDEX_REGISTER; |
8647 | 0 | else |
8648 | 0 | i.sib.index = i.index_reg->reg_num; |
8649 | 0 | i.sib.base = NO_BASE_REGISTER; |
8650 | 0 | i.sib.scale = i.log2_scale_factor; |
8651 | 0 | i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; |
8652 | 0 | i.types[op] = operand_type_and_not (i.types[op], anydisp); |
8653 | 0 | i.types[op].bitfield.disp32 = 1; |
8654 | 0 | if ((i.index_reg->reg_flags & RegRex) != 0) |
8655 | 0 | i.rex |= REX_X; |
8656 | 0 | } |
8657 | 98.7k | } |
8658 | | /* RIP addressing for 64bit mode. */ |
8659 | 0 | else if (i.base_reg->reg_num == RegIP) |
8660 | 0 | { |
8661 | 0 | gas_assert (!i.tm.opcode_modifier.sib); |
8662 | 0 | i.rm.regmem = NO_BASE_REGISTER; |
8663 | 0 | i.types[op].bitfield.disp8 = 0; |
8664 | 0 | i.types[op].bitfield.disp16 = 0; |
8665 | 0 | i.types[op].bitfield.disp32 = 1; |
8666 | 0 | i.types[op].bitfield.disp64 = 0; |
8667 | 0 | i.flags[op] |= Operand_PCrel; |
8668 | 0 | if (! i.disp_operands) |
8669 | 0 | fake_zero_displacement = 1; |
8670 | 0 | } |
8671 | 0 | else if (i.base_reg->reg_type.bitfield.word) |
8672 | 0 | { |
8673 | 0 | gas_assert (!i.tm.opcode_modifier.sib); |
8674 | 0 | switch (i.base_reg->reg_num) |
8675 | 0 | { |
8676 | 0 | case 3: /* (%bx) */ |
8677 | 0 | if (i.index_reg == 0) |
8678 | 0 | i.rm.regmem = 7; |
8679 | 0 | else /* (%bx,%si) -> 0, or (%bx,%di) -> 1 */ |
8680 | 0 | i.rm.regmem = i.index_reg->reg_num - 6; |
8681 | 0 | break; |
8682 | 0 | case 5: /* (%bp) */ |
8683 | 0 | default_seg = reg_ss; |
8684 | 0 | if (i.index_reg == 0) |
8685 | 0 | { |
8686 | 0 | i.rm.regmem = 6; |
8687 | 0 | if (operand_type_check (i.types[op], disp) == 0) |
8688 | 0 | { |
8689 | | /* fake (%bp) into 0(%bp) */ |
8690 | 0 | if (i.disp_encoding == disp_encoding_16bit) |
8691 | 0 | i.types[op].bitfield.disp16 = 1; |
8692 | 0 | else |
8693 | 0 | i.types[op].bitfield.disp8 = 1; |
8694 | 0 | fake_zero_displacement = 1; |
8695 | 0 | } |
8696 | 0 | } |
8697 | 0 | else /* (%bp,%si) -> 2, or (%bp,%di) -> 3 */ |
8698 | 0 | i.rm.regmem = i.index_reg->reg_num - 6 + 2; |
8699 | 0 | break; |
8700 | 0 | default: /* (%si) -> 4 or (%di) -> 5 */ |
8701 | 0 | i.rm.regmem = i.base_reg->reg_num - 6 + 4; |
8702 | 0 | } |
8703 | 0 | if (!fake_zero_displacement |
8704 | 0 | && !i.disp_operands |
8705 | 0 | && i.disp_encoding) |
8706 | 0 | { |
8707 | 0 | fake_zero_displacement = 1; |
8708 | 0 | if (i.disp_encoding == disp_encoding_8bit) |
8709 | 0 | i.types[op].bitfield.disp8 = 1; |
8710 | 0 | else |
8711 | 0 | i.types[op].bitfield.disp16 = 1; |
8712 | 0 | } |
8713 | 0 | i.rm.mode = mode_from_disp_size (i.types[op]); |
8714 | 0 | } |
8715 | 0 | else /* i.base_reg and 32/64 bit mode */ |
8716 | 0 | { |
8717 | 0 | if (operand_type_check (i.types[op], disp)) |
8718 | 0 | { |
8719 | 0 | i.types[op].bitfield.disp16 = 0; |
8720 | 0 | i.types[op].bitfield.disp64 = 0; |
8721 | 0 | i.types[op].bitfield.disp32 = 1; |
8722 | 0 | } |
8723 | |
|
8724 | 0 | if (!i.tm.opcode_modifier.sib) |
8725 | 0 | i.rm.regmem = i.base_reg->reg_num; |
8726 | 0 | if ((i.base_reg->reg_flags & RegRex) != 0) |
8727 | 0 | i.rex |= REX_B; |
8728 | 0 | i.sib.base = i.base_reg->reg_num; |
8729 | | /* x86-64 ignores REX prefix bit here to avoid decoder |
8730 | | complications. */ |
8731 | 0 | if (!(i.base_reg->reg_flags & RegRex) |
8732 | 0 | && (i.base_reg->reg_num == EBP_REG_NUM |
8733 | 0 | || i.base_reg->reg_num == ESP_REG_NUM)) |
8734 | 0 | default_seg = reg_ss; |
8735 | 0 | if (i.base_reg->reg_num == 5 && i.disp_operands == 0) |
8736 | 0 | { |
8737 | 0 | fake_zero_displacement = 1; |
8738 | 0 | if (i.disp_encoding == disp_encoding_32bit) |
8739 | 0 | i.types[op].bitfield.disp32 = 1; |
8740 | 0 | else |
8741 | 0 | i.types[op].bitfield.disp8 = 1; |
8742 | 0 | } |
8743 | 0 | i.sib.scale = i.log2_scale_factor; |
8744 | 0 | if (i.index_reg == 0) |
8745 | 0 | { |
8746 | | /* Only check for VSIB. */ |
8747 | 0 | gas_assert (i.tm.opcode_modifier.sib != VECSIB128 |
8748 | 0 | && i.tm.opcode_modifier.sib != VECSIB256 |
8749 | 0 | && i.tm.opcode_modifier.sib != VECSIB512); |
8750 | | |
8751 | | /* <disp>(%esp) becomes two byte modrm with no index |
8752 | | register. We've already stored the code for esp |
8753 | | in i.rm.regmem ie. ESCAPE_TO_TWO_BYTE_ADDRESSING. |
8754 | | Any base register besides %esp will not use the |
8755 | | extra modrm byte. */ |
8756 | 0 | i.sib.index = NO_INDEX_REGISTER; |
8757 | 0 | } |
8758 | 0 | else if (!i.tm.opcode_modifier.sib) |
8759 | 0 | { |
8760 | 0 | if (i.index_reg->reg_num == RegIZ) |
8761 | 0 | i.sib.index = NO_INDEX_REGISTER; |
8762 | 0 | else |
8763 | 0 | i.sib.index = i.index_reg->reg_num; |
8764 | 0 | i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; |
8765 | 0 | if ((i.index_reg->reg_flags & RegRex) != 0) |
8766 | 0 | i.rex |= REX_X; |
8767 | 0 | } |
8768 | | |
8769 | 0 | if (i.disp_operands |
8770 | 0 | && (i.reloc[op] == BFD_RELOC_386_TLS_DESC_CALL |
8771 | 0 | || i.reloc[op] == BFD_RELOC_X86_64_TLSDESC_CALL)) |
8772 | 0 | i.rm.mode = 0; |
8773 | 0 | else |
8774 | 0 | { |
8775 | 0 | if (!fake_zero_displacement |
8776 | 0 | && !i.disp_operands |
8777 | 0 | && i.disp_encoding) |
8778 | 0 | { |
8779 | 0 | fake_zero_displacement = 1; |
8780 | 0 | if (i.disp_encoding == disp_encoding_8bit) |
8781 | 0 | i.types[op].bitfield.disp8 = 1; |
8782 | 0 | else |
8783 | 0 | i.types[op].bitfield.disp32 = 1; |
8784 | 0 | } |
8785 | 0 | i.rm.mode = mode_from_disp_size (i.types[op]); |
8786 | 0 | } |
8787 | 0 | } |
8788 | | |
8789 | 98.7k | if (fake_zero_displacement) |
8790 | 0 | { |
8791 | | /* Fakes a zero displacement assuming that i.types[op] |
8792 | | holds the correct displacement size. */ |
8793 | 0 | expressionS *exp; |
8794 | |
|
8795 | 0 | gas_assert (i.op[op].disps == 0); |
8796 | 0 | exp = &disp_expressions[i.disp_operands++]; |
8797 | 0 | i.op[op].disps = exp; |
8798 | 0 | exp->X_op = O_constant; |
8799 | 0 | exp->X_add_number = 0; |
8800 | 0 | exp->X_add_symbol = (symbolS *) 0; |
8801 | 0 | exp->X_op_symbol = (symbolS *) 0; |
8802 | 0 | } |
8803 | 98.7k | } |
8804 | 0 | else |
8805 | 0 | { |
8806 | 0 | i.rm.mode = 3; |
8807 | 0 | i.rm.regmem = i.op[op].regs->reg_num; |
8808 | 0 | set_rex_vrex (i.op[op].regs, REX_B, false); |
8809 | 0 | } |
8810 | | |
8811 | 98.7k | if (op == dest) |
8812 | 0 | dest = ~0; |
8813 | 98.7k | if (op == source) |
8814 | 98.7k | source = ~0; |
8815 | 98.7k | } |
8816 | 0 | else |
8817 | 0 | { |
8818 | 0 | i.rm.mode = 3; |
8819 | 0 | if (!i.tm.opcode_modifier.regmem) |
8820 | 0 | { |
8821 | 0 | gas_assert (source < MAX_OPERANDS); |
8822 | 0 | i.rm.regmem = i.op[source].regs->reg_num; |
8823 | 0 | set_rex_vrex (i.op[source].regs, REX_B, |
8824 | 0 | dest >= MAX_OPERANDS && i.tm.opcode_modifier.sse2avx); |
8825 | 0 | source = ~0; |
8826 | 0 | } |
8827 | 0 | else |
8828 | 0 | { |
8829 | 0 | gas_assert (dest < MAX_OPERANDS); |
8830 | 0 | i.rm.regmem = i.op[dest].regs->reg_num; |
8831 | 0 | set_rex_vrex (i.op[dest].regs, REX_B, i.tm.opcode_modifier.sse2avx); |
8832 | 0 | dest = ~0; |
8833 | 0 | } |
8834 | 0 | } |
8835 | | |
8836 | | /* Fill in i.rm.reg field with extension opcode (if any) or the |
8837 | | appropriate register. */ |
8838 | 98.7k | if (i.tm.extension_opcode != None) |
8839 | 98.7k | i.rm.reg = i.tm.extension_opcode; |
8840 | 6 | else if (!i.tm.opcode_modifier.regmem && dest < MAX_OPERANDS) |
8841 | 6 | { |
8842 | 6 | i.rm.reg = i.op[dest].regs->reg_num; |
8843 | 6 | set_rex_vrex (i.op[dest].regs, REX_R, i.tm.opcode_modifier.sse2avx); |
8844 | 6 | } |
8845 | 0 | else |
8846 | 0 | { |
8847 | 0 | gas_assert (source < MAX_OPERANDS); |
8848 | 0 | i.rm.reg = i.op[source].regs->reg_num; |
8849 | 0 | set_rex_vrex (i.op[source].regs, REX_R, false); |
8850 | 0 | } |
8851 | | |
8852 | 98.7k | if (flag_code != CODE_64BIT && (i.rex & REX_R)) |
8853 | 0 | { |
8854 | 0 | gas_assert (i.types[!i.tm.opcode_modifier.regmem].bitfield.class == RegCR); |
8855 | 0 | i.rex &= ~REX_R; |
8856 | 0 | add_prefix (LOCK_PREFIX_OPCODE); |
8857 | 0 | } |
8858 | | |
8859 | 0 | return default_seg; |
8860 | 98.7k | } |
8861 | | |
8862 | | static INLINE void |
8863 | | frag_opcode_byte (unsigned char byte) |
8864 | 134k | { |
8865 | 134k | if (now_seg != absolute_section) |
8866 | 130k | FRAG_APPEND_1_CHAR (byte); |
8867 | 4.06k | else |
8868 | 4.06k | ++abs_section_offset; |
8869 | 134k | } |
8870 | | |
8871 | | static unsigned int |
8872 | | flip_code16 (unsigned int code16) |
8873 | 0 | { |
8874 | 0 | gas_assert (i.tm.operands == 1); |
8875 | | |
8876 | 0 | return !(i.prefix[REX_PREFIX] & REX_W) |
8877 | 0 | && (code16 ? i.tm.operand_types[0].bitfield.disp32 |
8878 | 0 | : i.tm.operand_types[0].bitfield.disp16) |
8879 | 0 | ? CODE16 : 0; |
8880 | 0 | } |
8881 | | |
8882 | | static void |
8883 | | output_branch (void) |
8884 | 21.0k | { |
8885 | 21.0k | char *p; |
8886 | 21.0k | int size; |
8887 | 21.0k | int code16; |
8888 | 21.0k | int prefix; |
8889 | 21.0k | relax_substateT subtype; |
8890 | 21.0k | symbolS *sym; |
8891 | 21.0k | offsetT off; |
8892 | | |
8893 | 21.0k | if (now_seg == absolute_section) |
8894 | 1.07k | { |
8895 | 1.07k | as_bad (_("relaxable branches not supported in absolute section")); |
8896 | 1.07k | return; |
8897 | 1.07k | } |
8898 | | |
8899 | 19.9k | code16 = flag_code == CODE_16BIT ? CODE16 : 0; |
8900 | 19.9k | size = i.disp_encoding > disp_encoding_8bit ? BIG : SMALL; |
8901 | | |
8902 | 19.9k | prefix = 0; |
8903 | 19.9k | if (i.prefix[DATA_PREFIX] != 0) |
8904 | 0 | { |
8905 | 0 | prefix = 1; |
8906 | 0 | i.prefixes -= 1; |
8907 | 0 | code16 ^= flip_code16(code16); |
8908 | 0 | } |
8909 | | /* Pentium4 branch hints. */ |
8910 | | if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE /* not taken */ |
8911 | 19.9k | || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE /* taken */) |
8912 | 4 | { |
8913 | 4 | prefix++; |
8914 | 4 | i.prefixes--; |
8915 | 4 | } |
8916 | 19.9k | if (i.prefix[REX_PREFIX] != 0) |
8917 | 0 | { |
8918 | 0 | prefix++; |
8919 | 0 | i.prefixes--; |
8920 | 0 | } |
8921 | | |
8922 | | /* BND prefixed jump. */ |
8923 | 19.9k | if (i.prefix[BND_PREFIX] != 0) |
8924 | 0 | { |
8925 | 0 | prefix++; |
8926 | 0 | i.prefixes--; |
8927 | 0 | } |
8928 | | |
8929 | 19.9k | if (i.prefixes != 0) |
8930 | 0 | as_warn (_("skipping prefixes on `%s'"), insn_name (&i.tm)); |
8931 | | |
8932 | | /* It's always a symbol; End frag & setup for relax. |
8933 | | Make sure there is enough room in this frag for the largest |
8934 | | instruction we may generate in md_convert_frag. This is 2 |
8935 | | bytes for the opcode and room for the prefix and largest |
8936 | | displacement. */ |
8937 | 19.9k | frag_grow (prefix + 2 + 4); |
8938 | | /* Prefix and 1 opcode byte go in fr_fix. */ |
8939 | 19.9k | p = frag_more (prefix + 1); |
8940 | 19.9k | if (i.prefix[DATA_PREFIX] != 0) |
8941 | 0 | *p++ = DATA_PREFIX_OPCODE; |
8942 | 19.9k | if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE |
8943 | 19.9k | || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE) |
8944 | 4 | *p++ = i.prefix[SEG_PREFIX]; |
8945 | 19.9k | if (i.prefix[BND_PREFIX] != 0) |
8946 | 0 | *p++ = BND_PREFIX_OPCODE; |
8947 | 19.9k | if (i.prefix[REX_PREFIX] != 0) |
8948 | 0 | *p++ = i.prefix[REX_PREFIX]; |
8949 | 19.9k | *p = i.tm.base_opcode; |
8950 | | |
8951 | 19.9k | if ((unsigned char) *p == JUMP_PC_RELATIVE) |
8952 | 42 | subtype = ENCODE_RELAX_STATE (UNCOND_JUMP, size); |
8953 | 19.9k | else if (cpu_arch_flags.bitfield.cpui386) |
8954 | 19.9k | subtype = ENCODE_RELAX_STATE (COND_JUMP, size); |
8955 | 0 | else |
8956 | 0 | subtype = ENCODE_RELAX_STATE (COND_JUMP86, size); |
8957 | 19.9k | subtype |= code16; |
8958 | | |
8959 | 19.9k | sym = i.op[0].disps->X_add_symbol; |
8960 | 19.9k | off = i.op[0].disps->X_add_number; |
8961 | | |
8962 | 19.9k | if (i.op[0].disps->X_op != O_constant |
8963 | 19.9k | && i.op[0].disps->X_op != O_symbol) |
8964 | 9.74k | { |
8965 | | /* Handle complex expressions. */ |
8966 | 9.74k | sym = make_expr_symbol (i.op[0].disps); |
8967 | 9.74k | off = 0; |
8968 | 9.74k | } |
8969 | | |
8970 | 19.9k | frag_now->tc_frag_data.code64 = flag_code == CODE_64BIT; |
8971 | | |
8972 | | /* 1 possible extra opcode + 4 byte displacement go in var part. |
8973 | | Pass reloc in fr_var. */ |
8974 | 19.9k | frag_var (rs_machine_dependent, 5, i.reloc[0], subtype, sym, off, p); |
8975 | 19.9k | } |
8976 | | |
8977 | | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
8978 | | /* Return TRUE iff PLT32 relocation should be used for branching to |
8979 | | symbol S. */ |
8980 | | |
8981 | | static bool |
8982 | | need_plt32_p (symbolS *s) |
8983 | 242 | { |
8984 | | /* PLT32 relocation is ELF only. */ |
8985 | 242 | if (!IS_ELF) |
8986 | 0 | return false; |
8987 | | |
8988 | | #ifdef TE_SOLARIS |
8989 | | /* Don't emit PLT32 relocation on Solaris: neither native linker nor |
8990 | | krtld support it. */ |
8991 | | return false; |
8992 | | #endif |
8993 | | |
8994 | | /* Since there is no need to prepare for PLT branch on x86-64, we |
8995 | | can generate R_X86_64_PLT32, instead of R_X86_64_PC32, which can |
8996 | | be used as a marker for 32-bit PC-relative branches. */ |
8997 | 242 | if (!object_64bit) |
8998 | 0 | return false; |
8999 | | |
9000 | 242 | if (s == NULL) |
9001 | 0 | return false; |
9002 | | |
9003 | | /* Weak or undefined symbol need PLT32 relocation. */ |
9004 | 242 | if (S_IS_WEAK (s) || !S_IS_DEFINED (s)) |
9005 | 180 | return true; |
9006 | | |
9007 | | /* Non-global symbol doesn't need PLT32 relocation. */ |
9008 | 62 | if (! S_IS_EXTERNAL (s)) |
9009 | 62 | return false; |
9010 | | |
9011 | | /* Other global symbols need PLT32 relocation. NB: Symbol with |
9012 | | non-default visibilities are treated as normal global symbol |
9013 | | so that PLT32 relocation can be used as a marker for 32-bit |
9014 | | PC-relative branches. It is useful for linker relaxation. */ |
9015 | 0 | return true; |
9016 | 62 | } |
9017 | | #endif |
9018 | | |
9019 | | static void |
9020 | | output_jump (void) |
9021 | 1.07k | { |
9022 | 1.07k | char *p; |
9023 | 1.07k | int size; |
9024 | 1.07k | fixS *fixP; |
9025 | 1.07k | bfd_reloc_code_real_type jump_reloc = i.reloc[0]; |
9026 | | |
9027 | 1.07k | if (i.tm.opcode_modifier.jump == JUMP_BYTE) |
9028 | 676 | { |
9029 | | /* This is a loop or jecxz type instruction. */ |
9030 | 676 | size = 1; |
9031 | 676 | if (i.prefix[ADDR_PREFIX] != 0) |
9032 | 0 | { |
9033 | 0 | frag_opcode_byte (ADDR_PREFIX_OPCODE); |
9034 | 0 | i.prefixes -= 1; |
9035 | 0 | } |
9036 | | /* Pentium4 branch hints. */ |
9037 | | if (i.prefix[SEG_PREFIX] == CS_PREFIX_OPCODE /* not taken */ |
9038 | 676 | || i.prefix[SEG_PREFIX] == DS_PREFIX_OPCODE /* taken */) |
9039 | 0 | { |
9040 | 0 | frag_opcode_byte (i.prefix[SEG_PREFIX]); |
9041 | 0 | i.prefixes--; |
9042 | 0 | } |
9043 | 676 | } |
9044 | 399 | else |
9045 | 399 | { |
9046 | 399 | int code16; |
9047 | | |
9048 | 399 | code16 = 0; |
9049 | 399 | if (flag_code == CODE_16BIT) |
9050 | 38 | code16 = CODE16; |
9051 | | |
9052 | 399 | if (i.prefix[DATA_PREFIX] != 0) |
9053 | 0 | { |
9054 | 0 | frag_opcode_byte (DATA_PREFIX_OPCODE); |
9055 | 0 | i.prefixes -= 1; |
9056 | 0 | code16 ^= flip_code16(code16); |
9057 | 0 | } |
9058 | | |
9059 | 399 | size = 4; |
9060 | 399 | if (code16) |
9061 | 38 | size = 2; |
9062 | 399 | } |
9063 | | |
9064 | | /* BND prefixed jump. */ |
9065 | 1.07k | if (i.prefix[BND_PREFIX] != 0) |
9066 | 0 | { |
9067 | 0 | frag_opcode_byte (i.prefix[BND_PREFIX]); |
9068 | 0 | i.prefixes -= 1; |
9069 | 0 | } |
9070 | | |
9071 | 1.07k | if (i.prefix[REX_PREFIX] != 0) |
9072 | 0 | { |
9073 | 0 | frag_opcode_byte (i.prefix[REX_PREFIX]); |
9074 | 0 | i.prefixes -= 1; |
9075 | 0 | } |
9076 | | |
9077 | 1.07k | if (i.prefixes != 0) |
9078 | 0 | as_warn (_("skipping prefixes on `%s'"), insn_name (&i.tm)); |
9079 | | |
9080 | 1.07k | if (now_seg == absolute_section) |
9081 | 591 | { |
9082 | 591 | abs_section_offset += i.opcode_length + size; |
9083 | 591 | return; |
9084 | 591 | } |
9085 | | |
9086 | 484 | p = frag_more (i.opcode_length + size); |
9087 | 484 | switch (i.opcode_length) |
9088 | 484 | { |
9089 | 0 | case 2: |
9090 | 0 | *p++ = i.tm.base_opcode >> 8; |
9091 | | /* Fall through. */ |
9092 | 484 | case 1: |
9093 | 484 | *p++ = i.tm.base_opcode; |
9094 | 484 | break; |
9095 | 0 | default: |
9096 | 0 | abort (); |
9097 | 484 | } |
9098 | | |
9099 | 484 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
9100 | 484 | if (flag_code == CODE_64BIT && size == 4 |
9101 | 484 | && jump_reloc == NO_RELOC && i.op[0].disps->X_add_number == 0 |
9102 | 484 | && need_plt32_p (i.op[0].disps->X_add_symbol)) |
9103 | 180 | jump_reloc = BFD_RELOC_X86_64_PLT32; |
9104 | 484 | #endif |
9105 | | |
9106 | 484 | jump_reloc = reloc (size, 1, 1, jump_reloc); |
9107 | | |
9108 | 484 | fixP = fix_new_exp (frag_now, p - frag_now->fr_literal, size, |
9109 | 484 | i.op[0].disps, 1, jump_reloc); |
9110 | | |
9111 | | /* All jumps handled here are signed, but don't unconditionally use a |
9112 | | signed limit check for 32 and 16 bit jumps as we want to allow wrap |
9113 | | around at 4G (outside of 64-bit mode) and 64k (except for XBEGIN) |
9114 | | respectively. */ |
9115 | 484 | switch (size) |
9116 | 484 | { |
9117 | 87 | case 1: |
9118 | 87 | fixP->fx_signed = 1; |
9119 | 87 | break; |
9120 | | |
9121 | 36 | case 2: |
9122 | 36 | if (i.tm.mnem_off == MN_xbegin) |
9123 | 0 | fixP->fx_signed = 1; |
9124 | 36 | break; |
9125 | | |
9126 | 361 | case 4: |
9127 | 361 | if (flag_code == CODE_64BIT) |
9128 | 277 | fixP->fx_signed = 1; |
9129 | 361 | break; |
9130 | 484 | } |
9131 | 484 | } |
9132 | | |
9133 | | static void |
9134 | | output_interseg_jump (void) |
9135 | 0 | { |
9136 | 0 | char *p; |
9137 | 0 | int size; |
9138 | 0 | int prefix; |
9139 | 0 | int code16; |
9140 | |
|
9141 | 0 | code16 = 0; |
9142 | 0 | if (flag_code == CODE_16BIT) |
9143 | 0 | code16 = CODE16; |
9144 | |
|
9145 | 0 | prefix = 0; |
9146 | 0 | if (i.prefix[DATA_PREFIX] != 0) |
9147 | 0 | { |
9148 | 0 | prefix = 1; |
9149 | 0 | i.prefixes -= 1; |
9150 | 0 | code16 ^= CODE16; |
9151 | 0 | } |
9152 | |
|
9153 | 0 | gas_assert (!i.prefix[REX_PREFIX]); |
9154 | | |
9155 | 0 | size = 4; |
9156 | 0 | if (code16) |
9157 | 0 | size = 2; |
9158 | |
|
9159 | 0 | if (i.prefixes != 0) |
9160 | 0 | as_warn (_("skipping prefixes on `%s'"), insn_name (&i.tm)); |
9161 | |
|
9162 | 0 | if (now_seg == absolute_section) |
9163 | 0 | { |
9164 | 0 | abs_section_offset += prefix + 1 + 2 + size; |
9165 | 0 | return; |
9166 | 0 | } |
9167 | | |
9168 | | /* 1 opcode; 2 segment; offset */ |
9169 | 0 | p = frag_more (prefix + 1 + 2 + size); |
9170 | |
|
9171 | 0 | if (i.prefix[DATA_PREFIX] != 0) |
9172 | 0 | *p++ = DATA_PREFIX_OPCODE; |
9173 | |
|
9174 | 0 | if (i.prefix[REX_PREFIX] != 0) |
9175 | 0 | *p++ = i.prefix[REX_PREFIX]; |
9176 | |
|
9177 | 0 | *p++ = i.tm.base_opcode; |
9178 | 0 | if (i.op[1].imms->X_op == O_constant) |
9179 | 0 | { |
9180 | 0 | offsetT n = i.op[1].imms->X_add_number; |
9181 | |
|
9182 | 0 | if (size == 2 |
9183 | 0 | && !fits_in_unsigned_word (n) |
9184 | 0 | && !fits_in_signed_word (n)) |
9185 | 0 | { |
9186 | 0 | as_bad (_("16-bit jump out of range")); |
9187 | 0 | return; |
9188 | 0 | } |
9189 | 0 | md_number_to_chars (p, n, size); |
9190 | 0 | } |
9191 | 0 | else |
9192 | 0 | fix_new_exp (frag_now, p - frag_now->fr_literal, size, |
9193 | 0 | i.op[1].imms, 0, reloc (size, 0, 0, i.reloc[1])); |
9194 | | |
9195 | 0 | p += size; |
9196 | 0 | if (i.op[0].imms->X_op == O_constant) |
9197 | 0 | md_number_to_chars (p, (valueT) i.op[0].imms->X_add_number, 2); |
9198 | 0 | else |
9199 | 0 | fix_new_exp (frag_now, p - frag_now->fr_literal, 2, |
9200 | 0 | i.op[0].imms, 0, reloc (2, 0, 0, i.reloc[0])); |
9201 | 0 | } |
9202 | | |
9203 | | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
9204 | | void |
9205 | | x86_cleanup (void) |
9206 | 1.15k | { |
9207 | 1.15k | char *p; |
9208 | 1.15k | asection *seg = now_seg; |
9209 | 1.15k | subsegT subseg = now_subseg; |
9210 | 1.15k | asection *sec; |
9211 | 1.15k | unsigned int alignment, align_size_1; |
9212 | 1.15k | unsigned int isa_1_descsz, feature_2_descsz, descsz; |
9213 | 1.15k | unsigned int isa_1_descsz_raw, feature_2_descsz_raw; |
9214 | 1.15k | unsigned int padding; |
9215 | | |
9216 | 1.15k | if (!IS_ELF || !x86_used_note) |
9217 | 0 | return; |
9218 | | |
9219 | 1.15k | x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_X86; |
9220 | | |
9221 | | /* The .note.gnu.property section layout: |
9222 | | |
9223 | | Field Length Contents |
9224 | | ---- ---- ---- |
9225 | | n_namsz 4 4 |
9226 | | n_descsz 4 The note descriptor size |
9227 | | n_type 4 NT_GNU_PROPERTY_TYPE_0 |
9228 | | n_name 4 "GNU" |
9229 | | n_desc n_descsz The program property array |
9230 | | .... .... .... |
9231 | | */ |
9232 | | |
9233 | | /* Create the .note.gnu.property section. */ |
9234 | 1.15k | sec = subseg_new (NOTE_GNU_PROPERTY_SECTION_NAME, 0); |
9235 | 1.15k | bfd_set_section_flags (sec, |
9236 | 1.15k | (SEC_ALLOC |
9237 | 1.15k | | SEC_LOAD |
9238 | 1.15k | | SEC_DATA |
9239 | 1.15k | | SEC_HAS_CONTENTS |
9240 | 1.15k | | SEC_READONLY)); |
9241 | | |
9242 | 1.15k | if (get_elf_backend_data (stdoutput)->s->elfclass == ELFCLASS64) |
9243 | 1.15k | { |
9244 | 1.15k | align_size_1 = 7; |
9245 | 1.15k | alignment = 3; |
9246 | 1.15k | } |
9247 | 0 | else |
9248 | 0 | { |
9249 | 0 | align_size_1 = 3; |
9250 | 0 | alignment = 2; |
9251 | 0 | } |
9252 | | |
9253 | 1.15k | bfd_set_section_alignment (sec, alignment); |
9254 | 1.15k | elf_section_type (sec) = SHT_NOTE; |
9255 | | |
9256 | | /* GNU_PROPERTY_X86_ISA_1_USED: 4-byte type + 4-byte data size |
9257 | | + 4-byte data */ |
9258 | 1.15k | isa_1_descsz_raw = 4 + 4 + 4; |
9259 | | /* Align GNU_PROPERTY_X86_ISA_1_USED. */ |
9260 | 1.15k | isa_1_descsz = (isa_1_descsz_raw + align_size_1) & ~align_size_1; |
9261 | | |
9262 | 1.15k | feature_2_descsz_raw = isa_1_descsz; |
9263 | | /* GNU_PROPERTY_X86_FEATURE_2_USED: 4-byte type + 4-byte data size |
9264 | | + 4-byte data */ |
9265 | 1.15k | feature_2_descsz_raw += 4 + 4 + 4; |
9266 | | /* Align GNU_PROPERTY_X86_FEATURE_2_USED. */ |
9267 | 1.15k | feature_2_descsz = ((feature_2_descsz_raw + align_size_1) |
9268 | 1.15k | & ~align_size_1); |
9269 | | |
9270 | 1.15k | descsz = feature_2_descsz; |
9271 | | /* Section size: n_namsz + n_descsz + n_type + n_name + n_descsz. */ |
9272 | 1.15k | p = frag_more (4 + 4 + 4 + 4 + descsz); |
9273 | | |
9274 | | /* Write n_namsz. */ |
9275 | 1.15k | md_number_to_chars (p, (valueT) 4, 4); |
9276 | | |
9277 | | /* Write n_descsz. */ |
9278 | 1.15k | md_number_to_chars (p + 4, (valueT) descsz, 4); |
9279 | | |
9280 | | /* Write n_type. */ |
9281 | 1.15k | md_number_to_chars (p + 4 * 2, (valueT) NT_GNU_PROPERTY_TYPE_0, 4); |
9282 | | |
9283 | | /* Write n_name. */ |
9284 | 1.15k | memcpy (p + 4 * 3, "GNU", 4); |
9285 | | |
9286 | | /* Write 4-byte type. */ |
9287 | 1.15k | md_number_to_chars (p + 4 * 4, |
9288 | 1.15k | (valueT) GNU_PROPERTY_X86_ISA_1_USED, 4); |
9289 | | |
9290 | | /* Write 4-byte data size. */ |
9291 | 1.15k | md_number_to_chars (p + 4 * 5, (valueT) 4, 4); |
9292 | | |
9293 | | /* Write 4-byte data. */ |
9294 | 1.15k | md_number_to_chars (p + 4 * 6, (valueT) x86_isa_1_used, 4); |
9295 | | |
9296 | | /* Zero out paddings. */ |
9297 | 1.15k | padding = isa_1_descsz - isa_1_descsz_raw; |
9298 | 1.15k | if (padding) |
9299 | 1.15k | memset (p + 4 * 7, 0, padding); |
9300 | | |
9301 | | /* Write 4-byte type. */ |
9302 | 1.15k | md_number_to_chars (p + isa_1_descsz + 4 * 4, |
9303 | 1.15k | (valueT) GNU_PROPERTY_X86_FEATURE_2_USED, 4); |
9304 | | |
9305 | | /* Write 4-byte data size. */ |
9306 | 1.15k | md_number_to_chars (p + isa_1_descsz + 4 * 5, (valueT) 4, 4); |
9307 | | |
9308 | | /* Write 4-byte data. */ |
9309 | 1.15k | md_number_to_chars (p + isa_1_descsz + 4 * 6, |
9310 | 1.15k | (valueT) x86_feature_2_used, 4); |
9311 | | |
9312 | | /* Zero out paddings. */ |
9313 | 1.15k | padding = feature_2_descsz - feature_2_descsz_raw; |
9314 | 1.15k | if (padding) |
9315 | 1.15k | memset (p + isa_1_descsz + 4 * 7, 0, padding); |
9316 | | |
9317 | | /* We probably can't restore the current segment, for there likely |
9318 | | isn't one yet... */ |
9319 | 1.15k | if (seg && subseg) |
9320 | 153 | subseg_set (seg, subseg); |
9321 | 1.15k | } |
9322 | | |
9323 | | bool |
9324 | | x86_support_sframe_p (void) |
9325 | 0 | { |
9326 | | /* At this time, SFrame stack trace is supported for AMD64 ABI only. */ |
9327 | 0 | return (x86_elf_abi == X86_64_ABI); |
9328 | 0 | } |
9329 | | |
9330 | | bool |
9331 | | x86_sframe_ra_tracking_p (void) |
9332 | 0 | { |
9333 | | /* In AMD64, return address is always stored on the stack at a fixed offset |
9334 | | from the CFA (provided via x86_sframe_cfa_ra_offset ()). |
9335 | | Do not track explicitly via an SFrame Frame Row Entry. */ |
9336 | 0 | return false; |
9337 | 0 | } |
9338 | | |
9339 | | offsetT |
9340 | | x86_sframe_cfa_ra_offset (void) |
9341 | 0 | { |
9342 | 0 | gas_assert (x86_elf_abi == X86_64_ABI); |
9343 | 0 | return (offsetT) -8; |
9344 | 0 | } |
9345 | | |
9346 | | unsigned char |
9347 | | x86_sframe_get_abi_arch (void) |
9348 | 0 | { |
9349 | 0 | unsigned char sframe_abi_arch = 0; |
9350 | |
|
9351 | 0 | if (x86_support_sframe_p ()) |
9352 | 0 | { |
9353 | 0 | gas_assert (!target_big_endian); |
9354 | 0 | sframe_abi_arch = SFRAME_ABI_AMD64_ENDIAN_LITTLE; |
9355 | 0 | } |
9356 | | |
9357 | 0 | return sframe_abi_arch; |
9358 | 0 | } |
9359 | | |
9360 | | #endif |
9361 | | |
9362 | | static unsigned int |
9363 | | encoding_length (const fragS *start_frag, offsetT start_off, |
9364 | | const char *frag_now_ptr) |
9365 | 326k | { |
9366 | 326k | unsigned int len = 0; |
9367 | | |
9368 | 326k | if (start_frag != frag_now) |
9369 | 150 | { |
9370 | 150 | const fragS *fr = start_frag; |
9371 | | |
9372 | 150 | do { |
9373 | 150 | len += fr->fr_fix; |
9374 | 150 | fr = fr->fr_next; |
9375 | 150 | } while (fr && fr != frag_now); |
9376 | 150 | } |
9377 | | |
9378 | 326k | return len - start_off + (frag_now_ptr - frag_now->fr_literal); |
9379 | 326k | } |
9380 | | |
9381 | | /* Return 1 for test, and, cmp, add, sub, inc and dec which may |
9382 | | be macro-fused with conditional jumps. |
9383 | | NB: If TEST/AND/CMP/ADD/SUB/INC/DEC is of RIP relative address, |
9384 | | or is one of the following format: |
9385 | | |
9386 | | cmp m, imm |
9387 | | add m, imm |
9388 | | sub m, imm |
9389 | | test m, imm |
9390 | | and m, imm |
9391 | | inc m |
9392 | | dec m |
9393 | | |
9394 | | it is unfusible. */ |
9395 | | |
9396 | | static int |
9397 | | maybe_fused_with_jcc_p (enum mf_cmp_kind* mf_cmp_p) |
9398 | 0 | { |
9399 | | /* No RIP address. */ |
9400 | 0 | if (i.base_reg && i.base_reg->reg_num == RegIP) |
9401 | 0 | return 0; |
9402 | | |
9403 | | /* No opcodes outside of base encoding space. */ |
9404 | 0 | if (i.tm.opcode_space != SPACE_BASE) |
9405 | 0 | return 0; |
9406 | | |
9407 | | /* add, sub without add/sub m, imm. */ |
9408 | 0 | if (i.tm.base_opcode <= 5 |
9409 | 0 | || (i.tm.base_opcode >= 0x28 && i.tm.base_opcode <= 0x2d) |
9410 | 0 | || ((i.tm.base_opcode | 3) == 0x83 |
9411 | 0 | && (i.tm.extension_opcode == 0x5 |
9412 | 0 | || i.tm.extension_opcode == 0x0))) |
9413 | 0 | { |
9414 | 0 | *mf_cmp_p = mf_cmp_alu_cmp; |
9415 | 0 | return !(i.mem_operands && i.imm_operands); |
9416 | 0 | } |
9417 | | |
9418 | | /* and without and m, imm. */ |
9419 | 0 | if ((i.tm.base_opcode >= 0x20 && i.tm.base_opcode <= 0x25) |
9420 | 0 | || ((i.tm.base_opcode | 3) == 0x83 |
9421 | 0 | && i.tm.extension_opcode == 0x4)) |
9422 | 0 | { |
9423 | 0 | *mf_cmp_p = mf_cmp_test_and; |
9424 | 0 | return !(i.mem_operands && i.imm_operands); |
9425 | 0 | } |
9426 | | |
9427 | | /* test without test m imm. */ |
9428 | 0 | if ((i.tm.base_opcode | 1) == 0x85 |
9429 | 0 | || (i.tm.base_opcode | 1) == 0xa9 |
9430 | 0 | || ((i.tm.base_opcode | 1) == 0xf7 |
9431 | 0 | && i.tm.extension_opcode == 0)) |
9432 | 0 | { |
9433 | 0 | *mf_cmp_p = mf_cmp_test_and; |
9434 | 0 | return !(i.mem_operands && i.imm_operands); |
9435 | 0 | } |
9436 | | |
9437 | | /* cmp without cmp m, imm. */ |
9438 | 0 | if ((i.tm.base_opcode >= 0x38 && i.tm.base_opcode <= 0x3d) |
9439 | 0 | || ((i.tm.base_opcode | 3) == 0x83 |
9440 | 0 | && (i.tm.extension_opcode == 0x7))) |
9441 | 0 | { |
9442 | 0 | *mf_cmp_p = mf_cmp_alu_cmp; |
9443 | 0 | return !(i.mem_operands && i.imm_operands); |
9444 | 0 | } |
9445 | | |
9446 | | /* inc, dec without inc/dec m. */ |
9447 | 0 | if ((is_cpu (&i.tm, CpuNo64) |
9448 | 0 | && (i.tm.base_opcode | 0xf) == 0x4f) |
9449 | 0 | || ((i.tm.base_opcode | 1) == 0xff |
9450 | 0 | && i.tm.extension_opcode <= 0x1)) |
9451 | 0 | { |
9452 | 0 | *mf_cmp_p = mf_cmp_incdec; |
9453 | 0 | return !i.mem_operands; |
9454 | 0 | } |
9455 | | |
9456 | 0 | return 0; |
9457 | 0 | } |
9458 | | |
9459 | | /* Return 1 if a FUSED_JCC_PADDING frag should be generated. */ |
9460 | | |
9461 | | static int |
9462 | | add_fused_jcc_padding_frag_p (enum mf_cmp_kind* mf_cmp_p) |
9463 | 750k | { |
9464 | | /* NB: Don't work with COND_JUMP86 without i386. */ |
9465 | 750k | if (!align_branch_power |
9466 | 750k | || now_seg == absolute_section |
9467 | 750k | || !cpu_arch_flags.bitfield.cpui386 |
9468 | 750k | || !(align_branch & align_branch_fused_bit)) |
9469 | 750k | return 0; |
9470 | | |
9471 | 0 | if (maybe_fused_with_jcc_p (mf_cmp_p)) |
9472 | 0 | { |
9473 | 0 | if (last_insn.kind == last_insn_other |
9474 | 0 | || last_insn.seg != now_seg) |
9475 | 0 | return 1; |
9476 | 0 | if (flag_debug) |
9477 | 0 | as_warn_where (last_insn.file, last_insn.line, |
9478 | 0 | _("`%s` skips -malign-branch-boundary on `%s`"), |
9479 | 0 | last_insn.name, insn_name (&i.tm)); |
9480 | 0 | } |
9481 | | |
9482 | 0 | return 0; |
9483 | 0 | } |
9484 | | |
9485 | | /* Return 1 if a BRANCH_PREFIX frag should be generated. */ |
9486 | | |
9487 | | static int |
9488 | | add_branch_prefix_frag_p (void) |
9489 | 750k | { |
9490 | | /* NB: Don't work with COND_JUMP86 without i386. Don't add prefix |
9491 | | to PadLock instructions since they include prefixes in opcode. */ |
9492 | 750k | if (!align_branch_power |
9493 | 750k | || !align_branch_prefix_size |
9494 | 750k | || now_seg == absolute_section |
9495 | 750k | || is_cpu (&i.tm, CpuPadLock) |
9496 | 750k | || !cpu_arch_flags.bitfield.cpui386) |
9497 | 750k | return 0; |
9498 | | |
9499 | | /* Don't add prefix if it is a prefix or there is no operand in case |
9500 | | that segment prefix is special. */ |
9501 | 0 | if (!i.operands || i.tm.opcode_modifier.isprefix) |
9502 | 0 | return 0; |
9503 | | |
9504 | 0 | if (last_insn.kind == last_insn_other |
9505 | 0 | || last_insn.seg != now_seg) |
9506 | 0 | return 1; |
9507 | | |
9508 | 0 | if (flag_debug) |
9509 | 0 | as_warn_where (last_insn.file, last_insn.line, |
9510 | 0 | _("`%s` skips -malign-branch-boundary on `%s`"), |
9511 | 0 | last_insn.name, insn_name (&i.tm)); |
9512 | |
|
9513 | 0 | return 0; |
9514 | 0 | } |
9515 | | |
9516 | | /* Return 1 if a BRANCH_PADDING frag should be generated. */ |
9517 | | |
9518 | | static int |
9519 | | add_branch_padding_frag_p (enum align_branch_kind *branch_p, |
9520 | | enum mf_jcc_kind *mf_jcc_p) |
9521 | 772k | { |
9522 | 772k | int add_padding; |
9523 | | |
9524 | | /* NB: Don't work with COND_JUMP86 without i386. */ |
9525 | 772k | if (!align_branch_power |
9526 | 772k | || now_seg == absolute_section |
9527 | 772k | || !cpu_arch_flags.bitfield.cpui386 |
9528 | 772k | || i.tm.opcode_space != SPACE_BASE) |
9529 | 772k | return 0; |
9530 | | |
9531 | 0 | add_padding = 0; |
9532 | | |
9533 | | /* Check for jcc and direct jmp. */ |
9534 | 0 | if (i.tm.opcode_modifier.jump == JUMP) |
9535 | 0 | { |
9536 | 0 | if (i.tm.base_opcode == JUMP_PC_RELATIVE) |
9537 | 0 | { |
9538 | 0 | *branch_p = align_branch_jmp; |
9539 | 0 | add_padding = align_branch & align_branch_jmp_bit; |
9540 | 0 | } |
9541 | 0 | else |
9542 | 0 | { |
9543 | | /* Because J<cc> and JN<cc> share same group in macro-fusible table, |
9544 | | igore the lowest bit. */ |
9545 | 0 | *mf_jcc_p = (i.tm.base_opcode & 0x0e) >> 1; |
9546 | 0 | *branch_p = align_branch_jcc; |
9547 | 0 | if ((align_branch & align_branch_jcc_bit)) |
9548 | 0 | add_padding = 1; |
9549 | 0 | } |
9550 | 0 | } |
9551 | 0 | else if ((i.tm.base_opcode | 1) == 0xc3) |
9552 | 0 | { |
9553 | | /* Near ret. */ |
9554 | 0 | *branch_p = align_branch_ret; |
9555 | 0 | if ((align_branch & align_branch_ret_bit)) |
9556 | 0 | add_padding = 1; |
9557 | 0 | } |
9558 | 0 | else |
9559 | 0 | { |
9560 | | /* Check for indirect jmp, direct and indirect calls. */ |
9561 | 0 | if (i.tm.base_opcode == 0xe8) |
9562 | 0 | { |
9563 | | /* Direct call. */ |
9564 | 0 | *branch_p = align_branch_call; |
9565 | 0 | if ((align_branch & align_branch_call_bit)) |
9566 | 0 | add_padding = 1; |
9567 | 0 | } |
9568 | 0 | else if (i.tm.base_opcode == 0xff |
9569 | 0 | && (i.tm.extension_opcode == 2 |
9570 | 0 | || i.tm.extension_opcode == 4)) |
9571 | 0 | { |
9572 | | /* Indirect call and jmp. */ |
9573 | 0 | *branch_p = align_branch_indirect; |
9574 | 0 | if ((align_branch & align_branch_indirect_bit)) |
9575 | 0 | add_padding = 1; |
9576 | 0 | } |
9577 | |
|
9578 | 0 | if (add_padding |
9579 | 0 | && i.disp_operands |
9580 | 0 | && tls_get_addr |
9581 | 0 | && (i.op[0].disps->X_op == O_symbol |
9582 | 0 | || (i.op[0].disps->X_op == O_subtract |
9583 | 0 | && i.op[0].disps->X_op_symbol == GOT_symbol))) |
9584 | 0 | { |
9585 | 0 | symbolS *s = i.op[0].disps->X_add_symbol; |
9586 | | /* No padding to call to global or undefined tls_get_addr. */ |
9587 | 0 | if ((S_IS_EXTERNAL (s) || !S_IS_DEFINED (s)) |
9588 | 0 | && strcmp (S_GET_NAME (s), tls_get_addr) == 0) |
9589 | 0 | return 0; |
9590 | 0 | } |
9591 | 0 | } |
9592 | | |
9593 | 0 | if (add_padding |
9594 | 0 | && last_insn.kind != last_insn_other |
9595 | 0 | && last_insn.seg == now_seg) |
9596 | 0 | { |
9597 | 0 | if (flag_debug) |
9598 | 0 | as_warn_where (last_insn.file, last_insn.line, |
9599 | 0 | _("`%s` skips -malign-branch-boundary on `%s`"), |
9600 | 0 | last_insn.name, insn_name (&i.tm)); |
9601 | 0 | return 0; |
9602 | 0 | } |
9603 | | |
9604 | 0 | return add_padding; |
9605 | 0 | } |
9606 | | |
9607 | | static void |
9608 | | output_insn (void) |
9609 | 772k | { |
9610 | 772k | fragS *insn_start_frag; |
9611 | 772k | offsetT insn_start_off; |
9612 | 772k | fragS *fragP = NULL; |
9613 | 772k | enum align_branch_kind branch = align_branch_none; |
9614 | | /* The initializer is arbitrary just to avoid uninitialized error. |
9615 | | it's actually either assigned in add_branch_padding_frag_p |
9616 | | or never be used. */ |
9617 | 772k | enum mf_jcc_kind mf_jcc = mf_jcc_jo; |
9618 | | |
9619 | 772k | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
9620 | 772k | if (IS_ELF && x86_used_note && now_seg != absolute_section) |
9621 | 347k | { |
9622 | 347k | if ((i.xstate & xstate_tmm) == xstate_tmm |
9623 | 347k | || is_cpu (&i.tm, CpuAMX_TILE)) |
9624 | 6 | x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_TMM; |
9625 | | |
9626 | 347k | if (is_cpu (&i.tm, Cpu8087) |
9627 | 347k | || is_cpu (&i.tm, Cpu287) |
9628 | 347k | || is_cpu (&i.tm, Cpu387) |
9629 | 347k | || is_cpu (&i.tm, Cpu687) |
9630 | 347k | || is_cpu (&i.tm, CpuFISTTP)) |
9631 | 2.47k | x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_X87; |
9632 | | |
9633 | 347k | if ((i.xstate & xstate_mmx) |
9634 | 347k | || i.tm.mnem_off == MN_emms |
9635 | 347k | || i.tm.mnem_off == MN_femms) |
9636 | 1 | x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_MMX; |
9637 | | |
9638 | 347k | if (i.index_reg) |
9639 | 0 | { |
9640 | 0 | if (i.index_reg->reg_type.bitfield.zmmword) |
9641 | 0 | i.xstate |= xstate_zmm; |
9642 | 0 | else if (i.index_reg->reg_type.bitfield.ymmword) |
9643 | 0 | i.xstate |= xstate_ymm; |
9644 | 0 | else if (i.index_reg->reg_type.bitfield.xmmword) |
9645 | 0 | i.xstate |= xstate_xmm; |
9646 | 0 | } |
9647 | | |
9648 | | /* vzeroall / vzeroupper */ |
9649 | 347k | if (i.tm.base_opcode == 0x77 && is_cpu (&i.tm, CpuAVX)) |
9650 | 0 | i.xstate |= xstate_ymm; |
9651 | | |
9652 | 347k | if ((i.xstate & xstate_xmm) |
9653 | | /* ldmxcsr / stmxcsr / vldmxcsr / vstmxcsr */ |
9654 | 347k | || (i.tm.base_opcode == 0xae |
9655 | 347k | && (is_cpu (&i.tm, CpuSSE) |
9656 | 24 | || is_cpu (&i.tm, CpuAVX))) |
9657 | 347k | || is_cpu (&i.tm, CpuWideKL) |
9658 | 347k | || is_cpu (&i.tm, CpuKL)) |
9659 | 0 | x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_XMM; |
9660 | | |
9661 | 347k | if ((i.xstate & xstate_ymm) == xstate_ymm) |
9662 | 0 | x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_YMM; |
9663 | 347k | if ((i.xstate & xstate_zmm) == xstate_zmm) |
9664 | 0 | x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_ZMM; |
9665 | 347k | if (i.mask.reg || (i.xstate & xstate_mask) == xstate_mask) |
9666 | 0 | x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_MASK; |
9667 | 347k | if (is_cpu (&i.tm, CpuFXSR)) |
9668 | 0 | x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_FXSR; |
9669 | 347k | if (is_cpu (&i.tm, CpuXsave)) |
9670 | 204 | x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_XSAVE; |
9671 | 347k | if (is_cpu (&i.tm, CpuXsaveopt)) |
9672 | 0 | x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT; |
9673 | 347k | if (is_cpu (&i.tm, CpuXSAVEC)) |
9674 | 1 | x86_feature_2_used |= GNU_PROPERTY_X86_FEATURE_2_XSAVEC; |
9675 | | |
9676 | 347k | if (x86_feature_2_used |
9677 | 347k | || is_cpu (&i.tm, CpuCMOV) |
9678 | 347k | || is_cpu (&i.tm, CpuSYSCALL) |
9679 | 347k | || i.tm.mnem_off == MN_cmpxchg8b) |
9680 | 347k | x86_isa_1_used |= GNU_PROPERTY_X86_ISA_1_BASELINE; |
9681 | 347k | if (is_cpu (&i.tm, CpuSSE3) |
9682 | 347k | || is_cpu (&i.tm, CpuSSSE3) |
9683 | 347k | || is_cpu (&i.tm, CpuSSE4_1) |
9684 | 347k | || is_cpu (&i.tm, CpuSSE4_2) |
9685 | 347k | || is_cpu (&i.tm, CpuCX16) |
9686 | 347k | || is_cpu (&i.tm, CpuPOPCNT) |
9687 | | /* LAHF-SAHF insns in 64-bit mode. */ |
9688 | 347k | || (flag_code == CODE_64BIT |
9689 | 347k | && (i.tm.base_opcode | 1) == 0x9f |
9690 | 347k | && i.tm.opcode_space == SPACE_BASE)) |
9691 | 1 | x86_isa_1_used |= GNU_PROPERTY_X86_ISA_1_V2; |
9692 | 347k | if (is_cpu (&i.tm, CpuAVX) |
9693 | 347k | || is_cpu (&i.tm, CpuAVX2) |
9694 | | /* Any VEX encoded insns execpt for AVX512F, AVX512BW, AVX512DQ, |
9695 | | XOP, FMA4, LPW, TBM, and AMX. */ |
9696 | 347k | || (i.tm.opcode_modifier.vex |
9697 | 347k | && !is_cpu (&i.tm, CpuAVX512F) |
9698 | 347k | && !is_cpu (&i.tm, CpuAVX512BW) |
9699 | 347k | && !is_cpu (&i.tm, CpuAVX512DQ) |
9700 | 347k | && !is_cpu (&i.tm, CpuXOP) |
9701 | 347k | && !is_cpu (&i.tm, CpuFMA4) |
9702 | 347k | && !is_cpu (&i.tm, CpuLWP) |
9703 | 347k | && !is_cpu (&i.tm, CpuTBM) |
9704 | 347k | && !(x86_feature_2_used & GNU_PROPERTY_X86_FEATURE_2_TMM)) |
9705 | 347k | || is_cpu (&i.tm, CpuF16C) |
9706 | 347k | || is_cpu (&i.tm, CpuFMA) |
9707 | 347k | || is_cpu (&i.tm, CpuLZCNT) |
9708 | 347k | || is_cpu (&i.tm, CpuMovbe) |
9709 | 347k | || is_cpu (&i.tm, CpuXSAVES) |
9710 | 347k | || (x86_feature_2_used |
9711 | 347k | & (GNU_PROPERTY_X86_FEATURE_2_XSAVE |
9712 | 347k | | GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT |
9713 | 347k | | GNU_PROPERTY_X86_FEATURE_2_XSAVEC)) != 0) |
9714 | 346k | x86_isa_1_used |= GNU_PROPERTY_X86_ISA_1_V3; |
9715 | 347k | if (is_cpu (&i.tm, CpuAVX512F) |
9716 | 347k | || is_cpu (&i.tm, CpuAVX512BW) |
9717 | 347k | || is_cpu (&i.tm, CpuAVX512DQ) |
9718 | 347k | || is_cpu (&i.tm, CpuAVX512VL) |
9719 | | /* Any EVEX encoded insns except for AVX512ER, AVX512PF, |
9720 | | AVX512-4FMAPS, and AVX512-4VNNIW. */ |
9721 | 347k | || (i.tm.opcode_modifier.evex |
9722 | 347k | && !is_cpu (&i.tm, CpuAVX512ER) |
9723 | 347k | && !is_cpu (&i.tm, CpuAVX512PF) |
9724 | 347k | && !is_cpu (&i.tm, CpuAVX512_4FMAPS) |
9725 | 347k | && !is_cpu (&i.tm, CpuAVX512_4VNNIW))) |
9726 | 0 | x86_isa_1_used |= GNU_PROPERTY_X86_ISA_1_V4; |
9727 | 347k | } |
9728 | 772k | #endif |
9729 | | |
9730 | | /* Tie dwarf2 debug info to the address at the start of the insn. |
9731 | | We can't do this after the insn has been output as the current |
9732 | | frag may have been closed off. eg. by frag_var. */ |
9733 | 772k | dwarf2_emit_insn (0); |
9734 | | |
9735 | 772k | insn_start_frag = frag_now; |
9736 | 772k | insn_start_off = frag_now_fix (); |
9737 | | |
9738 | 772k | if (add_branch_padding_frag_p (&branch, &mf_jcc)) |
9739 | 0 | { |
9740 | 0 | char *p; |
9741 | | /* Branch can be 8 bytes. Leave some room for prefixes. */ |
9742 | 0 | unsigned int max_branch_padding_size = 14; |
9743 | | |
9744 | | /* Align section to boundary. */ |
9745 | 0 | record_alignment (now_seg, align_branch_power); |
9746 | | |
9747 | | /* Make room for padding. */ |
9748 | 0 | frag_grow (max_branch_padding_size); |
9749 | | |
9750 | | /* Start of the padding. */ |
9751 | 0 | p = frag_more (0); |
9752 | |
|
9753 | 0 | fragP = frag_now; |
9754 | |
|
9755 | 0 | frag_var (rs_machine_dependent, max_branch_padding_size, 0, |
9756 | 0 | ENCODE_RELAX_STATE (BRANCH_PADDING, 0), |
9757 | 0 | NULL, 0, p); |
9758 | |
|
9759 | 0 | fragP->tc_frag_data.mf_type = mf_jcc; |
9760 | 0 | fragP->tc_frag_data.branch_type = branch; |
9761 | 0 | fragP->tc_frag_data.max_bytes = max_branch_padding_size; |
9762 | 0 | } |
9763 | | |
9764 | 772k | if (!cpu_arch_flags.bitfield.cpui386 && (flag_code != CODE_16BIT) |
9765 | 772k | && !pre_386_16bit_warned) |
9766 | 0 | { |
9767 | 0 | as_warn (_("use .code16 to ensure correct addressing mode")); |
9768 | 0 | pre_386_16bit_warned = true; |
9769 | 0 | } |
9770 | | |
9771 | | /* Output jumps. */ |
9772 | 772k | if (i.tm.opcode_modifier.jump == JUMP) |
9773 | 21.0k | output_branch (); |
9774 | 751k | else if (i.tm.opcode_modifier.jump == JUMP_BYTE |
9775 | 751k | || i.tm.opcode_modifier.jump == JUMP_DWORD) |
9776 | 1.07k | output_jump (); |
9777 | 750k | else if (i.tm.opcode_modifier.jump == JUMP_INTERSEGMENT) |
9778 | 0 | output_interseg_jump (); |
9779 | 750k | else |
9780 | 750k | { |
9781 | | /* Output normal instructions here. */ |
9782 | 750k | char *p; |
9783 | 750k | unsigned char *q; |
9784 | 750k | unsigned int j; |
9785 | 750k | enum mf_cmp_kind mf_cmp; |
9786 | | |
9787 | 750k | if (avoid_fence |
9788 | 750k | && (i.tm.base_opcode == 0xaee8 |
9789 | 0 | || i.tm.base_opcode == 0xaef0 |
9790 | 0 | || i.tm.base_opcode == 0xaef8)) |
9791 | 0 | { |
9792 | | /* Encode lfence, mfence, and sfence as |
9793 | | f0 83 04 24 00 lock addl $0x0, (%{re}sp). */ |
9794 | 0 | if (flag_code == CODE_16BIT) |
9795 | 0 | as_bad (_("Cannot convert `%s' in 16-bit mode"), insn_name (&i.tm)); |
9796 | 0 | else if (omit_lock_prefix) |
9797 | 0 | as_bad (_("Cannot convert `%s' with `-momit-lock-prefix=yes' in effect"), |
9798 | 0 | insn_name (&i.tm)); |
9799 | 0 | else if (now_seg != absolute_section) |
9800 | 0 | { |
9801 | 0 | offsetT val = 0x240483f0ULL; |
9802 | |
|
9803 | 0 | p = frag_more (5); |
9804 | 0 | md_number_to_chars (p, val, 5); |
9805 | 0 | } |
9806 | 0 | else |
9807 | 0 | abs_section_offset += 5; |
9808 | 0 | return; |
9809 | 0 | } |
9810 | | |
9811 | | /* Some processors fail on LOCK prefix. This options makes |
9812 | | assembler ignore LOCK prefix and serves as a workaround. */ |
9813 | 750k | if (omit_lock_prefix) |
9814 | 0 | { |
9815 | 0 | if (i.tm.base_opcode == LOCK_PREFIX_OPCODE |
9816 | 0 | && i.tm.opcode_modifier.isprefix) |
9817 | 0 | return; |
9818 | 0 | i.prefix[LOCK_PREFIX] = 0; |
9819 | 0 | } |
9820 | | |
9821 | 750k | if (branch) |
9822 | | /* Skip if this is a branch. */ |
9823 | 0 | ; |
9824 | 750k | else if (add_fused_jcc_padding_frag_p (&mf_cmp)) |
9825 | 0 | { |
9826 | | /* Make room for padding. */ |
9827 | 0 | frag_grow (MAX_FUSED_JCC_PADDING_SIZE); |
9828 | 0 | p = frag_more (0); |
9829 | |
|
9830 | 0 | fragP = frag_now; |
9831 | |
|
9832 | 0 | frag_var (rs_machine_dependent, MAX_FUSED_JCC_PADDING_SIZE, 0, |
9833 | 0 | ENCODE_RELAX_STATE (FUSED_JCC_PADDING, 0), |
9834 | 0 | NULL, 0, p); |
9835 | |
|
9836 | 0 | fragP->tc_frag_data.mf_type = mf_cmp; |
9837 | 0 | fragP->tc_frag_data.branch_type = align_branch_fused; |
9838 | 0 | fragP->tc_frag_data.max_bytes = MAX_FUSED_JCC_PADDING_SIZE; |
9839 | 0 | } |
9840 | 750k | else if (add_branch_prefix_frag_p ()) |
9841 | 0 | { |
9842 | 0 | unsigned int max_prefix_size = align_branch_prefix_size; |
9843 | | |
9844 | | /* Make room for padding. */ |
9845 | 0 | frag_grow (max_prefix_size); |
9846 | 0 | p = frag_more (0); |
9847 | |
|
9848 | 0 | fragP = frag_now; |
9849 | |
|
9850 | 0 | frag_var (rs_machine_dependent, max_prefix_size, 0, |
9851 | 0 | ENCODE_RELAX_STATE (BRANCH_PREFIX, 0), |
9852 | 0 | NULL, 0, p); |
9853 | |
|
9854 | 0 | fragP->tc_frag_data.max_bytes = max_prefix_size; |
9855 | 0 | } |
9856 | | |
9857 | | /* Since the VEX/EVEX prefix contains the implicit prefix, we |
9858 | | don't need the explicit prefix. */ |
9859 | 750k | if (!is_any_vex_encoding (&i.tm)) |
9860 | 750k | { |
9861 | 750k | switch (i.tm.opcode_modifier.opcodeprefix) |
9862 | 750k | { |
9863 | 24 | case PREFIX_0X66: |
9864 | 24 | add_prefix (0x66); |
9865 | 24 | break; |
9866 | 0 | case PREFIX_0XF2: |
9867 | 0 | add_prefix (0xf2); |
9868 | 0 | break; |
9869 | 26 | case PREFIX_0XF3: |
9870 | 26 | if (!is_cpu (&i.tm, CpuPadLock) |
9871 | 26 | || (i.prefix[REP_PREFIX] != 0xf3)) |
9872 | 26 | add_prefix (0xf3); |
9873 | 26 | break; |
9874 | 750k | case PREFIX_NONE: |
9875 | 750k | switch (i.opcode_length) |
9876 | 750k | { |
9877 | 412 | case 2: |
9878 | 412 | break; |
9879 | 749k | case 1: |
9880 | | /* Check for pseudo prefixes. */ |
9881 | 749k | if (!i.tm.opcode_modifier.isprefix || i.tm.base_opcode) |
9882 | 749k | break; |
9883 | 40 | as_bad_where (insn_start_frag->fr_file, |
9884 | 40 | insn_start_frag->fr_line, |
9885 | 40 | _("pseudo prefix without instruction")); |
9886 | 40 | return; |
9887 | 0 | default: |
9888 | 0 | abort (); |
9889 | 750k | } |
9890 | 750k | break; |
9891 | 750k | default: |
9892 | 0 | abort (); |
9893 | 750k | } |
9894 | | |
9895 | 750k | #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF) |
9896 | | /* For x32, add a dummy REX_OPCODE prefix for mov/add with |
9897 | | R_X86_64_GOTTPOFF relocation so that linker can safely |
9898 | | perform IE->LE optimization. A dummy REX_OPCODE prefix |
9899 | | is also needed for lea with R_X86_64_GOTPC32_TLSDESC |
9900 | | relocation for GDesc -> IE/LE optimization. */ |
9901 | 750k | if (x86_elf_abi == X86_64_X32_ABI |
9902 | 750k | && i.operands == 2 |
9903 | 750k | && (i.reloc[0] == BFD_RELOC_X86_64_GOTTPOFF |
9904 | 0 | || i.reloc[0] == BFD_RELOC_X86_64_GOTPC32_TLSDESC) |
9905 | 750k | && i.prefix[REX_PREFIX] == 0) |
9906 | 0 | add_prefix (REX_OPCODE); |
9907 | 750k | #endif |
9908 | | |
9909 | | /* The prefix bytes. */ |
9910 | 6.00M | for (j = ARRAY_SIZE (i.prefix), q = i.prefix; j > 0; j--, q++) |
9911 | 5.25M | if (*q) |
9912 | 3.18k | frag_opcode_byte (*q); |
9913 | 750k | } |
9914 | 6 | else |
9915 | 6 | { |
9916 | 48 | for (j = 0, q = i.prefix; j < ARRAY_SIZE (i.prefix); j++, q++) |
9917 | 42 | if (*q) |
9918 | 0 | switch (j) |
9919 | 0 | { |
9920 | 0 | case SEG_PREFIX: |
9921 | 0 | case ADDR_PREFIX: |
9922 | 0 | frag_opcode_byte (*q); |
9923 | 0 | break; |
9924 | 0 | default: |
9925 | | /* There should be no other prefixes for instructions |
9926 | | with VEX prefix. */ |
9927 | 0 | abort (); |
9928 | 0 | } |
9929 | | |
9930 | | /* For EVEX instructions i.vrex should become 0 after |
9931 | | build_evex_prefix. For VEX instructions upper 16 registers |
9932 | | aren't available, so VREX should be 0. */ |
9933 | 6 | if (i.vrex) |
9934 | 0 | abort (); |
9935 | | /* Now the VEX prefix. */ |
9936 | 6 | if (now_seg != absolute_section) |
9937 | 6 | { |
9938 | 6 | p = frag_more (i.vex.length); |
9939 | 24 | for (j = 0; j < i.vex.length; j++) |
9940 | 18 | p[j] = i.vex.bytes[j]; |
9941 | 6 | } |
9942 | 0 | else |
9943 | 0 | abs_section_offset += i.vex.length; |
9944 | 6 | } |
9945 | | |
9946 | | /* Now the opcode; be careful about word order here! */ |
9947 | 750k | j = i.opcode_length; |
9948 | 750k | if (!i.vex.length) |
9949 | 750k | switch (i.tm.opcode_space) |
9950 | 750k | { |
9951 | 744k | case SPACE_BASE: |
9952 | 744k | break; |
9953 | 5.90k | case SPACE_0F: |
9954 | 5.90k | ++j; |
9955 | 5.90k | break; |
9956 | 0 | case SPACE_0F38: |
9957 | 0 | case SPACE_0F3A: |
9958 | 0 | j += 2; |
9959 | 0 | break; |
9960 | 0 | default: |
9961 | 0 | abort (); |
9962 | 750k | } |
9963 | | |
9964 | 750k | if (now_seg == absolute_section) |
9965 | 423k | abs_section_offset += j; |
9966 | 326k | else if (j == 1) |
9967 | 320k | { |
9968 | 320k | FRAG_APPEND_1_CHAR (i.tm.base_opcode); |
9969 | 320k | } |
9970 | 6.00k | else |
9971 | 6.00k | { |
9972 | 6.00k | p = frag_more (j); |
9973 | 6.00k | if (!i.vex.length |
9974 | 6.00k | && i.tm.opcode_space != SPACE_BASE) |
9975 | 5.85k | { |
9976 | 5.85k | *p++ = 0x0f; |
9977 | 5.85k | if (i.tm.opcode_space != SPACE_0F) |
9978 | 0 | *p++ = i.tm.opcode_space == SPACE_0F38 |
9979 | 0 | ? 0x38 : 0x3a; |
9980 | 5.85k | } |
9981 | | |
9982 | 6.00k | switch (i.opcode_length) |
9983 | 6.00k | { |
9984 | 369 | case 2: |
9985 | | /* Put out high byte first: can't use md_number_to_chars! */ |
9986 | 369 | *p++ = (i.tm.base_opcode >> 8) & 0xff; |
9987 | | /* Fall through. */ |
9988 | 6.00k | case 1: |
9989 | 6.00k | *p = i.tm.base_opcode & 0xff; |
9990 | 6.00k | break; |
9991 | 0 | default: |
9992 | 0 | abort (); |
9993 | 0 | break; |
9994 | 6.00k | } |
9995 | | |
9996 | 6.00k | } |
9997 | | |
9998 | | /* Now the modrm byte and sib byte (if present). */ |
9999 | 750k | if (i.tm.opcode_modifier.modrm) |
10000 | 98.7k | { |
10001 | 98.7k | frag_opcode_byte ((i.rm.regmem << 0) |
10002 | 98.7k | | (i.rm.reg << 3) |
10003 | 98.7k | | (i.rm.mode << 6)); |
10004 | | /* If i.rm.regmem == ESP (4) |
10005 | | && i.rm.mode != (Register mode) |
10006 | | && not 16 bit |
10007 | | ==> need second modrm byte. */ |
10008 | 98.7k | if (i.rm.regmem == ESCAPE_TO_TWO_BYTE_ADDRESSING |
10009 | 98.7k | && i.rm.mode != 3 |
10010 | 98.7k | && !(i.base_reg && i.base_reg->reg_type.bitfield.word)) |
10011 | 32.5k | frag_opcode_byte ((i.sib.base << 0) |
10012 | 32.5k | | (i.sib.index << 3) |
10013 | 32.5k | | (i.sib.scale << 6)); |
10014 | 98.7k | } |
10015 | | |
10016 | 750k | if (i.disp_operands) |
10017 | 98.7k | output_disp (insn_start_frag, insn_start_off); |
10018 | | |
10019 | 750k | if (i.imm_operands) |
10020 | 93.2k | output_imm (insn_start_frag, insn_start_off); |
10021 | | |
10022 | | /* |
10023 | | * frag_now_fix () returning plain abs_section_offset when we're in the |
10024 | | * absolute section, and abs_section_offset not getting updated as data |
10025 | | * gets added to the frag breaks the logic below. |
10026 | | */ |
10027 | 750k | if (now_seg != absolute_section) |
10028 | 326k | { |
10029 | 326k | j = encoding_length (insn_start_frag, insn_start_off, frag_more (0)); |
10030 | 326k | if (j > 15) |
10031 | 0 | as_warn (_("instruction length of %u bytes exceeds the limit of 15"), |
10032 | 0 | j); |
10033 | 326k | else if (fragP) |
10034 | 0 | { |
10035 | | /* NB: Don't add prefix with GOTPC relocation since |
10036 | | output_disp() above depends on the fixed encoding |
10037 | | length. Can't add prefix with TLS relocation since |
10038 | | it breaks TLS linker optimization. */ |
10039 | 0 | unsigned int max = i.has_gotpc_tls_reloc ? 0 : 15 - j; |
10040 | | /* Prefix count on the current instruction. */ |
10041 | 0 | unsigned int count = i.vex.length; |
10042 | 0 | unsigned int k; |
10043 | 0 | for (k = 0; k < ARRAY_SIZE (i.prefix); k++) |
10044 | | /* REX byte is encoded in VEX/EVEX prefix. */ |
10045 | 0 | if (i.prefix[k] && (k != REX_PREFIX || !i.vex.length)) |
10046 | 0 | count++; |
10047 | | |
10048 | | /* Count prefixes for extended opcode maps. */ |
10049 | 0 | if (!i.vex.length) |
10050 | 0 | switch (i.tm.opcode_space) |
10051 | 0 | { |
10052 | 0 | case SPACE_BASE: |
10053 | 0 | break; |
10054 | 0 | case SPACE_0F: |
10055 | 0 | count++; |
10056 | 0 | break; |
10057 | 0 | case SPACE_0F38: |
10058 | 0 | case SPACE_0F3A: |
10059 | 0 | count += 2; |
10060 | 0 | break; |
10061 | 0 | default: |
10062 | 0 | abort (); |
10063 | 0 | } |
10064 | | |
10065 | 0 | if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) |
10066 | 0 | == BRANCH_PREFIX) |
10067 | 0 | { |
10068 | | /* Set the maximum prefix size in BRANCH_PREFIX |
10069 | | frag. */ |
10070 | 0 | if (fragP->tc_frag_data.max_bytes > max) |
10071 | 0 | fragP->tc_frag_data.max_bytes = max; |
10072 | 0 | if (fragP->tc_frag_data.max_bytes > count) |
10073 | 0 | fragP->tc_frag_data.max_bytes -= count; |
10074 | 0 | else |
10075 | 0 | fragP->tc_frag_data.max_bytes = 0; |
10076 | 0 | } |
10077 | 0 | else |
10078 | 0 | { |
10079 | | /* Remember the maximum prefix size in FUSED_JCC_PADDING |
10080 | | frag. */ |
10081 | 0 | unsigned int max_prefix_size; |
10082 | 0 | if (align_branch_prefix_size > max) |
10083 | 0 | max_prefix_size = max; |
10084 | 0 | else |
10085 | 0 | max_prefix_size = align_branch_prefix_size; |
10086 | 0 | if (max_prefix_size > count) |
10087 | 0 | fragP->tc_frag_data.max_prefix_length |
10088 | 0 | = max_prefix_size - count; |
10089 | 0 | } |
10090 | | |
10091 | | /* Use existing segment prefix if possible. Use CS |
10092 | | segment prefix in 64-bit mode. In 32-bit mode, use SS |
10093 | | segment prefix with ESP/EBP base register and use DS |
10094 | | segment prefix without ESP/EBP base register. */ |
10095 | 0 | if (i.prefix[SEG_PREFIX]) |
10096 | 0 | fragP->tc_frag_data.default_prefix = i.prefix[SEG_PREFIX]; |
10097 | 0 | else if (flag_code == CODE_64BIT) |
10098 | 0 | fragP->tc_frag_data.default_prefix = CS_PREFIX_OPCODE; |
10099 | 0 | else if (i.base_reg |
10100 | 0 | && (i.base_reg->reg_num == 4 |
10101 | 0 | || i.base_reg->reg_num == 5)) |
10102 | 0 | fragP->tc_frag_data.default_prefix = SS_PREFIX_OPCODE; |
10103 | 0 | else |
10104 | 0 | fragP->tc_frag_data.default_prefix = DS_PREFIX_OPCODE; |
10105 | 0 | } |
10106 | 326k | } |
10107 | 750k | } |
10108 | | |
10109 | | /* NB: Don't work with COND_JUMP86 without i386. */ |
10110 | 772k | if (align_branch_power |
10111 | 772k | && now_seg != absolute_section |
10112 | 772k | && cpu_arch_flags.bitfield.cpui386) |
10113 | 0 | { |
10114 | | /* Terminate each frag so that we can add prefix and check for |
10115 | | fused jcc. */ |
10116 | 0 | frag_wane (frag_now); |
10117 | 0 | frag_new (0); |
10118 | 0 | } |
10119 | | |
10120 | | #ifdef DEBUG386 |
10121 | | if (flag_debug) |
10122 | | { |
10123 | | pi ("" /*line*/, &i); |
10124 | | } |
10125 | | #endif /* DEBUG386 */ |
10126 | 772k | } |
10127 | | |
10128 | | /* Return the size of the displacement operand N. */ |
10129 | | |
10130 | | static int |
10131 | | disp_size (unsigned int n) |
10132 | 98.7k | { |
10133 | 98.7k | int size = 4; |
10134 | | |
10135 | 98.7k | if (i.types[n].bitfield.disp64) |
10136 | 0 | size = 8; |
10137 | 98.7k | else if (i.types[n].bitfield.disp8) |
10138 | 0 | size = 1; |
10139 | 98.7k | else if (i.types[n].bitfield.disp16) |
10140 | 47.6k | size = 2; |
10141 | 98.7k | return size; |
10142 | 98.7k | } |
10143 | | |
10144 | | /* Return the size of the immediate operand N. */ |
10145 | | |
10146 | | static int |
10147 | | imm_size (unsigned int n) |
10148 | 93.2k | { |
10149 | 93.2k | int size = 4; |
10150 | 93.2k | if (i.types[n].bitfield.imm64) |
10151 | 0 | size = 8; |
10152 | 93.2k | else if (i.types[n].bitfield.imm8 || i.types[n].bitfield.imm8s) |
10153 | 84.9k | size = 1; |
10154 | 8.33k | else if (i.types[n].bitfield.imm16) |
10155 | 5.77k | size = 2; |
10156 | 93.2k | return size; |
10157 | 93.2k | } |
10158 | | |
10159 | | static void |
10160 | | output_disp (fragS *insn_start_frag, offsetT insn_start_off) |
10161 | 98.7k | { |
10162 | 98.7k | char *p; |
10163 | 98.7k | unsigned int n; |
10164 | | |
10165 | 289k | for (n = 0; n < i.operands; n++) |
10166 | 190k | { |
10167 | 190k | if (operand_type_check (i.types[n], disp)) |
10168 | 98.7k | { |
10169 | 98.7k | int size = disp_size (n); |
10170 | | |
10171 | 98.7k | if (now_seg == absolute_section) |
10172 | 2.45k | abs_section_offset += size; |
10173 | 96.2k | else if (i.op[n].disps->X_op == O_constant) |
10174 | 84.6k | { |
10175 | 84.6k | offsetT val = i.op[n].disps->X_add_number; |
10176 | | |
10177 | 84.6k | val = offset_in_range (val >> (size == 1 ? i.memshift : 0), |
10178 | 84.6k | size); |
10179 | 84.6k | p = frag_more (size); |
10180 | 84.6k | md_number_to_chars (p, val, size); |
10181 | 84.6k | } |
10182 | 11.6k | else |
10183 | 11.6k | { |
10184 | 11.6k | enum bfd_reloc_code_real reloc_type; |
10185 | 11.6k | bool pcrel = (i.flags[n] & Operand_PCrel) != 0; |
10186 | 11.6k | bool sign = (flag_code == CODE_64BIT && size == 4 |
10187 | 11.6k | && (!want_disp32 (&i.tm) |
10188 | 5.20k | || (i.tm.opcode_modifier.jump && !i.jumpabsolute |
10189 | 0 | && !i.types[n].bitfield.baseindex))) |
10190 | 11.6k | || pcrel; |
10191 | 11.6k | fixS *fixP; |
10192 | | |
10193 | | /* We can't have 8 bit displacement here. */ |
10194 | 11.6k | gas_assert (!i.types[n].bitfield.disp8); |
10195 | | |
10196 | | /* The PC relative address is computed relative |
10197 | | to the instruction boundary, so in case immediate |
10198 | | fields follows, we need to adjust the value. */ |
10199 | 11.6k | if (pcrel && i.imm_operands) |
10200 | 0 | { |
10201 | 0 | unsigned int n1; |
10202 | 0 | int sz = 0; |
10203 | |
|
10204 | 0 | for (n1 = 0; n1 < i.operands; n1++) |
10205 | 0 | if (operand_type_check (i.types[n1], imm)) |
10206 | 0 | { |
10207 | | /* Only one immediate is allowed for PC |
10208 | | relative address, except with .insn. */ |
10209 | 0 | gas_assert (sz == 0 || dot_insn ()); |
10210 | 0 | sz += imm_size (n1); |
10211 | 0 | } |
10212 | | /* We should find at least one immediate. */ |
10213 | 0 | gas_assert (sz != 0); |
10214 | 0 | i.op[n].disps->X_add_number -= sz; |
10215 | 0 | } |
10216 | | |
10217 | 0 | p = frag_more (size); |
10218 | 11.6k | reloc_type = reloc (size, pcrel, sign, i.reloc[n]); |
10219 | 11.6k | if (GOT_symbol |
10220 | 11.6k | && GOT_symbol == i.op[n].disps->X_add_symbol |
10221 | 11.6k | && (((reloc_type == BFD_RELOC_32 |
10222 | 0 | || reloc_type == BFD_RELOC_X86_64_32S |
10223 | 0 | || (reloc_type == BFD_RELOC_64 |
10224 | 0 | && object_64bit)) |
10225 | 0 | && (i.op[n].disps->X_op == O_symbol |
10226 | 0 | || (i.op[n].disps->X_op == O_add |
10227 | 0 | && ((symbol_get_value_expression |
10228 | 0 | (i.op[n].disps->X_op_symbol)->X_op) |
10229 | 0 | == O_subtract)))) |
10230 | 0 | || reloc_type == BFD_RELOC_32_PCREL)) |
10231 | 0 | { |
10232 | 0 | if (!object_64bit) |
10233 | 0 | { |
10234 | 0 | reloc_type = BFD_RELOC_386_GOTPC; |
10235 | 0 | i.has_gotpc_tls_reloc = true; |
10236 | 0 | i.op[n].disps->X_add_number += |
10237 | 0 | encoding_length (insn_start_frag, insn_start_off, p); |
10238 | 0 | } |
10239 | 0 | else if (reloc_type == BFD_RELOC_64) |
10240 | 0 | reloc_type = BFD_RELOC_X86_64_GOTPC64; |
10241 | 0 | else |
10242 | | /* Don't do the adjustment for x86-64, as there |
10243 | | the pcrel addressing is relative to the _next_ |
10244 | | insn, and that is taken care of in other code. */ |
10245 | 0 | reloc_type = BFD_RELOC_X86_64_GOTPC32; |
10246 | 0 | } |
10247 | 11.6k | else if (align_branch_power) |
10248 | 0 | { |
10249 | 0 | switch (reloc_type) |
10250 | 0 | { |
10251 | 0 | case BFD_RELOC_386_TLS_GD: |
10252 | 0 | case BFD_RELOC_386_TLS_LDM: |
10253 | 0 | case BFD_RELOC_386_TLS_IE: |
10254 | 0 | case BFD_RELOC_386_TLS_IE_32: |
10255 | 0 | case BFD_RELOC_386_TLS_GOTIE: |
10256 | 0 | case BFD_RELOC_386_TLS_GOTDESC: |
10257 | 0 | case BFD_RELOC_386_TLS_DESC_CALL: |
10258 | 0 | case BFD_RELOC_X86_64_TLSGD: |
10259 | 0 | case BFD_RELOC_X86_64_TLSLD: |
10260 | 0 | case BFD_RELOC_X86_64_GOTTPOFF: |
10261 | 0 | case BFD_RELOC_X86_64_GOTPC32_TLSDESC: |
10262 | 0 | case BFD_RELOC_X86_64_TLSDESC_CALL: |
10263 | 0 | i.has_gotpc_tls_reloc = true; |
10264 | 0 | default: |
10265 | 0 | break; |
10266 | 0 | } |
10267 | 0 | } |
10268 | 11.6k | fixP = fix_new_exp (frag_now, p - frag_now->fr_literal, |
10269 | 11.6k | size, i.op[n].disps, pcrel, |
10270 | 11.6k | reloc_type); |
10271 | | |
10272 | 11.6k | if (flag_code == CODE_64BIT && size == 4 && pcrel |
10273 | 11.6k | && !i.prefix[ADDR_PREFIX]) |
10274 | 0 | fixP->fx_signed = 1; |
10275 | | |
10276 | | /* Check for "call/jmp *mem", "mov mem, %reg", |
10277 | | "test %reg, mem" and "binop mem, %reg" where binop |
10278 | | is one of adc, add, and, cmp, or, sbb, sub, xor |
10279 | | instructions without data prefix. Always generate |
10280 | | R_386_GOT32X for "sym*GOT" operand in 32-bit mode. */ |
10281 | 11.6k | if (i.prefix[DATA_PREFIX] == 0 |
10282 | 11.6k | && (generate_relax_relocations |
10283 | 11.5k | || (!object_64bit |
10284 | 0 | && i.rm.mode == 0 |
10285 | 0 | && i.rm.regmem == 5)) |
10286 | 11.6k | && (i.rm.mode == 2 |
10287 | 11.5k | || (i.rm.mode == 0 && i.rm.regmem == 5)) |
10288 | 11.6k | && i.tm.opcode_space == SPACE_BASE |
10289 | 11.6k | && ((i.operands == 1 |
10290 | 1.80k | && i.tm.base_opcode == 0xff |
10291 | 1.80k | && (i.rm.reg == 2 || i.rm.reg == 4)) |
10292 | 1.80k | || (i.operands == 2 |
10293 | 1.74k | && (i.tm.base_opcode == 0x8b |
10294 | 371 | || i.tm.base_opcode == 0x85 |
10295 | 371 | || (i.tm.base_opcode & ~0x38) == 0x03)))) |
10296 | 60 | { |
10297 | 60 | if (object_64bit) |
10298 | 60 | { |
10299 | 60 | fixP->fx_tcbit = i.rex != 0; |
10300 | 60 | if (i.base_reg |
10301 | 60 | && (i.base_reg->reg_num == RegIP)) |
10302 | 0 | fixP->fx_tcbit2 = 1; |
10303 | 60 | } |
10304 | 0 | else |
10305 | 0 | fixP->fx_tcbit2 = 1; |
10306 | 60 | } |
10307 | 11.6k | } |
10308 | 98.7k | } |
10309 | 190k | } |
10310 | 98.7k | } |
10311 | | |
10312 | | static void |
10313 | | output_imm (fragS *insn_start_frag, offsetT insn_start_off) |
10314 | 93.2k | { |
10315 | 93.2k | char *p; |
10316 | 93.2k | unsigned int n; |
10317 | | |
10318 | 278k | for (n = 0; n < i.operands; n++) |
10319 | 184k | { |
10320 | 184k | if (operand_type_check (i.types[n], imm)) |
10321 | 93.2k | { |
10322 | 93.2k | int size = imm_size (n); |
10323 | | |
10324 | 93.2k | if (now_seg == absolute_section) |
10325 | 2.45k | abs_section_offset += size; |
10326 | 90.8k | else if (i.op[n].imms->X_op == O_constant) |
10327 | 82.6k | { |
10328 | 82.6k | offsetT val; |
10329 | | |
10330 | 82.6k | val = offset_in_range (i.op[n].imms->X_add_number, |
10331 | 82.6k | size); |
10332 | 82.6k | p = frag_more (size); |
10333 | 82.6k | md_number_to_chars (p, val, size); |
10334 | 82.6k | } |
10335 | 8.15k | else |
10336 | 8.15k | { |
10337 | | /* Not absolute_section. |
10338 | | Need a 32-bit fixup (don't support 8bit |
10339 | | non-absolute imms). Try to support other |
10340 | | sizes ... */ |
10341 | 8.15k | enum bfd_reloc_code_real reloc_type; |
10342 | 8.15k | int sign; |
10343 | | |
10344 | 8.15k | if (i.types[n].bitfield.imm32s |
10345 | 8.15k | && (i.suffix == QWORD_MNEM_SUFFIX |
10346 | 0 | || (!i.suffix && i.tm.opcode_modifier.no_lsuf) |
10347 | 0 | || dot_insn ())) |
10348 | 0 | sign = 1; |
10349 | 8.15k | else |
10350 | 8.15k | sign = 0; |
10351 | | |
10352 | 8.15k | p = frag_more (size); |
10353 | 8.15k | reloc_type = reloc (size, 0, sign, i.reloc[n]); |
10354 | | |
10355 | | /* This is tough to explain. We end up with this one if we |
10356 | | * have operands that look like |
10357 | | * "_GLOBAL_OFFSET_TABLE_+[.-.L284]". The goal here is to |
10358 | | * obtain the absolute address of the GOT, and it is strongly |
10359 | | * preferable from a performance point of view to avoid using |
10360 | | * a runtime relocation for this. The actual sequence of |
10361 | | * instructions often look something like: |
10362 | | * |
10363 | | * call .L66 |
10364 | | * .L66: |
10365 | | * popl %ebx |
10366 | | * addl $_GLOBAL_OFFSET_TABLE_+[.-.L66],%ebx |
10367 | | * |
10368 | | * The call and pop essentially return the absolute address |
10369 | | * of the label .L66 and store it in %ebx. The linker itself |
10370 | | * will ultimately change the first operand of the addl so |
10371 | | * that %ebx points to the GOT, but to keep things simple, the |
10372 | | * .o file must have this operand set so that it generates not |
10373 | | * the absolute address of .L66, but the absolute address of |
10374 | | * itself. This allows the linker itself simply treat a GOTPC |
10375 | | * relocation as asking for a pcrel offset to the GOT to be |
10376 | | * added in, and the addend of the relocation is stored in the |
10377 | | * operand field for the instruction itself. |
10378 | | * |
10379 | | * Our job here is to fix the operand so that it would add |
10380 | | * the correct offset so that %ebx would point to itself. The |
10381 | | * thing that is tricky is that .-.L66 will point to the |
10382 | | * beginning of the instruction, so we need to further modify |
10383 | | * the operand so that it will point to itself. There are |
10384 | | * other cases where you have something like: |
10385 | | * |
10386 | | * .long $_GLOBAL_OFFSET_TABLE_+[.-.L66] |
10387 | | * |
10388 | | * and here no correction would be required. Internally in |
10389 | | * the assembler we treat operands of this form as not being |
10390 | | * pcrel since the '.' is explicitly mentioned, and I wonder |
10391 | | * whether it would simplify matters to do it this way. Who |
10392 | | * knows. In earlier versions of the PIC patches, the |
10393 | | * pcrel_adjust field was used to store the correction, but |
10394 | | * since the expression is not pcrel, I felt it would be |
10395 | | * confusing to do it this way. */ |
10396 | | |
10397 | 8.15k | if ((reloc_type == BFD_RELOC_32 |
10398 | 8.15k | || reloc_type == BFD_RELOC_X86_64_32S |
10399 | 8.15k | || reloc_type == BFD_RELOC_64) |
10400 | 8.15k | && GOT_symbol |
10401 | 8.15k | && GOT_symbol == i.op[n].imms->X_add_symbol |
10402 | 8.15k | && (i.op[n].imms->X_op == O_symbol |
10403 | 0 | || (i.op[n].imms->X_op == O_add |
10404 | 0 | && ((symbol_get_value_expression |
10405 | 0 | (i.op[n].imms->X_op_symbol)->X_op) |
10406 | 0 | == O_subtract)))) |
10407 | 0 | { |
10408 | 0 | if (!object_64bit) |
10409 | 0 | reloc_type = BFD_RELOC_386_GOTPC; |
10410 | 0 | else if (size == 4) |
10411 | 0 | reloc_type = BFD_RELOC_X86_64_GOTPC32; |
10412 | 0 | else if (size == 8) |
10413 | 0 | reloc_type = BFD_RELOC_X86_64_GOTPC64; |
10414 | 0 | i.has_gotpc_tls_reloc = true; |
10415 | 0 | i.op[n].imms->X_add_number += |
10416 | 0 | encoding_length (insn_start_frag, insn_start_off, p); |
10417 | 0 | } |
10418 | 8.15k | fix_new_exp (frag_now, p - frag_now->fr_literal, size, |
10419 | 8.15k | i.op[n].imms, 0, reloc_type); |
10420 | 8.15k | } |
10421 | 93.2k | } |
10422 | 184k | } |
10423 | 93.2k | } |
10424 | | |
10425 | | /* x86_cons_fix_new is called via the expression parsing code when a |
10426 | | reloc is needed. We use this hook to get the correct .got reloc. */ |
10427 | | static int cons_sign = -1; |
10428 | | |
10429 | | void |
10430 | | x86_cons_fix_new (fragS *frag, unsigned int off, unsigned int len, |
10431 | | expressionS *exp, bfd_reloc_code_real_type r) |
10432 | 74.5k | { |
10433 | 74.5k | r = reloc (len, 0, cons_sign, r); |
10434 | | |
10435 | | #ifdef TE_PE |
10436 | | if (exp->X_op == O_secrel) |
10437 | | { |
10438 | | exp->X_op = O_symbol; |
10439 | | r = BFD_RELOC_32_SECREL; |
10440 | | } |
10441 | | else if (exp->X_op == O_secidx) |
10442 | | r = BFD_RELOC_16_SECIDX; |
10443 | | #endif |
10444 | | |
10445 | 74.5k | fix_new_exp (frag, off, len, exp, 0, r); |
10446 | 74.5k | } |
10447 | | |
10448 | | /* Export the ABI address size for use by TC_ADDRESS_BYTES for the |
10449 | | purpose of the `.dc.a' internal pseudo-op. */ |
10450 | | |
10451 | | int |
10452 | | x86_address_bytes (void) |
10453 | 21 | { |
10454 | 21 | if ((stdoutput->arch_info->mach & bfd_mach_x64_32)) |
10455 | 0 | return 4; |
10456 | 21 | return stdoutput->arch_info->bits_per_address / 8; |
10457 | 21 | } |
10458 | | |
10459 | | #if (!(defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) || defined (OBJ_MACH_O)) \ |
10460 | | || defined (LEX_AT)) && !defined (TE_PE) |
10461 | | # define lex_got(reloc, adjust, types) NULL |
10462 | | #else |
10463 | | /* Parse operands of the form |
10464 | | <symbol>@GOTOFF+<nnn> |
10465 | | and similar .plt or .got references. |
10466 | | |
10467 | | If we find one, set up the correct relocation in RELOC and copy the |
10468 | | input string, minus the `@GOTOFF' into a malloc'd buffer for |
10469 | | parsing by the calling routine. Return this buffer, and if ADJUST |
10470 | | is non-null set it to the length of the string we removed from the |
10471 | | input line. Otherwise return NULL. */ |
10472 | | static char * |
10473 | | lex_got (enum bfd_reloc_code_real *rel, |
10474 | | int *adjust, |
10475 | | i386_operand_type *types) |
10476 | 433k | { |
10477 | | /* Some of the relocations depend on the size of what field is to |
10478 | | be relocated. But in our callers i386_immediate and i386_displacement |
10479 | | we don't yet know the operand size (this will be set by insn |
10480 | | matching). Hence we record the word32 relocation here, |
10481 | | and adjust the reloc according to the real size in reloc(). */ |
10482 | 433k | static const struct |
10483 | 433k | { |
10484 | 433k | const char *str; |
10485 | 433k | int len; |
10486 | 433k | const enum bfd_reloc_code_real rel[2]; |
10487 | 433k | const i386_operand_type types64; |
10488 | 433k | bool need_GOT_symbol; |
10489 | 433k | } |
10490 | 433k | gotrel[] = |
10491 | 433k | { |
10492 | | |
10493 | 3.03M | #define OPERAND_TYPE_IMM32_32S_DISP32 { .bitfield = \ |
10494 | 3.03M | { .imm32 = 1, .imm32s = 1, .disp32 = 1 } } |
10495 | 433k | #define OPERAND_TYPE_IMM32_32S_64_DISP32 { .bitfield = \ |
10496 | 433k | { .imm32 = 1, .imm32s = 1, .imm64 = 1, .disp32 = 1 } } |
10497 | 866k | #define OPERAND_TYPE_IMM32_32S_64_DISP32_64 { .bitfield = \ |
10498 | 866k | { .imm32 = 1, .imm32s = 1, .imm64 = 1, .disp32 = 1, .disp64 = 1 } } |
10499 | 866k | #define OPERAND_TYPE_IMM64_DISP64 { .bitfield = \ |
10500 | 866k | { .imm64 = 1, .disp64 = 1 } } |
10501 | | |
10502 | 433k | #ifndef TE_PE |
10503 | 433k | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
10504 | 433k | { STRING_COMMA_LEN ("SIZE"), { BFD_RELOC_SIZE32, |
10505 | 433k | BFD_RELOC_SIZE32 }, |
10506 | 433k | { .bitfield = { .imm32 = 1, .imm64 = 1 } }, false }, |
10507 | 433k | #endif |
10508 | 433k | { STRING_COMMA_LEN ("PLTOFF"), { _dummy_first_bfd_reloc_code_real, |
10509 | 433k | BFD_RELOC_X86_64_PLTOFF64 }, |
10510 | 433k | { .bitfield = { .imm64 = 1 } }, true }, |
10511 | 433k | { STRING_COMMA_LEN ("PLT"), { BFD_RELOC_386_PLT32, |
10512 | 433k | BFD_RELOC_X86_64_PLT32 }, |
10513 | 433k | OPERAND_TYPE_IMM32_32S_DISP32, false }, |
10514 | 433k | { STRING_COMMA_LEN ("GOTPLT"), { _dummy_first_bfd_reloc_code_real, |
10515 | 433k | BFD_RELOC_X86_64_GOTPLT64 }, |
10516 | 433k | OPERAND_TYPE_IMM64_DISP64, true }, |
10517 | 433k | { STRING_COMMA_LEN ("GOTOFF"), { BFD_RELOC_386_GOTOFF, |
10518 | 433k | BFD_RELOC_X86_64_GOTOFF64 }, |
10519 | 433k | OPERAND_TYPE_IMM64_DISP64, true }, |
10520 | 433k | { STRING_COMMA_LEN ("GOTPCREL"), { _dummy_first_bfd_reloc_code_real, |
10521 | 433k | BFD_RELOC_X86_64_GOTPCREL }, |
10522 | 433k | OPERAND_TYPE_IMM32_32S_DISP32, true }, |
10523 | 433k | { STRING_COMMA_LEN ("TLSGD"), { BFD_RELOC_386_TLS_GD, |
10524 | 433k | BFD_RELOC_X86_64_TLSGD }, |
10525 | 433k | OPERAND_TYPE_IMM32_32S_DISP32, true }, |
10526 | 433k | { STRING_COMMA_LEN ("TLSLDM"), { BFD_RELOC_386_TLS_LDM, |
10527 | 433k | _dummy_first_bfd_reloc_code_real }, |
10528 | 433k | OPERAND_TYPE_NONE, true }, |
10529 | 433k | { STRING_COMMA_LEN ("TLSLD"), { _dummy_first_bfd_reloc_code_real, |
10530 | 433k | BFD_RELOC_X86_64_TLSLD }, |
10531 | 433k | OPERAND_TYPE_IMM32_32S_DISP32, true }, |
10532 | 433k | { STRING_COMMA_LEN ("GOTTPOFF"), { BFD_RELOC_386_TLS_IE_32, |
10533 | 433k | BFD_RELOC_X86_64_GOTTPOFF }, |
10534 | 433k | OPERAND_TYPE_IMM32_32S_DISP32, true }, |
10535 | 433k | { STRING_COMMA_LEN ("TPOFF"), { BFD_RELOC_386_TLS_LE_32, |
10536 | 433k | BFD_RELOC_X86_64_TPOFF32 }, |
10537 | 433k | OPERAND_TYPE_IMM32_32S_64_DISP32_64, true }, |
10538 | 433k | { STRING_COMMA_LEN ("NTPOFF"), { BFD_RELOC_386_TLS_LE, |
10539 | 433k | _dummy_first_bfd_reloc_code_real }, |
10540 | 433k | OPERAND_TYPE_NONE, true }, |
10541 | 433k | { STRING_COMMA_LEN ("DTPOFF"), { BFD_RELOC_386_TLS_LDO_32, |
10542 | 433k | BFD_RELOC_X86_64_DTPOFF32 }, |
10543 | 433k | OPERAND_TYPE_IMM32_32S_64_DISP32_64, true }, |
10544 | 433k | { STRING_COMMA_LEN ("GOTNTPOFF"),{ BFD_RELOC_386_TLS_GOTIE, |
10545 | 433k | _dummy_first_bfd_reloc_code_real }, |
10546 | 433k | OPERAND_TYPE_NONE, true }, |
10547 | 433k | { STRING_COMMA_LEN ("INDNTPOFF"),{ BFD_RELOC_386_TLS_IE, |
10548 | 433k | _dummy_first_bfd_reloc_code_real }, |
10549 | 433k | OPERAND_TYPE_NONE, true }, |
10550 | 433k | { STRING_COMMA_LEN ("GOT"), { BFD_RELOC_386_GOT32, |
10551 | 433k | BFD_RELOC_X86_64_GOT32 }, |
10552 | 433k | OPERAND_TYPE_IMM32_32S_64_DISP32, true }, |
10553 | 433k | { STRING_COMMA_LEN ("TLSDESC"), { BFD_RELOC_386_TLS_GOTDESC, |
10554 | 433k | BFD_RELOC_X86_64_GOTPC32_TLSDESC }, |
10555 | 433k | OPERAND_TYPE_IMM32_32S_DISP32, true }, |
10556 | 433k | { STRING_COMMA_LEN ("TLSCALL"), { BFD_RELOC_386_TLS_DESC_CALL, |
10557 | 433k | BFD_RELOC_X86_64_TLSDESC_CALL }, |
10558 | 433k | OPERAND_TYPE_IMM32_32S_DISP32, true }, |
10559 | | #else /* TE_PE */ |
10560 | | { STRING_COMMA_LEN ("SECREL32"), { BFD_RELOC_32_SECREL, |
10561 | | BFD_RELOC_32_SECREL }, |
10562 | | OPERAND_TYPE_IMM32_32S_64_DISP32_64, false }, |
10563 | | #endif |
10564 | | |
10565 | 433k | #undef OPERAND_TYPE_IMM32_32S_DISP32 |
10566 | 433k | #undef OPERAND_TYPE_IMM32_32S_64_DISP32 |
10567 | 433k | #undef OPERAND_TYPE_IMM32_32S_64_DISP32_64 |
10568 | 433k | #undef OPERAND_TYPE_IMM64_DISP64 |
10569 | | |
10570 | 433k | }; |
10571 | 433k | char *cp; |
10572 | 433k | unsigned int j; |
10573 | | |
10574 | | #if defined (OBJ_MAYBE_ELF) && !defined (TE_PE) |
10575 | | if (!IS_ELF) |
10576 | | return NULL; |
10577 | | #endif |
10578 | | |
10579 | 2.48M | for (cp = input_line_pointer; *cp != '@'; cp++) |
10580 | 2.47M | if (is_end_of_line[(unsigned char) *cp] || *cp == ',') |
10581 | 424k | return NULL; |
10582 | | |
10583 | 131k | for (j = 0; j < ARRAY_SIZE (gotrel); j++) |
10584 | 125k | { |
10585 | 125k | int len = gotrel[j].len; |
10586 | 125k | if (strncasecmp (cp + 1, gotrel[j].str, len) == 0) |
10587 | 3.00k | { |
10588 | 3.00k | if (gotrel[j].rel[object_64bit] != 0) |
10589 | 2.90k | { |
10590 | 2.90k | int first, second; |
10591 | 2.90k | char *tmpbuf, *past_reloc; |
10592 | | |
10593 | 2.90k | *rel = gotrel[j].rel[object_64bit]; |
10594 | | |
10595 | 2.90k | if (types) |
10596 | 2.32k | { |
10597 | 2.32k | if (flag_code != CODE_64BIT) |
10598 | 1.45k | { |
10599 | 1.45k | types->bitfield.imm32 = 1; |
10600 | 1.45k | types->bitfield.disp32 = 1; |
10601 | 1.45k | } |
10602 | 865 | else |
10603 | 865 | *types = gotrel[j].types64; |
10604 | 2.32k | } |
10605 | | |
10606 | 2.90k | if (gotrel[j].need_GOT_symbol && GOT_symbol == NULL) |
10607 | 1 | GOT_symbol = symbol_find_or_make (GLOBAL_OFFSET_TABLE_NAME); |
10608 | | |
10609 | | /* The length of the first part of our input line. */ |
10610 | 2.90k | first = cp - input_line_pointer; |
10611 | | |
10612 | | /* The second part goes from after the reloc token until |
10613 | | (and including) an end_of_line char or comma. */ |
10614 | 2.90k | past_reloc = cp + 1 + len; |
10615 | 2.90k | cp = past_reloc; |
10616 | 58.2k | while (!is_end_of_line[(unsigned char) *cp] && *cp != ',') |
10617 | 55.3k | ++cp; |
10618 | 2.90k | second = cp + 1 - past_reloc; |
10619 | | |
10620 | | /* Allocate and copy string. The trailing NUL shouldn't |
10621 | | be necessary, but be safe. */ |
10622 | 2.90k | tmpbuf = XNEWVEC (char, first + second + 2); |
10623 | 2.90k | memcpy (tmpbuf, input_line_pointer, first); |
10624 | 2.90k | if (second != 0 && *past_reloc != ' ') |
10625 | | /* Replace the relocation token with ' ', so that |
10626 | | errors like foo@GOTOFF1 will be detected. */ |
10627 | 2.69k | tmpbuf[first++] = ' '; |
10628 | 206 | else |
10629 | | /* Increment length by 1 if the relocation token is |
10630 | | removed. */ |
10631 | 206 | len++; |
10632 | 2.90k | if (adjust) |
10633 | 579 | *adjust = len; |
10634 | 2.90k | memcpy (tmpbuf + first, past_reloc, second); |
10635 | 2.90k | tmpbuf[first + second] = '\0'; |
10636 | 2.90k | return tmpbuf; |
10637 | 2.90k | } |
10638 | | |
10639 | 102 | as_bad (_("@%s reloc is not supported with %d-bit output format"), |
10640 | 102 | gotrel[j].str, 1 << (5 + object_64bit)); |
10641 | 102 | return NULL; |
10642 | 3.00k | } |
10643 | 125k | } |
10644 | | |
10645 | | /* Might be a symbol version string. Don't as_bad here. */ |
10646 | 5.82k | return NULL; |
10647 | 8.83k | } |
10648 | | #endif |
10649 | | |
10650 | | bfd_reloc_code_real_type |
10651 | | x86_cons (expressionS *exp, int size) |
10652 | 16.0k | { |
10653 | 16.0k | bfd_reloc_code_real_type got_reloc = NO_RELOC; |
10654 | | |
10655 | 16.0k | intel_syntax = -intel_syntax; |
10656 | 16.0k | exp->X_md = 0; |
10657 | 16.0k | expr_mode = expr_operator_none; |
10658 | | |
10659 | 16.0k | #if ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) \ |
10660 | 16.0k | && !defined (LEX_AT)) \ |
10661 | 16.0k | || defined (TE_PE) |
10662 | 16.0k | if (size == 4 || (object_64bit && size == 8)) |
10663 | 14.4k | { |
10664 | | /* Handle @GOTOFF and the like in an expression. */ |
10665 | 14.4k | char *save; |
10666 | 14.4k | char *gotfree_input_line; |
10667 | 14.4k | int adjust = 0; |
10668 | | |
10669 | 14.4k | save = input_line_pointer; |
10670 | 14.4k | gotfree_input_line = lex_got (&got_reloc, &adjust, NULL); |
10671 | 14.4k | if (gotfree_input_line) |
10672 | 579 | input_line_pointer = gotfree_input_line; |
10673 | | |
10674 | 14.4k | expression (exp); |
10675 | | |
10676 | 14.4k | if (gotfree_input_line) |
10677 | 579 | { |
10678 | | /* expression () has merrily parsed up to the end of line, |
10679 | | or a comma - in the wrong buffer. Transfer how far |
10680 | | input_line_pointer has moved to the right buffer. */ |
10681 | 579 | input_line_pointer = (save |
10682 | 579 | + (input_line_pointer - gotfree_input_line) |
10683 | 579 | + adjust); |
10684 | 579 | free (gotfree_input_line); |
10685 | 579 | if (exp->X_op == O_constant |
10686 | 579 | || exp->X_op == O_absent |
10687 | 579 | || exp->X_op == O_illegal |
10688 | 579 | || exp->X_op == O_register |
10689 | 579 | || exp->X_op == O_big) |
10690 | 95 | { |
10691 | 95 | char c = *input_line_pointer; |
10692 | 95 | *input_line_pointer = 0; |
10693 | 95 | as_bad (_("missing or invalid expression `%s'"), save); |
10694 | 95 | *input_line_pointer = c; |
10695 | 95 | } |
10696 | 484 | else if ((got_reloc == BFD_RELOC_386_PLT32 |
10697 | 484 | || got_reloc == BFD_RELOC_X86_64_PLT32) |
10698 | 484 | && exp->X_op != O_symbol) |
10699 | 0 | { |
10700 | 0 | char c = *input_line_pointer; |
10701 | 0 | *input_line_pointer = 0; |
10702 | 0 | as_bad (_("invalid PLT expression `%s'"), save); |
10703 | 0 | *input_line_pointer = c; |
10704 | 0 | } |
10705 | 579 | } |
10706 | 14.4k | } |
10707 | 1.57k | else |
10708 | 1.57k | #endif |
10709 | 1.57k | expression (exp); |
10710 | | |
10711 | 16.0k | intel_syntax = -intel_syntax; |
10712 | | |
10713 | 16.0k | if (intel_syntax) |
10714 | 0 | i386_intel_simplify (exp); |
10715 | | |
10716 | | /* If not 64bit, massage value, to account for wraparound when !BFD64. */ |
10717 | 16.0k | if (size <= 4 && expr_mode == expr_operator_present |
10718 | 16.0k | && exp->X_op == O_constant && !object_64bit) |
10719 | 0 | exp->X_add_number = extend_to_32bit_address (exp->X_add_number); |
10720 | | |
10721 | 16.0k | return got_reloc; |
10722 | 16.0k | } |
10723 | | |
10724 | | static void |
10725 | | signed_cons (int size) |
10726 | 0 | { |
10727 | 0 | if (object_64bit) |
10728 | 0 | cons_sign = 1; |
10729 | 0 | cons (size); |
10730 | 0 | cons_sign = -1; |
10731 | 0 | } |
10732 | | |
10733 | | static void |
10734 | | s_insn (int dummy ATTRIBUTE_UNUSED) |
10735 | 100 | { |
10736 | 100 | char mnemonic[MAX_MNEM_SIZE], *line = input_line_pointer, *ptr; |
10737 | 100 | char *saved_ilp = find_end_of_line (line, false), saved_char; |
10738 | 100 | const char *end; |
10739 | 100 | unsigned int j; |
10740 | 100 | valueT val; |
10741 | 100 | bool vex = false, xop = false, evex = false; |
10742 | 100 | static const templates tt = { &i.tm, &i.tm + 1 }; |
10743 | | |
10744 | 100 | init_globals (); |
10745 | | |
10746 | 100 | saved_char = *saved_ilp; |
10747 | 100 | *saved_ilp = 0; |
10748 | | |
10749 | 100 | end = parse_insn (line, mnemonic, true); |
10750 | 100 | if (end == NULL) |
10751 | 68 | { |
10752 | 68 | bad: |
10753 | 68 | *saved_ilp = saved_char; |
10754 | 68 | ignore_rest_of_line (); |
10755 | 68 | i.tm.mnem_off = 0; |
10756 | 68 | return; |
10757 | 68 | } |
10758 | 32 | line += end - line; |
10759 | | |
10760 | 32 | current_templates = &tt; |
10761 | 32 | i.tm.mnem_off = MN__insn; |
10762 | 32 | i.tm.extension_opcode = None; |
10763 | | |
10764 | 32 | if (startswith (line, "VEX") |
10765 | 32 | && (line[3] == '.' || is_space_char (line[3]))) |
10766 | 0 | { |
10767 | 0 | vex = true; |
10768 | 0 | line += 3; |
10769 | 0 | } |
10770 | 32 | else if (startswith (line, "XOP") && ISDIGIT (line[3])) |
10771 | 0 | { |
10772 | 0 | char *e; |
10773 | 0 | unsigned long n = strtoul (line + 3, &e, 16); |
10774 | |
|
10775 | 0 | if (e == line + 5 && n >= 0x08 && n <= 0x1f |
10776 | 0 | && (*e == '.' || is_space_char (*e))) |
10777 | 0 | { |
10778 | 0 | xop = true; |
10779 | | /* Arrange for build_vex_prefix() to emit 0x8f. */ |
10780 | 0 | i.tm.opcode_space = SPACE_XOP08; |
10781 | 0 | i.insn_opcode_space = n; |
10782 | 0 | line = e; |
10783 | 0 | } |
10784 | 0 | } |
10785 | 32 | else if (startswith (line, "EVEX") |
10786 | 32 | && (line[4] == '.' || is_space_char (line[4]))) |
10787 | 0 | { |
10788 | 0 | evex = true; |
10789 | 0 | line += 4; |
10790 | 0 | } |
10791 | | |
10792 | 32 | if (vex || xop |
10793 | 32 | ? i.vec_encoding == vex_encoding_evex |
10794 | 32 | : evex |
10795 | 32 | ? i.vec_encoding == vex_encoding_vex |
10796 | 0 | || i.vec_encoding == vex_encoding_vex3 |
10797 | 32 | : i.vec_encoding != vex_encoding_default) |
10798 | 0 | { |
10799 | 0 | as_bad (_("pseudo-prefix conflicts with encoding specifier")); |
10800 | 0 | goto bad; |
10801 | 0 | } |
10802 | | |
10803 | 32 | if (line > end && i.vec_encoding == vex_encoding_default) |
10804 | 0 | i.vec_encoding = evex ? vex_encoding_evex : vex_encoding_vex; |
10805 | | |
10806 | 32 | if (line > end && *line == '.') |
10807 | 0 | { |
10808 | | /* Length specifier (VEX.L, XOP.L, EVEX.L'L). */ |
10809 | 0 | switch (line[1]) |
10810 | 0 | { |
10811 | 0 | case 'L': |
10812 | 0 | switch (line[2]) |
10813 | 0 | { |
10814 | 0 | case '0': |
10815 | 0 | if (evex) |
10816 | 0 | i.tm.opcode_modifier.evex = EVEX128; |
10817 | 0 | else |
10818 | 0 | i.tm.opcode_modifier.vex = VEX128; |
10819 | 0 | break; |
10820 | | |
10821 | 0 | case '1': |
10822 | 0 | if (evex) |
10823 | 0 | i.tm.opcode_modifier.evex = EVEX256; |
10824 | 0 | else |
10825 | 0 | i.tm.opcode_modifier.vex = VEX256; |
10826 | 0 | break; |
10827 | | |
10828 | 0 | case '2': |
10829 | 0 | if (evex) |
10830 | 0 | i.tm.opcode_modifier.evex = EVEX512; |
10831 | 0 | break; |
10832 | | |
10833 | 0 | case '3': |
10834 | 0 | if (evex) |
10835 | 0 | i.tm.opcode_modifier.evex = EVEX_L3; |
10836 | 0 | break; |
10837 | | |
10838 | 0 | case 'I': |
10839 | 0 | if (line[3] == 'G') |
10840 | 0 | { |
10841 | 0 | if (evex) |
10842 | 0 | i.tm.opcode_modifier.evex = EVEXLIG; |
10843 | 0 | else |
10844 | 0 | i.tm.opcode_modifier.vex = VEXScalar; /* LIG */ |
10845 | 0 | ++line; |
10846 | 0 | } |
10847 | 0 | break; |
10848 | 0 | } |
10849 | | |
10850 | 0 | if (i.tm.opcode_modifier.vex || i.tm.opcode_modifier.evex) |
10851 | 0 | line += 3; |
10852 | 0 | break; |
10853 | | |
10854 | 0 | case '1': |
10855 | 0 | if (line[2] == '2' && line[3] == '8') |
10856 | 0 | { |
10857 | 0 | if (evex) |
10858 | 0 | i.tm.opcode_modifier.evex = EVEX128; |
10859 | 0 | else |
10860 | 0 | i.tm.opcode_modifier.vex = VEX128; |
10861 | 0 | line += 4; |
10862 | 0 | } |
10863 | 0 | break; |
10864 | | |
10865 | 0 | case '2': |
10866 | 0 | if (line[2] == '5' && line[3] == '6') |
10867 | 0 | { |
10868 | 0 | if (evex) |
10869 | 0 | i.tm.opcode_modifier.evex = EVEX256; |
10870 | 0 | else |
10871 | 0 | i.tm.opcode_modifier.vex = VEX256; |
10872 | 0 | line += 4; |
10873 | 0 | } |
10874 | 0 | break; |
10875 | | |
10876 | 0 | case '5': |
10877 | 0 | if (evex && line[2] == '1' && line[3] == '2') |
10878 | 0 | { |
10879 | 0 | i.tm.opcode_modifier.evex = EVEX512; |
10880 | 0 | line += 4; |
10881 | 0 | } |
10882 | 0 | break; |
10883 | 0 | } |
10884 | 0 | } |
10885 | | |
10886 | 32 | if (line > end && *line == '.') |
10887 | 0 | { |
10888 | | /* embedded prefix (VEX.pp, XOP.pp, EVEX.pp). */ |
10889 | 0 | switch (line[1]) |
10890 | 0 | { |
10891 | 0 | case 'N': |
10892 | 0 | if (line[2] == 'P') |
10893 | 0 | line += 3; |
10894 | 0 | break; |
10895 | | |
10896 | 0 | case '6': |
10897 | 0 | if (line[2] == '6') |
10898 | 0 | { |
10899 | 0 | i.tm.opcode_modifier.opcodeprefix = PREFIX_0X66; |
10900 | 0 | line += 3; |
10901 | 0 | } |
10902 | 0 | break; |
10903 | | |
10904 | 0 | case 'F': case 'f': |
10905 | 0 | if (line[2] == '3') |
10906 | 0 | { |
10907 | 0 | i.tm.opcode_modifier.opcodeprefix = PREFIX_0XF3; |
10908 | 0 | line += 3; |
10909 | 0 | } |
10910 | 0 | else if (line[2] == '2') |
10911 | 0 | { |
10912 | 0 | i.tm.opcode_modifier.opcodeprefix = PREFIX_0XF2; |
10913 | 0 | line += 3; |
10914 | 0 | } |
10915 | 0 | break; |
10916 | 0 | } |
10917 | 0 | } |
10918 | | |
10919 | 32 | if (line > end && !xop && *line == '.') |
10920 | 0 | { |
10921 | | /* Encoding space (VEX.mmmmm, EVEX.mmmm). */ |
10922 | 0 | switch (line[1]) |
10923 | 0 | { |
10924 | 0 | case '0': |
10925 | 0 | if (TOUPPER (line[2]) != 'F') |
10926 | 0 | break; |
10927 | 0 | if (line[3] == '.' || is_space_char (line[3])) |
10928 | 0 | { |
10929 | 0 | i.insn_opcode_space = SPACE_0F; |
10930 | 0 | line += 3; |
10931 | 0 | } |
10932 | 0 | else if (line[3] == '3' |
10933 | 0 | && (line[4] == '8' || TOUPPER (line[4]) == 'A') |
10934 | 0 | && (line[5] == '.' || is_space_char (line[5]))) |
10935 | 0 | { |
10936 | 0 | i.insn_opcode_space = line[4] == '8' ? SPACE_0F38 : SPACE_0F3A; |
10937 | 0 | line += 5; |
10938 | 0 | } |
10939 | 0 | break; |
10940 | | |
10941 | 0 | case 'M': |
10942 | 0 | if (ISDIGIT (line[2]) && line[2] != '0') |
10943 | 0 | { |
10944 | 0 | char *e; |
10945 | 0 | unsigned long n = strtoul (line + 2, &e, 10); |
10946 | |
|
10947 | 0 | if (n <= (evex ? 15 : 31) |
10948 | 0 | && (*e == '.' || is_space_char (*e))) |
10949 | 0 | { |
10950 | 0 | i.insn_opcode_space = n; |
10951 | 0 | line = e; |
10952 | 0 | } |
10953 | 0 | } |
10954 | 0 | break; |
10955 | 0 | } |
10956 | 0 | } |
10957 | | |
10958 | 32 | if (line > end && *line == '.' && line[1] == 'W') |
10959 | 0 | { |
10960 | | /* VEX.W, XOP.W, EVEX.W */ |
10961 | 0 | switch (line[2]) |
10962 | 0 | { |
10963 | 0 | case '0': |
10964 | 0 | i.tm.opcode_modifier.vexw = VEXW0; |
10965 | 0 | break; |
10966 | | |
10967 | 0 | case '1': |
10968 | 0 | i.tm.opcode_modifier.vexw = VEXW1; |
10969 | 0 | break; |
10970 | | |
10971 | 0 | case 'I': |
10972 | 0 | if (line[3] == 'G') |
10973 | 0 | { |
10974 | 0 | i.tm.opcode_modifier.vexw = VEXWIG; |
10975 | 0 | ++line; |
10976 | 0 | } |
10977 | 0 | break; |
10978 | 0 | } |
10979 | | |
10980 | 0 | if (i.tm.opcode_modifier.vexw) |
10981 | 0 | line += 3; |
10982 | 0 | } |
10983 | | |
10984 | 32 | if (line > end && *line && !is_space_char (*line)) |
10985 | 0 | { |
10986 | | /* Improve diagnostic a little. */ |
10987 | 0 | if (*line == '.' && line[1] && !is_space_char (line[1])) |
10988 | 0 | ++line; |
10989 | 0 | goto done; |
10990 | 0 | } |
10991 | | |
10992 | | /* Before processing the opcode expression, find trailing "+r" or |
10993 | | "/<digit>" specifiers. */ |
10994 | 32 | for (ptr = line; ; ++ptr) |
10995 | 64 | { |
10996 | 64 | unsigned long n; |
10997 | 64 | char *e; |
10998 | | |
10999 | 64 | ptr = strpbrk (ptr, "+/,"); |
11000 | 64 | if (ptr == NULL || *ptr == ',') |
11001 | 32 | break; |
11002 | | |
11003 | 32 | if (*ptr == '+' && ptr[1] == 'r' |
11004 | 32 | && (ptr[2] == ',' || (is_space_char (ptr[2]) && ptr[3] == ','))) |
11005 | 0 | { |
11006 | 0 | *ptr = ' '; |
11007 | 0 | ptr[1] = ' '; |
11008 | 0 | i.short_form = true; |
11009 | 0 | break; |
11010 | 0 | } |
11011 | | |
11012 | 32 | if (*ptr == '/' && ISDIGIT (ptr[1]) |
11013 | 32 | && (n = strtoul (ptr + 1, &e, 8)) < 8 |
11014 | 32 | && e == ptr + 2 |
11015 | 32 | && (ptr[2] == ',' || (is_space_char (ptr[2]) && ptr[3] == ','))) |
11016 | 0 | { |
11017 | 0 | *ptr = ' '; |
11018 | 0 | ptr[1] = ' '; |
11019 | 0 | i.tm.extension_opcode = n; |
11020 | 0 | i.tm.opcode_modifier.modrm = 1; |
11021 | 0 | break; |
11022 | 0 | } |
11023 | 32 | } |
11024 | | |
11025 | 32 | input_line_pointer = line; |
11026 | 32 | val = get_absolute_expression (); |
11027 | 32 | line = input_line_pointer; |
11028 | | |
11029 | 32 | if (i.short_form && (val & 7)) |
11030 | 0 | as_warn ("`+r' assumes low three opcode bits to be clear"); |
11031 | | |
11032 | 32 | for (j = 1; j < sizeof(val); ++j) |
11033 | 32 | if (!(val >> (j * 8))) |
11034 | 32 | break; |
11035 | | |
11036 | | /* Trim off a prefix if present. */ |
11037 | 32 | if (j > 1 && !vex && !xop && !evex) |
11038 | 0 | { |
11039 | 0 | uint8_t byte = val >> ((j - 1) * 8); |
11040 | |
|
11041 | 0 | switch (byte) |
11042 | 0 | { |
11043 | 0 | case DATA_PREFIX_OPCODE: |
11044 | 0 | case REPE_PREFIX_OPCODE: |
11045 | 0 | case REPNE_PREFIX_OPCODE: |
11046 | 0 | if (!add_prefix (byte)) |
11047 | 0 | goto bad; |
11048 | 0 | val &= ((uint64_t)1 << (--j * 8)) - 1; |
11049 | 0 | break; |
11050 | 0 | } |
11051 | 0 | } |
11052 | | |
11053 | | /* Trim off encoding space. */ |
11054 | 32 | if (j > 1 && !i.insn_opcode_space && (val >> ((j - 1) * 8)) == 0x0f) |
11055 | 0 | { |
11056 | 0 | uint8_t byte = val >> ((--j - 1) * 8); |
11057 | |
|
11058 | 0 | i.insn_opcode_space = SPACE_0F; |
11059 | 0 | switch (byte & -(j > 1)) |
11060 | 0 | { |
11061 | 0 | case 0x38: |
11062 | 0 | i.insn_opcode_space = SPACE_0F38; |
11063 | 0 | --j; |
11064 | 0 | break; |
11065 | 0 | case 0x3a: |
11066 | 0 | i.insn_opcode_space = SPACE_0F3A; |
11067 | 0 | --j; |
11068 | 0 | break; |
11069 | 0 | } |
11070 | 0 | i.tm.opcode_space = i.insn_opcode_space; |
11071 | 0 | val &= ((uint64_t)1 << (j * 8)) - 1; |
11072 | 0 | } |
11073 | 32 | if (!i.tm.opcode_space && (vex || evex)) |
11074 | | /* Arrange for build_vex_prefix() to properly emit 0xC4/0xC5. |
11075 | | Also avoid hitting abort() there or in build_evex_prefix(). */ |
11076 | 0 | i.tm.opcode_space = i.insn_opcode_space == SPACE_0F ? SPACE_0F |
11077 | 0 | : SPACE_0F38; |
11078 | | |
11079 | 32 | if (j > 2) |
11080 | 0 | { |
11081 | 0 | as_bad (_("opcode residual (%#"PRIx64") too wide"), (uint64_t) val); |
11082 | 0 | goto bad; |
11083 | 0 | } |
11084 | 32 | i.opcode_length = j; |
11085 | | |
11086 | | /* Handle operands, if any. */ |
11087 | 32 | if (*line == ',') |
11088 | 1 | { |
11089 | 1 | i386_operand_type combined; |
11090 | 1 | expressionS *disp_exp = NULL; |
11091 | 1 | bool changed; |
11092 | | |
11093 | 1 | i.memshift = -1; |
11094 | | |
11095 | 1 | ptr = parse_operands (line + 1, &i386_mnemonics[MN__insn]); |
11096 | 1 | this_operand = -1; |
11097 | 1 | if (!ptr) |
11098 | 0 | goto bad; |
11099 | 1 | line = ptr; |
11100 | | |
11101 | 1 | if (!i.operands) |
11102 | 0 | { |
11103 | 0 | as_bad (_("expecting operand after ','; got nothing")); |
11104 | 0 | goto done; |
11105 | 0 | } |
11106 | | |
11107 | 1 | if (i.mem_operands > 1) |
11108 | 0 | { |
11109 | 0 | as_bad (_("too many memory references for `%s'"), |
11110 | 0 | &i386_mnemonics[MN__insn]); |
11111 | 0 | goto done; |
11112 | 0 | } |
11113 | | |
11114 | | /* Are we to emit ModR/M encoding? */ |
11115 | 1 | if (!i.short_form |
11116 | 1 | && (i.mem_operands |
11117 | 1 | || i.reg_operands > (i.vec_encoding != vex_encoding_default) |
11118 | 1 | || i.tm.extension_opcode != None)) |
11119 | 1 | i.tm.opcode_modifier.modrm = 1; |
11120 | | |
11121 | 1 | if (!i.tm.opcode_modifier.modrm |
11122 | 1 | && (i.reg_operands |
11123 | 0 | > i.short_form + 0U + (i.vec_encoding != vex_encoding_default) |
11124 | 0 | || i.mem_operands)) |
11125 | 0 | { |
11126 | 0 | as_bad (_("too many register/memory operands")); |
11127 | 0 | goto done; |
11128 | 0 | } |
11129 | | |
11130 | | /* Enforce certain constraints on operands. */ |
11131 | 1 | switch (i.reg_operands + i.mem_operands |
11132 | 1 | + (i.tm.extension_opcode != None)) |
11133 | 1 | { |
11134 | 0 | case 0: |
11135 | 0 | if (i.short_form) |
11136 | 0 | { |
11137 | 0 | as_bad (_("too few register/memory operands")); |
11138 | 0 | goto done; |
11139 | 0 | } |
11140 | | /* Fall through. */ |
11141 | 1 | case 1: |
11142 | 1 | if (i.tm.opcode_modifier.modrm) |
11143 | 1 | { |
11144 | 1 | as_bad (_("too few register/memory operands")); |
11145 | 1 | goto done; |
11146 | 1 | } |
11147 | 0 | break; |
11148 | | |
11149 | 0 | case 2: |
11150 | 0 | break; |
11151 | | |
11152 | 0 | case 4: |
11153 | 0 | if (i.imm_operands |
11154 | 0 | && (i.op[0].imms->X_op != O_constant |
11155 | 0 | || !fits_in_imm4 (i.op[0].imms->X_add_number))) |
11156 | 0 | { |
11157 | 0 | as_bad (_("constant doesn't fit in %d bits"), evex ? 3 : 4); |
11158 | 0 | goto done; |
11159 | 0 | } |
11160 | | /* Fall through. */ |
11161 | 0 | case 3: |
11162 | 0 | if (i.vec_encoding != vex_encoding_default) |
11163 | 0 | { |
11164 | 0 | i.tm.opcode_modifier.vexvvvv = 1; |
11165 | 0 | break; |
11166 | 0 | } |
11167 | | /* Fall through. */ |
11168 | 0 | default: |
11169 | 0 | as_bad (_("too many register/memory operands")); |
11170 | 0 | goto done; |
11171 | 1 | } |
11172 | | |
11173 | | /* Bring operands into canonical order (imm, mem, reg). */ |
11174 | 0 | do |
11175 | 0 | { |
11176 | 0 | changed = false; |
11177 | |
|
11178 | 0 | for (j = 1; j < i.operands; ++j) |
11179 | 0 | { |
11180 | 0 | if ((!operand_type_check (i.types[j - 1], imm) |
11181 | 0 | && operand_type_check (i.types[j], imm)) |
11182 | 0 | || (i.types[j - 1].bitfield.class != ClassNone |
11183 | 0 | && i.types[j].bitfield.class == ClassNone)) |
11184 | 0 | { |
11185 | 0 | swap_2_operands (j - 1, j); |
11186 | 0 | changed = true; |
11187 | 0 | } |
11188 | 0 | } |
11189 | 0 | } |
11190 | 0 | while (changed); |
11191 | | |
11192 | | /* For Intel syntax swap the order of register operands. */ |
11193 | 0 | if (intel_syntax) |
11194 | 0 | switch (i.reg_operands) |
11195 | 0 | { |
11196 | 0 | case 0: |
11197 | 0 | case 1: |
11198 | 0 | break; |
11199 | | |
11200 | 0 | case 4: |
11201 | 0 | swap_2_operands (i.imm_operands + i.mem_operands + 1, i.operands - 2); |
11202 | | /* Fall through. */ |
11203 | 0 | case 3: |
11204 | 0 | case 2: |
11205 | 0 | swap_2_operands (i.imm_operands + i.mem_operands, i.operands - 1); |
11206 | 0 | break; |
11207 | | |
11208 | 0 | default: |
11209 | 0 | abort (); |
11210 | 0 | } |
11211 | | |
11212 | | /* Enforce constraints when using VSIB. */ |
11213 | 0 | if (i.index_reg |
11214 | 0 | && (i.index_reg->reg_type.bitfield.xmmword |
11215 | 0 | || i.index_reg->reg_type.bitfield.ymmword |
11216 | 0 | || i.index_reg->reg_type.bitfield.zmmword)) |
11217 | 0 | { |
11218 | 0 | if (i.vec_encoding == vex_encoding_default) |
11219 | 0 | { |
11220 | 0 | as_bad (_("VSIB unavailable with legacy encoding")); |
11221 | 0 | goto done; |
11222 | 0 | } |
11223 | | |
11224 | 0 | if (i.vec_encoding == vex_encoding_evex |
11225 | 0 | && i.reg_operands > 1) |
11226 | 0 | { |
11227 | | /* We could allow two register operands, encoding the 2nd one in |
11228 | | an 8-bit immediate like for 4-register-operand insns, but that |
11229 | | would require ugly fiddling with process_operands() and/or |
11230 | | build_modrm_byte(). */ |
11231 | 0 | as_bad (_("too many register operands with VSIB")); |
11232 | 0 | goto done; |
11233 | 0 | } |
11234 | | |
11235 | 0 | i.tm.opcode_modifier.sib = 1; |
11236 | 0 | } |
11237 | | |
11238 | | /* Establish operand size encoding. */ |
11239 | 0 | operand_type_set (&combined, 0); |
11240 | |
|
11241 | 0 | for (j = i.imm_operands; j < i.operands; ++j) |
11242 | 0 | { |
11243 | 0 | i.types[j].bitfield.instance = InstanceNone; |
11244 | |
|
11245 | 0 | if (operand_type_check (i.types[j], disp)) |
11246 | 0 | { |
11247 | 0 | i.types[j].bitfield.baseindex = 1; |
11248 | 0 | disp_exp = i.op[j].disps; |
11249 | 0 | } |
11250 | |
|
11251 | 0 | if (evex && i.types[j].bitfield.baseindex) |
11252 | 0 | { |
11253 | 0 | unsigned int n = i.memshift; |
11254 | |
|
11255 | 0 | if (i.types[j].bitfield.byte) |
11256 | 0 | n = 0; |
11257 | 0 | else if (i.types[j].bitfield.word) |
11258 | 0 | n = 1; |
11259 | 0 | else if (i.types[j].bitfield.dword) |
11260 | 0 | n = 2; |
11261 | 0 | else if (i.types[j].bitfield.qword) |
11262 | 0 | n = 3; |
11263 | 0 | else if (i.types[j].bitfield.xmmword) |
11264 | 0 | n = 4; |
11265 | 0 | else if (i.types[j].bitfield.ymmword) |
11266 | 0 | n = 5; |
11267 | 0 | else if (i.types[j].bitfield.zmmword) |
11268 | 0 | n = 6; |
11269 | |
|
11270 | 0 | if (i.memshift < 32 && n != i.memshift) |
11271 | 0 | as_warn ("conflicting memory operand size specifiers"); |
11272 | 0 | i.memshift = n; |
11273 | 0 | } |
11274 | |
|
11275 | 0 | if ((i.broadcast.type || i.broadcast.bytes) |
11276 | 0 | && j == i.broadcast.operand) |
11277 | 0 | continue; |
11278 | | |
11279 | 0 | combined = operand_type_or (combined, i.types[j]); |
11280 | 0 | combined.bitfield.class = ClassNone; |
11281 | 0 | } |
11282 | |
|
11283 | 0 | switch ((i.broadcast.type ? i.broadcast.type : 1) |
11284 | 0 | << (i.memshift < 32 ? i.memshift : 0)) |
11285 | 0 | { |
11286 | 0 | case 64: combined.bitfield.zmmword = 1; break; |
11287 | 0 | case 32: combined.bitfield.ymmword = 1; break; |
11288 | 0 | case 16: combined.bitfield.xmmword = 1; break; |
11289 | 0 | case 8: combined.bitfield.qword = 1; break; |
11290 | 0 | case 4: combined.bitfield.dword = 1; break; |
11291 | 0 | } |
11292 | | |
11293 | 0 | if (i.vec_encoding == vex_encoding_default) |
11294 | 0 | { |
11295 | 0 | if (flag_code == CODE_64BIT && combined.bitfield.qword) |
11296 | 0 | i.rex |= REX_W; |
11297 | 0 | else if ((flag_code == CODE_16BIT ? combined.bitfield.dword |
11298 | 0 | : combined.bitfield.word) |
11299 | 0 | && !add_prefix (DATA_PREFIX_OPCODE)) |
11300 | 0 | goto done; |
11301 | 0 | } |
11302 | 0 | else if (!i.tm.opcode_modifier.vexw) |
11303 | 0 | { |
11304 | 0 | if (flag_code == CODE_64BIT) |
11305 | 0 | { |
11306 | 0 | if (combined.bitfield.qword) |
11307 | 0 | i.tm.opcode_modifier.vexw = VEXW1; |
11308 | 0 | else if (combined.bitfield.dword) |
11309 | 0 | i.tm.opcode_modifier.vexw = VEXW0; |
11310 | 0 | } |
11311 | |
|
11312 | 0 | if (!i.tm.opcode_modifier.vexw) |
11313 | 0 | i.tm.opcode_modifier.vexw = VEXWIG; |
11314 | 0 | } |
11315 | | |
11316 | 0 | if (vex || xop) |
11317 | 0 | { |
11318 | 0 | if (!i.tm.opcode_modifier.vex) |
11319 | 0 | { |
11320 | 0 | if (combined.bitfield.ymmword) |
11321 | 0 | i.tm.opcode_modifier.vex = VEX256; |
11322 | 0 | else if (combined.bitfield.xmmword) |
11323 | 0 | i.tm.opcode_modifier.vex = VEX128; |
11324 | 0 | } |
11325 | 0 | } |
11326 | 0 | else if (evex) |
11327 | 0 | { |
11328 | 0 | if (!i.tm.opcode_modifier.evex) |
11329 | 0 | { |
11330 | | /* Do _not_ consider AVX512VL here. */ |
11331 | 0 | if (i.rounding.type != rc_none || combined.bitfield.zmmword) |
11332 | 0 | i.tm.opcode_modifier.evex = EVEX512; |
11333 | 0 | else if (combined.bitfield.ymmword) |
11334 | 0 | i.tm.opcode_modifier.evex = EVEX256; |
11335 | 0 | else if (combined.bitfield.xmmword) |
11336 | 0 | i.tm.opcode_modifier.evex = EVEX128; |
11337 | 0 | } |
11338 | |
|
11339 | 0 | if (i.memshift >= 32) |
11340 | 0 | { |
11341 | 0 | unsigned int n = 0; |
11342 | |
|
11343 | 0 | switch (i.tm.opcode_modifier.evex) |
11344 | 0 | { |
11345 | 0 | case EVEX512: n = 64; break; |
11346 | 0 | case EVEX256: n = 32; break; |
11347 | 0 | case EVEX128: n = 16; break; |
11348 | 0 | } |
11349 | | |
11350 | 0 | if (i.broadcast.type) |
11351 | 0 | n /= i.broadcast.type; |
11352 | |
|
11353 | 0 | if (n > 0) |
11354 | 0 | for (i.memshift = 0; !(n & 1); n >>= 1) |
11355 | 0 | ++i.memshift; |
11356 | 0 | else if (disp_exp != NULL && disp_exp->X_op == O_constant |
11357 | 0 | && disp_exp->X_add_number != 0 |
11358 | 0 | && i.disp_encoding != disp_encoding_32bit) |
11359 | 0 | { |
11360 | 0 | if (!quiet_warnings) |
11361 | 0 | as_warn ("cannot determine memory operand size"); |
11362 | 0 | i.disp_encoding = disp_encoding_32bit; |
11363 | 0 | } |
11364 | 0 | } |
11365 | 0 | } |
11366 | | |
11367 | 0 | if (i.memshift >= 32) |
11368 | 0 | i.memshift = 0; |
11369 | 0 | else if (!evex) |
11370 | 0 | i.vec_encoding = vex_encoding_error; |
11371 | |
|
11372 | 0 | if (i.disp_operands && !optimize_disp (&i.tm)) |
11373 | 0 | goto done; |
11374 | | |
11375 | | /* Establish size for immediate operands. */ |
11376 | 0 | for (j = 0; j < i.imm_operands; ++j) |
11377 | 0 | { |
11378 | 0 | expressionS *expP = i.op[j].imms; |
11379 | |
|
11380 | 0 | gas_assert (operand_type_check (i.types[j], imm)); |
11381 | 0 | operand_type_set (&i.types[j], 0); |
11382 | |
|
11383 | 0 | if (i.imm_bits[j] > 32) |
11384 | 0 | i.types[j].bitfield.imm64 = 1; |
11385 | 0 | else if (i.imm_bits[j] > 16) |
11386 | 0 | { |
11387 | 0 | if (flag_code == CODE_64BIT && (i.flags[j] & Operand_Signed)) |
11388 | 0 | i.types[j].bitfield.imm32s = 1; |
11389 | 0 | else |
11390 | 0 | i.types[j].bitfield.imm32 = 1; |
11391 | 0 | } |
11392 | 0 | else if (i.imm_bits[j] > 8) |
11393 | 0 | i.types[j].bitfield.imm16 = 1; |
11394 | 0 | else if (i.imm_bits[j] > 0) |
11395 | 0 | { |
11396 | 0 | if (i.flags[j] & Operand_Signed) |
11397 | 0 | i.types[j].bitfield.imm8s = 1; |
11398 | 0 | else |
11399 | 0 | i.types[j].bitfield.imm8 = 1; |
11400 | 0 | } |
11401 | 0 | else if (expP->X_op == O_constant) |
11402 | 0 | { |
11403 | 0 | i.types[j] = smallest_imm_type (expP->X_add_number); |
11404 | 0 | i.types[j].bitfield.imm1 = 0; |
11405 | | /* Oddly enough imm_size() checks imm64 first, so the bit needs |
11406 | | zapping since smallest_imm_type() sets it unconditionally. */ |
11407 | 0 | if (flag_code != CODE_64BIT) |
11408 | 0 | { |
11409 | 0 | i.types[j].bitfield.imm64 = 0; |
11410 | 0 | i.types[j].bitfield.imm32s = 0; |
11411 | 0 | i.types[j].bitfield.imm32 = 1; |
11412 | 0 | } |
11413 | 0 | else if (i.types[j].bitfield.imm32 || i.types[j].bitfield.imm32s) |
11414 | 0 | i.types[j].bitfield.imm64 = 0; |
11415 | 0 | } |
11416 | 0 | else |
11417 | | /* Non-constant expressions are sized heuristically. */ |
11418 | 0 | switch (flag_code) |
11419 | 0 | { |
11420 | 0 | case CODE_64BIT: i.types[j].bitfield.imm32s = 1; break; |
11421 | 0 | case CODE_32BIT: i.types[j].bitfield.imm32 = 1; break; |
11422 | 0 | case CODE_16BIT: i.types[j].bitfield.imm16 = 1; break; |
11423 | 0 | } |
11424 | 0 | } |
11425 | | |
11426 | 0 | for (j = 0; j < i.operands; ++j) |
11427 | 0 | i.tm.operand_types[j] = i.types[j]; |
11428 | |
|
11429 | 0 | process_operands (); |
11430 | 0 | } |
11431 | | |
11432 | | /* Don't set opcode until after processing operands, to avoid any |
11433 | | potential special casing there. */ |
11434 | 31 | i.tm.base_opcode |= val; |
11435 | | |
11436 | 31 | if (i.vec_encoding == vex_encoding_error |
11437 | 31 | || (i.vec_encoding != vex_encoding_evex |
11438 | 31 | ? i.broadcast.type || i.broadcast.bytes |
11439 | 31 | || i.rounding.type != rc_none |
11440 | 31 | || i.mask.reg |
11441 | 31 | : (i.broadcast.type || i.broadcast.bytes) |
11442 | 0 | && i.rounding.type != rc_none)) |
11443 | 0 | { |
11444 | 0 | as_bad (_("conflicting .insn operands")); |
11445 | 0 | goto done; |
11446 | 0 | } |
11447 | | |
11448 | 31 | if (vex || xop) |
11449 | 0 | { |
11450 | 0 | if (!i.tm.opcode_modifier.vex) |
11451 | 0 | i.tm.opcode_modifier.vex = VEXScalar; /* LIG */ |
11452 | |
|
11453 | 0 | build_vex_prefix (NULL); |
11454 | 0 | i.rex &= REX_OPCODE; |
11455 | 0 | } |
11456 | 31 | else if (evex) |
11457 | 0 | { |
11458 | 0 | if (!i.tm.opcode_modifier.evex) |
11459 | 0 | i.tm.opcode_modifier.evex = EVEXLIG; |
11460 | |
|
11461 | 0 | build_evex_prefix (); |
11462 | 0 | i.rex &= REX_OPCODE; |
11463 | 0 | } |
11464 | 31 | else if (i.rex != 0) |
11465 | 0 | add_prefix (REX_OPCODE | i.rex); |
11466 | | |
11467 | 31 | output_insn (); |
11468 | | |
11469 | 32 | done: |
11470 | 32 | *saved_ilp = saved_char; |
11471 | 32 | input_line_pointer = line; |
11472 | | |
11473 | 32 | demand_empty_rest_of_line (); |
11474 | | |
11475 | | /* Make sure dot_insn() won't yield "true" anymore. */ |
11476 | 32 | i.tm.mnem_off = 0; |
11477 | 32 | } |
11478 | | |
11479 | | #ifdef TE_PE |
11480 | | static void |
11481 | | pe_directive_secrel (int dummy ATTRIBUTE_UNUSED) |
11482 | | { |
11483 | | expressionS exp; |
11484 | | |
11485 | | do |
11486 | | { |
11487 | | expression (&exp); |
11488 | | if (exp.X_op == O_symbol) |
11489 | | exp.X_op = O_secrel; |
11490 | | |
11491 | | emit_expr (&exp, 4); |
11492 | | } |
11493 | | while (*input_line_pointer++ == ','); |
11494 | | |
11495 | | input_line_pointer--; |
11496 | | demand_empty_rest_of_line (); |
11497 | | } |
11498 | | |
11499 | | static void |
11500 | | pe_directive_secidx (int dummy ATTRIBUTE_UNUSED) |
11501 | | { |
11502 | | expressionS exp; |
11503 | | |
11504 | | do |
11505 | | { |
11506 | | expression (&exp); |
11507 | | if (exp.X_op == O_symbol) |
11508 | | exp.X_op = O_secidx; |
11509 | | |
11510 | | emit_expr (&exp, 2); |
11511 | | } |
11512 | | while (*input_line_pointer++ == ','); |
11513 | | |
11514 | | input_line_pointer--; |
11515 | | demand_empty_rest_of_line (); |
11516 | | } |
11517 | | #endif |
11518 | | |
11519 | | /* Handle Rounding Control / SAE specifiers. */ |
11520 | | |
11521 | | static char * |
11522 | | RC_SAE_specifier (const char *pstr) |
11523 | 35 | { |
11524 | 35 | unsigned int j; |
11525 | | |
11526 | 202 | for (j = 0; j < ARRAY_SIZE (RC_NamesTable); j++) |
11527 | 175 | { |
11528 | 175 | if (!strncmp (pstr, RC_NamesTable[j].name, RC_NamesTable[j].len)) |
11529 | 8 | { |
11530 | 8 | if (i.rounding.type != rc_none) |
11531 | 0 | { |
11532 | 0 | as_bad (_("duplicated `{%s}'"), RC_NamesTable[j].name); |
11533 | 0 | return NULL; |
11534 | 0 | } |
11535 | | |
11536 | 8 | i.rounding.type = RC_NamesTable[j].type; |
11537 | | |
11538 | 8 | return (char *)(pstr + RC_NamesTable[j].len); |
11539 | 8 | } |
11540 | 175 | } |
11541 | | |
11542 | 27 | return NULL; |
11543 | 35 | } |
11544 | | |
11545 | | /* Handle Vector operations. */ |
11546 | | |
11547 | | static char * |
11548 | | check_VecOperations (char *op_string) |
11549 | 8 | { |
11550 | 8 | const reg_entry *mask; |
11551 | 8 | const char *saved; |
11552 | 8 | char *end_op; |
11553 | | |
11554 | 8 | while (*op_string) |
11555 | 8 | { |
11556 | 8 | saved = op_string; |
11557 | 8 | if (*op_string == '{') |
11558 | 8 | { |
11559 | 8 | op_string++; |
11560 | | |
11561 | | /* Check broadcasts. */ |
11562 | 8 | if (startswith (op_string, "1to")) |
11563 | 0 | { |
11564 | 0 | unsigned int bcst_type; |
11565 | |
|
11566 | 0 | if (i.broadcast.type) |
11567 | 0 | goto duplicated_vec_op; |
11568 | | |
11569 | 0 | op_string += 3; |
11570 | 0 | if (*op_string == '8') |
11571 | 0 | bcst_type = 8; |
11572 | 0 | else if (*op_string == '4') |
11573 | 0 | bcst_type = 4; |
11574 | 0 | else if (*op_string == '2') |
11575 | 0 | bcst_type = 2; |
11576 | 0 | else if (*op_string == '1' |
11577 | 0 | && *(op_string+1) == '6') |
11578 | 0 | { |
11579 | 0 | bcst_type = 16; |
11580 | 0 | op_string++; |
11581 | 0 | } |
11582 | 0 | else if (*op_string == '3' |
11583 | 0 | && *(op_string+1) == '2') |
11584 | 0 | { |
11585 | 0 | bcst_type = 32; |
11586 | 0 | op_string++; |
11587 | 0 | } |
11588 | 0 | else |
11589 | 0 | { |
11590 | 0 | as_bad (_("Unsupported broadcast: `%s'"), saved); |
11591 | 0 | return NULL; |
11592 | 0 | } |
11593 | 0 | op_string++; |
11594 | |
|
11595 | 0 | i.broadcast.type = bcst_type; |
11596 | 0 | i.broadcast.operand = this_operand; |
11597 | | |
11598 | | /* For .insn a data size specifier may be appended. */ |
11599 | 0 | if (dot_insn () && *op_string == ':') |
11600 | 0 | goto dot_insn_modifier; |
11601 | 0 | } |
11602 | | /* Check .insn special cases. */ |
11603 | 8 | else if (dot_insn () && *op_string == ':') |
11604 | 0 | { |
11605 | 0 | dot_insn_modifier: |
11606 | 0 | switch (op_string[1]) |
11607 | 0 | { |
11608 | 0 | unsigned long n; |
11609 | | |
11610 | 0 | case 'd': |
11611 | 0 | if (i.memshift < 32) |
11612 | 0 | goto duplicated_vec_op; |
11613 | | |
11614 | 0 | n = strtoul (op_string + 2, &end_op, 0); |
11615 | 0 | if (n) |
11616 | 0 | for (i.memshift = 0; !(n & 1); n >>= 1) |
11617 | 0 | ++i.memshift; |
11618 | 0 | if (i.memshift < 32 && n == 1) |
11619 | 0 | op_string = end_op; |
11620 | 0 | break; |
11621 | | |
11622 | 0 | case 's': case 'u': |
11623 | | /* This isn't really a "vector" operation, but a sign/size |
11624 | | specifier for immediate operands of .insn. Note that AT&T |
11625 | | syntax handles the same in i386_immediate(). */ |
11626 | 0 | if (!intel_syntax) |
11627 | 0 | break; |
11628 | | |
11629 | 0 | if (i.imm_bits[this_operand]) |
11630 | 0 | goto duplicated_vec_op; |
11631 | | |
11632 | 0 | n = strtoul (op_string + 2, &end_op, 0); |
11633 | 0 | if (n && n <= (flag_code == CODE_64BIT ? 64 : 32)) |
11634 | 0 | { |
11635 | 0 | i.imm_bits[this_operand] = n; |
11636 | 0 | if (op_string[1] == 's') |
11637 | 0 | i.flags[this_operand] |= Operand_Signed; |
11638 | 0 | op_string = end_op; |
11639 | 0 | } |
11640 | 0 | break; |
11641 | 0 | } |
11642 | 0 | } |
11643 | | /* Check masking operation. */ |
11644 | 8 | else if ((mask = parse_register (op_string, &end_op)) != NULL) |
11645 | 0 | { |
11646 | 0 | if (mask == &bad_reg) |
11647 | 0 | return NULL; |
11648 | | |
11649 | | /* k0 can't be used for write mask. */ |
11650 | 0 | if (mask->reg_type.bitfield.class != RegMask || !mask->reg_num) |
11651 | 0 | { |
11652 | 0 | as_bad (_("`%s%s' can't be used for write mask"), |
11653 | 0 | register_prefix, mask->reg_name); |
11654 | 0 | return NULL; |
11655 | 0 | } |
11656 | | |
11657 | 0 | if (!i.mask.reg) |
11658 | 0 | { |
11659 | 0 | i.mask.reg = mask; |
11660 | 0 | i.mask.operand = this_operand; |
11661 | 0 | } |
11662 | 0 | else if (i.mask.reg->reg_num) |
11663 | 0 | goto duplicated_vec_op; |
11664 | 0 | else |
11665 | 0 | { |
11666 | 0 | i.mask.reg = mask; |
11667 | | |
11668 | | /* Only "{z}" is allowed here. No need to check |
11669 | | zeroing mask explicitly. */ |
11670 | 0 | if (i.mask.operand != (unsigned int) this_operand) |
11671 | 0 | { |
11672 | 0 | as_bad (_("invalid write mask `%s'"), saved); |
11673 | 0 | return NULL; |
11674 | 0 | } |
11675 | 0 | } |
11676 | | |
11677 | 0 | op_string = end_op; |
11678 | 0 | } |
11679 | | /* Check zeroing-flag for masking operation. */ |
11680 | 8 | else if (*op_string == 'z') |
11681 | 0 | { |
11682 | 0 | if (!i.mask.reg) |
11683 | 0 | { |
11684 | 0 | i.mask.reg = reg_k0; |
11685 | 0 | i.mask.zeroing = 1; |
11686 | 0 | i.mask.operand = this_operand; |
11687 | 0 | } |
11688 | 0 | else |
11689 | 0 | { |
11690 | 0 | if (i.mask.zeroing) |
11691 | 0 | { |
11692 | 0 | duplicated_vec_op: |
11693 | 0 | as_bad (_("duplicated `%s'"), saved); |
11694 | 0 | return NULL; |
11695 | 0 | } |
11696 | | |
11697 | 0 | i.mask.zeroing = 1; |
11698 | | |
11699 | | /* Only "{%k}" is allowed here. No need to check mask |
11700 | | register explicitly. */ |
11701 | 0 | if (i.mask.operand != (unsigned int) this_operand) |
11702 | 0 | { |
11703 | 0 | as_bad (_("invalid zeroing-masking `%s'"), |
11704 | 0 | saved); |
11705 | 0 | return NULL; |
11706 | 0 | } |
11707 | 0 | } |
11708 | | |
11709 | 0 | op_string++; |
11710 | 0 | } |
11711 | 8 | else if (intel_syntax |
11712 | 8 | && (op_string = RC_SAE_specifier (op_string)) != NULL) |
11713 | 0 | i.rounding.modifier = true; |
11714 | 8 | else |
11715 | 8 | goto unknown_vec_op; |
11716 | | |
11717 | 0 | if (*op_string != '}') |
11718 | 0 | { |
11719 | 0 | as_bad (_("missing `}' in `%s'"), saved); |
11720 | 0 | return NULL; |
11721 | 0 | } |
11722 | 0 | op_string++; |
11723 | | |
11724 | | /* Strip whitespace since the addition of pseudo prefixes |
11725 | | changed how the scrubber treats '{'. */ |
11726 | 0 | if (is_space_char (*op_string)) |
11727 | 0 | ++op_string; |
11728 | |
|
11729 | 0 | continue; |
11730 | 0 | } |
11731 | 8 | unknown_vec_op: |
11732 | | /* We don't know this one. */ |
11733 | 8 | as_bad (_("unknown vector operation: `%s'"), saved); |
11734 | 8 | return NULL; |
11735 | 8 | } |
11736 | | |
11737 | 0 | if (i.mask.reg && i.mask.zeroing && !i.mask.reg->reg_num) |
11738 | 0 | { |
11739 | 0 | as_bad (_("zeroing-masking only allowed with write mask")); |
11740 | 0 | return NULL; |
11741 | 0 | } |
11742 | | |
11743 | 0 | return op_string; |
11744 | 0 | } |
11745 | | |
11746 | | static int |
11747 | | i386_immediate (char *imm_start) |
11748 | 179k | { |
11749 | 179k | char *save_input_line_pointer; |
11750 | 179k | char *gotfree_input_line; |
11751 | 179k | segT exp_seg = 0; |
11752 | 179k | expressionS *exp; |
11753 | 179k | i386_operand_type types; |
11754 | | |
11755 | 179k | operand_type_set (&types, ~0); |
11756 | | |
11757 | 179k | if (i.imm_operands == MAX_IMMEDIATE_OPERANDS) |
11758 | 0 | { |
11759 | 0 | as_bad (_("at most %d immediate operands are allowed"), |
11760 | 0 | MAX_IMMEDIATE_OPERANDS); |
11761 | 0 | return 0; |
11762 | 0 | } |
11763 | | |
11764 | 179k | exp = &im_expressions[i.imm_operands++]; |
11765 | 179k | i.op[this_operand].imms = exp; |
11766 | | |
11767 | 179k | if (is_space_char (*imm_start)) |
11768 | 2.76k | ++imm_start; |
11769 | | |
11770 | 179k | save_input_line_pointer = input_line_pointer; |
11771 | 179k | input_line_pointer = imm_start; |
11772 | | |
11773 | 179k | gotfree_input_line = lex_got (&i.reloc[this_operand], NULL, &types); |
11774 | 179k | if (gotfree_input_line) |
11775 | 580 | input_line_pointer = gotfree_input_line; |
11776 | | |
11777 | 179k | expr_mode = expr_operator_none; |
11778 | 179k | exp_seg = expression (exp); |
11779 | | |
11780 | | /* For .insn immediates there may be a size specifier. */ |
11781 | 179k | if (dot_insn () && *input_line_pointer == '{' && input_line_pointer[1] == ':' |
11782 | 179k | && (input_line_pointer[2] == 's' || input_line_pointer[2] == 'u')) |
11783 | 0 | { |
11784 | 0 | char *e; |
11785 | 0 | unsigned long n = strtoul (input_line_pointer + 3, &e, 0); |
11786 | |
|
11787 | 0 | if (*e == '}' && n && n <= (flag_code == CODE_64BIT ? 64 : 32)) |
11788 | 0 | { |
11789 | 0 | i.imm_bits[this_operand] = n; |
11790 | 0 | if (input_line_pointer[2] == 's') |
11791 | 0 | i.flags[this_operand] |= Operand_Signed; |
11792 | 0 | input_line_pointer = e + 1; |
11793 | 0 | } |
11794 | 0 | } |
11795 | | |
11796 | 179k | SKIP_WHITESPACE (); |
11797 | 179k | if (*input_line_pointer) |
11798 | 12.4k | as_bad (_("junk `%s' after expression"), input_line_pointer); |
11799 | | |
11800 | 179k | input_line_pointer = save_input_line_pointer; |
11801 | 179k | if (gotfree_input_line) |
11802 | 580 | { |
11803 | 580 | free (gotfree_input_line); |
11804 | | |
11805 | 580 | if (exp->X_op == O_constant) |
11806 | 220 | exp->X_op = O_illegal; |
11807 | 580 | } |
11808 | | |
11809 | 179k | if (exp_seg == reg_section) |
11810 | 41 | { |
11811 | 41 | as_bad (_("illegal immediate register operand %s"), imm_start); |
11812 | 41 | return 0; |
11813 | 41 | } |
11814 | | |
11815 | 179k | return i386_finalize_immediate (exp_seg, exp, types, imm_start); |
11816 | 179k | } |
11817 | | |
11818 | | static int |
11819 | | i386_finalize_immediate (segT exp_seg ATTRIBUTE_UNUSED, expressionS *exp, |
11820 | | i386_operand_type types, const char *imm_start) |
11821 | 179k | { |
11822 | 179k | if (exp->X_op == O_absent || exp->X_op == O_illegal || exp->X_op == O_big) |
11823 | 20.0k | { |
11824 | 20.0k | if (imm_start) |
11825 | 20.0k | as_bad (_("missing or invalid immediate expression `%s'"), |
11826 | 20.0k | imm_start); |
11827 | 20.0k | return 0; |
11828 | 20.0k | } |
11829 | 159k | else if (exp->X_op == O_constant) |
11830 | 141k | { |
11831 | | /* Size it properly later. */ |
11832 | 141k | i.types[this_operand].bitfield.imm64 = 1; |
11833 | | |
11834 | | /* If not 64bit, sign/zero extend val, to account for wraparound |
11835 | | when !BFD64. */ |
11836 | 141k | if (expr_mode == expr_operator_present |
11837 | 141k | && flag_code != CODE_64BIT && !object_64bit) |
11838 | 0 | exp->X_add_number = extend_to_32bit_address (exp->X_add_number); |
11839 | 141k | } |
11840 | | #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)) |
11841 | | else if (OUTPUT_FLAVOR == bfd_target_aout_flavour |
11842 | | && exp_seg != absolute_section |
11843 | | && exp_seg != text_section |
11844 | | && exp_seg != data_section |
11845 | | && exp_seg != bss_section |
11846 | | && exp_seg != undefined_section |
11847 | | && !bfd_is_com_section (exp_seg)) |
11848 | | { |
11849 | | as_bad (_("unimplemented segment %s in operand"), exp_seg->name); |
11850 | | return 0; |
11851 | | } |
11852 | | #endif |
11853 | 18.0k | else |
11854 | 18.0k | { |
11855 | | /* This is an address. The size of the address will be |
11856 | | determined later, depending on destination register, |
11857 | | suffix, or the default for the section. */ |
11858 | 18.0k | i.types[this_operand].bitfield.imm8 = 1; |
11859 | 18.0k | i.types[this_operand].bitfield.imm16 = 1; |
11860 | 18.0k | i.types[this_operand].bitfield.imm32 = 1; |
11861 | 18.0k | i.types[this_operand].bitfield.imm32s = 1; |
11862 | 18.0k | i.types[this_operand].bitfield.imm64 = 1; |
11863 | 18.0k | i.types[this_operand] = operand_type_and (i.types[this_operand], |
11864 | 18.0k | types); |
11865 | 18.0k | } |
11866 | | |
11867 | 159k | return 1; |
11868 | 179k | } |
11869 | | |
11870 | | static char * |
11871 | | i386_scale (char *scale) |
11872 | 26 | { |
11873 | 26 | offsetT val; |
11874 | 26 | char *save = input_line_pointer; |
11875 | | |
11876 | 26 | input_line_pointer = scale; |
11877 | 26 | val = get_absolute_expression (); |
11878 | | |
11879 | 26 | switch (val) |
11880 | 26 | { |
11881 | 0 | case 1: |
11882 | 0 | i.log2_scale_factor = 0; |
11883 | 0 | break; |
11884 | 13 | case 2: |
11885 | 13 | i.log2_scale_factor = 1; |
11886 | 13 | break; |
11887 | 0 | case 4: |
11888 | 0 | i.log2_scale_factor = 2; |
11889 | 0 | break; |
11890 | 0 | case 8: |
11891 | 0 | i.log2_scale_factor = 3; |
11892 | 0 | break; |
11893 | 13 | default: |
11894 | 13 | { |
11895 | 13 | char sep = *input_line_pointer; |
11896 | | |
11897 | 13 | *input_line_pointer = '\0'; |
11898 | 13 | as_bad (_("expecting scale factor of 1, 2, 4, or 8: got `%s'"), |
11899 | 13 | scale); |
11900 | 13 | *input_line_pointer = sep; |
11901 | 13 | input_line_pointer = save; |
11902 | 13 | return NULL; |
11903 | 0 | } |
11904 | 26 | } |
11905 | 13 | if (i.log2_scale_factor != 0 && i.index_reg == 0) |
11906 | 13 | { |
11907 | 13 | as_warn (_("scale factor of %d without an index register"), |
11908 | 13 | 1 << i.log2_scale_factor); |
11909 | 13 | i.log2_scale_factor = 0; |
11910 | 13 | } |
11911 | 13 | scale = input_line_pointer; |
11912 | 13 | input_line_pointer = save; |
11913 | 13 | return scale; |
11914 | 26 | } |
11915 | | |
11916 | | static int |
11917 | | i386_displacement (char *disp_start, char *disp_end) |
11918 | 239k | { |
11919 | 239k | expressionS *exp; |
11920 | 239k | segT exp_seg = 0; |
11921 | 239k | char *save_input_line_pointer; |
11922 | 239k | char *gotfree_input_line; |
11923 | 239k | int override; |
11924 | 239k | i386_operand_type bigdisp, types = anydisp; |
11925 | 239k | int ret; |
11926 | | |
11927 | 239k | if (i.disp_operands == MAX_MEMORY_OPERANDS) |
11928 | 0 | { |
11929 | 0 | as_bad (_("at most %d displacement operands are allowed"), |
11930 | 0 | MAX_MEMORY_OPERANDS); |
11931 | 0 | return 0; |
11932 | 0 | } |
11933 | | |
11934 | 239k | operand_type_set (&bigdisp, 0); |
11935 | 239k | if (i.jumpabsolute |
11936 | 239k | || i.types[this_operand].bitfield.baseindex |
11937 | 239k | || (current_templates->start->opcode_modifier.jump != JUMP |
11938 | 239k | && current_templates->start->opcode_modifier.jump != JUMP_DWORD)) |
11939 | 212k | { |
11940 | 212k | i386_addressing_mode (); |
11941 | 212k | override = (i.prefix[ADDR_PREFIX] != 0); |
11942 | 212k | if (flag_code == CODE_64BIT) |
11943 | 78.6k | { |
11944 | 78.6k | bigdisp.bitfield.disp32 = 1; |
11945 | 78.6k | if (!override) |
11946 | 78.6k | bigdisp.bitfield.disp64 = 1; |
11947 | 78.6k | } |
11948 | 134k | else if ((flag_code == CODE_16BIT) ^ override) |
11949 | 96.1k | bigdisp.bitfield.disp16 = 1; |
11950 | 38.2k | else |
11951 | 38.2k | bigdisp.bitfield.disp32 = 1; |
11952 | 212k | } |
11953 | 26.5k | else |
11954 | 26.5k | { |
11955 | | /* For PC-relative branches, the width of the displacement may be |
11956 | | dependent upon data size, but is never dependent upon address size. |
11957 | | Also make sure to not unintentionally match against a non-PC-relative |
11958 | | branch template. */ |
11959 | 26.5k | static templates aux_templates; |
11960 | 26.5k | const insn_template *t = current_templates->start; |
11961 | 26.5k | bool has_intel64 = false; |
11962 | | |
11963 | 26.5k | aux_templates.start = t; |
11964 | 27.4k | while (++t < current_templates->end) |
11965 | 1.37k | { |
11966 | 1.37k | if (t->opcode_modifier.jump |
11967 | 1.37k | != current_templates->start->opcode_modifier.jump) |
11968 | 469 | break; |
11969 | 902 | if ((t->opcode_modifier.isa64 >= INTEL64)) |
11970 | 481 | has_intel64 = true; |
11971 | 902 | } |
11972 | 26.5k | if (t < current_templates->end) |
11973 | 469 | { |
11974 | 469 | aux_templates.end = t; |
11975 | 469 | current_templates = &aux_templates; |
11976 | 469 | } |
11977 | | |
11978 | 26.5k | override = (i.prefix[DATA_PREFIX] != 0); |
11979 | 26.5k | if (flag_code == CODE_64BIT) |
11980 | 12.7k | { |
11981 | 12.7k | if ((override || i.suffix == WORD_MNEM_SUFFIX) |
11982 | 12.7k | && (!intel64 || !has_intel64)) |
11983 | 80 | bigdisp.bitfield.disp16 = 1; |
11984 | 12.6k | else |
11985 | 12.6k | bigdisp.bitfield.disp32 = 1; |
11986 | 12.7k | } |
11987 | 13.8k | else |
11988 | 13.8k | { |
11989 | 13.8k | if (!override) |
11990 | 13.8k | override = (i.suffix == (flag_code != CODE_16BIT |
11991 | 13.8k | ? WORD_MNEM_SUFFIX |
11992 | 13.8k | : LONG_MNEM_SUFFIX)); |
11993 | 13.8k | bigdisp.bitfield.disp32 = 1; |
11994 | 13.8k | if ((flag_code == CODE_16BIT) ^ override) |
11995 | 11.3k | { |
11996 | 11.3k | bigdisp.bitfield.disp32 = 0; |
11997 | 11.3k | bigdisp.bitfield.disp16 = 1; |
11998 | 11.3k | } |
11999 | 13.8k | } |
12000 | 26.5k | } |
12001 | 239k | i.types[this_operand] = operand_type_or (i.types[this_operand], |
12002 | 239k | bigdisp); |
12003 | | |
12004 | 239k | exp = &disp_expressions[i.disp_operands]; |
12005 | 239k | i.op[this_operand].disps = exp; |
12006 | 239k | i.disp_operands++; |
12007 | 239k | save_input_line_pointer = input_line_pointer; |
12008 | 239k | input_line_pointer = disp_start; |
12009 | 239k | END_STRING_AND_SAVE (disp_end); |
12010 | | |
12011 | 239k | #ifndef GCC_ASM_O_HACK |
12012 | 239k | #define GCC_ASM_O_HACK 0 |
12013 | 239k | #endif |
12014 | | #if GCC_ASM_O_HACK |
12015 | | END_STRING_AND_SAVE (disp_end + 1); |
12016 | | if (i.types[this_operand].bitfield.baseIndex |
12017 | | && displacement_string_end[-1] == '+') |
12018 | | { |
12019 | | /* This hack is to avoid a warning when using the "o" |
12020 | | constraint within gcc asm statements. |
12021 | | For instance: |
12022 | | |
12023 | | #define _set_tssldt_desc(n,addr,limit,type) \ |
12024 | | __asm__ __volatile__ ( \ |
12025 | | "movw %w2,%0\n\t" \ |
12026 | | "movw %w1,2+%0\n\t" \ |
12027 | | "rorl $16,%1\n\t" \ |
12028 | | "movb %b1,4+%0\n\t" \ |
12029 | | "movb %4,5+%0\n\t" \ |
12030 | | "movb $0,6+%0\n\t" \ |
12031 | | "movb %h1,7+%0\n\t" \ |
12032 | | "rorl $16,%1" \ |
12033 | | : "=o"(*(n)) : "q" (addr), "ri"(limit), "i"(type)) |
12034 | | |
12035 | | This works great except that the output assembler ends |
12036 | | up looking a bit weird if it turns out that there is |
12037 | | no offset. You end up producing code that looks like: |
12038 | | |
12039 | | #APP |
12040 | | movw $235,(%eax) |
12041 | | movw %dx,2+(%eax) |
12042 | | rorl $16,%edx |
12043 | | movb %dl,4+(%eax) |
12044 | | movb $137,5+(%eax) |
12045 | | movb $0,6+(%eax) |
12046 | | movb %dh,7+(%eax) |
12047 | | rorl $16,%edx |
12048 | | #NO_APP |
12049 | | |
12050 | | So here we provide the missing zero. */ |
12051 | | |
12052 | | *displacement_string_end = '0'; |
12053 | | } |
12054 | | #endif |
12055 | 239k | gotfree_input_line = lex_got (&i.reloc[this_operand], NULL, &types); |
12056 | 239k | if (gotfree_input_line) |
12057 | 1.74k | input_line_pointer = gotfree_input_line; |
12058 | | |
12059 | 239k | expr_mode = expr_operator_none; |
12060 | 239k | exp_seg = expression (exp); |
12061 | | |
12062 | 239k | SKIP_WHITESPACE (); |
12063 | 239k | if (*input_line_pointer) |
12064 | 33.4k | as_bad (_("junk `%s' after expression"), input_line_pointer); |
12065 | | #if GCC_ASM_O_HACK |
12066 | | RESTORE_END_STRING (disp_end + 1); |
12067 | | #endif |
12068 | 239k | input_line_pointer = save_input_line_pointer; |
12069 | 239k | if (gotfree_input_line) |
12070 | 1.74k | { |
12071 | 1.74k | free (gotfree_input_line); |
12072 | | |
12073 | 1.74k | if (exp->X_op == O_constant || exp->X_op == O_register) |
12074 | 32 | exp->X_op = O_illegal; |
12075 | 1.74k | } |
12076 | | |
12077 | 239k | ret = i386_finalize_displacement (exp_seg, exp, types, disp_start); |
12078 | | |
12079 | 239k | RESTORE_END_STRING (disp_end); |
12080 | | |
12081 | 239k | return ret; |
12082 | 239k | } |
12083 | | |
12084 | | static int |
12085 | | i386_finalize_displacement (segT exp_seg ATTRIBUTE_UNUSED, expressionS *exp, |
12086 | | i386_operand_type types, const char *disp_start) |
12087 | 239k | { |
12088 | 239k | int ret = 1; |
12089 | | |
12090 | | /* We do this to make sure that the section symbol is in |
12091 | | the symbol table. We will ultimately change the relocation |
12092 | | to be relative to the beginning of the section. */ |
12093 | 239k | if (i.reloc[this_operand] == BFD_RELOC_386_GOTOFF |
12094 | 239k | || i.reloc[this_operand] == BFD_RELOC_X86_64_GOTPCREL |
12095 | 239k | || i.reloc[this_operand] == BFD_RELOC_X86_64_GOTOFF64) |
12096 | 912 | { |
12097 | 912 | if (exp->X_op != O_symbol) |
12098 | 22 | goto inv_disp; |
12099 | | |
12100 | 890 | if (S_IS_LOCAL (exp->X_add_symbol) |
12101 | 890 | && S_GET_SEGMENT (exp->X_add_symbol) != undefined_section |
12102 | 890 | && S_GET_SEGMENT (exp->X_add_symbol) != expr_section) |
12103 | 109 | section_symbol (S_GET_SEGMENT (exp->X_add_symbol)); |
12104 | 890 | exp->X_op = O_subtract; |
12105 | 890 | exp->X_op_symbol = GOT_symbol; |
12106 | 890 | if (i.reloc[this_operand] == BFD_RELOC_X86_64_GOTPCREL) |
12107 | 262 | i.reloc[this_operand] = BFD_RELOC_32_PCREL; |
12108 | 628 | else if (i.reloc[this_operand] == BFD_RELOC_X86_64_GOTOFF64) |
12109 | 628 | i.reloc[this_operand] = BFD_RELOC_64; |
12110 | 0 | else |
12111 | 0 | i.reloc[this_operand] = BFD_RELOC_32; |
12112 | 890 | } |
12113 | | |
12114 | 238k | else if (exp->X_op == O_absent |
12115 | 238k | || exp->X_op == O_illegal |
12116 | 238k | || exp->X_op == O_big) |
12117 | 713 | { |
12118 | 735 | inv_disp: |
12119 | 735 | as_bad (_("missing or invalid displacement expression `%s'"), |
12120 | 735 | disp_start); |
12121 | 735 | ret = 0; |
12122 | 735 | } |
12123 | | |
12124 | 237k | else if (exp->X_op == O_constant) |
12125 | 123k | { |
12126 | | /* Sizing gets taken care of by optimize_disp(). |
12127 | | |
12128 | | If not 64bit, sign/zero extend val, to account for wraparound |
12129 | | when !BFD64. */ |
12130 | 123k | if (expr_mode == expr_operator_present |
12131 | 123k | && flag_code != CODE_64BIT && !object_64bit) |
12132 | 0 | exp->X_add_number = extend_to_32bit_address (exp->X_add_number); |
12133 | 123k | } |
12134 | | |
12135 | | #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)) |
12136 | | else if (OUTPUT_FLAVOR == bfd_target_aout_flavour |
12137 | | && exp_seg != absolute_section |
12138 | | && exp_seg != text_section |
12139 | | && exp_seg != data_section |
12140 | | && exp_seg != bss_section |
12141 | | && exp_seg != undefined_section |
12142 | | && !bfd_is_com_section (exp_seg)) |
12143 | | { |
12144 | | as_bad (_("unimplemented segment %s in operand"), exp_seg->name); |
12145 | | ret = 0; |
12146 | | } |
12147 | | #endif |
12148 | | |
12149 | 113k | else if (current_templates->start->opcode_modifier.jump == JUMP_BYTE) |
12150 | 676 | i.types[this_operand].bitfield.disp8 = 1; |
12151 | | |
12152 | | /* Check if this is a displacement only operand. */ |
12153 | 239k | if (!i.types[this_operand].bitfield.baseindex) |
12154 | 239k | i.types[this_operand] = |
12155 | 239k | operand_type_or (operand_type_and_not (i.types[this_operand], anydisp), |
12156 | 239k | operand_type_and (i.types[this_operand], types)); |
12157 | | |
12158 | 239k | return ret; |
12159 | 239k | } |
12160 | | |
12161 | | /* Return the active addressing mode, taking address override and |
12162 | | registers forming the address into consideration. Update the |
12163 | | address override prefix if necessary. */ |
12164 | | |
12165 | | static enum flag_code |
12166 | | i386_addressing_mode (void) |
12167 | 452k | { |
12168 | 452k | enum flag_code addr_mode; |
12169 | | |
12170 | 452k | if (i.prefix[ADDR_PREFIX]) |
12171 | 0 | addr_mode = flag_code == CODE_32BIT ? CODE_16BIT : CODE_32BIT; |
12172 | 452k | else if (flag_code == CODE_16BIT |
12173 | 452k | && is_cpu (current_templates->start, CpuMPX) |
12174 | | /* Avoid replacing the "16-bit addressing not allowed" diagnostic |
12175 | | from md_assemble() by "is not a valid base/index expression" |
12176 | | when there is a base and/or index. */ |
12177 | 452k | && !i.types[this_operand].bitfield.baseindex) |
12178 | 0 | { |
12179 | | /* MPX insn memory operands with neither base nor index must be forced |
12180 | | to use 32-bit addressing in 16-bit mode. */ |
12181 | 0 | addr_mode = CODE_32BIT; |
12182 | 0 | i.prefix[ADDR_PREFIX] = ADDR_PREFIX_OPCODE; |
12183 | 0 | ++i.prefixes; |
12184 | 0 | gas_assert (!i.types[this_operand].bitfield.disp16); |
12185 | 0 | gas_assert (!i.types[this_operand].bitfield.disp32); |
12186 | 0 | } |
12187 | 452k | else |
12188 | 452k | { |
12189 | 452k | addr_mode = flag_code; |
12190 | | |
12191 | 452k | #if INFER_ADDR_PREFIX |
12192 | 452k | if (i.mem_operands == 0) |
12193 | 404k | { |
12194 | | /* Infer address prefix from the first memory operand. */ |
12195 | 404k | const reg_entry *addr_reg = i.base_reg; |
12196 | | |
12197 | 404k | if (addr_reg == NULL) |
12198 | 404k | addr_reg = i.index_reg; |
12199 | | |
12200 | 404k | if (addr_reg) |
12201 | 0 | { |
12202 | 0 | if (addr_reg->reg_type.bitfield.dword) |
12203 | 0 | addr_mode = CODE_32BIT; |
12204 | 0 | else if (flag_code != CODE_64BIT |
12205 | 0 | && addr_reg->reg_type.bitfield.word) |
12206 | 0 | addr_mode = CODE_16BIT; |
12207 | |
|
12208 | 0 | if (addr_mode != flag_code) |
12209 | 0 | { |
12210 | 0 | i.prefix[ADDR_PREFIX] = ADDR_PREFIX_OPCODE; |
12211 | 0 | i.prefixes += 1; |
12212 | | /* Change the size of any displacement too. At most one |
12213 | | of Disp16 or Disp32 is set. |
12214 | | FIXME. There doesn't seem to be any real need for |
12215 | | separate Disp16 and Disp32 flags. The same goes for |
12216 | | Imm16 and Imm32. Removing them would probably clean |
12217 | | up the code quite a lot. */ |
12218 | 0 | if (flag_code != CODE_64BIT |
12219 | 0 | && (i.types[this_operand].bitfield.disp16 |
12220 | 0 | || i.types[this_operand].bitfield.disp32)) |
12221 | 0 | { |
12222 | 0 | static const i386_operand_type disp16_32 = { |
12223 | 0 | .bitfield = { .disp16 = 1, .disp32 = 1 } |
12224 | 0 | }; |
12225 | |
|
12226 | 0 | i.types[this_operand] |
12227 | 0 | = operand_type_xor (i.types[this_operand], disp16_32); |
12228 | 0 | } |
12229 | 0 | } |
12230 | 0 | } |
12231 | 404k | } |
12232 | 452k | #endif |
12233 | 452k | } |
12234 | | |
12235 | 0 | return addr_mode; |
12236 | 452k | } |
12237 | | |
12238 | | /* Make sure the memory operand we've been dealt is valid. |
12239 | | Return 1 on success, 0 on a failure. */ |
12240 | | |
12241 | | static int |
12242 | | i386_index_check (const char *operand_string) |
12243 | 239k | { |
12244 | 239k | const char *kind = "base/index"; |
12245 | 239k | enum flag_code addr_mode = i386_addressing_mode (); |
12246 | 239k | const insn_template *t = current_templates->end - 1; |
12247 | | |
12248 | 239k | if (t->opcode_modifier.isstring) |
12249 | 12.4k | { |
12250 | | /* Memory operands of string insns are special in that they only allow |
12251 | | a single register (rDI, rSI, or rBX) as their memory address. */ |
12252 | 12.4k | const reg_entry *expected_reg; |
12253 | 12.4k | static const char di_si[][2][4] = |
12254 | 12.4k | { |
12255 | 12.4k | { "esi", "edi" }, |
12256 | 12.4k | { "si", "di" }, |
12257 | 12.4k | { "rsi", "rdi" } |
12258 | 12.4k | }; |
12259 | 12.4k | static const char bx[][4] = { "ebx", "bx", "rbx" }; |
12260 | | |
12261 | 12.4k | kind = "string address"; |
12262 | | |
12263 | 12.4k | if (t->opcode_modifier.prefixok == PrefixRep) |
12264 | 12.2k | { |
12265 | 12.2k | int es_op = t->opcode_modifier.isstring - IS_STRING_ES_OP0; |
12266 | 12.2k | int op = 0; |
12267 | | |
12268 | 12.2k | if (!t->operand_types[0].bitfield.baseindex |
12269 | 12.2k | || ((!i.mem_operands != !intel_syntax) |
12270 | 12.1k | && t->operand_types[1].bitfield.baseindex)) |
12271 | 4.64k | op = 1; |
12272 | 12.2k | expected_reg |
12273 | 12.2k | = (const reg_entry *) str_hash_find (reg_hash, |
12274 | 12.2k | di_si[addr_mode][op == es_op]); |
12275 | 12.2k | } |
12276 | 153 | else |
12277 | 153 | expected_reg |
12278 | 153 | = (const reg_entry *)str_hash_find (reg_hash, bx[addr_mode]); |
12279 | | |
12280 | 12.4k | if (i.base_reg != expected_reg |
12281 | 12.4k | || i.index_reg |
12282 | 12.4k | || operand_type_check (i.types[this_operand], disp)) |
12283 | 12.4k | { |
12284 | | /* The second memory operand must have the same size as |
12285 | | the first one. */ |
12286 | 12.4k | if (i.mem_operands |
12287 | 12.4k | && i.base_reg |
12288 | 12.4k | && !((addr_mode == CODE_64BIT |
12289 | 0 | && i.base_reg->reg_type.bitfield.qword) |
12290 | 0 | || (addr_mode == CODE_32BIT |
12291 | 0 | ? i.base_reg->reg_type.bitfield.dword |
12292 | 0 | : i.base_reg->reg_type.bitfield.word))) |
12293 | 0 | goto bad_address; |
12294 | | |
12295 | 12.4k | as_warn (_("`%s' is not valid here (expected `%c%s%s%c')"), |
12296 | 12.4k | operand_string, |
12297 | 12.4k | intel_syntax ? '[' : '(', |
12298 | 12.4k | register_prefix, |
12299 | 12.4k | expected_reg->reg_name, |
12300 | 12.4k | intel_syntax ? ']' : ')'); |
12301 | 12.4k | return 1; |
12302 | 12.4k | } |
12303 | 0 | else |
12304 | 0 | return 1; |
12305 | | |
12306 | 0 | bad_address: |
12307 | 0 | as_bad (_("`%s' is not a valid %s expression"), |
12308 | 0 | operand_string, kind); |
12309 | 0 | return 0; |
12310 | 12.4k | } |
12311 | 226k | else |
12312 | 226k | { |
12313 | 226k | t = current_templates->start; |
12314 | | |
12315 | 226k | if (addr_mode != CODE_16BIT) |
12316 | 123k | { |
12317 | | /* 32-bit/64-bit checks. */ |
12318 | 123k | if (i.disp_encoding == disp_encoding_16bit) |
12319 | 0 | { |
12320 | 19 | bad_disp: |
12321 | 19 | as_bad (_("invalid `%s' prefix"), |
12322 | 19 | addr_mode == CODE_16BIT ? "{disp32}" : "{disp16}"); |
12323 | 19 | return 0; |
12324 | 0 | } |
12325 | | |
12326 | 123k | if ((i.base_reg |
12327 | 123k | && ((addr_mode == CODE_64BIT |
12328 | 0 | ? !i.base_reg->reg_type.bitfield.qword |
12329 | 0 | : !i.base_reg->reg_type.bitfield.dword) |
12330 | 0 | || (i.index_reg && i.base_reg->reg_num == RegIP) |
12331 | 0 | || i.base_reg->reg_num == RegIZ)) |
12332 | 123k | || (i.index_reg |
12333 | 123k | && !i.index_reg->reg_type.bitfield.xmmword |
12334 | 123k | && !i.index_reg->reg_type.bitfield.ymmword |
12335 | 123k | && !i.index_reg->reg_type.bitfield.zmmword |
12336 | 123k | && ((addr_mode == CODE_64BIT |
12337 | 0 | ? !i.index_reg->reg_type.bitfield.qword |
12338 | 0 | : !i.index_reg->reg_type.bitfield.dword) |
12339 | 0 | || !i.index_reg->reg_type.bitfield.baseindex))) |
12340 | 0 | goto bad_address; |
12341 | | |
12342 | | /* bndmk, bndldx, bndstx and mandatory non-vector SIB have special restrictions. */ |
12343 | 123k | if (t->mnem_off == MN_bndmk |
12344 | 123k | || t->mnem_off == MN_bndldx |
12345 | 123k | || t->mnem_off == MN_bndstx |
12346 | 123k | || t->opcode_modifier.sib == SIBMEM) |
12347 | 43 | { |
12348 | | /* They cannot use RIP-relative addressing. */ |
12349 | 43 | if (i.base_reg && i.base_reg->reg_num == RegIP) |
12350 | 0 | { |
12351 | 0 | as_bad (_("`%s' cannot be used here"), operand_string); |
12352 | 0 | return 0; |
12353 | 0 | } |
12354 | | |
12355 | | /* bndldx and bndstx ignore their scale factor. */ |
12356 | 43 | if ((t->mnem_off == MN_bndldx || t->mnem_off == MN_bndstx) |
12357 | 43 | && i.log2_scale_factor) |
12358 | 0 | as_warn (_("register scaling is being ignored here")); |
12359 | 43 | } |
12360 | 123k | } |
12361 | 102k | else |
12362 | 102k | { |
12363 | | /* 16-bit checks. */ |
12364 | 102k | if (i.disp_encoding == disp_encoding_32bit) |
12365 | 19 | goto bad_disp; |
12366 | | |
12367 | 102k | if ((i.base_reg |
12368 | 102k | && (!i.base_reg->reg_type.bitfield.word |
12369 | 0 | || !i.base_reg->reg_type.bitfield.baseindex)) |
12370 | 102k | || (i.index_reg |
12371 | 102k | && (!i.index_reg->reg_type.bitfield.word |
12372 | 0 | || !i.index_reg->reg_type.bitfield.baseindex |
12373 | 0 | || !(i.base_reg |
12374 | 0 | && i.base_reg->reg_num < 6 |
12375 | 0 | && i.index_reg->reg_num >= 6 |
12376 | 0 | && i.log2_scale_factor == 0)))) |
12377 | 0 | goto bad_address; |
12378 | 102k | } |
12379 | 226k | } |
12380 | 226k | return 1; |
12381 | 239k | } |
12382 | | |
12383 | | /* Handle vector immediates. */ |
12384 | | |
12385 | | static int |
12386 | | RC_SAE_immediate (const char *imm_start) |
12387 | 241k | { |
12388 | 241k | const char *pstr = imm_start; |
12389 | | |
12390 | 241k | if (*pstr != '{') |
12391 | 241k | return 0; |
12392 | | |
12393 | 35 | pstr = RC_SAE_specifier (pstr + 1); |
12394 | 35 | if (pstr == NULL) |
12395 | 27 | return 0; |
12396 | | |
12397 | 8 | if (*pstr++ != '}') |
12398 | 8 | { |
12399 | 8 | as_bad (_("Missing '}': '%s'"), imm_start); |
12400 | 8 | return 0; |
12401 | 8 | } |
12402 | 0 | /* RC/SAE immediate string should contain nothing more. */; |
12403 | 0 | if (*pstr != 0) |
12404 | 0 | { |
12405 | 0 | as_bad (_("Junk after '}': '%s'"), imm_start); |
12406 | 0 | return 0; |
12407 | 0 | } |
12408 | | |
12409 | | /* Internally this doesn't count as an operand. */ |
12410 | 0 | --i.operands; |
12411 | |
|
12412 | 0 | return 1; |
12413 | 0 | } |
12414 | | |
12415 | | static INLINE bool starts_memory_operand (char c) |
12416 | 241k | { |
12417 | 241k | return ISDIGIT (c) |
12418 | 241k | || is_name_beginner (c) |
12419 | 241k | || strchr ("([\"+-!~", c); |
12420 | 241k | } |
12421 | | |
12422 | | /* Parse OPERAND_STRING into the i386_insn structure I. Returns zero |
12423 | | on error. */ |
12424 | | |
12425 | | static int |
12426 | | i386_att_operand (char *operand_string) |
12427 | 421k | { |
12428 | 421k | const reg_entry *r; |
12429 | 421k | char *end_op; |
12430 | 421k | char *op_string = operand_string; |
12431 | | |
12432 | 421k | if (is_space_char (*op_string)) |
12433 | 0 | ++op_string; |
12434 | | |
12435 | | /* We check for an absolute prefix (differentiating, |
12436 | | for example, 'jmp pc_relative_label' from 'jmp *absolute_label'. */ |
12437 | 421k | if (*op_string == ABSOLUTE_PREFIX |
12438 | 421k | && current_templates->start->opcode_modifier.jump) |
12439 | 581 | { |
12440 | 581 | ++op_string; |
12441 | 581 | if (is_space_char (*op_string)) |
12442 | 11 | ++op_string; |
12443 | 581 | i.jumpabsolute = true; |
12444 | 581 | } |
12445 | | |
12446 | | /* Check if operand is a register. */ |
12447 | 421k | if ((r = parse_register (op_string, &end_op)) != NULL) |
12448 | 306 | { |
12449 | 306 | i386_operand_type temp; |
12450 | | |
12451 | 306 | if (r == &bad_reg) |
12452 | 0 | return 0; |
12453 | | |
12454 | | /* Check for a segment override by searching for ':' after a |
12455 | | segment register. */ |
12456 | 306 | op_string = end_op; |
12457 | 306 | if (is_space_char (*op_string)) |
12458 | 10 | ++op_string; |
12459 | 306 | if (*op_string == ':' && r->reg_type.bitfield.class == SReg) |
12460 | 276 | { |
12461 | 276 | i.seg[i.mem_operands] = r; |
12462 | | |
12463 | | /* Skip the ':' and whitespace. */ |
12464 | 276 | ++op_string; |
12465 | 276 | if (is_space_char (*op_string)) |
12466 | 0 | ++op_string; |
12467 | | |
12468 | | /* Handle case of %es:*foo. */ |
12469 | 276 | if (!i.jumpabsolute && *op_string == ABSOLUTE_PREFIX |
12470 | 276 | && current_templates->start->opcode_modifier.jump) |
12471 | 0 | { |
12472 | 0 | ++op_string; |
12473 | 0 | if (is_space_char (*op_string)) |
12474 | 0 | ++op_string; |
12475 | 0 | i.jumpabsolute = true; |
12476 | 0 | } |
12477 | | |
12478 | 276 | if (!starts_memory_operand (*op_string)) |
12479 | 0 | { |
12480 | 0 | as_bad (_("bad memory operand `%s'"), op_string); |
12481 | 0 | return 0; |
12482 | 0 | } |
12483 | 276 | goto do_memory_reference; |
12484 | 276 | } |
12485 | | |
12486 | | /* Handle vector operations. */ |
12487 | 30 | if (*op_string == '{') |
12488 | 0 | { |
12489 | 0 | op_string = check_VecOperations (op_string); |
12490 | 0 | if (op_string == NULL) |
12491 | 0 | return 0; |
12492 | 0 | } |
12493 | | |
12494 | 30 | if (*op_string) |
12495 | 23 | { |
12496 | 23 | as_bad (_("junk `%s' after register"), op_string); |
12497 | 23 | return 0; |
12498 | 23 | } |
12499 | | |
12500 | | /* Reject pseudo registers for .insn. */ |
12501 | 7 | if (dot_insn () && r->reg_type.bitfield.class == ClassNone) |
12502 | 0 | { |
12503 | 0 | as_bad (_("`%s%s' cannot be used here"), |
12504 | 0 | register_prefix, r->reg_name); |
12505 | 0 | return 0; |
12506 | 0 | } |
12507 | | |
12508 | 7 | temp = r->reg_type; |
12509 | 7 | temp.bitfield.baseindex = 0; |
12510 | 7 | i.types[this_operand] = operand_type_or (i.types[this_operand], |
12511 | 7 | temp); |
12512 | 7 | i.types[this_operand].bitfield.unspecified = 0; |
12513 | 7 | i.op[this_operand].regs = r; |
12514 | 7 | i.reg_operands++; |
12515 | | |
12516 | | /* A GPR may follow an RC or SAE immediate only if a (vector) register |
12517 | | operand was also present earlier on. */ |
12518 | 7 | if (i.rounding.type != rc_none && temp.bitfield.class == Reg |
12519 | 7 | && i.reg_operands == 1) |
12520 | 0 | { |
12521 | 0 | unsigned int j; |
12522 | |
|
12523 | 0 | for (j = 0; j < ARRAY_SIZE (RC_NamesTable); ++j) |
12524 | 0 | if (i.rounding.type == RC_NamesTable[j].type) |
12525 | 0 | break; |
12526 | 0 | as_bad (_("`%s': misplaced `{%s}'"), |
12527 | 0 | insn_name (current_templates->start), RC_NamesTable[j].name); |
12528 | 0 | return 0; |
12529 | 0 | } |
12530 | 7 | } |
12531 | 420k | else if (*op_string == REGISTER_PREFIX) |
12532 | 180 | { |
12533 | 180 | as_bad (_("bad register name `%s'"), op_string); |
12534 | 180 | return 0; |
12535 | 180 | } |
12536 | 420k | else if (*op_string == IMMEDIATE_PREFIX) |
12537 | 179k | { |
12538 | 179k | ++op_string; |
12539 | 179k | if (i.jumpabsolute) |
12540 | 0 | { |
12541 | 0 | as_bad (_("immediate operand illegal with absolute jump")); |
12542 | 0 | return 0; |
12543 | 0 | } |
12544 | 179k | if (!i386_immediate (op_string)) |
12545 | 20.0k | return 0; |
12546 | 159k | if (i.rounding.type != rc_none) |
12547 | 0 | { |
12548 | 0 | as_bad (_("`%s': RC/SAE operand must follow immediate operands"), |
12549 | 0 | insn_name (current_templates->start)); |
12550 | 0 | return 0; |
12551 | 0 | } |
12552 | 159k | } |
12553 | 241k | else if (RC_SAE_immediate (operand_string)) |
12554 | 0 | { |
12555 | | /* If it is a RC or SAE immediate, do the necessary placement check: |
12556 | | Only another immediate or a GPR may precede it. */ |
12557 | 0 | if (i.mem_operands || i.reg_operands + i.imm_operands > 1 |
12558 | 0 | || (i.reg_operands == 1 |
12559 | 0 | && i.op[0].regs->reg_type.bitfield.class != Reg)) |
12560 | 0 | { |
12561 | 0 | as_bad (_("`%s': misplaced `%s'"), |
12562 | 0 | insn_name (current_templates->start), operand_string); |
12563 | 0 | return 0; |
12564 | 0 | } |
12565 | 0 | } |
12566 | 241k | else if (starts_memory_operand (*op_string)) |
12567 | 240k | { |
12568 | | /* This is a memory reference of some sort. */ |
12569 | 240k | char *base_string; |
12570 | | |
12571 | | /* Start and end of displacement string expression (if found). */ |
12572 | 240k | char *displacement_string_start; |
12573 | 240k | char *displacement_string_end; |
12574 | | |
12575 | 240k | do_memory_reference: |
12576 | | /* Check for base index form. We detect the base index form by |
12577 | | looking for an ')' at the end of the operand, searching |
12578 | | for the '(' matching it, and finding a REGISTER_PREFIX or ',' |
12579 | | after the '('. */ |
12580 | 240k | base_string = op_string + strlen (op_string); |
12581 | | |
12582 | | /* Handle vector operations. */ |
12583 | 240k | --base_string; |
12584 | 240k | if (is_space_char (*base_string)) |
12585 | 257 | --base_string; |
12586 | | |
12587 | 240k | if (*base_string == '}') |
12588 | 563 | { |
12589 | 563 | char *vop_start = NULL; |
12590 | | |
12591 | 2.32k | while (base_string-- > op_string) |
12592 | 1.77k | { |
12593 | 1.77k | if (*base_string == '"') |
12594 | 9 | break; |
12595 | 1.77k | if (*base_string != '{') |
12596 | 1.76k | continue; |
12597 | | |
12598 | 8 | vop_start = base_string; |
12599 | | |
12600 | 8 | --base_string; |
12601 | 8 | if (is_space_char (*base_string)) |
12602 | 7 | --base_string; |
12603 | | |
12604 | 8 | if (*base_string != '}') |
12605 | 8 | break; |
12606 | | |
12607 | 0 | vop_start = NULL; |
12608 | 0 | } |
12609 | | |
12610 | 563 | if (!vop_start) |
12611 | 555 | { |
12612 | 555 | as_bad (_("unbalanced figure braces")); |
12613 | 555 | return 0; |
12614 | 555 | } |
12615 | | |
12616 | 8 | if (check_VecOperations (vop_start) == NULL) |
12617 | 8 | return 0; |
12618 | 8 | } |
12619 | | |
12620 | | /* If we only have a displacement, set-up for it to be parsed later. */ |
12621 | 240k | displacement_string_start = op_string; |
12622 | 240k | displacement_string_end = base_string + 1; |
12623 | | |
12624 | 240k | if (*base_string == ')') |
12625 | 2.44k | { |
12626 | 2.44k | char *temp_string; |
12627 | 2.44k | unsigned int parens_not_balanced = 0; |
12628 | 2.44k | bool in_quotes = false; |
12629 | | |
12630 | | /* We've already checked that the number of left & right ()'s are |
12631 | | equal, and that there's a matching set of double quotes. */ |
12632 | 2.44k | end_op = base_string; |
12633 | 28.1k | for (temp_string = op_string; temp_string < end_op; temp_string++) |
12634 | 25.6k | { |
12635 | 25.6k | if (*temp_string == '\\' && temp_string[1] == '"') |
12636 | 0 | ++temp_string; |
12637 | 25.6k | else if (*temp_string == '"') |
12638 | 0 | in_quotes = !in_quotes; |
12639 | 25.6k | else if (!in_quotes) |
12640 | 25.6k | { |
12641 | 25.6k | if (*temp_string == '(' && !parens_not_balanced++) |
12642 | 2.53k | base_string = temp_string; |
12643 | 25.6k | if (*temp_string == ')') |
12644 | 634 | --parens_not_balanced; |
12645 | 25.6k | } |
12646 | 25.6k | } |
12647 | | |
12648 | 2.44k | temp_string = base_string; |
12649 | | |
12650 | | /* Skip past '(' and whitespace. */ |
12651 | 2.44k | gas_assert (*base_string == '('); |
12652 | 0 | ++base_string; |
12653 | 2.44k | if (is_space_char (*base_string)) |
12654 | 235 | ++base_string; |
12655 | | |
12656 | 2.44k | if (*base_string == ',' |
12657 | 2.44k | || ((i.base_reg = parse_register (base_string, &end_op)) |
12658 | 2.41k | != NULL)) |
12659 | 26 | { |
12660 | 26 | displacement_string_end = temp_string; |
12661 | | |
12662 | 26 | i.types[this_operand].bitfield.baseindex = 1; |
12663 | | |
12664 | 26 | if (i.base_reg) |
12665 | 0 | { |
12666 | 0 | if (i.base_reg == &bad_reg) |
12667 | 0 | return 0; |
12668 | 0 | base_string = end_op; |
12669 | 0 | if (is_space_char (*base_string)) |
12670 | 0 | ++base_string; |
12671 | 0 | } |
12672 | | |
12673 | | /* There may be an index reg or scale factor here. */ |
12674 | 26 | if (*base_string == ',') |
12675 | 26 | { |
12676 | 26 | ++base_string; |
12677 | 26 | if (is_space_char (*base_string)) |
12678 | 0 | ++base_string; |
12679 | | |
12680 | 26 | if ((i.index_reg = parse_register (base_string, &end_op)) |
12681 | 26 | != NULL) |
12682 | 0 | { |
12683 | 0 | if (i.index_reg == &bad_reg) |
12684 | 0 | return 0; |
12685 | 0 | base_string = end_op; |
12686 | 0 | if (is_space_char (*base_string)) |
12687 | 0 | ++base_string; |
12688 | 0 | if (*base_string == ',') |
12689 | 0 | { |
12690 | 0 | ++base_string; |
12691 | 0 | if (is_space_char (*base_string)) |
12692 | 0 | ++base_string; |
12693 | 0 | } |
12694 | 0 | else if (*base_string != ')') |
12695 | 0 | { |
12696 | 0 | as_bad (_("expecting `,' or `)' " |
12697 | 0 | "after index register in `%s'"), |
12698 | 0 | operand_string); |
12699 | 0 | return 0; |
12700 | 0 | } |
12701 | 0 | } |
12702 | 26 | else if (*base_string == REGISTER_PREFIX) |
12703 | 0 | { |
12704 | 0 | end_op = strchr (base_string, ','); |
12705 | 0 | if (end_op) |
12706 | 0 | *end_op = '\0'; |
12707 | 0 | as_bad (_("bad register name `%s'"), base_string); |
12708 | 0 | return 0; |
12709 | 0 | } |
12710 | | |
12711 | | /* Check for scale factor. */ |
12712 | 26 | if (*base_string != ')') |
12713 | 26 | { |
12714 | 26 | char *end_scale = i386_scale (base_string); |
12715 | | |
12716 | 26 | if (!end_scale) |
12717 | 13 | return 0; |
12718 | | |
12719 | 13 | base_string = end_scale; |
12720 | 13 | if (is_space_char (*base_string)) |
12721 | 0 | ++base_string; |
12722 | 13 | if (*base_string != ')') |
12723 | 13 | { |
12724 | 13 | as_bad (_("expecting `)' " |
12725 | 13 | "after scale factor in `%s'"), |
12726 | 13 | operand_string); |
12727 | 13 | return 0; |
12728 | 13 | } |
12729 | 13 | } |
12730 | 0 | else if (!i.index_reg) |
12731 | 0 | { |
12732 | 0 | as_bad (_("expecting index register or scale factor " |
12733 | 0 | "after `,'; got '%c'"), |
12734 | 0 | *base_string); |
12735 | 0 | return 0; |
12736 | 0 | } |
12737 | 26 | } |
12738 | 0 | else if (*base_string != ')') |
12739 | 0 | { |
12740 | 0 | as_bad (_("expecting `,' or `)' " |
12741 | 0 | "after base register in `%s'"), |
12742 | 0 | operand_string); |
12743 | 0 | return 0; |
12744 | 0 | } |
12745 | 26 | } |
12746 | 2.41k | else if (*base_string == REGISTER_PREFIX) |
12747 | 408 | { |
12748 | 408 | end_op = strchr (base_string, ','); |
12749 | 408 | if (end_op) |
12750 | 2 | *end_op = '\0'; |
12751 | 408 | as_bad (_("bad register name `%s'"), base_string); |
12752 | 408 | return 0; |
12753 | 408 | } |
12754 | 2.44k | } |
12755 | | |
12756 | | /* If there's an expression beginning the operand, parse it, |
12757 | | assuming displacement_string_start and |
12758 | | displacement_string_end are meaningful. */ |
12759 | 239k | if (displacement_string_start != displacement_string_end) |
12760 | 239k | { |
12761 | 239k | if (!i386_displacement (displacement_string_start, |
12762 | 239k | displacement_string_end)) |
12763 | 735 | return 0; |
12764 | 239k | } |
12765 | | |
12766 | | /* Special case for (%dx) while doing input/output op. */ |
12767 | 239k | if (i.base_reg |
12768 | 239k | && i.base_reg->reg_type.bitfield.instance == RegD |
12769 | 239k | && i.base_reg->reg_type.bitfield.word |
12770 | 239k | && i.index_reg == 0 |
12771 | 239k | && i.log2_scale_factor == 0 |
12772 | 239k | && i.seg[i.mem_operands] == 0 |
12773 | 239k | && !operand_type_check (i.types[this_operand], disp)) |
12774 | 0 | { |
12775 | 0 | i.types[this_operand] = i.base_reg->reg_type; |
12776 | 0 | i.input_output_operand = true; |
12777 | 0 | return 1; |
12778 | 0 | } |
12779 | | |
12780 | 239k | if (i386_index_check (operand_string) == 0) |
12781 | 19 | return 0; |
12782 | 239k | i.flags[this_operand] |= Operand_Mem; |
12783 | 239k | i.mem_operands++; |
12784 | 239k | } |
12785 | 639 | else |
12786 | 639 | { |
12787 | | /* It's not a memory operand; argh! */ |
12788 | 639 | as_bad (_("invalid char %s beginning operand %d `%s'"), |
12789 | 639 | output_invalid (*op_string), |
12790 | 639 | this_operand + 1, |
12791 | 639 | op_string); |
12792 | 639 | return 0; |
12793 | 639 | } |
12794 | 398k | return 1; /* Normal return. */ |
12795 | 421k | } |
12796 | | |
12797 | | /* Calculate the maximum variable size (i.e., excluding fr_fix) |
12798 | | that an rs_machine_dependent frag may reach. */ |
12799 | | |
12800 | | unsigned int |
12801 | | i386_frag_max_var (fragS *frag) |
12802 | 0 | { |
12803 | | /* The only relaxable frags are for jumps. |
12804 | | Unconditional jumps can grow by 4 bytes and others by 5 bytes. */ |
12805 | 0 | gas_assert (frag->fr_type == rs_machine_dependent); |
12806 | 0 | return TYPE_FROM_RELAX_STATE (frag->fr_subtype) == UNCOND_JUMP ? 4 : 5; |
12807 | 0 | } |
12808 | | |
12809 | | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
12810 | | static int |
12811 | | elf_symbol_resolved_in_segment_p (symbolS *fr_symbol, offsetT fr_var) |
12812 | 0 | { |
12813 | | /* STT_GNU_IFUNC symbol must go through PLT. */ |
12814 | 0 | if ((symbol_get_bfdsym (fr_symbol)->flags |
12815 | 0 | & BSF_GNU_INDIRECT_FUNCTION) != 0) |
12816 | 0 | return 0; |
12817 | | |
12818 | 0 | if (!S_IS_EXTERNAL (fr_symbol)) |
12819 | | /* Symbol may be weak or local. */ |
12820 | 0 | return !S_IS_WEAK (fr_symbol); |
12821 | | |
12822 | | /* Global symbols with non-default visibility can't be preempted. */ |
12823 | 0 | if (ELF_ST_VISIBILITY (S_GET_OTHER (fr_symbol)) != STV_DEFAULT) |
12824 | 0 | return 1; |
12825 | | |
12826 | 0 | if (fr_var != NO_RELOC) |
12827 | 0 | switch ((enum bfd_reloc_code_real) fr_var) |
12828 | 0 | { |
12829 | 0 | case BFD_RELOC_386_PLT32: |
12830 | 0 | case BFD_RELOC_X86_64_PLT32: |
12831 | | /* Symbol with PLT relocation may be preempted. */ |
12832 | 0 | return 0; |
12833 | 0 | default: |
12834 | 0 | abort (); |
12835 | 0 | } |
12836 | | |
12837 | | /* Global symbols with default visibility in a shared library may be |
12838 | | preempted by another definition. */ |
12839 | 0 | return !shared; |
12840 | 0 | } |
12841 | | #endif |
12842 | | |
12843 | | /* Table 3-2. Macro-Fusible Instructions in Haswell Microarchitecture |
12844 | | Note also work for Skylake and Cascadelake. |
12845 | | --------------------------------------------------------------------- |
12846 | | | JCC | ADD/SUB/CMP | INC/DEC | TEST/AND | |
12847 | | | ------ | ----------- | ------- | -------- | |
12848 | | | Jo | N | N | Y | |
12849 | | | Jno | N | N | Y | |
12850 | | | Jc/Jb | Y | N | Y | |
12851 | | | Jae/Jnb | Y | N | Y | |
12852 | | | Je/Jz | Y | Y | Y | |
12853 | | | Jne/Jnz | Y | Y | Y | |
12854 | | | Jna/Jbe | Y | N | Y | |
12855 | | | Ja/Jnbe | Y | N | Y | |
12856 | | | Js | N | N | Y | |
12857 | | | Jns | N | N | Y | |
12858 | | | Jp/Jpe | N | N | Y | |
12859 | | | Jnp/Jpo | N | N | Y | |
12860 | | | Jl/Jnge | Y | Y | Y | |
12861 | | | Jge/Jnl | Y | Y | Y | |
12862 | | | Jle/Jng | Y | Y | Y | |
12863 | | | Jg/Jnle | Y | Y | Y | |
12864 | | --------------------------------------------------------------------- */ |
12865 | | static int |
12866 | | i386_macro_fusible_p (enum mf_cmp_kind mf_cmp, enum mf_jcc_kind mf_jcc) |
12867 | 0 | { |
12868 | 0 | if (mf_cmp == mf_cmp_alu_cmp) |
12869 | 0 | return ((mf_jcc >= mf_jcc_jc && mf_jcc <= mf_jcc_jna) |
12870 | 0 | || mf_jcc == mf_jcc_jl || mf_jcc == mf_jcc_jle); |
12871 | 0 | if (mf_cmp == mf_cmp_incdec) |
12872 | 0 | return (mf_jcc == mf_jcc_je || mf_jcc == mf_jcc_jl |
12873 | 0 | || mf_jcc == mf_jcc_jle); |
12874 | 0 | if (mf_cmp == mf_cmp_test_and) |
12875 | 0 | return 1; |
12876 | 0 | return 0; |
12877 | 0 | } |
12878 | | |
12879 | | /* Return the next non-empty frag. */ |
12880 | | |
12881 | | static fragS * |
12882 | | i386_next_non_empty_frag (fragS *fragP) |
12883 | 0 | { |
12884 | | /* There may be a frag with a ".fill 0" when there is no room in |
12885 | | the current frag for frag_grow in output_insn. */ |
12886 | 0 | for (fragP = fragP->fr_next; |
12887 | 0 | (fragP != NULL |
12888 | 0 | && fragP->fr_type == rs_fill |
12889 | 0 | && fragP->fr_fix == 0); |
12890 | 0 | fragP = fragP->fr_next) |
12891 | 0 | ; |
12892 | 0 | return fragP; |
12893 | 0 | } |
12894 | | |
12895 | | /* Return the next jcc frag after BRANCH_PADDING. */ |
12896 | | |
12897 | | static fragS * |
12898 | | i386_next_fusible_jcc_frag (fragS *maybe_cmp_fragP, fragS *pad_fragP) |
12899 | 0 | { |
12900 | 0 | fragS *branch_fragP; |
12901 | 0 | if (!pad_fragP) |
12902 | 0 | return NULL; |
12903 | | |
12904 | 0 | if (pad_fragP->fr_type == rs_machine_dependent |
12905 | 0 | && (TYPE_FROM_RELAX_STATE (pad_fragP->fr_subtype) |
12906 | 0 | == BRANCH_PADDING)) |
12907 | 0 | { |
12908 | 0 | branch_fragP = i386_next_non_empty_frag (pad_fragP); |
12909 | 0 | if (branch_fragP->fr_type != rs_machine_dependent) |
12910 | 0 | return NULL; |
12911 | 0 | if (TYPE_FROM_RELAX_STATE (branch_fragP->fr_subtype) == COND_JUMP |
12912 | 0 | && i386_macro_fusible_p (maybe_cmp_fragP->tc_frag_data.mf_type, |
12913 | 0 | pad_fragP->tc_frag_data.mf_type)) |
12914 | 0 | return branch_fragP; |
12915 | 0 | } |
12916 | | |
12917 | 0 | return NULL; |
12918 | 0 | } |
12919 | | |
12920 | | /* Classify BRANCH_PADDING, BRANCH_PREFIX and FUSED_JCC_PADDING frags. */ |
12921 | | |
12922 | | static void |
12923 | | i386_classify_machine_dependent_frag (fragS *fragP) |
12924 | 0 | { |
12925 | 0 | fragS *cmp_fragP; |
12926 | 0 | fragS *pad_fragP; |
12927 | 0 | fragS *branch_fragP; |
12928 | 0 | fragS *next_fragP; |
12929 | 0 | unsigned int max_prefix_length; |
12930 | |
|
12931 | 0 | if (fragP->tc_frag_data.classified) |
12932 | 0 | return; |
12933 | | |
12934 | | /* First scan for BRANCH_PADDING and FUSED_JCC_PADDING. Convert |
12935 | | FUSED_JCC_PADDING and merge BRANCH_PADDING. */ |
12936 | 0 | for (next_fragP = fragP; |
12937 | 0 | next_fragP != NULL; |
12938 | 0 | next_fragP = next_fragP->fr_next) |
12939 | 0 | { |
12940 | 0 | next_fragP->tc_frag_data.classified = 1; |
12941 | 0 | if (next_fragP->fr_type == rs_machine_dependent) |
12942 | 0 | switch (TYPE_FROM_RELAX_STATE (next_fragP->fr_subtype)) |
12943 | 0 | { |
12944 | 0 | case BRANCH_PADDING: |
12945 | | /* The BRANCH_PADDING frag must be followed by a branch |
12946 | | frag. */ |
12947 | 0 | branch_fragP = i386_next_non_empty_frag (next_fragP); |
12948 | 0 | next_fragP->tc_frag_data.u.branch_fragP = branch_fragP; |
12949 | 0 | break; |
12950 | 0 | case FUSED_JCC_PADDING: |
12951 | | /* Check if this is a fused jcc: |
12952 | | FUSED_JCC_PADDING |
12953 | | CMP like instruction |
12954 | | BRANCH_PADDING |
12955 | | COND_JUMP |
12956 | | */ |
12957 | 0 | cmp_fragP = i386_next_non_empty_frag (next_fragP); |
12958 | 0 | pad_fragP = i386_next_non_empty_frag (cmp_fragP); |
12959 | 0 | branch_fragP = i386_next_fusible_jcc_frag (next_fragP, pad_fragP); |
12960 | 0 | if (branch_fragP) |
12961 | 0 | { |
12962 | | /* The BRANCH_PADDING frag is merged with the |
12963 | | FUSED_JCC_PADDING frag. */ |
12964 | 0 | next_fragP->tc_frag_data.u.branch_fragP = branch_fragP; |
12965 | | /* CMP like instruction size. */ |
12966 | 0 | next_fragP->tc_frag_data.cmp_size = cmp_fragP->fr_fix; |
12967 | 0 | frag_wane (pad_fragP); |
12968 | | /* Skip to branch_fragP. */ |
12969 | 0 | next_fragP = branch_fragP; |
12970 | 0 | } |
12971 | 0 | else if (next_fragP->tc_frag_data.max_prefix_length) |
12972 | 0 | { |
12973 | | /* Turn FUSED_JCC_PADDING into BRANCH_PREFIX if it isn't |
12974 | | a fused jcc. */ |
12975 | 0 | next_fragP->fr_subtype |
12976 | 0 | = ENCODE_RELAX_STATE (BRANCH_PREFIX, 0); |
12977 | 0 | next_fragP->tc_frag_data.max_bytes |
12978 | 0 | = next_fragP->tc_frag_data.max_prefix_length; |
12979 | | /* This will be updated in the BRANCH_PREFIX scan. */ |
12980 | 0 | next_fragP->tc_frag_data.max_prefix_length = 0; |
12981 | 0 | } |
12982 | 0 | else |
12983 | 0 | frag_wane (next_fragP); |
12984 | 0 | break; |
12985 | 0 | } |
12986 | 0 | } |
12987 | | |
12988 | | /* Stop if there is no BRANCH_PREFIX. */ |
12989 | 0 | if (!align_branch_prefix_size) |
12990 | 0 | return; |
12991 | | |
12992 | | /* Scan for BRANCH_PREFIX. */ |
12993 | 0 | for (; fragP != NULL; fragP = fragP->fr_next) |
12994 | 0 | { |
12995 | 0 | if (fragP->fr_type != rs_machine_dependent |
12996 | 0 | || (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) |
12997 | 0 | != BRANCH_PREFIX)) |
12998 | 0 | continue; |
12999 | | |
13000 | | /* Count all BRANCH_PREFIX frags before BRANCH_PADDING and |
13001 | | COND_JUMP_PREFIX. */ |
13002 | 0 | max_prefix_length = 0; |
13003 | 0 | for (next_fragP = fragP; |
13004 | 0 | next_fragP != NULL; |
13005 | 0 | next_fragP = next_fragP->fr_next) |
13006 | 0 | { |
13007 | 0 | if (next_fragP->fr_type == rs_fill) |
13008 | | /* Skip rs_fill frags. */ |
13009 | 0 | continue; |
13010 | 0 | else if (next_fragP->fr_type != rs_machine_dependent) |
13011 | | /* Stop for all other frags. */ |
13012 | 0 | break; |
13013 | | |
13014 | | /* rs_machine_dependent frags. */ |
13015 | 0 | if (TYPE_FROM_RELAX_STATE (next_fragP->fr_subtype) |
13016 | 0 | == BRANCH_PREFIX) |
13017 | 0 | { |
13018 | | /* Count BRANCH_PREFIX frags. */ |
13019 | 0 | if (max_prefix_length >= MAX_FUSED_JCC_PADDING_SIZE) |
13020 | 0 | { |
13021 | 0 | max_prefix_length = MAX_FUSED_JCC_PADDING_SIZE; |
13022 | 0 | frag_wane (next_fragP); |
13023 | 0 | } |
13024 | 0 | else |
13025 | 0 | max_prefix_length |
13026 | 0 | += next_fragP->tc_frag_data.max_bytes; |
13027 | 0 | } |
13028 | 0 | else if ((TYPE_FROM_RELAX_STATE (next_fragP->fr_subtype) |
13029 | 0 | == BRANCH_PADDING) |
13030 | 0 | || (TYPE_FROM_RELAX_STATE (next_fragP->fr_subtype) |
13031 | 0 | == FUSED_JCC_PADDING)) |
13032 | 0 | { |
13033 | | /* Stop at BRANCH_PADDING and FUSED_JCC_PADDING. */ |
13034 | 0 | fragP->tc_frag_data.u.padding_fragP = next_fragP; |
13035 | 0 | break; |
13036 | 0 | } |
13037 | 0 | else |
13038 | | /* Stop for other rs_machine_dependent frags. */ |
13039 | 0 | break; |
13040 | 0 | } |
13041 | |
|
13042 | 0 | fragP->tc_frag_data.max_prefix_length = max_prefix_length; |
13043 | | |
13044 | | /* Skip to the next frag. */ |
13045 | 0 | fragP = next_fragP; |
13046 | 0 | } |
13047 | 0 | } |
13048 | | |
13049 | | /* Compute padding size for |
13050 | | |
13051 | | FUSED_JCC_PADDING |
13052 | | CMP like instruction |
13053 | | BRANCH_PADDING |
13054 | | COND_JUMP/UNCOND_JUMP |
13055 | | |
13056 | | or |
13057 | | |
13058 | | BRANCH_PADDING |
13059 | | COND_JUMP/UNCOND_JUMP |
13060 | | */ |
13061 | | |
13062 | | static int |
13063 | | i386_branch_padding_size (fragS *fragP, offsetT address) |
13064 | 0 | { |
13065 | 0 | unsigned int offset, size, padding_size; |
13066 | 0 | fragS *branch_fragP = fragP->tc_frag_data.u.branch_fragP; |
13067 | | |
13068 | | /* The start address of the BRANCH_PADDING or FUSED_JCC_PADDING frag. */ |
13069 | 0 | if (!address) |
13070 | 0 | address = fragP->fr_address; |
13071 | 0 | address += fragP->fr_fix; |
13072 | | |
13073 | | /* CMP like instrunction size. */ |
13074 | 0 | size = fragP->tc_frag_data.cmp_size; |
13075 | | |
13076 | | /* The base size of the branch frag. */ |
13077 | 0 | size += branch_fragP->fr_fix; |
13078 | | |
13079 | | /* Add opcode and displacement bytes for the rs_machine_dependent |
13080 | | branch frag. */ |
13081 | 0 | if (branch_fragP->fr_type == rs_machine_dependent) |
13082 | 0 | size += md_relax_table[branch_fragP->fr_subtype].rlx_length; |
13083 | | |
13084 | | /* Check if branch is within boundary and doesn't end at the last |
13085 | | byte. */ |
13086 | 0 | offset = address & ((1U << align_branch_power) - 1); |
13087 | 0 | if ((offset + size) >= (1U << align_branch_power)) |
13088 | | /* Padding needed to avoid crossing boundary. */ |
13089 | 0 | padding_size = (1U << align_branch_power) - offset; |
13090 | 0 | else |
13091 | | /* No padding needed. */ |
13092 | 0 | padding_size = 0; |
13093 | | |
13094 | | /* The return value may be saved in tc_frag_data.length which is |
13095 | | unsigned byte. */ |
13096 | 0 | if (!fits_in_unsigned_byte (padding_size)) |
13097 | 0 | abort (); |
13098 | | |
13099 | 0 | return padding_size; |
13100 | 0 | } |
13101 | | |
13102 | | /* i386_generic_table_relax_frag() |
13103 | | |
13104 | | Handle BRANCH_PADDING, BRANCH_PREFIX and FUSED_JCC_PADDING frags to |
13105 | | grow/shrink padding to align branch frags. Hand others to |
13106 | | relax_frag(). */ |
13107 | | |
13108 | | long |
13109 | | i386_generic_table_relax_frag (segT segment, fragS *fragP, long stretch) |
13110 | 0 | { |
13111 | 0 | if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PADDING |
13112 | 0 | || TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == FUSED_JCC_PADDING) |
13113 | 0 | { |
13114 | 0 | long padding_size = i386_branch_padding_size (fragP, 0); |
13115 | 0 | long grow = padding_size - fragP->tc_frag_data.length; |
13116 | | |
13117 | | /* When the BRANCH_PREFIX frag is used, the computed address |
13118 | | must match the actual address and there should be no padding. */ |
13119 | 0 | if (fragP->tc_frag_data.padding_address |
13120 | 0 | && (fragP->tc_frag_data.padding_address != fragP->fr_address |
13121 | 0 | || padding_size)) |
13122 | 0 | abort (); |
13123 | | |
13124 | | /* Update the padding size. */ |
13125 | 0 | if (grow) |
13126 | 0 | fragP->tc_frag_data.length = padding_size; |
13127 | |
|
13128 | 0 | return grow; |
13129 | 0 | } |
13130 | 0 | else if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PREFIX) |
13131 | 0 | { |
13132 | 0 | fragS *padding_fragP, *next_fragP; |
13133 | 0 | long padding_size, left_size, last_size; |
13134 | |
|
13135 | 0 | padding_fragP = fragP->tc_frag_data.u.padding_fragP; |
13136 | 0 | if (!padding_fragP) |
13137 | | /* Use the padding set by the leading BRANCH_PREFIX frag. */ |
13138 | 0 | return (fragP->tc_frag_data.length |
13139 | 0 | - fragP->tc_frag_data.last_length); |
13140 | | |
13141 | | /* Compute the relative address of the padding frag in the very |
13142 | | first time where the BRANCH_PREFIX frag sizes are zero. */ |
13143 | 0 | if (!fragP->tc_frag_data.padding_address) |
13144 | 0 | fragP->tc_frag_data.padding_address |
13145 | 0 | = padding_fragP->fr_address - (fragP->fr_address - stretch); |
13146 | | |
13147 | | /* First update the last length from the previous interation. */ |
13148 | 0 | left_size = fragP->tc_frag_data.prefix_length; |
13149 | 0 | for (next_fragP = fragP; |
13150 | 0 | next_fragP != padding_fragP; |
13151 | 0 | next_fragP = next_fragP->fr_next) |
13152 | 0 | if (next_fragP->fr_type == rs_machine_dependent |
13153 | 0 | && (TYPE_FROM_RELAX_STATE (next_fragP->fr_subtype) |
13154 | 0 | == BRANCH_PREFIX)) |
13155 | 0 | { |
13156 | 0 | if (left_size) |
13157 | 0 | { |
13158 | 0 | int max = next_fragP->tc_frag_data.max_bytes; |
13159 | 0 | if (max) |
13160 | 0 | { |
13161 | 0 | int size; |
13162 | 0 | if (max > left_size) |
13163 | 0 | size = left_size; |
13164 | 0 | else |
13165 | 0 | size = max; |
13166 | 0 | left_size -= size; |
13167 | 0 | next_fragP->tc_frag_data.last_length = size; |
13168 | 0 | } |
13169 | 0 | } |
13170 | 0 | else |
13171 | 0 | next_fragP->tc_frag_data.last_length = 0; |
13172 | 0 | } |
13173 | | |
13174 | | /* Check the padding size for the padding frag. */ |
13175 | 0 | padding_size = i386_branch_padding_size |
13176 | 0 | (padding_fragP, (fragP->fr_address |
13177 | 0 | + fragP->tc_frag_data.padding_address)); |
13178 | |
|
13179 | 0 | last_size = fragP->tc_frag_data.prefix_length; |
13180 | | /* Check if there is change from the last interation. */ |
13181 | 0 | if (padding_size == last_size) |
13182 | 0 | { |
13183 | | /* Update the expected address of the padding frag. */ |
13184 | 0 | padding_fragP->tc_frag_data.padding_address |
13185 | 0 | = (fragP->fr_address + padding_size |
13186 | 0 | + fragP->tc_frag_data.padding_address); |
13187 | 0 | return 0; |
13188 | 0 | } |
13189 | | |
13190 | 0 | if (padding_size > fragP->tc_frag_data.max_prefix_length) |
13191 | 0 | { |
13192 | | /* No padding if there is no sufficient room. Clear the |
13193 | | expected address of the padding frag. */ |
13194 | 0 | padding_fragP->tc_frag_data.padding_address = 0; |
13195 | 0 | padding_size = 0; |
13196 | 0 | } |
13197 | 0 | else |
13198 | | /* Store the expected address of the padding frag. */ |
13199 | 0 | padding_fragP->tc_frag_data.padding_address |
13200 | 0 | = (fragP->fr_address + padding_size |
13201 | 0 | + fragP->tc_frag_data.padding_address); |
13202 | |
|
13203 | 0 | fragP->tc_frag_data.prefix_length = padding_size; |
13204 | | |
13205 | | /* Update the length for the current interation. */ |
13206 | 0 | left_size = padding_size; |
13207 | 0 | for (next_fragP = fragP; |
13208 | 0 | next_fragP != padding_fragP; |
13209 | 0 | next_fragP = next_fragP->fr_next) |
13210 | 0 | if (next_fragP->fr_type == rs_machine_dependent |
13211 | 0 | && (TYPE_FROM_RELAX_STATE (next_fragP->fr_subtype) |
13212 | 0 | == BRANCH_PREFIX)) |
13213 | 0 | { |
13214 | 0 | if (left_size) |
13215 | 0 | { |
13216 | 0 | int max = next_fragP->tc_frag_data.max_bytes; |
13217 | 0 | if (max) |
13218 | 0 | { |
13219 | 0 | int size; |
13220 | 0 | if (max > left_size) |
13221 | 0 | size = left_size; |
13222 | 0 | else |
13223 | 0 | size = max; |
13224 | 0 | left_size -= size; |
13225 | 0 | next_fragP->tc_frag_data.length = size; |
13226 | 0 | } |
13227 | 0 | } |
13228 | 0 | else |
13229 | 0 | next_fragP->tc_frag_data.length = 0; |
13230 | 0 | } |
13231 | |
|
13232 | 0 | return (fragP->tc_frag_data.length |
13233 | 0 | - fragP->tc_frag_data.last_length); |
13234 | 0 | } |
13235 | 0 | return relax_frag (segment, fragP, stretch); |
13236 | 0 | } |
13237 | | |
13238 | | /* md_estimate_size_before_relax() |
13239 | | |
13240 | | Called just before relax() for rs_machine_dependent frags. The x86 |
13241 | | assembler uses these frags to handle variable size jump |
13242 | | instructions. |
13243 | | |
13244 | | Any symbol that is now undefined will not become defined. |
13245 | | Return the correct fr_subtype in the frag. |
13246 | | Return the initial "guess for variable size of frag" to caller. |
13247 | | The guess is actually the growth beyond the fixed part. Whatever |
13248 | | we do to grow the fixed or variable part contributes to our |
13249 | | returned value. */ |
13250 | | |
13251 | | int |
13252 | | md_estimate_size_before_relax (fragS *fragP, segT segment) |
13253 | 0 | { |
13254 | 0 | if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PADDING |
13255 | 0 | || TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PREFIX |
13256 | 0 | || TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == FUSED_JCC_PADDING) |
13257 | 0 | { |
13258 | 0 | i386_classify_machine_dependent_frag (fragP); |
13259 | 0 | return fragP->tc_frag_data.length; |
13260 | 0 | } |
13261 | | |
13262 | | /* We've already got fragP->fr_subtype right; all we have to do is |
13263 | | check for un-relaxable symbols. On an ELF system, we can't relax |
13264 | | an externally visible symbol, because it may be overridden by a |
13265 | | shared library. */ |
13266 | 0 | if (S_GET_SEGMENT (fragP->fr_symbol) != segment |
13267 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
13268 | 0 | || (IS_ELF |
13269 | 0 | && !elf_symbol_resolved_in_segment_p (fragP->fr_symbol, |
13270 | 0 | fragP->fr_var)) |
13271 | 0 | #endif |
13272 | | #if defined (OBJ_COFF) && defined (TE_PE) |
13273 | | || (OUTPUT_FLAVOR == bfd_target_coff_flavour |
13274 | | && S_IS_WEAK (fragP->fr_symbol)) |
13275 | | #endif |
13276 | 0 | ) |
13277 | 0 | { |
13278 | | /* Symbol is undefined in this segment, or we need to keep a |
13279 | | reloc so that weak symbols can be overridden. */ |
13280 | 0 | int size = (fragP->fr_subtype & CODE16) ? 2 : 4; |
13281 | 0 | enum bfd_reloc_code_real reloc_type; |
13282 | 0 | unsigned char *opcode; |
13283 | 0 | int old_fr_fix; |
13284 | 0 | fixS *fixP = NULL; |
13285 | |
|
13286 | 0 | if (fragP->fr_var != NO_RELOC) |
13287 | 0 | reloc_type = (enum bfd_reloc_code_real) fragP->fr_var; |
13288 | 0 | else if (size == 2) |
13289 | 0 | reloc_type = BFD_RELOC_16_PCREL; |
13290 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
13291 | 0 | else if (fragP->tc_frag_data.code64 && fragP->fr_offset == 0 |
13292 | 0 | && need_plt32_p (fragP->fr_symbol)) |
13293 | 0 | reloc_type = BFD_RELOC_X86_64_PLT32; |
13294 | 0 | #endif |
13295 | 0 | else |
13296 | 0 | reloc_type = BFD_RELOC_32_PCREL; |
13297 | |
|
13298 | 0 | old_fr_fix = fragP->fr_fix; |
13299 | 0 | opcode = (unsigned char *) fragP->fr_opcode; |
13300 | |
|
13301 | 0 | switch (TYPE_FROM_RELAX_STATE (fragP->fr_subtype)) |
13302 | 0 | { |
13303 | 0 | case UNCOND_JUMP: |
13304 | | /* Make jmp (0xeb) a (d)word displacement jump. */ |
13305 | 0 | opcode[0] = 0xe9; |
13306 | 0 | fragP->fr_fix += size; |
13307 | 0 | fixP = fix_new (fragP, old_fr_fix, size, |
13308 | 0 | fragP->fr_symbol, |
13309 | 0 | fragP->fr_offset, 1, |
13310 | 0 | reloc_type); |
13311 | 0 | break; |
13312 | | |
13313 | 0 | case COND_JUMP86: |
13314 | 0 | if (size == 2 |
13315 | 0 | && (!no_cond_jump_promotion || fragP->fr_var != NO_RELOC)) |
13316 | 0 | { |
13317 | | /* Negate the condition, and branch past an |
13318 | | unconditional jump. */ |
13319 | 0 | opcode[0] ^= 1; |
13320 | 0 | opcode[1] = 3; |
13321 | | /* Insert an unconditional jump. */ |
13322 | 0 | opcode[2] = 0xe9; |
13323 | | /* We added two extra opcode bytes, and have a two byte |
13324 | | offset. */ |
13325 | 0 | fragP->fr_fix += 2 + 2; |
13326 | 0 | fix_new (fragP, old_fr_fix + 2, 2, |
13327 | 0 | fragP->fr_symbol, |
13328 | 0 | fragP->fr_offset, 1, |
13329 | 0 | reloc_type); |
13330 | 0 | break; |
13331 | 0 | } |
13332 | | /* Fall through. */ |
13333 | | |
13334 | 0 | case COND_JUMP: |
13335 | 0 | if (no_cond_jump_promotion && fragP->fr_var == NO_RELOC) |
13336 | 0 | { |
13337 | 0 | fragP->fr_fix += 1; |
13338 | 0 | fixP = fix_new (fragP, old_fr_fix, 1, |
13339 | 0 | fragP->fr_symbol, |
13340 | 0 | fragP->fr_offset, 1, |
13341 | 0 | BFD_RELOC_8_PCREL); |
13342 | 0 | fixP->fx_signed = 1; |
13343 | 0 | break; |
13344 | 0 | } |
13345 | | |
13346 | | /* This changes the byte-displacement jump 0x7N |
13347 | | to the (d)word-displacement jump 0x0f,0x8N. */ |
13348 | 0 | opcode[1] = opcode[0] + 0x10; |
13349 | 0 | opcode[0] = TWO_BYTE_OPCODE_ESCAPE; |
13350 | | /* We've added an opcode byte. */ |
13351 | 0 | fragP->fr_fix += 1 + size; |
13352 | 0 | fixP = fix_new (fragP, old_fr_fix + 1, size, |
13353 | 0 | fragP->fr_symbol, |
13354 | 0 | fragP->fr_offset, 1, |
13355 | 0 | reloc_type); |
13356 | 0 | break; |
13357 | | |
13358 | 0 | default: |
13359 | 0 | BAD_CASE (fragP->fr_subtype); |
13360 | 0 | break; |
13361 | 0 | } |
13362 | | |
13363 | | /* All jumps handled here are signed, but don't unconditionally use a |
13364 | | signed limit check for 32 and 16 bit jumps as we want to allow wrap |
13365 | | around at 4G (outside of 64-bit mode) and 64k. */ |
13366 | 0 | if (size == 4 && flag_code == CODE_64BIT) |
13367 | 0 | fixP->fx_signed = 1; |
13368 | |
|
13369 | 0 | frag_wane (fragP); |
13370 | 0 | return fragP->fr_fix - old_fr_fix; |
13371 | 0 | } |
13372 | | |
13373 | | /* Guess size depending on current relax state. Initially the relax |
13374 | | state will correspond to a short jump and we return 1, because |
13375 | | the variable part of the frag (the branch offset) is one byte |
13376 | | long. However, we can relax a section more than once and in that |
13377 | | case we must either set fr_subtype back to the unrelaxed state, |
13378 | | or return the value for the appropriate branch. */ |
13379 | 0 | return md_relax_table[fragP->fr_subtype].rlx_length; |
13380 | 0 | } |
13381 | | |
13382 | | /* Called after relax() is finished. |
13383 | | |
13384 | | In: Address of frag. |
13385 | | fr_type == rs_machine_dependent. |
13386 | | fr_subtype is what the address relaxed to. |
13387 | | |
13388 | | Out: Any fixSs and constants are set up. |
13389 | | Caller will turn frag into a ".space 0". */ |
13390 | | |
13391 | | void |
13392 | | md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED, |
13393 | | fragS *fragP) |
13394 | 0 | { |
13395 | 0 | unsigned char *opcode; |
13396 | 0 | unsigned char *where_to_put_displacement = NULL; |
13397 | 0 | offsetT target_address; |
13398 | 0 | offsetT opcode_address; |
13399 | 0 | unsigned int extension = 0; |
13400 | 0 | offsetT displacement_from_opcode_start; |
13401 | |
|
13402 | 0 | if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PADDING |
13403 | 0 | || TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == FUSED_JCC_PADDING |
13404 | 0 | || TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PREFIX) |
13405 | 0 | { |
13406 | | /* Generate nop padding. */ |
13407 | 0 | unsigned int size = fragP->tc_frag_data.length; |
13408 | 0 | if (size) |
13409 | 0 | { |
13410 | 0 | if (size > fragP->tc_frag_data.max_bytes) |
13411 | 0 | abort (); |
13412 | | |
13413 | 0 | if (flag_debug) |
13414 | 0 | { |
13415 | 0 | const char *msg; |
13416 | 0 | const char *branch = "branch"; |
13417 | 0 | const char *prefix = ""; |
13418 | 0 | fragS *padding_fragP; |
13419 | 0 | if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) |
13420 | 0 | == BRANCH_PREFIX) |
13421 | 0 | { |
13422 | 0 | padding_fragP = fragP->tc_frag_data.u.padding_fragP; |
13423 | 0 | switch (fragP->tc_frag_data.default_prefix) |
13424 | 0 | { |
13425 | 0 | default: |
13426 | 0 | abort (); |
13427 | 0 | break; |
13428 | 0 | case CS_PREFIX_OPCODE: |
13429 | 0 | prefix = " cs"; |
13430 | 0 | break; |
13431 | 0 | case DS_PREFIX_OPCODE: |
13432 | 0 | prefix = " ds"; |
13433 | 0 | break; |
13434 | 0 | case ES_PREFIX_OPCODE: |
13435 | 0 | prefix = " es"; |
13436 | 0 | break; |
13437 | 0 | case FS_PREFIX_OPCODE: |
13438 | 0 | prefix = " fs"; |
13439 | 0 | break; |
13440 | 0 | case GS_PREFIX_OPCODE: |
13441 | 0 | prefix = " gs"; |
13442 | 0 | break; |
13443 | 0 | case SS_PREFIX_OPCODE: |
13444 | 0 | prefix = " ss"; |
13445 | 0 | break; |
13446 | 0 | } |
13447 | 0 | if (padding_fragP) |
13448 | 0 | msg = _("%s:%u: add %d%s at 0x%llx to align " |
13449 | 0 | "%s within %d-byte boundary\n"); |
13450 | 0 | else |
13451 | 0 | msg = _("%s:%u: add additional %d%s at 0x%llx to " |
13452 | 0 | "align %s within %d-byte boundary\n"); |
13453 | 0 | } |
13454 | 0 | else |
13455 | 0 | { |
13456 | 0 | padding_fragP = fragP; |
13457 | 0 | msg = _("%s:%u: add %d%s-byte nop at 0x%llx to align " |
13458 | 0 | "%s within %d-byte boundary\n"); |
13459 | 0 | } |
13460 | | |
13461 | 0 | if (padding_fragP) |
13462 | 0 | switch (padding_fragP->tc_frag_data.branch_type) |
13463 | 0 | { |
13464 | 0 | case align_branch_jcc: |
13465 | 0 | branch = "jcc"; |
13466 | 0 | break; |
13467 | 0 | case align_branch_fused: |
13468 | 0 | branch = "fused jcc"; |
13469 | 0 | break; |
13470 | 0 | case align_branch_jmp: |
13471 | 0 | branch = "jmp"; |
13472 | 0 | break; |
13473 | 0 | case align_branch_call: |
13474 | 0 | branch = "call"; |
13475 | 0 | break; |
13476 | 0 | case align_branch_indirect: |
13477 | 0 | branch = "indiret branch"; |
13478 | 0 | break; |
13479 | 0 | case align_branch_ret: |
13480 | 0 | branch = "ret"; |
13481 | 0 | break; |
13482 | 0 | default: |
13483 | 0 | break; |
13484 | 0 | } |
13485 | | |
13486 | 0 | fprintf (stdout, msg, |
13487 | 0 | fragP->fr_file, fragP->fr_line, size, prefix, |
13488 | 0 | (long long) fragP->fr_address, branch, |
13489 | 0 | 1 << align_branch_power); |
13490 | 0 | } |
13491 | 0 | if (TYPE_FROM_RELAX_STATE (fragP->fr_subtype) == BRANCH_PREFIX) |
13492 | 0 | memset (fragP->fr_opcode, |
13493 | 0 | fragP->tc_frag_data.default_prefix, size); |
13494 | 0 | else |
13495 | 0 | i386_generate_nops (fragP, (char *) fragP->fr_opcode, |
13496 | 0 | size, 0); |
13497 | 0 | fragP->fr_fix += size; |
13498 | 0 | } |
13499 | 0 | return; |
13500 | 0 | } |
13501 | | |
13502 | 0 | opcode = (unsigned char *) fragP->fr_opcode; |
13503 | | |
13504 | | /* Address we want to reach in file space. */ |
13505 | 0 | target_address = S_GET_VALUE (fragP->fr_symbol) + fragP->fr_offset; |
13506 | | |
13507 | | /* Address opcode resides at in file space. */ |
13508 | 0 | opcode_address = fragP->fr_address + fragP->fr_fix; |
13509 | | |
13510 | | /* Displacement from opcode start to fill into instruction. */ |
13511 | 0 | displacement_from_opcode_start = target_address - opcode_address; |
13512 | |
|
13513 | 0 | if ((fragP->fr_subtype & BIG) == 0) |
13514 | 0 | { |
13515 | | /* Don't have to change opcode. */ |
13516 | 0 | extension = 1; /* 1 opcode + 1 displacement */ |
13517 | 0 | where_to_put_displacement = &opcode[1]; |
13518 | 0 | } |
13519 | 0 | else |
13520 | 0 | { |
13521 | 0 | if (no_cond_jump_promotion |
13522 | 0 | && TYPE_FROM_RELAX_STATE (fragP->fr_subtype) != UNCOND_JUMP) |
13523 | 0 | as_warn_where (fragP->fr_file, fragP->fr_line, |
13524 | 0 | _("long jump required")); |
13525 | |
|
13526 | 0 | switch (fragP->fr_subtype) |
13527 | 0 | { |
13528 | 0 | case ENCODE_RELAX_STATE (UNCOND_JUMP, BIG): |
13529 | 0 | extension = 4; /* 1 opcode + 4 displacement */ |
13530 | 0 | opcode[0] = 0xe9; |
13531 | 0 | where_to_put_displacement = &opcode[1]; |
13532 | 0 | break; |
13533 | | |
13534 | 0 | case ENCODE_RELAX_STATE (UNCOND_JUMP, BIG16): |
13535 | 0 | extension = 2; /* 1 opcode + 2 displacement */ |
13536 | 0 | opcode[0] = 0xe9; |
13537 | 0 | where_to_put_displacement = &opcode[1]; |
13538 | 0 | break; |
13539 | | |
13540 | 0 | case ENCODE_RELAX_STATE (COND_JUMP, BIG): |
13541 | 0 | case ENCODE_RELAX_STATE (COND_JUMP86, BIG): |
13542 | 0 | extension = 5; /* 2 opcode + 4 displacement */ |
13543 | 0 | opcode[1] = opcode[0] + 0x10; |
13544 | 0 | opcode[0] = TWO_BYTE_OPCODE_ESCAPE; |
13545 | 0 | where_to_put_displacement = &opcode[2]; |
13546 | 0 | break; |
13547 | | |
13548 | 0 | case ENCODE_RELAX_STATE (COND_JUMP, BIG16): |
13549 | 0 | extension = 3; /* 2 opcode + 2 displacement */ |
13550 | 0 | opcode[1] = opcode[0] + 0x10; |
13551 | 0 | opcode[0] = TWO_BYTE_OPCODE_ESCAPE; |
13552 | 0 | where_to_put_displacement = &opcode[2]; |
13553 | 0 | break; |
13554 | | |
13555 | 0 | case ENCODE_RELAX_STATE (COND_JUMP86, BIG16): |
13556 | 0 | extension = 4; |
13557 | 0 | opcode[0] ^= 1; |
13558 | 0 | opcode[1] = 3; |
13559 | 0 | opcode[2] = 0xe9; |
13560 | 0 | where_to_put_displacement = &opcode[3]; |
13561 | 0 | break; |
13562 | | |
13563 | 0 | default: |
13564 | 0 | BAD_CASE (fragP->fr_subtype); |
13565 | 0 | break; |
13566 | 0 | } |
13567 | 0 | } |
13568 | | |
13569 | | /* If size if less then four we are sure that the operand fits, |
13570 | | but if it's 4, then it could be that the displacement is larger |
13571 | | then -/+ 2GB. */ |
13572 | 0 | if (DISP_SIZE_FROM_RELAX_STATE (fragP->fr_subtype) == 4 |
13573 | 0 | && object_64bit |
13574 | 0 | && ((addressT) (displacement_from_opcode_start - extension |
13575 | 0 | + ((addressT) 1 << 31)) |
13576 | 0 | > (((addressT) 2 << 31) - 1))) |
13577 | 0 | { |
13578 | 0 | as_bad_where (fragP->fr_file, fragP->fr_line, |
13579 | 0 | _("jump target out of range")); |
13580 | | /* Make us emit 0. */ |
13581 | 0 | displacement_from_opcode_start = extension; |
13582 | 0 | } |
13583 | | /* Now put displacement after opcode. */ |
13584 | 0 | md_number_to_chars ((char *) where_to_put_displacement, |
13585 | 0 | (valueT) (displacement_from_opcode_start - extension), |
13586 | 0 | DISP_SIZE_FROM_RELAX_STATE (fragP->fr_subtype)); |
13587 | 0 | fragP->fr_fix += extension; |
13588 | 0 | } |
13589 | | |
13590 | | /* Apply a fixup (fixP) to segment data, once it has been determined |
13591 | | by our caller that we have all the info we need to fix it up. |
13592 | | |
13593 | | Parameter valP is the pointer to the value of the bits. |
13594 | | |
13595 | | On the 386, immediates, displacements, and data pointers are all in |
13596 | | the same (little-endian) format, so we don't need to care about which |
13597 | | we are handling. */ |
13598 | | |
13599 | | void |
13600 | | md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) |
13601 | 0 | { |
13602 | 0 | char *p = fixP->fx_where + fixP->fx_frag->fr_literal; |
13603 | 0 | valueT value = *valP; |
13604 | |
|
13605 | 0 | #if !defined (TE_Mach) |
13606 | 0 | if (fixP->fx_pcrel) |
13607 | 0 | { |
13608 | 0 | switch (fixP->fx_r_type) |
13609 | 0 | { |
13610 | 0 | default: |
13611 | 0 | break; |
13612 | | |
13613 | 0 | case BFD_RELOC_64: |
13614 | 0 | fixP->fx_r_type = BFD_RELOC_64_PCREL; |
13615 | 0 | break; |
13616 | 0 | case BFD_RELOC_32: |
13617 | 0 | case BFD_RELOC_X86_64_32S: |
13618 | 0 | fixP->fx_r_type = BFD_RELOC_32_PCREL; |
13619 | 0 | break; |
13620 | 0 | case BFD_RELOC_16: |
13621 | 0 | fixP->fx_r_type = BFD_RELOC_16_PCREL; |
13622 | 0 | break; |
13623 | 0 | case BFD_RELOC_8: |
13624 | 0 | fixP->fx_r_type = BFD_RELOC_8_PCREL; |
13625 | 0 | break; |
13626 | 0 | } |
13627 | 0 | } |
13628 | | |
13629 | 0 | if (fixP->fx_addsy != NULL |
13630 | 0 | && (fixP->fx_r_type == BFD_RELOC_32_PCREL |
13631 | 0 | || fixP->fx_r_type == BFD_RELOC_64_PCREL |
13632 | 0 | || fixP->fx_r_type == BFD_RELOC_16_PCREL |
13633 | 0 | || fixP->fx_r_type == BFD_RELOC_8_PCREL) |
13634 | 0 | && !use_rela_relocations) |
13635 | 0 | { |
13636 | | /* This is a hack. There should be a better way to handle this. |
13637 | | This covers for the fact that bfd_install_relocation will |
13638 | | subtract the current location (for partial_inplace, PC relative |
13639 | | relocations); see more below. */ |
13640 | 0 | #ifndef OBJ_AOUT |
13641 | 0 | if (IS_ELF |
13642 | | #ifdef TE_PE |
13643 | | || OUTPUT_FLAVOR == bfd_target_coff_flavour |
13644 | | #endif |
13645 | 0 | ) |
13646 | 0 | value += fixP->fx_where + fixP->fx_frag->fr_address; |
13647 | 0 | #endif |
13648 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
13649 | 0 | if (IS_ELF) |
13650 | 0 | { |
13651 | 0 | segT sym_seg = S_GET_SEGMENT (fixP->fx_addsy); |
13652 | |
|
13653 | 0 | if ((sym_seg == seg |
13654 | 0 | || (symbol_section_p (fixP->fx_addsy) |
13655 | 0 | && sym_seg != absolute_section)) |
13656 | 0 | && !generic_force_reloc (fixP)) |
13657 | 0 | { |
13658 | | /* Yes, we add the values in twice. This is because |
13659 | | bfd_install_relocation subtracts them out again. I think |
13660 | | bfd_install_relocation is broken, but I don't dare change |
13661 | | it. FIXME. */ |
13662 | 0 | value += fixP->fx_where + fixP->fx_frag->fr_address; |
13663 | 0 | } |
13664 | 0 | } |
13665 | 0 | #endif |
13666 | | #if defined (OBJ_COFF) && defined (TE_PE) |
13667 | | /* For some reason, the PE format does not store a |
13668 | | section address offset for a PC relative symbol. */ |
13669 | | if (S_GET_SEGMENT (fixP->fx_addsy) != seg |
13670 | | || S_IS_WEAK (fixP->fx_addsy)) |
13671 | | value += md_pcrel_from (fixP); |
13672 | | #endif |
13673 | 0 | } |
13674 | | #if defined (OBJ_COFF) && defined (TE_PE) |
13675 | | if (fixP->fx_addsy != NULL |
13676 | | && S_IS_WEAK (fixP->fx_addsy) |
13677 | | /* PR 16858: Do not modify weak function references. */ |
13678 | | && ! fixP->fx_pcrel) |
13679 | | { |
13680 | | #if !defined (TE_PEP) |
13681 | | /* For x86 PE weak function symbols are neither PC-relative |
13682 | | nor do they set S_IS_FUNCTION. So the only reliable way |
13683 | | to detect them is to check the flags of their containing |
13684 | | section. */ |
13685 | | if (S_GET_SEGMENT (fixP->fx_addsy) != NULL |
13686 | | && S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_CODE) |
13687 | | ; |
13688 | | else |
13689 | | #endif |
13690 | | value -= S_GET_VALUE (fixP->fx_addsy); |
13691 | | } |
13692 | | #endif |
13693 | | |
13694 | | /* Fix a few things - the dynamic linker expects certain values here, |
13695 | | and we must not disappoint it. */ |
13696 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
13697 | 0 | if (IS_ELF && fixP->fx_addsy) |
13698 | 0 | switch (fixP->fx_r_type) |
13699 | 0 | { |
13700 | 0 | case BFD_RELOC_386_PLT32: |
13701 | 0 | case BFD_RELOC_X86_64_PLT32: |
13702 | | /* Make the jump instruction point to the address of the operand. |
13703 | | At runtime we merely add the offset to the actual PLT entry. |
13704 | | NB: Subtract the offset size only for jump instructions. */ |
13705 | 0 | if (fixP->fx_pcrel) |
13706 | 0 | value = -4; |
13707 | 0 | break; |
13708 | | |
13709 | 0 | case BFD_RELOC_386_TLS_GD: |
13710 | 0 | case BFD_RELOC_386_TLS_LDM: |
13711 | 0 | case BFD_RELOC_386_TLS_IE_32: |
13712 | 0 | case BFD_RELOC_386_TLS_IE: |
13713 | 0 | case BFD_RELOC_386_TLS_GOTIE: |
13714 | 0 | case BFD_RELOC_386_TLS_GOTDESC: |
13715 | 0 | case BFD_RELOC_X86_64_TLSGD: |
13716 | 0 | case BFD_RELOC_X86_64_TLSLD: |
13717 | 0 | case BFD_RELOC_X86_64_GOTTPOFF: |
13718 | 0 | case BFD_RELOC_X86_64_GOTPC32_TLSDESC: |
13719 | 0 | value = 0; /* Fully resolved at runtime. No addend. */ |
13720 | | /* Fallthrough */ |
13721 | 0 | case BFD_RELOC_386_TLS_LE: |
13722 | 0 | case BFD_RELOC_386_TLS_LDO_32: |
13723 | 0 | case BFD_RELOC_386_TLS_LE_32: |
13724 | 0 | case BFD_RELOC_X86_64_DTPOFF32: |
13725 | 0 | case BFD_RELOC_X86_64_DTPOFF64: |
13726 | 0 | case BFD_RELOC_X86_64_TPOFF32: |
13727 | 0 | case BFD_RELOC_X86_64_TPOFF64: |
13728 | 0 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
13729 | 0 | break; |
13730 | | |
13731 | 0 | case BFD_RELOC_386_TLS_DESC_CALL: |
13732 | 0 | case BFD_RELOC_X86_64_TLSDESC_CALL: |
13733 | 0 | value = 0; /* Fully resolved at runtime. No addend. */ |
13734 | 0 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
13735 | 0 | fixP->fx_done = 0; |
13736 | 0 | return; |
13737 | | |
13738 | 0 | case BFD_RELOC_VTABLE_INHERIT: |
13739 | 0 | case BFD_RELOC_VTABLE_ENTRY: |
13740 | 0 | fixP->fx_done = 0; |
13741 | 0 | return; |
13742 | | |
13743 | 0 | default: |
13744 | 0 | break; |
13745 | 0 | } |
13746 | 0 | #endif /* defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) */ |
13747 | | |
13748 | | /* If not 64bit, massage value, to account for wraparound when !BFD64. */ |
13749 | 0 | if (!object_64bit) |
13750 | 0 | value = extend_to_32bit_address (value); |
13751 | |
|
13752 | 0 | *valP = value; |
13753 | 0 | #endif /* !defined (TE_Mach) */ |
13754 | | |
13755 | | /* Are we finished with this relocation now? */ |
13756 | 0 | if (fixP->fx_addsy == NULL) |
13757 | 0 | { |
13758 | 0 | fixP->fx_done = 1; |
13759 | 0 | switch (fixP->fx_r_type) |
13760 | 0 | { |
13761 | 0 | case BFD_RELOC_X86_64_32S: |
13762 | 0 | fixP->fx_signed = 1; |
13763 | 0 | break; |
13764 | | |
13765 | 0 | default: |
13766 | 0 | break; |
13767 | 0 | } |
13768 | 0 | } |
13769 | | #if defined (OBJ_COFF) && defined (TE_PE) |
13770 | | else if (fixP->fx_addsy != NULL && S_IS_WEAK (fixP->fx_addsy)) |
13771 | | { |
13772 | | fixP->fx_done = 0; |
13773 | | /* Remember value for tc_gen_reloc. */ |
13774 | | fixP->fx_addnumber = value; |
13775 | | /* Clear out the frag for now. */ |
13776 | | value = 0; |
13777 | | } |
13778 | | #endif |
13779 | 0 | else if (use_rela_relocations) |
13780 | 0 | { |
13781 | 0 | if (!disallow_64bit_reloc || fixP->fx_r_type == NO_RELOC) |
13782 | 0 | fixP->fx_no_overflow = 1; |
13783 | | /* Remember value for tc_gen_reloc. */ |
13784 | 0 | fixP->fx_addnumber = value; |
13785 | 0 | value = 0; |
13786 | 0 | } |
13787 | | |
13788 | 0 | md_number_to_chars (p, value, fixP->fx_size); |
13789 | 0 | } |
13790 | | |
13791 | | const char * |
13792 | | md_atof (int type, char *litP, int *sizeP) |
13793 | 40.7k | { |
13794 | | /* This outputs the LITTLENUMs in REVERSE order; |
13795 | | in accord with the bigendian 386. */ |
13796 | 40.7k | return ieee_md_atof (type, litP, sizeP, false); |
13797 | 40.7k | } |
13798 | | |
13799 | | static char output_invalid_buf[sizeof (unsigned char) * 2 + 6]; |
13800 | | |
13801 | | static char * |
13802 | | output_invalid (int c) |
13803 | 770k | { |
13804 | 770k | if (ISPRINT (c)) |
13805 | 260k | snprintf (output_invalid_buf, sizeof (output_invalid_buf), |
13806 | 260k | "'%c'", c); |
13807 | 509k | else |
13808 | 509k | snprintf (output_invalid_buf, sizeof (output_invalid_buf), |
13809 | 509k | "(0x%x)", (unsigned char) c); |
13810 | 770k | return output_invalid_buf; |
13811 | 770k | } |
13812 | | |
13813 | | /* Verify that @r can be used in the current context. */ |
13814 | | |
13815 | | static bool check_register (const reg_entry *r) |
13816 | 10.1k | { |
13817 | 10.1k | if (allow_pseudo_reg) |
13818 | 2 | return true; |
13819 | | |
13820 | 10.1k | if (operand_type_all_zero (&r->reg_type)) |
13821 | 80 | return false; |
13822 | | |
13823 | 10.0k | if ((r->reg_type.bitfield.dword |
13824 | 10.0k | || (r->reg_type.bitfield.class == SReg && r->reg_num > 3) |
13825 | 10.0k | || r->reg_type.bitfield.class == RegCR |
13826 | 10.0k | || r->reg_type.bitfield.class == RegDR) |
13827 | 10.0k | && !cpu_arch_flags.bitfield.cpui386) |
13828 | 0 | return false; |
13829 | | |
13830 | 10.0k | if (r->reg_type.bitfield.class == RegTR |
13831 | 10.0k | && (flag_code == CODE_64BIT |
13832 | 200 | || !cpu_arch_flags.bitfield.cpui386 |
13833 | 200 | || cpu_arch_isa_flags.bitfield.cpui586 |
13834 | 200 | || cpu_arch_isa_flags.bitfield.cpui686)) |
13835 | 200 | return false; |
13836 | | |
13837 | 9.83k | if (r->reg_type.bitfield.class == RegMMX && !cpu_arch_flags.bitfield.cpummx) |
13838 | 0 | return false; |
13839 | | |
13840 | 9.83k | if (!cpu_arch_flags.bitfield.cpuavx512f) |
13841 | 6.85k | { |
13842 | 6.85k | if (r->reg_type.bitfield.zmmword |
13843 | 6.85k | || r->reg_type.bitfield.class == RegMask) |
13844 | 2 | return false; |
13845 | | |
13846 | 6.85k | if (!cpu_arch_flags.bitfield.cpuavx) |
13847 | 0 | { |
13848 | 0 | if (r->reg_type.bitfield.ymmword) |
13849 | 0 | return false; |
13850 | | |
13851 | 0 | if (!cpu_arch_flags.bitfield.cpusse && r->reg_type.bitfield.xmmword) |
13852 | 0 | return false; |
13853 | 0 | } |
13854 | 6.85k | } |
13855 | | |
13856 | 9.83k | if (r->reg_type.bitfield.tmmword |
13857 | 9.83k | && (!cpu_arch_flags.bitfield.cpuamx_tile |
13858 | 497 | || flag_code != CODE_64BIT)) |
13859 | 457 | return false; |
13860 | | |
13861 | 9.38k | if (r->reg_type.bitfield.class == RegBND && !cpu_arch_flags.bitfield.cpumpx) |
13862 | 0 | return false; |
13863 | | |
13864 | | /* Don't allow fake index register unless allow_index_reg isn't 0. */ |
13865 | 9.38k | if (!allow_index_reg && r->reg_num == RegIZ) |
13866 | 0 | return false; |
13867 | | |
13868 | | /* Upper 16 vector registers are only available with VREX in 64bit |
13869 | | mode, and require EVEX encoding. */ |
13870 | 9.38k | if (r->reg_flags & RegVRex) |
13871 | 1.06k | { |
13872 | 1.06k | if (!cpu_arch_flags.bitfield.cpuavx512f |
13873 | 1.06k | || flag_code != CODE_64BIT) |
13874 | 946 | return false; |
13875 | | |
13876 | 122 | if (i.vec_encoding == vex_encoding_default) |
13877 | 84 | i.vec_encoding = vex_encoding_evex; |
13878 | 38 | else if (i.vec_encoding != vex_encoding_evex) |
13879 | 0 | i.vec_encoding = vex_encoding_error; |
13880 | 122 | } |
13881 | | |
13882 | 8.43k | if (((r->reg_flags & (RegRex64 | RegRex)) || r->reg_type.bitfield.qword) |
13883 | 8.43k | && (!cpu_arch_flags.bitfield.cpulm |
13884 | 5.04k | || r->reg_type.bitfield.class != RegCR |
13885 | 5.04k | || dot_insn ()) |
13886 | 8.43k | && flag_code != CODE_64BIT) |
13887 | 3.87k | return false; |
13888 | | |
13889 | 4.55k | if (r->reg_type.bitfield.class == SReg && r->reg_num == RegFlat |
13890 | 4.55k | && !intel_syntax) |
13891 | 0 | return false; |
13892 | | |
13893 | 4.55k | return true; |
13894 | 4.55k | } |
13895 | | |
13896 | | /* REG_STRING starts *before* REGISTER_PREFIX. */ |
13897 | | |
13898 | | static const reg_entry * |
13899 | | parse_real_register (const char *reg_string, char **end_op) |
13900 | 98.9k | { |
13901 | 98.9k | const char *s = reg_string; |
13902 | 98.9k | char *p; |
13903 | 98.9k | char reg_name_given[MAX_REG_NAME_SIZE + 1]; |
13904 | 98.9k | const reg_entry *r; |
13905 | | |
13906 | | /* Skip possible REGISTER_PREFIX and possible whitespace. */ |
13907 | 98.9k | if (*s == REGISTER_PREFIX) |
13908 | 98.9k | ++s; |
13909 | | |
13910 | 98.9k | if (is_space_char (*s)) |
13911 | 8 | ++s; |
13912 | | |
13913 | 98.9k | p = reg_name_given; |
13914 | 164k | while ((*p++ = register_chars[(unsigned char) *s]) != '\0') |
13915 | 66.1k | { |
13916 | 66.1k | if (p >= reg_name_given + MAX_REG_NAME_SIZE) |
13917 | 645 | return (const reg_entry *) NULL; |
13918 | 65.5k | s++; |
13919 | 65.5k | } |
13920 | | |
13921 | 98.2k | if (is_part_of_name (*s)) |
13922 | 455 | return (const reg_entry *) NULL; |
13923 | | |
13924 | 97.8k | *end_op = (char *) s; |
13925 | | |
13926 | 97.8k | r = (const reg_entry *) str_hash_find (reg_hash, reg_name_given); |
13927 | | |
13928 | | /* Handle floating point regs, allowing spaces in the (i) part. */ |
13929 | 97.8k | if (r == reg_st0) |
13930 | 74 | { |
13931 | 74 | if (!cpu_arch_flags.bitfield.cpu8087 |
13932 | 74 | && !cpu_arch_flags.bitfield.cpu287 |
13933 | 74 | && !cpu_arch_flags.bitfield.cpu387 |
13934 | 74 | && !allow_pseudo_reg) |
13935 | 0 | return (const reg_entry *) NULL; |
13936 | | |
13937 | 74 | if (is_space_char (*s)) |
13938 | 0 | ++s; |
13939 | 74 | if (*s == '(') |
13940 | 0 | { |
13941 | 0 | ++s; |
13942 | 0 | if (is_space_char (*s)) |
13943 | 0 | ++s; |
13944 | 0 | if (*s >= '0' && *s <= '7') |
13945 | 0 | { |
13946 | 0 | int fpr = *s - '0'; |
13947 | 0 | ++s; |
13948 | 0 | if (is_space_char (*s)) |
13949 | 0 | ++s; |
13950 | 0 | if (*s == ')') |
13951 | 0 | { |
13952 | 0 | *end_op = (char *) s + 1; |
13953 | 0 | know (r[fpr].reg_num == fpr); |
13954 | 0 | return r + fpr; |
13955 | 0 | } |
13956 | 0 | } |
13957 | | /* We have "%st(" then garbage. */ |
13958 | 0 | return (const reg_entry *) NULL; |
13959 | 0 | } |
13960 | 74 | } |
13961 | | |
13962 | 97.8k | return r && check_register (r) ? r : NULL; |
13963 | 97.8k | } |
13964 | | |
13965 | | /* REG_STRING starts *before* REGISTER_PREFIX. */ |
13966 | | |
13967 | | static const reg_entry * |
13968 | | parse_register (const char *reg_string, char **end_op) |
13969 | 423k | { |
13970 | 423k | const reg_entry *r; |
13971 | | |
13972 | 423k | if (*reg_string == REGISTER_PREFIX || allow_naked_reg) |
13973 | 893 | r = parse_real_register (reg_string, end_op); |
13974 | 422k | else |
13975 | 422k | r = NULL; |
13976 | 423k | if (!r) |
13977 | 423k | { |
13978 | 423k | char *save = input_line_pointer; |
13979 | 423k | char *buf = xstrdup (reg_string), *name; |
13980 | 423k | symbolS *symbolP; |
13981 | | |
13982 | 423k | input_line_pointer = buf; |
13983 | 423k | get_symbol_name (&name); |
13984 | 423k | symbolP = symbol_find (name); |
13985 | 424k | while (symbolP && symbol_equated_p (symbolP)) |
13986 | 1.09k | { |
13987 | 1.09k | const expressionS *e = symbol_get_value_expression(symbolP); |
13988 | | |
13989 | 1.09k | if (e->X_add_number) |
13990 | 49 | break; |
13991 | 1.04k | symbolP = e->X_add_symbol; |
13992 | 1.04k | } |
13993 | 423k | if (symbolP && S_GET_SEGMENT (symbolP) == reg_section) |
13994 | 52 | { |
13995 | 52 | const expressionS *e = symbol_get_value_expression (symbolP); |
13996 | | |
13997 | 52 | if (e->X_op == O_register) |
13998 | 1 | { |
13999 | 1 | know (e->X_add_number >= 0 |
14000 | 0 | && (valueT) e->X_add_number < i386_regtab_size); |
14001 | 0 | r = i386_regtab + e->X_add_number; |
14002 | 1 | *end_op = (char *) reg_string + (input_line_pointer - buf); |
14003 | 1 | } |
14004 | 52 | if (r && !check_register (r)) |
14005 | 0 | { |
14006 | 0 | as_bad (_("register '%s%s' cannot be used here"), |
14007 | 0 | register_prefix, r->reg_name); |
14008 | 0 | r = &bad_reg; |
14009 | 0 | } |
14010 | 52 | } |
14011 | 0 | input_line_pointer = save; |
14012 | 423k | free (buf); |
14013 | 423k | } |
14014 | 0 | return r; |
14015 | 423k | } |
14016 | | |
14017 | | int |
14018 | | i386_parse_name (char *name, expressionS *e, char *nextcharP) |
14019 | 394k | { |
14020 | 394k | const reg_entry *r = NULL; |
14021 | 394k | char *end = input_line_pointer; |
14022 | | |
14023 | | /* We only know the terminating character here. It being double quote could |
14024 | | be the closing one of a quoted symbol name, or an opening one from a |
14025 | | following string (or another quoted symbol name). Since the latter can't |
14026 | | be valid syntax for anything, bailing in either case is good enough. */ |
14027 | 394k | if (*nextcharP == '"') |
14028 | 33.4k | return 0; |
14029 | | |
14030 | 361k | *end = *nextcharP; |
14031 | 361k | if (*name == REGISTER_PREFIX || allow_naked_reg) |
14032 | 9 | r = parse_real_register (name, &input_line_pointer); |
14033 | 361k | if (r && end <= input_line_pointer) |
14034 | 2 | { |
14035 | 2 | *nextcharP = *input_line_pointer; |
14036 | 2 | *input_line_pointer = 0; |
14037 | 2 | e->X_op = O_register; |
14038 | 2 | e->X_add_number = r - i386_regtab; |
14039 | 2 | return 1; |
14040 | 2 | } |
14041 | 361k | input_line_pointer = end; |
14042 | 361k | *end = 0; |
14043 | 361k | return intel_syntax ? i386_intel_parse_name (name, e) : 0; |
14044 | 361k | } |
14045 | | |
14046 | | void |
14047 | | md_operand (expressionS *e) |
14048 | 318k | { |
14049 | 318k | char *end; |
14050 | 318k | const reg_entry *r; |
14051 | | |
14052 | 318k | switch (*input_line_pointer) |
14053 | 318k | { |
14054 | 98.0k | case REGISTER_PREFIX: |
14055 | 98.0k | r = parse_real_register (input_line_pointer, &end); |
14056 | 98.0k | if (r) |
14057 | 4.25k | { |
14058 | 4.25k | e->X_op = O_register; |
14059 | 4.25k | e->X_add_number = r - i386_regtab; |
14060 | 4.25k | input_line_pointer = end; |
14061 | 4.25k | } |
14062 | 98.0k | break; |
14063 | | |
14064 | 0 | case '[': |
14065 | 0 | gas_assert (intel_syntax); |
14066 | 0 | end = input_line_pointer++; |
14067 | 0 | expression (e); |
14068 | 0 | if (*input_line_pointer == ']') |
14069 | 0 | { |
14070 | 0 | ++input_line_pointer; |
14071 | 0 | e->X_op_symbol = make_expr_symbol (e); |
14072 | 0 | e->X_add_symbol = NULL; |
14073 | 0 | e->X_add_number = 0; |
14074 | 0 | e->X_op = O_index; |
14075 | 0 | } |
14076 | 0 | else |
14077 | 0 | { |
14078 | 0 | e->X_op = O_absent; |
14079 | 0 | input_line_pointer = end; |
14080 | 0 | } |
14081 | 0 | break; |
14082 | 318k | } |
14083 | 318k | } |
14084 | | |
14085 | | #ifdef BFD64 |
14086 | | /* To maintain consistency with !BFD64 builds of gas record, whether any |
14087 | | (binary) operator was involved in an expression. As expressions are |
14088 | | evaluated in only 32 bits when !BFD64, we use this to decide whether to |
14089 | | truncate results. */ |
14090 | | bool i386_record_operator (operatorT op, |
14091 | | const expressionS *left, |
14092 | | const expressionS *right) |
14093 | 1.07M | { |
14094 | 1.07M | if (op == O_absent) |
14095 | 177k | return false; |
14096 | | |
14097 | 895k | if (!left) |
14098 | 439k | { |
14099 | | /* Since the expression parser applies unary operators fine to bignum |
14100 | | operands, we don't need to be concerned of respective operands not |
14101 | | fitting in 32 bits. */ |
14102 | 439k | if (right->X_op == O_constant && right->X_unsigned |
14103 | 439k | && !fits_in_unsigned_long (right->X_add_number)) |
14104 | 3.02k | return false; |
14105 | 439k | } |
14106 | | /* This isn't entirely right: The pattern can also result when constant |
14107 | | expressions are folded (e.g. 0xffffffff + 1). */ |
14108 | 455k | else if ((left->X_op == O_constant && left->X_unsigned |
14109 | 455k | && !fits_in_unsigned_long (left->X_add_number)) |
14110 | 455k | || (right->X_op == O_constant && right->X_unsigned |
14111 | 439k | && !fits_in_unsigned_long (right->X_add_number))) |
14112 | 31.8k | expr_mode = expr_large_value; |
14113 | | |
14114 | 892k | if (expr_mode != expr_large_value) |
14115 | 722k | expr_mode = expr_operator_present; |
14116 | | |
14117 | 892k | return false; |
14118 | 895k | } |
14119 | | #endif |
14120 | | |
14121 | | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
14122 | | const char *md_shortopts = "kVQ:sqnO::"; |
14123 | | #else |
14124 | | const char *md_shortopts = "qnO::"; |
14125 | | #endif |
14126 | | |
14127 | 0 | #define OPTION_32 (OPTION_MD_BASE + 0) |
14128 | 0 | #define OPTION_64 (OPTION_MD_BASE + 1) |
14129 | 0 | #define OPTION_DIVIDE (OPTION_MD_BASE + 2) |
14130 | 0 | #define OPTION_MARCH (OPTION_MD_BASE + 3) |
14131 | 0 | #define OPTION_MTUNE (OPTION_MD_BASE + 4) |
14132 | 0 | #define OPTION_MMNEMONIC (OPTION_MD_BASE + 5) |
14133 | 0 | #define OPTION_MSYNTAX (OPTION_MD_BASE + 6) |
14134 | 0 | #define OPTION_MINDEX_REG (OPTION_MD_BASE + 7) |
14135 | 0 | #define OPTION_MNAKED_REG (OPTION_MD_BASE + 8) |
14136 | 0 | #define OPTION_MRELAX_RELOCATIONS (OPTION_MD_BASE + 9) |
14137 | 0 | #define OPTION_MSSE2AVX (OPTION_MD_BASE + 10) |
14138 | 0 | #define OPTION_MSSE_CHECK (OPTION_MD_BASE + 11) |
14139 | 0 | #define OPTION_MOPERAND_CHECK (OPTION_MD_BASE + 12) |
14140 | 0 | #define OPTION_MAVXSCALAR (OPTION_MD_BASE + 13) |
14141 | 0 | #define OPTION_X32 (OPTION_MD_BASE + 14) |
14142 | 0 | #define OPTION_MADD_BND_PREFIX (OPTION_MD_BASE + 15) |
14143 | 0 | #define OPTION_MEVEXLIG (OPTION_MD_BASE + 16) |
14144 | 0 | #define OPTION_MEVEXWIG (OPTION_MD_BASE + 17) |
14145 | | #define OPTION_MBIG_OBJ (OPTION_MD_BASE + 18) |
14146 | 0 | #define OPTION_MOMIT_LOCK_PREFIX (OPTION_MD_BASE + 19) |
14147 | 0 | #define OPTION_MEVEXRCIG (OPTION_MD_BASE + 20) |
14148 | 0 | #define OPTION_MSHARED (OPTION_MD_BASE + 21) |
14149 | 0 | #define OPTION_MAMD64 (OPTION_MD_BASE + 22) |
14150 | 0 | #define OPTION_MINTEL64 (OPTION_MD_BASE + 23) |
14151 | 0 | #define OPTION_MFENCE_AS_LOCK_ADD (OPTION_MD_BASE + 24) |
14152 | 0 | #define OPTION_X86_USED_NOTE (OPTION_MD_BASE + 25) |
14153 | 0 | #define OPTION_MVEXWIG (OPTION_MD_BASE + 26) |
14154 | 0 | #define OPTION_MALIGN_BRANCH_BOUNDARY (OPTION_MD_BASE + 27) |
14155 | 0 | #define OPTION_MALIGN_BRANCH_PREFIX_SIZE (OPTION_MD_BASE + 28) |
14156 | 0 | #define OPTION_MALIGN_BRANCH (OPTION_MD_BASE + 29) |
14157 | 0 | #define OPTION_MBRANCHES_WITH_32B_BOUNDARIES (OPTION_MD_BASE + 30) |
14158 | 0 | #define OPTION_MLFENCE_AFTER_LOAD (OPTION_MD_BASE + 31) |
14159 | 0 | #define OPTION_MLFENCE_BEFORE_INDIRECT_BRANCH (OPTION_MD_BASE + 32) |
14160 | 0 | #define OPTION_MLFENCE_BEFORE_RET (OPTION_MD_BASE + 33) |
14161 | 0 | #define OPTION_MUSE_UNALIGNED_VECTOR_MOVE (OPTION_MD_BASE + 34) |
14162 | | |
14163 | | struct option md_longopts[] = |
14164 | | { |
14165 | | {"32", no_argument, NULL, OPTION_32}, |
14166 | | #if (defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \ |
14167 | | || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O)) |
14168 | | {"64", no_argument, NULL, OPTION_64}, |
14169 | | #endif |
14170 | | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
14171 | | {"x32", no_argument, NULL, OPTION_X32}, |
14172 | | {"mshared", no_argument, NULL, OPTION_MSHARED}, |
14173 | | {"mx86-used-note", required_argument, NULL, OPTION_X86_USED_NOTE}, |
14174 | | #endif |
14175 | | {"divide", no_argument, NULL, OPTION_DIVIDE}, |
14176 | | {"march", required_argument, NULL, OPTION_MARCH}, |
14177 | | {"mtune", required_argument, NULL, OPTION_MTUNE}, |
14178 | | {"mmnemonic", required_argument, NULL, OPTION_MMNEMONIC}, |
14179 | | {"msyntax", required_argument, NULL, OPTION_MSYNTAX}, |
14180 | | {"mindex-reg", no_argument, NULL, OPTION_MINDEX_REG}, |
14181 | | {"mnaked-reg", no_argument, NULL, OPTION_MNAKED_REG}, |
14182 | | {"msse2avx", no_argument, NULL, OPTION_MSSE2AVX}, |
14183 | | {"muse-unaligned-vector-move", no_argument, NULL, OPTION_MUSE_UNALIGNED_VECTOR_MOVE}, |
14184 | | {"msse-check", required_argument, NULL, OPTION_MSSE_CHECK}, |
14185 | | {"moperand-check", required_argument, NULL, OPTION_MOPERAND_CHECK}, |
14186 | | {"mavxscalar", required_argument, NULL, OPTION_MAVXSCALAR}, |
14187 | | {"mvexwig", required_argument, NULL, OPTION_MVEXWIG}, |
14188 | | {"madd-bnd-prefix", no_argument, NULL, OPTION_MADD_BND_PREFIX}, |
14189 | | {"mevexlig", required_argument, NULL, OPTION_MEVEXLIG}, |
14190 | | {"mevexwig", required_argument, NULL, OPTION_MEVEXWIG}, |
14191 | | # if defined (TE_PE) || defined (TE_PEP) |
14192 | | {"mbig-obj", no_argument, NULL, OPTION_MBIG_OBJ}, |
14193 | | #endif |
14194 | | {"momit-lock-prefix", required_argument, NULL, OPTION_MOMIT_LOCK_PREFIX}, |
14195 | | {"mfence-as-lock-add", required_argument, NULL, OPTION_MFENCE_AS_LOCK_ADD}, |
14196 | | {"mrelax-relocations", required_argument, NULL, OPTION_MRELAX_RELOCATIONS}, |
14197 | | {"mevexrcig", required_argument, NULL, OPTION_MEVEXRCIG}, |
14198 | | {"malign-branch-boundary", required_argument, NULL, OPTION_MALIGN_BRANCH_BOUNDARY}, |
14199 | | {"malign-branch-prefix-size", required_argument, NULL, OPTION_MALIGN_BRANCH_PREFIX_SIZE}, |
14200 | | {"malign-branch", required_argument, NULL, OPTION_MALIGN_BRANCH}, |
14201 | | {"mbranches-within-32B-boundaries", no_argument, NULL, OPTION_MBRANCHES_WITH_32B_BOUNDARIES}, |
14202 | | {"mlfence-after-load", required_argument, NULL, OPTION_MLFENCE_AFTER_LOAD}, |
14203 | | {"mlfence-before-indirect-branch", required_argument, NULL, |
14204 | | OPTION_MLFENCE_BEFORE_INDIRECT_BRANCH}, |
14205 | | {"mlfence-before-ret", required_argument, NULL, OPTION_MLFENCE_BEFORE_RET}, |
14206 | | {"mamd64", no_argument, NULL, OPTION_MAMD64}, |
14207 | | {"mintel64", no_argument, NULL, OPTION_MINTEL64}, |
14208 | | {NULL, no_argument, NULL, 0} |
14209 | | }; |
14210 | | size_t md_longopts_size = sizeof (md_longopts); |
14211 | | |
14212 | | int |
14213 | | md_parse_option (int c, const char *arg) |
14214 | 0 | { |
14215 | 0 | unsigned int j; |
14216 | 0 | char *arch, *next, *saved, *type; |
14217 | |
|
14218 | 0 | switch (c) |
14219 | 0 | { |
14220 | 0 | case 'n': |
14221 | 0 | optimize_align_code = 0; |
14222 | 0 | break; |
14223 | | |
14224 | 0 | case 'q': |
14225 | 0 | quiet_warnings = 1; |
14226 | 0 | break; |
14227 | | |
14228 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
14229 | | /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section |
14230 | | should be emitted or not. FIXME: Not implemented. */ |
14231 | 0 | case 'Q': |
14232 | 0 | if ((arg[0] != 'y' && arg[0] != 'n') || arg[1]) |
14233 | 0 | return 0; |
14234 | 0 | break; |
14235 | | |
14236 | | /* -V: SVR4 argument to print version ID. */ |
14237 | 0 | case 'V': |
14238 | 0 | print_version_id (); |
14239 | 0 | break; |
14240 | | |
14241 | | /* -k: Ignore for FreeBSD compatibility. */ |
14242 | 0 | case 'k': |
14243 | 0 | break; |
14244 | | |
14245 | 0 | case 's': |
14246 | | /* -s: On i386 Solaris, this tells the native assembler to use |
14247 | | .stab instead of .stab.excl. We always use .stab anyhow. */ |
14248 | 0 | break; |
14249 | | |
14250 | 0 | case OPTION_MSHARED: |
14251 | 0 | shared = 1; |
14252 | 0 | break; |
14253 | | |
14254 | 0 | case OPTION_X86_USED_NOTE: |
14255 | 0 | if (strcasecmp (arg, "yes") == 0) |
14256 | 0 | x86_used_note = 1; |
14257 | 0 | else if (strcasecmp (arg, "no") == 0) |
14258 | 0 | x86_used_note = 0; |
14259 | 0 | else |
14260 | 0 | as_fatal (_("invalid -mx86-used-note= option: `%s'"), arg); |
14261 | 0 | break; |
14262 | | |
14263 | | |
14264 | 0 | #endif |
14265 | 0 | #if (defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \ |
14266 | 0 | || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O)) |
14267 | 0 | case OPTION_64: |
14268 | 0 | { |
14269 | 0 | const char **list, **l; |
14270 | |
|
14271 | 0 | list = bfd_target_list (); |
14272 | 0 | for (l = list; *l != NULL; l++) |
14273 | 0 | if (startswith (*l, "elf64-x86-64") |
14274 | 0 | || strcmp (*l, "coff-x86-64") == 0 |
14275 | 0 | || strcmp (*l, "pe-x86-64") == 0 |
14276 | 0 | || strcmp (*l, "pei-x86-64") == 0 |
14277 | 0 | || strcmp (*l, "mach-o-x86-64") == 0) |
14278 | 0 | { |
14279 | 0 | default_arch = "x86_64"; |
14280 | 0 | break; |
14281 | 0 | } |
14282 | 0 | if (*l == NULL) |
14283 | 0 | as_fatal (_("no compiled in support for x86_64")); |
14284 | 0 | free (list); |
14285 | 0 | } |
14286 | 0 | break; |
14287 | 0 | #endif |
14288 | | |
14289 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
14290 | 0 | case OPTION_X32: |
14291 | 0 | if (IS_ELF) |
14292 | 0 | { |
14293 | 0 | const char **list, **l; |
14294 | |
|
14295 | 0 | list = bfd_target_list (); |
14296 | 0 | for (l = list; *l != NULL; l++) |
14297 | 0 | if (startswith (*l, "elf32-x86-64")) |
14298 | 0 | { |
14299 | 0 | default_arch = "x86_64:32"; |
14300 | 0 | break; |
14301 | 0 | } |
14302 | 0 | if (*l == NULL) |
14303 | 0 | as_fatal (_("no compiled in support for 32bit x86_64")); |
14304 | 0 | free (list); |
14305 | 0 | } |
14306 | 0 | else |
14307 | 0 | as_fatal (_("32bit x86_64 is only supported for ELF")); |
14308 | 0 | break; |
14309 | 0 | #endif |
14310 | | |
14311 | 0 | case OPTION_32: |
14312 | 0 | { |
14313 | 0 | const char **list, **l; |
14314 | |
|
14315 | 0 | list = bfd_target_list (); |
14316 | 0 | for (l = list; *l != NULL; l++) |
14317 | 0 | if (strstr (*l, "-i386") |
14318 | 0 | || strstr (*l, "-go32")) |
14319 | 0 | { |
14320 | 0 | default_arch = "i386"; |
14321 | 0 | break; |
14322 | 0 | } |
14323 | 0 | if (*l == NULL) |
14324 | 0 | as_fatal (_("no compiled in support for ix86")); |
14325 | 0 | free (list); |
14326 | 0 | } |
14327 | 0 | break; |
14328 | | |
14329 | 0 | case OPTION_DIVIDE: |
14330 | | #ifdef SVR4_COMMENT_CHARS |
14331 | | { |
14332 | | char *n, *t; |
14333 | | const char *s; |
14334 | | |
14335 | | n = XNEWVEC (char, strlen (i386_comment_chars) + 1); |
14336 | | t = n; |
14337 | | for (s = i386_comment_chars; *s != '\0'; s++) |
14338 | | if (*s != '/') |
14339 | | *t++ = *s; |
14340 | | *t = '\0'; |
14341 | | i386_comment_chars = n; |
14342 | | } |
14343 | | #endif |
14344 | 0 | break; |
14345 | | |
14346 | 0 | case OPTION_MARCH: |
14347 | 0 | saved = xstrdup (arg); |
14348 | 0 | arch = saved; |
14349 | | /* Allow -march=+nosse. */ |
14350 | 0 | if (*arch == '+') |
14351 | 0 | arch++; |
14352 | 0 | do |
14353 | 0 | { |
14354 | 0 | if (*arch == '.') |
14355 | 0 | as_fatal (_("invalid -march= option: `%s'"), arg); |
14356 | 0 | next = strchr (arch, '+'); |
14357 | 0 | if (next) |
14358 | 0 | *next++ = '\0'; |
14359 | 0 | for (j = 0; j < ARRAY_SIZE (cpu_arch); j++) |
14360 | 0 | { |
14361 | 0 | if (arch == saved && cpu_arch[j].type != PROCESSOR_NONE |
14362 | 0 | && strcmp (arch, cpu_arch[j].name) == 0) |
14363 | 0 | { |
14364 | | /* Processor. */ |
14365 | 0 | if (! cpu_arch[j].enable.bitfield.cpui386) |
14366 | 0 | continue; |
14367 | | |
14368 | 0 | cpu_arch_name = cpu_arch[j].name; |
14369 | 0 | free (cpu_sub_arch_name); |
14370 | 0 | cpu_sub_arch_name = NULL; |
14371 | 0 | cpu_arch_flags = cpu_arch[j].enable; |
14372 | 0 | cpu_arch_isa = cpu_arch[j].type; |
14373 | 0 | cpu_arch_isa_flags = cpu_arch[j].enable; |
14374 | 0 | if (!cpu_arch_tune_set) |
14375 | 0 | { |
14376 | 0 | cpu_arch_tune = cpu_arch_isa; |
14377 | 0 | cpu_arch_tune_flags = cpu_arch_isa_flags; |
14378 | 0 | } |
14379 | 0 | break; |
14380 | 0 | } |
14381 | 0 | else if (cpu_arch[j].type == PROCESSOR_NONE |
14382 | 0 | && strcmp (arch, cpu_arch[j].name) == 0 |
14383 | 0 | && !cpu_flags_all_zero (&cpu_arch[j].enable)) |
14384 | 0 | { |
14385 | | /* ISA extension. */ |
14386 | 0 | i386_cpu_flags flags; |
14387 | |
|
14388 | 0 | flags = cpu_flags_or (cpu_arch_flags, |
14389 | 0 | cpu_arch[j].enable); |
14390 | |
|
14391 | 0 | if (!cpu_flags_equal (&flags, &cpu_arch_flags)) |
14392 | 0 | { |
14393 | 0 | extend_cpu_sub_arch_name (arch); |
14394 | 0 | cpu_arch_flags = flags; |
14395 | 0 | cpu_arch_isa_flags = flags; |
14396 | 0 | } |
14397 | 0 | else |
14398 | 0 | cpu_arch_isa_flags |
14399 | 0 | = cpu_flags_or (cpu_arch_isa_flags, |
14400 | 0 | cpu_arch[j].enable); |
14401 | 0 | break; |
14402 | 0 | } |
14403 | 0 | } |
14404 | |
|
14405 | 0 | if (j >= ARRAY_SIZE (cpu_arch) && startswith (arch, "no")) |
14406 | 0 | { |
14407 | | /* Disable an ISA extension. */ |
14408 | 0 | for (j = 0; j < ARRAY_SIZE (cpu_arch); j++) |
14409 | 0 | if (cpu_arch[j].type == PROCESSOR_NONE |
14410 | 0 | && strcmp (arch + 2, cpu_arch[j].name) == 0) |
14411 | 0 | { |
14412 | 0 | i386_cpu_flags flags; |
14413 | |
|
14414 | 0 | flags = cpu_flags_and_not (cpu_arch_flags, |
14415 | 0 | cpu_arch[j].disable); |
14416 | 0 | if (!cpu_flags_equal (&flags, &cpu_arch_flags)) |
14417 | 0 | { |
14418 | 0 | extend_cpu_sub_arch_name (arch); |
14419 | 0 | cpu_arch_flags = flags; |
14420 | 0 | cpu_arch_isa_flags = flags; |
14421 | 0 | } |
14422 | 0 | break; |
14423 | 0 | } |
14424 | 0 | } |
14425 | |
|
14426 | 0 | if (j >= ARRAY_SIZE (cpu_arch)) |
14427 | 0 | as_fatal (_("invalid -march= option: `%s'"), arg); |
14428 | | |
14429 | 0 | arch = next; |
14430 | 0 | } |
14431 | 0 | while (next != NULL); |
14432 | 0 | free (saved); |
14433 | 0 | break; |
14434 | | |
14435 | 0 | case OPTION_MTUNE: |
14436 | 0 | if (*arg == '.') |
14437 | 0 | as_fatal (_("invalid -mtune= option: `%s'"), arg); |
14438 | 0 | for (j = 0; j < ARRAY_SIZE (cpu_arch); j++) |
14439 | 0 | { |
14440 | 0 | if (cpu_arch[j].type != PROCESSOR_NONE |
14441 | 0 | && strcmp (arg, cpu_arch[j].name) == 0) |
14442 | 0 | { |
14443 | 0 | cpu_arch_tune_set = 1; |
14444 | 0 | cpu_arch_tune = cpu_arch [j].type; |
14445 | 0 | cpu_arch_tune_flags = cpu_arch[j].enable; |
14446 | 0 | break; |
14447 | 0 | } |
14448 | 0 | } |
14449 | 0 | if (j >= ARRAY_SIZE (cpu_arch)) |
14450 | 0 | as_fatal (_("invalid -mtune= option: `%s'"), arg); |
14451 | 0 | break; |
14452 | | |
14453 | 0 | case OPTION_MMNEMONIC: |
14454 | 0 | if (strcasecmp (arg, "att") == 0) |
14455 | 0 | intel_mnemonic = 0; |
14456 | 0 | else if (strcasecmp (arg, "intel") == 0) |
14457 | 0 | intel_mnemonic = 1; |
14458 | 0 | else |
14459 | 0 | as_fatal (_("invalid -mmnemonic= option: `%s'"), arg); |
14460 | 0 | break; |
14461 | | |
14462 | 0 | case OPTION_MSYNTAX: |
14463 | 0 | if (strcasecmp (arg, "att") == 0) |
14464 | 0 | intel_syntax = 0; |
14465 | 0 | else if (strcasecmp (arg, "intel") == 0) |
14466 | 0 | intel_syntax = 1; |
14467 | 0 | else |
14468 | 0 | as_fatal (_("invalid -msyntax= option: `%s'"), arg); |
14469 | 0 | break; |
14470 | | |
14471 | 0 | case OPTION_MINDEX_REG: |
14472 | 0 | allow_index_reg = 1; |
14473 | 0 | break; |
14474 | | |
14475 | 0 | case OPTION_MNAKED_REG: |
14476 | 0 | allow_naked_reg = 1; |
14477 | 0 | break; |
14478 | | |
14479 | 0 | case OPTION_MSSE2AVX: |
14480 | 0 | sse2avx = 1; |
14481 | 0 | break; |
14482 | | |
14483 | 0 | case OPTION_MUSE_UNALIGNED_VECTOR_MOVE: |
14484 | 0 | use_unaligned_vector_move = 1; |
14485 | 0 | break; |
14486 | | |
14487 | 0 | case OPTION_MSSE_CHECK: |
14488 | 0 | if (strcasecmp (arg, "error") == 0) |
14489 | 0 | sse_check = check_error; |
14490 | 0 | else if (strcasecmp (arg, "warning") == 0) |
14491 | 0 | sse_check = check_warning; |
14492 | 0 | else if (strcasecmp (arg, "none") == 0) |
14493 | 0 | sse_check = check_none; |
14494 | 0 | else |
14495 | 0 | as_fatal (_("invalid -msse-check= option: `%s'"), arg); |
14496 | 0 | break; |
14497 | | |
14498 | 0 | case OPTION_MOPERAND_CHECK: |
14499 | 0 | if (strcasecmp (arg, "error") == 0) |
14500 | 0 | operand_check = check_error; |
14501 | 0 | else if (strcasecmp (arg, "warning") == 0) |
14502 | 0 | operand_check = check_warning; |
14503 | 0 | else if (strcasecmp (arg, "none") == 0) |
14504 | 0 | operand_check = check_none; |
14505 | 0 | else |
14506 | 0 | as_fatal (_("invalid -moperand-check= option: `%s'"), arg); |
14507 | 0 | break; |
14508 | | |
14509 | 0 | case OPTION_MAVXSCALAR: |
14510 | 0 | if (strcasecmp (arg, "128") == 0) |
14511 | 0 | avxscalar = vex128; |
14512 | 0 | else if (strcasecmp (arg, "256") == 0) |
14513 | 0 | avxscalar = vex256; |
14514 | 0 | else |
14515 | 0 | as_fatal (_("invalid -mavxscalar= option: `%s'"), arg); |
14516 | 0 | break; |
14517 | | |
14518 | 0 | case OPTION_MVEXWIG: |
14519 | 0 | if (strcmp (arg, "0") == 0) |
14520 | 0 | vexwig = vexw0; |
14521 | 0 | else if (strcmp (arg, "1") == 0) |
14522 | 0 | vexwig = vexw1; |
14523 | 0 | else |
14524 | 0 | as_fatal (_("invalid -mvexwig= option: `%s'"), arg); |
14525 | 0 | break; |
14526 | | |
14527 | 0 | case OPTION_MADD_BND_PREFIX: |
14528 | 0 | add_bnd_prefix = 1; |
14529 | 0 | break; |
14530 | | |
14531 | 0 | case OPTION_MEVEXLIG: |
14532 | 0 | if (strcmp (arg, "128") == 0) |
14533 | 0 | evexlig = evexl128; |
14534 | 0 | else if (strcmp (arg, "256") == 0) |
14535 | 0 | evexlig = evexl256; |
14536 | 0 | else if (strcmp (arg, "512") == 0) |
14537 | 0 | evexlig = evexl512; |
14538 | 0 | else |
14539 | 0 | as_fatal (_("invalid -mevexlig= option: `%s'"), arg); |
14540 | 0 | break; |
14541 | | |
14542 | 0 | case OPTION_MEVEXRCIG: |
14543 | 0 | if (strcmp (arg, "rne") == 0) |
14544 | 0 | evexrcig = rne; |
14545 | 0 | else if (strcmp (arg, "rd") == 0) |
14546 | 0 | evexrcig = rd; |
14547 | 0 | else if (strcmp (arg, "ru") == 0) |
14548 | 0 | evexrcig = ru; |
14549 | 0 | else if (strcmp (arg, "rz") == 0) |
14550 | 0 | evexrcig = rz; |
14551 | 0 | else |
14552 | 0 | as_fatal (_("invalid -mevexrcig= option: `%s'"), arg); |
14553 | 0 | break; |
14554 | | |
14555 | 0 | case OPTION_MEVEXWIG: |
14556 | 0 | if (strcmp (arg, "0") == 0) |
14557 | 0 | evexwig = evexw0; |
14558 | 0 | else if (strcmp (arg, "1") == 0) |
14559 | 0 | evexwig = evexw1; |
14560 | 0 | else |
14561 | 0 | as_fatal (_("invalid -mevexwig= option: `%s'"), arg); |
14562 | 0 | break; |
14563 | | |
14564 | | # if defined (TE_PE) || defined (TE_PEP) |
14565 | | case OPTION_MBIG_OBJ: |
14566 | | use_big_obj = 1; |
14567 | | break; |
14568 | | #endif |
14569 | | |
14570 | 0 | case OPTION_MOMIT_LOCK_PREFIX: |
14571 | 0 | if (strcasecmp (arg, "yes") == 0) |
14572 | 0 | omit_lock_prefix = 1; |
14573 | 0 | else if (strcasecmp (arg, "no") == 0) |
14574 | 0 | omit_lock_prefix = 0; |
14575 | 0 | else |
14576 | 0 | as_fatal (_("invalid -momit-lock-prefix= option: `%s'"), arg); |
14577 | 0 | break; |
14578 | | |
14579 | 0 | case OPTION_MFENCE_AS_LOCK_ADD: |
14580 | 0 | if (strcasecmp (arg, "yes") == 0) |
14581 | 0 | avoid_fence = 1; |
14582 | 0 | else if (strcasecmp (arg, "no") == 0) |
14583 | 0 | avoid_fence = 0; |
14584 | 0 | else |
14585 | 0 | as_fatal (_("invalid -mfence-as-lock-add= option: `%s'"), arg); |
14586 | 0 | break; |
14587 | | |
14588 | 0 | case OPTION_MLFENCE_AFTER_LOAD: |
14589 | 0 | if (strcasecmp (arg, "yes") == 0) |
14590 | 0 | lfence_after_load = 1; |
14591 | 0 | else if (strcasecmp (arg, "no") == 0) |
14592 | 0 | lfence_after_load = 0; |
14593 | 0 | else |
14594 | 0 | as_fatal (_("invalid -mlfence-after-load= option: `%s'"), arg); |
14595 | 0 | break; |
14596 | | |
14597 | 0 | case OPTION_MLFENCE_BEFORE_INDIRECT_BRANCH: |
14598 | 0 | if (strcasecmp (arg, "all") == 0) |
14599 | 0 | { |
14600 | 0 | lfence_before_indirect_branch = lfence_branch_all; |
14601 | 0 | if (lfence_before_ret == lfence_before_ret_none) |
14602 | 0 | lfence_before_ret = lfence_before_ret_shl; |
14603 | 0 | } |
14604 | 0 | else if (strcasecmp (arg, "memory") == 0) |
14605 | 0 | lfence_before_indirect_branch = lfence_branch_memory; |
14606 | 0 | else if (strcasecmp (arg, "register") == 0) |
14607 | 0 | lfence_before_indirect_branch = lfence_branch_register; |
14608 | 0 | else if (strcasecmp (arg, "none") == 0) |
14609 | 0 | lfence_before_indirect_branch = lfence_branch_none; |
14610 | 0 | else |
14611 | 0 | as_fatal (_("invalid -mlfence-before-indirect-branch= option: `%s'"), |
14612 | 0 | arg); |
14613 | 0 | break; |
14614 | | |
14615 | 0 | case OPTION_MLFENCE_BEFORE_RET: |
14616 | 0 | if (strcasecmp (arg, "or") == 0) |
14617 | 0 | lfence_before_ret = lfence_before_ret_or; |
14618 | 0 | else if (strcasecmp (arg, "not") == 0) |
14619 | 0 | lfence_before_ret = lfence_before_ret_not; |
14620 | 0 | else if (strcasecmp (arg, "shl") == 0 || strcasecmp (arg, "yes") == 0) |
14621 | 0 | lfence_before_ret = lfence_before_ret_shl; |
14622 | 0 | else if (strcasecmp (arg, "none") == 0) |
14623 | 0 | lfence_before_ret = lfence_before_ret_none; |
14624 | 0 | else |
14625 | 0 | as_fatal (_("invalid -mlfence-before-ret= option: `%s'"), |
14626 | 0 | arg); |
14627 | 0 | break; |
14628 | | |
14629 | 0 | case OPTION_MRELAX_RELOCATIONS: |
14630 | 0 | if (strcasecmp (arg, "yes") == 0) |
14631 | 0 | generate_relax_relocations = 1; |
14632 | 0 | else if (strcasecmp (arg, "no") == 0) |
14633 | 0 | generate_relax_relocations = 0; |
14634 | 0 | else |
14635 | 0 | as_fatal (_("invalid -mrelax-relocations= option: `%s'"), arg); |
14636 | 0 | break; |
14637 | | |
14638 | 0 | case OPTION_MALIGN_BRANCH_BOUNDARY: |
14639 | 0 | { |
14640 | 0 | char *end; |
14641 | 0 | long int align = strtoul (arg, &end, 0); |
14642 | 0 | if (*end == '\0') |
14643 | 0 | { |
14644 | 0 | if (align == 0) |
14645 | 0 | { |
14646 | 0 | align_branch_power = 0; |
14647 | 0 | break; |
14648 | 0 | } |
14649 | 0 | else if (align >= 16) |
14650 | 0 | { |
14651 | 0 | int align_power; |
14652 | 0 | for (align_power = 0; |
14653 | 0 | (align & 1) == 0; |
14654 | 0 | align >>= 1, align_power++) |
14655 | 0 | continue; |
14656 | | /* Limit alignment power to 31. */ |
14657 | 0 | if (align == 1 && align_power < 32) |
14658 | 0 | { |
14659 | 0 | align_branch_power = align_power; |
14660 | 0 | break; |
14661 | 0 | } |
14662 | 0 | } |
14663 | 0 | } |
14664 | 0 | as_fatal (_("invalid -malign-branch-boundary= value: %s"), arg); |
14665 | 0 | } |
14666 | 0 | break; |
14667 | | |
14668 | 0 | case OPTION_MALIGN_BRANCH_PREFIX_SIZE: |
14669 | 0 | { |
14670 | 0 | char *end; |
14671 | 0 | int align = strtoul (arg, &end, 0); |
14672 | | /* Some processors only support 5 prefixes. */ |
14673 | 0 | if (*end == '\0' && align >= 0 && align < 6) |
14674 | 0 | { |
14675 | 0 | align_branch_prefix_size = align; |
14676 | 0 | break; |
14677 | 0 | } |
14678 | 0 | as_fatal (_("invalid -malign-branch-prefix-size= value: %s"), |
14679 | 0 | arg); |
14680 | 0 | } |
14681 | 0 | break; |
14682 | | |
14683 | 0 | case OPTION_MALIGN_BRANCH: |
14684 | 0 | align_branch = 0; |
14685 | 0 | saved = xstrdup (arg); |
14686 | 0 | type = saved; |
14687 | 0 | do |
14688 | 0 | { |
14689 | 0 | next = strchr (type, '+'); |
14690 | 0 | if (next) |
14691 | 0 | *next++ = '\0'; |
14692 | 0 | if (strcasecmp (type, "jcc") == 0) |
14693 | 0 | align_branch |= align_branch_jcc_bit; |
14694 | 0 | else if (strcasecmp (type, "fused") == 0) |
14695 | 0 | align_branch |= align_branch_fused_bit; |
14696 | 0 | else if (strcasecmp (type, "jmp") == 0) |
14697 | 0 | align_branch |= align_branch_jmp_bit; |
14698 | 0 | else if (strcasecmp (type, "call") == 0) |
14699 | 0 | align_branch |= align_branch_call_bit; |
14700 | 0 | else if (strcasecmp (type, "ret") == 0) |
14701 | 0 | align_branch |= align_branch_ret_bit; |
14702 | 0 | else if (strcasecmp (type, "indirect") == 0) |
14703 | 0 | align_branch |= align_branch_indirect_bit; |
14704 | 0 | else |
14705 | 0 | as_fatal (_("invalid -malign-branch= option: `%s'"), arg); |
14706 | 0 | type = next; |
14707 | 0 | } |
14708 | 0 | while (next != NULL); |
14709 | 0 | free (saved); |
14710 | 0 | break; |
14711 | | |
14712 | 0 | case OPTION_MBRANCHES_WITH_32B_BOUNDARIES: |
14713 | 0 | align_branch_power = 5; |
14714 | 0 | align_branch_prefix_size = 5; |
14715 | 0 | align_branch = (align_branch_jcc_bit |
14716 | 0 | | align_branch_fused_bit |
14717 | 0 | | align_branch_jmp_bit); |
14718 | 0 | break; |
14719 | | |
14720 | 0 | case OPTION_MAMD64: |
14721 | 0 | isa64 = amd64; |
14722 | 0 | break; |
14723 | | |
14724 | 0 | case OPTION_MINTEL64: |
14725 | 0 | isa64 = intel64; |
14726 | 0 | break; |
14727 | | |
14728 | 0 | case 'O': |
14729 | 0 | if (arg == NULL) |
14730 | 0 | { |
14731 | 0 | optimize = 1; |
14732 | | /* Turn off -Os. */ |
14733 | 0 | optimize_for_space = 0; |
14734 | 0 | } |
14735 | 0 | else if (*arg == 's') |
14736 | 0 | { |
14737 | 0 | optimize_for_space = 1; |
14738 | | /* Turn on all encoding optimizations. */ |
14739 | 0 | optimize = INT_MAX; |
14740 | 0 | } |
14741 | 0 | else |
14742 | 0 | { |
14743 | 0 | optimize = atoi (arg); |
14744 | | /* Turn off -Os. */ |
14745 | 0 | optimize_for_space = 0; |
14746 | 0 | } |
14747 | 0 | break; |
14748 | | |
14749 | 0 | default: |
14750 | 0 | return 0; |
14751 | 0 | } |
14752 | 0 | return 1; |
14753 | 0 | } |
14754 | | |
14755 | 0 | #define MESSAGE_TEMPLATE \ |
14756 | 0 | " " |
14757 | | |
14758 | | static char * |
14759 | | output_message (FILE *stream, char *p, char *message, char *start, |
14760 | | int *left_p, const char *name, int len) |
14761 | 0 | { |
14762 | 0 | int size = sizeof (MESSAGE_TEMPLATE); |
14763 | 0 | int left = *left_p; |
14764 | | |
14765 | | /* Reserve 2 spaces for ", " or ",\0" */ |
14766 | 0 | left -= len + 2; |
14767 | | |
14768 | | /* Check if there is any room. */ |
14769 | 0 | if (left >= 0) |
14770 | 0 | { |
14771 | 0 | if (p != start) |
14772 | 0 | { |
14773 | 0 | *p++ = ','; |
14774 | 0 | *p++ = ' '; |
14775 | 0 | } |
14776 | 0 | p = mempcpy (p, name, len); |
14777 | 0 | } |
14778 | 0 | else |
14779 | 0 | { |
14780 | | /* Output the current message now and start a new one. */ |
14781 | 0 | *p++ = ','; |
14782 | 0 | *p = '\0'; |
14783 | 0 | fprintf (stream, "%s\n", message); |
14784 | 0 | p = start; |
14785 | 0 | left = size - (start - message) - len - 2; |
14786 | |
|
14787 | 0 | gas_assert (left >= 0); |
14788 | | |
14789 | 0 | p = mempcpy (p, name, len); |
14790 | 0 | } |
14791 | | |
14792 | 0 | *left_p = left; |
14793 | 0 | return p; |
14794 | 0 | } |
14795 | | |
14796 | | static void |
14797 | | show_arch (FILE *stream, int ext, int check) |
14798 | 0 | { |
14799 | 0 | static char message[] = MESSAGE_TEMPLATE; |
14800 | 0 | char *start = message + 27; |
14801 | 0 | char *p; |
14802 | 0 | int size = sizeof (MESSAGE_TEMPLATE); |
14803 | 0 | int left; |
14804 | 0 | const char *name; |
14805 | 0 | int len; |
14806 | 0 | unsigned int j; |
14807 | |
|
14808 | 0 | p = start; |
14809 | 0 | left = size - (start - message); |
14810 | |
|
14811 | 0 | if (!ext && check) |
14812 | 0 | { |
14813 | 0 | p = output_message (stream, p, message, start, &left, |
14814 | 0 | STRING_COMMA_LEN ("default")); |
14815 | 0 | p = output_message (stream, p, message, start, &left, |
14816 | 0 | STRING_COMMA_LEN ("push")); |
14817 | 0 | p = output_message (stream, p, message, start, &left, |
14818 | 0 | STRING_COMMA_LEN ("pop")); |
14819 | 0 | } |
14820 | |
|
14821 | 0 | for (j = 0; j < ARRAY_SIZE (cpu_arch); j++) |
14822 | 0 | { |
14823 | | /* Should it be skipped? */ |
14824 | 0 | if (cpu_arch [j].skip) |
14825 | 0 | continue; |
14826 | | |
14827 | 0 | name = cpu_arch [j].name; |
14828 | 0 | len = cpu_arch [j].len; |
14829 | 0 | if (cpu_arch[j].type == PROCESSOR_NONE) |
14830 | 0 | { |
14831 | | /* It is an extension. Skip if we aren't asked to show it. */ |
14832 | 0 | if (!ext || cpu_flags_all_zero (&cpu_arch[j].enable)) |
14833 | 0 | continue; |
14834 | 0 | } |
14835 | 0 | else if (ext) |
14836 | 0 | { |
14837 | | /* It is an processor. Skip if we show only extension. */ |
14838 | 0 | continue; |
14839 | 0 | } |
14840 | 0 | else if (check && ! cpu_arch[j].enable.bitfield.cpui386) |
14841 | 0 | { |
14842 | | /* It is an impossible processor - skip. */ |
14843 | 0 | continue; |
14844 | 0 | } |
14845 | | |
14846 | 0 | p = output_message (stream, p, message, start, &left, name, len); |
14847 | 0 | } |
14848 | | |
14849 | | /* Display disabled extensions. */ |
14850 | 0 | if (ext) |
14851 | 0 | for (j = 0; j < ARRAY_SIZE (cpu_arch); j++) |
14852 | 0 | { |
14853 | 0 | char *str; |
14854 | |
|
14855 | 0 | if (cpu_arch[j].type != PROCESSOR_NONE |
14856 | 0 | || !cpu_flags_all_zero (&cpu_arch[j].enable)) |
14857 | 0 | continue; |
14858 | 0 | str = xasprintf ("no%s", cpu_arch[j].name); |
14859 | 0 | p = output_message (stream, p, message, start, &left, str, |
14860 | 0 | strlen (str)); |
14861 | 0 | free (str); |
14862 | 0 | } |
14863 | |
|
14864 | 0 | *p = '\0'; |
14865 | 0 | fprintf (stream, "%s\n", message); |
14866 | 0 | } |
14867 | | |
14868 | | void |
14869 | | md_show_usage (FILE *stream) |
14870 | 0 | { |
14871 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
14872 | 0 | fprintf (stream, _("\ |
14873 | 0 | -Qy, -Qn ignored\n\ |
14874 | 0 | -V print assembler version number\n\ |
14875 | 0 | -k ignored\n")); |
14876 | 0 | #endif |
14877 | 0 | fprintf (stream, _("\ |
14878 | 0 | -n do not optimize code alignment\n\ |
14879 | 0 | -O{012s} attempt some code optimizations\n\ |
14880 | 0 | -q quieten some warnings\n")); |
14881 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
14882 | 0 | fprintf (stream, _("\ |
14883 | 0 | -s ignored\n")); |
14884 | 0 | #endif |
14885 | 0 | #ifdef BFD64 |
14886 | 0 | # if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
14887 | 0 | fprintf (stream, _("\ |
14888 | 0 | --32/--64/--x32 generate 32bit/64bit/x32 object\n")); |
14889 | | # elif defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O) |
14890 | | fprintf (stream, _("\ |
14891 | | --32/--64 generate 32bit/64bit object\n")); |
14892 | | # endif |
14893 | 0 | #endif |
14894 | | #ifdef SVR4_COMMENT_CHARS |
14895 | | fprintf (stream, _("\ |
14896 | | --divide do not treat `/' as a comment character\n")); |
14897 | | #else |
14898 | 0 | fprintf (stream, _("\ |
14899 | 0 | --divide ignored\n")); |
14900 | 0 | #endif |
14901 | 0 | fprintf (stream, _("\ |
14902 | 0 | -march=CPU[,+EXTENSION...]\n\ |
14903 | 0 | generate code for CPU and EXTENSION, CPU is one of:\n")); |
14904 | 0 | show_arch (stream, 0, 1); |
14905 | 0 | fprintf (stream, _("\ |
14906 | 0 | EXTENSION is combination of (possibly \"no\"-prefixed):\n")); |
14907 | 0 | show_arch (stream, 1, 0); |
14908 | 0 | fprintf (stream, _("\ |
14909 | 0 | -mtune=CPU optimize for CPU, CPU is one of:\n")); |
14910 | 0 | show_arch (stream, 0, 0); |
14911 | 0 | fprintf (stream, _("\ |
14912 | 0 | -msse2avx encode SSE instructions with VEX prefix\n")); |
14913 | 0 | fprintf (stream, _("\ |
14914 | 0 | -muse-unaligned-vector-move\n\ |
14915 | 0 | encode aligned vector move as unaligned vector move\n")); |
14916 | 0 | fprintf (stream, _("\ |
14917 | 0 | -msse-check=[none|error|warning] (default: warning)\n\ |
14918 | 0 | check SSE instructions\n")); |
14919 | 0 | fprintf (stream, _("\ |
14920 | 0 | -moperand-check=[none|error|warning] (default: warning)\n\ |
14921 | 0 | check operand combinations for validity\n")); |
14922 | 0 | fprintf (stream, _("\ |
14923 | 0 | -mavxscalar=[128|256] (default: 128)\n\ |
14924 | 0 | encode scalar AVX instructions with specific vector\n\ |
14925 | 0 | length\n")); |
14926 | 0 | fprintf (stream, _("\ |
14927 | 0 | -mvexwig=[0|1] (default: 0)\n\ |
14928 | 0 | encode VEX instructions with specific VEX.W value\n\ |
14929 | 0 | for VEX.W bit ignored instructions\n")); |
14930 | 0 | fprintf (stream, _("\ |
14931 | 0 | -mevexlig=[128|256|512] (default: 128)\n\ |
14932 | 0 | encode scalar EVEX instructions with specific vector\n\ |
14933 | 0 | length\n")); |
14934 | 0 | fprintf (stream, _("\ |
14935 | 0 | -mevexwig=[0|1] (default: 0)\n\ |
14936 | 0 | encode EVEX instructions with specific EVEX.W value\n\ |
14937 | 0 | for EVEX.W bit ignored instructions\n")); |
14938 | 0 | fprintf (stream, _("\ |
14939 | 0 | -mevexrcig=[rne|rd|ru|rz] (default: rne)\n\ |
14940 | 0 | encode EVEX instructions with specific EVEX.RC value\n\ |
14941 | 0 | for SAE-only ignored instructions\n")); |
14942 | 0 | fprintf (stream, _("\ |
14943 | 0 | -mmnemonic=[att|intel] ")); |
14944 | 0 | if (SYSV386_COMPAT) |
14945 | 0 | fprintf (stream, _("(default: att)\n")); |
14946 | 0 | else |
14947 | 0 | fprintf (stream, _("(default: intel)\n")); |
14948 | 0 | fprintf (stream, _("\ |
14949 | 0 | use AT&T/Intel mnemonic\n")); |
14950 | 0 | fprintf (stream, _("\ |
14951 | 0 | -msyntax=[att|intel] (default: att)\n\ |
14952 | 0 | use AT&T/Intel syntax\n")); |
14953 | 0 | fprintf (stream, _("\ |
14954 | 0 | -mindex-reg support pseudo index registers\n")); |
14955 | 0 | fprintf (stream, _("\ |
14956 | 0 | -mnaked-reg don't require `%%' prefix for registers\n")); |
14957 | 0 | fprintf (stream, _("\ |
14958 | 0 | -madd-bnd-prefix add BND prefix for all valid branches\n")); |
14959 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
14960 | 0 | fprintf (stream, _("\ |
14961 | 0 | -mshared disable branch optimization for shared code\n")); |
14962 | 0 | fprintf (stream, _("\ |
14963 | 0 | -mx86-used-note=[no|yes] ")); |
14964 | 0 | if (DEFAULT_X86_USED_NOTE) |
14965 | 0 | fprintf (stream, _("(default: yes)\n")); |
14966 | 0 | else |
14967 | 0 | fprintf (stream, _("(default: no)\n")); |
14968 | 0 | fprintf (stream, _("\ |
14969 | 0 | generate x86 used ISA and feature properties\n")); |
14970 | 0 | #endif |
14971 | | #if defined (TE_PE) || defined (TE_PEP) |
14972 | | fprintf (stream, _("\ |
14973 | | -mbig-obj generate big object files\n")); |
14974 | | #endif |
14975 | 0 | fprintf (stream, _("\ |
14976 | 0 | -momit-lock-prefix=[no|yes] (default: no)\n\ |
14977 | 0 | strip all lock prefixes\n")); |
14978 | 0 | fprintf (stream, _("\ |
14979 | 0 | -mfence-as-lock-add=[no|yes] (default: no)\n\ |
14980 | 0 | encode lfence, mfence and sfence as\n\ |
14981 | 0 | lock addl $0x0, (%%{re}sp)\n")); |
14982 | 0 | fprintf (stream, _("\ |
14983 | 0 | -mrelax-relocations=[no|yes] ")); |
14984 | 0 | if (DEFAULT_GENERATE_X86_RELAX_RELOCATIONS) |
14985 | 0 | fprintf (stream, _("(default: yes)\n")); |
14986 | 0 | else |
14987 | 0 | fprintf (stream, _("(default: no)\n")); |
14988 | 0 | fprintf (stream, _("\ |
14989 | 0 | generate relax relocations\n")); |
14990 | 0 | fprintf (stream, _("\ |
14991 | 0 | -malign-branch-boundary=NUM (default: 0)\n\ |
14992 | 0 | align branches within NUM byte boundary\n")); |
14993 | 0 | fprintf (stream, _("\ |
14994 | 0 | -malign-branch=TYPE[+TYPE...] (default: jcc+fused+jmp)\n\ |
14995 | 0 | TYPE is combination of jcc, fused, jmp, call, ret,\n\ |
14996 | 0 | indirect\n\ |
14997 | 0 | specify types of branches to align\n")); |
14998 | 0 | fprintf (stream, _("\ |
14999 | 0 | -malign-branch-prefix-size=NUM (default: 5)\n\ |
15000 | 0 | align branches with NUM prefixes per instruction\n")); |
15001 | 0 | fprintf (stream, _("\ |
15002 | 0 | -mbranches-within-32B-boundaries\n\ |
15003 | 0 | align branches within 32 byte boundary\n")); |
15004 | 0 | fprintf (stream, _("\ |
15005 | 0 | -mlfence-after-load=[no|yes] (default: no)\n\ |
15006 | 0 | generate lfence after load\n")); |
15007 | 0 | fprintf (stream, _("\ |
15008 | 0 | -mlfence-before-indirect-branch=[none|all|register|memory] (default: none)\n\ |
15009 | 0 | generate lfence before indirect near branch\n")); |
15010 | 0 | fprintf (stream, _("\ |
15011 | 0 | -mlfence-before-ret=[none|or|not|shl|yes] (default: none)\n\ |
15012 | 0 | generate lfence before ret\n")); |
15013 | 0 | fprintf (stream, _("\ |
15014 | 0 | -mamd64 accept only AMD64 ISA [default]\n")); |
15015 | 0 | fprintf (stream, _("\ |
15016 | 0 | -mintel64 accept only Intel64 ISA\n")); |
15017 | 0 | } |
15018 | | |
15019 | | #if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \ |
15020 | | || defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) \ |
15021 | | || defined (TE_PE) || defined (TE_PEP) || defined (OBJ_MACH_O)) |
15022 | | |
15023 | | /* Pick the target format to use. */ |
15024 | | |
15025 | | const char * |
15026 | | i386_target_format (void) |
15027 | 1.15k | { |
15028 | 1.15k | if (startswith (default_arch, "x86_64")) |
15029 | 1.15k | { |
15030 | 1.15k | update_code_flag (CODE_64BIT, 1); |
15031 | 1.15k | if (default_arch[6] == '\0') |
15032 | 1.15k | x86_elf_abi = X86_64_ABI; |
15033 | 0 | else |
15034 | 0 | x86_elf_abi = X86_64_X32_ABI; |
15035 | 1.15k | } |
15036 | 0 | else if (!strcmp (default_arch, "i386")) |
15037 | 0 | update_code_flag (CODE_32BIT, 1); |
15038 | 0 | else if (!strcmp (default_arch, "iamcu")) |
15039 | 0 | { |
15040 | 0 | update_code_flag (CODE_32BIT, 1); |
15041 | 0 | if (cpu_arch_isa == PROCESSOR_UNKNOWN) |
15042 | 0 | { |
15043 | 0 | static const i386_cpu_flags iamcu_flags = CPU_IAMCU_FLAGS; |
15044 | 0 | cpu_arch_name = "iamcu"; |
15045 | 0 | free (cpu_sub_arch_name); |
15046 | 0 | cpu_sub_arch_name = NULL; |
15047 | 0 | cpu_arch_flags = iamcu_flags; |
15048 | 0 | cpu_arch_isa = PROCESSOR_IAMCU; |
15049 | 0 | cpu_arch_isa_flags = iamcu_flags; |
15050 | 0 | if (!cpu_arch_tune_set) |
15051 | 0 | { |
15052 | 0 | cpu_arch_tune = cpu_arch_isa; |
15053 | 0 | cpu_arch_tune_flags = cpu_arch_isa_flags; |
15054 | 0 | } |
15055 | 0 | } |
15056 | 0 | else if (cpu_arch_isa != PROCESSOR_IAMCU) |
15057 | 0 | as_fatal (_("Intel MCU doesn't support `%s' architecture"), |
15058 | 0 | cpu_arch_name); |
15059 | 0 | } |
15060 | 0 | else |
15061 | 0 | as_fatal (_("unknown architecture")); |
15062 | | |
15063 | 1.15k | if (cpu_flags_all_zero (&cpu_arch_isa_flags)) |
15064 | 1 | cpu_arch_isa_flags = cpu_arch[flag_code == CODE_64BIT].enable; |
15065 | 1.15k | if (cpu_flags_all_zero (&cpu_arch_tune_flags)) |
15066 | 1 | cpu_arch_tune_flags = cpu_arch[flag_code == CODE_64BIT].enable; |
15067 | | |
15068 | 1.15k | switch (OUTPUT_FLAVOR) |
15069 | 1.15k | { |
15070 | | #if defined (OBJ_MAYBE_AOUT) || defined (OBJ_AOUT) |
15071 | | case bfd_target_aout_flavour: |
15072 | | return AOUT_TARGET_FORMAT; |
15073 | | #endif |
15074 | | #if defined (OBJ_MAYBE_COFF) || defined (OBJ_COFF) |
15075 | | # if defined (TE_PE) || defined (TE_PEP) |
15076 | | case bfd_target_coff_flavour: |
15077 | | if (flag_code == CODE_64BIT) |
15078 | | { |
15079 | | object_64bit = 1; |
15080 | | return use_big_obj ? "pe-bigobj-x86-64" : "pe-x86-64"; |
15081 | | } |
15082 | | return use_big_obj ? "pe-bigobj-i386" : "pe-i386"; |
15083 | | # elif defined (TE_GO32) |
15084 | | case bfd_target_coff_flavour: |
15085 | | return "coff-go32"; |
15086 | | # else |
15087 | | case bfd_target_coff_flavour: |
15088 | | return "coff-i386"; |
15089 | | # endif |
15090 | | #endif |
15091 | 0 | #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF) |
15092 | 1.15k | case bfd_target_elf_flavour: |
15093 | 1.15k | { |
15094 | 1.15k | const char *format; |
15095 | | |
15096 | 1.15k | switch (x86_elf_abi) |
15097 | 1.15k | { |
15098 | 0 | default: |
15099 | 0 | format = ELF_TARGET_FORMAT; |
15100 | 0 | #ifndef TE_SOLARIS |
15101 | 0 | tls_get_addr = "___tls_get_addr"; |
15102 | 0 | #endif |
15103 | 0 | break; |
15104 | 1.15k | case X86_64_ABI: |
15105 | 1.15k | use_rela_relocations = 1; |
15106 | 1.15k | object_64bit = 1; |
15107 | 1.15k | #ifndef TE_SOLARIS |
15108 | 1.15k | tls_get_addr = "__tls_get_addr"; |
15109 | 1.15k | #endif |
15110 | 1.15k | format = ELF_TARGET_FORMAT64; |
15111 | 1.15k | break; |
15112 | 0 | case X86_64_X32_ABI: |
15113 | 0 | use_rela_relocations = 1; |
15114 | 0 | object_64bit = 1; |
15115 | 0 | #ifndef TE_SOLARIS |
15116 | 0 | tls_get_addr = "__tls_get_addr"; |
15117 | 0 | #endif |
15118 | 0 | disallow_64bit_reloc = 1; |
15119 | 0 | format = ELF_TARGET_FORMAT32; |
15120 | 0 | break; |
15121 | 1.15k | } |
15122 | 1.15k | if (cpu_arch_isa == PROCESSOR_IAMCU) |
15123 | 0 | { |
15124 | 0 | if (x86_elf_abi != I386_ABI) |
15125 | 0 | as_fatal (_("Intel MCU is 32bit only")); |
15126 | 0 | return ELF_TARGET_IAMCU_FORMAT; |
15127 | 0 | } |
15128 | 1.15k | else |
15129 | 1.15k | return format; |
15130 | 1.15k | } |
15131 | 0 | #endif |
15132 | | #if defined (OBJ_MACH_O) |
15133 | | case bfd_target_mach_o_flavour: |
15134 | | if (flag_code == CODE_64BIT) |
15135 | | { |
15136 | | use_rela_relocations = 1; |
15137 | | object_64bit = 1; |
15138 | | return "mach-o-x86-64"; |
15139 | | } |
15140 | | else |
15141 | | return "mach-o-i386"; |
15142 | | #endif |
15143 | 0 | default: |
15144 | 0 | abort (); |
15145 | 0 | return NULL; |
15146 | 1.15k | } |
15147 | 1.15k | } |
15148 | | |
15149 | | #endif /* OBJ_MAYBE_ more than one */ |
15150 | | |
15151 | | symbolS * |
15152 | | md_undefined_symbol (char *name) |
15153 | 81.5k | { |
15154 | 81.5k | if (name[0] == GLOBAL_OFFSET_TABLE_NAME[0] |
15155 | 81.5k | && name[1] == GLOBAL_OFFSET_TABLE_NAME[1] |
15156 | 81.5k | && name[2] == GLOBAL_OFFSET_TABLE_NAME[2] |
15157 | 81.5k | && strcmp (name, GLOBAL_OFFSET_TABLE_NAME) == 0) |
15158 | 1 | { |
15159 | 1 | if (!GOT_symbol) |
15160 | 1 | { |
15161 | 1 | if (symbol_find (name)) |
15162 | 0 | as_bad (_("GOT already in symbol table")); |
15163 | 1 | GOT_symbol = symbol_new (name, undefined_section, |
15164 | 1 | &zero_address_frag, 0); |
15165 | 1 | }; |
15166 | 1 | return GOT_symbol; |
15167 | 1 | } |
15168 | 81.5k | return 0; |
15169 | 81.5k | } |
15170 | | |
15171 | | /* Round up a section size to the appropriate boundary. */ |
15172 | | |
15173 | | valueT |
15174 | | md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size) |
15175 | 0 | { |
15176 | | #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)) |
15177 | | if (OUTPUT_FLAVOR == bfd_target_aout_flavour) |
15178 | | { |
15179 | | /* For a.out, force the section size to be aligned. If we don't do |
15180 | | this, BFD will align it for us, but it will not write out the |
15181 | | final bytes of the section. This may be a bug in BFD, but it is |
15182 | | easier to fix it here since that is how the other a.out targets |
15183 | | work. */ |
15184 | | int align; |
15185 | | |
15186 | | align = bfd_section_alignment (segment); |
15187 | | size = ((size + (1 << align) - 1) & (-((valueT) 1 << align))); |
15188 | | } |
15189 | | #endif |
15190 | |
|
15191 | 0 | return size; |
15192 | 0 | } |
15193 | | |
15194 | | /* On the i386, PC-relative offsets are relative to the start of the |
15195 | | next instruction. That is, the address of the offset, plus its |
15196 | | size, since the offset is always the last part of the insn. */ |
15197 | | |
15198 | | long |
15199 | | md_pcrel_from (fixS *fixP) |
15200 | 0 | { |
15201 | 0 | return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address; |
15202 | 0 | } |
15203 | | |
15204 | | #ifndef I386COFF |
15205 | | |
15206 | | static void |
15207 | | s_bss (int ignore ATTRIBUTE_UNUSED) |
15208 | 1.86k | { |
15209 | 1.86k | int temp; |
15210 | | |
15211 | 1.86k | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
15212 | 1.86k | if (IS_ELF) |
15213 | 1.86k | obj_elf_section_change_hook (); |
15214 | 1.86k | #endif |
15215 | 1.86k | temp = get_absolute_expression (); |
15216 | 1.86k | subseg_set (bss_section, (subsegT) temp); |
15217 | 1.86k | demand_empty_rest_of_line (); |
15218 | 1.86k | } |
15219 | | |
15220 | | #endif |
15221 | | |
15222 | | /* Remember constant directive. */ |
15223 | | |
15224 | | void |
15225 | | i386_cons_align (int ignore ATTRIBUTE_UNUSED) |
15226 | 77.7k | { |
15227 | 77.7k | if (last_insn.kind != last_insn_directive |
15228 | 77.7k | && (bfd_section_flags (now_seg) & SEC_CODE)) |
15229 | 8.44k | { |
15230 | 8.44k | last_insn.seg = now_seg; |
15231 | 8.44k | last_insn.kind = last_insn_directive; |
15232 | 8.44k | last_insn.name = "constant directive"; |
15233 | 8.44k | last_insn.file = as_where (&last_insn.line); |
15234 | 8.44k | if (lfence_before_ret != lfence_before_ret_none) |
15235 | 0 | { |
15236 | 0 | if (lfence_before_indirect_branch != lfence_branch_none) |
15237 | 0 | as_warn (_("constant directive skips -mlfence-before-ret " |
15238 | 0 | "and -mlfence-before-indirect-branch")); |
15239 | 0 | else |
15240 | 0 | as_warn (_("constant directive skips -mlfence-before-ret")); |
15241 | 0 | } |
15242 | 8.44k | else if (lfence_before_indirect_branch != lfence_branch_none) |
15243 | 0 | as_warn (_("constant directive skips -mlfence-before-indirect-branch")); |
15244 | 8.44k | } |
15245 | 77.7k | } |
15246 | | |
15247 | | int |
15248 | | i386_validate_fix (fixS *fixp) |
15249 | 0 | { |
15250 | 0 | if (fixp->fx_addsy && S_GET_SEGMENT(fixp->fx_addsy) == reg_section) |
15251 | 0 | { |
15252 | 0 | reloc_howto_type *howto; |
15253 | |
|
15254 | 0 | howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); |
15255 | 0 | as_bad_where (fixp->fx_file, fixp->fx_line, |
15256 | 0 | _("invalid %s relocation against register"), |
15257 | 0 | howto ? howto->name : "<unknown>"); |
15258 | 0 | return 0; |
15259 | 0 | } |
15260 | | |
15261 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
15262 | 0 | if (fixp->fx_r_type == BFD_RELOC_SIZE32 |
15263 | 0 | || fixp->fx_r_type == BFD_RELOC_SIZE64) |
15264 | 0 | return IS_ELF && fixp->fx_addsy |
15265 | 0 | && (!S_IS_DEFINED (fixp->fx_addsy) |
15266 | 0 | || S_IS_EXTERNAL (fixp->fx_addsy)); |
15267 | 0 | #endif |
15268 | | |
15269 | 0 | if (fixp->fx_subsy) |
15270 | 0 | { |
15271 | 0 | if (fixp->fx_subsy == GOT_symbol) |
15272 | 0 | { |
15273 | 0 | if (fixp->fx_r_type == BFD_RELOC_32_PCREL) |
15274 | 0 | { |
15275 | 0 | if (!object_64bit) |
15276 | 0 | abort (); |
15277 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
15278 | 0 | if (fixp->fx_tcbit2) |
15279 | 0 | fixp->fx_r_type = (fixp->fx_tcbit |
15280 | 0 | ? BFD_RELOC_X86_64_REX_GOTPCRELX |
15281 | 0 | : BFD_RELOC_X86_64_GOTPCRELX); |
15282 | 0 | else |
15283 | 0 | #endif |
15284 | 0 | fixp->fx_r_type = BFD_RELOC_X86_64_GOTPCREL; |
15285 | 0 | } |
15286 | 0 | else |
15287 | 0 | { |
15288 | 0 | if (!object_64bit) |
15289 | 0 | fixp->fx_r_type = BFD_RELOC_386_GOTOFF; |
15290 | 0 | else |
15291 | 0 | fixp->fx_r_type = BFD_RELOC_X86_64_GOTOFF64; |
15292 | 0 | } |
15293 | 0 | fixp->fx_subsy = 0; |
15294 | 0 | } |
15295 | 0 | } |
15296 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
15297 | 0 | else |
15298 | 0 | { |
15299 | | /* NB: Commit 292676c1 resolved PLT32 reloc aganst local symbol |
15300 | | to section. Since PLT32 relocation must be against symbols, |
15301 | | turn such PLT32 relocation into PC32 relocation. */ |
15302 | 0 | if (fixp->fx_addsy |
15303 | 0 | && (fixp->fx_r_type == BFD_RELOC_386_PLT32 |
15304 | 0 | || fixp->fx_r_type == BFD_RELOC_X86_64_PLT32) |
15305 | 0 | && symbol_section_p (fixp->fx_addsy)) |
15306 | 0 | fixp->fx_r_type = BFD_RELOC_32_PCREL; |
15307 | 0 | if (!object_64bit) |
15308 | 0 | { |
15309 | 0 | if (fixp->fx_r_type == BFD_RELOC_386_GOT32 |
15310 | 0 | && fixp->fx_tcbit2) |
15311 | 0 | fixp->fx_r_type = BFD_RELOC_386_GOT32X; |
15312 | 0 | } |
15313 | 0 | } |
15314 | 0 | #endif |
15315 | | |
15316 | 0 | return 1; |
15317 | 0 | } |
15318 | | |
15319 | | arelent * |
15320 | | tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp) |
15321 | 0 | { |
15322 | 0 | arelent *rel; |
15323 | 0 | bfd_reloc_code_real_type code; |
15324 | |
|
15325 | 0 | switch (fixp->fx_r_type) |
15326 | 0 | { |
15327 | 0 | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
15328 | 0 | symbolS *sym; |
15329 | | |
15330 | 0 | case BFD_RELOC_SIZE32: |
15331 | 0 | case BFD_RELOC_SIZE64: |
15332 | 0 | if (fixp->fx_addsy |
15333 | 0 | && !bfd_is_abs_section (S_GET_SEGMENT (fixp->fx_addsy)) |
15334 | 0 | && (!fixp->fx_subsy |
15335 | 0 | || bfd_is_abs_section (S_GET_SEGMENT (fixp->fx_subsy)))) |
15336 | 0 | sym = fixp->fx_addsy; |
15337 | 0 | else if (fixp->fx_subsy |
15338 | 0 | && !bfd_is_abs_section (S_GET_SEGMENT (fixp->fx_subsy)) |
15339 | 0 | && (!fixp->fx_addsy |
15340 | 0 | || bfd_is_abs_section (S_GET_SEGMENT (fixp->fx_addsy)))) |
15341 | 0 | sym = fixp->fx_subsy; |
15342 | 0 | else |
15343 | 0 | sym = NULL; |
15344 | 0 | if (IS_ELF && sym && S_IS_DEFINED (sym) && !S_IS_EXTERNAL (sym)) |
15345 | 0 | { |
15346 | | /* Resolve size relocation against local symbol to size of |
15347 | | the symbol plus addend. */ |
15348 | 0 | valueT value = S_GET_SIZE (sym); |
15349 | |
|
15350 | 0 | if (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) |
15351 | 0 | value = bfd_section_size (S_GET_SEGMENT (sym)); |
15352 | 0 | if (sym == fixp->fx_subsy) |
15353 | 0 | { |
15354 | 0 | value = -value; |
15355 | 0 | if (fixp->fx_addsy) |
15356 | 0 | value += S_GET_VALUE (fixp->fx_addsy); |
15357 | 0 | } |
15358 | 0 | else if (fixp->fx_subsy) |
15359 | 0 | value -= S_GET_VALUE (fixp->fx_subsy); |
15360 | 0 | value += fixp->fx_offset; |
15361 | 0 | if (fixp->fx_r_type == BFD_RELOC_SIZE32 |
15362 | 0 | && object_64bit |
15363 | 0 | && !fits_in_unsigned_long (value)) |
15364 | 0 | as_bad_where (fixp->fx_file, fixp->fx_line, |
15365 | 0 | _("symbol size computation overflow")); |
15366 | 0 | fixp->fx_addsy = NULL; |
15367 | 0 | fixp->fx_subsy = NULL; |
15368 | 0 | md_apply_fix (fixp, (valueT *) &value, NULL); |
15369 | 0 | return NULL; |
15370 | 0 | } |
15371 | 0 | if (!fixp->fx_addsy || fixp->fx_subsy) |
15372 | 0 | { |
15373 | 0 | as_bad_where (fixp->fx_file, fixp->fx_line, |
15374 | 0 | "unsupported expression involving @size"); |
15375 | 0 | return NULL; |
15376 | 0 | } |
15377 | 0 | #endif |
15378 | | /* Fall through. */ |
15379 | | |
15380 | 0 | case BFD_RELOC_X86_64_PLT32: |
15381 | 0 | case BFD_RELOC_X86_64_GOT32: |
15382 | 0 | case BFD_RELOC_X86_64_GOTPCREL: |
15383 | 0 | case BFD_RELOC_X86_64_GOTPCRELX: |
15384 | 0 | case BFD_RELOC_X86_64_REX_GOTPCRELX: |
15385 | 0 | case BFD_RELOC_386_PLT32: |
15386 | 0 | case BFD_RELOC_386_GOT32: |
15387 | 0 | case BFD_RELOC_386_GOT32X: |
15388 | 0 | case BFD_RELOC_386_GOTOFF: |
15389 | 0 | case BFD_RELOC_386_GOTPC: |
15390 | 0 | case BFD_RELOC_386_TLS_GD: |
15391 | 0 | case BFD_RELOC_386_TLS_LDM: |
15392 | 0 | case BFD_RELOC_386_TLS_LDO_32: |
15393 | 0 | case BFD_RELOC_386_TLS_IE_32: |
15394 | 0 | case BFD_RELOC_386_TLS_IE: |
15395 | 0 | case BFD_RELOC_386_TLS_GOTIE: |
15396 | 0 | case BFD_RELOC_386_TLS_LE_32: |
15397 | 0 | case BFD_RELOC_386_TLS_LE: |
15398 | 0 | case BFD_RELOC_386_TLS_GOTDESC: |
15399 | 0 | case BFD_RELOC_386_TLS_DESC_CALL: |
15400 | 0 | case BFD_RELOC_X86_64_TLSGD: |
15401 | 0 | case BFD_RELOC_X86_64_TLSLD: |
15402 | 0 | case BFD_RELOC_X86_64_DTPOFF32: |
15403 | 0 | case BFD_RELOC_X86_64_DTPOFF64: |
15404 | 0 | case BFD_RELOC_X86_64_GOTTPOFF: |
15405 | 0 | case BFD_RELOC_X86_64_TPOFF32: |
15406 | 0 | case BFD_RELOC_X86_64_TPOFF64: |
15407 | 0 | case BFD_RELOC_X86_64_GOTOFF64: |
15408 | 0 | case BFD_RELOC_X86_64_GOTPC32: |
15409 | 0 | case BFD_RELOC_X86_64_GOT64: |
15410 | 0 | case BFD_RELOC_X86_64_GOTPCREL64: |
15411 | 0 | case BFD_RELOC_X86_64_GOTPC64: |
15412 | 0 | case BFD_RELOC_X86_64_GOTPLT64: |
15413 | 0 | case BFD_RELOC_X86_64_PLTOFF64: |
15414 | 0 | case BFD_RELOC_X86_64_GOTPC32_TLSDESC: |
15415 | 0 | case BFD_RELOC_X86_64_TLSDESC_CALL: |
15416 | 0 | case BFD_RELOC_RVA: |
15417 | 0 | case BFD_RELOC_VTABLE_ENTRY: |
15418 | 0 | case BFD_RELOC_VTABLE_INHERIT: |
15419 | | #ifdef TE_PE |
15420 | | case BFD_RELOC_32_SECREL: |
15421 | | case BFD_RELOC_16_SECIDX: |
15422 | | #endif |
15423 | 0 | code = fixp->fx_r_type; |
15424 | 0 | break; |
15425 | 0 | case BFD_RELOC_X86_64_32S: |
15426 | 0 | if (!fixp->fx_pcrel) |
15427 | 0 | { |
15428 | | /* Don't turn BFD_RELOC_X86_64_32S into BFD_RELOC_32. */ |
15429 | 0 | code = fixp->fx_r_type; |
15430 | 0 | break; |
15431 | 0 | } |
15432 | | /* Fall through. */ |
15433 | 0 | default: |
15434 | 0 | if (fixp->fx_pcrel) |
15435 | 0 | { |
15436 | 0 | switch (fixp->fx_size) |
15437 | 0 | { |
15438 | 0 | default: |
15439 | 0 | as_bad_where (fixp->fx_file, fixp->fx_line, |
15440 | 0 | _("can not do %d byte pc-relative relocation"), |
15441 | 0 | fixp->fx_size); |
15442 | 0 | code = BFD_RELOC_32_PCREL; |
15443 | 0 | break; |
15444 | 0 | case 1: code = BFD_RELOC_8_PCREL; break; |
15445 | 0 | case 2: code = BFD_RELOC_16_PCREL; break; |
15446 | 0 | case 4: code = BFD_RELOC_32_PCREL; break; |
15447 | 0 | #ifdef BFD64 |
15448 | 0 | case 8: code = BFD_RELOC_64_PCREL; break; |
15449 | 0 | #endif |
15450 | 0 | } |
15451 | 0 | } |
15452 | 0 | else |
15453 | 0 | { |
15454 | 0 | switch (fixp->fx_size) |
15455 | 0 | { |
15456 | 0 | default: |
15457 | 0 | as_bad_where (fixp->fx_file, fixp->fx_line, |
15458 | 0 | _("can not do %d byte relocation"), |
15459 | 0 | fixp->fx_size); |
15460 | 0 | code = BFD_RELOC_32; |
15461 | 0 | break; |
15462 | 0 | case 1: code = BFD_RELOC_8; break; |
15463 | 0 | case 2: code = BFD_RELOC_16; break; |
15464 | 0 | case 4: code = BFD_RELOC_32; break; |
15465 | 0 | #ifdef BFD64 |
15466 | 0 | case 8: code = BFD_RELOC_64; break; |
15467 | 0 | #endif |
15468 | 0 | } |
15469 | 0 | } |
15470 | 0 | break; |
15471 | 0 | } |
15472 | | |
15473 | 0 | if ((code == BFD_RELOC_32 |
15474 | 0 | || code == BFD_RELOC_32_PCREL |
15475 | 0 | || code == BFD_RELOC_X86_64_32S) |
15476 | 0 | && GOT_symbol |
15477 | 0 | && fixp->fx_addsy == GOT_symbol) |
15478 | 0 | { |
15479 | 0 | if (!object_64bit) |
15480 | 0 | code = BFD_RELOC_386_GOTPC; |
15481 | 0 | else |
15482 | 0 | code = BFD_RELOC_X86_64_GOTPC32; |
15483 | 0 | } |
15484 | 0 | if ((code == BFD_RELOC_64 || code == BFD_RELOC_64_PCREL) |
15485 | 0 | && GOT_symbol |
15486 | 0 | && fixp->fx_addsy == GOT_symbol) |
15487 | 0 | { |
15488 | 0 | code = BFD_RELOC_X86_64_GOTPC64; |
15489 | 0 | } |
15490 | |
|
15491 | 0 | rel = XNEW (arelent); |
15492 | 0 | rel->sym_ptr_ptr = XNEW (asymbol *); |
15493 | 0 | *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
15494 | |
|
15495 | 0 | rel->address = fixp->fx_frag->fr_address + fixp->fx_where; |
15496 | |
|
15497 | 0 | if (!use_rela_relocations) |
15498 | 0 | { |
15499 | | /* HACK: Since i386 ELF uses Rel instead of Rela, encode the |
15500 | | vtable entry to be used in the relocation's section offset. */ |
15501 | 0 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) |
15502 | 0 | rel->address = fixp->fx_offset; |
15503 | | #if defined (OBJ_COFF) && defined (TE_PE) |
15504 | | else if (fixp->fx_addsy && S_IS_WEAK (fixp->fx_addsy)) |
15505 | | rel->addend = fixp->fx_addnumber - (S_GET_VALUE (fixp->fx_addsy) * 2); |
15506 | | else |
15507 | | #endif |
15508 | 0 | rel->addend = 0; |
15509 | 0 | } |
15510 | | /* Use the rela in 64bit mode. */ |
15511 | 0 | else |
15512 | 0 | { |
15513 | 0 | if (disallow_64bit_reloc) |
15514 | 0 | switch (code) |
15515 | 0 | { |
15516 | 0 | case BFD_RELOC_X86_64_DTPOFF64: |
15517 | 0 | case BFD_RELOC_X86_64_TPOFF64: |
15518 | 0 | case BFD_RELOC_64_PCREL: |
15519 | 0 | case BFD_RELOC_X86_64_GOTOFF64: |
15520 | 0 | case BFD_RELOC_X86_64_GOT64: |
15521 | 0 | case BFD_RELOC_X86_64_GOTPCREL64: |
15522 | 0 | case BFD_RELOC_X86_64_GOTPC64: |
15523 | 0 | case BFD_RELOC_X86_64_GOTPLT64: |
15524 | 0 | case BFD_RELOC_X86_64_PLTOFF64: |
15525 | 0 | as_bad_where (fixp->fx_file, fixp->fx_line, |
15526 | 0 | _("cannot represent relocation type %s in x32 mode"), |
15527 | 0 | bfd_get_reloc_code_name (code)); |
15528 | 0 | break; |
15529 | 0 | default: |
15530 | 0 | break; |
15531 | 0 | } |
15532 | | |
15533 | 0 | if (!fixp->fx_pcrel) |
15534 | 0 | rel->addend = fixp->fx_offset; |
15535 | 0 | else |
15536 | 0 | switch (code) |
15537 | 0 | { |
15538 | 0 | case BFD_RELOC_X86_64_PLT32: |
15539 | 0 | case BFD_RELOC_X86_64_GOT32: |
15540 | 0 | case BFD_RELOC_X86_64_GOTPCREL: |
15541 | 0 | case BFD_RELOC_X86_64_GOTPCRELX: |
15542 | 0 | case BFD_RELOC_X86_64_REX_GOTPCRELX: |
15543 | 0 | case BFD_RELOC_X86_64_TLSGD: |
15544 | 0 | case BFD_RELOC_X86_64_TLSLD: |
15545 | 0 | case BFD_RELOC_X86_64_GOTTPOFF: |
15546 | 0 | case BFD_RELOC_X86_64_GOTPC32_TLSDESC: |
15547 | 0 | case BFD_RELOC_X86_64_TLSDESC_CALL: |
15548 | 0 | rel->addend = fixp->fx_offset - fixp->fx_size; |
15549 | 0 | break; |
15550 | 0 | default: |
15551 | 0 | rel->addend = (section->vma |
15552 | 0 | - fixp->fx_size |
15553 | 0 | + fixp->fx_addnumber |
15554 | 0 | + md_pcrel_from (fixp)); |
15555 | 0 | break; |
15556 | 0 | } |
15557 | 0 | } |
15558 | | |
15559 | 0 | rel->howto = bfd_reloc_type_lookup (stdoutput, code); |
15560 | 0 | if (rel->howto == NULL) |
15561 | 0 | { |
15562 | 0 | as_bad_where (fixp->fx_file, fixp->fx_line, |
15563 | 0 | _("cannot represent relocation type %s"), |
15564 | 0 | bfd_get_reloc_code_name (code)); |
15565 | | /* Set howto to a garbage value so that we can keep going. */ |
15566 | 0 | rel->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32); |
15567 | 0 | gas_assert (rel->howto != NULL); |
15568 | 0 | } |
15569 | | |
15570 | 0 | return rel; |
15571 | 0 | } |
15572 | | |
15573 | | #include "tc-i386-intel.c" |
15574 | | |
15575 | | void |
15576 | | tc_x86_parse_to_dw2regnum (expressionS *exp) |
15577 | 2 | { |
15578 | 2 | int saved_naked_reg; |
15579 | 2 | char saved_register_dot; |
15580 | | |
15581 | 2 | saved_naked_reg = allow_naked_reg; |
15582 | 2 | allow_naked_reg = 1; |
15583 | 2 | saved_register_dot = register_chars['.']; |
15584 | 2 | register_chars['.'] = '.'; |
15585 | 2 | allow_pseudo_reg = 1; |
15586 | 2 | expression_and_evaluate (exp); |
15587 | 2 | allow_pseudo_reg = 0; |
15588 | 2 | register_chars['.'] = saved_register_dot; |
15589 | 2 | allow_naked_reg = saved_naked_reg; |
15590 | | |
15591 | 2 | if (exp->X_op == O_register && exp->X_add_number >= 0) |
15592 | 2 | { |
15593 | 2 | if ((addressT) exp->X_add_number < i386_regtab_size) |
15594 | 2 | { |
15595 | 2 | exp->X_op = O_constant; |
15596 | 2 | exp->X_add_number = i386_regtab[exp->X_add_number] |
15597 | 2 | .dw2_regnum[flag_code >> 1]; |
15598 | 2 | } |
15599 | 0 | else |
15600 | 0 | exp->X_op = O_illegal; |
15601 | 2 | } |
15602 | 2 | } |
15603 | | |
15604 | | void |
15605 | | tc_x86_frame_initial_instructions (void) |
15606 | 103 | { |
15607 | 103 | static unsigned int sp_regno[2]; |
15608 | | |
15609 | 103 | if (!sp_regno[flag_code >> 1]) |
15610 | 2 | { |
15611 | 2 | char *saved_input = input_line_pointer; |
15612 | 2 | char sp[][4] = {"esp", "rsp"}; |
15613 | 2 | expressionS exp; |
15614 | | |
15615 | 2 | input_line_pointer = sp[flag_code >> 1]; |
15616 | 2 | tc_x86_parse_to_dw2regnum (&exp); |
15617 | 2 | gas_assert (exp.X_op == O_constant); |
15618 | 0 | sp_regno[flag_code >> 1] = exp.X_add_number; |
15619 | 2 | input_line_pointer = saved_input; |
15620 | 2 | } |
15621 | | |
15622 | 0 | cfi_add_CFA_def_cfa (sp_regno[flag_code >> 1], -x86_cie_data_alignment); |
15623 | 103 | cfi_add_CFA_offset (x86_dwarf2_return_column, x86_cie_data_alignment); |
15624 | 103 | } |
15625 | | |
15626 | | int |
15627 | | x86_dwarf2_addr_size (void) |
15628 | 10.4k | { |
15629 | 10.4k | #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF) |
15630 | 10.4k | if (x86_elf_abi == X86_64_X32_ABI) |
15631 | 0 | return 4; |
15632 | 10.4k | #endif |
15633 | 10.4k | return bfd_arch_bits_per_address (stdoutput) / 8; |
15634 | 10.4k | } |
15635 | | |
15636 | | int |
15637 | | i386_elf_section_type (const char *str, size_t len) |
15638 | 0 | { |
15639 | 0 | if (flag_code == CODE_64BIT |
15640 | 0 | && len == sizeof ("unwind") - 1 |
15641 | 0 | && startswith (str, "unwind")) |
15642 | 0 | return SHT_X86_64_UNWIND; |
15643 | | |
15644 | 0 | return -1; |
15645 | 0 | } |
15646 | | |
15647 | | #ifdef TE_SOLARIS |
15648 | | void |
15649 | | i386_solaris_fix_up_eh_frame (segT sec) |
15650 | | { |
15651 | | if (flag_code == CODE_64BIT) |
15652 | | elf_section_type (sec) = SHT_X86_64_UNWIND; |
15653 | | } |
15654 | | #endif |
15655 | | |
15656 | | #ifdef TE_PE |
15657 | | void |
15658 | | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
15659 | | { |
15660 | | expressionS exp; |
15661 | | |
15662 | | exp.X_op = O_secrel; |
15663 | | exp.X_add_symbol = symbol; |
15664 | | exp.X_add_number = 0; |
15665 | | emit_expr (&exp, size); |
15666 | | } |
15667 | | #endif |
15668 | | |
15669 | | #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) |
15670 | | /* For ELF on x86-64, add support for SHF_X86_64_LARGE. */ |
15671 | | |
15672 | | bfd_vma |
15673 | | x86_64_section_letter (int letter, const char **ptr_msg) |
15674 | 0 | { |
15675 | 0 | if (flag_code == CODE_64BIT) |
15676 | 0 | { |
15677 | 0 | if (letter == 'l') |
15678 | 0 | return SHF_X86_64_LARGE; |
15679 | | |
15680 | 0 | *ptr_msg = _("bad .section directive: want a,l,w,x,M,S,G,T in string"); |
15681 | 0 | } |
15682 | 0 | else |
15683 | 0 | *ptr_msg = _("bad .section directive: want a,w,x,M,S,G,T in string"); |
15684 | 0 | return -1; |
15685 | 0 | } |
15686 | | |
15687 | | static void |
15688 | | handle_large_common (int small ATTRIBUTE_UNUSED) |
15689 | 0 | { |
15690 | 0 | if (flag_code != CODE_64BIT) |
15691 | 0 | { |
15692 | 0 | s_comm_internal (0, elf_common_parse); |
15693 | 0 | as_warn (_(".largecomm supported only in 64bit mode, producing .comm")); |
15694 | 0 | } |
15695 | 0 | else |
15696 | 0 | { |
15697 | 0 | static segT lbss_section; |
15698 | 0 | asection *saved_com_section_ptr = elf_com_section_ptr; |
15699 | 0 | asection *saved_bss_section = bss_section; |
15700 | |
|
15701 | 0 | if (lbss_section == NULL) |
15702 | 0 | { |
15703 | 0 | flagword applicable; |
15704 | 0 | segT seg = now_seg; |
15705 | 0 | subsegT subseg = now_subseg; |
15706 | | |
15707 | | /* The .lbss section is for local .largecomm symbols. */ |
15708 | 0 | lbss_section = subseg_new (".lbss", 0); |
15709 | 0 | applicable = bfd_applicable_section_flags (stdoutput); |
15710 | 0 | bfd_set_section_flags (lbss_section, applicable & SEC_ALLOC); |
15711 | 0 | seg_info (lbss_section)->bss = 1; |
15712 | |
|
15713 | 0 | subseg_set (seg, subseg); |
15714 | 0 | } |
15715 | |
|
15716 | 0 | elf_com_section_ptr = &_bfd_elf_large_com_section; |
15717 | 0 | bss_section = lbss_section; |
15718 | |
|
15719 | 0 | s_comm_internal (0, elf_common_parse); |
15720 | |
|
15721 | 0 | elf_com_section_ptr = saved_com_section_ptr; |
15722 | 0 | bss_section = saved_bss_section; |
15723 | 0 | } |
15724 | 0 | } |
15725 | | #endif /* OBJ_ELF || OBJ_MAYBE_ELF */ |