feat(cpu): implement format 6 THUMB instructions

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-01-29 01:17:11 -04:00
parent 95efb3f35d
commit cfbd292edc
2 changed files with 23 additions and 0 deletions

View File

@ -22,6 +22,7 @@ const softwareInterrupt = @import("cpu/arm/software_interrupt.zig").softwareInte
// THUMB Instruction Groups // THUMB Instruction Groups
const format3 = @import("cpu/thumb/format3.zig").format3; const format3 = @import("cpu/thumb/format3.zig").format3;
const format5 = @import("cpu/thumb/format5.zig").format5; const format5 = @import("cpu/thumb/format5.zig").format5;
const format6 = @import("cpu/thumb/format6.zig").format6;
const format12 = @import("cpu/thumb/format12.zig").format12; const format12 = @import("cpu/thumb/format12.zig").format12;
pub const ArmInstrFn = fn (*Arm7tdmi, *Bus, u32) void; pub const ArmInstrFn = fn (*Arm7tdmi, *Bus, u32) void;
@ -330,6 +331,12 @@ fn thumbPopulate() [0x400]ThumbInstrFn {
lut[i] = format5(op, h1, h2); 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) { if (i >> 6 & 0xF == 0b1010) {
const isSP = i >> 5 & 1 == 1; const isSP = i >> 5 & 1 == 1;
const rd = i >> 2 & 0x7; const rd = i >> 2 & 0x7;

16
src/cpu/thumb/format6.zig Normal file
View File

@ -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;
}