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)
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
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
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. */
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
74 unsigned int operands
;
76 const i386_operators
[] =
78 { "and", O_bit_and
, 2 },
84 { "mod", O_modulus
, 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 }
100 unsigned short sz
[3];
104 #define I386_TYPE(t, n) { #t, O_##t##_ptr, { n, n, n } }
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),
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
)
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
;
143 switch (*input_line_pointer
)
146 ++input_line_pointer
;
149 ++input_line_pointer
;
152 if (this_operand
>= 0 && i
.reloc
[this_operand
] == NO_RELOC
)
155 char *gotfree_input_line
= lex_got (&i
.reloc
[this_operand
],
157 &intel_state
.reloc_types
);
159 if (!gotfree_input_line
)
161 free (gotfree_input_line
);
162 *input_line_pointer
++ = '+';
163 memset (input_line_pointer
, '0', adjust
- 1);
164 input_line_pointer
[adjust
- 1] = ' ';
172 /* See the quotation related comment in i386_parse_name(). */
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
)
182 return i386_operators
[j
].op
;
185 for (j
= 0; i386_types
[j
].name
; ++j
)
186 if (strcasecmp (i386_types
[j
].name
, name
) == 0)
189 if (i386_types
[j
].name
&& *pc
== ' ')
191 const char *start
= ++input_line_pointer
;
193 char c
= get_symbol_name (&pname
);
195 if (strcasecmp (pname
, "ptr") == 0 && (c
!= '"' || pname
== start
))
199 if (intel_syntax
> 0 || operands
!= 1)
201 return i386_types
[j
].op
;
204 if (strcasecmp (pname
, "bcst") == 0 && (c
!= '"' || pname
== start
))
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)))
214 case encoding_default
:
216 pp
.encoding
= encoding_evex
;
219 case encoding_evex512
:
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;
239 static int i386_intel_parse_name (const char *name
,
245 if (! strcmp (name
, "$"))
247 current_location (e
, mode
);
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
;
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"));
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
;
287 e
->X_add_number
+= val
;
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
;
302 i386_intel_simplify_register (expressionS
*e
)
306 if (this_operand
< 0 || intel_state
.in_offset
)
308 as_bad (_("invalid use of register"));
312 if (e
->X_op
== O_register
)
313 reg_num
= e
->X_add_number
;
315 reg_num
= e
->X_md
- 1;
317 if (reg_num
< 0 || reg_num
>= (int) i386_regtab_size
)
319 as_bad (_("invalid register number"));
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
);
330 if (!intel_state
.in_bracket
)
332 if (i
.op
[this_operand
].regs
)
334 as_bad (_("invalid use of register"));
337 if ((i386_regtab
[reg_num
].reg_type
.bitfield
.class == SReg
338 && i386_regtab
[reg_num
].reg_num
== RegFlat
)
340 && i386_regtab
[reg_num
].reg_type
.bitfield
.class == ClassNone
))
342 as_bad (_("invalid use of pseudo-register"));
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
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
;
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
;
375 /* esp is invalid as index */
376 intel_state
.index
= reg_eax
+ ESP_REG_NUM
;
382 i386_intel_simplify_symbol (symbolS
*sym
)
384 if (symbol_resolving_p (sym
))
387 symbol_mark_resolving (sym
);
388 int ret
= i386_intel_simplify (symbol_get_value_expression (sym
));
391 S_SET_SEGMENT (sym
, absolute_section
);
394 symbol_clear_resolving (sym
);
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
;
415 if (!i386_intel_simplify_symbol (e
->X_add_symbol
)
416 || !i386_intel_check(the_reg
, intel_state
.base
,
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
;
430 i386_intel_fold (e
, e
->X_op_symbol
);
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
))
440 i386_intel_fold (e
, e
->X_add_symbol
);
447 case O_qword_ptr
: /* O_mmword_ptr */
449 case O_oword_ptr
: /* O_xmmword_ptr */
454 if (intel_state
.op_modifier
== O_absent
)
455 intel_state
.op_modifier
= e
->X_op
;
458 if (symbol_get_value_expression (e
->X_add_symbol
)->X_op
461 as_bad (_("invalid use of register"));
464 if (!i386_intel_simplify_symbol (e
->X_add_symbol
))
466 i386_intel_fold (e
, e
->X_add_symbol
);
470 if (symbol_get_value_expression (e
->X_op_symbol
)->X_op
473 as_bad (_("invalid use of register"));
476 if (!i386_intel_simplify_symbol (e
->X_op_symbol
)
477 || !i386_intel_check(the_reg
, intel_state
.base
,
480 if (!intel_state
.in_offset
)
482 if (!intel_state
.seg
)
483 intel_state
.seg
= e
->X_add_symbol
;
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
);
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
);
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
);
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
;
528 if (!intel_state
.in_scale
)
529 switch (intel_state
.scale_factor
)
532 i
.log2_scale_factor
= 0;
535 i
.log2_scale_factor
= 1;
538 i
.log2_scale_factor
= 2;
541 i
.log2_scale_factor
= 3;
544 /* esp is invalid as index */
545 intel_state
.index
= reg_eax
+ ESP_REG_NUM
;
554 ret
= i386_intel_simplify_register (e
);
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
;
566 return i386_intel_simplify_register (e
);
572 && !i386_intel_simplify_symbol (e
->X_add_symbol
))
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
)
584 && !i386_intel_simplify_symbol (e
->X_op_symbol
))
585 || !i386_intel_check (the_reg
,
587 ? base
: intel_state
.base
),
589 ? state_index
: intel_state
.index
)))
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
;
609 int i386_need_index_operator (void)
611 return intel_syntax
< 0;
615 i386_intel_operand (char *operand_string
, int got_a_float
)
617 char *saved_input_line_pointer
, *buf
;
619 expressionS exp
, *expP
;
621 bool rc_sae_modifier
= i
.rounding
.type
!= rc_none
&& i
.rounding
.modifier
;
624 /* Handle vector immediates. */
625 if (RC_SAE_immediate (operand_string
))
629 as_bad (_("`%s': RC/SAE operand must precede immediate operands"),
630 insn_name (current_templates
.start
));
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
);
654 expr_mode
= expr_operator_none
;
655 memset (&exp
, 0, sizeof(exp
));
656 exp_seg
= expression (&exp
);
657 ret
= i386_intel_simplify (&exp
);
662 /* Handle vector operations. */
663 if (*input_line_pointer
== '{')
665 char *end
= check_VecOperations (input_line_pointer
);
667 input_line_pointer
= end
;
672 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
675 as_bad (_("junk `%s' after expression"), input_line_pointer
);
678 else if (exp
.X_op
== O_illegal
|| exp
.X_op
== O_absent
)
681 as_bad (_("invalid expression"));
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
;
695 gas_assert (!intel_state
.in_offset
);
696 gas_assert (!intel_state
.in_bracket
);
697 gas_assert (!intel_state
.in_scale
);
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
)
710 i
.types
[this_operand
].bitfield
.byte
= 1;
711 suffix
= BYTE_MNEM_SUFFIX
;
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
;
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
737 suffix
= WORD_MNEM_SUFFIX
;
739 else if (got_a_float
== 1) /* "f..." */
740 suffix
= SHORT_MNEM_SUFFIX
;
742 suffix
= LONG_MNEM_SUFFIX
;
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
);
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
;
767 suffix
= QWORD_MNEM_SUFFIX
;
771 i
.types
[this_operand
].bitfield
.tbyte
= 1;
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 */
781 i
.types
[this_operand
].bitfield
.byte
= 1; /* cause an error */
784 case O_oword_ptr
: /* O_xmmword_ptr */
785 i
.types
[this_operand
].bitfield
.xmmword
= 1;
789 if (vector_size
< VSZ256
)
791 as_bad (_("256-bit operands disabled"));
794 i
.types
[this_operand
].bitfield
.ymmword
= 1;
798 if (vector_size
< VSZ512
)
800 as_bad (_("512-bit operands disabled"));
803 i
.types
[this_operand
].bitfield
.zmmword
= 1;
810 if (current_templates
.start
->opcode_modifier
.jump
!= JUMP
811 && current_templates
.start
->opcode_modifier
.jump
!= JUMP_DWORD
)
814 i
.types
[this_operand
].bitfield
.byte
= 1;
815 i
.types
[this_operand
].bitfield
.tbyte
= 1;
821 BAD_CASE (intel_state
.op_modifier
);
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
)
846 case BYTE_MNEM_SUFFIX
:
847 if (t
->opcode_modifier
.no_bsuf
)
850 case WORD_MNEM_SUFFIX
:
851 if (t
->opcode_modifier
.no_wsuf
)
854 case LONG_MNEM_SUFFIX
:
855 if (t
->opcode_modifier
.no_lsuf
)
858 case QWORD_MNEM_SUFFIX
:
859 if (t
->opcode_modifier
.no_qsuf
|| !q_suffix_allowed (t
))
862 case SHORT_MNEM_SUFFIX
:
863 if (t
->opcode_modifier
.no_ssuf
)
870 /* We can skip templates with swappable operands here, as one
871 operand will be a register, which operand size can be
873 if (t
->opcode_modifier
.d
)
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
)
882 if (!t
->operand_types
[op
].bitfield
.baseindex
)
885 switch (t
->operand_types
[op
].bitfield
.class)
896 if (t
== current_templates
.end
)
902 else if (suffix
&& i
.suffix
!= suffix
)
904 as_bad (_("conflicting operand size modifiers"));
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
920 || intel_state
.is_mem
> 1)
923 switch (intel_state
.op_modifier
)
929 intel_state
.is_mem
= 1;
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)
942 as_bad (_("cannot infer the segment part of the operand"));
945 else if (S_GET_SEGMENT (intel_state
.seg
) == reg_section
)
948 if (intel_state
.op_modifier
== O_far_ptr
)
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
);
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
))
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;
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"));
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
],
1010 i
.types
[this_operand
].bitfield
.unspecified
= 0;
1013 if ((i
.rounding
.type
!= rc_none
&& !i
.rounding
.modifier
1014 && temp
.bitfield
.class != Reg
)
1019 for (j
= 0; j
< ARRAY_SIZE (RC_NamesTable
); ++j
)
1020 if (i
.rounding
.type
== RC_NamesTable
[j
].type
)
1022 as_bad (_("`%s': misplaced `{%s}'"),
1023 insn_name (current_templates
.start
), RC_NamesTable
[j
].name
);
1027 else if (intel_state
.base
1028 || intel_state
.index
1030 || intel_state
.is_mem
)
1032 /* Memory operand. */
1033 if (i
.imm_bits
[this_operand
])
1035 as_bad (_("invalid operand"));
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, */
1060 if (i386_finalize_immediate (exp_seg
, i
.op
[0].imms
,
1061 intel_state
.reloc_types
,
1065 expP
= &im_expressions
[0];
1066 i
.op
[this_operand
].imms
= expP
;
1069 /* Try to process the second operand as immediate, */
1070 if (i386_finalize_immediate (exp_seg
, expP
,
1071 intel_state
.reloc_types
,
1075 i
.disp_operands
= 0;
1077 i
.flags
[0] &= ~Operand_Mem
;
1078 i
.types
[0].bitfield
.disp16
= 0;
1079 i
.types
[0].bitfield
.disp32
= 0;
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
;
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
;
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;
1130 i
.types
[this_operand
].bitfield
.disp16
= 1;
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
1145 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
1146 && exp_seg
== reg_section
)
1147 exp_seg
= expP
->X_op
!= O_constant
? undefined_section
1151 if (!i386_finalize_displacement (exp_seg
, expP
,
1152 intel_state
.reloc_types
,
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
1166 intel_state
.seg
= expP
->X_add_symbol
;
1168 if (expP
->X_op
!= O_register
)
1170 as_bad (_("segment register name expected"));
1173 if (i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.class != SReg
)
1175 as_bad (_("invalid use of register"));
1181 as_bad (_("redundant segment overrides"));
1184 as_warn (_("redundant segment overrides"));
1187 if (i386_regtab
[expP
->X_add_number
].reg_num
== RegFlat
)
1188 i
.seg
[i
.mem_operands
] = NULL
;
1190 i
.seg
[i
.mem_operands
] = &i386_regtab
[expP
->X_add_number
];
1193 if (!i386_index_check (operand_string
))
1196 i
.flags
[this_operand
] |= Operand_Mem
;
1202 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
1204 as_bad (_("at most %d immediate operands are allowed"),
1205 MAX_IMMEDIATE_OPERANDS
);
1209 expP
= &im_expressions
[i
.imm_operands
++];
1210 i
.op
[this_operand
].imms
= expP
;
1213 return i386_finalize_immediate (exp_seg
, expP
, intel_state
.reloc_types
,