Coverage Report

Created: 2026-10-02 09:53

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
14
#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
0
#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
164k
{
124
164k
  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
164k
  if (!intel_syntax)
137
12.2k
    return O_absent;
138
139
152k
  if (!name)
140
59.3k
    {
141
59.3k
      if (operands != 2)
142
0
  return O_illegal;
143
59.3k
      switch (*input_line_pointer)
144
59.3k
  {
145
1.25k
  case ':':
146
1.25k
    ++input_line_pointer;
147
1.25k
    return O_full_ptr;
148
347
  case '[':
149
347
    ++input_line_pointer;
150
347
    return O_index;
151
289
  case '@':
152
289
    if (this_operand >= 0 && i.reloc[this_operand] == NO_RELOC)
153
288
      {
154
288
        int adjust = 0;
155
288
        char *gotfree_input_line = lex_got (&i.reloc[this_operand],
156
288
              &adjust,
157
288
              &intel_state.reloc_types);
158
159
288
        if (!gotfree_input_line)
160
24
    break;
161
264
        free (gotfree_input_line);
162
264
        *input_line_pointer++ = '+';
163
264
        memset (input_line_pointer, '0', adjust - 1);
164
264
        input_line_pointer[adjust - 1] = ' ';
165
264
        return O_add;
166
288
      }
167
1
    break;
168
59.3k
  }
169
57.5k
      return O_illegal;
170
59.3k
    }
171
172
  /* See the quotation related comment in i386_parse_name().  */
173
92.7k
  if (*pc == '"')
174
17.1k
    return O_absent;
175
176
1.20M
  for (j = 0; i386_operators[j].name; ++j)
177
1.13M
    if (strcasecmp (i386_operators[j].name, name) == 0)
178
19
      {
179
19
  if (i386_operators[j].operands
180
19
      && i386_operators[j].operands != operands)
181
5
    return O_illegal;
182
14
  return i386_operators[j].op;
183
19
      }
184
185
1.05M
  for (j = 0; i386_types[j].name; ++j)
186
982k
    if (strcasecmp (i386_types[j].name, name) == 0)
187
13
      break;
188
189
75.5k
  if (i386_types[j].name && is_whitespace (*pc))
190
0
    {
191
0
      const char *start = ++input_line_pointer;
192
0
      char *pname;
193
0
      char c = get_symbol_name (&pname);
194
195
0
      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
0
      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
0
      (void) restore_line_pointer (c);
233
0
      input_line_pointer = pname - 1;
234
0
    }
235
236
75.5k
  return O_absent;
237
75.5k
}
238
239
static int i386_intel_parse_name (const char *name,
240
          expressionS *e,
241
          enum expr_mode mode)
242
46.2k
{
243
46.2k
  unsigned int j;
244
245
46.2k
  if (! strcmp (name, "$"))
246
3.74k
    {
247
3.74k
      current_location (e, mode);
248
3.74k
      return 1;
249
3.74k
    }
250
251
595k
  for (j = 0; i386_types[j].name; ++j)
252
553k
    if (strcasecmp(i386_types[j].name, name) == 0)
253
1
      {
254
1
  e->X_op = O_constant;
255
1
  e->X_add_number = i386_types[j].sz[flag_code];
256
1
  e->X_add_symbol = NULL;
257
1
  e->X_op_symbol = NULL;
258
1
  return 1;
259
1
      }
260
261
42.5k
  return 0;
262
42.5k
}
263
264
static INLINE int i386_intel_check (const reg_entry *rreg,
265
            const reg_entry *base,
266
            const reg_entry *iindex)
267
34.9k
{
268
34.9k
  if ((this_operand >= 0
269
26.1k
       && rreg != i.op[this_operand].regs)
270
32.6k
      || base != intel_state.base
271
32.6k
      || iindex != intel_state.index)
272
2.23k
    {
273
2.23k
      as_bad (_("invalid use of register"));
274
2.23k
      return 0;
275
2.23k
    }
276
32.6k
  return 1;
277
34.9k
}
278
279
static INLINE void i386_intel_fold (expressionS *e, symbolS *sym)
280
1.27k
{
281
1.27k
  expressionS *exp = symbol_get_value_expression (sym);
282
283
1.27k
  if (S_GET_SEGMENT (sym) == absolute_section
284
141
      || S_GET_SEGMENT (sym) == expr_section)
285
1.16k
    {
286
1.16k
      offsetT val = e->X_add_number;
287
288
1.16k
      *e = *exp;
289
1.16k
      e->X_add_number += val;
290
1.16k
    }
291
112
  else
292
112
    {
293
112
      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
112
      e->X_add_symbol = sym;
298
112
      e->X_op_symbol = NULL;
299
112
      e->X_op = O_symbol;
300
112
    }
301
1.27k
}
302
303
static int
304
i386_intel_simplify_register (expressionS *e)
305
5.97k
{
306
5.97k
  int reg_num;
307
308
5.97k
  if (this_operand < 0 || intel_state.in_offset)
309
756
    {
310
756
      as_bad (_("invalid use of register"));
311
756
      return 0;
312
756
    }
313
314
5.21k
  if (e->X_op == O_register)
315
5.21k
    reg_num = e->X_add_number;
316
0
  else
317
0
    reg_num = e->X_md - 1;
318
319
5.21k
  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
5.21k
  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
5.21k
  if (!intel_state.in_bracket)
333
5.18k
    {
334
5.18k
      if (i.op[this_operand].regs)
335
0
  {
336
0
    as_bad (_("invalid use of register"));
337
0
    return 0;
338
0
  }
339
5.18k
      if ((i386_regtab[reg_num].reg_type.bitfield.class == SReg
340
0
     && i386_regtab[reg_num].reg_num == RegFlat)
341
5.18k
    || (dot_insn ()
342
1.66k
        && 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
5.18k
      i.op[this_operand].regs = i386_regtab + reg_num;
348
5.18k
    }
349
38
  else if (!intel_state.index
350
35
     && (i386_regtab[reg_num].reg_type.bitfield.xmmword
351
35
         || i386_regtab[reg_num].reg_type.bitfield.ymmword
352
35
         || i386_regtab[reg_num].reg_type.bitfield.zmmword
353
35
         || i386_regtab[reg_num].reg_num == RegIZ))
354
0
    intel_state.index = i386_regtab + reg_num;
355
38
  else if (!intel_state.base && !intel_state.in_scale)
356
26
    intel_state.base = i386_regtab + reg_num;
357
12
  else if (!intel_state.index)
358
12
    {
359
12
      const insn_template *t = current_templates.start;
360
361
12
      if (intel_state.in_scale
362
4
    || 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
11
  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
12
    }
375
0
  else
376
0
    {
377
      /* esp is invalid as index */
378
0
      intel_state.index = reg_eax + ESP_REG_NUM;
379
0
    }
380
5.21k
  return 2;
381
5.21k
}
382
383
static symbolS *
384
i386_intel_simplify_symbol (symbolS *sym)
385
24.4k
{
386
24.4k
  if (symbol_resolving_p (sym))
387
0
    return NULL;
388
389
24.4k
  symbolS *orig = sym;
390
24.4k
  offsetT off;
391
24.4k
  sym = symbol_equated_to (sym, &off);
392
24.4k
  if (sym == NULL)
393
1
    return NULL;
394
24.4k
  if (off != 0)
395
3
    return orig;
396
397
24.4k
  segT seg = S_GET_SEGMENT (sym);
398
24.4k
  if (seg == undefined_section
399
14.8k
      || (seg != expr_section && seg != reg_section && sym == orig))
400
16.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
7.92k
  expressionS *e = symbol_get_value_expression (sym);
411
7.92k
  expressionS exp;
412
7.92k
  memcpy (&exp, e, sizeof exp);
413
7.92k
  symbol_mark_resolving (sym);
414
7.92k
  int ret = i386_intel_simplify (&exp);
415
7.92k
  symbol_clear_resolving (sym);
416
7.92k
  if (ret == 0)
417
1.91k
    return NULL;
418
419
6.01k
  if (memcmp (&exp, e, sizeof exp) != 0)
420
2.42k
    sym = make_expr_symbol (&exp);
421
6.01k
  return sym;
422
7.92k
}
423
424
static int
425
i386_intel_simplify (expressionS *e)
426
26.7k
{
427
26.7k
  const reg_entry *the_reg = (this_operand >= 0
428
26.7k
            ? i.op[this_operand].regs : NULL);
429
26.7k
  const reg_entry *base = intel_state.base;
430
26.7k
  const reg_entry *state_index = intel_state.index;
431
26.7k
  symbolS *newsym;
432
26.7k
  int ret;
433
434
26.7k
  if (!intel_syntax)
435
0
    return 1;
436
437
26.7k
  switch (e->X_op)
438
26.7k
    {
439
205
    case O_index:
440
205
      if (e->X_add_symbol)
441
205
  {
442
205
    newsym = i386_intel_simplify_symbol (e->X_add_symbol);
443
205
    if (!newsym
444
200
        || !i386_intel_check(the_reg, intel_state.base,
445
200
           intel_state.index))
446
5
      return 0;
447
200
    e->X_add_symbol = newsym;
448
200
  }
449
200
      if (!intel_state.in_offset)
450
200
  ++intel_state.in_bracket;
451
200
      newsym = i386_intel_simplify_symbol (e->X_op_symbol);
452
200
      if (!intel_state.in_offset)
453
200
  --intel_state.in_bracket;
454
200
      if (!newsym)
455
1
  return 0;
456
199
      e->X_op_symbol = newsym;
457
199
      if (!e->X_add_symbol)
458
0
  i386_intel_fold (e, e->X_op_symbol);
459
199
      else if (S_GET_SEGMENT (e->X_add_symbol) == expr_section
460
45
         && (S_GET_SEGMENT (e->X_op_symbol) == absolute_section
461
22
       || S_GET_SEGMENT (e->X_op_symbol) == expr_section)
462
25
         && symbol_get_value_expression (e->X_op_symbol)->X_op
463
25
      == O_constant)
464
23
  {
465
23
    offsetT val
466
23
      = symbol_get_value_expression (e->X_op_symbol)->X_add_number;
467
468
23
    i386_intel_fold (e, e->X_add_symbol);
469
23
    e->X_add_number += val;
470
23
  }
471
176
      else
472
176
  e->X_op = O_add;
473
199
      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
14
    case O_short:
501
14
      if (symbol_get_value_expression (e->X_add_symbol)->X_op
502
14
    == O_register)
503
0
  {
504
0
    as_bad (_("invalid use of register"));
505
0
    return 0;
506
0
  }
507
14
      newsym = i386_intel_simplify_symbol (e->X_add_symbol);
508
14
      if (!newsym)
509
0
  return 0;
510
14
      e->X_add_symbol = newsym;
511
14
      i386_intel_fold (e, e->X_add_symbol);
512
14
      break;
513
514
1.24k
    case O_full_ptr:
515
1.24k
      if (symbol_get_value_expression (e->X_op_symbol)->X_op
516
1.24k
    == O_register)
517
34
  {
518
34
    as_bad (_("invalid use of register"));
519
34
    return 0;
520
34
  }
521
1.20k
      newsym = i386_intel_simplify_symbol (e->X_op_symbol);
522
1.20k
      if (!newsym
523
1.20k
    || !i386_intel_check(the_reg, intel_state.base,
524
1.20k
             intel_state.index))
525
0
  return 0;
526
1.20k
      e->X_op_symbol = newsym;
527
1.20k
      if (!intel_state.in_offset)
528
1.20k
  {
529
1.20k
    if (!intel_state.seg)
530
1.20k
      intel_state.seg = e->X_add_symbol;
531
3
    else
532
3
      {
533
3
        expressionS exp = {
534
3
    .X_op = O_full_ptr,
535
3
    .X_add_symbol = e->X_add_symbol,
536
3
    .X_op_symbol = intel_state.seg
537
3
        };
538
3
        intel_state.seg = make_expr_symbol (&exp);
539
3
      }
540
1.20k
  }
541
1.20k
      i386_intel_fold (e, e->X_op_symbol);
542
1.20k
      break;
543
544
2.29k
    case O_add:
545
2.29k
      if (this_operand >= 0 && intel_state.in_bracket)
546
38
  {
547
38
    expressionS *left = NULL, *right = NULL;
548
38
    segT leftseg = NULL, rightseg = NULL;
549
550
38
    newsym = i386_intel_simplify_symbol (e->X_add_symbol);
551
38
    if (!newsym)
552
0
      return 0;
553
38
    e->X_add_symbol = newsym;
554
555
38
    if (base != intel_state.base || state_index != intel_state.index)
556
32
      {
557
32
        base = intel_state.base;
558
32
        state_index = intel_state.index;
559
32
        left = symbol_get_value_expression (newsym);
560
32
        resolve_expression (left);
561
32
        leftseg = S_GET_SEGMENT (newsym);
562
32
      }
563
564
38
    newsym = i386_intel_simplify_symbol (e->X_op_symbol);
565
38
    if (!newsym)
566
1
      return 0;
567
37
    e->X_op_symbol = newsym;
568
569
37
    if (base != intel_state.base || state_index != intel_state.index)
570
16
      {
571
16
        base = intel_state.base;
572
16
        state_index = intel_state.index;
573
16
        right = symbol_get_value_expression (newsym);
574
16
        resolve_expression (right);
575
16
        rightseg = S_GET_SEGMENT (newsym);
576
16
      }
577
578
37
    if (left && right
579
12
        && (leftseg == absolute_section || leftseg == expr_section)
580
10
        && left->X_op == O_constant
581
9
        && (rightseg == absolute_section || rightseg == expr_section)
582
9
        && right->X_op == O_constant)
583
6
      {
584
6
         e->X_op = O_constant;
585
6
         e->X_add_number += left->X_add_number + right->X_add_number;
586
6
         e->X_add_symbol = NULL;
587
6
         e->X_op_symbol = NULL;
588
6
      }
589
31
    else if (left
590
26
       && (leftseg == absolute_section || leftseg == expr_section)
591
23
       && left->X_op == O_constant)
592
22
      i386_intel_fold (e, e->X_op_symbol);
593
9
    else if (right
594
7
       && (rightseg == absolute_section || rightseg == expr_section)
595
7
       && right->X_op == O_constant)
596
7
      i386_intel_fold (e, e->X_add_symbol);
597
37
  }
598
2.29k
      goto fallthrough;
599
600
2.29k
    case O_multiply:
601
115
      if (this_operand >= 0 && intel_state.in_bracket)
602
24
  {
603
24
    expressionS *scale = NULL, *other = NULL;
604
24
    int has_index = (intel_state.index != NULL);
605
606
24
    if (!intel_state.in_scale++)
607
13
      intel_state.scale_factor = 1;
608
609
24
    newsym = i386_intel_simplify_symbol (e->X_add_symbol);
610
24
    if (newsym)
611
24
      {
612
24
        e->X_add_symbol = newsym;
613
614
24
        if (!has_index && intel_state.index)
615
8
    {
616
8
      scale = symbol_get_value_expression (e->X_op_symbol);
617
8
      other = symbol_get_value_expression (e->X_add_symbol);
618
8
    }
619
620
24
        newsym = i386_intel_simplify_symbol (e->X_op_symbol);
621
24
      }
622
623
24
    if (newsym)
624
24
      {
625
24
        e->X_op_symbol = newsym;
626
627
24
        if (!scale && !has_index && intel_state.index)
628
5
    {
629
5
      scale = symbol_get_value_expression (e->X_add_symbol);
630
5
      other = symbol_get_value_expression (e->X_op_symbol);
631
5
    }
632
24
      }
633
634
24
    if (newsym && scale)
635
13
      {
636
13
        segT seg;
637
638
13
        resolve_expression (scale);
639
13
        if (scale->X_op != O_constant
640
12
      || intel_state.index->reg_type.bitfield.word)
641
1
    scale->X_add_number = 0;
642
13
        intel_state.scale_factor *= scale->X_add_number;
643
644
13
        resolve_expression (other);
645
13
        seg = S_GET_SEGMENT (newsym);
646
13
        if ((seg == absolute_section || seg == expr_section)
647
10
      && other->X_op == O_constant
648
10
      && other->X_add_number == 0)
649
10
    {
650
10
      e->X_op = O_constant;
651
10
      e->X_add_symbol = NULL;
652
10
      e->X_op_symbol = NULL;
653
10
    }
654
13
      }
655
656
24
    --intel_state.in_scale;
657
24
    if (!newsym)
658
0
      return 0;
659
660
24
    if (!intel_state.in_scale)
661
13
      switch (intel_state.scale_factor)
662
13
        {
663
5
        case 1:
664
5
    i.log2_scale_factor = 0;
665
5
    break;
666
0
        case 2:
667
0
    i.log2_scale_factor = 1;
668
0
    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
8
        default:
676
    /* esp is invalid as index */
677
8
    intel_state.index = reg_eax + ESP_REG_NUM;
678
8
    break;
679
13
        }
680
681
24
    break;
682
24
  }
683
91
      goto fallthrough;
684
685
5.97k
    case O_register:
686
5.97k
      ret = i386_intel_simplify_register (e);
687
5.97k
      if (ret == 2)
688
5.21k
  {
689
5.21k
    gas_assert (e->X_add_number < (unsigned short) -1);
690
5.21k
    e->X_md = (unsigned short) e->X_add_number + 1;
691
5.21k
    e->X_op = O_constant;
692
5.21k
    e->X_add_number = 0;
693
5.21k
  }
694
5.97k
      return ret;
695
696
1.30k
    case O_constant:
697
1.30k
      if (e->X_md)
698
0
  return i386_intel_simplify_register (e);
699
700
      /* FALLTHROUGH */
701
16.9k
    default:
702
19.3k
    fallthrough:
703
19.3k
      if (e->X_add_symbol)
704
17.9k
  {
705
17.9k
    newsym = i386_intel_simplify_symbol (e->X_add_symbol);
706
17.9k
    if (!newsym)
707
962
      return 0;
708
16.9k
    e->X_add_symbol = newsym;
709
16.9k
  }
710
18.3k
      if (!the_reg && this_operand >= 0
711
13.4k
    && e->X_op == O_symbol && !e->X_add_number)
712
6.21k
  the_reg = i.op[this_operand].regs;
713
18.3k
      if (e->X_op == O_add || e->X_op == O_subtract)
714
3.40k
  {
715
3.40k
    base = intel_state.base;
716
3.40k
    state_index = intel_state.index;
717
3.40k
  }
718
18.3k
      if (!i386_intel_check (the_reg, base, state_index))
719
2.23k
  return 0;
720
16.1k
      if (e->X_op_symbol)
721
4.81k
  {
722
4.81k
    newsym = i386_intel_simplify_symbol (e->X_op_symbol);
723
4.81k
    if (!newsym)
724
948
      return 0;
725
3.86k
    e->X_op_symbol = newsym;
726
3.86k
  }
727
15.1k
      if (!i386_intel_check (the_reg,
728
15.1k
           e->X_op != O_add ? base : intel_state.base,
729
15.1k
           (e->X_op != O_add ? state_index
730
15.1k
                 : intel_state.index)))
731
4
  return 0;
732
15.1k
      break;
733
26.7k
    }
734
735
16.6k
  if (this_operand >= 0
736
12.6k
      && e->X_op == O_symbol
737
8.89k
      && !intel_state.has_offset)
738
8.89k
    {
739
8.89k
      segT seg = S_GET_SEGMENT (e->X_add_symbol);
740
741
8.89k
      if (seg != absolute_section
742
8.89k
    && seg != reg_section
743
8.89k
    && seg != expr_section)
744
8.89k
  intel_state.is_mem |= 2 - !intel_state.in_bracket;
745
8.89k
    }
746
747
16.6k
  return 1;
748
26.7k
}
749
750
int i386_need_index_operator (void)
751
52
{
752
52
  return intel_syntax < 0;
753
52
}
754
755
static int
756
i386_intel_operand (char *operand_string, int got_a_float)
757
17.5k
{
758
17.5k
  char *saved_input_line_pointer, *buf;
759
17.5k
  segT exp_seg;
760
17.5k
  expressionS exp, *expP;
761
17.5k
  char suffix = 0;
762
17.5k
  bool rc_sae_modifier = i.rounding.type != rc_none && i.rounding.modifier;
763
17.5k
  int ret;
764
765
  /* Handle vector immediates.  */
766
17.5k
  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
17.5k
  intel_state.op_modifier = O_absent;
780
17.5k
  intel_state.is_mem = 0;
781
17.5k
  intel_state.is_indirect = 0;
782
17.5k
  intel_state.has_offset = 0;
783
17.5k
  intel_state.base = NULL;
784
17.5k
  intel_state.index = NULL;
785
17.5k
  intel_state.seg = NULL;
786
17.5k
  operand_type_set (&intel_state.reloc_types, ~0);
787
17.5k
  gas_assert (!intel_state.in_offset);
788
17.5k
  gas_assert (!intel_state.in_bracket);
789
17.5k
  gas_assert (!intel_state.in_scale);
790
791
17.5k
  saved_input_line_pointer = input_line_pointer;
792
17.5k
  input_line_pointer = buf = xstrdup (operand_string);
793
794
17.5k
  intel_syntax = -1;
795
17.5k
  expr_mode = expr_operator_none;
796
17.5k
  memset (&exp, 0, sizeof(exp));
797
17.5k
  exp_seg = expression (&exp);
798
17.5k
  ret = i386_intel_simplify (&exp);
799
17.5k
  intel_syntax = 1;
800
801
17.5k
  SKIP_WHITESPACE ();
802
803
  /* Handle vector operations.  */
804
17.5k
  if (*input_line_pointer == '{')
805
3.39k
    {
806
3.39k
      char *end = check_VecOperations (input_line_pointer);
807
3.39k
      if (end)
808
26
  input_line_pointer = end;
809
3.36k
      else
810
3.36k
  ret = 0;
811
3.39k
    }
812
813
17.5k
  if (!is_end_of_stmt (*input_line_pointer))
814
6.15k
    {
815
6.15k
      if (ret)
816
2.78k
  as_bad (_("junk `%s' after expression"), input_line_pointer);
817
6.15k
      ret = 0;
818
6.15k
    }
819
11.4k
  else if (exp.X_op == O_illegal || exp.X_op == O_absent)
820
2
    {
821
2
      if (ret)
822
2
  as_bad (_("invalid expression"));
823
2
      ret = 0;
824
2
    }
825
11.4k
  else if (!intel_state.has_offset
826
11.4k
     && input_line_pointer > buf
827
11.4k
     && *(input_line_pointer - 1) == ']')
828
0
    {
829
0
      intel_state.is_mem |= 1;
830
0
      intel_state.is_indirect = 1;
831
0
    }
832
833
17.5k
  input_line_pointer = saved_input_line_pointer;
834
17.5k
  free (buf);
835
836
17.5k
  gas_assert (!intel_state.in_offset);
837
17.5k
  gas_assert (!intel_state.in_bracket);
838
17.5k
  gas_assert (!intel_state.in_scale);
839
840
17.5k
  if (!ret)
841
6.19k
    return 0;
842
843
11.4k
  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
11.4k
  if (current_templates.start->opcode_modifier.jump
1055
11.3k
      || current_templates.start->mnem_off == MN_jmpabs)
1056
72
    {
1057
72
      bool jumpabsolute = false;
1058
1059
72
      if (i.op[this_operand].regs
1060
72
    || intel_state.base
1061
48
    || intel_state.index
1062
48
    || intel_state.is_mem > 1)
1063
24
  jumpabsolute = true;
1064
48
      else
1065
48
  switch (intel_state.op_modifier)
1066
48
    {
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
48
    case O_absent:
1075
48
      if (!intel_state.seg)
1076
48
        {
1077
48
    intel_state.is_mem = 1;
1078
48
    if (intel_state.op_modifier == O_absent)
1079
48
      {
1080
48
        if (intel_state.is_indirect == 1)
1081
0
          jumpabsolute = true;
1082
48
        break;
1083
48
      }
1084
0
    as_bad (_("cannot infer the segment part of the operand"));
1085
0
    return 0;
1086
48
        }
1087
0
      else if (S_GET_SEGMENT (intel_state.seg) == reg_section)
1088
0
        {
1089
0
    jumpabsolute = true;
1090
0
    if (intel_state.op_modifier == O_far_ptr)
1091
0
      i.far_branch = true;
1092
0
        }
1093
0
      else
1094
0
        {
1095
0
    i386_operand_type types;
1096
1097
0
    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
0
    expP = &im_expressions[i.imm_operands++];
1104
0
    memset (expP, 0, sizeof(*expP));
1105
0
    expP->X_op = O_symbol;
1106
0
    expP->X_add_symbol = intel_state.seg;
1107
0
    i.op[this_operand].imms = expP;
1108
1109
0
    resolve_expression (expP);
1110
0
    operand_type_set (&types, ~0);
1111
0
    if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state.seg),
1112
0
                expP, types, operand_string))
1113
0
      return 0;
1114
0
    if (i.operands < MAX_OPERANDS)
1115
0
      {
1116
0
        this_operand = i.operands++;
1117
0
        i.types[this_operand].bitfield.unspecified = 1;
1118
0
      }
1119
0
    intel_state.seg = NULL;
1120
0
    intel_state.is_mem = 0;
1121
0
        }
1122
0
      break;
1123
0
    default:
1124
0
      jumpabsolute = true;
1125
0
      break;
1126
48
    }
1127
72
      if (jumpabsolute)
1128
24
  {
1129
24
    i.jumpabsolute = true;
1130
24
    intel_state.is_mem |= 1;
1131
24
  }
1132
72
    }
1133
11.3k
  else if (intel_state.seg)
1134
1.20k
    intel_state.is_mem |= 1;
1135
1136
11.4k
  if (i.op[this_operand].regs)
1137
2.94k
    {
1138
2.94k
      i386_operand_type temp;
1139
1140
      /* Register operand.  */
1141
2.94k
      if (intel_state.base || intel_state.index || intel_state.seg
1142
2.94k
          || i.imm_bits[this_operand])
1143
0
  {
1144
0
    as_bad (_("invalid operand"));
1145
0
    return 0;
1146
0
  }
1147
1148
2.94k
      temp = i.op[this_operand].regs->reg_type;
1149
2.94k
      temp.bitfield.baseindex = 0;
1150
2.94k
      i.types[this_operand] = operand_type_or (i.types[this_operand],
1151
2.94k
                 temp);
1152
2.94k
      i.types[this_operand].bitfield.unspecified = 0;
1153
2.94k
      ++i.reg_operands;
1154
1155
2.94k
      if ((i.rounding.type != rc_none && !i.rounding.modifier
1156
0
     && temp.bitfield.class != Reg)
1157
2.94k
    || 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.94k
    }
1169
8.45k
  else if (intel_state.base
1170
8.43k
     || intel_state.index
1171
8.43k
     || intel_state.seg
1172
7.22k
     || intel_state.is_mem)
1173
6.91k
    {
1174
      /* Memory operand.  */
1175
6.91k
      if (i.imm_bits[this_operand])
1176
0
  {
1177
0
    as_bad (_("invalid operand"));
1178
0
    return 0;
1179
0
  }
1180
1181
6.91k
      if (i.mem_operands)
1182
183
  {
1183
    /* Handle
1184
1185
       call 0x9090,0x90909090
1186
       lcall  0x9090,0x90909090
1187
       jmp  0x9090,0x90909090
1188
       ljmp 0x9090,0x90909090
1189
     */
1190
1191
183
    if (current_templates.start->opcode_modifier.jump
1192
8
        && this_operand == 1
1193
8
        && intel_state.seg == NULL
1194
8
        && i.mem_operands == 1
1195
8
        && i.disp_operands == 1
1196
8
        && intel_state.op_modifier == O_absent)
1197
8
      {
1198
        /* Try to process the first operand as immediate,  */
1199
8
        this_operand = 0;
1200
8
        if (i386_finalize_immediate (exp_seg, i.op[0].imms,
1201
8
             intel_state.reloc_types,
1202
8
             NULL))
1203
8
    {
1204
8
      this_operand = 1;
1205
8
      expP = &im_expressions[0];
1206
8
      i.op[this_operand].imms = expP;
1207
8
      *expP = exp;
1208
1209
      /* Try to process the second operand as immediate,  */
1210
8
      if (i386_finalize_immediate (exp_seg, expP,
1211
8
                 intel_state.reloc_types,
1212
8
                 NULL))
1213
8
        {
1214
8
          i.mem_operands = 0;
1215
8
          i.disp_operands = 0;
1216
8
          i.imm_operands = 2;
1217
8
          i.flags[0] &= ~Operand_Mem;
1218
8
          i.types[0].bitfield.disp16 = 0;
1219
8
          i.types[0].bitfield.disp32 = 0;
1220
8
          return 1;
1221
8
        }
1222
8
    }
1223
8
      }
1224
183
  }
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
6.90k
      if (intel_state.base
1230
23
    && intel_state.index
1231
11
    && intel_state.base->reg_type.bitfield.word
1232
1
    && 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
6.90k
      else
1240
6.90k
  {
1241
6.90k
    i.base_reg = intel_state.base;
1242
6.90k
    i.index_reg = intel_state.index;
1243
6.90k
  }
1244
1245
6.90k
      if (i.base_reg || i.index_reg)
1246
23
  i.types[this_operand].bitfield.baseindex = 1;
1247
1248
6.90k
      expP = &disp_expressions[i.disp_operands];
1249
6.90k
      memcpy (expP, &exp, sizeof(exp));
1250
6.90k
      resolve_expression (expP);
1251
1252
6.90k
      if (expP->X_op != O_constant
1253
1.14k
    || expP->X_add_number
1254
1.14k
    || !i.types[this_operand].bitfield.baseindex)
1255
6.90k
  {
1256
6.90k
    i.op[this_operand].disps = expP;
1257
6.90k
    i.disp_operands++;
1258
1259
6.90k
    i386_addressing_mode ();
1260
1261
6.90k
    if (flag_code == CODE_64BIT)
1262
6.49k
      {
1263
6.49k
        i.types[this_operand].bitfield.disp32 = 1;
1264
6.49k
        if (!i.prefix[ADDR_PREFIX])
1265
6.49k
    i.types[this_operand].bitfield.disp64 = 1;
1266
6.49k
      }
1267
408
    else if (!i.prefix[ADDR_PREFIX] ^ (flag_code == CODE_16BIT))
1268
396
      i.types[this_operand].bitfield.disp32 = 1;
1269
12
    else
1270
12
      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
6.90k
    if (!i386_finalize_displacement (exp_seg, expP,
1292
6.90k
             intel_state.reloc_types,
1293
6.90k
             operand_string))
1294
0
      return 0;
1295
6.90k
  }
1296
1297
6.90k
      if (intel_state.seg)
1298
1.20k
  {
1299
1.20k
    for (ret = check_none; ; ret = operand_check)
1300
1.20k
      {
1301
1.20k
        expP = symbol_get_value_expression (intel_state.seg);
1302
1.20k
        if (expP->X_op != O_full_ptr 
1303
3
      || symbol_get_value_expression (expP->X_op_symbol)->X_op
1304
3
         != O_register)
1305
1.20k
    break;
1306
0
        intel_state.seg = expP->X_add_symbol;
1307
0
      }
1308
1.20k
    if (expP->X_op != O_register)
1309
78
      {
1310
78
        as_bad (_("segment register name expected"));
1311
78
        return 0;
1312
78
      }
1313
1.12k
    if (i386_regtab[expP->X_add_number].reg_type.bitfield.class != SReg)
1314
4
      {
1315
4
        as_bad (_("invalid use of register"));
1316
4
        return 0;
1317
4
      }
1318
1.12k
    switch (ret)
1319
1.12k
      {
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.12k
      }
1327
1.12k
    if (i386_regtab[expP->X_add_number].reg_num == RegFlat)
1328
0
      i.seg[i.mem_operands] = NULL;
1329
1.12k
    else
1330
1.12k
      i.seg[i.mem_operands] = &i386_regtab[expP->X_add_number];
1331
1.12k
  }
1332
1333
6.82k
      if (!i386_index_check (operand_string))
1334
23
  return 0;
1335
1336
6.80k
      i.flags[this_operand] |= Operand_Mem;
1337
6.80k
      ++i.mem_operands;
1338
6.80k
    }
1339
1.53k
  else
1340
1.53k
    {
1341
      /* Immediate.  */
1342
1.53k
      if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
1343
0
  {
1344
0
    as_bad (_("at most %d immediate operands are allowed"),
1345
0
      MAX_IMMEDIATE_OPERANDS);
1346
0
    return 0;
1347
0
  }
1348
1349
1.53k
      expP = &im_expressions[i.imm_operands++];
1350
1.53k
      i.op[this_operand].imms = expP;
1351
1.53k
      *expP = exp;
1352
1353
1.53k
      return i386_finalize_immediate (exp_seg, expP, intel_state.reloc_types,
1354
1.53k
              operand_string);
1355
1.53k
    }
1356
1357
9.75k
  return 1;
1358
11.4k
}