summaryrefslogtreecommitdiff
path: root/lume-legacy/src/kernel/main.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-07-10 11:31:46 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-07-10 11:31:46 +0800
commite90b72ec3082588b296956730bd2930cf8d5d671 (patch)
tree36ff6916af9b4176ea5a9662219d11e721f0b691 /lume-legacy/src/kernel/main.cc
parent1767d390fbf3d0c65389de46caf0b6d43ef3b6ad (diff)
downloadlume-e90b72ec3082588b296956730bd2930cf8d5d671.tar.gz
lume-e90b72ec3082588b296956730bd2930cf8d5d671.tar.xz
refactor: promote new architecture to repository root
Archive the deprecated implementation under lume-legacy, make the new kernel the default root-level build, and update repository entry points without changing kernel behavior.
Diffstat (limited to 'lume-legacy/src/kernel/main.cc')
-rw-r--r--lume-legacy/src/kernel/main.cc79
1 files changed, 79 insertions, 0 deletions
diff --git a/lume-legacy/src/kernel/main.cc b/lume-legacy/src/kernel/main.cc
new file mode 100644
index 0000000..6a19915
--- /dev/null
+++ b/lume-legacy/src/kernel/main.cc
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Richard QIn
+ */
+#include "common/types.h"
+#include "kernel/riscv.h"
+#include "drivers/uart.h"
+#include "drivers/plic.h"
+#include "drivers/virtio.h"
+#include "kernel/pmm.h"
+#include "kernel/mm.h"
+#include "kernel/slab.h"
+#include "kernel/proc.h"
+#include "kernel/trap.h"
+#include "kernel/timer.h"
+#include "kernel/cpu.h"
+#include "kernel/buf.h"
+#include "fs/fs.h"
+#include "fs/file.h"
+#include "fs/fat32.h"
+#include "lib/string.h"
+
+#include "kernel/fdt.h" // fdt_parse
+
+extern uint64 g_dtb_addr;
+
+// Placement new support (referenced from cxx.cc)
+void *operator new(unsigned long size, void *ptr);
+
+volatile static int started = 0;
+
+extern "C" void kernel_main(uint64 hartid, uint64 dtb)
+{
+ if (hartid == 0)
+ {
+ fdt_parse(dtb);
+
+ Drivers::uart_init();
+ Drivers::uart_puts("\n[Lume OS] Booting...\n");
+
+ Drivers::uart_puts("[Boot] PMP configured.\n");
+
+ PMM::init(); // Physical Memory Management
+ VM::kvminit(); // Kernel Pagetable
+ VM::kvminithart(); // Enable MMU
+ Slab::init();
+ Trap::init(); // Trap Management
+ Trap::inithart();
+ PLIC::init();
+ PLIC::inithart();
+ VirtIO::init();
+ BufferCache::init();
+ VFS::init();
+ // Initialize global FAT32 object manually (global constructors not supported yet)
+ new (&fat32_fs) FAT32FileSystem();
+ VFS::register_fs(&fat32_fs);
+ FileTable::init();
+ Timer::init();
+ ProcManager::init(); // Process Management
+ ProcManager::user_init(); // Initialize first user process
+
+ __atomic_store_n(&started, 1, __ATOMIC_RELEASE);
+
+ Drivers::uart_puts("[Boot] System initialized. Entering scheduler...\n");
+ }
+ else
+ {
+ while (__atomic_load_n(&started, __ATOMIC_ACQUIRE) == 0)
+ ;
+
+ VM::kvminithart();
+ Trap::inithart();
+ PLIC::inithart();
+ Timer::init();
+ Drivers::uart_puts("[Boot] Hart started.\n");
+ }
+
+ ProcManager::scheduler(); // Enable Scheduler
+} \ No newline at end of file