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