1 /* tc-i386.c -- Assemble Intel syntax code for ix86/x86-64
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 operatorT op_modifier
; /* Operand modifier. */
25 int is_mem
; /* 1 if operand is memory reference. */
26 int is_indirect
; /* 1 if operand is indirect reference. */
27 int has_offset
; /* 1 if operand has offset. */
28 unsigned int in_offset
; /* >=1 if processing operand of offset. */
29 unsigned int in_bracket
; /* >=1 if processing operand in brackets. */
30 unsigned int in_scale
; /* >=1 if processing multipication operand
32 i386_operand_type reloc_types
; /* Value obtained from lex_got(). */
33 const reg_entry
*base
; /* Base register (if any). */
34 const reg_entry
*index
; /* Index register (if any). */
35 offsetT scale_factor
; /* Accumulated scale factor. */
40 /* offset X_add_symbol */
41 #define O_offset O_md32
42 /* offset X_add_symbol */
43 #define O_short O_md31
44 /* near ptr X_add_symbol */
45 #define O_near_ptr O_md30
46 /* far ptr X_add_symbol */
47 #define O_far_ptr O_md29
48 /* byte ptr X_add_symbol */
49 #define O_byte_ptr O_md28
50 /* word ptr X_add_symbol */
51 #define O_word_ptr O_md27
52 /* dword ptr X_add_symbol */
53 #define O_dword_ptr O_md26
54 /* qword ptr X_add_symbol */
55 #define O_qword_ptr O_md25
56 /* oword ptr X_add_symbol */
57 #define O_oword_ptr O_md24
58 /* fword ptr X_add_symbol */
59 #define O_fword_ptr O_md23
60 /* tbyte ptr X_add_symbol */
61 #define O_tbyte_ptr O_md22
62 /* xmmword ptr X_add_symbol */
63 #define O_xmmword_ptr O_md21
64 /* ymmword ptr X_add_symbol */
65 #define O_ymmword_ptr O_md20
66 /* zmmword ptr X_add_symbol */
67 #define O_zmmword_ptr O_md19
73 unsigned int operands
;
75 const i386_operators
[] =
77 { "and", O_bit_and
, 2 },
83 { "mod", O_modulus
, 2 },
85 { "not", O_bit_not
, 1 },
86 { "offset", O_offset
, 1 },
87 { "or", O_bit_inclusive_or
, 2 },
88 { "shl", O_left_shift
, 2 },
89 { "short", O_short
, 1 },
90 { "shr", O_right_shift
, 2 },
91 { "xor", O_bit_exclusive_or
, 2 },
92 { NULL
, O_illegal
, 0 }
103 #define I386_TYPE(t, n) { #t, O_##t##_ptr, { n, n, n } }
109 I386_TYPE(tbyte
, 10),
110 I386_TYPE(oword
, 16),
111 I386_TYPE(xmmword
, 16),
112 I386_TYPE(ymmword
, 32),
113 I386_TYPE(zmmword
, 64),
115 { "near", O_near_ptr
, { 0xff04, 0xff02, 0xff08 } },
116 { "far", O_far_ptr
, { 0xff06, 0xff05, 0xff06 } },
117 { NULL
, O_illegal
, { 0, 0, 0 } }
120 operatorT
i386_operator (const char *name
, unsigned int operands
, char *pc
)
131 switch (*input_line_pointer
)
134 ++input_line_pointer
;
137 ++input_line_pointer
;
140 if (this_operand
>= 0 && i
.reloc
[this_operand
] == NO_RELOC
)
143 char *gotfree_input_line
= lex_got (&i
.reloc
[this_operand
],
145 &intel_state
.reloc_types
,
146 (i
.bnd_prefix
!= NULL
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)
174 if (i386_types
[j
].name
&& *pc
== ' ')
176 char *pname
= ++input_line_pointer
;
177 char c
= get_symbol_end ();
179 if (strcasecmp (pname
, "ptr") == 0)
183 if (intel_syntax
> 0 || operands
!= 1)
185 return i386_types
[j
].op
;
188 *input_line_pointer
= c
;
189 input_line_pointer
= pname
- 1;
195 static int i386_intel_parse_name (const char *name
, expressionS
*e
)
199 if (! strcmp (name
, "$"))
201 current_location (e
);
205 for (j
= 0; i386_types
[j
].name
; ++j
)
206 if (strcasecmp(i386_types
[j
].name
, name
) == 0)
208 e
->X_op
= O_constant
;
209 e
->X_add_number
= i386_types
[j
].sz
[flag_code
];
210 e
->X_add_symbol
= NULL
;
211 e
->X_op_symbol
= NULL
;
218 static INLINE
int i386_intel_check (const reg_entry
*rreg
,
219 const reg_entry
*base
,
220 const reg_entry
*iindex
)
222 if ((this_operand
>= 0
223 && rreg
!= i
.op
[this_operand
].regs
)
224 || base
!= intel_state
.base
225 || iindex
!= intel_state
.index
)
227 as_bad (_("invalid use of register"));
233 static INLINE
void i386_intel_fold (expressionS
*e
, symbolS
*sym
)
235 expressionS
*exp
= symbol_get_value_expression (sym
);
236 if (S_GET_SEGMENT (sym
) == absolute_section
)
238 offsetT val
= e
->X_add_number
;
241 e
->X_add_number
+= val
;
245 if (exp
->X_op
== O_symbol
246 && strcmp (S_GET_NAME (exp
->X_add_symbol
),
247 GLOBAL_OFFSET_TABLE_NAME
) == 0)
248 sym
= exp
->X_add_symbol
;
249 e
->X_add_symbol
= sym
;
250 e
->X_op_symbol
= NULL
;
256 i386_intel_simplify_register (expressionS
*e
)
260 if (this_operand
< 0 || intel_state
.in_offset
)
262 as_bad (_("invalid use of register"));
266 if (e
->X_op
== O_register
)
267 reg_num
= e
->X_add_number
;
269 reg_num
= e
->X_md
- 1;
271 if (!intel_state
.in_bracket
)
273 if (i
.op
[this_operand
].regs
)
275 as_bad (_("invalid use of register"));
278 if (i386_regtab
[reg_num
].reg_type
.bitfield
.sreg3
279 && i386_regtab
[reg_num
].reg_num
== RegFlat
)
281 as_bad (_("invalid use of pseudo-register"));
284 i
.op
[this_operand
].regs
= i386_regtab
+ reg_num
;
286 else if (!intel_state
.index
287 && (i386_regtab
[reg_num
].reg_type
.bitfield
.regxmm
288 || i386_regtab
[reg_num
].reg_type
.bitfield
.regymm
289 || i386_regtab
[reg_num
].reg_type
.bitfield
.regzmm
))
290 intel_state
.index
= i386_regtab
+ reg_num
;
291 else if (!intel_state
.base
&& !intel_state
.in_scale
)
292 intel_state
.base
= i386_regtab
+ reg_num
;
293 else if (!intel_state
.index
)
295 if (intel_state
.in_scale
296 || current_templates
->start
->base_opcode
== 0xf30f1b /* bndmk */
297 || (current_templates
->start
->base_opcode
& ~1) == 0x0f1a /* bnd{ld,st}x */
298 || i386_regtab
[reg_num
].reg_type
.bitfield
.baseindex
)
299 intel_state
.index
= i386_regtab
+ reg_num
;
302 /* Convert base to index and make ESP/RSP the base. */
303 intel_state
.index
= intel_state
.base
;
304 intel_state
.base
= i386_regtab
+ reg_num
;
309 /* esp is invalid as index */
310 intel_state
.index
= i386_regtab
+ REGNAM_EAX
+ ESP_REG_NUM
;
315 static int i386_intel_simplify (expressionS
*);
317 static INLINE
int i386_intel_simplify_symbol(symbolS
*sym
)
319 int ret
= i386_intel_simplify (symbol_get_value_expression (sym
));
323 S_SET_SEGMENT(sym
, absolute_section
);
329 static int i386_intel_simplify (expressionS
*e
)
331 const reg_entry
*the_reg
= (this_operand
>= 0
332 ? i
.op
[this_operand
].regs
: NULL
);
333 const reg_entry
*base
= intel_state
.base
;
334 const reg_entry
*state_index
= intel_state
.index
;
345 if (!i386_intel_simplify_symbol (e
->X_add_symbol
)
346 || !i386_intel_check(the_reg
, intel_state
.base
,
350 if (!intel_state
.in_offset
)
351 ++intel_state
.in_bracket
;
352 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
353 if (!intel_state
.in_offset
)
354 --intel_state
.in_bracket
;
360 i386_intel_fold (e
, e
->X_op_symbol
);
364 intel_state
.has_offset
= 1;
365 ++intel_state
.in_offset
;
366 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
367 --intel_state
.in_offset
;
368 if (!ret
|| !i386_intel_check(the_reg
, base
, state_index
))
370 i386_intel_fold (e
, e
->X_add_symbol
);
385 if (intel_state
.op_modifier
== O_absent
)
386 intel_state
.op_modifier
= e
->X_op
;
389 if (symbol_get_value_expression (e
->X_add_symbol
)->X_op
392 as_bad (_("invalid use of register"));
395 if (!i386_intel_simplify_symbol (e
->X_add_symbol
))
397 i386_intel_fold (e
, e
->X_add_symbol
);
401 if (symbol_get_value_expression (e
->X_op_symbol
)->X_op
404 as_bad (_("invalid use of register"));
407 if (!i386_intel_simplify_symbol (e
->X_op_symbol
)
408 || !i386_intel_check(the_reg
, intel_state
.base
,
411 if (!intel_state
.in_offset
)
412 intel_state
.seg
= e
->X_add_symbol
;
413 i386_intel_fold (e
, e
->X_op_symbol
);
417 if (this_operand
>= 0 && intel_state
.in_bracket
)
419 expressionS
*scale
= NULL
;
420 int has_index
= (intel_state
.index
!= NULL
);
422 if (!intel_state
.in_scale
++)
423 intel_state
.scale_factor
= 1;
425 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
426 if (ret
&& !has_index
&& intel_state
.index
)
427 scale
= symbol_get_value_expression (e
->X_op_symbol
);
430 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
431 if (ret
&& !scale
&& !has_index
&& intel_state
.index
)
432 scale
= symbol_get_value_expression (e
->X_add_symbol
);
436 resolve_expression (scale
);
437 if (scale
->X_op
!= O_constant
438 || intel_state
.index
->reg_type
.bitfield
.reg16
)
439 scale
->X_add_number
= 0;
440 intel_state
.scale_factor
*= scale
->X_add_number
;
443 --intel_state
.in_scale
;
447 if (!intel_state
.in_scale
)
448 switch (intel_state
.scale_factor
)
451 i
.log2_scale_factor
= 0;
454 i
.log2_scale_factor
= 1;
457 i
.log2_scale_factor
= 2;
460 i
.log2_scale_factor
= 3;
463 /* esp is invalid as index */
464 intel_state
.index
= i386_regtab
+ REGNAM_EAX
+ ESP_REG_NUM
;
473 ret
= i386_intel_simplify_register (e
);
476 gas_assert (e
->X_add_number
< (unsigned short) -1);
477 e
->X_md
= (unsigned short) e
->X_add_number
+ 1;
478 e
->X_op
= O_constant
;
485 return i386_intel_simplify_register (e
);
491 && !i386_intel_simplify_symbol (e
->X_add_symbol
))
493 if (e
->X_op
== O_add
|| e
->X_op
== O_subtract
)
495 base
= intel_state
.base
;
496 state_index
= intel_state
.index
;
498 if (!i386_intel_check (the_reg
, base
, state_index
)
500 && !i386_intel_simplify_symbol (e
->X_op_symbol
))
501 || !i386_intel_check (the_reg
,
503 ? base
: intel_state
.base
),
505 ? state_index
: intel_state
.index
)))
510 if (this_operand
>= 0
511 && e
->X_op
== O_symbol
512 && !intel_state
.in_offset
)
514 segT seg
= S_GET_SEGMENT (e
->X_add_symbol
);
516 if (seg
!= absolute_section
517 && seg
!= reg_section
518 && seg
!= expr_section
)
519 intel_state
.is_mem
|= 2 - !intel_state
.in_bracket
;
525 int i386_need_index_operator (void)
527 return intel_syntax
< 0;
531 i386_intel_operand (char *operand_string
, int got_a_float
)
533 char *saved_input_line_pointer
, *buf
;
535 expressionS exp
, *expP
;
539 /* Handle vector immediates. */
540 if (RC_SAE_immediate (operand_string
))
543 /* Initialize state structure. */
544 intel_state
.op_modifier
= O_absent
;
545 intel_state
.is_mem
= 0;
546 intel_state
.is_indirect
= 0;
547 intel_state
.has_offset
= 0;
548 intel_state
.base
= NULL
;
549 intel_state
.index
= NULL
;
550 intel_state
.seg
= NULL
;
551 operand_type_set (&intel_state
.reloc_types
, ~0);
552 gas_assert (!intel_state
.in_offset
);
553 gas_assert (!intel_state
.in_bracket
);
554 gas_assert (!intel_state
.in_scale
);
556 saved_input_line_pointer
= input_line_pointer
;
557 input_line_pointer
= buf
= xstrdup (operand_string
);
560 memset (&exp
, 0, sizeof(exp
));
561 exp_seg
= expression (&exp
);
562 ret
= i386_intel_simplify (&exp
);
567 /* Handle vector operations. */
568 if (*input_line_pointer
== '{')
570 char *end
= check_VecOperations (input_line_pointer
, NULL
);
572 input_line_pointer
= end
;
577 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
579 as_bad (_("junk `%s' after expression"), input_line_pointer
);
582 else if (exp
.X_op
== O_illegal
|| exp
.X_op
== O_absent
)
584 as_bad (_("invalid expression"));
587 else if (!intel_state
.has_offset
588 && input_line_pointer
> buf
589 && *(input_line_pointer
- 1) == ']')
591 intel_state
.is_mem
|= 1;
592 intel_state
.is_indirect
= 1;
595 input_line_pointer
= saved_input_line_pointer
;
598 gas_assert (!intel_state
.in_offset
);
599 gas_assert (!intel_state
.in_bracket
);
600 gas_assert (!intel_state
.in_scale
);
605 if (intel_state
.op_modifier
!= O_absent
606 && current_templates
->start
->base_opcode
!= 0x8d /* lea */)
608 i
.types
[this_operand
].bitfield
.unspecified
= 0;
610 switch (intel_state
.op_modifier
)
613 i
.types
[this_operand
].bitfield
.byte
= 1;
614 suffix
= BYTE_MNEM_SUFFIX
;
618 i
.types
[this_operand
].bitfield
.word
= 1;
619 if ((current_templates
->start
->name
[0] == 'l'
620 && current_templates
->start
->name
[2] == 's'
621 && current_templates
->start
->name
[3] == 0)
622 || current_templates
->start
->base_opcode
== 0x62 /* bound */)
623 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
624 else if (got_a_float
== 2) /* "fi..." */
625 suffix
= SHORT_MNEM_SUFFIX
;
627 suffix
= WORD_MNEM_SUFFIX
;
631 i
.types
[this_operand
].bitfield
.dword
= 1;
632 if ((current_templates
->start
->name
[0] == 'l'
633 && current_templates
->start
->name
[2] == 's'
634 && current_templates
->start
->name
[3] == 0)
635 || current_templates
->start
->base_opcode
== 0x62 /* bound */)
636 suffix
= WORD_MNEM_SUFFIX
;
637 else if (flag_code
== CODE_16BIT
638 && (current_templates
->start
->opcode_modifier
.jump
639 || current_templates
->start
->opcode_modifier
.jumpdword
))
640 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
641 else if (got_a_float
== 1) /* "f..." */
642 suffix
= SHORT_MNEM_SUFFIX
;
644 suffix
= LONG_MNEM_SUFFIX
;
648 i
.types
[this_operand
].bitfield
.fword
= 1;
649 if (current_templates
->start
->name
[0] == 'l'
650 && current_templates
->start
->name
[2] == 's'
651 && current_templates
->start
->name
[3] == 0)
652 suffix
= LONG_MNEM_SUFFIX
;
653 else if (!got_a_float
)
655 if (flag_code
== CODE_16BIT
)
656 add_prefix (DATA_PREFIX_OPCODE
);
657 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
660 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
664 i
.types
[this_operand
].bitfield
.qword
= 1;
665 if (current_templates
->start
->base_opcode
== 0x62 /* bound */
666 || got_a_float
== 1) /* "f..." */
667 suffix
= LONG_MNEM_SUFFIX
;
669 suffix
= QWORD_MNEM_SUFFIX
;
673 i
.types
[this_operand
].bitfield
.tbyte
= 1;
674 if (got_a_float
== 1)
675 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
677 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
682 i
.types
[this_operand
].bitfield
.xmmword
= 1;
683 suffix
= XMMWORD_MNEM_SUFFIX
;
687 i
.types
[this_operand
].bitfield
.ymmword
= 1;
688 suffix
= YMMWORD_MNEM_SUFFIX
;
692 i
.types
[this_operand
].bitfield
.zmmword
= 1;
693 suffix
= ZMMWORD_MNEM_SUFFIX
;
697 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
700 if (!current_templates
->start
->opcode_modifier
.jump
701 && !current_templates
->start
->opcode_modifier
.jumpdword
)
702 suffix
= got_a_float
/* so it will cause an error */
704 : LONG_DOUBLE_MNEM_SUFFIX
;
708 BAD_CASE (intel_state
.op_modifier
);
714 else if (i
.suffix
!= suffix
)
716 as_bad (_("conflicting operand size modifiers"));
721 /* Operands for jump/call need special consideration. */
722 if (current_templates
->start
->opcode_modifier
.jump
723 || current_templates
->start
->opcode_modifier
.jumpdword
724 || current_templates
->start
->opcode_modifier
.jumpintersegment
)
726 if (i
.op
[this_operand
].regs
729 || intel_state
.is_mem
> 1)
730 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
732 switch (intel_state
.op_modifier
)
736 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
738 intel_state
.is_mem
= 1;
742 if (!intel_state
.seg
)
744 intel_state
.is_mem
= 1;
745 if (intel_state
.op_modifier
== O_absent
)
747 if (intel_state
.is_indirect
== 1)
748 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
751 as_bad (_("cannot infer the segment part of the operand"));
754 else if (S_GET_SEGMENT (intel_state
.seg
) == reg_section
)
755 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
758 i386_operand_type types
;
760 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
762 as_bad (_("at most %d immediate operands are allowed"),
763 MAX_IMMEDIATE_OPERANDS
);
766 expP
= &im_expressions
[i
.imm_operands
++];
767 memset (expP
, 0, sizeof(*expP
));
768 expP
->X_op
= O_symbol
;
769 expP
->X_add_symbol
= intel_state
.seg
;
770 i
.op
[this_operand
].imms
= expP
;
772 resolve_expression (expP
);
773 operand_type_set (&types
, ~0);
774 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state
.seg
),
775 expP
, types
, operand_string
))
777 if (i
.operands
< MAX_OPERANDS
)
779 this_operand
= i
.operands
++;
780 i
.types
[this_operand
].bitfield
.unspecified
= 1;
782 if (suffix
== LONG_DOUBLE_MNEM_SUFFIX
)
784 intel_state
.seg
= NULL
;
785 intel_state
.is_mem
= 0;
789 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
792 if (i
.types
[this_operand
].bitfield
.jumpabsolute
)
793 intel_state
.is_mem
|= 1;
795 else if (intel_state
.seg
)
796 intel_state
.is_mem
|= 1;
798 if (i
.op
[this_operand
].regs
)
800 i386_operand_type temp
;
802 /* Register operand. */
803 if (intel_state
.base
|| intel_state
.index
|| intel_state
.seg
)
805 as_bad (_("invalid operand"));
809 temp
= i
.op
[this_operand
].regs
->reg_type
;
810 temp
.bitfield
.baseindex
= 0;
811 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
813 i
.types
[this_operand
].bitfield
.unspecified
= 0;
816 else if (intel_state
.base
819 || intel_state
.is_mem
)
821 /* Memory operand. */
822 if ((int) i
.mem_operands
823 >= 2 - !current_templates
->start
->opcode_modifier
.isstring
)
827 call 0x9090,0x90909090
828 lcall 0x9090,0x90909090
829 jmp 0x9090,0x90909090
830 ljmp 0x9090,0x90909090
833 if ((current_templates
->start
->opcode_modifier
.jumpintersegment
834 || current_templates
->start
->opcode_modifier
.jumpdword
835 || current_templates
->start
->opcode_modifier
.jump
)
837 && intel_state
.seg
== NULL
838 && i
.mem_operands
== 1
839 && i
.disp_operands
== 1
840 && intel_state
.op_modifier
== O_absent
)
842 /* Try to process the first operand as immediate, */
844 if (i386_finalize_immediate (exp_seg
, i
.op
[0].imms
,
845 intel_state
.reloc_types
,
849 expP
= &im_expressions
[0];
850 i
.op
[this_operand
].imms
= expP
;
853 /* Try to process the second operand as immediate, */
854 if (i386_finalize_immediate (exp_seg
, expP
,
855 intel_state
.reloc_types
,
861 i
.types
[0].bitfield
.mem
= 0;
862 i
.types
[0].bitfield
.disp16
= 0;
863 i
.types
[0].bitfield
.disp32
= 0;
864 i
.types
[0].bitfield
.disp32s
= 0;
870 as_bad (_("too many memory references for `%s'"),
871 current_templates
->start
->name
);
875 expP
= &disp_expressions
[i
.disp_operands
];
876 memcpy (expP
, &exp
, sizeof(exp
));
877 resolve_expression (expP
);
879 if (expP
->X_op
!= O_constant
880 || expP
->X_add_number
881 || (!intel_state
.base
882 && !intel_state
.index
))
884 i
.op
[this_operand
].disps
= expP
;
887 if (flag_code
== CODE_64BIT
)
889 i
.types
[this_operand
].bitfield
.disp32
= 1;
890 if (!i
.prefix
[ADDR_PREFIX
])
892 i
.types
[this_operand
].bitfield
.disp64
= 1;
893 i
.types
[this_operand
].bitfield
.disp32s
= 1;
896 else if (!i
.prefix
[ADDR_PREFIX
] ^ (flag_code
== CODE_16BIT
))
897 i
.types
[this_operand
].bitfield
.disp32
= 1;
899 i
.types
[this_operand
].bitfield
.disp16
= 1;
901 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
903 * exp_seg is used only for verification in
904 * i386_finalize_displacement, and we can end up seeing reg_section
905 * here - but we know we removed all registers from the expression
906 * (or error-ed on any remaining ones) in i386_intel_simplify. I
907 * consider the check in i386_finalize_displacement bogus anyway, in
908 * particular because it doesn't allow for expr_section, so I'd
909 * rather see that check (and the similar one in
910 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
911 * expert I can't really say whether that would have other bad side
914 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
915 && exp_seg
== reg_section
)
916 exp_seg
= expP
->X_op
!= O_constant
? undefined_section
920 if (!i386_finalize_displacement (exp_seg
, expP
,
921 intel_state
.reloc_types
,
926 if (intel_state
.base
|| intel_state
.index
)
927 i
.types
[this_operand
].bitfield
.baseindex
= 1;
933 expP
= symbol_get_value_expression (intel_state
.seg
);
934 if (expP
->X_op
!= O_full_ptr
)
936 intel_state
.seg
= expP
->X_add_symbol
;
938 if (expP
->X_op
!= O_register
)
940 as_bad (_("segment register name expected"));
943 if (!i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.sreg2
944 && !i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.sreg3
)
946 as_bad (_("invalid use of register"));
949 switch (i386_regtab
[expP
->X_add_number
].reg_num
)
951 case 0: i
.seg
[i
.mem_operands
] = &es
; break;
952 case 1: i
.seg
[i
.mem_operands
] = &cs
; break;
953 case 2: i
.seg
[i
.mem_operands
] = &ss
; break;
954 case 3: i
.seg
[i
.mem_operands
] = &ds
; break;
955 case 4: i
.seg
[i
.mem_operands
] = &fs
; break;
956 case 5: i
.seg
[i
.mem_operands
] = &gs
; break;
957 case RegFlat
: i
.seg
[i
.mem_operands
] = NULL
; break;
961 /* Swap base and index in 16-bit memory operands like
962 [si+bx]. Since i386_index_check is also used in AT&T
963 mode we have to do that here. */
966 && intel_state
.base
->reg_type
.bitfield
.reg16
967 && intel_state
.index
->reg_type
.bitfield
.reg16
968 && intel_state
.base
->reg_num
>= 6
969 && intel_state
.index
->reg_num
< 6)
971 i
.base_reg
= intel_state
.index
;
972 i
.index_reg
= intel_state
.base
;
976 i
.base_reg
= intel_state
.base
;
977 i
.index_reg
= intel_state
.index
;
980 if (!i386_index_check (operand_string
))
983 i
.types
[this_operand
].bitfield
.mem
= 1;
989 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
991 as_bad (_("at most %d immediate operands are allowed"),
992 MAX_IMMEDIATE_OPERANDS
);
996 expP
= &im_expressions
[i
.imm_operands
++];
997 i
.op
[this_operand
].imms
= expP
;
1000 return i386_finalize_immediate (exp_seg
, expP
, intel_state
.reloc_types
,