From 818e0b74042ca5b97d616db9c0e83a202ae41595 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 27 Jul 2023 17:56:57 +0300 Subject: [PATCH] improvements in sceKernelAllocateDirectMemory and function logging --- src/Core/PS4/HLE/ErrorCodes.h | 2 +- src/Core/PS4/HLE/Kernel/MemMngCodes.h | 8 ++--- src/Core/PS4/HLE/Kernel/MemoryManagement.cpp | 36 ++++++++++++++++++-- src/Core/PS4/HLE/LibKernel.cpp | 3 +- src/Core/PS4/HLE/LibSceVideoOut.cpp | 4 +-- src/Core/PS4/HLE/Libs.h | 9 +++++ 6 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/Core/PS4/HLE/ErrorCodes.h b/src/Core/PS4/HLE/ErrorCodes.h index d1f558ee..10abee85 100644 --- a/src/Core/PS4/HLE/ErrorCodes.h +++ b/src/Core/PS4/HLE/ErrorCodes.h @@ -3,4 +3,4 @@ constexpr int SCE_OK = 0; constexpr int SCE_KERNEL_ERROR_ENOMEM = 0x8002000c;//Insufficient memory constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016;//null or invalid states -constexpr int SCE_KERNEL_ERROR_EAGAIN = 0x80020023;// Memory cannot be allocated +constexpr int SCE_KERNEL_ERROR_EAGAIN = 0x80020023;//Memory cannot be allocated diff --git a/src/Core/PS4/HLE/Kernel/MemMngCodes.h b/src/Core/PS4/HLE/Kernel/MemMngCodes.h index 5ba52545..71251a4f 100644 --- a/src/Core/PS4/HLE/Kernel/MemMngCodes.h +++ b/src/Core/PS4/HLE/Kernel/MemMngCodes.h @@ -3,9 +3,9 @@ // constants -constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 5376_MB; // ~ 6GB +constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 5376_MB;// ~ 6GB //memory types -constexpr int SCE_KERNEL_WB_ONION = 0; // write - back mode (Onion bus) -constexpr int SCE_KERNEL_WC_GARLIC = 3; // write - combining mode (Garlic bus) -constexpr int SCE_KERNEL_WB_GARLIC = 10; // write - back mode (Garlic bus) +constexpr int SCE_KERNEL_WB_ONION = 0;//write - back mode (Onion bus) +constexpr int SCE_KERNEL_WC_GARLIC = 3;//write - combining mode (Garlic bus) +constexpr int SCE_KERNEL_WB_GARLIC = 10;//write - back mode (Garlic bus) diff --git a/src/Core/PS4/HLE/Kernel/MemoryManagement.cpp b/src/Core/PS4/HLE/Kernel/MemoryManagement.cpp index 4fd7943a..f58a6dc1 100644 --- a/src/Core/PS4/HLE/Kernel/MemoryManagement.cpp +++ b/src/Core/PS4/HLE/Kernel/MemoryManagement.cpp @@ -1,5 +1,8 @@ #include "MemoryManagement.h" #include "../../../../Debug.h" +#include "../../../../Util/Log.h" +#include "../Libs.h" +#include "../ErrorCodes.h" #include "MemMngCodes.h" #include @@ -7,11 +10,40 @@ namespace HLE::Libs::LibKernel::MemoryManagement { bool isPowerOfTwo(u64 n) { return std::popcount(n) == 1; } -bool is16KBAligned(u64 n) { return ((n % (static_cast(16) * 1024) == 0)); } +bool is16KBAligned(u64 n) { return ((n % (16ull * 1024) == 0)); } -u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() { return SCE_KERNEL_MAIN_DMEM_SIZE; } +u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() { + PRINT_FUNCTION_NAME(); + return SCE_KERNEL_MAIN_DMEM_SIZE; +} int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len, u64 alignment, int memoryType,s64* physAddrOut){ + + PRINT_FUNCTION_NAME(); + + if (searchStart < 0 || searchEnd <= searchStart) { + //TODO debug logging + return SCE_KERNEL_ERROR_EINVAL; + } + bool isInRange = (searchStart < len && searchEnd > len); + if (len <= 0 || !is16KBAligned(len) || !isInRange){ + // TODO debug logging + return SCE_KERNEL_ERROR_EINVAL; + } + if ((alignment != 0 || is16KBAligned(alignment)) && !isPowerOfTwo(alignment)){ + // TODO debug logging + return SCE_KERNEL_ERROR_EINVAL; + } + if (physAddrOut == nullptr) { + // TODO debug logging + return SCE_KERNEL_ERROR_EINVAL; + } + LOG_INFO_IF(true, "search_start = {:#018x}\n", searchStart); + LOG_INFO_IF(true, "search_end = {:#018x}\n", searchEnd); + LOG_INFO_IF(true, "len = {:#018x}\n", len); + LOG_INFO_IF(true, "alignment = {:#018x}\n", alignment); + LOG_INFO_IF(true, "memory_type = {}\n", memoryType); + BREAKPOINT(); return 0; } diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp index 27f36d87..81272194 100644 --- a/src/Core/PS4/HLE/LibKernel.cpp +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -21,7 +21,7 @@ namespace HLE::Libs::LibKernel { int PS4_SYSV_ABI sceKernelCreateEqueue(/* SceKernelEqueue* eq*/ int eq, const char* name) { //BREAKPOINT(); - LOG_INFO_IF(true, "dummy sceKernelCreateEqueue\n"); + PRINT_DUMMY_FUNCTION_NAME(); return 0; } int PS4_SYSV_ABI sceKernelWaitEqueue(/*SceKernelEqueue eq, SceKernelEvent* ev,*/ int num, int* out /*, SceKernelUseconds* timo*/) @@ -32,6 +32,7 @@ namespace HLE::Libs::LibKernel { int PS4_SYSV_ABI sceKernelIsNeoMode() { //BREAKPOINT(); + PRINT_DUMMY_FUNCTION_NAME(); return 0; //it isn't PS4VR TODO } diff --git a/src/Core/PS4/HLE/LibSceVideoOut.cpp b/src/Core/PS4/HLE/LibSceVideoOut.cpp index a056e38f..e4929cf4 100644 --- a/src/Core/PS4/HLE/LibSceVideoOut.cpp +++ b/src/Core/PS4/HLE/LibSceVideoOut.cpp @@ -24,7 +24,7 @@ namespace HLE::Libs::LibSceVideoOut { } int32_t PS4_SYSV_ABI sceVideoOutAddFlipEvent(/*SceKernelEqueue eq,*/ int32_t handle, void* udata) { //BREAKPOINT(); - LOG_INFO_IF(true, "dummy sceVideoOutAddFlipEvent\n"); + PRINT_DUMMY_FUNCTION_NAME(); return 0; } int32_t PS4_SYSV_ABI sceVideoOutSetFlipRate(int32_t handle, int32_t rate) { @@ -45,6 +45,7 @@ namespace HLE::Libs::LibSceVideoOut { 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(); @@ -61,7 +62,6 @@ namespace HLE::Libs::LibSceVideoOut { { BREAKPOINT(); } - LOG_INFO_IF(true, "dummy sceVideoOutOpen\n"); return 1;//dummy return TODO } int32_t PS4_SYSV_ABI sceVideoOutIsFlipPending(int32_t handle) { diff --git a/src/Core/PS4/HLE/Libs.h b/src/Core/PS4/HLE/Libs.h index 5f94e81c..66fd9909 100644 --- a/src/Core/PS4/HLE/Libs.h +++ b/src/Core/PS4/HLE/Libs.h @@ -29,6 +29,15 @@ auto func = reinterpret_cast(function); \ sym->AddSymbol(sr, func); \ } + +#define PRINT_FUNCTION_NAME() \ + { \ + LOG_INFO_IF(true, "{}()\n", __func__); \ + } + +#define PRINT_DUMMY_FUNCTION_NAME() \ + { LOG_INFO_IF(true, "dummy {}()\n", __func__); } + namespace HLE::Libs { void Init_HLE_Libs(SymbolsResolver* sym); } \ No newline at end of file