1 /* tc-i386.c -- Assemble Intel syntax code for ix86/x86-64
2 Copyright (C) 2009-2021 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 for (j
= 0; i386_operators
[j
].name
; ++j
)
173 if (strcasecmp (i386_operators
[j
].name
, name
) == 0)
175 if (i386_operators
[j
].operands
176 && i386_operators
[j
].operands
!= operands
)
178 return i386_operators
[j
].op
;
181 for (j
= 0; i386_types
[j
].name
; ++j
)
182 if (strcasecmp (i386_types
[j
].name
, name
) == 0)
185 if (i386_types
[j
].name
&& *pc
== ' ')
190 ++input_line_pointer
;
191 c
= get_symbol_name (&pname
);
193 if (strcasecmp (pname
, "ptr") == 0)
195 /* FIXME: What if c == '"' ? */
198 if (intel_syntax
> 0 || operands
!= 1)
200 return i386_types
[j
].op
;
203 (void) restore_line_pointer (c
);
204 input_line_pointer
= pname
- 1;
210 static int i386_intel_parse_name (const char *name
, expressionS
*e
)
214 if (! strcmp (name
, "$"))
216 current_location (e
);
220 for (j
= 0; i386_types
[j
].name
; ++j
)
221 if (strcasecmp(i386_types
[j
].name
, name
) == 0)
223 e
->X_op
= O_constant
;
224 e
->X_add_number
= i386_types
[j
].sz
[flag_code
];
225 e
->X_add_symbol
= NULL
;
226 e
->X_op_symbol
= NULL
;
233 static INLINE
int i386_intel_check (const reg_entry
*rreg
,
234 const reg_entry
*base
,
235 const reg_entry
*iindex
)
237 if ((this_operand
>= 0
238 && rreg
!= i
.op
[this_operand
].regs
)
239 || base
!= intel_state
.base
240 || iindex
!= intel_state
.index
)
242 as_bad (_("invalid use of register"));
248 static INLINE
void i386_intel_fold (expressionS
*e
, symbolS
*sym
)
250 expressionS
*exp
= symbol_get_value_expression (sym
);
251 if (S_GET_SEGMENT (sym
) == absolute_section
)
253 offsetT val
= e
->X_add_number
;
256 e
->X_add_number
+= val
;
260 if (exp
->X_op
== O_symbol
261 && strcmp (S_GET_NAME (exp
->X_add_symbol
),
262 GLOBAL_OFFSET_TABLE_NAME
) == 0)
263 sym
= exp
->X_add_symbol
;
264 e
->X_add_symbol
= sym
;
265 e
->X_op_symbol
= NULL
;
271 i386_intel_simplify_register (expressionS
*e
)
275 if (this_operand
< 0 || intel_state
.in_offset
)
277 as_bad (_("invalid use of register"));
281 if (e
->X_op
== O_register
)
282 reg_num
= e
->X_add_number
;
284 reg_num
= e
->X_md
- 1;
286 if (reg_num
< 0 || reg_num
>= (int) i386_regtab_size
)
288 as_bad (_("invalid register number"));
292 if (!intel_state
.in_bracket
)
294 if (i
.op
[this_operand
].regs
)
296 as_bad (_("invalid use of register"));
299 if (i386_regtab
[reg_num
].reg_type
.bitfield
.class == SReg
300 && i386_regtab
[reg_num
].reg_num
== RegFlat
)
302 as_bad (_("invalid use of pseudo-register"));
305 i
.op
[this_operand
].regs
= i386_regtab
+ reg_num
;
307 else if (!intel_state
.index
308 && (i386_regtab
[reg_num
].reg_type
.bitfield
.xmmword
309 || i386_regtab
[reg_num
].reg_type
.bitfield
.ymmword
310 || i386_regtab
[reg_num
].reg_type
.bitfield
.zmmword
311 || i386_regtab
[reg_num
].reg_num
== RegIZ
))
312 intel_state
.index
= i386_regtab
+ reg_num
;
313 else if (!intel_state
.base
&& !intel_state
.in_scale
)
314 intel_state
.base
= i386_regtab
+ reg_num
;
315 else if (!intel_state
.index
)
317 const insn_template
*t
= current_templates
->start
;
319 if (intel_state
.in_scale
320 || (t
->opcode_modifier
.opcodeprefix
== PREFIX_0XF3
321 && t
->opcode_modifier
.opcodespace
== SPACE_0F
322 && t
->base_opcode
== 0x1b /* bndmk */)
323 || (t
->opcode_modifier
.opcodeprefix
== PREFIX_NONE
324 && t
->opcode_modifier
.opcodespace
== SPACE_0F
325 && (t
->base_opcode
& ~1) == 0x1a /* bnd{ld,st}x */)
326 || i386_regtab
[reg_num
].reg_type
.bitfield
.baseindex
)
327 intel_state
.index
= i386_regtab
+ reg_num
;
330 /* Convert base to index and make ESP/RSP the base. */
331 intel_state
.index
= intel_state
.base
;
332 intel_state
.base
= i386_regtab
+ reg_num
;
337 /* esp is invalid as index */
338 intel_state
.index
= reg_eax
+ ESP_REG_NUM
;
343 static int i386_intel_simplify (expressionS
*);
345 static INLINE
int i386_intel_simplify_symbol(symbolS
*sym
)
347 int ret
= i386_intel_simplify (symbol_get_value_expression (sym
));
351 S_SET_SEGMENT(sym
, absolute_section
);
357 static int i386_intel_simplify (expressionS
*e
)
359 const reg_entry
*the_reg
= (this_operand
>= 0
360 ? i
.op
[this_operand
].regs
: NULL
);
361 const reg_entry
*base
= intel_state
.base
;
362 const reg_entry
*state_index
= intel_state
.index
;
373 if (!i386_intel_simplify_symbol (e
->X_add_symbol
)
374 || !i386_intel_check(the_reg
, intel_state
.base
,
378 if (!intel_state
.in_offset
)
379 ++intel_state
.in_bracket
;
380 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
381 if (!intel_state
.in_offset
)
382 --intel_state
.in_bracket
;
388 i386_intel_fold (e
, e
->X_op_symbol
);
392 intel_state
.has_offset
= 1;
393 ++intel_state
.in_offset
;
394 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
395 --intel_state
.in_offset
;
396 if (!ret
|| !i386_intel_check(the_reg
, base
, state_index
))
398 i386_intel_fold (e
, e
->X_add_symbol
);
405 case O_qword_ptr
: /* O_mmword_ptr */
407 case O_oword_ptr
: /* O_xmmword_ptr */
412 if (intel_state
.op_modifier
== O_absent
)
413 intel_state
.op_modifier
= e
->X_op
;
416 if (symbol_get_value_expression (e
->X_add_symbol
)->X_op
419 as_bad (_("invalid use of register"));
422 if (!i386_intel_simplify_symbol (e
->X_add_symbol
))
424 i386_intel_fold (e
, e
->X_add_symbol
);
428 if (symbol_get_value_expression (e
->X_op_symbol
)->X_op
431 as_bad (_("invalid use of register"));
434 if (!i386_intel_simplify_symbol (e
->X_op_symbol
)
435 || !i386_intel_check(the_reg
, intel_state
.base
,
438 if (!intel_state
.in_offset
)
440 if (!intel_state
.seg
)
441 intel_state
.seg
= e
->X_add_symbol
;
446 exp
.X_op
= O_full_ptr
;
447 exp
.X_add_symbol
= e
->X_add_symbol
;
448 exp
.X_op_symbol
= intel_state
.seg
;
449 intel_state
.seg
= make_expr_symbol (&exp
);
452 i386_intel_fold (e
, e
->X_op_symbol
);
456 if (this_operand
>= 0 && intel_state
.in_bracket
)
458 expressionS
*scale
= NULL
;
459 int has_index
= (intel_state
.index
!= NULL
);
461 if (!intel_state
.in_scale
++)
462 intel_state
.scale_factor
= 1;
464 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
465 if (ret
&& !has_index
&& intel_state
.index
)
466 scale
= symbol_get_value_expression (e
->X_op_symbol
);
469 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
470 if (ret
&& !scale
&& !has_index
&& intel_state
.index
)
471 scale
= symbol_get_value_expression (e
->X_add_symbol
);
475 resolve_expression (scale
);
476 if (scale
->X_op
!= O_constant
477 || intel_state
.index
->reg_type
.bitfield
.word
)
478 scale
->X_add_number
= 0;
479 intel_state
.scale_factor
*= scale
->X_add_number
;
482 --intel_state
.in_scale
;
486 if (!intel_state
.in_scale
)
487 switch (intel_state
.scale_factor
)
490 i
.log2_scale_factor
= 0;
493 i
.log2_scale_factor
= 1;
496 i
.log2_scale_factor
= 2;
499 i
.log2_scale_factor
= 3;
502 /* esp is invalid as index */
503 intel_state
.index
= reg_eax
+ ESP_REG_NUM
;
512 ret
= i386_intel_simplify_register (e
);
515 gas_assert (e
->X_add_number
< (unsigned short) -1);
516 e
->X_md
= (unsigned short) e
->X_add_number
+ 1;
517 e
->X_op
= O_constant
;
524 return i386_intel_simplify_register (e
);
530 && !i386_intel_simplify_symbol (e
->X_add_symbol
))
532 if (e
->X_op
== O_add
|| e
->X_op
== O_subtract
)
534 base
= intel_state
.base
;
535 state_index
= intel_state
.index
;
537 if (!i386_intel_check (the_reg
, base
, state_index
)
539 && !i386_intel_simplify_symbol (e
->X_op_symbol
))
540 || !i386_intel_check (the_reg
,
542 ? base
: intel_state
.base
),
544 ? state_index
: intel_state
.index
)))
549 if (this_operand
>= 0
550 && e
->X_op
== O_symbol
551 && !intel_state
.in_offset
)
553 segT seg
= S_GET_SEGMENT (e
->X_add_symbol
);
555 if (seg
!= absolute_section
556 && seg
!= reg_section
557 && seg
!= expr_section
)
558 intel_state
.is_mem
|= 2 - !intel_state
.in_bracket
;
564 int i386_need_index_operator (void)
566 return intel_syntax
< 0;
570 i386_intel_operand (char *operand_string
, int got_a_float
)
572 char *saved_input_line_pointer
, *buf
;
574 expressionS exp
, *expP
;
578 /* Handle vector immediates. */
579 if (RC_SAE_immediate (operand_string
))
582 /* Initialize state structure. */
583 intel_state
.op_modifier
= O_absent
;
584 intel_state
.is_mem
= 0;
585 intel_state
.is_indirect
= 0;
586 intel_state
.has_offset
= 0;
587 intel_state
.base
= NULL
;
588 intel_state
.index
= NULL
;
589 intel_state
.seg
= NULL
;
590 operand_type_set (&intel_state
.reloc_types
, ~0);
591 gas_assert (!intel_state
.in_offset
);
592 gas_assert (!intel_state
.in_bracket
);
593 gas_assert (!intel_state
.in_scale
);
595 saved_input_line_pointer
= input_line_pointer
;
596 input_line_pointer
= buf
= xstrdup (operand_string
);
599 memset (&exp
, 0, sizeof(exp
));
600 exp_seg
= expression (&exp
);
601 ret
= i386_intel_simplify (&exp
);
606 /* Handle vector operations. */
607 if (*input_line_pointer
== '{')
609 char *end
= check_VecOperations (input_line_pointer
, NULL
);
611 input_line_pointer
= end
;
616 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
619 as_bad (_("junk `%s' after expression"), input_line_pointer
);
622 else if (exp
.X_op
== O_illegal
|| exp
.X_op
== O_absent
)
625 as_bad (_("invalid expression"));
628 else if (!intel_state
.has_offset
629 && input_line_pointer
> buf
630 && *(input_line_pointer
- 1) == ']')
632 intel_state
.is_mem
|= 1;
633 intel_state
.is_indirect
= 1;
636 input_line_pointer
= saved_input_line_pointer
;
639 gas_assert (!intel_state
.in_offset
);
640 gas_assert (!intel_state
.in_bracket
);
641 gas_assert (!intel_state
.in_scale
);
646 if (intel_state
.op_modifier
!= O_absent
647 && (current_templates
->start
->opcode_modifier
.opcodespace
!= SPACE_BASE
648 || current_templates
->start
->base_opcode
!= 0x8d /* lea */))
650 i
.types
[this_operand
].bitfield
.unspecified
= 0;
652 switch (intel_state
.op_modifier
)
655 i
.types
[this_operand
].bitfield
.byte
= 1;
656 suffix
= BYTE_MNEM_SUFFIX
;
660 i
.types
[this_operand
].bitfield
.word
= 1;
661 if (got_a_float
== 2) /* "fi..." */
662 suffix
= SHORT_MNEM_SUFFIX
;
664 suffix
= WORD_MNEM_SUFFIX
;
668 i
.types
[this_operand
].bitfield
.dword
= 1;
669 if ((current_templates
->start
->name
[0] == 'l'
670 && current_templates
->start
->name
[2] == 's'
671 && current_templates
->start
->name
[3] == 0)
672 || (current_templates
->start
->opcode_modifier
.opcodespace
== SPACE_BASE
673 && current_templates
->start
->base_opcode
== 0x62 /* bound */))
674 suffix
= WORD_MNEM_SUFFIX
;
675 else if (flag_code
!= CODE_32BIT
676 && (current_templates
->start
->opcode_modifier
.jump
== JUMP
677 || current_templates
->start
->opcode_modifier
.jump
679 suffix
= flag_code
== CODE_16BIT
? LONG_DOUBLE_MNEM_SUFFIX
681 else if (got_a_float
== 1) /* "f..." */
682 suffix
= SHORT_MNEM_SUFFIX
;
684 suffix
= LONG_MNEM_SUFFIX
;
688 i
.types
[this_operand
].bitfield
.fword
= 1;
689 if (current_templates
->start
->name
[0] == 'l'
690 && current_templates
->start
->name
[2] == 's'
691 && current_templates
->start
->name
[3] == 0)
692 suffix
= LONG_MNEM_SUFFIX
;
693 else if (!got_a_float
)
695 if (flag_code
== CODE_16BIT
)
696 add_prefix (DATA_PREFIX_OPCODE
);
697 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
701 case O_qword_ptr
: /* O_mmword_ptr */
702 i
.types
[this_operand
].bitfield
.qword
= 1;
703 if ((current_templates
->start
->opcode_modifier
.opcodespace
== SPACE_BASE
704 && current_templates
->start
->base_opcode
== 0x62 /* bound */)
705 || got_a_float
== 1) /* "f..." */
706 suffix
= LONG_MNEM_SUFFIX
;
708 suffix
= QWORD_MNEM_SUFFIX
;
712 i
.types
[this_operand
].bitfield
.tbyte
= 1;
713 if (got_a_float
== 1)
714 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
715 else if ((current_templates
->start
->operand_types
[0].bitfield
.fword
716 || current_templates
->start
->operand_types
[0].bitfield
.tbyte
717 || current_templates
->start
->opcode_modifier
.jump
== JUMP_DWORD
718 || current_templates
->start
->opcode_modifier
.jump
== JUMP
)
719 && flag_code
== CODE_64BIT
)
720 suffix
= QWORD_MNEM_SUFFIX
; /* l[fgs]s, [ls][gi]dt, call, jmp */
722 i
.types
[this_operand
].bitfield
.byte
= 1; /* cause an error */
725 case O_oword_ptr
: /* O_xmmword_ptr */
726 i
.types
[this_operand
].bitfield
.xmmword
= 1;
730 i
.types
[this_operand
].bitfield
.ymmword
= 1;
734 i
.types
[this_operand
].bitfield
.zmmword
= 1;
738 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
741 if (current_templates
->start
->opcode_modifier
.jump
!= JUMP
742 && current_templates
->start
->opcode_modifier
.jump
!= JUMP_DWORD
)
745 i
.types
[this_operand
].bitfield
.byte
= 1;
746 i
.types
[this_operand
].bitfield
.tbyte
= 1;
752 BAD_CASE (intel_state
.op_modifier
);
758 else if (i
.suffix
!= suffix
)
760 as_bad (_("conflicting operand size modifiers"));
765 /* Operands for jump/call need special consideration. */
766 if (current_templates
->start
->opcode_modifier
.jump
== JUMP
767 || current_templates
->start
->opcode_modifier
.jump
== JUMP_DWORD
768 || current_templates
->start
->opcode_modifier
.jump
== JUMP_INTERSEGMENT
)
770 bfd_boolean jumpabsolute
= FALSE
;
772 if (i
.op
[this_operand
].regs
775 || intel_state
.is_mem
> 1)
778 switch (intel_state
.op_modifier
)
784 intel_state
.is_mem
= 1;
788 if (!intel_state
.seg
)
790 intel_state
.is_mem
= 1;
791 if (intel_state
.op_modifier
== O_absent
)
793 if (intel_state
.is_indirect
== 1)
797 as_bad (_("cannot infer the segment part of the operand"));
800 else if (S_GET_SEGMENT (intel_state
.seg
) == reg_section
)
804 i386_operand_type types
;
806 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
808 as_bad (_("at most %d immediate operands are allowed"),
809 MAX_IMMEDIATE_OPERANDS
);
812 expP
= &im_expressions
[i
.imm_operands
++];
813 memset (expP
, 0, sizeof(*expP
));
814 expP
->X_op
= O_symbol
;
815 expP
->X_add_symbol
= intel_state
.seg
;
816 i
.op
[this_operand
].imms
= expP
;
818 resolve_expression (expP
);
819 operand_type_set (&types
, ~0);
820 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state
.seg
),
821 expP
, types
, operand_string
))
823 if (i
.operands
< MAX_OPERANDS
)
825 this_operand
= i
.operands
++;
826 i
.types
[this_operand
].bitfield
.unspecified
= 1;
828 if (suffix
== LONG_DOUBLE_MNEM_SUFFIX
)
830 intel_state
.seg
= NULL
;
831 intel_state
.is_mem
= 0;
840 i
.jumpabsolute
= TRUE
;
841 intel_state
.is_mem
|= 1;
844 else if (intel_state
.seg
)
845 intel_state
.is_mem
|= 1;
847 if (i
.op
[this_operand
].regs
)
849 i386_operand_type temp
;
851 /* Register operand. */
852 if (intel_state
.base
|| intel_state
.index
|| intel_state
.seg
)
854 as_bad (_("invalid operand"));
858 temp
= i
.op
[this_operand
].regs
->reg_type
;
859 temp
.bitfield
.baseindex
= 0;
860 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
862 i
.types
[this_operand
].bitfield
.unspecified
= 0;
865 else if (intel_state
.base
868 || intel_state
.is_mem
)
870 /* Memory operand. */
871 if (i
.mem_operands
== 1 && !maybe_adjust_templates ())
873 if ((int) i
.mem_operands
874 >= 2 - !current_templates
->start
->opcode_modifier
.isstring
)
878 call 0x9090,0x90909090
879 lcall 0x9090,0x90909090
880 jmp 0x9090,0x90909090
881 ljmp 0x9090,0x90909090
884 if ((current_templates
->start
->opcode_modifier
.jump
== JUMP_INTERSEGMENT
885 || current_templates
->start
->opcode_modifier
.jump
== JUMP_DWORD
886 || current_templates
->start
->opcode_modifier
.jump
== JUMP
)
888 && intel_state
.seg
== NULL
889 && i
.mem_operands
== 1
890 && i
.disp_operands
== 1
891 && intel_state
.op_modifier
== O_absent
)
893 /* Try to process the first operand as immediate, */
895 if (i386_finalize_immediate (exp_seg
, i
.op
[0].imms
,
896 intel_state
.reloc_types
,
900 expP
= &im_expressions
[0];
901 i
.op
[this_operand
].imms
= expP
;
904 /* Try to process the second operand as immediate, */
905 if (i386_finalize_immediate (exp_seg
, expP
,
906 intel_state
.reloc_types
,
912 i
.flags
[0] &= ~Operand_Mem
;
913 i
.types
[0].bitfield
.disp16
= 0;
914 i
.types
[0].bitfield
.disp32
= 0;
915 i
.types
[0].bitfield
.disp32s
= 0;
921 as_bad (_("too many memory references for `%s'"),
922 current_templates
->start
->name
);
926 /* Swap base and index in 16-bit memory operands like
927 [si+bx]. Since i386_index_check is also used in AT&T
928 mode we have to do this here. */
931 && intel_state
.base
->reg_type
.bitfield
.word
932 && intel_state
.index
->reg_type
.bitfield
.word
933 && intel_state
.base
->reg_num
>= 6
934 && intel_state
.index
->reg_num
< 6)
936 i
.base_reg
= intel_state
.index
;
937 i
.index_reg
= intel_state
.base
;
941 i
.base_reg
= intel_state
.base
;
942 i
.index_reg
= intel_state
.index
;
945 if (i
.base_reg
|| i
.index_reg
)
946 i
.types
[this_operand
].bitfield
.baseindex
= 1;
948 expP
= &disp_expressions
[i
.disp_operands
];
949 memcpy (expP
, &exp
, sizeof(exp
));
950 resolve_expression (expP
);
952 if (expP
->X_op
!= O_constant
953 || expP
->X_add_number
954 || !i
.types
[this_operand
].bitfield
.baseindex
)
956 i
.op
[this_operand
].disps
= expP
;
959 i386_addressing_mode ();
961 if (flag_code
== CODE_64BIT
)
963 if (!i
.prefix
[ADDR_PREFIX
])
965 i
.types
[this_operand
].bitfield
.disp64
= 1;
966 i
.types
[this_operand
].bitfield
.disp32s
= 1;
969 i
.types
[this_operand
].bitfield
.disp32
= 1;
971 else if (!i
.prefix
[ADDR_PREFIX
] ^ (flag_code
== CODE_16BIT
))
972 i
.types
[this_operand
].bitfield
.disp32
= 1;
974 i
.types
[this_operand
].bitfield
.disp16
= 1;
976 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
978 * exp_seg is used only for verification in
979 * i386_finalize_displacement, and we can end up seeing reg_section
980 * here - but we know we removed all registers from the expression
981 * (or error-ed on any remaining ones) in i386_intel_simplify. I
982 * consider the check in i386_finalize_displacement bogus anyway, in
983 * particular because it doesn't allow for expr_section, so I'd
984 * rather see that check (and the similar one in
985 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
986 * expert I can't really say whether that would have other bad side
989 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
990 && exp_seg
== reg_section
)
991 exp_seg
= expP
->X_op
!= O_constant
? undefined_section
995 if (!i386_finalize_displacement (exp_seg
, expP
,
996 intel_state
.reloc_types
,
1001 if (intel_state
.seg
)
1003 for (ret
= check_none
; ; ret
= operand_check
)
1005 expP
= symbol_get_value_expression (intel_state
.seg
);
1006 if (expP
->X_op
!= O_full_ptr
1007 || symbol_get_value_expression (expP
->X_op_symbol
)->X_op
1010 intel_state
.seg
= expP
->X_add_symbol
;
1012 if (expP
->X_op
!= O_register
)
1014 as_bad (_("segment register name expected"));
1017 if (i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.class != SReg
)
1019 as_bad (_("invalid use of register"));
1025 as_bad (_("redundant segment overrides"));
1028 as_warn (_("redundant segment overrides"));
1031 switch (i386_regtab
[expP
->X_add_number
].reg_num
)
1033 case 0: i
.seg
[i
.mem_operands
] = &es
; break;
1034 case 1: i
.seg
[i
.mem_operands
] = &cs
; break;
1035 case 2: i
.seg
[i
.mem_operands
] = &ss
; break;
1036 case 3: i
.seg
[i
.mem_operands
] = &ds
; break;
1037 case 4: i
.seg
[i
.mem_operands
] = &fs
; break;
1038 case 5: i
.seg
[i
.mem_operands
] = &gs
; break;
1039 case RegFlat
: i
.seg
[i
.mem_operands
] = NULL
; break;
1043 if (!i386_index_check (operand_string
))
1046 i
.flags
[this_operand
] |= Operand_Mem
;
1047 if (i
.mem_operands
== 0)
1048 i
.memop1_string
= xstrdup (operand_string
);
1054 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
1056 as_bad (_("at most %d immediate operands are allowed"),
1057 MAX_IMMEDIATE_OPERANDS
);
1061 expP
= &im_expressions
[i
.imm_operands
++];
1062 i
.op
[this_operand
].imms
= expP
;
1065 return i386_finalize_immediate (exp_seg
, expP
, intel_state
.reloc_types
,