rpcsx/rpcs3/Emu/Cell/SPURecompiler.cpp

76 lines
1.3 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();
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)
{
2016-04-14 01:09:41 +02:00
throw fmt::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)
{
2016-04-14 01:09:41 +02:00
spu.state += cpu_state::ret;
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) throw std::runtime_error("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)
{
2016-04-14 01:09:41 +02:00
throw std::logic_error("Invalid interrupt status set" HERE);
}
spu.set_interrupt_status(true);
}
else if (res & 0x8000000)
{
spu.set_interrupt_status(false);
}
spu.pc = res & 0x3fffc;
}