From 28361e8b7dea9c0462a7abce51ec556873746a46 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:16 -0300 Subject: [PATCH] fix: implement the same LDRSH logic as THUMB LDRSH --- src/cpu/arm/half_signed_data_transfer.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cpu/arm/half_signed_data_transfer.zig b/src/cpu/arm/half_signed_data_transfer.zig index ba97d62..e30570a 100644 --- a/src/cpu/arm/half_signed_data_transfer.zig +++ b/src/cpu/arm/half_signed_data_transfer.zig @@ -45,7 +45,13 @@ pub fn halfAndSignedDataTransfer(comptime P: bool, comptime U: bool, comptime I: }, 0b11 => { // LDRSH - result = util.u32SignExtend(16, bus.read16(address & 0xFFFF_FFFE)); + const value = if (address & 1 == 1) blk: { + break :blk util.u32SignExtend(8, bus.read8(address)); + } else blk: { + break :blk util.u32SignExtend(16, bus.read16(address)); + }; + + result = std.math.rotr(u32, value, 8 * (address & 1)); }, 0b00 => unreachable, // SWP }