x86: remove pointless 2nd parameter from check_VecOperations()
[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-2021 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 /* 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
69
70 static struct
71 {
72 const char *name;
73 operatorT op;
74 unsigned int operands;
75 }
76 const i386_operators[] =
77 {
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 }
94 };
95
96 static struct
97 {
98 const char *name;
99 operatorT op;
100 unsigned short sz[3];
101 }
102 const i386_types[] =
103 {
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 } }
120 };
121
122 operatorT i386_operator (const char *name, unsigned int operands, char *pc)
123 {
124 unsigned int j;
125
126 #ifdef SVR4_COMMENT_CHARS
127 if (!name && operands == 2 && *input_line_pointer == '\\')
128 switch (input_line_pointer[1])
129 {
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;
133 }
134 #endif
135
136 if (!intel_syntax)
137 return O_absent;
138
139 if (!name)
140 {
141 if (operands != 2)
142 return O_illegal;
143 switch (*input_line_pointer)
144 {
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)
153 {
154 int adjust = 0;
155 char *gotfree_input_line = lex_got (&i.reloc[this_operand],
156 &adjust,
157 &intel_state.reloc_types);
158
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;
166 }
167 break;
168 }
169 return O_illegal;
170 }
171
172 for (j = 0; i386_operators[j].name; ++j)
173 if (strcasecmp (i386_operators[j].name, name) == 0)
174 {
175 if (i386_operators[j].operands
176 && i386_operators[j].operands != operands)
177 return O_illegal;
178 return i386_operators[j].op;
179 }
180
181 for (j = 0; i386_types[j].name; ++j)
182 if (strcasecmp (i386_types[j].name, name) == 0)
183 break;
184
185 if (i386_types[j].name && *pc == ' ')
186 {
187 char *pname;
188 char c;
189
190 ++input_line_pointer;
191 c = get_symbol_name (&pname);
192
193 if (strcasecmp (pname, "ptr") == 0)
194 {
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;
201 }
202
203 (void) restore_line_pointer (c);
204 input_line_pointer = pname - 1;
205 }
206
207 return O_absent;
208 }
209
210 static int i386_intel_parse_name (const char *name, expressionS *e)
211 {
212 unsigned int j;
213
214 if (! strcmp (name, "$"))
215 {
216 current_location (e);
217 return 1;
218 }
219
220 for (j = 0; i386_types[j].name; ++j)
221 if (strcasecmp(i386_types[j].name, name) == 0)
222 {
223 e->X_op = O_constant;
224 e->X_add_number = i386_types[j].sz[flag_code];
225 e->X_add_symbol = NULL;
226 e->X_op_symbol = NULL;
227 return 1;
228 }
229
230 return 0;
231 }
232
233 static INLINE int i386_intel_check (const reg_entry *rreg,
234 const reg_entry *base,
235 const reg_entry *iindex)
236 {
237 if ((this_operand >= 0
238 && rreg != i.op[this_operand].regs)
239 || base != intel_state.base
240 || iindex != intel_state.index)
241 {
242 as_bad (_("invalid use of register"));
243 return 0;
244 }
245 return 1;
246 }
247
248 static INLINE void i386_intel_fold (expressionS *e, symbolS *sym)
249 {
250 expressionS *exp = symbol_get_value_expression (sym);
251 if (S_GET_SEGMENT (sym) == absolute_section)
252 {
253 offsetT val = e->X_add_number;
254
255 *e = *exp;
256 e->X_add_number += val;
257 }
258 else
259 {
260 if (exp->X_op == O_symbol
261 && strcmp (S_GET_NAME (exp->X_add_symbol),
262 GLOBAL_OFFSET_TABLE_NAME) == 0)
263 sym = exp->X_add_symbol;
264 e->X_add_symbol = sym;
265 e->X_op_symbol = NULL;
266 e->X_op = O_symbol;
267 }
268 }
269
270 static int
271 i386_intel_simplify_register (expressionS *e)
272 {
273 int reg_num;
274
275 if (this_operand < 0 || intel_state.in_offset)
276 {
277 as_bad (_("invalid use of register"));
278 return 0;
279 }
280
281 if (e->X_op == O_register)
282 reg_num = e->X_add_number;
283 else
284 reg_num = e->X_md - 1;
285
286 if (reg_num < 0 || reg_num >= (int) i386_regtab_size)
287 {
288 as_bad (_("invalid register number"));
289 return 0;
290 }
291
292 if (!intel_state.in_bracket)
293 {
294 if (i.op[this_operand].regs)
295 {
296 as_bad (_("invalid use of register"));
297 return 0;
298 }
299 if (i386_regtab[reg_num].reg_type.bitfield.class == SReg
300 && i386_regtab[reg_num].reg_num == RegFlat)
301 {
302 as_bad (_("invalid use of pseudo-register"));
303 return 0;
304 }
305 i.op[this_operand].regs = i386_regtab + reg_num;
306 }
307 else if (!intel_state.index
308 && (i386_regtab[reg_num].reg_type.bitfield.xmmword
309 || i386_regtab[reg_num].reg_type.bitfield.ymmword
310 || i386_regtab[reg_num].reg_type.bitfield.zmmword
311 || i386_regtab[reg_num].reg_num == RegIZ))
312 intel_state.index = i386_regtab + reg_num;
313 else if (!intel_state.base && !intel_state.in_scale)
314 intel_state.base = i386_regtab + reg_num;
315 else if (!intel_state.index)
316 {
317 const insn_template *t = current_templates->start;
318
319 if (intel_state.in_scale
320 || (t->opcode_modifier.opcodeprefix == PREFIX_0XF3
321 && t->opcode_modifier.opcodespace == SPACE_0F
322 && t->base_opcode == 0x1b /* bndmk */)
323 || (t->opcode_modifier.opcodeprefix == PREFIX_NONE
324 && t->opcode_modifier.opcodespace == SPACE_0F
325 && (t->base_opcode & ~1) == 0x1a /* bnd{ld,st}x */)
326 || i386_regtab[reg_num].reg_type.bitfield.baseindex)
327 intel_state.index = i386_regtab + reg_num;
328 else
329 {
330 /* Convert base to index and make ESP/RSP the base. */
331 intel_state.index = intel_state.base;
332 intel_state.base = i386_regtab + reg_num;
333 }
334 }
335 else
336 {
337 /* esp is invalid as index */
338 intel_state.index = reg_eax + ESP_REG_NUM;
339 }
340 return 2;
341 }
342
343 static int i386_intel_simplify (expressionS *);
344
345 static INLINE int i386_intel_simplify_symbol(symbolS *sym)
346 {
347 int ret = i386_intel_simplify (symbol_get_value_expression (sym));
348
349 if (ret == 2)
350 {
351 S_SET_SEGMENT(sym, absolute_section);
352 ret = 1;
353 }
354 return ret;
355 }
356
357 static int i386_intel_simplify (expressionS *e)
358 {
359 const reg_entry *the_reg = (this_operand >= 0
360 ? i.op[this_operand].regs : NULL);
361 const reg_entry *base = intel_state.base;
362 const reg_entry *state_index = intel_state.index;
363 int ret;
364
365 if (!intel_syntax)
366 return 1;
367
368 switch (e->X_op)
369 {
370 case O_index:
371 if (e->X_add_symbol)
372 {
373 if (!i386_intel_simplify_symbol (e->X_add_symbol)
374 || !i386_intel_check(the_reg, intel_state.base,
375 intel_state.index))
376 return 0;
377 }
378 if (!intel_state.in_offset)
379 ++intel_state.in_bracket;
380 ret = i386_intel_simplify_symbol (e->X_op_symbol);
381 if (!intel_state.in_offset)
382 --intel_state.in_bracket;
383 if (!ret)
384 return 0;
385 if (e->X_add_symbol)
386 e->X_op = O_add;
387 else
388 i386_intel_fold (e, e->X_op_symbol);
389 break;
390
391 case O_offset:
392 intel_state.has_offset = 1;
393 ++intel_state.in_offset;
394 ret = i386_intel_simplify_symbol (e->X_add_symbol);
395 --intel_state.in_offset;
396 if (!ret || !i386_intel_check(the_reg, base, state_index))
397 return 0;
398 i386_intel_fold (e, e->X_add_symbol);
399 return ret;
400
401 case O_byte_ptr:
402 case O_word_ptr:
403 case O_dword_ptr:
404 case O_fword_ptr:
405 case O_qword_ptr: /* O_mmword_ptr */
406 case O_tbyte_ptr:
407 case O_oword_ptr: /* O_xmmword_ptr */
408 case O_ymmword_ptr:
409 case O_zmmword_ptr:
410 case O_near_ptr:
411 case O_far_ptr:
412 if (intel_state.op_modifier == O_absent)
413 intel_state.op_modifier = e->X_op;
414 /* FALLTHROUGH */
415 case O_short:
416 if (symbol_get_value_expression (e->X_add_symbol)->X_op
417 == O_register)
418 {
419 as_bad (_("invalid use of register"));
420 return 0;
421 }
422 if (!i386_intel_simplify_symbol (e->X_add_symbol))
423 return 0;
424 i386_intel_fold (e, e->X_add_symbol);
425 break;
426
427 case O_full_ptr:
428 if (symbol_get_value_expression (e->X_op_symbol)->X_op
429 == O_register)
430 {
431 as_bad (_("invalid use of register"));
432 return 0;
433 }
434 if (!i386_intel_simplify_symbol (e->X_op_symbol)
435 || !i386_intel_check(the_reg, intel_state.base,
436 intel_state.index))
437 return 0;
438 if (!intel_state.in_offset)
439 {
440 if (!intel_state.seg)
441 intel_state.seg = e->X_add_symbol;
442 else
443 {
444 expressionS exp;
445
446 exp.X_op = O_full_ptr;
447 exp.X_add_symbol = e->X_add_symbol;
448 exp.X_op_symbol = intel_state.seg;
449 intel_state.seg = make_expr_symbol (&exp);
450 }
451 }
452 i386_intel_fold (e, e->X_op_symbol);
453 break;
454
455 case O_multiply:
456 if (this_operand >= 0 && intel_state.in_bracket)
457 {
458 expressionS *scale = NULL;
459 int has_index = (intel_state.index != NULL);
460
461 if (!intel_state.in_scale++)
462 intel_state.scale_factor = 1;
463
464 ret = i386_intel_simplify_symbol (e->X_add_symbol);
465 if (ret && !has_index && intel_state.index)
466 scale = symbol_get_value_expression (e->X_op_symbol);
467
468 if (ret)
469 ret = i386_intel_simplify_symbol (e->X_op_symbol);
470 if (ret && !scale && !has_index && intel_state.index)
471 scale = symbol_get_value_expression (e->X_add_symbol);
472
473 if (ret && scale)
474 {
475 resolve_expression (scale);
476 if (scale->X_op != O_constant
477 || intel_state.index->reg_type.bitfield.word)
478 scale->X_add_number = 0;
479 intel_state.scale_factor *= scale->X_add_number;
480 }
481
482 --intel_state.in_scale;
483 if (!ret)
484 return 0;
485
486 if (!intel_state.in_scale)
487 switch (intel_state.scale_factor)
488 {
489 case 1:
490 i.log2_scale_factor = 0;
491 break;
492 case 2:
493 i.log2_scale_factor = 1;
494 break;
495 case 4:
496 i.log2_scale_factor = 2;
497 break;
498 case 8:
499 i.log2_scale_factor = 3;
500 break;
501 default:
502 /* esp is invalid as index */
503 intel_state.index = reg_eax + ESP_REG_NUM;
504 break;
505 }
506
507 break;
508 }
509 goto fallthrough;
510
511 case O_register:
512 ret = i386_intel_simplify_register (e);
513 if (ret == 2)
514 {
515 gas_assert (e->X_add_number < (unsigned short) -1);
516 e->X_md = (unsigned short) e->X_add_number + 1;
517 e->X_op = O_constant;
518 e->X_add_number = 0;
519 }
520 return ret;
521
522 case O_constant:
523 if (e->X_md)
524 return i386_intel_simplify_register (e);
525
526 /* FALLTHROUGH */
527 default:
528 fallthrough:
529 if (e->X_add_symbol
530 && !i386_intel_simplify_symbol (e->X_add_symbol))
531 return 0;
532 if (e->X_op == O_add || e->X_op == O_subtract)
533 {
534 base = intel_state.base;
535 state_index = intel_state.index;
536 }
537 if (!i386_intel_check (the_reg, base, state_index)
538 || (e->X_op_symbol
539 && !i386_intel_simplify_symbol (e->X_op_symbol))
540 || !i386_intel_check (the_reg,
541 (e->X_op != O_add
542 ? base : intel_state.base),
543 (e->X_op != O_add
544 ? state_index : intel_state.index)))
545 return 0;
546 break;
547 }
548
549 if (this_operand >= 0
550 && e->X_op == O_symbol
551 && !intel_state.in_offset)
552 {
553 segT seg = S_GET_SEGMENT (e->X_add_symbol);
554
555 if (seg != absolute_section
556 && seg != reg_section
557 && seg != expr_section)
558 intel_state.is_mem |= 2 - !intel_state.in_bracket;
559 }
560
561 return 1;
562 }
563
564 int i386_need_index_operator (void)
565 {
566 return intel_syntax < 0;
567 }
568
569 static int
570 i386_intel_operand (char *operand_string, int got_a_float)
571 {
572 char *saved_input_line_pointer, *buf;
573 segT exp_seg;
574 expressionS exp, *expP;
575 char suffix = 0;
576 int ret;
577
578 /* Handle vector immediates. */
579 if (RC_SAE_immediate (operand_string))
580 return 1;
581
582 /* Initialize state structure. */
583 intel_state.op_modifier = O_absent;
584 intel_state.is_mem = 0;
585 intel_state.is_indirect = 0;
586 intel_state.has_offset = 0;
587 intel_state.base = NULL;
588 intel_state.index = NULL;
589 intel_state.seg = NULL;
590 operand_type_set (&intel_state.reloc_types, ~0);
591 gas_assert (!intel_state.in_offset);
592 gas_assert (!intel_state.in_bracket);
593 gas_assert (!intel_state.in_scale);
594
595 saved_input_line_pointer = input_line_pointer;
596 input_line_pointer = buf = xstrdup (operand_string);
597
598 intel_syntax = -1;
599 memset (&exp, 0, sizeof(exp));
600 exp_seg = expression (&exp);
601 ret = i386_intel_simplify (&exp);
602 intel_syntax = 1;
603
604 SKIP_WHITESPACE ();
605
606 /* Handle vector operations. */
607 if (*input_line_pointer == '{')
608 {
609 char *end = check_VecOperations (input_line_pointer);
610 if (end)
611 input_line_pointer = end;
612 else
613 ret = 0;
614 }
615
616 if (!is_end_of_line[(unsigned char) *input_line_pointer])
617 {
618 if (ret)
619 as_bad (_("junk `%s' after expression"), input_line_pointer);
620 ret = 0;
621 }
622 else if (exp.X_op == O_illegal || exp.X_op == O_absent)
623 {
624 if (ret)
625 as_bad (_("invalid expression"));
626 ret = 0;
627 }
628 else if (!intel_state.has_offset
629 && input_line_pointer > buf
630 && *(input_line_pointer - 1) == ']')
631 {
632 intel_state.is_mem |= 1;
633 intel_state.is_indirect = 1;
634 }
635
636 input_line_pointer = saved_input_line_pointer;
637 free (buf);
638
639 gas_assert (!intel_state.in_offset);
640 gas_assert (!intel_state.in_bracket);
641 gas_assert (!intel_state.in_scale);
642
643 if (!ret)
644 return 0;
645
646 if (intel_state.op_modifier != O_absent
647 && (current_templates->start->opcode_modifier.opcodespace != SPACE_BASE
648 || current_templates->start->base_opcode != 0x8d /* lea */))
649 {
650 i.types[this_operand].bitfield.unspecified = 0;
651
652 switch (intel_state.op_modifier)
653 {
654 case O_byte_ptr:
655 i.types[this_operand].bitfield.byte = 1;
656 suffix = BYTE_MNEM_SUFFIX;
657 break;
658
659 case O_word_ptr:
660 i.types[this_operand].bitfield.word = 1;
661 if (got_a_float == 2) /* "fi..." */
662 suffix = SHORT_MNEM_SUFFIX;
663 else
664 suffix = WORD_MNEM_SUFFIX;
665 break;
666
667 case O_dword_ptr:
668 i.types[this_operand].bitfield.dword = 1;
669 if ((current_templates->start->name[0] == 'l'
670 && current_templates->start->name[2] == 's'
671 && current_templates->start->name[3] == 0)
672 || (current_templates->start->opcode_modifier.opcodespace == SPACE_BASE
673 && current_templates->start->base_opcode == 0x62 /* bound */))
674 suffix = WORD_MNEM_SUFFIX;
675 else if (flag_code != CODE_32BIT
676 && (current_templates->start->opcode_modifier.jump == JUMP
677 || current_templates->start->opcode_modifier.jump
678 == JUMP_DWORD))
679 suffix = flag_code == CODE_16BIT ? LONG_DOUBLE_MNEM_SUFFIX
680 : WORD_MNEM_SUFFIX;
681 else if (got_a_float == 1) /* "f..." */
682 suffix = SHORT_MNEM_SUFFIX;
683 else
684 suffix = LONG_MNEM_SUFFIX;
685 break;
686
687 case O_fword_ptr:
688 i.types[this_operand].bitfield.fword = 1;
689 if (current_templates->start->name[0] == 'l'
690 && current_templates->start->name[2] == 's'
691 && current_templates->start->name[3] == 0)
692 suffix = LONG_MNEM_SUFFIX;
693 else if (!got_a_float)
694 {
695 if (flag_code == CODE_16BIT)
696 add_prefix (DATA_PREFIX_OPCODE);
697 suffix = LONG_DOUBLE_MNEM_SUFFIX;
698 }
699 break;
700
701 case O_qword_ptr: /* O_mmword_ptr */
702 i.types[this_operand].bitfield.qword = 1;
703 if ((current_templates->start->opcode_modifier.opcodespace == SPACE_BASE
704 && current_templates->start->base_opcode == 0x62 /* bound */)
705 || got_a_float == 1) /* "f..." */
706 suffix = LONG_MNEM_SUFFIX;
707 else
708 suffix = QWORD_MNEM_SUFFIX;
709 break;
710
711 case O_tbyte_ptr:
712 i.types[this_operand].bitfield.tbyte = 1;
713 if (got_a_float == 1)
714 suffix = LONG_DOUBLE_MNEM_SUFFIX;
715 else if ((current_templates->start->operand_types[0].bitfield.fword
716 || current_templates->start->operand_types[0].bitfield.tbyte
717 || current_templates->start->opcode_modifier.jump == JUMP_DWORD
718 || current_templates->start->opcode_modifier.jump == JUMP)
719 && flag_code == CODE_64BIT)
720 suffix = QWORD_MNEM_SUFFIX; /* l[fgs]s, [ls][gi]dt, call, jmp */
721 else
722 i.types[this_operand].bitfield.byte = 1; /* cause an error */
723 break;
724
725 case O_oword_ptr: /* O_xmmword_ptr */
726 i.types[this_operand].bitfield.xmmword = 1;
727 break;
728
729 case O_ymmword_ptr:
730 i.types[this_operand].bitfield.ymmword = 1;
731 break;
732
733 case O_zmmword_ptr:
734 i.types[this_operand].bitfield.zmmword = 1;
735 break;
736
737 case O_far_ptr:
738 suffix = LONG_DOUBLE_MNEM_SUFFIX;
739 /* FALLTHROUGH */
740 case O_near_ptr:
741 if (current_templates->start->opcode_modifier.jump != JUMP
742 && current_templates->start->opcode_modifier.jump != JUMP_DWORD)
743 {
744 /* cause an error */
745 i.types[this_operand].bitfield.byte = 1;
746 i.types[this_operand].bitfield.tbyte = 1;
747 suffix = i.suffix;
748 }
749 break;
750
751 default:
752 BAD_CASE (intel_state.op_modifier);
753 break;
754 }
755
756 if (!i.suffix)
757 i.suffix = suffix;
758 else if (i.suffix != suffix)
759 {
760 as_bad (_("conflicting operand size modifiers"));
761 return 0;
762 }
763 }
764
765 /* Operands for jump/call need special consideration. */
766 if (current_templates->start->opcode_modifier.jump == JUMP
767 || current_templates->start->opcode_modifier.jump == JUMP_DWORD
768 || current_templates->start->opcode_modifier.jump == JUMP_INTERSEGMENT)
769 {
770 bool jumpabsolute = false;
771
772 if (i.op[this_operand].regs
773 || intel_state.base
774 || intel_state.index
775 || intel_state.is_mem > 1)
776 jumpabsolute = true;
777 else
778 switch (intel_state.op_modifier)
779 {
780 case O_near_ptr:
781 if (intel_state.seg)
782 jumpabsolute = true;
783 else
784 intel_state.is_mem = 1;
785 break;
786 case O_far_ptr:
787 case O_absent:
788 if (!intel_state.seg)
789 {
790 intel_state.is_mem = 1;
791 if (intel_state.op_modifier == O_absent)
792 {
793 if (intel_state.is_indirect == 1)
794 jumpabsolute = true;
795 break;
796 }
797 as_bad (_("cannot infer the segment part of the operand"));
798 return 0;
799 }
800 else if (S_GET_SEGMENT (intel_state.seg) == reg_section)
801 jumpabsolute = true;
802 else
803 {
804 i386_operand_type types;
805
806 if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
807 {
808 as_bad (_("at most %d immediate operands are allowed"),
809 MAX_IMMEDIATE_OPERANDS);
810 return 0;
811 }
812 expP = &im_expressions[i.imm_operands++];
813 memset (expP, 0, sizeof(*expP));
814 expP->X_op = O_symbol;
815 expP->X_add_symbol = intel_state.seg;
816 i.op[this_operand].imms = expP;
817
818 resolve_expression (expP);
819 operand_type_set (&types, ~0);
820 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state.seg),
821 expP, types, operand_string))
822 return 0;
823 if (i.operands < MAX_OPERANDS)
824 {
825 this_operand = i.operands++;
826 i.types[this_operand].bitfield.unspecified = 1;
827 }
828 if (suffix == LONG_DOUBLE_MNEM_SUFFIX)
829 i.suffix = 0;
830 intel_state.seg = NULL;
831 intel_state.is_mem = 0;
832 }
833 break;
834 default:
835 jumpabsolute = true;
836 break;
837 }
838 if (jumpabsolute)
839 {
840 i.jumpabsolute = true;
841 intel_state.is_mem |= 1;
842 }
843 }
844 else if (intel_state.seg)
845 intel_state.is_mem |= 1;
846
847 if (i.op[this_operand].regs)
848 {
849 i386_operand_type temp;
850
851 /* Register operand. */
852 if (intel_state.base || intel_state.index || intel_state.seg)
853 {
854 as_bad (_("invalid operand"));
855 return 0;
856 }
857
858 temp = i.op[this_operand].regs->reg_type;
859 temp.bitfield.baseindex = 0;
860 i.types[this_operand] = operand_type_or (i.types[this_operand],
861 temp);
862 i.types[this_operand].bitfield.unspecified = 0;
863 ++i.reg_operands;
864 }
865 else if (intel_state.base
866 || intel_state.index
867 || intel_state.seg
868 || intel_state.is_mem)
869 {
870 /* Memory operand. */
871 if (i.mem_operands == 1 && !maybe_adjust_templates ())
872 return 0;
873 if ((int) i.mem_operands
874 >= 2 - !current_templates->start->opcode_modifier.isstring)
875 {
876 /* Handle
877
878 call 0x9090,0x90909090
879 lcall 0x9090,0x90909090
880 jmp 0x9090,0x90909090
881 ljmp 0x9090,0x90909090
882 */
883
884 if ((current_templates->start->opcode_modifier.jump == JUMP_INTERSEGMENT
885 || current_templates->start->opcode_modifier.jump == JUMP_DWORD
886 || current_templates->start->opcode_modifier.jump == JUMP)
887 && this_operand == 1
888 && intel_state.seg == NULL
889 && i.mem_operands == 1
890 && i.disp_operands == 1
891 && intel_state.op_modifier == O_absent)
892 {
893 /* Try to process the first operand as immediate, */
894 this_operand = 0;
895 if (i386_finalize_immediate (exp_seg, i.op[0].imms,
896 intel_state.reloc_types,
897 NULL))
898 {
899 this_operand = 1;
900 expP = &im_expressions[0];
901 i.op[this_operand].imms = expP;
902 *expP = exp;
903
904 /* Try to process the second operand as immediate, */
905 if (i386_finalize_immediate (exp_seg, expP,
906 intel_state.reloc_types,
907 NULL))
908 {
909 i.mem_operands = 0;
910 i.disp_operands = 0;
911 i.imm_operands = 2;
912 i.flags[0] &= ~Operand_Mem;
913 i.types[0].bitfield.disp16 = 0;
914 i.types[0].bitfield.disp32 = 0;
915 i.types[0].bitfield.disp32s = 0;
916 return 1;
917 }
918 }
919 }
920
921 as_bad (_("too many memory references for `%s'"),
922 current_templates->start->name);
923 return 0;
924 }
925
926 /* Swap base and index in 16-bit memory operands like
927 [si+bx]. Since i386_index_check is also used in AT&T
928 mode we have to do this here. */
929 if (intel_state.base
930 && intel_state.index
931 && intel_state.base->reg_type.bitfield.word
932 && intel_state.index->reg_type.bitfield.word
933 && intel_state.base->reg_num >= 6
934 && intel_state.index->reg_num < 6)
935 {
936 i.base_reg = intel_state.index;
937 i.index_reg = intel_state.base;
938 }
939 else
940 {
941 i.base_reg = intel_state.base;
942 i.index_reg = intel_state.index;
943 }
944
945 if (i.base_reg || i.index_reg)
946 i.types[this_operand].bitfield.baseindex = 1;
947
948 expP = &disp_expressions[i.disp_operands];
949 memcpy (expP, &exp, sizeof(exp));
950 resolve_expression (expP);
951
952 if (expP->X_op != O_constant
953 || expP->X_add_number
954 || !i.types[this_operand].bitfield.baseindex)
955 {
956 i.op[this_operand].disps = expP;
957 i.disp_operands++;
958
959 i386_addressing_mode ();
960
961 if (flag_code == CODE_64BIT)
962 {
963 if (!i.prefix[ADDR_PREFIX])
964 {
965 i.types[this_operand].bitfield.disp64 = 1;
966 i.types[this_operand].bitfield.disp32s = 1;
967 }
968 else
969 i.types[this_operand].bitfield.disp32 = 1;
970 }
971 else if (!i.prefix[ADDR_PREFIX] ^ (flag_code == CODE_16BIT))
972 i.types[this_operand].bitfield.disp32 = 1;
973 else
974 i.types[this_operand].bitfield.disp16 = 1;
975
976 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
977 /*
978 * exp_seg is used only for verification in
979 * i386_finalize_displacement, and we can end up seeing reg_section
980 * here - but we know we removed all registers from the expression
981 * (or error-ed on any remaining ones) in i386_intel_simplify. I
982 * consider the check in i386_finalize_displacement bogus anyway, in
983 * particular because it doesn't allow for expr_section, so I'd
984 * rather see that check (and the similar one in
985 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
986 * expert I can't really say whether that would have other bad side
987 * effects.
988 */
989 if (OUTPUT_FLAVOR == bfd_target_aout_flavour
990 && exp_seg == reg_section)
991 exp_seg = expP->X_op != O_constant ? undefined_section
992 : absolute_section;
993 #endif
994
995 if (!i386_finalize_displacement (exp_seg, expP,
996 intel_state.reloc_types,
997 operand_string))
998 return 0;
999 }
1000
1001 if (intel_state.seg)
1002 {
1003 for (ret = check_none; ; ret = operand_check)
1004 {
1005 expP = symbol_get_value_expression (intel_state.seg);
1006 if (expP->X_op != O_full_ptr
1007 || symbol_get_value_expression (expP->X_op_symbol)->X_op
1008 != O_register)
1009 break;
1010 intel_state.seg = expP->X_add_symbol;
1011 }
1012 if (expP->X_op != O_register)
1013 {
1014 as_bad (_("segment register name expected"));
1015 return 0;
1016 }
1017 if (i386_regtab[expP->X_add_number].reg_type.bitfield.class != SReg)
1018 {
1019 as_bad (_("invalid use of register"));
1020 return 0;
1021 }
1022 switch (ret)
1023 {
1024 case check_error:
1025 as_bad (_("redundant segment overrides"));
1026 return 0;
1027 case check_warning:
1028 as_warn (_("redundant segment overrides"));
1029 break;
1030 }
1031 if (i386_regtab[expP->X_add_number].reg_num == RegFlat)
1032 i.seg[i.mem_operands] = NULL;
1033 else
1034 i.seg[i.mem_operands] = &i386_regtab[expP->X_add_number];
1035 }
1036
1037 if (!i386_index_check (operand_string))
1038 return 0;
1039
1040 i.flags[this_operand] |= Operand_Mem;
1041 if (i.mem_operands == 0)
1042 i.memop1_string = xstrdup (operand_string);
1043 ++i.mem_operands;
1044 }
1045 else
1046 {
1047 /* Immediate. */
1048 if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
1049 {
1050 as_bad (_("at most %d immediate operands are allowed"),
1051 MAX_IMMEDIATE_OPERANDS);
1052 return 0;
1053 }
1054
1055 expP = &im_expressions[i.imm_operands++];
1056 i.op[this_operand].imms = expP;
1057 *expP = exp;
1058
1059 return i386_finalize_immediate (exp_seg, expP, intel_state.reloc_types,
1060 operand_string);
1061 }
1062
1063 return 1;
1064 }
This page took 0.103869 seconds and 4 git commands to generate.