diff options
Diffstat (limited to 'Kernel/Arch')
-rw-r--r-- | Kernel/Arch/aarch64/Processor.cpp | 35 | ||||
-rw-r--r-- | Kernel/Arch/aarch64/Processor.h | 13 | ||||
-rw-r--r-- | Kernel/Arch/aarch64/init.cpp | 22 |
3 files changed, 56 insertions, 14 deletions
diff --git a/Kernel/Arch/aarch64/Processor.cpp b/Kernel/Arch/aarch64/Processor.cpp new file mode 100644 index 0000000000..1cc104dfbd --- /dev/null +++ b/Kernel/Arch/aarch64/Processor.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022, Timon Kruiper <timonkruiper@gmail.com> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <AK/Format.h> + +#include <Kernel/Arch/Processor.h> +#include <Kernel/Arch/aarch64/ASM_wrapper.h> +#include <Kernel/Arch/aarch64/Prekernel/Aarch64_asm_utils.h> +#include <Kernel/Arch/aarch64/Prekernel/Prekernel.h> + +extern "C" uintptr_t vector_table_el1; + +namespace Kernel { + +Processor* g_current_processor; + +void Processor::initialize(u32 cpu) +{ + VERIFY(g_current_processor == nullptr); + + auto current_exception_level = static_cast<u64>(Kernel::Aarch64::Asm::get_current_exception_level()); + dbgln("CPU{} started in: EL{}", cpu, current_exception_level); + + dbgln("Drop CPU{} to EL1", cpu); + Prekernel::drop_to_exception_level_1(); + + // Load EL1 vector table + el1_vector_table_install(&vector_table_el1); + + g_current_processor = this; +} +} diff --git a/Kernel/Arch/aarch64/Processor.h b/Kernel/Arch/aarch64/Processor.h index ed2e6bfdd8..17393471cf 100644 --- a/Kernel/Arch/aarch64/Processor.h +++ b/Kernel/Arch/aarch64/Processor.h @@ -22,6 +22,7 @@ class PageDirectory; }; class Thread; +class Processor; // FIXME This needs to go behind some sort of platform abstraction // it is used between Thread and Processor. @@ -30,8 +31,13 @@ struct [[gnu::aligned(16)]] FPUState u8 buffer[512]; }; +// FIXME: Remove this once we support SMP in aarch64 +extern Processor* g_current_processor; + class Processor { public: + void initialize(u32 cpu); + void set_specific(ProcessorSpecificDataID /*specific_id*/, void* /*ptr*/) { VERIFY_NOT_REACHED(); @@ -79,9 +85,9 @@ public: VERIFY_NOT_REACHED(); } + // FIXME: When aarch64 supports multiple cores, return the correct core id here. ALWAYS_INLINE static u32 current_id() { - VERIFY_NOT_REACHED(); return 0; } @@ -127,7 +133,10 @@ public: return nullptr; } - ALWAYS_INLINE static Processor& current() { VERIFY_NOT_REACHED(); } + ALWAYS_INLINE static Processor& current() + { + return *g_current_processor; + } static void deferred_call_queue(Function<void()> /* callback */) { diff --git a/Kernel/Arch/aarch64/init.cpp b/Kernel/Arch/aarch64/init.cpp index f4b717e009..da2222ffbb 100644 --- a/Kernel/Arch/aarch64/init.cpp +++ b/Kernel/Arch/aarch64/init.cpp @@ -10,9 +10,8 @@ #include <AK/Format.h> #include <AK/Types.h> -#include <Kernel/Arch/aarch64/ASM_wrapper.h> +#include <Kernel/Arch/Processor.h> #include <Kernel/Arch/aarch64/BootPPMParser.h> -#include <Kernel/Arch/aarch64/Prekernel/Aarch64_asm_utils.h> #include <Kernel/Arch/aarch64/Prekernel/Prekernel.h> #include <Kernel/Arch/aarch64/RPi/Framebuffer.h> #include <Kernel/Arch/aarch64/RPi/Mailbox.h> @@ -44,6 +43,12 @@ extern ctor_func_t end_heap_ctors[]; extern ctor_func_t start_ctors[]; extern ctor_func_t end_ctors[]; +ALWAYS_INLINE static Kernel::Processor& bootstrap_processor() +{ + alignas(Kernel::Processor) static u8 bootstrap_processor_storage[sizeof(Kernel::Processor)]; + return (Kernel::Processor&)bootstrap_processor_storage; +} + extern "C" [[noreturn]] void init() { dbgln("Welcome to Serenity OS!"); @@ -51,6 +56,9 @@ extern "C" [[noreturn]] void init() dbgln("Observed deviations from that ideal are shortcomings of your imagination."); dbgln(); + new (&bootstrap_processor()) Kernel::Processor(); + bootstrap_processor().initialize(0); + // We call the constructors of kmalloc.cpp separately, because other constructors in the Kernel // might rely on being able to call new/kmalloc in the constructor. We do have to run the // kmalloc constructors, because kmalloc_init relies on that. @@ -66,16 +74,6 @@ extern "C" [[noreturn]] void init() auto firmware_version = query_firmware_version(); dbgln("Firmware version: {}", firmware_version); - auto current_exception_level = static_cast<u64>(Kernel::Aarch64::Asm::get_current_exception_level()); - dbgln("CPU started in: EL{}", current_exception_level); - - dbgln("Drop CPU to EL1"); - Prekernel::drop_to_exception_level_1(); - - // Load EL1 vector table - extern uintptr_t vector_table_el1; - el1_vector_table_install(&vector_table_el1); - dbgln("Initialize MMU"); Prekernel::init_prekernel_page_tables(); |