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