mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2025-06-10 14:48:17 -05:00
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.
This commit is contained in:
@ -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];
|
||||
|
Reference in New Issue
Block a user