From dd4430609afce172542fba1d2cd53c3029f182ce Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Tue, 12 May 2015 23:38:56 -0300 Subject: Memory: Use a table based lookup scheme to read from memory regions --- src/core/mem_map.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/core/mem_map.cpp') diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp index 66c2f77c..5ecec956 100644 --- a/src/core/mem_map.cpp +++ b/src/core/mem_map.cpp @@ -7,8 +7,11 @@ #include "common/common_types.h" #include "common/logging/log.h" +#include "core/hle/config_mem.h" +#include "core/hle/shared_page.h" #include "core/mem_map.h" #include "core/memory.h" +#include "core/memory_setup.h" //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -26,18 +29,19 @@ namespace { struct MemoryArea { u8** ptr; - size_t size; + u32 base; + u32 size; }; // We don't declare the IO regions in here since its handled by other means. static MemoryArea memory_areas[] = { - {&g_exefs_code, PROCESS_IMAGE_MAX_SIZE}, - {&g_heap, HEAP_SIZE }, - {&g_shared_mem, SHARED_MEMORY_SIZE }, - {&g_heap_linear, LINEAR_HEAP_SIZE }, - {&g_vram, VRAM_SIZE }, - {&g_dsp_mem, DSP_RAM_SIZE }, - {&g_tls_mem, TLS_AREA_SIZE }, + {&g_exefs_code, PROCESS_IMAGE_VADDR, PROCESS_IMAGE_MAX_SIZE}, + {&g_heap, HEAP_VADDR, HEAP_SIZE }, + {&g_shared_mem, SHARED_MEMORY_VADDR, SHARED_MEMORY_SIZE }, + {&g_heap_linear, LINEAR_HEAP_VADDR, LINEAR_HEAP_SIZE }, + {&g_vram, VRAM_VADDR, VRAM_SIZE }, + {&g_dsp_mem, DSP_RAM_VADDR, DSP_RAM_SIZE }, + {&g_tls_mem, TLS_AREA_VADDR, TLS_AREA_SIZE }, }; /// Represents a block of memory mapped by ControlMemory/MapMemoryBlock @@ -132,9 +136,14 @@ VAddr PhysicalToVirtualAddress(const PAddr addr) { } void Init() { + InitMemoryMap(); + for (MemoryArea& area : memory_areas) { *area.ptr = new u8[area.size]; + MapMemoryRegion(area.base, area.size, *area.ptr); } + MapMemoryRegion(CONFIG_MEMORY_VADDR, CONFIG_MEMORY_SIZE, (u8*)&ConfigMem::config_mem); + MapMemoryRegion(SHARED_PAGE_VADDR, SHARED_PAGE_SIZE, (u8*)&SharedPage::shared_page); LOG_DEBUG(HW_Memory, "initialized OK, RAM at %p", g_heap); } -- cgit v1.2.3