Coverage Report

Created: 2023-06-29 07:13

/src/binutils-gdb/opcodes/sh-dis.c
Line
Count
Source (jump to first uncovered line)
1
/* Disassemble SH instructions.
2
   Copyright (C) 1993-2023 Free Software Foundation, Inc.
3
4
   This file is part of the GNU opcodes library.
5
6
   This library is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 3, or (at your option)
9
   any later version.
10
11
   It is distributed in the hope that it will be useful, but WITHOUT
12
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
14
   License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with this file; see the file COPYING.  If not, write to the
18
   Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
19
   MA 02110-1301, USA.  */
20
21
#include "sysdep.h"
22
#include <stdio.h>
23
24
#define STATIC_TABLE
25
#define DEFINE_TABLE
26
27
#include "sh-opc.h"
28
#include "disassemble.h"
29
30
static void
31
print_movxy (const sh_opcode_info *op,
32
       int rn,
33
       int rm,
34
       fprintf_ftype fprintf_fn,
35
       void *stream)
36
51.1k
{
37
51.1k
  int n;
38
39
51.1k
  fprintf_fn (stream, "%s\t", op->name);
40
153k
  for (n = 0; n < 2; n++)
41
102k
    {
42
102k
      switch (op->arg[n])
43
102k
  {
44
0
  case A_IND_N:
45
4.29k
  case AX_IND_N:
46
5.65k
  case AXY_IND_N:
47
11.9k
  case AY_IND_N:
48
13.0k
  case AYX_IND_N:
49
13.0k
    fprintf_fn (stream, "@r%d", rn);
50
13.0k
    break;
51
0
  case A_INC_N:
52
7.23k
  case AX_INC_N:
53
11.4k
  case AXY_INC_N:
54
16.6k
  case AY_INC_N:
55
17.6k
  case AYX_INC_N:
56
17.6k
    fprintf_fn (stream, "@r%d+", rn);
57
17.6k
    break;
58
5.53k
  case AX_PMOD_N:
59
6.12k
  case AXY_PMOD_N:
60
6.12k
    fprintf_fn (stream, "@r%d+r8", rn);
61
6.12k
    break;
62
5.90k
  case AY_PMOD_N:
63
8.86k
  case AYX_PMOD_N:
64
8.86k
    fprintf_fn (stream, "@r%d+r9", rn);
65
8.86k
    break;
66
21.6k
  case DSP_REG_A_M:
67
21.6k
    fprintf_fn (stream, "a%c", '0' + rm);
68
21.6k
    break;
69
12.3k
  case DSP_REG_X:
70
12.3k
    fprintf_fn (stream, "x%c", '0' + rm);
71
12.3k
    break;
72
11.3k
  case DSP_REG_Y:
73
11.3k
    fprintf_fn (stream, "y%c", '0' + rm);
74
11.3k
    break;
75
4.68k
  case DSP_REG_AX:
76
4.68k
    fprintf_fn (stream, "%c%c",
77
4.68k
          (rm & 1) ? 'x' : 'a',
78
4.68k
          (rm & 2) ? '1' : '0');
79
4.68k
    break;
80
1.46k
  case DSP_REG_XY:
81
1.46k
    fprintf_fn (stream, "%c%c",
82
1.46k
          (rm & 1) ? 'y' : 'x',
83
1.46k
          (rm & 2) ? '1' : '0');
84
1.46k
    break;
85
3.78k
  case DSP_REG_AY:
86
3.78k
    fprintf_fn (stream, "%c%c",
87
3.78k
          (rm & 2) ? 'y' : 'a',
88
3.78k
          (rm & 1) ? '1' : '0');
89
3.78k
    break;
90
1.29k
  case DSP_REG_YX:
91
1.29k
    fprintf_fn (stream, "%c%c",
92
1.29k
          (rm & 2) ? 'x' : 'y',
93
1.29k
          (rm & 1) ? '1' : '0');
94
1.29k
    break;
95
0
  default:
96
0
    abort ();
97
102k
  }
98
102k
      if (n == 0)
99
51.1k
  fprintf_fn (stream, ",");
100
102k
    }
101
51.1k
}
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
40.8k
{
110
40.8k
  fprintf_ftype fprintf_fn = info->fprintf_func;
111
40.8k
  void *stream = info->stream;
112
113
  /* If this is just a nop, make sure to emit something.  */
114
40.8k
  if (insn == 0x000)
115
691
    {
116
691
      fprintf_fn (stream, "nopx\tnopy");
117
691
      return;
118
691
    }
119
120
  /* If a parallel processing insn was printed before,
121
     and we got a non-nop, emit a tab.  */
122
40.1k
  if ((insn & 0x800) && (insn & 0x3ff))
123
22.6k
    fprintf_fn (stream, "\t");
124
125
  /* Check if either the x or y part is invalid.  */
126
40.1k
  if (((insn & 3) != 0 && (insn & 0xc) == 0 && (insn & 0x2a0))
127
40.1k
      || ((insn & 3) == 0 && (insn & 0xc) != 0 && (insn & 0x150)))
128
15.4k
    if (info->mach != bfd_mach_sh_dsp
129
15.4k
        && info->mach != bfd_mach_sh3_dsp)
130
11.2k
      {
131
11.2k
  static const sh_opcode_info *first_movx, *first_movy;
132
11.2k
  const sh_opcode_info *op;
133
11.2k
  int is_movy;
134
135
11.2k
  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
11.2k
  is_movy = ((insn & 3) != 0);
144
145
11.2k
  if (is_movy)
146
5.07k
    op = first_movy;
147
6.14k
  else
148
6.14k
    op = first_movx;
149
150
99.8k
  while (op->nibbles[2] != (unsigned) ((insn >> 4) & 3)
151
99.8k
         || op->nibbles[3] != (unsigned) (insn & 0xf))
152
88.6k
    op++;
153
154
11.2k
  print_movxy (op,
155
11.2k
         (4 * ((insn & (is_movy ? 0x200 : 0x100)) == 0)
156
11.2k
          + 2 * is_movy
157
11.2k
          + 1 * ((insn & (is_movy ? 0x100 : 0x200)) != 0)),
158
11.2k
         (insn >> 6) & 3,
159
11.2k
         fprintf_fn, stream);
160
11.2k
      }
161
4.27k
    else
162
4.27k
      fprintf_fn (stream, ".word 0x%x", insn | 0xf000);
163
24.6k
  else
164
24.6k
    {
165
24.6k
      static const sh_opcode_info *first_movx, *first_movy;
166
24.6k
      const sh_opcode_info *opx, *opy;
167
24.6k
      unsigned int insn_x, insn_y;
168
169
24.6k
      if (! first_movx)
170
2
  {
171
542
    for (first_movx = sh_table; first_movx->nibbles[1] != MOVX;)
172
540
      first_movx++;
173
38
    for (first_movy = first_movx; first_movy->nibbles[1] != MOVY;)
174
36
      first_movy++;
175
2
  }
176
24.6k
      insn_x = (insn >> 2) & 0xb;
177
24.6k
      if (insn_x)
178
19.8k
  {
179
176k
    for (opx = first_movx; opx->nibbles[2] != insn_x;)
180
156k
      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.6k
      insn_y = (insn & 3) | ((insn >> 1) & 8);
185
24.6k
      if (insn_y)
186
20.1k
  {
187
20.1k
    if (insn_x)
188
18.9k
      fprintf_fn (stream, "\t");
189
127k
    for (opy = first_movy; opy->nibbles[2] != insn_y;)
190
107k
      opy++;
191
20.1k
    print_movxy (opy, ((insn >> 8) & 1) + 6, (insn >> 6) & 1,
192
20.1k
           fprintf_fn, stream);
193
20.1k
  }
194
24.6k
      if (!insn_x && !insn_y && ((insn & 0x3ff) != 0 || (insn & 0x800) == 0))
195
2.35k
  fprintf_fn (stream, ".word 0x%x", insn | 0xf000);
196
24.6k
    }
197
40.1k
}
198
199
static void
200
print_dsp_reg (int rm, fprintf_ftype fprintf_fn, void *stream)
201
27.3k
{
202
27.3k
  switch (rm)
203
27.3k
    {
204
964
    case A_A1_NUM:
205
964
      fprintf_fn (stream, "a1");
206
964
      break;
207
1.24k
    case A_A0_NUM:
208
1.24k
      fprintf_fn (stream, "a0");
209
1.24k
      break;
210
2.18k
    case A_X0_NUM:
211
2.18k
      fprintf_fn (stream, "x0");
212
2.18k
      break;
213
2.45k
    case A_X1_NUM:
214
2.45k
      fprintf_fn (stream, "x1");
215
2.45k
      break;
216
1.73k
    case A_Y0_NUM:
217
1.73k
      fprintf_fn (stream, "y0");
218
1.73k
      break;
219
1.51k
    case A_Y1_NUM:
220
1.51k
      fprintf_fn (stream, "y1");
221
1.51k
      break;
222
851
    case A_M0_NUM:
223
851
      fprintf_fn (stream, "m0");
224
851
      break;
225
884
    case A_A1G_NUM:
226
884
      fprintf_fn (stream, "a1g");
227
884
      break;
228
1.80k
    case A_M1_NUM:
229
1.80k
      fprintf_fn (stream, "m1");
230
1.80k
      break;
231
5.94k
    case A_A0G_NUM:
232
5.94k
      fprintf_fn (stream, "a0g");
233
5.94k
      break;
234
7.77k
    default:
235
7.77k
      fprintf_fn (stream, "0x%x", rm);
236
7.77k
      break;
237
27.3k
    }
238
27.3k
}
239
240
static void
241
print_insn_ppi (int field_b, struct disassemble_info *info)
242
23.9k
{
243
23.9k
  static char *sx_tab[] = { "x0", "x1", "a0", "a1" };
244
23.9k
  static char *sy_tab[] = { "y0", "y1", "m0", "m1" };
245
23.9k
  fprintf_ftype fprintf_fn = info->fprintf_func;
246
23.9k
  void *stream = info->stream;
247
23.9k
  unsigned int nib1, nib2, nib3;
248
23.9k
  unsigned int altnib1, nib4;
249
23.9k
  char *dc = NULL;
250
23.9k
  const sh_opcode_info *op;
251
252
23.9k
  if ((field_b & 0xe800) == 0)
253
3.82k
    {
254
3.82k
      fprintf_fn (stream, "psh%c\t#%d,",
255
3.82k
      field_b & 0x1000 ? 'a' : 'l',
256
3.82k
      (field_b >> 4) & 127);
257
3.82k
      print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
258
3.82k
      return;
259
3.82k
    }
260
20.0k
  if ((field_b & 0xc000) == 0x4000 && (field_b & 0x3000) != 0x1000)
261
2.23k
    {
262
2.23k
      static char *du_tab[] = { "x0", "y0", "a0", "a1" };
263
2.23k
      static char *se_tab[] = { "x0", "x1", "y0", "a1" };
264
2.23k
      static char *sf_tab[] = { "y0", "y1", "x0", "a1" };
265
2.23k
      static char *sg_tab[] = { "m0", "m1", "a0", "a1" };
266
267
2.23k
      if (field_b & 0x2000)
268
1.73k
  fprintf_fn (stream, "p%s %s,%s,%s\t",
269
1.73k
        (field_b & 0x1000) ? "add" : "sub",
270
1.73k
        sx_tab[(field_b >> 6) & 3],
271
1.73k
        sy_tab[(field_b >> 4) & 3],
272
1.73k
        du_tab[(field_b >> 0) & 3]);
273
274
497
      else if ((field_b & 0xf0) == 0x10
275
497
         && info->mach != bfd_mach_sh_dsp
276
497
         && info->mach != bfd_mach_sh3_dsp)
277
34
  fprintf_fn (stream, "pclr %s \t", du_tab[(field_b >> 0) & 3]);
278
279
463
      else if ((field_b & 0xf3) != 0)
280
368
  fprintf_fn (stream, ".word 0x%x\t", field_b);
281
282
2.23k
      fprintf_fn (stream, "pmuls%c%s,%s,%s",
283
2.23k
      field_b & 0x2000 ? ' ' : '\t',
284
2.23k
      se_tab[(field_b >> 10) & 3],
285
2.23k
      sf_tab[(field_b >>  8) & 3],
286
2.23k
      sg_tab[(field_b >>  2) & 3]);
287
2.23k
      return;
288
2.23k
    }
289
290
17.8k
  nib1 = PPIC;
291
17.8k
  nib2 = field_b >> 12 & 0xf;
292
17.8k
  nib3 = field_b >> 8 & 0xf;
293
17.8k
  nib4 = field_b >> 4 & 0xf;
294
17.8k
  switch (nib3 & 0x3)
295
17.8k
    {
296
5.45k
    case 0:
297
5.45k
      dc = "";
298
5.45k
      nib1 = PPI3;
299
5.45k
      break;
300
4.33k
    case 1:
301
4.33k
      dc = "";
302
4.33k
      break;
303
3.77k
    case 2:
304
3.77k
      dc = "dct ";
305
3.77k
      nib3 -= 1;
306
3.77k
      break;
307
4.30k
    case 3:
308
4.30k
      dc = "dcf ";
309
4.30k
      nib3 -= 2;
310
4.30k
      break;
311
17.8k
    }
312
17.8k
  if (nib1 == PPI3)
313
5.45k
    altnib1 = PPI3NC;
314
12.4k
  else
315
12.4k
    altnib1 = nib1;
316
7.13M
  for (op = sh_table; op->name; op++)
317
7.13M
    {
318
7.13M
      if ((op->nibbles[1] == nib1 || op->nibbles[1] == altnib1)
319
7.13M
    && op->nibbles[2] == nib2
320
7.13M
    && op->nibbles[3] == nib3)
321
11.9k
  {
322
11.9k
    int n;
323
324
11.9k
    switch (op->nibbles[4])
325
11.9k
      {
326
7.50k
      case HEX_0:
327
7.50k
        break;
328
1.77k
      case HEX_XX00:
329
1.77k
        if ((nib4 & 3) != 0)
330
1.70k
    continue;
331
67
        break;
332
1.83k
      case HEX_1:
333
1.83k
        if ((nib4 & 3) != 1)
334
1.04k
    continue;
335
799
        break;
336
799
      case HEX_00YY:
337
369
        if ((nib4 & 0xc) != 0)
338
278
    continue;
339
91
        break;
340
448
      case HEX_4:
341
448
        if ((nib4 & 0xc) != 4)
342
404
    continue;
343
44
        break;
344
44
      default:
345
0
        abort ();
346
11.9k
      }
347
8.50k
    fprintf_fn (stream, "%s%s\t", dc, op->name);
348
26.6k
    for (n = 0; n < 3 && op->arg[n] != A_END; n++)
349
18.0k
      {
350
18.0k
        if (n && op->arg[1] != A_END)
351
9.59k
    fprintf_fn (stream, ",");
352
18.0k
        switch (op->arg[n])
353
18.0k
    {
354
8.48k
    case DSP_REG_N:
355
8.48k
      print_dsp_reg (field_b & 0xf, fprintf_fn, stream);
356
8.48k
      break;
357
2.42k
    case DSP_REG_X:
358
2.42k
      fprintf_fn (stream, "%s", sx_tab[(field_b >> 6) & 3]);
359
2.42k
      break;
360
5.35k
    case DSP_REG_Y:
361
5.35k
      fprintf_fn (stream, "%s", sy_tab[(field_b >> 4) & 3]);
362
5.35k
      break;
363
639
    case A_MACH:
364
639
      fprintf_fn (stream, "mach");
365
639
      break;
366
1.19k
    case A_MACL:
367
1.19k
      fprintf_fn (stream, "macl");
368
1.19k
      break;
369
0
    default:
370
0
      abort ();
371
18.0k
    }
372
18.0k
      }
373
8.50k
    return;
374
8.50k
  }
375
7.13M
    }
376
  /* Not found.  */
377
9.35k
  fprintf_fn (stream, ".word 0x%x", field_b);
378
9.35k
}
379
380
/* FIXME mvs: movx insns print as ".word 0x%03x", insn & 0xfff
381
   (ie. the upper nibble is missing).  */
382
383
int
384
print_insn_sh (bfd_vma memaddr, struct disassemble_info *info)
385
1.80M
{
386
1.80M
  fprintf_ftype fprintf_fn = info->fprintf_func;
387
1.80M
  void *stream = info->stream;
388
1.80M
  unsigned char insn[4];
389
1.80M
  unsigned char nibs[8];
390
1.80M
  int status;
391
1.80M
  bfd_vma relmask = ~(bfd_vma) 0;
392
1.80M
  const sh_opcode_info *op;
393
1.80M
  unsigned int target_arch;
394
1.80M
  int allow_op32;
395
396
1.80M
  switch (info->mach)
397
1.80M
    {
398
236k
    case bfd_mach_sh:
399
236k
      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
236k
      if (info->symbols
404
236k
    && bfd_asymbol_flavour(*info->symbols) == bfd_target_coff_flavour)
405
595
  target_arch = arch_sh4;
406
236k
      break;
407
1.57M
    default:
408
1.57M
      target_arch = sh_get_arch_from_bfd_mach (info->mach);
409
1.80M
    }
410
411
1.80M
  status = info->read_memory_func (memaddr, insn, 2, info);
412
413
1.80M
  if (status != 0)
414
350
    {
415
350
      info->memory_error_func (status, memaddr, info);
416
350
      return -1;
417
350
    }
418
419
1.80M
  if (info->endian == BFD_ENDIAN_LITTLE)
420
951k
    {
421
951k
      nibs[0] = (insn[1] >> 4) & 0xf;
422
951k
      nibs[1] = insn[1] & 0xf;
423
424
951k
      nibs[2] = (insn[0] >> 4) & 0xf;
425
951k
      nibs[3] = insn[0] & 0xf;
426
951k
    }
427
857k
  else
428
857k
    {
429
857k
      nibs[0] = (insn[0] >> 4) & 0xf;
430
857k
      nibs[1] = insn[0] & 0xf;
431
432
857k
      nibs[2] = (insn[1] >> 4) & 0xf;
433
857k
      nibs[3] = insn[1] & 0xf;
434
857k
    }
435
1.80M
  status = info->read_memory_func (memaddr + 2, insn + 2, 2, info);
436
1.80M
  if (status != 0)
437
838
    allow_op32 = 0;
438
1.80M
  else
439
1.80M
    {
440
1.80M
      allow_op32 = 1;
441
442
1.80M
      if (info->endian == BFD_ENDIAN_LITTLE)
443
950k
  {
444
950k
    nibs[4] = (insn[3] >> 4) & 0xf;
445
950k
    nibs[5] = insn[3] & 0xf;
446
447
950k
    nibs[6] = (insn[2] >> 4) & 0xf;
448
950k
    nibs[7] = insn[2] & 0xf;
449
950k
  }
450
857k
      else
451
857k
  {
452
857k
    nibs[4] = (insn[2] >> 4) & 0xf;
453
857k
    nibs[5] = insn[2] & 0xf;
454
455
857k
    nibs[6] = (insn[3] >> 4) & 0xf;
456
857k
    nibs[7] = insn[3] & 0xf;
457
857k
  }
458
1.80M
    }
459
460
1.80M
  if (nibs[0] == 0xf && (nibs[1] & 4) == 0
461
1.80M
      && SH_MERGE_ARCH_SET_VALID (target_arch, arch_sh_dsp_up))
462
40.8k
    {
463
40.8k
      if (nibs[1] & 8)
464
23.9k
  {
465
23.9k
    int field_b;
466
467
23.9k
    status = info->read_memory_func (memaddr + 2, insn, 2, info);
468
469
23.9k
    if (status != 0)
470
13
      {
471
13
        info->memory_error_func (status, memaddr + 2, info);
472
13
        return -1;
473
13
      }
474
475
23.9k
    if (info->endian == BFD_ENDIAN_LITTLE)
476
18.3k
      field_b = insn[1] << 8 | insn[0];
477
5.61k
    else
478
5.61k
      field_b = insn[0] << 8 | insn[1];
479
480
23.9k
    print_insn_ppi (field_b, info);
481
23.9k
    print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info);
482
23.9k
    return 4;
483
23.9k
  }
484
16.9k
      print_insn_ddt ((nibs[1] << 8) | (nibs[2] << 4) | nibs[3], info);
485
16.9k
      return 2;
486
40.8k
    }
487
349M
  for (op = sh_table; op->name; op++)
488
348M
    {
489
348M
      int n;
490
348M
      int imm = 0;
491
348M
      int rn = 0;
492
348M
      int rm = 0;
493
348M
      int rb = 0;
494
348M
      int disp_pc;
495
348M
      bfd_vma disp_pc_addr = 0;
496
348M
      int disp = 0;
497
348M
      int has_disp = 0;
498
348M
      int max_n = SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 8 : 4;
499
500
348M
      if (!allow_op32
501
348M
    && SH_MERGE_ARCH_SET (op->arch, arch_op32))
502
8.06k
  goto fail;
503
504
348M
      if (!SH_MERGE_ARCH_SET_VALID (op->arch, target_arch))
505
116M
  goto fail;
506
296M
      for (n = 0; n < max_n; n++)
507
296M
  {
508
296M
    int i = op->nibbles[n];
509
510
296M
    if (i < 16)
511
245M
      {
512
245M
        if (nibs[n] == i)
513
34.5M
    continue;
514
211M
        goto fail;
515
245M
      }
516
50.4M
    switch (i)
517
50.4M
      {
518
33.6k
      case BRANCH_8:
519
33.6k
        imm = (nibs[2] << 4) | (nibs[3]);
520
33.6k
        if (imm & 0x80)
521
14.9k
    imm |= ~0xff;
522
33.6k
        imm = ((char) imm) * 2 + 4;
523
33.6k
        goto ok;
524
116k
      case BRANCH_12:
525
116k
        imm = ((nibs[1]) << 8) | (nibs[2] << 4) | (nibs[3]);
526
116k
        if (imm & 0x800)
527
61.0k
    imm |= ~0xfff;
528
116k
        imm = imm * 2 + 4;
529
116k
        goto ok;
530
3.57k
      case IMM0_3c:
531
3.57k
        if (nibs[3] & 0x8)
532
535
    goto fail;
533
3.03k
        imm = nibs[3] & 0x7;
534
3.03k
        break;
535
2.63k
      case IMM0_3s:
536
2.63k
        if (!(nibs[3] & 0x8))
537
1.76k
    goto fail;
538
872
        imm = nibs[3] & 0x7;
539
872
        break;
540
24.3k
      case IMM0_3Uc:
541
24.3k
        if (nibs[2] & 0x8)
542
9.02k
    goto fail;
543
15.2k
        imm = nibs[2] & 0x7;
544
15.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
193
      case DISP0_12:
551
2.23k
      case DISP1_12:
552
2.23k
        disp = (nibs[5] << 8) | (nibs[6] << 4) | nibs[7];
553
2.23k
        has_disp = 1;
554
2.23k
        goto ok;
555
244
      case DISP0_12BY2:
556
537
      case DISP1_12BY2:
557
537
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 1;
558
537
        relmask = ~(bfd_vma) 1;
559
537
        has_disp = 1;
560
537
        goto ok;
561
281
      case DISP0_12BY4:
562
1.02k
      case DISP1_12BY4:
563
1.02k
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 2;
564
1.02k
        relmask = ~(bfd_vma) 3;
565
1.02k
        has_disp = 1;
566
1.02k
        goto ok;
567
564
      case DISP0_12BY8:
568
1.96k
      case DISP1_12BY8:
569
1.96k
        disp = ((nibs[5] << 8) | (nibs[6] << 4) | nibs[7]) << 3;
570
1.96k
        relmask = ~(bfd_vma) 7;
571
1.96k
        has_disp = 1;
572
1.96k
        goto ok;
573
110k
      case IMM0_20_4:
574
110k
        break;
575
69.8k
      case IMM0_20:
576
69.8k
        imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8)
577
69.8k
         | (nibs[6] << 4) | nibs[7]);
578
69.8k
        if (imm & 0x80000)
579
3.52k
    imm -= 0x100000;
580
69.8k
        goto ok;
581
6.87k
      case IMM0_20BY8:
582
6.87k
        imm = ((nibs[2] << 16) | (nibs[4] << 12) | (nibs[5] << 8)
583
6.87k
         | (nibs[6] << 4) | nibs[7]);
584
6.87k
        imm <<= 8;
585
6.87k
        if (imm & 0x8000000)
586
1.04k
    imm -= 0x10000000;
587
6.87k
        goto ok;
588
3.98k
      case IMM0_4:
589
12.5k
      case IMM1_4:
590
12.5k
        imm = nibs[3];
591
12.5k
        goto ok;
592
4.24k
      case IMM0_4BY2:
593
9.20k
      case IMM1_4BY2:
594
9.20k
        imm = nibs[3] << 1;
595
9.20k
        goto ok;
596
70.6k
      case IMM0_4BY4:
597
142k
      case IMM1_4BY4:
598
142k
        imm = nibs[3] << 2;
599
142k
        goto ok;
600
181k
      case IMM0_8S:
601
186k
      case IMM1_8:
602
186k
        imm = (nibs[2] << 4) | nibs[3];
603
186k
        disp = imm;
604
186k
        has_disp = 1;
605
186k
        if (imm & 0x80)
606
68.0k
    imm -= 0x100;
607
186k
        goto ok;
608
37.0k
      case IMM0_8U:
609
37.0k
        disp = imm = (nibs[2] << 4) | nibs[3];
610
37.0k
        has_disp = 1;
611
37.0k
        goto ok;
612
61.7k
      case PCRELIMM_8BY2:
613
61.7k
        imm = ((nibs[2] << 4) | nibs[3]) << 1;
614
61.7k
        relmask = ~(bfd_vma) 1;
615
61.7k
        goto ok;
616
72.8k
      case PCRELIMM_8BY4:
617
72.8k
        imm = ((nibs[2] << 4) | nibs[3]) << 2;
618
72.8k
        relmask = ~(bfd_vma) 3;
619
72.8k
        goto ok;
620
3.32k
      case IMM0_8BY2:
621
7.65k
      case IMM1_8BY2:
622
7.65k
        imm = ((nibs[2] << 4) | nibs[3]) << 1;
623
7.65k
        goto ok;
624
4.40k
      case IMM0_8BY4:
625
8.02k
      case IMM1_8BY4:
626
8.02k
        imm = ((nibs[2] << 4) | nibs[3]) << 2;
627
8.02k
        goto ok;
628
161k
      case REG_N_D:
629
161k
        if ((nibs[n] & 1) != 0)
630
139k
    goto fail;
631
        /* Fall through.  */
632
20.3M
      case REG_N:
633
20.3M
        rn = nibs[n];
634
20.3M
        break;
635
9.32M
      case REG_M:
636
9.32M
        rm = nibs[n];
637
9.32M
        break;
638
30.0k
      case REG_N_B01:
639
30.0k
        if ((nibs[n] & 0x3) != 1 /* binary 01 */)
640
29.3k
    goto fail;
641
702
        rn = (nibs[n] & 0xc) >> 2;
642
702
        break;
643
41.7k
      case REG_NM:
644
41.7k
        rn = (nibs[n] & 0xc) >> 2;
645
41.7k
        rm = (nibs[n] & 0x3);
646
41.7k
        break;
647
201k
      case REG_B:
648
201k
        if (!(nibs[n] & 0x08)) /* Must always be 1.  */
649
151k
    goto fail;
650
49.4k
        rb = nibs[n] & 0x07;
651
49.4k
        break;
652
1.26M
      case SDT_REG_N:
653
        /* sh-dsp: single data transfer.  */
654
1.26M
        rn = nibs[n];
655
1.26M
        if ((rn & 0xc) != 4)
656
1.14M
    goto fail;
657
123k
        rn = rn & 0x3;
658
123k
        rn |= (!(rn & 2)) << 2;
659
123k
        break;
660
17.5M
      case PPI:
661
18.1M
      case REPEAT:
662
18.1M
        goto fail;
663
0
      default:
664
0
        abort ();
665
50.4M
      }
666
50.4M
  }
667
668
1.38M
    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.38M
      if (target_arch == arch_sh2a
673
1.38M
    && ((op->arg[0] == DX_REG_M && (rm & 1) != 0)
674
230k
        || (op->arg[1] == DX_REG_N && (rn & 1) != 0)))
675
661
  goto fail;
676
677
1.38M
      fprintf_fn (stream, "%s\t", op->name);
678
1.38M
      disp_pc = 0;
679
3.81M
      for (n = 0; n < 3 && op->arg[n] != A_END; n++)
680
2.43M
  {
681
2.43M
    if (n && op->arg[1] != A_END)
682
1.11M
      fprintf_fn (stream, ",");
683
2.43M
    switch (op->arg[n])
684
2.43M
      {
685
296k
      case A_IMM:
686
296k
        fprintf_fn (stream, "#%d", imm);
687
296k
        break;
688
74.3k
      case A_R0:
689
74.3k
        fprintf_fn (stream, "r0");
690
74.3k
        break;
691
797k
      case A_REG_N:
692
797k
        fprintf_fn (stream, "r%d", rn);
693
797k
        break;
694
29.3k
      case A_INC_N:
695
29.3k
      case AS_INC_N:
696
29.3k
        fprintf_fn (stream, "@r%d+", rn);
697
29.3k
        break;
698
30.2k
      case A_DEC_N:
699
30.2k
      case AS_DEC_N:
700
30.2k
        fprintf_fn (stream, "@-r%d", rn);
701
30.2k
        break;
702
48.5k
      case A_IND_N:
703
48.5k
      case AS_IND_N:
704
48.5k
        fprintf_fn (stream, "@r%d", rn);
705
48.5k
        break;
706
75.7k
      case A_DISP_REG_N:
707
75.7k
        fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rn);
708
75.7k
        break;
709
3.61k
      case AS_PMOD_N:
710
3.61k
        fprintf_fn (stream, "@r%d+r8", rn);
711
3.61k
        break;
712
369k
      case A_REG_M:
713
369k
        fprintf_fn (stream, "r%d", rm);
714
369k
        break;
715
54.6k
      case A_INC_M:
716
54.6k
        fprintf_fn (stream, "@r%d+", rm);
717
54.6k
        break;
718
221
      case A_DEC_M:
719
221
        fprintf_fn (stream, "@-r%d", rm);
720
221
        break;
721
41.7k
      case A_IND_M:
722
41.7k
        fprintf_fn (stream, "@r%d", rm);
723
41.7k
        break;
724
93.5k
      case A_DISP_REG_M:
725
93.5k
        fprintf_fn (stream, "@(%d,r%d)", has_disp?disp:imm, rm);
726
93.5k
        break;
727
3.46k
      case A_REG_B:
728
3.46k
        fprintf_fn (stream, "r%d_bank", rb);
729
3.46k
        break;
730
134k
      case A_DISP_PC:
731
134k
        disp_pc = 1;
732
134k
        disp_pc_addr = imm + 4 + (memaddr & relmask);
733
134k
        (*info->print_address_func) (disp_pc_addr, info);
734
134k
        break;
735
41.4k
      case A_IND_R0_REG_N:
736
41.4k
        fprintf_fn (stream, "@(r0,r%d)", rn);
737
41.4k
        break;
738
31.2k
      case A_IND_R0_REG_M:
739
31.2k
        fprintf_fn (stream, "@(r0,r%d)", rm);
740
31.2k
        break;
741
23.6k
      case A_DISP_GBR:
742
23.6k
        fprintf_fn (stream, "@(%d,gbr)", has_disp?disp:imm);
743
23.6k
        break;
744
821
      case A_TBR:
745
821
        fprintf_fn (stream, "tbr");
746
821
        break;
747
1.65k
      case A_DISP2_TBR:
748
1.65k
        fprintf_fn (stream, "@@(%d,tbr)", has_disp?disp:imm);
749
1.65k
        break;
750
90
      case A_INC_R15:
751
90
        fprintf_fn (stream, "@r15+");
752
90
        break;
753
731
      case A_DEC_R15:
754
731
        fprintf_fn (stream, "@-r15");
755
731
        break;
756
13.6k
      case A_R0_GBR:
757
13.6k
        fprintf_fn (stream, "@(r0,gbr)");
758
13.6k
        break;
759
116k
      case A_BDISP12:
760
150k
      case A_BDISP8:
761
150k
        (*info->print_address_func) (imm + memaddr, info);
762
150k
        break;
763
7.74k
      case A_SR:
764
7.74k
        fprintf_fn (stream, "sr");
765
7.74k
        break;
766
2.59k
      case A_GBR:
767
2.59k
        fprintf_fn (stream, "gbr");
768
2.59k
        break;
769
1.62k
      case A_VBR:
770
1.62k
        fprintf_fn (stream, "vbr");
771
1.62k
        break;
772
819
      case A_DSR:
773
819
        fprintf_fn (stream, "dsr");
774
819
        break;
775
676
      case A_MOD:
776
676
        fprintf_fn (stream, "mod");
777
676
        break;
778
895
      case A_RE:
779
895
        fprintf_fn (stream, "re");
780
895
        break;
781
746
      case A_RS:
782
746
        fprintf_fn (stream, "rs");
783
746
        break;
784
773
      case A_A0:
785
773
        fprintf_fn (stream, "a0");
786
773
        break;
787
722
      case A_X0:
788
722
        fprintf_fn (stream, "x0");
789
722
        break;
790
403
      case A_X1:
791
403
        fprintf_fn (stream, "x1");
792
403
        break;
793
581
      case A_Y0:
794
581
        fprintf_fn (stream, "y0");
795
581
        break;
796
566
      case A_Y1:
797
566
        fprintf_fn (stream, "y1");
798
566
        break;
799
15.0k
      case DSP_REG_M:
800
15.0k
        print_dsp_reg (rm, fprintf_fn, stream);
801
15.0k
        break;
802
1.04k
      case A_SSR:
803
1.04k
        fprintf_fn (stream, "ssr");
804
1.04k
        break;
805
3.98k
      case A_SPC:
806
3.98k
        fprintf_fn (stream, "spc");
807
3.98k
        break;
808
3.31k
      case A_MACH:
809
3.31k
        fprintf_fn (stream, "mach");
810
3.31k
        break;
811
1.11k
      case A_MACL:
812
1.11k
        fprintf_fn (stream, "macl");
813
1.11k
        break;
814
4.01k
      case A_PR:
815
4.01k
        fprintf_fn (stream, "pr");
816
4.01k
        break;
817
681
      case A_SGR:
818
681
        fprintf_fn (stream, "sgr");
819
681
        break;
820
548
      case A_DBR:
821
548
        fprintf_fn (stream, "dbr");
822
548
        break;
823
28.2k
      case F_REG_N:
824
28.2k
        fprintf_fn (stream, "fr%d", rn);
825
28.2k
        break;
826
27.2k
      case F_REG_M:
827
27.2k
        fprintf_fn (stream, "fr%d", rm);
828
27.2k
        break;
829
430
      case DX_REG_N:
830
430
        if (rn & 1)
831
82
    {
832
82
      fprintf_fn (stream, "xd%d", rn & ~1);
833
82
      break;
834
82
    }
835
        /* Fall through.  */
836
524
      case D_REG_N:
837
524
        fprintf_fn (stream, "dr%d", rn);
838
524
        break;
839
871
      case DX_REG_M:
840
871
        if (rm & 1)
841
667
    {
842
667
      fprintf_fn (stream, "xd%d", rm & ~1);
843
667
      break;
844
667
    }
845
        /* Fall through.  */
846
204
      case D_REG_M:
847
204
        fprintf_fn (stream, "dr%d", rm);
848
204
        break;
849
1.47k
      case FPSCR_M:
850
1.67k
      case FPSCR_N:
851
1.67k
        fprintf_fn (stream, "fpscr");
852
1.67k
        break;
853
933
      case FPUL_M:
854
1.31k
      case FPUL_N:
855
1.31k
        fprintf_fn (stream, "fpul");
856
1.31k
        break;
857
3.30k
      case F_FR0:
858
3.30k
        fprintf_fn (stream, "fr0");
859
3.30k
        break;
860
573
      case V_REG_N:
861
573
        fprintf_fn (stream, "fv%d", rn * 4);
862
573
        break;
863
96
      case V_REG_M:
864
96
        fprintf_fn (stream, "fv%d", rm * 4);
865
96
        break;
866
477
      case XMTRX_M4:
867
477
        fprintf_fn (stream, "xmtrx");
868
477
        break;
869
0
      default:
870
0
        abort ();
871
2.43M
      }
872
2.43M
  }
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.38M
      if (disp_pc && strcmp (op->name, "mova") != 0)
898
131k
  {
899
131k
    int size;
900
131k
    bfd_byte bytes[4];
901
902
131k
    if (relmask == ~(bfd_vma) 1)
903
61.7k
      size = 2;
904
69.3k
    else
905
69.3k
      size = 4;
906
    /* Not reading an instruction - disable stop_vma.  */
907
131k
    info->stop_vma = 0;
908
131k
    status = info->read_memory_func (disp_pc_addr, bytes, size, info);
909
131k
    if (status == 0)
910
122k
      {
911
122k
        unsigned int val;
912
913
122k
        if (size == 2)
914
58.7k
    {
915
58.7k
      if (info->endian == BFD_ENDIAN_LITTLE)
916
23.2k
        val = bfd_getl16 (bytes);
917
35.5k
      else
918
35.5k
        val = bfd_getb16 (bytes);
919
58.7k
    }
920
63.9k
        else
921
63.9k
    {
922
63.9k
      if (info->endian == BFD_ENDIAN_LITTLE)
923
33.6k
        val = bfd_getl32 (bytes);
924
30.3k
      else
925
30.3k
        val = bfd_getb32 (bytes);
926
63.9k
    }
927
122k
        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
111k
        else
933
111k
    fprintf_fn (stream, "\t! %x", val);
934
122k
      }
935
131k
  }
936
937
1.38M
      return SH_MERGE_ARCH_SET (op->arch, arch_op32) ? 4 : 2;
938
347M
    fail:
939
347M
      ;
940
941
347M
    }
942
384k
  fprintf_fn (stream, ".word 0x%x%x%x%x", nibs[0], nibs[1], nibs[2], nibs[3]);
943
384k
  return 2;
944
1.76M
}