--- nono/vm/scheduler.cpp 2026/04/29 17:04:32 1.1.1.3 +++ nono/vm/scheduler.cpp 2026/04/29 17:04:36 1.1.1.4 @@ -1,14 +1,17 @@ // // nono -// Copyright (C) 2017 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // +#include "scheduler.h" +#include "config.h" #include "mainapp.h" #include "mfp.h" -#include "mpu.h" +#include "mpu680x0.h" +#include "mpu88xx0.h" +#include "mythread.h" #include "rtc.h" -#include "scheduler.h" -#include "config.h" #include "vm.h" // VM スケジューラは、仮想時間とイベントを管理する。 @@ -30,21 +33,6 @@ Scheduler::Scheduler() monitor.Init(68, 30); eventlist.clear(); - - // 機種ごとに MPU クロックの初期値は異なる。単位は MHz。 - int defval; - switch (gMainApp.GetVMType()) { - case VMTYPE_X68030: - case VMTYPE_LUNA88K: - defval = 25; - break; - case VMTYPE_LUNA: - defval = 20; - break; - default: - PANIC("unsupported vmtype"); - } - gConfig->Get("mpu-clock").SetDefault(defval); } // デストラクタ @@ -55,12 +43,14 @@ Scheduler::~Scheduler() // 初期化 // ここで mpu_clock が(非ゼロに)初期化されるとこれ以降 putlog() が使える。 -// そのため、Scheduler デバイスを必ずデバイスリストの先頭に置くことで、 -// これ以外のオブジェクトの Init() は putlog() を使ってよいとできる。 +// そのため、Scheduler デバイスをデバイスリストの先頭のほうに置くことで、 +// これ以降のオブジェクトの Init() は putlog() を使ってよいとできる。 +// BusErrDevice だけは Scheduler より先に作るが BusErrDevice に Init() は +// ないので (= 問題は起きないので)、よいことにする。 bool Scheduler::Init() { - const ConfigItem& item = gConfig->Get("mpu-clock"); + const ConfigItem& item = gConfig->Find("mpu-clock"); const std::string& val = item.AsString(); if (val.empty()) { item.Err(); @@ -105,7 +95,7 @@ Scheduler::Run() void * scheduler_run(void *arg) { - pthread_setname_np("VM"); + PTHREAD_SETNAME("VM"); gScheduler->ThreadRun(); return NULL; @@ -272,9 +262,10 @@ Scheduler::ThreadRun() // CPU の STOP 状態をこっちのモードに反映。 // このために SCHED_STOP と CPU_REQ_STOP は同じビット位置にしてある。 + // CPU の HALT はスケジューラ的には STOP と同じ扱いでいい。 if (((mode ^ outer) & SCHED_STOP)) { // 状態変更要求 - if ((outer & CPU_REQ_STOP)) { + if ((outer & (CPU_REQ_STOP | CPU_REQ_HALT)) != 0) { atomic_reqflag |= REQ_STOP; } else { atomic_reqflag |= REQ_RUN; @@ -469,16 +460,16 @@ Scheduler::MonitorUpdate() // 3.123'456'789 3.123'456'789 0123456789012345678901234 $01234567 x = 0; y++; - monitor.Print(x, y, "Set Time"); - monitor.Print(x + 16, y, "Remain Time"); - monitor.Print(x + 32, y, "Description"); - monitor.Print(x + 58, y, "Code"); + monitor.Puts(x, y, "Set Time"); + monitor.Puts(x + 16, y, "Remain Time"); + monitor.Puts(x + 32, y, "Description"); + monitor.Puts(x + 58, y, "Code"); y++; for (const auto& e : gEvents) { uint64 rem; - uint attr; + TA attr; if (e->active) { - attr = 0; + attr = TA::Normal; rem = Cycle2Vtime(e->cycle - cycle); } else { attr = TA::Disable;