Annotation of nono/lib/mainapp.h, revision 1.1.1.20

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
1.1.1.11  root        7: //
                      8: // CLI/GUI 共通のメイン部分
                      9: //
                     10: 
1.1       root       11: #pragma once
                     12: 
1.1.1.20! root       13: #include "header.h"
        !            14: #include <vector>
1.1.1.11  root       15: 
                     16: class Config;
                     17: class Logger;
                     18: class MonitorManager;
1.1.1.20! root       19: class Object;
1.1.1.19  root       20: class ThreadManager;
1.1.1.18  root       21: class UIMessage;
1.1.1.12  root       22: class VM;
                     23: 
                     24: // VM 種別
                     25: enum class VMType {
                     26:        NONE = 0,
                     27:        X68030,
                     28:        LUNA1,
                     29:        LUNA88K,
1.1.1.13  root       30:        NEWS,
1.1.1.14  root       31:        VIRT68K,
1.1.1.12  root       32: };
                     33: 
                     34: // VM ケーパビリティ (ビットマスク表現)
                     35: enum class VMCap : uint32 {
                     36:        NONE    = 0,
                     37:        X68030  = (1U << (int)VMType::X68030),
                     38:        LUNA1   = (1U << (int)VMType::LUNA1),
                     39:        LUNA88K = (1U << (int)VMType::LUNA88K),
1.1.1.13  root       40:        NEWS    = (1U << (int)VMType::NEWS),
1.1.1.14  root       41:        VIRT68K = (1U << (int)VMType::VIRT68K),
1.1.1.12  root       42: 
                     43:        LUNA    = VMCap::LUNA1 | VMCap::LUNA88K,
1.1.1.14  root       44:        M68K    = VMCap::X68030 | VMCap::LUNA1 | VMCap::NEWS | VMCap::VIRT68K,
1.1.1.12  root       45:        M88K    = VMCap::LUNA88K,
                     46:        ALL             = 0xffffffff,
                     47: };
1.1.1.20! root       48: inline VMCap operator|(VMCap a, VMCap b) {
1.1.1.13  root       49:        return static_cast<VMCap>(static_cast<uint32>(a) | static_cast<uint32>(b));
                     50: }
1.1       root       51: 
1.1.1.2   root       52: class MainApp
1.1       root       53: {
1.1.1.2   root       54:  public:
1.1.1.5   root       55:        // Init() の戻り値
                     56:        static const int PASS = -1;             // 実行を継続
                     57: 
1.1.1.19  root       58:        // CPU のバインド方法。
                     59:        // o Neutral は何もしない。
                     60:        // o Binding は、Heavy スレッドを高性能コアにバインドする。
                     61:        //   Light スレッドは
                     62:        //    高性能コアが 3個以上あれば、バインドしない (OS に任せる)。
                     63:        //    高性能コアが 2個以下なら、低性能コアにバインドする
                     64:        enum class AffinityPolicy {
                     65:                Neutral,
                     66:                Binding,
1.1.1.15  root       67:        };
                     68: 
1.1.1.5   root       69:  public:
1.1.1.11  root       70:        MainApp();
                     71:        ~MainApp();
                     72: 
1.1.1.14  root       73:        void Dispose();
                     74: 
1.1.1.7   root       75:        // 初期化 (ステージ1)
1.1.1.18  root       76:        int Init1(int ac, char *av[], std::string (*conv)(const std::string&));
1.1       root       77: 
1.1.1.7   root       78:        // 初期化 (ステージ2)
                     79:        bool Init2();
1.1       root       80: 
1.1.1.12  root       81:        // VM 種別を返す。
1.1.1.2   root       82:        // (Config が持っているのは文字列)
1.1.1.12  root       83:        VMType GetVMType() const { return vmtype; }
1.1.1.2   root       84: 
1.1.1.14  root       85:        // VM 種別を文字列で返す。"luna" とか。
                     86:        const std::string& GetVMTypeStr() const { return vmstr; }
1.1.1.13  root       87: 
                     88:        // たいていは、この機種か?で調べたいことが多いので。
                     89:        bool IsX68030() const   { return (GetVMType() == VMType::X68030); }
                     90:        bool IsLUNA1() const    { return (GetVMType() == VMType::LUNA1); }
                     91:        bool IsLUNA88K() const  { return (GetVMType() == VMType::LUNA88K); }
                     92:        bool IsNEWS() const             { return (GetVMType() == VMType::NEWS); }
1.1.1.14  root       93:        bool IsVIRT68K() const  { return (GetVMType() == VMType::VIRT68K); }
1.1.1.13  root       94: 
1.1.1.12  root       95:        // 現在の VM が指定のケーパビリティを持っているか?
                     96:        bool Has(VMCap cap) const;
1.1.1.3   root       97: 
1.1.1.14  root       98:        // VM 機種名を返す。こっちが "LUNA-I" とかで表示用。
                     99:        const char *GetVMName() const;
                    100: 
1.1.1.11  root      101:        // VM ディレクトリを返す
                    102:        const std::string& GetVMDir() const { return vmdir; }
                    103: 
1.1.1.14  root      104:        // ファイル名から適切なフルパスを検索。
                    105:        std::string SearchFile(const std::string& name) const;
                    106: 
                    107:        // 指定の path を正規化(展開)して返す。
                    108:        // path が絶対パスならそのまま返す。
                    109:        // path が '~' から始まっていればホームディレクトリからの相対パス、
                    110:        // それ以外なら VM ディレクトリからの相対パスとみなして展開する。
                    111:        std::string NormalizePath(const std::string& path) const;
                    112: 
1.1.1.13  root      113:        // オブジェクト登録
                    114:        void RegistObject(Object *obj);
                    115: 
                    116:        // オブジェクト削除
                    117:        void UnregistObject(Object *obj);
                    118: 
                    119:        // オブジェクトのリストを返す
                    120:        const std::vector<Object *>& GetObjects() const { return objects; }
                    121: 
                    122:        // 指定のオブジェクトを返す。こっちは、なければ NULL を返す。
1.1.1.15  root      123:        Object *FindObject(uint id) const;
1.1.1.13  root      124: 
                    125:        // 指定のオブジェクトを返す。こっちは、なければ assert する。
1.1.1.15  root      126:        Object *GetObject(uint id) const;
1.1.1.13  root      127: 
                    128:        // 指定のオブジェクトを型 T* にキャストして返す。
                    129:        // オブジェクトがないかキャストできなければ NULL を返す。
                    130:        template <typename T>
1.1.1.15  root      131:        T *FindObject(uint id) const {
1.1.1.13  root      132:                return dynamic_cast<T *>(FindObject(id));
                    133:        }
                    134: 
                    135:        // 指定のオブジェクトを型 T* にキャストして返す。
                    136:        // オブジェクトがないかキャストできなければ assert する。
                    137:        template <typename T>
1.1.1.15  root      138:        T *GetObject(uint id) const {
1.1.1.13  root      139:                auto dev = FindObject<T>(id);
                    140:                assert(dev);
                    141:                return dev;
                    142:        }
                    143: 
1.1.1.8   root      144:        // ログレベルを設定する。
                    145:        static bool SetLogopt(const std::vector<std::string>&, std::string *errmsg);
                    146: 
                    147:        // ログ名の一覧を表示する
                    148:        static std::vector<std::string> GetLogNames();
                    149: 
1.1.1.19  root      150:        // list を一覧表示をする
                    151:        static void ShowHelpList(FILE*, const std::vector<std::string>& list);
                    152: 
1.1.1.11  root      153:        // Logger を返す
                    154:        Logger *GetLogger() const { return logger.get(); }
1.1.1.2   root      155: 
1.1.1.19  root      156:        // ThreadManager を返す
                    157:        ThreadManager *GetThreadManager() const { return threadmanager.get(); }
                    158: 
1.1.1.18  root      159:        // UIMessage を返す
                    160:        UIMessage *GetUIMessage() const { return uimessage.get(); }
                    161: 
1.1.1.11  root      162:  public:
1.1.1.15  root      163:        // CLI/GUI 区別
                    164:        bool IsCLI() const { return  is_cli; }
                    165:        bool IsGUI() const { return !is_cli; }
1.1.1.2   root      166: 
1.1.1.18  root      167:        // -b(--b): ブレークポイント "[<cpu>,]<addr>[,<skip>]"
1.1.1.11  root      168:        std::vector<std::string> debug_breakaddr {};
1.1.1.2   root      169: 
1.1.1.18  root      170:        // --bi: 命令ブレークポイント "[<cpu>,]<inst>[:<mask>][,<skip>]"
                    171:        std::vector<std::string> debug_breakinst {};
                    172: 
                    173:        // --bv: ベクタブレークポイント "[<cpu>,]<vec1>[-<vec2>][,<skip>]"
                    174:        std::vector<std::string> debug_breakvec {};
                    175: 
1.1.1.14  root      176:        // --bi-exg (とりあえず)
                    177:        bool debug_breakinst_exg {};
                    178: 
1.1.1.16  root      179:        // --console-log: コンソールデバイスの出力ログ。
                    180:        const char *console_logfile {};
                    181: 
1.1.1.2   root      182:        // -d: 起動時にデバッガで停止
1.1.1.5   root      183:        bool debug_on_start {};
1.1.1.2   root      184: 
1.1.1.9   root      185:        // -H: 内蔵 Human68k 風を組み込む。-X による実行ファイル名が必要。
                    186:        bool human_mode {};
                    187: 
1.1.1.2   root      188:        // -M: モニタ名
                    189:        std::string monitor_opt {};
                    190: 
1.1.1.13  root      191:        // -M: 内蔵 MSX-DOS 風を組み込む。-X による実行ファイル名が必要。
                    192:        bool msxdos_mode {};
1.1.1.2   root      193: 
1.1.1.9   root      194:        // -X: ホスト実行ファイル名とその引数
                    195:        const char *exec_file {};
                    196:        std::string exec_arg {};
1.1.1.14  root      197: 
                    198:        // AVX2 を使うかどうか。ホスト CPU 調査と設定ファイル反映後の値。
                    199:        bool enable_avx2 {};
                    200: 
                    201:        // AVX2 をホストがサポートしているかどうか。(こっちは情報表示用)
                    202:        bool detect_avx2 {};
1.1.1.2   root      203: 
1.1.1.15  root      204:        // NEON を使うかどうか。ホスト CPU 調査の設定ファイル反映後の値。
                    205:        bool enable_neon {};
                    206: 
                    207:        // NEON をホストがサポートしているかどうか。(こっちは情報表示用)
                    208:        bool detect_neon {};
                    209: 
1.1.1.19  root      210:        // CPU のバインド方法。
                    211:        AffinityPolicy affinity_policy {};
1.1.1.15  root      212: 
1.1.1.19  root      213:        // 要素数がコア数。高性能コアのところが true。
                    214:        std::vector<bool> fastcore {};
1.1.1.15  root      215: 
                    216:        // ログ表示用
                    217:        std::unique_ptr<Object> hostcpu /*{}*/;
                    218: 
1.1.1.2   root      219:  private:
1.1.1.14  root      220:        // 初期化ステージ1 の下請け。
1.1.1.18  root      221:        int Init1a(int, char *[], std::string (*conv)(const std::string&));
1.1.1.14  root      222:        int Init1b();
                    223: 
1.1.1.17  root      224:        // path を絶対パスにして返す。
                    225:        // 相対パスならカレントディレクトリからのパスとする。
                    226:        static std::string AbsPath(const char *path);
                    227: 
1.1.1.14  root      228:        // path を正規化して返す (下請け)。
                    229:        // path が相対パスなら basedir を起点とする。
1.1.1.17  root      230:        static std::string NormalizePath(const std::string& path,
                    231:                const std::string& basedir);
1.1.1.14  root      232: 
1.1.1.2   root      233:        // ヘルプメッセージを表示する
                    234:        void ShowHelp(bool all) const;
                    235: 
                    236:        // バージョンを表示する
                    237:        void ShowVersion() const;
                    238: 
                    239:        // 引数を処理する
1.1.1.13  root      240:        int ParseOpt(int ac, char *av[]);
1.1.1.2   root      241: 
1.1.1.14  root      242:        // CPU の機能をチェックする。
                    243:        bool CheckCPU();
                    244: 
1.1.1.19  root      245:        // CPU のアフィニティを調べる。
                    246:        bool CheckCPUAffinity();
                    247: 
1.1.1.15  root      248:        // CPU 番号リスト文字列を処理する。
1.1.1.19  root      249:        std::string ParseCPUList(const std::string& input);
1.1.1.15  root      250: 
1.1.1.11  root      251:        // opt を logopt に追加する (-L オプション用)
                    252:        void AddLogopt(const char *opt);
                    253: 
1.1.1.2   root      254:        // -L オプションを処理する
                    255:        bool ParseLogopt();
1.1.1.19  root      256:        // 早期版
                    257:        void ParseLogoptEarly();
1.1.1.2   root      258: 
1.1.1.8   root      259:        // ログレベル1つを設定する。
                    260:        static bool SetLogopt1(const std::string&, std::string *errmsg);
                    261: 
                    262:        // コンパイルされている host netdriver の一覧を表示
                    263:        void ShowHostnet() const;
                    264: 
1.1.1.2   root      265:        // CLI/GUI 区別
1.1.1.5   root      266:        bool is_cli {};
1.1.1.2   root      267: 
1.1.1.11  root      268:        // ログ
                    269:        std::unique_ptr<Logger> logger /*{}*/;
                    270: 
1.1.1.18  root      271:        // UIMessage
                    272:        std::unique_ptr<UIMessage> uimessage /*{}*/;
                    273: 
1.1.1.11  root      274:        // 全オブジェクトへのポインタのリスト (所有はしていない)
                    275:        std::vector<Object*> objects {};
                    276: 
                    277:        // VM
1.1.1.12  root      278:        std::unique_ptr<VM> pVM /*{}*/;
1.1.1.11  root      279: 
                    280:        // 設定項目
                    281:        std::unique_ptr<Config> pConfig /*{}*/;
                    282: 
1.1.1.2   root      283:        // VM 種別
1.1.1.12  root      284:        VMType vmtype {};
1.1.1.13  root      285:        std::string vmstr {};
1.1.1.11  root      286: 
1.1.1.19  root      287:        // スレッドマネージャ
                    288:        std::unique_ptr<ThreadManager> threadmanager /*{}*/;
                    289: 
1.1.1.11  root      290:        // モニタマネージャ
                    291:        std::unique_ptr<MonitorManager> pMonitorManager /*{}*/;
                    292: 
                    293:        // -c: VM ディレクトリ or 設定ファイル
                    294:        std::string vmdir {};
                    295:        std::string vmfile {};
                    296: 
                    297:        // -C: ログをコンソールに出力
                    298:        bool log_to_console {};
                    299: 
                    300:        // -L: ログ指定文字列
                    301:        std::string logopt {};
                    302: 
1.1.1.20! root      303:        // --perf: パフォーマンス測定モード
        !           304:        bool opt_perf {};
        !           305: 
1.1.1.11  root      306:        // --show-config: 設定内容を表示 (1なら通常、2ならall)
                    307:        int show_config {};
                    308: 
                    309:        // -V: パラメータ指定
1.1.1.13  root      310:        std::vector<std::pair<std::string, std::string>> config_options {};
1.1.1.2   root      311: };
                    312: 
                    313: // グローバルインスタンス
                    314: extern MainApp gMainApp;

unix.superglobalmegacorp.com

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