--- nono/vm/romemu_virt68k.cpp 2026/04/29 17:05:37 1.1.1.4 +++ nono/vm/romemu_virt68k.cpp 2026/04/29 17:05:59 1.1.1.6 @@ -38,6 +38,7 @@ #include "mainram.h" #include "memorystream.h" #include "mpu680x0.h" +#include "power.h" #include #include #include @@ -47,13 +48,6 @@ Virt68kROMEmuDevice::Virt68kROMEmuDevice() : inherited(OBJ_PROM) { - // 適当 - uint devlen = 4096; - imagebuf.reset(new uint8 [devlen]); - memset(&imagebuf[0], 0, devlen); - - mem = &imagebuf[0]; - mask = devlen - 1; } // デストラクタ @@ -65,6 +59,12 @@ Virt68kROMEmuDevice::~Virt68kROMEmuDevic bool Virt68kROMEmuDevice::Init() { + // ROM 領域を用意。サイズは適当。 + if (AllocROM(2048, 0) == false) { + // エラーメッセージは表示済み。 + return false; + } + mainram = GetMainRAMDevice(); MemoryStreamBE roms(imagebuf.get()); @@ -127,8 +127,10 @@ Virt68kROMEmuDevice::ROM_Init() // カーネル側もそのように想定しているようだ。 info.loadsym = false; - if (mainram->LoadExec(&info) == false) { - warnx("** Couldn't load specified host program."); + if (BootLoader::LoadExec(mainram, &info) == false) { + // エラーメッセージは表示済み。 + auto power = GetPowerDevice(); + power->PushPowerButton(); return -1; } @@ -313,7 +315,7 @@ Virt68kROMEmuDevice::MakeBootInfo(LoadIn WriteBootInfo(ds, bi); } - uint32 ramsize = mainram->GetSize(); + uint32 ramsize = (uint32)mainram->GetSize(); // RAMDISK は (あれば) initrd イメージ置き場で、 // メモリセグメントとは別セグメントにする必要がある。 @@ -330,31 +332,31 @@ Virt68kROMEmuDevice::MakeBootInfo(LoadIn fd = open(cpath, O_RDONLY); if (fd == -1) { - warn("%s \"%s\" open failed", __func__, cpath); + warn("%s \"%s\" open failed", __method__, cpath); return false; } if (fstat(fd, &st) == -1) { - warn("%s \"%s\" fstat failed", __func__, cpath); + warn("%s \"%s\" fstat failed", __method__, cpath); return false; } if (S_ISDIR(st.st_mode)) { - warnx("%s \"%s\" is a directory", __func__, cpath); + warnx("%s \"%s\" is a directory", __method__, cpath); return false; } rdsize = st.st_size; mdata = (uint8 *)mmap(NULL, rdsize, PROT_READ, MAP_PRIVATE, fd, 0); if (mdata == MAP_FAILED) { - warnx("%s \"%s\" mmap failed", __func__, cpath); + warnx("%s \"%s\" mmap failed", __method__, cpath); return false; } // ロード。 LoadInfo rdinfo(cpath, mdata, rdsize); rdinfo.start = (ramsize - rdsize) & ~0xfff; - bool rv = mainram->LoadData(&rdinfo); + bool rv = BootLoader::LoadData(mainram, &rdinfo); munmap(mdata, rdsize); if (rv == false) { warnx("** Couldn't load specified initrd."); @@ -559,7 +561,7 @@ Virt68kROMEmuDevice::WriteBootInfo(IODev break; } putmsg(1, "BootInfo $%08x: %-14s: %s", - stream.GetOffset(), tagname.c_str(), buf.c_str()); + stream.GetAddr(), tagname.c_str(), buf.c_str()); } // 出力。