|
|
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.16 root 156: // --console-log: コンソールデバイスの出力ログ。
157: const char *console_logfile {};
158:
1.1.1.2 root 159: // -d: 起動時にデバッガで停止
1.1.1.5 root 160: bool debug_on_start {};
1.1.1.2 root 161:
1.1.1.9 root 162: // -H: 内蔵 Human68k 風を組み込む。-X による実行ファイル名が必要。
163: bool human_mode {};
164:
1.1.1.2 root 165: // -M: モニタ名
166: std::string monitor_opt {};
167:
1.1.1.13 root 168: // -M: 内蔵 MSX-DOS 風を組み込む。-X による実行ファイル名が必要。
169: bool msxdos_mode {};
1.1.1.2 root 170:
1.1.1.9 root 171: // -X: ホスト実行ファイル名とその引数
172: const char *exec_file {};
173: std::string exec_arg {};
1.1.1.14 root 174:
175: // AVX2 を使うかどうか。ホスト CPU 調査と設定ファイル反映後の値。
176: bool enable_avx2 {};
177:
178: // AVX2 をホストがサポートしているかどうか。(こっちは情報表示用)
179: bool detect_avx2 {};
1.1.1.2 root 180:
1.1.1.15 root 181: // NEON を使うかどうか。ホスト CPU 調査の設定ファイル反映後の値。
182: bool enable_neon {};
183:
184: // NEON をホストがサポートしているかどうか。(こっちは情報表示用)
185: bool detect_neon {};
186:
187: // CPU コアのアフィニティ。
188: CPUAffinity cpu_affinity {};
189:
190: // 要素数がコア数。true のところが cpu_affinity で指定した性質のコアを示す。
191: std::vector<bool> cpu_list {};
192:
193: // ログ表示用
194: std::unique_ptr<Object> hostcpu /*{}*/;
195:
1.1.1.2 root 196: private:
1.1.1.14 root 197: // 初期化ステージ1 の下請け。
198: int Init1a(int, char *[]);
199: int Init1b();
200:
1.1.1.17! root 201: // path を絶対パスにして返す。
! 202: // 相対パスならカレントディレクトリからのパスとする。
! 203: static std::string AbsPath(const char *path);
! 204:
1.1.1.14 root 205: // path を正規化して返す (下請け)。
206: // path が相対パスなら basedir を起点とする。
1.1.1.17! root 207: static std::string NormalizePath(const std::string& path,
! 208: const std::string& basedir);
1.1.1.14 root 209:
1.1.1.2 root 210: // ヘルプメッセージを表示する
211: void ShowHelp(bool all) const;
212:
213: // バージョンを表示する
214: void ShowVersion() const;
215:
216: // 引数を処理する
1.1.1.13 root 217: int ParseOpt(int ac, char *av[]);
1.1.1.2 root 218:
1.1.1.14 root 219: // CPU の機能をチェックする。
220: bool CheckCPU();
221:
1.1.1.15 root 222: // CPU 番号リスト文字列を処理する。
223: std::string ParseCPUList(std::vector<bool>& dst, const std::string& input);
224:
1.1.1.11 root 225: // opt を logopt に追加する (-L オプション用)
226: void AddLogopt(const char *opt);
227:
1.1.1.2 root 228: // -L オプションを処理する
229: bool ParseLogopt();
230:
1.1.1.8 root 231: // ログレベル1つを設定する。
232: static bool SetLogopt1(const std::string&, std::string *errmsg);
233:
1.1.1.13 root 234: // 初回起動時用に SRAM.DAT を作成する。
235: int CreateSRAM();
236:
1.1.1.8 root 237: // コンパイルされている host netdriver の一覧を表示
238: void ShowHostnet() const;
239:
1.1.1.2 root 240: // CLI/GUI 区別
1.1.1.5 root 241: bool is_cli {};
1.1.1.2 root 242:
1.1.1.11 root 243: // ログ
244: std::unique_ptr<Logger> logger /*{}*/;
245:
246: // 全オブジェクトへのポインタのリスト (所有はしていない)
247: std::vector<Object*> objects {};
248:
249: // VM
1.1.1.12 root 250: std::unique_ptr<VM> pVM /*{}*/;
1.1.1.11 root 251:
252: // 設定項目
253: std::unique_ptr<Config> pConfig /*{}*/;
254:
1.1.1.2 root 255: // VM 種別
1.1.1.12 root 256: VMType vmtype {};
1.1.1.13 root 257: std::string vmstr {};
1.1.1.11 root 258:
259: // モニタマネージャ
260: std::unique_ptr<MonitorManager> pMonitorManager /*{}*/;
261:
262: // -c: VM ディレクトリ or 設定ファイル
263: std::string vmdir {};
264: std::string vmfile {};
265:
266: // -C: ログをコンソールに出力
267: bool log_to_console {};
268:
269: // -L: ログ指定文字列
270: std::string logopt {};
271:
272: // --show-config: 設定内容を表示 (1なら通常、2ならall)
273: int show_config {};
274:
275: // -V: パラメータ指定
1.1.1.13 root 276: std::vector<std::pair<std::string, std::string>> config_options {};
277:
278: // --create-sram オプション
279: bool create_sram {};
1.1.1.2 root 280: };
281:
282: // グローバルインスタンス
283: extern MainApp gMainApp;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.