/* * Copyright 1993,1994,1995 Emin Gun Sirer * MIPSI - Mips Instruction Set Simulator. */ #include #include #include #include #include "config.h" #include "main.h" #include "mem.h" #include "minithread.h" #include "disk.h" #include #define MAXARG 100 int systrace = 0, stats = 0; jmp_buf toplevel; static char **env, *w[MAXARG]; /* words in the command */ /* declare machine state and registers */ unsigned int R[32]; /* CPU registers */ unsigned int CpCond[4], CCR[4][32], CPR[4][32]; float FGR[16]; /* FPU registers */ double *FPR = (void *) FGR; int *FWR = (void *) FGR; unsigned int pc, npc, nnpc, HI, LO; unsigned int ownedfp = 0; jmp_buf inrun; void dump_stats() { /* dump statistics at the end of the program run */ fprintf(stderr,"\n"); fprintf(stderr,"M ---***--- Disk Reads = %d\n", numreads); fprintf(stderr,"M ---***--- Disk Writes = %d\n", numwrites); fprintf(stderr,"M ---***--- Total Disk Access = %d\n",numreads+numwrites); fflush(stderr); } void main(int argc, char *argv[], char *mainenv[]) { static int i = 1, oldi, exitcode; run_struct *rs; int vary = 0; env = mainenv; if(argc - i > 0) do { oldi = i; if(strcmp("-systrace", argv[i]) == 0) systrace = 1, ++i; else if(strcmp("-stats", argv[i]) == 0) stats = 1, ++i; } while((argc - i > 0) && (oldi != i)); if(setjmp(toplevel) == 0) { if(i < argc) { /* input file specified */ int rv; /* Open the input file */ if(readaout(argv[i]) != 0) error(Fatal,"Cannot open input file\n"); /* Make sure to print out stats upon exit */ rv = atexit(dump_stats); /* Initialize the TLB */ tlb_flush(); /* Set up to run main */ mt_initialize(); rs = (run_struct *)malloc(sizeof(run_struct)); rs->paddress = pstaddress; rs->arg = NULL; minithread_system_initialize(run, (void*)rs); assert(0); /* should never get here ! */ /* Extra stuff here */ if(exitcode > 0) printf("Program exited with status %d.\n", exitcode); if(stats) print_memstats(); exit(exitcode); } error(TopLevel,"mipsi - MIPS Simulator (C) 1992, 1993, E. Gun Sirer\n"); } else { printf("Usage: mipsi \n"); exit(0); } }