don't enable interrupts until done with sstatus, scause, &c

This commit is contained in:
Robert Morris 2019-07-02 05:20:11 -04:00
parent abfe9999f4
commit 40f1041a0a

View file

@ -37,7 +37,7 @@ void
usertrap(void) usertrap(void)
{ {
int which_dev = 0; int which_dev = 0;
if((r_sstatus() & SSTATUS_SPP) != 0) if((r_sstatus() & SSTATUS_SPP) != 0)
panic("usertrap: not from user mode"); panic("usertrap: not from user mode");
@ -49,8 +49,6 @@ usertrap(void)
// save user program counter. // save user program counter.
p->tf->epc = r_sepc(); p->tf->epc = r_sepc();
intr_on();
if(r_scause() == 8){ if(r_scause() == 8){
// system call // system call
@ -59,11 +57,15 @@ usertrap(void)
// but we want to return to the next instruction. // but we want to return to the next instruction.
p->tf->epc += 4; p->tf->epc += 4;
// an interrupt will change sstatus &c registers,
// so don't enable until done with those registers.
intr_on();
syscall(); syscall();
} else if((which_dev = devintr()) != 0){ } else if((which_dev = devintr()) != 0){
// ok // ok
} else { } 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()); printf(" sepc=%p stval=%p\n", r_sepc(), r_stval());
p->killed = 1; p->killed = 1;
} }