Coverage Report

Created: 2026-03-10 08:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/z80-dis.c
Line
Count
Source
1
/* Print Z80, Z180, EZ80 and R800 instructions
2
   Copyright (C) 2005-2026 Free Software Foundation, Inc.
3
   Contributed by Arnold Metselaar <arnold_m@operamail.com>
4
5
   This file is part of the GNU opcodes library.
6
7
   This library is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3, or (at your option)
10
   any later version.
11
12
   It is distributed in the hope that it will be useful, but WITHOUT
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15
   License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
#include "sysdep.h"
23
#include "disassemble.h"
24
#include <stdio.h>
25
26
struct buffer
27
{
28
  bfd_vma base;
29
  int n_fetch;
30
  int n_used;
31
  signed char data[6];
32
  long inss; /* instruction set bit mask, taken from bfd_mach */
33
  int nn_len; /* address length: 2 - Z80 mode, 3 - ADL mode*/
34
} ;
35
36
typedef int (*func)(struct buffer *, disassemble_info *, const char *);
37
38
struct tab_elt
39
{
40
  unsigned char val;
41
  unsigned char mask;
42
  func          fp;
43
  const char *  text;
44
  unsigned      inss; /* bit mask of supported bfd_mach_* or 0 for all mach */
45
} ;
46
47
#define INSS_ALL 0
48
#define INSS_Z80 ((1 << bfd_mach_z80) | (1 << bfd_mach_z80strict) | (1 << bfd_mach_z80full))
49
#define INSS_R800 (1 << bfd_mach_r800)
50
376k
#define INSS_GBZ80 (1 << bfd_mach_gbz80)
51
#define INSS_Z180 (1 << bfd_mach_z180)
52
406k
#define INSS_EZ80_Z80 (1 << bfd_mach_ez80_z80)
53
406k
#define INSS_EZ80_ADL (1 << bfd_mach_ez80_adl)
54
406k
#define INSS_EZ80 (INSS_EZ80_ADL | INSS_EZ80_Z80)
55
#define INSS_Z80N (1 << bfd_mach_z80n)
56
57
42.5k
#define TXTSIZ 24
58
/* Names of 16-bit registers.  */
59
static const char * rr_str[] = { "bc", "de", "hl", "sp" };
60
/* Names of 8-bit registers.  */
61
static const char * r_str[]  = { "b", "c", "d", "e", "h", "l", "(hl)", "a" };
62
/* Texts for condition codes.  */
63
static const char * cc_str[] = { "nz", "z", "nc", "c", "po", "pe", "p", "m" };
64
/* Instruction names for 8-bit arithmetic, operand "a" is often implicit */
65
static const char * arit_str[] =
66
{
67
  "add a,", "adc a,", "sub ", "sbc a,", "and ", "xor ", "or ", "cp "
68
} ;
69
static const char * arit_str_gbz80[] =
70
{
71
  "add a,", "adc a,", "sub a,", "sbc a,", "and ", "xor ", "or ", "cp "
72
} ;
73
static const char * arit_str_ez80[] =
74
{
75
  "add a,", "adc a,", "sub a,", "sbc a,", "and a,", "xor a,", "or a,", "cp a,"
76
} ;
77
78

79
static int
80
mach_inst (struct buffer *buf, const struct tab_elt *p)
81
366k
{
82
366k
  return !p->inss || (p->inss & buf->inss);
83
366k
}
84
85
static int
86
fetch_data (struct buffer *buf, disassemble_info * info, int n)
87
419k
{
88
419k
  int r;
89
90
419k
  if (buf->n_fetch + n > (int)sizeof (buf->data))
91
0
    abort ();
92
93
419k
  r = info->read_memory_func (buf->base + buf->n_fetch,
94
419k
            (unsigned char*) buf->data + buf->n_fetch,
95
419k
            n, info);
96
419k
  if (r == 0)
97
419k
    buf->n_fetch += n;
98
125
  else
99
125
    info->memory_error_func (r, buf->base + buf->n_fetch, info);
100
419k
  return !r;
101
419k
}
102
103
static int
104
prt (struct buffer *buf, disassemble_info * info, const char *txt)
105
115k
{
106
115k
  info->fprintf_func (info->stream, "%s", txt);
107
115k
  buf->n_used = buf->n_fetch;
108
115k
  return 1;
109
115k
}
110
111
static int
112
prt_e (struct buffer *buf, disassemble_info * info, const char *txt)
113
7.69k
{
114
7.69k
  if (fetch_data (buf, info, 1))
115
7.68k
    {
116
7.68k
      signed char e = buf->data[1];
117
7.68k
      int target_addr = (buf->base + 2 + e) & 0xffff;
118
7.68k
      buf->n_used = buf->n_fetch;
119
7.68k
      info->fprintf_func (info->stream, "%s0x%04x", txt, target_addr);
120
7.68k
    }
121
12
  else
122
12
    buf->n_used = -1;
123
124
7.69k
  return buf->n_used;
125
7.69k
}
126
127
static int
128
jr_cc (struct buffer *buf, disassemble_info * info, const char *txt)
129
5.19k
{
130
5.19k
  char mytxt[TXTSIZ];
131
132
5.19k
  snprintf (mytxt, TXTSIZ, txt, cc_str[(buf->data[0] >> 3) & 3]);
133
5.19k
  return prt_e (buf, info, mytxt);
134
5.19k
}
135
136
static int
137
prt_nn (struct buffer *buf, disassemble_info * info, const char *txt)
138
18.2k
{
139
18.2k
  int nn;
140
18.2k
  unsigned char *p;
141
18.2k
  int i;
142
143
18.2k
  p = (unsigned char*) buf->data + buf->n_fetch;
144
18.2k
  if (fetch_data (buf, info, buf->nn_len))
145
18.1k
    {
146
18.1k
      nn = 0;
147
18.1k
      i = buf->nn_len;
148
62.8k
      while (i--)
149
44.6k
        nn = nn * 0x100 + p[i];
150
18.1k
      info->fprintf_func (info->stream, txt, nn);
151
18.1k
      buf->n_used = buf->n_fetch;
152
18.1k
    }
153
61
  else
154
61
    buf->n_used = -1;
155
18.2k
  return buf->n_used;
156
18.2k
}
157
158
static int
159
prt_rr_nn (struct buffer *buf, disassemble_info * info, const char *txt)
160
8.29k
{
161
8.29k
  char mytxt[TXTSIZ];
162
8.29k
  int rr;
163
164
8.29k
  rr = (buf->data[buf->n_fetch - 1] >> 4) & 3;
165
8.29k
  snprintf (mytxt, TXTSIZ, txt, rr_str[rr]);
166
8.29k
  return prt_nn (buf, info, mytxt);
167
8.29k
}
168
169
static int
170
prt_rr (struct buffer *buf, disassemble_info * info, const char *txt)
171
13.2k
{
172
13.2k
  info->fprintf_func (info->stream, "%s%s", txt,
173
13.2k
          rr_str[(buf->data[buf->n_fetch - 1] >> 4) & 3]);
174
13.2k
  buf->n_used = buf->n_fetch;
175
13.2k
  return buf->n_used;
176
13.2k
}
177
178
static int
179
prt_n (struct buffer *buf, disassemble_info * info, const char *txt)
180
15.3k
{
181
15.3k
  int n;
182
15.3k
  unsigned char *p;
183
184
15.3k
  p = (unsigned char*) buf->data + buf->n_fetch;
185
186
15.3k
  if (fetch_data (buf, info, 1))
187
15.2k
    {
188
15.2k
      n = p[0];
189
15.2k
      info->fprintf_func (info->stream, txt, n);
190
15.2k
      buf->n_used = buf->n_fetch;
191
15.2k
    }
192
23
  else
193
23
    buf->n_used = -1;
194
195
15.3k
  return buf->n_used;
196
15.3k
}
197
198
static int
199
prt_n_n (struct buffer *buf, disassemble_info * info, const char *txt)
200
31
{
201
31
  char mytxt[TXTSIZ];
202
31
  int n;
203
31
  unsigned char *p;
204
205
31
  p = (unsigned char*) buf->data + buf->n_fetch;
206
207
31
  if (fetch_data (buf, info, 1))
208
31
    {
209
31
      n = p[0];
210
31
      snprintf (mytxt, TXTSIZ, txt, n);
211
31
      buf->n_used = buf->n_fetch;
212
31
    }
213
0
  else
214
0
    buf->n_used = -1;
215
216
31
  return prt_n (buf, info, mytxt);
217
31
}
218
219
static int
220
prt_r_n (struct buffer *buf, disassemble_info * info, const char *txt)
221
251
{
222
251
  char mytxt[TXTSIZ];
223
251
  int r;
224
225
251
  r = (buf->data[buf->n_fetch - 1] >> 3) & 7;
226
251
  snprintf (mytxt, TXTSIZ, txt, r_str[r]);
227
251
  return prt_n (buf, info, mytxt);
228
251
}
229
230
static int
231
ld_r_n (struct buffer *buf, disassemble_info * info, const char *txt)
232
8.89k
{
233
8.89k
  char mytxt[TXTSIZ];
234
235
8.89k
  snprintf (mytxt, TXTSIZ, txt, r_str[(buf->data[buf->n_fetch - 1] >> 3) & 7]);
236
8.89k
  return prt_n (buf, info, mytxt);
237
8.89k
}
238
239
static int
240
prt_r (struct buffer *buf, disassemble_info * info, const char *txt)
241
16.5k
{
242
16.5k
  info->fprintf_func (info->stream, txt,
243
16.5k
          r_str[(buf->data[buf->n_fetch - 1] >> 3) & 7]);
244
16.5k
  buf->n_used = buf->n_fetch;
245
16.5k
  return buf->n_used;
246
16.5k
}
247
248
static int
249
ld_r_r (struct buffer *buf, disassemble_info * info, const char *txt)
250
56.3k
{
251
56.3k
  info->fprintf_func (info->stream, txt,
252
56.3k
          r_str[(buf->data[buf->n_fetch - 1] >> 3) & 7],
253
56.3k
          r_str[buf->data[buf->n_fetch - 1] & 7]);
254
56.3k
  buf->n_used = buf->n_fetch;
255
56.3k
  return buf->n_used;
256
56.3k
}
257
258
static int
259
prt_d (struct buffer *buf, disassemble_info * info, const char *txt)
260
1.58k
{
261
1.58k
  int d;
262
1.58k
  signed char *p;
263
264
1.58k
  p = buf->data + buf->n_fetch;
265
266
1.58k
  if (fetch_data (buf, info, 1))
267
1.57k
    {
268
1.57k
      d = p[0];
269
1.57k
      info->fprintf_func (info->stream, txt, d);
270
1.57k
      buf->n_used = buf->n_fetch;
271
1.57k
    }
272
9
  else
273
9
    buf->n_used = -1;
274
275
1.58k
  return buf->n_used;
276
1.58k
}
277
278
static int
279
prt_rr_d (struct buffer *buf, disassemble_info * info, const char *txt)
280
86
{
281
86
  char mytxt[TXTSIZ];
282
86
  int rr;
283
284
86
  rr = (buf->data[buf->n_fetch - 1] >> 4) & 3;
285
86
  if (rr == 3) /* SP is not supported */
286
0
    return 0;
287
288
86
  snprintf (mytxt, TXTSIZ, txt, rr_str[rr]);
289
86
  return prt_d (buf, info, mytxt);
290
86
}
291
292
static int
293
arit_r (struct buffer *buf, disassemble_info * info, const char *txt)
294
49.7k
{
295
49.7k
  const char * const *arit;
296
297
49.7k
  if (buf->inss & INSS_EZ80)
298
30.8k
    arit = arit_str_ez80;
299
18.9k
  else if (buf->inss & INSS_GBZ80)
300
3.92k
    arit = arit_str_gbz80;
301
14.9k
  else
302
14.9k
    arit = arit_str;
303
304
49.7k
  info->fprintf_func (info->stream, txt,
305
49.7k
                      arit[(buf->data[buf->n_fetch - 1] >> 3) & 7],
306
49.7k
                      r_str[buf->data[buf->n_fetch - 1] & 7]);
307
49.7k
  buf->n_used = buf->n_fetch;
308
49.7k
  return buf->n_used;
309
49.7k
}
310
311
static int
312
prt_cc (struct buffer *buf, disassemble_info * info, const char *txt)
313
5.48k
{
314
5.48k
  info->fprintf_func (info->stream, "%s%s", txt,
315
5.48k
          cc_str[(buf->data[0] >> 3) & 7]);
316
5.48k
  buf->n_used = buf->n_fetch;
317
5.48k
  return buf->n_used;
318
5.48k
}
319
320
static int
321
pop_rr (struct buffer *buf, disassemble_info * info, const char *txt)
322
4.53k
{
323
4.53k
  static char *rr_stack[] = { "bc","de","hl","af"};
324
325
4.53k
  info->fprintf_func (info->stream, "%s %s", txt,
326
4.53k
          rr_stack[(buf->data[0] >> 4) & 3]);
327
4.53k
  buf->n_used = buf->n_fetch;
328
4.53k
  return buf->n_used;
329
4.53k
}
330
331
332
static int
333
jp_cc_nn (struct buffer *buf, disassemble_info * info, const char *txt)
334
6.42k
{
335
6.42k
  char mytxt[TXTSIZ];
336
337
6.42k
  snprintf (mytxt,TXTSIZ,
338
6.42k
      "%s%s,0x%%04x", txt, cc_str[(buf->data[0] >> 3) & 7]);
339
6.42k
  return prt_nn (buf, info, mytxt);
340
6.42k
}
341
342
static int
343
arit_n (struct buffer *buf, disassemble_info * info, const char *txt)
344
4.51k
{
345
4.51k
  char mytxt[TXTSIZ];
346
4.51k
  const char * const *arit;
347
348
4.51k
  if (buf->inss & INSS_EZ80)
349
2.73k
    arit = arit_str_ez80;
350
1.78k
  else if (buf->inss & INSS_GBZ80)
351
283
    arit = arit_str_gbz80;
352
1.50k
  else
353
1.50k
    arit = arit_str;
354
355
4.51k
  snprintf (mytxt,TXTSIZ, txt, arit[(buf->data[0] >> 3) & 7]);
356
4.51k
  return prt_n (buf, info, mytxt);
357
4.51k
}
358
359
static int
360
rst (struct buffer *buf, disassemble_info * info, const char *txt)
361
34.2k
{
362
34.2k
  info->fprintf_func (info->stream, txt, buf->data[0] & 0x38);
363
34.2k
  buf->n_used = buf->n_fetch;
364
34.2k
  return buf->n_used;
365
34.2k
}
366
367
368
static int
369
cis (struct buffer *buf, disassemble_info * info, const char *txt ATTRIBUTE_UNUSED)
370
399
{
371
399
  static char * opar[] = { "ld", "cp", "in", "out" };
372
399
  char * op;
373
399
  char c;
374
375
399
  c = buf->data[1];
376
399
  op = ((0x13 & c) == 0x13) ? "ot" : (opar[c & 3]);
377
399
  info->fprintf_func (info->stream,
378
399
          "%s%c%s", op,
379
399
          (c & 0x08) ? 'd' : 'i',
380
399
          (c & 0x10) ? "r" : "");
381
399
  buf->n_used = 2;
382
399
  return buf->n_used;
383
399
}
384
385
static int
386
cism (struct buffer *buf, disassemble_info * info, const char *txt ATTRIBUTE_UNUSED)
387
302
{
388
302
  static char * opar[] = { "in%cm%s", "ot%cm%s" };
389
302
  char * op;
390
302
  char c;
391
392
302
  c = buf->data[1];
393
302
  op = opar[c & 1];
394
302
  info->fprintf_func (info->stream,
395
302
                      op,
396
302
                      (c & 0x08) ? 'd' : 'i',
397
302
                      (c & 0x10) ? "r" : "");
398
302
  buf->n_used = 2;
399
302
  return buf->n_used;
400
302
}
401
402
static int
403
dump (struct buffer *buf, disassemble_info * info, const char *txt)
404
5.36k
{
405
5.36k
  int i;
406
407
5.36k
  info->fprintf_func (info->stream, "defb ");
408
12.3k
  for (i = 0; txt[i]; ++i)
409
6.94k
    info->fprintf_func (info->stream, i ? ", 0x%02x" : "0x%02x",
410
6.94k
      (unsigned char) buf->data[i]);
411
5.36k
  buf->n_used = i;
412
5.36k
  return buf->n_used;
413
5.36k
}
414
415
/* Table to disassemble machine codes with prefix 0xED.  */
416
static const struct tab_elt opc_ed[] =
417
{
418
  { 0x30, 0xFF, prt, "mul d,e", INSS_Z80N },
419
  { 0x31, 0xFF, prt, "add hl,a", INSS_Z80N },
420
  { 0x31, 0xFF, prt, "ld iy,(hl)", INSS_EZ80 },
421
  { 0x30, 0xFE, dump, "xx", INSS_ALL }, /* do not move this line */
422
  { 0x00, 0xC7, prt_r_n, "in0 %s,(0x%%02x)", INSS_Z180|INSS_EZ80 },
423
  { 0x01, 0xC7, prt_r_n, "out0 (0x%%02x),%s", INSS_Z180|INSS_EZ80 },
424
  { 0x32, 0xFF, prt_d, "lea ix,ix%+d", INSS_EZ80 },
425
  { 0x33, 0xFF, prt_d, "lea iy,iy%+d", INSS_EZ80 },
426
  { 0x02, 0xCF, prt_rr_d, "lea %s,ix%%+d", INSS_EZ80 },
427
  { 0x03, 0xCF, prt_rr_d, "lea %s,iy%%+d", INSS_EZ80 },
428
  { 0x04, 0xC7, prt_r, "tst %s", INSS_Z180},
429
  { 0x04, 0xC7, prt_r, "tst a,%s", INSS_EZ80 },
430
  { 0x07, 0xFF, prt, "ld bc,(hl)", INSS_EZ80 },
431
  { 0x3F, 0xFF, prt, "ld (hl),ix", INSS_EZ80 },
432
  { 0x0F, 0xCF, prt_rr, "ld (hl),", INSS_EZ80 },
433
  { 0x17, 0xFF, prt, "ld de,(hl)", INSS_EZ80 },
434
  { 0x23, 0xFF, prt, "swapnib", INSS_Z80N },
435
  { 0x24, 0xFF, prt, "mirror", INSS_Z80N },
436
  { 0x27, 0xFF, prt, "ld hl,(hl)", INSS_EZ80 },
437
  { 0x27, 0xFF, prt_n, "test 0x%02x", INSS_Z80N },
438
  { 0x28, 0xFF, prt, "bsla de,b", INSS_Z80N },
439
  { 0x29, 0xFF, prt, "bsra de,b", INSS_Z80N },
440
  { 0x2A, 0xFF, prt, "bsrl de,b", INSS_Z80N },
441
  { 0x2B, 0xFF, prt, "bsrf de,b", INSS_Z80N },
442
  { 0x2C, 0xFF, prt, "bslc de,b", INSS_Z80N },
443
  { 0x32, 0xFF, prt, "add de,a", INSS_Z80N },
444
  { 0x33, 0xFF, prt, "add bc,a", INSS_Z80N },
445
  { 0x34, 0xFF, prt_nn, "add hl,0x%04x", INSS_Z80N },
446
  { 0x35, 0xFF, prt_nn, "add de,0x%04x", INSS_Z80N },
447
  { 0x36, 0xFF, prt_nn, "add bc,0x%04x", INSS_Z80N },
448
  { 0x37, 0xFF, prt, "ld ix,(hl)", INSS_EZ80 },
449
  { 0x3E, 0xFF, prt, "ld (hl),iy", INSS_EZ80 },
450
  { 0x70, 0xFF, prt, "in f,(c)", INSS_Z80 | INSS_R800 | INSS_Z80N },
451
  { 0x70, 0xFF, dump, "xx", INSS_ALL },
452
  { 0x40, 0xC7, prt_r, "in %s,(bc)", INSS_EZ80 },
453
  { 0x40, 0xC7, prt_r, "in %s,(c)", INSS_ALL },
454
  { 0x71, 0xFF, prt, "out (c),0", INSS_Z80 | INSS_Z80N },
455
  { 0x71, 0xFF, dump, "xx", INSS_ALL },
456
  { 0x41, 0xC7, prt_r, "out (bc),%s", INSS_EZ80 },
457
  { 0x41, 0xC7, prt_r, "out (c),%s", INSS_ALL },
458
  { 0x42, 0xCF, prt_rr, "sbc hl,", INSS_ALL },
459
  { 0x43, 0xCF, prt_rr_nn, "ld (0x%%04x),%s", INSS_ALL },
460
  { 0x44, 0xFF, prt, "neg", INSS_ALL },
461
  { 0x45, 0xFF, prt, "retn", INSS_ALL },
462
  { 0x46, 0xFF, prt, "im 0", INSS_ALL },
463
  { 0x47, 0xFF, prt, "ld i,a", INSS_ALL },
464
  { 0x4A, 0xCF, prt_rr, "adc hl,", INSS_ALL },
465
  { 0x4B, 0xCF, prt_rr_nn, "ld %s,(0x%%04x)", INSS_ALL },
466
  { 0x4C, 0xCF, prt_rr, "mlt ", INSS_Z180|INSS_EZ80 },
467
  { 0x4D, 0xFF, prt, "reti", INSS_ALL },
468
  { 0x4F, 0xFF, prt, "ld r,a", INSS_ALL },
469
  { 0x54, 0xFF, prt_d, "lea ix,iy%+d", INSS_EZ80 },
470
  { 0x55, 0xFF, prt_d, "lea iy,ix%+d", INSS_EZ80 },
471
  { 0x56, 0xFF, prt, "im 1", INSS_ALL },
472
  { 0x57, 0xFF, prt, "ld a,i", INSS_ALL },
473
  { 0x5E, 0xFF, prt, "im 2", INSS_ALL },
474
  { 0x5F, 0xFF, prt, "ld a,r", INSS_ALL },
475
  { 0x64, 0xFF, prt_n, "tst 0x%02x", INSS_Z180 },
476
  { 0x64, 0xFF, prt_n, "tst a,0x%02x", INSS_EZ80 },
477
  { 0x65, 0xFF, prt_d, "pea ix%+d", INSS_EZ80 },
478
  { 0x66, 0xFF, prt_d, "pea iy%+d", INSS_EZ80 },
479
  { 0x67, 0xFF, prt, "rrd", INSS_ALL },
480
  { 0x6D, 0xFF, prt, "ld mb,a", INSS_EZ80 },
481
  { 0x6E, 0xFF, prt, "ld a,mb", INSS_EZ80 },
482
  { 0x6F, 0xFF, prt, "rld", INSS_ALL },
483
  { 0x74, 0xFF, prt_n, "tstio 0x%02x", INSS_Z180|INSS_EZ80 },
484
  { 0x76, 0xFF, prt, "slp", INSS_Z180|INSS_EZ80 },
485
  { 0x7D, 0xFF, prt, "stmix", INSS_EZ80 },
486
  { 0x7E, 0xFF, prt, "rsmix", INSS_EZ80 },
487
  { 0x82, 0xE6, cism, "", INSS_Z180|INSS_EZ80 },
488
  { 0x84, 0xFF, prt, "ini2", INSS_EZ80 },
489
  { 0x8A, 0xFF, prt_n_n, "push 0x%02x%%02x", INSS_Z80N },
490
  { 0x8C, 0xFF, prt, "ind2", INSS_EZ80 },
491
  { 0x90, 0xFF, prt, "outinb", INSS_Z80N },
492
  { 0x91, 0xFF, prt_n_n, "nextreg 0x%02x,0x%%02x", INSS_Z80N },
493
  { 0x92, 0xFF, prt_n, "nextreg 0x%02x,a", INSS_Z80N },
494
  { 0x93, 0xFF, prt, "pixeldn", INSS_Z80N },
495
  { 0x94, 0xFF, prt, "ini2r", INSS_EZ80 },
496
  { 0x94, 0xFF, prt, "pixelad", INSS_Z80N },
497
  { 0x95, 0xFF, prt, "setae", INSS_Z80N },
498
  { 0x98, 0xFF, prt, "jp (c)", INSS_Z80N },
499
  { 0x9c, 0xFF, prt, "ind2r", INSS_EZ80 },
500
  { 0xA0, 0xE4, cis, "", INSS_ALL },
501
  { 0xA4, 0xFF, prt, "outi2", INSS_EZ80 },
502
  { 0xA4, 0xFF, prt, "ldix", INSS_Z80N },
503
  { 0xAC, 0xFF, prt, "outd2", INSS_EZ80 },
504
  { 0xAC, 0xFF, prt, "lddx", INSS_Z80N },
505
  { 0xA5, 0xFF, prt, "ldws", INSS_Z80N },
506
  { 0xB4, 0xFF, prt, "oti2r", INSS_EZ80 },
507
  { 0xB4, 0xFF, prt, "ldirx", INSS_Z80N },
508
  { 0xB7, 0xFF, prt, "ldpirx", INSS_Z80N },
509
  { 0xBC, 0xFF, prt, "otd2r", INSS_EZ80 },
510
  { 0xBC, 0xFF, prt, "lddrx", INSS_Z80N },
511
  { 0xC2, 0xFF, prt, "inirx", INSS_EZ80 },
512
  { 0xC3, 0xFF, prt, "otirx", INSS_EZ80 },
513
  { 0xC7, 0xFF, prt, "ld i,hl", INSS_EZ80 },
514
  { 0xCA, 0xFF, prt, "indrx", INSS_EZ80 },
515
  { 0xCB, 0xFF, prt, "otdrx", INSS_EZ80 },
516
  { 0xC3, 0xFF, prt, "muluw hl,bc", INSS_R800 },
517
  { 0xC5, 0xE7, prt_r, "mulub a,%s", INSS_R800 },
518
  { 0xD7, 0xFF, prt, "ld hl,i", INSS_EZ80 },
519
  { 0xF3, 0xFF, prt, "muluw hl,sp", INSS_R800 },
520
  { 0x00, 0x00, dump, "xx", INSS_ALL }
521
};
522
523
static int
524
pref_ed (struct buffer *buf, disassemble_info *info,
525
         const char *txt ATTRIBUTE_UNUSED)
526
2.96k
{
527
2.96k
  const struct tab_elt *p;
528
529
2.96k
  if (fetch_data (buf, info, 1))
530
2.95k
    {
531
228k
      for (p = opc_ed; p->val != (buf->data[1] & p->mask) || !mach_inst (buf, p); ++p)
532
225k
        ;
533
2.95k
      p->fp (buf, info, p->text);
534
2.95k
    }
535
10
  else
536
10
    buf->n_used = -1;
537
538
2.96k
  return buf->n_used;
539
2.96k
}
540

541
/* Instruction names for the instructions addressing single bits.  */
542
static char *cb1_str[] = { "", "bit", "res", "set"};
543
/* Instruction names for shifts and rotates.  */
544
static char *cb2_str[] =
545
{
546
  "rlc", "rrc", "rl", "rr", "sla", "sra", "sli", "srl"
547
};
548
549
static int
550
pref_cb (struct buffer *buf, disassemble_info *info,
551
         const char *txt ATTRIBUTE_UNUSED)
552
1.10k
{
553
1.10k
  const char *op_txt;
554
1.10k
  int idx;
555
1.10k
  if (fetch_data (buf, info, 1))
556
1.09k
    {
557
1.09k
      buf->n_used = 2;
558
1.09k
      if ((buf->data[1] & 0xc0) == 0)
559
244
        {
560
244
          idx = (buf->data[1] >> 3) & 7;
561
244
          if ((buf->inss & INSS_GBZ80) && (idx == 6))
562
27
            op_txt = "swap";
563
217
          else
564
217
            op_txt = cb2_str[idx];
565
244
          info->fprintf_func (info->stream, "%s %s",
566
244
                              op_txt,
567
244
                              r_str[buf->data[1] & 7]);
568
244
        }
569
855
      else
570
855
  info->fprintf_func (info->stream, "%s %d,%s",
571
855
          cb1_str[(buf->data[1] >> 6) & 3],
572
855
          (buf->data[1] >> 3) & 7,
573
855
          r_str[buf->data[1] & 7]);
574
1.09k
    }
575
1
  else
576
1
    buf->n_used = -1;
577
578
1.10k
  return buf->n_used;
579
1.10k
}
580
581
static int
582
addvv (struct buffer * buf, disassemble_info * info, const char *txt)
583
80
{
584
80
  info->fprintf_func (info->stream, "add %s,%s", txt, txt);
585
586
80
  return buf->n_used = buf->n_fetch;
587
80
}
588
589
static int
590
ld_v_v (struct buffer * buf, disassemble_info * info, const char *txt)
591
72
{
592
72
  char mytxt[TXTSIZ];
593
594
72
  snprintf (mytxt, TXTSIZ, "ld %s%%s,%s%%s", txt, txt);
595
72
  return ld_r_r (buf, info, mytxt);
596
72
}
597
598
static int
599
prt_d_n (struct buffer *buf, disassemble_info * info, const char *txt)
600
183
{
601
183
  char mytxt[TXTSIZ];
602
183
  int d;
603
183
  signed char *p;
604
605
183
  p = buf->data + buf->n_fetch;
606
607
183
  if (fetch_data (buf, info, 1))
608
182
    {
609
182
      d = p[0];
610
182
      snprintf (mytxt, TXTSIZ, txt, d);
611
182
      return prt_n (buf, info, mytxt);
612
182
    }
613
1
  else
614
1
    buf->n_used = -1;
615
616
1
  return buf->n_used;
617
183
}
618
619
static int
620
arit_d (struct buffer *buf, disassemble_info * info, const char *txt)
621
130
{
622
130
  char mytxt[TXTSIZ];
623
130
  signed char c;
624
130
  const char * const *arit;
625
626
130
  arit = (buf->inss & INSS_EZ80) ? arit_str_ez80 : arit_str;
627
130
  c = buf->data[buf->n_fetch - 1];
628
130
  snprintf (mytxt, TXTSIZ, txt, arit[(c >> 3) & 7]);
629
130
  return prt_d (buf, info, mytxt);
630
130
}
631
632
static int
633
ld_r_d (struct buffer *buf, disassemble_info * info, const char *txt)
634
145
{
635
145
  char mytxt[TXTSIZ];
636
145
  signed char c;
637
638
145
  c = buf->data[buf->n_fetch - 1];
639
145
  snprintf (mytxt, TXTSIZ, txt, r_str[(c >> 3) & 7]);
640
145
  return prt_d (buf, info, mytxt);
641
145
}
642
643
static int
644
ld_d_r (struct buffer *buf, disassemble_info * info, const char *txt)
645
754
{
646
754
  char mytxt[TXTSIZ];
647
754
  signed char c;
648
649
754
  c = buf->data[buf->n_fetch - 1];
650
754
  snprintf (mytxt, TXTSIZ, txt, r_str[c & 7]);
651
754
  return prt_d (buf, info, mytxt);
652
754
}
653
654
static int
655
ld_ii_ii (struct buffer *buf, disassemble_info * info, const char *txt)
656
143
{
657
143
  char mytxt[TXTSIZ];
658
143
  signed char c;
659
143
  int p;
660
143
  static const char *ii[2] = { "ix", "iy" };
661
662
143
  p = (buf->data[buf->n_fetch - 2] == (signed char) 0xdd) ? 0 : 1;
663
143
  c = buf->data[buf->n_fetch - 1];
664
143
  if ((c & 0x07) != 0x07)
665
82
    p = 1 - p; /* 0 -> 1, 1 -> 0 */
666
143
  snprintf (mytxt, TXTSIZ, txt, ii[p]);
667
143
  return prt_d (buf, info, mytxt);
668
143
}
669
670
static int
671
pref_xd_cb (struct buffer * buf, disassemble_info * info, const char *txt)
672
1.00k
{
673
1.00k
  if (fetch_data (buf, info, 2))
674
1.00k
    {
675
1.00k
      int d;
676
1.00k
      char arg[TXTSIZ];
677
1.00k
      signed char *p;
678
679
1.00k
      buf->n_used = 4;
680
1.00k
      p = buf->data;
681
1.00k
      d = p[2];
682
683
1.00k
      if (((p[3] & 0xC0) == 0x40) || ((p[3] & 7) == 0x06))
684
570
  snprintf (arg, TXTSIZ, "(%s%+d)", txt, d);
685
433
      else
686
433
  snprintf (arg, TXTSIZ, "(%s%+d),%s", txt, d, r_str[p[3] & 7]);
687
688
1.00k
      if ((p[3] & 0xc0) == 0)
689
345
  info->fprintf_func (info->stream, "%s %s",
690
345
          cb2_str[(buf->data[3] >> 3) & 7],
691
345
          arg);
692
658
      else
693
658
  info->fprintf_func (info->stream, "%s %d,%s",
694
658
          cb1_str[(buf->data[3] >> 6) & 3],
695
658
          (buf->data[3] >> 3) & 7,
696
658
          arg);
697
1.00k
    }
698
2
  else
699
2
    buf->n_used = -1;
700
701
1.00k
  return buf->n_used;
702
1.00k
}
703

704
/* Table to disassemble machine codes with prefix 0xDD or 0xFD.  */
705
static struct tab_elt opc_ind[] =
706
{
707
  { 0x07, 0xFF, prt_d, "ld bc,(%s%%+d)", INSS_EZ80 },
708
  { 0x0F, 0xFF, prt_d, "ld (%s%%+d),bc", INSS_EZ80 },
709
  { 0x17, 0xFF, prt_d, "ld de,(%s%%+d)", INSS_EZ80 },
710
  { 0x1F, 0xFF, prt_d, "ld (%s%%+d),de", INSS_EZ80 },
711
  { 0x24, 0xF7, prt_r, "inc %s%%s", INSS_ALL },
712
  { 0x25, 0xF7, prt_r, "dec %s%%s", INSS_ALL },
713
  { 0x26, 0xF7, ld_r_n, "ld %s%%s,0x%%%%02x", INSS_ALL },
714
  { 0x27, 0xFF, prt_d, "ld hl,(%s%%+d)", INSS_EZ80 },
715
  { 0x2F, 0xFF, prt_d, "ld (%s%%+d),hl", INSS_EZ80 },
716
  { 0x21, 0xFF, prt_nn, "ld %s,0x%%04x", INSS_ALL },
717
  { 0x22, 0xFF, prt_nn, "ld (0x%%04x),%s", INSS_ALL },
718
  { 0x2A, 0xFF, prt_nn, "ld %s,(0x%%04x)", INSS_ALL },
719
  { 0x23, 0xFF, prt, "inc %s", INSS_ALL },
720
  { 0x2B, 0xFF, prt, "dec %s", INSS_ALL },
721
  { 0x29, 0xFF, addvv, "%s", INSS_ALL },
722
  { 0x31, 0xFF, ld_ii_ii, "ld %%s,(%s%%%%+d)", INSS_EZ80 },
723
  { 0x37, 0xFF, ld_ii_ii, "ld %%s,(%s%%%%+d)", INSS_EZ80 },
724
  { 0x3E, 0xFE, ld_ii_ii, "ld (%s%%%%+d),%%s", INSS_EZ80 },
725
  { 0x09, 0xCF, prt_rr, "add %s,", INSS_ALL },
726
  { 0x34, 0xFF, prt_d, "inc (%s%%+d)", INSS_ALL },
727
  { 0x35, 0xFF, prt_d, "dec (%s%%+d)", INSS_ALL },
728
  { 0x36, 0xFF, prt_d_n, "ld (%s%%+d),0x%%%%02x", INSS_ALL },
729
730
  { 0x76, 0xFF, dump, "h", INSS_ALL },
731
  { 0x46, 0xC7, ld_r_d, "ld %%s,(%s%%%%+d)", INSS_ALL },
732
  { 0x70, 0xF8, ld_d_r, "ld (%s%%%%+d),%%s", INSS_ALL },
733
  { 0x64, 0xF6, ld_v_v, "%s", INSS_ALL },
734
  { 0x60, 0xF0, ld_r_r, "ld %s%%s,%%s", INSS_ALL },
735
  { 0x44, 0xC6, ld_r_r, "ld %%s,%s%%s", INSS_ALL },
736
737
  { 0x86, 0xC7, arit_d, "%%s(%s%%%%+d)", INSS_ALL },
738
  { 0x84, 0xC6, arit_r, "%%s%s%%s", INSS_ALL },
739
740
  { 0xE1, 0xFF, prt, "pop %s", INSS_ALL },
741
  { 0xE5, 0xFF, prt, "push %s", INSS_ALL },
742
  { 0xCB, 0xFF, pref_xd_cb, "%s", INSS_ALL },
743
  { 0xE3, 0xFF, prt, "ex (sp),%s", INSS_ALL },
744
  { 0xE9, 0xFF, prt, "jp (%s)", INSS_ALL },
745
  { 0xF9, 0xFF, prt, "ld sp,%s", INSS_ALL },
746
  { 0x00, 0x00, dump, "?", INSS_ALL },
747
} ;
748
749
static int
750
pref_ind (struct buffer *buf, disassemble_info *info, const char *txt)
751
6.45k
{
752
6.45k
  if (fetch_data (buf, info, 1))
753
6.45k
    {
754
6.45k
      char mytxt[TXTSIZ];
755
6.45k
      struct tab_elt *p;
756
757
209k
      for (p = opc_ind; p->val != (buf->data[1] & p->mask) || !mach_inst (buf, p); ++p)
758
202k
        ;
759
6.45k
      snprintf (mytxt, TXTSIZ, p->text, txt);
760
6.45k
      p->fp (buf, info, mytxt);
761
6.45k
    }
762
1
  else
763
1
    buf->n_used = -1;
764
765
6.45k
  return buf->n_used;
766
6.45k
}
767
768
static int
769
print_insn_z80_buf (struct buffer *buf, disassemble_info *info);
770
771
static int
772
suffix (struct buffer *buf, disassemble_info *info, const char *txt)
773
8.98k
{
774
8.98k
  char mybuf[TXTSIZ*4];
775
8.98k
  fprintf_ftype old_fprintf;
776
8.98k
  void *old_stream;
777
8.98k
  char *p;
778
779
8.98k
  switch (txt[2])
780
8.98k
    {
781
5.31k
    case 'l': /* SIL or LIL */
782
5.31k
      buf->nn_len = 3;
783
5.31k
      break;
784
3.67k
    case 's': /* SIS or LIS */
785
3.67k
      buf->nn_len = 2;
786
3.67k
      break;
787
0
    default:
788
0
      abort ();
789
8.98k
    }
790
8.98k
  if (!fetch_data (buf, info, 1)
791
8.98k
      || buf->data[1] == 0x40
792
7.26k
      || buf->data[1] == 0x49
793
7.02k
      || buf->data[1] == 0x52
794
6.52k
      || buf->data[1] == 0x5b)
795
5.53k
    {
796
      /* Double prefix, or end of data.  */
797
5.53k
      info->fprintf_func (info->stream, ".db 0x%02x ; %s", (unsigned)buf->data[0], txt);
798
5.53k
      buf->n_used = 1;
799
5.53k
      return buf->n_used;
800
5.53k
    }
801
802
3.45k
  old_fprintf = info->fprintf_func;
803
3.45k
  old_stream = info->stream;
804
3.45k
  info->fprintf_func = (fprintf_ftype) &sprintf;
805
3.45k
  info->stream = mybuf;
806
3.45k
  mybuf[0] = 0;
807
3.45k
  buf->base++;
808
3.45k
  if (print_insn_z80_buf (buf, info) >= 0)
809
3.44k
    buf->n_used++;
810
3.45k
  info->fprintf_func = old_fprintf;
811
3.45k
  info->stream = old_stream;
812
813
11.9k
  for (p = mybuf; *p; ++p)
814
11.0k
    if (*p == ' ')
815
2.52k
      break;
816
3.45k
  if (*p)
817
2.52k
    {
818
2.52k
      *p++ = '\0';
819
2.52k
      info->fprintf_func (info->stream, "%s.%s %s", mybuf, txt, p);
820
2.52k
    }
821
930
  else
822
930
    info->fprintf_func (info->stream, "%s.%s", mybuf, txt);
823
3.45k
  return buf->n_used;
824
8.98k
}
825
826
/* Table to disassemble machine codes without prefix.  */
827
static const struct tab_elt
828
opc_main[] =
829
{
830
  { 0x00, 0xFF, prt, "nop", INSS_ALL },
831
  { 0x01, 0xCF, prt_rr_nn, "ld %s,0x%%04x", INSS_ALL },
832
  { 0x02, 0xFF, prt, "ld (bc),a", INSS_ALL },
833
  { 0x03, 0xCF, prt_rr, "inc ", INSS_ALL },
834
  { 0x04, 0xC7, prt_r, "inc %s", INSS_ALL },
835
  { 0x05, 0xC7, prt_r, "dec %s", INSS_ALL },
836
  { 0x06, 0xC7, ld_r_n, "ld %s,0x%%02x", INSS_ALL },
837
  { 0x07, 0xFF, prt, "rlca", INSS_ALL },
838
  { 0x08, 0xFF, prt, "ex af,af'", ~INSS_GBZ80 },
839
  { 0x09, 0xCF, prt_rr, "add hl,", INSS_ALL },
840
  { 0x0A, 0xFF, prt, "ld a,(bc)", INSS_ALL },
841
  { 0x0B, 0xCF, prt_rr, "dec ", INSS_ALL },
842
  { 0x0F, 0xFF, prt, "rrca", INSS_ALL },
843
  { 0x10, 0xFF, prt_e, "djnz ", ~INSS_GBZ80 },
844
  { 0x12, 0xFF, prt, "ld (de),a", INSS_ALL },
845
  { 0x17, 0xFF, prt, "rla", INSS_ALL },
846
  { 0x18, 0xFF, prt_e, "jr ", INSS_ALL },
847
  { 0x1A, 0xFF, prt, "ld a,(de)", INSS_ALL },
848
  { 0x1F, 0xFF, prt, "rra", INSS_ALL },
849
  { 0x20, 0xE7, jr_cc, "jr %s,", INSS_ALL },
850
  { 0x22, 0xFF, prt_nn, "ld (0x%04x),hl", ~INSS_GBZ80 },
851
  { 0x27, 0xFF, prt, "daa", INSS_ALL },
852
  { 0x2A, 0xFF, prt_nn, "ld hl,(0x%04x)", ~INSS_GBZ80 },
853
  { 0x2F, 0xFF, prt, "cpl", INSS_ALL },
854
  { 0x32, 0xFF, prt_nn, "ld (0x%04x),a", INSS_ALL },
855
  { 0x37, 0xFF, prt, "scf", INSS_ALL },
856
  { 0x3A, 0xFF, prt_nn, "ld a,(0x%04x)", INSS_ALL },
857
  { 0x3F, 0xFF, prt, "ccf", INSS_ALL },
858
859
  { 0x76, 0xFF, prt, "halt", INSS_ALL },
860
861
  { 0x40, 0xFF, suffix, "sis", INSS_EZ80 },
862
  { 0x49, 0xFF, suffix, "lis", INSS_EZ80 },
863
  { 0x52, 0xFF, suffix, "sil", INSS_EZ80 },
864
  { 0x5B, 0xFF, suffix, "lil", INSS_EZ80 },
865
866
  { 0x40, 0xC0, ld_r_r, "ld %s,%s", INSS_ALL},
867
868
  { 0x80, 0xC0, arit_r, "%s%s", INSS_ALL },
869
870
  { 0xC0, 0xC7, prt_cc, "ret ", INSS_ALL },
871
  { 0xC1, 0xCF, pop_rr, "pop", INSS_ALL },
872
  { 0xC2, 0xC7, jp_cc_nn, "jp ", INSS_ALL },
873
  { 0xC3, 0xFF, prt_nn, "jp 0x%04x", INSS_ALL },
874
  { 0xC4, 0xC7, jp_cc_nn, "call ", INSS_ALL },
875
  { 0xC5, 0xCF, pop_rr, "push", INSS_ALL },
876
  { 0xC6, 0xC7, arit_n, "%s0x%%02x", INSS_ALL },
877
  { 0xC7, 0xC7, rst, "rst 0x%02x", INSS_ALL },
878
  { 0xC9, 0xFF, prt, "ret", INSS_ALL },
879
  { 0xCB, 0xFF, pref_cb, "", INSS_ALL },
880
  { 0xCD, 0xFF, prt_nn, "call 0x%04x", INSS_ALL },
881
  { 0xD3, 0xFF, prt_n, "out (0x%02x),a", ~INSS_GBZ80 },
882
  { 0xD9, 0xFF, prt, "exx", ~INSS_GBZ80 },
883
  { 0xDB, 0xFF, prt_n, "in a,(0x%02x)", ~INSS_GBZ80 },
884
  { 0xDD, 0xFF, pref_ind, "ix", ~INSS_GBZ80 },
885
  { 0xE3, 0xFF, prt, "ex (sp),hl", ~INSS_GBZ80 },
886
  { 0xE9, 0xFF, prt, "jp (hl)", INSS_ALL },
887
  { 0xEB, 0xFF, prt, "ex de,hl", ~INSS_GBZ80 },
888
  { 0xED, 0xFF, pref_ed, "", ~INSS_GBZ80 },
889
  { 0xF3, 0xFF, prt, "di", INSS_ALL },
890
  { 0xF9, 0xFF, prt, "ld sp,hl", INSS_ALL },
891
  { 0xFB, 0xFF, prt, "ei", INSS_ALL },
892
  { 0xFD, 0xFF, pref_ind, "iy", ~INSS_GBZ80 },
893
  { 0x00, 0x00, prt, "????", INSS_ALL },
894
} ;
895
896
/* Separate GBZ80 main opcode table due to many differences */
897
static const struct tab_elt
898
opc_main_gbz80[] =
899
{
900
  { 0x00, 0xFF, prt,"nop", INSS_ALL },
901
  { 0x01, 0xCF, prt_rr_nn, "ld %s,0x%%04x", INSS_ALL },
902
  { 0x02, 0xFF, prt, "ld (bc),a", INSS_ALL },
903
  { 0x03, 0xCF, prt_rr, "inc ", INSS_ALL },
904
  { 0x04, 0xC7, prt_r, "inc %s", INSS_ALL },
905
  { 0x05, 0xC7, prt_r, "dec %s", INSS_ALL },
906
  { 0x06, 0xC7, ld_r_n, "ld %s,0x%%02x", INSS_ALL },
907
  { 0x07, 0xFF, prt, "rlca", INSS_ALL },
908
  { 0x08, 0xFF, prt_nn, "ld (0x%04x),sp", INSS_GBZ80 },
909
  { 0x09, 0xCF, prt_rr, "add hl,", INSS_ALL },
910
  { 0x0A, 0xFF, prt, "ld a,(bc)", INSS_ALL },
911
  { 0x0B, 0xCF, prt_rr, "dec ", INSS_ALL },
912
  { 0x0F, 0xFF, prt, "rrca", INSS_ALL },
913
  { 0x10, 0xFF, prt, "stop", INSS_GBZ80 },
914
  { 0x12, 0xFF, prt, "ld (de),a", INSS_ALL },
915
  { 0x17, 0xFF, prt, "rla", INSS_ALL },
916
  { 0x18, 0xFF, prt_e, "jr ", INSS_ALL },
917
  { 0x1A, 0xFF, prt, "ld a,(de)", INSS_ALL },
918
  { 0x1F, 0xFF, prt, "rra", INSS_ALL },
919
  { 0x20, 0xE7, jr_cc, "jr %s,", INSS_ALL },
920
  { 0x22, 0xFF, prt, "ld (hl+),a", INSS_GBZ80 },
921
  { 0x27, 0xFF, prt, "daa", INSS_ALL },
922
  { 0x2A, 0xFF, prt, "ld a,(hl+)", INSS_GBZ80 },
923
  { 0x2F, 0xFF, prt, "cpl", INSS_ALL },
924
  { 0x32, 0xFF, prt, "ld (hl-),a", INSS_GBZ80 },
925
  { 0x37, 0xFF, prt, "scf", INSS_ALL },
926
  { 0x3A, 0xFF, prt, "ld a,(hl-)", INSS_GBZ80 },
927
  { 0x3F, 0xFF, prt, "ccf", INSS_ALL },
928
  { 0x76, 0xFF, prt, "halt", INSS_ALL },
929
  { 0x40, 0xC0, ld_r_r, "ld %s,%s", INSS_ALL},
930
  { 0x80, 0xC0, arit_r, "%s%s", INSS_ALL },
931
  { 0xC0, 0xE7, prt_cc, "ret ", INSS_ALL },
932
  { 0xC1, 0xCF, pop_rr, "pop", INSS_ALL },
933
  { 0xC2, 0xE7, jp_cc_nn, "jp ", INSS_ALL },
934
  { 0xC3, 0xFF, prt_nn, "jp 0x%04x", INSS_ALL },
935
  { 0xC4, 0xE7, jp_cc_nn, "call ", INSS_ALL },
936
  { 0xC5, 0xCF, pop_rr, "push", INSS_ALL },
937
  { 0xC6, 0xC7, arit_n, "%s0x%%02x", INSS_ALL },
938
  { 0xC7, 0xC7, rst, "rst 0x%02x", INSS_ALL },
939
  { 0xC9, 0xFF, prt, "ret", INSS_ALL },
940
  { 0xCB, 0xFF, pref_cb, "", INSS_ALL },
941
  { 0xCD, 0xFF, prt_nn, "call 0x%04x", INSS_ALL },
942
  { 0xD9, 0xFF, prt, "reti", INSS_GBZ80 },
943
  { 0xE0, 0xFF, prt_n, "ldh (0x%02x),a", INSS_GBZ80 },
944
  { 0xE2, 0xFF, prt, "ldh (c),a", INSS_GBZ80 },
945
  { 0xE8, 0xFF, prt_d, "add sp,%d", INSS_GBZ80 },
946
  { 0xE9, 0xFF, prt, "jp (hl)", INSS_ALL },
947
  { 0xEA, 0xFF, prt_nn, "ld (0x%04x),a", INSS_GBZ80 },
948
  { 0xF0, 0xFF, prt_n, "ldh a,(0x%02x)", INSS_GBZ80 },
949
  { 0xF2, 0xFF, prt, "ldh a,(c)", INSS_GBZ80 },
950
  { 0xF3, 0xFF, prt, "di", INSS_ALL },
951
  { 0xF8, 0xFF, prt_d, "ldhl sp,%d", INSS_GBZ80 },
952
  { 0xF9, 0xFF, prt, "ld sp,hl", INSS_ALL },
953
  { 0xFA, 0xFF, prt_nn, "ld a,(0x%04x)", INSS_GBZ80 },
954
  { 0xFB, 0xFF, prt, "ei", INSS_ALL },
955
  { 0x00, 0x00, dump, "?", INSS_ALL },
956
} ;
957
958
int
959
print_insn_z80 (bfd_vma addr, disassemble_info * info)
960
352k
{
961
352k
  struct buffer buf;
962
963
352k
  buf.base = addr;
964
352k
  buf.inss = 1 << info->mach;
965
352k
  buf.nn_len = info->mach == bfd_mach_ez80_adl ? 3 : 2;
966
352k
  info->bytes_per_line = (buf.inss & INSS_EZ80) ? 6 : 4; /* <ss pp oo nn mm MM> OR <pp oo nn mm> */
967
968
352k
  return print_insn_z80_buf (&buf, info);
969
352k
}
970
971
static int
972
print_insn_z80_buf (struct buffer *buf, disassemble_info *info)
973
355k
{
974
355k
  const struct tab_elt *p;
975
976
355k
  buf->n_fetch = 0;
977
355k
  buf->n_used = 0;
978
355k
  if (! fetch_data (buf, info, 1))
979
1
    return -1;
980
981
355k
  p = (buf->inss & INSS_GBZ80) ? opc_main_gbz80 : opc_main;
982
983
7.88M
  for (; p->val != (buf->data[0] & p->mask) || !mach_inst (buf, p); ++p)
984
7.53M
    ;
985
355k
  p->fp (buf, info, p->text);
986
987
355k
  return buf->n_used;
988
355k
}