diff options
Diffstat (limited to 'src/core/mem_map.cpp')
| -rw-r--r-- | src/core/mem_map.cpp | 113 |
1 files changed, 31 insertions, 82 deletions
diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp index ae88cfb11..46e271c80 100644 --- a/src/core/mem_map.cpp +++ b/src/core/mem_map.cpp | |||
| @@ -2,10 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/common_funcs.h" | ||
| 6 | #include "common/common_types.h" | 5 | #include "common/common_types.h" |
| 7 | #include "common/logging/log.h" | 6 | #include "common/logging/log.h" |
| 8 | #include "common/mem_arena.h" | ||
| 9 | 7 | ||
| 10 | #include "core/mem_map.h" | 8 | #include "core/mem_map.h" |
| 11 | 9 | ||
| @@ -13,100 +11,51 @@ | |||
| 13 | 11 | ||
| 14 | namespace Memory { | 12 | namespace Memory { |
| 15 | 13 | ||
| 16 | u8* g_base; ///< The base pointer to the auto-mirrored arena. | 14 | u8* g_exefs_code; ///< ExeFS:/.code is loaded here |
| 15 | u8* g_system_mem; ///< System memory | ||
| 16 | u8* g_heap; ///< Application heap (main memory) | ||
| 17 | u8* g_heap_linear; ///< Linear heap | ||
| 18 | u8* g_vram; ///< Video memory (VRAM) pointer | ||
| 19 | u8* g_shared_mem; ///< Shared memory | ||
| 20 | u8* g_dsp_mem; ///< DSP memory | ||
| 21 | u8* g_kernel_mem; ///< Kernel memory | ||
| 17 | 22 | ||
| 18 | static MemArena arena; ///< The MemArena class | 23 | namespace { |
| 19 | 24 | ||
| 20 | u8* g_exefs_code; ///< ExeFS:/.code is loaded here | 25 | struct MemoryArea { |
| 21 | u8* g_system_mem; ///< System memory | 26 | u8** ptr; |
| 22 | u8* g_heap; ///< Application heap (main memory) | 27 | size_t size; |
| 23 | u8* g_heap_linear; ///< Linear heap | ||
| 24 | u8* g_vram; ///< Video memory (VRAM) pointer | ||
| 25 | u8* g_shared_mem; ///< Shared memory | ||
| 26 | u8* g_dsp_mem; ///< DSP memory | ||
| 27 | u8* g_kernel_mem; ///< Kernel memory | ||
| 28 | |||
| 29 | static u8* physical_bootrom; ///< Bootrom physical memory | ||
| 30 | static u8* uncached_bootrom; | ||
| 31 | |||
| 32 | static u8* physical_exefs_code; ///< Phsical ExeFS:/.code is loaded here | ||
| 33 | static u8* physical_system_mem; ///< System physical memory | ||
| 34 | static u8* physical_fcram; ///< Main physical memory (FCRAM) | ||
| 35 | static u8* physical_heap_gsp; ///< GSP heap physical memory | ||
| 36 | static u8* physical_vram; ///< Video physical memory (VRAM) | ||
| 37 | static u8* physical_shared_mem; ///< Physical shared memory | ||
| 38 | static u8* physical_dsp_mem; ///< Physical DSP memory | ||
| 39 | static u8* physical_kernel_mem; ///< Kernel memory | ||
| 40 | |||
| 41 | // We don't declare the IO region in here since its handled by other means. | ||
| 42 | static MemoryView g_views[] = { | ||
| 43 | {&g_exefs_code, &physical_exefs_code, EXEFS_CODE_VADDR, EXEFS_CODE_SIZE, 0}, | ||
| 44 | {&g_vram, &physical_vram, VRAM_VADDR, VRAM_SIZE, 0}, | ||
| 45 | {&g_heap, &physical_fcram, HEAP_VADDR, HEAP_SIZE, MV_IS_PRIMARY_RAM}, | ||
| 46 | {&g_shared_mem, &physical_shared_mem, SHARED_MEMORY_VADDR, SHARED_MEMORY_SIZE, 0}, | ||
| 47 | {&g_system_mem, &physical_system_mem, SYSTEM_MEMORY_VADDR, SYSTEM_MEMORY_SIZE, 0}, | ||
| 48 | {&g_dsp_mem, &physical_dsp_mem, DSP_MEMORY_VADDR, DSP_MEMORY_SIZE, 0}, | ||
| 49 | {&g_kernel_mem, &physical_kernel_mem, KERNEL_MEMORY_VADDR, KERNEL_MEMORY_SIZE, 0}, | ||
| 50 | {&g_heap_linear, &physical_heap_gsp, HEAP_LINEAR_VADDR, HEAP_LINEAR_SIZE, 0}, | ||
| 51 | }; | 28 | }; |
| 52 | 29 | ||
| 53 | /*static MemoryView views[] = | 30 | // We don't declare the IO regions in here since its handled by other means. |
| 54 | { | 31 | static MemoryArea memory_areas[] = { |
| 55 | {&m_pScratchPad, &m_pPhysicalScratchPad, 0x00010000, SCRATCHPAD_SIZE, 0}, | 32 | {&g_exefs_code, EXEFS_CODE_SIZE }, |
| 56 | {NULL, &m_pUncachedScratchPad, 0x40010000, SCRATCHPAD_SIZE, MV_MIRROR_PREVIOUS}, | 33 | {&g_vram, VRAM_SIZE }, |
| 57 | {&m_pVRAM, &m_pPhysicalVRAM, 0x04000000, 0x00800000, 0}, | 34 | {&g_heap, HEAP_SIZE }, |
| 58 | {NULL, &m_pUncachedVRAM, 0x44000000, 0x00800000, MV_MIRROR_PREVIOUS}, | 35 | {&g_shared_mem, SHARED_MEMORY_SIZE}, |
| 59 | {&m_pRAM, &m_pPhysicalRAM, 0x08000000, g_MemorySize, MV_IS_PRIMARY_RAM}, // only from 0x08800000 is it usable (last 24 megs) | 36 | {&g_system_mem, SYSTEM_MEMORY_SIZE}, |
| 60 | {NULL, &m_pUncachedRAM, 0x48000000, g_MemorySize, MV_MIRROR_PREVIOUS | MV_IS_PRIMARY_RAM}, | 37 | {&g_dsp_mem, DSP_MEMORY_SIZE }, |
| 61 | {NULL, &m_pKernelRAM, 0x88000000, g_MemorySize, MV_MIRROR_PREVIOUS | MV_IS_PRIMARY_RAM}, | 38 | {&g_kernel_mem, KERNEL_MEMORY_SIZE}, |
| 62 | 39 | {&g_heap_linear, HEAP_LINEAR_SIZE }, | |
| 63 | // TODO: There are a few swizzled mirrors of VRAM, not sure about the best way to | 40 | }; |
| 64 | // implement those. | ||
| 65 | };*/ | ||
| 66 | 41 | ||
| 67 | static const int kNumMemViews = sizeof(g_views) / sizeof(MemoryView); ///< Number of mem views | 42 | } |
| 68 | 43 | ||
| 69 | void Init() { | 44 | void Init() { |
| 70 | int flags = 0; | 45 | for (MemoryArea& area : memory_areas) { |
| 71 | 46 | *area.ptr = new u8[area.size]; | |
| 72 | for (size_t i = 0; i < ARRAY_SIZE(g_views); i++) { | ||
| 73 | if (g_views[i].flags & MV_IS_PRIMARY_RAM) | ||
| 74 | g_views[i].size = FCRAM_SIZE; | ||
| 75 | } | 47 | } |
| 76 | |||
| 77 | g_base = MemoryMap_Setup(g_views, kNumMemViews, flags, &arena); | ||
| 78 | MemBlock_Init(); | 48 | MemBlock_Init(); |
| 79 | 49 | ||
| 80 | LOG_DEBUG(HW_Memory, "initialized OK, RAM at %p (mirror at 0 @ %p)", g_heap, | 50 | LOG_DEBUG(HW_Memory, "initialized OK, RAM at %p", g_heap); |
| 81 | physical_fcram); | ||
| 82 | } | 51 | } |
| 83 | 52 | ||
| 84 | void Shutdown() { | 53 | void Shutdown() { |
| 85 | u32 flags = 0; | ||
| 86 | MemoryMap_Shutdown(g_views, kNumMemViews, flags, &arena); | ||
| 87 | arena.ReleaseSpace(); | ||
| 88 | MemBlock_Shutdown(); | 54 | MemBlock_Shutdown(); |
| 89 | 55 | for (MemoryArea& area : memory_areas) { | |
| 90 | g_base = nullptr; | 56 | delete[] *area.ptr; |
| 91 | g_exefs_code = nullptr; | 57 | *area.ptr = nullptr; |
| 92 | g_system_mem = nullptr; | 58 | } |
| 93 | g_heap = nullptr; | ||
| 94 | g_heap_linear = nullptr; | ||
| 95 | g_vram = nullptr; | ||
| 96 | g_shared_mem = nullptr; | ||
| 97 | g_dsp_mem = nullptr; | ||
| 98 | g_kernel_mem = nullptr; | ||
| 99 | |||
| 100 | physical_bootrom = nullptr; | ||
| 101 | uncached_bootrom = nullptr; | ||
| 102 | physical_exefs_code = nullptr; | ||
| 103 | physical_system_mem = nullptr; | ||
| 104 | physical_fcram = nullptr; | ||
| 105 | physical_heap_gsp = nullptr; | ||
| 106 | physical_vram = nullptr; | ||
| 107 | physical_shared_mem = nullptr; | ||
| 108 | physical_dsp_mem = nullptr; | ||
| 109 | physical_kernel_mem = nullptr; | ||
| 110 | 59 | ||
| 111 | LOG_DEBUG(HW_Memory, "shutdown OK"); | 60 | LOG_DEBUG(HW_Memory, "shutdown OK"); |
| 112 | } | 61 | } |