Kernel: Put code in the aarch64 init.cpp file into the Kernel namespace

This commit is contained in:
Timon Kruiper 2022-05-12 23:00:39 +02:00 committed by Linus Groh
parent 9282e0db16
commit 18cad73b01
Notes: sideshowbarker 2024-07-17 10:55:48 +09:00

View File

@ -20,9 +20,6 @@
#include <Kernel/KSyms.h>
#include <Kernel/Panic.h>
static void draw_logo();
static u32 query_firmware_version();
struct TrapFrame {
u64 x[31]; // Saved general purpose registers
u64 spsr_el1; // Save Processor Status Register, EL1
@ -31,78 +28,7 @@ struct TrapFrame {
u64 sp_el0; // EL0 stack pointer
};
extern "C" [[noreturn]] void halt();
extern "C" [[noreturn]] void init();
extern "C" void exception_common(TrapFrame const* const trap_frame);
typedef void (*ctor_func_t)();
extern ctor_func_t start_heap_ctors[];
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!");
dbgln("Imagine this being your ideal operating system.");
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.
for (ctor_func_t* ctor = start_heap_ctors; ctor < end_heap_ctors; ctor++)
(*ctor)();
kmalloc_init();
for (ctor_func_t* ctor = start_ctors; ctor < end_ctors; ctor++)
(*ctor)();
Kernel::load_kernel_symbol_table();
auto firmware_version = query_firmware_version();
dbgln("Firmware version: {}", firmware_version);
dbgln("Initialize MMU");
Kernel::init_prekernel_page_tables();
auto& framebuffer = Kernel::Framebuffer::the();
if (framebuffer.initialized()) {
draw_logo();
}
dbgln("Enter loop");
auto& timer = Kernel::Timer::the();
u64 start_musec = 0;
for (;;) {
u64 now_musec;
while ((now_musec = timer.microseconds_since_boot()) - start_musec < 1'000'000)
;
start_musec = now_musec;
dbgln("Timer: {}", now_musec);
}
}
// FIXME: Share this with the Intel Prekernel.
extern size_t __stack_chk_guard;
size_t __stack_chk_guard;
extern "C" [[noreturn]] void __stack_chk_fail();
void __stack_chk_fail()
{
Kernel::Processor::halt();
}
extern "C" void exception_common(TrapFrame const* const trap_frame)
{
constexpr bool print_stack_frame = true;
@ -122,12 +48,88 @@ extern "C" void exception_common(TrapFrame const* const trap_frame)
}
}
class QueryFirmwareVersionMboxMessage : Kernel::Mailbox::Message {
typedef void (*ctor_func_t)();
extern ctor_func_t start_heap_ctors[];
extern ctor_func_t end_heap_ctors[];
extern ctor_func_t start_ctors[];
extern ctor_func_t end_ctors[];
// FIXME: Share this with the Intel Prekernel.
extern size_t __stack_chk_guard;
size_t __stack_chk_guard;
extern "C" [[noreturn]] void __stack_chk_fail();
void __stack_chk_fail()
{
Kernel::Processor::halt();
}
namespace Kernel {
static void draw_logo();
static u32 query_firmware_version();
extern "C" [[noreturn]] void halt();
extern "C" [[noreturn]] void init();
ALWAYS_INLINE static Processor& bootstrap_processor()
{
alignas(Processor) static u8 bootstrap_processor_storage[sizeof(Processor)];
return (Processor&)bootstrap_processor_storage;
}
extern "C" [[noreturn]] void init()
{
dbgln("Welcome to Serenity OS!");
dbgln("Imagine this being your ideal operating system.");
dbgln("Observed deviations from that ideal are shortcomings of your imagination.");
dbgln();
new (&bootstrap_processor()) 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.
for (ctor_func_t* ctor = start_heap_ctors; ctor < end_heap_ctors; ctor++)
(*ctor)();
kmalloc_init();
for (ctor_func_t* ctor = start_ctors; ctor < end_ctors; ctor++)
(*ctor)();
load_kernel_symbol_table();
auto firmware_version = query_firmware_version();
dbgln("Firmware version: {}", firmware_version);
dbgln("Initialize MMU");
init_prekernel_page_tables();
auto& framebuffer = Framebuffer::the();
if (framebuffer.initialized()) {
draw_logo();
}
dbgln("Enter loop");
auto& timer = Timer::the();
u64 start_musec = 0;
for (;;) {
u64 now_musec;
while ((now_musec = timer.microseconds_since_boot()) - start_musec < 1'000'000)
;
start_musec = now_musec;
dbgln("Timer: {}", now_musec);
}
}
class QueryFirmwareVersionMboxMessage : Mailbox::Message {
public:
u32 version;
QueryFirmwareVersionMboxMessage()
: Kernel::Mailbox::Message(0x0000'0001, 4)
: Mailbox::Message(0x0000'0001, 4)
{
version = 0;
}
@ -136,12 +138,12 @@ public:
static u32 query_firmware_version()
{
struct __attribute__((aligned(16))) {
Kernel::Mailbox::MessageHeader header;
Mailbox::MessageHeader header;
QueryFirmwareVersionMboxMessage query_firmware_version;
Kernel::Mailbox::MessageTail tail;
Mailbox::MessageTail tail;
} message_queue;
if (!Kernel::Mailbox::the().send_queue(&message_queue, sizeof(message_queue))) {
if (!Mailbox::the().send_queue(&message_queue, sizeof(message_queue))) {
return 0xffff'ffff;
}
@ -153,7 +155,7 @@ extern "C" const u32 serenity_boot_logo_size;
static void draw_logo()
{
Kernel::BootPPMParser logo_parser(reinterpret_cast<u8 const*>(&serenity_boot_logo_start), serenity_boot_logo_size);
BootPPMParser logo_parser(reinterpret_cast<u8 const*>(&serenity_boot_logo_start), serenity_boot_logo_size);
if (!logo_parser.parse()) {
dbgln("Failed to parse boot logo.");
return;
@ -161,7 +163,7 @@ static void draw_logo()
dbgln("Boot logo size: {} ({} x {})", serenity_boot_logo_size, logo_parser.image.width, logo_parser.image.height);
auto& framebuffer = Kernel::Framebuffer::the();
auto& framebuffer = Framebuffer::the();
auto fb_ptr = framebuffer.gpu_buffer();
auto image_left = (framebuffer.width() - logo_parser.image.width) / 2;
auto image_right = image_left + logo_parser.image.width;
@ -173,12 +175,12 @@ static void draw_logo()
for (u32 x = 0; x < framebuffer.width(); x++) {
if (x >= image_left && x < image_right && y >= image_top && y < image_bottom) {
switch (framebuffer.pixel_order()) {
case Kernel::Framebuffer::PixelOrder::RGB:
case Framebuffer::PixelOrder::RGB:
fb_ptr[0] = logo_pixels[0];
fb_ptr[1] = logo_pixels[1];
fb_ptr[2] = logo_pixels[2];
break;
case Kernel::Framebuffer::PixelOrder::BGR:
case Framebuffer::PixelOrder::BGR:
fb_ptr[0] = logo_pixels[2];
fb_ptr[1] = logo_pixels[1];
fb_ptr[2] = logo_pixels[0];
@ -201,3 +203,5 @@ static void draw_logo()
fb_ptr += framebuffer.pitch() - framebuffer.width() * 4;
}
}
}