os/task/
context.rs

1//! Implementation of [`TaskContext`]
2
3/// Task Context
4#[derive(Copy, Clone)]
5#[repr(C)]
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    /// callee saved registers:  s 0..11
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
25    /// set task context {__restore ASM funciton, kernel stack, s_0..12 }
26    pub fn goto_restore(kstack_ptr: usize) -> Self {
27        unsafe extern "C" {
28            unsafe fn __restore();
29        }
30        Self {
31            ra: __restore as usize,
32            sp: kstack_ptr,
33            s: [0; 12],
34        }
35    }
36}