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

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

unix.superglobalmegacorp.com

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