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
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
|
/* Simulator for the Hitachi SH architecture.
Written by Steve Chamberlain of Cygnus Support.
sac@cygnus.com
This file is part of SH sim
THIS SOFTWARE IS NOT COPYRIGHTED
Cygnus offers the following for use in the public domain. Cygnus
makes no warranty with regard to the software or it's performance
and the user accepts the software "AS IS" with all faults.
CYGNUS DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO
THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "config.h"
#include <signal.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "sysdep.h"
#include "bfd.h"
#include "callback.h"
#include "remote-sim.h"
/* This file is local - if newlib changes, then so should this. */
#include "syscall.h"
#include <math.h>
#ifdef _WIN32
#include <float.h> /* Needed for _isnan() */
#define isnan _isnan
#endif
#ifndef SIGBUS
#define SIGBUS SIGSEGV
#endif
#ifndef SIGQUIT
#define SIGQUIT SIGTERM
#endif
#ifndef SIGTRAP
#define SIGTRAP 5
#endif
#define O_RECOMPILE 85
#define DEFINE_TABLE
#define DISASSEMBLER_TABLE
typedef union
{
struct
{
int regs[16];
int pc;
int pr;
int gbr;
int vbr;
int mach;
int macl;
int sr;
int fpul;
int fpscr;
/* sh3e */
union fregs_u
{
float f[16];
double d[8];
int i[16];
}
/* start-sanitize-sh4 */
#if 1
fregs[2];
#else
/* end-sanitize-sh4 */
fregs;
/* start-sanitize-sh4 */
#endif
/* end-sanitize-sh4 */
int ssr;
int spc;
/* sh3 */
int bank[2][8];
int ticks;
int stalls;
int memstalls;
int cycles;
int insts;
int prevlock;
int thislock;
int exception;
int end_of_registers;
int msize;
#define PROFILE_FREQ 1
#define PROFILE_SHIFT 2
int profile;
unsigned short *profile_hist;
unsigned char *memory;
}
asregs;
int asints[28];
} saved_state_type;
saved_state_type saved_state;
/* These variables are at file scope so that functions other than
sim_resume can use the fetch/store macros */
static int target_little_endian;
static int host_little_endian;
#if 1
static int maskl = ~0;
static int maskw = ~0;
#endif
static SIM_OPEN_KIND sim_kind;
static char *myname;
/* Short hand definitions of the registers */
#define SBIT(x) ((x)&sbit)
#define R0 saved_state.asregs.regs[0]
#define Rn saved_state.asregs.regs[n]
#define Rm saved_state.asregs.regs[m]
#define UR0 (unsigned int)(saved_state.asregs.regs[0])
#define UR (unsigned int)R
#define UR (unsigned int)R
#define SR0 saved_state.asregs.regs[0]
#define GBR saved_state.asregs.gbr
#define VBR saved_state.asregs.vbr
#define SSR saved_state.asregs.ssr
#define SPC saved_state.asregs.spc
#define MACH saved_state.asregs.mach
#define MACL saved_state.asregs.macl
#define FPUL saved_state.asregs.fpul
#define PC pc
/* Alternate bank of registers r0-r6 */
/* Note: code controling SR handles flips between BANK0 and BANK1 */
#define Rn_BANK(n) (saved_state.asregs.bank[!SR_RB][(n)])
#define SET_Rn_BANK(n, EXP) do { saved_state.asregs.bank[!SR_RB][(n)] = (EXP); } while (0)
/* Manipulate SR */
#define SR_MASK_M (1 << 9)
#define SR_MASK_Q (1 << 8)
#define SR_MASK_I (0xf << 4)
#define SR_MASK_S (1 << 1)
#define SR_MASK_T (1 << 0)
#define SR_MASK_BL (1 << 28)
#define SR_MASK_RB (1 << 29)
#define SR_MASK_MD (1 << 30)
#define M ((saved_state.asregs.sr & SR_MASK_M) != 0)
#define Q ((saved_state.asregs.sr & SR_MASK_Q) != 0)
#define S ((saved_state.asregs.sr & SR_MASK_S) != 0)
#define T ((saved_state.asregs.sr & SR_MASK_T) != 0)
#define SR_BL ((saved_state.asregs.sr & SR_MASK_BL) != 0)
#define SR_RB ((saved_state.asregs.sr & SR_MASK_RB) != 0)
#define SR_MD ((saved_state.asregs.sr & SR_MASK_MD) != 0)
/* Note: don't use this for privileged bits */
#define SET_SR_BIT(EXP, BIT) \
do { \
if ((EXP) & 1) \
saved_state.asregs.sr |= (BIT); \
else \
saved_state.asregs.sr &= ~(BIT); \
} while (0)
#define SET_SR_M(EXP) SET_SR_BIT ((EXP), SR_MASK_M)
#define SET_SR_Q(EXP) SET_SR_BIT ((EXP), SR_MASK_Q)
#define SET_SR_S(EXP) SET_SR_BIT ((EXP), SR_MASK_S)
#define SET_SR_T(EXP) SET_SR_BIT ((EXP), SR_MASK_T)
#define GET_SR() (saved_state.asregs.sr - 0)
#define SET_SR(x) set_sr (x)
static void
set_sr (new_sr)
int new_sr;
{
/* do we need to swap banks */
int old_gpr = (SR_MD ? !SR_RB : 0);
int new_gpr = ((new_sr & SR_MASK_MD)
? (new_sr & SR_MASK_RB) == 0
: 0);
if (old_gpr != new_gpr)
{
int i;
for (i = 0; i < 8; i++)
{
saved_state.asregs.bank[old_gpr][i] = saved_state.asregs.regs[i];
saved_state.asregs.regs[i] = saved_state.asregs.bank[new_gpr][i];
}
}
}
/* Manipulate FPSCR */
/* start-sanitize-sh4 */
#if 1
#define FPSCR_MASK_FR (1 << 21)
#define FPSCR_MASK_SZ (1 << 20)
#define FPSCR_MASK_PR (1 << 19)
#define FPSCR_FR ((GET_FPSCR() & FPSCR_MASK_FR) != 0)
#define FPSCR_SZ ((GET_FPSCR() & FPSCR_MASK_SZ) != 0)
#define FPSCR_PR ((GET_FPSCR() & FPSCR_MASK_PR) != 0)
static void
set_fpscr1 (x)
int x;
{
int old = saved_state.asregs.fpscr;
saved_state.asregs.fpscr = (x);
/* swap the floating point register banks */
if ((saved_state.asregs.fpscr ^ old) & FPSCR_MASK_FR)
{
union fregs_u tmpf = saved_state.asregs.fregs[0];
saved_state.asregs.fregs[0] = saved_state.asregs.fregs[1];
saved_state.asregs.fregs[1] = tmpf;
}
}
#define GET_FPSCR() (saved_state.asregs.fpscr)
#define SET_FPSCR(x) \
do { \
set_fpscr1 (x); \
} while (0)
#else
/* end-sanitize-sh4 */
#define set_fpscr1(x)
#define SET_FPSCR(x) (saved_state.asregs.fpscr = (x))
#define GET_FPSCR() (saved_state.asregs.fpscr)
/* start-sanitize-sh4 */
#endif
/* end-sanitize-sh4 */
int
fail ()
{
abort ();
}
/* start-sanitize-sh4 */
int
special_address (addr, bits_written, data)
void *addr;
int bits_written, data;
{
if ((unsigned) addr >> 24 == 0xf0 && bits_written == 32 && (data & 1) == 0)
/* This invalidates (if not associative) or might invalidate
(if associative) an instruction cache line. This is used for
trampolines. Since we don't simulate the cache, this is a no-op
as far as the simulator is concerned. */
return 1;
/* We can't do anything useful with the other stuff, so fail. */
return 0;
}
/* end-sanitize-sh4 */
/* This function exists solely for the purpose of setting a breakpoint to
catch simulated bus errors when running the simulator under GDB. */
void
bp_holder ()
{
}
/* FIXME: sim_resume should be renamed to sim_engine_run. sim_resume
being implemented by ../common/sim_resume.c and the below should
make a call to sim_engine_halt */
/* restore-sanitize-sh4#define BUSERROR(addr, mask) \
restore-sanitize-sh4 if (addr & ~mask) { saved_state.asregs.exception = SIGBUS; bp_holder (); }
start-sanitize-sh4 */
#define BUSERROR(addr, mask, bits_written, data) \
if (addr & ~mask) \
{ \
if (special_address (addr, bits_written, data)) \
return; \
saved_state.asregs.exception = SIGBUS; \
bp_holder (); \
}
/* end-sanitize-sh4 */
/* Define this to enable register lifetime checking.
The compiler generates "add #0,rn" insns to mark registers as invalid,
the simulator uses this info to call fail if it finds a ref to an invalid
register before a def
#define PARANOID
*/
#ifdef PARANOID
int valid[16];
#define CREF(x) if(!valid[x]) fail();
#define CDEF(x) valid[x] = 1;
#define UNDEF(x) valid[x] = 0;
#else
#define CREF(x)
#define CDEF(x)
#define UNDEF(x)
#endif
static void parse_and_set_memory_size PARAMS ((char *str));
static int IOMEM PARAMS ((int addr, int write, int value));
static host_callback *callback;
/* Floating point registers */
/* start-sanitize-sh4 */
#if 1
#define DR(n) (get_dr (n))
static double
get_dr (n)
int n;
{
n = (n & ~1);
if (host_little_endian)
{
union
{
int i[2];
double d;
} dr;
dr.i[1] = saved_state.asregs.fregs[0].i[n + 0];
dr.i[0] = saved_state.asregs.fregs[0].i[n + 1];
return dr.d;
}
else
return (saved_state.asregs.fregs[0].d[n >> 1]);
}
#define SET_DR(n, EXP) set_dr ((n), (EXP))
static void
set_dr (n, exp)
int n;
double exp;
{
n = (n & ~1);
if (host_little_endian)
{
union
{
int i[2];
double d;
} dr;
dr.d = exp;
saved_state.asregs.fregs[0].i[n + 0] = dr.i[1];
saved_state.asregs.fregs[0].i[n + 1] = dr.i[0];
}
else
saved_state.asregs.fregs[0].d[n >> 1] = exp;
}
#define SET_FI(n,EXP) (saved_state.asregs.fregs[0].i[(n)] = (EXP))
#define FI(n) (saved_state.asregs.fregs[0].i[(n)])
#define FR(n) (saved_state.asregs.fregs[0].f[(n)])
#define SET_FR(n,EXP) (saved_state.asregs.fregs[0].f[(n)] = (EXP))
#define XD_TO_XF(n) ((((n) & 1) << 5) | ((n) & 0x1e))
#define XF(n) (saved_state.asregs.fregs[(n) >> 5].i[(n) & 0x1f])
#define SET_XF(n,EXP) (saved_state.asregs.fregs[(n) >> 5].i[(n) & 0x1f] = (EXP))
#define FP_OP(n, OP, m) \
{ \
if (FPSCR_PR) \
{ \
if (((n) & 1) || ((m) & 1)) \
saved_state.asregs.exception = SIGILL; \
else \
SET_DR(n, (DR(n) OP DR(m))); \
} \
else \
SET_FR(n, (FR(n) OP FR(m))); \
} while (0)
#define FP_UNARY(n, OP) \
{ \
if (FPSCR_PR) \
{ \
if ((n) & 1) \
saved_state.asregs.exception = SIGILL; \
else \
SET_DR(n, (OP (DR(n)))); \
} \
else \
SET_FR(n, (OP (FR(n)))); \
} while (0)
#define FP_CMP(n, OP, m) \
{ \
if (FPSCR_PR) \
{ \
if (((n) & 1) || ((m) & 1)) \
saved_state.asregs.exception = SIGILL; \
else \
SET_SR_T (DR(n) OP DR(m)); \
} \
else \
SET_SR_T (FR(n) OP FR(m)); \
} while (0)
#else
/* end-sanitize-sh4 */
#define FI(n) (saved_state.asregs.fregs.i[(n)])
#define FR(n) (saved_state.asregs.fregs.f[(n)])
#define SET_FI(n,EXP) (saved_state.asregs.fregs.i[(n)] = (EXP))
#define SET_FR(n,EXP) (saved_state.asregs.fregs.f[(n)] = (EXP))
#define FP_OP(n, OP, m) (SET_FR(n, (FR(n) OP FR(m))))
#define FP_UNARY(n, OP) (SET_FR(n, (OP (FR(n)))))
#define FP_CMP(n, OP, m) SET_SR_T(FR(n) OP FR(m))
/* start-sanitize-sh4 */
#endif
/* end-sanitize-sh4 */
static void INLINE
wlat_little (memory, x, value, maskl)
unsigned char *memory;
{
int v = value;
unsigned char *p = memory + ((x) & maskl);
/* restore-sanitize-sh4 BUSERROR(x, maskl);
start-sanitize-sh4 */
BUSERROR(x, maskl, 32, v);
/* end-sanitize-sh4 */
p[3] = v >> 24;
p[2] = v >> 16;
p[1] = v >> 8;
p[0] = v;
}
static void INLINE
wwat_little (memory, x, value, maskw)
unsigned char *memory;
{
int v = value;
unsigned char *p = memory + ((x) & maskw);
/* restore-sanitize-sh4 BUSERROR(x, maskw);
start-sanitize-sh4 */
BUSERROR(x, maskw, 16, v);
/* end-sanitize-sh4 */
p[1] = v >> 8;
p[0] = v;
}
static void INLINE
wbat_any (memory, x, value, maskb)
unsigned char *memory;
{
unsigned char *p = memory + (x & maskb);
if (x > 0x5000000)
IOMEM (x, 1, value);
/* restore-sanitize-sh4 BUSERROR(x, maskb);
start-sanitize-sh4 */
BUSERROR(x, maskb, 8, value);
/* end-sanitize-sh4 */
p[0] = value;
}
static void INLINE
wlat_big (memory, x, value, maskl)
unsigned char *memory;
{
int v = value;
unsigned char *p = memory + ((x) & maskl);
/* restore-sanitize-sh4 BUSERROR(x, maskl);
start-sanitize-sh4 */
BUSERROR(x, maskl, 32, v);
/* end-sanitize-sh4 */
p[0] = v >> 24;
p[1] = v >> 16;
p[2] = v >> 8;
p[3] = v;
}
static void INLINE
wwat_big (memory, x, value, maskw)
unsigned char *memory;
{
int v = value;
unsigned char *p = memory + ((x) & maskw);
/* restore-sanitize-sh4 BUSERROR(x, maskw);
start-sanitize-sh4 */
BUSERROR(x, maskw, 16, v);
/* end-sanitize-sh4 */
p[0] = v >> 8;
p[1] = v;
}
static void INLINE
wbat_big (memory, x, value, maskb)
unsigned char *memory;
{
unsigned char *p = memory + (x & maskb);
/* restore-sanitize-sh4 BUSERROR(x, maskb);
start-sanitize-sh4 */
BUSERROR(x, maskb, 8, value);
/* end-sanitize-sh4 */
if (x > 0x5000000)
IOMEM (x, 1, value);
p[0] = value;
}
/* Read functions */
static int INLINE
rlat_little (memory, x, maskl)
unsigned char *memory;
{
unsigned char *p = memory + ((x) & maskl);
/* restore-sanitize-sh4 BUSERROR(x, maskl);
start-sanitize-sh4 */
BUSERROR(x, maskl, -32, -1);
/* end-sanitize-sh4 */
return (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0];
}
static int INLINE
rwat_little (memory, x, maskw)
unsigned char *memory;
{
unsigned char *p = memory + ((x) & maskw);
/* restore-sanitize-sh4 BUSERROR(x, maskw);
start-sanitize-sh4 */
BUSERROR(x, maskw, -16, -1);
/* end-sanitize-sh4 */
return (p[1] << 8) | p[0];
}
static int INLINE
rbat_any (memory, x, maskb)
unsigned char *memory;
{
unsigned char *p = memory + ((x) & maskb);
/* restore-sanitize-sh4 BUSERROR(x, maskb);
start-sanitize-sh4 */
BUSERROR(x, maskb, -8, -1);
/* end-sanitize-sh4 */
return p[0];
}
static int INLINE
rlat_big (memory, x, maskl)
unsigned char *memory;
{
unsigned char *p = memory + ((x) & maskl);
/* restore-sanitize-sh4 BUSERROR(x, maskl);
start-sanitize-sh4 */
BUSERROR(x, maskl, -32, -1);
/* end-sanitize-sh4 */
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
}
static int INLINE
rwat_big (memory, x, maskw)
unsigned char *memory;
{
unsigned char *p = memory + ((x) & maskw);
/* restore-sanitize-sh4 BUSERROR(x, maskw);
start-sanitize-sh4 */
BUSERROR(x, maskw, -16, -1);
/* end-sanitize-sh4 */
return (p[0] << 8) | p[1];
}
#define RWAT(x) (little_endian ? rwat_little(memory, x, maskw): rwat_big(memory, x, maskw))
#define RLAT(x) (little_endian ? rlat_little(memory, x, maskl): rlat_big(memory, x, maskl))
#define RBAT(x) (rbat_any (memory, x, maskb))
#define WWAT(x,v) (little_endian ? wwat_little(memory, x, v, maskw): wwat_big(memory, x, v, maskw))
#define WLAT(x,v) (little_endian ? wlat_little(memory, x, v, maskl): wlat_big(memory, x, v, maskl))
#define WBAT(x,v) (wbat_any (memory, x, v, maskb))
#define RUWAT(x) (RWAT(x) & 0xffff)
#define RSWAT(x) ((short)(RWAT(x)))
#define RSBAT(x) (SEXT(RBAT(x)))
/* start-sanitize-sh4 */
#define RDAT(x, n) (do_rdat (memory, (x), (n), (little_endian)))
static int
do_rdat (memory, x, n, little_endian)
char *memory;
int x;
int n;
int little_endian;
{
int f0;
int f1;
int i = (n & 1);
int j = (n & ~1);
if (little_endian)
{
f0 = rlat_little (memory, x + 0, maskl);
f1 = rlat_little (memory, x + 4, maskl);
}
else
{
f0 = rlat_big (memory, x + 0, maskl);
f1 = rlat_big (memory, x + 4, maskl);
}
saved_state.asregs.fregs[i].i[(j + 0)] = f0;
saved_state.asregs.fregs[i].i[(j + 1)] = f1;
return 0;
}
/* end-sanitize-sh4 */
/* start-sanitize-sh4 */
#define WDAT(x, n) (do_wdat (memory, (x), (n), (little_endian)))
static int
do_wdat (memory, x, n, little_endian)
char *memory;
int x;
int n;
int little_endian;
{
int f0;
int f1;
int i = (n & 1);
int j = (n & ~1);
f0 = saved_state.asregs.fregs[i].i[(j + 0)];
f1 = saved_state.asregs.fregs[i].i[(j + 1)];
if (little_endian)
{
wlat_little (memory, (x + 0), f0, maskl);
wlat_little (memory, (x + 4), f1, maskl);
}
else
{
wlat_big (memory, (x + 0), f0, maskl);
wlat_big (memory, (x + 4), f1, maskl);
}
return 0;
}
/* end-sanitize-sh4 */
#define MA(n) do { memstalls += (((pc & 3) != 0) ? (n) : ((n) - 1)); } while (0)
#define SEXT(x) (((x & 0xff) ^ (~0x7f))+0x80)
#define SEXT12(x) (((x & 0xfff) ^ 0x800) - 0x800)
#define SEXTW(y) ((int)((short)y))
#define Delay_Slot(TEMPPC) iword = RUWAT(TEMPPC); goto top;
int empty[16];
#define L(x) thislock = x;
#define TL(x) if ((x) == prevlock) stalls++;
#define TB(x,y) if ((x) == prevlock || (y)==prevlock) stalls++;
#if defined(__GO32__) || defined(_WIN32)
int sim_memory_size = 19;
#else
int sim_memory_size = 24;
#endif
static int sim_profile_size = 17;
static int nsamples;
#undef TB
#define TB(x,y)
#define SMR1 (0x05FFFEC8) /* Channel 1 serial mode register */
#define BRR1 (0x05FFFEC9) /* Channel 1 bit rate register */
#define SCR1 (0x05FFFECA) /* Channel 1 serial control register */
#define TDR1 (0x05FFFECB) /* Channel 1 transmit data register */
#define SSR1 (0x05FFFECC) /* Channel 1 serial status register */
#define RDR1 (0x05FFFECD) /* Channel 1 receive data register */
#define SCI_RDRF 0x40 /* Recieve data register full */
#define SCI_TDRE 0x80 /* Transmit data register empty */
static int
IOMEM (addr, write, value)
int addr;
int write;
int value;
{
if (write)
{
switch (addr)
{
case TDR1:
if (value != '\r')
{
putchar (value);
fflush (stdout);
}
break;
}
}
else
{
switch (addr)
{
case RDR1:
return getchar ();
}
}
return 0;
}
static int
get_now ()
{
return time ((long *) 0);
}
static int
now_persec ()
{
return 1;
}
static FILE *profile_file;
static void
swap (memory, n)
unsigned char *memory;
int n;
{
int little_endian = target_little_endian;
WLAT (0, n);
}
static void
swap16 (memory, n)
unsigned char *memory;
int n;
{
int little_endian = target_little_endian;
WWAT (0, n);
}
static void
swapout (n)
int n;
{
if (profile_file)
{
char b[4];
swap (b, n);
fwrite (b, 4, 1, profile_file);
}
}
static void
swapout16 (n)
int n;
{
char b[4];
swap16 (b, n);
fwrite (b, 2, 1, profile_file);
}
/* Turn a pointer in a register into a pointer into real memory. */
static char *
ptr (x)
int x;
{
return (char *) (x + saved_state.asregs.memory);
}
/* Simulate a monitor trap, put the result into r0 and errno into r1 */
static void
trap (i, regs, memory, maskl, maskw, little_endian)
int i;
int *regs;
unsigned char *memory;
{
switch (i)
{
case 1:
printf ("%c", regs[0]);
break;
case 2:
saved_state.asregs.exception = SIGQUIT;
break;
case 3: /* FIXME: for backwards compat, should be removed */
case 34:
{
extern int errno;
int perrno = errno;
errno = 0;
switch (regs[4])
{
#if !defined(__GO32__) && !defined(_WIN32)
case SYS_fork:
regs[0] = fork ();
break;
case SYS_execve:
regs[0] = execve (ptr (regs[5]), (char **)ptr (regs[6]), (char **)ptr (regs[7]));
break;
case SYS_execv:
regs[0] = execve (ptr (regs[5]),(char **) ptr (regs[6]), 0);
break;
case SYS_pipe:
{
char *buf;
int host_fd[2];
buf = ptr (regs[5]);
regs[0] = pipe (host_fd);
WLAT (buf, host_fd[0]);
buf += 4;
WLAT (buf, host_fd[1]);
}
break;
case SYS_wait:
regs[0] = wait (ptr (regs[5]));
break;
#endif
case SYS_read:
regs[0] = callback->read (callback, regs[5], ptr (regs[6]), regs[7]);
break;
case SYS_write:
if (regs[5] == 1)
regs[0] = (int)callback->write_stdout (callback, ptr(regs[6]), regs[7]);
else
regs[0] = (int)callback->write (callback, regs[5], ptr (regs[6]), regs[7]);
break;
case SYS_lseek:
regs[0] = callback->lseek (callback,regs[5], regs[6], regs[7]);
break;
case SYS_close:
regs[0] = callback->close (callback,regs[5]);
break;
case SYS_open:
regs[0] = callback->open (callback,ptr (regs[5]), regs[6]);
break;
case SYS_exit:
/* EXIT - caller can look in r5 to work out the reason */
saved_state.asregs.exception = SIGQUIT;
regs[0] = regs[5];
break;
case SYS_stat: /* added at hmsi */
/* stat system call */
{
struct stat host_stat;
char *buf;
regs[0] = stat (ptr (regs[5]), &host_stat);
buf = ptr (regs[6]);
WWAT (buf, host_stat.st_dev);
buf += 2;
WWAT (buf, host_stat.st_ino);
buf += 2;
WLAT (buf, host_stat.st_mode);
buf += 4;
WWAT (buf, host_stat.st_nlink);
buf += 2;
WWAT (buf, host_stat.st_uid);
buf += 2;
WWAT (buf, host_stat.st_gid);
buf += 2;
WWAT (buf, host_stat.st_rdev);
buf += 2;
WLAT (buf, host_stat.st_size);
buf += 4;
WLAT (buf, host_stat.st_atime);
buf += 4;
WLAT (buf, 0);
buf += 4;
WLAT (buf, host_stat.st_mtime);
buf += 4;
WLAT (buf, 0);
buf += 4;
WLAT (buf, host_stat.st_ctime);
buf += 4;
WLAT (buf, 0);
buf += 4;
WLAT (buf, 0);
buf += 4;
WLAT (buf, 0);
buf += 4;
}
break;
#ifndef _WIN32
case SYS_chown:
regs[0] = chown (ptr (regs[5]), regs[6], regs[7]);
break;
#endif /* _WIN32 */
case SYS_chmod:
regs[0] = chmod (ptr (regs[5]), regs[6]);
break;
case SYS_utime:
/* Cast the second argument to void *, to avoid type mismatch
if a prototype is present. */
regs[0] = utime (ptr (regs[5]), (void *) ptr (regs[6]));
break;
default:
abort ();
}
regs[1] = callback->get_errno (callback);
errno = perrno;
}
break;
case 0xc3:
case 255:
saved_state.asregs.exception = SIGTRAP;
break;
}
}
void
control_c (sig, code, scp, addr)
int sig;
int code;
char *scp;
char *addr;
{
saved_state.asregs.exception = SIGINT;
}
static int
div1 (R, iRn2, iRn1/*, T*/)
int *R;
int iRn1;
int iRn2;
/* int T;*/
{
unsigned long tmp0;
unsigned char old_q, tmp1;
old_q = Q;
SET_SR_Q ((unsigned char) ((0x80000000 & R[iRn1]) != 0));
R[iRn1] <<= 1;
R[iRn1] |= (unsigned long) T;
switch (old_q)
{
case 0:
switch (M)
{
case 0:
tmp0 = R[iRn1];
R[iRn1] -= R[iRn2];
tmp1 = (R[iRn1] > tmp0);
switch (Q)
{
case 0:
SET_SR_Q (tmp1);
break;
case 1:
SET_SR_Q ((unsigned char) (tmp1 == 0));
break;
}
break;
case 1:
tmp0 = R[iRn1];
R[iRn1] += R[iRn2];
tmp1 = (R[iRn1] < tmp0);
switch (Q)
{
case 0:
SET_SR_Q ((unsigned char) (tmp1 == 0));
break;
case 1:
SET_SR_Q (tmp1);
break;
}
break;
}
break;
case 1:
switch (M)
{
case 0:
tmp0 = R[iRn1];
R[iRn1] += R[iRn2];
tmp1 = (R[iRn1] < tmp0);
switch (Q)
{
case 0:
SET_SR_Q (tmp1);
break;
case 1:
SET_SR_Q ((unsigned char) (tmp1 == 0));
break;
}
break;
case 1:
tmp0 = R[iRn1];
R[iRn1] -= R[iRn2];
tmp1 = (R[iRn1] > tmp0);
switch (Q)
{
case 0:
SET_SR_Q ((unsigned char) (tmp1 == 0));
break;
case 1:
SET_SR_Q (tmp1);
break;
}
break;
}
break;
}
/*T = (Q == M);*/
SET_SR_T (Q == M);
/*return T;*/
}
static void
dmul (sign, rm, rn)
int sign;
unsigned int rm;
unsigned int rn;
{
unsigned long RnL, RnH;
unsigned long RmL, RmH;
unsigned long temp0, temp1, temp2, temp3;
unsigned long Res2, Res1, Res0;
RnL = rn & 0xffff;
RnH = (rn >> 16) & 0xffff;
RmL = rm & 0xffff;
RmH = (rm >> 16) & 0xffff;
temp0 = RmL * RnL;
temp1 = RmH * RnL;
temp2 = RmL * RnH;
temp3 = RmH * RnH;
Res2 = 0;
Res1 = temp1 + temp2;
if (Res1 < temp1)
Res2 += 0x00010000;
temp1 = (Res1 << 16) & 0xffff0000;
Res0 = temp0 + temp1;
if (Res0 < temp0)
Res2 += 1;
Res2 += ((Res1 >> 16) & 0xffff) + temp3;
if (sign)
{
if (rn & 0x80000000)
Res2 -= rm;
if (rm & 0x80000000)
Res2 -= rn;
}
MACH = Res2;
MACL = Res0;
}
static void
macw (regs, memory, n, m)
int *regs;
unsigned char *memory;
int m, n;
{
int little_endian = target_little_endian;
long tempm, tempn;
long prod, macl, sum;
tempm=RSWAT(regs[m]); regs[m]+=2;
tempn=RSWAT(regs[n]); regs[n]+=2;
macl = MACL;
prod = (long)(short) tempm * (long)(short) tempn;
sum = prod + macl;
if (S)
{
if ((~(prod ^ macl) & (sum ^ prod)) < 0)
{
/* MACH's lsb is a sticky overflow bit. */
MACH |= 1;
/* Store the smallest negative number in MACL if prod is
negative, and the largest positive number otherwise. */
sum = 0x7fffffff + (prod < 0);
}
}
else
{
long mach;
/* Add to MACH the sign extended product, and carry from low sum. */
mach = MACH + (-(prod < 0)) + ((unsigned long) sum < prod);
/* Sign extend at 10:th bit in MACH. */
MACH = (mach & 0x1ff) | -(mach & 0x200);
}
MACL = sum;
}
/* Set the memory size to the power of two provided. */
void
sim_size (power)
int power;
{
saved_state.asregs.msize = 1 << power;
sim_memory_size = power;
if (saved_state.asregs.memory)
{
free (saved_state.asregs.memory);
}
saved_state.asregs.memory =
(unsigned char *) calloc (64, saved_state.asregs.msize / 64);
if (!saved_state.asregs.memory)
{
fprintf (stderr,
"Not enough VM for simulation of %d bytes of RAM\n",
saved_state.asregs.msize);
saved_state.asregs.msize = 1;
saved_state.asregs.memory = (unsigned char *) calloc (1, 1);
}
}
static void
init_pointers ()
{
host_little_endian = 0;
*(char*)&host_little_endian = 1;
host_little_endian &= 1;
if (saved_state.asregs.msize != 1 << sim_memory_size)
{
sim_size (sim_memory_size);
}
if (saved_state.asregs.profile && !profile_file)
{
profile_file = fopen ("gmon.out", "wb");
/* Seek to where to put the call arc data */
nsamples = (1 << sim_profile_size);
fseek (profile_file, nsamples * 2 + 12, 0);
if (!profile_file)
{
fprintf (stderr, "Can't open gmon.out\n");
}
else
{
saved_state.asregs.profile_hist =
(unsigned short *) calloc (64, (nsamples * sizeof (short) / 64));
}
}
}
static void
dump_profile ()
{
unsigned int minpc;
unsigned int maxpc;
unsigned short *p;
int i;
p = saved_state.asregs.profile_hist;
minpc = 0;
maxpc = (1 << sim_profile_size);
fseek (profile_file, 0L, 0);
swapout (minpc << PROFILE_SHIFT);
swapout (maxpc << PROFILE_SHIFT);
swapout (nsamples * 2 + 12);
for (i = 0; i < nsamples; i++)
swapout16 (saved_state.asregs.profile_hist[i]);
}
static void
gotcall (from, to)
int from;
int to;
{
swapout (from);
swapout (to);
swapout (1);
}
#define MMASKB ((saved_state.asregs.msize -1) & ~0)
int
sim_stop (sd)
SIM_DESC sd;
{
saved_state.asregs.exception = SIGINT;
return 1;
}
void
sim_resume (sd, step, siggnal)
SIM_DESC sd;
int step, siggnal;
{
register unsigned int pc;
register int cycles = 0;
register int stalls = 0;
register int memstalls = 0;
register int insts = 0;
register int prevlock;
register int thislock;
register unsigned int doprofile;
register int pollcount = 0;
register int little_endian = target_little_endian;
int tick_start = get_now ();
void (*prev) ();
void (*prev_fpe) ();
extern unsigned char sh_jump_table0[];
register unsigned char *jump_table = sh_jump_table0;
register int *R = &(saved_state.asregs.regs[0]);
/*register int T;*/
register int PR;
register int maskb = ((saved_state.asregs.msize - 1) & ~0);
register int maskw = ((saved_state.asregs.msize - 1) & ~1);
register int maskl = ((saved_state.asregs.msize - 1) & ~3);
register unsigned char *memory;
register unsigned int sbit = ((unsigned int) 1 << 31);
prev = signal (SIGINT, control_c);
prev_fpe = signal (SIGFPE, SIG_IGN);
init_pointers ();
memory = saved_state.asregs.memory;
if (step)
{
saved_state.asregs.exception = SIGTRAP;
}
else
{
saved_state.asregs.exception = 0;
}
pc = saved_state.asregs.pc;
PR = saved_state.asregs.pr;
/*T = GET_SR () & SR_MASK_T;*/
prevlock = saved_state.asregs.prevlock;
thislock = saved_state.asregs.thislock;
doprofile = saved_state.asregs.profile;
/* If profiling not enabled, disable it by asking for
profiles infrequently. */
if (doprofile == 0)
doprofile = ~0;
do
{
register unsigned int iword = RUWAT (pc);
register unsigned int ult;
register unsigned int nia = pc + 2;
#ifndef ACE_FAST
insts++;
#endif
top:
#include "code.c"
pc = nia;
pollcount++;
if (pollcount > 1000)
{
pollcount = 0;
if ((*callback->poll_quit) != NULL
&& (*callback->poll_quit) (callback))
{
sim_stop (sd);
}
}
#ifndef ACE_FAST
prevlock = thislock;
thislock = 30;
cycles++;
if (cycles >= doprofile)
{
saved_state.asregs.cycles += doprofile;
cycles -= doprofile;
if (saved_state.asregs.profile_hist)
{
int n = pc >> PROFILE_SHIFT;
if (n < nsamples)
{
int i = saved_state.asregs.profile_hist[n];
if (i < 65000)
saved_state.asregs.profile_hist[n] = i + 1;
}
}
}
#endif
}
while (!saved_state.asregs.exception);
if (saved_state.asregs.exception == SIGILL
|| saved_state.asregs.exception == SIGBUS)
{
pc -= 2;
}
saved_state.asregs.ticks += get_now () - tick_start;
saved_state.asregs.cycles += cycles;
saved_state.asregs.stalls += stalls;
saved_state.asregs.memstalls += memstalls;
saved_state.asregs.insts += insts;
saved_state.asregs.pc = pc;
/* restore the T and other cached SR bits */
SET_SR (GET_SR());
saved_state.asregs.pr = PR;
saved_state.asregs.prevlock = prevlock;
saved_state.asregs.thislock = thislock;
if (profile_file)
{
dump_profile ();
}
signal (SIGFPE, prev_fpe);
signal (SIGINT, prev);
}
int
sim_write (sd, addr, buffer, size)
SIM_DESC sd;
SIM_ADDR addr;
unsigned char *buffer;
int size;
{
int i;
init_pointers ();
for (i = 0; i < size; i++)
{
saved_state.asregs.memory[MMASKB & (addr + i)] = buffer[i];
}
return size;
}
int
sim_read (sd, addr, buffer, size)
SIM_DESC sd;
SIM_ADDR addr;
unsigned char *buffer;
int size;
{
int i;
init_pointers ();
for (i = 0; i < size; i++)
{
buffer[i] = saved_state.asregs.memory[MMASKB & (addr + i)];
}
return size;
}
void
sim_store_register (sd, rn, memory)
SIM_DESC sd;
int rn;
unsigned char *memory;
{
int little_endian;
init_pointers ();
little_endian = target_little_endian;
if (&saved_state.asints[rn]
== &saved_state.asregs.fpscr)
set_fpscr1 (RLAT(0));
else
saved_state.asints[rn] = RLAT(0);
}
void
sim_fetch_register (sd, rn, memory)
SIM_DESC sd;
int rn;
unsigned char *memory;
{
int little_endian;
init_pointers ();
little_endian = target_little_endian;
WLAT (0, saved_state.asints[rn]);
}
int
sim_trace (sd)
SIM_DESC sd;
{
return 0;
}
void
sim_stop_reason (sd, reason, sigrc)
SIM_DESC sd;
enum sim_stop *reason;
int *sigrc;
{
/* The SH simulator uses SIGQUIT to indicate that the program has
exited, so we must check for it here and translate it to exit. */
if (saved_state.asregs.exception == SIGQUIT)
{
*reason = sim_exited;
*sigrc = saved_state.asregs.regs[5];
}
else
{
*reason = sim_stopped;
*sigrc = saved_state.asregs.exception;
}
}
void
sim_info (sd, verbose)
SIM_DESC sd;
int verbose;
{
double timetaken = (double) saved_state.asregs.ticks / (double) now_persec ();
double virttime = saved_state.asregs.cycles / 36.0e6;
callback->printf_filtered (callback, "\n\n# instructions executed %10d\n",
saved_state.asregs.insts);
callback->printf_filtered (callback, "# cycles %10d\n",
saved_state.asregs.cycles);
callback->printf_filtered (callback, "# pipeline stalls %10d\n",
saved_state.asregs.stalls);
callback->printf_filtered (callback, "# misaligned load/store %10d\n",
saved_state.asregs.memstalls);
callback->printf_filtered (callback, "# real time taken %10.4f\n",
timetaken);
callback->printf_filtered (callback, "# virtual time taken %10.4f\n",
virttime);
callback->printf_filtered (callback, "# profiling size %10d\n",
sim_profile_size);
callback->printf_filtered (callback, "# profiling frequency %10d\n",
saved_state.asregs.profile);
callback->printf_filtered (callback, "# profile maxpc %10x\n",
(1 << sim_profile_size) << PROFILE_SHIFT);
if (timetaken != 0)
{
callback->printf_filtered (callback, "# cycles/second %10d\n",
(int) (saved_state.asregs.cycles / timetaken));
callback->printf_filtered (callback, "# simulation ratio %10.4f\n",
virttime / timetaken);
}
}
void
sim_set_profile (n)
int n;
{
saved_state.asregs.profile = n;
}
void
sim_set_profile_size (n)
int n;
{
sim_profile_size = n;
}
SIM_DESC
sim_open (kind, cb, abfd, argv)
SIM_OPEN_KIND kind;
host_callback *cb;
struct _bfd *abfd;
char **argv;
{
char **p;
sim_kind = kind;
myname = argv[0];
callback = cb;
for (p = argv + 1; *p != NULL; ++p)
{
if (strcmp (*p, "-E") == 0)
{
++p;
if (*p == NULL)
{
/* FIXME: This doesn't use stderr, but then the rest of the
file doesn't either. */
callback->printf_filtered (callback, "Missing argument to `-E'.\n");
return 0;
}
target_little_endian = strcmp (*p, "big") != 0;
}
else if (isdigit (**p))
parse_and_set_memory_size (*p);
}
/* fudge our descriptor for now */
return (SIM_DESC) 1;
}
static void
parse_and_set_memory_size (str)
char *str;
{
int n;
n = strtol (str, NULL, 10);
if (n > 0 && n <= 24)
sim_memory_size = n;
else
callback->printf_filtered (callback, "Bad memory size %d; must be 1 to 24, inclusive\n", n);
}
void
sim_close (sd, quitting)
SIM_DESC sd;
int quitting;
{
/* nothing to do */
}
SIM_RC
sim_load (sd, prog, abfd, from_tty)
SIM_DESC sd;
char *prog;
bfd *abfd;
int from_tty;
{
extern bfd *sim_load_file (); /* ??? Don't know where this should live. */
bfd *prog_bfd;
prog_bfd = sim_load_file (sd, myname, callback, prog, abfd,
sim_kind == SIM_OPEN_DEBUG);
if (prog_bfd == NULL)
return SIM_RC_FAIL;
if (abfd == NULL)
bfd_close (prog_bfd);
return SIM_RC_OK;
}
SIM_RC
sim_create_inferior (sd, prog_bfd, argv, env)
SIM_DESC sd;
struct _bfd *prog_bfd;
char **argv;
char **env;
{
/* clear the registers */
memset (&saved_state, 0,
(char*)&saved_state.asregs.end_of_registers - (char*)&saved_state);
/* set the PC */
if (prog_bfd != NULL)
saved_state.asregs.pc = bfd_get_start_address (prog_bfd);
return SIM_RC_OK;
}
void
sim_do_command (sd, cmd)
SIM_DESC sd;
char *cmd;
{
char *sms_cmd = "set-memory-size";
int cmdsize;
if (cmd == NULL || *cmd == '\0')
{
cmd = "help";
}
cmdsize = strlen (sms_cmd);
if (strncmp (cmd, sms_cmd, cmdsize) == 0 && strchr (" \t", cmd[cmdsize]) != NULL)
{
parse_and_set_memory_size (cmd + cmdsize + 1);
}
else if (strcmp (cmd, "help") == 0)
{
(callback->printf_filtered) (callback, "List of SH simulator commands:\n\n");
(callback->printf_filtered) (callback, "set-memory-size <n> -- Set the number of address bits to use\n");
(callback->printf_filtered) (callback, "\n");
}
else
{
(callback->printf_filtered) (callback, "Error: \"%s\" is not a valid SH simulator command.\n", cmd);
}
}
void
sim_set_callbacks (p)
host_callback *p;
{
callback = p;
}
|