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 /* oword ptr X_add_symbol */
56 #define O_oword_ptr O_md24
57 /* fword ptr X_add_symbol */
58 #define O_fword_ptr O_md23
59 /* tbyte ptr X_add_symbol */
60 #define O_tbyte_ptr O_md22
61 /* xmmword ptr X_add_symbol */
62 #define O_xmmword_ptr O_md21
63 /* ymmword ptr X_add_symbol */
64 #define O_ymmword_ptr O_md20
65 /* zmmword ptr X_add_symbol */
66 #define O_zmmword_ptr O_md19
72 unsigned int operands
;
74 const i386_operators
[] =
76 { "and", O_bit_and
, 2 },
82 { "mod", O_modulus
, 2 },
84 { "not", O_bit_not
, 1 },
85 { "offset", O_offset
, 1 },
86 { "or", O_bit_inclusive_or
, 2 },
87 { "shl", O_left_shift
, 2 },
88 { "short", O_short
, 1 },
89 { "shr", O_right_shift
, 2 },
90 { "xor", O_bit_exclusive_or
, 2 },
91 { NULL
, O_illegal
, 0 }
102 #define I386_TYPE(t, n) { #t, O_##t##_ptr, { n, n, n } }
108 I386_TYPE(tbyte
, 10),
109 I386_TYPE(oword
, 16),
110 I386_TYPE(xmmword
, 16),
111 I386_TYPE(ymmword
, 32),
112 I386_TYPE(zmmword
, 64),
114 { "near", O_near_ptr
, { 0xff04, 0xff02, 0xff08 } },
115 { "far", O_far_ptr
, { 0xff06, 0xff05, 0xff06 } },
116 { NULL
, O_illegal
, { 0, 0, 0 } }
119 operatorT
i386_operator (const char *name
, unsigned int operands
, char *pc
)
130 switch (*input_line_pointer
)
133 ++input_line_pointer
;
136 ++input_line_pointer
;
139 if (this_operand
>= 0 && i
.reloc
[this_operand
] == NO_RELOC
)
142 char *gotfree_input_line
= lex_got (&i
.reloc
[this_operand
],
144 &intel_state
.reloc_types
);
146 if (!gotfree_input_line
)
148 free (gotfree_input_line
);
149 *input_line_pointer
++ = '+';
150 memset (input_line_pointer
, '0', adjust
- 1);
151 input_line_pointer
[adjust
- 1] = ' ';
159 for (j
= 0; i386_operators
[j
].name
; ++j
)
160 if (strcasecmp (i386_operators
[j
].name
, name
) == 0)
162 if (i386_operators
[j
].operands
163 && i386_operators
[j
].operands
!= operands
)
165 return i386_operators
[j
].op
;
168 for (j
= 0; i386_types
[j
].name
; ++j
)
169 if (strcasecmp (i386_types
[j
].name
, name
) == 0)
172 if (i386_types
[j
].name
&& *pc
== ' ')
177 ++input_line_pointer
;
178 c
= get_symbol_name (&pname
);
180 if (strcasecmp (pname
, "ptr") == 0)
182 /* FIXME: What if c == '"' ? */
185 if (intel_syntax
> 0 || operands
!= 1)
187 return i386_types
[j
].op
;
190 (void) restore_line_pointer (c
);
191 input_line_pointer
= pname
- 1;
197 static int i386_intel_parse_name (const char *name
, expressionS
*e
)
201 if (! strcmp (name
, "$"))
203 current_location (e
);
207 for (j
= 0; i386_types
[j
].name
; ++j
)
208 if (strcasecmp(i386_types
[j
].name
, name
) == 0)
210 e
->X_op
= O_constant
;
211 e
->X_add_number
= i386_types
[j
].sz
[flag_code
];
212 e
->X_add_symbol
= NULL
;
213 e
->X_op_symbol
= NULL
;
220 static INLINE
int i386_intel_check (const reg_entry
*rreg
,
221 const reg_entry
*base
,
222 const reg_entry
*iindex
)
224 if ((this_operand
>= 0
225 && rreg
!= i
.op
[this_operand
].regs
)
226 || base
!= intel_state
.base
227 || iindex
!= intel_state
.index
)
229 as_bad (_("invalid use of register"));
235 static INLINE
void i386_intel_fold (expressionS
*e
, symbolS
*sym
)
237 expressionS
*exp
= symbol_get_value_expression (sym
);
238 if (S_GET_SEGMENT (sym
) == absolute_section
)
240 offsetT val
= e
->X_add_number
;
243 e
->X_add_number
+= val
;
247 if (exp
->X_op
== O_symbol
248 && strcmp (S_GET_NAME (exp
->X_add_symbol
),
249 GLOBAL_OFFSET_TABLE_NAME
) == 0)
250 sym
= exp
->X_add_symbol
;
251 e
->X_add_symbol
= sym
;
252 e
->X_op_symbol
= NULL
;
258 i386_intel_simplify_register (expressionS
*e
)
262 if (this_operand
< 0 || intel_state
.in_offset
)
264 as_bad (_("invalid use of register"));
268 if (e
->X_op
== O_register
)
269 reg_num
= e
->X_add_number
;
271 reg_num
= e
->X_md
- 1;
273 if (reg_num
< 0 || reg_num
>= (int) i386_regtab_size
)
275 as_bad (_("invalid register number"));
279 if (!intel_state
.in_bracket
)
281 if (i
.op
[this_operand
].regs
)
283 as_bad (_("invalid use of register"));
286 if (i386_regtab
[reg_num
].reg_type
.bitfield
.sreg3
287 && i386_regtab
[reg_num
].reg_num
== RegFlat
)
289 as_bad (_("invalid use of pseudo-register"));
292 i
.op
[this_operand
].regs
= i386_regtab
+ reg_num
;
294 else if (!intel_state
.index
295 && (i386_regtab
[reg_num
].reg_type
.bitfield
.xmmword
296 || i386_regtab
[reg_num
].reg_type
.bitfield
.ymmword
297 || i386_regtab
[reg_num
].reg_type
.bitfield
.zmmword
298 || i386_regtab
[reg_num
].reg_num
== RegIZ
))
299 intel_state
.index
= i386_regtab
+ reg_num
;
300 else if (!intel_state
.base
&& !intel_state
.in_scale
)
301 intel_state
.base
= i386_regtab
+ reg_num
;
302 else if (!intel_state
.index
)
304 if (intel_state
.in_scale
305 || current_templates
->start
->base_opcode
== 0xf30f1b /* bndmk */
306 || (current_templates
->start
->base_opcode
& ~1) == 0x0f1a /* bnd{ld,st}x */
307 || i386_regtab
[reg_num
].reg_type
.bitfield
.baseindex
)
308 intel_state
.index
= i386_regtab
+ reg_num
;
311 /* Convert base to index and make ESP/RSP the base. */
312 intel_state
.index
= intel_state
.base
;
313 intel_state
.base
= i386_regtab
+ reg_num
;
318 /* esp is invalid as index */
319 intel_state
.index
= i386_regtab
+ REGNAM_EAX
+ ESP_REG_NUM
;
324 static int i386_intel_simplify (expressionS
*);
326 static INLINE
int i386_intel_simplify_symbol(symbolS
*sym
)
328 int ret
= i386_intel_simplify (symbol_get_value_expression (sym
));
332 S_SET_SEGMENT(sym
, absolute_section
);
338 static int i386_intel_simplify (expressionS
*e
)
340 const reg_entry
*the_reg
= (this_operand
>= 0
341 ? i
.op
[this_operand
].regs
: NULL
);
342 const reg_entry
*base
= intel_state
.base
;
343 const reg_entry
*state_index
= intel_state
.index
;
354 if (!i386_intel_simplify_symbol (e
->X_add_symbol
)
355 || !i386_intel_check(the_reg
, intel_state
.base
,
359 if (!intel_state
.in_offset
)
360 ++intel_state
.in_bracket
;
361 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
362 if (!intel_state
.in_offset
)
363 --intel_state
.in_bracket
;
369 i386_intel_fold (e
, e
->X_op_symbol
);
373 intel_state
.has_offset
= 1;
374 ++intel_state
.in_offset
;
375 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
376 --intel_state
.in_offset
;
377 if (!ret
|| !i386_intel_check(the_reg
, base
, state_index
))
379 i386_intel_fold (e
, e
->X_add_symbol
);
394 if (intel_state
.op_modifier
== O_absent
)
395 intel_state
.op_modifier
= e
->X_op
;
398 if (symbol_get_value_expression (e
->X_add_symbol
)->X_op
401 as_bad (_("invalid use of register"));
404 if (!i386_intel_simplify_symbol (e
->X_add_symbol
))
406 i386_intel_fold (e
, e
->X_add_symbol
);
410 if (symbol_get_value_expression (e
->X_op_symbol
)->X_op
413 as_bad (_("invalid use of register"));
416 if (!i386_intel_simplify_symbol (e
->X_op_symbol
)
417 || !i386_intel_check(the_reg
, intel_state
.base
,
420 if (!intel_state
.in_offset
)
422 if (!intel_state
.seg
)
423 intel_state
.seg
= e
->X_add_symbol
;
428 exp
.X_op
= O_full_ptr
;
429 exp
.X_add_symbol
= e
->X_add_symbol
;
430 exp
.X_op_symbol
= intel_state
.seg
;
431 intel_state
.seg
= make_expr_symbol (&exp
);
434 i386_intel_fold (e
, e
->X_op_symbol
);
438 if (this_operand
>= 0 && intel_state
.in_bracket
)
440 expressionS
*scale
= NULL
;
441 int has_index
= (intel_state
.index
!= NULL
);
443 if (!intel_state
.in_scale
++)
444 intel_state
.scale_factor
= 1;
446 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
447 if (ret
&& !has_index
&& intel_state
.index
)
448 scale
= symbol_get_value_expression (e
->X_op_symbol
);
451 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
452 if (ret
&& !scale
&& !has_index
&& intel_state
.index
)
453 scale
= symbol_get_value_expression (e
->X_add_symbol
);
457 resolve_expression (scale
);
458 if (scale
->X_op
!= O_constant
459 || intel_state
.index
->reg_type
.bitfield
.word
)
460 scale
->X_add_number
= 0;
461 intel_state
.scale_factor
*= scale
->X_add_number
;
464 --intel_state
.in_scale
;
468 if (!intel_state
.in_scale
)
469 switch (intel_state
.scale_factor
)
472 i
.log2_scale_factor
= 0;
475 i
.log2_scale_factor
= 1;
478 i
.log2_scale_factor
= 2;
481 i
.log2_scale_factor
= 3;
484 /* esp is invalid as index */
485 intel_state
.index
= i386_regtab
+ REGNAM_EAX
+ ESP_REG_NUM
;
494 ret
= i386_intel_simplify_register (e
);
497 gas_assert (e
->X_add_number
< (unsigned short) -1);
498 e
->X_md
= (unsigned short) e
->X_add_number
+ 1;
499 e
->X_op
= O_constant
;
506 return i386_intel_simplify_register (e
);
512 && !i386_intel_simplify_symbol (e
->X_add_symbol
))
514 if (e
->X_op
== O_add
|| e
->X_op
== O_subtract
)
516 base
= intel_state
.base
;
517 state_index
= intel_state
.index
;
519 if (!i386_intel_check (the_reg
, base
, state_index
)
521 && !i386_intel_simplify_symbol (e
->X_op_symbol
))
522 || !i386_intel_check (the_reg
,
524 ? base
: intel_state
.base
),
526 ? state_index
: intel_state
.index
)))
531 if (this_operand
>= 0
532 && e
->X_op
== O_symbol
533 && !intel_state
.in_offset
)
535 segT seg
= S_GET_SEGMENT (e
->X_add_symbol
);
537 if (seg
!= absolute_section
538 && seg
!= reg_section
539 && seg
!= expr_section
)
540 intel_state
.is_mem
|= 2 - !intel_state
.in_bracket
;
546 int i386_need_index_operator (void)
548 return intel_syntax
< 0;
552 i386_intel_operand (char *operand_string
, int got_a_float
)
554 char *saved_input_line_pointer
, *buf
;
556 expressionS exp
, *expP
;
560 /* Handle vector immediates. */
561 if (RC_SAE_immediate (operand_string
))
564 /* Initialize state structure. */
565 intel_state
.op_modifier
= O_absent
;
566 intel_state
.is_mem
= 0;
567 intel_state
.is_indirect
= 0;
568 intel_state
.has_offset
= 0;
569 intel_state
.base
= NULL
;
570 intel_state
.index
= NULL
;
571 intel_state
.seg
= NULL
;
572 operand_type_set (&intel_state
.reloc_types
, ~0);
573 gas_assert (!intel_state
.in_offset
);
574 gas_assert (!intel_state
.in_bracket
);
575 gas_assert (!intel_state
.in_scale
);
577 saved_input_line_pointer
= input_line_pointer
;
578 input_line_pointer
= buf
= xstrdup (operand_string
);
581 memset (&exp
, 0, sizeof(exp
));
582 exp_seg
= expression (&exp
);
583 ret
= i386_intel_simplify (&exp
);
588 /* Handle vector operations. */
589 if (*input_line_pointer
== '{')
591 char *end
= check_VecOperations (input_line_pointer
, NULL
);
593 input_line_pointer
= end
;
598 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
601 as_bad (_("junk `%s' after expression"), input_line_pointer
);
604 else if (exp
.X_op
== O_illegal
|| exp
.X_op
== O_absent
)
607 as_bad (_("invalid expression"));
610 else if (!intel_state
.has_offset
611 && input_line_pointer
> buf
612 && *(input_line_pointer
- 1) == ']')
614 intel_state
.is_mem
|= 1;
615 intel_state
.is_indirect
= 1;
618 input_line_pointer
= saved_input_line_pointer
;
621 gas_assert (!intel_state
.in_offset
);
622 gas_assert (!intel_state
.in_bracket
);
623 gas_assert (!intel_state
.in_scale
);
628 if (intel_state
.op_modifier
!= O_absent
629 && current_templates
->start
->base_opcode
!= 0x8d /* lea */)
631 i
.types
[this_operand
].bitfield
.unspecified
= 0;
633 switch (intel_state
.op_modifier
)
636 i
.types
[this_operand
].bitfield
.byte
= 1;
637 suffix
= BYTE_MNEM_SUFFIX
;
641 i
.types
[this_operand
].bitfield
.word
= 1;
642 if ((current_templates
->start
->name
[0] == 'l'
643 && current_templates
->start
->name
[2] == 's'
644 && current_templates
->start
->name
[3] == 0)
645 || current_templates
->start
->base_opcode
== 0x62 /* bound */)
646 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
647 else if (got_a_float
== 2) /* "fi..." */
648 suffix
= SHORT_MNEM_SUFFIX
;
650 suffix
= WORD_MNEM_SUFFIX
;
654 i
.types
[this_operand
].bitfield
.dword
= 1;
655 if ((current_templates
->start
->name
[0] == 'l'
656 && current_templates
->start
->name
[2] == 's'
657 && current_templates
->start
->name
[3] == 0)
658 || current_templates
->start
->base_opcode
== 0x62 /* bound */)
659 suffix
= WORD_MNEM_SUFFIX
;
660 else if (flag_code
== CODE_16BIT
661 && (current_templates
->start
->opcode_modifier
.jump
662 || current_templates
->start
->opcode_modifier
.jumpdword
))
663 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
664 else if (got_a_float
== 1) /* "f..." */
665 suffix
= SHORT_MNEM_SUFFIX
;
667 suffix
= LONG_MNEM_SUFFIX
;
671 i
.types
[this_operand
].bitfield
.fword
= 1;
672 if (current_templates
->start
->name
[0] == 'l'
673 && current_templates
->start
->name
[2] == 's'
674 && current_templates
->start
->name
[3] == 0)
675 suffix
= LONG_MNEM_SUFFIX
;
676 else if (!got_a_float
)
678 if (flag_code
== CODE_16BIT
)
679 add_prefix (DATA_PREFIX_OPCODE
);
680 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
683 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
687 i
.types
[this_operand
].bitfield
.qword
= 1;
688 if (current_templates
->start
->base_opcode
== 0x62 /* bound */
689 || got_a_float
== 1) /* "f..." */
690 suffix
= LONG_MNEM_SUFFIX
;
692 suffix
= QWORD_MNEM_SUFFIX
;
696 i
.types
[this_operand
].bitfield
.tbyte
= 1;
697 if (got_a_float
== 1)
698 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
700 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
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
721 && !current_templates
->start
->opcode_modifier
.jumpdword
)
722 suffix
= got_a_float
/* so it will cause an error */
724 : LONG_DOUBLE_MNEM_SUFFIX
;
728 BAD_CASE (intel_state
.op_modifier
);
734 else if (i
.suffix
!= suffix
)
736 as_bad (_("conflicting operand size modifiers"));
741 /* Operands for jump/call need special consideration. */
742 if (current_templates
->start
->opcode_modifier
.jump
743 || current_templates
->start
->opcode_modifier
.jumpdword
744 || current_templates
->start
->opcode_modifier
.jumpintersegment
)
746 if (i
.op
[this_operand
].regs
749 || intel_state
.is_mem
> 1)
750 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
752 switch (intel_state
.op_modifier
)
756 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
758 intel_state
.is_mem
= 1;
762 if (!intel_state
.seg
)
764 intel_state
.is_mem
= 1;
765 if (intel_state
.op_modifier
== O_absent
)
767 if (intel_state
.is_indirect
== 1)
768 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
771 as_bad (_("cannot infer the segment part of the operand"));
774 else if (S_GET_SEGMENT (intel_state
.seg
) == reg_section
)
775 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
778 i386_operand_type types
;
780 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
782 as_bad (_("at most %d immediate operands are allowed"),
783 MAX_IMMEDIATE_OPERANDS
);
786 expP
= &im_expressions
[i
.imm_operands
++];
787 memset (expP
, 0, sizeof(*expP
));
788 expP
->X_op
= O_symbol
;
789 expP
->X_add_symbol
= intel_state
.seg
;
790 i
.op
[this_operand
].imms
= expP
;
792 resolve_expression (expP
);
793 operand_type_set (&types
, ~0);
794 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state
.seg
),
795 expP
, types
, operand_string
))
797 if (i
.operands
< MAX_OPERANDS
)
799 this_operand
= i
.operands
++;
800 i
.types
[this_operand
].bitfield
.unspecified
= 1;
802 if (suffix
== LONG_DOUBLE_MNEM_SUFFIX
)
804 intel_state
.seg
= NULL
;
805 intel_state
.is_mem
= 0;
809 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
812 if (i
.types
[this_operand
].bitfield
.jumpabsolute
)
813 intel_state
.is_mem
|= 1;
815 else if (intel_state
.seg
)
816 intel_state
.is_mem
|= 1;
818 if (i
.op
[this_operand
].regs
)
820 i386_operand_type temp
;
822 /* Register operand. */
823 if (intel_state
.base
|| intel_state
.index
|| intel_state
.seg
)
825 as_bad (_("invalid operand"));
829 temp
= i
.op
[this_operand
].regs
->reg_type
;
830 temp
.bitfield
.baseindex
= 0;
831 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
833 i
.types
[this_operand
].bitfield
.unspecified
= 0;
836 else if (intel_state
.base
839 || intel_state
.is_mem
)
841 /* Memory operand. */
842 if (i
.mem_operands
== 1 && !maybe_adjust_templates ())
844 if ((int) i
.mem_operands
845 >= 2 - !current_templates
->start
->opcode_modifier
.isstring
)
849 call 0x9090,0x90909090
850 lcall 0x9090,0x90909090
851 jmp 0x9090,0x90909090
852 ljmp 0x9090,0x90909090
855 if ((current_templates
->start
->opcode_modifier
.jumpintersegment
856 || current_templates
->start
->opcode_modifier
.jumpdword
857 || current_templates
->start
->opcode_modifier
.jump
)
859 && intel_state
.seg
== NULL
860 && i
.mem_operands
== 1
861 && i
.disp_operands
== 1
862 && intel_state
.op_modifier
== O_absent
)
864 /* Try to process the first operand as immediate, */
866 if (i386_finalize_immediate (exp_seg
, i
.op
[0].imms
,
867 intel_state
.reloc_types
,
871 expP
= &im_expressions
[0];
872 i
.op
[this_operand
].imms
= expP
;
875 /* Try to process the second operand as immediate, */
876 if (i386_finalize_immediate (exp_seg
, expP
,
877 intel_state
.reloc_types
,
883 i
.flags
[0] &= ~Operand_Mem
;
884 i
.types
[0].bitfield
.disp16
= 0;
885 i
.types
[0].bitfield
.disp32
= 0;
886 i
.types
[0].bitfield
.disp32s
= 0;
892 as_bad (_("too many memory references for `%s'"),
893 current_templates
->start
->name
);
897 /* Swap base and index in 16-bit memory operands like
898 [si+bx]. Since i386_index_check is also used in AT&T
899 mode we have to do this here. */
902 && intel_state
.base
->reg_type
.bitfield
.word
903 && intel_state
.index
->reg_type
.bitfield
.word
904 && intel_state
.base
->reg_num
>= 6
905 && intel_state
.index
->reg_num
< 6)
907 i
.base_reg
= intel_state
.index
;
908 i
.index_reg
= intel_state
.base
;
912 i
.base_reg
= intel_state
.base
;
913 i
.index_reg
= intel_state
.index
;
916 if (i
.base_reg
|| i
.index_reg
)
917 i
.types
[this_operand
].bitfield
.baseindex
= 1;
919 expP
= &disp_expressions
[i
.disp_operands
];
920 memcpy (expP
, &exp
, sizeof(exp
));
921 resolve_expression (expP
);
923 if (expP
->X_op
!= O_constant
924 || expP
->X_add_number
925 || !i
.types
[this_operand
].bitfield
.baseindex
)
927 i
.op
[this_operand
].disps
= expP
;
930 i386_addressing_mode ();
932 if (flag_code
== CODE_64BIT
)
934 i
.types
[this_operand
].bitfield
.disp32
= 1;
935 if (!i
.prefix
[ADDR_PREFIX
])
937 i
.types
[this_operand
].bitfield
.disp64
= 1;
938 i
.types
[this_operand
].bitfield
.disp32s
= 1;
941 else if (!i
.prefix
[ADDR_PREFIX
] ^ (flag_code
== CODE_16BIT
))
942 i
.types
[this_operand
].bitfield
.disp32
= 1;
944 i
.types
[this_operand
].bitfield
.disp16
= 1;
946 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
948 * exp_seg is used only for verification in
949 * i386_finalize_displacement, and we can end up seeing reg_section
950 * here - but we know we removed all registers from the expression
951 * (or error-ed on any remaining ones) in i386_intel_simplify. I
952 * consider the check in i386_finalize_displacement bogus anyway, in
953 * particular because it doesn't allow for expr_section, so I'd
954 * rather see that check (and the similar one in
955 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
956 * expert I can't really say whether that would have other bad side
959 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
960 && exp_seg
== reg_section
)
961 exp_seg
= expP
->X_op
!= O_constant
? undefined_section
965 if (!i386_finalize_displacement (exp_seg
, expP
,
966 intel_state
.reloc_types
,
973 for (ret
= check_none
; ; ret
= operand_check
)
975 expP
= symbol_get_value_expression (intel_state
.seg
);
976 if (expP
->X_op
!= O_full_ptr
977 || symbol_get_value_expression (expP
->X_op_symbol
)->X_op
980 intel_state
.seg
= expP
->X_add_symbol
;
982 if (expP
->X_op
!= O_register
)
984 as_bad (_("segment register name expected"));
987 if (!i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.sreg2
988 && !i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.sreg3
)
990 as_bad (_("invalid use of register"));
996 as_bad (_("redundant segment overrides"));
999 as_warn (_("redundant segment overrides"));
1002 switch (i386_regtab
[expP
->X_add_number
].reg_num
)
1004 case 0: i
.seg
[i
.mem_operands
] = &es
; break;
1005 case 1: i
.seg
[i
.mem_operands
] = &cs
; break;
1006 case 2: i
.seg
[i
.mem_operands
] = &ss
; break;
1007 case 3: i
.seg
[i
.mem_operands
] = &ds
; break;
1008 case 4: i
.seg
[i
.mem_operands
] = &fs
; break;
1009 case 5: i
.seg
[i
.mem_operands
] = &gs
; break;
1010 case RegFlat
: i
.seg
[i
.mem_operands
] = NULL
; break;
1014 if (!i386_index_check (operand_string
))
1017 i
.flags
[this_operand
] |= Operand_Mem
;
1018 if (i
.mem_operands
== 0)
1019 i
.memop1_string
= xstrdup (operand_string
);
1025 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
1027 as_bad (_("at most %d immediate operands are allowed"),
1028 MAX_IMMEDIATE_OPERANDS
);
1032 expP
= &im_expressions
[i
.imm_operands
++];
1033 i
.op
[this_operand
].imms
= expP
;
1036 return i386_finalize_immediate (exp_seg
, expP
, intel_state
.reloc_types
,