--- nono/vm/ethernet.cpp 2026/04/29 17:05:18 1.1.1.7 +++ nono/vm/ethernet.cpp 2026/04/29 17:05:29 1.1.1.9 @@ -14,8 +14,8 @@ #include "scheduler.h" // コンストラクタ -EthernetDevice::EthernetDevice() - : inherited(OBJ_ETHERNET) +EthernetDevice::EthernetDevice(uint objid_) + : inherited(objid_) { } @@ -23,7 +23,7 @@ EthernetDevice::EthernetDevice() EthernetDevice::~EthernetDevice() { if ((bool)hostnet) { - hostnet->SetCallbackDevice(NULL); + hostnet->SetRxCallback(NULL); } } @@ -32,10 +32,10 @@ bool EthernetDevice::Create() { // ホストドライバを作成してこのデバイスと紐付ける - hostnet.reset(new HostNetDevice()); + int n = GetId() - OBJ_ETHERNET0; + hostnet.reset(new HostNetDevice(this, n)); hostnet->SetRxCallback(ToDeviceCallback(&EthernetDevice::HostRxCallback)); - hostnet->SetCallbackDevice(this); return true; } @@ -45,7 +45,8 @@ void EthernetDevice::HostRxCallback() { // スレッドを超えるためにメッセージを投げる - scheduler->SendMessage(MessageID::HOSTNET_RX); + int n = GetId() - OBJ_ETHERNET0; + scheduler->SendMessage(MessageID::HOSTNET_RX(n)); } // 設定ファイルから MAC アドレスを読み込む。 @@ -62,9 +63,10 @@ EthernetDevice::HostRxCallback() // MAC アドレスが指定されているか自動生成したかで取得できれば mac に格納して // true を返す。それ以外の場合は、エラーメッセージを表示して false を返す。 /*static*/ bool -EthernetDevice::GetConfigMacAddr(macaddr_t *mac, bool accept_rom) +EthernetDevice::GetConfigMacAddr(uint n, macaddr_t *mac, bool accept_rom) { - const ConfigItem& item = gConfig->Find("ethernet-macaddr"); + std::string keyname = string_format("ethernet%u-macaddr", n); + const ConfigItem& item = gConfig->Find(keyname); const std::string& val = item.AsString(); if (val == "rom") {