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

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: 
                      7: #include "device.h"
                      8: #include "vm.h"
                      9: 
                     10: // 全デバイスリスト
                     11: std::vector<Device *> gDevices;
                     12: 
                     13: //
                     14: // Device
                     15: //
                     16: 
                     17: // コンストラクタ
1.1.1.7 ! root       18: Device::Device(const std::string& objname_)
        !            19:        : inherited(objname_)
1.1       root       20: {
                     21:        gDevices.push_back(this);
                     22: }
                     23: 
                     24: // デストラクタ
                     25: Device::~Device()
                     26: {
1.1.1.7 ! root       27:        // 自分自身をリストから削除する
        !            28:        // XXX マルチスレッドな状況からは呼ばれないはず?
        !            29:        for (auto it = gDevices.begin(); it != gDevices.end(); ++it) {
        !            30:                if (*it == this) {
        !            31:                        gDevices.erase(it);
        !            32:                        break;
        !            33:                }
        !            34:        }
1.1       root       35: }
                     36: 
                     37: bool
                     38: Device::Create()
                     39: {
                     40:        return true;
                     41: }
                     42: 
                     43: bool
                     44: Device::Init()
                     45: {
                     46:        return true;
                     47: }
                     48: 
                     49: bool
                     50: Device::Apply()
                     51: {
                     52:        return true;
                     53: }
                     54: 
                     55: bool
                     56: Device::PowerOn()
                     57: {
                     58:        return true;
                     59: }
                     60: 
                     61: bool
                     62: Device::PowerOff()
                     63: {
                     64:        return true;
                     65: }
                     66: 
                     67: // 本体リセットスイッチによるリセット
                     68: void
                     69: Device::ResetHard()
                     70: {
                     71: }
                     72: 
                     73: 
                     74: //
                     75: // IODevice
                     76: //
                     77: 
                     78: // コンストラクタ
1.1.1.7 ! root       79: IODevice::IODevice(const std::string& objname_)
        !            80:        : inherited(objname_)
1.1       root       81: {
                     82:        devaddr = 0;
                     83:        devlen  = 0;
                     84: }
                     85: 
                     86: // デストラクタ
                     87: IODevice::~IODevice()
                     88: {
                     89: }
                     90: 
                     91: uint64
                     92: IODevice::Read8(uint32 addr)
                     93: {
                     94:        return 0xff;
                     95: }
                     96: 
                     97: uint64
                     98: IODevice::Read16(uint32 addr)
                     99: {
                    100:        return (Read8(addr) << 8) | Read8(addr + 1);
                    101: }
                    102: 
                    103: uint64
                    104: IODevice::Read32(uint32 addr)
                    105: {
                    106:        return (Read16(addr) << 16) | Read16(addr + 2);
                    107: }
                    108: 
                    109: uint64
                    110: IODevice::Write8(uint32 addr, uint32 data)
                    111: {
                    112:        return 0;
                    113: }
                    114: 
                    115: uint64
                    116: IODevice::Write16(uint32 addr, uint32 data)
                    117: {
                    118:        int64 berr;
                    119: 
1.1.1.2   root      120:        berr = Write8(addr, data >> 8);
1.1       root      121:        if (berr < 0)
                    122:                return berr;
                    123:        berr = Write8(addr + 1, data & 0xff);
                    124:        if (berr < 0)
                    125:                return berr;
                    126:        return 0;
                    127: }
                    128: 
                    129: uint64
                    130: IODevice::Write32(uint32 addr, uint32 data)
                    131: {
                    132:        int64 berr;
                    133: 
                    134:        berr = Write16(addr, data >> 16);
                    135:        if (berr < 0)
                    136:                return berr;
                    137:        berr = Write16(addr + 2, data & 0xffff);
                    138:        if (berr < 0)
                    139:                return berr;
                    140:        return 0;
                    141: }
                    142: 
                    143: uint64
                    144: IODevice::Peek8(uint32 addr)
                    145: {
1.1.1.2   root      146:        return 0xff;
1.1       root      147: }
                    148: 
                    149: 
                    150: //
                    151: // バスエラー
                    152: //
                    153: 
1.1.1.6   root      154: std::unique_ptr<BusErrDevice> gBusErr;
                    155: 
1.1       root      156: // コンストラクタ
                    157: BusErrDevice::BusErrDevice()
1.1.1.7 ! root      158:        : inherited("(BusErr)")
1.1       root      159: {
1.1.1.7 ! root      160:        ClearAlias();
        !           161:        AddAlias("BusErr");
        !           162: 
1.1       root      163:        devaddr = -1;   // XXX どうしたもんか
                    164: }
                    165: 
                    166: BusErrDevice::~BusErrDevice()
                    167: {
                    168: }
                    169: 
                    170: uint64
                    171: BusErrDevice::Read8(uint32 addr)
                    172: {
1.1.1.4   root      173:        putlog(1, "$%08x.b", addr);
1.1       root      174:        return (uint64)-1;
                    175: }
                    176: 
                    177: uint64
                    178: BusErrDevice::Read16(uint32 addr)
                    179: {
1.1.1.4   root      180:        putlog(1, "$%08x.w", addr);
1.1       root      181:        return (uint64)-1;
                    182: }
                    183: 
                    184: uint64
                    185: BusErrDevice::Read32(uint32 addr)
                    186: {
1.1.1.4   root      187:        putlog(1, "$%08x.l", addr);
1.1       root      188:        return (uint64)-1;
                    189: }
                    190: 
                    191: uint64
                    192: BusErrDevice::Write8(uint32 addr, uint32 data)
                    193: {
1.1.1.4   root      194:        putlog(1, "$%08x.b <- %02X", addr, data);
1.1       root      195:        return (uint64)-1;
                    196: }
                    197: 
                    198: uint64
                    199: BusErrDevice::Write16(uint32 addr, uint32 data)
                    200: {
1.1.1.4   root      201:        putlog(1, "$%08x.w <- %04X", addr, data);
1.1       root      202:        return (uint64)-1;
                    203: }
                    204: 
                    205: uint64
                    206: BusErrDevice::Write32(uint32 addr, uint32 data)
                    207: {
1.1.1.4   root      208:        putlog(1, "$%08x.l <- %08X", addr, data);
1.1       root      209:        return (uint64)-1;
                    210: }
                    211: 
                    212: uint64
                    213: BusErrDevice::Peek8(uint32 addr)
                    214: {
                    215:        return (uint64)-1;
                    216: }
                    217: 
                    218: 
                    219: //
                    220: // 何もしないデバイス
                    221: //
                    222: 
1.1.1.7 ! root      223: std::unique_ptr<NopIODevice> gNopIO;
1.1.1.5   root      224: 
1.1       root      225: // コンストラクタ
1.1.1.7 ! root      226: NopIODevice::NopIODevice()
        !           227:        : inherited("(NopIO)")
1.1       root      228: {
1.1.1.7 ! root      229:        ClearAlias();
        !           230:        AddAlias("NopIO");
1.1       root      231: }
                    232: 
1.1.1.7 ! root      233: NopIODevice::~NopIODevice()
1.1       root      234: {
                    235: }
                    236: 
                    237: uint64
1.1.1.7 ! root      238: NopIODevice::Read8(uint32 addr)
1.1       root      239: {
1.1.1.5   root      240:        putlog(1, "$%08x.b", addr);
1.1       root      241:        return 0xff;
                    242: }
                    243: 
                    244: uint64
1.1.1.7 ! root      245: NopIODevice::Read16(uint32 addr)
1.1.1.5   root      246: {
                    247:        putlog(1, "$%08x.w", addr);
                    248:        return 0xffff;
                    249: }
                    250: 
                    251: uint64
1.1.1.7 ! root      252: NopIODevice::Read32(uint32 addr)
1.1.1.5   root      253: {
                    254:        putlog(1, "$%08x.l", addr);
                    255:        return 0xffffffff;
                    256: }
                    257: 
                    258: uint64
1.1.1.7 ! root      259: NopIODevice::Write8(uint32 addr, uint32 data)
1.1       root      260: {
1.1.1.5   root      261:        putlog(1, "$%08x.b <- $%02x", addr, data);
                    262:        return 0;
                    263: }
                    264: 
                    265: uint64
1.1.1.7 ! root      266: NopIODevice::Write16(uint32 addr, uint32 data)
1.1.1.5   root      267: {
                    268:        putlog(1, "$%08x.w <- $%04x", addr, data);
                    269:        return 0;
                    270: }
                    271: 
                    272: uint64
1.1.1.7 ! root      273: NopIODevice::Write32(uint32 addr, uint32 data)
1.1.1.5   root      274: {
                    275:        putlog(1, "$%08x.l <- $%08x", addr, data);
1.1       root      276:        return 0;
                    277: }
                    278: 
                    279: uint64
1.1.1.7 ! root      280: NopIODevice::Peek8(uint32 addr)
1.1       root      281: {
                    282:        return 0xff;
                    283: }

unix.superglobalmegacorp.com

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