/* handle `-dumpconfig' builtin option, print options from file argument */ static void dump_config(struct opt_odb_t *odb, /* option data base */ char *fname) /* output file name, "-" == stdout */ { FILE *fd; /* open output file stream */ if (!strcmp(fname, "-")) fd = stderr; else { fd = fopen(fname, "w"); if (!fd) fatal("could not open file `%s'", fname); } /* print current option values to output stream */ opt_print_options(odb, fd, /* long */FALSE, /* !notes */FALSE); /* close output stream, if not a standard stream */ if (fd != stdout && fd != stderr) fclose(fd); }
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; }
void main(int argc, char **argv) { /* build the command line options database */ odb = opt_new(/* no orphan fn */NULL); opt_reg_flag(odb, "-h", "print help message", &help_me, /* default */FALSE, /* !print */FALSE, NULL); opt_reg_flag(odb, "-defs", "make internal defs", &make_defs, /* default */FALSE, /* print */TRUE, NULL); opt_reg_string(odb, "-load", "load an EXO file", &load_file, /* default */NULL, /* print */TRUE, /* format */NULL); opt_reg_string(odb, "-save", "save an EXO file", &save_file, /* default */NULL, /* print */TRUE, /* format */NULL); opt_reg_flag(odb, "-print", "print the EXO DB to stdout", &print_db, /* default */FALSE, /* print */TRUE, /* format */NULL); /* process the command line options */ opt_process_options(odb, argc, argv); if (help_me) { /* print help message and exit */ usage(stderr, argc, argv); exit(1); } /* print options used */ opt_print_options(odb, stderr, /* short */TRUE, /* notes */TRUE); if (load_file) { ZFILE *exo_stream; struct exo_term_t *exo; exo_stream = myzfopen(load_file, "r"); if (!exo_stream) fatal("could not open EXO file `%s'", load_file); while ((exo = exo_read(exo_stream->fd)) != NULL) exo_db = exo_chain(exo_db, exo); myzfclose(exo_stream); } if (make_defs) { struct exo_term_t *list, *array, *a, *b, *c, *d, *e, *f, *g, *h, *i; char *data = "This is a test to see if blobs really work..."; char *data1 = "This is a test to see if blobs really work..." "This is a test to see if blobs really work..." "This is a test to see if blobs really work..." "This is a test to see if blobs really work..." "This is a test to see if blobs really work..." "This is a test to see if blobs really work..." "This is a test to see if blobs really work..." "This is a test to see if blobs really work..."; unsigned char data2[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; exo_db = exo_chain(exo_db, exo_new(ec_string, "** basic types tests **")); exo_db = exo_chain(exo_db, a = exo_new(ec_integer, (exo_integer_t)42)); exo_db = exo_chain(b = exo_new(ec_float, (exo_float_t)42.0), exo_db); exo_db = exo_chain(exo_db, c = exo_new(ec_char, (int)'x')); exo_db = exo_chain(exo_db, exo_new(ec_char, (int)'\n')); exo_db = exo_chain(exo_db, exo_new(ec_char, (int)'\b')); exo_db = exo_chain(exo_db, exo_new(ec_char, (int)'\x02')); exo_db = exo_chain(exo_db, exo_new(ec_char, (int)'\xab')); exo_db = exo_chain(exo_db, exo_new(ec_string, "this is a test...")); exo_db = exo_chain(exo_db, d = exo_new(ec_string, "this is\na test...\n")); exo_db = exo_chain(exo_db, exo_new(ec_string, "a test... <<\\\b>>\n")); exo_db = exo_chain(exo_db, exo_new(ec_string, "** deep copy tests **")); exo_db = exo_chain(exo_db, exo_deepcopy(d)); exo_db = exo_chain(exo_db, exo_deepcopy(c)); exo_db = exo_chain(exo_db, exo_deepcopy(b)); exo_db = exo_chain(exo_db, exo_deepcopy(a)); exo_db = exo_chain(exo_db, exo_new(ec_string, "** list tests **")); exo_db = exo_chain(exo_db, exo_new(ec_list, exo_deepcopy(d), exo_deepcopy(c), exo_deepcopy(b), exo_deepcopy(a), NULL)); exo_db = exo_chain(exo_db, exo_new(ec_list, NULL)); exo_db = exo_chain(exo_db, exo_new(ec_list, exo_new(ec_list, NULL), exo_new(ec_list, NULL), exo_new(ec_list, exo_deepcopy(a), NULL), NULL)); list = exo_deepcopy(a); list = exo_chain(list, exo_deepcopy(b)); list = exo_chain(list, exo_deepcopy(a)); list = exo_chain(list, exo_deepcopy(b)); list = exo_chain(exo_deepcopy(c), list); exo_db = exo_chain(exo_db, e = exo_new(ec_list, list, NULL)); exo_db = exo_chain(exo_db, exo_new(ec_list, exo_deepcopy(e), exo_new(ec_list, NULL), exo_deepcopy(e), exo_deepcopy(a), NULL)); exo_db = exo_chain(exo_db, exo_new(ec_string, "** array tests **")); exo_db = exo_chain(exo_db, exo_new(ec_array, 16, NULL)); f = array = exo_new(ec_array, 16, NULL); EXO_ARR(array, 2) = exo_deepcopy(e); EXO_ARR(array, 3) = exo_deepcopy(a); EXO_ARR(array, 4) = exo_deepcopy(c); EXO_ARR(array, 6) = exo_deepcopy(EXO_ARR(array, 2)); EXO_ARR(array, 7) = exo_deepcopy(EXO_ARR(array, 1)); exo_db = exo_chain(exo_db, array); exo_db = exo_chain(exo_db, exo_new(ec_array, 4, exo_deepcopy(a), exo_deepcopy(e), exo_deepcopy(c), exo_deepcopy(f), NULL)); exo_db = exo_chain(exo_db, exo_new(ec_string, "** token tests **")); #define SYM1 1 #define SYM2 2 exo_intern_as("sym1", SYM1); exo_intern_as("sym2", SYM2); g = exo_new(ec_token, "sym1"), exo_db = exo_chain(exo_db, exo_new(ec_list, g, exo_new(ec_integer, (exo_integer_t) g->as_token.ent->token), NULL)); h = exo_new(ec_token, "sym2"), exo_db = exo_chain(exo_db, exo_new(ec_list, h, exo_new(ec_integer, (exo_integer_t) h->as_token.ent->token), NULL)); i = exo_new(ec_token, "sym3"), exo_db = exo_chain(exo_db, exo_new(ec_list, i, exo_new(ec_integer, (exo_integer_t) i->as_token.ent->token), NULL)); /* das blobs */ exo_db = exo_chain(exo_db, exo_new(ec_blob, strlen(data), data)); exo_db = exo_chain(exo_db, exo_new(ec_blob, strlen(data1), data1)); exo_db = exo_chain(exo_db, exo_new(ec_blob, sizeof(data2), data2)); } if (print_db) { struct exo_term_t *exo; /* emit header comment */ fprintf(stdout, "\n/* EXO DB */\n\n"); fprintf(stdout, "/* EXO save file, file format version %d.%d */\n\n", EXO_FMT_MAJOR, EXO_FMT_MINOR); /* emit all defs */ for (exo=exo_db; exo != NULL; exo=exo->next) { exo_print(exo, stdout); fprintf(stdout, "\n\n"); } } if (save_file) { ZFILE *exo_stream; struct exo_term_t *exo; exo_stream = myzfopen(save_file, "w"); if (!exo_stream) fatal("could not open EXO file `%s'", save_file); /* emit header comment */ fprintf(exo_stream->fd, "/* EXO save file, file format version %d.%d */\n\n", EXO_FMT_MAJOR, EXO_FMT_MINOR); /* emit all defs */ for (exo=exo_db; exo != NULL; exo=exo->next) { exo_print(exo, exo_stream->fd); fprintf(exo_stream->fd, "\n\n"); } myzfclose(exo_stream); } }
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; }
void main(int argc, char **argv) { struct opt_odb_t *odb; int n_int_vars, n_uint_vars, n_float_vars, n_double_vars; int n_enum_vars, n_enum_eval_vars, n_flag_vars, n_string_vars; int int_var, int_vars[MAX_VARS]; unsigned int uint_var, uint_vars[MAX_VARS]; float float_var, float_vars[MAX_VARS]; double double_var, double_vars[MAX_VARS]; int flag_var, flag_vars[MAX_VARS]; char *string_var, *string_vars[MAX_VARS]; enum etest_t { enum_a, enum_b, enum_c, enum_d, enum_NUM }; static char *enum_emap[enum_NUM] = { "enum_a", "enum_b", "enum_c", "enum_d" }; static int enum_eval[enum_NUM] = { enum_d, enum_c, enum_b, enum_a }; int enum_var, enum_vars[MAX_VARS]; int enum_eval_var, enum_eval_vars[MAX_VARS]; /* get an options processor */ odb = opt_new(f_orphan_fn); opt_reg_int(odb, "-opt:int", "This is an integer option.", &int_var, 1, /* print */TRUE, /* default format */NULL); opt_reg_int_list(odb, "-opt:int:list", "This is an integer list option.", int_vars, MAX_VARS, &n_int_vars, 2, /* print */TRUE, /* default format */NULL); opt_reg_uint(odb, "-opt:uint", "This is an unsigned integer option.", &uint_var, 3, /* print */TRUE, /* default format */NULL); opt_reg_uint_list(odb, "-opt:uint:list", "This is an unsigned integer list option.", uint_vars, MAX_VARS, &n_uint_vars, 4, /* print */TRUE, /* default format */NULL); opt_reg_float(odb, "-opt:float", "This is a float option.", &float_var, 5.0, /* print */TRUE, /* default format */NULL); opt_reg_float_list(odb, "-opt:float:list", "This is a float list option.", float_vars, MAX_VARS, &n_float_vars, 6.0, /* print */TRUE, /* default format */NULL); opt_reg_double(odb, "-opt:double", "This is a double option.", &double_var, 7.0, /* print */TRUE, /* default format */NULL); opt_reg_double_list(odb, "-opt:double:list", "This is a double list option.", double_vars, MAX_VARS, &n_double_vars, 8.0, /* print */TRUE, /* default format */NULL); opt_reg_enum(odb, "-opt:enum", "This is an enumeration option.", &enum_var, "enum_a", enum_emap, /* index map */NULL, enum_NUM, /* print */TRUE, /* default format */NULL); opt_reg_enum_list(odb, "-opt:enum:list", "This is a enum list option.", enum_vars, MAX_VARS, &n_enum_vars, "enum_b", enum_emap, /* index map */NULL, enum_NUM, /* print */TRUE, /* default format */NULL); opt_reg_enum(odb, "-opt:enum:eval", "This is an enumeration option w/eval.", &enum_eval_var, "enum_b", enum_emap, enum_eval, enum_NUM, /* print */TRUE, /* default format */NULL); opt_reg_enum_list(odb, "-opt:enum:eval:list", "This is a enum list option w/eval.", enum_eval_vars, MAX_VARS, &n_enum_eval_vars, "enum_a", enum_emap, enum_eval, enum_NUM, /* print */TRUE, /* default format */NULL); opt_reg_flag(odb, "-opt:flag", "This is a boolean flag option.", &flag_var, FALSE, /* print */TRUE, /* default format */NULL); opt_reg_flag_list(odb, "-opt:flag:list", "This is a boolean flag list option.", flag_vars, MAX_VARS, &n_flag_vars, TRUE, /* print */TRUE, /* default format */NULL); opt_reg_string(odb, "-opt:string", "This is a string option.", &string_var, "a:string", /* print */TRUE, /* default format */NULL); opt_reg_string_list(odb, "-opt:string:list", "This is a string list option.", string_vars, MAX_VARS, &n_string_vars, "another:string", /* print */TRUE, /* default format */NULL); /* parse options */ opt_process_options(odb, argc, argv); /* print options */ fprintf(stdout, "## Current Option Values ##\n"); opt_print_options(odb, stdout, /* long */FALSE, /* notes */TRUE); /* all done */ opt_delete(odb); exit(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; }