--- upstream/dynamips-0.2.7-RC2/ppc32_exec.c 2007/10/06 16:24:54 8 +++ upstream/dynamips-0.2.8-RC1/ppc32_exec.c 2007/10/06 16:33:40 11 @@ -76,13 +76,13 @@ } /* Execute a memory operation */ -static forced_inline int ppc32_exec_memop(cpu_ppc_t *cpu,int memop, - m_uint32_t vaddr,u_int dst_reg) +static forced_inline void ppc32_exec_memop(cpu_ppc_t *cpu,int memop, + m_uint32_t vaddr,u_int dst_reg) { fastcall ppc_memop_fn fn; fn = cpu->mem_op_fn[memop]; - return(fn(cpu,vaddr,dst_reg)); + fn(cpu,vaddr,dst_reg); } /* Fetch an instruction */ @@ -118,7 +118,7 @@ register fastcall int (*exec)(cpu_ppc_t *,ppc_insn_t) = NULL; struct ppc32_insn_exec_tag *tag; int index; - + #if DEBUG_INSN_PERF_CNT cpu->perf_counter++; #endif @@ -145,6 +145,28 @@ return(res); } +/* Execute a page */ +fastcall int ppc32_exec_page(cpu_ppc_t *cpu) +{ + m_uint32_t exec_page,offset; + ppc_insn_t insn; + int res; + + exec_page = cpu->ia & ~PPC32_MIN_PAGE_IMASK; + cpu->njm_exec_page = exec_page; + cpu->njm_exec_ptr = cpu->mem_op_lookup(cpu,exec_page,PPC32_MTS_ICACHE); + + do { + offset = (cpu->ia & PPC32_MIN_PAGE_IMASK) >> 2; + insn = vmtoh32(cpu->njm_exec_ptr[offset]); + + res = ppc32_exec_single_instruction(cpu,insn); + if (likely(!res)) cpu->ia += sizeof(ppc_insn_t); + }while((cpu->ia & ~PPC32_MIN_PAGE_IMASK) == exec_page); + + return(0); +} + /* Run PowerPC code in step-by-step mode */ void *ppc32_exec_run_cpu(cpu_gen_t *gen) { @@ -164,6 +186,7 @@ } gen->cpu_thread_running = TRUE; + cpu_exec_loop_set(gen); start_cpu: for(;;) { @@ -1478,7 +1501,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_ICBI,vaddr,0)); + ppc32_exec_memop(cpu,PPC_MEMOP_ICBI,vaddr,0); + return(0); } /* ISYNC - Instruction Synchronize */ @@ -1500,7 +1524,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd)); + ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd); + return(0); } /* LBZU - Load Byte and Zero with Update */ @@ -1510,12 +1535,11 @@ int ra = bits(insn,16,20); m_uint16_t imm = bits(insn,0,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + sign_extend_32(imm,16); - res = ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd); + ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* LBZUX - Load Byte and Zero with Update Indexed */ @@ -1525,12 +1549,11 @@ int ra = bits(insn,16,20); int rb = bits(insn,11,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + cpu->gpr[rb]; - res = ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd); + ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* LBZX - Load Byte and Zero Indexed */ @@ -1546,7 +1569,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd)); + ppc32_exec_memop(cpu,PPC_MEMOP_LBZ,vaddr,rd); + return(0); } /* LHA - Load Half-Word Algebraic */ @@ -1562,7 +1586,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd)); + ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd); + return(0); } /* LHAU - Load Half-Word Algebraic with Update */ @@ -1572,12 +1597,11 @@ int ra = bits(insn,16,20); m_uint16_t imm = bits(insn,0,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + sign_extend_32(imm,16); - res = ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd); + ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* LHAUX - Load Half-Word Algebraic with Update Indexed */ @@ -1587,12 +1611,11 @@ int ra = bits(insn,16,20); int rb = bits(insn,11,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + cpu->gpr[rb]; - res = ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd); + ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* LHAX - Load Half-Word Algebraic ndexed */ @@ -1608,7 +1631,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd)); + ppc32_exec_memop(cpu,PPC_MEMOP_LHA,vaddr,rd); + return(0); } /* LHZ - Load Half-Word and Zero */ @@ -1624,7 +1648,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd)); + ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd); + return(0); } /* LHZU - Load Half-Word and Zero with Update */ @@ -1634,12 +1659,11 @@ int ra = bits(insn,16,20); m_uint16_t imm = bits(insn,0,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + sign_extend_32(imm,16); - res = ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd); + ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* LHZUX - Load Half-Word and Zero with Update Indexed */ @@ -1649,12 +1673,11 @@ int ra = bits(insn,16,20); int rb = bits(insn,11,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + cpu->gpr[rb]; - res = ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd); + ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* LHZX - Load Half-Word and Zero Indexed */ @@ -1670,7 +1693,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd)); + ppc32_exec_memop(cpu,PPC_MEMOP_LHZ,vaddr,rd); + return(0); } /* LMW - Load Multiple Word */ @@ -1680,7 +1704,7 @@ int ra = bits(insn,16,20); m_uint16_t imm = bits(insn,0,15); m_uint32_t vaddr; - int r,res; + int r; vaddr = sign_extend_32(imm,16); @@ -1688,9 +1712,7 @@ vaddr += cpu->gpr[ra]; for(r=rd;r<=31;r++) { - res = ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,r); - if (res != 0) return(res); - + ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,r); vaddr += sizeof(m_uint32_t); } @@ -1710,7 +1732,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_LWBR,vaddr,rd)); + ppc32_exec_memop(cpu,PPC_MEMOP_LWBR,vaddr,rd); + return(0); } /* LWZ - Load Word and Zero */ @@ -1726,7 +1749,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd)); + ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd); + return(0); } /* LWZU - Load Word and Zero with Update */ @@ -1736,12 +1760,11 @@ int ra = bits(insn,16,20); m_uint16_t imm = bits(insn,0,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + sign_extend_32(imm,16); - res = ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd); + ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* LWZUX - Load Word and Zero with Update Indexed */ @@ -1751,12 +1774,11 @@ int ra = bits(insn,16,20); int rb = bits(insn,11,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + cpu->gpr[rb]; - res = ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd); + ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* LWZX - Load Word and Zero Indexed */ @@ -1772,7 +1794,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd)); + ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd); + return(0); } /* LWARX - Load Word and Reserve Indexed */ @@ -1789,8 +1812,8 @@ vaddr += cpu->gpr[ra]; cpu->reserve = 1; - - return(ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd)); + ppc32_exec_memop(cpu,PPC_MEMOP_LWZ,vaddr,rd); + return(0); } /* LFD - Load Floating-Point Double */ @@ -1806,7 +1829,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd)); + ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd); + return(0); } /* LFDU - Load Floating-Point Double with Update */ @@ -1816,12 +1840,11 @@ int ra = bits(insn,16,20); m_uint16_t imm = bits(insn,0,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + sign_extend_32(imm,16); - res = ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd); + ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* LFDUX - Load Floating-Point Double with Update Indexed */ @@ -1831,12 +1854,11 @@ int ra = bits(insn,16,20); int rb = bits(insn,11,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + cpu->gpr[rb]; - res = ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd); + ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* LFDX - Load Floating-Point Double Indexed */ @@ -1852,7 +1874,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd)); + ppc32_exec_memop(cpu,PPC_MEMOP_LFD,vaddr,rd); + return(0); } /* LSWI - Load String Word Immediate */ @@ -1862,7 +1885,7 @@ int ra = bits(insn,16,20); int nb = bits(insn,11,15); m_uint32_t vaddr = 0; - int res,r; + int r; if (ra != 0) vaddr += cpu->gpr[ra]; @@ -1879,9 +1902,7 @@ cpu->gpr[r] = 0; } - if (unlikely(res = ppc32_exec_memop(cpu,PPC_MEMOP_LSW,vaddr,r)) != 0) - return(res); - + ppc32_exec_memop(cpu,PPC_MEMOP_LSW,vaddr,r); cpu->sw_pos += 8; if (cpu->sw_pos == 32) @@ -1901,7 +1922,7 @@ int ra = bits(insn,16,20); int rb = bits(insn,11,15); m_uint32_t vaddr; - int res,r,nb; + int r,nb; vaddr = cpu->gpr[rb]; @@ -1918,9 +1939,7 @@ cpu->gpr[r] = 0; } - if (unlikely(res = ppc32_exec_memop(cpu,PPC_MEMOP_LSW,vaddr,r)) != 0) - return(res); - + ppc32_exec_memop(cpu,PPC_MEMOP_LSW,vaddr,r); cpu->sw_pos += 8; if (cpu->sw_pos == 32) @@ -2054,7 +2073,7 @@ /* MPC860 IMMR */ case 638: - cpu->gpr[rd] = 0x68010000; + cpu->gpr[rd] = cpu->mpc860_immr; break; default: @@ -2815,7 +2834,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs)); + ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs); + return(0); } /* STBU - Store Byte with Update */ @@ -2825,12 +2845,11 @@ int ra = bits(insn,16,20); m_uint16_t imm = bits(insn,0,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + sign_extend_32(imm,16); - res = ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs); + ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* STBUX - Store Byte with Update Indexed */ @@ -2840,12 +2859,11 @@ int ra = bits(insn,16,20); int rb = bits(insn,11,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + cpu->gpr[rb]; - res = ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs); + ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* STBX - Store Byte Indexed */ @@ -2861,7 +2879,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs)); + ppc32_exec_memop(cpu,PPC_MEMOP_STB,vaddr,rs); + return(0); } /* STH - Store Half-Word */ @@ -2877,7 +2896,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs)); + ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs); + return(0); } /* STHU - Store Half-Word with Update */ @@ -2887,12 +2907,11 @@ int ra = bits(insn,16,20); m_uint16_t imm = bits(insn,0,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + sign_extend_32(imm,16); - res = ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs); + ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* STHUX - Store Half-Word with Update Indexed */ @@ -2902,12 +2921,11 @@ int ra = bits(insn,16,20); int rb = bits(insn,11,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + cpu->gpr[rb]; - res = ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs); + ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* STHX - Store Half-Word Indexed */ @@ -2923,7 +2941,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs)); + ppc32_exec_memop(cpu,PPC_MEMOP_STH,vaddr,rs); + return(0); } /* STMW - Store Multiple Word */ @@ -2933,7 +2952,7 @@ int ra = bits(insn,16,20); m_uint16_t imm = bits(insn,0,15); m_uint32_t vaddr; - int r,res; + int r; vaddr = sign_extend_32(imm,16); @@ -2941,9 +2960,7 @@ vaddr += cpu->gpr[ra]; for(r=rs;r<=31;r++) { - res = ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,r); - if (res != 0) return(res); - + ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,r); vaddr += sizeof(m_uint32_t); } @@ -2963,7 +2980,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs)); + ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs); + return(0); } /* STWU - Store Word with Update */ @@ -2973,12 +2991,11 @@ int ra = bits(insn,16,20); m_uint16_t imm = bits(insn,0,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + sign_extend_32(imm,16); - res = ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs); + ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* STWUX - Store Word with Update Indexed */ @@ -2988,12 +3005,11 @@ int ra = bits(insn,16,20); int rb = bits(insn,11,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + cpu->gpr[rb]; - res = ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs); + ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* STWX - Store Word Indexed */ @@ -3009,7 +3025,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs)); + ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs); + return(0); } /* STWBRX - Store Word Byte-Reverse Indexed */ @@ -3025,7 +3042,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_STWBR,vaddr,rs)); + ppc32_exec_memop(cpu,PPC_MEMOP_STWBR,vaddr,rs); + return(0); } /* STWCX. - Store Word Conditional Indexed */ @@ -3035,7 +3053,6 @@ int ra = bits(insn,16,20); int rb = bits(insn,11,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[rb]; @@ -3043,8 +3060,7 @@ vaddr += cpu->gpr[ra]; if (cpu->reserve) { - res = ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs); - if (res != 0) return(res); + ppc32_exec_memop(cpu,PPC_MEMOP_STW,vaddr,rs); cpu->cr_fields[0] = 1 << PPC32_CR_EQ_BIT; @@ -3075,7 +3091,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs)); + ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs); + return(0); } /* STFDU - Store Floating-Point Double with Update */ @@ -3085,12 +3102,11 @@ int ra = bits(insn,16,20); m_uint16_t imm = bits(insn,0,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + sign_extend_32(imm,16); - res = ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs); + ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* STFDUX - Store Floating-Point Double with Update Indexed */ @@ -3100,12 +3116,11 @@ int ra = bits(insn,16,20); int rb = bits(insn,11,15); m_uint32_t vaddr; - int res; vaddr = cpu->gpr[ra] + cpu->gpr[rb]; - res = ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs); + ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs); cpu->gpr[ra] = vaddr; - return(res); + return(0); } /* STFDX - Store Floating-Point Double Indexed */ @@ -3121,7 +3136,8 @@ if (ra != 0) vaddr += cpu->gpr[ra]; - return(ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs)); + ppc32_exec_memop(cpu,PPC_MEMOP_STFD,vaddr,rs); + return(0); } /* STSWI - Store String Word Immediate */ @@ -3131,7 +3147,7 @@ int ra = bits(insn,16,20); int nb = bits(insn,11,15); m_uint32_t vaddr = 0; - int res,r; + int r; if (ra != 0) vaddr += cpu->gpr[ra]; @@ -3146,9 +3162,7 @@ if (cpu->sw_pos == 0) r = (r + 1) & 0x1F; - if (unlikely(res = ppc32_exec_memop(cpu,PPC_MEMOP_STSW,vaddr,r)) != 0) - return(res); - + ppc32_exec_memop(cpu,PPC_MEMOP_STSW,vaddr,r); cpu->sw_pos += 8; if (cpu->sw_pos == 32) @@ -3168,7 +3182,7 @@ int ra = bits(insn,16,20); int rb = bits(insn,11,15); m_uint32_t vaddr; - int res,r,nb; + int r,nb; vaddr = cpu->gpr[rb]; @@ -3183,9 +3197,7 @@ if (cpu->sw_pos == 0) r = (r + 1) & 0x1F; - if (unlikely(res = ppc32_exec_memop(cpu,PPC_MEMOP_STSW,vaddr,r)) != 0) - return(res); - + ppc32_exec_memop(cpu,PPC_MEMOP_STSW,vaddr,r); cpu->sw_pos += 8; if (cpu->sw_pos == 32)