You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rCore_stu/ch3/os/src/task/switch.S

44 lines
1.4 KiB
ArmAsm

# 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 #