Skip to content

Commit

Permalink
riscv_hart: Omit PC increment for userland traps
Browse files Browse the repository at this point in the history
  • Loading branch information
LekKit authored Jan 13, 2024
1 parent c09716d commit cc3466c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/riscv_hart.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ rvvm_addr_t riscv_hart_run_userland(rvvm_hart_t* vm)
#ifdef USE_SJLJ
setjmp(vm->unwind);
#endif
if (atomic_load_uint32(&vm->wait_event)) {
riscv_run_till_event(vm);
riscv_run_till_event(vm);
if (vm->trap) {
vm->registers[REGISTER_PC] = vm->csr.tvec[PRIVILEGE_USER];
vm->trap = false;
}
return vm->csr.cause[PRIVILEGE_USER];
}
Expand Down Expand Up @@ -205,6 +207,7 @@ void riscv_trap(rvvm_hart_t* vm, bitcnt_t cause, maxlen_t tval)
// Defer usermode trap
vm->csr.cause[PRIVILEGE_USER] = cause;
vm->csr.tval[PRIVILEGE_USER] = tval;
vm->csr.tvec[PRIVILEGE_USER] = vm->registers[REGISTER_PC];
} else {
// Target privilege mode
uint8_t priv = PRIVILEGE_MACHINE;
Expand Down

0 comments on commit cc3466c

Please sign in to comment.