--- nono/lib/config.cpp 2026/04/29 17:05:22 1.1.1.14 +++ nono/lib/config.cpp 2026/04/29 17:05:44 1.1.1.19 @@ -31,8 +31,8 @@ Config::Config() Add("cgrom-image", "", VMCap::X68030); // VM 内の時計を同期する時間軸。 - // [ real, virtual ] - Add("clock-sync", "real"); + // "real" か "virtual"。初期値は各 VM クラスで設定している。 + Add("clock-sync"); // デバッガコンソール Add("debugger-driver", "none"); @@ -55,6 +55,10 @@ Config::Config() // RAMDISK (--initrd) Add("exec-initrd", "", VMCap::VIRT68K); + // virt-m68k のブートパラメータ文字列。BootInfo の BI_COMMANDLINE で、 + // NetBSD/virt68k ではルートデバイスの決定に使っている。 + Add("exec-bootparam", "", VMCap::VIRT68K); + // X68030 の拡張メモリサイズ Add("extram-size", "0", VMCap::X68030); @@ -62,47 +66,80 @@ Config::Config() Add("fd-drive", 2, VMCap::X68030); for (int id = 0; id < FDCDevice::MAX_DRIVE; id++) { // 種別とイメージパス - Add(string_format("fd%d-image", id), VMCap::X68030); + Add(string_format("fd%u-image", id), VMCap::X68030); // エミュレータ的に書き込みを禁止するか - Add(string_format("fd%d-writeignore", id), 0, VMCap::X68030); + Add(string_format("fd%u-writeignore", id), 0, VMCap::X68030); } - // X68030 時の FPU の有無。 - Add("fpu-type", "68881", VMCap::X68030); + // 68030 の FPU の有無。 + Add("fpu-type", "68881", VMCap::VIRT68K | VMCap::X68030); // 高速モード。 Add("fast-mode", "0"); // ホスト CPU アクセラレーション。 Add("host-avx2", "auto"); + Add("host-neon", "auto"); - // シリアルポートのホスト側設定 - Add("hostcom-driver", "none"); - Add("hostcom-fallback", 0); - Add("hostcom-tcp-port", 9998); + // CPU アフィニティ (解釈が複雑すぎるので隠しオプション)。 + // "" … 指定しない + // auto … 予約。現状は "" と同じ。 + // low: … Light スレッドを の CPU に割り付ける。 + // high: … Heavy スレッドを の CPU に割り付ける。 + // perf: … Heavy スレッドを の CPU に、 + // Light スレッドをその反集合の CPU に割り付ける。 + Add(".host-cpu-affinity", "auto"); + + // シリアルポートのホスト側設定。 + // fallback は少しの間残しておくがそのうち消す。 + Add("hostcom0-driver", "none"); + Add("hostcom0-fallback", 0); + Add("hostcom0-tcp-port", 9998); + + Add("hostcom1-driver", "none", VMCap::LUNA); + Add("hostcom1-fallback", 0, VMCap::LUNA); + Add("hostcom1-tcp-port", 9997, VMCap::LUNA); + + Add("hostcom2-driver", "none", VMCap::LUNA); + Add("hostcom2-fallback", 0, VMCap::LUNA); + Add("hostcom2-tcp-port", 9996, VMCap::LUNA); + + AddAlias("hostcom-driver", "hostcom0-driver"); + AddAlias("hostcom-fallback", "hostcom0-fallback"); + AddAlias("hostcom-tcp-port", "hostcom0-tcp-port"); // キーボードの入力モード Add("hostkbd-input", "char", VMCap::LUNA | VMCap::X68030); // ネットワークのホスト側設定。 // (0 と 1 で -driver の初期値が違う) + // fallback は少しの間残しておくがそのうち消す。 Add("hostnet0-driver", "auto"); Add("hostnet0-fallback", 0); Add("hostnet0-afpacket-ifname", "auto"); Add("hostnet0-bpf-ifname", "auto"); Add("hostnet0-tap-devpath", "auto"); + Add("hostnet0-usermode-hostfwd",""); + Add("hostnet0-usermode-net", "10.8.0.0/24"); + Add("hostnet0-usermode-net6", "fd08::/64"); Add("hostnet1-driver", "none", VMCap::X68030); Add("hostnet1-fallback", 0, VMCap::X68030); Add("hostnet1-afpacket-ifname", "auto", VMCap::X68030); Add("hostnet1-bpf-ifname", "auto", VMCap::X68030); Add("hostnet1-tap-devpath", "auto", VMCap::X68030); + Add("hostnet1-usermode-hostfwd","", VMCap::X68030); + Add("hostnet1-usermode-net", "10.8.0.0/24", VMCap::X68030); + Add("hostnet1-usermode-net6", "fd08::/64", VMCap::X68030); AddAlias("hostnet-driver", "hostnet0-driver"); AddAlias("hostnet-fallback", "hostnet0-fallback"); AddAlias("hostnet-afpacket-ifname", "hostnet0-afpacket-ifname"); AddAlias("hostnet-bpf-ifname", "hostnet0-bpf-ifname"); AddAlias("hostnet-tap-devpath", "hostnet0-tap-devpath"); + AddAlias("hostnet-usermode-hostfwd","hostnet0-usermode-hostfwd"); + AddAlias("hostnet-usermode-net", "hostnet0-usermode-net"); + AddAlias("hostnet-usermode-net6", "hostnet0-usermode-net6"); // IPLROM1/2 ファイルパス。なければ内蔵 ROM。 Add("iplrom1-image", "", VMCap::X68030); @@ -126,6 +163,11 @@ Config::Config() // m88100 の別名ニーモニックを併記する。 Add(".m88k-altname", 0, VMCap::M88K); + // m88100/88200 のバージョン。 + // 初期値はコンストラクタ側で用意している。 + Add("m88100-version", 0, VMCap::M88K); + Add("m88200-version", 0, VMCap::M88K); + // 画面サイズ。 Add("mainview-scale", "1"); @@ -142,6 +184,9 @@ Config::Config() // M88100 で疑似 STOP 状態をサポートする Add("mpu-pseudo-stop", 1, VMCap::M88K); + // MPU 種別。現状 m68k のみ。初期値は機種依存。 + Add("mpu-type", "", VMCap::M68K); + // Nereid Add("nereid0-enable", 0, VMCap::X68030); Add("nereid1-enable", 0, VMCap::X68030); @@ -188,26 +233,29 @@ Config::Config() for (int id = 0; id < 8; id++) { auto scsicap = VMCap::LUNA | VMCap::X68030; // 種別とイメージパス - Add(string_format("spc0-id%d-image", id), scsicap); - // エミュレータ的に書き込みを禁止するか - Add(string_format("spc0-id%d-writeignore", id), 0, scsicap); + Add(string_format("spc0-id%u-image", id), scsicap); // エミュレータ的に書き込みを禁止するか - // (後方互換、十分不要になった頃に削除する) - Add(string_format("spc0-id%d-writeprotect", id), 0, scsicap); + Add(string_format("spc0-id%u-writeignore", id), 0, scsicap); // シークタイム [msec] - Add(string_format("spc0-id%d-seektime", id), 0, scsicap); + Add(string_format("spc0-id%u-seektime", id), 0, scsicap); } // SRAM の RAM 容量を同期するか。 Add("sram-sync-ramsize", 1, VMCap::X68030); // virtio 設定。 + auto viocap = VMCap::VIRT68K; for (int id = 0; id < 8; id++) { - auto viocap = VMCap::VIRT68K; // イメージパス - Add(string_format("virtio-block%d-image", id), viocap); + Add(string_format("virtio-block%u-image", id), viocap); + // エミュレータ的に書き込みを禁止するか + Add(string_format("virtio-block%u-writeignore", id), 0, viocap); + } + for (int id = 0; id < 8; id++) { + // 種別とイメージパス + Add(string_format("virtio-scsi-id%u-image", id), viocap); // エミュレータ的に書き込みを禁止するか - Add(string_format("virtio-block%d-writeignore", id), 0, viocap); + Add(string_format("virtio-scsi-id%u-writeignore", id), 0, viocap); } // Windrv パス。 @@ -215,6 +263,9 @@ Config::Config() // X68030 で FC2 ピンを切るか。 Add("x68k-cut-fc2", 1, VMCap::X68030); + + // XP プロセッサのクロック (MHz 単位の実数、小数点以下は3桁まで)。 + Add("xp-clock", "6.144", VMCap::LUNA); } // デストラクタ @@ -286,9 +337,9 @@ Config::Update(const ConfigFile& file) for (const auto& pair : file.lines) { const std::string& line = pair.first; - int lineno = pair.second; + uint lineno = pair.second; - auto where = string_format("%s:%d", file.filepath.c_str(), lineno); + auto where = string_format("%s:%u", file.filepath.c_str(), lineno); if (UpdateLine(line, file.from, where) == false) { return false; } @@ -297,29 +348,84 @@ Config::Update(const ConfigFile& file) return true; } +#define UpdateLinePerf(str) do { \ + if (UpdateLine(str, ConfigItem::FromPerf, where) == false) \ + return false; \ +} while (0) + // コマンドラインオプションで更新 bool Config::Update(const std::string& line, const std::string& optname) { assert(fixed == false); - return UpdateLine(line, ConfigItem::FromOption, optname); + // パフォーマンス測定用オプション --perf が指定されたら + // line="--perf" という非正規の書式で呼ばれるので、ここで展開する。 + if (line == "--perf") { + // -V prom-image=PROM.DAT はパスの問題があるので、各自で追加指定 + // する必要がある。 + std::string where = "--perf -V"; + UpdateLinePerf(".rtc-force-fixed=1"); + UpdateLinePerf("clock-sync=virtual"); + UpdateLinePerf("fast-mode=1"); + UpdateLinePerf("fd0-writeignore=1"); + UpdateLinePerf("fd1-writeignore=1"); + UpdateLinePerf("fd2-writeignore=1"); + UpdateLinePerf("fd3-writeignore=1"); + UpdateLinePerf("ethernet-macaddr=02:00:00:00:00:01"); + UpdateLinePerf("hostcom-driver=none"); + UpdateLinePerf("hostnet-driver=none"); + UpdateLinePerf("luna-dipsw1=11110111"); + UpdateLinePerf("luna-video-plane=4"); + UpdateLinePerf("spc0-id0-writeignore=1"); + UpdateLinePerf("spc0-id1-writeignore=1"); + UpdateLinePerf("spc0-id2-writeignore=1"); + UpdateLinePerf("spc0-id3-writeignore=1"); + UpdateLinePerf("spc0-id4-writeignore=1"); + UpdateLinePerf("spc0-id5-writeignore=1"); + UpdateLinePerf("spc0-id6-writeignore=1"); + UpdateLinePerf("virtio-block0-writeignore=1"); + UpdateLinePerf("virtio-block1-writeignore=1"); + UpdateLinePerf("virtio-block2-writeignore=1"); + UpdateLinePerf("virtio-block3-writeignore=1"); + UpdateLinePerf("virtio-block4-writeignore=1"); + UpdateLinePerf("virtio-block5-writeignore=1"); + UpdateLinePerf("virtio-block6-writeignore=1"); + return true; + } else { + return UpdateLine(line, ConfigItem::FromOption, optname); + } +} + +// 実行中に動的に変更する。 +bool +Config::UpdateRunning(const std::string& line) +{ + return UpdateLine(line, ConfigItem::FromRunning, ""); } // 更新1行分の共通処理。 -// キーが見付からない場合、コマンドラインからならエラーとし、 -// それ以外からの場合は警告のみで無視する。 -// エラーが起きたらエラーメッセージを表示して false を返す。 +// キーが見付からない場合は from によって動作が異なる。 +// o 共通設定ファイルでなら、何もせず true を返す。 +// o VM 設定ファイルでなら、エラーメッセージを表示するが true を返す。 +// o コマンドラインでなら、エラーメッセージを表示して false を返す。 +// 起動前のこれらでは、false は実行中止を示す。 +// また +// o 実行中の変更なら、何もせず false を返す。 +// この場合の false はキーが見付からなかったことを意味する。 +// (文法エラーの場合にも false が返るが、それはプログラムエラー) bool Config::UpdateLine(const std::string& line, ConfigItem::from_t from, const std::string& where) { std::string key; std::string val; + std::string head; // キーと値に分解 if (SplitKeyVal(&key, &val, line) == false) { - ConfigItem::PrintErr(from, where, "", line, "Syntax error"); + head = ConfigItem::ErrFrom(from, where, "", line); + warnx("%s: Syntax error", head.c_str()); return false; } @@ -329,9 +435,11 @@ Config::UpdateLine(const std::string& li // キーで検索 ConfigItem *itemptr = FindItem(key); if (itemptr == NULL) { + head = ConfigItem::ErrFrom(from, where, key, val); switch (from) { default: case ConfigItem::FromHome: + case ConfigItem::FromPerf: // 共通設定ファイルなら黙って無視する。 // このファイルには他機種向けの設定も並んでいる可能性があるため // 無視してくれないと困る。 @@ -341,13 +449,17 @@ Config::UpdateLine(const std::string& li // VM 設定ファイルなら警告のみで無視する。 // このファイルに他機種向けの設定があるのはおかしいが // 止めるほどではない。 - ConfigItem::PrintErr(from, where, key, val, "Unknown key, ignored"); + warnx("%s: Unknown key, ignored", head.c_str()); return true; case ConfigItem::FromOption: // コマンドラインからの場合はエラーにする。 - ConfigItem::PrintErr(from, where, key, val, "Unknown key"); + warnx("%s: Unknown key", head.c_str()); return false; + + case ConfigItem::FromRunning: + // 実行中なら、黙って無視する。 + return true; } } @@ -422,7 +534,7 @@ Config::Show(bool all) const std::string buf = string_format("%s=\"%s\"", item.key.c_str(), item.value.c_str()); if (buf.size() < 40) { - int n = ((40 - buf.size()) + 7) / 8; + uint n = ((40 - buf.size()) + 7) / 8; buf.append(n, '\t'); } else { buf.push_back('\t'); @@ -440,9 +552,12 @@ Config::Show(bool all) const case ConfigItem::FromOption: fromstr = "option " + item.where; break; + case ConfigItem::FromPerf: + fromstr = "option --perf"; + break; default: - fromstr = string_format("corrupted item.from=%d for key=%s", - (int)item.from, item.key.c_str()); + fromstr = string_format("corrupted item.from=%u for key=%s", + (uint)item.from, item.key.c_str()); break; } @@ -505,7 +620,7 @@ Config::Fix() assert(fixed == false); // ここで、この機種に不要な変数を削除する。 - // が、その前にその変数がユーザから指定されていればエラーにする。 + // その変数がユーザから指定されていればエラーにする。 for (auto it = list.begin(); it != list.end(); ) { ConfigItem& item = *it; VMCap vmcap = item.GetVMCap(); @@ -574,6 +689,59 @@ ConfigItem::TryDouble(double *val) const return true; } +// b を e 乗した整数を返す。 +static inline int +ipow(int b, int e) +{ + int rv = 1; + + for (int i = 0; i < e; i++) { + rv *= b; + } + return rv; +} + +// 値を固定小数点値として取得してみる。 +// digit は小数点以下の桁数で、それ以下は四捨五入する。 +// 値が "1.2345" で digit=3 なら *val = 1235 を返す。 +bool +ConfigItem::TryFixedDecimal(int *val, int digit) const +{ + char *endp; + bool neg = false; + + if (value.empty()) { + return false; + } + + errno = 0; + int r = strtol(value.c_str(), &endp, 10); + if (errno == ERANGE || !(*endp == '\0' || *endp == '.')) { + return false; + } + if (r < 0) { + r = -r; + neg = true; + } + r *= ipow(10, digit); + if (*endp == '.') { + char *p = endp + 1; + errno = 0; + int f = strtol(p, &endp, 10); + if (errno == ERANGE || *endp != '\0') { + return false; + } + int n = endp - p; + if (n <= digit) { + r += f * ipow(10, digit - n); + } else { + r += f / ipow(10, n - digit) + (p[digit] >= '5'); + } + } + *val = neg ? -r : r; + return true; +} + // デフォルト値を差し替える void ConfigItem::SetDefault(const std::string& val) @@ -583,6 +751,33 @@ ConfigItem::SetDefault(const std::string } } +std::string +ConfigItem::ErrMsg() const +{ + // 定型文 + return ErrMsg("Invalid argument"); +} + +std::string +ConfigItem::ErrMsg(const char *fmt, ...) const +{ + char buf[1024]; + va_list ap; + + va_start(ap, fmt); + vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + + std::string msg(buf); + return ErrMsg(msg); +} + +std::string +ConfigItem::ErrMsg(const std::string& msg) const +{ + return ErrFrom(from, where, key, value) + ": " + msg; +} + void ConfigItem::Err() const { @@ -607,14 +802,14 @@ ConfigItem::Err(const char *fmt, ...) co void ConfigItem::Err(const std::string& msg) const { - PrintErr(from, where, key, value, msg); + warnx("%s", ErrMsg(msg).c_str()); } -// この item についてエラーを表示する。 +// この item のエラーメッセージのヘッダ部分を返す。 // key=val の '=' がない場合のみ key を空、value を行全体として呼ぶ。 -/*static*/ void -ConfigItem::PrintErr(ConfigItem::from_t from, const std::string& where, - const std::string& key, const std::string& value, const std::string& msg) +/*static*/ std::string +ConfigItem::ErrFrom(ConfigItem::from_t from, const std::string& where, + const std::string& key, const std::string& value) { std::string fromstr; @@ -637,6 +832,7 @@ ConfigItem::PrintErr(ConfigItem::from_t break; case FromOption: + case FromPerf: // コマンドラインオプションの場合は where は // "--fontsize" とか "-V" なので、 // "-V" なら (key =) value を追加し、 @@ -652,12 +848,12 @@ ConfigItem::PrintErr(ConfigItem::from_t break; default: - fromstr = string_format("corrupted item.from=%d for key=%s", - (int)from, key.c_str()); + fromstr = string_format("corrupted item.from=%u for key=%s", + (uint)from, key.c_str()); break; } - warnx("%s: %s", fromstr.c_str(), msg.c_str()); + return fromstr; } @@ -687,6 +883,10 @@ ConfigFile::Load() char buf[1024]; FILE *fp; + if (filepath.empty()) { + return true; + } + fp = fopen(filepath.c_str(), "r"); if (fp == NULL) { if (errno == ENOENT) {