From a254507be1fe7fb3cf0f1274e35eeb545f65618f Mon Sep 17 00:00:00 2001 From: S Gopal Rajagopal Date: Wed, 10 Dec 2014 10:12:13 +0530 Subject: [PATCH] SPURS: Implement taskset attribute functions --- rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp | 124 ++++++++++++++++++++--- rpcs3/Emu/SysCalls/Modules/cellSpurs.h | 23 +++++ 2 files changed, 134 insertions(+), 13 deletions(-) diff --git a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp index 4248c35d74..0aff338d50 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp @@ -2296,15 +2296,49 @@ s64 cellSpursJobChainGetSpursAddress() #endif } -s64 cellSpursCreateTasksetWithAttribute() +s64 spursCreateTaskset(vm::ptr spurs, vm::ptr taskset, u64 args, vm::ptr priority, + u32 max_contention, u32 enable_clear_ls, u32 size, u8 unknown /*TODO: Figure this out*/) +{ + if (!spurs || !taskset) + { + return CELL_SPURS_TASK_ERROR_NULL_POINTER; + } + + if (spurs.addr() % CELL_SPURS_ALIGN || taskset.addr() % CELL_SPURS_TASKSET_ALIGN) + { + return CELL_SPURS_TASK_ERROR_ALIGN; + } + + memset((void *)taskset.addr(), 0, size); + + // TODO: Implement the rest of this + return CELL_OK; +} + +s64 cellSpursCreateTasksetWithAttribute(vm::ptr spurs, vm::ptr taskset, vm::ptr attr) { #ifdef PRX_DEBUG cellSpurs->Warning("%s()", __FUNCTION__); return GetCurrentPPUThread().FastCall2(libsre + 0x14BEC, libsre_rtoc); -#else - UNIMPLEMENTED_FUNC(cellSpurs); - return CELL_OK; #endif + + if (!attr) + { + CELL_SPURS_TASK_ERROR_NULL_POINTER; + } + + if (attr.addr() % 8) + { + return CELL_SPURS_TASK_ERROR_ALIGN; + } + + if (attr->revision != 1) + { + return CELL_SPURS_TASK_ERROR_INVAL; + } + + return spursCreateTaskset(spurs, taskset, attr->args, vm::ptr::make(attr.addr() + offsetof(CellSpursTasksetAttribute, priority)), + attr->max_contention, attr->enable_clear_ls, attr->taskset_size, 0 /*TODO: Figure this out*/); } s64 cellSpursCreateTaskset(vm::ptr spurs, vm::ptr taskset, u64 args, vm::ptr priority, u32 maxContention) @@ -2314,12 +2348,16 @@ s64 cellSpursCreateTaskset(vm::ptr spurs, vm::ptr t #ifdef PRX_DEBUG return GetCurrentPPUThread().FastCall2(libsre + 0x14CB8, libsre_rtoc); -#else +#endif + +#if 0 SPURSManagerTasksetAttribute *tattr = new SPURSManagerTasksetAttribute(args, priority, maxContention); taskset->taskset = new SPURSManagerTaskset(taskset.addr(), tattr); return CELL_OK; #endif + + return spursCreateTaskset(spurs, taskset, args, priority, maxContention, 0, CELL_SPURS_TASKSET_SIZE, 0); } s64 cellSpursJoinTaskset(vm::ptr taskset) @@ -2390,35 +2428,70 @@ s64 cellSpursCreateTaskWithAttribute() #endif } -s64 cellSpursTasksetAttributeSetName() +s64 cellSpursTasksetAttributeSetName(vm::ptr attr, vm::ptr name) { #ifdef PRX_DEBUG cellSpurs->Warning("%s()", __FUNCTION__); return GetCurrentPPUThread().FastCall2(libsre + 0x14210, libsre_rtoc); #else - UNIMPLEMENTED_FUNC(cellSpurs); + if (!attr || !name) + { + return CELL_SPURS_TASK_ERROR_NULL_POINTER; + } + + if (attr.addr() % CELL_SPURS_TASKSET_ATTRIBUTE_ALIGN) + { + return CELL_SPURS_TASK_ERROR_ALIGN; + } + + attr->name = name.addr(); return CELL_OK; #endif } -s64 cellSpursTasksetAttributeSetTasksetSize() +s64 cellSpursTasksetAttributeSetTasksetSize(vm::ptr attr, size_t size) { #ifdef PRX_DEBUG cellSpurs->Warning("%s()", __FUNCTION__); return GetCurrentPPUThread().FastCall2(libsre + 0x14254, libsre_rtoc); #else - UNIMPLEMENTED_FUNC(cellSpurs); + if (!attr) + { + return CELL_SPURS_TASK_ERROR_NULL_POINTER; + } + + if (attr.addr() % CELL_SPURS_TASKSET_ATTRIBUTE_ALIGN) + { + return CELL_SPURS_TASK_ERROR_ALIGN; + } + + if (size != CELL_SPURS_TASKSET_SIZE && size != CELL_SPURS_TASKSET2_SIZE) + { + return CELL_SPURS_TASK_ERROR_INVAL; + } + + attr->taskset_size = size; return CELL_OK; #endif } -s64 cellSpursTasksetAttributeEnableClearLS() +s64 cellSpursTasksetAttributeEnableClearLS(vm::ptr attr, s32 enable) { #ifdef PRX_DEBUG cellSpurs->Warning("%s()", __FUNCTION__); return GetCurrentPPUThread().FastCall2(libsre + 0x142AC, libsre_rtoc); #else - UNIMPLEMENTED_FUNC(cellSpurs); + if (!attr) + { + return CELL_SPURS_TASK_ERROR_NULL_POINTER; + } + + if (attr.addr() % CELL_SPURS_TASKSET_ATTRIBUTE_ALIGN) + { + return CELL_SPURS_TASK_ERROR_ALIGN; + } + + attr->enable_clear_ls = enable ? 1 : 0; return CELL_OK; #endif } @@ -2430,6 +2503,7 @@ s64 _cellSpursTasksetAttribute2Initialize(vm::ptr at #ifdef PRX_DEBUG return GetCurrentPPUThread().FastCall2(libsre + 0x1474C, libsre_rtoc); #else + memset(attribute.get_ptr(), 0, CELL_SPURS_TASKSET_ATTRIBUTE2_SIZE); attribute->revision = revision; attribute->name_addr = NULL; attribute->argTaskset = 0; @@ -2694,13 +2768,37 @@ s64 cellSpursGetTasksetInfo() #endif } -s64 _cellSpursTasksetAttributeInitialize() +s64 _cellSpursTasksetAttributeInitialize(vm::ptr attribute, u32 revision, u32 sdk_version, u64 args, vm::ptr priority, u32 max_contention) { #ifdef PRX_DEBUG cellSpurs->Warning("%s()", __FUNCTION__); return GetCurrentPPUThread().FastCall2(libsre + 0x142FC, libsre_rtoc); #else - UNIMPLEMENTED_FUNC(cellSpurs); + if (!attribute) + { + return CELL_SPURS_TASK_ERROR_NULL_POINTER; + } + + if (attribute.addr() % CELL_SPURS_TASKSET_ATTRIBUTE_ALIGN) + { + return CELL_SPURS_TASK_ERROR_ALIGN; + } + + for (u32 i = 0; i < 8; i++) + { + if (priority[i] > 0xF) + { + return CELL_SPURS_TASK_ERROR_INVAL; + } + } + + memset(attribute.get_ptr(), 0, CELL_SPURS_TASKSET_ATTRIBUTE_SIZE); + attribute->revision = revision; + attribute->sdk_version = sdk_version; + attribute->args = args; + memcpy(attribute->priority, priority.get_ptr(), 8); + attribute->taskset_size = CELL_SPURS_TASKSET_SIZE; + attribute->max_contention = max_contention; return CELL_OK; #endif } diff --git a/rpcs3/Emu/SysCalls/Modules/cellSpurs.h b/rpcs3/Emu/SysCalls/Modules/cellSpurs.h index 4e72b50826..0248311f70 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpurs.h +++ b/rpcs3/Emu/SysCalls/Modules/cellSpurs.h @@ -130,6 +130,17 @@ enum TaskConstants CELL_SPURS_TASK_TOP = 0x3000, CELL_SPURS_TASK_BOTTOM = 0x40000, CELL_SPURS_MAX_TASK_NAME_LENGTH = 32, + CELL_SPURS_TASK_ATTRIBUTE_REVISION = 1, + CELL_SPURS_TASK_ATTRIBUTE_SIZE = 256, + CELL_SPURS_TASKSET_SIZE = 6400, + CELL_SPURS_TASKSET_ALIGN = 128, + CELL_SPURS_TASKSET_ATTRIBUTE_REVISION = 1, + CELL_SPURS_TASKSET_ATTRIBUTE_ALIGN = 8, + CELL_SPURS_TASKSET_ATTRIBUTE_SIZE = 512, + CELL_SPURS_TASKSET2_SIZE = 10496, + CELL_SPURS_TASKSET2_ALIGN = 128, + CELL_SPURS_TASKSET_ATTRIBUTE2_ALIGN = 8, + CELL_SPURS_TASKSET_ATTRIBUTE2_SIZE = 512, }; class SPURSManager; @@ -531,6 +542,18 @@ struct CellSpursTaskset2 be_t skip[10496]; }; +struct CellSpursTasksetAttribute +{ + be_t revision; + be_t sdk_version; + be_t args; + u8 priority[8]; + be_t max_contention; + be_t name; + be_t taskset_size; + be_t enable_clear_ls; +}; + struct CellSpursTasksetAttribute2 { be_t revision;