feat: heap support and re-worked
[lunaix-os.git] / lunaix-os / kernel / proc0.c
index 1e54e59e6d9ea9531470907bd481f5d4f88ec762..6f39299977eaf1dac49a312cb1efce05db75d2ae 100644 (file)
@@ -1,9 +1,8 @@
 #include <lunaix/block.h>
 #include <lunaix/common.h>
-#include <lunaix/fctrl.h>
+#include <lunaix/foptions.h>
 #include <lunaix/fs.h>
 #include <lunaix/fs/twifs.h>
-#include <lunaix/lunistd.h>
 #include <lunaix/lxconsole.h>
 #include <lunaix/mm/cake.h>
 #include <lunaix/mm/pmm.h>
 #include <lunaix/mm/vmm.h>
 #include <lunaix/peripheral/ps2kbd.h>
 #include <lunaix/peripheral/serial.h>
-#include <lunaix/proc.h>
 #include <lunaix/spike.h>
 #include <lunaix/syscall.h>
 #include <lunaix/syslog.h>
 #include <lunaix/types.h>
+
+#include <usr/fcntl.h>
+#include <usr/sys/lunaix.h>
+#include <usr/unistd.h>
+
 #include <sdbg/protocol.h>
 
 #include <hal/acpi/acpi.h>
@@ -76,6 +79,18 @@ input_test();
 extern void
 sh_main();
 
+void __USER__
+__setup_dir()
+{
+    int errno;
+    mkdir("/mnt");
+    mkdir("/mnt/lunaix-os");
+
+    if ((errno = mount("/dev/sdb", "/mnt/lunaix-os", "iso9660", 0))) {
+        syslog(2, "fail mounting boot medium. (%d)\n", errno);
+    }
+}
+
 void __USER__
 __proc0_usr()
 {
@@ -85,6 +100,8 @@ __proc0_usr()
     int fdstdout = open("/dev/tty", 0);
     int fdstdin = dup2(stdout, 1);
 
+    __setup_dir();
+
     pid_t p;
 
     if (!(p = fork())) {
@@ -154,7 +171,9 @@ extern multiboot_info_t* _k_init_mb_info; /* k_init.c */
 void
 init_platform()
 {
-    kprintf(KINFO "\033[11;0mLunaixOS \033[39;49m\n");
+    kprintf(KINFO "\033[11;0mLunaixOS (gcc v%s, %s)\033[39;49m\n",
+            __VERSION__,
+            __TIME__);
 
     // 锁定所有系统预留页(内存映射IO,ACPI之类的),并且进行1:1映射
     lock_reserved_memory();
@@ -193,7 +212,7 @@ init_platform()
 
     // clean up
     for (size_t i = 0; i < (uintptr_t)(&__init_hhk_end); i += PG_SIZE) {
-        vmm_del_mapping(PD_REFERENCED, (void*)i);
+        vmm_del_mapping(VMS_SELF, (void*)i);
         pmm_free_page(KERNEL_PID, (void*)i);
     }
 }
@@ -237,7 +256,7 @@ __do_reserved_memory(int unlock)
                     // Don't fuck up our kernel space!
                     break;
                 }
-                vmm_set_mapping(PD_REFERENCED, _pa, _pa, PG_PREM_R, VMAP_NULL);
+                vmm_set_mapping(VMS_SELF, _pa, _pa, PG_PREM_R, VMAP_NULL);
                 pmm_mark_page_occupied(
                   KERNEL_PID, _pa >> PG_SIZE_BITS, PP_FGLOCKED);
             }
@@ -250,7 +269,7 @@ __do_reserved_memory(int unlock)
                     mmap.type);
             for (; j < pg_num; j++) {
                 uintptr_t _pa = pa + (j << PG_SIZE_BITS);
-                vmm_del_mapping(PD_REFERENCED, _pa);
+                vmm_del_mapping(VMS_SELF, _pa);
                 if (mmap.type == MULTIBOOT_MEMORY_ACPI_RECLAIMABLE) {
                     pmm_mark_page_free(_pa >> PG_SIZE_BITS);
                 }