Coverage Report

Created: 2023-06-29 07:13

/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
461k
  ((addr) <= ((struct private *)(info->private_data))->max_fetched \
49
461k
   ? 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
461k
{
56
461k
  int status;
57
461k
  struct private *priv = (struct private *) info->private_data;
58
461k
  bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
59
60
461k
  status = (*info->read_memory_func) (start,
61
461k
              priv->max_fetched,
62
461k
              addr - priv->max_fetched, info);
63
461k
  if (status != 0)
64
207
    {
65
207
      (*info->memory_error_func) (status, start, info);
66
207
      longjmp (priv->bailout, 1);
67
207
    }
68
461k
  else
69
461k
    priv->max_fetched = addr;
70
461k
  return 1;
71
461k
}
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
105k
{
86
105k
  int opcode = (ins >> 21) & 0x000f;
87
88
105k
  if (ins & CLASS0_UNUSED_MASK)
89
57.8k
    goto illegal_opcode;
90
91
47.4k
  switch (opcode)
92
47.4k
    {
93
40.6k
    case 0:
94
      /* BRR instruction.  */
95
40.6k
      {
96
40.6k
  unsigned cbf = (ins >> 27) & 0x000f;
97
40.6k
  int displacement = ((ins & 0xffff) ^ 0x8000) - 0x8000;
98
99
40.6k
  if (ins == 0)
100
26.5k
    (*info->fprintf_func) (info->stream, "nop");
101
14.0k
  else
102
14.0k
    (*info->fprintf_func) (info->stream, "brr     %s,%+d",
103
14.0k
         cc_names[cbf], displacement);
104
40.6k
      }
105
40.6k
      break;
106
1.16k
    case 1:
107
      /* Illegal opcode.  */
108
1.16k
      goto illegal_opcode;
109
0
      break;
110
730
    case 2:
111
      /* Illegal opcode.  */
112
730
      goto illegal_opcode;
113
0
      break;
114
566
    case 3:
115
      /* Illegal opcode.  */
116
566
      goto illegal_opcode;
117
0
      break;
118
1.00k
    case 4:
119
      /* Illegal opcode.  */
120
1.00k
      goto illegal_opcode;
121
0
      break;
122
374
    case 5:
123
      /* Illegal opcode.  */
124
374
      goto illegal_opcode;
125
0
      break;
126
335
    case 6:
127
      /* Illegal opcode.  */
128
335
      goto illegal_opcode;
129
0
      break;
130
106
    case 7:
131
      /* Illegal opcode.  */
132
106
      goto illegal_opcode;
133
0
      break;
134
2.05k
    case 8:
135
      /* Illegal opcode.  */
136
2.05k
      goto illegal_opcode;
137
0
      break;
138
93
    case 9:
139
      /* Illegal opcode.  */
140
93
      goto illegal_opcode;
141
0
      break;
142
4
    case 10:
143
      /* Illegal opcode.  */
144
4
      goto illegal_opcode;
145
0
      break;
146
35
    case 11:
147
      /* Illegal opcode.  */
148
35
      goto illegal_opcode;
149
0
      break;
150
131
    case 12:
151
      /* Illegal opcode.  */
152
131
      goto illegal_opcode;
153
0
      break;
154
59
    case 13:
155
      /* Illegal opcode.  */
156
59
      goto illegal_opcode;
157
0
      break;
158
119
    case 14:
159
      /* Illegal opcode.  */
160
119
      goto illegal_opcode;
161
0
      break;
162
24
    case 15:
163
      /* Illegal opcode.  */
164
24
      goto illegal_opcode;
165
0
      break;
166
47.4k
    }
167
40.6k
  return 0;
168
169
64.6k
 illegal_opcode:
170
64.6k
  return -1;
171
47.4k
}
172
173
/* Disassemble non-storage register class instructions.   */
174
175
static int
176
disassem_class1 (disassemble_info *info, unsigned int ins)
177
45.6k
{
178
45.6k
  int opcode = (ins >> 21) & 0xf;
179
45.6k
  int source_a = (ins >> 16) & 0x1f;
180
45.6k
  int source_b = (ins >> 4) & 0x1f;
181
45.6k
  int indx = (ins >> 10) & 0x1f;
182
183
45.6k
  int size = ins & 0x7;
184
185
45.6k
  if (ins & CLASS1_UNUSED_MASK)
186
24.9k
    goto illegal_opcode;
187
188
20.7k
  switch (opcode)
189
20.7k
    {
190
3.34k
    case 0:
191
      /* Stop.  */
192
3.34k
      (*info->fprintf_func) (info->stream, "stop    %d,r%d", indx, source_a);
193
3.34k
      break;
194
1.13k
    case 1:
195
      /* BMI - Block Move Indirect.  */
196
1.13k
      if (ins != BMI)
197
1.13k
  goto illegal_opcode;
198
199
0
      (*info->fprintf_func) (info->stream, "bmi     r1,r2,r3");
200
0
      break;
201
593
    case 2:
202
      /* Illegal opcode.  */
203
593
      goto illegal_opcode;
204
0
      break;
205
1.30k
    case 3:
206
      /* BMD - Block Move Direct.  */
207
1.30k
      if (ins != BMD)
208
1.30k
  goto illegal_opcode;
209
210
1
      (*info->fprintf_func) (info->stream, "bmd     r1,r2,r3");
211
1
      break;
212
1.07k
    case 4:
213
      /* DSI - Disable Interrupts.  */
214
1.07k
      if (ins != DSI)
215
1.07k
  goto illegal_opcode;
216
217
0
      (*info->fprintf_func) (info->stream, "dsi");
218
0
      break;
219
220
574
    case 5:
221
      /* ENI - Enable Interrupts.  */
222
574
      if (ins != ENI)
223
568
  goto illegal_opcode;
224
225
6
      (*info->fprintf_func) (info->stream, "eni");
226
6
      break;
227
228
767
    case 6:
229
      /* Illegal opcode (was EUT).  */
230
767
      goto illegal_opcode;
231
0
      break;
232
1.21k
    case 7:
233
      /* RFI - Return from Interrupt.  */
234
1.21k
      if (ins != RFI)
235
1.21k
  goto illegal_opcode;
236
237
0
      (*info->fprintf_func) (info->stream, "rfi");
238
0
      break;
239
2.31k
    case 8:
240
      /* Illegal opcode.  */
241
2.31k
      goto illegal_opcode;
242
0
      break;
243
1.06k
    case 9:
244
      /* Illegal opcode.  */
245
1.06k
      goto illegal_opcode;
246
0
      break;
247
755
    case 10:
248
      /* Illegal opcode.  */
249
755
      goto illegal_opcode;
250
0
      break;
251
1.46k
    case 11:
252
      /* Illegal opcode.  */
253
1.46k
      goto illegal_opcode;
254
0
      break;
255
911
    case 12:
256
      /* Illegal opcode.  */
257
911
      goto illegal_opcode;
258
0
      break;
259
646
    case 13:
260
646
      goto illegal_opcode;
261
0
      break;
262
648
    case 14:
263
648
      goto illegal_opcode;
264
0
      break;
265
2.91k
    case 15:
266
2.91k
      if (ins & EAM_SELECT_MASK)
267
2.24k
  {
268
    /* Extension arithmetic module write */
269
2.24k
    int fp_ins = (ins >> 27) & 0xf;
270
271
2.24k
    if (size != 4)
272
894
      goto illegal_opcode;
273
274
1.35k
    if (ins & FP_SELECT_MASK)
275
705
      {
276
        /* Which floating point instructions don't need a fsrcB
277
           register.  */
278
705
        const int no_fsrcb[16] = { 1, 0, 0, 0, 0, 1, 1, 1,
279
705
    1, 1, 0, 0, 1, 0, 0, 0
280
705
        };
281
705
        if (no_fsrcb[fp_ins] && source_b)
282
56
    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
649
        if (ins & ((1 << 14) | (1 << 8)) || (fp_ins && ins & (1 << 20)))
288
125
    goto illegal_opcode;
289
290
524
        switch (fp_ins)
291
524
    {
292
37
    case 0:
293
37
      (*info->fprintf_func) (info->stream, "fload   f%d,r%d",
294
37
           indx, source_a);
295
37
      break;
296
110
    case 1:
297
110
      (*info->fprintf_func) (info->stream, "fadd    f%d,f%d,f%d",
298
110
           indx, source_a, source_b);
299
110
      break;
300
7
    case 2:
301
7
      (*info->fprintf_func) (info->stream, "fsub    f%d,f%d,f%d",
302
7
           indx, source_a, source_b);
303
7
      break;
304
23
    case 3:
305
23
      (*info->fprintf_func) (info->stream, "fmult   f%d,f%d,f%d",
306
23
           indx, source_a, source_b);
307
23
      break;
308
25
    case 4:
309
25
      (*info->fprintf_func) (info->stream, "fdiv    f%d,f%d,f%d",
310
25
           indx, source_a, source_b);
311
25
      break;
312
12
    case 5:
313
12
      (*info->fprintf_func) (info->stream, "fsqrt   f%d,f%d",
314
12
           indx, source_a);
315
12
      break;
316
8
    case 6:
317
8
      (*info->fprintf_func) (info->stream, "fneg    f%d,f%d",
318
8
           indx, source_a);
319
8
      break;
320
69
    case 7:
321
69
      (*info->fprintf_func) (info->stream, "fabs    f%d,f%d",
322
69
           indx, source_a);
323
69
      break;
324
41
    case 8:
325
41
      (*info->fprintf_func) (info->stream, "ftoi    f%d,f%d",
326
41
           indx, source_a);
327
41
      break;
328
94
    case 9:
329
94
      (*info->fprintf_func) (info->stream, "itof    f%d,f%d",
330
94
           indx, source_a);
331
94
      break;
332
39
    case 12:
333
39
      (*info->fprintf_func) (info->stream, "fmove   f%d,f%d",
334
39
           indx, source_a);
335
39
      break;
336
59
    default:
337
59
      (*info->fprintf_func) (info->stream,
338
59
           "fpinst  %d,f%d,f%d,f%d", fp_ins,
339
59
           indx, source_a, source_b);
340
59
      break;
341
524
    }
342
524
      }
343
645
    else
344
645
      {
345
        /* Which EAM operations do not need a srcB register.  */
346
645
        const int no_srcb[32] =
347
645
        { 0, 0, 1, 1, 0, 1, 1, 1,
348
645
    0, 1, 1, 1, 0, 0, 0, 0,
349
645
    0, 0, 0, 0, 0, 0, 0, 0,
350
645
    0, 0, 0, 0, 0, 0, 0, 0
351
645
        };
352
353
645
        if (no_srcb[indx] && source_b)
354
28
    goto illegal_opcode;
355
356
617
        if (fp_ins)
357
150
    goto illegal_opcode;
358
359
467
        switch (indx)
360
467
    {
361
27
    case 0:
362
27
      (*info->fprintf_func) (info->stream, "mults   r%d,r%d",
363
27
           source_a, source_b);
364
27
      break;
365
21
    case 1:
366
21
      (*info->fprintf_func) (info->stream, "multu   r%d,r%d",
367
21
           source_a, source_b);
368
21
      break;
369
134
    case 2:
370
134
      (*info->fprintf_func) (info->stream, "divs    r%d",
371
134
           source_a);
372
134
      break;
373
15
    case 3:
374
15
      (*info->fprintf_func) (info->stream, "divu    r%d",
375
15
           source_a);
376
15
      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
118
    case 5:
382
118
      (*info->fprintf_func) (info->stream, "writemdc r%d",
383
118
           source_a);
384
118
      break;
385
0
    case 6:
386
0
      (*info->fprintf_func) (info->stream, "divds   r%d",
387
0
           source_a);
388
0
      break;
389
37
    case 7:
390
37
      (*info->fprintf_func) (info->stream, "divdu   r%d",
391
37
           source_a);
392
37
      break;
393
13
    case 9:
394
13
      (*info->fprintf_func) (info->stream, "asrd    r%d",
395
13
           source_a);
396
13
      break;
397
28
    case 10:
398
28
      (*info->fprintf_func) (info->stream, "lsrd    r%d",
399
28
           source_a);
400
28
      break;
401
56
    case 11:
402
56
      (*info->fprintf_func) (info->stream, "asld    r%d",
403
56
           source_a);
404
56
      break;
405
18
    default:
406
18
      (*info->fprintf_func) (info->stream,
407
18
           "eamwrite %d,r%d,r%d", indx,
408
18
           source_a, source_b);
409
18
      break;
410
467
    }
411
467
      }
412
1.35k
  }
413
668
      else
414
668
  {
415
    /* WRITE - write to memory.  */
416
668
    (*info->fprintf_func) (info->stream, "write.%s %d(r%d),r%d",
417
668
         size_names[size], indx, source_a, source_b);
418
668
  }
419
1.65k
      break;
420
20.7k
    }
421
422
5.00k
  return 0;
423
424
40.6k
 illegal_opcode:
425
40.6k
  return -1;
426
20.7k
}
427
428
/* Disassemble storage immediate class instructions.   */
429
430
static int
431
disassem_class2 (disassemble_info *info, unsigned int ins)
432
56.0k
{
433
56.0k
  int opcode = (ins >> 21) & 0xf;
434
56.0k
  int source_a = (ins >> 16) & 0x1f;
435
56.0k
  unsigned immediate = ins & 0x0000ffff;
436
437
56.0k
  if (ins & CC_MASK)
438
48.6k
    goto illegal_opcode;
439
440
7.45k
  switch (opcode)
441
7.45k
    {
442
1.42k
    case 0:
443
      /* ADDI instruction.  */
444
1.42k
      (*info->fprintf_func) (info->stream, "addi    r%d,%d", source_a,
445
1.42k
           immediate);
446
1.42k
      break;
447
624
    case 1:
448
      /* Illegal opcode.  */
449
624
      goto illegal_opcode;
450
0
      break;
451
463
    case 2:
452
      /* SUBI instruction.  */
453
463
      (*info->fprintf_func) (info->stream, "subi    r%d,%d", source_a,
454
463
           immediate);
455
463
      break;
456
248
    case 3:
457
      /* Illegal opcode.  */
458
248
      goto illegal_opcode;
459
0
      break;
460
569
    case 4:
461
      /* MOVIL instruction.  */
462
569
      (*info->fprintf_func) (info->stream, "movil   r%d,0x%04X", source_a,
463
569
           immediate);
464
569
      break;
465
412
    case 5:
466
      /* MOVIU instruction.  */
467
412
      (*info->fprintf_func) (info->stream, "moviu   r%d,0x%04X", source_a,
468
412
           immediate);
469
412
      break;
470
96
    case 6:
471
      /* MOVIQ instruction.  */
472
96
      (*info->fprintf_func) (info->stream, "moviq   r%d,%u", source_a,
473
96
           immediate);
474
96
      break;
475
468
    case 7:
476
      /* Illegal opcode.  */
477
468
      goto illegal_opcode;
478
0
      break;
479
1.55k
    case 8:
480
      /* WRTL instruction.  */
481
1.55k
      if (source_a != 0)
482
1.12k
  goto illegal_opcode;
483
484
437
      (*info->fprintf_func) (info->stream, "wrtl    0x%04X", immediate);
485
437
      break;
486
181
    case 9:
487
      /* WRTU instruction.  */
488
181
      if (source_a != 0)
489
137
  goto illegal_opcode;
490
491
44
      (*info->fprintf_func) (info->stream, "wrtu    0x%04X", immediate);
492
44
      break;
493
163
    case 10:
494
      /* Illegal opcode.  */
495
163
      goto illegal_opcode;
496
0
      break;
497
230
    case 11:
498
      /* Illegal opcode.  */
499
230
      goto illegal_opcode;
500
0
      break;
501
323
    case 12:
502
      /* Illegal opcode.  */
503
323
      goto illegal_opcode;
504
0
      break;
505
210
    case 13:
506
      /* Illegal opcode.  */
507
210
      goto illegal_opcode;
508
0
      break;
509
283
    case 14:
510
      /* Illegal opcode.  */
511
283
      goto illegal_opcode;
512
0
      break;
513
198
    case 15:
514
      /* Illegal opcode.  */
515
198
      goto illegal_opcode;
516
0
      break;
517
7.45k
    }
518
519
3.44k
  return 0;
520
521
52.6k
 illegal_opcode:
522
52.6k
  return -1;
523
7.45k
}
524
525
/* Disassemble storage register class instructions.  */
526
527
static int
528
disassem_class3 (disassemble_info *info, unsigned int ins)
529
78.0k
{
530
78.0k
  int opcode = (ins >> 21) & 0xf;
531
78.0k
  int source_b = (ins >> 4) & 0x1f;
532
78.0k
  int source_a = (ins >> 16) & 0x1f;
533
78.0k
  int size = ins & 0x7;
534
78.0k
  int dest = (ins >> 10) & 0x1f;
535
536
  /* Those instructions that don't have a srcB register.  */
537
78.0k
  const int no_srcb[16] =
538
78.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
78.0k
  const int srcb_immed[16] =
542
78.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
78.0k
  if ((no_srcb[opcode] && source_b)
552
78.0k
      || (!srcb_immed[opcode] && ins & CLASS3_SOURCEB_IMMED)
553
78.0k
      || (opcode != 12 && opcode != 15 && ins & CC_MASK)
554
78.0k
      || (opcode != 15 && ins & (EAM_SELECT_MASK | FP_SELECT_MASK)))
555
48.5k
    goto illegal_opcode;
556
557
558
29.5k
  switch (opcode)
559
29.5k
    {
560
360
    case 0:
561
      /* ADD instruction.  */
562
360
      (*info->fprintf_func) (info->stream, "add.%s   r%d,r%d,r%d",
563
360
           size_names[size], dest, source_a, source_b);
564
360
      break;
565
70
    case 1:
566
      /* ADC instruction.  */
567
70
      (*info->fprintf_func) (info->stream, "adc.%s   r%d,r%d,r%d",
568
70
           size_names[size], dest, source_a, source_b);
569
70
      break;
570
97
    case 2:
571
      /* SUB instruction.  */
572
97
      if (dest == 0)
573
18
  (*info->fprintf_func) (info->stream, "cmp.%s   r%d,r%d",
574
18
             size_names[size], source_a, source_b);
575
79
      else
576
79
  (*info->fprintf_func) (info->stream, "sub.%s   r%d,r%d,r%d",
577
79
             size_names[size], dest, source_a, source_b);
578
97
      break;
579
103
    case 3:
580
      /* SUBC instruction.  */
581
103
      if (dest == 0)
582
30
  (*info->fprintf_func) (info->stream, "cmpc.%s  r%d,r%d",
583
30
             size_names[size], source_a, source_b);
584
73
      else
585
73
  (*info->fprintf_func) (info->stream, "subc.%s  r%d,r%d,r%d",
586
73
             size_names[size], dest, source_a, source_b);
587
103
      break;
588
20
    case 4:
589
      /* EXTW instruction.  */
590
20
      if (size == 1)
591
0
  goto illegal_opcode;
592
593
20
      (*info->fprintf_func) (info->stream, "extw.%s  r%d,r%d",
594
20
           size_names[size], dest, source_a);
595
20
      break;
596
162
    case 5:
597
      /* ASR instruction.  */
598
162
      if (ins & CLASS3_SOURCEB_IMMED)
599
20
  (*info->fprintf_func) (info->stream, "asr.%s   r%d,r%d,%d",
600
20
             size_names[size], dest, source_a, source_b);
601
142
      else
602
142
  (*info->fprintf_func) (info->stream, "asr.%s   r%d,r%d,r%d",
603
142
             size_names[size], dest, source_a, source_b);
604
162
      break;
605
77
    case 6:
606
      /* LSR instruction.  */
607
77
      if (ins & CLASS3_SOURCEB_IMMED)
608
26
  (*info->fprintf_func) (info->stream, "lsr.%s   r%d,r%d,%d",
609
26
             size_names[size], dest, source_a, source_b);
610
51
      else
611
51
  (*info->fprintf_func) (info->stream, "lsr.%s   r%d,r%d,r%d",
612
51
             size_names[size], dest, source_a, source_b);
613
77
      break;
614
114
    case 7:
615
      /* ASL instruction.  */
616
114
      if (ins & CLASS3_SOURCEB_IMMED)
617
34
  (*info->fprintf_func) (info->stream, "asl.%s   r%d,r%d,%d",
618
34
             size_names[size], dest, source_a, source_b);
619
80
      else
620
80
  (*info->fprintf_func) (info->stream, "asl.%s   r%d,r%d,r%d",
621
80
             size_names[size], dest, source_a, source_b);
622
114
      break;
623
223
    case 8:
624
      /* XOR instruction.  */
625
223
      (*info->fprintf_func) (info->stream, "xor.%s   r%d,r%d,r%d",
626
223
           size_names[size], dest, source_a, source_b);
627
223
      break;
628
130
    case 9:
629
      /* OR instruction.  */
630
130
      if (source_b == 0)
631
65
  (*info->fprintf_func) (info->stream, "move.%s  r%d,r%d",
632
65
             size_names[size], dest, source_a);
633
65
      else
634
65
  (*info->fprintf_func) (info->stream, "or.%s    r%d,r%d,r%d",
635
65
             size_names[size], dest, source_a, source_b);
636
130
      break;
637
34
    case 10:
638
      /* AND instruction.  */
639
34
      (*info->fprintf_func) (info->stream, "and.%s   r%d,r%d,r%d",
640
34
           size_names[size], dest, source_a, source_b);
641
34
      break;
642
44
    case 11:
643
      /* NOT instruction.  */
644
44
      (*info->fprintf_func) (info->stream, "not.%s   r%d,r%d",
645
44
           size_names[size], dest, source_a);
646
44
      break;
647
266
    case 12:
648
      /* BRA instruction.  */
649
266
      {
650
266
  unsigned cbf = (ins >> 27) & 0x000f;
651
652
266
  if (size != 4)
653
230
    goto illegal_opcode;
654
655
36
  (*info->fprintf_func) (info->stream, "bra     %s,r%d,r%d",
656
36
             cc_names[cbf], source_a, dest);
657
36
      }
658
0
      break;
659
23
    case 13:
660
      /* RFLAG instruction.  */
661
23
      if (source_a || size != 4)
662
23
  goto illegal_opcode;
663
664
0
      (*info->fprintf_func) (info->stream, "rflag   r%d", dest);
665
0
      break;
666
68
    case 14:
667
      /* EXTB instruction.  */
668
68
      (*info->fprintf_func) (info->stream, "extb.%s  r%d,r%d",
669
68
           size_names[size], dest, source_a);
670
68
      break;
671
27.7k
    case 15:
672
27.7k
      if (!(ins & CLASS3_SOURCEB_IMMED))
673
3.60k
  goto illegal_opcode;
674
675
24.1k
      if (ins & EAM_SELECT_MASK)
676
22.7k
  {
677
    /* Extension arithmetic module read.  */
678
22.7k
    int fp_ins = (ins >> 27) & 0xf;
679
680
22.7k
    if (size != 4)
681
22.1k
      goto illegal_opcode;
682
683
555
    if (ins & FP_SELECT_MASK)
684
120
      {
685
        /* Check fsrcA <= 15 and fsrcB <= 15.  */
686
120
        if (ins & ((1 << 20) | (1 << 8)))
687
104
    goto illegal_opcode;
688
689
16
        switch (fp_ins)
690
16
    {
691
10
    case 0:
692
10
      if (source_b)
693
10
        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
6
    case 10:
699
6
      (*info->fprintf_func) (info->stream, "fcmp    r%d,f%d,f%d",
700
6
           dest, source_a, source_b);
701
6
      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
0
    default:
707
0
      (*info->fprintf_func) (info->stream,
708
0
           "fpuread %d,r%d,f%d,f%d", fp_ins,
709
0
           dest, source_a, source_b);
710
0
      break;
711
16
    }
712
16
      }
713
435
    else
714
435
      {
715
435
        if (fp_ins || source_a)
716
435
    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
555
  }
736
1.37k
      else
737
1.37k
  {
738
1.37k
    if (ins & FP_SELECT_MASK)
739
716
      goto illegal_opcode;
740
741
    /* READ instruction.  */
742
656
    (*info->fprintf_func) (info->stream, "read.%s  r%d,%d(r%d)",
743
656
         size_names[size], dest, source_b, source_a);
744
656
  }
745
662
      break;
746
29.5k
    }
747
748
2.20k
  return 0;
749
750
75.8k
 illegal_opcode:
751
75.8k
  return -1;
752
753
29.5k
}
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
461k
{
761
461k
  unsigned ins;
762
461k
  unsigned p1, p2;
763
461k
  int ans;
764
461k
  int i;
765
766
  /* Stuff copied from m68k-dis.c.  */
767
461k
  struct private priv;
768
461k
  bfd_byte *buffer = priv.the_buffer;
769
461k
  info->private_data = &priv;
770
461k
  priv.max_fetched = priv.the_buffer;
771
461k
  priv.insn_start = addr;
772
461k
  if (setjmp (priv.bailout) != 0)
773
207
    {
774
      /* Error return.  */
775
207
      return -1;
776
207
    }
777
778
  /* We do return this info.  */
779
461k
  info->insn_info_valid = 1;
780
781
  /* Assume non branch insn.  */
782
461k
  info->insn_type = dis_nonbranch;
783
784
  /* Assume no delay.  */
785
461k
  info->branch_delay_insns = 0;
786
787
  /* Assume no target known.  */
788
461k
  info->target = 0;
789
790
  /* Get 32-bit instruction word.  */
791
461k
  FETCH_DATA (info, buffer + 4);
792
461k
  ins = (unsigned) buffer[0] << 24;
793
461k
  ins |= buffer[1] << 16;
794
461k
  ins |= buffer[2] << 8;
795
461k
  ins |= buffer[3];
796
797
461k
  ans = 0;
798
799
461k
  p1 = buffer[0] ^ buffer[1] ^ buffer[2] ^ buffer[3];
800
461k
  p2 = 0;
801
4.15M
  for (i = 0; i < 8; i++)
802
3.68M
    {
803
3.68M
      p2 += p1 & 1;
804
3.68M
      p1 >>= 1;
805
3.68M
    }
806
807
  /* Decode the instruction.  */
808
461k
  if (p2 & 1)
809
176k
    ans = -1;
810
285k
  else
811
285k
    {
812
285k
      switch ((ins >> 25) & 0x3)
813
285k
  {
814
105k
  case 0:
815
105k
    ans = disassem_class0 (info, ins);
816
105k
    break;
817
45.6k
  case 1:
818
45.6k
    ans = disassem_class1 (info, ins);
819
45.6k
    break;
820
56.0k
  case 2:
821
56.0k
    ans = disassem_class2 (info, ins);
822
56.0k
    break;
823
78.0k
  case 3:
824
78.0k
    ans = disassem_class3 (info, ins);
825
78.0k
    break;
826
285k
  }
827
285k
    }
828
829
461k
  if (ans != 0)
830
409k
    (*info->fprintf_func) (info->stream, "err");
831
832
  /* Return number of bytes consumed (always 4 for the Visium).  */
833
461k
  return 4;
834
461k
}