From: John Hodge Date: Thu, 6 Oct 2011 15:19:03 +0000 (+0800) Subject: Kernel/x86_64 - Commenting and cleanup X-Git-Tag: rel0.11~22 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=b56cd2207ddd8acebdaca2d9e236869a6498c15b;p=tpg%2Facess2.git Kernel/x86_64 - Commenting and cleanup --- diff --git a/Kernel/arch/x86_64/proc.asm b/Kernel/arch/x86_64/proc.asm index 4771e1b9..90eb3dca 100644 --- a/Kernel/arch/x86_64/proc.asm +++ b/Kernel/arch/x86_64/proc.asm @@ -98,21 +98,28 @@ SaveState: SwitchTasks: PUSH_GPR + ; Save state RIP and RSP lea rax, [rel .restore] - mov QWORD [rcx], rax + mov [rcx], rax mov [rsi], rsp + ; Change CR3 if requested test r8, r8 jz .setState mov cr3, r8 + + ; Make sure the stack is valid before jumping invlpg [rdi] invlpg [rdi+0x1000] + + ; Go to new state .setState: mov rsp, rdi jmp rdx + ; Restore point for saved state .restore: POP_GPR - xor eax, eax + xor eax, eax ; Return zero ret diff --git a/Kernel/arch/x86_64/proc.c b/Kernel/arch/x86_64/proc.c index 6ed99eea..2d07e1ac 100644 --- a/Kernel/arch/x86_64/proc.c +++ b/Kernel/arch/x86_64/proc.c @@ -16,7 +16,7 @@ #include // === FLAGS === -#define DEBUG_TRACE_SWITCH 1 +#define DEBUG_TRACE_SWITCH 0 #define BREAK_ON_SWITCH 0 // Break into bochs debugger on a task switch // === CONSTANTS === @@ -457,7 +457,7 @@ int Proc_NewKThread(void (*Fcn)(void*), void *Data) newThread->SavedState.RSP = rsp; newThread->SavedState.RIP = (Uint)&NewTaskHeader; - Log("New (KThread) %p, rsp = %p\n", newThread->SavedState.RIP, newThread->SavedState.RSP); +// Log("New (KThread) %p, rsp = %p\n", newThread->SavedState.RIP, newThread->SavedState.RSP); // MAGIC_BREAK(); Threads_AddActive(newThread); @@ -495,7 +495,7 @@ int Proc_Clone(Uint Flags) newThread->SavedState.RIP = rip; // DEBUG - Log("New (Clone) %p, rsp = %p, cr3 = %p", rip, newThread->SavedState.RSP, newThread->MemState.CR3); +// Log("New (Clone) %p, rsp = %p, cr3 = %p", rip, newThread->SavedState.RSP, newThread->MemState.CR3); { Uint cr3; __asm__ __volatile__ ("mov %%cr3, %0" : "=r" (cr3)); @@ -543,7 +543,7 @@ int Proc_SpawnWorker(void (*Fcn)(void*), void *Data) new->SavedState.RSP = new->KernelStack - sizeof(stack_contents); new->SavedState.RIP = (Uint)&NewTaskHeader; - Log("New (Worker) %p, rsp = %p\n", new->SavedState.RIP, new->SavedState.RSP); +// Log("New (Worker) %p, rsp = %p\n", new->SavedState.RIP, new->SavedState.RSP); // Mark as active new->Status = THREAD_STAT_PREINIT;