Annotation of nono/vm/virtio_entropy.cpp, revision 1.1.1.3

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_entropy.h"
                     12: #include "virtio_def.h"
1.1.1.2   root       13: #include "monitor.h"
1.1       root       14: 
                     15: // コンストラクタ
                     16: VirtIOEntropyDevice::VirtIOEntropyDevice(uint slot_)
                     17:        : inherited(OBJ_VIRTIO_ENTROPY, slot_)
                     18: {
                     19:        // 短縮形
                     20:        AddAlias("vent");
                     21: 
                     22:        device_id = VirtIO::DEVICE_ID_ENTROPY;
                     23:        int num_max = 4;
1.1.1.2   root       24:        vqueues.emplace_back(this, 0, "RequestQ", num_max);
1.1       root       25: 
                     26:        // 割り込み名
                     27:        strlcpy(intrname, "VIOEnt", sizeof(intrname));
                     28:        // 完了通知メッセージ
                     29:        msgid = MessageID::VIRTIO_ENTROPY_DONE;
                     30: 
1.1.1.2   root       31:        monitor = gMonitorManager->Regist(ID_MONITOR_VIRTIO_ENTROPY, this);
                     32:        monitor->func = ToMonitorCallback(&VirtIOEntropyDevice::MonitorUpdate);
                     33:        monitor->SetSize(MONITOR_WIDTH, 2 + 4 * 1 + num_max + 3);
1.1       root       34: }
                     35: 
                     36: // デストラクタ
                     37: VirtIOEntropyDevice::~VirtIOEntropyDevice()
                     38: {
                     39: }
                     40: 
                     41: void
                     42: VirtIOEntropyDevice::MonitorUpdate(Monitor *, TextScreen& screen)
                     43: {
                     44:        int y = 0;
                     45: 
                     46:        screen.Clear();
                     47: 
                     48:        y = MonitorUpdateDev(screen, y);
                     49:        y++;
                     50:        y = MonitorUpdateVirtQueue(screen, y, vqueues[0]);
                     51:        y++;
                     52:        y = MonitorUpdateVirtQDesc(screen, y, vqueues[0]);
                     53: }
                     54: 
                     55: // ディスクリプタを一つ処理する。
                     56: void
                     57: VirtIOEntropyDevice::ProcessDesc(VirtIOReq& req)
                     58: {
1.1.1.3 ! root       59:        std::vector<uint32> buf(roundup(req.wlen, 4));
1.1       root       60: 
1.1.1.3 ! root       61:        for (auto&& d : buf) {
        !            62:                d = rnd();
1.1       root       63:        }
1.1.1.3 ! root       64:        ReqWriteRegion(req, (const uint8 *)buf.data(), req.wlen);
1.1       root       65: }

unix.superglobalmegacorp.com

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