Annotation of nono/vm/virtio_def.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: // VirtIO 定義
        !             9: //
        !            10: 
        !            11: #include "virtio_def.h"
        !            12: #include "mystring.h"
        !            13: 
        !            14: /*static*/ std::string
        !            15: VirtIO::DeviceIDStr(uint32 id)
        !            16: {
        !            17:        static const char * const idnames[] = {
        !            18:                "invalid",
        !            19:                "Network Card", // 1
        !            20:                "Block Device", // 2
        !            21:        };
        !            22:        assert(id < countof(idnames));
        !            23:        return idnames[id];
        !            24: }
        !            25: 
        !            26: /*static*/ std::string
        !            27: VirtIO::StatusBits(uint32 status)
        !            28: {
        !            29:        static struct {
        !            30:                uint32 bit;
        !            31:                const char *name;
        !            32:        } table[] = {
        !            33:                { STATUS_FAILED,                "FAILED" },
        !            34:                { STATUS_NEEDS_RESET,   "NEEDS_RESET" },
        !            35:                { STATUS_FEATURES_OK,   "F_OK" },
        !            36:                { STATUS_OK,                    "OK" },
        !            37:                { STATUS_DRIVER,                "DRIVER" },
        !            38:                { STATUS_ACKNOWLEDGE,   "ACK" },
        !            39:        };
        !            40: 
        !            41:        if (status == STATUS_RESET) {
        !            42:                return "(RESET)";
        !            43:        }
        !            44: 
        !            45:        std::string str;
        !            46:        for (int i = 0; i < countof(table); i++) {
        !            47:                if ((status & table[i].bit) != 0) {
        !            48:                        str += ',';
        !            49:                        str += table[i].name;
        !            50:                }
        !            51:        }
        !            52: 
        !            53:        str[0] = '<';
        !            54:        str += '>';
        !            55:        return str;
        !            56: }
        !            57: 
        !            58: std::string
        !            59: VirtQDesc::ToStr() const
        !            60: {
        !            61:        std::string str;
        !            62: 
        !            63:        str = string_format("addr=$%08x len=$%08x flags=$%04x(%c%c%c) next=$%04x",
        !            64:                addr, len, flag,
        !            65:                ((flag & VIRTQ_DESC_F_INDIRECT) ? 'I' : '-'),
        !            66:                ((flag & VIRTQ_DESC_F_WRITE) ? 'W' : 'R'),
        !            67:                ((flag & VIRTQ_DESC_F_NEXT) ? 'N' : '-'),
        !            68:                next);
        !            69:        return str;
        !            70: }

unix.superglobalmegacorp.com

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