--- nono/vm/mainram.cpp 2026/04/29 17:05:29 1.1.1.3 +++ nono/vm/mainram.cpp 2026/04/29 17:06:00 1.1.1.6 @@ -8,20 +8,20 @@ // メインメモリ // +// MainRAM はロングワード単位でホストバイトオーダ配置なので、 +// バイトアクセス、ワードアクセス時は HLB(), HLW() マクロを使用のこと。 + #include "mainram.h" #include "config.h" #include "mainapp.h" #include "mpu.h" #include "prom.h" -// MainRAM はロングワード単位でホストバイトオーダ配置なので、 -// バイトアクセス、ワードアクセス時は HLB(), HLW() マクロを使用のこと。 -/*static*/ std::unique_ptr MainRAMDevice::mainram; - // コンストラクタ MainRAMDevice::MainRAMDevice() : inherited(OBJ_MAINRAM) { + clear_on_boot = true; } // デストラクタ @@ -33,10 +33,6 @@ MainRAMDevice::~MainRAMDevice() bool MainRAMDevice::Init() { - if (inherited::Init() == false) { - return false; - } - const ConfigItem& item = gConfig->Find("ram-size"); int ram_size_MB = item.AsInt(); if (ram_size_MB < 1) { @@ -44,7 +40,7 @@ MainRAMDevice::Init() return false; } - uint32 clock_nsec = mpu->GetClock_nsec(); + uint64 clock_tsec = mpu->GetClock_tsec(); // メモリの下限以外の制約は機種による。 switch (gMainApp.GetVMType()) { @@ -91,8 +87,8 @@ MainRAMDevice::Init() // 通常サイクルは1ウェイトらしい? // バーストウェイトは LUNA-88K の取説からの推論。 - normal_wait = busdata::Wait(1 * clock_nsec); - burst_wait = busdata::Wait(4 * clock_nsec); + normal_wait = busdata::Wait(1 * clock_tsec); + burst_wait = busdata::Wait(4 * clock_tsec); break; } @@ -132,14 +128,16 @@ MainRAMDevice::Init() // これは CMMU 以降のアクセスタイムらしいので、 // リード3クロック、ライト2クロック引いたものをウェイトとしてみる? // XXX 要確認。 - normal_wait = busdata::Wait(2 * clock_nsec); - burst_wait = busdata::Wait(5 * clock_nsec); + normal_wait = busdata::Wait(2 * clock_tsec); + burst_wait = busdata::Wait(5 * clock_tsec); break; } case VMType::NEWS: + // 電源オン時に RAM に書き込んでいるため、クリアしない。 + clear_on_boot = false; // 知らんけど 1クロックくらい入れておく。 - normal_wait = busdata::Wait(1 * clock_nsec); + normal_wait = busdata::Wait(1 * clock_tsec); // NWS-1750 はバースト転送をサポートしていないようだ。 // http://www.ceres.dti.ne.jp/tsutsui/netbsd/port-news68k.html#19991203 break; @@ -164,11 +162,10 @@ MainRAMDevice::Init() PANIC("vmtype=%s not configured", gMainApp.GetVMTypeStr().c_str()); } - ram_size = ram_size_MB * 1024 * 1024; + ram_size = (size_t)ram_size_MB * 1024 * 1024; mainram.reset(new(std::nothrow) uint8[ram_size]); if ((bool)mainram == false) { - errno = ENOMEM; - warn("MainRAM(%u bytes)", ram_size); + warnx("Could not allocate MainRAM(%zu bytes)", ram_size); return false; } @@ -182,6 +179,7 @@ MainRAMDevice::Init() // 必要がある。 if (gMainApp.human_mode) { memset(&mainram[0], 0, ram_size); + clear_on_boot = false; } return true; @@ -192,11 +190,7 @@ void MainRAMDevice::ResetHard(bool poweron) { if (poweron) { - if (gMainApp.human_mode || gMainApp.IsNEWS()) { - // Human モードと NEWS は Init() がメモリに書き込むので - // ここでクリアしない。うーん。 - } else { - // 通常モードならメモリをクリア + if (clear_on_boot) { // XXX ノイズを用意するべき memset(&mainram[0], 0, ram_size); } @@ -369,25 +363,5 @@ MainRAMDevice::WriteMem(uint32 addr, con void MainRAMDevice::SetWait(uint32 wait_clock) { - uint32 clock_nsec = mpu->GetClock_nsec(); - - normal_wait = busdata::Wait(wait_clock * clock_nsec); -} - -// info で指定された実行ファイルをゲストにロードする。 -bool -MainRAMDevice::LoadExec(LoadInfo *info) -{ - BootLoader loader(this); - - return loader.LoadExec(info); -} - -// info で指定されたデータファイルをゲストにロードする。 -bool -MainRAMDevice::LoadData(LoadInfo *info) -{ - BootLoader loader(this); - - return loader.LoadData(info); + normal_wait = busdata::Wait(wait_clock * mpu->GetClock_tsec()); }