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>
14 #include <klibc/string.h>
29 if (!kcmd_get_option("rootfs", &rootfs)) {
34 if ((errno = vfs_walk(NULL, rootfs, &dn, NULL, 0))) {
35 ERROR("%s: no such file (%d)", rootfs, errno);
39 dev = resolve_device(dn->inode->data);
41 ERROR("%s: not a device", rootfs);
45 // unmount the /dev to put old root fs in clear
46 must_success(vfs_unmount("/dev"));
48 // re-mount the root fs with our device.
49 if ((errno = vfs_mount_root(NULL, dev))) {
50 ERROR("mount root failed: %s (%d)", rootfs, errno);
61 const char* argv[] = { "/init", 0 };
62 const char* envp[] = { 0 };
64 kcmd_get_option("init", (char**)&argv[0]);
66 if ((errno = exec_kexecve(argv[0], argv, envp))) {
70 fail("should not reach");
73 ERROR("fail to load initd. (%d)", errno);
79 // No, these are not preemptive
83 fail("failed to initd");
88 * @brief LunaixOS的内核进程,该进程永远为可执行。
90 * 这主要是为了保证调度器在没有进程可调度时依然有事可做。
92 * 同时,该进程也负责fork出我们的init进程。
98 spawn_kthread((ptr_t)init_platform);
101 NOTE Kernel preemption after this point.
103 More specifically, it is not a real kernel preemption (as in preemption
104 happened at any point of kernel, except those marked explicitly).
105 In Lunaix, things are designed in an non-preemptive fashion, we implement
106 kernel preemption the other way around: only selected kernel functions which,
107 of course, with great care of preemptive assumption, will goes into kernel
108 thread (which is preemptive!)
114 cleanup_detached_threads();
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));