From 93922b65e3d638feae9dc71c1c27bab911747949 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:04 -0300 Subject: [PATCH] feat(cpu): implement format 6 THUMB instructions --- src/cpu.zig | 7 +++++++ src/cpu/thumb/format6.zig | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/cpu/thumb/format6.zig diff --git a/src/cpu.zig b/src/cpu.zig index 6292cde..284647f 100644 --- a/src/cpu.zig +++ b/src/cpu.zig @@ -22,6 +22,7 @@ const softwareInterrupt = @import("cpu/arm/software_interrupt.zig").softwareInte // THUMB Instruction Groups const format3 = @import("cpu/thumb/format3.zig").format3; const format5 = @import("cpu/thumb/format5.zig").format5; +const format6 = @import("cpu/thumb/format6.zig").format6; const format12 = @import("cpu/thumb/format12.zig").format12; pub const ArmInstrFn = fn (*Arm7tdmi, *Bus, u32) void; @@ -330,6 +331,12 @@ fn thumbPopulate() [0x400]ThumbInstrFn { lut[i] = format5(op, h1, h2); } + if (i >> 5 & 0x1F == 0b01001) { + const rd = i >> 2 & 0x7; + + lut[i] = format6(rd); + } + if (i >> 6 & 0xF == 0b1010) { const isSP = i >> 5 & 1 == 1; const rd = i >> 2 & 0x7; diff --git a/src/cpu/thumb/format6.zig b/src/cpu/thumb/format6.zig new file mode 100644 index 0000000..e90be49 --- /dev/null +++ b/src/cpu/thumb/format6.zig @@ -0,0 +1,16 @@ +const std = @import("std"); + +const Bus = @import("../../Bus.zig"); +const Arm7tdmi = @import("../../cpu.zig").Arm7tdmi; +const InstrFn = @import("../../cpu.zig").ThumbInstrFn; + +pub fn format6(comptime rd: u3) InstrFn { + return struct { + fn inner(cpu: *Arm7tdmi, bus: *Bus, opcode: u16) void { + const offset = (opcode & 0xFF) << 2; + + // FIXME: Should this overflow? + cpu.r[rd] = bus.read32((cpu.fakePC() & 0xFFFF_FFFC) + offset); + } + }.inner; +}