Kernel/x86_64 - Fixed recursive page fault, wasn't enabling the NX bit
authorJohn Hodge <[email protected]>
Sat, 29 Oct 2011 01:23:24 +0000 (09:23 +0800)
committerJohn Hodge <[email protected]>
Sat, 29 Oct 2011 01:23:24 +0000 (09:23 +0800)
Kernel/arch/x86_64/desctab.asm
Kernel/arch/x86_64/mm_virt.c
Kernel/arch/x86_64/start32.asm

index 2ad44a0..6e8aa63 100644 (file)
@@ -104,12 +104,6 @@ Desctab_Init:
        ; Start interrupts
        sti
 
-       ; Initialise System Calls (SYSCALL/SYSRET)
-       ; Set IA32_EFER.SCE
-       mov ecx, 0xC0000080
-       rdmsr
-       or eax, 1
-       wrmsr
        ; Set IA32_LSTAR (RIP of handler)
        mov ecx, 0xC0000082     ; IA32_LSTAR
        mov eax, SyscallStub - 0xFFFFFFFF00000000
index c04fcf3..c7b7a22 100644 (file)
@@ -154,6 +154,25 @@ void MM_int_ClonePageEnt( Uint64 *Ent, void *NextLevel, tVAddr Addr, int bTable
  */
 int MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs)
 {
+//     Log_Debug("MMVirt", "Addr = %p, ErrorCode = %x", Addr, ErrorCode);
+
+       // Catch reserved bits first
+       if( ErrorCode & 0x8 )
+       {
+               Log_Warning("MMVirt", "Reserved bits trashed!");
+               Log_Warning("MMVirt", "PML4 Ent   = %P", PAGEMAPLVL4(Addr>>39));
+               if( !(PAGEMAPLVL4(Addr>>39) & PF_PRESENT) )     goto print_done;
+               Log_Warning("MMVirt", "PDP Ent    = %P", PAGEDIRPTR(Addr>>30));
+               if( !(PAGEDIRPTR(Addr>>30) & PF_PRESENT) )      goto print_done;
+               Log_Warning("MMVirt", "PDir Ent   = %P", PAGEDIR(Addr>>21));
+               if( !(PAGEDIR(Addr>>21) & PF_PRESENT) ) goto print_done;
+               Log_Warning("MMVirt", "PTable Ent = %P", PAGETABLE(Addr>>12));
+               if( !(PAGETABLE(Addr>>12) & PF_PRESENT) )       goto print_done;
+       print_done:
+               
+               for(;;);
+       }
+
        // TODO: Implement Copy-on-Write
        #if 1
        if( PAGEMAPLVL4(Addr>>39) & PF_PRESENT
index d38c993..6b4f940 100644 (file)
@@ -58,6 +58,13 @@ start:
        or eax, 0x80|0x20|0x10
        mov cr4, eax
 
+       ; Initialise System Calls (SYSCALL/SYSRET)
+       ; Set IA32_EFER.(NXE|SCE)
+       mov ecx, 0xC0000080
+       rdmsr
+       or eax, (1 << 11)|(1 << 0)      ; NXE, SCE
+       wrmsr
+
        ; Load PDP4
        mov eax, gInitialPML4 - KERNEL_BASE
        mov cr3, eax

UCC git Repository :: git.ucc.asn.au