diff options
author | Tom <tomut@yahoo.com> | 2020-07-02 08:34:00 -0600 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-03 19:32:34 +0200 |
commit | 57b61b2dde7f07f830679983c3dac94b71d2a1f8 (patch) | |
tree | 7497ffeb004323c7ab66e845168f8675620e3f9f | |
parent | 137e1dc7bd93d23af53dafa44a7ab95746a03cef (diff) | |
download | serenity-57b61b2dde7f07f830679983c3dac94b71d2a1f8.zip |
Kernel: Split initialization of Processor structure
We need to very early on initialize the Processor structure so
that we can use RecursiveSpinLock early on.
-rw-r--r-- | Kernel/Arch/i386/CPU.cpp | 20 | ||||
-rw-r--r-- | Kernel/Arch/i386/CPU.h | 1 | ||||
-rw-r--r-- | Kernel/init.cpp | 11 |
3 files changed, 25 insertions, 7 deletions
diff --git a/Kernel/Arch/i386/CPU.cpp b/Kernel/Arch/i386/CPU.cpp index 325a824270..8a65051fbe 100644 --- a/Kernel/Arch/i386/CPU.cpp +++ b/Kernel/Arch/i386/CPU.cpp @@ -822,7 +822,7 @@ Processor& Processor::by_id(u32 cpu) return *procs[cpu]; } -void Processor::initialize(u32 cpu) +void Processor::early_initialize(u32 cpu) { m_self = this; @@ -832,15 +832,29 @@ void Processor::initialize(u32 cpu) m_idle_thread = nullptr; m_current_thread = nullptr; m_mm_data = nullptr; + m_info = nullptr; gdt_init(); + ASSERT(¤t() == this); // sanity check +} + +void Processor::initialize(u32 cpu) +{ + ASSERT(m_self == this); + ASSERT(¤t() == this); // sanity check + + m_cpu = cpu; + m_in_irq = 0; + + m_idle_thread = nullptr; + m_current_thread = nullptr; + m_mm_data = nullptr; + if (cpu == 0) idt_init(); else flush_idt(); - ASSERT(¤t() == this); // sanity check - if (cpu == 0) { ASSERT((FlatPtr(&s_clean_fpu_state) & 0xF) == 0); asm volatile("fninit"); diff --git a/Kernel/Arch/i386/CPU.h b/Kernel/Arch/i386/CPU.h index 0e2df7c357..6f6f7def92 100644 --- a/Kernel/Arch/i386/CPU.h +++ b/Kernel/Arch/i386/CPU.h @@ -639,6 +639,7 @@ class Processor { static Vector<Processor*>& processors(); public: + void early_initialize(u32 cpu); void initialize(u32 cpu); Descriptor& get_gdt_entry(u16 selector); diff --git a/Kernel/init.cpp b/Kernel/init.cpp index c38337b709..4912c11b02 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -89,6 +89,8 @@ static void setup_serial_debug(); VirtualConsole* tty0; +static Processor s_bsp_processor; // global but let's keep it "private" + // SerenityOS Kernel C++ entry point :^) // // This is where C++ execution begins, after boot.S transfers control here. @@ -103,15 +105,13 @@ extern "C" [[noreturn]] void init() { setup_serial_debug(); + s_bsp_processor.early_initialize(0); cpu_setup(0); kmalloc_init(); slab_alloc_init(); - { - static Processor s_bsp_processor_info; // global but let's keep it "private" - s_bsp_processor_info.initialize(0); - } + s_bsp_processor.initialize(0); CommandLine::initialize(reinterpret_cast<const char*>(low_physical_to_virtual(multiboot_info_ptr->cmdline))); MemoryManager::initialize(0); @@ -165,7 +165,10 @@ extern "C" [[noreturn]] void init() // extern "C" [[noreturn]] void init_ap(u32 cpu, Processor* processor_info) { + processor_info->early_initialize(cpu); + klog() << "CPU #" << cpu << " processor_info at " << VirtualAddress(FlatPtr(processor_info)); + cpu_setup(cpu); processor_info->initialize(cpu); MemoryManager::initialize(cpu); |