riscvarchive / riscv-qemu

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

can't execute rdtime instruction #186

Closed LoveZJT closed 5 years ago

LoveZJT commented 5 years ago

Why qemu-system-riscv32 executing rdtime instruction will cause illegal instruction exception, while rdcycle and rdinstret are right.

jim-wilson commented 5 years ago

I believe that on rocket, rdtime traps into machine mode which then emulates the instruction. I know that this is true for most if not all SiFive cores. So qemu is just faithfully implementing exactly what the hardware does. SiFive platforms have a MMIO timer register that you may be able to read directly, which is faster than using rdtime, because rdtime traps.