Update kstack switch.

master
Yuhao Zhou 6 years ago
parent 4a81242552
commit 2baf15acac

@ -6,6 +6,7 @@
.section .text.context
.globl switch_context
.extern _root_page_table_ptr
.extern _cur_kstack_ptr
switch_context:
// save from's registers
@ -25,6 +26,7 @@ switch_context:
// sw ra, 12*4(sp)
// sw sp, 13*4(sp)
// save page table address
la s0, _root_page_table_ptr
lw AT, 0(s0)
sw AT, 4(sp)
@ -34,6 +36,11 @@ switch_context:
lw AT, 4(sp)
sw AT, 0(s0)
// restore kstack ptr
// la s0, _cur_kstack_ptr
// addi s1, sp, 4 * 14
// sw s1, 0(s0)
lw ra, 0(sp)
lw s0, 2*4(sp)
lw s1, 3*4(sp)

@ -147,6 +147,13 @@ trap_return:
lw fp, 156(sp)
lw ra, 160(sp)
// save kernel stack
la k0, _cur_kstack_ptr
addiu k1, sp, 168
sw k1, 0(k0)
nop
// restore stack
lw sp, 152(sp)
eret

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

Loading…
Cancel
Save