Coverage Report

Created: 2025-07-08 11:15

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