--- nono/vm/bootloader.cpp 2026/04/29 17:05:28 1.1.1.3 +++ nono/vm/bootloader.cpp 2026/04/29 17:05:59 1.1.1.5 @@ -30,6 +30,22 @@ #include #include +// info で指定された実行ファイルを mainram にロードする。 +/*static*/ bool +BootLoader::LoadExec(MainRAMDevice *mainram_, LoadInfo *info) +{ + BootLoader loader(mainram_); + return loader.LoadExec(info); +} + +// info で指定されたデータファイルを mainram にロードする。 +/*static*/ bool +BootLoader::LoadData(MainRAMDevice *mainram_, LoadInfo *info) +{ + BootLoader loader(mainram_); + return loader.LoadData(info); +} + // コンストラクタ BootLoader::BootLoader(MainRAMDevice *mainram_) : inherited(OBJ_BOOTLOADER) @@ -96,30 +112,30 @@ BootLoader::LoadExecFromFile(LoadInfo *i fd = open(info->path, O_RDONLY); if (fd == -1) { - warn("%s \"%s\" open failed", __func__, info->path); + warn("%s \"%s\"", __method__, info->path); return false; } if (fstat(fd, &st) == -1) { - warn("%s \"%s\" fstat failed", __func__, info->path); + warn("%s \"%s\" fstat failed", __method__, info->path); return false; } if (!S_ISREG(st.st_mode)) { - warnx("%s \"%s\" not a regular file", __func__, info->path); + warnx("%s \"%s\" not a regular file", __method__, info->path); return false; } // 今の所マジック判定は最初の4バイトで出来るので if (st.st_size < 4) { - warnx("%s \"%s\" file too short", __func__, info->path); + warnx("%s \"%s\" file too short", __method__, info->path); return false; } filesize = st.st_size; filedata = (uint8 *)mmap(NULL, filesize, PROT_READ, MAP_PRIVATE, fd, 0); if (filedata == MAP_FAILED) { - warn("%s \"%s\" mmap failed", __func__, info->path); + warn("%s \"%s\" mmap failed", __method__, info->path); return false; } @@ -275,7 +291,7 @@ BootLoader::Load_aout(LoadInfo *info) "(text=%u + data=%u, filesize=%d); loading %d bytes", __func__, info->path, aout.textsize, aout.datasize, (int)info->size, copylen); - /* FALLTHROUGH */ + // FALLTHROUGH } if (aout.entry + copylen > mainram->GetSize()) { @@ -502,15 +518,15 @@ BootLoader::Load_elf32_exec(LoadInfo *in return false; } - // 読み込み開始位置。 - // 実際にはカーネルのプログラムヘッダは1つのはずだけど一応。 + // 読み込み開始位置を一応覚えておく。 + // 隙間のある2つ以上のヘッダが来られるとあまり意味はなくなるが。 if (j == 0) { info->start = p_vaddr; } else { info->start = std::min(info->start, p_vaddr); } - ds.SetOffset(p_vaddr); + ds.SetAddr(p_vaddr); ds.WriteMem(info->data + p_offset, p_filesz); for (int i = p_filesz; i < p_memsz; i++) { ds.Write1(0); @@ -530,7 +546,7 @@ BootLoader::Load_elf32_exec(LoadInfo *in } } - info->end = ds.GetOffset(); + info->end = ds.GetAddr(); info->sym = info->end; // シンボルテーブルをロード。出来なくても構わないので続行する。 @@ -937,7 +953,7 @@ BootLoader::Load_elf32_rel(LoadInfo *inf info->start = entry; info->entry = entry; - info->end = ds.GetOffset(); + info->end = ds.GetAddr(); return true; }