1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00

New dynamic paging implementation (3) #67

This commit is contained in:
Adrien Bourmault 2020-01-09 22:17:44 +01:00
parent 1073397b15
commit ad5b70b08a
3 changed files with 28 additions and 11 deletions

View File

@ -185,7 +185,7 @@ void MmUnSetPage(void* virtualAddr, ulong flags);
// //
// Map a page // Map a page
// //
void MmMapPage(void* virtualAddr, void* physicalAddr, ulong flags) void MmMapPage(void* virtualAddr, void* physicalAddr, ulong flags);
void MmUnmapPage(void* virtualAddr); void MmUnmapPage(void* virtualAddr);
// Page table entry // Page table entry

View File

@ -54,12 +54,12 @@ void MmInitPaging(void)
ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize; ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize;
// Difference between the end of kernel and the begin of userspace // 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 // Maximum VIRTUAL address in memory
MmVirtLastAddress = phRamSize + diffKernUsr; 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)); memzero((void *)&MmPageMapLevel4[0], sizeof(MmPageMapLevel4));
@ -149,15 +149,15 @@ void MmInitPaging(void)
MmPT[index] = (ulong)curAddrPT | PRESENT | READWRITE; MmPT[index] = (ulong)curAddrPT | PRESENT | READWRITE;
if ((ulong)curAddrPT == lastKernelAddr) { 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 // While we're inside the userspace pages
else if ((ulong)curAddrPT >= USERSPACE) { 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) { if ((ulong)curAddrPT == USERSPACE) {
DebugLog("\tUserspace at %p:%p\n", curAddrPT, curAddrPT + diffKernUsr); DebugLog("\tUserspace at %p:%p\n", curAddrPT, curAddrPT - diffKernUsr);
} }
} }
else { else {
@ -189,14 +189,14 @@ void *MmTransVirtToPhyAddr(void* virtualAddr)
} }
pdpe_t *pdp = (pdpe_t*)((ulong)MmPageMapLevel4[(virtAddrPage / ((ulong)KPAGESIZE * 0x8000000)) % 512] & ~(KPAGESIZE - 1)); 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)); 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)); 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]; 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))) { if (page == (page & ~(KPAGESIZE - 1))) {
return NULL; return NULL;
@ -311,7 +311,7 @@ static void PagingHandler(ISRFrame_t *regs)
); );
} else { } else {
//XXX page fault //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)", " Error code : 0x%x (%b)",
VGA_COLOR_LIGHT_RED, 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); KeBrkDumpRegisters(regs);
BStdOut->flusher(BStdOut); BStdOut->flusher(BStdOut);

Binary file not shown.