Coverage Report

Created: 2026-05-11 07:54

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