#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static const char zinnia_banner[] = "Zinnia " ZINNIA_VERSION " " CONFIG_KERNEL_FLAVOR " (" ZINNIA_ARCH ", " ZINNIA_COMPILER_ID ", " ZINNIA_LINKER_ID ")"; static void kernel_main_task(uintptr_t arg0) { errno_t status = 0; struct boot_info* info = (struct boot_info*)arg0; log("main: Hello from main task!\n"); // Finish the initgraph. initgraph_run(nullptr, info); // TODO: Try to run init. assert(info->num_files >= 1, "No init executable provided"); struct vma* init_space; assert(vma_new(&init_space) == 0, ""); struct boot_file* file_data = &info->files[0]; struct task* init_task = nullptr; struct paged_vmo* init_file; status = vmo_new_phys(&init_file); assert(status == 0, "Failed to allocate a memory object"); vmo_write(&init_file->object, 0, HHDM_PTR(file_data->data), file_data->length, nullptr); // Load init. const char* init_argv[] = {"init", nullptr}; const char* init_envp[] = {nullptr}; struct exec_info exec = { .space = init_space, .file_obj = &init_file->object, .argv = init_argv, .envp = init_envp, }; status = elf_load(&exec, &init_task); vmo_unref(&init_file->object); assert(status == 0, "Failed to load init process (%i)", status); sched_add_task(&percpu_get()->sched, init_task); while (true) { irq_wait(); } } [[__init]] void kernel_early_init() { percpu_bsp_init(); percpu_get()->online = true; irq_lock(); } [[noreturn]] void kernel_main(struct boot_info* info) { cmdline_parse(info->cmdline); log("%s\n", zinnia_banner); // Say hello! log("Command line: %s\n", info->cmdline); initgraph_run(sched_stage, info); struct task* main_task; task_create("main", &kernel_vma, kernel_main_task, (uintptr_t)info, &main_task); sched_add_task(&percpu_get()->sched, main_task); irq_unlock(); sched_yield(&percpu_get()->sched); unreachable(); }