void ctx_load_program(struct context *ctx, const char *name, const char *vertpath, const char *fragpath) { struct program *p = program_load(name, vertpath, fragpath); if (! p) fatalf("ctx", "failed to load program '%s'", name); ctx_setup_program(ctx, p); list_push(&ctx->programs, p); }
static bool compile_package(const char* path, pass_opt_t* opt, bool print_program_ast, bool print_package_ast) { ast_t* program = program_load(path, opt); if(program == NULL) return false; if(print_program_ast) ast_fprint(stderr, program); if(print_package_ast) ast_fprint(stderr, ast_child(program)); bool ok = generate_passes(program, opt); ast_free(program); return ok; }
int syscall_pgm_load(char *filename, int type) { return program_load(filename, type); }
int32_t execute(const uint8_t* command) { pcb_t* previous_pcb = curr_process; char* cmd = (char*)command; uint8_t* fname = (uint8_t*)parse(cmd); get_arg((char *)command, (int)strlen(cmd)); /* Looking for processes */ uint8_t process_mask = MASK; // Calculating the process mask, which keeps track of open processes. Here we search for a 0 in the mask // and set it to 1, giving the index in the bitmap to process_id int i = 0; for(i = 0; i < 7; i++) { if((process_mask & open_processes) == 0) { open_processes |= process_mask; process_id = i; break; } else process_mask >>= 1; } // if(num_processes + 1 > 2) // { // cout("PROCESS LIMIT EXCEEDED. NOT ALLOWED TO EXECUTE\n"); // //num_processes--; // sti(); // asm volatile("jmp ret_halt"); // } // Check if(i == 7) { printf("Too many processes!\n"); return 1; } /* Executable check */ uint8_t elf_check[4]; dentry_t dentry_temp; if(-1 == read_dentry_by_name(fname, &dentry_temp)) { return -1; } if(-1 == read_data(dentry_temp.inode_num, 0, elf_check, 4)) { return -1; } if(!(elf_check[0] == 0x7f && elf_check[1] == 0x45 && elf_check[2] == 0x4c && elf_check[3] == 0x46)) { return -1; } /* Find the address of the file's first instruction */ uint8_t buf_temp[4]; if(-1 == read_data(dentry_temp.inode_num, 24, buf_temp, 4)) { return -1; } int k = 0; uint32_t entry_addr = 0; for(k = 0; k < 4; k++) entry_addr |= (buf_temp[k] << 8*k); /* Set up paging */ PDE_t* PD_ptr = task_mem_init(process_id); if(PD_ptr == NULL) { printf("Too many processes!\n"); return 1; } // Load program image into memory if(-1 == program_load(fname, PGRM_IMG)) { return -1; } k_bp = _8MB - (_8KB)*(process_id) - 4; curr_process = (pcb_t *) (k_bp & 0xFFFFE000); // k_bp = _8MB - (_8KB)*(process_id); // curr_process = (pcb_t *) ((k_bp - 1) & 0xFFFFE000); curr_process->process_id = process_id; curr_process->PD_ptr = PD_ptr; curr_process->k_bp = k_bp; curr_process->k_sp = k_bp; // If initial shell, case should be handeled by making parent process the same shell if(initial_shell) { curr_process->parent_process = curr_process; curr_process->child_flag = 0; curr_process->parent_process->child = -1; initial_shell = 0; } else { curr_process->parent_process = previous_pcb; curr_process->parent_process->child_flag = 1; curr_process->parent_process->child = process_id; } // Initialize file descriptors for(i = 0; i < 8; i++) { curr_process->file_fds[i].file_op = NULL; curr_process->file_fds[i].inode_ptr = NULL; curr_process->file_fds[i].file_pos = 0; curr_process->file_fds[i].flags = 0; } task_queue[next_available] = process_id; next_available = (next_available + 1) % 7; stdin(0); //kernel should automatically open stdin and stdout stdout(1); //which correspond to fd 0 and 1 respectively task_queue[next_available] = process_id; next_available = (next_available + 1) % 7; // Setting TSS tss.esp0 = curr_process->k_sp; // This is good code tss.ss0 = KERNEL_DS; if(previous_pcb != NULL) { asm volatile("movl %%esp, %0":"=g"(previous_pcb->k_sp)); asm volatile("movl %%ebp, %0":"=g"(previous_pcb->k_bp)); } // Jump to program and being executions jump_to_userspace(entry_addr); // Halt jumps here for finishing execute asm volatile("ret_halt:\n\t"); return retval; }
int inventory_load_programs(void) { bool success = false; DIR *dp; struct dirent *dirent; const char *identifier; char directory[1024]; char filename[1024]; APIE error_code; log_debug("Loading program configurations from '%s'", _programs_directory); dp = opendir(_programs_directory); if (dp == NULL) { if (errno == ENOENT) { // no programs directory, nothing to load return 0; } log_error("Could not open programs directory '%s': %s (%d)", _programs_directory, get_errno_name(errno), errno); return -1; } for (;;) { errno = 0; dirent = readdir(dp); if (dirent == NULL) { if (errno == 0) { // end-of-directory reached break; } else { log_error("Could not get next entry of programs directory '%s': %s (%d)", _programs_directory, get_errno_name(errno), errno); goto cleanup; } } if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0 || dirent->d_type != DT_DIR) { continue; } identifier = dirent->d_name; if (robust_snprintf(directory, sizeof(directory), "%s/%s", _programs_directory, identifier) < 0) { log_error("Could not format program directory name: %s (%d)", get_errno_name(errno), errno); goto cleanup; } if (robust_snprintf(filename, sizeof(filename), "%s/program.conf", directory) < 0) { log_error("Could not format program config file name: %s (%d)", get_errno_name(errno), errno); goto cleanup; } log_debug("Loading program from '%s'", directory); error_code = program_load(identifier, directory, filename); if (error_code != API_E_SUCCESS) { // load errors are non-fatal log_debug("Could not load program from '%s', ignoring program: %s (%d)", directory, api_get_error_code_name(error_code), error_code); } } success = true; cleanup: closedir(dp); return success ? 0 : -1; }