x86_64: Load rflags after rsp on context restore

When starting multitasking there is a chance an interrupt could be fired
while rsp is still pointing to the ISR stack area if we load rflags
before rsp on "_CPU_Context_restore"
This commit is contained in:
Matheus Pecoraro
2024-06-19 04:26:30 -03:00
committed by Gedare Bloom
parent 3ca279e5b1
commit ef5ed795ec

View File

@@ -68,10 +68,16 @@ SYM(_CPU_Context_switch):
movq HEIRCONTEXT_ARG, rax /* rax = heir threads context */
restore:
pushq (0 * CPU_SIZEOF_POINTER)(rax) /* push rflags */
popf /* restore rflags */
movq (1 * CPU_SIZEOF_POINTER)(rax), rbx
movq (2 * CPU_SIZEOF_POINTER)(rax), rsp
/*
* We need to load rflags after rsp to avoid an interrupt while the ISR stack
* is still being used during the initialization process
*/
pushq (0 * CPU_SIZEOF_POINTER)(rax) /* push rflags */
popf /* restore rflags */
movq (3 * CPU_SIZEOF_POINTER)(rax), rbp
movq (4 * CPU_SIZEOF_POINTER)(rax), r12
movq (5 * CPU_SIZEOF_POINTER)(rax), r13