diff --git a/Makefile b/Makefile index ba7a6fb..7229d5e 100644 --- a/Makefile +++ b/Makefile @@ -104,7 +104,7 @@ $U/_forktest: $U/forktest.o $(ULIB) $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $U/_forktest $U/forktest.o $U/ulib.o $U/usys.o $(OBJDUMP) -S $U/_forktest > $U/forktest.asm -mkfs/mkfs: mkfs/mkfs.c $K/fs.h +mkfs/mkfs: mkfs/mkfs.c $K/fs.h $K/param.h gcc -Werror -Wall -I. -o mkfs/mkfs mkfs/mkfs.c # Prevent deletion of intermediate files, e.g. cat.o, after first build, so 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, diff --git a/user/usertests.c b/user/usertests.c index db9f680..eb10ee2 100644 --- a/user/usertests.c +++ b/user/usertests.c @@ -2105,9 +2105,9 @@ run(void f(char *), char *s) { } else { wait(&xstatus); if(xstatus != 0) - printf("FAILED\n", s); + printf("FAILED\n"); else - printf("OK\n", s); + printf("OK\n"); return xstatus == 0; } }