1 /* tc-i386.c -- Assemble Intel syntax code for ix86/x86-64
2 Copyright (C) 2009-2014 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 multipication 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
,
145 (i
.bnd_prefix
!= NULL
148 if (!gotfree_input_line
)
150 free (gotfree_input_line
);
151 *input_line_pointer
++ = '+';
152 memset (input_line_pointer
, '0', adjust
- 1);
153 input_line_pointer
[adjust
- 1] = ' ';
161 for (j
= 0; i386_operators
[j
].name
; ++j
)
162 if (strcasecmp (i386_operators
[j
].name
, name
) == 0)
164 if (i386_operators
[j
].operands
165 && i386_operators
[j
].operands
!= operands
)
167 return i386_operators
[j
].op
;
170 for (j
= 0; i386_types
[j
].name
; ++j
)
171 if (strcasecmp (i386_types
[j
].name
, name
) == 0)
173 if (i386_types
[j
].name
&& *pc
== ' ')
175 char *pname
= ++input_line_pointer
;
176 char c
= get_symbol_end ();
178 if (strcasecmp (pname
, "ptr") == 0)
182 if (intel_syntax
> 0 || operands
!= 1)
184 return i386_types
[j
].op
;
187 *input_line_pointer
= c
;
188 input_line_pointer
= pname
- 1;
194 static int i386_intel_parse_name (const char *name
, expressionS
*e
)
198 if (! strcmp (name
, "$"))
200 current_location (e
);
204 for (j
= 0; i386_types
[j
].name
; ++j
)
205 if (strcasecmp(i386_types
[j
].name
, name
) == 0)
207 e
->X_op
= O_constant
;
208 e
->X_add_number
= i386_types
[j
].sz
[flag_code
];
209 e
->X_add_symbol
= NULL
;
210 e
->X_op_symbol
= NULL
;
217 static INLINE
int i386_intel_check (const reg_entry
*rreg
,
218 const reg_entry
*base
,
219 const reg_entry
*iindex
)
221 if ((this_operand
>= 0
222 && rreg
!= i
.op
[this_operand
].regs
)
223 || base
!= intel_state
.base
224 || iindex
!= intel_state
.index
)
226 as_bad (_("invalid use of register"));
232 static INLINE
void i386_intel_fold (expressionS
*e
, symbolS
*sym
)
234 expressionS
*exp
= symbol_get_value_expression (sym
);
235 if (S_GET_SEGMENT (sym
) == absolute_section
)
237 offsetT val
= e
->X_add_number
;
240 e
->X_add_number
+= val
;
244 if (exp
->X_op
== O_symbol
245 && strcmp (S_GET_NAME (exp
->X_add_symbol
),
246 GLOBAL_OFFSET_TABLE_NAME
) == 0)
247 sym
= exp
->X_add_symbol
;
248 e
->X_add_symbol
= sym
;
249 e
->X_op_symbol
= NULL
;
255 i386_intel_simplify_register (expressionS
*e
)
259 if (this_operand
< 0 || intel_state
.in_offset
)
261 as_bad (_("invalid use of register"));
265 if (e
->X_op
== O_register
)
266 reg_num
= e
->X_add_number
;
268 reg_num
= e
->X_md
- 1;
270 if (!intel_state
.in_bracket
)
272 if (i
.op
[this_operand
].regs
)
274 as_bad (_("invalid use of register"));
277 if (i386_regtab
[reg_num
].reg_type
.bitfield
.sreg3
278 && i386_regtab
[reg_num
].reg_num
== RegFlat
)
280 as_bad (_("invalid use of pseudo-register"));
283 i
.op
[this_operand
].regs
= i386_regtab
+ reg_num
;
285 else if (!intel_state
.index
286 && (i386_regtab
[reg_num
].reg_type
.bitfield
.regxmm
287 || i386_regtab
[reg_num
].reg_type
.bitfield
.regymm
288 || i386_regtab
[reg_num
].reg_type
.bitfield
.regzmm
))
289 intel_state
.index
= i386_regtab
+ reg_num
;
290 else if (!intel_state
.base
&& !intel_state
.in_scale
)
291 intel_state
.base
= i386_regtab
+ reg_num
;
292 else if (!intel_state
.index
)
294 if (intel_state
.in_scale
295 || current_templates
->start
->base_opcode
== 0xf30f1b /* bndmk */
296 || (current_templates
->start
->base_opcode
& ~1) == 0x0f1a /* bnd{ld,st}x */
297 || i386_regtab
[reg_num
].reg_type
.bitfield
.baseindex
)
298 intel_state
.index
= i386_regtab
+ reg_num
;
301 /* Convert base to index and make ESP/RSP the base. */
302 intel_state
.index
= intel_state
.base
;
303 intel_state
.base
= i386_regtab
+ reg_num
;
308 /* esp is invalid as index */
309 intel_state
.index
= i386_regtab
+ REGNAM_EAX
+ ESP_REG_NUM
;
314 static int i386_intel_simplify (expressionS
*);
316 static INLINE
int i386_intel_simplify_symbol(symbolS
*sym
)
318 int ret
= i386_intel_simplify (symbol_get_value_expression (sym
));
322 S_SET_SEGMENT(sym
, absolute_section
);
328 static int i386_intel_simplify (expressionS
*e
)
330 const reg_entry
*the_reg
= (this_operand
>= 0
331 ? i
.op
[this_operand
].regs
: NULL
);
332 const reg_entry
*base
= intel_state
.base
;
333 const reg_entry
*state_index
= intel_state
.index
;
344 if (!i386_intel_simplify_symbol (e
->X_add_symbol
)
345 || !i386_intel_check(the_reg
, intel_state
.base
,
349 if (!intel_state
.in_offset
)
350 ++intel_state
.in_bracket
;
351 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
352 if (!intel_state
.in_offset
)
353 --intel_state
.in_bracket
;
359 i386_intel_fold (e
, e
->X_op_symbol
);
363 intel_state
.has_offset
= 1;
364 ++intel_state
.in_offset
;
365 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
366 --intel_state
.in_offset
;
367 if (!ret
|| !i386_intel_check(the_reg
, base
, state_index
))
369 i386_intel_fold (e
, e
->X_add_symbol
);
384 if (intel_state
.op_modifier
== O_absent
)
385 intel_state
.op_modifier
= e
->X_op
;
388 if (symbol_get_value_expression (e
->X_add_symbol
)->X_op
391 as_bad (_("invalid use of register"));
394 if (!i386_intel_simplify_symbol (e
->X_add_symbol
))
396 i386_intel_fold (e
, e
->X_add_symbol
);
400 if (symbol_get_value_expression (e
->X_op_symbol
)->X_op
403 as_bad (_("invalid use of register"));
406 if (!i386_intel_simplify_symbol (e
->X_op_symbol
)
407 || !i386_intel_check(the_reg
, intel_state
.base
,
410 if (!intel_state
.in_offset
)
411 intel_state
.seg
= e
->X_add_symbol
;
412 i386_intel_fold (e
, e
->X_op_symbol
);
416 if (this_operand
>= 0 && intel_state
.in_bracket
)
418 expressionS
*scale
= NULL
;
419 int has_index
= (intel_state
.index
!= NULL
);
421 if (!intel_state
.in_scale
++)
422 intel_state
.scale_factor
= 1;
424 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
425 if (ret
&& !has_index
&& intel_state
.index
)
426 scale
= symbol_get_value_expression (e
->X_op_symbol
);
429 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
430 if (ret
&& !scale
&& !has_index
&& intel_state
.index
)
431 scale
= symbol_get_value_expression (e
->X_add_symbol
);
435 resolve_expression (scale
);
436 if (scale
->X_op
!= O_constant
437 || intel_state
.index
->reg_type
.bitfield
.reg16
)
438 scale
->X_add_number
= 0;
439 intel_state
.scale_factor
*= scale
->X_add_number
;
442 --intel_state
.in_scale
;
446 if (!intel_state
.in_scale
)
447 switch (intel_state
.scale_factor
)
450 i
.log2_scale_factor
= 0;
453 i
.log2_scale_factor
= 1;
456 i
.log2_scale_factor
= 2;
459 i
.log2_scale_factor
= 3;
462 /* esp is invalid as index */
463 intel_state
.index
= i386_regtab
+ REGNAM_EAX
+ ESP_REG_NUM
;
472 ret
= i386_intel_simplify_register (e
);
475 gas_assert (e
->X_add_number
< (unsigned short) -1);
476 e
->X_md
= (unsigned short) e
->X_add_number
+ 1;
477 e
->X_op
= O_constant
;
484 return i386_intel_simplify_register (e
);
490 && !i386_intel_simplify_symbol (e
->X_add_symbol
))
492 if (e
->X_op
== O_add
|| e
->X_op
== O_subtract
)
494 base
= intel_state
.base
;
495 state_index
= intel_state
.index
;
497 if (!i386_intel_check (the_reg
, base
, state_index
)
499 && !i386_intel_simplify_symbol (e
->X_op_symbol
))
500 || !i386_intel_check (the_reg
,
502 ? base
: intel_state
.base
),
504 ? state_index
: intel_state
.index
)))
509 if (this_operand
>= 0
510 && e
->X_op
== O_symbol
511 && !intel_state
.in_offset
)
513 segT seg
= S_GET_SEGMENT (e
->X_add_symbol
);
515 if (seg
!= absolute_section
516 && seg
!= reg_section
517 && seg
!= expr_section
)
518 intel_state
.is_mem
|= 2 - !intel_state
.in_bracket
;
524 int i386_need_index_operator (void)
526 return intel_syntax
< 0;
530 i386_intel_operand (char *operand_string
, int got_a_float
)
532 char *saved_input_line_pointer
, *buf
;
534 expressionS exp
, *expP
;
538 /* Handle vector immediates. */
539 if (RC_SAE_immediate (operand_string
))
542 /* Initialize state structure. */
543 intel_state
.op_modifier
= O_absent
;
544 intel_state
.is_mem
= 0;
545 intel_state
.is_indirect
= 0;
546 intel_state
.has_offset
= 0;
547 intel_state
.base
= NULL
;
548 intel_state
.index
= NULL
;
549 intel_state
.seg
= NULL
;
550 operand_type_set (&intel_state
.reloc_types
, ~0);
551 gas_assert (!intel_state
.in_offset
);
552 gas_assert (!intel_state
.in_bracket
);
553 gas_assert (!intel_state
.in_scale
);
555 saved_input_line_pointer
= input_line_pointer
;
556 input_line_pointer
= buf
= xstrdup (operand_string
);
559 memset (&exp
, 0, sizeof(exp
));
560 exp_seg
= expression (&exp
);
561 ret
= i386_intel_simplify (&exp
);
566 /* Handle vector operations. */
567 if (*input_line_pointer
== '{')
569 char *end
= check_VecOperations (input_line_pointer
, NULL
);
571 input_line_pointer
= end
;
576 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
578 as_bad (_("junk `%s' after expression"), input_line_pointer
);
581 else if (exp
.X_op
== O_illegal
|| exp
.X_op
== O_absent
)
583 as_bad (_("invalid expression"));
586 else if (!intel_state
.has_offset
587 && input_line_pointer
> buf
588 && *(input_line_pointer
- 1) == ']')
590 intel_state
.is_mem
|= 1;
591 intel_state
.is_indirect
= 1;
594 input_line_pointer
= saved_input_line_pointer
;
597 gas_assert (!intel_state
.in_offset
);
598 gas_assert (!intel_state
.in_bracket
);
599 gas_assert (!intel_state
.in_scale
);
604 if (intel_state
.op_modifier
!= O_absent
605 && current_templates
->start
->base_opcode
!= 0x8d /* lea */)
607 i
.types
[this_operand
].bitfield
.unspecified
= 0;
609 switch (intel_state
.op_modifier
)
612 i
.types
[this_operand
].bitfield
.byte
= 1;
613 suffix
= BYTE_MNEM_SUFFIX
;
617 i
.types
[this_operand
].bitfield
.word
= 1;
618 if ((current_templates
->start
->name
[0] == 'l'
619 && current_templates
->start
->name
[2] == 's'
620 && current_templates
->start
->name
[3] == 0)
621 || current_templates
->start
->base_opcode
== 0x62 /* bound */)
622 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
623 else if (got_a_float
== 2) /* "fi..." */
624 suffix
= SHORT_MNEM_SUFFIX
;
626 suffix
= WORD_MNEM_SUFFIX
;
630 i
.types
[this_operand
].bitfield
.dword
= 1;
631 if ((current_templates
->start
->name
[0] == 'l'
632 && current_templates
->start
->name
[2] == 's'
633 && current_templates
->start
->name
[3] == 0)
634 || current_templates
->start
->base_opcode
== 0x62 /* bound */)
635 suffix
= WORD_MNEM_SUFFIX
;
636 else if (flag_code
== CODE_16BIT
637 && (current_templates
->start
->opcode_modifier
.jump
638 || current_templates
->start
->opcode_modifier
.jumpdword
))
639 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
640 else if (got_a_float
== 1) /* "f..." */
641 suffix
= SHORT_MNEM_SUFFIX
;
643 suffix
= LONG_MNEM_SUFFIX
;
647 i
.types
[this_operand
].bitfield
.fword
= 1;
648 if (current_templates
->start
->name
[0] == 'l'
649 && current_templates
->start
->name
[2] == 's'
650 && current_templates
->start
->name
[3] == 0)
651 suffix
= LONG_MNEM_SUFFIX
;
652 else if (!got_a_float
)
654 if (flag_code
== CODE_16BIT
)
655 add_prefix (DATA_PREFIX_OPCODE
);
656 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
659 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
663 i
.types
[this_operand
].bitfield
.qword
= 1;
664 if (current_templates
->start
->base_opcode
== 0x62 /* bound */
665 || got_a_float
== 1) /* "f..." */
666 suffix
= LONG_MNEM_SUFFIX
;
668 suffix
= QWORD_MNEM_SUFFIX
;
672 i
.types
[this_operand
].bitfield
.tbyte
= 1;
673 if (got_a_float
== 1)
674 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
676 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
681 i
.types
[this_operand
].bitfield
.xmmword
= 1;
682 suffix
= XMMWORD_MNEM_SUFFIX
;
686 i
.types
[this_operand
].bitfield
.ymmword
= 1;
687 suffix
= YMMWORD_MNEM_SUFFIX
;
691 i
.types
[this_operand
].bitfield
.zmmword
= 1;
692 suffix
= ZMMWORD_MNEM_SUFFIX
;
696 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
699 if (!current_templates
->start
->opcode_modifier
.jump
700 && !current_templates
->start
->opcode_modifier
.jumpdword
)
701 suffix
= got_a_float
/* so it will cause an error */
703 : LONG_DOUBLE_MNEM_SUFFIX
;
707 BAD_CASE (intel_state
.op_modifier
);
713 else if (i
.suffix
!= suffix
)
715 as_bad (_("conflicting operand size modifiers"));
720 /* Operands for jump/call need special consideration. */
721 if (current_templates
->start
->opcode_modifier
.jump
722 || current_templates
->start
->opcode_modifier
.jumpdword
723 || current_templates
->start
->opcode_modifier
.jumpintersegment
)
725 if (i
.op
[this_operand
].regs
728 || intel_state
.is_mem
> 1)
729 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
731 switch (intel_state
.op_modifier
)
735 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
737 intel_state
.is_mem
= 1;
741 if (!intel_state
.seg
)
743 intel_state
.is_mem
= 1;
744 if (intel_state
.op_modifier
== O_absent
)
746 if (intel_state
.is_indirect
== 1)
747 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
750 as_bad (_("cannot infer the segment part of the operand"));
753 else if (S_GET_SEGMENT (intel_state
.seg
) == reg_section
)
754 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
757 i386_operand_type types
;
759 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
761 as_bad (_("at most %d immediate operands are allowed"),
762 MAX_IMMEDIATE_OPERANDS
);
765 expP
= &im_expressions
[i
.imm_operands
++];
766 memset (expP
, 0, sizeof(*expP
));
767 expP
->X_op
= O_symbol
;
768 expP
->X_add_symbol
= intel_state
.seg
;
769 i
.op
[this_operand
].imms
= expP
;
771 resolve_expression (expP
);
772 operand_type_set (&types
, ~0);
773 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state
.seg
),
774 expP
, types
, operand_string
))
776 if (i
.operands
< MAX_OPERANDS
)
778 this_operand
= i
.operands
++;
779 i
.types
[this_operand
].bitfield
.unspecified
= 1;
781 if (suffix
== LONG_DOUBLE_MNEM_SUFFIX
)
783 intel_state
.seg
= NULL
;
784 intel_state
.is_mem
= 0;
788 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
791 if (i
.types
[this_operand
].bitfield
.jumpabsolute
)
792 intel_state
.is_mem
|= 1;
794 else if (intel_state
.seg
)
795 intel_state
.is_mem
|= 1;
797 if (i
.op
[this_operand
].regs
)
799 i386_operand_type temp
;
801 /* Register operand. */
802 if (intel_state
.base
|| intel_state
.index
|| intel_state
.seg
)
804 as_bad (_("invalid operand"));
808 temp
= i
.op
[this_operand
].regs
->reg_type
;
809 temp
.bitfield
.baseindex
= 0;
810 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
812 i
.types
[this_operand
].bitfield
.unspecified
= 0;
815 else if (intel_state
.base
818 || intel_state
.is_mem
)
820 /* Memory operand. */
821 if ((int) i
.mem_operands
822 >= 2 - !current_templates
->start
->opcode_modifier
.isstring
)
826 call 0x9090,0x90909090
827 lcall 0x9090,0x90909090
828 jmp 0x9090,0x90909090
829 ljmp 0x9090,0x90909090
832 if ((current_templates
->start
->opcode_modifier
.jumpintersegment
833 || current_templates
->start
->opcode_modifier
.jumpdword
834 || current_templates
->start
->opcode_modifier
.jump
)
836 && intel_state
.seg
== NULL
837 && i
.mem_operands
== 1
838 && i
.disp_operands
== 1
839 && intel_state
.op_modifier
== O_absent
)
841 /* Try to process the first operand as immediate, */
843 if (i386_finalize_immediate (exp_seg
, i
.op
[0].imms
,
844 intel_state
.reloc_types
,
848 expP
= &im_expressions
[0];
849 i
.op
[this_operand
].imms
= expP
;
852 /* Try to process the second operand as immediate, */
853 if (i386_finalize_immediate (exp_seg
, expP
,
854 intel_state
.reloc_types
,
860 i
.types
[0].bitfield
.mem
= 0;
861 i
.types
[0].bitfield
.disp16
= 0;
862 i
.types
[0].bitfield
.disp32
= 0;
863 i
.types
[0].bitfield
.disp32s
= 0;
869 as_bad (_("too many memory references for `%s'"),
870 current_templates
->start
->name
);
874 expP
= &disp_expressions
[i
.disp_operands
];
875 memcpy (expP
, &exp
, sizeof(exp
));
876 resolve_expression (expP
);
878 if (expP
->X_op
!= O_constant
879 || expP
->X_add_number
880 || (!intel_state
.base
881 && !intel_state
.index
))
883 i
.op
[this_operand
].disps
= expP
;
886 if (flag_code
== CODE_64BIT
)
888 i
.types
[this_operand
].bitfield
.disp32
= 1;
889 if (!i
.prefix
[ADDR_PREFIX
])
891 i
.types
[this_operand
].bitfield
.disp64
= 1;
892 i
.types
[this_operand
].bitfield
.disp32s
= 1;
895 else if (!i
.prefix
[ADDR_PREFIX
] ^ (flag_code
== CODE_16BIT
))
896 i
.types
[this_operand
].bitfield
.disp32
= 1;
898 i
.types
[this_operand
].bitfield
.disp16
= 1;
900 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
902 * exp_seg is used only for verification in
903 * i386_finalize_displacement, and we can end up seeing reg_section
904 * here - but we know we removed all registers from the expression
905 * (or error-ed on any remaining ones) in i386_intel_simplify. I
906 * consider the check in i386_finalize_displacement bogus anyway, in
907 * particular because it doesn't allow for expr_section, so I'd
908 * rather see that check (and the similar one in
909 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
910 * expert I can't really say whether that would have other bad side
913 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
914 && exp_seg
== reg_section
)
915 exp_seg
= expP
->X_op
!= O_constant
? undefined_section
919 if (!i386_finalize_displacement (exp_seg
, expP
,
920 intel_state
.reloc_types
,
925 if (intel_state
.base
|| intel_state
.index
)
926 i
.types
[this_operand
].bitfield
.baseindex
= 1;
932 expP
= symbol_get_value_expression (intel_state
.seg
);
933 if (expP
->X_op
!= O_full_ptr
)
935 intel_state
.seg
= expP
->X_add_symbol
;
937 if (expP
->X_op
!= O_register
)
939 as_bad (_("segment register name expected"));
942 if (!i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.sreg2
943 && !i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.sreg3
)
945 as_bad (_("invalid use of register"));
948 switch (i386_regtab
[expP
->X_add_number
].reg_num
)
950 case 0: i
.seg
[i
.mem_operands
] = &es
; break;
951 case 1: i
.seg
[i
.mem_operands
] = &cs
; break;
952 case 2: i
.seg
[i
.mem_operands
] = &ss
; break;
953 case 3: i
.seg
[i
.mem_operands
] = &ds
; break;
954 case 4: i
.seg
[i
.mem_operands
] = &fs
; break;
955 case 5: i
.seg
[i
.mem_operands
] = &gs
; break;
956 case RegFlat
: i
.seg
[i
.mem_operands
] = NULL
; break;
960 /* Swap base and index in 16-bit memory operands like
961 [si+bx]. Since i386_index_check is also used in AT&T
962 mode we have to do that here. */
965 && intel_state
.base
->reg_type
.bitfield
.reg16
966 && intel_state
.index
->reg_type
.bitfield
.reg16
967 && intel_state
.base
->reg_num
>= 6
968 && intel_state
.index
->reg_num
< 6)
970 i
.base_reg
= intel_state
.index
;
971 i
.index_reg
= intel_state
.base
;
975 i
.base_reg
= intel_state
.base
;
976 i
.index_reg
= intel_state
.index
;
979 if (!i386_index_check (operand_string
))
982 i
.types
[this_operand
].bitfield
.mem
= 1;
988 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
990 as_bad (_("at most %d immediate operands are allowed"),
991 MAX_IMMEDIATE_OPERANDS
);
995 expP
= &im_expressions
[i
.imm_operands
++];
996 i
.op
[this_operand
].imms
= expP
;
999 return i386_finalize_immediate (exp_seg
, expP
, intel_state
.reloc_types
,