From c4a9c5ee5e3c3418ec91b9fca4ce4ff4340102e5 Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Thu, 13 Jun 2024 03:54:46 +0530 Subject: [PATCH] cpu: align PC every step Signed-off-by: Amneesh Singh --- src/cpu/cpu.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cpu/cpu.cc b/src/cpu/cpu.cc index 6e58909..1b73b2c 100644 --- a/src/cpu/cpu.cc +++ b/src/cpu/cpu.cc @@ -1,6 +1,7 @@ #include "cpu/cpu.hh" #include "cpu/arm/instruction.hh" #include "cpu/thumb/instruction.hh" +#include "util/bits.hh" #include "util/log.hh" #include #include @@ -131,8 +132,12 @@ Cpu::chg_mode(const Mode to) { void Cpu::step() { - // Current instruction is two instructions behind PC + // halfword align + rst_bit(pc, 0); if (cpsr.state() == State::Arm) { + // word align + rst_bit(pc, 1); + // Current instruction is two instructions behind PC uint32_t cur_pc = pc - 2 * arm::INSTRUCTION_SIZE; arm::Instruction instruction(bus->read_word(cur_pc));