Skip to content

Commit

Permalink
Fix rd update when the jump fail
Browse files Browse the repository at this point in the history
From spec, an instruction-address-misaligned exception is
reported on the branch or jump instruction, implying rd would not be updated.

For simplicity, I keep `do_jump` function to handle branch instruction,
and modify only `op_jump_link` function.

Reference: [spec](https://riscv.org/technical/specifications/) (section 2.2)
  • Loading branch information
chiangkd committed Jul 22, 2023
1 parent 3d92e57 commit 0edceca
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,12 @@ static void do_jump(vm_t *vm, uint32_t addr)

static void op_jump_link(vm_t *vm, uint32_t insn, uint32_t addr)
{
/* TODO: If the jump fails (misalign), shall rd have to be updated? */
set_dest(vm, insn, vm->pc);
do_jump(vm, addr);
if (unlikely(addr & 0b11))
vm_set_exception(vm, RV_EXC_PC_MISALIGN, addr);
else {
set_dest(vm, insn, vm->pc);
vm->pc = addr;
}
}

#define AMO_OP(STORED_EXPR) \
Expand Down

0 comments on commit 0edceca

Please sign in to comment.