switch_to

Function switch_to 

Source
pub unsafe extern "C" fn switch_to(
    prev_ctx: *mut KernelContext,
    next_ctx: *const KernelContext,
)
Expand description

Switch from the current kernel context to the next kernel context

This function performs a complete kernel context switch:

  1. Saves callee-saved registers (sp, ra, s0-s11) to prev_ctx
  2. Restores callee-saved registers from next_ctx
  3. Returns to the point where next_ctx was previously switched out

§Arguments

  • prev_ctx - Mutable reference to store the current context
  • next_ctx - Reference to the context to switch to

§Safety

This function must only be called from kernel code with valid contexts. The stack pointers in both contexts must point to valid, allocated stacks.

§Returns

This function returns twice:

  • Once immediately (when switching away from this context)
  • Once when this context is resumed later