2015-08-26 04:54:06 +02:00
|
|
|
#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)
|
2015-08-26 04:54:06 +02:00
|
|
|
{
|
2016-04-14 01:09:41 +02:00
|
|
|
if (spu.pc >= 0x40000 || spu.pc % 4)
|
2015-08-26 04:54:06 +02:00
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Invalid PC: 0x%05x", spu.pc);
|
2015-08-26 04:54:06 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-14 01:09:41 +02:00
|
|
|
// Get SPU LS pointer
|
2015-09-26 22:46:04 +02:00
|
|
|
const auto _ls = vm::ps3::_ptr<u32>(spu.offset);
|
2015-08-26 04:54:06 +02:00
|
|
|
|
2016-04-14 01:09:41 +02:00
|
|
|
// Always validate (TODO)
|
|
|
|
|
const auto func = spu.spu_db->analyse(_ls, spu.pc);
|
2015-08-26 04:54:06 +02:00
|
|
|
|
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)
|
2015-08-26 04:54:06 +02:00
|
|
|
{
|
2016-08-09 16:14:41 +02:00
|
|
|
spu.state += cpu_flag::ret;
|
2016-04-14 01:09:41 +02:00
|
|
|
return;
|
2015-09-04 01:23:31 +02:00
|
|
|
}
|
2015-08-26 04:54:06 +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>();
|
|
|
|
|
}
|
2015-08-26 04:54:06 +02:00
|
|
|
|
2016-04-14 01:09:41 +02:00
|
|
|
spu.spu_rec->compile(*func);
|
|
|
|
|
|
2016-08-08 18:01:06 +02:00
|
|
|
if (!func->compiled) fmt::throw_exception("Compilation failed" HERE);
|
2015-08-26 04:54:06 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-04 01:23:31 +02:00
|
|
|
const u32 res = func->compiled(&spu, _ls);
|
2015-08-26 04:54:06 +02:00
|
|
|
|
|
|
|
|
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-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Invalid interrupt status set (0x%x)" HERE, res);
|
2015-08-26 04:54:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spu.set_interrupt_status(true);
|
|
|
|
|
}
|
|
|
|
|
else if (res & 0x8000000)
|
|
|
|
|
{
|
|
|
|
|
spu.set_interrupt_status(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spu.pc = res & 0x3fffc;
|
|
|
|
|
}
|