Skip to content

Commit

Permalink
Handle misalignment properly in jump-link instruction (sysprog21#20)
Browse files Browse the repository at this point in the history
As per the ISA specs, when a branch/jump instruction encounters an
instruction-address-misaligned exception, it signifies that the rd
register would not be updated.

To maintain simplicity, do_jump() will continue handling branch
instructions, while exclusive modifications will be made to
op_jump_link().
  • Loading branch information
chiangkd authored Jul 22, 2023
1 parent 3d92e57 commit ec5824d
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 ec5824d

Please sign in to comment.