summaryrefslogtreecommitdiff
path: root/kernel/trap.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/trap.c')
-rw-r--r--kernel/trap.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/kernel/trap.c b/kernel/trap.c
index 018b7db..ea5799f 100644
--- a/kernel/trap.c
+++ b/kernel/trap.c
@@ -53,6 +53,9 @@ usertrap(void)
if(r_scause() == 8){
// system call
+ if(p->killed)
+ exit();
+
// sepc points to the ecall instruction,
// but we want to return to the next instruction.
p->tf->epc += 4;
@@ -100,7 +103,7 @@ usertrapret(void)
p->tf->kernel_satp = r_satp();
p->tf->kernel_sp = (uint64)p->kstack + PGSIZE;
p->tf->kernel_trap = (uint64)usertrap;
- p->tf->hartid = r_tp();
+ p->tf->kernel_hartid = r_tp();
// set up the registers that trampoline.S's sret will use
// to get to user space.
@@ -155,6 +158,15 @@ kerneltrap()
w_sstatus(sstatus);
}
+void
+clockintr()
+{
+ acquire(&tickslock);
+ ticks++;
+ wakeup(&ticks);
+ release(&tickslock);
+}
+
// check if it's an external interrupt or software interrupt,
// and handle it.
// returns 2 if timer interrupt,
@@ -179,16 +191,15 @@ devintr()
plic_complete(irq);
return 1;
} else if(scause == 0x8000000000000001){
- // software interrupt from a machine-mode timer interrupt.
+ // software interrupt from a machine-mode timer interrupt,
+ // forwarded by machinevec in kernelvec.S.
if(cpuid() == 0){
- acquire(&tickslock);
- ticks++;
- wakeup(&ticks);
- release(&tickslock);
+ clockintr();
}
- // acknowledge.
+ // acknowledge the software interrupt by clearing
+ // the SSIP bit in sip.
w_sip(r_sip() & ~2);
return 2;