diff options
| author | taitep <taitep@taitep.se> | 2025-12-23 18:31:04 +0100 |
|---|---|---|
| committer | taitep <taitep@taitep.se> | 2025-12-23 18:31:04 +0100 |
| commit | 23392a55dff889bad89dcb495390fde88e3bfb69 (patch) | |
| tree | 616c28fea8abd5dda8232b38c59f8020af99ac88 /src/instructions/rvi | |
| parent | f38114dbd7a897a8048bf27446c75f12b994249f (diff) | |
Implement SH
Diffstat (limited to 'src/instructions/rvi')
| -rw-r--r-- | src/instructions/rvi/mem.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/instructions/rvi/mem.rs b/src/instructions/rvi/mem.rs index d065e8d..47eb01d 100644 --- a/src/instructions/rvi/mem.rs +++ b/src/instructions/rvi/mem.rs @@ -86,6 +86,26 @@ pub fn lw(core: &mut Core, instr: Instruction) -> InstructionResult { } } +pub fn sh(core: &mut Core, instr: Instruction) -> InstructionResult { + let addr = core.reg_read(instr.rs1()).wrapping_add(instr.imm_s()); + + if !addr.is_multiple_of(std::mem::size_of::<HWord>() as Addr) { + return InstructionResult::Exception(()); + } + + let page = (addr / 4096) as PageNum; + let offset = (addr / 2 & ((4096 / 2 as Addr) - 1)) as u16; + let value = core.reg_read(instr.rs2()) as HWord; + + match core.mem.write_hword(page, offset, value) { + Ok(_) => { + core.advance_pc(); + InstructionResult::Normal + } + Err(_) => InstructionResult::Exception(()), + } +} + pub fn lh(core: &mut Core, instr: Instruction) -> InstructionResult { let addr = core.reg_read(instr.rs1()).wrapping_add(instr.imm_i()); |
