summaryrefslogtreecommitdiff
path: root/src/core/mem_map.cpp
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2015-05-21 00:37:07 -0300
committerGravatar Yuri Kunde Schlesner2015-05-27 03:24:12 -0300
commit0a60aa75c2b03b8ed6752e5c64462bf86c52fcfc (patch)
tree3113ce6d149d7adf9ab5c1eb189102869760e55a /src/core/mem_map.cpp
parentMerge pull request #826 from lioncash/tables (diff)
downloadyuzu-0a60aa75c2b03b8ed6752e5c64462bf86c52fcfc.tar.gz
yuzu-0a60aa75c2b03b8ed6752e5c64462bf86c52fcfc.tar.xz
yuzu-0a60aa75c2b03b8ed6752e5c64462bf86c52fcfc.zip
Kernel: Add VMManager to manage process address spaces
This enables more dynamic management of the process address space, compared to just directly configuring the page table for major areas. This will serve as the foundation upon which the rest of the Kernel memory management functions will be built.
Diffstat (limited to 'src/core/mem_map.cpp')
-rw-r--r--src/core/mem_map.cpp42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp
index 5ecec9566..66d95ed27 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"
@@ -31,17 +35,18 @@ struct MemoryArea {
31 u8** ptr; 35 u8** ptr;
32 u32 base; 36 u32 base;
33 u32 size; 37 u32 size;
38 const char* name;
34}; 39};
35 40
36// We don't declare the IO regions in here since its handled by other means. 41// We don't declare the IO regions in here since its handled by other means.
37static MemoryArea memory_areas[] = { 42static MemoryArea memory_areas[] = {
38 {&g_exefs_code, PROCESS_IMAGE_VADDR, PROCESS_IMAGE_MAX_SIZE}, 43 {&g_exefs_code, PROCESS_IMAGE_VADDR, PROCESS_IMAGE_MAX_SIZE, "Process Image"},
39 {&g_heap, HEAP_VADDR, HEAP_SIZE }, 44 {&g_heap, HEAP_VADDR, HEAP_SIZE, "Heap"},
40 {&g_shared_mem, SHARED_MEMORY_VADDR, SHARED_MEMORY_SIZE }, 45 {&g_shared_mem, SHARED_MEMORY_VADDR, SHARED_MEMORY_SIZE, "Shared Memory"},
41 {&g_heap_linear, LINEAR_HEAP_VADDR, LINEAR_HEAP_SIZE }, 46 {&g_heap_linear, LINEAR_HEAP_VADDR, LINEAR_HEAP_SIZE, "Linear Heap"},
42 {&g_vram, VRAM_VADDR, VRAM_SIZE }, 47 {&g_vram, VRAM_VADDR, VRAM_SIZE, "VRAM"},
43 {&g_dsp_mem, DSP_RAM_VADDR, DSP_RAM_SIZE }, 48 {&g_dsp_mem, DSP_RAM_VADDR, DSP_RAM_SIZE, "DSP RAM"},
44 {&g_tls_mem, TLS_AREA_VADDR, TLS_AREA_SIZE }, 49 {&g_tls_mem, TLS_AREA_VADDR, TLS_AREA_SIZE, "TLS Area"},
45}; 50};
46 51
47/// Represents a block of memory mapped by ControlMemory/MapMemoryBlock 52/// Represents a block of memory mapped by ControlMemory/MapMemoryBlock
@@ -135,15 +140,27 @@ VAddr PhysicalToVirtualAddress(const PAddr addr) {
135 return addr | 0x80000000; 140 return addr | 0x80000000;
136} 141}
137 142
143// TODO(yuriks): Move this into Process
144static Kernel::VMManager address_space;
145
138void Init() { 146void Init() {
147 using namespace Kernel;
148
139 InitMemoryMap(); 149 InitMemoryMap();
140 150
141 for (MemoryArea& area : memory_areas) { 151 for (MemoryArea& area : memory_areas) {
142 *area.ptr = new u8[area.size]; 152 auto block = std::make_shared<std::vector<u8>>(area.size);
143 MapMemoryRegion(area.base, area.size, *area.ptr); 153 *area.ptr = block->data(); // TODO(yuriks): Remove
154 address_space.MapMemoryBlock(area.base, std::move(block), 0, area.size, MemoryState::Private).Unwrap();
144 } 155 }
145 MapMemoryRegion(CONFIG_MEMORY_VADDR, CONFIG_MEMORY_SIZE, (u8*)&ConfigMem::config_mem); 156
146 MapMemoryRegion(SHARED_PAGE_VADDR, SHARED_PAGE_SIZE, (u8*)&SharedPage::shared_page); 157 auto cfg_mem_vma = address_space.MapBackingMemory(CONFIG_MEMORY_VADDR,
158 (u8*)&ConfigMem::config_mem, CONFIG_MEMORY_SIZE, MemoryState::Shared).MoveFrom();
159 address_space.Reprotect(cfg_mem_vma, VMAPermission::Read);
160
161 auto shared_page_vma = address_space.MapBackingMemory(SHARED_PAGE_VADDR,
162 (u8*)&SharedPage::shared_page, SHARED_PAGE_SIZE, MemoryState::Shared).MoveFrom();
163 address_space.Reprotect(shared_page_vma, VMAPermission::Read);
147 164
148 LOG_DEBUG(HW_Memory, "initialized OK, RAM at %p", g_heap); 165 LOG_DEBUG(HW_Memory, "initialized OK, RAM at %p", g_heap);
149} 166}
@@ -152,8 +169,9 @@ void Shutdown() {
152 heap_map.clear(); 169 heap_map.clear();
153 heap_linear_map.clear(); 170 heap_linear_map.clear();
154 171
172 address_space.Reset();
173
155 for (MemoryArea& area : memory_areas) { 174 for (MemoryArea& area : memory_areas) {
156 delete[] *area.ptr;
157 *area.ptr = nullptr; 175 *area.ptr = nullptr;
158 } 176 }
159 177