refactoring

This commit is contained in:
georgemoralis 2023-08-02 13:51:10 +03:00
parent 13ff3588fd
commit 7773e11c2d
5 changed files with 31 additions and 28 deletions

View File

@ -36,8 +36,8 @@ add_executable(shadps4
src/Core/PS4/Linker.h
src/Lib/Threads.cpp
src/Lib/Threads.h
src/Core/PS4/HLE/Kernel/Objects/PhysicalMemory.h
src/Core/PS4/HLE/Kernel/Objects/PhysicalMemory.cpp
src/Core/PS4/HLE/Kernel/Objects/physical_memory.h
src/Core/PS4/HLE/Kernel/Objects/physical_memory.cpp
"src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/Debug.h" "src/Core/PS4/HLE/Kernel/MemoryManagement.cpp" "src/Core/PS4/HLE/Kernel/MemoryManagement.h" "src/Core/PS4/HLE/Kernel/MemMngCodes.h" "src/Util/StringUtil.cpp")
find_package(OpenGL REQUIRED)

View File

@ -1,12 +1,14 @@
#include "MemoryManagement.h"
#include <bit>
#include "../../../../Debug.h"
#include "../../../../Util/Log.h"
#include "../Libs.h"
#include "../ErrorCodes.h"
#include "MemMngCodes.h"
#include <bit>
#include "../../../../Util/Singleton.h"
#include "Objects/PhysicalMemory.h"
#include "../ErrorCodes.h"
#include "../Libs.h"
#include "MemMngCodes.h"
#include "Objects/physical_memory.h"
namespace HLE::Libs::LibKernel::MemoryManagement {
@ -19,20 +21,19 @@ u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() {
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)){
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;
}
@ -49,7 +50,7 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u
u64 physical_addr = 0;
auto* physical_memory = Singleton<HLE::Kernel::Objects::PhysicalMemory>::Instance();
if (!physical_memory->Alloc(searchStart, searchEnd, len, alignment, &physical_addr, memoryType)) {
//TODO debug logging
// TODO debug logging
return SCE_KERNEL_ERROR_EAGAIN;
}
*physAddrOut = static_cast<s64>(physical_addr);

View File

@ -1,4 +1,4 @@
#include "PhysicalMemory.h"
#include "physical_memory.h"
namespace HLE::Kernel::Objects {
@ -11,12 +11,12 @@ bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignmen
for (const auto& block : m_allocatedBlocks) {
u64 n = block.start_addr + block.size;
if (n > find_free_pos) {
find_free_pos = n;
find_free_pos = n;
}
}
}
// align free position
find_free_pos = AlignUp(find_free_pos, alignment);
find_free_pos = AlignUp(find_free_pos, alignment);
// if the new position is between searchStart - searchEnd , allocate a new block
if (find_free_pos >= searchStart && find_free_pos + len <= searchEnd) {
@ -33,4 +33,4 @@ bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignmen
return false;
}
}
} // namespace HLE::Kernel::Objects

View File

@ -1,5 +1,6 @@
#pragma once
#include <vector>
#include "../../../../../types.h"
namespace HLE::Kernel::Objects {
@ -11,13 +12,14 @@ class PhysicalMemory {
u64 size;
int memoryType;
};
PhysicalMemory() { }
virtual ~PhysicalMemory() { }
PhysicalMemory() {}
virtual ~PhysicalMemory() {}
public:
bool Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment, u64* physAddrOut, int memoryType);
private:
std::vector<AllocatedBlock> m_allocatedBlocks;
};
}
} // namespace HLE::Kernel::Objects

View File

@ -5,7 +5,7 @@
#include "../../../Util/Log.h"
#include "Kernel/MemoryManagement.h"
#include "../../../Util/Singleton.h"
#include "Kernel/Objects/PhysicalMemory.h"
#include "Kernel/Objects/physical_memory.h"
namespace HLE::Libs::LibKernel {