diff --git a/arch/x86/kernel/entry64.asm b/arch/x86/kernel/entry64.asm index f70d9f44..ba38163c 100644 --- a/arch/x86/kernel/entry64.asm +++ b/arch/x86/kernel/entry64.asm @@ -1146,8 +1146,14 @@ common_switch: xor rax, rax %endif add rax, task_state_segments - ; set rsp0 in TSS - mov [rax+4], rsp + + ; determine and set esp0 in TSS + mov rbx, rsp + mov rcx, KERNEL_STACK_SIZE-1 + not rcx + and rbx, rcx + add rbx, KERNEL_STACK_SIZE-16 + mov [rax+4], rbx ; call cleanup code call finish_task_switch