gas/
[deliverable/binutils-gdb.git] / gas / config / tc-i386-intel.c
1 /* tc-i386.c -- Assemble Intel syntax code for ix86/x86-64
2 Copyright 2009
3 Free Software Foundation, Inc.
4
5 This file is part of GAS, the GNU Assembler.
6
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20 02110-1301, USA. */
21
22 static struct
23 {
24 operatorT op_modifier; /* Operand modifier. */
25 int is_mem; /* 1 if operand is memory reference. */
26 unsigned int in_offset; /* >=1 if processing operand of offset. */
27 unsigned int in_bracket; /* >=1 if processing operand in brackets. */
28 unsigned int in_scale; /* >=1 if processing multipication operand
29 * in brackets. */
30 i386_operand_type reloc_types; /* Value obtained from lex_got(). */
31 const reg_entry *base; /* Base register (if any). */
32 const reg_entry *index; /* Index register (if any). */
33 offsetT scale_factor; /* Accumulated scale factor. */
34 symbolS *seg;
35 }
36 intel_state;
37
38 /* offset X_add_symbol */
39 #define O_offset O_md32
40 /* byte ptr X_add_symbol */
41 #define O_byte_ptr O_md31
42 /* word ptr X_add_symbol */
43 #define O_word_ptr O_md30
44 /* dword ptr X_add_symbol */
45 #define O_dword_ptr O_md29
46 /* qword ptr X_add_symbol */
47 #define O_qword_ptr O_md28
48 /* oword ptr X_add_symbol */
49 #define O_oword_ptr O_md27
50 /* fword ptr X_add_symbol */
51 #define O_fword_ptr O_md26
52 /* tbyte ptr X_add_symbol */
53 #define O_tbyte_ptr O_md25
54 /* xmmword ptr X_add_symbol */
55 #define O_xmmword_ptr O_md24
56 /* ymmword ptr X_add_symbol */
57 #define O_ymmword_ptr O_md23
58 /* near ptr X_add_symbol */
59 #define O_near_ptr O_md22
60 /* far ptr X_add_symbol */
61 #define O_far_ptr O_md21
62 /* offset X_add_symbol */
63 #define O_short O_md20
64
65 static struct
66 {
67 const char *name;
68 operatorT operator;
69 unsigned int operands;
70 }
71 const i386_operators[] =
72 {
73 { "and", O_bit_and, 2 },
74 { "eq", O_eq, 2 },
75 { "ge", O_ge, 2 },
76 { "gt", O_gt, 2 },
77 { "le", O_le, 2 },
78 { "lt", O_lt, 2 },
79 { "mod", O_modulus, 2 },
80 { "ne", O_ne, 2 },
81 { "not", O_bit_not, 1 },
82 { "offset", O_offset, 1 },
83 { "or", O_bit_inclusive_or, 2 },
84 { "shl", O_left_shift, 2 },
85 { "short", O_short, 1 },
86 { "shr", O_right_shift, 2 },
87 { "xor", O_bit_exclusive_or, 2 },
88 { NULL, O_illegal, 0 }
89 };
90
91 static struct
92 {
93 const char *name;
94 operatorT operator;
95 unsigned short sz[3];
96 }
97 const i386_types[] =
98 {
99 #define I386_TYPE(t, n) { #t, O_##t##_ptr, { n, n, n } }
100 I386_TYPE(byte, 1),
101 I386_TYPE(word, 2),
102 I386_TYPE(dword, 4),
103 I386_TYPE(fword, 6),
104 I386_TYPE(qword, 8),
105 I386_TYPE(tbyte, 10),
106 I386_TYPE(oword, 16),
107 I386_TYPE(xmmword, 16),
108 I386_TYPE(ymmword, 32),
109 #undef I386_TYPE
110 { "near", O_near_ptr, { 0xff04, 0xff02, 0xff08 } },
111 { "far", O_far_ptr, { 0xff06, 0xff05, 0xff06 } },
112 { NULL, O_illegal, { 0, 0, 0 } }
113 };
114
115 operatorT i386_operator (const char *name, unsigned int operands, char *pc)
116 {
117 unsigned int j;
118
119 if (!intel_syntax)
120 return O_absent;
121
122 if (!name)
123 {
124 if (operands != 2)
125 return O_illegal;
126 switch (*input_line_pointer)
127 {
128 case ':':
129 ++input_line_pointer;
130 return O_full_ptr;
131 case '[':
132 ++input_line_pointer;
133 return O_index;
134 case '@':
135 if (this_operand >= 0 && i.reloc[this_operand] == NO_RELOC)
136 {
137 int adjust = 0;
138 char *gotfree_input_line = lex_got (&i.reloc[this_operand],
139 &adjust,
140 &intel_state.reloc_types);
141
142 if (!gotfree_input_line)
143 break;
144 free (gotfree_input_line);
145 *input_line_pointer++ = '+';
146 memset (input_line_pointer, '0', adjust - 1);
147 input_line_pointer[adjust - 1] = ' ';
148 return O_add;
149 }
150 break;
151 }
152 return O_illegal;
153 }
154
155 for (j = 0; i386_operators[j].name; ++j)
156 if (strcasecmp(i386_operators[j].name, name) == 0)
157 {
158 if (i386_operators[j].operands
159 && i386_operators[j].operands != operands)
160 return O_illegal;
161 return i386_operators[j].operator;
162 }
163
164 for (j = 0; i386_types[j].name; ++j)
165 if (strcasecmp(i386_types[j].name, name) == 0)
166 break;
167 if (i386_types[j].name && *pc == ' ')
168 {
169 char *name = ++input_line_pointer;
170 char c = get_symbol_end ();
171
172 if (strcasecmp (name, "ptr") == 0)
173 {
174 name[-1] = *pc;
175 *pc = c;
176 if (intel_syntax > 0 || operands != 1)
177 return O_illegal;
178 return i386_types[j].operator;
179 }
180
181 *input_line_pointer = c;
182 input_line_pointer = name - 1;
183 }
184
185 return O_absent;
186 }
187
188 static int i386_intel_parse_name (const char *name, expressionS *e)
189 {
190 unsigned int i;
191
192 for (i = 0; i386_types[i].name; ++i)
193 if (strcasecmp(i386_types[i].name, name) == 0)
194 {
195 e->X_op = O_constant;
196 e->X_add_number = i386_types[i].sz[flag_code];
197 e->X_add_symbol = NULL;
198 e->X_op_symbol = NULL;
199 return 1;
200 }
201
202 return 0;
203 }
204
205 static INLINE int i386_intel_check (const reg_entry *reg,
206 const reg_entry *base,
207 const reg_entry *index)
208 {
209 if ((this_operand >= 0 && reg != i.op[this_operand].regs)
210 || base != intel_state.base || index != intel_state.index)
211 {
212 as_bad (_("invalid use of register"));
213 return 0;
214 }
215 return 1;
216 }
217
218 static INLINE void i386_intel_fold (expressionS *e, symbolS *sym)
219 {
220 if (S_GET_SEGMENT (sym) == absolute_section)
221 {
222 offsetT val = e->X_add_number;
223
224 *e = *symbol_get_value_expression (sym);
225 e->X_add_number += val;
226 }
227 else
228 {
229 e->X_add_symbol = sym;
230 e->X_op_symbol = NULL;
231 e->X_op = O_symbol;
232 }
233 }
234
235 static int i386_intel_simplify (expressionS *);
236
237 static INLINE int i386_intel_simplify_symbol(symbolS *sym)
238 {
239 int ret = i386_intel_simplify (symbol_get_value_expression (sym));
240
241 if (ret == 2)
242 {
243 S_SET_SEGMENT(sym, absolute_section);
244 ret = 1;
245 }
246 return ret;
247 }
248
249 static int i386_intel_simplify (expressionS *e)
250 {
251 const reg_entry *reg = this_operand >= 0 ? i.op[this_operand].regs : NULL;
252 const reg_entry *base = intel_state.base;
253 const reg_entry *index = intel_state.index;
254 int ret;
255
256 if (!intel_syntax)
257 return 1;
258
259 switch (e->X_op)
260 {
261 case O_index:
262 if (e->X_add_symbol)
263 {
264 if (!i386_intel_simplify_symbol (e->X_add_symbol)
265 || !i386_intel_check(reg, intel_state.base, intel_state.index))
266 return 0;;
267 }
268 if (!intel_state.in_offset)
269 ++intel_state.in_bracket;
270 ret = i386_intel_simplify_symbol (e->X_op_symbol);
271 if (!intel_state.in_offset)
272 --intel_state.in_bracket;
273 if (!ret)
274 return 0;
275 if (e->X_add_symbol)
276 e->X_op = O_add;
277 else
278 i386_intel_fold (e, e->X_op_symbol);
279 break;
280
281 case O_offset:
282 ++intel_state.in_offset;
283 ret = i386_intel_simplify_symbol (e->X_add_symbol);
284 --intel_state.in_offset;
285 if (!ret || !i386_intel_check(reg, base, index))
286 return 0;
287 i386_intel_fold (e, e->X_add_symbol);
288 return ret;
289
290 case O_byte_ptr:
291 case O_word_ptr:
292 case O_dword_ptr:
293 case O_fword_ptr:
294 case O_qword_ptr:
295 case O_tbyte_ptr:
296 case O_oword_ptr:
297 case O_xmmword_ptr:
298 case O_ymmword_ptr:
299 case O_near_ptr:
300 case O_far_ptr:
301 if (intel_state.op_modifier == O_absent)
302 intel_state.op_modifier = e->X_op;
303 /* FALLTHROUGH */
304 case O_short:
305 if (symbol_get_value_expression (e->X_add_symbol)->X_op == O_register)
306 {
307 as_bad (_("invalid use of register"));
308 return 0;
309 }
310 if (!i386_intel_simplify_symbol (e->X_add_symbol))
311 return 0;
312 i386_intel_fold (e, e->X_add_symbol);
313 break;
314
315 case O_full_ptr:
316 if (symbol_get_value_expression (e->X_op_symbol)->X_op == O_register)
317 {
318 as_bad (_("invalid use of register"));
319 return 0;
320 }
321 if (!i386_intel_simplify_symbol (e->X_op_symbol)
322 || !i386_intel_check(reg, intel_state.base, intel_state.index))
323 return 0;
324 if (!intel_state.in_offset)
325 intel_state.seg = e->X_add_symbol;
326 i386_intel_fold (e, e->X_op_symbol);
327 break;
328
329 case O_register:
330 if (this_operand < 0 || intel_state.in_offset)
331 {
332 as_bad (_("invalid use of register"));
333 return 0;
334 }
335 if (!intel_state.in_bracket)
336 {
337 if (i.op[this_operand].regs)
338 {
339 as_bad (_("invalid use of register"));
340 return 0;
341 }
342 if (i386_regtab[e->X_add_number].reg_type.bitfield.sreg3
343 && i386_regtab[e->X_add_number].reg_num == RegFlat)
344 {
345 as_bad (_("invalid use of pseudo-register"));
346 return 0;
347 }
348 i.op[this_operand].regs = i386_regtab + e->X_add_number;
349 }
350 else if (!intel_state.base && !intel_state.in_scale)
351 intel_state.base = i386_regtab + e->X_add_number;
352 else if (!intel_state.index)
353 intel_state.index = i386_regtab + e->X_add_number;
354 else
355 {
356 /* esp is invalid as index */
357 intel_state.index = i386_regtab + REGNAM_EAX + 4;
358 }
359 e->X_op = O_constant;
360 e->X_add_number = 0;
361 return 2;
362
363 case O_multiply:
364 if (this_operand >= 0 && intel_state.in_bracket)
365 {
366 expressionS *scale = NULL;
367
368 if (intel_state.index)
369 --scale;
370
371 if (!intel_state.in_scale++)
372 intel_state.scale_factor = 1;
373
374 ret = i386_intel_simplify_symbol (e->X_add_symbol);
375 if (ret && !scale && intel_state.index)
376 scale = symbol_get_value_expression (e->X_op_symbol);
377
378 if (ret)
379 ret = i386_intel_simplify_symbol (e->X_op_symbol);
380 if (ret && !scale && intel_state.index)
381 scale = symbol_get_value_expression (e->X_add_symbol);
382
383 if (ret && scale && (scale + 1))
384 {
385 resolve_expression (scale);
386 if (scale->X_op != O_constant
387 || intel_state.index->reg_type.bitfield.reg16)
388 scale->X_add_number = 0;
389 intel_state.scale_factor *= scale->X_add_number;
390 }
391
392 --intel_state.in_scale;
393 if (!ret)
394 return 0;
395
396 if (!intel_state.in_scale)
397 switch (intel_state.scale_factor)
398 {
399 case 1:
400 i.log2_scale_factor = 0;
401 break;
402 case 2:
403 i.log2_scale_factor = 1;
404 break;
405 case 4:
406 i.log2_scale_factor = 2;
407 break;
408 case 8:
409 i.log2_scale_factor = 3;
410 break;
411 default:
412 /* esp is invalid as index */
413 intel_state.index = i386_regtab + REGNAM_EAX + 4;
414 break;
415 }
416
417 break;
418 }
419 /* FALLTHROUGH */
420 default:
421 if (e->X_add_symbol && !i386_intel_simplify_symbol (e->X_add_symbol))
422 return 0;
423 if (e->X_op == O_add || e->X_op == O_subtract)
424 {
425 base = intel_state.base;
426 index = intel_state.index;
427 }
428 if (!i386_intel_check (reg, base, index)
429 || (e->X_op_symbol && !i386_intel_simplify_symbol (e->X_op_symbol))
430 || !i386_intel_check (reg,
431 e->X_op != O_add ? base : intel_state.base,
432 e->X_op != O_add ? index : intel_state.index))
433 return 0;
434 break;
435 }
436
437 if (this_operand >= 0 && e->X_op == O_symbol && !intel_state.in_offset)
438 {
439 segT seg = S_GET_SEGMENT (e->X_add_symbol);
440
441 if (seg != absolute_section
442 && seg != reg_section
443 && seg != expr_section)
444 intel_state.is_mem |= 2 - !intel_state.in_bracket;
445 }
446
447 return 1;
448 }
449
450 int i386_need_index_operator (void)
451 {
452 return intel_syntax < 0;
453 }
454
455 static int
456 i386_intel_operand (char *operand_string, int got_a_float)
457 {
458 char *saved_input_line_pointer, *buf;
459 segT exp_seg;
460 expressionS exp, *expP;
461 char suffix = 0;
462 int ret;
463
464 /* Initialize state structure. */
465 intel_state.op_modifier = O_absent;
466 intel_state.is_mem = 0;
467 intel_state.base = NULL;
468 intel_state.index = NULL;
469 intel_state.seg = NULL;
470 operand_type_set (&intel_state.reloc_types, ~0);
471 assert (!intel_state.in_offset);
472 assert (!intel_state.in_bracket);
473 assert (!intel_state.in_scale);
474
475 saved_input_line_pointer = input_line_pointer;
476 input_line_pointer = buf = xstrdup (operand_string);
477
478 intel_syntax = -1;
479 memset (&exp, 0, sizeof(exp));
480 exp_seg = expression (&exp);
481 ret = i386_intel_simplify (&exp);
482 intel_syntax = 1;
483
484 SKIP_WHITESPACE ();
485 if (!is_end_of_line[(unsigned char) *input_line_pointer])
486 {
487 as_bad (_("junk `%s' after expression"), input_line_pointer);
488 ret = 0;
489 }
490 else if (exp.X_op == O_illegal || exp.X_op == O_absent)
491 {
492 as_bad (_("invalid expression"));
493 ret = 0;
494 }
495
496 input_line_pointer = saved_input_line_pointer;
497 free (buf);
498
499 assert (!intel_state.in_offset);
500 assert (!intel_state.in_bracket);
501 assert (!intel_state.in_scale);
502
503 if (!ret)
504 return 0;
505
506 if (intel_state.op_modifier != O_absent
507 && current_templates->start->base_opcode != 0x8d /* lea */)
508 {
509 i.types[this_operand].bitfield.unspecified = 0;
510
511 switch (intel_state.op_modifier)
512 {
513 case O_byte_ptr:
514 i.types[this_operand].bitfield.byte = 1;
515 suffix = BYTE_MNEM_SUFFIX;
516 break;
517
518 case O_word_ptr:
519 i.types[this_operand].bitfield.word = 1;
520 if ((current_templates->start->name[0] == 'l'
521 && current_templates->start->name[2] == 's'
522 && current_templates->start->name[3] == 0)
523 || current_templates->start->base_opcode == 0x62 /* bound */)
524 suffix = BYTE_MNEM_SUFFIX; /* so it will cause an error */
525 else if (got_a_float == 2) /* "fi..." */
526 suffix = SHORT_MNEM_SUFFIX;
527 else
528 suffix = WORD_MNEM_SUFFIX;
529 break;
530
531 case O_dword_ptr:
532 i.types[this_operand].bitfield.dword = 1;
533 if ((current_templates->start->name[0] == 'l'
534 && current_templates->start->name[2] == 's'
535 && current_templates->start->name[3] == 0)
536 || current_templates->start->base_opcode == 0x62 /* bound */)
537 suffix = WORD_MNEM_SUFFIX;
538 else if (flag_code == CODE_16BIT
539 && (current_templates->start->opcode_modifier.jump
540 || current_templates->start->opcode_modifier.jumpdword))
541 suffix = LONG_DOUBLE_MNEM_SUFFIX;
542 else if (got_a_float == 1) /* "f..." */
543 suffix = SHORT_MNEM_SUFFIX;
544 else
545 suffix = LONG_MNEM_SUFFIX;
546 break;
547
548 case O_fword_ptr:
549 i.types[this_operand].bitfield.fword = 1;
550 if (current_templates->start->name[0] == 'l'
551 && current_templates->start->name[2] == 's'
552 && current_templates->start->name[3] == 0)
553 suffix = LONG_MNEM_SUFFIX;
554 else if (!got_a_float)
555 {
556 if (flag_code == CODE_16BIT)
557 add_prefix (DATA_PREFIX_OPCODE);
558 suffix = LONG_DOUBLE_MNEM_SUFFIX;
559 }
560 else
561 suffix = BYTE_MNEM_SUFFIX; /* so it will cause an error */
562 break;
563
564 case O_qword_ptr:
565 i.types[this_operand].bitfield.qword = 1;
566 if (current_templates->start->base_opcode == 0x62 /* bound */
567 || got_a_float == 1) /* "f..." */
568 suffix = LONG_MNEM_SUFFIX;
569 else
570 suffix = QWORD_MNEM_SUFFIX;
571 break;
572
573 case O_tbyte_ptr:
574 i.types[this_operand].bitfield.tbyte = 1;
575 if (got_a_float == 1)
576 suffix = LONG_DOUBLE_MNEM_SUFFIX;
577 else
578 suffix = BYTE_MNEM_SUFFIX; /* so it will cause an error */
579 break;
580
581 case O_oword_ptr:
582 case O_xmmword_ptr:
583 i.types[this_operand].bitfield.xmmword = 1;
584 suffix = XMMWORD_MNEM_SUFFIX;
585 break;
586
587 case O_ymmword_ptr:
588 i.types[this_operand].bitfield.ymmword = 1;
589 suffix = YMMWORD_MNEM_SUFFIX;
590 break;
591
592 case O_far_ptr:
593 suffix = LONG_DOUBLE_MNEM_SUFFIX;
594 /* FALLTHROUGH */
595 case O_near_ptr:
596 if (!current_templates->start->opcode_modifier.jump
597 && !current_templates->start->opcode_modifier.jumpdword)
598 suffix = got_a_float /* so it will cause an error */
599 ? BYTE_MNEM_SUFFIX
600 : LONG_DOUBLE_MNEM_SUFFIX;
601 break;
602
603 default:
604 BAD_CASE (intel_state.op_modifier);
605 break;
606 }
607
608 if (!i.suffix)
609 i.suffix = suffix;
610 else if (i.suffix != suffix)
611 {
612 as_bad (_("conflicting operand size modifiers"));
613 return 0;
614 }
615 }
616
617 /* Operands for jump/call need special consideration. */
618 if (current_templates->start->opcode_modifier.jump
619 || current_templates->start->opcode_modifier.jumpdword
620 || current_templates->start->opcode_modifier.jumpintersegment)
621 {
622 if (i.op[this_operand].regs || intel_state.base || intel_state.index
623 || intel_state.is_mem > 1)
624 i.types[this_operand].bitfield.jumpabsolute = 1;
625 else
626 switch (intel_state.op_modifier)
627 {
628 case O_near_ptr:
629 if (intel_state.seg)
630 i.types[this_operand].bitfield.jumpabsolute = 1;
631 else
632 intel_state.is_mem = 1;
633 break;
634 case O_far_ptr:
635 case O_absent:
636 if (!intel_state.seg)
637 {
638 intel_state.is_mem = 1;
639 if (intel_state.op_modifier == O_absent)
640 break;
641 as_bad (_("cannot infer the segment part of the operand"));
642 return 0;
643 }
644 else if (S_GET_SEGMENT (intel_state.seg) == reg_section)
645 i.types[this_operand].bitfield.jumpabsolute = 1;
646 else
647 {
648 i386_operand_type types;
649
650 if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
651 {
652 as_bad (_("at most %d immediate operands are allowed"),
653 MAX_IMMEDIATE_OPERANDS);
654 return 0;
655 }
656 expP = &im_expressions[i.imm_operands++];
657 memset (expP, 0, sizeof(*expP));
658 expP->X_op = O_symbol;
659 expP->X_add_symbol = intel_state.seg;
660 i.op[this_operand].imms = expP;
661
662 resolve_expression (expP);
663 operand_type_set (&types, ~0);
664 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state.seg),
665 expP, types, operand_string))
666 return 0;
667 if (i.operands < MAX_OPERANDS)
668 {
669 this_operand = i.operands++;
670 i.types[this_operand].bitfield.unspecified = 1;
671 }
672 if (suffix == LONG_DOUBLE_MNEM_SUFFIX)
673 i.suffix = 0;
674 intel_state.seg = NULL;
675 intel_state.is_mem = 0;
676 }
677 break;
678 default:
679 i.types[this_operand].bitfield.jumpabsolute = 1;
680 break;
681 }
682 if (i.types[this_operand].bitfield.jumpabsolute)
683 intel_state.is_mem |= 1;
684 }
685 else if (intel_state.seg)
686 intel_state.is_mem |= 1;
687
688 if (i.op[this_operand].regs)
689 {
690 i386_operand_type temp;
691
692 /* Register operand. */
693 if (intel_state.base || intel_state.index || intel_state.seg)
694 {
695 as_bad (_("invalid operand"));
696 return 0;
697 }
698
699 temp = i.op[this_operand].regs->reg_type;
700 temp.bitfield.baseindex = 0;
701 i.types[this_operand] = operand_type_or (i.types[this_operand], temp);
702 i.types[this_operand].bitfield.unspecified = 0;
703 ++i.reg_operands;
704 }
705 else if (intel_state.base || intel_state.index || intel_state.seg
706 || intel_state.is_mem)
707 {
708 /* Memory operand. */
709 if (i.mem_operands
710 >= 2 - !current_templates->start->opcode_modifier.isstring)
711 {
712 as_bad (_("too many memory references for `%s'"),
713 current_templates->start->name);
714 return 0;
715 }
716
717 expP = &disp_expressions[i.disp_operands];
718 memcpy (expP, &exp, sizeof(exp));
719 resolve_expression (expP);
720
721 if (expP->X_op != O_constant || expP->X_add_number
722 || (!intel_state.base && !intel_state.index))
723 {
724 i.op[this_operand].disps = expP;
725 i.disp_operands++;
726
727 if (flag_code == CODE_64BIT)
728 {
729 i.types[this_operand].bitfield.disp32 = 1;
730 if (!i.prefix[ADDR_PREFIX])
731 {
732 i.types[this_operand].bitfield.disp64 = 1;
733 i.types[this_operand].bitfield.disp32s = 1;
734 }
735 }
736 else if (!i.prefix[ADDR_PREFIX] ^ (flag_code == CODE_16BIT))
737 i.types[this_operand].bitfield.disp32 = 1;
738 else
739 i.types[this_operand].bitfield.disp16 = 1;
740
741 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
742 /*
743 * exp_seg is used only for verification in
744 * i386_finalize_displacement, and we can end up seeing reg_section
745 * here - but we know we removed all registers from the expression
746 * (or error-ed on any remaining ones) in i386_intel_simplify. I
747 * consider the check in i386_finalize_displacement bogus anyway, in
748 * particular because it doesn't allow for expr_section, so I'd
749 * rather see that check (and the similar one in
750 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
751 * expert I can't really say whether that would have other bad side
752 * effects.
753 */
754 if (OUTPUT_FLAVOR == bfd_target_aout_flavour
755 && exp_seg == reg_section)
756 exp_seg = expP->X_op != O_constant ? undefined_section
757 : absolute_section;
758 #endif
759
760 if (!i386_finalize_displacement (exp_seg, expP,
761 intel_state.reloc_types,
762 operand_string))
763 return 0;
764 }
765
766 if (intel_state.base || intel_state.index)
767 i.types[this_operand].bitfield.baseindex = 1;
768
769 if (intel_state.seg)
770 {
771 for (;;)
772 {
773 expP = symbol_get_value_expression (intel_state.seg);
774 if (expP->X_op != O_full_ptr)
775 break;
776 intel_state.seg = expP->X_add_symbol;
777 }
778 if (expP->X_op != O_register)
779 {
780 as_bad (_("segment register name expected"));
781 return 0;
782 }
783 if (!i386_regtab[expP->X_add_number].reg_type.bitfield.sreg2
784 && !i386_regtab[expP->X_add_number].reg_type.bitfield.sreg3)
785 {
786 as_bad (_("invalid use of register"));
787 return 0;
788 }
789 switch (i386_regtab[expP->X_add_number].reg_num)
790 {
791 case 0: i.seg[i.mem_operands] = &es; break;
792 case 1: i.seg[i.mem_operands] = &cs; break;
793 case 2: i.seg[i.mem_operands] = &ss; break;
794 case 3: i.seg[i.mem_operands] = &ds; break;
795 case 4: i.seg[i.mem_operands] = &fs; break;
796 case 5: i.seg[i.mem_operands] = &gs; break;
797 case RegFlat: i.seg[i.mem_operands] = NULL; break;
798 }
799 }
800
801 /* Swap base and index in 16-bit memory operands like
802 [si+bx]. Since i386_index_check is also used in AT&T
803 mode we have to do that here. */
804 if (intel_state.base
805 && intel_state.index
806 && intel_state.base->reg_type.bitfield.reg16
807 && intel_state.index->reg_type.bitfield.reg16
808 && intel_state.base->reg_num >= 6
809 && intel_state.index->reg_num < 6)
810 {
811 i.base_reg = intel_state.index;
812 i.index_reg = intel_state.base;
813 }
814 else
815 {
816 i.base_reg = intel_state.base;
817 i.index_reg = intel_state.index;
818 }
819
820 if (!i386_index_check (operand_string))
821 return 0;
822
823 i.types[this_operand].bitfield.mem = 1;
824 ++i.mem_operands;
825 }
826 else
827 {
828 /* Immediate. */
829 if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
830 {
831 as_bad (_("at most %d immediate operands are allowed"),
832 MAX_IMMEDIATE_OPERANDS);
833 return 0;
834 }
835
836 expP = &im_expressions[i.imm_operands++];
837 i.op[this_operand].imms = expP;
838 *expP = exp;
839
840 return i386_finalize_immediate (exp_seg, expP, intel_state.reloc_types,
841 operand_string);
842 }
843
844 return 1;
845 }
This page took 0.049992 seconds and 5 git commands to generate.