--- nono/vm/human68k.cpp 2026/04/29 17:04:50 1.1.1.6 +++ nono/vm/human68k.cpp 2026/04/29 17:04:55 1.1.1.7 @@ -16,6 +16,7 @@ #include "m68030bus.h" #include "m68030core.h" #include "mpu680x0.h" +#include "scheduler.h" #include "vm.h" #include #include @@ -37,10 +38,8 @@ static bool human68k_fline_callback(m68k // コンストラクタ Human68k::Human68k() + : inherited("Human68k") { - logname = "human68k"; - devname = "Human68k"; - assert(gMainApp.human68k_file); human68k_file = gMainApp.human68k_file; human68k_arg = gMainApp.human68k_arg; @@ -111,15 +110,19 @@ Human68k::Init() } else if (isext(human68k_file, ".z")) { r = LoadZ(file, file_size); } else { - if (file[0] == 0x48 && file[1] == 0x55) { - r = LoadX(file, file_size); - } else if (file[0] == 0x60 && file[1] == 0x1a) { - r = LoadZ(file, file_size); - } else { - warnx("Human68k executable \"%s\" cannot identify file type", - human68k_file); - munmap(file, file_size); - return false; + // ELF .o のロードを試行する + r = LoadELF(file, file_size); + if (!r) { + if (file[0] == 0x48 && file[1] == 0x55) { + r = LoadX(file, file_size); + } else if (file[0] == 0x60 && file[1] == 0x1a) { + r = LoadZ(file, file_size); + } else { + warnx("Human68k executable \"%s\" cannot identify file type", + human68k_file); + munmap(file, file_size); + return false; + } } } if (!r) { @@ -273,7 +276,6 @@ Human68k::LoadX(uint8 *file, uint size) return true; } - bool Human68k::LoadZ(uint8 *file, uint size) { @@ -301,6 +303,25 @@ Human68k::LoadZ(uint8 *file, uint size) return true; } +// なぜか m68k ELF .o が読める +bool +Human68k::LoadELF(uint8 *file, uint size) +{ + uint32 r; + + r = gRAM->LoadFile(human68k_file, file, size); + if (r == 0) { + return false; + } + + // XXX LoadFile は実際のセクションサイズを今は返さないので size は適当 + load_addr = r; + load_size = size; + exec_addr = r; + text_size = size; + return true; +} + bool Human68k::LoadMem(uint32 addr, uint8 *src, uint size) { @@ -332,6 +353,14 @@ Human68k::isext(const char *file, const } +// 仮想マシンの中から終了させる +void +Human68k::RequestExit(int code) +{ + gMPU->Release(); + gScheduler->RequestExit(); +} + // fileaddr: Human68k ファイル名のゲストVA // atr: Human68k atr // mode: unix open mode @@ -529,7 +558,8 @@ Human68k::IOCS(m68kcpu *cpu) default: printf("Unimplemented IOCS $%02x\n", RegD(0) & 0xff); - exit(1); + RequestExit(1); + break; } } @@ -552,7 +582,8 @@ Human68k::FLineOp(m68kcpu *cpu) case 0xff00: // EXIT putmsg(1, "DOS EXIT"); - exit(0); + RequestExit(0); + break; case 0xff09: // PRINT { @@ -719,7 +750,8 @@ Human68k::FLineOp(m68kcpu *cpu) { uint32 data = m68030_read_16(cpu, RegA(7)); putmsg(1, "DOS EXIT2(%d)", data); - exit(data); + RequestExit(data); + break; } case 0xffac: // GETFCB @@ -786,7 +818,8 @@ Human68k::FLineOp(m68kcpu *cpu) default: printf("Unimplemented DOSCALL $%02x at $%08X\n", RegIR, RegPPC); - exit(1); + RequestExit(1); + break; } return true; }