--- nono/vm/interrupt.cpp 2026/04/29 17:05:10 1.1.1.6 +++ nono/vm/interrupt.cpp 2026/04/29 17:05:20 1.1.1.8 @@ -26,7 +26,7 @@ // | +---------------+ // | // +-- PEDECDevice (X68030 の Lv1 担当コントローラ) -// +-- SysCtlrDevice (LUNA88K の割り込みコントローラ) +// +-- SysCtlrDevice (LUNA-88K の割り込みコントローラ) #include "interrupt.h" #include "dmac.h" @@ -35,35 +35,33 @@ #include "m68030.h" #include "mfp.h" #include "mpu680x0.h" +#include "newsctlr.h" #include "nmi.h" +#include "rtl8019as.h" #include "scc.h" #include "sio.h" #include "spc.h" #include "sysclk.h" -// グローバル参照用 -InterruptDevice *gInterrupt; - // // 仮想割り込みコントローラ (共通部) // -// コンストラクタ(オブジェクト名指定あり) -InterruptDevice::InterruptDevice(const std::string& objname_) - : inherited(objname_) +// コンストラクタ(オブジェクト名指定なし) +InterruptDevice::InterruptDevice() + : InterruptDevice(OBJ_INTERRUPT) // 移譲 { } -// コンストラクタ(オブジェクト名指定なし) -InterruptDevice::InterruptDevice() - : InterruptDevice("Interrupt") +// コンストラクタ(オブジェクト名指定あり) +InterruptDevice::InterruptDevice(int objid_) + : inherited(objid_) { } // デストラクタ InterruptDevice::~InterruptDevice() { - gInterrupt = NULL; } // リセット @@ -108,17 +106,22 @@ InterruptDevice::NegateINT(Device *sourc } } +// 割り込み信号線の状態を取得 +bool +InterruptDevice::GetINT(const Device *source) const +{ + uint32 srcmap; + + srcmap = GetIntmap(source); + + return (intmap & srcmap); +} + + // // 仮想割り込みコントローラ (m680x0 共通部) // -// CPU コアからの割り込みアクノリッジを受け付けるグローバル関数 -int -m68030_interrupt_acknowledge(int lv) -{ - return gInterrupt->InterruptAcknowledge(lv); -} - // コンストラクタ M680x0Interrupt::M680x0Interrupt() { @@ -129,6 +132,17 @@ M680x0Interrupt::~M680x0Interrupt() { } +// 初期化 +bool +M680x0Interrupt::Init() +{ + if (inherited::Init() == false) { + return false; + } + + return true; +} + // リセット void M680x0Interrupt::ResetHard(bool poweron) @@ -148,7 +162,7 @@ M680x0Interrupt::ChangeInterrupt() // 割り込みレベルが変わったら、新しいレベルを通知 if (newipl != ipl) { ipl = newipl; - gMPU->Interrupt(ipl); + mpu->Interrupt(ipl); } } @@ -161,7 +175,7 @@ M680x0Interrupt::ChangeInterrupt() X68030Interrupt::X68030Interrupt() { monitor.func = ToMonitorCallback(&X68030Interrupt::MonitorUpdate); - monitor.SetSize(25, 11); + monitor.SetSize(41, 13); monitor.Regist(ID_MONITOR_INTERRUPT); } @@ -170,23 +184,50 @@ X68030Interrupt::~X68030Interrupt() { } +// 初期化 +bool +X68030Interrupt::Init() +{ + if (inherited::Init() == false) { + return false; + } + + dmac = GetDMACDevice(); + mfp = GetMFPDevice(); + // Nereid は拡張ボードなので存在しない可能性がある + for (int i = 0; i < 2; i++) { + net[i] = gMainApp.FindObject(OBJ_ETHERNET(i)); + } + nmi = GetNMIDevice(); + pedec = GetPEDECDevice(); + scc = GetSCCDevice(); + + return true; +} + // デバイスから Intmap 値を引く uint32 -X68030Interrupt::GetIntmap(Device *source) const +X68030Interrupt::GetIntmap(const Device *source) const { - if (__predict_true(source == gMFP)) { + if (__predict_true(source == mfp)) { return IntmapMFP; } - if (__predict_true(source == gSCC)) { + if (__predict_true(source == scc)) { return IntmapSCC; } - if (__predict_true(source == gDMAC)) { + if (__predict_true(source == net[0])) { + return IntmapNereid0; + } + if (__predict_true(source == net[1])) { + return IntmapNereid1; + } + if (__predict_true(source == dmac)) { return IntmapDMAC; } - if (__predict_true(source == gPEDEC)) { + if (__predict_true(source == pedec)) { return IntmapPEDEC; } - if (source == gNMI) { + if (source == nmi) { return IntmapNMI; } VMPANIC("Unknown interrupt source?"); @@ -201,16 +242,24 @@ X68030Interrupt::InterruptAcknowledge(in return AutoVector; case 6: - return gMFP->InterruptAcknowledge(); + return mfp->InterruptAcknowledge(); case 5: - return gSCC->InterruptAcknowledge(); + return scc->InterruptAcknowledge(); + + case 4: + for (int i = 0; i < 2; i++) { + if (net[i]) { + return net[i]->InterruptAcknowledge(); + } + } + break; case 3: - return gDMAC->InterruptAcknowledge(); + return dmac->InterruptAcknowledge(); case 1: - return gPEDEC->InterruptAcknowledge(lv); + return pedec->InterruptAcknowledge(lv); default: break; @@ -226,35 +275,52 @@ X68030Interrupt::MonitorUpdate(Monitor * const char *name; uint32 map; } table[] = { - { "NMI", IntmapNMI }, - { "MFP", IntmapMFP }, - { "SCC", IntmapSCC }, - { "DMAC", IntmapDMAC }, - { "PEDEC", IntmapPEDEC }, + { "NMI", IntmapNMI }, + { "MFP", IntmapMFP }, + { "SCC", IntmapSCC }, + { "Nereid0", IntmapNereid0 }, + { "Nereid1", IntmapNereid1 }, + { "DMAC", IntmapDMAC }, + { "PEDEC", IntmapPEDEC }, }; // CPU の割り込み可否は本当は関係ないけど、便宜的に一緒に表示したい - uint intr_mask = gMPU680x0->GetCPU()->reg.intr_mask; + auto mpu680x0 = dynamic_cast(mpu); + uint intr_mask = mpu680x0->reg.intr_mask; screen.Clear(); + // 0 1 2 3 4 + // 01234567890123456789012345678901234567890 + // Lv Device IM=7 Count + // 1 Nereid0 01234567890123456789012345 + // SPC Mask + y = 0; - screen.Print(0, y++, "Lv Device Count IM=%d", intr_mask); + screen.Print(0, y, "Lv Device IM=%d", intr_mask); + screen.Puts(36, y, "Count"); + y++; for (int i = 0; i < countof(table); i++) { uint32 map = table[i].map; int clz = __builtin_clz(map); int lv = (31 - clz) / 4; screen.Print(0, y, "%d", lv); - screen.Print(2, y, TA::OnOff(intmap & map), "%s", table[i].name); - screen.Print(8, y, "%11" PRIu64, counter[clz]); + if ((map == IntmapNereid0 && net[0] == NULL) || + (map == IntmapNereid1 && net[1] == NULL)) + { + screen.Puts(3, y, TA::Disable, table[i].name); + } else { + screen.Puts(3, y, TA::OnOff(intmap & map), table[i].name); + } if (lv <= intr_mask) { - screen.Puts(21, y, "Mask"); + screen.Puts(11, y, "Mask"); } + screen.Print(15, y, "%26s", format_number(counter[clz]).c_str()); y++; } // PEDEC 分も一緒に表示したい - gPEDEC->MonitorUpdate(screen, intr_mask, y); + pedec->MonitorUpdate(screen, intr_mask, y); } @@ -266,7 +332,7 @@ X68030Interrupt::MonitorUpdate(Monitor * LunaInterrupt::LunaInterrupt() { monitor.func = ToMonitorCallback(&LunaInterrupt::MonitorUpdate); - monitor.SetSize(25, 6); + monitor.SetSize(40, 8); monitor.Regist(ID_MONITOR_INTERRUPT); } @@ -275,23 +341,46 @@ LunaInterrupt::~LunaInterrupt() { } +// 初期化 +bool +LunaInterrupt::Init() +{ + if (inherited::Init() == false) { + return false; + } + + lance = GetLanceDevice(); + nmi = GetNMIDevice(); + sio = GetSIODevice(); + spc = GetSPCDevice(); + sysclk = GetSysClkDevice(); + + return true; +} + // デバイスから Intmap 値を引く uint32 -LunaInterrupt::GetIntmap(Device *source) const +LunaInterrupt::GetIntmap(const Device *source) const { - if (__predict_true(source == gSIO)) { + if (__predict_true(source == sio)) { return IntmapSIO; } - if (__predict_true(source == gSysClk)) { + if (__predict_true(source == sysclk)) { return IntmapSysClk; } - if (__predict_true(source == gEthernet)) { + if (__predict_true(source == lance)) { return IntmapLance; } - if (__predict_true(source == gSPC)) { + if (__predict_true(source == spc)) { return IntmapSPC; } - if (source == gNMI) { + if (__predict_true(source == DEVICE_XPINT_HIGH)) { + return IntmapXPHigh; + } + if (__predict_true(source == DEVICE_XPINT_LOW)) { + return IntmapXPLow; + } + if (source == nmi) { return IntmapNMI; } VMPANIC("Unknown interrupt source?"); @@ -316,27 +405,158 @@ LunaInterrupt::MonitorUpdate(Monitor *, { "NMI", IntmapNMI }, { "SIO", IntmapSIO }, { "Clock", IntmapSysClk }, + { "XP(Hi)", IntmapXPHigh }, { "Lance", IntmapLance }, { "SPC", IntmapSPC }, + { "XP(Lo)", IntmapXPLow }, }; // CPU の割り込み可否は本当は関係ないけど、便宜的に一緒に表示したい - uint intr_mask = gMPU680x0->GetCPU()->reg.intr_mask; + auto mpu680x0 = dynamic_cast(mpu); + uint intr_mask = mpu680x0->reg.intr_mask; screen.Clear(); + // 0 1 2 3 4 + // 01234567890123456789012345678901234567890 + // Lv Device IM=7 Count + // 1 XP(Hi) Mask01234567890123456789012345 + + y = 0; + screen.Print(0, y, "Lv Device IM=%d", intr_mask); + screen.Puts(35, y, "Count"); + y++; + for (int i = 0; i < countof(table); i++) { + uint32 map = table[i].map; + int clz = __builtin_clz(map); + int lv = (31 - clz) / 4; + screen.Print(0, y, "%d", lv); + screen.Print(3, y, TA::OnOff(intmap & map), "%s", table[i].name); + if (lv <= intr_mask) { + screen.Puts(10, y, "Mask"); + } + screen.Print(14, y, "%26s", format_number(counter[clz]).c_str()); + y++; + } +} + + +// +// NEWS 仮想割り込みコントローラ +// + +// コンストラクタ +NewsInterrupt::NewsInterrupt() +{ + monitor.func = ToMonitorCallback(&NewsInterrupt::MonitorUpdate); + monitor.SetSize(40, 5); + monitor.Regist(ID_MONITOR_INTERRUPT); +} + +// デストラクタ +NewsInterrupt::~NewsInterrupt() +{ +} + +// 初期化 +bool +NewsInterrupt::Init() +{ + if (inherited::Init() == false) { + return false; + } + + lance = GetLanceDevice(); + newsctlr = GetNewsCtlrDevice(); + scc = GetSCCDevice(); + + return true; +} + +// デバイスから Intmap 値を引く +uint32 +NewsInterrupt::GetIntmap(const Device *source) const +{ + if (__predict_true(source == newsctlr)) { + return IntmapTimer; + } + if (__predict_true(source == scc)) { + return IntmapSCC; + } + if (__predict_true(source == lance)) { + return IntmapLance; + } + VMPANIC("Unknown interrupt source?"); +} + +// 割り込みアクノリッジに応答する +int +NewsInterrupt::InterruptAcknowledge(int lv) +{ + // NEWS では 5 の SCC だけベクタで、他はオートベクタ? + switch (lv) { + case 5: + return scc->InterruptAcknowledge(); + + default: + return AutoVector; + } +} + +// ステータスバイトを読み出す。NewsCtlr から呼ばれる。 +uint8 +NewsInterrupt::PeekStatus() const +{ + uint8 data = 0; + + if ((intmap & IntmapSIC)) { + data |= 0x80; + } + if ((intmap & IntmapLance)) { + data |= 0x04; + } + + return data; +} + +void +NewsInterrupt::MonitorUpdate(Monitor *, TextScreen& screen) +{ + int y; + struct { + const char *name; + uint32 map; + } table[] = { + { "Timer", IntmapTimer }, + { "SCC", IntmapSCC }, + { "Lance", IntmapLance }, + }; + + // CPU の割り込み可否は本当は関係ないけど、便宜的に一緒に表示したい + auto mpu680x0 = dynamic_cast(mpu); + uint intr_mask = mpu680x0->reg.intr_mask; + + screen.Clear(); + + // 0 1 2 3 4 + // 01234567890123456789012345678901234567890 + // Lv Device IM=7 Count + // 1 XP(Hi) Mask01234567890123456789012345 + y = 0; - screen.Print(0, y++, "Lv Device Count IM=%d", intr_mask); + screen.Print(0, y, "Lv Device IM=%d", intr_mask); + screen.Puts(35, y, "Count"); + y++; for (int i = 0; i < countof(table); i++) { uint32 map = table[i].map; int clz = __builtin_clz(map); int lv = (31 - clz) / 4; screen.Print(0, y, "%d", lv); - screen.Print(2, y, TA::OnOff(intmap & map), "%s", table[i].name); - screen.Print(8, y, "%11" PRIu64, counter[clz]); + screen.Print(3, y, TA::OnOff(intmap & map), "%s", table[i].name); if (lv <= intr_mask) { - screen.Puts(21, y, "Mask"); + screen.Puts(10, y, "Mask"); } + screen.Print(14, y, "%26s", format_number(counter[clz]).c_str()); y++; } }