Coverage Report

Created: 2026-07-25 10:20

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
592k
#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
473k
  do            \
77
473k
    {           \
78
473k
      p += 2;         \
79
473k
      if (!FETCH_DATA (info, p))   \
80
473k
  return PRINT_INSN_ARG_MEMORY_ERROR; \
81
473k
      val = COERCE_SIGNED_CHAR (p[-1]);   \
82
473k
    }            \
83
473k
  while (0)
84
85
/* Get a 2 byte signed integer.  */
86
383k
#define COERCE16(x) ((int) (((x) ^ 0x8000) - 0x8000))
87
88
#define NEXTWORD(p, val, ret_val)   \
89
384k
  do            \
90
384k
    {           \
91
384k
      p += 2;         \
92
384k
      if (!FETCH_DATA (info, p))   \
93
384k
  return ret_val;       \
94
384k
      val = COERCE16 ((p[-2] << 8) + p[-1]);  \
95
383k
    }            \
96
384k
  while (0)
97
98
/* Get a 4 byte signed integer.  */
99
77.1k
#define COERCE32(x) (((bfd_vma) (x) ^ 0x80000000) - 0x80000000)
100
101
#define NEXTLONG(p, val, ret_val)         \
102
77.2k
  do                  \
103
77.2k
    {                 \
104
77.2k
      p += 4;               \
105
77.2k
      if (!FETCH_DATA (info, p))         \
106
77.2k
  return ret_val;             \
107
77.2k
      val = COERCE32 (((((((unsigned) p[-4] << 8) + p[-3]) << 8)  \
108
77.1k
      + p[-2]) << 8) + p[-1]);      \
109
77.1k
    }                  \
110
77.2k
  while (0)
111
112
/* Get a 4 byte unsigned integer.  */
113
#define NEXTULONG(p, val)           \
114
15.5k
  do                  \
115
15.5k
    {                 \
116
15.5k
      p += 4;               \
117
15.5k
      if (!FETCH_DATA (info, p))         \
118
15.5k
  return PRINT_INSN_ARG_MEMORY_ERROR;       \
119
15.5k
      val = (((((((unsigned) p[-4] << 8) + p[-3]) << 8)     \
120
15.5k
         + p[-2]) << 8) + p[-1]);         \
121
15.5k
    }                  \
122
15.5k
  while (0)
123
124
/* Get a single precision float.  */
125
#define NEXTSINGLE(val, p)          \
126
358
  do                \
127
358
    {               \
128
358
      p += 4;             \
129
358
      if (!FETCH_DATA (info, p))       \
130
358
  return PRINT_INSN_ARG_MEMORY_ERROR;     \
131
358
      floatformat_to_double (& floatformat_ieee_single_big, \
132
358
           (char *) p - 4, & val);    \
133
358
    }                \
134
358
  while (0)
135
136
/* Get a double precision float.  */
137
#define NEXTDOUBLE(val, p)          \
138
1.05k
  do                \
139
1.05k
    {               \
140
1.05k
      p += 8;             \
141
1.05k
      if (!FETCH_DATA (info, p))       \
142
1.05k
  return PRINT_INSN_ARG_MEMORY_ERROR;     \
143
1.05k
      floatformat_to_double (& floatformat_ieee_double_big, \
144
1.05k
           (char *) p - 8, & val);    \
145
1.05k
    }                \
146
1.05k
  while (0)
147
148
/* Get an extended precision float.  */
149
#define NEXTEXTEND(val, p)        \
150
887
  do              \
151
887
    {             \
152
887
      p += 12;            \
153
887
      if (!FETCH_DATA (info, p))     \
154
887
  return PRINT_INSN_ARG_MEMORY_ERROR;   \
155
887
      floatformat_to_double (& floatformat_m68881_ext,  \
156
886
           (char *) p - 12, & val); \
157
886
    }              \
158
887
  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
734
  do            \
166
734
    {           \
167
734
      p += 12;          \
168
734
      if (!FETCH_DATA (info, p))   \
169
734
  return PRINT_INSN_ARG_MEMORY_ERROR; \
170
734
      val = 0.0;        \
171
728
    }            \
172
734
  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
39.2M
  ((addr) <= ((struct private *) (info->private_data))->max_fetched \
191
39.2M
   ? 1 : fetch_data ((info), (addr)))
192
193
static int
194
fetch_data (struct disassemble_info *info, bfd_byte *addr)
195
1.72M
{
196
1.72M
  int status;
197
1.72M
  struct private *priv = (struct private *)info->private_data;
198
1.72M
  bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
199
200
1.72M
  status = (*info->read_memory_func) (start,
201
1.72M
              priv->max_fetched,
202
1.72M
              addr - priv->max_fetched,
203
1.72M
              info);
204
1.72M
  if (status != 0)
205
22.8k
    {
206
22.8k
      (*info->memory_error_func) (status, start, info);
207
22.8k
      return 0;
208
22.8k
    }
209
1.70M
  else
210
1.70M
    priv->max_fetched = addr;
211
1.70M
  return 1;
212
1.72M
}
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.59M
{
221
2.59M
  return 0;
222
2.59M
}
223
224
static void
225
dummy_print_address (bfd_vma vma ATTRIBUTE_UNUSED,
226
         struct disassemble_info *info ATTRIBUTE_UNUSED)
227
93.9k
{
228
93.9k
}
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.97M
{
242
2.97M
  int val = 0;
243
244
2.97M
  switch (code)
245
2.97M
    {
246
9.98k
    case '/': /* MAC/EMAC mask bit.  */
247
9.98k
      val = buffer[3] >> 5;
248
9.98k
      break;
249
250
1.39k
    case 'G': /* EMAC ACC load.  */
251
1.39k
      val = ((buffer[3] >> 3) & 0x2) | ((~buffer[1] >> 7) & 0x1);
252
1.39k
      break;
253
254
840
    case 'H': /* EMAC ACC !load.  */
255
840
      val = ((buffer[3] >> 3) & 0x2) | ((buffer[1] >> 7) & 0x1);
256
840
      break;
257
258
526
    case ']': /* EMAC ACCEXT bit.  */
259
526
      val = buffer[0] >> 2;
260
526
      break;
261
262
16.2k
    case 'I': /* MAC/EMAC scale factor.  */
263
16.2k
      val = buffer[2] >> 1;
264
16.2k
      break;
265
266
848
    case 'F': /* EMAC ACCx.  */
267
848
      val = buffer[0] >> 1;
268
848
      break;
269
270
314
    case 'f':
271
314
      val = buffer[1];
272
314
      break;
273
274
1.75M
    case 's':
275
1.75M
      val = buffer[1];
276
1.75M
      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
238k
    case 'x':     /* Destination, for general arg.  */
284
238k
      val = (buffer[0] << 8) + buffer[1];
285
238k
      val >>= 6;
286
238k
      break;
287
288
112
    case 'k':
289
112
      if (! FETCH_DATA (info, buffer + 3))
290
0
  return -1;
291
112
      val = (buffer[3] >> 4);
292
112
      break;
293
294
612
    case 'C':
295
612
      if (! FETCH_DATA (info, buffer + 3))
296
0
  return -1;
297
612
      val = buffer[3];
298
612
      break;
299
300
55.5k
    case '1':
301
55.5k
      if (! FETCH_DATA (info, buffer + 3))
302
0
  return -1;
303
55.5k
      val = (buffer[2] << 8) + buffer[3];
304
55.5k
      val >>= 12;
305
55.5k
      break;
306
307
2.99k
    case '2':
308
2.99k
      if (! FETCH_DATA (info, buffer + 3))
309
0
  return -1;
310
2.99k
      val = (buffer[2] << 8) + buffer[3];
311
2.99k
      val >>= 6;
312
2.99k
      break;
313
314
48.6k
    case '3':
315
51.5k
    case 'j':
316
51.5k
      if (! FETCH_DATA (info, buffer + 3))
317
0
  return -1;
318
51.5k
      val = (buffer[2] << 8) + buffer[3];
319
51.5k
      break;
320
321
1.01k
    case '4':
322
1.01k
      if (! FETCH_DATA (info, buffer + 5))
323
0
  return -1;
324
1.01k
      val = (buffer[4] << 8) + buffer[5];
325
1.01k
      val >>= 12;
326
1.01k
      break;
327
328
1.01k
    case '5':
329
1.01k
      if (! FETCH_DATA (info, buffer + 5))
330
0
  return -1;
331
1.01k
      val = (buffer[4] << 8) + buffer[5];
332
1.01k
      val >>= 6;
333
1.01k
      break;
334
335
1.01k
    case '6':
336
1.01k
      if (! FETCH_DATA (info, buffer + 5))
337
0
  return -1;
338
1.01k
      val = (buffer[4] << 8) + buffer[5];
339
1.01k
      break;
340
341
5.57k
    case '7':
342
5.57k
      if (! FETCH_DATA (info, buffer + 3))
343
0
  return -1;
344
5.57k
      val = (buffer[2] << 8) + buffer[3];
345
5.57k
      val >>= 7;
346
5.57k
      break;
347
348
11.6k
    case '8':
349
11.6k
      if (! FETCH_DATA (info, buffer + 3))
350
0
  return -1;
351
11.6k
      val = (buffer[2] << 8) + buffer[3];
352
11.6k
      val >>= 10;
353
11.6k
      break;
354
355
691
    case '9':
356
691
      if (! FETCH_DATA (info, buffer + 3))
357
0
  return -1;
358
691
      val = (buffer[2] << 8) + buffer[3];
359
691
      val >>= 5;
360
691
      break;
361
362
3.93k
    case 'e':
363
3.93k
      val = (buffer[1] >> 6);
364
3.93k
      break;
365
366
41.8k
    case 'E':
367
41.8k
      if (! FETCH_DATA (info, buffer + 3))
368
0
  return -1;
369
41.8k
      val = (buffer[2] >> 1);
370
41.8k
      break;
371
372
8.34k
    case 'm':
373
8.34k
      val = (buffer[1] & 0x40 ? 0x8 : 0)
374
8.34k
  | ((buffer[0] >> 1) & 0x7)
375
8.34k
  | (buffer[3] & 0x80 ? 0x10 : 0);
376
8.34k
      break;
377
378
9.98k
    case 'n':
379
9.98k
      val = (buffer[1] & 0x40 ? 0x8 : 0) | ((buffer[0] >> 1) & 0x7);
380
9.98k
      break;
381
382
14.2k
    case 'o':
383
14.2k
      val = (buffer[2] >> 4) | (buffer[3] & 0x80 ? 0x10 : 0);
384
14.2k
      break;
385
386
8.34k
    case 'M':
387
8.34k
      val = (buffer[1] & 0xf) | (buffer[3] & 0x40 ? 0x10 : 0);
388
8.34k
      break;
389
390
14.2k
    case 'N':
391
14.2k
      val = (buffer[3] & 0xf) | (buffer[3] & 0x40 ? 0x10 : 0);
392
14.2k
      break;
393
394
770
    case 'h':
395
770
      val = buffer[2] >> 2;
396
770
      break;
397
398
0
    default:
399
0
      abort ();
400
2.97M
    }
401
402
  /* bits is never too big.  */
403
2.97M
  return val & ((1 << bits) - 1);
404
2.97M
}
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.82M
{
416
1.82M
  int mode, mask;
417
1.82M
#define M(n0,n1,n2,n3,n4,n5,n6,n70,n71,n72,n73,n74) \
418
1.82M
  (n0 | n1 << 1 | n2 << 2 | n3 << 3 | n4 << 4 | n5 << 5 | n6 << 6 \
419
1.82M
   | n70 << 7 | n71 << 8 | n72 << 9 | n73 << 10 | n74 << 11)
420
421
1.82M
  switch (code)
422
1.82M
    {
423
320k
    case '*':
424
320k
      mask = M (1,1,1,1,1,1,1,1,1,1,1,1);
425
320k
      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
250k
    case '%':
430
250k
      mask = M (1,1,1,1,1,1,1,1,1,0,0,0);
431
250k
      break;
432
273k
    case ';':
433
273k
      mask = M (1,0,1,1,1,1,1,1,1,1,1,1);
434
273k
      break;
435
6.62k
    case '@':
436
6.62k
      mask = M (1,0,1,1,1,1,1,1,1,1,1,0);
437
6.62k
      break;
438
12.1k
    case '!':
439
12.1k
      mask = M (0,0,1,0,0,1,1,1,1,1,1,0);
440
12.1k
      break;
441
5.04k
    case '&':
442
5.04k
      mask = M (0,0,1,0,0,1,1,1,1,0,0,0);
443
5.04k
      break;
444
714k
    case '$':
445
714k
      mask = M (1,0,1,1,1,1,1,1,1,0,0,0);
446
714k
      break;
447
1.14k
    case '?':
448
1.14k
      mask = M (1,0,1,0,0,1,1,1,1,0,0,0);
449
1.14k
      break;
450
1.11k
    case '/':
451
1.11k
      mask = M (1,0,1,0,0,1,1,1,1,1,1,0);
452
1.11k
      break;
453
143
    case '|':
454
143
      mask = M (0,0,1,0,0,1,1,1,1,1,1,0);
455
143
      break;
456
1.96k
    case '>':
457
1.96k
      mask = M (0,0,1,0,1,1,1,1,1,0,0,0);
458
1.96k
      break;
459
3.55k
    case '<':
460
3.55k
      mask = M (0,0,1,1,0,1,1,1,1,1,1,0);
461
3.55k
      break;
462
35.4k
    case 'm':
463
35.4k
      mask = M (1,1,1,1,1,0,0,0,0,0,0,0);
464
35.4k
      break;
465
29.6k
    case 'n':
466
29.6k
      mask = M (0,0,0,0,0,1,0,0,0,1,0,0);
467
29.6k
      break;
468
24.2k
    case 'o':
469
24.2k
      mask = M (0,0,0,0,0,0,1,1,1,0,1,1);
470
24.2k
      break;
471
52.1k
    case 'p':
472
52.1k
      mask = M (1,1,1,1,1,1,0,0,0,0,0,0);
473
52.1k
      break;
474
3.61k
    case 'q':
475
3.61k
      mask = M (1,0,1,1,1,1,0,0,0,0,0,0);
476
3.61k
      break;
477
2.41k
    case 'v':
478
2.41k
      mask = M (1,0,1,1,1,1,0,1,1,0,0,0);
479
2.41k
      break;
480
97
    case 'b':
481
97
      mask = M (1,0,1,1,1,1,0,0,0,1,0,0);
482
97
      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
1.68k
    case 'y':
487
1.68k
      mask = M (0,0,1,0,0,1,0,0,0,0,0,0);
488
1.68k
      break;
489
286
    case 'z':
490
286
      mask = M (0,0,1,0,0,1,0,0,0,1,0,0);
491
286
      break;
492
11.6k
    case '4':
493
11.6k
      mask = M (0,0,1,1,1,1,0,0,0,0,0,0);
494
11.6k
      break;
495
0
    default:
496
0
      abort ();
497
1.82M
    }
498
1.82M
#undef M
499
500
1.82M
  mode = (val >> 3) & 7;
501
1.82M
  if (mode == 7)
502
214k
    mode += val & 7;
503
1.82M
  return (mask & (1 << mode)) != 0;
504
1.82M
}
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
128k
{
512
128k
  if (regno == -1)
513
7.37k
    {
514
7.37k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%pc");
515
7.37k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
516
7.37k
      (*info->print_address_func) (disp, info);
517
7.37k
    }
518
121k
  else
519
121k
    {
520
121k
      if (regno == -3)
521
1.74k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
522
1.74k
              "%%zpc");
523
119k
      else if (regno != -2)
524
102k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
525
102k
              "%s", reg_names[regno]);
526
121k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
527
121k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
528
121k
            "%" PRIx64, (uint64_t) disp);
529
121k
    }
530
128k
}
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
104k
{
538
104k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
539
104k
        "%s", reg_names[(ext >> 12) & 0xf]);
540
104k
  (*info->fprintf_styled_func) (info->stream, dis_style_text,
541
104k
        ":%c", ext & 0x800 ? 'l' : 'w');
542
104k
  if ((ext >> 9) & 3)
543
61.4k
    {
544
61.4k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ":");
545
61.4k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
546
61.4k
            "%d", 1 << ((ext >> 9) & 3));
547
61.4k
    }
548
104k
}
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
129k
{
561
129k
  int word;
562
129k
  bfd_vma base_disp;
563
129k
  bfd_vma outer_disp;
564
129k
  bool print_index = true;
565
566
129k
  NEXTWORD (p, word, NULL);
567
568
  /* Handle the 68000 style of indexing.  */
569
570
128k
  if ((word & 0x100) == 0)
571
72.5k
    {
572
72.5k
      base_disp = word & 0xff;
573
72.5k
      if ((base_disp & 0x80) != 0)
574
21.9k
  base_disp -= 0x100;
575
72.5k
      if (basereg == -1)
576
2.86k
  base_disp += addr;
577
72.5k
      print_base (basereg, base_disp, info);
578
72.5k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ",");
579
72.5k
      print_index_register (word, info);
580
72.5k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
581
72.5k
      return p;
582
72.5k
    }
583
584
  /* Handle the generalized kind.  */
585
  /* First, compute the displacement to add to the base register.  */
586
56.3k
  if (word & 0200)
587
19.1k
    {
588
19.1k
      if (basereg == -1)
589
1.75k
  basereg = -3;
590
17.3k
      else
591
17.3k
  basereg = -2;
592
19.1k
    }
593
56.3k
  if (word & 0100)
594
24.8k
    print_index = false;
595
56.3k
  base_disp = 0;
596
56.3k
  switch ((word >> 4) & 3)
597
56.3k
    {
598
11.8k
    case 2:
599
11.8k
      NEXTWORD (p, base_disp, NULL);
600
11.8k
      break;
601
25.3k
    case 3:
602
25.3k
      NEXTLONG (p, base_disp, NULL);
603
56.3k
    }
604
56.3k
  if (basereg == -1)
605
4.52k
    base_disp += addr;
606
607
  /* Handle single-level case (not indirect).  */
608
56.3k
  if ((word & 7) == 0)
609
9.34k
    {
610
9.34k
      print_base (basereg, base_disp, info);
611
9.34k
      if (print_index)
612
6.89k
  {
613
6.89k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, ",");
614
6.89k
    print_index_register (word, info);
615
6.89k
  }
616
9.34k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
617
9.34k
      return p;
618
9.34k
    }
619
620
  /* Two level.  Compute displacement to add after indirection.  */
621
46.9k
  outer_disp = 0;
622
46.9k
  switch (word & 3)
623
46.9k
    {
624
11.5k
    case 2:
625
11.5k
      NEXTWORD (p, outer_disp, NULL);
626
11.4k
      break;
627
14.9k
    case 3:
628
14.9k
      NEXTLONG (p, outer_disp, NULL);
629
46.9k
    }
630
631
46.9k
  print_base (basereg, base_disp, info);
632
46.9k
  if ((word & 4) == 0 && print_index)
633
13.0k
    {
634
13.0k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ",");
635
13.0k
      print_index_register (word, info);
636
13.0k
      print_index = false;
637
13.0k
    }
638
46.9k
  (*info->fprintf_styled_func) (info->stream, dis_style_text,
639
46.9k
        ")@(");
640
46.9k
  (*info->fprintf_styled_func) (info->stream, dis_style_address_offset,
641
46.9k
        "%" PRIx64, (uint64_t) outer_disp);
642
46.9k
  if (print_index)
643
11.4k
    {
644
11.4k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ",");
645
11.4k
      print_index_register (word, info);
646
11.4k
    }
647
46.9k
  (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
648
649
46.9k
  return p;
650
46.9k
}
651
652
#define FETCH_ARG(size, val)        \
653
1.09M
  do              \
654
1.09M
    {             \
655
1.09M
      val = fetch_arg (buffer, place, size, info);  \
656
1.09M
      if (val < 0)         \
657
1.09M
  return PRINT_INSN_ARG_MEMORY_ERROR;   \
658
1.09M
    }             \
659
1.09M
  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.63M
{
672
3.63M
  int val = 0;
673
3.63M
  int place = d[1];
674
3.63M
  unsigned char *p = p0;
675
3.63M
  int regno;
676
3.63M
  const char *regname;
677
3.63M
  unsigned char *p1;
678
3.63M
  double flval;
679
3.63M
  int flt_p;
680
3.63M
  bfd_signed_vma disp;
681
3.63M
  unsigned int uval;
682
683
3.63M
  switch (*d)
684
3.63M
    {
685
3.93k
    case 'c':   /* Cache identifier.  */
686
3.93k
      {
687
3.93k
        static char *const cacheFieldName[] = { "nc", "dc", "ic", "bc" };
688
3.93k
        FETCH_ARG (2, val);
689
3.93k
  (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic,
690
3.93k
              "%s", cacheFieldName[val]);
691
3.93k
        break;
692
3.93k
      }
693
694
6.48k
    case 'a':   /* Address register indirect only. Cf. case '+'.  */
695
6.48k
      {
696
6.48k
  FETCH_ARG (3, val);
697
6.48k
  (*info->fprintf_styled_func) (info->stream, dis_style_register, "%s",
698
6.48k
              reg_names[val + 8]);
699
6.48k
  (*info->fprintf_styled_func) (info->stream, dis_style_text, "@");
700
6.48k
        break;
701
6.48k
      }
702
703
1.40k
    case '_':   /* 32-bit absolute address for move16.  */
704
1.40k
      {
705
1.40k
        NEXTULONG (p, uval);
706
1.40k
  (*info->print_address_func) (uval, info);
707
1.40k
        break;
708
1.40k
      }
709
710
3.47k
    case 'C':
711
3.47k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%ccr");
712
3.47k
      break;
713
714
2.66k
    case 'S':
715
2.66k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%sr");
716
2.66k
      break;
717
718
660
    case 'U':
719
660
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%usp");
720
660
      break;
721
722
1.19k
    case 'E':
723
1.19k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%acc");
724
1.19k
      break;
725
726
706
    case 'G':
727
706
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%macsr");
728
706
      break;
729
730
2.72k
    case 'H':
731
2.72k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%mask");
732
2.72k
      break;
733
734
2.90k
    case 'J':
735
2.90k
      {
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.90k
  struct regname { char * name; int value; };
740
2.90k
  static const struct regname names[] =
741
2.90k
    {
742
2.90k
      {"%sfc", 0x000}, {"%dfc", 0x001}, {"%cacr", 0x002},
743
2.90k
      {"%tc",  0x003}, {"%itt0",0x004}, {"%itt1", 0x005},
744
2.90k
      {"%dtt0",0x006}, {"%dtt1",0x007}, {"%buscr",0x008},
745
2.90k
      {"%rgpiobar", 0x009}, {"%acr4",0x00c},
746
2.90k
      {"%acr5",0x00d}, {"%acr6",0x00e}, {"%acr7", 0x00f},
747
2.90k
      {"%usp", 0x800}, {"%vbr", 0x801}, {"%caar", 0x802},
748
2.90k
      {"%msp", 0x803}, {"%isp", 0x804},
749
2.90k
      {"%pc", 0x80f},
750
      /* Reg c04 is sometimes called flashbar or rambar.
751
         Reg c05 is also sometimes called rambar.  */
752
2.90k
      {"%rambar0", 0xc04}, {"%rambar1", 0xc05},
753
754
      /* reg c0e is sometimes called mbar2 or secmbar.
755
         reg c0f is sometimes called mbar.  */
756
2.90k
      {"%mbar0", 0xc0e}, {"%mbar1", 0xc0f},
757
758
      /* Should we be calling this psr like we do in case 'Y'?  */
759
2.90k
      {"%mmusr",0x805},
760
761
2.90k
      {"%urp", 0x806}, {"%srp", 0x807}, {"%pcr", 0x808},
762
763
      /* Fido added these.  */
764
2.90k
      {"%cac", 0xffe}, {"%mbo", 0xfff}
765
2.90k
  };
766
  /* Alternate names for v4e (MCF5407/5445x/MCF547x/MCF548x), at least.  */
767
2.90k
  static const struct regname names_v4e[] =
768
2.90k
    {
769
2.90k
      {"%asid",0x003}, {"%acr0",0x004}, {"%acr1",0x005},
770
2.90k
      {"%acr2",0x006}, {"%acr3",0x007}, {"%mmubar",0x008},
771
2.90k
    };
772
2.90k
  unsigned int arch_mask;
773
774
2.90k
  arch_mask = bfd_m68k_mach_to_features (info->mach);
775
2.90k
  FETCH_ARG (12, val);
776
2.90k
  if (arch_mask & (mcfisa_b | mcfisa_c))
777
1.07k
    {
778
7.38k
      for (regno = ARRAY_SIZE (names_v4e); --regno >= 0;)
779
6.42k
        if (names_v4e[regno].value == val)
780
104
    {
781
104
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
782
104
                 "%s", names_v4e[regno].name);
783
104
      break;
784
104
    }
785
1.07k
      if (regno >= 0)
786
104
        break;
787
1.07k
    }
788
83.3k
  for (regno = ARRAY_SIZE (names) - 1; regno >= 0; regno--)
789
81.1k
    if (names[regno].value == val)
790
632
      {
791
632
        (*info->fprintf_styled_func) (info->stream, dis_style_register,
792
632
              "%s", names[regno].name);
793
632
        break;
794
632
      }
795
2.80k
  if (regno < 0)
796
2.16k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "0x%x", val);
797
2.80k
      }
798
0
      break;
799
800
122k
    case 'Q':
801
122k
      FETCH_ARG (3, val);
802
      /* 0 means 8, except for the bkpt instruction... */
803
122k
      if (val == 0 && d[1] != 's')
804
8.92k
  val = 8;
805
122k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
806
122k
            "#%d", val);
807
122k
      break;
808
809
5.56k
    case 'x':
810
5.56k
      FETCH_ARG (3, val);
811
      /* 0 means -1.  */
812
5.56k
      if (val == 0)
813
853
  val = -1;
814
5.56k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
815
5.56k
            "#%d", val);
816
5.56k
      break;
817
818
41.8k
    case 'j':
819
41.8k
      FETCH_ARG (3, val);
820
41.8k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
821
41.8k
            "#%d", val+1);
822
41.8k
      break;
823
824
40.9k
    case 'K':
825
40.9k
      FETCH_ARG (9, val);
826
40.9k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
827
40.9k
            "#%d", val);
828
40.9k
      break;
829
830
49.5k
    case 'M':
831
49.5k
      if (place == 'h')
832
770
  {
833
770
    static char *const scalefactor_name[] = { "<<", ">>" };
834
835
770
    FETCH_ARG (1, val);
836
770
    (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic,
837
770
          "%s", scalefactor_name[val]);
838
770
  }
839
48.7k
      else
840
48.7k
  {
841
48.7k
    FETCH_ARG (8, val);
842
48.7k
    if (val & 0x80)
843
12.8k
      val = val - 0x100;
844
48.7k
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
845
48.7k
          "#%d", val);
846
48.7k
  }
847
49.5k
      break;
848
849
49.5k
    case 'T':
850
10.4k
      FETCH_ARG (4, val);
851
10.4k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
852
10.4k
            "#%d", val);
853
10.4k
      break;
854
855
529k
    case 'D':
856
529k
      FETCH_ARG (3, val);
857
529k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
858
529k
            "%s", reg_names[val]);
859
529k
      break;
860
861
68.3k
    case 'A':
862
68.3k
      FETCH_ARG (3, val);
863
68.3k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
864
68.3k
            "%s", reg_names[val + 010]);
865
68.3k
      break;
866
867
85.0k
    case 'R':
868
85.0k
      FETCH_ARG (4, val);
869
85.0k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
870
85.0k
            "%s", reg_names[val]);
871
85.0k
      break;
872
873
2.02k
    case 'r':
874
2.02k
      FETCH_ARG (4, regno);
875
2.02k
      if (regno > 7)
876
316
  {
877
316
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
878
316
          "%s", reg_names[regno]);
879
316
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@");
880
316
  }
881
1.70k
      else
882
1.70k
  {
883
1.70k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
884
1.70k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
885
1.70k
          "%s", reg_names[regno]);
886
1.70k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
887
1.70k
  }
888
2.02k
      break;
889
890
7.01k
    case 'F':
891
7.01k
      FETCH_ARG (3, val);
892
7.01k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
893
7.01k
            "%%fp%d", val);
894
7.01k
      break;
895
896
3.78k
    case 'O':
897
3.78k
      FETCH_ARG (6, val);
898
3.78k
      if (val & 0x20)
899
1.55k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
900
1.55k
              "%s", reg_names[val & 7]);
901
2.23k
      else
902
2.23k
  (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
903
2.23k
              "%d", val);
904
3.78k
      break;
905
906
6.19k
    case '+':
907
6.19k
      FETCH_ARG (3, val);
908
6.19k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
909
6.19k
            "%s", reg_names[val + 8]);
910
6.19k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, "@+");
911
6.19k
      break;
912
913
17.0k
    case '-':
914
17.0k
      FETCH_ARG (3, val);
915
17.0k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
916
17.0k
            "%s", reg_names[val + 8]);
917
17.0k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, "@-");
918
17.0k
      break;
919
920
392
    case 'k':
921
392
      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
392
      else if (place == 'C')
930
392
  {
931
392
    FETCH_ARG (7, val);
932
392
    if (val > 63)    /* This is a signed constant.  */
933
260
      val -= 128;
934
392
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "{");
935
392
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
936
392
          "#%d", val);
937
392
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "}");
938
392
  }
939
0
      else
940
0
  return PRINT_INSN_ARG_INVALID_OPERAND;
941
392
      break;
942
943
561k
    case '#':
944
562k
    case '^':
945
562k
      p1 = buffer + (*d == '#' ? 2 : 4);
946
562k
      if (place == 's')
947
0
  FETCH_ARG (4, val);
948
562k
      else if (place == 'C')
949
220
  FETCH_ARG (7, val);
950
562k
      else if (place == '8')
951
0
  FETCH_ARG (3, val);
952
562k
      else if (place == '3')
953
1.13k
  FETCH_ARG (8, val);
954
561k
      else if (place == 'b')
955
471k
  NEXTBYTE (p1, val);
956
90.0k
      else if (place == 'w' || place == 'W')
957
61.9k
  NEXTWORD (p1, val, PRINT_INSN_ARG_MEMORY_ERROR);
958
28.1k
      else if (place == 'l')
959
28.1k
  NEXTLONG (p1, val, PRINT_INSN_ARG_MEMORY_ERROR);
960
0
      else
961
0
  return PRINT_INSN_ARG_INVALID_OP_TABLE;
962
963
562k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
964
562k
            "#%d", val);
965
562k
      break;
966
967
137k
    case 'B':
968
137k
      if (place == 'b')
969
0
  NEXTBYTE (p, disp);
970
137k
      else if (place == 'B')
971
119k
  disp = COERCE_SIGNED_CHAR (buffer[1]);
972
18.6k
      else if (place == 'w' || place == 'W')
973
11.6k
  NEXTWORD (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
974
6.96k
      else if (place == 'l' || place == 'L' || place == 'C')
975
5.44k
  NEXTLONG (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
976
1.52k
      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.52k
      else if (place == 'c')
985
1.52k
  {
986
1.52k
    if (buffer[1] & 0x40)    /* If bit six is one, long offset.  */
987
834
      NEXTLONG (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
988
690
    else
989
690
      NEXTWORD (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
990
1.52k
  }
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
10.9k
    case 'd':
1000
10.9k
      {
1001
10.9k
  int val1;
1002
1003
10.9k
  NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1004
10.9k
  FETCH_ARG (3, val1);
1005
10.9k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
1006
10.9k
              "%s", reg_names[val1 + 8]);
1007
10.9k
  (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
1008
10.9k
  (*info->fprintf_styled_func) (info->stream, dis_style_address_offset,
1009
10.9k
              "%d", val);
1010
10.9k
  (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
1011
10.9k
  break;
1012
10.9k
      }
1013
1014
1.31k
    case 's':
1015
1.31k
      FETCH_ARG (3, val);
1016
1.31k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1017
1.31k
            "%s", fpcr_names[val]);
1018
1.31k
      break;
1019
1020
3.39k
    case 'e':
1021
3.39k
      FETCH_ARG (2, val);
1022
3.39k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1023
3.39k
            "%%acc%d", val);
1024
3.39k
      break;
1025
1026
526
    case 'g':
1027
526
      FETCH_ARG (1, val);
1028
526
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1029
526
            "%%accext%s", val == 0 ? "01" : "23");
1030
526
      break;
1031
1032
16.2k
    case 'i':
1033
16.2k
      FETCH_ARG (2, val);
1034
16.2k
      if (val == 1)
1035
5.74k
  (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic,
1036
5.74k
              "<<");
1037
10.5k
      else if (val == 3)
1038
4.39k
  (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic,
1039
4.39k
              ">>");
1040
6.15k
      else
1041
6.15k
  return PRINT_INSN_ARG_INVALID_OPERAND;
1042
10.1k
      break;
1043
1044
14.8k
    case 'I':
1045
      /* Get coprocessor ID... */
1046
14.8k
      val = fetch_arg (buffer, 'd', 3, info);
1047
14.8k
      if (val < 0)
1048
0
  return PRINT_INSN_ARG_MEMORY_ERROR;
1049
14.8k
      if (val != 1)        /* Unusual coprocessor ID?  */
1050
0
  (*info->fprintf_styled_func) (info->stream, dis_style_text,
1051
0
              "(cpid=%d) ", val);
1052
14.8k
      break;
1053
1054
11.6k
    case '4':
1055
332k
    case '*':
1056
402k
    case '~':
1057
653k
    case '%':
1058
927k
    case ';':
1059
933k
    case '@':
1060
945k
    case '!':
1061
1.66M
    case '$':
1062
1.66M
    case '?':
1063
1.66M
    case '/':
1064
1.66M
    case '&':
1065
1.66M
    case '|':
1066
1.67M
    case '<':
1067
1.67M
    case '>':
1068
1.70M
    case 'm':
1069
1.73M
    case 'n':
1070
1.76M
    case 'o':
1071
1.81M
    case 'p':
1072
1.81M
    case 'q':
1073
1.82M
    case 'v':
1074
1.82M
    case 'b':
1075
1.82M
    case 'w':
1076
1.82M
    case 'y':
1077
1.82M
    case 'z':
1078
1.82M
      if (place == 'd')
1079
238k
  {
1080
238k
    val = fetch_arg (buffer, 'x', 6, info);
1081
238k
    if (val < 0)
1082
0
      return PRINT_INSN_ARG_MEMORY_ERROR;
1083
238k
    val = ((val & 7) << 3) + ((val >> 3) & 7);
1084
238k
  }
1085
1.58M
      else
1086
1.58M
  {
1087
1.58M
    val = fetch_arg (buffer, 's', 6, info);
1088
1.58M
    if (val < 0)
1089
0
      return PRINT_INSN_ARG_MEMORY_ERROR;
1090
1.58M
  }
1091
1092
      /* If the <ea> is invalid for *d, then reject this match.  */
1093
1.82M
      if (!m68k_valid_ea (*d, val))
1094
270k
  return PRINT_INSN_ARG_INVALID_OPERAND;
1095
1096
      /* Get register number assuming address register.  */
1097
1.55M
      regno = (val & 7) + 8;
1098
1.55M
      regname = reg_names[regno];
1099
1.55M
      switch (val >> 3)
1100
1.55M
  {
1101
772k
  case 0:
1102
772k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1103
772k
          "%s", reg_names[val]);
1104
772k
    break;
1105
1106
39.0k
  case 1:
1107
39.0k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1108
39.0k
          "%s", regname);
1109
39.0k
    break;
1110
1111
109k
  case 2:
1112
109k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1113
109k
          "%s", regname);
1114
109k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@");
1115
109k
    break;
1116
1117
162k
  case 3:
1118
162k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1119
162k
          "%s", regname);
1120
162k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@+");
1121
162k
    break;
1122
1123
176k
  case 4:
1124
176k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1125
176k
          "%s", regname);
1126
176k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@-");
1127
176k
    break;
1128
1129
108k
  case 5:
1130
108k
    NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1131
107k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1132
107k
          "%s", regname);
1133
107k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
1134
107k
    (*info->fprintf_styled_func) (info->stream, dis_style_address_offset,
1135
107k
          "%d", val);
1136
107k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
1137
107k
    break;
1138
1139
119k
  case 6:
1140
119k
    p = print_indexed (regno, p, addr, info);
1141
119k
    if (p == NULL)
1142
195
      return PRINT_INSN_ARG_MEMORY_ERROR;
1143
119k
    break;
1144
1145
119k
  case 7:
1146
63.9k
    switch (val & 7)
1147
63.9k
      {
1148
15.2k
      case 0:
1149
15.2k
        NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1150
15.2k
        (*info->print_address_func) (val, info);
1151
15.2k
        break;
1152
1153
14.1k
      case 1:
1154
14.1k
        NEXTULONG (p, uval);
1155
14.1k
        (*info->print_address_func) (uval, info);
1156
14.1k
        break;
1157
1158
10.7k
      case 2:
1159
10.7k
        NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1160
10.7k
        (*info->fprintf_styled_func) (info->stream, dis_style_register,
1161
10.7k
              "%%pc");
1162
10.7k
        (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
1163
10.7k
        (*info->print_address_func) (addr + val, info);
1164
10.7k
        (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
1165
10.7k
        break;
1166
1167
9.15k
      case 3:
1168
9.15k
        p = print_indexed (-1, p, addr, info);
1169
9.15k
        if (p == NULL)
1170
36
    return PRINT_INSN_ARG_MEMORY_ERROR;
1171
9.11k
        break;
1172
1173
14.6k
      case 4:
1174
14.6k
        flt_p = 1;  /* Assume it's a float... */
1175
14.6k
        switch (place)
1176
14.6k
        {
1177
2.18k
    case 'b':
1178
2.18k
      NEXTBYTE (p, val);
1179
2.18k
      flt_p = 0;
1180
2.18k
      break;
1181
1182
6.82k
    case 'w':
1183
6.82k
      NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1184
6.80k
      flt_p = 0;
1185
6.80k
      break;
1186
1187
2.60k
    case 'l':
1188
2.60k
      NEXTLONG (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1189
2.58k
      flt_p = 0;
1190
2.58k
      break;
1191
1192
358
    case 'f':
1193
358
      NEXTSINGLE (flval, p);
1194
358
      break;
1195
1196
1.05k
    case 'F':
1197
1.05k
      NEXTDOUBLE (flval, p);
1198
1.05k
      break;
1199
1200
1.05k
    case 'x':
1201
887
      NEXTEXTEND (flval, p);
1202
886
      break;
1203
1204
886
    case 'p':
1205
734
      NEXTPACKED (p, flval);
1206
728
      break;
1207
1208
728
    default:
1209
0
      return PRINT_INSN_ARG_INVALID_OPERAND;
1210
14.6k
        }
1211
14.6k
        if (flt_p)  /* Print a float? */
1212
3.02k
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1213
3.02k
                "#0e%g", flval);
1214
11.5k
        else
1215
11.5k
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1216
11.5k
                "#%d", val);
1217
14.6k
        break;
1218
1219
0
      default:
1220
0
        return PRINT_INSN_ARG_INVALID_OPERAND;
1221
63.9k
      }
1222
1.55M
  }
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.55M
      if (place == '/')
1228
9.98k
  {
1229
9.98k
    FETCH_ARG (1, val);
1230
9.98k
    if (val)
1231
7.97k
      info->fprintf_styled_func (info->stream, dis_style_text, "&");
1232
9.98k
  }
1233
1.55M
      break;
1234
1235
1.55M
    case 'L':
1236
7.78k
    case 'l':
1237
7.78k
  if (place == 'w')
1238
5.68k
    {
1239
5.68k
      char doneany;
1240
5.68k
      p1 = buffer + 2;
1241
5.68k
      NEXTWORD (p1, val, PRINT_INSN_ARG_MEMORY_ERROR);
1242
      /* Move the pointer ahead if this point is farther ahead
1243
         than the last.  */
1244
5.68k
      p = p1 > p ? p1 : p;
1245
5.68k
      if (val == 0)
1246
376
        {
1247
376
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1248
376
                "#0");
1249
376
    break;
1250
376
        }
1251
5.31k
      if (*d == 'l')
1252
1.56k
        {
1253
1.56k
    int newval = 0;
1254
1255
26.5k
    for (regno = 0; regno < 16; ++regno)
1256
25.0k
      if (val & (0x8000 >> regno))
1257
9.36k
        newval |= 1 << regno;
1258
1.56k
    val = newval;
1259
1.56k
        }
1260
5.31k
      val &= 0xffff;
1261
5.31k
      doneany = 0;
1262
69.6k
      for (regno = 0; regno < 16; ++regno)
1263
64.2k
        if (val & (1 << regno))
1264
17.6k
    {
1265
17.6k
      int first_regno;
1266
1267
17.6k
      if (doneany)
1268
12.3k
        (*info->fprintf_styled_func) (info->stream, dis_style_text,
1269
12.3k
              "/");
1270
17.6k
      doneany = 1;
1271
17.6k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1272
17.6k
            "%s", reg_names[regno]);
1273
17.6k
      first_regno = regno;
1274
38.3k
      while (val & (1 << (regno + 1)))
1275
20.6k
        ++regno;
1276
17.6k
      if (regno > first_regno)
1277
8.64k
        {
1278
8.64k
          (*info->fprintf_styled_func) (info->stream,
1279
8.64k
                dis_style_text, "-");
1280
8.64k
          (*info->fprintf_styled_func) (info->stream,
1281
8.64k
                dis_style_register, "%s",
1282
8.64k
                reg_names[regno]);
1283
8.64k
        }
1284
17.6k
    }
1285
5.31k
    }
1286
2.09k
  else if (place == '3')
1287
1.30k
    {
1288
      /* `fmovem' insn.  */
1289
1.30k
      char doneany;
1290
1291
1.30k
      FETCH_ARG (8, val);
1292
1.30k
      if (val == 0)
1293
318
        {
1294
318
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1295
318
                "#0");
1296
318
    break;
1297
318
        }
1298
982
      if (*d == 'l')
1299
912
        {
1300
912
    int newval = 0;
1301
1302
8.20k
    for (regno = 0; regno < 8; ++regno)
1303
7.29k
      if (val & (0x80 >> regno))
1304
2.99k
        newval |= 1 << regno;
1305
912
    val = newval;
1306
912
        }
1307
982
      val &= 0xff;
1308
982
      doneany = 0;
1309
6.96k
      for (regno = 0; regno < 8; ++regno)
1310
5.98k
        if (val & (1 << regno))
1311
1.33k
    {
1312
1.33k
      int first_regno;
1313
1.33k
      if (doneany)
1314
350
        (*info->fprintf_styled_func) (info->stream, dis_style_text,
1315
350
              "/");
1316
1.33k
      doneany = 1;
1317
1.33k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1318
1.33k
            "%%fp%d", regno);
1319
1.33k
      first_regno = regno;
1320
3.20k
      while (val & (1 << (regno + 1)))
1321
1.87k
        ++regno;
1322
1.33k
      if (regno > first_regno)
1323
470
        {
1324
470
          (*info->fprintf_styled_func) (info->stream,
1325
470
                dis_style_text, "-");
1326
470
          (*info->fprintf_styled_func) (info->stream,
1327
470
                dis_style_register,
1328
470
                "%%fp%d", regno);
1329
470
        }
1330
1.33k
    }
1331
982
    }
1332
794
  else if (place == '8')
1333
794
    {
1334
794
      FETCH_ARG (3, val);
1335
      /* fmoveml for FP status registers.  */
1336
794
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1337
794
            "%s", fpcr_names[val]);
1338
794
    }
1339
0
  else
1340
0
    return PRINT_INSN_ARG_INVALID_OP_TABLE;
1341
7.08k
      break;
1342
1343
7.08k
    case 'X':
1344
1.52k
      place = '8';
1345
      /* Fall through.  */
1346
1.93k
    case 'Y':
1347
2.00k
    case 'Z':
1348
3.12k
    case 'W':
1349
3.29k
    case '0':
1350
3.88k
    case '1':
1351
5.74k
    case '2':
1352
6.43k
    case '3':
1353
6.43k
      {
1354
6.43k
  char *name = 0;
1355
1356
6.43k
  FETCH_ARG (5, val);
1357
6.43k
  switch (val)
1358
6.43k
    {
1359
503
    case 2: name = "%tt0"; break;
1360
185
    case 3: name = "%tt1"; break;
1361
262
    case 0x10: name = "%tc"; break;
1362
80
    case 0x11: name = "%drp"; break;
1363
600
    case 0x12: name = "%srp"; break;
1364
140
    case 0x13: name = "%crp"; break;
1365
296
    case 0x14: name = "%cal"; break;
1366
592
    case 0x15: name = "%val"; break;
1367
22
    case 0x16: name = "%scc"; break;
1368
1.74k
    case 0x17: name = "%ac"; break;
1369
539
    case 0x18: name = "%psr"; break;
1370
144
    case 0x19: name = "%pcsr"; break;
1371
149
    case 0x1c:
1372
952
    case 0x1d:
1373
952
      {
1374
952
        int break_reg = ((buffer[3] >> 2) & 7);
1375
1376
952
        (*info->fprintf_styled_func)
1377
952
    (info->stream, dis_style_register,
1378
952
     val == 0x1c ? "%%bad%d" : "%%bac%d", break_reg);
1379
952
      }
1380
952
      break;
1381
368
    default:
1382
368
      (*info->fprintf_styled_func) (info->stream, dis_style_text,
1383
368
            "<mmu register %d>", val);
1384
6.43k
    }
1385
6.43k
  if (name)
1386
5.11k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1387
5.11k
          "%s", name);
1388
6.43k
      }
1389
0
      break;
1390
1391
296
    case 'f':
1392
296
      {
1393
296
  int fc;
1394
1395
296
  FETCH_ARG (5, fc);
1396
296
  if (fc == 1)
1397
74
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1398
74
          "%%dfc");
1399
222
  else if (fc == 0)
1400
222
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1401
222
          "%%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
296
      }
1407
0
      break;
1408
1409
62
    case 'V':
1410
62
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%val");
1411
62
      break;
1412
1413
4.07k
    case 't':
1414
4.07k
      {
1415
4.07k
  int level;
1416
1417
4.07k
  FETCH_ARG (3, level);
1418
4.07k
  (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1419
4.07k
              "%d", level);
1420
4.07k
      }
1421
0
      break;
1422
1423
30.2k
    case 'u':
1424
30.2k
      {
1425
30.2k
  short is_upper = 0;
1426
30.2k
  int reg;
1427
1428
30.2k
  FETCH_ARG (5, reg);
1429
30.2k
  if (reg & 0x10)
1430
10.2k
    {
1431
10.2k
      is_upper = 1;
1432
10.2k
      reg &= 0xf;
1433
10.2k
    }
1434
30.2k
  (*info->fprintf_styled_func) (info->stream, dis_style_register, "%s%s",
1435
30.2k
              reg_half_names[reg],
1436
30.2k
              is_upper ? "u" : "l");
1437
30.2k
      }
1438
0
      break;
1439
1440
0
    default:
1441
0
      return PRINT_INSN_ARG_INVALID_OP_TABLE;
1442
3.63M
    }
1443
1444
3.35M
  return p - p0;
1445
3.63M
}
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
820k
{
1452
  /* All branches have an operand in 'B' format (the 'B' place only comes
1453
     with the 'B' format).  */
1454
820k
  if (strchr (opc->args, 'B') == NULL)
1455
751k
    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
5.22k
    return dis_branch;
1461
1462
63.7k
  if (strncmp (opc->name, "bsr", 3) == 0)
1463
6.66k
    return dis_jsr;
1464
1465
57.0k
  return dis_condbranch;
1466
63.7k
}
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.09M
{
1477
1.09M
  unsigned char *save_p;
1478
1.09M
  unsigned char *p;
1479
1.09M
  const char *d;
1480
1.09M
  const char *args = best->args;
1481
1482
1.09M
  struct private *priv = (struct private *) info->private_data;
1483
1.09M
  bfd_byte *buffer = priv->the_buffer;
1484
1.09M
  fprintf_styled_ftype save_printer = info->fprintf_styled_func;
1485
1.09M
  void (* save_print_address) (bfd_vma, struct disassemble_info *)
1486
1.09M
    = info->print_address_func;
1487
1488
1.09M
  if (*args == '.')
1489
28.9k
    args++;
1490
1491
  /* Point at first word of argument data,
1492
     and at descriptor for first argument.  */
1493
1.09M
  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.29M
  for (d = args; *d; d += 2)
1500
2.19M
    {
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.19M
      if (d[0] == '#')
1504
307k
  {
1505
307k
    if (d[1] == 'l' && p - buffer < 6)
1506
15.0k
      p = buffer + 6;
1507
292k
    else if (p - buffer < 4 && d[1] != 'C' && d[1] != '8')
1508
291k
      p = buffer + 4;
1509
307k
  }
1510
1511
2.19M
      if ((d[0] == 'L' || d[0] == 'l') && d[1] == 'w' && p - buffer < 4)
1512
4.89k
  p = buffer + 4;
1513
1514
2.19M
      switch (d[1])
1515
2.19M
  {
1516
36.0k
  case '1':
1517
37.9k
  case '2':
1518
74.0k
  case '3':
1519
77.1k
  case '7':
1520
84.4k
  case '8':
1521
84.9k
  case '9':
1522
92.6k
  case 'i':
1523
92.6k
    if (p - buffer < 4)
1524
51.0k
      p = buffer + 4;
1525
92.6k
    break;
1526
506
  case '4':
1527
1.01k
  case '5':
1528
1.51k
  case '6':
1529
1.51k
    if (p - buffer < 6)
1530
506
      p = buffer + 6;
1531
1.51k
    break;
1532
2.09M
  default:
1533
2.09M
    break;
1534
2.19M
  }
1535
2.19M
    }
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.09M
  if (p - buffer < 4 && (best->match & 0xFFFF) != 0)
1540
15.7k
    p = buffer + 4;
1541
1542
  /* lpstop is another exception.  It takes a one word argument but is
1543
     three words long.  */
1544
1.09M
  if (p - buffer < 6
1545
1.08M
      && (best->match & 0xffff) == 0xffff
1546
2.97k
      && args[0] == '#'
1547
85
      && args[1] == 'w')
1548
85
    {
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
85
      p = buffer + 6;
1554
85
      if (!FETCH_DATA (info, p))
1555
2
  return -1;
1556
83
      buffer[2] = buffer[4];
1557
83
      buffer[3] = buffer[5];
1558
83
    }
1559
1560
1.09M
  if (!FETCH_DATA (info, p))
1561
325
    return -1;
1562
1563
1.09M
  save_p = p;
1564
1.09M
  info->print_address_func = dummy_print_address;
1565
1.09M
  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.85M
  for (d = args; *d; d += 2)
1570
2.03M
    {
1571
2.03M
      int eaten = print_insn_arg (d, buffer, p, memaddr + (p - buffer), info);
1572
1573
2.03M
      if (eaten >= 0)
1574
1.75M
  p += eaten;
1575
277k
      else if (eaten == PRINT_INSN_ARG_INVALID_OPERAND
1576
518
         || eaten == PRINT_INSN_ARG_MEMORY_ERROR)
1577
277k
  {
1578
277k
    info->fprintf_styled_func = save_printer;
1579
277k
    info->print_address_func = save_print_address;
1580
277k
    return eaten == PRINT_INSN_ARG_MEMORY_ERROR ? -1 : 0;
1581
277k
  }
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.03M
    }
1595
1596
820k
  p = save_p;
1597
820k
  info->fprintf_styled_func = save_printer;
1598
820k
  info->print_address_func = save_print_address;
1599
820k
  info->insn_type = m68k_opcode_to_insn_type (best);
1600
1601
820k
  d = args;
1602
1603
820k
  info->fprintf_styled_func (info->stream, dis_style_mnemonic, "%s", best->name);
1604
1605
820k
  if (*d)
1606
820k
    info->fprintf_styled_func (info->stream, dis_style_text, " ");
1607
1608
2.42M
  while (*d)
1609
1.60M
    {
1610
1.60M
      p += print_insn_arg (d, buffer, p, memaddr + (p - buffer), info);
1611
1.60M
      d += 2;
1612
1613
1.60M
      if (*d && *(d - 2) != 'I' && *d != 'k')
1614
778k
  info->fprintf_styled_func (info->stream, dis_style_text, ",");
1615
1.60M
    }
1616
1617
820k
  return p - buffer;
1618
1.09M
}
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.38M
{
1630
1.38M
  int i;
1631
1.38M
  const char *d;
1632
1.38M
  static const struct m68k_opcode **opcodes[16];
1633
1.38M
  static int numopcodes[16];
1634
1.38M
  int val;
1635
1.38M
  int major_opcode;
1636
1637
1.38M
  struct private *priv = (struct private *) info->private_data;
1638
1.38M
  bfd_byte *buffer = priv->the_buffer;
1639
1640
1.38M
  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.38M
  if (!FETCH_DATA (info, buffer + 2))
1667
928
    return -1;
1668
1.38M
  major_opcode = (buffer[0] >> 4) & 15;
1669
1670
321M
  for (i = 0; i < numopcodes[major_opcode]; i++)
1671
321M
    {
1672
321M
      const struct m68k_opcode *opc = opcodes[major_opcode][i];
1673
321M
      unsigned long opcode = opc->opcode;
1674
321M
      unsigned long match = opc->match;
1675
321M
      const char *args = opc->args;
1676
1677
321M
      if (*args == '.')
1678
3.58M
  args++;
1679
1680
321M
      if (((0xff & buffer[0] & (match >> 24)) == (0xff & (opcode >> 24)))
1681
70.8M
    && ((0xff & buffer[1] & (match >> 16)) == (0xff & (opcode >> 16)))
1682
    /* Only fetch the next two bytes if we need to.  */
1683
19.2M
    && (((0xffff & match) == 0)
1684
17.7M
        ||
1685
17.7M
        (FETCH_DATA (info, buffer + 4)
1686
17.7M
         && ((0xff & buffer[2] & (match >> 8)) == (0xff & (opcode >> 8)))
1687
1.27M
         && ((0xff & buffer[3] & match) == (0xff & opcode)))
1688
19.2M
        )
1689
1.58M
    && (opc->arch & arch_mask) != 0)
1690
1.13M
  {
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.39M
    for (d = args; *d; d += 2)
1695
2.26M
      if (d[1] == 'D')
1696
675
        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.13M
    if (*d == '\0')
1702
3.39M
      for (d = args; *d; d += 2)
1703
2.26M
        if (d[1] == 't')
1704
733
    break;
1705
1706
    /* Don't match fmovel with more than one register;
1707
       wait for fmoveml.  */
1708
1.13M
    if (*d == '\0')
1709
1.13M
      {
1710
3.39M
        for (d = args; *d; d += 2)
1711
2.26M
    {
1712
2.26M
      if (d[0] == 's' && d[1] == '8')
1713
1.56k
        {
1714
1.56k
          val = fetch_arg (buffer, d[1], 3, info);
1715
1.56k
          if (val < 0)
1716
0
      return 0;
1717
1.56k
          if ((val & (val - 1)) != 0)
1718
251
      break;
1719
1.56k
        }
1720
2.26M
    }
1721
1.13M
      }
1722
1723
    /* Don't match FPU insns with non-default coprocessor ID.  */
1724
1.13M
    if (*d == '\0')
1725
1.13M
      {
1726
3.32M
        for (d = args; *d; d += 2)
1727
2.22M
    {
1728
2.22M
      if (d[0] == 'I')
1729
43.0k
        {
1730
43.0k
          val = fetch_arg (buffer, 'd', 3, info);
1731
43.0k
          if (val != 1)
1732
32.5k
      break;
1733
43.0k
        }
1734
2.22M
    }
1735
1.13M
      }
1736
1737
1.13M
    if (*d == '\0')
1738
1.09M
      if ((val = match_insn_m68k (memaddr, info, opc)))
1739
821k
        return val;
1740
1.13M
  }
1741
321M
    }
1742
566k
  return 0;
1743
1.38M
}
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.12M
{
1751
1.12M
  unsigned int arch_mask;
1752
1.12M
  struct private priv;
1753
1.12M
  int val;
1754
1755
1.12M
  bfd_byte *buffer = priv.the_buffer;
1756
1757
1.12M
  info->insn_info_valid = 1;
1758
1.12M
  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.12M
  info->bytes_per_chunk = 2;
1762
1.12M
  info->bytes_per_line = 6;
1763
1.12M
  info->display_endian = BFD_ENDIAN_BIG;
1764
1.12M
  priv.max_fetched = priv.the_buffer;
1765
1.12M
  priv.insn_start = memaddr;
1766
1767
1.12M
  arch_mask = bfd_m68k_mach_to_features (info->mach);
1768
1.12M
  if (!arch_mask)
1769
943k
    {
1770
      /* First try printing an m680x0 instruction.  Try printing a Coldfire
1771
   one if that fails.  */
1772
943k
      val = m68k_scan_mask (memaddr, info, m68k_mask);
1773
943k
      if (val <= 0)
1774
261k
  val = m68k_scan_mask (memaddr, info, mcf_mask);
1775
943k
    }
1776
184k
  else
1777
184k
    {
1778
184k
      val = m68k_scan_mask (memaddr, info, arch_mask);
1779
184k
    }
1780
1781
1.12M
  if (val == 0)
1782
306k
    {
1783
      /* Handle undefined instructions.  */
1784
306k
      info->fprintf_styled_func (info->stream, dis_style_assembler_directive,
1785
306k
         ".short");
1786
306k
      info->fprintf_styled_func (info->stream, dis_style_text, " ");
1787
306k
      info->fprintf_styled_func (info->stream, dis_style_immediate,
1788
306k
         "0x%04x", (buffer[0] << 8) + buffer[1]);
1789
1790
306k
      info->insn_type = dis_noninsn;
1791
306k
    }
1792
1793
1.12M
  return val ? val : 2;
1794
1.12M
}