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/input.h>
7 #include <lunaix/mm/cake.h>
8 #include <lunaix/mm/pmm.h>
9 #include <lunaix/mm/page.h>
10 #include <lunaix/mm/valloc.h>
11 #include <lunaix/mm/vmm.h>
12 #include <lunaix/process.h>
13 #include <lunaix/sched.h>
14 #include <lunaix/spike.h>
15 #include <lunaix/trace.h>
16 #include <lunaix/owloysius.h>
17 #include <lunaix/hart_state.h>
18 #include <lunaix/syslog.h>
19 #include <lunaix/sections.h>
21 #include <hal/acpi/acpi.h>
22 #include <hal/devtree.h>
25 #include <sys/mm/mm_defs.h>
27 #include <klibc/strfmt.h>
28 #include <klibc/string.h>
36 * @brief 创建并运行Lunaix守护进程
43 struct thread* kthread;
45 has_error = spawn_process(&kthread, (ptr_t)lunad_main, false);
46 assert_msg(!has_error, "failed to spawn lunad");
50 fail("Unexpected Return");
54 kmem_init(struct boot_handoff* bhctx)
56 pte_t* ptep = mkptep_va(VMS_SELF, KERNEL_RESIDENT);
60 unsigned int i = ptep_vfn(ptep);
62 if (l0tep_implie_vmnts(ptep)) {
68 assert(mkl1t(ptep++, 0, KERNEL_PGTAB));
70 assert(mkl2t(ptep++, 0, KERNEL_PGTAB));
72 assert(mkl3t(ptep++, 0, KERNEL_PGTAB));
74 assert(mklft(ptep++, 0, KERNEL_PGTAB));
76 } while (++i < MAX_PTEN);
84 __remap_and_load_dtb(struct boot_handoff* bhctx)
86 #ifdef CONFIG_USE_DEVICETREE
87 ptr_t dtb = bhctx->kexec.dtb_pa;
94 WARN("bad-aligned dtb location, expect page aligned");
102 pte = mkpte(dtb, KERNEL_DATA);
103 ptep = mkptep_va(VMS_SELF, dtb_start);
104 nr_pages = leaf_count(CONFIG_DTB_MAXSIZE);
106 pmm_onhold_range(dtb, nr_pages);
107 vmm_set_ptes_contig(ptep, pte, PAGE_SIZE, nr_pages);
109 loaded = dt_load(dtb_start);
111 ERROR("dtb load failed");
119 kernel_bootstrap(struct boot_handoff* bhctx)
124 // now we can start reserving physical space
126 /* Begin kernel bootstrapping sequence */
129 /* Setup kernel memory layout and services */
132 __remap_and_load_dtb(bhctx);
134 boot_parse_cmdline(bhctx);
136 /* Prepare stack trace environment */
137 trace_modksyms_init(bhctx);
139 device_scan_drivers();
141 device_sysconf_load();
143 invoke_init_function(on_earlyboot);
149 TODO autoload these init function that do not have dependency between
153 /* Let's get fs online as soon as possible, as things rely on them */
160 device_onboot_load();
162 /* the bare metal are now happy, let's get software over with */
164 must_success(vfs_mount_root("ramfs", NULL));
165 must_success(vfs_mount("/dev", "devfs", NULL, 0));
167 invoke_init_function(on_boot);
169 /* Finish up bootstrapping sequence, we are ready to spawn the root process
170 * and start geting into uspace