From 1ac193c50666994a2b733ba853521c34b6fbfa58 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:06 -0300 Subject: [PATCH] fix(cpu): don't ignore 11th bit of THUMB BL offset --- src/cpu/thumb/format19.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpu/thumb/format19.zig b/src/cpu/thumb/format19.zig index 86efb03..4fc5513 100644 --- a/src/cpu/thumb/format19.zig +++ b/src/cpu/thumb/format19.zig @@ -9,7 +9,7 @@ pub fn format19(comptime is_low: bool) InstrFn { return struct { fn inner(cpu: *Arm7tdmi, _: *Bus, opcode: u16) void { // BL - const offset = opcode & 0x3FF; + const offset = opcode & 0x7FF; if (is_low) { // Instruction 2 @@ -19,7 +19,7 @@ pub fn format19(comptime is_low: bool) InstrFn { cpu.r[14] = old_pc | 1; } else { // Instruction 1 - cpu.r[14] = (cpu.r[15] + 2) + (u32SignExtend(11, @as(u32, offset)) << 12); + cpu.r[14] = (cpu.r[15] + 2) +% (u32SignExtend(11, @as(u32, offset)) << 12); } } }.inner;