Coverage Report

Created: 2026-09-14 08:07

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
404k
{
79
404k
  switch (looking_for & SIZE)
80
404k
    {
81
114k
    case L_2:
82
114k
      *len = 2;
83
114k
      *cst = thisnib & 3;
84
85
      /* DISP2 special treatment.  */
86
114k
      if ((looking_for & MODE) == DISP)
87
114k
  {
88
114k
    if (OP_KIND (q->how) == O_MOVAB
89
114k
        || OP_KIND (q->how) == O_MOVAW
90
113k
        || OP_KIND (q->how) == O_MOVAL)
91
624
      {
92
        /* Handling for mova insn.  */
93
624
        switch (q->args.nib[0] & MODE)
94
624
    {
95
342
    case INDEXB:
96
342
    default:
97
342
      break;
98
342
    case INDEXW:
99
282
      *cst *= 2;
100
282
      break;
101
0
    case INDEXL:
102
0
      *cst *= 4;
103
0
      break;
104
624
    }
105
624
      }
106
113k
    else
107
113k
      {
108
        /* Handling for non-mova insn.  */
109
113k
        switch (OP_SIZE (q->how))
110
113k
    {
111
9.31k
    default: break;
112
17.3k
    case SW:
113
17.3k
      *cst *= 2;
114
17.3k
      break;
115
87.0k
    case SL:
116
87.0k
      *cst *= 4;
117
87.0k
      break;
118
113k
    }
119
113k
      }
120
114k
  }
121
114k
      break;
122
282k
    case L_8:
123
282k
      *len = 8;
124
282k
      *cst = data[0];
125
282k
      break;
126
5.84k
    case L_16:
127
6.98k
    case L_16U:
128
6.98k
      *len = 16;
129
6.98k
      *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
6.98k
      break;
135
989
    case L_32:
136
989
      *len = 32;
137
989
      *cst = (((unsigned) data[0] << 24) + (data[1] << 16)
138
989
        + (data[2] << 8) + data[3]);
139
989
      break;
140
0
    default:
141
0
      *len = 0;
142
0
      *cst = 0;
143
0
      fprintf (stream, "DISP bad size\n");
144
0
      break;
145
404k
    }
146
404k
}
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
764k
{
179
764k
  void * stream = info->stream;
180
764k
  fprintf_ftype outfn = info->fprintf_func;
181
182
764k
  if ((x & SIZE) == L_3 || (x & SIZE) == L_3NZ)
183
26.6k
    outfn (stream, "#0x%x", (unsigned) cst);
184
737k
  else if ((x & MODE) == IMM)
185
203k
    outfn (stream, "#0x%x", (unsigned) cst);
186
533k
  else if ((x & MODE) == DBIT || (x & MODE) == KBIT)
187
281
    outfn (stream, "#%d", (unsigned) cst);
188
533k
  else if ((x & MODE) == CONST_2)
189
2.16k
    outfn (stream, "#2");
190
530k
  else if ((x & MODE) == CONST_4)
191
557
    outfn (stream, "#4");
192
530k
  else if ((x & MODE) == CONST_8)
193
562
    outfn (stream, "#8");
194
529k
  else if ((x & MODE) == CONST_16)
195
409
    outfn (stream, "#16");
196
529k
  else if ((x & MODE) == REG)
197
406k
    {
198
406k
      switch (x & SIZE)
199
406k
  {
200
341k
  case L_8:
201
341k
    outfn (stream, "%s", regnames[rn]);
202
341k
    break;
203
52.9k
  case L_16:
204
52.9k
  case L_16U:
205
52.9k
    outfn (stream, "%s", wregnames[rn]);
206
52.9k
    break;
207
0
  case L_P:
208
11.8k
  case L_32:
209
11.8k
    outfn (stream, "%s", lregnames[rn]);
210
11.8k
    break;
211
406k
  }
212
406k
    }
213
122k
  else if ((x & MODE) == LOWREG)
214
468
    {
215
468
      switch (x & SIZE)
216
468
  {
217
218
  case L_8:
218
    /* Always take low half of reg.  */
219
218
    outfn (stream, "%s.b", regnames[rn < 8 ? rn + 8 : rn]);
220
218
    break;
221
250
  case L_16:
222
250
  case L_16U:
223
    /* Always take low half of reg.  */
224
250
    outfn (stream, "%s.w", wregnames[rn < 8 ? rn : rn - 8]);
225
250
    break;
226
0
  case L_P:
227
0
  case L_32:
228
0
    outfn (stream, "%s.l", lregnames[rn]);
229
0
    break;
230
468
  }
231
468
    }
232
122k
  else if ((x & MODE) == POSTINC)
233
2.98k
    outfn (stream, "@%s+", pregnames[rn]);
234
235
119k
  else if ((x & MODE) == POSTDEC)
236
364
    outfn (stream, "@%s-", pregnames[rn]);
237
238
118k
  else if ((x & MODE) == PREINC)
239
399
    outfn (stream, "@+%s", pregnames[rn]);
240
241
118k
  else if ((x & MODE) == PREDEC)
242
666
    outfn (stream, "@-%s", pregnames[rn]);
243
244
117k
  else if ((x & MODE) == IND)
245
5.45k
    outfn (stream, "@%s", pregnames[rn]);
246
247
112k
  else if ((x & MODE) == ABS || (x & ABSJMP))
248
58.4k
    outfn (stream, "@0x%x:%d", (unsigned) cst, cstlen);
249
250
54.0k
  else if ((x & MODE) == MEMIND)
251
3.81k
    outfn (stream, "@@%d (0x%x)", cst, cst);
252
253
50.1k
  else if ((x & MODE) == VECIND)
254
1.92k
    {
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.92k
      int offset = (cst + 0x80) * 4;
259
1.92k
      outfn (stream, "@@%d (0x%x)", offset, offset);
260
1.92k
    }
261
48.2k
  else if ((x & MODE) == PCREL)
262
17.9k
    {
263
17.9k
      if ((x & SIZE) == L_16 ||
264
17.7k
    (x & SIZE) == L_16U)
265
163
  {
266
163
    outfn (stream, ".%s%d (0x%lx)",
267
163
       (short) cst > 0 ? "+" : "",
268
163
       (short) cst,
269
163
       (long)(addr + (short) cst + len));
270
163
  }
271
17.7k
      else
272
17.7k
  {
273
17.7k
    outfn (stream, ".%s%d (0x%lx)",
274
17.7k
       (char) cst > 0 ? "+" : "",
275
17.7k
       (char) cst,
276
17.7k
       (long)(addr + (char) cst + len));
277
17.7k
  }
278
17.9k
    }
279
30.3k
  else if ((x & MODE) == DISP)
280
5.22k
    outfn (stream, "@(0x%x:%d,%s)", cst, cstlen, pregnames[rdisp_n]);
281
282
25.1k
  else if ((x & MODE) == INDEXB)
283
    /* Always take low half of reg.  */
284
191
    outfn (stream, "@(0x%x:%d,%s.b)", cst, cstlen,
285
191
     regnames[rdisp_n < 8 ? rdisp_n + 8 : rdisp_n]);
286
287
24.9k
  else if ((x & MODE) == INDEXW)
288
    /* Always take low half of reg.  */
289
144
    outfn (stream, "@(0x%x:%d,%s.w)", cst, cstlen,
290
144
     wregnames[rdisp_n < 8 ? rdisp_n : rdisp_n - 8]);
291
292
24.7k
  else if ((x & MODE) == INDEXL)
293
150
    outfn (stream, "@(0x%x:%d,%s.l)", cst, cstlen, lregnames[rdisp_n]);
294
295
24.6k
  else if (x & CTRL)
296
24.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
764k
}
311
312
static unsigned int
313
bfd_h8_disassemble (bfd_vma addr, disassemble_info *info, int mach)
314
604k
{
315
  /* Find the first entry in the table for this opcode.  */
316
604k
  int regno[3] = { 0, 0, 0 };
317
604k
  int dispregno[3] = { 0, 0, 0 };
318
604k
  int cst[3] = { 0, 0, 0 };
319
604k
  int cstlen[3] = { 0, 0, 0 };
320
604k
  static bool init = 0;
321
604k
  const struct h8_instruction *qi;
322
604k
  char const **pregnames = mach != 0 ? lregnames : wregnames;
323
604k
  int status;
324
604k
  unsigned int maxlen;
325
604k
  unsigned char data[MAX_CODE_NIBBLES / 2];
326
604k
  void *stream = info->stream;
327
604k
  fprintf_ftype outfn = info->fprintf_func;
328
329
604k
  if (!init)
330
2
    {
331
2
      bfd_h8_disassemble_init ();
332
2
      init = 1;
333
2
    }
334
335
604k
  status = info->read_memory_func (addr, data, 2, info);
336
604k
  if (status != 0)
337
199
    {
338
199
      info->memory_error_func (status, addr, info);
339
199
      return -1;
340
199
    }
341
342
4.81M
  for (maxlen = 2; maxlen < sizeof (data); maxlen += 2)
343
4.21M
    {
344
4.21M
      status = info->read_memory_func (addr + maxlen, data + maxlen, 2, info);
345
4.21M
      if (status != 0)
346
4.46k
  break;
347
4.21M
    }
348
349
  /* Find the exact opcode/arg combo.  */
350
2.64G
  for (qi = h8_instructions; qi->opcode->name; qi++)
351
2.64G
    {
352
2.64G
      const struct h8_opcode *q;
353
2.64G
      const op_type *nib;
354
2.64G
      unsigned int len;
355
2.64G
      op_type looking_for;
356
357
2.64G
      if (qi->length > maxlen)
358
9.02M
  continue;
359
360
2.63G
      q = qi->opcode;
361
2.63G
      nib = q->data.nib;
362
2.63G
      len = 0;
363
3.57G
      while ((looking_for = *nib) != (op_type) E)
364
3.57G
  {
365
3.57G
    int thisnib;
366
3.57G
    int opnr;
367
368
3.57G
    OPCODES_ASSERT (len / 2 < maxlen);
369
3.57G
    thisnib = data[len / 2];
370
3.57G
    thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib / 16) & 0xf);
371
3.57G
    opnr = ((looking_for & OP3) == OP3 ? 2
372
3.57G
      : (looking_for & DST) == DST ? 1 : 0);
373
374
3.57G
    if (looking_for < 16 && looking_for >= 0)
375
3.56G
      {
376
3.56G
        if (looking_for != thisnib)
377
2.63G
    goto fail;
378
3.56G
      }
379
6.94M
    else
380
6.94M
      {
381
6.94M
        if ((int) looking_for & (int) B31)
382
1.51M
    {
383
1.51M
      if (!((thisnib & 0x8) != 0))
384
1.05M
        goto fail;
385
386
459k
      looking_for = (op_type) ((int) looking_for & ~(int) B31);
387
459k
      thisnib &= 0x7;
388
459k
    }
389
5.43M
        else if ((int) looking_for & (int) B30)
390
3.80M
    {
391
3.80M
      if (!((thisnib & 0x8) == 0))
392
964k
        goto fail;
393
394
2.83M
      looking_for = (op_type) ((int) looking_for & ~(int) B30);
395
2.83M
    }
396
397
4.92M
        if ((int) looking_for & (int) B21)
398
861k
    {
399
861k
      if (!((thisnib & 0x4) != 0))
400
760k
        goto fail;
401
402
100k
      looking_for = (op_type) ((int) looking_for & ~(int) B21);
403
100k
      thisnib &= 0xb;
404
100k
    }
405
4.06M
        else if ((int) looking_for & (int) B20)
406
17.7k
    {
407
17.7k
      if (!((thisnib & 0x4) == 0))
408
2.65k
        goto fail;
409
410
15.0k
      looking_for = (op_type) ((int) looking_for & ~(int) B20);
411
15.0k
    }
412
4.16M
        if ((int) looking_for & (int) B11)
413
576
    {
414
576
      if (!((thisnib & 0x2) != 0))
415
288
        goto fail;
416
417
288
      looking_for = (op_type) ((int) looking_for & ~(int) B11);
418
288
      thisnib &= 0xd;
419
288
    }
420
4.16M
        else if ((int) looking_for & (int) B10)
421
576
    {
422
576
      if (!((thisnib & 0x2) == 0))
423
288
        goto fail;
424
425
288
      looking_for = (op_type) ((int) looking_for & ~(int) B10);
426
288
    }
427
428
4.16M
        if ((int) looking_for & (int) B01)
429
3.69k
    {
430
3.69k
      if (!((thisnib & 0x1) != 0))
431
1.58k
        goto fail;
432
433
2.10k
      looking_for = (op_type) ((int) looking_for & ~(int) B01);
434
2.10k
      thisnib &= 0xe;
435
2.10k
    }
436
4.16M
        else if ((int) looking_for & (int) B00)
437
29.8k
    {
438
29.8k
      if (!((thisnib & 0x1) == 0))
439
14.6k
        goto fail;
440
441
15.1k
      looking_for = (op_type) ((int) looking_for & ~(int) B00);
442
15.1k
    }
443
444
4.14M
        if (looking_for & IGNORE)
445
88.2k
    {
446
      /* Hitachi has declared that IGNORE must be zero.  */
447
88.2k
      if (thisnib != 0)
448
82.7k
        goto fail;
449
88.2k
    }
450
4.06M
        else if ((looking_for & MODE) == DATA)
451
558k
    {
452
558k
      ;     /* Skip embedded data.  */
453
558k
    }
454
3.50M
        else if ((looking_for & MODE) == DBIT)
455
7.98k
    {
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
7.98k
      if ((looking_for & 7) != (thisnib & 7))
460
7.29k
        goto fail;
461
462
686
      cst[opnr] = (thisnib & 0x8) ? 2 : 1;
463
686
    }
464
3.49M
        else if ((looking_for & MODE) == DISP
465
3.37M
           || (looking_for & MODE) == ABS
466
3.12M
           || (looking_for & MODE) == PCREL
467
3.08M
           || (looking_for & MODE) == INDEXB
468
3.08M
           || (looking_for & MODE) == INDEXW
469
3.08M
           || (looking_for & MODE) == INDEXL)
470
404k
    {
471
404k
      int extra;
472
404k
      switch (looking_for & SIZE)
473
404k
        {
474
5.84k
        case L_16:
475
6.98k
        case L_16U:
476
6.98k
          extra = 1;
477
6.98k
          break;
478
989
        case L_32:
479
989
          extra = 3;
480
989
          break;
481
396k
        default:
482
396k
          extra = 0;
483
396k
          break;
484
404k
        }
485
404k
      OPCODES_ASSERT (len / 2 + extra < maxlen);
486
404k
      extract_immediate (stream, looking_for, thisnib,
487
404k
             data + len / 2, cst + opnr,
488
404k
             cstlen + opnr, q);
489
      /* Even address == bra, odd == bra/s.  */
490
404k
      if (q->how == O (O_BRAS, SB))
491
1.14k
        cst[opnr] -= 1;
492
404k
    }
493
3.08M
        else if ((looking_for & MODE) == REG
494
2.62M
           || (looking_for & MODE) == LOWREG
495
2.62M
           || (looking_for & MODE) == IND
496
2.32M
           || (looking_for & MODE) == PREINC
497
2.32M
           || (looking_for & MODE) == POSTINC
498
2.32M
           || (looking_for & MODE) == PREDEC
499
2.32M
           || (looking_for & MODE) == POSTDEC)
500
768k
    {
501
768k
      regno[opnr] = thisnib;
502
768k
    }
503
2.32M
        else if (looking_for & CTRL)  /* Control Register.  */
504
33.1k
    {
505
33.1k
      thisnib &= 7;
506
33.1k
      if (((looking_for & MODE) == CCR  && (thisnib != C_CCR))
507
28.1k
          || ((looking_for & MODE) == EXR  && (thisnib != C_EXR))
508
23.4k
          || ((looking_for & MODE) == MACH && (thisnib != C_MACH))
509
23.4k
          || ((looking_for & MODE) == MACL && (thisnib != C_MACL))
510
23.4k
          || ((looking_for & MODE) == VBR  && (thisnib != C_VBR))
511
23.4k
          || ((looking_for & MODE) == SBR  && (thisnib != C_SBR)))
512
9.62k
        goto fail;
513
23.4k
      if (((looking_for & MODE) == CCR_EXR
514
8.17k
           && (thisnib != C_CCR && thisnib != C_EXR))
515
20.3k
          || ((looking_for & MODE) == VBR_SBR
516
3.16k
        && (thisnib != C_VBR && thisnib != C_SBR))
517
19.0k
          || ((looking_for & MODE) == MACREG
518
5.26k
        && (thisnib != C_MACH && thisnib != C_MACL)))
519
7.41k
        goto fail;
520
16.0k
      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
16.0k
      regno[opnr] = thisnib;
526
16.0k
    }
527
2.28M
        else if ((looking_for & SIZE) == L_5)
528
10.8k
    {
529
10.8k
      cst[opnr] = data[len / 2] & 31;
530
10.8k
      cstlen[opnr] = 5;
531
10.8k
    }
532
2.27M
        else if ((looking_for & SIZE) == L_4)
533
181
    {
534
181
      cst[opnr] = thisnib;
535
181
      cstlen[opnr] = 4;
536
181
    }
537
2.27M
        else if ((looking_for & SIZE) == L_16
538
2.27M
           || (looking_for & SIZE) == L_16U)
539
2.25k
    {
540
2.25k
      OPCODES_ASSERT (len / 2 + 1 < maxlen);
541
2.25k
      cst[opnr] = (data[len / 2]) * 256 + data[(len + 2) / 2];
542
2.25k
      cstlen[opnr] = 16;
543
2.25k
    }
544
2.27M
        else if ((looking_for & MODE) == MEMIND)
545
3.81k
    {
546
3.81k
      cst[opnr] = data[1];
547
3.81k
    }
548
2.27M
        else if ((looking_for & MODE) == VECIND)
549
1.92k
    {
550
1.92k
      cst[opnr] = data[1] & 0x7f;
551
1.92k
    }
552
2.26M
        else if ((looking_for & SIZE) == L_32)
553
625
    {
554
625
      unsigned int i = len / 2;
555
556
625
      OPCODES_ASSERT (i + 3 < maxlen);
557
625
      cst[opnr] = (((unsigned) data[i] << 24)
558
625
             | (data[i + 1] << 16)
559
625
             | (data[i + 2] << 8)
560
625
             | (data[i + 3]));
561
562
625
      cstlen[opnr] = 32;
563
625
    }
564
2.26M
        else if ((looking_for & SIZE) == L_24)
565
2.41k
    {
566
2.41k
      unsigned int i = len / 2;
567
568
2.41k
      OPCODES_ASSERT (i + 2 < maxlen);
569
2.41k
      cst[opnr] =
570
2.41k
        (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]);
571
2.41k
      cstlen[opnr] = 24;
572
2.41k
    }
573
2.26M
        else if (looking_for & DISPREG)
574
2.02M
    {
575
2.02M
      dispregno[opnr] = thisnib & 7;
576
2.02M
    }
577
238k
        else if ((looking_for & MODE) == KBIT)
578
5.95k
    {
579
5.95k
      switch (thisnib)
580
5.95k
        {
581
338
        case 9:
582
338
          cst[opnr] = 4;
583
338
          break;
584
230
        case 8:
585
230
          cst[opnr] = 2;
586
230
          break;
587
2.10k
        case 0:
588
2.10k
          cst[opnr] = 1;
589
2.10k
          break;
590
3.27k
        default:
591
3.27k
          goto fail;
592
5.95k
        }
593
5.95k
    }
594
232k
        else if ((looking_for & SIZE) == L_8)
595
202k
    {
596
202k
      cstlen[opnr] = 8;
597
202k
      cst[opnr] = data[len / 2];
598
202k
    }
599
30.3k
        else if ((looking_for & SIZE) == L_3
600
7.28k
           || (looking_for & SIZE) == L_3NZ)
601
29.3k
    {
602
29.3k
      cst[opnr] = thisnib & 0x7;
603
29.3k
      if (cst[opnr] == 0 && (looking_for & SIZE) == L_3NZ)
604
2.06k
        goto fail;
605
29.3k
    }
606
1.00k
        else if ((looking_for & SIZE) == L_2)
607
1.00k
    {
608
1.00k
      cstlen[opnr] = 2;
609
1.00k
      cst[opnr] = thisnib & 0x3;
610
1.00k
    }
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
4.14M
      }
619
620
935M
    len++;
621
935M
    nib++;
622
935M
  }
623
624
500k
      outfn (stream, "%s\t", q->name);
625
626
      /* Gross.  Disgusting.  */
627
500k
      if (strcmp (q->name, "ldm.l") == 0)
628
82
  {
629
82
    int count, high;
630
631
82
    count = (data[1] / 16) & 0x3;
632
82
    high = regno[1];
633
634
82
    outfn (stream, "@sp+,er%d-er%d", high - count, high);
635
82
    return qi->length;
636
82
  }
637
638
500k
      if (strcmp (q->name, "stm.l") == 0)
639
10
  {
640
10
    int count, low;
641
642
10
    count = (data[1] / 16) & 0x3;
643
10
    low = regno[0];
644
645
10
    outfn (stream, "er%d-er%d,@-sp", low, low + count);
646
10
    return qi->length;
647
10
  }
648
500k
      if (strcmp (q->name, "rte/l") == 0
649
498k
    || strcmp (q->name, "rts/l") == 0)
650
3.81k
  {
651
3.81k
    if (regno[0] == 0)
652
378
      outfn (stream, "er%d", regno[1]);
653
3.43k
    else
654
3.43k
      outfn (stream, "er%d-er%d", regno[1] - regno[0],
655
3.43k
       regno[1]);
656
3.81k
    return qi->length;
657
3.81k
  }
658
496k
      if (startswith (q->name, "mova"))
659
419
  {
660
419
    const op_type *args = q->args.nib;
661
662
419
    if (args[1] == (op_type) E)
663
307
      {
664
        /* Short form.  */
665
307
        print_one_arg (info, addr, args[0], cst[0],
666
307
           cstlen[0], dispregno[0], regno[0],
667
307
           pregnames, qi->length);
668
307
        outfn (stream, ",er%d", dispregno[0]);
669
307
      }
670
112
    else
671
112
      {
672
112
        outfn (stream, "@(0x%x:%d,", cst[0], cstlen[0]);
673
112
        print_one_arg (info, addr, args[1], cst[1],
674
112
           cstlen[1], dispregno[1], regno[1],
675
112
           pregnames, qi->length);
676
112
        outfn (stream, ".%c),",
677
112
         (args[0] & MODE) == INDEXB ? 'b' : 'w');
678
112
        print_one_arg (info, addr, args[2], cst[2],
679
112
           cstlen[2], dispregno[2], regno[2],
680
112
           pregnames, qi->length);
681
112
      }
682
419
    return qi->length;
683
419
  }
684
      /* Fill in the args.  */
685
496k
      {
686
496k
  const op_type *args = q->args.nib;
687
496k
  int hadone = 0;
688
496k
  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
496k
  if (strcmp (qi->opcode->name, "adds") == 0
695
494k
      || strcmp (qi->opcode->name, "subs") == 0)
696
2.67k
    {
697
2.67k
      outfn (stream, "#%d,%s", cst[0], pregnames[regno[1] & 0x7]);
698
2.67k
      return qi->length;
699
2.67k
    }
700
701
493k
  for (nargs = 0;
702
1.25M
       nargs < 3 && args[nargs] != (op_type) E;
703
763k
       nargs++)
704
763k
    {
705
763k
      int x = args[nargs];
706
707
763k
      if (hadone)
708
361k
        outfn (stream, ",");
709
710
763k
      print_one_arg (info, addr, x,
711
763k
         cst[nargs], cstlen[nargs],
712
763k
         dispregno[nargs], regno[nargs],
713
763k
         pregnames, qi->length);
714
715
763k
      hadone = 1;
716
763k
    }
717
493k
      }
718
0
      return qi->length;
719
720
2.63G
    fail:
721
2.63G
      ;
722
2.63G
    }
723
724
  /* Fell off the end.  */
725
103k
  outfn (stream, ".word\tH'%x,H'%x", data[0], data[1]);
726
103k
  return 2;
727
604k
}
728
729
int
730
print_insn_h8300 (bfd_vma addr, disassemble_info *info)
731
561k
{
732
561k
  return bfd_h8_disassemble (addr, info, 0);
733
561k
}
734
735
int
736
print_insn_h8300h (bfd_vma addr, disassemble_info *info)
737
21.5k
{
738
21.5k
  return bfd_h8_disassemble (addr, info, 1);
739
21.5k
}
740
741
int
742
print_insn_h8300s (bfd_vma addr, disassemble_info *info)
743
21.0k
{
744
21.0k
  return bfd_h8_disassemble (addr, info, 2);
745
21.0k
}