Coverage Report

Created: 2026-03-10 08:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/sh-dis.c
Line
Count
Source
1
/* Disassemble SH instructions.
2
   Copyright (C) 1993-2026 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
43.3k
{
37
43.3k
  int n;
38
39
43.3k
  fprintf_fn (stream, "%s\t", op->name);
40
130k
  for (n = 0; n < 2; n++)
41
86.7k
    {
42
86.7k
      switch (op->arg[n])
43
86.7k
  {
44
0
  case A_IND_N:
45
3.78k
  case AX_IND_N:
46
4.36k
  case AXY_IND_N:
47
9.44k
  case AY_IND_N:
48
10.2k
  case AYX_IND_N:
49
10.2k
    fprintf_fn (stream, "@r%d", rn);
50
10.2k
    break;
51
0
  case A_INC_N:
52
7.96k
  case AX_INC_N:
53
10.5k
  case AXY_INC_N:
54
14.8k
  case AY_INC_N:
55
15.6k
  case AYX_INC_N:
56
15.6k
    fprintf_fn (stream, "@r%d+", rn);
57
15.6k
    break;
58
4.67k
  case AX_PMOD_N:
59
5.21k
  case AXY_PMOD_N:
60
5.21k
    fprintf_fn (stream, "@r%d+r8", rn);
61
5.21k
    break;
62
6.74k
  case AY_PMOD_N:
63
8.07k
  case AYX_PMOD_N:
64
8.07k
    fprintf_fn (stream, "@r%d+r9", rn);
65
8.07k
    break;
66
20.4k
  case DSP_REG_A_M:
67
20.4k
    fprintf_fn (stream, "a%c", '0' + rm);
68
20.4k
    break;
69
10.4k
  case DSP_REG_X:
70
10.4k
    fprintf_fn (stream, "x%c", '0' + rm);
71
10.4k
    break;
72
9.93k
  case DSP_REG_Y:
73
9.93k
    fprintf_fn (stream, "y%c", '0' + rm);
74
9.93k
    break;
75
2.84k
  case DSP_REG_AX:
76
2.84k
    fprintf_fn (stream, "%c%c",
77
2.84k
          (rm & 1) ? 'x' : 'a',
78
2.84k
          (rm & 2) ? '1' : '0');
79
2.84k
    break;
80
851
  case DSP_REG_XY:
81
851
    fprintf_fn (stream, "%c%c",
82
851
          (rm & 1) ? 'y' : 'x',
83
851
          (rm & 2) ? '1' : '0');
84
851
    break;
85
2.18k
  case DSP_REG_AY:
86
2.18k
    fprintf_fn (stream, "%c%c",
87
2.18k
          (rm & 2) ? 'y' : 'a',
88
2.18k
          (rm & 1) ? '1' : '0');
89
2.18k
    break;
90
847
  case DSP_REG_YX:
91
847
    fprintf_fn (stream, "%c%c",
92
847
          (rm & 2) ? 'x' : 'y',
93
847
          (rm & 1) ? '1' : '0');
94
847
    break;
95
0
  default:
96
0
    abort ();
97
86.7k
  }
98
86.7k
      if (n == 0)
99
43.3k
  fprintf_fn (stream, ",");
100
86.7k
    }
101
43.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
35.2k
{
110
35.2k
  fprintf_ftype fprintf_fn = info->fprintf_func;
111
35.2k
  void *stream = info->stream;
112
113
  /* If this is just a nop, make sure to emit something.  */
114
35.2k
  if (insn == 0x000)
115
521
    {
116
521
      fprintf_fn (stream, "nopx\tnopy");
117
521
      return;
118
521
    }
119
120
  /* If a parallel processing insn was printed before,
121
     and we got a non-nop, emit a tab.  */
122
34.7k
  if ((insn & 0x800) && (insn & 0x3ff))
123
21.0k
    fprintf_fn (stream, "\t");
124
125
  /* Check if either the x or y part is invalid.  */
126
34.7k
  if (((insn & 3) != 0 && (insn & 0xc) == 0 && (insn & 0x2a0))
127
29.1k
      || ((insn & 3) == 0 && (insn & 0xc) != 0 && (insn & 0x150)))
128
12.0k
    if (info->mach != bfd_mach_sh_dsp
129
6.76k
        && info->mach != bfd_mach_sh3_dsp)
130
6.72k
      {
131
6.72k
  static const sh_opcode_info *first_movx, *first_movy;
132
6.72k
  const sh_opcode_info *op;
133
6.72k
  int is_movy;
134
135
6.72k
  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
6.72k
  is_movy = ((insn & 3) != 0);
144
145
6.72k
  if (is_movy)
146
3.03k
    op = first_movy;
147
3.69k
  else
148
3.69k
    op = first_movx;
149
150
58.6k
  while (op->nibbles[2] != (unsigned) ((insn >> 4) & 3)
151
13.9k
         || op->nibbles[3] != (unsigned) (insn & 0xf))
152
51.8k
    op++;
153
154
6.72k
  print_movxy (op,
155
6.72k
         (4 * ((insn & (is_movy ? 0x200 : 0x100)) == 0)
156
6.72k
          + 2 * is_movy
157
6.72k
          + 1 * ((insn & (is_movy ? 0x100 : 0x200)) != 0)),
158
6.72k
         (insn >> 6) & 3,
159
6.72k
         fprintf_fn, stream);
160
6.72k
      }
161
5.33k
    else
162
5.33k
      fprintf_fn (stream, ".word 0x%x", insn | 0xf000);
163
22.6k
  else
164
22.6k
    {
165
22.6k
      static const sh_opcode_info *first_movx, *first_movy;
166
22.6k
      const sh_opcode_info *opx, *opy;
167
22.6k
      unsigned int insn_x, insn_y;
168
169
22.6k
      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
22.6k
      insn_x = (insn >> 2) & 0xb;
177
22.6k
      if (insn_x)
178
18.5k
  {
179
150k
    for (opx = first_movx; opx->nibbles[2] != insn_x;)
180
132k
      opx++;
181
18.5k
    print_movxy (opx, ((insn >> 9) & 1) + 4, (insn >> 7) & 1,
182
18.5k
           fprintf_fn, stream);
183
18.5k
  }
184
22.6k
      insn_y = (insn & 3) | ((insn >> 1) & 8);
185
22.6k
      if (insn_y)
186
18.0k
  {
187
18.0k
    if (insn_x)
188
16.7k
      fprintf_fn (stream, "\t");
189
107k
    for (opy = first_movy; opy->nibbles[2] != insn_y;)
190
89.5k
      opy++;
191
18.0k
    print_movxy (opy, ((insn >> 8) & 1) + 6, (insn >> 6) & 1,
192
18.0k
           fprintf_fn, stream);
193
18.0k
  }
194
22.6k
      if (!insn_x && !insn_y && ((insn & 0x3ff) != 0 || (insn & 0x800) == 0))
195
2.11k
  fprintf_fn (stream, ".word 0x%x", insn | 0xf000);
196
22.6k
    }
197
34.7k
}
198
199
static void
200
print_dsp_reg (int rm, fprintf_ftype fprintf_fn, void *stream)
201
21.7k
{
202
21.7k
  switch (rm)
203
21.7k
    {
204
661
    case A_A1_NUM:
205
661
      fprintf_fn (stream, "a1");
206
661
      break;
207
1.19k
    case A_A0_NUM:
208
1.19k
      fprintf_fn (stream, "a0");
209
1.19k
      break;
210
1.48k
    case A_X0_NUM:
211
1.48k
      fprintf_fn (stream, "x0");
212
1.48k
      break;
213
2.32k
    case A_X1_NUM:
214
2.32k
      fprintf_fn (stream, "x1");
215
2.32k
      break;
216
1.23k
    case A_Y0_NUM:
217
1.23k
      fprintf_fn (stream, "y0");
218
1.23k
      break;
219
1.76k
    case A_Y1_NUM:
220
1.76k
      fprintf_fn (stream, "y1");
221
1.76k
      break;
222
1.03k
    case A_M0_NUM:
223
1.03k
      fprintf_fn (stream, "m0");
224
1.03k
      break;
225
842
    case A_A1G_NUM:
226
842
      fprintf_fn (stream, "a1g");
227
842
      break;
228
573
    case A_M1_NUM:
229
573
      fprintf_fn (stream, "m1");
230
573
      break;
231
3.60k
    case A_A0G_NUM:
232
3.60k
      fprintf_fn (stream, "a0g");
233
3.60k
      break;
234
7.01k
    default:
235
7.01k
      fprintf_fn (stream, "0x%x", rm);
236
7.01k
      break;
237
21.7k
    }
238
21.7k
}
239
240
static void
241
print_insn_ppi (int field_b, struct disassemble_info *info)
242
21.6k
{
243
21.6k
  static char *sx_tab[] = { "x0", "x1", "a0", "a1" };
244
21.6k
  static char *sy_tab[] = { "y0", "y1", "m0", "m1" };
245
21.6k
  fprintf_ftype fprintf_fn = info->fprintf_func;
246
21.6k
  void *stream = info->stream;
247
21.6k
  unsigned int nib1, nib2, nib3;
248
21.6k
  unsigned int altnib1, nib4;
249
21.6k
  char *dc = NULL;
250
21.6k
  const sh_opcode_info *op;
251
252
21.6k
  if ((field_b & 0xe800) == 0)
253
4.19k
    {
254
4.19k
      fprintf_fn (stream, "psh%c\t#%d,",
255
4.19k
      field_b & 0x1000 ? 'a' : 'l',
256
4.19k
      (field_b >> 4) & 127);
257
4.19k
      print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
258
4.19k
      return;
259
4.19k
    }
260
17.4k
  if ((field_b & 0xc000) == 0x4000 && (field_b & 0x3000) != 0x1000)
261
1.72k
    {
262
1.72k
      static char *du_tab[] = { "x0", "y0", "a0", "a1" };
263
1.72k
      static char *se_tab[] = { "x0", "x1", "y0", "a1" };
264
1.72k
      static char *sf_tab[] = { "y0", "y1", "x0", "a1" };
265
1.72k
      static char *sg_tab[] = { "m0", "m1", "a0", "a1" };
266
267
1.72k
      if (field_b & 0x2000)
268
960
  fprintf_fn (stream, "p%s %s,%s,%s\t",
269
960
        (field_b & 0x1000) ? "add" : "sub",
270
960
        sx_tab[(field_b >> 6) & 3],
271
960
        sy_tab[(field_b >> 4) & 3],
272
960
        du_tab[(field_b >> 0) & 3]);
273
274
768
      else if ((field_b & 0xf0) == 0x10
275
79
         && info->mach != bfd_mach_sh_dsp
276
19
         && info->mach != bfd_mach_sh3_dsp)
277
19
  fprintf_fn (stream, "pclr %s \t", du_tab[(field_b >> 0) & 3]);
278
279
749
      else if ((field_b & 0xf3) != 0)
280
641
  fprintf_fn (stream, ".word 0x%x\t", field_b);
281
282
1.72k
      fprintf_fn (stream, "pmuls%c%s,%s,%s",
283
1.72k
      field_b & 0x2000 ? ' ' : '\t',
284
1.72k
      se_tab[(field_b >> 10) & 3],
285
1.72k
      sf_tab[(field_b >>  8) & 3],
286
1.72k
      sg_tab[(field_b >>  2) & 3]);
287
1.72k
      return;
288
1.72k
    }
289
290
15.7k
  nib1 = PPIC;
291
15.7k
  nib2 = field_b >> 12 & 0xf;
292
15.7k
  nib3 = field_b >> 8 & 0xf;
293
15.7k
  nib4 = field_b >> 4 & 0xf;
294
15.7k
  switch (nib3 & 0x3)
295
15.7k
    {
296
4.48k
    case 0:
297
4.48k
      dc = "";
298
4.48k
      nib1 = PPI3;
299
4.48k
      break;
300
3.85k
    case 1:
301
3.85k
      dc = "";
302
3.85k
      break;
303
2.95k
    case 2:
304
2.95k
      dc = "dct ";
305
2.95k
      nib3 -= 1;
306
2.95k
      break;
307
4.43k
    case 3:
308
4.43k
      dc = "dcf ";
309
4.43k
      nib3 -= 2;
310
4.43k
      break;
311
15.7k
    }
312
15.7k
  if (nib1 == PPI3)
313
4.48k
    altnib1 = PPI3NC;
314
11.2k
  else
315
11.2k
    altnib1 = nib1;
316
6.25M
  for (op = sh_table; op->name; op++)
317
6.24M
    {
318
6.24M
      if ((op->nibbles[1] == nib1 || op->nibbles[1] == altnib1)
319
304k
    && op->nibbles[2] == nib2
320
21.9k
    && op->nibbles[3] == nib3)
321
10.0k
  {
322
10.0k
    int n;
323
324
10.0k
    switch (op->nibbles[4])
325
10.0k
      {
326
7.14k
      case HEX_0:
327
7.14k
        break;
328
653
      case HEX_XX00:
329
653
        if ((nib4 & 3) != 0)
330
490
    continue;
331
163
        break;
332
782
      case HEX_1:
333
782
        if ((nib4 & 3) != 1)
334
546
    continue;
335
236
        break;
336
728
      case HEX_00YY:
337
728
        if ((nib4 & 0xc) != 0)
338
553
    continue;
339
175
        break;
340
776
      case HEX_4:
341
776
        if ((nib4 & 0xc) != 4)
342
665
    continue;
343
111
        break;
344
111
      default:
345
0
        abort ();
346
10.0k
      }
347
7.82k
    fprintf_fn (stream, "%s%s\t", dc, op->name);
348
24.5k
    for (n = 0; n < 3 && op->arg[n] != A_END; n++)
349
16.7k
      {
350
16.7k
        if (n && op->arg[1] != A_END)
351
8.89k
    fprintf_fn (stream, ",");
352
16.7k
        switch (op->arg[n])
353
16.7k
    {
354
7.77k
    case DSP_REG_N:
355
7.77k
      print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
356
7.77k
      break;
357
2.00k
    case DSP_REG_X:
358
2.00k
      fprintf_fn (stream, "%s", sx_tab[(field_b >> 6) & 3]);
359
2.00k
      break;
360
5.34k
    case DSP_REG_Y:
361
5.34k
      fprintf_fn (stream, "%s", sy_tab[(field_b >> 4) & 3]);
362
5.34k
      break;
363
573
    case A_MACH:
364
573
      fprintf_fn (stream, "mach");
365
573
      break;
366
1.02k
    case A_MACL:
367
1.02k
      fprintf_fn (stream, "macl");
368
1.02k
      break;
369
0
    default:
370
0
      abort ();
371
16.7k
    }
372
16.7k
      }
373
7.82k
    return;
374
7.82k
  }
375
6.24M
    }
376
  /* Not found.  */
377
7.90k
  fprintf_fn (stream, ".word 0x%x", field_b);
378
7.90k
}
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
1.50M
{
386
1.50M
  fprintf_ftype fprintf_fn = info->fprintf_func;
387
1.50M
  void *stream = info->stream;
388
1.50M
  unsigned char insn[4];
389
1.50M
  unsigned char nibs[8];
390
1.50M
  int status;
391
1.50M
  bfd_vma relmask = ~(bfd_vma) 0;
392
1.50M
  const sh_opcode_info *op;
393
1.50M
  unsigned int target_arch;
394
1.50M
  int allow_op32;
395
396
1.50M
  switch (info->mach)
397
1.50M
    {
398
204k
    case bfd_mach_sh:
399
204k
      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
204k
      if (info->symbols
404
0
    && bfd_asymbol_flavour(*info->symbols) == bfd_target_coff_flavour)
405
0
  target_arch = arch_sh4;
406
204k
      break;
407
1.29M
    default:
408
1.29M
      target_arch = sh_get_arch_from_bfd_mach (info->mach);
409
1.50M
    }
410
411
1.50M
  status = info->read_memory_func (memaddr, insn, 2, info);
412
413
1.50M
  if (status != 0)
414
695
    {
415
695
      info->memory_error_func (status, memaddr, info);
416
695
      return -1;
417
695
    }
418
419
1.50M
  if (info->endian == BFD_ENDIAN_LITTLE)
420
494k
    {
421
494k
      nibs[0] = (insn[1] >> 4) & 0xf;
422
494k
      nibs[1] = insn[1] & 0xf;
423
424
494k
      nibs[2] = (insn[0] >> 4) & 0xf;
425
494k
      nibs[3] = insn[0] & 0xf;
426
494k
    }
427
1.00M
  else
428
1.00M
    {
429
1.00M
      nibs[0] = (insn[0] >> 4) & 0xf;
430
1.00M
      nibs[1] = insn[0] & 0xf;
431
432
1.00M
      nibs[2] = (insn[1] >> 4) & 0xf;
433
1.00M
      nibs[3] = insn[1] & 0xf;
434
1.00M
    }
435
1.50M
  status = info->read_memory_func (memaddr + 2, insn + 2, 2, info);
436
1.50M
  if (status != 0)
437
1.54k
    allow_op32 = 0;
438
1.50M
  else
439
1.50M
    {
440
1.50M
      allow_op32 = 1;
441
442
1.50M
      if (info->endian == BFD_ENDIAN_LITTLE)
443
494k
  {
444
494k
    nibs[4] = (insn[3] >> 4) & 0xf;
445
494k
    nibs[5] = insn[3] & 0xf;
446
447
494k
    nibs[6] = (insn[2] >> 4) & 0xf;
448
494k
    nibs[7] = insn[2] & 0xf;
449
494k
  }
450
1.00M
      else
451
1.00M
  {
452
1.00M
    nibs[4] = (insn[2] >> 4) & 0xf;
453
1.00M
    nibs[5] = insn[2] & 0xf;
454
455
1.00M
    nibs[6] = (insn[3] >> 4) & 0xf;
456
1.00M
    nibs[7] = insn[3] & 0xf;
457
1.00M
  }
458
1.50M
    }
459
460
1.50M
  if (nibs[0] == 0xf && (nibs[1] & 4) == 0
461
39.3k
      && SH_MERGE_ARCH_SET_VALID (target_arch, arch_sh_dsp_up))
462
35.2k
    {
463
35.2k
      if (nibs[1] & 8)
464
21.6k
  {
465
21.6k
    int field_b;
466
467
21.6k
    status = info->read_memory_func (memaddr + 2, insn, 2, info);
468
469
21.6k
    if (status != 0)
470
19
      {
471
19
        info->memory_error_func (status, memaddr + 2, info);
472
19
        return -1;
473
19
      }
474
475
21.6k
    if (info->endian == BFD_ENDIAN_LITTLE)
476
12.5k
      field_b = insn[1] << 8 | insn[0];
477
9.09k
    else
478
9.09k
      field_b = insn[0] << 8 | insn[1];
479
480
21.6k
    print_insn_ppi (field_b, info);
481
21.6k
    print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info);
482
21.6k
    return 4;
483
21.6k
  }
484
13.5k
      print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info);
485
13.5k
      return 2;
486
35.2k
    }
487
373M
  for (op = sh_table; op->name; op++)
488
372M
    {
489
372M
      int n;
490
372M
      int imm = 0;
491
372M
      int rn = 0;
492
372M
      int rm = 0;
493
372M
      int rb = 0;
494
372M
      int disp_pc;
495
372M
      bfd_vma disp_pc_addr = 0;
496
372M
      int disp = 0;
497
372M
      int has_disp = 0;
498
372M
      int max_n = SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 8 : 4;
499
500
372M
      if (!allow_op32
501
357k
    && SH_MERGE_ARCH_SET (op->arch, arch_op32))
502
15.7k
  goto fail;
503
504
372M
      if (!SH_MERGE_ARCH_SET_VALID (op->arch, target_arch))
505
147M
  goto fail;
506
288M
      for (n = 0; n < max_n; n++)
507
288M
  {
508
288M
    int i = op->nibbles[n];
509
510
288M
    if (i < 16)
511
233M
      {
512
233M
        if (nibs[n] == i)
513
34.9M
    continue;
514
198M
        goto fail;
515
233M
      }
516
54.8M
    switch (i)
517
54.8M
      {
518
12.4k
      case BRANCH_8:
519
12.4k
        imm = (nibs[2] << 4) | (nibs[3]);
520
12.4k
        if (imm & 0x80)
521
4.95k
    imm |= ~0xff;
522
12.4k
        imm = ((char) imm) * 2 + 4;
523
12.4k
        goto ok;
524
67.2k
      case BRANCH_12:
525
67.2k
        imm = ((nibs[1]) << 8) | (nibs[2] << 4) | (nibs[3]);
526
67.2k
        if (imm & 0x800)
527
34.9k
    imm |= ~0xfff;
528
67.2k
        imm = imm * 2 + 4;
529
67.2k
        goto ok;
530
2.70k
      case IMM0_3c:
531
2.70k
        if (nibs[3] & 0x8)
532
135
    goto fail;
533
2.56k
        imm = nibs[3] & 0x7;
534
2.56k
        break;
535
2.76k
      case IMM0_3s:
536
2.76k
        if (!(nibs[3] & 0x8))
537
2.06k
    goto fail;
538
702
        imm = nibs[3] & 0x7;
539
702
        break;
540
17.9k
      case IMM0_3Uc:
541
17.9k
        if (nibs[2] & 0x8)
542
7.09k
    goto fail;
543
10.8k
        imm = nibs[2] & 0x7;
544
10.8k
        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
311
      case DISP0_12:
551
1.28k
      case DISP1_12:
552
1.28k
        disp = (nibs[5] << 8) | (nibs[6] << 4) | nibs[7];
553
1.28k
        has_disp = 1;
554
1.28k
        goto ok;
555
453
      case DISP0_12BY2:
556
593
      case DISP1_12BY2:
557
593
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 1;
558
593
        relmask = ~(bfd_vma) 1;
559
593
        has_disp = 1;
560
593
        goto ok;
561
256
      case DISP0_12BY4:
562
1.86k
      case DISP1_12BY4:
563
1.86k
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 2;
564
1.86k
        relmask = ~(bfd_vma) 3;
565
1.86k
        has_disp = 1;
566
1.86k
        goto ok;
567
545
      case DISP0_12BY8:
568
3.16k
      case DISP1_12BY8:
569
3.16k
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 3;
570
3.16k
        relmask = ~(bfd_vma) 7;
571
3.16k
        has_disp = 1;
572
3.16k
        goto ok;
573
89.3k
      case IMM0_20_4:
574
89.3k
        break;
575
58.5k
      case IMM0_20:
576
58.5k
        imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8)
577
58.5k
         | (nibs[6] << 4) | nibs[7]);
578
58.5k
        if (imm & 0x80000)
579
2.02k
    imm -= 0x100000;
580
58.5k
        goto ok;
581
5.51k
      case IMM0_20BY8:
582
5.51k
        imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8)
583
5.51k
         | (nibs[6] << 4) | nibs[7]);
584
5.51k
        imm <<= 8;
585
5.51k
        if (imm & 0x8000000)
586
821
    imm -= 0x10000000;
587
5.51k
        goto ok;
588
3.40k
      case IMM0_4:
589
11.6k
      case IMM1_4:
590
11.6k
        imm = nibs[3];
591
11.6k
        goto ok;
592
3.24k
      case IMM0_4BY2:
593
6.26k
      case IMM1_4BY2:
594
6.26k
        imm = nibs[3] << 1;
595
6.26k
        goto ok;
596
41.4k
      case IMM0_4BY4:
597
111k
      case IMM1_4BY4:
598
111k
        imm = nibs[3] << 2;
599
111k
        goto ok;
600
108k
      case IMM0_8S:
601
112k
      case IMM1_8:
602
112k
        imm = (nibs[2] << 4) | nibs[3];
603
112k
        disp = imm;
604
112k
        has_disp = 1;
605
112k
        if (imm & 0x80)
606
44.3k
    imm -= 0x100;
607
112k
        goto ok;
608
25.8k
      case IMM0_8U:
609
25.8k
        disp = imm = (nibs[2] << 4) | nibs[3];
610
25.8k
        has_disp = 1;
611
25.8k
        goto ok;
612
40.4k
      case PCRELIMM_8BY2:
613
40.4k
        imm = ((nibs[2] << 4) | nibs[3]) << 1;
614
40.4k
        relmask = ~(bfd_vma) 1;
615
40.4k
        goto ok;
616
38.7k
      case PCRELIMM_8BY4:
617
38.7k
        imm = ((nibs[2] << 4) | nibs[3]) << 2;
618
38.7k
        relmask = ~(bfd_vma) 3;
619
38.7k
        goto ok;
620
3.21k
      case IMM0_8BY2:
621
6.63k
      case IMM1_8BY2:
622
6.63k
        imm = ((nibs[2] << 4) | nibs[3]) << 1;
623
6.63k
        goto ok;
624
3.53k
      case IMM0_8BY4:
625
5.61k
      case IMM1_8BY4:
626
5.61k
        imm = ((nibs[2] << 4) | nibs[3]) << 2;
627
5.61k
        goto ok;
628
84.2k
      case REG_N_D:
629
84.2k
        if ((nibs[n] & 1) != 0)
630
73.2k
    goto fail;
631
        /* Fall through.  */
632
20.1M
      case REG_N:
633
20.1M
        rn = nibs[n];
634
20.1M
        break;
635
7.94M
      case REG_M:
636
7.94M
        rm = nibs[n];
637
7.94M
        break;
638
14.5k
      case REG_N_B01:
639
14.5k
        if ((nibs[n] & 0x3) != 1 /* binary 01 */)
640
14.0k
    goto fail;
641
508
        rn = (nibs[n] & 0xc) >> 2;
642
508
        break;
643
21.8k
      case REG_NM:
644
21.8k
        rn = (nibs[n] & 0xc) >> 2;
645
21.8k
        rm = (nibs[n] & 0x3);
646
21.8k
        break;
647
127k
      case REG_B:
648
127k
        if (!(nibs[n] & 0x08)) /* Must always be 1.  */
649
98.1k
    goto fail;
650
29.2k
        rb = nibs[n] & 0x07;
651
29.2k
        break;
652
1.23M
      case SDT_REG_N:
653
        /* sh-dsp: single data transfer.  */
654
1.23M
        rn = nibs[n];
655
1.23M
        if ((rn & 0xc) != 4)
656
1.16M
    goto fail;
657
74.2k
        rn = rn & 0x3;
658
74.2k
        rn |= (!(rn & 2)) << 2;
659
74.2k
        break;
660
23.6M
      case PPI:
661
24.6M
      case REPEAT:
662
24.6M
        goto fail;
663
0
      default:
664
0
        abort ();
665
54.8M
      }
666
54.8M
  }
667
668
919k
    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
919k
      if (target_arch == arch_sh2a
673
130k
    && ((op->arg[0] == DX_REG_M && (rm & 1) != 0)
674
128k
        || (op->arg[1] == DX_REG_N && (rn & 1) != 0)))
675
1.69k
  goto fail;
676
677
917k
      fprintf_fn (stream, "%s\t", op->name);
678
917k
      disp_pc = 0;
679
2.62M
      for (n = 0; n < 3 && op->arg[n] != A_END; n++)
680
1.70M
  {
681
1.70M
    if (n && op->arg[1] != A_END)
682
796k
      fprintf_fn (stream, ",");
683
1.70M
    switch (op->arg[n])
684
1.70M
      {
685
199k
      case A_IMM:
686
199k
        fprintf_fn (stream, "#%d", imm);
687
199k
        break;
688
56.4k
      case A_R0:
689
56.4k
        fprintf_fn (stream, "r0");
690
56.4k
        break;
691
547k
      case A_REG_N:
692
547k
        fprintf_fn (stream, "r%d", rn);
693
547k
        break;
694
24.8k
      case A_INC_N:
695
24.8k
      case AS_INC_N:
696
24.8k
        fprintf_fn (stream, "@r%d+", rn);
697
24.8k
        break;
698
15.9k
      case A_DEC_N:
699
15.9k
      case AS_DEC_N:
700
15.9k
        fprintf_fn (stream, "@-r%d", rn);
701
15.9k
        break;
702
29.3k
      case A_IND_N:
703
29.3k
      case AS_IND_N:
704
29.3k
        fprintf_fn (stream, "@r%d", rn);
705
29.3k
        break;
706
73.4k
      case A_DISP_REG_N:
707
73.4k
        fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rn);
708
73.4k
        break;
709
2.02k
      case AS_PMOD_N:
710
2.02k
        fprintf_fn (stream, "@r%d+r8", rn);
711
2.02k
        break;
712
293k
      case A_REG_M:
713
293k
        fprintf_fn (stream, "r%d", rm);
714
293k
        break;
715
29.9k
      case A_INC_M:
716
29.9k
        fprintf_fn (stream, "@r%d+", rm);
717
29.9k
        break;
718
372
      case A_DEC_M:
719
372
        fprintf_fn (stream, "@-r%d", rm);
720
372
        break;
721
23.2k
      case A_IND_M:
722
23.2k
        fprintf_fn (stream, "@r%d", rm);
723
23.2k
        break;
724
60.7k
      case A_DISP_REG_M:
725
60.7k
        fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rm);
726
60.7k
        break;
727
2.06k
      case A_REG_B:
728
2.06k
        fprintf_fn (stream, "r%d_bank", rb);
729
2.06k
        break;
730
79.2k
      case A_DISP_PC:
731
79.2k
        disp_pc = 1;
732
79.2k
        disp_pc_addr = imm + 4 + (memaddr & relmask);
733
79.2k
        (*info->print_address_func) (disp_pc_addr, info);
734
79.2k
        break;
735
44.8k
      case A_IND_R0_REG_N:
736
44.8k
        fprintf_fn (stream, "@(r0,r%d)", rn);
737
44.8k
        break;
738
34.9k
      case A_IND_R0_REG_M:
739
34.9k
        fprintf_fn (stream, "@(r0,r%d)", rm);
740
34.9k
        break;
741
18.0k
      case A_DISP_GBR:
742
18.0k
        fprintf_fn (stream, "@(%d,gbr)", has_disp?disp:imm);
743
18.0k
        break;
744
1.35k
      case A_TBR:
745
1.35k
        fprintf_fn (stream, "tbr");
746
1.35k
        break;
747
1.05k
      case A_DISP2_TBR:
748
1.05k
        fprintf_fn (stream, "@@(%d,tbr)", has_disp?disp:imm);
749
1.05k
        break;
750
149
      case A_INC_R15:
751
149
        fprintf_fn (stream, "@r15+");
752
149
        break;
753
163
      case A_DEC_R15:
754
163
        fprintf_fn (stream, "@-r15");
755
163
        break;
756
9.15k
      case A_R0_GBR:
757
9.15k
        fprintf_fn (stream, "@(r0,gbr)");
758
9.15k
        break;
759
67.2k
      case A_BDISP12:
760
79.7k
      case A_BDISP8:
761
79.7k
        (*info->print_address_func) (imm + memaddr, info);
762
79.7k
        break;
763
8.92k
      case A_SR:
764
8.92k
        fprintf_fn (stream, "sr");
765
8.92k
        break;
766
2.53k
      case A_GBR:
767
2.53k
        fprintf_fn (stream, "gbr");
768
2.53k
        break;
769
1.59k
      case A_VBR:
770
1.59k
        fprintf_fn (stream, "vbr");
771
1.59k
        break;
772
693
      case A_DSR:
773
693
        fprintf_fn (stream, "dsr");
774
693
        break;
775
752
      case A_MOD:
776
752
        fprintf_fn (stream, "mod");
777
752
        break;
778
595
      case A_RE:
779
595
        fprintf_fn (stream, "re");
780
595
        break;
781
837
      case A_RS:
782
837
        fprintf_fn (stream, "rs");
783
837
        break;
784
1.03k
      case A_A0:
785
1.03k
        fprintf_fn (stream, "a0");
786
1.03k
        break;
787
538
      case A_X0:
788
538
        fprintf_fn (stream, "x0");
789
538
        break;
790
1.02k
      case A_X1:
791
1.02k
        fprintf_fn (stream, "x1");
792
1.02k
        break;
793
913
      case A_Y0:
794
913
        fprintf_fn (stream, "y0");
795
913
        break;
796
823
      case A_Y1:
797
823
        fprintf_fn (stream, "y1");
798
823
        break;
799
9.75k
      case DSP_REG_M:
800
9.75k
        print_dsp_reg (rm, fprintf_fn, stream);
801
9.75k
        break;
802
338
      case A_SSR:
803
338
        fprintf_fn (stream, "ssr");
804
338
        break;
805
2.42k
      case A_SPC:
806
2.42k
        fprintf_fn (stream, "spc");
807
2.42k
        break;
808
4.38k
      case A_MACH:
809
4.38k
        fprintf_fn (stream, "mach");
810
4.38k
        break;
811
1.17k
      case A_MACL:
812
1.17k
        fprintf_fn (stream, "macl");
813
1.17k
        break;
814
1.39k
      case A_PR:
815
1.39k
        fprintf_fn (stream, "pr");
816
1.39k
        break;
817
756
      case A_SGR:
818
756
        fprintf_fn (stream, "sgr");
819
756
        break;
820
848
      case A_DBR:
821
848
        fprintf_fn (stream, "dbr");
822
848
        break;
823
14.0k
      case F_REG_N:
824
14.0k
        fprintf_fn (stream, "fr%d", rn);
825
14.0k
        break;
826
14.4k
      case F_REG_M:
827
14.4k
        fprintf_fn (stream, "fr%d", rm);
828
14.4k
        break;
829
378
      case DX_REG_N:
830
378
        if (rn & 1)
831
160
    {
832
160
      fprintf_fn (stream, "xd%d", rn & ~1);
833
160
      break;
834
160
    }
835
        /* Fall through.  */
836
390
      case D_REG_N:
837
390
        fprintf_fn (stream, "dr%d", rn);
838
390
        break;
839
1.09k
      case DX_REG_M:
840
1.09k
        if (rm & 1)
841
853
    {
842
853
      fprintf_fn (stream, "xd%d", rm & ~1);
843
853
      break;
844
853
    }
845
        /* Fall through.  */
846
242
      case D_REG_M:
847
242
        fprintf_fn (stream, "dr%d", rm);
848
242
        break;
849
88
      case FPSCR_M:
850
102
      case FPSCR_N:
851
102
        fprintf_fn (stream, "fpscr");
852
102
        break;
853
717
      case FPUL_M:
854
830
      case FPUL_N:
855
830
        fprintf_fn (stream, "fpul");
856
830
        break;
857
2.46k
      case F_FR0:
858
2.46k
        fprintf_fn (stream, "fr0");
859
2.46k
        break;
860
685
      case V_REG_N:
861
685
        fprintf_fn (stream, "fv%d", rn * 4);
862
685
        break;
863
295
      case V_REG_M:
864
295
        fprintf_fn (stream, "fv%d", rm * 4);
865
295
        break;
866
390
      case XMTRX_M4:
867
390
        fprintf_fn (stream, "xmtrx");
868
390
        break;
869
0
      default:
870
0
        abort ();
871
1.70M
      }
872
1.70M
  }
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
917k
      if (disp_pc && strcmp (op->name, "mova") != 0)
898
76.9k
  {
899
76.9k
    int size;
900
76.9k
    bfd_byte bytes[4];
901
902
76.9k
    if (relmask == ~(bfd_vma) 1)
903
40.4k
      size = 2;
904
36.4k
    else
905
36.4k
      size = 4;
906
    /* Not reading an instruction - disable stop_vma.  */
907
76.9k
    info->stop_vma = 0;
908
76.9k
    status = info->read_memory_func (disp_pc_addr, bytes, size, info);
909
76.9k
    if (status == 0)
910
67.2k
      {
911
67.2k
        unsigned int val;
912
913
67.2k
        if (size == 2)
914
36.9k
    {
915
36.9k
      if (info->endian == BFD_ENDIAN_LITTLE)
916
11.1k
        val = bfd_getl16 (bytes);
917
25.8k
      else
918
25.8k
        val = bfd_getb16 (bytes);
919
36.9k
    }
920
30.2k
        else
921
30.2k
    {
922
30.2k
      if (info->endian == BFD_ENDIAN_LITTLE)
923
6.02k
        val = bfd_getl32 (bytes);
924
24.2k
      else
925
24.2k
        val = bfd_getb32 (bytes);
926
30.2k
    }
927
67.2k
        if ((*info->symbol_at_address_func) (val, info))
928
0
    {
929
0
      fprintf_fn (stream, "\t! ");
930
0
      (*info->print_address_func) (val, info);
931
0
    }
932
67.2k
        else
933
67.2k
    fprintf_fn (stream, "\t! %x", val);
934
67.2k
      }
935
76.9k
  }
936
937
917k
      return SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 4 : 2;
938
371M
    fail:
939
371M
      ;
940
941
371M
    }
942
549k
  fprintf_fn (stream, ".word 0x%x%x%x%x", nibs[0], nibs[1], nibs[2], nibs[3]);
943
549k
  return 2;
944
1.46M
}