Coverage Report

Created: 2026-04-04 08:16

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