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