* po/bfd.pot: Updated by the Translation project.
[binutils.git] / gas / config / tc-i386-intel.c
blobff20874b3f541c48e8c027717f12bd4237292515
1 /* tc-i386.c -- Assemble Intel syntax code for ix86/x86-64
2 Copyright 2009
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
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.
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.
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. */
22 static struct
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;
36 intel_state;
38 /* offset X_add_symbol */
39 #define O_offset O_md32
40 /* offset X_add_symbol */
41 #define O_short O_md31
42 /* near ptr X_add_symbol */
43 #define O_near_ptr O_md30
44 /* far ptr X_add_symbol */
45 #define O_far_ptr O_md29
46 /* byte ptr X_add_symbol */
47 #define O_byte_ptr O_md28
48 /* word ptr X_add_symbol */
49 #define O_word_ptr O_md27
50 /* dword ptr X_add_symbol */
51 #define O_dword_ptr O_md26
52 /* qword ptr X_add_symbol */
53 #define O_qword_ptr O_md25
54 /* oword ptr X_add_symbol */
55 #define O_oword_ptr O_md24
56 /* fword ptr X_add_symbol */
57 #define O_fword_ptr O_md23
58 /* tbyte ptr X_add_symbol */
59 #define O_tbyte_ptr O_md22
60 /* xmmword ptr X_add_symbol */
61 #define O_xmmword_ptr O_md21
62 /* ymmword ptr X_add_symbol */
63 #define O_ymmword_ptr O_md20
65 static struct
67 const char *name;
68 operatorT op;
69 unsigned int operands;
71 const i386_operators[] =
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 }
91 static struct
93 const char *name;
94 operatorT op;
95 unsigned short sz[3];
97 const i386_types[] =
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 } }
115 operatorT i386_operator (const char *name, unsigned int operands, char *pc)
117 unsigned int j;
119 if (!intel_syntax)
120 return O_absent;
122 if (!name)
124 if (operands != 2)
125 return O_illegal;
126 switch (*input_line_pointer)
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)
137 int adjust = 0;
138 char *gotfree_input_line = lex_got (&i.reloc[this_operand],
139 &adjust,
140 &intel_state.reloc_types);
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;
150 break;
152 return O_illegal;
155 for (j = 0; i386_operators[j].name; ++j)
156 if (strcasecmp(i386_operators[j].name, name) == 0)
158 if (i386_operators[j].operands
159 && i386_operators[j].operands != operands)
160 return O_illegal;
161 return i386_operators[j].op;
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 == ' ')
169 char *name = ++input_line_pointer;
170 char c = get_symbol_end ();
172 if (strcasecmp (name, "ptr") == 0)
174 name[-1] = *pc;
175 *pc = c;
176 if (intel_syntax > 0 || operands != 1)
177 return O_illegal;
178 return i386_types[j].op;
181 *input_line_pointer = c;
182 input_line_pointer = name - 1;
185 return O_absent;
188 static int i386_intel_parse_name (const char *name, expressionS *e)
190 unsigned int i;
192 for (i = 0; i386_types[i].name; ++i)
193 if (strcasecmp(i386_types[i].name, name) == 0)
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;
202 return 0;
205 static INLINE int i386_intel_check (const reg_entry *reg,
206 const reg_entry *base,
207 const reg_entry *index)
209 if ((this_operand >= 0 && reg != i.op[this_operand].regs)
210 || base != intel_state.base || index != intel_state.index)
212 as_bad (_("invalid use of register"));
213 return 0;
215 return 1;
218 static INLINE void i386_intel_fold (expressionS *e, symbolS *sym)
220 if (S_GET_SEGMENT (sym) == absolute_section)
222 offsetT val = e->X_add_number;
224 *e = *symbol_get_value_expression (sym);
225 e->X_add_number += val;
227 else
229 e->X_add_symbol = sym;
230 e->X_op_symbol = NULL;
231 e->X_op = O_symbol;
235 static int i386_intel_simplify (expressionS *);
237 static INLINE int i386_intel_simplify_symbol(symbolS *sym)
239 int ret = i386_intel_simplify (symbol_get_value_expression (sym));
241 if (ret == 2)
243 S_SET_SEGMENT(sym, absolute_section);
244 ret = 1;
246 return ret;
249 static int i386_intel_simplify (expressionS *e)
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;
256 if (!intel_syntax)
257 return 1;
259 switch (e->X_op)
261 case O_index:
262 if (e->X_add_symbol)
264 if (!i386_intel_simplify_symbol (e->X_add_symbol)
265 || !i386_intel_check(reg, intel_state.base, intel_state.index))
266 return 0;;
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;
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;
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)
307 as_bad (_("invalid use of register"));
308 return 0;
310 if (!i386_intel_simplify_symbol (e->X_add_symbol))
311 return 0;
312 i386_intel_fold (e, e->X_add_symbol);
313 break;
315 case O_full_ptr:
316 if (symbol_get_value_expression (e->X_op_symbol)->X_op == O_register)
318 as_bad (_("invalid use of register"));
319 return 0;
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;
329 case O_register:
330 if (this_operand < 0 || intel_state.in_offset)
332 as_bad (_("invalid use of register"));
333 return 0;
335 if (!intel_state.in_bracket)
337 if (i.op[this_operand].regs)
339 as_bad (_("invalid use of register"));
340 return 0;
342 if (i386_regtab[e->X_add_number].reg_type.bitfield.sreg3
343 && i386_regtab[e->X_add_number].reg_num == RegFlat)
345 as_bad (_("invalid use of pseudo-register"));
346 return 0;
348 i.op[this_operand].regs = i386_regtab + e->X_add_number;
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
356 /* esp is invalid as index */
357 intel_state.index = i386_regtab + REGNAM_EAX + 4;
359 e->X_op = O_constant;
360 e->X_add_number = 0;
361 return 2;
363 case O_multiply:
364 if (this_operand >= 0 && intel_state.in_bracket)
366 expressionS *scale = NULL;
368 if (intel_state.index)
369 --scale;
371 if (!intel_state.in_scale++)
372 intel_state.scale_factor = 1;
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);
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);
383 if (ret && scale && (scale + 1))
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;
392 --intel_state.in_scale;
393 if (!ret)
394 return 0;
396 if (!intel_state.in_scale)
397 switch (intel_state.scale_factor)
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;
417 break;
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)
425 base = intel_state.base;
426 index = intel_state.index;
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;
437 if (this_operand >= 0 && e->X_op == O_symbol && !intel_state.in_offset)
439 segT seg = S_GET_SEGMENT (e->X_add_symbol);
441 if (seg != absolute_section
442 && seg != reg_section
443 && seg != expr_section)
444 intel_state.is_mem |= 2 - !intel_state.in_bracket;
447 return 1;
450 int i386_need_index_operator (void)
452 return intel_syntax < 0;
455 static int
456 i386_intel_operand (char *operand_string, int got_a_float)
458 char *saved_input_line_pointer, *buf;
459 segT exp_seg;
460 expressionS exp, *expP;
461 char suffix = 0;
462 int ret;
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 gas_assert (!intel_state.in_offset);
472 gas_assert (!intel_state.in_bracket);
473 gas_assert (!intel_state.in_scale);
475 saved_input_line_pointer = input_line_pointer;
476 input_line_pointer = buf = xstrdup (operand_string);
478 /* A '$' followed by an identifier char is an identifier. Otherwise,
479 it's operator '.' followed by an expression. */
480 if (*buf == '$' && !is_identifier_char (buf[1]))
481 *buf = '.';
483 intel_syntax = -1;
484 memset (&exp, 0, sizeof(exp));
485 exp_seg = expression (&exp);
486 ret = i386_intel_simplify (&exp);
487 intel_syntax = 1;
489 SKIP_WHITESPACE ();
490 if (!is_end_of_line[(unsigned char) *input_line_pointer])
492 as_bad (_("junk `%s' after expression"), input_line_pointer);
493 ret = 0;
495 else if (exp.X_op == O_illegal || exp.X_op == O_absent)
497 as_bad (_("invalid expression"));
498 ret = 0;
501 input_line_pointer = saved_input_line_pointer;
502 free (buf);
504 gas_assert (!intel_state.in_offset);
505 gas_assert (!intel_state.in_bracket);
506 gas_assert (!intel_state.in_scale);
508 if (!ret)
509 return 0;
511 if (intel_state.op_modifier != O_absent
512 && current_templates->start->base_opcode != 0x8d /* lea */)
514 i.types[this_operand].bitfield.unspecified = 0;
516 switch (intel_state.op_modifier)
518 case O_byte_ptr:
519 i.types[this_operand].bitfield.byte = 1;
520 suffix = BYTE_MNEM_SUFFIX;
521 break;
523 case O_word_ptr:
524 i.types[this_operand].bitfield.word = 1;
525 if ((current_templates->start->name[0] == 'l'
526 && current_templates->start->name[2] == 's'
527 && current_templates->start->name[3] == 0)
528 || current_templates->start->base_opcode == 0x62 /* bound */)
529 suffix = BYTE_MNEM_SUFFIX; /* so it will cause an error */
530 else if (got_a_float == 2) /* "fi..." */
531 suffix = SHORT_MNEM_SUFFIX;
532 else
533 suffix = WORD_MNEM_SUFFIX;
534 break;
536 case O_dword_ptr:
537 i.types[this_operand].bitfield.dword = 1;
538 if ((current_templates->start->name[0] == 'l'
539 && current_templates->start->name[2] == 's'
540 && current_templates->start->name[3] == 0)
541 || current_templates->start->base_opcode == 0x62 /* bound */)
542 suffix = WORD_MNEM_SUFFIX;
543 else if (flag_code == CODE_16BIT
544 && (current_templates->start->opcode_modifier.jump
545 || current_templates->start->opcode_modifier.jumpdword))
546 suffix = LONG_DOUBLE_MNEM_SUFFIX;
547 else if (got_a_float == 1) /* "f..." */
548 suffix = SHORT_MNEM_SUFFIX;
549 else
550 suffix = LONG_MNEM_SUFFIX;
551 break;
553 case O_fword_ptr:
554 i.types[this_operand].bitfield.fword = 1;
555 if (current_templates->start->name[0] == 'l'
556 && current_templates->start->name[2] == 's'
557 && current_templates->start->name[3] == 0)
558 suffix = LONG_MNEM_SUFFIX;
559 else if (!got_a_float)
561 if (flag_code == CODE_16BIT)
562 add_prefix (DATA_PREFIX_OPCODE);
563 suffix = LONG_DOUBLE_MNEM_SUFFIX;
565 else
566 suffix = BYTE_MNEM_SUFFIX; /* so it will cause an error */
567 break;
569 case O_qword_ptr:
570 i.types[this_operand].bitfield.qword = 1;
571 if (current_templates->start->base_opcode == 0x62 /* bound */
572 || got_a_float == 1) /* "f..." */
573 suffix = LONG_MNEM_SUFFIX;
574 else
575 suffix = QWORD_MNEM_SUFFIX;
576 break;
578 case O_tbyte_ptr:
579 i.types[this_operand].bitfield.tbyte = 1;
580 if (got_a_float == 1)
581 suffix = LONG_DOUBLE_MNEM_SUFFIX;
582 else
583 suffix = BYTE_MNEM_SUFFIX; /* so it will cause an error */
584 break;
586 case O_oword_ptr:
587 case O_xmmword_ptr:
588 i.types[this_operand].bitfield.xmmword = 1;
589 suffix = XMMWORD_MNEM_SUFFIX;
590 break;
592 case O_ymmword_ptr:
593 i.types[this_operand].bitfield.ymmword = 1;
594 suffix = YMMWORD_MNEM_SUFFIX;
595 break;
597 case O_far_ptr:
598 suffix = LONG_DOUBLE_MNEM_SUFFIX;
599 /* FALLTHROUGH */
600 case O_near_ptr:
601 if (!current_templates->start->opcode_modifier.jump
602 && !current_templates->start->opcode_modifier.jumpdword)
603 suffix = got_a_float /* so it will cause an error */
604 ? BYTE_MNEM_SUFFIX
605 : LONG_DOUBLE_MNEM_SUFFIX;
606 break;
608 default:
609 BAD_CASE (intel_state.op_modifier);
610 break;
613 if (!i.suffix)
614 i.suffix = suffix;
615 else if (i.suffix != suffix)
617 as_bad (_("conflicting operand size modifiers"));
618 return 0;
622 /* Operands for jump/call need special consideration. */
623 if (current_templates->start->opcode_modifier.jump
624 || current_templates->start->opcode_modifier.jumpdword
625 || current_templates->start->opcode_modifier.jumpintersegment)
627 if (i.op[this_operand].regs || intel_state.base || intel_state.index
628 || intel_state.is_mem > 1)
629 i.types[this_operand].bitfield.jumpabsolute = 1;
630 else
631 switch (intel_state.op_modifier)
633 case O_near_ptr:
634 if (intel_state.seg)
635 i.types[this_operand].bitfield.jumpabsolute = 1;
636 else
637 intel_state.is_mem = 1;
638 break;
639 case O_far_ptr:
640 case O_absent:
641 if (!intel_state.seg)
643 intel_state.is_mem = 1;
644 if (intel_state.op_modifier == O_absent)
645 break;
646 as_bad (_("cannot infer the segment part of the operand"));
647 return 0;
649 else if (S_GET_SEGMENT (intel_state.seg) == reg_section)
650 i.types[this_operand].bitfield.jumpabsolute = 1;
651 else
653 i386_operand_type types;
655 if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
657 as_bad (_("at most %d immediate operands are allowed"),
658 MAX_IMMEDIATE_OPERANDS);
659 return 0;
661 expP = &im_expressions[i.imm_operands++];
662 memset (expP, 0, sizeof(*expP));
663 expP->X_op = O_symbol;
664 expP->X_add_symbol = intel_state.seg;
665 i.op[this_operand].imms = expP;
667 resolve_expression (expP);
668 operand_type_set (&types, ~0);
669 if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state.seg),
670 expP, types, operand_string))
671 return 0;
672 if (i.operands < MAX_OPERANDS)
674 this_operand = i.operands++;
675 i.types[this_operand].bitfield.unspecified = 1;
677 if (suffix == LONG_DOUBLE_MNEM_SUFFIX)
678 i.suffix = 0;
679 intel_state.seg = NULL;
680 intel_state.is_mem = 0;
682 break;
683 default:
684 i.types[this_operand].bitfield.jumpabsolute = 1;
685 break;
687 if (i.types[this_operand].bitfield.jumpabsolute)
688 intel_state.is_mem |= 1;
690 else if (intel_state.seg)
691 intel_state.is_mem |= 1;
693 if (i.op[this_operand].regs)
695 i386_operand_type temp;
697 /* Register operand. */
698 if (intel_state.base || intel_state.index || intel_state.seg)
700 as_bad (_("invalid operand"));
701 return 0;
704 temp = i.op[this_operand].regs->reg_type;
705 temp.bitfield.baseindex = 0;
706 i.types[this_operand] = operand_type_or (i.types[this_operand], temp);
707 i.types[this_operand].bitfield.unspecified = 0;
708 ++i.reg_operands;
710 else if (intel_state.base || intel_state.index || intel_state.seg
711 || intel_state.is_mem)
713 /* Memory operand. */
714 if (i.mem_operands
715 >= 2 - !current_templates->start->opcode_modifier.isstring)
717 as_bad (_("too many memory references for `%s'"),
718 current_templates->start->name);
719 return 0;
722 expP = &disp_expressions[i.disp_operands];
723 memcpy (expP, &exp, sizeof(exp));
724 resolve_expression (expP);
726 if (expP->X_op != O_constant || expP->X_add_number
727 || (!intel_state.base && !intel_state.index))
729 i.op[this_operand].disps = expP;
730 i.disp_operands++;
732 if (flag_code == CODE_64BIT)
734 i.types[this_operand].bitfield.disp32 = 1;
735 if (!i.prefix[ADDR_PREFIX])
737 i.types[this_operand].bitfield.disp64 = 1;
738 i.types[this_operand].bitfield.disp32s = 1;
741 else if (!i.prefix[ADDR_PREFIX] ^ (flag_code == CODE_16BIT))
742 i.types[this_operand].bitfield.disp32 = 1;
743 else
744 i.types[this_operand].bitfield.disp16 = 1;
746 #if defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)
748 * exp_seg is used only for verification in
749 * i386_finalize_displacement, and we can end up seeing reg_section
750 * here - but we know we removed all registers from the expression
751 * (or error-ed on any remaining ones) in i386_intel_simplify. I
752 * consider the check in i386_finalize_displacement bogus anyway, in
753 * particular because it doesn't allow for expr_section, so I'd
754 * rather see that check (and the similar one in
755 * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
756 * expert I can't really say whether that would have other bad side
757 * effects.
759 if (OUTPUT_FLAVOR == bfd_target_aout_flavour
760 && exp_seg == reg_section)
761 exp_seg = expP->X_op != O_constant ? undefined_section
762 : absolute_section;
763 #endif
765 if (!i386_finalize_displacement (exp_seg, expP,
766 intel_state.reloc_types,
767 operand_string))
768 return 0;
771 if (intel_state.base || intel_state.index)
772 i.types[this_operand].bitfield.baseindex = 1;
774 if (intel_state.seg)
776 for (;;)
778 expP = symbol_get_value_expression (intel_state.seg);
779 if (expP->X_op != O_full_ptr)
780 break;
781 intel_state.seg = expP->X_add_symbol;
783 if (expP->X_op != O_register)
785 as_bad (_("segment register name expected"));
786 return 0;
788 if (!i386_regtab[expP->X_add_number].reg_type.bitfield.sreg2
789 && !i386_regtab[expP->X_add_number].reg_type.bitfield.sreg3)
791 as_bad (_("invalid use of register"));
792 return 0;
794 switch (i386_regtab[expP->X_add_number].reg_num)
796 case 0: i.seg[i.mem_operands] = &es; break;
797 case 1: i.seg[i.mem_operands] = &cs; break;
798 case 2: i.seg[i.mem_operands] = &ss; break;
799 case 3: i.seg[i.mem_operands] = &ds; break;
800 case 4: i.seg[i.mem_operands] = &fs; break;
801 case 5: i.seg[i.mem_operands] = &gs; break;
802 case RegFlat: i.seg[i.mem_operands] = NULL; break;
806 /* Swap base and index in 16-bit memory operands like
807 [si+bx]. Since i386_index_check is also used in AT&T
808 mode we have to do that here. */
809 if (intel_state.base
810 && intel_state.index
811 && intel_state.base->reg_type.bitfield.reg16
812 && intel_state.index->reg_type.bitfield.reg16
813 && intel_state.base->reg_num >= 6
814 && intel_state.index->reg_num < 6)
816 i.base_reg = intel_state.index;
817 i.index_reg = intel_state.base;
819 else
821 i.base_reg = intel_state.base;
822 i.index_reg = intel_state.index;
825 if (!i386_index_check (operand_string))
826 return 0;
828 i.types[this_operand].bitfield.mem = 1;
829 ++i.mem_operands;
831 else
833 /* Immediate. */
834 if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
836 as_bad (_("at most %d immediate operands are allowed"),
837 MAX_IMMEDIATE_OPERANDS);
838 return 0;
841 expP = &im_expressions[i.imm_operands++];
842 i.op[this_operand].imms = expP;
843 *expP = exp;
845 return i386_finalize_immediate (exp_seg, expP, intel_state.reloc_types,
846 operand_string);
849 return 1;