Coverage Report

Created: 2026-04-04 08:16

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
41.6k
{
37
41.6k
  int n;
38
39
41.6k
  fprintf_fn (stream, "%s\t", op->name);
40
124k
  for (n = 0; n < 2; n++)
41
83.2k
    {
42
83.2k
      switch (op->arg[n])
43
83.2k
  {
44
0
  case A_IND_N:
45
3.73k
  case AX_IND_N:
46
4.59k
  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.90k
  case AX_INC_N:
53
10.2k
  case AXY_INC_N:
54
14.4k
  case AY_INC_N:
55
15.1k
  case AYX_INC_N:
56
15.1k
    fprintf_fn (stream, "@r%d+", rn);
57
15.1k
    break;
58
4.22k
  case AX_PMOD_N:
59
4.74k
  case AXY_PMOD_N:
60
4.74k
    fprintf_fn (stream, "@r%d+r8", rn);
61
4.74k
    break;
62
6.39k
  case AY_PMOD_N:
63
7.51k
  case AYX_PMOD_N:
64
7.51k
    fprintf_fn (stream, "@r%d+r9", rn);
65
7.51k
    break;
66
19.5k
  case DSP_REG_A_M:
67
19.5k
    fprintf_fn (stream, "a%c", '0' + rm);
68
19.5k
    break;
69
10.1k
  case DSP_REG_X:
70
10.1k
    fprintf_fn (stream, "x%c", '0' + rm);
71
10.1k
    break;
72
9.51k
  case DSP_REG_Y:
73
9.51k
    fprintf_fn (stream, "y%c", '0' + rm);
74
9.51k
    break;
75
2.62k
  case DSP_REG_AX:
76
2.62k
    fprintf_fn (stream, "%c%c",
77
2.62k
          (rm & 1) ? 'x' : 'a',
78
2.62k
          (rm & 2) ? '1' : '0');
79
2.62k
    break;
80
1.08k
  case DSP_REG_XY:
81
1.08k
    fprintf_fn (stream, "%c%c",
82
1.08k
          (rm & 1) ? 'y' : 'x',
83
1.08k
          (rm & 2) ? '1' : '0');
84
1.08k
    break;
85
1.75k
  case DSP_REG_AY:
86
1.75k
    fprintf_fn (stream, "%c%c",
87
1.75k
          (rm & 2) ? 'y' : 'a',
88
1.75k
          (rm & 1) ? '1' : '0');
89
1.75k
    break;
90
876
  case DSP_REG_YX:
91
876
    fprintf_fn (stream, "%c%c",
92
876
          (rm & 2) ? 'x' : 'y',
93
876
          (rm & 1) ? '1' : '0');
94
876
    break;
95
0
  default:
96
0
    abort ();
97
83.2k
  }
98
83.2k
      if (n == 0)
99
41.6k
  fprintf_fn (stream, ",");
100
83.2k
    }
101
41.6k
}
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.5k
{
110
35.5k
  fprintf_ftype fprintf_fn = info->fprintf_func;
111
35.5k
  void *stream = info->stream;
112
113
  /* If this is just a nop, make sure to emit something.  */
114
35.5k
  if (insn == 0x000)
115
492
    {
116
492
      fprintf_fn (stream, "nopx\tnopy");
117
492
      return;
118
492
    }
119
120
  /* If a parallel processing insn was printed before,
121
     and we got a non-nop, emit a tab.  */
122
35.0k
  if ((insn & 0x800) && (insn & 0x3ff))
123
20.8k
    fprintf_fn (stream, "\t");
124
125
  /* Check if either the x or y part is invalid.  */
126
35.0k
  if (((insn & 3) != 0 && (insn & 0xc) == 0 && (insn & 0x2a0))
127
28.9k
      || ((insn & 3) == 0 && (insn & 0xc) != 0 && (insn & 0x150)))
128
12.8k
    if (info->mach != bfd_mach_sh_dsp
129
6.37k
        && info->mach != bfd_mach_sh3_dsp)
130
6.34k
      {
131
6.34k
  static const sh_opcode_info *first_movx, *first_movy;
132
6.34k
  const sh_opcode_info *op;
133
6.34k
  int is_movy;
134
135
6.34k
  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.34k
  is_movy = ((insn & 3) != 0);
144
145
6.34k
  if (is_movy)
146
2.63k
    op = first_movy;
147
3.70k
  else
148
3.70k
    op = first_movx;
149
150
52.8k
  while (op->nibbles[2] != (unsigned) ((insn >> 4) & 3)
151
12.6k
         || op->nibbles[3] != (unsigned) (insn & 0xf))
152
46.5k
    op++;
153
154
6.34k
  print_movxy (op,
155
6.34k
         (4 * ((insn & (is_movy ? 0x200 : 0x100)) == 0)
156
6.34k
          + 2 * is_movy
157
6.34k
          + 1 * ((insn & (is_movy ? 0x100 : 0x200)) != 0)),
158
6.34k
         (insn >> 6) & 3,
159
6.34k
         fprintf_fn, stream);
160
6.34k
      }
161
6.51k
    else
162
6.51k
      fprintf_fn (stream, ".word 0x%x", insn | 0xf000);
163
22.2k
  else
164
22.2k
    {
165
22.2k
      static const sh_opcode_info *first_movx, *first_movy;
166
22.2k
      const sh_opcode_info *opx, *opy;
167
22.2k
      unsigned int insn_x, insn_y;
168
169
22.2k
      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.2k
      insn_x = (insn >> 2) & 0xb;
177
22.2k
      if (insn_x)
178
18.0k
  {
179
147k
    for (opx = first_movx; opx->nibbles[2] != insn_x;)
180
129k
      opx++;
181
18.0k
    print_movxy (opx, ((insn >> 9) & 1) + 4, (insn >> 7) & 1,
182
18.0k
           fprintf_fn, stream);
183
18.0k
  }
184
22.2k
      insn_y = (insn & 3) | ((insn >> 1) & 8);
185
22.2k
      if (insn_y)
186
17.2k
  {
187
17.2k
    if (insn_x)
188
16.0k
      fprintf_fn (stream, "\t");
189
101k
    for (opy = first_movy; opy->nibbles[2] != insn_y;)
190
83.7k
      opy++;
191
17.2k
    print_movxy (opy, ((insn >> 8) & 1) + 6, (insn >> 6) & 1,
192
17.2k
           fprintf_fn, stream);
193
17.2k
  }
194
22.2k
      if (!insn_x && !insn_y && ((insn & 0x3ff) != 0 || (insn & 0x800) == 0))
195
2.28k
  fprintf_fn (stream, ".word 0x%x", insn | 0xf000);
196
22.2k
    }
197
35.0k
}
198
199
static void
200
print_dsp_reg (int rm, fprintf_ftype fprintf_fn, void *stream)
201
21.5k
{
202
21.5k
  switch (rm)
203
21.5k
    {
204
758
    case A_A1_NUM:
205
758
      fprintf_fn (stream, "a1");
206
758
      break;
207
1.28k
    case A_A0_NUM:
208
1.28k
      fprintf_fn (stream, "a0");
209
1.28k
      break;
210
1.43k
    case A_X0_NUM:
211
1.43k
      fprintf_fn (stream, "x0");
212
1.43k
      break;
213
2.02k
    case A_X1_NUM:
214
2.02k
      fprintf_fn (stream, "x1");
215
2.02k
      break;
216
1.34k
    case A_Y0_NUM:
217
1.34k
      fprintf_fn (stream, "y0");
218
1.34k
      break;
219
1.80k
    case A_Y1_NUM:
220
1.80k
      fprintf_fn (stream, "y1");
221
1.80k
      break;
222
881
    case A_M0_NUM:
223
881
      fprintf_fn (stream, "m0");
224
881
      break;
225
1.03k
    case A_A1G_NUM:
226
1.03k
      fprintf_fn (stream, "a1g");
227
1.03k
      break;
228
512
    case A_M1_NUM:
229
512
      fprintf_fn (stream, "m1");
230
512
      break;
231
3.36k
    case A_A0G_NUM:
232
3.36k
      fprintf_fn (stream, "a0g");
233
3.36k
      break;
234
7.13k
    default:
235
7.13k
      fprintf_fn (stream, "0x%x", rm);
236
7.13k
      break;
237
21.5k
    }
238
21.5k
}
239
240
static void
241
print_insn_ppi (int field_b, struct disassemble_info *info)
242
21.5k
{
243
21.5k
  static char *sx_tab[] = { "x0", "x1", "a0", "a1" };
244
21.5k
  static char *sy_tab[] = { "y0", "y1", "m0", "m1" };
245
21.5k
  fprintf_ftype fprintf_fn = info->fprintf_func;
246
21.5k
  void *stream = info->stream;
247
21.5k
  unsigned int nib1, nib2, nib3;
248
21.5k
  unsigned int altnib1, nib4;
249
21.5k
  char *dc = NULL;
250
21.5k
  const sh_opcode_info *op;
251
252
21.5k
  if ((field_b & 0xe800) == 0)
253
4.51k
    {
254
4.51k
      fprintf_fn (stream, "psh%c\t#%d,",
255
4.51k
      field_b & 0x1000 ? 'a' : 'l',
256
4.51k
      (field_b >> 4) & 127);
257
4.51k
      print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
258
4.51k
      return;
259
4.51k
    }
260
17.0k
  if ((field_b & 0xc000) == 0x4000 && (field_b & 0x3000) != 0x1000)
261
1.73k
    {
262
1.73k
      static char *du_tab[] = { "x0", "y0", "a0", "a1" };
263
1.73k
      static char *se_tab[] = { "x0", "x1", "y0", "a1" };
264
1.73k
      static char *sf_tab[] = { "y0", "y1", "x0", "a1" };
265
1.73k
      static char *sg_tab[] = { "m0", "m1", "a0", "a1" };
266
267
1.73k
      if (field_b & 0x2000)
268
924
  fprintf_fn (stream, "p%s %s,%s,%s\t",
269
924
        (field_b & 0x1000) ? "add" : "sub",
270
924
        sx_tab[(field_b >> 6) & 3],
271
924
        sy_tab[(field_b >> 4) & 3],
272
924
        du_tab[(field_b >> 0) & 3]);
273
274
812
      else if ((field_b & 0xf0) == 0x10
275
143
         && info->mach != bfd_mach_sh_dsp
276
91
         && info->mach != bfd_mach_sh3_dsp)
277
91
  fprintf_fn (stream, "pclr %s \t", du_tab[(field_b >> 0) & 3]);
278
279
721
      else if ((field_b & 0xf3) != 0)
280
622
  fprintf_fn (stream, ".word 0x%x\t", field_b);
281
282
1.73k
      fprintf_fn (stream, "pmuls%c%s,%s,%s",
283
1.73k
      field_b & 0x2000 ? ' ' : '\t',
284
1.73k
      se_tab[(field_b >> 10) & 3],
285
1.73k
      sf_tab[(field_b >>  8) & 3],
286
1.73k
      sg_tab[(field_b >>  2) & 3]);
287
1.73k
      return;
288
1.73k
    }
289
290
15.3k
  nib1 = PPIC;
291
15.3k
  nib2 = field_b >> 12 & 0xf;
292
15.3k
  nib3 = field_b >> 8 & 0xf;
293
15.3k
  nib4 = field_b >> 4 & 0xf;
294
15.3k
  switch (nib3 & 0x3)
295
15.3k
    {
296
4.49k
    case 0:
297
4.49k
      dc = "";
298
4.49k
      nib1 = PPI3;
299
4.49k
      break;
300
3.78k
    case 1:
301
3.78k
      dc = "";
302
3.78k
      break;
303
2.66k
    case 2:
304
2.66k
      dc = "dct ";
305
2.66k
      nib3 -= 1;
306
2.66k
      break;
307
4.37k
    case 3:
308
4.37k
      dc = "dcf ";
309
4.37k
      nib3 -= 2;
310
4.37k
      break;
311
15.3k
    }
312
15.3k
  if (nib1 == PPI3)
313
4.49k
    altnib1 = PPI3NC;
314
10.8k
  else
315
10.8k
    altnib1 = nib1;
316
6.10M
  for (op = sh_table; op->name; op++)
317
6.09M
    {
318
6.09M
      if ((op->nibbles[1] == nib1 || op->nibbles[1] == altnib1)
319
294k
    && op->nibbles[2] == nib2
320
19.7k
    && op->nibbles[3] == nib3)
321
9.33k
  {
322
9.33k
    int n;
323
324
9.33k
    switch (op->nibbles[4])
325
9.33k
      {
326
6.91k
      case HEX_0:
327
6.91k
        break;
328
481
      case HEX_XX00:
329
481
        if ((nib4 & 3) != 0)
330
319
    continue;
331
162
        break;
332
595
      case HEX_1:
333
595
        if ((nib4 & 3) != 1)
334
464
    continue;
335
131
        break;
336
646
      case HEX_00YY:
337
646
        if ((nib4 & 0xc) != 0)
338
499
    continue;
339
147
        break;
340
698
      case HEX_4:
341
698
        if ((nib4 & 0xc) != 4)
342
586
    continue;
343
112
        break;
344
112
      default:
345
0
        abort ();
346
9.33k
      }
347
7.46k
    fprintf_fn (stream, "%s%s\t", dc, op->name);
348
23.3k
    for (n = 0; n < 3 && op->arg[n] != A_END; n++)
349
15.8k
      {
350
15.8k
        if (n && op->arg[1] != A_END)
351
8.43k
    fprintf_fn (stream, ",");
352
15.8k
        switch (op->arg[n])
353
15.8k
    {
354
7.43k
    case DSP_REG_N:
355
7.43k
      print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
356
7.43k
      break;
357
1.81k
    case DSP_REG_X:
358
1.81k
      fprintf_fn (stream, "%s", sx_tab[(field_b >> 6) & 3]);
359
1.81k
      break;
360
5.16k
    case DSP_REG_Y:
361
5.16k
      fprintf_fn (stream, "%s", sy_tab[(field_b >> 4) & 3]);
362
5.16k
      break;
363
545
    case A_MACH:
364
545
      fprintf_fn (stream, "mach");
365
545
      break;
366
941
    case A_MACL:
367
941
      fprintf_fn (stream, "macl");
368
941
      break;
369
0
    default:
370
0
      abort ();
371
15.8k
    }
372
15.8k
      }
373
7.46k
    return;
374
7.46k
  }
375
6.09M
    }
376
  /* Not found.  */
377
7.86k
  fprintf_fn (stream, ".word 0x%x", field_b);
378
7.86k
}
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.43M
{
386
1.43M
  fprintf_ftype fprintf_fn = info->fprintf_func;
387
1.43M
  void *stream = info->stream;
388
1.43M
  unsigned char insn[4];
389
1.43M
  unsigned char nibs[8];
390
1.43M
  int status;
391
1.43M
  bfd_vma relmask = ~(bfd_vma) 0;
392
1.43M
  const sh_opcode_info *op;
393
1.43M
  unsigned int target_arch;
394
1.43M
  int allow_op32;
395
396
1.43M
  switch (info->mach)
397
1.43M
    {
398
157k
    case bfd_mach_sh:
399
157k
      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
157k
      if (info->symbols
404
0
    && bfd_asymbol_flavour(*info->symbols) == bfd_target_coff_flavour)
405
0
  target_arch = arch_sh4;
406
157k
      break;
407
1.27M
    default:
408
1.27M
      target_arch = sh_get_arch_from_bfd_mach (info->mach);
409
1.43M
    }
410
411
1.43M
  status = info->read_memory_func (memaddr, insn, 2, info);
412
413
1.43M
  if (status != 0)
414
610
    {
415
610
      info->memory_error_func (status, memaddr, info);
416
610
      return -1;
417
610
    }
418
419
1.43M
  if (info->endian == BFD_ENDIAN_LITTLE)
420
422k
    {
421
422k
      nibs[0] = (insn[1] >> 4) & 0xf;
422
422k
      nibs[1] = insn[1] & 0xf;
423
424
422k
      nibs[2] = (insn[0] >> 4) & 0xf;
425
422k
      nibs[3] = insn[0] & 0xf;
426
422k
    }
427
1.01M
  else
428
1.01M
    {
429
1.01M
      nibs[0] = (insn[0] >> 4) & 0xf;
430
1.01M
      nibs[1] = insn[0] & 0xf;
431
432
1.01M
      nibs[2] = (insn[1] >> 4) & 0xf;
433
1.01M
      nibs[3] = insn[1] & 0xf;
434
1.01M
    }
435
1.43M
  status = info->read_memory_func (memaddr + 2, insn + 2, 2, info);
436
1.43M
  if (status != 0)
437
1.39k
    allow_op32 = 0;
438
1.43M
  else
439
1.43M
    {
440
1.43M
      allow_op32 = 1;
441
442
1.43M
      if (info->endian == BFD_ENDIAN_LITTLE)
443
421k
  {
444
421k
    nibs[4] = (insn[3] >> 4) & 0xf;
445
421k
    nibs[5] = insn[3] & 0xf;
446
447
421k
    nibs[6] = (insn[2] >> 4) & 0xf;
448
421k
    nibs[7] = insn[2] & 0xf;
449
421k
  }
450
1.01M
      else
451
1.01M
  {
452
1.01M
    nibs[4] = (insn[2] >> 4) & 0xf;
453
1.01M
    nibs[5] = insn[2] & 0xf;
454
455
1.01M
    nibs[6] = (insn[3] >> 4) & 0xf;
456
1.01M
    nibs[7] = insn[3] & 0xf;
457
1.01M
  }
458
1.43M
    }
459
460
1.43M
  if (nibs[0] == 0xf && (nibs[1] & 4) == 0
461
39.6k
      && SH_MERGE_ARCH_SET_VALID (target_arch, arch_sh_dsp_up))
462
35.5k
    {
463
35.5k
      if (nibs[1] & 8)
464
21.5k
  {
465
21.5k
    int field_b;
466
467
21.5k
    status = info->read_memory_func (memaddr + 2, insn, 2, info);
468
469
21.5k
    if (status != 0)
470
19
      {
471
19
        info->memory_error_func (status, memaddr + 2, info);
472
19
        return -1;
473
19
      }
474
475
21.5k
    if (info->endian == BFD_ENDIAN_LITTLE)
476
12.5k
      field_b = insn[1] << 8 | insn[0];
477
9.07k
    else
478
9.07k
      field_b = insn[0] << 8 | insn[1];
479
480
21.5k
    print_insn_ppi (field_b, info);
481
21.5k
    print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info);
482
21.5k
    return 4;
483
21.5k
  }
484
13.9k
      print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info);
485
13.9k
      return 2;
486
35.5k
    }
487
353M
  for (op = sh_table; op->name; op++)
488
352M
    {
489
352M
      int n;
490
352M
      int imm = 0;
491
352M
      int rn = 0;
492
352M
      int rm = 0;
493
352M
      int rb = 0;
494
352M
      int disp_pc;
495
352M
      bfd_vma disp_pc_addr = 0;
496
352M
      int disp = 0;
497
352M
      int has_disp = 0;
498
352M
      int max_n = SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 8 : 4;
499
500
352M
      if (!allow_op32
501
317k
    && SH_MERGE_ARCH_SET (op->arch, arch_op32))
502
14.0k
  goto fail;
503
504
352M
      if (!SH_MERGE_ARCH_SET_VALID (op->arch, target_arch))
505
134M
  goto fail;
506
279M
      for (n = 0; n < max_n; n++)
507
279M
  {
508
279M
    int i = op->nibbles[n];
509
510
279M
    if (i < 16)
511
225M
      {
512
225M
        if (nibs[n] == i)
513
33.9M
    continue;
514
191M
        goto fail;
515
225M
      }
516
54.1M
    switch (i)
517
54.1M
      {
518
11.8k
      case BRANCH_8:
519
11.8k
        imm = (nibs[2] << 4) | (nibs[3]);
520
11.8k
        if (imm & 0x80)
521
4.67k
    imm |= ~0xff;
522
11.8k
        imm = ((char) imm) * 2 + 4;
523
11.8k
        goto ok;
524
65.1k
      case BRANCH_12:
525
65.1k
        imm = ((nibs[1]) << 8) | (nibs[2] << 4) | (nibs[3]);
526
65.1k
        if (imm & 0x800)
527
34.1k
    imm |= ~0xfff;
528
65.1k
        imm = imm * 2 + 4;
529
65.1k
        goto ok;
530
2.32k
      case IMM0_3c:
531
2.32k
        if (nibs[3] & 0x8)
532
164
    goto fail;
533
2.15k
        imm = nibs[3] & 0x7;
534
2.15k
        break;
535
2.58k
      case IMM0_3s:
536
2.58k
        if (!(nibs[3] & 0x8))
537
1.91k
    goto fail;
538
677
        imm = nibs[3] & 0x7;
539
677
        break;
540
18.6k
      case IMM0_3Uc:
541
18.6k
        if (nibs[2] & 0x8)
542
7.89k
    goto fail;
543
10.7k
        imm = nibs[2] & 0x7;
544
10.7k
        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
281
      case DISP0_12:
551
1.20k
      case DISP1_12:
552
1.20k
        disp = (nibs[5] << 8) | (nibs[6] << 4) | nibs[7];
553
1.20k
        has_disp = 1;
554
1.20k
        goto ok;
555
436
      case DISP0_12BY2:
556
582
      case DISP1_12BY2:
557
582
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 1;
558
582
        relmask = ~(bfd_vma) 1;
559
582
        has_disp = 1;
560
582
        goto ok;
561
242
      case DISP0_12BY4:
562
1.89k
      case DISP1_12BY4:
563
1.89k
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 2;
564
1.89k
        relmask = ~(bfd_vma) 3;
565
1.89k
        has_disp = 1;
566
1.89k
        goto ok;
567
519
      case DISP0_12BY8:
568
3.10k
      case DISP1_12BY8:
569
3.10k
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 3;
570
3.10k
        relmask = ~(bfd_vma) 7;
571
3.10k
        has_disp = 1;
572
3.10k
        goto ok;
573
90.4k
      case IMM0_20_4:
574
90.4k
        break;
575
58.1k
      case IMM0_20:
576
58.1k
        imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8)
577
58.1k
         | (nibs[6] << 4) | nibs[7]);
578
58.1k
        if (imm & 0x80000)
579
1.94k
    imm -= 0x100000;
580
58.1k
        goto ok;
581
5.22k
      case IMM0_20BY8:
582
5.22k
        imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8)
583
5.22k
         | (nibs[6] << 4) | nibs[7]);
584
5.22k
        imm <<= 8;
585
5.22k
        if (imm & 0x8000000)
586
737
    imm -= 0x10000000;
587
5.22k
        goto ok;
588
3.04k
      case IMM0_4:
589
10.7k
      case IMM1_4:
590
10.7k
        imm = nibs[3];
591
10.7k
        goto ok;
592
2.48k
      case IMM0_4BY2:
593
5.26k
      case IMM1_4BY2:
594
5.26k
        imm = nibs[3] << 1;
595
5.26k
        goto ok;
596
38.2k
      case IMM0_4BY4:
597
107k
      case IMM1_4BY4:
598
107k
        imm = nibs[3] << 2;
599
107k
        goto ok;
600
107k
      case IMM0_8S:
601
110k
      case IMM1_8:
602
110k
        imm = (nibs[2] << 4) | nibs[3];
603
110k
        disp = imm;
604
110k
        has_disp = 1;
605
110k
        if (imm & 0x80)
606
41.2k
    imm -= 0x100;
607
110k
        goto ok;
608
24.3k
      case IMM0_8U:
609
24.3k
        disp = imm = (nibs[2] << 4) | nibs[3];
610
24.3k
        has_disp = 1;
611
24.3k
        goto ok;
612
38.1k
      case PCRELIMM_8BY2:
613
38.1k
        imm = ((nibs[2] << 4) | nibs[3]) << 1;
614
38.1k
        relmask = ~(bfd_vma) 1;
615
38.1k
        goto ok;
616
37.0k
      case PCRELIMM_8BY4:
617
37.0k
        imm = ((nibs[2] << 4) | nibs[3]) << 2;
618
37.0k
        relmask = ~(bfd_vma) 3;
619
37.0k
        goto ok;
620
3.86k
      case IMM0_8BY2:
621
6.91k
      case IMM1_8BY2:
622
6.91k
        imm = ((nibs[2] << 4) | nibs[3]) << 1;
623
6.91k
        goto ok;
624
3.47k
      case IMM0_8BY4:
625
5.30k
      case IMM1_8BY4:
626
5.30k
        imm = ((nibs[2] << 4) | nibs[3]) << 2;
627
5.30k
        goto ok;
628
85.3k
      case REG_N_D:
629
85.3k
        if ((nibs[n] & 1) != 0)
630
75.1k
    goto fail;
631
        /* Fall through.  */
632
19.6M
      case REG_N:
633
19.6M
        rn = nibs[n];
634
19.6M
        break;
635
7.69M
      case REG_M:
636
7.69M
        rm = nibs[n];
637
7.69M
        break;
638
14.6k
      case REG_N_B01:
639
14.6k
        if ((nibs[n] & 0x3) != 1 /* binary 01 */)
640
13.8k
    goto fail;
641
738
        rn = (nibs[n] & 0xc) >> 2;
642
738
        break;
643
21.0k
      case REG_NM:
644
21.0k
        rn = (nibs[n] & 0xc) >> 2;
645
21.0k
        rm = (nibs[n] & 0x3);
646
21.0k
        break;
647
128k
      case REG_B:
648
128k
        if (!(nibs[n] & 0x08)) /* Must always be 1.  */
649
100k
    goto fail;
650
28.3k
        rb = nibs[n] & 0x07;
651
28.3k
        break;
652
1.20M
      case SDT_REG_N:
653
        /* sh-dsp: single data transfer.  */
654
1.20M
        rn = nibs[n];
655
1.20M
        if ((rn & 0xc) != 4)
656
1.13M
    goto fail;
657
73.2k
        rn = rn & 0x3;
658
73.2k
        rn |= (!(rn & 2)) << 2;
659
73.2k
        break;
660
23.8M
      case PPI:
661
24.8M
      case REPEAT:
662
24.8M
        goto fail;
663
0
      default:
664
0
        abort ();
665
54.1M
      }
666
54.1M
  }
667
668
884k
    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
884k
      if (target_arch == arch_sh2a
673
137k
    && ((op->arg[0] == DX_REG_M && (rm & 1) != 0)
674
136k
        || (op->arg[1] == DX_REG_N && (rn & 1) != 0)))
675
1.75k
  goto fail;
676
677
882k
      fprintf_fn (stream, "%s\t", op->name);
678
882k
      disp_pc = 0;
679
2.52M
      for (n = 0; n < 3 && op->arg[n] != A_END; n++)
680
1.63M
  {
681
1.63M
    if (n && op->arg[1] != A_END)
682
766k
      fprintf_fn (stream, ",");
683
1.63M
    switch (op->arg[n])
684
1.63M
      {
685
196k
      case A_IMM:
686
196k
        fprintf_fn (stream, "#%d", imm);
687
196k
        break;
688
52.7k
      case A_R0:
689
52.7k
        fprintf_fn (stream, "r0");
690
52.7k
        break;
691
528k
      case A_REG_N:
692
528k
        fprintf_fn (stream, "r%d", rn);
693
528k
        break;
694
24.5k
      case A_INC_N:
695
24.5k
      case AS_INC_N:
696
24.5k
        fprintf_fn (stream, "@r%d+", rn);
697
24.5k
        break;
698
15.0k
      case A_DEC_N:
699
15.0k
      case AS_DEC_N:
700
15.0k
        fprintf_fn (stream, "@-r%d", rn);
701
15.0k
        break;
702
28.8k
      case A_IND_N:
703
28.8k
      case AS_IND_N:
704
28.8k
        fprintf_fn (stream, "@r%d", rn);
705
28.8k
        break;
706
72.6k
      case A_DISP_REG_N:
707
72.6k
        fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rn);
708
72.6k
        break;
709
2.26k
      case AS_PMOD_N:
710
2.26k
        fprintf_fn (stream, "@r%d+r8", rn);
711
2.26k
        break;
712
276k
      case A_REG_M:
713
276k
        fprintf_fn (stream, "r%d", rm);
714
276k
        break;
715
30.2k
      case A_INC_M:
716
30.2k
        fprintf_fn (stream, "@r%d+", rm);
717
30.2k
        break;
718
284
      case A_DEC_M:
719
284
        fprintf_fn (stream, "@-r%d", rm);
720
284
        break;
721
26.0k
      case A_IND_M:
722
26.0k
        fprintf_fn (stream, "@r%d", rm);
723
26.0k
        break;
724
55.5k
      case A_DISP_REG_M:
725
55.5k
        fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rm);
726
55.5k
        break;
727
1.90k
      case A_REG_B:
728
1.90k
        fprintf_fn (stream, "r%d_bank", rb);
729
1.90k
        break;
730
75.1k
      case A_DISP_PC:
731
75.1k
        disp_pc = 1;
732
75.1k
        disp_pc_addr = imm + 4 + (memaddr & relmask);
733
75.1k
        (*info->print_address_func) (disp_pc_addr, info);
734
75.1k
        break;
735
39.1k
      case A_IND_R0_REG_N:
736
39.1k
        fprintf_fn (stream, "@(r0,r%d)", rn);
737
39.1k
        break;
738
34.7k
      case A_IND_R0_REG_M:
739
34.7k
        fprintf_fn (stream, "@(r0,r%d)", rm);
740
34.7k
        break;
741
17.0k
      case A_DISP_GBR:
742
17.0k
        fprintf_fn (stream, "@(%d,gbr)", has_disp?disp:imm);
743
17.0k
        break;
744
535
      case A_TBR:
745
535
        fprintf_fn (stream, "tbr");
746
535
        break;
747
1.12k
      case A_DISP2_TBR:
748
1.12k
        fprintf_fn (stream, "@@(%d,tbr)", has_disp?disp:imm);
749
1.12k
        break;
750
155
      case A_INC_R15:
751
155
        fprintf_fn (stream, "@r15+");
752
155
        break;
753
150
      case A_DEC_R15:
754
150
        fprintf_fn (stream, "@-r15");
755
150
        break;
756
8.87k
      case A_R0_GBR:
757
8.87k
        fprintf_fn (stream, "@(r0,gbr)");
758
8.87k
        break;
759
65.1k
      case A_BDISP12:
760
77.0k
      case A_BDISP8:
761
77.0k
        (*info->print_address_func) (imm + memaddr, info);
762
77.0k
        break;
763
8.59k
      case A_SR:
764
8.59k
        fprintf_fn (stream, "sr");
765
8.59k
        break;
766
2.34k
      case A_GBR:
767
2.34k
        fprintf_fn (stream, "gbr");
768
2.34k
        break;
769
1.28k
      case A_VBR:
770
1.28k
        fprintf_fn (stream, "vbr");
771
1.28k
        break;
772
627
      case A_DSR:
773
627
        fprintf_fn (stream, "dsr");
774
627
        break;
775
779
      case A_MOD:
776
779
        fprintf_fn (stream, "mod");
777
779
        break;
778
860
      case A_RE:
779
860
        fprintf_fn (stream, "re");
780
860
        break;
781
857
      case A_RS:
782
857
        fprintf_fn (stream, "rs");
783
857
        break;
784
1.01k
      case A_A0:
785
1.01k
        fprintf_fn (stream, "a0");
786
1.01k
        break;
787
511
      case A_X0:
788
511
        fprintf_fn (stream, "x0");
789
511
        break;
790
867
      case A_X1:
791
867
        fprintf_fn (stream, "x1");
792
867
        break;
793
917
      case A_Y0:
794
917
        fprintf_fn (stream, "y0");
795
917
        break;
796
486
      case A_Y1:
797
486
        fprintf_fn (stream, "y1");
798
486
        break;
799
9.64k
      case DSP_REG_M:
800
9.64k
        print_dsp_reg (rm, fprintf_fn, stream);
801
9.64k
        break;
802
298
      case A_SSR:
803
298
        fprintf_fn (stream, "ssr");
804
298
        break;
805
2.05k
      case A_SPC:
806
2.05k
        fprintf_fn (stream, "spc");
807
2.05k
        break;
808
3.87k
      case A_MACH:
809
3.87k
        fprintf_fn (stream, "mach");
810
3.87k
        break;
811
1.04k
      case A_MACL:
812
1.04k
        fprintf_fn (stream, "macl");
813
1.04k
        break;
814
1.38k
      case A_PR:
815
1.38k
        fprintf_fn (stream, "pr");
816
1.38k
        break;
817
795
      case A_SGR:
818
795
        fprintf_fn (stream, "sgr");
819
795
        break;
820
1.03k
      case A_DBR:
821
1.03k
        fprintf_fn (stream, "dbr");
822
1.03k
        break;
823
13.4k
      case F_REG_N:
824
13.4k
        fprintf_fn (stream, "fr%d", rn);
825
13.4k
        break;
826
13.7k
      case F_REG_M:
827
13.7k
        fprintf_fn (stream, "fr%d", rm);
828
13.7k
        break;
829
348
      case DX_REG_N:
830
348
        if (rn & 1)
831
153
    {
832
153
      fprintf_fn (stream, "xd%d", rn & ~1);
833
153
      break;
834
153
    }
835
        /* Fall through.  */
836
373
      case D_REG_N:
837
373
        fprintf_fn (stream, "dr%d", rn);
838
373
        break;
839
999
      case DX_REG_M:
840
999
        if (rm & 1)
841
753
    {
842
753
      fprintf_fn (stream, "xd%d", rm & ~1);
843
753
      break;
844
753
    }
845
        /* Fall through.  */
846
246
      case D_REG_M:
847
246
        fprintf_fn (stream, "dr%d", rm);
848
246
        break;
849
92
      case FPSCR_M:
850
119
      case FPSCR_N:
851
119
        fprintf_fn (stream, "fpscr");
852
119
        break;
853
684
      case FPUL_M:
854
844
      case FPUL_N:
855
844
        fprintf_fn (stream, "fpul");
856
844
        break;
857
1.97k
      case F_FR0:
858
1.97k
        fprintf_fn (stream, "fr0");
859
1.97k
        break;
860
799
      case V_REG_N:
861
799
        fprintf_fn (stream, "fv%d", rn * 4);
862
799
        break;
863
238
      case V_REG_M:
864
238
        fprintf_fn (stream, "fv%d", rm * 4);
865
238
        break;
866
561
      case XMTRX_M4:
867
561
        fprintf_fn (stream, "xmtrx");
868
561
        break;
869
0
      default:
870
0
        abort ();
871
1.63M
      }
872
1.63M
  }
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
882k
      if (disp_pc && strcmp (op->name, "mova") != 0)
898
73.0k
  {
899
73.0k
    int size;
900
73.0k
    bfd_byte bytes[4];
901
902
73.0k
    if (relmask == ~(bfd_vma) 1)
903
38.1k
      size = 2;
904
34.9k
    else
905
34.9k
      size = 4;
906
    /* Not reading an instruction - disable stop_vma.  */
907
73.0k
    info->stop_vma = 0;
908
73.0k
    status = info->read_memory_func (disp_pc_addr, bytes, size, info);
909
73.0k
    if (status == 0)
910
63.8k
      {
911
63.8k
        unsigned int val;
912
913
63.8k
        if (size == 2)
914
35.1k
    {
915
35.1k
      if (info->endian == BFD_ENDIAN_LITTLE)
916
10.2k
        val = bfd_getl16 (bytes);
917
24.8k
      else
918
24.8k
        val = bfd_getb16 (bytes);
919
35.1k
    }
920
28.7k
        else
921
28.7k
    {
922
28.7k
      if (info->endian == BFD_ENDIAN_LITTLE)
923
5.92k
        val = bfd_getl32 (bytes);
924
22.8k
      else
925
22.8k
        val = bfd_getb32 (bytes);
926
28.7k
    }
927
63.8k
        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
63.8k
        else
933
63.8k
    fprintf_fn (stream, "\t! %x", val);
934
63.8k
      }
935
73.0k
  }
936
937
882k
      return SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 4 : 2;
938
352M
    fail:
939
352M
      ;
940
941
352M
    }
942
516k
  fprintf_fn (stream, ".word 0x%x%x%x%x", nibs[0], nibs[1], nibs[2], nibs[3]);
943
516k
  return 2;
944
1.39M
}