From: John Hodge Date: Sat, 29 Oct 2011 01:23:24 +0000 (+0800) Subject: Kernel/x86_64 - Fixed recursive page fault, wasn't enabling the NX bit X-Git-Tag: rel0.14~173 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=4fc7ede122603881c8532ddda13dbc5dad7064e6;p=tpg%2Facess2.git Kernel/x86_64 - Fixed recursive page fault, wasn't enabling the NX bit --- diff --git a/Kernel/arch/x86_64/desctab.asm b/Kernel/arch/x86_64/desctab.asm index 2ad44a0c..6e8aa639 100644 --- a/Kernel/arch/x86_64/desctab.asm +++ b/Kernel/arch/x86_64/desctab.asm @@ -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 diff --git a/Kernel/arch/x86_64/mm_virt.c b/Kernel/arch/x86_64/mm_virt.c index c04fcf3a..c7b7a224 100644 --- a/Kernel/arch/x86_64/mm_virt.c +++ b/Kernel/arch/x86_64/mm_virt.c @@ -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 diff --git a/Kernel/arch/x86_64/start32.asm b/Kernel/arch/x86_64/start32.asm index d38c993e..6b4f9403 100644 --- a/Kernel/arch/x86_64/start32.asm +++ b/Kernel/arch/x86_64/start32.asm @@ -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