You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.0 KiB
C++
93 lines
2.0 KiB
C++
4 weeks ago
|
#include "textoutput.hpp"
|
||
|
|
||
|
#include <cstdint>
|
||
|
|
||
|
extern TextOutput& term;
|
||
|
|
||
3 weeks ago
|
struct multiboot2_tag
|
||
|
{
|
||
|
alignas(8)
|
||
|
std::uint16_t id;
|
||
|
std::uint16_t flags;
|
||
|
std::uint32_t length;
|
||
|
std::uint32_t data[1];
|
||
|
} __attribute__((packed));
|
||
|
|
||
3 weeks ago
|
template<int N>
|
||
4 weeks ago
|
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)
|
||
3 weeks ago
|
std::uint32_t magic = MAGIC;
|
||
|
std::uint32_t flags = FLAGS;
|
||
|
std::uint32_t length = LENGTH;
|
||
|
std::uint32_t checksum = CHECKSUM;
|
||
4 weeks ago
|
|
||
3 weeks ago
|
multiboot2_tag tags[N];
|
||
3 weeks ago
|
} __attribute__((packed));
|
||
4 weeks ago
|
|
||
|
__attribute__((section(".multiboot2")))
|
||
3 weeks ago
|
multiboot2 multibootHeader = {
|
||
|
.tags = {
|
||
|
{
|
||
|
1, 0, sizeof(multiboot2_tag) + sizeof(std::uint32_t),
|
||
|
{4}
|
||
|
},
|
||
|
{
|
||
|
0, 0, 8, {}
|
||
|
}
|
||
|
}
|
||
4 weeks ago
|
};
|
||
|
|
||
4 weeks ago
|
std::uint32_t multiboot_magic;
|
||
|
std::uint32_t *multiboot_ptr;
|
||
|
|
||
|
std::uint32_t lowerMem = 0;
|
||
|
std::uint32_t upperMem = 0;
|
||
4 weeks ago
|
std::uint32_t *acpiRsdp = nullptr;
|
||
|
std::uint32_t *acpiRsdpV2 = nullptr;
|
||
4 weeks ago
|
|
||
|
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(", ");
|
||
|
|
||
4 weeks ago
|
switch (ptr[0]) {
|
||
|
case 4:
|
||
4 weeks ago
|
lowerMem = ptr[2] * 1024;
|
||
|
upperMem = ptr[3] * 1024;
|
||
4 weeks ago
|
break;
|
||
|
case 14:
|
||
|
acpiRsdp = ptr + 2;
|
||
|
break;
|
||
|
case 15:
|
||
|
acpiRsdpV2 = ptr + 2;
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
4 weeks ago
|
}
|
||
|
|
||
|
auto next = reinterpret_cast<std::uintptr_t>(ptr);
|
||
|
next += ptr[1];
|
||
|
next = (next + 7) & ~7;
|
||
|
ptr = reinterpret_cast<std::uint32_t *>(next);
|
||
|
}
|
||
|
|
||
|
term.write('\n');
|
||
|
return true;
|
||
|
}
|
||
|
|