VERY experimental Nintendo Switch 2 emulator
C++
core/memory: Create a special MapMemoryRegion for physical memory.
Markus Wick4042bd107bc7
diff --git a/src/core/hle/kernel/physical_memory.h b/src/core/hle/kernel/physical_memory.hindex 0905653102..b689e8e8b1 100644--- a/src/core/hle/kernel/physical_memory.h+++ b/src/core/hle/kernel/physical_memory.h@@ -14,6 +14,9 @@ namespace Kernel {// - Second to ensure all host backing memory used is aligned to 256 bytes due// to strict alignment restrictions on GPU memory.-using PhysicalMemory = std::vector<u8, Common::AlignmentAllocator<u8, 256>>;+using PhysicalMemoryVector = std::vector<u8, Common::AlignmentAllocator<u8, 256>>;+class PhysicalMemory final : public PhysicalMemoryVector {+ using PhysicalMemoryVector::PhysicalMemoryVector;+};} // namespace Kerneldiff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cppindex d223b4eccc..0b3500fce5 100644--- a/src/core/hle/kernel/vm_manager.cpp+++ b/src/core/hle/kernel/vm_manager.cpp@@ -780,8 +780,7 @@ void VMManager::UpdatePageTableForVMA(const VirtualMemoryArea& vma) {memory.UnmapRegion(page_table, vma.base, vma.size);break;case VMAType::AllocatedMemoryBlock:- memory.MapMemoryRegion(page_table, vma.base, vma.size,- vma.backing_block->data() + vma.offset);+ memory.MapMemoryRegion(page_table, vma.base, vma.size, *vma.backing_block, vma.offset);break;case VMAType::BackingMemory:memory.MapMemoryRegion(page_table, vma.base, vma.size, vma.backing_memory);diff --git a/src/core/memory.cpp b/src/core/memory.cppindex 3c2a29d9b8..f0888327f2 100644--- a/src/core/memory.cpp+++ b/src/core/memory.cpp@@ -14,6 +14,7 @@#include "common/swap.h"#include "core/arm/arm_interface.h"#include "core/core.h"+#include "core/hle/kernel/physical_memory.h"#include "core/hle/kernel/process.h"#include "core/hle/kernel/vm_manager.h"#include "core/memory.h"@@ -38,6 +39,11 @@ struct Memory::Impl {system.ArmInterface(3).PageTableChanged(*current_page_table, address_space_width);}+ void MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size,+ Kernel::PhysicalMemory& memory, VAddr offset) {+ MapMemoryRegion(page_table, base, size, memory.data() + offset);+ }+void MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, u8* target) {ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: {:016X}", size);ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: {:016X}", base);@@ -601,6 +607,11 @@ void Memory::SetCurrentPageTable(Kernel::Process& process) {impl->SetCurrentPageTable(process);}+void Memory::MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size,+ Kernel::PhysicalMemory& memory, VAddr offset) {+ impl->MapMemoryRegion(page_table, base, size, memory, offset);+}+void Memory::MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size, u8* target) {impl->MapMemoryRegion(page_table, base, size, target);}diff --git a/src/core/memory.h b/src/core/memory.hindex 1428a6d609..8913a9da42 100644--- a/src/core/memory.h+++ b/src/core/memory.h@@ -19,8 +19,9 @@ class System;}namespace Kernel {+class PhysicalMemory;class Process;-}+} // namespace Kernelnamespace Memory {@@ -65,6 +66,19 @@ public:*/void SetCurrentPageTable(Kernel::Process& process);+ /**+ * Maps an physical buffer onto a region of the emulated process address space.+ *+ * @param page_table The page table of the emulated process.+ * @param base The address to start mapping at. Must be page-aligned.+ * @param size The amount of bytes to map. Must be page-aligned.+ * @param memory Physical buffer with the memory backing the mapping. Must be of length+ * at least `size + offset`.+ * @param offset The offset within the physical memory. Must be page-aligned.+ */+ void MapMemoryRegion(Common::PageTable& page_table, VAddr base, u64 size,+ Kernel::PhysicalMemory& memory, VAddr offset);+/*** Maps an allocated buffer onto a region of the emulated process address space.*