From 5a5604c35d493f503b96ed902871b7778220e283 Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Thu, 28 May 2026 23:50:02 +0200 Subject: [PATCH] Register dispatch interrupt handler --- xtoskrnl/includes/ke/dispatch.hh | 1 + xtoskrnl/ke/amd64/krnlinit.cc | 6 ++++++ xtoskrnl/ke/dispatch.cc | 19 +++++++++++++++++++ xtoskrnl/ke/i686/krnlinit.cc | 6 ++++++ 4 files changed, 32 insertions(+) diff --git a/xtoskrnl/includes/ke/dispatch.hh b/xtoskrnl/includes/ke/dispatch.hh index 5d65064..ca1fdd1 100644 --- a/xtoskrnl/includes/ke/dispatch.hh +++ b/xtoskrnl/includes/ke/dispatch.hh @@ -19,6 +19,7 @@ namespace KE { public: STATIC XTFASTCALL VOID ExitDispatcher(IN KRUNLEVEL OldRunLevel); + STATIC XTCDECL VOID HandleDispatchInterrupt(IN PKTRAP_FRAME TrapFrame); STATIC XTFASTCALL BOOLEAN SwitchContext(IN PKTHREAD CurrentThread, IN KRUNLEVEL RunLevel); STATIC XTAPI VOID UpdateRunTime(IN PKTRAP_FRAME TrapFrame, diff --git a/xtoskrnl/ke/amd64/krnlinit.cc b/xtoskrnl/ke/amd64/krnlinit.cc index 2a23e87..d1871ad 100644 --- a/xtoskrnl/ke/amd64/krnlinit.cc +++ b/xtoskrnl/ke/amd64/krnlinit.cc @@ -57,6 +57,9 @@ KE::KernelInit::BootstrapApplicationProcessor(IN PPROCESSOR_START_BLOCK StartBlo /* Initialize local clock for this CPU */ HL::Timer::InitializeLocalClock(); + /* Register DISPATCH interrupt handler */ + HL::Irq::RegisterSystemInterruptHandler(APIC_VECTOR_DPC, KE::Dispatcher::HandleDispatchInterrupt); + /* Enter infinite loop */ DebugPrint(L"KernelInit::BootstrapApplicationProcessor() finished for CPU #%lu. Entering infinite loop.\n", ControlBlock->CpuNumber); @@ -129,6 +132,9 @@ KE::KernelInit::BootstrapKernel(VOID) KE::Processor::InitializeProcessorBlocks(); HL::Cpu::StartAllProcessors(); + /* Register DISPATCH interrupt handler */ + HL::Irq::RegisterSystemInterruptHandler(APIC_VECTOR_DPC, KE::Dispatcher::HandleDispatchInterrupt); + /* Enter infinite loop */ DebugPrint(L"KernelInit::BootstrapKernel() finished. Entering infinite loop.\n"); KE::Crash::HaltSystem(); diff --git a/xtoskrnl/ke/dispatch.cc b/xtoskrnl/ke/dispatch.cc index df464aa..2682d4d 100644 --- a/xtoskrnl/ke/dispatch.cc +++ b/xtoskrnl/ke/dispatch.cc @@ -29,6 +29,25 @@ KE::Dispatcher::ExitDispatcher(IN KRUNLEVEL OldRunLevel) RunLevel::LowerRunLevel(OldRunLevel); } +/** + * Handles the dispatch interrupt by retiring pending DPCs, asking the scheduler for the next runnable thread + * and performing the context switch. + * + * @param TrapFrame + * Supplies a pointer to the hardware trap frame representing the interrupted context. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTCDECL +VOID +KE::Dispatcher::HandleDispatchInterrupt(IN PKTRAP_FRAME TrapFrame) +{ + /* End the interrupt */ + HL::Pic::SendEoi(); +} + /** * Updates the runtime quantum of the currently executing thread and handles preemption. * diff --git a/xtoskrnl/ke/i686/krnlinit.cc b/xtoskrnl/ke/i686/krnlinit.cc index 7dd579b..44e719f 100644 --- a/xtoskrnl/ke/i686/krnlinit.cc +++ b/xtoskrnl/ke/i686/krnlinit.cc @@ -57,6 +57,9 @@ KE::KernelInit::BootstrapApplicationProcessor(IN PPROCESSOR_START_BLOCK StartBlo /* Initialize local clock for this CPU */ HL::Timer::InitializeLocalClock(); + /* Register DISPATCH interrupt handler */ + HL::Irq::RegisterSystemInterruptHandler(APIC_VECTOR_DPC, KE::Dispatcher::HandleDispatchInterrupt); + /* Enter infinite loop */ DebugPrint(L"KernelInit::BootstrapApplicationProcessor() finished for CPU #%lu. Entering infinite loop.\n", ControlBlock->CpuNumber); @@ -129,6 +132,9 @@ KE::KernelInit::BootstrapKernel(VOID) KE::Processor::InitializeProcessorBlocks(); HL::Cpu::StartAllProcessors(); + /* Register DISPATCH interrupt handler */ + HL::Irq::RegisterSystemInterruptHandler(APIC_VECTOR_DPC, KE::Dispatcher::HandleDispatchInterrupt); + /* Enter infinite loop */ DebugPrint(L"KernelInit::BootstrapKernel() finished. Entering infinite loop.\n"); KE::Crash::HaltSystem();