Annotation of nono/vm/device.cpp, revision 1.1.1.11

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
1.1.1.8   root        7: //
                      8: // デバイスの基本クラスなど
                      9: //
1.1       root       10: 
1.1.1.8   root       11: #include "device.h"
                     12: #include "mpu.h"
                     13: #include "scheduler.h"
1.1       root       14: 
                     15: //
                     16: // Device
                     17: //
                     18: 
                     19: // コンストラクタ
1.1.1.11! root       20: Device::Device(uint objid_)
1.1.1.9   root       21:        : inherited(objid_)
1.1       root       22: {
                     23: }
                     24: 
                     25: // デストラクタ
                     26: Device::~Device()
                     27: {
                     28: }
                     29: 
                     30: bool
                     31: Device::Create()
                     32: {
                     33:        return true;
                     34: }
                     35: 
                     36: bool
                     37: Device::Init()
                     38: {
1.1.1.9   root       39:        mpu = GetMPUDevice();
                     40:        scheduler = GetScheduler();
                     41: 
1.1       root       42:        return true;
                     43: }
                     44: 
                     45: bool
                     46: Device::Apply()
                     47: {
                     48:        return true;
                     49: }
                     50: 
1.1.1.8   root       51: void
                     52: Device::ResetHard(bool poweron)
1.1       root       53: {
                     54: }
                     55: 
1.1.1.8   root       56: void
1.1       root       57: Device::PowerOff()
                     58: {
                     59: }
                     60: 
1.1.1.8   root       61: // ログ表示。
                     62: // VM デバイスでは、仮想時間、PC、オブジェクト名を表示する。
1.1       root       63: void
1.1.1.8   root       64: Device::putlogn(const char *fmt, ...) const
1.1       root       65: {
1.1.1.8   root       66:        char buf[1024];
                     67:        va_list ap;
                     68:        uint64 vt;
                     69:        int len;
                     70: 
1.1.1.9   root       71:        vt = scheduler->GetVirtTime();
1.1.1.11! root       72:        len = snprintf(buf, sizeof(buf), "%4u.%03u'%03u'%03u %08x %s ",
        !            73:                (uint)(vt / 1000 / 1000 / 1000),
        !            74:                (uint)((vt / 1000 / 1000) % 1000),
        !            75:                (uint)((vt / 1000) % 1000),
        !            76:                (uint)(vt % 1000),
1.1.1.9   root       77:                mpu->GetPPC(),
1.1.1.8   root       78:                GetName().c_str());
                     79: 
                     80:        va_start(ap, fmt);
                     81:        vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
                     82:        va_end(ap);
                     83: 
                     84:        WriteLog(buf);
1.1       root       85: }
                     86: 
                     87: 
                     88: //
                     89: // IODevice
                     90: //
                     91: 
                     92: // コンストラクタ
1.1.1.11! root       93: IODevice::IODevice(uint objid_)
1.1.1.9   root       94:        : inherited(objid_)
1.1       root       95: {
                     96: }
                     97: 
                     98: // デストラクタ
                     99: IODevice::~IODevice()
                    100: {
                    101: }
                    102: 
1.1.1.9   root      103: // 初期化
                    104: bool
                    105: IODevice::Init()
                    106: {
                    107:        if (inherited::Init() == false) {
                    108:                return false;
                    109:        }
                    110: 
                    111:        return true;
                    112: }
                    113: 
1.1.1.10  root      114: busdata
1.1.1.11! root      115: IODevice::Read(busaddr addr)
1.1       root      116: {
1.1.1.11! root      117:        return 0;
1.1       root      118: }
                    119: 
1.1.1.10  root      120: busdata
1.1.1.11! root      121: IODevice::Write(busaddr addr, uint32 data)
1.1       root      122: {
1.1.1.11! root      123:        return 0;
1.1       root      124: }
                    125: 
1.1.1.10  root      126: busdata
1.1.1.11! root      127: IODevice::ReadBurst16(busaddr addr, uint32 *dst)
1.1       root      128: {
1.1.1.11! root      129:        return BusData::BusErr;
1.1       root      130: }
                    131: 
1.1.1.10  root      132: busdata
1.1.1.11! root      133: IODevice::WriteBurst16(busaddr addr, const uint32 *src)
1.1       root      134: {
1.1.1.11! root      135:        return BusData::BusErr;
1.1       root      136: }
                    137: 
1.1.1.10  root      138: busdata
1.1.1.11! root      139: IODevice::Read1(uint32 addr)
1.1       root      140: {
1.1.1.11! root      141:        return 0xff;
1.1       root      142: }
                    143: 
1.1.1.10  root      144: busdata
1.1.1.11! root      145: IODevice::Write1(uint32 addr, uint32 data)
1.1       root      146: {
                    147:        return 0;
                    148: }
                    149: 
1.1.1.10  root      150: busdata
1.1.1.11! root      151: IODevice::Peek1(uint32 addr)
1.1       root      152: {
1.1.1.2   root      153:        return 0xff;
1.1       root      154: }
                    155: 
1.1.1.10  root      156: bool
1.1.1.11! root      157: IODevice::Poke1(uint32 addr, uint32 data)
1.1.1.9   root      158: {
1.1.1.10  root      159:        return false;
1.1.1.9   root      160: }
                    161: 
                    162: 
                    163: //
                    164: // バスエラー
                    165: //
1.1.1.6   root      166: 
1.1       root      167: // コンストラクタ
                    168: BusErrDevice::BusErrDevice()
1.1.1.9   root      169:        : inherited(OBJ_BUSERR)
1.1       root      170: {
1.1.1.7   root      171:        ClearAlias();
                    172:        AddAlias("BusErr");
1.1       root      173: }
                    174: 
1.1.1.8   root      175: // デストラクタ
1.1       root      176: BusErrDevice::~BusErrDevice()
                    177: {
                    178: }
                    179: 
1.1.1.10  root      180: busdata
1.1.1.11! root      181: BusErrDevice::Read(busaddr addr)
1.1       root      182: {
1.1.1.11! root      183:        uint32 datasize = addr.GetSize();
1.1       root      184: 
1.1.1.11! root      185:        putlog(1, "$%08x.%u", addr.Addr(), datasize);
        !           186:        busdata data = BusData::BusErr;
        !           187:        data |= busdata::Size(datasize);
        !           188:        return data;
1.1       root      189: }
                    190: 
1.1.1.10  root      191: busdata
1.1.1.11! root      192: BusErrDevice::Write(busaddr addr, uint32 data)
1.1       root      193: {
1.1.1.11! root      194:        uint32 datasize = addr.GetSize();
1.1       root      195: 
1.1.1.11! root      196:        putlog(1, "$%08x.%u <- %0*X", addr.Addr(), datasize, datasize * 2, data);
        !           197:        busdata r = BusData::BusErr;
        !           198:        r |= busdata::Size(datasize);
        !           199:        return r;
1.1       root      200: }
                    201: 
1.1.1.10  root      202: busdata
1.1.1.11! root      203: BusErrDevice::Peek1(uint32 addr)
1.1       root      204: {
1.1.1.11! root      205:        return BusData::BusErr;
1.1       root      206: }
                    207: 
                    208: 
                    209: //
                    210: // 何もしないデバイス
                    211: //
                    212: 
                    213: // コンストラクタ
1.1.1.7   root      214: NopIODevice::NopIODevice()
1.1.1.9   root      215:        : inherited(OBJ_NOPIO)
1.1       root      216: {
1.1.1.7   root      217:        ClearAlias();
                    218:        AddAlias("NopIO");
1.1       root      219: }
                    220: 
1.1.1.8   root      221: // デストラクタ
1.1.1.7   root      222: NopIODevice::~NopIODevice()
1.1       root      223: {
                    224: }
                    225: 
1.1.1.10  root      226: busdata
1.1.1.11! root      227: NopIODevice::Read(busaddr addr)
1.1       root      228: {
1.1.1.11! root      229:        uint32 datasize = addr.GetSize();
1.1       root      230: 
1.1.1.11! root      231:        putlog(1, "$%08x.%u", addr.Addr(), datasize);
        !           232:        busdata data = (1ULL << (datasize * 8)) - 1;
        !           233:        data |= busdata::Size(datasize);
        !           234:        return data;
1.1.1.5   root      235: }
                    236: 
1.1.1.10  root      237: busdata
1.1.1.11! root      238: NopIODevice::Write(busaddr addr, uint32 data)
1.1.1.5   root      239: {
1.1.1.11! root      240:        uint32 datasize = addr.GetSize();
1.1.1.5   root      241: 
1.1.1.11! root      242:        putlog(1, "$%08x.%u <- $%0*x", addr.Addr(), datasize, datasize * 2, data);
        !           243:        busdata r = busdata::Size(datasize);
        !           244:        return r;
1.1.1.5   root      245: }
                    246: 
1.1.1.10  root      247: busdata
1.1.1.11! root      248: NopIODevice::Peek1(uint32 addr)
1.1.1.5   root      249: {
1.1.1.11! root      250:        return 0xff;
1.1.1.5   root      251: }
                    252: 
1.1.1.10  root      253: busdata
1.1.1.11! root      254: NopIODevice::Read1(uint32 addr)
1.1.1.5   root      255: {
1.1.1.11! root      256:        putlog(1, "XP $%05x", addr);
        !           257:        busdata data = 0xff;
        !           258:        return data;
1.1       root      259: }
                    260: 
1.1.1.10  root      261: busdata
1.1.1.11! root      262: NopIODevice::Write1(uint32 addr, uint32 data)
1.1       root      263: {
1.1.1.11! root      264:        putlog(1, "XP $%05x <- $%02x", addr, data);
        !           265:        return 0;
1.1       root      266: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.