From 9e6b1219189ac5e2767dbb37cbea93ea7de2bc0e Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Tue, 11 Jun 2024 23:22:34 +0530 Subject: [PATCH] cpu/thumb: fix pc relative load Signed-off-by: Amneesh Singh --- src/cpu/thumb/exec.cc | 1 + tests/cpu/thumb/exec.cc | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cpu/thumb/exec.cc b/src/cpu/thumb/exec.cc index b8bf328..47b92fe 100644 --- a/src/cpu/thumb/exec.cc +++ b/src/cpu/thumb/exec.cc @@ -189,6 +189,7 @@ Instruction::exec(Cpu& cpu) { }, [&cpu](PcRelativeLoad& data) { uint32_t pc = cpu.pc; + rst_bit(pc, 0); rst_bit(pc, 1); cpu.gpr[data.rd] = cpu.bus->read_word(pc + data.word); diff --git a/tests/cpu/thumb/exec.cc b/tests/cpu/thumb/exec.cc index 6227966..ac68cb4 100644 --- a/tests/cpu/thumb/exec.cc +++ b/tests/cpu/thumb/exec.cc @@ -1,6 +1,5 @@ #include "cpu/cpu-fixture.hh" #include "cpu/thumb/instruction.hh" -#include "util/bits.hh" #include using namespace matar; @@ -531,8 +530,9 @@ TEST_CASE_METHOD(CpuFixture, "PC Relative Load", TAG) { InstructionData data = PcRelativeLoad{ .word = 0x578, .rd = 0 }; setr(15, 0x3003FD5); - // 0x3003FD5 + 0x578 - bus.write_word(0x300454D, 489753492); + // resetting bit 0 for 0x3003FD5, we get 0x3003FD4 + // 0x3003FD4 + 0x578 + bus.write_word(0x300454C, 489753492); CHECK(getr(0) == 0); exec(data);