[Linux kernel] __switch_to (RISC-V)
The following routine performs the context switching:
ENTRY(__switch_to)
/* Save context into prev->thread */
li a4, TASK_THREAD_RA
add a3, a0, a4
add a4, a1, a4
REG_S ra, TASK_THREAD_RA_RA(a3)
REG_S sp, TASK_THREAD_SP_RA(a3)
REG_S s0, TASK_THREAD_S0_RA(a3) // x8
REG_S s1, TASK_THREAD_S1_RA(a3) // x9
REG_S s2, TASK_THREAD_S2_RA(a3) // x18
REG_S s3, TASK_THREAD_S3_RA(a3) // x19
REG_S s4, TASK_THREAD_S4_RA(a3) // x20
REG_S s5, TASK_THREAD_S5_RA(a3) // x21
REG_S s6, TASK_THREAD_S6_RA(a3) // x22
REG_S s7, TASK_THREAD_S7_RA(a3) // x23
REG_S s8, TASK_THREAD_S8_RA(a3) // x24
REG_S s9, TASK_THREAD_S9_RA(a3) // x25
REG_S s10, TASK_THREAD_S10_RA(a3) // x26
REG_S s11, TASK_THREAD_S11_RA(a3) // x27
/* Restore context from next->thread */
REG_L ra, TASK_THREAD_RA_RA(a4)
REG_L sp, TASK_THREAD_SP_RA(a4)
REG_L s0, TASK_THREAD_S0_RA(a4)
REG_L s1, TASK_THREAD_S1_RA(a4)
REG_L s2, TASK_THREAD_S2_RA(a4)
REG_L s3, TASK_THREAD_S3_RA(a4)
REG_L s4, TASK_THREAD_S4_RA(a4)
REG_L s5, TASK_THREAD_S5_RA(a4)
REG_L s6, TASK_THREAD_S6_RA(a4)
REG_L s7, TASK_THREAD_S7_RA(a4)
REG_L s8, TASK_THREAD_S8_RA(a4)
REG_L s9, TASK_THREAD_S9_RA(a4)
REG_L s10, TASK_THREAD_S10_RA(a4)
REG_L s11, TASK_THREAD_S11_RA(a4)
/* The offset of thread_info in task_struct is zero. */
move tp, a1
ret
ENDPROC(__switch_to)