riscvarchive / riscv-qemu

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

Fix bug to read/write pmpcfg csr #162

Closed wxjstz closed 5 years ago

wxjstz commented 5 years ago
    for (i = 0; i < sizeof(target_ulong); i++) {
        cfg_val = (val >> 8 * i)  & 0xff;
        pmp_write_cfg(env, (reg_index * sizeof(target_ulong)) + i,
            cfg_val);
    }

RV64 PMP config register is pmpcfg0/pmpcfg2 not pmpcfg0/pmpcfg1. So under RV64, needs to convert the register index to 0/1. If not do that will overflow. reg_index * sizeof(target_ulong) + i will between [0, 8) / [16, 24)