From 40f1041a0a7cd8a1902371cf459989c19f1dc718 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Tue, 2 Jul 2019 05:20:11 -0400 Subject: [PATCH] don't enable interrupts until done with sstatus, scause, &c --- kernel/trap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/trap.c b/kernel/trap.c index 06fc4b3..835a3b0 100644 --- a/kernel/trap.c +++ b/kernel/trap.c @@ -37,7 +37,7 @@ void usertrap(void) { int which_dev = 0; - + if((r_sstatus() & SSTATUS_SPP) != 0) panic("usertrap: not from user mode"); @@ -49,8 +49,6 @@ usertrap(void) // save user program counter. p->tf->epc = r_sepc(); - - intr_on(); if(r_scause() == 8){ // system call @@ -59,11 +57,15 @@ usertrap(void) // but we want to return to the next instruction. p->tf->epc += 4; + // an interrupt will change sstatus &c registers, + // so don't enable until done with those registers. + intr_on(); + syscall(); } else if((which_dev = devintr()) != 0){ // ok } else { - printf("usertrap(): unexpected scause 0x%p pid=%d\n", r_scause(), p->pid); + printf("usertrap(): unexpected scause %p pid=%d\n", r_scause(), p->pid); printf(" sepc=%p stval=%p\n", r_sepc(), r_stval()); p->killed = 1; }