--- nono/vm/mpu.cpp 2026/04/29 17:04:45 1.1.1.5 +++ nono/vm/mpu.cpp 2026/04/29 17:05:13 1.1.1.10 @@ -4,35 +4,39 @@ // Licensed under nono-license.txt // +// // MPU 共通部 +// #include "mpu.h" #include "config.h" +#include "scheduler.h" -std::unique_ptr gMPU; +// グローバル参照用 +MPUDevice *gMPU; // コンストラクタ -MPUDevice::MPUDevice() +MPUDevice::MPUDevice(const std::string& objname_) + : inherited(objname_) { - logname = "mpu"; - devname = "MPU"; + ClearAlias(); + AddAlias("MPU"); - // リセット例外を起こすイベント。 - // ハンドラは MPU ごとに異なるので継承クラス側で用意している。 - // (この時点ではまだ Scheduler インスタンスは存在してないが、イベントを - // 実際に Scheduler に登録するのは ResetHard() の時点なので問題ない) - event.dev = this; - event.SetName("MPU"); + exec_event.Regist("MPU Execute"); } // デストラクタ MPUDevice::~MPUDevice() { + gMPU = NULL; } bool MPUDevice::Init() { + gScheduler->ConnectMessage(MessageID::MPU_TRACE, this, + ToMessageCallback(&MPUDevice::TraceMessage)); + // MPU クロック const ConfigItem& item = gConfig->Find("mpu-clock"); const std::string& val = item.AsString(); @@ -50,21 +54,40 @@ MPUDevice::Init() } // 設定の "mpu-clock" は MHz 単位だが、変数 clock_khz は kHz 単位。 clock_khz = (int)(f * 1000); - // 1MHz 以下はエラー。実際 10MHz 以下でもいい気がするけど + // 1MHz 未満はエラー。実際 10MHz 未満でもいい気がするけど if (clock_khz < 1000) { item.Err(); return false; } + clock_nsec = 1000 * 1000 / clock_khz; return true; } -// リセット void -MPUDevice::ResetHard() +MPUDevice::PowerOff() +{ + gScheduler->StopEvent(exec_event); +} + +// MPU トレース状態設定要求メッセージ +void +MPUDevice::TraceMessage(MessageID msgid, uint32 arg) { - // 0 サイクル後にリセット例外を起こす - event.time = 0; - event.code = (uint32)-1; - event.Start(); + // リセット中は SetTrace しない + if (resetting) { + return; + } + + // デバッガから MPU のトレース状態を設定してくれと言われた + SetTrace((bool)arg); } + +// Round Mode (モニタ表示用) +/*static*/ const char * const +MPUDevice::rmstr[4] = { + "Near", + "Zero", + "Minus", + "Plus", +};