Implement Application Processor bootstrap function
All checks were successful
Builds / ExectOS (i686, debug) (push) Successful in 39s
Builds / ExectOS (i686, release) (push) Successful in 38s
Builds / ExectOS (amd64, release) (push) Successful in 59s
Builds / ExectOS (amd64, debug) (push) Successful in 1m1s

This commit is contained in:
2026-05-17 14:29:45 +02:00
parent 29368a0dd8
commit 9603453334
3 changed files with 186 additions and 107 deletions

View File

@@ -9,6 +9,111 @@
#include <xtos.hh>
/**
* Bootstraps an Application Processor (AP) into the active kernel. This routine is executed exclusively by secondary
* processors after being awakened by the BSP. It is called directly from the startup trampoline.
*
* @param StartBlock
* Supplies a pointer to the processor start block containing initialization information provided by the kernel.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
KE::KernelInit::BootstrapApplicationProcessor(IN PPROCESSOR_START_BLOCK StartBlock)
{
PKPROCESSOR_BLOCK ProcessorBlock;
/* Initialize application CPU */
AR::ProcSup::InitializeProcessor(StartBlock->ProcessorStructures);
/* Initialize processor */
HL::Cpu::InitializeProcessor();
/* Raise to HIGH runlevel */
KE::RunLevel::RaiseRunLevel(HIGH_LEVEL);
/* Mark processor as started */
StartBlock->Started = TRUE;
/* Get current processor block */
ProcessorBlock = KE::Processor::GetCurrentProcessorBlock();
/* Enter infinite loop */
DebugPrint(L"KernelInit::BootstrapApplicationProcessor() finished for CPU #%lu. Entering infinite loop.\n",
ProcessorBlock->CpuNumber);
KE::Crash::HaltSystem();
}
/**
* Bootstraps the XT kernel and global subsystems. This routine is executed exclusively by the Bootstrap Processor
* and it is called immediately after switching to the kernel boot stack.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
KE::KernelInit::BootstrapKernel(VOID)
{
PKPROCESSOR_CONTROL_BLOCK Prcb;
ULONG_PTR PageDirectory[2];
PKPROCESS CurrentProcess;
PKTHREAD CurrentThread;
/* Get processor control block and current thread */
Prcb = KE::Processor::GetCurrentProcessorControlBlock();
CurrentThread = KE::Processor::GetCurrentThread();
/* Get current process */
CurrentProcess = CurrentThread->ApcState.Process;
/* Initialize CPU power state structures */
PO::Idle::InitializeProcessorIdleState(Prcb);
/* Save processor state */
KE::Processor::SaveProcessorState(&Prcb->ProcessorState);
/* Initialize spin locks */
KE::SpinLock::InitializeAllLocks();
KE::SpinLock::InitializeLockQueues();
/* Lower to APC runlevel */
KE::RunLevel::LowerRunLevel(APC_LEVEL);
/* Initialize XTOS kernel */
InitializeKernel();
/* Initialize Idle process */
PageDirectory[0] = 0;
PageDirectory[1] = 0;
KE::KProcess::InitializeProcess(CurrentProcess, 0, MAXULONG_PTR, PageDirectory, FALSE);
CurrentProcess->Quantum = MAXCHAR;
/* Initialize Idle thread */
KE::KThread::InitializeThread(CurrentProcess, CurrentThread, NULLPTR, NULLPTR, NULLPTR,
NULLPTR, NULLPTR, AR::ProcSup::GetBootStack(), TRUE);
CurrentThread->NextProcessor = Prcb->CpuNumber;
CurrentThread->Priority = THREAD_HIGH_PRIORITY;
CurrentThread->State = Running;
CurrentThread->Affinity = (ULONG_PTR)1 << Prcb->CpuNumber;
CurrentThread->WaitRunLevel = DISPATCH_LEVEL;
CurrentProcess->ActiveProcessors |= (ULONG_PTR)1 << Prcb->CpuNumber;
/* Initialize Memory Manager */
MM::Manager::InitializeMemoryManager();
/* Enable shadow buffer for framebuffer */
HL::FrameBuffer::EnableShadowBuffer();
/* Enter infinite loop */
DebugPrint(L"KernelInit::BootstrapKernel() finished. Entering infinite loop.\n");
KE::Crash::HaltSystem();
}
/**
* This routine initializes XT kernel.
*
@@ -60,72 +165,6 @@ KE::KernelInit::InitializeMachine(VOID)
HL::Cpu::InitializeProcessor();
}
/**
* This routine starts up the XT kernel. It is called after switching boot stack.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
KE::KernelInit::StartKernel(VOID)
{
PKPROCESSOR_CONTROL_BLOCK Prcb;
ULONG_PTR PageDirectory[2];
PKPROCESS CurrentProcess;
PKTHREAD CurrentThread;
/* Get processor control block and current thread */
Prcb = KE::Processor::GetCurrentProcessorControlBlock();
CurrentThread = KE::Processor::GetCurrentThread();
/* Get current process */
CurrentProcess = CurrentThread->ApcState.Process;
/* Initialize CPU power state structures */
PO::Idle::InitializeProcessorIdleState(Prcb);
/* Save processor state */
KE::Processor::SaveProcessorState(&Prcb->ProcessorState);
/* Initialize spin locks */
KE::SpinLock::InitializeAllLocks();
KE::SpinLock::InitializeLockQueues();
/* Lower to APC runlevel */
KE::RunLevel::LowerRunLevel(APC_LEVEL);
/* Initialize XTOS kernel */
InitializeKernel();
/* Initialize Idle process */
PageDirectory[0] = 0;
PageDirectory[1] = 0;
KE::KProcess::InitializeProcess(CurrentProcess, 0, MAXULONG_PTR, PageDirectory, FALSE);
CurrentProcess->Quantum = MAXCHAR;
/* Initialize Idle thread */
KE::KThread::InitializeThread(CurrentProcess, CurrentThread, NULLPTR, NULLPTR, NULLPTR,
NULLPTR, NULLPTR, AR::ProcSup::GetBootStack(), TRUE);
CurrentThread->NextProcessor = Prcb->CpuNumber;
CurrentThread->Priority = THREAD_HIGH_PRIORITY;
CurrentThread->State = Running;
CurrentThread->Affinity = (ULONG_PTR)1 << Prcb->CpuNumber;
CurrentThread->WaitRunLevel = DISPATCH_LEVEL;
CurrentProcess->ActiveProcessors |= (ULONG_PTR)1 << Prcb->CpuNumber;
/* Initialize Memory Manager */
MM::Manager::InitializeMemoryManager();
/* Enable shadow buffer for framebuffer */
HL::FrameBuffer::EnableShadowBuffer();
/* Enter infinite loop */
DebugPrint(L"KernelInit::StartKernel() finished. Entering infinite loop.\n");
KE::Crash::HaltSystem();
}
/**
* Switches execution to a new boot stack and transfers control to the KernelInit::StartKernel() routine.
*
@@ -144,7 +183,7 @@ KE::KernelInit::SwitchBootStack(VOID)
Stack = ((ULONG_PTR)AR::ProcSup::GetBootStack() + KERNEL_STACK_SIZE) & ~(STACK_ALIGNMENT - 1);
/* Get address of KernelInit::StartKernel() */
StartKernel = (PVOID)KE::KernelInit::StartKernel;
StartKernel = (PVOID)KE::KernelInit::BootstrapKernel;
/* Discard old stack frame, switch stack and jump to KernelInit::StartKernel() */
__asm__ volatile("movq %[Stack], %%rsp\n"