Kernel: Parse RSDP from multiboot headers if exists

This commit is contained in:
Bananymous 2024-01-26 00:49:42 +02:00
parent 0408aa9bbc
commit 6bfe833aa5
4 changed files with 51 additions and 33 deletions

View File

@ -3,6 +3,7 @@
#include <BAN/String.h> #include <BAN/String.h>
#include <BAN/StringView.h> #include <BAN/StringView.h>
#include <BAN/Vector.h> #include <BAN/Vector.h>
#include <kernel/RSDP.h>
namespace Kernel namespace Kernel
{ {
@ -34,7 +35,8 @@ namespace Kernel
struct BootInfo struct BootInfo
{ {
BAN::String command_line; BAN::String command_line;
FramebufferInfo framebuffer; FramebufferInfo framebuffer {};
RSDP rsdp {};
BAN::Vector<MemoryMapEntry> memory_map_entries; BAN::Vector<MemoryMapEntry> memory_map_entries;
}; };

View File

@ -0,0 +1,23 @@
#pragma once
#include <stdint.h>
namespace Kernel
{
struct RSDP
{
uint8_t signature[8];
uint8_t checksum;
uint8_t oemid[6];
uint8_t revision;
uint32_t rsdt_address;
// only in revision >= 2
uint32_t length;
uint64_t xsdt_address;
uint8_t extended_checksum;
uint8_t reserved[3];
};
}

View File

@ -1,6 +1,7 @@
#include <BAN/ScopeGuard.h> #include <BAN/ScopeGuard.h>
#include <BAN/StringView.h> #include <BAN/StringView.h>
#include <kernel/ACPI.h> #include <kernel/ACPI.h>
#include <kernel/BootInfo.h>
#include <kernel/Memory/PageTable.h> #include <kernel/Memory/PageTable.h>
#include <lai/core.h> #include <lai/core.h>
@ -11,21 +12,6 @@
namespace Kernel namespace Kernel
{ {
struct RSDP
{
uint8_t signature[8];
uint8_t checksum;
uint8_t oemid[6];
uint8_t revision;
uint32_t rsdt_address;
// only in revision >= 2
uint32_t length;
uint64_t xsdt_address;
uint8_t extended_checksum;
uint8_t reserved[3];
};
struct RSDT : public ACPI::SDTHeader struct RSDT : public ACPI::SDTHeader
{ {
uint32_t entries[]; uint32_t entries[];
@ -84,19 +70,13 @@ namespace Kernel
static const RSDP* locate_rsdp() static const RSDP* locate_rsdp()
{ {
// FIXME: add this back if (g_boot_info.rsdp.length)
#if 0 return &g_boot_info.rsdp;
// Check the multiboot headers
if (auto* rsdp_new = (multiboot2_rsdp_tag_t*)multiboot2_find_tag(MULTIBOOT2_TAG_NEW_RSDP))
return (const RSDP*)rsdp_new->data;
if (auto* rsdp_old = (multiboot2_rsdp_tag_t*)multiboot2_find_tag(MULTIBOOT2_TAG_OLD_RSDP))
return (const RSDP*)rsdp_old->data;
#endif
// Look in main BIOS area below 1 MB // Look in main BIOS area below 1 MB
for (uintptr_t addr = P2V(0x000E0000); addr < P2V(0x000FFFFF); addr += 16) for (uintptr_t addr = P2V(0x000E0000); addr < P2V(0x000FFFFF); addr += 16)
if (is_rsdp(addr)) if (is_rsdp(addr))
return (const RSDP*)addr; return reinterpret_cast<const RSDP*>(addr);
return nullptr; return nullptr;
} }

View File

@ -7,7 +7,7 @@ namespace Kernel
BootInfo g_boot_info; BootInfo g_boot_info;
void parse_boot_info_multiboot2(uint32_t info) static void parse_boot_info_multiboot2(uint32_t info)
{ {
const auto& multiboot2_info = *reinterpret_cast<const multiboot2_info_t*>(info); const auto& multiboot2_info = *reinterpret_cast<const multiboot2_info_t*>(info);
@ -15,12 +15,12 @@ namespace Kernel
{ {
if (tag->type == MULTIBOOT2_TAG_CMDLINE) if (tag->type == MULTIBOOT2_TAG_CMDLINE)
{ {
const auto& command_line_tag = *reinterpret_cast<const multiboot2_cmdline_tag_t*>(tag); const auto& command_line_tag = *static_cast<const multiboot2_cmdline_tag_t*>(tag);
MUST(g_boot_info.command_line.append(command_line_tag.cmdline)); MUST(g_boot_info.command_line.append(command_line_tag.cmdline));
} }
else if (tag->type == MULTIBOOT2_TAG_FRAMEBUFFER) else if (tag->type == MULTIBOOT2_TAG_FRAMEBUFFER)
{ {
const auto& framebuffer_tag = *reinterpret_cast<const multiboot2_framebuffer_tag_t*>(tag); const auto& framebuffer_tag = *static_cast<const multiboot2_framebuffer_tag_t*>(tag);
g_boot_info.framebuffer.address = framebuffer_tag.framebuffer_addr; g_boot_info.framebuffer.address = framebuffer_tag.framebuffer_addr;
g_boot_info.framebuffer.pitch = framebuffer_tag.framebuffer_pitch; g_boot_info.framebuffer.pitch = framebuffer_tag.framebuffer_pitch;
g_boot_info.framebuffer.width = framebuffer_tag.framebuffer_width; g_boot_info.framebuffer.width = framebuffer_tag.framebuffer_width;
@ -33,7 +33,7 @@ namespace Kernel
} }
else if (tag->type == MULTIBOOT2_TAG_MMAP) else if (tag->type == MULTIBOOT2_TAG_MMAP)
{ {
const auto& mmap_tag = *reinterpret_cast<const multiboot2_mmap_tag_t*>(tag); const auto& mmap_tag = *static_cast<const multiboot2_mmap_tag_t*>(tag);
const size_t entry_count = (mmap_tag.size - sizeof(multiboot2_mmap_tag_t)) / mmap_tag.entry_size; const size_t entry_count = (mmap_tag.size - sizeof(multiboot2_mmap_tag_t)) / mmap_tag.entry_size;
@ -52,19 +52,32 @@ namespace Kernel
g_boot_info.memory_map_entries[i].type = mmap_entry.type; g_boot_info.memory_map_entries[i].type = mmap_entry.type;
} }
} }
else if (tag->type == MULTIBOOT2_TAG_OLD_RSDP)
{
if (g_boot_info.rsdp.length == 0)
{
memcpy(&g_boot_info.rsdp, static_cast<const multiboot2_rsdp_tag_t*>(tag)->data, 20);
g_boot_info.rsdp.length = 20;
}
}
else if (tag->type == MULTIBOOT2_TAG_NEW_RSDP)
{
const auto& rsdp = *reinterpret_cast<const RSDP*>(static_cast<const multiboot2_rsdp_tag_t*>(tag)->data);
memcpy(&g_boot_info.rsdp, &rsdp, BAN::Math::min<uint32_t>(rsdp.length, sizeof(g_boot_info.rsdp)));
}
} }
} }
BAN::StringView get_early_boot_command_line_multiboot2(uint32_t info) static BAN::StringView get_early_boot_command_line_multiboot2(uint32_t info)
{ {
const auto& multiboot2_info = *reinterpret_cast<const multiboot2_info_t*>(info); const auto& multiboot2_info = *reinterpret_cast<const multiboot2_info_t*>(info);
for (const auto* tag = multiboot2_info.tags; tag->type != MULTIBOOT2_TAG_END; tag = tag->next()) for (const auto* tag = multiboot2_info.tags; tag->type != MULTIBOOT2_TAG_END; tag = tag->next())
if (tag->type == MULTIBOOT2_TAG_CMDLINE) if (tag->type == MULTIBOOT2_TAG_CMDLINE)
return reinterpret_cast<const multiboot2_cmdline_tag_t*>(tag)->cmdline; return static_cast<const multiboot2_cmdline_tag_t*>(tag)->cmdline;
return {}; return {};
} }
void parse_boot_info_banan_bootloader(uint32_t info) static void parse_boot_info_banan_bootloader(uint32_t info)
{ {
const auto& banan_bootloader_info = *reinterpret_cast<const BananBootloaderInfo*>(info); const auto& banan_bootloader_info = *reinterpret_cast<const BananBootloaderInfo*>(info);
@ -93,7 +106,7 @@ namespace Kernel
} }
} }
BAN::StringView get_early_boot_command_line_banan_bootloader(uint32_t info) static BAN::StringView get_early_boot_command_line_banan_bootloader(uint32_t info)
{ {
const auto& banan_bootloader_info = *reinterpret_cast<const BananBootloaderInfo*>(info); const auto& banan_bootloader_info = *reinterpret_cast<const BananBootloaderInfo*>(info);
return reinterpret_cast<const char*>(banan_bootloader_info.command_line_addr); return reinterpret_cast<const char*>(banan_bootloader_info.command_line_addr);