Coverage Report

Created: 2026-04-04 08:16

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