#pragma once #include "bus.hh" #include "instruction.hh" #include "psr.hh" #include using std::size_t; class Cpu { public: Cpu(Bus& bus); void step(); private: static constexpr uint8_t GPR_COUNT = 16; static constexpr uint8_t GPR_FIQ_FIRST = 8; static constexpr uint8_t GPR_SVC_FIRST = 13; static constexpr uint8_t GPR_ABT_FIRST = 13; static constexpr uint8_t GPR_IRQ_FIRST = 13; static constexpr uint8_t GPR_UND_FIRST = 13; static constexpr uint8_t GPR_SYS_USR_FIRST = 8; std::shared_ptr bus; std::array gpr; // general purpose registers Psr cpsr; // current program status register Psr spsr; // status program status register static constexpr uint8_t PC_INDEX = 15; uint32_t& pc = gpr[PC_INDEX]; bool is_flushed; void chg_mode(const Mode to); void exec_arm(const arm::ArmInstruction instruction); struct { std::array fiq; std::array svc; std::array abt; std::array irq; std::array und; // visible registers before the mode switch std::array old; } gpr_banked; // banked general purpose registers struct { Psr fiq; Psr svc; Psr abt; Psr irq; Psr und; } spsr_banked; // banked saved program status registers };