Skip to content

Commit

Permalink
Handle misalignment properly in jump-link instruction
Browse files Browse the repository at this point in the history
As per the specifications, if a branch or jump instruction
is found to have an instruction-address-misaligned exception,
it indicates that the `rd` would not be updated.

To maintain simplicity, the `do_jump` function will continue
to handle branch instructions, which modifications will be
made exclusively to the `op_jump_link` function.
  • Loading branch information
chiangkd committed Jul 22, 2023
1 parent 3d92e57 commit c5786ab
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 c5786ab

Please sign in to comment.