1 /* tc-i386.c -- Assemble Intel syntax code for ix86/x86-64
2 Copyright (C) 2009-2019 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 && flag_code
== CODE_64BIT
)
699 suffix
= QWORD_MNEM_SUFFIX
; /* l[fgs]s, [ls][gi]dt */
701 i
.types
[this_operand
].bitfield
.byte
= 1; /* cause an error */
704 case O_oword_ptr
: /* O_xmmword_ptr */
705 i
.types
[this_operand
].bitfield
.xmmword
= 1;
709 i
.types
[this_operand
].bitfield
.ymmword
= 1;
713 i
.types
[this_operand
].bitfield
.zmmword
= 1;
717 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
720 if (current_templates
->start
->opcode_modifier
.jump
!= JUMP
721 && current_templates
->start
->opcode_modifier
.jump
!= JUMP_DWORD
)
724 i
.types
[this_operand
].bitfield
.byte
= 1;
725 i
.types
[this_operand
].bitfield
.tbyte
= 1;
731 BAD_CASE (intel_state
.op_modifier
);
737 else if (i
.suffix
!= suffix
)
739 as_bad (_("conflicting operand size modifiers"));
744 /* Operands for jump/call need special consideration. */
745 if (current_templates
->start
->opcode_modifier
.jump
== JUMP
746 || current_templates
->start
->opcode_modifier
.jump
== JUMP_DWORD
747 || current_templates
->start
->opcode_modifier
.jump
== JUMP_INTERSEGMENT
)
749 bfd_boolean jumpabsolute
= FALSE
;
751 if (i
.op
[this_operand
].regs
754 || intel_state
.is_mem
> 1)
757 switch (intel_state
.op_modifier
)
763 intel_state
.is_mem
= 1;
767 if (!intel_state
.seg
)
769 intel_state
.is_mem
= 1;
770 if (intel_state
.op_modifier
== O_absent
)
772 if (intel_state
.is_indirect
== 1)
776 as_bad (_("cannot infer the segment part of the operand"));
779 else if (S_GET_SEGMENT (intel_state
.seg
) == reg_section
)
783 i386_operand_type types
;
785 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
787 as_bad (_("at most %d immediate operands are allowed"),
788 MAX_IMMEDIATE_OPERANDS
);
791 expP
= &im_expressions
[i
.imm_operands
++];
792 memset (expP
, 0, sizeof(*expP
));
793 expP
->X_op
= O_symbol
;
794 expP
->X_add_symbol
= intel_state
.seg
;
795 i
.op
[this_operand
].imms
= expP
;
797 resolve_expression (expP
);
798 operand_type_set (&types
, ~0);
799 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state
.seg
),
800 expP
, types
, operand_string
))
802 if (i
.operands
< MAX_OPERANDS
)
804 this_operand
= i
.operands
++;
805 i
.types
[this_operand
].bitfield
.unspecified
= 1;
807 if (suffix
== LONG_DOUBLE_MNEM_SUFFIX
)
809 intel_state
.seg
= NULL
;
810 intel_state
.is_mem
= 0;
819 i
.jumpabsolute
= TRUE
;
820 intel_state
.is_mem
|= 1;
823 else if (intel_state
.seg
)
824 intel_state
.is_mem
|= 1;
826 if (i
.op
[this_operand
].regs
)
828 i386_operand_type temp
;
830 /* Register operand. */
831 if (intel_state
.base
|| intel_state
.index
|| intel_state
.seg
)
833 as_bad (_("invalid operand"));
837 temp
= i
.op
[this_operand
].regs
->reg_type
;
838 temp
.bitfield
.baseindex
= 0;
839 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
841 i
.types
[this_operand
].bitfield
.unspecified
= 0;
844 else if (intel_state
.base
847 || intel_state
.is_mem
)
849 /* Memory operand. */
850 if (i
.mem_operands
== 1 && !maybe_adjust_templates ())
852 if ((int) i
.mem_operands
853 >= 2 - !current_templates
->start
->opcode_modifier
.isstring
)
857 call 0x9090,0x90909090
858 lcall 0x9090,0x90909090
859 jmp 0x9090,0x90909090
860 ljmp 0x9090,0x90909090
863 if ((current_templates
->start
->opcode_modifier
.jump
== JUMP_INTERSEGMENT
864 || current_templates
->start
->opcode_modifier
.jump
== JUMP_DWORD
865 || current_templates
->start
->opcode_modifier
.jump
== JUMP
)
867 && intel_state
.seg
== NULL
868 && i
.mem_operands
== 1
869 && i
.disp_operands
== 1
870 && intel_state
.op_modifier
== O_absent
)
872 /* Try to process the first operand as immediate, */
874 if (i386_finalize_immediate (exp_seg
, i
.op
[0].imms
,
875 intel_state
.reloc_types
,
879 expP
= &im_expressions
[0];
880 i
.op
[this_operand
].imms
= expP
;
883 /* Try to process the second operand as immediate, */
884 if (i386_finalize_immediate (exp_seg
, expP
,
885 intel_state
.reloc_types
,
891 i
.flags
[0] &= ~Operand_Mem
;
892 i
.types
[0].bitfield
.disp16
= 0;
893 i
.types
[0].bitfield
.disp32
= 0;
894 i
.types
[0].bitfield
.disp32s
= 0;
900 as_bad (_("too many memory references for `%s'"),
901 current_templates
->start
->name
);
905 /* Swap base and index in 16-bit memory operands like
906 [si+bx]. Since i386_index_check is also used in AT&T
907 mode we have to do this here. */
910 && intel_state
.base
->reg_type
.bitfield
.word
911 && intel_state
.index
->reg_type
.bitfield
.word
912 && intel_state
.base
->reg_num
>= 6
913 && intel_state
.index
->reg_num
< 6)
915 i
.base_reg
= intel_state
.index
;
916 i
.index_reg
= intel_state
.base
;
920 i
.base_reg
= intel_state
.base
;
921 i
.index_reg
= intel_state
.index
;
924 if (i
.base_reg
|| i
.index_reg
)
925 i
.types
[this_operand
].bitfield
.baseindex
= 1;
927 expP
= &disp_expressions
[i
.disp_operands
];
928 memcpy (expP
, &exp
, sizeof(exp
));
929 resolve_expression (expP
);
931 if (expP
->X_op
!= O_constant
932 || expP
->X_add_number
933 || !i
.types
[this_operand
].bitfield
.baseindex
)
935 i
.op
[this_operand
].disps
= expP
;
938 i386_addressing_mode ();
940 if (flag_code
== CODE_64BIT
)
942 i
.types
[this_operand
].bitfield
.disp32
= 1;
943 if (!i
.prefix
[ADDR_PREFIX
])
945 i
.types
[this_operand
].bitfield
.disp64
= 1;
946 i
.types
[this_operand
].bitfield
.disp32s
= 1;
949 else if (!i
.prefix
[ADDR_PREFIX
] ^ (flag_code
== CODE_16BIT
))
950 i
.types
[this_operand
].bitfield
.disp32
= 1;
952 i
.types
[this_operand
].bitfield
.disp16
= 1;
954 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
956 * exp_seg is used only for verification in
957 * i386_finalize_displacement, and we can end up seeing reg_section
958 * here - but we know we removed all registers from the expression
959 * (or error-ed on any remaining ones) in i386_intel_simplify. I
960 * consider the check in i386_finalize_displacement bogus anyway, in
961 * particular because it doesn't allow for expr_section, so I'd
962 * rather see that check (and the similar one in
963 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
964 * expert I can't really say whether that would have other bad side
967 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
968 && exp_seg
== reg_section
)
969 exp_seg
= expP
->X_op
!= O_constant
? undefined_section
973 if (!i386_finalize_displacement (exp_seg
, expP
,
974 intel_state
.reloc_types
,
981 for (ret
= check_none
; ; ret
= operand_check
)
983 expP
= symbol_get_value_expression (intel_state
.seg
);
984 if (expP
->X_op
!= O_full_ptr
985 || symbol_get_value_expression (expP
->X_op_symbol
)->X_op
988 intel_state
.seg
= expP
->X_add_symbol
;
990 if (expP
->X_op
!= O_register
)
992 as_bad (_("segment register name expected"));
995 if (i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.class != SReg
)
997 as_bad (_("invalid use of register"));
1003 as_bad (_("redundant segment overrides"));
1006 as_warn (_("redundant segment overrides"));
1009 switch (i386_regtab
[expP
->X_add_number
].reg_num
)
1011 case 0: i
.seg
[i
.mem_operands
] = &es
; break;
1012 case 1: i
.seg
[i
.mem_operands
] = &cs
; break;
1013 case 2: i
.seg
[i
.mem_operands
] = &ss
; break;
1014 case 3: i
.seg
[i
.mem_operands
] = &ds
; break;
1015 case 4: i
.seg
[i
.mem_operands
] = &fs
; break;
1016 case 5: i
.seg
[i
.mem_operands
] = &gs
; break;
1017 case RegFlat
: i
.seg
[i
.mem_operands
] = NULL
; break;
1021 if (!i386_index_check (operand_string
))
1024 i
.flags
[this_operand
] |= Operand_Mem
;
1025 if (i
.mem_operands
== 0)
1026 i
.memop1_string
= xstrdup (operand_string
);
1032 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
1034 as_bad (_("at most %d immediate operands are allowed"),
1035 MAX_IMMEDIATE_OPERANDS
);
1039 expP
= &im_expressions
[i
.imm_operands
++];
1040 i
.op
[this_operand
].imms
= expP
;
1043 return i386_finalize_immediate (exp_seg
, expP
, intel_state
.reloc_types
,