--- nono/vm/device.cpp 2026/04/29 17:04:44 1.1.1.4 +++ nono/vm/device.cpp 2026/04/29 17:05:25 1.1.1.10 @@ -4,20 +4,22 @@ // 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() +Device::Device(int objid_) + : inherited(objid_) { - gDevices.push_back(this); } // デストラクタ @@ -34,6 +36,9 @@ Device::Create() bool Device::Init() { + mpu = GetMPUDevice(); + scheduler = GetScheduler(); + return true; } @@ -43,28 +48,40 @@ Device::Apply() return true; } -bool -Device::PowerOn() +void +Device::ResetHard(bool poweron) { - return true; } -bool +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), "%4d.%03d'%03d'%03d %08x %s ", + (int)(vt / 1000 / 1000 / 1000), + (int)((vt / 1000 / 1000) % 1000), + (int)((vt / 1000) % 1000), + (int)(vt % 1000), + mpu->GetPPC(), + GetName().c_str()); + + va_start(ap, fmt); + vsnprintf(buf + len, sizeof(buf) - len, fmt, ap); + va_end(ap); -// MPU の RESET 命令によるリセット -void -Device::ResetSoft() -{ + WriteLog(buf); } @@ -73,10 +90,9 @@ Device::ResetSoft() // // コンストラクタ -IODevice::IODevice() +IODevice::IODevice(int objid_) + : inherited(objid_) { - devaddr = 0; - devlen = 0; } // デストラクタ @@ -84,31 +100,42 @@ IODevice::~IODevice() { } -uint64 +// 初期化 +bool +IODevice::Init() +{ + if (inherited::Init() == false) { + return false; + } + + return true; +} + +busdata IODevice::Read8(uint32 addr) { return 0xff; } -uint64 +busdata IODevice::Read16(uint32 addr) { return (Read8(addr) << 8) | Read8(addr + 1); } -uint64 +busdata IODevice::Read32(uint32 addr) { return (Read16(addr) << 16) | Read16(addr + 2); } -uint64 +busdata IODevice::Write8(uint32 addr, uint32 data) { return 0; } -uint64 +busdata IODevice::Write16(uint32 addr, uint32 data) { int64 berr; @@ -122,7 +149,7 @@ IODevice::Write16(uint32 addr, uint32 da return 0; } -uint64 +busdata IODevice::Write32(uint32 addr, uint32 data) { int64 berr; @@ -136,12 +163,24 @@ IODevice::Write32(uint32 addr, uint32 da return 0; } -uint64 +busdata IODevice::Peek8(uint32 addr) { return 0xff; } +bool +IODevice::Poke8(uint32 addr, uint32 data) +{ + return false; +} + +bool +IODevice::Poke(uint32 addr, uint32 data) +{ + return false; +} + // // バスエラー @@ -149,62 +188,63 @@ IODevice::Peek8(uint32 addr) // コンストラクタ BusErrDevice::BusErrDevice() + : inherited(OBJ_BUSERR) { - logname = "buserr"; - devname = "(BusErr)"; - devaddr = -1; // XXX どうしたもんか + ClearAlias(); + AddAlias("BusErr"); } +// デストラクタ BusErrDevice::~BusErrDevice() { } -uint64 +busdata BusErrDevice::Read8(uint32 addr) { putlog(1, "$%08x.b", addr); - return (uint64)-1; + return busdata::BusErr; } -uint64 +busdata BusErrDevice::Read16(uint32 addr) { putlog(1, "$%08x.w", addr); - return (uint64)-1; + return busdata::BusErr; } -uint64 +busdata BusErrDevice::Read32(uint32 addr) { putlog(1, "$%08x.l", addr); - return (uint64)-1; + return busdata::BusErr; } -uint64 +busdata BusErrDevice::Write8(uint32 addr, uint32 data) { putlog(1, "$%08x.b <- %02X", addr, data); - return (uint64)-1; + return busdata::BusErr; } -uint64 +busdata BusErrDevice::Write16(uint32 addr, uint32 data) { putlog(1, "$%08x.w <- %04X", addr, data); - return (uint64)-1; + return busdata::BusErr; } -uint64 +busdata BusErrDevice::Write32(uint32 addr, uint32 data) { putlog(1, "$%08x.l <- %08X", addr, data); - return (uint64)-1; + return busdata::BusErr; } -uint64 +busdata BusErrDevice::Peek8(uint32 addr) { - return (uint64)-1; + return busdata::BusErr; } @@ -213,29 +253,62 @@ BusErrDevice::Peek8(uint32 addr) // // コンストラクタ -NullDevice::NullDevice() +NopIODevice::NopIODevice() + : inherited(OBJ_NOPIO) { - devname = "(Null)"; + ClearAlias(); + AddAlias("NopIO"); } -NullDevice::~NullDevice() +// デストラクタ +NopIODevice::~NopIODevice() { } -uint64 -NullDevice::Read8(uint32 addr) +busdata +NopIODevice::Read8(uint32 addr) { + putlog(1, "$%08x.b", addr); return 0xff; } -uint64 -NullDevice::Write8(uint32 addr, uint32 data) +busdata +NopIODevice::Read16(uint32 addr) +{ + putlog(1, "$%08x.w", addr); + return 0xffff; +} + +busdata +NopIODevice::Read32(uint32 addr) +{ + putlog(1, "$%08x.l", addr); + return 0xffffffff; +} + +busdata +NopIODevice::Write8(uint32 addr, uint32 data) +{ + putlog(1, "$%08x.b <- $%02x", addr, data); + return 0; +} + +busdata +NopIODevice::Write16(uint32 addr, uint32 data) +{ + putlog(1, "$%08x.w <- $%04x", addr, data); + return 0; +} + +busdata +NopIODevice::Write32(uint32 addr, uint32 data) { + putlog(1, "$%08x.l <- $%08x", addr, data); return 0; } -uint64 -NullDevice::Peek8(uint32 addr) +busdata +NopIODevice::Peek8(uint32 addr) { return 0xff; }