diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2024-09-30 11:08:46 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2024-09-30 11:08:46 -0400 |
commit | 19d9a04e36e7fb96eebe89e24311408460c29a70 (patch) | |
tree | 4d5f5ba595d5a5e2b59ce7b102c06b77c7be7721 /src/boot.cpp | |
parent | 85c8fd05f1a0c0224882c4fafa60003d3ef56cf3 (diff) |
reorganize files
Diffstat (limited to 'src/boot.cpp')
-rw-r--r-- | src/boot.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/boot.cpp b/src/boot.cpp new file mode 100644 index 0000000..6b1da6a --- /dev/null +++ b/src/boot.cpp @@ -0,0 +1,36 @@ +#include <array> +#include <cstdint> +#include <span> + +extern void (*__init_array_start)(); +extern void (*__init_array_end)(); +extern void kernel_main(); + +alignas(16) +static std::array<std::uint8_t, 16384> stack; + +static void init_array() +{ + std::span initArray (&__init_array_start, &__init_array_end); + for (auto& fn : initArray) + fn(); +} + +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())); + + init_array(); + kernel_main(); + + asm volatile("cli"); + for (;;) + asm volatile("hlt"); +} + |