Cleanup, be_t fixed

Some functions renamed:
get_ps3_function_name
execute_syscall_by_index
This commit is contained in:
Nekotekina 2015-09-14 19:32:35 +03:00
parent 4e62ec7458
commit 59f1077a36
15 changed files with 476 additions and 564 deletions

File diff suppressed because it is too large Load Diff

View File

@ -970,8 +970,8 @@ void ppu_interpreter::VSLB(PPUThread& CPU, ppu_opcode_t op)
void ppu_interpreter::VSLDOI(PPUThread& CPU, ppu_opcode_t op)
{
u8 tmpSRC[32];
memcpy(tmpSRC, CPU.VPR[op.vb]._u8, 16);
memcpy(tmpSRC + 16, CPU.VPR[op.va]._u8, 16);
std::memcpy(tmpSRC, CPU.VPR + op.vb, 16);
std::memcpy(tmpSRC + 16, CPU.VPR + op.va, 16);
for (uint b = 0; b<16; b++)
{
@ -1475,7 +1475,7 @@ void ppu_interpreter::SC(PPUThread& CPU, ppu_opcode_t op)
{
switch (op.lev)
{
case 0x0: SysCalls::DoSyscall(CPU, CPU.GPR[11]); break;
case 0x0: execute_syscall_by_index(CPU, CPU.GPR[11]); break;
case 0x3: CPU.fast_stop(); break;
default: throw EXCEPTION("");
}

View File

@ -1,9 +1,6 @@
#pragma once
#include "Emu/Cell/PPUOpcodes.h"
#include "Emu/SysCalls/SysCalls.h"
#include "rpcs3/Ini.h"
#include "Emu/SysCalls/Modules.h"
#include "Emu/Memory/Memory.h"
#include <stdint.h>
@ -16,7 +13,7 @@
#include <fenv.h>
extern u64 rotate_mask[64][64]; // defined in PPUThread.cpp, static didn't work correctly in GCC 4.9 for some reason
extern u64 rotate_mask[64][64]; // defined in PPUThread.cpp
extern u64 get_timebased_time();
inline void InitRotateMask()
@ -1327,8 +1324,8 @@ private:
void VPERM(u32 vd, u32 va, u32 vb, u32 vc)
{
u8 tmpSRC[32];
memcpy(tmpSRC, CPU.VPR[vb]._u8, 16);
memcpy(tmpSRC + 16, CPU.VPR[va]._u8, 16);
std::memcpy(tmpSRC, CPU.VPR + vb, 16);
std::memcpy(tmpSRC + 16, CPU.VPR + va, 16);
for (uint b = 0; b < 16; b++)
{
@ -1703,8 +1700,8 @@ private:
void VSLDOI(u32 vd, u32 va, u32 vb, u32 sh)
{
u8 tmpSRC[32];
memcpy(tmpSRC, CPU.VPR[vb]._u8, 16);
memcpy(tmpSRC + 16, CPU.VPR[va]._u8, 16);
std::memcpy(tmpSRC, CPU.VPR + vb, 16);
std::memcpy(tmpSRC + 16, CPU.VPR + va, 16);
for(uint b=0; b<16; b++)
{
@ -2232,13 +2229,17 @@ private:
}
void HACK(u32 index)
{
extern void execute_ppu_func_by_index(PPUThread& ppu, u32 index);
execute_ppu_func_by_index(CPU, index);
}
void SC(u32 lev)
{
extern void execute_syscall_by_index(PPUThread& ppu, u64 code);
switch (lev)
{
case 0x0: SysCalls::DoSyscall(CPU, CPU.GPR[11]); break;
case 0x0: execute_syscall_by_index(CPU, CPU.GPR[11]); break;
case 0x1: throw EXCEPTION("HyperCall LV1");
case 0x3: CPU.fast_stop(); break;
default: throw EXCEPTION("Unknown level (0x%x)", lev);
@ -2487,12 +2488,12 @@ private:
void LDX(u32 rd, u32 ra, u32 rb)
{
const u64 addr = ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb];
CPU.GPR[rd] = vm::read64(VM_CAST(addr));
CPU.GPR[rd] = vm::ps3::read64(VM_CAST(addr));
}
void LWZX(u32 rd, u32 ra, u32 rb)
{
const u64 addr = ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb];
CPU.GPR[rd] = vm::read32(VM_CAST(addr));
CPU.GPR[rd] = vm::ps3::read32(VM_CAST(addr));
}
void SLW(u32 ra, u32 rs, u32 rb, u32 rc)
{
@ -2564,7 +2565,7 @@ private:
void LVEHX(u32 vd, u32 ra, u32 rb)
{
const u64 addr = (ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb]) & ~1ULL;
CPU.VPR[vd]._u16[7 - ((addr >> 1) & 0x7)] = vm::read16(VM_CAST(addr));
CPU.VPR[vd]._u16[7 - ((addr >> 1) & 0x7)] = vm::ps3::read16(VM_CAST(addr));
// check LVEWX comments
}
void SUBF(u32 rd, u32 ra, u32 rb, u32 oe, u32 rc)
@ -2578,7 +2579,7 @@ private:
void LDUX(u32 rd, u32 ra, u32 rb)
{
const u64 addr = CPU.GPR[ra] + CPU.GPR[rb];
CPU.GPR[rd] = vm::read64(VM_CAST(addr));
CPU.GPR[rd] = vm::ps3::read64(VM_CAST(addr));
CPU.GPR[ra] = addr;
}
void DCBST(u32 ra, u32 rb)
@ -2587,7 +2588,7 @@ private:
void LWZUX(u32 rd, u32 ra, u32 rb)
{
const u64 addr = CPU.GPR[ra] + CPU.GPR[rb];
CPU.GPR[rd] = vm::read32(VM_CAST(addr));
CPU.GPR[rd] = vm::ps3::read32(VM_CAST(addr));
CPU.GPR[ra] = addr;
}
void CNTLZD(u32 ra, u32 rs, u32 rc)
@ -2613,7 +2614,7 @@ private:
void LVEWX(u32 vd, u32 ra, u32 rb)
{
const u64 addr = (ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb]) & ~3ULL;
CPU.VPR[vd]._u32[3 - ((addr >> 2) & 0x3)] = vm::read32(VM_CAST(addr));
CPU.VPR[vd]._u32[3 - ((addr >> 2) & 0x3)] = vm::ps3::read32(VM_CAST(addr));
// It's not very good idea to implement it using read128(),
// because it can theoretically read RawSPU 32-bit MMIO register (read128() will fail)
//CPU.VPR[vd] = vm::read128((ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb]) & ~0xfULL);
@ -2650,7 +2651,7 @@ private:
void LVX(u32 vd, u32 ra, u32 rb)
{
const u64 addr = (ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb]) & ~0xfull;
CPU.VPR[vd] = vm::read128(VM_CAST(addr));
CPU.VPR[vd] = vm::ps3::read128(VM_CAST(addr));
}
void NEG(u32 rd, u32 ra, u32 oe, u32 rc)
{
@ -2746,7 +2747,7 @@ private:
void STDX(u32 rs, u32 ra, u32 rb)
{
const u64 addr = ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb];
vm::write64(VM_CAST(addr), CPU.GPR[rs]);
vm::ps3::write64(VM_CAST(addr), CPU.GPR[rs]);
}
void STWCX_(u32 rs, u32 ra, u32 rb)
{
@ -2758,31 +2759,31 @@ private:
void STWX(u32 rs, u32 ra, u32 rb)
{
const u64 addr = ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb];
vm::write32(VM_CAST(addr), (u32)CPU.GPR[rs]);
vm::ps3::write32(VM_CAST(addr), (u32)CPU.GPR[rs]);
}
void STVEHX(u32 vs, u32 ra, u32 rb)
{
const u64 addr = (ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb]) & ~1ULL;
const u8 eb = (addr & 0xf) >> 1;
vm::write16(VM_CAST(addr), CPU.VPR[vs]._u16[7 - eb]);
vm::ps3::write16(VM_CAST(addr), CPU.VPR[vs]._u16[7 - eb]);
}
void STDUX(u32 rs, u32 ra, u32 rb)
{
const u64 addr = CPU.GPR[ra] + CPU.GPR[rb];
vm::write64(VM_CAST(addr), CPU.GPR[rs]);
vm::ps3::write64(VM_CAST(addr), CPU.GPR[rs]);
CPU.GPR[ra] = addr;
}
void STWUX(u32 rs, u32 ra, u32 rb)
{
const u64 addr = CPU.GPR[ra] + CPU.GPR[rb];
vm::write32(VM_CAST(addr), (u32)CPU.GPR[rs]);
vm::ps3::write32(VM_CAST(addr), (u32)CPU.GPR[rs]);
CPU.GPR[ra] = addr;
}
void STVEWX(u32 vs, u32 ra, u32 rb)
{
const u64 addr = (ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb]) & ~3ULL;
const u8 eb = (addr & 0xf) >> 2;
vm::write32(VM_CAST(addr), CPU.VPR[vs]._u32[3 - eb]);
vm::ps3::write32(VM_CAST(addr), CPU.VPR[vs]._u32[3 - eb]);
}
void SUBFZE(u32 rd, u32 ra, u32 oe, u32 rc)
{
@ -2815,7 +2816,7 @@ private:
void STVX(u32 vs, u32 ra, u32 rb)
{
const u64 addr = (ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb]) & ~0xfull;
vm::write128(VM_CAST(addr), CPU.VPR[vs]);
vm::ps3::write128(VM_CAST(addr), CPU.VPR[vs]);
}
void MULLD(u32 rd, u32 ra, u32 rb, u32 oe, u32 rc)
{
@ -2875,7 +2876,7 @@ private:
void LHZX(u32 rd, u32 ra, u32 rb)
{
const u64 addr = ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb];
CPU.GPR[rd] = vm::read16(VM_CAST(addr));
CPU.GPR[rd] = vm::ps3::read16(VM_CAST(addr));
}
void EQV(u32 ra, u32 rs, u32 rb, u32 rc)
{
@ -2889,7 +2890,7 @@ private:
void LHZUX(u32 rd, u32 ra, u32 rb)
{
const u64 addr = ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb];
CPU.GPR[rd] = vm::read16(VM_CAST(addr));
CPU.GPR[rd] = vm::ps3::read16(VM_CAST(addr));
CPU.GPR[ra] = addr;
}
void XOR(u32 ra, u32 rs, u32 rb, u32 rc)
@ -2904,7 +2905,7 @@ private:
void LWAX(u32 rd, u32 ra, u32 rb)
{
const u64 addr = ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb];
CPU.GPR[rd] = (s64)(s32)vm::read32(VM_CAST(addr));
CPU.GPR[rd] = (s64)(s32)vm::ps3::read32(VM_CAST(addr));
}
void DST(u32 ra, u32 rb, u32 strm, u32 t)
{
@ -2912,12 +2913,12 @@ private:
void LHAX(u32 rd, u32 ra, u32 rb)
{
const u64 addr = ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb];
CPU.GPR[rd] = (s64)(s16)vm::read16(VM_CAST(addr));
CPU.GPR[rd] = (s64)(s16)vm::ps3::read16(VM_CAST(addr));
}
void LVXL(u32 vd, u32 ra, u32 rb)
{
const u64 addr = (ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb]) & ~0xfull;
CPU.VPR[vd] = vm::read128(VM_CAST(addr));
CPU.VPR[vd] = vm::ps3::read128(VM_CAST(addr));
}
void MFTB(u32 rd, u32 spr)
{
@ -2934,7 +2935,7 @@ private:
void LWAUX(u32 rd, u32 ra, u32 rb)
{
const u64 addr = ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb];
CPU.GPR[rd] = (s64)(s32)vm::read32(VM_CAST(addr));
CPU.GPR[rd] = (s64)(s32)vm::ps3::read32(VM_CAST(addr));
CPU.GPR[ra] = addr;
}
void DSTST(u32 ra, u32 rb, u32 strm, u32 t)
@ -2943,13 +2944,13 @@ private:
void LHAUX(u32 rd, u32 ra, u32 rb)
{
const u64 addr = ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb];
CPU.GPR[rd] = (s64)(s16)vm::read16(VM_CAST(addr));
CPU.GPR[rd] = (s64)(s16)vm::ps3::read16(VM_CAST(addr));
CPU.GPR[ra] = addr;
}
void STHX(u32 rs, u32 ra, u32 rb)
{
const u64 addr = ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb];
vm::write16(VM_CAST(addr), (u16)CPU.GPR[rs]);
vm::ps3::write16(VM_CAST(addr), (u16)CPU.GPR[rs]);
}
void ORC(u32 ra, u32 rs, u32 rb, u32 rc)
{
@ -2963,7 +2964,7 @@ private:
void STHUX(u32 rs, u32 ra, u32 rb)
{
const u64 addr = CPU.GPR[ra] + CPU.GPR[rb];
vm::write16(VM_CAST(addr), (u16)CPU.GPR[rs]);
vm::ps3::write16(VM_CAST(addr), (u16)CPU.GPR[rs]);
CPU.GPR[ra] = addr;
}
void OR(u32 ra, u32 rs, u32 rb, u32 rc)
@ -3023,7 +3024,7 @@ private:
void STVXL(u32 vs, u32 ra, u32 rb)
{
const u64 addr = (ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb]) & ~0xfull;
vm::write128(VM_CAST(addr), CPU.VPR[vs]);
vm::ps3::write128(VM_CAST(addr), CPU.VPR[vs]);
}
void DIVD(u32 rd, u32 ra, u32 rb, u32 oe, u32 rc)
{
@ -3148,7 +3149,7 @@ private:
{
if (N > 3)
{
CPU.GPR[reg] = vm::read32(VM_CAST(addr));
CPU.GPR[reg] = vm::ps3::read32(VM_CAST(addr));
addr += 4;
N -= 4;
}
@ -3216,7 +3217,7 @@ private:
u32 count = CPU.XER.XER & 0x7F;
for (; count >= 4; count -= 4, addr += 4, rs = (rs+1) & 31)
{
vm::write32(VM_CAST(addr), (u32)CPU.GPR[rs]);
vm::ps3::write32(VM_CAST(addr), (u32)CPU.GPR[rs]);
}
if (count)
{
@ -3281,7 +3282,7 @@ private:
{
if (N > 3)
{
vm::write32(VM_CAST(addr), (u32)CPU.GPR[reg]);
vm::ps3::write32(VM_CAST(addr), (u32)CPU.GPR[reg]);
addr += 4;
N -= 4;
}
@ -3424,7 +3425,7 @@ private:
void STFIWX(u32 frs, u32 ra, u32 rb)
{
const u64 addr = ra ? CPU.GPR[ra] + CPU.GPR[rb] : CPU.GPR[rb];
vm::write32(VM_CAST(addr), (u32&)CPU.FPR[frs]);
vm::ps3::write32(VM_CAST(addr), (u32&)CPU.FPR[frs]);
}
void EXTSW(u32 ra, u32 rs, u32 rc)
{
@ -3444,12 +3445,12 @@ private:
void LWZ(u32 rd, u32 ra, s32 d)
{
const u64 addr = ra ? CPU.GPR[ra] + d : d;
CPU.GPR[rd] = vm::read32(VM_CAST(addr));
CPU.GPR[rd] = vm::ps3::read32(VM_CAST(addr));
}
void LWZU(u32 rd, u32 ra, s32 d)
{
const u64 addr = CPU.GPR[ra] + d;
CPU.GPR[rd] = vm::read32(VM_CAST(addr));
CPU.GPR[rd] = vm::ps3::read32(VM_CAST(addr));
CPU.GPR[ra] = addr;
}
void LBZ(u32 rd, u32 ra, s32 d)
@ -3466,12 +3467,12 @@ private:
void STW(u32 rs, u32 ra, s32 d)
{
const u64 addr = ra ? CPU.GPR[ra] + d : d;
vm::write32(VM_CAST(addr), (u32)CPU.GPR[rs]);
vm::ps3::write32(VM_CAST(addr), (u32)CPU.GPR[rs]);
}
void STWU(u32 rs, u32 ra, s32 d)
{
const u64 addr = CPU.GPR[ra] + d;
vm::write32(VM_CAST(addr), (u32)CPU.GPR[rs]);
vm::ps3::write32(VM_CAST(addr), (u32)CPU.GPR[rs]);
CPU.GPR[ra] = addr;
}
void STB(u32 rs, u32 ra, s32 d)
@ -3488,34 +3489,34 @@ private:
void LHZ(u32 rd, u32 ra, s32 d)
{
const u64 addr = ra ? CPU.GPR[ra] + d : d;
CPU.GPR[rd] = vm::read16(VM_CAST(addr));
CPU.GPR[rd] = vm::ps3::read16(VM_CAST(addr));
}
void LHZU(u32 rd, u32 ra, s32 d)
{
const u64 addr = CPU.GPR[ra] + d;
CPU.GPR[rd] = vm::read16(VM_CAST(addr));
CPU.GPR[rd] = vm::ps3::read16(VM_CAST(addr));
CPU.GPR[ra] = addr;
}
void LHA(u32 rd, u32 ra, s32 d)
{
const u64 addr = ra ? CPU.GPR[ra] + d : d;
CPU.GPR[rd] = (s64)(s16)vm::read16(VM_CAST(addr));
CPU.GPR[rd] = (s64)(s16)vm::ps3::read16(VM_CAST(addr));
}
void LHAU(u32 rd, u32 ra, s32 d)
{
const u64 addr = CPU.GPR[ra] + d;
CPU.GPR[rd] = (s64)(s16)vm::read16(VM_CAST(addr));
CPU.GPR[rd] = (s64)(s16)vm::ps3::read16(VM_CAST(addr));
CPU.GPR[ra] = addr;
}
void STH(u32 rs, u32 ra, s32 d)
{
const u64 addr = ra ? CPU.GPR[ra] + d : d;
vm::write16(VM_CAST(addr), (u16)CPU.GPR[rs]);
vm::ps3::write16(VM_CAST(addr), (u16)CPU.GPR[rs]);
}
void STHU(u32 rs, u32 ra, s32 d)
{
const u64 addr = CPU.GPR[ra] + d;
vm::write16(VM_CAST(addr), (u16)CPU.GPR[rs]);
vm::ps3::write16(VM_CAST(addr), (u16)CPU.GPR[rs]);
CPU.GPR[ra] = addr;
}
void LMW(u32 rd, u32 ra, s32 d)
@ -3523,7 +3524,7 @@ private:
u64 addr = ra ? CPU.GPR[ra] + d : d;
for(u32 i=rd; i<32; ++i, addr += 4)
{
CPU.GPR[i] = vm::read32(VM_CAST(addr));
CPU.GPR[i] = vm::ps3::read32(VM_CAST(addr));
}
}
void STMW(u32 rs, u32 ra, s32 d)
@ -3531,7 +3532,7 @@ private:
u64 addr = ra ? CPU.GPR[ra] + d : d;
for(u32 i=rs; i<32; ++i, addr += 4)
{
vm::write32(VM_CAST(addr), (u32)CPU.GPR[i]);
vm::ps3::write32(VM_CAST(addr), (u32)CPU.GPR[i]);
}
}
void LFS(u32 frd, u32 ra, s32 d)
@ -3619,18 +3620,18 @@ private:
void LD(u32 rd, u32 ra, s32 ds)
{
const u64 addr = ra ? CPU.GPR[ra] + ds : ds;
CPU.GPR[rd] = vm::read64(VM_CAST(addr));
CPU.GPR[rd] = vm::ps3::read64(VM_CAST(addr));
}
void LDU(u32 rd, u32 ra, s32 ds)
{
const u64 addr = CPU.GPR[ra] + ds;
CPU.GPR[rd] = vm::read64(VM_CAST(addr));
CPU.GPR[rd] = vm::ps3::read64(VM_CAST(addr));
CPU.GPR[ra] = addr;
}
void LWA(u32 rd, u32 ra, s32 ds)
{
const u64 addr = ra ? CPU.GPR[ra] + ds : ds;
CPU.GPR[rd] = (s64)(s32)vm::read32(VM_CAST(addr));
CPU.GPR[rd] = (s64)(s32)vm::ps3::read32(VM_CAST(addr));
}
void FDIVS(u32 frd, u32 fra, u32 frb, u32 rc) {FDIV(frd, fra, frb, rc, true);}
void FSUBS(u32 frd, u32 fra, u32 frb, u32 rc) {FSUB(frd, fra, frb, rc, true);}
@ -3684,12 +3685,12 @@ private:
void STD(u32 rs, u32 ra, s32 d)
{
const u64 addr = ra ? CPU.GPR[ra] + d : d;
vm::write64(VM_CAST(addr), CPU.GPR[rs]);
vm::ps3::write64(VM_CAST(addr), CPU.GPR[rs]);
}
void STDU(u32 rs, u32 ra, s32 ds)
{
const u64 addr = CPU.GPR[ra] + ds;
vm::write64(VM_CAST(addr), CPU.GPR[rs]);
vm::ps3::write64(VM_CAST(addr), CPU.GPR[rs]);
CPU.GPR[ra] = addr;
}
void MTFSB1(u32 crbd, u32 rc)

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#ifdef LLVM_AVAILABLE
#include "rpcs3/Ini.h"
#include "Utilities/Log.h"
#include "Emu/System.h"
#include "Emu/Cell/PPUDisAsm.h"

View File

@ -29,6 +29,9 @@
#pragma warning(pop)
#endif
extern void execute_ppu_func_by_index(PPUThread& ppu, u32 id);
extern void execute_syscall_by_index(PPUThread& ppu, u64 code);
using namespace llvm;
using namespace ppu_recompiler_llvm;
@ -1787,7 +1790,7 @@ void Compiler::HACK(u32 index) {
static u32 wrappedDoSyscall(PPUThread &CPU, u64 code) noexcept {
try
{
SysCalls::DoSyscall(CPU, code);
execute_syscall_by_index(CPU, code);
return ExecutionStatus::ExecutionStatusBlockEnded;
}
catch (...)
@ -1812,7 +1815,7 @@ void Compiler::SC(u32 lev) {
}
break;
case 3:
Call<void>("PPUThread.FastStop", &PPUThread::fast_stop, m_state.args[CompileTaskState::Args::State]);
Call<void>("PPUThread.fast_stop", &PPUThread::fast_stop, m_state.args[CompileTaskState::Args::State]);
break;
default:
CompilationError(fmt::format("SC %u", lev));
@ -2160,7 +2163,7 @@ void Compiler::TW(u32 to, u32 ra, u32 rb) {
}
void Compiler::LVSL(u32 vd, u32 ra, u32 rb) {
static const v128 s_lvsl_values[] = {
static const u64 s_lvsl_values[0x10][2] = {
{ 0x08090A0B0C0D0E0F, 0x0001020304050607 },
{ 0x090A0B0C0D0E0F10, 0x0102030405060708 },
{ 0x0A0B0C0D0E0F1011, 0x0203040506070809 },
@ -2389,7 +2392,7 @@ void Compiler::CMPL(u32 crfd, u32 l, u32 ra, u32 rb) {
}
void Compiler::LVSR(u32 vd, u32 ra, u32 rb) {
static const v128 s_lvsr_values[] = {
static const u64 s_lvsr_values[0x10][2] = {
{ 0x18191A1B1C1D1E1F, 0x1011121314151617 },
{ 0x1718191A1B1C1D1E, 0x0F10111213141516 },
{ 0x161718191A1B1C1D, 0x0E0F101112131415 },

View File

@ -99,7 +99,7 @@ struct ppu_recompiler_llvm::PPUState {
address = addr;
for (int i = 0; i < (sizeof(mem_block) / 8); i++) {
mem_block[i] = vm::read64(address + (i * 8));
mem_block[i] = vm::ps3::read64(address + (i * 8));
}
}
@ -123,7 +123,7 @@ struct ppu_recompiler_llvm::PPUState {
ppu.TB = TB;
for (int i = 0; i < (sizeof(mem_block) / 8); i++) {
vm::write64(address + (i * 8), mem_block[i]);
vm::ps3::write64(address + (i * 8), mem_block[i]);
}
}

View File

@ -5,8 +5,6 @@
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUThread.h"
#include "Emu/SysCalls/SysCalls.h"
#include "Emu/SysCalls/Modules.h"
#include "Emu/Cell/PPUDecoder.h"
#include "Emu/Cell/PPUInterpreter.h"
#include "Emu/Cell/PPUInterpreter2.h"
@ -51,7 +49,7 @@ void ppu_decoder_cache_t::initialize(u32 addr, u32 size)
inter->func = ppu_interpreter::NULL_OP;
// decode PPU opcode
dec.Decode(vm::read32(pos));
dec.Decode(vm::ps3::read32(pos));
// store function address
pointer[pos / 4] = inter->func;
@ -81,13 +79,15 @@ PPUThread::~PPUThread()
void PPUThread::dump_info() const
{
extern std::string get_ps3_function_name(u64 fid);
if (~hle_code < 1024)
{
LOG_SUCCESS(HLE, "Last syscall: %lld (%s)", ~hle_code, SysCalls::GetFuncName(hle_code));
LOG_SUCCESS(HLE, "Last syscall: %lld (%s)", ~hle_code, get_ps3_function_name(hle_code));
}
else if (hle_code)
{
LOG_SUCCESS(HLE, "Last function: %s (0x%llx)", SysCalls::GetFuncName(hle_code), hle_code);
LOG_SUCCESS(HLE, "Last function: %s (0x%llx)", get_ps3_function_name(hle_code), hle_code);
}
CPUThread::dump_info();
@ -214,7 +214,7 @@ int FPRdouble::Cmp(PPCdouble a, PPCdouble b)
u64 PPUThread::get_stack_arg(s32 i)
{
return vm::read64(VM_CAST(GPR[1] + 0x70 + 0x8 * (i - 9)));
return vm::ps3::read64(VM_CAST(GPR[1] + 0x70 + 0x8 * (i - 9)));
}
void PPUThread::fast_call(u32 addr, u32 rtoc)
@ -313,7 +313,7 @@ void PPUThread::task()
if (!m_state.load())
{
// call interpreter function
func(*this, { vm::read32(PC) });
func(*this, { vm::ps3::read32(PC) });
// next instruction
PC += 4;
@ -335,8 +335,8 @@ ppu_thread::ppu_thread(u32 entry, const std::string& name, u32 stack_size, s32 p
if (entry)
{
ppu->PC = vm::read32(entry);
ppu->GPR[2] = vm::read32(entry + 4); // rtoc
ppu->PC = vm::ps3::read32(entry);
ppu->GPR[2] = vm::ps3::read32(entry + 4); // rtoc
}
ppu->stack_size = stack_size ? stack_size : Emu.GetPrimaryStackSize();

View File

@ -1012,3 +1012,20 @@ force_inline T cast_from_ppu_gpr(const u64 reg)
{
return cast_ppu_gpr<T>::from_gpr(reg);
}
// flags set in ModuleFunc
enum : u32
{
MFF_FORCED_HLE = (1 << 0), // always call HLE function
MFF_NO_RETURN = (1 << 1), // uses EIF_USE_BRANCH flag with LLE, ignored with MFF_FORCED_HLE
};
// flags passed with index
enum : u32
{
EIF_SAVE_RTOC = (1 << 25), // save RTOC in [SP+0x28] before calling HLE/LLE function
EIF_PERFORM_BLR = (1 << 24), // do BLR after calling HLE/LLE function
EIF_USE_BRANCH = (1 << 23), // do only branch, LLE must be set, last_syscall must be zero
EIF_FLAGS = 0x3800000, // all flags
};

View File

@ -2,7 +2,7 @@
#include "Modules.h"
#include "SysCalls.h"
std::string SysCalls::GetFuncName(const u64 fid)
std::string get_ps3_function_name(u64 fid)
{
// check syscalls
switch (~fid)

View File

@ -112,18 +112,18 @@ ModuleFunc* get_ppu_func_by_index(u32 index)
return &g_ppu_func_list[index];
}
void execute_ppu_func_by_index(PPUThread& CPU, u32 index)
void execute_ppu_func_by_index(PPUThread& ppu, u32 index)
{
if (auto func = get_ppu_func_by_index(index))
{
// save RTOC if necessary
if (index & EIF_SAVE_RTOC)
{
vm::write64(VM_CAST(CPU.GPR[1] + 0x28), CPU.GPR[2]);
vm::write64(VM_CAST(ppu.GPR[1] + 0x28), ppu.GPR[2]);
}
// save old syscall/NID value
const auto last_code = CPU.hle_code;
const auto last_code = ppu.hle_code;
// branch directly to the LLE function
if (index & EIF_USE_BRANCH)
@ -132,39 +132,39 @@ void execute_ppu_func_by_index(PPUThread& CPU, u32 index)
if (last_code)
{
throw EXCEPTION("This function cannot be called from the callback: %s (0x%llx)", SysCalls::GetFuncName(func->id), func->id);
throw EXCEPTION("This function cannot be called from the callback: %s (0x%llx)", get_ps3_function_name(func->id), func->id);
}
if (!func->lle_func)
{
throw EXCEPTION("LLE function not set: %s (0x%llx)", SysCalls::GetFuncName(func->id), func->id);
throw EXCEPTION("LLE function not set: %s (0x%llx)", get_ps3_function_name(func->id), func->id);
}
if (func->flags & MFF_FORCED_HLE)
{
throw EXCEPTION("Forced HLE enabled: %s (0x%llx)", SysCalls::GetFuncName(func->id), func->id);
throw EXCEPTION("Forced HLE enabled: %s (0x%llx)", get_ps3_function_name(func->id), func->id);
}
if (Ini.HLELogging.GetValue())
{
LOG_NOTICE(HLE, "Branch to LLE function: %s (0x%llx)", SysCalls::GetFuncName(func->id), func->id);
LOG_NOTICE(HLE, "Branch to LLE function: %s (0x%llx)", get_ps3_function_name(func->id), func->id);
}
if (index & EIF_PERFORM_BLR)
{
throw EXCEPTION("TODO: Branch with link: %s (0x%llx)", SysCalls::GetFuncName(func->id), func->id);
throw EXCEPTION("TODO: Branch with link: %s (0x%llx)", get_ps3_function_name(func->id), func->id);
// CPU.LR = CPU.PC + 4;
}
const auto data = vm::get_ptr<be_t<u32>>(func->lle_func.addr());
CPU.PC = data[0] - 4;
CPU.GPR[2] = data[1]; // set rtoc
ppu.PC = data[0] - 4;
ppu.GPR[2] = data[1]; // set rtoc
return;
}
// change current syscall/NID value
CPU.hle_code = func->id;
ppu.hle_code = func->id;
if (func->lle_func && !(func->flags & MFF_FORCED_HLE))
{
@ -176,49 +176,49 @@ void execute_ppu_func_by_index(PPUThread& CPU, u32 index)
if (Ini.HLELogging.GetValue())
{
LOG_NOTICE(HLE, "LLE function called: %s", SysCalls::GetFuncName(func->id));
LOG_NOTICE(HLE, "LLE function called: %s", get_ps3_function_name(func->id));
}
CPU.fast_call(pc, rtoc);
ppu.fast_call(pc, rtoc);
if (Ini.HLELogging.GetValue())
{
LOG_NOTICE(HLE, "LLE function finished: %s -> 0x%llx", SysCalls::GetFuncName(func->id), CPU.GPR[3]);
LOG_NOTICE(HLE, "LLE function finished: %s -> 0x%llx", get_ps3_function_name(func->id), ppu.GPR[3]);
}
}
else if (func->func)
{
if (Ini.HLELogging.GetValue())
{
LOG_NOTICE(HLE, "HLE function called: %s", SysCalls::GetFuncName(func->id));
LOG_NOTICE(HLE, "HLE function called: %s", get_ps3_function_name(func->id));
}
func->func(CPU);
func->func(ppu);
if (Ini.HLELogging.GetValue())
{
LOG_NOTICE(HLE, "HLE function finished: %s -> 0x%llx", SysCalls::GetFuncName(func->id), CPU.GPR[3]);
LOG_NOTICE(HLE, "HLE function finished: %s -> 0x%llx", get_ps3_function_name(func->id), ppu.GPR[3]);
}
}
else
{
LOG_ERROR(HLE, "Unimplemented function: %s -> CELL_OK", SysCalls::GetFuncName(func->id));
CPU.GPR[3] = 0;
LOG_ERROR(HLE, "Unimplemented function: %s -> CELL_OK", get_ps3_function_name(func->id));
ppu.GPR[3] = 0;
}
if (index & EIF_PERFORM_BLR)
{
// return if necessary
CPU.PC = VM_CAST(CPU.LR & ~3) - 4;
ppu.PC = VM_CAST(ppu.LR & ~3) - 4;
}
// execute module-specific error check
if ((s64)CPU.GPR[3] < 0 && func->module && func->module->on_error)
if ((s64)ppu.GPR[3] < 0 && func->module && func->module->on_error)
{
func->module->on_error(CPU.GPR[3], func);
func->module->on_error(ppu.GPR[3], func);
}
CPU.hle_code = last_code;
ppu.hle_code = last_code;
}
else
{

View File

@ -9,23 +9,6 @@ namespace vm { using namespace ps3; }
template<typename T = void> class Module;
// flags set in ModuleFunc
enum : u32
{
MFF_FORCED_HLE = (1 << 0), // always call HLE function
MFF_NO_RETURN = (1 << 1), // uses EIF_USE_BRANCH flag with LLE, ignored with MFF_FORCED_HLE
};
// flags passed with index
enum : u32
{
EIF_SAVE_RTOC = (1 << 25), // save RTOC in [SP+0x28] before calling HLE/LLE function
EIF_PERFORM_BLR = (1 << 24), // do BLR after calling HLE/LLE function
EIF_USE_BRANCH = (1 << 23), // do only branch, LLE must be set, last_syscall must be zero
EIF_FLAGS = 0x3800000, // all flags
};
struct ModuleFunc
{
u32 id;
@ -153,7 +136,8 @@ void add_variable(u32 nid, Module<>* module, const char* name, u32(*addr)());
ModuleFunc* get_ppu_func_by_nid(u32 nid, u32* out_index = nullptr);
ModuleFunc* get_ppu_func_by_index(u32 index);
ModuleVariable* get_variable_by_nid(u32 nid);
void execute_ppu_func_by_index(PPUThread& CPU, u32 id);
void execute_ppu_func_by_index(PPUThread& ppu, u32 id);
extern std::string get_ps3_function_name(u64 fid);
void clear_ppu_functions();
u32 get_function_id(const char* name);

View File

@ -37,7 +37,7 @@
void null_func(PPUThread& ppu)
{
const u64 code = ppu.GPR[11];
LOG_ERROR(HLE, "Unimplemented syscall %lld: %s -> CELL_OK", code, SysCalls::GetFuncName(~code));
LOG_ERROR(HLE, "Unimplemented syscall %lld: %s -> CELL_OK", code, get_ps3_function_name(~code));
ppu.GPR[3] = 0;
}
@ -891,27 +891,27 @@ const ppu_func_caller g_sc_table[1024] =
null_func, null_func, null_func, BIND_FUNC(cellGcmCallback), //1023 UNS
};
void SysCalls::DoSyscall(PPUThread& CPU, u64 code)
void execute_syscall_by_index(PPUThread& ppu, u64 code)
{
if (code >= 1024)
{
throw EXCEPTION("Invalid syscall number (0x%llx)", code);
}
auto last_code = CPU.hle_code;
CPU.hle_code = ~code;
auto last_code = ppu.hle_code;
ppu.hle_code = ~code;
if (Ini.HLELogging.GetValue())
{
LOG_NOTICE(PPU, "Syscall %lld called: %s", code, SysCalls::GetFuncName(~code));
LOG_NOTICE(PPU, "Syscall %lld called: %s", code, get_ps3_function_name(~code));
}
g_sc_table[code](CPU);
g_sc_table[code](ppu);
if (Ini.HLELogging.GetValue())
{
LOG_NOTICE(PPU, "Syscall %lld finished: %s -> 0x%llx", code, SysCalls::GetFuncName(~code), CPU.GPR[3]);
LOG_NOTICE(PPU, "Syscall %lld finished: %s -> 0x%llx", code, get_ps3_function_name(~code), ppu.GPR[3]);
}
CPU.hle_code = last_code;
ppu.hle_code = last_code;
}

View File

@ -19,11 +19,5 @@ public:
}
};
class PPUThread;
class SysCalls
{
public:
static void DoSyscall(PPUThread& CPU, u64 code);
static std::string GetFuncName(const u64 fid);
};
void execute_syscall_by_index(class PPUThread& ppu, u64 code);
std::string get_ps3_function_name(u64 fid);

View File

@ -83,7 +83,7 @@ s32 prx_load_module(std::string path, u64 flags, vm::ptr<sys_prx_load_module_opt
if (!vm::check_addr(addr, 8) || !vm::check_addr(i_addr = vm::read32(addr), 4))
{
sys_prx.Error("Failed to inject code for exported function '%s' (opd=0x%x, 0x%x)", SysCalls::GetFuncName(nid), addr, i_addr);
sys_prx.Error("Failed to inject code for exported function '%s' (opd=0x%x, 0x%x)", get_ps3_function_name(nid), addr, i_addr);
}
else
{
@ -104,7 +104,7 @@ s32 prx_load_module(std::string path, u64 flags, vm::ptr<sys_prx_load_module_opt
if (!func)
{
sys_prx.Error("Unknown function '%s' in '%s' module (0x%x)", SysCalls::GetFuncName(nid), module_.first);
sys_prx.Error("Unknown function '%s' in '%s' module (0x%x)", get_ps3_function_name(nid), module_.first);
index = add_ppu_func(ModuleFunc(nid, 0, module, nullptr, nullptr));
}
@ -112,7 +112,7 @@ s32 prx_load_module(std::string path, u64 flags, vm::ptr<sys_prx_load_module_opt
{
const bool is_lle = func->lle_func && !(func->flags & MFF_FORCED_HLE);
sys_prx.Error("Imported %sfunction '%s' in '%s' module (0x%x)", (is_lle ? "LLE " : ""), SysCalls::GetFuncName(nid), module_.first, addr);
sys_prx.Error("Imported %sfunction '%s' in '%s' module (0x%x)", (is_lle ? "LLE " : ""), get_ps3_function_name(nid), module_.first, addr);
}
if (!patch_ppu_import(addr, index))

View File

@ -167,8 +167,8 @@ namespace loader
module.exports[fnid] = fstub;
//LOG_NOTICE(LOADER, "Exported function '%s' in '%s' module (LLE)", SysCalls::GetFuncName(fnid).c_str(), module_name.c_str());
LOG_WARNING(LOADER, "**** %s: [%s] -> 0x%x", modulename.c_str(), SysCalls::GetFuncName(fnid).c_str(), (u32)fstub);
//LOG_NOTICE(LOADER, "Exported function '%s' in '%s' module (LLE)", get_ps3_function_name(fnid), module_name);
LOG_WARNING(LOADER, "**** %s: [%s] -> 0x%x", modulename, get_ps3_function_name(fnid), (u32)fstub);
}
}
@ -204,7 +204,7 @@ namespace loader
module.imports[fnid] = fstub;
LOG_WARNING(LOADER, "**** %s: [%s] -> 0x%x", modulename.c_str(), SysCalls::GetFuncName(fnid).c_str(), (u32)fstub);
LOG_WARNING(LOADER, "**** %s: [%s] -> 0x%x", modulename, get_ps3_function_name(fnid), (u32)fstub);
}
}
}
@ -449,7 +449,7 @@ namespace loader
if (!vm::check_addr(addr, 8) || !vm::check_addr(i_addr = vm::read32(addr), 4))
{
LOG_ERROR(LOADER, "Failed to inject code for exported function '%s' (opd=0x%x, 0x%x)", SysCalls::GetFuncName(nid), addr, i_addr);
LOG_ERROR(LOADER, "Failed to inject code for exported function '%s' (opd=0x%x, 0x%x)", get_ps3_function_name(nid), addr, i_addr);
}
else
{
@ -470,18 +470,18 @@ namespace loader
if (!func)
{
LOG_ERROR(LOADER, "Unknown function '%s' (0x%x)", SysCalls::GetFuncName(nid), addr);
LOG_ERROR(LOADER, "Unknown function '%s' (0x%x)", get_ps3_function_name(nid), addr);
index = add_ppu_func(ModuleFunc(nid, 0, module, nullptr, nullptr));
}
else
{
LOG_NOTICE(LOADER, "Imported function '%s' (0x%x)", SysCalls::GetFuncName(nid), addr);
LOG_NOTICE(LOADER, "Imported function '%s' (0x%x)", get_ps3_function_name(nid), addr);
}
if (!patch_ppu_import(addr, index))
{
LOG_ERROR(LOADER, "Failed to inject code for function '%s' (0x%x)", SysCalls::GetFuncName(nid), addr);
LOG_ERROR(LOADER, "Failed to inject code for function '%s' (0x%x)", get_ps3_function_name(nid), addr);
}
}
}
@ -708,7 +708,7 @@ namespace loader
if (!func)
{
LOG_ERROR(LOADER, "Unknown function '%s' in '%s' module (0x%x)", SysCalls::GetFuncName(nid), module_name, addr);
LOG_ERROR(LOADER, "Unknown function '%s' in '%s' module (0x%x)", get_ps3_function_name(nid), module_name, addr);
index = add_ppu_func(ModuleFunc(nid, 0, module, nullptr, nullptr));
}
@ -716,7 +716,7 @@ namespace loader
{
const bool is_lle = func->lle_func && !(func->flags & MFF_FORCED_HLE);
LOG_NOTICE(LOADER, "Imported %sfunction '%s' in '%s' module (0x%x)", is_lle ? "LLE " : "", SysCalls::GetFuncName(nid), module_name, addr);
LOG_NOTICE(LOADER, "Imported %sfunction '%s' in '%s' module (0x%x)", is_lle ? "LLE " : "", get_ps3_function_name(nid), module_name, addr);
}
if (!patch_ppu_import(addr, index))