/*======================================================================* kernel_main *======================================================================*/ PUBLIC int kernel_main() { clear_screen(); loadELF(); TASK* p_task = task_table; PROCESS* p_proc = proc_table; char* p_task_stack = task_stack + STACK_SIZE_TOTAL; u16 selector_ldt = SELECTOR_LDT_FIRST; int i,priority; proc_table[0].ticks = proc_table[0].pre_ticks=proc_table[0].priority = 20; proc_table[0].status = RUNNING; init_task(proc_table,task_table,SELECTOR_LDT_FIRST,p_task_stack,20,RUNNING); for (i=1; i<NR_TASKS; i++){ proc_table[i].pid=i+1; proc_table[i].status=STOPPED; task_table[i].stacksize=0x400; } control_ticks(); k_reenter=0; ticks=0; p_proc_ready=proc_table; init_clock(); init_keyboard(); restart(); while(1){} }
int main(int argc, char **argv, char **envp) { struct ELF_File *f; void **newstack; int i, envc; if (argc < 2) { fprintf(stderr, "Use: elfload <elf file> [arguments]\n"); return 1; } /* load them all in */ f = loadELF(argv[1]); /* initialize .so files */ initELF(f); /* make its stack */ for (envc = 0; envp[envc]; envc++); newstack = (void**) alloca((argc + envc + 2) * sizeof(void*)); newstack[0] = (void*) (argc - 1); for (i = 1; i < argc; i++) { newstack[i] = (void*) argv[i]; } newstack[i] = NULL; for (i = 0; i < envc; i++) { newstack[i+argc+1] = (void*) envp[i]; } newstack[i+argc+1] = NULL; /* and call it */ WITHSTACK_JMP(newstack, f->ehdr->e_entry + f->offset); }
void *elfload_dlopen(const char *filename, int flag) { /* pretty simple, just load based on the file name */ struct ELF_File *f = loadELF(filename, elfload_dlinstdir, 0); if (f == NULL) { dlLastError = "Could not find or load file."; } return (void *) f; }
int main(int argc, char **argv, char **envp) { struct ELF_File *f; void **newstack; int i, envc, progarg; char *dir, *fil; int maybe = 0; progarg = -1; for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { if (!strcmp(argv[i], "-m")) { maybe = 1; } else if (!strcmp(argv[i], "--")) { progarg = i + 1; break; } } else { progarg = i; break; } } if (progarg == -1) { fprintf(stderr, "Use: elfload [-m] <elf file> [arguments]\n"); return 1; } whereAmI(argv[0], &dir, &fil); elfload_dlinstdir = dir; /* load them all in */ f = loadELF(argv[progarg], dir, maybe); if (!f) { /* try just execing it */ execv(argv[progarg], argv + progarg); fprintf(stderr, "Failed to load %s.\n", argv[progarg]); return 1; } /* relocate them */ relocateELFs(); /* initialize .so files */ initELF(f); /* make its stack */ for (envc = 0; envp[envc]; envc++); newstack = (void**) alloca((argc + envc + 2) * sizeof(void*)); newstack[0] = (void*) (size_t) (argc - progarg); for (i = progarg; i < argc; i++) { newstack[i - progarg + 1] = (void*) argv[i]; } newstack[i - progarg + 1] = NULL; for (i = 0; i < envc; i++) { newstack[i-progarg+argc+2] = (void*) envp[i]; } newstack[i-progarg+argc+2] = NULL; /* and call it */ WITHSTACK_JMP(newstack, f->ehdr->e_entry + f->offset); }