From 369d92fa56bf023ca33c1afec76c8320a7a036d6 Mon Sep 17 00:00:00 2001 From: GPUCode Date: Mon, 6 Nov 2023 01:11:54 +0200 Subject: [PATCH] core: Reorganize --- CMakeLists.txt | 74 +++++++++---------- src/GUI/ElfViewer.cpp | 11 +-- src/GUI/ElfViewer.h | 16 ++-- .../HLE/Graphics/Objects/video_out_ctx.cpp | 11 ++- .../PS4/HLE/Graphics/Objects/video_out_ctx.h | 5 +- src/core/PS4/HLE/Graphics/video_out.cpp | 60 +++++++++------ src/core/PS4/HLE/Graphics/video_out.h | 14 ++-- src/core/PS4/HLE/Kernel/cpu_management.cpp | 13 ---- src/core/PS4/HLE/Kernel/event_queues.h | 12 --- src/core/PS4/HLE/LibKernel.h | 10 --- src/core/PS4/HLE/LibSceGnmDriver.cpp | 27 ------- src/core/PS4/HLE/LibSceGnmDriver.h | 9 --- src/core/PS4/HLE/Libs.cpp | 23 ------ src/core/PS4/Stubs.h | 4 - src/core/PS4/Util/aerolib.cpp | 38 ---------- src/core/PS4/Util/aerolib.h | 11 --- src/core/aerolib/aerolib.cpp | 33 +++++++++ src/core/aerolib/aerolib.h | 14 ++++ src/core/{PS4/Util => aerolib}/aerolib.inl | 0 src/core/{PS4/Stubs.cpp => aerolib/stubs.cpp} | 18 +++-- src/core/aerolib/stubs.h | 11 +++ .../HLE/ErrorCodes.h => hle/error_codes.h} | 1 + .../kernel}/Objects/event_queue.cpp | 13 ++-- .../kernel}/Objects/event_queue.h | 11 ++- .../kernel}/Objects/physical_memory.cpp | 18 +++-- .../kernel}/Objects/physical_memory.h | 12 +-- .../kernel}/ThreadManagement.cpp | 10 +-- .../Kernel => hle/kernel}/ThreadManagement.h | 6 +- src/core/hle/kernel/cpu_management.cpp | 13 ++++ .../Kernel => hle/kernel}/cpu_management.h | 7 +- .../Kernel => hle/kernel}/event_queues.cpp | 29 +++++--- src/core/hle/kernel/event_queues.h | 14 ++++ .../kernel}/memory_management.cpp | 33 ++++----- .../Kernel => hle/kernel}/memory_management.h | 10 +-- src/core/hle/libraries/libc/libc.cpp | 33 ++++++--- src/core/hle/libraries/libc/libc.h | 9 ++- src/core/hle/libraries/libc/libc_cxa.cpp | 3 +- src/core/hle/libraries/libc/libc_cxa.h | 4 +- src/core/hle/libraries/libc/libc_math.cpp | 37 +++++++--- src/core/hle/libraries/libc/libc_math.h | 4 +- src/core/hle/libraries/libc/libc_stdio.cpp | 15 ++-- src/core/hle/libraries/libc/libc_stdio.h | 7 +- src/core/hle/libraries/libc/libc_stdlib.cpp | 30 +++++--- src/core/hle/libraries/libc/libc_stdlib.h | 7 +- src/core/hle/libraries/libc/libc_string.cpp | 41 +++++++--- src/core/hle/libraries/libc/libc_string.h | 7 +- src/core/hle/libraries/libc/va_ctx.h | 2 +- .../hle/libraries/libkernel/file_system.cpp | 10 +-- .../hle/libraries/libkernel/file_system.h | 12 ++- .../libraries/libkernel/libkernel.cpp} | 50 +++++++------ src/core/hle/libraries/libkernel/libkernel.h | 16 ++++ .../libraries/libkernel/time_management.cpp | 21 ++++-- .../hle/libraries/libkernel/time_management.h | 11 ++- src/core/hle/libraries/libpad/pad.cpp | 19 +++-- src/core/hle/libraries/libpad/pad.h | 52 ++++++------- src/core/hle/libraries/libs.cpp | 22 ++++++ .../{PS4/HLE/Libs.h => hle/libraries/libs.h} | 17 +++-- .../libscegnmdriver/libscegnmdriver.cpp | 24 ++++++ .../libscegnmdriver/libscegnmdriver.h | 16 ++++ .../libsystemservice/system_service.cpp | 14 ++-- .../libsystemservice/system_service.h | 12 ++- .../{user_service.cpp => libuserservice.cpp} | 13 ++-- .../{user_service.h => libuserservice.h} | 12 ++- .../libraries/libuserservice/usr_mng_codes.h} | 0 src/core/{PS4/Linker.cpp => linker.cpp} | 40 +++++----- src/core/{PS4/Linker.h => linker.h} | 44 +++++------ .../{PS4/Loader/Elf.cpp => loader/elf.cpp} | 9 ++- src/core/{PS4/Loader/Elf.h => loader/elf.h} | 4 + .../symbols_resolver.cpp} | 11 ++- .../symbols_resolver.h} | 33 +++++---- src/core/virtual_memory.cpp | 4 +- src/emulator.cpp | 18 ++--- src/main.cpp | 22 +++--- 73 files changed, 724 insertions(+), 572 deletions(-) delete mode 100644 src/core/PS4/HLE/Kernel/cpu_management.cpp delete mode 100644 src/core/PS4/HLE/Kernel/event_queues.h delete mode 100644 src/core/PS4/HLE/LibKernel.h delete mode 100644 src/core/PS4/HLE/LibSceGnmDriver.cpp delete mode 100644 src/core/PS4/HLE/LibSceGnmDriver.h delete mode 100644 src/core/PS4/HLE/Libs.cpp delete mode 100644 src/core/PS4/Stubs.h delete mode 100644 src/core/PS4/Util/aerolib.cpp delete mode 100644 src/core/PS4/Util/aerolib.h create mode 100644 src/core/aerolib/aerolib.cpp create mode 100644 src/core/aerolib/aerolib.h rename src/core/{PS4/Util => aerolib}/aerolib.inl (100%) rename src/core/{PS4/Stubs.cpp => aerolib/stubs.cpp} (89%) create mode 100644 src/core/aerolib/stubs.h rename src/core/{PS4/HLE/ErrorCodes.h => hle/error_codes.h} (99%) rename src/core/{PS4/HLE/Kernel => hle/kernel}/Objects/event_queue.cpp (91%) rename src/core/{PS4/HLE/Kernel => hle/kernel}/Objects/event_queue.h (92%) rename src/core/{PS4/HLE/Kernel => hle/kernel}/Objects/physical_memory.cpp (80%) rename src/core/{PS4/HLE/Kernel => hle/kernel}/Objects/physical_memory.h (84%) rename src/core/{PS4/HLE/Kernel => hle/kernel}/ThreadManagement.cpp (95%) rename src/core/{PS4/HLE/Kernel => hle/kernel}/ThreadManagement.h (88%) create mode 100644 src/core/hle/kernel/cpu_management.cpp rename src/core/{PS4/HLE/Kernel => hle/kernel}/cpu_management.h (58%) rename src/core/{PS4/HLE/Kernel => hle/kernel}/event_queues.cpp (74%) create mode 100644 src/core/hle/kernel/event_queues.h rename src/core/{PS4/HLE/Kernel => hle/kernel}/memory_management.cpp (87%) rename src/core/{PS4/HLE/Kernel => hle/kernel}/memory_management.h (90%) rename src/core/{PS4/HLE/LibKernel.cpp => hle/libraries/libkernel/libkernel.cpp} (57%) create mode 100644 src/core/hle/libraries/libkernel/libkernel.h create mode 100644 src/core/hle/libraries/libs.cpp rename src/core/{PS4/HLE/Libs.h => hle/libraries/libs.h} (86%) create mode 100644 src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp create mode 100644 src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h rename src/core/hle/libraries/libuserservice/{user_service.cpp => libuserservice.cpp} (75%) rename src/core/hle/libraries/libuserservice/{user_service.h => libuserservice.h} (68%) rename src/core/{PS4/HLE/UserManagement/UsrMngCodes.h => hle/libraries/libuserservice/usr_mng_codes.h} (100%) rename src/core/{PS4/Linker.cpp => linker.cpp} (96%) rename src/core/{PS4/Linker.h => linker.h} (82%) rename src/core/{PS4/Loader/Elf.cpp => loader/elf.cpp} (99%) rename src/core/{PS4/Loader/Elf.h => loader/elf.h} (99%) rename src/core/{PS4/Loader/SymbolsResolver.cpp => loader/symbols_resolver.cpp} (88%) rename src/core/{PS4/Loader/SymbolsResolver.h => loader/symbols_resolver.h} (51%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c3a85b1..28e521b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,12 +30,12 @@ endfunction() add_subdirectory(third-party) include_directories(src) -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(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 src/core/hle/libraries/libc/libc_stdio.cpp src/core/hle/libraries/libc/libc_stdio.h src/core/hle/libraries/libc/libc_math.cpp @@ -45,8 +45,8 @@ set(LIBC_SOURCES src/core/hle/libraries/Libc/Libc.cpp src/core/hle/libraries/libc/libc_stdlib.cpp src/core/hle/libraries/libc/libc_stdlib.h ) -set(USERSERVICE_SOURCES src/core/hle/libraries/libuserservice/user_service.cpp - src/core/hle/libraries/libuserservice/user_service.h +set(USERSERVICE_SOURCES src/core/hle/libraries/libuserservice/libuserservice.cpp + src/core/hle/libraries/libuserservice/libuserservice.h ) set(PAD_SOURCES src/core/hle/libraries/libpad/pad.cpp @@ -89,47 +89,47 @@ add_executable(shadps4 src/Lib/Timer.cpp src/Lib/Timer.h src/main.cpp - src/core/PS4/Loader/Elf.cpp - src/core/PS4/Loader/Elf.h + src/core/loader/elf.cpp + src/core/loader/elf.h src/GUI/ElfViewer.cpp src/GUI/ElfViewer.h src/Util/config.cpp src/Util/config.h src/core/virtual_memory.cpp src/core/virtual_memory.h - src/core/PS4/Linker.cpp - src/core/PS4/Linker.h - src/core/PS4/Stubs.cpp - src/core/PS4/Stubs.h - src/core/PS4/Util/aerolib.cpp - src/core/PS4/HLE/Kernel/Objects/physical_memory.h - src/core/PS4/HLE/Kernel/Objects/physical_memory.cpp + src/core/linker.cpp + src/core/linker.h + src/core/aerolib/stubs.cpp + src/core/aerolib/stubs.h + src/core/aerolib/aerolib.cpp + src/core/aerolib/aerolib.h + src/core/hle/kernel/Objects/physical_memory.h + src/core/hle/kernel/Objects/physical_memory.cpp src/core/PS4/HLE/Graphics/video_out.cpp src/core/PS4/HLE/Graphics/video_out.h - src/core/PS4/HLE/Kernel/event_queues.cpp - 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/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/core/PS4/HLE/Kernel/memory_management.cpp - src/core/PS4/HLE/Kernel/memory_management.h + src/core/hle/kernel/event_queues.cpp + src/core/hle/kernel/event_queues.h + src/core/hle/kernel/cpu_management.cpp + src/core/hle/kernel/cpu_management.h + src/core/loader/symbols_resolver.h + src/core/loader/symbols_resolver.cpp + src/core/hle/libraries/libs.cpp + src/core/hle/libraries/libs.h + src/core/hle/libraries/libkernel/libkernel.cpp + src/core/hle/libraries/libkernel/libkernel.h + src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp + src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h + src/core/hle/kernel/ThreadManagement.cpp + src/core/hle/kernel/ThreadManagement.h + src/core/hle/kernel/memory_management.cpp + src/core/hle/kernel/memory_management.h + src/core/hle/error_codes.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/hle/kernel/Objects/event_queue.h + src/core/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 diff --git a/src/GUI/ElfViewer.cpp b/src/GUI/ElfViewer.cpp index fdb1fc07..641a1437 100644 --- a/src/GUI/ElfViewer.cpp +++ b/src/GUI/ElfViewer.cpp @@ -1,14 +1,12 @@ -#include "ElfViewer.h" +#include "core/loader/elf.h" +#include "GUI/ElfViewer.h" #include "imgui.h" -ElfViewer::ElfViewer(Elf* elf) -{ +ElfViewer::ElfViewer(Core::Loader::Elf* elf) { this->elf = elf; } -//function to display Self/Elf window -void ElfViewer::display(bool enabled) -{ +void ElfViewer::Display(bool enabled) { int SELF_HEADER = 0; int ELF_HEADER = 1; int SEG_HEADER_START = 100; @@ -97,5 +95,4 @@ void ElfViewer::display(bool enabled) } ImGui::EndChild(); ImGui::End(); - } diff --git a/src/GUI/ElfViewer.h b/src/GUI/ElfViewer.h index 13a24d8c..dcdf1cb3 100644 --- a/src/GUI/ElfViewer.h +++ b/src/GUI/ElfViewer.h @@ -1,11 +1,15 @@ #pragma once -#include "../core/PS4/Loader/Elf.h" + +namespace Core::Loader { +class Elf; +} class ElfViewer { -private: - Elf* elf; public: - ElfViewer(Elf* elf); - void display(bool enabled);//display imgui window + explicit ElfViewer(Core::Loader::Elf* elf); -}; \ No newline at end of file + void Display(bool enabled); + +private: + Core::Loader::Elf* elf; +}; diff --git a/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp b/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp index b18d3b7c..3947d645 100644 --- a/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp +++ b/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp @@ -1,8 +1,6 @@ -#include "video_out_ctx.h" - -#include #include "common/debug.h" -#include +#include "core/PS4/HLE/Graphics/Objects/video_out_ctx.h" +#include "core/hle/libraries/libkernel/time_management.h" namespace HLE::Graphics::Objects { @@ -12,6 +10,7 @@ void VideoOutCtx::Init(u32 width, u32 height) { m_video_out_ctx.m_resolution.paneWidth = width; m_video_out_ctx.m_resolution.paneHeight = height; } + int VideoOutCtx::Open() { std::scoped_lock lock{m_mutex}; @@ -112,7 +111,7 @@ bool FlipQueue::flip(u32 micros) { std::scoped_lock cfg_lock{request->cfg->m_mutex}; for (auto& flip_eq : request->cfg->m_flip_evtEq) { if (flip_eq != nullptr) { - flip_eq->triggerEvent(SCE_VIDEO_OUT_EVENT_FLIP, HLE::Kernel::Objects::EVFILT_VIDEO_OUT, reinterpret_cast(request->flip_arg)); + flip_eq->triggerEvent(SCE_VIDEO_OUT_EVENT_FLIP, Core::Kernel::EVFILT_VIDEO_OUT, reinterpret_cast(request->flip_arg)); } } } @@ -131,4 +130,4 @@ bool FlipQueue::flip(u32 micros) { return true; } -}; // namespace HLE::Graphics::Objects +} // namespace HLE::Graphics::Objects diff --git a/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h b/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h index 0a60c1cf..781e0c61 100644 --- a/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h +++ b/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h @@ -24,7 +24,7 @@ struct VideoConfigInternal { bool isOpened = false; SceVideoOutFlipStatus m_flip_status; SceVideoOutVblankStatus m_vblank_status; - std::vector m_flip_evtEq; + std::vector m_flip_evtEq; int m_flip_rate = 0; VideoOutBufferInfo buffers[16]; std::vector buffers_sets; @@ -78,4 +78,5 @@ class VideoOutCtx { FlipQueue m_flip_queue; HLE::Libs::Graphics::GraphicCtx* m_graphic_ctx = nullptr; }; -}; // namespace HLE::Graphics::Objects \ No newline at end of file + +} // namespace HLE::Graphics::Objects diff --git a/src/core/PS4/HLE/Graphics/video_out.cpp b/src/core/PS4/HLE/Graphics/video_out.cpp index cbd08386..c87c1a87 100644 --- a/src/core/PS4/HLE/Graphics/video_out.cpp +++ b/src/core/PS4/HLE/Graphics/video_out.cpp @@ -1,19 +1,17 @@ -#include "video_out.h" - -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include "common/log.h" #include "common/debug.h" -#include - -#include -#include - +#include "core/loader/symbols_resolver.h" +#include "core/PS4/HLE/Graphics/video_out.h" +#include "core/PS4/GPU/gpu_memory.h" +#include "core/PS4/GPU/video_out_buffer.h" +#include "core/hle/error_codes.h" +#include "core/hle/libraries/libscegnmdriver/libscegnmdriver.h" +#include "core/hle/libraries/libs.h" +#include "core/hle/libraries/libuserservice/usr_mng_codes.h" +#include "Util/config.h" #include "Objects/video_out_ctx.h" #include "common/singleton.h" #include "emulator.h" @@ -60,7 +58,7 @@ void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(SceVideoOutBufferAttribute* attr LOG_INFO_IF(log_file_videoout, "height = {}\n", height); LOG_INFO_IF(log_file_videoout, "pitchInPixel = {}\n", pitchInPixel); - memset(attribute, 0, sizeof(SceVideoOutBufferAttribute)); + std::memset(attribute, 0, sizeof(SceVideoOutBufferAttribute)); attribute->pixelFormat = pixelFormat; attribute->tilingMode = tilingMode; @@ -71,21 +69,23 @@ void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(SceVideoOutBufferAttribute* attr attribute->option = SCE_VIDEO_OUT_BUFFER_ATTRIBUTE_OPTION_NONE; } -static void flip_reset_event_func(HLE::Kernel::Objects::EqueueEvent* event) { +static void flip_reset_event_func(Core::Kernel::EqueueEvent* event) { event->isTriggered = false; event->event.fflags = 0; event->event.data = 0; } -static void flip_trigger_event_func(HLE::Kernel::Objects::EqueueEvent* event, void* trigger_data) { + +static void flip_trigger_event_func(Core::Kernel::EqueueEvent* event, void* trigger_data) { event->isTriggered = true; event->event.fflags++; event->event.data = reinterpret_cast(trigger_data); } -static void flip_delete_event_func(LibKernel::EventQueues::SceKernelEqueue eq, HLE::Kernel::Objects::EqueueEvent* event) { + +static void flip_delete_event_func(Core::Kernel::SceKernelEqueue eq, Core::Kernel::EqueueEvent* event) { BREAKPOINT(); // TODO } -s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(LibKernel::EventQueues::SceKernelEqueue eq, s32 handle, void* udata) { +s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(Core::Kernel::SceKernelEqueue eq, s32 handle, void* udata) { PRINT_FUNCTION_NAME(); auto* videoOut = Common::Singleton::Instance(); @@ -100,10 +100,10 @@ s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(LibKernel::EventQueues::SceKernelEqueue return SCE_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE; } - HLE::Kernel::Objects::EqueueEvent event; + Core::Kernel::EqueueEvent event{}; event.isTriggered = false; event.event.ident = SCE_VIDEO_OUT_EVENT_FLIP; - event.event.filter = HLE::Kernel::Objects::EVFILT_VIDEO_OUT; + event.event.filter = Core::Kernel::EVFILT_VIDEO_OUT; event.event.udata = udata; event.event.fflags = 0; event.event.data = 0; @@ -213,18 +213,21 @@ s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* co return registration_index; } + s32 PS4_SYSV_ABI sceVideoOutSetFlipRate(s32 handle, s32 rate) { PRINT_FUNCTION_NAME(); auto* videoOut = Common::Singleton::Instance(); videoOut->getCtx(handle)->m_flip_rate = rate; return SCE_OK; } + s32 PS4_SYSV_ABI sceVideoOutIsFlipPending(s32 handle) { PRINT_FUNCTION_NAME(); auto* videoOut = Common::Singleton::Instance(); s32 pending = videoOut->getCtx(handle)->m_flip_status.flipPendingNum; return pending; } + s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode, s64 flipArg) { PRINT_FUNCTION_NAME(); auto* videoOut = Common::Singleton::Instance(); @@ -249,9 +252,10 @@ s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode LOG_TRACE_IF(log_file_videoout, "sceVideoOutSubmitFlip flip queue is full\n"); return SCE_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL; } - HLE::Libs::LibSceGnmDriver::sceGnmFlushGarlic(); // hackish should be done that neccesary for niko's homebrew + Core::Libraries::LibSceGnmDriver::sceGnmFlushGarlic(); // hackish should be done that neccesary for niko's homebrew return SCE_OK; } + s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* status) { PRINT_FUNCTION_NAME(); auto* videoOut = Common::Singleton::Instance(); @@ -268,12 +272,14 @@ s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* sta LOG_INFO_IF(log_file_videoout, "currentBuffer = {}\n", status->currentBuffer); return 0; } + s32 PS4_SYSV_ABI sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutionStatus* status) { PRINT_FUNCTION_NAME(); auto* videoOut = Common::Singleton::Instance(); *status = videoOut->getCtx(handle)->m_resolution; return SCE_OK; } + s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param) { PRINT_FUNCTION_NAME(); if (userId != SCE_USER_SERVICE_USER_ID_SYSTEM && userId != 0) { @@ -299,14 +305,20 @@ s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 i return handle; } + s32 PS4_SYSV_ABI sceVideoOutClose(s32 handle) { auto* videoOut = Common::Singleton::Instance(); videoOut->Close(handle); return SCE_OK; } -s32 PS4_SYSV_ABI sceVideoOutUnregisterBuffers(s32 handle, s32 attributeIndex) { BREAKPOINT(); } -void videoOutRegisterLib(SymbolsResolver* sym) { +s32 PS4_SYSV_ABI sceVideoOutUnregisterBuffers(s32 handle, s32 attributeIndex) { + BREAKPOINT(); + return 0; +} + +void videoOutRegisterLib(Core::Loader::SymbolsResolver* sym) { + using namespace Core; 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); diff --git a/src/core/PS4/HLE/Graphics/video_out.h b/src/core/PS4/HLE/Graphics/video_out.h index 65a8fa10..8a8a88d5 100644 --- a/src/core/PS4/HLE/Graphics/video_out.h +++ b/src/core/PS4/HLE/Graphics/video_out.h @@ -1,8 +1,11 @@ #pragma once -#include -#include #include +#include "core/hle/kernel/event_queues.h" + +namespace Core::Loader { +class SymbolsResolver; +} namespace HLE::Libs::Graphics::VideoOut { @@ -95,12 +98,12 @@ struct VideoOutBufferSetInternal { void videoOutInit(u32 width, u32 height); std::string getPixelFormatString(s32 format); -void videoOutRegisterLib(SymbolsResolver* sym); +void videoOutRegisterLib(Core::Loader::SymbolsResolver* sym); bool videoOutFlip(u32 micros); void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(SceVideoOutBufferAttribute* attribute, u32 pixelFormat, u32 tilingMode, u32 aspectRatio, u32 width, u32 height, u32 pitchInPixel); -s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(LibKernel::EventQueues::SceKernelEqueue eq, s32 handle, void* udata); +s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(Core::Kernel::SceKernelEqueue eq, s32 handle, void* udata); s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses, s32 bufferNum, const SceVideoOutBufferAttribute* attribute); s32 PS4_SYSV_ABI sceVideoOutSetFlipRate(s32 handle, s32 rate); @@ -110,4 +113,5 @@ s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* sta s32 PS4_SYSV_ABI sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutionStatus* status); s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param); s32 PS4_SYSV_ABI sceVideoOutClose(s32 handle); -} // namespace HLE::Libs::Graphics::VideoOut + +} // namespace HLE::Libs::Graphics::VideoOut diff --git a/src/core/PS4/HLE/Kernel/cpu_management.cpp b/src/core/PS4/HLE/Kernel/cpu_management.cpp deleted file mode 100644 index 6c334024..00000000 --- a/src/core/PS4/HLE/Kernel/cpu_management.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "cpu_management.h" -#include "Util/config.h" -#include "common/log.h" -#include - -namespace HLE::Libs::LibKernel::CPUManagement { -int PS4_SYSV_ABI sceKernelIsNeoMode() { - PRINT_FUNCTION_NAME(); - bool isNeo = Config::isNeoMode(); - return isNeo ? 1 : 0; -} - -}; // namespace HLE::Libs::LibKernel::CPUManagement diff --git a/src/core/PS4/HLE/Kernel/event_queues.h b/src/core/PS4/HLE/Kernel/event_queues.h deleted file mode 100644 index c59367b2..00000000 --- a/src/core/PS4/HLE/Kernel/event_queues.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "Objects/event_queue.h" - -namespace HLE::Libs::LibKernel::EventQueues { -using SceKernelUseconds = u32; -using SceKernelEqueue = Kernel::Objects::EqueueInternal*; - -int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name); -int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, HLE::Kernel::Objects::SceKernelEvent* ev, int num, int* out, SceKernelUseconds *timo); - -}; // namespace HLE::Libs::LibKernel::EventQueues diff --git a/src/core/PS4/HLE/LibKernel.h b/src/core/PS4/HLE/LibKernel.h deleted file mode 100644 index ee5fc613..00000000 --- a/src/core/PS4/HLE/LibKernel.h +++ /dev/null @@ -1,10 +0,0 @@ -#include "../Loader/SymbolsResolver.h" - -namespace HLE::Libs::LibKernel { - -void LibKernel_Register(SymbolsResolver* sym); - -// functions - -int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len); -}; // namespace HLE::Libs::LibKernel \ No newline at end of file diff --git a/src/core/PS4/HLE/LibSceGnmDriver.cpp b/src/core/PS4/HLE/LibSceGnmDriver.cpp deleted file mode 100644 index be81d557..00000000 --- a/src/core/PS4/HLE/LibSceGnmDriver.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "LibSceGnmDriver.h" -#include "Libs.h" -#include "../Loader/Elf.h" -#include "common/log.h" -#include "common/debug.h" -#include -#include - -namespace HLE::Libs::LibSceGnmDriver { - - int32_t sceGnmSubmitDone() - { - PRINT_DUMMY_FUNCTION_NAME(); - return 0; - } - - void sceGnmFlushGarlic() { PRINT_FUNCTION_NAME(); - GPU::flushGarlic(Emu::getGraphicCtx()); - } - - void LibSceGnmDriver_Register(SymbolsResolver* sym) - { - LIB_FUNCTION("yvZ73uQUqrk", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitDone); - LIB_FUNCTION("iBt3Oe00Kvc", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmFlushGarlic); - } - -}; \ No newline at end of file diff --git a/src/core/PS4/HLE/LibSceGnmDriver.h b/src/core/PS4/HLE/LibSceGnmDriver.h deleted file mode 100644 index 120ec93a..00000000 --- a/src/core/PS4/HLE/LibSceGnmDriver.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "../Loader/SymbolsResolver.h" - -namespace HLE::Libs::LibSceGnmDriver { - -void LibSceGnmDriver_Register(SymbolsResolver* sym); -int32_t sceGnmSubmitDone(); -void sceGnmFlushGarlic(); -}; // namespace HLE::Libs::LibSceGnmDriver \ No newline at end of file diff --git a/src/core/PS4/HLE/Libs.cpp b/src/core/PS4/HLE/Libs.cpp deleted file mode 100644 index ae8431f8..00000000 --- a/src/core/PS4/HLE/Libs.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "Libs.h" - -#include "LibKernel.h" -#include "LibSceGnmDriver.h" -#include -#include "core/hle/libraries/libuserservice/user_service.h" -#include "core/hle/libraries/libpad/pad.h" -#include -#include "core/hle/libraries/libc/libc.h" - -namespace HLE::Libs { - -void Init_HLE_Libs(SymbolsResolver *sym) { - - LibKernel::LibKernel_Register(sym); - Graphics::VideoOut::videoOutRegisterLib(sym); - LibSceGnmDriver::LibSceGnmDriver_Register(sym); - Core::Libraries::LibUserService::userServiceSymbolsRegister(sym); - Core::Libraries::LibPad::padSymbolsRegister(sym); - Core::Libraries::LibSystemService::systemServiceSymbolsRegister(sym); - Core::Libraries::LibC::libcSymbolsRegister(sym); -} -} // namespace HLE::Libs \ No newline at end of file diff --git a/src/core/PS4/Stubs.h b/src/core/PS4/Stubs.h deleted file mode 100644 index 1a7f0081..00000000 --- a/src/core/PS4/Stubs.h +++ /dev/null @@ -1,4 +0,0 @@ -#include "common/types.h" - -u64 UnresolvedStub(); -u64 GetStub(const char *nid); \ No newline at end of file diff --git a/src/core/PS4/Util/aerolib.cpp b/src/core/PS4/Util/aerolib.cpp deleted file mode 100644 index b095fa7c..00000000 --- a/src/core/PS4/Util/aerolib.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "aerolib.h" - -#include "common/types.h" - -#include - -#include "common/log.h" - -namespace aerolib { - -// Use a direct table here + binary search as contents are static -nid_entry nids[] = { -#define STUB(nid, name) \ - { nid, #name }, -#include "aerolib.inl" -#undef STUB -}; - -nid_entry* find_by_nid(const char* nid) { - s64 l = 0; - s64 r = sizeof(nids) / sizeof(nids[0]) - 1; - - while (l <= r) { - size_t m = l + (r - l) / 2; - - int cmp = strcmp(nids[m].nid, nid); - - if (cmp == 0) - return &nids[m]; - else if (cmp < 0) - l = m + 1; - else - r = m - 1; - } - - return nullptr; -} -} // namespace aerolib \ No newline at end of file diff --git a/src/core/PS4/Util/aerolib.h b/src/core/PS4/Util/aerolib.h deleted file mode 100644 index 168cce43..00000000 --- a/src/core/PS4/Util/aerolib.h +++ /dev/null @@ -1,11 +0,0 @@ -#include - -namespace aerolib { - - struct nid_entry { - const char* nid; - const char* name; - }; - - nid_entry* find_by_nid(const char* nid); -}; \ No newline at end of file diff --git a/src/core/aerolib/aerolib.cpp b/src/core/aerolib/aerolib.cpp new file mode 100644 index 00000000..eb93fe18 --- /dev/null +++ b/src/core/aerolib/aerolib.cpp @@ -0,0 +1,33 @@ +#include +#include "common/types.h" +#include "core/aerolib/aerolib.h" + +namespace Core::AeroLib { + +// Use a direct table here + binary search as contents are static +static constexpr NidEntry NIDS[] = { +#define STUB(nid, name) \ + { nid, #name }, +#include "aerolib.inl" +#undef STUB +}; + +const NidEntry* FindByNid(const char* nid) { + s64 l = 0; + s64 r = sizeof(NIDS) / sizeof(NIDS[0]) - 1; + + while (l <= r) { + const size_t m = l + (r - l) / 2; + const int cmp = std::strcmp(NIDS[m].nid, nid); + if (cmp == 0) { + return &NIDS[m]; + } else if (cmp < 0) { + l = m + 1; + } else { + r = m - 1; + } + } + return nullptr; +} + +} // namespace Core::AeroLib diff --git a/src/core/aerolib/aerolib.h b/src/core/aerolib/aerolib.h new file mode 100644 index 00000000..a07eb4cb --- /dev/null +++ b/src/core/aerolib/aerolib.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace Core::AeroLib { + +struct NidEntry { + const char* nid; + const char* name; +}; + +const NidEntry* FindByNid(const char* nid); + +} // namespace Core::AeroLib diff --git a/src/core/PS4/Util/aerolib.inl b/src/core/aerolib/aerolib.inl similarity index 100% rename from src/core/PS4/Util/aerolib.inl rename to src/core/aerolib/aerolib.inl diff --git a/src/core/PS4/Stubs.cpp b/src/core/aerolib/stubs.cpp similarity index 89% rename from src/core/PS4/Stubs.cpp rename to src/core/aerolib/stubs.cpp index 36afc0a0..e971ae31 100644 --- a/src/core/PS4/Stubs.cpp +++ b/src/core/aerolib/stubs.cpp @@ -1,8 +1,8 @@ -#include "Stubs.h" - -#include "Util/aerolib.h" - #include "common/log.h" +#include "core/aerolib/aerolib.h" +#include "core/aerolib/stubs.h" + +namespace Core::AeroLib { // Helper to provide stub implementations for missing functions // @@ -16,7 +16,7 @@ // and to longer compile / CI times // // Must match STUBS_LIST define -#define MAX_STUBS 128 +constexpr u32 MAX_STUBS = 128; u64 UnresolvedStub() { LOG_ERROR("Unresolved Stub: called, returning zero to {}\n", __builtin_return_address(0)); @@ -29,7 +29,7 @@ static u64 UnknownStub() { } -static aerolib::nid_entry* stub_nids[MAX_STUBS]; +static const NidEntry* stub_nids[MAX_STUBS]; static std::string stub_nids_unknown[MAX_STUBS]; template @@ -69,7 +69,7 @@ u64 GetStub(const char* nid) { return (u64)&UnknownStub; } - auto entry = aerolib::find_by_nid(nid); + const auto entry = FindByNid(nid); if (!entry) { stub_nids_unknown[UsedStubEntries] = nid; } else { @@ -77,4 +77,6 @@ u64 GetStub(const char* nid) { } return (u64)stub_handlers[UsedStubEntries++]; -} \ No newline at end of file +} + +} // namespace Core::AeroLib diff --git a/src/core/aerolib/stubs.h b/src/core/aerolib/stubs.h new file mode 100644 index 00000000..d36154e7 --- /dev/null +++ b/src/core/aerolib/stubs.h @@ -0,0 +1,11 @@ +#pragma once + +#include "common/types.h" + +namespace Core::AeroLib { + +u64 UnresolvedStub(); + +u64 GetStub(const char* nid); + +} // namespace Core::AeroLib diff --git a/src/core/PS4/HLE/ErrorCodes.h b/src/core/hle/error_codes.h similarity index 99% rename from src/core/PS4/HLE/ErrorCodes.h rename to src/core/hle/error_codes.h index 06c3014d..cdb26407 100644 --- a/src/core/PS4/HLE/ErrorCodes.h +++ b/src/core/hle/error_codes.h @@ -1,4 +1,5 @@ #pragma once + constexpr int SCE_OK = 0; constexpr int SCE_KERNEL_ERROR_EBADF = 0x80020009; diff --git a/src/core/PS4/HLE/Kernel/Objects/event_queue.cpp b/src/core/hle/kernel/Objects/event_queue.cpp similarity index 91% rename from src/core/PS4/HLE/Kernel/Objects/event_queue.cpp rename to src/core/hle/kernel/Objects/event_queue.cpp index 4cc99fc8..1a84e06d 100644 --- a/src/core/PS4/HLE/Kernel/Objects/event_queue.cpp +++ b/src/core/hle/kernel/Objects/event_queue.cpp @@ -1,11 +1,10 @@ -#include "event_queue.h" - -#include - #include "common/debug.h" +#include "core/hle/kernel/objects/event_queue.h" +#include "Lib/Timer.h" -namespace HLE::Kernel::Objects { -EqueueInternal::~EqueueInternal() {} +namespace Core::Kernel { + +EqueueInternal::~EqueueInternal() = default; int EqueueInternal::addEvent(const EqueueEvent& event) { std::scoped_lock lock{m_mutex}; @@ -87,4 +86,4 @@ int EqueueInternal::getTriggeredEvents(SceKernelEvent* ev, int num) { return ret; } -}; // namespace HLE::Kernel::Objects \ No newline at end of file +} // namespace Core::Kernel diff --git a/src/core/PS4/HLE/Kernel/Objects/event_queue.h b/src/core/hle/kernel/Objects/event_queue.h similarity index 92% rename from src/core/PS4/HLE/Kernel/Objects/event_queue.h rename to src/core/hle/kernel/Objects/event_queue.h index ade6fbd2..3217bed2 100644 --- a/src/core/PS4/HLE/Kernel/Objects/event_queue.h +++ b/src/core/hle/kernel/Objects/event_queue.h @@ -1,11 +1,11 @@ #pragma once -#include "common/types.h" #include #include #include +#include "common/types.h" -namespace HLE::Kernel::Objects { +namespace Core::Kernel { constexpr s16 EVFILT_READ = -1; constexpr s16 EVFILT_WRITE = -2; @@ -33,11 +33,9 @@ constexpr s16 EVFILT_SYSCOUNT = 22; class EqueueInternal; struct EqueueEvent; -using SceKernelEqueue = Kernel::Objects::EqueueInternal*; - using TriggerFunc = void (*)(EqueueEvent* event, void* trigger_data); using ResetFunc = void (*)(EqueueEvent* event); -using DeleteFunc = void (*)(SceKernelEqueue eq, EqueueEvent* event); +using DeleteFunc = void (*)(EqueueInternal* eq, EqueueEvent* event); struct SceKernelEvent { u64 ident = 0; /* identifier for this event */ @@ -76,4 +74,5 @@ class EqueueInternal { std::vector m_events; std::condition_variable m_cond; }; -}; // namespace HLE::Kernel::Objects + +} // namespace Core::Kernel diff --git a/src/core/PS4/HLE/Kernel/Objects/physical_memory.cpp b/src/core/hle/kernel/Objects/physical_memory.cpp similarity index 80% rename from src/core/PS4/HLE/Kernel/Objects/physical_memory.cpp rename to src/core/hle/kernel/Objects/physical_memory.cpp index a8a41d62..a4bca4c8 100644 --- a/src/core/PS4/HLE/Kernel/Objects/physical_memory.cpp +++ b/src/core/hle/kernel/Objects/physical_memory.cpp @@ -1,10 +1,13 @@ -#include "physical_memory.h" +#include "core/hle/kernel/objects/physical_memory.h" -namespace HLE::Kernel::Objects { +namespace Core::Kernel { -static u64 AlignUp(u64 pos, u64 align) { return (align != 0 ? (pos + (align - 1)) & ~(align - 1) : pos); } +static u64 AlignUp(u64 pos, u64 align) { + return (align != 0 ? (pos + (align - 1)) & ~(align - 1) : pos); +} -bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment, u64* physAddrOut, int memoryType) { +bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment, + u64* physAddrOut, int memoryType) { std::scoped_lock lock{m_mutex}; u64 find_free_pos = 0; @@ -39,7 +42,9 @@ bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignmen return false; } -bool PhysicalMemory::Map(u64 virtual_addr, u64 phys_addr, u64 len, int prot, VirtualMemory::MemoryMode cpu_mode, GPU::MemoryMode gpu_mode) { + +bool PhysicalMemory::Map(u64 virtual_addr, u64 phys_addr, u64 len, int prot, + VirtualMemory::MemoryMode cpu_mode, GPU::MemoryMode gpu_mode) { std::scoped_lock lock{m_mutex}; for (auto& b : m_allocatedBlocks) { if (phys_addr >= b.start_addr && phys_addr < b.start_addr + b.size) { @@ -59,4 +64,5 @@ bool PhysicalMemory::Map(u64 virtual_addr, u64 phys_addr, u64 len, int prot, Vir return false; } -} // namespace HLE::Kernel::Objects + +} // namespace Core::Kernel diff --git a/src/core/PS4/HLE/Kernel/Objects/physical_memory.h b/src/core/hle/kernel/Objects/physical_memory.h similarity index 84% rename from src/core/PS4/HLE/Kernel/Objects/physical_memory.h rename to src/core/hle/kernel/Objects/physical_memory.h index 3c5038a0..200e81d5 100644 --- a/src/core/PS4/HLE/Kernel/Objects/physical_memory.h +++ b/src/core/hle/kernel/Objects/physical_memory.h @@ -1,11 +1,13 @@ #pragma once -#include "common/types.h" -#include -#include + #include #include -namespace HLE::Kernel::Objects { +#include "common/types.h" +#include "core/virtual_memory.h" +#include "core/PS4/GPU/gpu_memory.h" + +namespace Core::Kernel { class PhysicalMemory { public: @@ -31,4 +33,4 @@ class PhysicalMemory { std::mutex m_mutex; }; -} // namespace HLE::Kernel::Objects \ No newline at end of file +} // namespace Core::Kernel diff --git a/src/core/PS4/HLE/Kernel/ThreadManagement.cpp b/src/core/hle/kernel/ThreadManagement.cpp similarity index 95% rename from src/core/PS4/HLE/Kernel/ThreadManagement.cpp rename to src/core/hle/kernel/ThreadManagement.cpp index 2a3ef089..0aef3ce4 100644 --- a/src/core/PS4/HLE/Kernel/ThreadManagement.cpp +++ b/src/core/hle/kernel/ThreadManagement.cpp @@ -1,10 +1,8 @@ -#include "ThreadManagement.h" - #include "common/debug.h" +#include "core/hle/kernel/ThreadManagement.h" +#include "core/hle/error_codes.h" -#include "../ErrorCodes.h" - -namespace HLE::Libs::LibKernel::ThreadManagement { +namespace Core::Kernel { thread_local PthreadInternal* g_pthread_self = nullptr; PThreadCxt* g_pthread_cxt = nullptr; @@ -122,4 +120,4 @@ int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) { return SCE_KERNEL_ERROR_EINVAL; } -}; // namespace HLE::Libs::LibKernel::ThreadManagement \ No newline at end of file +} // namespace Core::Kernel diff --git a/src/core/PS4/HLE/Kernel/ThreadManagement.h b/src/core/hle/kernel/ThreadManagement.h similarity index 88% rename from src/core/PS4/HLE/Kernel/ThreadManagement.h rename to src/core/hle/kernel/ThreadManagement.h index 31e45213..4dd50eb9 100644 --- a/src/core/PS4/HLE/Kernel/ThreadManagement.h +++ b/src/core/hle/kernel/ThreadManagement.h @@ -6,7 +6,7 @@ #include "common/types.h" #include -namespace HLE::Libs::LibKernel::ThreadManagement { +namespace Core::Kernel { struct PthreadAttrInternal; @@ -19,6 +19,7 @@ struct PthreadInternal { pthread_t pth; ScePthreadAttr attr; }; + struct PthreadAttrInternal { u08 reserved[64]; u64 affinity; @@ -32,11 +33,10 @@ class PThreadCxt {}; void Pthread_Init_Self_MainThread(); - //HLE FUNCTIONS int scePthreadAttrInit(ScePthreadAttr* attr); int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate); int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched); int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param); int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy); -} // namespace HLE::Libs::LibKernel::ThreadManagement \ No newline at end of file +} // namespace Core::Kernel diff --git a/src/core/hle/kernel/cpu_management.cpp b/src/core/hle/kernel/cpu_management.cpp new file mode 100644 index 00000000..5ae6e639 --- /dev/null +++ b/src/core/hle/kernel/cpu_management.cpp @@ -0,0 +1,13 @@ +#include "common/log.h" +#include "core/hle/kernel/cpu_management.h" +#include "core/hle/libraries/libs.h" +#include "Util/config.h" + +namespace Core::Kernel { + +int PS4_SYSV_ABI sceKernelIsNeoMode() { + PRINT_FUNCTION_NAME(); + return Config::isNeoMode(); +} + +} // namespace Core::Kernel diff --git a/src/core/PS4/HLE/Kernel/cpu_management.h b/src/core/hle/kernel/cpu_management.h similarity index 58% rename from src/core/PS4/HLE/Kernel/cpu_management.h rename to src/core/hle/kernel/cpu_management.h index e463d316..a8f1d33a 100644 --- a/src/core/PS4/HLE/Kernel/cpu_management.h +++ b/src/core/hle/kernel/cpu_management.h @@ -1,6 +1,9 @@ #pragma once + #include "common/types.h" -namespace HLE::Libs::LibKernel::CPUManagement { +namespace Core::Kernel { + int PS4_SYSV_ABI sceKernelIsNeoMode(); -}; \ No newline at end of file + +} // namespace Core::Kernel diff --git a/src/core/PS4/HLE/Kernel/event_queues.cpp b/src/core/hle/kernel/event_queues.cpp similarity index 74% rename from src/core/PS4/HLE/Kernel/event_queues.cpp rename to src/core/hle/kernel/event_queues.cpp index 61b15344..016b21ed 100644 --- a/src/core/PS4/HLE/Kernel/event_queues.cpp +++ b/src/core/hle/kernel/event_queues.cpp @@ -1,11 +1,11 @@ -#include "event_queues.h" - -#include -#include -#include "common/log.h" #include "common/debug.h" +#include "common/log.h" +#include "core/hle/kernel/event_queues.h" +#include "core/hle/error_codes.h" +#include "core/hle/libraries/libs.h" + +namespace Core::Kernel { -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) { @@ -28,15 +28,15 @@ int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name) { 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 = new EqueueInternal; (*eq)->setName(std::string(name)); LOG_INFO_IF(log_file_equeues, "sceKernelCreateEqueue created with name \"{}\"\n", name); return SCE_OK; } -int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, HLE::Kernel::Objects::SceKernelEvent* ev, int num, int* out, SceKernelUseconds* timo) { +int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev, + int num, int* out, SceKernelUseconds* timo) { PRINT_FUNCTION_NAME(); if (eq == nullptr) { @@ -50,17 +50,22 @@ int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, HLE::Kernel::Objects::S if (num < 1) { return SCE_KERNEL_ERROR_EINVAL; } + if (timo == nullptr) { // wait until an event arrives without timing out *out = eq->waitForEvents(ev, num, 0); } + if (timo != nullptr) { - if (*timo == 0) {//only events that have already arrived at the time of this function call can be received + // Only events that have already arrived at the time of this function call can be received + if (*timo == 0) { BREAKPOINT(); - } else { // wait until an event arrives with timing out + } else { + // Wait until an event arrives with timing out BREAKPOINT(); } } + return SCE_OK; } -}; // namespace HLE::Libs::LibKernel::EventQueues \ No newline at end of file +} // namespace Core::Kernel diff --git a/src/core/hle/kernel/event_queues.h b/src/core/hle/kernel/event_queues.h new file mode 100644 index 00000000..e26be3bc --- /dev/null +++ b/src/core/hle/kernel/event_queues.h @@ -0,0 +1,14 @@ +#pragma once + +#include "core/hle/kernel/objects/event_queue.h" + +namespace Core::Kernel { + +using SceKernelUseconds = u32; +using SceKernelEqueue = EqueueInternal*; + +int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name); +int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev, + int num, int* out, SceKernelUseconds *timo); + +} // namespace Core::Kernel diff --git a/src/core/PS4/HLE/Kernel/memory_management.cpp b/src/core/hle/kernel/memory_management.cpp similarity index 87% rename from src/core/PS4/HLE/Kernel/memory_management.cpp rename to src/core/hle/kernel/memory_management.cpp index 379e4e23..db61d2d6 100644 --- a/src/core/PS4/HLE/Kernel/memory_management.cpp +++ b/src/core/hle/kernel/memory_management.cpp @@ -1,25 +1,22 @@ -#include "memory_management.h" - +#include +#include #include #include #include "common/log.h" #include "common/debug.h" - -#include -#include - #include "common/singleton.h" -#include "../ErrorCodes.h" -#include "../Libs.h" -#include "Objects/physical_memory.h" +#include "core/hle/kernel/memory_management.h" +#include "core/hle/libraries/libs.h" +#include "core/hle/kernel/Objects/physical_memory.h" +#include "core/hle/error_codes.h" -namespace HLE::Libs::LibKernel::MemoryManagement { +namespace Core::Kernel { constexpr bool log_file_memory = true; // disable it to disable logging -bool isPowerOfTwo(u64 n) { return std::popcount(n) == 1; } - -bool is16KBAligned(u64 n) { return ((n % (16ull * 1024) == 0)); } +bool is16KBAligned(u64 n) { + return ((n % (16ull * 1024) == 0)); +} u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() { PRINT_FUNCTION_NAME(); @@ -38,7 +35,7 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL memory range invalid\n"); return SCE_KERNEL_ERROR_EINVAL; } - if ((alignment != 0 || is16KBAligned(alignment)) && !isPowerOfTwo(alignment)) { + if ((alignment != 0 || is16KBAligned(alignment)) && !std::has_single_bit(alignment)) { LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n"); return SCE_KERNEL_ERROR_EINVAL; } @@ -55,7 +52,7 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u LOG_INFO_IF(log_file_memory, "memory_type = {}\n", magic_enum::enum_name(memtype.value())); u64 physical_addr = 0; - auto* physical_memory = Common::Singleton::Instance(); + auto* physical_memory = Common::Singleton::Instance(); if (!physical_memory->Alloc(searchStart, searchEnd, len, alignment, &physical_addr, memoryType)) { LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EAGAIN can't allocate physical memory\n"); return SCE_KERNEL_ERROR_EAGAIN; @@ -76,7 +73,7 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl return SCE_KERNEL_ERROR_EINVAL; } if (alignment != 0) { - if ((!isPowerOfTwo(alignment) && !is16KBAligned(alignment))) { + if ((!std::has_single_bit(alignment) && !is16KBAligned(alignment))) { LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n"); return SCE_KERNEL_ERROR_EINVAL; } @@ -115,7 +112,7 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl return SCE_KERNEL_ERROR_ENOMEM; } - auto* physical_memory = Common::Singleton::Instance(); + auto* physical_memory = Common::Singleton::Instance(); if (!physical_memory->Map(out_addr, directMemoryStart, len, prot, cpu_mode, gpu_mode)) { BREAKPOINT(); } @@ -126,4 +123,4 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl return SCE_OK; } -} // namespace HLE::Libs::LibKernel::MemoryManagement +} // namespace Core::Kernel diff --git a/src/core/PS4/HLE/Kernel/memory_management.h b/src/core/hle/kernel/memory_management.h similarity index 90% rename from src/core/PS4/HLE/Kernel/memory_management.h rename to src/core/hle/kernel/memory_management.h index 80ef67fe..8c2e43ca 100644 --- a/src/core/PS4/HLE/Kernel/memory_management.h +++ b/src/core/hle/kernel/memory_management.h @@ -2,13 +2,9 @@ #include "common/types.h" -// constants - constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 5376_MB; // ~ 6GB -namespace HLE::Libs::LibKernel::MemoryManagement { - -// memory types +namespace Core::Kernel { enum MemoryTypes : u32 { SCE_KERNEL_WB_ONION = 0, // write - back mode (Onion bus) @@ -21,6 +17,7 @@ enum MemoryFlags : u32 { SCE_KERNEL_MAP_NO_OVERWRITE = 0x0080, SCE_KERNEL_MAP_NO_COALESCE = 0x400000 }; + enum MemoryProtection : u32 { SCE_KERNEL_PROT_CPU_READ = 0x01, // Permit reads from the CPU SCE_KERNEL_PROT_CPU_RW = 0x02, // Permit reads/writes from the CPU @@ -33,4 +30,5 @@ enum MemoryProtection : u32 { u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize(); int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len, u64 alignment, int memoryType, s64* physAddrOut); int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags, s64 directMemoryStart, u64 alignment); -}; // namespace HLE::Libs::LibKernel::MemoryManagement \ No newline at end of file + +} // namespace Core::Kernel diff --git a/src/core/hle/libraries/libc/libc.cpp b/src/core/hle/libraries/libc/libc.cpp index 44bdde44..bc55f822 100644 --- a/src/core/hle/libraries/libc/libc.cpp +++ b/src/core/hle/libraries/libc/libc.cpp @@ -1,19 +1,17 @@ -#include "libc.h" - +#include #include "common/debug.h" -#include - #include "common/singleton.h" #include "common/log.h" -#include "core/PS4/HLE/Libs.h" #include "core/hle/libraries/libc/libc.h" #include "core/hle/libraries/libc/libc_cxa.h" #include "core/hle/libraries/libc/libc_math.h" #include "core/hle/libraries/libc/libc_stdio.h" #include "core/hle/libraries/libc/libc_stdlib.h" #include "core/hle/libraries/libc/libc_string.h" +#include "core/hle/libraries/libs.h" namespace Core::Libraries::LibC { + constexpr bool log_file_libc = true; // disable it to disable logging static u32 g_need_sceLibc = 1; @@ -39,28 +37,41 @@ static PS4_SYSV_ABI int __cxa_atexit(void (*func)(void*), void* arg, void* dso_h return 0; } -void PS4_SYSV_ABI __cxa_finalize(void* d) { __debugbreak(); } +void PS4_SYSV_ABI __cxa_finalize(void* d) { + BREAKPOINT(); +} -void PS4_SYSV_ABI __cxa_pure_virtual() { __debugbreak(); } +void PS4_SYSV_ABI __cxa_pure_virtual() { + BREAKPOINT(); +} -static PS4_SYSV_ABI void init_env() { PRINT_DUMMY_FUNCTION_NAME(); } +static PS4_SYSV_ABI void init_env() { + PRINT_DUMMY_FUNCTION_NAME(); +} -static PS4_SYSV_ABI void catchReturnFromMain(int status) { LOG_INFO_IF(log_file_libc, "catchReturnFromMain returned ={}\n", status); } +static PS4_SYSV_ABI void catchReturnFromMain(int status) { + LOG_INFO_IF(log_file_libc, "catchReturnFromMain returned ={}\n", status); +} static PS4_SYSV_ABI void _Assert() { PRINT_DUMMY_FUNCTION_NAME(); BREAKPOINT(); } -PS4_SYSV_ABI void _ZdlPv(void* ptr) { std::free(ptr); } +PS4_SYSV_ABI void _ZdlPv(void* ptr) { + std::free(ptr); +} + PS4_SYSV_ABI void _ZSt11_Xbad_allocv() { PRINT_DUMMY_FUNCTION_NAME(); BREAKPOINT(); } + PS4_SYSV_ABI void _ZSt14_Xlength_errorPKc() { PRINT_DUMMY_FUNCTION_NAME(); BREAKPOINT(); } + PS4_SYSV_ABI void* _Znwm(u64 count) { if (count == 0) { LOG_ERROR_IF(log_file_libc, "_Znwm count ={}\n", count); @@ -70,7 +81,7 @@ PS4_SYSV_ABI void* _Znwm(u64 count) { return ptr; } -void libcSymbolsRegister(SymbolsResolver* sym) { +void libcSymbolsRegister(Loader::SymbolsResolver* sym) { // cxa functions LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1, __cxa_guard_acquire); LIB_FUNCTION("9rAeANT2tyE", "libc", 1, "libc", 1, 1, __cxa_guard_release); diff --git a/src/core/hle/libraries/libc/libc.h b/src/core/hle/libraries/libc/libc.h index 686da34b..522bb111 100644 --- a/src/core/hle/libraries/libc/libc.h +++ b/src/core/hle/libraries/libc/libc.h @@ -1,10 +1,11 @@ #pragma once -#include "common/types.h" -#include "core/PS4/Loader/SymbolsResolver.h" +namespace Core::Loader { +class SymbolsResolver; +} namespace Core::Libraries::LibC { -void libcSymbolsRegister(SymbolsResolver* sym); +void libcSymbolsRegister(Loader::SymbolsResolver* sym); -} // namespace Core::Libraries::LibC \ No newline at end of file +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_cxa.cpp b/src/core/hle/libraries/libc/libc_cxa.cpp index 7fcf3e6c..4c8abd14 100644 --- a/src/core/hle/libraries/libc/libc_cxa.cpp +++ b/src/core/hle/libraries/libc/libc_cxa.cpp @@ -6,6 +6,7 @@ // adapted from https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx.auto.html namespace Core::Libraries::LibC { + constexpr bool log_file_cxa = true; // disable it to disable logging // This file implements the __cxa_guard_* functions as defined at: @@ -145,4 +146,4 @@ void PS4_SYSV_ABI __cxa_guard_abort(u64* guard_object) { setNotInUse(guard_object); } -} // namespace Core::Libraries::LibC \ No newline at end of file +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_cxa.h b/src/core/hle/libraries/libc/libc_cxa.h index 617b8f33..7818b243 100644 --- a/src/core/hle/libraries/libc/libc_cxa.h +++ b/src/core/hle/libraries/libc/libc_cxa.h @@ -5,7 +5,9 @@ #include "common/types.h" namespace Core::Libraries::LibC { + 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 Core::Libraries::LibC \ No newline at end of file + +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_math.cpp b/src/core/hle/libraries/libc/libc_math.cpp index e66c6334..7a18b8e1 100644 --- a/src/core/hle/libraries/libc/libc_math.cpp +++ b/src/core/hle/libraries/libc/libc_math.cpp @@ -1,23 +1,38 @@ -#include "libc_math.h" - #include +#include "core/hle/libraries/libc/libc_math.h" namespace Core::Libraries::LibC { -float PS4_SYSV_ABI atan2f(float y, float x) { return std::atan2f(y, x); } +float PS4_SYSV_ABI atan2f(float y, float x) { + return std::atan2f(y, x); +} -float PS4_SYSV_ABI acosf(float num) { return std::acosf(num); } +float PS4_SYSV_ABI acosf(float num) { + return std::acosf(num); +} -float PS4_SYSV_ABI tanf(float num) { return std::tanf(num); } +float PS4_SYSV_ABI tanf(float num) { + return std::tanf(num); +} -float PS4_SYSV_ABI asinf(float num) { return std::asinf(num); } +float PS4_SYSV_ABI asinf(float num) { + return std::asinf(num); +} -double PS4_SYSV_ABI pow(double base, double exponent) { return std::pow(base, exponent); } +double PS4_SYSV_ABI pow(double base, double exponent) { + return std::pow(base, exponent); +} -double PS4_SYSV_ABI _Sin(double x) { return std::sin(x); } +double PS4_SYSV_ABI _Sin(double x) { + return std::sin(x); +} -float PS4_SYSV_ABI _Fsin(float arg) { return std::sinf(arg); } +float PS4_SYSV_ABI _Fsin(float arg) { + return std::sinf(arg); +} -double PS4_SYSV_ABI exp2(double arg) { return std::exp2(arg); } +double PS4_SYSV_ABI exp2(double arg) { + return std::exp2(arg); +} -} // namespace Core::Libraries::LibC \ No newline at end of file +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_math.h b/src/core/hle/libraries/libc/libc_math.h index bb95ddaf..53a51fd4 100644 --- a/src/core/hle/libraries/libc/libc_math.h +++ b/src/core/hle/libraries/libc/libc_math.h @@ -3,6 +3,7 @@ #include "common/types.h" namespace Core::Libraries::LibC { + float PS4_SYSV_ABI atan2f(float y, float x); float PS4_SYSV_ABI acosf(float num); float PS4_SYSV_ABI tanf(float num); @@ -11,4 +12,5 @@ double PS4_SYSV_ABI pow(double base, double exponent); double PS4_SYSV_ABI _Sin(double x); float PS4_SYSV_ABI _Fsin(float arg); double PS4_SYSV_ABI exp2(double arg); -} // namespace Core::Libraries::LibC \ No newline at end of file + +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_stdio.cpp b/src/core/hle/libraries/libc/libc_stdio.cpp index ea84522e..52e0c26a 100644 --- a/src/core/hle/libraries/libc/libc_stdio.cpp +++ b/src/core/hle/libraries/libc/libc_stdio.cpp @@ -1,15 +1,16 @@ -#include "libc_stdio.h" - #include "common/debug.h" #include "common/log.h" +#include "core/hle/libraries/libc/libc_stdio.h" namespace Core::Libraries::LibC { + constexpr bool log_file_libc = true; // disable it to disable logging int PS4_SYSV_ABI printf(VA_ARGS) { VA_CTX(ctx); return printf_ctx(&ctx); } + int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS) { int fd = _fileno(file); if (fd == 1 || fd == 2) { // output stdout and stderr to console @@ -21,8 +22,12 @@ int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS) { return 0; } -int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg) { return vsnprintf_ctx(s, n, format, arg); } +int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg) { + return vsnprintf_ctx(s, n, format, arg); +} -int PS4_SYSV_ABI puts(const char* s) { return std::puts(s); } +int PS4_SYSV_ABI puts(const char* s) { + return std::puts(s); +} -} // namespace Core::Libraries::LibC \ No newline at end of file +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_stdio.h b/src/core/hle/libraries/libc/libc_stdio.h index 0d403387..20ffbc21 100644 --- a/src/core/hle/libraries/libc/libc_stdio.h +++ b/src/core/hle/libraries/libc/libc_stdio.h @@ -1,12 +1,13 @@ #pragma once #include "common/types.h" - -#include "printf.h" +#include "core/hle/libraries/libc/printf.h" namespace Core::Libraries::LibC { + int PS4_SYSV_ABI printf(VA_ARGS); int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg); int PS4_SYSV_ABI puts(const char* s); int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS); -} // namespace Core::Libraries::LibC \ No newline at end of file + +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_stdlib.cpp b/src/core/hle/libraries/libc/libc_stdlib.cpp index 9ff6177b..d5c32d56 100644 --- a/src/core/hle/libraries/libc/libc_stdlib.cpp +++ b/src/core/hle/libraries/libc/libc_stdlib.cpp @@ -1,14 +1,15 @@ -#include "libc_stdlib.h" - +#include #include "common/log.h" #include "common/debug.h" - -#include +#include "core/hle/libraries/libc/libc_stdlib.h" namespace Core::Libraries::LibC { + constexpr bool log_file_libc = true; // disable it to disable logging -void PS4_SYSV_ABI exit(int code) { std::exit(code); } +void PS4_SYSV_ABI exit(int code) { + std::exit(code); +} int PS4_SYSV_ABI atexit(void (*func)()) { int rt = std::atexit(func); @@ -19,19 +20,28 @@ int PS4_SYSV_ABI atexit(void (*func)()) { return rt; } -void* PS4_SYSV_ABI malloc(size_t size) { return std::malloc(size); } +void* PS4_SYSV_ABI malloc(size_t size) { + return std::malloc(size); +} -void PS4_SYSV_ABI free(void* ptr) { std::free(ptr); } +void PS4_SYSV_ABI free(void* ptr) { + std::free(ptr); +} typedef int(PS4_SYSV_ABI* pfunc_QsortCmp)(const void*, const void*); thread_local static pfunc_QsortCmp compair_ps4; -int qsort_compair(const void* arg1, const void* arg2) { return compair_ps4(arg1, arg2); } +int qsort_compair(const void* arg1, const void* arg2) { + return compair_ps4(arg1, arg2); +} void PS4_SYSV_ABI qsort(void* ptr, size_t count, size_t size, int(PS4_SYSV_ABI* comp)(const void*, const void*)) { compair_ps4 = comp; std::qsort(ptr, count, size, qsort_compair); } -int PS4_SYSV_ABI rand() { return std::rand(); } -} // namespace Core::Libraries::LibC +int PS4_SYSV_ABI rand() { + return std::rand(); +} + +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_stdlib.h b/src/core/hle/libraries/libc/libc_stdlib.h index 04cb3dd4..5704d648 100644 --- a/src/core/hle/libraries/libc/libc_stdlib.h +++ b/src/core/hle/libraries/libc/libc_stdlib.h @@ -1,14 +1,15 @@ #pragma once +#include #include "common/types.h" -#include - namespace Core::Libraries::LibC { + void PS4_SYSV_ABI exit(int code); int PS4_SYSV_ABI atexit(void (*func)()); void* PS4_SYSV_ABI malloc(size_t size); void PS4_SYSV_ABI free(void* ptr); void PS4_SYSV_ABI qsort(void* ptr, size_t count, size_t size, int(PS4_SYSV_ABI* comp)(const void*, const void*)); int PS4_SYSV_ABI rand(); -} // namespace Core::Libraries::LibC + +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_string.cpp b/src/core/hle/libraries/libc/libc_string.cpp index 8cfffd1d..3effa7bf 100644 --- a/src/core/hle/libraries/libc/libc_string.cpp +++ b/src/core/hle/libraries/libc/libc_string.cpp @@ -1,25 +1,42 @@ -#include "libc_string.h" - #include +#include "core/hle/libraries/libc/libc_string.h" namespace Core::Libraries::LibC { -int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n) { return std::memcmp(s1, s2, n); } +int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n) { + return std::memcmp(s1, s2, n); +} -void* PS4_SYSV_ABI memcpy(void* dest, const void* src, size_t n) { return std::memcpy(dest, src, n); } +void* PS4_SYSV_ABI memcpy(void* dest, const void* src, size_t n) { + return std::memcpy(dest, src, n); +} -void* PS4_SYSV_ABI memset(void* s, int c, size_t n) { return std::memset(s, c, n); } +void* PS4_SYSV_ABI memset(void* s, int c, size_t n) { + return std::memset(s, c, n); +} -int PS4_SYSV_ABI strcmp(const char* str1, const char* str2) { return std::strcmp(str1, str2); } +int PS4_SYSV_ABI strcmp(const char* str1, const char* str2) { + return std::strcmp(str1, str2); +} -char* PS4_SYSV_ABI strncpy(char* dest, const char* src, size_t count) { return std::strncpy(dest, src, count); } +char* PS4_SYSV_ABI strncpy(char* dest, const char* src, size_t count) { + return std::strncpy(dest, src, count); +} -void* PS4_SYSV_ABI memmove(void* dest, const void* src, std::size_t count) { return std::memmove(dest, src, count); } +void* PS4_SYSV_ABI memmove(void* dest, const void* src, std::size_t count) { + return std::memmove(dest, src, count); +} -char* PS4_SYSV_ABI strcpy(char* dest, const char* src) { return std::strcpy(dest, src); } +char* PS4_SYSV_ABI strcpy(char* dest, const char* src) { + return std::strcpy(dest, src); +} -char* PS4_SYSV_ABI strcat(char* dest, const char* src) { return std::strcat(dest, src); } +char* PS4_SYSV_ABI strcat(char* dest, const char* src) { + return std::strcat(dest, src); +} -size_t PS4_SYSV_ABI strlen(const char* str) { return std::strlen(str); } +size_t PS4_SYSV_ABI strlen(const char* str) { + return std::strlen(str); +} -} // namespace Core::Libraries::LibC +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/libc_string.h b/src/core/hle/libraries/libc/libc_string.h index ff7c9e6e..b5c29e23 100644 --- a/src/core/hle/libraries/libc/libc_string.h +++ b/src/core/hle/libraries/libc/libc_string.h @@ -1,10 +1,10 @@ #pragma once +#include #include "common/types.h" -#include - namespace Core::Libraries::LibC { + int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n); void* PS4_SYSV_ABI memcpy(void* dest, const void* src, size_t n); void* PS4_SYSV_ABI memset(void* s, int c, size_t n); @@ -14,4 +14,5 @@ void* PS4_SYSV_ABI memmove(void* dest, const void* src, std::size_t count); char* PS4_SYSV_ABI strcpy(char* destination, const char* source); char* PS4_SYSV_ABI strcat(char* dest, const char* src); size_t PS4_SYSV_ABI strlen(const char* str); -} // namespace Core::Libraries::LibC \ No newline at end of file + +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libc/va_ctx.h b/src/core/hle/libraries/libc/va_ctx.h index 12324cfd..d17e1e58 100644 --- a/src/core/hle/libraries/libc/va_ctx.h +++ b/src/core/hle/libraries/libc/va_ctx.h @@ -103,4 +103,4 @@ T* vaArgPtr(VaList* l) { return vaArgOverflowArgArea(l); } -} // namespace Core::Libraries::LibC \ No newline at end of file +} // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libkernel/file_system.cpp b/src/core/hle/libraries/libkernel/file_system.cpp index 311ff094..271cf363 100644 --- a/src/core/hle/libraries/libkernel/file_system.cpp +++ b/src/core/hle/libraries/libkernel/file_system.cpp @@ -1,10 +1,10 @@ -#include "file_system.h" - -#include #include "common/log.h" #include "common/debug.h" +#include "core/hle/libraries/libkernel/file_system.h" +#include "core/hle/libraries/libs.h" namespace Core::Libraries::LibKernel { + constexpr bool log_file_fs = true; // disable it to disable logging int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) { @@ -21,9 +21,9 @@ int PS4_SYSV_ABI open(const char* path, int flags, /* SceKernelMode*/ u16 mode) return result; } -void fileSystemSymbolsRegister(SymbolsResolver* sym) { +void fileSystemSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("1G3lF1Gg1k8", "libkernel", 1, "libkernel", 1, 1, sceKernelOpen); LIB_FUNCTION("wuCroIGjt2g", "libScePosix", 1, "libkernel", 1, 1, open); } -} // namespace Core::Libraries::LibKernel \ No newline at end of file +} // namespace Core::Libraries::LibKernel diff --git a/src/core/hle/libraries/libkernel/file_system.h b/src/core/hle/libraries/libkernel/file_system.h index 4956a075..f5be1d1e 100644 --- a/src/core/hle/libraries/libkernel/file_system.h +++ b/src/core/hle/libraries/libkernel/file_system.h @@ -1,13 +1,17 @@ #pragma once + #include "common/types.h" -#include "core/PS4/Loader/SymbolsResolver.h" + +namespace Core::Loader { +class SymbolsResolver; +} namespace Core::Libraries::LibKernel { + int PS4_SYSV_ABI sceKernelOpen(const char *path, int flags, /* SceKernelMode*/ u16 mode); -// posix file system int PS4_SYSV_ABI open(const char *path, int flags, /* SceKernelMode*/ u16 mode); +void fileSystemSymbolsRegister(Loader::SymbolsResolver *sym); -void fileSystemSymbolsRegister(SymbolsResolver *sym); -} // namespace Core::Libraries::LibKernel \ No newline at end of file +} // namespace Core::Libraries::LibKernel diff --git a/src/core/PS4/HLE/LibKernel.cpp b/src/core/hle/libraries/libkernel/libkernel.cpp similarity index 57% rename from src/core/PS4/HLE/LibKernel.cpp rename to src/core/hle/libraries/libkernel/libkernel.cpp index 2a4a4bf6..65b96dcd 100644 --- a/src/core/PS4/HLE/LibKernel.cpp +++ b/src/core/hle/libraries/libkernel/libkernel.cpp @@ -1,20 +1,21 @@ -#include "LibKernel.h" - #include "common/log.h" #include "common/debug.h" -#include - #include "common/singleton.h" -#include "../Loader/Elf.h" -#include "Kernel/Objects/physical_memory.h" -#include "Kernel/cpu_management.h" -#include "Kernel/event_queues.h" -#include "Kernel/memory_management.h" -#include "Libs.h" +#include "core/loader/elf.h" +#include "core/hle/kernel/Objects/physical_memory.h" +#include "core/hle/kernel/cpu_management.h" +#include "core/hle/kernel/event_queues.h" +#include "core/hle/kernel/memory_management.h" +#include "core/hle/libraries/libkernel/libkernel.h" #include "core/hle/libraries/libkernel/file_system.h" #include "core/hle/libraries/libkernel/time_management.h" +#include "core/hle/libraries/libs.h" -namespace HLE::Libs::LibKernel { +#ifdef _WIN64 +#include +#endif + +namespace Core::Libraries::LibKernel { static u64 g_stack_chk_guard = 0xDEADBEEF54321ABC; // dummy return @@ -23,27 +24,32 @@ int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len) { return 0; } -static PS4_SYSV_ABI void stack_chk_fail() { BREAKPOINT(); } +static PS4_SYSV_ABI void stack_chk_fail() { + BREAKPOINT(); +} -int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) { BREAKPOINT(); } -void LibKernel_Register(SymbolsResolver* sym) { +int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) { + BREAKPOINT(); +} + +void LibKernel_Register(Loader::SymbolsResolver* sym) { // obj - LIB_OBJ("f7uOxY9mM1U", "libkernel", 1, "libkernel", 1, 1, &HLE::Libs::LibKernel::g_stack_chk_guard); + LIB_OBJ("f7uOxY9mM1U", "libkernel", 1, "libkernel", 1, 1, &g_stack_chk_guard); // memory - LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, MemoryManagement::sceKernelAllocateDirectMemory); - LIB_FUNCTION("pO96TwzOm5E", "libkernel", 1, "libkernel", 1, 1, MemoryManagement::sceKernelGetDirectMemorySize); - LIB_FUNCTION("L-Q3LEjIbgA", "libkernel", 1, "libkernel", 1, 1, MemoryManagement::sceKernelMapDirectMemory); + LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelAllocateDirectMemory); + LIB_FUNCTION("pO96TwzOm5E", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelGetDirectMemorySize); + LIB_FUNCTION("L-Q3LEjIbgA", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelMapDirectMemory); LIB_FUNCTION("MBuItvba6z8", "libkernel", 1, "libkernel", 1, 1, sceKernelReleaseDirectMemory); LIB_FUNCTION("cQke9UuBQOk", "libkernel", 1, "libkernel", 1, 1, sceKernelMunmap); // equeue - LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, EventQueues::sceKernelCreateEqueue); - LIB_FUNCTION("fzyMKs9kim0", "libkernel", 1, "libkernel", 1, 1, EventQueues::sceKernelWaitEqueue); + LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelCreateEqueue); + LIB_FUNCTION("fzyMKs9kim0", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelWaitEqueue); // misc - LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, CPUManagement::sceKernelIsNeoMode); + LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelIsNeoMode); LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail); Core::Libraries::LibKernel::fileSystemSymbolsRegister(sym); Core::Libraries::LibKernel::timeSymbolsRegister(sym); } -}; // namespace HLE::Libs::LibKernel \ No newline at end of file +} // namespace Core::Libraries::LibKernel diff --git a/src/core/hle/libraries/libkernel/libkernel.h b/src/core/hle/libraries/libkernel/libkernel.h new file mode 100644 index 00000000..a10adbb3 --- /dev/null +++ b/src/core/hle/libraries/libkernel/libkernel.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include "common/types.h" + +namespace Core::Loader { +class SymbolsResolver; +} + +namespace Core::Libraries::LibKernel { + +int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len); + +void LibKernel_Register(Loader::SymbolsResolver* sym); + +} // namespace Core::Libraries::LibKernel diff --git a/src/core/hle/libraries/libkernel/time_management.cpp b/src/core/hle/libraries/libkernel/time_management.cpp index 77665812..bb062b71 100644 --- a/src/core/hle/libraries/libkernel/time_management.cpp +++ b/src/core/hle/libraries/libkernel/time_management.cpp @@ -1,20 +1,27 @@ -#include "time_management.h" - -#include +#include "core/hle/libraries/libkernel/time_management.h" +#include "core/hle/libraries/libs.h" #include "Lib/Timer.h" #include "emuTimer.h" namespace Core::Libraries::LibKernel { + u64 PS4_SYSV_ABI sceKernelGetProcessTime() { return static_cast(Emulator::emuTimer::getTimeMsec() * 1000.0); // return time in microseconds } -u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounter() { return Emulator::emuTimer::getTimeCounter(); } -u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounterFrequency() { return Emulator::emuTimer::getTimeFrequency(); } +u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounter() { + return Emulator::emuTimer::getTimeCounter(); +} -u64 PS4_SYSV_ABI sceKernelReadTsc() { return Lib::Timer::getQueryPerformanceCounter(); } +u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounterFrequency() { + return Emulator::emuTimer::getTimeFrequency(); +} -void timeSymbolsRegister(SymbolsResolver* sym) { +u64 PS4_SYSV_ABI sceKernelReadTsc() { + return Lib::Timer::getQueryPerformanceCounter(); +} + +void timeSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("4J2sUJmuHZQ", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTime); LIB_FUNCTION("fgxnMeTNUtY", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTimeCounter); LIB_FUNCTION("BNowx2l588E", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTimeCounterFrequency); diff --git a/src/core/hle/libraries/libkernel/time_management.h b/src/core/hle/libraries/libkernel/time_management.h index 29660af5..a3e6ee9f 100644 --- a/src/core/hle/libraries/libkernel/time_management.h +++ b/src/core/hle/libraries/libkernel/time_management.h @@ -1,13 +1,18 @@ #pragma once #include "common/types.h" -#include "core/PS4/Loader/SymbolsResolver.h" + +namespace Core::Loader { +class SymbolsResolver; +} namespace Core::Libraries::LibKernel { + u64 PS4_SYSV_ABI sceKernelGetProcessTime(); u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounter(); u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounterFrequency(); u64 PS4_SYSV_ABI sceKernelReadTsc(); -void timeSymbolsRegister(SymbolsResolver* sym); -} \ No newline at end of file +void timeSymbolsRegister(Loader::SymbolsResolver* sym); + +} // namespace Core::Libraries::LibKernel diff --git a/src/core/hle/libraries/libpad/pad.cpp b/src/core/hle/libraries/libpad/pad.cpp index 298dd52d..670422fb 100644 --- a/src/core/hle/libraries/libpad/pad.cpp +++ b/src/core/hle/libraries/libpad/pad.cpp @@ -1,18 +1,17 @@ -#include "pad.h" - -#include -#include - -#include "common/singleton.h" -#include "Emulator/Host/controller.h" -#include "common/debug.h" #include "common/log.h" +#include "common/singleton.h" +#include "core/hle/libraries/libpad/pad.h" +#include "core/hle/error_codes.h" +#include "core/hle/libraries/libs.h" +#include "Emulator/Host/controller.h" namespace Core::Libraries::LibPad { constexpr bool log_file_pad = true; // disable it to disable logging -int PS4_SYSV_ABI scePadInit() { return SCE_OK; } +int PS4_SYSV_ABI scePadInit() { + return SCE_OK; +} int PS4_SYSV_ABI scePadOpen(Core::Libraries::LibUserService::SceUserServiceUserId userId, s32 type, s32 index, const ScePadOpenParam* pParam) { @@ -47,7 +46,7 @@ int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) { return SCE_OK; } -void padSymbolsRegister(SymbolsResolver* sym) { +void padSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("hv1luiJrqQM", "libScePad", 1, "libScePad", 1, 1, scePadInit); LIB_FUNCTION("xk0AcarP3V4", "libScePad", 1, "libScePad", 1, 1, scePadOpen); LIB_FUNCTION("YndgXqQVV7c", "libScePad", 1, "libScePad", 1, 1, scePadReadState); diff --git a/src/core/hle/libraries/libpad/pad.h b/src/core/hle/libraries/libpad/pad.h index ffdfec6a..b1d9f51f 100644 --- a/src/core/hle/libraries/libpad/pad.h +++ b/src/core/hle/libraries/libpad/pad.h @@ -1,30 +1,29 @@ #pragma once -#include "common/types.h" -#include "core/PS4/Loader/SymbolsResolver.h" -#include "core/hle/libraries/libuserservice/user_service.h" +#include "common/types.h" +#include "core/hle/libraries/libuserservice/libuserservice.h" namespace Core::Libraries::LibPad { -typedef enum : u32 { - SCE_PAD_BUTTON_L3 = 0x00000002, - SCE_PAD_BUTTON_R3 = 0x00000004, - SCE_PAD_BUTTON_OPTIONS = 0x00000008, - SCE_PAD_BUTTON_UP = 0x00000010, - SCE_PAD_BUTTON_RIGHT = 0x00000020, - SCE_PAD_BUTTON_DOWN = 0x00000040, - SCE_PAD_BUTTON_LEFT = 0x00000080, - SCE_PAD_BUTTON_L2 = 0x00000100, - SCE_PAD_BUTTON_R2 = 0x00000200, - SCE_PAD_BUTTON_L1 = 0x00000400, - SCE_PAD_BUTTON_R1 = 0x00000800, - SCE_PAD_BUTTON_TRIANGLE = 0x00001000, - SCE_PAD_BUTTON_CIRCLE = 0x00002000, - SCE_PAD_BUTTON_CROSS = 0x00004000, - SCE_PAD_BUTTON_SQUARE = 0x00008000, - SCE_PAD_BUTTON_TOUCH_PAD = 0x00100000, - SCE_PAD_BUTTON_INTERCEPTED = 0x80000000, -} ScePadButton; +enum ScePadButton : u32 { + L3 = 0x00000002, + R3 = 0x00000004, + OPTIONS = 0x00000008, + UP = 0x00000010, + RIGHT = 0x00000020, + DOWN = 0x00000040, + LEFT = 0x00000080, + L2 = 0x00000100, + R2 = 0x00000200, + L1 = 0x00000400, + R1 = 0x00000800, + TRIANGLE = 0x00001000, + CIRCLE = 0x00002000, + CROSS = 0x00004000, + SQUARE = 0x00008000, + TOUCH_PAD = 0x00100000, + INTERCEPTED = 0x80000000, +}; struct ScePadOpenParam { u08 reserve[8]; @@ -88,11 +87,12 @@ struct ScePadData { uint8_t deviceUniqueDataLen; uint8_t deviceUniqueData[12]; }; -// hle functions + int PS4_SYSV_ABI scePadInit(); -int PS4_SYSV_ABI scePadOpen(Core::Libraries::LibUserService::SceUserServiceUserId userId, s32 type, s32 index, +int PS4_SYSV_ABI scePadOpen(LibUserService::SceUserServiceUserId userId, s32 type, s32 index, const ScePadOpenParam* pParam); int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData); -void padSymbolsRegister(SymbolsResolver* sym); -}; // namespace Core::Libraries::LibPad \ No newline at end of file +void padSymbolsRegister(Loader::SymbolsResolver* sym); + +}; // namespace Core::Libraries::LibPad diff --git a/src/core/hle/libraries/libs.cpp b/src/core/hle/libraries/libs.cpp new file mode 100644 index 00000000..815a7c54 --- /dev/null +++ b/src/core/hle/libraries/libs.cpp @@ -0,0 +1,22 @@ +#include "core/hle/libraries/libs.h" +#include "core/PS4/HLE/Graphics/video_out.h" +#include "core/hle/libraries/libkernel/libkernel.h" +#include "core/hle/libraries/libscegnmdriver/libscegnmdriver.h" +#include "core/hle/libraries/libuserservice/libuserservice.h" +#include "core/hle/libraries/libpad/pad.h" +#include "core/hle/libraries/libsystemservice/system_service.h" +#include "core/hle/libraries/libc/libc.h" + +namespace Core::Libraries { + +void InitHLELibs(Loader::SymbolsResolver* sym) { + LibKernel::LibKernel_Register(sym); + HLE::Libs::Graphics::VideoOut::videoOutRegisterLib(sym); + LibSceGnmDriver::LibSceGnmDriver_Register(sym); + LibUserService::userServiceSymbolsRegister(sym); + LibPad::padSymbolsRegister(sym); + LibSystemService::systemServiceSymbolsRegister(sym); + LibC::libcSymbolsRegister(sym); +} + +} // namespace Core::Libraries diff --git a/src/core/PS4/HLE/Libs.h b/src/core/hle/libraries/libs.h similarity index 86% rename from src/core/PS4/HLE/Libs.h rename to src/core/hle/libraries/libs.h index be663939..dc88423b 100644 --- a/src/core/PS4/HLE/Libs.h +++ b/src/core/hle/libraries/libs.h @@ -1,10 +1,11 @@ #pragma once -#include "../Loader/SymbolsResolver.h" -#include + +#include "core/loader/elf.h" +#include "core/loader/symbols_resolver.h" #define LIB_FUNCTION(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \ {\ - SymbolRes sr{}; \ + Loader::SymbolRes sr{}; \ sr.name = nid; \ sr.library = lib; \ sr.library_version = libversion;\ @@ -18,7 +19,7 @@ #define LIB_OBJ(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \ { \ - SymbolRes sr{}; \ + Loader::SymbolRes sr{}; \ sr.name = nid; \ sr.library = lib; \ sr.library_version = libversion; \ @@ -38,6 +39,8 @@ #define PRINT_DUMMY_FUNCTION_NAME() \ { LOG_WARN_IF(true, "dummy {}()\n", __func__); } -namespace HLE::Libs { - void Init_HLE_Libs(SymbolsResolver* sym); -} \ No newline at end of file +namespace Core::Libraries { + +void InitHLELibs(Loader::SymbolsResolver* sym); + +} // namespace Core::Libraries diff --git a/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp b/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp new file mode 100644 index 00000000..3205433f --- /dev/null +++ b/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp @@ -0,0 +1,24 @@ +#include "common/log.h" +#include "core/PS4/GPU/gpu_memory.h" +#include "core/hle/libraries/libscegnmdriver/libscegnmdriver.h" +#include "core/hle/libraries/libs.h" +#include "emulator.h" + +namespace Core::Libraries::LibSceGnmDriver { + +int32_t sceGnmSubmitDone() { + PRINT_DUMMY_FUNCTION_NAME(); + return 0; +} + +void sceGnmFlushGarlic() { + PRINT_FUNCTION_NAME(); + GPU::flushGarlic(Emu::getGraphicCtx()); +} + +void LibSceGnmDriver_Register(Loader::SymbolsResolver* sym) { + LIB_FUNCTION("yvZ73uQUqrk", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmSubmitDone); + LIB_FUNCTION("iBt3Oe00Kvc", "libSceGnmDriver", 1, "libSceGnmDriver", 1, 1, sceGnmFlushGarlic); +} + +}; diff --git a/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h b/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h new file mode 100644 index 00000000..810d49af --- /dev/null +++ b/src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h @@ -0,0 +1,16 @@ +#pragma once + +#include "common/types.h" + +namespace Core::Loader { +class SymbolsResolver; +} + +namespace Core::Libraries::LibSceGnmDriver { + +int32_t sceGnmSubmitDone(); +void sceGnmFlushGarlic(); + +void LibSceGnmDriver_Register(Loader::SymbolsResolver* sym); + +}; // namespace Core::Libraries::LibSceGnmDriver diff --git a/src/core/hle/libraries/libsystemservice/system_service.cpp b/src/core/hle/libraries/libsystemservice/system_service.cpp index 5517bcdb..85023606 100644 --- a/src/core/hle/libraries/libsystemservice/system_service.cpp +++ b/src/core/hle/libraries/libsystemservice/system_service.cpp @@ -1,7 +1,7 @@ -#include -#include #include "common/log.h" -#include "system_service.h" +#include "core/hle/error_codes.h" +#include "core/hle/libraries/libs.h" +#include "core/hle/libraries/libsystemservice/system_service.h" namespace Core::Libraries::LibSystemService { @@ -10,7 +10,9 @@ s32 PS4_SYSV_ABI sceSystemServiceHideSplashScreen() { return SCE_OK; } -void systemServiceSymbolsRegister(SymbolsResolver* sym) { - LIB_FUNCTION("Vo5V8KAwCmk", "libSceSystemService", 1, "libSceSystemService", 1, 1, sceSystemServiceHideSplashScreen); +void systemServiceSymbolsRegister(Loader::SymbolsResolver* sym) { + LIB_FUNCTION("Vo5V8KAwCmk", "libSceSystemService", 1, "libSceSystemService", 1, 1, + sceSystemServiceHideSplashScreen); } -}; // namespace Emulator::HLE::Libraries::LibUserService \ No newline at end of file + +}; // namespace Core::Libraries::LibSystemService diff --git a/src/core/hle/libraries/libsystemservice/system_service.h b/src/core/hle/libraries/libsystemservice/system_service.h index c786a848..1b31cab3 100644 --- a/src/core/hle/libraries/libsystemservice/system_service.h +++ b/src/core/hle/libraries/libsystemservice/system_service.h @@ -1,11 +1,15 @@ #pragma once -#include "core/PS4/Loader/SymbolsResolver.h" + +#include "common/types.h" + +namespace Core::Loader { +class SymbolsResolver; +} namespace Core::Libraries::LibSystemService { -//HLE functions s32 PS4_SYSV_ABI sceSystemServiceHideSplashScreen(); -void systemServiceSymbolsRegister(SymbolsResolver* sym); +void systemServiceSymbolsRegister(Loader::SymbolsResolver* sym); -}; // namespace Emulator::HLE::Libraries::LibUserService \ No newline at end of file +}; // namespace Core::Libraries::LibSystemService diff --git a/src/core/hle/libraries/libuserservice/user_service.cpp b/src/core/hle/libraries/libuserservice/libuserservice.cpp similarity index 75% rename from src/core/hle/libraries/libuserservice/user_service.cpp rename to src/core/hle/libraries/libuserservice/libuserservice.cpp index 314d052f..bcef432c 100644 --- a/src/core/hle/libraries/libuserservice/user_service.cpp +++ b/src/core/hle/libraries/libuserservice/libuserservice.cpp @@ -1,9 +1,7 @@ -#include "user_service.h" - -#include -#include - #include "common/log.h" +#include "core/hle/libraries/libuserservice/libuserservice.h" +#include "core/hle/error_codes.h" +#include "core/hle/libraries/libs.h" namespace Core::Libraries::LibUserService { @@ -21,9 +19,10 @@ s32 PS4_SYSV_ABI sceUserServiceGetLoginUserIdList(SceUserServiceLoginUserIdList* return SCE_OK; } -void userServiceSymbolsRegister(SymbolsResolver* sym) { + +void userServiceSymbolsRegister(Loader::SymbolsResolver* sym) { LIB_FUNCTION("j3YMu1MVNNo", "libSceUserService", 1, "libSceUserService", 1, 1, sceUserServiceInitialize); LIB_FUNCTION("fPhymKNvK-A", "libSceUserService", 1, "libSceUserService", 1, 1, sceUserServiceGetLoginUserIdList); } -} // namespace Core::Libraries::LibUserService +} // namespace Core::Libraries::LibUserService diff --git a/src/core/hle/libraries/libuserservice/user_service.h b/src/core/hle/libraries/libuserservice/libuserservice.h similarity index 68% rename from src/core/hle/libraries/libuserservice/user_service.h rename to src/core/hle/libraries/libuserservice/libuserservice.h index 4a386946..a61c2be2 100644 --- a/src/core/hle/libraries/libuserservice/user_service.h +++ b/src/core/hle/libraries/libuserservice/libuserservice.h @@ -1,5 +1,10 @@ #pragma once -#include "core/PS4/Loader/SymbolsResolver.h" + +#include "common/types.h" + +namespace Core::Loader { +class SymbolsResolver; +} namespace Core::Libraries::LibUserService { @@ -16,5 +21,6 @@ struct SceUserServiceLoginUserIdList { s32 PS4_SYSV_ABI sceUserServiceInitialize(const SceUserServiceInitializeParams* initParams); s32 PS4_SYSV_ABI sceUserServiceGetLoginUserIdList(SceUserServiceLoginUserIdList* userIdList); -void userServiceSymbolsRegister(SymbolsResolver* sym); -}; // namespace Emulator::HLE::Libraries::LibUserService \ No newline at end of file +void userServiceSymbolsRegister(Loader::SymbolsResolver* sym); + +}; // namespace Core::Libraries::LibUserService diff --git a/src/core/PS4/HLE/UserManagement/UsrMngCodes.h b/src/core/hle/libraries/libuserservice/usr_mng_codes.h similarity index 100% rename from src/core/PS4/HLE/UserManagement/UsrMngCodes.h rename to src/core/hle/libraries/libuserservice/usr_mng_codes.h diff --git a/src/core/PS4/Linker.cpp b/src/core/linker.cpp similarity index 96% rename from src/core/PS4/Linker.cpp rename to src/core/linker.cpp index d4c48305..18809e41 100644 --- a/src/core/PS4/Linker.cpp +++ b/src/core/linker.cpp @@ -1,13 +1,14 @@ -#include "Linker.h" -#include "../virtual_memory.h" -#include "common/log.h" #include #include +#include "common/log.h" #include "common/string_util.h" -#include "Util/aerolib.h" -#include "Loader/SymbolsResolver.h" -#include "HLE/Kernel/ThreadManagement.h" -#include "Stubs.h" +#include "core/aerolib/aerolib.h" +#include "core/aerolib/stubs.h" +#include "core/linker.h" +#include "core/virtual_memory.h" +#include "core/hle/kernel/ThreadManagement.h" + +namespace Core { constexpr bool debug_loader = true; @@ -452,7 +453,7 @@ void Linker::LoadSymbols(Module* m) bool is_sym_export = sym->st_value != 0; std::string nidName = ""; - auto aeronid = aerolib::find_by_nid(ids.at(0).c_str()); + auto aeronid = AeroLib::FindByNid(ids.at(0).c_str()); if (aeronid != nullptr) { @@ -463,7 +464,7 @@ void Linker::LoadSymbols(Module* m) nidName = "UNK"; } - SymbolRes sym_r{}; + Loader::SymbolRes sym_r{}; sym_r.name = ids.at(0); sym_r.nidName = nidName; sym_r.library = library->name; @@ -519,7 +520,7 @@ static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) { auto sym_type = sym.GetType(); auto sym_visibility = sym.GetVisibility(); u64 symbol_vitrual_addr = 0; - SymbolRecord symrec{}; + Loader::SymbolRecord symrec{}; switch (sym_type) { case STT_FUN: rel_sym_type = 2; break; case STT_OBJECT: rel_sym_type = 1; break; @@ -575,7 +576,7 @@ void Linker::Relocate(Module* m) } } -void Linker::Resolve(const std::string& name, int Symtype, Module* m, SymbolRecord* return_info) { +void Linker::Resolve(const std::string& name, int Symtype, Module* m, Loader::SymbolRecord* return_info) { const auto ids = Common::SplitString(name, '#'); if (ids.size() == 3) // symbols are 3 parts name , library , module { @@ -583,7 +584,7 @@ void Linker::Resolve(const std::string& name, int Symtype, Module* m, SymbolReco const auto* module = FindModule(*m, ids.at(2)); if (library != nullptr && module != nullptr) { - SymbolRes sr{}; + Loader::SymbolRes sr{}; sr.name = ids.at(0); sr.library = library->name; sr.library_version = library->version; @@ -592,18 +593,18 @@ void Linker::Resolve(const std::string& name, int Symtype, Module* m, SymbolReco sr.module_version_minor = module->version_minor; sr.type = Symtype; - const SymbolRecord* rec = nullptr; + const Loader::SymbolRecord* rec = nullptr; rec = m_hle_symbols.FindSymbol(sr); if (rec != nullptr) { *return_info = *rec; } else { - auto aeronid = aerolib::find_by_nid(sr.name.c_str()); + auto aeronid = AeroLib::FindByNid(sr.name.c_str()); if (aeronid) { return_info->name = aeronid->name; - return_info->virtual_address = GetStub(aeronid->nid); + return_info->virtual_address = AeroLib::GetStub(aeronid->nid); } else { - return_info->virtual_address = GetStub(sr.name.c_str()); + return_info->virtual_address = AeroLib::GetStub(sr.name.c_str()); return_info->name = "Unknown !!!"; } LOG_ERROR_IF(debug_loader, "Linker: Stub resolved {} as {} (lib: {}, mod: {}) \n", sr.name, return_info->name, library->name, module->name); @@ -652,9 +653,8 @@ static void run_main_entry(u64 addr, EntryParams* params, exit_func_t exit_func) ); } -void Linker::Execute() -{ - HLE::Libs::LibKernel::ThreadManagement::Pthread_Init_Self_MainThread(); +void Linker::Execute() { + Core::Kernel::Pthread_Init_Self_MainThread(); EntryParams p{}; p.argc = 1; p.argv[0] = "eboot.bin"; //hmm should be ok? @@ -662,3 +662,5 @@ void Linker::Execute() const auto& module = m_modules.at(0); run_main_entry(module.elf.GetElfEntry() + module.base_virtual_addr, &p, ProgramExitFunc); } + +} // namespace Core diff --git a/src/core/PS4/Linker.h b/src/core/linker.h similarity index 82% rename from src/core/PS4/Linker.h rename to src/core/linker.h index b9872995..0d2672c3 100644 --- a/src/core/PS4/Linker.h +++ b/src/core/linker.h @@ -2,8 +2,10 @@ #include #include -#include "Loader/Elf.h" -#include "Loader/SymbolsResolver.h" +#include "core/loader/elf.h" +#include "core/loader/symbols_resolver.h" + +namespace Core { struct DynamicModuleInfo; class Linker; @@ -14,14 +16,11 @@ struct EntryParams { const char* argv[3]; }; -struct ModuleInfo -{ +struct ModuleInfo { std::string name; - union - { + union { u64 value; - struct - { + struct { u32 name_offset; u08 version_minor; u08 version_major; @@ -31,14 +30,11 @@ struct ModuleInfo std::string enc_id; }; -struct LibraryInfo -{ +struct LibraryInfo { std::string name; - union - { + union { u64 value; - struct - { + struct { u32 name_offset; u16 version; u16 id; @@ -47,8 +43,7 @@ struct LibraryInfo std::string enc_id; }; -struct DynamicModuleInfo -{ +struct DynamicModuleInfo { void* hash_table = nullptr; u64 hash_table_size = 0; @@ -91,9 +86,8 @@ struct DynamicModuleInfo }; // This struct keeps neccesary info about loaded modules. Main executeable is included too as well -struct Module -{ - Elf elf; +struct Module { + Loader::Elf elf; u64 aligned_base_size = 0; u64 base_virtual_addr = 0; // Base virtual address @@ -103,8 +97,8 @@ struct Module std::vector m_dynamic_data; DynamicModuleInfo dynamic_info{}; - SymbolsResolver export_sym; - SymbolsResolver import_sym; + Loader::SymbolsResolver export_sym; + Loader::SymbolsResolver import_sym; }; class Linker { @@ -117,9 +111,9 @@ public: void LoadModuleToMemory(Module* m); void LoadDynamicInfo(Module* m); void LoadSymbols(Module* m); - SymbolsResolver& getHLESymbols() { return m_hle_symbols; } + Loader::SymbolsResolver& getHLESymbols() { return m_hle_symbols; } void Relocate(Module* m); - void Resolve(const std::string& name, int Symtype, Module* m, SymbolRecord* return_info); + void Resolve(const std::string& name, int Symtype, Module* m, Loader::SymbolRecord* return_info); void Execute(); private: @@ -127,6 +121,8 @@ private: const LibraryInfo* FindLibrary(const Module& program, const std::string& id); std::vector m_modules; - SymbolsResolver m_hle_symbols{}; + Loader::SymbolsResolver m_hle_symbols{}; std::mutex m_mutex; }; + +} // namespace Core diff --git a/src/core/PS4/Loader/Elf.cpp b/src/core/loader/elf.cpp similarity index 99% rename from src/core/PS4/Loader/Elf.cpp rename to src/core/loader/elf.cpp index bfb4008b..729d6b93 100644 --- a/src/core/PS4/Loader/Elf.cpp +++ b/src/core/loader/elf.cpp @@ -1,8 +1,9 @@ -#include "Elf.h" - +#include #include "common/log.h" #include "common/debug.h" -#include +#include "core/loader/elf.h" + +namespace Core::Loader { constexpr bool log_file_loader = true; // disable it to disable logging @@ -432,3 +433,5 @@ void Elf::LoadSegment(u64 virtual_addr, u64 file_offset, u64 size) { } BREAKPOINT(); // Hmm we didn't return something... } + +} // namespace Core::Loader diff --git a/src/core/PS4/Loader/Elf.h b/src/core/loader/elf.h similarity index 99% rename from src/core/PS4/Loader/Elf.h rename to src/core/loader/elf.h index ffc62d27..349d8029 100644 --- a/src/core/PS4/Loader/Elf.h +++ b/src/core/loader/elf.h @@ -450,6 +450,8 @@ constexpr u32 R_X86_64_64 = 1; // Direct 64 bit constexpr u32 R_X86_64_JUMP_SLOT = 7; // Create PLT entry constexpr u32 R_X86_64_RELATIVE = 8; // Adjust by program base +namespace Core::Loader { + class Elf { public: Elf() = default; @@ -502,3 +504,5 @@ class Elf { std::vector m_elf_shdr; elf_program_id_header m_self_id_header{}; }; + +} // namespace Core::Loader diff --git a/src/core/PS4/Loader/SymbolsResolver.cpp b/src/core/loader/symbols_resolver.cpp similarity index 88% rename from src/core/PS4/Loader/SymbolsResolver.cpp rename to src/core/loader/symbols_resolver.cpp index 85a826c5..b82495dd 100644 --- a/src/core/PS4/Loader/SymbolsResolver.cpp +++ b/src/core/loader/symbols_resolver.cpp @@ -1,9 +1,10 @@ -#include "common/types.h" -#include "SymbolsResolver.h" #include "common/log.h" +#include "common/types.h" +#include "core/loader/symbols_resolver.h" -void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr) -{ +namespace Core::Loader { + +void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr) { SymbolRecord r{}; r.name = GenerateName(s); r.virtual_address = virtual_addr; @@ -27,3 +28,5 @@ const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const { LOG_INFO("Unresolved! {}\n", name); return nullptr; } + +} // namespace Core::Loader diff --git a/src/core/PS4/Loader/SymbolsResolver.h b/src/core/loader/symbols_resolver.h similarity index 51% rename from src/core/PS4/Loader/SymbolsResolver.h rename to src/core/loader/symbols_resolver.h index ee227ee9..a095f9a5 100644 --- a/src/core/PS4/Loader/SymbolsResolver.h +++ b/src/core/loader/symbols_resolver.h @@ -5,26 +5,25 @@ #include #include "common/types.h" -struct SymbolRecord -{ - std::string name; +namespace Core::Loader { + +struct SymbolRecord { + std::string name; u64 virtual_address; }; -struct SymbolRes -{ - std::string name; - std::string nidName; - std::string library; - u16 library_version; - std::string module; - u08 module_version_major; - u08 module_version_minor; - u32 type; +struct SymbolRes { + std::string name; + std::string nidName; + std::string library; + u16 library_version; + std::string module; + u08 module_version_major; + u08 module_version_minor; + u32 type; }; -class SymbolsResolver -{ +class SymbolsResolver { public: SymbolsResolver() = default; virtual ~SymbolsResolver() = default; @@ -35,5 +34,7 @@ public: static std::string GenerateName(const SymbolRes& s); private: - std::vector m_symbols; + std::vector m_symbols; }; + +} // namespace Core::Loader diff --git a/src/core/virtual_memory.cpp b/src/core/virtual_memory.cpp index f1248554..1aed5514 100644 --- a/src/core/virtual_memory.cpp +++ b/src/core/virtual_memory.cpp @@ -1,7 +1,5 @@ -#include "common/debug.h" #include "common/log.h" -#include "virtual_memory.h" -#include "core/PS4/Loader/Elf.h" +#include "core/virtual_memory.h" #ifdef _WIN64 #include diff --git a/src/emulator.cpp b/src/emulator.cpp index 2fdd01fb..b2ee632b 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -306,15 +306,15 @@ void keyboardEvent(SDL_Event* event) { if (event->type == SDL_EVENT_KEY_DOWN || event->type == SDL_EVENT_KEY_UP) { u32 button = 0; switch (event->key.keysym.sym) { - case SDLK_UP: button = ScePadButton::SCE_PAD_BUTTON_UP; break; - case SDLK_DOWN: button = ScePadButton::SCE_PAD_BUTTON_DOWN; break; - case SDLK_LEFT: button = ScePadButton::SCE_PAD_BUTTON_LEFT; break; - case SDLK_RIGHT: button = ScePadButton::SCE_PAD_BUTTON_RIGHT; break; - case SDLK_KP_8: button = ScePadButton ::SCE_PAD_BUTTON_TRIANGLE; break; - case SDLK_KP_6: button = ScePadButton ::SCE_PAD_BUTTON_CIRCLE; break; - case SDLK_KP_2: button = ScePadButton ::SCE_PAD_BUTTON_CROSS; break; - case SDLK_KP_4: button = ScePadButton ::SCE_PAD_BUTTON_SQUARE; break; - case SDLK_RETURN: button = ScePadButton ::SCE_PAD_BUTTON_OPTIONS; break; + case SDLK_UP: button = ScePadButton::UP; break; + case SDLK_DOWN: button = ScePadButton::DOWN; break; + case SDLK_LEFT: button = ScePadButton::LEFT; break; + case SDLK_RIGHT: button = ScePadButton::RIGHT; break; + case SDLK_KP_8: button = ScePadButton ::TRIANGLE; break; + case SDLK_KP_6: button = ScePadButton ::CIRCLE; break; + case SDLK_KP_2: button = ScePadButton ::CROSS; break; + case SDLK_KP_4: button = ScePadButton ::SQUARE; break; + case SDLK_RETURN: button = ScePadButton ::OPTIONS; break; default: break; } if (button != 0) { diff --git a/src/main.cpp b/src/main.cpp index 4f19cd2a..4c727527 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,18 +1,18 @@ -#include #include +#include +#include #include +#include +#include #include "common/discord.h" #include "common/types.h" #include "common/log.h" #include "common/singleton.h" -#include -#include -#include -#include -#include -#include -#include "core/PS4/HLE/Libs.h" -#include "core/PS4/Linker.h" +#include "core/PS4/HLE/Graphics/video_out.h" +#include "Util/config.h" +#include "emulator.h" +#include "core/hle/libraries/libs.h" +#include "core/linker.h" #include "emuTimer.h" int main(int argc, char* argv[]) { @@ -31,8 +31,8 @@ int main(int argc, char* argv[]) { // Argument 1 is the path of self file to boot const char* const path = argv[1]; - auto linker = Common::Singleton::Instance(); - HLE::Libs::Init_HLE_Libs(&linker->getHLESymbols()); + auto linker = Common::Singleton::Instance(); + Core::Libraries::InitHLELibs(&linker->getHLESymbols()); linker->LoadModule(path); std::jthread mainthread( [linker](std::stop_token stop_token, void*) {