feat: make kernel architecture-agnostic; primitive work on arm port
This commit is contained in:
1 parent
dab7d5427b
commit
1bae77ec84
164 files changed
+3664
-1641
No files matched your search
+17
-67
@@ -10,40 +10,31 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <Boot/Boot.hpp>
|
||||
#include <Hal/GDT.hpp>
|
||||
#include <Terminal/Terminal.hpp>
|
||||
#include <Efi/UEFI.hpp>
|
||||
#include <Common/Panic.hpp>
|
||||
#include <Memory/Memmap.hpp>
|
||||
#include <Memory/Heap.hpp>
|
||||
#include <Memory/HHDM.hpp>
|
||||
#include <Platform/Util.hpp>
|
||||
#include <Hal/IDT.hpp>
|
||||
#include <Memory/PageFrameAllocator.hpp>
|
||||
#include <Memory/Paging.hpp>
|
||||
#include <ACPI/ACPI.hpp>
|
||||
#include <ACPI/CpuIdle.hpp>
|
||||
#include <ACPI/AcpiShutdown.hpp>
|
||||
#include <ACPI/AcpiEvents.hpp>
|
||||
#include <ACPI/EmbeddedController.hpp>
|
||||
#include <ACPI/Battery.hpp>
|
||||
#include <ACPI/AML/AmlParser.hpp>
|
||||
#include <Hal/Apic/ApicInit.hpp>
|
||||
#include <Pci/Pci.hpp>
|
||||
#include <Timekeeping/ApicTimer.hpp>
|
||||
#include <Drivers/PS2/PS2Controller.hpp>
|
||||
#include <Drivers/PS2/Keyboard.hpp>
|
||||
#include <Drivers/PS2/Mouse.hpp>
|
||||
#include <Timekeeping/Timer.hpp>
|
||||
#include <Drivers/Init.hpp>
|
||||
#include <Graphics/Framebuffer.hpp>
|
||||
#include <Hal/MSR.hpp>
|
||||
#include <Hal/Cpu.hpp>
|
||||
#include <Hal/CpuPower.hpp>
|
||||
#include <Arch/Cpu.hpp>
|
||||
#include <Arch/Platform.hpp>
|
||||
#include <Fs/Boot.hpp>
|
||||
#include <Sched/Scheduler.hpp>
|
||||
#include <Ipc/Ipc.hpp>
|
||||
#include <Api/Syscall.hpp>
|
||||
#include <Hal/SmpBoot.hpp>
|
||||
#include <Arch/Smp.hpp>
|
||||
using namespace Kt;
|
||||
|
||||
namespace Memory {
|
||||
@@ -69,7 +60,7 @@ extern "C" void kmain() {
|
||||
}
|
||||
|
||||
if (!montauk::boot::Initialize()) {
|
||||
Hal::Halt();
|
||||
Arch::HaltForever();
|
||||
}
|
||||
const montauk::boot::BootInfo& boot = montauk::boot::Info();
|
||||
const montauk::boot::Framebuffer& framebuffer = boot.framebuffer;
|
||||
@@ -88,12 +79,7 @@ extern "C" void kmain() {
|
||||
);
|
||||
|
||||
|
||||
#if defined (__x86_64__)
|
||||
Hal::PrepareGDT();
|
||||
Hal::BridgeLoadGDT();
|
||||
|
||||
Hal::EnableSSE();
|
||||
#endif
|
||||
Arch::EarlyInitialize();
|
||||
|
||||
Memory::HHDMBase = boot.hhdmBase;
|
||||
|
||||
@@ -112,26 +98,19 @@ extern "C" void kmain() {
|
||||
heap.Walk();
|
||||
|
||||
|
||||
#if defined (__x86_64__)
|
||||
Hal::IDTInitialize();
|
||||
Arch::InitializeTraps();
|
||||
|
||||
Memory::VMM::Paging g_paging{};
|
||||
Memory::VMM::g_paging = &g_paging;
|
||||
g_paging.Init((uint64_t)&KernelStartSymbol, ((uint64_t)&KernelEndSymbol - (uint64_t)&KernelStartSymbol), boot.memoryMap, framebuffer);
|
||||
|
||||
Hal::InitializePAT();
|
||||
|
||||
#endif
|
||||
Arch::InitializeMemoryAttributes();
|
||||
|
||||
Graphics::Framebuffer::Initialize(framebuffer);
|
||||
|
||||
#if defined (__x86_64__)
|
||||
Graphics::Framebuffer::MapWriteCombining();
|
||||
#endif
|
||||
|
||||
Hal::ACPI g_acpi((Hal::ACPI::XSDP*)Memory::HHDM(boot.rsdpPhysical));
|
||||
|
||||
#if defined (__x86_64__)
|
||||
if (g_acpi.GetXSDT() != nullptr) {
|
||||
Hal::AcpiShutdown::Initialize(g_acpi.GetXSDT());
|
||||
|
||||
@@ -140,15 +119,11 @@ extern "C" void kmain() {
|
||||
Hal::EmbeddedController::Initialize(g_acpi.GetXSDT());
|
||||
Hal::Battery::Initialize();
|
||||
|
||||
Hal::CpuIdle::Initialize(g_acpi.GetXSDT());
|
||||
// Interrupt controllers, this CPU's per-CPU data, idle and power
|
||||
// management.
|
||||
Arch::InitializeInterrupts(g_acpi.GetXSDT());
|
||||
|
||||
Hal::ApicInitialize(g_acpi.GetXSDT());
|
||||
|
||||
Smp::InitBsp();
|
||||
|
||||
Hal::CpuPower::InitializeBsp();
|
||||
|
||||
asm volatile("sti");
|
||||
Arch::EnableInterrupts();
|
||||
|
||||
Hal::AcpiEvents::Initialize(g_acpi.GetXSDT());
|
||||
|
||||
@@ -163,11 +138,9 @@ extern "C" void kmain() {
|
||||
Drivers::ProbeEarly();
|
||||
Drivers::InitializeGraphics();
|
||||
|
||||
Timekeeping::ApicTimerInitialize();
|
||||
Timekeeping::TimerInitialize();
|
||||
|
||||
Drivers::PS2::Initialize();
|
||||
Drivers::PS2::Keyboard::Initialize();
|
||||
Drivers::PS2::Mouse::Initialize();
|
||||
Arch::InitializePlatformDevices();
|
||||
|
||||
// Hybrid graphics: switch off a discrete GPU nothing drives before
|
||||
// the normal probe can claim its USB-C/audio functions.
|
||||
@@ -178,7 +151,6 @@ extern "C" void kmain() {
|
||||
Drivers::InitializeStorage();
|
||||
Drivers::InitializeAudio();
|
||||
}
|
||||
#endif
|
||||
|
||||
// UEFI runtime services are optional (absent on legacy-BIOS boots).
|
||||
if (boot.has(montauk::boot::FeatureEfiSystemTable)) {
|
||||
@@ -188,9 +160,7 @@ extern "C" void kmain() {
|
||||
|
||||
Fs::InitializeBootFilesystems(boot.modules);
|
||||
|
||||
#if defined (__x86_64__)
|
||||
Hal::LoadTSS();
|
||||
#endif
|
||||
Arch::PrepareUserMode();
|
||||
|
||||
montauk::abi::InitializeSyscalls();
|
||||
|
||||
@@ -199,36 +169,16 @@ extern "C" void kmain() {
|
||||
Fs::LogProtectedPaths();
|
||||
Ipc::Initialize();
|
||||
|
||||
#if defined (__x86_64__)
|
||||
Smp::BootAPs(boot.smp);
|
||||
#endif
|
||||
|
||||
#if defined (__x86_64__)
|
||||
Drivers::PS2::Mouse::FlushState();
|
||||
#endif
|
||||
Arch::LateInitialize();
|
||||
|
||||
Kt::SuppressKernelLog();
|
||||
Sched::Spawn("0:/os/init.elf");
|
||||
|
||||
Timekeeping::EnableSchedulerTick();
|
||||
|
||||
#if defined (__x86_64__)
|
||||
// Use MWAIT for deeper C-states if available, otherwise HLT.
|
||||
auto* bspCpu = Smp::GetCpuData(0);
|
||||
|
||||
if (bspCpu && bspCpu->hasMwait) {
|
||||
static volatile uint64_t s_bspIdleMonitor = 0;
|
||||
for (;;) {
|
||||
Timekeeping::IdleOnce(true, &s_bspIdleMonitor);
|
||||
}
|
||||
} else {
|
||||
for (;;) {
|
||||
Timekeeping::IdleOnce(false);
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (;;) {
|
||||
Timekeeping::IdleOnce(false);
|
||||
Timekeeping::IdleOnce();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in new issue
Block a user