--- nono/vm/lance.h 2026/04/29 17:04:50 1.1.1.7 +++ nono/vm/lance.h 2026/04/29 17:04:55 1.1.1.8 @@ -7,6 +7,7 @@ #pragma once #include "ethernet.h" +#include "monitor.h" #include "scheduler.h" struct AM7990 @@ -135,21 +136,24 @@ struct AM7990 bool IsBSWP() const { return (csr3 & CSR3_BSWP); } }; -class LanceDevice - : public EthernetDevice +class LanceDevice : public EthernetDevice { using inherited = EthernetDevice; - public: - static const uint32 REQ_TXIDLE = 0x00000001; // ポーリングフェーズ - static const uint32 REQ_TXCOPY = 0x00000002; // バッファ読込フェーズ - static const uint32 REQ_TXSEND = 0x00000004; // 送信フェーズ - static const uint32 REQ_TXNEXT = 0x00000008; // TMD 更新フェーズ - static const uint32 REQ_RXIDLE = 0x00000010; // ポーリングフェーズ - static const uint32 REQ_RXCOPY = 0x00000020; // バッファ書込フェーズ - static const uint32 REQ_RXNEXT = 0x00000040; // RMD 更新フェーズ - static const uint32 REQ_RXMISS = 0x00000080; // 受信 MISS - static const uint32 REQ_RXRECV = 0x00000100; // 受信イベント - static const uint32 REQ_TERMINATE = 0x80000000; // スレッド終了指示 + + // 受信フェーズ + enum class RXPhase { + IDLE = 0, // ポーリング + COPY, // バッファ書き込み + NEXT, // RMD 更新 + MISS, // 受信ミス + }; + // 送信フェーズ + enum class TXPhase { + IDLE = 0, // ポーリング + COPY, // バッファ読み込み + SEND, // 送信 + NEXT, // TMD 更新 + }; public: LanceDevice(); @@ -158,14 +162,6 @@ class LanceDevice bool Init() override; void ResetHard() override; - void MonitorUpdate(TextScreen&) override; - - // ワーカスレッド (エントリポイントから呼ばれる) - void ThreadRun() override; - - // パケットを受信した (ホストネットワークスレッドから呼ばれる) - bool RecvPacket(qvector& buf) override; - protected: // BusIO インタフェース static const uint32 NPORT = 2; @@ -173,13 +169,11 @@ class LanceDevice uint64 Write(uint32 offset, uint32 data); uint64 Peek(uint32 offset); - private: - pthread_t thread {}; - bool thread_created {}; // スレッドが作成されたら true - - // スレッドの終了を指示 - void Terminate(); + // パケット受信通知 (親クラスから) + void NotifyRecvPacket() override; + private: + DECLARE_MONITOR_CALLBACK(MonitorUpdate); void MonitorReg(TextScreen&, int x, int y, uint32 data, const char * const * names); uint32 ReadData(); @@ -199,16 +193,20 @@ class LanceDevice // 割り込み信号線の状態を変える void ChangeInterrupt(); - void TXIdle(); - void TXCopy(); - void TXSend(); - void TXNext(); - void RXIdle(); - void RXCopy(); - void RXNext(); - void RXRecv(); - void RXMiss(); - void Callback(Event& ev); + void TXIdle(Event&); + void TXCopy(Event&); + void TXSend(Event&); + void TXNext(Event&); + + void RXIdle(Event&); + void RXCopy(Event&); + void RXNext(Event&); + void RXRecv(Event&); + void RXMiss(Event&); + + // フェーズ遷移 + void ChangePhase(TXPhase new_phase, uint64 time = 100_nsec); + void ChangePhase(RXPhase new_phase, uint64 time = 100_nsec); const std::string BitToString(const char * const name[], uint16 bits); const std::string CSR0ToString(uint16 bits); @@ -225,6 +223,8 @@ class LanceDevice // Initialization Block uint16 initblock[12] {}; + uint64 padr {}; // PADR を下位詰めしたもの + uint32 rmd_base {}; // 受信ディスクリプタの(ZRAM での)開始アドレス int rmd_num {}; // 受信ディスクリプタ数 int rmd_cur {}; // RMD 内の現在の注目インデックス @@ -234,15 +234,21 @@ class LanceDevice uint16 rmd1 {}; // 現在の RMD1 uint32 rmd1_ahead {}; // 次の RMD1 先読み (負なら先読みしてない状態) - qvector rxq {}; // 受信バッファ + + RXPacket rxpacket {}; // 受信バッファ uint16 tmd1 {}; // 現在の TMD1 uint32 tmd1_ahead {}; // 次の TMD1 先読み (負なら先読みしてない状態) std::vector txq {}; // 送信バッファ + RXPhase rx_phase {}; // 受信フェーズ + TXPhase tx_phase {}; // 送信フェーズ + // 待ち時間用イベント - Event rx_event {}; - Event tx_event {}; + Event rx_event { this }; + Event tx_event { this }; + + Monitor monitor { this }; // 前回の TMD 状態文字列 (デバッグ表示用) std::string last_tmdstr {};