Coverage Report

Created: 2023-08-28 06:31

/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
48.8k
{
37
48.8k
  int n;
38
39
48.8k
  fprintf_fn (stream, "%s\t", op->name);
40
146k
  for (n = 0; n < 2; n++)
41
97.6k
    {
42
97.6k
      switch (op->arg[n])
43
97.6k
  {
44
0
  case A_IND_N:
45
4.40k
  case AX_IND_N:
46
5.53k
  case AXY_IND_N:
47
10.8k
  case AY_IND_N:
48
12.5k
  case AYX_IND_N:
49
12.5k
    fprintf_fn (stream, "@r%d", rn);
50
12.5k
    break;
51
0
  case A_INC_N:
52
6.94k
  case AX_INC_N:
53
8.74k
  case AXY_INC_N:
54
13.7k
  case AY_INC_N:
55
15.4k
  case AYX_INC_N:
56
15.4k
    fprintf_fn (stream, "@r%d+", rn);
57
15.4k
    break;
58
5.35k
  case AX_PMOD_N:
59
6.07k
  case AXY_PMOD_N:
60
6.07k
    fprintf_fn (stream, "@r%d+r8", rn);
61
6.07k
    break;
62
6.38k
  case AY_PMOD_N:
63
8.21k
  case AYX_PMOD_N:
64
8.21k
    fprintf_fn (stream, "@r%d+r9", rn);
65
8.21k
    break;
66
20.2k
  case DSP_REG_A_M:
67
20.2k
    fprintf_fn (stream, "a%c", '0' + rm);
68
20.2k
    break;
69
12.9k
  case DSP_REG_X:
70
12.9k
    fprintf_fn (stream, "x%c", '0' + rm);
71
12.9k
    break;
72
13.4k
  case DSP_REG_Y:
73
13.4k
    fprintf_fn (stream, "y%c", '0' + rm);
74
13.4k
    break;
75
2.15k
  case DSP_REG_AX:
76
2.15k
    fprintf_fn (stream, "%c%c",
77
2.15k
          (rm & 1) ? 'x' : 'a',
78
2.15k
          (rm & 2) ? '1' : '0');
79
2.15k
    break;
80
1.49k
  case DSP_REG_XY:
81
1.49k
    fprintf_fn (stream, "%c%c",
82
1.49k
          (rm & 1) ? 'y' : 'x',
83
1.49k
          (rm & 2) ? '1' : '0');
84
1.49k
    break;
85
3.84k
  case DSP_REG_AY:
86
3.84k
    fprintf_fn (stream, "%c%c",
87
3.84k
          (rm & 2) ? 'y' : 'a',
88
3.84k
          (rm & 1) ? '1' : '0');
89
3.84k
    break;
90
1.30k
  case DSP_REG_YX:
91
1.30k
    fprintf_fn (stream, "%c%c",
92
1.30k
          (rm & 2) ? 'x' : 'y',
93
1.30k
          (rm & 1) ? '1' : '0');
94
1.30k
    break;
95
0
  default:
96
0
    abort ();
97
97.6k
  }
98
97.6k
      if (n == 0)
99
48.8k
  fprintf_fn (stream, ",");
100
97.6k
    }
101
48.8k
}
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
37.5k
{
110
37.5k
  fprintf_ftype fprintf_fn = info->fprintf_func;
111
37.5k
  void *stream = info->stream;
112
113
  /* If this is just a nop, make sure to emit something.  */
114
37.5k
  if (insn == 0x000)
115
426
    {
116
426
      fprintf_fn (stream, "nopx\tnopy");
117
426
      return;
118
426
    }
119
120
  /* If a parallel processing insn was printed before,
121
     and we got a non-nop, emit a tab.  */
122
37.1k
  if ((insn & 0x800) && (insn & 0x3ff))
123
19.5k
    fprintf_fn (stream, "\t");
124
125
  /* Check if either the x or y part is invalid.  */
126
37.1k
  if (((insn & 3) != 0 && (insn & 0xc) == 0 && (insn & 0x2a0))
127
37.1k
      || ((insn & 3) == 0 && (insn & 0xc) != 0 && (insn & 0x150)))
128
12.8k
    if (info->mach != bfd_mach_sh_dsp
129
12.8k
        && info->mach != bfd_mach_sh3_dsp)
130
8.80k
      {
131
8.80k
  static const sh_opcode_info *first_movx, *first_movy;
132
8.80k
  const sh_opcode_info *op;
133
8.80k
  int is_movy;
134
135
8.80k
  if (! first_movx)
136
2
    {
137
554
      for (first_movx = sh_table; first_movx->nibbles[1] != MOVX_NOPY;)
138
552
        first_movx++;
139
38
      for (first_movy = first_movx; first_movy->nibbles[1] != MOVY_NOPX;)
140
36
        first_movy++;
141
2
    }
142
143
8.80k
  is_movy = ((insn & 3) != 0);
144
145
8.80k
  if (is_movy)
146
5.14k
    op = first_movy;
147
3.65k
  else
148
3.65k
    op = first_movx;
149
150
72.9k
  while (op->nibbles[2] != (unsigned) ((insn >> 4) & 3)
151
72.9k
         || op->nibbles[3] != (unsigned) (insn & 0xf))
152
64.1k
    op++;
153
154
8.80k
  print_movxy (op,
155
8.80k
         (4 * ((insn & (is_movy ? 0x200 : 0x100)) == 0)
156
8.80k
          + 2 * is_movy
157
8.80k
          + 1 * ((insn & (is_movy ? 0x100 : 0x200)) != 0)),
158
8.80k
         (insn >> 6) & 3,
159
8.80k
         fprintf_fn, stream);
160
8.80k
      }
161
4.00k
    else
162
4.00k
      fprintf_fn (stream, ".word 0x%x", insn | 0xf000);
163
24.3k
  else
164
24.3k
    {
165
24.3k
      static const sh_opcode_info *first_movx, *first_movy;
166
24.3k
      const sh_opcode_info *opx, *opy;
167
24.3k
      unsigned int insn_x, insn_y;
168
169
24.3k
      if (! first_movx)
170
2
  {
171
542
    for (first_movx = sh_table; first_movx->nibbles[1] != MOVX;)
172
540
      first_movx++;
173
38
    for (first_movy = first_movx; first_movy->nibbles[1] != MOVY;)
174
36
      first_movy++;
175
2
  }
176
24.3k
      insn_x = (insn >> 2) & 0xb;
177
24.3k
      if (insn_x)
178
19.9k
  {
179
195k
    for (opx = first_movx; opx->nibbles[2] != insn_x;)
180
175k
      opx++;
181
19.9k
    print_movxy (opx, ((insn >> 9) & 1) + 4, (insn >> 7) & 1,
182
19.9k
           fprintf_fn, stream);
183
19.9k
  }
184
24.3k
      insn_y = (insn & 3) | ((insn >> 1) & 8);
185
24.3k
      if (insn_y)
186
20.0k
  {
187
20.0k
    if (insn_x)
188
18.7k
      fprintf_fn (stream, "\t");
189
138k
    for (opy = first_movy; opy->nibbles[2] != insn_y;)
190
118k
      opy++;
191
20.0k
    print_movxy (opy, ((insn >> 8) & 1) + 6, (insn >> 6) & 1,
192
20.0k
           fprintf_fn, stream);
193
20.0k
  }
194
24.3k
      if (!insn_x && !insn_y && ((insn & 0x3ff) != 0 || (insn & 0x800) == 0))
195
2.32k
  fprintf_fn (stream, ".word 0x%x", insn | 0xf000);
196
24.3k
    }
197
37.1k
}
198
199
static void
200
print_dsp_reg (int rm, fprintf_ftype fprintf_fn, void *stream)
201
24.8k
{
202
24.8k
  switch (rm)
203
24.8k
    {
204
763
    case A_A1_NUM:
205
763
      fprintf_fn (stream, "a1");
206
763
      break;
207
959
    case A_A0_NUM:
208
959
      fprintf_fn (stream, "a0");
209
959
      break;
210
1.52k
    case A_X0_NUM:
211
1.52k
      fprintf_fn (stream, "x0");
212
1.52k
      break;
213
1.86k
    case A_X1_NUM:
214
1.86k
      fprintf_fn (stream, "x1");
215
1.86k
      break;
216
1.54k
    case A_Y0_NUM:
217
1.54k
      fprintf_fn (stream, "y0");
218
1.54k
      break;
219
1.80k
    case A_Y1_NUM:
220
1.80k
      fprintf_fn (stream, "y1");
221
1.80k
      break;
222
960
    case A_M0_NUM:
223
960
      fprintf_fn (stream, "m0");
224
960
      break;
225
748
    case A_A1G_NUM:
226
748
      fprintf_fn (stream, "a1g");
227
748
      break;
228
1.53k
    case A_M1_NUM:
229
1.53k
      fprintf_fn (stream, "m1");
230
1.53k
      break;
231
5.34k
    case A_A0G_NUM:
232
5.34k
      fprintf_fn (stream, "a0g");
233
5.34k
      break;
234
7.81k
    default:
235
7.81k
      fprintf_fn (stream, "0x%x", rm);
236
7.81k
      break;
237
24.8k
    }
238
24.8k
}
239
240
static void
241
print_insn_ppi (int field_b, struct disassemble_info *info)
242
20.3k
{
243
20.3k
  static char *sx_tab[] = { "x0", "x1", "a0", "a1" };
244
20.3k
  static char *sy_tab[] = { "y0", "y1", "m0", "m1" };
245
20.3k
  fprintf_ftype fprintf_fn = info->fprintf_func;
246
20.3k
  void *stream = info->stream;
247
20.3k
  unsigned int nib1, nib2, nib3;
248
20.3k
  unsigned int altnib1, nib4;
249
20.3k
  char *dc = NULL;
250
20.3k
  const sh_opcode_info *op;
251
252
20.3k
  if ((field_b & 0xe800) == 0)
253
3.33k
    {
254
3.33k
      fprintf_fn (stream, "psh%c\t#%d,",
255
3.33k
      field_b & 0x1000 ? 'a' : 'l',
256
3.33k
      (field_b >> 4) & 127);
257
3.33k
      print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
258
3.33k
      return;
259
3.33k
    }
260
16.9k
  if ((field_b & 0xc000) == 0x4000 && (field_b & 0x3000) != 0x1000)
261
2.18k
    {
262
2.18k
      static char *du_tab[] = { "x0", "y0", "a0", "a1" };
263
2.18k
      static char *se_tab[] = { "x0", "x1", "y0", "a1" };
264
2.18k
      static char *sf_tab[] = { "y0", "y1", "x0", "a1" };
265
2.18k
      static char *sg_tab[] = { "m0", "m1", "a0", "a1" };
266
267
2.18k
      if (field_b & 0x2000)
268
1.58k
  fprintf_fn (stream, "p%s %s,%s,%s\t",
269
1.58k
        (field_b & 0x1000) ? "add" : "sub",
270
1.58k
        sx_tab[(field_b >> 6) & 3],
271
1.58k
        sy_tab[(field_b >> 4) & 3],
272
1.58k
        du_tab[(field_b >> 0) & 3]);
273
274
597
      else if ((field_b & 0xf0) == 0x10
275
597
         && info->mach != bfd_mach_sh_dsp
276
597
         && info->mach != bfd_mach_sh3_dsp)
277
56
  fprintf_fn (stream, "pclr %s \t", du_tab[(field_b >> 0) & 3]);
278
279
541
      else if ((field_b & 0xf3) != 0)
280
439
  fprintf_fn (stream, ".word 0x%x\t", field_b);
281
282
2.18k
      fprintf_fn (stream, "pmuls%c%s,%s,%s",
283
2.18k
      field_b & 0x2000 ? ' ' : '\t',
284
2.18k
      se_tab[(field_b >> 10) & 3],
285
2.18k
      sf_tab[(field_b >>  8) & 3],
286
2.18k
      sg_tab[(field_b >>  2) & 3]);
287
2.18k
      return;
288
2.18k
    }
289
290
14.8k
  nib1 = PPIC;
291
14.8k
  nib2 = field_b >> 12 & 0xf;
292
14.8k
  nib3 = field_b >> 8 & 0xf;
293
14.8k
  nib4 = field_b >> 4 & 0xf;
294
14.8k
  switch (nib3 & 0x3)
295
14.8k
    {
296
3.71k
    case 0:
297
3.71k
      dc = "";
298
3.71k
      nib1 = PPI3;
299
3.71k
      break;
300
3.39k
    case 1:
301
3.39k
      dc = "";
302
3.39k
      break;
303
3.15k
    case 2:
304
3.15k
      dc = "dct ";
305
3.15k
      nib3 -= 1;
306
3.15k
      break;
307
4.54k
    case 3:
308
4.54k
      dc = "dcf ";
309
4.54k
      nib3 -= 2;
310
4.54k
      break;
311
14.8k
    }
312
14.8k
  if (nib1 == PPI3)
313
3.71k
    altnib1 = PPI3NC;
314
11.0k
  else
315
11.0k
    altnib1 = nib1;
316
5.86M
  for (op = sh_table; op->name; op++)
317
5.85M
    {
318
5.85M
      if ((op->nibbles[1] == nib1 || op->nibbles[1] == altnib1)
319
5.85M
    && op->nibbles[2] == nib2
320
5.85M
    && op->nibbles[3] == nib3)
321
9.57k
  {
322
9.57k
    int n;
323
324
9.57k
    switch (op->nibbles[4])
325
9.57k
      {
326
6.82k
      case HEX_0:
327
6.82k
        break;
328
938
      case HEX_XX00:
329
938
        if ((nib4 & 3) != 0)
330
874
    continue;
331
64
        break;
332
1.03k
      case HEX_1:
333
1.03k
        if ((nib4 & 3) != 1)
334
696
    continue;
335
342
        break;
336
361
      case HEX_00YY:
337
361
        if ((nib4 & 0xc) != 0)
338
189
    continue;
339
172
        break;
340
412
      case HEX_4:
341
412
        if ((nib4 & 0xc) != 4)
342
362
    continue;
343
50
        break;
344
50
      default:
345
0
        abort ();
346
9.57k
      }
347
7.45k
    fprintf_fn (stream, "%s%s\t", dc, op->name);
348
23.9k
    for (n = 0; n < 3 && op->arg[n] != A_END; n++)
349
16.5k
      {
350
16.5k
        if (n && op->arg[1] != A_END)
351
9.05k
    fprintf_fn (stream, ",");
352
16.5k
        switch (op->arg[n])
353
16.5k
    {
354
7.41k
    case DSP_REG_N:
355
7.41k
      print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
356
7.41k
      break;
357
2.51k
    case DSP_REG_X:
358
2.51k
      fprintf_fn (stream, "%s", sx_tab[(field_b >> 6) & 3]);
359
2.51k
      break;
360
4.71k
    case DSP_REG_Y:
361
4.71k
      fprintf_fn (stream, "%s", sy_tab[(field_b >> 4) & 3]);
362
4.71k
      break;
363
681
    case A_MACH:
364
681
      fprintf_fn (stream, "mach");
365
681
      break;
366
1.18k
    case A_MACL:
367
1.18k
      fprintf_fn (stream, "macl");
368
1.18k
      break;
369
0
    default:
370
0
      abort ();
371
16.5k
    }
372
16.5k
      }
373
7.45k
    return;
374
7.45k
  }
375
5.85M
    }
376
  /* Not found.  */
377
7.35k
  fprintf_fn (stream, ".word 0x%x", field_b);
378
7.35k
}
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.55M
{
386
2.55M
  fprintf_ftype fprintf_fn = info->fprintf_func;
387
2.55M
  void *stream = info->stream;
388
2.55M
  unsigned char insn[4];
389
2.55M
  unsigned char nibs[8];
390
2.55M
  int status;
391
2.55M
  bfd_vma relmask = ~(bfd_vma) 0;
392
2.55M
  const sh_opcode_info *op;
393
2.55M
  unsigned int target_arch;
394
2.55M
  int allow_op32;
395
396
2.55M
  switch (info->mach)
397
2.55M
    {
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
2.10M
    default:
408
2.10M
      target_arch = sh_get_arch_from_bfd_mach (info->mach);
409
2.55M
    }
410
411
2.55M
  status = info->read_memory_func (memaddr, insn, 2, info);
412
413
2.55M
  if (status != 0)
414
355
    {
415
355
      info->memory_error_func (status, memaddr, info);
416
355
      return -1;
417
355
    }
418
419
2.55M
  if (info->endian == BFD_ENDIAN_LITTLE)
420
844k
    {
421
844k
      nibs[0] = (insn[1] >> 4) & 0xf;
422
844k
      nibs[1] = insn[1] & 0xf;
423
424
844k
      nibs[2] = (insn[0] >> 4) & 0xf;
425
844k
      nibs[3] = insn[0] & 0xf;
426
844k
    }
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.55M
  status = info->read_memory_func (memaddr + 2, insn + 2, 2, info);
436
2.55M
  if (status != 0)
437
1.19k
    allow_op32 = 0;
438
2.55M
  else
439
2.55M
    {
440
2.55M
      allow_op32 = 1;
441
442
2.55M
      if (info->endian == BFD_ENDIAN_LITTLE)
443
843k
  {
444
843k
    nibs[4] = (insn[3] >> 4) & 0xf;
445
843k
    nibs[5] = insn[3] & 0xf;
446
447
843k
    nibs[6] = (insn[2] >> 4) & 0xf;
448
843k
    nibs[7] = insn[2] & 0xf;
449
843k
  }
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.55M
    }
459
460
2.55M
  if (nibs[0] == 0xf && (nibs[1] & 4) == 0
461
2.55M
      && SH_MERGE_ARCH_SET_VALID (target_arch, arch_sh_dsp_up))
462
37.6k
    {
463
37.6k
      if (nibs[1] & 8)
464
20.3k
  {
465
20.3k
    int field_b;
466
467
20.3k
    status = info->read_memory_func (memaddr + 2, insn, 2, info);
468
469
20.3k
    if (status != 0)
470
16
      {
471
16
        info->memory_error_func (status, memaddr + 2, info);
472
16
        return -1;
473
16
      }
474
475
20.3k
    if (info->endian == BFD_ENDIAN_LITTLE)
476
12.5k
      field_b = insn[1] << 8 | insn[0];
477
7.79k
    else
478
7.79k
      field_b = insn[0] << 8 | insn[1];
479
480
20.3k
    print_insn_ppi (field_b, info);
481
20.3k
    print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info);
482
20.3k
    return 4;
483
20.3k
  }
484
17.2k
      print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info);
485
17.2k
      return 2;
486
37.6k
    }
487
523M
  for (op = sh_table; op->name; op++)
488
522M
    {
489
522M
      int n;
490
522M
      int imm = 0;
491
522M
      int rn = 0;
492
522M
      int rm = 0;
493
522M
      int rb = 0;
494
522M
      int disp_pc;
495
522M
      bfd_vma disp_pc_addr = 0;
496
522M
      int disp = 0;
497
522M
      int has_disp = 0;
498
522M
      int max_n = SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 8 : 4;
499
500
522M
      if (!allow_op32
501
522M
    && SH_MERGE_ARCH_SET (op->arch, arch_op32))
502
10.8k
  goto fail;
503
504
522M
      if (!SH_MERGE_ARCH_SET_VALID (op->arch, target_arch))
505
194M
  goto fail;
506
422M
      for (n = 0; n < max_n; n++)
507
421M
  {
508
421M
    int i = op->nibbles[n];
509
510
421M
    if (i < 16)
511
351M
      {
512
351M
        if (nibs[n] == i)
513
50.5M
    continue;
514
300M
        goto fail;
515
351M
      }
516
70.2M
    switch (i)
517
70.2M
      {
518
46.0k
      case BRANCH_8:
519
46.0k
        imm = (nibs[2] << 4) | (nibs[3]);
520
46.0k
        if (imm & 0x80)
521
21.9k
    imm |= ~0xff;
522
46.0k
        imm = ((char) imm) * 2 + 4;
523
46.0k
        goto ok;
524
158k
      case BRANCH_12:
525
158k
        imm = ((nibs[1]) << 8) | (nibs[2] << 4) | (nibs[3]);
526
158k
        if (imm & 0x800)
527
82.1k
    imm |= ~0xfff;
528
158k
        imm = imm * 2 + 4;
529
158k
        goto ok;
530
3.48k
      case IMM0_3c:
531
3.48k
        if (nibs[3] & 0x8)
532
857
    goto fail;
533
2.62k
        imm = nibs[3] & 0x7;
534
2.62k
        break;
535
2.61k
      case IMM0_3s:
536
2.61k
        if (!(nibs[3] & 0x8))
537
1.25k
    goto fail;
538
1.36k
        imm = nibs[3] & 0x7;
539
1.36k
        break;
540
36.4k
      case IMM0_3Uc:
541
36.4k
        if (nibs[2] & 0x8)
542
15.0k
    goto fail;
543
21.4k
        imm = nibs[2] & 0x7;
544
21.4k
        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
271
      case DISP0_12:
551
2.66k
      case DISP1_12:
552
2.66k
        disp = (nibs[5] << 8) | (nibs[6] << 4) | nibs[7];
553
2.66k
        has_disp = 1;
554
2.66k
        goto ok;
555
376
      case DISP0_12BY2:
556
633
      case DISP1_12BY2:
557
633
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 1;
558
633
        relmask = ~(bfd_vma) 1;
559
633
        has_disp = 1;
560
633
        goto ok;
561
579
      case DISP0_12BY4:
562
1.87k
      case DISP1_12BY4:
563
1.87k
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 2;
564
1.87k
        relmask = ~(bfd_vma) 3;
565
1.87k
        has_disp = 1;
566
1.87k
        goto ok;
567
908
      case DISP0_12BY8:
568
2.37k
      case DISP1_12BY8:
569
2.37k
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 3;
570
2.37k
        relmask = ~(bfd_vma) 7;
571
2.37k
        has_disp = 1;
572
2.37k
        goto ok;
573
175k
      case IMM0_20_4:
574
175k
        break;
575
115k
      case IMM0_20:
576
115k
        imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8)
577
115k
         | (nibs[6] << 4) | nibs[7]);
578
115k
        if (imm & 0x80000)
579
5.46k
    imm -= 0x100000;
580
115k
        goto ok;
581
10.2k
      case IMM0_20BY8:
582
10.2k
        imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8)
583
10.2k
         | (nibs[6] << 4) | nibs[7]);
584
10.2k
        imm <<= 8;
585
10.2k
        if (imm & 0x8000000)
586
1.58k
    imm -= 0x10000000;
587
10.2k
        goto ok;
588
6.33k
      case IMM0_4:
589
20.0k
      case IMM1_4:
590
20.0k
        imm = nibs[3];
591
20.0k
        goto ok;
592
5.35k
      case IMM0_4BY2:
593
10.9k
      case IMM1_4BY2:
594
10.9k
        imm = nibs[3] << 1;
595
10.9k
        goto ok;
596
105k
      case IMM0_4BY4:
597
209k
      case IMM1_4BY4:
598
209k
        imm = nibs[3] << 2;
599
209k
        goto ok;
600
257k
      case IMM0_8S:
601
264k
      case IMM1_8:
602
264k
        imm = (nibs[2] << 4) | nibs[3];
603
264k
        disp = imm;
604
264k
        has_disp = 1;
605
264k
        if (imm & 0x80)
606
93.6k
    imm -= 0x100;
607
264k
        goto ok;
608
47.6k
      case IMM0_8U:
609
47.6k
        disp = imm = (nibs[2] << 4) | nibs[3];
610
47.6k
        has_disp = 1;
611
47.6k
        goto ok;
612
88.4k
      case PCRELIMM_8BY2:
613
88.4k
        imm = ((nibs[2] << 4) | nibs[3]) << 1;
614
88.4k
        relmask = ~(bfd_vma) 1;
615
88.4k
        goto ok;
616
96.3k
      case PCRELIMM_8BY4:
617
96.3k
        imm = ((nibs[2] << 4) | nibs[3]) << 2;
618
96.3k
        relmask = ~(bfd_vma) 3;
619
96.3k
        goto ok;
620
4.19k
      case IMM0_8BY2:
621
10.6k
      case IMM1_8BY2:
622
10.6k
        imm = ((nibs[2] << 4) | nibs[3]) << 1;
623
10.6k
        goto ok;
624
7.88k
      case IMM0_8BY4:
625
11.6k
      case IMM1_8BY4:
626
11.6k
        imm = ((nibs[2] << 4) | nibs[3]) << 2;
627
11.6k
        goto ok;
628
215k
      case REG_N_D:
629
215k
        if ((nibs[n] & 1) != 0)
630
184k
    goto fail;
631
        /* Fall through.  */
632
29.7M
      case REG_N:
633
29.7M
        rn = nibs[n];
634
29.7M
        break;
635
13.2M
      case REG_M:
636
13.2M
        rm = nibs[n];
637
13.2M
        break;
638
34.4k
      case REG_N_B01:
639
34.4k
        if ((nibs[n] & 0x3) != 1 /* binary 01 */)
640
33.3k
    goto fail;
641
1.16k
        rn = (nibs[n] & 0xc) >> 2;
642
1.16k
        break;
643
46.0k
      case REG_NM:
644
46.0k
        rn = (nibs[n] & 0xc) >> 2;
645
46.0k
        rm = (nibs[n] & 0x3);
646
46.0k
        break;
647
283k
      case REG_B:
648
283k
        if (!(nibs[n] & 0x08)) /* Must always be 1.  */
649
220k
    goto fail;
650
63.2k
        rb = nibs[n] & 0x07;
651
63.2k
        break;
652
1.39M
      case SDT_REG_N:
653
        /* sh-dsp: single data transfer.  */
654
1.39M
        rn = nibs[n];
655
1.39M
        if ((rn & 0xc) != 4)
656
1.27M
    goto fail;
657
115k
        rn = rn & 0x3;
658
115k
        rn |= (!(rn & 2)) << 2;
659
115k
        break;
660
23.1M
      case PPI:
661
23.9M
      case REPEAT:
662
23.9M
        goto fail;
663
0
      default:
664
0
        abort ();
665
70.2M
      }
666
70.2M
  }
667
668
1.91M
    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.91M
      if (target_arch == arch_sh2a
673
1.91M
    && ((op->arg[0] == DX_REG_M && (rm & 1) != 0)
674
566k
        || (op->arg[1] == DX_REG_N && (rn & 1) != 0)))
675
1.05k
  goto fail;
676
677
1.90M
      fprintf_fn (stream, "%s\t", op->name);
678
1.90M
      disp_pc = 0;
679
5.31M
      for (n = 0; n < 3 && op->arg[n] != A_END; n++)
680
3.40M
  {
681
3.40M
    if (n && op->arg[1] != A_END)
682
1.57M
      fprintf_fn (stream, ",");
683
3.40M
    switch (op->arg[n])
684
3.40M
      {
685
430k
      case A_IMM:
686
430k
        fprintf_fn (stream, "#%d", imm);
687
430k
        break;
688
103k
      case A_R0:
689
103k
        fprintf_fn (stream, "r0");
690
103k
        break;
691
1.12M
      case A_REG_N:
692
1.12M
        fprintf_fn (stream, "r%d", rn);
693
1.12M
        break;
694
37.6k
      case A_INC_N:
695
37.6k
      case AS_INC_N:
696
37.6k
        fprintf_fn (stream, "@r%d+", rn);
697
37.6k
        break;
698
39.9k
      case A_DEC_N:
699
39.9k
      case AS_DEC_N:
700
39.9k
        fprintf_fn (stream, "@-r%d", rn);
701
39.9k
        break;
702
64.0k
      case A_IND_N:
703
64.0k
      case AS_IND_N:
704
64.0k
        fprintf_fn (stream, "@r%d", rn);
705
64.0k
        break;
706
108k
      case A_DISP_REG_N:
707
108k
        fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rn);
708
108k
        break;
709
2.75k
      case AS_PMOD_N:
710
2.75k
        fprintf_fn (stream, "@r%d+r8", rn);
711
2.75k
        break;
712
518k
      case A_REG_M:
713
518k
        fprintf_fn (stream, "r%d", rm);
714
518k
        break;
715
72.3k
      case A_INC_M:
716
72.3k
        fprintf_fn (stream, "@r%d+", rm);
717
72.3k
        break;
718
611
      case A_DEC_M:
719
611
        fprintf_fn (stream, "@-r%d", rm);
720
611
        break;
721
52.5k
      case A_IND_M:
722
52.5k
        fprintf_fn (stream, "@r%d", rm);
723
52.5k
        break;
724
138k
      case A_DISP_REG_M:
725
138k
        fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rm);
726
138k
        break;
727
3.83k
      case A_REG_B:
728
3.83k
        fprintf_fn (stream, "r%d_bank", rb);
729
3.83k
        break;
730
184k
      case A_DISP_PC:
731
184k
        disp_pc = 1;
732
184k
        disp_pc_addr = imm + 4 + (memaddr & relmask);
733
184k
        (*info->print_address_func) (disp_pc_addr, info);
734
184k
        break;
735
62.3k
      case A_IND_R0_REG_N:
736
62.3k
        fprintf_fn (stream, "@(r0,r%d)", rn);
737
62.3k
        break;
738
46.9k
      case A_IND_R0_REG_M:
739
46.9k
        fprintf_fn (stream, "@(r0,r%d)", rm);
740
46.9k
        break;
741
32.7k
      case A_DISP_GBR:
742
32.7k
        fprintf_fn (stream, "@(%d,gbr)", has_disp?disp:imm);
743
32.7k
        break;
744
958
      case A_TBR:
745
958
        fprintf_fn (stream, "tbr");
746
958
        break;
747
2.91k
      case A_DISP2_TBR:
748
2.91k
        fprintf_fn (stream, "@@(%d,tbr)", has_disp?disp:imm);
749
2.91k
        break;
750
157
      case A_INC_R15:
751
157
        fprintf_fn (stream, "@r15+");
752
157
        break;
753
601
      case A_DEC_R15:
754
601
        fprintf_fn (stream, "@-r15");
755
601
        break;
756
18.9k
      case A_R0_GBR:
757
18.9k
        fprintf_fn (stream, "@(r0,gbr)");
758
18.9k
        break;
759
158k
      case A_BDISP12:
760
204k
      case A_BDISP8:
761
204k
        (*info->print_address_func) (imm + memaddr, info);
762
204k
        break;
763
12.8k
      case A_SR:
764
12.8k
        fprintf_fn (stream, "sr");
765
12.8k
        break;
766
3.56k
      case A_GBR:
767
3.56k
        fprintf_fn (stream, "gbr");
768
3.56k
        break;
769
1.30k
      case A_VBR:
770
1.30k
        fprintf_fn (stream, "vbr");
771
1.30k
        break;
772
1.24k
      case A_DSR:
773
1.24k
        fprintf_fn (stream, "dsr");
774
1.24k
        break;
775
671
      case A_MOD:
776
671
        fprintf_fn (stream, "mod");
777
671
        break;
778
723
      case A_RE:
779
723
        fprintf_fn (stream, "re");
780
723
        break;
781
617
      case A_RS:
782
617
        fprintf_fn (stream, "rs");
783
617
        break;
784
925
      case A_A0:
785
925
        fprintf_fn (stream, "a0");
786
925
        break;
787
1.01k
      case A_X0:
788
1.01k
        fprintf_fn (stream, "x0");
789
1.01k
        break;
790
530
      case A_X1:
791
530
        fprintf_fn (stream, "x1");
792
530
        break;
793
645
      case A_Y0:
794
645
        fprintf_fn (stream, "y0");
795
645
        break;
796
852
      case A_Y1:
797
852
        fprintf_fn (stream, "y1");
798
852
        break;
799
14.1k
      case DSP_REG_M:
800
14.1k
        print_dsp_reg (rm, fprintf_fn, stream);
801
14.1k
        break;
802
828
      case A_SSR:
803
828
        fprintf_fn (stream, "ssr");
804
828
        break;
805
4.74k
      case A_SPC:
806
4.74k
        fprintf_fn (stream, "spc");
807
4.74k
        break;
808
5.19k
      case A_MACH:
809
5.19k
        fprintf_fn (stream, "mach");
810
5.19k
        break;
811
1.66k
      case A_MACL:
812
1.66k
        fprintf_fn (stream, "macl");
813
1.66k
        break;
814
4.57k
      case A_PR:
815
4.57k
        fprintf_fn (stream, "pr");
816
4.57k
        break;
817
902
      case A_SGR:
818
902
        fprintf_fn (stream, "sgr");
819
902
        break;
820
532
      case A_DBR:
821
532
        fprintf_fn (stream, "dbr");
822
532
        break;
823
43.1k
      case F_REG_N:
824
43.1k
        fprintf_fn (stream, "fr%d", rn);
825
43.1k
        break;
826
42.4k
      case F_REG_M:
827
42.4k
        fprintf_fn (stream, "fr%d", rm);
828
42.4k
        break;
829
730
      case DX_REG_N:
830
730
        if (rn & 1)
831
48
    {
832
48
      fprintf_fn (stream, "xd%d", rn & ~1);
833
48
      break;
834
48
    }
835
        /* Fall through.  */
836
851
      case D_REG_N:
837
851
        fprintf_fn (stream, "dr%d", rn);
838
851
        break;
839
590
      case DX_REG_M:
840
590
        if (rm & 1)
841
455
    {
842
455
      fprintf_fn (stream, "xd%d", rm & ~1);
843
455
      break;
844
455
    }
845
        /* Fall through.  */
846
135
      case D_REG_M:
847
135
        fprintf_fn (stream, "dr%d", rm);
848
135
        break;
849
461
      case FPSCR_M:
850
897
      case FPSCR_N:
851
897
        fprintf_fn (stream, "fpscr");
852
897
        break;
853
1.35k
      case FPUL_M:
854
1.95k
      case FPUL_N:
855
1.95k
        fprintf_fn (stream, "fpul");
856
1.95k
        break;
857
3.66k
      case F_FR0:
858
3.66k
        fprintf_fn (stream, "fr0");
859
3.66k
        break;
860
1.02k
      case V_REG_N:
861
1.02k
        fprintf_fn (stream, "fv%d", rn * 4);
862
1.02k
        break;
863
99
      case V_REG_M:
864
99
        fprintf_fn (stream, "fv%d", rm * 4);
865
99
        break;
866
921
      case XMTRX_M4:
867
921
        fprintf_fn (stream, "xmtrx");
868
921
        break;
869
0
      default:
870
0
        abort ();
871
3.40M
      }
872
3.40M
  }
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.90M
      if (disp_pc && strcmp (op->name, "mova") != 0)
898
178k
  {
899
178k
    int size;
900
178k
    bfd_byte bytes[4];
901
902
178k
    if (relmask == ~(bfd_vma) 1)
903
88.4k
      size = 2;
904
90.2k
    else
905
90.2k
      size = 4;
906
    /* Not reading an instruction - disable stop_vma.  */
907
178k
    info->stop_vma = 0;
908
178k
    status = info->read_memory_func (disp_pc_addr, bytes, size, info);
909
178k
    if (status == 0)
910
168k
      {
911
168k
        unsigned int val;
912
913
168k
        if (size == 2)
914
84.1k
    {
915
84.1k
      if (info->endian == BFD_ENDIAN_LITTLE)
916
22.8k
        val = bfd_getl16 (bytes);
917
61.2k
      else
918
61.2k
        val = bfd_getb16 (bytes);
919
84.1k
    }
920
84.2k
        else
921
84.2k
    {
922
84.2k
      if (info->endian == BFD_ENDIAN_LITTLE)
923
31.1k
        val = bfd_getl32 (bytes);
924
53.0k
      else
925
53.0k
        val = bfd_getb32 (bytes);
926
84.2k
    }
927
168k
        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
156k
        else
933
156k
    fprintf_fn (stream, "\t! %x", val);
934
168k
      }
935
178k
  }
936
937
1.90M
      return SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 4 : 2;
938
521M
    fail:
939
521M
      ;
940
941
521M
    }
942
609k
  fprintf_fn (stream, ".word 0x%x%x%x%x", nibs[0], nibs[1], nibs[2], nibs[3]);
943
609k
  return 2;
944
2.51M
}