--- nono/lib/branchhistory.h 2026/04/29 17:04:34 1.1 +++ nono/lib/branchhistory.h 2026/04/29 17:04:40 1.1.1.3 @@ -23,22 +23,29 @@ class BranchHistory : public Object { + protected: struct BranchEntry { uint32 count; // 連続通過回数 uint32 from; // ジャンプ元アドレス(VA) uint32 to; // ジャンプ先アドレス(VA) - uint32 padding; + uint32 inst; // ジャンプ元命令や例外情報など (機種による↓) } __packed; public: + // 表示系フラグ + static const uint64 ExHist = (1ULL << 63); // ヘッダを例外履歴に + static const uint64 BottomToTop = (1ULL << 62); // 新しい方を下に + + public: BranchHistory(); - ~BranchHistory() override; + virtual ~BranchHistory() override; - bool MonitorUpdate() override; + // 初期化 + void Clear(); // エントリを追加。 // エントリを返す。 - const BranchEntry& AddEntry(uint32 from, uint32 to) { + const BranchEntry& AddEntry(uint32 from, uint32 to, uint32 inst) { BranchEntry *e = &entry[top]; if (e->from == from && e->to == to) { @@ -51,12 +58,49 @@ class BranchHistory : public Object e->count = 1; e->from = from; e->to = to; + e->inst = inst; } return *e; } + void MonitorUpdate(TextScreen&) override; + + // 使用中のエントリ数を取得する + int GetUsed() const; + // 16バイト単位のテーブルなので16バイト境界に整列がよかろう。 alignas(16) BranchEntry entry[256] {}; // 直近に使用した位置 uint8 top {}; + + protected: + virtual std::string FormatEntry(const BranchEntry& e) = 0; +}; + +// +// m680x0 ブランチ履歴 +// (MPU に依存しないとは一体…) +// +class BranchHistory_m680x0 : public BranchHistory +{ + using inherited = BranchHistory; + public: + BranchHistory_m680x0(); + virtual ~BranchHistory_m680x0() override; + + std::string FormatEntry(const BranchEntry& e) override; +}; + +// +// m88xx0 ブランチ履歴 +// (MPU に依存しないとは一体…) +// +class BranchHistory_m88xx0 : public BranchHistory +{ + using inherited = BranchHistory; + public: + BranchHistory_m88xx0(); + virtual ~BranchHistory_m88xx0() override; + + std::string FormatEntry(const BranchEntry& e) override; };