#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void spawn_lunad(); void kmem_init(struct boot_handoff* bhctx); void kernel_bootstrap(struct boot_handoff* bhctx) { pmm_init(bhctx->mem.size); vmm_init(); /* Begin kernel bootstrapping sequence */ boot_begin(bhctx); /* Setup kernel memory layout and services */ kmem_init(bhctx); boot_parse_cmdline(bhctx); /* Prepare stack trace environment */ trace_modksyms_init(bhctx); device_scan_drivers(); invoke_init_function(on_earlyboot); // FIXME this goes to hal/gfxa tty_init(ioremap(0xB8000, PG_SIZE)); tty_set_theme(VGA_COLOR_WHITE, VGA_COLOR_BLACK); device_sysconf_load(); /* Get intc online, this is the cornerstone when initing devices */ intc_init(); clock_init(); timer_init(); /* TODO autoload these init function that do not have dependency between them */ /* Let's get fs online as soon as possible, as things rely on them */ vfs_init(); fsm_init(); input_init(); block_init(); sched_init(); device_onboot_load(); /* the bare metal are now happy, let's get software over with */ must_success(vfs_mount_root("ramfs", NULL)); must_success(vfs_mount("/dev", "devfs", NULL, 0)); invoke_init_function(on_boot); must_success(vfs_unmount("/dev")); /* Finish up bootstrapping sequence, we are ready to spawn the root process * and start geting into uspace */ boot_end(bhctx); spawn_lunad(); } extern void lunad_main(); /** * @brief 创建并运行Lunaix守护进程 * */ void spawn_lunad() { int has_error; struct thread* kthread; has_error = spawn_process(&kthread, (ptr_t)lunad_main, false); assert_msg(!has_error, "failed to spawn lunad"); run(kthread); fail("Unexpected Return"); } void kmem_init(struct boot_handoff* bhctx) { extern u8_t __kexec_end; // 将内核占据的页,包括前1MB,hhk_init 设为已占用 size_t pg_count = ((ptr_t)&__kexec_end - KERNEL_EXEC) >> PG_SIZE_BITS; pmm_mark_chunk_occupied(0, pg_count, PP_FGLOCKED); // reserve higher half for (size_t i = L1_INDEX(KERNEL_EXEC); i < 1023; i++) { assert(vmm_set_mapping(VMS_SELF, i << 22, 0, 0, VMAP_NOMAP)); } // allocators cake_init(); valloc_init(); }