main.c 3.43 KB

/*************************************************************************
 *
 *  File: main.c
 *
 *  $Header: /root/leakn64/depot/rf/sw/bbplayer/iosim/src/dp_test/main.c,v 1.2 2003/07/02 17:43:20 jprincen Exp $
 *
 */
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>

#include "iomap.h"
#include "iotest.h"
#include "sim.h"
#include "simipc.h"
#include "trace.h"
#include "bcp_util.h"

#define PASS 0
#define FAIL -1

/***********************************************************************
 * Extern definitions
 */
extern	TstCmd	TstCmdTbl[];
extern	void	IoTestAll(void);


/***********************************************************************
 * Macro definitions
 */
#define	TEST_CMD_FILE	"all.tst"
#define	OPTARG		"r:d:l:hc:qx:"


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



/***********************************************************************
 * Local static definitions
 */
static void		usage(void);

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

    int c; 
    int do_quit = 0;
    char *file;
    char *lfile;
    FILE *fp = NULL;
    int do_checksum = 0;

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

    optind = 1;
    Dflags = 0;
    LogFp  = stdout;
    

    while ((c = getopt(argc, argv, OPTARG)) != EOF) {
        switch (c) {
        case 'd': {	/* Debug flag */
            Dflags = strtoul(optarg, NULL, 16);
            printf("Debug flag=0x%08lx\n", Dflags);
            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 'h': {	/* Help */
            usage();
            exit(0);
        }
        case 'q': {
            do_quit = 1;
            break;
        }
        case 'r': {	/* RDRAM file */
            file = optarg;
            printf("RDRAM file = %s\n", file);
            break;
        }
        case 'x': {	/* DP list file */
            lfile = optarg;
            printf("DP list file = %s\n", lfile);
            break;
        }
        case 'c': {
            do_checksum = 1;
            break;
        }
        default:
            break;
        }
    }  /* while */

    ExceptionHandlerInit();
    IpcInit(NULL);
    FindServer();

    do_keep_alive_socket(1);

    /*
     * Load RDRAM
     */
    if (bd_memory_read_rdram(file, 4*1024*1024) != PASS) {
        fprintf(LogFp, "Memory read failed\n");
    } else {
        dp_list_file_xbus(lfile);

        /*
         * Dump RDRAM
         */
        bd_memory_write_rdram(file, 4*1024*1024);
     }

    do_keep_alive_socket(0);

    /* exit simulator */
    if (do_quit) {
        printf("Quit\n");
        IoCmd(REQ_QUIT, 0);
    }

    if (fp)
        fclose(fp);

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

    exit(0);

}

static void
usage(void)
{
	printf("Usage: mi_test \n");
	printf("       <-l log_file>\n");
	printf("       <-d debug_flags in hex>\n");
	printf("       <-s scale (example 20)>\n");
}