diff options
| author | 2015-05-29 18:00:17 -0700 | |
|---|---|---|
| committer | 2015-05-29 18:00:17 -0700 | |
| commit | 8a04c65e20ba1f5c472c026b7a558e1d54324306 (patch) | |
| tree | c11c0c6a472184f25479b0679748ee71653a2985 /src/core/mem_map.cpp | |
| parent | Merge pull request #818 from linkmauve/no-trailing-whitespace (diff) | |
| parent | Memmap: Remove unused global pointers to memory areas (diff) | |
| download | yuzu-8a04c65e20ba1f5c472c026b7a558e1d54324306.tar.gz yuzu-8a04c65e20ba1f5c472c026b7a558e1d54324306.tar.xz yuzu-8a04c65e20ba1f5c472c026b7a558e1d54324306.zip | |
Merge pull request #810 from yuriks/memmap
Kernel: Add VMManager to manage process address spaces
Diffstat (limited to 'src/core/mem_map.cpp')
| -rw-r--r-- | src/core/mem_map.cpp | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp index 5ecec9566..bf814b945 100644 --- a/src/core/mem_map.cpp +++ b/src/core/mem_map.cpp | |||
| @@ -8,6 +8,10 @@ | |||
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | 9 | ||
| 10 | #include "core/hle/config_mem.h" | 10 | #include "core/hle/config_mem.h" |
| 11 | #include "core/hle/kernel/kernel.h" | ||
| 12 | #include "core/hle/kernel/shared_memory.h" | ||
| 13 | #include "core/hle/kernel/vm_manager.h" | ||
| 14 | #include "core/hle/result.h" | ||
| 11 | #include "core/hle/shared_page.h" | 15 | #include "core/hle/shared_page.h" |
| 12 | #include "core/mem_map.h" | 16 | #include "core/mem_map.h" |
| 13 | #include "core/memory.h" | 17 | #include "core/memory.h" |
| @@ -17,31 +21,23 @@ | |||
| 17 | 21 | ||
| 18 | namespace Memory { | 22 | namespace Memory { |
| 19 | 23 | ||
| 20 | u8* g_exefs_code; ///< ExeFS:/.code is loaded here | ||
| 21 | u8* g_heap; ///< Application heap (main memory) | ||
| 22 | u8* g_shared_mem; ///< Shared memory | ||
| 23 | u8* g_heap_linear; ///< Linear heap | ||
| 24 | u8* g_vram; ///< Video memory (VRAM) pointer | ||
| 25 | u8* g_dsp_mem; ///< DSP memory | ||
| 26 | u8* g_tls_mem; ///< TLS memory | ||
| 27 | |||
| 28 | namespace { | 24 | namespace { |
| 29 | 25 | ||
| 30 | struct MemoryArea { | 26 | struct MemoryArea { |
| 31 | u8** ptr; | ||
| 32 | u32 base; | 27 | u32 base; |
| 33 | u32 size; | 28 | u32 size; |
| 29 | const char* name; | ||
| 34 | }; | 30 | }; |
| 35 | 31 | ||
| 36 | // We don't declare the IO regions in here since its handled by other means. | 32 | // We don't declare the IO regions in here since its handled by other means. |
| 37 | static MemoryArea memory_areas[] = { | 33 | static MemoryArea memory_areas[] = { |
| 38 | {&g_exefs_code, PROCESS_IMAGE_VADDR, PROCESS_IMAGE_MAX_SIZE}, | 34 | {PROCESS_IMAGE_VADDR, PROCESS_IMAGE_MAX_SIZE, "Process Image"}, // ExeFS:/.code is loaded here |
| 39 | {&g_heap, HEAP_VADDR, HEAP_SIZE }, | 35 | {HEAP_VADDR, HEAP_SIZE, "Heap"}, // Application heap (main memory) |
| 40 | {&g_shared_mem, SHARED_MEMORY_VADDR, SHARED_MEMORY_SIZE }, | 36 | {SHARED_MEMORY_VADDR, SHARED_MEMORY_SIZE, "Shared Memory"}, // Shared memory |
| 41 | {&g_heap_linear, LINEAR_HEAP_VADDR, LINEAR_HEAP_SIZE }, | 37 | {LINEAR_HEAP_VADDR, LINEAR_HEAP_SIZE, "Linear Heap"}, // Linear heap (main memory) |
| 42 | {&g_vram, VRAM_VADDR, VRAM_SIZE }, | 38 | {VRAM_VADDR, VRAM_SIZE, "VRAM"}, // Video memory (VRAM) |
| 43 | {&g_dsp_mem, DSP_RAM_VADDR, DSP_RAM_SIZE }, | 39 | {DSP_RAM_VADDR, DSP_RAM_SIZE, "DSP RAM"}, // DSP memory |
| 44 | {&g_tls_mem, TLS_AREA_VADDR, TLS_AREA_SIZE }, | 40 | {TLS_AREA_VADDR, TLS_AREA_SIZE, "TLS Area"}, // TLS memory |
| 45 | }; | 41 | }; |
| 46 | 42 | ||
| 47 | /// Represents a block of memory mapped by ControlMemory/MapMemoryBlock | 43 | /// Represents a block of memory mapped by ControlMemory/MapMemoryBlock |
| @@ -135,27 +131,34 @@ VAddr PhysicalToVirtualAddress(const PAddr addr) { | |||
| 135 | return addr | 0x80000000; | 131 | return addr | 0x80000000; |
| 136 | } | 132 | } |
| 137 | 133 | ||
| 134 | // TODO(yuriks): Move this into Process | ||
| 135 | static Kernel::VMManager address_space; | ||
| 136 | |||
| 138 | void Init() { | 137 | void Init() { |
| 138 | using namespace Kernel; | ||
| 139 | |||
| 139 | InitMemoryMap(); | 140 | InitMemoryMap(); |
| 140 | 141 | ||
| 141 | for (MemoryArea& area : memory_areas) { | 142 | for (MemoryArea& area : memory_areas) { |
| 142 | *area.ptr = new u8[area.size]; | 143 | auto block = std::make_shared<std::vector<u8>>(area.size); |
| 143 | MapMemoryRegion(area.base, area.size, *area.ptr); | 144 | address_space.MapMemoryBlock(area.base, std::move(block), 0, area.size, MemoryState::Private).Unwrap(); |
| 144 | } | 145 | } |
| 145 | MapMemoryRegion(CONFIG_MEMORY_VADDR, CONFIG_MEMORY_SIZE, (u8*)&ConfigMem::config_mem); | ||
| 146 | MapMemoryRegion(SHARED_PAGE_VADDR, SHARED_PAGE_SIZE, (u8*)&SharedPage::shared_page); | ||
| 147 | 146 | ||
| 148 | LOG_DEBUG(HW_Memory, "initialized OK, RAM at %p", g_heap); | 147 | auto cfg_mem_vma = address_space.MapBackingMemory(CONFIG_MEMORY_VADDR, |
| 148 | (u8*)&ConfigMem::config_mem, CONFIG_MEMORY_SIZE, MemoryState::Shared).MoveFrom(); | ||
| 149 | address_space.Reprotect(cfg_mem_vma, VMAPermission::Read); | ||
| 150 | |||
| 151 | auto shared_page_vma = address_space.MapBackingMemory(SHARED_PAGE_VADDR, | ||
| 152 | (u8*)&SharedPage::shared_page, SHARED_PAGE_SIZE, MemoryState::Shared).MoveFrom(); | ||
| 153 | address_space.Reprotect(shared_page_vma, VMAPermission::Read); | ||
| 154 | |||
| 155 | LOG_DEBUG(HW_Memory, "initialized OK"); | ||
| 149 | } | 156 | } |
| 150 | 157 | ||
| 151 | void Shutdown() { | 158 | void Shutdown() { |
| 152 | heap_map.clear(); | 159 | heap_map.clear(); |
| 153 | heap_linear_map.clear(); | 160 | heap_linear_map.clear(); |
| 154 | 161 | address_space.Reset(); | |
| 155 | for (MemoryArea& area : memory_areas) { | ||
| 156 | delete[] *area.ptr; | ||
| 157 | *area.ptr = nullptr; | ||
| 158 | } | ||
| 159 | 162 | ||
| 160 | LOG_DEBUG(HW_Memory, "shutdown OK"); | 163 | LOG_DEBUG(HW_Memory, "shutdown OK"); |
| 161 | } | 164 | } |