修复不稳定的问题

This commit is contained in:
2026-05-22 20:53:29 +08:00
parent 80e32d4fb8
commit ab11821c0c
2 changed files with 42 additions and 39 deletions
+12 -11
View File
@@ -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