memory management refactoring

This commit is contained in:
georgemoralis 2023-08-03 13:05:13 +03:00
parent 3e60a67785
commit b7420e7daa
8 changed files with 96 additions and 115 deletions

View File

@ -1,10 +0,0 @@
#pragma once
#include <types.h>
namespace HLE::Libs::LibKernel::MemoryManagement {
u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize();
int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len, u64 alignment, int memoryType, s64* physAddrOut);
}; // namespace HLE::Libs::LibKernel::MemoryManagement

View File

@ -1,14 +1,14 @@
#include <debug.h>
#include "ThreadManagement.h" #include "ThreadManagement.h"
#include <debug.h>
#include "../ErrorCodes.h" #include "../ErrorCodes.h"
namespace HLE::Libs::LibKernel::ThreadManagement 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;
void Pthread_Init_Self_MainThread() { void Pthread_Init_Self_MainThread() {
g_pthread_self = new PthreadInternal{}; g_pthread_self = new PthreadInternal{};
scePthreadAttrInit(&g_pthread_self->attr); scePthreadAttrInit(&g_pthread_self->attr);
@ -17,7 +17,6 @@ void Pthread_Init_Self_MainThread() {
} }
int scePthreadAttrInit(ScePthreadAttr* attr) { int scePthreadAttrInit(ScePthreadAttr* attr) {
*attr = new PthreadAttrInternal{}; *attr = new PthreadAttrInternal{};
int result = pthread_attr_init(&(*attr)->pth_attr); int result = pthread_attr_init(&(*attr)->pth_attr);
@ -41,7 +40,6 @@ int scePthreadAttrInit(ScePthreadAttr* attr) {
} }
int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) { int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) {
if (attr == nullptr || *attr == nullptr) { if (attr == nullptr || *attr == nullptr) {
return SCE_KERNEL_ERROR_EINVAL; return SCE_KERNEL_ERROR_EINVAL;
} }
@ -50,8 +48,7 @@ int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) {
switch (detachstate) { switch (detachstate) {
case 0: pstate = PTHREAD_CREATE_JOINABLE; break; case 0: pstate = PTHREAD_CREATE_JOINABLE; break;
case 1: pstate = PTHREAD_CREATE_DETACHED; break; case 1: pstate = PTHREAD_CREATE_DETACHED; break;
default: default: BREAKPOINT(); // unknown state
BREAKPOINT(); // unknown state
} }
int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate); int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate);
@ -65,7 +62,6 @@ int scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachstate) {
} }
int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) { int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) {
if (attr == nullptr || *attr == nullptr) { if (attr == nullptr || *attr == nullptr) {
return SCE_KERNEL_ERROR_EINVAL; return SCE_KERNEL_ERROR_EINVAL;
} }
@ -86,7 +82,6 @@ int scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) {
} }
int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param) { int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param) {
if (param == nullptr || attr == nullptr || *attr == nullptr) { if (param == nullptr || attr == nullptr || *attr == nullptr) {
return SCE_KERNEL_ERROR_EINVAL; return SCE_KERNEL_ERROR_EINVAL;
} }
@ -109,13 +104,11 @@ int scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam*
} }
int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) { int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) {
if (attr == nullptr || *attr == nullptr) { if (attr == nullptr || *attr == nullptr) {
return SCE_KERNEL_ERROR_EINVAL; return SCE_KERNEL_ERROR_EINVAL;
} }
if (policy!= SCHED_OTHER) if (policy != SCHED_OTHER) {
{
BREAKPOINT(); // invest if policy is other and if winpthreadlibrary support it BREAKPOINT(); // invest if policy is other and if winpthreadlibrary support it
} }
@ -129,4 +122,4 @@ int scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) {
return SCE_KERNEL_ERROR_EINVAL; return SCE_KERNEL_ERROR_EINVAL;
} }
}; }; // namespace HLE::Libs::LibKernel::ThreadManagement

View File

@ -1,16 +1,13 @@
#include "MemoryManagement.h" #include <debug.h>
#include <bit> #include <bit>
#include <magic_enum.hpp> #include <magic_enum.hpp>
#include <debug.h>
#include <debug.h>
#include "../../../../Util/Log.h" #include "../../../../Util/Log.h"
#include "../../../../Util/Singleton.h" #include "../../../../Util/Singleton.h"
#include "../ErrorCodes.h" #include "../ErrorCodes.h"
#include "../Libs.h" #include "../Libs.h"
#include "MemMngCodes.h"
#include "Objects/physical_memory.h" #include "Objects/physical_memory.h"
#include "memory_management.h"
namespace HLE::Libs::LibKernel::MemoryManagement { namespace HLE::Libs::LibKernel::MemoryManagement {

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <types.h> #include <types.h>
// constants // constants
@ -12,3 +13,10 @@ enum MemoryTypes : u32 {
SCE_KERNEL_WC_GARLIC = 3, // write - combining mode (Garlic bus) SCE_KERNEL_WC_GARLIC = 3, // write - combining mode (Garlic bus)
SCE_KERNEL_WB_GARLIC = 10 // write - back mode (Garlic bus) SCE_KERNEL_WB_GARLIC = 10 // write - back mode (Garlic bus)
}; };
namespace HLE::Libs::LibKernel::MemoryManagement {
u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize();
int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len, u64 alignment, int memoryType, s64* physAddrOut);
}; // namespace HLE::Libs::LibKernel::MemoryManagement

View File

@ -3,7 +3,7 @@
#include "Libs.h" #include "Libs.h"
#include <debug.h> #include <debug.h>
#include "../../../Util/Log.h" #include "../../../Util/Log.h"
#include "Kernel/MemoryManagement.h" #include "Kernel/memory_management.h"
#include "../../../Util/Singleton.h" #include "../../../Util/Singleton.h"
#include "Kernel/Objects/physical_memory.h" #include "Kernel/Objects/physical_memory.h"

View File

@ -5,7 +5,7 @@ namespace HLE::Libs::LibSceGnmDriver {
void LibSceGnmDriver_Register(SymbolsResolver* sym); void LibSceGnmDriver_Register(SymbolsResolver* sym);
//functions // functions
int sceGnmAddEqEvent(/* SceKernelEqueue eq, EqEventType id,*/ void* udata); int sceGnmAddEqEvent(/* SceKernelEqueue eq, EqEventType id,*/ void* udata);
bool sceGnmAreSubmitsAllowed(); bool sceGnmAreSubmitsAllowed();
int /* WorkloadStatus*/ sceGnmBeginWorkload(uint64_t* workload /*, WorkloadStream stream*/); int /* WorkloadStatus*/ sceGnmBeginWorkload(uint64_t* workload /*, WorkloadStream stream*/);

View File

@ -1,75 +1,68 @@
#include "LibSceVideoOut.h" #include "LibSceVideoOut.h"
#include "Libs.h"
#include "../Loader/Elf.h"
#include <debug.h> #include <debug.h>
#include "VideoOut/VideoOutCodes.h"
#include "UserManagement/UsrMngCodes.h"
#include "../../../Util/Log.h" #include "../../../Util/Log.h"
#include "../Loader/Elf.h"
#include "Libs.h"
#include "UserManagement/UsrMngCodes.h"
#include "VideoOut/VideoOutCodes.h"
namespace HLE::Libs::LibSceVideoOut { namespace HLE::Libs::LibSceVideoOut {
int32_t PS4_SYSV_ABI sceVideoOutGetFlipStatus(int32_t handle /*, SceVideoOutFlipStatus* status*/) { int32_t PS4_SYSV_ABI sceVideoOutGetFlipStatus(int32_t handle /*, SceVideoOutFlipStatus* status*/) {
BREAKPOINT(); BREAKPOINT();
return 0; return 0;
} }
int32_t PS4_SYSV_ABI sceVideoOutSubmitFlip(int32_t handle, int32_t bufferIndex, int32_t flipMode, int64_t flipArg) { int32_t PS4_SYSV_ABI sceVideoOutSubmitFlip(int32_t handle, int32_t bufferIndex, int32_t flipMode, int64_t flipArg) {
BREAKPOINT(); BREAKPOINT();
return 0; return 0;
} }
int32_t PS4_SYSV_ABI sceVideoOutRegisterBuffers(int32_t handle, int32_t startIndex, void* const* addresses, int32_t bufferNum /*, int32_t PS4_SYSV_ABI sceVideoOutRegisterBuffers(int32_t handle, int32_t startIndex, void* const* addresses, int32_t bufferNum /*,
const SceVideoOutBufferAttribute* attribute*/) { const SceVideoOutBufferAttribute* attribute*/) {
BREAKPOINT(); BREAKPOINT();
return 0; return 0;
} }
int32_t PS4_SYSV_ABI sceVideoOutAddFlipEvent(/*SceKernelEqueue eq,*/ int32_t handle, void* udata) { int32_t PS4_SYSV_ABI sceVideoOutAddFlipEvent(/*SceKernelEqueue eq,*/ int32_t handle, void* udata) {
//BREAKPOINT(); // BREAKPOINT();
PRINT_DUMMY_FUNCTION_NAME(); PRINT_DUMMY_FUNCTION_NAME();
return 0; return 0;
} }
int32_t PS4_SYSV_ABI sceVideoOutSetFlipRate(int32_t handle, int32_t rate) { int32_t PS4_SYSV_ABI sceVideoOutSetFlipRate(int32_t handle, int32_t rate) {
BREAKPOINT(); BREAKPOINT();
return 0; return 0;
} }
void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(/* SceVideoOutBufferAttribute* attribute,*/ uint32_t pixelFormat, uint32_t tilingMode, void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(/* SceVideoOutBufferAttribute* attribute,*/ uint32_t pixelFormat, uint32_t tilingMode,
uint32_t aspectRatio, uint32_t aspectRatio, uint32_t width, uint32_t height, uint32_t pitchInPixel) {
uint32_t width, uint32_t height, uint32_t pitchInPixel)
{
BREAKPOINT(); BREAKPOINT();
} }
int32_t PS4_SYSV_ABI sceVideoOutGetResolutionStatus(int32_t handle /*, SceVideoOutResolutionStatus* status*/) { int32_t PS4_SYSV_ABI sceVideoOutGetResolutionStatus(int32_t handle /*, SceVideoOutResolutionStatus* status*/) {
BREAKPOINT(); BREAKPOINT();
return 0; return 0;
} }
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_DUMMY_FUNCTION_NAME(); PRINT_DUMMY_FUNCTION_NAME();
if (userId != SCE_USER_SERVICE_USER_ID_SYSTEM) if (userId != SCE_USER_SERVICE_USER_ID_SYSTEM) {
{
BREAKPOINT(); BREAKPOINT();
} }
if (busType != SCE_VIDEO_OUT_BUS_TYPE_MAIN) if (busType != SCE_VIDEO_OUT_BUS_TYPE_MAIN) {
{
BREAKPOINT(); BREAKPOINT();
} }
if (index != 0) if (index != 0) {
{
BREAKPOINT(); BREAKPOINT();
} }
if (param != nullptr) if (param != nullptr) {
{
BREAKPOINT(); BREAKPOINT();
} }
return 1;//dummy return TODO return 1; // dummy return TODO
} }
int32_t PS4_SYSV_ABI sceVideoOutIsFlipPending(int32_t handle) { int32_t PS4_SYSV_ABI sceVideoOutIsFlipPending(int32_t handle) {
BREAKPOINT(); BREAKPOINT();
return 0; return 0;
} }
void LibSceVideoOut_Register(SymbolsResolver* sym) void LibSceVideoOut_Register(SymbolsResolver* sym) {
{
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);
@ -79,6 +72,6 @@ namespace HLE::Libs::LibSceVideoOut {
LIB_FUNCTION("6kPnj51T62Y", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutGetResolutionStatus); LIB_FUNCTION("6kPnj51T62Y", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutGetResolutionStatus);
LIB_FUNCTION("Up36PTk687E", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutOpen); LIB_FUNCTION("Up36PTk687E", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutOpen);
LIB_FUNCTION("zgXifHT9ErY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutIsFlipPending); LIB_FUNCTION("zgXifHT9ErY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutIsFlipPending);
} }
}; }; // namespace HLE::Libs::LibSceVideoOut

View File

@ -1,16 +1,16 @@
#include "Libs.h" #include "Libs.h"
#include "LibC.h" #include "LibC.h"
#include "LibKernel.h" #include "LibKernel.h"
#include "LibSceVideoOut.h"
#include "LibSceGnmDriver.h" #include "LibSceGnmDriver.h"
#include "LibSceVideoOut.h"
namespace HLE::Libs { namespace HLE::Libs {
void Init_HLE_Libs(SymbolsResolver *sym) void Init_HLE_Libs(SymbolsResolver *sym) {
{
LibC::LibC_Register(sym); LibC::LibC_Register(sym);
LibKernel::LibKernel_Register(sym); LibKernel::LibKernel_Register(sym);
LibSceVideoOut::LibSceVideoOut_Register(sym); LibSceVideoOut::LibSceVideoOut_Register(sym);
LibSceGnmDriver::LibSceGnmDriver_Register(sym); LibSceGnmDriver::LibSceGnmDriver_Register(sym);
}
} }
} // namespace HLE::Libs