target/riscv: fix pmp implementation
PATCH 1/1 target/riscv: fix pmp implementation
The end address calculation for NA4 mode is wrong because the address used isn't shifted.
That imply all NA4 setup are not applied by the PMP.
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).
--- target/riscv/pmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/pmp.c +1 -1
@@ -171,7 +171,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 :
Signature · 1 line
2.17.1
Quoted 5 lines · Alexandre Mergnat
The end address calculation for NA4 mode is wrong because the address used isn't shifted.
That imply all NA4 setup are not applied by the PMP.
I'm not sure what you mean here, can you clarify this?
Quoted 8 lines
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).
Signed-off-by Alexandre Mergnat <[email protected]>
Otherwise:
Alistair
Quoted 21 lines
--- target/riscv/pmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/riscv/pmp.c +1
-2@@ -171,7 +171,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 : --2.17.1
Quoted 9 lines · Alistair Francis
Quoted 5 lines · Alexandre Mergnat
The end address calculation for NA4 mode is wrong because the address used isn't shifted.
That imply all NA4 setup are not applied by the PMP.
I'm not sure what you mean here, can you clarify this?
I'm just saying NA4 configuration doesn't work properly on QEMU (It doesn't watch 4byte but a huge range)
because the end address calculation is wrong.
Quoted 37 lines
Quoted 9 lines
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).
Signed-off-by Alexandre Mergnat <[email protected]>Otherwise:
Reviewed-by Alistair Francis <[email protected]>Alistair
Quoted 21 lines
--- target/riscv/pmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/riscv/pmp.c +1
-2@@ -171,7 +171,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 : --2.17.1
Quoted 8 lines · Alexandre Mergnat
Quoted 6 lines · Alistair Francis
Quoted 4 lines · Alexandre Mergnat
The end address calculation for NA4 mode is wrong because the address used isn't shifted.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
That imply all NA4 setup are not applied by the PMP.
I'm not sure what you mean here, can you clarify this?
I'm just saying NA4 configuration doesn't work properly on QEMU (It doesn't watch 4byte but a huge range)
because the end address calculation is wrong.
Ok, I replaced the original sentence with:
It doesn't watch 4 bytes but a huge range because the end address calculation is wrong.
and changed the title to: target/riscv: Fix pmp NA4 implementation
and applied it to the RISC-V tree.
Alistair
Quoted 38 lines
Quoted 38 lines
Quoted 10 lines
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).
Signed-off-by Alexandre Mergnat <[email protected]>Otherwise:
Reviewed-by Alistair Francis <[email protected]>Alistair
Quoted 21 lines
--- target/riscv/pmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/riscv/pmp.c +1
-2@@ -171,7 +171,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 : --2.17.1