/** @brief Wait fss in dds */ static int fss_ops_wait() { /* Just yield current thread, giving other a chance */ kt_schedule(); //TODO: test thread dieing... return 0; }
void __init __noreturn hal_main() { /* 开辟鸿蒙,谁为情种?最初的一切*/ km_cluster_init(); build_ram_list(); /* Go back to ARCH, we have inited the basic paging allocator */ hal_arch_init(HAL_ARCH_INIT_PHASE_EARLY); /* KERNEL */ kc_init(); kp_init(); ks_init(); hal_malloc_init(); hal_dpc_init(); hal_time_init(); hal_arch_init(HAL_ARCH_INIT_PHASE_MIDDLE); hal_console_init(); printk("GridOS 启动中...\n"); ke_module_entry(); local_irq_enable(); /* Driver pakcage loading, and it must be the last file */ hal_boot_module_loop(start_driver_ctx); if (last_package_id == driver_package_id && driver_pakcage) { ke_startup_driver_process(driver_pakcage, driver_size); } else { if (driver_size) printk("Driver package is not the last one, BSS in it may overlay the useful file data after it..."); else printk("No driver package was loaded..."); } printk("Hal startup ok.\n"); kernel_test(); while (1) { kt_schedule_driver(); /* If have no process, sleep */ if (!kt_schedule_running_count()) dumy_idle_ops(0); else kt_schedule(); } }
static void file_thread(void *para) { struct file_process_startup_para *package = para; printk("File thread startup, startup file %x, size %d, ks addr %x...", package->data, package->size, package->ks_start); memcpy((void*)package->ks_start, package->data, package->size); package->data = NULL; printk("Copy ok.\n"); while(1) { kt_schedule(); } }
/** @brief run startup process */ void ke_run_first_user_process(void *data, int size, char *cmdline) { char *first_space, first_exe_name[128] = {0}; struct ko_section *ks; void *entry_address; struct ko_exe *kee, *ke_tmp = kp_exe_create_temp(); first_space = strchr(cmdline, ' '); if (!first_space) goto err; if (first_space - cmdline >= sizeof(first_exe_name) - sizeof(xchar)) goto err; strncpy(first_exe_name, cmdline, first_space - cmdline); /* Kernel file process, because early we cannot copy lv2 table of driver */ kernel_file_process = kp_create(KP_CPL0_FAKE, "操作系统文件进程"); if (!kernel_file_process) goto err; printk("启动用户第一个可执行文件%x, size %d.\n", data, size); if (size == 0/*no file*/ || size == 1/*buffer error*/) goto err; if (elf_analyze(data, size, &entry_address, KO_EXE_TO_PRIVATE(ke_tmp)) == false) goto err; ks = ks_create(kp_get_file_process(), KS_TYPE_PRIVATE, 0, size, KM_PROT_READ|KM_PROT_WRITE); if (!ks) goto err; kee = kp_exe_create_from_file(first_exe_name, ks, KO_EXE_TO_PRIVATE(ke_tmp), entry_address); if (!kee) goto err; /* But this is a special one, we have to fill the data on it */ do { struct kt_thread_creating_context ctx = {0}; struct file_process_startup_para package; package.ks_start = ks->node.start; package.size = size; package.data = data; ctx.thread_entry = file_thread; ctx.flags = KT_CREATE_RUN; ctx.para = (unsigned long)&package; if (kt_create(kernel_file_process, &ctx) == NULL) goto err; /* Wait it to finish */ while (package.data) kt_schedule(); } while(0); /* OK, create the process */ if (kp_run_user(kee, ++first_space/*Real application*/) == false) goto err; return; err: printk("启动第一可执行文件失败。\n"); }
static void goto_idle() { kt_schedule(); }
void __noreturn kt_delete_current() { //TODO TODO(""); while (1) kt_schedule(); }