22#include <uacpi/uacpi.h>
33#include <uacpi/namespace.h>
44#include <uacpi/resources.h>
5+ #include <stdatomic.h>
56#include "uacpi/context.h"
67
78volatile struct limine_rsdp_request rsdp_request = {
@@ -11,6 +12,8 @@ volatile struct limine_rsdp_request rsdp_request = {
1112
1213extern volatile struct limine_smp_request smp_request ;
1314
15+ extern atomic_size_t aps_online ;
16+
1417static uint8_t lapic_ids [256 ] = {0 }; // CPU core Local APIC IDs
1518static uint8_t ioapic_ids [256 ] = {0 }; // CPU core Local APIC IDs
1619static uint16_t numcore = 0 ; // number of cores detected
@@ -128,7 +131,7 @@ ioapic_t get_ioapic(uint16_t index) {
128131 return ioapic ;
129132}
130133
131- void init_cores () {
134+ void init_acpi () {
132135 uint8_t * ptr , * ptr2 ;
133136 uint32_t len ;
134137 uint8_t * rsdt = (uint8_t * ) get_sdt_header ();
@@ -212,6 +215,13 @@ void init_cores() {
212215 (r -> detected_from == FROM_MADT ? "_MADT" : (r -> detected_from == FROM_PRT ? "_PRT" : "FALLBACK" )));
213216 }
214217 }
218+ for (int i = 0 ; i < 16 ; ++ i ) {
219+ dprintf ("IRQ %d maps to GSI %d\n" , i , irq_to_gsi (i ));
220+ }
221+ rr_flip ();
222+ }
223+
224+ void boot_aps () {
215225 if (numcore > 0 ) {
216226 kprintf ("SMP: %d cores, %d IOAPICs\n" , numcore , numioapic );
217227 if (!smp_request .response ) {
@@ -230,18 +240,18 @@ void init_cores() {
230240 set_lapic_id_for_cpu_id (cpu -> processor_id , cpu -> lapic_id );
231241 }
232242 if (cpu -> lapic_id == smp_request .response -> bsp_lapic_id || cpu -> processor_id > 254 ) {
243+ if (cpu -> lapic_id == smp_request .response -> bsp_lapic_id ) {
244+ kprintf ("CPU: %d online; ID: %d\n" , cpu -> processor_id , cpu -> lapic_id );
245+ }
233246 // Skip BSP and IDs over 254 (255 is broadcast, 256+ are too big for our array)
234247 continue ;
235- } else if (cpu -> lapic_id == smp_request .response -> bsp_lapic_id ) {
236- kprintf ("CPU: %d online; ID: %d\n" , cpu -> processor_id , cpu -> lapic_id );
237248 }
238249 cpu -> goto_address = kmain_ap ;
239250 }
251+ while (atomic_load (& aps_online ) < limit - 1 ) {
252+ _mm_pause ();
253+ }
240254 }
241- for (int i = 0 ; i < 16 ; ++ i ) {
242- dprintf ("IRQ %d maps to GSI %d\n" , i , irq_to_gsi (i ));
243- }
244- rr_flip ();
245255}
246256
247257uint32_t irq_to_gsi (uint8_t irq ) {
0 commit comments