main.c
3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*************************************************************************
*
* File: main.c
*
* This file contains the main routine for the I/O simulator.
*
* $Header: /root/leakn64/depot/rf/sw/n64os20l/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");
}