feat: add acpi rsdp parsing and extend startup memory mapping

This commit is contained in:
Katharina 2026-07-01 23:05:01 +02:00
parent e028f9ba63
commit 6c5c1f5c60
5 changed files with 166 additions and 30 deletions

View file

@ -3,6 +3,7 @@
#include "init/init.h"
#include "init/multiboot2.h"
#include "init/print.h"
#include "init/acpi.h"
#include "memory/allocator.h"
[[maybe_unused]] [[noreturn]] __attribute__((used)) static void halt() {
@ -142,30 +143,55 @@ void PhysicalAllocator::init(const multiboot::tag_mmap* multiboot_info) {
PhysicalAllocator::getInstance() = alloc;
}
static void loadMultiboot() {
static void setupMemory() {
multiboot::visit_all(overloaded{
[](const multiboot::tag_mmap* mem) {
print("Tag Memory Map\n");
step("memory setup", [mem](){PhysicalAllocator::init(mem);});
PhysicalAllocator::init(mem);
},
[](const multiboot::tag_string* str) {
print("Tag String (");
print(multiboot::get_tag_name(str->type));
print("): ");
print(str->string);
print("\n");
[](const auto* tag) {}
});
}
static paddr_t rsdp_physical_of(const uint8_t* rsdp_payload) {
const multiboot::info* mb = multiboot::get_multiboot_info();
uint64_t info_phys = reinterpret_cast<uint64_t>(mb) - high_base;
uint64_t offset_in_info = reinterpret_cast<uint64_t>(rsdp_payload) - reinterpret_cast<uint64_t>(mb);
return paddr_t{info_phys + offset_in_info};
}
static acpi::Rsdp findRsdp() {
optional<paddr_t> rsdp{};
multiboot::visit_all(overloaded{
[&](const multiboot::tag_new_acpi* tag) {
rsdp = rsdp_physical_of(tag->rsdp);
},
[](const auto* tag) {
print("Tag ");
print(multiboot::get_tag_name(tag->type));
print("\n");
}
[&](const multiboot::tag_old_acpi* tag) {
if(!rsdp.has_value()) {
rsdp = rsdp_physical_of(tag->rsdp);
}
},
[&](const auto* tag) {}
});
if(!rsdp.has_value()) {
panic("System could not find ACPI RSDP!");
}
return acpi::Rsdp(*rsdp);
}
static void setupAcpi() {
auto rsdp = findRsdp();
rsdp.for_each_table([](paddr_t table) {
auto header = table.access<acpi::sdt_header_t>();
print(acpi::unfold_signature(header->signature).text);
print("\n");
});
}
[[maybe_unused]] [[noreturn]] __attribute__((used)) void init() {
initFromLow();
print("Reached init\n");
step("multiboot", loadMultiboot);
step("memory", setupMemory);
step("acpi", setupAcpi);
halt();
}

BIN
kernel/src/init/init.o Normal file

Binary file not shown.

View file

@ -225,13 +225,19 @@ __page_level_4:
.align 0x1000
__page_level_3_low_1gb_identity_map:
.quad (1 << 0) | (1 << 1) | (1 << 7) | 0x0
.zero 0xFF8 # rest of table is 0
.set gib_index, 0
.rept 512 # identity-map all 512 GiB the PDPT spans, one 1 GiB huge page each
.quad (1 << 0) | (1 << 1) | (1 << 7) | (gib_index << 30)
.set gib_index, gib_index + 1
.endr
.align 0x1000
__page_level_3_kernel_1gb_identity_map:
.quad (1 << 0) | (1 << 1) | (1 << 7) | 0x0
.zero 0xFF8 # rest of table is 0
.set gib_index, 0
.rept 512 # identity-map all 512 GiB the PDPT spans, one 1 GiB huge page each
.quad (1 << 0) | (1 << 1) | (1 << 7) | (gib_index << 30)
.set gib_index, gib_index + 1
.endr
)");
// startup gdt