From 0a14865f96cd6aa28539657680839c615a06fdd9 Mon Sep 17 00:00:00 2001 From: Justin Miller Date: Fri, 27 Sep 2024 22:22:47 -0700 Subject: [PATCH] [HALX86] Fix AP startup by properly avoiding the BSP --- hal/halx86/acpi/madt.c | 15 ++++++++++++--- hal/halx86/apic/apic.c | 6 ++++++ hal/halx86/pic/pic.c | 6 ++++++ hal/halx86/smp/i386/spinup.c | 9 ++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/hal/halx86/acpi/madt.c b/hal/halx86/acpi/madt.c index f61d51b5d024c..6d57fb587f887 100644 --- a/hal/halx86/acpi/madt.c +++ b/hal/halx86/acpi/madt.c @@ -42,11 +42,12 @@ HALP_APIC_INFO_TABLE HalpApicInfoTable; // Bits 2-31 are reserved. static PROCESSOR_IDENTITY HalpStaticProcessorIdentity[MAXIMUM_PROCESSORS]; -const PPROCESSOR_IDENTITY HalpProcessorIdentity = HalpStaticProcessorIdentity; +PPROCESSOR_IDENTITY HalpProcessorIdentity; -#if 0 extern ULONG HalpPicVectorRedirect[16]; -#endif + +ULONG +HalpGetCurrentProcessorHwID(); /* FUNCTIONS ******************************************************************/ @@ -59,6 +60,7 @@ HalpParseApicTables( ACPI_SUBTABLE_HEADER *AcpiHeader; ULONG_PTR TableEnd; + HalpProcessorIdentity = HalpStaticProcessorIdentity; MadtTable = HalAcpiGetTable(LoaderBlock, APIC_SIGNATURE); if (!MadtTable) { @@ -153,6 +155,13 @@ HalpParseApicTables( LocalApic->ProcessorId; HalpProcessorIdentity[HalpApicInfoTable.ProcessorCount].LapicId = LocalApic->Id; + /* Check against the processor running this code, which is only the BSP. */ + if (LocalApic->Id == HalpGetCurrentProcessorHwID()) + { + HalpProcessorIdentity[HalpApicInfoTable.ProcessorCount].BSPCheck = TRUE; + HalpProcessorIdentity[HalpApicInfoTable.ProcessorCount].ProcessorStarted = TRUE; + } + HalpApicInfoTable.ProcessorCount++; break; diff --git a/hal/halx86/apic/apic.c b/hal/halx86/apic/apic.c index ae2c2e5a4abeb..5e3b9ef13061f 100644 --- a/hal/halx86/apic/apic.c +++ b/hal/halx86/apic/apic.c @@ -27,6 +27,12 @@ ULONG ApicVersion; UCHAR HalpVectorToIndex[256]; +ULONG +HalpGetCurrentProcessorHwID() +{ + return ApicRead(APIC_ID); +} + #ifndef _M_AMD64 const UCHAR HalpIRQLtoTPR[32] = diff --git a/hal/halx86/pic/pic.c b/hal/halx86/pic/pic.c index e901dc8be37d5..663ab85f23aa4 100644 --- a/hal/halx86/pic/pic.c +++ b/hal/halx86/pic/pic.c @@ -17,6 +17,12 @@ NTAPI HalpEndSoftwareInterrupt(IN KIRQL OldIrql, IN PKTRAP_FRAME TrapFrame); +ULONG +HalpGetCurrentProcessorHwID() +{ + return 0; +} + /* GLOBALS ********************************************************************/ #ifndef _MINIHAL_ diff --git a/hal/halx86/smp/i386/spinup.c b/hal/halx86/smp/i386/spinup.c index 12fbea168cb35..c97752bc0a730 100644 --- a/hal/halx86/smp/i386/spinup.c +++ b/hal/halx86/smp/i386/spinup.c @@ -26,8 +26,9 @@ extern PVOID HalpAPEntryData; extern PVOID HalpAPEntry32; extern PVOID HalpAPEntry16End; extern HALP_APIC_INFO_TABLE HalpApicInfoTable; +extern PPROCESSOR_IDENTITY HalpProcessorIdentity; -ULONG HalpStartedProcessorCount = 1; +ULONG HalpStartedProcessorCount = 0; #ifndef Add2Ptr #define Add2Ptr(P,I) ((PVOID)((PUCHAR)(P) + (I))) @@ -91,6 +92,12 @@ HalStartNextProcessor( if (HalpStartedProcessorCount == HalpApicInfoTable.ProcessorCount) return FALSE; + if (HalpProcessorIdentity[HalpStartedProcessorCount].BSPCheck == TRUE) + { + // SKIP the BSP + HalpStartedProcessorCount++; + } + // Initalize the temporary page table // TODO: clean it up after an AP boots successfully ULONG initialCr3 = HalpSetupTemporaryMappings(ProcessorState);