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[]){return sim_main(argc,argv);}
int main(int argc, char *argv[]) {plusmode=0;return sim_main(argc,argv);}
int main(int argc, char *argv[]) { int i, n; bool wasRunning = FALSE; bool save_cfg = FALSE; bool change_settings_ui(menu_e *menu, u1_t key, bool *skip_first, cfg_t *cfg); bool show_ip = FALSE; bool config_valid, config_key = FALSE; bool config_ip = FALSE, config_nm = FALSE, config_gw = FALSE, config_am = FALSE; u4_t key; menu_e menu; int addr_mode; int ip[4], nm[4], gw[4], bc[4]; FILE *cfp, *efp; char *config_file = ROOT_DIR "/.5370.config"; cfg_t *cfg = &cfg_buf; dsp_7seg_init(FALSE); // panic routine can't use display until bus is setup // silently ignores unrecognized arguments for (i=1; i<argc; i++) { if (strcmp(argv[i], "-bg") == 0) background_mode = TRUE; if (strcmp(argv[i], "-ip") == 0) show_ip = TRUE; if (strcmp(argv[i], "-no") == 0) menu_action = FALSE; if (strcmp(argv[i], "?")==0 || strcmp(argv[i], "-?")==0 || strcmp(argv[i], "--?")==0 || strcmp(argv[i], "-h")==0 || strcmp(argv[i], "h")==0 || strcmp(argv[i], "-help")==0 || strcmp(argv[i], "--h")==0 || strcmp(argv[i], "--help")==0) { printf( "-rcl|-recall [name] load key settings from named profile\n" "-hpib-hard use the original HPIB hardware interface, assuming installed\n" "-hpib-sim simulate the HPIB interface in software (debug mode)\n" "-hpib-net simulate and re-direct transfers over an Ethernet connection\n" "-ip show IP address of Ethernet interface and exit\n" ); xit(0); } } lprintf("HP%s v%d.%d\n", INST_STR, FIRMWARE_VER_MAJ, FIRMWARE_VER_MIN); lprintf("compiled: %s %s\n", __DATE__, __TIME__); sim_args(TRUE, argc, argv); hpib_args(TRUE, argc, argv); sim_init(); web_server_init(); if (!menu_action) printf("menu action disabled\n"); reset: // To support the action of the 'reset' key most code files have a reset routine that zeros static variables. // This is similar to the C runtime idea of zeroing the bss when a program is first run. if (wasRunning) { wasRunning = FALSE; net_reset(NET_HPIB); net_reset(NET_TELNET); web_server_stop(); skip_first = save_cfg = config_key = config_ip = config_nm = config_gw = config_am = FALSE; } sim_reset(); if (!(bus_read(RREG_LDACSR) & DSR_VOK)) { lprintf("waiting for 5370 power\n"); usleep(1000000); while (!(bus_read(RREG_LDACSR) & DSR_VOK)) { sched_yield(); usleep(250000); } lprintf("5370 power on\n"); usleep(1000000); } else { lprintf("5370 is powered on\n"); } // display firmware version dsp_7seg_init(TRUE); dsp_7seg_str(DSP_LEFT, INST_STR, DSP_CLEAR); dsp_7seg_chr(POS(10), 'v'); dsp_7seg_num(POS(11), POS_IS_LSD, FIRMWARE_VER_MAJ, DEFAULT_WIDTH, SPACE_FILL); dsp_7seg_num(POS(12), POS_IS_MSD, FIRMWARE_VER_MIN, FIELD_WIDTH(0), ZERO_FILL); dsp_7seg_dp(POS(12)); dsp_leds_clr_all(); delay(2000); if ((cfp = fopen(config_file, "r")) == NULL) { if (errno != ENOENT) sys_panic(config_file); config_valid = FALSE; } else { while (fgets(lbuf, LBUF, cfp)) { if ((sscanf(lbuf, "key 0x%x", &key) == 1) && (key == 0xcafe5370)) config_key = TRUE; else if (sscanf(lbuf, "am %d", &addr_mode) == 1) config_am = TRUE; else if (sscanf(lbuf, "ip %d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3]) == 4) config_ip = TRUE; else if (sscanf(lbuf, "nm %d.%d.%d.%d", &nm[0], &nm[1], &nm[2], &nm[3]) == 4) config_nm = TRUE; else if (sscanf(lbuf, "gw %d.%d.%d.%d", &gw[0], &gw[1], &gw[2], &gw[3]) == 4) config_gw = TRUE; else ; } assert((addr_mode == 0) || (addr_mode == 1)); menu = cfg->menu = (addr_mode == 0)? M_DHCP : M_IP; if (config_key && config_ip && config_nm && config_gw && config_am) { printf("valid config file %s\n", config_file); config_valid = TRUE; if (menu == M_IP) { printf("setting interface address\n"); sprintf(lbuf, "ifconfig eth0 %d.%d.%d.%d netmask %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3], nm[0], nm[1], nm[2], nm[3]); if (menu_action) system(lbuf); sprintf(lbuf, "route add default %d.%d.%d.%d", gw[0], gw[1], gw[2], gw[3]); if (menu_action) system(lbuf); } } else { printf("invalid config file %s\n", config_file); config_valid = FALSE; } fclose(cfp); } if (!config_valid) { menu = cfg->menu = M_DHCP; // try DHCP first if not valid config } #define ENET_RETRY 20 if (menu == M_DHCP) { // see if interface configured by DHCP gw[3]=gw[2]=gw[1]=gw[0]=0; // ifconfig doesn't tell us the gateway, only the broadcast which we don't care about // sometimes the link is slow to come up, so retry a few times for (i=0; i<ENET_RETRY; i++) { if ((efp = popen("ifconfig eth0", "r")) == NULL) sys_panic("ifconfig eth0"); char *lp = lbuf; n=0; while (fgets(lp, LBUF, efp)) { if ((n = sscanf(lp, "%*[ ]inet addr:%d.%d.%d.%d Bcast:%d.%d.%d.%d Mask:%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3], &bc[0], &bc[1], &bc[2], &bc[3], &nm[0], &nm[1], &nm[2], &nm[3])) == 12) break; } pclose(efp); if (n == 12) break; delay(1000); } } else { i=0; // interface configured manually above } if (i != ENET_RETRY) { for (i=0; i<4; i++) { cfg->ip[i] = ip[i]; cfg->nm[i] = nm[i]; cfg->gw[i] = gw[i]; } if (menu == M_DHCP) lprintf("via DHCP "); lprintf("eth0: ip %d.%d.%d.%d mask %d.%d.%d.%d ", ip[0], ip[1], ip[2], ip[3], nm[0], nm[1], nm[2], nm[3]); if (menu != M_DHCP) lprintf("gw %d.%d.%d.%d", gw[0], gw[1], gw[2], gw[3]); lprintf("\n"); dsp_7seg_str(DSP_LEFT, "ip", DSP_CLEAR); display_ipaddr(cfg->ip); } else { lprintf("eth0: not configured from DHCP?"); dsp_7seg_str(DSP_LEFT, "no dhcp?", DSP_CLEAR); } if (!config_valid && (i == ENET_RETRY)) { // configuration not valid, DHCP failed, so set some defaults menu = cfg->menu = M_IP; bcopy(default_ipinfo, cfg->if_ipinfo, sizeof(default_ipinfo)); save_cfg = TRUE; } if (show_ip) xit(0); delay(2000); // show ip on display for a moment before continuing net_connect(NET_HPIB, SERVER, NULL, HPIB_TCP_PORT); net_connect(NET_TELNET, SERVER, NULL, TELNET_TCP_PORT); web_server_start(); // place a call here to setup your measurement extension code meas_extend_example_init(); // reset key held down during a reboot -- drop into menu mode preempt_reset_key(TRUE); // while in the boot routine the reset key either starts the app or saves the changed config app_state = S_MENU; while (1) { u1_t key; sim_input(); // for remote debugging of menu mode key = handler_dev_display_read(RREG_KEY_SCAN); // called instead of bus_read() so simulated keys will be returned switch(app_state) { case S_MENU: if (key != KEY(RESET)) { app_state = S_START; break; } dsp_7seg_str(DSP_LEFT, "ready", DSP_CLEAR); printf("ready\n"); dsp_led_set(RESET); wait_key_release(); dsp_led_clr(RESET); dsp_7seg_str(DSP_LEFT, "chg settings", DSP_CLEAR); printf("menu mode\n"); skip_first = TRUE; menu = M_HALT; // first menu item displayed // light up the keys valid during menu mode for (i=0; settings_keys[i].key; i++) { dsp_led_set(settings_keys[i].key); } app_state = S_MENU_POLL; break; case S_MENU_POLL: if (key == KEY(RESET)) { dsp_led_set(RESET); wait_key_release(); dsp_led_clr(RESET); app_state = S_MENU_DONE; break; } if (change_settings_ui(&menu, key, &skip_first, cfg)) save_cfg = TRUE; break; case S_MENU_DONE: if (!skip_first && (menu == M_HALT)) { // Debian takes a while to halt, but nicely clears the GPIOs so the // display goes blank right when halted. // Angstrom with Gnome disabled halts very fast, but doesn't // clear the GPIOs like Debian. So we get the PRU to poll the LEDs // until they go off, then blank the display. dsp_7seg_str(DSP_LEFT, " halting...", DSP_CLEAR); printf("halting...\n"); #ifdef DIST_DEBIAN if (menu_action) system("halt"); exit(0); #endif #ifdef DIST_ANGSTROM dsp_7seg_chr(POS(0), ' '); // preload address & data send_pru_cmd(PRU_HALT); if (menu_action) system("halt"); exit(0); #endif } else if (menu == M_CANCEL || (skip_first && (menu == M_HALT))) { app_state = S_START; break; } else { if (menu != M_DHCP) menu = M_IP; if (menu != cfg->menu) save_cfg = TRUE; } if (save_cfg) { dsp_7seg_str(DSP_LEFT, "config changed", DSP_CLEAR); delay(2000); cfg->menu = menu; if (menu == M_DHCP) { dsp_7seg_str(DSP_LEFT, "using dhcp mode", DSP_CLEAR); } else { dsp_7seg_str(DSP_LEFT, "using ip mode", DSP_CLEAR); } delay(2000); dsp_7seg_str(DSP_LEFT, "saving config", DSP_CLEAR); if ((cfp = fopen(config_file, "w")) == NULL) sys_panic(config_file); printf("writing config file %s\n", config_file); fprintf(cfp, "key 0xcafe5370\n"); fprintf(cfp, "am %d\n", (cfg->menu == M_DHCP)? 0:1); fprintf(cfp, "ip %d.%d.%d.%d\n", cfg->ip[0], cfg->ip[1], cfg->ip[2], cfg->ip[3]); fprintf(cfp, "nm %d.%d.%d.%d\n", cfg->nm[0], cfg->nm[1], cfg->nm[2], cfg->nm[3]); fprintf(cfp, "gw %d.%d.%d.%d\n", cfg->gw[0], cfg->gw[1], cfg->gw[2], cfg->gw[3]); fclose(cfp); delay(2000); } app_state = S_START; break; case S_START: if (wasRunning) { // if previous sim was interrupted must reset before starting new one goto reset; } preempt_reset_key(FALSE); sim_main(); preempt_reset_key(TRUE); handler_dev_display_read(RREG_KEY_SCAN); // flush extra sim reset key, if any delay(1000); // this sim was interrupted, so can't restart a new sim without doing a reset first wasRunning = TRUE; // if key still down after one second delay enter menu mode, else treat as simple reset if (handler_dev_display_read(RREG_KEY_SCAN) == KEY(RESET)) { app_state = S_MENU; } else { goto reset; } break; } } 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 ; 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 }