From ed20aa45fd171ef9e5e81ce08cbe55f2c5739adb Mon Sep 17 00:00:00 2001 From: WangRunji Date: Thu, 1 Nov 2018 19:53:30 +0800 Subject: [PATCH] Fix user process bug on RV32. Set sstatus.SIE = 0 on the initial TrapFrame, to prevent interrupt on switching. --- kernel/src/arch/riscv32/boot/trap.asm | 2 +- kernel/src/arch/riscv32/context.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/src/arch/riscv32/boot/trap.asm b/kernel/src/arch/riscv32/boot/trap.asm index 37afaf11..bf4aba54 100644 --- a/kernel/src/arch/riscv32/boot/trap.asm +++ b/kernel/src/arch/riscv32/boot/trap.asm @@ -62,7 +62,7 @@ _save_context: lw s1, 32*4(sp) # s1 = sstatus lw s2, 33*4(sp) # s2 = sepc andi s0, s1, 1 << 8 - bnez s0, _restore_context # back to U-mode? (sstatus.SPP = 1) + bnez s0, _restore_context # back to S-mode? (sstatus.SPP = 1) _save_kernel_sp: addi s0, sp, 36*4 csrw 0x140, s0 # sscratch = kernel-sp diff --git a/kernel/src/arch/riscv32/context.rs b/kernel/src/arch/riscv32/context.rs index d1a6d61a..0d412989 100644 --- a/kernel/src/arch/riscv32/context.rs +++ b/kernel/src/arch/riscv32/context.rs @@ -30,7 +30,8 @@ impl TrapFrame { tf.x[2] = sp; tf.sepc = entry_addr; tf.sstatus = sstatus::read(); - tf.sstatus.set_spie(false); // Enable interrupt + tf.sstatus.set_spie(true); + tf.sstatus.set_sie(false); tf.sstatus.set_spp(sstatus::SPP::User); tf }