From a7ca51b3a52df8d692fb8afb816c6d1d356a80f4 Mon Sep 17 00:00:00 2001 From: Kuan-Wei Chiu Date: Thu, 11 Dec 2025 15:16:36 +0000 Subject: [PATCH] Fix PLIC priority tie-breaking to favor lowest ID The RISC-V PLIC specification states that "if two or more pending interrupts have the same priority, the one with the lowest ID has the highest priority." The previous implementation used ilog2(), which identifies the most significant bit (highest ID). Replace it with rv_ctz() to select the least significant bit (lowest ID), ensuring compliance with the specification's arbitration rule. --- src/devices/plic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/plic.c b/src/devices/plic.c index 06e47acf9..b1462cea8 100644 --- a/src/devices/plic.c +++ b/src/devices/plic.c @@ -44,7 +44,7 @@ uint32_t plic_read(plic_t *plic, const uint32_t addr) { uint32_t intr_candidate = plic->ip & plic->ie; if (intr_candidate) { - plic_read_val = ilog2(intr_candidate); + plic_read_val = rv_ctz(intr_candidate); plic->ip &= ~(1U << (plic_read_val)); } break;