2020-11-29 01:31:36 +08:00
|
|
|
.altmacro
|
|
|
|
.macro SAVE_SN n
|
2021-07-10 12:35:17 +08:00
|
|
|
sd s\n, (\n+2)*8(a0)
|
2020-11-29 01:31:36 +08:00
|
|
|
.endm
|
|
|
|
.macro LOAD_SN n
|
2021-07-10 12:35:17 +08:00
|
|
|
ld s\n, (\n+2)*8(a1)
|
2020-11-29 01:31:36 +08:00
|
|
|
.endm
|
|
|
|
.section .text
|
|
|
|
.globl __switch
|
|
|
|
__switch:
|
2021-01-04 16:03:07 +08:00
|
|
|
# __switch(
|
2021-07-10 12:35:17 +08:00
|
|
|
# current_task_cx_ptr: *mut TaskContext,
|
|
|
|
# next_task_cx_ptr: *const TaskContext
|
2021-01-04 16:03:07 +08:00
|
|
|
# )
|
2021-07-10 12:35:17 +08:00
|
|
|
# save kernel stack of current task
|
|
|
|
sd sp, 8(a0)
|
|
|
|
# save ra & s0~s11 of current execution
|
|
|
|
sd ra, 0(a0)
|
2020-11-29 01:31:36 +08:00
|
|
|
.set n, 0
|
|
|
|
.rept 12
|
|
|
|
SAVE_SN %n
|
|
|
|
.set n, n + 1
|
|
|
|
.endr
|
2021-07-10 12:35:17 +08:00
|
|
|
# restore ra & s0~s11 of next execution
|
|
|
|
ld ra, 0(a1)
|
2020-11-29 01:31:36 +08:00
|
|
|
.set n, 0
|
|
|
|
.rept 12
|
|
|
|
LOAD_SN %n
|
|
|
|
.set n, n + 1
|
|
|
|
.endr
|
2021-07-10 12:35:17 +08:00
|
|
|
# restore kernel stack of next task
|
|
|
|
ld sp, 8(a1)
|
2020-11-29 01:31:36 +08:00
|
|
|
ret
|
|
|
|
|