--- nono/vm/interrupt.cpp 2026/04/29 17:05:06 1.1.1.5 +++ nono/vm/interrupt.cpp 2026/04/29 17:05:10 1.1.1.6 @@ -4,6 +4,30 @@ // Licensed under nono-license.txt // +// +// 割り込みコントローラ +// + +// IODevice +// | +// | +-----------------+ +// +--| InterruptDevice | (割り込みコントローラの共通部) +// +-----------------+ +// | +-----------------+ +// +--| M680x0Interrupt | (m68k 割り込みコントローラの共通部) +// | +-----------------+ +// | | +// | | +-----------------+ +// | +--| X68030Interrupt | (X68030 の割り込みコントローラ) +// | | +-----------------+ +// | | +// | | +---------------+ +// | +--| LunaInterrupt | (LUNA-I の割り込みコントローラ) +// | +---------------+ +// | +// +-- PEDECDevice (X68030 の Lv1 担当コントローラ) +// +-- SysCtlrDevice (LUNA88K の割り込みコントローラ) + #include "interrupt.h" #include "dmac.h" #include "lance.h" @@ -11,28 +35,14 @@ #include "m68030.h" #include "mfp.h" #include "mpu680x0.h" +#include "nmi.h" #include "scc.h" #include "sio.h" #include "spc.h" #include "sysclk.h" -// IODevice -// | -// v -// InterruptDevice -// | -// +------------------------+-------------------------+ -// | | | -// | v | -// | M680x0Interrupt | -// | | | -// | +--------+--------+ | -// v v v v -// PEDECDevice X68030Interrupt LunaInterrupt SysCtlrDevice -// (X68030のLv1 (X68030) (LUNA-I) (LUNA88K) -// カスケード) - -std::unique_ptr gInterrupt; +// グローバル参照用 +InterruptDevice *gInterrupt; // // 仮想割り込みコントローラ (共通部) @@ -53,11 +63,12 @@ InterruptDevice::InterruptDevice() // デストラクタ InterruptDevice::~InterruptDevice() { + gInterrupt = NULL; } // リセット void -InterruptDevice::ResetHard() +InterruptDevice::ResetHard(bool poweron) { intmap = IntmapSentinel; memset(&counter, 0, sizeof(counter)); @@ -120,9 +131,9 @@ M680x0Interrupt::~M680x0Interrupt() // リセット void -M680x0Interrupt::ResetHard() +M680x0Interrupt::ResetHard(bool poweron) { - inherited::ResetHard(); + inherited::ResetHard(poweron); ipl = 0; } @@ -131,7 +142,7 @@ M680x0Interrupt::ChangeInterrupt() { int newipl; - // intmap の最下位ビットは常に立ててあるので 0 にならない + // intmap は最下位ビットを常に立ててあるので 0 にならない newipl = (uint)(31 - __builtin_clz(intmap)) / 4; // 割り込みレベルが変わったら、新しいレベルを通知 @@ -149,7 +160,7 @@ M680x0Interrupt::ChangeInterrupt() // コンストラクタ X68030Interrupt::X68030Interrupt() { - monitor.func = (MonitorCallback_t)&X68030Interrupt::MonitorUpdate; + monitor.func = ToMonitorCallback(&X68030Interrupt::MonitorUpdate); monitor.SetSize(25, 11); monitor.Regist(ID_MONITOR_INTERRUPT); } @@ -163,23 +174,22 @@ X68030Interrupt::~X68030Interrupt() uint32 X68030Interrupt::GetIntmap(Device *source) const { - if (__predict_true(source == gMFP.get())) { + if (__predict_true(source == gMFP)) { return IntmapMFP; } - if (__predict_true(source == gSCC.get())) { + if (__predict_true(source == gSCC)) { return IntmapSCC; } - if (__predict_true(source == gDMAC.get())) { + if (__predict_true(source == gDMAC)) { return IntmapDMAC; } - if (__predict_true(source == gPEDEC.get())) { + if (__predict_true(source == gPEDEC)) { return IntmapPEDEC; } - if (source == NULL) { - // XXX デバイスまだいないのでとりあえず + if (source == gNMI) { return IntmapNMI; } - PANIC("Unknown interrupt source?"); + VMPANIC("Unknown interrupt source?"); } // 割り込みアクノリッジに応答する @@ -187,6 +197,9 @@ int X68030Interrupt::InterruptAcknowledge(int lv) { switch (lv) { + case 7: + return AutoVector; + case 6: return gMFP->InterruptAcknowledge(); @@ -202,7 +215,7 @@ X68030Interrupt::InterruptAcknowledge(in default: break; } - PANIC("Unknown interrupt acknowledge lv=%d", lv); + VMPANIC("Unknown interrupt acknowledge lv=%d", lv); } void @@ -221,12 +234,12 @@ X68030Interrupt::MonitorUpdate(Monitor * }; // CPU の割り込み可否は本当は関係ないけど、便宜的に一緒に表示したい - uint intr_level = gMPU680x0->GetCPU()->reg.intr_level; + uint intr_mask = gMPU680x0->GetCPU()->reg.intr_mask; screen.Clear(); y = 0; - screen.Print(0, y++, "Lv Device Count IM=%d", intr_level); + screen.Print(0, y++, "Lv Device Count IM=%d", intr_mask); for (int i = 0; i < countof(table); i++) { uint32 map = table[i].map; int clz = __builtin_clz(map); @@ -234,16 +247,17 @@ X68030Interrupt::MonitorUpdate(Monitor * 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 (lv <= intr_level) { + if (lv <= intr_mask) { screen.Puts(21, y, "Mask"); } y++; } // PEDEC 分も一緒に表示したい - gPEDEC->MonitorUpdate(screen, intr_level, y); + gPEDEC->MonitorUpdate(screen, intr_mask, y); } + // // LUNA-I 仮想割り込みコントローラ // @@ -251,8 +265,8 @@ X68030Interrupt::MonitorUpdate(Monitor * // コンストラクタ LunaInterrupt::LunaInterrupt() { - monitor.func = (MonitorCallback_t)&LunaInterrupt::MonitorUpdate; - monitor.SetSize(25, 5); + monitor.func = ToMonitorCallback(&LunaInterrupt::MonitorUpdate); + monitor.SetSize(25, 6); monitor.Regist(ID_MONITOR_INTERRUPT); } @@ -261,24 +275,26 @@ LunaInterrupt::~LunaInterrupt() { } - // デバイスから Intmap 値を引く uint32 LunaInterrupt::GetIntmap(Device *source) const { - if (__predict_true(source == gSIO.get())) { + if (__predict_true(source == gSIO)) { return IntmapSIO; } - if (__predict_true(source == gSysClk.get())) { + if (__predict_true(source == gSysClk)) { return IntmapSysClk; } - if (__predict_true(source == gEthernet.get())) { + if (__predict_true(source == gEthernet)) { return IntmapLance; } - if (__predict_true(source == gSPC.get())) { + if (__predict_true(source == gSPC)) { return IntmapSPC; } - PANIC("Unknown interrupt source?"); + if (source == gNMI) { + return IntmapNMI; + } + VMPANIC("Unknown interrupt source?"); } // 割り込みアクノリッジに応答する @@ -297,6 +313,7 @@ LunaInterrupt::MonitorUpdate(Monitor *, const char *name; uint32 map; } table[] = { + { "NMI", IntmapNMI }, { "SIO", IntmapSIO }, { "Clock", IntmapSysClk }, { "Lance", IntmapLance }, @@ -304,12 +321,12 @@ LunaInterrupt::MonitorUpdate(Monitor *, }; // CPU の割り込み可否は本当は関係ないけど、便宜的に一緒に表示したい - uint intr_level = gMPU680x0->GetCPU()->reg.intr_level; + uint intr_mask = gMPU680x0->GetCPU()->reg.intr_mask; screen.Clear(); y = 0; - screen.Print(0, y++, "Lv Device Count IM=%d", intr_level); + screen.Print(0, y++, "Lv Device Count IM=%d", intr_mask); for (int i = 0; i < countof(table); i++) { uint32 map = table[i].map; int clz = __builtin_clz(map); @@ -317,7 +334,7 @@ LunaInterrupt::MonitorUpdate(Monitor *, 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 (lv <= intr_level) { + if (lv <= intr_mask) { screen.Puts(21, y, "Mask"); } y++;