Coverage Report

Created: 2023-08-28 06:31

/src/binutils-gdb/opcodes/visium-dis.c
Line
Count
Source (jump to first uncovered line)
1
/* Single instruction disassembler for the Visium.
2
3
   Copyright (C) 2002-2023 Free Software Foundation, Inc.
4
5
   This file is part of the GNU opcodes library.
6
7
   This library is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3, or (at your option)
10
   any later version.
11
12
   It is distributed in the hope that it will be useful, but WITHOUT
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15
   License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
#include "sysdep.h"
23
#include "disassemble.h"
24
#include "opcode/visium.h"
25
26
#include <string.h>
27
#include <stdlib.h>
28
#include <stdio.h>
29
#include <ctype.h>
30
#include <setjmp.h>
31
32
/* Maximum length of an instruction.  */
33
#define MAXLEN 4
34
35
struct private
36
{
37
  /* Points to first byte not fetched.  */
38
  bfd_byte *max_fetched;
39
  bfd_byte the_buffer[MAXLEN];
40
  bfd_vma insn_start;
41
  jmp_buf bailout;
42
};
43
44
/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
45
   to ADDR (exclusive) are valid.  Returns 1 for success, longjmps
46
   on error.  */
47
#define FETCH_DATA(info, addr) \
48
313k
  ((addr) <= ((struct private *)(info->private_data))->max_fetched \
49
313k
   ? 1 : fetch_data ((info), (addr)))
50
51
static int fetch_data (struct disassemble_info *info, bfd_byte * addr);
52
53
static int
54
fetch_data (struct disassemble_info *info, bfd_byte *addr)
55
313k
{
56
313k
  int status;
57
313k
  struct private *priv = (struct private *) info->private_data;
58
313k
  bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
59
60
313k
  status = (*info->read_memory_func) (start,
61
313k
              priv->max_fetched,
62
313k
              addr - priv->max_fetched, info);
63
313k
  if (status != 0)
64
140
    {
65
140
      (*info->memory_error_func) (status, start, info);
66
140
      longjmp (priv->bailout, 1);
67
140
    }
68
313k
  else
69
313k
    priv->max_fetched = addr;
70
313k
  return 1;
71
313k
}
72
73
static char *size_names[] = { "?", "b", "w", "?", "l", "?", "?", "?" };
74
75
static char *cc_names[] =
76
{
77
  "fa", "eq", "cs", "os", "ns", "ne", "cc", "oc",
78
  "nc", "ge", "gt", "hi", "le", "ls", "lt", "tr"
79
};
80
81
/* Disassemble non-storage relative instructions.  */
82
83
static int
84
disassem_class0 (disassemble_info *info, unsigned int ins)
85
76.5k
{
86
76.5k
  int opcode = (ins >> 21) & 0x000f;
87
88
76.5k
  if (ins & CLASS0_UNUSED_MASK)
89
41.4k
    goto illegal_opcode;
90
91
35.0k
  switch (opcode)
92
35.0k
    {
93
29.6k
    case 0:
94
      /* BRR instruction.  */
95
29.6k
      {
96
29.6k
  unsigned cbf = (ins >> 27) & 0x000f;
97
29.6k
  int displacement = ((ins & 0xffff) ^ 0x8000) - 0x8000;
98
99
29.6k
  if (ins == 0)
100
16.5k
    (*info->fprintf_func) (info->stream, "nop");
101
13.0k
  else
102
13.0k
    (*info->fprintf_func) (info->stream, "brr     %s,%+d",
103
13.0k
         cc_names[cbf], displacement);
104
29.6k
      }
105
29.6k
      break;
106
255
    case 1:
107
      /* Illegal opcode.  */
108
255
      goto illegal_opcode;
109
0
      break;
110
547
    case 2:
111
      /* Illegal opcode.  */
112
547
      goto illegal_opcode;
113
0
      break;
114
291
    case 3:
115
      /* Illegal opcode.  */
116
291
      goto illegal_opcode;
117
0
      break;
118
685
    case 4:
119
      /* Illegal opcode.  */
120
685
      goto illegal_opcode;
121
0
      break;
122
727
    case 5:
123
      /* Illegal opcode.  */
124
727
      goto illegal_opcode;
125
0
      break;
126
227
    case 6:
127
      /* Illegal opcode.  */
128
227
      goto illegal_opcode;
129
0
      break;
130
294
    case 7:
131
      /* Illegal opcode.  */
132
294
      goto illegal_opcode;
133
0
      break;
134
1.91k
    case 8:
135
      /* Illegal opcode.  */
136
1.91k
      goto illegal_opcode;
137
0
      break;
138
130
    case 9:
139
      /* Illegal opcode.  */
140
130
      goto illegal_opcode;
141
0
      break;
142
32
    case 10:
143
      /* Illegal opcode.  */
144
32
      goto illegal_opcode;
145
0
      break;
146
6
    case 11:
147
      /* Illegal opcode.  */
148
6
      goto illegal_opcode;
149
0
      break;
150
186
    case 12:
151
      /* Illegal opcode.  */
152
186
      goto illegal_opcode;
153
0
      break;
154
18
    case 13:
155
      /* Illegal opcode.  */
156
18
      goto illegal_opcode;
157
0
      break;
158
31
    case 14:
159
      /* Illegal opcode.  */
160
31
      goto illegal_opcode;
161
0
      break;
162
40
    case 15:
163
      /* Illegal opcode.  */
164
40
      goto illegal_opcode;
165
0
      break;
166
35.0k
    }
167
29.6k
  return 0;
168
169
46.8k
 illegal_opcode:
170
46.8k
  return -1;
171
35.0k
}
172
173
/* Disassemble non-storage register class instructions.   */
174
175
static int
176
disassem_class1 (disassemble_info *info, unsigned int ins)
177
28.6k
{
178
28.6k
  int opcode = (ins >> 21) & 0xf;
179
28.6k
  int source_a = (ins >> 16) & 0x1f;
180
28.6k
  int source_b = (ins >> 4) & 0x1f;
181
28.6k
  int indx = (ins >> 10) & 0x1f;
182
183
28.6k
  int size = ins & 0x7;
184
185
28.6k
  if (ins & CLASS1_UNUSED_MASK)
186
15.9k
    goto illegal_opcode;
187
188
12.7k
  switch (opcode)
189
12.7k
    {
190
2.46k
    case 0:
191
      /* Stop.  */
192
2.46k
      (*info->fprintf_func) (info->stream, "stop    %d,r%d", indx, source_a);
193
2.46k
      break;
194
860
    case 1:
195
      /* BMI - Block Move Indirect.  */
196
860
      if (ins != BMI)
197
860
  goto illegal_opcode;
198
199
0
      (*info->fprintf_func) (info->stream, "bmi     r1,r2,r3");
200
0
      break;
201
501
    case 2:
202
      /* Illegal opcode.  */
203
501
      goto illegal_opcode;
204
0
      break;
205
797
    case 3:
206
      /* BMD - Block Move Direct.  */
207
797
      if (ins != BMD)
208
797
  goto illegal_opcode;
209
210
0
      (*info->fprintf_func) (info->stream, "bmd     r1,r2,r3");
211
0
      break;
212
545
    case 4:
213
      /* DSI - Disable Interrupts.  */
214
545
      if (ins != DSI)
215
545
  goto illegal_opcode;
216
217
0
      (*info->fprintf_func) (info->stream, "dsi");
218
0
      break;
219
220
415
    case 5:
221
      /* ENI - Enable Interrupts.  */
222
415
      if (ins != ENI)
223
415
  goto illegal_opcode;
224
225
0
      (*info->fprintf_func) (info->stream, "eni");
226
0
      break;
227
228
311
    case 6:
229
      /* Illegal opcode (was EUT).  */
230
311
      goto illegal_opcode;
231
0
      break;
232
395
    case 7:
233
      /* RFI - Return from Interrupt.  */
234
395
      if (ins != RFI)
235
395
  goto illegal_opcode;
236
237
0
      (*info->fprintf_func) (info->stream, "rfi");
238
0
      break;
239
1.34k
    case 8:
240
      /* Illegal opcode.  */
241
1.34k
      goto illegal_opcode;
242
0
      break;
243
619
    case 9:
244
      /* Illegal opcode.  */
245
619
      goto illegal_opcode;
246
0
      break;
247
632
    case 10:
248
      /* Illegal opcode.  */
249
632
      goto illegal_opcode;
250
0
      break;
251
1.01k
    case 11:
252
      /* Illegal opcode.  */
253
1.01k
      goto illegal_opcode;
254
0
      break;
255
767
    case 12:
256
      /* Illegal opcode.  */
257
767
      goto illegal_opcode;
258
0
      break;
259
335
    case 13:
260
335
      goto illegal_opcode;
261
0
      break;
262
635
    case 14:
263
635
      goto illegal_opcode;
264
0
      break;
265
1.06k
    case 15:
266
1.06k
      if (ins & EAM_SELECT_MASK)
267
634
  {
268
    /* Extension arithmetic module write */
269
634
    int fp_ins = (ins >> 27) & 0xf;
270
271
634
    if (size != 4)
272
332
      goto illegal_opcode;
273
274
302
    if (ins & FP_SELECT_MASK)
275
75
      {
276
        /* Which floating point instructions don't need a fsrcB
277
           register.  */
278
75
        const int no_fsrcb[16] = { 1, 0, 0, 0, 0, 1, 1, 1,
279
75
    1, 1, 0, 0, 1, 0, 0, 0
280
75
        };
281
75
        if (no_fsrcb[fp_ins] && source_b)
282
61
    goto illegal_opcode;
283
284
        /* Check that none of the floating register register numbers
285
           is higher than 15. (If this is fload, then srcA is a
286
           general register.  */
287
14
        if (ins & ((1 << 14) | (1 << 8)) || (fp_ins && ins & (1 << 20)))
288
4
    goto illegal_opcode;
289
290
10
        switch (fp_ins)
291
10
    {
292
0
    case 0:
293
0
      (*info->fprintf_func) (info->stream, "fload   f%d,r%d",
294
0
           indx, source_a);
295
0
      break;
296
5
    case 1:
297
5
      (*info->fprintf_func) (info->stream, "fadd    f%d,f%d,f%d",
298
5
           indx, source_a, source_b);
299
5
      break;
300
0
    case 2:
301
0
      (*info->fprintf_func) (info->stream, "fsub    f%d,f%d,f%d",
302
0
           indx, source_a, source_b);
303
0
      break;
304
0
    case 3:
305
0
      (*info->fprintf_func) (info->stream, "fmult   f%d,f%d,f%d",
306
0
           indx, source_a, source_b);
307
0
      break;
308
0
    case 4:
309
0
      (*info->fprintf_func) (info->stream, "fdiv    f%d,f%d,f%d",
310
0
           indx, source_a, source_b);
311
0
      break;
312
0
    case 5:
313
0
      (*info->fprintf_func) (info->stream, "fsqrt   f%d,f%d",
314
0
           indx, source_a);
315
0
      break;
316
0
    case 6:
317
0
      (*info->fprintf_func) (info->stream, "fneg    f%d,f%d",
318
0
           indx, source_a);
319
0
      break;
320
0
    case 7:
321
0
      (*info->fprintf_func) (info->stream, "fabs    f%d,f%d",
322
0
           indx, source_a);
323
0
      break;
324
0
    case 8:
325
0
      (*info->fprintf_func) (info->stream, "ftoi    f%d,f%d",
326
0
           indx, source_a);
327
0
      break;
328
0
    case 9:
329
0
      (*info->fprintf_func) (info->stream, "itof    f%d,f%d",
330
0
           indx, source_a);
331
0
      break;
332
0
    case 12:
333
0
      (*info->fprintf_func) (info->stream, "fmove   f%d,f%d",
334
0
           indx, source_a);
335
0
      break;
336
5
    default:
337
5
      (*info->fprintf_func) (info->stream,
338
5
           "fpinst  %d,f%d,f%d,f%d", fp_ins,
339
5
           indx, source_a, source_b);
340
5
      break;
341
10
    }
342
10
      }
343
227
    else
344
227
      {
345
        /* Which EAM operations do not need a srcB register.  */
346
227
        const int no_srcb[32] =
347
227
        { 0, 0, 1, 1, 0, 1, 1, 1,
348
227
    0, 1, 1, 1, 0, 0, 0, 0,
349
227
    0, 0, 0, 0, 0, 0, 0, 0,
350
227
    0, 0, 0, 0, 0, 0, 0, 0
351
227
        };
352
353
227
        if (no_srcb[indx] && source_b)
354
5
    goto illegal_opcode;
355
356
222
        if (fp_ins)
357
35
    goto illegal_opcode;
358
359
187
        switch (indx)
360
187
    {
361
0
    case 0:
362
0
      (*info->fprintf_func) (info->stream, "mults   r%d,r%d",
363
0
           source_a, source_b);
364
0
      break;
365
0
    case 1:
366
0
      (*info->fprintf_func) (info->stream, "multu   r%d,r%d",
367
0
           source_a, source_b);
368
0
      break;
369
0
    case 2:
370
0
      (*info->fprintf_func) (info->stream, "divs    r%d",
371
0
           source_a);
372
0
      break;
373
1
    case 3:
374
1
      (*info->fprintf_func) (info->stream, "divu    r%d",
375
1
           source_a);
376
1
      break;
377
0
    case 4:
378
0
      (*info->fprintf_func) (info->stream, "writemd r%d,r%d",
379
0
           source_a, source_b);
380
0
      break;
381
116
    case 5:
382
116
      (*info->fprintf_func) (info->stream, "writemdc r%d",
383
116
           source_a);
384
116
      break;
385
0
    case 6:
386
0
      (*info->fprintf_func) (info->stream, "divds   r%d",
387
0
           source_a);
388
0
      break;
389
69
    case 7:
390
69
      (*info->fprintf_func) (info->stream, "divdu   r%d",
391
69
           source_a);
392
69
      break;
393
0
    case 9:
394
0
      (*info->fprintf_func) (info->stream, "asrd    r%d",
395
0
           source_a);
396
0
      break;
397
0
    case 10:
398
0
      (*info->fprintf_func) (info->stream, "lsrd    r%d",
399
0
           source_a);
400
0
      break;
401
0
    case 11:
402
0
      (*info->fprintf_func) (info->stream, "asld    r%d",
403
0
           source_a);
404
0
      break;
405
1
    default:
406
1
      (*info->fprintf_func) (info->stream,
407
1
           "eamwrite %d,r%d,r%d", indx,
408
1
           source_a, source_b);
409
1
      break;
410
187
    }
411
187
      }
412
302
  }
413
430
      else
414
430
  {
415
    /* WRITE - write to memory.  */
416
430
    (*info->fprintf_func) (info->stream, "write.%s %d(r%d),r%d",
417
430
         size_names[size], indx, source_a, source_b);
418
430
  }
419
627
      break;
420
12.7k
    }
421
422
3.08k
  return 0;
423
424
25.6k
 illegal_opcode:
425
25.6k
  return -1;
426
12.7k
}
427
428
/* Disassemble storage immediate class instructions.   */
429
430
static int
431
disassem_class2 (disassemble_info *info, unsigned int ins)
432
31.3k
{
433
31.3k
  int opcode = (ins >> 21) & 0xf;
434
31.3k
  int source_a = (ins >> 16) & 0x1f;
435
31.3k
  unsigned immediate = ins & 0x0000ffff;
436
437
31.3k
  if (ins & CC_MASK)
438
27.5k
    goto illegal_opcode;
439
440
3.79k
  switch (opcode)
441
3.79k
    {
442
1.17k
    case 0:
443
      /* ADDI instruction.  */
444
1.17k
      (*info->fprintf_func) (info->stream, "addi    r%d,%d", source_a,
445
1.17k
           immediate);
446
1.17k
      break;
447
104
    case 1:
448
      /* Illegal opcode.  */
449
104
      goto illegal_opcode;
450
0
      break;
451
129
    case 2:
452
      /* SUBI instruction.  */
453
129
      (*info->fprintf_func) (info->stream, "subi    r%d,%d", source_a,
454
129
           immediate);
455
129
      break;
456
67
    case 3:
457
      /* Illegal opcode.  */
458
67
      goto illegal_opcode;
459
0
      break;
460
213
    case 4:
461
      /* MOVIL instruction.  */
462
213
      (*info->fprintf_func) (info->stream, "movil   r%d,0x%04X", source_a,
463
213
           immediate);
464
213
      break;
465
77
    case 5:
466
      /* MOVIU instruction.  */
467
77
      (*info->fprintf_func) (info->stream, "moviu   r%d,0x%04X", source_a,
468
77
           immediate);
469
77
      break;
470
77
    case 6:
471
      /* MOVIQ instruction.  */
472
77
      (*info->fprintf_func) (info->stream, "moviq   r%d,%u", source_a,
473
77
           immediate);
474
77
      break;
475
290
    case 7:
476
      /* Illegal opcode.  */
477
290
      goto illegal_opcode;
478
0
      break;
479
723
    case 8:
480
      /* WRTL instruction.  */
481
723
      if (source_a != 0)
482
220
  goto illegal_opcode;
483
484
503
      (*info->fprintf_func) (info->stream, "wrtl    0x%04X", immediate);
485
503
      break;
486
122
    case 9:
487
      /* WRTU instruction.  */
488
122
      if (source_a != 0)
489
120
  goto illegal_opcode;
490
491
2
      (*info->fprintf_func) (info->stream, "wrtu    0x%04X", immediate);
492
2
      break;
493
126
    case 10:
494
      /* Illegal opcode.  */
495
126
      goto illegal_opcode;
496
0
      break;
497
48
    case 11:
498
      /* Illegal opcode.  */
499
48
      goto illegal_opcode;
500
0
      break;
501
116
    case 12:
502
      /* Illegal opcode.  */
503
116
      goto illegal_opcode;
504
0
      break;
505
43
    case 13:
506
      /* Illegal opcode.  */
507
43
      goto illegal_opcode;
508
0
      break;
509
253
    case 14:
510
      /* Illegal opcode.  */
511
253
      goto illegal_opcode;
512
0
      break;
513
228
    case 15:
514
      /* Illegal opcode.  */
515
228
      goto illegal_opcode;
516
0
      break;
517
3.79k
    }
518
519
2.17k
  return 0;
520
521
29.1k
 illegal_opcode:
522
29.1k
  return -1;
523
3.79k
}
524
525
/* Disassemble storage register class instructions.  */
526
527
static int
528
disassem_class3 (disassemble_info *info, unsigned int ins)
529
51.0k
{
530
51.0k
  int opcode = (ins >> 21) & 0xf;
531
51.0k
  int source_b = (ins >> 4) & 0x1f;
532
51.0k
  int source_a = (ins >> 16) & 0x1f;
533
51.0k
  int size = ins & 0x7;
534
51.0k
  int dest = (ins >> 10) & 0x1f;
535
536
  /* Those instructions that don't have a srcB register.  */
537
51.0k
  const int no_srcb[16] =
538
51.0k
  { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 };
539
540
  /* These are instructions which can take an immediate srcB value.  */
541
51.0k
  const int srcb_immed[16] =
542
51.0k
  { 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1 };
543
544
  /* User opcodes should not provide a non-zero srcB register
545
     when none is required. Only a BRA or floating point
546
     instruction should have a non-zero condition code field.
547
     Only a WRITE or EAMWRITE (opcode 15) should select an EAM
548
     or floating point operation.  Note that FP_SELECT_MASK is
549
     the same bit (bit 3) as the interrupt bit which
550
     distinguishes SYS1 from BRA and SYS2 from RFLAG.  */
551
51.0k
  if ((no_srcb[opcode] && source_b)
552
51.0k
      || (!srcb_immed[opcode] && ins & CLASS3_SOURCEB_IMMED)
553
51.0k
      || (opcode != 12 && opcode != 15 && ins & CC_MASK)
554
51.0k
      || (opcode != 15 && ins & (EAM_SELECT_MASK | FP_SELECT_MASK)))
555
35.0k
    goto illegal_opcode;
556
557
558
16.0k
  switch (opcode)
559
16.0k
    {
560
132
    case 0:
561
      /* ADD instruction.  */
562
132
      (*info->fprintf_func) (info->stream, "add.%s   r%d,r%d,r%d",
563
132
           size_names[size], dest, source_a, source_b);
564
132
      break;
565
14
    case 1:
566
      /* ADC instruction.  */
567
14
      (*info->fprintf_func) (info->stream, "adc.%s   r%d,r%d,r%d",
568
14
           size_names[size], dest, source_a, source_b);
569
14
      break;
570
68
    case 2:
571
      /* SUB instruction.  */
572
68
      if (dest == 0)
573
65
  (*info->fprintf_func) (info->stream, "cmp.%s   r%d,r%d",
574
65
             size_names[size], source_a, source_b);
575
3
      else
576
3
  (*info->fprintf_func) (info->stream, "sub.%s   r%d,r%d,r%d",
577
3
             size_names[size], dest, source_a, source_b);
578
68
      break;
579
8
    case 3:
580
      /* SUBC instruction.  */
581
8
      if (dest == 0)
582
1
  (*info->fprintf_func) (info->stream, "cmpc.%s  r%d,r%d",
583
1
             size_names[size], source_a, source_b);
584
7
      else
585
7
  (*info->fprintf_func) (info->stream, "subc.%s  r%d,r%d,r%d",
586
7
             size_names[size], dest, source_a, source_b);
587
8
      break;
588
6
    case 4:
589
      /* EXTW instruction.  */
590
6
      if (size == 1)
591
0
  goto illegal_opcode;
592
593
6
      (*info->fprintf_func) (info->stream, "extw.%s  r%d,r%d",
594
6
           size_names[size], dest, source_a);
595
6
      break;
596
12
    case 5:
597
      /* ASR instruction.  */
598
12
      if (ins & CLASS3_SOURCEB_IMMED)
599
7
  (*info->fprintf_func) (info->stream, "asr.%s   r%d,r%d,%d",
600
7
             size_names[size], dest, source_a, source_b);
601
5
      else
602
5
  (*info->fprintf_func) (info->stream, "asr.%s   r%d,r%d,r%d",
603
5
             size_names[size], dest, source_a, source_b);
604
12
      break;
605
36
    case 6:
606
      /* LSR instruction.  */
607
36
      if (ins & CLASS3_SOURCEB_IMMED)
608
21
  (*info->fprintf_func) (info->stream, "lsr.%s   r%d,r%d,%d",
609
21
             size_names[size], dest, source_a, source_b);
610
15
      else
611
15
  (*info->fprintf_func) (info->stream, "lsr.%s   r%d,r%d,r%d",
612
15
             size_names[size], dest, source_a, source_b);
613
36
      break;
614
45
    case 7:
615
      /* ASL instruction.  */
616
45
      if (ins & CLASS3_SOURCEB_IMMED)
617
6
  (*info->fprintf_func) (info->stream, "asl.%s   r%d,r%d,%d",
618
6
             size_names[size], dest, source_a, source_b);
619
39
      else
620
39
  (*info->fprintf_func) (info->stream, "asl.%s   r%d,r%d,r%d",
621
39
             size_names[size], dest, source_a, source_b);
622
45
      break;
623
121
    case 8:
624
      /* XOR instruction.  */
625
121
      (*info->fprintf_func) (info->stream, "xor.%s   r%d,r%d,r%d",
626
121
           size_names[size], dest, source_a, source_b);
627
121
      break;
628
38
    case 9:
629
      /* OR instruction.  */
630
38
      if (source_b == 0)
631
24
  (*info->fprintf_func) (info->stream, "move.%s  r%d,r%d",
632
24
             size_names[size], dest, source_a);
633
14
      else
634
14
  (*info->fprintf_func) (info->stream, "or.%s    r%d,r%d,r%d",
635
14
             size_names[size], dest, source_a, source_b);
636
38
      break;
637
21
    case 10:
638
      /* AND instruction.  */
639
21
      (*info->fprintf_func) (info->stream, "and.%s   r%d,r%d,r%d",
640
21
           size_names[size], dest, source_a, source_b);
641
21
      break;
642
23
    case 11:
643
      /* NOT instruction.  */
644
23
      (*info->fprintf_func) (info->stream, "not.%s   r%d,r%d",
645
23
           size_names[size], dest, source_a);
646
23
      break;
647
150
    case 12:
648
      /* BRA instruction.  */
649
150
      {
650
150
  unsigned cbf = (ins >> 27) & 0x000f;
651
652
150
  if (size != 4)
653
149
    goto illegal_opcode;
654
655
1
  (*info->fprintf_func) (info->stream, "bra     %s,r%d,r%d",
656
1
             cc_names[cbf], source_a, dest);
657
1
      }
658
0
      break;
659
4
    case 13:
660
      /* RFLAG instruction.  */
661
4
      if (source_a || size != 4)
662
4
  goto illegal_opcode;
663
664
0
      (*info->fprintf_func) (info->stream, "rflag   r%d", dest);
665
0
      break;
666
4
    case 14:
667
      /* EXTB instruction.  */
668
4
      (*info->fprintf_func) (info->stream, "extb.%s  r%d,r%d",
669
4
           size_names[size], dest, source_a);
670
4
      break;
671
15.3k
    case 15:
672
15.3k
      if (!(ins & CLASS3_SOURCEB_IMMED))
673
1.85k
  goto illegal_opcode;
674
675
13.4k
      if (ins & EAM_SELECT_MASK)
676
12.9k
  {
677
    /* Extension arithmetic module read.  */
678
12.9k
    int fp_ins = (ins >> 27) & 0xf;
679
680
12.9k
    if (size != 4)
681
12.7k
      goto illegal_opcode;
682
683
129
    if (ins & FP_SELECT_MASK)
684
53
      {
685
        /* Check fsrcA <= 15 and fsrcB <= 15.  */
686
53
        if (ins & ((1 << 20) | (1 << 8)))
687
47
    goto illegal_opcode;
688
689
6
        switch (fp_ins)
690
6
    {
691
0
    case 0:
692
0
      if (source_b)
693
0
        goto illegal_opcode;
694
695
0
      (*info->fprintf_func) (info->stream, "fstore  r%d,f%d",
696
0
           dest, source_a);
697
0
      break;
698
0
    case 10:
699
0
      (*info->fprintf_func) (info->stream, "fcmp    r%d,f%d,f%d",
700
0
           dest, source_a, source_b);
701
0
      break;
702
0
    case 11:
703
0
      (*info->fprintf_func) (info->stream, "fcmpe   r%d,f%d,f%d",
704
0
           dest, source_a, source_b);
705
0
      break;
706
6
    default:
707
6
      (*info->fprintf_func) (info->stream,
708
6
           "fpuread %d,r%d,f%d,f%d", fp_ins,
709
6
           dest, source_a, source_b);
710
6
      break;
711
6
    }
712
6
      }
713
76
    else
714
76
      {
715
76
        if (fp_ins || source_a)
716
76
    goto illegal_opcode;
717
718
0
        switch (source_b)
719
0
    {
720
0
    case 0:
721
0
      (*info->fprintf_func) (info->stream, "readmda r%d", dest);
722
0
      break;
723
0
    case 1:
724
0
      (*info->fprintf_func) (info->stream, "readmdb r%d", dest);
725
0
      break;
726
0
    case 2:
727
0
      (*info->fprintf_func) (info->stream, "readmdc r%d", dest);
728
0
      break;
729
0
    default:
730
0
      (*info->fprintf_func) (info->stream, "eamread r%d,%d",
731
0
           dest, source_b);
732
0
      break;
733
0
    }
734
0
      }
735
129
  }
736
562
      else
737
562
  {
738
562
    if (ins & FP_SELECT_MASK)
739
211
      goto illegal_opcode;
740
741
    /* READ instruction.  */
742
351
    (*info->fprintf_func) (info->stream, "read.%s  r%d,%d(r%d)",
743
351
         size_names[size], dest, source_b, source_a);
744
351
  }
745
357
      break;
746
16.0k
    }
747
748
886
  return 0;
749
750
50.1k
 illegal_opcode:
751
50.1k
  return -1;
752
753
16.0k
}
754
755
/* Print the visium instruction at address addr in debugged memory,
756
   on info->stream. Return length of the instruction, in bytes.  */
757
758
int
759
print_insn_visium (bfd_vma addr, disassemble_info *info)
760
313k
{
761
313k
  unsigned ins;
762
313k
  unsigned p1, p2;
763
313k
  int ans;
764
313k
  int i;
765
766
  /* Stuff copied from m68k-dis.c.  */
767
313k
  struct private priv;
768
313k
  bfd_byte *buffer = priv.the_buffer;
769
313k
  info->private_data = &priv;
770
313k
  priv.max_fetched = priv.the_buffer;
771
313k
  priv.insn_start = addr;
772
313k
  if (setjmp (priv.bailout) != 0)
773
140
    {
774
      /* Error return.  */
775
140
      return -1;
776
140
    }
777
778
  /* We do return this info.  */
779
313k
  info->insn_info_valid = 1;
780
781
  /* Assume non branch insn.  */
782
313k
  info->insn_type = dis_nonbranch;
783
784
  /* Assume no delay.  */
785
313k
  info->branch_delay_insns = 0;
786
787
  /* Assume no target known.  */
788
313k
  info->target = 0;
789
790
  /* Get 32-bit instruction word.  */
791
313k
  FETCH_DATA (info, buffer + 4);
792
313k
  ins = (unsigned) buffer[0] << 24;
793
313k
  ins |= buffer[1] << 16;
794
313k
  ins |= buffer[2] << 8;
795
313k
  ins |= buffer[3];
796
797
313k
  ans = 0;
798
799
313k
  p1 = buffer[0] ^ buffer[1] ^ buffer[2] ^ buffer[3];
800
313k
  p2 = 0;
801
2.82M
  for (i = 0; i < 8; i++)
802
2.50M
    {
803
2.50M
      p2 += p1 & 1;
804
2.50M
      p1 >>= 1;
805
2.50M
    }
806
807
  /* Decode the instruction.  */
808
313k
  if (p2 & 1)
809
125k
    ans = -1;
810
187k
  else
811
187k
    {
812
187k
      switch ((ins >> 25) & 0x3)
813
187k
  {
814
76.5k
  case 0:
815
76.5k
    ans = disassem_class0 (info, ins);
816
76.5k
    break;
817
28.6k
  case 1:
818
28.6k
    ans = disassem_class1 (info, ins);
819
28.6k
    break;
820
31.3k
  case 2:
821
31.3k
    ans = disassem_class2 (info, ins);
822
31.3k
    break;
823
51.0k
  case 3:
824
51.0k
    ans = disassem_class3 (info, ins);
825
51.0k
    break;
826
187k
  }
827
187k
    }
828
829
313k
  if (ans != 0)
830
277k
    (*info->fprintf_func) (info->stream, "err");
831
832
  /* Return number of bytes consumed (always 4 for the Visium).  */
833
313k
  return 4;
834
313k
}