/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 | 33.0M | #define INSS_GBZ80 (1 << bfd_mach_gbz80) |
51 | | #define INSS_Z180 (1 << bfd_mach_z180) |
52 | 33.8M | #define INSS_EZ80_Z80 (1 << bfd_mach_ez80_z80) |
53 | 33.8M | #define INSS_EZ80_ADL (1 << bfd_mach_ez80_adl) |
54 | 33.8M | #define INSS_EZ80 (INSS_EZ80_ADL | INSS_EZ80_Z80) |
55 | | #define INSS_Z80N (1 << bfd_mach_z80n) |
56 | | |
57 | 1.69M | #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 | 32.5M | { |
82 | 32.5M | return !p->inss || (p->inss & buf->inss); |
83 | 32.5M | } |
84 | | |
85 | | static int |
86 | | fetch_data (struct buffer *buf, disassemble_info * info, int n) |
87 | 34.6M | { |
88 | 34.6M | int r; |
89 | | |
90 | 34.6M | if (buf->n_fetch + n > (int)sizeof (buf->data)) |
91 | 0 | abort (); |
92 | | |
93 | 34.6M | r = info->read_memory_func (buf->base + buf->n_fetch, |
94 | 34.6M | (unsigned char*) buf->data + buf->n_fetch, |
95 | 34.6M | n, info); |
96 | 34.6M | if (r == 0) |
97 | 34.6M | buf->n_fetch += n; |
98 | 796 | else |
99 | 796 | info->memory_error_func (r, buf->base + buf->n_fetch, info); |
100 | 34.6M | return !r; |
101 | 34.6M | } |
102 | | |
103 | | static int |
104 | | prt (struct buffer *buf, disassemble_info * info, const char *txt) |
105 | 19.3M | { |
106 | 19.3M | info->fprintf_func (info->stream, "%s", txt); |
107 | 19.3M | buf->n_used = buf->n_fetch; |
108 | 19.3M | return 1; |
109 | 19.3M | } |
110 | | |
111 | | static int |
112 | | prt_e (struct buffer *buf, disassemble_info * info, const char *txt) |
113 | 380k | { |
114 | 380k | char e; |
115 | 380k | int target_addr; |
116 | | |
117 | 380k | if (fetch_data (buf, info, 1)) |
118 | 380k | { |
119 | 380k | e = buf->data[1]; |
120 | 380k | target_addr = (buf->base + 2 + e) & 0xffff; |
121 | 380k | buf->n_used = buf->n_fetch; |
122 | 380k | info->fprintf_func (info->stream, "%s0x%04x", txt, target_addr); |
123 | 380k | } |
124 | 117 | else |
125 | 117 | buf->n_used = -1; |
126 | | |
127 | 380k | return buf->n_used; |
128 | 380k | } |
129 | | |
130 | | static int |
131 | | jr_cc (struct buffer *buf, disassemble_info * info, const char *txt) |
132 | 220k | { |
133 | 220k | char mytxt[TXTSIZ]; |
134 | | |
135 | 220k | snprintf (mytxt, TXTSIZ, txt, cc_str[(buf->data[0] >> 3) & 3]); |
136 | 220k | return prt_e (buf, info, mytxt); |
137 | 220k | } |
138 | | |
139 | | static int |
140 | | prt_nn (struct buffer *buf, disassemble_info * info, const char *txt) |
141 | 1.08M | { |
142 | 1.08M | int nn; |
143 | 1.08M | unsigned char *p; |
144 | 1.08M | int i; |
145 | | |
146 | 1.08M | p = (unsigned char*) buf->data + buf->n_fetch; |
147 | 1.08M | if (fetch_data (buf, info, buf->nn_len)) |
148 | 1.08M | { |
149 | 1.08M | nn = 0; |
150 | 1.08M | i = buf->nn_len; |
151 | 3.34M | while (i--) |
152 | 2.25M | nn = nn * 0x100 + p[i]; |
153 | 1.08M | info->fprintf_func (info->stream, txt, nn); |
154 | 1.08M | buf->n_used = buf->n_fetch; |
155 | 1.08M | } |
156 | 497 | else |
157 | 497 | buf->n_used = -1; |
158 | 1.08M | return buf->n_used; |
159 | 1.08M | } |
160 | | |
161 | | static int |
162 | | prt_rr_nn (struct buffer *buf, disassemble_info * info, const char *txt) |
163 | 704k | { |
164 | 704k | char mytxt[TXTSIZ]; |
165 | 704k | int rr; |
166 | | |
167 | 704k | rr = (buf->data[buf->n_fetch - 1] >> 4) & 3; |
168 | 704k | snprintf (mytxt, TXTSIZ, txt, rr_str[rr]); |
169 | 704k | return prt_nn (buf, info, mytxt); |
170 | 704k | } |
171 | | |
172 | | static int |
173 | | prt_rr (struct buffer *buf, disassemble_info * info, const char *txt) |
174 | 1.96M | { |
175 | 1.96M | info->fprintf_func (info->stream, "%s%s", txt, |
176 | 1.96M | rr_str[(buf->data[buf->n_fetch - 1] >> 4) & 3]); |
177 | 1.96M | buf->n_used = buf->n_fetch; |
178 | 1.96M | return buf->n_used; |
179 | 1.96M | } |
180 | | |
181 | | static int |
182 | | prt_n (struct buffer *buf, disassemble_info * info, const char *txt) |
183 | 510k | { |
184 | 510k | int n; |
185 | 510k | unsigned char *p; |
186 | | |
187 | 510k | p = (unsigned char*) buf->data + buf->n_fetch; |
188 | | |
189 | 510k | if (fetch_data (buf, info, 1)) |
190 | 510k | { |
191 | 510k | n = p[0]; |
192 | 510k | info->fprintf_func (info->stream, txt, n); |
193 | 510k | buf->n_used = buf->n_fetch; |
194 | 510k | } |
195 | 101 | else |
196 | 101 | buf->n_used = -1; |
197 | | |
198 | 510k | return buf->n_used; |
199 | 510k | } |
200 | | |
201 | | static int |
202 | | prt_n_n (struct buffer *buf, disassemble_info * info, const char *txt) |
203 | 37 | { |
204 | 37 | char mytxt[TXTSIZ]; |
205 | 37 | int n; |
206 | 37 | unsigned char *p; |
207 | | |
208 | 37 | p = (unsigned char*) buf->data + buf->n_fetch; |
209 | | |
210 | 37 | if (fetch_data (buf, info, 1)) |
211 | 36 | { |
212 | 36 | n = p[0]; |
213 | 36 | snprintf (mytxt, TXTSIZ, txt, n); |
214 | 36 | buf->n_used = buf->n_fetch; |
215 | 36 | } |
216 | 1 | else |
217 | 1 | buf->n_used = -1; |
218 | | |
219 | 37 | return prt_n (buf, info, mytxt); |
220 | 37 | } |
221 | | |
222 | | static int |
223 | | prt_r_n (struct buffer *buf, disassemble_info * info, const char *txt) |
224 | 1.42k | { |
225 | 1.42k | char mytxt[TXTSIZ]; |
226 | 1.42k | int r; |
227 | | |
228 | 1.42k | r = (buf->data[buf->n_fetch - 1] >> 3) & 7; |
229 | 1.42k | snprintf (mytxt, TXTSIZ, txt, r_str[r]); |
230 | 1.42k | return prt_n (buf, info, mytxt); |
231 | 1.42k | } |
232 | | |
233 | | static int |
234 | | ld_r_n (struct buffer *buf, disassemble_info * info, const char *txt) |
235 | 365k | { |
236 | 365k | char mytxt[TXTSIZ]; |
237 | | |
238 | 365k | snprintf (mytxt, TXTSIZ, txt, r_str[(buf->data[buf->n_fetch - 1] >> 3) & 7]); |
239 | 365k | return prt_n (buf, info, mytxt); |
240 | 365k | } |
241 | | |
242 | | static int |
243 | | prt_r (struct buffer *buf, disassemble_info * info, const char *txt) |
244 | 972k | { |
245 | 972k | info->fprintf_func (info->stream, txt, |
246 | 972k | r_str[(buf->data[buf->n_fetch - 1] >> 3) & 7]); |
247 | 972k | buf->n_used = buf->n_fetch; |
248 | 972k | return buf->n_used; |
249 | 972k | } |
250 | | |
251 | | static int |
252 | | ld_r_r (struct buffer *buf, disassemble_info * info, const char *txt) |
253 | 5.53M | { |
254 | 5.53M | info->fprintf_func (info->stream, txt, |
255 | 5.53M | r_str[(buf->data[buf->n_fetch - 1] >> 3) & 7], |
256 | 5.53M | r_str[buf->data[buf->n_fetch - 1] & 7]); |
257 | 5.53M | buf->n_used = buf->n_fetch; |
258 | 5.53M | return buf->n_used; |
259 | 5.53M | } |
260 | | |
261 | | static int |
262 | | prt_d (struct buffer *buf, disassemble_info * info, const char *txt) |
263 | 4.59k | { |
264 | 4.59k | int d; |
265 | 4.59k | signed char *p; |
266 | | |
267 | 4.59k | p = buf->data + buf->n_fetch; |
268 | | |
269 | 4.59k | if (fetch_data (buf, info, 1)) |
270 | 4.57k | { |
271 | 4.57k | d = p[0]; |
272 | 4.57k | info->fprintf_func (info->stream, txt, d); |
273 | 4.57k | buf->n_used = buf->n_fetch; |
274 | 4.57k | } |
275 | 28 | else |
276 | 28 | buf->n_used = -1; |
277 | | |
278 | 4.59k | return buf->n_used; |
279 | 4.59k | } |
280 | | |
281 | | static int |
282 | | prt_rr_d (struct buffer *buf, disassemble_info * info, const char *txt) |
283 | 228 | { |
284 | 228 | char mytxt[TXTSIZ]; |
285 | 228 | int rr; |
286 | | |
287 | 228 | rr = (buf->data[buf->n_fetch - 1] >> 4) & 3; |
288 | 228 | if (rr == 3) /* SP is not supported */ |
289 | 0 | return 0; |
290 | | |
291 | 228 | snprintf (mytxt, TXTSIZ, txt, rr_str[rr]); |
292 | 228 | return prt_d (buf, info, mytxt); |
293 | 228 | } |
294 | | |
295 | | static int |
296 | | arit_r (struct buffer *buf, disassemble_info * info, const char *txt) |
297 | 1.32M | { |
298 | 1.32M | const char * const *arit; |
299 | | |
300 | 1.32M | if (buf->inss & INSS_EZ80) |
301 | 754k | arit = arit_str_ez80; |
302 | 568k | else if (buf->inss & INSS_GBZ80) |
303 | 9.25k | arit = arit_str_gbz80; |
304 | 559k | else |
305 | 559k | arit = arit_str; |
306 | | |
307 | 1.32M | info->fprintf_func (info->stream, txt, |
308 | 1.32M | arit[(buf->data[buf->n_fetch - 1] >> 3) & 7], |
309 | 1.32M | r_str[buf->data[buf->n_fetch - 1] & 7]); |
310 | 1.32M | buf->n_used = buf->n_fetch; |
311 | 1.32M | return buf->n_used; |
312 | 1.32M | } |
313 | | |
314 | | static int |
315 | | prt_cc (struct buffer *buf, disassemble_info * info, const char *txt) |
316 | 210k | { |
317 | 210k | info->fprintf_func (info->stream, "%s%s", txt, |
318 | 210k | cc_str[(buf->data[0] >> 3) & 7]); |
319 | 210k | buf->n_used = buf->n_fetch; |
320 | 210k | return buf->n_used; |
321 | 210k | } |
322 | | |
323 | | static int |
324 | | pop_rr (struct buffer *buf, disassemble_info * info, const char *txt) |
325 | 114k | { |
326 | 114k | static char *rr_stack[] = { "bc","de","hl","af"}; |
327 | | |
328 | 114k | info->fprintf_func (info->stream, "%s %s", txt, |
329 | 114k | rr_stack[(buf->data[0] >> 4) & 3]); |
330 | 114k | buf->n_used = buf->n_fetch; |
331 | 114k | return buf->n_used; |
332 | 114k | } |
333 | | |
334 | | |
335 | | static int |
336 | | jp_cc_nn (struct buffer *buf, disassemble_info * info, const char *txt) |
337 | 239k | { |
338 | 239k | char mytxt[TXTSIZ]; |
339 | | |
340 | 239k | snprintf (mytxt,TXTSIZ, |
341 | 239k | "%s%s,0x%%04x", txt, cc_str[(buf->data[0] >> 3) & 7]); |
342 | 239k | return prt_nn (buf, info, mytxt); |
343 | 239k | } |
344 | | |
345 | | static int |
346 | | arit_n (struct buffer *buf, disassemble_info * info, const char *txt) |
347 | 122k | { |
348 | 122k | char mytxt[TXTSIZ]; |
349 | 122k | const char * const *arit; |
350 | | |
351 | 122k | if (buf->inss & INSS_EZ80) |
352 | 54.5k | arit = arit_str_ez80; |
353 | 68.3k | else if (buf->inss & INSS_GBZ80) |
354 | 1.00k | arit = arit_str_gbz80; |
355 | 67.3k | else |
356 | 67.3k | arit = arit_str; |
357 | | |
358 | 122k | snprintf (mytxt,TXTSIZ, txt, arit[(buf->data[0] >> 3) & 7]); |
359 | 122k | return prt_n (buf, info, mytxt); |
360 | 122k | } |
361 | | |
362 | | static int |
363 | | rst (struct buffer *buf, disassemble_info * info, const char *txt) |
364 | 820k | { |
365 | 820k | info->fprintf_func (info->stream, txt, buf->data[0] & 0x38); |
366 | 820k | buf->n_used = buf->n_fetch; |
367 | 820k | return buf->n_used; |
368 | 820k | } |
369 | | |
370 | | |
371 | | static int |
372 | | cis (struct buffer *buf, disassemble_info * info, const char *txt ATTRIBUTE_UNUSED) |
373 | 737 | { |
374 | 737 | static char * opar[] = { "ld", "cp", "in", "out" }; |
375 | 737 | char * op; |
376 | 737 | char c; |
377 | | |
378 | 737 | c = buf->data[1]; |
379 | 737 | op = ((0x13 & c) == 0x13) ? "ot" : (opar[c & 3]); |
380 | 737 | info->fprintf_func (info->stream, |
381 | 737 | "%s%c%s", op, |
382 | 737 | (c & 0x08) ? 'd' : 'i', |
383 | 737 | (c & 0x10) ? "r" : ""); |
384 | 737 | buf->n_used = 2; |
385 | 737 | return buf->n_used; |
386 | 737 | } |
387 | | |
388 | | static int |
389 | | cism (struct buffer *buf, disassemble_info * info, const char *txt ATTRIBUTE_UNUSED) |
390 | 375 | { |
391 | 375 | static char * opar[] = { "in%cm%s", "ot%cm%s" }; |
392 | 375 | char * op; |
393 | 375 | char c; |
394 | | |
395 | 375 | c = buf->data[1]; |
396 | 375 | op = opar[c & 1]; |
397 | 375 | info->fprintf_func (info->stream, |
398 | 375 | op, |
399 | 375 | (c & 0x08) ? 'd' : 'i', |
400 | 375 | (c & 0x10) ? "r" : ""); |
401 | 375 | buf->n_used = 2; |
402 | 375 | return buf->n_used; |
403 | 375 | } |
404 | | |
405 | | static int |
406 | | dump (struct buffer *buf, disassemble_info * info, const char *txt) |
407 | 34.0k | { |
408 | 34.0k | int i; |
409 | | |
410 | 34.0k | info->fprintf_func (info->stream, "defb "); |
411 | 75.0k | for (i = 0; txt[i]; ++i) |
412 | 40.9k | info->fprintf_func (info->stream, i ? ", 0x%02x" : "0x%02x", |
413 | 40.9k | (unsigned char) buf->data[i]); |
414 | 34.0k | buf->n_used = i; |
415 | 34.0k | return buf->n_used; |
416 | 34.0k | } |
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 | 11.5k | { |
530 | 11.5k | const struct tab_elt *p; |
531 | | |
532 | 11.5k | if (fetch_data (buf, info, 1)) |
533 | 11.5k | { |
534 | 878k | for (p = opc_ed; p->val != (buf->data[1] & p->mask) || !mach_inst (buf, p); ++p) |
535 | 867k | ; |
536 | 11.5k | p->fp (buf, info, p->text); |
537 | 11.5k | } |
538 | 2 | else |
539 | 2 | buf->n_used = -1; |
540 | | |
541 | 11.5k | return buf->n_used; |
542 | 11.5k | } |
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 | 9.37k | { |
556 | 9.37k | const char *op_txt; |
557 | 9.37k | int idx; |
558 | 9.37k | if (fetch_data (buf, info, 1)) |
559 | 9.36k | { |
560 | 9.36k | buf->n_used = 2; |
561 | 9.36k | if ((buf->data[1] & 0xc0) == 0) |
562 | 2.72k | { |
563 | 2.72k | idx = (buf->data[1] >> 3) & 7; |
564 | 2.72k | if ((buf->inss & INSS_GBZ80) && (idx == 6)) |
565 | 249 | op_txt = "swap"; |
566 | 2.47k | else |
567 | 2.47k | op_txt = cb2_str[idx]; |
568 | 2.72k | info->fprintf_func (info->stream, "%s %s", |
569 | 2.72k | op_txt, |
570 | 2.72k | r_str[buf->data[1] & 7]); |
571 | 2.72k | } |
572 | 6.64k | else |
573 | 6.64k | info->fprintf_func (info->stream, "%s %d,%s", |
574 | 6.64k | cb1_str[(buf->data[1] >> 6) & 3], |
575 | 6.64k | (buf->data[1] >> 3) & 7, |
576 | 6.64k | r_str[buf->data[1] & 7]); |
577 | 9.36k | } |
578 | 7 | else |
579 | 7 | buf->n_used = -1; |
580 | | |
581 | 9.37k | return buf->n_used; |
582 | 9.37k | } |
583 | | |
584 | | static int |
585 | | addvv (struct buffer * buf, disassemble_info * info, const char *txt) |
586 | 176 | { |
587 | 176 | info->fprintf_func (info->stream, "add %s,%s", txt, txt); |
588 | | |
589 | 176 | return buf->n_used = buf->n_fetch; |
590 | 176 | } |
591 | | |
592 | | static int |
593 | | ld_v_v (struct buffer * buf, disassemble_info * info, const char *txt) |
594 | 860 | { |
595 | 860 | char mytxt[TXTSIZ]; |
596 | | |
597 | 860 | snprintf (mytxt, TXTSIZ, "ld %s%%s,%s%%s", txt, txt); |
598 | 860 | return ld_r_r (buf, info, mytxt); |
599 | 860 | } |
600 | | |
601 | | static int |
602 | | prt_d_n (struct buffer *buf, disassemble_info * info, const char *txt) |
603 | 307 | { |
604 | 307 | char mytxt[TXTSIZ]; |
605 | 307 | int d; |
606 | 307 | signed char *p; |
607 | | |
608 | 307 | p = buf->data + buf->n_fetch; |
609 | | |
610 | 307 | if (fetch_data (buf, info, 1)) |
611 | 306 | { |
612 | 306 | d = p[0]; |
613 | 306 | snprintf (mytxt, TXTSIZ, txt, d); |
614 | 306 | return prt_n (buf, info, mytxt); |
615 | 306 | } |
616 | 1 | else |
617 | 1 | buf->n_used = -1; |
618 | | |
619 | 1 | return buf->n_used; |
620 | 307 | } |
621 | | |
622 | | static int |
623 | | arit_d (struct buffer *buf, disassemble_info * info, const char *txt) |
624 | 472 | { |
625 | 472 | char mytxt[TXTSIZ]; |
626 | 472 | signed char c; |
627 | 472 | const char * const *arit; |
628 | | |
629 | 472 | arit = (buf->inss & INSS_EZ80) ? arit_str_ez80 : arit_str; |
630 | 472 | c = buf->data[buf->n_fetch - 1]; |
631 | 472 | snprintf (mytxt, TXTSIZ, txt, arit[(c >> 3) & 7]); |
632 | 472 | return prt_d (buf, info, mytxt); |
633 | 472 | } |
634 | | |
635 | | static int |
636 | | ld_r_d (struct buffer *buf, disassemble_info * info, const char *txt) |
637 | 684 | { |
638 | 684 | char mytxt[TXTSIZ]; |
639 | 684 | signed char c; |
640 | | |
641 | 684 | c = buf->data[buf->n_fetch - 1]; |
642 | 684 | snprintf (mytxt, TXTSIZ, txt, r_str[(c >> 3) & 7]); |
643 | 684 | return prt_d (buf, info, mytxt); |
644 | 684 | } |
645 | | |
646 | | static int |
647 | | ld_d_r (struct buffer *buf, disassemble_info * info, const char *txt) |
648 | 2.01k | { |
649 | 2.01k | char mytxt[TXTSIZ]; |
650 | 2.01k | signed char c; |
651 | | |
652 | 2.01k | c = buf->data[buf->n_fetch - 1]; |
653 | 2.01k | snprintf (mytxt, TXTSIZ, txt, r_str[c & 7]); |
654 | 2.01k | return prt_d (buf, info, mytxt); |
655 | 2.01k | } |
656 | | |
657 | | static int |
658 | | ld_ii_ii (struct buffer *buf, disassemble_info * info, const char *txt) |
659 | 316 | { |
660 | 316 | char mytxt[TXTSIZ]; |
661 | 316 | signed char c; |
662 | 316 | int p; |
663 | 316 | static const char *ii[2] = { "ix", "iy" }; |
664 | | |
665 | 316 | p = (buf->data[buf->n_fetch - 2] == (signed char) 0xdd) ? 0 : 1; |
666 | 316 | c = buf->data[buf->n_fetch - 1]; |
667 | 316 | if ((c & 0x07) != 0x07) |
668 | 173 | p = 1 - p; /* 0 -> 1, 1 -> 0 */ |
669 | 316 | snprintf (mytxt, TXTSIZ, txt, ii[p]); |
670 | 316 | return prt_d (buf, info, mytxt); |
671 | 316 | } |
672 | | |
673 | | static int |
674 | | pref_xd_cb (struct buffer * buf, disassemble_info * info, const char *txt) |
675 | 1.64k | { |
676 | 1.64k | if (fetch_data (buf, info, 2)) |
677 | 1.64k | { |
678 | 1.64k | int d; |
679 | 1.64k | char arg[TXTSIZ]; |
680 | 1.64k | signed char *p; |
681 | | |
682 | 1.64k | buf->n_used = 4; |
683 | 1.64k | p = buf->data; |
684 | 1.64k | d = p[2]; |
685 | | |
686 | 1.64k | if (((p[3] & 0xC0) == 0x40) || ((p[3] & 7) == 0x06)) |
687 | 985 | snprintf (arg, TXTSIZ, "(%s%+d)", txt, d); |
688 | 660 | else |
689 | 660 | snprintf (arg, TXTSIZ, "(%s%+d),%s", txt, d, r_str[p[3] & 7]); |
690 | | |
691 | 1.64k | if ((p[3] & 0xc0) == 0) |
692 | 573 | info->fprintf_func (info->stream, "%s %s", |
693 | 573 | cb2_str[(buf->data[3] >> 3) & 7], |
694 | 573 | arg); |
695 | 1.07k | else |
696 | 1.07k | info->fprintf_func (info->stream, "%s %d,%s", |
697 | 1.07k | cb1_str[(buf->data[3] >> 6) & 3], |
698 | 1.07k | (buf->data[3] >> 3) & 7, |
699 | 1.07k | arg); |
700 | 1.64k | } |
701 | 3 | else |
702 | 3 | buf->n_used = -1; |
703 | | |
704 | 1.64k | return buf->n_used; |
705 | 1.64k | } |
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 | 34.5k | { |
755 | 34.5k | if (fetch_data (buf, info, 1)) |
756 | 34.5k | { |
757 | 34.5k | char mytxt[TXTSIZ]; |
758 | 34.5k | struct tab_elt *p; |
759 | | |
760 | 1.17M | for (p = opc_ind; p->val != (buf->data[1] & p->mask) || !mach_inst (buf, p); ++p) |
761 | 1.14M | ; |
762 | 34.5k | snprintf (mytxt, TXTSIZ, p->text, txt); |
763 | 34.5k | p->fp (buf, info, mytxt); |
764 | 34.5k | } |
765 | 18 | else |
766 | 18 | buf->n_used = -1; |
767 | | |
768 | 34.5k | return buf->n_used; |
769 | 34.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 | 156k | { |
777 | 156k | char mybuf[TXTSIZ*4]; |
778 | 156k | fprintf_ftype old_fprintf; |
779 | 156k | void *old_stream; |
780 | 156k | char *p; |
781 | | |
782 | 156k | switch (txt[2]) |
783 | 156k | { |
784 | 100k | case 'l': /* SIL or LIL */ |
785 | 100k | buf->nn_len = 3; |
786 | 100k | break; |
787 | 55.2k | case 's': /* SIS or LIS */ |
788 | 55.2k | buf->nn_len = 2; |
789 | 55.2k | break; |
790 | 0 | default: |
791 | 0 | abort (); |
792 | 156k | } |
793 | 156k | if (!fetch_data (buf, info, 1) |
794 | 156k | || buf->data[1] == 0x40 |
795 | 156k | || buf->data[1] == 0x49 |
796 | 156k | || buf->data[1] == 0x52 |
797 | 156k | || buf->data[1] == 0x5b) |
798 | 87.9k | { |
799 | | /* Double prefix, or end of data. */ |
800 | 87.9k | info->fprintf_func (info->stream, ".db 0x%02x ; %s", (unsigned)buf->data[0], txt); |
801 | 87.9k | buf->n_used = 1; |
802 | 87.9k | return buf->n_used; |
803 | 87.9k | } |
804 | | |
805 | 68.2k | old_fprintf = info->fprintf_func; |
806 | 68.2k | old_stream = info->stream; |
807 | 68.2k | info->fprintf_func = (fprintf_ftype) &sprintf; |
808 | 68.2k | info->stream = mybuf; |
809 | 68.2k | mybuf[0] = 0; |
810 | 68.2k | buf->base++; |
811 | 68.2k | if (print_insn_z80_buf (buf, info) >= 0) |
812 | 68.1k | buf->n_used++; |
813 | 68.2k | info->fprintf_func = old_fprintf; |
814 | 68.2k | info->stream = old_stream; |
815 | | |
816 | 254k | for (p = mybuf; *p; ++p) |
817 | 226k | if (*p == ' ') |
818 | 39.8k | break; |
819 | 68.2k | if (*p) |
820 | 39.8k | { |
821 | 39.8k | *p++ = '\0'; |
822 | 39.8k | info->fprintf_func (info->stream, "%s.%s %s", mybuf, txt, p); |
823 | 39.8k | } |
824 | 28.3k | else |
825 | 28.3k | info->fprintf_func (info->stream, "%s.%s", mybuf, txt); |
826 | 68.2k | return buf->n_used; |
827 | 156k | } |
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 | 32.3M | { |
964 | 32.3M | struct buffer buf; |
965 | | |
966 | 32.3M | buf.base = addr; |
967 | 32.3M | buf.inss = 1 << info->mach; |
968 | 32.3M | buf.nn_len = info->mach == bfd_mach_ez80_adl ? 3 : 2; |
969 | 32.3M | info->bytes_per_line = (buf.inss & INSS_EZ80) ? 6 : 4; /* <ss pp oo nn mm MM> OR <pp oo nn mm> */ |
970 | | |
971 | 32.3M | return print_insn_z80_buf (&buf, info); |
972 | 32.3M | } |
973 | | |
974 | | static int |
975 | | print_insn_z80_buf (struct buffer *buf, disassemble_info *info) |
976 | 32.4M | { |
977 | 32.4M | const struct tab_elt *p; |
978 | | |
979 | 32.4M | buf->n_fetch = 0; |
980 | 32.4M | buf->n_used = 0; |
981 | 32.4M | if (! fetch_data (buf, info, 1)) |
982 | 1 | return -1; |
983 | | |
984 | 32.4M | p = (buf->inss & INSS_GBZ80) ? opc_main_gbz80 : opc_main; |
985 | | |
986 | 376M | for (; p->val != (buf->data[0] & p->mask) || !mach_inst (buf, p); ++p) |
987 | 344M | ; |
988 | 32.4M | p->fp (buf, info, p->text); |
989 | | |
990 | 32.4M | return buf->n_used; |
991 | 32.4M | } |