Implement HLE cellSpursAddUrgentCommand

This commit is contained in:
Eladash 2020-04-14 18:00:10 +03:00 committed by Ani
parent 17f7f329a8
commit 019d2d5dcf
2 changed files with 72 additions and 2 deletions

View File

@ -17,6 +17,11 @@
LOG_CHANNEL(cellSpurs);
extern u64 ppu_ldarx(ppu_thread&, u32);
extern u32 ppu_lwarx(ppu_thread&, u32);
extern bool ppu_stwcx(ppu_thread&, u32, u32);
extern bool ppu_stdcx(ppu_thread&, u32, u64);
error_code sys_spu_image_close(ppu_thread&, vm::ptr<sys_spu_image> img);
//----------------------------------------------------------------------------
@ -4087,9 +4092,60 @@ s32 cellSpursJobHeaderSetJobbin2Param()
return CELL_OK;
}
s32 cellSpursAddUrgentCommand()
s32 cellSpursAddUrgentCommand(ppu_thread& ppu, vm::ptr<CellSpursJobChain> jobChain, u64 newCmd)
{
UNIMPLEMENTED_FUNC(cellSpurs);
cellSpurs.trace("cellSpursAddUrgentCommand(jobChain=*0x%x, newCmd=0x%llx)", jobChain, newCmd);
if (!jobChain)
return CELL_SPURS_JOB_ERROR_NULL_POINTER;
if (!jobChain.aligned(128))
return CELL_SPURS_JOB_ERROR_ALIGN;
if (jobChain->workloadId >= 32)
return CELL_SPURS_JOB_ERROR_INVAL;
for (u32 i = 0;;)
{
if (i >= std::size(jobChain->urgentCmds))
{
// Exausted all slots
return CELL_SPURS_JOB_ERROR_BUSY;
}
u64 currCmd = ppu_ldarx(ppu, jobChain.ptr(&CellSpursJobChain::urgentCmds, i).addr());
std::atomic_thread_fence(std::memory_order_acq_rel);
bool found = false;
bool reset = false;
if (!currCmd)
{
if (i != 0 && !jobChain->urgentCmds[i - 1])
{
// Restart search, someone emptied out the previous one
reset = true;
}
else
{
found = true;
currCmd = newCmd;
}
}
if (reset || !ppu_stdcx(ppu, jobChain.ptr(&CellSpursJobChain::urgentCmds, i).addr(), currCmd))
{
// Someone modified the job chain or the previous slot is empty, restart search
i = 0;
continue;
}
if (found)
break;
i++;
}
return CELL_OK;
}

View File

@ -410,6 +410,20 @@ struct alignas(16) CellSpursTracePacket
CHECK_SIZE_ALIGN(CellSpursTracePacket, 16, 16);
struct alignas(128) CellSpursJobChain
{
u8 unk1[0x2C]; // 0x0
u8 val2C; // 0x2C
u8 val2D; // 0x2D
u8 val2E; // 0x2E
u8 val2F; // 0x2F
atomic_be_t<u64> urgentCmds[4]; // 0x30
u8 unk2[0x24]; // 0x50
be_t<u32> workloadId; // 0x74
vm::bptr<CellSpurs> spurs; // 0x78
u8 unk3[0x94]; // 0x7C
};
// Core CellSpurs structures
struct alignas(128) CellSpurs
{