From c071500ff47d9117626de1775d377af967f675b6 Mon Sep 17 00:00:00 2001 From: Gliniak Date: Wed, 16 Sep 2020 20:09:32 +0200 Subject: [PATCH] [Base] Specify heap type on initialization --- src/xenia/memory.cc | 57 ++++++++++++++++++++++++--------------------- src/xenia/memory.h | 23 +++++++++++++----- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/xenia/memory.cc b/src/xenia/memory.cc index f70e00f66..b6ceb54b4 100644 --- a/src/xenia/memory.cc +++ b/src/xenia/memory.cc @@ -158,24 +158,26 @@ bool Memory::Initialize() { physical_membase_ = mapping_base_ + 0x100000000ull; // Prepare virtual heaps. - heaps_.v00000000.Initialize(this, virtual_membase_, 0x00000000, 0x40000000, - 4096); - heaps_.v40000000.Initialize(this, virtual_membase_, 0x40000000, - 0x40000000 - 0x01000000, 64 * 1024); - heaps_.v80000000.Initialize(this, virtual_membase_, 0x80000000, 0x10000000, - 64 * 1024); - heaps_.v90000000.Initialize(this, virtual_membase_, 0x90000000, 0x10000000, - 4096); + heaps_.v00000000.Initialize(this, virtual_membase_, HeapType::kGuestVirtual, + 0x00000000, 0x40000000, 4096); + heaps_.v40000000.Initialize(this, virtual_membase_, HeapType::kGuestVirtual, + 0x40000000, 0x40000000 - 0x01000000, 64 * 1024); + heaps_.v80000000.Initialize(this, virtual_membase_, HeapType::kGuestXex, + 0x80000000, 0x10000000, 64 * 1024); + heaps_.v90000000.Initialize(this, virtual_membase_, HeapType::kGuestXex, + 0x90000000, 0x10000000, 4096); // Prepare physical heaps. - heaps_.physical.Initialize(this, physical_membase_, 0x00000000, 0x20000000, - 4096); - heaps_.vA0000000.Initialize(this, virtual_membase_, 0xA0000000, 0x20000000, - 64 * 1024, &heaps_.physical); - heaps_.vC0000000.Initialize(this, virtual_membase_, 0xC0000000, 0x20000000, - 16 * 1024 * 1024, &heaps_.physical); - heaps_.vE0000000.Initialize(this, virtual_membase_, 0xE0000000, 0x1FD00000, - 4096, &heaps_.physical); + heaps_.physical.Initialize(this, physical_membase_, HeapType::kGuestPhysical, + 0x00000000, 0x20000000, 4096); + heaps_.vA0000000.Initialize(this, virtual_membase_, HeapType::kGuestPhysical, + 0xA0000000, 0x20000000, 64 * 1024, + &heaps_.physical); + heaps_.vC0000000.Initialize(this, virtual_membase_, HeapType::kGuestPhysical, + 0xC0000000, 0x20000000, 16 * 1024 * 1024, + &heaps_.physical); + heaps_.vE0000000.Initialize(this, virtual_membase_, HeapType::kGuestPhysical, + 0xE0000000, 0x1FD00000, 4096, &heaps_.physical); // Protect the first and last 64kb of memory. heaps_.v00000000.AllocFixed( @@ -633,11 +635,12 @@ BaseHeap::BaseHeap() BaseHeap::~BaseHeap() = default; -void BaseHeap::Initialize(Memory* memory, uint8_t* membase, uint32_t heap_base, - uint32_t heap_size, uint32_t page_size, - uint32_t host_address_offset) { +void BaseHeap::Initialize(Memory* memory, uint8_t* membase, HeapType heap_type, + uint32_t heap_base, uint32_t heap_size, + uint32_t page_size, uint32_t host_address_offset) { memory_ = memory; membase_ = membase; + heap_type_ = heap_type; heap_base_ = heap_base; heap_size_ = heap_size; page_size_ = page_size; @@ -1346,9 +1349,10 @@ VirtualHeap::VirtualHeap() = default; VirtualHeap::~VirtualHeap() = default; void VirtualHeap::Initialize(Memory* memory, uint8_t* membase, - uint32_t heap_base, uint32_t heap_size, - uint32_t page_size) { - BaseHeap::Initialize(memory, membase, heap_base, heap_size, page_size); + HeapType heap_type, uint32_t heap_base, + uint32_t heap_size, uint32_t page_size) { + BaseHeap::Initialize(memory, membase, heap_type, heap_base, heap_size, + page_size); } PhysicalHeap::PhysicalHeap() : parent_heap_(nullptr) {} @@ -1356,8 +1360,9 @@ PhysicalHeap::PhysicalHeap() : parent_heap_(nullptr) {} PhysicalHeap::~PhysicalHeap() = default; void PhysicalHeap::Initialize(Memory* memory, uint8_t* membase, - uint32_t heap_base, uint32_t heap_size, - uint32_t page_size, VirtualHeap* parent_heap) { + HeapType heap_type, uint32_t heap_base, + uint32_t heap_size, uint32_t page_size, + VirtualHeap* parent_heap) { uint32_t host_address_offset; if (heap_base >= 0xE0000000 && xe::memory::allocation_granularity() > 0x1000) { @@ -1366,8 +1371,8 @@ void PhysicalHeap::Initialize(Memory* memory, uint8_t* membase, host_address_offset = 0; } - BaseHeap::Initialize(memory, membase, heap_base, heap_size, page_size, - host_address_offset); + BaseHeap::Initialize(memory, membase, heap_type, heap_base, heap_size, + page_size, host_address_offset); parent_heap_ = parent_heap; system_page_size_ = uint32_t(xe::memory::page_size()); diff --git a/src/xenia/memory.h b/src/xenia/memory.h index df76c39bc..d5e7ea4da 100644 --- a/src/xenia/memory.h +++ b/src/xenia/memory.h @@ -36,6 +36,13 @@ enum SystemHeapFlag : uint32_t { kSystemHeapDefault = kSystemHeapVirtual, }; +enum class HeapType : uint8_t { + kGuestVirtual, + kGuestXex, + kGuestPhysical, + kHostPhysical, +}; + enum MemoryAllocationFlag : uint32_t { kMemoryAllocationReserve = 1 << 0, kMemoryAllocationCommit = 1 << 1, @@ -106,6 +113,9 @@ class BaseHeap { // Size of each page within the heap range in bytes. uint32_t page_size() const { return page_size_; } + // Type of specified heap + HeapType heap_type() const { return heap_type_; } + // Offset added to the virtual addresses to convert them to host addresses // (not including membase). uint32_t host_address_offset() const { return host_address_offset_; } @@ -188,12 +198,13 @@ class BaseHeap { protected: BaseHeap(); - void Initialize(Memory* memory, uint8_t* membase, uint32_t heap_base, - uint32_t heap_size, uint32_t page_size, + void Initialize(Memory* memory, uint8_t* membase, HeapType heap_type, + uint32_t heap_base, uint32_t heap_size, uint32_t page_size, uint32_t host_address_offset = 0); Memory* memory_; uint8_t* membase_; + HeapType heap_type_; uint32_t heap_base_; uint32_t heap_size_; uint32_t page_size_; @@ -209,8 +220,8 @@ class VirtualHeap : public BaseHeap { ~VirtualHeap() override; // Initializes the heap properties and allocates the page table. - void Initialize(Memory* memory, uint8_t* membase, uint32_t heap_base, - uint32_t heap_size, uint32_t page_size); + void Initialize(Memory* memory, uint8_t* membase, HeapType heap_type, + uint32_t heap_base, uint32_t heap_size, uint32_t page_size); }; // A heap for ranges of memory that are mapped to physical ranges. @@ -226,8 +237,8 @@ class PhysicalHeap : public BaseHeap { ~PhysicalHeap() override; // Initializes the heap properties and allocates the page table. - void Initialize(Memory* memory, uint8_t* membase, uint32_t heap_base, - uint32_t heap_size, uint32_t page_size, + void Initialize(Memory* memory, uint8_t* membase, HeapType heap_type, + uint32_t heap_base, uint32_t heap_size, uint32_t page_size, VirtualHeap* parent_heap); bool Alloc(uint32_t size, uint32_t alignment, uint32_t allocation_type,