--- nono/vm/mpu.h 2026/04/29 17:05:24 1.1.1.14 +++ nono/vm/mpu.h 2026/04/29 17:05:41 1.1.1.16 @@ -5,7 +5,7 @@ // // -// メイン MPU (680x0/88xx0) 共通部 +// MPU 共通部 // #pragma once @@ -13,16 +13,18 @@ #include "device.h" #include "event.h" #include "message.h" +#include class Debugger; class MainbusDevice; class Syncer; +// 全 MPU の共通部 class MPUDevice : public Device { using inherited = Device; public: - MPUDevice(); + explicit MPUDevice(uint objid_); ~MPUDevice() override; bool Init() override; @@ -31,6 +33,29 @@ class MPUDevice : public Device // 現在実行中の命令の PC を取得 virtual uint32 GetPPC() const = 0; + protected: + // 1命令実行イベント + Event exec_event { this }; + + Debugger *debugger {}; +}; + +// メイン MPU (680x0/88xxx0) 共通部 +class MainMPUDevice : public MPUDevice +{ + using inherited = MPUDevice; + protected: + // CPU の実行状態 + static const uint32 CPU_STATE_NORMAL = 0; + static const uint32 CPU_STATE_STOP = 1; + static const uint32 CPU_STATE_HALT = 2; + + public: + MainMPUDevice(); + ~MainMPUDevice() override; + + bool Init() override; + // 現在の VBR を取得 virtual uint32 GetVBR() const = 0; @@ -40,11 +65,14 @@ class MPUDevice : public Device virtual uint32 GetLaddr() const = 0; virtual uint32 GetPaddr() const = 0; + // CPU の実行状態 (uint32) を返す。 + uint32 GetState() const noexcept { return cpu_state; } + // MPU 名を取得する。("MC68030" みたいなやつ、ログ名とは別) virtual const char *GetMPUName() const = 0; // MPU クロック [kHz] を取得する。 - int GetClockSpeed() const { return clock_khz; } + uint GetClockSpeed() const { return clock_khz; } // MPU クロック [nsec] を取得する。 uint64 GetClock_nsec() const { return clock_nsec; } @@ -55,26 +83,31 @@ class MPUDevice : public Device // デバイスが CI (キャッシュ禁止) をセットする。 virtual void SetCI() = 0; + // 例外カウンタ + std::vector excep_counter {}; + protected: void TraceMessage(MessageID, uint32); - virtual void SetTrace(bool trace_on) = 0; + virtual void SetTrace(bool enable) = 0; + + // CPU の状態 + void ChangeState(uint32 new_state); - int clock_khz {}; // MPU クロック [kHz] + // CPU の実行状態 + uint32 cpu_state {}; + + uint clock_khz {}; // MPU クロック [kHz] uint64 clock_nsec {}; // MPU クロック [nsec] bool resetting {}; // リセット処理中フラグ - Debugger *debugger {}; MainbusDevice *mainbus {}; Syncer *syncer {}; - // 1命令実行イベント - Event exec_event { this }; - // Round Mode (モニタ表示用) static const char * const rmstr[4]; }; -static inline MPUDevice *GetMPUDevice() { - return Object::GetObject(OBJ_MPU); +static inline MainMPUDevice *GetMPUDevice() { + return Object::GetObject(OBJ_MPU); }