Skip to contentSkip to conversation

target/riscv/pmp.c: Fix PMP NAPOT decoding bug

PATCH New Dayeol Lee 1 participant 1 message Jul 17, 2018 RISC-V

lore
Share & tools
lore

Dayeol Lee

author
#0 lore raw

PATCH 1/1 target/riscv/pmp.c: Fix PMP NAPOT decoding bug

According to the RISC-V priv. v1.10 ISA document,
pmpaddr register stores (base_addr | (size/2 - 1)) >> 2 for a NAPOT-encoded address.
However, the current code decodes (base_addr | (size - 1)) >> 3 which leads to a wrong base address and size.

---
 target/riscv/pmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/pmp.c +1 -1
index f432f3b..c4c6b09 100644
@@ -138,7 +138,7 @@ static void pmp_decode_napot(target_ulong a, target_ulong *sa, target_ulong *ea)
         return;
     } else {
         target_ulong t1 = ctz64(~a);
-        target_ulong base = (a & ~(((target_ulong)1 << t1) - 1)) << 3;
+        target_ulong base = (a & ~(((target_ulong)1 << t1) - 1)) << 2;
         target_ulong range = ((target_ulong)1 << (t1 + 3)) - 1;
         *sa = base;
         *ea = base + range;
Signature · 1 line
2.7.4