feat: introduce bootloader-agnostic Boot Contract, add btlist command to list connected Bluetooth devices
This commit is contained in:
+31
-30
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <limine.h>
|
||||
#include <Boot/Boot.hpp>
|
||||
#include <Hal/GDT.hpp>
|
||||
#include <Terminal/Terminal.hpp>
|
||||
#include <Efi/UEFI.hpp>
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <Memory/Memmap.hpp>
|
||||
#include <Memory/Heap.hpp>
|
||||
#include <Memory/HHDM.hpp>
|
||||
#include <Platform/Limine.hpp>
|
||||
#include <Platform/Util.hpp>
|
||||
#include <Hal/IDT.hpp>
|
||||
#include <Memory/PageFrameAllocator.hpp>
|
||||
@@ -58,33 +57,33 @@ extern "C" uint64_t KernelStartSymbol;
|
||||
extern "C" uint64_t KernelEndSymbol;
|
||||
|
||||
extern "C" void kmain() {
|
||||
if (LIMINE_BASE_REVISION_SUPPORTED == false) {
|
||||
Hal::Halt();
|
||||
}
|
||||
|
||||
// Call global constructors.
|
||||
for (std::size_t i = 0; &__init_array[i] != __init_array_end; i++) {
|
||||
__init_array[i]();
|
||||
}
|
||||
|
||||
if (framebuffer_request.response == nullptr
|
||||
|| framebuffer_request.response->framebuffer_count < 1) {
|
||||
// Acquire the boot environment through the Montauk Boot Contract. The
|
||||
// active bootloader adapter (see Boot/Protocols/) translates its native
|
||||
// handoff into this bootloader-agnostic structure. A false return means
|
||||
// we cannot even bring up a console (unsupported loader, no HHDM, or no
|
||||
// framebuffer) -- there is nothing to do but halt.
|
||||
if (!montauk::boot::Initialize()) {
|
||||
Hal::Halt();
|
||||
}
|
||||
|
||||
limine_framebuffer *framebuffer{framebuffer_request.response->framebuffers[0]};
|
||||
const montauk::boot::BootInfo& boot = montauk::boot::Info();
|
||||
const montauk::boot::Framebuffer& framebuffer = boot.framebuffer;
|
||||
|
||||
Kt::Initialize(
|
||||
(uint32_t*)framebuffer->address,
|
||||
framebuffer->width,
|
||||
framebuffer->height,
|
||||
framebuffer->pitch,
|
||||
framebuffer->red_mask_size,
|
||||
framebuffer->red_mask_shift,
|
||||
framebuffer->green_mask_size,
|
||||
framebuffer->green_mask_shift,
|
||||
framebuffer->blue_mask_size,
|
||||
framebuffer->blue_mask_shift
|
||||
(uint32_t*)framebuffer.address,
|
||||
framebuffer.width,
|
||||
framebuffer.height,
|
||||
framebuffer.pitch,
|
||||
framebuffer.redMaskSize,
|
||||
framebuffer.redMaskShift,
|
||||
framebuffer.greenMaskSize,
|
||||
framebuffer.greenMaskShift,
|
||||
framebuffer.blueMaskSize,
|
||||
framebuffer.blueMaskShift
|
||||
);
|
||||
|
||||
|
||||
@@ -95,15 +94,14 @@ extern "C" void kmain() {
|
||||
Hal::EnableSSE();
|
||||
#endif
|
||||
|
||||
uint64_t hhdm_offset = hhdm_request.response->offset;
|
||||
Memory::HHDMBase = hhdm_offset;
|
||||
Memory::HHDMBase = boot.hhdmBase;
|
||||
|
||||
if (memmap_request.response == nullptr) {
|
||||
if (boot.memoryMap.regions == nullptr || boot.memoryMap.count == 0) {
|
||||
Panic("System memory map missing!", nullptr);
|
||||
}
|
||||
|
||||
Kt::KernelLogStream(OK, "Mem") << "Creating PageFrameAllocator";
|
||||
Memory::PageFrameAllocator pmm(Memory::Scan(memmap_request.response));
|
||||
Memory::PageFrameAllocator pmm(Memory::Scan(boot.memoryMap));
|
||||
Memory::g_pfa = &pmm;
|
||||
|
||||
Kt::KernelLogStream(OK, "Mem") << "Creating HeapAllocator";
|
||||
@@ -118,7 +116,7 @@ extern "C" void kmain() {
|
||||
|
||||
Memory::VMM::Paging g_paging{};
|
||||
Memory::VMM::g_paging = &g_paging;
|
||||
g_paging.Init((uint64_t)&KernelStartSymbol, ((uint64_t)&KernelEndSymbol - (uint64_t)&KernelStartSymbol), memmap_request.response);
|
||||
g_paging.Init((uint64_t)&KernelStartSymbol, ((uint64_t)&KernelEndSymbol - (uint64_t)&KernelStartSymbol), boot.memoryMap, framebuffer);
|
||||
|
||||
// Reprogram PAT so entry 1 = Write-Combining (default is Write-Through).
|
||||
// Must be done after paging init and before any WC mappings.
|
||||
@@ -137,7 +135,7 @@ extern "C" void kmain() {
|
||||
Graphics::Cursor::MapWriteCombining();
|
||||
#endif
|
||||
|
||||
Hal::ACPI g_acpi((Hal::ACPI::XSDP*)Memory::HHDM(rsdp_request.response->address));
|
||||
Hal::ACPI g_acpi((Hal::ACPI::XSDP*)Memory::HHDM(boot.rsdpPhysical));
|
||||
|
||||
#if defined (__x86_64__)
|
||||
if (g_acpi.GetXSDT() != nullptr) {
|
||||
@@ -174,10 +172,13 @@ extern "C" void kmain() {
|
||||
}
|
||||
#endif
|
||||
|
||||
Efi::SystemTable* ST = (Efi::SystemTable*)Memory::HHDM(system_table_request.response->address);
|
||||
Efi::Init(ST, efi_memmap_request.response);
|
||||
// UEFI runtime services are optional (absent on legacy-BIOS boots).
|
||||
if (boot.has(montauk::boot::FeatureEfiSystemTable)) {
|
||||
Efi::SystemTable* ST = (Efi::SystemTable*)Memory::HHDM(boot.efi.systemTablePhysical);
|
||||
Efi::Init(ST, boot.efi);
|
||||
}
|
||||
|
||||
Fs::InitializeBootFilesystems(module_request.response);
|
||||
Fs::InitializeBootFilesystems(boot.modules);
|
||||
|
||||
// A Bluetooth adapter present at boot enumerates during the xHCI port scan,
|
||||
// before the ramdisk is mounted. Now that drive 0 is up, finish any
|
||||
@@ -191,7 +192,7 @@ extern "C" void kmain() {
|
||||
Ipc::Initialize();
|
||||
|
||||
// Boot Application Processors (all subsystems ready, APs can schedule)
|
||||
Smp::BootAPs();
|
||||
Smp::BootAPs(boot.smp);
|
||||
|
||||
// Flush any stale PS/2 mouse bytes that accumulated during boot
|
||||
// (edge-triggered IRQs can be lost while spinlocks disable interrupts)
|
||||
|
||||
Reference in New Issue
Block a user