Skip to main content

LocalContext

Struct LocalContext 

Source
pub struct LocalContext {
    pub supervisor: bool,
    pub interrupt: bool,
    /* private fields */
}
Expand description

线程上下文。

Fields§

§supervisor: bool

是否以特权态切换。

§interrupt: bool

线程中断是否开启。

Implementations§

Source§

impl LocalContext

Source

pub const fn empty() -> Self

创建空白上下文。

Source

pub const fn user(pc: usize) -> Self

初始化指定入口的用户上下文。

切换到用户态时会打开内核中断。

Source

pub const fn thread(pc: usize, interrupt: bool) -> Self

初始化指定入口的内核上下文。

Source

pub fn x(&self, n: usize) -> usize

读取用户通用寄存器。

Source

pub fn x_mut(&mut self, n: usize) -> &mut usize

修改用户通用寄存器。

Source

pub fn a(&self, n: usize) -> usize

读取用户参数寄存器。

Source

pub fn a_mut(&mut self, n: usize) -> &mut usize

修改用户参数寄存器。

Source

pub fn ra(&self) -> usize

读取用户栈指针。

Source

pub fn sp(&self) -> usize

读取用户栈指针。

Source

pub fn sp_mut(&mut self) -> &mut usize

修改用户栈指针。

Source

pub fn pc(&self) -> usize

当前上下文的 pc。

Source

pub fn pc_mut(&mut self) -> &mut usize

修改上下文的 pc。

Source

pub fn move_next(&mut self)

将 pc 移至下一条指令。

§Notice

假设这一条指令不是压缩版本。

Source

pub unsafe fn execute(&mut self) -> usize

执行此线程,并返回 sstatus

§Safety

将修改 sscratchsepcsstatusstvec。 调用者需要确保:

  • 当前处于 S 模式
  • stvec 可以被安全地修改
  • 上下文中的 sepc 指向有效的代码地址

Trait Implementations§

Source§

impl Clone for LocalContext

Source§

fn clone(&self) -> LocalContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.