rpcsx/rpcs3/Emu/Cell/SPURecompiler.cpp

80 lines
1.4 KiB
C++
Raw Normal View History

#include "stdafx.h"
#include "Emu/IdManager.h"
#include "Emu/Memory/Memory.h"
#include "SPUThread.h"
#include "SPURecompiler.h"
#include "SPUASMJITRecompiler.h"
extern u64 get_system_time();
2017-01-25 00:22:19 +01:00
spu_recompiler_base::~spu_recompiler_base()
{
}
2016-04-14 01:09:41 +02:00
void spu_recompiler_base::enter(SPUThread& spu)
{
2016-04-14 01:09:41 +02:00
if (spu.pc >= 0x40000 || spu.pc % 4)
{
fmt::throw_exception("Invalid PC: 0x%05x", spu.pc);
}
2016-04-14 01:09:41 +02:00
// Get SPU LS pointer
const auto _ls = vm::ps3::_ptr<u32>(spu.offset);
2016-04-14 01:09:41 +02:00
// Always validate (TODO)
const auto func = spu.spu_db->analyse(_ls, spu.pc);
2016-04-14 01:09:41 +02:00
// Reset callstack if necessary
2015-09-04 01:23:31 +02:00
if (func->does_reset_stack && spu.recursion_level)
{
spu.state += cpu_flag::ret;
2016-04-14 01:09:41 +02:00
return;
2015-09-04 01:23:31 +02:00
}
2015-09-04 01:23:31 +02:00
if (!func->compiled)
{
2016-04-14 01:09:41 +02:00
if (!spu.spu_rec)
{
spu.spu_rec = fxm::get_always<spu_recompiler>();
}
2016-04-14 01:09:41 +02:00
spu.spu_rec->compile(*func);
if (!func->compiled) fmt::throw_exception("Compilation failed" HERE);
}
2015-09-04 01:23:31 +02:00
const u32 res = func->compiled(&spu, _ls);
if (const auto exception = spu.pending_exception)
{
spu.pending_exception = nullptr;
std::rethrow_exception(exception);
}
if (res & 0x1000000)
{
spu.halt();
}
if (res & 0x2000000)
{
}
if (res & 0x4000000)
{
if (res & 0x8000000)
{
fmt::throw_exception("Invalid interrupt status set (0x%x)" HERE, res);
}
spu.set_interrupt_status(true);
}
else if (res & 0x8000000)
{
spu.set_interrupt_status(false);
}
spu.pc = res & 0x3fffc;
}