Skip to content

Commit

Permalink
[HALX86] Fix AP startup by properly avoiding the BSP
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkFire01 committed Sep 28, 2024
1 parent 053939e commit 0a14865
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
15 changes: 12 additions & 3 deletions hal/halx86/acpi/madt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ******************************************************************/

Expand All @@ -59,6 +60,7 @@ HalpParseApicTables(
ACPI_SUBTABLE_HEADER *AcpiHeader;
ULONG_PTR TableEnd;

HalpProcessorIdentity = HalpStaticProcessorIdentity;
MadtTable = HalAcpiGetTable(LoaderBlock, APIC_SIGNATURE);
if (!MadtTable)
{
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions hal/halx86/apic/apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
ULONG ApicVersion;
UCHAR HalpVectorToIndex[256];

ULONG
HalpGetCurrentProcessorHwID()
{
return ApicRead(APIC_ID);
}

#ifndef _M_AMD64
const UCHAR
HalpIRQLtoTPR[32] =
Expand Down
6 changes: 6 additions & 0 deletions hal/halx86/pic/pic.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ NTAPI
HalpEndSoftwareInterrupt(IN KIRQL OldIrql,
IN PKTRAP_FRAME TrapFrame);

ULONG
HalpGetCurrentProcessorHwID()
{
return 0;
}

/* GLOBALS ********************************************************************/

#ifndef _MINIHAL_
Expand Down
9 changes: 8 additions & 1 deletion hal/halx86/smp/i386/spinup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0a14865

Please sign in to comment.