mirror of
https://github.com/LearningOS/rust-based-os-comp2022.git
synced 2026-05-09 07:11:25 +08:00
31 lines
582 B
Rust
31 lines
582 B
Rust
//! Implementation of [`TaskContext`]
|
|
|
|
#[derive(Copy, Clone)]
|
|
#[repr(C)]
|
|
/// task context structure containing some registers
|
|
pub struct TaskContext {
|
|
ra: usize,
|
|
sp: usize,
|
|
s: [usize; 12],
|
|
}
|
|
|
|
impl TaskContext {
|
|
pub fn zero_init() -> Self {
|
|
Self {
|
|
ra: 0,
|
|
sp: 0,
|
|
s: [0; 12],
|
|
}
|
|
}
|
|
pub fn goto_restore(kstack_ptr: usize) -> Self {
|
|
extern "C" {
|
|
fn __restore();
|
|
}
|
|
Self {
|
|
ra: __restore as usize,
|
|
sp: kstack_ptr,
|
|
s: [0; 12],
|
|
}
|
|
}
|
|
}
|