Coverage Report

Created: 2026-07-25 10:20

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
357k
{
79
357k
  switch (looking_for & SIZE)
80
357k
    {
81
93.6k
    case L_2:
82
93.6k
      *len = 2;
83
93.6k
      *cst = thisnib & 3;
84
85
      /* DISP2 special treatment.  */
86
93.6k
      if ((looking_for & MODE) == DISP)
87
93.6k
  {
88
93.6k
    if (OP_KIND (q->how) == O_MOVAB
89
93.2k
        || OP_KIND (q->how) == O_MOVAW
90
92.8k
        || OP_KIND (q->how) == O_MOVAL)
91
1.05k
      {
92
        /* Handling for mova insn.  */
93
1.05k
        switch (q->args.nib[0] & MODE)
94
1.05k
    {
95
333
    case INDEXB:
96
333
    default:
97
333
      break;
98
720
    case INDEXW:
99
720
      *cst *= 2;
100
720
      break;
101
0
    case INDEXL:
102
0
      *cst *= 4;
103
0
      break;
104
1.05k
    }
105
1.05k
      }
106
92.5k
    else
107
92.5k
      {
108
        /* Handling for non-mova insn.  */
109
92.5k
        switch (OP_SIZE (q->how))
110
92.5k
    {
111
7.88k
    default: break;
112
13.4k
    case SW:
113
13.4k
      *cst *= 2;
114
13.4k
      break;
115
71.2k
    case SL:
116
71.2k
      *cst *= 4;
117
71.2k
      break;
118
92.5k
    }
119
92.5k
      }
120
93.6k
  }
121
93.6k
      break;
122
256k
    case L_8:
123
256k
      *len = 8;
124
256k
      *cst = data[0];
125
256k
      break;
126
5.72k
    case L_16:
127
6.77k
    case L_16U:
128
6.77k
      *len = 16;
129
6.77k
      *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.77k
      break;
135
991
    case L_32:
136
991
      *len = 32;
137
991
      *cst = (((unsigned) data[0] << 24) + (data[1] << 16)
138
991
        + (data[2] << 8) + data[3]);
139
991
      break;
140
0
    default:
141
0
      *len = 0;
142
0
      *cst = 0;
143
0
      fprintf (stream, "DISP bad size\n");
144
0
      break;
145
357k
    }
146
357k
}
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
715k
{
179
715k
  void * stream = info->stream;
180
715k
  fprintf_ftype outfn = info->fprintf_func;
181
182
715k
  if ((x & SIZE) == L_3 || (x & SIZE) == L_3NZ)
183
23.1k
    outfn (stream, "#0x%x", (unsigned) cst);
184
692k
  else if ((x & MODE) == IMM)
185
196k
    outfn (stream, "#0x%x", (unsigned) cst);
186
496k
  else if ((x & MODE) == DBIT || (x & MODE) == KBIT)
187
306
    outfn (stream, "#%d", (unsigned) cst);
188
496k
  else if ((x & MODE) == CONST_2)
189
2.19k
    outfn (stream, "#2");
190
493k
  else if ((x & MODE) == CONST_4)
191
513
    outfn (stream, "#4");
192
493k
  else if ((x & MODE) == CONST_8)
193
682
    outfn (stream, "#8");
194
492k
  else if ((x & MODE) == CONST_16)
195
406
    outfn (stream, "#16");
196
492k
  else if ((x & MODE) == REG)
197
380k
    {
198
380k
      switch (x & SIZE)
199
380k
  {
200
321k
  case L_8:
201
321k
    outfn (stream, "%s", regnames[rn]);
202
321k
    break;
203
50.1k
  case L_16:
204
50.1k
  case L_16U:
205
50.1k
    outfn (stream, "%s", wregnames[rn]);
206
50.1k
    break;
207
0
  case L_P:
208
8.79k
  case L_32:
209
8.79k
    outfn (stream, "%s", lregnames[rn]);
210
8.79k
    break;
211
380k
  }
212
380k
    }
213
111k
  else if ((x & MODE) == LOWREG)
214
366
    {
215
366
      switch (x & SIZE)
216
366
  {
217
257
  case L_8:
218
    /* Always take low half of reg.  */
219
257
    outfn (stream, "%s.b", regnames[rn < 8 ? rn + 8 : rn]);
220
257
    break;
221
109
  case L_16:
222
109
  case L_16U:
223
    /* Always take low half of reg.  */
224
109
    outfn (stream, "%s.w", wregnames[rn < 8 ? rn : rn - 8]);
225
109
    break;
226
0
  case L_P:
227
0
  case L_32:
228
0
    outfn (stream, "%s.l", lregnames[rn]);
229
0
    break;
230
366
  }
231
366
    }
232
111k
  else if ((x & MODE) == POSTINC)
233
2.99k
    outfn (stream, "@%s+", pregnames[rn]);
234
235
108k
  else if ((x & MODE) == POSTDEC)
236
261
    outfn (stream, "@%s-", pregnames[rn]);
237
238
108k
  else if ((x & MODE) == PREINC)
239
361
    outfn (stream, "@+%s", pregnames[rn]);
240
241
107k
  else if ((x & MODE) == PREDEC)
242
801
    outfn (stream, "@-%s", pregnames[rn]);
243
244
107k
  else if ((x & MODE) == IND)
245
4.51k
    outfn (stream, "@%s", pregnames[rn]);
246
247
102k
  else if ((x & MODE) == ABS || (x & ABSJMP))
248
54.1k
    outfn (stream, "@0x%x:%d", (unsigned) cst, cstlen);
249
250
48.4k
  else if ((x & MODE) == MEMIND)
251
4.17k
    outfn (stream, "@@%d (0x%x)", cst, cst);
252
253
44.2k
  else if ((x & MODE) == VECIND)
254
2.15k
    {
255
      /* FIXME Multiplier should be 2 or 4, depending on processor mode,
256
   by which is meant "normal" vs. "middle", "advanced", "maximum".  */
257
258
2.15k
      int offset = (cst + 0x80) * 4;
259
2.15k
      outfn (stream, "@@%d (0x%x)", offset, offset);
260
2.15k
    }
261
42.0k
  else if ((x & MODE) == PCREL)
262
16.4k
    {
263
16.4k
      if ((x & SIZE) == L_16 ||
264
16.1k
    (x & SIZE) == L_16U)
265
304
  {
266
304
    outfn (stream, ".%s%d (0x%lx)",
267
304
       (short) cst > 0 ? "+" : "",
268
304
       (short) cst,
269
304
       (long)(addr + (short) cst + len));
270
304
  }
271
16.1k
      else
272
16.1k
  {
273
16.1k
    outfn (stream, ".%s%d (0x%lx)",
274
16.1k
       (char) cst > 0 ? "+" : "",
275
16.1k
       (char) cst,
276
16.1k
       (long)(addr + (char) cst + len));
277
16.1k
  }
278
16.4k
    }
279
25.6k
  else if ((x & MODE) == DISP)
280
4.87k
    outfn (stream, "@(0x%x:%d,%s)", cst, cstlen, pregnames[rdisp_n]);
281
282
20.8k
  else if ((x & MODE) == INDEXB)
283
    /* Always take low half of reg.  */
284
250
    outfn (stream, "@(0x%x:%d,%s.b)", cst, cstlen,
285
250
     regnames[rdisp_n < 8 ? rdisp_n + 8 : rdisp_n]);
286
287
20.5k
  else if ((x & MODE) == INDEXW)
288
    /* Always take low half of reg.  */
289
173
    outfn (stream, "@(0x%x:%d,%s.w)", cst, cstlen,
290
173
     wregnames[rdisp_n < 8 ? rdisp_n : rdisp_n - 8]);
291
292
20.3k
  else if ((x & MODE) == INDEXL)
293
176
    outfn (stream, "@(0x%x:%d,%s.l)", cst, cstlen, lregnames[rdisp_n]);
294
295
20.2k
  else if (x & CTRL)
296
20.2k
    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
715k
}
311
312
static unsigned int
313
bfd_h8_disassemble (bfd_vma addr, disassemble_info *info, int mach)
314
561k
{
315
  /* Find the first entry in the table for this opcode.  */
316
561k
  int regno[3] = { 0, 0, 0 };
317
561k
  int dispregno[3] = { 0, 0, 0 };
318
561k
  int cst[3] = { 0, 0, 0 };
319
561k
  int cstlen[3] = { 0, 0, 0 };
320
561k
  static bool init = 0;
321
561k
  const struct h8_instruction *qi;
322
561k
  char const **pregnames = mach != 0 ? lregnames : wregnames;
323
561k
  int status;
324
561k
  unsigned int maxlen;
325
561k
  unsigned char data[MAX_CODE_NIBBLES / 2];
326
561k
  void *stream = info->stream;
327
561k
  fprintf_ftype outfn = info->fprintf_func;
328
329
561k
  if (!init)
330
2
    {
331
2
      bfd_h8_disassemble_init ();
332
2
      init = 1;
333
2
    }
334
335
561k
  status = info->read_memory_func (addr, data, 2, info);
336
561k
  if (status != 0)
337
179
    {
338
179
      info->memory_error_func (status, addr, info);
339
179
      return -1;
340
179
    }
341
342
4.47M
  for (maxlen = 2; maxlen < sizeof (data); maxlen += 2)
343
3.91M
    {
344
3.91M
      status = info->read_memory_func (addr + maxlen, data + maxlen, 2, info);
345
3.91M
      if (status != 0)
346
4.13k
  break;
347
3.91M
    }
348
349
  /* Find the exact opcode/arg combo.  */
350
2.43G
  for (qi = h8_instructions; qi->opcode->name; qi++)
351
2.43G
    {
352
2.43G
      const struct h8_opcode *q;
353
2.43G
      const op_type *nib;
354
2.43G
      unsigned int len;
355
2.43G
      op_type looking_for;
356
357
2.43G
      if (qi->length > maxlen)
358
8.35M
  continue;
359
360
2.42G
      q = qi->opcode;
361
2.42G
      nib = q->data.nib;
362
2.42G
      len = 0;
363
3.24G
      while ((looking_for = *nib) != (op_type) E)
364
3.24G
  {
365
3.24G
    int thisnib;
366
3.24G
    int opnr;
367
368
3.24G
    OPCODES_ASSERT (len / 2 < maxlen);
369
3.24G
    thisnib = data[len / 2];
370
3.24G
    thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib / 16) & 0xf);
371
3.24G
    opnr = ((looking_for & OP3) == OP3 ? 2
372
3.24G
      : (looking_for & DST) == DST ? 1 : 0);
373
374
3.24G
    if (looking_for < 16 && looking_for >= 0)
375
3.24G
      {
376
3.24G
        if (looking_for != thisnib)
377
2.42G
    goto fail;
378
3.24G
      }
379
5.85M
    else
380
5.85M
      {
381
5.85M
        if ((int) looking_for & (int) B31)
382
1.22M
    {
383
1.22M
      if (!((thisnib & 0x8) != 0))
384
781k
        goto fail;
385
386
438k
      looking_for = (op_type) ((int) looking_for & ~(int) B31);
387
438k
      thisnib &= 0x7;
388
438k
    }
389
4.63M
        else if ((int) looking_for & (int) B30)
390
3.11M
    {
391
3.11M
      if (!((thisnib & 0x8) == 0))
392
942k
        goto fail;
393
394
2.17M
      looking_for = (op_type) ((int) looking_for & ~(int) B30);
395
2.17M
    }
396
397
4.12M
        if ((int) looking_for & (int) B21)
398
752k
    {
399
752k
      if (!((thisnib & 0x4) != 0))
400
671k
        goto fail;
401
402
80.9k
      looking_for = (op_type) ((int) looking_for & ~(int) B21);
403
80.9k
      thisnib &= 0xb;
404
80.9k
    }
405
3.37M
        else if ((int) looking_for & (int) B20)
406
16.8k
    {
407
16.8k
      if (!((thisnib & 0x4) == 0))
408
2.29k
        goto fail;
409
410
14.5k
      looking_for = (op_type) ((int) looking_for & ~(int) B20);
411
14.5k
    }
412
3.45M
        if ((int) looking_for & (int) B11)
413
768
    {
414
768
      if (!((thisnib & 0x2) != 0))
415
480
        goto fail;
416
417
288
      looking_for = (op_type) ((int) looking_for & ~(int) B11);
418
288
      thisnib &= 0xd;
419
288
    }
420
3.45M
        else if ((int) looking_for & (int) B10)
421
768
    {
422
768
      if (!((thisnib & 0x2) == 0))
423
288
        goto fail;
424
425
480
      looking_for = (op_type) ((int) looking_for & ~(int) B10);
426
480
    }
427
428
3.45M
        if ((int) looking_for & (int) B01)
429
3.35k
    {
430
3.35k
      if (!((thisnib & 0x1) != 0))
431
1.35k
        goto fail;
432
433
2.00k
      looking_for = (op_type) ((int) looking_for & ~(int) B01);
434
2.00k
      thisnib &= 0xe;
435
2.00k
    }
436
3.45M
        else if ((int) looking_for & (int) B00)
437
28.1k
    {
438
28.1k
      if (!((thisnib & 0x1) == 0))
439
14.0k
        goto fail;
440
441
14.1k
      looking_for = (op_type) ((int) looking_for & ~(int) B00);
442
14.1k
    }
443
444
3.43M
        if (looking_for & IGNORE)
445
81.6k
    {
446
      /* Hitachi has declared that IGNORE must be zero.  */
447
81.6k
      if (thisnib != 0)
448
74.3k
        goto fail;
449
81.6k
    }
450
3.35M
        else if ((looking_for & MODE) == DATA)
451
521k
    {
452
521k
      ;     /* Skip embedded data.  */
453
521k
    }
454
2.83M
        else if ((looking_for & MODE) == DBIT)
455
7.16k
    {
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.16k
      if ((looking_for & 7) != (thisnib & 7))
460
6.63k
        goto fail;
461
462
531
      cst[opnr] = (thisnib & 0x8) ? 2 : 1;
463
531
    }
464
2.82M
        else if ((looking_for & MODE) == DISP
465
2.72M
           || (looking_for & MODE) == ABS
466
2.50M
           || (looking_for & MODE) == PCREL
467
2.47M
           || (looking_for & MODE) == INDEXB
468
2.47M
           || (looking_for & MODE) == INDEXW
469
2.47M
           || (looking_for & MODE) == INDEXL)
470
357k
    {
471
357k
      int extra;
472
357k
      switch (looking_for & SIZE)
473
357k
        {
474
5.72k
        case L_16:
475
6.77k
        case L_16U:
476
6.77k
          extra = 1;
477
6.77k
          break;
478
991
        case L_32:
479
991
          extra = 3;
480
991
          break;
481
350k
        default:
482
350k
          extra = 0;
483
350k
          break;
484
357k
        }
485
357k
      OPCODES_ASSERT (len / 2 + extra < maxlen);
486
357k
      extract_immediate (stream, looking_for, thisnib,
487
357k
             data + len / 2, cst + opnr,
488
357k
             cstlen + opnr, q);
489
      /* Even address == bra, odd == bra/s.  */
490
357k
      if (q->how == O (O_BRAS, SB))
491
1.05k
        cst[opnr] -= 1;
492
357k
    }
493
2.47M
        else if ((looking_for & MODE) == REG
494
2.04M
           || (looking_for & MODE) == LOWREG
495
2.03M
           || (looking_for & MODE) == IND
496
1.72M
           || (looking_for & MODE) == PREINC
497
1.72M
           || (looking_for & MODE) == POSTINC
498
1.71M
           || (looking_for & MODE) == PREDEC
499
1.71M
           || (looking_for & MODE) == POSTDEC)
500
751k
    {
501
751k
      regno[opnr] = thisnib;
502
751k
    }
503
1.71M
        else if (looking_for & CTRL)  /* Control Register.  */
504
26.6k
    {
505
26.6k
      thisnib &= 7;
506
26.6k
      if (((looking_for & MODE) == CCR  && (thisnib != C_CCR))
507
23.5k
          || ((looking_for & MODE) == EXR  && (thisnib != C_EXR))
508
19.9k
          || ((looking_for & MODE) == MACH && (thisnib != C_MACH))
509
19.9k
          || ((looking_for & MODE) == MACL && (thisnib != C_MACL))
510
19.9k
          || ((looking_for & MODE) == VBR  && (thisnib != C_VBR))
511
19.9k
          || ((looking_for & MODE) == SBR  && (thisnib != C_SBR)))
512
6.66k
        goto fail;
513
19.9k
      if (((looking_for & MODE) == CCR_EXR
514
9.30k
           && (thisnib != C_CCR && thisnib != C_EXR))
515
16.3k
          || ((looking_for & MODE) == VBR_SBR
516
1.82k
        && (thisnib != C_VBR && thisnib != C_SBR))
517
15.4k
          || ((looking_for & MODE) == MACREG
518
3.06k
        && (thisnib != C_MACH && thisnib != C_MACL)))
519
6.69k
        goto fail;
520
13.3k
      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
13.3k
      regno[opnr] = thisnib;
526
13.3k
    }
527
1.69M
        else if ((looking_for & SIZE) == L_5)
528
7.21k
    {
529
7.21k
      cst[opnr] = data[len / 2] & 31;
530
7.21k
      cstlen[opnr] = 5;
531
7.21k
    }
532
1.68M
        else if ((looking_for & SIZE) == L_4)
533
188
    {
534
188
      cst[opnr] = thisnib;
535
188
      cstlen[opnr] = 4;
536
188
    }
537
1.68M
        else if ((looking_for & SIZE) == L_16
538
1.68M
           || (looking_for & SIZE) == L_16U)
539
2.63k
    {
540
2.63k
      OPCODES_ASSERT (len / 2 + 1 < maxlen);
541
2.63k
      cst[opnr] = (data[len / 2]) * 256 + data[(len + 2) / 2];
542
2.63k
      cstlen[opnr] = 16;
543
2.63k
    }
544
1.68M
        else if ((looking_for & MODE) == MEMIND)
545
4.17k
    {
546
4.17k
      cst[opnr] = data[1];
547
4.17k
    }
548
1.67M
        else if ((looking_for & MODE) == VECIND)
549
2.15k
    {
550
2.15k
      cst[opnr] = data[1] & 0x7f;
551
2.15k
    }
552
1.67M
        else if ((looking_for & SIZE) == L_32)
553
675
    {
554
675
      unsigned int i = len / 2;
555
556
675
      OPCODES_ASSERT (i + 3 < maxlen);
557
675
      cst[opnr] = (((unsigned) data[i] << 24)
558
675
             | (data[i + 1] << 16)
559
675
             | (data[i + 2] << 8)
560
675
             | (data[i + 3]));
561
562
675
      cstlen[opnr] = 32;
563
675
    }
564
1.67M
        else if ((looking_for & SIZE) == L_24)
565
2.13k
    {
566
2.13k
      unsigned int i = len / 2;
567
568
2.13k
      OPCODES_ASSERT (i + 2 < maxlen);
569
2.13k
      cst[opnr] =
570
2.13k
        (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]);
571
2.13k
      cstlen[opnr] = 24;
572
2.13k
    }
573
1.67M
        else if (looking_for & DISPREG)
574
1.44M
    {
575
1.44M
      dispregno[opnr] = thisnib & 7;
576
1.44M
    }
577
226k
        else if ((looking_for & MODE) == KBIT)
578
4.61k
    {
579
4.61k
      switch (thisnib)
580
4.61k
        {
581
348
        case 9:
582
348
          cst[opnr] = 4;
583
348
          break;
584
229
        case 8:
585
229
          cst[opnr] = 2;
586
229
          break;
587
1.32k
        case 0:
588
1.32k
          cst[opnr] = 1;
589
1.32k
          break;
590
2.71k
        default:
591
2.71k
          goto fail;
592
4.61k
        }
593
4.61k
    }
594
221k
        else if ((looking_for & SIZE) == L_8)
595
194k
    {
596
194k
      cstlen[opnr] = 8;
597
194k
      cst[opnr] = data[len / 2];
598
194k
    }
599
26.8k
        else if ((looking_for & SIZE) == L_3
600
6.75k
           || (looking_for & SIZE) == L_3NZ)
601
25.3k
    {
602
25.3k
      cst[opnr] = thisnib & 0x7;
603
25.3k
      if (cst[opnr] == 0 && (looking_for & SIZE) == L_3NZ)
604
1.82k
        goto fail;
605
25.3k
    }
606
1.42k
        else if ((looking_for & SIZE) == L_2)
607
1.42k
    {
608
1.42k
      cstlen[opnr] = 2;
609
1.42k
      cst[opnr] = thisnib & 0x3;
610
1.42k
    }
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
3.43M
      }
619
620
823M
    len++;
621
823M
    nib++;
622
823M
  }
623
624
466k
      outfn (stream, "%s\t", q->name);
625
626
      /* Gross.  Disgusting.  */
627
466k
      if (strcmp (q->name, "ldm.l") == 0)
628
87
  {
629
87
    int count, high;
630
631
87
    count = (data[1] / 16) & 0x3;
632
87
    high = regno[1];
633
634
87
    outfn (stream, "@sp+,er%d-er%d", high - count, high);
635
87
    return qi->length;
636
87
  }
637
638
466k
      if (strcmp (q->name, "stm.l") == 0)
639
18
  {
640
18
    int count, low;
641
642
18
    count = (data[1] / 16) & 0x3;
643
18
    low = regno[0];
644
645
18
    outfn (stream, "er%d-er%d,@-sp", low, low + count);
646
18
    return qi->length;
647
18
  }
648
466k
      if (strcmp (q->name, "rte/l") == 0
649
464k
    || strcmp (q->name, "rts/l") == 0)
650
4.09k
  {
651
4.09k
    if (regno[0] == 0)
652
423
      outfn (stream, "er%d", regno[1]);
653
3.67k
    else
654
3.67k
      outfn (stream, "er%d-er%d", regno[1] - regno[0],
655
3.67k
       regno[1]);
656
4.09k
    return qi->length;
657
4.09k
  }
658
462k
      if (startswith (q->name, "mova"))
659
474
  {
660
474
    const op_type *args = q->args.nib;
661
662
474
    if (args[1] == (op_type) E)
663
392
      {
664
        /* Short form.  */
665
392
        print_one_arg (info, addr, args[0], cst[0],
666
392
           cstlen[0], dispregno[0], regno[0],
667
392
           pregnames, qi->length);
668
392
        outfn (stream, ",er%d", dispregno[0]);
669
392
      }
670
82
    else
671
82
      {
672
82
        outfn (stream, "@(0x%x:%d,", cst[0], cstlen[0]);
673
82
        print_one_arg (info, addr, args[1], cst[1],
674
82
           cstlen[1], dispregno[1], regno[1],
675
82
           pregnames, qi->length);
676
82
        outfn (stream, ".%c),",
677
82
         (args[0] & MODE) == INDEXB ? 'b' : 'w');
678
82
        print_one_arg (info, addr, args[2], cst[2],
679
82
           cstlen[2], dispregno[2], regno[2],
680
82
           pregnames, qi->length);
681
82
      }
682
474
    return qi->length;
683
474
  }
684
      /* Fill in the args.  */
685
462k
      {
686
462k
  const op_type *args = q->args.nib;
687
462k
  int hadone = 0;
688
462k
  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
462k
  if (strcmp (qi->opcode->name, "adds") == 0
695
461k
      || strcmp (qi->opcode->name, "subs") == 0)
696
1.89k
    {
697
1.89k
      outfn (stream, "#%d,%s", cst[0], pregnames[regno[1] & 0x7]);
698
1.89k
      return qi->length;
699
1.89k
    }
700
701
460k
  for (nargs = 0;
702
1.17M
       nargs < 3 && args[nargs] != (op_type) E;
703
715k
       nargs++)
704
715k
    {
705
715k
      int x = args[nargs];
706
707
715k
      if (hadone)
708
339k
        outfn (stream, ",");
709
710
715k
      print_one_arg (info, addr, x,
711
715k
         cst[nargs], cstlen[nargs],
712
715k
         dispregno[nargs], regno[nargs],
713
715k
         pregnames, qi->length);
714
715
715k
      hadone = 1;
716
715k
    }
717
460k
      }
718
0
      return qi->length;
719
720
2.42G
    fail:
721
2.42G
      ;
722
2.42G
    }
723
724
  /* Fell off the end.  */
725
94.0k
  outfn (stream, ".word\tH'%x,H'%x", data[0], data[1]);
726
94.0k
  return 2;
727
561k
}
728
729
int
730
print_insn_h8300 (bfd_vma addr, disassemble_info *info)
731
503k
{
732
503k
  return bfd_h8_disassemble (addr, info, 0);
733
503k
}
734
735
int
736
print_insn_h8300h (bfd_vma addr, disassemble_info *info)
737
25.0k
{
738
25.0k
  return bfd_h8_disassemble (addr, info, 1);
739
25.0k
}
740
741
int
742
print_insn_h8300s (bfd_vma addr, disassemble_info *info)
743
32.9k
{
744
32.9k
  return bfd_h8_disassemble (addr, info, 2);
745
32.9k
}