diff --git a/init/main.c b/init/main.c index 57fa730..e3f7ecb 100644 --- a/init/main.c +++ b/init/main.c @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include @@ -185,8 +185,11 @@ void kmain() _pic_init(); apic_init(); + sem_t *init_sem = sem_create(0); + for (unsigned i = 0; i < smp_resp->cpu_count; i++) { struct limine_smp_info *info = smp_resp->cpus[i]; + info->extra_argument = (uint64_t)init_sem; if (info->lapic_id == smp_resp->bsp_lapic_id) continue; @@ -195,8 +198,10 @@ void kmain() } /* wait for the application processors to finish their initialization */ - for (unsigned i = 0; i < 100000; i++) - ; + for (unsigned i = 0; i < smp_resp->cpu_count - 1; i++) { + while (sem_trywait(init_sem)) + (void)0; + } console_init(); @@ -231,5 +236,8 @@ void ap_kmain(struct limine_smp_info *info) uint16_t tss = gdt_insert_tss(ptr); ltr(tss); + sem_t *init_sem = (sem_t *)info->extra_argument; + sem_post(init_sem); + load_stack_and_park(ptr, ptr); }