From 4b43dcd2565958b3a3a3d7a08d71d16e0264ee29 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:11:48 -0300 Subject: [PATCH] fix(cpu): improve LDR/STR write-back logic --- src/cpu/half_signed_data_transfer.zig | 13 ++++++------- src/cpu/single_data_transfer.zig | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/cpu/half_signed_data_transfer.zig b/src/cpu/half_signed_data_transfer.zig index 95a9bfe..7adfb2a 100644 --- a/src/cpu/half_signed_data_transfer.zig +++ b/src/cpu/half_signed_data_transfer.zig @@ -34,18 +34,17 @@ pub fn comptimeHalfSignedDataTransfer(comptime P: bool, comptime U: bool, compti }, 0b01 => { // LDRH - const halfword = bus.read16(address); - cpu.r[rd] = @as(u32, halfword); + cpu.r[rd] = bus.read16(address); }, 0b10 => { // LDRSB - const byte = bus.read8(address); - cpu.r[rd] = util.u32SignExtend(8, @as(u32, byte)); + cpu.r[rd] = util.u32SignExtend(8, @as(u32, bus.read8(address))); + std.debug.panic("TODO: Affect the CPSR", .{}); }, 0b11 => { // LDRSH - const halfword = bus.read16(address); - cpu.r[rd] = util.u32SignExtend(16, @as(u32, halfword)); + cpu.r[rd] = util.u32SignExtend(16, @as(u32, bus.read16(address))); + std.debug.panic("TODO: Affect the CPSR", .{}); }, } } else { @@ -58,7 +57,7 @@ pub fn comptimeHalfSignedDataTransfer(comptime P: bool, comptime U: bool, compti } address = modified_base; - if (W and P) cpu.r[rn] = address; + if (W and P or !P) cpu.r[rn] = address; } }.halfSignedDataTransfer; } diff --git a/src/cpu/single_data_transfer.zig b/src/cpu/single_data_transfer.zig index 2febda2..acef639 100644 --- a/src/cpu/single_data_transfer.zig +++ b/src/cpu/single_data_transfer.zig @@ -40,7 +40,7 @@ pub fn comptimeSingleDataTransfer(comptime I: bool, comptime P: bool, comptime U } address = modified_base; - if (W and P or !W) cpu.r[rn] = address; + if (W and P or !P) cpu.r[rn] = address; // TODO: W-bit forces non-privledged mode for the transfer }