49 lines
1.3 KiB
C
49 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// Copyright (c) 2026 0xKSor
|
|
|
|
#include "../Common/bootinfo.h"
|
|
#include <Arch/DTB.h>
|
|
#include <Arch/Timer.h>
|
|
#include <Arch/CPU.h>
|
|
#include <Arch/GIC.h>
|
|
#include <IO/Serial.h>
|
|
#include <VM/PMM.h>
|
|
#include <VM/VMM.h>
|
|
#include <VM/Heap.h>
|
|
#include <OS/Log.h>
|
|
#include <OS/Panic.h>
|
|
#include <OS/Scheduler.h>
|
|
#include <OS/Modules.h>
|
|
|
|
void KernelMain(Bootinfo* bootinfo) {
|
|
OSLog("Kernel started.\n");
|
|
if (bootinfo->magic != BOOTINFO_MAGIC) {
|
|
OSPanic("Invalid bootinfo magic");
|
|
}
|
|
|
|
VMBootMemoryMap bootMap = {0};
|
|
|
|
bootMap.reservedCount = 0;
|
|
DTBParse(bootinfo->dtb, &bootMap);
|
|
PMMInitialize(&bootMap);
|
|
VMMInitialize(&bootMap, bootinfo);
|
|
bootinfo = (Bootinfo*)VMPhysToHHDM((Address)bootinfo);
|
|
SerialUpdate(VMPhysToHHDM(bootMap.UART.base));
|
|
HeapInitialize();
|
|
|
|
GICInitialize(
|
|
(Pointer)VMPhysToHHDM(bootMap.GIC.GICD.base),
|
|
(Pointer)VMPhysToHHDM(bootMap.GIC.GICC.base)
|
|
);
|
|
TimerInitialize();
|
|
CPUEnableInterrupts();
|
|
SchedulerInitialize();
|
|
|
|
for (UInt32 i = 0; i < bootinfo->moduleCount; i++) {
|
|
ModuleLoad(&bootinfo->modules[i]); // TODO: make some sort of priority of loading modules
|
|
// like init first then uart then fb ...
|
|
}
|
|
|
|
OSLog("Kernel initialized.\n");
|
|
}
|