int main(int argc, char **argv, char **env) { float speed; #ifndef WITH_SERIAL_PTY set_conio_terminal_mode(); #endif Verilated::commandArgs(argc, argv); dut = new Vdut; Verilated::traceEverOn(true); tfp = new VerilatedVcdC; dut->trace(tfp, 99); tfp->open("dut.vcd"); struct sim s; sim_init(&s); #ifdef WITH_SERIAL_PTY console_init(&s); console_open(&s); #endif #ifdef WITH_ETH eth_init(&s, "/dev/net/tap0", "tap0"); // XXX get this from /tmp/simethernet eth_open(&s); #endif s.run = true; while(s.run) { sim_tick(&s); if(SYS_CLK) { #ifdef WITH_SERIAL if(console_service(&s) != 0) s.run = false; #endif #ifdef WITH_ETH ethernet_service(&s); #endif } } s.end = clock(); speed = (s.tick/2)/((s.end-s.start)/CLOCKS_PER_SEC); printf("average speed: %3.3f MHz\n\r", speed/1000000); tfp->close(); #ifdef WITH_SERIAL_PTY console_close(&s); #endif #ifdef WITH_ETH eth_close(&s); #endif exit(0); }
/* ---------------------------------------------------------------------[<]- Function: service_begin Synopsis: depending on arguments (from the command line): -i: install service (windows) -u: remove service (windows) -d: runs service in console mode (windows) -h: basic help information (windows) -d: runs service in background (UNIX / Linux) if no arguments, the service is actually started. NOTE: with Windows, the working directory is set to the one where the binary program stands. Returns: 0 is everything is OK, negative error code otherwise ---------------------------------------------------------------------[>]-*/ int service_begin ( int argc, char **argv, SMT_AGENTS_INIT_FCT *init_fct, SMT_AGENTS_TERM_FCT *term_fct, const char *appl_version) { int action; int rc = 0; #if (defined(WIN32)) static char buffer [LINE_MAX]; char *p_char; SERVICE_TABLE_ENTRY dispatch_table [] = { { NULL, (LPSERVICE_MAIN_FUNCTION) service_main }, { NULL, NULL } }; /* Change to the correct working directory, where config file stands */ GetModuleFileName (NULL, buffer, LINE_MAX); if ((p_char = strrchr (buffer, '\\')) != NULL) *p_char = '\0'; SetCurrentDirectory (buffer); #endif rc = init_resources (argv[0], appl_version, init_fct, term_fct); if (rc != 0) return (1); ASSERT (application_config); /* init_resources post condition */ if (load_service_config (application_config) != 0) { free_resources (); return (1); } ASSERT (service_trace_file); /* load_service_config postcondition */ console_set_mode (CONSOLE_DATETIME); console_capture (service_trace_file, 'a'); #if (defined(WIN32)) dispatch_table [0].lpServiceName = service_name; win_version = get_windows_version (); #endif action = parse_command_line (argc, argv); if (action == ACTION_HELP) { puts (USAGE); } #if (defined(WIN32)) else if (action == ACTION_INSTALL) { if (win_version == WINDOWS_95) set_win95_service (TRUE); else install_service (); } else if (action == ACTION_UNINSTALL) { if (win_version == WINDOWS_95) set_win95_service (FALSE); else remove_service (); } else if (action == ACTION_CONSOLE) { console_mode = TRUE; console_service (argc, argv); } else if (action == ACTION_NOARG) { console_send (NULL, FALSE); if (win_version == WINDOWS_95) { hide_window (); console_mode = TRUE; console_service (argc, argv); } else if (win_version == WINDOWS_NT_3X || win_version == WINDOWS_NT_4 || win_version == WINDOWS_2000) { log_printf ("%s: initialising service ...", application_name); if (!StartServiceCtrlDispatcher (dispatch_table)) add_to_message_log ("StartServiceCtrlDispatcher failed"); } } #elif (defined(__UNIX__)) else if (action == ACTION_BACKGROUND) { const char *background_args [] = { "-s", NULL }; log_printf ("Moving into the background"); if (process_server (NULL, NULL, argc, argv, background_args) != 0) { log_printf ("Backgrounding failed. Giving up."); rc = -1; } else action = ACTION_NOARG; } if (action == ACTION_NOARG) { rc = smt_init (); if (!rc && (init_fct != NULL)) rc = (*init_fct)(application_config); if (!rc) smt_exec_full (); if (term_fct != NULL) (*term_fct)(); smt_term (); } #endif else if (action == ACTION_ERROR) puts (USAGE); free_resources (); return rc; }