diff --git a/CMakeLists.txt b/CMakeLists.txt index 89a5cc03..68236dd7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ add_executable(shadps4 src/Core/PS4/HLE/Kernel/event_queues.h src/Core/PS4/HLE/Kernel/cpu_management.cpp src/Core/PS4/HLE/Kernel/cpu_management.h - "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h" ) + "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp") find_package(OpenGL REQUIRED) target_link_libraries(shadps4 PUBLIC fmt mincore spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY}) diff --git a/src/Core/PS4/HLE/ErrorCodes.h b/src/Core/PS4/HLE/ErrorCodes.h index 10abee85..de26175d 100644 --- a/src/Core/PS4/HLE/ErrorCodes.h +++ b/src/Core/PS4/HLE/ErrorCodes.h @@ -1,6 +1,8 @@ #pragma once 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_ENOMEM = 0x8002000c; // Insufficient memory +constexpr int SCE_KERNEL_ERROR_EFAULT = 0x8002000e; // Invalid address pointer +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_ENAMETOOLONG = 0x8002003f; // character strings exceeds valid size diff --git a/src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp b/src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp new file mode 100644 index 00000000..7f3ab986 --- /dev/null +++ b/src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp @@ -0,0 +1,5 @@ +#include "event_queue.h" + +namespace HLE::Kernel::Objects { +EqueueInternal::~EqueueInternal() {} +}; // namespace HLE::Kernel::Objects \ No newline at end of file diff --git a/src/Core/PS4/HLE/Kernel/Objects/event_queue.h b/src/Core/PS4/HLE/Kernel/Objects/event_queue.h new file mode 100644 index 00000000..930848d4 --- /dev/null +++ b/src/Core/PS4/HLE/Kernel/Objects/event_queue.h @@ -0,0 +1,14 @@ +#pragma once +#include + +namespace HLE::Kernel::Objects { +class EqueueInternal { + public: + EqueueInternal() = default; + virtual ~EqueueInternal(); + void setName(const std::string& m_name) { this->m_name = m_name; } + + private: + std::string m_name; +}; +}; // namespace HLE::Kernel::Objects \ No newline at end of file diff --git a/src/Core/PS4/HLE/Kernel/event_queues.cpp b/src/Core/PS4/HLE/Kernel/event_queues.cpp index e69de29b..d7c64473 100644 --- a/src/Core/PS4/HLE/Kernel/event_queues.cpp +++ b/src/Core/PS4/HLE/Kernel/event_queues.cpp @@ -0,0 +1,37 @@ +#include "event_queues.h" + +#include +#include +#include + +namespace HLE::Libs::LibKernel::EventQueues { +constexpr bool log_file_equeues = true; // disable it to disable logging + +int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name) { + PRINT_FUNCTION_NAME(); + + if (eq == nullptr) { + LOG_TRACE_IF(log_file_equeues, "sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EINVAL eq invalid\n"); + return SCE_KERNEL_ERROR_EINVAL; + } + if (name == nullptr) { + LOG_TRACE_IF(log_file_equeues, "sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EFAULT name invalid\n"); + return SCE_KERNEL_ERROR_EFAULT; + } + if (name == NULL) { + LOG_TRACE_IF(log_file_equeues, "sceKernelCreateEqueue returned SCE_KERNEL_ERROR_EINVAL name is null\n"); + return SCE_KERNEL_ERROR_EINVAL; + } + int s = sizeof(char); + if (strlen(name) > 31) { // max is 32 including null terminator + LOG_TRACE_IF(log_file_equeues, "sceKernelCreateEqueue returned SCE_KERNEL_ERROR_ENAMETOOLONG name size exceeds 32 bytes\n"); + return SCE_KERNEL_ERROR_ENAMETOOLONG; + } + *eq = new Kernel::Objects::EqueueInternal; + + (*eq)->setName(std::string(name)); + + LOG_INFO_IF(log_file_equeues, "sceKernelCreateEqueue created with name \"{}\"\n", name); + return SCE_OK; +} +}; // namespace HLE::Libs::LibKernel::EventQueues \ No newline at end of file diff --git a/src/Core/PS4/HLE/Kernel/event_queues.h b/src/Core/PS4/HLE/Kernel/event_queues.h index c59b3075..3072e4fd 100644 --- a/src/Core/PS4/HLE/Kernel/event_queues.h +++ b/src/Core/PS4/HLE/Kernel/event_queues.h @@ -1,5 +1,10 @@ #pragma once #include +#include "Objects/event_queue.h" -namespace HLE::Libs::LibKernel::EventQueues {}; \ No newline at end of file +namespace HLE::Libs::LibKernel::EventQueues { +using SceKernelEqueue = Kernel::Objects::EqueueInternal*; + +int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name); +}; // namespace HLE::Libs::LibKernel::EventQueues \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp index a33454df..9ddf0d70 100644 --- a/src/Core/PS4/HLE/LibKernel.cpp +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -7,6 +7,7 @@ #include "../../../Util/Singleton.h" #include "Kernel/Objects/physical_memory.h" #include "Kernel/cpu_management.h" +#include "Kernel/event_queues.h" namespace HLE::Libs::LibKernel { @@ -17,12 +18,6 @@ namespace HLE::Libs::LibKernel { return 0; } - int PS4_SYSV_ABI sceKernelCreateEqueue(/* SceKernelEqueue* eq*/ int eq, const char* name) - { - //BREAKPOINT(); - PRINT_DUMMY_FUNCTION_NAME(); - return 0; - } int PS4_SYSV_ABI sceKernelWaitEqueue(/*SceKernelEqueue eq, SceKernelEvent* ev,*/ int num, int* out /*, SceKernelUseconds* timo*/) { BREAKPOINT(); @@ -40,7 +35,7 @@ namespace HLE::Libs::LibKernel { LIB_FUNCTION("L-Q3LEjIbgA", "libkernel", 1, "libkernel", 1, 1, MemoryManagement::sceKernelMapDirectMemory); LIB_FUNCTION("MBuItvba6z8", "libkernel", 1, "libkernel", 1, 1, sceKernelReleaseDirectMemory); //equeue - LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, sceKernelCreateEqueue); + LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, EventQueues::sceKernelCreateEqueue); LIB_FUNCTION("fzyMKs9kim0", "libkernel", 1, "libkernel", 1, 1, sceKernelWaitEqueue); //misc LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, CPUManagement::sceKernelIsNeoMode); diff --git a/src/Core/PS4/HLE/LibKernel.h b/src/Core/PS4/HLE/LibKernel.h index 2ae505ff..cf38fcc0 100644 --- a/src/Core/PS4/HLE/LibKernel.h +++ b/src/Core/PS4/HLE/LibKernel.h @@ -5,7 +5,7 @@ namespace HLE::Libs::LibKernel { void LibKernel_Register(SymbolsResolver* sym); // functions -int PS4_SYSV_ABI sceKernelCreateEqueue(/* SceKernelEqueue* eq*/ int eq, const char* name); + int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len); diff --git a/src/Core/PS4/HLE/Libs.h b/src/Core/PS4/HLE/Libs.h index 66fd9909..1a246f1a 100644 --- a/src/Core/PS4/HLE/Libs.h +++ b/src/Core/PS4/HLE/Libs.h @@ -36,7 +36,7 @@ } #define PRINT_DUMMY_FUNCTION_NAME() \ - { LOG_INFO_IF(true, "dummy {}()\n", __func__); } + { LOG_WARN_IF(true, "dummy {}()\n", __func__); } namespace HLE::Libs { void Init_HLE_Libs(SymbolsResolver* sym);