2 This file is part of GNU Binutils.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 /* These are all indexed by nibble number (i.e only every other entry
32 of bytes is used, and every 4th entry of words). */
33 unsigned char nibbles[24];
34 unsigned char bytes[24];
35 unsigned short words[24];
37 /* Nibble number of first word not yet fetched. */
43 char instr_asmsrc[80];
44 unsigned long arg_reg[0x0f];
45 unsigned long immediate;
46 unsigned long displacement;
47 unsigned long address;
48 unsigned long cond_code;
49 unsigned long ctrl_code;
51 unsigned long interrupts;
55 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
56 to ADDR (exclusive) are valid. Returns 1 for success, longjmps
58 #define FETCH_DATA(info, nibble) \
59 ((nibble) < ((instr_data_s *)(info->private_data))->max_fetched \
60 ? 1 : fetch_data ((info), (nibble)))
63 fetch_data (info, nibble)
64 struct disassemble_info *info;
67 unsigned char mybuf[20];
69 instr_data_s *priv = (instr_data_s *)info->private_data;
72 if ((nibble % 4) != 0)
75 status = (*info->read_memory_func) (priv->insn_start,
81 (*info->memory_error_func) (status, priv->insn_start, info);
82 longjmp (priv->bailout, 1);
87 unsigned char *p = mybuf ;
89 for (i = 0; i < nibble;)
91 priv->words[i] = (p[0] << 8) | p[1];
94 priv->nibbles[i++] = *p >> 4;
95 priv->nibbles[i++] = *p &0xf;
99 priv->nibbles[i++] = *p >> 4;
100 priv->nibbles[i++] = *p & 0xf;
105 priv->max_fetched = nibble;
109 static char *codes[16] =
129 int z8k_lookup_instr PARAMS ((unsigned char*, disassemble_info *));
130 static void output_instr
131 PARAMS ((instr_data_s *, unsigned long, disassemble_info *));
132 static void unpack_instr PARAMS ((instr_data_s *, int, disassemble_info *));
133 static void unparse_instr PARAMS ((instr_data_s *));
136 print_insn_z8k (addr, info, is_segmented)
138 disassemble_info *info;
141 instr_data_s instr_data;
143 info->private_data = (PTR) &instr_data;
144 instr_data.max_fetched = 0;
145 instr_data.insn_start = addr;
146 if (setjmp (instr_data.bailout) != 0)
150 instr_data.tabl_index = z8k_lookup_instr (instr_data.nibbles, info);
151 if (instr_data.tabl_index > 0)
153 unpack_instr (&instr_data, is_segmented, info);
154 unparse_instr (&instr_data);
155 output_instr (&instr_data, addr, info);
156 return z8k_table[instr_data.tabl_index].length;
160 FETCH_DATA (info, 4);
161 (*info->fprintf_func) (info->stream, ".word %02x%02x",
162 instr_data.bytes[0], instr_data.bytes[2]);
167 print_insn_z8001 (addr, info)
169 disassemble_info *info;
171 return print_insn_z8k (addr, info, 1);
174 print_insn_z8002 (addr, info)
176 disassemble_info *info;
178 return print_insn_z8k (addr, info, 0);
182 z8k_lookup_instr (nibbles, info)
183 unsigned char *nibbles;
184 disassemble_info *info;
187 int nibl_index, tabl_index;
189 unsigned short instr_nibl;
190 unsigned short tabl_datum, datum_class, datum_value;
194 while (!nibl_matched && z8k_table[tabl_index].name)
197 for (nibl_index = 0; nibl_index < z8k_table[tabl_index].length * 2 && nibl_matched; nibl_index++)
199 if ((nibl_index % 4) == 0)
200 /* Fetch one word at a time. */
201 FETCH_DATA (info, nibl_index + 4);
202 instr_nibl = nibbles[nibl_index];
204 tabl_datum = z8k_table[tabl_index].byte_info[nibl_index];
205 datum_class = tabl_datum & CLASS_MASK;
206 datum_value = ~CLASS_MASK & tabl_datum;
211 if (datum_value != instr_nibl)
215 if (!((~instr_nibl) & 0x4))
219 if (!(instr_nibl & 0x4))
223 if (!((~instr_nibl) & 0x8))
227 if (!(instr_nibl & 0x8))
231 if (!((~instr_nibl) & 0x8))
236 if (!(instr_nibl & 0x8))
245 if ((instr_nibl | 0x2) != (datum_value | 0x2))
264 output_instr (instr_data, addr, info)
265 instr_data_s *instr_data;
267 disassemble_info *info;
269 int loop, loop_limit;
273 strcpy (out_str, "\t");
275 loop_limit = z8k_table[instr_data->tabl_index].length * 2;
276 FETCH_DATA (info, loop_limit);
277 for (loop = 0; loop < loop_limit; loop++)
279 sprintf (tmp_str, "%x", instr_data->nibbles[loop]);
280 strcat (out_str, tmp_str);
285 strcat (out_str, " ");
288 strcat (out_str, instr_data->instr_asmsrc);
290 (*info->fprintf_func) (info->stream, "%s", out_str);
294 unpack_instr (instr_data, is_segmented, info)
295 instr_data_s *instr_data;
297 disassemble_info *info;
299 int nibl_count, loop;
300 unsigned short instr_nibl, instr_byte, instr_word;
302 unsigned short tabl_datum, datum_class, datum_value;
306 while (z8k_table[instr_data->tabl_index].byte_info[loop] != 0)
308 FETCH_DATA (info, nibl_count + 4 - (nibl_count % 4));
309 instr_nibl = instr_data->nibbles[nibl_count];
310 instr_byte = instr_data->bytes[nibl_count];
311 instr_word = instr_data->words[nibl_count];
313 tabl_datum = z8k_table[instr_data->tabl_index].byte_info[loop];
314 datum_class = tabl_datum & CLASS_MASK;
315 datum_value = tabl_datum & ~CLASS_MASK;
320 instr_data->address = instr_nibl;
323 instr_data->displacement = instr_nibl;
326 instr_data->arg_reg[datum_value] = instr_nibl;
332 instr_data->displacement = instr_word;
336 instr_data->displacement = instr_word & 0x0fff;
347 instr_data->immediate = instr_nibl;
350 instr_data->immediate = (-instr_byte);
354 instr_data->immediate = instr_byte;
358 instr_data->immediate = instr_word;
362 FETCH_DATA (info, nibl_count + 8);
363 instr_long = (instr_data->words[nibl_count] << 16)
364 | (instr_data->words[nibl_count + 4]);
365 instr_data->immediate = instr_long;
369 instr_data->immediate = instr_nibl - 1;
372 instr_data->immediate = instr_nibl + 1;
375 instr_data->immediate = 1;
378 instr_data->immediate = 2;
381 instr_data->immediate = instr_nibl & 0x3;
388 instr_data->cond_code = instr_nibl;
391 instr_data->ctrl_code = instr_nibl;
397 if (instr_nibl & 0x8)
399 FETCH_DATA (info, nibl_count + 8);
400 instr_long = (instr_data->words[nibl_count] << 16)
401 | (instr_data->words[nibl_count + 4]);
402 instr_data->address = ((instr_word & 0x7f00) << 8) +
403 (instr_long & 0xffff);
408 instr_data->address = ((instr_word & 0x7f00) << 8) +
409 (instr_word & 0x00ff);
415 instr_data->address = instr_word;
420 instr_data->cond_code = instr_nibl & 0x7;
423 instr_data->cond_code = instr_nibl & 0x7;
426 instr_data->displacement = instr_byte & 0x7f;
430 instr_data->displacement = instr_byte & 0x7f;
434 instr_data->interrupts = instr_nibl & 0x3;
437 instr_data->interrupts = instr_nibl & 0x3;
443 instr_data->arg_reg[datum_value] = instr_nibl;
446 instr_data->flags = instr_nibl;
449 instr_data->arg_reg[datum_value] = instr_nibl;
452 instr_data->arg_reg[datum_value] = instr_nibl;
455 instr_data->arg_reg[datum_value] = instr_nibl;
458 instr_data->arg_reg[datum_value] = instr_nibl;
461 instr_data->arg_reg[datum_value] = instr_nibl;
464 instr_data->arg_reg[datum_value] = instr_nibl;
476 unparse_instr (instr_data)
477 instr_data_s *instr_data;
479 unsigned short tabl_datum, datum_class, datum_value;
480 int loop, loop_limit;
481 char out_str[80], tmp_str[25];
483 sprintf (out_str, "\t%s\t", z8k_table[instr_data->tabl_index].name);
485 loop_limit = z8k_table[instr_data->tabl_index].noperands;
486 for (loop = 0; loop < loop_limit; loop++)
489 strcat (out_str, ",");
491 tabl_datum = z8k_table[instr_data->tabl_index].arg_info[loop];
492 datum_class = tabl_datum & CLASS_MASK;
493 datum_value = tabl_datum & ~CLASS_MASK;
498 sprintf (tmp_str, "0x%0x(R%d)", instr_data->address,
499 instr_data->arg_reg[datum_value]);
500 strcat (out_str, tmp_str);
503 sprintf (tmp_str, "r%d(#%x)", instr_data->arg_reg[datum_value],
504 instr_data->immediate);
505 strcat (out_str, tmp_str);
508 sprintf (tmp_str, "r%d(R%d)", instr_data->arg_reg[datum_value],
509 instr_data->arg_reg[ARG_RX]);
510 strcat (out_str, tmp_str);
513 sprintf (tmp_str, "#0x%0x", instr_data->displacement);
514 strcat (out_str, tmp_str);
517 sprintf (tmp_str, "#0x%0x", instr_data->immediate);
518 strcat (out_str, tmp_str);
521 sprintf (tmp_str, "%s", codes[instr_data->cond_code]);
522 strcat (out_str, tmp_str);
525 sprintf (tmp_str, "0x%0x", instr_data->ctrl_code);
526 strcat (out_str, tmp_str);
530 sprintf (tmp_str, "#0x%0x", instr_data->address);
531 strcat (out_str, tmp_str);
534 sprintf (tmp_str, "@R%d", instr_data->arg_reg[datum_value]);
535 strcat (out_str, tmp_str);
538 sprintf (tmp_str, "0x%0x", instr_data->flags);
539 strcat (out_str, tmp_str);
542 if (instr_data->arg_reg[datum_value] >= 0x8)
544 sprintf (tmp_str, "rl%d",
545 instr_data->arg_reg[datum_value] - 0x8);
549 sprintf (tmp_str, "rh%d", instr_data->arg_reg[datum_value]);
551 strcat (out_str, tmp_str);
554 sprintf (tmp_str, "r%d", instr_data->arg_reg[datum_value]);
555 strcat (out_str, tmp_str);
558 sprintf (tmp_str, "rq%d", instr_data->arg_reg[datum_value]);
559 strcat (out_str, tmp_str);
562 sprintf (tmp_str, "rr%d", instr_data->arg_reg[datum_value]);
563 strcat (out_str, tmp_str);
570 strcpy (instr_data->instr_asmsrc, out_str);