Coverage Report

Created: 2026-10-02 09:53

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
564k
#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
440k
  do            \
77
440k
    {           \
78
440k
      p += 2;         \
79
440k
      if (!FETCH_DATA (info, p))   \
80
440k
  return PRINT_INSN_ARG_MEMORY_ERROR; \
81
440k
      val = COERCE_SIGNED_CHAR (p[-1]);   \
82
440k
    }            \
83
440k
  while (0)
84
85
/* Get a 2 byte signed integer.  */
86
387k
#define COERCE16(x) ((int) (((x) ^ 0x8000) - 0x8000))
87
88
#define NEXTWORD(p, val, ret_val)   \
89
387k
  do            \
90
387k
    {           \
91
387k
      p += 2;         \
92
387k
      if (!FETCH_DATA (info, p))   \
93
387k
  return ret_val;       \
94
387k
      val = COERCE16 ((p[-2] << 8) + p[-1]);  \
95
387k
    }            \
96
387k
  while (0)
97
98
/* Get a 4 byte signed integer.  */
99
76.1k
#define COERCE32(x) (((bfd_vma) (x) ^ 0x80000000) - 0x80000000)
100
101
#define NEXTLONG(p, val, ret_val)         \
102
76.3k
  do                  \
103
76.3k
    {                 \
104
76.3k
      p += 4;               \
105
76.3k
      if (!FETCH_DATA (info, p))         \
106
76.3k
  return ret_val;             \
107
76.3k
      val = COERCE32 (((((((unsigned) p[-4] << 8) + p[-3]) << 8)  \
108
76.1k
      + p[-2]) << 8) + p[-1]);      \
109
76.1k
    }                  \
110
76.3k
  while (0)
111
112
/* Get a 4 byte unsigned integer.  */
113
#define NEXTULONG(p, val)           \
114
16.0k
  do                  \
115
16.0k
    {                 \
116
16.0k
      p += 4;               \
117
16.0k
      if (!FETCH_DATA (info, p))         \
118
16.0k
  return PRINT_INSN_ARG_MEMORY_ERROR;       \
119
16.0k
      val = (((((((unsigned) p[-4] << 8) + p[-3]) << 8)     \
120
16.0k
         + p[-2]) << 8) + p[-1]);         \
121
16.0k
    }                  \
122
16.0k
  while (0)
123
124
/* Get a single precision float.  */
125
#define NEXTSINGLE(val, p)          \
126
286
  do                \
127
286
    {               \
128
286
      p += 4;             \
129
286
      if (!FETCH_DATA (info, p))       \
130
286
  return PRINT_INSN_ARG_MEMORY_ERROR;     \
131
286
      floatformat_to_double (& floatformat_ieee_single_big, \
132
286
           (char *) p - 4, & val);    \
133
286
    }                \
134
286
  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
599
  do              \
151
599
    {             \
152
599
      p += 12;            \
153
599
      if (!FETCH_DATA (info, p))     \
154
599
  return PRINT_INSN_ARG_MEMORY_ERROR;   \
155
599
      floatformat_to_double (& floatformat_m68881_ext,  \
156
598
           (char *) p - 12, & val); \
157
598
    }              \
158
599
  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
1.08k
  do            \
166
1.08k
    {           \
167
1.08k
      p += 12;          \
168
1.08k
      if (!FETCH_DATA (info, p))   \
169
1.08k
  return PRINT_INSN_ARG_MEMORY_ERROR; \
170
1.08k
      val = 0.0;        \
171
1.07k
    }            \
172
1.08k
  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.5M
  ((addr) <= ((struct private *) (info->private_data))->max_fetched \
191
39.5M
   ? 1 : fetch_data ((info), (addr)))
192
193
static int
194
fetch_data (struct disassemble_info *info, bfd_byte *addr)
195
1.68M
{
196
1.68M
  int status;
197
1.68M
  struct private *priv = (struct private *)info->private_data;
198
1.68M
  bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
199
200
1.68M
  status = (*info->read_memory_func) (start,
201
1.68M
              priv->max_fetched,
202
1.68M
              addr - priv->max_fetched,
203
1.68M
              info);
204
1.68M
  if (status != 0)
205
18.5k
    {
206
18.5k
      (*info->memory_error_func) (status, start, info);
207
18.5k
      return 0;
208
18.5k
    }
209
1.66M
  else
210
1.66M
    priv->max_fetched = addr;
211
1.66M
  return 1;
212
1.68M
}
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.56M
{
221
2.56M
  return 0;
222
2.56M
}
223
224
static void
225
dummy_print_address (bfd_vma vma ATTRIBUTE_UNUSED,
226
         struct disassemble_info *info ATTRIBUTE_UNUSED)
227
96.4k
{
228
96.4k
}
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.93M
{
242
2.93M
  int val = 0;
243
244
2.93M
  switch (code)
245
2.93M
    {
246
10.0k
    case '/': /* MAC/EMAC mask bit.  */
247
10.0k
      val = buffer[3] >> 5;
248
10.0k
      break;
249
250
1.23k
    case 'G': /* EMAC ACC load.  */
251
1.23k
      val = ((buffer[3] >> 3) & 0x2) | ((~buffer[1] >> 7) & 0x1);
252
1.23k
      break;
253
254
790
    case 'H': /* EMAC ACC !load.  */
255
790
      val = ((buffer[3] >> 3) & 0x2) | ((buffer[1] >> 7) & 0x1);
256
790
      break;
257
258
384
    case ']': /* EMAC ACCEXT bit.  */
259
384
      val = buffer[0] >> 2;
260
384
      break;
261
262
15.0k
    case 'I': /* MAC/EMAC scale factor.  */
263
15.0k
      val = buffer[2] >> 1;
264
15.0k
      break;
265
266
874
    case 'F': /* EMAC ACCx.  */
267
874
      val = buffer[0] >> 1;
268
874
      break;
269
270
298
    case 'f':
271
298
      val = buffer[1];
272
298
      break;
273
274
1.72M
    case 's':
275
1.72M
      val = buffer[1];
276
1.72M
      break;
277
278
721k
    case 'd':     /* Destination, for register or quick.  */
279
721k
      val = (buffer[0] << 8) + buffer[1];
280
721k
      val >>= 9;
281
721k
      break;
282
283
240k
    case 'x':     /* Destination, for general arg.  */
284
240k
      val = (buffer[0] << 8) + buffer[1];
285
240k
      val >>= 6;
286
240k
      break;
287
288
398
    case 'k':
289
398
      if (! FETCH_DATA (info, buffer + 3))
290
0
  return -1;
291
398
      val = (buffer[3] >> 4);
292
398
      break;
293
294
838
    case 'C':
295
838
      if (! FETCH_DATA (info, buffer + 3))
296
0
  return -1;
297
838
      val = buffer[3];
298
838
      break;
299
300
53.0k
    case '1':
301
53.0k
      if (! FETCH_DATA (info, buffer + 3))
302
0
  return -1;
303
53.0k
      val = (buffer[2] << 8) + buffer[3];
304
53.0k
      val >>= 12;
305
53.0k
      break;
306
307
2.56k
    case '2':
308
2.56k
      if (! FETCH_DATA (info, buffer + 3))
309
0
  return -1;
310
2.56k
      val = (buffer[2] << 8) + buffer[3];
311
2.56k
      val >>= 6;
312
2.56k
      break;
313
314
46.1k
    case '3':
315
48.2k
    case 'j':
316
48.2k
      if (! FETCH_DATA (info, buffer + 3))
317
0
  return -1;
318
48.2k
      val = (buffer[2] << 8) + buffer[3];
319
48.2k
      break;
320
321
548
    case '4':
322
548
      if (! FETCH_DATA (info, buffer + 5))
323
0
  return -1;
324
548
      val = (buffer[4] << 8) + buffer[5];
325
548
      val >>= 12;
326
548
      break;
327
328
548
    case '5':
329
548
      if (! FETCH_DATA (info, buffer + 5))
330
0
  return -1;
331
548
      val = (buffer[4] << 8) + buffer[5];
332
548
      val >>= 6;
333
548
      break;
334
335
548
    case '6':
336
548
      if (! FETCH_DATA (info, buffer + 5))
337
0
  return -1;
338
548
      val = (buffer[4] << 8) + buffer[5];
339
548
      break;
340
341
5.71k
    case '7':
342
5.71k
      if (! FETCH_DATA (info, buffer + 3))
343
0
  return -1;
344
5.71k
      val = (buffer[2] << 8) + buffer[3];
345
5.71k
      val >>= 7;
346
5.71k
      break;
347
348
10.8k
    case '8':
349
10.8k
      if (! FETCH_DATA (info, buffer + 3))
350
0
  return -1;
351
10.8k
      val = (buffer[2] << 8) + buffer[3];
352
10.8k
      val >>= 10;
353
10.8k
      break;
354
355
1.01k
    case '9':
356
1.01k
      if (! FETCH_DATA (info, buffer + 3))
357
0
  return -1;
358
1.01k
      val = (buffer[2] << 8) + buffer[3];
359
1.01k
      val >>= 5;
360
1.01k
      break;
361
362
3.22k
    case 'e':
363
3.22k
      val = (buffer[1] >> 6);
364
3.22k
      break;
365
366
40.1k
    case 'E':
367
40.1k
      if (! FETCH_DATA (info, buffer + 3))
368
0
  return -1;
369
40.1k
      val = (buffer[2] >> 1);
370
40.1k
      break;
371
372
7.08k
    case 'm':
373
7.08k
      val = (buffer[1] & 0x40 ? 0x8 : 0)
374
7.08k
  | ((buffer[0] >> 1) & 0x7)
375
7.08k
  | (buffer[3] & 0x80 ? 0x10 : 0);
376
7.08k
      break;
377
378
10.0k
    case 'n':
379
10.0k
      val = (buffer[1] & 0x40 ? 0x8 : 0) | ((buffer[0] >> 1) & 0x7);
380
10.0k
      break;
381
382
14.5k
    case 'o':
383
14.5k
      val = (buffer[2] >> 4) | (buffer[3] & 0x80 ? 0x10 : 0);
384
14.5k
      break;
385
386
7.08k
    case 'M':
387
7.08k
      val = (buffer[1] & 0xf) | (buffer[3] & 0x40 ? 0x10 : 0);
388
7.08k
      break;
389
390
14.5k
    case 'N':
391
14.5k
      val = (buffer[3] & 0xf) | (buffer[3] & 0x40 ? 0x10 : 0);
392
14.5k
      break;
393
394
858
    case 'h':
395
858
      val = buffer[2] >> 2;
396
858
      break;
397
398
0
    default:
399
0
      abort ();
400
2.93M
    }
401
402
  /* bits is never too big.  */
403
2.93M
  return val & ((1 << bits) - 1);
404
2.93M
}
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
316k
    case '*':
424
316k
      mask = M (1,1,1,1,1,1,1,1,1,1,1,1);
425
316k
      break;
426
73.9k
    case '~':
427
73.9k
      mask = M (0,0,1,1,1,1,1,1,1,0,0,0);
428
73.9k
      break;
429
257k
    case '%':
430
257k
      mask = M (1,1,1,1,1,1,1,1,1,0,0,0);
431
257k
      break;
432
270k
    case ';':
433
270k
      mask = M (1,0,1,1,1,1,1,1,1,1,1,1);
434
270k
      break;
435
8.23k
    case '@':
436
8.23k
      mask = M (1,0,1,1,1,1,1,1,1,1,1,0);
437
8.23k
      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
3.50k
    case '&':
442
3.50k
      mask = M (0,0,1,0,0,1,1,1,1,0,0,0);
443
3.50k
      break;
444
665k
    case '$':
445
665k
      mask = M (1,0,1,1,1,1,1,1,1,0,0,0);
446
665k
      break;
447
1.23k
    case '?':
448
1.23k
      mask = M (1,0,1,0,0,1,1,1,1,0,0,0);
449
1.23k
      break;
450
1.10k
    case '/':
451
1.10k
      mask = M (1,0,1,0,0,1,1,1,1,1,1,0);
452
1.10k
      break;
453
135
    case '|':
454
135
      mask = M (0,0,1,0,0,1,1,1,1,1,1,0);
455
135
      break;
456
1.68k
    case '>':
457
1.68k
      mask = M (0,0,1,0,1,1,1,1,1,0,0,0);
458
1.68k
      break;
459
3.78k
    case '<':
460
3.78k
      mask = M (0,0,1,1,0,1,1,1,1,1,1,0);
461
3.78k
      break;
462
44.5k
    case 'm':
463
44.5k
      mask = M (1,1,1,1,1,0,0,0,0,0,0,0);
464
44.5k
      break;
465
33.8k
    case 'n':
466
33.8k
      mask = M (0,0,0,0,0,1,0,0,0,1,0,0);
467
33.8k
      break;
468
28.7k
    case 'o':
469
28.7k
      mask = M (0,0,0,0,0,0,1,1,1,0,1,1);
470
28.7k
      break;
471
49.5k
    case 'p':
472
49.5k
      mask = M (1,1,1,1,1,1,0,0,0,0,0,0);
473
49.5k
      break;
474
3.92k
    case 'q':
475
3.92k
      mask = M (1,0,1,1,1,1,0,0,0,0,0,0);
476
3.92k
      break;
477
2.23k
    case 'v':
478
2.23k
      mask = M (1,0,1,1,1,1,0,1,1,0,0,0);
479
2.23k
      break;
480
74
    case 'b':
481
74
      mask = M (1,0,1,1,1,1,0,0,0,1,0,0);
482
74
      break;
483
93
    case 'w':
484
93
      mask = M (0,0,1,1,1,1,0,0,0,1,0,0);
485
93
      break;
486
1.70k
    case 'y':
487
1.70k
      mask = M (0,0,1,0,0,1,0,0,0,0,0,0);
488
1.70k
      break;
489
342
    case 'z':
490
342
      mask = M (0,0,1,0,0,1,0,0,0,1,0,0);
491
342
      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.79M
    }
498
1.79M
#undef M
499
500
1.79M
  mode = (val >> 3) & 7;
501
1.79M
  if (mode == 7)
502
212k
    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
130k
{
512
130k
  if (regno == -1)
513
6.83k
    {
514
6.83k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%pc");
515
6.83k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
516
6.83k
      (*info->print_address_func) (disp, info);
517
6.83k
    }
518
123k
  else
519
123k
    {
520
123k
      if (regno == -3)
521
1.61k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
522
1.61k
              "%%zpc");
523
121k
      else if (regno != -2)
524
102k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
525
102k
              "%s", reg_names[regno]);
526
123k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
527
123k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
528
123k
            "%" PRIx64, (uint64_t) disp);
529
123k
    }
530
130k
}
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
62.6k
    {
544
62.6k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ":");
545
62.6k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
546
62.6k
            "%d", 1 << ((ext >> 9) & 3));
547
62.6k
    }
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
130k
{
561
130k
  int word;
562
130k
  bfd_vma base_disp;
563
130k
  bfd_vma outer_disp;
564
130k
  bool print_index = true;
565
566
130k
  NEXTWORD (p, word, NULL);
567
568
  /* Handle the 68000 style of indexing.  */
569
570
130k
  if ((word & 0x100) == 0)
571
73.1k
    {
572
73.1k
      base_disp = word & 0xff;
573
73.1k
      if ((base_disp & 0x80) != 0)
574
23.3k
  base_disp -= 0x100;
575
73.1k
      if (basereg == -1)
576
2.98k
  base_disp += addr;
577
73.1k
      print_base (basereg, base_disp, info);
578
73.1k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ",");
579
73.1k
      print_index_register (word, info);
580
73.1k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
581
73.1k
      return p;
582
73.1k
    }
583
584
  /* Handle the generalized kind.  */
585
  /* First, compute the displacement to add to the base register.  */
586
57.4k
  if (word & 0200)
587
21.4k
    {
588
21.4k
      if (basereg == -1)
589
1.61k
  basereg = -3;
590
19.7k
      else
591
19.7k
  basereg = -2;
592
21.4k
    }
593
57.4k
  if (word & 0100)
594
25.7k
    print_index = false;
595
57.4k
  base_disp = 0;
596
57.4k
  switch ((word >> 4) & 3)
597
57.4k
    {
598
12.7k
    case 2:
599
12.7k
      NEXTWORD (p, base_disp, NULL);
600
12.7k
      break;
601
23.3k
    case 3:
602
23.3k
      NEXTLONG (p, base_disp, NULL);
603
57.4k
    }
604
57.3k
  if (basereg == -1)
605
3.85k
    base_disp += addr;
606
607
  /* Handle single-level case (not indirect).  */
608
57.3k
  if ((word & 7) == 0)
609
10.2k
    {
610
10.2k
      print_base (basereg, base_disp, info);
611
10.2k
      if (print_index)
612
7.35k
  {
613
7.35k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, ",");
614
7.35k
    print_index_register (word, info);
615
7.35k
  }
616
10.2k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
617
10.2k
      return p;
618
10.2k
    }
619
620
  /* Two level.  Compute displacement to add after indirection.  */
621
47.1k
  outer_disp = 0;
622
47.1k
  switch (word & 3)
623
47.1k
    {
624
12.8k
    case 2:
625
12.8k
      NEXTWORD (p, outer_disp, NULL);
626
12.7k
      break;
627
14.6k
    case 3:
628
14.6k
      NEXTLONG (p, outer_disp, NULL);
629
47.1k
    }
630
631
47.0k
  print_base (basereg, base_disp, info);
632
47.0k
  if ((word & 4) == 0 && print_index)
633
12.3k
    {
634
12.3k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ",");
635
12.3k
      print_index_register (word, info);
636
12.3k
      print_index = false;
637
12.3k
    }
638
47.0k
  (*info->fprintf_styled_func) (info->stream, dis_style_text,
639
47.0k
        ")@(");
640
47.0k
  (*info->fprintf_styled_func) (info->stream, dis_style_address_offset,
641
47.0k
        "%" PRIx64, (uint64_t) outer_disp);
642
47.0k
  if (print_index)
643
11.8k
    {
644
11.8k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, ",");
645
11.8k
      print_index_register (word, info);
646
11.8k
    }
647
47.0k
  (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
648
649
47.0k
  return p;
650
47.1k
}
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.57M
{
672
3.57M
  int val = 0;
673
3.57M
  int place = d[1];
674
3.57M
  unsigned char *p = p0;
675
3.57M
  int regno;
676
3.57M
  const char *regname;
677
3.57M
  unsigned char *p1;
678
3.57M
  double flval;
679
3.57M
  int flt_p;
680
3.57M
  bfd_signed_vma disp;
681
3.57M
  unsigned int uval;
682
683
3.57M
  switch (*d)
684
3.57M
    {
685
3.22k
    case 'c':   /* Cache identifier.  */
686
3.22k
      {
687
3.22k
        static char *const cacheFieldName[] = { "nc", "dc", "ic", "bc" };
688
3.22k
        FETCH_ARG (2, val);
689
3.22k
  (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic,
690
3.22k
              "%s", cacheFieldName[val]);
691
3.22k
        break;
692
3.22k
      }
693
694
5.98k
    case 'a':   /* Address register indirect only. Cf. case '+'.  */
695
5.98k
      {
696
5.98k
  FETCH_ARG (3, val);
697
5.98k
  (*info->fprintf_styled_func) (info->stream, dis_style_register, "%s",
698
5.98k
              reg_names[val + 8]);
699
5.98k
  (*info->fprintf_styled_func) (info->stream, dis_style_text, "@");
700
5.98k
        break;
701
5.98k
      }
702
703
1.42k
    case '_':   /* 32-bit absolute address for move16.  */
704
1.42k
      {
705
1.42k
        NEXTULONG (p, uval);
706
1.42k
  (*info->print_address_func) (uval, info);
707
1.42k
        break;
708
1.42k
      }
709
710
2.80k
    case 'C':
711
2.80k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%ccr");
712
2.80k
      break;
713
714
2.32k
    case 'S':
715
2.32k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%sr");
716
2.32k
      break;
717
718
602
    case 'U':
719
602
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%usp");
720
602
      break;
721
722
1.05k
    case 'E':
723
1.05k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%acc");
724
1.05k
      break;
725
726
556
    case 'G':
727
556
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%macsr");
728
556
      break;
729
730
2.18k
    case 'H':
731
2.18k
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%mask");
732
2.18k
      break;
733
734
2.11k
    case 'J':
735
2.11k
      {
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.11k
  struct regname { char * name; int value; };
740
2.11k
  static const struct regname names[] =
741
2.11k
    {
742
2.11k
      {"%sfc", 0x000}, {"%dfc", 0x001}, {"%cacr", 0x002},
743
2.11k
      {"%tc",  0x003}, {"%itt0",0x004}, {"%itt1", 0x005},
744
2.11k
      {"%dtt0",0x006}, {"%dtt1",0x007}, {"%buscr",0x008},
745
2.11k
      {"%rgpiobar", 0x009}, {"%acr4",0x00c},
746
2.11k
      {"%acr5",0x00d}, {"%acr6",0x00e}, {"%acr7", 0x00f},
747
2.11k
      {"%usp", 0x800}, {"%vbr", 0x801}, {"%caar", 0x802},
748
2.11k
      {"%msp", 0x803}, {"%isp", 0x804},
749
2.11k
      {"%pc", 0x80f},
750
      /* Reg c04 is sometimes called flashbar or rambar.
751
         Reg c05 is also sometimes called rambar.  */
752
2.11k
      {"%rambar0", 0xc04}, {"%rambar1", 0xc05},
753
754
      /* reg c0e is sometimes called mbar2 or secmbar.
755
         reg c0f is sometimes called mbar.  */
756
2.11k
      {"%mbar0", 0xc0e}, {"%mbar1", 0xc0f},
757
758
      /* Should we be calling this psr like we do in case 'Y'?  */
759
2.11k
      {"%mmusr",0x805},
760
761
2.11k
      {"%urp", 0x806}, {"%srp", 0x807}, {"%pcr", 0x808},
762
763
      /* Fido added these.  */
764
2.11k
      {"%cac", 0xffe}, {"%mbo", 0xfff}
765
2.11k
  };
766
  /* Alternate names for v4e (MCF5407/5445x/MCF547x/MCF548x), at least.  */
767
2.11k
  static const struct regname names_v4e[] =
768
2.11k
    {
769
2.11k
      {"%asid",0x003}, {"%acr0",0x004}, {"%acr1",0x005},
770
2.11k
      {"%acr2",0x006}, {"%acr3",0x007}, {"%mmubar",0x008},
771
2.11k
    };
772
2.11k
  unsigned int arch_mask;
773
774
2.11k
  arch_mask = bfd_m68k_mach_to_features (info->mach);
775
2.11k
  FETCH_ARG (12, val);
776
2.11k
  if (arch_mask & (mcfisa_b | mcfisa_c))
777
762
    {
778
5.25k
      for (regno = ARRAY_SIZE (names_v4e); --regno >= 0;)
779
4.57k
        if (names_v4e[regno].value == val)
780
80
    {
781
80
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
782
80
                 "%s", names_v4e[regno].name);
783
80
      break;
784
80
    }
785
762
      if (regno >= 0)
786
80
        break;
787
762
    }
788
60.6k
  for (regno = ARRAY_SIZE (names) - 1; regno >= 0; regno--)
789
59.0k
    if (names[regno].value == val)
790
466
      {
791
466
        (*info->fprintf_styled_func) (info->stream, dis_style_register,
792
466
              "%s", names[regno].name);
793
466
        break;
794
466
      }
795
2.03k
  if (regno < 0)
796
1.57k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "0x%x", val);
797
2.03k
      }
798
0
      break;
799
800
129k
    case 'Q':
801
129k
      FETCH_ARG (3, val);
802
      /* 0 means 8, except for the bkpt instruction... */
803
129k
      if (val == 0 && d[1] != 's')
804
7.53k
  val = 8;
805
129k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
806
129k
            "#%d", val);
807
129k
      break;
808
809
5.24k
    case 'x':
810
5.24k
      FETCH_ARG (3, val);
811
      /* 0 means -1.  */
812
5.24k
      if (val == 0)
813
1.08k
  val = -1;
814
5.24k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
815
5.24k
            "#%d", val);
816
5.24k
      break;
817
818
40.1k
    case 'j':
819
40.1k
      FETCH_ARG (3, val);
820
40.1k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
821
40.1k
            "#%d", val+1);
822
40.1k
      break;
823
824
39.4k
    case 'K':
825
39.4k
      FETCH_ARG (9, val);
826
39.4k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
827
39.4k
            "#%d", val);
828
39.4k
      break;
829
830
52.6k
    case 'M':
831
52.6k
      if (place == 'h')
832
858
  {
833
858
    static char *const scalefactor_name[] = { "<<", ">>" };
834
835
858
    FETCH_ARG (1, val);
836
858
    (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic,
837
858
          "%s", scalefactor_name[val]);
838
858
  }
839
51.7k
      else
840
51.7k
  {
841
51.7k
    FETCH_ARG (8, val);
842
51.7k
    if (val & 0x80)
843
13.7k
      val = val - 0x100;
844
51.7k
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
845
51.7k
          "#%d", val);
846
51.7k
  }
847
52.6k
      break;
848
849
52.6k
    case 'T':
850
7.76k
      FETCH_ARG (4, val);
851
7.76k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
852
7.76k
            "#%d", val);
853
7.76k
      break;
854
855
533k
    case 'D':
856
533k
      FETCH_ARG (3, val);
857
533k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
858
533k
            "%s", reg_names[val]);
859
533k
      break;
860
861
71.9k
    case 'A':
862
71.9k
      FETCH_ARG (3, val);
863
71.9k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
864
71.9k
            "%s", reg_names[val + 010]);
865
71.9k
      break;
866
867
85.8k
    case 'R':
868
85.8k
      FETCH_ARG (4, val);
869
85.8k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
870
85.8k
            "%s", reg_names[val]);
871
85.8k
      break;
872
873
1.09k
    case 'r':
874
1.09k
      FETCH_ARG (4, regno);
875
1.09k
      if (regno > 7)
876
204
  {
877
204
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
878
204
          "%s", reg_names[regno]);
879
204
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@");
880
204
  }
881
892
      else
882
892
  {
883
892
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
884
892
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
885
892
          "%s", reg_names[regno]);
886
892
    (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
887
892
  }
888
1.09k
      break;
889
890
7.16k
    case 'F':
891
7.16k
      FETCH_ARG (3, val);
892
7.16k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
893
7.16k
            "%%fp%d", val);
894
7.16k
      break;
895
896
3.84k
    case 'O':
897
3.84k
      FETCH_ARG (6, val);
898
3.84k
      if (val & 0x20)
899
1.59k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
900
1.59k
              "%s", reg_names[val & 7]);
901
2.25k
      else
902
2.25k
  (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
903
2.25k
              "%d", val);
904
3.84k
      break;
905
906
5.92k
    case '+':
907
5.92k
      FETCH_ARG (3, val);
908
5.92k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
909
5.92k
            "%s", reg_names[val + 8]);
910
5.92k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, "@+");
911
5.92k
      break;
912
913
16.6k
    case '-':
914
16.6k
      FETCH_ARG (3, val);
915
16.6k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
916
16.6k
            "%s", reg_names[val + 8]);
917
16.6k
      (*info->fprintf_styled_func) (info->stream, dis_style_text, "@-");
918
16.6k
      break;
919
920
640
    case 'k':
921
640
      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
640
      else if (place == 'C')
930
640
  {
931
640
    FETCH_ARG (7, val);
932
640
    if (val > 63)    /* This is a signed constant.  */
933
504
      val -= 128;
934
640
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "{");
935
640
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
936
640
          "#%d", val);
937
640
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "}");
938
640
  }
939
0
      else
940
0
  return PRINT_INSN_ARG_INVALID_OPERAND;
941
640
      break;
942
943
525k
    case '#':
944
526k
    case '^':
945
526k
      p1 = buffer + (*d == '#' ? 2 : 4);
946
526k
      if (place == 's')
947
0
  FETCH_ARG (4, val);
948
526k
      else if (place == 'C')
949
198
  FETCH_ARG (7, val);
950
526k
      else if (place == '8')
951
0
  FETCH_ARG (3, val);
952
526k
      else if (place == '3')
953
622
  FETCH_ARG (8, val);
954
525k
      else if (place == 'b')
955
437k
  NEXTBYTE (p1, val);
956
88.9k
      else if (place == 'w' || place == 'W')
957
58.6k
  NEXTWORD (p1, val, PRINT_INSN_ARG_MEMORY_ERROR);
958
30.2k
      else if (place == 'l')
959
30.2k
  NEXTLONG (p1, val, PRINT_INSN_ARG_MEMORY_ERROR);
960
0
      else
961
0
  return PRINT_INSN_ARG_INVALID_OP_TABLE;
962
963
526k
      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
964
526k
            "#%d", val);
965
526k
      break;
966
967
142k
    case 'B':
968
142k
      if (place == 'b')
969
0
  NEXTBYTE (p, disp);
970
142k
      else if (place == 'B')
971
124k
  disp = COERCE_SIGNED_CHAR (buffer[1]);
972
18.0k
      else if (place == 'w' || place == 'W')
973
11.2k
  NEXTWORD (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
974
6.75k
      else if (place == 'l' || place == 'L' || place == 'C')
975
4.91k
  NEXTLONG (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
976
1.84k
      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.84k
      else if (place == 'c')
985
1.84k
  {
986
1.84k
    if (buffer[1] & 0x40)    /* If bit six is one, long offset.  */
987
1.03k
      NEXTLONG (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
988
817
    else
989
817
      NEXTWORD (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
990
1.84k
  }
991
0
      else
992
0
  return PRINT_INSN_ARG_INVALID_OP_TABLE;
993
994
142k
      info->target = addr + disp;
995
996
142k
      (*info->print_address_func) (addr + disp, info);
997
142k
      break;
998
999
11.2k
    case 'd':
1000
11.2k
      {
1001
11.2k
  int val1;
1002
1003
11.2k
  NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1004
11.2k
  FETCH_ARG (3, val1);
1005
11.2k
  (*info->fprintf_styled_func) (info->stream, dis_style_register,
1006
11.2k
              "%s", reg_names[val1 + 8]);
1007
11.2k
  (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
1008
11.2k
  (*info->fprintf_styled_func) (info->stream, dis_style_address_offset,
1009
11.2k
              "%d", val);
1010
11.2k
  (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
1011
11.2k
  break;
1012
11.2k
      }
1013
1014
974
    case 's':
1015
974
      FETCH_ARG (3, val);
1016
974
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1017
974
            "%s", fpcr_names[val]);
1018
974
      break;
1019
1020
3.20k
    case 'e':
1021
3.20k
      FETCH_ARG (2, val);
1022
3.20k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1023
3.20k
            "%%acc%d", val);
1024
3.20k
      break;
1025
1026
384
    case 'g':
1027
384
      FETCH_ARG (1, val);
1028
384
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1029
384
            "%%accext%s", val == 0 ? "01" : "23");
1030
384
      break;
1031
1032
15.0k
    case 'i':
1033
15.0k
      FETCH_ARG (2, val);
1034
15.0k
      if (val == 1)
1035
4.72k
  (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic,
1036
4.72k
              "<<");
1037
10.3k
      else if (val == 3)
1038
4.15k
  (*info->fprintf_styled_func) (info->stream, dis_style_sub_mnemonic,
1039
4.15k
              ">>");
1040
6.15k
      else
1041
6.15k
  return PRINT_INSN_ARG_INVALID_OPERAND;
1042
8.87k
      break;
1043
1044
14.2k
    case 'I':
1045
      /* Get coprocessor ID... */
1046
14.2k
      val = fetch_arg (buffer, 'd', 3, info);
1047
14.2k
      if (val < 0)
1048
0
  return PRINT_INSN_ARG_MEMORY_ERROR;
1049
14.2k
      if (val != 1)        /* Unusual coprocessor ID?  */
1050
0
  (*info->fprintf_styled_func) (info->stream, dis_style_text,
1051
0
              "(cpid=%d) ", val);
1052
14.2k
      break;
1053
1054
11.6k
    case '4':
1055
328k
    case '*':
1056
402k
    case '~':
1057
659k
    case '%':
1058
929k
    case ';':
1059
937k
    case '@':
1060
950k
    case '!':
1061
1.61M
    case '$':
1062
1.61M
    case '?':
1063
1.61M
    case '/':
1064
1.62M
    case '&':
1065
1.62M
    case '|':
1066
1.62M
    case '<':
1067
1.62M
    case '>':
1068
1.67M
    case 'm':
1069
1.70M
    case 'n':
1070
1.73M
    case 'o':
1071
1.78M
    case 'p':
1072
1.78M
    case 'q':
1073
1.78M
    case 'v':
1074
1.78M
    case 'b':
1075
1.78M
    case 'w':
1076
1.79M
    case 'y':
1077
1.79M
    case 'z':
1078
1.79M
      if (place == 'd')
1079
240k
  {
1080
240k
    val = fetch_arg (buffer, 'x', 6, info);
1081
240k
    if (val < 0)
1082
0
      return PRINT_INSN_ARG_MEMORY_ERROR;
1083
240k
    val = ((val & 7) << 3) + ((val >> 3) & 7);
1084
240k
  }
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
269k
  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
727k
  case 0:
1102
727k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1103
727k
          "%s", reg_names[val]);
1104
727k
    break;
1105
1106
38.4k
  case 1:
1107
38.4k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1108
38.4k
          "%s", regname);
1109
38.4k
    break;
1110
1111
116k
  case 2:
1112
116k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1113
116k
          "%s", regname);
1114
116k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@");
1115
116k
    break;
1116
1117
167k
  case 3:
1118
167k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1119
167k
          "%s", regname);
1120
167k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@+");
1121
167k
    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
112k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1132
112k
          "%s", regname);
1133
112k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
1134
112k
    (*info->fprintf_styled_func) (info->stream, dis_style_address_offset,
1135
112k
          "%d", val);
1136
112k
    (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
1137
112k
    break;
1138
1139
122k
  case 6:
1140
122k
    p = print_indexed (regno, p, addr, info);
1141
122k
    if (p == NULL)
1142
238
      return PRINT_INSN_ARG_MEMORY_ERROR;
1143
121k
    break;
1144
1145
121k
  case 7:
1146
63.8k
    switch (val & 7)
1147
63.8k
      {
1148
15.5k
      case 0:
1149
15.5k
        NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1150
15.5k
        (*info->print_address_func) (val, info);
1151
15.5k
        break;
1152
1153
14.6k
      case 1:
1154
14.6k
        NEXTULONG (p, uval);
1155
14.5k
        (*info->print_address_func) (uval, info);
1156
14.5k
        break;
1157
1158
10.4k
      case 2:
1159
10.4k
        NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1160
10.4k
        (*info->fprintf_styled_func) (info->stream, dis_style_register,
1161
10.4k
              "%%pc");
1162
10.4k
        (*info->fprintf_styled_func) (info->stream, dis_style_text, "@(");
1163
10.4k
        (*info->print_address_func) (addr + val, info);
1164
10.4k
        (*info->fprintf_styled_func) (info->stream, dis_style_text, ")");
1165
10.4k
        break;
1166
1167
8.47k
      case 3:
1168
8.47k
        p = print_indexed (-1, p, addr, info);
1169
8.47k
        if (p == NULL)
1170
26
    return PRINT_INSN_ARG_MEMORY_ERROR;
1171
8.44k
        break;
1172
1173
14.7k
      case 4:
1174
14.7k
        flt_p = 1;  /* Assume it's a float... */
1175
14.7k
        switch (place)
1176
14.7k
        {
1177
2.98k
    case 'b':
1178
2.98k
      NEXTBYTE (p, val);
1179
2.98k
      flt_p = 0;
1180
2.98k
      break;
1181
1182
6.58k
    case 'w':
1183
6.58k
      NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1184
6.56k
      flt_p = 0;
1185
6.56k
      break;
1186
1187
2.20k
    case 'l':
1188
2.20k
      NEXTLONG (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
1189
2.18k
      flt_p = 0;
1190
2.18k
      break;
1191
1192
286
    case 'f':
1193
286
      NEXTSINGLE (flval, p);
1194
286
      break;
1195
1196
1.05k
    case 'F':
1197
1.05k
      NEXTDOUBLE (flval, p);
1198
1.05k
      break;
1199
1200
1.05k
    case 'x':
1201
599
      NEXTEXTEND (flval, p);
1202
598
      break;
1203
1204
1.08k
    case 'p':
1205
1.08k
      NEXTPACKED (p, flval);
1206
1.07k
      break;
1207
1208
1.07k
    default:
1209
0
      return PRINT_INSN_ARG_INVALID_OPERAND;
1210
14.7k
        }
1211
14.7k
        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
11.7k
        else
1215
11.7k
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1216
11.7k
                "#%d", val);
1217
14.7k
        break;
1218
1219
0
      default:
1220
0
        return PRINT_INSN_ARG_INVALID_OPERAND;
1221
63.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
10.0k
  {
1229
10.0k
    FETCH_ARG (1, val);
1230
10.0k
    if (val)
1231
8.33k
      info->fprintf_styled_func (info->stream, dis_style_text, "&");
1232
10.0k
  }
1233
1.52M
      break;
1234
1235
1.52M
    case 'L':
1236
6.15k
    case 'l':
1237
6.15k
  if (place == 'w')
1238
4.39k
    {
1239
4.39k
      char doneany;
1240
4.39k
      p1 = buffer + 2;
1241
4.39k
      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.39k
      p = p1 > p ? p1 : p;
1245
4.39k
      if (val == 0)
1246
256
        {
1247
256
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1248
256
                "#0");
1249
256
    break;
1250
256
        }
1251
4.13k
      if (*d == 'l')
1252
1.33k
        {
1253
1.33k
    int newval = 0;
1254
1255
22.6k
    for (regno = 0; regno < 16; ++regno)
1256
21.3k
      if (val & (0x8000 >> regno))
1257
7.07k
        newval |= 1 << regno;
1258
1.33k
    val = newval;
1259
1.33k
        }
1260
4.13k
      val &= 0xffff;
1261
4.13k
      doneany = 0;
1262
56.0k
      for (regno = 0; regno < 16; ++regno)
1263
51.8k
        if (val & (1 << regno))
1264
13.2k
    {
1265
13.2k
      int first_regno;
1266
1267
13.2k
      if (doneany)
1268
9.14k
        (*info->fprintf_styled_func) (info->stream, dis_style_text,
1269
9.14k
              "/");
1270
13.2k
      doneany = 1;
1271
13.2k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1272
13.2k
            "%s", reg_names[regno]);
1273
13.2k
      first_regno = regno;
1274
27.5k
      while (val & (1 << (regno + 1)))
1275
14.3k
        ++regno;
1276
13.2k
      if (regno > first_regno)
1277
6.22k
        {
1278
6.22k
          (*info->fprintf_styled_func) (info->stream,
1279
6.22k
                dis_style_text, "-");
1280
6.22k
          (*info->fprintf_styled_func) (info->stream,
1281
6.22k
                dis_style_register, "%s",
1282
6.22k
                reg_names[regno]);
1283
6.22k
        }
1284
13.2k
    }
1285
4.13k
    }
1286
1.76k
  else if (place == '3')
1287
1.01k
    {
1288
      /* `fmovem' insn.  */
1289
1.01k
      char doneany;
1290
1291
1.01k
      FETCH_ARG (8, val);
1292
1.01k
      if (val == 0)
1293
76
        {
1294
76
    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1295
76
                "#0");
1296
76
    break;
1297
76
        }
1298
934
      if (*d == 'l')
1299
862
        {
1300
862
    int newval = 0;
1301
1302
7.75k
    for (regno = 0; regno < 8; ++regno)
1303
6.89k
      if (val & (0x80 >> regno))
1304
4.55k
        newval |= 1 << regno;
1305
862
    val = newval;
1306
862
        }
1307
934
      val &= 0xff;
1308
934
      doneany = 0;
1309
5.25k
      for (regno = 0; regno < 8; ++regno)
1310
4.31k
        if (val & (1 << regno))
1311
1.61k
    {
1312
1.61k
      int first_regno;
1313
1.61k
      if (doneany)
1314
680
        (*info->fprintf_styled_func) (info->stream, dis_style_text,
1315
680
              "/");
1316
1.61k
      doneany = 1;
1317
1.61k
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1318
1.61k
            "%%fp%d", regno);
1319
1.61k
      first_regno = regno;
1320
4.77k
      while (val & (1 << (regno + 1)))
1321
3.15k
        ++regno;
1322
1.61k
      if (regno > first_regno)
1323
580
        {
1324
580
          (*info->fprintf_styled_func) (info->stream,
1325
580
                dis_style_text, "-");
1326
580
          (*info->fprintf_styled_func) (info->stream,
1327
580
                dis_style_register,
1328
580
                "%%fp%d", regno);
1329
580
        }
1330
1.61k
    }
1331
934
    }
1332
751
  else if (place == '8')
1333
751
    {
1334
751
      FETCH_ARG (3, val);
1335
      /* fmoveml for FP status registers.  */
1336
751
      (*info->fprintf_styled_func) (info->stream, dis_style_register,
1337
751
            "%s", fpcr_names[val]);
1338
751
    }
1339
0
  else
1340
0
    return PRINT_INSN_ARG_INVALID_OP_TABLE;
1341
5.82k
      break;
1342
1343
5.82k
    case 'X':
1344
1.06k
      place = '8';
1345
      /* Fall through.  */
1346
1.34k
    case 'Y':
1347
1.42k
    case 'Z':
1348
2.46k
    case 'W':
1349
2.81k
    case '0':
1350
3.29k
    case '1':
1351
5.30k
    case '2':
1352
5.96k
    case '3':
1353
5.96k
      {
1354
5.96k
  char *name = 0;
1355
1356
5.96k
  FETCH_ARG (5, val);
1357
5.96k
  switch (val)
1358
5.96k
    {
1359
506
    case 2: name = "%tt0"; break;
1360
159
    case 3: name = "%tt1"; break;
1361
265
    case 0x10: name = "%tc"; break;
1362
262
    case 0x11: name = "%drp"; break;
1363
632
    case 0x12: name = "%srp"; break;
1364
330
    case 0x13: name = "%crp"; break;
1365
364
    case 0x14: name = "%cal"; break;
1366
524
    case 0x15: name = "%val"; break;
1367
50
    case 0x16: name = "%scc"; break;
1368
1.45k
    case 0x17: name = "%ac"; break;
1369
368
    case 0x18: name = "%psr"; break;
1370
152
    case 0x19: name = "%pcsr"; break;
1371
152
    case 0x1c:
1372
640
    case 0x1d:
1373
640
      {
1374
640
        int break_reg = ((buffer[3] >> 2) & 7);
1375
1376
640
        (*info->fprintf_styled_func)
1377
640
    (info->stream, dis_style_register,
1378
640
     val == 0x1c ? "%%bad%d" : "%%bac%d", break_reg);
1379
640
      }
1380
640
      break;
1381
260
    default:
1382
260
      (*info->fprintf_styled_func) (info->stream, dis_style_text,
1383
260
            "<mmu register %d>", val);
1384
5.96k
    }
1385
5.96k
  if (name)
1386
5.06k
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1387
5.06k
          "%s", name);
1388
5.96k
      }
1389
0
      break;
1390
1391
274
    case 'f':
1392
274
      {
1393
274
  int fc;
1394
1395
274
  FETCH_ARG (5, fc);
1396
274
  if (fc == 1)
1397
96
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1398
96
          "%%dfc");
1399
178
  else if (fc == 0)
1400
178
    (*info->fprintf_styled_func) (info->stream, dis_style_register,
1401
178
          "%%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
274
      }
1407
0
      break;
1408
1409
54
    case 'V':
1410
54
      (*info->fprintf_styled_func) (info->stream, dis_style_register, "%%val");
1411
54
      break;
1412
1413
3.38k
    case 't':
1414
3.38k
      {
1415
3.38k
  int level;
1416
1417
3.38k
  FETCH_ARG (3, level);
1418
3.38k
  (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
1419
3.38k
              "%d", level);
1420
3.38k
      }
1421
0
      break;
1422
1423
24.4k
    case 'u':
1424
24.4k
      {
1425
24.4k
  short is_upper = 0;
1426
24.4k
  int reg;
1427
1428
24.4k
  FETCH_ARG (5, reg);
1429
24.4k
  if (reg & 0x10)
1430
7.99k
    {
1431
7.99k
      is_upper = 1;
1432
7.99k
      reg &= 0xf;
1433
7.99k
    }
1434
24.4k
  (*info->fprintf_styled_func) (info->stream, dis_style_register, "%s%s",
1435
24.4k
              reg_half_names[reg],
1436
24.4k
              is_upper ? "u" : "l");
1437
24.4k
      }
1438
0
      break;
1439
1440
0
    default:
1441
0
      return PRINT_INSN_ARG_INVALID_OP_TABLE;
1442
3.57M
    }
1443
1444
3.29M
  return p - p0;
1445
3.57M
}
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
807k
{
1452
  /* All branches have an operand in 'B' format (the 'B' place only comes
1453
     with the 'B' format).  */
1454
807k
  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
71.3k
  if (strncmp (opc->name, "bra", 3) == 0)
1460
4.63k
    return dis_branch;
1461
1462
66.7k
  if (strncmp (opc->name, "bsr", 3) == 0)
1463
5.93k
    return dis_jsr;
1464
1465
60.8k
  return dis_condbranch;
1466
66.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.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.4k
    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.24M
  for (d = args; *d; d += 2)
1500
2.16M
    {
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.16M
      if (d[0] == '#')
1504
287k
  {
1505
287k
    if (d[1] == 'l' && p - buffer < 6)
1506
16.4k
      p = buffer + 6;
1507
270k
    else if (p - buffer < 4 && d[1] != 'C' && d[1] != '8')
1508
270k
      p = buffer + 4;
1509
287k
  }
1510
1511
2.16M
      if ((d[0] == 'L' || d[0] == 'l') && d[1] == 'w' && p - buffer < 4)
1512
4.17k
  p = buffer + 4;
1513
1514
2.16M
      switch (d[1])
1515
2.16M
  {
1516
34.0k
  case '1':
1517
35.7k
  case '2':
1518
69.0k
  case '3':
1519
72.1k
  case '7':
1520
78.9k
  case '8':
1521
79.5k
  case '9':
1522
87.2k
  case 'i':
1523
87.2k
    if (p - buffer < 4)
1524
48.0k
      p = buffer + 4;
1525
87.2k
    break;
1526
274
  case '4':
1527
548
  case '5':
1528
822
  case '6':
1529
822
    if (p - buffer < 6)
1530
274
      p = buffer + 6;
1531
822
    break;
1532
2.07M
  default:
1533
2.07M
    break;
1534
2.16M
  }
1535
2.16M
    }
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
15.1k
    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.70k
      && args[0] == '#'
1547
73
      && args[1] == 'w')
1548
73
    {
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
73
      p = buffer + 6;
1554
73
      if (!FETCH_DATA (info, p))
1555
2
  return -1;
1556
71
      buffer[2] = buffer[4];
1557
71
      buffer[3] = buffer[5];
1558
71
    }
1559
1560
1.08M
  if (!FETCH_DATA (info, p))
1561
337
    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.80M
  for (d = args; *d; d += 2)
1570
1.99M
    {
1571
1.99M
      int eaten = print_insn_arg (d, buffer, p, memaddr + (p - buffer), info);
1572
1573
1.99M
      if (eaten >= 0)
1574
1.72M
  p += eaten;
1575
276k
      else if (eaten == PRINT_INSN_ARG_INVALID_OPERAND
1576
599
         || eaten == PRINT_INSN_ARG_MEMORY_ERROR)
1577
276k
  {
1578
276k
    info->fprintf_styled_func = save_printer;
1579
276k
    info->print_address_func = save_print_address;
1580
276k
    return eaten == PRINT_INSN_ARG_MEMORY_ERROR ? -1 : 0;
1581
276k
  }
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
1.99M
    }
1595
1596
807k
  p = save_p;
1597
807k
  info->fprintf_styled_func = save_printer;
1598
807k
  info->print_address_func = save_print_address;
1599
807k
  info->insn_type = m68k_opcode_to_insn_type (best);
1600
1601
807k
  d = args;
1602
1603
807k
  info->fprintf_styled_func (info->stream, dis_style_mnemonic, "%s", best->name);
1604
1605
807k
  if (*d)
1606
806k
    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
763k
  info->fprintf_styled_func (info->stream, dis_style_text, ",");
1615
1.57M
    }
1616
1617
807k
  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
979
    return -1;
1668
1.36M
  major_opcode = (buffer[0] >> 4) & 15;
1669
1670
317M
  for (i = 0; i < numopcodes[major_opcode]; i++)
1671
317M
    {
1672
317M
      const struct m68k_opcode *opc = opcodes[major_opcode][i];
1673
317M
      unsigned long opcode = opc->opcode;
1674
317M
      unsigned long match = opc->match;
1675
317M
      const char *args = opc->args;
1676
1677
317M
      if (*args == '.')
1678
3.56M
  args++;
1679
1680
317M
      if (((0xff & buffer[0] & (match >> 24)) == (0xff & (opcode >> 24)))
1681
74.1M
    && ((0xff & buffer[1] & (match >> 16)) == (0xff & (opcode >> 16)))
1682
    /* Only fetch the next two bytes if we need to.  */
1683
19.4M
    && (((0xffff & match) == 0)
1684
18.0M
        ||
1685
18.0M
        (FETCH_DATA (info, buffer + 4)
1686
17.9M
         && ((0xff & buffer[2] & (match >> 8)) == (0xff & (opcode >> 8)))
1687
1.31M
         && ((0xff & buffer[3] & match) == (0xff & opcode)))
1688
19.4M
        )
1689
1.57M
    && (opc->arch & arch_mask) != 0)
1690
1.11M
  {
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.35M
    for (d = args; *d; d += 2)
1695
2.23M
      if (d[1] == 'D')
1696
505
        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.11M
    if (*d == '\0')
1702
3.34M
      for (d = args; *d; d += 2)
1703
2.23M
        if (d[1] == 't')
1704
710
    break;
1705
1706
    /* Don't match fmovel with more than one register;
1707
       wait for fmoveml.  */
1708
1.11M
    if (*d == '\0')
1709
1.11M
      {
1710
3.34M
        for (d = args; *d; d += 2)
1711
2.23M
    {
1712
2.23M
      if (d[0] == 's' && d[1] == '8')
1713
1.62k
        {
1714
1.62k
          val = fetch_arg (buffer, d[1], 3, info);
1715
1.62k
          if (val < 0)
1716
0
      return 0;
1717
1.62k
          if ((val & (val - 1)) != 0)
1718
461
      break;
1719
1.62k
        }
1720
2.23M
    }
1721
1.11M
      }
1722
1723
    /* Don't match FPU insns with non-default coprocessor ID.  */
1724
1.11M
    if (*d == '\0')
1725
1.11M
      {
1726
3.27M
        for (d = args; *d; d += 2)
1727
2.19M
    {
1728
2.19M
      if (d[0] == 'I')
1729
41.4k
        {
1730
41.4k
          val = fetch_arg (buffer, 'd', 3, info);
1731
41.4k
          if (val != 1)
1732
31.7k
      break;
1733
41.4k
        }
1734
2.19M
    }
1735
1.11M
      }
1736
1737
1.11M
    if (*d == '\0')
1738
1.08M
      if ((val = match_insn_m68k (memaddr, info, opc)))
1739
808k
        return val;
1740
1.11M
  }
1741
317M
    }
1742
554k
  return 0;
1743
1.36M
}
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
937k
    {
1770
      /* First try printing an m680x0 instruction.  Try printing a Coldfire
1771
   one if that fails.  */
1772
937k
      val = m68k_scan_mask (memaddr, info, m68k_mask);
1773
937k
      if (val <= 0)
1774
254k
  val = m68k_scan_mask (memaddr, info, mcf_mask);
1775
937k
    }
1776
171k
  else
1777
171k
    {
1778
171k
      val = m68k_scan_mask (memaddr, info, arch_mask);
1779
171k
    }
1780
1781
1.10M
  if (val == 0)
1782
301k
    {
1783
      /* Handle undefined instructions.  */
1784
301k
      info->fprintf_styled_func (info->stream, dis_style_assembler_directive,
1785
301k
         ".short");
1786
301k
      info->fprintf_styled_func (info->stream, dis_style_text, " ");
1787
301k
      info->fprintf_styled_func (info->stream, dis_style_immediate,
1788
301k
         "0x%04x", (buffer[0] << 8) + buffer[1]);
1789
1790
301k
      info->insn_type = dis_noninsn;
1791
301k
    }
1792
1793
1.10M
  return val ? val : 2;
1794
1.10M
}