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., 675 Mass Ave, Cambridge, MA 02139, 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
;
70 bfd_vma start
= priv
->insn_start
+ priv
->max_fetched
/ 2;
72 if ((nibble
% 4) != 0)
74 status
= (*info
->read_memory_func
) (start
,
76 (nibble
- priv
->max_fetched
) / 2,
80 (*info
->memory_error_func
) (status
, start
, info
);
81 longjmp (priv
->bailout
, 1);
86 char *p
= mybuf
+ priv
->max_fetched
/ 2;
88 for (i
= priv
->max_fetched
; 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 int z8k_lookup_instr
PARAMS ((unsigned char*, disassemble_info
*));
129 static void output_instr
130 PARAMS ((instr_data_s
*, unsigned long, disassemble_info
*));
131 static void unpack_instr
PARAMS ((instr_data_s
*, int, disassemble_info
*));
132 static void unparse_instr
PARAMS ((instr_data_s
*));
135 print_insn_z8k (addr
, info
, is_segmented
)
137 disassemble_info
*info
;
140 instr_data_s instr_data
;
142 info
->private_data
= (PTR
) &instr_data
;
143 instr_data
.max_fetched
= 0;
144 instr_data
.insn_start
= addr
;
145 if (setjmp (instr_data
.bailout
) != 0)
149 instr_data
.tabl_index
= z8k_lookup_instr (instr_data
.nibbles
, info
);
150 if (instr_data
.tabl_index
> 0)
152 unpack_instr (&instr_data
, is_segmented
, info
);
153 unparse_instr (&instr_data
);
154 output_instr (&instr_data
, addr
, info
);
155 return z8k_table
[instr_data
.tabl_index
].length
;
159 FETCH_DATA (info
, 4);
160 (*info
->fprintf_func
) (info
->stream
, ".word %02x%02x",
161 instr_data
.bytes
[0], instr_data
.bytes
[2]);
166 print_insn_z8001 (addr
, info
)
168 disassemble_info
*info
;
170 return print_insn_z8k (addr
, info
, 1);
173 print_insn_z8002 (addr
, info
)
175 disassemble_info
*info
;
177 return print_insn_z8k (addr
, info
, 0);
181 z8k_lookup_instr (nibbles
, info
)
182 unsigned char *nibbles
;
183 disassemble_info
*info
;
186 int nibl_index
, tabl_index
;
188 unsigned short instr_nibl
;
189 unsigned short tabl_datum
, datum_class
, datum_value
;
193 while (!nibl_matched
&& z8k_table
[tabl_index
].name
)
196 for (nibl_index
= 0; nibl_index
< z8k_table
[tabl_index
].length
* 2 && nibl_matched
; nibl_index
++)
198 if ((nibl_index
% 4) == 0)
199 /* Fetch one word at a time. */
200 FETCH_DATA (info
, nibl_index
+ 4);
201 instr_nibl
= nibbles
[nibl_index
];
203 tabl_datum
= z8k_table
[tabl_index
].byte_info
[nibl_index
];
204 datum_class
= tabl_datum
& CLASS_MASK
;
205 datum_value
= ~CLASS_MASK
& tabl_datum
;
210 if (datum_value
!= instr_nibl
)
214 if (!((~instr_nibl
) & 0x4))
218 if (!(instr_nibl
& 0x4))
222 if (!((~instr_nibl
) & 0x8))
226 if (!(instr_nibl
& 0x8))
230 if (!((~instr_nibl
) & 0x8))
235 if (!(instr_nibl
& 0x8))
244 if ((instr_nibl
| 0x2) != (datum_value
| 0x2))
263 output_instr (instr_data
, addr
, info
)
264 instr_data_s
*instr_data
;
266 disassemble_info
*info
;
268 int loop
, loop_limit
;
272 strcpy (out_str
, "\t");
274 loop_limit
= z8k_table
[instr_data
->tabl_index
].length
* 2;
275 FETCH_DATA (info
, loop_limit
);
276 for (loop
= 0; loop
< loop_limit
; loop
++)
278 sprintf (tmp_str
, "%x", instr_data
->nibbles
[loop
]);
279 strcat (out_str
, tmp_str
);
284 strcat (out_str
, " ");
287 strcat (out_str
, instr_data
->instr_asmsrc
);
289 (*info
->fprintf_func
) (info
->stream
, "%s", out_str
);
293 unpack_instr (instr_data
, is_segmented
, info
)
294 instr_data_s
*instr_data
;
296 disassemble_info
*info
;
298 int nibl_count
, loop
;
299 unsigned short instr_nibl
, instr_byte
, instr_word
;
301 unsigned short tabl_datum
, datum_class
, datum_value
;
305 while (z8k_table
[instr_data
->tabl_index
].byte_info
[loop
] != 0)
307 FETCH_DATA (info
, nibl_count
+ 4 - (nibl_count
% 4));
308 instr_nibl
= instr_data
->nibbles
[nibl_count
];
309 instr_byte
= instr_data
->bytes
[nibl_count
];
310 instr_word
= instr_data
->words
[nibl_count
];
312 tabl_datum
= z8k_table
[instr_data
->tabl_index
].byte_info
[loop
];
313 datum_class
= tabl_datum
& CLASS_MASK
;
314 datum_value
= tabl_datum
& ~CLASS_MASK
;
319 instr_data
->address
= instr_nibl
;
322 instr_data
->displacement
= instr_nibl
;
325 instr_data
->arg_reg
[datum_value
] = instr_nibl
;
331 instr_data
->displacement
= instr_word
;
335 instr_data
->displacement
= instr_word
& 0x0fff;
346 instr_data
->immediate
= instr_nibl
;
349 instr_data
->immediate
= (-instr_byte
);
353 instr_data
->immediate
= instr_byte
;
357 instr_data
->immediate
= instr_word
;
361 FETCH_DATA (info
, nibl_count
+ 8);
362 instr_long
= (instr_data
->words
[nibl_count
] << 16)
363 | (instr_data
->words
[nibl_count
+ 4]);
364 instr_data
->immediate
= instr_long
;
368 instr_data
->immediate
= instr_nibl
- 1;
371 /* missing ARG_IMMNMINUS1 */
373 instr_data
->immediate
= 1;
376 instr_data
->immediate
= 2;
379 instr_data
->immediate
= instr_nibl
& 0x3;
386 instr_data
->cond_code
= instr_nibl
;
389 instr_data
->ctrl_code
= instr_nibl
;
395 if (instr_nibl
& 0x8)
397 FETCH_DATA (info
, nibl_count
+ 8);
398 instr_long
= (instr_data
->words
[nibl_count
] << 16)
399 | (instr_data
->words
[nibl_count
+ 4]);
400 instr_data
->address
= ((instr_word
& 0x7f00) << 8) +
401 (instr_long
& 0xffff);
406 instr_data
->address
= ((instr_word
& 0x7f00) << 8) +
407 (instr_word
& 0x00ff);
413 instr_data
->address
= instr_word
;
418 instr_data
->cond_code
= instr_nibl
& 0x7;
421 instr_data
->cond_code
= instr_nibl
& 0x7;
424 instr_data
->displacement
= instr_byte
& 0x7f;
428 instr_data
->displacement
= instr_byte
& 0x7f;
432 instr_data
->interrupts
= instr_nibl
& 0x3;
435 instr_data
->interrupts
= instr_nibl
& 0x3;
441 instr_data
->arg_reg
[datum_value
] = instr_nibl
;
444 instr_data
->flags
= instr_nibl
;
447 instr_data
->arg_reg
[datum_value
] = instr_nibl
;
450 instr_data
->arg_reg
[datum_value
] = instr_nibl
;
453 instr_data
->arg_reg
[datum_value
] = instr_nibl
;
456 instr_data
->arg_reg
[datum_value
] = instr_nibl
;
459 instr_data
->arg_reg
[datum_value
] = instr_nibl
;
462 instr_data
->arg_reg
[datum_value
] = instr_nibl
;
474 unparse_instr (instr_data
)
475 instr_data_s
*instr_data
;
477 unsigned short tabl_datum
, datum_class
, datum_value
;
478 int loop
, loop_limit
;
479 char out_str
[80], tmp_str
[25];
481 sprintf (out_str
, "\t%s\t", z8k_table
[instr_data
->tabl_index
].name
);
483 loop_limit
= z8k_table
[instr_data
->tabl_index
].noperands
;
484 for (loop
= 0; loop
< loop_limit
; loop
++)
487 strcat (out_str
, ",");
489 tabl_datum
= z8k_table
[instr_data
->tabl_index
].arg_info
[loop
];
490 datum_class
= tabl_datum
& CLASS_MASK
;
491 datum_value
= tabl_datum
& ~CLASS_MASK
;
496 sprintf (tmp_str
, "0x%0x(R%d)", instr_data
->address
,
497 instr_data
->arg_reg
[datum_value
]);
498 strcat (out_str
, tmp_str
);
501 sprintf (tmp_str
, "r%d(#%x)", instr_data
->arg_reg
[datum_value
],
502 instr_data
->immediate
);
503 strcat (out_str
, tmp_str
);
506 sprintf (tmp_str
, "r%d(R%d)", instr_data
->arg_reg
[datum_value
],
507 instr_data
->arg_reg
[ARG_RX
]);
508 strcat (out_str
, tmp_str
);
511 sprintf (tmp_str
, "#0x%0x", instr_data
->displacement
);
512 strcat (out_str
, tmp_str
);
515 sprintf (tmp_str
, "#0x%0x", instr_data
->immediate
);
516 strcat (out_str
, tmp_str
);
519 sprintf (tmp_str
, "%s", codes
[instr_data
->cond_code
]);
520 strcat (out_str
, tmp_str
);
523 sprintf (tmp_str
, "0x%0x", instr_data
->ctrl_code
);
524 strcat (out_str
, tmp_str
);
528 sprintf (tmp_str
, "#0x%0x", instr_data
->address
);
529 strcat (out_str
, tmp_str
);
532 sprintf (tmp_str
, "@R%d", instr_data
->arg_reg
[datum_value
]);
533 strcat (out_str
, tmp_str
);
536 sprintf (tmp_str
, "0x%0x", instr_data
->flags
);
537 strcat (out_str
, tmp_str
);
540 if (instr_data
->arg_reg
[datum_value
] >= 0x8)
542 sprintf (tmp_str
, "rl%d",
543 instr_data
->arg_reg
[datum_value
] - 0x8);
547 sprintf (tmp_str
, "rh%d", instr_data
->arg_reg
[datum_value
]);
549 strcat (out_str
, tmp_str
);
552 sprintf (tmp_str
, "r%d", instr_data
->arg_reg
[datum_value
]);
553 strcat (out_str
, tmp_str
);
556 sprintf (tmp_str
, "rq%d", instr_data
->arg_reg
[datum_value
]);
557 strcat (out_str
, tmp_str
);
560 sprintf (tmp_str
, "rr%d", instr_data
->arg_reg
[datum_value
]);
561 strcat (out_str
, tmp_str
);
568 strcpy (instr_data
->instr_asmsrc
, out_str
);
This page took 0.040971 seconds and 4 git commands to generate.