Skip to main content

TaskContext

Struct TaskContext 

Source
#[repr(C)]
pub struct TaskContext {
Show 17 fields pub ra: usize, pub sp: usize, pub s0: usize, pub s1: usize, pub s2: usize, pub s3: usize, pub s4: usize, pub s5: usize, pub s6: usize, pub s7: usize, pub s8: usize, pub s9: usize, pub s10: usize, pub s11: usize, pub tp: usize, pub satp: PhysAddr, pub fp_state: FpState,
}
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: usize§sp: usize§s0: usize§s1: usize§s2: usize§s3: usize§s4: usize§s5: usize§s6: usize§s7: usize§s8: usize§s9: usize§s10: usize§s11: usize§tp: usize

Thread Pointer

§satp: PhysAddr
Available on crate feature uspace only.

The satp register value, i.e., the page table root.

§fp_state: FpState
Available on crate feature fp-simd only.

Implementations§

Source§

impl TaskContext

Source

pub fn new() -> Self

Creates a dummy context for a new task.

Note the context is not initialized, it will be filled by switch_to (for initial tasks) and init (for regular tasks) methods.

Source

pub fn init(&mut self, entry: usize, kstack_top: VirtAddr, tls_area: VirtAddr)

Initializes the context for a new task, with the given entry point and kernel stack.

Source

pub fn set_page_table_root(&mut self, satp: PhysAddr)

Available on crate feature uspace only.

Changes the page table root in this context.

The hardware register for page table root (satp for riscv64) will be updated to the next task’s after Self::switch_to.

Source

pub fn switch_to(&mut self, next_ctx: &Self)

Switches to another task.

It first saves the current task’s context from CPU to this place, and then restores the next task’s context from next_ctx to CPU.

Trait Implementations§

Source§

impl Debug for TaskContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TaskContext

Source§

fn default() -> TaskContext

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.