Coverage Report

Created: 2026-05-11 07:54

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
3
#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
4
#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
172k
{
124
172k
  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
172k
  if (!intel_syntax)
137
118k
    return O_absent;
138
139
54.0k
  if (!name)
140
27.5k
    {
141
27.5k
      if (operands != 2)
142
0
  return O_illegal;
143
27.5k
      switch (*input_line_pointer)
144
27.5k
  {
145
1.23k
  case ':':
146
1.23k
    ++input_line_pointer;
147
1.23k
    return O_full_ptr;
148
189
  case '[':
149
189
    ++input_line_pointer;
150
189
    return O_index;
151
264
  case '@':
152
264
    if (this_operand >= 0 && i.reloc[this_operand] == NO_RELOC)
153
27
      {
154
27
        int adjust = 0;
155
27
        char *gotfree_input_line = lex_got (&i.reloc[this_operand],
156
27
              &adjust,
157
27
              &intel_state.reloc_types);
158
159
27
        if (!gotfree_input_line)
160
4
    break;
161
23
        free (gotfree_input_line);
162
23
        *input_line_pointer++ = '+';
163
23
        memset (input_line_pointer, '0', adjust - 1);
164
23
        input_line_pointer[adjust - 1] = ' ';
165
23
        return O_add;
166
27
      }
167
237
    break;
168
27.5k
  }
169
26.1k
      return O_illegal;
170
27.5k
    }
171
172
  /* See the quotation related comment in i386_parse_name().  */
173
26.4k
  if (*pc == '"')
174
1.90k
    return O_absent;
175
176
392k
  for (j = 0; i386_operators[j].name; ++j)
177
367k
    if (strcasecmp (i386_operators[j].name, name) == 0)
178
18
      {
179
18
  if (i386_operators[j].operands
180
18
      && i386_operators[j].operands != operands)
181
12
    return O_illegal;
182
6
  return i386_operators[j].op;
183
18
      }
184
185
343k
  for (j = 0; i386_types[j].name; ++j)
186
318k
    if (strcasecmp (i386_types[j].name, name) == 0)
187
76
      break;
188
189
24.5k
  if (i386_types[j].name && is_whitespace (*pc))
190
7
    {
191
7
      const char *start = ++input_line_pointer;
192
7
      char *pname;
193
7
      char c = get_symbol_name (&pname);
194
195
7
      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
7
      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
7
      (void) restore_line_pointer (c);
233
7
      input_line_pointer = pname - 1;
234
7
    }
235
236
24.5k
  return O_absent;
237
24.5k
}
238
239
static int i386_intel_parse_name (const char *name,
240
          expressionS *e,
241
          enum expr_mode mode)
242
16.5k
{
243
16.5k
  unsigned int j;
244
245
16.5k
  if (! strcmp (name, "$"))
246
13
    {
247
13
      current_location (e, mode);
248
13
      return 1;
249
13
    }
250
251
231k
  for (j = 0; i386_types[j].name; ++j)
252
214k
    if (strcasecmp(i386_types[j].name, name) == 0)
253
13
      {
254
13
  e->X_op = O_constant;
255
13
  e->X_add_number = i386_types[j].sz[flag_code];
256
13
  e->X_add_symbol = NULL;
257
13
  e->X_op_symbol = NULL;
258
13
  return 1;
259
13
      }
260
261
16.5k
  return 0;
262
16.5k
}
263
264
static INLINE int i386_intel_check (const reg_entry *rreg,
265
            const reg_entry *base,
266
            const reg_entry *iindex)
267
21.1k
{
268
21.1k
  if ((this_operand >= 0
269
15.9k
       && rreg != i.op[this_operand].regs)
270
20.9k
      || base != intel_state.base
271
20.9k
      || iindex != intel_state.index)
272
204
    {
273
204
      as_bad (_("invalid use of register"));
274
204
      return 0;
275
204
    }
276
20.9k
  return 1;
277
21.1k
}
278
279
static INLINE void i386_intel_fold (expressionS *e, symbolS *sym)
280
432
{
281
432
  expressionS *exp = symbol_get_value_expression (sym);
282
283
432
  if (S_GET_SEGMENT (sym) == absolute_section
284
393
      || S_GET_SEGMENT (sym) == expr_section)
285
69
    {
286
69
      offsetT val = e->X_add_number;
287
288
69
      *e = *exp;
289
69
      e->X_add_number += val;
290
69
    }
291
363
  else
292
363
    {
293
363
      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
363
      e->X_add_symbol = sym;
298
363
      e->X_op_symbol = NULL;
299
363
      e->X_op = O_symbol;
300
363
    }
301
432
}
302
303
static int
304
i386_intel_simplify_register (expressionS *e)
305
557
{
306
557
  int reg_num;
307
308
557
  if (this_operand < 0 || intel_state.in_offset)
309
0
    {
310
0
      as_bad (_("invalid use of register"));
311
0
      return 0;
312
0
    }
313
314
557
  if (e->X_op == O_register)
315
557
    reg_num = e->X_add_number;
316
0
  else
317
0
    reg_num = e->X_md - 1;
318
319
557
  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
557
  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
557
  if (!intel_state.in_bracket)
333
551
    {
334
551
      if (i.op[this_operand].regs)
335
0
  {
336
0
    as_bad (_("invalid use of register"));
337
0
    return 0;
338
0
  }
339
551
      if ((i386_regtab[reg_num].reg_type.bitfield.class == SReg
340
218
     && i386_regtab[reg_num].reg_num == RegFlat)
341
550
    || (dot_insn ()
342
20
        && i386_regtab[reg_num].reg_type.bitfield.class == ClassNone))
343
1
  {
344
1
    as_bad (_("invalid use of pseudo-register"));
345
1
    return 0;
346
1
  }
347
550
      i.op[this_operand].regs = i386_regtab + reg_num;
348
550
    }
349
6
  else if (!intel_state.index
350
6
     && (i386_regtab[reg_num].reg_type.bitfield.xmmword
351
6
         || i386_regtab[reg_num].reg_type.bitfield.ymmword
352
6
         || i386_regtab[reg_num].reg_type.bitfield.zmmword
353
6
         || i386_regtab[reg_num].reg_num == RegIZ))
354
0
    intel_state.index = i386_regtab + reg_num;
355
6
  else if (!intel_state.base && !intel_state.in_scale)
356
2
    intel_state.base = i386_regtab + reg_num;
357
4
  else if (!intel_state.index)
358
4
    {
359
4
      const insn_template *t = current_templates.start;
360
361
4
      if (intel_state.in_scale
362
0
    || i386_regtab[reg_num].reg_type.bitfield.baseindex
363
0
    || dot_insn ()
364
0
    || t->mnem_off == MN_bndmk
365
0
    || t->mnem_off == MN_bndldx
366
0
    || t->mnem_off == MN_bndstx)
367
4
  intel_state.index = i386_regtab + reg_num;
368
0
      else
369
0
  {
370
    /* Convert base to index and make ESP/RSP the base.  */
371
0
    intel_state.index = intel_state.base;
372
0
    intel_state.base = i386_regtab + reg_num;
373
0
  }
374
4
    }
375
0
  else
376
0
    {
377
      /* esp is invalid as index */
378
0
      intel_state.index = reg_eax + ESP_REG_NUM;
379
0
    }
380
556
  return 2;
381
557
}
382
383
static symbolS *
384
i386_intel_simplify_symbol (symbolS *sym, bool in_equate)
385
15.0k
{
386
15.0k
  if (symbol_resolving_p (sym))
387
0
    return sym;
388
389
15.0k
  segT seg = S_GET_SEGMENT (sym);
390
15.0k
  if (seg != expr_section && seg != reg_section && !symbol_equated_p(sym))
391
12.7k
    return sym;
392
393
2.34k
  for (;;)
394
2.34k
    {
395
      /* While we're after equates, symbol_equated_p() isn't suitable here.  */
396
2.34k
      if (symbol_on_chain(sym, symbol_rootP, symbol_lastP))
397
4
  {
398
4
    in_equate = true;
399
4
    sym = symbol_clone (sym, 0);
400
4
  }
401
2.34k
      else if (in_equate)
402
0
  {
403
0
    expressionS *e = symbol_get_value_expression (sym);
404
405
0
    if (e->X_op == O_symbol && !e->X_add_number)
406
0
      {
407
0
        sym = e->X_add_symbol;
408
0
        continue;
409
0
      }
410
0
    sym = make_expr_symbol (e);
411
0
  }
412
413
2.34k
      break;
414
2.34k
    }
415
416
2.34k
  symbol_mark_resolving (sym);
417
2.34k
  int ret = i386_intel_simplify (symbol_get_value_expression (sym), in_equate);
418
2.34k
  if (ret == 2)
419
207
    S_SET_SEGMENT (sym, absolute_section);
420
2.34k
  symbol_clear_resolving (sym);
421
422
2.34k
  return ret ? sym : NULL;
423
15.0k
}
424
425
static int
426
i386_intel_simplify (expressionS *e, bool in_equate)
427
11.5k
{
428
11.5k
  const reg_entry *the_reg = (this_operand >= 0
429
11.5k
            ? i.op[this_operand].regs : NULL);
430
11.5k
  const reg_entry *base = intel_state.base;
431
11.5k
  const reg_entry *state_index = intel_state.index;
432
11.5k
  symbolS *newsym;
433
11.5k
  int ret;
434
435
11.5k
  if (!intel_syntax)
436
0
    return 1;
437
438
11.5k
  switch (e->X_op)
439
11.5k
    {
440
45
    case O_index:
441
45
      if (e->X_add_symbol)
442
20
  {
443
20
    newsym = i386_intel_simplify_symbol (e->X_add_symbol, in_equate);
444
20
    if (!newsym
445
20
        || !i386_intel_check(the_reg, intel_state.base,
446
20
           intel_state.index))
447
0
      return 0;
448
20
    e->X_add_symbol = newsym;
449
20
  }
450
45
      if (!intel_state.in_offset)
451
45
  ++intel_state.in_bracket;
452
45
      newsym = i386_intel_simplify_symbol (e->X_op_symbol, in_equate);
453
45
      if (!intel_state.in_offset)
454
45
  --intel_state.in_bracket;
455
45
      if (!newsym)
456
3
  return 0;
457
42
      e->X_op_symbol = newsym;
458
42
      if (!e->X_add_symbol)
459
25
  i386_intel_fold (e, e->X_op_symbol);
460
17
      else if (S_GET_SEGMENT (e->X_add_symbol) == expr_section
461
10
         && (S_GET_SEGMENT (e->X_op_symbol) == absolute_section
462
4
       || S_GET_SEGMENT (e->X_op_symbol) == expr_section)
463
10
         && symbol_get_value_expression (e->X_op_symbol)->X_op
464
10
      == O_constant)
465
7
  {
466
7
    offsetT val
467
7
      = symbol_get_value_expression (e->X_op_symbol)->X_add_number;
468
469
7
    i386_intel_fold (e, e->X_add_symbol);
470
7
    e->X_add_number += val;
471
7
  }
472
10
      else
473
10
  e->X_op = O_add;
474
42
      break;
475
476
3
    case O_offset:
477
3
      intel_state.has_offset = 1;
478
3
      ++intel_state.in_offset;
479
3
      newsym = i386_intel_simplify_symbol (e->X_add_symbol, in_equate);
480
3
      --intel_state.in_offset;
481
3
      if (!newsym || !i386_intel_check(the_reg, base, state_index))
482
0
  return 0;
483
3
      e->X_add_symbol = newsym;
484
3
      i386_intel_fold (e, e->X_add_symbol);
485
3
      return 1;
486
487
0
    case O_byte_ptr:
488
0
    case O_word_ptr:
489
0
    case O_dword_ptr:
490
0
    case O_fword_ptr:
491
0
    case O_qword_ptr: /* O_mmword_ptr */
492
0
    case O_tbyte_ptr:
493
0
    case O_oword_ptr: /* O_xmmword_ptr */
494
0
    case O_ymmword_ptr:
495
0
    case O_zmmword_ptr:
496
0
    case O_near_ptr:
497
0
    case O_far_ptr:
498
0
      if (intel_state.op_modifier == O_absent)
499
0
  intel_state.op_modifier = e->X_op;
500
      /* FALLTHROUGH */
501
0
    case O_short:
502
0
      if (symbol_get_value_expression (e->X_add_symbol)->X_op
503
0
    == O_register)
504
0
  {
505
0
    as_bad (_("invalid use of register"));
506
0
    return 0;
507
0
  }
508
0
      newsym = i386_intel_simplify_symbol (e->X_add_symbol, in_equate);
509
0
      if (!newsym)
510
0
  return 0;
511
0
      e->X_add_symbol = newsym;
512
0
      i386_intel_fold (e, e->X_add_symbol);
513
0
      break;
514
515
399
    case O_full_ptr:
516
399
      if (symbol_get_value_expression (e->X_op_symbol)->X_op
517
399
    == O_register)
518
2
  {
519
2
    as_bad (_("invalid use of register"));
520
2
    return 0;
521
2
  }
522
397
      newsym = i386_intel_simplify_symbol (e->X_op_symbol, in_equate);
523
397
      if (!newsym
524
397
    || !i386_intel_check(the_reg, intel_state.base,
525
397
             intel_state.index))
526
0
  return 0;
527
397
      e->X_op_symbol = newsym;
528
397
      if (!intel_state.in_offset)
529
397
  {
530
397
    if (!intel_state.seg)
531
50
      intel_state.seg = e->X_add_symbol;
532
347
    else
533
347
      {
534
347
        expressionS exp = {
535
347
    .X_op = O_full_ptr,
536
347
    .X_add_symbol = e->X_add_symbol,
537
347
    .X_op_symbol = intel_state.seg
538
347
        };
539
347
        intel_state.seg = make_expr_symbol (&exp);
540
347
      }
541
397
  }
542
397
      i386_intel_fold (e, e->X_op_symbol);
543
397
      break;
544
545
1.05k
    case O_add:
546
1.05k
      if (this_operand >= 0 && intel_state.in_bracket)
547
0
  {
548
0
    expressionS *left = NULL, *right = NULL;
549
0
    segT leftseg = NULL, rightseg = NULL;
550
551
0
    newsym = i386_intel_simplify_symbol (e->X_add_symbol, in_equate);
552
0
    if (newsym)
553
0
      {
554
0
        e->X_add_symbol = newsym;
555
556
0
        if (base != intel_state.base || state_index != intel_state.index)
557
0
    {
558
0
      base = intel_state.base;
559
0
      state_index = intel_state.index;
560
0
      left = symbol_get_value_expression (newsym);
561
0
      resolve_expression (left);
562
0
      leftseg = S_GET_SEGMENT (newsym);
563
0
    }
564
0
      }
565
566
0
    newsym = i386_intel_simplify_symbol (e->X_op_symbol, in_equate);
567
0
    if (newsym)
568
0
      {
569
0
        e->X_op_symbol = newsym;
570
571
0
        if (base != intel_state.base || state_index != intel_state.index)
572
0
    {
573
0
      base = intel_state.base;
574
0
      state_index = intel_state.index;
575
0
      right = symbol_get_value_expression (newsym);
576
0
      resolve_expression (right);
577
0
      rightseg = S_GET_SEGMENT (newsym);
578
0
    }
579
0
      }
580
581
0
    if (left && right
582
0
        && (leftseg == absolute_section || leftseg == expr_section)
583
0
        && left->X_op == O_constant
584
0
        && (rightseg == absolute_section || rightseg == expr_section)
585
0
        && right->X_op == O_constant)
586
0
      {
587
0
         e->X_op = O_constant;
588
0
         e->X_add_number += left->X_add_number + right->X_add_number;
589
0
         e->X_add_symbol = NULL;
590
0
         e->X_op_symbol = NULL;
591
0
      }
592
0
    else if (left
593
0
       && (leftseg == absolute_section || leftseg == expr_section)
594
0
       && left->X_op == O_constant)
595
0
      i386_intel_fold (e, e->X_op_symbol);
596
0
    else if (right
597
0
       && (rightseg == absolute_section || rightseg == expr_section)
598
0
       && right->X_op == O_constant)
599
0
      i386_intel_fold (e, e->X_add_symbol);
600
0
  }
601
1.05k
      goto fallthrough;
602
603
977
    case O_multiply:
604
977
      if (this_operand >= 0 && intel_state.in_bracket)
605
4
  {
606
4
    expressionS *scale = NULL, *other = NULL;
607
4
    int has_index = (intel_state.index != NULL);
608
609
4
    if (!intel_state.in_scale++)
610
4
      intel_state.scale_factor = 1;
611
612
4
    newsym = i386_intel_simplify_symbol (e->X_add_symbol, in_equate);
613
4
    if (newsym)
614
2
      {
615
2
        e->X_add_symbol = newsym;
616
617
2
        if (!has_index && intel_state.index)
618
2
    {
619
2
      scale = symbol_get_value_expression (e->X_op_symbol);
620
2
      other = symbol_get_value_expression (e->X_add_symbol);
621
2
    }
622
623
2
        newsym = i386_intel_simplify_symbol (e->X_op_symbol, in_equate);
624
2
      }
625
626
4
    if (newsym)
627
2
      {
628
2
        e->X_op_symbol = newsym;
629
630
2
        if (!scale && !has_index && intel_state.index)
631
0
    {
632
0
      scale = symbol_get_value_expression (e->X_add_symbol);
633
0
      other = symbol_get_value_expression (e->X_op_symbol);
634
0
    }
635
2
      }
636
637
4
    if (newsym && scale)
638
2
      {
639
2
        segT seg;
640
641
2
        resolve_expression (scale);
642
2
        if (scale->X_op != O_constant
643
2
      || intel_state.index->reg_type.bitfield.word)
644
0
    scale->X_add_number = 0;
645
2
        intel_state.scale_factor *= scale->X_add_number;
646
647
2
        resolve_expression (other);
648
2
        seg = S_GET_SEGMENT (newsym);
649
2
        if ((seg == absolute_section || seg == expr_section)
650
0
      && other->X_op == O_constant
651
0
      && other->X_add_number == 0)
652
0
    {
653
0
      e->X_op = O_constant;
654
0
      e->X_add_symbol = NULL;
655
0
      e->X_op_symbol = NULL;
656
0
    }
657
2
      }
658
659
4
    --intel_state.in_scale;
660
4
    if (!newsym)
661
2
      return 0;
662
663
2
    if (!intel_state.in_scale)
664
2
      switch (intel_state.scale_factor)
665
2
        {
666
0
        case 1:
667
0
    i.log2_scale_factor = 0;
668
0
    break;
669
0
        case 2:
670
0
    i.log2_scale_factor = 1;
671
0
    break;
672
0
        case 4:
673
0
    i.log2_scale_factor = 2;
674
0
    break;
675
0
        case 8:
676
0
    i.log2_scale_factor = 3;
677
0
    break;
678
2
        default:
679
    /* esp is invalid as index */
680
2
    intel_state.index = reg_eax + ESP_REG_NUM;
681
2
    break;
682
2
        }
683
684
2
    break;
685
2
  }
686
973
      goto fallthrough;
687
688
973
    case O_register:
689
557
      ret = i386_intel_simplify_register (e);
690
557
      if (ret == 2)
691
556
  {
692
556
    gas_assert (e->X_add_number < (unsigned short) -1);
693
556
    e->X_md = (unsigned short) e->X_add_number + 1;
694
556
    e->X_op = O_constant;
695
556
    e->X_add_number = 0;
696
556
  }
697
557
      return ret;
698
699
861
    case O_constant:
700
861
      if (e->X_md)
701
0
  return i386_intel_simplify_register (e);
702
703
      /* FALLTHROUGH */
704
8.47k
    default:
705
10.5k
    fallthrough:
706
10.5k
      if (e->X_add_symbol)
707
9.27k
  {
708
9.27k
    newsym = i386_intel_simplify_symbol (e->X_add_symbol, in_equate);
709
9.27k
    if (!newsym)
710
29
      return 0;
711
9.24k
    e->X_add_symbol = newsym;
712
9.24k
  }
713
10.4k
      if (!the_reg && this_operand >= 0
714
8.05k
    && e->X_op == O_symbol && !e->X_add_number)
715
1.77k
  the_reg = i.op[this_operand].regs;
716
10.4k
      if (e->X_op == O_add || e->X_op == O_subtract)
717
2.64k
  {
718
2.64k
    base = intel_state.base;
719
2.64k
    state_index = intel_state.index;
720
2.64k
  }
721
10.4k
      if (!i386_intel_check (the_reg, base, state_index))
722
204
  return 0;
723
10.2k
      if (e->X_op_symbol)
724
5.34k
  {
725
5.34k
    newsym = i386_intel_simplify_symbol (e->X_op_symbol, in_equate);
726
5.34k
    if (!newsym)
727
2
      return 0;
728
5.34k
    e->X_op_symbol = newsym;
729
5.34k
  }
730
10.2k
      if (!i386_intel_check (the_reg,
731
10.2k
           e->X_op != O_add ? base : intel_state.base,
732
10.2k
           (e->X_op != O_add ? state_index
733
10.2k
                 : intel_state.index)))
734
0
  return 0;
735
10.2k
      break;
736
11.5k
    }
737
738
10.7k
  if (this_operand >= 0
739
7.93k
      && e->X_op == O_symbol
740
2.61k
      && !intel_state.has_offset)
741
2.61k
    {
742
2.61k
      segT seg = S_GET_SEGMENT (e->X_add_symbol);
743
744
2.61k
      if (seg != absolute_section
745
2.61k
    && seg != reg_section
746
2.61k
    && seg != expr_section)
747
2.61k
  intel_state.is_mem |= 2 - !intel_state.in_bracket;
748
2.61k
    }
749
750
10.7k
  return 1;
751
11.5k
}
752
753
int i386_need_index_operator (void)
754
785
{
755
785
  return intel_syntax < 0;
756
785
}
757
758
static int
759
i386_intel_operand (char *operand_string, int got_a_float)
760
7.05k
{
761
7.05k
  char *saved_input_line_pointer, *buf;
762
7.05k
  segT exp_seg;
763
7.05k
  expressionS exp, *expP;
764
7.05k
  char suffix = 0;
765
7.05k
  bool rc_sae_modifier = i.rounding.type != rc_none && i.rounding.modifier;
766
7.05k
  int ret;
767
768
  /* Handle vector immediates.  */
769
7.05k
  if (RC_SAE_immediate (operand_string))
770
0
    {
771
0
      if (i.imm_operands)
772
0
  {
773
0
    as_bad (_("`%s': RC/SAE operand must precede immediate operands"),
774
0
      insn_name (current_templates.start));
775
0
    return 0;
776
0
  }
777
778
0
      return 1;
779
0
    }
780
781
  /* Initialize state structure.  */
782
7.05k
  intel_state.op_modifier = O_absent;
783
7.05k
  intel_state.is_mem = 0;
784
7.05k
  intel_state.is_indirect = 0;
785
7.05k
  intel_state.has_offset = 0;
786
7.05k
  intel_state.base = NULL;
787
7.05k
  intel_state.index = NULL;
788
7.05k
  intel_state.seg = NULL;
789
7.05k
  operand_type_set (&intel_state.reloc_types, ~0);
790
7.05k
  gas_assert (!intel_state.in_offset);
791
7.05k
  gas_assert (!intel_state.in_bracket);
792
7.05k
  gas_assert (!intel_state.in_scale);
793
794
7.05k
  saved_input_line_pointer = input_line_pointer;
795
7.05k
  input_line_pointer = buf = xstrdup (operand_string);
796
797
7.05k
  intel_syntax = -1;
798
7.05k
  expr_mode = expr_operator_none;
799
7.05k
  memset (&exp, 0, sizeof(exp));
800
7.05k
  exp_seg = expression (&exp);
801
7.05k
  ret = i386_intel_simplify (&exp, false);
802
7.05k
  intel_syntax = 1;
803
804
7.05k
  SKIP_WHITESPACE ();
805
806
  /* Handle vector operations.  */
807
7.05k
  if (*input_line_pointer == '{')
808
23
    {
809
23
      char *end = check_VecOperations (input_line_pointer);
810
23
      if (end)
811
5
  input_line_pointer = end;
812
18
      else
813
18
  ret = 0;
814
23
    }
815
816
7.05k
  if (!is_end_of_stmt (*input_line_pointer))
817
3.02k
    {
818
3.02k
      if (ret)
819
2.81k
  as_bad (_("junk `%s' after expression"), input_line_pointer);
820
3.02k
      ret = 0;
821
3.02k
    }
822
4.03k
  else if (exp.X_op == O_illegal || exp.X_op == O_absent)
823
4
    {
824
4
      if (ret)
825
4
  as_bad (_("invalid expression"));
826
4
      ret = 0;
827
4
    }
828
4.02k
  else if (!intel_state.has_offset
829
4.02k
     && input_line_pointer > buf
830
4.02k
     && *(input_line_pointer - 1) == ']')
831
0
    {
832
0
      intel_state.is_mem |= 1;
833
0
      intel_state.is_indirect = 1;
834
0
    }
835
836
7.05k
  input_line_pointer = saved_input_line_pointer;
837
7.05k
  free (buf);
838
839
7.05k
  gas_assert (!intel_state.in_offset);
840
7.05k
  gas_assert (!intel_state.in_bracket);
841
7.05k
  gas_assert (!intel_state.in_scale);
842
843
7.05k
  if (!ret)
844
3.04k
    return 0;
845
846
4.01k
  if (intel_state.op_modifier != O_absent
847
0
      && current_templates.start->mnem_off != MN_lea)
848
0
    {
849
0
      i.types[this_operand].bitfield.unspecified = 0;
850
851
0
      switch (intel_state.op_modifier)
852
0
  {
853
0
  case O_byte_ptr:
854
0
    i.types[this_operand].bitfield.byte = 1;
855
0
    suffix = BYTE_MNEM_SUFFIX;
856
0
    break;
857
858
0
  case O_word_ptr:
859
0
    i.types[this_operand].bitfield.word = 1;
860
0
    if (got_a_float == 2) /* "fi..." */
861
0
      suffix = SHORT_MNEM_SUFFIX;
862
0
    else if (current_templates.start->mnem_off != MN_lar
863
0
       && current_templates.start->mnem_off != MN_lsl
864
0
       && current_templates.start->mnem_off != MN_arpl)
865
0
      suffix = WORD_MNEM_SUFFIX;
866
0
    break;
867
868
0
  case O_dword_ptr:
869
0
    i.types[this_operand].bitfield.dword = 1;
870
0
    if ((insn_name (current_templates.start)[0] == 'l'
871
0
         && insn_name (current_templates.start)[2] == 's'
872
0
         && insn_name (current_templates.start)[3] == 0)
873
0
        || current_templates.start->mnem_off == MN_bound)
874
0
      suffix = WORD_MNEM_SUFFIX;
875
0
    else if (flag_code != CODE_32BIT
876
0
       && (current_templates.start->opcode_modifier.jump == JUMP
877
0
           || current_templates.start->opcode_modifier.jump
878
0
        == JUMP_DWORD))
879
0
      {
880
0
        i.far_branch = true;
881
0
        suffix = WORD_MNEM_SUFFIX;
882
0
      }
883
0
    else if (got_a_float == 1) /* "f..." */
884
0
      suffix = SHORT_MNEM_SUFFIX;
885
0
    else
886
0
      suffix = LONG_MNEM_SUFFIX;
887
0
    break;
888
889
0
  case O_fword_ptr:
890
0
    i.types[this_operand].bitfield.fword = 1;
891
0
    if (current_templates.start->mnem_off == MN_les
892
0
        || current_templates.start->mnem_off == MN_lds
893
0
        || current_templates.start->mnem_off == MN_lss
894
0
        || current_templates.start->mnem_off == MN_lfs
895
0
        || current_templates.start->mnem_off == MN_lgs)
896
0
      suffix = LONG_MNEM_SUFFIX;
897
0
    else if (!got_a_float)
898
0
      {
899
0
        if (flag_code == CODE_16BIT)
900
0
    add_prefix (DATA_PREFIX_OPCODE);
901
0
        i.far_branch = true;
902
0
      }
903
0
    break;
904
905
0
  case O_qword_ptr: /* O_mmword_ptr */
906
0
    i.types[this_operand].bitfield.qword = 1;
907
0
    if (current_templates.start->mnem_off == MN_bound
908
0
        || got_a_float == 1) /* "f..." */
909
0
      suffix = LONG_MNEM_SUFFIX;
910
0
    else
911
0
      suffix = QWORD_MNEM_SUFFIX;
912
0
    break;
913
914
0
  case O_tbyte_ptr:
915
0
    i.types[this_operand].bitfield.tbyte = 1;
916
0
    if (got_a_float)
917
0
      break;
918
0
    if (flag_code == CODE_64BIT
919
0
        && (current_templates.start->operand_types[0].bitfield.fword
920
0
      || current_templates.start->operand_types[0].bitfield.tbyte
921
0
      || current_templates.start->opcode_modifier.jump == JUMP_DWORD
922
0
      || current_templates.start->opcode_modifier.jump == JUMP))
923
0
      suffix = QWORD_MNEM_SUFFIX; /* l[fgs]s, [ls][gi]dt, call, jmp */
924
0
    else
925
0
      i.types[this_operand].bitfield.byte = 1; /* cause an error */
926
0
    break;
927
928
0
  case O_oword_ptr: /* O_xmmword_ptr */
929
0
    i.types[this_operand].bitfield.xmmword = 1;
930
0
    break;
931
932
0
  case O_ymmword_ptr:
933
0
    if (vector_size < VSZ256)
934
0
      {
935
0
        as_bad (_("256-bit operands disabled"));
936
0
        return 0;
937
0
      }
938
0
    i.types[this_operand].bitfield.ymmword = 1;
939
0
    break;
940
941
0
  case O_zmmword_ptr:
942
0
    if (vector_size < VSZ512)
943
0
      {
944
0
        as_bad (_("512-bit operands disabled"));
945
0
        return 0;
946
0
      }
947
0
    i.types[this_operand].bitfield.zmmword = 1;
948
0
    break;
949
950
0
  case O_far_ptr:
951
0
    i.far_branch = true;
952
    /* FALLTHROUGH */
953
0
  case O_near_ptr:
954
0
    if (current_templates.start->opcode_modifier.jump != JUMP
955
0
        && current_templates.start->opcode_modifier.jump != JUMP_DWORD)
956
0
      {
957
        /* cause an error */
958
0
        i.types[this_operand].bitfield.byte = 1;
959
0
        i.types[this_operand].bitfield.tbyte = 1;
960
0
        suffix = i.suffix;
961
0
      }
962
0
    break;
963
964
0
  default:
965
0
    BAD_CASE (intel_state.op_modifier);
966
0
    break;
967
0
  }
968
969
      /* Now check whether we actually want to infer an AT&T-like suffix.
970
   We really only need to do this when operand size determination (incl.
971
   REX.W) is going to be derived from it.  For this we check whether the
972
   given suffix is valid for any of the candidate templates.  */
973
0
      if (suffix && suffix != i.suffix
974
0
    && current_templates.start->mnem_off != MN_bound)
975
0
  {
976
0
    const insn_template *t;
977
978
0
    for (t = current_templates.start; t < current_templates.end; ++t)
979
0
      {
980
        /* Operands haven't been swapped yet.  */
981
0
        unsigned int op = t->operands - 1 - this_operand;
982
983
        /* Easy checks to skip templates which won't match anyway.  */
984
0
        if (this_operand >= t->operands
985
0
      || t->opcode_modifier.dialect >= ATT_SYNTAX)
986
0
    continue;
987
988
0
        switch (suffix)
989
0
    {
990
0
    case BYTE_MNEM_SUFFIX:
991
0
      if (t->opcode_modifier.no_bsuf)
992
0
        continue;
993
0
      break;
994
0
    case WORD_MNEM_SUFFIX:
995
0
      if (t->opcode_modifier.no_wsuf)
996
0
        continue;
997
0
      break;
998
0
    case LONG_MNEM_SUFFIX:
999
0
      if (t->opcode_modifier.no_lsuf)
1000
0
        continue;
1001
0
      break;
1002
0
    case QWORD_MNEM_SUFFIX:
1003
0
      if (t->opcode_modifier.no_qsuf || !q_suffix_allowed (t))
1004
0
        continue;
1005
0
      break;
1006
0
    case SHORT_MNEM_SUFFIX:
1007
0
      if (t->opcode_modifier.no_ssuf)
1008
0
        continue;
1009
0
      break;
1010
0
    default:
1011
0
      abort ();
1012
0
    }
1013
1014
        /* We can skip templates with swappable operands here, as one
1015
     operand will be a register, which operand size can be
1016
     determined from.  */
1017
0
        if (t->opcode_modifier.d)
1018
0
    continue;
1019
1020
        /* In a few cases suffixes are permitted, but we can nevertheless
1021
     derive that these aren't going to be needed.  This is only of
1022
     interest for insns using ModR/M.  */
1023
0
        if (!t->opcode_modifier.modrm)
1024
0
    break;
1025
1026
0
        if (!t->operand_types[op].bitfield.baseindex)
1027
0
    continue;
1028
1029
0
        switch (t->operand_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
4.01k
  if (current_templates.start->opcode_modifier.jump
1055
3.90k
      || current_templates.start->mnem_off == MN_jmpabs)
1056
115
    {
1057
115
      bool jumpabsolute = false;
1058
1059
115
      if (i.op[this_operand].regs
1060
115
    || intel_state.base
1061
113
    || intel_state.index
1062
112
    || intel_state.is_mem > 1)
1063
3
  jumpabsolute = true;
1064
112
      else
1065
112
  switch (intel_state.op_modifier)
1066
112
    {
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
112
    case O_absent:
1075
112
      if (!intel_state.seg)
1076
101
        {
1077
101
    intel_state.is_mem = 1;
1078
101
    if (intel_state.op_modifier == O_absent)
1079
101
      {
1080
101
        if (intel_state.is_indirect == 1)
1081
0
          jumpabsolute = true;
1082
101
        break;
1083
101
      }
1084
0
    as_bad (_("cannot infer the segment part of the operand"));
1085
0
    return 0;
1086
101
        }
1087
11
      else if (S_GET_SEGMENT (intel_state.seg) == reg_section)
1088
4
        {
1089
4
    jumpabsolute = true;
1090
4
    if (intel_state.op_modifier == O_far_ptr)
1091
0
      i.far_branch = true;
1092
4
        }
1093
7
      else
1094
7
        {
1095
7
    i386_operand_type types;
1096
1097
7
    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
7
    expP = &im_expressions[i.imm_operands++];
1104
7
    memset (expP, 0, sizeof(*expP));
1105
7
    expP->X_op = O_symbol;
1106
7
    expP->X_add_symbol = intel_state.seg;
1107
7
    i.op[this_operand].imms = expP;
1108
1109
7
    resolve_expression (expP);
1110
7
    operand_type_set (&types, ~0);
1111
7
    if (!i386_finalize_immediate (S_GET_SEGMENT (intel_state.seg),
1112
7
                expP, types, operand_string))
1113
0
      return 0;
1114
7
    if (i.operands < MAX_OPERANDS)
1115
7
      {
1116
7
        this_operand = i.operands++;
1117
7
        i.types[this_operand].bitfield.unspecified = 1;
1118
7
      }
1119
7
    intel_state.seg = NULL;
1120
7
    intel_state.is_mem = 0;
1121
7
        }
1122
11
      break;
1123
11
    default:
1124
0
      jumpabsolute = true;
1125
0
      break;
1126
112
    }
1127
115
      if (jumpabsolute)
1128
7
  {
1129
7
    i.jumpabsolute = true;
1130
7
    intel_state.is_mem |= 1;
1131
7
  }
1132
115
    }
1133
3.90k
  else if (intel_state.seg)
1134
33
    intel_state.is_mem |= 1;
1135
1136
4.01k
  if (i.op[this_operand].regs)
1137
326
    {
1138
326
      i386_operand_type temp;
1139
1140
      /* Register operand.  */
1141
326
      if (intel_state.base || intel_state.index || intel_state.seg
1142
326
          || i.imm_bits[this_operand])
1143
0
  {
1144
0
    as_bad (_("invalid operand"));
1145
0
    return 0;
1146
0
  }
1147
1148
326
      temp = i.op[this_operand].regs->reg_type;
1149
326
      temp.bitfield.baseindex = 0;
1150
326
      i.types[this_operand] = operand_type_or (i.types[this_operand],
1151
326
                 temp);
1152
326
      i.types[this_operand].bitfield.unspecified = 0;
1153
326
      ++i.reg_operands;
1154
1155
326
      if ((i.rounding.type != rc_none && !i.rounding.modifier
1156
0
     && temp.bitfield.class != Reg)
1157
326
    || 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
326
    }
1169
3.69k
  else if (intel_state.base
1170
3.69k
     || intel_state.index
1171
3.68k
     || intel_state.seg
1172
3.65k
     || intel_state.is_mem)
1173
2.32k
    {
1174
      /* Memory operand.  */
1175
2.32k
      if (i.imm_bits[this_operand])
1176
0
  {
1177
0
    as_bad (_("invalid operand"));
1178
0
    return 0;
1179
0
  }
1180
1181
2.32k
      if (i.mem_operands)
1182
46
  {
1183
    /* Handle
1184
1185
       call 0x9090,0x90909090
1186
       lcall  0x9090,0x90909090
1187
       jmp  0x9090,0x90909090
1188
       ljmp 0x9090,0x90909090
1189
     */
1190
1191
46
    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
46
  }
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
2.31k
      if (intel_state.base
1230
2
    && intel_state.index
1231
0
    && intel_state.base->reg_type.bitfield.word
1232
0
    && 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
2.31k
      else
1240
2.31k
  {
1241
2.31k
    i.base_reg = intel_state.base;
1242
2.31k
    i.index_reg = intel_state.index;
1243
2.31k
  }
1244
1245
2.31k
      if (i.base_reg || i.index_reg)
1246
3
  i.types[this_operand].bitfield.baseindex = 1;
1247
1248
2.31k
      expP = &disp_expressions[i.disp_operands];
1249
2.31k
      memcpy (expP, &exp, sizeof(exp));
1250
2.31k
      resolve_expression (expP);
1251
1252
2.31k
      if (expP->X_op != O_constant
1253
72
    || expP->X_add_number
1254
62
    || !i.types[this_operand].bitfield.baseindex)
1255
2.31k
  {
1256
2.31k
    i.op[this_operand].disps = expP;
1257
2.31k
    i.disp_operands++;
1258
1259
2.31k
    i386_addressing_mode ();
1260
1261
2.31k
    if (flag_code == CODE_64BIT)
1262
805
      {
1263
805
        i.types[this_operand].bitfield.disp32 = 1;
1264
805
        if (!i.prefix[ADDR_PREFIX])
1265
805
    i.types[this_operand].bitfield.disp64 = 1;
1266
805
      }
1267
1.50k
    else if (!i.prefix[ADDR_PREFIX] ^ (flag_code == CODE_16BIT))
1268
9
      i.types[this_operand].bitfield.disp32 = 1;
1269
1.50k
    else
1270
1.50k
      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
2.31k
    if (!i386_finalize_displacement (exp_seg, expP,
1292
2.31k
             intel_state.reloc_types,
1293
2.31k
             operand_string))
1294
0
      return 0;
1295
2.31k
  }
1296
1297
2.31k
      if (intel_state.seg)
1298
37
  {
1299
37
    for (ret = check_none; ; ret = operand_check)
1300
37
      {
1301
37
        expP = symbol_get_value_expression (intel_state.seg);
1302
37
        if (expP->X_op != O_full_ptr 
1303
9
      || symbol_get_value_expression (expP->X_op_symbol)->X_op
1304
9
         != O_register)
1305
37
    break;
1306
0
        intel_state.seg = expP->X_add_symbol;
1307
0
      }
1308
37
    if (expP->X_op != O_register)
1309
13
      {
1310
13
        as_bad (_("segment register name expected"));
1311
13
        return 0;
1312
13
      }
1313
24
    if (i386_regtab[expP->X_add_number].reg_type.bitfield.class != SReg)
1314
20
      {
1315
20
        as_bad (_("invalid use of register"));
1316
20
        return 0;
1317
20
      }
1318
4
    switch (ret)
1319
4
      {
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
4
      }
1327
4
    if (i386_regtab[expP->X_add_number].reg_num == RegFlat)
1328
0
      i.seg[i.mem_operands] = NULL;
1329
4
    else
1330
4
      i.seg[i.mem_operands] = &i386_regtab[expP->X_add_number];
1331
4
  }
1332
1333
2.28k
      if (!i386_index_check (operand_string))
1334
3
  return 0;
1335
1336
2.27k
      i.flags[this_operand] |= Operand_Mem;
1337
2.27k
      ++i.mem_operands;
1338
2.27k
    }
1339
1.36k
  else
1340
1.36k
    {
1341
      /* Immediate.  */
1342
1.36k
      if (i.imm_operands >= MAX_IMMEDIATE_OPERANDS)
1343
9
  {
1344
9
    as_bad (_("at most %d immediate operands are allowed"),
1345
9
      MAX_IMMEDIATE_OPERANDS);
1346
9
    return 0;
1347
9
  }
1348
1349
1.36k
      expP = &im_expressions[i.imm_operands++];
1350
1.36k
      i.op[this_operand].imms = expP;
1351
1.36k
      *expP = exp;
1352
1353
1.36k
      return i386_finalize_immediate (exp_seg, expP, intel_state.reloc_types,
1354
1.36k
              operand_string);
1355
1.36k
    }
1356
1357
2.60k
  return 1;
1358
4.01k
}