"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

main.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <setjmp.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/time.h>
#include "host.h"
#include "misc.h"
#include "machine.h"
#include "endian.h"
#include "version.h"
#include "dlite.h"
#include "options.h"
#include "stats.h"
#include "loader.h"
#include "sim.h"

Include dependency graph for main.c:

Include dependency graph

Go to the source code of this file.

Defines

Functions

Variables


Define Documentation

#define NICE_DEFAULT_VALUE   0
 

Definition at line 198 of file main.c.

Referenced by main().


Function Documentation

void banner FILE *    fd,
int    argc,
char **    argv
[static]
 

Definition at line 208 of file main.c.

References s, VER_MAJOR, VER_MINOR, and VER_UPDATE.

Referenced by main().

00209 {
00210   char *s;
00211 
00212   fprintf(fd,
00213           "%s: SimpleScalar/%s Tool Set version %d.%d of %s.\n"
00214           "Copyright (c) 1994-2000 by Todd M. Austin.  All Rights Reserved.\n"
00215           "This version of SimpleScalar is licensed for academic non-commercial use only.\n"
00216           "\n",
00217           ((s = strrchr(argv[0], '/')) ? s+1 : argv[0]),
00218           VER_TARGET, VER_MAJOR, VER_MINOR, VER_UPDATE);
00219 }

void exit_now int    exit_code [static]
 

Definition at line 259 of file main.c.

References sim_print_stats(), and sim_uninit().

Referenced by main().

00260 {
00261   /* print simulation stats */
00262   sim_print_stats(stderr);
00263 
00264   /* un-initialize the simulator */
00265   sim_uninit();
00266 
00267   /* all done! */
00268   exit(exit_code);
00269 }

int main int    argc,
char **    argv,
char **    envp
 

Definition at line 272 of file main.c.

References banner(), exec_index, exit_now(), FALSE, fatal(), fatal_hook(), help_me, init_quit, md_init_decoder(), mysrand(), NICE_DEFAULT_VALUE, nice_priority, opt_new(), opt_print_options(), opt_process_options(), opt_reg_flag(), opt_reg_int(), opt_reg_string(), orphan_fn(), rand_seed, running, s, signal_exit_now(), signal_sim_stats(), sim_aux_config(), sim_check_options(), sim_chkpt_fname, sim_exit_buf, sim_init(), sim_load_prog(), sim_main(), sim_num_insn, sim_print_stats(), sim_progfd, sim_progout, sim_reg_options(), sim_reg_stats(), sim_simout, sim_start_time, stat_new(), stat_reg_uint(), TRUE, and usage().

00273 {
00274   char *s;
00275   int i, exit_code;
00276 
00277 #ifndef _MSC_VER
00278   /* catch SIGUSR1 and dump intermediate stats */
00279   signal(SIGUSR1, signal_sim_stats);
00280 
00281   /* catch SIGUSR2 and dump final stats and exit */
00282   signal(SIGUSR2, signal_exit_now);
00283 #endif /* _MSC_VER */
00284 
00285   /* register an error handler */
00286   fatal_hook(sim_print_stats);
00287 
00288   /* set up a non-local exit point */
00289   if ((exit_code = setjmp(sim_exit_buf)) != 0)
00290     {
00291       /* special handling as longjmp cannot pass 0 */
00292       exit_now(exit_code-1);
00293     }
00294 
00295   /* register global options */
00296   sim_odb = opt_new(orphan_fn);
00297   opt_reg_flag(sim_odb, "-h", "print help message",
00298                &help_me, /* default */FALSE, /* !print */FALSE, NULL);
00299   opt_reg_flag(sim_odb, "-v", "verbose operation",
00300                &verbose, /* default */FALSE, /* !print */FALSE, NULL);
00301 #ifdef DEBUG
00302   opt_reg_flag(sim_odb, "-d", "enable debug message",
00303                &debugging, /* default */FALSE, /* !print */FALSE, NULL);
00304 #endif /* DEBUG */
00305   opt_reg_flag(sim_odb, "-i", "start in Dlite debugger",
00306                &dlite_active, /* default */FALSE, /* !print */FALSE, NULL);
00307   opt_reg_int(sim_odb, "-seed",
00308               "random number generator seed (0 for timer seed)",
00309               &rand_seed, /* default */1, /* print */TRUE, NULL);
00310   opt_reg_flag(sim_odb, "-q", "initialize and terminate immediately",
00311                &init_quit, /* default */FALSE, /* !print */FALSE, NULL);
00312   opt_reg_string(sim_odb, "-chkpt", "restore EIO trace execution from <fname>",
00313                  &sim_chkpt_fname, /* default */NULL, /* !print */FALSE, NULL);
00314 
00315   /* stdio redirection options */
00316   opt_reg_string(sim_odb, "-redir:sim",
00317                  "redirect simulator output to file (non-interactive only)",
00318                  &sim_simout,
00319                  /* default */NULL, /* !print */FALSE, NULL);
00320   opt_reg_string(sim_odb, "-redir:prog",
00321                  "redirect simulated program output to file",
00322                  &sim_progout, /* default */NULL, /* !print */FALSE, NULL);
00323 
00324 #ifndef _MSC_VER
00325   /* scheduling priority option */
00326   opt_reg_int(sim_odb, "-nice",
00327               "simulator scheduling priority", &nice_priority,
00328               /* default */NICE_DEFAULT_VALUE, /* print */TRUE, NULL);
00329 #endif
00330 
00331   /* FIXME: add stats intervals and max insts... */
00332 
00333   /* register all simulator-specific options */
00334   sim_reg_options(sim_odb);
00335 
00336   /* parse simulator options */
00337   exec_index = -1;
00338   opt_process_options(sim_odb, argc, argv);
00339 
00340   /* redirect I/O? */
00341   if (sim_simout != NULL)
00342     {
00343       /* send simulator non-interactive output (STDERR) to file SIM_SIMOUT */
00344       fflush(stderr);
00345       if (!freopen(sim_simout, "w", stderr))
00346         fatal("unable to redirect simulator output to file `%s'", sim_simout);
00347     }
00348 
00349   if (sim_progout != NULL)
00350     {
00351       /* redirect simulated program output to file SIM_PROGOUT */
00352       sim_progfd = fopen(sim_progout, "w");
00353       if (!sim_progfd)
00354         fatal("unable to redirect program output to file `%s'", sim_progout);
00355     }
00356 
00357   /* need at least two argv values to run */
00358   if (argc < 2)
00359     {
00360       banner(stderr, argc, argv);
00361       usage(stderr, argc, argv);
00362       exit(1);
00363     }
00364 
00365   /* opening banner */
00366   banner(stderr, argc, argv);
00367 
00368   if (help_me)
00369     {
00370       /* print help message and exit */
00371       usage(stderr, argc, argv);
00372       exit(1);
00373     }
00374 
00375   /* seed the random number generator */
00376   if (rand_seed == 0)
00377     {
00378       /* seed with the timer value, true random */
00379       mysrand(time((time_t *)NULL));
00380     }
00381   else
00382     {
00383       /* seed with default or user-specified random number generator seed */
00384       mysrand(rand_seed);
00385     }
00386 
00387   /* exec_index is set in orphan_fn() */
00388   if (exec_index == -1)
00389     {
00390       /* executable was not found */
00391       fprintf(stderr, "error: no executable specified\n");
00392       usage(stderr, argc, argv);
00393       exit(1);
00394     }
00395   /* else, exec_index points to simulated program arguments */
00396 
00397   /* check simulator-specific options */
00398   sim_check_options(sim_odb, argc, argv);
00399 
00400 #ifndef _MSC_VER
00401   /* set simulator scheduling priority */
00402   if (nice(0) < nice_priority)
00403     {
00404       if (nice(nice_priority - nice(0)) < 0)
00405         fatal("could not renice simulator process");
00406     }
00407 #endif
00408 
00409   /* default architected value... */
00410   sim_num_insn = 0;
00411 
00412 #ifdef BFD_LOADER
00413   /* initialize the bfd library */
00414   bfd_init();
00415 #endif /* BFD_LOADER */
00416 
00417   /* initialize the instruction decoder */
00418   md_init_decoder();
00419 
00420   /* initialize all simulation modules */
00421   sim_init();
00422 
00423   /* initialize architected state */
00424   sim_load_prog(argv[exec_index], argc-exec_index, argv+exec_index, envp);
00425 
00426   /* register all simulator stats */
00427   sim_sdb = stat_new();
00428   sim_reg_stats(sim_sdb);
00429 #if 0 /* not portable... :-( */
00430   stat_reg_uint(sim_sdb, "sim_mem_usage",
00431                 "total simulator (data) memory usage",
00432                 &sim_mem_usage, sim_mem_usage, "%11dk");
00433 #endif
00434 
00435   /* record start of execution time, used in rate stats */
00436   sim_start_time = time((time_t *)NULL);
00437 
00438   /* emit the command line for later reuse */
00439   fprintf(stderr, "sim: command line: ");
00440   for (i=0; i < argc; i++)
00441     fprintf(stderr, "%s ", argv[i]);
00442   fprintf(stderr, "\n");
00443 
00444   /* output simulation conditions */
00445   s = ctime(&sim_start_time);
00446   if (s[strlen(s)-1] == '\n')
00447     s[strlen(s)-1] = '\0';
00448   fprintf(stderr, "\nsim: simulation started @ %s, options follow:\n", s);
00449   opt_print_options(sim_odb, stderr, /* short */TRUE, /* notes */TRUE);
00450   sim_aux_config(stderr);
00451   fprintf(stderr, "\n");
00452 
00453   /* omit option dump time from rate stats */
00454   sim_start_time = time((time_t *)NULL);
00455 
00456   if (init_quit)
00457     exit_now(0);
00458 
00459   running = TRUE;
00460   sim_main();
00461 
00462   /* simulation finished early */
00463   exit_now(0);
00464 
00465   return 0;
00466 }

int orphan_fn int    i,
int    argc,
char **    argv
[static]
 

Definition at line 201 of file main.c.

References exec_index, and FALSE.

Referenced by main().

00202 {
00203   exec_index = i;
00204   return /* done */FALSE;
00205 }

void signal_exit_now int    sigtype [static]
 

Definition at line 133 of file main.c.

References sim_exit_now, and TRUE.

Referenced by main().

00134 {
00135   sim_exit_now = TRUE;
00136 }

void signal_sim_stats int    sigtype [static]
 

Definition at line 126 of file main.c.

References sim_dump_stats, and TRUE.

Referenced by main().

00127 {
00128   sim_dump_stats = TRUE;
00129 }

void sim_print_stats FILE *    fd
 

Definition at line 232 of file main.c.

References MAX, running, sim_aux_stats(), sim_elapsed_time, sim_end_time, sim_start_time, and stat_print_stats().

Referenced by bpred_mstate_obj(), cache_mstate_obj(), exit_now(), main(), and profile_mstate_obj().

00233 {
00234 #if 0 /* not portable... :-( */
00235   extern char etext, *sbrk(int);
00236 #endif
00237 
00238   if (!running)
00239     return;
00240 
00241   /* get stats time */
00242   sim_end_time = time((time_t *)NULL);
00243   sim_elapsed_time = MAX(sim_end_time - sim_start_time, 1);
00244 
00245 #if 0 /* not portable... :-( */
00246   /* compute simulator memory usage */
00247   sim_mem_usage = (sbrk(0) - &etext) / 1024;
00248 #endif
00249 
00250   /* print simulation stats */
00251   fprintf(fd, "\nsim: ** simulation statistics **\n");
00252   stat_print_stats(sim_sdb, fd);
00253   sim_aux_stats(fd);
00254   fprintf(fd, "\n");
00255 }

void usage FILE *    fd,
int    argc,
char **    argv
[static]
 

Definition at line 222 of file main.c.

References opt_print_help().

Referenced by main().

00223 {
00224   fprintf(fd, "Usage: %s {-options} executable {arguments}\n", argv[0]);
00225   opt_print_help(sim_odb, fd);
00226 }


Variable Documentation

int exec_index = -1 [static]
 

Definition at line 181 of file main.c.

Referenced by main(), and orphan_fn().

int help_me [static]
 

Definition at line 184 of file main.c.

Referenced by main().

int init_quit [static]
 

Definition at line 190 of file main.c.

Referenced by main().

int nice_priority [static]
 

Definition at line 194 of file main.c.

Referenced by main().

int rand_seed [static]
 

Definition at line 187 of file main.c.

Referenced by main().

int running = FALSE [static]
 

Definition at line 228 of file main.c.

Referenced by main(), and sim_print_stats().

char* sim_chkpt_fname = NULL
 

Definition at line 172 of file main.c.

Referenced by main().

int sim_dump_stats = FALSE
 

Definition at line 162 of file main.c.

Referenced by signal_sim_stats().

FILE* sim_eio_fd = NULL
 

Definition at line 173 of file main.c.

char* sim_eio_fname = NULL
 

Definition at line 171 of file main.c.

int sim_elapsed_time
 

Definition at line 149 of file main.c.

Referenced by sim_print_stats().

time_t sim_end_time
 

Definition at line 148 of file main.c.

Referenced by sim_print_stats().

jmp_buf sim_exit_buf
 

Definition at line 159 of file main.c.

Referenced by main().

int sim_exit_now = FALSE
 

Definition at line 156 of file main.c.

Referenced by signal_exit_now().

counter_t sim_num_insn = 0
 

Definition at line 139 of file main.c.

Referenced by main().

struct opt_odb_t* sim_odb
 

Definition at line 165 of file main.c.

FILE* sim_progfd = NULL
 

Definition at line 178 of file main.c.

Referenced by main().

char* sim_progout = NULL [static]
 

Definition at line 177 of file main.c.

Referenced by main().

struct stat_sdb_t* sim_sdb
 

Definition at line 168 of file main.c.

char* sim_simout = NULL [static]
 

Definition at line 176 of file main.c.

Referenced by main().

time_t sim_start_time
 

Definition at line 147 of file main.c.

Referenced by main(), and sim_print_stats().

int sim_swap_bytes
 

Definition at line 152 of file main.c.

int sim_swap_words
 

Definition at line 153 of file main.c.



UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214