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

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