From cd956f5aa6822fd31ee2d721d0e9d244685cb1ef Mon Sep 17 00:00:00 2001 From: Alexandre Mergnat Date: Mon, 8 Mar 2021 12:14:42 -0500 Subject: [PATCH] target/riscv: Fix pmp NA4 implementation The end address calculation for NA4 mode is wrong because the address used isn't shifted. It doesn't watch 4 bytes but a huge range because the end address calculation is wrong. The solution is to use the shifted address calculated for start address variable. Modifications are tested on Zephyr OS userspace test suite which works for other RISC-V boards (E31 and E34 core). Backports cfad709bceb629a4ebeb5d8a3acd1871b9a6436b --- qemu/target/riscv/pmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu/target/riscv/pmp.c b/qemu/target/riscv/pmp.c index e385f6f7..1878698f 100644 --- a/qemu/target/riscv/pmp.c +++ b/qemu/target/riscv/pmp.c @@ -181,7 +181,7 @@ static void pmp_update_rule(CPURISCVState *env, uint32_t pmp_index) case PMP_AMATCH_NA4: sa = this_addr << 2; /* shift up from [xx:0] to [xx+2:2] */ - ea = (this_addr + 4u) - 1u; + ea = (sa + 4u) - 1u; break; case PMP_AMATCH_NAPOT: