core: Reorganize

This commit is contained in:
GPUCode 2023-11-06 01:11:54 +02:00
parent 89cf4dbfcb
commit 369d92fa56
73 changed files with 724 additions and 572 deletions

View File

@ -30,12 +30,12 @@ endfunction()
add_subdirectory(third-party) add_subdirectory(third-party)
include_directories(src) include_directories(src)
set(LIBC_SOURCES src/core/hle/libraries/Libc/Libc.cpp set(LIBC_SOURCES src/core/hle/libraries/libc/Libc.cpp
src/core/hle/libraries/Libc/Libc.h src/core/hle/libraries/libc/Libc.h
src/core/hle/libraries/Libc/printf.h src/core/hle/libraries/libc/printf.h
src/core/hle/libraries/Libc/va_ctx.h src/core/hle/libraries/libc/va_ctx.h
src/core/hle/libraries/Libc/libc_cxa.cpp src/core/hle/libraries/libc/libc_cxa.cpp
src/core/hle/libraries/Libc/libc_cxa.h src/core/hle/libraries/libc/libc_cxa.h
src/core/hle/libraries/libc/libc_stdio.cpp src/core/hle/libraries/libc/libc_stdio.cpp
src/core/hle/libraries/libc/libc_stdio.h src/core/hle/libraries/libc/libc_stdio.h
src/core/hle/libraries/libc/libc_math.cpp 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.cpp
src/core/hle/libraries/libc/libc_stdlib.h src/core/hle/libraries/libc/libc_stdlib.h
) )
set(USERSERVICE_SOURCES src/core/hle/libraries/libuserservice/user_service.cpp set(USERSERVICE_SOURCES src/core/hle/libraries/libuserservice/libuserservice.cpp
src/core/hle/libraries/libuserservice/user_service.h src/core/hle/libraries/libuserservice/libuserservice.h
) )
set(PAD_SOURCES src/core/hle/libraries/libpad/pad.cpp set(PAD_SOURCES src/core/hle/libraries/libpad/pad.cpp
@ -89,47 +89,47 @@ add_executable(shadps4
src/Lib/Timer.cpp src/Lib/Timer.cpp
src/Lib/Timer.h src/Lib/Timer.h
src/main.cpp src/main.cpp
src/core/PS4/Loader/Elf.cpp src/core/loader/elf.cpp
src/core/PS4/Loader/Elf.h src/core/loader/elf.h
src/GUI/ElfViewer.cpp src/GUI/ElfViewer.cpp
src/GUI/ElfViewer.h src/GUI/ElfViewer.h
src/Util/config.cpp src/Util/config.cpp
src/Util/config.h src/Util/config.h
src/core/virtual_memory.cpp src/core/virtual_memory.cpp
src/core/virtual_memory.h src/core/virtual_memory.h
src/core/PS4/Linker.cpp src/core/linker.cpp
src/core/PS4/Linker.h src/core/linker.h
src/core/PS4/Stubs.cpp src/core/aerolib/stubs.cpp
src/core/PS4/Stubs.h src/core/aerolib/stubs.h
src/core/PS4/Util/aerolib.cpp src/core/aerolib/aerolib.cpp
src/core/PS4/HLE/Kernel/Objects/physical_memory.h src/core/aerolib/aerolib.h
src/core/PS4/HLE/Kernel/Objects/physical_memory.cpp 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.cpp
src/core/PS4/HLE/Graphics/video_out.h src/core/PS4/HLE/Graphics/video_out.h
src/core/PS4/HLE/Kernel/event_queues.cpp src/core/hle/kernel/event_queues.cpp
src/core/PS4/HLE/Kernel/event_queues.h src/core/hle/kernel/event_queues.h
src/core/PS4/HLE/Kernel/cpu_management.cpp src/core/hle/kernel/cpu_management.cpp
src/core/PS4/HLE/Kernel/cpu_management.h src/core/hle/kernel/cpu_management.h
src/core/PS4/Util/aerolib.h src/core/loader/symbols_resolver.h
src/core/PS4/Loader/SymbolsResolver.h src/core/loader/symbols_resolver.cpp
src/core/PS4/Loader/SymbolsResolver.cpp src/core/hle/libraries/libs.cpp
src/core/PS4/HLE/Libs.cpp src/core/hle/libraries/libs.h
src/core/PS4/HLE/Libs.h src/core/hle/libraries/libkernel/libkernel.cpp
src/core/PS4/HLE/LibKernel.cpp src/core/hle/libraries/libkernel/libkernel.h
src/core/PS4/HLE/LibKernel.h src/core/hle/libraries/libscegnmdriver/libscegnmdriver.cpp
src/core/PS4/HLE/LibSceGnmDriver.cpp src/core/hle/libraries/libscegnmdriver/libscegnmdriver.h
src/core/PS4/HLE/LibSceGnmDriver.h src/core/hle/kernel/ThreadManagement.cpp
src/core/PS4/HLE/Kernel/ThreadManagement.cpp src/core/hle/kernel/ThreadManagement.h
src/core/PS4/HLE/Kernel/ThreadManagement.h src/core/hle/kernel/memory_management.cpp
src/core/PS4/HLE/ErrorCodes.h src/core/hle/kernel/memory_management.h
src/core/PS4/HLE/Kernel/memory_management.cpp src/core/hle/error_codes.h
src/core/PS4/HLE/Kernel/memory_management.h
src/core/PS4/GPU/gpu_memory.cpp src/core/PS4/GPU/gpu_memory.cpp
src/core/PS4/GPU/gpu_memory.h src/core/PS4/GPU/gpu_memory.h
src/emulator.cpp src/emulator.cpp
src/emulator.h src/emulator.h
src/core/PS4/HLE/Kernel/Objects/event_queue.h src/core/hle/kernel/Objects/event_queue.h
src/core/PS4/HLE/Kernel/Objects/event_queue.cpp 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.cpp
src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h
src/core/PS4/HLE/Graphics/graphics_ctx.h src/core/PS4/HLE/Graphics/graphics_ctx.h

View File

@ -1,14 +1,12 @@
#include "ElfViewer.h" #include "core/loader/elf.h"
#include "GUI/ElfViewer.h"
#include "imgui.h" #include "imgui.h"
ElfViewer::ElfViewer(Elf* elf) ElfViewer::ElfViewer(Core::Loader::Elf* elf) {
{
this->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 SELF_HEADER = 0;
int ELF_HEADER = 1; int ELF_HEADER = 1;
int SEG_HEADER_START = 100; int SEG_HEADER_START = 100;
@ -97,5 +95,4 @@ void ElfViewer::display(bool enabled)
} }
ImGui::EndChild(); ImGui::EndChild();
ImGui::End(); ImGui::End();
} }

View File

@ -1,11 +1,15 @@
#pragma once #pragma once
#include "../core/PS4/Loader/Elf.h"
namespace Core::Loader {
class Elf;
}
class ElfViewer { class ElfViewer {
private:
Elf* elf;
public: public:
ElfViewer(Elf* elf); explicit ElfViewer(Core::Loader::Elf* elf);
void display(bool enabled);//display imgui window
void Display(bool enabled);
private:
Core::Loader::Elf* elf;
}; };

View File

@ -1,8 +1,6 @@
#include "video_out_ctx.h"
#include <core/PS4/HLE/LibKernel.h>
#include "common/debug.h" #include "common/debug.h"
#include <core/hle/libraries/libkernel/time_management.h> #include "core/PS4/HLE/Graphics/Objects/video_out_ctx.h"
#include "core/hle/libraries/libkernel/time_management.h"
namespace HLE::Graphics::Objects { 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.paneWidth = width;
m_video_out_ctx.m_resolution.paneHeight = height; m_video_out_ctx.m_resolution.paneHeight = height;
} }
int VideoOutCtx::Open() { int VideoOutCtx::Open() {
std::scoped_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
@ -112,7 +111,7 @@ bool FlipQueue::flip(u32 micros) {
std::scoped_lock cfg_lock{request->cfg->m_mutex}; std::scoped_lock cfg_lock{request->cfg->m_mutex};
for (auto& flip_eq : request->cfg->m_flip_evtEq) { for (auto& flip_eq : request->cfg->m_flip_evtEq) {
if (flip_eq != nullptr) { if (flip_eq != nullptr) {
flip_eq->triggerEvent(SCE_VIDEO_OUT_EVENT_FLIP, HLE::Kernel::Objects::EVFILT_VIDEO_OUT, reinterpret_cast<void*>(request->flip_arg)); flip_eq->triggerEvent(SCE_VIDEO_OUT_EVENT_FLIP, Core::Kernel::EVFILT_VIDEO_OUT, reinterpret_cast<void*>(request->flip_arg));
} }
} }
} }
@ -131,4 +130,4 @@ bool FlipQueue::flip(u32 micros) {
return true; return true;
} }
}; // namespace HLE::Graphics::Objects } // namespace HLE::Graphics::Objects

View File

@ -24,7 +24,7 @@ struct VideoConfigInternal {
bool isOpened = false; bool isOpened = false;
SceVideoOutFlipStatus m_flip_status; SceVideoOutFlipStatus m_flip_status;
SceVideoOutVblankStatus m_vblank_status; SceVideoOutVblankStatus m_vblank_status;
std::vector<HLE::Libs::LibKernel::EventQueues::SceKernelEqueue> m_flip_evtEq; std::vector<Core::Kernel::SceKernelEqueue> m_flip_evtEq;
int m_flip_rate = 0; int m_flip_rate = 0;
VideoOutBufferInfo buffers[16]; VideoOutBufferInfo buffers[16];
std::vector<VideoOutBufferSetInternal> buffers_sets; std::vector<VideoOutBufferSetInternal> buffers_sets;
@ -78,4 +78,5 @@ class VideoOutCtx {
FlipQueue m_flip_queue; FlipQueue m_flip_queue;
HLE::Libs::Graphics::GraphicCtx* m_graphic_ctx = nullptr; HLE::Libs::Graphics::GraphicCtx* m_graphic_ctx = nullptr;
}; };
}; // namespace HLE::Graphics::Objects
} // namespace HLE::Graphics::Objects

View File

@ -1,19 +1,17 @@
#include "video_out.h" #include <cstdio>
#include <string>
#include <core/PS4/GPU/gpu_memory.h> #include <magic_enum.hpp>
#include <core/PS4/GPU/video_out_buffer.h>
#include <core/PS4/HLE/ErrorCodes.h>
#include <core/PS4/HLE/LibSceGnmDriver.h>
#include <core/PS4/HLE/Libs.h>
#include <core/PS4/HLE/UserManagement/UsrMngCodes.h>
#include <Util/config.h>
#include "common/log.h" #include "common/log.h"
#include "common/debug.h" #include "common/debug.h"
#include <stdio.h> #include "core/loader/symbols_resolver.h"
#include "core/PS4/HLE/Graphics/video_out.h"
#include <magic_enum.hpp> #include "core/PS4/GPU/gpu_memory.h"
#include <string> #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 "Objects/video_out_ctx.h"
#include "common/singleton.h" #include "common/singleton.h"
#include "emulator.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, "height = {}\n", height);
LOG_INFO_IF(log_file_videoout, "pitchInPixel = {}\n", pitchInPixel); LOG_INFO_IF(log_file_videoout, "pitchInPixel = {}\n", pitchInPixel);
memset(attribute, 0, sizeof(SceVideoOutBufferAttribute)); std::memset(attribute, 0, sizeof(SceVideoOutBufferAttribute));
attribute->pixelFormat = pixelFormat; attribute->pixelFormat = pixelFormat;
attribute->tilingMode = tilingMode; attribute->tilingMode = tilingMode;
@ -71,21 +69,23 @@ void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(SceVideoOutBufferAttribute* attr
attribute->option = SCE_VIDEO_OUT_BUFFER_ATTRIBUTE_OPTION_NONE; 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->isTriggered = false;
event->event.fflags = 0; event->event.fflags = 0;
event->event.data = 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->isTriggered = true;
event->event.fflags++; event->event.fflags++;
event->event.data = reinterpret_cast<intptr_t>(trigger_data); event->event.data = reinterpret_cast<intptr_t>(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 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(); PRINT_FUNCTION_NAME();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
@ -100,10 +100,10 @@ s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(LibKernel::EventQueues::SceKernelEqueue
return SCE_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE; return SCE_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE;
} }
HLE::Kernel::Objects::EqueueEvent event; Core::Kernel::EqueueEvent event{};
event.isTriggered = false; event.isTriggered = false;
event.event.ident = SCE_VIDEO_OUT_EVENT_FLIP; 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.udata = udata;
event.event.fflags = 0; event.event.fflags = 0;
event.event.data = 0; event.event.data = 0;
@ -213,18 +213,21 @@ s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* co
return registration_index; return registration_index;
} }
s32 PS4_SYSV_ABI sceVideoOutSetFlipRate(s32 handle, s32 rate) { s32 PS4_SYSV_ABI sceVideoOutSetFlipRate(s32 handle, s32 rate) {
PRINT_FUNCTION_NAME(); PRINT_FUNCTION_NAME();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
videoOut->getCtx(handle)->m_flip_rate = rate; videoOut->getCtx(handle)->m_flip_rate = rate;
return SCE_OK; return SCE_OK;
} }
s32 PS4_SYSV_ABI sceVideoOutIsFlipPending(s32 handle) { s32 PS4_SYSV_ABI sceVideoOutIsFlipPending(s32 handle) {
PRINT_FUNCTION_NAME(); PRINT_FUNCTION_NAME();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
s32 pending = videoOut->getCtx(handle)->m_flip_status.flipPendingNum; s32 pending = videoOut->getCtx(handle)->m_flip_status.flipPendingNum;
return pending; return pending;
} }
s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode, s64 flipArg) { s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode, s64 flipArg) {
PRINT_FUNCTION_NAME(); PRINT_FUNCTION_NAME();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::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"); LOG_TRACE_IF(log_file_videoout, "sceVideoOutSubmitFlip flip queue is full\n");
return SCE_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL; 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; return SCE_OK;
} }
s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* status) { s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* status) {
PRINT_FUNCTION_NAME(); PRINT_FUNCTION_NAME();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
@ -268,12 +272,14 @@ s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* sta
LOG_INFO_IF(log_file_videoout, "currentBuffer = {}\n", status->currentBuffer); LOG_INFO_IF(log_file_videoout, "currentBuffer = {}\n", status->currentBuffer);
return 0; return 0;
} }
s32 PS4_SYSV_ABI sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutionStatus* status) { s32 PS4_SYSV_ABI sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutionStatus* status) {
PRINT_FUNCTION_NAME(); PRINT_FUNCTION_NAME();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
*status = videoOut->getCtx(handle)->m_resolution; *status = videoOut->getCtx(handle)->m_resolution;
return SCE_OK; return SCE_OK;
} }
s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param) { s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param) {
PRINT_FUNCTION_NAME(); PRINT_FUNCTION_NAME();
if (userId != SCE_USER_SERVICE_USER_ID_SYSTEM && userId != 0) { 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; return handle;
} }
s32 PS4_SYSV_ABI sceVideoOutClose(s32 handle) { s32 PS4_SYSV_ABI sceVideoOutClose(s32 handle) {
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance(); auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
videoOut->Close(handle); videoOut->Close(handle);
return SCE_OK; 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("SbU3dwp80lQ", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutGetFlipStatus);
LIB_FUNCTION("U46NwOiJpys", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSubmitFlip); LIB_FUNCTION("U46NwOiJpys", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutSubmitFlip);
LIB_FUNCTION("w3BY+tAEiQY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutRegisterBuffers); LIB_FUNCTION("w3BY+tAEiQY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutRegisterBuffers);

View File

@ -1,8 +1,11 @@
#pragma once #pragma once
#include <core/PS4/HLE/Kernel/event_queues.h>
#include <core/PS4/Loader/SymbolsResolver.h>
#include <string> #include <string>
#include "core/hle/kernel/event_queues.h"
namespace Core::Loader {
class SymbolsResolver;
}
namespace HLE::Libs::Graphics::VideoOut { namespace HLE::Libs::Graphics::VideoOut {
@ -95,12 +98,12 @@ struct VideoOutBufferSetInternal {
void videoOutInit(u32 width, u32 height); void videoOutInit(u32 width, u32 height);
std::string getPixelFormatString(s32 format); std::string getPixelFormatString(s32 format);
void videoOutRegisterLib(SymbolsResolver* sym); void videoOutRegisterLib(Core::Loader::SymbolsResolver* sym);
bool videoOutFlip(u32 micros); bool videoOutFlip(u32 micros);
void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(SceVideoOutBufferAttribute* attribute, u32 pixelFormat, u32 tilingMode, u32 aspectRatio, u32 width, void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(SceVideoOutBufferAttribute* attribute, u32 pixelFormat, u32 tilingMode, u32 aspectRatio, u32 width,
u32 height, u32 pitchInPixel); 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, s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses, s32 bufferNum,
const SceVideoOutBufferAttribute* attribute); const SceVideoOutBufferAttribute* attribute);
s32 PS4_SYSV_ABI sceVideoOutSetFlipRate(s32 handle, s32 rate); 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 sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutionStatus* status);
s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param); s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param);
s32 PS4_SYSV_ABI sceVideoOutClose(s32 handle); s32 PS4_SYSV_ABI sceVideoOutClose(s32 handle);
} // namespace HLE::Libs::Graphics::VideoOut
} // namespace HLE::Libs::Graphics::VideoOut

View File

@ -1,13 +0,0 @@
#include "cpu_management.h"
#include "Util/config.h"
#include "common/log.h"
#include <core/PS4/HLE/Libs.h>
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

View File

@ -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

View File

@ -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

View File

@ -1,27 +0,0 @@
#include "LibSceGnmDriver.h"
#include "Libs.h"
#include "../Loader/Elf.h"
#include "common/log.h"
#include "common/debug.h"
#include <core/PS4/GPU/gpu_memory.h>
#include <emulator.h>
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);
}
};

View File

@ -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

View File

@ -1,23 +0,0 @@
#include "Libs.h"
#include "LibKernel.h"
#include "LibSceGnmDriver.h"
#include <core/PS4/HLE/Graphics/video_out.h>
#include "core/hle/libraries/libuserservice/user_service.h"
#include "core/hle/libraries/libpad/pad.h"
#include <core/hle/libraries/libsystemservice/system_service.h>
#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

View File

@ -1,4 +0,0 @@
#include "common/types.h"
u64 UnresolvedStub();
u64 GetStub(const char *nid);

View File

@ -1,38 +0,0 @@
#include "aerolib.h"
#include "common/types.h"
#include <string.h>
#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

View File

@ -1,11 +0,0 @@
#include <stdint.h>
namespace aerolib {
struct nid_entry {
const char* nid;
const char* name;
};
nid_entry* find_by_nid(const char* nid);
};

View File

@ -0,0 +1,33 @@
#include <cstring>
#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

View File

@ -0,0 +1,14 @@
#pragma once
#include <cstdint>
namespace Core::AeroLib {
struct NidEntry {
const char* nid;
const char* name;
};
const NidEntry* FindByNid(const char* nid);
} // namespace Core::AeroLib

View File

@ -1,8 +1,8 @@
#include "Stubs.h"
#include "Util/aerolib.h"
#include "common/log.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 // Helper to provide stub implementations for missing functions
// //
@ -16,7 +16,7 @@
// and to longer compile / CI times // and to longer compile / CI times
// //
// Must match STUBS_LIST define // Must match STUBS_LIST define
#define MAX_STUBS 128 constexpr u32 MAX_STUBS = 128;
u64 UnresolvedStub() { u64 UnresolvedStub() {
LOG_ERROR("Unresolved Stub: called, returning zero to {}\n", __builtin_return_address(0)); 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]; static std::string stub_nids_unknown[MAX_STUBS];
template <int stub_index> template <int stub_index>
@ -69,7 +69,7 @@ u64 GetStub(const char* nid) {
return (u64)&UnknownStub; return (u64)&UnknownStub;
} }
auto entry = aerolib::find_by_nid(nid); const auto entry = FindByNid(nid);
if (!entry) { if (!entry) {
stub_nids_unknown[UsedStubEntries] = nid; stub_nids_unknown[UsedStubEntries] = nid;
} else { } else {
@ -78,3 +78,5 @@ u64 GetStub(const char* nid) {
return (u64)stub_handlers[UsedStubEntries++]; return (u64)stub_handlers[UsedStubEntries++];
} }
} // namespace Core::AeroLib

11
src/core/aerolib/stubs.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include "common/types.h"
namespace Core::AeroLib {
u64 UnresolvedStub();
u64 GetStub(const char* nid);
} // namespace Core::AeroLib

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
constexpr int SCE_OK = 0; constexpr int SCE_OK = 0;
constexpr int SCE_KERNEL_ERROR_EBADF = 0x80020009; constexpr int SCE_KERNEL_ERROR_EBADF = 0x80020009;

View File

@ -1,11 +1,10 @@
#include "event_queue.h"
#include <Lib/Timer.h>
#include "common/debug.h" #include "common/debug.h"
#include "core/hle/kernel/objects/event_queue.h"
#include "Lib/Timer.h"
namespace HLE::Kernel::Objects { namespace Core::Kernel {
EqueueInternal::~EqueueInternal() {}
EqueueInternal::~EqueueInternal() = default;
int EqueueInternal::addEvent(const EqueueEvent& event) { int EqueueInternal::addEvent(const EqueueEvent& event) {
std::scoped_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
@ -87,4 +86,4 @@ int EqueueInternal::getTriggeredEvents(SceKernelEvent* ev, int num) {
return ret; return ret;
} }
}; // namespace HLE::Kernel::Objects } // namespace Core::Kernel

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include "common/types.h"
#include <mutex> #include <mutex>
#include <string> #include <string>
#include <vector> #include <vector>
#include "common/types.h"
namespace HLE::Kernel::Objects { namespace Core::Kernel {
constexpr s16 EVFILT_READ = -1; constexpr s16 EVFILT_READ = -1;
constexpr s16 EVFILT_WRITE = -2; constexpr s16 EVFILT_WRITE = -2;
@ -33,11 +33,9 @@ constexpr s16 EVFILT_SYSCOUNT = 22;
class EqueueInternal; class EqueueInternal;
struct EqueueEvent; struct EqueueEvent;
using SceKernelEqueue = Kernel::Objects::EqueueInternal*;
using TriggerFunc = void (*)(EqueueEvent* event, void* trigger_data); using TriggerFunc = void (*)(EqueueEvent* event, void* trigger_data);
using ResetFunc = void (*)(EqueueEvent* event); using ResetFunc = void (*)(EqueueEvent* event);
using DeleteFunc = void (*)(SceKernelEqueue eq, EqueueEvent* event); using DeleteFunc = void (*)(EqueueInternal* eq, EqueueEvent* event);
struct SceKernelEvent { struct SceKernelEvent {
u64 ident = 0; /* identifier for this event */ u64 ident = 0; /* identifier for this event */
@ -76,4 +74,5 @@ class EqueueInternal {
std::vector<EqueueEvent> m_events; std::vector<EqueueEvent> m_events;
std::condition_variable m_cond; std::condition_variable m_cond;
}; };
}; // namespace HLE::Kernel::Objects
} // namespace Core::Kernel

View File

@ -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}; std::scoped_lock lock{m_mutex};
u64 find_free_pos = 0; u64 find_free_pos = 0;
@ -39,7 +42,9 @@ bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignmen
return false; 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}; std::scoped_lock lock{m_mutex};
for (auto& b : m_allocatedBlocks) { for (auto& b : m_allocatedBlocks) {
if (phys_addr >= b.start_addr && phys_addr < b.start_addr + b.size) { 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; return false;
} }
} // namespace HLE::Kernel::Objects
} // namespace Core::Kernel

View File

@ -1,11 +1,13 @@
#pragma once #pragma once
#include "common/types.h"
#include <core/virtual_memory.h>
#include <core/PS4/GPU/gpu_memory.h>
#include <mutex> #include <mutex>
#include <vector> #include <vector>
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 { class PhysicalMemory {
public: public:
@ -31,4 +33,4 @@ class PhysicalMemory {
std::mutex m_mutex; std::mutex m_mutex;
}; };
} // namespace HLE::Kernel::Objects } // namespace Core::Kernel

View File

@ -1,10 +1,8 @@
#include "ThreadManagement.h"
#include "common/debug.h" #include "common/debug.h"
#include "core/hle/kernel/ThreadManagement.h"
#include "core/hle/error_codes.h"
#include "../ErrorCodes.h" namespace Core::Kernel {
namespace HLE::Libs::LibKernel::ThreadManagement {
thread_local PthreadInternal* g_pthread_self = nullptr; thread_local PthreadInternal* g_pthread_self = nullptr;
PThreadCxt* g_pthread_cxt = nullptr; PThreadCxt* g_pthread_cxt = nullptr;
@ -122,4 +120,4 @@ int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) {
return SCE_KERNEL_ERROR_EINVAL; return SCE_KERNEL_ERROR_EINVAL;
} }
}; // namespace HLE::Libs::LibKernel::ThreadManagement } // namespace Core::Kernel

View File

@ -6,7 +6,7 @@
#include "common/types.h" #include "common/types.h"
#include <string> #include <string>
namespace HLE::Libs::LibKernel::ThreadManagement { namespace Core::Kernel {
struct PthreadAttrInternal; struct PthreadAttrInternal;
@ -19,6 +19,7 @@ struct PthreadInternal {
pthread_t pth; pthread_t pth;
ScePthreadAttr attr; ScePthreadAttr attr;
}; };
struct PthreadAttrInternal { struct PthreadAttrInternal {
u08 reserved[64]; u08 reserved[64];
u64 affinity; u64 affinity;
@ -32,11 +33,10 @@ class PThreadCxt {};
void Pthread_Init_Self_MainThread(); void Pthread_Init_Self_MainThread();
//HLE FUNCTIONS
int scePthreadAttrInit(ScePthreadAttr* attr); int scePthreadAttrInit(ScePthreadAttr* attr);
int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate); int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate);
int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched); int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched);
int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param); int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param);
int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy); int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy);
} // namespace HLE::Libs::LibKernel::ThreadManagement } // namespace Core::Kernel

View File

@ -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

View File

@ -1,6 +1,9 @@
#pragma once #pragma once
#include "common/types.h" #include "common/types.h"
namespace HLE::Libs::LibKernel::CPUManagement { namespace Core::Kernel {
int PS4_SYSV_ABI sceKernelIsNeoMode(); int PS4_SYSV_ABI sceKernelIsNeoMode();
};
} // namespace Core::Kernel

View File

@ -1,11 +1,11 @@
#include "event_queues.h"
#include <core/PS4/HLE/ErrorCodes.h>
#include <core/PS4/HLE/Libs.h>
#include "common/log.h"
#include "common/debug.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 constexpr bool log_file_equeues = true; // disable it to disable logging
int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name) { 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"); LOG_TRACE_IF(log_file_equeues, "sceKernelCreateEqueue returned SCE_KERNEL_ERROR_ENAMETOOLONG name size exceeds 32 bytes\n");
return SCE_KERNEL_ERROR_ENAMETOOLONG; return SCE_KERNEL_ERROR_ENAMETOOLONG;
} }
*eq = new Kernel::Objects::EqueueInternal; *eq = new EqueueInternal;
(*eq)->setName(std::string(name)); (*eq)->setName(std::string(name));
LOG_INFO_IF(log_file_equeues, "sceKernelCreateEqueue created with name \"{}\"\n", name); LOG_INFO_IF(log_file_equeues, "sceKernelCreateEqueue created with name \"{}\"\n", name);
return SCE_OK; 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(); PRINT_FUNCTION_NAME();
if (eq == nullptr) { if (eq == nullptr) {
@ -50,17 +50,22 @@ int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, HLE::Kernel::Objects::S
if (num < 1) { if (num < 1) {
return SCE_KERNEL_ERROR_EINVAL; return SCE_KERNEL_ERROR_EINVAL;
} }
if (timo == nullptr) { // wait until an event arrives without timing out if (timo == nullptr) { // wait until an event arrives without timing out
*out = eq->waitForEvents(ev, num, 0); *out = eq->waitForEvents(ev, num, 0);
} }
if (timo != nullptr) { 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(); BREAKPOINT();
} else { // wait until an event arrives with timing out } else {
// Wait until an event arrives with timing out
BREAKPOINT(); BREAKPOINT();
} }
} }
return SCE_OK; return SCE_OK;
} }
}; // namespace HLE::Libs::LibKernel::EventQueues } // namespace Core::Kernel

View File

@ -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

View File

@ -1,25 +1,22 @@
#include "memory_management.h" #include <bit>
#include <magic_enum.hpp>
#include <core/PS4/GPU/gpu_memory.h> #include <core/PS4/GPU/gpu_memory.h>
#include <core/virtual_memory.h> #include <core/virtual_memory.h>
#include "common/log.h" #include "common/log.h"
#include "common/debug.h" #include "common/debug.h"
#include <bit>
#include <magic_enum.hpp>
#include "common/singleton.h" #include "common/singleton.h"
#include "../ErrorCodes.h" #include "core/hle/kernel/memory_management.h"
#include "../Libs.h" #include "core/hle/libraries/libs.h"
#include "Objects/physical_memory.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 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() { u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() {
PRINT_FUNCTION_NAME(); 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"); LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL memory range invalid\n");
return SCE_KERNEL_ERROR_EINVAL; 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"); LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n");
return SCE_KERNEL_ERROR_EINVAL; 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())); LOG_INFO_IF(log_file_memory, "memory_type = {}\n", magic_enum::enum_name(memtype.value()));
u64 physical_addr = 0; u64 physical_addr = 0;
auto* physical_memory = Common::Singleton<HLE::Kernel::Objects::PhysicalMemory>::Instance(); auto* physical_memory = Common::Singleton<PhysicalMemory>::Instance();
if (!physical_memory->Alloc(searchStart, searchEnd, len, alignment, &physical_addr, memoryType)) { 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"); LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EAGAIN can't allocate physical memory\n");
return SCE_KERNEL_ERROR_EAGAIN; 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; return SCE_KERNEL_ERROR_EINVAL;
} }
if (alignment != 0) { 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"); LOG_TRACE_IF(log_file_memory, "sceKernelMapDirectMemory returned SCE_KERNEL_ERROR_EINVAL alignment invalid\n");
return SCE_KERNEL_ERROR_EINVAL; 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; return SCE_KERNEL_ERROR_ENOMEM;
} }
auto* physical_memory = Common::Singleton<HLE::Kernel::Objects::PhysicalMemory>::Instance(); auto* physical_memory = Common::Singleton<PhysicalMemory>::Instance();
if (!physical_memory->Map(out_addr, directMemoryStart, len, prot, cpu_mode, gpu_mode)) { if (!physical_memory->Map(out_addr, directMemoryStart, len, prot, cpu_mode, gpu_mode)) {
BREAKPOINT(); BREAKPOINT();
} }
@ -126,4 +123,4 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
return SCE_OK; return SCE_OK;
} }
} // namespace HLE::Libs::LibKernel::MemoryManagement } // namespace Core::Kernel

View File

@ -2,13 +2,9 @@
#include "common/types.h" #include "common/types.h"
// constants
constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 5376_MB; // ~ 6GB constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 5376_MB; // ~ 6GB
namespace HLE::Libs::LibKernel::MemoryManagement { namespace Core::Kernel {
// memory types
enum MemoryTypes : u32 { enum MemoryTypes : u32 {
SCE_KERNEL_WB_ONION = 0, // write - back mode (Onion bus) 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_OVERWRITE = 0x0080,
SCE_KERNEL_MAP_NO_COALESCE = 0x400000 SCE_KERNEL_MAP_NO_COALESCE = 0x400000
}; };
enum MemoryProtection : u32 { enum MemoryProtection : u32 {
SCE_KERNEL_PROT_CPU_READ = 0x01, // Permit reads from the CPU SCE_KERNEL_PROT_CPU_READ = 0x01, // Permit reads from the CPU
SCE_KERNEL_PROT_CPU_RW = 0x02, // Permit reads/writes 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(); 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 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); int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags, s64 directMemoryStart, u64 alignment);
}; // namespace HLE::Libs::LibKernel::MemoryManagement
} // namespace Core::Kernel

View File

@ -1,19 +1,17 @@
#include "libc.h" #include <cstdlib>
#include "common/debug.h" #include "common/debug.h"
#include <stdlib.h>
#include "common/singleton.h" #include "common/singleton.h"
#include "common/log.h" #include "common/log.h"
#include "core/PS4/HLE/Libs.h"
#include "core/hle/libraries/libc/libc.h" #include "core/hle/libraries/libc/libc.h"
#include "core/hle/libraries/libc/libc_cxa.h" #include "core/hle/libraries/libc/libc_cxa.h"
#include "core/hle/libraries/libc/libc_math.h" #include "core/hle/libraries/libc/libc_math.h"
#include "core/hle/libraries/libc/libc_stdio.h" #include "core/hle/libraries/libc/libc_stdio.h"
#include "core/hle/libraries/libc/libc_stdlib.h" #include "core/hle/libraries/libc/libc_stdlib.h"
#include "core/hle/libraries/libc/libc_string.h" #include "core/hle/libraries/libc/libc_string.h"
#include "core/hle/libraries/libs.h"
namespace Core::Libraries::LibC { namespace Core::Libraries::LibC {
constexpr bool log_file_libc = true; // disable it to disable logging constexpr bool log_file_libc = true; // disable it to disable logging
static u32 g_need_sceLibc = 1; 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; 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() { static PS4_SYSV_ABI void _Assert() {
PRINT_DUMMY_FUNCTION_NAME(); PRINT_DUMMY_FUNCTION_NAME();
BREAKPOINT(); 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() { PS4_SYSV_ABI void _ZSt11_Xbad_allocv() {
PRINT_DUMMY_FUNCTION_NAME(); PRINT_DUMMY_FUNCTION_NAME();
BREAKPOINT(); BREAKPOINT();
} }
PS4_SYSV_ABI void _ZSt14_Xlength_errorPKc() { PS4_SYSV_ABI void _ZSt14_Xlength_errorPKc() {
PRINT_DUMMY_FUNCTION_NAME(); PRINT_DUMMY_FUNCTION_NAME();
BREAKPOINT(); BREAKPOINT();
} }
PS4_SYSV_ABI void* _Znwm(u64 count) { PS4_SYSV_ABI void* _Znwm(u64 count) {
if (count == 0) { if (count == 0) {
LOG_ERROR_IF(log_file_libc, "_Znwm count ={}\n", count); LOG_ERROR_IF(log_file_libc, "_Znwm count ={}\n", count);
@ -70,7 +81,7 @@ PS4_SYSV_ABI void* _Znwm(u64 count) {
return ptr; return ptr;
} }
void libcSymbolsRegister(SymbolsResolver* sym) { void libcSymbolsRegister(Loader::SymbolsResolver* sym) {
// cxa functions // cxa functions
LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1, __cxa_guard_acquire); LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1, __cxa_guard_acquire);
LIB_FUNCTION("9rAeANT2tyE", "libc", 1, "libc", 1, 1, __cxa_guard_release); LIB_FUNCTION("9rAeANT2tyE", "libc", 1, "libc", 1, 1, __cxa_guard_release);

View File

@ -1,10 +1,11 @@
#pragma once #pragma once
#include "common/types.h" namespace Core::Loader {
#include "core/PS4/Loader/SymbolsResolver.h" class SymbolsResolver;
}
namespace Core::Libraries::LibC { namespace Core::Libraries::LibC {
void libcSymbolsRegister(SymbolsResolver* sym); void libcSymbolsRegister(Loader::SymbolsResolver* sym);
} // namespace Core::Libraries::LibC } // namespace Core::Libraries::LibC

View File

@ -6,6 +6,7 @@
// adapted from https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx.auto.html // adapted from https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx.auto.html
namespace Core::Libraries::LibC { namespace Core::Libraries::LibC {
constexpr bool log_file_cxa = true; // disable it to disable logging constexpr bool log_file_cxa = true; // disable it to disable logging
// This file implements the __cxa_guard_* functions as defined at: // This file implements the __cxa_guard_* functions as defined at:

View File

@ -5,7 +5,9 @@
#include "common/types.h" #include "common/types.h"
namespace Core::Libraries::LibC { namespace Core::Libraries::LibC {
int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object); 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_release(u64* guard_object);
void PS4_SYSV_ABI __cxa_guard_abort(u64* guard_object); void PS4_SYSV_ABI __cxa_guard_abort(u64* guard_object);
} // namespace Core::Libraries::LibC
} // namespace Core::Libraries::LibC

View File

@ -1,23 +1,38 @@
#include "libc_math.h"
#include <cmath> #include <cmath>
#include "core/hle/libraries/libc/libc_math.h"
namespace Core::Libraries::LibC { 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 } // namespace Core::Libraries::LibC

View File

@ -3,6 +3,7 @@
#include "common/types.h" #include "common/types.h"
namespace Core::Libraries::LibC { namespace Core::Libraries::LibC {
float PS4_SYSV_ABI atan2f(float y, float x); float PS4_SYSV_ABI atan2f(float y, float x);
float PS4_SYSV_ABI acosf(float num); float PS4_SYSV_ABI acosf(float num);
float PS4_SYSV_ABI tanf(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); double PS4_SYSV_ABI _Sin(double x);
float PS4_SYSV_ABI _Fsin(float arg); float PS4_SYSV_ABI _Fsin(float arg);
double PS4_SYSV_ABI exp2(double arg); double PS4_SYSV_ABI exp2(double arg);
} // namespace Core::Libraries::LibC
} // namespace Core::Libraries::LibC

View File

@ -1,15 +1,16 @@
#include "libc_stdio.h"
#include "common/debug.h" #include "common/debug.h"
#include "common/log.h" #include "common/log.h"
#include "core/hle/libraries/libc/libc_stdio.h"
namespace Core::Libraries::LibC { namespace Core::Libraries::LibC {
constexpr bool log_file_libc = true; // disable it to disable logging constexpr bool log_file_libc = true; // disable it to disable logging
int PS4_SYSV_ABI printf(VA_ARGS) { int PS4_SYSV_ABI printf(VA_ARGS) {
VA_CTX(ctx); VA_CTX(ctx);
return printf_ctx(&ctx); return printf_ctx(&ctx);
} }
int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS) { int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS) {
int fd = _fileno(file); int fd = _fileno(file);
if (fd == 1 || fd == 2) { // output stdout and stderr to console 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; 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 } // namespace Core::Libraries::LibC

View File

@ -1,12 +1,13 @@
#pragma once #pragma once
#include "common/types.h" #include "common/types.h"
#include "core/hle/libraries/libc/printf.h"
#include "printf.h"
namespace Core::Libraries::LibC { namespace Core::Libraries::LibC {
int PS4_SYSV_ABI printf(VA_ARGS); 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 vsnprintf(char* s, size_t n, const char* format, VaList* arg);
int PS4_SYSV_ABI puts(const char* s); int PS4_SYSV_ABI puts(const char* s);
int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS); int PS4_SYSV_ABI fprintf(FILE* file, VA_ARGS);
} // namespace Core::Libraries::LibC
} // namespace Core::Libraries::LibC

View File

@ -1,14 +1,15 @@
#include "libc_stdlib.h" #include <cstdlib>
#include "common/log.h" #include "common/log.h"
#include "common/debug.h" #include "common/debug.h"
#include "core/hle/libraries/libc/libc_stdlib.h"
#include <cstdlib>
namespace Core::Libraries::LibC { namespace Core::Libraries::LibC {
constexpr bool log_file_libc = true; // disable it to disable logging 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 PS4_SYSV_ABI atexit(void (*func)()) {
int rt = std::atexit(func); int rt = std::atexit(func);
@ -19,19 +20,28 @@ int PS4_SYSV_ABI atexit(void (*func)()) {
return rt; 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*); typedef int(PS4_SYSV_ABI* pfunc_QsortCmp)(const void*, const void*);
thread_local static pfunc_QsortCmp compair_ps4; 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*)) { 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; compair_ps4 = comp;
std::qsort(ptr, count, size, qsort_compair); 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

View File

@ -1,14 +1,15 @@
#pragma once #pragma once
#include <cstddef>
#include "common/types.h" #include "common/types.h"
#include <cstddef>
namespace Core::Libraries::LibC { namespace Core::Libraries::LibC {
void PS4_SYSV_ABI exit(int code); void PS4_SYSV_ABI exit(int code);
int PS4_SYSV_ABI atexit(void (*func)()); int PS4_SYSV_ABI atexit(void (*func)());
void* PS4_SYSV_ABI malloc(size_t size); void* PS4_SYSV_ABI malloc(size_t size);
void PS4_SYSV_ABI free(void* ptr); 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*)); 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(); int PS4_SYSV_ABI rand();
} // namespace Core::Libraries::LibC
} // namespace Core::Libraries::LibC

View File

@ -1,25 +1,42 @@
#include "libc_string.h"
#include <cstring> #include <cstring>
#include "core/hle/libraries/libc/libc_string.h"
namespace Core::Libraries::LibC { 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

View File

@ -1,10 +1,10 @@
#pragma once #pragma once
#include <cstddef>
#include "common/types.h" #include "common/types.h"
#include <cstddef>
namespace Core::Libraries::LibC { namespace Core::Libraries::LibC {
int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n); 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 memcpy(void* dest, const void* src, size_t n);
void* PS4_SYSV_ABI memset(void* s, int c, 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 strcpy(char* destination, const char* source);
char* PS4_SYSV_ABI strcat(char* dest, const char* src); char* PS4_SYSV_ABI strcat(char* dest, const char* src);
size_t PS4_SYSV_ABI strlen(const char* str); size_t PS4_SYSV_ABI strlen(const char* str);
} // namespace Core::Libraries::LibC
} // namespace Core::Libraries::LibC

View File

@ -103,4 +103,4 @@ T* vaArgPtr(VaList* l) {
return vaArgOverflowArgArea<T*, 1, 8>(l); return vaArgOverflowArgArea<T*, 1, 8>(l);
} }
} // namespace Core::Libraries::LibC } // namespace Core::Libraries::LibC

View File

@ -1,10 +1,10 @@
#include "file_system.h"
#include <core/PS4/HLE/Libs.h>
#include "common/log.h" #include "common/log.h"
#include "common/debug.h" #include "common/debug.h"
#include "core/hle/libraries/libkernel/file_system.h"
#include "core/hle/libraries/libs.h"
namespace Core::Libraries::LibKernel { namespace Core::Libraries::LibKernel {
constexpr bool log_file_fs = true; // disable it to disable logging constexpr bool log_file_fs = true; // disable it to disable logging
int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) { 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; return result;
} }
void fileSystemSymbolsRegister(SymbolsResolver* sym) { void fileSystemSymbolsRegister(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("1G3lF1Gg1k8", "libkernel", 1, "libkernel", 1, 1, sceKernelOpen); LIB_FUNCTION("1G3lF1Gg1k8", "libkernel", 1, "libkernel", 1, 1, sceKernelOpen);
LIB_FUNCTION("wuCroIGjt2g", "libScePosix", 1, "libkernel", 1, 1, open); LIB_FUNCTION("wuCroIGjt2g", "libScePosix", 1, "libkernel", 1, 1, open);
} }
} // namespace Core::Libraries::LibKernel } // namespace Core::Libraries::LibKernel

View File

@ -1,13 +1,17 @@
#pragma once #pragma once
#include "common/types.h" #include "common/types.h"
#include "core/PS4/Loader/SymbolsResolver.h"
namespace Core::Loader {
class SymbolsResolver;
}
namespace Core::Libraries::LibKernel { namespace Core::Libraries::LibKernel {
int PS4_SYSV_ABI sceKernelOpen(const char *path, int flags, /* SceKernelMode*/ u16 mode); 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); 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
} // namespace Core::Libraries::LibKernel

View File

@ -1,20 +1,21 @@
#include "LibKernel.h"
#include "common/log.h" #include "common/log.h"
#include "common/debug.h" #include "common/debug.h"
#include <windows.h>
#include "common/singleton.h" #include "common/singleton.h"
#include "../Loader/Elf.h" #include "core/loader/elf.h"
#include "Kernel/Objects/physical_memory.h" #include "core/hle/kernel/Objects/physical_memory.h"
#include "Kernel/cpu_management.h" #include "core/hle/kernel/cpu_management.h"
#include "Kernel/event_queues.h" #include "core/hle/kernel/event_queues.h"
#include "Kernel/memory_management.h" #include "core/hle/kernel/memory_management.h"
#include "Libs.h" #include "core/hle/libraries/libkernel/libkernel.h"
#include "core/hle/libraries/libkernel/file_system.h" #include "core/hle/libraries/libkernel/file_system.h"
#include "core/hle/libraries/libkernel/time_management.h" #include "core/hle/libraries/libkernel/time_management.h"
#include "core/hle/libraries/libs.h"
namespace HLE::Libs::LibKernel { #ifdef _WIN64
#include <windows.h>
#endif
namespace Core::Libraries::LibKernel {
static u64 g_stack_chk_guard = 0xDEADBEEF54321ABC; // dummy return 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; 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(); } int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) {
void LibKernel_Register(SymbolsResolver* sym) { BREAKPOINT();
}
void LibKernel_Register(Loader::SymbolsResolver* sym) {
// obj // 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 // memory
LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, MemoryManagement::sceKernelAllocateDirectMemory); LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelAllocateDirectMemory);
LIB_FUNCTION("pO96TwzOm5E", "libkernel", 1, "libkernel", 1, 1, MemoryManagement::sceKernelGetDirectMemorySize); LIB_FUNCTION("pO96TwzOm5E", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelGetDirectMemorySize);
LIB_FUNCTION("L-Q3LEjIbgA", "libkernel", 1, "libkernel", 1, 1, MemoryManagement::sceKernelMapDirectMemory); LIB_FUNCTION("L-Q3LEjIbgA", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelMapDirectMemory);
LIB_FUNCTION("MBuItvba6z8", "libkernel", 1, "libkernel", 1, 1, sceKernelReleaseDirectMemory); LIB_FUNCTION("MBuItvba6z8", "libkernel", 1, "libkernel", 1, 1, sceKernelReleaseDirectMemory);
LIB_FUNCTION("cQke9UuBQOk", "libkernel", 1, "libkernel", 1, 1, sceKernelMunmap); LIB_FUNCTION("cQke9UuBQOk", "libkernel", 1, "libkernel", 1, 1, sceKernelMunmap);
// equeue // equeue
LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, EventQueues::sceKernelCreateEqueue); LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelCreateEqueue);
LIB_FUNCTION("fzyMKs9kim0", "libkernel", 1, "libkernel", 1, 1, EventQueues::sceKernelWaitEqueue); LIB_FUNCTION("fzyMKs9kim0", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelWaitEqueue);
// misc // 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); LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail);
Core::Libraries::LibKernel::fileSystemSymbolsRegister(sym); Core::Libraries::LibKernel::fileSystemSymbolsRegister(sym);
Core::Libraries::LibKernel::timeSymbolsRegister(sym); Core::Libraries::LibKernel::timeSymbolsRegister(sym);
} }
}; // namespace HLE::Libs::LibKernel } // namespace Core::Libraries::LibKernel

View File

@ -0,0 +1,16 @@
#pragma once
#include <sys/types.h>
#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

View File

@ -1,20 +1,27 @@
#include "time_management.h" #include "core/hle/libraries/libkernel/time_management.h"
#include "core/hle/libraries/libs.h"
#include <core/PS4/HLE/Libs.h>
#include "Lib/Timer.h" #include "Lib/Timer.h"
#include "emuTimer.h" #include "emuTimer.h"
namespace Core::Libraries::LibKernel { namespace Core::Libraries::LibKernel {
u64 PS4_SYSV_ABI sceKernelGetProcessTime() { u64 PS4_SYSV_ABI sceKernelGetProcessTime() {
return static_cast<u64>(Emulator::emuTimer::getTimeMsec() * 1000.0); // return time in microseconds return static_cast<u64>(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("4J2sUJmuHZQ", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTime);
LIB_FUNCTION("fgxnMeTNUtY", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTimeCounter); LIB_FUNCTION("fgxnMeTNUtY", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTimeCounter);
LIB_FUNCTION("BNowx2l588E", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTimeCounterFrequency); LIB_FUNCTION("BNowx2l588E", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcessTimeCounterFrequency);

View File

@ -1,13 +1,18 @@
#pragma once #pragma once
#include "common/types.h" #include "common/types.h"
#include "core/PS4/Loader/SymbolsResolver.h"
namespace Core::Loader {
class SymbolsResolver;
}
namespace Core::Libraries::LibKernel { namespace Core::Libraries::LibKernel {
u64 PS4_SYSV_ABI sceKernelGetProcessTime(); u64 PS4_SYSV_ABI sceKernelGetProcessTime();
u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounter(); u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounter();
u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounterFrequency(); u64 PS4_SYSV_ABI sceKernelGetProcessTimeCounterFrequency();
u64 PS4_SYSV_ABI sceKernelReadTsc(); u64 PS4_SYSV_ABI sceKernelReadTsc();
void timeSymbolsRegister(SymbolsResolver* sym); void timeSymbolsRegister(Loader::SymbolsResolver* sym);
}
} // namespace Core::Libraries::LibKernel

View File

@ -1,18 +1,17 @@
#include "pad.h"
#include <core/PS4/HLE/ErrorCodes.h>
#include <core/PS4/HLE/Libs.h>
#include "common/singleton.h"
#include "Emulator/Host/controller.h"
#include "common/debug.h"
#include "common/log.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 { namespace Core::Libraries::LibPad {
constexpr bool log_file_pad = true; // disable it to disable logging 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, int PS4_SYSV_ABI scePadOpen(Core::Libraries::LibUserService::SceUserServiceUserId userId, s32 type, s32 index,
const ScePadOpenParam* pParam) { const ScePadOpenParam* pParam) {
@ -47,7 +46,7 @@ int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) {
return SCE_OK; return SCE_OK;
} }
void padSymbolsRegister(SymbolsResolver* sym) { void padSymbolsRegister(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("hv1luiJrqQM", "libScePad", 1, "libScePad", 1, 1, scePadInit); LIB_FUNCTION("hv1luiJrqQM", "libScePad", 1, "libScePad", 1, 1, scePadInit);
LIB_FUNCTION("xk0AcarP3V4", "libScePad", 1, "libScePad", 1, 1, scePadOpen); LIB_FUNCTION("xk0AcarP3V4", "libScePad", 1, "libScePad", 1, 1, scePadOpen);
LIB_FUNCTION("YndgXqQVV7c", "libScePad", 1, "libScePad", 1, 1, scePadReadState); LIB_FUNCTION("YndgXqQVV7c", "libScePad", 1, "libScePad", 1, 1, scePadReadState);

View File

@ -1,30 +1,29 @@
#pragma once #pragma once
#include "common/types.h"
#include "core/PS4/Loader/SymbolsResolver.h" #include "common/types.h"
#include "core/hle/libraries/libuserservice/user_service.h" #include "core/hle/libraries/libuserservice/libuserservice.h"
namespace Core::Libraries::LibPad { namespace Core::Libraries::LibPad {
typedef enum : u32 { enum ScePadButton : u32 {
SCE_PAD_BUTTON_L3 = 0x00000002, L3 = 0x00000002,
SCE_PAD_BUTTON_R3 = 0x00000004, R3 = 0x00000004,
SCE_PAD_BUTTON_OPTIONS = 0x00000008, OPTIONS = 0x00000008,
SCE_PAD_BUTTON_UP = 0x00000010, UP = 0x00000010,
SCE_PAD_BUTTON_RIGHT = 0x00000020, RIGHT = 0x00000020,
SCE_PAD_BUTTON_DOWN = 0x00000040, DOWN = 0x00000040,
SCE_PAD_BUTTON_LEFT = 0x00000080, LEFT = 0x00000080,
SCE_PAD_BUTTON_L2 = 0x00000100, L2 = 0x00000100,
SCE_PAD_BUTTON_R2 = 0x00000200, R2 = 0x00000200,
SCE_PAD_BUTTON_L1 = 0x00000400, L1 = 0x00000400,
SCE_PAD_BUTTON_R1 = 0x00000800, R1 = 0x00000800,
SCE_PAD_BUTTON_TRIANGLE = 0x00001000, TRIANGLE = 0x00001000,
SCE_PAD_BUTTON_CIRCLE = 0x00002000, CIRCLE = 0x00002000,
SCE_PAD_BUTTON_CROSS = 0x00004000, CROSS = 0x00004000,
SCE_PAD_BUTTON_SQUARE = 0x00008000, SQUARE = 0x00008000,
SCE_PAD_BUTTON_TOUCH_PAD = 0x00100000, TOUCH_PAD = 0x00100000,
SCE_PAD_BUTTON_INTERCEPTED = 0x80000000, INTERCEPTED = 0x80000000,
} ScePadButton; };
struct ScePadOpenParam { struct ScePadOpenParam {
u08 reserve[8]; u08 reserve[8];
@ -88,11 +87,12 @@ struct ScePadData {
uint8_t deviceUniqueDataLen; uint8_t deviceUniqueDataLen;
uint8_t deviceUniqueData[12]; uint8_t deviceUniqueData[12];
}; };
// hle functions
int PS4_SYSV_ABI scePadInit(); 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); const ScePadOpenParam* pParam);
int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData); int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData);
void padSymbolsRegister(SymbolsResolver* sym); void padSymbolsRegister(Loader::SymbolsResolver* sym);
}; // namespace Core::Libraries::LibPad }; // namespace Core::Libraries::LibPad

View File

@ -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

View File

@ -1,10 +1,11 @@
#pragma once #pragma once
#include "../Loader/SymbolsResolver.h"
#include <core/PS4/Loader/Elf.h> #include "core/loader/elf.h"
#include "core/loader/symbols_resolver.h"
#define LIB_FUNCTION(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \ #define LIB_FUNCTION(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \
{\ {\
SymbolRes sr{}; \ Loader::SymbolRes sr{}; \
sr.name = nid; \ sr.name = nid; \
sr.library = lib; \ sr.library = lib; \
sr.library_version = libversion;\ sr.library_version = libversion;\
@ -18,7 +19,7 @@
#define LIB_OBJ(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \ #define LIB_OBJ(nid, lib, libversion, mod, moduleVersionMajor, moduleVersionMinor, function) \
{ \ { \
SymbolRes sr{}; \ Loader::SymbolRes sr{}; \
sr.name = nid; \ sr.name = nid; \
sr.library = lib; \ sr.library = lib; \
sr.library_version = libversion; \ sr.library_version = libversion; \
@ -38,6 +39,8 @@
#define PRINT_DUMMY_FUNCTION_NAME() \ #define PRINT_DUMMY_FUNCTION_NAME() \
{ LOG_WARN_IF(true, "dummy {}()\n", __func__); } { LOG_WARN_IF(true, "dummy {}()\n", __func__); }
namespace HLE::Libs { namespace Core::Libraries {
void Init_HLE_Libs(SymbolsResolver* sym);
} void InitHLELibs(Loader::SymbolsResolver* sym);
} // namespace Core::Libraries

View File

@ -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);
}
};

View File

@ -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

View File

@ -1,7 +1,7 @@
#include <core/PS4/HLE/ErrorCodes.h>
#include <core/PS4/HLE/Libs.h>
#include "common/log.h" #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 { namespace Core::Libraries::LibSystemService {
@ -10,7 +10,9 @@ s32 PS4_SYSV_ABI sceSystemServiceHideSplashScreen() {
return SCE_OK; return SCE_OK;
} }
void systemServiceSymbolsRegister(SymbolsResolver* sym) { void systemServiceSymbolsRegister(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("Vo5V8KAwCmk", "libSceSystemService", 1, "libSceSystemService", 1, 1, sceSystemServiceHideSplashScreen); LIB_FUNCTION("Vo5V8KAwCmk", "libSceSystemService", 1, "libSceSystemService", 1, 1,
sceSystemServiceHideSplashScreen);
} }
}; // namespace Emulator::HLE::Libraries::LibUserService
}; // namespace Core::Libraries::LibSystemService

View File

@ -1,11 +1,15 @@
#pragma once #pragma once
#include "core/PS4/Loader/SymbolsResolver.h"
#include "common/types.h"
namespace Core::Loader {
class SymbolsResolver;
}
namespace Core::Libraries::LibSystemService { namespace Core::Libraries::LibSystemService {
//HLE functions
s32 PS4_SYSV_ABI sceSystemServiceHideSplashScreen(); s32 PS4_SYSV_ABI sceSystemServiceHideSplashScreen();
void systemServiceSymbolsRegister(SymbolsResolver* sym); void systemServiceSymbolsRegister(Loader::SymbolsResolver* sym);
}; // namespace Emulator::HLE::Libraries::LibUserService }; // namespace Core::Libraries::LibSystemService

View File

@ -1,9 +1,7 @@
#include "user_service.h"
#include <core/PS4/HLE/ErrorCodes.h>
#include <core/PS4/HLE/Libs.h>
#include "common/log.h" #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 { namespace Core::Libraries::LibUserService {
@ -21,9 +19,10 @@ s32 PS4_SYSV_ABI sceUserServiceGetLoginUserIdList(SceUserServiceLoginUserIdList*
return SCE_OK; return SCE_OK;
} }
void userServiceSymbolsRegister(SymbolsResolver* sym) {
void userServiceSymbolsRegister(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("j3YMu1MVNNo", "libSceUserService", 1, "libSceUserService", 1, 1, sceUserServiceInitialize); LIB_FUNCTION("j3YMu1MVNNo", "libSceUserService", 1, "libSceUserService", 1, 1, sceUserServiceInitialize);
LIB_FUNCTION("fPhymKNvK-A", "libSceUserService", 1, "libSceUserService", 1, 1, sceUserServiceGetLoginUserIdList); LIB_FUNCTION("fPhymKNvK-A", "libSceUserService", 1, "libSceUserService", 1, 1, sceUserServiceGetLoginUserIdList);
} }
} // namespace Core::Libraries::LibUserService } // namespace Core::Libraries::LibUserService

View File

@ -1,5 +1,10 @@
#pragma once #pragma once
#include "core/PS4/Loader/SymbolsResolver.h"
#include "common/types.h"
namespace Core::Loader {
class SymbolsResolver;
}
namespace Core::Libraries::LibUserService { namespace Core::Libraries::LibUserService {
@ -16,5 +21,6 @@ struct SceUserServiceLoginUserIdList {
s32 PS4_SYSV_ABI sceUserServiceInitialize(const SceUserServiceInitializeParams* initParams); s32 PS4_SYSV_ABI sceUserServiceInitialize(const SceUserServiceInitializeParams* initParams);
s32 PS4_SYSV_ABI sceUserServiceGetLoginUserIdList(SceUserServiceLoginUserIdList* userIdList); s32 PS4_SYSV_ABI sceUserServiceGetLoginUserIdList(SceUserServiceLoginUserIdList* userIdList);
void userServiceSymbolsRegister(SymbolsResolver* sym); void userServiceSymbolsRegister(Loader::SymbolsResolver* sym);
}; // namespace Emulator::HLE::Libraries::LibUserService
}; // namespace Core::Libraries::LibUserService

View File

@ -1,13 +1,14 @@
#include "Linker.h"
#include "../virtual_memory.h"
#include "common/log.h"
#include <fmt/core.h> #include <fmt/core.h>
#include <Zydis/Zydis.h> #include <Zydis/Zydis.h>
#include "common/log.h"
#include "common/string_util.h" #include "common/string_util.h"
#include "Util/aerolib.h" #include "core/aerolib/aerolib.h"
#include "Loader/SymbolsResolver.h" #include "core/aerolib/stubs.h"
#include "HLE/Kernel/ThreadManagement.h" #include "core/linker.h"
#include "Stubs.h" #include "core/virtual_memory.h"
#include "core/hle/kernel/ThreadManagement.h"
namespace Core {
constexpr bool debug_loader = true; constexpr bool debug_loader = true;
@ -452,7 +453,7 @@ void Linker::LoadSymbols(Module* m)
bool is_sym_export = sym->st_value != 0; bool is_sym_export = sym->st_value != 0;
std::string nidName = ""; 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) if (aeronid != nullptr)
{ {
@ -463,7 +464,7 @@ void Linker::LoadSymbols(Module* m)
nidName = "UNK"; nidName = "UNK";
} }
SymbolRes sym_r{}; Loader::SymbolRes sym_r{};
sym_r.name = ids.at(0); sym_r.name = ids.at(0);
sym_r.nidName = nidName; sym_r.nidName = nidName;
sym_r.library = library->name; 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_type = sym.GetType();
auto sym_visibility = sym.GetVisibility(); auto sym_visibility = sym.GetVisibility();
u64 symbol_vitrual_addr = 0; u64 symbol_vitrual_addr = 0;
SymbolRecord symrec{}; Loader::SymbolRecord symrec{};
switch (sym_type) { switch (sym_type) {
case STT_FUN: rel_sym_type = 2; break; case STT_FUN: rel_sym_type = 2; break;
case STT_OBJECT: rel_sym_type = 1; 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, '#'); const auto ids = Common::SplitString(name, '#');
if (ids.size() == 3) // symbols are 3 parts name , library , module 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)); const auto* module = FindModule(*m, ids.at(2));
if (library != nullptr && module != nullptr) { if (library != nullptr && module != nullptr) {
SymbolRes sr{}; Loader::SymbolRes sr{};
sr.name = ids.at(0); sr.name = ids.at(0);
sr.library = library->name; sr.library = library->name;
sr.library_version = library->version; 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.module_version_minor = module->version_minor;
sr.type = Symtype; sr.type = Symtype;
const SymbolRecord* rec = nullptr; const Loader::SymbolRecord* rec = nullptr;
rec = m_hle_symbols.FindSymbol(sr); rec = m_hle_symbols.FindSymbol(sr);
if (rec != nullptr) { if (rec != nullptr) {
*return_info = *rec; *return_info = *rec;
} else { } else {
auto aeronid = aerolib::find_by_nid(sr.name.c_str()); auto aeronid = AeroLib::FindByNid(sr.name.c_str());
if (aeronid) { if (aeronid) {
return_info->name = aeronid->name; return_info->name = aeronid->name;
return_info->virtual_address = GetStub(aeronid->nid); return_info->virtual_address = AeroLib::GetStub(aeronid->nid);
} else { } else {
return_info->virtual_address = GetStub(sr.name.c_str()); return_info->virtual_address = AeroLib::GetStub(sr.name.c_str());
return_info->name = "Unknown !!!"; 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); 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() void Linker::Execute() {
{ Core::Kernel::Pthread_Init_Self_MainThread();
HLE::Libs::LibKernel::ThreadManagement::Pthread_Init_Self_MainThread();
EntryParams p{}; EntryParams p{};
p.argc = 1; p.argc = 1;
p.argv[0] = "eboot.bin"; //hmm should be ok? p.argv[0] = "eboot.bin"; //hmm should be ok?
@ -662,3 +662,5 @@ void Linker::Execute()
const auto& module = m_modules.at(0); const auto& module = m_modules.at(0);
run_main_entry(module.elf.GetElfEntry() + module.base_virtual_addr, &p, ProgramExitFunc); run_main_entry(module.elf.GetElfEntry() + module.base_virtual_addr, &p, ProgramExitFunc);
} }
} // namespace Core

View File

@ -2,8 +2,10 @@
#include <vector> #include <vector>
#include <mutex> #include <mutex>
#include "Loader/Elf.h" #include "core/loader/elf.h"
#include "Loader/SymbolsResolver.h" #include "core/loader/symbols_resolver.h"
namespace Core {
struct DynamicModuleInfo; struct DynamicModuleInfo;
class Linker; class Linker;
@ -14,14 +16,11 @@ struct EntryParams {
const char* argv[3]; const char* argv[3];
}; };
struct ModuleInfo struct ModuleInfo {
{
std::string name; std::string name;
union union {
{
u64 value; u64 value;
struct struct {
{
u32 name_offset; u32 name_offset;
u08 version_minor; u08 version_minor;
u08 version_major; u08 version_major;
@ -31,14 +30,11 @@ struct ModuleInfo
std::string enc_id; std::string enc_id;
}; };
struct LibraryInfo struct LibraryInfo {
{
std::string name; std::string name;
union union {
{
u64 value; u64 value;
struct struct {
{
u32 name_offset; u32 name_offset;
u16 version; u16 version;
u16 id; u16 id;
@ -47,8 +43,7 @@ struct LibraryInfo
std::string enc_id; std::string enc_id;
}; };
struct DynamicModuleInfo struct DynamicModuleInfo {
{
void* hash_table = nullptr; void* hash_table = nullptr;
u64 hash_table_size = 0; 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 // This struct keeps neccesary info about loaded modules. Main executeable is included too as well
struct Module struct Module {
{ Loader::Elf elf;
Elf elf;
u64 aligned_base_size = 0; u64 aligned_base_size = 0;
u64 base_virtual_addr = 0; // Base virtual address u64 base_virtual_addr = 0; // Base virtual address
@ -103,8 +97,8 @@ struct Module
std::vector<u08> m_dynamic_data; std::vector<u08> m_dynamic_data;
DynamicModuleInfo dynamic_info{}; DynamicModuleInfo dynamic_info{};
SymbolsResolver export_sym; Loader::SymbolsResolver export_sym;
SymbolsResolver import_sym; Loader::SymbolsResolver import_sym;
}; };
class Linker { class Linker {
@ -117,9 +111,9 @@ public:
void LoadModuleToMemory(Module* m); void LoadModuleToMemory(Module* m);
void LoadDynamicInfo(Module* m); void LoadDynamicInfo(Module* m);
void LoadSymbols(Module* m); void LoadSymbols(Module* m);
SymbolsResolver& getHLESymbols() { return m_hle_symbols; } Loader::SymbolsResolver& getHLESymbols() { return m_hle_symbols; }
void Relocate(Module* m); 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(); void Execute();
private: private:
@ -127,6 +121,8 @@ private:
const LibraryInfo* FindLibrary(const Module& program, const std::string& id); const LibraryInfo* FindLibrary(const Module& program, const std::string& id);
std::vector<Module> m_modules; std::vector<Module> m_modules;
SymbolsResolver m_hle_symbols{}; Loader::SymbolsResolver m_hle_symbols{};
std::mutex m_mutex; std::mutex m_mutex;
}; };
} // namespace Core

View File

@ -1,8 +1,9 @@
#include "Elf.h" #include <fmt/core.h>
#include "common/log.h" #include "common/log.h"
#include "common/debug.h" #include "common/debug.h"
#include <fmt/core.h> #include "core/loader/elf.h"
namespace Core::Loader {
constexpr bool log_file_loader = true; // disable it to disable logging 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... BREAKPOINT(); // Hmm we didn't return something...
} }
} // namespace Core::Loader

View File

@ -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_JUMP_SLOT = 7; // Create PLT entry
constexpr u32 R_X86_64_RELATIVE = 8; // Adjust by program base constexpr u32 R_X86_64_RELATIVE = 8; // Adjust by program base
namespace Core::Loader {
class Elf { class Elf {
public: public:
Elf() = default; Elf() = default;
@ -502,3 +504,5 @@ class Elf {
std::vector<elf_section_header> m_elf_shdr; std::vector<elf_section_header> m_elf_shdr;
elf_program_id_header m_self_id_header{}; elf_program_id_header m_self_id_header{};
}; };
} // namespace Core::Loader

View File

@ -1,9 +1,10 @@
#include "common/types.h"
#include "SymbolsResolver.h"
#include "common/log.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{}; SymbolRecord r{};
r.name = GenerateName(s); r.name = GenerateName(s);
r.virtual_address = virtual_addr; r.virtual_address = virtual_addr;
@ -27,3 +28,5 @@ const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const {
LOG_INFO("Unresolved! {}\n", name); LOG_INFO("Unresolved! {}\n", name);
return nullptr; return nullptr;
} }
} // namespace Core::Loader

View File

@ -5,26 +5,25 @@
#include <unordered_map> #include <unordered_map>
#include "common/types.h" #include "common/types.h"
struct SymbolRecord namespace Core::Loader {
{
std::string name; struct SymbolRecord {
std::string name;
u64 virtual_address; u64 virtual_address;
}; };
struct SymbolRes struct SymbolRes {
{ std::string name;
std::string name; std::string nidName;
std::string nidName; std::string library;
std::string library; u16 library_version;
u16 library_version; std::string module;
std::string module; u08 module_version_major;
u08 module_version_major; u08 module_version_minor;
u08 module_version_minor; u32 type;
u32 type;
}; };
class SymbolsResolver class SymbolsResolver {
{
public: public:
SymbolsResolver() = default; SymbolsResolver() = default;
virtual ~SymbolsResolver() = default; virtual ~SymbolsResolver() = default;
@ -35,5 +34,7 @@ public:
static std::string GenerateName(const SymbolRes& s); static std::string GenerateName(const SymbolRes& s);
private: private:
std::vector<SymbolRecord> m_symbols; std::vector<SymbolRecord> m_symbols;
}; };
} // namespace Core::Loader

View File

@ -1,7 +1,5 @@
#include "common/debug.h"
#include "common/log.h" #include "common/log.h"
#include "virtual_memory.h" #include "core/virtual_memory.h"
#include "core/PS4/Loader/Elf.h"
#ifdef _WIN64 #ifdef _WIN64
#include <windows.h> #include <windows.h>

View File

@ -306,15 +306,15 @@ void keyboardEvent(SDL_Event* event) {
if (event->type == SDL_EVENT_KEY_DOWN || event->type == SDL_EVENT_KEY_UP) { if (event->type == SDL_EVENT_KEY_DOWN || event->type == SDL_EVENT_KEY_UP) {
u32 button = 0; u32 button = 0;
switch (event->key.keysym.sym) { switch (event->key.keysym.sym) {
case SDLK_UP: button = ScePadButton::SCE_PAD_BUTTON_UP; break; case SDLK_UP: button = ScePadButton::UP; break;
case SDLK_DOWN: button = ScePadButton::SCE_PAD_BUTTON_DOWN; break; case SDLK_DOWN: button = ScePadButton::DOWN; break;
case SDLK_LEFT: button = ScePadButton::SCE_PAD_BUTTON_LEFT; break; case SDLK_LEFT: button = ScePadButton::LEFT; break;
case SDLK_RIGHT: button = ScePadButton::SCE_PAD_BUTTON_RIGHT; break; case SDLK_RIGHT: button = ScePadButton::RIGHT; break;
case SDLK_KP_8: button = ScePadButton ::SCE_PAD_BUTTON_TRIANGLE; break; case SDLK_KP_8: button = ScePadButton ::TRIANGLE; break;
case SDLK_KP_6: button = ScePadButton ::SCE_PAD_BUTTON_CIRCLE; break; case SDLK_KP_6: button = ScePadButton ::CIRCLE; break;
case SDLK_KP_2: button = ScePadButton ::SCE_PAD_BUTTON_CROSS; break; case SDLK_KP_2: button = ScePadButton ::CROSS; break;
case SDLK_KP_4: button = ScePadButton ::SCE_PAD_BUTTON_SQUARE; break; case SDLK_KP_4: button = ScePadButton ::SQUARE; break;
case SDLK_RETURN: button = ScePadButton ::SCE_PAD_BUTTON_OPTIONS; break; case SDLK_RETURN: button = ScePadButton ::OPTIONS; break;
default: break; default: break;
} }
if (button != 0) { if (button != 0) {

View File

@ -1,18 +1,18 @@
#include <SDL3/SDL.h>
#include <cstdio> #include <cstdio>
#include <cinttypes>
#include <thread>
#include <fmt/core.h> #include <fmt/core.h>
#include <SDL3/SDL.h>
#include <Zydis/Zydis.h>
#include "common/discord.h" #include "common/discord.h"
#include "common/types.h" #include "common/types.h"
#include "common/log.h" #include "common/log.h"
#include "common/singleton.h" #include "common/singleton.h"
#include <core/PS4/HLE/Graphics/video_out.h> #include "core/PS4/HLE/Graphics/video_out.h"
#include <Util/config.h> #include "Util/config.h"
#include <Zydis/Zydis.h> #include "emulator.h"
#include <emulator.h> #include "core/hle/libraries/libs.h"
#include <cinttypes> #include "core/linker.h"
#include <thread>
#include "core/PS4/HLE/Libs.h"
#include "core/PS4/Linker.h"
#include "emuTimer.h" #include "emuTimer.h"
int main(int argc, char* argv[]) { 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 // Argument 1 is the path of self file to boot
const char* const path = argv[1]; const char* const path = argv[1];
auto linker = Common::Singleton<Linker>::Instance(); auto linker = Common::Singleton<Core::Linker>::Instance();
HLE::Libs::Init_HLE_Libs(&linker->getHLESymbols()); Core::Libraries::InitHLELibs(&linker->getHLESymbols());
linker->LoadModule(path); linker->LoadModule(path);
std::jthread mainthread( std::jthread mainthread(
[linker](std::stop_token stop_token, void*) { [linker](std::stop_token stop_token, void*) {