Annotation of nono/vm/scsitarget.h, revision 1.1.1.1

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2018 [email protected]
                      4: //
                      5: 
                      6: #pragma once
                      7: 
                      8: #include "device.h"
                      9: #include "scsi.h"
                     10: 
                     11: // 前方参照 (scsitarget.cpp 内だけで使われている)
                     12: // friend class に書くクラス名は前方参照なくても大丈夫らしい。
                     13: class SCSICmd;
                     14: 
                     15: class SCSITarget : public Device
                     16: {
                     17:        typedef Device inherited;
                     18:        friend class SCSICmdModeSelect6;
                     19:        friend class SCSICmdRead6;
                     20:        friend class SCSICmdWrite6;
                     21:        friend class SCSICmdRead10;
                     22:  public:
                     23:        SCSITarget(SCSIHostDevice *host, int id, SCSI::DevType type);
                     24:        virtual ~SCSITarget();
                     25: 
                     26:        // SCSI デバイス種別を取得
                     27:        SCSI::DevType GetDevType() const { return devtype; }
                     28: 
                     29:        void Selected();
                     30:        void Ack();
                     31: 
                     32:        // コマンドフェーズの処理。
                     33:        void ExecCommand(const std::vector<uint8>& cmds);
                     34: 
                     35:        // デバイス固有のコマンドの処理。(派生クラスで用意)
                     36:        virtual SCSICmd *ExecDeviceCommand();
                     37: 
                     38:        // データインフェーズを開始。
                     39:        uint ExecDataIn(const uint8 **ptr);
                     40: 
                     41:        // データアウトフェーズを開始。
                     42:        uint ExecDataOut(uint8 **ptr);
                     43: 
                     44:        // ステータスバイトを取得 (およびデータアウトフェーズ完了処理)。
                     45:        uint8 GetStatusByte();
                     46: 
                     47:        // メッセージバイトを取得。
                     48:        uint8 GetMessageByte();
                     49: 
                     50:  protected:
                     51:        SCSIHostDevice *host = NULL;    // ホストアダプタ
                     52:        SCSI::DevType devtype {};               // デバイス種別
                     53:        int ID = 0;                                             // 自分の SCSI ID
                     54: 
                     55:        // SCSI バス信号は SCSIHost が管理
                     56:        uint8 GetDATA() { return host->GetDATA(); }
                     57:        void SetDATA(uint8 val) { host->SetDATA(val); }
                     58: 
                     59:        bool GetACK() const { return host->GetACK(); }
                     60:        void SetACK(bool val) { host->SetACK(val); }
                     61: 
                     62:        bool GetREQ() const { return host->GetREQ(); }
                     63:        void SetREQ(bool val) { host->SetREQ(val); }
                     64: 
                     65:        bool GetSEL() const { return host->GetSEL(); }
                     66:        void AssertSEL(int id) { host->AssertSEL(id); }
                     67:        void NegateSEL(int id) { host->NegateSEL(id); }
                     68: 
                     69:        bool GetBSY() const { return host->GetBSY(); }
                     70:        void AssertBSY(int id) { host->AssertBSY(id); }
                     71:        void NegateBSY(int id) { host->NegateBSY(id); }
                     72: 
                     73:        bool GetMSG() const { return host->GetMSG(); }
                     74:        void SetMSG(bool val) { host->SetMSG(val); }
                     75: 
                     76:        bool GetCD() const { return host->GetCD(); }
                     77:        void SetCD(bool val) { host->SetCD(val); }
                     78: 
                     79:        bool GetIO() const { return host->GetIO(); }
                     80:        void SetIO(bool val) { host->SetIO(val); }
                     81: 
                     82:        bool GetATN() const { return host->GetATN(); }
                     83: 
                     84:        void BusFreePhase();
                     85:        void DataOutPhase();
                     86:        void DataInPhase();
                     87:        void CommandPhase();
                     88:        void StatusPhase();
                     89:        void MsgOutPhase();
                     90:        void MsgInPhase();
                     91: 
                     92:        uint phase = 0;                         // ターゲットの状態
                     93:        uint nextphase = 0;                     // ATN による MsgOut の次の本来のフェーズ
                     94:        // ターゲットの現在のフェーズを取得
                     95:        uint GetPhase() const { return phase; }
                     96:        // ターゲットのフェーズを newphase に移行
                     97:        void SetPhase(uint newphase);
                     98: 
                     99:        // コマンド
                    100:        std::vector<uint8> cmds {};
                    101:        SCSICmd *cmd = NULL;
                    102: 
                    103:        uint8 lastdata = 0;
                    104:        uint8 lastmsg = 0;                      // 前回の MsgOut のメッセージ
                    105: 
                    106:        // 論理ブロック長 (ModeSelect コマンドでホストから指定される)
                    107:        uint32 blocksize = 0;
                    108: };
                    109: 
                    110: // SCSI HD
                    111: class SCSIHD : public SCSITarget
                    112: {
                    113:        typedef SCSITarget inherited;
                    114:        friend class SCSICmdRead6;
                    115:        friend class SCSICmdWrite6;
                    116:        friend class SCSICmdReadCapacity;
                    117:        friend class SCSICmdRead10;
                    118:  public:
                    119:        SCSIHD(SCSIHostDevice *host, int id);
                    120:        virtual ~SCSIHD();
                    121: 
                    122:        virtual bool Init();
                    123: 
                    124:        // デバイス固有のコマンドの処理。
                    125:        virtual SCSICmd *ExecDeviceCommand();
                    126: 
                    127:  private:
                    128:        int fd = 0;
                    129:        uint8 *mem = NULL;
                    130:        size_t memlen = 0;
                    131:        bool writeprotect = false;
                    132: 
                    133:        static const uint8 inquiry_data[36];
                    134: };

unix.superglobalmegacorp.com

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