Coverage Report

Created: 2026-11-21 09:00

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