|
|
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",
1.1.1.2 ! root 19: "Network Device", // 1
! 20: "Block Device", // 2
! 21: "Console Device", // 3
! 22: "Entropy Device", // 4
1.1 root 23: };
24: assert(id < countof(idnames));
25: return idnames[id];
26: }
27:
28: /*static*/ std::string
29: VirtIO::StatusBits(uint32 status)
30: {
31: static struct {
32: uint32 bit;
33: const char *name;
34: } table[] = {
35: { STATUS_FAILED, "FAILED" },
36: { STATUS_NEEDS_RESET, "NEEDS_RESET" },
37: { STATUS_FEATURES_OK, "F_OK" },
38: { STATUS_OK, "OK" },
39: { STATUS_DRIVER, "DRIVER" },
40: { STATUS_ACKNOWLEDGE, "ACK" },
41: };
42:
43: if (status == STATUS_RESET) {
44: return "(RESET)";
45: }
46:
47: std::string str;
1.1.1.2 ! root 48: for (; status != 0; ) {
! 49: // lowest は立ってる一番下のビットだけ取り出したもの
! 50: decltype(status) lowest = status & (-status);
! 51:
! 52: str += ',';
! 53: bool found = false;
! 54: for (int i = 0; i < countof(table); i++) {
! 55: if (table[i].bit == lowest) {
! 56: str += table[i].name;
! 57: found = true;
! 58: break;
! 59: }
1.1 root 60: }
1.1.1.2 ! root 61: if (found == false) {
! 62: str += string_format("b%u", __builtin_ctz(lowest));
! 63: }
! 64:
! 65: status &= ~lowest;
1.1 root 66: }
67:
1.1.1.2 ! root 68: if (str.empty()) {
! 69: return "<>";
! 70: }
1.1 root 71: str[0] = '<';
72: str += '>';
73: return str;
74: }
75:
76: std::string
77: VirtQDesc::ToStr() const
78: {
79: std::string str;
80:
81: str = string_format("addr=$%08x len=$%08x flags=$%04x(%c%c%c) next=$%04x",
82: addr, len, flag,
83: ((flag & VIRTQ_DESC_F_INDIRECT) ? 'I' : '-'),
84: ((flag & VIRTQ_DESC_F_WRITE) ? 'W' : 'R'),
85: ((flag & VIRTQ_DESC_F_NEXT) ? 'N' : '-'),
86: next);
87: return str;
88: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.