添加switch 需要用的汇编以及函数

ch3
zhangxinyu 2 years ago
parent 87b3f159ef
commit b0338d7648

@ -1 +1,2 @@
mod context; mod context;
mod switch;

@ -0,0 +1,43 @@
# os/src/task/switch.S
.altmacro
.macro SAVE_SN n
sd s\n, (\n+2)*8(a0) # s(n)
.endm
.macro LOAD_SN n
ld s\n, (\n+2)*8(a1) # s(n)
.endm
.section .text
.globl __switch
__switch:
# [1]
# __switch(
# current_task_cx_ptr: *mut TaskContext,
# next_task_cx_ptr: *const TaskContext
# )
# [2] current_task_cx_ptr
# save kernel stack of current task
sd sp, 8(a0) # current_task_cx_ptr
# save ra & s0~s11 of current execution
sd ra, 0(a0) # ras0~s11current_task_cx_ptr
.set n, 0
.rept 12
SAVE_SN %n # s0~s11
.set n, n + 1
.endr
# [3] next_task_cx_ptr
# restore ra & s0~s11 of next execution
ld ra, 0(a1) # ra
.set n, 0
.rept 12
LOAD_SN %n # s0~s11
.set n, n + 1
.endr
# restore kernel stack of next task
ld sp, 8(a1) #
# [4]
ret #

@ -0,0 +1,11 @@
use core::arch::global_asm;
global_asm!(include_str!("switch.S")); // 读入switch.S 到当前代码
use super::context::TaskContext;
extern "C" {
// 引入 switch.S 中的切换函数
pub fn __switch(
current_task_cx_ptr: *mut TaskContext,
next_task_cx_ptr: *const TaskContext
);
}
Loading…
Cancel
Save