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/pcontext.h>
21 #include <hal/acpi/acpi.h>
25 #include <sys/mm/mm_defs.h>
27 #include <klibc/strfmt.h>
28 #include <klibc/string.h>
34 kmem_init(struct boot_handoff* bhctx);
37 kernel_bootstrap(struct boot_handoff* bhctx)
42 // now we can start reserving physical space
44 /* Begin kernel bootstrapping sequence */
47 tty_init(ioremap(0xB8000, PAGE_SIZE));
49 /* Setup kernel memory layout and services */
52 // FIXME this goes to hal/gfxa
53 tty_set_theme(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
55 boot_parse_cmdline(bhctx);
57 /* Prepare stack trace environment */
58 trace_modksyms_init(bhctx);
60 device_scan_drivers();
62 invoke_init_function(on_earlyboot);
64 device_sysconf_load();
66 /* Get intc online, this is the cornerstone when initing devices */
73 TODO autoload these init function that do not have dependency between
77 /* Let's get fs online as soon as possible, as things rely on them */
86 /* the bare metal are now happy, let's get software over with */
88 must_success(vfs_mount_root("ramfs", NULL));
89 must_success(vfs_mount("/dev", "devfs", NULL, 0));
91 invoke_init_function(on_boot);
93 must_success(vfs_unmount("/dev"));
95 /* Finish up bootstrapping sequence, we are ready to spawn the root process
96 * and start geting into uspace
108 * @brief 创建并运行Lunaix守护进程
115 struct thread* kthread;
117 has_error = spawn_process(&kthread, (ptr_t)lunad_main, false);
118 assert_msg(!has_error, "failed to spawn lunad");
122 fail("Unexpected Return");
126 kmem_init(struct boot_handoff* bhctx)
128 pte_t* ptep = mkptep_va(VMS_SELF, KERNEL_RESIDENT);
129 ptep = mkl0tep(ptep);
133 assert(mkl1t(ptep++, 0, KERNEL_DATA));
135 assert(mkl2t(ptep++, 0, KERNEL_DATA));
137 assert(mkl3t(ptep++, 0, KERNEL_DATA));
139 assert(mklft(ptep++, 0, KERNEL_DATA));
141 } while (ptep_vfn(ptep) < MAX_PTEN - 2);