Coverage Report

Created: 2026-07-12 09:22

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