summaryrefslogtreecommitdiff
path: root/src/instructions/rvi.rs
diff options
context:
space:
mode:
authortaitep <taitep@taitep.se>2025-12-21 19:36:25 +0100
committertaitep <taitep@taitep.se>2025-12-21 19:36:25 +0100
commit6c39a5eef270e160f9954dc8eac99ce53e8423c9 (patch)
tree37a48d9899b4a6284cd99e6a4510bc3f429ba114 /src/instructions/rvi.rs
parent944ed573c6f69e34c56179f98efd71b05e2bb02b (diff)
Implement JALR, fix JAL, change how some stuff in instructions.rs is expressed
Diffstat (limited to 'src/instructions/rvi.rs')
-rw-r--r--src/instructions/rvi.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/instructions/rvi.rs b/src/instructions/rvi.rs
index 5c06b62..239ae98 100644
--- a/src/instructions/rvi.rs
+++ b/src/instructions/rvi.rs
@@ -117,15 +117,21 @@ pub fn lui(core: &mut Core, instr: Instruction) -> InstructionResult {
InstructionResult::Normal
}
+pub fn auipc(core: &mut Core, instr: Instruction) -> InstructionResult {
+ core.reg_write(instr.rd(), core.pc.wrapping_add(instr.imm_u()));
+ core.advance_pc();
+ InstructionResult::Normal
+}
+
pub fn jal(core: &mut Core, instr: Instruction) -> InstructionResult {
- core.reg_write(instr.rd(), core.pc);
+ core.reg_write(instr.rd(), core.pc.wrapping_add(4));
core.pc = core.pc.wrapping_add(instr.imm_j());
InstructionResult::Normal
}
-pub fn auipc(core: &mut Core, instr: Instruction) -> InstructionResult {
- core.reg_write(instr.rd(), core.pc.wrapping_add(instr.imm_u()));
- core.advance_pc();
+pub fn jalr(core: &mut Core, instr: Instruction) -> InstructionResult {
+ core.reg_write(instr.rd(), core.pc.wrapping_add(4));
+ core.pc = core.reg_read(instr.rs1()).wrapping_add(instr.imm_i());
InstructionResult::Normal
}