Annotation of nono/vm/qemusysctlr.cpp, revision 1.1

1.1     ! root        1: //
        !             2: // nono
        !             3: // Copyright (C) 2024 nono project
        !             4: // Licensed under nono-license.txt
        !             5: //
        !             6: 
        !             7: //
        !             8: // QEMU Virtual System Controller
        !             9: //
        !            10: 
        !            11: // https://www.qemu.org/docs/master/specs/virt-ctlr.html
        !            12: 
        !            13: #include "qemusysctlr.h"
        !            14: #include "power.h"
        !            15: 
        !            16: // コンストラクタ
        !            17: QemuSysCtlrDevice::QemuSysCtlrDevice()
        !            18:        : inherited(OBJ_QEMUSYSCTLR)
        !            19: {
        !            20: }
        !            21: 
        !            22: // デストラクタ
        !            23: QemuSysCtlrDevice::~QemuSysCtlrDevice()
        !            24: {
        !            25: }
        !            26: 
        !            27: busdata
        !            28: QemuSysCtlrDevice::Read32(uint32 addr)
        !            29: {
        !            30:        uint32 offset = addr & 0xff;
        !            31: 
        !            32:        if (offset == 0) {
        !            33:                // Features (Read Only)
        !            34:                uint32 data = FEATURES;
        !            35:                putlog(2, "FEATURES -> $%08x", data);
        !            36:                return data;
        !            37:        } else {
        !            38:                // 他のポートがどうなるのかは仕様に書いてない。
        !            39:                putlog(1, "Read32 $%08x (BusErr)", addr);
        !            40:                return busdata::BusErr;
        !            41:        }
        !            42: }
        !            43: 
        !            44: busdata
        !            45: QemuSysCtlrDevice::Write32(uint32 addr, uint32 data)
        !            46: {
        !            47:        uint32 offset = addr & 0xff;
        !            48: 
        !            49:        if (offset == 4) {
        !            50:                // Command (Write Only)
        !            51:                static const char *cmdname[] = {
        !            52:                        "no-op",
        !            53:                        "reset",
        !            54:                        "halt",
        !            55:                        "panic",
        !            56:                };
        !            57:                putlog(1, "Command <- $%08x (%s)", data,
        !            58:                        (data < countof(cmdname) ? cmdname[data] : cmdname[0]));
        !            59:                switch (data) {
        !            60:                 default:
        !            61:                 case 0:        // no-op
        !            62:                        break;
        !            63: 
        !            64:                 case 1:        // reset
        !            65:                        GetPowerDevice()->MakeResetHard();
        !            66:                        break;
        !            67: 
        !            68:                 case 2:        // halt
        !            69:                 case 3:        // panic
        !            70:                        GetPowerDevice()->PushPowerButton();
        !            71:                        break;
        !            72:                }
        !            73:                return 0;
        !            74:        } else {
        !            75:                // 他のポートがどうなるのかは仕様に書いてない。
        !            76:                putlog(1, "Write32 $%08x <- $%08x (BusErr)", addr, data);
        !            77:                return busdata::BusErr;
        !            78:        }
        !            79: }
        !            80: 
        !            81: busdata
        !            82: QemuSysCtlrDevice::Peek8(uint32 addr)
        !            83: {
        !            84:        uint32 offset = addr & 0xff;
        !            85: 
        !            86:        switch (offset) {
        !            87:         case 0:        return (FEATURES >> 24);
        !            88:         case 1:        return (FEATURES >> 16) & 0xff;
        !            89:         case 2:        return (FEATURES >>  8) & 0xff;
        !            90:         case 3:        return (FEATURES      ) & 0xff;
        !            91: 
        !            92:         default:
        !            93:                return busdata::BusErr;
        !            94:        }
        !            95: }

unix.superglobalmegacorp.com

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