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

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.7   root       20: Device::Device(const std::string& objname_)
                     21:        : inherited(objname_)
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: {
                     39:        return true;
                     40: }
                     41: 
                     42: bool
                     43: Device::Apply()
                     44: {
                     45:        return true;
                     46: }
                     47: 
1.1.1.8 ! root       48: void
        !            49: Device::ResetHard(bool poweron)
1.1       root       50: {
                     51: }
                     52: 
1.1.1.8 ! root       53: void
1.1       root       54: Device::PowerOff()
                     55: {
                     56: }
                     57: 
1.1.1.8 ! root       58: // ログ表示。
        !            59: // VM デバイスでは、仮想時間、PC、オブジェクト名を表示する。
1.1       root       60: void
1.1.1.8 ! root       61: Device::putlogn(const char *fmt, ...) const
1.1       root       62: {
1.1.1.8 ! root       63:        char buf[1024];
        !            64:        va_list ap;
        !            65:        uint64 vt;
        !            66:        int len;
        !            67: 
        !            68:        vt = gScheduler->GetVirtTime();
        !            69:        len = snprintf(buf, sizeof(buf), "%4d.%03d'%03d'%03d %08x %s ",
        !            70:                (int)(vt / 1000 / 1000 / 1000),
        !            71:                (int)((vt / 1000 / 1000) % 1000),
        !            72:                (int)((vt / 1000) % 1000),
        !            73:                (int)(vt % 1000),
        !            74:                gMPU->GetPPC(),
        !            75:                GetName().c_str());
        !            76: 
        !            77:        va_start(ap, fmt);
        !            78:        vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
        !            79:        va_end(ap);
        !            80: 
        !            81:        WriteLog(buf);
1.1       root       82: }
                     83: 
                     84: 
                     85: //
                     86: // IODevice
                     87: //
                     88: 
                     89: // コンストラクタ
1.1.1.7   root       90: IODevice::IODevice(const std::string& objname_)
                     91:        : inherited(objname_)
1.1       root       92: {
                     93:        devaddr = 0;
                     94:        devlen  = 0;
                     95: }
                     96: 
                     97: // デストラクタ
                     98: IODevice::~IODevice()
                     99: {
                    100: }
                    101: 
                    102: uint64
                    103: IODevice::Read8(uint32 addr)
                    104: {
                    105:        return 0xff;
                    106: }
                    107: 
                    108: uint64
                    109: IODevice::Read16(uint32 addr)
                    110: {
                    111:        return (Read8(addr) << 8) | Read8(addr + 1);
                    112: }
                    113: 
                    114: uint64
                    115: IODevice::Read32(uint32 addr)
                    116: {
                    117:        return (Read16(addr) << 16) | Read16(addr + 2);
                    118: }
                    119: 
                    120: uint64
                    121: IODevice::Write8(uint32 addr, uint32 data)
                    122: {
                    123:        return 0;
                    124: }
                    125: 
                    126: uint64
                    127: IODevice::Write16(uint32 addr, uint32 data)
                    128: {
                    129:        int64 berr;
                    130: 
1.1.1.2   root      131:        berr = Write8(addr, data >> 8);
1.1       root      132:        if (berr < 0)
                    133:                return berr;
                    134:        berr = Write8(addr + 1, data & 0xff);
                    135:        if (berr < 0)
                    136:                return berr;
                    137:        return 0;
                    138: }
                    139: 
                    140: uint64
                    141: IODevice::Write32(uint32 addr, uint32 data)
                    142: {
                    143:        int64 berr;
                    144: 
                    145:        berr = Write16(addr, data >> 16);
                    146:        if (berr < 0)
                    147:                return berr;
                    148:        berr = Write16(addr + 2, data & 0xffff);
                    149:        if (berr < 0)
                    150:                return berr;
                    151:        return 0;
                    152: }
                    153: 
                    154: uint64
                    155: IODevice::Peek8(uint32 addr)
                    156: {
1.1.1.2   root      157:        return 0xff;
1.1       root      158: }
                    159: 
                    160: 
                    161: //
                    162: // バスエラー
                    163: //
                    164: 
1.1.1.8 ! root      165: // グローバル参照用
        !           166: BusErrDevice *gBusErr;
1.1.1.6   root      167: 
1.1       root      168: // コンストラクタ
                    169: BusErrDevice::BusErrDevice()
1.1.1.7   root      170:        : inherited("(BusErr)")
1.1       root      171: {
1.1.1.7   root      172:        ClearAlias();
                    173:        AddAlias("BusErr");
                    174: 
1.1       root      175:        devaddr = -1;   // XXX どうしたもんか
                    176: }
                    177: 
1.1.1.8 ! root      178: // デストラクタ
1.1       root      179: BusErrDevice::~BusErrDevice()
                    180: {
1.1.1.8 ! root      181:        gBusErr = NULL;
1.1       root      182: }
                    183: 
                    184: uint64
                    185: BusErrDevice::Read8(uint32 addr)
                    186: {
1.1.1.4   root      187:        putlog(1, "$%08x.b", addr);
1.1       root      188:        return (uint64)-1;
                    189: }
                    190: 
                    191: uint64
                    192: BusErrDevice::Read16(uint32 addr)
                    193: {
1.1.1.4   root      194:        putlog(1, "$%08x.w", addr);
1.1       root      195:        return (uint64)-1;
                    196: }
                    197: 
                    198: uint64
                    199: BusErrDevice::Read32(uint32 addr)
                    200: {
1.1.1.4   root      201:        putlog(1, "$%08x.l", addr);
1.1       root      202:        return (uint64)-1;
                    203: }
                    204: 
                    205: uint64
                    206: BusErrDevice::Write8(uint32 addr, uint32 data)
                    207: {
1.1.1.4   root      208:        putlog(1, "$%08x.b <- %02X", addr, data);
1.1       root      209:        return (uint64)-1;
                    210: }
                    211: 
                    212: uint64
                    213: BusErrDevice::Write16(uint32 addr, uint32 data)
                    214: {
1.1.1.4   root      215:        putlog(1, "$%08x.w <- %04X", addr, data);
1.1       root      216:        return (uint64)-1;
                    217: }
                    218: 
                    219: uint64
                    220: BusErrDevice::Write32(uint32 addr, uint32 data)
                    221: {
1.1.1.4   root      222:        putlog(1, "$%08x.l <- %08X", addr, data);
1.1       root      223:        return (uint64)-1;
                    224: }
                    225: 
                    226: uint64
                    227: BusErrDevice::Peek8(uint32 addr)
                    228: {
                    229:        return (uint64)-1;
                    230: }
                    231: 
                    232: 
                    233: //
                    234: // 何もしないデバイス
                    235: //
                    236: 
1.1.1.8 ! root      237: // グローバル参照用
        !           238: NopIODevice *gNopIO;
1.1.1.5   root      239: 
1.1       root      240: // コンストラクタ
1.1.1.7   root      241: NopIODevice::NopIODevice()
                    242:        : inherited("(NopIO)")
1.1       root      243: {
1.1.1.7   root      244:        ClearAlias();
                    245:        AddAlias("NopIO");
1.1       root      246: }
                    247: 
1.1.1.8 ! root      248: // デストラクタ
1.1.1.7   root      249: NopIODevice::~NopIODevice()
1.1       root      250: {
1.1.1.8 ! root      251:        gNopIO = NULL;
1.1       root      252: }
                    253: 
                    254: uint64
1.1.1.7   root      255: NopIODevice::Read8(uint32 addr)
1.1       root      256: {
1.1.1.5   root      257:        putlog(1, "$%08x.b", addr);
1.1       root      258:        return 0xff;
                    259: }
                    260: 
                    261: uint64
1.1.1.7   root      262: NopIODevice::Read16(uint32 addr)
1.1.1.5   root      263: {
                    264:        putlog(1, "$%08x.w", addr);
                    265:        return 0xffff;
                    266: }
                    267: 
                    268: uint64
1.1.1.7   root      269: NopIODevice::Read32(uint32 addr)
1.1.1.5   root      270: {
                    271:        putlog(1, "$%08x.l", addr);
                    272:        return 0xffffffff;
                    273: }
                    274: 
                    275: uint64
1.1.1.7   root      276: NopIODevice::Write8(uint32 addr, uint32 data)
1.1       root      277: {
1.1.1.5   root      278:        putlog(1, "$%08x.b <- $%02x", addr, data);
                    279:        return 0;
                    280: }
                    281: 
                    282: uint64
1.1.1.7   root      283: NopIODevice::Write16(uint32 addr, uint32 data)
1.1.1.5   root      284: {
                    285:        putlog(1, "$%08x.w <- $%04x", addr, data);
                    286:        return 0;
                    287: }
                    288: 
                    289: uint64
1.1.1.7   root      290: NopIODevice::Write32(uint32 addr, uint32 data)
1.1.1.5   root      291: {
                    292:        putlog(1, "$%08x.l <- $%08x", addr, data);
1.1       root      293:        return 0;
                    294: }
                    295: 
                    296: uint64
1.1.1.7   root      297: NopIODevice::Peek8(uint32 addr)
1.1       root      298: {
                    299:        return 0xff;
                    300: }

unix.superglobalmegacorp.com

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