From b7420e7daa4709b90725c7a1d87554f9b7b742e3 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 3 Aug 2023 13:05:13 +0300 Subject: [PATCH] memory management refactoring --- src/Core/PS4/HLE/Kernel/MemoryManagement.h | 10 -- src/Core/PS4/HLE/Kernel/ThreadManagement.cpp | 21 +-- ...ryManagement.cpp => memory_management.cpp} | 7 +- .../{MemMngCodes.h => memory_management.h} | 10 +- src/Core/PS4/HLE/LibKernel.cpp | 2 +- src/Core/PS4/HLE/LibSceGnmDriver.h | 4 +- src/Core/PS4/HLE/LibSceVideoOut.cpp | 139 +++++++++--------- src/Core/PS4/HLE/Libs.cpp | 18 +-- 8 files changed, 96 insertions(+), 115 deletions(-) delete mode 100644 src/Core/PS4/HLE/Kernel/MemoryManagement.h rename src/Core/PS4/HLE/Kernel/{MemoryManagement.cpp => memory_management.cpp} (94%) rename src/Core/PS4/HLE/Kernel/{MemMngCodes.h => memory_management.h} (53%) diff --git a/src/Core/PS4/HLE/Kernel/MemoryManagement.h b/src/Core/PS4/HLE/Kernel/MemoryManagement.h deleted file mode 100644 index 3cc6a489..00000000 --- a/src/Core/PS4/HLE/Kernel/MemoryManagement.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include - -namespace HLE::Libs::LibKernel::MemoryManagement { - -u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize(); -int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len, u64 alignment, int memoryType, s64* physAddrOut); - -}; // namespace HLE::Libs::LibKernel::MemoryManagement \ No newline at end of file diff --git a/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp b/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp index 79573d83..c6ea8f8d 100644 --- a/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp +++ b/src/Core/PS4/HLE/Kernel/ThreadManagement.cpp @@ -1,14 +1,14 @@ -#include #include "ThreadManagement.h" + +#include + #include "../ErrorCodes.h" -namespace HLE::Libs::LibKernel::ThreadManagement -{ +namespace HLE::Libs::LibKernel::ThreadManagement { thread_local PthreadInternal* g_pthread_self = nullptr; PThreadCxt* g_pthread_cxt = nullptr; - void Pthread_Init_Self_MainThread() { g_pthread_self = new PthreadInternal{}; scePthreadAttrInit(&g_pthread_self->attr); @@ -17,7 +17,6 @@ void Pthread_Init_Self_MainThread() { } int scePthreadAttrInit(ScePthreadAttr* attr) { - *attr = new PthreadAttrInternal{}; int result = pthread_attr_init(&(*attr)->pth_attr); @@ -41,7 +40,6 @@ int scePthreadAttrInit(ScePthreadAttr* attr) { } int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) { - if (attr == nullptr || *attr == nullptr) { return SCE_KERNEL_ERROR_EINVAL; } @@ -50,8 +48,7 @@ int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) { switch (detachstate) { case 0: pstate = PTHREAD_CREATE_JOINABLE; break; case 1: pstate = PTHREAD_CREATE_DETACHED; break; - default: - BREAKPOINT(); // unknown state + default: BREAKPOINT(); // unknown state } int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate); @@ -65,7 +62,6 @@ int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) { } int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) { - if (attr == nullptr || *attr == nullptr) { return SCE_KERNEL_ERROR_EINVAL; } @@ -86,7 +82,6 @@ int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) { } int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param) { - if (param == nullptr || attr == nullptr || *attr == nullptr) { return SCE_KERNEL_ERROR_EINVAL; } @@ -109,13 +104,11 @@ int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* } int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) { - if (attr == nullptr || *attr == nullptr) { return SCE_KERNEL_ERROR_EINVAL; } - if (policy!= SCHED_OTHER) - { + if (policy != SCHED_OTHER) { BREAKPOINT(); // invest if policy is other and if winpthreadlibrary support it } @@ -129,4 +122,4 @@ int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) { return SCE_KERNEL_ERROR_EINVAL; } -}; \ No newline at end of file +}; // namespace HLE::Libs::LibKernel::ThreadManagement \ No newline at end of file diff --git a/src/Core/PS4/HLE/Kernel/MemoryManagement.cpp b/src/Core/PS4/HLE/Kernel/memory_management.cpp similarity index 94% rename from src/Core/PS4/HLE/Kernel/MemoryManagement.cpp rename to src/Core/PS4/HLE/Kernel/memory_management.cpp index 5183a894..5c05979a 100644 --- a/src/Core/PS4/HLE/Kernel/MemoryManagement.cpp +++ b/src/Core/PS4/HLE/Kernel/memory_management.cpp @@ -1,16 +1,13 @@ -#include "MemoryManagement.h" - +#include #include #include -#include -#include #include "../../../../Util/Log.h" #include "../../../../Util/Singleton.h" #include "../ErrorCodes.h" #include "../Libs.h" -#include "MemMngCodes.h" #include "Objects/physical_memory.h" +#include "memory_management.h" namespace HLE::Libs::LibKernel::MemoryManagement { diff --git a/src/Core/PS4/HLE/Kernel/MemMngCodes.h b/src/Core/PS4/HLE/Kernel/memory_management.h similarity index 53% rename from src/Core/PS4/HLE/Kernel/MemMngCodes.h rename to src/Core/PS4/HLE/Kernel/memory_management.h index be68f994..72f633c2 100644 --- a/src/Core/PS4/HLE/Kernel/MemMngCodes.h +++ b/src/Core/PS4/HLE/Kernel/memory_management.h @@ -1,4 +1,5 @@ #pragma once + #include // constants @@ -11,4 +12,11 @@ enum MemoryTypes : u32 { SCE_KERNEL_WB_ONION = 0, // write - back mode (Onion bus) SCE_KERNEL_WC_GARLIC = 3, // write - combining mode (Garlic bus) SCE_KERNEL_WB_GARLIC = 10 // write - back mode (Garlic bus) -}; \ No newline at end of file +}; + +namespace HLE::Libs::LibKernel::MemoryManagement { + +u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize(); +int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len, u64 alignment, int memoryType, s64* physAddrOut); + +}; // namespace HLE::Libs::LibKernel::MemoryManagement \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp index 2a20ed5a..190e17a8 100644 --- a/src/Core/PS4/HLE/LibKernel.cpp +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -3,7 +3,7 @@ #include "Libs.h" #include #include "../../../Util/Log.h" -#include "Kernel/MemoryManagement.h" +#include "Kernel/memory_management.h" #include "../../../Util/Singleton.h" #include "Kernel/Objects/physical_memory.h" diff --git a/src/Core/PS4/HLE/LibSceGnmDriver.h b/src/Core/PS4/HLE/LibSceGnmDriver.h index b4a640d1..cef6e98e 100644 --- a/src/Core/PS4/HLE/LibSceGnmDriver.h +++ b/src/Core/PS4/HLE/LibSceGnmDriver.h @@ -5,7 +5,7 @@ namespace HLE::Libs::LibSceGnmDriver { void LibSceGnmDriver_Register(SymbolsResolver* sym); -//functions +// functions int sceGnmAddEqEvent(/* SceKernelEqueue eq, EqEventType id,*/ void* udata); bool sceGnmAreSubmitsAllowed(); int /* WorkloadStatus*/ sceGnmBeginWorkload(uint64_t* workload /*, WorkloadStream stream*/); @@ -14,7 +14,7 @@ void sceGnmDebugHardwareStatus(/* HardwareStatus flag*/); void sceGnmSetGsRingSizes(/* GsRingSizeSetup esgsRingSize, GsRingSizeSetup gsvsRingSize*/); int32_t sceGnmSetWaveLimitMultipliers(uint16_t targetPipeMask, uint8_t gfxRatio, const uint8_t (*pipeRatios)[7]); int /*MipStatsError*/ sceGnmSetupMipStatsReport(void* outputBuffer, uint32_t sizeInBytes, uint8_t intervalsBetweenReports, - uint8_t numReportsBeforeReset /*, MipStatsResetForce mipStatsResetForce*/); + uint8_t numReportsBeforeReset /*, MipStatsResetForce mipStatsResetForce*/); int sceGnmSubmitCommandBuffers(uint32_t count, void* dcb_gpu_addrs[], const uint32_t* dcb_sizes_in_bytes, void* ccb_gpu_addrs[], const uint32_t* ccb_sizes_in_bytes); int sceGnmSubmitAndFlipCommandBuffers(uint32_t count, void* dcb_gpu_addrs[], const uint32_t* dcb_sizes_in_bytes, void* ccb_gpu_addrs[], diff --git a/src/Core/PS4/HLE/LibSceVideoOut.cpp b/src/Core/PS4/HLE/LibSceVideoOut.cpp index 0f0f55f7..790bc3e5 100644 --- a/src/Core/PS4/HLE/LibSceVideoOut.cpp +++ b/src/Core/PS4/HLE/LibSceVideoOut.cpp @@ -1,84 +1,77 @@ #include "LibSceVideoOut.h" -#include "Libs.h" -#include "../Loader/Elf.h" + #include -#include "VideoOut/VideoOutCodes.h" -#include "UserManagement/UsrMngCodes.h" + #include "../../../Util/Log.h" +#include "../Loader/Elf.h" +#include "Libs.h" +#include "UserManagement/UsrMngCodes.h" +#include "VideoOut/VideoOutCodes.h" namespace HLE::Libs::LibSceVideoOut { - int32_t PS4_SYSV_ABI sceVideoOutGetFlipStatus(int32_t handle /*, SceVideoOutFlipStatus* status*/) { - BREAKPOINT(); - return 0; - } +int32_t PS4_SYSV_ABI sceVideoOutGetFlipStatus(int32_t handle /*, SceVideoOutFlipStatus* status*/) { + BREAKPOINT(); + return 0; +} - int32_t PS4_SYSV_ABI sceVideoOutSubmitFlip(int32_t handle, int32_t bufferIndex, int32_t flipMode, int64_t flipArg) { - BREAKPOINT(); - return 0; - } - int32_t PS4_SYSV_ABI sceVideoOutRegisterBuffers(int32_t handle, int32_t startIndex, void* const* addresses, int32_t bufferNum /*, +int32_t PS4_SYSV_ABI sceVideoOutSubmitFlip(int32_t handle, int32_t bufferIndex, int32_t flipMode, int64_t flipArg) { + BREAKPOINT(); + return 0; +} +int32_t PS4_SYSV_ABI sceVideoOutRegisterBuffers(int32_t handle, int32_t startIndex, void* const* addresses, int32_t bufferNum /*, const SceVideoOutBufferAttribute* attribute*/) { - BREAKPOINT(); - return 0; - } - int32_t PS4_SYSV_ABI sceVideoOutAddFlipEvent(/*SceKernelEqueue eq,*/ int32_t handle, void* udata) { - //BREAKPOINT(); - PRINT_DUMMY_FUNCTION_NAME(); - return 0; - } - int32_t PS4_SYSV_ABI sceVideoOutSetFlipRate(int32_t handle, int32_t rate) { - BREAKPOINT(); - return 0; - } - void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(/* SceVideoOutBufferAttribute* attribute,*/ uint32_t pixelFormat, uint32_t tilingMode, - uint32_t aspectRatio, - uint32_t width, uint32_t height, uint32_t pitchInPixel) - { - BREAKPOINT(); - } - int32_t PS4_SYSV_ABI sceVideoOutGetResolutionStatus(int32_t handle /*, SceVideoOutResolutionStatus* status*/) { - BREAKPOINT(); - return 0; - } - + BREAKPOINT(); + return 0; +} +int32_t PS4_SYSV_ABI sceVideoOutAddFlipEvent(/*SceKernelEqueue eq,*/ int32_t handle, void* udata) { + // BREAKPOINT(); + PRINT_DUMMY_FUNCTION_NAME(); + return 0; +} +int32_t PS4_SYSV_ABI sceVideoOutSetFlipRate(int32_t handle, int32_t rate) { + BREAKPOINT(); + return 0; +} +void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(/* SceVideoOutBufferAttribute* attribute,*/ uint32_t pixelFormat, uint32_t tilingMode, + uint32_t aspectRatio, uint32_t width, uint32_t height, uint32_t pitchInPixel) { + BREAKPOINT(); +} +int32_t PS4_SYSV_ABI sceVideoOutGetResolutionStatus(int32_t handle /*, SceVideoOutResolutionStatus* status*/) { + BREAKPOINT(); + return 0; +} - s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param) - { - PRINT_DUMMY_FUNCTION_NAME(); - if (userId != SCE_USER_SERVICE_USER_ID_SYSTEM) - { - BREAKPOINT(); - } - if (busType != SCE_VIDEO_OUT_BUS_TYPE_MAIN) - { - BREAKPOINT(); - } - if (index != 0) - { - BREAKPOINT(); - } - if (param != nullptr) - { - BREAKPOINT(); - } - return 1;//dummy return TODO - } - int32_t PS4_SYSV_ABI sceVideoOutIsFlipPending(int32_t handle) { +s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param) { + PRINT_DUMMY_FUNCTION_NAME(); + if (userId != SCE_USER_SERVICE_USER_ID_SYSTEM) { BREAKPOINT(); - return 0; - } - void LibSceVideoOut_Register(SymbolsResolver* sym) - { - LIB_FUNCTION("SbU3dwp80lQ", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutGetFlipStatus); - LIB_FUNCTION("U46NwOiJpys", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSubmitFlip); - LIB_FUNCTION("w3BY+tAEiQY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutRegisterBuffers); - LIB_FUNCTION("HXzjK9yI30k", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutAddFlipEvent); - LIB_FUNCTION("CBiu4mCE1DA", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSetFlipRate); - LIB_FUNCTION("i6-sR91Wt-4", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSetBufferAttribute); - LIB_FUNCTION("6kPnj51T62Y", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutGetResolutionStatus); - LIB_FUNCTION("Up36PTk687E", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutOpen); - LIB_FUNCTION("zgXifHT9ErY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutIsFlipPending); - } + } + if (busType != SCE_VIDEO_OUT_BUS_TYPE_MAIN) { + BREAKPOINT(); + } + if (index != 0) { + BREAKPOINT(); + } + if (param != nullptr) { + BREAKPOINT(); + } + return 1; // dummy return TODO +} +int32_t PS4_SYSV_ABI sceVideoOutIsFlipPending(int32_t handle) { + BREAKPOINT(); + return 0; +} +void LibSceVideoOut_Register(SymbolsResolver* sym) { + LIB_FUNCTION("SbU3dwp80lQ", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutGetFlipStatus); + LIB_FUNCTION("U46NwOiJpys", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSubmitFlip); + LIB_FUNCTION("w3BY+tAEiQY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutRegisterBuffers); + LIB_FUNCTION("HXzjK9yI30k", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutAddFlipEvent); + LIB_FUNCTION("CBiu4mCE1DA", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSetFlipRate); + LIB_FUNCTION("i6-sR91Wt-4", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSetBufferAttribute); + LIB_FUNCTION("6kPnj51T62Y", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutGetResolutionStatus); + LIB_FUNCTION("Up36PTk687E", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutOpen); + LIB_FUNCTION("zgXifHT9ErY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutIsFlipPending); +} -}; \ No newline at end of file +}; // namespace HLE::Libs::LibSceVideoOut \ No newline at end of file diff --git a/src/Core/PS4/HLE/Libs.cpp b/src/Core/PS4/HLE/Libs.cpp index 09f1d85b..f7559ac7 100644 --- a/src/Core/PS4/HLE/Libs.cpp +++ b/src/Core/PS4/HLE/Libs.cpp @@ -1,16 +1,16 @@ #include "Libs.h" + #include "LibC.h" #include "LibKernel.h" -#include "LibSceVideoOut.h" #include "LibSceGnmDriver.h" +#include "LibSceVideoOut.h" namespace HLE::Libs { - void Init_HLE_Libs(SymbolsResolver *sym) - { - LibC::LibC_Register(sym); - LibKernel::LibKernel_Register(sym); - LibSceVideoOut::LibSceVideoOut_Register(sym); - LibSceGnmDriver::LibSceGnmDriver_Register(sym); - } -} \ No newline at end of file +void Init_HLE_Libs(SymbolsResolver *sym) { + LibC::LibC_Register(sym); + LibKernel::LibKernel_Register(sym); + LibSceVideoOut::LibSceVideoOut_Register(sym); + LibSceGnmDriver::LibSceGnmDriver_Register(sym); +} +} // namespace HLE::Libs \ No newline at end of file