From 2a1990e043434d721485191be3c8077f64a5b582 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 1 Mar 2021 16:57:48 +0100 Subject: [PATCH] Userspace code runs ! --- kaleid/kernel/mm/paging.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index 4ef2472..e34575a 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -113,7 +113,8 @@ void MmInitPaging(void) //DebugLog("\t\t\t\tPDP %d : %p\n", index, MmPDP); MmPageMapLevel4[index] = (pdpe_t *)((ulong)MmPDP | PRESENT - | READWRITE); + | READWRITE + | USERMODE ); for (curAddrPDP = curAddrPML4; curAddrPDP < (curAddrPML4 + ((ulong)KPAGESIZE * 0x8000000)); @@ -134,7 +135,8 @@ void MmInitPaging(void) index = (curAddrPDP / ((ulong)KPAGESIZE * 0x40000)) % 512; //DebugLog("\t\t\t\tPD %d : %p\n", index, MmPD); - MmPDP[index] = (pde_t *)((ulong)MmPD | PRESENT | READWRITE); + MmPDP[index] = (pde_t *)((ulong)MmPD | PRESENT + | READWRITE ); for (curAddrPD = curAddrPDP; curAddrPD < (curAddrPDP + ((ulong)KPAGESIZE * 0x40000)); @@ -155,7 +157,7 @@ void MmInitPaging(void) //DebugLog("\t\t\t\tPT %d : %p\n", index, MmPT); MmPD[index] = (pte_t *)((ulong)MmPT | PRESENT - | READWRITE); + | READWRITE ); for (curAddrPT = curAddrPD; curAddrPT < (curAddrPD + ((ulong)KPAGESIZE * 0x200)); @@ -252,7 +254,10 @@ ulong *MmGetPageDescriptorFromVirtual(void *virtualAddr) // Set present MmPageMapLevel4[pml4Index] = - (pml4_t)((ulong)MmPageMapLevel4[pml4Index] | PRESENT | READWRITE); + (pml4_t)((ulong)MmPageMapLevel4[pml4Index] + | PRESENT + | READWRITE + | USERMODE * (virtualAddr >= USERSPACE) ); pdp = (pdpe_t *)((ulong)MmPageMapLevel4[pml4Index] & 0xFFFFFFFFFF000); //DebugLog("\tCreate PDP at %p\n", MmPageMapLevel4[pml4Index]); @@ -268,7 +273,10 @@ ulong *MmGetPageDescriptorFromVirtual(void *virtualAddr) pdp[pdpIndex] = memalign(512*sizeof(pde_t), KPAGESIZE); - pdp[pdpIndex] = (pdpe_t)((ulong)pdp[pdpIndex] | PRESENT | READWRITE); + pdp[pdpIndex] = (pdpe_t)((ulong)pdp[pdpIndex] + | PRESENT + | READWRITE + | USERMODE * (virtualAddr >= USERSPACE) ); pd = (pde_t *)((ulong)pdp[pdpIndex] & 0xFFFFFFFFFF000); //DebugLog("\tCreate PD at %p\n", (ulong)pdp[pdpIndex]); @@ -284,7 +292,10 @@ ulong *MmGetPageDescriptorFromVirtual(void *virtualAddr) pd[pdIndex] = memalign(512*sizeof(pte_t), KPAGESIZE); - pd[pdIndex] = (pde_t)((ulong)pd[pdIndex] | PRESENT | READWRITE); + pd[pdIndex] = (pde_t)((ulong)pd[pdIndex] + | PRESENT + | READWRITE + | USERMODE * (virtualAddr >= USERSPACE) ); pt = (pte_t *)((ulong)pd[pdIndex] & 0xFFFFFFFFFF000); //DebugLog("\tCreate PT at %p\n", (ulong)pd[pdIndex]);