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
);
147 if (!gotfree_input_line
)
149 free (gotfree_input_line
);
150 *input_line_pointer
++ = '+';
151 memset (input_line_pointer
, '0', adjust
- 1);
152 input_line_pointer
[adjust
- 1] = ' ';
160 for (j
= 0; i386_operators
[j
].name
; ++j
)
161 if (strcasecmp (i386_operators
[j
].name
, name
) == 0)
163 if (i386_operators
[j
].operands
164 && i386_operators
[j
].operands
!= operands
)
166 return i386_operators
[j
].op
;
169 for (j
= 0; i386_types
[j
].name
; ++j
)
170 if (strcasecmp (i386_types
[j
].name
, name
) == 0)
172 if (i386_types
[j
].name
&& *pc
== ' ')
174 char *pname
= ++input_line_pointer
;
175 char c
= get_symbol_end ();
177 if (strcasecmp (pname
, "ptr") == 0)
181 if (intel_syntax
> 0 || operands
!= 1)
183 return i386_types
[j
].op
;
186 *input_line_pointer
= c
;
187 input_line_pointer
= pname
- 1;
193 static int i386_intel_parse_name (const char *name
, expressionS
*e
)
197 if (! strcmp (name
, "$"))
199 current_location (e
);
203 for (j
= 0; i386_types
[j
].name
; ++j
)
204 if (strcasecmp(i386_types
[j
].name
, name
) == 0)
206 e
->X_op
= O_constant
;
207 e
->X_add_number
= i386_types
[j
].sz
[flag_code
];
208 e
->X_add_symbol
= NULL
;
209 e
->X_op_symbol
= NULL
;
216 static INLINE
int i386_intel_check (const reg_entry
*rreg
,
217 const reg_entry
*base
,
218 const reg_entry
*iindex
)
220 if ((this_operand
>= 0
221 && rreg
!= i
.op
[this_operand
].regs
)
222 || base
!= intel_state
.base
223 || iindex
!= intel_state
.index
)
225 as_bad (_("invalid use of register"));
231 static INLINE
void i386_intel_fold (expressionS
*e
, symbolS
*sym
)
233 expressionS
*exp
= symbol_get_value_expression (sym
);
234 if (S_GET_SEGMENT (sym
) == absolute_section
)
236 offsetT val
= e
->X_add_number
;
239 e
->X_add_number
+= val
;
243 if (exp
->X_op
== O_symbol
244 && strcmp (S_GET_NAME (exp
->X_add_symbol
),
245 GLOBAL_OFFSET_TABLE_NAME
) == 0)
246 sym
= exp
->X_add_symbol
;
247 e
->X_add_symbol
= sym
;
248 e
->X_op_symbol
= NULL
;
254 i386_intel_simplify_register (expressionS
*e
)
258 if (this_operand
< 0 || intel_state
.in_offset
)
260 as_bad (_("invalid use of register"));
264 if (e
->X_op
== O_register
)
265 reg_num
= e
->X_add_number
;
267 reg_num
= e
->X_md
- 1;
269 if (!intel_state
.in_bracket
)
271 if (i
.op
[this_operand
].regs
)
273 as_bad (_("invalid use of register"));
276 if (i386_regtab
[reg_num
].reg_type
.bitfield
.sreg3
277 && i386_regtab
[reg_num
].reg_num
== RegFlat
)
279 as_bad (_("invalid use of pseudo-register"));
282 i
.op
[this_operand
].regs
= i386_regtab
+ reg_num
;
284 else if (!intel_state
.index
285 && (i386_regtab
[reg_num
].reg_type
.bitfield
.regxmm
286 || i386_regtab
[reg_num
].reg_type
.bitfield
.regymm
287 || i386_regtab
[reg_num
].reg_type
.bitfield
.regzmm
))
288 intel_state
.index
= i386_regtab
+ reg_num
;
289 else if (!intel_state
.base
&& !intel_state
.in_scale
)
290 intel_state
.base
= i386_regtab
+ reg_num
;
291 else if (!intel_state
.index
)
293 if (intel_state
.in_scale
294 || i386_regtab
[reg_num
].reg_type
.bitfield
.baseindex
)
295 intel_state
.index
= i386_regtab
+ reg_num
;
298 /* Convert base to index and make ESP/RSP the base. */
299 intel_state
.index
= intel_state
.base
;
300 intel_state
.base
= i386_regtab
+ reg_num
;
305 /* esp is invalid as index */
306 intel_state
.index
= i386_regtab
+ REGNAM_EAX
+ ESP_REG_NUM
;
311 static int i386_intel_simplify (expressionS
*);
313 static INLINE
int i386_intel_simplify_symbol(symbolS
*sym
)
315 int ret
= i386_intel_simplify (symbol_get_value_expression (sym
));
319 S_SET_SEGMENT(sym
, absolute_section
);
325 static int i386_intel_simplify (expressionS
*e
)
327 const reg_entry
*the_reg
= (this_operand
>= 0
328 ? i
.op
[this_operand
].regs
: NULL
);
329 const reg_entry
*base
= intel_state
.base
;
330 const reg_entry
*state_index
= intel_state
.index
;
341 if (!i386_intel_simplify_symbol (e
->X_add_symbol
)
342 || !i386_intel_check(the_reg
, intel_state
.base
,
346 if (!intel_state
.in_offset
)
347 ++intel_state
.in_bracket
;
348 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
349 if (!intel_state
.in_offset
)
350 --intel_state
.in_bracket
;
356 i386_intel_fold (e
, e
->X_op_symbol
);
360 intel_state
.has_offset
= 1;
361 ++intel_state
.in_offset
;
362 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
363 --intel_state
.in_offset
;
364 if (!ret
|| !i386_intel_check(the_reg
, base
, state_index
))
366 i386_intel_fold (e
, e
->X_add_symbol
);
381 if (intel_state
.op_modifier
== O_absent
)
382 intel_state
.op_modifier
= e
->X_op
;
385 if (symbol_get_value_expression (e
->X_add_symbol
)->X_op
388 as_bad (_("invalid use of register"));
391 if (!i386_intel_simplify_symbol (e
->X_add_symbol
))
393 i386_intel_fold (e
, e
->X_add_symbol
);
397 if (symbol_get_value_expression (e
->X_op_symbol
)->X_op
400 as_bad (_("invalid use of register"));
403 if (!i386_intel_simplify_symbol (e
->X_op_symbol
)
404 || !i386_intel_check(the_reg
, intel_state
.base
,
407 if (!intel_state
.in_offset
)
408 intel_state
.seg
= e
->X_add_symbol
;
409 i386_intel_fold (e
, e
->X_op_symbol
);
413 if (this_operand
>= 0 && intel_state
.in_bracket
)
415 expressionS
*scale
= NULL
;
417 if (intel_state
.index
)
420 if (!intel_state
.in_scale
++)
421 intel_state
.scale_factor
= 1;
423 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
424 if (ret
&& !scale
&& intel_state
.index
)
425 scale
= symbol_get_value_expression (e
->X_op_symbol
);
428 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
429 if (ret
&& !scale
&& intel_state
.index
)
430 scale
= symbol_get_value_expression (e
->X_add_symbol
);
432 if (ret
&& scale
&& (scale
+ 1))
434 resolve_expression (scale
);
435 if (scale
->X_op
!= O_constant
436 || intel_state
.index
->reg_type
.bitfield
.reg16
)
437 scale
->X_add_number
= 0;
438 intel_state
.scale_factor
*= scale
->X_add_number
;
441 --intel_state
.in_scale
;
445 if (!intel_state
.in_scale
)
446 switch (intel_state
.scale_factor
)
449 i
.log2_scale_factor
= 0;
452 i
.log2_scale_factor
= 1;
455 i
.log2_scale_factor
= 2;
458 i
.log2_scale_factor
= 3;
461 /* esp is invalid as index */
462 intel_state
.index
= i386_regtab
+ REGNAM_EAX
+ ESP_REG_NUM
;
471 ret
= i386_intel_simplify_register (e
);
474 gas_assert (e
->X_add_number
< (unsigned short) -1);
475 e
->X_md
= (unsigned short) e
->X_add_number
+ 1;
476 e
->X_op
= O_constant
;
483 return i386_intel_simplify_register (e
);
489 && !i386_intel_simplify_symbol (e
->X_add_symbol
))
491 if (e
->X_op
== O_add
|| e
->X_op
== O_subtract
)
493 base
= intel_state
.base
;
494 state_index
= intel_state
.index
;
496 if (!i386_intel_check (the_reg
, base
, state_index
)
498 && !i386_intel_simplify_symbol (e
->X_op_symbol
))
499 || !i386_intel_check (the_reg
,
501 ? base
: intel_state
.base
),
503 ? state_index
: intel_state
.index
)))
508 if (this_operand
>= 0
509 && e
->X_op
== O_symbol
510 && !intel_state
.in_offset
)
512 segT seg
= S_GET_SEGMENT (e
->X_add_symbol
);
514 if (seg
!= absolute_section
515 && seg
!= reg_section
516 && seg
!= expr_section
)
517 intel_state
.is_mem
|= 2 - !intel_state
.in_bracket
;
523 int i386_need_index_operator (void)
525 return intel_syntax
< 0;
529 i386_intel_operand (char *operand_string
, int got_a_float
)
531 char *saved_input_line_pointer
, *buf
;
533 expressionS exp
, *expP
;
537 /* Handle vector immediates. */
538 if (RC_SAE_immediate (operand_string
))
541 /* Initialize state structure. */
542 intel_state
.op_modifier
= O_absent
;
543 intel_state
.is_mem
= 0;
544 intel_state
.is_indirect
= 0;
545 intel_state
.has_offset
= 0;
546 intel_state
.base
= NULL
;
547 intel_state
.index
= NULL
;
548 intel_state
.seg
= NULL
;
549 operand_type_set (&intel_state
.reloc_types
, ~0);
550 gas_assert (!intel_state
.in_offset
);
551 gas_assert (!intel_state
.in_bracket
);
552 gas_assert (!intel_state
.in_scale
);
554 saved_input_line_pointer
= input_line_pointer
;
555 input_line_pointer
= buf
= xstrdup (operand_string
);
558 memset (&exp
, 0, sizeof(exp
));
559 exp_seg
= expression (&exp
);
560 ret
= i386_intel_simplify (&exp
);
565 /* Handle vector operations. */
566 if (*input_line_pointer
== '{')
568 char *end
= check_VecOperations (input_line_pointer
, NULL
);
570 input_line_pointer
= end
;
575 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
577 as_bad (_("junk `%s' after expression"), input_line_pointer
);
580 else if (exp
.X_op
== O_illegal
|| exp
.X_op
== O_absent
)
582 as_bad (_("invalid expression"));
585 else if (!intel_state
.has_offset
586 && input_line_pointer
> buf
587 && *(input_line_pointer
- 1) == ']')
589 intel_state
.is_mem
|= 1;
590 intel_state
.is_indirect
= 1;
593 input_line_pointer
= saved_input_line_pointer
;
596 gas_assert (!intel_state
.in_offset
);
597 gas_assert (!intel_state
.in_bracket
);
598 gas_assert (!intel_state
.in_scale
);
603 if (intel_state
.op_modifier
!= O_absent
604 && current_templates
->start
->base_opcode
!= 0x8d /* lea */)
606 i
.types
[this_operand
].bitfield
.unspecified
= 0;
608 switch (intel_state
.op_modifier
)
611 i
.types
[this_operand
].bitfield
.byte
= 1;
612 suffix
= BYTE_MNEM_SUFFIX
;
616 i
.types
[this_operand
].bitfield
.word
= 1;
617 if ((current_templates
->start
->name
[0] == 'l'
618 && current_templates
->start
->name
[2] == 's'
619 && current_templates
->start
->name
[3] == 0)
620 || current_templates
->start
->base_opcode
== 0x62 /* bound */)
621 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
622 else if (got_a_float
== 2) /* "fi..." */
623 suffix
= SHORT_MNEM_SUFFIX
;
625 suffix
= WORD_MNEM_SUFFIX
;
629 i
.types
[this_operand
].bitfield
.dword
= 1;
630 if ((current_templates
->start
->name
[0] == 'l'
631 && current_templates
->start
->name
[2] == 's'
632 && current_templates
->start
->name
[3] == 0)
633 || current_templates
->start
->base_opcode
== 0x62 /* bound */)
634 suffix
= WORD_MNEM_SUFFIX
;
635 else if (flag_code
== CODE_16BIT
636 && (current_templates
->start
->opcode_modifier
.jump
637 || current_templates
->start
->opcode_modifier
.jumpdword
))
638 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
639 else if (got_a_float
== 1) /* "f..." */
640 suffix
= SHORT_MNEM_SUFFIX
;
642 suffix
= LONG_MNEM_SUFFIX
;
646 i
.types
[this_operand
].bitfield
.fword
= 1;
647 if (current_templates
->start
->name
[0] == 'l'
648 && current_templates
->start
->name
[2] == 's'
649 && current_templates
->start
->name
[3] == 0)
650 suffix
= LONG_MNEM_SUFFIX
;
651 else if (!got_a_float
)
653 if (flag_code
== CODE_16BIT
)
654 add_prefix (DATA_PREFIX_OPCODE
);
655 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
658 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
662 i
.types
[this_operand
].bitfield
.qword
= 1;
663 if (current_templates
->start
->base_opcode
== 0x62 /* bound */
664 || got_a_float
== 1) /* "f..." */
665 suffix
= LONG_MNEM_SUFFIX
;
667 suffix
= QWORD_MNEM_SUFFIX
;
671 i
.types
[this_operand
].bitfield
.tbyte
= 1;
672 if (got_a_float
== 1)
673 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
675 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
680 i
.types
[this_operand
].bitfield
.xmmword
= 1;
681 suffix
= XMMWORD_MNEM_SUFFIX
;
685 i
.types
[this_operand
].bitfield
.ymmword
= 1;
686 suffix
= YMMWORD_MNEM_SUFFIX
;
690 i
.types
[this_operand
].bitfield
.zmmword
= 1;
691 suffix
= ZMMWORD_MNEM_SUFFIX
;
695 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
698 if (!current_templates
->start
->opcode_modifier
.jump
699 && !current_templates
->start
->opcode_modifier
.jumpdword
)
700 suffix
= got_a_float
/* so it will cause an error */
702 : LONG_DOUBLE_MNEM_SUFFIX
;
706 BAD_CASE (intel_state
.op_modifier
);
712 else if (i
.suffix
!= suffix
)
714 as_bad (_("conflicting operand size modifiers"));
719 /* Operands for jump/call need special consideration. */
720 if (current_templates
->start
->opcode_modifier
.jump
721 || current_templates
->start
->opcode_modifier
.jumpdword
722 || current_templates
->start
->opcode_modifier
.jumpintersegment
)
724 if (i
.op
[this_operand
].regs
727 || intel_state
.is_mem
> 1)
728 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
730 switch (intel_state
.op_modifier
)
734 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
736 intel_state
.is_mem
= 1;
740 if (!intel_state
.seg
)
742 intel_state
.is_mem
= 1;
743 if (intel_state
.op_modifier
== O_absent
)
745 if (intel_state
.is_indirect
== 1)
746 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
749 as_bad (_("cannot infer the segment part of the operand"));
752 else if (S_GET_SEGMENT (intel_state
.seg
) == reg_section
)
753 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
756 i386_operand_type types
;
758 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
760 as_bad (_("at most %d immediate operands are allowed"),
761 MAX_IMMEDIATE_OPERANDS
);
764 expP
= &im_expressions
[i
.imm_operands
++];
765 memset (expP
, 0, sizeof(*expP
));
766 expP
->X_op
= O_symbol
;
767 expP
->X_add_symbol
= intel_state
.seg
;
768 i
.op
[this_operand
].imms
= expP
;
770 resolve_expression (expP
);
771 operand_type_set (&types
, ~0);
772 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state
.seg
),
773 expP
, types
, operand_string
))
775 if (i
.operands
< MAX_OPERANDS
)
777 this_operand
= i
.operands
++;
778 i
.types
[this_operand
].bitfield
.unspecified
= 1;
780 if (suffix
== LONG_DOUBLE_MNEM_SUFFIX
)
782 intel_state
.seg
= NULL
;
783 intel_state
.is_mem
= 0;
787 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
790 if (i
.types
[this_operand
].bitfield
.jumpabsolute
)
791 intel_state
.is_mem
|= 1;
793 else if (intel_state
.seg
)
794 intel_state
.is_mem
|= 1;
796 if (i
.op
[this_operand
].regs
)
798 i386_operand_type temp
;
800 /* Register operand. */
801 if (intel_state
.base
|| intel_state
.index
|| intel_state
.seg
)
803 as_bad (_("invalid operand"));
807 temp
= i
.op
[this_operand
].regs
->reg_type
;
808 temp
.bitfield
.baseindex
= 0;
809 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
811 i
.types
[this_operand
].bitfield
.unspecified
= 0;
814 else if (intel_state
.base
817 || intel_state
.is_mem
)
819 /* Memory operand. */
820 if ((int) i
.mem_operands
821 >= 2 - !current_templates
->start
->opcode_modifier
.isstring
)
825 call 0x9090,0x90909090
826 lcall 0x9090,0x90909090
827 jmp 0x9090,0x90909090
828 ljmp 0x9090,0x90909090
831 if ((current_templates
->start
->opcode_modifier
.jumpintersegment
832 || current_templates
->start
->opcode_modifier
.jumpdword
833 || current_templates
->start
->opcode_modifier
.jump
)
835 && intel_state
.seg
== NULL
836 && i
.mem_operands
== 1
837 && i
.disp_operands
== 1
838 && intel_state
.op_modifier
== O_absent
)
840 /* Try to process the first operand as immediate, */
842 if (i386_finalize_immediate (exp_seg
, i
.op
[0].imms
,
843 intel_state
.reloc_types
,
847 expP
= &im_expressions
[0];
848 i
.op
[this_operand
].imms
= expP
;
851 /* Try to process the second operand as immediate, */
852 if (i386_finalize_immediate (exp_seg
, expP
,
853 intel_state
.reloc_types
,
859 i
.types
[0].bitfield
.mem
= 0;
860 i
.types
[0].bitfield
.disp16
= 0;
861 i
.types
[0].bitfield
.disp32
= 0;
862 i
.types
[0].bitfield
.disp32s
= 0;
868 as_bad (_("too many memory references for `%s'"),
869 current_templates
->start
->name
);
873 expP
= &disp_expressions
[i
.disp_operands
];
874 memcpy (expP
, &exp
, sizeof(exp
));
875 resolve_expression (expP
);
877 if (expP
->X_op
!= O_constant
878 || expP
->X_add_number
879 || (!intel_state
.base
880 && !intel_state
.index
))
882 i
.op
[this_operand
].disps
= expP
;
885 if (flag_code
== CODE_64BIT
)
887 i
.types
[this_operand
].bitfield
.disp32
= 1;
888 if (!i
.prefix
[ADDR_PREFIX
])
890 i
.types
[this_operand
].bitfield
.disp64
= 1;
891 i
.types
[this_operand
].bitfield
.disp32s
= 1;
894 else if (!i
.prefix
[ADDR_PREFIX
] ^ (flag_code
== CODE_16BIT
))
895 i
.types
[this_operand
].bitfield
.disp32
= 1;
897 i
.types
[this_operand
].bitfield
.disp16
= 1;
899 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
901 * exp_seg is used only for verification in
902 * i386_finalize_displacement, and we can end up seeing reg_section
903 * here - but we know we removed all registers from the expression
904 * (or error-ed on any remaining ones) in i386_intel_simplify. I
905 * consider the check in i386_finalize_displacement bogus anyway, in
906 * particular because it doesn't allow for expr_section, so I'd
907 * rather see that check (and the similar one in
908 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
909 * expert I can't really say whether that would have other bad side
912 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
913 && exp_seg
== reg_section
)
914 exp_seg
= expP
->X_op
!= O_constant
? undefined_section
918 if (!i386_finalize_displacement (exp_seg
, expP
,
919 intel_state
.reloc_types
,
924 if (intel_state
.base
|| intel_state
.index
)
925 i
.types
[this_operand
].bitfield
.baseindex
= 1;
931 expP
= symbol_get_value_expression (intel_state
.seg
);
932 if (expP
->X_op
!= O_full_ptr
)
934 intel_state
.seg
= expP
->X_add_symbol
;
936 if (expP
->X_op
!= O_register
)
938 as_bad (_("segment register name expected"));
941 if (!i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.sreg2
942 && !i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.sreg3
)
944 as_bad (_("invalid use of register"));
947 switch (i386_regtab
[expP
->X_add_number
].reg_num
)
949 case 0: i
.seg
[i
.mem_operands
] = &es
; break;
950 case 1: i
.seg
[i
.mem_operands
] = &cs
; break;
951 case 2: i
.seg
[i
.mem_operands
] = &ss
; break;
952 case 3: i
.seg
[i
.mem_operands
] = &ds
; break;
953 case 4: i
.seg
[i
.mem_operands
] = &fs
; break;
954 case 5: i
.seg
[i
.mem_operands
] = &gs
; break;
955 case RegFlat
: i
.seg
[i
.mem_operands
] = NULL
; break;
959 /* Swap base and index in 16-bit memory operands like
960 [si+bx]. Since i386_index_check is also used in AT&T
961 mode we have to do that here. */
964 && intel_state
.base
->reg_type
.bitfield
.reg16
965 && intel_state
.index
->reg_type
.bitfield
.reg16
966 && intel_state
.base
->reg_num
>= 6
967 && intel_state
.index
->reg_num
< 6)
969 i
.base_reg
= intel_state
.index
;
970 i
.index_reg
= intel_state
.base
;
974 i
.base_reg
= intel_state
.base
;
975 i
.index_reg
= intel_state
.index
;
978 if (!i386_index_check (operand_string
))
981 i
.types
[this_operand
].bitfield
.mem
= 1;
987 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
989 as_bad (_("at most %d immediate operands are allowed"),
990 MAX_IMMEDIATE_OPERANDS
);
994 expP
= &im_expressions
[i
.imm_operands
++];
995 i
.op
[this_operand
].imms
= expP
;
998 return i386_finalize_immediate (exp_seg
, expP
, intel_state
.reloc_types
,