| 1 | /* Disassemble z8000 code. | 
|---|
| 2 | Copyright 1992, 1993, 1998, 2000 | 
|---|
| 3 | Free Software Foundation, Inc. | 
|---|
| 4 |  | 
|---|
| 5 | This file is part of GNU Binutils. | 
|---|
| 6 |  | 
|---|
| 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. | 
|---|
| 11 |  | 
|---|
| 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. | 
|---|
| 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */ | 
|---|
| 20 |  | 
|---|
| 21 | #include "sysdep.h" | 
|---|
| 22 | #include "dis-asm.h" | 
|---|
| 23 |  | 
|---|
| 24 | #define DEFINE_TABLE | 
|---|
| 25 | #include "z8k-opc.h" | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | #include <setjmp.h> | 
|---|
| 29 |  | 
|---|
| 30 |  | 
|---|
| 31 | typedef struct | 
|---|
| 32 | { | 
|---|
| 33 | /* These are all indexed by nibble number (i.e only every other entry | 
|---|
| 34 | of bytes is used, and every 4th entry of words).  */ | 
|---|
| 35 | unsigned char nibbles[24]; | 
|---|
| 36 | unsigned char bytes[24]; | 
|---|
| 37 | unsigned short words[24]; | 
|---|
| 38 |  | 
|---|
| 39 | /* Nibble number of first word not yet fetched.  */ | 
|---|
| 40 | int max_fetched; | 
|---|
| 41 | bfd_vma insn_start; | 
|---|
| 42 | jmp_buf bailout; | 
|---|
| 43 |  | 
|---|
| 44 | long tabl_index; | 
|---|
| 45 | char instr_asmsrc[80]; | 
|---|
| 46 | unsigned long arg_reg[0x0f]; | 
|---|
| 47 | unsigned long immediate; | 
|---|
| 48 | unsigned long displacement; | 
|---|
| 49 | unsigned long address; | 
|---|
| 50 | unsigned long cond_code; | 
|---|
| 51 | unsigned long ctrl_code; | 
|---|
| 52 | unsigned long flags; | 
|---|
| 53 | unsigned long interrupts; | 
|---|
| 54 | } | 
|---|
| 55 | instr_data_s; | 
|---|
| 56 |  | 
|---|
| 57 | /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive) | 
|---|
| 58 | to ADDR (exclusive) are valid.  Returns 1 for success, longjmps | 
|---|
| 59 | on error.  */ | 
|---|
| 60 | #define FETCH_DATA(info, nibble) \ | 
|---|
| 61 | ((nibble) < ((instr_data_s *)(info->private_data))->max_fetched \ | 
|---|
| 62 | ? 1 : fetch_data ((info), (nibble))) | 
|---|
| 63 |  | 
|---|
| 64 | static int | 
|---|
| 65 | fetch_data (info, nibble) | 
|---|
| 66 | struct disassemble_info *info; | 
|---|
| 67 | int nibble; | 
|---|
| 68 | { | 
|---|
| 69 | unsigned char mybuf[20]; | 
|---|
| 70 | int status; | 
|---|
| 71 | instr_data_s *priv = (instr_data_s *) info->private_data; | 
|---|
| 72 |  | 
|---|
| 73 | if ((nibble % 4) != 0) | 
|---|
| 74 | abort (); | 
|---|
| 75 |  | 
|---|
| 76 | status = (*info->read_memory_func) (priv->insn_start, | 
|---|
| 77 | (bfd_byte *) mybuf, | 
|---|
| 78 | nibble / 2, | 
|---|
| 79 | info); | 
|---|
| 80 | if (status != 0) | 
|---|
| 81 | { | 
|---|
| 82 | (*info->memory_error_func) (status, priv->insn_start, info); | 
|---|
| 83 | longjmp (priv->bailout, 1); | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | { | 
|---|
| 87 | int i; | 
|---|
| 88 | unsigned char *p = mybuf; | 
|---|
| 89 |  | 
|---|
| 90 | for (i = 0; i < nibble;) | 
|---|
| 91 | { | 
|---|
| 92 | priv->words[i] = (p[0] << 8) | p[1]; | 
|---|
| 93 |  | 
|---|
| 94 | priv->bytes[i] = *p; | 
|---|
| 95 | priv->nibbles[i++] = *p >> 4; | 
|---|
| 96 | priv->nibbles[i++] = *p & 0xf; | 
|---|
| 97 |  | 
|---|
| 98 | ++p; | 
|---|
| 99 | priv->bytes[i] = *p; | 
|---|
| 100 | priv->nibbles[i++] = *p >> 4; | 
|---|
| 101 | priv->nibbles[i++] = *p & 0xf; | 
|---|
| 102 |  | 
|---|
| 103 | ++p; | 
|---|
| 104 | } | 
|---|
| 105 | } | 
|---|
| 106 | priv->max_fetched = nibble; | 
|---|
| 107 | return 1; | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | static char *codes[16] = | 
|---|
| 111 | { | 
|---|
| 112 | "f", | 
|---|
| 113 | "lt", | 
|---|
| 114 | "le", | 
|---|
| 115 | "ule", | 
|---|
| 116 | "ov/pe", | 
|---|
| 117 | "mi", | 
|---|
| 118 | "eq", | 
|---|
| 119 | "c/ult", | 
|---|
| 120 | "t", | 
|---|
| 121 | "ge", | 
|---|
| 122 | "gt", | 
|---|
| 123 | "ugt", | 
|---|
| 124 | "nov/po", | 
|---|
| 125 | "pl", | 
|---|
| 126 | "ne", | 
|---|
| 127 | "nc/uge" | 
|---|
| 128 | }; | 
|---|
| 129 |  | 
|---|
| 130 | int z8k_lookup_instr PARAMS ((unsigned char *, disassemble_info *)); | 
|---|
| 131 | static void output_instr | 
|---|
| 132 | PARAMS ((instr_data_s *, unsigned long, disassemble_info *)); | 
|---|
| 133 | static void unpack_instr PARAMS ((instr_data_s *, int, disassemble_info *)); | 
|---|
| 134 | static void unparse_instr PARAMS ((instr_data_s *)); | 
|---|
| 135 |  | 
|---|
| 136 | static int | 
|---|
| 137 | print_insn_z8k (addr, info, is_segmented) | 
|---|
| 138 | bfd_vma addr; | 
|---|
| 139 | disassemble_info *info; | 
|---|
| 140 | int is_segmented; | 
|---|
| 141 | { | 
|---|
| 142 | instr_data_s instr_data; | 
|---|
| 143 |  | 
|---|
| 144 | info->private_data = (PTR) &instr_data; | 
|---|
| 145 | instr_data.max_fetched = 0; | 
|---|
| 146 | instr_data.insn_start = addr; | 
|---|
| 147 | if (setjmp (instr_data.bailout) != 0) | 
|---|
| 148 | /* Error return.  */ | 
|---|
| 149 | return -1; | 
|---|
| 150 |  | 
|---|
| 151 | instr_data.tabl_index = z8k_lookup_instr (instr_data.nibbles, info); | 
|---|
| 152 | if (instr_data.tabl_index > 0) | 
|---|
| 153 | { | 
|---|
| 154 | unpack_instr (&instr_data, is_segmented, info); | 
|---|
| 155 | unparse_instr (&instr_data); | 
|---|
| 156 | output_instr (&instr_data, addr, info); | 
|---|
| 157 | return z8k_table[instr_data.tabl_index].length; | 
|---|
| 158 | } | 
|---|
| 159 | else | 
|---|
| 160 | { | 
|---|
| 161 | FETCH_DATA (info, 4); | 
|---|
| 162 | (*info->fprintf_func) (info->stream, ".word %02x%02x", | 
|---|
| 163 | instr_data.bytes[0], instr_data.bytes[2]); | 
|---|
| 164 | return 2; | 
|---|
| 165 | } | 
|---|
| 166 | } | 
|---|
| 167 |  | 
|---|
| 168 | int | 
|---|
| 169 | print_insn_z8001 (addr, info) | 
|---|
| 170 | bfd_vma addr; | 
|---|
| 171 | disassemble_info *info; | 
|---|
| 172 | { | 
|---|
| 173 | return print_insn_z8k (addr, info, 1); | 
|---|
| 174 | } | 
|---|
| 175 |  | 
|---|
| 176 | int | 
|---|
| 177 | print_insn_z8002 (addr, info) | 
|---|
| 178 | bfd_vma addr; | 
|---|
| 179 | disassemble_info *info; | 
|---|
| 180 | { | 
|---|
| 181 | return print_insn_z8k (addr, info, 0); | 
|---|
| 182 | } | 
|---|
| 183 |  | 
|---|
| 184 | int | 
|---|
| 185 | z8k_lookup_instr (nibbles, info) | 
|---|
| 186 | unsigned char *nibbles; | 
|---|
| 187 | disassemble_info *info; | 
|---|
| 188 | { | 
|---|
| 189 |  | 
|---|
| 190 | int nibl_index, tabl_index; | 
|---|
| 191 | int nibl_matched; | 
|---|
| 192 | unsigned short instr_nibl; | 
|---|
| 193 | unsigned short tabl_datum, datum_class, datum_value; | 
|---|
| 194 |  | 
|---|
| 195 | nibl_matched = 0; | 
|---|
| 196 | tabl_index = 0; | 
|---|
| 197 | while (!nibl_matched && z8k_table[tabl_index].name) | 
|---|
| 198 | { | 
|---|
| 199 | nibl_matched = 1; | 
|---|
| 200 | for (nibl_index = 0; | 
|---|
| 201 | nibl_index < z8k_table[tabl_index].length * 2 && nibl_matched; | 
|---|
| 202 | nibl_index++) | 
|---|
| 203 | { | 
|---|
| 204 | if ((nibl_index % 4) == 0) | 
|---|
| 205 | /* Fetch one word at a time.  */ | 
|---|
| 206 | FETCH_DATA (info, nibl_index + 4); | 
|---|
| 207 | instr_nibl = nibbles[nibl_index]; | 
|---|
| 208 |  | 
|---|
| 209 | tabl_datum = z8k_table[tabl_index].byte_info[nibl_index]; | 
|---|
| 210 | datum_class = tabl_datum & CLASS_MASK; | 
|---|
| 211 | datum_value = ~CLASS_MASK & tabl_datum; | 
|---|
| 212 |  | 
|---|
| 213 | switch (datum_class) | 
|---|
| 214 | { | 
|---|
| 215 | case CLASS_BIT: | 
|---|
| 216 | if (datum_value != instr_nibl) | 
|---|
| 217 | nibl_matched = 0; | 
|---|
| 218 | break; | 
|---|
| 219 | case CLASS_00II: | 
|---|
| 220 | if (!((~instr_nibl) & 0x4)) | 
|---|
| 221 | nibl_matched = 0; | 
|---|
| 222 | break; | 
|---|
| 223 | case CLASS_01II: | 
|---|
| 224 | if (!(instr_nibl & 0x4)) | 
|---|
| 225 | nibl_matched = 0; | 
|---|
| 226 | break; | 
|---|
| 227 | case CLASS_0CCC: | 
|---|
| 228 | if (!((~instr_nibl) & 0x8)) | 
|---|
| 229 | nibl_matched = 0; | 
|---|
| 230 | break; | 
|---|
| 231 | case CLASS_1CCC: | 
|---|
| 232 | if (!(instr_nibl & 0x8)) | 
|---|
| 233 | nibl_matched = 0; | 
|---|
| 234 | break; | 
|---|
| 235 | case CLASS_0DISP7: | 
|---|
| 236 | if (!((~instr_nibl) & 0x8)) | 
|---|
| 237 | nibl_matched = 0; | 
|---|
| 238 | nibl_index += 1; | 
|---|
| 239 | break; | 
|---|
| 240 | case CLASS_1DISP7: | 
|---|
| 241 | if (!(instr_nibl & 0x8)) | 
|---|
| 242 | nibl_matched = 0; | 
|---|
| 243 | nibl_index += 1; | 
|---|
| 244 | break; | 
|---|
| 245 | case CLASS_REGN0: | 
|---|
| 246 | if (instr_nibl == 0) | 
|---|
| 247 | nibl_matched = 0; | 
|---|
| 248 | break; | 
|---|
| 249 | case CLASS_BIT_1OR2: | 
|---|
| 250 | if ((instr_nibl | 0x2) != (datum_value | 0x2)) | 
|---|
| 251 | nibl_matched = 0; | 
|---|
| 252 | break; | 
|---|
| 253 | default: | 
|---|
| 254 | break; | 
|---|
| 255 | } | 
|---|
| 256 | } | 
|---|
| 257 | if (nibl_matched) | 
|---|
| 258 | { | 
|---|
| 259 | return tabl_index; | 
|---|
| 260 | } | 
|---|
| 261 |  | 
|---|
| 262 | tabl_index++; | 
|---|
| 263 | } | 
|---|
| 264 | return -1; | 
|---|
| 265 |  | 
|---|
| 266 | } | 
|---|
| 267 |  | 
|---|
| 268 | static void | 
|---|
| 269 | output_instr (instr_data, addr, info) | 
|---|
| 270 | instr_data_s *instr_data; | 
|---|
| 271 | unsigned long addr; | 
|---|
| 272 | disassemble_info *info; | 
|---|
| 273 | { | 
|---|
| 274 | int loop, loop_limit; | 
|---|
| 275 | char tmp_str[20]; | 
|---|
| 276 | char out_str[100]; | 
|---|
| 277 |  | 
|---|
| 278 | strcpy (out_str, "\t"); | 
|---|
| 279 |  | 
|---|
| 280 | loop_limit = z8k_table[instr_data->tabl_index].length * 2; | 
|---|
| 281 | FETCH_DATA (info, loop_limit); | 
|---|
| 282 | for (loop = 0; loop < loop_limit; loop++) | 
|---|
| 283 | { | 
|---|
| 284 | sprintf (tmp_str, "%x", instr_data->nibbles[loop]); | 
|---|
| 285 | strcat (out_str, tmp_str); | 
|---|
| 286 | } | 
|---|
| 287 |  | 
|---|
| 288 | while (loop++ < 8) | 
|---|
| 289 | { | 
|---|
| 290 | strcat (out_str, " "); | 
|---|
| 291 | } | 
|---|
| 292 |  | 
|---|
| 293 | strcat (out_str, instr_data->instr_asmsrc); | 
|---|
| 294 |  | 
|---|
| 295 | (*info->fprintf_func) (info->stream, "%s", out_str); | 
|---|
| 296 | } | 
|---|
| 297 |  | 
|---|
| 298 | static void | 
|---|
| 299 | unpack_instr (instr_data, is_segmented, info) | 
|---|
| 300 | instr_data_s *instr_data; | 
|---|
| 301 | int is_segmented; | 
|---|
| 302 | disassemble_info *info; | 
|---|
| 303 | { | 
|---|
| 304 | int nibl_count, loop; | 
|---|
| 305 | unsigned short instr_nibl, instr_byte, instr_word; | 
|---|
| 306 | long instr_long; | 
|---|
| 307 | unsigned short tabl_datum, datum_class, datum_value; | 
|---|
| 308 |  | 
|---|
| 309 | nibl_count = 0; | 
|---|
| 310 | loop = 0; | 
|---|
| 311 | while (z8k_table[instr_data->tabl_index].byte_info[loop] != 0) | 
|---|
| 312 | { | 
|---|
| 313 | FETCH_DATA (info, nibl_count + 4 - (nibl_count % 4)); | 
|---|
| 314 | instr_nibl = instr_data->nibbles[nibl_count]; | 
|---|
| 315 | instr_byte = instr_data->bytes[nibl_count]; | 
|---|
| 316 | instr_word = instr_data->words[nibl_count]; | 
|---|
| 317 |  | 
|---|
| 318 | tabl_datum = z8k_table[instr_data->tabl_index].byte_info[loop]; | 
|---|
| 319 | datum_class = tabl_datum & CLASS_MASK; | 
|---|
| 320 | datum_value = tabl_datum & ~CLASS_MASK; | 
|---|
| 321 |  | 
|---|
| 322 | switch (datum_class) | 
|---|
| 323 | { | 
|---|
| 324 | case CLASS_X: | 
|---|
| 325 | instr_data->address = instr_nibl; | 
|---|
| 326 | break; | 
|---|
| 327 | case CLASS_BA: | 
|---|
| 328 | instr_data->displacement = instr_nibl; | 
|---|
| 329 | break; | 
|---|
| 330 | case CLASS_BX: | 
|---|
| 331 | instr_data->arg_reg[datum_value] = instr_nibl; | 
|---|
| 332 | break; | 
|---|
| 333 | case CLASS_DISP: | 
|---|
| 334 | switch (datum_value) | 
|---|
| 335 | { | 
|---|
| 336 | case ARG_DISP16: | 
|---|
| 337 | instr_data->displacement = instr_word; | 
|---|
| 338 | nibl_count += 3; | 
|---|
| 339 | break; | 
|---|
| 340 | case ARG_DISP12: | 
|---|
| 341 | instr_data->displacement = instr_word & 0x0fff; | 
|---|
| 342 | nibl_count += 2; | 
|---|
| 343 | break; | 
|---|
| 344 | default: | 
|---|
| 345 | break; | 
|---|
| 346 | } | 
|---|
| 347 | break; | 
|---|
| 348 | case CLASS_IMM: | 
|---|
| 349 | switch (datum_value) | 
|---|
| 350 | { | 
|---|
| 351 | case ARG_IMM4: | 
|---|
| 352 | instr_data->immediate = instr_nibl; | 
|---|
| 353 | break; | 
|---|
| 354 | case ARG_NIM8: | 
|---|
| 355 | instr_data->immediate = (-instr_byte); | 
|---|
| 356 | nibl_count += 1; | 
|---|
| 357 | break; | 
|---|
| 358 | case ARG_IMM8: | 
|---|
| 359 | instr_data->immediate = instr_byte; | 
|---|
| 360 | nibl_count += 1; | 
|---|
| 361 | break; | 
|---|
| 362 | case ARG_IMM16: | 
|---|
| 363 | instr_data->immediate = instr_word; | 
|---|
| 364 | nibl_count += 3; | 
|---|
| 365 | break; | 
|---|
| 366 | case ARG_IMM32: | 
|---|
| 367 | FETCH_DATA (info, nibl_count + 8); | 
|---|
| 368 | instr_long = (instr_data->words[nibl_count] << 16) | 
|---|
| 369 | | (instr_data->words[nibl_count + 4]); | 
|---|
| 370 | instr_data->immediate = instr_long; | 
|---|
| 371 | nibl_count += 7; | 
|---|
| 372 | break; | 
|---|
| 373 | case ARG_IMMN: | 
|---|
| 374 | instr_data->immediate = instr_nibl - 1; | 
|---|
| 375 | break; | 
|---|
| 376 | case ARG_IMM4M1: | 
|---|
| 377 | instr_data->immediate = instr_nibl + 1; | 
|---|
| 378 | break; | 
|---|
| 379 | case ARG_IMM_1: | 
|---|
| 380 | instr_data->immediate = 1; | 
|---|
| 381 | break; | 
|---|
| 382 | case ARG_IMM_2: | 
|---|
| 383 | instr_data->immediate = 2; | 
|---|
| 384 | break; | 
|---|
| 385 | case ARG_IMM2: | 
|---|
| 386 | instr_data->immediate = instr_nibl & 0x3; | 
|---|
| 387 | break; | 
|---|
| 388 | default: | 
|---|
| 389 | break; | 
|---|
| 390 | } | 
|---|
| 391 | break; | 
|---|
| 392 | case CLASS_CC: | 
|---|
| 393 | instr_data->cond_code = instr_nibl; | 
|---|
| 394 | break; | 
|---|
| 395 | case CLASS_CTRL: | 
|---|
| 396 | instr_data->ctrl_code = instr_nibl; | 
|---|
| 397 | break; | 
|---|
| 398 | case CLASS_DA: | 
|---|
| 399 | case CLASS_ADDRESS: | 
|---|
| 400 | if (is_segmented) | 
|---|
| 401 | { | 
|---|
| 402 | if (instr_nibl & 0x8) | 
|---|
| 403 | { | 
|---|
| 404 | FETCH_DATA (info, nibl_count + 8); | 
|---|
| 405 | instr_long = (instr_data->words[nibl_count] << 16) | 
|---|
| 406 | | (instr_data->words[nibl_count + 4]); | 
|---|
| 407 | instr_data->address = ((instr_word & 0x7f00) << 8) + | 
|---|
| 408 | (instr_long & 0xffff); | 
|---|
| 409 | nibl_count += 7; | 
|---|
| 410 | } | 
|---|
| 411 | else | 
|---|
| 412 | { | 
|---|
| 413 | instr_data->address = ((instr_word & 0x7f00) << 8) + | 
|---|
| 414 | (instr_word & 0x00ff); | 
|---|
| 415 | nibl_count += 3; | 
|---|
| 416 | } | 
|---|
| 417 | } | 
|---|
| 418 | else | 
|---|
| 419 | { | 
|---|
| 420 | instr_data->address = instr_word; | 
|---|
| 421 | nibl_count += 3; | 
|---|
| 422 | } | 
|---|
| 423 | break; | 
|---|
| 424 | case CLASS_0CCC: | 
|---|
| 425 | instr_data->cond_code = instr_nibl & 0x7; | 
|---|
| 426 | break; | 
|---|
| 427 | case CLASS_1CCC: | 
|---|
| 428 | instr_data->cond_code = instr_nibl & 0x7; | 
|---|
| 429 | break; | 
|---|
| 430 | case CLASS_0DISP7: | 
|---|
| 431 | instr_data->displacement = instr_byte & 0x7f; | 
|---|
| 432 | nibl_count += 1; | 
|---|
| 433 | break; | 
|---|
| 434 | case CLASS_1DISP7: | 
|---|
| 435 | instr_data->displacement = instr_byte & 0x7f; | 
|---|
| 436 | nibl_count += 1; | 
|---|
| 437 | break; | 
|---|
| 438 | case CLASS_01II: | 
|---|
| 439 | instr_data->interrupts = instr_nibl & 0x3; | 
|---|
| 440 | break; | 
|---|
| 441 | case CLASS_00II: | 
|---|
| 442 | instr_data->interrupts = instr_nibl & 0x3; | 
|---|
| 443 | break; | 
|---|
| 444 | case CLASS_BIT: | 
|---|
| 445 | /* Do nothing.  */ | 
|---|
| 446 | break; | 
|---|
| 447 | case CLASS_IR: | 
|---|
| 448 | instr_data->arg_reg[datum_value] = instr_nibl; | 
|---|
| 449 | break; | 
|---|
| 450 | case CLASS_FLAGS: | 
|---|
| 451 | instr_data->flags = instr_nibl; | 
|---|
| 452 | break; | 
|---|
| 453 | case CLASS_REG: | 
|---|
| 454 | instr_data->arg_reg[datum_value] = instr_nibl; | 
|---|
| 455 | break; | 
|---|
| 456 | case CLASS_REG_BYTE: | 
|---|
| 457 | instr_data->arg_reg[datum_value] = instr_nibl; | 
|---|
| 458 | break; | 
|---|
| 459 | case CLASS_REG_WORD: | 
|---|
| 460 | instr_data->arg_reg[datum_value] = instr_nibl; | 
|---|
| 461 | break; | 
|---|
| 462 | case CLASS_REG_QUAD: | 
|---|
| 463 | instr_data->arg_reg[datum_value] = instr_nibl; | 
|---|
| 464 | break; | 
|---|
| 465 | case CLASS_REG_LONG: | 
|---|
| 466 | instr_data->arg_reg[datum_value] = instr_nibl; | 
|---|
| 467 | break; | 
|---|
| 468 | case CLASS_REGN0: | 
|---|
| 469 | instr_data->arg_reg[datum_value] = instr_nibl; | 
|---|
| 470 | break; | 
|---|
| 471 | default: | 
|---|
| 472 | break; | 
|---|
| 473 | } | 
|---|
| 474 |  | 
|---|
| 475 | loop += 1; | 
|---|
| 476 | nibl_count += 1; | 
|---|
| 477 | } | 
|---|
| 478 | } | 
|---|
| 479 |  | 
|---|
| 480 | static void | 
|---|
| 481 | unparse_instr (instr_data) | 
|---|
| 482 | instr_data_s *instr_data; | 
|---|
| 483 | { | 
|---|
| 484 | unsigned short tabl_datum, datum_class, datum_value; | 
|---|
| 485 | int loop, loop_limit; | 
|---|
| 486 | char out_str[80], tmp_str[25]; | 
|---|
| 487 |  | 
|---|
| 488 | sprintf (out_str, "\t%s\t", z8k_table[instr_data->tabl_index].name); | 
|---|
| 489 |  | 
|---|
| 490 | loop_limit = z8k_table[instr_data->tabl_index].noperands; | 
|---|
| 491 | for (loop = 0; loop < loop_limit; loop++) | 
|---|
| 492 | { | 
|---|
| 493 | if (loop) | 
|---|
| 494 | strcat (out_str, ","); | 
|---|
| 495 |  | 
|---|
| 496 | tabl_datum = z8k_table[instr_data->tabl_index].arg_info[loop]; | 
|---|
| 497 | datum_class = tabl_datum & CLASS_MASK; | 
|---|
| 498 | datum_value = tabl_datum & ~CLASS_MASK; | 
|---|
| 499 |  | 
|---|
| 500 | switch (datum_class) | 
|---|
| 501 | { | 
|---|
| 502 | case CLASS_X: | 
|---|
| 503 | sprintf (tmp_str, "0x%0lx(R%ld)", instr_data->address, | 
|---|
| 504 | instr_data->arg_reg[datum_value]); | 
|---|
| 505 | strcat (out_str, tmp_str); | 
|---|
| 506 | break; | 
|---|
| 507 | case CLASS_BA: | 
|---|
| 508 | sprintf (tmp_str, "r%ld(#%lx)", instr_data->arg_reg[datum_value], | 
|---|
| 509 | instr_data->immediate); | 
|---|
| 510 | strcat (out_str, tmp_str); | 
|---|
| 511 | break; | 
|---|
| 512 | case CLASS_BX: | 
|---|
| 513 | sprintf (tmp_str, "r%ld(R%ld)", instr_data->arg_reg[datum_value], | 
|---|
| 514 | instr_data->arg_reg[ARG_RX]); | 
|---|
| 515 | strcat (out_str, tmp_str); | 
|---|
| 516 | break; | 
|---|
| 517 | case CLASS_DISP: | 
|---|
| 518 | sprintf (tmp_str, "#0x%0lx", instr_data->displacement); | 
|---|
| 519 | strcat (out_str, tmp_str); | 
|---|
| 520 | break; | 
|---|
| 521 | case CLASS_IMM: | 
|---|
| 522 | sprintf (tmp_str, "#0x%0lx", instr_data->immediate); | 
|---|
| 523 | strcat (out_str, tmp_str); | 
|---|
| 524 | break; | 
|---|
| 525 | case CLASS_CC: | 
|---|
| 526 | sprintf (tmp_str, "%s", codes[instr_data->cond_code]); | 
|---|
| 527 | strcat (out_str, tmp_str); | 
|---|
| 528 | break; | 
|---|
| 529 | case CLASS_CTRL: | 
|---|
| 530 | sprintf (tmp_str, "0x%0lx", instr_data->ctrl_code); | 
|---|
| 531 | strcat (out_str, tmp_str); | 
|---|
| 532 | break; | 
|---|
| 533 | case CLASS_DA: | 
|---|
| 534 | case CLASS_ADDRESS: | 
|---|
| 535 | sprintf (tmp_str, "#0x%0lx", instr_data->address); | 
|---|
| 536 | strcat (out_str, tmp_str); | 
|---|
| 537 | break; | 
|---|
| 538 | case CLASS_IR: | 
|---|
| 539 | sprintf (tmp_str, "@R%ld", instr_data->arg_reg[datum_value]); | 
|---|
| 540 | strcat (out_str, tmp_str); | 
|---|
| 541 | break; | 
|---|
| 542 | case CLASS_FLAGS: | 
|---|
| 543 | sprintf (tmp_str, "0x%0lx", instr_data->flags); | 
|---|
| 544 | strcat (out_str, tmp_str); | 
|---|
| 545 | break; | 
|---|
| 546 | case CLASS_REG_BYTE: | 
|---|
| 547 | if (instr_data->arg_reg[datum_value] >= 0x8) | 
|---|
| 548 | { | 
|---|
| 549 | sprintf (tmp_str, "rl%ld", | 
|---|
| 550 | instr_data->arg_reg[datum_value] - 0x8); | 
|---|
| 551 | } | 
|---|
| 552 | else | 
|---|
| 553 | { | 
|---|
| 554 | sprintf (tmp_str, "rh%ld", instr_data->arg_reg[datum_value]); | 
|---|
| 555 | } | 
|---|
| 556 | strcat (out_str, tmp_str); | 
|---|
| 557 | break; | 
|---|
| 558 | case CLASS_REG_WORD: | 
|---|
| 559 | sprintf (tmp_str, "r%ld", instr_data->arg_reg[datum_value]); | 
|---|
| 560 | strcat (out_str, tmp_str); | 
|---|
| 561 | break; | 
|---|
| 562 | case CLASS_REG_QUAD: | 
|---|
| 563 | sprintf (tmp_str, "rq%ld", instr_data->arg_reg[datum_value]); | 
|---|
| 564 | strcat (out_str, tmp_str); | 
|---|
| 565 | break; | 
|---|
| 566 | case CLASS_REG_LONG: | 
|---|
| 567 | sprintf (tmp_str, "rr%ld", instr_data->arg_reg[datum_value]); | 
|---|
| 568 | strcat (out_str, tmp_str); | 
|---|
| 569 | break; | 
|---|
| 570 | default: | 
|---|
| 571 | break; | 
|---|
| 572 | } | 
|---|
| 573 | } | 
|---|
| 574 |  | 
|---|
| 575 | strcpy (instr_data->instr_asmsrc, out_str); | 
|---|
| 576 | } | 
|---|