From ad5b70b08abafb615e905ac445de343ff4c36857 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 9 Jan 2020 22:17:44 +0100 Subject: [PATCH] New dynamic paging implementation (3) #67 --- include/mm/mm.h | 2 +- kaleid/kernel/mm/paging.c | 37 ++++++++++++++++++++++++++---------- kaleid/kernel/sh/testcmds.c | Bin 8685 -> 8755 bytes 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/include/mm/mm.h b/include/mm/mm.h index a1a6c45..50657f1 100644 --- a/include/mm/mm.h +++ b/include/mm/mm.h @@ -185,7 +185,7 @@ void MmUnSetPage(void* virtualAddr, ulong flags); // // Map a page // -void MmMapPage(void* virtualAddr, void* physicalAddr, ulong flags) +void MmMapPage(void* virtualAddr, void* physicalAddr, ulong flags); void MmUnmapPage(void* virtualAddr); // Page table entry diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index 87bc78f..d3265e5 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -54,12 +54,12 @@ void MmInitPaging(void) ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize; // Difference between the end of kernel and the begin of userspace - ulong diffKernUsr = (ulong)USERSPACE - lastKernelAddr; + ulong diffKernUsr = (ulong)USERSPACE - lastKernelAddr - KPAGESIZE; // Maximum VIRTUAL address in memory MmVirtLastAddress = phRamSize + diffKernUsr; - DebugLog("\tPaging gap : %u MB (%p)\n\tLast virtual address %p\n", diffKernUsr / MB, diffKernUsr, MmVirtLastAddress); + //DebugLog("\tPaging gap : %u MB (%p)\n\tLast virtual address %p\n", diffKernUsr / MB, diffKernUsr, MmVirtLastAddress); memzero((void *)&MmPageMapLevel4[0], sizeof(MmPageMapLevel4)); @@ -149,15 +149,15 @@ void MmInitPaging(void) MmPT[index] = (ulong)curAddrPT | PRESENT | READWRITE; if ((ulong)curAddrPT == lastKernelAddr) { - DebugLog("\tLast page of kernel at %p\n", curAddrPT); + //DebugLog("\tLast page of kernel at %p\n", curAddrPT); } } // While we're inside the userspace pages else if ((ulong)curAddrPT >= USERSPACE) { - MmPT[index] = ((ulong)curAddrPT); // Not present for instance + MmPT[index] = ((ulong)curAddrPT - diffKernUsr) | PRESENT; // Not present for instance if ((ulong)curAddrPT == USERSPACE) { - DebugLog("\tUserspace at %p:%p\n", curAddrPT, curAddrPT + diffKernUsr); + DebugLog("\tUserspace at %p:%p\n", curAddrPT, curAddrPT - diffKernUsr); } } else { @@ -189,14 +189,14 @@ void *MmTransVirtToPhyAddr(void* virtualAddr) } pdpe_t *pdp = (pdpe_t*)((ulong)MmPageMapLevel4[(virtAddrPage / ((ulong)KPAGESIZE * 0x8000000)) % 512] & ~(KPAGESIZE - 1)); - DebugLog("pdp : %p\n", pdp); + DebugLog("pdp\t: %p\n", pdp); pde_t *pd = (pde_t*)( (ulong)pdp[(virtAddrPage / ((ulong)KPAGESIZE * 0x40000)) % 512] & ~(KPAGESIZE - 1)); - DebugLog("pd : %p\n", pd); + DebugLog("pd\t: %p\n", pd); pte_t *pt = (pte_t*)( (ulong)pd[(virtAddrPage / ((ulong)KPAGESIZE * 0x200)) % 512] & ~(KPAGESIZE - 1)); - DebugLog("pt : %p\n", pt); + DebugLog("pt\t: %p\n", pt); ulong page = (ulong)pt[(virtAddrPage / ((ulong)KPAGESIZE)) % 512]; - DebugLog("page : %p\n", page); + DebugLog("page (with flags): %p\n", page); if (page == (page & ~(KPAGESIZE - 1))) { return NULL; @@ -311,7 +311,7 @@ static void PagingHandler(ISRFrame_t *regs) ); } else { //XXX page fault - bprintf(BStdOut, "\n\n%CPANIC\n[ISR 0x8] Irrecoverable Kernel Page Fault at %p\n\n" + bprintf(BStdOut, "\n\n%CPANIC\n[ISR 0x8] Irrecoverable Page Fault at %p\n\n" " Error code : 0x%x (%b)", VGA_COLOR_LIGHT_RED, @@ -321,6 +321,23 @@ static void PagingHandler(ISRFrame_t *regs) ); } + bprintf(BStdOut, "\n Description : "); + + if (regs->ErrorCode & PRESENT) { + bprintf(BStdOut, "Page-protection violation "); + } else { + bprintf(BStdOut, "Non present page "); + } + if (regs->ErrorCode & READWRITE) { + bprintf(BStdOut, "during write access "); + } else { + bprintf(BStdOut, "during read access "); + } + if (regs->ErrorCode & (1 << 3)) + bprintf(BStdOut, "from userspace "); + if (regs->ErrorCode & (1 << 4)) + bprintf(BStdOut, "after instruction fetching "); + KeBrkDumpRegisters(regs); BStdOut->flusher(BStdOut); diff --git a/kaleid/kernel/sh/testcmds.c b/kaleid/kernel/sh/testcmds.c index 411e17e89c8edf802d203212df03d72145a16eb0..025bdcc8497bce31ebf6caeb4228a8d685baab2c 100644 GIT binary patch delta 99 zcmaFsyxC=gA*%ob8rbZ}S|~VqH9x0`U%o`^YF>$gl|o5TVqS4hVo7FRx+(t delta 51 zcmdn&^458SA*(=1Mt*6DLTXuRo