From 42edab01d90370a6a2eb3ae9b29a82ad440a004c Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Wed, 21 Nov 2018 16:18:23 -0500 Subject: [PATCH] Memory: move states into class --- src/core/hle/kernel/process.cpp | 11 ++++++----- src/core/hle/kernel/shared_memory.cpp | 8 ++++---- src/core/hle/kernel/thread.cpp | 2 +- src/core/memory.cpp | 14 +------------- src/core/memory.h | 17 +++++++++++++++-- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 78e9c030d..a94643111 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -188,10 +188,11 @@ ResultVal Process::HeapAllocate(VAddr target, u32 size, VMAPermission per u32 interval_size = interval.upper() - interval.lower(); LOG_DEBUG(Kernel, "Allocated FCRAM region lower={:08X}, upper={:08X}", interval.lower(), interval.upper()); - std::fill(Memory::fcram.begin() + interval.lower(), - Memory::fcram.begin() + interval.upper(), 0); - auto vma = vm_manager.MapBackingMemory( - interval_target, Memory::fcram.data() + interval.lower(), interval_size, memory_state); + std::fill(kernel.memory.fcram.begin() + interval.lower(), + kernel.memory.fcram.begin() + interval.upper(), 0); + auto vma = vm_manager.MapBackingMemory(interval_target, + kernel.memory.fcram.data() + interval.lower(), + interval_size, memory_state); ASSERT(vma.Succeeded()); vm_manager.Reprotect(vma.Unwrap(), perms); interval_target += interval_size; @@ -262,7 +263,7 @@ ResultVal Process::LinearAllocate(VAddr target, u32 size, VMAPermission p } } - u8* backing_memory = Memory::fcram.data() + physical_offset; + u8* backing_memory = kernel.memory.fcram.data() + physical_offset; std::fill(backing_memory, backing_memory + size, 0); auto vma = vm_manager.MapBackingMemory(target, backing_memory, size, MemoryState::Continuous); diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index f1acca74d..99fe2a436 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp @@ -43,8 +43,8 @@ ResultVal> KernelSystem::CreateSharedMemory( ASSERT_MSG(offset, "Not enough space in region to allocate shared memory!"); - std::fill(Memory::fcram.data() + *offset, Memory::fcram.data() + *offset + size, 0); - shared_memory->backing_blocks = {{Memory::fcram.data() + *offset, size}}; + std::fill(memory.fcram.data() + *offset, memory.fcram.data() + *offset + size, 0); + shared_memory->backing_blocks = {{memory.fcram.data() + *offset, size}}; shared_memory->holding_memory += MemoryRegionInfo::Interval(*offset, *offset + size); shared_memory->linear_heap_phys_offset = *offset; @@ -86,8 +86,8 @@ SharedPtr KernelSystem::CreateSharedMemoryForApplet( shared_memory->other_permissions = other_permissions; for (const auto& interval : backing_blocks) { shared_memory->backing_blocks.push_back( - {Memory::fcram.data() + interval.lower(), interval.upper() - interval.lower()}); - std::fill(Memory::fcram.data() + interval.lower(), Memory::fcram.data() + interval.upper(), + {memory.fcram.data() + interval.lower(), interval.upper() - interval.lower()}); + std::fill(memory.fcram.data() + interval.lower(), memory.fcram.data() + interval.upper(), 0); } shared_memory->base_address = Memory::HEAP_VADDR + offset; diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 5b26b8214..f2afc37e9 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -355,7 +355,7 @@ ResultVal> KernelSystem::CreateThread(std::string name, VAddr // Map the page to the current process' address space. vm_manager.MapBackingMemory(Memory::TLS_AREA_VADDR + available_page * Memory::PAGE_SIZE, - Memory::fcram.data() + *offset, Memory::PAGE_SIZE, + memory.fcram.data() + *offset, Memory::PAGE_SIZE, MemoryState::Locked); } diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 763b305ed..048c18d6b 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -21,12 +21,6 @@ namespace Memory { -static std::array vram; -static std::array n3ds_extra_ram; -std::array fcram; - -static PageTable* current_page_table = nullptr; - void MemorySystem::SetCurrentPageTable(PageTable* page_table) { current_page_table = page_table; if (Core::System::GetInstance().IsPoweredOn()) { @@ -78,13 +72,7 @@ void UnmapRegion(PageTable& page_table, VAddr base, u32 size) { MapPages(page_table, base / PAGE_SIZE, size / PAGE_SIZE, nullptr, PageType::Unmapped); } -/** - * Gets the pointer for virtual memory where the page is marked as RasterizerCachedMemory. - * This is used to access the memory where the page pointer is nullptr due to rasterizer cache. - * Since the cache only happens on linear heap or VRAM, we know the exact physical address and - * pointer of such virtual address - */ -static u8* GetPointerForRasterizerCache(VAddr addr) { +u8* MemorySystem::GetPointerForRasterizerCache(VAddr addr) { if (addr >= LINEAR_HEAP_VADDR && addr < LINEAR_HEAP_VADDR_END) { return fcram.data() + (addr - LINEAR_HEAP_VADDR); } diff --git a/src/core/memory.h b/src/core/memory.h index 049a1b6f0..1c78bb8ca 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -178,8 +178,6 @@ enum : VAddr { NEW_LINEAR_HEAP_VADDR_END = NEW_LINEAR_HEAP_VADDR + NEW_LINEAR_HEAP_SIZE, }; -extern std::array fcram; - /** * Flushes any externally cached rasterizer resources touching the given region. */ @@ -258,12 +256,27 @@ public: */ void RasterizerMarkRegionCached(PAddr start, u32 size, bool cached); + std::array fcram{}; + private: template T Read(const VAddr vaddr); template void Write(const VAddr vaddr, const T data); + + /** + * Gets the pointer for virtual memory where the page is marked as RasterizerCachedMemory. + * This is used to access the memory where the page pointer is nullptr due to rasterizer cache. + * Since the cache only happens on linear heap or VRAM, we know the exact physical address and + * pointer of such virtual address + */ + u8* GetPointerForRasterizerCache(VAddr addr); + + std::array vram{}; + std::array n3ds_extra_ram{}; + + PageTable* current_page_table = nullptr; }; } // namespace Memory