From a8035052a9ee3f8541cee5e7b8865a3aa43006f7 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 20 Jan 2020 19:09:42 +0100 Subject: [PATCH] [Bug] Problem with mapping --- kaleid/kernel/mm/paging.c | 29 +++++++++++++++++++++++------ kaleid/kernel/mm/palloc.c | 2 +- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index b70f146..16d574d 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -230,34 +230,51 @@ ulong *MmGetPageDescriptorFromVirtual(void *virtualAddr) DebugLog("PML4[%d], PDP[%d], PD[%d], PT[%d]\n", pml4Index, pdpIndex, pdIndex, ptIndex); if (!((ulong)MmPageMapLevel4[pml4Index] & 0xFFFFFFFFFF000)) { // Select bit from 12 to 51 + + // Alloc space KalAllocMemoryEx((void**)&MmPageMapLevel4[pml4Index], 512*sizeof(pdpe_t), M_ZEROED, KPAGESIZE); + + // Set present + MmPageMapLevel4[pml4Index] = (pml4_t)((ulong)MmPageMapLevel4[pml4Index] | PRESENT | READWRITE); + pdp = (pdpe_t *)((ulong)MmPageMapLevel4[pml4Index] & 0xFFFFFFFFFF000); - DebugLog("Create PDP\n"); + DebugLog("\tCreate PDP at %p\n", MmPageMapLevel4[pml4Index]); + } else { pdp = (pdpe_t *)((ulong)MmPageMapLevel4[pml4Index] & 0xFFFFFFFFFF000); } - DebugLog("PDP at %p = %p\n", &pdp[0], pdp[pdpIndex]); + DebugLog("\tPDP[%d] = %p\n", pdpIndex, pdp[pdpIndex]); if (!((ulong)pdp[pdpIndex] & 0xFFFFFFFFFF000)) { // Select bit from 12 to 51 + KalAllocMemoryEx((void**)&pdp[pdpIndex], 512*sizeof(pde_t), M_ZEROED, KPAGESIZE); + + pdp[pdpIndex] = (pdpe_t)((ulong)pdp[pdpIndex] | PRESENT | READWRITE); + pd = (pde_t *)((ulong)pdp[pdpIndex] & 0xFFFFFFFFFF000); - DebugLog("Create PD\n"); + DebugLog("\tCreate PD at %p\n", (ulong)pdp[pdpIndex]); + } else { pd = (pde_t *)((ulong)pdp[pdpIndex] & 0xFFFFFFFFFF000); } - DebugLog("PD at %p = %p\n", &pd[0], pd[pdIndex]); + DebugLog("\tPD[%d] = %p\n", pdIndex, pd[pdIndex]); if (!((ulong)pd[pdIndex] & 0xFFFFFFFFFF000)) { // Select bit from 12 to 51 + // KalAllocMemoryEx((void**)&pd[pdIndex], 512*sizeof(pte_t), M_ZEROED, KPAGESIZE); + + pd[pdIndex] = (pde_t)((ulong)pd[pdIndex] | PRESENT | READWRITE); + pt = (pte_t *)((ulong)pd[pdIndex] & 0xFFFFFFFFFF000); - DebugLog("Create PT\n"); + DebugLog("\tCreate PT at %p\n", (ulong)pd[pdIndex]); + } else { pt = (pte_t *)((ulong)pd[pdIndex] & 0xFFFFFFFFFF000); } - DebugLog("PT at %p = %p\n", &pt[0], pt[ptIndex]); + DebugLog("\tPT[%d] = %p\n", ptIndex, pt[ptIndex]); MmLoadPML4((void *)MmPageMapLevel4); diff --git a/kaleid/kernel/mm/palloc.c b/kaleid/kernel/mm/palloc.c index bb80886..03e79be 100644 --- a/kaleid/kernel/mm/palloc.c +++ b/kaleid/kernel/mm/palloc.c @@ -297,7 +297,7 @@ error_t MmTestBusyPage(void) ulong a = KeGetTicks(); DebugLog("Start alloc 30 MB: %lu s\n", a/1000); tab[j++] = MmAllocPageFrame(5*MB, NORMAL); - tab[j++] = MmAllocPageFrame(8*KB, NORMAL); + tab[j++] = MmAllocPageFrame(513*4*KB, NORMAL); ulong b = KeGetTicks(); DebugLog("End alloc : %lu s\n", b/1000); DebugLog("Alloc time : %lu s\n", (b-a)/1000);