1 /* tc-i386.c -- Assemble Intel syntax code for ix86/x86-64
2 Copyright (C) 2009-2020 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
)
133 switch (*input_line_pointer
)
136 ++input_line_pointer
;
139 ++input_line_pointer
;
142 if (this_operand
>= 0 && i
.reloc
[this_operand
] == NO_RELOC
)
145 char *gotfree_input_line
= lex_got (&i
.reloc
[this_operand
],
147 &intel_state
.reloc_types
);
149 if (!gotfree_input_line
)
151 free (gotfree_input_line
);
152 *input_line_pointer
++ = '+';
153 memset (input_line_pointer
, '0', adjust
- 1);
154 input_line_pointer
[adjust
- 1] = ' ';
162 for (j
= 0; i386_operators
[j
].name
; ++j
)
163 if (strcasecmp (i386_operators
[j
].name
, name
) == 0)
165 if (i386_operators
[j
].operands
166 && i386_operators
[j
].operands
!= operands
)
168 return i386_operators
[j
].op
;
171 for (j
= 0; i386_types
[j
].name
; ++j
)
172 if (strcasecmp (i386_types
[j
].name
, name
) == 0)
175 if (i386_types
[j
].name
&& *pc
== ' ')
180 ++input_line_pointer
;
181 c
= get_symbol_name (&pname
);
183 if (strcasecmp (pname
, "ptr") == 0)
185 /* FIXME: What if c == '"' ? */
188 if (intel_syntax
> 0 || operands
!= 1)
190 return i386_types
[j
].op
;
193 (void) restore_line_pointer (c
);
194 input_line_pointer
= pname
- 1;
200 static int i386_intel_parse_name (const char *name
, expressionS
*e
)
204 if (! strcmp (name
, "$"))
206 current_location (e
);
210 for (j
= 0; i386_types
[j
].name
; ++j
)
211 if (strcasecmp(i386_types
[j
].name
, name
) == 0)
213 e
->X_op
= O_constant
;
214 e
->X_add_number
= i386_types
[j
].sz
[flag_code
];
215 e
->X_add_symbol
= NULL
;
216 e
->X_op_symbol
= NULL
;
223 static INLINE
int i386_intel_check (const reg_entry
*rreg
,
224 const reg_entry
*base
,
225 const reg_entry
*iindex
)
227 if ((this_operand
>= 0
228 && rreg
!= i
.op
[this_operand
].regs
)
229 || base
!= intel_state
.base
230 || iindex
!= intel_state
.index
)
232 as_bad (_("invalid use of register"));
238 static INLINE
void i386_intel_fold (expressionS
*e
, symbolS
*sym
)
240 expressionS
*exp
= symbol_get_value_expression (sym
);
241 if (S_GET_SEGMENT (sym
) == absolute_section
)
243 offsetT val
= e
->X_add_number
;
246 e
->X_add_number
+= val
;
250 if (exp
->X_op
== O_symbol
251 && strcmp (S_GET_NAME (exp
->X_add_symbol
),
252 GLOBAL_OFFSET_TABLE_NAME
) == 0)
253 sym
= exp
->X_add_symbol
;
254 e
->X_add_symbol
= sym
;
255 e
->X_op_symbol
= NULL
;
261 i386_intel_simplify_register (expressionS
*e
)
265 if (this_operand
< 0 || intel_state
.in_offset
)
267 as_bad (_("invalid use of register"));
271 if (e
->X_op
== O_register
)
272 reg_num
= e
->X_add_number
;
274 reg_num
= e
->X_md
- 1;
276 if (reg_num
< 0 || reg_num
>= (int) i386_regtab_size
)
278 as_bad (_("invalid register number"));
282 if (!intel_state
.in_bracket
)
284 if (i
.op
[this_operand
].regs
)
286 as_bad (_("invalid use of register"));
289 if (i386_regtab
[reg_num
].reg_type
.bitfield
.class == SReg
290 && i386_regtab
[reg_num
].reg_num
== RegFlat
)
292 as_bad (_("invalid use of pseudo-register"));
295 i
.op
[this_operand
].regs
= i386_regtab
+ reg_num
;
297 else if (!intel_state
.index
298 && (i386_regtab
[reg_num
].reg_type
.bitfield
.xmmword
299 || i386_regtab
[reg_num
].reg_type
.bitfield
.ymmword
300 || i386_regtab
[reg_num
].reg_type
.bitfield
.zmmword
301 || i386_regtab
[reg_num
].reg_num
== RegIZ
))
302 intel_state
.index
= i386_regtab
+ reg_num
;
303 else if (!intel_state
.base
&& !intel_state
.in_scale
)
304 intel_state
.base
= i386_regtab
+ reg_num
;
305 else if (!intel_state
.index
)
307 if (intel_state
.in_scale
308 || current_templates
->start
->base_opcode
== 0xf30f1b /* bndmk */
309 || (current_templates
->start
->base_opcode
& ~1) == 0x0f1a /* bnd{ld,st}x */
310 || i386_regtab
[reg_num
].reg_type
.bitfield
.baseindex
)
311 intel_state
.index
= i386_regtab
+ reg_num
;
314 /* Convert base to index and make ESP/RSP the base. */
315 intel_state
.index
= intel_state
.base
;
316 intel_state
.base
= i386_regtab
+ reg_num
;
321 /* esp is invalid as index */
322 intel_state
.index
= i386_regtab
+ REGNAM_EAX
+ ESP_REG_NUM
;
327 static int i386_intel_simplify (expressionS
*);
329 static INLINE
int i386_intel_simplify_symbol(symbolS
*sym
)
331 int ret
= i386_intel_simplify (symbol_get_value_expression (sym
));
335 S_SET_SEGMENT(sym
, absolute_section
);
341 static int i386_intel_simplify (expressionS
*e
)
343 const reg_entry
*the_reg
= (this_operand
>= 0
344 ? i
.op
[this_operand
].regs
: NULL
);
345 const reg_entry
*base
= intel_state
.base
;
346 const reg_entry
*state_index
= intel_state
.index
;
357 if (!i386_intel_simplify_symbol (e
->X_add_symbol
)
358 || !i386_intel_check(the_reg
, intel_state
.base
,
362 if (!intel_state
.in_offset
)
363 ++intel_state
.in_bracket
;
364 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
365 if (!intel_state
.in_offset
)
366 --intel_state
.in_bracket
;
372 i386_intel_fold (e
, e
->X_op_symbol
);
376 intel_state
.has_offset
= 1;
377 ++intel_state
.in_offset
;
378 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
379 --intel_state
.in_offset
;
380 if (!ret
|| !i386_intel_check(the_reg
, base
, state_index
))
382 i386_intel_fold (e
, e
->X_add_symbol
);
389 case O_qword_ptr
: /* O_mmword_ptr */
391 case O_oword_ptr
: /* O_xmmword_ptr */
396 if (intel_state
.op_modifier
== O_absent
)
397 intel_state
.op_modifier
= e
->X_op
;
400 if (symbol_get_value_expression (e
->X_add_symbol
)->X_op
403 as_bad (_("invalid use of register"));
406 if (!i386_intel_simplify_symbol (e
->X_add_symbol
))
408 i386_intel_fold (e
, e
->X_add_symbol
);
412 if (symbol_get_value_expression (e
->X_op_symbol
)->X_op
415 as_bad (_("invalid use of register"));
418 if (!i386_intel_simplify_symbol (e
->X_op_symbol
)
419 || !i386_intel_check(the_reg
, intel_state
.base
,
422 if (!intel_state
.in_offset
)
424 if (!intel_state
.seg
)
425 intel_state
.seg
= e
->X_add_symbol
;
430 exp
.X_op
= O_full_ptr
;
431 exp
.X_add_symbol
= e
->X_add_symbol
;
432 exp
.X_op_symbol
= intel_state
.seg
;
433 intel_state
.seg
= make_expr_symbol (&exp
);
436 i386_intel_fold (e
, e
->X_op_symbol
);
440 if (this_operand
>= 0 && intel_state
.in_bracket
)
442 expressionS
*scale
= NULL
;
443 int has_index
= (intel_state
.index
!= NULL
);
445 if (!intel_state
.in_scale
++)
446 intel_state
.scale_factor
= 1;
448 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
449 if (ret
&& !has_index
&& intel_state
.index
)
450 scale
= symbol_get_value_expression (e
->X_op_symbol
);
453 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
454 if (ret
&& !scale
&& !has_index
&& intel_state
.index
)
455 scale
= symbol_get_value_expression (e
->X_add_symbol
);
459 resolve_expression (scale
);
460 if (scale
->X_op
!= O_constant
461 || intel_state
.index
->reg_type
.bitfield
.word
)
462 scale
->X_add_number
= 0;
463 intel_state
.scale_factor
*= scale
->X_add_number
;
466 --intel_state
.in_scale
;
470 if (!intel_state
.in_scale
)
471 switch (intel_state
.scale_factor
)
474 i
.log2_scale_factor
= 0;
477 i
.log2_scale_factor
= 1;
480 i
.log2_scale_factor
= 2;
483 i
.log2_scale_factor
= 3;
486 /* esp is invalid as index */
487 intel_state
.index
= i386_regtab
+ REGNAM_EAX
+ ESP_REG_NUM
;
496 ret
= i386_intel_simplify_register (e
);
499 gas_assert (e
->X_add_number
< (unsigned short) -1);
500 e
->X_md
= (unsigned short) e
->X_add_number
+ 1;
501 e
->X_op
= O_constant
;
508 return i386_intel_simplify_register (e
);
514 && !i386_intel_simplify_symbol (e
->X_add_symbol
))
516 if (e
->X_op
== O_add
|| e
->X_op
== O_subtract
)
518 base
= intel_state
.base
;
519 state_index
= intel_state
.index
;
521 if (!i386_intel_check (the_reg
, base
, state_index
)
523 && !i386_intel_simplify_symbol (e
->X_op_symbol
))
524 || !i386_intel_check (the_reg
,
526 ? base
: intel_state
.base
),
528 ? state_index
: intel_state
.index
)))
533 if (this_operand
>= 0
534 && e
->X_op
== O_symbol
535 && !intel_state
.in_offset
)
537 segT seg
= S_GET_SEGMENT (e
->X_add_symbol
);
539 if (seg
!= absolute_section
540 && seg
!= reg_section
541 && seg
!= expr_section
)
542 intel_state
.is_mem
|= 2 - !intel_state
.in_bracket
;
548 int i386_need_index_operator (void)
550 return intel_syntax
< 0;
554 i386_intel_operand (char *operand_string
, int got_a_float
)
556 char *saved_input_line_pointer
, *buf
;
558 expressionS exp
, *expP
;
562 /* Handle vector immediates. */
563 if (RC_SAE_immediate (operand_string
))
566 /* Initialize state structure. */
567 intel_state
.op_modifier
= O_absent
;
568 intel_state
.is_mem
= 0;
569 intel_state
.is_indirect
= 0;
570 intel_state
.has_offset
= 0;
571 intel_state
.base
= NULL
;
572 intel_state
.index
= NULL
;
573 intel_state
.seg
= NULL
;
574 operand_type_set (&intel_state
.reloc_types
, ~0);
575 gas_assert (!intel_state
.in_offset
);
576 gas_assert (!intel_state
.in_bracket
);
577 gas_assert (!intel_state
.in_scale
);
579 saved_input_line_pointer
= input_line_pointer
;
580 input_line_pointer
= buf
= xstrdup (operand_string
);
583 memset (&exp
, 0, sizeof(exp
));
584 exp_seg
= expression (&exp
);
585 ret
= i386_intel_simplify (&exp
);
590 /* Handle vector operations. */
591 if (*input_line_pointer
== '{')
593 char *end
= check_VecOperations (input_line_pointer
, NULL
);
595 input_line_pointer
= end
;
600 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
603 as_bad (_("junk `%s' after expression"), input_line_pointer
);
606 else if (exp
.X_op
== O_illegal
|| exp
.X_op
== O_absent
)
609 as_bad (_("invalid expression"));
612 else if (!intel_state
.has_offset
613 && input_line_pointer
> buf
614 && *(input_line_pointer
- 1) == ']')
616 intel_state
.is_mem
|= 1;
617 intel_state
.is_indirect
= 1;
620 input_line_pointer
= saved_input_line_pointer
;
623 gas_assert (!intel_state
.in_offset
);
624 gas_assert (!intel_state
.in_bracket
);
625 gas_assert (!intel_state
.in_scale
);
630 if (intel_state
.op_modifier
!= O_absent
631 && current_templates
->start
->base_opcode
!= 0x8d /* lea */)
633 i
.types
[this_operand
].bitfield
.unspecified
= 0;
635 switch (intel_state
.op_modifier
)
638 i
.types
[this_operand
].bitfield
.byte
= 1;
639 suffix
= BYTE_MNEM_SUFFIX
;
643 i
.types
[this_operand
].bitfield
.word
= 1;
644 if (got_a_float
== 2) /* "fi..." */
645 suffix
= SHORT_MNEM_SUFFIX
;
647 suffix
= WORD_MNEM_SUFFIX
;
651 i
.types
[this_operand
].bitfield
.dword
= 1;
652 if ((current_templates
->start
->name
[0] == 'l'
653 && current_templates
->start
->name
[2] == 's'
654 && current_templates
->start
->name
[3] == 0)
655 || current_templates
->start
->base_opcode
== 0x62 /* bound */)
656 suffix
= WORD_MNEM_SUFFIX
;
657 else if (flag_code
!= CODE_32BIT
658 && (current_templates
->start
->opcode_modifier
.jump
== JUMP
659 || current_templates
->start
->opcode_modifier
.jump
661 suffix
= flag_code
== CODE_16BIT
? LONG_DOUBLE_MNEM_SUFFIX
663 else if (got_a_float
== 1) /* "f..." */
664 suffix
= SHORT_MNEM_SUFFIX
;
666 suffix
= LONG_MNEM_SUFFIX
;
670 i
.types
[this_operand
].bitfield
.fword
= 1;
671 if (current_templates
->start
->name
[0] == 'l'
672 && current_templates
->start
->name
[2] == 's'
673 && current_templates
->start
->name
[3] == 0)
674 suffix
= LONG_MNEM_SUFFIX
;
675 else if (!got_a_float
)
677 if (flag_code
== CODE_16BIT
)
678 add_prefix (DATA_PREFIX_OPCODE
);
679 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
683 case O_qword_ptr
: /* O_mmword_ptr */
684 i
.types
[this_operand
].bitfield
.qword
= 1;
685 if (current_templates
->start
->base_opcode
== 0x62 /* bound */
686 || got_a_float
== 1) /* "f..." */
687 suffix
= LONG_MNEM_SUFFIX
;
689 suffix
= QWORD_MNEM_SUFFIX
;
693 i
.types
[this_operand
].bitfield
.tbyte
= 1;
694 if (got_a_float
== 1)
695 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
696 else if ((current_templates
->start
->operand_types
[0].bitfield
.fword
697 || current_templates
->start
->operand_types
[0].bitfield
.tbyte
698 || current_templates
->start
->opcode_modifier
.jump
== JUMP_DWORD
699 || current_templates
->start
->opcode_modifier
.jump
== JUMP
)
700 && flag_code
== CODE_64BIT
)
701 suffix
= QWORD_MNEM_SUFFIX
; /* l[fgs]s, [ls][gi]dt, call, jmp */
703 i
.types
[this_operand
].bitfield
.byte
= 1; /* cause an error */
706 case O_oword_ptr
: /* O_xmmword_ptr */
707 i
.types
[this_operand
].bitfield
.xmmword
= 1;
711 i
.types
[this_operand
].bitfield
.ymmword
= 1;
715 i
.types
[this_operand
].bitfield
.zmmword
= 1;
719 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
722 if (current_templates
->start
->opcode_modifier
.jump
!= JUMP
723 && current_templates
->start
->opcode_modifier
.jump
!= JUMP_DWORD
)
726 i
.types
[this_operand
].bitfield
.byte
= 1;
727 i
.types
[this_operand
].bitfield
.tbyte
= 1;
733 BAD_CASE (intel_state
.op_modifier
);
739 else if (i
.suffix
!= suffix
)
741 as_bad (_("conflicting operand size modifiers"));
746 /* Operands for jump/call need special consideration. */
747 if (current_templates
->start
->opcode_modifier
.jump
== JUMP
748 || current_templates
->start
->opcode_modifier
.jump
== JUMP_DWORD
749 || current_templates
->start
->opcode_modifier
.jump
== JUMP_INTERSEGMENT
)
751 bfd_boolean jumpabsolute
= FALSE
;
753 if (i
.op
[this_operand
].regs
756 || intel_state
.is_mem
> 1)
759 switch (intel_state
.op_modifier
)
765 intel_state
.is_mem
= 1;
769 if (!intel_state
.seg
)
771 intel_state
.is_mem
= 1;
772 if (intel_state
.op_modifier
== O_absent
)
774 if (intel_state
.is_indirect
== 1)
778 as_bad (_("cannot infer the segment part of the operand"));
781 else if (S_GET_SEGMENT (intel_state
.seg
) == reg_section
)
785 i386_operand_type types
;
787 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
789 as_bad (_("at most %d immediate operands are allowed"),
790 MAX_IMMEDIATE_OPERANDS
);
793 expP
= &im_expressions
[i
.imm_operands
++];
794 memset (expP
, 0, sizeof(*expP
));
795 expP
->X_op
= O_symbol
;
796 expP
->X_add_symbol
= intel_state
.seg
;
797 i
.op
[this_operand
].imms
= expP
;
799 resolve_expression (expP
);
800 operand_type_set (&types
, ~0);
801 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state
.seg
),
802 expP
, types
, operand_string
))
804 if (i
.operands
< MAX_OPERANDS
)
806 this_operand
= i
.operands
++;
807 i
.types
[this_operand
].bitfield
.unspecified
= 1;
809 if (suffix
== LONG_DOUBLE_MNEM_SUFFIX
)
811 intel_state
.seg
= NULL
;
812 intel_state
.is_mem
= 0;
821 i
.jumpabsolute
= TRUE
;
822 intel_state
.is_mem
|= 1;
825 else if (intel_state
.seg
)
826 intel_state
.is_mem
|= 1;
828 if (i
.op
[this_operand
].regs
)
830 i386_operand_type temp
;
832 /* Register operand. */
833 if (intel_state
.base
|| intel_state
.index
|| intel_state
.seg
)
835 as_bad (_("invalid operand"));
839 temp
= i
.op
[this_operand
].regs
->reg_type
;
840 temp
.bitfield
.baseindex
= 0;
841 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
843 i
.types
[this_operand
].bitfield
.unspecified
= 0;
846 else if (intel_state
.base
849 || intel_state
.is_mem
)
851 /* Memory operand. */
852 if (i
.mem_operands
== 1 && !maybe_adjust_templates ())
854 if ((int) i
.mem_operands
855 >= 2 - !current_templates
->start
->opcode_modifier
.isstring
)
859 call 0x9090,0x90909090
860 lcall 0x9090,0x90909090
861 jmp 0x9090,0x90909090
862 ljmp 0x9090,0x90909090
865 if ((current_templates
->start
->opcode_modifier
.jump
== JUMP_INTERSEGMENT
866 || current_templates
->start
->opcode_modifier
.jump
== JUMP_DWORD
867 || current_templates
->start
->opcode_modifier
.jump
== JUMP
)
869 && intel_state
.seg
== NULL
870 && i
.mem_operands
== 1
871 && i
.disp_operands
== 1
872 && intel_state
.op_modifier
== O_absent
)
874 /* Try to process the first operand as immediate, */
876 if (i386_finalize_immediate (exp_seg
, i
.op
[0].imms
,
877 intel_state
.reloc_types
,
881 expP
= &im_expressions
[0];
882 i
.op
[this_operand
].imms
= expP
;
885 /* Try to process the second operand as immediate, */
886 if (i386_finalize_immediate (exp_seg
, expP
,
887 intel_state
.reloc_types
,
893 i
.flags
[0] &= ~Operand_Mem
;
894 i
.types
[0].bitfield
.disp16
= 0;
895 i
.types
[0].bitfield
.disp32
= 0;
896 i
.types
[0].bitfield
.disp32s
= 0;
902 as_bad (_("too many memory references for `%s'"),
903 current_templates
->start
->name
);
907 /* Swap base and index in 16-bit memory operands like
908 [si+bx]. Since i386_index_check is also used in AT&T
909 mode we have to do this here. */
912 && intel_state
.base
->reg_type
.bitfield
.word
913 && intel_state
.index
->reg_type
.bitfield
.word
914 && intel_state
.base
->reg_num
>= 6
915 && intel_state
.index
->reg_num
< 6)
917 i
.base_reg
= intel_state
.index
;
918 i
.index_reg
= intel_state
.base
;
922 i
.base_reg
= intel_state
.base
;
923 i
.index_reg
= intel_state
.index
;
926 if (i
.base_reg
|| i
.index_reg
)
927 i
.types
[this_operand
].bitfield
.baseindex
= 1;
929 expP
= &disp_expressions
[i
.disp_operands
];
930 memcpy (expP
, &exp
, sizeof(exp
));
931 resolve_expression (expP
);
933 if (expP
->X_op
!= O_constant
934 || expP
->X_add_number
935 || !i
.types
[this_operand
].bitfield
.baseindex
)
937 i
.op
[this_operand
].disps
= expP
;
940 i386_addressing_mode ();
942 if (flag_code
== CODE_64BIT
)
944 if (!i
.prefix
[ADDR_PREFIX
])
946 i
.types
[this_operand
].bitfield
.disp64
= 1;
947 i
.types
[this_operand
].bitfield
.disp32s
= 1;
950 i
.types
[this_operand
].bitfield
.disp32
= 1;
952 else if (!i
.prefix
[ADDR_PREFIX
] ^ (flag_code
== CODE_16BIT
))
953 i
.types
[this_operand
].bitfield
.disp32
= 1;
955 i
.types
[this_operand
].bitfield
.disp16
= 1;
957 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
959 * exp_seg is used only for verification in
960 * i386_finalize_displacement, and we can end up seeing reg_section
961 * here - but we know we removed all registers from the expression
962 * (or error-ed on any remaining ones) in i386_intel_simplify. I
963 * consider the check in i386_finalize_displacement bogus anyway, in
964 * particular because it doesn't allow for expr_section, so I'd
965 * rather see that check (and the similar one in
966 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
967 * expert I can't really say whether that would have other bad side
970 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
971 && exp_seg
== reg_section
)
972 exp_seg
= expP
->X_op
!= O_constant
? undefined_section
976 if (!i386_finalize_displacement (exp_seg
, expP
,
977 intel_state
.reloc_types
,
984 for (ret
= check_none
; ; ret
= operand_check
)
986 expP
= symbol_get_value_expression (intel_state
.seg
);
987 if (expP
->X_op
!= O_full_ptr
988 || symbol_get_value_expression (expP
->X_op_symbol
)->X_op
991 intel_state
.seg
= expP
->X_add_symbol
;
993 if (expP
->X_op
!= O_register
)
995 as_bad (_("segment register name expected"));
998 if (i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.class != SReg
)
1000 as_bad (_("invalid use of register"));
1006 as_bad (_("redundant segment overrides"));
1009 as_warn (_("redundant segment overrides"));
1012 switch (i386_regtab
[expP
->X_add_number
].reg_num
)
1014 case 0: i
.seg
[i
.mem_operands
] = &es
; break;
1015 case 1: i
.seg
[i
.mem_operands
] = &cs
; break;
1016 case 2: i
.seg
[i
.mem_operands
] = &ss
; break;
1017 case 3: i
.seg
[i
.mem_operands
] = &ds
; break;
1018 case 4: i
.seg
[i
.mem_operands
] = &fs
; break;
1019 case 5: i
.seg
[i
.mem_operands
] = &gs
; break;
1020 case RegFlat
: i
.seg
[i
.mem_operands
] = NULL
; break;
1024 if (!i386_index_check (operand_string
))
1027 i
.flags
[this_operand
] |= Operand_Mem
;
1028 if (i
.mem_operands
== 0)
1029 i
.memop1_string
= xstrdup (operand_string
);
1035 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
1037 as_bad (_("at most %d immediate operands are allowed"),
1038 MAX_IMMEDIATE_OPERANDS
);
1042 expP
= &im_expressions
[i
.imm_operands
++];
1043 i
.op
[this_operand
].imms
= expP
;
1046 return i386_finalize_immediate (exp_seg
, expP
, intel_state
.reloc_types
,