--- nono/m88xx0/m88200.h 2026/04/29 17:05:15 1.1.1.8 +++ nono/m88xx0/m88200.h 2026/04/29 17:05:56 1.1.1.13 @@ -9,10 +9,12 @@ #pragma once #include "device.h" +#include "bus.h" #include "mainbus.h" -#include "monitor.h" #include +#define M88200_STAT + class MPU88xx0Device; class MainbusDevice; @@ -21,6 +23,7 @@ struct m88200APR { bool enable; uint32 addr; + // stat は ACC_STAT_MASK と同じ位置の WT,G,CI のみ使用。APR に WP はない。 uint32 stat; const char *name; // 自分の名前(ログ表示用) }; @@ -34,6 +37,7 @@ struct m88200BATC // +-------------------------+-------------------------+-+-------+--+ // | LBA | 0 |S| 0 |~V| // +-------------------------+-------------------------+-+-------+--+ + static const uint32 LBAMASK = 0xfff80000; static const uint32 S = 0x00000020; static const uint32 INVALID = 0x00000001; uint32 lba; // LBA,S,~V @@ -47,6 +51,8 @@ struct m88200BATC bool IsValid() const { return (lba & INVALID) == 0; } // S ビットが立っていれば true を返す bool IsS() const { return (lba & S); } + // 論理アドレス(32ビット)を返す + uint32 Laddr() const { return (lba & LBAMASK); } }; // PATC @@ -59,6 +65,7 @@ struct m88200PATC // +---------------------------------------+-----------+-+-------+--+ // | LPA | 0 |S| 0 |~V| // +---------------------------------------+-----------+-+-------+--+ + static const uint32 LPAMASK = 0xfffff000; static const uint32 S = 0x00000020; static const uint32 INVALID = 0x00000001; uint32 lpa; // LPA,S,~V @@ -71,6 +78,8 @@ struct m88200PATC bool IsValid() const { return (lpa & INVALID) == 0; } // S ビットが立っていれば true を返す bool IsS() const { return (lpa & S); } + // 論理アドレス(32ビット)を返す + uint32 Laddr() const { return (lpa & LPAMASK); } }; // キャッシュの1セット @@ -84,12 +93,11 @@ class m88200CacheSet IV = 3, // Invalid }; - // // 3 2 1 - // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 - // +---------------------------------------+---------------+----+---+ - // | tag | set |Word| | - // +---------------------------------------+---------------+----+---+ + // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + // +---------------------------------------+---------------+----+-+--+ + // | tag | set |word|0|~V| + // +---------------------------------------+---------------+----+-+--+ // タグはアドレスの上位 20ビット。 // ただし無効なラインかどうかのチェックも一度で済ませるために @@ -100,7 +108,7 @@ class m88200CacheSet // LRU // CSSP の L ビットのロジックに従う。 - int L {}; + uint L {}; // ステータス Status vv[4] {}; @@ -118,15 +126,15 @@ class m88200CacheSet // 引数 L の状態から line を最新にしたらどうなるか、を返す。 // 表示処理で一時変数に対して処理が必要なため static 分離してある。 - static int TryUseLine(int L, int line); + static uint TryUseLine(uint tmpL, int line); // 引数 L の状態から line を最古にしたらどうなるか、を返す。 // 対称性のため static 分離してある。 - static int TryUnuseLine(int L, int line); + static uint TryUnuseLine(uint tmpL, int line); // 引数 L の状態で、最新の line を返す。 // 表示処理で一時変数に対して処理が必要なため static 分離してある。 - static int TryGetOldestLine(int L); + static int TryGetOldestLine(uint tmpL); void Use(int line) { L = TryUseLine(L, line); @@ -135,9 +143,9 @@ class m88200CacheSet // 更新用に最も古いラインを選んで差し出す int SelectOldestLine() const; - void Update(int line, Status status); + void Update(uint line, Status status); - void Write(int line, uint32 paddr, uint32 data, int size); + void Write(uint line, uint32 paddr, uint32 data, uint size); // キャッシュを検索して、ヒットした line を返す。 int Lookup(uint32 tagaddr) const; @@ -156,16 +164,16 @@ class m88200 : public Device void Reset(); private: - DECLARE_MONITOR_CALLBACK(MonitorUpdateReg); - DECLARE_MONITOR_CALLBACK(MonitorUpdateATC); - DECLARE_MONITOR_CALLBACK(MonitorUpdateCache); + DECLARE_MONITOR_SCREEN(MonitorScreenReg); + DECLARE_MONITOR_SCREEN(MonitorScreenATC); + DECLARE_MONITOR_SCREEN(MonitorScreenCache); MPU88xx0Device *parent {}; // モニター - Monitor reg_monitor { this }; - Monitor atc_monitor { this }; - Monitor cache_monitor { this }; + Monitor *reg_monitor {}; + Monitor *atc_monitor {}; + Monitor *cache_monitor {}; public: // @@ -182,7 +190,6 @@ class m88200 : public Device // ID はリセット時、下位7ビットはハードウェアで初期化、最上位ビットは // 0 で初期化。その後は全ビット変更可能。 // Type は $5 = 88200、$6 = 88204。ここでは 88200 固定。 - // Version は不明。 uint32 id {}; uint32 version {}; @@ -208,8 +215,8 @@ class m88200 : public Device static const uint32 GG_PAGE = 1; static const uint32 GG_SEG = 2; static const uint32 GG_ALL = 3; - void FlushCache(); - void InvalidatePATC(); + void FlushCacheCmd(); + void InvalidatePATCCmd(); public: // SSR (System Status Register) +$008 @@ -316,6 +323,11 @@ class m88200 : public Device uint32 GetPFAR() const { return fault_addr; } void SetPFAR(uint32 val) { fault_addr = val; } + void SetFault(uint32 code_, uint32 addr_) { + fault_code = code_; + fault_addr = addr_; + } + // BWP0-7 (BATC Write Ports 0..7) +$400..+$41c // 3 2 1 // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 @@ -325,6 +337,7 @@ class m88200 : public Device // +---------------------------------------------------------------+ static const uint32 BWP_LBA_MASK = 0xfff80000; static const uint32 BWP_PBA_MASK = 0x0007ffc0; + static const uint32 BWP_FLAG_MASK = 0x0000003f; static const uint32 BWP_S = 0x00000020; // Address Space static const uint32 BWP_WT = 0x00000010; // WriteThrough static const uint32 BWP_G = 0x00000008; // Global @@ -332,6 +345,7 @@ class m88200 : public Device static const uint32 BWP_WP = 0x00000002; // Write Protect static const uint32 BWP_V = 0x00000001; // Valid void SetBWP(uint n, uint32 val); + void SetBATC(uint n, uint32 laddr, uint32 paddr, uint32 flags); // CDP0-3 (Cache Data Ports 0..3) +$800..+$80c // 3 2 1 @@ -378,28 +392,26 @@ class m88200 : public Device // // 物理バスアクセス // - // XXX size をどうするか - uint64 MBusRead(uint32 paddr, int size); - uint64 MBusWrite(uint32 paddr, uint32 data, int size); - uint64 MBusXmem(uint32 paddr, uint32 data, int size); + busdata MBusRead(busaddr paddr); + busdata MBusWrite(busaddr paddr, uint32 data); + busdata MBusXmem(busaddr paddr, uint32 data); // // アクセス関数 // private: - template uint64 load(uint32 addr); - template uint64 store(uint32 addr, uint32 data); - template uint64 xmem(uint32 addr, uint32 data); + template busdata load(uint32 addr); + template busdata store(uint32 addr, uint32 data); + template busdata xmem(uint32 addr, uint32 data); public: - uint64 load_8(uint32 addr); - uint64 load_16(uint32 addr); - uint64 load_32(uint32 addr); - uint64 store_8(uint32 addr, uint32 data); - uint64 store_16(uint32 addr, uint32 data); - uint64 store_32(uint32 addr, uint32 data); - uint64 xmem_8(uint32 addr, uint32 data); - uint64 xmem_16(uint32 addr, uint32 data); - uint64 xmem_32(uint32 addr, uint32 data); + busdata load_1(uint32 addr); + busdata load_2(uint32 addr); + busdata load_4(uint32 addr); + busdata store_1(uint32 addr, uint32 data); + busdata store_2(uint32 addr, uint32 data); + busdata store_4(uint32 addr, uint32 data); + busdata xmem_1(uint32 addr, uint32 data); + busdata xmem_4(uint32 addr, uint32 data); // // 現在のアクセス中の状態。 @@ -445,14 +457,9 @@ class m88200 : public Device static const uint32 DESC_WP = 0x00000004; // Write Protect static const uint32 DESC_V = 0x00000001; // Valid - uint32 GetLaddr() const { return acc_laddr; } - uint32 GetPaddr() const { return acc_paddrH | acc_paddrL; } private: uint32 acc_laddr {}; // Logical Address - uint32 acc_paddrH {}; // Physical Address 上位30ビット。 - // 下位2ビットは 0 固定。 - uint32 acc_paddrL {}; // paddr の下位2ビット - // 上位30ビットは 0 固定。 + uint32 acc_paddr {}; // Physical Address public: // acc_stat は 4 ビットのみ使用。 @@ -467,16 +474,18 @@ class m88200 : public Device // pdaddr ... Page Descriptor Address // の2つに明確に分けて管理することにする。 uint32 acc_sdaddr {}; - uint32 acc_pdaddr {}; + busaddr acc_pdaddr {}; bool acc_read {}; // True if read access bool acc_IsWrite() const { return !acc_read; } // True if write access // S/U 信号線 // 実際には P Bus の Address フェーズで毎回送られてくるが // そうそう変わらないので状態変化を通知してもらう方式。 - // true なら super, false なら user。 - bool acc_super {}; + // acc_super は S か U のみ。 + busaddr acc_super {}; void SetSuper(bool super); + bool IsSuper() const { return acc_super.IsSuper(); } + bool IsUser() const { return !IsSuper(); } m88200PATC *acc_patc {}; // ヒットした PATC エントリ uint32 tmp_desc {}; // TEMP_DESCR @@ -485,7 +494,7 @@ class m88200 : public Device // アドレス変換 // bool Translate(); - uint64 TranslatePeek(uint32 laddr, bool issuper, bool do_search) const; + busaddr TranslatePeek(busaddr laddr) const; private: static std::string stat2str(uint32 stat); bool SelectAreaDesc(); @@ -505,7 +514,7 @@ class m88200 : public Device // [0x00] => 0b00'0000'0000; std::array batc_hash_s {}; std::array batc_hash_u {}; - // 現在の特権状態によって batc_hash_{s,u} のいずれかを指す + // 現在の特権状態によって batc_hash_{s,u} のいずれかを指す。 uint16 *batc_hash {}; static int batc_hash_func(uint32 a) { return (a >> 19) & 0x0f; @@ -521,14 +530,14 @@ class m88200 : public Device // ハッシュに当たることを示している (この後完全一致で比較する必要はある)。 std::array patc_hash_s {}; std::array patc_hash_u {}; - // 現在の特権状態によって patc_hash_{s,u} のいずれかを指す + // 現在の特権状態によって patc_hash_{s,u} のいずれかを指す。 uint64 *patc_hash {}; static int patc_hash_func(uint32 a) { return (a >> 12) & 0xff; } - // patc[] のうち空きエントリはビットを立てて示す - uint64 patc_free_map {}; - // 次回追加する位置 + // 空きエントリ。patc[N] が空いていればビット N を立てる。 + uint64 patc_free {}; + // 次回追加する位置。 int patc_next {}; // 統計 @@ -536,44 +545,48 @@ class m88200 : public Device std::array batc_hit {}; uint64 patc_hit {}; uint64 atc_miss {}; -#define M88200_STAT 1 #if defined(M88200_STAT) // 開発用の統計 - uint64 stat_patc_search {}; // ハッシュを引いた回数 - uint64 stat_patc_hit {}; // ヒットした回数 - uint64 stat_patc_miss1 {}; // ハッシュだけでミスした回数 - uint64 stat_patc_miss2 {}; // ビットを調べてミスした回数 uint64 stat_patc_create {}; // エントリ作成回数 uint64 stat_patc_invcmd_all {}; // Invalidate ALL 発行回数 uint64 stat_patc_invcmd_seg {}; // Invalidate Segment 発行回数 uint64 stat_patc_invcmd_page {}; // Invalidate Page 発行回数 uint64 stat_patc_invalidate {}; // 無効にした PATC の総数 + uint64 stat_patc_search {}; // ハッシュを引いた回数 + uint64 stat_patc_miss1 {}; // ハッシュだけでミスした回数 + uint64 stat_patc_miss2 {}; // ビットを調べてミスした回数 std::array stat_batc_hash_s {}; // BATC.S の衝突状況 std::array stat_batc_hash_u {}; // BATC.U の衝突状況 #endif // + // 物理アドレスアクセス + // + busdata PhysRead(busaddr paddr, uint32 stat); + busdata PhysWrite(busaddr paddr, uint32 data, uint32 stat); + + // // キャッシュ // private: std::array setarray {}; // キャッシュラインにメモリから読み込む - uint64 ReadLine(m88200CacheSet& set, int line, uint32 tagaddr); + bool ReadLine(m88200CacheSet& set, uint line, uint32 tagaddr); // キャッシュラインをメモリに書き出す - uint64 CopyBackLine(m88200CacheSet& set, int line); + bool CopyBackLine(m88200CacheSet& set, uint line); - public: // キャッシュに対して paddr の読み込みを行う - uint64 CacheRead(uint32 paddr); + busdata CacheRead(uint32 paddr); // キャッシュに対して paddr への書き込みを行う - uint64 CacheWrite(uint32 paddr, uint32 data, int size); - uint64 CacheWriteHit(m88200CacheSet& set, int line, - uint32 paddr, uint32 data, int size); - uint64 CacheXmem(uint32 paddr, uint32 data, int size); + busdata CacheWrite(uint32 paddr, uint32 data, uint size); + busdata CacheWriteHit(m88200CacheSet& set, uint line, + uint32 paddr, uint32 data, uint size); + busdata CacheXmem(uint32 paddr, uint32 data, uint size); + public: // モニタスクリーン作成用 - void MonitorCacheSet(TextScreen&, int y, int setidx); - void MonitorCacheOverview(TextScreen&, int y, int cursor, bool is_gui); + void MonitorCacheSet(TextScreen&, int y, uint setidx); + void MonitorCacheOverview(TextScreen&, int y, uint cursor, bool is_gui); void MonitorCacheOverview(TextScreen& s, int y, bool is_gui) { MonitorCacheOverview(s, y, -1, is_gui); } @@ -587,12 +600,14 @@ class m88200 : public Device static m88200 *GetBusMaster() { return mbus_master; } private: + static constexpr bool IM_0 = false; + static constexpr bool IM_1 = true; void MBusAcquire(); void MBusRelease() { } // 他 CMMU にスヌープさせる (バスマスタ側) - void MBusMakeSnoop(uint32, int); + void MBusMakeSnoop(uint32 addr, bool im); // バススヌープを行う (スレーブ側) - void Snoop(uint32, int); + void Snoop(uint32 addr, bool im); MainbusDevice *mainbus {};