From 58c7107eb0a5ae254c135f2eaa6263751f1ebe67 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 26 Sep 2011 13:07:19 +0800 Subject: [PATCH] Kernel/x86_64 - Debugging iret->CPL3 crash --- Kernel/arch/x86_64/desctab.asm | 5 +++++ Kernel/arch/x86_64/mm_virt.c | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Kernel/arch/x86_64/desctab.asm b/Kernel/arch/x86_64/desctab.asm index 694672c7..739b219f 100644 --- a/Kernel/arch/x86_64/desctab.asm +++ b/Kernel/arch/x86_64/desctab.asm @@ -374,6 +374,7 @@ SchedulerIRQ: pop gs POP_GPR add rsp, 2*8 ; Dummy error code and IRQ num +; xchg bx, bx iretq [extern ci_offsetof_tThread_KernelStack] @@ -416,6 +417,10 @@ SyscallStub: pop r11 pop rcx pop rsp ; Change back to user stack + ; TODO: Determine if user is 64 or 32 bit + +; xchg bx, bx + db 0x48 ; REX, nasm doesn't have a sysretq opcode sysret [section .data] diff --git a/Kernel/arch/x86_64/mm_virt.c b/Kernel/arch/x86_64/mm_virt.c index a34c6ad2..1640586b 100644 --- a/Kernel/arch/x86_64/mm_virt.c +++ b/Kernel/arch/x86_64/mm_virt.c @@ -90,11 +90,11 @@ void MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs) { // TODO: Implement Copy-on-Write #if 1 - if( PAGEMAPLVL4(Addr>39) & PF_PRESENT - && PAGEDIRPTR(Addr>>30) & PF_PRESENT - && PAGEDIR(Addr>>21) & PF_PRESENT - && PAGETABLE(Addr>>12) & PF_PRESENT - && PAGETABLE(Addr>>12) & PF_COW ) + if( PAGEMAPLVL4(Addr>>39) & PF_PRESENT + && PAGEDIRPTR (Addr>>30) & PF_PRESENT + && PAGEDIR (Addr>>21) & PF_PRESENT + && PAGETABLE (Addr>>12) & PF_PRESENT + && PAGETABLE (Addr>>12) & PF_COW ) { tPAddr paddr; if(MM_GetRefCount( PAGETABLE(Addr>>12) & PADDR_MASK ) == 1) -- 2.20.1