Annotation of nono/m88xx0/m88200.h, revision 1.1.1.6

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
                      7: // MC88200(CMMU)
                      8: 
                      9: #pragma once
                     10: 
                     11: #include "bus.h"
1.1.1.6 ! root       12: #include "monitor.h"
1.1       root       13: #include <array>
                     14: 
                     15: class m88kcpu;
                     16: 
                     17: // SAPR, UAPR レジスタ
                     18: struct m88200APR
                     19: {
                     20:        bool enable;
                     21:        uint32 addr;
                     22:        uint32 stat;
                     23:        const char *name;       // 自分の名前(ログ表示用)
                     24: };
                     25: 
                     26: // BATC
                     27: struct m88200BATC
                     28: {
                     29:        // LBA には S, V ビットを混ぜておく。比較を1回で済ませるため。
                     30:        // V ビットは invalid なら %1 にして一致しなくしておく。
                     31:        //  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
                     32:        // +-------------------------+-------------------------+-+-------+--+
                     33:        // |           LBA           |           0             |S|   0   |~V|
                     34:        // +-------------------------+-------------------------+-+-------+--+
                     35:        uint32 lba;             // LBA,S,V
                     36:        uint32 pba;             // PBA
                     37:        // stat は ACC_STAT_MASK と同じ WT,G,CI,WP のみ使用。
                     38:        // BATC (BWP レジスタ) のビット位置とは違うので注意。
                     39:        uint32 stat;
                     40:        bool wp;                // WP (比較で使うのでこれだけ抜き出しておく)
                     41: };
                     42: 
                     43: // PATC
                     44: struct m88200PATC
                     45: {
                     46:        // LPA には S ビットと有効/無効情報を混ぜておく。比較を1回で済ませるため。
                     47:        // V ビットは invalid なら %1 にして一致しなくしておく。実際の
                     48:        // PATC エントリの有効/無効は 46ビットの PATC 構造の外で管理されている?
                     49:        //  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
                     50:        // +---------------------------------------+-----------+-+-------+--+
                     51:        // |                 LPA                   |           |S|    0  |~V|
                     52:        // +---------------------------------------+-----------+-+-------+--+
                     53:        uint32 lpa;             // LPA,S,(V)
                     54:        uint32 pfa;             // PFA
                     55:        uint32 stat;    // ACC_STAT_MASK と同じ WT,G,CI,WP のみ使用。
                     56:        bool m;                 // Modified
                     57:        bool wp;                // Write Protect (比較で使うのでこれだけ抜き出しておく)
                     58: };
                     59: 
                     60: // キャッシュの1セット
                     61: class m88200CacheSet
                     62: {
                     63:  public:
                     64:        enum Status {
                     65:                EU = 0,         // Exclusive Unmodified
                     66:                EM = 1,         // Exclusive Modified
                     67:                SU = 2,         // Shared Unmodified
                     68:                IV = 3,         // Invalid
                     69:        };
                     70: 
                     71:        //
                     72:        //    3                   2                   1
                     73:        //  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
                     74:        // +---------------------------------------+---------------+----+---+
                     75:        // |                tag                    |      set      |Word|   |
                     76:        // +---------------------------------------+---------------+----+---+
                     77: 
                     78:        // タグはアドレスの上位 20ビット。
                     79:        // ただし無効なラインかどうかのチェックも一度で済ませるために
                     80:        // 無効(vv[]==IV)ならビット 0 を 1 にしておく。比較対象の paddr は
                     81:        // 下位12ビットを落としているため、これで絶対に一致しなくなる。
                     82:        static const uint32 TAG_INVALID = 0x00000001;
1.1.1.3   root       83:        uint32 tag[4] {};
1.1       root       84: 
                     85:        // LRU
                     86:        // CSSP の L ビットのロジックに従う。
                     87:        int L {};
                     88: 
                     89:        // ステータス
1.1.1.3   root       90:        Status vv[4] {};
1.1       root       91: 
                     92:        // データ。word[] は以下の順
                     93:        //       Word
                     94:        //        +0   +1   +2   +3
                     95:        // line0 [ 0] [ 1] [ 2] [ 3]
                     96:        // line1 [ 4] [ 5] [ 6] [ 7]
                     97:        // :
1.1.1.3   root       98:        uint32 word[16] {};
1.1       root       99: 
                    100:        // 自身のセットインデックス
1.1.1.3   root      101:        uint32 setidx {};
1.1       root      102: 
                    103:        // 引数 L の状態から line を最新にしたらどうなるか、を返す。
                    104:        // 表示処理で一時変数に対して処理が必要なため static 分離してある。
                    105:        static int TryUseLine(int L, int line);
                    106: 
                    107:        // 引数 L の状態から line を最古にしたらどうなるか、を返す。
                    108:        // 対称性のため static 分離してある。
                    109:        static int TryUnuseLine(int L, int line);
                    110: 
                    111:        // 引数 L の状態で、最新の line を返す。
                    112:        // 表示処理で一時変数に対して処理が必要なため static 分離してある。
                    113:        static int TryGetOldestLine(int L);
                    114: 
                    115:        void Use(int line) {
                    116:                L = TryUseLine(L, line);
                    117:        }
                    118: 
                    119:        // 更新用に最も古いラインを選んで差し出す
                    120:        int SelectOldestLine() const;
                    121: 
                    122:        void Update(int line, Status status);
                    123: 
                    124:        void Write(int line, uint32 paddr, uint32 data, int size);
                    125: 
                    126:        // キャッシュを検索して、ヒットした line を返す。
                    127:        int Lookup(uint32 tagaddr) const;
                    128: };
                    129: 
                    130: class m88200 : public Object
                    131: {
1.1.1.6 ! root      132:        using inherited = Object;
1.1       root      133:  public:
                    134:        m88200();
                    135:        ~m88200() override;
                    136: 
                    137:        // 本当はコンストラクタ渡ししたかったもの
                    138:        void Ctor(m88kcpu *parent_);
                    139: 
                    140:        // リセット
                    141:        void Reset();
                    142: 
1.1.1.6 ! root      143:        // モニター
        !           144:        Monitor reg_monitor { this };
        !           145:        Monitor atc_monitor { this };
        !           146:        Monitor cache_monitor { this };
1.1       root      147: 
                    148:  private:
1.1.1.6 ! root      149:        DECLARE_MONITOR_CALLBACK(MonitorUpdateReg);
        !           150:        DECLARE_MONITOR_CALLBACK(MonitorUpdateATC);
        !           151:        DECLARE_MONITOR_CALLBACK(MonitorUpdateCache);
        !           152: 
1.1.1.3   root      153:        m88kcpu *parent {};
1.1       root      154: 
                    155:  public:
                    156:        //
                    157:        // レジスタ
                    158:        //
                    159: 
                    160:        // IDR (ID Register) +$000
                    161:        //    3                   2                   1
                    162:        //  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
                    163:        // +---------------+-----+---------+-------------------------------+
                    164:        // |      ID       | Type| Version |           reserved            |
                    165:        // +---------------+-----+---------+-------------------------------+
                    166:        //
                    167:        // ID はリセット時、下位7ビットはハードウェアで初期化、最上位ビットは
                    168:        // 0 で初期化。その後は全ビット変更可能。
                    169:        // Type は $5 = 88200、$6 = 88204。ここでは 88200 固定。
                    170:        // Version は不明。
1.1.1.3   root      171:        uint32 id {};
                    172:        uint32 version {};
1.1       root      173: 
                    174:        // IDR レジスタの内容を返す
                    175:        uint32 GetIDR() const {
                    176:                return (id << 24) | (0x5 << 21);
                    177:        }
                    178:        // ID を設定する (IDR ではない)
                    179:        void SetID(uint id_);
                    180:        // Version フィールドを設定する
                    181:        void SetVersion(uint version_);
                    182: 
                    183:        // SCR (System Command Register) +$004
                    184:        //    3                   2                   1
                    185:        //  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
                    186:        // +---------------------------------------------------+-----------+
                    187:        // |                     reserved                      |CommandCode|
                    188:        // +---------------------------------------------------+-----------+
1.1.1.3   root      189:        uint32 command {};
1.1       root      190:        uint32 GetSCR() const;
                    191:        void SetSCR(uint32 val);
                    192:  private:
                    193:        static const char * const commandname[];
                    194:        static const uint32 GG_LINE     = 0;
                    195:        static const uint32 GG_PAGE     = 1;
                    196:        static const uint32 GG_SEG      = 2;
                    197:        static const uint32 GG_ALL      = 3;
                    198:        void FlushCache();
                    199:        void InvalidatePATC();
                    200: 
                    201:  public:
                    202:        // SSR (System Status Register) +$008
                    203:        //    3                   2                   1
                    204:        //  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
                    205:        // +---------------------------------------------------------------+
                    206:        // |                               |C|B|       |W|S|G|C| |M|U|W|B|V|
                    207:        // |            reserved           |E|E|  res  |T|P| |I|r| | |P|H| |
                    208:        // +---------------------------------------------------------------+
                    209:        static const uint32 SSR_CE      = 0x00008000;   // Copyback Error
                    210:        static const uint32 SSR_BE      = 0x00004000;   // Bus Error
                    211:        static const uint32 SSR_WT      = 0x00000200;   // WriteThrough
                    212:        static const uint32 SSR_SP      = 0x00000100;   // Supervisor Privilege
                    213:        static const uint32 SSR_G       = 0x00000080;   // Global
                    214:        static const uint32 SSR_CI      = 0x00000040;   // Cache Inhibit
                    215:        static const uint32 SSR_M       = 0x00000010;   // Modified
                    216:        static const uint32 SSR_U       = 0x00000008;   // Used
                    217:        static const uint32 SSR_WP      = 0x00000004;   // Write Protection
                    218:        static const uint32 SSR_BH      = 0x00000002;   // BATC Hit
                    219:        static const uint32 SSR_V       = 0x00000001;   // Valid
1.1.1.3   root      220:        uint32 ssr {};
1.1       root      221:        uint32 GetSSR() const { return ssr; }
                    222:        void SetSSR(uint32 val) { ssr = val; }
                    223: 
                    224:        // SAR (System Address Register) +$00c
                    225:        //    3                   2                   1
                    226:        //  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
                    227:        // +---------------------------------------------------------------+
                    228:        // |                          Address                              |
                    229:        // +---------------------------------------------------------------+
1.1.1.3   root      230:        uint32 sar {};
1.1       root      231:        uint32 GetSAR() const { return sar; }
                    232:        void SetSAR(uint32 val) { sar = val; }
                    233: 
                    234:        // SCTR (System Control Register) +$104
                    235:        //    3                   2                   1
                    236:        //  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
                    237:        // +-------------------------------+-+-+-+-------------------------+
                    238:        // |                               |P|S|P|                         |
                    239:        // |           reserved            |E|E|R|         reserved        |
                    240:        // +-------------------------------+-+-+-+-------------------------+
                    241:        static const uint32 SCTR_PE     = 0x00008000;   // Parity Enable
                    242:        static const uint32 SCTR_SE     = 0x00004000;   // Snoop Enable
                    243:        static const uint32 SCTR_PR     = 0x00002000;   // Priority Arbitration
1.1.1.3   root      244:        uint32 sctr {};
1.1       root      245:        uint32 GetSCTR() const { return sctr; }
                    246:        void SetSCTR(uint32 val);
                    247: 
                    248:        // SAPR (Supervisor Area Pointer Register) +$200
                    249:        // UAPR (User       Area Pointer Register) +$204
                    250:        //    3                   2                   1
                    251:        //  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
                    252:        // +---------------------------------------+---+-+-+-+-+---------+-+
                    253:        // | Supervisor Segment Table Base Address |   |W| |G|C|         |T|
                    254:        // | or    User Segment Table Base Address |0 0|T|0| |I|0 0 0 0 0|E|
                    255:        // +---------------------------------------+---+-+-+-+-+---------+-+
                    256:        static const uint32 APR_ADDR_MASK       = 0xfffff000;   // Base Address
                    257:        static const uint32 APR_WT                      = 0x00000200;   // WriteThrough
                    258:        static const uint32 APR_G                       = 0x00000080;   // Global
                    259:        static const uint32 APR_CI                      = 0x00000040;   // Cache Inhibit
                    260:        static const uint32 APR_TE                      = 0x00000001;   // Translation Enable
                    261:        m88200APR uapr {};
                    262:        m88200APR sapr {};
                    263:  private:
                    264:        uint32 GetAPR(const m88200APR&) const;
                    265:        void SetAPR(m88200APR&, uint32 data);
                    266:  public:
                    267:        uint32 GetAPR(uint issuper) const;
                    268:        uint32 GetUAPR() const { return GetAPR(uapr); }
                    269:        uint32 GetSAPR() const { return GetAPR(sapr); }
                    270:        void SetAPR(uint issuper, uint32 data);
                    271:        void SetUAPR(uint32 data) { SetAPR(uapr, data); }
                    272:        void SetSAPR(uint32 data) { SetAPR(sapr, data); }
                    273: 
                    274:        // PFSR (P Bus Fault Status Register) +$108
                    275:        //    3                   2                   1
                    276:        //  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
                    277:        // +-------------------------+-----+-------------------------------+
                    278:        // |                         |Fault|                               |
                    279:        // |        reserved         | Code|            reserved           |
                    280:        // +-------------------------+-----+-------------------------------+
                    281:        static const uint32 FAULT_CODE_SUCCESS          = 0;    // Success (No fault)
                    282:        static const uint32 FAULT_CODE_BUSERR           = 3;    // Bus Error
                    283:        static const uint32 FAULT_CODE_SEGMENT          = 4;    // Segment Fault
                    284:        static const uint32 FAULT_CODE_PAGE                     = 5;    // Page Fault
                    285:        static const uint32 FAULT_CODE_SUPERVISOR       = 6;    // Supervisor Violation
                    286:        static const uint32 FAULT_CODE_WRITE            = 7;    // Write Violation
1.1.1.3   root      287:        uint32 fault_code {};
1.1       root      288:        uint32 GetPFSR() const {
                    289:                return fault_code << 16;
                    290:        }
                    291:        void SetPFSR(uint32 data) {
                    292:                fault_code = (data >> 16) & 7;
                    293:        }
                    294: 
                    295:        // PFAR (P Bus Fault Address Register) +$10c
                    296:        //    3                   2                   1
                    297:        //  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
                    298:        // +---------------------------------------------------------------+
                    299:        // |                          Address                              |
                    300:        // +---------------------------------------------------------------+
1.1.1.3   root      301:        uint32 fault_addr {};
1.1       root      302:        uint32 GetPFAR() const { return fault_addr; }
                    303:        void SetPFAR(uint32 val) { fault_addr = val; }
                    304: 
                    305:        // BWP0-7 (BATC Write Ports 0..7) +$400..+$41c
                    306:        //    3                   2                   1
                    307:        //  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
                    308:        // +---------------------------------------------------------------+
                    309:        // |                         |                         |S|W|G|C|W|V|
                    310:        // |  Logical Block Address  | Physical Block Address  | |T| |I|P| |
                    311:        // +---------------------------------------------------------------+
                    312:        static const uint32 BATC_LBA_MASK       = 0xfff80000;
                    313:        static const uint32 BATC_PBA_MASK       = 0x0007ffc0;
                    314:        static const uint32 BATC_S                      = 0x00000020;   // Address Space
                    315:        static const uint32 BATC_WT                     = 0x00000010;   // WriteThrough
                    316:        static const uint32 BATC_G                      = 0x00000008;   // Global
                    317:        static const uint32 BATC_CI                     = 0x00000004;   // Cache Inhibit
                    318:        static const uint32 BATC_WP                     = 0x00000002;   // Write Protect
                    319:        static const uint32 BATC_V                      = 0x00000001;   // Valid
                    320:        std::array<m88200BATC, 10> batc {};
                    321:        uint32 GetBATC(uint n) const;
                    322:        void SetBATC(uint n, uint32 val);
                    323: 
                    324:        // CDP0-3 (Cache Data Ports 0..3) +$800..+$80c
                    325:        //    3                   2                   1
                    326:        //  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
                    327:        // +---------------------------------------------------------------+
                    328:        // |                          Data Word                            |
                    329:        // +---------------------------------------------------------------+
                    330: 
                    331:        // CTP0-3 (Cache Tag Ports 0..3) +$840..+$84c
                    332:        //    3                   2                   1
                    333:        //  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
                    334:        // +---------------------------------------+-----------------------+
                    335:        // |            Physical Address           |       reserved        |
                    336:        // +---------------------------------------+-----------------------+
                    337: 
                    338:        // CSSP (Cache Set Status Port) +$880
                    339:        //    3                   2                   1
                    340:        //  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
                    341:        // +---------------------------------------------------------------+
                    342:        // |   |L|L|L|L|L|L|D|D|D|D|VV3|VV2|VV1|VV0|                       |
                    343:        // |res|5|4|3|2|1|0|3|2|1|0|   |   |   |   |       reserved        |
                    344:        // +---------------------------------------------------------------+
                    345:        static const uint32 CSSP_L5             = 0x20000000;   // Line5
                    346:        static const uint32 CSSP_L4             = 0x10000000;   // Line4
                    347:        static const uint32 CSSP_L3             = 0x08000000;   // Line3
                    348:        static const uint32 CSSP_L2             = 0x04000000;   // Line2
                    349:        static const uint32 CSSP_L1             = 0x02000000;   // Line1
                    350:        static const uint32 CSSP_L0             = 0x01000000;   // Line0
                    351:        static const uint32 CSSP_D3             = 0x00800000;   // Line Disable
                    352:        static const uint32 CSSP_D2             = 0x00400000;   // Line Disable
                    353:        static const uint32 CSSP_D1             = 0x00200000;   // Line Disable
                    354:        static const uint32 CSSP_D0             = 0x00100000;   // Line Disable
                    355:        static const uint32 CSSP_VV3    = 0x000c0000;   // Line Valid
                    356:        static const uint32 CSSP_VV2    = 0x00030000;   // Line Valid
                    357:        static const uint32 CSSP_VV1    = 0x0000c000;   // Line Valid
                    358:        static const uint32 CSSP_VV0    = 0x00003000;   // Line Valid
                    359:        static const uint32 CSSP_VV3_OFFSET     = 18;
                    360:        static const uint32 CSSP_VV2_OFFSET     = 16;
                    361:        static const uint32 CSSP_VV1_OFFSET     = 14;
                    362:        static const uint32 CSSP_VV0_OFFSET     = 12;
                    363:        uint32 GetCSSP() const;
                    364:        void SetCSSP(uint32 val);
                    365: 
                    366:        //
                    367:        // 物理バスアクセス
                    368:        //
                    369:        // XXX size をどうするか
                    370:        uint64 MBusRead(uint32 paddr, int size);
                    371:        uint64 MBusWrite(uint32 paddr, uint32 data, int size);
                    372:        uint64 MBusXmem(uint32 paddr, uint32 data, int size);
                    373: 
                    374:        //
                    375:        // アクセス関数
                    376:        //
                    377:  private:
                    378:        template <int bits> uint64 load(uint32 addr);
                    379:        template <int bits> uint64 store(uint32 addr, uint32 data);
                    380:        template <int bits> uint64 xmem(uint32 addr, uint32 data);
                    381:  public:
                    382:        uint64 load_8(uint32 addr);
                    383:        uint64 load_16(uint32 addr);
                    384:        uint64 load_32(uint32 addr);
                    385:        uint64 store_8(uint32 addr, uint32 data);
                    386:        uint64 store_16(uint32 addr, uint32 data);
                    387:        uint64 store_32(uint32 addr, uint32 data);
                    388:        uint64 xmem_8(uint32 addr, uint32 data);
                    389:        uint64 xmem_16(uint32 addr, uint32 data);
                    390:        uint64 xmem_32(uint32 addr, uint32 data);
                    391: 
                    392:        //
                    393:        // 現在のアクセス中の状態。
                    394:        //
                    395:        // アドレス変換およびデータキャッシュルーチンではこれらの値を
                    396:        // グローバルに状態変数として使う。
                    397: 
                    398:        // ディスクリプタの下位にあるフラグは全部ビット位置が同じ。
                    399:        // Area descriptor (SAPR or UAPR)
                    400:        //  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
                    401:        // +---------------------------------------+---+-+-+-+-+---------+-+
                    402:        // | Supervisor Segment Table Base Address |   |W| |G|C|         |T|
                    403:        // | or    User Segment Table Base Address |0 0|T|0| |I|0 0 0 0 0|E|
                    404:        // +---------------------------------------+---+-+-+-+-+---------+-+
                    405:        //
                    406:        // Segment Descriptor
                    407:        //  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
                    408:        // +---------------------------------------+---+-+-+-+-+-----+-+-+-+
                    409:        // |    Page Table Base Address (PTBA)     |   |W|S|G|C|     |W| |V|
                    410:        // |                                       |0 0|T|P| |I|0 0 0|P|0| |
                    411:        // +---------------------------------------+---+-+-+-+-+-----+-+-+-+
                    412:        //
                    413:        // Page Descriptor
                    414:        //  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
                    415:        // +---------------------------------------+---+-+-+-+-+-+-+-+-+-+-+
                    416:        // |       Page Frame Address (PFA)        |   |W|S|G|C| |M|U|W| |V|
                    417:        // |                                       |0 0|T|P| |I|0| | |P|0| |
                    418:        // +---------------------------------------+---+-+-+-+-+-+-+-+-+-+-+
                    419:        //
                    420:        // acc_stat も同じビット位置を使う。
                    421:        //  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
                    422:        // +---------------------------------------+---+-+-+-+-+-----+-+---+
                    423:        // |                                       |   |W| |G|C|     |W|   |
                    424:        // |                                       |0 0|T|0| |I|  0  |P| 0 |
                    425:        // +---------------------------------------+---+-+-+-+-+-----+-+---+
                    426:        //
                    427:        static const uint32 DESC_WT             = 0x00000200;   // Write Through
                    428:        static const uint32 DESC_SP             = 0x00000100;   // Supervisor Protect
                    429:        static const uint32 DESC_G              = 0x00000080;   // Global
                    430:        static const uint32 DESC_CI             = 0x00000040;   // Cache Inhibit
                    431:        static const uint32 DESC_M              = 0x00000010;   // Modified
                    432:        static const uint32 DESC_U              = 0x00000008;   // Used
                    433:        static const uint32 DESC_WP             = 0x00000004;   // Write Protect
                    434:        static const uint32 DESC_V              = 0x00000001;   // Valid
                    435: 
1.1.1.5   root      436:        uint32 GetLaddr() const { return acc_laddr; }
                    437:        uint32 GetPaddr() const { return acc_paddrH | acc_paddrL; }
                    438:  private:
1.1       root      439:        uint32 acc_laddr {};            // Logical Address
                    440:        uint32 acc_paddrH {};           // Physical Address 上位30ビット。
                    441:                                                                //  下位2ビットは 0 固定。
                    442:        uint32 acc_paddrL {};           // paddr の下位2ビット
                    443:                                                                //  上位30ビットは 0 固定。
                    444: 
1.1.1.5   root      445:  public:
1.1       root      446:        // acc_stat は 4 ビットのみ使用。
                    447:        // それ以外のビットは代入時にマスクすること。
                    448:        static const uint32 ACC_STAT_MASK = DESC_WT | DESC_G | DESC_CI | DESC_WP;
                    449:        uint32 acc_stat {};
                    450:        // Table Address.  とマニュアルには書いてあるけど、テーブル先頭と
                    451:        // 紛らわしいし 88200 のアドレス変換ツリーは2段固定で、今何段目か
                    452:        // しらんけど現在のテーブルアドレス…みたいなのを持つ必要はないので、
                    453:        // ここでは
                    454:        // sdaddr ... Segment Descriptor Address
                    455:        // pdaddr ... Page    Descriptor Address
                    456:        // の2つに明確に分けて管理することにする。
                    457:        uint32 acc_sdaddr {};
                    458:        uint32 acc_pdaddr {};
1.1.1.3   root      459:        bool acc_read {};                       // True if read access
1.1       root      460:        bool acc_IsWrite() const { return !acc_read; }  // True if write access
                    461: 
                    462:        // S/U 信号線
                    463:        // 実際には P Bus の Address フェーズで毎回送られてくるが
                    464:        // そうそう変わらないので状態変化を通知してもらう方式。
                    465:        // true なら super, false なら user。
1.1.1.3   root      466:        bool acc_super {};
1.1       root      467:        void SetSuper(bool super) {
                    468:                acc_super = super;
                    469:        }
                    470: 
                    471:        m88200PATC *acc_patc {};        // ヒットした PATC エントリ
1.1.1.3   root      472:        uint32 tmp_desc {};                     // TEMP_DESCR
1.1       root      473: 
                    474:        //
                    475:        // アドレス変換
                    476:        //
                    477:        bool Translate();
                    478:        uint64 TranslatePeek(uint32 laddr, bool issuper, bool do_search) const;
                    479:  private:
                    480:        static std::string stat2str(uint32 stat);
                    481:        bool SelectAreaDesc();
                    482:        bool TableSearch();
                    483:        bool FetchSegmentDesc();
                    484:        bool FetchPageDesc();
                    485:        bool UpdatePageDesc();
                    486:        void CreatePATCEntry();
                    487: 
                    488:  public:
                    489:        // PATC
                    490:        static const uint32 PATC_S                      = 0x00000020;   // Supervisor
                    491:        std::array<m88200PATC, 56> patc {};
                    492: 
                    493: 
                    494:        //
                    495:        // キャッシュ
                    496:        //
1.1.1.3   root      497:  private:
1.1       root      498:        std::array<m88200CacheSet,256> setarray {};
1.1.1.3   root      499:        // キャッシュラインにメモリから読み込む
                    500:        uint64 ReadLine(m88200CacheSet& set, int line, uint32 tagaddr);
                    501:        // キャッシュラインをメモリに書き出す
                    502:        uint64 CopyBackLine(m88200CacheSet& set, int line);
1.1       root      503: 
1.1.1.3   root      504:  public:
1.1       root      505:        // キャッシュに対して paddr の読み込みを行う
                    506:        uint64 CacheRead(uint32 paddr);
                    507:        // キャッシュに対して paddr への書き込みを行う
                    508:        uint64 CacheWrite(uint32 paddr, uint32 data, int size);
                    509:        uint64 CacheWriteHit(m88200CacheSet& set, int line,
                    510:                uint32 paddr, uint32 data, int size);
                    511:        uint64 CacheXmem(uint32 paddr, uint32 data, int size);
                    512: 
                    513:        // モニタスクリーン作成用
                    514:        void MonitorCacheSet(TextScreen&, int y, int setidx);
                    515:        void MonitorCacheOverview(TextScreen&, int y, int cursor, bool is_gui);
                    516:        void MonitorCacheOverview(TextScreen& s, int y, bool is_gui) {
                    517:                MonitorCacheOverview(s, y, -1, is_gui);
                    518:        }
                    519: 
1.1.1.3   root      520:        //
                    521:        // MBus
                    522:        //
                    523:  public:
                    524:        // MBus を所有している CMMU ID を返す。誰も持っていなければ -1。
                    525:        // これは static 関数
                    526:        static m88200 *GetBusMaster() { return mbus_master; }
                    527: 
                    528:        // この CMMU からのアクセスにウェイトを加算する (VM から使う)
1.1.1.4   root      529:        void AddCycle(int32 cycle);
1.1.1.3   root      530: 
1.1       root      531:  private:
1.1.1.3   root      532:        void MBusAcquire();
1.1       root      533:        void MBusRelease() { }
1.1.1.3   root      534: 
                    535:        // MBus を所有してる CMMU を指す。NULL なら解放。
                    536:        // これは static 変数で全 m88200 で共有している
                    537:        static m88200 *mbus_master;
1.1       root      538: };

unix.superglobalmegacorp.com

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