Fix kstack switch.

master
Yuhao Zhou 6 years ago
parent 248623096b
commit 4a81242552

@ -3,12 +3,18 @@
.set noreorder .set noreorder
.section .text.entry .section .text.entry
.globl _start .globl _start
.extern _root_page_table_buffer
.extern _cur_kstack_ptr
_start: _start:
# setup stack and gp # setup stack and gp
la sp, bootstacktop la sp, bootstacktop
la gp, _gp la gp, _gp
la t0, _cur_kstack_ptr
la t1, _root_page_table_buffer
sw t1, 0(t0)
# set ebase # set ebase
la t0, trap_entry la t0, trap_entry
mfc0 t1, $15 # C0_EBASE mfc0 t1, $15 # C0_EBASE

@ -21,8 +21,10 @@ general_trap_vec:
trap_from_user: trap_from_user:
# load kstack, we can use k0 to store something # load kstack, we can use k0 to store something
la k0, kernel_stack # la k0, kernel_stack
la sp, kernel_stack_top # la sp, kernel_stack_top
la k0, _cur_kstack_ptr
lw sp, 0(k0)
trap_from_kernel: trap_from_kernel:
/* /*
@ -161,7 +163,10 @@ kernel_stack_top:
.align 12 #PGSHIFT .align 12 #PGSHIFT
.global _root_page_table_buffer .global _root_page_table_buffer
_root_page_table_buffer: _root_page_table_buffer:
.space 1024 * 4 # 4KB .space 1024 * 64 # 64KB
.global _root_page_table_ptr .global _root_page_table_ptr
_root_page_table_ptr: _root_page_table_ptr:
.space 4 # 4bytes .space 4 # 4bytes
.global _cur_kstack_ptr
_cur_kstack_ptr:
.space 4 # 4bytes

@ -149,6 +149,10 @@ pub struct Context {
sp: usize, sp: usize,
} }
extern "C" {
fn _cur_kstack_ptr();
}
impl Context { impl Context {
/// Switch to another kernel thread. /// Switch to another kernel thread.
/// ///
@ -161,6 +165,10 @@ impl Context {
fn switch_context(src: *mut Context, dst: *mut Context); fn switch_context(src: *mut Context, dst: *mut Context);
} }
unsafe {
*(_cur_kstack_ptr as *mut usize) = target.sp;
}
switch_context(self as *mut Context, target as *mut Context); switch_context(self as *mut Context, target as *mut Context);
} }

@ -68,7 +68,10 @@ pub extern fn rust_trap(tf: &mut TrapFrame) {
E::TLBModification => page_fault(tf), E::TLBModification => page_fault(tf),
E::TLBLoadMiss => page_fault(tf), E::TLBLoadMiss => page_fault(tf),
E::TLBStoreMiss => page_fault(tf), E::TLBStoreMiss => page_fault(tf),
_ => crate::trap::error(tf), _ => {
error!("Unhandled Exception @ CPU{}: {:?} ", 0, tf.cause.cause());
crate::trap::error(tf)
}
} }
trace!("Interrupt end"); trace!("Interrupt end");
} }

Loading…
Cancel
Save