Coverage Report

Created: 2026-09-14 08:07

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