--- nono/m680x0/m68030mmu.h 2026/04/29 17:04:28 1.1 +++ nono/m680x0/m68030mmu.h 2026/04/29 17:05:22 1.1.1.7 @@ -1,10 +1,13 @@ // // nono -// Copyright (C) 2017 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #pragma once +class MPU680x0Device; + // ATC_SINGLE は過去との比較のために残してある、双方向リストによる // FC 混合 22 エントリ実装。 // 定義しない場合(デフォルト)は、FC 別の世代付き配列みたいなもの。 @@ -25,12 +28,13 @@ class m68030RP // | TABLE ADDRESS (PA31-PA4) |unused | // +-------------------------------------------------------+-------+ public: + static const uint32 DT_MASK = 0x00000003; static const uint32 H_MASK = 0xffff0003; static const uint32 L_MASK = 0xfffffff0; }; // TT レジスタの各フィールドを束ねた構造体のようなもの。 -// m68kcpu::SetTT(), GetTT() で読み書きする。 +// MPU680x0Device::SetTT(), GetTT() で読み書きする。 class m68030TT { // 3 2 1 0 @@ -51,19 +55,27 @@ class m68030TT static const uint32 FCBASE_MASK = 0x00000070; static const uint32 FCMASK_MASK = 0x00000007; - uint32 e = 0; // 00008000 イネーブル - uint32 ci = 0; // 00000400 キャッシュ禁止 - uint64 base = 0; // ベース - uint64 mask = 0; // マスク + bool e {}; // イネーブル + bool ci {}; // キャッシュ禁止 + uint64 base {}; // ベース + uint64 mask {}; // マスク // アクセスがこの TT と一致するか調べる。 - bool Match(uint64 ssw_laddr); + bool Match(busaddr addr) const; }; // TC レジスタの各フィールドを束ねた構造体のようなもの。 // m68kcpu::SetTC(), GetTC() で読み書きする。 class m68030TC { + // 3 2 1 0 + // 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 + // +-+---------+-+-+-------+-------+-------+-------+-------+-------+ + // |E| 0 |S|F| PS | IS | TIA | TIB | TIC | TID | + // +-+---------+-+-+-------+-------+-------+-------+-------+-------+ + // | | +-- FCL (Function Code Lookup Enable) + // | +---- SRE (Supervisor Root Pointer Enable) + // +-- Enable public: static const uint32 MASK = 0x83ffffff; static const uint32 TC_E = 0x80000000; @@ -71,11 +83,11 @@ class m68030TC static const uint32 TC_FCL = 0x01000000; // レジスタの各フィールド - uint32 e = 0; // TC_E の位置 - uint32 sre = 0; // TC_SRE の位置 - uint32 fcl = 0; // TC_FCL の位置 - uint ps = 0; - uint is = 0; + uint32 e {}; // TC_E の位置 + uint32 sre {}; // TC_SRE の位置 + uint32 fcl {}; // TC_FCL の位置 + uint ps {}; + uint is {}; union { uint tix[4] {}; struct { @@ -88,8 +100,8 @@ class m68030TC int shift[4] {}; // TIA-TID の各部分のシフト量 uint32 mask[4] {}; // TIA-TID の各部分のマスク - uint32 lmask = 0; // TIA-TID 全体のマスク - uint32 pgmask = 0; // PS 部分のマスク + uint32 lmask {}; // TIA-TID 全体のマスク + uint32 pgmask {}; // PS 部分のマスク public: void Set(uint32); @@ -114,16 +126,17 @@ class m68030MMUSR // ATC の1エントリ struct m68030ATCLine { - // 1エントリはタグとデータの計64ビット。 - // - // タグ + // tag // LLLLLLLL_LLLLLLLL_LLLLLLLL_0000000I : L は論理アドレス // +-- invalid (%1で無効) // // FC はテーブル選択の時点で確定しているのでタグには不要。 // - // データ - // PPPPPPPP_PPPPPPPP_PPPPPPPP_0000BCPM : P は物理アドレス + // paddr + // PPPPPPPP_PPPPPPPP_PPPPPPPP_00000000 : P は物理アドレス + // + // data + // 00000000_00000000_00000000_0000BCPM // |||+-- Modified // ||+--- Write Protect // |+---- Cache Inhibit @@ -166,17 +179,17 @@ struct m68030ATCLine #endif // デバッグ表示 - void fill_print(uint fc); + std::string fill_print(uint fc); }; // ATC のテーブル -class m68030ATCTable +class m68030ATCTable final { public: static const int LINES = 22; m68030ATCTable(); - virtual ~m68030ATCTable() { } + ~m68030ATCTable(); #if !defined(ATC_SINGLE) // 空きエントリを取得。 @@ -221,30 +234,37 @@ class m68030ATCTable // ATC_SINGLE ならリストの先頭。 // !ATC_SINGLE なら注目エントリ。 - m68030ATCLine *head = NULL; + m68030ATCLine *head {}; #if !defined(ATC_SINGLE) // LRU 用の更新カウンタ - uint32 counter = 0; + uint32 counter {}; // head のヒット回数。 - uint64 hit_head = 0; + uint64 hit_head {}; #endif + + int loglevel {}; + + MPU680x0Device *cpu {}; }; // ATC (Address Translation Cache) -class m68030ATC +class m68030ATC final { - friend class MPUATC; + friend class MPU680x0Device; public: - m68030ATC(m68kcpu *); - virtual ~m68030ATC() { } + m68030ATC(MPU680x0Device *); + ~m68030ATC(); + + // ログレベルを設定する。Object のとは同じ使い方だけど別物。 + void SetLogLevel(int loglevel_); // エントリをサーチ&更新 - const m68030ATCLine& fill_fetch(); - const m68030ATCLine& fill_read(); - const m68030ATCLine& fill_write(); + const m68030ATCLine& fill_fetch(busaddr addr); + const m68030ATCLine& fill_read(busaddr addr); + const m68030ATCLine& fill_write(busaddr addr); // デバッグ用にエントリを検索 - uint64 fill_peek(uint32 laddr, uint fc); + const m68030ATCLine *fill_peek(uint32 laddr, uint fc); // フラッシュ (pflush* 命令から呼ばれる) void flush(); @@ -261,15 +281,7 @@ class m68030ATC m68030ATCTable tables[1] {}; #endif - m68kcpu *cpu = NULL; -}; + int loglevel {}; -extern bool m68030_mmu_translate_fetch(m68kcpu *cpu); -extern bool m68030_mmu_translate_read(m68kcpu *cpu); -extern bool m68030_mmu_translate_write(m68kcpu *cpu); -extern uint64 m68030_mmu_translate_peek(m68kcpu *cpu, uint32 laddr, uint fc, - bool do_search); -extern void mmu_op_pflush(m68kcpu *cpu); -extern void mmu_op_pflush_ea(m68kcpu *cpu); -extern void mmu_op_pload(m68kcpu *cpu); -extern void mmu_op_ptest(m68kcpu *cpu); + MPU680x0Device *cpu {}; +};