mirror of
https://github.com/LearningOS/rust-based-os-comp2022.git
synced 2026-07-02 18:46:02 +08:00
add os[1-8]-ref for os refereces, add guide, add README
This commit is contained in:
32
os5-ref/src/task/context.rs
Normal file
32
os5-ref/src/task/context.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
//! Implementation of [`TaskContext`]
|
||||
|
||||
use crate::trap::trap_return;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
/// task context structure containing some registers
|
||||
pub struct TaskContext {
|
||||
/// Ret position after task switching
|
||||
ra: usize,
|
||||
/// Stack pointer
|
||||
sp: usize,
|
||||
/// s0-11 register, callee saved
|
||||
s: [usize; 12],
|
||||
}
|
||||
|
||||
impl TaskContext {
|
||||
pub fn zero_init() -> Self {
|
||||
Self {
|
||||
ra: 0,
|
||||
sp: 0,
|
||||
s: [0; 12],
|
||||
}
|
||||
}
|
||||
pub fn goto_trap_return(kstack_ptr: usize) -> Self {
|
||||
Self {
|
||||
ra: trap_return as usize,
|
||||
sp: kstack_ptr,
|
||||
s: [0; 12],
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user