Esempio n. 1
0
void
main(void)
{
  struct stat_sdb_t *sdb;
  struct stat_stat_t *stat, *stat1, *stat2, *stat3, *stat4, *stat5;
  int an_int;
  unsigned int a_uint;
  float a_float;
  double a_double;
  static char *my_imap[8] = {
    "foo", "bar", "uxxe", "blah", "gaga", "dada", "mama", "googoo"
  };

  /* make stats database */
  sdb = stat_new();

  /* register stat variables */
  stat_reg_int(sdb, "stat.an_int", "An integer stat variable.",
	       &an_int, 1, NULL);
  stat_reg_uint(sdb, "stat.a_uint", "An unsigned integer stat variable.",
		&a_uint, 2, "%u (unsigned)");
  stat_reg_float(sdb, "stat.a_float", "A float stat variable.",
		 &a_float, 3, NULL);
  stat_reg_double(sdb, "stat.a_double", "A double stat variable.",
		  &a_double, 4, NULL);
  stat_reg_formula(sdb, "stat.a_formula", "A double stat formula.",
		   "stat.a_float / stat.a_uint", NULL);
  stat_reg_formula(sdb, "stat.a_formula1", "A double stat formula #1.",
		   "2 * (stat.a_formula / (1.5 * stat.an_int))", NULL);
  stat_reg_formula(sdb, "stat.a_bad_formula", "A double stat formula w/error.",
		   "stat.a_float / (stat.a_uint - 2)", NULL);
  stat = stat_reg_dist(sdb, "stat.a_dist", "An array distribution.",
		       0, 8, 1, PF_ALL, NULL, NULL, NULL);
  stat1 = stat_reg_dist(sdb, "stat.a_dist1", "An array distribution #1.",
			0, 8, 4, PF_ALL, NULL, NULL, NULL);
  stat2 = stat_reg_dist(sdb, "stat.a_dist2", "An array distribution #2.",
			0, 8, 1, (PF_PDF|PF_CDF), NULL, NULL, NULL);
  stat3 = stat_reg_dist(sdb, "stat.a_dist3", "An array distribution #3.",
			0, 8, 1, PF_ALL, NULL, my_imap, NULL);
  stat4 = stat_reg_sdist(sdb, "stat.a_sdist", "A sparse array distribution.",
			 0, PF_ALL, NULL, NULL);
  stat5 = stat_reg_sdist(sdb, "stat.a_sdist1",
			 "A sparse array distribution #1.",
			 0, PF_ALL, "0x%08lx        %10lu %6.2f %6.2f",
			 NULL);

  /* print initial stats */
  fprintf(stdout, "** Initial stats...\n");
  stat_print_stats(sdb, stdout);

  /* adjust stats */
  an_int++;
  a_uint++;
  a_float *= 2;
  a_double *= 4;

  stat_add_sample(stat, 8);
  stat_add_sample(stat, 8);
  stat_add_sample(stat, 1);
  stat_add_sample(stat, 3);
  stat_add_sample(stat, 4);
  stat_add_sample(stat, 4);
  stat_add_sample(stat, 7);

  stat_add_sample(stat1, 32);
  stat_add_sample(stat1, 32);
  stat_add_sample(stat1, 1);
  stat_add_sample(stat1, 12);
  stat_add_sample(stat1, 17);
  stat_add_sample(stat1, 18);
  stat_add_sample(stat1, 30);

  stat_add_sample(stat2, 8);
  stat_add_sample(stat2, 8);
  stat_add_sample(stat2, 1);
  stat_add_sample(stat2, 3);
  stat_add_sample(stat2, 4);
  stat_add_sample(stat2, 4);
  stat_add_sample(stat2, 7);

  stat_add_sample(stat3, 8);
  stat_add_sample(stat3, 8);
  stat_add_sample(stat3, 1);
  stat_add_sample(stat3, 3);
  stat_add_sample(stat3, 4);
  stat_add_sample(stat3, 4);
  stat_add_sample(stat3, 7);

  stat_add_sample(stat4, 800);
  stat_add_sample(stat4, 800);
  stat_add_sample(stat4, 1123);
  stat_add_sample(stat4, 3332);
  stat_add_sample(stat4, 4000);
  stat_add_samples(stat4, 4001, 18);
  stat_add_sample(stat4, 7);

  stat_add_sample(stat5, 800);
  stat_add_sample(stat5, 800);
  stat_add_sample(stat5, 1123);
  stat_add_sample(stat5, 3332);
  stat_add_sample(stat5, 4000);
  stat_add_samples(stat5, 4001, 18);
  stat_add_sample(stat5, 7);

  /* print final stats */
  fprintf(stdout, "** Final stats...\n");
  stat_print_stats(sdb, stdout);

  /* all done */
  stat_delete(sdb);
  exit(0);
}
Esempio n. 2
0
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, 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
}