os/task/
context.rs

1//! Implementation of [`TaskContext`]
2use crate::trap::trap_return;
3
4#[repr(C)]
5/// task context structure containing some registers
6pub struct TaskContext {
7    /// return address ( e.g. __restore ) of __switch ASM function
8    ra: usize,
9    /// kernel stack pointer of app
10    sp: usize,
11    /// s0-11 register, callee saved
12    s: [usize; 12],
13}
14
15impl TaskContext {
16    /// init task context
17    pub fn zero_init() -> Self {
18        Self {
19            ra: 0,
20            sp: 0,
21            s: [0; 12],
22        }
23    }
24    /// set Task Context{__restore ASM funciton: trap_return, sp: kstack_ptr, s: s_0..12}
25    pub fn goto_trap_return(kstack_ptr: usize) -> Self {
26        Self {
27            ra: trap_return as usize,
28            sp: kstack_ptr,
29            s: [0; 12],
30        }
31    }
32}