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)
39 pmm_init(bhctx->mem.size);
42 /* Begin kernel bootstrapping sequence */
45 /* Setup kernel memory layout and services */
48 boot_parse_cmdline(bhctx);
50 /* Prepare stack trace environment */
51 trace_modksyms_init(bhctx);
53 device_scan_drivers();
55 invoke_init_function(on_earlyboot);
57 // FIXME this goes to hal/gfxa
58 tty_init(ioremap(0xB8000, PAGE_SIZE));
59 tty_set_theme(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
61 device_sysconf_load();
63 /* Get intc online, this is the cornerstone when initing devices */
70 TODO autoload these init function that do not have dependency between
74 /* Let's get fs online as soon as possible, as things rely on them */
83 /* the bare metal are now happy, let's get software over with */
85 must_success(vfs_mount_root("ramfs", NULL));
86 must_success(vfs_mount("/dev", "devfs", NULL, 0));
88 invoke_init_function(on_boot);
90 must_success(vfs_unmount("/dev"));
92 /* Finish up bootstrapping sequence, we are ready to spawn the root process
93 * and start geting into uspace
105 * @brief 创建并运行Lunaix守护进程
112 struct thread* kthread;
114 has_error = spawn_process(&kthread, (ptr_t)lunad_main, false);
115 assert_msg(!has_error, "failed to spawn lunad");
119 fail("Unexpected Return");
123 kmem_init(struct boot_handoff* bhctx)
125 extern u8_t __kexec_end;
126 // 将内核占据的页,包括前1MB,hhk_init 设为已占用
127 size_t pg_count = leaf_count((ptr_t)&__kexec_end - KERNEL_RESIDENT);
128 pmm_mark_chunk_occupied(0, pg_count, PP_FGLOCKED);
130 pte_t* ptep = mkptep_va(VMS_SELF, KERNEL_RESIDENT);
131 ptep = mkl0tep(ptep);
135 assert(mkl1t(ptep++, 0, KERNEL_DATA));
137 assert(mkl2t(ptep++, 0, KERNEL_DATA));
139 assert(mkl3t(ptep++, 0, KERNEL_DATA));
141 assert(mklft(ptep++, 0, KERNEL_DATA));
143 } while (ptep_vfn(ptep) < MAX_PTEN - 2);