diff --git a/kernel/include/kernel/Scheduler.h b/kernel/include/kernel/Scheduler.h index 06ea08039d..c2091d68e3 100644 --- a/kernel/include/kernel/Scheduler.h +++ b/kernel/include/kernel/Scheduler.h @@ -12,6 +12,7 @@ namespace Kernel public: static BAN::ErrorOr initialize(); static Scheduler& get(); + static bool is_started(); [[noreturn]] void start(); diff --git a/kernel/kernel/Scheduler.cpp b/kernel/kernel/Scheduler.cpp index 3a3ad914f5..c68428bb6a 100644 --- a/kernel/kernel/Scheduler.cpp +++ b/kernel/kernel/Scheduler.cpp @@ -15,6 +15,7 @@ namespace Kernel extern "C" [[noreturn]] void continue_thread(uintptr_t rsp, uintptr_t rip); static Scheduler* s_instance = nullptr; + static BAN::Atomic s_started { false }; ALWAYS_INLINE static void load_temp_stack() { @@ -40,12 +41,17 @@ namespace Kernel { ASSERT(Processor::get_interrupt_state() == InterruptState::Disabled); m_lock.lock(); - ASSERT(!m_active_threads.empty()); + s_started = true; advance_current_thread(); execute_current_thread_locked(); ASSERT_NOT_REACHED(); } + bool Scheduler::is_started() + { + return s_started; + } + Thread& Scheduler::current_thread() { auto* current = Processor::get_current_thread(); diff --git a/kernel/kernel/kernel.cpp b/kernel/kernel/kernel.cpp index 007b324686..238d1f8d91 100644 --- a/kernel/kernel/kernel.cpp +++ b/kernel/kernel/kernel.cpp @@ -217,6 +217,7 @@ extern "C" void ap_main() dprintln("ap{} initialized", Processor::current_id()); - for (;;) - asm volatile("hlt"); + while (!Scheduler::is_started()) + __builtin_ia32_pause(); + Scheduler::get().start(); }