Coverage Report

Created: 2026-03-10 08:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/h8300-dis.c
Line
Count
Source
1
/* Disassemble h8300 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 program; if not, write to the Free Software
18
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19
   MA 02110-1301, USA.  */
20
21
#define DEFINE_TABLE
22
23
#include "sysdep.h"
24
4
#define h8_opcodes h8ops
25
#include "opcode/h8300.h"
26
#include "disassemble.h"
27
#include "opintl.h"
28
#include "libiberty.h"
29
30
struct h8_instruction
31
{
32
  unsigned int length;
33
  const struct h8_opcode *opcode;
34
};
35
36
struct h8_instruction *h8_instructions;
37
38
/* Run through the opcodes and sort them into order to make them easy
39
   to disassemble.  */
40
41
static void
42
bfd_h8_disassemble_init (void)
43
2
{
44
2
  unsigned int i;
45
2
  unsigned int nopcodes;
46
2
  const struct h8_opcode *p;
47
2
  struct h8_instruction *pi;
48
49
2
  nopcodes = sizeof (h8_opcodes) / sizeof (struct h8_opcode);
50
51
2
  h8_instructions = xmalloc (nopcodes * sizeof (struct h8_instruction));
52
53
16.9k
  for (p = h8_opcodes, pi = h8_instructions; p->name; p++, pi++)
54
16.9k
    {
55
      /* Just make sure there are an even number of nibbles in it, and
56
   that the count is the same as the length.  */
57
299k
      for (i = 0; p->data.nib[i] != (op_type) E; i++)
58
282k
  ;
59
16.9k
      OPCODES_ASSERT (!(i & 1));
60
61
16.9k
      pi->length = i / 2;
62
16.9k
      pi->opcode = p;
63
16.9k
    }
64
65
  /* Add entry for the NULL vector terminator.  */
66
2
  pi->length = 0;
67
2
  pi->opcode = p;
68
2
}
69
70
static void
71
extract_immediate (FILE *stream,
72
       op_type looking_for,
73
       int thisnib,
74
       unsigned char *data,
75
       int *cst,
76
       int *len,
77
       const struct h8_opcode *q)
78
204k
{
79
204k
  switch (looking_for & SIZE)
80
204k
    {
81
56.4k
    case L_2:
82
56.4k
      *len = 2;
83
56.4k
      *cst = thisnib & 3;
84
85
      /* DISP2 special treatment.  */
86
56.4k
      if ((looking_for & MODE) == DISP)
87
56.4k
  {
88
56.4k
    if (OP_KIND (q->how) == O_MOVAB
89
56.2k
        || OP_KIND (q->how) == O_MOVAW
90
56.0k
        || OP_KIND (q->how) == O_MOVAL)
91
560
      {
92
        /* Handling for mova insn.  */
93
560
        switch (q->args.nib[0] & MODE)
94
560
    {
95
129
    case INDEXB:
96
129
    default:
97
129
      break;
98
431
    case INDEXW:
99
431
      *cst *= 2;
100
431
      break;
101
0
    case INDEXL:
102
0
      *cst *= 4;
103
0
      break;
104
560
    }
105
560
      }
106
55.8k
    else
107
55.8k
      {
108
        /* Handling for non-mova insn.  */
109
55.8k
        switch (OP_SIZE (q->how))
110
55.8k
    {
111
5.77k
    default: break;
112
9.21k
    case SW:
113
9.21k
      *cst *= 2;
114
9.21k
      break;
115
40.8k
    case SL:
116
40.8k
      *cst *= 4;
117
40.8k
      break;
118
55.8k
    }
119
55.8k
      }
120
56.4k
  }
121
56.4k
      break;
122
140k
    case L_8:
123
140k
      *len = 8;
124
140k
      *cst = data[0];
125
140k
      break;
126
2.87k
    case L_16:
127
3.68k
    case L_16U:
128
3.68k
      *len = 16;
129
3.68k
      *cst = (data[0] << 8) + data [1];
130
#if 0
131
      if ((looking_for & SIZE) == L_16)
132
  *cst = (short) *cst;  /* Sign extend.  */
133
#endif
134
3.68k
      break;
135
3.57k
    case L_32:
136
3.57k
      *len = 32;
137
3.57k
      *cst = (((unsigned) data[0] << 24) + (data[1] << 16)
138
3.57k
        + (data[2] << 8) + data[3]);
139
3.57k
      break;
140
0
    default:
141
0
      *len = 0;
142
0
      *cst = 0;
143
0
      fprintf (stream, "DISP bad size\n");
144
0
      break;
145
204k
    }
146
204k
}
147
148
static const char *regnames[] =
149
{
150
  "r0h", "r1h", "r2h", "r3h", "r4h", "r5h", "r6h", "r7h",
151
  "r0l", "r1l", "r2l", "r3l", "r4l", "r5l", "r6l", "r7l"
152
};
153
static const char *wregnames[] =
154
{
155
  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
156
  "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7"
157
};
158
static const char *lregnames[] =
159
{
160
  "er0", "er1", "er2", "er3", "er4", "er5", "er6", "er7",
161
  "er0", "er1", "er2", "er3", "er4", "er5", "er6", "er7"
162
};
163
static const char *cregnames[] =
164
{
165
  "ccr", "exr", "mach", "macl", "", "", "vbr", "sbr"
166
};
167
168
static void
169
print_one_arg (disassemble_info *info,
170
         bfd_vma addr,
171
         op_type x,
172
         int cst,
173
         int cstlen,
174
         int rdisp_n,
175
         int rn,
176
         const char **pregnames,
177
         int len)
178
394k
{
179
394k
  void * stream = info->stream;
180
394k
  fprintf_ftype outfn = info->fprintf_func;
181
182
394k
  if ((x & SIZE) == L_3 || (x & SIZE) == L_3NZ)
183
13.1k
    outfn (stream, "#0x%x", (unsigned) cst);
184
381k
  else if ((x & MODE) == IMM)
185
103k
    outfn (stream, "#0x%x", (unsigned) cst);
186
277k
  else if ((x & MODE) == DBIT || (x & MODE) == KBIT)
187
377
    outfn (stream, "#%d", (unsigned) cst);
188
277k
  else if ((x & MODE) == CONST_2)
189
909
    outfn (stream, "#2");
190
276k
  else if ((x & MODE) == CONST_4)
191
248
    outfn (stream, "#4");
192
276k
  else if ((x & MODE) == CONST_8)
193
355
    outfn (stream, "#8");
194
275k
  else if ((x & MODE) == CONST_16)
195
219
    outfn (stream, "#16");
196
275k
  else if ((x & MODE) == REG)
197
208k
    {
198
208k
      switch (x & SIZE)
199
208k
  {
200
178k
  case L_8:
201
178k
    outfn (stream, "%s", regnames[rn]);
202
178k
    break;
203
24.8k
  case L_16:
204
24.8k
  case L_16U:
205
24.8k
    outfn (stream, "%s", wregnames[rn]);
206
24.8k
    break;
207
0
  case L_P:
208
4.85k
  case L_32:
209
4.85k
    outfn (stream, "%s", lregnames[rn]);
210
4.85k
    break;
211
208k
  }
212
208k
    }
213
67.2k
  else if ((x & MODE) == LOWREG)
214
267
    {
215
267
      switch (x & SIZE)
216
267
  {
217
180
  case L_8:
218
    /* Always take low half of reg.  */
219
180
    outfn (stream, "%s.b", regnames[rn < 8 ? rn + 8 : rn]);
220
180
    break;
221
87
  case L_16:
222
87
  case L_16U:
223
    /* Always take low half of reg.  */
224
87
    outfn (stream, "%s.w", wregnames[rn < 8 ? rn : rn - 8]);
225
87
    break;
226
0
  case L_P:
227
0
  case L_32:
228
0
    outfn (stream, "%s.l", lregnames[rn]);
229
0
    break;
230
267
  }
231
267
    }
232
67.0k
  else if ((x & MODE) == POSTINC)
233
2.08k
    outfn (stream, "@%s+", pregnames[rn]);
234
235
64.9k
  else if ((x & MODE) == POSTDEC)
236
68
    outfn (stream, "@%s-", pregnames[rn]);
237
238
64.8k
  else if ((x & MODE) == PREINC)
239
104
    outfn (stream, "@+%s", pregnames[rn]);
240
241
64.7k
  else if ((x & MODE) == PREDEC)
242
380
    outfn (stream, "@-%s", pregnames[rn]);
243
244
64.3k
  else if ((x & MODE) == IND)
245
2.99k
    outfn (stream, "@%s", pregnames[rn]);
246
247
61.3k
  else if ((x & MODE) == ABS || (x & ABSJMP))
248
35.3k
    outfn (stream, "@0x%x:%d", (unsigned) cst, cstlen);
249
250
26.0k
  else if ((x & MODE) == MEMIND)
251
1.97k
    outfn (stream, "@@%d (0x%x)", cst, cst);
252
253
24.0k
  else if ((x & MODE) == VECIND)
254
1.48k
    {
255
      /* FIXME Multiplier should be 2 or 4, depending on processor mode,
256
   by which is meant "normal" vs. "middle", "advanced", "maximum".  */
257
258
1.48k
      int offset = (cst + 0x80) * 4;
259
1.48k
      outfn (stream, "@@%d (0x%x)", offset, offset);
260
1.48k
    }
261
22.5k
  else if ((x & MODE) == PCREL)
262
8.07k
    {
263
8.07k
      if ((x & SIZE) == L_16 ||
264
7.99k
    (x & SIZE) == L_16U)
265
80
  {
266
80
    outfn (stream, ".%s%d (0x%lx)",
267
80
       (short) cst > 0 ? "+" : "",
268
80
       (short) cst,
269
80
       (long)(addr + (short) cst + len));
270
80
  }
271
7.99k
      else
272
7.99k
  {
273
7.99k
    outfn (stream, ".%s%d (0x%lx)",
274
7.99k
       (char) cst > 0 ? "+" : "",
275
7.99k
       (char) cst,
276
7.99k
       (long)(addr + (char) cst + len));
277
7.99k
  }
278
8.07k
    }
279
14.4k
  else if ((x & MODE) == DISP)
280
2.57k
    outfn (stream, "@(0x%x:%d,%s)", cst, cstlen, pregnames[rdisp_n]);
281
282
11.9k
  else if ((x & MODE) == INDEXB)
283
    /* Always take low half of reg.  */
284
151
    outfn (stream, "@(0x%x:%d,%s.b)", cst, cstlen,
285
151
     regnames[rdisp_n < 8 ? rdisp_n + 8 : rdisp_n]);
286
287
11.7k
  else if ((x & MODE) == INDEXW)
288
    /* Always take low half of reg.  */
289
47
    outfn (stream, "@(0x%x:%d,%s.w)", cst, cstlen,
290
47
     wregnames[rdisp_n < 8 ? rdisp_n : rdisp_n - 8]);
291
292
11.7k
  else if ((x & MODE) == INDEXL)
293
88
    outfn (stream, "@(0x%x:%d,%s.l)", cst, cstlen, lregnames[rdisp_n]);
294
295
11.6k
  else if (x & CTRL)
296
11.6k
    outfn (stream, "%s", cregnames[rn]);
297
298
0
  else if ((x & MODE) == CCR)
299
0
    outfn (stream, "ccr");
300
301
0
  else if ((x & MODE) == EXR)
302
0
    outfn (stream, "exr");
303
304
0
  else if ((x & MODE) == MACREG)
305
0
    outfn (stream, "mac%c", cst ? 'l' : 'h');
306
307
0
  else
308
    /* xgettext:c-format */
309
0
    outfn (stream, _("Hmmmm 0x%x"), x);
310
394k
}
311
312
static unsigned int
313
bfd_h8_disassemble (bfd_vma addr, disassemble_info *info, int mach)
314
309k
{
315
  /* Find the first entry in the table for this opcode.  */
316
309k
  int regno[3] = { 0, 0, 0 };
317
309k
  int dispregno[3] = { 0, 0, 0 };
318
309k
  int cst[3] = { 0, 0, 0 };
319
309k
  int cstlen[3] = { 0, 0, 0 };
320
309k
  static bool init = 0;
321
309k
  const struct h8_instruction *qi;
322
309k
  char const **pregnames = mach != 0 ? lregnames : wregnames;
323
309k
  int status;
324
309k
  unsigned int maxlen;
325
309k
  unsigned char data[MAX_CODE_NIBBLES / 2];
326
309k
  void *stream = info->stream;
327
309k
  fprintf_ftype outfn = info->fprintf_func;
328
329
309k
  if (!init)
330
2
    {
331
2
      bfd_h8_disassemble_init ();
332
2
      init = 1;
333
2
    }
334
335
309k
  status = info->read_memory_func (addr, data, 2, info);
336
309k
  if (status != 0)
337
142
    {
338
142
      info->memory_error_func (status, addr, info);
339
142
      return -1;
340
142
    }
341
342
2.46M
  for (maxlen = 2; maxlen < sizeof (data); maxlen += 2)
343
2.15M
    {
344
2.15M
      status = info->read_memory_func (addr + maxlen, data + maxlen, 2, info);
345
2.15M
      if (status != 0)
346
2.55k
  break;
347
2.15M
    }
348
349
  /* Find the exact opcode/arg combo.  */
350
1.35G
  for (qi = h8_instructions; qi->opcode->name; qi++)
351
1.35G
    {
352
1.35G
      const struct h8_opcode *q;
353
1.35G
      const op_type *nib;
354
1.35G
      unsigned int len;
355
1.35G
      op_type looking_for;
356
357
1.35G
      if (qi->length > maxlen)
358
5.30M
  continue;
359
360
1.34G
      q = qi->opcode;
361
1.34G
      nib = q->data.nib;
362
1.34G
      len = 0;
363
1.81G
      while ((looking_for = *nib) != (op_type) E)
364
1.81G
  {
365
1.81G
    int thisnib;
366
1.81G
    int opnr;
367
368
1.81G
    OPCODES_ASSERT (len / 2 < maxlen);
369
1.81G
    thisnib = data[len / 2];
370
1.81G
    thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib / 16) & 0xf);
371
1.81G
    opnr = ((looking_for & OP3) == OP3 ? 2
372
1.81G
      : (looking_for & DST) == DST ? 1 : 0);
373
374
1.81G
    if (looking_for < 16 && looking_for >= 0)
375
1.81G
      {
376
1.81G
        if (looking_for != thisnib)
377
1.34G
    goto fail;
378
1.81G
      }
379
2.53M
    else
380
2.53M
      {
381
2.53M
        if ((int) looking_for & (int) B31)
382
426k
    {
383
426k
      if (!((thisnib & 0x8) != 0))
384
317k
        goto fail;
385
386
109k
      looking_for = (op_type) ((int) looking_for & ~(int) B31);
387
109k
      thisnib &= 0x7;
388
109k
    }
389
2.10M
        else if ((int) looking_for & (int) B30)
390
1.27M
    {
391
1.27M
      if (!((thisnib & 0x8) == 0))
392
249k
        goto fail;
393
394
1.02M
      looking_for = (op_type) ((int) looking_for & ~(int) B30);
395
1.02M
    }
396
397
1.96M
        if ((int) looking_for & (int) B21)
398
453k
    {
399
453k
      if (!((thisnib & 0x4) != 0))
400
404k
        goto fail;
401
402
48.9k
      looking_for = (op_type) ((int) looking_for & ~(int) B21);
403
48.9k
      thisnib &= 0xb;
404
48.9k
    }
405
1.51M
        else if ((int) looking_for & (int) B20)
406
9.92k
    {
407
9.92k
      if (!((thisnib & 0x4) == 0))
408
1.35k
        goto fail;
409
410
8.57k
      looking_for = (op_type) ((int) looking_for & ~(int) B20);
411
8.57k
    }
412
1.56M
        if ((int) looking_for & (int) B11)
413
384
    {
414
384
      if (!((thisnib & 0x2) != 0))
415
288
        goto fail;
416
417
96
      looking_for = (op_type) ((int) looking_for & ~(int) B11);
418
96
      thisnib &= 0xd;
419
96
    }
420
1.56M
        else if ((int) looking_for & (int) B10)
421
384
    {
422
384
      if (!((thisnib & 0x2) == 0))
423
96
        goto fail;
424
425
288
      looking_for = (op_type) ((int) looking_for & ~(int) B10);
426
288
    }
427
428
1.56M
        if ((int) looking_for & (int) B01)
429
1.43k
    {
430
1.43k
      if (!((thisnib & 0x1) != 0))
431
663
        goto fail;
432
433
770
      looking_for = (op_type) ((int) looking_for & ~(int) B01);
434
770
      thisnib &= 0xe;
435
770
    }
436
1.55M
        else if ((int) looking_for & (int) B00)
437
14.3k
    {
438
14.3k
      if (!((thisnib & 0x1) == 0))
439
7.30k
        goto fail;
440
441
6.99k
      looking_for = (op_type) ((int) looking_for & ~(int) B00);
442
6.99k
    }
443
444
1.55M
        if (looking_for & IGNORE)
445
38.1k
    {
446
      /* Hitachi has declared that IGNORE must be zero.  */
447
38.1k
      if (thisnib != 0)
448
35.1k
        goto fail;
449
38.1k
    }
450
1.51M
        else if ((looking_for & MODE) == DATA)
451
302k
    {
452
302k
      ;     /* Skip embedded data.  */
453
302k
    }
454
1.21M
        else if ((looking_for & MODE) == DBIT)
455
8.85k
    {
456
      /* Exclude adds/subs by looking at bit 0 and 2, and
457
                     make sure the operand size, either w or l,
458
                     matches by looking at bit 1.  */
459
8.85k
      if ((looking_for & 7) != (thisnib & 7))
460
8.17k
        goto fail;
461
462
674
      cst[opnr] = (thisnib & 0x8) ? 2 : 1;
463
674
    }
464
1.20M
        else if ((looking_for & MODE) == DISP
465
1.14M
           || (looking_for & MODE) == ABS
466
1.01M
           || (looking_for & MODE) == PCREL
467
998k
           || (looking_for & MODE) == INDEXB
468
998k
           || (looking_for & MODE) == INDEXW
469
998k
           || (looking_for & MODE) == INDEXL)
470
204k
    {
471
204k
      int extra;
472
204k
      switch (looking_for & SIZE)
473
204k
        {
474
2.87k
        case L_16:
475
3.68k
        case L_16U:
476
3.68k
          extra = 1;
477
3.68k
          break;
478
3.57k
        case L_32:
479
3.57k
          extra = 3;
480
3.57k
          break;
481
196k
        default:
482
196k
          extra = 0;
483
196k
          break;
484
204k
        }
485
204k
      OPCODES_ASSERT (len / 2 + extra < maxlen);
486
204k
      extract_immediate (stream, looking_for, thisnib,
487
204k
             data + len / 2, cst + opnr,
488
204k
             cstlen + opnr, q);
489
      /* Even address == bra, odd == bra/s.  */
490
204k
      if (q->how == O (O_BRAS, SB))
491
386
        cst[opnr] -= 1;
492
204k
    }
493
998k
        else if ((looking_for & MODE) == REG
494
773k
           || (looking_for & MODE) == LOWREG
495
769k
           || (looking_for & MODE) == IND
496
625k
           || (looking_for & MODE) == PREINC
497
624k
           || (looking_for & MODE) == POSTINC
498
622k
           || (looking_for & MODE) == PREDEC
499
622k
           || (looking_for & MODE) == POSTDEC)
500
377k
    {
501
377k
      regno[opnr] = thisnib;
502
377k
    }
503
621k
        else if (looking_for & CTRL)  /* Control Register.  */
504
13.1k
    {
505
13.1k
      thisnib &= 7;
506
13.1k
      if (((looking_for & MODE) == CCR  && (thisnib != C_CCR))
507
11.4k
          || ((looking_for & MODE) == EXR  && (thisnib != C_EXR))
508
9.77k
          || ((looking_for & MODE) == MACH && (thisnib != C_MACH))
509
9.77k
          || ((looking_for & MODE) == MACL && (thisnib != C_MACL))
510
9.77k
          || ((looking_for & MODE) == VBR  && (thisnib != C_VBR))
511
9.77k
          || ((looking_for & MODE) == SBR  && (thisnib != C_SBR)))
512
3.42k
        goto fail;
513
9.77k
      if (((looking_for & MODE) == CCR_EXR
514
3.10k
           && (thisnib != C_CCR && thisnib != C_EXR))
515
8.68k
          || ((looking_for & MODE) == VBR_SBR
516
1.09k
        && (thisnib != C_VBR && thisnib != C_SBR))
517
8.15k
          || ((looking_for & MODE) == MACREG
518
1.86k
        && (thisnib != C_MACH && thisnib != C_MACL)))
519
2.93k
        goto fail;
520
6.83k
      if (((looking_for & MODE) == CC_EX_VB_SB
521
0
           && (thisnib != C_CCR && thisnib != C_EXR
522
0
         && thisnib != C_VBR && thisnib != C_SBR)))
523
0
        goto fail;
524
525
6.83k
      regno[opnr] = thisnib;
526
6.83k
    }
527
608k
        else if ((looking_for & SIZE) == L_5)
528
2.16k
    {
529
2.16k
      cst[opnr] = data[len / 2] & 31;
530
2.16k
      cstlen[opnr] = 5;
531
2.16k
    }
532
606k
        else if ((looking_for & SIZE) == L_4)
533
167
    {
534
167
      cst[opnr] = thisnib;
535
167
      cstlen[opnr] = 4;
536
167
    }
537
606k
        else if ((looking_for & SIZE) == L_16
538
605k
           || (looking_for & SIZE) == L_16U)
539
1.38k
    {
540
1.38k
      OPCODES_ASSERT (len / 2 + 1 < maxlen);
541
1.38k
      cst[opnr] = (data[len / 2]) * 256 + data[(len + 2) / 2];
542
1.38k
      cstlen[opnr] = 16;
543
1.38k
    }
544
604k
        else if ((looking_for & MODE) == MEMIND)
545
1.97k
    {
546
1.97k
      cst[opnr] = data[1];
547
1.97k
    }
548
602k
        else if ((looking_for & MODE) == VECIND)
549
1.48k
    {
550
1.48k
      cst[opnr] = data[1] & 0x7f;
551
1.48k
    }
552
601k
        else if ((looking_for & SIZE) == L_32)
553
223
    {
554
223
      unsigned int i = len / 2;
555
556
223
      OPCODES_ASSERT (i + 3 < maxlen);
557
223
      cst[opnr] = (((unsigned) data[i] << 24)
558
223
             | (data[i + 1] << 16)
559
223
             | (data[i + 2] << 8)
560
223
             | (data[i + 3]));
561
562
223
      cstlen[opnr] = 32;
563
223
    }
564
601k
        else if ((looking_for & SIZE) == L_24)
565
1.54k
    {
566
1.54k
      unsigned int i = len / 2;
567
568
1.54k
      OPCODES_ASSERT (i + 2 < maxlen);
569
1.54k
      cst[opnr] =
570
1.54k
        (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]);
571
1.54k
      cstlen[opnr] = 24;
572
1.54k
    }
573
599k
        else if (looking_for & DISPREG)
574
476k
    {
575
476k
      dispregno[opnr] = thisnib & 7;
576
476k
    }
577
123k
        else if ((looking_for & MODE) == KBIT)
578
5.39k
    {
579
5.39k
      switch (thisnib)
580
5.39k
        {
581
117
        case 9:
582
117
          cst[opnr] = 4;
583
117
          break;
584
193
        case 8:
585
193
          cst[opnr] = 2;
586
193
          break;
587
1.26k
        case 0:
588
1.26k
          cst[opnr] = 1;
589
1.26k
          break;
590
3.81k
        default:
591
3.81k
          goto fail;
592
5.39k
        }
593
5.39k
    }
594
117k
        else if ((looking_for & SIZE) == L_8)
595
102k
    {
596
102k
      cstlen[opnr] = 8;
597
102k
      cst[opnr] = data[len / 2];
598
102k
    }
599
14.9k
        else if ((looking_for & SIZE) == L_3
600
3.19k
           || (looking_for & SIZE) == L_3NZ)
601
14.3k
    {
602
14.3k
      cst[opnr] = thisnib & 0x7;
603
14.3k
      if (cst[opnr] == 0 && (looking_for & SIZE) == L_3NZ)
604
932
        goto fail;
605
14.3k
    }
606
598
        else if ((looking_for & SIZE) == L_2)
607
598
    {
608
598
      cstlen[opnr] = 2;
609
598
      cst[opnr] = thisnib & 0x3;
610
598
    }
611
0
        else if ((looking_for & MODE) == MACREG)
612
0
    {
613
0
      cst[opnr] = (thisnib == 3);
614
0
    }
615
0
        else
616
    /* xgettext:c-format */
617
0
    outfn (stream, _("Don't understand 0x%x \n"), looking_for);
618
1.55M
      }
619
620
466M
    len++;
621
466M
    nib++;
622
466M
  }
623
624
255k
      outfn (stream, "%s\t", q->name);
625
626
      /* Gross.  Disgusting.  */
627
255k
      if (strcmp (q->name, "ldm.l") == 0)
628
16
  {
629
16
    int count, high;
630
631
16
    count = (data[1] / 16) & 0x3;
632
16
    high = regno[1];
633
634
16
    outfn (stream, "@sp+,er%d-er%d", high - count, high);
635
16
    return qi->length;
636
16
  }
637
638
255k
      if (strcmp (q->name, "stm.l") == 0)
639
0
  {
640
0
    int count, low;
641
642
0
    count = (data[1] / 16) & 0x3;
643
0
    low = regno[0];
644
645
0
    outfn (stream, "er%d-er%d,@-sp", low, low + count);
646
0
    return qi->length;
647
0
  }
648
255k
      if (strcmp (q->name, "rte/l") == 0
649
254k
    || strcmp (q->name, "rts/l") == 0)
650
1.71k
  {
651
1.71k
    if (regno[0] == 0)
652
189
      outfn (stream, "er%d", regno[1]);
653
1.52k
    else
654
1.52k
      outfn (stream, "er%d-er%d", regno[1] - regno[0],
655
1.52k
       regno[1]);
656
1.71k
    return qi->length;
657
1.71k
  }
658
253k
      if (startswith (q->name, "mova"))
659
208
  {
660
208
    const op_type *args = q->args.nib;
661
662
208
    if (args[1] == (op_type) E)
663
166
      {
664
        /* Short form.  */
665
166
        print_one_arg (info, addr, args[0], cst[0],
666
166
           cstlen[0], dispregno[0], regno[0],
667
166
           pregnames, qi->length);
668
166
        outfn (stream, ",er%d", dispregno[0]);
669
166
      }
670
42
    else
671
42
      {
672
42
        outfn (stream, "@(0x%x:%d,", cst[0], cstlen[0]);
673
42
        print_one_arg (info, addr, args[1], cst[1],
674
42
           cstlen[1], dispregno[1], regno[1],
675
42
           pregnames, qi->length);
676
42
        outfn (stream, ".%c),",
677
42
         (args[0] & MODE) == INDEXB ? 'b' : 'w');
678
42
        print_one_arg (info, addr, args[2], cst[2],
679
42
           cstlen[2], dispregno[2], regno[2],
680
42
           pregnames, qi->length);
681
42
      }
682
208
    return qi->length;
683
208
  }
684
      /* Fill in the args.  */
685
253k
      {
686
253k
  const op_type *args = q->args.nib;
687
253k
  int hadone = 0;
688
253k
  int nargs;
689
690
  /* Special case handling for the adds and subs instructions
691
     since in H8 mode thay can only take the r0-r7 registers
692
     but in other (higher) modes they can take the er0-er7
693
     registers as well.  */
694
253k
  if (strcmp (qi->opcode->name, "adds") == 0
695
252k
      || strcmp (qi->opcode->name, "subs") == 0)
696
1.57k
    {
697
1.57k
      outfn (stream, "#%d,%s", cst[0], pregnames[regno[1] & 0x7]);
698
1.57k
      return qi->length;
699
1.57k
    }
700
701
251k
  for (nargs = 0;
702
646k
       nargs < 3 && args[nargs] != (op_type) E;
703
394k
       nargs++)
704
394k
    {
705
394k
      int x = args[nargs];
706
707
394k
      if (hadone)
708
187k
        outfn (stream, ",");
709
710
394k
      print_one_arg (info, addr, x,
711
394k
         cst[nargs], cstlen[nargs],
712
394k
         dispregno[nargs], regno[nargs],
713
394k
         pregnames, qi->length);
714
715
394k
      hadone = 1;
716
394k
    }
717
251k
      }
718
0
      return qi->length;
719
720
1.34G
    fail:
721
1.34G
      ;
722
1.34G
    }
723
724
  /* Fell off the end.  */
725
54.2k
  outfn (stream, ".word\tH'%x,H'%x", data[0], data[1]);
726
54.2k
  return 2;
727
309k
}
728
729
int
730
print_insn_h8300 (bfd_vma addr, disassemble_info *info)
731
275k
{
732
275k
  return bfd_h8_disassemble (addr, info, 0);
733
275k
}
734
735
int
736
print_insn_h8300h (bfd_vma addr, disassemble_info *info)
737
20.5k
{
738
20.5k
  return bfd_h8_disassemble (addr, info, 1);
739
20.5k
}
740
741
int
742
print_insn_h8300s (bfd_vma addr, disassemble_info *info)
743
13.6k
{
744
13.6k
  return bfd_h8_disassemble (addr, info, 2);
745
13.6k
}