gdb/testsuite: fix gdb.trace/signal.exp on x86
[binutils-gdb/blckswan.git] / gas / config / tc-i386-intel.c
blob0991f4f687c2c5e95944b2667e8a4dc0d8dc19e4
1 /* tc-i386.c -- Assemble Intel syntax code for ix86/x86-64
2 Copyright (C) 2009-2022 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)
9 any later version.
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
19 02110-1301, USA. */
21 static struct
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
30 * in brackets. */
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. */
35 symbolS *seg;
37 intel_state;
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 /* mmword ptr X_add_symbol */
56 #define O_mmword_ptr O_qword_ptr
57 /* fword ptr X_add_symbol */
58 #define O_fword_ptr O_md24
59 /* tbyte ptr X_add_symbol */
60 #define O_tbyte_ptr O_md23
61 /* oword ptr X_add_symbol */
62 #define O_oword_ptr O_md22
63 /* xmmword ptr X_add_symbol */
64 #define O_xmmword_ptr O_oword_ptr
65 /* ymmword ptr X_add_symbol */
66 #define O_ymmword_ptr O_md21
67 /* zmmword ptr X_add_symbol */
68 #define O_zmmword_ptr O_md20
70 static struct
72 const char *name;
73 operatorT op;
74 unsigned int operands;
76 const i386_operators[] =
78 { "and", O_bit_and, 2 },
79 { "eq", O_eq, 2 },
80 { "ge", O_ge, 2 },
81 { "gt", O_gt, 2 },
82 { "le", O_le, 2 },
83 { "lt", O_lt, 2 },
84 { "mod", O_modulus, 2 },
85 { "ne", O_ne, 2 },
86 { "not", O_bit_not, 1 },
87 { "offset", O_offset, 1 },
88 { "or", O_bit_inclusive_or, 2 },
89 { "shl", O_left_shift, 2 },
90 { "short", O_short, 1 },
91 { "shr", O_right_shift, 2 },
92 { "xor", O_bit_exclusive_or, 2 },
93 { NULL, O_illegal, 0 }
96 static struct
98 const char *name;
99 operatorT op;
100 unsigned short sz[3];
102 const i386_types[] =
104 #define I386_TYPE(t, n) { #t, O_##t##_ptr, { n, n, n } }
105 I386_TYPE(byte, 1),
106 I386_TYPE(word, 2),
107 I386_TYPE(dword, 4),
108 I386_TYPE(fword, 6),
109 I386_TYPE(qword, 8),
110 I386_TYPE(mmword, 8),
111 I386_TYPE(tbyte, 10),
112 I386_TYPE(oword, 16),
113 I386_TYPE(xmmword, 16),
114 I386_TYPE(ymmword, 32),
115 I386_TYPE(zmmword, 64),
116 #undef I386_TYPE
117 { "near", O_near_ptr, { 0xff04, 0xff02, 0xff08 } },
118 { "far", O_far_ptr, { 0xff06, 0xff05, 0xff06 } },
119 { NULL, O_illegal, { 0, 0, 0 } }
122 operatorT i386_operator (const char *name, unsigned int operands, char *pc)
124 unsigned int j;
126 #ifdef SVR4_COMMENT_CHARS
127 if (!name && operands == 2 && *input_line_pointer == '\\')
128 switch (input_line_pointer[1])
130 case '/': input_line_pointer += 2; return O_divide;
131 case '%': input_line_pointer += 2; return O_modulus;
132 case '*': input_line_pointer += 2; return O_multiply;
134 #endif
136 if (!intel_syntax)
137 return O_absent;
139 if (!name)
141 if (operands != 2)
142 return O_illegal;
143 switch (*input_line_pointer)
145 case ':':
146 ++input_line_pointer;
147 return O_full_ptr;
148 case '[':
149 ++input_line_pointer;
150 return O_index;
151 case '@':
152 if (this_operand >= 0 && i.reloc[this_operand] == NO_RELOC)
154 int adjust = 0;
155 char *gotfree_input_line = lex_got (&i.reloc[this_operand],
156 &adjust,
157 &intel_state.reloc_types);
159 if (!gotfree_input_line)
160 break;
161 free (gotfree_input_line);
162 *input_line_pointer++ = '+';
163 memset (input_line_pointer, '0', adjust - 1);
164 input_line_pointer[adjust - 1] = ' ';
165 return O_add;
167 break;
169 return O_illegal;
172 for (j = 0; i386_operators[j].name; ++j)
173 if (strcasecmp (i386_operators[j].name, name) == 0)
175 if (i386_operators[j].operands
176 && i386_operators[j].operands != operands)
177 return O_illegal;
178 return i386_operators[j].op;
181 for (j = 0; i386_types[j].name; ++j)
182 if (strcasecmp (i386_types[j].name, name) == 0)
183 break;
185 if (i386_types[j].name && *pc == ' ')
187 char *pname;
188 char c;
190 ++input_line_pointer;
191 c = get_symbol_name (&pname);
193 if (strcasecmp (pname, "ptr") == 0)
195 /* FIXME: What if c == '"' ? */
196 pname[-1] = *pc;
197 *pc = c;
198 if (intel_syntax > 0 || operands != 1)
199 return O_illegal;
200 return i386_types[j].op;
203 if (strcasecmp (pname, "bcst") == 0)
205 /* FIXME: Again, what if c == '"' ? */
206 pname[-1] = *pc;
207 *pc = c;
208 if (intel_syntax > 0 || operands != 1
209 || i386_types[j].sz[0] > 8
210 || (i386_types[j].sz[0] & (i386_types[j].sz[0] - 1)))
211 return O_illegal;
212 if (!i.broadcast.bytes && !i.broadcast.type)
214 i.broadcast.bytes = i386_types[j].sz[0];
215 i.broadcast.operand = this_operand;
217 return i386_types[j].op;
220 (void) restore_line_pointer (c);
221 input_line_pointer = pname - 1;
224 return O_absent;
227 static int i386_intel_parse_name (const char *name, expressionS *e)
229 unsigned int j;
231 if (! strcmp (name, "$"))
233 current_location (e);
234 return 1;
237 for (j = 0; i386_types[j].name; ++j)
238 if (strcasecmp(i386_types[j].name, name) == 0)
240 e->X_op = O_constant;
241 e->X_add_number = i386_types[j].sz[flag_code];
242 e->X_add_symbol = NULL;
243 e->X_op_symbol = NULL;
244 return 1;
247 return 0;
250 static INLINE int i386_intel_check (const reg_entry *rreg,
251 const reg_entry *base,
252 const reg_entry *iindex)
254 if ((this_operand >= 0
255 && rreg != i.op[this_operand].regs)
256 || base != intel_state.base
257 || iindex != intel_state.index)
259 as_bad (_("invalid use of register"));
260 return 0;
262 return 1;
265 static INLINE void i386_intel_fold (expressionS *e, symbolS *sym)
267 expressionS *exp = symbol_get_value_expression (sym);
268 if (S_GET_SEGMENT (sym) == absolute_section)
270 offsetT val = e->X_add_number;
272 *e = *exp;
273 e->X_add_number += val;
275 else
277 if (exp->X_op == O_symbol
278 && strcmp (S_GET_NAME (exp->X_add_symbol),
279 GLOBAL_OFFSET_TABLE_NAME) == 0)
280 sym = exp->X_add_symbol;
281 e->X_add_symbol = sym;
282 e->X_op_symbol = NULL;
283 e->X_op = O_symbol;
287 static int
288 i386_intel_simplify_register (expressionS *e)
290 int reg_num;
292 if (this_operand < 0 || intel_state.in_offset)
294 as_bad (_("invalid use of register"));
295 return 0;
298 if (e->X_op == O_register)
299 reg_num = e->X_add_number;
300 else
301 reg_num = e->X_md - 1;
303 if (reg_num < 0 || reg_num >= (int) i386_regtab_size)
305 as_bad (_("invalid register number"));
306 return 0;
309 if (!check_register (&i386_regtab[reg_num]))
311 as_bad (_("register '%s%s' cannot be used here"),
312 register_prefix, i386_regtab[reg_num].reg_name);
313 return 0;
316 if (!intel_state.in_bracket)
318 if (i.op[this_operand].regs)
320 as_bad (_("invalid use of register"));
321 return 0;
323 if (i386_regtab[reg_num].reg_type.bitfield.class == SReg
324 && i386_regtab[reg_num].reg_num == RegFlat)
326 as_bad (_("invalid use of pseudo-register"));
327 return 0;
329 i.op[this_operand].regs = i386_regtab + reg_num;
331 else if (!intel_state.index
332 && (i386_regtab[reg_num].reg_type.bitfield.xmmword
333 || i386_regtab[reg_num].reg_type.bitfield.ymmword
334 || i386_regtab[reg_num].reg_type.bitfield.zmmword
335 || i386_regtab[reg_num].reg_num == RegIZ))
336 intel_state.index = i386_regtab + reg_num;
337 else if (!intel_state.base && !intel_state.in_scale)
338 intel_state.base = i386_regtab + reg_num;
339 else if (!intel_state.index)
341 const insn_template *t = current_templates->start;
343 if (intel_state.in_scale
344 || (t->opcode_modifier.opcodeprefix == PREFIX_0XF3
345 && t->opcode_modifier.opcodespace == SPACE_0F
346 && t->base_opcode == 0x1b /* bndmk */)
347 || (t->opcode_modifier.opcodeprefix == PREFIX_NONE
348 && t->opcode_modifier.opcodespace == SPACE_0F
349 && (t->base_opcode & ~1) == 0x1a /* bnd{ld,st}x */)
350 || i386_regtab[reg_num].reg_type.bitfield.baseindex)
351 intel_state.index = i386_regtab + reg_num;
352 else
354 /* Convert base to index and make ESP/RSP the base. */
355 intel_state.index = intel_state.base;
356 intel_state.base = i386_regtab + reg_num;
359 else
361 /* esp is invalid as index */
362 intel_state.index = reg_eax + ESP_REG_NUM;
364 return 2;
367 static int i386_intel_simplify (expressionS *);
369 static INLINE int i386_intel_simplify_symbol(symbolS *sym)
371 int ret = i386_intel_simplify (symbol_get_value_expression (sym));
373 if (ret == 2)
375 S_SET_SEGMENT(sym, absolute_section);
376 ret = 1;
378 return ret;
381 static int i386_intel_simplify (expressionS *e)
383 const reg_entry *the_reg = (this_operand >= 0
384 ? i.op[this_operand].regs : NULL);
385 const reg_entry *base = intel_state.base;
386 const reg_entry *state_index = intel_state.index;
387 int ret;
389 if (!intel_syntax)
390 return 1;
392 switch (e->X_op)
394 case O_index:
395 if (e->X_add_symbol)
397 if (!i386_intel_simplify_symbol (e->X_add_symbol)
398 || !i386_intel_check(the_reg, intel_state.base,
399 intel_state.index))
400 return 0;
402 if (!intel_state.in_offset)
403 ++intel_state.in_bracket;
404 ret = i386_intel_simplify_symbol (e->X_op_symbol);
405 if (!intel_state.in_offset)
406 --intel_state.in_bracket;
407 if (!ret)
408 return 0;
409 if (e->X_add_symbol)
410 e->X_op = O_add;
411 else
412 i386_intel_fold (e, e->X_op_symbol);
413 break;
415 case O_offset:
416 intel_state.has_offset = 1;
417 ++intel_state.in_offset;
418 ret = i386_intel_simplify_symbol (e->X_add_symbol);
419 --intel_state.in_offset;
420 if (!ret || !i386_intel_check(the_reg, base, state_index))
421 return 0;
422 i386_intel_fold (e, e->X_add_symbol);
423 return ret;
425 case O_byte_ptr:
426 case O_word_ptr:
427 case O_dword_ptr:
428 case O_fword_ptr:
429 case O_qword_ptr: /* O_mmword_ptr */
430 case O_tbyte_ptr:
431 case O_oword_ptr: /* O_xmmword_ptr */
432 case O_ymmword_ptr:
433 case O_zmmword_ptr:
434 case O_near_ptr:
435 case O_far_ptr:
436 if (intel_state.op_modifier == O_absent)
437 intel_state.op_modifier = e->X_op;
438 /* FALLTHROUGH */
439 case O_short:
440 if (symbol_get_value_expression (e->X_add_symbol)->X_op
441 == O_register)
443 as_bad (_("invalid use of register"));
444 return 0;
446 if (!i386_intel_simplify_symbol (e->X_add_symbol))
447 return 0;
448 i386_intel_fold (e, e->X_add_symbol);
449 break;
451 case O_full_ptr:
452 if (symbol_get_value_expression (e->X_op_symbol)->X_op
453 == O_register)
455 as_bad (_("invalid use of register"));
456 return 0;
458 if (!i386_intel_simplify_symbol (e->X_op_symbol)
459 || !i386_intel_check(the_reg, intel_state.base,
460 intel_state.index))
461 return 0;
462 if (!intel_state.in_offset)
464 if (!intel_state.seg)
465 intel_state.seg = e->X_add_symbol;
466 else
468 expressionS exp;
470 exp.X_op = O_full_ptr;
471 exp.X_add_symbol = e->X_add_symbol;
472 exp.X_op_symbol = intel_state.seg;
473 intel_state.seg = make_expr_symbol (&exp);
476 i386_intel_fold (e, e->X_op_symbol);
477 break;
479 case O_multiply:
480 if (this_operand >= 0 && intel_state.in_bracket)
482 expressionS *scale = NULL;
483 int has_index = (intel_state.index != NULL);
485 if (!intel_state.in_scale++)
486 intel_state.scale_factor = 1;
488 ret = i386_intel_simplify_symbol (e->X_add_symbol);
489 if (ret && !has_index && intel_state.index)
490 scale = symbol_get_value_expression (e->X_op_symbol);
492 if (ret)
493 ret = i386_intel_simplify_symbol (e->X_op_symbol);
494 if (ret && !scale && !has_index && intel_state.index)
495 scale = symbol_get_value_expression (e->X_add_symbol);
497 if (ret && scale)
499 resolve_expression (scale);
500 if (scale->X_op != O_constant
501 || intel_state.index->reg_type.bitfield.word)
502 scale->X_add_number = 0;
503 intel_state.scale_factor *= scale->X_add_number;
506 --intel_state.in_scale;
507 if (!ret)
508 return 0;
510 if (!intel_state.in_scale)
511 switch (intel_state.scale_factor)
513 case 1:
514 i.log2_scale_factor = 0;
515 break;
516 case 2:
517 i.log2_scale_factor = 1;
518 break;
519 case 4:
520 i.log2_scale_factor = 2;
521 break;
522 case 8:
523 i.log2_scale_factor = 3;
524 break;
525 default:
526 /* esp is invalid as index */
527 intel_state.index = reg_eax + ESP_REG_NUM;
528 break;
531 break;
533 goto fallthrough;
535 case O_register:
536 ret = i386_intel_simplify_register (e);
537 if (ret == 2)
539 gas_assert (e->X_add_number < (unsigned short) -1);
540 e->X_md = (unsigned short) e->X_add_number + 1;
541 e->X_op = O_constant;
542 e->X_add_number = 0;
544 return ret;
546 case O_constant:
547 if (e->X_md)
548 return i386_intel_simplify_register (e);
550 /* FALLTHROUGH */
551 default:
552 fallthrough:
553 if (e->X_add_symbol
554 && !i386_intel_simplify_symbol (e->X_add_symbol))
555 return 0;
556 if (!the_reg && this_operand >= 0
557 && e->X_op == O_symbol && !e->X_add_number)
558 the_reg = i.op[this_operand].regs;
559 if (e->X_op == O_add || e->X_op == O_subtract)
561 base = intel_state.base;
562 state_index = intel_state.index;
564 if (!i386_intel_check (the_reg, base, state_index)
565 || (e->X_op_symbol
566 && !i386_intel_simplify_symbol (e->X_op_symbol))
567 || !i386_intel_check (the_reg,
568 (e->X_op != O_add
569 ? base : intel_state.base),
570 (e->X_op != O_add
571 ? state_index : intel_state.index)))
572 return 0;
573 break;
576 if (this_operand >= 0
577 && e->X_op == O_symbol
578 && !intel_state.in_offset)
580 segT seg = S_GET_SEGMENT (e->X_add_symbol);
582 if (seg != absolute_section
583 && seg != reg_section
584 && seg != expr_section)
585 intel_state.is_mem |= 2 - !intel_state.in_bracket;
588 return 1;
591 int i386_need_index_operator (void)
593 return intel_syntax < 0;
596 static int
597 i386_intel_operand (char *operand_string, int got_a_float)
599 char *saved_input_line_pointer, *buf;
600 segT exp_seg;
601 expressionS exp, *expP;
602 char suffix = 0;
603 bool rc_sae_modifier = i.rounding.type != rc_none && i.rounding.modifier;
604 int ret;
606 /* Handle vector immediates. */
607 if (RC_SAE_immediate (operand_string))
609 if (i.imm_operands)
611 as_bad (_("`%s': RC/SAE operand must precede immediate operands"),
612 current_templates->start->name);
613 return 0;
616 return 1;
619 /* Initialize state structure. */
620 intel_state.op_modifier = O_absent;
621 intel_state.is_mem = 0;
622 intel_state.is_indirect = 0;
623 intel_state.has_offset = 0;
624 intel_state.base = NULL;
625 intel_state.index = NULL;
626 intel_state.seg = NULL;
627 operand_type_set (&intel_state.reloc_types, ~0);
628 gas_assert (!intel_state.in_offset);
629 gas_assert (!intel_state.in_bracket);
630 gas_assert (!intel_state.in_scale);
632 saved_input_line_pointer = input_line_pointer;
633 input_line_pointer = buf = xstrdup (operand_string);
635 intel_syntax = -1;
636 memset (&exp, 0, sizeof(exp));
637 exp_seg = expression (&exp);
638 ret = i386_intel_simplify (&exp);
639 intel_syntax = 1;
641 SKIP_WHITESPACE ();
643 /* Handle vector operations. */
644 if (*input_line_pointer == '{')
646 char *end = check_VecOperations (input_line_pointer);
647 if (end)
648 input_line_pointer = end;
649 else
650 ret = 0;
653 if (!is_end_of_line[(unsigned char) *input_line_pointer])
655 if (ret)
656 as_bad (_("junk `%s' after expression"), input_line_pointer);
657 ret = 0;
659 else if (exp.X_op == O_illegal || exp.X_op == O_absent)
661 if (ret)
662 as_bad (_("invalid expression"));
663 ret = 0;
665 else if (!intel_state.has_offset
666 && input_line_pointer > buf
667 && *(input_line_pointer - 1) == ']')
669 intel_state.is_mem |= 1;
670 intel_state.is_indirect = 1;
673 input_line_pointer = saved_input_line_pointer;
674 free (buf);
676 gas_assert (!intel_state.in_offset);
677 gas_assert (!intel_state.in_bracket);
678 gas_assert (!intel_state.in_scale);
680 if (!ret)
681 return 0;
683 if (intel_state.op_modifier != O_absent
684 && (current_templates->start->opcode_modifier.opcodespace != SPACE_BASE
685 || current_templates->start->base_opcode != 0x8d /* lea */))
687 i.types[this_operand].bitfield.unspecified = 0;
689 switch (intel_state.op_modifier)
691 case O_byte_ptr:
692 i.types[this_operand].bitfield.byte = 1;
693 suffix = BYTE_MNEM_SUFFIX;
694 break;
696 case O_word_ptr:
697 i.types[this_operand].bitfield.word = 1;
698 if (got_a_float == 2) /* "fi..." */
699 suffix = SHORT_MNEM_SUFFIX;
700 else
701 suffix = WORD_MNEM_SUFFIX;
702 break;
704 case O_dword_ptr:
705 i.types[this_operand].bitfield.dword = 1;
706 if ((current_templates->start->name[0] == 'l'
707 && current_templates->start->name[2] == 's'
708 && current_templates->start->name[3] == 0)
709 || (current_templates->start->opcode_modifier.opcodespace == SPACE_BASE
710 && current_templates->start->base_opcode == 0x62 /* bound */))
711 suffix = WORD_MNEM_SUFFIX;
712 else if (flag_code != CODE_32BIT
713 && (current_templates->start->opcode_modifier.jump == JUMP
714 || current_templates->start->opcode_modifier.jump
715 == JUMP_DWORD))
716 suffix = flag_code == CODE_16BIT ? LONG_DOUBLE_MNEM_SUFFIX
717 : WORD_MNEM_SUFFIX;
718 else if (got_a_float == 1) /* "f..." */
719 suffix = SHORT_MNEM_SUFFIX;
720 else
721 suffix = LONG_MNEM_SUFFIX;
722 break;
724 case O_fword_ptr:
725 i.types[this_operand].bitfield.fword = 1;
726 if (current_templates->start->name[0] == 'l'
727 && current_templates->start->name[2] == 's'
728 && current_templates->start->name[3] == 0)
729 suffix = LONG_MNEM_SUFFIX;
730 else if (!got_a_float)
732 if (flag_code == CODE_16BIT)
733 add_prefix (DATA_PREFIX_OPCODE);
734 suffix = LONG_DOUBLE_MNEM_SUFFIX;
736 break;
738 case O_qword_ptr: /* O_mmword_ptr */
739 i.types[this_operand].bitfield.qword = 1;
740 if ((current_templates->start->opcode_modifier.opcodespace == SPACE_BASE
741 && current_templates->start->base_opcode == 0x62 /* bound */)
742 || got_a_float == 1) /* "f..." */
743 suffix = LONG_MNEM_SUFFIX;
744 else
745 suffix = QWORD_MNEM_SUFFIX;
746 break;
748 case O_tbyte_ptr:
749 i.types[this_operand].bitfield.tbyte = 1;
750 if (got_a_float == 1)
751 suffix = LONG_DOUBLE_MNEM_SUFFIX;
752 else if ((current_templates->start->operand_types[0].bitfield.fword
753 || current_templates->start->operand_types[0].bitfield.tbyte
754 || current_templates->start->opcode_modifier.jump == JUMP_DWORD
755 || current_templates->start->opcode_modifier.jump == JUMP)
756 && flag_code == CODE_64BIT)
757 suffix = QWORD_MNEM_SUFFIX; /* l[fgs]s, [ls][gi]dt, call, jmp */
758 else
759 i.types[this_operand].bitfield.byte = 1; /* cause an error */
760 break;
762 case O_oword_ptr: /* O_xmmword_ptr */
763 i.types[this_operand].bitfield.xmmword = 1;
764 break;
766 case O_ymmword_ptr:
767 i.types[this_operand].bitfield.ymmword = 1;
768 break;
770 case O_zmmword_ptr:
771 i.types[this_operand].bitfield.zmmword = 1;
772 break;
774 case O_far_ptr:
775 suffix = LONG_DOUBLE_MNEM_SUFFIX;
776 /* FALLTHROUGH */
777 case O_near_ptr:
778 if (current_templates->start->opcode_modifier.jump != JUMP
779 && current_templates->start->opcode_modifier.jump != JUMP_DWORD)
781 /* cause an error */
782 i.types[this_operand].bitfield.byte = 1;
783 i.types[this_operand].bitfield.tbyte = 1;
784 suffix = i.suffix;
786 break;
788 default:
789 BAD_CASE (intel_state.op_modifier);
790 break;
793 if (!i.suffix)
794 i.suffix = suffix;
795 else if (i.suffix != suffix)
797 as_bad (_("conflicting operand size modifiers"));
798 return 0;
802 /* Operands for jump/call need special consideration. */
803 if (current_templates->start->opcode_modifier.jump == JUMP
804 || current_templates->start->opcode_modifier.jump == JUMP_DWORD
805 || current_templates->start->opcode_modifier.jump == JUMP_INTERSEGMENT)
807 bool jumpabsolute = false;
809 if (i.op[this_operand].regs
810 || intel_state.base
811 || intel_state.index
812 || intel_state.is_mem > 1)
813 jumpabsolute = true;
814 else
815 switch (intel_state.op_modifier)
817 case O_near_ptr:
818 if (intel_state.seg)
819 jumpabsolute = true;
820 else
821 intel_state.is_mem = 1;
822 break;
823 case O_far_ptr:
824 case O_absent:
825 if (!intel_state.seg)
827 intel_state.is_mem = 1;
828 if (intel_state.op_modifier == O_absent)
830 if (intel_state.is_indirect == 1)
831 jumpabsolute = true;
832 break;
834 as_bad (_("cannot infer the segment part of the operand"));
835 return 0;
837 else if (S_GET_SEGMENT (intel_state.seg) == reg_section)
838 jumpabsolute = true;
839 else
841 i386_operand_type types;
843 if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
845 as_bad (_("at most %d immediate operands are allowed"),
846 MAX_IMMEDIATE_OPERANDS);
847 return 0;
849 expP = &im_expressions[i.imm_operands++];
850 memset (expP, 0, sizeof(*expP));
851 expP->X_op = O_symbol;
852 expP->X_add_symbol = intel_state.seg;
853 i.op[this_operand].imms = expP;
855 resolve_expression (expP);
856 operand_type_set (&types, ~0);
857 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state.seg),
858 expP, types, operand_string))
859 return 0;
860 if (i.operands < MAX_OPERANDS)
862 this_operand = i.operands++;
863 i.types[this_operand].bitfield.unspecified = 1;
865 if (suffix == LONG_DOUBLE_MNEM_SUFFIX)
866 i.suffix = 0;
867 intel_state.seg = NULL;
868 intel_state.is_mem = 0;
870 break;
871 default:
872 jumpabsolute = true;
873 break;
875 if (jumpabsolute)
877 i.jumpabsolute = true;
878 intel_state.is_mem |= 1;
881 else if (intel_state.seg)
882 intel_state.is_mem |= 1;
884 if (i.op[this_operand].regs)
886 i386_operand_type temp;
888 /* Register operand. */
889 if (intel_state.base || intel_state.index || intel_state.seg)
891 as_bad (_("invalid operand"));
892 return 0;
895 temp = i.op[this_operand].regs->reg_type;
896 temp.bitfield.baseindex = 0;
897 i.types[this_operand] = operand_type_or (i.types[this_operand],
898 temp);
899 i.types[this_operand].bitfield.unspecified = 0;
900 ++i.reg_operands;
902 if ((i.rounding.type != rc_none && !i.rounding.modifier
903 && temp.bitfield.class != Reg)
904 || rc_sae_modifier)
906 unsigned int j;
908 for (j = 0; j < ARRAY_SIZE (RC_NamesTable); ++j)
909 if (i.rounding.type == RC_NamesTable[j].type)
910 break;
911 as_bad (_("`%s': misplaced `{%s}'"),
912 current_templates->start->name, RC_NamesTable[j].name);
913 return 0;
916 else if (intel_state.base
917 || intel_state.index
918 || intel_state.seg
919 || intel_state.is_mem)
921 /* Memory operand. */
922 if (i.mem_operands == 1 && !maybe_adjust_templates ())
923 return 0;
924 if ((int) i.mem_operands
925 >= 2 - !current_templates->start->opcode_modifier.isstring)
927 /* Handle
929 call 0x9090,0x90909090
930 lcall 0x9090,0x90909090
931 jmp 0x9090,0x90909090
932 ljmp 0x9090,0x90909090
935 if ((current_templates->start->opcode_modifier.jump == JUMP_INTERSEGMENT
936 || current_templates->start->opcode_modifier.jump == JUMP_DWORD
937 || current_templates->start->opcode_modifier.jump == JUMP)
938 && this_operand == 1
939 && intel_state.seg == NULL
940 && i.mem_operands == 1
941 && i.disp_operands == 1
942 && intel_state.op_modifier == O_absent)
944 /* Try to process the first operand as immediate, */
945 this_operand = 0;
946 if (i386_finalize_immediate (exp_seg, i.op[0].imms,
947 intel_state.reloc_types,
948 NULL))
950 this_operand = 1;
951 expP = &im_expressions[0];
952 i.op[this_operand].imms = expP;
953 *expP = exp;
955 /* Try to process the second operand as immediate, */
956 if (i386_finalize_immediate (exp_seg, expP,
957 intel_state.reloc_types,
958 NULL))
960 i.mem_operands = 0;
961 i.disp_operands = 0;
962 i.imm_operands = 2;
963 i.flags[0] &= ~Operand_Mem;
964 i.types[0].bitfield.disp16 = 0;
965 i.types[0].bitfield.disp32 = 0;
966 i.types[0].bitfield.disp32s = 0;
967 return 1;
972 as_bad (_("too many memory references for `%s'"),
973 current_templates->start->name);
974 return 0;
977 /* Swap base and index in 16-bit memory operands like
978 [si+bx]. Since i386_index_check is also used in AT&T
979 mode we have to do this here. */
980 if (intel_state.base
981 && intel_state.index
982 && intel_state.base->reg_type.bitfield.word
983 && intel_state.index->reg_type.bitfield.word
984 && intel_state.base->reg_num >= 6
985 && intel_state.index->reg_num < 6)
987 i.base_reg = intel_state.index;
988 i.index_reg = intel_state.base;
990 else
992 i.base_reg = intel_state.base;
993 i.index_reg = intel_state.index;
996 if (i.base_reg || i.index_reg)
997 i.types[this_operand].bitfield.baseindex = 1;
999 expP = &disp_expressions[i.disp_operands];
1000 memcpy (expP, &exp, sizeof(exp));
1001 resolve_expression (expP);
1003 if (expP->X_op != O_constant
1004 || expP->X_add_number
1005 || !i.types[this_operand].bitfield.baseindex)
1007 i.op[this_operand].disps = expP;
1008 i.disp_operands++;
1010 i386_addressing_mode ();
1012 if (flag_code == CODE_64BIT)
1014 if (!i.prefix[ADDR_PREFIX])
1016 i.types[this_operand].bitfield.disp64 = 1;
1017 i.types[this_operand].bitfield.disp32s = 1;
1019 else
1020 i.types[this_operand].bitfield.disp32 = 1;
1022 else if (!i.prefix[ADDR_PREFIX] ^ (flag_code == CODE_16BIT))
1023 i.types[this_operand].bitfield.disp32 = 1;
1024 else
1025 i.types[this_operand].bitfield.disp16 = 1;
1027 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
1029 * exp_seg is used only for verification in
1030 * i386_finalize_displacement, and we can end up seeing reg_section
1031 * here - but we know we removed all registers from the expression
1032 * (or error-ed on any remaining ones) in i386_intel_simplify. I
1033 * consider the check in i386_finalize_displacement bogus anyway, in
1034 * particular because it doesn't allow for expr_section, so I'd
1035 * rather see that check (and the similar one in
1036 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
1037 * expert I can't really say whether that would have other bad side
1038 * effects.
1040 if (OUTPUT_FLAVOR == bfd_target_aout_flavour
1041 && exp_seg == reg_section)
1042 exp_seg = expP->X_op != O_constant ? undefined_section
1043 : absolute_section;
1044 #endif
1046 if (!i386_finalize_displacement (exp_seg, expP,
1047 intel_state.reloc_types,
1048 operand_string))
1049 return 0;
1052 if (intel_state.seg)
1054 for (ret = check_none; ; ret = operand_check)
1056 expP = symbol_get_value_expression (intel_state.seg);
1057 if (expP->X_op != O_full_ptr
1058 || symbol_get_value_expression (expP->X_op_symbol)->X_op
1059 != O_register)
1060 break;
1061 intel_state.seg = expP->X_add_symbol;
1063 if (expP->X_op != O_register)
1065 as_bad (_("segment register name expected"));
1066 return 0;
1068 if (i386_regtab[expP->X_add_number].reg_type.bitfield.class != SReg)
1070 as_bad (_("invalid use of register"));
1071 return 0;
1073 switch (ret)
1075 case check_error:
1076 as_bad (_("redundant segment overrides"));
1077 return 0;
1078 case check_warning:
1079 as_warn (_("redundant segment overrides"));
1080 break;
1082 if (i386_regtab[expP->X_add_number].reg_num == RegFlat)
1083 i.seg[i.mem_operands] = NULL;
1084 else
1085 i.seg[i.mem_operands] = &i386_regtab[expP->X_add_number];
1088 if (!i386_index_check (operand_string))
1089 return 0;
1091 i.flags[this_operand] |= Operand_Mem;
1092 if (i.mem_operands == 0)
1093 i.memop1_string = xstrdup (operand_string);
1094 ++i.mem_operands;
1096 else
1098 /* Immediate. */
1099 if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
1101 as_bad (_("at most %d immediate operands are allowed"),
1102 MAX_IMMEDIATE_OPERANDS);
1103 return 0;
1106 expP = &im_expressions[i.imm_operands++];
1107 i.op[this_operand].imms = expP;
1108 *expP = exp;
1110 return i386_finalize_immediate (exp_seg, expP, intel_state.reloc_types,
1111 operand_string);
1114 return 1;