Coverage Report

Created: 2025-07-08 11:15

/src/binutils-gdb/opcodes/h8300-dis.c
Line
Count
Source (jump to first uncovered line)
1
/* Disassemble h8300 instructions.
2
   Copyright (C) 1993-2025 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
182k
{
79
182k
  switch (looking_for & SIZE)
80
182k
    {
81
42.4k
    case L_2:
82
42.4k
      *len = 2;
83
42.4k
      *cst = thisnib & 3;
84
85
      /* DISP2 special treatment.  */
86
42.4k
      if ((looking_for & MODE) == DISP)
87
42.4k
  {
88
42.4k
    if (OP_KIND (q->how) == O_MOVAB
89
42.4k
        || OP_KIND (q->how) == O_MOVAW
90
42.4k
        || OP_KIND (q->how) == O_MOVAL)
91
342
      {
92
        /* Handling for mova insn.  */
93
342
        switch (q->args.nib[0] & MODE)
94
342
    {
95
75
    case INDEXB:
96
75
    default:
97
75
      break;
98
267
    case INDEXW:
99
267
      *cst *= 2;
100
267
      break;
101
0
    case INDEXL:
102
0
      *cst *= 4;
103
0
      break;
104
342
    }
105
342
      }
106
42.0k
    else
107
42.0k
      {
108
        /* Handling for non-mova insn.  */
109
42.0k
        switch (OP_SIZE (q->how))
110
42.0k
    {
111
14.5k
    default: break;
112
14.5k
    case SW:
113
5.30k
      *cst *= 2;
114
5.30k
      break;
115
22.2k
    case SL:
116
22.2k
      *cst *= 4;
117
22.2k
      break;
118
42.0k
    }
119
42.0k
      }
120
42.4k
  }
121
42.4k
      break;
122
135k
    case L_8:
123
135k
      *len = 8;
124
135k
      *cst = data[0];
125
135k
      break;
126
2.84k
    case L_16:
127
3.58k
    case L_16U:
128
3.58k
      *len = 16;
129
3.58k
      *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.58k
      break;
135
873
    case L_32:
136
873
      *len = 32;
137
873
      *cst = (((unsigned) data[0] << 24) + (data[1] << 16)
138
873
        + (data[2] << 8) + data[3]);
139
873
      break;
140
0
    default:
141
0
      *len = 0;
142
0
      *cst = 0;
143
0
      fprintf (stream, "DISP bad size\n");
144
0
      break;
145
182k
    }
146
182k
}
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
408k
{
179
408k
  void * stream = info->stream;
180
408k
  fprintf_ftype outfn = info->fprintf_func;
181
182
408k
  if ((x & SIZE) == L_3 || (x & SIZE) == L_3NZ)
183
12.8k
    outfn (stream, "#0x%x", (unsigned) cst);
184
395k
  else if ((x & MODE) == IMM)
185
115k
    outfn (stream, "#0x%x", (unsigned) cst);
186
280k
  else if ((x & MODE) == DBIT || (x & MODE) == KBIT)
187
187
    outfn (stream, "#%d", (unsigned) cst);
188
280k
  else if ((x & MODE) == CONST_2)
189
672
    outfn (stream, "#2");
190
279k
  else if ((x & MODE) == CONST_4)
191
378
    outfn (stream, "#4");
192
279k
  else if ((x & MODE) == CONST_8)
193
389
    outfn (stream, "#8");
194
278k
  else if ((x & MODE) == CONST_16)
195
576
    outfn (stream, "#16");
196
278k
  else if ((x & MODE) == REG)
197
214k
    {
198
214k
      switch (x & SIZE)
199
214k
  {
200
184k
  case L_8:
201
184k
    outfn (stream, "%s", regnames[rn]);
202
184k
    break;
203
25.0k
  case L_16:
204
25.0k
  case L_16U:
205
25.0k
    outfn (stream, "%s", wregnames[rn]);
206
25.0k
    break;
207
0
  case L_P:
208
4.95k
  case L_32:
209
4.95k
    outfn (stream, "%s", lregnames[rn]);
210
4.95k
    break;
211
214k
  }
212
214k
    }
213
63.3k
  else if ((x & MODE) == LOWREG)
214
269
    {
215
269
      switch (x & SIZE)
216
269
  {
217
199
  case L_8:
218
    /* Always take low half of reg.  */
219
199
    outfn (stream, "%s.b", regnames[rn < 8 ? rn + 8 : rn]);
220
199
    break;
221
70
  case L_16:
222
70
  case L_16U:
223
    /* Always take low half of reg.  */
224
70
    outfn (stream, "%s.w", wregnames[rn < 8 ? rn : rn - 8]);
225
70
    break;
226
0
  case L_P:
227
0
  case L_32:
228
0
    outfn (stream, "%s.l", lregnames[rn]);
229
0
    break;
230
269
  }
231
269
    }
232
63.0k
  else if ((x & MODE) == POSTINC)
233
2.18k
    outfn (stream, "@%s+", pregnames[rn]);
234
235
60.8k
  else if ((x & MODE) == POSTDEC)
236
248
    outfn (stream, "@%s-", pregnames[rn]);
237
238
60.6k
  else if ((x & MODE) == PREINC)
239
50
    outfn (stream, "@+%s", pregnames[rn]);
240
241
60.5k
  else if ((x & MODE) == PREDEC)
242
570
    outfn (stream, "@-%s", pregnames[rn]);
243
244
60.0k
  else if ((x & MODE) == IND)
245
3.88k
    outfn (stream, "@%s", pregnames[rn]);
246
247
56.1k
  else if ((x & MODE) == ABS || (x & ABSJMP))
248
30.1k
    outfn (stream, "@0x%x:%d", (unsigned) cst, cstlen);
249
250
25.9k
  else if ((x & MODE) == MEMIND)
251
2.01k
    outfn (stream, "@@%d (0x%x)", cst, cst);
252
253
23.9k
  else if ((x & MODE) == VECIND)
254
992
    {
255
      /* FIXME Multiplier should be 2 or 4, depending on processor mode,
256
   by which is meant "normal" vs. "middle", "advanced", "maximum".  */
257
258
992
      int offset = (cst + 0x80) * 4;
259
992
      outfn (stream, "@@%d (0x%x)", offset, offset);
260
992
    }
261
22.9k
  else if ((x & MODE) == PCREL)
262
8.61k
    {
263
8.61k
      if ((x & SIZE) == L_16 ||
264
8.61k
    (x & SIZE) == L_16U)
265
168
  {
266
168
    outfn (stream, ".%s%d (0x%lx)",
267
168
       (short) cst > 0 ? "+" : "",
268
168
       (short) cst,
269
168
       (long)(addr + (short) cst + len));
270
168
  }
271
8.44k
      else
272
8.44k
  {
273
8.44k
    outfn (stream, ".%s%d (0x%lx)",
274
8.44k
       (char) cst > 0 ? "+" : "",
275
8.44k
       (char) cst,
276
8.44k
       (long)(addr + (char) cst + len));
277
8.44k
  }
278
8.61k
    }
279
14.3k
  else if ((x & MODE) == DISP)
280
2.44k
    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
113
    outfn (stream, "@(0x%x:%d,%s.b)", cst, cstlen,
285
113
     regnames[rdisp_n < 8 ? rdisp_n + 8 : rdisp_n]);
286
287
11.7k
  else if ((x & MODE) == INDEXW)
288
    /* Always take low half of reg.  */
289
117
    outfn (stream, "@(0x%x:%d,%s.w)", cst, cstlen,
290
117
     wregnames[rdisp_n < 8 ? rdisp_n : rdisp_n - 8]);
291
292
11.6k
  else if ((x & MODE) == INDEXL)
293
246
    outfn (stream, "@(0x%x:%d,%s.l)", cst, cstlen, lregnames[rdisp_n]);
294
295
11.4k
  else if (x & CTRL)
296
11.4k
    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
408k
}
311
312
static unsigned int
313
bfd_h8_disassemble (bfd_vma addr, disassemble_info *info, int mach)
314
304k
{
315
  /* Find the first entry in the table for this opcode.  */
316
304k
  int regno[3] = { 0, 0, 0 };
317
304k
  int dispregno[3] = { 0, 0, 0 };
318
304k
  int cst[3] = { 0, 0, 0 };
319
304k
  int cstlen[3] = { 0, 0, 0 };
320
304k
  static bool init = 0;
321
304k
  const struct h8_instruction *qi;
322
304k
  char const **pregnames = mach != 0 ? lregnames : wregnames;
323
304k
  int status;
324
304k
  unsigned int maxlen;
325
304k
  unsigned char data[MAX_CODE_NIBBLES / 2];
326
304k
  void *stream = info->stream;
327
304k
  fprintf_ftype outfn = info->fprintf_func;
328
329
304k
  if (!init)
330
2
    {
331
2
      bfd_h8_disassemble_init ();
332
2
      init = 1;
333
2
    }
334
335
304k
  status = info->read_memory_func (addr, data, 2, info);
336
304k
  if (status != 0)
337
199
    {
338
199
      info->memory_error_func (status, addr, info);
339
199
      return -1;
340
199
    }
341
342
2.42M
  for (maxlen = 2; maxlen < sizeof (data); maxlen += 2)
343
2.12M
    {
344
2.12M
      status = info->read_memory_func (addr + maxlen, data + maxlen, 2, info);
345
2.12M
      if (status != 0)
346
2.86k
  break;
347
2.12M
    }
348
349
  /* Find the exact opcode/arg combo.  */
350
1.29G
  for (qi = h8_instructions; qi->opcode->name; qi++)
351
1.29G
    {
352
1.29G
      const struct h8_opcode *q;
353
1.29G
      const op_type *nib;
354
1.29G
      unsigned int len;
355
1.29G
      op_type looking_for;
356
357
1.29G
      if (qi->length > maxlen)
358
6.05M
  continue;
359
360
1.28G
      q = qi->opcode;
361
1.28G
      nib = q->data.nib;
362
1.28G
      len = 0;
363
1.69G
      while ((looking_for = *nib) != (op_type) E)
364
1.69G
  {
365
1.69G
    int thisnib;
366
1.69G
    int opnr;
367
368
1.69G
    OPCODES_ASSERT (len / 2 < maxlen);
369
1.69G
    thisnib = data[len / 2];
370
1.69G
    thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib / 16) & 0xf);
371
1.69G
    opnr = ((looking_for & OP3) == OP3 ? 2
372
1.69G
      : (looking_for & DST) == DST ? 1 : 0);
373
374
1.69G
    if (looking_for < 16 && looking_for >= 0)
375
1.69G
      {
376
1.69G
        if (looking_for != thisnib)
377
1.28G
    goto fail;
378
1.69G
      }
379
2.84M
    else
380
2.84M
      {
381
2.84M
        if ((int) looking_for & (int) B31)
382
589k
    {
383
589k
      if (!((thisnib & 0x8) != 0))
384
435k
        goto fail;
385
386
153k
      looking_for = (op_type) ((int) looking_for & ~(int) B31);
387
153k
      thisnib &= 0x7;
388
153k
    }
389
2.25M
        else if ((int) looking_for & (int) B30)
390
1.41M
    {
391
1.41M
      if (!((thisnib & 0x8) == 0))
392
335k
        goto fail;
393
394
1.08M
      looking_for = (op_type) ((int) looking_for & ~(int) B30);
395
1.08M
    }
396
397
2.07M
        if ((int) looking_for & (int) B21)
398
325k
    {
399
325k
      if (!((thisnib & 0x4) != 0))
400
288k
        goto fail;
401
402
36.7k
      looking_for = (op_type) ((int) looking_for & ~(int) B21);
403
36.7k
      thisnib &= 0xb;
404
36.7k
    }
405
1.75M
        else if ((int) looking_for & (int) B20)
406
7.44k
    {
407
7.44k
      if (!((thisnib & 0x4) == 0))
408
1.27k
        goto fail;
409
410
6.16k
      looking_for = (op_type) ((int) looking_for & ~(int) B20);
411
6.16k
    }
412
1.78M
        if ((int) looking_for & (int) B11)
413
192
    {
414
192
      if (!((thisnib & 0x2) != 0))
415
0
        goto fail;
416
417
192
      looking_for = (op_type) ((int) looking_for & ~(int) B11);
418
192
      thisnib &= 0xd;
419
192
    }
420
1.78M
        else if ((int) looking_for & (int) B10)
421
192
    {
422
192
      if (!((thisnib & 0x2) == 0))
423
192
        goto fail;
424
425
0
      looking_for = (op_type) ((int) looking_for & ~(int) B10);
426
0
    }
427
428
1.78M
        if ((int) looking_for & (int) B01)
429
1.76k
    {
430
1.76k
      if (!((thisnib & 0x1) != 0))
431
673
        goto fail;
432
433
1.08k
      looking_for = (op_type) ((int) looking_for & ~(int) B01);
434
1.08k
      thisnib &= 0xe;
435
1.08k
    }
436
1.78M
        else if ((int) looking_for & (int) B00)
437
13.5k
    {
438
13.5k
      if (!((thisnib & 0x1) == 0))
439
6.16k
        goto fail;
440
441
7.38k
      looking_for = (op_type) ((int) looking_for & ~(int) B00);
442
7.38k
    }
443
444
1.78M
        if (looking_for & IGNORE)
445
41.0k
    {
446
      /* Hitachi has declared that IGNORE must be zero.  */
447
41.0k
      if (thisnib != 0)
448
38.8k
        goto fail;
449
41.0k
    }
450
1.73M
        else if ((looking_for & MODE) == DATA)
451
292k
    {
452
292k
      ;     /* Skip embedded data.  */
453
292k
    }
454
1.44M
        else if ((looking_for & MODE) == DBIT)
455
2.89k
    {
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
2.89k
      if ((looking_for & 7) != (thisnib & 7))
460
2.61k
        goto fail;
461
462
281
      cst[opnr] = (thisnib & 0x8) ? 2 : 1;
463
281
    }
464
1.44M
        else if ((looking_for & MODE) == DISP
465
1.44M
           || (looking_for & MODE) == ABS
466
1.44M
           || (looking_for & MODE) == PCREL
467
1.44M
           || (looking_for & MODE) == INDEXB
468
1.44M
           || (looking_for & MODE) == INDEXW
469
1.44M
           || (looking_for & MODE) == INDEXL)
470
182k
    {
471
182k
      int extra;
472
182k
      switch (looking_for & SIZE)
473
182k
        {
474
2.84k
        case L_16:
475
3.58k
        case L_16U:
476
3.58k
          extra = 1;
477
3.58k
          break;
478
873
        case L_32:
479
873
          extra = 3;
480
873
          break;
481
178k
        default:
482
178k
          extra = 0;
483
178k
          break;
484
182k
        }
485
182k
      OPCODES_ASSERT (len / 2 + extra < maxlen);
486
182k
      extract_immediate (stream, looking_for, thisnib,
487
182k
             data + len / 2, cst + opnr,
488
182k
             cstlen + opnr, q);
489
      /* Even address == bra, odd == bra/s.  */
490
182k
      if (q->how == O (O_BRAS, SB))
491
516
        cst[opnr] -= 1;
492
182k
    }
493
1.26M
        else if ((looking_for & MODE) == REG
494
1.26M
           || (looking_for & MODE) == LOWREG
495
1.26M
           || (looking_for & MODE) == IND
496
1.26M
           || (looking_for & MODE) == PREINC
497
1.26M
           || (looking_for & MODE) == POSTINC
498
1.26M
           || (looking_for & MODE) == PREDEC
499
1.26M
           || (looking_for & MODE) == POSTDEC)
500
451k
    {
501
451k
      regno[opnr] = thisnib;
502
451k
    }
503
808k
        else if (looking_for & CTRL)  /* Control Register.  */
504
14.4k
    {
505
14.4k
      thisnib &= 7;
506
14.4k
      if (((looking_for & MODE) == CCR  && (thisnib != C_CCR))
507
14.4k
          || ((looking_for & MODE) == EXR  && (thisnib != C_EXR))
508
14.4k
          || ((looking_for & MODE) == MACH && (thisnib != C_MACH))
509
14.4k
          || ((looking_for & MODE) == MACL && (thisnib != C_MACL))
510
14.4k
          || ((looking_for & MODE) == VBR  && (thisnib != C_VBR))
511
14.4k
          || ((looking_for & MODE) == SBR  && (thisnib != C_SBR)))
512
3.56k
        goto fail;
513
10.8k
      if (((looking_for & MODE) == CCR_EXR
514
10.8k
           && (thisnib != C_CCR && thisnib != C_EXR))
515
10.8k
          || ((looking_for & MODE) == VBR_SBR
516
10.2k
        && (thisnib != C_VBR && thisnib != C_SBR))
517
10.8k
          || ((looking_for & MODE) == MACREG
518
9.40k
        && (thisnib != C_MACH && thisnib != C_MACL)))
519
2.91k
        goto fail;
520
7.96k
      if (((looking_for & MODE) == CC_EX_VB_SB
521
7.96k
           && (thisnib != C_CCR && thisnib != C_EXR
522
0
         && thisnib != C_VBR && thisnib != C_SBR)))
523
0
        goto fail;
524
525
7.96k
      regno[opnr] = thisnib;
526
7.96k
    }
527
794k
        else if ((looking_for & SIZE) == L_5)
528
4.56k
    {
529
4.56k
      cst[opnr] = data[len / 2] & 31;
530
4.56k
      cstlen[opnr] = 5;
531
4.56k
    }
532
789k
        else if ((looking_for & SIZE) == L_4)
533
135
    {
534
135
      cst[opnr] = thisnib;
535
135
      cstlen[opnr] = 4;
536
135
    }
537
789k
        else if ((looking_for & SIZE) == L_16
538
789k
           || (looking_for & SIZE) == L_16U)
539
1.53k
    {
540
1.53k
      OPCODES_ASSERT (len / 2 + 1 < maxlen);
541
1.53k
      cst[opnr] = (data[len / 2]) * 256 + data[(len + 2) / 2];
542
1.53k
      cstlen[opnr] = 16;
543
1.53k
    }
544
788k
        else if ((looking_for & MODE) == MEMIND)
545
2.01k
    {
546
2.01k
      cst[opnr] = data[1];
547
2.01k
    }
548
786k
        else if ((looking_for & MODE) == VECIND)
549
992
    {
550
992
      cst[opnr] = data[1] & 0x7f;
551
992
    }
552
785k
        else if ((looking_for & SIZE) == L_32)
553
340
    {
554
340
      unsigned int i = len / 2;
555
556
340
      OPCODES_ASSERT (i + 3 < maxlen);
557
340
      cst[opnr] = (((unsigned) data[i] << 24)
558
340
             | (data[i + 1] << 16)
559
340
             | (data[i + 2] << 8)
560
340
             | (data[i + 3]));
561
562
340
      cstlen[opnr] = 32;
563
340
    }
564
784k
        else if ((looking_for & SIZE) == L_24)
565
1.59k
    {
566
1.59k
      unsigned int i = len / 2;
567
568
1.59k
      OPCODES_ASSERT (i + 2 < maxlen);
569
1.59k
      cst[opnr] =
570
1.59k
        (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]);
571
1.59k
      cstlen[opnr] = 24;
572
1.59k
    }
573
783k
        else if (looking_for & DISPREG)
574
651k
    {
575
651k
      dispregno[opnr] = thisnib & 7;
576
651k
    }
577
131k
        else if ((looking_for & MODE) == KBIT)
578
2.69k
    {
579
2.69k
      switch (thisnib)
580
2.69k
        {
581
119
        case 9:
582
119
          cst[opnr] = 4;
583
119
          break;
584
149
        case 8:
585
149
          cst[opnr] = 2;
586
149
          break;
587
1.34k
        case 0:
588
1.34k
          cst[opnr] = 1;
589
1.34k
          break;
590
1.08k
        default:
591
1.08k
          goto fail;
592
2.69k
        }
593
2.69k
    }
594
128k
        else if ((looking_for & SIZE) == L_8)
595
114k
    {
596
114k
      cstlen[opnr] = 8;
597
114k
      cst[opnr] = data[len / 2];
598
114k
    }
599
14.3k
        else if ((looking_for & SIZE) == L_3
600
14.3k
           || (looking_for & SIZE) == L_3NZ)
601
13.9k
    {
602
13.9k
      cst[opnr] = thisnib & 0x7;
603
13.9k
      if (cst[opnr] == 0 && (looking_for & SIZE) == L_3NZ)
604
828
        goto fail;
605
13.9k
    }
606
402
        else if ((looking_for & SIZE) == L_2)
607
402
    {
608
402
      cstlen[opnr] = 2;
609
402
      cst[opnr] = thisnib & 0x3;
610
402
    }
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.78M
      }
619
620
409M
    len++;
621
409M
    nib++;
622
409M
  }
623
624
257k
      outfn (stream, "%s\t", q->name);
625
626
      /* Gross.  Disgusting.  */
627
257k
      if (strcmp (q->name, "ldm.l") == 0)
628
35
  {
629
35
    int count, high;
630
631
35
    count = (data[1] / 16) & 0x3;
632
35
    high = regno[1];
633
634
35
    outfn (stream, "@sp+,er%d-er%d", high - count, high);
635
35
    return qi->length;
636
35
  }
637
638
257k
      if (strcmp (q->name, "stm.l") == 0)
639
10
  {
640
10
    int count, low;
641
642
10
    count = (data[1] / 16) & 0x3;
643
10
    low = regno[0];
644
645
10
    outfn (stream, "er%d-er%d,@-sp", low, low + count);
646
10
    return qi->length;
647
10
  }
648
257k
      if (strcmp (q->name, "rte/l") == 0
649
257k
    || strcmp (q->name, "rts/l") == 0)
650
1.63k
  {
651
1.63k
    if (regno[0] == 0)
652
252
      outfn (stream, "er%d", regno[1]);
653
1.38k
    else
654
1.38k
      outfn (stream, "er%d-er%d", regno[1] - regno[0],
655
1.38k
       regno[1]);
656
1.63k
    return qi->length;
657
1.63k
  }
658
256k
      if (startswith (q->name, "mova"))
659
251
  {
660
251
    const op_type *args = q->args.nib;
661
662
251
    if (args[1] == (op_type) E)
663
227
      {
664
        /* Short form.  */
665
227
        print_one_arg (info, addr, args[0], cst[0],
666
227
           cstlen[0], dispregno[0], regno[0],
667
227
           pregnames, qi->length);
668
227
        outfn (stream, ",er%d", dispregno[0]);
669
227
      }
670
24
    else
671
24
      {
672
24
        outfn (stream, "@(0x%x:%d,", cst[0], cstlen[0]);
673
24
        print_one_arg (info, addr, args[1], cst[1],
674
24
           cstlen[1], dispregno[1], regno[1],
675
24
           pregnames, qi->length);
676
24
        outfn (stream, ".%c),",
677
24
         (args[0] & MODE) == INDEXB ? 'b' : 'w');
678
24
        print_one_arg (info, addr, args[2], cst[2],
679
24
           cstlen[2], dispregno[2], regno[2],
680
24
           pregnames, qi->length);
681
24
      }
682
251
    return qi->length;
683
251
  }
684
      /* Fill in the args.  */
685
255k
      {
686
255k
  const op_type *args = q->args.nib;
687
255k
  int hadone = 0;
688
255k
  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
255k
  if (strcmp (qi->opcode->name, "adds") == 0
695
255k
      || strcmp (qi->opcode->name, "subs") == 0)
696
1.61k
    {
697
1.61k
      outfn (stream, "#%d,%s", cst[0], pregnames[regno[1] & 0x7]);
698
1.61k
      return qi->length;
699
1.61k
    }
700
701
254k
  for (nargs = 0;
702
662k
       nargs < 3 && args[nargs] != (op_type) E;
703
408k
       nargs++)
704
408k
    {
705
408k
      int x = args[nargs];
706
707
408k
      if (hadone)
708
194k
        outfn (stream, ",");
709
710
408k
      print_one_arg (info, addr, x,
711
408k
         cst[nargs], cstlen[nargs],
712
408k
         dispregno[nargs], regno[nargs],
713
408k
         pregnames, qi->length);
714
715
408k
      hadone = 1;
716
408k
    }
717
254k
      }
718
0
      return qi->length;
719
720
1.28G
    fail:
721
1.28G
      ;
722
1.28G
    }
723
724
  /* Fell off the end.  */
725
46.5k
  outfn (stream, ".word\tH'%x,H'%x", data[0], data[1]);
726
46.5k
  return 2;
727
304k
}
728
729
int
730
print_insn_h8300 (bfd_vma addr, disassemble_info *info)
731
263k
{
732
263k
  return bfd_h8_disassemble (addr, info, 0);
733
263k
}
734
735
int
736
print_insn_h8300h (bfd_vma addr, disassemble_info *info)
737
6.27k
{
738
6.27k
  return bfd_h8_disassemble (addr, info, 1);
739
6.27k
}
740
741
int
742
print_insn_h8300s (bfd_vma addr, disassemble_info *info)
743
34.9k
{
744
34.9k
  return bfd_h8_disassemble (addr, info, 2);
745
34.9k
}