From 5f4d891b4251c1bde44a3f9238c07f41f2a6741b Mon Sep 17 00:00:00 2001 From: LekKit <50500857+LekKit@users.noreply.github.com> Date: Tue, 5 Mar 2024 21:39:50 +0200 Subject: [PATCH] plic: Clear hart interrupt before consuming IRQ bits --- src/devices/plic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/devices/plic.c b/src/devices/plic.c index 273722473..be935aa85 100644 --- a/src/devices/plic.c +++ b/src/devices/plic.c @@ -121,6 +121,7 @@ static uint32_t plic_claim_irq(plic_ctx_t* plic, uint32_t ctx) size_t nirqs = 0; uint32_t claimed_irq = 0; uint32_t max_prio = 0; + riscv_interrupt_clear(vector_at(plic->machine->harts, CTX_HARTID(ctx)), CTX_IRQ_PRIO(ctx)); for (size_t i=0; ipending[i]); // Only enabled interrupts will pass @@ -147,8 +148,8 @@ static uint32_t plic_claim_irq(plic_ctx_t* plic, uint32_t ctx) return 0; } } - if (nirqs <= 1 || max_prio <= atomic_load_uint32(&plic->threshold[ctx])) { - riscv_interrupt_clear(vector_at(plic->machine->harts, CTX_HARTID(ctx)), CTX_IRQ_PRIO(ctx)); + if (nirqs > 1 && max_prio > atomic_load_uint32(&plic->threshold[ctx])) { + riscv_interrupt(vector_at(plic->machine->harts, CTX_HARTID(ctx)), CTX_IRQ_PRIO(ctx)); } return claimed_irq; }