2022-09-05 14:13:51 +00:00
|
|
|
#include "acpi/RSDT.h"
|
|
|
|
#include "assert.h"
|
|
|
|
#include "bootboot.h"
|
|
|
|
#include "cpu/CPU.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "gdt/GDT.h"
|
|
|
|
#include "init/Init.h"
|
|
|
|
#include "init/InitRD.h"
|
|
|
|
#include "interrupts/IDT.h"
|
|
|
|
#include "interrupts/Install.h"
|
|
|
|
#include "interrupts/Interrupts.h"
|
|
|
|
#include "io/PIC.h"
|
|
|
|
#include "io/Serial.h"
|
|
|
|
#include "log/Log.h"
|
|
|
|
#include "memory/KernelHeap.h"
|
|
|
|
#include "panic/hang.h"
|
|
|
|
#include "render/BBRenderer.h"
|
|
|
|
#include "render/Draw.h"
|
|
|
|
#include "render/TextRenderer.h"
|
|
|
|
#include "scheduling/PIT.h"
|
|
|
|
#include "std/stdio.h"
|
|
|
|
#include "std/stdlib.h"
|
|
|
|
#include "std/string.h"
|
|
|
|
|
|
|
|
extern BOOTBOOT bootboot;
|
|
|
|
|
|
|
|
extern "C" void _start()
|
|
|
|
{
|
|
|
|
Init::check_magic();
|
|
|
|
Init::disable_smp(); // Put all other cores except the bootstrap one in an infinite loop
|
|
|
|
Debug::DebugStatus::the()->Init();
|
|
|
|
Debug::DebugStatus::the()->StartBootStage(Color::White);
|
|
|
|
Init::early_init();
|
|
|
|
Debug::DebugStatus::the()->PassBootStage(Color::White);
|
|
|
|
|
|
|
|
kinfoln("Hello World!");
|
|
|
|
|
|
|
|
Debug::DebugStatus::the()->StartBootStage(Color::Gray);
|
|
|
|
GDT::load();
|
|
|
|
Debug::DebugStatus::the()->PassBootStage(Color::Gray);
|
|
|
|
|
|
|
|
kinfoln("Loaded GDT");
|
|
|
|
|
|
|
|
Debug::DebugStatus::the()->StartBootStage(Color::Cyan);
|
|
|
|
Interrupts::install();
|
|
|
|
Debug::DebugStatus::the()->PassBootStage(Color::Cyan);
|
|
|
|
|
|
|
|
Debug::DebugStatus::the()->StartBootStage(Color::Blue);
|
|
|
|
IDT::load();
|
|
|
|
Debug::DebugStatus::the()->PassBootStage(Color::Blue);
|
|
|
|
|
|
|
|
kinfoln("Loaded IDT");
|
|
|
|
|
|
|
|
Debug::DebugStatus::the()->StartBootStage(Color::Green);
|
|
|
|
PIC::remap();
|
|
|
|
PIC::enable_master(0b11111100); // enable keyboard and PIT
|
|
|
|
PIC::enable_slave(0b11111111);
|
|
|
|
Debug::DebugStatus::the()->PassBootStage(Color::Green);
|
|
|
|
|
|
|
|
kinfoln("Prepared PIC");
|
|
|
|
|
|
|
|
Debug::DebugStatus::the()->StartBootStage(Color::Magenta);
|
|
|
|
PIT::initialize(100); // 100 times per second
|
|
|
|
Debug::DebugStatus::the()->PassBootStage(Color::Magenta);
|
|
|
|
|
|
|
|
kinfoln("Prepared PIT");
|
|
|
|
|
2022-09-05 14:59:45 +00:00
|
|
|
uint64_t mmap_entries = (bootboot.size - 128) / 16;
|
|
|
|
MMapEnt* entry = (&bootboot.mmap);
|
|
|
|
for (uint64_t i = 0; i < mmap_entries; i++)
|
|
|
|
{
|
|
|
|
if (MMapEnt_IsFree(entry))
|
|
|
|
{
|
|
|
|
printf("Free region at 0x%zx, of size 0x%zx\n", MMapEnt_Ptr(entry), MMapEnt_Size(entry));
|
|
|
|
}
|
|
|
|
else { printf("Used region at 0x%zx, of size 0x%zx\n", MMapEnt_Ptr(entry), MMapEnt_Size(entry)); }
|
|
|
|
entry++;
|
|
|
|
}
|
|
|
|
|
2022-09-05 14:13:51 +00:00
|
|
|
Debug::DebugStatus::the()->StartBootStage(Color::Yellow);
|
|
|
|
Interrupts::enable();
|
|
|
|
Debug::DebugStatus::the()->PassBootStage(Color::Yellow);
|
|
|
|
|
|
|
|
kinfoln("Interrupts enabled");
|
|
|
|
|
|
|
|
Debug::DebugStatus::the()->StartBootStage(Color{0x33, 0x33, 0x00, 0xFF});
|
|
|
|
ACPI::SDTHeader* rootSDT = ACPI::GetRSDTOrXSDT();
|
|
|
|
bool isXSDT = false;
|
|
|
|
if (strncmp(rootSDT->Signature, "XSDT", 4) != 0)
|
|
|
|
{
|
|
|
|
if (strncmp(rootSDT->Signature, "RSDT", 4) != 0)
|
|
|
|
{
|
|
|
|
kerrorln("Invalid RootSDT signature");
|
|
|
|
Debug::DebugStatus::the()->FailBootStage();
|
|
|
|
while (1) halt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
isXSDT = true;
|
|
|
|
if (ACPI::ValidateSDTHeader(rootSDT))
|
|
|
|
{
|
|
|
|
kinfoln(isXSDT ? "XSDT is valid" : "RSDT is valid");
|
|
|
|
Debug::DebugStatus::the()->PassBootStage(Color{0x33, 0x33, 0x00, 0xFF});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kinfoln(isXSDT ? "Invalid XSDT :(" : "Invalid RSDT :(");
|
|
|
|
Debug::DebugStatus::the()->FailBootStage();
|
|
|
|
while (1) halt();
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug::DebugStatus::the()->StartBootStage(Color{0x00, 0x66, 0xCC, 0xFF});
|
|
|
|
ACPI::SDTHeader* fadt = (ACPI::SDTHeader*)ACPI::FindTable(rootSDT, "FACP");
|
|
|
|
if (!fadt)
|
|
|
|
{
|
|
|
|
kerrorln("FADT not found");
|
|
|
|
Debug::DebugStatus::the()->FailBootStage();
|
|
|
|
while (1) halt();
|
|
|
|
}
|
|
|
|
if (strncmp(fadt->Signature, "FACP", 4) != 0)
|
|
|
|
{
|
|
|
|
kerrorln("Invalid FADT signature");
|
|
|
|
Debug::DebugStatus::the()->FailBootStage();
|
|
|
|
while (1) halt();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ACPI::ValidateSDTHeader(fadt))
|
|
|
|
{
|
|
|
|
kinfoln("FADT is valid");
|
|
|
|
Debug::DebugStatus::the()->PassBootStage(Color{0x00, 0x66, 0xCC, 0xFF});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kinfoln("Invalid FADT :(");
|
|
|
|
Debug::DebugStatus::the()->FailBootStage();
|
|
|
|
while (1) halt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) halt();
|
|
|
|
loop:
|
|
|
|
goto loop;
|
|
|
|
}
|