diff --git a/src/Core/PS4/HLE/Kernel/memory_management.cpp b/src/Core/PS4/HLE/Kernel/memory_management.cpp index 5c05979a..a3885953 100644 --- a/src/Core/PS4/HLE/Kernel/memory_management.cpp +++ b/src/Core/PS4/HLE/Kernel/memory_management.cpp @@ -42,10 +42,10 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u } auto memtype = magic_enum::enum_cast(memoryType); - 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, "search_start = {}\n", log_hex_full(searchStart)); + LOG_INFO_IF(true, "search_end = {}\n", log_hex_full(searchEnd)); + LOG_INFO_IF(true, "len = {}\n", log_hex_full(len)); + LOG_INFO_IF(true, "alignment = {}\n", log_hex_full(alignment)); LOG_INFO_IF(true, "memory_type = {}\n", magic_enum::enum_name(memtype.value())); u64 physical_addr = 0; @@ -55,7 +55,14 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u return SCE_KERNEL_ERROR_EAGAIN; } *physAddrOut = static_cast(physical_addr); - LOG_INFO_IF(true, "physAddrOut = {:#018x}\n", physical_addr); + LOG_INFO_IF(true, "physAddrOut = {}\n", log_hex_full(physical_addr)); + return SCE_OK; +} + +int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags, s64 directMemoryStart, u64 alignment) +{ + auto* physical_memory = Singleton::Instance(); + BREAKPOINT(); return SCE_OK; } diff --git a/src/Core/PS4/HLE/Kernel/memory_management.h b/src/Core/PS4/HLE/Kernel/memory_management.h index 72f633c2..bab7acf3 100644 --- a/src/Core/PS4/HLE/Kernel/memory_management.h +++ b/src/Core/PS4/HLE/Kernel/memory_management.h @@ -18,5 +18,5 @@ 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); - +int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int flags, s64 directMemoryStart, u64 alignment); }; // namespace HLE::Libs::LibKernel::MemoryManagement \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp index 190e17a8..df66ab42 100644 --- a/src/Core/PS4/HLE/LibKernel.cpp +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -11,11 +11,6 @@ namespace HLE::Libs::LibKernel { static u64 g_stack_chk_guard = 0xDEADBEEF54321ABC; //dummy return - int32_t PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, size_t len, int prot, int flags, off_t directMemoryStart, size_t alignment) { - auto* physical_memory = Singleton::Instance(); - BREAKPOINT(); - return 0; - } int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len) { BREAKPOINT(); return 0; @@ -45,9 +40,9 @@ namespace HLE::Libs::LibKernel { //obj LIB_OBJ("f7uOxY9mM1U", "libkernel", 1, "libkernel", 1, 1, &HLE::Libs::LibKernel::g_stack_chk_guard); //memory - LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, HLE::Libs::LibKernel::MemoryManagement::sceKernelAllocateDirectMemory); - LIB_FUNCTION("pO96TwzOm5E", "libkernel", 1, "libkernel", 1, 1, HLE::Libs::LibKernel::MemoryManagement::sceKernelGetDirectMemorySize); - LIB_FUNCTION("L-Q3LEjIbgA", "libkernel", 1, "libkernel", 1, 1, sceKernelMapDirectMemory); + LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, MemoryManagement::sceKernelAllocateDirectMemory); + LIB_FUNCTION("pO96TwzOm5E", "libkernel", 1, "libkernel", 1, 1, MemoryManagement::sceKernelGetDirectMemorySize); + LIB_FUNCTION("L-Q3LEjIbgA", "libkernel", 1, "libkernel", 1, 1, MemoryManagement::sceKernelMapDirectMemory); LIB_FUNCTION("MBuItvba6z8", "libkernel", 1, "libkernel", 1, 1, sceKernelReleaseDirectMemory); //equeue LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, sceKernelCreateEqueue); diff --git a/src/Core/PS4/HLE/LibKernel.h b/src/Core/PS4/HLE/LibKernel.h index 539bc9dc..16a7b4c4 100644 --- a/src/Core/PS4/HLE/LibKernel.h +++ b/src/Core/PS4/HLE/LibKernel.h @@ -6,7 +6,7 @@ void LibKernel_Register(SymbolsResolver* sym); // functions int PS4_SYSV_ABI sceKernelCreateEqueue(/* SceKernelEqueue* eq*/ int eq, const char* name); -int32_t PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, size_t len, int prot, int flags, off_t directMemoryStart, size_t alignment); + int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len); int PS4_SYSV_ABI sceKernelIsNeoMode(); int PS4_SYSV_ABI sceKernelWaitEqueue(/*SceKernelEqueue eq, SceKernelEvent* ev,*/ int num, int* out /*, SceKernelUseconds* timo*/); diff --git a/src/Util/Log.h b/src/Util/Log.h index 8ee272b2..d825a324 100644 --- a/src/Util/Log.h +++ b/src/Util/Log.h @@ -2,7 +2,6 @@ #include - namespace logging { #define LOG_TRACE SPDLOG_TRACE @@ -13,23 +12,59 @@ namespace logging { #define LOG_CRITICAL SPDLOG_CRITICAL #define LOG_TRACE_IF(flag, ...) \ - if (flag) \ - LOG_TRACE(__VA_ARGS__) + if (flag) LOG_TRACE(__VA_ARGS__) #define LOG_DEBUG_IF(flag, ...) \ - if (flag) \ - LOG_DEBUG(__VA_ARGS__) + if (flag) LOG_DEBUG(__VA_ARGS__) #define LOG_INFO_IF(flag, ...) \ - if (flag) \ - LOG_INFO(__VA_ARGS__) + if (flag) LOG_INFO(__VA_ARGS__) #define LOG_WARN_IF(flag, ...) \ - if (flag) \ - LOG_WARN(__VA_ARGS__) + if (flag) LOG_WARN(__VA_ARGS__) #define LOG_ERROR_IF(flag, ...) \ - if (flag) \ - LOG_ERROR(__VA_ARGS__) + if (flag) LOG_ERROR(__VA_ARGS__) #define LOG_CRITICAL_IF(flag, ...) \ - if (flag) \ - LOG_CRITICAL(__VA_ARGS__) + if (flag) LOG_CRITICAL(__VA_ARGS__) - int init(bool use_stdout); +int init(bool use_stdout); +} // namespace logging + +// copyright vita3k emu https://github.com/Vita3K/Vita3K/blob/master/vita3k/util/include/util/log.h +/* + returns: A string with the input number formatted in hexadecimal + Examples: + * `12` returns: `"0xC"` + * `1337` returns: `"0x539"` + * `72742069` returns: `"0x455F4B5"` +*/ +template +std::string log_hex(T val) { + using unsigned_type = typename std::make_unsigned::type; + std::stringstream ss; + ss << "0x"; + ss << std::hex << static_cast(val); + return ss.str(); +} + +/* + returns: A string with the input number formatted in hexadecimal with padding of the inputted type size + Examples: + * `uint8_t 5` returns: `"0x05"` + * `uint8_t 15` returns: `"0x0F"` + * `uint8_t 255` returns: `"0xFF"` + + * `uint16_t 15` returns: `"0x000F"` + * `uint16_t 1337` returns: `"0x0539"` + * `uint16_t 65535` returns: `"0xFFFF"` + + + * `uint32_t 15` returns: `"0x0000000F"` + * `uint32_t 1337` returns: `"0x00000539"` + * `uint32_t 65535` returns: `"0x0000FFFF"` + * `uint32_t 134217728` returns: `"0x08000000"` +*/ +template +std::string log_hex_full(T val) { + std::stringstream ss; + ss << "0x"; + ss << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex << val; + return ss.str(); }