#include "textoutput.hpp" #include extern TextOutput& term; struct multiboot2_tag { alignas(8) std::uint16_t id; std::uint16_t flags; std::uint32_t length; std::uint32_t data[1]; } __attribute__((packed)); struct multiboot2 { static constexpr std::uint32_t MAGIC = 0xE85250D6; static constexpr std::uint32_t FLAGS = 0; static constexpr std::uint32_t LENGTH = 16; static constexpr std::uint32_t CHECKSUM = -(MAGIC + FLAGS + LENGTH); alignas(8) std::uint32_t magic; std::uint32_t flags; std::uint32_t length; std::uint32_t checksum; multiboot2_tag tags[]; } __attribute__((packed)); __attribute__((section(".multiboot2"))) multiboot2 multibootHeader = { .magic = multiboot2::MAGIC, .flags = multiboot2::FLAGS, .length = multiboot2::LENGTH, .checksum = multiboot2::CHECKSUM, .tags = { { 1, 0, sizeof(multiboot2_tag) + sizeof(std::uint32_t), {4} }, { 0, 0, 8, {} } } }; std::uint32_t multiboot_magic; std::uint32_t *multiboot_ptr; std::uint32_t lowerMem = 0; std::uint32_t upperMem = 0; std::uint32_t *acpiRsdp = nullptr; std::uint32_t *acpiRsdpV2 = nullptr; bool multiboot_initialize() { if (multiboot_magic != 0x36d76289) { term.write("Not multiboot!"); return false; } term.write("Found multiboot headers: "); auto ptr = multiboot_ptr + 2; while (ptr[0] != 0 && ptr[1] != 8) { term.write(ptr[0]); term.write(", "); switch (ptr[0]) { case 4: lowerMem = ptr[2] * 1024; upperMem = ptr[3] * 1024; break; case 14: acpiRsdp = ptr + 2; break; case 15: acpiRsdpV2 = ptr + 2; break; default: break; } auto next = reinterpret_cast(ptr); next += ptr[1]; next = (next + 7) & ~7; ptr = reinterpret_cast(next); } term.write('\n'); return true; }