aboutsummaryrefslogtreecommitdiffstats
path: root/boot.cpp
blob: 1c46b63ac3c3cd0522a9d8caaa818cb0210a4ba5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <array>
#include <cstdint>

extern void kernel_main();

alignas(16)
std::array<std::uint8_t, 16384> stack;

extern "C"
__attribute__((naked))
void _start()
{
    asm volatile(R"(
        mov %%eax, multiboot_magic
        mov %%ebx, multiboot_ptr
        mov %0, %%esp
    )" :: "i" (stack.data() + stack.size()));

    extern std::uint32_t __init_array_start;
    extern std::uint32_t __init_array_end;

    auto it = &__init_array_start;
    while (it < &__init_array_end) {
        auto fn = reinterpret_cast<void (*)()>(*it);
        fn();
        ++it;
    }

    kernel_main();

    asm volatile("cli");
    for (;;)
        asm volatile("hlt");
}