Coverage Report

Created: 2026-05-11 07:54

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