Move TaskContext into TCB instead of kstack.

This commit is contained in:
Yifan Wu 2021-07-10 12:35:17 +08:00
parent f1aabb5e0e
commit 92b949a01f
6 changed files with 49 additions and 46 deletions

View file

@ -28,14 +28,10 @@ impl KernelStack {
fn get_sp(&self) -> usize {
self.data.as_ptr() as usize + KERNEL_STACK_SIZE
}
pub fn push_context(&self, trap_cx: TrapContext, task_cx: TaskContext) -> &'static mut TaskContext {
unsafe {
let trap_cx_ptr = (self.get_sp() - core::mem::size_of::<TrapContext>()) as *mut TrapContext;
*trap_cx_ptr = trap_cx;
let task_cx_ptr = (trap_cx_ptr as usize - core::mem::size_of::<TaskContext>()) as *mut TaskContext;
*task_cx_ptr = task_cx;
task_cx_ptr.as_mut().unwrap()
}
pub fn push_context(&self, trap_cx: TrapContext) -> usize {
let trap_cx_ptr = (self.get_sp() - core::mem::size_of::<TrapContext>()) as *mut TrapContext;
unsafe { *trap_cx_ptr = trap_cx; }
trap_cx_ptr as usize
}
}
@ -81,9 +77,8 @@ pub fn load_apps() {
}
}
pub fn init_app_cx(app_id: usize) -> &'static TaskContext {
pub fn init_app_cx(app_id: usize) -> usize {
KERNEL_STACK[app_id].push_context(
TrapContext::app_init_context(get_base_i(app_id), USER_STACK[app_id].get_sp()),
TaskContext::goto_restore(),
)
}