cpu: bring back the flush pipeline method

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2024-06-21 01:56:25 +05:30
parent f510a54d40
commit 514aeb7d44
4 changed files with 23 additions and 19 deletions

View File

@@ -98,7 +98,21 @@ class Cpu {
void advance_pc_arm(); void advance_pc_arm();
void advance_pc_thumb(); void advance_pc_thumb();
void flush_pipeline(); template<State S>
void flush_pipeline() {
if constexpr (S == State::Arm) {
opcodes[0] = bus->read_word(pc, CpuAccess::NonSequential);
advance_pc_arm();
opcodes[1] = bus->read_word(pc, CpuAccess::Sequential);
advance_pc_arm();
} else {
opcodes[0] = bus->read_halfword(pc, CpuAccess::NonSequential);
advance_pc_thumb();
opcodes[1] = bus->read_halfword(pc, CpuAccess::Sequential);
advance_pc_thumb();
}
next_access = CpuAccess::Sequential;
}
#ifdef GDB_DEBUG #ifdef GDB_DEBUG
friend class GdbRsp; friend class GdbRsp;

View File

@@ -705,13 +705,9 @@ Cpu::exec(arm::Instruction& instruction) {
} }, } },
instruction.data); instruction.data);
if (is_flushed) { if (is_flushed)
opcodes[0] = bus->read_word(pc, CpuAccess::NonSequential); flush_pipeline<State::Arm>();
advance_pc_arm(); else
opcodes[1] = bus->read_word(pc, CpuAccess::Sequential);
advance_pc_arm();
next_access = CpuAccess::Sequential;
} else
advance_pc_arm(); advance_pc_arm();
} }
} }

View File

@@ -14,7 +14,7 @@ Cpu::Cpu(std::shared_ptr<Bus> bus) noexcept
glogger.info("CPU successfully initialised"); glogger.info("CPU successfully initialised");
// PC always points to two instructions ahead // PC always points to two instructions ahead
flush_pipeline(); flush_pipeline<State::Arm>();
} }
/* change modes */ /* change modes */
@@ -163,12 +163,10 @@ Cpu::advance_pc_arm() {
rst_bit(pc, 1); rst_bit(pc, 1);
pc += arm::INSTRUCTION_SIZE; pc += arm::INSTRUCTION_SIZE;
}; };
void void
Cpu::advance_pc_thumb() { Cpu::advance_pc_thumb() {
rst_bit(pc, 0); rst_bit(pc, 0);
pc += thumb::INSTRUCTION_SIZE; pc += thumb::INSTRUCTION_SIZE;
} }
void
Cpu::flush_pipeline() {};
} }

View File

@@ -604,13 +604,9 @@ Cpu::exec(thumb::Instruction& instruction) {
} }, } },
instruction.data); instruction.data);
if (is_flushed) { if (is_flushed)
opcodes[0] = bus->read_halfword(pc, CpuAccess::NonSequential); flush_pipeline<State::Thumb>();
advance_pc_thumb(); else
opcodes[1] = bus->read_halfword(pc, CpuAccess::Sequential);
advance_pc_thumb();
next_access = CpuAccess::Sequential;
} else
advance_pc_thumb(); advance_pc_thumb();
} }
} }