Coverage Report

Created: 2026-07-25 10:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/gas/config/tc-i386-intel.c
Line
Count
Source
1
/* tc-i386.c -- Assemble Intel syntax code for ix86/x86-64
2
   Copyright (C) 2009-2026 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
2
#define O_offset O_md32
41
/* offset X_add_symbol */
42
0
#define O_short O_md31
43
/* near ptr X_add_symbol */
44
0
#define O_near_ptr O_md30
45
/* far ptr X_add_symbol */
46
64
#define O_far_ptr O_md29
47
/* byte ptr X_add_symbol */
48
0
#define O_byte_ptr O_md28
49
/* word ptr X_add_symbol */
50
0
#define O_word_ptr O_md27
51
/* dword ptr X_add_symbol */
52
0
#define O_dword_ptr O_md26
53
/* qword ptr X_add_symbol */
54
0
#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
0
#define O_fword_ptr O_md24
59
/* tbyte ptr X_add_symbol */
60
0
#define O_tbyte_ptr O_md23
61
/* oword ptr X_add_symbol */
62
0
#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
0
#define O_ymmword_ptr O_md21
67
/* zmmword ptr X_add_symbol */
68
0
#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
609k
{
124
609k
  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
609k
  if (!intel_syntax)
137
41.5k
    return O_absent;
138
139
568k
  if (!name)
140
260k
    {
141
260k
      if (operands != 2)
142
0
  return O_illegal;
143
260k
      switch (*input_line_pointer)
144
260k
  {
145
2.76k
  case ':':
146
2.76k
    ++input_line_pointer;
147
2.76k
    return O_full_ptr;
148
5.13k
  case '[':
149
5.13k
    ++input_line_pointer;
150
5.13k
    return O_index;
151
205
  case '@':
152
205
    if (this_operand >= 0 && i.reloc[this_operand] == NO_RELOC)
153
107
      {
154
107
        int adjust = 0;
155
107
        char *gotfree_input_line = lex_got (&i.reloc[this_operand],
156
107
              &adjust,
157
107
              &intel_state.reloc_types);
158
159
107
        if (!gotfree_input_line)
160
40
    break;
161
67
        free (gotfree_input_line);
162
67
        *input_line_pointer++ = '+';
163
67
        memset (input_line_pointer, '0', adjust - 1);
164
67
        input_line_pointer[adjust - 1] = ' ';
165
67
        return O_add;
166
107
      }
167
98
    break;
168
260k
  }
169
252k
      return O_illegal;
170
260k
    }
171
172
  /* See the quotation related comment in i386_parse_name().  */
173
307k
  if (*pc == '"')
174
44.3k
    return O_absent;
175
176
4.21M
  for (j = 0; i386_operators[j].name; ++j)
177
3.94M
    if (strcasecmp (i386_operators[j].name, name) == 0)
178
13
      {
179
13
  if (i386_operators[j].operands
180
13
      && i386_operators[j].operands != operands)
181
9
    return O_illegal;
182
4
  return i386_operators[j].op;
183
13
      }
184
185
3.68M
  for (j = 0; i386_types[j].name; ++j)
186
3.42M
    if (strcasecmp (i386_types[j].name, name) == 0)
187
19
      break;
188
189
263k
  if (i386_types[j].name && is_whitespace (*pc))
190
1
    {
191
1
      const char *start = ++input_line_pointer;
192
1
      char *pname;
193
1
      char c = get_symbol_name (&pname);
194
195
1
      if (strcasecmp (pname, "ptr") == 0 && (c != '"' || pname == start))
196
0
  {
197
0
    pname[-1] = *pc;
198
0
    *pc = c;
199
0
    if (intel_syntax > 0 || operands != 1)
200
0
      return O_illegal;
201
0
    return i386_types[j].op;
202
0
  }
203
204
1
      if (strcasecmp (pname, "bcst") == 0 && (c != '"' || pname == start))
205
0
  {
206
0
    pname[-1] = *pc;
207
0
    *pc = c;
208
0
    if (intel_syntax > 0 || operands != 1
209
0
        || i386_types[j].sz[0] > 8
210
0
        || (i386_types[j].sz[0] & (i386_types[j].sz[0] - 1)))
211
0
      return O_illegal;
212
0
    switch (pp.encoding)
213
0
      {
214
0
      case encoding_default:
215
0
      case encoding_egpr:
216
0
        pp.encoding = encoding_evex;
217
0
        break;
218
0
      case encoding_evex:
219
0
      case encoding_evex512:
220
0
        break;
221
0
      default:
222
0
        return O_illegal;
223
0
      }
224
0
    if (!i.broadcast.bytes && !i.broadcast.type)
225
0
      {
226
0
        i.broadcast.bytes = i386_types[j].sz[0];
227
0
        i.broadcast.operand = this_operand;
228
0
      }
229
0
    return i386_types[j].op;
230
0
  }
231
232
1
      (void) restore_line_pointer (c);
233
1
      input_line_pointer = pname - 1;
234
1
    }
235
236
263k
  return O_absent;
237
263k
}
238
239
static int i386_intel_parse_name (const char *name,
240
          expressionS *e,
241
          enum expr_mode mode)
242
182k
{
243
182k
  unsigned int j;
244
245
182k
  if (! strcmp (name, "$"))
246
521
    {
247
521
      current_location (e, mode);
248
521
      return 1;
249
521
    }
250
251
2.54M
  for (j = 0; i386_types[j].name; ++j)
252
2.36M
    if (strcasecmp(i386_types[j].name, name) == 0)
253
6
      {
254
6
  e->X_op = O_constant;
255
6
  e->X_add_number = i386_types[j].sz[flag_code];
256
6
  e->X_add_symbol = NULL;
257
6
  e->X_op_symbol = NULL;
258
6
  return 1;
259
6
      }
260
261
181k
  return 0;
262
181k
}
263
264
static INLINE int i386_intel_check (const reg_entry *rreg,
265
            const reg_entry *base,
266
            const reg_entry *iindex)
267
162k
{
268
162k
  if ((this_operand >= 0
269
114k
       && rreg != i.op[this_operand].regs)
270
162k
      || base != intel_state.base
271
162k
      || iindex != intel_state.index)
272
444
    {
273
444
      as_bad (_("invalid use of register"));
274
444
      return 0;
275
444
    }
276
162k
  return 1;
277
162k
}
278
279
static INLINE void i386_intel_fold (expressionS *e, symbolS *sym)
280
2.39k
{
281
2.39k
  expressionS *exp = symbol_get_value_expression (sym);
282
283
2.39k
  if (S_GET_SEGMENT (sym) == absolute_section
284
2.27k
      || S_GET_SEGMENT (sym) == expr_section)
285
176
    {
286
176
      offsetT val = e->X_add_number;
287
288
176
      *e = *exp;
289
176
      e->X_add_number += val;
290
176
    }
291
2.22k
  else
292
2.22k
    {
293
2.22k
      if (exp->X_op == O_symbol
294
0
    && strcmp (S_GET_NAME (exp->X_add_symbol),
295
0
         GLOBAL_OFFSET_TABLE_NAME) == 0)
296
0
  sym = exp->X_add_symbol;
297
2.22k
      e->X_add_symbol = sym;
298
2.22k
      e->X_op_symbol = NULL;
299
2.22k
      e->X_op = O_symbol;
300
2.22k
    }
301
2.39k
}
302
303
static int
304
i386_intel_simplify_register (expressionS *e)
305
3.62k
{
306
3.62k
  int reg_num;
307
308
3.62k
  if (this_operand < 0 || intel_state.in_offset)
309
282
    {
310
282
      as_bad (_("invalid use of register"));
311
282
      return 0;
312
282
    }
313
314
3.34k
  if (e->X_op == O_register)
315
3.34k
    reg_num = e->X_add_number;
316
0
  else
317
0
    reg_num = e->X_md - 1;
318
319
3.34k
  if (reg_num < 0 || reg_num >= (int) i386_regtab_size)
320
0
    {
321
0
      as_bad (_("invalid register number"));
322
0
      return 0;
323
0
    }
324
325
3.34k
  if (!check_register (&i386_regtab[reg_num]))
326
0
    {
327
0
      as_bad (_("register '%s%s' cannot be used here"),
328
0
        register_prefix, i386_regtab[reg_num].reg_name);
329
0
      return 0;
330
0
    }
331
332
3.34k
  if (!intel_state.in_bracket)
333
2.91k
    {
334
2.91k
      if (i.op[this_operand].regs)
335
0
  {
336
0
    as_bad (_("invalid use of register"));
337
0
    return 0;
338
0
  }
339
2.91k
      if ((i386_regtab[reg_num].reg_type.bitfield.class == SReg
340
310
     && i386_regtab[reg_num].reg_num == RegFlat)
341
2.91k
    || (dot_insn ()
342
58
        && i386_regtab[reg_num].reg_type.bitfield.class == ClassNone))
343
0
  {
344
0
    as_bad (_("invalid use of pseudo-register"));
345
0
    return 0;
346
0
  }
347
2.91k
      i.op[this_operand].regs = i386_regtab + reg_num;
348
2.91k
    }
349
431
  else if (!intel_state.index
350
426
     && (i386_regtab[reg_num].reg_type.bitfield.xmmword
351
426
         || i386_regtab[reg_num].reg_type.bitfield.ymmword
352
426
         || i386_regtab[reg_num].reg_type.bitfield.zmmword
353
426
         || i386_regtab[reg_num].reg_num == RegIZ))
354
0
    intel_state.index = i386_regtab + reg_num;
355
431
  else if (!intel_state.base && !intel_state.in_scale)
356
417
    intel_state.base = i386_regtab + reg_num;
357
14
  else if (!intel_state.index)
358
9
    {
359
9
      const insn_template *t = current_templates.start;
360
361
9
      if (intel_state.in_scale
362
1
    || i386_regtab[reg_num].reg_type.bitfield.baseindex
363
1
    || dot_insn ()
364
1
    || t->mnem_off == MN_bndmk
365
1
    || t->mnem_off == MN_bndldx
366
1
    || t->mnem_off == MN_bndstx)
367
8
  intel_state.index = i386_regtab + reg_num;
368
1
      else
369
1
  {
370
    /* Convert base to index and make ESP/RSP the base.  */
371
1
    intel_state.index = intel_state.base;
372
1
    intel_state.base = i386_regtab + reg_num;
373
1
  }
374
9
    }
375
5
  else
376
5
    {
377
      /* esp is invalid as index */
378
5
      intel_state.index = reg_eax + ESP_REG_NUM;
379
5
    }
380
3.34k
  return 2;
381
3.34k
}
382
383
static symbolS *
384
i386_intel_simplify_symbol (symbolS *sym)
385
125k
{
386
125k
  if (symbol_resolving_p (sym))
387
4
    return sym;
388
389
125k
  symbolS *orig = sym;
390
125k
  offsetT off;
391
125k
  sym = symbol_equated_to (sym, &off);
392
125k
  if (sym == NULL || off != 0)
393
5
    return orig;
394
395
125k
  segT seg = S_GET_SEGMENT (sym);
396
125k
  if (seg == undefined_section
397
22.4k
      || (seg != expr_section && seg != reg_section && sym == orig))
398
108k
    return sym;
399
400
  /* i386_intel_simplify modifies its arg.  We don't want to make
401
     premature changes to symbols here, particularly for a symbol
402
     equate.  Changing a symbol may affect future uses of that
403
     symbol.  So copy the symbol value and make a new symbol after
404
     i386_intel_simplify has done its work.  Don't use structure
405
     assignment to copy the value as that doesn't guarantee writing
406
     any padding bytes, and we want to use memcmp below rather than
407
     comparing every field.  */
408
16.9k
  expressionS *e = symbol_get_value_expression (sym);
409
16.9k
  expressionS exp;
410
16.9k
  memcpy (&exp, e, sizeof exp);
411
16.9k
  symbol_mark_resolving (sym);
412
16.9k
  int ret = i386_intel_simplify (&exp);
413
16.9k
  symbol_clear_resolving (sym);
414
16.9k
  if (ret == 0)
415
2.51k
    return NULL;
416
417
14.4k
  if (memcmp (&exp, e, sizeof exp) != 0)
418
659
    sym = make_expr_symbol (&exp);
419
14.4k
  return sym;
420
16.9k
}
421
422
static int
423
i386_intel_simplify (expressionS *e)
424
88.2k
{
425
88.2k
  const reg_entry *the_reg = (this_operand >= 0
426
88.2k
            ? i.op[this_operand].regs : NULL);
427
88.2k
  const reg_entry *base = intel_state.base;
428
88.2k
  const reg_entry *state_index = intel_state.index;
429
88.2k
  symbolS *newsym;
430
88.2k
  int ret;
431
432
88.2k
  if (!intel_syntax)
433
0
    return 1;
434
435
88.2k
  switch (e->X_op)
436
88.2k
    {
437
1.07k
    case O_index:
438
1.07k
      if (e->X_add_symbol)
439
1.04k
  {
440
1.04k
    newsym = i386_intel_simplify_symbol (e->X_add_symbol);
441
1.04k
    if (!newsym
442
620
        || !i386_intel_check(the_reg, intel_state.base,
443
620
           intel_state.index))
444
421
      return 0;
445
619
    e->X_add_symbol = newsym;
446
619
    symbol_mark_resolving (e->X_add_symbol);
447
619
  }
448
651
      if (!intel_state.in_offset)
449
651
  ++intel_state.in_bracket;
450
651
      newsym = i386_intel_simplify_symbol (e->X_op_symbol);
451
651
      if (e->X_add_symbol)
452
619
  symbol_clear_resolving (e->X_add_symbol);
453
651
      if (!intel_state.in_offset)
454
651
  --intel_state.in_bracket;
455
651
      if (!newsym)
456
414
  return 0;
457
237
      e->X_op_symbol = newsym;
458
237
      if (!e->X_add_symbol)
459
32
  i386_intel_fold (e, e->X_op_symbol);
460
205
      else if (S_GET_SEGMENT (e->X_add_symbol) == expr_section
461
19
         && (S_GET_SEGMENT (e->X_op_symbol) == absolute_section
462
7
       || S_GET_SEGMENT (e->X_op_symbol) == expr_section)
463
18
         && symbol_get_value_expression (e->X_op_symbol)->X_op
464
18
      == O_constant)
465
12
  {
466
12
    offsetT val
467
12
      = symbol_get_value_expression (e->X_op_symbol)->X_add_number;
468
469
12
    i386_intel_fold (e, e->X_add_symbol);
470
12
    e->X_add_number += val;
471
12
  }
472
193
      else
473
193
  e->X_op = O_add;
474
237
      break;
475
476
2
    case O_offset:
477
2
      intel_state.has_offset = 1;
478
2
      ++intel_state.in_offset;
479
2
      newsym = i386_intel_simplify_symbol (e->X_add_symbol);
480
2
      --intel_state.in_offset;
481
2
      if (!newsym || !i386_intel_check(the_reg, base, state_index))
482
0
  return 0;
483
2
      e->X_add_symbol = newsym;
484
2
      i386_intel_fold (e, e->X_add_symbol);
485
2
      return 1;
486
487
0
    case O_byte_ptr:
488
0
    case O_word_ptr:
489
0
    case O_dword_ptr:
490
0
    case O_fword_ptr:
491
0
    case O_qword_ptr: /* O_mmword_ptr */
492
0
    case O_tbyte_ptr:
493
0
    case O_oword_ptr: /* O_xmmword_ptr */
494
0
    case O_ymmword_ptr:
495
0
    case O_zmmword_ptr:
496
0
    case O_near_ptr:
497
0
    case O_far_ptr:
498
0
      if (intel_state.op_modifier == O_absent)
499
0
  intel_state.op_modifier = e->X_op;
500
      /* FALLTHROUGH */
501
0
    case O_short:
502
0
      if (symbol_get_value_expression (e->X_add_symbol)->X_op
503
0
    == O_register)
504
0
  {
505
0
    as_bad (_("invalid use of register"));
506
0
    return 0;
507
0
  }
508
0
      newsym = i386_intel_simplify_symbol (e->X_add_symbol);
509
0
      if (!newsym)
510
0
  return 0;
511
0
      e->X_add_symbol = newsym;
512
0
      i386_intel_fold (e, e->X_add_symbol);
513
0
      break;
514
515
2.35k
    case O_full_ptr:
516
2.35k
      if (symbol_get_value_expression (e->X_op_symbol)->X_op
517
2.35k
    == O_register)
518
2
  {
519
2
    as_bad (_("invalid use of register"));
520
2
    return 0;
521
2
  }
522
2.35k
      newsym = i386_intel_simplify_symbol (e->X_op_symbol);
523
2.35k
      if (!newsym
524
2.35k
    || !i386_intel_check(the_reg, intel_state.base,
525
2.35k
             intel_state.index))
526
0
  return 0;
527
2.35k
      e->X_op_symbol = newsym;
528
2.35k
      if (!intel_state.in_offset)
529
2.35k
  {
530
2.35k
    if (!intel_state.seg)
531
204
      intel_state.seg = e->X_add_symbol;
532
2.14k
    else
533
2.14k
      {
534
2.14k
        expressionS exp = {
535
2.14k
    .X_op = O_full_ptr,
536
2.14k
    .X_add_symbol = e->X_add_symbol,
537
2.14k
    .X_op_symbol = intel_state.seg
538
2.14k
        };
539
2.14k
        intel_state.seg = make_expr_symbol (&exp);
540
2.14k
      }
541
2.35k
  }
542
2.35k
      i386_intel_fold (e, e->X_op_symbol);
543
2.35k
      break;
544
545
40.3k
    case O_add:
546
40.3k
      if (this_operand >= 0 && intel_state.in_bracket)
547
448
  {
548
448
    expressionS *left = NULL, *right = NULL;
549
448
    segT leftseg = NULL, rightseg = NULL;
550
551
448
    newsym = i386_intel_simplify_symbol (e->X_add_symbol);
552
448
    if (newsym)
553
445
      {
554
445
        e->X_add_symbol = newsym;
555
556
445
        if (base != intel_state.base || state_index != intel_state.index)
557
2
    {
558
2
      base = intel_state.base;
559
2
      state_index = intel_state.index;
560
2
      left = symbol_get_value_expression (newsym);
561
2
      resolve_expression (left);
562
2
      leftseg = S_GET_SEGMENT (newsym);
563
2
    }
564
445
      }
565
566
448
    symbol_mark_resolving (e->X_add_symbol);
567
448
    newsym = i386_intel_simplify_symbol (e->X_op_symbol);
568
448
    symbol_clear_resolving (e->X_add_symbol);
569
448
    if (newsym)
570
445
      {
571
445
        e->X_op_symbol = newsym;
572
573
445
        if (base != intel_state.base || state_index != intel_state.index)
574
5
    {
575
5
      base = intel_state.base;
576
5
      state_index = intel_state.index;
577
5
      right = symbol_get_value_expression (newsym);
578
5
      resolve_expression (right);
579
5
      rightseg = S_GET_SEGMENT (newsym);
580
5
    }
581
445
      }
582
583
448
    if (left && right
584
0
        && (leftseg == absolute_section || leftseg == expr_section)
585
0
        && left->X_op == O_constant
586
0
        && (rightseg == absolute_section || rightseg == expr_section)
587
0
        && right->X_op == O_constant)
588
0
      {
589
0
         e->X_op = O_constant;
590
0
         e->X_add_number += left->X_add_number + right->X_add_number;
591
0
         e->X_add_symbol = NULL;
592
0
         e->X_op_symbol = NULL;
593
0
      }
594
448
    else if (left
595
2
       && (leftseg == absolute_section || leftseg == expr_section)
596
2
       && left->X_op == O_constant)
597
0
      i386_intel_fold (e, e->X_op_symbol);
598
448
    else if (right
599
5
       && (rightseg == absolute_section || rightseg == expr_section)
600
5
       && right->X_op == O_constant)
601
1
      i386_intel_fold (e, e->X_add_symbol);
602
448
  }
603
40.3k
      goto fallthrough;
604
605
761
    case O_multiply:
606
761
      if (this_operand >= 0 && intel_state.in_bracket)
607
21
  {
608
21
    expressionS *scale = NULL, *other = NULL;
609
21
    int has_index = (intel_state.index != NULL);
610
611
21
    if (!intel_state.in_scale++)
612
11
      intel_state.scale_factor = 1;
613
614
21
    newsym = i386_intel_simplify_symbol (e->X_add_symbol);
615
21
    if (newsym)
616
17
      {
617
17
        e->X_add_symbol = newsym;
618
619
17
        if (!has_index && intel_state.index)
620
2
    {
621
2
      scale = symbol_get_value_expression (e->X_op_symbol);
622
2
      other = symbol_get_value_expression (e->X_add_symbol);
623
2
    }
624
625
17
        symbol_mark_resolving (e->X_add_symbol);
626
17
        newsym = i386_intel_simplify_symbol (e->X_op_symbol);
627
17
        symbol_clear_resolving (e->X_add_symbol);
628
17
      }
629
630
21
    if (newsym)
631
17
      {
632
17
        e->X_op_symbol = newsym;
633
634
17
        if (!scale && !has_index && intel_state.index)
635
2
    {
636
2
      scale = symbol_get_value_expression (e->X_add_symbol);
637
2
      other = symbol_get_value_expression (e->X_op_symbol);
638
2
    }
639
17
      }
640
641
21
    if (newsym && scale)
642
4
      {
643
4
        segT seg;
644
645
4
        resolve_expression (scale);
646
4
        if (scale->X_op != O_constant
647
4
      || intel_state.index->reg_type.bitfield.word)
648
0
    scale->X_add_number = 0;
649
4
        intel_state.scale_factor *= scale->X_add_number;
650
651
4
        resolve_expression (other);
652
4
        seg = S_GET_SEGMENT (newsym);
653
4
        if ((seg == absolute_section || seg == expr_section)
654
2
      && other->X_op == O_constant
655
0
      && other->X_add_number == 0)
656
0
    {
657
0
      e->X_op = O_constant;
658
0
      e->X_add_symbol = NULL;
659
0
      e->X_op_symbol = NULL;
660
0
    }
661
4
      }
662
663
21
    --intel_state.in_scale;
664
21
    if (!newsym)
665
4
      return 0;
666
667
17
    if (!intel_state.in_scale)
668
7
      switch (intel_state.scale_factor)
669
7
        {
670
3
        case 1:
671
3
    i.log2_scale_factor = 0;
672
3
    break;
673
0
        case 2:
674
0
    i.log2_scale_factor = 1;
675
0
    break;
676
0
        case 4:
677
0
    i.log2_scale_factor = 2;
678
0
    break;
679
0
        case 8:
680
0
    i.log2_scale_factor = 3;
681
0
    break;
682
4
        default:
683
    /* esp is invalid as index */
684
4
    intel_state.index = reg_eax + ESP_REG_NUM;
685
4
    break;
686
7
        }
687
688
17
    break;
689
17
  }
690
740
      goto fallthrough;
691
692
3.62k
    case O_register:
693
3.62k
      ret = i386_intel_simplify_register (e);
694
3.62k
      if (ret == 2)
695
3.34k
  {
696
3.34k
    gas_assert (e->X_add_number < (unsigned short) -1);
697
3.34k
    e->X_md = (unsigned short) e->X_add_number + 1;
698
3.34k
    e->X_op = O_constant;
699
3.34k
    e->X_add_number = 0;
700
3.34k
  }
701
3.62k
      return ret;
702
703
12.7k
    case O_constant:
704
12.7k
      if (e->X_md)
705
0
  return i386_intel_simplify_register (e);
706
707
      /* FALLTHROUGH */
708
40.0k
    default:
709
81.2k
    fallthrough:
710
81.2k
      if (e->X_add_symbol)
711
65.8k
  {
712
65.8k
    newsym = i386_intel_simplify_symbol (e->X_add_symbol);
713
65.8k
    if (!newsym)
714
1.25k
      return 0;
715
64.5k
    e->X_add_symbol = newsym;
716
64.5k
  }
717
79.9k
      if (!the_reg && this_operand >= 0
718
56.9k
    && e->X_op == O_symbol && !e->X_add_number)
719
5.34k
  the_reg = i.op[this_operand].regs;
720
79.9k
      if (e->X_op == O_add || e->X_op == O_subtract)
721
41.3k
  {
722
41.3k
    base = intel_state.base;
723
41.3k
    state_index = intel_state.index;
724
41.3k
  }
725
79.9k
      if (!i386_intel_check (the_reg, base, state_index))
726
10
  return 0;
727
79.9k
      if (e->X_op_symbol)
728
54.7k
  {
729
54.7k
    if (e->X_add_symbol)
730
54.7k
      symbol_mark_resolving (e->X_add_symbol);
731
54.7k
    newsym = i386_intel_simplify_symbol (e->X_op_symbol);
732
54.7k
    if (e->X_add_symbol)
733
54.7k
      symbol_clear_resolving (e->X_add_symbol);
734
54.7k
    if (!newsym)
735
417
      return 0;
736
54.3k
    e->X_op_symbol = newsym;
737
54.3k
  }
738
79.5k
      if (!i386_intel_check (the_reg,
739
79.5k
           e->X_op != O_add ? base : intel_state.base,
740
79.5k
           (e->X_op != O_add ? state_index
741
79.5k
                 : intel_state.index)))
742
433
  return 0;
743
79.0k
      break;
744
88.2k
    }
745
746
81.7k
  if (this_operand >= 0
747
56.5k
      && e->X_op == O_symbol
748
5.53k
      && !intel_state.has_offset)
749
5.53k
    {
750
5.53k
      segT seg = S_GET_SEGMENT (e->X_add_symbol);
751
752
5.53k
      if (seg != absolute_section
753
5.53k
    && seg != reg_section
754
5.53k
    && seg != expr_section)
755
5.53k
  intel_state.is_mem |= 2 - !intel_state.in_bracket;
756
5.53k
    }
757
758
81.7k
  return 1;
759
88.2k
}
760
761
int i386_need_index_operator (void)
762
1.13k
{
763
1.13k
  return intel_syntax < 0;
764
1.13k
}
765
766
static int
767
i386_intel_operand (char *operand_string, int got_a_float)
768
56.0k
{
769
56.0k
  char *saved_input_line_pointer, *buf;
770
56.0k
  segT exp_seg;
771
56.0k
  expressionS exp, *expP;
772
56.0k
  char suffix = 0;
773
56.0k
  bool rc_sae_modifier = i.rounding.type != rc_none && i.rounding.modifier;
774
56.0k
  int ret;
775
776
  /* Handle vector immediates.  */
777
56.0k
  if (RC_SAE_immediate (operand_string))
778
0
    {
779
0
      if (i.imm_operands)
780
0
  {
781
0
    as_bad (_("`%s': RC/SAE operand must precede immediate operands"),
782
0
      insn_name (current_templates.start));
783
0
    return 0;
784
0
  }
785
786
0
      return 1;
787
0
    }
788
789
  /* Initialize state structure.  */
790
56.0k
  intel_state.op_modifier = O_absent;
791
56.0k
  intel_state.is_mem = 0;
792
56.0k
  intel_state.is_indirect = 0;
793
56.0k
  intel_state.has_offset = 0;
794
56.0k
  intel_state.base = NULL;
795
56.0k
  intel_state.index = NULL;
796
56.0k
  intel_state.seg = NULL;
797
56.0k
  operand_type_set (&intel_state.reloc_types, ~0);
798
56.0k
  gas_assert (!intel_state.in_offset);
799
56.0k
  gas_assert (!intel_state.in_bracket);
800
56.0k
  gas_assert (!intel_state.in_scale);
801
802
56.0k
  saved_input_line_pointer = input_line_pointer;
803
56.0k
  input_line_pointer = buf = xstrdup (operand_string);
804
805
56.0k
  intel_syntax = -1;
806
56.0k
  expr_mode = expr_operator_none;
807
56.0k
  memset (&exp, 0, sizeof(exp));
808
56.0k
  exp_seg = expression (&exp);
809
56.0k
  ret = i386_intel_simplify (&exp);
810
56.0k
  intel_syntax = 1;
811
812
56.0k
  SKIP_WHITESPACE ();
813
814
  /* Handle vector operations.  */
815
56.0k
  if (*input_line_pointer == '{')
816
32.6k
    {
817
32.6k
      char *end = check_VecOperations (input_line_pointer);
818
32.6k
      if (end)
819
0
  input_line_pointer = end;
820
32.6k
      else
821
32.6k
  ret = 0;
822
32.6k
    }
823
824
56.0k
  if (!is_end_of_stmt (*input_line_pointer))
825
35.2k
    {
826
35.2k
      if (ret)
827
2.58k
  as_bad (_("junk `%s' after expression"), input_line_pointer);
828
35.2k
      ret = 0;
829
35.2k
    }
830
20.8k
  else if (exp.X_op == O_illegal || exp.X_op == O_absent)
831
16
    {
832
16
      if (ret)
833
16
  as_bad (_("invalid expression"));
834
16
      ret = 0;
835
16
    }
836
20.8k
  else if (!intel_state.has_offset
837
20.8k
     && input_line_pointer > buf
838
20.8k
     && *(input_line_pointer - 1) == ']')
839
0
    {
840
0
      intel_state.is_mem |= 1;
841
0
      intel_state.is_indirect = 1;
842
0
    }
843
844
56.0k
  input_line_pointer = saved_input_line_pointer;
845
56.0k
  free (buf);
846
847
56.0k
  gas_assert (!intel_state.in_offset);
848
56.0k
  gas_assert (!intel_state.in_bracket);
849
56.0k
  gas_assert (!intel_state.in_scale);
850
851
56.0k
  if (!ret)
852
35.6k
    return 0;
853
854
20.3k
  if (intel_state.op_modifier != O_absent
855
0
      && current_templates.start->mnem_off != MN_lea)
856
0
    {
857
0
      i.types[this_operand].bitfield.unspecified = 0;
858
859
0
      switch (intel_state.op_modifier)
860
0
  {
861
0
  case O_byte_ptr:
862
0
    i.types[this_operand].bitfield.byte = 1;
863
0
    suffix = BYTE_MNEM_SUFFIX;
864
0
    break;
865
866
0
  case O_word_ptr:
867
0
    i.types[this_operand].bitfield.word = 1;
868
0
    if (got_a_float == 2) /* "fi..." */
869
0
      suffix = SHORT_MNEM_SUFFIX;
870
0
    else if (current_templates.start->mnem_off != MN_lar
871
0
       && current_templates.start->mnem_off != MN_lsl
872
0
       && current_templates.start->mnem_off != MN_arpl)
873
0
      suffix = WORD_MNEM_SUFFIX;
874
0
    break;
875
876
0
  case O_dword_ptr:
877
0
    i.types[this_operand].bitfield.dword = 1;
878
0
    if ((insn_name (current_templates.start)[0] == 'l'
879
0
         && insn_name (current_templates.start)[2] == 's'
880
0
         && insn_name (current_templates.start)[3] == 0)
881
0
        || current_templates.start->mnem_off == MN_bound)
882
0
      suffix = WORD_MNEM_SUFFIX;
883
0
    else if (flag_code != CODE_32BIT
884
0
       && (current_templates.start->opcode_modifier.jump == JUMP
885
0
           || current_templates.start->opcode_modifier.jump
886
0
        == JUMP_DWORD))
887
0
      {
888
0
        i.far_branch = true;
889
0
        suffix = WORD_MNEM_SUFFIX;
890
0
      }
891
0
    else if (got_a_float == 1) /* "f..." */
892
0
      suffix = SHORT_MNEM_SUFFIX;
893
0
    else
894
0
      suffix = LONG_MNEM_SUFFIX;
895
0
    break;
896
897
0
  case O_fword_ptr:
898
0
    i.types[this_operand].bitfield.fword = 1;
899
0
    if (current_templates.start->mnem_off == MN_les
900
0
        || current_templates.start->mnem_off == MN_lds
901
0
        || current_templates.start->mnem_off == MN_lss
902
0
        || current_templates.start->mnem_off == MN_lfs
903
0
        || current_templates.start->mnem_off == MN_lgs)
904
0
      suffix = LONG_MNEM_SUFFIX;
905
0
    else if (!got_a_float)
906
0
      {
907
0
        if (flag_code == CODE_16BIT)
908
0
    add_prefix (DATA_PREFIX_OPCODE);
909
0
        i.far_branch = true;
910
0
      }
911
0
    break;
912
913
0
  case O_qword_ptr: /* O_mmword_ptr */
914
0
    i.types[this_operand].bitfield.qword = 1;
915
0
    if (current_templates.start->mnem_off == MN_bound
916
0
        || got_a_float == 1) /* "f..." */
917
0
      suffix = LONG_MNEM_SUFFIX;
918
0
    else
919
0
      suffix = QWORD_MNEM_SUFFIX;
920
0
    break;
921
922
0
  case O_tbyte_ptr:
923
0
    i.types[this_operand].bitfield.tbyte = 1;
924
0
    if (got_a_float)
925
0
      break;
926
0
    if (flag_code == CODE_64BIT
927
0
        && (current_templates.start->operand_types[0].bitfield.fword
928
0
      || current_templates.start->operand_types[0].bitfield.tbyte
929
0
      || current_templates.start->opcode_modifier.jump == JUMP_DWORD
930
0
      || current_templates.start->opcode_modifier.jump == JUMP))
931
0
      suffix = QWORD_MNEM_SUFFIX; /* l[fgs]s, [ls][gi]dt, call, jmp */
932
0
    else
933
0
      i.types[this_operand].bitfield.byte = 1; /* cause an error */
934
0
    break;
935
936
0
  case O_oword_ptr: /* O_xmmword_ptr */
937
0
    i.types[this_operand].bitfield.xmmword = 1;
938
0
    break;
939
940
0
  case O_ymmword_ptr:
941
0
    if (vector_size < VSZ256)
942
0
      {
943
0
        as_bad (_("256-bit operands disabled"));
944
0
        return 0;
945
0
      }
946
0
    i.types[this_operand].bitfield.ymmword = 1;
947
0
    break;
948
949
0
  case O_zmmword_ptr:
950
0
    if (vector_size < VSZ512)
951
0
      {
952
0
        as_bad (_("512-bit operands disabled"));
953
0
        return 0;
954
0
      }
955
0
    i.types[this_operand].bitfield.zmmword = 1;
956
0
    break;
957
958
0
  case O_far_ptr:
959
0
    i.far_branch = true;
960
    /* FALLTHROUGH */
961
0
  case O_near_ptr:
962
0
    if (current_templates.start->opcode_modifier.jump != JUMP
963
0
        && current_templates.start->opcode_modifier.jump != JUMP_DWORD)
964
0
      {
965
        /* cause an error */
966
0
        i.types[this_operand].bitfield.byte = 1;
967
0
        i.types[this_operand].bitfield.tbyte = 1;
968
0
        suffix = i.suffix;
969
0
      }
970
0
    break;
971
972
0
  default:
973
0
    BAD_CASE (intel_state.op_modifier);
974
0
    break;
975
0
  }
976
977
      /* Now check whether we actually want to infer an AT&T-like suffix.
978
   We really only need to do this when operand size determination (incl.
979
   REX.W) is going to be derived from it.  For this we check whether the
980
   given suffix is valid for any of the candidate templates.  */
981
0
      if (suffix && suffix != i.suffix
982
0
    && current_templates.start->mnem_off != MN_bound)
983
0
  {
984
0
    const insn_template *t;
985
986
0
    for (t = current_templates.start; t < current_templates.end; ++t)
987
0
      {
988
        /* Operands haven't been swapped yet.  */
989
0
        unsigned int op = t->operands - 1 - this_operand;
990
991
        /* Easy checks to skip templates which won't match anyway.  */
992
0
        if (this_operand >= t->operands
993
0
      || t->opcode_modifier.dialect >= ATT_SYNTAX)
994
0
    continue;
995
996
0
        switch (suffix)
997
0
    {
998
0
    case BYTE_MNEM_SUFFIX:
999
0
      if (t->opcode_modifier.no_bsuf)
1000
0
        continue;
1001
0
      break;
1002
0
    case WORD_MNEM_SUFFIX:
1003
0
      if (t->opcode_modifier.no_wsuf)
1004
0
        continue;
1005
0
      break;
1006
0
    case LONG_MNEM_SUFFIX:
1007
0
      if (t->opcode_modifier.no_lsuf)
1008
0
        continue;
1009
0
      break;
1010
0
    case QWORD_MNEM_SUFFIX:
1011
0
      if (t->opcode_modifier.no_qsuf || !q_suffix_allowed (t))
1012
0
        continue;
1013
0
      break;
1014
0
    case SHORT_MNEM_SUFFIX:
1015
0
      if (t->opcode_modifier.no_ssuf)
1016
0
        continue;
1017
0
      break;
1018
0
    default:
1019
0
      abort ();
1020
0
    }
1021
1022
        /* We can skip templates with swappable operands here, as one
1023
     operand will be a register, which operand size can be
1024
     determined from.  */
1025
0
        if (t->opcode_modifier.d)
1026
0
    continue;
1027
1028
        /* In a few cases suffixes are permitted, but we can nevertheless
1029
     derive that these aren't going to be needed.  This is only of
1030
     interest for insns using ModR/M.  */
1031
0
        if (!t->opcode_modifier.modrm)
1032
0
    break;
1033
1034
0
        if (!t->operand_types[op].bitfield.baseindex)
1035
0
    continue;
1036
1037
0
        switch (t->operand_types[op].bitfield.class)
1038
0
    {
1039
0
    case RegMMX:
1040
0
    case RegSIMD:
1041
0
    case RegMask:
1042
0
      continue;
1043
0
    }
1044
1045
0
        break;
1046
0
      }
1047
1048
0
    if (t == current_templates.end)
1049
0
      suffix = 0;
1050
0
  }
1051
1052
0
      if (!i.suffix)
1053
0
  i.suffix = suffix;
1054
0
      else if (suffix && i.suffix != suffix)
1055
0
  {
1056
0
    as_bad (_("conflicting operand size modifiers"));
1057
0
    return 0;
1058
0
  }
1059
0
    }
1060
1061
  /* Operands for jump/call need special consideration.  */
1062
20.3k
  if (current_templates.start->opcode_modifier.jump
1063
19.9k
      || current_templates.start->mnem_off == MN_jmpabs)
1064
405
    {
1065
405
      bool jumpabsolute = false;
1066
1067
405
      if (i.op[this_operand].regs
1068
405
    || intel_state.base
1069
398
    || intel_state.index
1070
396
    || intel_state.is_mem > 1)
1071
9
  jumpabsolute = true;
1072
396
      else
1073
396
  switch (intel_state.op_modifier)
1074
396
    {
1075
0
    case O_near_ptr:
1076
0
      if (intel_state.seg)
1077
0
        jumpabsolute = true;
1078
0
      else
1079
0
        intel_state.is_mem = 1;
1080
0
      break;
1081
0
    case O_far_ptr:
1082
396
    case O_absent:
1083
396
      if (!intel_state.seg)
1084
309
        {
1085
309
    intel_state.is_mem = 1;
1086
309
    if (intel_state.op_modifier == O_absent)
1087
309
      {
1088
309
        if (intel_state.is_indirect == 1)
1089
0
          jumpabsolute = true;
1090
309
        break;
1091
309
      }
1092
0
    as_bad (_("cannot infer the segment part of the operand"));
1093
0
    return 0;
1094
309
        }
1095
87
      else if (S_GET_SEGMENT (intel_state.seg) == reg_section)
1096
64
        {
1097
64
    jumpabsolute = true;
1098
64
    if (intel_state.op_modifier == O_far_ptr)
1099
0
      i.far_branch = true;
1100
64
        }
1101
23
      else
1102
23
        {
1103
23
    i386_operand_type types;
1104
1105
23
    if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
1106
1
      {
1107
1
        as_bad (_("at most %d immediate operands are allowed"),
1108
1
          MAX_IMMEDIATE_OPERANDS);
1109
1
        return 0;
1110
1
      }
1111
22
    expP = &im_expressions[i.imm_operands++];
1112
22
    memset (expP, 0, sizeof(*expP));
1113
22
    expP->X_op = O_symbol;
1114
22
    expP->X_add_symbol = intel_state.seg;
1115
22
    i.op[this_operand].imms = expP;
1116
1117
22
    resolve_expression (expP);
1118
22
    operand_type_set (&types, ~0);
1119
22
    if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state.seg),
1120
22
                expP, types, operand_string))
1121
0
      return 0;
1122
22
    if (i.operands < MAX_OPERANDS)
1123
22
      {
1124
22
        this_operand = i.operands++;
1125
22
        i.types[this_operand].bitfield.unspecified = 1;
1126
22
      }
1127
22
    intel_state.seg = NULL;
1128
22
    intel_state.is_mem = 0;
1129
22
        }
1130
86
      break;
1131
86
    default:
1132
0
      jumpabsolute = true;
1133
0
      break;
1134
396
    }
1135
404
      if (jumpabsolute)
1136
73
  {
1137
73
    i.jumpabsolute = true;
1138
73
    intel_state.is_mem |= 1;
1139
73
  }
1140
404
    }
1141
19.9k
  else if (intel_state.seg)
1142
106
    intel_state.is_mem |= 1;
1143
1144
20.3k
  if (i.op[this_operand].regs)
1145
2.88k
    {
1146
2.88k
      i386_operand_type temp;
1147
1148
      /* Register operand.  */
1149
2.88k
      if (intel_state.base || intel_state.index || intel_state.seg
1150
2.88k
          || i.imm_bits[this_operand])
1151
0
  {
1152
0
    as_bad (_("invalid operand"));
1153
0
    return 0;
1154
0
  }
1155
1156
2.88k
      temp = i.op[this_operand].regs->reg_type;
1157
2.88k
      temp.bitfield.baseindex = 0;
1158
2.88k
      i.types[this_operand] = operand_type_or (i.types[this_operand],
1159
2.88k
                 temp);
1160
2.88k
      i.types[this_operand].bitfield.unspecified = 0;
1161
2.88k
      ++i.reg_operands;
1162
1163
2.88k
      if ((i.rounding.type != rc_none && !i.rounding.modifier
1164
0
     && temp.bitfield.class != Reg)
1165
2.88k
    || rc_sae_modifier)
1166
0
  {
1167
0
    unsigned int j;
1168
1169
0
    for (j = 0; j < ARRAY_SIZE (RC_NamesTable); ++j)
1170
0
      if (i.rounding.type == RC_NamesTable[j].type)
1171
0
        break;
1172
0
    as_bad (_("`%s': misplaced `{%s}'"),
1173
0
      insn_name (current_templates.start), RC_NamesTable[j].name);
1174
0
    return 0;
1175
0
  }
1176
2.88k
    }
1177
17.5k
  else if (intel_state.base
1178
17.4k
     || intel_state.index
1179
17.4k
     || intel_state.seg
1180
17.3k
     || intel_state.is_mem)
1181
4.93k
    {
1182
      /* Memory operand.  */
1183
4.93k
      if (i.imm_bits[this_operand])
1184
0
  {
1185
0
    as_bad (_("invalid operand"));
1186
0
    return 0;
1187
0
  }
1188
1189
4.93k
      if (i.mem_operands)
1190
153
  {
1191
    /* Handle
1192
1193
       call 0x9090,0x90909090
1194
       lcall  0x9090,0x90909090
1195
       jmp  0x9090,0x90909090
1196
       ljmp 0x9090,0x90909090
1197
     */
1198
1199
153
    if (current_templates.start->opcode_modifier.jump
1200
17
        && this_operand == 1
1201
17
        && intel_state.seg == NULL
1202
17
        && i.mem_operands == 1
1203
17
        && i.disp_operands == 1
1204
17
        && intel_state.op_modifier == O_absent)
1205
17
      {
1206
        /* Try to process the first operand as immediate,  */
1207
17
        this_operand = 0;
1208
17
        if (i386_finalize_immediate (exp_seg, i.op[0].imms,
1209
17
             intel_state.reloc_types,
1210
17
             NULL))
1211
17
    {
1212
17
      this_operand = 1;
1213
17
      expP = &im_expressions[0];
1214
17
      i.op[this_operand].imms = expP;
1215
17
      *expP = exp;
1216
1217
      /* Try to process the second operand as immediate,  */
1218
17
      if (i386_finalize_immediate (exp_seg, expP,
1219
17
                 intel_state.reloc_types,
1220
17
                 NULL))
1221
17
        {
1222
17
          i.mem_operands = 0;
1223
17
          i.disp_operands = 0;
1224
17
          i.imm_operands = 2;
1225
17
          i.flags[0] &= ~Operand_Mem;
1226
17
          i.types[0].bitfield.disp16 = 0;
1227
17
          i.types[0].bitfield.disp32 = 0;
1228
17
          return 1;
1229
17
        }
1230
17
    }
1231
17
      }
1232
153
  }
1233
1234
      /* Swap base and index in 16-bit memory operands like
1235
   [si+bx]. Since i386_index_check is also used in AT&T
1236
   mode we have to do this here.  */
1237
4.91k
      if (intel_state.base
1238
7
    && intel_state.index
1239
0
    && intel_state.base->reg_type.bitfield.word
1240
0
    && intel_state.index->reg_type.bitfield.word
1241
0
    && intel_state.base->reg_num >= 6
1242
0
    && intel_state.index->reg_num < 6)
1243
0
  {
1244
0
    i.base_reg = intel_state.index;
1245
0
    i.index_reg = intel_state.base;
1246
0
  }
1247
4.91k
      else
1248
4.91k
  {
1249
4.91k
    i.base_reg = intel_state.base;
1250
4.91k
    i.index_reg = intel_state.index;
1251
4.91k
  }
1252
1253
4.91k
      if (i.base_reg || i.index_reg)
1254
11
  i.types[this_operand].bitfield.baseindex = 1;
1255
1256
4.91k
      expP = &disp_expressions[i.disp_operands];
1257
4.91k
      memcpy (expP, &exp, sizeof(exp));
1258
4.91k
      resolve_expression (expP);
1259
1260
4.91k
      if (expP->X_op != O_constant
1261
250
    || expP->X_add_number
1262
229
    || !i.types[this_operand].bitfield.baseindex)
1263
4.91k
  {
1264
4.91k
    i.op[this_operand].disps = expP;
1265
4.91k
    i.disp_operands++;
1266
1267
4.91k
    i386_addressing_mode ();
1268
1269
4.91k
    if (flag_code == CODE_64BIT)
1270
4.49k
      {
1271
4.49k
        i.types[this_operand].bitfield.disp32 = 1;
1272
4.49k
        if (!i.prefix[ADDR_PREFIX])
1273
4.49k
    i.types[this_operand].bitfield.disp64 = 1;
1274
4.49k
      }
1275
423
    else if (!i.prefix[ADDR_PREFIX] ^ (flag_code == CODE_16BIT))
1276
352
      i.types[this_operand].bitfield.disp32 = 1;
1277
71
    else
1278
71
      i.types[this_operand].bitfield.disp16 = 1;
1279
1280
#ifdef OBJ_AOUT
1281
    /*
1282
     * exp_seg is used only for verification in
1283
     * i386_finalize_displacement, and we can end up seeing reg_section
1284
     * here - but we know we removed all registers from the expression
1285
     * (or error-ed on any remaining ones) in i386_intel_simplify.  I
1286
     * consider the check in i386_finalize_displacement bogus anyway, in
1287
     * particular because it doesn't allow for expr_section, so I'd
1288
     * rather see that check (and the similar one in
1289
     * i386_finalize_immediate) use SEG_NORMAL(), but not being an a.out
1290
     * expert I can't really say whether that would have other bad side
1291
     * effects.
1292
     */
1293
    if (OUTPUT_FLAVOR == bfd_target_aout_flavour
1294
        && exp_seg == reg_section)
1295
      exp_seg = expP->X_op != O_constant ? undefined_section
1296
                 : absolute_section;
1297
#endif
1298
1299
4.91k
    if (!i386_finalize_displacement (exp_seg, expP,
1300
4.91k
             intel_state.reloc_types,
1301
4.91k
             operand_string))
1302
0
      return 0;
1303
4.91k
  }
1304
1305
4.91k
      if (intel_state.seg)
1306
170
  {
1307
170
    for (ret = check_none; ; ret = operand_check)
1308
173
      {
1309
173
        expP = symbol_get_value_expression (intel_state.seg);
1310
173
        if (expP->X_op != O_full_ptr 
1311
7
      || symbol_get_value_expression (expP->X_op_symbol)->X_op
1312
7
         != O_register)
1313
170
    break;
1314
3
        intel_state.seg = expP->X_add_symbol;
1315
3
      }
1316
170
    if (expP->X_op != O_register)
1317
86
      {
1318
86
        as_bad (_("segment register name expected"));
1319
86
        return 0;
1320
86
      }
1321
84
    if (i386_regtab[expP->X_add_number].reg_type.bitfield.class != SReg)
1322
6
      {
1323
6
        as_bad (_("invalid use of register"));
1324
6
        return 0;
1325
6
      }
1326
78
    switch (ret)
1327
78
      {
1328
0
      case check_error:
1329
0
        as_bad (_("redundant segment overrides"));
1330
0
        return 0;
1331
0
      case check_warning:
1332
0
        as_warn (_("redundant segment overrides"));
1333
0
        break;
1334
78
      }
1335
78
    if (i386_regtab[expP->X_add_number].reg_num == RegFlat)
1336
0
      i.seg[i.mem_operands] = NULL;
1337
78
    else
1338
78
      i.seg[i.mem_operands] = &i386_regtab[expP->X_add_number];
1339
78
  }
1340
1341
4.82k
      if (!i386_index_check (operand_string))
1342
15
  return 0;
1343
1344
4.80k
      i.flags[this_operand] |= Operand_Mem;
1345
4.80k
      ++i.mem_operands;
1346
4.80k
    }
1347
12.5k
  else
1348
12.5k
    {
1349
      /* Immediate.  */
1350
12.5k
      if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
1351
0
  {
1352
0
    as_bad (_("at most %d immediate operands are allowed"),
1353
0
      MAX_IMMEDIATE_OPERANDS);
1354
0
    return 0;
1355
0
  }
1356
1357
12.5k
      expP = &im_expressions[i.imm_operands++];
1358
12.5k
      i.op[this_operand].imms = expP;
1359
12.5k
      *expP = exp;
1360
1361
12.5k
      return i386_finalize_immediate (exp_seg, expP, intel_state.reloc_types,
1362
12.5k
              operand_string);
1363
12.5k
    }
1364
1365
7.69k
  return 1;
1366
20.3k
}