pub struct TaskContext {
pub ra: usize,
pub sp: usize,
pub s: [usize; 10],
pub fpu: FpuState,
/* private fields */
}context only.Expand description
Saved hardware states of a task.
The context usually includes:
- Callee-saved registers
- Stack pointer register
- Thread pointer register (for kernel-space thread-local storage)
- FP/SIMD registers
On context switch, current task saves its context from CPU to memory, and the next task restores its context from memory to CPU.
Fields§
§ra: usizeReturn Address
sp: usizeStack Pointer
s: [usize; 10]loongArch need to save 10 static registers from $r22 to $r31
fpu: FpuStatefp-simd only.Floating Point Unit states
Implementations§
Source§impl TaskContext
impl TaskContext
Sourcepub fn init(
&mut self,
entry: usize,
kstack_top: VirtAddr,
kernel_tls: KernelTlsBase,
)
pub fn init( &mut self, entry: usize, kstack_top: VirtAddr, kernel_tls: KernelTlsBase, )
Initializes a task context with its entry point, kernel stack, and task-owned kernel TLS base.
Sourcepub fn set_task_anchor(&mut self, header: TaskAnchor)
pub fn set_task_anchor(&mut self, header: TaskAnchor)
Sets the pinned task-owned runtime task anchor.
Sourcepub const fn task_anchor(&self) -> Option<TaskAnchor>
pub const fn task_anchor(&self) -> Option<TaskAnchor>
Returns the configured task-owned runtime task anchor.
Sourcepub fn clone_user_fp_state_into(&self, child: &mut Self)
Available on crate features fp-simd and uspace only.
pub fn clone_user_fp_state_into(&self, child: &mut Self)
fp-simd and uspace only.Saves the running parent’s hardware FP image into an unpublished child.
The runtime must pin the parent CPU while calling this method. Kernel code uses the soft-float ABI; eager task switching keeps the parent’s user register image live across kernel entry and preemption.
Sourcepub fn prepare_switch_to(&mut self, _next_ctx: &Self)
pub fn prepare_switch_to(&mut self, _next_ctx: &Self)
Completes FPU work before current-context publication.
Sourcepub unsafe fn switch_to(&mut self, next_ctx: &Self)
pub unsafe fn switch_to(&mut self, next_ctx: &Self)
Performs only the final GPR/current/TLS transfer.
§Safety
Scheduling must be serialized, FPU state prepared, and the next current anchor published. Both contexts and their anchors must remain pinned and alive. IRQs must remain disabled from publication through this call, with no intervening fallible or ownership-sensitive work.