improvements in sceKernelAllocateDirectMemory and function logging

This commit is contained in:
georgemoralis 2023-07-27 17:56:57 +03:00
parent c0c6024e2c
commit 818e0b7404
6 changed files with 52 additions and 10 deletions

View File

@ -3,4 +3,4 @@ constexpr int SCE_OK = 0;
constexpr int SCE_KERNEL_ERROR_ENOMEM = 0x8002000c;//Insufficient memory constexpr int SCE_KERNEL_ERROR_ENOMEM = 0x8002000c;//Insufficient memory
constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016;//null or invalid states constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016;//null or invalid states
constexpr int SCE_KERNEL_ERROR_EAGAIN = 0x80020023;// Memory cannot be allocated constexpr int SCE_KERNEL_ERROR_EAGAIN = 0x80020023;//Memory cannot be allocated

View File

@ -3,9 +3,9 @@
// constants // constants
constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 5376_MB; // ~ 6GB constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 5376_MB;// ~ 6GB
//memory types //memory types
constexpr int SCE_KERNEL_WB_ONION = 0; // write - back mode (Onion bus) constexpr int SCE_KERNEL_WB_ONION = 0;//write - back mode (Onion bus)
constexpr int SCE_KERNEL_WC_GARLIC = 3; // write - combining mode (Garlic bus) constexpr int SCE_KERNEL_WC_GARLIC = 3;//write - combining mode (Garlic bus)
constexpr int SCE_KERNEL_WB_GARLIC = 10; // write - back mode (Garlic bus) constexpr int SCE_KERNEL_WB_GARLIC = 10;//write - back mode (Garlic bus)

View File

@ -1,5 +1,8 @@
#include "MemoryManagement.h" #include "MemoryManagement.h"
#include "../../../../Debug.h" #include "../../../../Debug.h"
#include "../../../../Util/Log.h"
#include "../Libs.h"
#include "../ErrorCodes.h"
#include "MemMngCodes.h" #include "MemMngCodes.h"
#include <bit> #include <bit>
@ -7,11 +10,40 @@ namespace HLE::Libs::LibKernel::MemoryManagement {
bool isPowerOfTwo(u64 n) { return std::popcount(n) == 1; } bool isPowerOfTwo(u64 n) { return std::popcount(n) == 1; }
bool is16KBAligned(u64 n) { return ((n % (static_cast<u64>(16) * 1024) == 0)); } bool is16KBAligned(u64 n) { return ((n % (16ull * 1024) == 0)); }
u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() { return SCE_KERNEL_MAIN_DMEM_SIZE; } u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() {
PRINT_FUNCTION_NAME();
return SCE_KERNEL_MAIN_DMEM_SIZE;
}
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){
PRINT_FUNCTION_NAME();
if (searchStart < 0 || searchEnd <= searchStart) {
//TODO debug logging
return SCE_KERNEL_ERROR_EINVAL;
}
bool isInRange = (searchStart < len && searchEnd > len);
if (len <= 0 || !is16KBAligned(len) || !isInRange){
// TODO debug logging
return SCE_KERNEL_ERROR_EINVAL;
}
if ((alignment != 0 || is16KBAligned(alignment)) && !isPowerOfTwo(alignment)){
// TODO debug logging
return SCE_KERNEL_ERROR_EINVAL;
}
if (physAddrOut == nullptr) {
// TODO debug logging
return SCE_KERNEL_ERROR_EINVAL;
}
LOG_INFO_IF(true, "search_start = {:#018x}\n", searchStart);
LOG_INFO_IF(true, "search_end = {:#018x}\n", searchEnd);
LOG_INFO_IF(true, "len = {:#018x}\n", len);
LOG_INFO_IF(true, "alignment = {:#018x}\n", alignment);
LOG_INFO_IF(true, "memory_type = {}\n", memoryType);
BREAKPOINT(); BREAKPOINT();
return 0; return 0;
} }

View File

@ -21,7 +21,7 @@ namespace HLE::Libs::LibKernel {
int PS4_SYSV_ABI sceKernelCreateEqueue(/* SceKernelEqueue* eq*/ int eq, const char* name) int PS4_SYSV_ABI sceKernelCreateEqueue(/* SceKernelEqueue* eq*/ int eq, const char* name)
{ {
//BREAKPOINT(); //BREAKPOINT();
LOG_INFO_IF(true, "dummy sceKernelCreateEqueue\n"); PRINT_DUMMY_FUNCTION_NAME();
return 0; return 0;
} }
int PS4_SYSV_ABI sceKernelWaitEqueue(/*SceKernelEqueue eq, SceKernelEvent* ev,*/ int num, int* out /*, SceKernelUseconds* timo*/) int PS4_SYSV_ABI sceKernelWaitEqueue(/*SceKernelEqueue eq, SceKernelEvent* ev,*/ int num, int* out /*, SceKernelUseconds* timo*/)
@ -32,6 +32,7 @@ namespace HLE::Libs::LibKernel {
int PS4_SYSV_ABI sceKernelIsNeoMode() int PS4_SYSV_ABI sceKernelIsNeoMode()
{ {
//BREAKPOINT(); //BREAKPOINT();
PRINT_DUMMY_FUNCTION_NAME();
return 0; //it isn't PS4VR TODO return 0; //it isn't PS4VR TODO
} }

View File

@ -24,7 +24,7 @@ namespace HLE::Libs::LibSceVideoOut {
} }
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();
LOG_INFO_IF(true, "dummy sceVideoOutAddFlipEvent\n"); 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) {
@ -45,6 +45,7 @@ namespace HLE::Libs::LibSceVideoOut {
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();
if (userId != SCE_USER_SERVICE_USER_ID_SYSTEM) if (userId != SCE_USER_SERVICE_USER_ID_SYSTEM)
{ {
BREAKPOINT(); BREAKPOINT();
@ -61,7 +62,6 @@ namespace HLE::Libs::LibSceVideoOut {
{ {
BREAKPOINT(); BREAKPOINT();
} }
LOG_INFO_IF(true, "dummy sceVideoOutOpen\n");
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) {

View File

@ -29,6 +29,15 @@
auto func = reinterpret_cast<u64>(function); \ auto func = reinterpret_cast<u64>(function); \
sym->AddSymbol(sr, func); \ sym->AddSymbol(sr, func); \
} }
#define PRINT_FUNCTION_NAME() \
{ \
LOG_INFO_IF(true, "{}()\n", __func__); \
}
#define PRINT_DUMMY_FUNCTION_NAME() \
{ LOG_INFO_IF(true, "dummy {}()\n", __func__); }
namespace HLE::Libs { namespace HLE::Libs {
void Init_HLE_Libs(SymbolsResolver* sym); void Init_HLE_Libs(SymbolsResolver* sym);
} }