Files
Operator-system/context_switch.S
2026-02-26 21:08:06 +00:00

45 lines
1.0 KiB
ArmAsm
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* context_switch.S cooperative context switch for x86_64
*
* void context_switch(UINT64 *old_rsp, UINT64 new_rsp);
*
* %rdi = pointer to save current RSP (old task's PCB field)
* %rsi = RSP value to restore (new task's saved RSP)
*
* Saves callee-saved registers and RFLAGS on the current stack,
* stores RSP, loads the new stack, restores registers, and returns
* into the new task's execution context.
*/
.text
.global context_switch
context_switch:
/* Save callee-saved registers and flags on the current stack */
pushq %rbp
pushq %rbx
pushq %r12
pushq %r13
pushq %r14
pushq %r15
pushfq
/* Save current stack pointer into *old_rsp */
movq %rsp, (%rdi)
/* Load new task's stack pointer */
movq %rsi, %rsp
/* Restore callee-saved registers and flags from the new stack */
popfq
popq %r15
popq %r14
popq %r13
popq %r12
popq %rbx
popq %rbp
ret
.section .note.GNU-stack,"",@progbits