diff --git a/CMakeLists.txt b/CMakeLists.txt index ba180f89..357476d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,8 +117,6 @@ set(KERNEL_LIB src/core/libraries/kernel/libkernel.h src/core/libraries/kernel/memory_management.cpp src/core/libraries/kernel/memory_management.h - src/core/libraries/kernel/physical_memory.cpp - src/core/libraries/kernel/physical_memory.h src/core/libraries/kernel/thread_management.cpp src/core/libraries/kernel/thread_management.h src/core/libraries/kernel/time_management.cpp diff --git a/src/core/libraries/kernel/physical_memory.cpp b/src/core/libraries/kernel/physical_memory.cpp deleted file mode 100644 index d81bbe5f..00000000 --- a/src/core/libraries/kernel/physical_memory.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "common/alignment.h" -#include "core/libraries/kernel/physical_memory.h" - -namespace Libraries::Kernel { - -bool PhysicalMemory::Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment, u64* physAddrOut, - int memoryType) { - std::scoped_lock lock{m_mutex}; - u64 find_free_pos = 0; - - // Iterate through allocated blocked and find the next free position - for (const auto& block : m_allocatedBlocks) { - u64 n = block.start_addr + block.size; - if (n > find_free_pos) { - find_free_pos = n; - } - } - - // Align free position - find_free_pos = Common::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) { - AllocatedBlock block{}; - block.size = len; - block.start_addr = find_free_pos; - block.memoryType = memoryType; - block.map_size = 0; - block.map_virtual_addr = 0; - block.prot = 0; - block.cpu_mode = VirtualMemory::MemoryMode::NoAccess; - - m_allocatedBlocks.push_back(block); - - *physAddrOut = find_free_pos; - return true; - } - - return false; -} - -bool PhysicalMemory::Map(u64 virtual_addr, u64 phys_addr, u64 len, int prot, - VirtualMemory::MemoryMode cpu_mode) { - std::scoped_lock lock{m_mutex}; - for (auto& b : m_allocatedBlocks) { - if (phys_addr >= b.start_addr && phys_addr < b.start_addr + b.size) { - if (b.map_virtual_addr != 0 || b.map_size != 0) { - return false; - } - - b.map_virtual_addr = virtual_addr; - b.map_size = len; - b.prot = prot; - b.cpu_mode = cpu_mode; - - return true; - } - } - - return false; -} - -} // namespace Libraries::Kernel diff --git a/src/core/libraries/kernel/physical_memory.h b/src/core/libraries/kernel/physical_memory.h deleted file mode 100644 index 27ef0666..00000000 --- a/src/core/libraries/kernel/physical_memory.h +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include -#include -#include "common/types.h" -#include "core/virtual_memory.h" - -namespace Libraries::Kernel { - -class PhysicalMemory { -public: - struct AllocatedBlock { - u64 start_addr; - u64 size; - int memoryType; - u64 map_virtual_addr; - u64 map_size; - int prot; - VirtualMemory::MemoryMode cpu_mode; - }; - PhysicalMemory() {} - virtual ~PhysicalMemory() {} - -public: - bool Alloc(u64 searchStart, u64 searchEnd, u64 len, u64 alignment, u64* physAddrOut, - int memoryType); - bool Map(u64 virtual_addr, u64 phys_addr, u64 len, int prot, - VirtualMemory::MemoryMode cpu_mode); - -private: - std::vector m_allocatedBlocks; - std::mutex m_mutex; -}; - -} // namespace Libraries::Kernel diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 8ecd311b..acae3b52 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -35,7 +35,7 @@ PAddr MemoryManager::Allocate(PAddr search_start, PAddr search_end, size_t size, } // Align free position - free_addr = Common::AlignUp(free_addr, alignment); + free_addr = alignment > 0 ? Common::AlignUp(free_addr, alignment) : free_addr; ASSERT(free_addr >= search_start && free_addr + size <= search_end); // Add the allocated region to the list and commit its pages.