--- nono/vm/device.cpp 2026/04/29 17:05:11 1.1.1.8 +++ nono/vm/device.cpp 2026/04/29 17:05:18 1.1.1.9 @@ -17,8 +17,8 @@ // // コンストラクタ -Device::Device(const std::string& objname_) - : inherited(objname_) +Device::Device(int objid_) + : inherited(objid_) { } @@ -36,6 +36,9 @@ Device::Create() bool Device::Init() { + mpu = GetMPUDevice(); + scheduler = GetScheduler(); + return true; } @@ -65,13 +68,13 @@ Device::putlogn(const char *fmt, ...) co uint64 vt; int len; - vt = gScheduler->GetVirtTime(); + vt = scheduler->GetVirtTime(); len = snprintf(buf, sizeof(buf), "%4d.%03d'%03d'%03d %08x %s ", (int)(vt / 1000 / 1000 / 1000), (int)((vt / 1000 / 1000) % 1000), (int)((vt / 1000) % 1000), (int)(vt % 1000), - gMPU->GetPPC(), + mpu->GetPPC(), GetName().c_str()); va_start(ap, fmt); @@ -87,11 +90,9 @@ Device::putlogn(const char *fmt, ...) co // // コンストラクタ -IODevice::IODevice(const std::string& objname_) - : inherited(objname_) +IODevice::IODevice(int objid_) + : inherited(objid_) { - devaddr = 0; - devlen = 0; } // デストラクタ @@ -99,6 +100,17 @@ IODevice::~IODevice() { } +// 初期化 +bool +IODevice::Init() +{ + if (inherited::Init() == false) { + return false; + } + + return true; +} + uint64 IODevice::Read8(uint32 addr) { @@ -157,28 +169,66 @@ IODevice::Peek8(uint32 addr) return 0xff; } +uint64 +IODevice::Poke8(uint32 addr, uint32 data) +{ + return (uint64)-1; +} + +uint64 +IODevice::Poke(uint32 addr, uint32 data) +{ + return (uint64)-1; +} + // -// バスエラー +// IOContainerDevice // -// グローバル参照用 -BusErrDevice *gBusErr; +// コンストラクタ +IOContainerDevice::IOContainerDevice(int objid_) + : inherited(objid_) +{ +} + +// デストラクタ +IOContainerDevice::~IOContainerDevice() +{ +} + +// このアドレスを担当する IODevice を再帰的に探して返す。 +IODevice * +IOContainerDevice::FindDevice(uint32 addr) const +{ + IODevice *d = GetDevice(addr); + IOContainerDevice *cd = dynamic_cast(d); + + if (cd) { + // 次段はコンテナデバイス + return cd->FindDevice(addr); + } else { + // 次段は終端のデバイス + return d; + } +} + + +// +// バスエラー +// // コンストラクタ BusErrDevice::BusErrDevice() - : inherited("(BusErr)") + : inherited(OBJ_BUSERR) { ClearAlias(); AddAlias("BusErr"); - - devaddr = -1; // XXX どうしたもんか } // デストラクタ BusErrDevice::~BusErrDevice() { - gBusErr = NULL; } uint64 @@ -234,12 +284,9 @@ BusErrDevice::Peek8(uint32 addr) // 何もしないデバイス // -// グローバル参照用 -NopIODevice *gNopIO; - // コンストラクタ NopIODevice::NopIODevice() - : inherited("(NopIO)") + : inherited(OBJ_NOPIO) { ClearAlias(); AddAlias("NopIO"); @@ -248,7 +295,6 @@ NopIODevice::NopIODevice() // デストラクタ NopIODevice::~NopIODevice() { - gNopIO = NULL; } uint64