Kernel: Don't use multiboot2 explicitly. Parse it to common structure

This allows support of multiple different bootloaders
This commit is contained in:
2023-11-17 18:54:59 +02:00
parent 641a2dec00
commit 84040e64b8
10 changed files with 226 additions and 97 deletions

View File

@@ -0,0 +1,47 @@
#pragma once
#include <BAN/String.h>
#include <BAN/StringView.h>
#include <BAN/Vector.h>
namespace Kernel
{
enum class FramebufferType
{
NONE,
UNKNOWN,
RGB
};
struct FramebufferInfo
{
paddr_t address;
uint32_t pitch;
uint32_t width;
uint32_t height;
uint8_t bpp;
FramebufferType type = FramebufferType::NONE;
};
struct MemoryMapEntry
{
uint32_t type;
paddr_t address;
uint64_t length;
};
struct BootInfo
{
BAN::String command_line;
FramebufferInfo framebuffer;
BAN::Vector<MemoryMapEntry> memory_map_entries;
};
bool validate_boot_magic(uint32_t magic);
void parse_boot_info(uint32_t magic, uint32_t info);
BAN::StringView get_early_boot_command_line(uint32_t magic, uint32_t info);
extern BootInfo g_boot_info;
}

View File

@@ -13,11 +13,18 @@
#define MULTIBOOT2_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT2_MAGIC 0x36d76289
struct multiboot2_tag_t
{
uint32_t type;
uint32_t size;
multiboot2_tag_t* next() { return (multiboot2_tag_t*)((uintptr_t)this + ((size + 7) & ~7)); }
const multiboot2_tag_t* next() const
{
return reinterpret_cast<const multiboot2_tag_t*>(
reinterpret_cast<uintptr_t>(this) + ((size + 7) & ~7)
);
}
} __attribute__((packed));
struct multiboot2_cmdline_tag_t : public multiboot2_tag_t
@@ -62,14 +69,3 @@ struct multiboot2_info_t
uint32_t reserved;
multiboot2_tag_t tags[];
} __attribute__((packed));
extern "C" multiboot2_info_t* g_multiboot2_info;
extern "C" uint32_t g_multiboot2_magic;
inline multiboot2_tag_t* multiboot2_find_tag(uint32_t type)
{
for (auto* tag = g_multiboot2_info->tags; tag->type != MULTIBOOT2_TAG_END; tag = tag->next())
if (tag->type == type)
return tag;
return nullptr;
}