int main(int argc, char **argv) { uint64_t t; int myargc = 2; ///char **myargv; // printf("\n argc val =%d",argc); /// argc = 2; //// argv[0] = "myself"; //char *name = "/home/prajakta/praj_multi2sim_RandD/guestos_multi2sim/mytest/simple"; //printf("\n The length of the hardcoded complete path of simple file is : %d\n", strlen(name)); //argv[1] = "/home/prajakta/praj_multi2sim_RandD/guestos_multi2sim/mytest/simple"; fprintf(stderr, "********************************************************"); fprintf(stderr, "\n WELCOME TO GUESTOS\n"); fprintf(stderr, "********************************************************\n"); //Subhajit Changes /* Options */ opt_init(); sim_reg_options(); /////////////////////////////////////// ///// p_reg_options(); /// cache_system_reg_options(); //// opt_check_options(&argc, argv); ///////////////////////////////////////////// /* Initialize */ ke_init(); boot(); ///// install_sighandler(); // printf("\n enter path:"); // fgets(user_prog_path,200,stdin); //for( ii=0;ii<strlen(user_prog_path);ii++) // argv[1][ii]=user_prog_path[ii]; //char * origargv= argv; //argv=argv++; //argv[1]=(char *)user_prog_path; //The following lines are written to take the file path from the user and removing the last string terminating character.... /* argv[1] = (char *)malloc(strlen( (user_prog_path) - 1) * sizeof(char)); for(i = 0; i < strlen(user_prog_path) - 1;i++) argv[1][i] = user_prog_path[i];*/ //argv=origargv; //argv=argv++; //// argv=user_prog_path; //argv=origargv; ///fgets(user_prog_path,max_path_length,stdin); shell(); if (*configfile) { /// printf("\n Entered inside checking\n\n") ; opt_check_config(configfile); } //////////printf("\n User entered path of binary in main : %s",user_prog_path); //strncpy(*(argv+1),user_prog_path,max_path_length); // strncpy(myargv[0],user_prog_path,200); // strcpy(argv[1],user_prog_path); //printf("\nafter strcpy"); //argv[1] = user_prog_path; //printf("\n\n\\nnnnnnnnnnnnnnnnnnnnnnnn"); // printf("\n Value of argv[1] is : %s\n\n\n", argv[1]); // printf("\n Length of file name in argv[1] = %d\n", strlen(argv[1])); //strncpy(argv[1],user_prog_path,max_path_length); ///////strcpy(argv[0],user_prog_path); ///printf("\n the rcvd pa ths is %s \n",user_prog_path); ///printf("\n the rcvd pa ths is %s \n",user_prog_path); ///printf("\n the rcvd pa ths is %s \n",user_prog_path); /* Load programs from configuration file and command line. */ /////// if (*ctxconfig) ld_load_prog_from_ctxconfig(ctxconfig); ///////////////////if (argc >= 1) /// ld_load_prog_from_cmdline(argc - 1, user_prog_path ); //////////// ld_load_prog_from_cmdline(argc - 1, argv + 1); /// ld_load_prog_from_cmdline(argc - 1, myargv); /* Simulation loop */ signal(SIGINT, &sim_signal_handler); signal(SIGABRT, &sim_signal_handler); signal(SIGFPE, &sim_signal_handler); signal(SIGUSR2, &sim_signal_handler); //raise(8); //raise(10); //raise(12); while (!sigint_received) { /* Break point */ if (break_point && ke->context_list_head->regs->eip == break_point) { regs_dump(ke->context_list_head->regs, stdout); break; } /* Run an instruction from each running context */ ke_run(); sim_inst += ke->running_count; if (!ke->context_list_head) break; /* Stop conditions */ sim_cycle++; if ((sim_cycle >= max_cycles && max_cycles) || (sim_inst >= max_inst && max_inst)) { regs_dump(isa_regs, stdout); ke_dump(stdout); break; } if (sim_cycle == inst_reset && inst_reset) isa_inst_stat_reset(); if (*inst_stop && !strcmp(isa_inst.format, inst_stop)) panic("instruction '%s' found", inst_stop); } /* Finalization */ ke_done(); ///opt_done(); ///debug_done(); mhandle_done(); return 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, "-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; 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 }