/* Assumes a Pseudo graphic display. */ void init_colormaps (Display *dpy) { screen = XDefaultScreen (dpy); fprintf(stderr, "Number of display cells = %d\n", XDisplayCells(dpy, screen)); fprintf(stderr, "Number of display planes = %d\n", XDisplayPlanes(dpy, screen)); colormap = XDefaultColormap(dpy, screen); while (XAllocColorCells(display_, colormap, False, NULL, 0, &(pixels[cmapsize]), 1)) cmapsize++; cmapsize = (cmapsize > 60) ? 60 : cmapsize; fprintf(stderr, "Number of colors available = %d\n", cmapsize); if (cmapsize<5) { fprintf(stderr, "Number of colors available = %d\n", cmapsize); fprintf(stderr, "This is too few to run the display software.\n"); fprintf(stderr, "Shut down windows, or restart X server.\n"); exit(-1); } /* build a grey scale colormap as a default, so that other programs */ /* can't grab the colors*/ { XColor xcolor; int i; xcolor.flags= DoRed | DoGreen | DoBlue; for (i = 0 ; i < cmapsize; i++) { xcolor.pixel = pixels[i]; xcolor.red = (unsigned short) (i<<8); xcolor.green = (unsigned short) (i<<8); xcolor.blue = (unsigned short) (i<<8); XStoreColor (display_, colormap, &xcolor); } } /* Generate global gamma correction table for this display */ { Pixel index; double gamma = 1.0/1.0; for(index =0; index < 255; index++) { GammaCorrect[index] = (Pixel)(0.5 + 255.0 * (double) pow((double)(index)/255.0, gamma)); } } /* Set up the internal histogram tables*/ translate_init(); return; }
vine_blocks_t *instmap_translate_address_range(instmap_t *insts, address_t start, address_t end) { translate_init(); vx_FreeAll(); vector<Instruction *> foo; vine_blocks_t *ret = new vine_blocks_t; for(address_t i = start; i <= end; i++){ if(insts->imap.find(i) == insts->imap.end()) continue; foo.push_back(insts->imap.find(i)->second); } vector<vine_block_t *> blocks = generate_vex_ir(insts->prog, foo); blocks = generate_vine_ir(insts->prog, blocks); for(unsigned i = 0; i < blocks.size(); i++){ vine_block_t *block = blocks.at(i); assert(block); if(block->inst == NULL) continue; /* This is broken as it removes the jumps from the end of repz instructions. Just because control flow eventually goes on to the following instruction doesn't mean that jump is at the end. It should simply be checking that the jump is to the following instruction since we know where that is. // If the statement isn't control flow, and not the last // remove the dummy jumps to the next block that vex inserts bfd_vma target; int ctype = get_control_transfer_type(block->inst, &target); Stmt *s; switch(ctype){ case INST_CONT: s = block->vine_ir->back(); if(s->stmt_type == JMP){ block->vine_ir->pop_back(); } break; default: break; } */ } ret->insert(ret->end(), blocks.begin(), blocks.end()); for(vector<vine_block_t *>::iterator it = ret->begin(); it != ret->end(); it++){ vine_block_t *block = *it; block->vex_ir = NULL; // this isn't available. } return ret; }
void parse_args_and_init(int argc, char **argv, UpdaterAppState *app_state) { int i; for (i = 1; i < argc; i++) { if ((!strcmp(argv[i], "--url")) && (++i < argc)) { app_state->url = argv[i]; } else if ((!strcmp(argv[i], "--file")) && (++i < argc)) { app_state->file = argv[i]; } else if ((!strcmp(argv[i], "--name")) && (++i < argc)) { app_state->app_name = argv[i]; } else if ((!strcmp(argv[i], "--image-dir")) && (++i < argc)) { app_state->image_dir = argv[i]; app_state->image_dir_iter = new LLDirIterator(argv[i], "*.jpg"); } else if ((!strcmp(argv[i], "--dest")) && (++i < argc)) { app_state->dest_dir = argv[i]; } else if ((!strcmp(argv[i], "--stringsdir")) && (++i < argc)) { app_state->strings_dirs = argv[i]; } else if ((!strcmp(argv[i], "--stringsfile")) && (++i < argc)) { app_state->strings_file = argv[i]; } else { // show usage, an invalid option was given. show_usage_and_exit(); } } if (app_state->app_name.empty() || (app_state->url.empty() && app_state->file.empty()) || app_state->dest_dir.empty()) { show_usage_and_exit(); } app_state->progress_value = 0.0; app_state->activity_mode = FALSE; app_state->failure = FALSE; translate_init(app_state->strings_dirs, app_state->strings_file); }
Vector& BkStressLimSurface2D::getEvolDirection(Vector &f_new) { // -1 => Radial Evolution // 0 => From geometric center (~ normal) // 1 => Constant-P v2(0) = 0.0; if(direction >= 0) v2(1) = direction*f_new(1); else v2(1) = direction*translate_init(1); return v2; }
// moved from ir_program.cpp vine_block_t* asm_addr_to_ir(asm_program_t *p, address_t addr) { translate_init(); asm_function_t *f = get_nearest_function(p, addr); assert(f); assert(f->instmap.find(addr) != f->instmap.end()); Instruction *inst = f->instmap.find(addr)->second; vector<Instruction *> instrs; instrs.push_back(inst); vector<vine_block_t *> vine_blocks = generate_vex_ir(p, instrs); vine_blocks = generate_vine_ir(p, vine_blocks); vx_FreeAll(); assert(vine_blocks.size() == 1); return vine_blocks[0]; }
int translate_init(struct translate_state *ts) /* two pass: first to find optimal length, second to alloc/fill */ { int max_length = 100000; int i, s, c, best_i; double a, a2, err, best_360; if (fabs(ts->angle) < 2*M_PI/max_length) { fprintf(stderr, "angle too small or array too short\n"); return 1; } ts->i = 0; ts->sincos = NULL; if (ts->len) { max_length = ts->len; ts->sincos = malloc(max_length * sizeof(int16_t)); } a = 0.0; err = 0.0; best_i = 0; best_360 = 4.0; for (i=0; i < max_length; i+=2) { s = (int)round(sin(a + err) * (1<<14)); c = (int)round(cos(a + err) * (1<<14)); a2 = atan2(s, c); err = fmod(a, 2*M_PI) - a2; a += ts->angle; while (a > M_PI) { a -= 2*M_PI;} while (a < -M_PI) { a += 2*M_PI;} if (i != 0 && fabs(a) < best_360) { best_i = i; best_360 = fabs(a); } if (i != 0 && fabs(a) < 0.0000001) { break;} if (ts->sincos) { ts->sincos[i] = s; ts->sincos[i+1] = c; //fprintf(stderr, "%i %i %i\n", i, s, c); } } if (ts->sincos) { return 0; } ts->len = best_i + 2; return translate_init(ts); }
vine_block_t *instmap_translate_address(instmap_t *insts, address_t addr) { translate_init(); vx_FreeAll(); vector<Instruction *> foo; assert(insts->imap.find(addr) != insts->imap.end()); foo.push_back(insts->imap.find(addr)->second); vector<vine_block_t *> blocks = generate_vex_ir(insts->prog, foo); blocks = generate_vine_ir(insts->prog, blocks); assert(blocks.size() == 1); vine_block_t *block = *(blocks.begin()); block->vex_ir = NULL; vx_FreeAll(); return block; }
// moved from ir_program.cpp bap_block_t* asmir_addr_to_bap(asm_program_t *p, address_t addr, address_t *next) { // Set longjmp to handle possible VEX errors jmp_buf_set = 1; if (setjmp(vex_error) != 0) { /* There was an exception */ jmp_buf_set = 0; cerr << "There was an exception in asmir_addr_to_bap" << endl; return NULL; } translate_init(); bap_block_t * bap_block = generate_vex_ir(p, addr); generate_bap_ir_block(p, bap_block); if (next) *next = addr + asmir_get_instr_length(p, addr); return bap_block; }
int main() { unsigned char insn[] = { 0xf7, 0xd0 }; /* Rex r; r.ToIR( insn, (unsigned int)0x8000 ); */ translate_init(); IRSB *bb = translate_insn( VexArchX86, insn, (unsigned int)0x8000000); printf("stmts_size: %d\n", bb->stmts_size); printf("stmts_used: %d\n", bb->stmts_used); IRStmt **stmts = bb->stmts; printf("stmts->tag: %08x\n", (*stmts)->tag ); printf("stmts->IMark->addr: %08x\n", (*stmts)->Ist.IMark.addr); printf("stmts->IMark->len: %d\n", (*stmts)->Ist.IMark.len); }
bool emu_start(unsigned int port_gdb, unsigned int port_rdbg, const char *snapshot_file) { gui_busy_raii gui_busy; if(snapshot_file) { // Open snapshot size_t snapshot_size = gzip_filesize(snapshot_file); if(snapshot_size < sizeof(emu_snapshot)) return false; FILE *fp = fopen_utf8(snapshot_file, "rb"); if(!fp) return false; int dupfd = dup(fileno(fp)); fclose(fp); fp = nullptr; // gzdopen takes ownership of the fd gzFile gzf = gzdopen(dupfd, "r"); if(!gzf) { close(dupfd); return false; } auto snapshot = (struct emu_snapshot *) malloc(snapshot_size); if(!snapshot) { gzclose(gzf); return false; } if((size_t) gzread(gzf, snapshot, snapshot_size) != snapshot_size) { gzclose(gzf); free(snapshot); return false; } gzclose(gzf); //sched_reset(); sched.items[SCHED_THROTTLE].clock = CLOCK_27M; sched.items[SCHED_THROTTLE].proc = throttle_interval_event; // TODO: Max length path_boot1 = std::string(snapshot->path_boot1); path_flash = std::string(snapshot->path_flash); // TODO: Pass snapshot_size to flash_resume to avoid reading after the buffer // Resume components uint32_t sdram_size; if(snapshot->sig != SNAPSHOT_SIG || snapshot->version != SNAPSHOT_VER || !flash_resume(snapshot) || !flash_read_settings(&sdram_size, &product, &features, &asic_user_flags) || !cpu_resume(snapshot) || !memory_resume(snapshot) || !sched_resume(snapshot)) { emu_cleanup(); free(snapshot); return false; } free(snapshot); } else { if (!flash_open(path_flash.c_str())) return false; uint32_t sdram_size; flash_read_settings(&sdram_size, &product, &features, &asic_user_flags); flash_set_bootorder(boot_order); if(!memory_initialize(sdram_size)) { emu_cleanup(); return false; } } if(debug_on_start) cpu_events |= EVENT_DEBUG_STEP; uint8_t *rom = mem_areas[0].ptr; memset(rom, -1, 0x80000); for (int i = 0x00000; i < 0x80000; i += 4) RAM_FLAGS(&rom[i]) = RF_READ_ONLY; /* Load the ROM */ FILE *f = fopen_utf8(path_boot1.c_str(), "rb"); if (!f) { gui_perror(path_boot1.c_str()); emu_cleanup(); return false; } (void)fread(rom, 1, 0x80000, f); fclose(f); #ifndef NO_TRANSLATION if(!translate_init()) { gui_debug_printf("Could not init JIT, disabling translation.\n"); do_translate = false; } #endif addr_cache_init(); throttle_timer_on(); if(port_gdb) gdbstub_init(port_gdb); if(port_rdbg) rdebug_bind(port_rdbg); usblink_queue_reset(); if(!snapshot_file) emu_reset(); return true; }