Coverage Report

Created: 2023-08-28 06:30

/src/binutils-gdb/opcodes/sh-dis.c
Line
Count
Source (jump to first uncovered line)
1
/* Disassemble SH instructions.
2
   Copyright (C) 1993-2023 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 file; see the file COPYING.  If not, write to the
18
   Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
19
   MA 02110-1301, USA.  */
20
21
#include "sysdep.h"
22
#include <stdio.h>
23
24
#define STATIC_TABLE
25
#define DEFINE_TABLE
26
27
#include "sh-opc.h"
28
#include "disassemble.h"
29
30
static void
31
print_movxy (const sh_opcode_info *op,
32
       int rn,
33
       int rm,
34
       fprintf_ftype fprintf_fn,
35
       void *stream)
36
21.3k
{
37
21.3k
  int n;
38
39
21.3k
  fprintf_fn (stream, "%s\t", op->name);
40
64.1k
  for (n = 0; n < 2; n++)
41
42.7k
    {
42
42.7k
      switch (op->arg[n])
43
42.7k
  {
44
0
  case A_IND_N:
45
2.11k
  case AX_IND_N:
46
2.54k
  case AXY_IND_N:
47
4.66k
  case AY_IND_N:
48
5.14k
  case AYX_IND_N:
49
5.14k
    fprintf_fn (stream, "@r%d", rn);
50
5.14k
    break;
51
0
  case A_INC_N:
52
2.63k
  case AX_INC_N:
53
3.18k
  case AXY_INC_N:
54
5.87k
  case AY_INC_N:
55
6.14k
  case AYX_INC_N:
56
6.14k
    fprintf_fn (stream, "@r%d+", rn);
57
6.14k
    break;
58
2.71k
  case AX_PMOD_N:
59
3.00k
  case AXY_PMOD_N:
60
3.00k
    fprintf_fn (stream, "@r%d+r8", rn);
61
3.00k
    break;
62
2.68k
  case AY_PMOD_N:
63
3.21k
  case AYX_PMOD_N:
64
3.21k
    fprintf_fn (stream, "@r%d+r9", rn);
65
3.21k
    break;
66
8.09k
  case DSP_REG_A_M:
67
8.09k
    fprintf_fn (stream, "a%c", '0' + rm);
68
8.09k
    break;
69
7.22k
  case DSP_REG_X:
70
7.22k
    fprintf_fn (stream, "x%c", '0' + rm);
71
7.22k
    break;
72
7.40k
  case DSP_REG_Y:
73
7.40k
    fprintf_fn (stream, "y%c", '0' + rm);
74
7.40k
    break;
75
588
  case DSP_REG_AX:
76
588
    fprintf_fn (stream, "%c%c",
77
588
          (rm & 1) ? 'x' : 'a',
78
588
          (rm & 2) ? '1' : '0');
79
588
    break;
80
674
  case DSP_REG_XY:
81
674
    fprintf_fn (stream, "%c%c",
82
674
          (rm & 1) ? 'y' : 'x',
83
674
          (rm & 2) ? '1' : '0');
84
674
    break;
85
723
  case DSP_REG_AY:
86
723
    fprintf_fn (stream, "%c%c",
87
723
          (rm & 2) ? 'y' : 'a',
88
723
          (rm & 1) ? '1' : '0');
89
723
    break;
90
561
  case DSP_REG_YX:
91
561
    fprintf_fn (stream, "%c%c",
92
561
          (rm & 2) ? 'x' : 'y',
93
561
          (rm & 1) ? '1' : '0');
94
561
    break;
95
0
  default:
96
0
    abort ();
97
42.7k
  }
98
42.7k
      if (n == 0)
99
21.3k
  fprintf_fn (stream, ",");
100
42.7k
    }
101
21.3k
}
102
103
/* Print a double data transfer insn.  INSN is just the lower three
104
   nibbles of the insn, i.e. field a and the bit that indicates if
105
   a parallel processing insn follows.  */
106
107
static void
108
print_insn_ddt (int insn, struct disassemble_info *info)
109
16.1k
{
110
16.1k
  fprintf_ftype fprintf_fn = info->fprintf_func;
111
16.1k
  void *stream = info->stream;
112
113
  /* If this is just a nop, make sure to emit something.  */
114
16.1k
  if (insn == 0x000)
115
189
    {
116
189
      fprintf_fn (stream, "nopx\tnopy");
117
189
      return;
118
189
    }
119
120
  /* If a parallel processing insn was printed before,
121
     and we got a non-nop, emit a tab.  */
122
15.9k
  if ((insn & 0x800) && (insn & 0x3ff))
123
7.66k
    fprintf_fn (stream, "\t");
124
125
  /* Check if either the x or y part is invalid.  */
126
15.9k
  if (((insn & 3) != 0 && (insn & 0xc) == 0 && (insn & 0x2a0))
127
15.9k
      || ((insn & 3) == 0 && (insn & 0xc) != 0 && (insn & 0x150)))
128
4.60k
    if (info->mach != bfd_mach_sh_dsp
129
4.60k
        && info->mach != bfd_mach_sh3_dsp)
130
2.54k
      {
131
2.54k
  static const sh_opcode_info *first_movx, *first_movy;
132
2.54k
  const sh_opcode_info *op;
133
2.54k
  int is_movy;
134
135
2.54k
  if (! first_movx)
136
1
    {
137
277
      for (first_movx = sh_table; first_movx->nibbles[1] != MOVX_NOPY;)
138
276
        first_movx++;
139
19
      for (first_movy = first_movx; first_movy->nibbles[1] != MOVY_NOPX;)
140
18
        first_movy++;
141
1
    }
142
143
2.54k
  is_movy = ((insn & 3) != 0);
144
145
2.54k
  if (is_movy)
146
1.28k
    op = first_movy;
147
1.26k
  else
148
1.26k
    op = first_movx;
149
150
17.8k
  while (op->nibbles[2] != (unsigned) ((insn >> 4) & 3)
151
17.8k
         || op->nibbles[3] != (unsigned) (insn & 0xf))
152
15.2k
    op++;
153
154
2.54k
  print_movxy (op,
155
2.54k
         (4 * ((insn & (is_movy ? 0x200 : 0x100)) == 0)
156
2.54k
          + 2 * is_movy
157
2.54k
          + 1 * ((insn & (is_movy ? 0x100 : 0x200)) != 0)),
158
2.54k
         (insn >> 6) & 3,
159
2.54k
         fprintf_fn, stream);
160
2.54k
      }
161
2.05k
    else
162
2.05k
      fprintf_fn (stream, ".word 0x%x", insn | 0xf000);
163
11.3k
  else
164
11.3k
    {
165
11.3k
      static const sh_opcode_info *first_movx, *first_movy;
166
11.3k
      const sh_opcode_info *opx, *opy;
167
11.3k
      unsigned int insn_x, insn_y;
168
169
11.3k
      if (! first_movx)
170
1
  {
171
271
    for (first_movx = sh_table; first_movx->nibbles[1] != MOVX;)
172
270
      first_movx++;
173
19
    for (first_movy = first_movx; first_movy->nibbles[1] != MOVY;)
174
18
      first_movy++;
175
1
  }
176
11.3k
      insn_x = (insn >> 2) & 0xb;
177
11.3k
      if (insn_x)
178
9.39k
  {
179
105k
    for (opx = first_movx; opx->nibbles[2] != insn_x;)
180
95.6k
      opx++;
181
9.39k
    print_movxy (opx, ((insn >> 9) & 1) + 4, (insn >> 7) & 1,
182
9.39k
           fprintf_fn, stream);
183
9.39k
  }
184
11.3k
      insn_y = (insn & 3) | ((insn >> 1) & 8);
185
11.3k
      if (insn_y)
186
9.44k
  {
187
9.44k
    if (insn_x)
188
8.84k
      fprintf_fn (stream, "\t");
189
70.4k
    for (opy = first_movy; opy->nibbles[2] != insn_y;)
190
60.9k
      opy++;
191
9.44k
    print_movxy (opy, ((insn >> 8) & 1) + 6, (insn >> 6) & 1,
192
9.44k
           fprintf_fn, stream);
193
9.44k
  }
194
11.3k
      if (!insn_x && !insn_y && ((insn & 0x3ff) != 0 || (insn & 0x800) == 0))
195
1.18k
  fprintf_fn (stream, ".word 0x%x", insn | 0xf000);
196
11.3k
    }
197
15.9k
}
198
199
static void
200
print_dsp_reg (int rm, fprintf_ftype fprintf_fn, void *stream)
201
11.1k
{
202
11.1k
  switch (rm)
203
11.1k
    {
204
411
    case A_A1_NUM:
205
411
      fprintf_fn (stream, "a1");
206
411
      break;
207
402
    case A_A0_NUM:
208
402
      fprintf_fn (stream, "a0");
209
402
      break;
210
542
    case A_X0_NUM:
211
542
      fprintf_fn (stream, "x0");
212
542
      break;
213
379
    case A_X1_NUM:
214
379
      fprintf_fn (stream, "x1");
215
379
      break;
216
874
    case A_Y0_NUM:
217
874
      fprintf_fn (stream, "y0");
218
874
      break;
219
946
    case A_Y1_NUM:
220
946
      fprintf_fn (stream, "y1");
221
946
      break;
222
527
    case A_M0_NUM:
223
527
      fprintf_fn (stream, "m0");
224
527
      break;
225
282
    case A_A1G_NUM:
226
282
      fprintf_fn (stream, "a1g");
227
282
      break;
228
481
    case A_M1_NUM:
229
481
      fprintf_fn (stream, "m1");
230
481
      break;
231
2.31k
    case A_A0G_NUM:
232
2.31k
      fprintf_fn (stream, "a0g");
233
2.31k
      break;
234
4.04k
    default:
235
4.04k
      fprintf_fn (stream, "0x%x", rm);
236
4.04k
      break;
237
11.1k
    }
238
11.1k
}
239
240
static void
241
print_insn_ppi (int field_b, struct disassemble_info *info)
242
7.79k
{
243
7.79k
  static char *sx_tab[] = { "x0", "x1", "a0", "a1" };
244
7.79k
  static char *sy_tab[] = { "y0", "y1", "m0", "m1" };
245
7.79k
  fprintf_ftype fprintf_fn = info->fprintf_func;
246
7.79k
  void *stream = info->stream;
247
7.79k
  unsigned int nib1, nib2, nib3;
248
7.79k
  unsigned int altnib1, nib4;
249
7.79k
  char *dc = NULL;
250
7.79k
  const sh_opcode_info *op;
251
252
7.79k
  if ((field_b & 0xe800) == 0)
253
1.02k
    {
254
1.02k
      fprintf_fn (stream, "psh%c\t#%d,",
255
1.02k
      field_b & 0x1000 ? 'a' : 'l',
256
1.02k
      (field_b >> 4) & 127);
257
1.02k
      print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
258
1.02k
      return;
259
1.02k
    }
260
6.76k
  if ((field_b & 0xc000) == 0x4000 && (field_b & 0x3000) != 0x1000)
261
1.14k
    {
262
1.14k
      static char *du_tab[] = { "x0", "y0", "a0", "a1" };
263
1.14k
      static char *se_tab[] = { "x0", "x1", "y0", "a1" };
264
1.14k
      static char *sf_tab[] = { "y0", "y1", "x0", "a1" };
265
1.14k
      static char *sg_tab[] = { "m0", "m1", "a0", "a1" };
266
267
1.14k
      if (field_b & 0x2000)
268
813
  fprintf_fn (stream, "p%s %s,%s,%s\t",
269
813
        (field_b & 0x1000) ? "add" : "sub",
270
813
        sx_tab[(field_b >> 6) & 3],
271
813
        sy_tab[(field_b >> 4) & 3],
272
813
        du_tab[(field_b >> 0) & 3]);
273
274
334
      else if ((field_b & 0xf0) == 0x10
275
334
         && info->mach != bfd_mach_sh_dsp
276
334
         && info->mach != bfd_mach_sh3_dsp)
277
4
  fprintf_fn (stream, "pclr %s \t", du_tab[(field_b >> 0) & 3]);
278
279
330
      else if ((field_b & 0xf3) != 0)
280
266
  fprintf_fn (stream, ".word 0x%x\t", field_b);
281
282
1.14k
      fprintf_fn (stream, "pmuls%c%s,%s,%s",
283
1.14k
      field_b & 0x2000 ? ' ' : '\t',
284
1.14k
      se_tab[(field_b >> 10) & 3],
285
1.14k
      sf_tab[(field_b >>  8) & 3],
286
1.14k
      sg_tab[(field_b >>  2) & 3]);
287
1.14k
      return;
288
1.14k
    }
289
290
5.62k
  nib1 = PPIC;
291
5.62k
  nib2 = field_b >> 12 & 0xf;
292
5.62k
  nib3 = field_b >> 8 & 0xf;
293
5.62k
  nib4 = field_b >> 4 & 0xf;
294
5.62k
  switch (nib3 & 0x3)
295
5.62k
    {
296
1.24k
    case 0:
297
1.24k
      dc = "";
298
1.24k
      nib1 = PPI3;
299
1.24k
      break;
300
1.35k
    case 1:
301
1.35k
      dc = "";
302
1.35k
      break;
303
1.29k
    case 2:
304
1.29k
      dc = "dct ";
305
1.29k
      nib3 -= 1;
306
1.29k
      break;
307
1.73k
    case 3:
308
1.73k
      dc = "dcf ";
309
1.73k
      nib3 -= 2;
310
1.73k
      break;
311
5.62k
    }
312
5.62k
  if (nib1 == PPI3)
313
1.24k
    altnib1 = PPI3NC;
314
4.38k
  else
315
4.38k
    altnib1 = nib1;
316
2.24M
  for (op = sh_table; op->name; op++)
317
2.23M
    {
318
2.23M
      if ((op->nibbles[1] == nib1 || op->nibbles[1] == altnib1)
319
2.23M
    && op->nibbles[2] == nib2
320
2.23M
    && op->nibbles[3] == nib3)
321
3.19k
  {
322
3.19k
    int n;
323
324
3.19k
    switch (op->nibbles[4])
325
3.19k
      {
326
2.46k
      case HEX_0:
327
2.46k
        break;
328
134
      case HEX_XX00:
329
134
        if ((nib4 & 3) != 0)
330
102
    continue;
331
32
        break;
332
222
      case HEX_1:
333
222
        if ((nib4 & 3) != 1)
334
173
    continue;
335
49
        break;
336
147
      case HEX_00YY:
337
147
        if ((nib4 & 0xc) != 0)
338
80
    continue;
339
67
        break;
340
229
      case HEX_4:
341
229
        if ((nib4 & 0xc) != 4)
342
191
    continue;
343
38
        break;
344
38
      default:
345
0
        abort ();
346
3.19k
      }
347
2.64k
    fprintf_fn (stream, "%s%s\t", dc, op->name);
348
8.59k
    for (n = 0; n < 3 && op->arg[n] != A_END; n++)
349
5.95k
      {
350
5.95k
        if (n && op->arg[1] != A_END)
351
3.30k
    fprintf_fn (stream, ",");
352
5.95k
        switch (op->arg[n])
353
5.95k
    {
354
2.62k
    case DSP_REG_N:
355
2.62k
      print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
356
2.62k
      break;
357
1.08k
    case DSP_REG_X:
358
1.08k
      fprintf_fn (stream, "%s", sx_tab[(field_b >> 6) & 3]);
359
1.08k
      break;
360
1.68k
    case DSP_REG_Y:
361
1.68k
      fprintf_fn (stream, "%s", sy_tab[(field_b >> 4) & 3]);
362
1.68k
      break;
363
199
    case A_MACH:
364
199
      fprintf_fn (stream, "mach");
365
199
      break;
366
370
    case A_MACL:
367
370
      fprintf_fn (stream, "macl");
368
370
      break;
369
0
    default:
370
0
      abort ();
371
5.95k
    }
372
5.95k
      }
373
2.64k
    return;
374
2.64k
  }
375
2.23M
    }
376
  /* Not found.  */
377
2.97k
  fprintf_fn (stream, ".word 0x%x", field_b);
378
2.97k
}
379
380
/* FIXME mvs: movx insns print as ".word 0x%03x", insn & 0xfff
381
   (ie. the upper nibble is missing).  */
382
383
int
384
print_insn_sh (bfd_vma memaddr, struct disassemble_info *info)
385
2.06M
{
386
2.06M
  fprintf_ftype fprintf_fn = info->fprintf_func;
387
2.06M
  void *stream = info->stream;
388
2.06M
  unsigned char insn[4];
389
2.06M
  unsigned char nibs[8];
390
2.06M
  int status;
391
2.06M
  bfd_vma relmask = ~(bfd_vma) 0;
392
2.06M
  const sh_opcode_info *op;
393
2.06M
  unsigned int target_arch;
394
2.06M
  int allow_op32;
395
396
2.06M
  switch (info->mach)
397
2.06M
    {
398
450k
    case bfd_mach_sh:
399
450k
      target_arch = arch_sh1;
400
      /* SH coff object files lack information about the machine type, so
401
         we end up with bfd_mach_sh unless it was set explicitly (which
402
   could have happended if this is a call from gdb or the simulator.)  */
403
450k
      if (info->symbols
404
450k
    && bfd_asymbol_flavour(*info->symbols) == bfd_target_coff_flavour)
405
1.49k
  target_arch = arch_sh4;
406
450k
      break;
407
1.61M
    default:
408
1.61M
      target_arch = sh_get_arch_from_bfd_mach (info->mach);
409
2.06M
    }
410
411
2.06M
  status = info->read_memory_func (memaddr, insn, 2, info);
412
413
2.06M
  if (status != 0)
414
157
    {
415
157
      info->memory_error_func (status, memaddr, info);
416
157
      return -1;
417
157
    }
418
419
2.06M
  if (info->endian == BFD_ENDIAN_LITTLE)
420
348k
    {
421
348k
      nibs[0] = (insn[1] >> 4) & 0xf;
422
348k
      nibs[1] = insn[1] & 0xf;
423
424
348k
      nibs[2] = (insn[0] >> 4) & 0xf;
425
348k
      nibs[3] = insn[0] & 0xf;
426
348k
    }
427
1.71M
  else
428
1.71M
    {
429
1.71M
      nibs[0] = (insn[0] >> 4) & 0xf;
430
1.71M
      nibs[1] = insn[0] & 0xf;
431
432
1.71M
      nibs[2] = (insn[1] >> 4) & 0xf;
433
1.71M
      nibs[3] = insn[1] & 0xf;
434
1.71M
    }
435
2.06M
  status = info->read_memory_func (memaddr + 2, insn + 2, 2, info);
436
2.06M
  if (status != 0)
437
818
    allow_op32 = 0;
438
2.05M
  else
439
2.05M
    {
440
2.05M
      allow_op32 = 1;
441
442
2.05M
      if (info->endian == BFD_ENDIAN_LITTLE)
443
348k
  {
444
348k
    nibs[4] = (insn[3] >> 4) & 0xf;
445
348k
    nibs[5] = insn[3] & 0xf;
446
447
348k
    nibs[6] = (insn[2] >> 4) & 0xf;
448
348k
    nibs[7] = insn[2] & 0xf;
449
348k
  }
450
1.71M
      else
451
1.71M
  {
452
1.71M
    nibs[4] = (insn[2] >> 4) & 0xf;
453
1.71M
    nibs[5] = insn[2] & 0xf;
454
455
1.71M
    nibs[6] = (insn[3] >> 4) & 0xf;
456
1.71M
    nibs[7] = insn[3] & 0xf;
457
1.71M
  }
458
2.05M
    }
459
460
2.06M
  if (nibs[0] == 0xf && (nibs[1] & 4) == 0
461
2.06M
      && SH_MERGE_ARCH_SET_VALID (target_arch, arch_sh_dsp_up))
462
16.1k
    {
463
16.1k
      if (nibs[1] & 8)
464
7.80k
  {
465
7.80k
    int field_b;
466
467
7.80k
    status = info->read_memory_func (memaddr + 2, insn, 2, info);
468
469
7.80k
    if (status != 0)
470
8
      {
471
8
        info->memory_error_func (status, memaddr + 2, info);
472
8
        return -1;
473
8
      }
474
475
7.79k
    if (info->endian == BFD_ENDIAN_LITTLE)
476
0
      field_b = insn[1] << 8 | insn[0];
477
7.79k
    else
478
7.79k
      field_b = insn[0] << 8 | insn[1];
479
480
7.79k
    print_insn_ppi (field_b, info);
481
7.79k
    print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info);
482
7.79k
    return 4;
483
7.80k
  }
484
8.30k
      print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info);
485
8.30k
      return 2;
486
16.1k
    }
487
426M
  for (op = sh_table; op->name; op++)
488
426M
    {
489
426M
      int n;
490
426M
      int imm = 0;
491
426M
      int rn = 0;
492
426M
      int rm = 0;
493
426M
      int rb = 0;
494
426M
      int disp_pc;
495
426M
      bfd_vma disp_pc_addr = 0;
496
426M
      int disp = 0;
497
426M
      int has_disp = 0;
498
426M
      int max_n = SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 8 : 4;
499
500
426M
      if (!allow_op32
501
426M
    && SH_MERGE_ARCH_SET (op->arch, arch_op32))
502
7.29k
  goto fail;
503
504
426M
      if (!SH_MERGE_ARCH_SET_VALID (op->arch, target_arch))
505
186M
  goto fail;
506
309M
      for (n = 0; n < max_n; n++)
507
308M
  {
508
308M
    int i = op->nibbles[n];
509
510
308M
    if (i < 16)
511
261M
      {
512
261M
        if (nibs[n] == i)
513
37.4M
    continue;
514
224M
        goto fail;
515
261M
      }
516
46.9M
    switch (i)
517
46.9M
      {
518
35.4k
      case BRANCH_8:
519
35.4k
        imm = (nibs[2] << 4) | (nibs[3]);
520
35.4k
        if (imm & 0x80)
521
13.0k
    imm |= ~0xff;
522
35.4k
        imm = ((char) imm) * 2 + 4;
523
35.4k
        goto ok;
524
126k
      case BRANCH_12:
525
126k
        imm = ((nibs[1]) << 8) | (nibs[2] << 4) | (nibs[3]);
526
126k
        if (imm & 0x800)
527
66.4k
    imm |= ~0xfff;
528
126k
        imm = imm * 2 + 4;
529
126k
        goto ok;
530
1.56k
      case IMM0_3c:
531
1.56k
        if (nibs[3] & 0x8)
532
555
    goto fail;
533
1.01k
        imm = nibs[3] & 0x7;
534
1.01k
        break;
535
1.37k
      case IMM0_3s:
536
1.37k
        if (!(nibs[3] & 0x8))
537
485
    goto fail;
538
886
        imm = nibs[3] & 0x7;
539
886
        break;
540
24.0k
      case IMM0_3Uc:
541
24.0k
        if (nibs[2] & 0x8)
542
9.35k
    goto fail;
543
14.6k
        imm = nibs[2] & 0x7;
544
14.6k
        break;
545
0
      case IMM0_3Us:
546
0
        if (!(nibs[2] & 0x8))
547
0
    goto fail;
548
0
        imm = nibs[2] & 0x7;
549
0
        break;
550
149
      case DISP0_12:
551
1.60k
      case DISP1_12:
552
1.60k
        disp = (nibs[5] << 8) | (nibs[6] << 4) | nibs[7];
553
1.60k
        has_disp = 1;
554
1.60k
        goto ok;
555
298
      case DISP0_12BY2:
556
403
      case DISP1_12BY2:
557
403
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 1;
558
403
        relmask = ~(bfd_vma) 1;
559
403
        has_disp = 1;
560
403
        goto ok;
561
352
      case DISP0_12BY4:
562
1.37k
      case DISP1_12BY4:
563
1.37k
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 2;
564
1.37k
        relmask = ~(bfd_vma) 3;
565
1.37k
        has_disp = 1;
566
1.37k
        goto ok;
567
724
      case DISP0_12BY8:
568
1.65k
      case DISP1_12BY8:
569
1.65k
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 3;
570
1.65k
        relmask = ~(bfd_vma) 7;
571
1.65k
        has_disp = 1;
572
1.65k
        goto ok;
573
110k
      case IMM0_20_4:
574
110k
        break;
575
73.2k
      case IMM0_20:
576
73.2k
        imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8)
577
73.2k
         | (nibs[6] << 4) | nibs[7]);
578
73.2k
        if (imm & 0x80000)
579
3.35k
    imm -= 0x100000;
580
73.2k
        goto ok;
581
5.55k
      case IMM0_20BY8:
582
5.55k
        imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8)
583
5.55k
         | (nibs[6] << 4) | nibs[7]);
584
5.55k
        imm <<= 8;
585
5.55k
        if (imm & 0x8000000)
586
686
    imm -= 0x10000000;
587
5.55k
        goto ok;
588
5.26k
      case IMM0_4:
589
16.1k
      case IMM1_4:
590
16.1k
        imm = nibs[3];
591
16.1k
        goto ok;
592
4.65k
      case IMM0_4BY2:
593
8.75k
      case IMM1_4BY2:
594
8.75k
        imm = nibs[3] << 1;
595
8.75k
        goto ok;
596
89.9k
      case IMM0_4BY4:
597
172k
      case IMM1_4BY4:
598
172k
        imm = nibs[3] << 2;
599
172k
        goto ok;
600
209k
      case IMM0_8S:
601
215k
      case IMM1_8:
602
215k
        imm = (nibs[2] << 4) | nibs[3];
603
215k
        disp = imm;
604
215k
        has_disp = 1;
605
215k
        if (imm & 0x80)
606
70.6k
    imm -= 0x100;
607
215k
        goto ok;
608
35.4k
      case IMM0_8U:
609
35.4k
        disp = imm = (nibs[2] << 4) | nibs[3];
610
35.4k
        has_disp = 1;
611
35.4k
        goto ok;
612
67.5k
      case PCRELIMM_8BY2:
613
67.5k
        imm = ((nibs[2] << 4) | nibs[3]) << 1;
614
67.5k
        relmask = ~(bfd_vma) 1;
615
67.5k
        goto ok;
616
79.7k
      case PCRELIMM_8BY4:
617
79.7k
        imm = ((nibs[2] << 4) | nibs[3]) << 2;
618
79.7k
        relmask = ~(bfd_vma) 3;
619
79.7k
        goto ok;
620
3.13k
      case IMM0_8BY2:
621
8.78k
      case IMM1_8BY2:
622
8.78k
        imm = ((nibs[2] << 4) | nibs[3]) << 1;
623
8.78k
        goto ok;
624
6.22k
      case IMM0_8BY4:
625
8.81k
      case IMM1_8BY4:
626
8.81k
        imm = ((nibs[2] << 4) | nibs[3]) << 2;
627
8.81k
        goto ok;
628
82.4k
      case REG_N_D:
629
82.4k
        if ((nibs[n] & 1) != 0)
630
62.7k
    goto fail;
631
        /* Fall through.  */
632
21.8M
      case REG_N:
633
21.8M
        rn = nibs[n];
634
21.8M
        break;
635
9.65M
      case REG_M:
636
9.65M
        rm = nibs[n];
637
9.65M
        break;
638
403
      case REG_N_B01:
639
403
        if ((nibs[n] & 0x3) != 1 /* binary 01 */)
640
348
    goto fail;
641
55
        rn = (nibs[n] & 0xc) >> 2;
642
55
        break;
643
1.69k
      case REG_NM:
644
1.69k
        rn = (nibs[n] & 0xc) >> 2;
645
1.69k
        rm = (nibs[n] & 0x3);
646
1.69k
        break;
647
173k
      case REG_B:
648
173k
        if (!(nibs[n] & 0x08)) /* Must always be 1.  */
649
135k
    goto fail;
650
38.0k
        rb = nibs[n] & 0x07;
651
38.0k
        break;
652
486k
      case SDT_REG_N:
653
        /* sh-dsp: single data transfer.  */
654
486k
        rn = nibs[n];
655
486k
        if ((rn & 0xc) != 4)
656
425k
    goto fail;
657
60.7k
        rn = rn & 0x3;
658
60.7k
        rn |= (!(rn & 2)) << 2;
659
60.7k
        break;
660
13.3M
      case PPI:
661
13.7M
      case REPEAT:
662
13.7M
        goto fail;
663
0
      default:
664
0
        abort ();
665
46.9M
      }
666
46.9M
  }
667
668
1.50M
    ok:
669
      /* sh2a has D_REG but not X_REG.  We don't know the pattern
670
   doesn't match unless we check the output args to see if they
671
   make sense.  */
672
1.50M
      if (target_arch == arch_sh2a
673
1.50M
    && ((op->arg[0] == DX_REG_M && (rm & 1) != 0)
674
544k
        || (op->arg[1] == DX_REG_N && (rn & 1) != 0)))
675
997
  goto fail;
676
677
1.50M
      fprintf_fn (stream, "%s\t", op->name);
678
1.50M
      disp_pc = 0;
679
4.17M
      for (n = 0; n < 3 && op->arg[n] != A_END; n++)
680
2.66M
  {
681
2.66M
    if (n && op->arg[1] != A_END)
682
1.22M
      fprintf_fn (stream, ",");
683
2.66M
    switch (op->arg[n])
684
2.66M
      {
685
322k
      case A_IMM:
686
322k
        fprintf_fn (stream, "#%d", imm);
687
322k
        break;
688
83.0k
      case A_R0:
689
83.0k
        fprintf_fn (stream, "r0");
690
83.0k
        break;
691
889k
      case A_REG_N:
692
889k
        fprintf_fn (stream, "r%d", rn);
693
889k
        break;
694
25.4k
      case A_INC_N:
695
25.4k
      case AS_INC_N:
696
25.4k
        fprintf_fn (stream, "@r%d+", rn);
697
25.4k
        break;
698
30.6k
      case A_DEC_N:
699
30.6k
      case AS_DEC_N:
700
30.6k
        fprintf_fn (stream, "@-r%d", rn);
701
30.6k
        break;
702
54.2k
      case A_IND_N:
703
54.2k
      case AS_IND_N:
704
54.2k
        fprintf_fn (stream, "@r%d", rn);
705
54.2k
        break;
706
85.2k
      case A_DISP_REG_N:
707
85.2k
        fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rn);
708
85.2k
        break;
709
1.38k
      case AS_PMOD_N:
710
1.38k
        fprintf_fn (stream, "@r%d+r8", rn);
711
1.38k
        break;
712
420k
      case A_REG_M:
713
420k
        fprintf_fn (stream, "r%d", rm);
714
420k
        break;
715
55.4k
      case A_INC_M:
716
55.4k
        fprintf_fn (stream, "@r%d+", rm);
717
55.4k
        break;
718
108
      case A_DEC_M:
719
108
        fprintf_fn (stream, "@-r%d", rm);
720
108
        break;
721
42.1k
      case A_IND_M:
722
42.1k
        fprintf_fn (stream, "@r%d", rm);
723
42.1k
        break;
724
116k
      case A_DISP_REG_M:
725
116k
        fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rm);
726
116k
        break;
727
2.12k
      case A_REG_B:
728
2.12k
        fprintf_fn (stream, "r%d_bank", rb);
729
2.12k
        break;
730
147k
      case A_DISP_PC:
731
147k
        disp_pc = 1;
732
147k
        disp_pc_addr = imm + 4 + (memaddr & relmask);
733
147k
        (*info->print_address_func) (disp_pc_addr, info);
734
147k
        break;
735
49.8k
      case A_IND_R0_REG_N:
736
49.8k
        fprintf_fn (stream, "@(r0,r%d)", rn);
737
49.8k
        break;
738
35.1k
      case A_IND_R0_REG_M:
739
35.1k
        fprintf_fn (stream, "@(r0,r%d)", rm);
740
35.1k
        break;
741
25.5k
      case A_DISP_GBR:
742
25.5k
        fprintf_fn (stream, "@(%d,gbr)", has_disp?disp:imm);
743
25.5k
        break;
744
358
      case A_TBR:
745
358
        fprintf_fn (stream, "tbr");
746
358
        break;
747
2.05k
      case A_DISP2_TBR:
748
2.05k
        fprintf_fn (stream, "@@(%d,tbr)", has_disp?disp:imm);
749
2.05k
        break;
750
88
      case A_INC_R15:
751
88
        fprintf_fn (stream, "@r15+");
752
88
        break;
753
361
      case A_DEC_R15:
754
361
        fprintf_fn (stream, "@-r15");
755
361
        break;
756
12.9k
      case A_R0_GBR:
757
12.9k
        fprintf_fn (stream, "@(r0,gbr)");
758
12.9k
        break;
759
126k
      case A_BDISP12:
760
162k
      case A_BDISP8:
761
162k
        (*info->print_address_func) (imm + memaddr, info);
762
162k
        break;
763
10.2k
      case A_SR:
764
10.2k
        fprintf_fn (stream, "sr");
765
10.2k
        break;
766
3.25k
      case A_GBR:
767
3.25k
        fprintf_fn (stream, "gbr");
768
3.25k
        break;
769
1.11k
      case A_VBR:
770
1.11k
        fprintf_fn (stream, "vbr");
771
1.11k
        break;
772
519
      case A_DSR:
773
519
        fprintf_fn (stream, "dsr");
774
519
        break;
775
570
      case A_MOD:
776
570
        fprintf_fn (stream, "mod");
777
570
        break;
778
370
      case A_RE:
779
370
        fprintf_fn (stream, "re");
780
370
        break;
781
459
      case A_RS:
782
459
        fprintf_fn (stream, "rs");
783
459
        break;
784
747
      case A_A0:
785
747
        fprintf_fn (stream, "a0");
786
747
        break;
787
798
      case A_X0:
788
798
        fprintf_fn (stream, "x0");
789
798
        break;
790
363
      case A_X1:
791
363
        fprintf_fn (stream, "x1");
792
363
        break;
793
395
      case A_Y0:
794
395
        fprintf_fn (stream, "y0");
795
395
        break;
796
401
      case A_Y1:
797
401
        fprintf_fn (stream, "y1");
798
401
        break;
799
7.55k
      case DSP_REG_M:
800
7.55k
        print_dsp_reg (rm, fprintf_fn, stream);
801
7.55k
        break;
802
310
      case A_SSR:
803
310
        fprintf_fn (stream, "ssr");
804
310
        break;
805
1.31k
      case A_SPC:
806
1.31k
        fprintf_fn (stream, "spc");
807
1.31k
        break;
808
4.69k
      case A_MACH:
809
4.69k
        fprintf_fn (stream, "mach");
810
4.69k
        break;
811
1.39k
      case A_MACL:
812
1.39k
        fprintf_fn (stream, "macl");
813
1.39k
        break;
814
4.25k
      case A_PR:
815
4.25k
        fprintf_fn (stream, "pr");
816
4.25k
        break;
817
523
      case A_SGR:
818
523
        fprintf_fn (stream, "sgr");
819
523
        break;
820
280
      case A_DBR:
821
280
        fprintf_fn (stream, "dbr");
822
280
        break;
823
26.9k
      case F_REG_N:
824
26.9k
        fprintf_fn (stream, "fr%d", rn);
825
26.9k
        break;
826
27.4k
      case F_REG_M:
827
27.4k
        fprintf_fn (stream, "fr%d", rm);
828
27.4k
        break;
829
571
      case DX_REG_N:
830
571
        if (rn & 1)
831
0
    {
832
0
      fprintf_fn (stream, "xd%d", rn & ~1);
833
0
      break;
834
0
    }
835
        /* Fall through.  */
836
657
      case D_REG_N:
837
657
        fprintf_fn (stream, "dr%d", rn);
838
657
        break;
839
90
      case DX_REG_M:
840
90
        if (rm & 1)
841
0
    {
842
0
      fprintf_fn (stream, "xd%d", rm & ~1);
843
0
      break;
844
0
    }
845
        /* Fall through.  */
846
90
      case D_REG_M:
847
90
        fprintf_fn (stream, "dr%d", rm);
848
90
        break;
849
161
      case FPSCR_M:
850
564
      case FPSCR_N:
851
564
        fprintf_fn (stream, "fpscr");
852
564
        break;
853
966
      case FPUL_M:
854
1.52k
      case FPUL_N:
855
1.52k
        fprintf_fn (stream, "fpul");
856
1.52k
        break;
857
1.48k
      case F_FR0:
858
1.48k
        fprintf_fn (stream, "fr0");
859
1.48k
        break;
860
22
      case V_REG_N:
861
22
        fprintf_fn (stream, "fv%d", rn * 4);
862
22
        break;
863
14
      case V_REG_M:
864
14
        fprintf_fn (stream, "fv%d", rm * 4);
865
14
        break;
866
8
      case XMTRX_M4:
867
8
        fprintf_fn (stream, "xmtrx");
868
8
        break;
869
0
      default:
870
0
        abort ();
871
2.66M
      }
872
2.66M
  }
873
874
#if 0
875
      /* This code prints instructions in delay slots on the same line
876
         as the instruction which needs the delay slots.  This can be
877
         confusing, since other disassembler don't work this way, and
878
         it means that the instructions are not all in a line.  So I
879
         disabled it.  Ian.  */
880
      if (!(info->flags & 1)
881
    && (op->name[0] == 'j'
882
        || (op->name[0] == 'b'
883
      && (op->name[1] == 'r'
884
          || op->name[1] == 's'))
885
        || (op->name[0] == 'r' && op->name[1] == 't')
886
        || (op->name[0] == 'b' && op->name[2] == '.')))
887
  {
888
    info->flags |= 1;
889
    fprintf_fn (stream, "\t(slot ");
890
    print_insn_sh (memaddr + 2, info);
891
    info->flags &= ~1;
892
    fprintf_fn (stream, ")");
893
    return 4;
894
  }
895
#endif
896
897
1.50M
      if (disp_pc && strcmp (op->name, "mova") != 0)
898
142k
  {
899
142k
    int size;
900
142k
    bfd_byte bytes[4];
901
902
142k
    if (relmask == ~(bfd_vma) 1)
903
67.5k
      size = 2;
904
75.0k
    else
905
75.0k
      size = 4;
906
    /* Not reading an instruction - disable stop_vma.  */
907
142k
    info->stop_vma = 0;
908
142k
    status = info->read_memory_func (disp_pc_addr, bytes, size, info);
909
142k
    if (status == 0)
910
135k
      {
911
135k
        unsigned int val;
912
913
135k
        if (size == 2)
914
64.4k
    {
915
64.4k
      if (info->endian == BFD_ENDIAN_LITTLE)
916
3.17k
        val = bfd_getl16 (bytes);
917
61.2k
      else
918
61.2k
        val = bfd_getb16 (bytes);
919
64.4k
    }
920
71.5k
        else
921
71.5k
    {
922
71.5k
      if (info->endian == BFD_ENDIAN_LITTLE)
923
18.4k
        val = bfd_getl32 (bytes);
924
53.0k
      else
925
53.0k
        val = bfd_getb32 (bytes);
926
71.5k
    }
927
135k
        if ((*info->symbol_at_address_func) (val, info))
928
11.7k
    {
929
11.7k
      fprintf_fn (stream, "\t! ");
930
11.7k
      (*info->print_address_func) (val, info);
931
11.7k
    }
932
124k
        else
933
124k
    fprintf_fn (stream, "\t! %x", val);
934
135k
      }
935
142k
  }
936
937
1.50M
      return SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 4 : 2;
938
424M
    fail:
939
424M
      ;
940
941
424M
    }
942
535k
  fprintf_fn (stream, ".word 0x%x%x%x%x", nibs[0], nibs[1], nibs[2], nibs[3]);
943
535k
  return 2;
944
2.04M
}