EXP_FUNC void * STDCALL ax_calloc(size_t n, size_t s) { void *x; if ((x = calloc(n, s)) == NULL) exit_now(out_of_mem_str); return x; }
EXP_FUNC int STDCALL ax_open(const char *pathname, int flags) { int x; if ((x = open(pathname, flags)) < 0) exit_now(file_open_str, pathname); return x; }
EXP_FUNC void * STDCALL ax_realloc(void *y, size_t s) { void *x; if ((x = realloc(y, s)) == NULL) exit_now(out_of_mem_str); return x; }
void open_file(hid_t *fid, hid_t *sid) { char test_file[] = FILENAME; char sim_name[] = SIMNAME; herr_t err = output_file_open_rdonly(test_file,fid); if ( H5_RETURN_FAIL(err) ) { danu_error_printf("Failed to create test output file"); exit_now(err); } err = simulation_open(*fid,sim_name,sid); if ( H5_RETURN_FAIL(err) ) { danu_error_printf("Failed to create test sim group"); exit_now(err); } }
EXP_FUNC void * ax_zalloc(size_t s, const char* file, int line) { void *x; if ((x = (void*)zalloc(s)) == NULL) exit_now("out of memory %s %d\n", file, line); else { debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, esp_get_free_heap_size()); //add_mem_info(x, s, file, line); } return x; }
EXP_FUNC void * ICACHE_FLASH_ATTR ax_realloc(void *y, size_t s, const char* file, int line) { void *x; if ((x = realloc(y, s)) == NULL) exit_now("out of memory %s %d\n", file, line); else { debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, system_get_free_heap_size()); //add_mem_info(x, s, file, line); } return x; }
EXP_FUNC void * ICACHE_FLASH_ATTR ax_zalloc(size_t s, const char* file, int line) { void *x; if ((x = (void*)malloc(s)) == NULL) exit_now("out of memory %s %d\n", file, line); else { debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, system_get_free_heap_size()); memset(x, 0, s); } return x; }
EXP_FUNC void * ax_calloc(size_t n, size_t s, const char* file, int line) { void *x; //unsigned total_size =0; if ((x = calloc(n, s)) == NULL) exit_now("out of memory %s %d\n", file, line); else { debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, esp_get_free_heap_size()); //total_size = n * s; //add_mem_info (x, total_size, file, line); } return x; }
EXP_FUNC void * STDCALL ax_calloc(size_t n, size_t s, const char* f, const int l) { if(enable) printf("calloc\t"); void *x; if ((x = calloc(n, s)) == NULL) { exit_now(out_of_mem_str); } add_entry(x,n*s, f, l); print_buf_stats(); return x; }
EXP_FUNC void * STDCALL ax_realloc(void *y, size_t s, const char* f, const int l) { if(enable) printf("realloc\t"); void *x; if ((x = realloc(y, s)) == NULL) exit_now(out_of_mem_str); remove_entry(y, f, l); add_entry(x,s, f, l); print_buf_stats(); return x; }
int main(int argc, char **argv, char **envp) { char *s; int i, exit_code; #ifndef _MSC_VER /* catch SIGUSR1 and dump intermediate stats */ signal(SIGUSR1, signal_sim_stats); /* catch SIGUSR2 and dump final stats and exit */ signal(SIGUSR2, signal_exit_now); #endif /* _MSC_VER */ /* register an error handler */ fatal_hook(sim_print_stats); /* set up a non-local exit point */ if ((exit_code = setjmp(sim_exit_buf)) != 0) { /* special handling as longjmp cannot pass 0 */ exit_now(exit_code-1); } /* register global options */ sim_odb = opt_new(orphan_fn); opt_reg_flag(sim_odb, "-h", "print help message", &help_me, /* default */FALSE, /* !print */FALSE, NULL); opt_reg_flag(sim_odb, "-v", "verbose operation", &verbose, /* default */FALSE, /* !print */FALSE, NULL); #ifdef DEBUG opt_reg_flag(sim_odb, "-d", "enable debug message", &debugging, /* default */FALSE, /* !print */FALSE, NULL); #endif /* DEBUG */ opt_reg_flag(sim_odb, "-i", "start in Dlite debugger", &dlite_active, /* default */FALSE, /* !print */FALSE, NULL); opt_reg_int(sim_odb, "-seed", "random number generator seed (0 for timer seed)", &rand_seed, /* default */1, /* print */TRUE, NULL); opt_reg_flag(sim_odb, "-q", "initialize and terminate immediately", &init_quit, /* default */FALSE, /* !print */FALSE, NULL); opt_reg_string(sim_odb, "-chkpt", "restore EIO trace execution from <fname>", &sim_chkpt_fname, /* default */NULL, /* !print */FALSE, NULL); /* stdio redirection options */ opt_reg_string(sim_odb, "-redir:sim", "redirect simulator output to file (non-interactive only)", &sim_simout, /* default */NULL, /* !print */FALSE, NULL); opt_reg_string(sim_odb, "-redir:prog", "redirect simulated program output to file", &sim_progout, /* default */NULL, /* !print */FALSE, NULL); #ifndef _MSC_VER /* scheduling priority option */ opt_reg_int(sim_odb, "-nice", "simulator scheduling priority", &nice_priority, /* default */NICE_DEFAULT_VALUE, /* print */TRUE, NULL); #endif /* FIXME: add stats intervals and max insts... */ /* register all simulator-specific options */ sim_reg_options(sim_odb); /* parse simulator options */ exec_index = -1; opt_process_options(sim_odb, argc, argv); /* redirect I/O? */ if (sim_simout != NULL) { /* send simulator non-interactive output (STDERR) to file SIM_SIMOUT */ fflush(stderr); if (!freopen(sim_simout, "w", stderr)) fatal("unable to redirect simulator output to file `%s'", sim_simout); } if (sim_progout != NULL) { /* redirect simulated program output to file SIM_PROGOUT */ sim_progfd = fopen(sim_progout, "w"); if (!sim_progfd) fatal("unable to redirect program output to file `%s'", sim_progout); } /* need at least two argv values to run */ if (argc < 2) { banner(stderr, argc, argv); usage(stderr, argc, argv); exit(1); } /* opening banner */ banner(stderr, argc, argv); if (help_me) { /* print help message and exit */ usage(stderr, argc, argv); exit(1); } /* seed the random number generator */ if (rand_seed == 0) { /* seed with the timer value, true random */ mysrand(time((time_t *)NULL)); } else { /* seed with default or user-specified random number generator seed */ mysrand(rand_seed); } /* exec_index is set in orphan_fn() */ if (exec_index == -1) { /* executable was not found */ fprintf(stderr, "error: no executable specified\n"); usage(stderr, argc, argv); exit(1); } /* else, exec_index points to simulated program arguments */ /************modification for XAMP*************/ cseq_outfile=argv[exec_index]; /***************end****************************/ /* check simulator-specific options */ sim_check_options(sim_odb, argc, argv); #ifndef _MSC_VER /* set simulator scheduling priority */ if (nice(0) < nice_priority) { if (nice(nice_priority - nice(0)) < 0) fatal("could not renice simulator process"); } #endif /* default architected value... */ sim_num_insn = 0; #ifdef BFD_LOADER /* initialize the bfd library */ bfd_init(); #endif /* BFD_LOADER */ /* initialize the instruction decoder */ md_init_decoder(); /* initialize all simulation modules */ sim_init(); /* initialize architected state */ sim_load_prog(argv[exec_index], argc-exec_index, argv+exec_index, envp); /* register all simulator stats */ sim_sdb = stat_new(); sim_reg_stats(sim_sdb); #if 0 /* not portable... :-( */ stat_reg_uint(sim_sdb, "sim_mem_usage", "total simulator (data) memory usage", &sim_mem_usage, sim_mem_usage, "%11dk"); #endif /* record start of execution time, used in rate stats */ sim_start_time = time((time_t *)NULL); /* emit the command line for later reuse */ fprintf(stderr, "sim: command line: "); for (i=0; i < argc; i++) fprintf(stderr, "%s ", argv[i]); fprintf(stderr, "\n"); /* output simulation conditions */ s = ctime(&sim_start_time); if (s[strlen(s)-1] == '\n') s[strlen(s)-1] = '\0'; fprintf(stderr, "\nsim: simulation started @ %s, options follow:\n", s); opt_print_options(sim_odb, stderr, /* short */TRUE, /* notes */TRUE); sim_aux_config(stderr); fprintf(stderr, "\n"); /* omit option dump time from rate stats */ sim_start_time = time((time_t *)NULL); if (init_quit) exit_now(0); running = TRUE; sim_main(); /* simulation finished early */ exit_now(0); return 0; }
int main(int argc, char *argv[]) { /* MAIN CODE STARTS HERE */ int i, /* j, */ bin; double val, bin_width; STATS stats; char log_name[25]; /* Check for correct number of comand line arguments */ if (argc != 4) { fprintf(stderr, "Missing comand line arguments,\nUSAGE: <program name> <config file> <points file> <wind file>\n\n"); exit(1); } /* Each node opens a file for logging */ sprintf(log_name, "%s", LOG_FILE); fprintf(stderr, "%s\n", log_name); log_file = fopen(log_name, "w+"); if (log_file == NULL) { fprintf(stderr, "Cannot open LOG file=[%s]:[%s]. Exiting.\n", log_name, strerror(errno)); exit(1); } /* Initialize the global variables (see top of file) with inputs from the configuration file. */ if ( init_globals(argv[1]) ) { exit(1); } #ifdef _PRINT fflush(log_file); #endif /*make sure the points file exists*/ in_points= fopen(argv[2], "r"); if (in_points == NULL) { fprintf(stderr, "Cannot open points file=[%s]:[%s]. Exiting.\n", argv[2], strerror(errno)); exit_now(1); } /* Input the data points from a file using the get_points function. */ if (get_points(in_points) ) { exit_now(1); } #ifdef _PRINT fflush(log_file); #endif /*make sure the wind file exists*/ in_wind= fopen(argv[3], "r"); if (in_wind == NULL) { fprintf(stderr, "Cannot open wind file=[%s]:[%s]. Exiting.\n", argv[3], strerror(errno)); exit_now(1); } if (get_wind(in_wind) ) { exit_now(1); } #ifdef _PRINT fflush(log_file); #endif set_global_values(log_file); #ifdef _PRINT fflush(log_file); #endif set_eruption_values(&e, W[0]); for (i = 0; i < num_pts; i++) {/* For each location */ tephra_calc(&e, pt+i, W[0], &stats); } #ifdef _PRINT fprintf(log_file, "Calculated mass...\n"); for (i = 0; i < num_pts; i++) { fprintf(log_file, "[%.0f][%.0f] %g ", (pt+i)->easting, (pt+i)->northing, (pt+i)->calculated_mass) ; fprintf(log_file, "\n"); } fprintf(log_file, "Finished.\n"); fflush(log_file); #endif fprintf(stderr,"\nMin Particle Fall Time = %gs\nMax Particle Fall Time = %gs\n",stats.min_falltime, stats.max_falltime); //printf("Mean_fall_time %15.6e\n",stats. /*phi_bins = (int)((erupt+j)->max_phi - (erupt+j)->min_phi); if (phi_bins < 1) phi_bins = 1; */ bin_width = (e.max_phi - e.min_phi)/PART_STEPS; printf("#EAST NORTH ELEV Kg/m^2 "); for (bin = 0; bin < PART_STEPS; bin++) printf("[%6.5f:%6.5f) ", e.min_phi + bin_width*bin, e.min_phi + bin_width*(bin+1)); printf("\n"); fprintf(stderr, "PART_STEPS=%d bin_width=%g\n", PART_STEPS, bin_width); for (i=0; i < num_pts; i++) { printf("%20.8e %20.8e %20.8e %20.8e ", (pt+i)->easting, (pt+i)->northing, (pt+i)->elevation, (pt+i)->calculated_mass); ///* Print out percent of total */ for (bin=0; bin < PART_STEPS; bin++) { //val = ((pt+i)->calculated_phi[bin]/(pt+i)->calculated_mass); val = (pt+i)->calculated_phi[bin]; //fprintf(stderr, "bin = %g mass = %g ", (pt+i)->phi[bin], (pt+i)->mass ) printf("%20.8e ", val); } printf("\n"); } print_for_stats(0); fprintf(log_file, "Finished.\n"); exit_now(0); return 1; }
int main(int argc, char **argv, char **envp) { char *s; int i, exit_code; #ifndef _MSC_VER /* catch SIGUSR1 and dump intermediate stats */ signal(SIGUSR1, signal_sim_stats); /* catch SIGUSR2 and dump final stats and exit */ signal(SIGUSR2, signal_exit_now); #endif /* _MSC_VER */ /* register an error handler */ fatal_hook(sim_print_stats); /* set up a non-local exit point */ if ((exit_code = setjmp(sim_exit_buf)) != 0) { /* special handling as longjmp cannot pass 0 */ exit_now(exit_code-1); } /* register global options */ sim_odb = opt_new(orphan_fn); opt_reg_flag(sim_odb, "-v", "verbose operation", &verbose, /* default */FALSE, /* !print */FALSE, NULL); opt_reg_int(sim_odb, "-seed", "random number generator seed (0 for timer seed)", &rand_seed, /* default */1, /* print */TRUE, NULL); opt_reg_string(sim_odb, "-chkpt", "restore EIO trace execution from <fname>", &sim_chkpt_fname, /* default */NULL, /* !print */FALSE, NULL); /* register instruction execution options */ insn_reg_options(sim_odb); /* register all simulator-specific options */ sim_reg_options(sim_odb); /* parse simulator options */ exec_index = -1; opt_process_options(sim_odb, argc, argv); /* need at least two argv values to run */ if (argc < 2) { banner(stderr, argc, argv); usage(stderr, argc, argv); exit(1); } /* opening banner */ banner(stderr, argc, argv); /* seed the random number generator */ if (rand_seed == 0) { /* seed with the timer value, true random */ mysrand(time((time_t *)NULL)); } else { /* seed with default or user-specified random number generator seed */ mysrand(rand_seed); } /* exec_index is set in orphan_fn() */ if (exec_index == -1) { /* executable was not found */ fprintf(stderr, "error: no executable specified\n"); usage(stderr, argc, argv); exit(1); } /* else, exec_index points to simulated program arguments */ /* initialize the instruction decoder */ md_init_decoder(); /* need options */ insn_check_options(); /* check simulator-specific options */ sim_check_options(); /* default architected value... */ sim_num_insn = 0; #ifdef BFD_LOADER /* initialize the bfd library */ bfd_init(); #endif /* BFD_LOADER */ /* initialize all simulation modules */ sim_init(); /* initialize architected state */ sim_load_prog(argv[exec_index], argc-exec_index, argv+exec_index, envp); /* register all simulator stats */ /* record start of execution time, used in rate stats */ sim_start_time = time((time_t *)NULL); /* emit the command line for later reuse */ fprintf(stderr, "sim: command line: "); for (i=0; i < argc; i++) fprintf(stderr, "%s ", argv[i]); fprintf(stderr, "\n"); /* output simulation conditions */ s = ctime(&sim_start_time); if (s[strlen(s)-1] == '\n') s[strlen(s)-1] = '\0'; fprintf(stderr, "\nsim: simulation started @ %s, options follow:\n", s); opt_print_options(sim_odb, stderr, /* short */TRUE, /* notes */TRUE); sim_aux_config(stderr); fprintf(stderr, "\n"); /* omit option dump time from rate stats */ sim_start_time = time((time_t *)NULL); running = TRUE; sim_main(); /* simulation finished early */ exit_now(0); return 0; }
int main (int argc, char **argv, char **envp) { char *s ; s = NULL ; int i, exit_code, j; #ifndef _MSC_VER /* catch SIGUSR1 and dump intermediate stats */ signal (SIGUSR1, signal_sim_stats); /* catch SIGUSR2 and dump final stats and exit */ signal (SIGUSR2, signal_exit_now); #endif /* _MSC_VER */ /* register an error handler */ fatal_hook (sim_print_stats); /* set up a non-local exit point */ if ((exit_code = setjmp (sim_exit_buf)) != 0) { /* special handling as longjmp cannot pass 0 */ exit_now (exit_code - 1); } /* register global options */ sim_odb = opt_new (orphan_fn); opt_reg_flag (sim_odb, "-h", "print help message", &help_me, /* default */ FALSE, /* !print */ FALSE, NULL); opt_reg_flag (sim_odb, "-v", "verbose operation", &verbose, /* default */ FALSE, /* !print */ FALSE, NULL); #ifdef DEBUG opt_reg_flag (sim_odb, "-d", "enable debug message", &debugging, /* default */ FALSE, /* !print */ FALSE, NULL); #endif /* DEBUG */ opt_reg_flag (sim_odb, "-i", "start in Dlite debugger", &dlite_active, /* default */ FALSE, /* !print */ FALSE, NULL); opt_reg_int (sim_odb, "-seed", "random number generator seed (0 for timer seed)", &rand_seed, /* default */ 1, /* print */ TRUE, NULL); opt_reg_flag (sim_odb, "-q", "initialize and terminate immediately", &init_quit, /* default */ FALSE, /* !print */ FALSE, NULL); #ifdef SMT_SS fprintf (stderr, "Note: -chkpt option is disabled for SMT version \n"); #else opt_reg_string (sim_odb, "-chkpt", "restore EIO trace execution from <fname>", &sim_chkpt_fname, /* default */ NULL, /* !print */ FALSE, NULL); #endif #ifdef REMOVE_MY_CODE opt_reg_string (sim_odb, "-chkpt", "restore EIO trace execution from <fname>", &sim_chkpt_fname, /* default */ NULL, /* !print */ FALSE, NULL); #endif /* stdio redirection options */ opt_reg_string (sim_odb, "-redir:sim", "redirect simulator output to file (non-interactive only)", &sim_simout, /* default */ NULL, /* !print */ FALSE, NULL); #ifdef SMT_SS #ifndef PROG_OUT_FROM_SIM_OUT fprintf (stderr, "Note: -redir:prog option is controled in *.bnc configuration " "file of each program in SMT version \n"); #else // !PROG_OUT_FROM_SIM_OUT fprintf (stderr, "Note: -redir:prog option is controled by combining the *.bnc configuration " "setting with the -redir:sim option. \n"); #endif // !PROG_OUT_FROM_SIM_OUT #else opt_reg_string (sim_odb, "-redir:prog", "redirect simulated program output to file", &sim_progout, /* default */ NULL, /* !print */ FALSE, NULL); #endif #ifdef REMOVE_MY_CODE opt_reg_string (sim_odb, "-redir:prog", "redirect simulated program output to file", &sim_progout, /* default */ NULL, /* !print */ FALSE, NULL); #endif /* Dump files to load assembly code and dumping stats etc. */ opt_reg_string (sim_odb, "-redir:dump", "redirect simulated program output to file", &sim_str_dump, /* default */ NULL, /* !print */ FALSE, NULL); #ifndef _MSC_VER /* scheduling priority option */ opt_reg_int (sim_odb, "-nice", "simulator scheduling priority", &nice_priority, /* default */ NICE_DEFAULT_VALUE, /* print */ TRUE, NULL); #endif /* register all simulator-specific options */ sim_reg_options (sim_odb); /* parse simulator options */ exec_index = -1; #ifdef REMOVE_MY_CODE fprintf (stderr, "sim_odb %lu \n", (long) sim_odb); fprintf (stderr, "sim: command line: "); for (i = 0; i < argc; i++) fprintf (stderr, "%s ", argv[i]); fprintf (stderr, "\n"); { char name[256]; gethostname (name, 256); fprintf (stderr, "Run on %s\n", name); } #endif opt_process_options (sim_odb, argc, argv); /* redirect I/O? */ if (sim_simout != NULL) { /* send simulator non-interactive output (STDERR) to file SIM_SIMOUT */ if (fflush (stderr)) fatal ("unable to flush stderr "); else { if (!freopen (sim_simout, "w", stderr)) fatal ("unable to redirect simulator output to file `%s'", sim_simout); } } #ifndef SMT_SS if (sim_progout != NULL) { /* redirect simulated program output to file SIM_PROGOUT */ sim_progfd = fopen (sim_progout, "w"); if (!sim_progfd) fatal ("unable to redirect program output to file `%s'", sim_progout); } #endif /* need at least two argv values to run */ if (argc < 2) { banner (stderr, argc, argv); usage (stderr, argc, argv); fprintf (stderr, "error:exit from main argc < 2\n"); exit (1); } /* opening banner */ banner (stderr, argc, argv); if (help_me) { /* print help message and exit */ usage (stderr, argc, argv); fprintf (stderr, "error:exit from main help_me\n"); exit (1); } /* seed the random number generator */ if (rand_seed == 0) { /* seed with the timer value, true random */ mysrand (time ((time_t *) NULL)); } else { /* seed with default or user-specified random number generator seed */ mysrand (rand_seed); } /* exec_index is set in orphan_fn() */ if (exec_index == -1) { /* executable was not found */ fprintf (stderr, "error: no executable specified\n"); usage (stderr, argc, argv); exit (1); } /* else, exec_index points to simulated program arguments */ /* check simulator-specific options */ sim_check_options (sim_odb, argc, argv); #ifndef _MSC_VER /* set simulator scheduling priority */ if (nice (0) < nice_priority) { if (nice (nice_priority - nice (0)) < 0) fatal ("could not renice simulator process"); } #endif /* emit the command line for later reuse */ /* copied here for easier debugging */ fprintf (stderr, "sim: command line: "); for (i = 0; i < argc; i++) fprintf (stderr, "%s ", argv[i]); fprintf (stderr, "\n"); { char name[256]; gethostname (name, 256); fprintf (stderr, "Run on %s\n", name); } /* default architected value... */ sim_num_insn = 0; #ifdef BFD_LOADER /* initialize the bfd library */ bfd_init (); #endif /* BFD_LOADER */ /* initialize the instruction decoder */ md_init_decoder (); #ifndef SMT_SS /* initialize all simulation modules */ sim_init (); #endif /* initialize architected state */ #ifdef SMT_SS sim_load_threads (argc - exec_index, argv + exec_index, envp); #else sim_load_prog (argv[exec_index], argc - exec_index, argv + exec_index, envp); #endif #ifdef SMT_SS /* initialize all simulation modules */ sim_init (); #endif #ifndef PARALLEL_EMUL /* register all simulator stats */ sim_sdb = stat_new (); sim_reg_stats (sim_sdb); #endif /* record start of execution time, used in rate stats */ sim_start_time = time ((time_t *) NULL); /* emit the command line for later reuse */ fprintf (stderr, "sim: command line: "); for (i = 0; i < argc; i++) fprintf (stderr, "%s ", argv[i]); fprintf (stderr, "\n"); { char name[256]; gethostname (name, 256); fprintf (stderr, "Run on %s\n", name); } /* output simulation conditions */ s = ctime (&sim_start_time); if (s[strlen (s) - 1] == '\n') s[strlen (s) - 1] = '\0'; #ifdef __VERSION__ #define COMPILEDWITH "gcc version " __VERSION__ #else #define COMPILEDWITH "unknown compiler" #endif fprintf (stderr, "\nsim: main.c compiled on " __DATE__ " at " __TIME__ " with " COMPILEDWITH); fprintf (stderr, "\nsim: simulation started @ %s, options follow:\n", s); opt_print_options (sim_odb, stderr, /* short */ TRUE, /* notes */ TRUE); sim_aux_config (stderr); fprintf (stderr, "\n"); /* omit option dump time from rate stats */ sim_start_time = time ((time_t *) NULL); if (init_quit) exit_now (0); running = TRUE; for (j = 0; j < 4; j++) { for (i = 0; i < NUM_COM_REGS; i++) { common_regs_s[j][i].regs_lock = 0; common_regs_s[j][i].address = 0; } } //outFile = fopen ("simOutFile.txt", "w"); // fprintf(outFile,"fanglei\n"); // fprintf test @ fanglei // fflush(outFile); // flush @ fanglei if(!strcmp(argv[9], "ilink1030.BNC")) ilink_run = 1; else ilink_run = 0; if(!strcmp(argv[9], "../../BNCfor16/em3d1030.BNC")) em3d_run = 1; else em3d_run = 0; sim_main (); /* simulation finished early */ exit_now (0); #ifdef __GNUC__ return 0; #endif }
int main(int argc, char **argv, char **envp) { char *s; int i, exit_code; simoutorder sim1(OCORE), sim2(RCORE); #ifndef _MSC_VER /* catch SIGUSR1 and dump intermediate stats */ signal(SIGUSR1, signal_sim_stats); /* catch SIGUSR2 and dump final stats and exit */ signal(SIGUSR2, signal_exit_now); #endif /* _MSC_VER */ /* register an error handler */ fatal_hook(sim_print_stats_prev); /* set up a non-local exit point */ if ((exit_code = setjmp(sim_exit_buf)) != 0) { /* special handling as longjmp cannot pass 0 */ if(isSim1Run) { exit_now(exit_code-1, &sim1); isSim1Run = false; goto sim2ex; } else if(isSim2Run) { exit_now(exit_code-1, &sim2); isSim2Run = false; exit(0); } else { fprintf(stderr, "\n\n fatal error during exit\n"); } } banner(stderr, argc, argv); sim_num_insn = 0; #ifdef BFD_LOADER /* initialize the bfd library */ bfd_init(); #endif /* BFD_LOADER */ /* initialize the instruction decoder */ md_init_decoder(); init( &sim1, argc, argv, envp ); init( &sim2, argc, argv, envp ); /* record start of execution time, used in rate stats */ sim_start_time = time((time_t *)NULL); /* emit the command line for later reuse */ fprintf(stderr, "sim: command line: "); for (i=0; i < argc; i++) fprintf(stderr, "%s ", argv[i]); fprintf(stderr, "\n"); /* output simulation conditions */ s = ctime(&sim_start_time); if (s[strlen(s)-1] == '\n') s[strlen(s)-1] = '\0'; fprintf(stderr, "\nsim: simulation started @ %s, options follow:\n", s); opt_print_options(sim1.sim_odb, stderr, /* short */TRUE, /* notes */TRUE); sim1.sim_aux_config(stderr); fprintf(stderr, "\n"); /* omit option dump time from rate stats */ sim_start_time = time((time_t *)NULL); if (init_quit) exit_now(0, &sim1); running = TRUE; isSim1Run = true; sim1.sim_main(); running = TRUE; sim2ex: isSim2Run = true; sim2.sim_main(); /* simulation finished early */ exit_now(0, &sim1); return 0; }