|
|
@ -96,15 +96,16 @@ pub fn init() {
|
|
|
|
APP_MANAGER.exclusive_access().show_app_info();
|
|
|
|
APP_MANAGER.exclusive_access().show_app_info();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn run_next_app() -> *mut TrapContext{
|
|
|
|
pub fn run_next_app() -> ! {
|
|
|
|
// 运行一个新的app
|
|
|
|
// 运行一个新的app
|
|
|
|
// 把需要执行的指定app, 加载到执行位置APP_BASE_ADDRESS
|
|
|
|
// 把需要执行的指定app, 加载到执行位置APP_BASE_ADDRESS
|
|
|
|
// app_manager 需要drop 或者在一个作用域中, 因为这个函数不会返回, 后面直接进入用户态了
|
|
|
|
// app_manager 需要drop 或者在一个作用域中, 因为这个函数不会返回, 后面直接进入用户态了
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let mut app_manager = APP_MANAGER.exclusive_access();
|
|
|
|
let mut app_manager = APP_MANAGER.exclusive_access();
|
|
|
|
|
|
|
|
|
|
|
|
unsafe{
|
|
|
|
unsafe{
|
|
|
|
app_manager.load_app(app_manager.current_app);
|
|
|
|
app_manager.load_app(app_manager.current_app);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!("------------- run_next_app load app {}", app_manager.current_app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
app_manager.current_app += 1;
|
|
|
|
app_manager.current_app += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -119,19 +120,17 @@ pub fn run_next_app() -> *mut TrapContext{
|
|
|
|
// 得到用户trap的上下文以及寄存器状态
|
|
|
|
// 得到用户trap的上下文以及寄存器状态
|
|
|
|
let user_trap_context = TrapContext::app_init_context(APP_BASE_ADDRESS, user_stack_top);
|
|
|
|
let user_trap_context = TrapContext::app_init_context(APP_BASE_ADDRESS, user_stack_top);
|
|
|
|
|
|
|
|
|
|
|
|
// 把用户trap copy到内核栈, 并把内核栈栈顶返回
|
|
|
|
// 把用户trap copy到内核栈
|
|
|
|
let kernel_stack_top = KERNEL_STACK.as_ptr() as usize + KERNEL_STACK_SIZE; // 现在栈顶和栈底都在一个内存位置
|
|
|
|
let kernel_stack_top = KERNEL_STACK.as_ptr() as usize + KERNEL_STACK_SIZE; // 现在栈顶和栈底都在一个内存位置
|
|
|
|
let kernel_trap_context_ptr = (kernel_stack_top - core::mem::size_of::<TrapContext>()) as * mut TrapContext; // 为trap context 分配栈空间
|
|
|
|
// 为trap context 分配栈空间
|
|
|
|
|
|
|
|
let kernel_trap_context_ptr = (kernel_stack_top - core::mem::size_of::<TrapContext>()) as * mut TrapContext;
|
|
|
|
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
unsafe {
|
|
|
|
|
|
|
|
// 把user_trap_context copy到内核栈顶
|
|
|
|
*kernel_trap_context_ptr = user_trap_context;
|
|
|
|
*kernel_trap_context_ptr = user_trap_context;
|
|
|
|
// 返回现在的内核栈顶
|
|
|
|
// 返回现在的内核栈顶
|
|
|
|
kernel_trap_context_ptr
|
|
|
|
__restore(kernel_trap_context_ptr as *const _ as usize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
panic!("Unreachable in batch::run_current_app!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|