From 74d68ead7218220505704d82820947746f70e282 Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Fri, 26 Jun 2026 20:46:27 +0000 Subject: [PATCH] stos/amd64: lapic: Detect if x2APIC mode is present Signed-off-by: Chloe M. --- paw/stos/arch/amd64/cpu/lapic.c | 14 ++++++++++++++ paw/stos/head/arch/amd64/mcb.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/paw/stos/arch/amd64/cpu/lapic.c b/paw/stos/arch/amd64/cpu/lapic.c index 00662e1..8004f43 100644 --- a/paw/stos/arch/amd64/cpu/lapic.c +++ b/paw/stos/arch/amd64/cpu/lapic.c @@ -43,6 +43,19 @@ LapicIsSupported(VOID) return ISSET(Edx, BIT(9)) != 0; } +/* + * Returns true if the CPU can operate its Local APIC unit + * in the newer x2APIC mode. + */ +static BOOLEAN +LapicHasX2Apic(VOID) +{ + ULONG Ecx, Unused; + + CPUID(1, Unused, Unused, Ecx, Unused); + return ISSET(Ecx, BIT(21)) != 0; +} + /* * Enable the Local APIC unit */ @@ -85,6 +98,7 @@ MdLapicInit(KPCR *Kpcr) Mcb = &Kpcr->Mcb; Mcb->LapicBase = PMA_TO_VMA((UPTR)Madt->LapicAddr); + Mcb->HasX2Apic = LapicHasX2Apic(); /* Enable the Local APIC */ LapicEnable(); diff --git a/paw/stos/head/arch/amd64/mcb.h b/paw/stos/head/arch/amd64/mcb.h index 3722867..0357c50 100644 --- a/paw/stos/head/arch/amd64/mcb.h +++ b/paw/stos/head/arch/amd64/mcb.h @@ -18,11 +18,13 @@ * @ModelId: Processor model ID * @FamilyId: Processor family ID * @LapicBase: Local APIC MMIO base + * @HasX2Apic: If set, x2APIC is supported */ typedef struct { UCHAR ModelId; USHORT FamilyId : 12; VOID *LapicBase; + UCHAR HasX2Apic : 1; } MCB; #endif /* !_MACHINE_MCB_H_ */