display_lang: Add descriptions for post DWARF5 constants
[binutils-gdb.git] / gas / config / tc-i386-intel.c
blob94e3aaffdf4484e2557dab33020d5bcc44931a67
1 /* tc-i386.c -- Assemble Intel syntax code for ix86/x86-64
2 Copyright (C) 2009-2024 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA. */
21 static struct
23 operatorT op_modifier; /* Operand modifier. */
24 int is_mem; /* 1 if operand is memory reference. */
25 int is_indirect; /* 1 if operand is indirect reference. */
26 int has_offset; /* 1 if operand has offset. */
27 unsigned int in_offset; /* >=1 if processing operand of offset. */
28 unsigned int in_bracket; /* >=1 if processing operand in brackets. */
29 unsigned int in_scale; /* >=1 if processing multiplication operand
30 * in brackets. */
31 i386_operand_type reloc_types; /* Value obtained from lex_got(). */
32 const reg_entry *base; /* Base register (if any). */
33 const reg_entry *index; /* Index register (if any). */
34 offsetT scale_factor; /* Accumulated scale factor. */
35 symbolS *seg;
37 intel_state;
39 /* offset X_add_symbol */
40 #define O_offset O_md32
41 /* offset X_add_symbol */
42 #define O_short O_md31
43 /* near ptr X_add_symbol */
44 #define O_near_ptr O_md30
45 /* far ptr X_add_symbol */
46 #define O_far_ptr O_md29
47 /* byte ptr X_add_symbol */
48 #define O_byte_ptr O_md28
49 /* word ptr X_add_symbol */
50 #define O_word_ptr O_md27
51 /* dword ptr X_add_symbol */
52 #define O_dword_ptr O_md26
53 /* qword ptr X_add_symbol */
54 #define O_qword_ptr O_md25
55 /* mmword ptr X_add_symbol */
56 #define O_mmword_ptr O_qword_ptr
57 /* fword ptr X_add_symbol */
58 #define O_fword_ptr O_md24
59 /* tbyte ptr X_add_symbol */
60 #define O_tbyte_ptr O_md23
61 /* oword ptr X_add_symbol */
62 #define O_oword_ptr O_md22
63 /* xmmword ptr X_add_symbol */
64 #define O_xmmword_ptr O_oword_ptr
65 /* ymmword ptr X_add_symbol */
66 #define O_ymmword_ptr O_md21
67 /* zmmword ptr X_add_symbol */
68 #define O_zmmword_ptr O_md20
70 static struct
72 const char *name;
73 operatorT op;
74 unsigned int operands;
76 const i386_operators[] =
78 { "and", O_bit_and, 2 },
79 { "eq", O_eq, 2 },
80 { "ge", O_ge, 2 },
81 { "gt", O_gt, 2 },
82 { "le", O_le, 2 },
83 { "lt", O_lt, 2 },
84 { "mod", O_modulus, 2 },
85 { "ne", O_ne, 2 },
86 { "not", O_bit_not, 1 },
87 { "offset", O_offset, 1 },
88 { "or", O_bit_inclusive_or, 2 },
89 { "shl", O_left_shift, 2 },
90 { "short", O_short, 1 },
91 { "shr", O_right_shift, 2 },
92 { "xor", O_bit_exclusive_or, 2 },
93 { NULL, O_illegal, 0 }
96 static struct
98 const char *name;
99 operatorT op;
100 unsigned short sz[3];
102 const i386_types[] =
104 #define I386_TYPE(t, n) { #t, O_##t##_ptr, { n, n, n } }
105 I386_TYPE(byte, 1),
106 I386_TYPE(word, 2),
107 I386_TYPE(dword, 4),
108 I386_TYPE(fword, 6),
109 I386_TYPE(qword, 8),
110 I386_TYPE(mmword, 8),
111 I386_TYPE(tbyte, 10),
112 I386_TYPE(oword, 16),
113 I386_TYPE(xmmword, 16),
114 I386_TYPE(ymmword, 32),
115 I386_TYPE(zmmword, 64),
116 #undef I386_TYPE
117 { "near", O_near_ptr, { 0xff04, 0xff02, 0xff08 } },
118 { "far", O_far_ptr, { 0xff06, 0xff05, 0xff06 } },
119 { NULL, O_illegal, { 0, 0, 0 } }
122 operatorT i386_operator (const char *name, unsigned int operands, char *pc)
124 unsigned int j;
126 #ifdef SVR4_COMMENT_CHARS
127 if (!name && operands == 2 && *input_line_pointer == '\\')
128 switch (input_line_pointer[1])
130 case '/': input_line_pointer += 2; return O_divide;
131 case '%': input_line_pointer += 2; return O_modulus;
132 case '*': input_line_pointer += 2; return O_multiply;
134 #endif
136 if (!intel_syntax)
137 return O_absent;
139 if (!name)
141 if (operands != 2)
142 return O_illegal;
143 switch (*input_line_pointer)
145 case ':':
146 ++input_line_pointer;
147 return O_full_ptr;
148 case '[':
149 ++input_line_pointer;
150 return O_index;
151 case '@':
152 if (this_operand >= 0 && i.reloc[this_operand] == NO_RELOC)
154 int adjust = 0;
155 char *gotfree_input_line = lex_got (&i.reloc[this_operand],
156 &adjust,
157 &intel_state.reloc_types);
159 if (!gotfree_input_line)
160 break;
161 free (gotfree_input_line);
162 *input_line_pointer++ = '+';
163 memset (input_line_pointer, '0', adjust - 1);
164 input_line_pointer[adjust - 1] = ' ';
165 return O_add;
167 break;
169 return O_illegal;
172 /* See the quotation related comment in i386_parse_name(). */
173 if (*pc == '"')
174 return O_absent;
176 for (j = 0; i386_operators[j].name; ++j)
177 if (strcasecmp (i386_operators[j].name, name) == 0)
179 if (i386_operators[j].operands
180 && i386_operators[j].operands != operands)
181 return O_illegal;
182 return i386_operators[j].op;
185 for (j = 0; i386_types[j].name; ++j)
186 if (strcasecmp (i386_types[j].name, name) == 0)
187 break;
189 if (i386_types[j].name && *pc == ' ')
191 const char *start = ++input_line_pointer;
192 char *pname;
193 char c = get_symbol_name (&pname);
195 if (strcasecmp (pname, "ptr") == 0 && (c != '"' || pname == start))
197 pname[-1] = *pc;
198 *pc = c;
199 if (intel_syntax > 0 || operands != 1)
200 return O_illegal;
201 return i386_types[j].op;
204 if (strcasecmp (pname, "bcst") == 0 && (c != '"' || pname == start))
206 pname[-1] = *pc;
207 *pc = c;
208 if (intel_syntax > 0 || operands != 1
209 || i386_types[j].sz[0] > 8
210 || (i386_types[j].sz[0] & (i386_types[j].sz[0] - 1)))
211 return O_illegal;
212 switch (pp.encoding)
214 case encoding_default:
215 case encoding_egpr:
216 pp.encoding = encoding_evex;
217 break;
218 case encoding_evex:
219 case encoding_evex512:
220 break;
221 default:
222 return O_illegal;
224 if (!i.broadcast.bytes && !i.broadcast.type)
226 i.broadcast.bytes = i386_types[j].sz[0];
227 i.broadcast.operand = this_operand;
229 return i386_types[j].op;
232 (void) restore_line_pointer (c);
233 input_line_pointer = pname - 1;
236 return O_absent;
239 static int i386_intel_parse_name (const char *name,
240 expressionS *e,
241 enum expr_mode mode)
243 unsigned int j;
245 if (! strcmp (name, "$"))
247 current_location (e, mode);
248 return 1;
251 for (j = 0; i386_types[j].name; ++j)
252 if (strcasecmp(i386_types[j].name, name) == 0)
254 e->X_op = O_constant;
255 e->X_add_number = i386_types[j].sz[flag_code];
256 e->X_add_symbol = NULL;
257 e->X_op_symbol = NULL;
258 return 1;
261 return 0;
264 static INLINE int i386_intel_check (const reg_entry *rreg,
265 const reg_entry *base,
266 const reg_entry *iindex)
268 if ((this_operand >= 0
269 && rreg != i.op[this_operand].regs)
270 || base != intel_state.base
271 || iindex != intel_state.index)
273 as_bad (_("invalid use of register"));
274 return 0;
276 return 1;
279 static INLINE void i386_intel_fold (expressionS *e, symbolS *sym)
281 expressionS *exp = symbol_get_value_expression (sym);
282 if (S_GET_SEGMENT (sym) == absolute_section)
284 offsetT val = e->X_add_number;
286 *e = *exp;
287 e->X_add_number += val;
289 else
291 if (exp->X_op == O_symbol
292 && strcmp (S_GET_NAME (exp->X_add_symbol),
293 GLOBAL_OFFSET_TABLE_NAME) == 0)
294 sym = exp->X_add_symbol;
295 e->X_add_symbol = sym;
296 e->X_op_symbol = NULL;
297 e->X_op = O_symbol;
301 static int
302 i386_intel_simplify_register (expressionS *e)
304 int reg_num;
306 if (this_operand < 0 || intel_state.in_offset)
308 as_bad (_("invalid use of register"));
309 return 0;
312 if (e->X_op == O_register)
313 reg_num = e->X_add_number;
314 else
315 reg_num = e->X_md - 1;
317 if (reg_num < 0 || reg_num >= (int) i386_regtab_size)
319 as_bad (_("invalid register number"));
320 return 0;
323 if (!check_register (&i386_regtab[reg_num]))
325 as_bad (_("register '%s%s' cannot be used here"),
326 register_prefix, i386_regtab[reg_num].reg_name);
327 return 0;
330 if (!intel_state.in_bracket)
332 if (i.op[this_operand].regs)
334 as_bad (_("invalid use of register"));
335 return 0;
337 if ((i386_regtab[reg_num].reg_type.bitfield.class == SReg
338 && i386_regtab[reg_num].reg_num == RegFlat)
339 || (dot_insn ()
340 && i386_regtab[reg_num].reg_type.bitfield.class == ClassNone))
342 as_bad (_("invalid use of pseudo-register"));
343 return 0;
345 i.op[this_operand].regs = i386_regtab + reg_num;
347 else if (!intel_state.index
348 && (i386_regtab[reg_num].reg_type.bitfield.xmmword
349 || i386_regtab[reg_num].reg_type.bitfield.ymmword
350 || i386_regtab[reg_num].reg_type.bitfield.zmmword
351 || i386_regtab[reg_num].reg_num == RegIZ))
352 intel_state.index = i386_regtab + reg_num;
353 else if (!intel_state.base && !intel_state.in_scale)
354 intel_state.base = i386_regtab + reg_num;
355 else if (!intel_state.index)
357 const insn_template *t = current_templates.start;
359 if (intel_state.in_scale
360 || i386_regtab[reg_num].reg_type.bitfield.baseindex
361 || dot_insn ()
362 || t->mnem_off == MN_bndmk
363 || t->mnem_off == MN_bndldx
364 || t->mnem_off == MN_bndstx)
365 intel_state.index = i386_regtab + reg_num;
366 else
368 /* Convert base to index and make ESP/RSP the base. */
369 intel_state.index = intel_state.base;
370 intel_state.base = i386_regtab + reg_num;
373 else
375 /* esp is invalid as index */
376 intel_state.index = reg_eax + ESP_REG_NUM;
378 return 2;
381 static int
382 i386_intel_simplify_symbol (symbolS *sym)
384 if (symbol_resolving_p (sym))
385 return 1;
387 symbol_mark_resolving (sym);
388 int ret = i386_intel_simplify (symbol_get_value_expression (sym));
389 if (ret == 2)
391 S_SET_SEGMENT (sym, absolute_section);
392 ret = 1;
394 symbol_clear_resolving (sym);
395 return ret;
398 static int
399 i386_intel_simplify (expressionS *e)
401 const reg_entry *the_reg = (this_operand >= 0
402 ? i.op[this_operand].regs : NULL);
403 const reg_entry *base = intel_state.base;
404 const reg_entry *state_index = intel_state.index;
405 int ret;
407 if (!intel_syntax)
408 return 1;
410 switch (e->X_op)
412 case O_index:
413 if (e->X_add_symbol)
415 if (!i386_intel_simplify_symbol (e->X_add_symbol)
416 || !i386_intel_check(the_reg, intel_state.base,
417 intel_state.index))
418 return 0;
420 if (!intel_state.in_offset)
421 ++intel_state.in_bracket;
422 ret = i386_intel_simplify_symbol (e->X_op_symbol);
423 if (!intel_state.in_offset)
424 --intel_state.in_bracket;
425 if (!ret)
426 return 0;
427 if (e->X_add_symbol)
428 e->X_op = O_add;
429 else
430 i386_intel_fold (e, e->X_op_symbol);
431 break;
433 case O_offset:
434 intel_state.has_offset = 1;
435 ++intel_state.in_offset;
436 ret = i386_intel_simplify_symbol (e->X_add_symbol);
437 --intel_state.in_offset;
438 if (!ret || !i386_intel_check(the_reg, base, state_index))
439 return 0;
440 i386_intel_fold (e, e->X_add_symbol);
441 return ret;
443 case O_byte_ptr:
444 case O_word_ptr:
445 case O_dword_ptr:
446 case O_fword_ptr:
447 case O_qword_ptr: /* O_mmword_ptr */
448 case O_tbyte_ptr:
449 case O_oword_ptr: /* O_xmmword_ptr */
450 case O_ymmword_ptr:
451 case O_zmmword_ptr:
452 case O_near_ptr:
453 case O_far_ptr:
454 if (intel_state.op_modifier == O_absent)
455 intel_state.op_modifier = e->X_op;
456 /* FALLTHROUGH */
457 case O_short:
458 if (symbol_get_value_expression (e->X_add_symbol)->X_op
459 == O_register)
461 as_bad (_("invalid use of register"));
462 return 0;
464 if (!i386_intel_simplify_symbol (e->X_add_symbol))
465 return 0;
466 i386_intel_fold (e, e->X_add_symbol);
467 break;
469 case O_full_ptr:
470 if (symbol_get_value_expression (e->X_op_symbol)->X_op
471 == O_register)
473 as_bad (_("invalid use of register"));
474 return 0;
476 if (!i386_intel_simplify_symbol (e->X_op_symbol)
477 || !i386_intel_check(the_reg, intel_state.base,
478 intel_state.index))
479 return 0;
480 if (!intel_state.in_offset)
482 if (!intel_state.seg)
483 intel_state.seg = e->X_add_symbol;
484 else
486 expressionS exp;
488 exp.X_op = O_full_ptr;
489 exp.X_add_symbol = e->X_add_symbol;
490 exp.X_op_symbol = intel_state.seg;
491 intel_state.seg = make_expr_symbol (&exp);
494 i386_intel_fold (e, e->X_op_symbol);
495 break;
497 case O_multiply:
498 if (this_operand >= 0 && intel_state.in_bracket)
500 expressionS *scale = NULL;
501 int has_index = (intel_state.index != NULL);
503 if (!intel_state.in_scale++)
504 intel_state.scale_factor = 1;
506 ret = i386_intel_simplify_symbol (e->X_add_symbol);
507 if (ret && !has_index && intel_state.index)
508 scale = symbol_get_value_expression (e->X_op_symbol);
510 if (ret)
511 ret = i386_intel_simplify_symbol (e->X_op_symbol);
512 if (ret && !scale && !has_index && intel_state.index)
513 scale = symbol_get_value_expression (e->X_add_symbol);
515 if (ret && scale)
517 resolve_expression (scale);
518 if (scale->X_op != O_constant
519 || intel_state.index->reg_type.bitfield.word)
520 scale->X_add_number = 0;
521 intel_state.scale_factor *= scale->X_add_number;
524 --intel_state.in_scale;
525 if (!ret)
526 return 0;
528 if (!intel_state.in_scale)
529 switch (intel_state.scale_factor)
531 case 1:
532 i.log2_scale_factor = 0;
533 break;
534 case 2:
535 i.log2_scale_factor = 1;
536 break;
537 case 4:
538 i.log2_scale_factor = 2;
539 break;
540 case 8:
541 i.log2_scale_factor = 3;
542 break;
543 default:
544 /* esp is invalid as index */
545 intel_state.index = reg_eax + ESP_REG_NUM;
546 break;
549 break;
551 goto fallthrough;
553 case O_register:
554 ret = i386_intel_simplify_register (e);
555 if (ret == 2)
557 gas_assert (e->X_add_number < (unsigned short) -1);
558 e->X_md = (unsigned short) e->X_add_number + 1;
559 e->X_op = O_constant;
560 e->X_add_number = 0;
562 return ret;
564 case O_constant:
565 if (e->X_md)
566 return i386_intel_simplify_register (e);
568 /* FALLTHROUGH */
569 default:
570 fallthrough:
571 if (e->X_add_symbol
572 && !i386_intel_simplify_symbol (e->X_add_symbol))
573 return 0;
574 if (!the_reg && this_operand >= 0
575 && e->X_op == O_symbol && !e->X_add_number)
576 the_reg = i.op[this_operand].regs;
577 if (e->X_op == O_add || e->X_op == O_subtract)
579 base = intel_state.base;
580 state_index = intel_state.index;
582 if (!i386_intel_check (the_reg, base, state_index)
583 || (e->X_op_symbol
584 && !i386_intel_simplify_symbol (e->X_op_symbol))
585 || !i386_intel_check (the_reg,
586 (e->X_op != O_add
587 ? base : intel_state.base),
588 (e->X_op != O_add
589 ? state_index : intel_state.index)))
590 return 0;
591 break;
594 if (this_operand >= 0
595 && e->X_op == O_symbol
596 && !intel_state.in_offset)
598 segT seg = S_GET_SEGMENT (e->X_add_symbol);
600 if (seg != absolute_section
601 && seg != reg_section
602 && seg != expr_section)
603 intel_state.is_mem |= 2 - !intel_state.in_bracket;
606 return 1;
609 int i386_need_index_operator (void)
611 return intel_syntax < 0;
614 static int
615 i386_intel_operand (char *operand_string, int got_a_float)
617 char *saved_input_line_pointer, *buf;
618 segT exp_seg;
619 expressionS exp, *expP;
620 char suffix = 0;
621 bool rc_sae_modifier = i.rounding.type != rc_none && i.rounding.modifier;
622 int ret;
624 /* Handle vector immediates. */
625 if (RC_SAE_immediate (operand_string))
627 if (i.imm_operands)
629 as_bad (_("`%s': RC/SAE operand must precede immediate operands"),
630 insn_name (current_templates.start));
631 return 0;
634 return 1;
637 /* Initialize state structure. */
638 intel_state.op_modifier = O_absent;
639 intel_state.is_mem = 0;
640 intel_state.is_indirect = 0;
641 intel_state.has_offset = 0;
642 intel_state.base = NULL;
643 intel_state.index = NULL;
644 intel_state.seg = NULL;
645 operand_type_set (&intel_state.reloc_types, ~0);
646 gas_assert (!intel_state.in_offset);
647 gas_assert (!intel_state.in_bracket);
648 gas_assert (!intel_state.in_scale);
650 saved_input_line_pointer = input_line_pointer;
651 input_line_pointer = buf = xstrdup (operand_string);
653 intel_syntax = -1;
654 expr_mode = expr_operator_none;
655 memset (&exp, 0, sizeof(exp));
656 exp_seg = expression (&exp);
657 ret = i386_intel_simplify (&exp);
658 intel_syntax = 1;
660 SKIP_WHITESPACE ();
662 /* Handle vector operations. */
663 if (*input_line_pointer == '{')
665 char *end = check_VecOperations (input_line_pointer);
666 if (end)
667 input_line_pointer = end;
668 else
669 ret = 0;
672 if (!is_end_of_line[(unsigned char) *input_line_pointer])
674 if (ret)
675 as_bad (_("junk `%s' after expression"), input_line_pointer);
676 ret = 0;
678 else if (exp.X_op == O_illegal || exp.X_op == O_absent)
680 if (ret)
681 as_bad (_("invalid expression"));
682 ret = 0;
684 else if (!intel_state.has_offset
685 && input_line_pointer > buf
686 && *(input_line_pointer - 1) == ']')
688 intel_state.is_mem |= 1;
689 intel_state.is_indirect = 1;
692 input_line_pointer = saved_input_line_pointer;
693 free (buf);
695 gas_assert (!intel_state.in_offset);
696 gas_assert (!intel_state.in_bracket);
697 gas_assert (!intel_state.in_scale);
699 if (!ret)
700 return 0;
702 if (intel_state.op_modifier != O_absent
703 && current_templates.start->mnem_off != MN_lea)
705 i.types[this_operand].bitfield.unspecified = 0;
707 switch (intel_state.op_modifier)
709 case O_byte_ptr:
710 i.types[this_operand].bitfield.byte = 1;
711 suffix = BYTE_MNEM_SUFFIX;
712 break;
714 case O_word_ptr:
715 i.types[this_operand].bitfield.word = 1;
716 if (got_a_float == 2) /* "fi..." */
717 suffix = SHORT_MNEM_SUFFIX;
718 else if (current_templates.start->mnem_off != MN_lar
719 && current_templates.start->mnem_off != MN_lsl
720 && current_templates.start->mnem_off != MN_arpl)
721 suffix = WORD_MNEM_SUFFIX;
722 break;
724 case O_dword_ptr:
725 i.types[this_operand].bitfield.dword = 1;
726 if ((insn_name (current_templates.start)[0] == 'l'
727 && insn_name (current_templates.start)[2] == 's'
728 && insn_name (current_templates.start)[3] == 0)
729 || current_templates.start->mnem_off == MN_bound)
730 suffix = WORD_MNEM_SUFFIX;
731 else if (flag_code != CODE_32BIT
732 && (current_templates.start->opcode_modifier.jump == JUMP
733 || current_templates.start->opcode_modifier.jump
734 == JUMP_DWORD))
736 i.far_branch = true;
737 suffix = WORD_MNEM_SUFFIX;
739 else if (got_a_float == 1) /* "f..." */
740 suffix = SHORT_MNEM_SUFFIX;
741 else
742 suffix = LONG_MNEM_SUFFIX;
743 break;
745 case O_fword_ptr:
746 i.types[this_operand].bitfield.fword = 1;
747 if (current_templates.start->mnem_off == MN_les
748 || current_templates.start->mnem_off == MN_lds
749 || current_templates.start->mnem_off == MN_lss
750 || current_templates.start->mnem_off == MN_lfs
751 || current_templates.start->mnem_off == MN_lgs)
752 suffix = LONG_MNEM_SUFFIX;
753 else if (!got_a_float)
755 if (flag_code == CODE_16BIT)
756 add_prefix (DATA_PREFIX_OPCODE);
757 i.far_branch = true;
759 break;
761 case O_qword_ptr: /* O_mmword_ptr */
762 i.types[this_operand].bitfield.qword = 1;
763 if (current_templates.start->mnem_off == MN_bound
764 || got_a_float == 1) /* "f..." */
765 suffix = LONG_MNEM_SUFFIX;
766 else
767 suffix = QWORD_MNEM_SUFFIX;
768 break;
770 case O_tbyte_ptr:
771 i.types[this_operand].bitfield.tbyte = 1;
772 if (got_a_float)
773 break;
774 if (flag_code == CODE_64BIT
775 && (current_templates.start->operand_types[0].bitfield.fword
776 || current_templates.start->operand_types[0].bitfield.tbyte
777 || current_templates.start->opcode_modifier.jump == JUMP_DWORD
778 || current_templates.start->opcode_modifier.jump == JUMP))
779 suffix = QWORD_MNEM_SUFFIX; /* l[fgs]s, [ls][gi]dt, call, jmp */
780 else
781 i.types[this_operand].bitfield.byte = 1; /* cause an error */
782 break;
784 case O_oword_ptr: /* O_xmmword_ptr */
785 i.types[this_operand].bitfield.xmmword = 1;
786 break;
788 case O_ymmword_ptr:
789 if (vector_size < VSZ256)
791 as_bad (_("256-bit operands disabled"));
792 return 0;
794 i.types[this_operand].bitfield.ymmword = 1;
795 break;
797 case O_zmmword_ptr:
798 if (vector_size < VSZ512)
800 as_bad (_("512-bit operands disabled"));
801 return 0;
803 i.types[this_operand].bitfield.zmmword = 1;
804 break;
806 case O_far_ptr:
807 i.far_branch = true;
808 /* FALLTHROUGH */
809 case O_near_ptr:
810 if (current_templates.start->opcode_modifier.jump != JUMP
811 && current_templates.start->opcode_modifier.jump != JUMP_DWORD)
813 /* cause an error */
814 i.types[this_operand].bitfield.byte = 1;
815 i.types[this_operand].bitfield.tbyte = 1;
816 suffix = i.suffix;
818 break;
820 default:
821 BAD_CASE (intel_state.op_modifier);
822 break;
825 /* Now check whether we actually want to infer an AT&T-like suffix.
826 We really only need to do this when operand size determination (incl.
827 REX.W) is going to be derived from it. For this we check whether the
828 given suffix is valid for any of the candidate templates. */
829 if (suffix && suffix != i.suffix
830 && current_templates.start->mnem_off != MN_bound)
832 const insn_template *t;
834 for (t = current_templates.start; t < current_templates.end; ++t)
836 /* Operands haven't been swapped yet. */
837 unsigned int op = t->operands - 1 - this_operand;
839 /* Easy checks to skip templates which won't match anyway. */
840 if (this_operand >= t->operands
841 || t->opcode_modifier.dialect >= ATT_SYNTAX)
842 continue;
844 switch (suffix)
846 case BYTE_MNEM_SUFFIX:
847 if (t->opcode_modifier.no_bsuf)
848 continue;
849 break;
850 case WORD_MNEM_SUFFIX:
851 if (t->opcode_modifier.no_wsuf)
852 continue;
853 break;
854 case LONG_MNEM_SUFFIX:
855 if (t->opcode_modifier.no_lsuf)
856 continue;
857 break;
858 case QWORD_MNEM_SUFFIX:
859 if (t->opcode_modifier.no_qsuf || !q_suffix_allowed (t))
860 continue;
861 break;
862 case SHORT_MNEM_SUFFIX:
863 if (t->opcode_modifier.no_ssuf)
864 continue;
865 break;
866 default:
867 abort ();
870 /* We can skip templates with swappable operands here, as one
871 operand will be a register, which operand size can be
872 determined from. */
873 if (t->opcode_modifier.d)
874 continue;
876 /* In a few cases suffixes are permitted, but we can nevertheless
877 derive that these aren't going to be needed. This is only of
878 interest for insns using ModR/M. */
879 if (!t->opcode_modifier.modrm)
880 break;
882 if (!t->operand_types[op].bitfield.baseindex)
883 continue;
885 switch (t->operand_types[op].bitfield.class)
887 case RegMMX:
888 case RegSIMD:
889 case RegMask:
890 continue;
893 break;
896 if (t == current_templates.end)
897 suffix = 0;
900 if (!i.suffix)
901 i.suffix = suffix;
902 else if (suffix && i.suffix != suffix)
904 as_bad (_("conflicting operand size modifiers"));
905 return 0;
909 /* Operands for jump/call need special consideration. */
910 if (current_templates.start->opcode_modifier.jump == JUMP
911 || current_templates.start->opcode_modifier.jump == JUMP_DWORD
912 || current_templates.start->opcode_modifier.jump == JUMP_INTERSEGMENT
913 || current_templates.start->mnem_off == MN_jmpabs)
915 bool jumpabsolute = false;
917 if (i.op[this_operand].regs
918 || intel_state.base
919 || intel_state.index
920 || intel_state.is_mem > 1)
921 jumpabsolute = true;
922 else
923 switch (intel_state.op_modifier)
925 case O_near_ptr:
926 if (intel_state.seg)
927 jumpabsolute = true;
928 else
929 intel_state.is_mem = 1;
930 break;
931 case O_far_ptr:
932 case O_absent:
933 if (!intel_state.seg)
935 intel_state.is_mem = 1;
936 if (intel_state.op_modifier == O_absent)
938 if (intel_state.is_indirect == 1)
939 jumpabsolute = true;
940 break;
942 as_bad (_("cannot infer the segment part of the operand"));
943 return 0;
945 else if (S_GET_SEGMENT (intel_state.seg) == reg_section)
947 jumpabsolute = true;
948 if (intel_state.op_modifier == O_far_ptr)
949 i.far_branch = true;
951 else
953 i386_operand_type types;
955 if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
957 as_bad (_("at most %d immediate operands are allowed"),
958 MAX_IMMEDIATE_OPERANDS);
959 return 0;
961 expP = &im_expressions[i.imm_operands++];
962 memset (expP, 0, sizeof(*expP));
963 expP->X_op = O_symbol;
964 expP->X_add_symbol = intel_state.seg;
965 i.op[this_operand].imms = expP;
967 resolve_expression (expP);
968 operand_type_set (&types, ~0);
969 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state.seg),
970 expP, types, operand_string))
971 return 0;
972 if (i.operands < MAX_OPERANDS)
974 this_operand = i.operands++;
975 i.types[this_operand].bitfield.unspecified = 1;
977 intel_state.seg = NULL;
978 intel_state.is_mem = 0;
980 break;
981 default:
982 jumpabsolute = true;
983 break;
985 if (jumpabsolute)
987 i.jumpabsolute = true;
988 intel_state.is_mem |= 1;
991 else if (intel_state.seg)
992 intel_state.is_mem |= 1;
994 if (i.op[this_operand].regs)
996 i386_operand_type temp;
998 /* Register operand. */
999 if (intel_state.base || intel_state.index || intel_state.seg
1000 || i.imm_bits[this_operand])
1002 as_bad (_("invalid operand"));
1003 return 0;
1006 temp = i.op[this_operand].regs->reg_type;
1007 temp.bitfield.baseindex = 0;
1008 i.types[this_operand] = operand_type_or (i.types[this_operand],
1009 temp);
1010 i.types[this_operand].bitfield.unspecified = 0;
1011 ++i.reg_operands;
1013 if ((i.rounding.type != rc_none && !i.rounding.modifier
1014 && temp.bitfield.class != Reg)
1015 || rc_sae_modifier)
1017 unsigned int j;
1019 for (j = 0; j < ARRAY_SIZE (RC_NamesTable); ++j)
1020 if (i.rounding.type == RC_NamesTable[j].type)
1021 break;
1022 as_bad (_("`%s': misplaced `{%s}'"),
1023 insn_name (current_templates.start), RC_NamesTable[j].name);
1024 return 0;
1027 else if (intel_state.base
1028 || intel_state.index
1029 || intel_state.seg
1030 || intel_state.is_mem)
1032 /* Memory operand. */
1033 if (i.imm_bits[this_operand])
1035 as_bad (_("invalid operand"));
1036 return 0;
1039 if (i.mem_operands)
1041 /* Handle
1043 call 0x9090,0x90909090
1044 lcall 0x9090,0x90909090
1045 jmp 0x9090,0x90909090
1046 ljmp 0x9090,0x90909090
1049 if ((current_templates.start->opcode_modifier.jump == JUMP_INTERSEGMENT
1050 || current_templates.start->opcode_modifier.jump == JUMP_DWORD
1051 || current_templates.start->opcode_modifier.jump == JUMP)
1052 && this_operand == 1
1053 && intel_state.seg == NULL
1054 && i.mem_operands == 1
1055 && i.disp_operands == 1
1056 && intel_state.op_modifier == O_absent)
1058 /* Try to process the first operand as immediate, */
1059 this_operand = 0;
1060 if (i386_finalize_immediate (exp_seg, i.op[0].imms,
1061 intel_state.reloc_types,
1062 NULL))
1064 this_operand = 1;
1065 expP = &im_expressions[0];
1066 i.op[this_operand].imms = expP;
1067 *expP = exp;
1069 /* Try to process the second operand as immediate, */
1070 if (i386_finalize_immediate (exp_seg, expP,
1071 intel_state.reloc_types,
1072 NULL))
1074 i.mem_operands = 0;
1075 i.disp_operands = 0;
1076 i.imm_operands = 2;
1077 i.flags[0] &= ~Operand_Mem;
1078 i.types[0].bitfield.disp16 = 0;
1079 i.types[0].bitfield.disp32 = 0;
1080 return 1;
1086 /* Swap base and index in 16-bit memory operands like
1087 [si+bx]. Since i386_index_check is also used in AT&T
1088 mode we have to do this here. */
1089 if (intel_state.base
1090 && intel_state.index
1091 && intel_state.base->reg_type.bitfield.word
1092 && intel_state.index->reg_type.bitfield.word
1093 && intel_state.base->reg_num >= 6
1094 && intel_state.index->reg_num < 6)
1096 i.base_reg = intel_state.index;
1097 i.index_reg = intel_state.base;
1099 else
1101 i.base_reg = intel_state.base;
1102 i.index_reg = intel_state.index;
1105 if (i.base_reg || i.index_reg)
1106 i.types[this_operand].bitfield.baseindex = 1;
1108 expP = &disp_expressions[i.disp_operands];
1109 memcpy (expP, &exp, sizeof(exp));
1110 resolve_expression (expP);
1112 if (expP->X_op != O_constant
1113 || expP->X_add_number
1114 || !i.types[this_operand].bitfield.baseindex)
1116 i.op[this_operand].disps = expP;
1117 i.disp_operands++;
1119 i386_addressing_mode ();
1121 if (flag_code == CODE_64BIT)
1123 i.types[this_operand].bitfield.disp32 = 1;
1124 if (!i.prefix[ADDR_PREFIX])
1125 i.types[this_operand].bitfield.disp64 = 1;
1127 else if (!i.prefix[ADDR_PREFIX] ^ (flag_code == CODE_16BIT))
1128 i.types[this_operand].bitfield.disp32 = 1;
1129 else
1130 i.types[this_operand].bitfield.disp16 = 1;
1132 #ifdef OBJ_AOUT
1134 * exp_seg is used only for verification in
1135 * i386_finalize_displacement, and we can end up seeing reg_section
1136 * here - but we know we removed all registers from the expression
1137 * (or error-ed on any remaining ones) in i386_intel_simplify. I
1138 * consider the check in i386_finalize_displacement bogus anyway, in
1139 * particular because it doesn't allow for expr_section, so I'd
1140 * rather see that check (and the similar one in
1141 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
1142 * expert I can't really say whether that would have other bad side
1143 * effects.
1145 if (OUTPUT_FLAVOR == bfd_target_aout_flavour
1146 && exp_seg == reg_section)
1147 exp_seg = expP->X_op != O_constant ? undefined_section
1148 : absolute_section;
1149 #endif
1151 if (!i386_finalize_displacement (exp_seg, expP,
1152 intel_state.reloc_types,
1153 operand_string))
1154 return 0;
1157 if (intel_state.seg)
1159 for (ret = check_none; ; ret = operand_check)
1161 expP = symbol_get_value_expression (intel_state.seg);
1162 if (expP->X_op != O_full_ptr
1163 || symbol_get_value_expression (expP->X_op_symbol)->X_op
1164 != O_register)
1165 break;
1166 intel_state.seg = expP->X_add_symbol;
1168 if (expP->X_op != O_register)
1170 as_bad (_("segment register name expected"));
1171 return 0;
1173 if (i386_regtab[expP->X_add_number].reg_type.bitfield.class != SReg)
1175 as_bad (_("invalid use of register"));
1176 return 0;
1178 switch (ret)
1180 case check_error:
1181 as_bad (_("redundant segment overrides"));
1182 return 0;
1183 case check_warning:
1184 as_warn (_("redundant segment overrides"));
1185 break;
1187 if (i386_regtab[expP->X_add_number].reg_num == RegFlat)
1188 i.seg[i.mem_operands] = NULL;
1189 else
1190 i.seg[i.mem_operands] = &i386_regtab[expP->X_add_number];
1193 if (!i386_index_check (operand_string))
1194 return 0;
1196 i.flags[this_operand] |= Operand_Mem;
1197 ++i.mem_operands;
1199 else
1201 /* Immediate. */
1202 if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
1204 as_bad (_("at most %d immediate operands are allowed"),
1205 MAX_IMMEDIATE_OPERANDS);
1206 return 0;
1209 expP = &im_expressions[i.imm_operands++];
1210 i.op[this_operand].imms = expP;
1211 *expP = exp;
1213 return i386_finalize_immediate (exp_seg, expP, intel_state.reloc_types,
1214 operand_string);
1217 return 1;