riscv-software-src / riscv-tests

Other
902 stars 463 forks source link

Question about rv32ui-v tests using `sret` in M-mode #593

Closed zhc7 closed 1 week ago

zhc7 commented 1 week ago

Hi, I'm new to risc-v. I've noticed that rv32ui-v tests call vm_boot at the beginning, and then vm_boot calls pop_tf. An sret instruction appears at the end of pop_tf, but the program should still be in M-mode, because there isn't an mret, isn't this an illegal instruction? I might have missed something. Really appreciated if anyone can help.

aswaterman commented 1 week ago

sret is legal in M-mode. It does the same thing it does in S-mode (it changes the mode to S or U, based upon sstatus.SPP).

zhc7 commented 1 week ago

Thank you for clarifying that!