private void SetPageEntry(uint *pageTablePtr, uint entry, uint addr, PTEFlags flags) { #if PAGING_TRACE BasicConsole.WriteLine("Setting page entry..."); BasicConsole.WriteLine(((FOS_System.String) "pageTablePtr=") + (uint)pageTablePtr); BasicConsole.WriteLine(((FOS_System.String) "entry=") + entry); BasicConsole.WriteLine(((FOS_System.String) "addr=") + addr); #endif pageTablePtr[entry] = addr | (uint)flags; #if PAGING_TRACE if (pageTablePtr[entry] != (addr | 3)) { BasicConsole.WriteLine("Set page entry verification failed."); } #endif }
public override void Map(uint pAddr, uint vAddr, PageFlags flags, UpdateUsedPagesFlags UpdateUsedPages = UpdateUsedPagesFlags.Both) { PTEFlags pteFlags = PTEFlags.None; if ((flags & PageFlags.Present) != 0) { pteFlags |= PTEFlags.Present; } if ((flags & PageFlags.KernelOnly) == 0) { pteFlags |= PTEFlags.UserAllowed; } if ((flags & PageFlags.Writeable) != 0) { pteFlags |= PTEFlags.Writeable; } Map(pAddr, vAddr, pteFlags, UpdateUsedPages); }
private void Map(uint pAddr, uint vAddr, PTEFlags flags, UpdateUsedPagesFlags UpdateUsedPages = UpdateUsedPagesFlags.Both) { #if PAGING_TRACE BasicConsole.WriteLine("Mapping addresses..."); #endif //Calculate page directory and page table indices uint virtPDIdx = vAddr >> 22; uint virtPTIdx = (vAddr >> 12) & 0x03FF; uint physPDIdx = pAddr >> 22; uint physPTIdx = (pAddr >> 12) & 0x03FF; #if PAGING_TRACE BasicConsole.WriteLine(((FOS_System.String) "pAddr=") + pAddr); BasicConsole.WriteLine(((FOS_System.String) "vAddr=") + vAddr); BasicConsole.WriteLine(((FOS_System.String) "physPDIdx=") + physPDIdx); BasicConsole.WriteLine(((FOS_System.String) "physPTIdx=") + physPTIdx); BasicConsole.WriteLine(((FOS_System.String) "virtPDIdx=") + virtPDIdx); BasicConsole.WriteLine(((FOS_System.String) "virtPTIdx=") + virtPTIdx); #endif if ((UpdateUsedPages & UpdateUsedPagesFlags.Physical) != 0) { UsedPhysPages.Set((int)((physPDIdx * 1024) + physPTIdx)); } if ((UpdateUsedPages & UpdateUsedPagesFlags.Virtual) != 0) { UsedVirtPages.Set((int)((virtPDIdx * 1024) + virtPTIdx)); } //Get a pointer to the pre-allocated page table uint *virtPTPtr = GetFixedPage(virtPDIdx); #if PAGING_TRACE BasicConsole.WriteLine(((FOS_System.String) "ptPtr=") + (uint)virtPTPtr); #endif //Set the page table entry SetPageEntry(virtPTPtr, virtPTIdx, pAddr, flags); //Set directory table entry SetDirectoryEntry(virtPDIdx, (uint *)GetPhysicalAddress((uint)virtPTPtr)); //Invalidate the page table entry so that mapping isn't CPU cached. InvalidatePTE(vAddr); }
private void SetPageEntry(uint* pageTablePtr, uint entry, uint addr, PTEFlags flags) { #if PAGING_TRACE BasicConsole.WriteLine("Setting page entry..."); BasicConsole.WriteLine(((FOS_System.String)"pageTablePtr=") + (uint)pageTablePtr); BasicConsole.WriteLine(((FOS_System.String)"entry=") + entry); BasicConsole.WriteLine(((FOS_System.String)"addr=") + addr); #endif pageTablePtr[entry] = addr | (uint)flags; #if PAGING_TRACE if(pageTablePtr[entry] != (addr | 3)) { BasicConsole.WriteLine("Set page entry verification failed."); } #endif }
private void Map(uint pAddr, uint vAddr, PTEFlags flags, UpdateUsedPagesFlags UpdateUsedPages = UpdateUsedPagesFlags.Both) { #if PAGING_TRACE BasicConsole.WriteLine("Mapping addresses..."); #endif //Calculate page directory and page table indices uint virtPDIdx = vAddr >> 22; uint virtPTIdx = (vAddr >> 12) & 0x03FF; uint physPDIdx = pAddr >> 22; uint physPTIdx = (pAddr >> 12) & 0x03FF; #if PAGING_TRACE BasicConsole.WriteLine(((FOS_System.String)"pAddr=") + pAddr); BasicConsole.WriteLine(((FOS_System.String)"vAddr=") + vAddr); BasicConsole.WriteLine(((FOS_System.String)"physPDIdx=") + physPDIdx); BasicConsole.WriteLine(((FOS_System.String)"physPTIdx=") + physPTIdx); BasicConsole.WriteLine(((FOS_System.String)"virtPDIdx=") + virtPDIdx); BasicConsole.WriteLine(((FOS_System.String)"virtPTIdx=") + virtPTIdx); #endif if ((UpdateUsedPages & UpdateUsedPagesFlags.Physical) != 0) { UsedPhysPages.Set((int)((physPDIdx * 1024) + physPTIdx)); } if((UpdateUsedPages & UpdateUsedPagesFlags.Virtual) != 0) { UsedVirtPages.Set((int)((virtPDIdx * 1024) + virtPTIdx)); } //Get a pointer to the pre-allocated page table uint* virtPTPtr = GetFixedPage(virtPDIdx); #if PAGING_TRACE BasicConsole.WriteLine(((FOS_System.String)"ptPtr=") + (uint)virtPTPtr); #endif //Set the page table entry SetPageEntry(virtPTPtr, virtPTIdx, pAddr, flags); //Set directory table entry SetDirectoryEntry(virtPDIdx, (uint*)GetPhysicalAddress((uint)virtPTPtr)); //Invalidate the page table entry so that mapping isn't CPU cached. InvalidatePTE(vAddr); }