trunk/src/emu/cpu/sharc/sharc.c
| r17729 | r17730 | |
| 66 | 66 | UINT32 ext_count; |
| 67 | 67 | } DMA_REGS; |
| 68 | 68 | |
| 69 | typedef struct |
| 70 | { |
| 71 | UINT32 addr; |
| 72 | UINT32 code; |
| 73 | UINT32 loop_type; |
| 74 | } LADDR; |
| 75 | |
| 69 | 76 | typedef struct _SHARC_REGS SHARC_REGS; |
| 70 | 77 | struct _SHARC_REGS |
| 71 | 78 | { |
| r17729 | r17730 | |
| 84 | 91 | UINT32 daddr; |
| 85 | 92 | UINT32 pcstk; |
| 86 | 93 | UINT32 pcstkp; |
| 87 | | UINT32 laddr; |
| 94 | LADDR laddr; |
| 88 | 95 | UINT32 curlcntr; |
| 89 | 96 | UINT32 lcntr; |
| 90 | 97 | |
| r17729 | r17730 | |
| 131 | 138 | void (*opcode_handler)(SHARC_REGS *cpustate); |
| 132 | 139 | int icount; |
| 133 | 140 | UINT64 opcode; |
| 134 | | UINT64 fetch_opcode; |
| 135 | | UINT64 decode_opcode; |
| 136 | 141 | |
| 137 | 142 | UINT32 nfaddr; |
| 138 | 143 | |
| r17729 | r17730 | |
| 197 | 202 | cpustate->daddr = newpc; |
| 198 | 203 | cpustate->faddr = newpc+1; |
| 199 | 204 | cpustate->nfaddr = newpc+2; |
| 200 | | |
| 201 | | // next instruction to be executed |
| 202 | | cpustate->decode_opcode = ROPCODE(cpustate->daddr); |
| 203 | | // next instruction to be decoded |
| 204 | | cpustate->fetch_opcode = ROPCODE(cpustate->faddr); |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | INLINE void CHANGE_PC_DELAYED(SHARC_REGS *cpustate, UINT32 newpc) |
| r17729 | r17730 | |
| 449 | 449 | device->save_item(NAME(cpustate->daddr)); |
| 450 | 450 | device->save_item(NAME(cpustate->pcstk)); |
| 451 | 451 | device->save_item(NAME(cpustate->pcstkp)); |
| 452 | | device->save_item(NAME(cpustate->laddr)); |
| 452 | device->save_item(NAME(cpustate->laddr.addr)); |
| 453 | device->save_item(NAME(cpustate->laddr.code)); |
| 454 | device->save_item(NAME(cpustate->laddr.loop_type)); |
| 453 | 455 | device->save_item(NAME(cpustate->curlcntr)); |
| 454 | 456 | device->save_item(NAME(cpustate->lcntr)); |
| 455 | 457 | |
| r17729 | r17730 | |
| 510 | 512 | device->save_pointer(NAME(cpustate->internal_ram), 2 * 0x10000); |
| 511 | 513 | |
| 512 | 514 | device->save_item(NAME(cpustate->opcode)); |
| 513 | | device->save_item(NAME(cpustate->fetch_opcode)); |
| 514 | | device->save_item(NAME(cpustate->decode_opcode)); |
| 515 | 515 | |
| 516 | 516 | device->save_item(NAME(cpustate->nfaddr)); |
| 517 | 517 | |
| r17729 | r17730 | |
| 600 | 600 | |
| 601 | 601 | static void sharc_set_irq_line(SHARC_REGS *cpustate, int irqline, int state) |
| 602 | 602 | { |
| 603 | | if (state) |
| 603 | if (state == ASSERT_LINE) |
| 604 | 604 | { |
| 605 | 605 | cpustate->irq_active |= 1 << (8-irqline); |
| 606 | 606 | } |
| 607 | else |
| 608 | { |
| 609 | cpustate->irq_active &= ~(1 << (8-irqline)); |
| 610 | } |
| 607 | 611 | } |
| 608 | 612 | |
| 609 | 613 | void sharc_set_flag_input(device_t *device, int flag_num, int state) |
| r17729 | r17730 | |
| 696 | 700 | cpustate->idle = 0; |
| 697 | 701 | } |
| 698 | 702 | |
| 699 | | // fill the initial pipeline |
| 700 | | |
| 701 | | // next executed instruction |
| 702 | | cpustate->opcode = ROPCODE(cpustate->daddr); |
| 703 | | cpustate->opcode_handler = sharc_op[(cpustate->opcode >> 39) & 0x1ff]; |
| 704 | | |
| 705 | | // next decoded instruction |
| 706 | | cpustate->fetch_opcode = ROPCODE(cpustate->faddr); |
| 707 | | |
| 708 | 703 | while (cpustate->icount > 0 && !cpustate->idle) |
| 709 | 704 | { |
| 710 | 705 | cpustate->pc = cpustate->daddr; |
| r17729 | r17730 | |
| 716 | 711 | cpustate->astat_old_old = cpustate->astat_old; |
| 717 | 712 | cpustate->astat_old = cpustate->astat; |
| 718 | 713 | |
| 719 | | cpustate->decode_opcode = cpustate->fetch_opcode; |
| 714 | cpustate->opcode = ROPCODE(cpustate->pc); |
| 720 | 715 | |
| 721 | | // fetch next instruction |
| 722 | | cpustate->fetch_opcode = ROPCODE(cpustate->faddr); |
| 723 | | |
| 724 | 716 | debugger_instruction_hook(device, cpustate->pc); |
| 725 | 717 | |
| 726 | 718 | // handle looping |
| 727 | | if (cpustate->pc == (cpustate->laddr & 0xffffff)) |
| 719 | if (cpustate->pc == cpustate->laddr.addr) |
| 728 | 720 | { |
| 729 | | switch (cpustate->laddr >> 30) |
| 721 | switch (cpustate->laddr.loop_type) |
| 730 | 722 | { |
| 731 | 723 | case 0: // arithmetic condition-based |
| 732 | 724 | { |
| 733 | | int condition = (cpustate->laddr >> 24) & 0x1f; |
| 725 | int condition = cpustate->laddr.code; |
| 734 | 726 | |
| 735 | 727 | { |
| 736 | 728 | UINT32 looptop = TOP_PC(cpustate); |
| r17729 | r17730 | |
| 779 | 771 | } |
| 780 | 772 | } |
| 781 | 773 | } |
| 774 | |
| 775 | sharc_op[(cpustate->opcode >> 39) & 0x1ff](cpustate); |
| 782 | 776 | |
| 783 | | // execute current instruction |
| 784 | | cpustate->opcode_handler(cpustate); |
| 785 | 777 | |
| 786 | | // decode next instruction |
| 787 | | cpustate->opcode = cpustate->decode_opcode; |
| 788 | | cpustate->opcode_handler = sharc_op[(cpustate->opcode >> 39) & 0x1ff]; |
| 789 | 778 | |
| 790 | 779 | |
| 791 | | |
| 792 | | |
| 793 | 780 | // System register latency effect |
| 794 | 781 | if (cpustate->systemreg_latency_cycles > 0) |
| 795 | 782 | { |
trunk/src/emu/cpu/sharc/sharcops.c
| r17729 | r17730 | |
| 1106 | 1106 | return cpustate->pcstack[cpustate->pcstkp]; |
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | | INLINE void PUSH_LOOP(SHARC_REGS *cpustate, UINT32 pc, UINT32 count) |
| 1109 | INLINE void PUSH_LOOP(SHARC_REGS *cpustate, UINT32 addr, UINT32 code, UINT32 type, UINT32 count) |
| 1110 | 1110 | { |
| 1111 | 1111 | cpustate->lstkp++; |
| 1112 | 1112 | if(cpustate->lstkp >= 6) |
| r17729 | r17730 | |
| 1124 | 1124 | } |
| 1125 | 1125 | |
| 1126 | 1126 | cpustate->lcstack[cpustate->lstkp] = count; |
| 1127 | | cpustate->lastack[cpustate->lstkp] = pc; |
| 1127 | cpustate->lastack[cpustate->lstkp] = (type << 30) | (code << 24) | addr; |
| 1128 | 1128 | cpustate->curlcntr = count; |
| 1129 | | cpustate->laddr = pc; |
| 1129 | |
| 1130 | cpustate->laddr.addr = addr; |
| 1131 | cpustate->laddr.code = code; |
| 1132 | cpustate->laddr.loop_type = type; |
| 1130 | 1133 | } |
| 1131 | 1134 | |
| 1132 | 1135 | INLINE void POP_LOOP(SHARC_REGS *cpustate) |
| r17729 | r17730 | |
| 1148 | 1151 | } |
| 1149 | 1152 | |
| 1150 | 1153 | cpustate->curlcntr = cpustate->lcstack[cpustate->lstkp]; |
| 1151 | | cpustate->laddr = cpustate->lastack[cpustate->lstkp]; |
| 1154 | |
| 1155 | cpustate->laddr.addr = cpustate->lastack[cpustate->lstkp] & 0xffffff; |
| 1156 | cpustate->laddr.code = (cpustate->lastack[cpustate->lstkp] >> 24) & 0x1f; |
| 1157 | cpustate->laddr.loop_type = (cpustate->lastack[cpustate->lstkp] >> 30) & 0x3; |
| 1152 | 1158 | } |
| 1153 | 1159 | |
| 1154 | 1160 | INLINE void PUSH_STATUS_STACK(SHARC_REGS *cpustate) |
| r17729 | r17730 | |
| 2391 | 2397 | if (cpustate->lcntr > 0) |
| 2392 | 2398 | { |
| 2393 | 2399 | PUSH_PC(cpustate, cpustate->pc+1); |
| 2394 | | PUSH_LOOP(cpustate, address | (type << 30) | (cond << 24), cpustate->lcntr); |
| 2400 | PUSH_LOOP(cpustate, address, cond, type, cpustate->lcntr); |
| 2395 | 2401 | } |
| 2396 | 2402 | } |
| 2397 | 2403 | |
| r17729 | r17730 | |
| 2425 | 2431 | if (cpustate->lcntr > 0) |
| 2426 | 2432 | { |
| 2427 | 2433 | PUSH_PC(cpustate, cpustate->pc+1); |
| 2428 | | PUSH_LOOP(cpustate, address | (type << 30) | (cond << 24), cpustate->lcntr); |
| 2434 | PUSH_LOOP(cpustate, address, cond, type, cpustate->lcntr); |
| 2429 | 2435 | } |
| 2430 | 2436 | } |
| 2431 | 2437 | |
| r17729 | r17730 | |
| 2440 | 2446 | UINT32 address = (cpustate->pc + offset); |
| 2441 | 2447 | |
| 2442 | 2448 | PUSH_PC(cpustate, cpustate->pc+1); |
| 2443 | | PUSH_LOOP(cpustate, address | (cond << 24), 0); |
| 2449 | PUSH_LOOP(cpustate, address, cond, 0, 0); |
| 2444 | 2450 | } |
| 2445 | 2451 | |
| 2446 | 2452 | /*****************************************************************************/ |
| r17729 | r17730 | |
| 2737 | 2743 | cpustate->faddr = cpustate->pc+1; |
| 2738 | 2744 | cpustate->nfaddr = cpustate->pc+2; |
| 2739 | 2745 | |
| 2740 | | cpustate->decode_opcode = ROPCODE(cpustate->daddr); |
| 2741 | | cpustate->fetch_opcode = ROPCODE(cpustate->faddr); |
| 2742 | | |
| 2743 | 2746 | cpustate->idle = 1; |
| 2744 | 2747 | } |
| 2745 | 2748 | |