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

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.9 ! root       20: Device::Device(int objid_)
        !            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.8   root       72:        len = snprintf(buf, sizeof(buf), "%4d.%03d'%03d'%03d %08x %s ",
                     73:                (int)(vt / 1000 / 1000 / 1000),
                     74:                (int)((vt / 1000 / 1000) % 1000),
                     75:                (int)((vt / 1000) % 1000),
                     76:                (int)(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.9 ! root       93: IODevice::IODevice(int objid_)
        !            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       root      114: uint64
                    115: IODevice::Read8(uint32 addr)
                    116: {
                    117:        return 0xff;
                    118: }
                    119: 
                    120: uint64
                    121: IODevice::Read16(uint32 addr)
                    122: {
                    123:        return (Read8(addr) << 8) | Read8(addr + 1);
                    124: }
                    125: 
                    126: uint64
                    127: IODevice::Read32(uint32 addr)
                    128: {
                    129:        return (Read16(addr) << 16) | Read16(addr + 2);
                    130: }
                    131: 
                    132: uint64
                    133: IODevice::Write8(uint32 addr, uint32 data)
                    134: {
                    135:        return 0;
                    136: }
                    137: 
                    138: uint64
                    139: IODevice::Write16(uint32 addr, uint32 data)
                    140: {
                    141:        int64 berr;
                    142: 
1.1.1.2   root      143:        berr = Write8(addr, data >> 8);
1.1       root      144:        if (berr < 0)
                    145:                return berr;
                    146:        berr = Write8(addr + 1, data & 0xff);
                    147:        if (berr < 0)
                    148:                return berr;
                    149:        return 0;
                    150: }
                    151: 
                    152: uint64
                    153: IODevice::Write32(uint32 addr, uint32 data)
                    154: {
                    155:        int64 berr;
                    156: 
                    157:        berr = Write16(addr, data >> 16);
                    158:        if (berr < 0)
                    159:                return berr;
                    160:        berr = Write16(addr + 2, data & 0xffff);
                    161:        if (berr < 0)
                    162:                return berr;
                    163:        return 0;
                    164: }
                    165: 
                    166: uint64
                    167: IODevice::Peek8(uint32 addr)
                    168: {
1.1.1.2   root      169:        return 0xff;
1.1       root      170: }
                    171: 
1.1.1.9 ! root      172: uint64
        !           173: IODevice::Poke8(uint32 addr, uint32 data)
        !           174: {
        !           175:        return (uint64)-1;
        !           176: }
        !           177: 
        !           178: uint64
        !           179: IODevice::Poke(uint32 addr, uint32 data)
        !           180: {
        !           181:        return (uint64)-1;
        !           182: }
        !           183: 
1.1       root      184: 
                    185: //
1.1.1.9 ! root      186: // IOContainerDevice
1.1       root      187: //
                    188: 
1.1.1.9 ! root      189: // コンストラクタ
        !           190: IOContainerDevice::IOContainerDevice(int objid_)
        !           191:        : inherited(objid_)
        !           192: {
        !           193: }
        !           194: 
        !           195: // デストラクタ
        !           196: IOContainerDevice::~IOContainerDevice()
        !           197: {
        !           198: }
        !           199: 
        !           200: // このアドレスを担当する IODevice を再帰的に探して返す。
        !           201: IODevice *
        !           202: IOContainerDevice::FindDevice(uint32 addr) const
        !           203: {
        !           204:        IODevice *d = GetDevice(addr);
        !           205:        IOContainerDevice *cd = dynamic_cast<IOContainerDevice *>(d);
        !           206: 
        !           207:        if (cd) {
        !           208:                // 次段はコンテナデバイス
        !           209:                return cd->FindDevice(addr);
        !           210:        } else {
        !           211:                // 次段は終端のデバイス
        !           212:                return d;
        !           213:        }
        !           214: }
        !           215: 
        !           216: 
        !           217: //
        !           218: // バスエラー
        !           219: //
1.1.1.6   root      220: 
1.1       root      221: // コンストラクタ
                    222: BusErrDevice::BusErrDevice()
1.1.1.9 ! root      223:        : inherited(OBJ_BUSERR)
1.1       root      224: {
1.1.1.7   root      225:        ClearAlias();
                    226:        AddAlias("BusErr");
1.1       root      227: }
                    228: 
1.1.1.8   root      229: // デストラクタ
1.1       root      230: BusErrDevice::~BusErrDevice()
                    231: {
                    232: }
                    233: 
                    234: uint64
                    235: BusErrDevice::Read8(uint32 addr)
                    236: {
1.1.1.4   root      237:        putlog(1, "$%08x.b", addr);
1.1       root      238:        return (uint64)-1;
                    239: }
                    240: 
                    241: uint64
                    242: BusErrDevice::Read16(uint32 addr)
                    243: {
1.1.1.4   root      244:        putlog(1, "$%08x.w", addr);
1.1       root      245:        return (uint64)-1;
                    246: }
                    247: 
                    248: uint64
                    249: BusErrDevice::Read32(uint32 addr)
                    250: {
1.1.1.4   root      251:        putlog(1, "$%08x.l", addr);
1.1       root      252:        return (uint64)-1;
                    253: }
                    254: 
                    255: uint64
                    256: BusErrDevice::Write8(uint32 addr, uint32 data)
                    257: {
1.1.1.4   root      258:        putlog(1, "$%08x.b <- %02X", addr, data);
1.1       root      259:        return (uint64)-1;
                    260: }
                    261: 
                    262: uint64
                    263: BusErrDevice::Write16(uint32 addr, uint32 data)
                    264: {
1.1.1.4   root      265:        putlog(1, "$%08x.w <- %04X", addr, data);
1.1       root      266:        return (uint64)-1;
                    267: }
                    268: 
                    269: uint64
                    270: BusErrDevice::Write32(uint32 addr, uint32 data)
                    271: {
1.1.1.4   root      272:        putlog(1, "$%08x.l <- %08X", addr, data);
1.1       root      273:        return (uint64)-1;
                    274: }
                    275: 
                    276: uint64
                    277: BusErrDevice::Peek8(uint32 addr)
                    278: {
                    279:        return (uint64)-1;
                    280: }
                    281: 
                    282: 
                    283: //
                    284: // 何もしないデバイス
                    285: //
                    286: 
                    287: // コンストラクタ
1.1.1.7   root      288: NopIODevice::NopIODevice()
1.1.1.9 ! root      289:        : inherited(OBJ_NOPIO)
1.1       root      290: {
1.1.1.7   root      291:        ClearAlias();
                    292:        AddAlias("NopIO");
1.1       root      293: }
                    294: 
1.1.1.8   root      295: // デストラクタ
1.1.1.7   root      296: NopIODevice::~NopIODevice()
1.1       root      297: {
                    298: }
                    299: 
                    300: uint64
1.1.1.7   root      301: NopIODevice::Read8(uint32 addr)
1.1       root      302: {
1.1.1.5   root      303:        putlog(1, "$%08x.b", addr);
1.1       root      304:        return 0xff;
                    305: }
                    306: 
                    307: uint64
1.1.1.7   root      308: NopIODevice::Read16(uint32 addr)
1.1.1.5   root      309: {
                    310:        putlog(1, "$%08x.w", addr);
                    311:        return 0xffff;
                    312: }
                    313: 
                    314: uint64
1.1.1.7   root      315: NopIODevice::Read32(uint32 addr)
1.1.1.5   root      316: {
                    317:        putlog(1, "$%08x.l", addr);
                    318:        return 0xffffffff;
                    319: }
                    320: 
                    321: uint64
1.1.1.7   root      322: NopIODevice::Write8(uint32 addr, uint32 data)
1.1       root      323: {
1.1.1.5   root      324:        putlog(1, "$%08x.b <- $%02x", addr, data);
                    325:        return 0;
                    326: }
                    327: 
                    328: uint64
1.1.1.7   root      329: NopIODevice::Write16(uint32 addr, uint32 data)
1.1.1.5   root      330: {
                    331:        putlog(1, "$%08x.w <- $%04x", addr, data);
                    332:        return 0;
                    333: }
                    334: 
                    335: uint64
1.1.1.7   root      336: NopIODevice::Write32(uint32 addr, uint32 data)
1.1.1.5   root      337: {
                    338:        putlog(1, "$%08x.l <- $%08x", addr, data);
1.1       root      339:        return 0;
                    340: }
                    341: 
                    342: uint64
1.1.1.7   root      343: NopIODevice::Peek8(uint32 addr)
1.1       root      344: {
                    345:        return 0xff;
                    346: }

unix.superglobalmegacorp.com

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