From 6f941c277adac08589e31cd0ef1d4f2f92820209 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 30 Oct 2023 20:22:25 +0200 Subject: [PATCH] reimplemented sceKernelReadTsc in proper package and some abi fixes --- src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp | 4 ++-- src/Core/PS4/HLE/LibKernel.cpp | 8 +------- src/Core/PS4/HLE/LibKernel.h | 1 - src/Core/hle/libraries/libkernel/time_management.cpp | 11 +++++++---- src/Core/hle/libraries/libkernel/time_management.h | 5 ++++- src/Lib/Timer.cpp | 6 ++++++ src/Lib/Timer.h | 2 +- 7 files changed, 21 insertions(+), 16 deletions(-) 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 035bb5bd..74af085c 100644 --- a/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp +++ b/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp @@ -77,7 +77,7 @@ bool FlipQueue::submitFlip(VideoConfigInternal* cfg, s32 index, s64 flip_arg) { r.cfg = cfg; r.index = index; r.flip_arg = flip_arg; - r.submit_tsc = HLE::Libs::LibKernel::sceKernelReadTsc(); + r.submit_tsc = Core::Libraries::LibKernel::sceKernelReadTsc(); m_requests.push_back(r); @@ -122,7 +122,7 @@ bool FlipQueue::flip(u32 micros) { request->cfg->m_flip_status.count++; request->cfg->m_flip_status.processTime = Core::Libraries::LibKernel::sceKernelGetProcessTime(); - request->cfg->m_flip_status.tsc = HLE::Libs::LibKernel::sceKernelReadTsc(); + request->cfg->m_flip_status.tsc = Core::Libraries::LibKernel::sceKernelReadTsc(); request->cfg->m_flip_status.submitTsc = request->submit_tsc; request->cfg->m_flip_status.flipArg = request->flip_arg; request->cfg->m_flip_status.currentBuffer = request->index; diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp index 7d246f69..bbd1f148 100644 --- a/src/Core/PS4/HLE/LibKernel.cpp +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -25,11 +25,7 @@ int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len) { } static PS4_SYSV_ABI void stack_chk_fail() { BREAKPOINT(); } -u64 PS4_SYSV_ABI sceKernelReadTsc() { - LARGE_INTEGER c; - QueryPerformanceCounter(&c); - return c.QuadPart; -} + int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) { BREAKPOINT(); } void LibKernel_Register(SymbolsResolver* sym) { // obj @@ -46,8 +42,6 @@ void LibKernel_Register(SymbolsResolver* sym) { // misc LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, CPUManagement::sceKernelIsNeoMode); LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail); - // time - LIB_FUNCTION("-2IRUCO--PM", "libkernel", 1, "libkernel", 1, 1, sceKernelReadTsc); // fs LIB_FUNCTION("1G3lF1Gg1k8", "libkernel", 1, "libkernel", 1, 1, Emulator::HLE::Libraries::LibKernel::FileSystem::sceKernelOpen); LIB_FUNCTION("wuCroIGjt2g", "libScePosix", 1, "libkernel", 1, 1, Emulator::HLE::Libraries::LibKernel::FileSystem::POSIX::open); diff --git a/src/Core/PS4/HLE/LibKernel.h b/src/Core/PS4/HLE/LibKernel.h index 903aef84..ee5fc613 100644 --- a/src/Core/PS4/HLE/LibKernel.h +++ b/src/Core/PS4/HLE/LibKernel.h @@ -6,6 +6,5 @@ void LibKernel_Register(SymbolsResolver* sym); // functions -u64 PS4_SYSV_ABI sceKernelReadTsc(); 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/hle/libraries/libkernel/time_management.cpp b/src/Core/hle/libraries/libkernel/time_management.cpp index f7ca9841..ab5d94d4 100644 --- a/src/Core/hle/libraries/libkernel/time_management.cpp +++ b/src/Core/hle/libraries/libkernel/time_management.cpp @@ -1,21 +1,24 @@ #include "time_management.h" #include - +#include "Lib/Timer.h" #include "emuTimer.h" namespace Core::Libraries::LibKernel { -u64 sceKernelGetProcessTime() { +u64 PS4_SYSV_ABI sceKernelGetProcessTime() { return static_cast(Emulator::emuTimer::getTimeMsec() * 1000.0); // return time in microseconds } -u64 sceKernelGetProcessTimeCounter() { return Emulator::emuTimer::getTimeCounter(); } +u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounter() { return Emulator::emuTimer::getTimeCounter(); } -u64 sceKernelGetProcessTimeCounterFrequency() { return Emulator::emuTimer::getTimeFrequency(); } +u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounterFrequency() { return Emulator::emuTimer::getTimeFrequency(); } + +u64 PS4_SYSV_ABI sceKernelReadTsc() { return Lib::Timer::getQueryPerformanceCounter(); } void timeSymbolsRegister(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); + LIB_FUNCTION("-2IRUCO--PM", "libkernel", 1, "libkernel", 1, 1, sceKernelReadTsc); } } // namespace Core::Libraries::LibKernel diff --git a/src/Core/hle/libraries/libkernel/time_management.h b/src/Core/hle/libraries/libkernel/time_management.h index 35d997fb..faa4ed85 100644 --- a/src/Core/hle/libraries/libkernel/time_management.h +++ b/src/Core/hle/libraries/libkernel/time_management.h @@ -4,7 +4,10 @@ #include "Core/PS4/Loader/SymbolsResolver.h" namespace Core::Libraries::LibKernel { -u64 sceKernelGetProcessTime(); +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 diff --git a/src/Lib/Timer.cpp b/src/Lib/Timer.cpp index 3dd1d251..74392fb5 100644 --- a/src/Lib/Timer.cpp +++ b/src/Lib/Timer.cpp @@ -101,3 +101,9 @@ u64 Lib::Timer::GetTicks() const { u64 Lib::Timer::GetFrequency() const { return m_Frequency; } +u64 Lib::Timer::getQueryPerformanceCounter() { + LARGE_INTEGER c; + QueryPerformanceCounter(&c); + return c.QuadPart; +} + diff --git a/src/Lib/Timer.h b/src/Lib/Timer.h index cdb0cc42..8dcc8593 100644 --- a/src/Lib/Timer.h +++ b/src/Lib/Timer.h @@ -18,7 +18,7 @@ namespace Lib { double GetTimeSec() const;// return time in seconds u64 GetTicks() const;// return time in ticks u64 GetFrequency() const;// return ticks frequency - + [[nodiscard]] static u64 getQueryPerformanceCounter(); public: Timer(const Timer&) = delete; Timer& operator=(const Timer&) = delete;