From 1fb53a5430d4a677acbf1da08a6f9fb1df11f2ef Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 16 Oct 2023 13:27:37 +0300 Subject: [PATCH] initial file system work --- CMakeLists.txt | 9 ++++++++- src/Core/PS4/HLE/LibC.cpp | 4 ++++ src/Core/PS4/HLE/LibKernel.cpp | 5 +++++ .../LibKernel/FileSystem/file_system.cpp | 13 +++++++++++++ .../Libraries/LibKernel/FileSystem/file_system.h | 7 +++++++ .../LibKernel/FileSystem/posix_file_system.cpp | 15 +++++++++++++++ .../LibKernel/FileSystem/posix_file_system.h | 6 ++++++ 7 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.cpp create mode 100644 src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h create mode 100644 src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.cpp create mode 100644 src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 590c9823e..ecf42a12e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,12 @@ set(SYSTEMSERVICE_SOURCES src/Emulator/HLE/Libraries/LibSystemService/system_ser src/Emulator/HLE/Libraries/LibSystemService/system_service.h ) +set(FILESYSTEM_SOURCES src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.cpp + src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h + src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.cpp + src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h +) + set(UTIL_SOURCES src/Emulator/Util/singleton.h ) @@ -51,6 +57,7 @@ add_executable(shadps4 ${USERSERVICE_SOURCES} ${PAD_SOURCES} ${SYSTEMSERVICE_SOURCES} + ${FILESYSTEM_SOURCES} ${UTIL_SOURCES} src/main.cpp src/types.h @@ -86,7 +93,7 @@ add_executable(shadps4 src/Core/PS4/HLE/Kernel/cpu_management.cpp src/Core/PS4/HLE/Kernel/cpu_management.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/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" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h" "src/Core/PS4/HLE/Graphics/graphics_ctx.h" "src/vulkan_util.cpp" "src/vulkan_util.h" "src/Core/PS4/GPU/video_out_buffer.cpp" "src/Core/PS4/GPU/video_out_buffer.h" "src/Core/PS4/HLE/Graphics/graphics_render.cpp" "src/Core/PS4/HLE/Graphics/graphics_render.h" "src/Core/PS4/GPU/tile_manager.cpp" "src/Core/PS4/GPU/tile_manager.h" "src/version.h" "src/Emulator/HLE/Libraries/LibSystemService/system_service.cpp" "src/Emulator/HLE/Libraries/LibSystemService/system_service.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/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" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h" "src/Core/PS4/HLE/Graphics/graphics_ctx.h" "src/vulkan_util.cpp" "src/vulkan_util.h" "src/Core/PS4/GPU/video_out_buffer.cpp" "src/Core/PS4/GPU/video_out_buffer.h" "src/Core/PS4/HLE/Graphics/graphics_render.cpp" "src/Core/PS4/HLE/Graphics/graphics_render.h" "src/Core/PS4/GPU/tile_manager.cpp" "src/Core/PS4/GPU/tile_manager.h" "src/version.h" "src/Emulator/HLE/Libraries/LibSystemService/system_service.cpp" "src/Emulator/HLE/Libraries/LibSystemService/system_service.h" "src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.cpp" "src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h" "src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.cpp" "src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h") find_package(OpenGL REQUIRED) target_link_libraries(shadps4 PUBLIC fmt mincore spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY} vulkan-1 spirv-tools-opt spirv-tools) diff --git a/src/Core/PS4/HLE/LibC.cpp b/src/Core/PS4/HLE/LibC.cpp index e2b7068e8..e9c2bf5d9 100644 --- a/src/Core/PS4/HLE/LibC.cpp +++ b/src/Core/PS4/HLE/LibC.cpp @@ -107,6 +107,9 @@ void PS4_SYSV_ABI qsort(void* ptr, size_t count,size_t size, int(PS4_SYSV_ABI* c std::qsort(ptr, count, size, qsort_compair); } +void* PS4_SYSV_ABI fopen(const char* filename, const char* mode) { + return std::fopen(filename, mode); +} void LibC_Register(SymbolsResolver* sym) { LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env); @@ -137,6 +140,7 @@ void LibC_Register(SymbolsResolver* sym) { LIB_FUNCTION("eT2UsmTewbU", "libc", 1, "libc", 1, 1, _ZSt11_Xbad_allocv); LIB_FUNCTION("tQIo+GIPklo", "libc", 1, "libc", 1, 1, _ZSt14_Xlength_errorPKc); LIB_FUNCTION("fJnpuVVBbKk", "libc", 1, "libc", 1, 1, _Znwm); + LIB_FUNCTION("xeYO4u7uyJ0", "libc", 1, "libc", 1, 1, fopen); } }; // namespace HLE::Libs::LibC \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp index 77fb3c71e..528cc7cc1 100644 --- a/src/Core/PS4/HLE/LibKernel.cpp +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -10,6 +10,8 @@ #include "Kernel/event_queues.h" #include "Kernel/memory_management.h" #include "Libs.h" +#include "Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h" +#include "Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h" namespace HLE::Libs::LibKernel { @@ -44,6 +46,9 @@ void LibKernel_Register(SymbolsResolver* sym) { LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail); // time LIB_FUNCTION("-2IRUCO--PM", "libkernel", 1, "libkernel", 1, 1, sceKernelReadTsc); + //fs + LIB_FUNCTION("1G3lF1Gg1k8", "libkernel", 1, "libkernel", 1, 1, Emulator::HLE::Libraries::LibKernel::FileSystem::sceKernelOpen); + LIB_FUNCTION("wuCroIGjt2g", "libScePosix", 1, "libkernel", 1, 1, Emulator::HLE::Libraries::LibKernel::FileSystem::POSIX::open); } }; // namespace HLE::Libs::LibKernel \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.cpp b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.cpp new file mode 100644 index 000000000..cdf35595c --- /dev/null +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.cpp @@ -0,0 +1,13 @@ +#include "file_system.h" +#include +#include + +namespace Emulator::HLE::Libraries::LibKernel::FileSystem { +constexpr bool log_file_fs = true; // disable it to disable logging + +int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) { + LOG_INFO_IF(log_file_fs, "sceKernelOpen path = {} flags = {} mode = {}\n", path, log_hex_full(flags), log_hex_full(mode)); + return 0; +} + +} // namespace Emulator::HLE::Libraries::LibKernel::FileSystem \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h new file mode 100644 index 000000000..98f090f08 --- /dev/null +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h @@ -0,0 +1,7 @@ +#pragma once +#include + +namespace Emulator::HLE::Libraries::LibKernel::FileSystem { +int PS4_SYSV_ABI sceKernelOpen(const char *path, int flags, /* SceKernelMode*/ u16 mode); + +} \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.cpp b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.cpp new file mode 100644 index 000000000..caa6fb43f --- /dev/null +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.cpp @@ -0,0 +1,15 @@ +#include "posix_file_system.h" + +#include + +#include "file_system.h" + +namespace Emulator::HLE::Libraries::LibKernel::FileSystem::POSIX { +int PS4_SYSV_ABI open(const char* path, int flags, /* SceKernelMode*/ u16 mode) { + int result = sceKernelOpen(path, flags, mode); + if (result < 0) { + BREAKPOINT(); // posix calls different only for their return values + } + return result; +} +} // namespace Emulator::HLE::Libraries::LibKernel::FileSystem::POSIX diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h new file mode 100644 index 000000000..cce1c6c08 --- /dev/null +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h @@ -0,0 +1,6 @@ +#pragma once +#include "types.h" + +namespace Emulator::HLE::Libraries::LibKernel::FileSystem::POSIX { +int PS4_SYSV_ABI open(const char *path, int flags, /* SceKernelMode*/ u16 mode); +} \ No newline at end of file