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

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.1.10! root      114: busdata
1.1       root      115: IODevice::Read8(uint32 addr)
                    116: {
                    117:        return 0xff;
                    118: }
                    119: 
1.1.1.10! root      120: busdata
1.1       root      121: IODevice::Read16(uint32 addr)
                    122: {
                    123:        return (Read8(addr) << 8) | Read8(addr + 1);
                    124: }
                    125: 
1.1.1.10! root      126: busdata
1.1       root      127: IODevice::Read32(uint32 addr)
                    128: {
                    129:        return (Read16(addr) << 16) | Read16(addr + 2);
                    130: }
                    131: 
1.1.1.10! root      132: busdata
1.1       root      133: IODevice::Write8(uint32 addr, uint32 data)
                    134: {
                    135:        return 0;
                    136: }
                    137: 
1.1.1.10! root      138: busdata
1.1       root      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: 
1.1.1.10! root      152: busdata
1.1       root      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: 
1.1.1.10! root      166: busdata
1.1       root      167: IODevice::Peek8(uint32 addr)
                    168: {
1.1.1.2   root      169:        return 0xff;
1.1       root      170: }
                    171: 
1.1.1.10! root      172: bool
1.1.1.9   root      173: IODevice::Poke8(uint32 addr, uint32 data)
                    174: {
1.1.1.10! root      175:        return false;
1.1.1.9   root      176: }
                    177: 
1.1.1.10! root      178: bool
1.1.1.9   root      179: IODevice::Poke(uint32 addr, uint32 data)
                    180: {
1.1.1.10! root      181:        return false;
1.1.1.9   root      182: }
                    183: 
                    184: 
                    185: //
                    186: // バスエラー
                    187: //
1.1.1.6   root      188: 
1.1       root      189: // コンストラクタ
                    190: BusErrDevice::BusErrDevice()
1.1.1.9   root      191:        : inherited(OBJ_BUSERR)
1.1       root      192: {
1.1.1.7   root      193:        ClearAlias();
                    194:        AddAlias("BusErr");
1.1       root      195: }
                    196: 
1.1.1.8   root      197: // デストラクタ
1.1       root      198: BusErrDevice::~BusErrDevice()
                    199: {
                    200: }
                    201: 
1.1.1.10! root      202: busdata
1.1       root      203: BusErrDevice::Read8(uint32 addr)
                    204: {
1.1.1.4   root      205:        putlog(1, "$%08x.b", addr);
1.1.1.10! root      206:        return busdata::BusErr;
1.1       root      207: }
                    208: 
1.1.1.10! root      209: busdata
1.1       root      210: BusErrDevice::Read16(uint32 addr)
                    211: {
1.1.1.4   root      212:        putlog(1, "$%08x.w", addr);
1.1.1.10! root      213:        return busdata::BusErr;
1.1       root      214: }
                    215: 
1.1.1.10! root      216: busdata
1.1       root      217: BusErrDevice::Read32(uint32 addr)
                    218: {
1.1.1.4   root      219:        putlog(1, "$%08x.l", addr);
1.1.1.10! root      220:        return busdata::BusErr;
1.1       root      221: }
                    222: 
1.1.1.10! root      223: busdata
1.1       root      224: BusErrDevice::Write8(uint32 addr, uint32 data)
                    225: {
1.1.1.4   root      226:        putlog(1, "$%08x.b <- %02X", addr, data);
1.1.1.10! root      227:        return busdata::BusErr;
1.1       root      228: }
                    229: 
1.1.1.10! root      230: busdata
1.1       root      231: BusErrDevice::Write16(uint32 addr, uint32 data)
                    232: {
1.1.1.4   root      233:        putlog(1, "$%08x.w <- %04X", addr, data);
1.1.1.10! root      234:        return busdata::BusErr;
1.1       root      235: }
                    236: 
1.1.1.10! root      237: busdata
1.1       root      238: BusErrDevice::Write32(uint32 addr, uint32 data)
                    239: {
1.1.1.4   root      240:        putlog(1, "$%08x.l <- %08X", addr, data);
1.1.1.10! root      241:        return busdata::BusErr;
1.1       root      242: }
                    243: 
1.1.1.10! root      244: busdata
1.1       root      245: BusErrDevice::Peek8(uint32 addr)
                    246: {
1.1.1.10! root      247:        return busdata::BusErr;
1.1       root      248: }
                    249: 
                    250: 
                    251: //
                    252: // 何もしないデバイス
                    253: //
                    254: 
                    255: // コンストラクタ
1.1.1.7   root      256: NopIODevice::NopIODevice()
1.1.1.9   root      257:        : inherited(OBJ_NOPIO)
1.1       root      258: {
1.1.1.7   root      259:        ClearAlias();
                    260:        AddAlias("NopIO");
1.1       root      261: }
                    262: 
1.1.1.8   root      263: // デストラクタ
1.1.1.7   root      264: NopIODevice::~NopIODevice()
1.1       root      265: {
                    266: }
                    267: 
1.1.1.10! root      268: busdata
1.1.1.7   root      269: NopIODevice::Read8(uint32 addr)
1.1       root      270: {
1.1.1.5   root      271:        putlog(1, "$%08x.b", addr);
1.1       root      272:        return 0xff;
                    273: }
                    274: 
1.1.1.10! root      275: busdata
1.1.1.7   root      276: NopIODevice::Read16(uint32 addr)
1.1.1.5   root      277: {
                    278:        putlog(1, "$%08x.w", addr);
                    279:        return 0xffff;
                    280: }
                    281: 
1.1.1.10! root      282: busdata
1.1.1.7   root      283: NopIODevice::Read32(uint32 addr)
1.1.1.5   root      284: {
                    285:        putlog(1, "$%08x.l", addr);
                    286:        return 0xffffffff;
                    287: }
                    288: 
1.1.1.10! root      289: busdata
1.1.1.7   root      290: NopIODevice::Write8(uint32 addr, uint32 data)
1.1       root      291: {
1.1.1.5   root      292:        putlog(1, "$%08x.b <- $%02x", addr, data);
                    293:        return 0;
                    294: }
                    295: 
1.1.1.10! root      296: busdata
1.1.1.7   root      297: NopIODevice::Write16(uint32 addr, uint32 data)
1.1.1.5   root      298: {
                    299:        putlog(1, "$%08x.w <- $%04x", addr, data);
                    300:        return 0;
                    301: }
                    302: 
1.1.1.10! root      303: busdata
1.1.1.7   root      304: NopIODevice::Write32(uint32 addr, uint32 data)
1.1.1.5   root      305: {
                    306:        putlog(1, "$%08x.l <- $%08x", addr, data);
1.1       root      307:        return 0;
                    308: }
                    309: 
1.1.1.10! root      310: busdata
1.1.1.7   root      311: NopIODevice::Peek8(uint32 addr)
1.1       root      312: {
                    313:        return 0xff;
                    314: }

unix.superglobalmegacorp.com

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