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; }