refactor: elf parsing utility and exec related
[lunaix-os.git] / lunaix-os / kernel / proc0.c
index abd0ac0df4f3d925a6f7f171b2f8d9e67f4a37f7..d765691a3d622482076d07c161ca414833639b1c 100644 (file)
@@ -1,9 +1,10 @@
 #include <lunaix/block.h>
 #include <lunaix/common.h>
 #include <lunaix/block.h>
 #include <lunaix/common.h>
+#include <lunaix/exec.h>
 #include <lunaix/foptions.h>
 #include <lunaix/fs.h>
 #include <lunaix/foptions.h>
 #include <lunaix/fs.h>
+#include <lunaix/fs/probe_boot.h>
 #include <lunaix/fs/twifs.h>
 #include <lunaix/fs/twifs.h>
-#include <lunaix/ld.h>
 #include <lunaix/lxconsole.h>
 #include <lunaix/mm/cake.h>
 #include <lunaix/mm/pmm.h>
 #include <lunaix/lxconsole.h>
 #include <lunaix/mm/cake.h>
 #include <lunaix/mm/pmm.h>
@@ -48,14 +49,14 @@ mount_bootmedium()
 {
     struct v_dnode* dnode;
     int errno = 0;
 {
     struct v_dnode* dnode;
     int errno = 0;
-    if ((errno = vfs_walk_proc("/dev/sdb", &dnode, NULL, 0))) {
+    struct device* dev = probe_boot_medium();
+    if (!dev) {
         kprintf(KERROR "fail to acquire device. (%d)", errno);
         return 0;
     }
 
         kprintf(KERROR "fail to acquire device. (%d)", errno);
         return 0;
     }
 
-    struct device* dev = (struct device*)dnode->inode->data;
     if ((errno = vfs_mount("/mnt/lunaix-os", "iso9660", dev, 0))) {
     if ((errno = vfs_mount("/mnt/lunaix-os", "iso9660", dev, 0))) {
-        kprintf(KERROR "fail to boot medium. (%d)", errno);
+        kprintf(KERROR "fail to mount boot medium. (%d)", errno);
         return 0;
     }
 
         return 0;
     }
 
@@ -66,31 +67,11 @@ int
 exec_initd()
 {
     int errno = 0;
 exec_initd()
 {
     int errno = 0;
-    struct ld_param param;
-    char filename[] = "/mnt/lunaix-os/usr/init";
 
 
-    ld_create_param(&param, __current, VMS_SELF);
-
-    if ((errno = exec_load_byname(&param, filename, NULL, NULL))) {
+    if (exec_kexecve("/mnt/lunaix-os/usr/init", NULL, NULL)) {
         goto fail;
     }
 
         goto fail;
     }
 
-    // user space
-    asm volatile("movw %0, %%ax\n"
-                 "movw %%ax, %%es\n"
-                 "movw %%ax, %%ds\n"
-                 "movw %%ax, %%fs\n"
-                 "movw %%ax, %%gs\n"
-                 "pushl %0\n"
-                 "pushl %1\n"
-                 "pushl %2\n"
-                 "pushl %3\n"
-                 "retf" ::"i"(UDATA_SEG),
-                 "r"(param.info.stack_top),
-                 "i"(UCODE_SEG),
-                 "r"(param.info.entry)
-                 : "eax", "memory");
-
     fail("should not reach");
 
 fail:
     fail("should not reach");
 
 fail: