Coverage Report

Created: 2026-09-14 08:07

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