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