Coverage Report

Created: 2023-08-28 06:30

/src/binutils-gdb/opcodes/h8300-dis.c
Line
Count
Source (jump to first uncovered line)
1
/* Disassemble h8300 instructions.
2
   Copyright (C) 1993-2023 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
2
#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
1
{
44
1
  unsigned int i;
45
1
  unsigned int nopcodes;
46
1
  const struct h8_opcode *p;
47
1
  struct h8_instruction *pi;
48
49
1
  nopcodes = sizeof (h8_opcodes) / sizeof (struct h8_opcode);
50
51
1
  h8_instructions = xmalloc (nopcodes * sizeof (struct h8_instruction));
52
53
8.48k
  for (p = h8_opcodes, pi = h8_instructions; p->name; p++, pi++)
54
8.48k
    {
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
149k
      for (i = 0; p->data.nib[i] != (op_type) E; i++)
58
141k
  ;
59
8.48k
      OPCODES_ASSERT (!(i & 1));
60
61
8.48k
      pi->length = i / 2;
62
8.48k
      pi->opcode = p;
63
8.48k
    }
64
65
  /* Add entry for the NULL vector terminator.  */
66
1
  pi->length = 0;
67
1
  pi->opcode = p;
68
1
}
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
200k
{
79
200k
  switch (looking_for & SIZE)
80
200k
    {
81
57.9k
    case L_2:
82
57.9k
      *len = 2;
83
57.9k
      *cst = thisnib & 3;
84
85
      /* DISP2 special treatment.  */
86
57.9k
      if ((looking_for & MODE) == DISP)
87
57.9k
  {
88
57.9k
    if (OP_KIND (q->how) == O_MOVAB
89
57.9k
        || OP_KIND (q->how) == O_MOVAW
90
57.9k
        || OP_KIND (q->how) == O_MOVAL)
91
6
      {
92
        /* Handling for mova insn.  */
93
6
        switch (q->args.nib[0] & MODE)
94
6
    {
95
6
    case INDEXB:
96
6
    default:
97
6
      break;
98
6
    case INDEXW:
99
0
      *cst *= 2;
100
0
      break;
101
0
    case INDEXL:
102
0
      *cst *= 4;
103
0
      break;
104
6
    }
105
6
      }
106
57.9k
    else
107
57.9k
      {
108
        /* Handling for non-mova insn.  */
109
57.9k
        switch (OP_SIZE (q->how))
110
57.9k
    {
111
4.89k
    default: break;
112
34.9k
    case SW:
113
34.9k
      *cst *= 2;
114
34.9k
      break;
115
18.0k
    case SL:
116
18.0k
      *cst *= 4;
117
18.0k
      break;
118
57.9k
    }
119
57.9k
      }
120
57.9k
  }
121
57.9k
      break;
122
138k
    case L_8:
123
138k
      *len = 8;
124
138k
      *cst = data[0];
125
138k
      break;
126
2.51k
    case L_16:
127
3.09k
    case L_16U:
128
3.09k
      *len = 16;
129
3.09k
      *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.09k
      break;
135
731
    case L_32:
136
731
      *len = 32;
137
731
      *cst = (((unsigned) data[0] << 24) + (data[1] << 16)
138
731
        + (data[2] << 8) + data[3]);
139
731
      break;
140
0
    default:
141
0
      *len = 0;
142
0
      *cst = 0;
143
0
      fprintf (stream, "DISP bad size\n");
144
0
      break;
145
200k
    }
146
200k
}
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
427k
{
179
427k
  void * stream = info->stream;
180
427k
  fprintf_ftype outfn = info->fprintf_func;
181
182
427k
  if ((x & SIZE) == L_3 || (x & SIZE) == L_3NZ)
183
11.7k
    outfn (stream, "#0x%x", (unsigned) cst);
184
415k
  else if ((x & MODE) == IMM)
185
115k
    outfn (stream, "#0x%x", (unsigned) cst);
186
299k
  else if ((x & MODE) == DBIT || (x & MODE) == KBIT)
187
254
    outfn (stream, "#%d", (unsigned) cst);
188
299k
  else if ((x & MODE) == CONST_2)
189
1.00k
    outfn (stream, "#2");
190
298k
  else if ((x & MODE) == CONST_4)
191
235
    outfn (stream, "#4");
192
298k
  else if ((x & MODE) == CONST_8)
193
149
    outfn (stream, "#8");
194
298k
  else if ((x & MODE) == CONST_16)
195
75
    outfn (stream, "#16");
196
298k
  else if ((x & MODE) == REG)
197
231k
    {
198
231k
      switch (x & SIZE)
199
231k
  {
200
192k
  case L_8:
201
192k
    outfn (stream, "%s", regnames[rn]);
202
192k
    break;
203
34.3k
  case L_16:
204
34.3k
  case L_16U:
205
34.3k
    outfn (stream, "%s", wregnames[rn]);
206
34.3k
    break;
207
0
  case L_P:
208
5.47k
  case L_32:
209
5.47k
    outfn (stream, "%s", lregnames[rn]);
210
5.47k
    break;
211
231k
  }
212
231k
    }
213
66.2k
  else if ((x & MODE) == LOWREG)
214
102
    {
215
102
      switch (x & SIZE)
216
102
  {
217
46
  case L_8:
218
    /* Always take low half of reg.  */
219
46
    outfn (stream, "%s.b", regnames[rn < 8 ? rn + 8 : rn]);
220
46
    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
102
  }
231
102
    }
232
66.1k
  else if ((x & MODE) == POSTINC)
233
4.95k
    outfn (stream, "@%s+", pregnames[rn]);
234
235
61.1k
  else if ((x & MODE) == POSTDEC)
236
1
    outfn (stream, "@%s-", pregnames[rn]);
237
238
61.1k
  else if ((x & MODE) == PREINC)
239
6
    outfn (stream, "@+%s", pregnames[rn]);
240
241
61.1k
  else if ((x & MODE) == PREDEC)
242
502
    outfn (stream, "@-%s", pregnames[rn]);
243
244
60.6k
  else if ((x & MODE) == IND)
245
2.80k
    outfn (stream, "@%s", pregnames[rn]);
246
247
57.8k
  else if ((x & MODE) == ABS || (x & ABSJMP))
248
30.9k
    outfn (stream, "@0x%x:%d", (unsigned) cst, cstlen);
249
250
26.8k
  else if ((x & MODE) == MEMIND)
251
1.82k
    outfn (stream, "@@%d (0x%x)", cst, cst);
252
253
25.0k
  else if ((x & MODE) == VECIND)
254
861
    {
255
      /* FIXME Multiplier should be 2 or 4, depending on processor mode,
256
   by which is meant "normal" vs. "middle", "advanced", "maximum".  */
257
258
861
      int offset = (cst + 0x80) * 4;
259
861
      outfn (stream, "@@%d (0x%x)", offset, offset);
260
861
    }
261
24.1k
  else if ((x & MODE) == PCREL)
262
10.0k
    {
263
10.0k
      if ((x & SIZE) == L_16 ||
264
10.0k
    (x & SIZE) == L_16U)
265
101
  {
266
101
    outfn (stream, ".%s%d (0x%lx)",
267
101
       (short) cst > 0 ? "+" : "",
268
101
       (short) cst,
269
101
       (long)(addr + (short) cst + len));
270
101
  }
271
9.99k
      else
272
9.99k
  {
273
9.99k
    outfn (stream, ".%s%d (0x%lx)",
274
9.99k
       (char) cst > 0 ? "+" : "",
275
9.99k
       (char) cst,
276
9.99k
       (long)(addr + (char) cst + len));
277
9.99k
  }
278
10.0k
    }
279
14.0k
  else if ((x & MODE) == DISP)
280
2.30k
    outfn (stream, "@(0x%x:%d,%s)", cst, cstlen, pregnames[rdisp_n]);
281
282
11.7k
  else if ((x & MODE) == INDEXB)
283
    /* Always take low half of reg.  */
284
78
    outfn (stream, "@(0x%x:%d,%s.b)", cst, cstlen,
285
78
     regnames[rdisp_n < 8 ? rdisp_n + 8 : rdisp_n]);
286
287
11.6k
  else if ((x & MODE) == INDEXW)
288
    /* Always take low half of reg.  */
289
115
    outfn (stream, "@(0x%x:%d,%s.w)", cst, cstlen,
290
115
     wregnames[rdisp_n < 8 ? rdisp_n : rdisp_n - 8]);
291
292
11.5k
  else if ((x & MODE) == INDEXL)
293
1
    outfn (stream, "@(0x%x:%d,%s.l)", cst, cstlen, lregnames[rdisp_n]);
294
295
11.5k
  else if (x & CTRL)
296
11.5k
    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
427k
}
311
312
static unsigned int
313
bfd_h8_disassemble (bfd_vma addr, disassemble_info *info, int mach)
314
325k
{
315
  /* Find the first entry in the table for this opcode.  */
316
325k
  int regno[3] = { 0, 0, 0 };
317
325k
  int dispregno[3] = { 0, 0, 0 };
318
325k
  int cst[3] = { 0, 0, 0 };
319
325k
  int cstlen[3] = { 0, 0, 0 };
320
325k
  static bool init = 0;
321
325k
  const struct h8_instruction *qi;
322
325k
  char const **pregnames = mach != 0 ? lregnames : wregnames;
323
325k
  int status;
324
325k
  unsigned int maxlen;
325
325k
  unsigned char data[MAX_CODE_NIBBLES / 2];
326
325k
  void *stream = info->stream;
327
325k
  fprintf_ftype outfn = info->fprintf_func;
328
329
325k
  if (!init)
330
1
    {
331
1
      bfd_h8_disassemble_init ();
332
1
      init = 1;
333
1
    }
334
335
325k
  status = info->read_memory_func (addr, data, 2, info);
336
325k
  if (status != 0)
337
36
    {
338
36
      info->memory_error_func (status, addr, info);
339
36
      return -1;
340
36
    }
341
342
2.59M
  for (maxlen = 2; maxlen < sizeof (data); maxlen += 2)
343
2.27M
    {
344
2.27M
      status = info->read_memory_func (addr + maxlen, data + maxlen, 2, info);
345
2.27M
      if (status != 0)
346
2.04k
  break;
347
2.27M
    }
348
349
  /* Find the exact opcode/arg combo.  */
350
1.43G
  for (qi = h8_instructions; qi->opcode->name; qi++)
351
1.43G
    {
352
1.43G
      const struct h8_opcode *q;
353
1.43G
      const op_type *nib;
354
1.43G
      unsigned int len;
355
1.43G
      op_type looking_for;
356
357
1.43G
      if (qi->length > maxlen)
358
4.29M
  continue;
359
360
1.42G
      q = qi->opcode;
361
1.42G
      nib = q->data.nib;
362
1.42G
      len = 0;
363
1.88G
      while ((looking_for = *nib) != (op_type) E)
364
1.88G
  {
365
1.88G
    int thisnib;
366
1.88G
    int opnr;
367
368
1.88G
    OPCODES_ASSERT (len / 2 < maxlen);
369
1.88G
    thisnib = data[len / 2];
370
1.88G
    thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib / 16) & 0xf);
371
1.88G
    opnr = ((looking_for & OP3) == OP3 ? 2
372
1.88G
      : (looking_for & DST) == DST ? 1 : 0);
373
374
1.88G
    if (looking_for < 16 && looking_for >= 0)
375
1.87G
      {
376
1.87G
        if (looking_for != thisnib)
377
1.42G
    goto fail;
378
1.87G
      }
379
3.19M
    else
380
3.19M
      {
381
3.19M
        if ((int) looking_for & (int) B31)
382
651k
    {
383
651k
      if (!((thisnib & 0x8) != 0))
384
440k
        goto fail;
385
386
210k
      looking_for = (op_type) ((int) looking_for & ~(int) B31);
387
210k
      thisnib &= 0x7;
388
210k
    }
389
2.54M
        else if ((int) looking_for & (int) B30)
390
1.69M
    {
391
1.69M
      if (!((thisnib & 0x8) == 0))
392
386k
        goto fail;
393
394
1.31M
      looking_for = (op_type) ((int) looking_for & ~(int) B30);
395
1.31M
    }
396
397
2.36M
        if ((int) looking_for & (int) B21)
398
487k
    {
399
487k
      if (!((thisnib & 0x4) != 0))
400
437k
        goto fail;
401
402
50.3k
      looking_for = (op_type) ((int) looking_for & ~(int) B21);
403
50.3k
      thisnib &= 0xb;
404
50.3k
    }
405
1.87M
        else if ((int) looking_for & (int) B20)
406
9.04k
    {
407
9.04k
      if (!((thisnib & 0x4) == 0))
408
1.34k
        goto fail;
409
410
7.70k
      looking_for = (op_type) ((int) looking_for & ~(int) B20);
411
7.70k
    }
412
1.92M
        if ((int) looking_for & (int) B11)
413
0
    {
414
0
      if (!((thisnib & 0x2) != 0))
415
0
        goto fail;
416
417
0
      looking_for = (op_type) ((int) looking_for & ~(int) B11);
418
0
      thisnib &= 0xd;
419
0
    }
420
1.92M
        else if ((int) looking_for & (int) B10)
421
0
    {
422
0
      if (!((thisnib & 0x2) == 0))
423
0
        goto fail;
424
425
0
      looking_for = (op_type) ((int) looking_for & ~(int) B10);
426
0
    }
427
428
1.92M
        if ((int) looking_for & (int) B01)
429
2.08k
    {
430
2.08k
      if (!((thisnib & 0x1) != 0))
431
875
        goto fail;
432
433
1.21k
      looking_for = (op_type) ((int) looking_for & ~(int) B01);
434
1.21k
      thisnib &= 0xe;
435
1.21k
    }
436
1.92M
        else if ((int) looking_for & (int) B00)
437
18.6k
    {
438
18.6k
      if (!((thisnib & 0x1) == 0))
439
9.89k
        goto fail;
440
441
8.80k
      looking_for = (op_type) ((int) looking_for & ~(int) B00);
442
8.80k
    }
443
444
1.91M
        if (looking_for & IGNORE)
445
31.5k
    {
446
      /* Hitachi has declared that IGNORE must be zero.  */
447
31.5k
      if (thisnib != 0)
448
27.7k
        goto fail;
449
31.5k
    }
450
1.88M
        else if ((looking_for & MODE) == DATA)
451
287k
    {
452
287k
      ;     /* Skip embedded data.  */
453
287k
    }
454
1.59M
        else if ((looking_for & MODE) == DBIT)
455
3.06k
    {
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
3.06k
      if ((looking_for & 7) != (thisnib & 7))
460
2.70k
        goto fail;
461
462
360
      cst[opnr] = (thisnib & 0x8) ? 2 : 1;
463
360
    }
464
1.59M
        else if ((looking_for & MODE) == DISP
465
1.59M
           || (looking_for & MODE) == ABS
466
1.59M
           || (looking_for & MODE) == PCREL
467
1.59M
           || (looking_for & MODE) == INDEXB
468
1.59M
           || (looking_for & MODE) == INDEXW
469
1.59M
           || (looking_for & MODE) == INDEXL)
470
200k
    {
471
200k
      int extra;
472
200k
      switch (looking_for & SIZE)
473
200k
        {
474
2.51k
        case L_16:
475
3.09k
        case L_16U:
476
3.09k
          extra = 1;
477
3.09k
          break;
478
731
        case L_32:
479
731
          extra = 3;
480
731
          break;
481
196k
        default:
482
196k
          extra = 0;
483
196k
          break;
484
200k
        }
485
200k
      OPCODES_ASSERT (len / 2 + extra < maxlen);
486
200k
      extract_immediate (stream, looking_for, thisnib,
487
200k
             data + len / 2, cst + opnr,
488
200k
             cstlen + opnr, q);
489
      /* Even address == bra, odd == bra/s.  */
490
200k
      if (q->how == O (O_BRAS, SB))
491
471
        cst[opnr] -= 1;
492
200k
    }
493
1.39M
        else if ((looking_for & MODE) == REG
494
1.39M
           || (looking_for & MODE) == LOWREG
495
1.39M
           || (looking_for & MODE) == IND
496
1.39M
           || (looking_for & MODE) == PREINC
497
1.39M
           || (looking_for & MODE) == POSTINC
498
1.39M
           || (looking_for & MODE) == PREDEC
499
1.39M
           || (looking_for & MODE) == POSTDEC)
500
392k
    {
501
392k
      regno[opnr] = thisnib;
502
392k
    }
503
1.00M
        else if (looking_for & CTRL)  /* Control Register.  */
504
13.8k
    {
505
13.8k
      thisnib &= 7;
506
13.8k
      if (((looking_for & MODE) == CCR  && (thisnib != C_CCR))
507
13.8k
          || ((looking_for & MODE) == EXR  && (thisnib != C_EXR))
508
13.8k
          || ((looking_for & MODE) == MACH && (thisnib != C_MACH))
509
13.8k
          || ((looking_for & MODE) == MACL && (thisnib != C_MACL))
510
13.8k
          || ((looking_for & MODE) == VBR  && (thisnib != C_VBR))
511
13.8k
          || ((looking_for & MODE) == SBR  && (thisnib != C_SBR)))
512
3.81k
        goto fail;
513
10.0k
      if (((looking_for & MODE) == CCR_EXR
514
10.0k
           && (thisnib != C_CCR && thisnib != C_EXR))
515
10.0k
          || ((looking_for & MODE) == VBR_SBR
516
8.41k
        && (thisnib != C_VBR && thisnib != C_SBR))
517
10.0k
          || ((looking_for & MODE) == MACREG
518
7.63k
        && (thisnib != C_MACH && thisnib != C_MACL)))
519
3.80k
        goto fail;
520
6.22k
      if (((looking_for & MODE) == CC_EX_VB_SB
521
6.22k
           && (thisnib != C_CCR && thisnib != C_EXR
522
0
         && thisnib != C_VBR && thisnib != C_SBR)))
523
0
        goto fail;
524
525
6.22k
      regno[opnr] = thisnib;
526
6.22k
    }
527
987k
        else if ((looking_for & SIZE) == L_5)
528
4.03k
    {
529
4.03k
      cst[opnr] = data[len / 2] & 31;
530
4.03k
      cstlen[opnr] = 5;
531
4.03k
    }
532
983k
        else if ((looking_for & SIZE) == L_4)
533
128
    {
534
128
      cst[opnr] = thisnib;
535
128
      cstlen[opnr] = 4;
536
128
    }
537
983k
        else if ((looking_for & SIZE) == L_16
538
983k
           || (looking_for & SIZE) == L_16U)
539
689
    {
540
689
      OPCODES_ASSERT (len / 2 + 1 < maxlen);
541
689
      cst[opnr] = (data[len / 2]) * 256 + data[(len + 2) / 2];
542
689
      cstlen[opnr] = 16;
543
689
    }
544
982k
        else if ((looking_for & MODE) == MEMIND)
545
1.82k
    {
546
1.82k
      cst[opnr] = data[1];
547
1.82k
    }
548
980k
        else if ((looking_for & MODE) == VECIND)
549
861
    {
550
861
      cst[opnr] = data[1] & 0x7f;
551
861
    }
552
979k
        else if ((looking_for & SIZE) == L_32)
553
197
    {
554
197
      unsigned int i = len / 2;
555
556
197
      OPCODES_ASSERT (i + 3 < maxlen);
557
197
      cst[opnr] = (((unsigned) data[i] << 24)
558
197
             | (data[i + 1] << 16)
559
197
             | (data[i + 2] << 8)
560
197
             | (data[i + 3]));
561
562
197
      cstlen[opnr] = 32;
563
197
    }
564
979k
        else if ((looking_for & SIZE) == L_24)
565
1.28k
    {
566
1.28k
      unsigned int i = len / 2;
567
568
1.28k
      OPCODES_ASSERT (i + 2 < maxlen);
569
1.28k
      cst[opnr] =
570
1.28k
        (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]);
571
1.28k
      cstlen[opnr] = 24;
572
1.28k
    }
573
978k
        else if (looking_for & DISPREG)
574
847k
    {
575
847k
      dispregno[opnr] = thisnib & 7;
576
847k
    }
577
130k
        else if ((looking_for & MODE) == KBIT)
578
1.85k
    {
579
1.85k
      switch (thisnib)
580
1.85k
        {
581
63
        case 9:
582
63
          cst[opnr] = 4;
583
63
          break;
584
124
        case 8:
585
124
          cst[opnr] = 2;
586
124
          break;
587
524
        case 0:
588
524
          cst[opnr] = 1;
589
524
          break;
590
1.14k
        default:
591
1.14k
          goto fail;
592
1.85k
        }
593
1.85k
    }
594
129k
        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.1k
        else if ((looking_for & SIZE) == L_3
600
14.1k
           || (looking_for & SIZE) == L_3NZ)
601
13.4k
    {
602
13.4k
      cst[opnr] = thisnib & 0x7;
603
13.4k
      if (cst[opnr] == 0 && (looking_for & SIZE) == L_3NZ)
604
1.54k
        goto fail;
605
13.4k
    }
606
660
        else if ((looking_for & SIZE) == L_2)
607
660
    {
608
660
      cstlen[opnr] = 2;
609
660
      cst[opnr] = thisnib & 0x3;
610
660
    }
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.91M
      }
619
620
453M
    len++;
621
453M
    nib++;
622
453M
  }
623
624
268k
      outfn (stream, "%s\t", q->name);
625
626
      /* Gross.  Disgusting.  */
627
268k
      if (strcmp (q->name, "ldm.l") == 0)
628
0
  {
629
0
    int count, high;
630
631
0
    count = (data[1] / 16) & 0x3;
632
0
    high = regno[1];
633
634
0
    outfn (stream, "@sp+,er%d-er%d", high - count, high);
635
0
    return qi->length;
636
0
  }
637
638
268k
      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
268k
      if (strcmp (q->name, "rte/l") == 0
649
268k
    || strcmp (q->name, "rts/l") == 0)
650
1.15k
  {
651
1.15k
    if (regno[0] == 0)
652
379
      outfn (stream, "er%d", regno[1]);
653
772
    else
654
772
      outfn (stream, "er%d-er%d", regno[1] - regno[0],
655
772
       regno[1]);
656
1.15k
    return qi->length;
657
1.15k
  }
658
267k
      if (startswith (q->name, "mova"))
659
185
  {
660
185
    const op_type *args = q->args.nib;
661
662
185
    if (args[1] == (op_type) E)
663
185
      {
664
        /* Short form.  */
665
185
        print_one_arg (info, addr, args[0], cst[0],
666
185
           cstlen[0], dispregno[0], regno[0],
667
185
           pregnames, qi->length);
668
185
        outfn (stream, ",er%d", dispregno[0]);
669
185
      }
670
0
    else
671
0
      {
672
0
        outfn (stream, "@(0x%x:%d,", cst[0], cstlen[0]);
673
0
        print_one_arg (info, addr, args[1], cst[1],
674
0
           cstlen[1], dispregno[1], regno[1],
675
0
           pregnames, qi->length);
676
0
        outfn (stream, ".%c),",
677
0
         (args[0] & MODE) == INDEXB ? 'b' : 'w');
678
0
        print_one_arg (info, addr, args[2], cst[2],
679
0
           cstlen[2], dispregno[2], regno[2],
680
0
           pregnames, qi->length);
681
0
      }
682
185
    return qi->length;
683
185
  }
684
      /* Fill in the args.  */
685
267k
      {
686
267k
  const op_type *args = q->args.nib;
687
267k
  int hadone = 0;
688
267k
  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
267k
  if (strcmp (qi->opcode->name, "adds") == 0
695
267k
      || strcmp (qi->opcode->name, "subs") == 0)
696
711
    {
697
711
      outfn (stream, "#%d,%s", cst[0], pregnames[regno[1] & 0x7]);
698
711
      return qi->length;
699
711
    }
700
701
266k
  for (nargs = 0;
702
694k
       nargs < 3 && args[nargs] != (op_type) E;
703
427k
       nargs++)
704
427k
    {
705
427k
      int x = args[nargs];
706
707
427k
      if (hadone)
708
200k
        outfn (stream, ",");
709
710
427k
      print_one_arg (info, addr, x,
711
427k
         cst[nargs], cstlen[nargs],
712
427k
         dispregno[nargs], regno[nargs],
713
427k
         pregnames, qi->length);
714
715
427k
      hadone = 1;
716
427k
    }
717
266k
      }
718
0
      return qi->length;
719
720
1.42G
    fail:
721
1.42G
      ;
722
1.42G
    }
723
724
  /* Fell off the end.  */
725
56.7k
  outfn (stream, ".word\tH'%x,H'%x", data[0], data[1]);
726
56.7k
  return 2;
727
325k
}
728
729
int
730
print_insn_h8300 (bfd_vma addr, disassemble_info *info)
731
325k
{
732
325k
  return bfd_h8_disassemble (addr, info, 0);
733
325k
}
734
735
int
736
print_insn_h8300h (bfd_vma addr, disassemble_info *info)
737
0
{
738
0
  return bfd_h8_disassemble (addr, info, 1);
739
0
}
740
741
int
742
print_insn_h8300s (bfd_vma addr, disassemble_info *info)
743
0
{
744
0
  return bfd_h8_disassemble (addr, info, 2);
745
0
}