Struct axhal::arch::TaskContext

source ·
pub struct TaskContext {
    pub kstack_top: VirtAddr,
    pub rsp: u64,
    pub fs_base: usize,
    pub ext_state: ExtendedState,
}
Expand description

Saved hardware states of a task.

The context usually includes:

  • Callee-saved registers
  • Stack pointer register
  • Thread pointer register (for thread-local storage, currently unsupported)
  • 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.

On x86_64, callee-saved registers are saved to the kernel stack by the PUSH instruction. So that rsp is the RSP after callee-saved registers are pushed, and kstack_top is the top of the kernel stack (RSP before any push).

Fields§

§kstack_top: VirtAddr

The kernel stack top of the task.

§rsp: u64

RSP after all callee-saved registers are pushed.

§fs_base: usize

Thread Local Storage (TLS).

§ext_state: ExtendedState
Available on crate feature fp_simd only.

Extended states, i.e., FP/SIMD states.

Implementations§

source§

impl TaskContext

source

pub const fn new() -> Self

Creates a new default context for a new task.

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 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

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>,

§

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>,

§

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.