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