|
|
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.2 root 159: // SCSIBus コールバック
160:
161: // バスフリーになった (全員に通知される)
1.1.1.4 root 162: void BusFreeCB(int id) override;
1.1 root 163:
1.1.1.2 root 164: // ターゲットがセレクションに応答した (イニシエータのみ通知される)
1.1.1.4 root 165: void SelectionAckCB() override;
1.1.1.2 root 166:
167: // 情報転送フェーズで REQ を立てた (イニシエータのみ通知される)
1.1.1.4 root 168: void TransferReqCB() override;
1.1 root 169:
1.1.1.8 ! root 170: // BusIO インタフェース
! 171: // (内蔵 ROM からのアクセス用に特別に public にしてある)
! 172: uint64 Write(uint32 offset, uint32 data);
! 173:
1.1.1.3 root 174: protected:
175: // BusIO インタフェース
176: static const uint32 NPORT = 16;
1.1.1.8 ! root 177: uint64 Read(uint32 offset);
! 178: uint64 Peek(uint32 offset);
1.1.1.3 root 179:
1.1 root 180: private:
1.1.1.5 root 181: void MonitorReg(TextScreen&,
182: int x, int y, uint32 reg, const char * const *names);
1.1 root 183:
184: // SCTL レジスタへの書き込み
185: void WriteSCTL(uint32);
1.1.1.7 root 186: // 割り込みマスクの再構成
187: void MakeIntsMask();
1.1 root 188:
189: // SCMD レジスタへの書き込み
190: void WriteSCMD(uint32);
191:
192: // INTS レジスタへの書き込み
193: void WriteINTS(uint32);
1.1.1.3 root 194: // 表示のための前回値
195: uint32 prev_ints {};
1.1 root 196:
197: // INTS 設定
198: void SetINTS(uint32);
1.1.1.7 root 199: // INTS レジスタ値の取得
200: uint32 GetINTS() const;
201: // 割り込み信号線の状態を変える
202: void ChangeInterrupt();
1.1 root 203:
204: // PSNS レジスタ値の取得
205: uint32 GetPSNS() const;
206:
207: // SSTS レジスタ値の取得
208: uint32 GetSSTS() const;
1.1.1.3 root 209: // 表示のための前回値
210: uint32 prev_ssts {};
1.1 root 211:
1.1.1.7 root 212: // SERR レジスタ値の取得
213: uint32 GetSERR() const;
214:
1.1 root 215: // PCTL レジスタ値の取得
216: uint32 GetPCTL() const;
217:
1.1.1.3 root 218: // DREG レジスタアクセス
219: uint64 ReadDREG();
220: uint64 WriteDREG(uint32 data);
221:
1.1 root 222: // バスフリーフェーズに移行する
223: void BusFree();
1.1.1.2 root 224: // 直近のバスフリーフェーズになった時刻
225: // (アービトレーション/セレクション開始時に使う)
226: uint64 last_busfree_time {};
227: // バスをリリースする
228: void BusRelease();
1.1 root 229:
230: // Select コマンド実行
231: void SelectCommand();
1.1.1.6 root 232: void Arbitration1(Event& ev);
233: void Arbitration2(Event& ev);
234: void Selection1(Event& ev);
235: void SelectionTimeout(Event& ev);
1.1.1.2 root 236:
237: // SetATN コマンド実行
238: void SetATNCommand();
239: // セレクションフェーズで ATN を立てる
1.1.1.6 root 240: bool set_atn_in_selection {};
1.1 root 241:
242: // Transfer コマンド実行
243: void TransferCommand();
1.1.1.6 root 244: void TransferCommandStart(Event& ev);
245: void HardwareTransfer(Event& ev);
1.1.1.3 root 246: void TransferComplete();
1.1.1.2 root 247: // Transfer コマンド実行中なら true
1.1.1.6 root 248: bool transfer_command_running {};
1.1 root 249:
250: // SCSI コマンド
251: void ExecCommand();
252:
253: // レジスタ
254: struct SPC spc {};
255:
1.1.1.3 root 256: // VM 種別
257: vmtype_t vmtype {};
1.1 root 258:
259: // SPC に入力されるクロック周期 [nsec]
1.1.1.6 root 260: int t_CLF {};
261:
262: // アクセスウェイト
263: uint32 read_wait {};
264: uint32 write_wait {};
265:
1.1.1.7 root 266: // 割り込み信号線の接続先デバイス
267: InterruptDevice *interrupt {};
268:
1.1.1.6 root 269: // 接続中のデバイス(イニシエータ含む)を ID 順に並べたリスト (モニタ用)
270: std::vector<SCSIDevice*> connected_devices {};
1.1 root 271:
272: // イベント
273: Event event {};
1.1.1.2 root 274: Event event_tc {};
1.1 root 275: };
276:
1.1.1.3 root 277: 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.