std_cmds.c
39.4 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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
/**************************************************************************
* *
* 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_cmds.c
* Creator: hsa@sgi.com
* Create Date: Tue Feb 8 13:44:53 PST 1994
*
*/
#include <stdio.h>
#include <ctype.h>
#include "rsp.h"
#include "rspctl.h"
#include "memory.h"
#include "std_cmds.h"
#include "su.h"
#include "vu.h"
#include "cop0.h"
extern boolean hit_quit;
/*
* The following routines are the dispatch routines for each
* simulator command. The purpose of these routines is mainly
* argument processing, the real work usually happens elsewhere.
*
*/
/* called-forward... */
static rsp_CmdDispResult do_Register(char *input_line, FILE *input_file);
static rsp_CmdDispResult do_actual_write(char *input_line,
FILE *input_file, boolean doAppend);
/*
* do a shell command.
*/
static rsp_CmdDispResult
do_system(char *input_line, FILE *input_file)
{
char *c;
c = &(input_line[1]);
while (*c != ' ' && *c != '\n' && *c != '\0')
c++;
if (*c == '\n' || *c == '\0') {
return rsp_COMMAND_ERROR;
}
system(c);
return rsp_COMMAND_SUCCESS;
}
/*
* append memory to a file.
*/
static rsp_CmdDispResult
do_append(char *input_line, FILE *input_file)
{
return(do_actual_write(input_line, input_file, TRUE));
}
/*
* Do a 'bcopy' within the RSP.
*/
static rsp_CmdDispResult
do_bcopy(char *input_line, FILE *input_file)
{
u32 froma, toa, len;
int arg_count;
char cmd[32];
arg_count = sscanf(input_line,"%s %i %i %i",
cmd, &froma, &toa, &len);
if (rsp_MemBcopy(froma, toa, len)) {
return rsp_COMMAND_SUCCESS;
} else {
return rsp_COMMAND_ERROR;
}
}
/*
* evaluate()
*
* Recursive function called by do_evaluate() and a few other commands.
* "l" and "r" are the first and last character in the expression.
*
* XXX Should set the "err" flag more often (i.e., do more checking).
*/
static int
evaluate(char *s, int l, int r, int *err)
{
int i, paren;
char var[32];
paren = 0;
for (i = r; i >= l; i--) {
if (s[i] == ')') {
paren++;
}
if (s[i] == '(') {
paren--;
}
if (s[i] == '+' && paren == 0 && i != l) {
return evaluate (s, l, i - 1, err) + evaluate (s, i + 1, r, err);
}
if (s[i] == '-' && paren == 0 && i != l) {
return evaluate (s, l, i - 1, err) - evaluate (s, i + 1, r, err);
}
}
if (paren != 0) {
*err = 1;
return 1;
}
paren = 0;
for (i = r; i >= l; i--) {
if (s[i] == ')') {
paren++;
}
if (s[i] == '(') {
paren--;
}
if (s[i] == '*' && paren == 0) {
return evaluate (s, l, i - 1, err) * evaluate (s, i + 1, r, err);
}
if (s[i] == '/' && paren == 0) {
return evaluate (s, l, i - 1, err) / evaluate (s, i + 1, r, err);
}
}
if (paren != 0) {
*err = 1;
return 1;
}
if (s[l] == '(' && s[r] == ')') {
return evaluate (s, l + 1, r - 1, err);
}
for (i = 0; i <= r - l; i++) {
var[i] = s[i + l];
}
var[i] = '\0';
if (strcasecmp (var, "pc") == 0 || strcmp (var, ".") == 0) {
return rsp_programCounter;
}
if (strcasecmp (var, "ctl") == 0) {
return rsp_controlReg;
}
if (strcasecmp (var, "clk") == 0) {
return rsp_clock;
}
if (var[0] == '$') {
if (!isdigit (var[1])) {
*err = 1;
return 1;
}
return rsp_SuGPRGet (strtol (var + 1, NULL, 0));
}
if (isdigit (var[0]) || var[0] == '-' || var[0] == '+') {
return strtol (s + l, NULL, 0);
}
*err = 1;
return 1;
}
/*
* set a breakpoint at <addr> or clock value.
*/
static rsp_CmdDispResult
do_break(char *input_line, FILE *input_file)
{
int arg_count;
u32 value;
char cmd[32], junk[32];
arg_count = sscanf(input_line,"%s %i %s",
cmd, &value, junk);
if (arg_count > 2 && (strcmp(junk,"clk")==0)) {
rsp_ProcessorBreakpointInstall(value, FALSE);
} else if (arg_count == 2) {
rsp_ProcessorBreakpointInstall(value, TRUE);
} else {
return rsp_COMMAND_ERROR;
}
return rsp_COMMAND_SUCCESS;
}
static rsp_CmdDispResult
do_checkpoint(char *input_line, FILE *input_file)
{
rsp_fprintf(stderr,"checkpoint not implemented.\n");
return rsp_COMMAND_ERROR;
}
/*
* installs a command for a breakpoint.
*/
static rsp_CmdDispResult
do_command(char *input_line, FILE *input_file)
{
boolean keep_going;
int arg_count, bp;
char cmd[32], junk[32], *cp, line[80];
arg_count = sscanf(input_line,"%s %d %s", cmd, &bp, junk);
if (arg_count < 2) {
return rsp_COMMAND_ERROR;
}
if (arg_count > 2) { /* command is on the line */
cp = &(input_line[0]);
while (*cp != ' ') /* skip 'comm' string */
cp++;
while (*cp == ' ') /* skip first gap */
cp++;
while (*cp != ' ') /* skip bkpt number */
cp++;
while (*cp == ' ') /* skip second gap */
cp++;
rsp_ProcessorBreakpointCmdInstall(bp, cp);
} else { /* interactively add commands */
if (input_file == stdin) {
rsp_fprintf(stdout,
"Enter commands to be executed when breakpoint [%d] is hit.\n",
bp);
rsp_fprintf(stdout,"Enter 'end' when finished.\n\n? ");
fflush(stdout);
}
keep_going = TRUE;
rsp_ProcessorBreakpointCmdInit(bp);
while (keep_going) {
fgets(line, 80, input_file);
if (strncmp(line, "end", 3) == 0) {
keep_going = FALSE;
} else {
rsp_ProcessorBreakpointCmdInstall(bp, line);
if (input_file == stdin) {
rsp_fprintf(stdout,"? ");
fflush(stdout);
}
}
}
}
return rsp_COMMAND_SUCCESS;
}
/*
* continue execution of halted processor.
*/
static rsp_CmdDispResult
do_continue(char *input_line, FILE *input_file)
{
rsp_controlReg = UnFlag(rsp_controlReg, rsp_CtlHaltMask);
rsp_ProcessorRun();
return rsp_COMMAND_SUCCESS;
}
/*
* disable a breakpoint
*/
static rsp_CmdDispResult
do_disable(char *input_line, FILE *input_file)
{
int arg_count, bp;
char cmd[32];
arg_count = sscanf(input_line,"%s %d",cmd,&bp);
if (arg_count != 2) {
return rsp_COMMAND_ERROR;
}
rsp_ProcessorBreakpointEnable(bp, FALSE);
return rsp_COMMAND_SUCCESS;
}
/*
* set data window address
*/
static rsp_CmdDispResult
do_dbase(char *input_line, FILE *input_file)
{
char buf[512], *dst, *src;
int value, err;
/* Remove spaces from input line */
dst = buf;
src = input_line;
while (isalpha (*src)) { /* Skip command */
src++;
}
while (*src) {
if (!isspace (*src)) {
*dst++ = *src;
}
src++;
}
*dst = '\0';
err = 0;
value = evaluate (buf, 0, strlen (buf) - 1, &err);
if (err) {
rsp_fprintf(stdout,"Error in expression.\n");
} else {
rsp_VisualData (value);
}
return rsp_COMMAND_SUCCESS;
}
/*
* enable a breakpoint
*/
static rsp_CmdDispResult
do_enable(char *input_line, FILE *input_file)
{
int arg_count, bp;
char cmd[32];
arg_count = sscanf(input_line,"%s %d",cmd,&bp);
if (arg_count != 2) {
return rsp_COMMAND_ERROR;
}
rsp_ProcessorBreakpointEnable(bp, TRUE);
return rsp_COMMAND_SUCCESS;
}
/*
* Deposit <value> into register <reg>
* Private routine called from do_deposit()
*/
static rsp_CmdDispResult
do_Register(char *input_line, FILE *input_file)
{
int arg_count, regnum;
i32 regvalue, tmpvalue;
char cmd[32], regsym[32], *s;
arg_count = sscanf(input_line,"%s %s %i",cmd,regsym,®value);
if (arg_count != 3) {
return rsp_COMMAND_ERROR;
}
/* translate symbolic registers: */
if (strcasecmp(regsym,"pc")==0) {
regnum = 32;
} else if (strcasecmp(regsym,"ctl")==0) {
regnum = 33;
} else if (strcasecmp(regsym,"clk")==0) {
regnum = 34;
} else if (regsym[0] == '$') {
if (regsym[1] == 'v') {
s = &(regsym[2]);
regnum = atoi(s);
sprintf(regsym,"v%d",regnum);
} else {
s = &(regsym[1]);
regnum = atoi(s);
sprintf(regsym,"r%d",regnum);
}
} else {
regnum = atoi(regsym);
sprintf(regsym,"r%d",regnum);
}
if (regnum >= 0 && regnum < 35) {
/* print out "before" value, in case user screwed up: */
tmpvalue = rsp_SuGPRGet(regnum); /* read back */
rsp_fprintf(stdout,"%s = %08x (before)\n",regsym,tmpvalue);
rsp_SuGPRSet(regnum, regvalue);
tmpvalue = rsp_SuGPRGet(regnum); /* read back */
rsp_fprintf(stdout,"%s = %08x (after)\n",regsym,tmpvalue);
return rsp_COMMAND_SUCCESS;
} else {
return rsp_COMMAND_ERROR;
}
}
/*
* Deposit <value> into VU register <reg>
* Private routine called from do_deposit()
*/
static rsp_CmdDispResult
do_VRegister(char *input_line, FILE *input_file)
{
int arg_count, regnum;
i64 tlong1 = 0x0, tlong0 = 0x0;
i128 regvalue, tmpvalue;
char cmd[32], regsym[32], *s;
arg_count = sscanf(input_line,"%s %s %lli %lli",cmd,regsym,&tlong0,&tlong1);
if (arg_count < 3) {
return rsp_COMMAND_ERROR;
}
s = &(regsym[2]); /* skip '$v' */
regnum = atoi(s);
sprintf(regsym,"v%d",regnum);
Set128By64(®value, tlong0, 0);
Set128By64(®value, tlong1, 1);
if (regnum >= 0 && regnum < 32) {
/* print out "before" value, in case user screwed up: */
tmpvalue = rsp_VURGet(regnum); /* read back */
rsp_fprintf(stdout,"%s = ",regsym);
Print128(stdout, tmpvalue);
rsp_fprintf(stdout," (before)\n");
rsp_VURSet(regnum, regvalue);
tmpvalue = rsp_VURGet(regnum); /* read back */
rsp_fprintf(stdout,"%s = ",regsym);
Print128(stdout, tmpvalue);
rsp_fprintf(stdout," (after)\n");
return rsp_COMMAND_SUCCESS;
} else {
return rsp_COMMAND_ERROR;
}
}
/*
* Deposit:
*
* rsp > deposit <address> <value>
*
* tries to be intelligent about decimal/octal/hex numbers.
* Can only address by words.
*
*/
static rsp_CmdDispResult
do_deposit(char *input_line, FILE *input_file)
{
int arg_count;
u32 addr, value, tmpvalue;
char cmd[32], addrs[32], *s;
arg_count = sscanf(input_line,"%s %s %i",cmd,addrs,&value);
if (arg_count == 3) {
/*
* check for register access
*/
if ((strcasecmp(addrs,"pc")==0) ||
(strcasecmp(addrs,"ctl")==0)||
(strcasecmp(addrs,"clk")==0)) {
sprintf(cmd,"Reg %s %d",addrs,value);
return(do_Register(cmd, input_file));
} else if (addrs[0] == '$' && addrs[1] == 'v') {
return(do_VRegister(input_line, input_file));
} else if (addrs[0] == '$') {
s = &(addrs[1]);
addr = atoi(s);
sprintf(cmd,"Reg %d %d",addr,value);
return(do_Register(cmd, input_file));
}
sscanf(addrs,"%i",&addr);
addr &= 0xfffffffc; /* make sure word-aligned */
/* print out "before" value, in case user screwed up: */
tmpvalue = rsp_ExamineMemory(addr); /* read back */
rsp_fprintf(stdout,"0x%08x = %08x (before)\n",addr,tmpvalue);
rsp_DepositMemory(addr, value); /* make the change */
tmpvalue = rsp_ExamineMemory(addr); /* read back */
rsp_fprintf(stdout,"0x%08x = %08x (after)\n",addr,tmpvalue);
return rsp_COMMAND_SUCCESS;
} else {
return rsp_COMMAND_ERROR;
}
}
/*
* Evaluate:
*
* Evaluates a mathematical expression and displays the result.
*/
static rsp_CmdDispResult
do_evaluate(char *input_line, FILE *input_file)
{
char buf[512], *dst, *src;
int value, err;
/* Remove spaces from input line */
dst = buf;
src = input_line;
while (isalpha (*src)) { /* Skip command */
src++;
}
while (*src) {
if (!isspace (*src)) {
*dst++ = *src;
}
src++;
}
*dst = '\0';
err = 0;
value = evaluate (buf, 0, strlen (buf) - 1, &err);
if (err) {
rsp_fprintf(stdout,"Error in expression.\n");
} else {
rsp_fprintf(stdout,"Result of %s:\n", buf);
rsp_fprintf(stdout,"Decimal: %d, ", value);
if (value < 0) {
rsp_fprintf(stdout,"Unsigned: %u, ", value);
}
rsp_fprintf(stdout,"Hex: 0x%x, Octal: 0%o\n", value, value);
}
return rsp_COMMAND_SUCCESS;
}
/*
* Examine:
*
* rsp > examine <address> <value> [<count>]
*
* Count is 1, if not given.
* Can only address by words.
*
*/
static rsp_CmdDispResult
do_examine(char *input_line, FILE *input_file)
{
int arg_count, i, byte, col = 4;
u32 addr, value, count = 0;
char cmd[32], ascii_string[18], *abuf;
arg_count = sscanf(input_line,"%s %i %i",cmd,&addr,&count);
addr &= 0xfffffffc; /* make sure word-aligned */
count = (count+3) >> 2; /* word addressing */
if (arg_count >= 2) {
if (arg_count == 2)
count = 1;
for (i=0; i<count; i++) {
if (col == 4) {
rsp_fprintf(stdout,"0x%08x : ",addr);
col = 0; byte = 0;
}
value = rsp_ExamineMemory(addr);
rsp_fprintf(stdout,"%08x ",value);
/* convert value to printable ascii, if possible: */
#define rsp_CtoA(b) (((b) < '!') ? '.' : ((b) > '~') ? '.' : (b));
abuf = (char *) &value;
ascii_string[byte++] = rsp_CtoA(abuf[0]);
ascii_string[byte++] = rsp_CtoA(abuf[1]);
ascii_string[byte++] = rsp_CtoA(abuf[2]);
ascii_string[byte++] = rsp_CtoA(abuf[3]);
ascii_string[byte] = '\0';
#undef rsp_CtoA
addr += 4; col++;
if (col == 4) { /* display ascii data */
rsp_fprintf(stdout," %s\n",ascii_string);
}
}
if (col != 4) { /* pad with blanks, if leftover */
for (i=col; i<4; i++) {
rsp_fprintf(stdout," ");
}
rsp_fprintf(stdout," %s\n",ascii_string);
}
return rsp_COMMAND_SUCCESS;
} else {
return rsp_COMMAND_ERROR; /* bad arguments */
}
}
/*
* Switches file viewed in source window
*
*/
static rsp_CmdDispResult
do_file(char *input_line, FILE *input_file)
{
int arg_count;
char cmd[32], arg[256];
arg_count = sscanf(input_line,"%s %s", cmd, arg);
if (arg_count > 1)
{
ViewFile(arg);
}
else
{
rsp_fprintf(stdout, "SPECIFY FILE TO VIEW \n");
fflush(stdout);
}
return rsp_COMMAND_SUCCESS;
}
/*
* Print out general help, or help for a requested command.
*/
static rsp_CmdDispResult
do_help(char *input_line, FILE *input_file)
{
command_table_t *tb, *entryp;
int arg_count;
char cmd[32], arg[32];
arg_count = sscanf(input_line,"%s %s", cmd, arg);
if (arg_count > 1) { /* requested specific help */
entryp = (command_table_t *) NULL;
tb = (command_table_t *) &(simulator_commands[0]);
while (tb->keyword != NULL) {
/* match only the first few unique letters: */
if (strncmp(arg, tb->keyword, strlen(arg)) == 0) {
if (entryp != (command_table_t *) NULL) {
rsp_fprintf(stdout,
"AMBIGUOUS HELP REQUEST : %s",input_line);
fflush(stdout);
return rsp_COMMAND_SUCCESS;
}
entryp = tb;
}
tb++;
}
if (entryp != (command_table_t *) NULL) {
/* execute this command's help: */
rsp_fprintf(stdout,"\n%s : %s\n\n", entryp->keyword,
entryp->syntax_string);
rsp_fprintf(stdout,"%s\n\n", entryp->long_help);
} else {
rsp_fprintf(stdout,"AMBIGUOUS HELP REQUEST : %s",input_line);
}
} else { /* requested general help */
rsp_fprintf(stdout,"\n RSP Simulator, Version %s %s\n\n",
RSP_VERSION, RSP_VERSION_DATE);
rsp_fprintf(stdout,"\tSimulator Commands:\n\n");
tb = (command_table_t *) &(simulator_commands[0]);
while (tb->keyword != NULL) {
rsp_fprintf(stdout," %s\t- %s, %s\n",tb->keyword,
tb->syntax_string, tb->help_string);
tb++;
}
rsp_fprintf(stdout,"\n");
}
fflush(stdout);
return rsp_COMMAND_SUCCESS;
}
/*
* show info on the debugger state (like breakpoints, etc.)
*/
static rsp_CmdDispResult
do_info(char *input_line, FILE *input_file)
{
rsp_ProcessorBreakpointList(stdout);
return rsp_COMMAND_SUCCESS;
}
/*
* List <count> instructions from <addr>
*/
static rsp_CmdDispResult
do_list(char *input_line, FILE *input_file)
{
int arg_count, i;
u32 addr, value, count = 0;
char cmd[32], addrs[32];
arg_count = sscanf(input_line,"%s %s %i",cmd,addrs,&count);
if (arg_count < 2) {
addr = rsp_programCounter;
count = 10;
}
if (addrs[0] == '.') { /* from program counter */
addr = rsp_programCounter;
} else {
sscanf(addrs,"%i", &addr); /* user supplied address */
}
if (arg_count == 2)
count = 10;
for (i=0; i<count; i++) {
value = rsp_ExamineMemory1(addr,rsp_ICACHE_ACCESS);
rsp_fprintf(stdout,"0x%08x : 0x%08x ", addr, value);
rsp_DisasmInst(value, cmd, addr);
rsp_fprintf(stdout,"%s\n",cmd);
addr += 4;
}
return rsp_COMMAND_SUCCESS;
}
/*
* load RSP memory from a file.
*/
static rsp_CmdDispResult
do_load(char *input_line, FILE *input_file)
{
u32 baseaddr;
int arg_count;
char cmd[32], filename[80];
arg_count = sscanf(input_line,"%s %s %i",cmd,filename,&baseaddr);
if ((arg_count == 3) && rsp_MemLoad(filename, baseaddr)) {
return rsp_COMMAND_SUCCESS;
} else {
return rsp_COMMAND_ERROR;
}
}
/*
* Quit RSP simulator
*/
static rsp_CmdDispResult
do_quit(char *input_line, FILE *input_file)
{
rsp_eprintf(stdout,"exiting RSP...\n");
hit_quit = TRUE;
return rsp_COMMAND_QUIT;
}
/*
* view vector registers.
*/
static rsp_CmdDispResult
do_vregister(char *input_line, FILE *input_file)
{
int arg_count, i, regnum, lo=0, hi=32, col=2;
char cmd[32];
i128 regvalue;
arg_count = sscanf(input_line,"%s %d",cmd,®num);
if (arg_count > 1) {
lo = regnum;
hi = lo+1;
} else {
/*
* output ACC, etc.
*/
rsp_fprintf(stdout,"\n VAC = 0x%012llx VCO = 0x%04x VCC = 0x%04x\n",
rsp_ACC[0]&VU_ACC_MASK, rsp_VCO, rsp_VCC);
for (i=1; i<8; i++) {
rsp_fprintf(stdout," 0x%012llx\n",rsp_ACC[i]&VU_ACC_MASK);
}
}
for (i=lo; i<hi; i++) {
if (col >= 2) {
rsp_fprintf(stdout,"\n");
col = 0;
}
regvalue = rsp_VURGet(i);
if (i < 10) {
rsp_fprintf(stdout," ");
}
rsp_fprintf(stdout,"v%d = ",i);
Print128(stdout,regvalue);
rsp_fprintf(stdout," ");
col++;
}
rsp_fprintf(stdout,"\n\n");
return rsp_COMMAND_SUCCESS;
}
/*
* view vector registers as ints.
*/
static rsp_CmdDispResult
do_vrint(char *input_line, FILE *input_file)
{
int arg_count, i, regnum;
char cmd[32],regname[32];
i128 regvalue;
int thevalue;
/*arg_count = sscanf(input_line,"%s %d",cmd,®num);*/
arg_count = sscanf(input_line,"%s %s",cmd,regname);
if (arg_count <= 1) {
rsp_fprintf(stdout,"\n Please specify a vector register number with this command.\n");
return rsp_COMMAND_SUCCESS;
}
regnum=rsp_VisualNameInst(regname)-32;
if (regnum == -2-32) {
rsp_fprintf(stdout,"\n Ambiguous register name. Please use more characters.\n");
return rsp_COMMAND_SUCCESS;
}
if (regnum<0 || regnum>31)
sscanf(regname,"%d",®num);
if (regnum<0 || regnum>31) {
rsp_fprintf(stdout,"\n Please specify a vector register number between 0 and 31.\n");
return rsp_COMMAND_SUCCESS;
}
regvalue = rsp_VURGet(regnum);
rsp_fprintf(stdout,"v%d = ",regnum);
for (i=0;i<16;i+=2) {
thevalue=((float)256*regvalue.b[i] + regvalue.b[i+1]);
if (thevalue & 0x8000) thevalue = -((thevalue^0xFFFF)+1);
rsp_fprintf(stdout,"%6d ",thevalue);
}
rsp_fprintf(stdout,"\n");
return rsp_COMMAND_SUCCESS;
}
/*
* view vector registers as fracs.
*/
static rsp_CmdDispResult
do_vrfrac(char *input_line, FILE *input_file)
{
int arg_count, i, regnum;
char cmd[32],regname[32];
i128 regvalue;
int thevalue;
/*arg_count = sscanf(input_line,"%s %d",cmd,®num);*/
arg_count = sscanf(input_line,"%s %s",cmd,regname);
if (arg_count <= 1) {
rsp_fprintf(stdout,"\n Please specify a vector register number with this command.\n");
return rsp_COMMAND_SUCCESS;
}
regnum=rsp_VisualNameInst(regname)-32;
if (regnum == -2-32) {
rsp_fprintf(stdout,"\n Ambiguous register name. Please use more characters.\n");
return rsp_COMMAND_SUCCESS;
}
if (regnum<0 || regnum>31)
sscanf(regname,"%d",®num);
if (regnum<0 || regnum>31) {
rsp_fprintf(stdout,"\n Please specify a vector register number between 0 and 31.\n");
return rsp_COMMAND_SUCCESS;
}
regvalue = rsp_VURGet(regnum);
rsp_fprintf(stdout,"v%d = ",regnum);
for (i=0;i<16;i+=2) {
thevalue=((float)256*regvalue.b[i] + regvalue.b[i+1]);
if (thevalue & 0x8000) thevalue =-( (thevalue^0xFFFF)+1);
rsp_fprintf(stdout,"%01.6f ",(float)thevalue/32768.0);
}
rsp_fprintf(stdout,"\n");
return rsp_COMMAND_SUCCESS;
}
/*
* view vector registers as doubles.
*/
static rsp_CmdDispResult
do_vrdouble(char *input_line, FILE *input_file)
{
int arg_count, i, regnumi, regnumf;
char cmd[32],regnamei[32],regnamef[32];
i128 regvaluei,regvaluef;
int thevaluei,thevaluef,thesign;
/*arg_count = sscanf(input_line,"%s %d %d",cmd,®numi,®numf);*/
arg_count = sscanf(input_line,"%s %s %s",cmd,regnamei,regnamef);
if (arg_count <= 2) {
rsp_fprintf(stdout,"\n Please specify 2 vector register numbers with this command.\n");
return rsp_COMMAND_SUCCESS;
}
regnumi=rsp_VisualNameInst(regnamei)-32;
regnumf=rsp_VisualNameInst(regnamef)-32;
if (regnumi == -2-32 || regnumf == -2-32) {
rsp_fprintf(stdout,"\n Ambiguous register name. Please use more characters.\n");
return rsp_COMMAND_SUCCESS;
}
if (regnumi<0 || regnumi>31)
sscanf(regnamei,"%d",®numi);
if (regnumf<0 || regnumf>31)
sscanf(regnamef,"%d",®numf);
if (regnumi<0 || regnumi>31 || regnumf<0 || regnumf>31) {
rsp_fprintf(stdout,"\n Please specify vector register numbers between 0 and 31.\n");
return rsp_COMMAND_SUCCESS;
}
regvaluei = rsp_VURGet(regnumi);
regvaluef = rsp_VURGet(regnumf);
rsp_fprintf(stdout,"v%02d:v%02d = ",regnumi,regnumf);
for (i=0;i<16;i+=2) {
thesign=1;
thevaluef=256*regvaluef.b[i] + regvaluef.b[i+1];
thevaluei=256*regvaluei.b[i] + regvaluei.b[i+1];
if (thevaluei & 0x8000) {
thevaluef = (thevaluef^0xFFFF)+1;
thevaluei = (thevaluei^0xFFFF)+((thevaluef&0x10000)>0);
thevaluef &= 0xFFFF;
thesign=-1;
}
rsp_fprintf(stdout,"%5.6f ",((float)thevaluef/65536.0+(float)thevaluei)
* (float) thesign);
if (i==6) rsp_fprintf(stdout,"\n ");
}
rsp_fprintf(stdout,"\n");
return rsp_COMMAND_SUCCESS;
}
float floatprint(int num, int whole, int frac, int rpad, int sign)
{
float val,sgn=1.0;
int mask;
if (sign>=0) {
mask=1<<sign;
if (num&mask) {
sgn=-1.0;
num *= -1;
}
}
if (rpad)
val = (num>>rpad) & (((1<<(rpad+frac))-1) ^ ((1<<(rpad))-1));
else
val = (num) & (((1<<(frac))-1));
val /= (float) (1<<(frac+rpad));
val += (float) ((num>>(frac+rpad)) & ((1<<whole)-1));
val *= sgn;
/*
rsp_fprintf(stdout,"\nnum=%08x frac=%08X div=%f int=%f val=%f\n",num,(num>>rpad) & (((1<<(rpad+frac-1))-1)),(float) (1<<(frac+rpad)),(float) ((num>>(frac+rpad)) & ((1<<whole)-1)),val);
*/
return val;
}
/*
* TExamine:
*
* rsp > texamine <address> <type>
*
* Count is 1, if not given.
* Can only address by words.
*
*/
static rsp_CmdDispResult
do_texamine(char *input_line, FILE *input_file)
{
int arg_count, i, byte,type;
u32 addr, value1, value2;
float f1,f2;
char cmd[32];
arg_count = sscanf(input_line,"%s %i %i",cmd,&addr,&type);
addr &= 0xfffffffc; /* make sure word-aligned */
if (arg_count == 3) {
if (type < 0) {
type *= -1;
addr |= 0x04000000;
}
switch(type) {
case 1: /* point */
value1 = rsp_ExamineMemory(addr);
value2 = rsp_ExamineMemory(addr+8);
f1=floatprint((value1&0xffff0000)|((value2>>16)&0xffff),15,16,0,31);
f2=floatprint(((value1<<16)&0xffff0000)|(value2&0xffff),15,16,0,31);
rsp_fprintf(stdout,"** X=%5.6f Y=%5.6f ",f1,f2);
value1 = rsp_ExamineMemory(addr+4);
value2 = rsp_ExamineMemory(addr+12);
f1=floatprint((value1&0xffff0000)|((value2>>16)&0xffff),15,16,0,31);
f2=floatprint(((value1<<16)&0xffff0000)|(value2&0xffff),15,16,0,31);
rsp_fprintf(stdout,"Z=%5.6f W=%5.6f\n",f1,f2);
value1 = rsp_ExamineMemory(addr+16);
rsp_fprintf(stdout,"** R=0x%02X G=0x%02X B=0x%02X A=0x%02X ",
value1>>24,(value1>>16)&0xff,(value1>>8)&0xff,value1&0xff);
value1 = rsp_ExamineMemory(addr+20);
rsp_fprintf(stdout,"S=0x%04X T=0x%04X\n",
(value1>>16)&0xffff,value1&0xffff);
value1 = rsp_ExamineMemory(addr+24)>>16;
value2 = rsp_ExamineMemory(addr+24)&0xffff;
f1=floatprint(value1,11,2,0,13);
f2=floatprint(value2,11,2,0,13);
rsp_fprintf(stdout,"** SX=%5.2f SY=%5.2f ",f1,f2);
value1 = rsp_ExamineMemory(addr+28);
rsp_fprintf(stdout,"SZ=0x%08x ",value1);
value1 = rsp_ExamineMemory(addr+32);
f1=floatprint(value1,15,16,0,31);
rsp_fprintf(stdout,"1/W=%5.6f\n",f1);
value1 = (rsp_ExamineMemory(addr+36)>>16) &0xff;
value2 = rsp_ExamineMemory(addr+36)&0xffff;
rsp_fprintf(stdout,"** flag=%02X cc=%03X\n",value1,value2);
break;
case 2: /* matrix */
value1 = rsp_ExamineMemory(addr);
value2 = rsp_ExamineMemory(addr+32);
f1=floatprint((value1&0xffff0000)|((value2>>16)&0xffff),15,16,0,31);
f2=floatprint(((value1<<16)&0xffff0000)|(value2&0xffff),15,16,0,31);
rsp_fprintf(stdout,"MTX: %11.6f\t%11.6f",f1,f2);
addr += 4;
value1 = rsp_ExamineMemory(addr);
value2 = rsp_ExamineMemory(addr+32);
f1=floatprint((value1&0xffff0000)|((value2>>16)&0xffff),15,16,0,31);
f2=floatprint(((value1<<16)&0xffff0000)|(value2&0xffff),15,16,0,31);
rsp_fprintf(stdout,"\t%11.6f\t%11.6f\n",f1,f2);
addr += 4;
value1 = rsp_ExamineMemory(addr);
value2 = rsp_ExamineMemory(addr+32);
f1=floatprint((value1&0xffff0000)|((value2>>16)&0xffff),15,16,0,31);
f2=floatprint(((value1<<16)&0xffff0000)|(value2&0xffff),15,16,0,31);
rsp_fprintf(stdout," : %11.6f\t%11.6f",f1,f2);
addr += 4;
value1 = rsp_ExamineMemory(addr);
value2 = rsp_ExamineMemory(addr+32);
f1=floatprint((value1&0xffff0000)|((value2>>16)&0xffff),15,16,0,31);
f2=floatprint(((value1<<16)&0xffff0000)|(value2&0xffff),15,16,0,31);
rsp_fprintf(stdout,"\t%11.6f\t%11.6f\n",f1,f2);
addr += 4;
value1 = rsp_ExamineMemory(addr);
value2 = rsp_ExamineMemory(addr+32);
f1=floatprint((value1&0xffff0000)|((value2>>16)&0xffff),15,16,0,31);
f2=floatprint(((value1<<16)&0xffff0000)|(value2&0xffff),15,16,0,31);
rsp_fprintf(stdout," : %11.6f\t%11.6f",f1,f2);
addr += 4;
value1 = rsp_ExamineMemory(addr);
value2 = rsp_ExamineMemory(addr+32);
f1=floatprint((value1&0xffff0000)|((value2>>16)&0xffff),15,16,0,31);
f2=floatprint(((value1<<16)&0xffff0000)|(value2&0xffff),15,16,0,31);
rsp_fprintf(stdout,"\t%11.6f\t%11.6f\n",f1,f2);
addr += 4;
value1 = rsp_ExamineMemory(addr);
value2 = rsp_ExamineMemory(addr+32);
f1=floatprint((value1&0xffff0000)|((value2>>16)&0xffff),15,16,0,31);
f2=floatprint(((value1<<16)&0xffff0000)|(value2&0xffff),15,16,0,31);
rsp_fprintf(stdout," : %11.6f\t%11.6f",f1,f2);
addr += 4;
value1 = rsp_ExamineMemory(addr);
value2 = rsp_ExamineMemory(addr+32);
f1=floatprint((value1&0xffff0000)|((value2>>16)&0xffff),15,16,0,31);
f2=floatprint(((value1<<16)&0xffff0000)|(value2&0xffff),15,16,0,31);
rsp_fprintf(stdout,"\t%11.6f\t%11.6f\n",f1,f2);
break;
default: /* error */
rsp_fprintf(stdout,"invalid type: %d\n",type);
break;
}
/*
for (i=0; i<type; i++) {
value = rsp_ExamineMemory(addr);
rsp_fprintf(stdout,"%08x ",value);
addr += 4;
}
rsp_fprintf(stdout,"\n");
*/
return rsp_COMMAND_SUCCESS;
} else {
return rsp_COMMAND_ERROR; /* bad arguments */
}
}
/*
* view registers.
*/
static rsp_CmdDispResult
do_register(char *input_line, FILE *input_file)
{
int arg_count, i, regnum, lo=0, hi=32, col=4;
i32 regValue;
u32 readRegValue, writeRegValue;
char cmd[32], regs[32], *s;
arg_count = sscanf(input_line,"%s %s",cmd,regs);
if (arg_count < 2) {
/*
* output PC, etc.
*/
rsp_fprintf(stdout,
"\n PC = 0x%08x CTL = 0x%08x CLK = 0x%08x\n",
rsp_programCounter, rsp_controlReg, rsp_clock);
rsp_fprintf(stdout,
" DMA: Dmem = 0x%04x Dbus = 0x%06x Busy = %d Full = %d\n",
cop0_RegGet(0), cop0_RegGet(1),
(cop0_DmaBusy() ? 1 : 0), (cop0_DmaFull() ? 1 : 0));
readRegValue = cop0_RegGet(2);
writeRegValue = cop0_RegGet(3);
rsp_fprintf(stdout,
" Read Length = (%d,%d,%d) Write Length = (%d,%d,%d)\n",
readRegValue == -1 ? -1 : LINESTRIDE(readRegValue),
readRegValue == -1 ? -1 : LINECOUNT(readRegValue),
readRegValue == -1 ? -1 : BYTECOUNT(readRegValue),
writeRegValue == -1 ? -1 : LINESTRIDE(writeRegValue),
writeRegValue == -1 ? -1 : LINECOUNT(writeRegValue),
writeRegValue == -1 ? -1 : BYTECOUNT(writeRegValue));
} else {
if (regs[0] == '$') {
if (regs[1] == 'v') {
s = &(regs[2]);
regnum = atoi(s);
sprintf(cmd,"reg %d",regnum);
return(do_vregister(cmd, input_file));
} else {
s = &(regs[1]);
regnum = atoi(s);
lo = regnum;
hi = lo+1;
}
} else if (regs[0] == 'v') {
s = &(regs[1]);
regnum = atoi(s);
sprintf(cmd,"reg %d",regnum);
return(do_vregister(cmd, input_file));
} else {
regnum = atoi(regs);
lo = regnum;
hi = lo+1;
}
}
for (i=lo; i<hi; i++) {
if (col == 4) {
rsp_fprintf(stdout,"\n ");
col = 0;
}
regValue = rsp_SuGPRGet(i);
if (i < 10) {
rsp_fprintf(stdout," ");
}
rsp_fprintf(stdout,"r%d = 0x%08x ", i, regValue);
col++;
}
rsp_fprintf(stdout,"\n\n");
return rsp_COMMAND_SUCCESS;
}
/*
* Run the processor. Resets PC, CLK, etc.
*/
static rsp_CmdDispResult
do_run(char *input_line, FILE *input_file)
{
rsp_ProcessorReset(rsp_programCounter);
rsp_ProcessorRun();
return rsp_COMMAND_SUCCESS;
}
static rsp_CmdDispResult
do_silent(char *input_line, FILE *input_file)
{
rsp_SetVerbose(FALSE);
return rsp_COMMAND_SUCCESS;
}
static rsp_CmdDispResult
do_nosilent(char *input_line, FILE *input_file)
{
rsp_SetVerbose(TRUE);
return rsp_COMMAND_SUCCESS;
}
static rsp_CmdDispResult
do_source(char *input_line, FILE *input_file)
{
FILE *srcfile;
char cmd[32], line[80];
int arg_count;
arg_count = sscanf(input_line,"%s %s", cmd, line);
if (arg_count == 1) {
return rsp_COMMAND_ERROR;
}
if ((srcfile=fopen(line,"r"))==NULL) {
rsp_fprintf(stderr,"source file [%s] not found.\n",line);
return rsp_COMMAND_ERROR;
}
while (fgets(line, 80, srcfile) != NULL) {
if (line[0] == '\n') {
continue;
}
/*
rsp_fprintf(stdout,"rsp > %s",line);
fflush(stdout);
*/
/* pick off first thing typed: */
sscanf(line,"%s",cmd);
if (!process_command(cmd, line, srcfile)) {
break; /* quit/fatal error */
}
}
fclose(srcfile);
return rsp_COMMAND_SUCCESS;
}
/*
* Step processor 1 clock tick.
*/
static rsp_CmdDispResult
do_step(char *input_line, FILE *input_file)
{
int arg_count, step_count, i;
char cmd[32];
boolean old_verbose;
arg_count = sscanf(input_line,"%s %d", cmd, &step_count);
if (arg_count == 1) {
step_count = 1;
}
old_verbose = rsp_SetVerbose(TRUE);
for (i=0; i<step_count; i++) {
rsp_ProcessorStep();
if (i < step_count - 1) { /* Don't do last one */
rsp_UpdateVisual ();
}
}
if (!old_verbose) {
rsp_UpdateVisual ();
}
rsp_SetVerbose(old_verbose);
return rsp_COMMAND_SUCCESS;
}
/*
* load symbol table
*/
static rsp_CmdDispResult
do_symboltable(char *input_line, FILE *input_file)
{
char cmd[32], fn[128];
int arg_count;
arg_count = sscanf(input_line,"%s %s", cmd, fn);
if (arg_count != 2) {
rsp_fprintf(stdout,"Must specify filename of symbol table.\n");
return rsp_COMMAND_ERROR;
} else {
rsp_VisualSymbolTable (fn);
}
return rsp_COMMAND_SUCCESS;
}
/*
* set a memory watch point at <addr>
*/
static rsp_CmdDispResult
do_watch(char *input_line, FILE *input_file)
{
int arg_count;
u32 value;
char cmd[32];
arg_count = sscanf(input_line,"%s %i",
cmd, &value);
if (arg_count == 2) {
rsp_ProcessorWatchpointInstall(value);
} else {
return rsp_COMMAND_ERROR;
}
return rsp_COMMAND_SUCCESS;
}
/*
* write out memory to a file, possibly appending.
*/
static rsp_CmdDispResult
do_actual_write(char *input_line, FILE *input_file, boolean doAppend)
{
u32 baseaddr, length;
int arg_count;
char cmd[32], filename[80], lenstr[32];
/* HACK */
/* make sure we wait for all the xbus traffic */
while (cop0_TestXBUS()) {
cop0_Step();
}
arg_count = sscanf(input_line,"%s %s %i %s",
cmd,filename,&baseaddr,lenstr);
/*
* if the length argument starts with '*', it is a de-reference
* to a memory address. Take the 32-bit integer at that address
* and use it as a length...
*/
if (arg_count == 4 && lenstr[0] == '*') {
sscanf(lenstr,"*%i",&length);
length = rsp_ExamineMemory(length); /* read back */
} else {
sscanf(lenstr,"%i",&length);
}
if ((arg_count == 4) &&
rsp_MemUnLoad(filename, baseaddr, length, doAppend)) {
return rsp_COMMAND_SUCCESS;
} else {
return rsp_COMMAND_ERROR;
}
}
/*
* write out memory to a file.
*/
static rsp_CmdDispResult
do_write(char *input_line, FILE *input_file)
{
return(do_actual_write(input_line, input_file, FALSE));
}
/*
* This is the actual table of simulator commands. Arranged
* in alphabetical order. Only enough of the keyword to be
* unique need be typed.
*
*/
command_table_t simulator_commands[] =
{
/* keyword: procedure: syntax:
* short help: long help:
*/
{"! ", do_system, "! <cmd>",
"executes shell command <cmd>.", "Calls a shell command."},
{"append", do_append, "ap <file> <addr> <len>",
"append memory to file.", "Copy memory from <addr> for <len> bytes to output file\nnamed <file>."},
{"bcopy", do_bcopy, "bc <from> <to> <len>",
"copy memory around.", "Copy memory at <from> addr to <to> addr, for <len> bytes.\nMemory layout: 0x00000000 - 0x001fffff : DRAM\n 0x04000000 - 0x04001fff : RSP DMem\n 0x04001000 - 0x04001fff : RSP IMem\n 0x10003000 - ... : RSP memory-mapped registers\n etc."},
{"break", do_break, "br <addr> [clk]",
"set breakpoint.", "Halt processor when the PC (or CLK) reaches this value.\nSpecifying 'clk' breaks on the clock value, not the PC."},
{"check", do_checkpoint, "ch <file>",
"checkpoint simulator to a file.", "Write out the entire simulator state to a file for later\ndebugging."},
{"command", do_command, "com <bp>",
"add command(s) to breakpoint.", "Installs debugger command(s) to be executed when breakpoint <bp>\nis hit."},
{"continue", do_continue, "cont",
"continue execution.", "Continue exectution."},
{"dbase", do_dbase, "dbase <addr>",
"set base address of data window.",
"Set the start address of the 4K displayed in the data window."},
{"deposit", do_deposit, "dep <where> <value>",
"deposit value into register or memory.", "Deposit a value into register or memory address (word access only).\nYou can specify a control register with a nmemonic, or\na CPU register as $reg."},
{"disable", do_disable, "dis <brkpt>",
"disable a breakpoint.", "Disable the specified breakpoint. Use 'info' to list\ncurrent breakpoints and their status."},
{"enable", do_enable, "ena <brkpt>",
"enable a breakpoint.", "Enable the specified breakpoint. Use 'info' to list\ncurrent breakpoints and their status."},
{"evaluate", do_evaluate, "eval <expr>",
"evaluate an expression.", "Evaluate a mathematical expression."},
{"examine", do_examine, "ex <addr> [<count>]",
"examine memory.", "Examine contents of memory address (word access only)."},
{"file", do_file, "f <sourcefile>",
"view source file.", "Switches source window over to viewing specified file."},
{"help", do_help, "h [<cmd>]",
"display simulator commands.", "Display list of simulator commands, or verbose help for\na particular command."},
{"info", do_info, "info",
"show info about debugger.", "Display information about the debugger state, such as\nbreakpoints set, etc."},
{"list", do_list, "li <addr> [<count>]",
"list program.", "List (disassemble) program at <addr> for <count> lines.\nDefault <count> is 10 statements.\nUse '.' as address to reference PC."},
{"load", do_load, "lo <file> <addr>",
"load memory.", "Load memory at <addr> from a file <file>."},
{"nosilent", do_nosilent, "nosilent",
"enable messages.", "Enables display of non-essential messages generated\nby the RSP simulator."},
{"quit", do_quit, "q",
"quit simulator.", "Exit simulator."},
{"register", do_register, "reg [<reg>]",
"examine registers.", "Read register <reg>, or all registers if none specified."},
{"run ", do_run, "run",
"run simulator.", "Begin program execution on simulator."},
{"silent", do_silent, "silent",
"inhibit messages.", "Prevents display of non-essential messages generated\nby the RSP simulator."},
{"source", do_source, "source <cmdfile>",
"read command file.", "Execute rspsim commands from <cmdfile>."},
{"step", do_step, "step [<count>]",
"step simulator.", "Step program execution <count> CPU clock ticks. Default is 1."},
{"symboltable", do_symboltable, "sym <filename>",
"load symbol table", "Load a symbol table of line and file information."},
{"vregister", do_vregister, "vreg [<reg>]",
"examine VU registers.", "Read VU register <reg>, or all VU registers if none specified."},
{"vrint", do_vrint, "vri <reg>",
"examine integer VU register.", "Read VU register <reg> as 8 16 bit integers."},
{"vrdouble", do_vrdouble, "vrd <intreg> <fracreg>",
"examine fix VU registeri pair.", "Read VU register pair <intreg>.<fracreg> as 8 32 bit fixed point number."},
{"vrfrac", do_vrfrac, "vrf <reg>",
"examine frac VU register.", "Read VU register <reg> as 8 16 bit fractions."},
{"texamine", do_texamine, "t <addr> <type>",
"Look at a structure in memory.", "Look at a structure in memory. Type=\n 1 - point"},
{"watch", do_watch, "wa <addr>",
"set memory watchpoint.", "Halt when memory <addr> is touched."},
{"write", do_write, "wr <file> <addr> <len>",
"write memory to file.", "Copy memory from <addr> for <len> bytes to output file\nnamed <file>."},
{NULL, NULL, NULL, NULL, NULL} /* last entry, keep this */
};
/*
* This function dispatches one command typed in by the user:
*/
int
process_command(char *command, char *input_line, FILE *input_file)
{
command_table_t *tb, *entryp;
rsp_CmdDispResult result;
/* allow 'comments', useful for script files */
if (input_line[0] == '#' || input_line[0] == '\n') {
#if 0
fprintf(stdout,"rsp > %s",input_line);
fflush(stdout);
#endif
return(TRUE);
}
entryp = (command_table_t *) NULL;
tb = (command_table_t *) &(simulator_commands[0]);
while (tb->keyword != NULL) {
/* match only the first few unique letters: */
if (strncmp(command, tb->keyword, strlen(command)) == 0) {
if (entryp != (command_table_t *) NULL) {
rsp_fprintf(stdout,"AMBIGUOUS COMMAND : %s",input_line);
return(TRUE);
}
entryp = tb;
}
tb++;
}
if (entryp != (command_table_t *) NULL) {
/* execute this command */
if ((result = (*entryp->command_proc)(input_line, input_file)) ==
rsp_COMMAND_SUCCESS) {
return(TRUE); /* it worked.. */
} else if (result == rsp_COMMAND_QUIT) {
return(FALSE);
} else if (result == rsp_COMMAND_ERROR) {
rsp_eprintf(stdout,"SYNTAX ERROR : %s\n",
entryp->syntax_string);
return(TRUE); /* command error (args, syntax, etc.) */
}
} else {
/* command not found */
rsp_eprintf(stdout,"ERROR : bad command : %s",input_line);
return(TRUE);
}
}