Annotation of nono/vm/mainbus.h, revision 1.1.1.3

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
                      7: //
1.1.1.3 ! root        8: // メインバス (共通部分)
1.1       root        9: //
                     10: 
                     11: #pragma once
                     12: 
                     13: #include "device.h"
1.1.1.3 ! root       14: #include "bus.h"
1.1.1.2   root       15: #include "monitor.h"
1.1       root       16: #include <array>
1.1.1.2   root       17: #include <utility>
1.1       root       18: 
1.1.1.3 ! root       19: // メインバスの素質を持つクラス
        !            20: class MainbusBaseDevice : public IODevice
1.1       root       21: {
1.1.1.3 ! root       22:        using inherited = IODevice;
1.1       root       23:  public:
1.1.1.3 ! root       24:        MainbusBaseDevice(int objid_);
        !            25:        ~MainbusBaseDevice() override;
1.1       root       26: 
1.1.1.3 ! root       27:        // メインバスの初期化
        !            28:        virtual bool InitMainbus() = 0;
1.1       root       29: 
1.1.1.3 ! root       30:        // MPU からのリセット (ここ?)
        !            31:        virtual void ResetByMPU();
1.1       root       32: 
1.1.1.3 ! root       33:        // addr 版 (こっちは呼ばないこと)
        !            34:        busdata Read8(uint32 addr) override final;
        !            35:        busdata Read16(uint32 addr) override final;
        !            36:        busdata Read32(uint32 addr) override final;
        !            37:        busdata Write8(uint32 addr, uint32 data) override final;
        !            38:        busdata Write16(uint32 addr, uint32 data) override final;
        !            39:        busdata Write32(uint32 addr, uint32 data) override final;
        !            40: 
        !            41:        // busaddr 版
        !            42:        virtual busdata Read8(busaddr addr) = 0;
        !            43:        virtual busdata Read16(busaddr addr) = 0;
        !            44:        virtual busdata Read32(busaddr addr) = 0;
        !            45:        virtual busdata Write8(busaddr addr, uint32 data) = 0;
        !            46:        virtual busdata Write16(busaddr addr, uint32 data) = 0;
        !            47:        virtual busdata Write32(busaddr addr, uint32 data) = 0;
        !            48: 
        !            49:        // ブートページを ROM に切り替える
        !            50:        void SwitchBootPageToROM() { SwitchBootPage(true); }
        !            51:        // ブートページを RAM に切り替える
        !            52:        void SwitchBootPageToRAM() { SwitchBootPage(false); }
1.1       root       53: 
1.1.1.3 ! root       54:        // モニタ表示用にデバイス名を整形。
1.1.1.2   root       55:        static std::pair<std::string, TA> FormatDevName(const Device *dev);
                     56: 
1.1.1.3 ! root       57:  protected:
        !            58:        // ブートページを切り替える (内部用)
        !            59:        virtual void SwitchBootPage(bool isrom) = 0;
        !            60: };
        !            61: 
        !            62: // メインバス (システムに1つ)
        !            63: class MainbusDevice : public MainbusBaseDevice
        !            64: {
        !            65:        using inherited = MainbusBaseDevice;
        !            66:  public:
        !            67:        // アクセス状況 (詳細は機種ごと)
        !            68:        static const uint8 ACC_READ             = 0x01;
        !            69:        static const uint8 ACC_WRITE    = 0x02;
1.1       root       70: 
1.1.1.3 ! root       71:  public:
        !            72:        MainbusDevice(int objid_);
        !            73:        ~MainbusDevice() override;
1.1       root       74: 
1.1.1.3 ! root       75:        // ハイパーバイザ的アクセスというか、
        !            76:        // 今となってはミスアライン可能なアクセスというだけかも知れない。
        !            77:        busdata HVRead8(uint32 addr);
        !            78:        busdata HVRead16(uint32 addr);
        !            79:        busdata HVRead32(uint32 addr);
        !            80:        busdata HVWrite8(uint32 addr, uint32 data);
        !            81:        busdata HVWrite16(uint32 addr, uint32 data);
        !            82:        busdata HVWrite32(uint32 addr, uint32 data);
1.1.1.2   root       83: 
1.1.1.3 ! root       84:        uint64 Peek32(uint32 addr);
        !            85: };
        !            86: 
        !            87: // 上位8ビットがテーブルで表せる構造のメインバス (共通部分)
        !            88: class Mainbus24Device : public MainbusDevice
        !            89: {
        !            90:        using inherited = MainbusDevice;
        !            91:  public:
        !            92:        Mainbus24Device();
        !            93:        ~Mainbus24Device() override;
        !            94: 
        !            95:        void ResetHard(bool poweron) override;
        !            96: 
        !            97:        busdata Read8(busaddr addr) override;
        !            98:        busdata Read16(busaddr addr) override;
        !            99:        busdata Read32(busaddr addr) override;
        !           100:        busdata Write8(busaddr addr, uint32 data) override;
        !           101:        busdata Write16(busaddr addr, uint32 data) override;
        !           102:        busdata Write32(busaddr addr, uint32 data) override;
        !           103:        busdata Peek8(uint32 addr) override;
        !           104:        bool Poke8(uint32 addr, uint32 data) override;
        !           105: 
        !           106:  protected:
1.1.1.2   root      107:        DECLARE_MONITOR_CALLBACK(MonitorUpdate);
1.1.1.3 ! root      108:        DECLARE_MONITOR_CALLBACK(MonitorUpdateAccStat);
        !           109: 
        !           110:        void InitAccStat();
        !           111: 
        !           112:        std::array<IODevice *, 256> devtable {};
        !           113: 
        !           114:        // アクセス状況は 32bit 空間全域を 2048 * 2MB ずつ。
        !           115:        // (NEWS は読み出し時にマージする)
        !           116:        std::array<uint8, 2048> accstat_read {};
        !           117:        std::array<uint8, 2048> accstat_write {};
        !           118:        // 表示エリア
        !           119:        std::array<uint8, 256 / 8> accstat_area {};
        !           120:        // 表示用(要素数は機種による)
        !           121:        std::vector<uint8> acc {};
1.1.1.2   root      122: 
                    123:        Monitor monitor { this };
1.1.1.3 ! root      124:        Monitor monitor_accstat { this };
        !           125: 
        !           126:  private:
        !           127:        inline IODevice *Decoder(uint32 addr) const;
1.1       root      128: };
                    129: 
                    130: static inline MainbusDevice *GetMainbusDevice() {
                    131:        return Object::GetObject<MainbusDevice>(OBJ_MAINBUS);
                    132: }

unix.superglobalmegacorp.com

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