x86/Intel: don't report multiple errors for a single insn operand
[deliverable/binutils-gdb.git] / gas / config / tc-i386-intel.c
1 /* tc-i386.c -- Assemble Intel syntax code for ix86/x86-64
2 Copyright (C) 2009-2017 Free Software Foundation, Inc.
3
4 This file is part of GAS, the GNU Assembler.
5
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.
10
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.
15
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. */
20
21 static struct
22 {
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;
36 }
37 intel_state;
38
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
67
68 static struct
69 {
70 const char *name;
71 operatorT op;
72 unsigned int operands;
73 }
74 const i386_operators[] =
75 {
76 { "and", O_bit_and, 2 },
77 { "eq", O_eq, 2 },
78 { "ge", O_ge, 2 },
79 { "gt", O_gt, 2 },
80 { "le", O_le, 2 },
81 { "lt", O_lt, 2 },
82 { "mod", O_modulus, 2 },
83 { "ne", O_ne, 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 }
92 };
93
94 static struct
95 {
96 const char *name;
97 operatorT op;
98 unsigned short sz[3];
99 }
100 const i386_types[] =
101 {
102 #define I386_TYPE(t, n) { #t, O_##t##_ptr, { n, n, n } }
103 I386_TYPE(byte, 1),
104 I386_TYPE(word, 2),
105 I386_TYPE(dword, 4),
106 I386_TYPE(fword, 6),
107 I386_TYPE(qword, 8),
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),
113 #undef I386_TYPE
114 { "near", O_near_ptr, { 0xff04, 0xff02, 0xff08 } },
115 { "far", O_far_ptr, { 0xff06, 0xff05, 0xff06 } },
116 { NULL, O_illegal, { 0, 0, 0 } }
117 };
118
119 operatorT i386_operator (const char *name, unsigned int operands, char *pc)
120 {
121 unsigned int j;
122
123 if (!intel_syntax)
124 return O_absent;
125
126 if (!name)
127 {
128 if (operands != 2)
129 return O_illegal;
130 switch (*input_line_pointer)
131 {
132 case ':':
133 ++input_line_pointer;
134 return O_full_ptr;
135 case '[':
136 ++input_line_pointer;
137 return O_index;
138 case '@':
139 if (this_operand >= 0 && i.reloc[this_operand] == NO_RELOC)
140 {
141 int adjust = 0;
142 char *gotfree_input_line = lex_got (&i.reloc[this_operand],
143 &adjust,
144 &intel_state.reloc_types);
145
146 if (!gotfree_input_line)
147 break;
148 free (gotfree_input_line);
149 *input_line_pointer++ = '+';
150 memset (input_line_pointer, '0', adjust - 1);
151 input_line_pointer[adjust - 1] = ' ';
152 return O_add;
153 }
154 break;
155 }
156 return O_illegal;
157 }
158
159 for (j = 0; i386_operators[j].name; ++j)
160 if (strcasecmp (i386_operators[j].name, name) == 0)
161 {
162 if (i386_operators[j].operands
163 && i386_operators[j].operands != operands)
164 return O_illegal;
165 return i386_operators[j].op;
166 }
167
168 for (j = 0; i386_types[j].name; ++j)
169 if (strcasecmp (i386_types[j].name, name) == 0)
170 break;
171
172 if (i386_types[j].name && *pc == ' ')
173 {
174 char *pname;
175 char c;
176
177 ++input_line_pointer;
178 c = get_symbol_name (&pname);
179
180 if (strcasecmp (pname, "ptr") == 0)
181 {
182 /* FIXME: What if c == '"' ? */
183 pname[-1] = *pc;
184 *pc = c;
185 if (intel_syntax > 0 || operands != 1)
186 return O_illegal;
187 return i386_types[j].op;
188 }
189
190 (void) restore_line_pointer (c);
191 input_line_pointer = pname - 1;
192 }
193
194 return O_absent;
195 }
196
197 static int i386_intel_parse_name (const char *name, expressionS *e)
198 {
199 unsigned int j;
200
201 if (! strcmp (name, "$"))
202 {
203 current_location (e);
204 return 1;
205 }
206
207 for (j = 0; i386_types[j].name; ++j)
208 if (strcasecmp(i386_types[j].name, name) == 0)
209 {
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;
214 return 1;
215 }
216
217 return 0;
218 }
219
220 static INLINE int i386_intel_check (const reg_entry *rreg,
221 const reg_entry *base,
222 const reg_entry *iindex)
223 {
224 if ((this_operand >= 0
225 && rreg != i.op[this_operand].regs)
226 || base != intel_state.base
227 || iindex != intel_state.index)
228 {
229 as_bad (_("invalid use of register"));
230 return 0;
231 }
232 return 1;
233 }
234
235 static INLINE void i386_intel_fold (expressionS *e, symbolS *sym)
236 {
237 expressionS *exp = symbol_get_value_expression (sym);
238 if (S_GET_SEGMENT (sym) == absolute_section)
239 {
240 offsetT val = e->X_add_number;
241
242 *e = *exp;
243 e->X_add_number += val;
244 }
245 else
246 {
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;
253 e->X_op = O_symbol;
254 }
255 }
256
257 static int
258 i386_intel_simplify_register (expressionS *e)
259 {
260 int reg_num;
261
262 if (this_operand < 0 || intel_state.in_offset)
263 {
264 as_bad (_("invalid use of register"));
265 return 0;
266 }
267
268 if (e->X_op == O_register)
269 reg_num = e->X_add_number;
270 else
271 reg_num = e->X_md - 1;
272
273 if (!intel_state.in_bracket)
274 {
275 if (i.op[this_operand].regs)
276 {
277 as_bad (_("invalid use of register"));
278 return 0;
279 }
280 if (i386_regtab[reg_num].reg_type.bitfield.sreg3
281 && i386_regtab[reg_num].reg_num == RegFlat)
282 {
283 as_bad (_("invalid use of pseudo-register"));
284 return 0;
285 }
286 i.op[this_operand].regs = i386_regtab + reg_num;
287 }
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)
298 {
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;
304 else
305 {
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;
309 }
310 }
311 else
312 {
313 /* esp is invalid as index */
314 intel_state.index = i386_regtab + REGNAM_EAX + ESP_REG_NUM;
315 }
316 return 2;
317 }
318
319 static int i386_intel_simplify (expressionS *);
320
321 static INLINE int i386_intel_simplify_symbol(symbolS *sym)
322 {
323 int ret = i386_intel_simplify (symbol_get_value_expression (sym));
324
325 if (ret == 2)
326 {
327 S_SET_SEGMENT(sym, absolute_section);
328 ret = 1;
329 }
330 return ret;
331 }
332
333 static int i386_intel_simplify (expressionS *e)
334 {
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;
339 int ret;
340
341 if (!intel_syntax)
342 return 1;
343
344 switch (e->X_op)
345 {
346 case O_index:
347 if (e->X_add_symbol)
348 {
349 if (!i386_intel_simplify_symbol (e->X_add_symbol)
350 || !i386_intel_check(the_reg, intel_state.base,
351 intel_state.index))
352 return 0;
353 }
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;
359 if (!ret)
360 return 0;
361 if (e->X_add_symbol)
362 e->X_op = O_add;
363 else
364 i386_intel_fold (e, e->X_op_symbol);
365 break;
366
367 case O_offset:
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))
373 return 0;
374 i386_intel_fold (e, e->X_add_symbol);
375 return ret;
376
377 case O_byte_ptr:
378 case O_word_ptr:
379 case O_dword_ptr:
380 case O_fword_ptr:
381 case O_qword_ptr:
382 case O_tbyte_ptr:
383 case O_oword_ptr:
384 case O_xmmword_ptr:
385 case O_ymmword_ptr:
386 case O_zmmword_ptr:
387 case O_near_ptr:
388 case O_far_ptr:
389 if (intel_state.op_modifier == O_absent)
390 intel_state.op_modifier = e->X_op;
391 /* FALLTHROUGH */
392 case O_short:
393 if (symbol_get_value_expression (e->X_add_symbol)->X_op
394 == O_register)
395 {
396 as_bad (_("invalid use of register"));
397 return 0;
398 }
399 if (!i386_intel_simplify_symbol (e->X_add_symbol))
400 return 0;
401 i386_intel_fold (e, e->X_add_symbol);
402 break;
403
404 case O_full_ptr:
405 if (symbol_get_value_expression (e->X_op_symbol)->X_op
406 == O_register)
407 {
408 as_bad (_("invalid use of register"));
409 return 0;
410 }
411 if (!i386_intel_simplify_symbol (e->X_op_symbol)
412 || !i386_intel_check(the_reg, intel_state.base,
413 intel_state.index))
414 return 0;
415 if (!intel_state.in_offset)
416 intel_state.seg = e->X_add_symbol;
417 i386_intel_fold (e, e->X_op_symbol);
418 break;
419
420 case O_multiply:
421 if (this_operand >= 0 && intel_state.in_bracket)
422 {
423 expressionS *scale = NULL;
424 int has_index = (intel_state.index != NULL);
425
426 if (!intel_state.in_scale++)
427 intel_state.scale_factor = 1;
428
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);
432
433 if (ret)
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);
437
438 if (ret && scale)
439 {
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;
445 }
446
447 --intel_state.in_scale;
448 if (!ret)
449 return 0;
450
451 if (!intel_state.in_scale)
452 switch (intel_state.scale_factor)
453 {
454 case 1:
455 i.log2_scale_factor = 0;
456 break;
457 case 2:
458 i.log2_scale_factor = 1;
459 break;
460 case 4:
461 i.log2_scale_factor = 2;
462 break;
463 case 8:
464 i.log2_scale_factor = 3;
465 break;
466 default:
467 /* esp is invalid as index */
468 intel_state.index = i386_regtab + REGNAM_EAX + ESP_REG_NUM;
469 break;
470 }
471
472 break;
473 }
474 goto fallthrough;
475
476 case O_register:
477 ret = i386_intel_simplify_register (e);
478 if (ret == 2)
479 {
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;
483 e->X_add_number = 0;
484 }
485 return ret;
486
487 case O_constant:
488 if (e->X_md)
489 return i386_intel_simplify_register (e);
490
491 /* FALLTHROUGH */
492 default:
493 fallthrough:
494 if (e->X_add_symbol
495 && !i386_intel_simplify_symbol (e->X_add_symbol))
496 return 0;
497 if (e->X_op == O_add || e->X_op == O_subtract)
498 {
499 base = intel_state.base;
500 state_index = intel_state.index;
501 }
502 if (!i386_intel_check (the_reg, base, state_index)
503 || (e->X_op_symbol
504 && !i386_intel_simplify_symbol (e->X_op_symbol))
505 || !i386_intel_check (the_reg,
506 (e->X_op != O_add
507 ? base : intel_state.base),
508 (e->X_op != O_add
509 ? state_index : intel_state.index)))
510 return 0;
511 break;
512 }
513
514 if (this_operand >= 0
515 && e->X_op == O_symbol
516 && !intel_state.in_offset)
517 {
518 segT seg = S_GET_SEGMENT (e->X_add_symbol);
519
520 if (seg != absolute_section
521 && seg != reg_section
522 && seg != expr_section)
523 intel_state.is_mem |= 2 - !intel_state.in_bracket;
524 }
525
526 return 1;
527 }
528
529 int i386_need_index_operator (void)
530 {
531 return intel_syntax < 0;
532 }
533
534 static int
535 i386_intel_operand (char *operand_string, int got_a_float)
536 {
537 char *saved_input_line_pointer, *buf;
538 segT exp_seg;
539 expressionS exp, *expP;
540 char suffix = 0;
541 int ret;
542
543 /* Handle vector immediates. */
544 if (RC_SAE_immediate (operand_string))
545 return 1;
546
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);
559
560 saved_input_line_pointer = input_line_pointer;
561 input_line_pointer = buf = xstrdup (operand_string);
562
563 intel_syntax = -1;
564 memset (&exp, 0, sizeof(exp));
565 exp_seg = expression (&exp);
566 ret = i386_intel_simplify (&exp);
567 intel_syntax = 1;
568
569 SKIP_WHITESPACE ();
570
571 /* Handle vector operations. */
572 if (*input_line_pointer == '{')
573 {
574 char *end = check_VecOperations (input_line_pointer, NULL);
575 if (end)
576 input_line_pointer = end;
577 else
578 ret = 0;
579 }
580
581 if (!is_end_of_line[(unsigned char) *input_line_pointer])
582 {
583 if (ret)
584 as_bad (_("junk `%s' after expression"), input_line_pointer);
585 ret = 0;
586 }
587 else if (exp.X_op == O_illegal || exp.X_op == O_absent)
588 {
589 if (ret)
590 as_bad (_("invalid expression"));
591 ret = 0;
592 }
593 else if (!intel_state.has_offset
594 && input_line_pointer > buf
595 && *(input_line_pointer - 1) == ']')
596 {
597 intel_state.is_mem |= 1;
598 intel_state.is_indirect = 1;
599 }
600
601 input_line_pointer = saved_input_line_pointer;
602 free (buf);
603
604 gas_assert (!intel_state.in_offset);
605 gas_assert (!intel_state.in_bracket);
606 gas_assert (!intel_state.in_scale);
607
608 if (!ret)
609 return 0;
610
611 if (intel_state.op_modifier != O_absent
612 && current_templates->start->base_opcode != 0x8d /* lea */)
613 {
614 i.types[this_operand].bitfield.unspecified = 0;
615
616 switch (intel_state.op_modifier)
617 {
618 case O_byte_ptr:
619 i.types[this_operand].bitfield.byte = 1;
620 suffix = BYTE_MNEM_SUFFIX;
621 break;
622
623 case O_word_ptr:
624 i.types[this_operand].bitfield.word = 1;
625 if ((current_templates->start->name[0] == 'l'
626 && current_templates->start->name[2] == 's'
627 && current_templates->start->name[3] == 0)
628 || current_templates->start->base_opcode == 0x62 /* bound */)
629 suffix = BYTE_MNEM_SUFFIX; /* so it will cause an error */
630 else if (got_a_float == 2) /* "fi..." */
631 suffix = SHORT_MNEM_SUFFIX;
632 else
633 suffix = WORD_MNEM_SUFFIX;
634 break;
635
636 case O_dword_ptr:
637 i.types[this_operand].bitfield.dword = 1;
638 if ((current_templates->start->name[0] == 'l'
639 && current_templates->start->name[2] == 's'
640 && current_templates->start->name[3] == 0)
641 || current_templates->start->base_opcode == 0x62 /* bound */)
642 suffix = WORD_MNEM_SUFFIX;
643 else if (flag_code == CODE_16BIT
644 && (current_templates->start->opcode_modifier.jump
645 || current_templates->start->opcode_modifier.jumpdword))
646 suffix = LONG_DOUBLE_MNEM_SUFFIX;
647 else if (got_a_float == 1) /* "f..." */
648 suffix = SHORT_MNEM_SUFFIX;
649 else
650 suffix = LONG_MNEM_SUFFIX;
651 break;
652
653 case O_fword_ptr:
654 i.types[this_operand].bitfield.fword = 1;
655 if (current_templates->start->name[0] == 'l'
656 && current_templates->start->name[2] == 's'
657 && current_templates->start->name[3] == 0)
658 suffix = LONG_MNEM_SUFFIX;
659 else if (!got_a_float)
660 {
661 if (flag_code == CODE_16BIT)
662 add_prefix (DATA_PREFIX_OPCODE);
663 suffix = LONG_DOUBLE_MNEM_SUFFIX;
664 }
665 else
666 suffix = BYTE_MNEM_SUFFIX; /* so it will cause an error */
667 break;
668
669 case O_qword_ptr:
670 i.types[this_operand].bitfield.qword = 1;
671 if (current_templates->start->base_opcode == 0x62 /* bound */
672 || got_a_float == 1) /* "f..." */
673 suffix = LONG_MNEM_SUFFIX;
674 else
675 suffix = QWORD_MNEM_SUFFIX;
676 break;
677
678 case O_tbyte_ptr:
679 i.types[this_operand].bitfield.tbyte = 1;
680 if (got_a_float == 1)
681 suffix = LONG_DOUBLE_MNEM_SUFFIX;
682 else
683 suffix = BYTE_MNEM_SUFFIX; /* so it will cause an error */
684 break;
685
686 case O_oword_ptr:
687 case O_xmmword_ptr:
688 i.types[this_operand].bitfield.xmmword = 1;
689 suffix = XMMWORD_MNEM_SUFFIX;
690 break;
691
692 case O_ymmword_ptr:
693 i.types[this_operand].bitfield.ymmword = 1;
694 suffix = YMMWORD_MNEM_SUFFIX;
695 break;
696
697 case O_zmmword_ptr:
698 i.types[this_operand].bitfield.zmmword = 1;
699 suffix = ZMMWORD_MNEM_SUFFIX;
700 break;
701
702 case O_far_ptr:
703 suffix = LONG_DOUBLE_MNEM_SUFFIX;
704 /* FALLTHROUGH */
705 case O_near_ptr:
706 if (!current_templates->start->opcode_modifier.jump
707 && !current_templates->start->opcode_modifier.jumpdword)
708 suffix = got_a_float /* so it will cause an error */
709 ? BYTE_MNEM_SUFFIX
710 : LONG_DOUBLE_MNEM_SUFFIX;
711 break;
712
713 default:
714 BAD_CASE (intel_state.op_modifier);
715 break;
716 }
717
718 if (!i.suffix)
719 i.suffix = suffix;
720 else if (i.suffix != suffix)
721 {
722 as_bad (_("conflicting operand size modifiers"));
723 return 0;
724 }
725 }
726
727 /* Operands for jump/call need special consideration. */
728 if (current_templates->start->opcode_modifier.jump
729 || current_templates->start->opcode_modifier.jumpdword
730 || current_templates->start->opcode_modifier.jumpintersegment)
731 {
732 if (i.op[this_operand].regs
733 || intel_state.base
734 || intel_state.index
735 || intel_state.is_mem > 1)
736 i.types[this_operand].bitfield.jumpabsolute = 1;
737 else
738 switch (intel_state.op_modifier)
739 {
740 case O_near_ptr:
741 if (intel_state.seg)
742 i.types[this_operand].bitfield.jumpabsolute = 1;
743 else
744 intel_state.is_mem = 1;
745 break;
746 case O_far_ptr:
747 case O_absent:
748 if (!intel_state.seg)
749 {
750 intel_state.is_mem = 1;
751 if (intel_state.op_modifier == O_absent)
752 {
753 if (intel_state.is_indirect == 1)
754 i.types[this_operand].bitfield.jumpabsolute = 1;
755 break;
756 }
757 as_bad (_("cannot infer the segment part of the operand"));
758 return 0;
759 }
760 else if (S_GET_SEGMENT (intel_state.seg) == reg_section)
761 i.types[this_operand].bitfield.jumpabsolute = 1;
762 else
763 {
764 i386_operand_type types;
765
766 if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
767 {
768 as_bad (_("at most %d immediate operands are allowed"),
769 MAX_IMMEDIATE_OPERANDS);
770 return 0;
771 }
772 expP = &im_expressions[i.imm_operands++];
773 memset (expP, 0, sizeof(*expP));
774 expP->X_op = O_symbol;
775 expP->X_add_symbol = intel_state.seg;
776 i.op[this_operand].imms = expP;
777
778 resolve_expression (expP);
779 operand_type_set (&types, ~0);
780 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state.seg),
781 expP, types, operand_string))
782 return 0;
783 if (i.operands < MAX_OPERANDS)
784 {
785 this_operand = i.operands++;
786 i.types[this_operand].bitfield.unspecified = 1;
787 }
788 if (suffix == LONG_DOUBLE_MNEM_SUFFIX)
789 i.suffix = 0;
790 intel_state.seg = NULL;
791 intel_state.is_mem = 0;
792 }
793 break;
794 default:
795 i.types[this_operand].bitfield.jumpabsolute = 1;
796 break;
797 }
798 if (i.types[this_operand].bitfield.jumpabsolute)
799 intel_state.is_mem |= 1;
800 }
801 else if (intel_state.seg)
802 intel_state.is_mem |= 1;
803
804 if (i.op[this_operand].regs)
805 {
806 i386_operand_type temp;
807
808 /* Register operand. */
809 if (intel_state.base || intel_state.index || intel_state.seg)
810 {
811 as_bad (_("invalid operand"));
812 return 0;
813 }
814
815 temp = i.op[this_operand].regs->reg_type;
816 temp.bitfield.baseindex = 0;
817 i.types[this_operand] = operand_type_or (i.types[this_operand],
818 temp);
819 i.types[this_operand].bitfield.unspecified = 0;
820 ++i.reg_operands;
821 }
822 else if (intel_state.base
823 || intel_state.index
824 || intel_state.seg
825 || intel_state.is_mem)
826 {
827 /* Memory operand. */
828 if (i.mem_operands == 1 && !maybe_adjust_templates ())
829 return 0;
830 if ((int) i.mem_operands
831 >= 2 - !current_templates->start->opcode_modifier.isstring)
832 {
833 /* Handle
834
835 call 0x9090,0x90909090
836 lcall 0x9090,0x90909090
837 jmp 0x9090,0x90909090
838 ljmp 0x9090,0x90909090
839 */
840
841 if ((current_templates->start->opcode_modifier.jumpintersegment
842 || current_templates->start->opcode_modifier.jumpdword
843 || current_templates->start->opcode_modifier.jump)
844 && this_operand == 1
845 && intel_state.seg == NULL
846 && i.mem_operands == 1
847 && i.disp_operands == 1
848 && intel_state.op_modifier == O_absent)
849 {
850 /* Try to process the first operand as immediate, */
851 this_operand = 0;
852 if (i386_finalize_immediate (exp_seg, i.op[0].imms,
853 intel_state.reloc_types,
854 NULL))
855 {
856 this_operand = 1;
857 expP = &im_expressions[0];
858 i.op[this_operand].imms = expP;
859 *expP = exp;
860
861 /* Try to process the second operand as immediate, */
862 if (i386_finalize_immediate (exp_seg, expP,
863 intel_state.reloc_types,
864 NULL))
865 {
866 i.mem_operands = 0;
867 i.disp_operands = 0;
868 i.imm_operands = 2;
869 i.types[0].bitfield.mem = 0;
870 i.types[0].bitfield.disp16 = 0;
871 i.types[0].bitfield.disp32 = 0;
872 i.types[0].bitfield.disp32s = 0;
873 return 1;
874 }
875 }
876 }
877
878 as_bad (_("too many memory references for `%s'"),
879 current_templates->start->name);
880 return 0;
881 }
882
883 /* Swap base and index in 16-bit memory operands like
884 [si+bx]. Since i386_index_check is also used in AT&T
885 mode we have to do this here. */
886 if (intel_state.base
887 && intel_state.index
888 && intel_state.base->reg_type.bitfield.reg16
889 && intel_state.index->reg_type.bitfield.reg16
890 && intel_state.base->reg_num >= 6
891 && intel_state.index->reg_num < 6)
892 {
893 i.base_reg = intel_state.index;
894 i.index_reg = intel_state.base;
895 }
896 else
897 {
898 i.base_reg = intel_state.base;
899 i.index_reg = intel_state.index;
900 }
901
902 if (i.base_reg || i.index_reg)
903 i.types[this_operand].bitfield.baseindex = 1;
904
905 expP = &disp_expressions[i.disp_operands];
906 memcpy (expP, &exp, sizeof(exp));
907 resolve_expression (expP);
908
909 if (expP->X_op != O_constant
910 || expP->X_add_number
911 || !i.types[this_operand].bitfield.baseindex)
912 {
913 i.op[this_operand].disps = expP;
914 i.disp_operands++;
915
916 i386_addressing_mode ();
917
918 if (flag_code == CODE_64BIT)
919 {
920 i.types[this_operand].bitfield.disp32 = 1;
921 if (!i.prefix[ADDR_PREFIX])
922 {
923 i.types[this_operand].bitfield.disp64 = 1;
924 i.types[this_operand].bitfield.disp32s = 1;
925 }
926 }
927 else if (!i.prefix[ADDR_PREFIX] ^ (flag_code == CODE_16BIT))
928 i.types[this_operand].bitfield.disp32 = 1;
929 else
930 i.types[this_operand].bitfield.disp16 = 1;
931
932 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
933 /*
934 * exp_seg is used only for verification in
935 * i386_finalize_displacement, and we can end up seeing reg_section
936 * here - but we know we removed all registers from the expression
937 * (or error-ed on any remaining ones) in i386_intel_simplify. I
938 * consider the check in i386_finalize_displacement bogus anyway, in
939 * particular because it doesn't allow for expr_section, so I'd
940 * rather see that check (and the similar one in
941 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
942 * expert I can't really say whether that would have other bad side
943 * effects.
944 */
945 if (OUTPUT_FLAVOR == bfd_target_aout_flavour
946 && exp_seg == reg_section)
947 exp_seg = expP->X_op != O_constant ? undefined_section
948 : absolute_section;
949 #endif
950
951 if (!i386_finalize_displacement (exp_seg, expP,
952 intel_state.reloc_types,
953 operand_string))
954 return 0;
955 }
956
957 if (intel_state.seg)
958 {
959 expP = symbol_get_value_expression (intel_state.seg);
960 if (expP->X_op != O_register)
961 {
962 as_bad (_("segment register name expected"));
963 return 0;
964 }
965 if (!i386_regtab[expP->X_add_number].reg_type.bitfield.sreg2
966 && !i386_regtab[expP->X_add_number].reg_type.bitfield.sreg3)
967 {
968 as_bad (_("invalid use of register"));
969 return 0;
970 }
971 switch (i386_regtab[expP->X_add_number].reg_num)
972 {
973 case 0: i.seg[i.mem_operands] = &es; break;
974 case 1: i.seg[i.mem_operands] = &cs; break;
975 case 2: i.seg[i.mem_operands] = &ss; break;
976 case 3: i.seg[i.mem_operands] = &ds; break;
977 case 4: i.seg[i.mem_operands] = &fs; break;
978 case 5: i.seg[i.mem_operands] = &gs; break;
979 case RegFlat: i.seg[i.mem_operands] = NULL; break;
980 }
981 }
982
983 if (!i386_index_check (operand_string))
984 return 0;
985
986 i.types[this_operand].bitfield.mem = 1;
987 if (i.mem_operands == 0)
988 i.memop1_string = xstrdup (operand_string);
989 ++i.mem_operands;
990 }
991 else
992 {
993 /* Immediate. */
994 if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
995 {
996 as_bad (_("at most %d immediate operands are allowed"),
997 MAX_IMMEDIATE_OPERANDS);
998 return 0;
999 }
1000
1001 expP = &im_expressions[i.imm_operands++];
1002 i.op[this_operand].imms = expP;
1003 *expP = exp;
1004
1005 return i386_finalize_immediate (exp_seg, expP, intel_state.reloc_types,
1006 operand_string);
1007 }
1008
1009 return 1;
1010 }
This page took 0.063916 seconds and 5 git commands to generate.