1 /* tc-i386.c -- Assemble Intel syntax code for ix86/x86-64
2 Copyright (C) 2009-2023 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)))
212 if (!i
.broadcast
.bytes
&& !i
.broadcast
.type
)
214 i
.broadcast
.bytes
= i386_types
[j
].sz
[0];
215 i
.broadcast
.operand
= this_operand
;
217 return i386_types
[j
].op
;
220 (void) restore_line_pointer (c
);
221 input_line_pointer
= pname
- 1;
227 static int i386_intel_parse_name (const char *name
, expressionS
*e
)
231 if (! strcmp (name
, "$"))
233 current_location (e
);
237 for (j
= 0; i386_types
[j
].name
; ++j
)
238 if (strcasecmp(i386_types
[j
].name
, name
) == 0)
240 e
->X_op
= O_constant
;
241 e
->X_add_number
= i386_types
[j
].sz
[flag_code
];
242 e
->X_add_symbol
= NULL
;
243 e
->X_op_symbol
= NULL
;
250 static INLINE
int i386_intel_check (const reg_entry
*rreg
,
251 const reg_entry
*base
,
252 const reg_entry
*iindex
)
254 if ((this_operand
>= 0
255 && rreg
!= i
.op
[this_operand
].regs
)
256 || base
!= intel_state
.base
257 || iindex
!= intel_state
.index
)
259 as_bad (_("invalid use of register"));
265 static INLINE
void i386_intel_fold (expressionS
*e
, symbolS
*sym
)
267 expressionS
*exp
= symbol_get_value_expression (sym
);
268 if (S_GET_SEGMENT (sym
) == absolute_section
)
270 offsetT val
= e
->X_add_number
;
273 e
->X_add_number
+= val
;
277 if (exp
->X_op
== O_symbol
278 && strcmp (S_GET_NAME (exp
->X_add_symbol
),
279 GLOBAL_OFFSET_TABLE_NAME
) == 0)
280 sym
= exp
->X_add_symbol
;
281 e
->X_add_symbol
= sym
;
282 e
->X_op_symbol
= NULL
;
288 i386_intel_simplify_register (expressionS
*e
)
292 if (this_operand
< 0 || intel_state
.in_offset
)
294 as_bad (_("invalid use of register"));
298 if (e
->X_op
== O_register
)
299 reg_num
= e
->X_add_number
;
301 reg_num
= e
->X_md
- 1;
303 if (reg_num
< 0 || reg_num
>= (int) i386_regtab_size
)
305 as_bad (_("invalid register number"));
309 if (!check_register (&i386_regtab
[reg_num
]))
311 as_bad (_("register '%s%s' cannot be used here"),
312 register_prefix
, i386_regtab
[reg_num
].reg_name
);
316 if (!intel_state
.in_bracket
)
318 if (i
.op
[this_operand
].regs
)
320 as_bad (_("invalid use of register"));
323 if ((i386_regtab
[reg_num
].reg_type
.bitfield
.class == SReg
324 && i386_regtab
[reg_num
].reg_num
== RegFlat
)
326 && i386_regtab
[reg_num
].reg_type
.bitfield
.class == ClassNone
))
328 as_bad (_("invalid use of pseudo-register"));
331 i
.op
[this_operand
].regs
= i386_regtab
+ reg_num
;
333 else if (!intel_state
.index
334 && (i386_regtab
[reg_num
].reg_type
.bitfield
.xmmword
335 || i386_regtab
[reg_num
].reg_type
.bitfield
.ymmword
336 || i386_regtab
[reg_num
].reg_type
.bitfield
.zmmword
337 || i386_regtab
[reg_num
].reg_num
== RegIZ
))
338 intel_state
.index
= i386_regtab
+ reg_num
;
339 else if (!intel_state
.base
&& !intel_state
.in_scale
)
340 intel_state
.base
= i386_regtab
+ reg_num
;
341 else if (!intel_state
.index
)
343 const insn_template
*t
= current_templates
->start
;
345 if (intel_state
.in_scale
346 || i386_regtab
[reg_num
].reg_type
.bitfield
.baseindex
348 || t
->mnem_off
== MN_bndmk
349 || t
->mnem_off
== MN_bndldx
350 || t
->mnem_off
== MN_bndstx
)
351 intel_state
.index
= i386_regtab
+ reg_num
;
354 /* Convert base to index and make ESP/RSP the base. */
355 intel_state
.index
= intel_state
.base
;
356 intel_state
.base
= i386_regtab
+ reg_num
;
361 /* esp is invalid as index */
362 intel_state
.index
= reg_eax
+ ESP_REG_NUM
;
367 static int i386_intel_simplify (expressionS
*);
369 static INLINE
int i386_intel_simplify_symbol(symbolS
*sym
)
371 int ret
= i386_intel_simplify (symbol_get_value_expression (sym
));
375 S_SET_SEGMENT(sym
, absolute_section
);
381 static int i386_intel_simplify (expressionS
*e
)
383 const reg_entry
*the_reg
= (this_operand
>= 0
384 ? i
.op
[this_operand
].regs
: NULL
);
385 const reg_entry
*base
= intel_state
.base
;
386 const reg_entry
*state_index
= intel_state
.index
;
397 if (!i386_intel_simplify_symbol (e
->X_add_symbol
)
398 || !i386_intel_check(the_reg
, intel_state
.base
,
402 if (!intel_state
.in_offset
)
403 ++intel_state
.in_bracket
;
404 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
405 if (!intel_state
.in_offset
)
406 --intel_state
.in_bracket
;
412 i386_intel_fold (e
, e
->X_op_symbol
);
416 intel_state
.has_offset
= 1;
417 ++intel_state
.in_offset
;
418 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
419 --intel_state
.in_offset
;
420 if (!ret
|| !i386_intel_check(the_reg
, base
, state_index
))
422 i386_intel_fold (e
, e
->X_add_symbol
);
429 case O_qword_ptr
: /* O_mmword_ptr */
431 case O_oword_ptr
: /* O_xmmword_ptr */
436 if (intel_state
.op_modifier
== O_absent
)
437 intel_state
.op_modifier
= e
->X_op
;
440 if (symbol_get_value_expression (e
->X_add_symbol
)->X_op
443 as_bad (_("invalid use of register"));
446 if (!i386_intel_simplify_symbol (e
->X_add_symbol
))
448 i386_intel_fold (e
, e
->X_add_symbol
);
452 if (symbol_get_value_expression (e
->X_op_symbol
)->X_op
455 as_bad (_("invalid use of register"));
458 if (!i386_intel_simplify_symbol (e
->X_op_symbol
)
459 || !i386_intel_check(the_reg
, intel_state
.base
,
462 if (!intel_state
.in_offset
)
464 if (!intel_state
.seg
)
465 intel_state
.seg
= e
->X_add_symbol
;
470 exp
.X_op
= O_full_ptr
;
471 exp
.X_add_symbol
= e
->X_add_symbol
;
472 exp
.X_op_symbol
= intel_state
.seg
;
473 intel_state
.seg
= make_expr_symbol (&exp
);
476 i386_intel_fold (e
, e
->X_op_symbol
);
480 if (this_operand
>= 0 && intel_state
.in_bracket
)
482 expressionS
*scale
= NULL
;
483 int has_index
= (intel_state
.index
!= NULL
);
485 if (!intel_state
.in_scale
++)
486 intel_state
.scale_factor
= 1;
488 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
489 if (ret
&& !has_index
&& intel_state
.index
)
490 scale
= symbol_get_value_expression (e
->X_op_symbol
);
493 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
494 if (ret
&& !scale
&& !has_index
&& intel_state
.index
)
495 scale
= symbol_get_value_expression (e
->X_add_symbol
);
499 resolve_expression (scale
);
500 if (scale
->X_op
!= O_constant
501 || intel_state
.index
->reg_type
.bitfield
.word
)
502 scale
->X_add_number
= 0;
503 intel_state
.scale_factor
*= scale
->X_add_number
;
506 --intel_state
.in_scale
;
510 if (!intel_state
.in_scale
)
511 switch (intel_state
.scale_factor
)
514 i
.log2_scale_factor
= 0;
517 i
.log2_scale_factor
= 1;
520 i
.log2_scale_factor
= 2;
523 i
.log2_scale_factor
= 3;
526 /* esp is invalid as index */
527 intel_state
.index
= reg_eax
+ ESP_REG_NUM
;
536 ret
= i386_intel_simplify_register (e
);
539 gas_assert (e
->X_add_number
< (unsigned short) -1);
540 e
->X_md
= (unsigned short) e
->X_add_number
+ 1;
541 e
->X_op
= O_constant
;
548 return i386_intel_simplify_register (e
);
554 && !i386_intel_simplify_symbol (e
->X_add_symbol
))
556 if (!the_reg
&& this_operand
>= 0
557 && e
->X_op
== O_symbol
&& !e
->X_add_number
)
558 the_reg
= i
.op
[this_operand
].regs
;
559 if (e
->X_op
== O_add
|| e
->X_op
== O_subtract
)
561 base
= intel_state
.base
;
562 state_index
= intel_state
.index
;
564 if (!i386_intel_check (the_reg
, base
, state_index
)
566 && !i386_intel_simplify_symbol (e
->X_op_symbol
))
567 || !i386_intel_check (the_reg
,
569 ? base
: intel_state
.base
),
571 ? state_index
: intel_state
.index
)))
576 if (this_operand
>= 0
577 && e
->X_op
== O_symbol
578 && !intel_state
.in_offset
)
580 segT seg
= S_GET_SEGMENT (e
->X_add_symbol
);
582 if (seg
!= absolute_section
583 && seg
!= reg_section
584 && seg
!= expr_section
)
585 intel_state
.is_mem
|= 2 - !intel_state
.in_bracket
;
591 int i386_need_index_operator (void)
593 return intel_syntax
< 0;
597 i386_intel_operand (char *operand_string
, int got_a_float
)
599 char *saved_input_line_pointer
, *buf
;
601 expressionS exp
, *expP
;
603 bool rc_sae_modifier
= i
.rounding
.type
!= rc_none
&& i
.rounding
.modifier
;
606 /* Handle vector immediates. */
607 if (RC_SAE_immediate (operand_string
))
611 as_bad (_("`%s': RC/SAE operand must precede immediate operands"),
612 insn_name (current_templates
->start
));
619 /* Initialize state structure. */
620 intel_state
.op_modifier
= O_absent
;
621 intel_state
.is_mem
= 0;
622 intel_state
.is_indirect
= 0;
623 intel_state
.has_offset
= 0;
624 intel_state
.base
= NULL
;
625 intel_state
.index
= NULL
;
626 intel_state
.seg
= NULL
;
627 operand_type_set (&intel_state
.reloc_types
, ~0);
628 gas_assert (!intel_state
.in_offset
);
629 gas_assert (!intel_state
.in_bracket
);
630 gas_assert (!intel_state
.in_scale
);
632 saved_input_line_pointer
= input_line_pointer
;
633 input_line_pointer
= buf
= xstrdup (operand_string
);
636 expr_mode
= expr_operator_none
;
637 memset (&exp
, 0, sizeof(exp
));
638 exp_seg
= expression (&exp
);
639 ret
= i386_intel_simplify (&exp
);
644 /* Handle vector operations. */
645 if (*input_line_pointer
== '{')
647 char *end
= check_VecOperations (input_line_pointer
);
649 input_line_pointer
= end
;
654 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
657 as_bad (_("junk `%s' after expression"), input_line_pointer
);
660 else if (exp
.X_op
== O_illegal
|| exp
.X_op
== O_absent
)
663 as_bad (_("invalid expression"));
666 else if (!intel_state
.has_offset
667 && input_line_pointer
> buf
668 && *(input_line_pointer
- 1) == ']')
670 intel_state
.is_mem
|= 1;
671 intel_state
.is_indirect
= 1;
674 input_line_pointer
= saved_input_line_pointer
;
677 gas_assert (!intel_state
.in_offset
);
678 gas_assert (!intel_state
.in_bracket
);
679 gas_assert (!intel_state
.in_scale
);
684 if (intel_state
.op_modifier
!= O_absent
685 && current_templates
->start
->mnem_off
!= MN_lea
)
687 i
.types
[this_operand
].bitfield
.unspecified
= 0;
689 switch (intel_state
.op_modifier
)
692 i
.types
[this_operand
].bitfield
.byte
= 1;
693 suffix
= BYTE_MNEM_SUFFIX
;
697 i
.types
[this_operand
].bitfield
.word
= 1;
698 if (got_a_float
== 2) /* "fi..." */
699 suffix
= SHORT_MNEM_SUFFIX
;
700 else if (current_templates
->start
->mnem_off
!= MN_lar
701 && current_templates
->start
->mnem_off
!= MN_lsl
702 && current_templates
->start
->mnem_off
!= MN_arpl
)
703 suffix
= WORD_MNEM_SUFFIX
;
707 i
.types
[this_operand
].bitfield
.dword
= 1;
708 if ((insn_name (current_templates
->start
)[0] == 'l'
709 && insn_name (current_templates
->start
)[2] == 's'
710 && insn_name (current_templates
->start
)[3] == 0)
711 || current_templates
->start
->mnem_off
== MN_bound
)
712 suffix
= WORD_MNEM_SUFFIX
;
713 else if (flag_code
!= CODE_32BIT
714 && (current_templates
->start
->opcode_modifier
.jump
== JUMP
715 || current_templates
->start
->opcode_modifier
.jump
719 suffix
= WORD_MNEM_SUFFIX
;
721 else if (got_a_float
== 1) /* "f..." */
722 suffix
= SHORT_MNEM_SUFFIX
;
724 suffix
= LONG_MNEM_SUFFIX
;
728 i
.types
[this_operand
].bitfield
.fword
= 1;
729 if (current_templates
->start
->mnem_off
== MN_les
730 || current_templates
->start
->mnem_off
== MN_lds
731 || current_templates
->start
->mnem_off
== MN_lss
732 || current_templates
->start
->mnem_off
== MN_lfs
733 || current_templates
->start
->mnem_off
== MN_lgs
)
734 suffix
= LONG_MNEM_SUFFIX
;
735 else if (!got_a_float
)
737 if (flag_code
== CODE_16BIT
)
738 add_prefix (DATA_PREFIX_OPCODE
);
743 case O_qword_ptr
: /* O_mmword_ptr */
744 i
.types
[this_operand
].bitfield
.qword
= 1;
745 if (current_templates
->start
->mnem_off
== MN_bound
746 || got_a_float
== 1) /* "f..." */
747 suffix
= LONG_MNEM_SUFFIX
;
749 suffix
= QWORD_MNEM_SUFFIX
;
753 i
.types
[this_operand
].bitfield
.tbyte
= 1;
756 if (flag_code
== CODE_64BIT
757 && (current_templates
->start
->operand_types
[0].bitfield
.fword
758 || current_templates
->start
->operand_types
[0].bitfield
.tbyte
759 || current_templates
->start
->opcode_modifier
.jump
== JUMP_DWORD
760 || current_templates
->start
->opcode_modifier
.jump
== JUMP
))
761 suffix
= QWORD_MNEM_SUFFIX
; /* l[fgs]s, [ls][gi]dt, call, jmp */
763 i
.types
[this_operand
].bitfield
.byte
= 1; /* cause an error */
766 case O_oword_ptr
: /* O_xmmword_ptr */
767 i
.types
[this_operand
].bitfield
.xmmword
= 1;
771 i
.types
[this_operand
].bitfield
.ymmword
= 1;
775 i
.types
[this_operand
].bitfield
.zmmword
= 1;
782 if (current_templates
->start
->opcode_modifier
.jump
!= JUMP
783 && current_templates
->start
->opcode_modifier
.jump
!= JUMP_DWORD
)
786 i
.types
[this_operand
].bitfield
.byte
= 1;
787 i
.types
[this_operand
].bitfield
.tbyte
= 1;
793 BAD_CASE (intel_state
.op_modifier
);
797 /* Now check whether we actually want to infer an AT&T-like suffix.
798 We really only need to do this when operand size determination (incl.
799 REX.W) is going to be derived from it. For this we check whether the
800 given suffix is valid for any of the candidate templates. */
801 if (suffix
&& suffix
!= i
.suffix
802 && current_templates
->start
->mnem_off
!= MN_bound
)
804 const insn_template
*t
;
806 for (t
= current_templates
->start
; t
< current_templates
->end
; ++t
)
808 /* Operands haven't been swapped yet. */
809 unsigned int op
= t
->operands
- 1 - this_operand
;
811 /* Easy checks to skip templates which won't match anyway. */
812 if (this_operand
>= t
->operands
|| t
->opcode_modifier
.attsyntax
)
817 case BYTE_MNEM_SUFFIX
:
818 if (t
->opcode_modifier
.no_bsuf
)
821 case WORD_MNEM_SUFFIX
:
822 if (t
->opcode_modifier
.no_wsuf
)
825 case LONG_MNEM_SUFFIX
:
826 if (t
->opcode_modifier
.no_lsuf
)
829 case QWORD_MNEM_SUFFIX
:
830 if (t
->opcode_modifier
.no_qsuf
|| !q_suffix_allowed (t
))
833 case SHORT_MNEM_SUFFIX
:
834 if (t
->opcode_modifier
.no_ssuf
)
841 /* We can skip templates with swappable operands here, as one
842 operand will be a register, which operand size can be
844 if (t
->opcode_modifier
.d
)
847 /* In a few cases suffixes are permitted, but we can nevertheless
848 derive that these aren't going to be needed. This is only of
849 interest for insns using ModR/M. */
850 if (!t
->opcode_modifier
.modrm
)
853 if (!t
->operand_types
[op
].bitfield
.baseindex
)
856 switch (t
->operand_types
[op
].bitfield
.class)
867 if (t
== current_templates
->end
)
873 else if (suffix
&& i
.suffix
!= suffix
)
875 as_bad (_("conflicting operand size modifiers"));
880 /* Operands for jump/call need special consideration. */
881 if (current_templates
->start
->opcode_modifier
.jump
== JUMP
882 || current_templates
->start
->opcode_modifier
.jump
== JUMP_DWORD
883 || current_templates
->start
->opcode_modifier
.jump
== JUMP_INTERSEGMENT
)
885 bool jumpabsolute
= false;
887 if (i
.op
[this_operand
].regs
890 || intel_state
.is_mem
> 1)
893 switch (intel_state
.op_modifier
)
899 intel_state
.is_mem
= 1;
903 if (!intel_state
.seg
)
905 intel_state
.is_mem
= 1;
906 if (intel_state
.op_modifier
== O_absent
)
908 if (intel_state
.is_indirect
== 1)
912 as_bad (_("cannot infer the segment part of the operand"));
915 else if (S_GET_SEGMENT (intel_state
.seg
) == reg_section
)
918 if (intel_state
.op_modifier
== O_far_ptr
)
923 i386_operand_type types
;
925 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
927 as_bad (_("at most %d immediate operands are allowed"),
928 MAX_IMMEDIATE_OPERANDS
);
931 expP
= &im_expressions
[i
.imm_operands
++];
932 memset (expP
, 0, sizeof(*expP
));
933 expP
->X_op
= O_symbol
;
934 expP
->X_add_symbol
= intel_state
.seg
;
935 i
.op
[this_operand
].imms
= expP
;
937 resolve_expression (expP
);
938 operand_type_set (&types
, ~0);
939 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state
.seg
),
940 expP
, types
, operand_string
))
942 if (i
.operands
< MAX_OPERANDS
)
944 this_operand
= i
.operands
++;
945 i
.types
[this_operand
].bitfield
.unspecified
= 1;
947 intel_state
.seg
= NULL
;
948 intel_state
.is_mem
= 0;
957 i
.jumpabsolute
= true;
958 intel_state
.is_mem
|= 1;
961 else if (intel_state
.seg
)
962 intel_state
.is_mem
|= 1;
964 if (i
.op
[this_operand
].regs
)
966 i386_operand_type temp
;
968 /* Register operand. */
969 if (intel_state
.base
|| intel_state
.index
|| intel_state
.seg
970 || i
.imm_bits
[this_operand
])
972 as_bad (_("invalid operand"));
976 temp
= i
.op
[this_operand
].regs
->reg_type
;
977 temp
.bitfield
.baseindex
= 0;
978 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
980 i
.types
[this_operand
].bitfield
.unspecified
= 0;
983 if ((i
.rounding
.type
!= rc_none
&& !i
.rounding
.modifier
984 && temp
.bitfield
.class != Reg
)
989 for (j
= 0; j
< ARRAY_SIZE (RC_NamesTable
); ++j
)
990 if (i
.rounding
.type
== RC_NamesTable
[j
].type
)
992 as_bad (_("`%s': misplaced `{%s}'"),
993 insn_name (current_templates
->start
), RC_NamesTable
[j
].name
);
997 else if (intel_state
.base
1000 || intel_state
.is_mem
)
1002 /* Memory operand. */
1003 if (i
.imm_bits
[this_operand
])
1005 as_bad (_("invalid operand"));
1013 call 0x9090,0x90909090
1014 lcall 0x9090,0x90909090
1015 jmp 0x9090,0x90909090
1016 ljmp 0x9090,0x90909090
1019 if ((current_templates
->start
->opcode_modifier
.jump
== JUMP_INTERSEGMENT
1020 || current_templates
->start
->opcode_modifier
.jump
== JUMP_DWORD
1021 || current_templates
->start
->opcode_modifier
.jump
== JUMP
)
1022 && this_operand
== 1
1023 && intel_state
.seg
== NULL
1024 && i
.mem_operands
== 1
1025 && i
.disp_operands
== 1
1026 && intel_state
.op_modifier
== O_absent
)
1028 /* Try to process the first operand as immediate, */
1030 if (i386_finalize_immediate (exp_seg
, i
.op
[0].imms
,
1031 intel_state
.reloc_types
,
1035 expP
= &im_expressions
[0];
1036 i
.op
[this_operand
].imms
= expP
;
1039 /* Try to process the second operand as immediate, */
1040 if (i386_finalize_immediate (exp_seg
, expP
,
1041 intel_state
.reloc_types
,
1045 i
.disp_operands
= 0;
1047 i
.flags
[0] &= ~Operand_Mem
;
1048 i
.types
[0].bitfield
.disp16
= 0;
1049 i
.types
[0].bitfield
.disp32
= 0;
1056 /* Swap base and index in 16-bit memory operands like
1057 [si+bx]. Since i386_index_check is also used in AT&T
1058 mode we have to do this here. */
1059 if (intel_state
.base
1060 && intel_state
.index
1061 && intel_state
.base
->reg_type
.bitfield
.word
1062 && intel_state
.index
->reg_type
.bitfield
.word
1063 && intel_state
.base
->reg_num
>= 6
1064 && intel_state
.index
->reg_num
< 6)
1066 i
.base_reg
= intel_state
.index
;
1067 i
.index_reg
= intel_state
.base
;
1071 i
.base_reg
= intel_state
.base
;
1072 i
.index_reg
= intel_state
.index
;
1075 if (i
.base_reg
|| i
.index_reg
)
1076 i
.types
[this_operand
].bitfield
.baseindex
= 1;
1078 expP
= &disp_expressions
[i
.disp_operands
];
1079 memcpy (expP
, &exp
, sizeof(exp
));
1080 resolve_expression (expP
);
1082 if (expP
->X_op
!= O_constant
1083 || expP
->X_add_number
1084 || !i
.types
[this_operand
].bitfield
.baseindex
)
1086 i
.op
[this_operand
].disps
= expP
;
1089 i386_addressing_mode ();
1091 if (flag_code
== CODE_64BIT
)
1093 i
.types
[this_operand
].bitfield
.disp32
= 1;
1094 if (!i
.prefix
[ADDR_PREFIX
])
1095 i
.types
[this_operand
].bitfield
.disp64
= 1;
1097 else if (!i
.prefix
[ADDR_PREFIX
] ^ (flag_code
== CODE_16BIT
))
1098 i
.types
[this_operand
].bitfield
.disp32
= 1;
1100 i
.types
[this_operand
].bitfield
.disp16
= 1;
1102 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
1104 * exp_seg is used only for verification in
1105 * i386_finalize_displacement, and we can end up seeing reg_section
1106 * here - but we know we removed all registers from the expression
1107 * (or error-ed on any remaining ones) in i386_intel_simplify. I
1108 * consider the check in i386_finalize_displacement bogus anyway, in
1109 * particular because it doesn't allow for expr_section, so I'd
1110 * rather see that check (and the similar one in
1111 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
1112 * expert I can't really say whether that would have other bad side
1115 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
1116 && exp_seg
== reg_section
)
1117 exp_seg
= expP
->X_op
!= O_constant
? undefined_section
1121 if (!i386_finalize_displacement (exp_seg
, expP
,
1122 intel_state
.reloc_types
,
1127 if (intel_state
.seg
)
1129 for (ret
= check_none
; ; ret
= operand_check
)
1131 expP
= symbol_get_value_expression (intel_state
.seg
);
1132 if (expP
->X_op
!= O_full_ptr
1133 || symbol_get_value_expression (expP
->X_op_symbol
)->X_op
1136 intel_state
.seg
= expP
->X_add_symbol
;
1138 if (expP
->X_op
!= O_register
)
1140 as_bad (_("segment register name expected"));
1143 if (i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.class != SReg
)
1145 as_bad (_("invalid use of register"));
1151 as_bad (_("redundant segment overrides"));
1154 as_warn (_("redundant segment overrides"));
1157 if (i386_regtab
[expP
->X_add_number
].reg_num
== RegFlat
)
1158 i
.seg
[i
.mem_operands
] = NULL
;
1160 i
.seg
[i
.mem_operands
] = &i386_regtab
[expP
->X_add_number
];
1163 if (!i386_index_check (operand_string
))
1166 i
.flags
[this_operand
] |= Operand_Mem
;
1172 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
1174 as_bad (_("at most %d immediate operands are allowed"),
1175 MAX_IMMEDIATE_OPERANDS
);
1179 expP
= &im_expressions
[i
.imm_operands
++];
1180 i
.op
[this_operand
].imms
= expP
;
1183 return i386_finalize_immediate (exp_seg
, expP
, intel_state
.reloc_types
,