diff --git a/CMakeLists.txt b/CMakeLists.txt index 31cbdc72..d8e145d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,12 +24,12 @@ add_subdirectory("third-party") #=================== EXAMPLE =================== include_directories(src) -set(LIBC_SOURCES src/Emulator/HLE/Libraries/LibC/Libc.cpp - src/Emulator/HLE/Libraries/LibC/Libc.h - src/Emulator/HLE/Libraries/LibC/printf.h - src/Emulator/HLE/Libraries/LibC/va_ctx.h - src/Emulator/HLE/Libraries/LibC/libc_cxa.cpp - src/Emulator/HLE/Libraries/LibC/libc_cxa.h +set(LIBC_SOURCES src/core/hle/libraries/Libc/Libc.cpp + src/core/hle/libraries/Libc/Libc.h + src/core/hle/libraries/Libc/printf.h + src/core/hle/libraries/Libc/va_ctx.h + src/core/hle/libraries/Libc/libc_cxa.cpp + src/core/hle/libraries/Libc/libc_cxa.h ) set(USERSERVICE_SOURCES src/core/hle/libraries/libuserservice/user_service.cpp src/core/hle/libraries/libuserservice/user_service.h @@ -97,8 +97,10 @@ 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/core/PS4/HLE/LibC.cpp + src/core/PS4/HLE/LibC.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/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/emuTimer.cpp" "src/emuTimer.h" "src/core/hle/libraries/libkernel/time_management.cpp" "src/core/hle/libraries/libkernel/time_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/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/emuTimer.cpp" "src/emuTimer.h" "src/core/hle/libraries/libkernel/time_management.cpp" "src/core/hle/libraries/libkernel/time_management.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 4d591c39..92936dab 100644 --- a/src/core/PS4/HLE/LibC.cpp +++ b/src/core/PS4/HLE/LibC.cpp @@ -4,8 +4,8 @@ #include #include "../Loader/Elf.h" -#include "Emulator/HLE/Libraries/LibC/libc.h" -#include "Emulator/HLE/Libraries/LibC/libc_cxa.h" +#include "core/hle/libraries/libc/libc.h" +#include "core/hle/libraries/libc/libc_cxa.h" #include "ErrorCodes.h" #include "Libs.h" @@ -56,36 +56,36 @@ void PS4_SYSV_ABI qsort(void* ptr, size_t count,size_t size, int(PS4_SYSV_ABI* c void LibC_Register(SymbolsResolver* sym) { LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env); - LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::Cxa::__cxa_guard_acquire); - LIB_FUNCTION("9rAeANT2tyE", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::Cxa::__cxa_guard_release); - LIB_FUNCTION("2emaaluWzUw", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::Cxa::__cxa_guard_abort); - LIB_FUNCTION("DfivPArhucg", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::memcmp); - LIB_FUNCTION("Q3VBxCXhUHs", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::memcpy); - LIB_FUNCTION("8zTFvBIAIN8", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::memset); + LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::Cxa::__cxa_guard_acquire); + LIB_FUNCTION("9rAeANT2tyE", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::Cxa::__cxa_guard_release); + LIB_FUNCTION("2emaaluWzUw", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::Cxa::__cxa_guard_abort); + LIB_FUNCTION("DfivPArhucg", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::memcmp); + LIB_FUNCTION("Q3VBxCXhUHs", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::memcpy); + LIB_FUNCTION("8zTFvBIAIN8", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::memset); LIB_FUNCTION("XKRegsFpEpk", "libc", 1, "libc", 1, 1, catchReturnFromMain); - LIB_FUNCTION("uMei1W9uyNo", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::exit); - LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::atexit); + LIB_FUNCTION("uMei1W9uyNo", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::exit); + LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::atexit); LIB_FUNCTION("-QgqOT5u2Vk", "libc", 1, "libc", 1, 1, _Assert); - LIB_FUNCTION("hcuQgD53UxM", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::printf); - LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::vsnprintf); + LIB_FUNCTION("hcuQgD53UxM", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::printf); + LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::vsnprintf); LIB_FUNCTION("YQ0navp+YIc", "libc", 1, "libc", 1, 1, puts); LIB_FUNCTION("cpCOXWMgha0", "libc", 1, "libc", 1, 1, rand); LIB_FUNCTION("ZtjspkJQ+vw", "libc", 1, "libc", 1, 1, _Fsin); LIB_FUNCTION("AEJdIVZTEmo", "libc", 1, "libc", 1, 1, qsort); - LIB_FUNCTION("Ovb2dSJOAuE", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::strcmp); - LIB_FUNCTION("gQX+4GDQjpM", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::malloc); - LIB_FUNCTION("tIhsqj0qsFE", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::free); - LIB_FUNCTION("j4ViWNHEgww", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::strlen); - LIB_FUNCTION("6sJWiWSRuqk", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::strncpy); - LIB_FUNCTION("+P6FRGH4LfA", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::memmove); - LIB_FUNCTION("kiZSXIWd9vg", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::strcpy); - LIB_FUNCTION("Ls4tzzhimqQ", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::strcat); - LIB_FUNCTION("EH-x713A99c", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::atan2f); - LIB_FUNCTION("QI-x0SL8jhw", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::acosf); - LIB_FUNCTION("ZE6RNL+eLbk", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::tanf); - LIB_FUNCTION("GZWjF-YIFFk", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::asinf); - LIB_FUNCTION("9LCjpWyQ5Zc", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::pow); - LIB_FUNCTION("cCXjU72Z0Ow", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::_Sin); + LIB_FUNCTION("Ovb2dSJOAuE", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::strcmp); + LIB_FUNCTION("gQX+4GDQjpM", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::malloc); + LIB_FUNCTION("tIhsqj0qsFE", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::free); + LIB_FUNCTION("j4ViWNHEgww", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::strlen); + LIB_FUNCTION("6sJWiWSRuqk", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::strncpy); + LIB_FUNCTION("+P6FRGH4LfA", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::memmove); + LIB_FUNCTION("kiZSXIWd9vg", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::strcpy); + LIB_FUNCTION("Ls4tzzhimqQ", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::strcat); + LIB_FUNCTION("EH-x713A99c", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::atan2f); + LIB_FUNCTION("QI-x0SL8jhw", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::acosf); + LIB_FUNCTION("ZE6RNL+eLbk", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::tanf); + LIB_FUNCTION("GZWjF-YIFFk", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::asinf); + LIB_FUNCTION("9LCjpWyQ5Zc", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::pow); + LIB_FUNCTION("cCXjU72Z0Ow", "libc", 1, "libc", 1, 1,Core::Libraries::LibC::_Sin); LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &HLE::Libs::LibC::g_need_sceLibc); diff --git a/src/Emulator/HLE/Libraries/LibC/libc.cpp b/src/core/hle/libraries/libc/libc.cpp similarity index 95% rename from src/Emulator/HLE/Libraries/LibC/libc.cpp rename to src/core/hle/libraries/libc/libc.cpp index ec531b4e..f72c635a 100644 --- a/src/Emulator/HLE/Libraries/LibC/libc.cpp +++ b/src/core/hle/libraries/libc/libc.cpp @@ -6,7 +6,7 @@ #include #include -namespace Emulator::HLE::Libraries::LibC { +namespace Core::Libraries::LibC { PS4_SYSV_ABI int printf(VA_ARGS) { VA_CTX(ctx); @@ -60,4 +60,4 @@ double PS4_SYSV_ABI pow(double base, double exponent) { return std::pow(base, ex double PS4_SYSV_ABI _Sin(double x) { return std::sin(x); } -}; // namespace Emulator::HLE::Libraries::LibC \ No newline at end of file +}; // namespace Core::Libraries::LibC \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibC/libc.h b/src/core/hle/libraries/libc/libc.h similarity index 92% rename from src/Emulator/HLE/Libraries/LibC/libc.h rename to src/core/hle/libraries/libc/libc.h index 1608612e..100612cf 100644 --- a/src/Emulator/HLE/Libraries/LibC/libc.h +++ b/src/core/hle/libraries/libc/libc.h @@ -4,7 +4,7 @@ #include "printf.h" -namespace Emulator::HLE::Libraries::LibC { +namespace Core::Libraries::LibC { // HLE functions PS4_SYSV_ABI int printf(VA_ARGS); @@ -29,4 +29,4 @@ float PS4_SYSV_ABI asinf(float num); double PS4_SYSV_ABI pow(double base, double exponent); double PS4_SYSV_ABI _Sin(double x); -} // namespace Emulator::HLE::Libraries::LibC \ No newline at end of file +} // namespace Core::Libraries::LibC \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibC/libc_cxa.cpp b/src/core/hle/libraries/libc/libc_cxa.cpp similarity index 89% rename from src/Emulator/HLE/Libraries/LibC/libc_cxa.cpp rename to src/core/hle/libraries/libc/libc_cxa.cpp index 2dbe9dec..adcb0a42 100644 --- a/src/Emulator/HLE/Libraries/LibC/libc_cxa.cpp +++ b/src/core/hle/libraries/libc/libc_cxa.cpp @@ -1,10 +1,11 @@ #include "libc_cxa.h" -#include "debug.h" + #include "Util/log.h" +#include "debug.h" // adapted from https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx.auto.html -namespace Emulator::HLE::Libraries::LibC::Cxa { +namespace Core::Libraries::LibC::Cxa { constexpr bool log_file_cxa = true; // disable it to disable logging // This file implements the __cxa_guard_* functions as defined at: @@ -87,7 +88,7 @@ int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object) { int result = ::pthread_mutex_lock(guard_mutex()); if (result != 0) { - LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): pthread_mutex_lock failed with {}\n",result); + LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): pthread_mutex_lock failed with {}\n", result); } // At this point all other threads will block in __cxa_guard_acquire() @@ -95,7 +96,7 @@ int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object) { if (initializerHasRun(guard_object)) { int result = ::pthread_mutex_unlock(guard_mutex()); if (result != 0) { - LOG_TRACE_IF(log_file_cxa,"__cxa_guard_acquire(): pthread_mutex_unlock failed with {}\n",result); + LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): pthread_mutex_unlock failed with {}\n", result); } return 0; } @@ -105,7 +106,7 @@ int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object) { // But if the same thread can call __cxa_guard_acquire() on the // *same* guard object again, we call abort(); if (inUse(guard_object)) { - LOG_TRACE_IF(log_file_cxa,"__cxa_guard_acquire(): initializer for function local static variable called enclosing function\n"); + LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): initializer for function local static variable called enclosing function\n"); } // mark this guard object as being in use @@ -127,7 +128,7 @@ void PS4_SYSV_ABI __cxa_guard_release(u64* guard_object) { // release global mutex int result = ::pthread_mutex_unlock(guard_mutex()); if (result != 0) { - LOG_TRACE_IF(log_file_cxa,"__cxa_guard_acquire(): pthread_mutex_unlock failed with {}\n",result); + LOG_TRACE_IF(log_file_cxa, "__cxa_guard_acquire(): pthread_mutex_unlock failed with {}\n", result); } } @@ -137,11 +138,11 @@ void PS4_SYSV_ABI __cxa_guard_release(u64* guard_object) { void PS4_SYSV_ABI __cxa_guard_abort(u64* guard_object) { int result = ::pthread_mutex_unlock(guard_mutex()); if (result != 0) { - LOG_TRACE_IF(log_file_cxa,"__cxa_guard_abort(): pthread_mutex_unlock failed with {}\n",result); + LOG_TRACE_IF(log_file_cxa, "__cxa_guard_abort(): pthread_mutex_unlock failed with {}\n", result); } // now reset state, so possible to try to initialize again setNotInUse(guard_object); } -} // namespace Emulator::HLE::Libraries::LibC::Cxa \ No newline at end of file +} // namespace Core::Libraries::LibC::Cxa \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibC/libc_cxa.h b/src/core/hle/libraries/libc/libc_cxa.h similarity index 71% rename from src/Emulator/HLE/Libraries/LibC/libc_cxa.h rename to src/core/hle/libraries/libc/libc_cxa.h index 228aae1a..11e8873c 100644 --- a/src/Emulator/HLE/Libraries/LibC/libc_cxa.h +++ b/src/core/hle/libraries/libc/libc_cxa.h @@ -4,8 +4,8 @@ #include #include -namespace Emulator::HLE::Libraries::LibC::Cxa { +namespace Core::Libraries::LibC::Cxa { int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object); void PS4_SYSV_ABI __cxa_guard_release(u64* guard_object); void PS4_SYSV_ABI __cxa_guard_abort(u64* guard_object); -} // namespace Emulator::HLE::Libraries::LibC::Cxa \ No newline at end of file +} // namespace Core::Libraries::LibC::Cxa \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibC/printf.h b/src/core/hle/libraries/libc/printf.h similarity index 99% rename from src/Emulator/HLE/Libraries/LibC/printf.h rename to src/core/hle/libraries/libc/printf.h index 9a1a33e7..1fa58253 100644 --- a/src/Emulator/HLE/Libraries/LibC/printf.h +++ b/src/core/hle/libraries/libc/printf.h @@ -57,9 +57,10 @@ #include #include #include + #include "va_ctx.h" -namespace Emulator::HLE::Libraries::LibC { +namespace Core::Libraries::LibC { // ntoa conversion buffer size, this must be big enough to hold // one converted numeric number including padded zeros (dynamically created on stack) // 32 byte is a good default @@ -693,10 +694,10 @@ static int printf_ctx(VaCtx* ctx) { return result; } -static int vsnprintf_ctx(char* s, size_t n, const char* format, VaList* arg) { - char buffer[n]; +static int vsnprintf_ctx(char* s, size_t n, const char* format, VaList* arg) { + char buffer[n]; int result = _vsnprintf(_out_buffer, buffer, format, arg); std::strcpy(s, buffer); return result; } -} // namespace Emulator::HLE::Libraries::LibC +} // namespace Core::Libraries::LibC diff --git a/src/Emulator/HLE/Libraries/LibC/va_ctx.h b/src/core/hle/libraries/libc/va_ctx.h similarity index 97% rename from src/Emulator/HLE/Libraries/LibC/va_ctx.h rename to src/core/hle/libraries/libc/va_ctx.h index a2d78a52..a8b0c177 100644 --- a/src/Emulator/HLE/Libraries/LibC/va_ctx.h +++ b/src/core/hle/libraries/libc/va_ctx.h @@ -26,7 +26,7 @@ (ctx).va_list.fp_offset = offsetof(VaRegSave, fp); \ (ctx).va_list.overflow_arg_area = &overflow_arg_area; -namespace Emulator::HLE::Libraries::LibC { +namespace Core::Libraries::LibC { // https://stackoverflow.com/questions/4958384/what-is-the-format-of-the-x86-64-va-list-structure @@ -103,4 +103,4 @@ T* vaArgPtr(VaList* l) { return vaArgOverflowArgArea(l); } -} // namespace Emulator::HLE::Libraries::LibC \ No newline at end of file +} // namespace Core::Libraries::LibC \ No newline at end of file