From 9479f3d3641d67ac7bef38879135933e63ae78b4 Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Wed, 25 Mar 2026 22:52:58 +0100 Subject: [PATCH] Implement APIC presence check and panic if unsupported --- xtoskrnl/hl/x86/pic.cc | 43 +++++++++++++++++++++++++++++++++++++ xtoskrnl/includes/hl/pic.hh | 1 + 2 files changed, 44 insertions(+) diff --git a/xtoskrnl/hl/x86/pic.cc b/xtoskrnl/hl/x86/pic.cc index 2d31e2ba..8fefc6c2 100644 --- a/xtoskrnl/hl/x86/pic.cc +++ b/xtoskrnl/hl/x86/pic.cc @@ -9,6 +9,41 @@ #include +/** + * Checks whether the APIC is supported by the processor. + * + * @return This routine returns TRUE if APIC is supported, or FALSE otherwise. + * + * @since XT 1.0 + */ +XTAPI +BOOLEAN +HL::Pic::CheckApicSupport(VOID) +{ + CPUID_REGISTERS CpuRegisters; + + /* Prepare CPUID registers */ + CpuRegisters.Leaf = CPUID_GET_STANDARD1_FEATURES; + CpuRegisters.SubLeaf = 0; + CpuRegisters.Eax = 0; + CpuRegisters.Ebx = 0; + CpuRegisters.Ecx = 0; + CpuRegisters.Edx = 0; + + /* Get CPUID */ + AR::CpuFunc::CpuId(&CpuRegisters); + + /* Check APIC status from the CPUID results */ + if(!(CpuRegisters.Edx & CPUID_FEATURES_EDX_APIC)) + { + /* APIC is not supported */ + return FALSE; + } + + /* APIC is supported */ + return TRUE; +} + /** * Checks whether the x2APIC extension is supported by the processor. * @@ -124,6 +159,14 @@ HL::Pic::InitializeApic(VOID) APIC_LVT_REGISTER LvtRegister; ULONG CpuNumber; + /* Check APIC support */ + if(!CheckApicSupport()) + { + /* APIC is not supported, raise kernel panic */ + DebugPrint(L"FATAL ERROR: Local APIC not present.\n"); + KE::Crash::Panic(0x5D, CPUID_GET_STANDARD1_FEATURES, 0x0, 0x0, CPUID_FEATURES_EDX_APIC); + } + /* Determine APIC mode (xAPIC compatibility or x2APIC) */ if(CheckX2ApicSupport()) { diff --git a/xtoskrnl/includes/hl/pic.hh b/xtoskrnl/includes/hl/pic.hh index 85b8fcae..c90b0980 100644 --- a/xtoskrnl/includes/hl/pic.hh +++ b/xtoskrnl/includes/hl/pic.hh @@ -32,6 +32,7 @@ namespace HL IN ULONGLONG Value); private: + STATIC XTAPI BOOLEAN CheckApicSupport(VOID); STATIC XTAPI BOOLEAN CheckX2ApicSupport(VOID); STATIC XTCDECL VOID HandleApicSpuriousService(VOID); STATIC XTCDECL VOID HandlePicSpuriousService(VOID);