|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2024 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: #pragma once
8:
9: struct m68040MMU
10: {
11: // 3 2 1 0
12: // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
13: // +-------------------------------------+-+-+-+---+-+---+-+-+-+---+
14: // | Physical Address (4K/8K) : | |G|U10|S|CM |M|U|W|PDT|
15: // +-------------------------------------+-+-+-+---+-+---+-+-+-+---+
16: // ^ ^
17: // | |
18: // +-+-- UR (ユーザ用予約)
19: static const uint32 DESC_G = 0x00000400;
20: static const uint32 DESC_S = 0x00000080;
21: static const uint32 DESC_CM = 0x00000060;
22: static const uint32 DESC_M = 0x00000010;
23: static const uint32 DESC_U = 0x00000008;
24: static const uint32 DESC_W = 0x00000004;
25: static const uint32 DESC_DT = 0x00000003;
26:
1.1.1.2 ! root 27: // ATCEntry.desc は PDT/UDT どちらから作られても bit0 を Resident とする。
! 28: static const uint32 DESC_R = 0x00000001;
! 29:
1.1 root 30: // PDT は
31: // %00 無効
32: // %01 常駐
33: // %10 間接
34: // %11 常駐
35: static const uint32 PDT_INVALID = 0;
36: static const uint32 PDT_INDIRECT = 2;
37:
38: // UDT は
39: // %00 無効
40: // %01 無効
41: // %10 常駐
42: // %11 常駐
43: };
44:
45: class m68040RP
46: {
47: // SRP, URP
48: //
49: // 3 2 1 0
50: // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
51: // +-------------------------------------------+-------------------+
52: // | Root Pointer | 0 |
53: // +-------------------------------------------+-------------------+
54:
55: public:
56: static const uint32 ADDR_MASK = 0xfffffc00;
57: };
58:
59: class m68040TT
60: {
61: // 3 2 1 0
62: // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
63: // +---------------+---------------+-+-+-+-+-+-+---+-+-+-+-+-+-+-+-+
64: // |LogicalAddrBase|LogicalAddrMask|E| S | | U | |CM | |W| |
65: // +---------------+---------------+-+-+-+-+-+-+---+-+-+-+-+-+-+-+-+
66:
67: public:
68: static const uint32 MASK = 0xffffe364;
69: static const uint32 LBASE_MASK = 0xff000000;
70: static const uint32 LMASK_MASK = 0x00ff0000;
71: static const uint32 E = 0x00008000;
72: static const uint32 S_IGN = 0x00004000;
73: static const uint32 S_FC2 = 0x00002000;
74: static const uint32 U_MASK = 0x00000300;
75: static const uint32 U1 = 0x00000200;
76: static const uint32 U0 = 0x00000100;
77: static const uint32 CM = 0x00000060;
78: static const uint32 W = 0x00000004;
79:
80: m68040TT(const char *, uint32 *);
81: ~m68040TT();
82:
83: bool Match(busaddr addr) const;
84: const char *GetName() const { return name; }
85:
86: uint32 base {};
87: uint32 mask {};
88: bool e {};
89: bool s_ign {};
90: bool s_fc2 {};
91: uint32 u {};
92: uint8 cm {};
93: bool w {};
94:
95: uint32 *reg {}; // レジスタイメージ置き場 (®.*tt)
96: private:
97: const char *name {}; // 表示用のレジスタ名
98: };
99:
100: class m68040TC
101: {
102: // 1 0
103: // 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
104: // +-+-+---------------------------+
105: // |E|P| reserved |
106: // +-+-+---------------------------+
107:
108: public:
109: static const uint16 MASK = 0xc000;
110: static const uint16 E = 0x8000; // 有効
111: static const uint16 P = 0x4000; // ページサイズ(%1=8K)
112:
113: bool e {};
114: bool ps4k {}; // ページサイズが 4K なら true (ビット定義と逆)
115: uint32 table_mask {}; // ページテーブルアドレスのマスク
116: uint32 tic_shift {}; // 論理アドレス TIC 部の右シフト量
117: uint32 tic_mask {}; // 論理アドレス TIC 部のマスク
118: uint32 page_mask {}; // ページディスクリプタの物理アドレスマスク
119: };
120:
121: class m68040MMUSR
122: {
123: // 3 2 1 0
124: // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
125: // +---------------------------------------+-+-+---+-+-+-+-+-+-+-+-+
126: // | Physical Address |B|G| U |S|CM |M| |W|T|R|
127: // +---------------------------------------+-+-+---+-+-+-+-+-+-+-+-+
128:
129: public:
130: static const uint32 ADDR_MASK = 0xfffff000; // 物理アドレス
131: static const uint32 B = 0x00000800; // バスエラー
132: static const uint32 G = 0x00000400; // グローバル
133: static const uint32 U_MASK = 0x00000300; // ユーザ領域
134: static const uint32 U1 = 0x00000200;
135: static const uint32 U0 = 0x00000100;
136: static const uint32 S = 0x00000080; // スーパーバイザ保護
137: static const uint32 CM = 0x00000060; // キャッシュモード
138: static const uint32 M = 0x00000010; // 修正済み
139: static const uint32 W = 0x00000004; // 書き込み保護
140: static const uint32 T = 0x00000002; // 透過変換がヒット
141: static const uint32 R = 0x00000001; // 常駐
142: };
143:
144: // ATC エントリ
145: class m68040ATCEntry
146: {
147: public:
148: // タグは無効なら最下位ビットを立てる。これでマッチしなくなる。
149: //
150: // 3 2 1 0
151: // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
152: // +-----+-+---------------------------------------+-------------+--+
153: // | 0 |S| Logical Address (4K/8K) : | 0 |~V|
154: // +-----+-+---------------------------------------+-------------+--+
155: static const uint32 SUPER = 0x10000000;
156: static const uint32 INVALID = 0x00000001;
157: uint32 tag {};
158:
159: bool IsValid() const { return (tag & INVALID) == 0; }
160: bool IsSuper() const { return (tag & SUPER) != 0; }
161: void Invalidate() { tag |= INVALID; }
162:
163: // desc はページディスクリプタをそのまま持っておく。
164: // ページディスクリプタなので PDT(下位2bit) は %01 か %11 なら Resident。
165: //
166: // 3 2 1 0
167: // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
168: // +-----------------------------------------+-+---+-+---+-+-+-+-+-+
169: // | (not used) |G|U10|S|CM |M|U|W|-|R|
170: // +-----------------------------------------+-+---+-+---+-+-+-+-+-+
171: uint32 paddr {};
172: uint32 desc {};
173:
174: bool IsGlobal() const { return (desc & m68040MMU::DESC_G); }
175: bool IsSuperProtected() const { return (desc & m68040MMU::DESC_S); }
176: bool IsWriteProtected() const { return (desc & m68040MMU::DESC_W); }
1.1.1.2 ! root 177: bool IsResident() const { return (desc & m68040MMU::DESC_R); }
1.1 root 178:
179: bool MatchStatus(busaddr laddr) const;
180: };
181:
182: // ATC セット
183: class m68040ATCSet
184: {
185: public:
186: std::array<m68040ATCEntry, 4> entry {};
187: uint LRU {};
188:
189: int GetEntry() const;
190: };
191:
192: // ATC
193: class m68040ATC
194: {
195: public:
196: std::array<m68040ATCSet, 16> sets {};
197:
198: // アドレス (busaddr >> 4) からタグを作る際のマスク。
199: // PS が 4K か 8K かで長さが違うため。
200: uint32 tag_mask {};
201:
202: void Flush(bool s, bool global);
203: void Flush(busaddr addr, bool global);
204: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.