From d8bd6da563dcbe0ac3d7c19fc666938e7ab1ced5 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:14 -0300 Subject: [PATCH] fix: resolve decoding mixup in THUMB format 8 instructions --- src/cpu/thumb/data_transfer.zig | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cpu/thumb/data_transfer.zig b/src/cpu/thumb/data_transfer.zig index 6d09719..3b18d2b 100644 --- a/src/cpu/thumb/data_transfer.zig +++ b/src/cpu/thumb/data_transfer.zig @@ -28,26 +28,28 @@ pub fn format78(comptime op: u2, comptime T: bool) InstrFn { const address = cpu.r[rb] + cpu.r[ro]; if (T) { + // Format 8 switch (op) { 0b00 => { // STRH bus.write16(address & 0xFFFF_FFFE, @truncate(u16, cpu.r[rd])); }, 0b01 => { + // LDSB + cpu.r[rd] = u32SignExtend(8, @as(u32, bus.read8(address))); + }, + 0b10 => { // LDRH const value = bus.read16(address & 0xFFFF_FFFE); cpu.r[rd] = std.math.rotr(u32, @as(u32, value), 8 * (address & 1)); }, - 0b10 => { - // LDSB - cpu.r[rd] = u32SignExtend(8, @as(u32, bus.read8(address))); - }, 0b11 => { // LDSH cpu.r[rd] = u32SignExtend(16, @as(u32, bus.read16(address & 0xFFFF_FFFE))); }, } } else { + // Format 7 switch (op) { 0b00 => { // STR