修复不稳定的问题
This commit is contained in:
+12
-11
@@ -5,17 +5,14 @@
|
||||
SW_Handler:
|
||||
/* save all from thread context */
|
||||
addi sp, sp, -32 * 4
|
||||
sw x5, 5 * 4(sp) /* 保存 t0, 后面要使用这个寄存器 */
|
||||
sw t0, 5 * 4(sp) /* 保存 t0, 后面要使用这个寄存器 */
|
||||
|
||||
csrr t0, mstatus /* 读取 mstatus */
|
||||
li t0, 0x80 /* 读取 mstatus */
|
||||
sw t0, 2 * 4(sp) /* 保存到 x2 位置 */
|
||||
|
||||
li t0,0x1800 /* 关闭中断,并进入 M-Mode 模式 */
|
||||
li t0, 0x1800 /* 关闭中断,并进入 M-Mode 模式 */
|
||||
csrw mstatus, t0
|
||||
|
||||
csrr t0, mepc /* 额外保存 mepc 到 x0 位置 */
|
||||
sw t0, 0 * 4(sp)
|
||||
|
||||
sw x1, 1 * 4(sp) /* return address */
|
||||
sw x4, 4 * 4(sp) /* tp */
|
||||
sw x6, 6 * 4(sp)
|
||||
@@ -45,6 +42,9 @@ SW_Handler:
|
||||
sw x30, 30 * 4(sp)
|
||||
sw x31, 31 * 4(sp)
|
||||
|
||||
csrr t0, mepc /* 额外保存 mepc 到 x0 位置 */
|
||||
sw t0, 0 * 4(sp)
|
||||
|
||||
la s0, g_os_port_switch_from_sp /* 更新旧任务栈指针 */
|
||||
lw s1, 0(s0)
|
||||
sw sp, 0(s1)
|
||||
@@ -63,6 +63,8 @@ SW_Handler:
|
||||
|
||||
lw x1, 1 * 4(sp) /* 加载 return address */
|
||||
|
||||
li t0, 0x1800
|
||||
csrs mstatus, t0
|
||||
lw t0, 2*4(sp) /* 将栈里面的 mstatus 恢复 */
|
||||
csrs mstatus, t0 /* 设置 MPIE = 1 */
|
||||
|
||||
@@ -115,14 +117,13 @@ os_port_context_restore:
|
||||
addi t0, t0, -512
|
||||
csrw mscratch,t0
|
||||
|
||||
/* keep machine mode */
|
||||
/* 关闭中断 */
|
||||
li t0, 0x1800
|
||||
csrw mstatus, t0
|
||||
|
||||
/* ---------- 收尾工作 ---------- */
|
||||
jal os_port_on_switch_success
|
||||
|
||||
|
||||
/* ---- Load target sp ---- */
|
||||
|
||||
lw sp, (a0) /* 将 to 的指针加载到 sp */
|
||||
@@ -131,6 +132,9 @@ os_port_context_restore:
|
||||
lw a0, 0 * 4(sp)
|
||||
csrw mepc, a0
|
||||
|
||||
lw a0, 2*4(sp) /* 恢复 MPIE */
|
||||
csrs mstatus, a0
|
||||
|
||||
lw x1, 1 * 4(sp) /* 返回地址 */
|
||||
lw x4, 4 * 4(sp)
|
||||
lw x5, 5 * 4(sp)
|
||||
@@ -161,9 +165,6 @@ os_port_context_restore:
|
||||
lw x30, 30 * 4(sp)
|
||||
lw x31, 31 * 4(sp)
|
||||
|
||||
lw t0, 2*4(sp)
|
||||
csrs mstatus, t0
|
||||
|
||||
addi sp, sp, 32 * 4
|
||||
|
||||
mret
|
||||
|
||||
Reference in New Issue
Block a user