Kernel: Add initial implementation of Processor in aarch64

Instead of storing the current Processor into a core local register, we
currently just store it into a global, since we don't support SMP for
aarch64 anyway. This simplifies the initial implementation.
This commit is contained in:
Timon Kruiper 2022-05-09 12:14:20 +02:00 committed by Linus Groh
parent ed4bfaed12
commit c515e1341a
Notes: sideshowbarker 2024-07-17 11:07:22 +09:00
4 changed files with 57 additions and 14 deletions

View file

@ -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;
}
}

View file

@ -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 */)
{

View file

@ -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();

View file

@ -426,6 +426,7 @@ else()
Arch/aarch64/MainIdRegister.cpp
Arch/aarch64/PageDirectory.cpp
Arch/aarch64/Panic.cpp
Arch/aarch64/Processor.cpp
Arch/aarch64/SafeMem.cpp
Arch/aarch64/ScopedCritical.cpp
Arch/aarch64/SmapDisabler.cpp