From 6813473367dbbeee67375311a8991cedfc72eaea Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 28 Oct 2014 04:02:12 -0700 Subject: [PATCH] MemArena: Remove the low mappings for our pointers These are effectively unused, since the memmap already maps them in one place. For 32-bit, they might have some slight advantage, but we already special-case the regular "high-mem" pointer for 32-bit, so just use the one we already have... --- Source/Core/Common/MemArena.cpp | 48 ++++++++++++------------------- Source/Core/Common/MemArena.h | 8 +++--- Source/Core/Core/HW/Memmap.cpp | 51 +++++++++++---------------------- 3 files changed, 39 insertions(+), 68 deletions(-) diff --git a/Source/Core/Common/MemArena.cpp b/Source/Core/Common/MemArena.cpp index 5c3972d44a..237dc4356f 100644 --- a/Source/Core/Common/MemArena.cpp +++ b/Source/Core/Common/MemArena.cpp @@ -170,8 +170,7 @@ u8* MemArena::Find4GBBase() if (!(a_flags & MV_FAKE_VMEM) && (b_flags & MV_FAKE_VMEM)) \ continue; \ - -static bool Memory_TryBase(u8 *base, const MemoryView *views, int num_views, u32 flags, MemArena *arena) +static bool Memory_TryBase(u8 *base, MemoryView *views, int num_views, u32 flags, MemArena *arena) { // OK, we know where to find free space. Now grab it! // We just mimic the popular BAT setup. @@ -181,45 +180,38 @@ static bool Memory_TryBase(u8 *base, const MemoryView *views, int num_views, u32 // Zero all the pointers to be sure. for (int i = 0; i < num_views; i++) { - if (views[i].out_ptr_low) - *views[i].out_ptr_low = nullptr; - if (views[i].out_ptr) - *views[i].out_ptr = nullptr; + views[i].mapped_ptr = nullptr; } int i; for (i = 0; i < num_views; i++) { SKIP(flags, views[i].flags); + if (views[i].flags & MV_MIRROR_PREVIOUS) - { position = last_position; - } - else - { - *(views[i].out_ptr_low) = (u8*)arena->CreateView(position, views[i].size); - if (!*views[i].out_ptr_low) - goto bail; - } + #if _ARCH_64 - *views[i].out_ptr = (u8*)arena->CreateView( + views[i].mapped_ptr = arena->CreateView( position, views[i].size, base + views[i].virtual_address); #else if (views[i].flags & MV_MIRROR_PREVIOUS) { // No need to create multiple identical views. - *views[i].out_ptr = *views[i - 1].out_ptr; + views[i].mapped_ptr = views[i - 1].mapped_ptr; } else { - *views[i].out_ptr = (u8*)arena->CreateView( + views[i].mapped_ptr = arena->CreateView( position, views[i].size, base + (views[i].virtual_address & 0x3FFFFFFF)); } #endif - if (!*views[i].out_ptr) + if (!views[i].mapped_ptr) goto bail; - last_position = position; + if (views[i].out_ptr) + *views[i].out_ptr = (u8*) views[i].mapped_ptr; + position += views[i].size; } @@ -231,7 +223,7 @@ bail: return false; } -u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena *arena) +u8 *MemoryMap_Setup(MemoryView *views, int num_views, u32 flags, MemArena *arena) { u32 total_mem = 0; @@ -258,21 +250,17 @@ u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena return base; } -void MemoryMap_Shutdown(const MemoryView *views, int num_views, u32 flags, MemArena *arena) +void MemoryMap_Shutdown(MemoryView *views, int num_views, u32 flags, MemArena *arena) { std::set freeset; for (int i = 0; i < num_views; i++) { - const MemoryView* view = &views[i]; - u8** outptrs[2] = {view->out_ptr_low, view->out_ptr}; - for (auto outptr : outptrs) + MemoryView* view = &views[i]; + if (view->mapped_ptr && *(u8*)view->mapped_ptr && !freeset.count(view->mapped_ptr)) { - if (outptr && *outptr && !freeset.count(*outptr)) - { - arena->ReleaseView(*outptr, view->size); - freeset.insert(*outptr); - *outptr = nullptr; - } + arena->ReleaseView(view->mapped_ptr, view->size); + freeset.insert(view->mapped_ptr); + view->mapped_ptr = nullptr; } } } diff --git a/Source/Core/Common/MemArena.h b/Source/Core/Common/MemArena.h index ccfc962f22..2cc6dc3f27 100644 --- a/Source/Core/Common/MemArena.h +++ b/Source/Core/Common/MemArena.h @@ -43,14 +43,14 @@ enum { struct MemoryView { - u8 **out_ptr_low; - u8 **out_ptr; + u8** out_ptr; u32 virtual_address; u32 size; u32 flags; + void* mapped_ptr; }; // Uses a memory arena to set up an emulator-friendly memory map according to // a passed-in list of MemoryView structures. -u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena *arena); -void MemoryMap_Shutdown(const MemoryView *views, int num_views, u32 flags, MemArena *arena); +u8 *MemoryMap_Setup(MemoryView *views, int num_views, u32 flags, MemArena *arena); +void MemoryMap_Shutdown(MemoryView *views, int num_views, u32 flags, MemArena *arena); diff --git a/Source/Core/Core/HW/Memmap.cpp b/Source/Core/Core/HW/Memmap.cpp index 2483ac4906..21387577bd 100644 --- a/Source/Core/Core/HW/Memmap.cpp +++ b/Source/Core/Core/HW/Memmap.cpp @@ -63,24 +63,11 @@ static MemArena g_arena; static bool m_IsInitialized = false; // Save the Init(), Shutdown() state // END STATE_TO_SAVE -// 64-bit: Pointers to low-mem (sub-0x10000000) mirror -// 32-bit: Same as the corresponding physical/virtual pointers. u8* m_pRAM; u8* m_pL1Cache; u8* m_pEXRAM; u8* m_pFakeVMEM; -// 64-bit: Pointers to high-mem mirrors -// 32-bit: Same as above -static u8* m_pPhysicalRAM; -static u8* m_pVirtualCachedRAM; -static u8* m_pVirtualUncachedRAM; -static u8* m_pPhysicalEXRAM; // wii only -static u8* m_pVirtualCachedEXRAM; // wii only -static u8* m_pVirtualUncachedEXRAM; // wii only -static u8* m_pVirtualL1Cache; -static u8* m_pVirtualFakeVMEM; - // MMIO mapping object. MMIO::Mapping* mmio_mapping; @@ -116,19 +103,16 @@ bool IsInitialized() // We don't declare the IO region in here since its handled by other means. -static const MemoryView views[] = +static MemoryView views[] = { - {&m_pRAM, &m_pPhysicalRAM, 0x00000000, RAM_SIZE, 0}, - {nullptr, &m_pVirtualCachedRAM, 0x80000000, RAM_SIZE, MV_MIRROR_PREVIOUS}, - {nullptr, &m_pVirtualUncachedRAM, 0xC0000000, RAM_SIZE, MV_MIRROR_PREVIOUS}, - - {&m_pL1Cache, &m_pVirtualL1Cache, 0xE0000000, L1_CACHE_SIZE, 0}, - - {&m_pFakeVMEM, &m_pVirtualFakeVMEM, 0x7E000000, FAKEVMEM_SIZE, MV_FAKE_VMEM}, - - {&m_pEXRAM, &m_pPhysicalEXRAM, 0x10000000, EXRAM_SIZE, MV_WII_ONLY}, - {nullptr, &m_pVirtualCachedEXRAM, 0x90000000, EXRAM_SIZE, MV_WII_ONLY | MV_MIRROR_PREVIOUS}, - {nullptr, &m_pVirtualUncachedEXRAM, 0xD0000000, EXRAM_SIZE, MV_WII_ONLY | MV_MIRROR_PREVIOUS}, + {&m_pRAM, 0x00000000, RAM_SIZE, 0}, + {nullptr, 0x80000000, RAM_SIZE, MV_MIRROR_PREVIOUS}, + {nullptr, 0xC0000000, RAM_SIZE, MV_MIRROR_PREVIOUS}, + {&m_pL1Cache, 0xE0000000, L1_CACHE_SIZE, 0}, + {&m_pFakeVMEM, 0x7E000000, FAKEVMEM_SIZE, MV_FAKE_VMEM}, + {&m_pEXRAM, 0x10000000, EXRAM_SIZE, MV_WII_ONLY}, + {nullptr, 0x90000000, EXRAM_SIZE, MV_WII_ONLY | MV_MIRROR_PREVIOUS}, + {nullptr, 0xD0000000, EXRAM_SIZE, MV_WII_ONLY | MV_MIRROR_PREVIOUS}, }; static const int num_views = sizeof(views) / sizeof(MemoryView); @@ -154,19 +138,18 @@ void Init() else InitMMIO(mmio_mapping); - INFO_LOG(MEMMAP, "Memory system initialized. RAM at %p (mirrors at 0 @ %p, 0x80000000 @ %p , 0xC0000000 @ %p)", - m_pRAM, m_pPhysicalRAM, m_pVirtualCachedRAM, m_pVirtualUncachedRAM); + INFO_LOG(MEMMAP, "Memory system initialized. RAM at %p", m_pRAM); m_IsInitialized = true; } void DoState(PointerWrap &p) { bool wii = SConfig::GetInstance().m_LocalCoreStartupParameter.bWii; - p.DoArray(m_pPhysicalRAM, RAM_SIZE); - p.DoArray(m_pVirtualL1Cache, L1_CACHE_SIZE); + p.DoArray(m_pRAM, RAM_SIZE); + p.DoArray(m_pL1Cache, L1_CACHE_SIZE); p.DoMarker("Memory RAM"); if (bFakeVMEM) - p.DoArray(m_pVirtualFakeVMEM, FAKEVMEM_SIZE); + p.DoArray(m_pFakeVMEM, FAKEVMEM_SIZE); p.DoMarker("Memory FakeVMEM"); if (wii) p.DoArray(m_pEXRAM, EXRAM_SIZE); @@ -328,7 +311,7 @@ u8* GetPointer(const u32 _Address) case 0x0: case 0x8: if ((_Address & 0xfffffff) < REALRAM_SIZE) - return m_pPhysicalRAM + (_Address & RAM_MASK); + return m_pRAM + (_Address & RAM_MASK); case 0xc: switch (_Address >> 24) { @@ -341,7 +324,7 @@ u8* GetPointer(const u32 _Address) default: if ((_Address & 0xfffffff) < REALRAM_SIZE) - return m_pPhysicalRAM + (_Address & RAM_MASK); + return m_pRAM + (_Address & RAM_MASK); } case 0x1: @@ -350,7 +333,7 @@ u8* GetPointer(const u32 _Address) if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) { if ((_Address & 0xfffffff) < EXRAM_SIZE) - return m_pPhysicalEXRAM + (_Address & EXRAM_MASK); + return m_pEXRAM + (_Address & EXRAM_MASK); } else break; @@ -363,7 +346,7 @@ u8* GetPointer(const u32 _Address) default: if (bFakeVMEM) - return m_pVirtualFakeVMEM + (_Address & FAKEVMEM_MASK); + return m_pFakeVMEM + (_Address & FAKEVMEM_MASK); } ERROR_LOG(MEMMAP, "Unknown Pointer %#8x PC %#8x LR %#8x", _Address, PC, LR);