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