src/emu/cpu/mips/mips3fe.c
| r0 | r1037 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | mips3fe.c |
| 4 | |
| 5 | Front-end for MIPS3 recompiler |
| 6 | |
| 7 | ***************************************************************************/ |
| 8 | |
| 9 | #include <stddef.h> |
| 10 | #include "cpuintrf.h" |
| 11 | #include "mips3fe.h" |
| 12 | |
| 13 | |
| 14 | /*************************************************************************** |
| 15 | CONSTANTS |
| 16 | ***************************************************************************/ |
| 17 | |
| 18 | #define MAX_STACK_DEPTH 100 |
| 19 | |
| 20 | |
| 21 | |
| 22 | /*************************************************************************** |
| 23 | TYPE DEFINITIONS |
| 24 | ***************************************************************************/ |
| 25 | |
| 26 | typedef struct _pc_stack_entry pc_stack_entry; |
| 27 | struct _pc_stack_entry |
| 28 | { |
| 29 | UINT32 targetpc; |
| 30 | UINT32 srcpc; |
| 31 | }; |
| 32 | |
| 33 | |
| 34 | |
| 35 | /*************************************************************************** |
| 36 | LOCAL VARAIBLES |
| 37 | ***************************************************************************/ |
| 38 | |
| 39 | static mips3_opcode_desc *desc_free_list; |
| 40 | static mips3_opcode_desc **desc_array; |
| 41 | static UINT32 desc_array_size; |
| 42 | static UINT32 dummy_nop = 0; |
| 43 | |
| 44 | |
| 45 | |
| 46 | /*************************************************************************** |
| 47 | FUNCTION PROTOTYPES |
| 48 | ***************************************************************************/ |
| 49 | |
| 50 | static int describe_one(mips3_state *mips, UINT32 curpc, mips3_opcode_desc *curdesc); |
| 51 | static void describe_instruction(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc); |
| 52 | static void describe_instruction_special(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc); |
| 53 | static void describe_instruction_regimm(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc); |
| 54 | static void describe_instruction_idt(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc); |
| 55 | static void describe_instruction_cop0(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc); |
| 56 | static void describe_instruction_cop1(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc); |
| 57 | static void describe_instruction_cop1x(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc); |
| 58 | static void describe_instruction_cop2(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc); |
| 59 | |
| 60 | |
| 61 | |
| 62 | /*************************************************************************** |
| 63 | INLINE FUNCTIONS |
| 64 | ***************************************************************************/ |
| 65 | |
| 66 | INLINE mips3_opcode_desc *desc_alloc(void) |
| 67 | { |
| 68 | mips3_opcode_desc *desc = desc_free_list; |
| 69 | |
| 70 | /* pull a description off of the free list or allocate a new one */ |
| 71 | if (desc != NULL) |
| 72 | desc_free_list = desc->next; |
| 73 | else |
| 74 | desc = malloc_or_die(sizeof(*desc)); |
| 75 | return desc; |
| 76 | } |
| 77 | |
| 78 | |
| 79 | INLINE void desc_free(mips3_opcode_desc *desc) |
| 80 | { |
| 81 | /* just put ourselves on the free list */ |
| 82 | desc->next = desc_free_list; |
| 83 | desc_free_list = desc; |
| 84 | } |
| 85 | |
| 86 | |
| 87 | INLINE void invalid_opcode(mips3_opcode_desc *desc) |
| 88 | { |
| 89 | desc->flags |= IDESC_WILL_CAUSE_EXCEPTION | IDESC_END_SEQUENCE | IDESC_INVALID_OPCODE; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | INLINE int is_fixed_mapped(UINT32 pc) |
| 94 | { |
| 95 | return (pc >= 0x80000000 && pc < 0xc0000000); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | |
| 100 | /*************************************************************************** |
| 101 | CORE IMPLEMENTATION |
| 102 | ***************************************************************************/ |
| 103 | |
| 104 | /*------------------------------------------------- |
| 105 | mips3fe_init - initialization |
| 106 | -------------------------------------------------*/ |
| 107 | |
| 108 | void mips3fe_init(void) |
| 109 | { |
| 110 | desc_free_list = NULL; |
| 111 | desc_array = NULL; |
| 112 | desc_array_size = 0; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | /*------------------------------------------------- |
| 117 | mipsfe_exit - clean up after ourselves |
| 118 | -------------------------------------------------*/ |
| 119 | |
| 120 | void mips3fe_exit(void) |
| 121 | { |
| 122 | /* free our free list of descriptions */ |
| 123 | while (desc_free_list != NULL) |
| 124 | { |
| 125 | mips3_opcode_desc *freeme = desc_free_list; |
| 126 | desc_free_list = desc_free_list->next; |
| 127 | free(freeme); |
| 128 | } |
| 129 | |
| 130 | /* free the description array */ |
| 131 | if (desc_array != NULL) |
| 132 | free(desc_array); |
| 133 | desc_array_size = 0; |
| 134 | } |
| 135 | |
| 136 | |
| 137 | /*------------------------------------------------- |
| 138 | mips3fe_describe_sequence - describe a |
| 139 | sequence of instructions that falls within |
| 140 | the given range |
| 141 | -------------------------------------------------*/ |
| 142 | |
| 143 | mips3_opcode_desc *mips3fe_describe_sequence(mips3_state *mips, UINT32 startpc, UINT32 minpc, UINT32 maxpc) |
| 144 | { |
| 145 | pc_stack_entry pcstack[MAX_STACK_DEPTH]; |
| 146 | pc_stack_entry *pcstackptr = &pcstack[0]; |
| 147 | mips3_opcode_desc *head, **tailptr; |
| 148 | int descnum, descend; |
| 149 | |
| 150 | /* make sure our array is big enough */ |
| 151 | if ((maxpc - minpc) / 4 + 10 > desc_array_size) |
| 152 | { |
| 153 | desc_array_size = (maxpc - minpc) / 4 + 10; |
| 154 | desc_array = realloc(desc_array, desc_array_size * sizeof(desc_array[0])); |
| 155 | memset(desc_array, 0, desc_array_size * sizeof(desc_array[0])); |
| 156 | } |
| 157 | |
| 158 | /* add the initial PC to the stack */ |
| 159 | pcstackptr->srcpc = 0; |
| 160 | pcstackptr->targetpc = startpc; |
| 161 | pcstackptr++; |
| 162 | |
| 163 | /* loop while we still have a stack */ |
| 164 | while (pcstackptr != &pcstack[0]) |
| 165 | { |
| 166 | pc_stack_entry *curstack = --pcstackptr; |
| 167 | mips3_opcode_desc *prevdesc = NULL; |
| 168 | mips3_opcode_desc *curdesc; |
| 169 | UINT32 curpc; |
| 170 | |
| 171 | /* if we've already hit this PC, just mark it a branch target and continue */ |
| 172 | curdesc = desc_array[(curstack->targetpc - minpc) / 4]; |
| 173 | if (curdesc != NULL) |
| 174 | { |
| 175 | curdesc->flags |= IDESC_IS_BRANCH_TARGET; |
| 176 | |
| 177 | /* if the branch crosses a page boundary, mark the target as needing to revalidate */ |
| 178 | if (!is_fixed_mapped(curdesc->pc) && ((curstack->srcpc ^ curdesc->pc) & ~0xfff) != 0) |
| 179 | curdesc->flags |= IDESC_VALIDATE_TLB | IDESC_CAN_CAUSE_EXCEPTION; |
| 180 | |
| 181 | /* continue processing */ |
| 182 | continue; |
| 183 | } |
| 184 | |
| 185 | /* loop until we exit the block */ |
| 186 | for (curpc = curstack->targetpc; curpc < maxpc && desc_array[(curpc - minpc) / 4] == NULL; curpc += 4) |
| 187 | { |
| 188 | /* describe one instruction */ |
| 189 | desc_array[(curpc - minpc) / 4] = curdesc = desc_alloc(); |
| 190 | if (!describe_one(mips, curpc, curdesc)) |
| 191 | break; |
| 192 | |
| 193 | /* first instruction in a block is always a branch target */ |
| 194 | if (curpc == curstack->targetpc) |
| 195 | curdesc->flags |= IDESC_IS_BRANCH_TARGET; |
| 196 | |
| 197 | /* first instruction in a block or page must always validate the TLB */ |
| 198 | if (!is_fixed_mapped(curpc) && (curpc == startpc || (curpc & 0xfff) == 0)) |
| 199 | curdesc->flags |= IDESC_VALIDATE_TLB | IDESC_CAN_CAUSE_EXCEPTION; |
| 200 | |
| 201 | /* if we are a branch, add the branch target to our stack */ |
| 202 | if ((curdesc->flags & IDESC_IS_BRANCH) && curdesc->targetpc >= minpc && curdesc->targetpc < maxpc && pcstackptr < &pcstack[MAX_STACK_DEPTH]) |
| 203 | { |
| 204 | curdesc->flags |= IDESC_INTRABLOCK_BRANCH; |
| 205 | pcstackptr->srcpc = curdesc->pc; |
| 206 | pcstackptr->targetpc = curdesc->targetpc; |
| 207 | pcstackptr++; |
| 208 | } |
| 209 | |
| 210 | /* we now become the previous desc */ |
| 211 | prevdesc = curdesc; |
| 212 | |
| 213 | /* if we're done, we're done */ |
| 214 | if (curdesc->flags & IDESC_END_SEQUENCE) |
| 215 | break; |
| 216 | |
| 217 | /* if this is a likely branch, advance an extra 4 */ |
| 218 | if (curdesc->flags & IDESC_IS_LIKELY_BRANCH) |
| 219 | curpc += 4; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | /* now build the list of descriptions in order */ |
| 224 | head = NULL; |
| 225 | tailptr = &head; |
| 226 | |
| 227 | /* first from startpc -> maxpc */ |
| 228 | descend = (maxpc - minpc) / 4; |
| 229 | for (descnum = (startpc - minpc) / 4; descnum < descend; descnum++) |
| 230 | if (desc_array[descnum] != NULL) |
| 231 | { |
| 232 | /* if this is a likely branch and we need the delay slot, mark it as end-of-sequence */ |
| 233 | if ((desc_array[descnum]->flags & IDESC_IS_LIKELY_BRANCH) && desc_array[descnum + 1] != NULL) |
| 234 | desc_array[descnum]->flags |= IDESC_END_SEQUENCE; |
| 235 | |
| 236 | /* if the next instruction is a branch target, mark this instruction as end of sequence */ |
| 237 | if (descnum != descend - 1 && desc_array[descnum + 1] != NULL && (desc_array[descnum + 1]->flags & IDESC_IS_BRANCH_TARGET)) |
| 238 | desc_array[descnum]->flags |= IDESC_END_SEQUENCE; |
| 239 | |
| 240 | /* if we are the last instruction, indicate end-of-sequence and redispatch */ |
| 241 | if (descnum == descend - 1 || (descnum == descend - 2 && (desc_array[descnum]->flags & IDESC_IS_LIKELY_BRANCH))) |
| 242 | desc_array[descnum]->flags |= IDESC_REDISPATCH | IDESC_END_SEQUENCE; |
| 243 | |
| 244 | /* add us to the end of the list */ |
| 245 | *tailptr = desc_array[descnum]; |
| 246 | tailptr = &desc_array[descnum]->next; |
| 247 | desc_array[descnum] = NULL; |
| 248 | } |
| 249 | |
| 250 | /* then from minpc -> startpc */ |
| 251 | descend = (startpc - minpc) / 4; |
| 252 | for (descnum = (minpc - minpc) / 4; descnum < descend; descnum++) |
| 253 | if (desc_array[descnum] != NULL) |
| 254 | { |
| 255 | /* if this is a likely branch and we need the delay slot, mark it as end-of-sequence */ |
| 256 | if ((desc_array[descnum]->flags & IDESC_IS_LIKELY_BRANCH) && desc_array[descnum + 1] != NULL) |
| 257 | desc_array[descnum]->flags |= IDESC_END_SEQUENCE; |
| 258 | |
| 259 | /* if the next instruction is a branch target, mark this instruction as end of sequence */ |
| 260 | if (descnum != descend - 1 && desc_array[descnum + 1] != NULL && (desc_array[descnum + 1]->flags & IDESC_IS_BRANCH_TARGET)) |
| 261 | desc_array[descnum]->flags |= IDESC_END_SEQUENCE; |
| 262 | |
| 263 | /* if we are the last instruction, indicate return-to-start and redispatch */ |
| 264 | if (descnum == descend - 1 || (descnum == descend - 2 && (desc_array[descnum]->flags & IDESC_IS_LIKELY_BRANCH))) |
| 265 | desc_array[descnum]->flags |= IDESC_RETURN_TO_START | IDESC_END_SEQUENCE; |
| 266 | |
| 267 | /* add us to the end of the list */ |
| 268 | *tailptr = desc_array[descnum]; |
| 269 | tailptr = &desc_array[descnum]->next; |
| 270 | desc_array[descnum] = NULL; |
| 271 | } |
| 272 | |
| 273 | return head; |
| 274 | } |
| 275 | |
| 276 | |
| 277 | /*------------------------------------------------- |
| 278 | mips3fe_release_descriptions - release a |
| 279 | list of descriptions |
| 280 | -------------------------------------------------*/ |
| 281 | |
| 282 | void mips3fe_release_descriptions(mips3_opcode_desc *desc) |
| 283 | { |
| 284 | while (desc != NULL) |
| 285 | { |
| 286 | mips3_opcode_desc *freeme = desc; |
| 287 | if (desc->delay != NULL) |
| 288 | mips3fe_release_descriptions(desc->delay); |
| 289 | desc = desc->next; |
| 290 | desc_free(freeme); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | |
| 295 | |
| 296 | /*************************************************************************** |
| 297 | INSTRUCTION PARSERS |
| 298 | ***************************************************************************/ |
| 299 | |
| 300 | /*------------------------------------------------- |
| 301 | describe_one - describe a single instruction |
| 302 | -------------------------------------------------*/ |
| 303 | |
| 304 | static int describe_one(mips3_state *mips, UINT32 curpc, mips3_opcode_desc *curdesc) |
| 305 | { |
| 306 | /* fill in default values */ |
| 307 | curdesc->next = NULL; |
| 308 | curdesc->delay = NULL; |
| 309 | curdesc->pc = curpc; |
| 310 | curdesc->targetpc = ~0; |
| 311 | curdesc->flags = 0; |
| 312 | curdesc->cycles = 1; |
| 313 | curdesc->intused = 0; |
| 314 | curdesc->intmod = 0; |
| 315 | curdesc->fpused = 0; |
| 316 | curdesc->fpmod = 0; |
| 317 | |
| 318 | /* determine the physical PC and pointer to opcode for this instruction */ |
| 319 | curdesc->physpc = curpc; |
| 320 | if (!mips3com_translate_address(mips, ADDRESS_SPACE_PROGRAM, &curdesc->physpc)) |
| 321 | { |
| 322 | /* if we're not mapped, generate an exception */ |
| 323 | curdesc->opptr = &dummy_nop; |
| 324 | curdesc->flags = IDESC_CAN_CAUSE_EXCEPTION | IDESC_END_SEQUENCE | IDESC_REDISPATCH; |
| 325 | return FALSE; |
| 326 | } |
| 327 | curdesc->opptr = memory_get_op_ptr(cpu_getactivecpu(), curdesc->physpc, FALSE); |
| 328 | assert(curdesc->opptr != NULL); |
| 329 | |
| 330 | /* describe this instruction */ |
| 331 | describe_instruction(mips, curpc, *curdesc->opptr, curdesc); |
| 332 | |
| 333 | /* if we are a branch, describe the delay slot as well */ |
| 334 | if (curdesc->flags & IDESC_IS_BRANCH) |
| 335 | { |
| 336 | curdesc->delay = desc_alloc(); |
| 337 | describe_one(mips, curpc + 4, curdesc->delay); |
| 338 | curdesc->delay->flags |= IDESC_IN_DELAY_SLOT; |
| 339 | curdesc->delay->branch = curdesc; |
| 340 | } |
| 341 | return TRUE; |
| 342 | } |
| 343 | |
| 344 | |
| 345 | /*------------------------------------------------- |
| 346 | describe_instruction - build a description |
| 347 | of a single instruction |
| 348 | -------------------------------------------------*/ |
| 349 | |
| 350 | static void describe_instruction(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc) |
| 351 | { |
| 352 | /* parse the instruction */ |
| 353 | switch (op >> 26) |
| 354 | { |
| 355 | case 0x00: /* SPECIAL */ |
| 356 | describe_instruction_special(mips, pc, op, desc); |
| 357 | break; |
| 358 | |
| 359 | case 0x01: /* REGIMM */ |
| 360 | describe_instruction_regimm(mips, pc, op, desc); |
| 361 | break; |
| 362 | |
| 363 | case 0x10: /* COP0 */ |
| 364 | describe_instruction_cop0(mips, pc, op, desc); |
| 365 | break; |
| 366 | |
| 367 | case 0x11: /* COP1 */ |
| 368 | describe_instruction_cop1(mips, pc, op, desc); |
| 369 | break; |
| 370 | |
| 371 | case 0x12: /* COP2 */ |
| 372 | describe_instruction_cop2(mips, pc, op, desc); |
| 373 | break; |
| 374 | |
| 375 | case 0x13: /* COP1X - MIPS IV */ |
| 376 | if (mips->flavor < MIPS3_TYPE_MIPS_IV) |
| 377 | { |
| 378 | invalid_opcode(desc); |
| 379 | break; |
| 380 | } |
| 381 | describe_instruction_cop1x(mips, pc, op, desc); |
| 382 | break; |
| 383 | |
| 384 | case 0x1c: /* IDT-specific opcodes: mad/madu/mul on R4640/4650, msub on RC32364 */ |
| 385 | describe_instruction_idt(mips, pc, op, desc); |
| 386 | break; |
| 387 | |
| 388 | case 0x02: /* J */ |
| 389 | desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE; |
| 390 | desc->targetpc = (pc & 0xf0000000) | (LIMMVAL << 2); |
| 391 | break; |
| 392 | |
| 393 | case 0x03: /* JAL */ |
| 394 | desc->intmod |= REGFLAG_R(31); |
| 395 | desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE; |
| 396 | desc->targetpc = (pc & 0xf0000000) | (LIMMVAL << 2); |
| 397 | break; |
| 398 | |
| 399 | case 0x14: /* BEQL */ |
| 400 | case 0x15: /* BNEL */ |
| 401 | desc->flags |= IDESC_IS_LIKELY_BRANCH; |
| 402 | /* fall through */ |
| 403 | |
| 404 | case 0x04: /* BEQ */ |
| 405 | case 0x05: /* BNE */ |
| 406 | if (((op >> 26) == 0x04 || (op >> 26) == 0x14) && RSREG == RTREG) |
| 407 | desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE; |
| 408 | else |
| 409 | { |
| 410 | desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG); |
| 411 | desc->flags |= IDESC_IS_CONDITIONAL_BRANCH; |
| 412 | } |
| 413 | desc->targetpc = pc + 4 + (SIMMVAL << 2); |
| 414 | break; |
| 415 | |
| 416 | case 0x16: /* BLEZL */ |
| 417 | case 0x17: /* BGTZL */ |
| 418 | desc->flags |= IDESC_IS_LIKELY_BRANCH; |
| 419 | /* fall through */ |
| 420 | |
| 421 | case 0x06: /* BLEZ */ |
| 422 | case 0x07: /* BGTZ */ |
| 423 | if (((op >> 26) == 0x06 || (op >> 26) == 0x16) && RSREG == 0) |
| 424 | desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE; |
| 425 | else |
| 426 | { |
| 427 | desc->intused |= REGFLAG_R(RSREG); |
| 428 | desc->flags |= IDESC_IS_CONDITIONAL_BRANCH; |
| 429 | } |
| 430 | desc->targetpc = pc + 4 + (SIMMVAL << 2); |
| 431 | break; |
| 432 | |
| 433 | case 0x08: /* ADDI */ |
| 434 | case 0x18: /* DADDI */ |
| 435 | desc->intused |= REGFLAG_R(RSREG); |
| 436 | desc->intmod |= REGFLAG_R(RTREG); |
| 437 | desc->flags |= IDESC_CAN_CAUSE_EXCEPTION; |
| 438 | break; |
| 439 | |
| 440 | case 0x09: /* ADDIU */ |
| 441 | case 0x0a: /* SLTI */ |
| 442 | case 0x0b: /* SLTIU */ |
| 443 | case 0x0c: /* ANDI */ |
| 444 | case 0x0d: /* ORI */ |
| 445 | case 0x0e: /* XORI */ |
| 446 | case 0x19: /* DADDIU */ |
| 447 | desc->intused |= REGFLAG_R(RSREG); |
| 448 | desc->intmod |= REGFLAG_R(RTREG); |
| 449 | break; |
| 450 | |
| 451 | case 0x0f: /* LUI */ |
| 452 | desc->intmod |= REGFLAG_R(RTREG); |
| 453 | break; |
| 454 | |
| 455 | case 0x1a: /* LDL */ |
| 456 | case 0x1b: /* LDR */ |
| 457 | case 0x20: /* LB */ |
| 458 | case 0x21: /* LH */ |
| 459 | case 0x22: /* LWL */ |
| 460 | case 0x23: /* LW */ |
| 461 | case 0x24: /* LBU */ |
| 462 | case 0x25: /* LHU */ |
| 463 | case 0x26: /* LWR */ |
| 464 | case 0x27: /* LWU */ |
| 465 | case 0x30: /* LL */ |
| 466 | case 0x34: /* LLD */ |
| 467 | case 0x37: /* LD */ |
| 468 | desc->intused |= REGFLAG_R(RSREG); |
| 469 | desc->intmod |= REGFLAG_R(RTREG); |
| 470 | desc->flags |= IDESC_READS_MEMORY | IDESC_CAN_CAUSE_EXCEPTION; |
| 471 | break; |
| 472 | |
| 473 | case 0x28: /* SB */ |
| 474 | case 0x29: /* SH */ |
| 475 | case 0x2a: /* SWL */ |
| 476 | case 0x2b: /* SW */ |
| 477 | case 0x2c: /* SDL */ |
| 478 | case 0x2d: /* SDR */ |
| 479 | case 0x2e: /* SWR */ |
| 480 | case 0x38: /* SC */ |
| 481 | case 0x3c: /* SCD */ |
| 482 | case 0x3f: /* SD */ |
| 483 | desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG); |
| 484 | desc->flags |= IDESC_WRITES_MEMORY | IDESC_CAN_CAUSE_EXCEPTION; |
| 485 | break; |
| 486 | |
| 487 | case 0x31: /* LWC1 */ |
| 488 | case 0x35: /* LDC1 */ |
| 489 | desc->intused |= REGFLAG_R(RSREG); |
| 490 | desc->fpmod |= REGFLAG_CPR1(RTREG); |
| 491 | desc->flags |= IDESC_READS_MEMORY | IDESC_CAN_CAUSE_EXCEPTION; |
| 492 | break; |
| 493 | |
| 494 | case 0x39: /* SWC1 */ |
| 495 | case 0x3d: /* SDC1 */ |
| 496 | desc->intused |= REGFLAG_R(RSREG); |
| 497 | desc->fpused |= REGFLAG_CPR1(RTREG); |
| 498 | desc->flags |= IDESC_WRITES_MEMORY | IDESC_CAN_CAUSE_EXCEPTION; |
| 499 | break; |
| 500 | |
| 501 | case 0x32: /* LWC2 */ |
| 502 | case 0x36: /* LDC2 */ |
| 503 | desc->intused |= REGFLAG_R(RSREG); |
| 504 | desc->flags |= IDESC_READS_MEMORY | IDESC_CAN_CAUSE_EXCEPTION; |
| 505 | break; |
| 506 | |
| 507 | case 0x3a: /* SWC2 */ |
| 508 | case 0x3e: /* SDC2 */ |
| 509 | desc->intused |= REGFLAG_R(RSREG); |
| 510 | desc->flags |= IDESC_WRITES_MEMORY | IDESC_CAN_CAUSE_EXCEPTION; |
| 511 | break; |
| 512 | |
| 513 | case 0x2f: /* CACHE */ |
| 514 | /* effective no-op */ |
| 515 | break; |
| 516 | |
| 517 | case 0x33: /* PREF */ |
| 518 | if (mips->flavor < MIPS3_TYPE_MIPS_IV) |
| 519 | invalid_opcode(desc); |
| 520 | else |
| 521 | ; /* effective no-op */ |
| 522 | break; |
| 523 | |
| 524 | default: /* anything else */ |
| 525 | invalid_opcode(desc); |
| 526 | break; |
| 527 | } |
| 528 | |
| 529 | /* remove any modifications of R0 */ |
| 530 | desc->intmod &= ~REGFLAG_R(0); |
| 531 | } |
| 532 | |
| 533 | |
| 534 | /*------------------------------------------------- |
| 535 | describe_instruction_special - build a |
| 536 | description of a single instruction in the |
| 537 | 'special' group |
| 538 | -------------------------------------------------*/ |
| 539 | |
| 540 | static void describe_instruction_special(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc) |
| 541 | { |
| 542 | switch (op & 63) |
| 543 | { |
| 544 | case 0x00: /* SLL */ |
| 545 | case 0x02: /* SRL */ |
| 546 | case 0x03: /* SRA */ |
| 547 | case 0x38: /* DSLL */ |
| 548 | case 0x3a: /* DSRL */ |
| 549 | case 0x3b: /* DSRA */ |
| 550 | case 0x3c: /* DSLL32 */ |
| 551 | case 0x3e: /* DSRL32 */ |
| 552 | case 0x3f: /* DSRA32 */ |
| 553 | desc->intused |= REGFLAG_R(RTREG); |
| 554 | desc->intmod |= REGFLAG_R(RDREG); |
| 555 | break; |
| 556 | |
| 557 | case 0x0a: /* MOVZ - MIPS IV */ |
| 558 | case 0x0b: /* MOVN - MIPS IV */ |
| 559 | if (mips->flavor < MIPS3_TYPE_MIPS_IV) |
| 560 | { |
| 561 | invalid_opcode(desc); |
| 562 | break; |
| 563 | } |
| 564 | case 0x04: /* SLLV */ |
| 565 | case 0x06: /* SRLV */ |
| 566 | case 0x07: /* SRAV */ |
| 567 | case 0x14: /* DSLLV */ |
| 568 | case 0x16: /* DSRLV */ |
| 569 | case 0x17: /* DSRAV */ |
| 570 | case 0x21: /* ADDU */ |
| 571 | case 0x23: /* SUBU */ |
| 572 | case 0x24: /* AND */ |
| 573 | case 0x25: /* OR */ |
| 574 | case 0x26: /* XOR */ |
| 575 | case 0x27: /* NOR */ |
| 576 | case 0x2a: /* SLT */ |
| 577 | case 0x2b: /* SLTU */ |
| 578 | case 0x2d: /* DADDU */ |
| 579 | case 0x2f: /* DSUBU */ |
| 580 | desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG); |
| 581 | desc->intmod |= REGFLAG_R(RDREG); |
| 582 | break; |
| 583 | |
| 584 | case 0x20: /* ADD */ |
| 585 | case 0x22: /* SUB */ |
| 586 | case 0x2c: /* DADD */ |
| 587 | case 0x2e: /* DSUB */ |
| 588 | desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG); |
| 589 | desc->intmod |= REGFLAG_R(RDREG); |
| 590 | desc->flags |= IDESC_CAN_CAUSE_EXCEPTION; |
| 591 | break; |
| 592 | |
| 593 | case 0x30: /* TGE */ |
| 594 | case 0x31: /* TGEU */ |
| 595 | case 0x32: /* TLT */ |
| 596 | case 0x33: /* TLTU */ |
| 597 | case 0x34: /* TEQ */ |
| 598 | case 0x36: /* TNE */ |
| 599 | desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG); |
| 600 | desc->flags |= IDESC_CAN_CAUSE_EXCEPTION; |
| 601 | break; |
| 602 | |
| 603 | case 0x01: /* MOVF - MIPS IV */ |
| 604 | if (mips->flavor < MIPS3_TYPE_MIPS_IV) |
| 605 | { |
| 606 | invalid_opcode(desc); |
| 607 | break; |
| 608 | } |
| 609 | desc->intused |= REGFLAG_R(RSREG); |
| 610 | desc->fpused |= REGFLAG_FCC; |
| 611 | desc->intmod |= REGFLAG_R(RDREG); |
| 612 | break; |
| 613 | |
| 614 | case 0x08: /* JR */ |
| 615 | desc->intused |= REGFLAG_R(RSREG); |
| 616 | desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE; |
| 617 | break; |
| 618 | |
| 619 | case 0x09: /* JALR */ |
| 620 | desc->intused |= REGFLAG_R(RSREG); |
| 621 | desc->intmod |= REGFLAG_R(RDREG); |
| 622 | desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE; |
| 623 | break; |
| 624 | |
| 625 | case 0x10: /* MFHI */ |
| 626 | desc->intused |= REGFLAG_HI; |
| 627 | desc->intmod |= REGFLAG_R(RDREG); |
| 628 | break; |
| 629 | |
| 630 | case 0x11: /* MTHI */ |
| 631 | desc->intused |= REGFLAG_R(RSREG); |
| 632 | desc->intmod |= REGFLAG_HI; |
| 633 | break; |
| 634 | |
| 635 | case 0x12: /* MFLO */ |
| 636 | desc->intused |= REGFLAG_LO; |
| 637 | desc->intmod |= REGFLAG_R(RDREG); |
| 638 | break; |
| 639 | |
| 640 | case 0x13: /* MTLO */ |
| 641 | desc->intused |= REGFLAG_R(RSREG); |
| 642 | desc->intmod |= REGFLAG_LO; |
| 643 | break; |
| 644 | |
| 645 | case 0x18: /* MULT */ |
| 646 | case 0x19: /* MULTU */ |
| 647 | desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG); |
| 648 | desc->intmod |= REGFLAG_LO | REGFLAG_HI; |
| 649 | desc->cycles = 3; |
| 650 | break; |
| 651 | |
| 652 | case 0x1a: /* DIV */ |
| 653 | case 0x1b: /* DIVU */ |
| 654 | desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG); |
| 655 | desc->intmod |= REGFLAG_LO | REGFLAG_HI; |
| 656 | desc->cycles = 35; |
| 657 | break; |
| 658 | |
| 659 | case 0x1c: /* DMULT */ |
| 660 | case 0x1d: /* DMULTU */ |
| 661 | desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG); |
| 662 | desc->intmod |= REGFLAG_LO | REGFLAG_HI; |
| 663 | desc->cycles = 7; |
| 664 | break; |
| 665 | |
| 666 | case 0x1e: /* DDIV */ |
| 667 | case 0x1f: /* DDIVU */ |
| 668 | desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG); |
| 669 | desc->intmod |= REGFLAG_LO | REGFLAG_HI; |
| 670 | desc->cycles = 67; |
| 671 | break; |
| 672 | |
| 673 | case 0x0c: /* SYSCALL */ |
| 674 | case 0x0d: /* BREAK */ |
| 675 | desc->flags |= IDESC_WILL_CAUSE_EXCEPTION | IDESC_END_SEQUENCE; |
| 676 | break; |
| 677 | |
| 678 | case 0x0f: /* SYNC */ |
| 679 | /* effective no-op */ |
| 680 | break; |
| 681 | |
| 682 | default: /* anything else */ |
| 683 | invalid_opcode(desc); |
| 684 | break; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | |
| 689 | /*------------------------------------------------- |
| 690 | describe_instruction_regimm - build a |
| 691 | description of a single instruction in the |
| 692 | 'regimm' group |
| 693 | -------------------------------------------------*/ |
| 694 | |
| 695 | static void describe_instruction_regimm(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc) |
| 696 | { |
| 697 | switch (RTREG) |
| 698 | { |
| 699 | case 0x02: /* BLTZL */ |
| 700 | case 0x03: /* BGEZL */ |
| 701 | desc->flags |= IDESC_IS_LIKELY_BRANCH; |
| 702 | /* fall through */ |
| 703 | |
| 704 | case 0x00: /* BLTZ */ |
| 705 | case 0x01: /* BGEZ */ |
| 706 | if (RTREG == 0x01 && RSREG == 0) |
| 707 | desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE; |
| 708 | else |
| 709 | { |
| 710 | desc->intused |= REGFLAG_R(RSREG); |
| 711 | desc->flags |= IDESC_IS_CONDITIONAL_BRANCH; |
| 712 | } |
| 713 | desc->targetpc = pc + 4 + (SIMMVAL << 2); |
| 714 | break; |
| 715 | |
| 716 | case 0x08: /* TGEI */ |
| 717 | case 0x09: /* TGEIU */ |
| 718 | case 0x0a: /* TLTI */ |
| 719 | case 0x0b: /* TLTIU */ |
| 720 | case 0x0c: /* TEQI */ |
| 721 | case 0x0e: /* TNEI */ |
| 722 | desc->intused |= REGFLAG_R(RSREG); |
| 723 | desc->flags |= IDESC_CAN_CAUSE_EXCEPTION; |
| 724 | break; |
| 725 | |
| 726 | case 0x12: /* BLTZALL */ |
| 727 | case 0x13: /* BGEZALL */ |
| 728 | desc->flags |= IDESC_IS_LIKELY_BRANCH; |
| 729 | /* fall through */ |
| 730 | |
| 731 | case 0x10: /* BLTZAL */ |
| 732 | case 0x11: /* BGEZAL */ |
| 733 | if (RTREG == 0x11 && RSREG == 0) |
| 734 | desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE; |
| 735 | else |
| 736 | { |
| 737 | desc->intused |= REGFLAG_R(RSREG); |
| 738 | desc->flags |= IDESC_IS_CONDITIONAL_BRANCH; |
| 739 | } |
| 740 | desc->intmod |= REGFLAG_R(31); |
| 741 | desc->targetpc = pc + 4 + (SIMMVAL << 2); |
| 742 | break; |
| 743 | |
| 744 | default: /* anything else */ |
| 745 | invalid_opcode(desc); |
| 746 | break; |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | |
| 751 | /*------------------------------------------------- |
| 752 | describe_instruction_idt - build a |
| 753 | description of a single instruction in the |
| 754 | IDT-specific group |
| 755 | -------------------------------------------------*/ |
| 756 | |
| 757 | static void describe_instruction_idt(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc) |
| 758 | { |
| 759 | switch (op & 0x1f) |
| 760 | { |
| 761 | case 2: /* MUL */ |
| 762 | desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG); |
| 763 | desc->intmod |= REGFLAG_R(RDREG); |
| 764 | desc->cycles = 3; |
| 765 | break; |
| 766 | |
| 767 | default: /* anything else */ |
| 768 | invalid_opcode(desc); |
| 769 | break; |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | |
| 774 | /*------------------------------------------------- |
| 775 | describe_instruction_cop0 - build a |
| 776 | description of a single instruction in the |
| 777 | COP0 group |
| 778 | -------------------------------------------------*/ |
| 779 | |
| 780 | static void describe_instruction_cop0(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc) |
| 781 | { |
| 782 | /* any COP0 instruction can potentially cause an exception */ |
| 783 | desc->flags |= IDESC_CAN_CAUSE_EXCEPTION; |
| 784 | |
| 785 | switch (RSREG) |
| 786 | { |
| 787 | case 0x00: /* MFCz */ |
| 788 | case 0x01: /* DMFCz */ |
| 789 | case 0x02: /* CFCz */ |
| 790 | desc->intmod |= REGFLAG_R(RTREG); |
| 791 | break; |
| 792 | |
| 793 | case 0x04: /* MTCz */ |
| 794 | case 0x05: /* DMTCz */ |
| 795 | case 0x06: /* CTCz */ |
| 796 | desc->intused |= REGFLAG_R(RTREG); |
| 797 | if (RSREG == 0x04 || RSREG == 0x05) |
| 798 | { |
| 799 | if (RDREG == COP0_Cause) |
| 800 | desc->flags |= IDESC_CAN_TRIGGER_SW_INT; |
| 801 | if (RDREG == COP0_Status) |
| 802 | desc->flags |= IDESC_CAN_EXPOSE_EXTERNAL_INT; |
| 803 | } |
| 804 | break; |
| 805 | |
| 806 | case 0x08: /* BC */ |
| 807 | switch (RTREG) |
| 808 | { |
| 809 | case 0x00: /* BCzF */ |
| 810 | case 0x01: /* BCzT */ |
| 811 | desc->flags |= IDESC_IS_CONDITIONAL_BRANCH; |
| 812 | desc->targetpc = pc + 4 + (SIMMVAL << 2); |
| 813 | break; |
| 814 | |
| 815 | default: /* anything else */ |
| 816 | invalid_opcode(desc); |
| 817 | break; |
| 818 | } |
| 819 | break; |
| 820 | |
| 821 | case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: |
| 822 | case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f: /* COP */ |
| 823 | switch (op & 0x01ffffff) |
| 824 | { |
| 825 | case 0x01: /* TLBR */ |
| 826 | case 0x08: /* TLBP */ |
| 827 | break; |
| 828 | |
| 829 | case 0x02: /* TLBWI */ |
| 830 | case 0x06: /* TLBWR */ |
| 831 | desc->flags |= IDESC_MODIFIES_TRANSLATION; |
| 832 | break; |
| 833 | |
| 834 | case 0x18: /* ERET */ |
| 835 | desc->flags |= IDESC_IS_UNCONDITIONAL_BRANCH | IDESC_END_SEQUENCE; |
| 836 | break; |
| 837 | |
| 838 | default: /* anything else */ |
| 839 | invalid_opcode(desc); |
| 840 | break; |
| 841 | } |
| 842 | break; |
| 843 | |
| 844 | default: /* anything else */ |
| 845 | invalid_opcode(desc); |
| 846 | break; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | |
| 851 | /*------------------------------------------------- |
| 852 | describe_instruction_cop1 - build a |
| 853 | description of a single instruction in the |
| 854 | COP1 group |
| 855 | -------------------------------------------------*/ |
| 856 | |
| 857 | static void describe_instruction_cop1(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc) |
| 858 | { |
| 859 | /* any COP1 instruction can potentially cause an exception */ |
| 860 | // desc->flags |= IDESC_CAN_CAUSE_EXCEPTION; |
| 861 | |
| 862 | switch (RSREG) |
| 863 | { |
| 864 | case 0x00: /* MFCz */ |
| 865 | case 0x01: /* DMFCz */ |
| 866 | desc->fpused |= REGFLAG_CPR1(RDREG); |
| 867 | desc->intmod |= REGFLAG_R(RTREG); |
| 868 | break; |
| 869 | |
| 870 | case 0x02: /* CFCz */ |
| 871 | desc->intmod |= REGFLAG_R(RTREG); |
| 872 | break; |
| 873 | |
| 874 | case 0x04: /* MTCz */ |
| 875 | case 0x05: /* DMTCz */ |
| 876 | desc->intused |= REGFLAG_R(RTREG); |
| 877 | desc->fpmod |= REGFLAG_CPR1(RDREG); |
| 878 | break; |
| 879 | |
| 880 | case 0x06: /* CTCz */ |
| 881 | desc->intused |= REGFLAG_R(RTREG); |
| 882 | break; |
| 883 | |
| 884 | case 0x08: /* BC */ |
| 885 | switch (RTREG) |
| 886 | { |
| 887 | case 0x02: /* BCzFL */ |
| 888 | case 0x03: /* BCzTL */ |
| 889 | desc->flags |= IDESC_IS_LIKELY_BRANCH; |
| 890 | /* fall through */ |
| 891 | |
| 892 | case 0x00: /* BCzF */ |
| 893 | case 0x01: /* BCzT */ |
| 894 | desc->fpused |= REGFLAG_FCC; |
| 895 | desc->flags |= IDESC_IS_CONDITIONAL_BRANCH; |
| 896 | desc->targetpc = pc + 4 + (SIMMVAL << 2); |
| 897 | break; |
| 898 | |
| 899 | default: /* anything else */ |
| 900 | invalid_opcode(desc); |
| 901 | break; |
| 902 | } |
| 903 | break; |
| 904 | |
| 905 | case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: |
| 906 | case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f: /* COP */ |
| 907 | switch (op & 0x3f) |
| 908 | { |
| 909 | case 0x12: /* MOVZ - MIPS IV */ |
| 910 | case 0x13: /* MOVN - MIPS IV */ |
| 911 | if (mips->flavor < MIPS3_TYPE_MIPS_IV) |
| 912 | { |
| 913 | invalid_opcode(desc); |
| 914 | break; |
| 915 | } |
| 916 | case 0x00: /* ADD */ |
| 917 | case 0x01: /* SUB */ |
| 918 | case 0x02: /* MUL */ |
| 919 | case 0x03: /* DIV */ |
| 920 | desc->fpused |= REGFLAG_CPR1(FSREG) | REGFLAG_CPR1(FTREG); |
| 921 | desc->fpmod |= REGFLAG_CPR1(FDREG); |
| 922 | break; |
| 923 | |
| 924 | case 0x15: /* RECIP - MIPS IV */ |
| 925 | case 0x16: /* RSQRT - MIPS IV */ |
| 926 | if (mips->flavor < MIPS3_TYPE_MIPS_IV) |
| 927 | { |
| 928 | invalid_opcode(desc); |
| 929 | break; |
| 930 | } |
| 931 | case 0x04: /* SQRT */ |
| 932 | case 0x05: /* ABS */ |
| 933 | case 0x06: /* MOV */ |
| 934 | case 0x07: /* NEG */ |
| 935 | case 0x08: /* ROUND.L */ |
| 936 | case 0x09: /* TRUNC.L */ |
| 937 | case 0x0a: /* CEIL.L */ |
| 938 | case 0x0b: /* FLOOR.L */ |
| 939 | case 0x0c: /* ROUND.W */ |
| 940 | case 0x0d: /* TRUNC.W */ |
| 941 | case 0x0e: /* CEIL.W */ |
| 942 | case 0x0f: /* FLOOR.W */ |
| 943 | case 0x20: /* CVT.S */ |
| 944 | case 0x21: /* CVT.D */ |
| 945 | case 0x24: /* CVT.W */ |
| 946 | case 0x25: /* CVT.L */ |
| 947 | desc->fpused |= REGFLAG_CPR1(FSREG); |
| 948 | desc->fpmod |= REGFLAG_CPR1(FDREG); |
| 949 | break; |
| 950 | |
| 951 | case 0x11: /* MOVT/F - MIPS IV */ |
| 952 | if (mips->flavor < MIPS3_TYPE_MIPS_IV) |
| 953 | { |
| 954 | invalid_opcode(desc); |
| 955 | break; |
| 956 | } |
| 957 | desc->fpused |= REGFLAG_CPR1(FSREG) | REGFLAG_FCC; |
| 958 | desc->fpmod |= REGFLAG_CPR1(FDREG); |
| 959 | break; |
| 960 | |
| 961 | case 0x30: case 0x38: /* C.F */ |
| 962 | case 0x31: case 0x39: /* C.UN */ |
| 963 | desc->fpmod |= REGFLAG_FCC; |
| 964 | break; |
| 965 | |
| 966 | case 0x32: case 0x3a: /* C.EQ */ |
| 967 | case 0x33: case 0x3b: /* C.UEQ */ |
| 968 | case 0x34: case 0x3c: /* C.OLT */ |
| 969 | case 0x35: case 0x3d: /* C.ULT */ |
| 970 | case 0x36: case 0x3e: /* C.OLE */ |
| 971 | case 0x37: case 0x3f: /* C.ULE */ |
| 972 | desc->fpused |= REGFLAG_CPR1(FSREG) | REGFLAG_CPR1(FTREG); |
| 973 | desc->fpmod |= REGFLAG_FCC; |
| 974 | break; |
| 975 | |
| 976 | default: /* anything else */ |
| 977 | invalid_opcode(desc); |
| 978 | break; |
| 979 | } |
| 980 | break; |
| 981 | |
| 982 | default: /* anything else */ |
| 983 | invalid_opcode(desc); |
| 984 | break; |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | |
| 989 | /*------------------------------------------------- |
| 990 | describe_instruction_cop1x - build a |
| 991 | description of a single instruction in the |
| 992 | COP1X group |
| 993 | -------------------------------------------------*/ |
| 994 | |
| 995 | static void describe_instruction_cop1x(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc) |
| 996 | { |
| 997 | /* any COP1 instruction can potentially cause an exception */ |
| 998 | // desc->flags |= IDESC_CAN_CAUSE_EXCEPTION; |
| 999 | |
| 1000 | switch (op & 0x3f) |
| 1001 | { |
| 1002 | case 0x00: /* LWXC1 */ |
| 1003 | case 0x01: /* LDXC1 */ |
| 1004 | desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG); |
| 1005 | desc->fpmod |= REGFLAG_CPR1(FDREG); |
| 1006 | desc->flags |= IDESC_READS_MEMORY; |
| 1007 | break; |
| 1008 | |
| 1009 | case 0x02: /* SWXC1 */ |
| 1010 | case 0x03: /* SDXC1 */ |
| 1011 | desc->intused |= REGFLAG_R(RSREG) | REGFLAG_R(RTREG); |
| 1012 | desc->fpused |= REGFLAG_CPR1(FDREG); |
| 1013 | desc->flags |= IDESC_WRITES_MEMORY; |
| 1014 | break; |
| 1015 | |
| 1016 | case 0x0f: /* PREFX */ |
| 1017 | /* effective no-op */ |
| 1018 | break; |
| 1019 | |
| 1020 | case 0x20: case 0x21: /* MADD */ |
| 1021 | case 0x28: case 0x29: /* MSUB */ |
| 1022 | case 0x30: case 0x31: /* NMADD */ |
| 1023 | case 0x32: case 0x39: /* NMSUB */ |
| 1024 | desc->fpused |= REGFLAG_CPR1(FSREG) | REGFLAG_CPR1(FTREG) | REGFLAG_CPR1(FRREG); |
| 1025 | desc->fpmod |= REGFLAG_CPR1(FDREG); |
| 1026 | break; |
| 1027 | |
| 1028 | default: /* anything else */ |
| 1029 | invalid_opcode(desc); |
| 1030 | break; |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | |
| 1035 | /*------------------------------------------------- |
| 1036 | describe_instruction_cop2 - build a |
| 1037 | description of a single instruction in the |
| 1038 | COP2 group |
| 1039 | -------------------------------------------------*/ |
| 1040 | |
| 1041 | static void describe_instruction_cop2(mips3_state *mips, UINT32 pc, UINT32 op, mips3_opcode_desc *desc) |
| 1042 | { |
| 1043 | /* any COP2 instruction can potentially cause an exception */ |
| 1044 | desc->flags |= IDESC_CAN_CAUSE_EXCEPTION; |
| 1045 | |
| 1046 | switch (RSREG) |
| 1047 | { |
| 1048 | case 0x00: /* MFCz */ |
| 1049 | case 0x01: /* DMFCz */ |
| 1050 | case 0x02: /* CFCz */ |
| 1051 | desc->intmod |= REGFLAG_R(RTREG); |
| 1052 | break; |
| 1053 | |
| 1054 | case 0x04: /* MTCz */ |
| 1055 | case 0x05: /* DMTCz */ |
| 1056 | case 0x06: /* CTCz */ |
| 1057 | desc->intused |= REGFLAG_R(RTREG); |
| 1058 | break; |
| 1059 | |
| 1060 | case 0x08: /* BC */ |
| 1061 | switch (RTREG) |
| 1062 | { |
| 1063 | case 0x00: /* BCzF */ |
| 1064 | case 0x01: /* BCzT */ |
| 1065 | desc->flags |= IDESC_IS_CONDITIONAL_BRANCH; |
| 1066 | desc->targetpc = pc + 4 + (SIMMVAL << 2); |
| 1067 | break; |
| 1068 | |
| 1069 | default: /* anything else */ |
| 1070 | invalid_opcode(desc); |
| 1071 | break; |
| 1072 | } |
| 1073 | break; |
| 1074 | |
| 1075 | default: /* anything else */ |
| 1076 | invalid_opcode(desc); |
| 1077 | break; |
| 1078 | } |
| 1079 | } |
src/emu/cpu/mips/mips3drc.c
| r1036 | r1037 | |
| 29 | 29 | DEBUGGING |
| 30 | 30 | ***************************************************************************/ |
| 31 | 31 | |
| 32 | | #define LOG_CODE (0) |
| 32 | #define LOG_CODE (0) |
| 33 | 33 | |
| 34 | #ifdef MAME_DEBUG |
| 35 | #define COMPARE_AGAINST_C (0) |
| 36 | #else |
| 37 | #define COMPARE_AGAINST_C (0) |
| 38 | #endif |
| 34 | 39 | |
| 35 | 40 | |
| 41 | |
| 36 | 42 | /*************************************************************************** |
| 37 | 43 | CONFIGURATION |
| 38 | 44 | ***************************************************************************/ |
| 39 | 45 | |
| 40 | | #define MAX_INSTRUCTIONS 512 |
| 41 | | #define CACHE_SIZE (32 * 1024 * 1024) |
| 46 | #define MAX_INSTRUCTIONS 512 |
| 47 | #define CACHE_SIZE (32 * 1024 * 1024) |
| 42 | 48 | |
| 43 | 49 | |
| 44 | 50 | |
| r1036 | r1037 | |
| 46 | 52 | MACROS |
| 47 | 53 | ***************************************************************************/ |
| 48 | 54 | |
| 49 | | #define SR mips3.core->cpr[0][COP0_Status] |
| 50 | | #define IS_FR0 (!(SR & SR_FR)) |
| 51 | | #define IS_FR1 (SR & SR_FR) |
| 55 | #define SR mips3.core->cpr[0][COP0_Status] |
| 56 | #define IS_FR0 (!(SR & SR_FR)) |
| 57 | #define IS_FR1 (SR & SR_FR) |
| 52 | 58 | |
| 53 | 59 | |
| 54 | 60 | |
| r1036 | r1037 | |
| 62 | 68 | { |
| 63 | 69 | UINT32 pc; |
| 64 | 70 | UINT32 op; |
| 65 | | void * base; |
| 71 | x86code * base; |
| 72 | const char *string; |
| 66 | 73 | }; |
| 67 | 74 | |
| 68 | 75 | |
| r1036 | r1037 | |
| 113 | 120 | /* hotspots */ |
| 114 | 121 | UINT32 hotspot_select; |
| 115 | 122 | hotspot_info hotspot[MIPS3_MAX_HOTSPOTS]; |
| 123 | |
| 124 | #if COMPARE_AGAINST_C |
| 125 | /* memory state */ |
| 126 | UINT8 access_size; |
| 127 | UINT8 access_type; |
| 128 | offs_t access_addr; |
| 129 | UINT64 access_data; |
| 130 | UINT64 access_mask; |
| 131 | memory_handlers orighandler; |
| 132 | #endif |
| 116 | 133 | }; |
| 117 | 134 | |
| 118 | 135 | |
| r1036 | r1037 | |
| 124 | 141 | static void mips3drc_init(void); |
| 125 | 142 | static void mips3drc_exit(void); |
| 126 | 143 | |
| 144 | #if COMPARE_AGAINST_C |
| 145 | static void execute_c_version(void); |
| 146 | static void compare_c_version(void); |
| 147 | static void mips3c_init(mips3_flavor flavor, int bigendian, int index, int clock, const struct mips3_config *config, int (*irqcallback)(int)); |
| 148 | static void mips3c_reset(void); |
| 149 | #endif |
| 127 | 150 | |
| 128 | 151 | |
| 152 | |
| 129 | 153 | /*************************************************************************** |
| 130 | 154 | PRIVATE GLOBAL VARIABLES |
| 131 | 155 | ***************************************************************************/ |
| r1036 | r1037 | |
| 142 | 166 | mips3_init - initialize the processor |
| 143 | 167 | -------------------------------------------------*/ |
| 144 | 168 | |
| 145 | | void mips3_init(mips3_state *mips, mips3_flavor flavor, int bigendian, int index, int clock, const struct mips3_config *config, int (*irqcallback)(int)) |
| 169 | static void mips3_init(mips3_state *mips, mips3_flavor flavor, int bigendian, int index, int clock, const struct mips3_config *config, int (*irqcallback)(int)) |
| 146 | 170 | { |
| 147 | 171 | /* allocate a cache and memory for the core data in a single block */ |
| 148 | 172 | mips3.core = osd_alloc_executable(CACHE_SIZE + sizeof(*mips3.core)); |
| r1036 | r1037 | |
| 152 | 176 | |
| 153 | 177 | /* initialize the core */ |
| 154 | 178 | mips3com_init(mips3.core, flavor, bigendian, index, clock, config, irqcallback); |
| 179 | #if COMPARE_AGAINST_C |
| 180 | mips3c_init(flavor, bigendian, index, clock, config, irqcallback); |
| 181 | #endif |
| 155 | 182 | |
| 156 | 183 | /* initialize the DRC to use the cache */ |
| 157 | 184 | mips3drc_init(); |
| r1036 | r1037 | |
| 167 | 194 | /* reset the common code and flush the cache */ |
| 168 | 195 | mips3com_reset(mips3.core); |
| 169 | 196 | drc_cache_reset(mips3.drc); |
| 197 | |
| 198 | #if COMPARE_AGAINST_C |
| 199 | mips3c_reset(); |
| 200 | #endif |
| 170 | 201 | } |
| 171 | 202 | |
| 172 | 203 | |
| r1036 | r1037 | |
| 198 | 229 | |
| 199 | 230 | static void mips3_exit(void) |
| 200 | 231 | { |
| 232 | /* clean up the DRC */ |
| 201 | 233 | mips3drc_exit(); |
| 202 | | |
| 203 | | /* clean up the DRC */ |
| 204 | 234 | drc_exit(mips3.drc); |
| 205 | 235 | |
| 206 | 236 | /* free the cache */ |
| r1036 | r1037 | |
| 256 | 286 | |
| 257 | 287 | |
| 258 | 288 | |
| 289 | |
| 259 | 290 | /*************************************************************************** |
| 260 | 291 | CODE LOGGING |
| 261 | 292 | ***************************************************************************/ |
| r1036 | r1037 | |
| 294 | 325 | code_log_add_entry - add an entry to the log |
| 295 | 326 | -------------------------------------------------*/ |
| 296 | 327 | |
| 297 | | INLINE void code_log_add_entry(UINT32 pc, UINT32 op, void *base) |
| 328 | INLINE void code_log_add_entry(x86code *base, UINT32 pc, UINT32 op) |
| 298 | 329 | { |
| 330 | code_log_buffer[code_log_index].base = base; |
| 299 | 331 | code_log_buffer[code_log_index].pc = pc; |
| 300 | 332 | code_log_buffer[code_log_index].op = op; |
| 333 | code_log_buffer[code_log_index].string = NULL; |
| 334 | code_log_index++; |
| 335 | } |
| 336 | |
| 337 | |
| 338 | /*------------------------------------------------- |
| 339 | code_log_add_entry_string - add a string |
| 340 | entry to the log |
| 341 | -------------------------------------------------*/ |
| 342 | |
| 343 | INLINE void code_log_add_entry_string(x86code *base, const char *string, UINT32 param) |
| 344 | { |
| 301 | 345 | code_log_buffer[code_log_index].base = base; |
| 346 | code_log_buffer[code_log_index].string = string; |
| 347 | code_log_buffer[code_log_index].op = param; |
| 348 | code_log_buffer[code_log_index].pc = 0; |
| 302 | 349 | code_log_index++; |
| 303 | 350 | } |
| 304 | 351 | |
| r1036 | r1037 | |
| 307 | 354 | code_log - actually log some code |
| 308 | 355 | -------------------------------------------------*/ |
| 309 | 356 | |
| 310 | | static void code_log(const char *label, x86code *start, x86code *stop) |
| 357 | static void print_log_entry(code_log_entry *entry, x86code *cur, const char *x86buffer) |
| 311 | 358 | { |
| 312 | | extern int i386_dasm_one(char *buffer, UINT32 eip, UINT8 *oprom, int mode); |
| 313 | 359 | extern unsigned dasmmips3(char *buffer, unsigned pc, UINT32 op); |
| 314 | | UINT8 *cur = start; |
| 315 | 360 | |
| 361 | /* if we have a match and a string, print it */ |
| 362 | if (entry->string != NULL) |
| 363 | { |
| 364 | fprintf(logfile, "%p: %-50s ", cur, x86buffer); |
| 365 | fprintf(logfile, entry->string, entry->op); |
| 366 | fprintf(logfile, "\n"); |
| 367 | } |
| 368 | |
| 369 | /* otherwise, output with the original instruction to the right */ |
| 370 | else |
| 371 | { |
| 372 | char buffer2[100]; |
| 373 | dasmmips3(buffer2, entry->pc, entry->op); |
| 374 | fprintf(logfile, "%p: %-50s %08X: %s\n", cur, x86buffer, entry->pc, buffer2); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | static void code_log(const char *label, x86code *start, x86code *stop) |
| 379 | { |
| 380 | extern int i386_dasm_one(char *buffer, UINT32 eip, const UINT8 *oprom, int mode); |
| 381 | x86code *cur = start; |
| 382 | int data_remaining = 0; |
| 383 | |
| 316 | 384 | /* open the file, creating it if necessary */ |
| 317 | 385 | if (!open_logfile()) |
| 318 | 386 | return; |
| r1036 | r1037 | |
| 322 | 390 | while (cur < stop) |
| 323 | 391 | { |
| 324 | 392 | char buffer[100]; |
| 393 | int op, lastop; |
| 325 | 394 | int bytes; |
| 326 | | int op; |
| 327 | 395 | |
| 328 | 396 | /* skip filler opcodes */ |
| 329 | 397 | if (*cur == 0xcc) |
| r1036 | r1037 | |
| 334 | 402 | |
| 335 | 403 | /* disassemble this instruction */ |
| 336 | 404 | #ifdef PTR64 |
| 337 | | bytes = i386_dasm_one(buffer, (UINT32)(FPTR)cur, cur, 64) & DASMFLAG_LENGTHMASK; |
| 405 | /* look for special signatures and output as data */ |
| 406 | if (cur[0] == 0x90 && cur[1] == 0xcc && cur[2] == 0x90 && cur[3] == 0xcc && |
| 407 | cur[4] == 0x90 && cur[5] == 0xcc && cur[6] == 0x90 && cur[7] == 0xcc) |
| 408 | data_remaining = 2; |
| 409 | |
| 410 | /* handle data cases first */ |
| 411 | if (data_remaining > 0) |
| 412 | { |
| 413 | UINT64 data = *(UINT64 *)cur; |
| 414 | data_remaining--; |
| 415 | sprintf(buffer, "dq %08X%08X", (UINT32)(data >> 32), (UINT32)data); |
| 416 | bytes = 8; |
| 417 | } |
| 418 | else |
| 419 | bytes = i386_dasm_one(buffer, (UINT32)(FPTR)cur, cur, 64) & DASMFLAG_LENGTHMASK; |
| 338 | 420 | #else |
| 339 | 421 | bytes = i386_dasm_one(buffer, (UINT32)cur, cur, 32) & DASMFLAG_LENGTHMASK; |
| 340 | 422 | #endif |
| 341 | 423 | |
| 342 | 424 | /* look for a match in the registered opcodes */ |
| 425 | lastop = -1; |
| 343 | 426 | for (op = 0; op < code_log_index; op++) |
| 344 | | if (code_log_buffer[op].base == (void *)cur) |
| 345 | | break; |
| 427 | if (code_log_buffer[op].base == cur) |
| 428 | { |
| 429 | if (lastop != -1) |
| 430 | print_log_entry(&code_log_buffer[lastop], cur, ""); |
| 431 | lastop = op; |
| 432 | } |
| 346 | 433 | |
| 347 | 434 | /* if no match, just output the current instruction */ |
| 348 | | if (op == code_log_index) |
| 435 | if (lastop == -1) |
| 349 | 436 | fprintf(logfile, "%p: %s\n", cur, buffer); |
| 350 | 437 | |
| 351 | | /* otherwise, output with the original instruction to the right */ |
| 438 | /* if we have a match and a string, print it */ |
| 352 | 439 | else |
| 353 | | { |
| 354 | | char buffer2[100]; |
| 355 | | dasmmips3(buffer2, code_log_buffer[op].pc, code_log_buffer[op].op); |
| 356 | | fprintf(logfile, "%p: %-50s %08X: %s\n", cur, buffer, code_log_buffer[op].pc, buffer2); |
| 357 | | } |
| 440 | print_log_entry(&code_log_buffer[lastop], cur, buffer); |
| 358 | 441 | |
| 359 | 442 | /* advance past this instruction */ |
| 360 | 443 | cur += bytes; |
| r1036 | r1037 | |
| 454 | 537 | |
| 455 | 538 | #define code_log_reset() |
| 456 | 539 | #define code_log_add_entry(a,b,c) |
| 540 | #define code_log_add_entry_string(a,b,c) |
| 457 | 541 | #define code_log(a,b,c) |
| 458 | | #define desc_log(a) |
| 542 | #define desc_log(a,b) |
| 459 | 543 | |
| 460 | 544 | #endif |
| 461 | 545 | |
| r1036 | r1037 | |
| 867 | 951 | #include "mips3dsm.c" |
| 868 | 952 | #include "cpu/i386/i386dasm.c" |
| 869 | 953 | #endif |
| 954 | |
| 955 | |
| 956 | |
| 957 | /*************************************************************************** |
| 958 | C CORE FOR COMPARISON |
| 959 | ***************************************************************************/ |
| 960 | |
| 961 | #if COMPARE_AGAINST_C |
| 962 | |
| 963 | static UINT8 dummy_read_byte_32le(offs_t offs) |
| 964 | { |
| 965 | if (mips3.access_type == 0) |
| 966 | { |
| 967 | mips3.access_type = 1; |
| 968 | mips3.access_size = 1; |
| 969 | mips3.access_addr = offs; |
| 970 | mips3.access_mask = 0; |
| 971 | mips3.access_data = program_read_byte_32le(offs); |
| 972 | } |
| 973 | else |
| 974 | { |
| 975 | assert(mips3.access_type == 1); |
| 976 | assert(mips3.access_size == 1); |
| 977 | assert(mips3.access_addr == offs); |
| 978 | assert(mips3.access_mask == 0); |
| 979 | mips3.access_type = 0; |
| 980 | } |
| 981 | return mips3.access_data; |
| 982 | } |
| 983 | |
| 984 | static UINT16 dummy_read_word_32le(offs_t offs) |
| 985 | { |
| 986 | if (mips3.access_type == 0) |
| 987 | { |
| 988 | mips3.access_type = 1; |
| 989 | mips3.access_size = 2; |
| 990 | mips3.access_addr = offs; |
| 991 | mips3.access_mask = 0; |
| 992 | mips3.access_data = program_read_word_32le(offs); |
| 993 | } |
| 994 | else |
| 995 | { |
| 996 | assert(mips3.access_type == 1); |
| 997 | assert(mips3.access_size == 2); |
| 998 | assert(mips3.access_addr == offs); |
| 999 | assert(mips3.access_mask == 0); |
| 1000 | mips3.access_type = 0; |
| 1001 | } |
| 1002 | return mips3.access_data; |
| 1003 | } |
| 1004 | |
| 1005 | static UINT32 dummy_read_dword_32le(offs_t offs) |
| 1006 | { |
| 1007 | if (mips3.access_type == 0) |
| 1008 | { |
| 1009 | mips3.access_type = 1; |
| 1010 | mips3.access_size = 4; |
| 1011 | mips3.access_addr = offs; |
| 1012 | mips3.access_mask = 0; |
| 1013 | mips3.access_data = program_read_dword_32le(offs); |
| 1014 | } |
| 1015 | else |
| 1016 | { |
| 1017 | assert(mips3.access_type == 1); |
| 1018 | assert(mips3.access_size == 4); |
| 1019 | assert(mips3.access_addr == offs); |
| 1020 | assert(mips3.access_mask == 0); |
| 1021 | mips3.access_type = 0; |
| 1022 | } |
| 1023 | return mips3.access_data; |
| 1024 | } |
| 1025 | |
| 1026 | static UINT32 dummy_read_masked_32le(offs_t offs, UINT32 mask) |
| 1027 | { |
| 1028 | if (mips3.access_type == 0) |
| 1029 | { |
| 1030 | mips3.access_type = 1; |
| 1031 | mips3.access_size = 4; |
| 1032 | mips3.access_addr = offs; |
| 1033 | mips3.access_mask = mask; |
| 1034 | mips3.access_data = program_read_masked_32le(offs, mask); |
| 1035 | } |
| 1036 | else |
| 1037 | { |
| 1038 | assert(mips3.access_type == 1); |
| 1039 | assert(mips3.access_size == 4); |
| 1040 | assert(mips3.access_addr == offs); |
| 1041 | assert(mips3.access_mask == mask); |
| 1042 | mips3.access_type = 0; |
| 1043 | } |
| 1044 | return mips3.access_data; |
| 1045 | } |
| 1046 | |
| 1047 | static UINT64 dummy_read_qword_32le(offs_t offs) |
| 1048 | { |
| 1049 | if (mips3.access_type == 0) |
| 1050 | { |
| 1051 | mips3.access_type = 1; |
| 1052 | mips3.access_size = 8; |
| 1053 | mips3.access_addr = offs; |
| 1054 | mips3.access_mask = 0; |
| 1055 | mips3.access_data = (*mips3.orighandler.readdouble)(offs); |
| 1056 | } |
| 1057 | else |
| 1058 | { |
| 1059 | assert(mips3.access_type == 1); |
| 1060 | assert(mips3.access_size == 8); |
| 1061 | assert(mips3.access_addr == offs); |
| 1062 | assert(mips3.access_mask == 0); |
| 1063 | mips3.access_type = 0; |
| 1064 | } |
| 1065 | return mips3.access_data; |
| 1066 | } |
| 1067 | |
| 1068 | static UINT64 dummy_read_qword_masked_32le(offs_t offs, UINT64 mask) |
| 1069 | { |
| 1070 | if (mips3.access_type == 0) |
| 1071 | { |
| 1072 | mips3.access_type = 1; |
| 1073 | mips3.access_size = 8; |
| 1074 | mips3.access_addr = offs; |
| 1075 | mips3.access_mask = mask; |
| 1076 | mips3.access_data = (*mips3.orighandler.readdouble_masked)(offs, mask); |
| 1077 | } |
| 1078 | else |
| 1079 | { |
| 1080 | assert(mips3.access_type == 1); |
| 1081 | assert(mips3.access_size == 8); |
| 1082 | assert(mips3.access_addr == offs); |
| 1083 | assert(mips3.access_mask == mask); |
| 1084 | mips3.access_type = 0; |
| 1085 | } |
| 1086 | return mips3.access_data; |
| 1087 | } |
| 1088 | |
| 1089 | static void dummy_write_byte_32le(offs_t offs, UINT8 data) |
| 1090 | { |
| 1091 | if (mips3.access_type == 0) |
| 1092 | { |
| 1093 | mips3.access_type = 2; |
| 1094 | mips3.access_size = 1; |
| 1095 | mips3.access_addr = offs; |
| 1096 | mips3.access_data = data; |
| 1097 | mips3.access_mask = 0; |
| 1098 | } |
| 1099 | else |
| 1100 | { |
| 1101 | assert(mips3.access_type == 2); |
| 1102 | assert(mips3.access_size == 1); |
| 1103 | assert(mips3.access_addr == offs); |
| 1104 | assert(mips3.access_data == data); |
| 1105 | assert(mips3.access_mask == 0); |
| 1106 | mips3.access_type = 0; |
| 1107 | program_write_byte_32le(offs, data); |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | static void dummy_write_word_32le(offs_t offs, UINT16 data) |
| 1112 | { |
| 1113 | if (mips3.access_type == 0) |
| 1114 | { |
| 1115 | mips3.access_type = 2; |
| 1116 | mips3.access_size = 2; |
| 1117 | mips3.access_addr = offs; |
| 1118 | mips3.access_data = data; |
| 1119 | mips3.access_mask = 0; |
| 1120 | } |
| 1121 | else |
| 1122 | { |
| 1123 | assert(mips3.access_type == 2); |
| 1124 | assert(mips3.access_size == 2); |
| 1125 | assert(mips3.access_addr == offs); |
| 1126 | assert(mips3.access_data == data); |
| 1127 | assert(mips3.access_mask == 0); |
| 1128 | mips3.access_type = 0; |
| 1129 | program_write_word_32le(offs, data); |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | static void dummy_write_dword_32le(offs_t offs, UINT32 data) |
| 1134 | { |
| 1135 | if (mips3.access_type == 0) |
| 1136 | { |
| 1137 | mips3.access_type = 2; |
| 1138 | mips3.access_size = 4; |
| 1139 | mips3.access_addr = offs; |
| 1140 | mips3.access_data = data; |
| 1141 | mips3.access_mask = 0; |
| 1142 | } |
| 1143 | else |
| 1144 | { |
| 1145 | assert(mips3.access_type == 2); |
| 1146 | assert(mips3.access_size == 4); |
| 1147 | assert(mips3.access_addr == offs); |
| 1148 | assert(mips3.access_data == data); |
| 1149 | assert(mips3.access_mask == 0); |
| 1150 | mips3.access_type = 0; |
| 1151 | program_write_dword_32le(offs, data); |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | static void dummy_write_masked_32le(offs_t offs, UINT32 data, UINT32 mask) |
| 1156 | { |
| 1157 | if (mips3.access_type == 0) |
| 1158 | { |
| 1159 | mips3.access_type = 2; |
| 1160 | mips3.access_size = 4; |
| 1161 | mips3.access_addr = offs; |
| 1162 | mips3.access_data = data; |
| 1163 | mips3.access_mask = mask; |
| 1164 | } |
| 1165 | else |
| 1166 | { |
| 1167 | assert(mips3.access_type == 2); |
| 1168 | assert(mips3.access_size == 4); |
| 1169 | assert(mips3.access_addr == offs); |
| 1170 | assert(mips3.access_data == data); |
| 1171 | assert(mips3.access_mask == mask); |
| 1172 | mips3.access_type = 0; |
| 1173 | program_write_masked_32le(offs, data, mask); |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | static void dummy_write_qword_32le(offs_t offs, UINT64 data) |
| 1178 | { |
| 1179 | if (mips3.access_type == 0) |
| 1180 | { |
| 1181 | mips3.access_type = 2; |
| 1182 | mips3.access_size = 8; |
| 1183 | mips3.access_addr = offs; |
| 1184 | mips3.access_data = data; |
| 1185 | mips3.access_mask = 0; |
| 1186 | } |
| 1187 | else |
| 1188 | { |
| 1189 | assert(mips3.access_type == 2); |
| 1190 | assert(mips3.access_size == 8); |
| 1191 | assert(mips3.access_addr == offs); |
| 1192 | assert(mips3.access_data == data); |
| 1193 | assert(mips3.access_mask == 0); |
| 1194 | mips3.access_type = 0; |
| 1195 | (*mips3.orighandler.writedouble)(offs, data); |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | static void dummy_write_qword_masked_32le(offs_t offs, UINT64 data, UINT64 mask) |
| 1200 | { |
| 1201 | if (mips3.access_type == 0) |
| 1202 | { |
| 1203 | mips3.access_type = 2; |
| 1204 | mips3.access_size = 8; |
| 1205 | mips3.access_addr = offs; |
| 1206 | mips3.access_data = data; |
| 1207 | mips3.access_mask = mask; |
| 1208 | } |
| 1209 | else |
| 1210 | { |
| 1211 | assert(mips3.access_type == 2); |
| 1212 | assert(mips3.access_size == 8); |
| 1213 | assert(mips3.access_addr == offs); |
| 1214 | assert(mips3.access_data == data); |
| 1215 | assert(mips3.access_mask == mask); |
| 1216 | mips3.access_type = 0; |
| 1217 | (*mips3.orighandler.writedouble_masked)(offs, data, mask); |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | static const memory_handlers override_memory = |
| 1222 | { |
| 1223 | dummy_read_byte_32le, |
| 1224 | dummy_read_word_32le, |
| 1225 | dummy_read_dword_32le, |
| 1226 | dummy_read_masked_32le, |
| 1227 | dummy_read_qword_32le, |
| 1228 | dummy_read_qword_masked_32le, |
| 1229 | |
| 1230 | dummy_write_byte_32le, |
| 1231 | dummy_write_word_32le, |
| 1232 | dummy_write_dword_32le, |
| 1233 | dummy_write_masked_32le, |
| 1234 | dummy_write_qword_32le, |
| 1235 | dummy_write_qword_masked_32le |
| 1236 | }; |
| 1237 | |
| 1238 | #undef SR |
| 1239 | |
| 1240 | #define mips3 c_mips3 |
| 1241 | #define mips3_regs c_mips3_regs |
| 1242 | |
| 1243 | #define mips3_get_context c_mips3_get_context |
| 1244 | #define mips3_set_context c_mips3_set_context |
| 1245 | #define mips3_reset c_mips3_reset |
| 1246 | #define mips3_translate c_mips3_translate |
| 1247 | #define mips3_dasm c_mips3_dasm |
| 1248 | #define mips3_execute c_mips3_execute |
| 1249 | #define mips3_set_info c_mips3_set_info |
| 1250 | #define mips3_get_info c_mips3_get_info |
| 1251 | |
| 1252 | #define r4600be_init c_r4600be_init |
| 1253 | #define r4600le_init c_r4600le_init |
| 1254 | #define r4600be_get_info c_r4600be_get_info |
| 1255 | #define r4600le_get_info c_r4600le_get_info |
| 1256 | |
| 1257 | #define r4650be_init c_r4650be_init |
| 1258 | #define r4650le_init c_r4650le_init |
| 1259 | #define r4650be_get_info c_r4650be_get_info |
| 1260 | #define r4650le_get_info c_r4650le_get_info |
| 1261 | |
| 1262 | #define r4700be_init c_r4700be_init |
| 1263 | #define r4700le_init c_r4700le_init |
| 1264 | #define r4700be_get_info c_r4700be_get_info |
| 1265 | #define r4700le_get_info c_r4700le_get_info |
| 1266 | |
| 1267 | #define r5000be_init c_r5000be_init |
| 1268 | #define r5000le_init c_r5000le_init |
| 1269 | #define r5000be_get_info c_r5000be_get_info |
| 1270 | #define r5000le_get_info c_r5000le_get_info |
| 1271 | |
| 1272 | #define qed5271be_init c_qed5271be_init |
| 1273 | #define qed5271le_init c_qed5271le_init |
| 1274 | #define qed5271be_get_info c_qed5271be_get_info |
| 1275 | #define qed5271le_get_info c_qed5271le_get_info |
| 1276 | |
| 1277 | #define rm7000be_init c_rm7000be_init |
| 1278 | #define rm7000le_init c_rm7000le_init |
| 1279 | #define rm7000be_get_info c_rm7000be_get_info |
| 1280 | #define rm7000le_get_info c_rm7000le_get_info |
| 1281 | |
| 1282 | #include "mips3.c" |
| 1283 | |
| 1284 | #undef mips3 |
| 1285 | |
| 1286 | static void mips3c_init(mips3_flavor flavor, int bigendian, int index, int clock, const struct mips3_config *config, int (*irqcallback)(int)) |
| 1287 | { |
| 1288 | mips3com_init(&c_mips3.core, flavor, bigendian, index, clock, config, irqcallback); |
| 1289 | mips3.orighandler = mips3.core->memory; |
| 1290 | mips3.core->memory = override_memory; |
| 1291 | c_mips3.core.memory = override_memory; |
| 1292 | } |
| 1293 | |
| 1294 | static void mips3c_reset(void) |
| 1295 | { |
| 1296 | c_mips3_reset(); |
| 1297 | } |
| 1298 | |
| 1299 | static void execute_c_version(void) |
| 1300 | { |
| 1301 | int save_debug_mode = Machine->debug_mode; |
| 1302 | int i; |
| 1303 | |
| 1304 | assert(mips3.access_type == 0); |
| 1305 | |
| 1306 | c_mips3.core.cpr[0][COP0_Cause] = (c_mips3.core.cpr[0][COP0_Cause] & ~0xfc00) | (mips3.core->cpr[0][COP0_Cause] & 0xfc00); |
| 1307 | check_irqs(); |
| 1308 | |
| 1309 | assert(c_mips3.core.pc == mips3.core->pc); |
| 1310 | assert(c_mips3.core.hi == mips3.core->hi); |
| 1311 | assert(c_mips3.core.lo == mips3.core->lo); |
| 1312 | for (i = 0; i < 32; i++) |
| 1313 | { |
| 1314 | assert(c_mips3.core.r[i] == mips3.core->r[i]); |
| 1315 | assert(c_mips3.core.cpr[0][i] == mips3.core->cpr[0][i]); |
| 1316 | assert(c_mips3.core.ccr[0][i] == mips3.core->ccr[0][i]); |
| 1317 | assert(c_mips3.core.cpr[1][i] == mips3.core->cpr[1][i]); |
| 1318 | assert(c_mips3.core.ccr[1][i] == mips3.core->ccr[1][i]); |
| 1319 | } |
| 1320 | for (i = 0; i < 8; i++) |
| 1321 | assert(c_mips3.core.cf[1][i] == mips3.core->cf[1][i]); |
| 1322 | assert(c_mips3.core.count_zero_time == mips3.core->count_zero_time); |
| 1323 | |
| 1324 | mips3.access_type = 0; |
| 1325 | |
| 1326 | Machine->debug_mode = 0; |
| 1327 | c_mips3_execute(0); |
| 1328 | Machine->debug_mode = save_debug_mode; |
| 1329 | } |
| 1330 | |
| 1331 | static void compare_c_version(void) |
| 1332 | { |
| 1333 | } |
| 1334 | |
| 1335 | #endif |
src/emu/cpu/mips/mdrcold.c
| r1036 | r1037 | |
| 1015 | 1015 | UINT32 op = cpu_readop32(physpc); |
| 1016 | 1016 | int cycles; |
| 1017 | 1017 | |
| 1018 | | code_log_add_entry(pc, op, drc->cache_top); |
| 1018 | code_log_add_entry(drc->cache_top, pc, op); |
| 1019 | 1019 | |
| 1020 | 1020 | switch (op >> 26) |
| 1021 | 1021 | { |
| r1036 | r1037 | |
| 1031 | 1031 | return RECOMPILE_SUCCESSFUL_CP(0,0) | RECOMPILE_END_OF_STRING; |
| 1032 | 1032 | |
| 1033 | 1033 | case 0x03: /* JAL */ |
| 1034 | | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 1035 | 1034 | emit_mov_m64_imm32(DRCTOP, REGADDR(31), pc + 8); // mov [31],pc + 8 |
| 1035 | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 1036 | 1036 | append_branch_or_dispatch(drc, (pc & 0xf0000000) | (LIMMVAL << 2), 1+cycles); // <branch or dispatch> |
| 1037 | 1037 | return RECOMPILE_SUCCESSFUL_CP(0,0) | RECOMPILE_END_OF_STRING; |
| 1038 | 1038 | |
| r1036 | r1037 | |
| 2379 | 2379 | return RECOMPILE_SUCCESSFUL_CP(1+cycles,0) | RECOMPILE_END_OF_STRING | RECOMPILE_ADD_DISPATCH; |
| 2380 | 2380 | |
| 2381 | 2381 | case 0x09: /* JALR */ |
| 2382 | | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 2383 | 2382 | if (RDREG != 0) |
| 2384 | 2383 | emit_mov_m64_imm32(DRCTOP, REGADDR(RDREG), pc + 8); // mov [rdreg],pc + 8 |
| 2384 | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 2385 | 2385 | emit_mov_r32_m32(DRCTOP, REG_EDI, REGADDRLO(RSREG)); // mov edi,[rsreg].lo |
| 2386 | 2386 | return RECOMPILE_SUCCESSFUL_CP(1+cycles,0) | RECOMPILE_END_OF_STRING | RECOMPILE_ADD_DISPATCH; |
| 2387 | 2387 | |
| r1036 | r1037 | |
| 3447 | 3447 | emit_cmp_m32_imm(DRCTOP, REGADDRHI(RSREG), 0); // cmp [rsreg].hi,0 |
| 3448 | 3448 | emit_jcc_near_link(DRCTOP, COND_GE, &link1); // jge skip |
| 3449 | 3449 | } |
| 3450 | | |
| 3451 | | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 3452 | 3450 | emit_mov_m64_imm32(DRCTOP, MABS(&mips3.core->r[31]), pc + 8); // mov [31],pc + 8 |
| 3451 | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 3453 | 3452 | append_branch_or_dispatch(drc, pc + 4 + (SIMMVAL << 2), 1+cycles); // <branch or dispatch> |
| 3454 | 3453 | resolve_link(DRCTOP, &link1); // skip: |
| 3455 | 3454 | return RECOMPILE_SUCCESSFUL_CP(1,4); |
| r1036 | r1037 | |
| 3457 | 3456 | case 0x11: /* BGEZAL */ |
| 3458 | 3457 | if (RSREG == 0) |
| 3459 | 3458 | { |
| 3460 | | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 3461 | 3459 | emit_mov_m64_imm32(DRCTOP, MABS(&mips3.core->r[31]), pc + 8); // mov [31],pc + 8 |
| 3460 | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 3462 | 3461 | append_branch_or_dispatch(drc, pc + 4 + (SIMMVAL << 2), 1+cycles); // <branch or dispatch> |
| 3463 | 3462 | return RECOMPILE_SUCCESSFUL_CP(0,0) | RECOMPILE_END_OF_STRING; |
| 3464 | 3463 | } |
| r1036 | r1037 | |
| 3468 | 3467 | emit_jcc_near_link(DRCTOP, COND_L, &link1); // jl skip |
| 3469 | 3468 | } |
| 3470 | 3469 | |
| 3471 | | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 3472 | 3470 | emit_mov_m64_imm32(DRCTOP, MABS(&mips3.core->r[31]), pc + 8); // mov [31],pc + 8 |
| 3471 | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 3473 | 3472 | append_branch_or_dispatch(drc, pc + 4 + (SIMMVAL << 2), 1+cycles); // <branch or dispatch> |
| 3474 | 3473 | resolve_link(DRCTOP, &link1); // skip: |
| 3475 | 3474 | return RECOMPILE_SUCCESSFUL_CP(1,4); |
| r1036 | r1037 | |
| 3483 | 3482 | emit_jcc_near_link(DRCTOP, COND_GE, &link1); // jge skip |
| 3484 | 3483 | } |
| 3485 | 3484 | |
| 3486 | | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 3487 | 3485 | emit_mov_m64_imm32(DRCTOP, MABS(&mips3.core->r[31]), pc + 8); // mov [31],pc + 8 |
| 3486 | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 3488 | 3487 | append_branch_or_dispatch(drc, pc + 4 + (SIMMVAL << 2), 1+cycles); // <branch or dispatch> |
| 3489 | 3488 | resolve_link(DRCTOP, &link1); // skip: |
| 3490 | 3489 | return RECOMPILE_SUCCESSFUL_CP(1,8); |
| r1036 | r1037 | |
| 3492 | 3491 | case 0x13: /* BGEZALL */ |
| 3493 | 3492 | if (RSREG == 0) |
| 3494 | 3493 | { |
| 3495 | | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 3496 | 3494 | emit_mov_m64_imm32(DRCTOP, MABS(&mips3.core->r[31]), pc + 8); // mov [31],pc + 8 |
| 3495 | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 3497 | 3496 | append_branch_or_dispatch(drc, pc + 4 + (SIMMVAL << 2), 1+cycles); // <branch or dispatch> |
| 3498 | 3497 | return RECOMPILE_SUCCESSFUL_CP(0,0) | RECOMPILE_END_OF_STRING; |
| 3499 | 3498 | } |
| r1036 | r1037 | |
| 3503 | 3502 | emit_jcc_near_link(DRCTOP, COND_L, &link1); // jl skip |
| 3504 | 3503 | } |
| 3505 | 3504 | |
| 3506 | | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 3507 | 3505 | emit_mov_m64_imm32(DRCTOP, MABS(&mips3.core->r[31]), pc + 8); // mov [31],pc + 8 |
| 3506 | cycles = recompile_delay_slot(drc, pc + 4); // <next instruction> |
| 3508 | 3507 | append_branch_or_dispatch(drc, pc + 4 + (SIMMVAL << 2), 1+cycles); // <branch or dispatch> |
| 3509 | 3508 | resolve_link(DRCTOP, &link1); // skip: |
| 3510 | 3509 | return RECOMPILE_SUCCESSFUL_CP(1,8); |