1 /* Disassemble z8000 code.
2 Copyright 1992, 1993, 1998, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program 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 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
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., 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
;
71 if ((nibble
% 4) != 0)
74 status
= (*info
->read_memory_func
) (priv
->insn_start
,
80 (*info
->memory_error_func
) (status
, priv
->insn_start
, info
);
81 longjmp (priv
->bailout
, 1);
86 unsigned char *p
= mybuf
;
88 for (i
= 0; i
< nibble
;)
90 priv
->words
[i
] = (p
[0] << 8) | p
[1];
93 priv
->nibbles
[i
++] = *p
>> 4;
94 priv
->nibbles
[i
++] = *p
& 0xf;
98 priv
->nibbles
[i
++] = *p
>> 4;
99 priv
->nibbles
[i
++] = *p
& 0xf;
104 priv
->max_fetched
= nibble
;
108 static char *codes
[16] =
128 static char *ctrl_names
[8] =
140 static int seg_length
;
141 int z8k_lookup_instr
PARAMS ((unsigned char *, disassemble_info
*));
142 static void output_instr
143 PARAMS ((instr_data_s
*, unsigned long, disassemble_info
*));
144 static void unpack_instr
PARAMS ((instr_data_s
*, int, disassemble_info
*));
145 static void unparse_instr
PARAMS ((instr_data_s
*, int));
148 print_insn_z8k (addr
, info
, is_segmented
)
150 disassemble_info
*info
;
153 instr_data_s instr_data
;
155 info
->private_data
= (PTR
) &instr_data
;
156 instr_data
.max_fetched
= 0;
157 instr_data
.insn_start
= addr
;
158 if (setjmp (instr_data
.bailout
) != 0)
162 instr_data
.tabl_index
= z8k_lookup_instr (instr_data
.nibbles
, info
);
163 if (instr_data
.tabl_index
> 0)
165 unpack_instr (&instr_data
, is_segmented
, info
);
166 unparse_instr (&instr_data
, is_segmented
);
167 output_instr (&instr_data
, addr
, info
);
168 return z8k_table
[instr_data
.tabl_index
].length
+ seg_length
;
172 FETCH_DATA (info
, 4);
173 (*info
->fprintf_func
) (info
->stream
, ".word %02x%02x",
174 instr_data
.bytes
[0], instr_data
.bytes
[2]);
180 print_insn_z8001 (addr
, info
)
182 disassemble_info
*info
;
184 return print_insn_z8k (addr
, info
, 1);
188 print_insn_z8002 (addr
, info
)
190 disassemble_info
*info
;
192 return print_insn_z8k (addr
, info
, 0);
196 z8k_lookup_instr (nibbles
, info
)
197 unsigned char *nibbles
;
198 disassemble_info
*info
;
201 int nibl_index
, tabl_index
;
203 unsigned short instr_nibl
;
204 unsigned short tabl_datum
, datum_class
, datum_value
;
208 while (!nibl_matched
&& z8k_table
[tabl_index
].name
)
212 nibl_index
< z8k_table
[tabl_index
].length
* 2 && nibl_matched
;
215 if ((nibl_index
% 4) == 0)
216 /* Fetch one word at a time. */
217 FETCH_DATA (info
, nibl_index
+ 4);
218 instr_nibl
= nibbles
[nibl_index
];
220 tabl_datum
= z8k_table
[tabl_index
].byte_info
[nibl_index
];
221 datum_class
= tabl_datum
& CLASS_MASK
;
222 datum_value
= ~CLASS_MASK
& tabl_datum
;
227 if (datum_value
!= instr_nibl
)
231 if (!((~instr_nibl
) & 0x4))
235 if (!(instr_nibl
& 0x4))
239 if (!((~instr_nibl
) & 0x8))
243 if (!(instr_nibl
& 0x8))
247 if (!((~instr_nibl
) & 0x8))
252 if (!(instr_nibl
& 0x8))
261 if ((instr_nibl
| 0x2) != (datum_value
| 0x2))
280 output_instr (instr_data
, addr
, info
)
281 instr_data_s
*instr_data
;
283 disassemble_info
*info
;
285 int loop
, loop_limit
;
289 strcpy (out_str
, "\t");
291 loop_limit
= (z8k_table
[instr_data
->tabl_index
].length
+ seg_length
) * 2;
292 FETCH_DATA (info
, loop_limit
);
293 for (loop
= 0; loop
< loop_limit
; loop
++)
295 sprintf (tmp_str
, "%x", instr_data
->nibbles
[loop
]);
296 strcat (out_str
, tmp_str
);
301 strcat (out_str
, " ");
304 strcat (out_str
, instr_data
->instr_asmsrc
);
306 (*info
->fprintf_func
) (info
->stream
, "%s", out_str
);
310 unpack_instr (instr_data
, is_segmented
, info
)
311 instr_data_s
*instr_data
;
313 disassemble_info
*info
;
315 int nibl_count
, loop
;
316 unsigned short instr_nibl
, instr_byte
, instr_word
;
318 unsigned int tabl_datum
, datum_class
;
319 unsigned short datum_value
;
324 while (z8k_table
[instr_data
->tabl_index
].byte_info
[loop
] != 0)
326 FETCH_DATA (info
, nibl_count
+ 4 - (nibl_count
% 4));
327 instr_nibl
= instr_data
->nibbles
[nibl_count
];
328 instr_byte
= instr_data
->bytes
[nibl_count
&~1];
329 instr_word
= instr_data
->words
[nibl_count
&~3];
331 tabl_datum
= z8k_table
[instr_data
->tabl_index
].byte_info
[loop
];
332 datum_class
= tabl_datum
& CLASS_MASK
;
333 datum_value
= tabl_datum
& ~CLASS_MASK
;
341 instr_data
->displacement
= instr_data
->insn_start
+ 4 +
342 (signed short)(instr_word
& 0xffff);
346 if (instr_word
& 0x800) { /* neg. 12 bit displacement */
347 instr_data
->displacement
= instr_data
->insn_start
+ 2 -
348 (signed short)((instr_word
& 0xfff) | 0xf000) * 2;
351 instr_data
->displacement
= instr_data
->insn_start
+ 2 - (instr_word
& 0x0fff) * 2;
363 instr_data
->immediate
= instr_nibl
;
366 instr_data
->immediate
= (-instr_byte
);
370 instr_data
->immediate
= instr_byte
;
374 instr_data
->immediate
= instr_word
;
378 FETCH_DATA (info
, nibl_count
+ 8);
379 instr_long
= (instr_data
->words
[nibl_count
] << 16)
380 | (instr_data
->words
[nibl_count
+ 4]);
381 instr_data
->immediate
= instr_long
;
385 instr_data
->immediate
= instr_nibl
- 1;
388 instr_data
->immediate
= instr_nibl
+ 1;
391 instr_data
->immediate
= 1;
394 instr_data
->immediate
= 2;
397 instr_data
->immediate
= instr_nibl
& 0x3;
404 instr_data
->cond_code
= instr_nibl
;
409 if (instr_nibl
& 0x8)
411 FETCH_DATA (info
, nibl_count
+ 8);
412 instr_long
= (instr_data
->words
[nibl_count
] << 16)
413 | (instr_data
->words
[nibl_count
+ 4]);
414 instr_data
->address
= ((instr_word
& 0x7f00) << 8) +
415 (instr_long
& 0xffff);
421 instr_data
->address
= ((instr_word
& 0x7f00) << 8) +
422 (instr_word
& 0x00ff);
428 instr_data
->address
= instr_word
;
434 instr_data
->ctrl_code
= instr_nibl
& 0x7;
437 instr_data
->displacement
= instr_data
->insn_start
+ 2 - (instr_byte
& 0x7f) * 2;
441 instr_data
->displacement
= instr_data
->insn_start
+ 2 - (instr_byte
& 0x7f) * 2;
445 instr_data
->interrupts
= instr_nibl
& 0x3;
448 instr_data
->interrupts
= instr_nibl
& 0x3;
451 instr_data
->ctrl_code
= instr_nibl
& 0x7;
454 instr_data
->flags
= instr_nibl
;
457 instr_data
->arg_reg
[datum_value
] = instr_nibl
;
460 instr_data
->arg_reg
[datum_value
] = instr_nibl
;
463 instr_data
->displacement
= instr_data
->insn_start
+ 2 + (signed char)instr_byte
* 2;
477 unparse_instr (instr_data
,is_segmented
)
478 instr_data_s
*instr_data
;
481 unsigned short datum_value
;
482 unsigned int tabl_datum
, datum_class
;
483 int loop
, loop_limit
;
484 char out_str
[80], tmp_str
[25];
486 sprintf (out_str
, "\t%s\t", z8k_table
[instr_data
->tabl_index
].name
);
488 loop_limit
= z8k_table
[instr_data
->tabl_index
].noperands
;
489 for (loop
= 0; loop
< loop_limit
; loop
++)
492 strcat (out_str
, ",");
494 tabl_datum
= z8k_table
[instr_data
->tabl_index
].arg_info
[loop
];
495 datum_class
= tabl_datum
& CLASS_MASK
;
496 datum_value
= tabl_datum
& ~CLASS_MASK
;
501 sprintf (tmp_str
, "0x%0lx(R%ld)", instr_data
->address
,
502 instr_data
->arg_reg
[datum_value
]);
503 strcat (out_str
, tmp_str
);
506 sprintf (tmp_str
, "r%ld(#%lx)", instr_data
->arg_reg
[datum_value
],
507 instr_data
->immediate
);
508 strcat (out_str
, tmp_str
);
511 sprintf (tmp_str
, "r%ld(R%ld)", instr_data
->arg_reg
[datum_value
],
512 instr_data
->arg_reg
[ARG_RX
]);
513 strcat (out_str
, tmp_str
);
516 sprintf (tmp_str
, "0x%0lx", instr_data
->displacement
);
517 strcat (out_str
, tmp_str
);
520 sprintf (tmp_str
, "#0x%0lx", instr_data
->immediate
);
521 strcat (out_str
, tmp_str
);
524 sprintf (tmp_str
, "%s", codes
[instr_data
->cond_code
]);
525 strcat (out_str
, tmp_str
);
528 sprintf (tmp_str
, "%s", ctrl_names
[instr_data
->ctrl_code
]);
529 strcat (out_str
, tmp_str
);
533 sprintf (tmp_str
, "0x%0lx", instr_data
->address
);
534 strcat (out_str
, tmp_str
);
537 sprintf (tmp_str
, "@R%ld", instr_data
->arg_reg
[datum_value
]);
538 strcat (out_str
, tmp_str
);
541 sprintf (tmp_str
, "0x%0lx", instr_data
->flags
);
542 strcat (out_str
, tmp_str
);
545 if (instr_data
->arg_reg
[datum_value
] >= 0x8)
547 sprintf (tmp_str
, "rl%ld",
548 instr_data
->arg_reg
[datum_value
] - 0x8);
552 sprintf (tmp_str
, "rh%ld", instr_data
->arg_reg
[datum_value
]);
554 strcat (out_str
, tmp_str
);
557 sprintf (tmp_str
, "r%ld", instr_data
->arg_reg
[datum_value
]);
558 strcat (out_str
, tmp_str
);
561 sprintf (tmp_str
, "rq%ld", instr_data
->arg_reg
[datum_value
]);
562 strcat (out_str
, tmp_str
);
565 sprintf (tmp_str
, "rr%ld", instr_data
->arg_reg
[datum_value
]);
566 strcat (out_str
, tmp_str
);
570 sprintf (tmp_str
, "rr%ld", instr_data
->arg_reg
[datum_value
]);
572 sprintf (tmp_str
, "r%ld", instr_data
->arg_reg
[datum_value
]);
573 strcat (out_str
, tmp_str
);
581 strcpy (instr_data
->instr_asmsrc
, out_str
);
This page took 0.040905 seconds and 4 git commands to generate.