diff options
author | Yuri Kunde Schlesner <yuriks@yuriks.net> | 2015-05-29 18:00:17 -0700 |
---|---|---|
committer | Yuri Kunde Schlesner <yuriks@yuriks.net> | 2015-05-29 18:00:17 -0700 |
commit | 8a04c65e20ba1f5c472c026b7a558e1d54324306 (patch) | |
tree | c11c0c6a472184f25479b0679748ee71653a2985 /src/core/memory.cpp | |
parent | a489a846563fc64f236c7ede69ce0eb34af3521a (diff) | |
parent | 88365a23e76fe3a4a64c9dc65aa8554e25a20af0 (diff) |
Merge pull request #810 from yuriks/memmap
Kernel: Add VMManager to manage process address spaces
Diffstat (limited to 'src/core/memory.cpp')
-rw-r--r-- | src/core/memory.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 5d8069acd..28844a915 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -14,12 +14,10 @@ #include "core/hw/hw.h" #include "core/mem_map.h" #include "core/memory.h" +#include "core/memory_setup.h" namespace Memory { -const u32 PAGE_MASK = PAGE_SIZE - 1; -const int PAGE_BITS = 12; - enum class PageType { /// Page is unmapped and should cause an access error. Unmapped, @@ -64,7 +62,7 @@ static void MapPages(u32 base, u32 size, u8* memory, PageType type) { while (base != end) { ASSERT_MSG(base < PageTable::NUM_ENTRIES, "out of range mapping at %08X", base); - if (current_page_table->attributes[base] != PageType::Unmapped) { + if (current_page_table->attributes[base] != PageType::Unmapped && type != PageType::Unmapped) { LOG_ERROR(HW_Memory, "overlapping memory ranges at %08X", base * PAGE_SIZE); } current_page_table->attributes[base] = type; @@ -92,6 +90,12 @@ void MapIoRegion(VAddr base, u32 size) { MapPages(base / PAGE_SIZE, size / PAGE_SIZE, nullptr, PageType::Special); } +void UnmapRegion(VAddr base, u32 size) { + ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: %08X", size); + ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: %08X", base); + MapPages(base / PAGE_SIZE, size / PAGE_SIZE, nullptr, PageType::Unmapped); +} + template <typename T> T Read(const VAddr vaddr) { const u8* page_pointer = current_page_table->pointers[vaddr >> PAGE_BITS]; |