--- nono/vm/device.cpp 2026/04/29 17:04:32 1.1.1.2 +++ nono/vm/device.cpp 2026/04/29 17:05:38 1.1.1.12 @@ -1,22 +1,25 @@ // // nono -// Copyright (C) 2017 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// 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(uint objid_) + : inherited(objid_) { - gDevices.push_back(this); } // デストラクタ @@ -31,51 +34,75 @@ 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 -Device::PowerOff() +Device::Apply() { return true; } -// 本体リセットスイッチによるリセット void -Device::ResetHard() +Device::ResetHard(bool poweron) { } -// MPU の RESET 命令によるリセット void -Device::ResetSoft() +Device::PowerOff() { } +// ログ表示。 +// VM デバイスでは、仮想時間、PC、オブジェクト名を表示する。 +void +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); +} + // // IODevice // // コンストラクタ -IODevice::IODevice() +IODevice::IODevice(uint objid_) + : inherited(objid_) { - devaddr = 0; - devlen = 0; } // デストラクタ @@ -83,64 +110,54 @@ IODevice::~IODevice() { } -uint64 -IODevice::Read8(uint32 addr) +busdata +IODevice::Read(busaddr addr) { - return 0xff; + return 0; } -uint64 -IODevice::Read16(uint32 addr) +busdata +IODevice::Write(busaddr addr, uint32 data) { - return (Read8(addr) << 8) | Read8(addr + 1); + return 0; } -uint64 -IODevice::Read32(uint32 addr) +busdata +IODevice::ReadBurst16(busaddr addr, uint32 *dst) { - return (Read16(addr) << 16) | Read16(addr + 2); + return BusData::BusErr; } -uint64 -IODevice::Write8(uint32 addr, uint32 data) +busdata +IODevice::WriteBurst16(busaddr addr, const uint32 *src) { - return 0; + return BusData::BusErr; } -uint64 -IODevice::Write16(uint32 addr, uint32 data) +busdata +IODevice::Read1(uint32 addr) { - 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; + return 0xff; } -uint64 -IODevice::Write32(uint32 addr, uint32 data) +busdata +IODevice::Write1(uint32 addr, uint32 data) { - 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; } -uint64 -IODevice::Peek8(uint32 addr) +busdata +IODevice::Peek1(uint32 addr) { return 0xff; } +bool +IODevice::Poke1(uint32 addr, uint32 data) +{ + return false; +} + // // バスエラー @@ -148,55 +165,43 @@ IODevice::Peek8(uint32 addr) // コンストラクタ BusErrDevice::BusErrDevice() + : inherited(OBJ_BUSERR) { - devname = "(BusErr)"; - devaddr = -1; // XXX どうしたもんか + ClearAlias(); + AddAlias("BusErr"); } +// デストラクタ BusErrDevice::~BusErrDevice() { } -uint64 -BusErrDevice::Read8(uint32 addr) +busdata +BusErrDevice::Read(busaddr addr) { - return (uint64)-1; -} + uint32 datasize = addr.GetSize(); -uint64 -BusErrDevice::Read16(uint32 addr) -{ - return (uint64)-1; + putlog(1, "$%08x.%u", addr.Addr(), datasize); + busdata data = BusData::BusErr; + data |= busdata::Size(datasize); + return data; } -uint64 -BusErrDevice::Read32(uint32 addr) +busdata +BusErrDevice::Write(busaddr addr, uint32 data) { - return (uint64)-1; -} - -uint64 -BusErrDevice::Write8(uint32 addr, uint32 data) -{ - return (uint64)-1; -} - -uint64 -BusErrDevice::Write16(uint32 addr, uint32 data) -{ - return (uint64)-1; -} + uint32 datasize = addr.GetSize(); -uint64 -BusErrDevice::Write32(uint32 addr, uint32 data) -{ - return (uint64)-1; + putlog(1, "$%08x.%u <- %0*X", addr.Addr(), datasize, datasize * 2, data); + busdata r = BusData::BusErr; + r |= busdata::Size(datasize); + return r; } -uint64 -BusErrDevice::Peek8(uint32 addr) +busdata +BusErrDevice::Peek1(uint32 addr) { - return (uint64)-1; + return BusData::BusErr; } @@ -205,29 +210,56 @@ 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::Read(busaddr addr) { - return 0xff; + uint32 datasize = addr.GetSize(); + + putlog(1, "$%08x.%u", addr.Addr(), datasize); + busdata data = (1ULL << (datasize * 8)) - 1; + data |= busdata::Size(datasize); + return data; } -uint64 -NullDevice::Write8(uint32 addr, uint32 data) +busdata +NopIODevice::Write(busaddr addr, uint32 data) { - return 0; + uint32 datasize = addr.GetSize(); + + putlog(1, "$%08x.%u <- $%0*x", addr.Addr(), datasize, datasize * 2, data); + busdata r = busdata::Size(datasize); + return r; } -uint64 -NullDevice::Peek8(uint32 addr) +busdata +NopIODevice::Peek1(uint32 addr) { return 0xff; } + +busdata +NopIODevice::Read1(uint32 addr) +{ + putlog(1, "XP $%05x", addr); + busdata data = 0xff; + return data; +} + +busdata +NopIODevice::Write1(uint32 addr, uint32 data) +{ + putlog(1, "XP $%05x <- $%02x", addr, data); + return 0; +}