From a800d21a317412562b205e7243b9259d82927cce Mon Sep 17 00:00:00 2001 From: S Gopal Rajagopal Date: Tue, 10 Mar 2015 00:51:05 +0530 Subject: [PATCH] SPURS: Fix some bugs Conflicts: rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp --- rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp | 48 ++++++++++++++++----- rpcs3/Emu/SysCalls/Modules/cellSpursSpu.cpp | 27 +++++++----- rpcs3/Emu/SysCalls/lv2/sys_event.cpp | 7 --- rpcs3/Emu/SysCalls/lv2/sys_event.h | 2 - rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp | 7 --- rpcs3/Emu/SysCalls/lv2/sys_lwmutex.h | 3 -- rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp | 9 ---- rpcs3/Emu/SysCalls/lv2/sys_semaphore.h | 3 -- rpcs3/Emu/SysCalls/lv2/sys_spu.cpp | 7 --- rpcs3/Emu/SysCalls/lv2/sys_spu.h | 1 - 10 files changed, 53 insertions(+), 61 deletions(-) diff --git a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp index 42b980e53e..3478028406 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp @@ -295,6 +295,13 @@ s32 spursCreateLv2EventQueue(PPUThread& CPU, vm::ptr spurs, vm::ptr attr(CPU); + auto sys_event_queue_attribute_initialize = [](vm::ptr 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); @@ -954,9 +961,7 @@ s32 spursInit( vm::stackvar> sem(CPU); vm::stackvar semAttr(CPU); vm::stackvar lwCondAttr(CPU); - vm::stackvar lwCond(CPU); - vm::stackvar lwMutextAttr(CPU); - vm::stackvar lwMutex(CPU); + vm::stackvar lwMutexAttr(CPU); vm::stackvar> spuTgId(CPU); vm::stackvar spuTgName(CPU, 128); vm::stackvar spuTgAttr(CPU); @@ -1041,6 +1046,14 @@ s32 spursInit( spurs->wklInfoSysSrv.uniqueId.write_relaxed(0xff); + auto sys_semaphore_attribute_initialize = [](vm::ptr 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 @@ -1093,6 +1106,13 @@ s32 spursInit( spuTgName[spurs->prefixSize] = '\0'; strcat(spuTgName.get_ptr(), "CellSpursKernelGroup"); + auto sys_spu_thread_group_attribute_initialize = [](vm::ptr 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; @@ -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 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)) @@ -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::make(-1)); @@ -3638,7 +3664,7 @@ s32 cellSpursCreateTask(PPUThread& CPU, vm::ptr taskset, vm::p return rc; } - rc = spursTaskStart(CPU, taskset, tmpTaskId->value()); + rc = spursTaskStart(CPU, taskset, tmpTaskId.value()); if (rc != CELL_OK) { return rc; diff --git a/rpcs3/Emu/SysCalls/Modules/cellSpursSpu.cpp b/rpcs3/Emu/SysCalls/Modules/cellSpursSpu.cpp index c9a813d7b9..dc2816bb82 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpursSpu.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSpursSpu.cpp @@ -1115,19 +1115,24 @@ bool spursTasksetEntry(SPUThread & spu) { bool spursTasksetSyscallEntry(SPUThread & spu) { auto ctxt = vm::get_ptr(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]); + + // Resume the previously executing task if the syscall did not cause a context switch + if (spu.m_is_branch == false) { + spursTasksetResumeTask(spu); + } } - // 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); + catch (SpursModuleExit) { } return false; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_event.cpp b/rpcs3/Emu/SysCalls/lv2/sys_event.cpp index 394766b056..a278bbaccf 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_event.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_event.cpp @@ -13,13 +13,6 @@ SysCallBase sys_event("sys_event"); -void sys_event_queue_attribute_initialize(vm::ptr attr) -{ - attr->protocol = SYS_SYNC_PRIORITY; - attr->type = SYS_PPU_QUEUE; - attr->name[0] = '\0'; -} - s32 sys_event_queue_create(vm::ptr equeue_id, vm::ptr 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); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_event.h b/rpcs3/Emu/SysCalls/lv2/sys_event.h index 58fcb3c846..e20a6a15b3 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_event.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_event.h @@ -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 attr); - // SysCalls s32 sys_event_queue_create(vm::ptr equeue_id, vm::ptr attr, u64 event_queue_key, s32 size); s32 sys_event_queue_destroy(u32 equeue_id, s32 mode); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp index 7c192db208..3aff7e8203 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp @@ -12,13 +12,6 @@ SysCallBase sys_lwmutex("sys_lwmutex"); -void sys_lwmutex_attribute_initialize(vm::ptr attr) -{ - attr->protocol = SYS_SYNC_PRIORITY; - attr->recursive = SYS_SYNC_NOT_RECURSIVE; - attr->name[0] = '\0'; -} - s32 _sys_lwmutex_create(vm::ptr lwmutex_id, u32 protocol, vm::ptr 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); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.h b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.h index e07efe29c9..ed0bb82345 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.h @@ -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 attr); - // SysCalls s32 _sys_lwmutex_create(vm::ptr lwmutex_id, u32 protocol, vm::ptr control, u32 arg4, u64 name, u32 arg6); s32 _sys_lwmutex_destroy(u32 lwmutex_id); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp index eaf4210f33..26528daa6b 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp @@ -12,15 +12,6 @@ SysCallBase sys_semaphore("sys_semaphore"); -void sys_semaphore_attribute_initialize(vm::ptr 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 sem, vm::ptr 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); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.h b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.h index ccf9f6535b..25a0071cc0 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.h @@ -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 attr); - // SysCalls s32 sys_semaphore_create(vm::ptr sem, vm::ptr attr, s32 initial_val, s32 max_val); s32 sys_semaphore_destroy(u32 sem); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_spu.cpp b/rpcs3/Emu/SysCalls/lv2/sys_spu.cpp index b366b8191c..68e9ca41c5 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_spu.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_spu.cpp @@ -465,13 +465,6 @@ s32 sys_spu_thread_group_yield(u32 id) return CELL_OK; } -void sys_spu_thread_group_attribute_initialize(vm::ptr 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); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_spu.h b/rpcs3/Emu/SysCalls/lv2/sys_spu.h index 07a4da499f..876df65468 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_spu.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_spu.h @@ -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 img, const std::string& name, u32 option, u64 a1, u64 a2, u64 a3, u64 a4, std::function task = nullptr); -void sys_spu_thread_group_attribute_initialize(vm::ptr attr); // SysCalls s32 sys_spu_initialize(u32 max_usable_spu, u32 max_raw_spu);