int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks) { int err, nodeoffset; int addr_cell_len, size_cell_len, len; u8 tmp[MEMORY_BANKS_MAX * 16]; /* Up to 64-bit address + 64-bit size */ int bank; if (banks > MEMORY_BANKS_MAX) { printf("%s: num banks %d exceeds hardcoded limit %d." " Recompile with higher MEMORY_BANKS_MAX?\n", __FUNCTION__, banks, MEMORY_BANKS_MAX); return -1; } err = fdt_check_header(blob); if (err < 0) { printf("%s: %s\n", __FUNCTION__, fdt_strerror(err)); return err; } /* update, or add and update /memory node */ nodeoffset = fdt_path_offset(blob, "/memory"); if (nodeoffset < 0) { nodeoffset = fdt_add_subnode(blob, 0, "memory"); if (nodeoffset < 0) { printf("WARNING: could not create /memory: %s.\n", fdt_strerror(nodeoffset)); return nodeoffset; } } err = fdt_setprop(blob, nodeoffset, "device_type", "memory", sizeof("memory")); if (err < 0) { printf("WARNING: could not set %s %s.\n", "device_type", fdt_strerror(err)); return err; } addr_cell_len = get_cells_len(blob, "#address-cells"); size_cell_len = get_cells_len(blob, "#size-cells"); for (bank = 0, len = 0; bank < banks; bank++) { write_cell(tmp + len, start[bank], addr_cell_len); len += addr_cell_len; write_cell(tmp + len, size[bank], size_cell_len); len += size_cell_len; } err = fdt_setprop(blob, nodeoffset, "reg", tmp, len); if (err < 0) { printf("WARNING: could not set %s %s.\n", "reg", fdt_strerror(err)); return err; } return 0; }
static cell parm1(FILE *fbin,const char *params,cell opcode,cell cip) { ucell p=getparamvalue(params,NULL); (void)cip; if (fbin!=NULL) { write_cell(fbin,opcode); write_cell(fbin,p); } /* if */ return opcodes(1)+opargs(1); }
static cell do_caseovl(FILE *fbin,const char *params,cell opcode,cell cip) { ucell v=hex2ucell(params,¶ms); ucell p=hex2ucell(params,NULL); (void)opcode; (void)cip; if (fbin!=NULL) { write_cell(fbin,v); write_cell(fbin,p); } /* if */ return opcodes(0)+opargs(2); }
int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks) { int err, nodeoffset; int addr_cell_len, size_cell_len, len; u8 tmp[banks * 8]; int bank; err = fdt_check_header(blob); if (err < 0) { printf("%s: %s\n", __FUNCTION__, fdt_strerror(err)); return err; } /* update, or add and update /memory node */ nodeoffset = fdt_path_offset(blob, "/memory"); if (nodeoffset < 0) { nodeoffset = fdt_add_subnode(blob, 0, "memory"); if (nodeoffset < 0) printf("WARNING: could not create /memory: %s.\n", fdt_strerror(nodeoffset)); return nodeoffset; } err = fdt_setprop(blob, nodeoffset, "device_type", "memory", sizeof("memory")); if (err < 0) { printf("WARNING: could not set %s %s.\n", "device_type", fdt_strerror(err)); return err; } addr_cell_len = get_cells_len(blob, "#address-cells"); size_cell_len = get_cells_len(blob, "#size-cells"); for (bank = 0, len = 0; bank < banks; bank++) { write_cell(tmp + len, start[bank], addr_cell_len); len += addr_cell_len; write_cell(tmp + len, size[bank], size_cell_len); len += size_cell_len; } err = fdt_setprop(blob, nodeoffset, "reg", tmp, len); if (err < 0) { printf("WARNING: could not set %s %s.\n", "reg", fdt_strerror(err)); return err; } return 0; }
/*! * Get the next generation * * \param x The x position of the cell * \param y The y position of the cell * \param *world The world in which we'll read * \param *nn The pointer where to write the number of living neighbours * \param *n1 The pointer where to write the number of living neighbours of 'x' type * \param *n2 The pointer where to write the number of living neighbours of 'o' type */ short newgeneration(unsigned int *world1, unsigned int *world2, int xstart, int xend) { // Variables used here int x, y, nn, n1, n2; short change = 0; // Fill the world with emptyness for (x = 0; x < N; ++x) { for (y = 0; y < N; ++y) { write_cell(x, y, 0, world2); } } // Generate the new world for (x = xstart; x < xend; ++x) { for (y = 0; y < N; ++y) { // Check the neighbours of each cell neighbors(x, y, world1, &nn, &n1, &n2); //If the cell is alive if (world1[code(x, y, 0, 0)] != 0) { // If less than 2 neighbours : death if (nn < 2) change = 1; // If more than 3 neighbours : death else if (nn > 3) change = 1; // If exaclty 2 or 3 neighbours : live else write_cell(x, y, world1[code(x, y, 0, 0)], world2); } // Else if it's an empty cell with 3 living neighbours : birth else if (nn == 3) { // In function of the number of living cells' type if (n1 > n2) write_cell(x, y, 1, world2); else write_cell(x, y, 2, world2); change = 1; } } // End of for y } // End of for x // Return the boolean value to know if there was a change or not return change; }
static cell parmx(FILE *fbin,const char *params,cell opcode,cell cip) { int idx; ucell count=getparamvalue(params,¶ms); (void)cip; if (fbin!=NULL) { write_cell(fbin,opcode); write_cell(fbin,(ucell)count); } /* if */ for (idx=0; idx<count; idx++) { ucell p=getparamvalue(params,¶ms); if (fbin!=NULL) write_cell(fbin,p); } /* for */ return opcodes(1)+opargs(count+1); }
static cell do_switch(FILE *fbin,const char *params,cell opcode,cell cip) { int i; ucell p; i=(int)hex2ucell(params,NULL); assert(i>=0 && i<sc_labnum); if (fbin!=NULL) { assert(lbltab!=NULL); p=lbltab[i]-cip; write_cell(fbin,opcode); write_cell(fbin,p); } /* if */ return opcodes(1)+opargs(1); }
/*! * Initialize the world randomly * * \return A pointer to the world created */ unsigned int* initialize_random() { // Variables used here int x, y; unsigned int cell; unsigned int *world; // Allocate the world world = allocate(); // Initialize randomly each cell for (x = 0; x < N; ++x) { for (y = 0; y < N; ++y) { // Initialize cell value from rand() function if (rand()%5 != 0) cell = 0; else if (rand()%2 == 0) cell = 1; else cell = 2; // Write this generated cell write_cell(x, y, cell, world); } } // Return a pointer to the world return world; }
static cell parm0(FILE *fbin,const char *params,cell opcode,cell cip) { (void)params; (void)cip; if (fbin!=NULL) write_cell(fbin,opcode); return opcodes(1); }
void recalculate_grid_cpu ( unsigned char* output_cell_grid, const unsigned char* input_cell_grid, unsigned width, unsigned height ) { // 1) Any live cell with fewer than two live neighbours dies, as if caused by under-population. // 2) Any live cell with two or three live neighbours lives on to the next generation. // 3) Any live cell with more than three live neighbours dies, as if by over-population. // 4) Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. // // and... // // if a cell is on a boundary, non-existent neighbors should be counted as dead cells. // Loop through every x and y, count the number of alive neighbors, // apply the rule, fill in output_cell_grid for (int x = 0; x < (int)width; x++) { for (int y = 0; y < (int)height; y++) { int neighbor_sum = 0; bool curr_cell_alive = get_cell(input_cell_grid, x, y, width, height); bool next_cell_alive = curr_cell_alive; //get sum of neighbors for(int j = -1; j < 2; j++) { for(int i = -1; i < 2; i++) { if (i != 0 || j != 0) { if (get_cell(input_cell_grid, x+i, y+j, width, height)) { neighbor_sum++; } } } } //check rules if(curr_cell_alive) { if(neighbor_sum < 2)//under-population rule next_cell_alive = false; else if(neighbor_sum < 4) next_cell_alive = true; else next_cell_alive = false; } else { if(neighbor_sum == 3) next_cell_alive = true; else next_cell_alive = false; } write_cell(next_cell_alive, x, y, width, height, output_cell_grid); } } }
static cell do_case(FILE *fbin,const char *params,cell opcode,cell cip) { int i; ucell p,v; (void)opcode; v=hex2ucell(params,¶ms); i=(int)hex2ucell(params,NULL); assert(i>=0 && i<sc_labnum); if (fbin!=NULL) { assert(lbltab!=NULL); p=lbltab[i]-cip; write_cell(fbin,v); write_cell(fbin,p); } /* if */ return opcodes(0)+opargs(2); }
void write_at(u32 pos, char c) { switch(c) { case '\n': // new line new_line(pos); break; case '\t': // tab move_cursor(cursor_pos + 8); break; case '\b': // backspace cursor_pos = pos - 2; move_cursor(cursor_pos); write_cell(pos - 1, NULL_CHAR, FB_WHITE, FB_BLACK); break; default: write_cell(pos, c, FB_WHITE, FB_BLACK); } }
static cell parmx_p(FILE *fbin,const char *params,cell opcode,cell cip) { int idx; ucell p; ucell count=getparamvalue(params,¶ms); (void)cip; assert(count<((ucell)1<<(pc_cellsize*4))); assert(opcode>=0 && opcode<=255); /* write the instruction (optionally) */ if (fbin!=NULL) { p=(count<<pc_cellsize*4) | opcode; write_cell(fbin,p); } /* if */ for (idx=0; idx<count; idx++) { p=getparamvalue(params,¶ms); if (fbin!=NULL) write_cell(fbin,p); } /* for */ return opcodes(1)+opargs(count); }
/* * write_row: * * @output: the stream * @sheet: the gnumeric sheet * @row: the row number * * Set up a TD node for each cell in the given row, witht eh appropriate * colspan and rowspan. * Call write_cell for each cell. */ static void write_row (GsfOutput *output, Sheet *sheet, gint row, GnmRange *range, html_version_t version) { gint col; ColRowInfo const *ri = sheet_row_get_info (sheet, row); if (ri->needs_respan) row_calc_spans ((ColRowInfo *) ri, row, sheet); for (col = range->start.col; col <= range->end.col; col++) { CellSpanInfo const *the_span; GnmRange const *merge_range; GnmCellPos pos; pos.col = col; pos.row = row; /* Is this a span */ the_span = row_span_get (ri, col); if (the_span != NULL) { gsf_output_printf (output, "<td colspan=\"%i\" ", the_span->right - col + 1); write_cell (output, sheet, row, the_span->cell->pos.col, version, FALSE); col = the_span->right; continue; } /* is this covered by a merge */ merge_range = gnm_sheet_merge_contains_pos (sheet, &pos); if (merge_range != NULL) { if (merge_range->start.col != col || merge_range->start.row != row) continue; gsf_output_printf (output, "<td colspan=\"%i\" rowspan=\"%i\" ", merge_range->end.col - merge_range->start.col + 1, merge_range->end.row - merge_range->start.row + 1); write_cell (output, sheet, row, col, version, TRUE); col = merge_range->end.col; continue; } gsf_output_puts (output, "<td "); write_cell (output, sheet, row, col, version, FALSE); } }
static cell parm1_p(FILE *fbin,const char *params,cell opcode,cell cip) { ucell p=getparamvalue(params,NULL); (void)cip; assert(p<((ucell)1<<(pc_cellsize*4))); assert(opcode>=0 && opcode<=255); if (fbin!=NULL) { p=(p<<pc_cellsize*4) | opcode; write_cell(fbin,p); } /* if */ return opcodes(1); }
static cell do_call(FILE *fbin,const char *params,cell opcode,cell cip) { char name[sNAMEMAX+1]; int i; symbol *sym; ucell p; for (i=0; !isspace(*params); i++,params++) { assert(*params!='\0'); assert(i<sNAMEMAX); name[i]=*params; } /* for */ name[i]='\0'; if (name[0]=='l' && name[1]=='.') { /* this is a label, not a function symbol */ i=(int)hex2ucell(name+2,NULL); assert(i>=0 && i<sc_labnum); if (fbin!=NULL) { assert(lbltab!=NULL); p=lbltab[i]-cip; /* make relative address */ } /* if */ } else { /* look up the function address; note that the correct file number must * already have been set (in order for static globals to be found). */ sym=findglb(name,sGLOBAL); assert(sym!=NULL); assert(sym->ident==iFUNCTN || sym->ident==iREFFUNC); assert(sym->vclass==sGLOBAL); p=sym->addr-cip; /* make relative address */ } /* if */ if (fbin!=NULL) { write_cell(fbin,opcode); write_cell(fbin,p); } /* if */ return opcodes(1)+opargs(1); }
void write_options(FILE * fp, gehash_t * the_table) { short option_key, option_length; short option_value; option_key = SUBREAD_INDEX_OPTION_INDEX_GAP; option_length = 2; option_value = the_table -> index_gap; write_cell(option_key, option_length, (char *) &option_value,fp); option_key = 0; fwrite(&option_key, 2, 1, fp); }
/*! * Initialize the world with a small exploder in the center * * \return A pointer to the world created */ unsigned int* initialize_small_exploder() { // Variables used here int x, y, mx, my; unsigned int *world; // Allocate the world world = allocate(); // Fill the world with emptyness for (x = 0; x < N; ++x) { for (y = 0; y < N; ++y) { write_cell(x, y, 0, world); } } // Here, draw a small exploder mx = N/2 - 2; my = N/2 - 2; x = mx; y = my + 1; write_cell(x, y, 2, world); x = mx + 1; y = my; write_cell(x, y, 2, world); y = my + 1; write_cell(x, y, 2, world); y = my + 2; write_cell(x, y, 2, world); x = mx + 2; y = my; write_cell(x, y, 2, world); y = my + 2; write_cell(x, y, 2, world); x = mx + 3; y = my + 1; write_cell(x, y, 2, world); // Return a pointer to the world return world; }
void on_tick() { // Function to be called once per tick. // Every tick we should go through the world and run check_cell on each cell in // world_write to determine the new value of world_calc's cells // Then, we set world_write's values equal to world_calc's new value and display them for (j=0; j<number_of_rows; j++) { for (k=0; k<32; k++){ write_cell( j, k, check_cell( j, k, is_world_calc) ); } } display_world(); is_world_calc = !(is_world_calc); }
static cell do_dump(FILE *fbin,const char *params,cell opcode,cell cip) { ucell p; int num = 0; (void)opcode; (void)cip; while (*params!='\0') { p=getparamvalue(params,¶ms); if (fbin!=NULL) write_cell(fbin,p); num++; while (isspace(*params)) params++; } /* while */ return num*pc_cellsize; }
/*! * Initialize the world by a dummy way * * \return A pointer to the world created */ unsigned int* initialize_dummy() { // Variables used here int x, y; unsigned int *world; // Allocate the world world = allocate(); // Initialize by a dummy way each cell for (x = 0; x < N; ++x) { for (y = 0; y < N; ++y) { write_cell(x, y, x%3, world); // Only write x modulo 3 as value } } // Return a pointer to the world return world; }
static void write_organism(FILE *fp, ORGANISM *o) { KFORTH_DISASSEMBLY *kfd; char buf[5000], *p; CELL *c; ASSERT( fp != NULL ); ASSERT( o != NULL ); fprintf(fp, #ifndef __linux__ "ORGANISM %I64d %d %d %I64d %I64d %d %d %d\n", #else "ORGANISM %lld %d %d %lld %lld %d %d %d\n", #endif o->id, o->strain, o->oflags, o->parent1, o->parent2, o->generation, o->energy, o->age); kfd = kforth_disassembly_make(o->program, 80, 0); fprintf(fp, " { # program\n"); p = kfd->program_text; while( getline(&p, buf) ) { fprintf(fp, "\t\"%s\"\n", buf); } fprintf(fp, " }\n"); kforth_disassembly_delete(kfd); fprintf(fp, "\n"); for(c=o->cells; c; c=c->next) { write_cell(fp, o->id, c); } }
static void plusstore(void) { const ucell *aaddr = (ucell *)cell2pointer(POP()); const cell nu = POP(); write_cell(aaddr,read_cell(aaddr)+nu); }
int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force) { int nodeoffset, addr_cell_len; int err, j, total; fdt64_t tmp; const char *path; uint64_t addr, size; /* Find the "chosen" node. */ nodeoffset = fdt_path_offset (fdt, "/chosen"); /* If there is no "chosen" node in the blob return */ if (nodeoffset < 0) { printf("fdt_initrd: %s\n", fdt_strerror(nodeoffset)); return nodeoffset; } /* just return if initrd_start/end aren't valid */ if ((initrd_start == 0) || (initrd_end == 0)) return 0; total = fdt_num_mem_rsv(fdt); /* * Look for an existing entry and update it. If we don't find * the entry, we will j be the next available slot. */ for (j = 0; j < total; j++) { err = fdt_get_mem_rsv(fdt, j, &addr, &size); if (addr == initrd_start) { fdt_del_mem_rsv(fdt, j); break; } } err = fdt_add_mem_rsv(fdt, initrd_start, initrd_end - initrd_start); if (err < 0) { printf("fdt_initrd: %s\n", fdt_strerror(err)); return err; } addr_cell_len = get_cells_len(fdt, "#address-cells"); path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL); if ((path == NULL) || force) { write_cell((u8 *)&tmp, initrd_start, addr_cell_len); err = fdt_setprop(fdt, nodeoffset, "linux,initrd-start", &tmp, addr_cell_len); if (err < 0) { printf("WARNING: " "could not set linux,initrd-start %s.\n", fdt_strerror(err)); return err; } write_cell((u8 *)&tmp, initrd_end, addr_cell_len); err = fdt_setprop(fdt, nodeoffset, "linux,initrd-end", &tmp, addr_cell_len); if (err < 0) { printf("WARNING: could not set linux,initrd-end %s.\n", fdt_strerror(err)); return err; } } return 0; }