Annotation of nono/vm/spc.h, revision 1.1.1.9

1.1       root        1: //
                      2: // nono
1.1.1.4   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
                      7: #pragma once
                      8: 
                      9: #include "device.h"
                     10: #include "fixedqueue.h"
1.1.1.4   root       11: #include "scheduler.h"
                     12: #include "scsidev.h"
1.1.1.3   root       13: #include "vm.h"
1.1       root       14: 
                     15: struct SPC
                     16: {
                     17:        static const int BDID = 0x0;    // $E96021 RW  $E100_0000
                     18:        static const int SCTL = 0x1;    // $E96023 RW  $E100_0004
                     19:        static const int SCMD = 0x2;    // $E96025 RW  $E100_0008
                     20:        static const int TMOD = 0x3;    // (MB89352 にはない)
                     21:        static const int INTS = 0x4;    // $E96029 RW  $E100_0010
                     22:        static const int PSNS = 0x5;    // $E9602B R-  $E100_0014
                     23:        static const int SDGC = 0x5;    // $E9602B -W  $E100_0014
                     24:        static const int SSTS = 0x6;    // $E9602D R-  $E100_0018
                     25:        static const int SERR = 0x7;    // $E9602F R-  $E100_001C
                     26:        static const int PCTL = 0x8;    // $E96031 RW  $E100_0020
                     27:        static const int MBC  = 0x9;    // $E96033 R-  $E100_0024
                     28:        static const int DREG = 0xa;    // $E96035 RW  $E100_0028
                     29:        static const int TEMP = 0xb;    // $E96037 RW  $E100_002C
                     30:        static const int TCH  = 0xc;    // $E96039 RW  $E100_0030
                     31:        static const int TCM  = 0xd;    // $E9603B RW  $E100_0034
                     32:        static const int TCL  = 0xe;    // $E9603D RW  $E100_0038
                     33:        static const int EXBF = 0xf;    // (MB89352 にはない)
                     34: 
                     35: 
                     36:        // SCTL レジスタ
                     37:        // 全ビットを保持。
                     38:        uint8 sctl;
                     39:        static const int SCTL_RESET                     = 0x80; // Reset & Disable
                     40:        static const int SCTL_CTL_RESET         = 0x40; // Control Reset
                     41:        static const int SCTL_DIAG_MODE         = 0x20; // Diag Mode
                     42:        static const int SCTL_ARBIT_EN          = 0x10; // Arbitration Enable
                     43:        static const int SCTL_PARITY_EN         = 0x08; // Parity Enable
                     44:        static const int SCTL_SEL_EN            = 0x04; // Select Enable
                     45:        static const int SCTL_RESEL_EN          = 0x02; // Reselect Enable
                     46:        static const int SCTL_INTR_EN           = 0x01; // Interrupt Enable
                     47: 
                     48:        // SCMD レジスタ
1.1.1.2   root       49:        // 全ビットを保持。
1.1       root       50:        uint8 scmd;
                     51:        static const int SCMD_CMD_MASK          = 0xe0; // Command code
                     52:        static const int SCMD_RST_OUT           = 0x10; // RST Out
                     53:        static const int SCMD_INTERCEPT         = 0x08; // Intersept Transfer
                     54:        static const int SCMD_PROGRAM           = 0x04; // Program Transfer
                     55:        static const int SCMD_TERM_MODE         = 0x01; // Termination Mode
                     56: 
                     57:        // INTS レジスタ
1.1.1.7   root       58:        //
                     59:        // 内部変数 ints は割り込み状態を一度に判別するため SERR レジスタの
                     60:        // xfer ビット(SERR_XFER_OUT) もここの bit8 に含めている。
                     61:        // 残りの下位8ビットは INTS と同じ。
                     62:        //
                     63:        //               | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
                     64:        // INTS          |SEL |RESL|DIS |CMPL|SERV|TOUT|HERR|REST|
                     65:        //            b8
                     66:        // ints変数 |xfer|SEL |RESL|DIS |CMPL|SERV|TOUT|HERR|REST|
                     67:        //
                     68:        uint16 ints;
1.1       root       69:        static const int INTS_SELECTED          = 0x80; // Selected
                     70:        static const int INTS_RESELECTED        = 0x40; // Reselected
                     71:        static const int INTS_DISCONNECTED      = 0x20; // Disconnected
                     72:        static const int INTS_COMPLETE          = 0x10; // Command Complete
                     73:        static const int INTS_SERV_REQ          = 0x08; // Service Required
                     74:        static const int INTS_TIMEOUT           = 0x04; // Time Out
                     75:        static const int INTS_HARD_ERR          = 0x02; // SPC Hard Error
                     76:        static const int INTS_RESET_COND        = 0x01; // Reset Condition
                     77: 
1.1.1.7   root       78:        static const int INTS_XFER_OUT          = 0x100;        // SERR_XFER_OUT
                     79: 
                     80:        // 割り込みマスク (INTS_RESET_COND はノンマスカブル割り込み)
                     81:        uint16 ints_mask;
                     82:        static const int INTS_ENABLE_MASK       = 0x01ff;
                     83:        static const int INTS_DISABLE_MASK      = 0x0001;
                     84: 
1.1       root       85:        // PSNS レジスタ
                     86:        uint8 psns;
                     87:        static const int PSNS_REQ                       = 0x80;
                     88:        static const int PSNS_ACK                       = 0x40;
                     89:        static const int PSNS_ATN                       = 0x20;
                     90:        static const int PSNS_SEL                       = 0x10;
                     91:        static const int PSNS_BSY                       = 0x08;
                     92:        static const int PSNS_MSG                       = 0x04;
                     93:        static const int PSNS_CD                        = 0x02;
                     94:        static const int PSNS_IO                        = 0x01;
                     95: 
                     96:        // SDGC レジスタ
                     97:        uint8 sdgc;
                     98:        static const int SDGC_XFER_ENABLE       = 0x20;
                     99: 
                    100:        // SSTS レジスタ
                    101:        // 上位4ビットを保持。下位4ビットは読み出し時に生成。
                    102:        uint8 ssts;
                    103:        static const int SSTS_CONN_INIT         = 0x80; // Connected (Initiator)
                    104:        static const int SSTS_CONN_TARG         = 0x40; // Connected (Target)
                    105:        static const int SSTS_SPC_BUSY          = 0x20; // SPC Busy
                    106:        static const int SSTS_IN_PROGRESS       = 0x10; // Transfer in Progress
                    107:        static const int SSTS_RST_IN            = 0x08; // SCSI RST In
                    108:        static const int SSTS_TC_ZERO           = 0x04; // TC=0
                    109:        static const int SSTS_DREG_FULL         = 0x02; // DREG Status (Full)
                    110:        static const int SSTS_DREG_EMPTY        = 0x01; // DREG Status (Empty)
                    111: 
                    112:        // SERR レジスタ
1.1.1.7   root      113:        // XFER_OUT 以外の4つの有効ビットを保持。
                    114:        // XFER_OUT は ints が担当している。
1.1       root      115:        uint8 serr;
                    116:        static const int SERR_DATAERR_SCSI      = 0x80; // Data Error: SCSI
                    117:        static const int SERR_DATAERR_SPC       = 0x40; // Data Error: SPC
                    118:        static const int SERR_XFER_OUT          = 0x20; // Xfer Out
                    119:        static const int SERR_TC_PARITY_ERR     = 0x08; // TC Parity Error
                    120:        static const int SERR_SHORT_XFER        = 0x02; // Short Transfer Period
                    121: 
                    122:        // PCTL レジスタ
                    123:        // ここでは BusFree INT Enable ビットだけを保持。
                    124:        // 残りの MSG, C/D, I/O は親クラスの信号線フラグから生成。
                    125:        bool busfree_intr_enable;
                    126:        static const int PCTL_MASK                      = 0x87; // 書き込みマスク
                    127:        static const int PCTL_BFINT_EN          = 0x80; // BusFree INT Enable
                    128:        static const int PCTL_MSG                       = 0x04;
                    129:        static const int PCTL_CD                        = 0x02;
                    130:        static const int PCTL_IO                        = 0x01;
                    131: 
                    132:        FixedQueue<uint8, 8> dreg;      // DREG レジスタ
                    133: 
                    134:        uint8 temp_in;  // TEMP レジスタ (SCSI -> MPU)
                    135:        uint8 temp_out; // TEMP レジスタ (MPU -> SCSI)
                    136:        uint32 tc;              // TC
                    137: 
                    138:        uint32 GetTCL() const { return tc & 0x0000ff; } // TCL
                    139: 
                    140:        // MBC (内部の読み込み専用レジスタ)
                    141:        // TC の下位4ビットが読めるらしい
                    142:        uint8 mbc() const {
                    143:                return tc & 15;
                    144:        }
                    145: };
                    146: 
                    147: class SPCDevice : public SCSIHostDevice
                    148: {
1.1.1.4   root      149:        using inherited = SCSIHostDevice;
1.1       root      150:  public:
1.1.1.3   root      151:        SPCDevice();
1.1.1.7   root      152:        virtual ~SPCDevice() override;
1.1       root      153: 
1.1.1.4   root      154:        bool Init() override;
                    155:        void ResetHard() override;
1.1       root      156: 
1.1.1.5   root      157:        void MonitorUpdate(TextScreen&) override;
1.1       root      158: 
1.1.1.9 ! root      159:        // 接続中のデバイスを ID 順に並べたリストを返す (UI ステータスパネル用)
        !           160:        const std::vector<SCSIDevice*>& GetConnectedDevices() const {
        !           161:                return connected_devices;
        !           162:        }
        !           163: 
1.1.1.2   root      164:        // SCSIBus コールバック
                    165: 
                    166:        // バスフリーになった (全員に通知される)
1.1.1.4   root      167:        void BusFreeCB(int id) override;
1.1       root      168: 
1.1.1.2   root      169:        // ターゲットがセレクションに応答した (イニシエータのみ通知される)
1.1.1.4   root      170:        void SelectionAckCB() override;
1.1.1.2   root      171: 
                    172:        // 情報転送フェーズで REQ を立てた (イニシエータのみ通知される)
1.1.1.4   root      173:        void TransferReqCB() override;
1.1       root      174: 
1.1.1.8   root      175:        // BusIO インタフェース
                    176:        // (内蔵 ROM からのアクセス用に特別に public にしてある)
                    177:        uint64 Write(uint32 offset, uint32 data);
                    178: 
1.1.1.3   root      179:  protected:
                    180:        // BusIO インタフェース
                    181:        static const uint32 NPORT = 16;
1.1.1.8   root      182:        uint64 Read(uint32 offset);
                    183:        uint64 Peek(uint32 offset);
1.1.1.3   root      184: 
1.1       root      185:  private:
1.1.1.5   root      186:        void MonitorReg(TextScreen&,
                    187:                int x, int y, uint32 reg, const char * const *names);
1.1       root      188: 
                    189:        // SCTL レジスタへの書き込み
                    190:        void WriteSCTL(uint32);
1.1.1.7   root      191:        // 割り込みマスクの再構成
                    192:        void MakeIntsMask();
1.1       root      193: 
                    194:        // SCMD レジスタへの書き込み
                    195:        void WriteSCMD(uint32);
                    196: 
                    197:        // INTS レジスタへの書き込み
                    198:        void WriteINTS(uint32);
1.1.1.3   root      199:        // 表示のための前回値
                    200:        uint32 prev_ints {};
1.1       root      201: 
                    202:        // INTS 設定
                    203:        void SetINTS(uint32);
1.1.1.7   root      204:        // INTS レジスタ値の取得
                    205:        uint32 GetINTS() const;
                    206:        // 割り込み信号線の状態を変える
                    207:        void ChangeInterrupt();
1.1       root      208: 
                    209:        // PSNS レジスタ値の取得
                    210:        uint32 GetPSNS() const;
                    211: 
                    212:        // SSTS レジスタ値の取得
                    213:        uint32 GetSSTS() const;
1.1.1.3   root      214:        // 表示のための前回値
                    215:        uint32 prev_ssts {};
1.1       root      216: 
1.1.1.7   root      217:        // SERR レジスタ値の取得
                    218:        uint32 GetSERR() const;
                    219: 
1.1       root      220:        // PCTL レジスタ値の取得
                    221:        uint32 GetPCTL() const;
                    222: 
1.1.1.3   root      223:        // DREG レジスタアクセス
                    224:        uint64 ReadDREG();
                    225:        uint64 WriteDREG(uint32 data);
                    226: 
1.1       root      227:        // バスフリーフェーズに移行する
                    228:        void BusFree();
1.1.1.2   root      229:        // 直近のバスフリーフェーズになった時刻
                    230:        // (アービトレーション/セレクション開始時に使う)
                    231:        uint64 last_busfree_time {};
                    232:        // バスをリリースする
                    233:        void BusRelease();
1.1       root      234: 
                    235:        // Select コマンド実行
                    236:        void SelectCommand();
1.1.1.6   root      237:        void Arbitration1(Event& ev);
                    238:        void Arbitration2(Event& ev);
                    239:        void Selection1(Event& ev);
                    240:        void SelectionTimeout(Event& ev);
1.1.1.2   root      241: 
                    242:        // SetATN コマンド実行
                    243:        void SetATNCommand();
                    244:        // セレクションフェーズで ATN を立てる
1.1.1.6   root      245:        bool set_atn_in_selection {};
1.1       root      246: 
                    247:        // Transfer コマンド実行
                    248:        void TransferCommand();
1.1.1.6   root      249:        void TransferCommandStart(Event& ev);
                    250:        void HardwareTransfer(Event& ev);
1.1.1.3   root      251:        void TransferComplete();
1.1.1.2   root      252:        // Transfer コマンド実行中なら true
1.1.1.6   root      253:        bool transfer_command_running {};
1.1       root      254: 
                    255:        // SCSI コマンド
                    256:        void ExecCommand();
                    257: 
                    258:        // レジスタ
                    259:        struct SPC spc {};
                    260: 
1.1.1.3   root      261:        // VM 種別
                    262:        vmtype_t vmtype {};
1.1       root      263: 
                    264:        // SPC に入力されるクロック周期 [nsec]
1.1.1.6   root      265:        int t_CLF {};
                    266: 
                    267:        // アクセスウェイト
                    268:        uint32 read_wait {};
                    269:        uint32 write_wait {};
                    270: 
1.1.1.7   root      271:        // 割り込み信号線の接続先デバイス
                    272:        InterruptDevice *interrupt {};
                    273: 
1.1.1.6   root      274:        // 接続中のデバイス(イニシエータ含む)を ID 順に並べたリスト (モニタ用)
                    275:        std::vector<SCSIDevice*> connected_devices {};
1.1       root      276: 
                    277:        // イベント
                    278:        Event event {};
1.1.1.2   root      279:        Event event_tc {};
1.1       root      280: };
                    281: 
1.1.1.3   root      282: extern std::unique_ptr<SPCDevice> gSPC;

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.