--- nono/vm/device.cpp 2026/04/29 17:04:55 1.1.1.7 +++ nono/vm/device.cpp 2026/04/29 17:05:51 1.1.1.13 @@ -4,34 +4,27 @@ // Licensed under nono-license.txt // -#include "device.h" -#include "vm.h" +// +// デバイスの基本クラスなど +// -// 全デバイスリスト -std::vector gDevices; +#include "device.h" +#include "mpu.h" +#include "scheduler.h" // // Device // // コンストラクタ -Device::Device(const std::string& objname_) - : inherited(objname_) +Device::Device(uint objid_) + : inherited(objid_) { - gDevices.push_back(this); } // デストラクタ Device::~Device() { - // 自分自身をリストから削除する - // XXX マルチスレッドな状況からは呼ばれないはず? - for (auto it = gDevices.begin(); it != gDevices.end(); ++it) { - if (*it == this) { - gDevices.erase(it); - break; - } - } } bool @@ -41,33 +34,58 @@ Device::Create() } bool -Device::Init() +Device::Create2() { return true; } -bool -Device::Apply() +void +Device::EarlyInit() { - return true; + mpu = GetMPUDevice(); + scheduler = GetScheduler(); } bool -Device::PowerOn() +Device::Init() { return true; } -bool +void +Device::ResetHard(bool poweron) +{ +} + +void Device::PowerOff() { - return true; } -// 本体リセットスイッチによるリセット +// ログ表示。 +// VM デバイスでは、仮想時間、PC、オブジェクト名を表示する。 void -Device::ResetHard() +Device::putlogn(const char *fmt, ...) const { + char buf[1024]; + va_list ap; + uint64 vt; + int len; + + vt = scheduler->GetVirtTime(); + len = snprintf(buf, sizeof(buf), "%4u.%03u'%03u'%03u %08x %s ", + (uint)(vt / 1000 / 1000 / 1000), + (uint)((vt / 1000 / 1000) % 1000), + (uint)((vt / 1000) % 1000), + (uint)(vt % 1000), + mpu->GetPPC(), + GetName().c_str()); + + va_start(ap, fmt); + vsnprintf(buf + len, sizeof(buf) - len, fmt, ap); + va_end(ap); + + WriteLog(buf); } @@ -76,11 +94,9 @@ Device::ResetHard() // // コンストラクタ -IODevice::IODevice(const std::string& objname_) - : inherited(objname_) +IODevice::IODevice(uint objid_) + : inherited(objid_) { - devaddr = 0; - devlen = 0; } // デストラクタ @@ -88,196 +104,50 @@ IODevice::~IODevice() { } -uint64 -IODevice::Read8(uint32 addr) -{ - return 0xff; -} - -uint64 -IODevice::Read16(uint32 addr) -{ - return (Read8(addr) << 8) | Read8(addr + 1); -} - -uint64 -IODevice::Read32(uint32 addr) -{ - return (Read16(addr) << 16) | Read16(addr + 2); -} - -uint64 -IODevice::Write8(uint32 addr, uint32 data) +busdata +IODevice::Read(busaddr addr) { return 0; } -uint64 -IODevice::Write16(uint32 addr, uint32 data) +busdata +IODevice::Write(busaddr addr, uint32 data) { - int64 berr; - - berr = Write8(addr, data >> 8); - if (berr < 0) - return berr; - berr = Write8(addr + 1, data & 0xff); - if (berr < 0) - return berr; return 0; } -uint64 -IODevice::Write32(uint32 addr, uint32 data) +busdata +IODevice::ReadBurst16(busaddr addr, uint32 *dst) { - int64 berr; - - berr = Write16(addr, data >> 16); - if (berr < 0) - return berr; - berr = Write16(addr + 2, data & 0xffff); - if (berr < 0) - return berr; - return 0; + return BusData::BusErr; } -uint64 -IODevice::Peek8(uint32 addr) +busdata +IODevice::WriteBurst16(busaddr addr, const uint32 *src) { - return 0xff; + return BusData::BusErr; } - -// -// バスエラー -// - -std::unique_ptr gBusErr; - -// コンストラクタ -BusErrDevice::BusErrDevice() - : inherited("(BusErr)") -{ - ClearAlias(); - AddAlias("BusErr"); - - devaddr = -1; // XXX どうしたもんか -} - -BusErrDevice::~BusErrDevice() +busdata +IODevice::Read1(uint32 addr) { -} - -uint64 -BusErrDevice::Read8(uint32 addr) -{ - putlog(1, "$%08x.b", addr); - return (uint64)-1; -} - -uint64 -BusErrDevice::Read16(uint32 addr) -{ - putlog(1, "$%08x.w", addr); - return (uint64)-1; -} - -uint64 -BusErrDevice::Read32(uint32 addr) -{ - putlog(1, "$%08x.l", addr); - return (uint64)-1; -} - -uint64 -BusErrDevice::Write8(uint32 addr, uint32 data) -{ - putlog(1, "$%08x.b <- %02X", addr, data); - return (uint64)-1; -} - -uint64 -BusErrDevice::Write16(uint32 addr, uint32 data) -{ - putlog(1, "$%08x.w <- %04X", addr, data); - return (uint64)-1; -} - -uint64 -BusErrDevice::Write32(uint32 addr, uint32 data) -{ - putlog(1, "$%08x.l <- %08X", addr, data); - return (uint64)-1; -} - -uint64 -BusErrDevice::Peek8(uint32 addr) -{ - return (uint64)-1; -} - - -// -// 何もしないデバイス -// - -std::unique_ptr gNopIO; - -// コンストラクタ -NopIODevice::NopIODevice() - : inherited("(NopIO)") -{ - ClearAlias(); - AddAlias("NopIO"); -} - -NopIODevice::~NopIODevice() -{ -} - -uint64 -NopIODevice::Read8(uint32 addr) -{ - putlog(1, "$%08x.b", addr); return 0xff; } -uint64 -NopIODevice::Read16(uint32 addr) -{ - putlog(1, "$%08x.w", addr); - return 0xffff; -} - -uint64 -NopIODevice::Read32(uint32 addr) +busdata +IODevice::Write1(uint32 addr, uint32 data) { - putlog(1, "$%08x.l", addr); - return 0xffffffff; -} - -uint64 -NopIODevice::Write8(uint32 addr, uint32 data) -{ - putlog(1, "$%08x.b <- $%02x", addr, data); return 0; } -uint64 -NopIODevice::Write16(uint32 addr, uint32 data) +busdata +IODevice::Peek1(uint32 addr) { - putlog(1, "$%08x.w <- $%04x", addr, data); - return 0; -} - -uint64 -NopIODevice::Write32(uint32 addr, uint32 data) -{ - putlog(1, "$%08x.l <- $%08x", addr, data); - return 0; + return 0xff; } -uint64 -NopIODevice::Peek8(uint32 addr) +bool +IODevice::Poke1(uint32 addr, uint32 data) { - return 0xff; + return false; }