Coverage Report

Created: 2024-05-21 06:29

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