Move context switch to context.S

master
Yuhao Zhou 6 years ago
parent 747d5e2bee
commit 8ed6822636

@ -0,0 +1,54 @@
#include "regdef.h"
.set noat
.set noreorder
// .section .text.context
.globl switch_context
.extern root_page_table_ptr
switch_context:
// save from's registers
addi sp, sp, (-4*14)
sw sp, 0(a0)
sw ra, 0(sp)
sw s0, 2*4(sp)
sw s1, 3*4(sp)
sw s2, 4*4(sp)
sw s3, 5*4(sp)
sw s4, 6*4(sp)
sw s5, 7*4(sp)
sw s6, 8*4(sp)
sw s7, 9*4(sp)
sw s8, 10*4(sp)
sw gp, 11*4(sp)
sw ra, 12*4(sp)
sw sp, 13*4(sp)
la s0, root_page_table_ptr
lw at, 0(s0)
sw at, 4(sp)
// restore to's registers
lw sp, 0(a1)
lw at, 4(sp)
sw at, 0(s0)
lw ra, 0(sp)
lw s0, 2*4(sp)
lw s1, 3*4(sp)
lw s2, 4*4(sp)
lw s3, 5*4(sp)
lw s4, 6*4(sp)
lw s5, 7*4(sp)
lw s6, 8*4(sp)
lw s7, 9*4(sp)
lw s8, 10*4(sp)
lw gp, 11*4(sp)
lw ra, 12*4(sp)
lw sp, 13*4(sp)
addi sp, sp, (4*14)
sw zero, 0(a1)
jr ra
nop

@ -159,57 +159,7 @@ impl Context {
#[naked] #[naked]
#[inline(never)] #[inline(never)]
pub unsafe extern fn switch(&mut self, _target: &mut Self) { pub unsafe extern fn switch(&mut self, _target: &mut Self) {
asm!(r" asm!(include_str!("boot/context.S"));
.equ XLENB, 4
.macro Load reg, mem
lw \reg, \mem
.endm
.macro Store reg, mem
sw \reg, \mem
.endm");
asm!("
// save from's registers
addi sp, sp, (-XLENB*14)
Store sp, 0(a0)
Store ra, 0*XLENB(sp)
Store s0, 2*XLENB(sp)
Store s1, 3*XLENB(sp)
Store s2, 4*XLENB(sp)
Store s3, 5*XLENB(sp)
Store s4, 6*XLENB(sp)
Store s5, 7*XLENB(sp)
Store s6, 8*XLENB(sp)
Store s7, 9*XLENB(sp)
Store s8, 10*XLENB(sp)
Store gp, 11*XLENB(sp)
Store ra, 12*XLENB(sp)
Store sp, 13*XLENB(sp)
Store $1, 1*XLENB(sp)
// restore to's registers
Load sp, 0(a1)
Load $0, 1*XLENB(sp)
Load ra, 0*XLENB(sp)
Load s0, 2*XLENB(sp)
Load s1, 3*XLENB(sp)
Load s2, 4*XLENB(sp)
Load s3, 5*XLENB(sp)
Load s4, 6*XLENB(sp)
Load s5, 7*XLENB(sp)
Load s6, 8*XLENB(sp)
Load s7, 9*XLENB(sp)
Load s8, 10*XLENB(sp)
Load gp, 11*XLENB(sp)
Load ra, 12*XLENB(sp)
Load sp, 13*XLENB(sp)
addi sp, sp, (XLENB*14)
Store zero, 0(a1)
jr ra
nop"
:"=r"(*root_page_table_ptr) :"r"(*root_page_table_ptr) : : "volatile" )
} }
/// Constructs a null Context for the current running thread. /// Constructs a null Context for the current running thread.

Loading…
Cancel
Save