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; }
/* * Initalizes a thread context. This includes loading the binary into memory, * parsing command line options from the argument file, and setting up infile * and outfile for redirecting stdin, stdout, and stderr for this process. * * NOTE: Some of the code in this function, along with the concept of the ".arg" * file, was adopted from Dean Tullsen's SMTSIM: * * Simulaton and Modeling of a Simultaneous Multithreading Processor, * D.M. Tullsen, in the 22nd Annual Computer Measurement Group Conference, * December, 1996. * */ void init_thread(std::vector<std::string> env, std::string filename, int curcontext) { char buffer[256]; // open the file containing the command line arguments for this thread FILE * argfile = fopen(filename.c_str(), "r"); contexts[curcontext].filename = filename; if(argfile == NULL) { std::cerr << "ERROR: cannot open argument file: " << filename << std::endl; exit(-1); } // Anything before the first # is the fastfwd distance. int retcode = fscanf(argfile, "%s", buffer); if(buffer[0] != '#') { contexts[curcontext].fastfwd_cnt = atol(buffer); contexts[curcontext].fastfwd_left = contexts[curcontext].fastfwd_cnt; if(!fscanf(argfile, "%s", buffer)) /* this should be the # */ { fatal("Deformed .arg file, could not find \'#\'"); } } std::vector<std::string> locargv; //Until we hit a redirecter, we retain the arguments from the .arg file bool gather = TRUE; while(1) { retcode = fscanf(argfile, "%s", buffer); if(retcode == EOF) { fclose(argfile); std::cerr << "args: "; for(unsigned int i=0;i<locargv.size();i++) { std::cerr << i << ": " << locargv[i] << " "; } std::cerr << std::endl; //actually load the program into memory sim_load_prog(locargv[0], locargv, env); return; } //handle input redirection (of stdin) else if(std::string(buffer) == "<") { if(!fscanf(argfile, "%s", buffer)) { fatal("Deformed .arg file, could not read redirected input"); } std::cerr << "Opening " << buffer << " as redirected input:"; md_gpr_t temp = contexts[curcontext].file_table.opener(buffer,O_RDONLY, S_IRUSR | S_IRWXU | S_IRWXG, 0); if(temp == (md_gpr_t)-1) { std::cerr << " - failed: couldn't open for reading" << std::endl; exit(1); } std::cerr << " fd: " << temp << std::endl; gather = FALSE; } //handle output redirection (of stdout) else if(std::string(buffer) == ">") { if(!fscanf(argfile, "%s", buffer)) { fatal("Deformed .arg file, could not read redirected output (stdout)"); } std::cerr << "Opening " << buffer << " as redirected output (stdout)"; md_gpr_t temp = contexts[curcontext].file_table.opener(buffer,O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG, 1); if(temp == (md_gpr_t)-1) { std::cerr << " - failed: couldn't open for reading" << std::endl; exit(1); } std::cerr << " fd: " << temp << std::endl; gather = FALSE; } //handle output redirection (of stderr) else if(std::string(buffer) == "2>" || std::string(buffer) == ">&" || std::string(buffer) == "2>>") { if(!fscanf(argfile, "%s", buffer)) { fatal("Deformed .arg file, could not read redirected output (stderr)"); } std::cerr << "Opening " << buffer << " as redirected output (stderr)"; md_gpr_t temp = contexts[curcontext].file_table.opener(buffer,O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG, 2); if(temp == (md_gpr_t)-1) { std::cerr << " - failed: couldn't open for reading" << std::endl; exit(1); } std::cerr << " fd: " << temp << std::endl; } if(gather) { locargv.push_back(buffer); } } }
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 }