1 #include <lunaix/types.h>
2 #include <lunaix/block.h>
3 #include <lunaix/boot_generic.h>
4 #include <lunaix/device.h>
5 #include <lunaix/foptions.h>
6 #include <lunaix/fs/twifs.h>
7 #include <lunaix/input.h>
8 #include <lunaix/mm/cake.h>
9 #include <lunaix/mm/mmio.h>
10 #include <lunaix/mm/pmm.h>
11 #include <lunaix/mm/valloc.h>
12 #include <lunaix/mm/vmm.h>
13 #include <lunaix/process.h>
14 #include <lunaix/sched.h>
15 #include <lunaix/spike.h>
16 #include <lunaix/trace.h>
17 #include <lunaix/tty/tty.h>
18 #include <lunaix/owloysius.h>
19 #include <lunaix/hart_state.h>
21 #include <hal/acpi/acpi.h>
24 #include <sys/mm/mm_defs.h>
26 #include <klibc/strfmt.h>
27 #include <klibc/string.h>
33 kmem_init(struct boot_handoff* bhctx);
36 kernel_bootstrap(struct boot_handoff* bhctx)
41 // now we can start reserving physical space
43 /* Begin kernel bootstrapping sequence */
46 tty_init(ioremap(0xB8000, PAGE_SIZE));
48 /* Setup kernel memory layout and services */
51 // FIXME this goes to hal/gfxa
52 tty_set_theme(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
54 boot_parse_cmdline(bhctx);
56 /* Prepare stack trace environment */
57 trace_modksyms_init(bhctx);
59 device_scan_drivers();
61 device_sysconf_load();
63 invoke_init_function(on_earlyboot);
69 TODO autoload these init function that do not have dependency between
73 /* Let's get fs online as soon as possible, as things rely on them */
82 /* the bare metal are now happy, let's get software over with */
84 must_success(vfs_mount_root("ramfs", NULL));
85 must_success(vfs_mount("/dev", "devfs", NULL, 0));
87 invoke_init_function(on_boot);
89 must_success(vfs_unmount("/dev"));
91 /* Finish up bootstrapping sequence, we are ready to spawn the root process
92 * and start geting into uspace
104 * @brief 创建并运行Lunaix守护进程
111 struct thread* kthread;
113 has_error = spawn_process(&kthread, (ptr_t)lunad_main, false);
114 assert_msg(!has_error, "failed to spawn lunad");
118 fail("Unexpected Return");
122 kmem_init(struct boot_handoff* bhctx)
124 pte_t* ptep = mkptep_va(VMS_SELF, KERNEL_RESIDENT);
125 ptep = mkl0tep(ptep);
129 assert(mkl1t(ptep++, 0, KERNEL_DATA));
131 assert(mkl2t(ptep++, 0, KERNEL_DATA));
133 assert(mkl3t(ptep++, 0, KERNEL_DATA));
135 assert(mklft(ptep++, 0, KERNEL_DATA));
137 } while (ptep_vfn(ptep) < MAX_PTEN - 2);