|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2017 [email protected]
4: //
5:
6: #pragma once
7:
8: #include "device.h"
1.1.1.2 root 9: #include "scsidev.h"
1.1 root 10: #include "scheduler.h"
11: #include "fixedqueue.h"
1.1.1.3 ! root 12: #include "vm.h"
1.1 root 13:
14: struct SPC
15: {
16: static const int BDID = 0x0; // $E96021 RW $E100_0000
17: static const int SCTL = 0x1; // $E96023 RW $E100_0004
18: static const int SCMD = 0x2; // $E96025 RW $E100_0008
19: static const int TMOD = 0x3; // (MB89352 にはない)
20: static const int INTS = 0x4; // $E96029 RW $E100_0010
21: static const int PSNS = 0x5; // $E9602B R- $E100_0014
22: static const int SDGC = 0x5; // $E9602B -W $E100_0014
23: static const int SSTS = 0x6; // $E9602D R- $E100_0018
24: static const int SERR = 0x7; // $E9602F R- $E100_001C
25: static const int PCTL = 0x8; // $E96031 RW $E100_0020
26: static const int MBC = 0x9; // $E96033 R- $E100_0024
27: static const int DREG = 0xa; // $E96035 RW $E100_0028
28: static const int TEMP = 0xb; // $E96037 RW $E100_002C
29: static const int TCH = 0xc; // $E96039 RW $E100_0030
30: static const int TCM = 0xd; // $E9603B RW $E100_0034
31: static const int TCL = 0xe; // $E9603D RW $E100_0038
32: static const int EXBF = 0xf; // (MB89352 にはない)
33:
34:
35: // SCTL レジスタ
36: // 全ビットを保持。
37: uint8 sctl;
38: static const int SCTL_RESET = 0x80; // Reset & Disable
39: static const int SCTL_CTL_RESET = 0x40; // Control Reset
40: static const int SCTL_DIAG_MODE = 0x20; // Diag Mode
41: static const int SCTL_ARBIT_EN = 0x10; // Arbitration Enable
42: static const int SCTL_PARITY_EN = 0x08; // Parity Enable
43: static const int SCTL_SEL_EN = 0x04; // Select Enable
44: static const int SCTL_RESEL_EN = 0x02; // Reselect Enable
45: static const int SCTL_INTR_EN = 0x01; // Interrupt Enable
46:
47: // SCMD レジスタ
1.1.1.2 root 48: // 全ビットを保持。
1.1 root 49: uint8 scmd;
50: static const int SCMD_CMD_MASK = 0xe0; // Command code
51: static const int SCMD_RST_OUT = 0x10; // RST Out
52: static const int SCMD_INTERCEPT = 0x08; // Intersept Transfer
53: static const int SCMD_PROGRAM = 0x04; // Program Transfer
54: static const int SCMD_TERM_MODE = 0x01; // Termination Mode
55:
56: // INTS レジスタ
57: // 全ビットを保持。
58: uint8 ints;
59: static const int INTS_SELECTED = 0x80; // Selected
60: static const int INTS_RESELECTED = 0x40; // Reselected
61: static const int INTS_DISCONNECTED = 0x20; // Disconnected
62: static const int INTS_COMPLETE = 0x10; // Command Complete
63: static const int INTS_SERV_REQ = 0x08; // Service Required
64: static const int INTS_TIMEOUT = 0x04; // Time Out
65: static const int INTS_HARD_ERR = 0x02; // SPC Hard Error
66: static const int INTS_RESET_COND = 0x01; // Reset Condition
67:
68: // PSNS レジスタ
69: uint8 psns;
70: static const int PSNS_REQ = 0x80;
71: static const int PSNS_ACK = 0x40;
72: static const int PSNS_ATN = 0x20;
73: static const int PSNS_SEL = 0x10;
74: static const int PSNS_BSY = 0x08;
75: static const int PSNS_MSG = 0x04;
76: static const int PSNS_CD = 0x02;
77: static const int PSNS_IO = 0x01;
78:
79: // SDGC レジスタ
80: uint8 sdgc;
81: static const int SDGC_XFER_ENABLE = 0x20;
82:
83: // SSTS レジスタ
84: // 上位4ビットを保持。下位4ビットは読み出し時に生成。
85: uint8 ssts;
86: static const int SSTS_CONN_INIT = 0x80; // Connected (Initiator)
87: static const int SSTS_CONN_TARG = 0x40; // Connected (Target)
88: static const int SSTS_SPC_BUSY = 0x20; // SPC Busy
89: static const int SSTS_IN_PROGRESS = 0x10; // Transfer in Progress
90: static const int SSTS_RST_IN = 0x08; // SCSI RST In
91: static const int SSTS_TC_ZERO = 0x04; // TC=0
92: static const int SSTS_DREG_FULL = 0x02; // DREG Status (Full)
93: static const int SSTS_DREG_EMPTY = 0x01; // DREG Status (Empty)
94:
95: // SERR レジスタ
96: uint8 serr;
97: static const int SERR_DATAERR_SCSI = 0x80; // Data Error: SCSI
98: static const int SERR_DATAERR_SPC = 0x40; // Data Error: SPC
99: static const int SERR_XFER_OUT = 0x20; // Xfer Out
100: static const int SERR_TC_PARITY_ERR = 0x08; // TC Parity Error
101: static const int SERR_SHORT_XFER = 0x02; // Short Transfer Period
102:
103: // PCTL レジスタ
104: // ここでは BusFree INT Enable ビットだけを保持。
105: // 残りの MSG, C/D, I/O は親クラスの信号線フラグから生成。
106: bool busfree_intr_enable;
107: static const int PCTL_MASK = 0x87; // 書き込みマスク
108: static const int PCTL_BFINT_EN = 0x80; // BusFree INT Enable
109: static const int PCTL_MSG = 0x04;
110: static const int PCTL_CD = 0x02;
111: static const int PCTL_IO = 0x01;
112:
113: FixedQueue<uint8, 8> dreg; // DREG レジスタ
114:
115: uint8 temp_in; // TEMP レジスタ (SCSI -> MPU)
116: uint8 temp_out; // TEMP レジスタ (MPU -> SCSI)
117: uint32 tc; // TC
118:
119: uint32 GetTCL() const { return tc & 0x0000ff; } // TCL
120:
121: // MBC (内部の読み込み専用レジスタ)
122: // TC の下位4ビットが読めるらしい
123: uint8 mbc() const {
124: return tc & 15;
125: }
126: };
127:
128: class SPCDevice : public SCSIHostDevice
129: {
130: typedef SCSIHostDevice inherited;
131: public:
1.1.1.3 ! root 132: SPCDevice();
1.1 root 133: virtual ~SPCDevice();
134:
135: virtual bool Init();
136: virtual void ResetHard();
137: virtual void ResetSoft();
138: void Reset();
139:
140: virtual bool MonitorUpdate();
141:
1.1.1.2 root 142: // SCSIBus コールバック
143:
144: // バスフリーになった (全員に通知される)
145: virtual void BusFreeCB(int id);
1.1 root 146:
1.1.1.2 root 147: // ターゲットがセレクションに応答した (イニシエータのみ通知される)
148: virtual void SelectionAckCB();
149:
150: // 情報転送フェーズで REQ を立てた (イニシエータのみ通知される)
151: virtual void TransferReqCB();
1.1 root 152:
1.1.1.3 ! root 153: protected:
! 154: // BusIO インタフェース
! 155: static const uint32 NPORT = 16;
! 156: uint64 Read(uint32 addr);
! 157: uint64 Write(uint32 addr, uint32 data);
! 158: uint64 Peek(uint32 addr);
! 159:
1.1 root 160: private:
161: void MonitorReg(int x, int y, uint32 reg, const char * const *names);
162:
163: // SCTL レジスタへの書き込み
164: void WriteSCTL(uint32);
165:
166: // SCMD レジスタ値の取得
167: uint32 GetSCMD() const;
168:
169: // SCMD レジスタへの書き込み
170: void WriteSCMD(uint32);
171:
172: // INTS レジスタへの書き込み
173: void WriteINTS(uint32);
1.1.1.3 ! root 174: // 表示のための前回値
! 175: uint32 prev_ints {};
1.1 root 176:
177: // INTS 設定
178: void SetINTS(uint32);
179:
180: // PSNS レジスタ値の取得
181: uint32 GetPSNS() const;
182:
183: // SSTS レジスタ値の取得
184: uint32 GetSSTS() const;
1.1.1.3 ! root 185: // 表示のための前回値
! 186: uint32 prev_ssts {};
1.1 root 187:
188: // PCTL レジスタ値の取得
189: uint32 GetPCTL() const;
190:
1.1.1.3 ! root 191: // DREG レジスタアクセス
! 192: uint64 ReadDREG();
! 193: uint64 WriteDREG(uint32 data);
! 194:
1.1 root 195: // バスフリーフェーズに移行する
196: void BusFree();
1.1.1.2 root 197: // 直近のバスフリーフェーズになった時刻
198: // (アービトレーション/セレクション開始時に使う)
199: uint64 last_busfree_time {};
200: // バスをリリースする
201: void BusRelease();
1.1 root 202:
203: // Select コマンド実行
204: void SelectCommand();
1.1.1.2 root 205: void Arbitration1(int code);
206: void Arbitration2(int code);
207: void Selection1(int code);
208: void SelectionTimeout(int code);
209:
210: // SetATN コマンド実行
211: void SetATNCommand();
212: // セレクションフェーズで ATN を立てる
213: bool set_atn_in_selection = false;
1.1 root 214:
215: // Transfer コマンド実行
216: void TransferCommand();
1.1.1.2 root 217: void TransferCommandStart(int code);
1.1.1.3 ! root 218: void HardwareTransfer(int code);
! 219: void TransferComplete();
1.1.1.2 root 220: // Transfer コマンド実行中なら true
221: bool transfer_command_running = false;
1.1 root 222:
223: // SCSI コマンド
224: void ExecCommand();
225:
226: // レジスタ
227: struct SPC spc {};
228:
1.1.1.3 ! root 229: // VM 種別
! 230: vmtype_t vmtype {};
1.1 root 231:
232: // SPC に入力されるクロック周期 [nsec]
233: int t_CLF = 0;
234:
235: // イベント
236: Event event {};
1.1.1.2 root 237: Event event_tc {};
1.1 root 238: };
239:
1.1.1.3 ! root 240: extern std::unique_ptr<SPCDevice> gSPC;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.