--- nono/vm/mainram.cpp 2026/04/29 17:05:29 1.1.1.3 +++ nono/vm/mainram.cpp 2026/04/29 17:05:42 1.1.1.5 @@ -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) { @@ -138,6 +134,8 @@ MainRAMDevice::Init() } case VMType::NEWS: + // 電源オン時に RAM に書き込んでいるため、クリアしない。 + clear_on_boot = false; // 知らんけど 1クロックくらい入れておく。 normal_wait = busdata::Wait(1 * clock_nsec); // NWS-1750 はバースト転送をサポートしていないようだ。 @@ -164,11 +162,11 @@ 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); + warn("MainRAM(%zu bytes)", ram_size); return false; } @@ -182,6 +180,7 @@ MainRAMDevice::Init() // 必要がある。 if (gMainApp.human_mode) { memset(&mainram[0], 0, ram_size); + clear_on_boot = false; } return true; @@ -192,11 +191,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); } @@ -373,21 +368,3 @@ MainRAMDevice::SetWait(uint32 wait_clock 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); -}