semantic: 0.907 mistranslation: 0.879 other: 0.869 assembly: 0.855 instruction: 0.854 socket: 0.832 device: 0.813 graphic: 0.805 KVM: 0.794 vnc: 0.737 boot: 0.724 network: 0.710 RISC-V priviledged instruction error Hello when performing an MRET with MPP set to something else than 0b11 in MSTATUS, 'Invalid Instruction' exception will be triggered. The problem appeared in code after version 5.2.0.
  # setup interrupt handling for monitor mode
  la t0, entry_loop
  la t1, entry_trap
  li t2, 0x888
  li t3, 0x1880 # MPP in MSTATUS selects to which mode to return & MPIE selects if to enable interrupts after MRET
  csrw mepc, t0
  csrw mtvec, t1
  csrs mie, t2
  csrs mstatus, t3

  # if supervisor mode not supported, then loop forever
  csrr t0, misa
  li t1, 0x40000
  and t2, t1, t0
  beqz t2, 1f

  # setup interrupt i& exception delegation for supervisor mode
  li t0, 0xc0000000 # 3 GiB (entry address of supervisor)
  li t1, 0x1000
  #li t2, 0x300 # bit 8 & 9 is for ecall from user & supervisor mode
  #li t3, 0x222
  csrw mepc, t0
  csrc mstatus, t1
  #csrs medeleg, t2
  #csrs mideleg, t3

  # pass mhartid as first parameter to supervisor
  csrr a0, mhartid

1:
  mret
I'm guessing that this is a bug in your guest as it hasn't configured PMP regions. From the RISC-V spec: " If no PMP entry matches an M-mode access, the access succeeds. If no PMP entry matches an S-mode or U-mode access, but at least one PMP entry is implemented, the access fails. " Confusingly implemented here means implemented in hardware, not just configured. You can check this by reverting this QEMU commit: commit d102f19a2085ac931cb998e6153b73248cca49f1 Author: Atish Patra