process* create_child_process(process* parent){ void *addr = k_malloc(sizeof(process)); process* child = addr; child->self_memory = (uint64_t)addr; child->pid = get_process_id(); child->ppid = parent->pid; child->timer_val = 0; child->state = TASK_INTERRUPTIBLE; child->memory = NULL; child->pp = parent; child->p_cache = 0; child->kernel_stack = k_malloc_stack(4095); clear_registers(child->reg); child->cr3 = create_user_process_table(); child->memory = create_mm_object(child); copy_vma(parent,child); copy_fdtable(parent,child); //child->fdtable = parent->fdtable; child->maxfd = parent->maxfd; copy_memory(parent,child); set_COW_bits(child,parent); child->start_exec = parent->start_exec; copy_registers(child,parent); strcpy(parent->p_name,child->p_name); child->env_set =0; refresh_cr3(); return child; }
void create_init_process() { process *p = k_malloc(sizeof(process)); p->pid = process_id; p->ppid = process_id; process_id += 1; p->timer_val =0; p->state = TASK_INTERRUPTIBLE; p->memory = NULL; p->kernel_stack = k_malloc_stack(4095); clear_registers(p->reg); p->cr3 = create_process_page_table(); p->fdtable = k_malloc(sizeof(fd_obj)*50); p->maxfd=2; //0,1,2 are reserved for stdin,stdout, and stderr respectively. p->fdtable[0].fileptr=NULL; p->fdtable[0].file_offset=0; p->fdtable[0].flags=O_RDONLY; //std input is read only p->fdtable[0].filetype='S'; //standard i/o p->fdtable[1].fileptr=NULL; p->fdtable[1].file_offset=0; p->fdtable[1].flags=O_WRONLY; //std output is write only p->fdtable[1].filetype='S'; //standard i/o tarfs_init("bin/init_process",p); //tarfs_init("bin/sbush",p); create_STACK_memory(p->memory,U_STACK); memcpy("bin/init_process",p->p_name,50); //////print("Working === %x",p->kernel_stack); //////print("Process created with id = %d ",p->pid); // run_process(p); init_process = p; }
//Here we should make the call, and if we are saving the result, tell the regdesc that void code_call(FILE *file, RegDesc *registers, Symbol *function, Symbol *result) { code_spill_all(file, registers); clear_registers(registers); if (function->external != NULL) { //If this is printf, push the appropriate string if (strcmp(function->external, "printf") == 0) { arg_count++; code_instruction(file, PUSH, "$.LC0", NULL); } //This an external call, so drop the instruction using the linked name code_instruction(file, CALL, function->external, NULL); } else { //This is an internal routine //Therefore, we need to set up the static link int caller_nested = current_scope->symbols->nested; int callee_nested = function->symbols->nested; debug("Static Linking - Caller: %d to Callee: %d", caller_nested, callee_nested); if (caller_nested < callee_nested) { //This is one hop, so we can Load address code_instruction(file, LOAD_ADDRESS, CURRENT_STATIC_LINK, EAX); code_instruction(file, MOVE, EAX, NEXT_STATIC_LINK); } else { code_instruction(file, MOVE, CURRENT_STATIC_LINK, EDI); int i; int hops = caller_nested - callee_nested + 1; for (i = 0; i < hops - 1; i++) code_instruction(file, MOVE, make_relative_address(0, EDI), EDI); code_instruction(file, MOVE, EDI, NEXT_STATIC_LINK); } code_instruction(file, CALL, function->name, NULL); } //Clean up the stack if (arg_count > 0) { code_instruction(file, ADD, make_integer(arg_count * 4), ESP); arg_count = 0; } if (result != NULL) { //Return values are put in eax insert_register(registers, REG_EAX, result, TRUE); } }
void code_arg(FILE *file, RegDesc *registers, Symbol *result) { arg_count++; debug("Code_Arg - Symbol: %s, Arg Count: %d", symbol_to_string(result), arg_count); code_spill_all(file, registers); clear_registers(registers); if (result->type->code == TYPE_NATURAL) code_instruction(file, PUSH, make_integer(result->value.integer), NULL); else code_instruction(file, PUSH, get_location(file, registers, result), NULL); }
TEARDOWN() { int i; for(i = 0; i < lwin.list_rows; i++) free(lwin.dir_entry[i].name); free(lwin.dir_entry); for(i = 0; i < rwin.list_rows; i++) free(rwin.dir_entry[i].name); free(rwin.dir_entry); clear_registers(); }
process* create_process_new(process* pp,char* bin_file,int create_fd) { void *addr = k_malloc(sizeof(process)); process *p = addr; p->pid = process_id; process_id += 1; p->ppid = pp->pid; p->timer_val =0; p->state = TASK_INTERRUPTIBLE; p->memory = NULL; p->self_memory = (uint64_t)addr; p->pp= pp; clear_registers(p->reg); p->cr3 = create_user_process_table(); tarfs_init(bin_file,p); create_STACK_memory(p->memory,U_STACK); p->kernel_stack = k_malloc_stack(4095); p->env_set = 0; if(create_fd == 1) { p->fdtable = k_malloc(sizeof(fd_obj)*50); p->maxfd=2; //0,1,2 are reserved for stdin,stdout, and stderr respectively. p->fdtable[0].fileptr=NULL; p->fdtable[0].file_offset=0; p->fdtable[0].flags=O_RDONLY; //std input is read only p->fdtable[0].filetype='S'; //standard i/o p->fdtable[1].fileptr=NULL; p->fdtable[1].file_offset=0; p->fdtable[1].flags=O_WRONLY; //std output is write only p->fdtable[1].filetype='S'; //standard i/o } // uint64_t* a = (uint64_t*)p->kernel_stack; // a[0] = 24; //////print("Working === %x",p->kernel_stack); //////print("Process created with id = %d ",p->pid); // run_process(p); // //print("strlen = %d",strlen(bin_file)); // //print("bin_file = %s",bin_file); int size = strlen(bin_file); size = size > 50 ? 49:size; memcpy(bin_file,p->p_name,size); // //print("file name = %s",p->p_name); add_to_readyQ(p); return p; }
void generate_code(FILE *file, Tac *code, SymbolTable *programTable, SymbolTable *constantTable) { //Get our register descriptors RegDesc registers[REG_MAX]; Tac *current = code; //Clear registers name_registers(registers); clear_registers(registers); //Put our constant strings in the file code_strings(file, constantTable); while (current != NULL) { code_comment(file, "Current %d", current); code_tac(file, registers, current); current = current->next; } }
void code_jump(FILE *file, RegDesc *registers, char *op, Symbol *location, Symbol *condition) { debug("Code_Jump - Op: %s Location: %s Condition: %s", op, symbol_to_string(location), symbol_to_string(condition)); code_spill_all(file, registers); clear_registers(registers); //If there is a condition, compare it to 1 if (condition != NULL) { int dest_reg = get_result_register(file, registers, condition); int source_reg = get_argument_register(file, registers, symbol_one, dest_reg); debug("Dest %d Source %d", dest_reg, source_reg); //code_instruction(file, COMPARE, registers[source_reg].name, registers[dest_reg].name); code_instruction(file, COMPARE, registers[dest_reg].name, registers[source_reg].name); } code_flush_all(file, registers); //Output jump instruction code_instruction(file, op, location->name, NULL); }
/* * Free everything that we allocated. * Can be used to detect memory leaks, e.g., with ccmalloc. * NOTE: This is tricky! Things are freed that functions depend on. Don't be * surprised if Vim crashes... * Some things can't be freed, esp. things local to a library function. */ void free_all_mem(void) { buf_T *buf, *nextbuf; static int entered = FALSE; /* When we cause a crash here it is caught and Vim tries to exit cleanly. * Don't try freeing everything again. */ if (entered) return; entered = TRUE; block_autocmds(); /* don't want to trigger autocommands here */ /* Close all tabs and windows. Reset 'equalalways' to avoid redraws. */ p_ea = FALSE; if (first_tabpage->tp_next != NULL) do_cmdline_cmd((char_u *)"tabonly!"); if (firstwin != lastwin) do_cmdline_cmd((char_u *)"only!"); /* Free all spell info. */ spell_free_all(); /* Clear user commands (before deleting buffers). */ ex_comclear(NULL); /* Clear menus. */ do_cmdline_cmd((char_u *)"aunmenu *"); do_cmdline_cmd((char_u *)"menutranslate clear"); /* Clear mappings, abbreviations, breakpoints. */ do_cmdline_cmd((char_u *)"lmapclear"); do_cmdline_cmd((char_u *)"xmapclear"); do_cmdline_cmd((char_u *)"mapclear"); do_cmdline_cmd((char_u *)"mapclear!"); do_cmdline_cmd((char_u *)"abclear"); do_cmdline_cmd((char_u *)"breakdel *"); do_cmdline_cmd((char_u *)"profdel *"); do_cmdline_cmd((char_u *)"set keymap="); free_titles(); free_findfile(); /* Obviously named calls. */ free_all_autocmds(); clear_termcodes(); free_all_options(); free_all_marks(); alist_clear(&global_alist); free_homedir(); free_users(); free_search_patterns(); free_old_sub(); free_last_insert(); free_prev_shellcmd(); free_regexp_stuff(); free_tag_stuff(); free_cd_dir(); free_signs(); set_expr_line(NULL); diff_clear(curtab); clear_sb_text(); /* free any scrollback text */ /* Free some global vars. */ vim_free(last_cmdline); vim_free(new_last_cmdline); set_keep_msg(NULL, 0); /* Clear cmdline history. */ p_hi = 0; init_history(); { win_T *win; tabpage_T *tab; qf_free_all(NULL); /* Free all location lists */ FOR_ALL_TAB_WINDOWS(tab, win) qf_free_all(win); } /* Close all script inputs. */ close_all_scripts(); /* Destroy all windows. Must come before freeing buffers. */ win_free_all(); /* Free all buffers. Reset 'autochdir' to avoid accessing things that * were freed already. */ p_acd = FALSE; for (buf = firstbuf; buf != NULL; ) { nextbuf = buf->b_next; close_buffer(NULL, buf, DOBUF_WIPE, FALSE); if (buf_valid(buf)) buf = nextbuf; /* didn't work, try next one */ else buf = firstbuf; } free_cmdline_buf(); /* Clear registers. */ clear_registers(); ResetRedobuff(); ResetRedobuff(); /* highlight info */ free_highlight(); reset_last_sourcing(); free_tabpage(first_tabpage); first_tabpage = NULL; # ifdef UNIX /* Machine-specific free. */ mch_free_mem(); # endif /* message history */ for (;; ) if (delete_first_msg() == FAIL) break; eval_clear(); free_termoptions(); /* screenlines (can't display anything now!) */ free_screenlines(); clear_hl_tables(); vim_free(NameBuff); }
void code_flush_all(FILE *file, RegDesc *registers) { code_spill_all(file, registers); clear_registers(registers); }