diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/riscv.h | 1 | ||||
-rw-r--r-- | kernel/spinlock.c | 7 | ||||
-rw-r--r-- | kernel/start.c | 1 | ||||
-rw-r--r-- | kernel/trap.c | 7 |
4 files changed, 9 insertions, 7 deletions
diff --git a/kernel/riscv.h b/kernel/riscv.h index f46ba59..0aec003 100644 --- a/kernel/riscv.h +++ b/kernel/riscv.h @@ -261,7 +261,6 @@ r_time() static inline void intr_on() { - w_sie(r_sie() | SIE_SEIE | SIE_STIE | SIE_SSIE); w_sstatus(r_sstatus() | SSTATUS_SIE); } diff --git a/kernel/spinlock.c b/kernel/spinlock.c index f192832..9840302 100644 --- a/kernel/spinlock.c +++ b/kernel/spinlock.c @@ -72,13 +72,12 @@ release(struct spinlock *lk) } // Check whether this cpu is holding the lock. +// Interrupts must be off. int holding(struct spinlock *lk) { int r; - push_off(); r = (lk->locked && lk->cpu == mycpu()); - pop_off(); return r; } @@ -103,9 +102,9 @@ pop_off(void) struct cpu *c = mycpu(); if(intr_get()) panic("pop_off - interruptible"); - c->noff -= 1; - if(c->noff < 0) + if(c->noff < 1) panic("pop_off"); + c->noff -= 1; if(c->noff == 0 && c->intena) intr_on(); } diff --git a/kernel/start.c b/kernel/start.c index 203c5e6..4eb6c2d 100644 --- a/kernel/start.c +++ b/kernel/start.c @@ -36,6 +36,7 @@ start() // delegate all interrupts and exceptions to supervisor mode. w_medeleg(0xffff); w_mideleg(0xffff); + w_sie(r_sie() | SIE_SEIE | SIE_STIE | SIE_SSIE); // ask for clock interrupts. timerinit(); diff --git a/kernel/trap.c b/kernel/trap.c index ca732f2..5e11e4b 100644 --- a/kernel/trap.c +++ b/kernel/trap.c @@ -129,7 +129,6 @@ usertrapret(void) // interrupts and exceptions from kernel code go here via kernelvec, // on whatever the current kernel stack is. -// must be 4-byte aligned to fit in stvec. void kerneltrap() { @@ -189,9 +188,13 @@ devintr() uartintr(); } else if(irq == VIRTIO0_IRQ){ virtio_disk_intr(); + } else if(irq){ + printf("unexpected interrupt irq=%d\n", irq); } - plic_complete(irq); + if(irq) + plic_complete(irq); + return 1; } else if(scause == 0x8000000000000001L){ // software interrupt from a machine-mode timer interrupt, |