X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86%2Fmm_virt.c;h=cf77b8759b0f51c43b8d9626099445800ed7edd7;hb=60149f3ea48a795f9fbb15149e87d3a41aa136bf;hp=0ef677107bcaa7397cc72e8e3b5d4b1bfef233ee;hpb=8d062ceb17eb6cfb2e3db8af6794d38391c245d3;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86/mm_virt.c b/Kernel/arch/x86/mm_virt.c index 0ef67710..cf77b875 100644 --- a/Kernel/arch/x86/mm_virt.c +++ b/Kernel/arch/x86/mm_virt.c @@ -9,7 +9,8 @@ * 0xFE - Unused * 0xFF - System Calls / Kernel's User Code */ -#define DEBUG 1 +#define DEBUG 0 +#define SANITY 1 #include #include #include @@ -105,10 +106,8 @@ Uint32 gWorkerStacks[(NUM_WORKER_STACKS+31)/32]; void MM_PreinitVirtual() { #if USE_PAE - //gaInitPDPT[ 0 ] = 0; gaInitPageDir[ ((PAGE_TABLE_ADDR >> TAB)-3*512+3)*2 ] = ((tTabEnt)&gaInitPageDir - KERNEL_BASE) | 3; #else - //gaInitPageDir[ 0 ] = 0; // Needed for SMP startup code gaInitPageDir[ PAGE_TABLE_ADDR >> 22 ] = ((tTabEnt)&gaInitPageDir - KERNEL_BASE) | 3; #endif INVLPG( PAGE_TABLE_ADDR ); @@ -156,6 +155,18 @@ void MM_InstallVirtual() #endif } +/** + * \brief Cleans up the SMP required mappings + */ +void MM_FinishVirtualInit() +{ + #if USE_PAE + gaInitPDPT[ 0 ] = 0; + #else + gaInitPageDir[ 0 ] = 0; + #endif +} + /** * \fn void MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs) * \brief Called on a page fault @@ -177,6 +188,7 @@ void MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs) } else { + //Log("MM_PageFault: COW - MM_DuplicatePage(0x%x)", Addr); paddr = MM_DuplicatePage( Addr ); MM_DerefPhys( gaPageTable[Addr>>12] & ~0xFFF ); gaPageTable[Addr>>12] &= PF_USER; @@ -196,7 +208,7 @@ void MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs) (ErrorCode&1?"bad/locked":"non-present"), (ErrorCode&16?" (Instruction Fetch)":"") ); - Warning("User Pagefault: Instruction at %p accessed %p", Regs->eip, Addr); + Warning("User Pagefault: Instruction at %04x:%08x accessed %p", Regs->cs, Regs->eip, Addr); __asm__ __volatile__ ("sti"); // Restart IRQs Threads_SegFault(Addr); return ; @@ -318,7 +330,7 @@ tPAddr MM_Allocate(tVAddr VAddr) //LOG("paddr = 0x%llx (new table)", paddr); if( paddr == 0 ) { Warning("MM_Allocate - Out of Memory (Called by %p)", __builtin_return_address(0)); - LEAVE('i',0); + //LEAVE('i',0); return 0; } // Map @@ -524,7 +536,7 @@ tPAddr MM_Clone() memsetd( gaTmpDir, 0, 1024 ); // Copy Tables - for(i=0;i<768;i++) + for( i = 0; i < 768; i ++) { // Check if table is allocated if( !(gaPageDir[i] & PF_PRESENT) ) { @@ -802,6 +814,8 @@ tPAddr MM_DuplicatePage(tVAddr VAddr) Uint temp; int wasRO = 0; + //ENTER("xVAddr", VAddr); + // Check if mapped if( !(gaPageDir [VAddr >> 22] & PF_PRESENT) ) return 0; if( !(gaPageTable[VAddr >> 12] & PF_PRESENT) ) return 0; @@ -826,6 +840,7 @@ tPAddr MM_DuplicatePage(tVAddr VAddr) if(!wasRO) gaPageTable[VAddr >> 12] |= PF_WRITE; INVLPG(VAddr); + //LEAVE('X', ret); return ret; } @@ -880,10 +895,10 @@ void MM_FreeTemp(tVAddr VAddr) } /** - * \fn tVAddr MM_MapHWPage(tPAddr PAddr, Uint Number) + * \fn tVAddr MM_MapHWPages(tPAddr PAddr, Uint Number) * \brief Allocates a contigous number of pages */ -tVAddr MM_MapHWPage(tPAddr PAddr, Uint Number) +tVAddr MM_MapHWPages(tPAddr PAddr, Uint Number) { int i, j; @@ -947,7 +962,7 @@ tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr) { phys = MM_AllocPhys(); *PhysAddr = phys; - ret = MM_MapHWPage(phys, 1); + ret = MM_MapHWPages(phys, 1); if(ret == 0) { MM_DerefPhys(phys); LEAVE('i', 0); @@ -966,7 +981,7 @@ tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr) } // Allocated successfully, now map - ret = MM_MapHWPage(phys, Pages); + ret = MM_MapHWPages(phys, Pages); if( ret == 0 ) { // If it didn't map, free then return 0 for(;Pages--;phys+=0x1000) @@ -981,10 +996,10 @@ tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr) } /** - * \fn void MM_UnmapHWPage(tVAddr VAddr, Uint Number) + * \fn void MM_UnmapHWPages(tVAddr VAddr, Uint Number) * \brief Unmap a hardware page */ -void MM_UnmapHWPage(tVAddr VAddr, Uint Number) +void MM_UnmapHWPages(tVAddr VAddr, Uint Number) { int i, j; // Sanity Check @@ -1007,6 +1022,6 @@ void MM_UnmapHWPage(tVAddr VAddr, Uint Number) EXPORT(MM_GetPhysAddr); EXPORT(MM_Map); //EXPORT(MM_Unmap); -EXPORT(MM_MapHWPage); +EXPORT(MM_MapHWPages); EXPORT(MM_AllocDMA); -EXPORT(MM_UnmapHWPage); +EXPORT(MM_UnmapHWPages);