From 470eb5e9f971da21d322d2ae9c5586f9f0f345e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Thu, 4 Jan 2018 00:39:50 +0100 Subject: [PATCH] Also map non-free memory areas into kernel space --- src/kernel/boot/kmain.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/kernel/boot/kmain.c b/src/kernel/boot/kmain.c index b2e01fd..4cd2a38 100644 --- a/src/kernel/boot/kmain.c +++ b/src/kernel/boot/kmain.c @@ -23,19 +23,18 @@ void kmain(uint64_t multiboot_magic, void *multiboot_data) uint32_t type, i=0; while(!multiboot_get_memory_area(i++, &start, &end, &type)) { - if(type != 1) - continue; - debug_printf("Mem %d 0x%x-0x%x\n", type, start, end); + debug("Mem %d 0x%x-0x%x\n", type, start, end); for(uintptr_t p = start; p < end; p += PAGE_SIZE) { if(p >= V2P(&kernel_start) && p < V2P(&kernel_end)) continue; - if(!(p & 0x1FFFFF)) + if(vmm_get_page(&BootP4, (uintptr_t)P2V(p)) == (uintptr_t)-1) { - touch_page(&BootP4, (uintptr_t)P2V(p), PAGE_HUGE); + touch_page(&BootP4, (uintptr_t)P2V(p), PAGE_WRITE | PAGE_HUGE); vmm_set_page(&BootP4, (uintptr_t)P2V(p), p, PAGE_HUGE | PAGE_WRITE | PAGE_PRESENT); } - pmm_free(p); + if(type == 1) + pmm_free(p); } }