From 40f5f73658a2e4ad388884feacfdf9f963aed359 Mon Sep 17 00:00:00 2001 From: S Gopal Rajagopal Date: Sun, 14 Dec 2014 00:22:31 +0530 Subject: [PATCH] SPURS: Implement some taskset functions --- rpcs3/Emu/Memory/vm_ptr.h | 4 +- rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp | 91 ++++++++++++++++++++---- rpcs3/Emu/SysCalls/Modules/cellSpurs.h | 81 ++++++++++++++++++--- rpcs3/emucore.vcxproj | 5 ++ 4 files changed, 156 insertions(+), 25 deletions(-) diff --git a/rpcs3/Emu/Memory/vm_ptr.h b/rpcs3/Emu/Memory/vm_ptr.h index 838caf930c..6f0c65ed0d 100644 --- a/rpcs3/Emu/Memory/vm_ptr.h +++ b/rpcs3/Emu/Memory/vm_ptr.h @@ -253,7 +253,7 @@ namespace vm void* get_ptr() const { - return vm::get_ptr(m_addr); + return vm::get_ptr((u32)m_addr); } explicit operator void*() const @@ -313,7 +313,7 @@ namespace vm const void* get_ptr() const { - return vm::get_ptr(m_addr); + return vm::get_ptr((u32)m_addr); } explicit operator const void*() const diff --git a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp index aebf52dbf8..831748949b 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp @@ -2309,7 +2309,7 @@ s64 spursCreateTaskset(vm::ptr spurs, vm::ptr tasks return CELL_SPURS_TASK_ERROR_ALIGN; } - memset((void *)taskset.addr(), 0, size); + memset(taskset.get_ptr(), 0, size); taskset->m.spurs = spurs; taskset->m.args = args; @@ -2406,13 +2406,28 @@ s64 cellSpursJoinTaskset(vm::ptr taskset) #endif } -s64 cellSpursGetTasksetId(vm::ptr taskset, vm::ptr workloadId) +s64 cellSpursGetTasksetId(vm::ptr taskset, vm::ptr wid) { #ifdef PRX_DEBUG cellSpurs->Warning("cellSpursGetTasksetId(taskset_addr=0x%x, workloadId_addr=0x%x)", taskset.addr(), workloadId.addr()); return GetCurrentPPUThread().FastCall2(libsre + 0x14EA0, libsre_rtoc); #else - UNIMPLEMENTED_FUNC(cellSpurs); + if (!taskset || !wid) + { + return CELL_SPURS_TASK_ERROR_NULL_POINTER; + } + + if (taskset.addr() % CellSpursTaskset::align) + { + return CELL_SPURS_TASK_ERROR_ALIGN; + } + + if (taskset->m.wid >= CELL_SPURS_MAX_WORKLOAD) + { + return CELL_SPURS_TASK_ERROR_INVAL; + } + + *wid = taskset->m.wid.ToBE(); return CELL_OK; #endif } @@ -2777,29 +2792,66 @@ s64 cellSpursCreateTask2WithBinInfo() #endif } -s64 cellSpursTasksetSetExceptionEventHandler() +s64 cellSpursTasksetSetExceptionEventHandler(vm::ptr taskset, vm::ptr handler, vm::ptr arg) { #ifdef PRX_DEBUG cellSpurs->Warning("%s()", __FUNCTION__); return GetCurrentPPUThread().FastCall2(libsre + 0x13124, libsre_rtoc); #else - UNIMPLEMENTED_FUNC(cellSpurs); + if (!taskset || !handler) + { + return CELL_SPURS_TASK_ERROR_NULL_POINTER; + } + + if (taskset.addr() % CellSpursTaskset::align) + { + return CELL_SPURS_TASK_ERROR_ALIGN; + } + + if (taskset->m.wid >= CELL_SPURS_MAX_WORKLOAD) + { + return CELL_SPURS_TASK_ERROR_INVAL; + } + + if (taskset->m.exception_handler != 0) + { + return CELL_SPURS_TASK_ERROR_BUSY; + } + + taskset->m.exception_handler = handler; + taskset->m.exception_handler_arg = arg; return CELL_OK; #endif } -s64 cellSpursTasksetUnsetExceptionEventHandler() +s64 cellSpursTasksetUnsetExceptionEventHandler(vm::ptr taskset) { #ifdef PRX_DEBUG cellSpurs->Warning("%s()", __FUNCTION__); return GetCurrentPPUThread().FastCall2(libsre + 0x13194, libsre_rtoc); #else - UNIMPLEMENTED_FUNC(cellSpurs); + if (!taskset) + { + return CELL_SPURS_TASK_ERROR_NULL_POINTER; + } + + if (taskset.addr() % CellSpursTaskset::align) + { + return CELL_SPURS_TASK_ERROR_ALIGN; + } + + if (taskset->m.wid >= CELL_SPURS_MAX_WORKLOAD) + { + return CELL_SPURS_TASK_ERROR_INVAL; + } + + taskset->m.exception_handler.set(0); + taskset->m.exception_handler_arg.set(0); return CELL_OK; #endif } -s64 cellSpursLookUpTasksetAddress(vm::ptr spurs, vm::ptr taskset, u32 id) +s64 cellSpursLookUpTasksetAddress(vm::ptr spurs, vm::ptr taskset, u32 id) { #ifdef PRX_DEBUG cellSpurs->Warning("%s()", __FUNCTION__); @@ -2810,13 +2862,28 @@ s64 cellSpursLookUpTasksetAddress(vm::ptr spurs, vm::ptr taskset, vm::ptr spurs) +s64 cellSpursTasksetGetSpursAddress(vm::ptr taskset, vm::ptr spurs) { #ifdef PRX_DEBUG cellSpurs->Warning("%s()", __FUNCTION__); return GetCurrentPPUThread().FastCall2(libsre + 0x14408, libsre_rtoc); #else - UNIMPLEMENTED_FUNC(cellSpurs); + if (!taskset || !spurs) + { + return CELL_SPURS_TASK_ERROR_NULL_POINTER; + } + + if (taskset.addr() % CellSpursTaskset::align) + { + return CELL_SPURS_TASK_ERROR_ALIGN; + } + + if (taskset->m.wid >= CELL_SPURS_MAX_WORKLOAD) + { + return CELL_SPURS_TASK_ERROR_INVAL; + } + + *spurs = (u32)taskset->m.spurs.addr().ToBE(); return CELL_OK; #endif } @@ -3092,6 +3159,8 @@ void cellSpurs_init(Module *pxThis) REG_FUNC(cellSpurs, cellSpursEnableExceptionEventHandler); REG_FUNC(cellSpurs, cellSpursSetGlobalExceptionEventHandler); REG_FUNC(cellSpurs, cellSpursUnsetGlobalExceptionEventHandler); + REG_FUNC(cellSpurs, cellSpursSetExceptionEventHandler); + REG_FUNC(cellSpurs, cellSpursUnsetExceptionEventHandler); // Event flag REG_FUNC(cellSpurs, _cellSpursEventFlagInitialize); @@ -3137,8 +3206,6 @@ void cellSpurs_init(Module *pxThis) REG_FUNC(cellSpurs, cellSpursCreateTask2WithBinInfo); REG_FUNC(cellSpurs, cellSpursLookUpTasksetAddress); REG_FUNC(cellSpurs, cellSpursTasksetGetSpursAddress); - REG_FUNC(cellSpurs, cellSpursSetExceptionEventHandler); - REG_FUNC(cellSpurs, cellSpursUnsetExceptionEventHandler); REG_FUNC(cellSpurs, cellSpursGetTasksetInfo); REG_FUNC(cellSpurs, cellSpursTasksetSetExceptionEventHandler); REG_FUNC(cellSpurs, cellSpursTasksetUnsetExceptionEventHandler); diff --git a/rpcs3/Emu/SysCalls/Modules/cellSpurs.h b/rpcs3/Emu/SysCalls/Modules/cellSpurs.h index adb1a60799..fc8871ecd6 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpurs.h +++ b/rpcs3/Emu/SysCalls/Modules/cellSpurs.h @@ -427,19 +427,38 @@ struct CellSpursTaskset // Raw data u8 _u8[size]; + struct TaskInfo + { + be_t args[4]; + vm::bptr elf; + vm::bptr context_save_storage; + be_t ls_pattern[4]; + }; + // Real data struct { - u8 unk1[0x64]; // 0x00 - vm::bptr spurs; // 0x64 - be_t args; // 0x68 - u8 enable_clear_ls; // 0x70 - u8 x71; // 0x71 - u8 x72; // 0x72 - u8 x73; // 0x73 - be_t wid; // 0x74 - u8 unk3[0x1818]; // 0x78 - be_t size; // 0x1890 + be_t running_set[4]; // 0x00 + be_t ready_set[4]; // 0x10 + be_t unk_set[4]; // 0x20 - TODO: Find out what this is + be_t enabled_set[4]; // 0x30 + be_t signal_received_set[4]; // 0x40 + be_t waiting_set[4]; // 0x50 + vm::bptr spurs; // 0x60 + be_t args; // 0x68 + u8 enable_clear_ls; // 0x70 + u8 x71; // 0x71 + u8 x72; // 0x72 + u8 last_scheduled_task; // 0x73 + be_t wid; // 0x74 + u8 unk1[8]; // 0x78 + TaskInfo task_info[128]; // 0x80 + vm::bptr exception_handler; // 0x1880 + vm::bptr exception_handler_arg; // 0x1888 + be_t size; // 0x1890 + u32 unk2; // 0x1894 + u32 event_flag_id1; // 0x1898 + u32 event_flag_id2; // 0x189C } m; SPURSManagerTaskset *taskset; @@ -564,7 +583,47 @@ struct CellSpursTaskset2 static const u32 align = 128; static const u32 size = 10496; - be_t skip[10496]; + union + { + // Raw data + u8 _u8[size]; + + struct TaskInfo + { + be_t args[4]; + vm::bptr elf_address; + vm::bptr context_save_storage; + be_t ls_pattern[4]; + }; + + // Real data + struct + { + be_t running_set[4]; // 0x00 + be_t ready_set[4]; // 0x10 + be_t unk_set[4]; // 0x20 - TODO: Find out what this is + be_t enabled_set[4]; // 0x30 + be_t signal_received_set[4]; // 0x40 + be_t waiting_set[4]; // 0x50 + vm::bptr spurs; // 0x60 + be_t args; // 0x68 + u8 enable_clear_ls; // 0x70 + u8 x71; // 0x71 + u8 x72; // 0x72 + u8 last_scheduled_task; // 0x73 + be_t wid; // 0x74 + u8 unk1[8]; // 0x78 + TaskInfo task_info[128]; // 0x80 + vm::bptr exception_handler; // 0x1880 + vm::bptr exception_handler_arg; // 0x1888 + be_t size; // 0x1890 + u32 unk2; // 0x1894 + u32 event_flag_id1; // 0x1898 + u32 event_flag_id2; // 0x189C + u8 unk3[0x88]; // 0x1900 + u128 task_exit_code[128]; // 0x1988 + } m; + }; }; struct CellSpursTasksetAttribute diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index b0990ba2f6..8e2629cea3 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -662,6 +662,7 @@ _UNICODE;UNICODE;%(PreprocessorDefinitions) stdafx.h Async + true true @@ -676,6 +677,7 @@ _UNICODE;UNICODE;LLVM_AVAILABLE;%(PreprocessorDefinitions) stdafx.h Async + true true @@ -694,6 +696,7 @@ _UNICODE;UNICODE;MSVC_CRT_MEMLEAK_DETECTION;%(PreprocessorDefinitions) stdafx.h Async + true true @@ -741,6 +744,7 @@ Use stdafx.h Async + true true @@ -759,6 +763,7 @@ stdafx.h Async LLVM_AVAILABLE;%(PreprocessorDefinitions) + true true