Skip to content

Commit

Permalink
SPURS: Fix some bugs
Browse files Browse the repository at this point in the history
Conflicts:
	rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp
  • Loading branch information
gopalsr83 authored and Nekotekina committed Jul 10, 2015
1 parent fe67504 commit a800d21
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 61 deletions.
48 changes: 37 additions & 11 deletions rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ s32 spursCreateLv2EventQueue(PPUThread& CPU, vm::ptr<CellSpurs> spurs, vm::ptr<u
{
vm::stackvar<sys_event_queue_attr> attr(CPU);

auto sys_event_queue_attribute_initialize = [](vm::ptr<sys_event_queue_attr> attr)
{
attr->protocol = SYS_SYNC_PRIORITY;
attr->type = SYS_PPU_QUEUE;
attr->name[0] = '\0';
};

sys_event_queue_attribute_initialize(attr);
memcpy(attr->name, name.get_ptr(), sizeof(attr->name));
auto rc = sys_event_queue_create(queueId, attr, SYS_EVENT_QUEUE_LOCAL, size);
Expand Down Expand Up @@ -954,9 +961,7 @@ s32 spursInit(
vm::stackvar<be_t<u32>> sem(CPU);
vm::stackvar<sys_semaphore_attribute_t> semAttr(CPU);
vm::stackvar<sys_lwcond_attribute_t> lwCondAttr(CPU);
vm::stackvar<sys_lwcond_t> lwCond(CPU);
vm::stackvar<sys_lwmutex_attribute_t> lwMutextAttr(CPU);
vm::stackvar<sys_lwmutex_t> lwMutex(CPU);
vm::stackvar<sys_lwmutex_attribute_t> lwMutexAttr(CPU);
vm::stackvar<be_t<u32>> spuTgId(CPU);
vm::stackvar<char> spuTgName(CPU, 128);
vm::stackvar<sys_spu_thread_group_attribute> spuTgAttr(CPU);
Expand Down Expand Up @@ -1041,6 +1046,14 @@ s32 spursInit(
spurs->wklInfoSysSrv.uniqueId.write_relaxed(0xff);


auto sys_semaphore_attribute_initialize = [](vm::ptr<sys_semaphore_attribute_t> attr)
{
attr->protocol = SYS_SYNC_PRIORITY;
attr->pshared = SYS_SYNC_NOT_PROCESS_SHARED;
attr->ipc_key = 0;
attr->flags = 0;
attr->name[0] = '\0';
};

// Create semaphores for each workload
// TODO: Find out why these semaphores are needed
Expand Down Expand Up @@ -1093,6 +1106,13 @@ s32 spursInit(
spuTgName[spurs->prefixSize] = '\0';
strcat(spuTgName.get_ptr(), "CellSpursKernelGroup");

auto sys_spu_thread_group_attribute_initialize = [](vm::ptr<sys_spu_thread_group_attribute> attr)
{
attr->name = vm::null;
attr->nsize = 0;
attr->type = SYS_SPU_THREAD_GROUP_TYPE_NORMAL;
};

sys_spu_thread_group_attribute_initialize(spuTgAttr);
spuTgAttr->name = spuTgName;
spuTgAttr->nsize = (u32)strlen(spuTgAttr->name.get_ptr()) + 1;
Expand Down Expand Up @@ -1173,17 +1193,25 @@ s32 spursInit(
}
}

const auto lwMutex = spurs.of(&CellSpurs::mutex);
const auto lwCond = spurs.of(&CellSpurs::cond);

auto sys_lwmutex_attribute_initialize = [](vm::ptr<sys_lwmutex_attribute_t> attr)
{
attr->protocol = SYS_SYNC_PRIORITY;
attr->recursive = SYS_SYNC_NOT_RECURSIVE;
attr->name[0] = '\0';
};

// Create a mutex to protect access to SPURS handler thread data
sys_lwmutex_attribute_initialize(lwMutextAttr);
memcpy(lwMutextAttr->name, "_spuPrv", 8);
if (s32 rc = sys_lwmutex_create(lwMutex, lwMutextAttr))
sys_lwmutex_attribute_initialize(lwMutexAttr);
memcpy(lwMutexAttr->name, "_spuPrv", 8);
if (s32 rc = sys_lwmutex_create(lwMutex, lwMutexAttr))
{
spursFinalizeSpu(spurs);
return rollback(), rc;
}

spurs->mutex = lwMutex.value();

// Create condition variable to signal the SPURS handler thread
memcpy(lwCondAttr->name, "_spuPrv", 8);
if (s32 rc = sys_lwcond_create(lwCond, lwMutex, lwCondAttr))
Expand All @@ -1193,8 +1221,6 @@ s32 spursInit(
return rollback(), rc;
}

spurs->cond = lwCond;

spurs->flags1 = (flags & SAF_EXIT_IF_NO_WORK ? SF1_EXIT_IF_NO_WORK : 0) | (isSecond ? SF1_32_WORKLOADS : 0);
spurs->wklFlagReceiver.write_relaxed(0xff);
spurs->wklFlag.flag.write_relaxed(be_t<u32>::make(-1));
Expand Down Expand Up @@ -3638,7 +3664,7 @@ s32 cellSpursCreateTask(PPUThread& CPU, vm::ptr<CellSpursTaskset> taskset, vm::p
return rc;
}

rc = spursTaskStart(CPU, taskset, tmpTaskId->value());
rc = spursTaskStart(CPU, taskset, tmpTaskId.value());
if (rc != CELL_OK)
{
return rc;
Expand Down
27 changes: 16 additions & 11 deletions rpcs3/Emu/SysCalls/Modules/cellSpursSpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,19 +1115,24 @@ bool spursTasksetEntry(SPUThread & spu) {
bool spursTasksetSyscallEntry(SPUThread & spu) {
auto ctxt = vm::get_ptr<SpursTasksetContext>(spu.offset + 0x2700);

// Save task context
ctxt->savedContextLr = spu.GPR[0];
ctxt->savedContextSp = spu.GPR[1];
for (auto i = 0; i < 48; i++) {
ctxt->savedContextR80ToR127[i] = spu.GPR[80 + i];
}
try {
// Save task context
ctxt->savedContextLr = spu.GPR[0];
ctxt->savedContextSp = spu.GPR[1];
for (auto i = 0; i < 48; i++) {
ctxt->savedContextR80ToR127[i] = spu.GPR[80 + i];
}

// Handle the syscall
spu.GPR[3]._u32[3] = spursTasksetProcessSyscall(spu, spu.GPR[3]._u32[3], spu.GPR[4]._u32[3]);
// Handle the syscall
spu.GPR[3]._u32[3] = spursTasksetProcessSyscall(spu, spu.GPR[3]._u32[3], spu.GPR[4]._u32[3]);

// Resume the previously executing task if the syscall did not cause a context switch
if (spu.m_is_branch == false) {
spursTasksetResumeTask(spu);
// Resume the previously executing task if the syscall did not cause a context switch
if (spu.m_is_branch == false) {
spursTasksetResumeTask(spu);
}
}

catch (SpursModuleExit) {
}

return false;
Expand Down
7 changes: 0 additions & 7 deletions rpcs3/Emu/SysCalls/lv2/sys_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@

SysCallBase sys_event("sys_event");

void sys_event_queue_attribute_initialize(vm::ptr<sys_event_queue_attr> attr)
{
attr->protocol = SYS_SYNC_PRIORITY;
attr->type = SYS_PPU_QUEUE;
attr->name[0] = '\0';
}

s32 sys_event_queue_create(vm::ptr<u32> equeue_id, vm::ptr<sys_event_queue_attr> attr, u64 event_queue_key, s32 size)
{
sys_event.Warning("sys_event_queue_create(equeue_id=*0x%x, attr=*0x%x, event_queue_key=0x%llx, size=%d)", equeue_id, attr, event_queue_key, size);
Expand Down
2 changes: 0 additions & 2 deletions rpcs3/Emu/SysCalls/lv2/sys_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ REG_ID_TYPE(lv2_event_port_t, 0x0E); // SYS_EVENT_PORT_OBJECT

class PPUThread;

void sys_event_queue_attribute_initialize(vm::ptr<sys_event_queue_attr> attr);

// SysCalls
s32 sys_event_queue_create(vm::ptr<u32> equeue_id, vm::ptr<sys_event_queue_attr> attr, u64 event_queue_key, s32 size);
s32 sys_event_queue_destroy(u32 equeue_id, s32 mode);
Expand Down
7 changes: 0 additions & 7 deletions rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@

SysCallBase sys_lwmutex("sys_lwmutex");

void sys_lwmutex_attribute_initialize(vm::ptr<sys_lwmutex_attribute_t> attr)
{
attr->protocol = SYS_SYNC_PRIORITY;
attr->recursive = SYS_SYNC_NOT_RECURSIVE;
attr->name[0] = '\0';
}

s32 _sys_lwmutex_create(vm::ptr<u32> lwmutex_id, u32 protocol, vm::ptr<sys_lwmutex_t> control, u32 arg4, u64 name, u32 arg6)
{
sys_lwmutex.Warning("_sys_lwmutex_create(lwmutex_id=*0x%x, protocol=0x%x, control=*0x%x, arg4=0x%x, name=0x%llx, arg6=0x%x)", lwmutex_id, protocol, control, arg4, name, arg6);
Expand Down
3 changes: 0 additions & 3 deletions rpcs3/Emu/SysCalls/lv2/sys_lwmutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ struct lv2_lwmutex_t

REG_ID_TYPE(lv2_lwmutex_t, 0x95); // SYS_LWMUTEX_OBJECT

// Aux
void sys_lwmutex_attribute_initialize(vm::ptr<sys_lwmutex_attribute_t> attr);

// SysCalls
s32 _sys_lwmutex_create(vm::ptr<u32> lwmutex_id, u32 protocol, vm::ptr<sys_lwmutex_t> control, u32 arg4, u64 name, u32 arg6);
s32 _sys_lwmutex_destroy(u32 lwmutex_id);
Expand Down
9 changes: 0 additions & 9 deletions rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@

SysCallBase sys_semaphore("sys_semaphore");

void sys_semaphore_attribute_initialize(vm::ptr<sys_semaphore_attribute_t> attr)
{
attr->protocol = SYS_SYNC_PRIORITY;
attr->pshared = SYS_SYNC_NOT_PROCESS_SHARED;
attr->ipc_key = 0;
attr->flags = 0;
attr->name[0] = '\0';
}

s32 sys_semaphore_create(vm::ptr<u32> sem, vm::ptr<sys_semaphore_attribute_t> attr, s32 initial_val, s32 max_val)
{
sys_semaphore.Warning("sys_semaphore_create(sem=*0x%x, attr=*0x%x, initial_val=%d, max_val=%d)", sem, attr, initial_val, max_val);
Expand Down
3 changes: 0 additions & 3 deletions rpcs3/Emu/SysCalls/lv2/sys_semaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ struct lv2_sema_t

REG_ID_TYPE(lv2_sema_t, 0x96); // SYS_SEMAPHORE_OBJECT

// Aux
void sys_semaphore_attribute_initialize(vm::ptr<sys_semaphore_attribute_t> attr);

// SysCalls
s32 sys_semaphore_create(vm::ptr<u32> sem, vm::ptr<sys_semaphore_attribute_t> attr, s32 initial_val, s32 max_val);
s32 sys_semaphore_destroy(u32 sem);
Expand Down
7 changes: 0 additions & 7 deletions rpcs3/Emu/SysCalls/lv2/sys_spu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,6 @@ s32 sys_spu_thread_group_yield(u32 id)
return CELL_OK;
}

void sys_spu_thread_group_attribute_initialize(vm::ptr<sys_spu_thread_group_attribute> attr)
{
attr->name = vm::null;
attr->nsize = 0;
attr->type = SYS_SPU_THREAD_GROUP_TYPE_NORMAL;
}

s32 sys_spu_thread_group_terminate(u32 id, s32 value)
{
sys_spu.Warning("sys_spu_thread_group_terminate(id=0x%x, value=0x%x)", id, value);
Expand Down
1 change: 0 additions & 1 deletion rpcs3/Emu/SysCalls/lv2/sys_spu.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ u32 LoadSpuImage(vfsStream& stream, u32& spu_ep);
s32 spu_image_import(sys_spu_image& img, u32 src, u32 type);
u32 spu_thread_group_create(const std::string& name, u32 num, s32 prio, s32 type, u32 container);
u32 spu_thread_initialize(u32 group, u32 spu_num, vm::ptr<sys_spu_image> img, const std::string& name, u32 option, u64 a1, u64 a2, u64 a3, u64 a4, std::function<void(SPUThread&)> task = nullptr);
void sys_spu_thread_group_attribute_initialize(vm::ptr<sys_spu_thread_group_attribute> attr);

// SysCalls
s32 sys_spu_initialize(u32 max_usable_spu, u32 max_raw_spu);
Expand Down

0 comments on commit a800d21

Please sign in to comment.