1 #include <lunaix/boot_generic.h>
2 #include <lunaix/exec.h>
3 #include <lunaix/foptions.h>
5 #include <lunaix/fs/twifs.h>
6 #include <lunaix/spike.h>
7 #include <lunaix/syslog.h>
8 #include <lunaix/types.h>
9 #include <lunaix/owloysius.h>
10 #include <lunaix/sched.h>
11 #include <lunaix/kpreempt.h>
12 #include <lunaix/kcmd.h>
13 #include <lunaix/kthread.h>
15 #include <klibc/string.h>
30 if (!kcmd_get_option("rootfs", &rootfs)) {
35 if ((errno = vfs_walk(NULL, rootfs, &dn, NULL, 0))) {
36 ERROR("%s: no such file (%d)", rootfs, errno);
40 dev = resolve_device(dn->inode->data);
42 ERROR("%s: not a device", rootfs);
46 // unmount the /dev to put old root fs in clear
47 must_success(vfs_unmount("/dev"));
49 // re-mount the root fs with our device.
50 if ((errno = vfs_mount_root(NULL, dev))) {
51 ERROR("mount root failed: %s (%d)", rootfs, errno);
62 const char* argv[] = { "/init", 0 };
63 const char* envp[] = { 0 };
65 kcmd_get_option("init", (char**)&argv[0]);
67 if ((errno = exec_kexecve(argv[0], argv, envp))) {
71 fail("should not reach");
74 ERROR("fail to load initd. (%d)", errno);
80 // No, these are not preemptive
84 fail("failed to initd");
93 cleanup_detached_threads();
100 * @brief LunaixOS的内核进程,该进程永远为可执行。
102 * 这主要是为了保证调度器在没有进程可调度时依然有事可做。
104 * 同时,该进程也负责fork出我们的init进程。
110 kthread_spawn((ptr_t)init_platform);
111 kthread_spawn((ptr_t)__thread_cleaner);
122 device_postboot_load();
123 invoke_init_function(on_postboot);
125 twifs_register_plugins();
127 if (!mount_bootmedium()) {
128 ERROR("failed to boot");
132 // FIXME Re-design needed!!
135 assert(!spawn_process(NULL, (ptr_t)lunad_do_usr, true));