From f092c767a1988b91c481022f29f167f231d635ad Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 17 Apr 2025 23:56:28 +0200 Subject: kernel, SMP: put back AP init code. Signed-off-by: Amlal El Mahrouss --- dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'dev/kernel') diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index 938907f4..94c1ae73 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -210,15 +210,24 @@ namespace Kernel::HAL if (kMADTBlock) { - SizeT index = 1UL; + SizeT index = 1; kSMPInterrupt = 0; kSMPCount = 0; - kout << "SMP: Registering APIC IDs...\r"; + kout << "SMP: Starting APs...\r"; kApicBaseAddress = kMADTBlock->Address; + constexpr auto kMemoryAPStart = 0x7C000; + Char* ptr_ap_code = reinterpret_cast(kMemoryAPStart); + + mm_map_page(ptr_ap_code, ptr_ap_code, kMMFlagsWr | kMMFlagsPCD); + + SizeT hal_ap_blob_len = hal_ap_blob_end - hal_ap_blob_start; + + rt_copy_memory((Char*)hal_ap_blob_start, ptr_ap_code, hal_ap_blob_len); + while (Yes) { if (kMADTBlock->List[index].Type > 9 || @@ -232,7 +241,18 @@ namespace Kernel::HAL break; kAPICLocales[kSMPCount] = kMADTBlock->List[kSMPCount].LAPIC.ProcessorID; - (Void)(kout << "SMP: APIC ID: " << number(kAPICLocales[kSMPCount]) << kendl); + (void)(kout << "SMP: APIC ID: " << number(kAPICLocales[kSMPCount]) << kendl); + + // I'll just make the AP start from scratch here. + + hal_send_start_ipi(kApicBaseAddress, kAPICLocales[kSMPCount]); + + HardwareTimer timer(Kernel::rtl_ms(10)); + timer.Wait(); + + /// TODO: HAL helper to create an address. + + hal_send_sipi(kApicBaseAddress, kAPICLocales[kSMPCount], (UInt8)(((UIntPtr)ptr_ap_code) >> 12)); ++kSMPCount; break; @@ -244,7 +264,7 @@ namespace Kernel::HAL ++index; } - (Void)(kout << "SMP: Number of IDs: " << number(kSMPCount) << kendl); + (void)(kout << "SMP: number of APs: " << number(kSMPCount) << kendl); // Kernel is now SMP aware. // That means that the scheduler is now available (on MP Kernels) -- cgit v1.2.3