Coverage Report

Created: 2025-07-08 11:15

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