From c49941df7c045a6dd97d246a68f14d0562578fab Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 28 Mar 2019 10:34:18 +0100 Subject: [PATCH] Correction of the mapping that sucked --- boot/loader/mem/management.inc | 18 +++++++++--------- boot/loader/mem/structures.inc | 2 +- kaleid/kernel/init/init.c | 23 ++++++++++++++++++++++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/boot/loader/mem/management.inc b/boot/loader/mem/management.inc index 8e4676d..43ab13e 100644 --- a/boot/loader/mem/management.inc +++ b/boot/loader/mem/management.inc @@ -36,18 +36,20 @@ Setup_paging: or eax, 1 << 1 | 1 << 0 ; present + writable mov [PML4_table], eax - ;; Map the first PDP entries to PD table - mov ecx, 0x0 - mov eax, PD_table + ;; Map the PDP entries to PD tables + mov ebx, PD_table ; start address + mov ecx, 0x0 ; counter variable .map_pdp_table: + mov eax, ebx or eax, 1 << 1 | 1 << 0 ; present + writable - mov [PDP_table + ecx * 8], eax - add eax, 8 + mov [PDP_table + 8 * ecx], eax inc ecx - cmp ecx, MAX_MEMORY - jne .map_pdp_table + add ebx, 4096 + cmp ecx, MAX_MEMORY ; PDP table is mapped if MAX_MEMORY + jne .map_pdp_table ; else map the next entry ;; Map each PD entry to a 'huge' 2MiB page + mov ecx, 0x0 ; counter variable .map_pd_table: ;; map ecx-th PD entry to a huge page that starts at address 2MiB*ecx @@ -59,8 +61,6 @@ Setup_paging: cmp ecx, 512 * MAX_MEMORY ; PD table is mapped if 512 jne .map_pd_table ; else map the next entry - ret - ; ---------------------------------------------------------------------------- ; ; Enable long mode and paging ; ; ---------------------------------------------------------------------------- ; diff --git a/boot/loader/mem/structures.inc b/boot/loader/mem/structures.inc index baeca97..b5ba719 100644 --- a/boot/loader/mem/structures.inc +++ b/boot/loader/mem/structures.inc @@ -59,4 +59,4 @@ PML4_table: PDP_table: resb 4096 PD_table: - resb 4096 * MAX_MEMORY + times MAX_MEMORY resb 4096 diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 88fd242..0aae959 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -150,10 +150,31 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, int mbMagic) //if(rc)KernLog("error\n"); //KernLog((char*)buf->buf); - uchar *addr = (uchar *)(ullong)(1024*5*MB - 7); + uchar *addr = (uchar *)(ullong)(10); + *addr = 2; + addr = (uchar *)(ullong)(1*GB+10); + *addr = 4; + + addr = (uchar *)(ullong)(2*GB+10); + *addr = 9; + + addr = (uchar *)(ullong)(4*GB + 10); + *addr = 16; + + addr = (uchar *)(ullong)(10); KernLog("Test, valeur autour de %p: %hhu\n", addr, *addr); + addr = (uchar *)(ullong)(1*GB+10); + KernLog("Test, valeur autour de %p: %hhu\n", addr, *addr); + + addr = (uchar *)(ullong)(2*GB+10); + KernLog("Test, valeur autour de %p: %hhu\n", addr, *addr); + + addr = (uchar *)(ullong)(4*GB + 10); + KernLog("Test, valeur autour de %p: %hhu\n", addr, *addr); + + // We're out PsFiniSched(); KeCrashSystem(); //yay