fix: corner cases when printing large content through term interface
[lunaix-os.git] / lunaix-os / kernel / kinit.c
index 607ba20a9d6aea6bcdb4bb11d05d978c4e9ca0d1..a54b68a7adaf0e76ecc9e9410d0376ea9796e54a 100644 (file)
@@ -1,11 +1,10 @@
+#include <lunaix/types.h>
 #include <lunaix/block.h>
 #include <lunaix/boot_generic.h>
-#include <lunaix/common.h>
 #include <lunaix/device.h>
 #include <lunaix/foptions.h>
 #include <lunaix/fs/twifs.h>
 #include <lunaix/input.h>
-#include <lunaix/lxconsole.h>
 #include <lunaix/mm/cake.h>
 #include <lunaix/mm/mmio.h>
 #include <lunaix/mm/page.h>
 #include <lunaix/spike.h>
 #include <lunaix/trace.h>
 #include <lunaix/tty/tty.h>
-#include <lunaix/types.h>
+#include <lunaix/owloysius.h>
 
 #include <hal/acpi/acpi.h>
 #include <hal/intc.h>
-#include <hal/pci.h>
 
 #include <sys/abi.h>
 #include <sys/interrupts.h>
 #include <sys/mm/mempart.h>
 
-#include <klibc/stdio.h>
+#include <klibc/strfmt.h>
 #include <klibc/string.h>
 
 extern void
@@ -51,46 +49,49 @@ kernel_bootstrap(struct boot_handoff* bhctx)
     /* Setup kernel memory layout and services */
     kmem_init(bhctx);
 
+    boot_parse_cmdline(bhctx);
+
     /* Prepare stack trace environment */
     trace_modksyms_init(bhctx);
 
-    // crt
-    tty_init(ioremap(VGA_FRAMEBUFFER, PG_SIZE));
-    tty_set_theme(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
-    lxconsole_init();
+    device_scan_drivers();
 
-    /* Get platform configuration */
-    acpi_init();
+    invoke_init_function(on_earlyboot);
 
-    /* Let's get fs online as soon as possible, as things rely on them */
-    vfs_init();
-    fsm_init();
-    input_init();
+    // FIXME this goes to hal/gfxa
+    tty_init(ioremap(0xB8000, PG_SIZE));
+    tty_set_theme(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
+
+    device_sysconf_load();
 
     /* Get intc online, this is the cornerstone when initing devices */
     intc_init();
 
-    /* System timing and clock support */
     clock_init();
     timer_init();
 
-    block_init();
+    /*
+        TODO autoload these init function that do not have dependency between
+       them
+    */
 
-    /* the bare metal are now happy, let's get software over with */
+    /* Let's get fs online as soon as possible, as things rely on them */
+    vfs_init();
+    fsm_init();
+    input_init();
+    block_init();
     sched_init();
 
-    int errno = 0;
-    if ((errno = vfs_mount_root("ramfs", NULL))) {
-        panickf("Fail to mount root. (errno=%d)", errno);
-    }
+    device_onboot_load();
+
+    /* the bare metal are now happy, let's get software over with */
 
-    /* Mount these system-wide pseudo-fs */
-    vfs_mount("/dev", "devfs", NULL, 0);
-    vfs_mount("/sys", "twifs", NULL, MNT_RO);
-    vfs_mount("/task", "taskfs", NULL, MNT_RO);
+    must_success(vfs_mount_root("ramfs", NULL));
+    must_success(vfs_mount("/dev", "devfs", NULL, 0));
+    
+    invoke_init_function(on_boot);
 
-    lxconsole_spawn_ttydev();
-    device_init_builtin();
+    must_success(vfs_unmount("/dev"));
 
     /* Finish up bootstrapping sequence, we are ready to spawn the root process
      * and start geting into uspace
@@ -138,16 +139,12 @@ spawn_proc0()
     cpu_chvmspace(proc0->page_table);
 
     // 为内核创建一个专属栈空间。
-    for (size_t i = 0; i < (KSTACK_SIZE >> PG_SIZE_BITS); i++) {
+    for (size_t i = 0; i < KERNEL_STACK_SIZE; i += PG_SIZE) {
         ptr_t pa = pmm_alloc_page(KERNEL_PID, 0);
-        vmm_set_mapping(VMS_SELF,
-                        KSTACK_START + (i << PG_SIZE_BITS),
-                        pa,
-                        PG_PREM_RW,
-                        VMAP_NULL);
+        vmm_set_mapping(VMS_SELF, KERNEL_STACK + i, pa, PG_PREM_RW, VMAP_NULL);
     }
 
-    proc_init_transfer(proc0, KSTACK_TOP, (ptr_t)__proc0, 0);
+    proc_init_transfer(proc0, KERNEL_STACK_END, (ptr_t)__proc0, 0);
 
     // 向调度器注册进程。
     commit_process(proc0);