WINDOW * openvmm(void) { if (symbols_read == 0) { symbols_read = 1; read_symbols(NULL); } if (kinfo_get_cpus(&vmm_ncpus)) err(1, "kinfo_get_cpus"); vmm_cur = calloc(vmm_ncpus, sizeof(*vmm_cur)); if (vmm_cur == NULL) err(1, "calloc vmm_cur"); vmm_prev = calloc(vmm_ncpus, sizeof(*vmm_prev)); if (vmm_prev == NULL) err(1, "calloc vmm_prev"); vmm_cptime_cur = calloc(vmm_ncpus, sizeof(*vmm_cptime_cur)); if (vmm_cptime_cur == NULL) err(1, "calloc vmm_cptime_cur"); vmm_cptime_prev = calloc(vmm_ncpus, sizeof(*vmm_cptime_prev)); if (vmm_cptime_prev == NULL) err(1, "calloc vmm_cptime_prev"); getvmm(); return (stdscr); }
// Ex. 14 automaton* read_automaton(FILE* fptr) { int state_c; int symbol_c; int initial_state; int final_state_c; int* final_states; s_table_element* symbol_table; state* state_table; char line[MAX_LEN+1]; if(fseek(fptr, 0, SEEK_SET)) { puts("Couldn't seek the start of the file!"); return NULL; } // Reading the number of states, number of symbols, and initial state fgets(line, (int)MAX_LEN, fptr); sscanf(line, "%d %d %d", &state_c, &symbol_c, &initial_state); // Constructing the table of final states final_states = read_final_states(fptr, &final_state_c); // Constructing the symbol table symbol_table = read_symbols(symbol_c, fptr); // Constructing the state table state_table = malloc(sizeof(state)*state_c); if(state_table == NULL) { puts("Couldn't allocate the state table"); return NULL; } int type; for(int i = 0; i < state_c; ++i) { if((i+1) == initial_state) type = 1; else if(is_final_state(final_states, final_state_c, i+1)) type = -1; else type = 0; state_table[i] = new_state(i+1, type, NULL); } while(read_transition(state_table, fptr)); automaton* ret = malloc(sizeof(automaton)); if(ret == NULL) return NULL; ret->initial_state = initial_state; ret->states = state_c; ret->symbol_c = symbol_c; ret->state_table = state_table; ret->symbol_table = symbol_table; ret->final_states = final_states; ret->final_state_c = final_state_c; return ret; }
/* load_file -- load a file of object code */ void load_file(FILE *bfp) { trailer t; int i, nread; int seglen[NSEGS]; int start; /* Get trailer */ fseek(bfp, -sizeof(trailer), SEEK_END); nread = fread(&t, 1, sizeof(trailer), bfp); /* Check magic numbers */ if (strncmp((char *) t.magic, MAGIC, 4) != 0) panic("bad magic number\n%s", "[The program you are running is not a valid" " Oberon bytecode file]"); if (get_int(t.sig) != SIG) panic("bad signature %#0.8x\n%s\n%s", get_int(t.sig), "[Although this appears to be an Oberon bytecode file,", " it needs a different version of the runtime system]"); if (prim_check != 0 && (unsigned) get_int(t.primsig) != prim_check) panic("bad primitive checksum\n%s\n%s", "[This program uses a different set of primitives", " from the ones built into the runtime system]"); /* Decode the other data */ for (i = 0; i < NSEGS; i++) seglen[i] = get_int(t.segment[i]); code_size = seglen[S_CODE]; stack_size = seglen[S_STACK]; nmods = get_int(t.nmods); nprocs = get_int(t.nprocs); nsyms = get_int(t.nsyms); start = get_int(t.start); #ifdef DEBUG if (dflag) { printf("csize = %d, dsize = %d, bss = %d, stk = %d\n", seglen[S_CODE], seglen[S_DATA], seglen[S_BSS], seglen[S_STACK]); printf("nmods = %d, nprocs = %d, nsyms = %d\n", nmods, nprocs, nsyms); } #endif fseek(bfp, start, SEEK_END); binfp = bfp; /* Load the code */ imem = (uchar *) scratch_alloc(seglen[S_CODE], TRUE); binread(imem, seglen[S_CODE]); /* Load and relocate the data */ dmem = (uchar *) scratch_alloc(seglen[S_DATA]+seglen[S_BSS], FALSE); binread(dmem, seglen[S_DATA]); relocate(seglen[S_DATA]); memset(dmem+seglen[S_DATA], 0, seglen[S_BSS]); /* Allocate stack */ stack = (uchar *) scratch_alloc(stack_size, FALSE); /* Save the entry point, pointer map and library path */ entry = (value *) &dmem[get_int(t.entry)]; gcmap = (value *) &dmem[get_int(t.gcmap)]; if (get_int(t.libdir) != 0) libpath = (char *) &dmem[get_int(t.libdir)]; /* Read the symbols */ if (nsyms > 0) read_symbols(seglen[S_DATA]); }
int main() { read_symbols("data.o"); exit(retcode); return 0; }