std_main.c
8.86 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/**************************************************************************
* *
* Copyright (C) 1994, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
*************************************************************************/
/*
* File: std_main.c
* Creator: hsa@sgi.com
* Create Date: Thu Jan 27 15:22:52 PST 1994
*
* This file is the top level of the standalone C simulator of the
* RSP.
*
*/
#include <getopt.h>
#include <string.h>
#include <signal.h>
#include <stdio.h>
#include "rsp.h"
#include "rspctl.h"
#include "memory.h"
#include "std_cmds.h"
#include "std_visual.h"
#include "vu.h"
static void fatal_handler(int);
static void int_handler(int);
static void winch_handler(int);
static boolean rsp_visual = FALSE;
static boolean rsp_quiet = FALSE;
static boolean rsp_server = FALSE;
static int server_key = 0;
static char dramFile[256];
#ifdef __sgi__
static const struct sigaction fatal_act = {SA_RESETHAND, fatal_handler, 0};
static const struct sigaction int_act = {SA_RESTART, int_handler, 0};
static const struct sigaction winch_act = {0, winch_handler, 0};
#else
static const struct sigaction fatal_act = {fatal_handler, 0, SA_RESETHAND};
static const struct sigaction int_act = {int_handler, 0, SA_RESTART};
static const struct sigaction winch_act = {winch_handler, 0, 0};
#endif
int rsp_disable_scratch_mem = 0;
boolean hit_quit = FALSE;
boolean XBUS_stdout = FALSE;
boolean use_alt_divrom = FALSE;
boolean Clear_Breakpoints = FALSE;
unsigned int ForegroundColor = 0x00000000;
unsigned int BackgroundColor = 0x00ffffff;
unsigned int UpdateColor = 0x00ffff00;
unsigned int HighlightColor = 0x00ffff00;
static void
rsp_usage(void)
{
fprintf(stderr,"usage: rsp [-d] [-c] [-b col] [-f col] [-u col] [-r] [-v] [-q] [-s] [-n] [-t] [-T] [-z] [-Z] [-R] [-D file] [-S key] [-M] [-X] [script_file]\n");
}
static void
fatal_handler(int sig)
{
if (rsp_visual)
rsp_VisualCleanup();
fprintf(stderr,"FATAL HANDLER: KILLING!!!!!!\n");
kill(getpid(), sig);
}
static void
int_handler(int sig)
{
rsp_controlReg = Flag(rsp_controlReg, rsp_CtlHaltMask);
}
static void
winch_handler(int sig)
{
rsp_VisualResize();
}
/*
* This function loops, prompting the user for input.
* The RSP is not running at this point, we are processing
* debugger-like commands.
*
* When the 'run' command is entered, the RSP will begin
* to run, returning here only when hitting a breakpoint, etc.
*
*/
static int
run_processor(FILE *in)
{
char cmd[32], line[256], oldline[256];
if (hit_quit)
return(0);
/*
* if we are in rsp_visual mode, 'in' might be a pointer
* to an initialization file which we still want to read...
*/
strcpy(oldline, "\n");
strcpy(line, "\n");
if (rsp_visual) {
if (!rsp_VisualUpdate())
exit(-1);
}
while (rsp_fgets(line, 256, in) != -1) {
if (line[0] != '\n') {
strcpy(oldline, line);
}
/* pick off first thing typed: */
sscanf(oldline,"%s",cmd);
if (!process_command(cmd, oldline, stdin)) {
break; /* quit/fatal error */
}
if (rsp_visual) {
if (!rsp_VisualUpdate())
exit(-1);
}
if (hit_quit)
break;
}
}
/*
* Top level of the standalone simulator.
*/
int rsp_VUSpacing;
FILE *trout;
extern FILE *trout;
boolean trout_en;
int debug_vmask;
FILE *vtout = NULL;
int
main(int argc, char *argv[])
{
FILE *in = stdin, *initfp = NULL;
char *initfile = NULL;
int init_regs = 0;
int c;
VUZeroPipe = 1;
debug_vmask = 0;
if (strstr (argv[0], "rspg") != NULL) {
rsp_visual = TRUE;
}
rsp_VUSpacing = 16; /* Turns spacing off (VU < 16 bytes) */
trout_en = FALSE;
/* process arguments */
while ((c = getopt(argc, argv, "h:dcb:f:u:rvqsntTzZRD:S:MX")) != EOF) {
switch(c) {
case 'R': /* Real chip */
rsp_disable_scratch_mem = 1;
break;
case 'D':
rsp_server = TRUE;
strcpy(dramFile, optarg);
break;
case 'S':
rsp_server = TRUE;
server_key = strtoul(optarg, (char **)NULL, 0);
break;
case 'M':
debug_vmask = TRUE;
break;
case 'v':
rsp_visual = TRUE;
break;
case 'q':
rsp_quiet = TRUE;
break;
case 's':
rsp_VUSpacing = 1;
break;
case 'Z':
VUZeroPipe = 0;
break;
case 'z':
VUZeroPipe = 1;
break;
case 'n': /* no verbose */
printf ("setting no verbose \n");
rsp_SetVerbose(0);
break;
case 't': /* Enabling the (reg,mem) traces*/
printf ("reg,mem trace enabled \n");
trout = fopen("trace_out","w");
trout_en = TRUE;
break;
case 'T': /* Enabling the verilog check traces */
if ((vtout = fopen("exec_trace.log","w")) == NULL) {
fprintf(stderr,"rsp : could not open exec trace log.\n");
}
break;
case 'r': /* Enabling register reset (otherwise random) */
printf ("SU/VU regs initialized to zero \n");
init_regs = 1;
break;
case 'X':
XBUS_stdout = TRUE;
rsp_quiet = TRUE;
break;
case 'd':
rsp_eprintf(stdout,"rsp : using alt div rom.\n");
use_alt_divrom = TRUE;
break;
case 'c':
Clear_Breakpoints = TRUE;
break;
case 'b':
BackgroundColor = strtoul(optarg, (char **)NULL, 0);
break;
case 'f':
ForegroundColor = strtoul(optarg, (char **)NULL, 0);
break;
case 'u':
UpdateColor = strtoul(optarg, (char **)NULL, 0);
break;
case 'h':
HighlightColor = strtoul(optarg, (char **)NULL, 0);
break;
default:
case '?':
rsp_usage();
break;
}
}
rsp_MemoryInit();
if (rsp_server) {
rsp_eprintf(stdout,"RSP Simulator running in SERVER mode.\n");
rsp_ShmemInit(server_key, dramFile);
}
if (rsp_visual) {
if (!rsp_VisualInit())
exit(-1);
sigaction(SIGWINCH, &winch_act, NULL);
in = NULL; /* all input from window. Except initfp... */
}
sigaction(SIGSEGV, &fatal_act, NULL);
sigaction(SIGBUS, &fatal_act, NULL);
sigaction(SIGINT, &int_act, NULL);
rsp_eprintf(stdout,"\nRSP Simulator, Version %s, created %s %s\n\n",
RSP_VERSION, RSP_VERSION_DATE, RSP_VERSION_TIME);
/* a command script file is an option */
if (optind < argc) {
initfile = argv[optind];
if ((initfp = fopen(initfile,"r"))==NULL) {
fprintf(stderr,"could not open script file [%s]\n",initfile);
exit(-1);
}
}
/* initialize things */
rsp_ProcessorInit();
rsp_SuInit(init_regs);
rsp_VuInit(init_regs);
if (!cop0_Init(NULL, rsp_ICACHE_LOW)) { /* load into IMEM */
if (rsp_visual)
rsp_VisualCleanup();
exit(-1);
}
if (rsp_server) {
rsp_ShmemRun(); /* does not return... */
} else {
/* process any command line init file */
if (initfp != NULL)
run_processor(initfp);
/* process user input */
run_processor(in);
/* clean up */
if (rsp_visual)
rsp_VisualCleanup();
exit(0);
if (trout_en==TRUE)
fclose(trout);
}
exit(0);
}
void
rsp_fprintf(FILE *out, char *fmt, ...)
{
va_list ap;
if (XBUS_stdout && out == stdout)
return;
va_start(ap, fmt);
if (rsp_visual)
rsp_VisualPrint(out, fmt, ap);
else if (!rsp_quiet)
vfprintf(out, fmt, ap);
va_end(ap);
}
void
rsp_eprintf(FILE *out, char *fmt, ...)
{
va_list ap;
if (XBUS_stdout && out == stdout)
return;
va_start(ap, fmt);
if (rsp_visual)
rsp_VisualPrint(out, fmt, ap);
else
vfprintf(out, fmt, ap);
va_end(ap);
}
int
rsp_fgets(char *s, int n, FILE *in)
{
/*
* if we are in rsp_visual mode, 'in' might be a pointer
* to an initialization file which we still want to read...
*/
if (rsp_visual) {
if (in != NULL)
return(fgets(s, n, in) == NULL ? -1 : 0);
else
return(rsp_VisualGets(s, n));
} else {
rsp_fprintf(stdout,"rsp > ");
if (!rsp_quiet)
fflush(stdout);
return(fgets(s, n, in) == NULL ? -1 : 0);
}
}
static boolean rsp_verbose = TRUE;
boolean
rsp_SetVerbose(boolean value)
{
boolean old;
old = rsp_verbose;
rsp_verbose = value;
return(old);
}
boolean
rsp_GetVerbose(void)
{
return rsp_verbose;
}
void
rsp_Verbose(FILE *out, char *fmt, ...)
{
va_list ap;
if (XBUS_stdout && out == stdout)
return;
if (rsp_verbose) {
va_start(ap, fmt);
if (rsp_visual)
rsp_VisualPrint(out, fmt, ap);
else
vfprintf(out, fmt, ap);
va_end(ap);
}
}
void
rsp_UpdateVisual(void)
{
if (rsp_visual) {
rsp_VisualUpdate ();
}
}