main.c 3.48 KB

/*************************************************************************
 *
 *  File: main.c
 *
 *  This file contains the main routine for the I/O simulator.
 *
 *  $Header: /root/leakn64/depot/rf/sw/bbplayer/iosim/src/main.c,v 1.2 2002/05/30 05:52:50 whs Exp $
 *
 */

#ifdef __sgi__
	#include <sys/cachectl.h>
#endif
#include <sys/mman.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#ifdef __sgi__
	#include <libelf.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>

#include "sim.h"
#include "simipc.h"

#define	TEST_CMD_FILE	"io.tst"
#define	OPTARG		"w:d:f:l:mn:c:h:s:v?"

/*
 * Forward declarations
 */
static void	usage(void);

/*
 * External references
 */
extern void	IoInit(void);
extern int	IoTest(void);
extern char	IpcName[];
extern int	VerifyMemory;
extern int	MemoryLoad;

/*
 * Global variables
 */
int		IpcFd = -1;
unsigned long	Dflags;
char		*CmdFile = TEST_CMD_FILE;
FILE		*LogFp, *CmdFp;
int		ConfigRdramV = 0;
char		*Server = NULL;
int             NumberStallCycles = 0;

/*
 * Local variables
 */
static char	*ipcName = NULL;


/*
 * Main
 */
main(int argc, char **argv)
{

	int c, testId;
	char	*file;
	FILE	*fp = NULL;
	struct descriptor d;

	extern char *optarg;
	extern int optind, opterr, optopt;

	optind = 1;
	Dflags = 0;
	LogFp  = stderr;

	while ((c = getopt(argc, argv, OPTARG)) != EOF) {
		switch (c) {
			case 'w': {	/* Stall Cycles */
				NumberStallCycles = strtoul(optarg, NULL, 0);
				printf("Stall Cycles=%d\n", NumberStallCycles);
				break;
			}

			case 'd': {	/* Debug */
				Dflags = strtoul(optarg, NULL, 16);
				printf("Debug flag=0x%08x\n", Dflags);
				break;
			}
			case 'f': {	/* Command file */
				CmdFile = optarg;
				break;
			}
			case 'l': {	/* Log file */
				file = optarg;
				printf("Log file = %s\n", file);
				if ((fp = fopen(file, "w+")) == NULL) {
					printf("Unable to open log: %s\n",
						file);
				}
				else
					LogFp = fp;
				break;
			}
			case 'm': {	/* Enable memory loading/unloading */
				printf("Memory loading enabled\n");
				MemoryLoad = 1;
				break;
			}
			case 'n': {	/* IPC name */
				ipcName = optarg;
				break;
			}
			case 'c': {	/* Config RDRAM */
				printf("Config RDRAM using verilog\n");
				ConfigRdramV = 1;
				break;
			}
			case 's': {	/* Automatically exec simv.ipc */
				Server = optarg;
				break;
			}
			case 'v': {	/* Verify memory loading/unloading */
				printf("Verify memory enabled\n");
				VerifyMemory = 1;
				break;
			}
			case 'h': 	/* Help */
			case '?': {
				usage();
				exit(0);
			}
			default:
				break;
		}
	}  /* while */

	printf("Using test file '%s' ...\n", CmdFile);

	IpcInit(ipcName);
	printf("Using IPC name '%s' ...\n", IpcName);

	if (Server == NULL) {
		Server = getenv("SIMV");
		if ((Server != NULL) && (*Server == '\0'))
			Server = NULL;
	}

	if (Server != NULL)
		ExecServer(Server);

	FindServer();
	ExceptionHandlerInit();
	IoInit();

	if (IoTest() < 0)
		printf("ERROR: Unable to perform IO testing!\n");

	if (fp)
		fclose(fp);

	if (IpcFd != -1)
		IpcClose(IpcFd);

	if (Server != NULL)
		WaitServer();

	exit(0);

}

static void
usage(void)
{
	printf("Usage: iosim\n");
	printf("       -d <debug_flags in hex>\n");
	printf("       -f <test_file>\n");
	printf("       -l <log_file>\n");
	printf("       -m (enable memory loading)\n");
	printf("       -n <ipc name>\n");
	printf("       -h (help - this message)\n");
	printf("       -s <simv ... >\n");
	printf("       -v (verify memory when loading/unloading file)\n");
}