1 #include <lunaix/types.h>
2 #include <lunaix/block.h>
3 #include <lunaix/boot_generic.h>
4 #include <lunaix/device.h>
5 #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>
13 #include <lunaix/process.h>
14 #include <lunaix/sched.h>
15 #include <lunaix/spike.h>
16 #include <lunaix/trace.h>
17 #include <lunaix/owloysius.h>
18 #include <lunaix/hart_state.h>
19 #include <lunaix/syslog.h>
20 #include <lunaix/sections.h>
22 #include <hal/devtree.h>
24 #include <asm/mm_defs.h>
32 * @brief 创建并运行Lunaix守护进程
39 struct thread* kthread;
41 has_error = spawn_process(&kthread, (ptr_t)lunad_main, false);
42 assert_msg(!has_error, "failed to spawn lunad");
46 fail("Unexpected Return");
50 kmem_init(struct boot_handoff* bhctx)
52 pte_t* ptep = mkptep_va(VMS_SELF, KERNEL_RESIDENT);
56 unsigned int i = ptep_vfn(ptep);
58 if (lntep_implie_vmnts(ptep, L0T_SIZE)) {
64 assert(mkl1t(ptep++, 0, KERNEL_PGTAB));
66 assert(mkl2t(ptep++, 0, KERNEL_PGTAB));
68 assert(mkl3t(ptep++, 0, KERNEL_PGTAB));
70 assert(mklft(ptep++, 0, KERNEL_PGTAB));
72 } while (++i < MAX_PTEN);
80 __remap_and_load_dtb(struct boot_handoff* bhctx)
82 #ifdef CONFIG_USE_DEVICETREE
83 ptr_t dtb = bhctx->kexec.dtb_pa;
90 WARN("bad-aligned dtb location, expect page aligned");
98 pte = mkpte(dtb, KERNEL_DATA);
99 ptep = mkptep_va(VMS_SELF, dtb_start);
100 nr_pages = leaf_count(CONFIG_DTB_MAXSIZE);
102 pmm_onhold_range(dtb, nr_pages);
103 vmm_set_ptes_contig(ptep, pte, PAGE_SIZE, nr_pages);
105 loaded = dt_load(dtb_start);
107 ERROR("dtb load failed");
115 kernel_bootstrap(struct boot_handoff* bhctx)
118 // now we can start reserving physical space
120 /* Begin kernel bootstrapping sequence */
123 /* Setup kernel memory layout and services */
126 __remap_and_load_dtb(bhctx);
128 boot_parse_cmdline(bhctx);
130 /* Prepare stack trace environment */
131 trace_modksyms_init(bhctx);
133 device_scan_drivers();
135 device_sysconf_load();
137 invoke_init_function(on_earlyboot);
143 TODO autoload these init function that do not have dependency between
147 /* Let's get fs online as soon as possible, as things rely on them */
154 device_onboot_load();
156 /* the bare metal are now happy, let's get software over with */
158 must_success(vfs_mount_root("ramfs", NULL));
159 must_success(vfs_mount("/dev", "devfs", NULL, 0));
161 invoke_init_function(on_boot);
163 /* Finish up bootstrapping sequence, we are ready to spawn the root process
164 * and start geting into uspace