riscvarchive / riscv-qemu

QEMU with RISC-V (RV64G, RV32G) Emulation Support
384 stars 154 forks source link

riscv pmp issues (address error) #169

Closed wxjstz closed 5 years ago

wxjstz commented 5 years ago

I try to test PMP by qemu/riscv-probe. But I found this issues.

I try to monitor all PMP check (dump info in function pmp_hart_has_privs).

When load/store at 0x80000000+, address will be error. It look like be signed-extension.

etc: When I try to access 0x80000000, the actual access is 0xffffffff80000000

wxjstz commented 5 years ago

This's not issues of qemu. It's a bug of my test case.

#define CHECK_PMP_R8(addr)  asm volatile("lb zero,0(%0)"::"r"(addr))

The correct one should be:

#define CHECK_PMP_R8(addr)  asm volatile("lb zero,0(%0)"::"r"((void*)addr))
michaeljclark commented 5 years ago

Okay

Do note I’ve recently pushed changes to the qemu-for-testing branch. The branch has squashed changes so you may want to do git fetch and get reset instead of git pull. The method has been renamed to pmp_has_access and there is now tracing support so you can check your rules.

You can add the following (or subset) to your qemu command line

-d trace:pmpcfg_csr_read,trace:pmpcfg_csr_write,trace:pmpaddr_csr_read,trace:pmpaddr_csr_write,trace:pmp_has_access,trace:pmp_rule_match