Coverage Report

Created: 2026-11-21 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/m68k-dis.c
Line
Count
Source
1
/* Print Motorola 68k instructions.
2
   Copyright (C) 1986-2026 Free Software Foundation, Inc.
3
4
   This file is part of the GNU opcodes library.
5
6
   This library 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
   It is distributed in the hope that it will be useful, but WITHOUT
12
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
14
   License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19
   MA 02110-1301, USA.  */
20
21
#include "sysdep.h"
22
#include "disassemble.h"
23
#include "floatformat.h"
24
#include "libiberty.h"
25
#include "opintl.h"
26
#include "cpu-m68k.h"
27
#include "opcode/m68k.h"
28
29
/* Local function prototypes.  */
30
31
const char * const fpcr_names[] =
32
{
33
  "", "%fpiar", "%fpsr", "%fpiar/%fpsr", "%fpcr",
34
  "%fpiar/%fpcr", "%fpsr/%fpcr", "%fpiar/%fpsr/%fpcr"
35
};
36
37
static char *const reg_names[] =
38
{
39
  "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7",
40
  "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%fp", "%sp",
41
  "%ps", "%pc"
42
};
43
44
/* Name of register halves for MAC/EMAC.
45
   Seperate from reg_names since 'spu', 'fpl' look weird.  */
46
static char *const reg_half_names[] =
47
{
48
  "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6", "%d7",
49
  "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%a6", "%a7",
50
  "%ps", "%pc"
51
};
52
53
/* Sign-extend an (unsigned char).  */
54
#if __STDC__ == 1
55
575k
#define COERCE_SIGNED_CHAR(ch) ((signed char) (ch))
56
#else
57
#define COERCE_SIGNED_CHAR(ch) ((int) (((ch) ^ 0x80) & 0xFF) - 128)
58
#endif
59
60
/* Error code of print_insn_arg's return value.  */
61
62
enum print_insn_arg_error
63
  {
64
    /* An invalid operand is found.  */
65
    PRINT_INSN_ARG_INVALID_OPERAND = -1,
66
67
    /* An opcode table error.  */
68
    PRINT_INSN_ARG_INVALID_OP_TABLE = -2,
69
70
    /* A memory error.  */
71
    PRINT_INSN_ARG_MEMORY_ERROR = -3,
72
  };
73
74
/* Get a 1 byte signed integer.  */
75
#define NEXTBYTE(p, val)      \
76
455k
  do            \
77
455k
    {           \
78
455k
      p += 2;         \
79
455k
      if (!FETCH_DATA (info, p))   \
80
455k
  return PRINT_INSN_ARG_MEMORY_ERROR; \
81
455k
      val = COERCE_SIGNED_CHAR (p[-1]);   \
82
455k
    }            \
83
455k
  while (0)
84
85
/* Get a 2 byte signed integer.  */
86
389k
#define COERCE16(x) ((int) (((x) ^ 0x8000) - 0x8000))
87
88
#define NEXTWORD(p, val, ret_val)   \
89
390k
  do            \
90
390k
    {           \
91
390k
      p += 2;         \
92
390k
      if (!FETCH_DATA (info, p))   \
93
390k
  return ret_val;       \
94
390k
      val = COERCE16 ((p[-2] << 8) + p[-1]);  \
95
389k
    }            \
96
390k
  while (0)
97
98
/* Get a 4 byte signed integer.  */
99
76.9k
#define COERCE32(x) (((bfd_vma) (x) ^ 0x80000000) - 0x80000000)
100
101
#define NEXTLONG(p, val, ret_val)         \
102
77.0k
  do                  \
103
77.0k
    {                 \
104
77.0k
      p += 4;               \
105
77.0k
      if (!FETCH_DATA (info, p))         \
106
77.0k
  return ret_val;             \
107
77.0k
      val = COERCE32 (((((((unsigned) p[-4] << 8) + p[-3]) << 8)  \
108
76.9k
      + p[-2]) << 8) + p[-1]);      \
109
76.9k
    }                  \
110
77.0k
  while (0)
111
112
/* Get a 4 byte unsigned integer.  */
113
#define NEXTULONG(p, val)           \
114
16.6k
  do                  \
115
16.6k
    {                 \
116
16.6k
      p += 4;               \
117
16.6k
      if (!FETCH_DATA (info, p))         \
118
16.6k
  return PRINT_INSN_ARG_MEMORY_ERROR;       \
119
16.6k
      val = (((((((unsigned) p[-4] << 8) + p[-3]) << 8)     \
120
16.6k
         + p[-2]) << 8) + p[-1]);         \
121
16.6k
    }                  \
122
16.6k
  while (0)
123
124
/* Get a single precision float.  */
125
#define NEXTSINGLE(val, p)          \
126
376
  do                \
127
376
    {               \
128
376
      p += 4;             \
129
376
      if (!FETCH_DATA (info, p))       \
130
376
  return PRINT_INSN_ARG_MEMORY_ERROR;     \
131
376
      floatformat_to_double (& floatformat_ieee_single_big, \
132
376
           (char *) p - 4, & val);    \
133
376
    }                \
134
376
  while (0)
135
136
/* Get a double precision float.  */
137
#define NEXTDOUBLE(val, p)          \
138
911
  do                \
139
911
    {               \
140
911
      p += 8;             \
141
911
      if (!FETCH_DATA (info, p))       \
142
911
  return PRINT_INSN_ARG_MEMORY_ERROR;     \
143
911
      floatformat_to_double (& floatformat_ieee_double_big, \
144
910
           (char *) p - 8, & val);    \
145
910
    }                \
146
911
  while (0)
147
148
/* Get an extended precision float.  */
149
#define NEXTEXTEND(val, p)        \
150
840
  do              \
151
840
    {             \
152
840
      p += 12;            \
153
840
      if (!FETCH_DATA (info, p))     \
154
840
  return PRINT_INSN_ARG_MEMORY_ERROR;   \
155
840
      floatformat_to_double (& floatformat_m68881_ext,  \
156
838
           (char *) p - 12, & val); \
157
838
    }              \
158
840
  while (0)
159
160
/* Need a function to convert from packed to double
161
   precision.   Actually, it's easier to print a
162
   packed number than a double anyway, so maybe
163
   there should be a special case to handle this... */
164
#define NEXTPACKED(p, val)      \
165
895
  do            \
166
895
    {           \
167
895
      p += 12;          \
168
895
      if (!FETCH_DATA (info, p))   \
169
895
  return PRINT_INSN_ARG_MEMORY_ERROR; \
170
895
      val = 0.0;        \
171
888
    }            \
172
895
  while (0)
173
174

175
/* Maximum length of an instruction.  */
176
#define MAXLEN 22
177
178
struct private
179
{
180
  /* Points to first byte not fetched.  */
181
  bfd_byte *max_fetched;
182
  bfd_byte the_buffer[MAXLEN];
183
  bfd_vma insn_start;
184
};
185
186
/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
187
   to ADDR (exclusive) are valid.  Returns 1 for success, 0 on memory
188
   error.  */
189
#define FETCH_DATA(info, addr) \
190
48.6M
  ((addr) <= ((struct private *) (info->private_data))->max_fetched \
191
48.6M
   ? 1 : fetch_data ((info), (addr)))
192
193
static int
194
fetch_data (struct disassemble_info *info, bfd_byte *addr)
195
1.70M
{
196
1.70M
  int status;
197
1.70M
  struct private *priv = (struct private *)info->private_data;
198
1.70M
  bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
199
200
1.70M
  status = (*info->read_memory_func) (start,
201
1.70M
              priv->max_fetched,
202
1.70M
              addr - priv->max_fetched,
203
1.70M
              info);
204
1.70M
  if (status != 0)
205
29.5k
    {
206
29.5k
      (*info->memory_error_func) (status, start, info);
207
29.5k
      return 0;
208
29.5k
    }
209
1.67M
  else
210
1.67M
    priv->max_fetched = addr;
211
1.67M
  return 1;
212
1.70M
}
213

214
/* This function is used to print to the bit-bucket.  */
215
static int
216
dummy_printer (void *file ATTRIBUTE_UNUSED,
217
         enum disassembler_style style ATTRIBUTE_UNUSED,
218
         const char *format ATTRIBUTE_UNUSED,
219
         ...)
220
2.57M
{
221
2.57M
  return 0;
222
2.57M
}
223
224
static void
225
dummy_print_address (bfd_vma vma ATTRIBUTE_UNUSED,
226
         struct disassemble_info *info ATTRIBUTE_UNUSED)
227
94.6k
{
228
94.6k
}
229
230
/* Fetch BITS bits from a position in the instruction specified by CODE.
231
   CODE is a "place to put an argument", or 'x' for a destination
232
   that is a general address (mode and register).
233
   BUFFER contains the instruction.
234
   Returns -1 on failure.  */
235
236
static int
237
fetch_arg (unsigned char *buffer,
238
     int code,
239
     int bits,
240
     disassemble_info *info)
241
2.94M
{
242
2.94M
  int val = 0;
243
244
2.94M
  switch (code)
245
2.94M
    {
246
11.1k
    case '/': /* MAC/EMAC mask bit.  */
247
11.1k
      val = buffer[3] >> 5;
248
11.1k
      break;
249
250
1.97k
    case 'G': /* EMAC ACC load.  */
251
1.97k
      val = ((buffer[3] >> 3) & 0x2) | ((~buffer[1] >> 7) & 0x1);
252
1.97k
      break;
253
254
794
    case 'H': /* EMAC ACC !load.  */
255
794
      val = ((buffer[3] >> 3) & 0x2) | ((buffer[1] >> 7) & 0x1);
256
794
      break;
257
258
340
    case ']': /* EMAC ACCEXT bit.  */
259
340
      val = buffer[0] >> 2;
260
340
      break;
261
262
17.4k
    case 'I': /* MAC/EMAC scale factor.  */
263
17.4k
      val = buffer[2] >> 1;
264
17.4k
      break;
265
266
686
    case 'F': /* EMAC ACCx.  */
267
686
      val = buffer[0] >> 1;
268
686
      break;
269
270
262
    case 'f':
271
262
      val = buffer[1];
272
262
      break;
273
274
1.72M
    case 's':
275
1.72M
      val = buffer[1];
276
1.72M
      break;
277
278
712k
    case 'd':     /* Destination, for register or quick.  */
279
712k
      val = (buffer[0] << 8) + buffer[1];
280
712k
      val >>= 9;
281
712k
      break;
282
283
241k
    case 'x':     /* Destination, for general arg.  */
284
241k
      val = (buffer[0] << 8) + buffer[1];
285
241k
      val >>= 6;
286
241k
      break;
287
288
310
    case 'k':
289
310
      if (! FETCH_DATA (info, buffer + 3))
290
0
  return -1;
291
310
      val = (buffer[3] >> 4);
292
310
      break;
293
294
1.18k
    case 'C':
295
1.18k
      if (! FETCH_DATA (info, buffer + 3))
296
0
  return -1;
297
1.18k
      val = buffer[3];
298
1.18k
      break;
299
300
55.8k
    case '1':
301
55.8k
      if (! FETCH_DATA (info, buffer + 3))
302
0
  return -1;
303
55.8k
      val = (buffer[2] << 8) + buffer[3];
304
55.8k
      val >>= 12;
305
55.8k
      break;
306
307
2.84k
    case '2':
308
2.84k
      if (! FETCH_DATA (info, buffer + 3))
309
0
  return -1;
310
2.84k
      val = (buffer[2] << 8) + buffer[3];
311
2.84k
      val >>= 6;
312
2.84k
      break;
313
314
48.6k
    case '3':
315
51.3k
    case 'j':
316
51.3k
      if (! FETCH_DATA (info, buffer + 3))
317
0
  return -1;
318
51.3k
      val = (buffer[2] << 8) + buffer[3];
319
51.3k
      break;
320
321
666
    case '4':
322
666
      if (! FETCH_DATA (info, buffer + 5))
323
0
  return -1;
324
666
      val = (buffer[4] << 8) + buffer[5];
325
666
      val >>= 12;
326
666
      break;
327
328
666
    case '5':
329
666
      if (! FETCH_DATA (info, buffer + 5))
330
0
  return -1;
331
666
      val = (buffer[4] << 8) + buffer[5];
332
666
      val >>= 6;
333
666
      break;
334
335
666
    case '6':
336
666
      if (! FETCH_DATA (info, buffer + 5))
337
0
  return -1;
338
666
      val = (buffer[4] << 8) + buffer[5];
339
666
      break;
340
341
6.22k
    case '7':
342
6.22k
      if (! FETCH_DATA (info, buffer + 3))
343
0
  return -1;
344
6.22k
      val = (buffer[2] << 8) + buffer[3];
345
6.22k
      val >>= 7;
346
6.22k
      break;
347
348
10.7k
    case '8':
349
10.7k
      if (! FETCH_DATA (info, buffer + 3))
350
0
  return -1;
351
10.7k
      val = (buffer[2] << 8) + buffer[3];
352
10.7k
      val >>= 10;
353
10.7k
      break;
354
355
847
    case '9':
356
847
      if (! FETCH_DATA (info, buffer + 3))
357
0
  return -1;
358
847
      val = (buffer[2] << 8) + buffer[3];
359
847
      val >>= 5;
360
847
      break;
361
362
3.75k
    case 'e':
363
3.75k
      val = (buffer[1] >> 6);
364
3.75k
      break;
365
366
40.6k
    case 'E':
367
40.6k
      if (! FETCH_DATA (info, buffer + 3))
368
0
  return -1;
369
40.6k
      val = (buffer[2] >> 1);
370
40.6k
      break;
371
372
8.20k
    case 'm':
373
8.20k
      val = (buffer[1] & 0x40 ? 0x8 : 0)
374
8.20k
  | ((buffer[0] >> 1) & 0x7)
375
8.20k
  | (buffer[3] & 0x80 ? 0x10 : 0);
376
8.20k
      break;
377
378
11.1k
    case 'n':
379
11.1k
      val = (buffer[1] & 0x40 ? 0x8 : 0) | ((buffer[0] >> 1) & 0x7);
380
11.1k
      break;
381
382
15.0k
    case 'o':
383
15.0k
      val = (buffer[2] >> 4) | (buffer[3] & 0x80 ? 0x10 : 0);
384
15.0k
      break;
385
386
8.20k
    case 'M':
387
8.20k
      val = (buffer[1] & 0xf) | (buffer[3] & 0x40 ? 0x10 : 0);
388
8.20k
      break;
389
390
15.0k
    case 'N':
391
15.0k
      val = (buffer[3] & 0xf) | (buffer[3] & 0x40 ? 0x10 : 0);
392
15.0k
      break;
393
394
962
    case 'h':
395
962
      val = buffer[2] >> 2;
396
962
      break;
397
398
0
    default:
399
0
      abort ();
400
2.94M
    }
401
402
  /* bits is never too big.  */
403
2.94M
  return val & ((1 << bits) - 1);
404
2.94M
}
405
406
/* Check if an EA is valid for a particular code.  This is required
407
   for the EMAC instructions since the type of source address determines
408
   if it is a EMAC-load instruciton if the EA is mode 2-5, otherwise it
409
   is a non-load EMAC instruction and the bits mean register Ry.
410
   A similar case exists for the movem instructions where the register
411
   mask is interpreted differently for different EAs.  */
412
413
static bool
414
m68k_valid_ea (char code, int val)
415
1.79M
{
416
1.79M
  int mode, mask;
417
1.79M
#define M(n0,n1,n2,n3,n4,n5,n6,n70,n71,n72,n73,n74) \
418
1.79M
  (n0 | n1 << 1 | n2 << 2 | n3 << 3 | n4 << 4 | n5 << 5 | n6 << 6 \
419
1.79M
   | n70 << 7 | n71 << 8 | n72 << 9 | n73 << 10 | n74 << 11)
420
421
1.79M
  switch (code)
422
1.79M
    {
423
312k
    case '*':
424
312k
      mask = M (1,1,1,1,1,1,1,1,1,1,1,1);
425
312k
      break;
426
70.3k
    case '~':
427
70.3k
      mask = M (0,0,1,1,1,1,1,1,1,0,0,0);
428
70.3k
      break;
429
251k
    case '%':
430
251k
      mask = M (1,1,1,1,1,1,1,1,1,0,0,0);
431
251k
      break;
432
267k
    case ';':
433
267k
      mask = M (1,0,1,1,1,1,1,1,1,1,1,1);
434
267k
      break;
435
8.34k
    case '@':
436
8.34k
      mask = M (1,0,1,1,1,1,1,1,1,1,1,0);
437
8.34k
      break;
438
13.0k
    case '!':
439
13.0k
      mask = M (0,0,1,0,0,1,1,1,1,1,1,0);
440
13.0k
      break;
441
3.79k
    case '&':
442
3.79k
      mask = M (0,0,1,0,0,1,1,1,1,0,0,0);
443
3.79k
      break;
444
685k
    case '$':
445
685k
      mask = M (1,0,1,1,1,1,1,1,1,0,0,0);
446
685k
      break;
447
881
    case '?':
448
881
      mask = M (1,0,1,0,0,1,1,1,1,0,0,0);
449
881
      break;
450
1.44k
    case '/':
451
1.44k
      mask = M (1,0,1,0,0,1,1,1,1,1,1,0);
452
1.44k
      break;
453
316
    case '|':
454
316
      mask = M (0,0,1,0,0,1,1,1,1,1,1,0);
455
316
      break;
456
2.08k
    case '>':
457
2.08k
      mask = M (0,0,1,0,1,1,1,1,1,0,0,0);
458
2.08k
      break;
459
3.59k
    case '<':
460
3.59k
      mask = M (0,0,1,1,0,1,1,1,1,1,1,0);
461
3.59k
      break;
462
41.5k
    case 'm':
463
41.5k
      mask = M (1,1,1,1,1,0,0,0,0,0,0,0);
464
41.5k
      break;
465
33.4k
    case 'n':
466
33.4k
      mask = M (0,0,0,0,0,1,0,0,0,1,0,0);
467
33.4k
      break;
468
27.4k
    case 'o':
469
27.4k
      mask = M (0,0,0,0,0,0,1,1,1,0,1,1);
470
27.4k
      break;
471
50.2k
    case 'p':
472
50.2k
      mask = M (1,1,1,1,1,1,0,0,0,0,0,0);
473
50.2k
      break;
474
4.53k
    case 'q':
475
4.53k
      mask = M (1,0,1,1,1,1,0,0,0,0,0,0);
476
4.53k
      break;
477
2.53k
    case 'v':
478
2.53k
      mask = M (1,0,1,1,1,1,0,1,1,0,0,0);
479
2.53k
      break;
480
85
    case 'b':
481
85
      mask = M (1,0,1,1,1,1,0,0,0,1,0,0);
482
85
      break;
483
70
    case 'w':
484
70
      mask = M (0,0,1,1,1,1,0,0,0,1,0,0);
485
70
      break;
486
2.00k
    case 'y':
487
2.00k
      mask = M (0,0,1,0,0,1,0,0,0,0,0,0);
488
2.00k
      break;
489
300
    case 'z':
490
300
      mask = M (0,0,1,0,0,1,0,0,0,1,0,0);
491
300
      break;
492
12.7k
    case '4':
493
12.7k
      mask = M (0,0,1,1,1,1,0,0,0,0,0,0);
494
12.7k
      break;
495
0
    default:
496
0
      abort ();
497
1.79M
    }
498
1.79M
#undef M
499
500
1.79M
  mode = (val >> 3) & 7;
501
1.79M
  if (mode == 7)
502
215k
    mode += val & 7;
503
1.79M
  return (mask & (1 << mode)) != 0;
504
1.79M
}
505
506
/* Print a base register REGNO and displacement DISP, on INFO->STREAM.
507
   REGNO = -1 for pc, -2 for none (suppressed).  */
508
509
static void
510
print_base (int regno, bfd_vma disp, disassemble_info *info)
511
132k
{
512
132k
  if (regno == -1)
513
7.68k
    {
514
7.68k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%pc");
515
7.68k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
516
7.68k
      (*info->print_address_func) (disp, info);
517
7.68k
    }
518
125k
  else
519
125k
    {
520
125k
      if (regno == -3)
521
1.63k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
522
1.63k
              "%%zpc");
523
123k
      else if (regno != -2)
524
103k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
525
103k
              "%s", reg_names[regno]);
526
125k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
527
125k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
528
125k
            "%" PRIx64, (uint64_t) disp);
529
125k
    }
530
132k
}
531
532
/* Print the index register of an indexed argument, as encoded in the
533
   extension word.  */
534
535
static void
536
print_index_register (int ext, disassemble_info *info)
537
106k
{
538
106k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
539
106k
        "%s", reg_names[(ext >> 12) & 0xf]);
540
106k
  (*info->fprintf_styled_func) (info->stream, dis_style_text,
541
106k
        ":%c", ext & 0x800 ? 'l' : 'w');
542
106k
  if ((ext >> 9) & 3)
543
63.8k
    {
544
63.8k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ":");
545
63.8k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
546
63.8k
            "%d", 1 << ((ext >> 9) & 3));
547
63.8k
    }
548
106k
}
549
550
/* Print an indexed argument.  The base register is BASEREG (-1 for pc).
551
   P points to extension word, in buffer.
552
   ADDR is the nominal core address of that extension word.
553
   Returns NULL upon error.  */
554
555
static unsigned char *
556
print_indexed (int basereg,
557
         unsigned char *p,
558
         bfd_vma addr,
559
         disassemble_info *info)
560
133k
{
561
133k
  int word;
562
133k
  bfd_vma base_disp;
563
133k
  bfd_vma outer_disp;
564
133k
  bool print_index = true;
565
566
133k
  NEXTWORD (p, word, NULL);
567
568
  /* Handle the 68000 style of indexing.  */
569
570
132k
  if ((word & 0x100) == 0)
571
75.1k
    {
572
75.1k
      base_disp = word & 0xff;
573
75.1k
      if ((base_disp & 0x80) != 0)
574
24.6k
  base_disp -= 0x100;
575
75.1k
      if (basereg == -1)
576
3.16k
  base_disp += addr;
577
75.1k
      print_base (basereg, base_disp, info);
578
75.1k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ",");
579
75.1k
      print_index_register (word, info);
580
75.1k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
581
75.1k
      return p;
582
75.1k
    }
583
584
  /* Handle the generalized kind.  */
585
  /* First, compute the displacement to add to the base register.  */
586
57.8k
  if (word & 0200)
587
21.5k
    {
588
21.5k
      if (basereg == -1)
589
1.63k
  basereg = -3;
590
19.8k
      else
591
19.8k
  basereg = -2;
592
21.5k
    }
593
57.8k
  if (word & 0100)
594
26.0k
    print_index = false;
595
57.8k
  base_disp = 0;
596
57.8k
  switch ((word >> 4) & 3)
597
57.8k
    {
598
12.3k
    case 2:
599
12.3k
      NEXTWORD (p, base_disp, NULL);
600
12.3k
      break;
601
24.4k
    case 3:
602
24.4k
      NEXTLONG (p, base_disp, NULL);
603
57.8k
    }
604
57.7k
  if (basereg == -1)
605
4.52k
    base_disp += addr;
606
607
  /* Handle single-level case (not indirect).  */
608
57.7k
  if ((word & 7) == 0)
609
9.90k
    {
610
9.90k
      print_base (basereg, base_disp, info);
611
9.90k
      if (print_index)
612
7.47k
  {
613
7.47k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, ",");
614
7.47k
    print_index_register (word, info);
615
7.47k
  }
616
9.90k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
617
9.90k
      return p;
618
9.90k
    }
619
620
  /* Two level.  Compute displacement to add after indirection.  */
621
47.8k
  outer_disp = 0;
622
47.8k
  switch (word & 3)
623
47.8k
    {
624
13.1k
    case 2:
625
13.1k
      NEXTWORD (p, outer_disp, NULL);
626
13.1k
      break;
627
14.7k
    case 3:
628
14.7k
      NEXTLONG (p, outer_disp, NULL);
629
47.8k
    }
630
631
47.7k
  print_base (basereg, base_disp, info);
632
47.7k
  if ((word & 4) == 0 && print_index)
633
12.1k
    {
634
12.1k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ",");
635
12.1k
      print_index_register (word, info);
636
12.1k
      print_index = false;
637
12.1k
    }
638
47.7k
  (*info->fprintf_styled_func) (info->stream, dis_style_text,
639
47.7k
        ")@(");
640
47.7k
  (*info->fprintf_styled_func) (info->stream, dis_style_address_offset,
641
47.7k
        "%" PRIx64, (uint64_t) outer_disp);
642
47.7k
  if (print_index)
643
12.1k
    {
644
12.1k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ",");
645
12.1k
      print_index_register (word, info);
646
12.1k
    }
647
47.7k
  (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
648
649
47.7k
  return p;
650
47.8k
}
651
652
#define FETCH_ARG(size, val)        \
653
1.08M
  do              \
654
1.08M
    {             \
655
1.08M
      val = fetch_arg (buffer, place, size, info);  \
656
1.08M
      if (val < 0)         \
657
1.08M
  return PRINT_INSN_ARG_MEMORY_ERROR;   \
658
1.08M
    }             \
659
1.08M
  while (0)
660
661
/* Returns number of bytes "eaten" by the operand, or
662
   return enum print_insn_arg_error.  ADDR is the pc for this arg to be
663
   relative to.  */
664
665
static int
666
print_insn_arg (const char *d,
667
    unsigned char *buffer,
668
    unsigned char *p0,
669
    bfd_vma addr,
670
    disassemble_info *info)
671
3.58M
{
672
3.58M
  int val = 0;
673
3.58M
  int place = d[1];
674
3.58M
  unsigned char *p = p0;
675
3.58M
  int regno;
676
3.58M
  const char *regname;
677
3.58M
  unsigned char *p1;
678
3.58M
  double flval;
679
3.58M
  int flt_p;
680
3.58M
  bfd_signed_vma disp;
681
3.58M
  unsigned int uval;
682
683
3.58M
  switch (*d)
684
3.58M
    {
685
3.75k
    case 'c':   /* Cache identifier.  */
686
3.75k
      {
687
3.75k
        static char *const cacheFieldName[] = { "nc", "dc", "ic", "bc" };
688
3.75k
        FETCH_ARG (2, val);
689
3.75k
  (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic,
690
3.75k
              "%s", cacheFieldName[val]);
691
3.75k
        break;
692
3.75k
      }
693
694
5.94k
    case 'a':   /* Address register indirect only. Cf. case '+'.  */
695
5.94k
      {
696
5.94k
  FETCH_ARG (3, val);
697
5.94k
  (*info->fprintf_styled_func) (info->stream, dis_style_register, "%s",
698
5.94k
              reg_names[val + 8]);
699
5.94k
  (*info->fprintf_styled_func) (info->stream, dis_style_text, "@");
700
5.94k
        break;
701
5.94k
      }
702
703
1.21k
    case '_':   /* 32-bit absolute address for move16.  */
704
1.21k
      {
705
1.21k
        NEXTULONG (p, uval);
706
1.20k
  (*info->print_address_func) (uval, info);
707
1.20k
        break;
708
1.21k
      }
709
710
2.58k
    case 'C':
711
2.58k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%ccr");
712
2.58k
      break;
713
714
1.76k
    case 'S':
715
1.76k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%sr");
716
1.76k
      break;
717
718
558
    case 'U':
719
558
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%usp");
720
558
      break;
721
722
1.23k
    case 'E':
723
1.23k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%acc");
724
1.23k
      break;
725
726
744
    case 'G':
727
744
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%macsr");
728
744
      break;
729
730
2.48k
    case 'H':
731
2.48k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%mask");
732
2.48k
      break;
733
734
2.63k
    case 'J':
735
2.63k
      {
736
  /* FIXME: There's a problem here, different m68k processors call the
737
     same address different names.  The tables below try to get it right
738
     using info->mach, but only for v4e.  */
739
2.63k
  struct regname { char * name; int value; };
740
2.63k
  static const struct regname names[] =
741
2.63k
    {
742
2.63k
      {"%sfc", 0x000}, {"%dfc", 0x001}, {"%cacr", 0x002},
743
2.63k
      {"%tc",  0x003}, {"%itt0",0x004}, {"%itt1", 0x005},
744
2.63k
      {"%dtt0",0x006}, {"%dtt1",0x007}, {"%buscr",0x008},
745
2.63k
      {"%rgpiobar", 0x009}, {"%acr4",0x00c},
746
2.63k
      {"%acr5",0x00d}, {"%acr6",0x00e}, {"%acr7", 0x00f},
747
2.63k
      {"%usp", 0x800}, {"%vbr", 0x801}, {"%caar", 0x802},
748
2.63k
      {"%msp", 0x803}, {"%isp", 0x804},
749
2.63k
      {"%pc", 0x80f},
750
      /* Reg c04 is sometimes called flashbar or rambar.
751
         Reg c05 is also sometimes called rambar.  */
752
2.63k
      {"%rambar0", 0xc04}, {"%rambar1", 0xc05},
753
754
      /* reg c0e is sometimes called mbar2 or secmbar.
755
         reg c0f is sometimes called mbar.  */
756
2.63k
      {"%mbar0", 0xc0e}, {"%mbar1", 0xc0f},
757
758
      /* Should we be calling this psr like we do in case 'Y'?  */
759
2.63k
      {"%mmusr",0x805},
760
761
2.63k
      {"%urp", 0x806}, {"%srp", 0x807}, {"%pcr", 0x808},
762
763
      /* Fido added these.  */
764
2.63k
      {"%cac", 0xffe}, {"%mbo", 0xfff}
765
2.63k
  };
766
  /* Alternate names for v4e (MCF5407/5445x/MCF547x/MCF548x), at least.  */
767
2.63k
  static const struct regname names_v4e[] =
768
2.63k
    {
769
2.63k
      {"%asid",0x003}, {"%acr0",0x004}, {"%acr1",0x005},
770
2.63k
      {"%acr2",0x006}, {"%acr3",0x007}, {"%mmubar",0x008},
771
2.63k
    };
772
2.63k
  unsigned int arch_mask;
773
774
2.63k
  arch_mask = bfd_m68k_mach_to_features (info->mach);
775
2.63k
  FETCH_ARG (12, val);
776
2.63k
  if (arch_mask & (mcfisa_b | mcfisa_c))
777
916
    {
778
6.28k
      for (regno = ARRAY_SIZE (names_v4e); --regno >= 0;)
779
5.49k
        if (names_v4e[regno].value == val)
780
128
    {
781
128
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
782
128
                 "%s", names_v4e[regno].name);
783
128
      break;
784
128
    }
785
916
      if (regno >= 0)
786
128
        break;
787
916
    }
788
74.7k
  for (regno = ARRAY_SIZE (names) - 1; regno >= 0; regno--)
789
72.9k
    if (names[regno].value == val)
790
692
      {
791
692
        (*info->fprintf_styled_func) (info->stream, dis_style_register,
792
692
              "%s", names[regno].name);
793
692
        break;
794
692
      }
795
2.50k
  if (regno < 0)
796
1.81k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "0x%x", val);
797
2.50k
      }
798
0
      break;
799
800
124k
    case 'Q':
801
124k
      FETCH_ARG (3, val);
802
      /* 0 means 8, except for the bkpt instruction... */
803
124k
      if (val == 0 && d[1] != 's')
804
8.37k
  val = 8;
805
124k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
806
124k
            "#%d", val);
807
124k
      break;
808
809
4.61k
    case 'x':
810
4.61k
      FETCH_ARG (3, val);
811
      /* 0 means -1.  */
812
4.61k
      if (val == 0)
813
770
  val = -1;
814
4.61k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
815
4.61k
            "#%d", val);
816
4.61k
      break;
817
818
40.6k
    case 'j':
819
40.6k
      FETCH_ARG (3, val);
820
40.6k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
821
40.6k
            "#%d", val+1);
822
40.6k
      break;
823
824
39.9k
    case 'K':
825
39.9k
      FETCH_ARG (9, val);
826
39.9k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
827
39.9k
            "#%d", val);
828
39.9k
      break;
829
830
53.2k
    case 'M':
831
53.2k
      if (place == 'h')
832
962
  {
833
962
    static char *const scalefactor_name[] = { "<<", ">>" };
834
835
962
    FETCH_ARG (1, val);
836
962
    (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic,
837
962
          "%s", scalefactor_name[val]);
838
962
  }
839
52.3k
      else
840
52.3k
  {
841
52.3k
    FETCH_ARG (8, val);
842
52.3k
    if (val & 0x80)
843
13.4k
      val = val - 0x100;
844
52.3k
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
845
52.3k
          "#%d", val);
846
52.3k
  }
847
53.2k
      break;
848
849
53.2k
    case 'T':
850
8.73k
      FETCH_ARG (4, val);
851
8.73k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
852
8.73k
            "#%d", val);
853
8.73k
      break;
854
855
528k
    case 'D':
856
528k
      FETCH_ARG (3, val);
857
528k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
858
528k
            "%s", reg_names[val]);
859
528k
      break;
860
861
67.5k
    case 'A':
862
67.5k
      FETCH_ARG (3, val);
863
67.5k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
864
67.5k
            "%s", reg_names[val + 010]);
865
67.5k
      break;
866
867
89.8k
    case 'R':
868
89.8k
      FETCH_ARG (4, val);
869
89.8k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
870
89.8k
            "%s", reg_names[val]);
871
89.8k
      break;
872
873
1.33k
    case 'r':
874
1.33k
      FETCH_ARG (4, regno);
875
1.33k
      if (regno > 7)
876
324
  {
877
324
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
878
324
          "%s", reg_names[regno]);
879
324
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@");
880
324
  }
881
1.00k
      else
882
1.00k
  {
883
1.00k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
884
1.00k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
885
1.00k
          "%s", reg_names[regno]);
886
1.00k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
887
1.00k
  }
888
1.33k
      break;
889
890
8.09k
    case 'F':
891
8.09k
      FETCH_ARG (3, val);
892
8.09k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
893
8.09k
            "%%fp%d", val);
894
8.09k
      break;
895
896
4.10k
    case 'O':
897
4.10k
      FETCH_ARG (6, val);
898
4.10k
      if (val & 0x20)
899
2.50k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
900
2.50k
              "%s", reg_names[val & 7]);
901
1.59k
      else
902
1.59k
  (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
903
1.59k
              "%d", val);
904
4.10k
      break;
905
906
5.83k
    case '+':
907
5.83k
      FETCH_ARG (3, val);
908
5.83k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
909
5.83k
            "%s", reg_names[val + 8]);
910
5.83k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, "@+");
911
5.83k
      break;
912
913
13.7k
    case '-':
914
13.7k
      FETCH_ARG (3, val);
915
13.7k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
916
13.7k
            "%s", reg_names[val + 8]);
917
13.7k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, "@-");
918
13.7k
      break;
919
920
1.14k
    case 'k':
921
1.14k
      if (place == 'k')
922
0
  {
923
0
    FETCH_ARG (3, val);
924
0
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "{");
925
0
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
926
0
          "%s", reg_names[val]);
927
0
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "}");
928
0
  }
929
1.14k
      else if (place == 'C')
930
1.14k
  {
931
1.14k
    FETCH_ARG (7, val);
932
1.14k
    if (val > 63)    /* This is a signed constant.  */
933
914
      val -= 128;
934
1.14k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "{");
935
1.14k
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
936
1.14k
          "#%d", val);
937
1.14k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "}");
938
1.14k
  }
939
0
      else
940
0
  return PRINT_INSN_ARG_INVALID_OPERAND;
941
1.14k
      break;
942
943
540k
    case '#':
944
542k
    case '^':
945
542k
      p1 = buffer + (*d == '#' ? 2 : 4);
946
542k
      if (place == 's')
947
0
  FETCH_ARG (4, val);
948
542k
      else if (place == 'C')
949
38
  FETCH_ARG (7, val);
950
542k
      else if (place == '8')
951
0
  FETCH_ARG (3, val);
952
542k
      else if (place == '3')
953
960
  FETCH_ARG (8, val);
954
541k
      else if (place == 'b')
955
453k
  NEXTBYTE (p1, val);
956
87.3k
      else if (place == 'w' || place == 'W')
957
58.5k
  NEXTWORD (p1, val, PRINT_INSN_ARG_MEMORY_ERROR);
958
28.7k
      else if (place == 'l')
959
28.7k
  NEXTLONG (p1, val, PRINT_INSN_ARG_MEMORY_ERROR);
960
0
      else
961
0
  return PRINT_INSN_ARG_INVALID_OP_TABLE;
962
963
542k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
964
542k
            "#%d", val);
965
542k
      break;
966
967
138k
    case 'B':
968
138k
      if (place == 'b')
969
0
  NEXTBYTE (p, disp);
970
138k
      else if (place == 'B')
971
119k
  disp = COERCE_SIGNED_CHAR (buffer[1]);
972
18.3k
      else if (place == 'w' || place == 'W')
973
11.1k
  NEXTWORD (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
974
7.23k
      else if (place == 'l' || place == 'L' || place == 'C')
975
5.57k
  NEXTLONG (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
976
1.66k
      else if (place == 'g')
977
0
  {
978
0
    NEXTBYTE (buffer, disp);
979
0
    if (disp == 0)
980
0
      NEXTWORD (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
981
0
    else if (disp == -1)
982
0
      NEXTLONG (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
983
0
  }
984
1.66k
      else if (place == 'c')
985
1.66k
  {
986
1.66k
    if (buffer[1] & 0x40)    /* If bit six is one, long offset.  */
987
1.04k
      NEXTLONG (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
988
620
    else
989
620
      NEXTWORD (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
990
1.66k
  }
991
0
      else
992
0
  return PRINT_INSN_ARG_INVALID_OP_TABLE;
993
994
137k
      info->target = addr + disp;
995
996
137k
      (*info->print_address_func) (addr + disp, info);
997
137k
      break;
998
999
11.6k
    case 'd':
1000
11.6k
      {
1001
11.6k
  int val1;
1002
1003
11.6k
  NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1004
11.6k
  FETCH_ARG (3, val1);
1005
11.6k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
1006
11.6k
              "%s", reg_names[val1 + 8]);
1007
11.6k
  (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
1008
11.6k
  (*info->fprintf_styled_func) (info->stream, dis_style_address_offset,
1009
11.6k
              "%d", val);
1010
11.6k
  (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
1011
11.6k
  break;
1012
11.6k
      }
1013
1014
951
    case 's':
1015
951
      FETCH_ARG (3, val);
1016
951
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1017
951
            "%s", fpcr_names[val]);
1018
951
      break;
1019
1020
3.72k
    case 'e':
1021
3.72k
      FETCH_ARG (2, val);
1022
3.72k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1023
3.72k
            "%%acc%d", val);
1024
3.72k
      break;
1025
1026
340
    case 'g':
1027
340
      FETCH_ARG (1, val);
1028
340
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1029
340
            "%%accext%s", val == 0 ? "01" : "23");
1030
340
      break;
1031
1032
17.4k
    case 'i':
1033
17.4k
      FETCH_ARG (2, val);
1034
17.4k
      if (val == 1)
1035
4.90k
  (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic,
1036
4.90k
              "<<");
1037
12.5k
      else if (val == 3)
1038
5.41k
  (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic,
1039
5.41k
              ">>");
1040
7.10k
      else
1041
7.10k
  return PRINT_INSN_ARG_INVALID_OPERAND;
1042
10.3k
      break;
1043
1044
14.3k
    case 'I':
1045
      /* Get coprocessor ID... */
1046
14.3k
      val = fetch_arg (buffer, 'd', 3, info);
1047
14.3k
      if (val < 0)
1048
0
  return PRINT_INSN_ARG_MEMORY_ERROR;
1049
14.3k
      if (val != 1)        /* Unusual coprocessor ID?  */
1050
0
  (*info->fprintf_styled_func) (info->stream, dis_style_text,
1051
0
              "(cpid=%d) ", val);
1052
14.3k
      break;
1053
1054
12.7k
    case '4':
1055
325k
    case '*':
1056
396k
    case '~':
1057
647k
    case '%':
1058
915k
    case ';':
1059
923k
    case '@':
1060
936k
    case '!':
1061
1.62M
    case '$':
1062
1.62M
    case '?':
1063
1.62M
    case '/':
1064
1.62M
    case '&':
1065
1.62M
    case '|':
1066
1.63M
    case '<':
1067
1.63M
    case '>':
1068
1.67M
    case 'm':
1069
1.70M
    case 'n':
1070
1.73M
    case 'o':
1071
1.78M
    case 'p':
1072
1.79M
    case 'q':
1073
1.79M
    case 'v':
1074
1.79M
    case 'b':
1075
1.79M
    case 'w':
1076
1.79M
    case 'y':
1077
1.79M
    case 'z':
1078
1.79M
      if (place == 'd')
1079
241k
  {
1080
241k
    val = fetch_arg (buffer, 'x', 6, info);
1081
241k
    if (val < 0)
1082
0
      return PRINT_INSN_ARG_MEMORY_ERROR;
1083
241k
    val = ((val & 7) << 3) + ((val >> 3) & 7);
1084
241k
  }
1085
1.55M
      else
1086
1.55M
  {
1087
1.55M
    val = fetch_arg (buffer, 's', 6, info);
1088
1.55M
    if (val < 0)
1089
0
      return PRINT_INSN_ARG_MEMORY_ERROR;
1090
1.55M
  }
1091
1092
      /* If the <ea> is invalid for *d, then reject this match.  */
1093
1.79M
      if (!m68k_valid_ea (*d, val))
1094
271k
  return PRINT_INSN_ARG_INVALID_OPERAND;
1095
1096
      /* Get register number assuming address register.  */
1097
1.52M
      regno = (val & 7) + 8;
1098
1.52M
      regname = reg_names[regno];
1099
1.52M
      switch (val >> 3)
1100
1.52M
  {
1101
745k
  case 0:
1102
745k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1103
745k
          "%s", reg_names[val]);
1104
745k
    break;
1105
1106
35.1k
  case 1:
1107
35.1k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1108
35.1k
          "%s", regname);
1109
35.1k
    break;
1110
1111
108k
  case 2:
1112
108k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1113
108k
          "%s", regname);
1114
108k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@");
1115
108k
    break;
1116
1117
159k
  case 3:
1118
159k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1119
159k
          "%s", regname);
1120
159k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@+");
1121
159k
    break;
1122
1123
173k
  case 4:
1124
173k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1125
173k
          "%s", regname);
1126
173k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@-");
1127
173k
    break;
1128
1129
112k
  case 5:
1130
112k
    NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1131
111k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1132
111k
          "%s", regname);
1133
111k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
1134
111k
    (*info->fprintf_styled_func) (info->stream, dis_style_address_offset,
1135
111k
          "%d", val);
1136
111k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
1137
111k
    break;
1138
1139
123k
  case 6:
1140
123k
    p = print_indexed (regno, p, addr, info);
1141
123k
    if (p == NULL)
1142
245
      return PRINT_INSN_ARG_MEMORY_ERROR;
1143
123k
    break;
1144
1145
123k
  case 7:
1146
65.8k
    switch (val & 7)
1147
65.8k
      {
1148
15.4k
      case 0:
1149
15.4k
        NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1150
15.4k
        (*info->print_address_func) (val, info);
1151
15.4k
        break;
1152
1153
15.4k
      case 1:
1154
15.4k
        NEXTULONG (p, uval);
1155
15.4k
        (*info->print_address_func) (uval, info);
1156
15.4k
        break;
1157
1158
10.4k
      case 2:
1159
10.4k
        NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1160
10.3k
        (*info->fprintf_styled_func) (info->stream, dis_style_register,
1161
10.3k
              "%%pc");
1162
10.3k
        (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
1163
10.3k
        (*info->print_address_func) (addr + val, info);
1164
10.3k
        (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
1165
10.3k
        break;
1166
1167
9.34k
      case 3:
1168
9.34k
        p = print_indexed (-1, p, addr, info);
1169
9.34k
        if (p == NULL)
1170
31
    return PRINT_INSN_ARG_MEMORY_ERROR;
1171
9.31k
        break;
1172
1173
15.2k
      case 4:
1174
15.2k
        flt_p = 1;  /* Assume it's a float... */
1175
15.2k
        switch (place)
1176
15.2k
        {
1177
2.25k
    case 'b':
1178
2.25k
      NEXTBYTE (p, val);
1179
2.24k
      flt_p = 0;
1180
2.24k
      break;
1181
1182
7.37k
    case 'w':
1183
7.37k
      NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1184
7.35k
      flt_p = 0;
1185
7.35k
      break;
1186
1187
2.55k
    case 'l':
1188
2.55k
      NEXTLONG (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1189
2.53k
      flt_p = 0;
1190
2.53k
      break;
1191
1192
376
    case 'f':
1193
376
      NEXTSINGLE (flval, p);
1194
376
      break;
1195
1196
911
    case 'F':
1197
911
      NEXTDOUBLE (flval, p);
1198
910
      break;
1199
1200
910
    case 'x':
1201
840
      NEXTEXTEND (flval, p);
1202
838
      break;
1203
1204
895
    case 'p':
1205
895
      NEXTPACKED (p, flval);
1206
888
      break;
1207
1208
888
    default:
1209
0
      return PRINT_INSN_ARG_INVALID_OPERAND;
1210
15.2k
        }
1211
15.1k
        if (flt_p)  /* Print a float? */
1212
3.01k
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1213
3.01k
                "#0e%g", flval);
1214
12.1k
        else
1215
12.1k
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1216
12.1k
                "#%d", val);
1217
15.1k
        break;
1218
1219
0
      default:
1220
0
        return PRINT_INSN_ARG_INVALID_OPERAND;
1221
65.8k
      }
1222
1.52M
  }
1223
1224
      /* If place is '/', then this is the case of the mask bit for
1225
   mac/emac loads. Now that the arg has been printed, grab the
1226
   mask bit and if set, add a '&' to the arg.  */
1227
1.52M
      if (place == '/')
1228
11.1k
  {
1229
11.1k
    FETCH_ARG (1, val);
1230
11.1k
    if (val)
1231
9.41k
      info->fprintf_styled_func (info->stream, dis_style_text, "&");
1232
11.1k
  }
1233
1.52M
      break;
1234
1235
1.52M
    case 'L':
1236
6.17k
    case 'l':
1237
6.17k
  if (place == 'w')
1238
4.51k
    {
1239
4.51k
      char doneany;
1240
4.51k
      p1 = buffer + 2;
1241
4.51k
      NEXTWORD (p1, val, PRINT_INSN_ARG_MEMORY_ERROR);
1242
      /* Move the pointer ahead if this point is farther ahead
1243
         than the last.  */
1244
4.51k
      p = p1 > p ? p1 : p;
1245
4.51k
      if (val == 0)
1246
432
        {
1247
432
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1248
432
                "#0");
1249
432
    break;
1250
432
        }
1251
4.08k
      if (*d == 'l')
1252
1.10k
        {
1253
1.10k
    int newval = 0;
1254
1255
18.7k
    for (regno = 0; regno < 16; ++regno)
1256
17.6k
      if (val & (0x8000 >> regno))
1257
5.56k
        newval |= 1 << regno;
1258
1.10k
    val = newval;
1259
1.10k
        }
1260
4.08k
      val &= 0xffff;
1261
4.08k
      doneany = 0;
1262
53.8k
      for (regno = 0; regno < 16; ++regno)
1263
49.7k
        if (val & (1 << regno))
1264
12.8k
    {
1265
12.8k
      int first_regno;
1266
1267
12.8k
      if (doneany)
1268
8.73k
        (*info->fprintf_styled_func) (info->stream, dis_style_text,
1269
8.73k
              "/");
1270
12.8k
      doneany = 1;
1271
12.8k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1272
12.8k
            "%s", reg_names[regno]);
1273
12.8k
      first_regno = regno;
1274
28.4k
      while (val & (1 << (regno + 1)))
1275
15.6k
        ++regno;
1276
12.8k
      if (regno > first_regno)
1277
6.35k
        {
1278
6.35k
          (*info->fprintf_styled_func) (info->stream,
1279
6.35k
                dis_style_text, "-");
1280
6.35k
          (*info->fprintf_styled_func) (info->stream,
1281
6.35k
                dis_style_register, "%s",
1282
6.35k
                reg_names[regno]);
1283
6.35k
        }
1284
12.8k
    }
1285
4.08k
    }
1286
1.65k
  else if (place == '3')
1287
1.06k
    {
1288
      /* `fmovem' insn.  */
1289
1.06k
      char doneany;
1290
1291
1.06k
      FETCH_ARG (8, val);
1292
1.06k
      if (val == 0)
1293
209
        {
1294
209
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1295
209
                "#0");
1296
209
    break;
1297
209
        }
1298
857
      if (*d == 'l')
1299
795
        {
1300
795
    int newval = 0;
1301
1302
7.15k
    for (regno = 0; regno < 8; ++regno)
1303
6.36k
      if (val & (0x80 >> regno))
1304
3.88k
        newval |= 1 << regno;
1305
795
    val = newval;
1306
795
        }
1307
857
      val &= 0xff;
1308
857
      doneany = 0;
1309
4.82k
      for (regno = 0; regno < 8; ++regno)
1310
3.96k
        if (val & (1 << regno))
1311
1.17k
    {
1312
1.17k
      int first_regno;
1313
1.17k
      if (doneany)
1314
318
        (*info->fprintf_styled_func) (info->stream, dis_style_text,
1315
318
              "/");
1316
1.17k
      doneany = 1;
1317
1.17k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1318
1.17k
            "%%fp%d", regno);
1319
1.17k
      first_regno = regno;
1320
4.06k
      while (val & (1 << (regno + 1)))
1321
2.89k
        ++regno;
1322
1.17k
      if (regno > first_regno)
1323
578
        {
1324
578
          (*info->fprintf_styled_func) (info->stream,
1325
578
                dis_style_text, "-");
1326
578
          (*info->fprintf_styled_func) (info->stream,
1327
578
                dis_style_register,
1328
578
                "%%fp%d", regno);
1329
578
        }
1330
1.17k
    }
1331
857
    }
1332
590
  else if (place == '8')
1333
590
    {
1334
590
      FETCH_ARG (3, val);
1335
      /* fmoveml for FP status registers.  */
1336
590
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1337
590
            "%s", fpcr_names[val]);
1338
590
    }
1339
0
  else
1340
0
    return PRINT_INSN_ARG_INVALID_OP_TABLE;
1341
5.53k
      break;
1342
1343
5.53k
    case 'X':
1344
1.18k
      place = '8';
1345
      /* Fall through.  */
1346
1.52k
    case 'Y':
1347
1.59k
    case 'Z':
1348
2.80k
    case 'W':
1349
3.14k
    case '0':
1350
3.75k
    case '1':
1351
5.34k
    case '2':
1352
6.12k
    case '3':
1353
6.12k
      {
1354
6.12k
  char *name = 0;
1355
1356
6.12k
  FETCH_ARG (5, val);
1357
6.12k
  switch (val)
1358
6.12k
    {
1359
506
    case 2: name = "%tt0"; break;
1360
275
    case 3: name = "%tt1"; break;
1361
165
    case 0x10: name = "%tc"; break;
1362
288
    case 0x11: name = "%drp"; break;
1363
124
    case 0x12: name = "%srp"; break;
1364
262
    case 0x13: name = "%crp"; break;
1365
220
    case 0x14: name = "%cal"; break;
1366
516
    case 0x15: name = "%val"; break;
1367
352
    case 0x16: name = "%scc"; break;
1368
1.81k
    case 0x17: name = "%ac"; break;
1369
464
    case 0x18: name = "%psr"; break;
1370
147
    case 0x19: name = "%pcsr"; break;
1371
197
    case 0x1c:
1372
606
    case 0x1d:
1373
606
      {
1374
606
        int break_reg = ((buffer[3] >> 2) & 7);
1375
1376
606
        (*info->fprintf_styled_func)
1377
606
    (info->stream, dis_style_register,
1378
606
     val == 0x1c ? "%%bad%d" : "%%bac%d", break_reg);
1379
606
      }
1380
606
      break;
1381
381
    default:
1382
381
      (*info->fprintf_styled_func) (info->stream, dis_style_text,
1383
381
            "<mmu register %d>", val);
1384
6.12k
    }
1385
6.12k
  if (name)
1386
5.13k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1387
5.13k
          "%s", name);
1388
6.12k
      }
1389
0
      break;
1390
1391
324
    case 'f':
1392
324
      {
1393
324
  int fc;
1394
1395
324
  FETCH_ARG (5, fc);
1396
324
  if (fc == 1)
1397
71
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1398
71
          "%%dfc");
1399
253
  else if (fc == 0)
1400
253
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1401
253
          "%%sfc");
1402
0
  else
1403
    /* xgettext:c-format */
1404
0
    (*info->fprintf_styled_func) (info->stream, dis_style_text,
1405
0
          _("<function code %d>"), fc);
1406
324
      }
1407
0
      break;
1408
1409
124
    case 'V':
1410
124
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%val");
1411
124
      break;
1412
1413
2.96k
    case 't':
1414
2.96k
      {
1415
2.96k
  int level;
1416
1417
2.96k
  FETCH_ARG (3, level);
1418
2.96k
  (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1419
2.96k
              "%d", level);
1420
2.96k
      }
1421
0
      break;
1422
1423
28.5k
    case 'u':
1424
28.5k
      {
1425
28.5k
  short is_upper = 0;
1426
28.5k
  int reg;
1427
1428
28.5k
  FETCH_ARG (5, reg);
1429
28.5k
  if (reg & 0x10)
1430
9.23k
    {
1431
9.23k
      is_upper = 1;
1432
9.23k
      reg &= 0xf;
1433
9.23k
    }
1434
28.5k
  (*info->fprintf_styled_func) (info->stream, dis_style_register, "%s%s",
1435
28.5k
              reg_half_names[reg],
1436
28.5k
              is_upper ? "u" : "l");
1437
28.5k
      }
1438
0
      break;
1439
1440
0
    default:
1441
0
      return PRINT_INSN_ARG_INVALID_OP_TABLE;
1442
3.58M
    }
1443
1444
3.30M
  return p - p0;
1445
3.58M
}
1446
1447
/* Return the insn type determined from the opcode information.  */
1448
1449
static enum dis_insn_type
1450
m68k_opcode_to_insn_type (const struct m68k_opcode *opc)
1451
804k
{
1452
  /* All branches have an operand in 'B' format (the 'B' place only comes
1453
     with the 'B' format).  */
1454
804k
  if (strchr (opc->args, 'B') == NULL)
1455
735k
    return dis_nonbranch;
1456
1457
  /* Most branches are conditional branches, detect the ones that aren't
1458
     from the opcode name.  */
1459
68.9k
  if (strncmp (opc->name, "bra", 3) == 0)
1460
4.10k
    return dis_branch;
1461
1462
64.8k
  if (strncmp (opc->name, "bsr", 3) == 0)
1463
6.09k
    return dis_jsr;
1464
1465
58.7k
  return dis_condbranch;
1466
64.8k
}
1467
1468
/* Try to match the current instruction to best and if so, return the
1469
   number of bytes consumed from the instruction stream, else zero.
1470
   Return -1 on memory error.  */
1471
1472
static int
1473
match_insn_m68k (bfd_vma memaddr,
1474
     disassemble_info * info,
1475
     const struct m68k_opcode * best)
1476
1.08M
{
1477
1.08M
  unsigned char *save_p;
1478
1.08M
  unsigned char *p;
1479
1.08M
  const char *d;
1480
1.08M
  const char *args = best->args;
1481
1482
1.08M
  struct private *priv = (struct private *) info->private_data;
1483
1.08M
  bfd_byte *buffer = priv->the_buffer;
1484
1.08M
  fprintf_styled_ftype save_printer = info->fprintf_styled_func;
1485
1.08M
  void (* save_print_address) (bfd_vma, struct disassemble_info *)
1486
1.08M
    = info->print_address_func;
1487
1488
1.08M
  if (*args == '.')
1489
27.7k
    args++;
1490
1491
  /* Point at first word of argument data,
1492
     and at descriptor for first argument.  */
1493
1.08M
  p = buffer + 2;
1494
1495
  /* Figure out how long the fixed-size portion of the instruction is.
1496
     The only place this is stored in the opcode table is
1497
     in the arguments--look for arguments which specify fields in the 2nd
1498
     or 3rd words of the instruction.  */
1499
3.25M
  for (d = args; *d; d += 2)
1500
2.17M
    {
1501
      /* I don't think it is necessary to be checking d[0] here;
1502
   I suspect all this could be moved to the case statement below.  */
1503
2.17M
      if (d[0] == '#')
1504
296k
  {
1505
296k
    if (d[1] == 'l' && p - buffer < 6)
1506
15.7k
      p = buffer + 6;
1507
281k
    else if (p - buffer < 4 && d[1] != 'C' && d[1] != '8')
1508
280k
      p = buffer + 4;
1509
296k
  }
1510
1511
2.17M
      if ((d[0] == 'L' || d[0] == 'l') && d[1] == 'w' && p - buffer < 4)
1512
4.14k
  p = buffer + 4;
1513
1514
2.17M
      switch (d[1])
1515
2.17M
  {
1516
36.0k
  case '1':
1517
37.8k
  case '2':
1518
73.2k
  case '3':
1519
76.5k
  case '7':
1520
83.8k
  case '8':
1521
84.4k
  case '9':
1522
92.0k
  case 'i':
1523
92.0k
    if (p - buffer < 4)
1524
50.7k
      p = buffer + 4;
1525
92.0k
    break;
1526
333
  case '4':
1527
666
  case '5':
1528
999
  case '6':
1529
999
    if (p - buffer < 6)
1530
333
      p = buffer + 6;
1531
999
    break;
1532
2.07M
  default:
1533
2.07M
    break;
1534
2.17M
  }
1535
2.17M
    }
1536
1537
  /* pflusha is an exceptions.  It takes no arguments but is two words
1538
     long.  Recognize it by looking at the lower 16 bits of the mask.  */
1539
1.08M
  if (p - buffer < 4 && (best->match & 0xFFFF) != 0)
1540
16.2k
    p = buffer + 4;
1541
1542
  /* lpstop is another exception.  It takes a one word argument but is
1543
     three words long.  */
1544
1.08M
  if (p - buffer < 6
1545
1.06M
      && (best->match & 0xffff) == 0xffff
1546
2.51k
      && args[0] == '#'
1547
77
      && args[1] == 'w')
1548
77
    {
1549
      /* Copy the one word argument into the usual location for a one
1550
   word argument, to simplify printing it.  We can get away with
1551
   this because we know exactly what the second word is, and we
1552
   aren't going to print anything based on it.  */
1553
77
      p = buffer + 6;
1554
77
      if (!FETCH_DATA (info, p))
1555
2
  return -1;
1556
75
      buffer[2] = buffer[4];
1557
75
      buffer[3] = buffer[5];
1558
75
    }
1559
1560
1.08M
  if (!FETCH_DATA (info, p))
1561
315
    return -1;
1562
1563
1.08M
  save_p = p;
1564
1.08M
  info->print_address_func = dummy_print_address;
1565
1.08M
  info->fprintf_styled_func = dummy_printer;
1566
1567
  /* We scan the operands twice.  The first time we don't print anything,
1568
     but look for errors.  */
1569
2.81M
  for (d = args; *d; d += 2)
1570
2.00M
    {
1571
2.00M
      int eaten = print_insn_arg (d, buffer, p, memaddr + (p - buffer), info);
1572
1573
2.00M
      if (eaten >= 0)
1574
1.72M
  p += eaten;
1575
279k
      else if (eaten == PRINT_INSN_ARG_INVALID_OPERAND
1576
597
         || eaten == PRINT_INSN_ARG_MEMORY_ERROR)
1577
279k
  {
1578
279k
    info->fprintf_styled_func = save_printer;
1579
279k
    info->print_address_func = save_print_address;
1580
279k
    return eaten == PRINT_INSN_ARG_MEMORY_ERROR ? -1 : 0;
1581
279k
  }
1582
0
      else
1583
0
  {
1584
    /* We must restore the print functions before trying to print the
1585
       error message.  */
1586
0
    info->fprintf_styled_func = save_printer;
1587
0
    info->print_address_func = save_print_address;
1588
0
    info->fprintf_styled_func (info->stream, dis_style_text,
1589
             /* xgettext:c-format */
1590
0
             _("<internal error in opcode table: %s %s>\n"),
1591
0
             best->name, best->args);
1592
0
    return 2;
1593
0
  }
1594
2.00M
    }
1595
1596
804k
  p = save_p;
1597
804k
  info->fprintf_styled_func = save_printer;
1598
804k
  info->print_address_func = save_print_address;
1599
804k
  info->insn_type = m68k_opcode_to_insn_type (best);
1600
1601
804k
  d = args;
1602
1603
804k
  info->fprintf_styled_func (info->stream, dis_style_mnemonic, "%s", best->name);
1604
1605
804k
  if (*d)
1606
804k
    info->fprintf_styled_func (info->stream, dis_style_text, " ");
1607
1608
2.38M
  while (*d)
1609
1.57M
    {
1610
1.57M
      p += print_insn_arg (d, buffer, p, memaddr + (p - buffer), info);
1611
1.57M
      d += 2;
1612
1613
1.57M
      if (*d && *(d - 2) != 'I' && *d != 'k')
1614
766k
  info->fprintf_styled_func (info->stream, dis_style_text, ",");
1615
1.57M
    }
1616
1617
804k
  return p - buffer;
1618
1.08M
}
1619
1620
/* Try to interpret the instruction at address MEMADDR as one that
1621
   can execute on a processor with the features given by ARCH_MASK.
1622
   If successful, print the instruction to INFO->STREAM and return
1623
   its length in bytes.  Return 0 otherwise.  Return -1 on memory
1624
   error.  */
1625
1626
static int
1627
m68k_scan_mask (bfd_vma memaddr, disassemble_info *info,
1628
    unsigned int arch_mask)
1629
1.36M
{
1630
1.36M
  int i;
1631
1.36M
  const char *d;
1632
1.36M
  static const struct m68k_opcode **opcodes[16];
1633
1.36M
  static int numopcodes[16];
1634
1.36M
  int val;
1635
1.36M
  int major_opcode;
1636
1637
1.36M
  struct private *priv = (struct private *) info->private_data;
1638
1.36M
  bfd_byte *buffer = priv->the_buffer;
1639
1640
1.36M
  if (!opcodes[0])
1641
2
    {
1642
      /* Speed up the matching by sorting the opcode
1643
   table on the upper four bits of the opcode.  */
1644
2
      const struct m68k_opcode **opc_pointer[16];
1645
1646
      /* First count how many opcodes are in each of the sixteen buckets.  */
1647
3.81k
      for (i = 0; i < m68k_numopcodes; i++)
1648
3.81k
  numopcodes[(m68k_opcodes[i].opcode >> 28) & 15]++;
1649
1650
      /* Then create a sorted table of pointers
1651
   that point into the unsorted table.  */
1652
2
      opc_pointer[0] = xmalloc (sizeof (struct m68k_opcode *)
1653
2
        * m68k_numopcodes);
1654
2
      opcodes[0] = opc_pointer[0];
1655
1656
32
      for (i = 1; i < 16; i++)
1657
30
  {
1658
30
    opc_pointer[i] = opc_pointer[i - 1] + numopcodes[i - 1];
1659
30
    opcodes[i] = opc_pointer[i];
1660
30
  }
1661
1662
3.81k
      for (i = 0; i < m68k_numopcodes; i++)
1663
3.81k
  *opc_pointer[(m68k_opcodes[i].opcode >> 28) & 15]++ = &m68k_opcodes[i];
1664
2
    }
1665
1666
1.36M
  if (!FETCH_DATA (info, buffer + 2))
1667
874
    return -1;
1668
1.35M
  major_opcode = (buffer[0] >> 4) & 15;
1669
1670
323M
  for (i = 0; i < numopcodes[major_opcode]; i++)
1671
322M
    {
1672
322M
      const struct m68k_opcode *opc = opcodes[major_opcode][i];
1673
322M
      unsigned long opcode = opc->opcode;
1674
322M
      unsigned long match = opc->match;
1675
322M
      const char *args = opc->args;
1676
1677
322M
      if (*args == '.')
1678
3.62M
  args++;
1679
1680
322M
      if (((0xff & buffer[0] & (match >> 24)) == (0xff & (opcode >> 24)))
1681
85.5M
    && ((0xff & buffer[1] & (match >> 16)) == (0xff & (opcode >> 16)))
1682
    /* Only fetch the next two bytes if we need to.  */
1683
23.9M
    && (((0xffff & match) == 0)
1684
22.5M
        ||
1685
22.5M
        (FETCH_DATA (info, buffer + 4)
1686
22.5M
         && ((0xff & buffer[2] & (match >> 8)) == (0xff & (opcode >> 8)))
1687
1.45M
         && ((0xff & buffer[3] & match) == (0xff & opcode)))
1688
23.9M
        )
1689
1.60M
    && (opc->arch & arch_mask) != 0)
1690
1.12M
  {
1691
    /* Don't use for printout the variants of divul and divsl
1692
       that have the same register number in two places.
1693
       The more general variants will match instead.  */
1694
3.38M
    for (d = args; *d; d += 2)
1695
2.26M
      if (d[1] == 'D')
1696
754
        break;
1697
1698
    /* Don't use for printout the variants of most floating
1699
       point coprocessor instructions which use the same
1700
       register number in two places, as above.  */
1701
1.12M
    if (*d == '\0')
1702
3.38M
      for (d = args; *d; d += 2)
1703
2.26M
        if (d[1] == 't')
1704
795
    break;
1705
1706
    /* Don't match fmovel with more than one register;
1707
       wait for fmoveml.  */
1708
1.12M
    if (*d == '\0')
1709
1.12M
      {
1710
3.38M
        for (d = args; *d; d += 2)
1711
2.25M
    {
1712
2.25M
      if (d[0] == 's' && d[1] == '8')
1713
1.37k
        {
1714
1.37k
          val = fetch_arg (buffer, d[1], 3, info);
1715
1.37k
          if (val < 0)
1716
0
      return 0;
1717
1.37k
          if ((val & (val - 1)) != 0)
1718
283
      break;
1719
1.37k
        }
1720
2.25M
    }
1721
1.12M
      }
1722
1723
    /* Don't match FPU insns with non-default coprocessor ID.  */
1724
1.12M
    if (*d == '\0')
1725
1.12M
      {
1726
3.29M
        for (d = args; *d; d += 2)
1727
2.20M
    {
1728
2.20M
      if (d[0] == 'I')
1729
48.0k
        {
1730
48.0k
          val = fetch_arg (buffer, 'd', 3, info);
1731
48.0k
          if (val != 1)
1732
38.1k
      break;
1733
48.0k
        }
1734
2.20M
    }
1735
1.12M
      }
1736
1737
1.12M
    if (*d == '\0')
1738
1.08M
      if ((val = match_insn_m68k (memaddr, info, opc)))
1739
805k
        return val;
1740
1.12M
  }
1741
322M
    }
1742
553k
  return 0;
1743
1.35M
}
1744
1745
/* Print the m68k instruction at address MEMADDR in debugged memory,
1746
   on INFO->STREAM.  Returns length of the instruction, in bytes.  */
1747
1748
int
1749
print_insn_m68k (bfd_vma memaddr, disassemble_info *info)
1750
1.10M
{
1751
1.10M
  unsigned int arch_mask;
1752
1.10M
  struct private priv;
1753
1.10M
  int val;
1754
1755
1.10M
  bfd_byte *buffer = priv.the_buffer;
1756
1757
1.10M
  info->insn_info_valid = 1;
1758
1.10M
  info->private_data = & priv;
1759
  /* Tell objdump to use two bytes per chunk
1760
     and six bytes per line for displaying raw data.  */
1761
1.10M
  info->bytes_per_chunk = 2;
1762
1.10M
  info->bytes_per_line = 6;
1763
1.10M
  info->display_endian = BFD_ENDIAN_BIG;
1764
1.10M
  priv.max_fetched = priv.the_buffer;
1765
1.10M
  priv.insn_start = memaddr;
1766
1767
1.10M
  arch_mask = bfd_m68k_mach_to_features (info->mach);
1768
1.10M
  if (!arch_mask)
1769
941k
    {
1770
      /* First try printing an m680x0 instruction.  Try printing a Coldfire
1771
   one if that fails.  */
1772
941k
      val = m68k_scan_mask (memaddr, info, m68k_mask);
1773
941k
      if (val <= 0)
1774
259k
  val = m68k_scan_mask (memaddr, info, mcf_mask);
1775
941k
    }
1776
159k
  else
1777
159k
    {
1778
159k
      val = m68k_scan_mask (memaddr, info, arch_mask);
1779
159k
    }
1780
1781
1.10M
  if (val == 0)
1782
295k
    {
1783
      /* Handle undefined instructions.  */
1784
295k
      info->fprintf_styled_func (info->stream, dis_style_assembler_directive,
1785
295k
         ".short");
1786
295k
      info->fprintf_styled_func (info->stream, dis_style_text, " ");
1787
295k
      info->fprintf_styled_func (info->stream, dis_style_immediate,
1788
295k
         "0x%04x", (buffer[0] << 8) + buffer[1]);
1789
1790
295k
      info->insn_type = dis_noninsn;
1791
295k
    }
1792
1793
1.10M
  return val ? val : 2;
1794
1.10M
}