diff options
| author | Arseney300 <Arseney300@gmail.com> | 2026-04-11 17:48:52 +0700 |
|---|---|---|
| committer | Arseney300 <Arseney300@gmail.com> | 2026-04-11 17:48:52 +0700 |
| commit | 496246c92dabe6757480147016490ea6ae43bb66 (patch) | |
| tree | cb922a0b1569410db44f6da17862b7e949df9fad /kernel/core/kernel_main.cpp | |
| parent | 2f95320e0859029f520d46f777591751dcd39634 (diff) | |
Kernel: main singleton object, that provide access to core kernel
entities
Processor: empty class, that will be used later for per-CPU entities
AcpiTables: class for acpi access (can be obtained through the kernel
object)
DeviceTree: class for dt access (can be obtained through the kernel
object)
Diffstat (limited to 'kernel/core/kernel_main.cpp')
| -rw-r--r-- | kernel/core/kernel_main.cpp | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/kernel/core/kernel_main.cpp b/kernel/core/kernel_main.cpp index 9c744c7..cf95b59 100644 --- a/kernel/core/kernel_main.cpp +++ b/kernel/core/kernel_main.cpp @@ -8,7 +8,10 @@ #include <boot/boot_info.h> #include <kernel/kprint.h> #include <kernel/arch.h> +#include <kernel/kernel.h> +#include "Processor.h" +using namespace kernel; // ── Memory region type names ─────────────────────────────────────────────── namespace { @@ -36,39 +39,41 @@ extern "C" void kernel_main(BootInfo* boot_info) { if (boot_info->magic != BOOT_INFO_MAGIC) arch::halt(); - // Initialize framebuffer console. + // Initialize framebuffer console (needed before Kernel::init for logging). // TODO: Add driver skeleton and move framebuffer to early drivers. kcon::init(boot_info->framebuffer); + // Initialize the kernel object — copies boot data, safe to use after this. + GetKernel().init(*boot_info); + + // Store arch-specific per-CPU state (Phase 2: GDT/IDT, VBAR/GIC, etc.). + processor().InitEarly(*boot_info); + // ── Banner ───────────────────────────────────────────────────────── kcon::println("========================================"); - kcon::println(" Bastion Kernel " CONFIG_KERNEL_VERSION); - kcon::kprintf(" Architecture: %s\n", arch::name()); + kcon::kprintf(" Bastion Kernel %s\n", GetKernel().GetVersion().string); + kcon::kprintf(" Architecture: %s\n", GetKernel().GetArchName()); kcon::println("========================================"); kcon::putchar('\n'); // ── Framebuffer info ─────────────────────────────────────────────── kcon::kprintf("Framebuffer: %ux%u, pitch=%u, base=%x\n", - boot_info->framebuffer.width, - boot_info->framebuffer.height, - boot_info->framebuffer.pitch, - boot_info->framebuffer.base); + GetKernel().GetFramebuffer().width, + GetKernel().GetFramebuffer().height, + GetKernel().GetFramebuffer().pitch, + GetKernel().GetFramebuffer().base); kcon::putchar('\n'); // ── Firmware tables ──────────────────────────────────────────────── - -#ifdef CONFIG_X86 - if (boot_info->rsdp_address) - kcon::kprintf("ACPI RSDP at: %x\n", boot_info->rsdp_address); -#elif CONFIG_AARCH64 - if (boot_info->fdt_address) - kcon::kprintf("Device Tree at: %x\n", boot_info->fdt_address); -#endif + if (GetKernel().GetAcpiTables() && GetKernel().GetAcpiTables()->GetRsdpAddress()) + kcon::kprintf("ACPI RSDP at: %x\n", GetKernel().GetAcpiTables()->GetRsdpAddress()); + if (GetKernel().GetDeviceTree() && GetKernel().GetDeviceTree()->GetFdtAddress()) + kcon::kprintf("Device Tree at: %x\n", GetKernel().GetDeviceTree()->GetFdtAddress()); kcon::putchar('\n'); - // ── Memory map ───────────────────────────────────────────────────── + // ── Memory map (read directly from boot_info, consumed by PMM later) ── kcon::kprintf("Memory map (%u entries):\n", boot_info->memory_map_count); @@ -96,12 +101,14 @@ extern "C" void kernel_main(BootInfo* boot_info) { kcon::putchar('\n'); kcon::kprintf("Kernel loaded at phys %x, virt %x, size %u KiB\n", - boot_info->kernel_phys_base, - boot_info->kernel_virt_base, - boot_info->kernel_size / 1024u); + GetKernel().GetKernelPhysBase(), + GetKernel().GetKernelPhysBase(), + GetKernel().GetKernelSize() / 1024u); // ── Done (for now) ───────────────────────────────────────────────── + GetKernel().SetRunning(); + kcon::putchar('\n'); kcon::println("Hello, World from BastionOS!"); kcon::putchar('\n'); @@ -109,5 +116,8 @@ extern "C" void kernel_main(BootInfo* boot_info) { kcon::println("Next: GDT, IDT, paging, memory allocator..."); kcon::println("Halting."); - arch::halt(); // [[noreturn]] — never comes back + //KERNEL_PANIC("panic test"); + + GetKernel().SetHalt(); + arch::halt(); } |
