From fd355ae2b660856a204a54c5aba90a61406cb870 Mon Sep 17 00:00:00 2001 From: zhangxinyu <840317537@qq.com> Date: Fri, 19 May 2023 14:09:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=BA=9B=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E5=92=8C=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ch2/os/src/batch.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/ch2/os/src/batch.rs b/ch2/os/src/batch.rs index cd88811..559a257 100644 --- a/ch2/os/src/batch.rs +++ b/ch2/os/src/batch.rs @@ -96,15 +96,16 @@ pub fn init() { APP_MANAGER.exclusive_access().show_app_info(); } -pub fn run_next_app() -> *mut TrapContext{ +pub fn run_next_app() -> ! { // 运行一个新的app // 把需要执行的指定app, 加载到执行位置APP_BASE_ADDRESS // app_manager 需要drop 或者在一个作用域中, 因为这个函数不会返回, 后面直接进入用户态了 { let mut app_manager = APP_MANAGER.exclusive_access(); - unsafe{ app_manager.load_app(app_manager.current_app); + + println!("------------- run_next_app load app {}", app_manager.current_app); } app_manager.current_app += 1; } @@ -119,19 +120,17 @@ pub fn run_next_app() -> *mut TrapContext{ // 得到用户trap的上下文以及寄存器状态 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_trap_context_ptr = (kernel_stack_top - core::mem::size_of::()) as * mut TrapContext; // 为trap context 分配栈空间 + // 为trap context 分配栈空间 + let kernel_trap_context_ptr = (kernel_stack_top - core::mem::size_of::()) as * mut TrapContext; unsafe { + // 把user_trap_context copy到内核栈顶 *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!"); } - - - - -