This source file includes following definitions.
- SET_PR_BITNO
- SET_AR_CHAR_BITNO
- trackport
- doFault
- core_write
- core_write_zone
- core_read2
- core_write2
- core_readN
- core_writeN
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #ifndef __STDC_WANT_IEC_60559_BFP_EXT__
24 # define __STDC_WANT_IEC_60559_BFP_EXT__ 1
25 #endif
26
27 #include <sys/types.h>
28
29 #ifdef __APPLE__
30 # undef SCHED_NEVER_YIELD
31 # define SCHED_NEVER_YIELD 1
32 # include <mach/thread_policy.h>
33 # include <mach/task_info.h>
34 # include <sys/types.h>
35 # include <sys/sysctl.h>
36 # include <mach/thread_policy.h>
37 # include <mach/thread_act.h>
38 #endif
39
40 #include "../simh/sim_timer.h"
41 #include "hdbg.h"
42
43 #define N_CPU_UNITS 1
44
45
46
47 #define JMP_ENTRY 0
48 #define JMP_REENTRY 1
49 #define JMP_STOP 2
50 #define JMP_SYNC_FAULT_RETURN 3
51 #define JMP_REFETCH 4
52 #define JMP_RESTART 5
53
54
55
56
57
58 typedef enum
59 {
60 ABSOLUTE_mode,
61 APPEND_mode,
62 } addr_modes_e;
63
64
65
66
67
68 typedef enum
69 {
70 FAULT_cycle,
71 EXEC_cycle,
72 FAULT_EXEC_cycle,
73 INTERRUPT_cycle,
74 INTERRUPT_EXEC_cycle,
75 FETCH_cycle,
76 PSEUDO_FETCH_cycle,
77 SYNC_FAULT_RTN_cycle,
78 } cycles_e;
79
80 struct tpr_s
81 {
82 word3 TRR;
83 word15 TSR;
84 word6 TBR;
85
86 word18 CA;
87
88 };
89
90 struct ppr_s
91 {
92 word3 PRR;
93
94
95 word15 PSR;
96 word1 P;
97
98
99
100
101 word18 IC;
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 struct par_s
162 {
163 word15 SNR;
164
165 word3 RNR;
166
167
168 word6 PR_BITNO;
169
170
171
172 word2 AR_CHAR;
173 word4 AR_BITNO;
174
175 word18 WORDNO;
176
177 };
178
179
180
181 #define AR PAR
182 #define PR PAR
183
184 struct bar_s
185 {
186 word9 BASE;
187
188
189 word9 BOUND;
190
191
192
193
194 };
195
196 struct dsbr_s
197 {
198 word24 ADDR;
199
200
201
202 word14 BND;
203
204
205
206 word1 U;
207
208 word12 STACK;
209
210
211
212 };
213
214
215
216
217
218
219 struct sdw_s
220 {
221 word24 ADDR;
222
223
224
225 word3 R1;
226 word3 R2;
227 word3 R3;
228 word14 BOUND;
229
230
231 word1 R;
232
233 word1 E;
234
235
236
237 word1 W;
238
239 word1 P;
240
241
242 word1 U;
243
244
245
246
247
248 word1 G;
249
250
251
252 word1 C;
253
254
255 word14 EB;
256
257
258 word15 POINTER;
259
260 word1 DF;
261
262
263
264 word2 FC;
265 word1 FE;
266
267
268
269
270
271 word6 USE;
272
273
274
275
276
277
278
279 };
280
281 typedef struct sdw_s sdw_s;
282 typedef struct sdw_s sdw0_s;
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 struct ptw_s
341 {
342 word18 ADDR;
343
344 word1 U;
345 word1 M;
346
347
348
349
350 word1 DF;
351
352
353 word2 FC;
354 word15 POINTER;
355
356 word12 PAGENO;
357
358
359 word1 FE;
360
361
362
363
364
365 word6 USE;
366
367
368
369
370
371
372
373
374 };
375
376 typedef struct ptw_s ptw_s;
377 typedef struct ptw_s ptw0_s;
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 struct cache_mode_register_s
403 {
404 word15 cache_dir_address;
405 word1 par_bit;
406 word1 lev_ful;
407 word1 csh1_on;
408
409 word1 csh2_on;
410
411
412 word1 opnd_on;
413
414 word1 inst_on;
415
416
417
418
419
420
421
422 word1 csh_reg;
423 word1 str_asd;
424 word1 col_ful;
425 word2 rro_AB;
426 word1 bypass_cache;
427 word2 luf;
428
429
430
431
432
433 };
434
435 typedef struct cache_mode_register_s cache_mode_register_s;
436
437 typedef struct mode_register_s
438 {
439 word36 r;
440
441
442 word15 FFV;
443 word1 OC_TRAP;
444 word1 ADR_TRAP;
445 word9 OPCODE;
446 word1 OPCODEX;
447
448
449
450 word1 sdpap;
451 word1 separ;
452
453
454
455
456 word1 hrhlt;
457
458
459 word1 hrxfr;
460
461
462 word1 ihr;
463 word1 ihrrs;
464
465
466
467
468 word1 hexfp;
469
470 word1 emr;
471 } mode_register_s;
472
473 extern DEVICE cpu_dev;
474
475 typedef struct MOP_struct_s
476 {
477 char * mopName;
478 int (* f) (void);
479 } MOP_struct;
480
481
482 typedef struct EISaddr_s
483 {
484 #ifndef EIS_PTR
485 word18 address;
486 #endif
487
488 word36 data;
489 word1 bit;
490 eRW mode;
491
492 int last_bit_posn;
493
494
495
496
497
498 #ifndef EIS_PTR3
499 int TA;
500 #endif
501 int TN;
502 int cPos;
503 int bPos;
504
505 #ifndef EIS_PTR4
506
507 word15 SNR;
508
509 word3 RNR;
510
511 MemoryAccessType mat;
512 #endif
513
514
515
516
517
518
519
520
521
522
523
524
525
526 bool cacheValid;
527 bool cacheDirty;
528 #define paragraphSz 8
529 #define paragraphMask 077777770
530 #define paragraphOffsetMask 07
531 word36 cachedParagraph [paragraphSz];
532 bool wordDirty [paragraphSz];
533 word18 cachedAddr;
534
535 } EISaddr;
536
537 typedef struct EISstruct_s
538 {
539 word36 op [3];
540 #define OP1 op [0]
541 #define OP2 op [1]
542 #define OP3 op [2]
543
544 bool P;
545
546 uint MF [3];
547 #define MF1 MF [0]
548 #define MF2 MF [1]
549 #define MF3 MF [2]
550
551 uint CN [3];
552 #define CN1 CN [0]
553 #define CN2 CN [1]
554 #define CN3 CN [2]
555
556 uint WN [3];
557 #define WN1 WN [0]
558 #define WN2 WN [1]
559 #define WN3 CN [2]
560
561 uint C [3];
562 #define C1 C [0]
563 #define C2 C [1]
564 #define C3 C [2]
565
566 uint B [3];
567 #define B1 B [0]
568 #define B2 B [1]
569 #define B3 B [2]
570
571 uint N [3];
572 #define N1 N [0]
573 #define N2 N [1]
574 #define N3 N [2]
575
576 uint TN [3];
577 #define TN1 TN [0]
578 #define TN2 TN [1]
579 #define TN3 TN [2]
580
581 #ifdef EIS_PTR3
582 # define TA1 cpu.du.TAk[0]
583 # define TA2 cpu.du.TAk[1]
584 # define TA3 cpu.du.TAk[2]
585 #else
586
587 uint TA [3];
588 # define TA1 TA [0]
589 # define TA2 TA [1]
590 # define TA3 TA [2]
591 #endif
592
593 uint S [3];
594 #define S1 S [0]
595 #define S2 S [1]
596 #define S3 S [2]
597
598 int SF [3];
599 #define SF1 SF [0]
600 #define SF2 SF [1]
601 #define SF3 SF [2]
602
603 word18 _flags;
604 word18 _faults;
605
606 word72s x;
607
608
609
610 word9 editInsertionTable [8];
611
612 int mopIF;
613 MOP_struct *m;
614
615 word9 inBuffer [64];
616 word9 *in;
617 uint inBufferCnt;
618 word9 outBuffer [64];
619 word9 *out;
620
621 int exponent;
622 int sign;
623
624 #ifdef EIS_PTR2
625 # define KMOP 1
626 #else
627 EISaddr *mopAddress;
628 #endif
629
630 int mopTally;
631 int mopPos;
632
633
634
635
636
637 bool mopES;
638
639 bool mopSN;
640
641
642
643
644
645
646
647
648
649
650 bool mopZ;
651
652
653 bool mopBZ;
654
655
656
657
658
659
660 EISaddr addr [3];
661
662 #define ADDR1 addr [0]
663 int srcTally;
664 int srcTA;
665 int srcSZ;
666
667 #define ADDR2 addr [1]
668
669 #define ADDR3 addr [2]
670 int dstTally;
671 int dstSZ;
672
673 bool mvne;
674 } EISstruct;
675
676
677
678 typedef struct DCDstruct_s
679 {
680 struct opcode_s * info;
681 uint32 opcode;
682 bool opcodeX;
683 uint32 opcode10;
684 word18 address;
685 word1 b29;
686 bool i;
687 word6 tag;
688
689 bool stiTally;
690 bool restart;
691 } DCDstruct;
692
693
694
695 typedef struct
696 {
697 vol int fault [N_FAULT_GROUPS];
698
699 vol bool XIP [N_SCU_UNITS_MAX];
700 } events_t;
701
702
703
704 enum procModeSettings { procModeGCOS = 1, procModeMultics = 0 };
705
706
707 typedef struct
708 {
709 uint FLT_BASE;
710 uint cpu_num;
711 word36 data_switches;
712 word18 addr_switches;
713 uint assignment [N_CPU_PORTS];
714 uint interlace [N_CPU_PORTS];
715 uint enable [N_CPU_PORTS];
716 uint init_enable [N_CPU_PORTS];
717 uint store_size [N_CPU_PORTS];
718 enum procModeSettings procMode;
719
720 bool enable_cache;
721 bool sdwam_enable;
722 bool ptwam_enable;
723
724
725 uint serno;
726 } switches_t;
727
728
729 typedef struct {
730 uint proc_speed;
731 bool hex_mode_installed;
732 bool prom_installed;
733 bool cache_installed;
734 bool clock_slave_installed;
735 } optionsType;
736
737
738 typedef struct {
739 uint report_faults;
740 uint tro_enable;
741 uint drl_fatal;
742 bool useMap;
743 uint dis_enable;
744 uint halt_on_unimp;
745 bool isolts_mode;
746 uint enable_wam;
747 bool enable_emcall;
748 bool nodis;
749 bool l68_mode;
750 } tweaksType;
751
752 enum ou_cycle_e
753 {
754 ou_GIN = 0400,
755 ou_GOS = 0200,
756 ou_GD1 = 0100,
757 ou_GD2 = 0040,
758 ou_GOE = 0020,
759 ou_GOA = 0010,
760 ou_GOM = 0004,
761 ou_GON = 0002,
762 ou_GOF = 0001
763 };
764
765 typedef struct
766 {
767
768 bool directOperandFlag;
769 word36 directOperand;
770 word6 characterOperandSize;
771 word3 characterOperandOffset;
772 word18 character_address;
773 word36 character_data;
774 bool crflag;
775
776
777 word2 eac;
778 word1 RB1_FULL;
779 word1 RP_FULL;
780 word1 RS_FULL;
781 word9 cycle;
782 word1 STR_OP;
783
784
785 #ifdef PANEL68
786 word9 RS;
787 word4 opsz;
788 word10 reguse;
789 #endif
790 } ou_unit_data_t;
791
792
793
794 enum APUH_e
795 {
796 APUH_FDSPTW = 1llu << (35 - 17),
797 APUH_MDSPTW = 1llu << (35 - 18),
798 APUH_FSDWP = 1llu << (35 - 19),
799 APUH_FPTW = 1llu << (35 - 20),
800 APUH_FPTW2 = 1llu << (35 - 21),
801 APUH_MPTW = 1llu << (35 - 22),
802 APUH_FANP = 1llu << (35 - 23),
803 APUH_FAP = 1llu << (35 - 24)
804 };
805
806 enum {
807
808 apu_FLT = 1ll << (33 - 0),
809
810
811 apu_ESN_PSR = 0,
812 apu_ESN_SNR = 1ll << (33- 1),
813 apu_ESN_TSR = 1ll << (33- 2),
814
815
816 apu_HOLD = 1ll << (33- 4),
817
818
819
820
821 apu_TP_P = 1ll << (33- 8),
822
823 apu_PP_P = 1ll << (33- 9),
824
825
826
827
828
829
830
831
832
833
834 apu_FDPT = 1ll << (33-20),
835 apu_MDPT = 1ll << (33-21),
836 apu_FSDP = 1ll << (33-22),
837 apu_FSDN = 1ll << (33-23),
838 apu_FPTW = 1ll << (33-24),
839 apu_MPTW = 1ll << (33-25),
840 apu_FPTW2 = 1ll << (33-26),
841 apu_FAP = 1ll << (33-27),
842
843 apu_FANP = 1ll << (33-28),
844
845
846 apu_FA = 1ll << (33-30),
847
848 apu_PIAU = 1ll << (33-32)
849
850 };
851
852 typedef struct
853 {
854 processor_cycle_type lastCycle;
855 #ifdef PANEL68
856 word34 state;
857 #endif
858 } apu_unit_data_t;
859
860 typedef struct
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 word1 XSF;
890 word1 SDWAMM;
891 word1 SD_ON;
892 word1 PTWAMM;
893 word1 PT_ON;
894
895
896
897
898
899
900
901
902
903
904
905
906
907 word12 APUCycleBits;
908
909
910
911
912
913
914
915 word1 IRO_ISN;
916
917 word1 OEB_IOC;
918
919
920 word1 EOFF_IAIM;
921
922
923 word1 ORB_ISP;
924
925 word1 ROFF_IPR;
926
927 word1 OWB_NEA;
928
929 word1 WOFF_OOB;
930
931 word1 NO_GA;
932 word1 OCB;
933 word1 OCALL;
934 word1 BOC;
935
936 word1 PTWAM_ER;
937 word1 CRT;
938 word1 RALR;
939
940 word1 SDWAM_ER;
941 word1 OOSB;
942 word1 PARU;
943 word1 PARL;
944 word1 ONC1;
945 word1 ONC2;
946 word4 IA;
947 word3 IACHN;
948 word3 CNCHN;
949 word5 FI_ADDR;
950 word1 FLT_INT;
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967 word6 delta;
968
969
970
971
972
973
974
975
976
977
978
979
980
981 word3 TSN_PRNO [3];
982 word1 TSN_VALID [3];
983
984
985
986
987
988 word18 IR;
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009 word1 repeat_first;
1010
1011 word1 rpt;
1012 word1 rd;
1013 word1 rl;
1014 word1 pot;
1015
1016
1017
1018
1019
1020
1021 word1 xde;
1022
1023 word1 xdo;
1024 word1 itp;
1025 word1 rfi;
1026 word1 its;
1027 word1 FIF;
1028 word6 CT_HOLD;
1029
1030
1031 word36 IWB;
1032
1033
1034 word36 IRODD;
1035 } ctl_unit_data_t;
1036
1037 #define USE_IRODD (cpu.cu.rd && ((cpu. PPR.IC & 1) != 0))
1038 #define IWB_IRODD (USE_IRODD ? cpu.cu.IRODD : cpu.cu.IWB)
1039
1040
1041 enum du_cycle1_e
1042 {
1043
1044 du1_nFPOL = 0400000000000ll,
1045
1046 du1_nFPOP = 0200000000000ll,
1047
1048 du1_nNEED_DESC = 0100000000000ll,
1049
1050 du1_nSEL_DIR = 0040000000000ll,
1051
1052 du1_nDLEN_DIRECT = 0020000000000ll,
1053
1054 du1_nDFRST = 0010000000000ll,
1055
1056 du1_nFEXR = 0004000000000ll,
1057
1058 du1_nLAST_DFRST = 0002000000000ll,
1059
1060 du1_nDDU_LDEA = 0001000000000ll,
1061
1062 du1_nDDU_STEA = 0000400000000ll,
1063
1064 du1_nDREDO = 0000200000000ll,
1065
1066 du1_nDLVL_WD_SZ = 0000100000000ll,
1067
1068 du1_nEXH = 0000040000000ll,
1069
1070 du1_DEND_SEQ = 0000020000000ll,
1071
1072 du1_nEND = 0000010000000ll,
1073
1074 du1_nDU_RD_WRT = 0000004000000ll,
1075
1076 du1_nPTRA00 = 0000002000000ll,
1077
1078 du1_nPTRA01 = 0000001000000ll,
1079
1080 du1_FA_I1 = 0000000400000ll,
1081
1082 du1_FA_I2 = 0000000200000ll,
1083
1084 du1_FA_I3 = 0000000100000ll,
1085
1086 du1_nWRD = 0000000040000ll,
1087
1088 du1_nNINE = 0000000020000ll,
1089
1090 du1_nSIX = 0000000010000ll,
1091
1092 du1_nFOUR = 0000000004000ll,
1093
1094 du1_nBIT = 0000000002000ll,
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104 du1_FSAMPL = 0000000000040ll,
1105
1106 du1_nDFRST_CT = 0000000000020ll,
1107
1108 du1_nADJ_LENTGH = 0000000000010ll,
1109
1110 du1_nINTRPTD = 0000000000004ll,
1111
1112 du1_nINHIB = 0000000000002ll,
1113
1114
1115 };
1116
1117
1118 enum du_cycle2_e
1119 {
1120
1121 du2_DUD = 0400000000000ll,
1122
1123 du2_nGDLDA = 0200000000000ll,
1124
1125 du2_nGDLDB = 0100000000000ll,
1126
1127 du2_nGDLDC = 0040000000000ll,
1128
1129 du2_NLD1 = 0020000000000ll,
1130
1131 du2_GLDP1 = 0010000000000ll,
1132
1133 du2_NLD2 = 0004000000000ll,
1134
1135 du2_GLDP2 = 0002000000000ll,
1136
1137 du2_ANLD1 = 0001000000000ll,
1138
1139 du2_ANLD2 = 0000400000000ll,
1140
1141 du2_LDWRT1 = 0000200000000ll,
1142
1143 du2_LDWRT2 = 0000100000000ll,
1144
1145 du2_nDATA_AVLDU = 0000040000000ll,
1146
1147 du2_WRT1 = 0000020000000ll,
1148
1149 du2_GSTR = 0000010000000ll,
1150
1151 du2_ANSTR = 0000004000000ll,
1152
1153 du2_FSTR_OP_AV = 0000002000000ll,
1154
1155 du2_nFEND_SEQ = 0000001000000ll,
1156
1157 du2_nFLEN_128 = 0000000400000ll,
1158
1159 du2_FGCH = 0000000200000ll,
1160
1161 du2_FANPK = 0000000100000ll,
1162
1163 du2_FEXOP = 0000000040000ll,
1164
1165 du2_FBLNK = 0000000020000ll,
1166
1167
1168
1169 du2_DGBD = 0000000004000ll,
1170
1171 du2_DGDB = 0000000002000ll,
1172
1173 du2_DGSP = 0000000001000ll,
1174
1175 du2_FFLTG = 0000000000400ll,
1176
1177 du2_FRND = 0000000000200ll,
1178
1179 du2_DADD_GATE = 0000000000100ll,
1180
1181 du2_DMP_DV_GATE = 0000000000040ll,
1182
1183 du2_DXPN_GATE = 0000000000020ll,
1184
1185
1186
1187
1188
1189
1190
1191
1192 };
1193
1194
1195 #define DU_CYCLE_GDLDA { clrmask (& cpu.du.cycle2, du2_nGDLDA); \
1196 setmask (& cpu.du.cycle2, du2_nGDLDB | du2_nGDLDC); }
1197 #define DU_CYCLE_GDLDB { clrmask (& cpu.du.cycle2, du2_nGDLDB); \
1198 setmask (& cpu.du.cycle2, du2_nGDLDA | du2_nGDLDC); }
1199 #define DU_CYCLE_GDLDC { clrmask (& cpu.du.cycle2, du2_nGDLDC); \
1200 setmask (& cpu.du.cycle2, du2_nGDLDA | du2_nGDLDB); }
1201 #define DU_CYCLE_FA_I1 setmask (& cpu.du.cycle1, du1_FA_I1)
1202 #define DU_CYCLE_FA_I2 setmask (& cpu.du.cycle1, du1_FA_I2)
1203 #define DU_CYCLE_FA_I3 setmask (& cpu.du.cycle1, du1_FA_I3)
1204 #define DU_CYCLE_ANLD1 setmask (& cpu.du.cycle2, du2_ANLD1)
1205 #define DU_CYCLE_ANLD2 setmask (& cpu.du.cycle2, du2_ANLD2)
1206 #define DU_CYCLE_NLD1 setmask (& cpu.du.cycle2, du2_NLD1)
1207 #define DU_CYCLE_NLD2 setmask (& cpu.du.cycle2, du2_NLD2)
1208 #define DU_CYCLE_FRND setmask (& cpu.du.cycle2, du2_FRND)
1209 #define DU_CYCLE_DGBD setmask (& cpu.du.cycle2, du2_DGBD)
1210 #define DU_CYCLE_DGDB setmask (& cpu.du.cycle2, du2_DGDB)
1211 #define DU_CYCLE_DDU_LDEA clrmask (& cpu.du.cycle1, du1_nDDU_LDEA)
1212 #define DU_CYCLE_DDU_STEA clrmask (& cpu.du.cycle1, du1_nDDU_STEA)
1213 #define DU_CYCLE_END clrmask (& cpu.du.cycle1, du1_nEND)
1214 #define DU_CYCLE_LDWRT1 setmask (& cpu.du.cycle2, du2_LDWRT1)
1215 #define DU_CYCLE_LDWRT2 setmask (& cpu.du.cycle2, du2_LDWRT2)
1216 #define DU_CYCLE_FEXOP setmask (& cpu.du.cycle2, du2_FEXOP)
1217 #define DU_CYCLE_ANSTR setmask (& cpu.du.cycle2, du2_ANSTR)
1218 #define DU_CYCLE_GSTR setmask (& cpu.du.cycle2, du2_GSTR)
1219 #define DU_CYCLE_FLEN_128 clrmask (& cpu.du.cycle2, du2_nFLEN_128)
1220 #define DU_CYCLE_FDUD { cpu.du.cycle1 = \
1221 du1_nFPOL | \
1222 du1_nFPOP | \
1223 du1_nNEED_DESC | \
1224 du1_nSEL_DIR | \
1225 du1_nDLEN_DIRECT | \
1226 du1_nDFRST | \
1227 du1_nFEXR | \
1228 du1_nLAST_DFRST | \
1229 du1_nDDU_LDEA | \
1230 du1_nDDU_STEA | \
1231 du1_nDREDO | \
1232 du1_nDLVL_WD_SZ | \
1233 du1_nEXH | \
1234 du1_nEND | \
1235 du1_nDU_RD_WRT | \
1236 du1_nWRD | \
1237 du1_nNINE | \
1238 du1_nSIX | \
1239 du1_nFOUR | \
1240 du1_nBIT | \
1241 du1_nINTRPTD | \
1242 du1_nINHIB; \
1243 cpu.du.cycle2 = \
1244 du2_DUD | \
1245 du2_nGDLDA | \
1246 du2_nGDLDB | \
1247 du2_nGDLDC | \
1248 du2_nDATA_AVLDU | \
1249 du2_nFEND_SEQ | \
1250 du2_nFLEN_128; \
1251 }
1252 #define DU_CYCLE_nDUD clrmask (& cpu.du.cycle2, du2_DUD)
1253
1254 #ifdef PANEL68
1255
1256
1257 # define CPT(R,C) cpu.cpt[R][C]=1
1258 # define CPTUR(C) cpu.cpt[cpt5L][C]=1
1259 #else
1260 # define CPT(R,C)
1261 # define CPTUR(C)
1262 #endif
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 typedef struct du_unit_data_t
1356 {
1357
1358
1359
1360 word1 Z;
1361
1362 word1 NOP;
1363
1364 word24 CHTALLY;
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 word10 LEVEL1;
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410 word1 R;
1411
1412
1413
1414
1415
1416
1417
1418
1419 word10 LEVEL2;
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441 word3 JMP;
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453 word2 TAk [3];
1454
1455
1456
1457
1458 word18 Dk_PTR_W [3];
1459 #define D1_PTR_W Dk_PTR_W [0]
1460 #define D2_PTR_W Dk_PTR_W [1]
1461 #define D3_PTR_W Dk_PTR_W [2]
1462
1463 word6 Dk_PTR_B [3];
1464 #define D1_PTR_B Dk_PTR_B [0]
1465 #define D2_PTR_B Dk_PTR_B [1]
1466 #define D3_PTR_B Dk_PTR_B [2]
1467
1468 word24 Dk_RES [3];
1469 #define D_RES Dk_RES
1470 #define D1_RES Dk_RES [0]
1471 #define D2_RES Dk_RES [1]
1472 #define D3_RES Dk_RES [2]
1473
1474 word1 Fk [3];
1475
1476 #define F1 Fk [0]
1477 #define F2 Fk [0]
1478 #define F3 Fk [0]
1479
1480 word1 Ak [3];
1481
1482
1483
1484
1485 word7 MF [3];
1486
1487
1488 word36 image [8];
1489
1490 #ifdef PANEL68
1491 word37 cycle1;
1492 word37 cycle2;
1493 word1 POL;
1494 word1 POP;
1495 #endif
1496 } du_unit_data_t;
1497
1498 #ifdef PANEL68
1499
1500 enum
1501 {
1502 ps_PIA = 0200,
1503 ps_POA = 0100,
1504 ps_RIW = 0040,
1505 ps_SIW = 0020,
1506 ps_POT = 0010,
1507 ps_PON = 0004,
1508 ps_RAW = 0002,
1509 ps_SAW = 0001
1510 };
1511 #endif
1512
1513
1514
1515
1516
1517 enum { CUH_XINT = 0100, CUH_IFT = 040, CUH_CRD = 020, CUH_MRD = 010,
1518 CUH_MSTO = 04, CUH_PIB = 02 };
1519
1520 #define N_DPS8M_WAM_ENTRIES 64
1521 #define N_DPS8M_WAM_MASK 077
1522 #define N_L68_WAM_ENTRIES 16
1523 #define N_L68_WAM_MASK 017
1524 #define N_NAX_WAM_ENTRIES 64
1525 #define N_MODEL_WAM_ENTRIES (cpu.tweaks.l68_mode ? N_L68_WAM_ENTRIES : N_DPS8M_WAM_ENTRIES)
1526
1527 typedef struct
1528 {
1529
1530 EISstruct currentEISinstruction;
1531
1532 unsigned long long cycleCnt;
1533 unsigned long long instrCnt;
1534 unsigned long long instrCntT0;
1535 unsigned long long instrCntT1;
1536 unsigned long long lockCnt;
1537 unsigned long long lockImmediate;
1538 unsigned long long lockWait;
1539 unsigned long long lockWaitMax;
1540 #ifndef SCHED_NEVER_YIELD
1541 unsigned long long lockYield;
1542 #endif
1543
1544
1545 _fault_subtype subFault;
1546
1547 word36 rA;
1548 word36 rQ;
1549
1550 fault_acv_subtype_ acvFaults;
1551
1552 sdw_s * SDW;
1553
1554
1555 word36 zone;
1556
1557 ptw_s * PTW;
1558
1559 word36 CY;
1560
1561 uint64 lufCounter;
1562
1563 _fault_subtype dlySubFltNum;
1564
1565 const char * dlyCtx;
1566
1567 word36 faultRegister [2];
1568
1569 word36 itxPair [2];
1570
1571
1572
1573
1574
1575 mode_register_s MR;
1576
1577
1578
1579 mode_register_s MR_cache;
1580
1581 DCDstruct currentInstruction;
1582
1583 ou_unit_data_t ou;
1584
1585 word36 Ypair[2];
1586 word36 Yblock8[8];
1587 word36 Yblock16[16];
1588 word36 Yblock32[32];
1589
1590 word36 scu_data[8];
1591
1592 ctl_unit_data_t cu;
1593 du_unit_data_t du;
1594
1595 switches_t switches;
1596 optionsType options;
1597 tweaksType tweaks;
1598 switches_t isolts_switches_save;
1599
1600 jmp_buf jmpMain;
1601
1602 unsigned long faultCnt [N_FAULTS];
1603
1604 _fault_subtype g7SubFaults [N_FAULTS];
1605
1606 word36 history [N_HIST_SETS] [N_MAX_HIST_SIZE] [2];
1607
1608 cycles_e cycle;
1609
1610 _fault faultNumber;
1611
1612 apu_unit_data_t apu;
1613
1614 word27 rTR;
1615 #if defined(THREADZ) || defined(LOCKLESS)
1616 uint rTRsample;
1617 #endif
1618
1619 word24 rY;
1620
1621 word18 lnk;
1622
1623 uint g7FaultsPreset;
1624 uint g7Faults;
1625
1626 word24 iefpFinalAddress;
1627
1628
1629 uint rTRlsb;
1630 uint shadowTR;
1631 uint TR0;
1632
1633
1634 _fault dlyFltNum;
1635
1636 word18 last_write;
1637
1638 #ifdef LOCKLESS
1639 word24 locked_addr;
1640 word24 char_word_address;
1641 #endif
1642
1643 word24 rmw_address;
1644
1645 uint restart_address;
1646
1647 struct
1648 {
1649 word15 PSR;
1650 word3 PRR;
1651 word18 IC;
1652 } cu_data;
1653 uint rTRticks;
1654
1655 struct tpr_s TPR;
1656 struct ppr_s PPR;
1657 struct dsbr_s DSBR;
1658 ptw0_s PTW0;
1659
1660 uint history_cyclic [N_HIST_SETS];
1661
1662 sdw_s SDW0;
1663 sdw_s _s;
1664
1665 word18 rX [8];
1666
1667
1668 uint sc_num_banks [N_SCU_UNITS_MAX];
1669
1670
1671
1672
1673
1674
1675 uint scu_port[N_SCU_UNITS_MAX];
1676
1677
1678
1679 uint FFV_faults_preset;
1680 uint FFV_faults;
1681 uint FFV_fault_number;
1682
1683 #ifdef AFFINITY
1684 uint affinity;
1685 #endif
1686
1687 events_t events;
1688
1689 word24 pad[16];
1690
1691 struct par_s PAR [8];
1692
1693 ptw_s PTWAM [N_NAX_WAM_ENTRIES];
1694
1695
1696
1697
1698
1699 int sc_addr_map [N_SCBANKS];
1700
1701 int sc_scu_map [N_SCBANKS];
1702
1703 sdw_s SDWAM [N_NAX_WAM_ENTRIES];
1704
1705
1706 word12 AM_tally;
1707
1708 struct bar_s BAR;
1709
1710 cache_mode_register_s CMR;
1711
1712
1713
1714 bool interrupt_flag;
1715 bool g7_flag;
1716
1717 bool wasXfer;
1718
1719 bool wasInhibited;
1720
1721
1722 bool isExec;
1723
1724 bool isXED;
1725
1726
1727 bool isolts_switches_saved;
1728
1729 word8 rE;
1730
1731 word6 rTAG;
1732 word3 rRALR;
1733 word3 RSDWH_R1;
1734
1735
1736
1737 word6 SDWAMR;
1738
1739
1740 bool useZone;
1741
1742
1743
1744 word6 PTWAMR;
1745
1746
1747 bool bTroubleFaultCycle;
1748
1749 bool lufOccurred;
1750 bool secret_addressing_mode;
1751
1752
1753 bool skip_cu_hist;
1754
1755
1756 bool dlyFlt;
1757
1758 bool restart;
1759
1760
1761 bool is_FFV;
1762
1763 #ifdef ROUND_ROBIN
1764 bool isRunning;
1765 #endif
1766
1767 #ifdef AFFINITY
1768 bool set_affinity;
1769 #endif
1770
1771 #ifdef SPEED
1772 # define SC_MAP_ADDR(addr,real_addr) \
1773 if (cpu.tweaks.useMap) \
1774 { \
1775 uint pgnum = addr / SCBANK_SZ; \
1776 uint os = addr % SCBANK_SZ; \
1777 int base = cpu.sc_addr_map[pgnum]; \
1778 if (base < 0) \
1779 { \
1780 doFault (FAULT_STR, fst_str_nea, __func__); \
1781 } \
1782 real_addr = (uint) base + os; \
1783 } \
1784 else \
1785 real_addr = addr;
1786 #else
1787 # define SC_MAP_ADDR(addr,real_addr) \
1788 if (cpu.tweaks.useMap) \
1789 { \
1790 uint pgnum = addr / SCBANK_SZ; \
1791 uint os = addr % SCBANK_SZ; \
1792 int base = cpu.sc_addr_map[pgnum]; \
1793 if (base < 0) \
1794 { \
1795 doFault (FAULT_STR, fst_str_nea, __func__); \
1796 } \
1797 real_addr = (uint) base + os; \
1798 } \
1799 else \
1800 { \
1801 nem_check (addr, __func__); \
1802 real_addr = addr; \
1803 }
1804 #endif
1805
1806 #ifdef PANEL68
1807
1808 word18 lastPTWOffset;
1809
1810
1811
1812 bool lastPTWIsDS;
1813 word18 APUDataBusOffset;
1814 word24 APUDataBusAddr;
1815 word24 APUMemAddr;
1816 word1 panel4_red_ready_light_state;
1817 word1 panel7_enabled_light_state;
1818
1819 volatile word15 APU_panel_segno_sw;
1820 volatile word1 APU_panel_enable_match_ptw_sw;
1821 volatile word1 APU_panel_enable_match_sdw_sw;
1822 volatile word1 APU_panel_scroll_select_ul_sw;
1823 volatile word4 APU_panel_scroll_select_n_sw;
1824 volatile word4 APU_panel_scroll_wheel_sw;
1825
1826 volatile word18 APU_panel_enter_sw;
1827 volatile word18 APU_panel_display_sw;
1828 volatile word4 CP_panel_wheel_sw;
1829 volatile word4 DATA_panel_ds_sw;
1830 volatile word4 DATA_panel_d1_sw;
1831 volatile word4 DATA_panel_d2_sw;
1832 volatile word4 DATA_panel_d3_sw;
1833 volatile word4 DATA_panel_d4_sw;
1834 volatile word4 DATA_panel_d5_sw;
1835 volatile word4 DATA_panel_d6_sw;
1836 volatile word4 DATA_panel_d7_sw;
1837 volatile word4 DATA_panel_wheel_sw;
1838 volatile word4 DATA_panel_addr_stop_sw;
1839 volatile word1 DATA_panel_enable_sw;
1840 volatile word1 DATA_panel_validate_sw;
1841 volatile word1 DATA_panel_auto_fast_sw;
1842 volatile word1 DATA_panel_auto_slow_sw;
1843 volatile word4 DATA_panel_cycle_sw;
1844 volatile word1 DATA_panel_step_sw;
1845 volatile word1 DATA_panel_s_trig_sw;
1846 volatile word1 DATA_panel_execute_sw;
1847 volatile word1 DATA_panel_scope_sw;
1848 volatile word1 DATA_panel_init_sw;
1849 volatile word1 DATA_panel_exec_sw;
1850 volatile word4 DATA_panel_hr_sel_sw;
1851 volatile word4 DATA_panel_trackers_sw;
1852 volatile bool panelInitialize;
1853
1854
1855 bool portBusy;
1856 word2 portSelect;
1857 word36 portAddr [N_CPU_PORTS];
1858 word36 portData [N_CPU_PORTS];
1859
1860 word36 IWRAddr;
1861 word7 dataMode;
1862
1863
1864
1865
1866
1867
1868 word8 prepare_state;
1869 bool DACVpDF;
1870 bool AR_F_E;
1871 bool INS_FETCH;
1872
1873 word1 cpt [28] [36];
1874 #endif
1875 #define cpt1U 0
1876 #define cpt1L 1
1877 #define cpt2U 2
1878 #define cpt2L 3
1879 #define cpt3U 4
1880 #define cpt3L 5
1881 #define cpt4U 6
1882 #define cpt4L 7
1883 #define cpt5U 8
1884 #define cpt5L 9
1885 #define cpt6U 10
1886 #define cpt6L 11
1887 #define cpt7U 12
1888 #define cpt7L 13
1889 #define cpt8U 14
1890 #define cpt8L 15
1891 #define cpt9U 16
1892 #define cpt9L 17
1893 #define cpt10U 18
1894 #define cpt10L 19
1895 #define cpt11U 20
1896 #define cpt11L 21
1897 #define cpt12U 22
1898 #define cpt12L 23
1899 #define cpt13U 24
1900 #define cpt13L 25
1901 #define cpt14U 26
1902 #define cpt14L 27
1903
1904 #define cptUseE 0
1905 #define cptUseBAR 1
1906 #define cptUseTR 2
1907 #define cptUseRALR 3
1908 #define cptUsePRn 4
1909 #define cptUseDSBR 12
1910 #define cptUseFR 13
1911 #define cptUseMR 14
1912 #define cptUseCMR 15
1913 #define cptUseIR 16
1914 } cpu_state_t;
1915
1916 #ifdef M_SHARED
1917 extern cpu_state_t * cpus;
1918 #else
1919 extern cpu_state_t cpus [N_CPU_UNITS_MAX];
1920 #endif
1921
1922 #if defined(THREADZ) || defined(LOCKLESS)
1923 extern __thread cpu_state_t * restrict cpup;
1924 #else
1925 extern cpu_state_t * restrict cpup;
1926 #endif
1927 #define cpu (* cpup)
1928
1929 #define N_STALL_POINTS 16
1930 struct stall_point_s
1931 {
1932 word15 segno;
1933 word18 offset;
1934 useconds_t time;
1935 };
1936 extern struct stall_point_s stall_points [N_STALL_POINTS];
1937 extern bool stall_point_active;
1938
1939 uint set_cpu_idx (uint cpuNum);
1940 #if defined(THREADZ) || defined(LOCKLESS)
1941 extern __thread uint current_running_cpu_idx;
1942 extern bool bce_dis_called;
1943 #else
1944 # ifdef ROUND_ROBIN
1945 extern uint current_running_cpu_idx;
1946 # else
1947 # define current_running_cpu_idx 0
1948 # endif
1949 #endif
1950
1951
1952
1953 #define GET_PR_BITNO(n) (cpu.PAR[n].PR_BITNO)
1954 #define GET_AR_BITNO(n) (cpu.PAR[n].AR_BITNO)
1955 #define GET_AR_CHAR(n) (cpu.PAR[n].AR_CHAR)
1956 static inline void SET_PR_BITNO (uint n, word6 b)
1957 {
1958 cpu.PAR[n].PR_BITNO = b;
1959 cpu.PAR[n].AR_BITNO = (b % 9) & MASK4;
1960 cpu.PAR[n].AR_CHAR = (b / 9) & MASK2;
1961 }
1962 static inline void SET_AR_CHAR_BITNO (uint n, word2 c, word4 b)
1963 {
1964 cpu.PAR[n].PR_BITNO = c * 9 + b;
1965 cpu.PAR[n].AR_BITNO = b & MASK4;
1966 cpu.PAR[n].AR_CHAR = c & MASK2;
1967 }
1968
1969 bool sample_interrupts (void);
1970 t_stat simh_hooks (void);
1971 int operand_size (void);
1972 t_stat read_operand (word18 addr, processor_cycle_type cyctyp);
1973 t_stat write_operand (word18 addr, processor_cycle_type acctyp);
1974
1975 #ifdef PANEL68
1976 static inline void trackport (word24 a, word36 d)
1977 {
1978
1979 word2 port = (a >> 22) & MASK2;
1980 cpu.portSelect = port;
1981 cpu.portAddr [port] = a;
1982 cpu.portData [port] = d;
1983 cpu.portBusy = false;
1984 }
1985 #endif
1986
1987 #if defined(SPEED) && defined(INLINE_CORE)
1988
1989 void doFault (_fault faultNumber, _fault_subtype faultSubtype,
1990 const char * faultMsg) NO_RETURN;
1991 extern const _fault_subtype fst_str_nea;
1992
1993 static inline int core_read (word24 addr, word36 *data, \
1994 UNUSED const char * ctx)
1995 {
1996 PNL (cpu.portBusy = true;)
1997 SC_MAP_ADDR (addr, addr);
1998 * data = M[addr] & DMASK;
1999 # ifdef TR_WORK_MEM
2000 cpu.rTRticks ++;
2001 # endif
2002 PNL (trackport (addr, * data);)
2003 return 0;
2004 }
2005
2006 static inline int core_write (word24 addr, word36 data, \
2007 UNUSED const char * ctx)
2008 {
2009 PNL (cpu.portBusy = true;)
2010 SC_MAP_ADDR (addr, addr);
2011 if (cpu.tweaks.isolts_mode)
2012 {
2013 if (cpu.MR.sdpap)
2014 {
2015 sim_warn ("failing to implement sdpap\n");
2016 cpu.MR.sdpap = 0;
2017 }
2018 if (cpu.MR.separ)
2019 {
2020 sim_warn ("failing to implement separ\n");
2021 cpu.MR.separ = 0;
2022 }
2023 }
2024 M[addr] = data & DMASK;
2025 # ifdef TR_WORK_MEM
2026 cpu.rTRticks ++;
2027 # endif
2028 PNL (trackport (addr, data);)
2029 return 0;
2030 }
2031
2032 static inline int core_write_zone (word24 addr, word36 data, \
2033 UNUSED const char * ctx)
2034 {
2035 PNL (cpu.portBusy = true;)
2036 SC_MAP_ADDR (addr, addr);
2037 if (cpu.tweaks.isolts_mode)
2038 {
2039 if (cpu.MR.sdpap)
2040 {
2041 sim_warn ("failing to implement sdpap\n");
2042 cpu.MR.sdpap = 0;
2043 }
2044 if (cpu.MR.separ)
2045 {
2046 sim_warn ("failing to implement separ\n");
2047 cpu.MR.separ = 0;
2048 }
2049 }
2050 M[addr] = (M[addr] & ~cpu.zone) | (data & cpu.zone);
2051 cpu.useZone = false;
2052 # ifdef TR_WORK_MEM
2053 cpu.rTRticks ++;
2054 # endif
2055 PNL (trackport (addr, data);)
2056 return 0;
2057 }
2058
2059 static inline int core_read2 (word24 addr, word36 *even, word36 *odd,
2060 UNUSED const char * ctx)
2061 {
2062 PNL (cpu.portBusy = true;)
2063 SC_MAP_ADDR (addr, addr);
2064 *even = M[addr++] & DMASK;
2065 *odd = M[addr] & DMASK;
2066 # ifdef TR_WORK_MEM
2067 cpu.rTRticks ++;
2068 # endif
2069 PNL (trackport (addr - 1, * even);)
2070 return 0;
2071 }
2072
2073 static inline int core_write2 (word24 addr, word36 even, word36 odd,
2074 UNUSED const char * ctx)
2075 {
2076 PNL (cpu.portBusy = true;)
2077 SC_MAP_ADDR (addr, addr);
2078 if (cpu.tweaks.isolts_mode)
2079 {
2080 if (cpu.MR.sdpap)
2081 {
2082 sim_warn ("failing to implement sdpap\n");
2083 cpu.MR.sdpap = 0;
2084 }
2085 if (cpu.MR.separ)
2086 {
2087 sim_warn ("failing to implement separ\n");
2088 cpu.MR.separ = 0;
2089 }
2090 }
2091 M[addr++] = even;
2092 M[addr] = odd;
2093 PNL (trackport (addr - 1, even);)
2094 # ifdef TR_WORK_MEM
2095 cpu.rTRticks ++;
2096 # endif
2097 return 0;
2098 }
2099 #else
2100 int core_read (word24 addr, word36 *data, const char * ctx);
2101 int core_write (word24 addr, word36 data, const char * ctx);
2102 int core_write_zone (word24 addr, word36 data, const char * ctx);
2103 int core_read2 (word24 addr, word36 *even, word36 *odd, const char * ctx);
2104 int core_write2 (word24 addr, word36 even, word36 odd, const char * ctx);
2105 #endif
2106
2107 #ifdef LOCKLESS
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146 # if ( defined (AIX_ATOMICS) && \
2147 (! (defined (SYNC_ATOMICS))))
2148 # define SYNC_ATOMICS 1
2149 # endif
2150
2151
2152 # if (! defined (GNU_ATOMICS)) && (! defined (SYNC_ATOMICS)) && \
2153 (! defined (BSD_ATOMICS)) && (! defined (AIX_ATOMICS))
2154 # if defined(__FreeBSD__) \
2155 || defined(__FreeBSD_kernel__) \
2156 || defined(__DragonFly__)
2157 # undef BSD_ATOMICS
2158 # define BSD_ATOMICS 1
2159 # endif
2160 # endif
2161
2162
2163 # if (! defined (GNU_ATOMICS)) && (! defined (BSD_ATOMICS)) && \
2164 (! defined (SYNC_ATOMICS)) && (! defined (AIX_ATOMICS))
2165 # undef GNU_ATOMICS
2166 # define GNU_ATOMICS 1
2167 # endif
2168
2169 int core_read_lock (word24 addr, word36 *data, const char * ctx);
2170 int core_write_unlock (word24 addr, word36 data, const char * ctx);
2171 int core_unlock_all(void);
2172
2173 # define DEADLOCK_DETECT 0x40000000U
2174 # define MEM_LOCKED_BIT 61
2175 # define MEM_LOCKED (1LLU<<MEM_LOCKED_BIT)
2176
2177 # ifndef SCHED_NEVER_YIELD
2178 # undef SCHED_YIELD
2179 # define SCHED_YIELD \
2180 do \
2181 { \
2182 if ((i & 0xff) == 0) \
2183 { \
2184 sched_yield(); \
2185 cpu.lockYield++; \
2186 } \
2187 } \
2188 while(0)
2189 # else
2190 # undef SCHED_YIELD
2191 # define SCHED_YIELD \
2192 do \
2193 { \
2194 } \
2195 while(0)
2196 # endif
2197
2198 # if defined (BSD_ATOMICS)
2199 # include <machine/atomic.h>
2200
2201 # define LOCK_CORE_WORD(addr) \
2202 do \
2203 { \
2204 unsigned int i = DEADLOCK_DETECT; \
2205 while ( atomic_testandset_64((volatile uint64_t *)&M[addr], \
2206 MEM_LOCKED_BIT) == 1 && i > 0) \
2207 { \
2208 i--; \
2209 SCHED_YIELD; \
2210 } \
2211 if (i == 0) \
2212 { \
2213 sim_warn ("%s: locked %x addr %x deadlock\n", __func__, \
2214 cpu.locked_addr, addr); \
2215 } \
2216 cpu.lockCnt++; \
2217 if (i == DEADLOCK_DETECT) \
2218 cpu.lockImmediate++; \
2219 cpu.lockWait += (DEADLOCK_DETECT-i); \
2220 cpu.lockWaitMax = ((DEADLOCK_DETECT-i) > cpu.lockWaitMax) ? \
2221 (DEADLOCK_DETECT-i) : cpu.lockWaitMax; \
2222 } \
2223 while (0)
2224
2225 # define LOAD_ACQ_CORE_WORD(res, addr) \
2226 do \
2227 { \
2228 res = atomic_load_acq_64((volatile uint64_t *)&M[addr]); \
2229 } \
2230 while (0)
2231
2232 # define STORE_REL_CORE_WORD(addr, data) \
2233 do \
2234 { \
2235 atomic_store_rel_64((volatile uint64_t *)&M[addr], data & DMASK); \
2236 } \
2237 while (0)
2238
2239 # endif
2240
2241 # if defined(GNU_ATOMICS)
2242
2243 # define LOCK_CORE_WORD(addr) \
2244 do \
2245 { \
2246 unsigned int i = DEADLOCK_DETECT; \
2247 while ((__atomic_fetch_or((volatile uint64_t *)&M[addr], \
2248 MEM_LOCKED, __ATOMIC_ACQ_REL) & MEM_LOCKED) \
2249 && i > 0) \
2250 { \
2251 i--; \
2252 SCHED_YIELD; \
2253 } \
2254 if (i == 0) \
2255 { \
2256 sim_warn ("%s: locked %x addr %x deadlock\n", \
2257 __func__, cpu.locked_addr, addr); \
2258 } \
2259 cpu.lockCnt++; \
2260 if (i == DEADLOCK_DETECT) \
2261 cpu.lockImmediate++; \
2262 cpu.lockWait += (DEADLOCK_DETECT-i); \
2263 cpu.lockWaitMax = ((DEADLOCK_DETECT-i) > \
2264 cpu.lockWaitMax) ? (DEADLOCK_DETECT-i) : \
2265 cpu.lockWaitMax; \
2266 } \
2267 while (0)
2268
2269 # define LOAD_ACQ_CORE_WORD(res, addr) \
2270 do \
2271 { \
2272 res = __atomic_load_n((volatile uint64_t *)&M[addr], \
2273 __ATOMIC_ACQUIRE); \
2274 } \
2275 while (0)
2276
2277 # define STORE_REL_CORE_WORD(addr, data) \
2278 do \
2279 { \
2280 __atomic_store_n((volatile uint64_t *)&M[addr], data & \
2281 DMASK, __ATOMIC_RELEASE); \
2282 } \
2283 while (0)
2284
2285 # endif
2286
2287 # if defined(SYNC_ATOMICS)
2288 # ifdef MEMORY_ACCESS_NOT_STRONGLY_ORDERED
2289 # define MEM_BARRIER() do { __sync_synchronize(); } while (0)
2290 # else
2291 # define MEM_BARRIER() do {} while (0)
2292 # endif
2293
2294 # define LOCK_CORE_WORD(addr) \
2295 do \
2296 { \
2297 unsigned int i = DEADLOCK_DETECT; \
2298 while ((__sync_fetch_and_or((volatile uint64_t *)&M[addr], \
2299 MEM_LOCKED) & MEM_LOCKED) && i > 0) \
2300 { \
2301 i--; \
2302 SCHED_YIELD; \
2303 } \
2304 if (i == 0) \
2305 { \
2306 sim_warn ("%s: locked %x addr %x deadlock\n", __func__, \
2307 cpu.locked_addr, addr); \
2308 } \
2309 cpu.lockCnt++; \
2310 if (i == DEADLOCK_DETECT) \
2311 cpu.lockImmediate++; \
2312 cpu.lockWait += (DEADLOCK_DETECT-i); \
2313 cpu.lockWaitMax = ((DEADLOCK_DETECT-i) > cpu.lockWaitMax) ? \
2314 (DEADLOCK_DETECT-i) : cpu.lockWaitMax; \
2315 } \
2316 while (0)
2317
2318 # define LOAD_ACQ_CORE_WORD(res, addr) \
2319 do \
2320 { \
2321 res = M[addr]; \
2322 MEM_BARRIER(); \
2323 } \
2324 while (0)
2325
2326 # define STORE_REL_CORE_WORD(addr, data) \
2327 do \
2328 { \
2329 MEM_BARRIER(); \
2330 M[addr] = data & DMASK; \
2331 } \
2332 while (0)
2333
2334 # endif
2335 #endif
2336
2337 static inline void core_readN (word24 addr, word36 * data, uint n,
2338 UNUSED const char * ctx)
2339 {
2340 for (uint i = 0; i < n; i ++)
2341 {
2342 core_read (addr + i, data + i, ctx);
2343
2344 }
2345 }
2346
2347 static inline void core_writeN (word24 addr, word36 * data, uint n,
2348 UNUSED const char * ctx)
2349 {
2350 for (uint i = 0; i < n; i ++)
2351 {
2352 core_write (addr + i, data [i], ctx);
2353
2354 }
2355 }
2356
2357 int is_priv_mode (void);
2358
2359
2360
2361 bool get_bar_mode (void);
2362 addr_modes_e get_addr_mode (void);
2363 void set_addr_mode (addr_modes_e mode);
2364 void decode_instruction (word36 inst, DCDstruct * p);
2365 #ifndef SPEED
2366 t_stat set_mem_watch (int32 arg, const char * buf);
2367 #endif
2368 char *str_SDW0 (char * buf, sdw_s *SDW);
2369 int lookup_cpu_mem_map (word24 addr);
2370 void cpu_init (void);
2371 void setup_scbank_map (void);
2372 void add_dps8m_CU_history (void);
2373 void add_dps8m_DUOU_history (word36 flags, word18 ICT, word9 RS_REG, word9 flags2);
2374 void add_dps8m_APU_history (word15 ESN, word21 flags, word24 RMA, word3 RTRR, word9 flags2);
2375 void add_dps8m_EAPU_history (word18 ZCA, word18 opcode);
2376 void add_l68_CU_history (void);
2377 void add_l68_OU_history (void);
2378 void add_l68_DU_history (void);
2379 void add_l68_APU_history (enum APUH_e op);
2380 void add_history_force (uint hset, word36 w0, word36 w1);
2381 void printPtid(pthread_t pt);
2382 word18 get_BAR_address(word18 addr);
2383 #if defined(THREADZ) || defined(LOCKLESS)
2384 t_stat threadz_sim_instr (void);
2385 void * cpu_thread_main (void * arg);
2386 #endif
2387 void cpu_reset_unit_idx (UNUSED uint cpun, bool clear_mem);
2388 void setupPROM (uint cpuNo, unsigned char * PROM);