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/page.h>
11 #include <lunaix/mm/pmm.h>
12 #include <lunaix/mm/valloc.h>
13 #include <lunaix/mm/vmm.h>
14 #include <lunaix/process.h>
15 #include <lunaix/sched.h>
16 #include <lunaix/spike.h>
17 #include <lunaix/trace.h>
18 #include <lunaix/tty/tty.h>
19 #include <lunaix/owloysius.h>
20 #include <lunaix/pcontext.h>
22 #include <hal/acpi/acpi.h>
26 #include <sys/mm/mempart.h>
28 #include <klibc/strfmt.h>
29 #include <klibc/string.h>
35 kmem_init(struct boot_handoff* bhctx);
38 kernel_bootstrap(struct boot_handoff* bhctx)
40 pmm_init(bhctx->mem.size);
43 /* Begin kernel bootstrapping sequence */
46 /* Setup kernel memory layout and services */
49 boot_parse_cmdline(bhctx);
51 /* Prepare stack trace environment */
52 trace_modksyms_init(bhctx);
54 device_scan_drivers();
56 invoke_init_function(on_earlyboot);
58 // FIXME this goes to hal/gfxa
59 tty_init(ioremap(0xB8000, PG_SIZE));
60 tty_set_theme(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
62 device_sysconf_load();
64 /* Get intc online, this is the cornerstone when initing devices */
71 TODO autoload these init function that do not have dependency between
75 /* Let's get fs online as soon as possible, as things rely on them */
84 /* the bare metal are now happy, let's get software over with */
86 must_success(vfs_mount_root("ramfs", NULL));
87 must_success(vfs_mount("/dev", "devfs", NULL, 0));
89 invoke_init_function(on_boot);
91 must_success(vfs_unmount("/dev"));
93 /* Finish up bootstrapping sequence, we are ready to spawn the root process
94 * 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 = ((ptr_t)&__kexec_end - KERNEL_EXEC) >> PG_SIZE_BITS;
128 pmm_mark_chunk_occupied(0, pg_count, PP_FGLOCKED);
130 // reserve higher half
131 for (size_t i = L1_INDEX(KERNEL_EXEC); i < 1023; i++) {
132 assert(vmm_set_mapping(VMS_SELF, i << 22, 0, 0, VMAP_NOMAP));