1 /* tc-i386.c -- Assemble Intel syntax code for ix86/x86-64
2 Copyright (C) 2009-2017 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 (!intel_state
.in_bracket
)
275 if (i
.op
[this_operand
].regs
)
277 as_bad (_("invalid use of register"));
280 if (i386_regtab
[reg_num
].reg_type
.bitfield
.sreg3
281 && i386_regtab
[reg_num
].reg_num
== RegFlat
)
283 as_bad (_("invalid use of pseudo-register"));
286 i
.op
[this_operand
].regs
= i386_regtab
+ reg_num
;
288 else if (!intel_state
.index
289 && (i386_regtab
[reg_num
].reg_type
.bitfield
.regxmm
290 || i386_regtab
[reg_num
].reg_type
.bitfield
.regymm
291 || i386_regtab
[reg_num
].reg_type
.bitfield
.regzmm
292 || i386_regtab
[reg_num
].reg_num
== RegRiz
293 || i386_regtab
[reg_num
].reg_num
== RegEiz
))
294 intel_state
.index
= i386_regtab
+ reg_num
;
295 else if (!intel_state
.base
&& !intel_state
.in_scale
)
296 intel_state
.base
= i386_regtab
+ reg_num
;
297 else if (!intel_state
.index
)
299 if (intel_state
.in_scale
300 || current_templates
->start
->base_opcode
== 0xf30f1b /* bndmk */
301 || (current_templates
->start
->base_opcode
& ~1) == 0x0f1a /* bnd{ld,st}x */
302 || i386_regtab
[reg_num
].reg_type
.bitfield
.baseindex
)
303 intel_state
.index
= i386_regtab
+ reg_num
;
306 /* Convert base to index and make ESP/RSP the base. */
307 intel_state
.index
= intel_state
.base
;
308 intel_state
.base
= i386_regtab
+ reg_num
;
313 /* esp is invalid as index */
314 intel_state
.index
= i386_regtab
+ REGNAM_EAX
+ ESP_REG_NUM
;
319 static int i386_intel_simplify (expressionS
*);
321 static INLINE
int i386_intel_simplify_symbol(symbolS
*sym
)
323 int ret
= i386_intel_simplify (symbol_get_value_expression (sym
));
327 S_SET_SEGMENT(sym
, absolute_section
);
333 static int i386_intel_simplify (expressionS
*e
)
335 const reg_entry
*the_reg
= (this_operand
>= 0
336 ? i
.op
[this_operand
].regs
: NULL
);
337 const reg_entry
*base
= intel_state
.base
;
338 const reg_entry
*state_index
= intel_state
.index
;
349 if (!i386_intel_simplify_symbol (e
->X_add_symbol
)
350 || !i386_intel_check(the_reg
, intel_state
.base
,
354 if (!intel_state
.in_offset
)
355 ++intel_state
.in_bracket
;
356 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
357 if (!intel_state
.in_offset
)
358 --intel_state
.in_bracket
;
364 i386_intel_fold (e
, e
->X_op_symbol
);
368 intel_state
.has_offset
= 1;
369 ++intel_state
.in_offset
;
370 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
371 --intel_state
.in_offset
;
372 if (!ret
|| !i386_intel_check(the_reg
, base
, state_index
))
374 i386_intel_fold (e
, e
->X_add_symbol
);
389 if (intel_state
.op_modifier
== O_absent
)
390 intel_state
.op_modifier
= e
->X_op
;
393 if (symbol_get_value_expression (e
->X_add_symbol
)->X_op
396 as_bad (_("invalid use of register"));
399 if (!i386_intel_simplify_symbol (e
->X_add_symbol
))
401 i386_intel_fold (e
, e
->X_add_symbol
);
405 if (symbol_get_value_expression (e
->X_op_symbol
)->X_op
408 as_bad (_("invalid use of register"));
411 if (!i386_intel_simplify_symbol (e
->X_op_symbol
)
412 || !i386_intel_check(the_reg
, intel_state
.base
,
415 if (!intel_state
.in_offset
)
416 intel_state
.seg
= e
->X_add_symbol
;
417 i386_intel_fold (e
, e
->X_op_symbol
);
421 if (this_operand
>= 0 && intel_state
.in_bracket
)
423 expressionS
*scale
= NULL
;
424 int has_index
= (intel_state
.index
!= NULL
);
426 if (!intel_state
.in_scale
++)
427 intel_state
.scale_factor
= 1;
429 ret
= i386_intel_simplify_symbol (e
->X_add_symbol
);
430 if (ret
&& !has_index
&& intel_state
.index
)
431 scale
= symbol_get_value_expression (e
->X_op_symbol
);
434 ret
= i386_intel_simplify_symbol (e
->X_op_symbol
);
435 if (ret
&& !scale
&& !has_index
&& intel_state
.index
)
436 scale
= symbol_get_value_expression (e
->X_add_symbol
);
440 resolve_expression (scale
);
441 if (scale
->X_op
!= O_constant
442 || intel_state
.index
->reg_type
.bitfield
.reg16
)
443 scale
->X_add_number
= 0;
444 intel_state
.scale_factor
*= scale
->X_add_number
;
447 --intel_state
.in_scale
;
451 if (!intel_state
.in_scale
)
452 switch (intel_state
.scale_factor
)
455 i
.log2_scale_factor
= 0;
458 i
.log2_scale_factor
= 1;
461 i
.log2_scale_factor
= 2;
464 i
.log2_scale_factor
= 3;
467 /* esp is invalid as index */
468 intel_state
.index
= i386_regtab
+ REGNAM_EAX
+ ESP_REG_NUM
;
477 ret
= i386_intel_simplify_register (e
);
480 gas_assert (e
->X_add_number
< (unsigned short) -1);
481 e
->X_md
= (unsigned short) e
->X_add_number
+ 1;
482 e
->X_op
= O_constant
;
489 return i386_intel_simplify_register (e
);
495 && !i386_intel_simplify_symbol (e
->X_add_symbol
))
497 if (e
->X_op
== O_add
|| e
->X_op
== O_subtract
)
499 base
= intel_state
.base
;
500 state_index
= intel_state
.index
;
502 if (!i386_intel_check (the_reg
, base
, state_index
)
504 && !i386_intel_simplify_symbol (e
->X_op_symbol
))
505 || !i386_intel_check (the_reg
,
507 ? base
: intel_state
.base
),
509 ? state_index
: intel_state
.index
)))
514 if (this_operand
>= 0
515 && e
->X_op
== O_symbol
516 && !intel_state
.in_offset
)
518 segT seg
= S_GET_SEGMENT (e
->X_add_symbol
);
520 if (seg
!= absolute_section
521 && seg
!= reg_section
522 && seg
!= expr_section
)
523 intel_state
.is_mem
|= 2 - !intel_state
.in_bracket
;
529 int i386_need_index_operator (void)
531 return intel_syntax
< 0;
535 i386_intel_operand (char *operand_string
, int got_a_float
)
537 char *saved_input_line_pointer
, *buf
;
539 expressionS exp
, *expP
;
543 /* Handle vector immediates. */
544 if (RC_SAE_immediate (operand_string
))
547 /* Initialize state structure. */
548 intel_state
.op_modifier
= O_absent
;
549 intel_state
.is_mem
= 0;
550 intel_state
.is_indirect
= 0;
551 intel_state
.has_offset
= 0;
552 intel_state
.base
= NULL
;
553 intel_state
.index
= NULL
;
554 intel_state
.seg
= NULL
;
555 operand_type_set (&intel_state
.reloc_types
, ~0);
556 gas_assert (!intel_state
.in_offset
);
557 gas_assert (!intel_state
.in_bracket
);
558 gas_assert (!intel_state
.in_scale
);
560 saved_input_line_pointer
= input_line_pointer
;
561 input_line_pointer
= buf
= xstrdup (operand_string
);
564 memset (&exp
, 0, sizeof(exp
));
565 exp_seg
= expression (&exp
);
566 ret
= i386_intel_simplify (&exp
);
571 /* Handle vector operations. */
572 if (*input_line_pointer
== '{')
574 char *end
= check_VecOperations (input_line_pointer
, NULL
);
576 input_line_pointer
= end
;
581 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
583 as_bad (_("junk `%s' after expression"), input_line_pointer
);
586 else if (exp
.X_op
== O_illegal
|| exp
.X_op
== O_absent
)
588 as_bad (_("invalid expression"));
591 else if (!intel_state
.has_offset
592 && input_line_pointer
> buf
593 && *(input_line_pointer
- 1) == ']')
595 intel_state
.is_mem
|= 1;
596 intel_state
.is_indirect
= 1;
599 input_line_pointer
= saved_input_line_pointer
;
602 gas_assert (!intel_state
.in_offset
);
603 gas_assert (!intel_state
.in_bracket
);
604 gas_assert (!intel_state
.in_scale
);
609 if (intel_state
.op_modifier
!= O_absent
610 && current_templates
->start
->base_opcode
!= 0x8d /* lea */)
612 i
.types
[this_operand
].bitfield
.unspecified
= 0;
614 switch (intel_state
.op_modifier
)
617 i
.types
[this_operand
].bitfield
.byte
= 1;
618 suffix
= BYTE_MNEM_SUFFIX
;
622 i
.types
[this_operand
].bitfield
.word
= 1;
623 if ((current_templates
->start
->name
[0] == 'l'
624 && current_templates
->start
->name
[2] == 's'
625 && current_templates
->start
->name
[3] == 0)
626 || current_templates
->start
->base_opcode
== 0x62 /* bound */)
627 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
628 else if (got_a_float
== 2) /* "fi..." */
629 suffix
= SHORT_MNEM_SUFFIX
;
631 suffix
= WORD_MNEM_SUFFIX
;
635 i
.types
[this_operand
].bitfield
.dword
= 1;
636 if ((current_templates
->start
->name
[0] == 'l'
637 && current_templates
->start
->name
[2] == 's'
638 && current_templates
->start
->name
[3] == 0)
639 || current_templates
->start
->base_opcode
== 0x62 /* bound */)
640 suffix
= WORD_MNEM_SUFFIX
;
641 else if (flag_code
== CODE_16BIT
642 && (current_templates
->start
->opcode_modifier
.jump
643 || current_templates
->start
->opcode_modifier
.jumpdword
))
644 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
645 else if (got_a_float
== 1) /* "f..." */
646 suffix
= SHORT_MNEM_SUFFIX
;
648 suffix
= LONG_MNEM_SUFFIX
;
652 i
.types
[this_operand
].bitfield
.fword
= 1;
653 if (current_templates
->start
->name
[0] == 'l'
654 && current_templates
->start
->name
[2] == 's'
655 && current_templates
->start
->name
[3] == 0)
656 suffix
= LONG_MNEM_SUFFIX
;
657 else if (!got_a_float
)
659 if (flag_code
== CODE_16BIT
)
660 add_prefix (DATA_PREFIX_OPCODE
);
661 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
664 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
668 i
.types
[this_operand
].bitfield
.qword
= 1;
669 if (current_templates
->start
->base_opcode
== 0x62 /* bound */
670 || got_a_float
== 1) /* "f..." */
671 suffix
= LONG_MNEM_SUFFIX
;
673 suffix
= QWORD_MNEM_SUFFIX
;
677 i
.types
[this_operand
].bitfield
.tbyte
= 1;
678 if (got_a_float
== 1)
679 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
681 suffix
= BYTE_MNEM_SUFFIX
; /* so it will cause an error */
686 i
.types
[this_operand
].bitfield
.xmmword
= 1;
687 suffix
= XMMWORD_MNEM_SUFFIX
;
691 i
.types
[this_operand
].bitfield
.ymmword
= 1;
692 suffix
= YMMWORD_MNEM_SUFFIX
;
696 i
.types
[this_operand
].bitfield
.zmmword
= 1;
697 suffix
= ZMMWORD_MNEM_SUFFIX
;
701 suffix
= LONG_DOUBLE_MNEM_SUFFIX
;
704 if (!current_templates
->start
->opcode_modifier
.jump
705 && !current_templates
->start
->opcode_modifier
.jumpdword
)
706 suffix
= got_a_float
/* so it will cause an error */
708 : LONG_DOUBLE_MNEM_SUFFIX
;
712 BAD_CASE (intel_state
.op_modifier
);
718 else if (i
.suffix
!= suffix
)
720 as_bad (_("conflicting operand size modifiers"));
725 /* Operands for jump/call need special consideration. */
726 if (current_templates
->start
->opcode_modifier
.jump
727 || current_templates
->start
->opcode_modifier
.jumpdword
728 || current_templates
->start
->opcode_modifier
.jumpintersegment
)
730 if (i
.op
[this_operand
].regs
733 || intel_state
.is_mem
> 1)
734 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
736 switch (intel_state
.op_modifier
)
740 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
742 intel_state
.is_mem
= 1;
746 if (!intel_state
.seg
)
748 intel_state
.is_mem
= 1;
749 if (intel_state
.op_modifier
== O_absent
)
751 if (intel_state
.is_indirect
== 1)
752 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
755 as_bad (_("cannot infer the segment part of the operand"));
758 else if (S_GET_SEGMENT (intel_state
.seg
) == reg_section
)
759 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
762 i386_operand_type types
;
764 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
766 as_bad (_("at most %d immediate operands are allowed"),
767 MAX_IMMEDIATE_OPERANDS
);
770 expP
= &im_expressions
[i
.imm_operands
++];
771 memset (expP
, 0, sizeof(*expP
));
772 expP
->X_op
= O_symbol
;
773 expP
->X_add_symbol
= intel_state
.seg
;
774 i
.op
[this_operand
].imms
= expP
;
776 resolve_expression (expP
);
777 operand_type_set (&types
, ~0);
778 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state
.seg
),
779 expP
, types
, operand_string
))
781 if (i
.operands
< MAX_OPERANDS
)
783 this_operand
= i
.operands
++;
784 i
.types
[this_operand
].bitfield
.unspecified
= 1;
786 if (suffix
== LONG_DOUBLE_MNEM_SUFFIX
)
788 intel_state
.seg
= NULL
;
789 intel_state
.is_mem
= 0;
793 i
.types
[this_operand
].bitfield
.jumpabsolute
= 1;
796 if (i
.types
[this_operand
].bitfield
.jumpabsolute
)
797 intel_state
.is_mem
|= 1;
799 else if (intel_state
.seg
)
800 intel_state
.is_mem
|= 1;
802 if (i
.op
[this_operand
].regs
)
804 i386_operand_type temp
;
806 /* Register operand. */
807 if (intel_state
.base
|| intel_state
.index
|| intel_state
.seg
)
809 as_bad (_("invalid operand"));
813 temp
= i
.op
[this_operand
].regs
->reg_type
;
814 temp
.bitfield
.baseindex
= 0;
815 i
.types
[this_operand
] = operand_type_or (i
.types
[this_operand
],
817 i
.types
[this_operand
].bitfield
.unspecified
= 0;
820 else if (intel_state
.base
823 || intel_state
.is_mem
)
825 /* Memory operand. */
826 if (i
.mem_operands
== 1 && !maybe_adjust_templates ())
828 if ((int) i
.mem_operands
829 >= 2 - !current_templates
->start
->opcode_modifier
.isstring
)
833 call 0x9090,0x90909090
834 lcall 0x9090,0x90909090
835 jmp 0x9090,0x90909090
836 ljmp 0x9090,0x90909090
839 if ((current_templates
->start
->opcode_modifier
.jumpintersegment
840 || current_templates
->start
->opcode_modifier
.jumpdword
841 || current_templates
->start
->opcode_modifier
.jump
)
843 && intel_state
.seg
== NULL
844 && i
.mem_operands
== 1
845 && i
.disp_operands
== 1
846 && intel_state
.op_modifier
== O_absent
)
848 /* Try to process the first operand as immediate, */
850 if (i386_finalize_immediate (exp_seg
, i
.op
[0].imms
,
851 intel_state
.reloc_types
,
855 expP
= &im_expressions
[0];
856 i
.op
[this_operand
].imms
= expP
;
859 /* Try to process the second operand as immediate, */
860 if (i386_finalize_immediate (exp_seg
, expP
,
861 intel_state
.reloc_types
,
867 i
.types
[0].bitfield
.mem
= 0;
868 i
.types
[0].bitfield
.disp16
= 0;
869 i
.types
[0].bitfield
.disp32
= 0;
870 i
.types
[0].bitfield
.disp32s
= 0;
876 as_bad (_("too many memory references for `%s'"),
877 current_templates
->start
->name
);
881 /* Swap base and index in 16-bit memory operands like
882 [si+bx]. Since i386_index_check is also used in AT&T
883 mode we have to do this here. */
886 && intel_state
.base
->reg_type
.bitfield
.reg16
887 && intel_state
.index
->reg_type
.bitfield
.reg16
888 && intel_state
.base
->reg_num
>= 6
889 && intel_state
.index
->reg_num
< 6)
891 i
.base_reg
= intel_state
.index
;
892 i
.index_reg
= intel_state
.base
;
896 i
.base_reg
= intel_state
.base
;
897 i
.index_reg
= intel_state
.index
;
900 if (i
.base_reg
|| i
.index_reg
)
901 i
.types
[this_operand
].bitfield
.baseindex
= 1;
903 expP
= &disp_expressions
[i
.disp_operands
];
904 memcpy (expP
, &exp
, sizeof(exp
));
905 resolve_expression (expP
);
907 if (expP
->X_op
!= O_constant
908 || expP
->X_add_number
909 || !i
.types
[this_operand
].bitfield
.baseindex
)
911 i
.op
[this_operand
].disps
= expP
;
914 i386_addressing_mode ();
916 if (flag_code
== CODE_64BIT
)
918 i
.types
[this_operand
].bitfield
.disp32
= 1;
919 if (!i
.prefix
[ADDR_PREFIX
])
921 i
.types
[this_operand
].bitfield
.disp64
= 1;
922 i
.types
[this_operand
].bitfield
.disp32s
= 1;
925 else if (!i
.prefix
[ADDR_PREFIX
] ^ (flag_code
== CODE_16BIT
))
926 i
.types
[this_operand
].bitfield
.disp32
= 1;
928 i
.types
[this_operand
].bitfield
.disp16
= 1;
930 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
932 * exp_seg is used only for verification in
933 * i386_finalize_displacement, and we can end up seeing reg_section
934 * here - but we know we removed all registers from the expression
935 * (or error-ed on any remaining ones) in i386_intel_simplify. I
936 * consider the check in i386_finalize_displacement bogus anyway, in
937 * particular because it doesn't allow for expr_section, so I'd
938 * rather see that check (and the similar one in
939 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
940 * expert I can't really say whether that would have other bad side
943 if (OUTPUT_FLAVOR
== bfd_target_aout_flavour
944 && exp_seg
== reg_section
)
945 exp_seg
= expP
->X_op
!= O_constant
? undefined_section
949 if (!i386_finalize_displacement (exp_seg
, expP
,
950 intel_state
.reloc_types
,
957 expP
= symbol_get_value_expression (intel_state
.seg
);
958 if (expP
->X_op
!= O_register
)
960 as_bad (_("segment register name expected"));
963 if (!i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.sreg2
964 && !i386_regtab
[expP
->X_add_number
].reg_type
.bitfield
.sreg3
)
966 as_bad (_("invalid use of register"));
969 switch (i386_regtab
[expP
->X_add_number
].reg_num
)
971 case 0: i
.seg
[i
.mem_operands
] = &es
; break;
972 case 1: i
.seg
[i
.mem_operands
] = &cs
; break;
973 case 2: i
.seg
[i
.mem_operands
] = &ss
; break;
974 case 3: i
.seg
[i
.mem_operands
] = &ds
; break;
975 case 4: i
.seg
[i
.mem_operands
] = &fs
; break;
976 case 5: i
.seg
[i
.mem_operands
] = &gs
; break;
977 case RegFlat
: i
.seg
[i
.mem_operands
] = NULL
; break;
981 if (!i386_index_check (operand_string
))
984 i
.types
[this_operand
].bitfield
.mem
= 1;
985 if (i
.mem_operands
== 0)
986 i
.memop1_string
= xstrdup (operand_string
);
992 if (i
.imm_operands
>= MAX_IMMEDIATE_OPERANDS
)
994 as_bad (_("at most %d immediate operands are allowed"),
995 MAX_IMMEDIATE_OPERANDS
);
999 expP
= &im_expressions
[i
.imm_operands
++];
1000 i
.op
[this_operand
].imms
= expP
;
1003 return i386_finalize_immediate (exp_seg
, expP
, intel_state
.reloc_types
,