This source file includes following definitions.
- scu_show_nunits
- scu_set_nunits
- scu_show_state
- scu_show_config
- scu_set_config
- dump_intr_regs
- scu_unit_reset
- scu_reset
- set_SCU_clock
- pcells
- deliver_interrupts
- scu_smic
- scu_sscr
- scu_rscr
- scu_cioc
- scu_set_interrupt
- scu_get_highest_intr
- scu_reset_unit
- scu_init
- scu_rmcm
- scu_smcm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543 #include <sys/time.h>
544 #include "dps8.h"
545 #include "dps8_sys.h"
546 #include "dps8_iom.h"
547 #include "dps8_cable.h"
548 #include "dps8_cpu.h"
549 #include "dps8_faults.h"
550 #include "dps8_scu.h"
551 #include "dps8_utils.h"
552 #if defined(THREADZ) || defined(LOCKLESS)
553 # include "threadz.h"
554 #endif
555
556 #define DBG_CTR 1
557
558 scu_t scu [N_SCU_UNITS_MAX];
559
560 #define N_SCU_UNITS 1
561
562 static UNIT scu_unit [N_SCU_UNITS_MAX] = {
563 #if defined(NO_C_ELLIPSIS)
564 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
565 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
566 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
567 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
568 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
569 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
570 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
571 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL }
572 #else
573 [0 ... N_SCU_UNITS_MAX-1] = {
574 UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL
575 }
576 #endif
577 };
578
579 #define UNIT_NUM(uptr) ((uptr) - scu_unit)
580
581
582
583
584
585 static struct config_switches
586 {
587 uint mode;
588 uint port_enable [N_SCU_PORTS];
589 uint mask_enable [N_ASSIGNMENTS];
590 uint mask_assignment [N_ASSIGNMENTS];
591 uint lower_store_size;
592 uint cyclic;
593 uint nea;
594 uint onl;
595 uint interlace;
596 uint lwr;
597 } config_switches [N_SCU_UNITS_MAX];
598
599 enum { MODE_MANUAL = 0, MODE_PROGRAM = 1 };
600
601 unsigned int gtod_warned = 0;
602
603
604
605 static t_stat scu_show_nunits (UNUSED FILE * st, UNUSED UNIT * uptr,
606 UNUSED int val, const UNUSED void * desc)
607 {
608 sim_printf("Number of SCU units in system is %d\n", scu_dev.numunits);
609 return SCPE_OK;
610 }
611
612 static t_stat scu_set_nunits (UNUSED UNIT * uptr, UNUSED int32 value,
613 const char * cptr, UNUSED void * desc)
614 {
615 if (! cptr)
616 return SCPE_ARG;
617 int n = atoi (cptr);
618 if (n < 1 || n > N_SCU_UNITS_MAX)
619 return SCPE_ARG;
620 scu_dev.numunits = (uint) n;
621 return SCPE_OK;
622 }
623
624 static t_stat scu_show_state (UNUSED FILE * st, UNIT *uptr, UNUSED int val,
625 UNUSED const void * desc)
626 {
627 #if defined(TESTING)
628 cpu_state_t * cpup = _cpup;
629 #endif
630 long scu_unit_idx = UNIT_NUM (uptr);
631 if (scu_unit_idx < 0 || scu_unit_idx >= (int) scu_dev.numunits)
632 {
633 sim_debug (DBG_ERR, & scu_dev,
634 "scu_show_state: Invalid unit number %ld\n",
635 (long) scu_unit_idx);
636 sim_printf ("error: Invalid unit number %ld\n", (long) scu_unit_idx);
637 return SCPE_ARG;
638 }
639
640 sim_printf ("SCU unit number %ld\n", (long) scu_unit_idx);
641 scu_t * scup = scu + scu_unit_idx;
642 sim_printf (" Mode %s\n",
643 config_switches[scu_unit_idx].mode ? "PROGRAM" : "MANUAL");
644
645 for (int i = 0; i < N_SCU_PORTS; i ++)
646 {
647 struct ports * pp = scup -> ports + i;
648
649 sim_printf (" Port %d %s dev_idx %d dev_port %d type %s\n",
650 i, scup->port_enable[i] ? "ENABLE " : "DISABLE",
651 pp->dev_idx, pp->dev_port[XXX_TEMP_SCU_SUBPORT],
652 pp->type == ADEV_NONE ? "NONE" :
653 pp->type == ADEV_CPU ? "CPU" :
654 pp->type == ADEV_IOM ? "IOM" :
655 "<enum broken>");
656 }
657 for (int i = 0; i < N_ASSIGNMENTS; i ++)
658 {
659
660
661 sim_printf (" Cell %c\n", 'A' + i);
662 sim_printf (" exec_intr_mask %012o\n",
663 scup -> exec_intr_mask [i]);
664 sim_printf (" mask_enable %s\n",
665 scup -> mask_enable [i] ? "ENABLE" : "DISABLE");
666 sim_printf (" mask_assignment %d\n",
667 scup -> mask_assignment [i]);
668 sim_printf (" cells ");
669 for (int j = 0; j < N_CELL_INTERRUPTS; j ++)
670 sim_printf("%d", scup -> cells [j]);
671 sim_printf ("\n");
672 }
673 sim_printf("Lower store size: %d\n", scup -> lower_store_size);
674 sim_printf("Cyclic: %03o\n", scup -> cyclic);
675 sim_printf("NEA: %03o\n", scup -> nea);
676 sim_printf("Online: %02o\n", scup -> onl);
677 sim_printf("Interlace: %o\n", scup -> interlace);
678 sim_printf("Lower: %o\n", scup -> lwr);
679 sim_printf("ID: %o\n", scup -> id);
680 sim_printf("mode_reg: %06o\n", scup -> mode_reg);
681 sim_printf("Elapsed days: %d\n", scup -> elapsed_days);
682 sim_printf("Steady clock: %d\n", scup -> steady_clock);
683 sim_printf("Bullet time: %d\n", scup -> bullet_time);
684 sim_printf("Y2K enabled: %d\n", scup -> y2k);
685 return SCPE_OK;
686 }
687
688 static t_stat scu_show_config (UNUSED FILE * st, UNUSED UNIT * uptr,
689 UNUSED int val, UNUSED const void * desc)
690 {
691 #if defined(TESTING)
692 cpu_state_t * cpup = _cpup;
693 #endif
694 static const char * map [N_SCU_PORTS] =
695 {
696 "0", "1", "2", "3", "4", "5", "6", "7"
697 };
698 long scu_unit_idx = UNIT_NUM (uptr);
699 if (scu_unit_idx < 0 || scu_unit_idx >= (int) scu_dev.numunits)
700 {
701 sim_debug (DBG_ERR, & scu_dev,
702 "scu_show_config: Invalid unit number %ld\n",
703 (long) scu_unit_idx);
704 sim_printf ("error: Invalid unit number %ld\n", (long) scu_unit_idx);
705 return SCPE_ARG;
706 }
707
708 sim_printf ("SCU unit number %ld\n", (long) scu_unit_idx);
709
710 struct config_switches * sw = config_switches + scu_unit_idx;
711
712 const char * mode = "<out of range>";
713 switch (sw -> mode)
714 {
715 case MODE_PROGRAM:
716 mode = "Program";
717 break;
718 case MODE_MANUAL:
719 mode = "Manual";
720 break;
721 }
722
723 sim_printf ("Mode: %s\n", mode);
724 sim_printf ("Port Enable: ");
725 for (int i = 0; i < N_SCU_PORTS; i ++)
726 sim_printf (" %3o", sw -> port_enable [i]);
727 sim_printf ("\n");
728 for (int i = 0; i < N_ASSIGNMENTS; i ++)
729 {
730 sim_printf ("Mask %c: %s\n",
731 'A' + i,
732 sw->mask_enable[i] ? (map[sw->mask_assignment[i]]) : "Off");
733 }
734 sim_printf ("Lower Store Size: %o\n", sw -> lower_store_size);
735 sim_printf ("Cyclic: %03o\n", sw -> cyclic);
736 sim_printf ("Non-existent address: %03o\n", sw -> nea);
737
738 return SCPE_OK;
739 }
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764 static config_value_list_t cfg_mode_list [] =
765 {
766 { "manual", 0 },
767 { "program", 1 },
768 { NULL, 0 }
769 };
770
771 static config_value_list_t cfg_mask_list [] =
772 {
773 { "off", -1 },
774 { NULL, 0 }
775 };
776
777 static config_value_list_t cfg_able_list [] =
778 {
779 { "disable", 0 },
780 { "enable", 1 },
781 { NULL, 0 }
782 };
783
784 static config_value_list_t cfg_size_list [] =
785 {
786 { "32", 0 },
787 { "64", 1 },
788 { "128", 2 },
789 { "256", 3 },
790 { "512", 4 },
791 { "1024", 5 },
792 { "2048", 6 },
793 { "4096", 7 },
794 { "32K", 0 },
795 { "64K", 1 },
796 { "128K", 2 },
797 { "256K", 3 },
798 { "512K", 4 },
799 { "1024K", 5 },
800 { "2048K", 6 },
801 { "4096K", 7 },
802 { "1M", 5 },
803 { "2M", 6 },
804 { "4M", 7 },
805 { NULL, 0 }
806 };
807
808 static config_value_list_t cfg_on_off [] =
809 {
810 { "off", 0 },
811 { "on", 1 },
812 { "disable", 0 },
813 { "enable", 1 },
814 { NULL, 0 }
815 };
816
817 static config_list_t scu_config_list [] =
818 {
819 { "mode", 1, 0, cfg_mode_list },
820 { "maska", 0, N_SCU_PORTS - 1, cfg_mask_list },
821 { "maskb", 0, N_SCU_PORTS - 1, cfg_mask_list },
822 { "port0", 1, 0, cfg_able_list },
823 { "port1", 1, 0, cfg_able_list },
824 { "port2", 1, 0, cfg_able_list },
825 { "port3", 1, 0, cfg_able_list },
826 { "port4", 1, 0, cfg_able_list },
827 { "port5", 1, 0, cfg_able_list },
828 { "port6", 1, 0, cfg_able_list },
829 { "port7", 1, 0, cfg_able_list },
830 { "lwrstoresize", 0, 7, cfg_size_list },
831 { "cyclic", 0, 0177, NULL },
832 { "nea", 0, 0377, NULL },
833
834 { "onl", 0, 017, NULL },
835 { "int", 0, 1, NULL },
836 { "lwr", 0, 1, NULL },
837
838
839
840 { "elapsed_days", 0, 20000, NULL },
841 { "steady_clock", 0, 1, cfg_on_off },
842 { "bullet_time", 0, 1, cfg_on_off },
843 { "y2k", 0, 1, cfg_on_off },
844 { NULL, 0, 0, NULL }
845 };
846
847 static t_stat scu_set_config (UNIT * uptr, UNUSED int32 value,
848 const char * cptr, UNUSED void * desc)
849 {
850 #if defined(TESTING)
851 cpu_state_t * cpup = _cpup;
852 #endif
853 long scu_unit_idx = UNIT_NUM (uptr);
854 if (scu_unit_idx < 0 || scu_unit_idx >= (int) scu_dev.numunits)
855 {
856 sim_debug (DBG_ERR, & scu_dev,
857 "scu_set_config: Invalid unit number %ld\n", (long) scu_unit_idx);
858 sim_printf ("error: scu_set_config: Invalid unit number %ld\n",
859 (long) scu_unit_idx);
860 return SCPE_ARG;
861 }
862
863 struct config_switches * sw = config_switches + scu_unit_idx;
864
865 config_state_t cfg_state = { NULL, NULL };
866
867 for (;;)
868 {
869 int64_t v;
870 int rc = cfg_parse ("scu_set_config", cptr, scu_config_list,
871 & cfg_state, & v);
872 if (rc == -1)
873 break;
874
875 if (rc == -2)
876 {
877 cfg_parse_done (& cfg_state);
878 return SCPE_ARG;
879 }
880
881 const char * p = scu_config_list [rc].name;
882 if (strcmp (p, "mode") == 0)
883 sw -> mode = (uint) v;
884 else if (strcmp (p, "maska") == 0)
885 {
886 if (v == -1)
887 sw -> mask_enable [0] = false;
888 else
889 {
890 sw -> mask_enable [0] = true;
891 sw -> mask_assignment [0] = (uint) v;
892 }
893 }
894 else if (strcmp (p, "maskb") == 0)
895 {
896 if (v == -1)
897 sw -> mask_enable [1] = false;
898 else
899 {
900 sw -> mask_enable [1] = true;
901 sw -> mask_assignment [1] = (uint) v;
902 }
903 }
904 else if (strcmp (p, "port0") == 0)
905 sw -> port_enable [0] = (uint) v;
906 else if (strcmp (p, "port1") == 0)
907 sw -> port_enable [1] = (uint) v;
908 else if (strcmp (p, "port2") == 0)
909 sw -> port_enable [2] = (uint) v;
910 else if (strcmp (p, "port3") == 0)
911 sw -> port_enable [3] = (uint) v;
912 else if (strcmp (p, "port4") == 0)
913 sw -> port_enable [4] = (uint) v;
914 else if (strcmp (p, "port5") == 0)
915 sw -> port_enable [5] = (uint) v;
916 else if (strcmp (p, "port6") == 0)
917 sw -> port_enable [6] = (uint) v;
918 else if (strcmp (p, "port7") == 0)
919 sw -> port_enable [7] = (uint) v;
920 else if (strcmp (p, "lwrstoresize") == 0)
921 sw -> lower_store_size = (uint) v;
922 else if (strcmp (p, "cyclic") == 0)
923 sw -> cyclic = (uint) v;
924 else if (strcmp (p, "nea") == 0)
925 sw -> nea = (uint) v;
926 else if (strcmp (p, "onl") == 0)
927 sw -> onl = (uint) v;
928 else if (strcmp (p, "int") == 0)
929 sw -> interlace = (uint) v;
930 else if (strcmp (p, "lwr") == 0)
931 sw -> lwr = (uint) v;
932 else if (strcmp (p, "elapsed_days") == 0)
933 scu [scu_unit_idx].elapsed_days = (uint) v;
934 else if (strcmp (p, "steady_clock") == 0)
935 scu [scu_unit_idx].steady_clock = (uint) v;
936 else if (strcmp (p, "bullet_time") == 0)
937 scu [scu_unit_idx].bullet_time = (uint) v;
938 else if (strcmp (p, "y2k") == 0)
939 scu [scu_unit_idx].y2k = (uint) v;
940 else
941 {
942 sim_printf ("error: scu_set_config: invalid cfg_parse rc <%d>\n",
943 rc);
944 cfg_parse_done (& cfg_state);
945 return SCPE_ARG;
946 }
947 }
948 cfg_parse_done (& cfg_state);
949 return SCPE_OK;
950 }
951
952 static MTAB scu_mod [] =
953 {
954 {
955 MTAB_XTD | MTAB_VUN | \
956 MTAB_NMO | MTAB_VALR,
957 0,
958 (char *) "CONFIG",
959 (char *) "CONFIG",
960 scu_set_config,
961 scu_show_config,
962 NULL,
963 NULL
964 },
965 {
966 MTAB_XTD | MTAB_VDV | \
967 MTAB_NMO | MTAB_VALR,
968 0,
969 (char *) "NUNITS",
970 (char *) "NUNITS",
971 scu_set_nunits,
972 scu_show_nunits,
973 (char *) "Number of SCU units in the system",
974 NULL
975 },
976 {
977 MTAB_XTD | MTAB_VUN | \
978 MTAB_NMO | MTAB_VALR,
979 0,
980 (char *) "STATE",
981 (char *) "STATE",
982 NULL,
983 scu_show_state,
984 (char *) "SCU unit internal state",
985 NULL
986 },
987 {
988 MTAB_XTD | MTAB_VUN | \
989 MTAB_NMO | MTAB_VALR,
990 0,
991 (char *) "RESET",
992 (char *) "RESET",
993 scu_reset_unit,
994 NULL,
995 (char *) "reset SCU unit",
996 NULL
997 },
998 {
999 0, 0, NULL, NULL, NULL, NULL, NULL, NULL
1000 }
1001 };
1002
1003
1004
1005 static DEBTAB scu_dt [] =
1006 {
1007 { (char *) "TRACE", DBG_TRACE, NULL },
1008 { (char *) "NOTIFY", DBG_NOTIFY, NULL },
1009 { (char *) "INFO", DBG_INFO, NULL },
1010 { (char *) "ERR", DBG_ERR, NULL },
1011 { (char *) "WARN", DBG_WARN, NULL },
1012 { (char *) "DEBUG", DBG_DEBUG, NULL },
1013 { (char *) "INTR", DBG_INTR, NULL },
1014 { (char *) "ALL", DBG_ALL, NULL },
1015 { NULL, 0, NULL }
1016 };
1017
1018 DEVICE scu_dev =
1019 {
1020 (char *) "SCU",
1021 scu_unit,
1022 NULL,
1023 scu_mod,
1024 N_SCU_UNITS,
1025 10,
1026 8,
1027 1,
1028 8,
1029 8,
1030 NULL,
1031 NULL,
1032 & scu_reset,
1033 NULL,
1034 NULL,
1035 NULL,
1036 NULL,
1037 DEV_DEBUG,
1038 0,
1039 scu_dt,
1040 NULL,
1041 NULL,
1042 NULL,
1043 NULL,
1044 NULL,
1045 NULL,
1046 NULL
1047 };
1048
1049 static void dump_intr_regs (char * ctx, uint scu_unit_idx)
1050 {
1051 #if defined(TESTING)
1052 scu_t * up = scu + scu_unit_idx;
1053 cpu_state_t * cpup = _cpup;
1054
1055 sim_debug (DBG_DEBUG, & scu_dev,
1056 "%s A: mask %011o enable %o assignment %o\n",
1057 ctx, up -> exec_intr_mask [0], up -> mask_enable [0],
1058 up -> mask_assignment [0]);
1059 sim_debug (DBG_DEBUG, & scu_dev,
1060 "%s B: mask %011o enable %o assignment %o\n",
1061 ctx, up -> exec_intr_mask [1], up -> mask_enable [1],
1062 up -> mask_assignment [1]);
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110 #endif
1111 }
1112
1113 void scu_unit_reset (int scu_unit_idx)
1114 {
1115 scu_t * up = scu + scu_unit_idx;
1116 struct config_switches * sw = config_switches + scu_unit_idx;
1117
1118 for (int i = 0; i < N_SCU_PORTS; i ++)
1119 {
1120 up -> port_enable [i] = sw -> port_enable [i];
1121 }
1122
1123 for (int i = 0; i < N_ASSIGNMENTS; i ++)
1124 {
1125 up -> mask_enable [i] = sw -> mask_enable [i];
1126 up -> mask_assignment [i] = sw -> mask_assignment [i];
1127 }
1128 up -> lower_store_size = sw -> lower_store_size;
1129 up -> cyclic = sw -> cyclic;
1130 up -> nea = sw -> nea;
1131 up -> onl = sw -> onl;
1132 up -> interlace = sw -> interlace;
1133 up -> lwr = sw -> lwr;
1134
1135
1136
1137
1138 for (uint port_num = 0; port_num < N_SCU_PORTS; port_num ++)
1139 {
1140 struct ports * portp = & scu [scu_unit_idx].ports [port_num];
1141 if (portp->type != ADEV_IOM)
1142 continue;
1143
1144
1145 iom_unit_reset_idx ((uint) portp->dev_idx);
1146 }
1147
1148
1149
1150
1151
1152 for (int i = 0; i < N_ASSIGNMENTS; i ++)
1153 {
1154
1155 up -> exec_intr_mask [i] = 037777777777;
1156 }
1157 }
1158
1159 t_stat scu_reset (UNUSED DEVICE * dptr)
1160 {
1161
1162
1163 for (int scu_unit_idx = 0; scu_unit_idx < N_SCU_UNITS_MAX; scu_unit_idx ++)
1164 scu_unit_reset (scu_unit_idx);
1165 return SCPE_OK;
1166 }
1167
1168
1169
1170 #if defined(THREADZ) || defined(LOCKLESS)
1171 static pthread_mutex_t clock_lock = PTHREAD_MUTEX_INITIALIZER;
1172 #endif
1173
1174
1175 static uint64 set_SCU_clock (cpu_state_t * cpup, uint scu_unit_idx)
1176 {
1177 #if defined(THREADZ) || defined(LOCKLESS)
1178 pthread_mutex_lock (& clock_lock);
1179 #endif
1180
1181
1182
1183
1184
1185
1186 if (scu [0].steady_clock)
1187 {
1188
1189
1190 #if defined(NEED_128)
1191 uint128 big = construct_128 (0, cpu.instrCnt);
1192
1193
1194 big = lshift_128 (big, 2);
1195 if (scu [0].bullet_time)
1196 big = multiply_128 (big, construct_128 (0, 10000u));
1197
1198
1199 uint128 days = construct_128 (0, scu[0].elapsed_days);
1200 days = multiply_128 (days, construct_128 (0, 1000000));
1201 days = multiply_128 (days, construct_128 (0, 60 * 60 * 24));
1202 big = add_128 (big, days);
1203 #else
1204 __uint128_t big = cpu.instrCnt;
1205
1206 big *= 4u;
1207
1208 if (scu [0].bullet_time)
1209 big *= 10000;
1210
1211 big += scu [0].elapsed_days * 1000000llu * 60llu * 60llu * 24llu;
1212 #endif
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226 uint64 UNIX_secs = (uint64)time(NULL);
1227
1228 #if defined(NEED_128)
1229 uint64 UNIX_usecs = UNIX_secs * 1000000llu + big.l;
1230 #else
1231 uint64 UNIX_usecs = UNIX_secs * 1000000llu + (uint64) big;
1232 #endif
1233
1234 uint64 Multics_usecs = 2177452800000000llu + UNIX_usecs;
1235
1236
1237
1238 Multics_usecs += (uint64) scu [scu_unit_idx].user_correction;
1239
1240
1241
1242
1243 if (scu [scu_unit_idx].last_time >= Multics_usecs)
1244 {
1245 sim_debug (DBG_TRACE, & scu_dev, "finagle clock\n");
1246 Multics_usecs = scu [scu_unit_idx].last_time + 1;
1247 }
1248 scu [scu_unit_idx].last_time = Multics_usecs;
1249 goto done;
1250 }
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263 struct timeval now;
1264 gettimeofday(& now, NULL);
1265
1266 if (scu [0].y2k)
1267 {
1268
1269
1270
1271
1272 now.tv_sec -= (1685451324 - 738766524);
1273 }
1274 uint64 UNIX_secs = (uint64) now.tv_sec;
1275 uint64 UNIX_usecs = UNIX_secs * 1000000LL + (uint64) now.tv_usec;
1276
1277 static uint64 last_UNIX_usecs = 0;
1278 if ( (!sim_quiet) && (UNIX_usecs < last_UNIX_usecs))
1279 {
1280 if (gtod_warned < 11)
1281 {
1282 sim_warn ("\rHost clock went backwards %llu uS!\r\n",
1283 (unsigned long long)(last_UNIX_usecs - UNIX_usecs));
1284 gtod_warned++;
1285 }
1286 else if (gtod_warned == 11)
1287 {
1288 sim_warn ("\rHost clock went backwards %llu uS! Suppressing further warnings.\r\n",
1289 (unsigned long long)(last_UNIX_usecs - UNIX_usecs));
1290 gtod_warned++;
1291 }
1292 }
1293 last_UNIX_usecs = UNIX_usecs;
1294
1295
1296 uint64 Multics_usecs = 2177452800000000LL + UNIX_usecs;
1297
1298
1299
1300
1301
1302 Multics_usecs += (uint64) scu [scu_unit_idx].user_correction;
1303
1304 if (scu [scu_unit_idx].last_time >= Multics_usecs)
1305 Multics_usecs = scu [scu_unit_idx].last_time + 1;
1306 scu [scu_unit_idx].last_time = Multics_usecs;
1307
1308 done:
1309 #if defined(THREADZ) || defined(LOCKLESS)
1310 pthread_mutex_unlock (& clock_lock);
1311 #endif
1312
1313 return scu [scu_unit_idx].last_time;
1314 }
1315
1316
1317 static char * pcells (uint scu_unit_idx, char * buf)
1318 {
1319 for (uint i = 0; i < N_CELL_INTERRUPTS; i ++)
1320 {
1321 if (scu [scu_unit_idx].cells [i])
1322 buf [i] = '1';
1323 else
1324 buf [i] = '0';
1325 }
1326 buf [N_CELL_INTERRUPTS] = '\0';
1327 return buf;
1328 }
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344 static void deliver_interrupts (uint scu_unit_idx)
1345 {
1346 #if defined(TESTING)
1347 cpu_state_t * cpup = _cpup;
1348 sim_debug (DBG_DEBUG, & scu_dev, "deliver_interrupts %o\n", scu_unit_idx);
1349 #endif
1350 for (uint cpun = 0; cpun < cpu_dev.numunits; cpun ++)
1351 {
1352 cpus[cpun].events.XIP[scu_unit_idx] = false;
1353 }
1354
1355
1356
1357
1358
1359 #if defined(REORDER)
1360 for (uint jnum = 0; jnum < N_CELL_INTERRUPTS; jnum ++)
1361 {
1362 static const uint reorder[N_CELL_INTERRUPTS] = {
1363 0, 1, 2, 3, 4, 5, 6, 7,
1364 16, 17, 18, 29, 20, 21, 22, 23,
1365 8, 9, 10, 11, 12, 13, 14, 15,
1366 25, 25, 26, 27, 28, 29, 30, 31 };
1367 uint inum = reorder[jnum];
1368 if (! scu [scu_unit_idx].cells [inum])
1369 continue;
1370 sim_debug (DBG_DEBUG, & scu_dev, "trying to deliver %d\n", inum);
1371 sim_debug (DBG_INTR, & scu_dev,
1372 "scu %u trying to deliver %d\n", scu_unit_idx, inum);
1373
1374 for (uint pima = 0; pima < N_ASSIGNMENTS; pima ++)
1375 {
1376
1377
1378
1379 if (scu [scu_unit_idx].mask_enable [pima] == 0)
1380 continue;
1381 uint mask = scu [scu_unit_idx].exec_intr_mask [pima];
1382 uint port = scu [scu_unit_idx].mask_assignment [pima];
1383
1384
1385
1386
1387 if (scu [scu_unit_idx].ports [port].type != ADEV_CPU)
1388 continue;
1389 if ((mask & (1u << (31 - inum))) != 0)
1390 {
1391 uint sn = 0;
1392 if (scu[scu_unit_idx].ports[port].is_exp)
1393 {
1394 sn = (uint) scu[scu_unit_idx].ports[port].xipmaskval;
1395 if (sn >= N_SCU_SUBPORTS)
1396 {
1397 sim_warn ("XIP mask not set; defaulting to subport 0\n");
1398 sn = 0;
1399 }
1400 }
1401 if (! cables->scu_to_cpu[scu_unit_idx][port][sn].in_use)
1402 {
1403 sim_warn ("bad scu_unit_idx %u\n", scu_unit_idx);
1404 continue;
1405 }
1406 uint cpu_unit_udx = cables->scu_to_cpu[scu_unit_idx][port][sn].cpu_unit_idx;
1407 # if defined(THREADZ) || defined(LOCKLESS)
1408 cpus[cpu_unit_udx].events.XIP[scu_unit_idx] = true;
1409 # if defined(TESTING)
1410 HDBGIntrSet (inum, cpu_unit_udx, scu_unit_idx, __func__);
1411 # endif
1412 createCPUThread((uint) cpu_unit_udx);
1413 # if !defined(NO_TIMEWAIT)
1414 wakeCPU ((uint) cpu_unit_udx);
1415 # endif
1416 sim_debug (DBG_DEBUG, & scu_dev,
1417 "interrupt set for CPU %d SCU %d\n",
1418 cpu_unit_udx, scu_unit_idx);
1419 # else
1420
1421 # if defined(ROUND_ROBIN)
1422 cpus[cpu_unit_udx].isRunning = true;
1423 # endif
1424 cpus[cpu_unit_udx].events.XIP[scu_unit_idx] = true;
1425 sim_debug (DBG_DEBUG, & scu_dev, "interrupt set for CPU %d SCU %d\n", cpu_unit_udx, scu_unit_idx);
1426 sim_debug (DBG_INTR, & scu_dev,
1427 "XIP set for SCU %d\n", scu_unit_idx);
1428 # endif
1429 }
1430 }
1431 }
1432 #else
1433 for (uint inum = 0; inum < N_CELL_INTERRUPTS; inum ++)
1434 {
1435 if (! scu [scu_unit_idx].cells [inum])
1436 continue;
1437 sim_debug (DBG_DEBUG, & scu_dev, "trying to deliver %d\n", inum);
1438 sim_debug (DBG_INTR, & scu_dev,
1439 "scu %u trying to deliver %d\n", scu_unit_idx, inum);
1440
1441 for (uint pima = 0; pima < N_ASSIGNMENTS; pima ++)
1442 {
1443
1444
1445
1446 if (scu [scu_unit_idx].mask_enable [pima] == 0)
1447 continue;
1448 uint mask = scu [scu_unit_idx].exec_intr_mask [pima];
1449 uint port = scu [scu_unit_idx].mask_assignment [pima];
1450
1451
1452
1453
1454 if (scu [scu_unit_idx].ports [port].type != ADEV_CPU)
1455 continue;
1456 if ((mask & (1u << (31 - inum))) != 0)
1457 {
1458 uint sn = 0;
1459 if (scu[scu_unit_idx].ports[port].is_exp)
1460 {
1461 sn = (uint) scu[scu_unit_idx].ports[port].xipmaskval;
1462 if (sn >= N_SCU_SUBPORTS)
1463 {
1464 sim_warn ("XIP mask not set; defaulting to subport 0\n");
1465 sn = 0;
1466 }
1467 }
1468 if (! cables->scu_to_cpu[scu_unit_idx][port][sn].in_use)
1469 {
1470 sim_warn ("bad scu_unit_idx %u\n", scu_unit_idx);
1471 continue;
1472 }
1473 uint cpu_unit_udx = cables->scu_to_cpu[scu_unit_idx][port][sn].cpu_unit_idx;
1474 # if defined(THREADZ) || defined(LOCKLESS)
1475 cpus[cpu_unit_udx].events.XIP[scu_unit_idx] = true;
1476 # if defined(TESTING)
1477 HDBGIntrSet (inum, cpu_unit_udx, scu_unit_idx, __func__);
1478 # endif
1479 # ifdef SYNCTEST
1480 if (cpus[cpu_unit_udx].rcfDelete) sim_printf ("Poking CPU %c in rcfDelete\n", 'A' + cpu_unit_udx);
1481 # endif
1482 createCPUThread((uint) cpu_unit_udx);
1483 # if !defined(NO_TIMEWAIT)
1484 wakeCPU ((uint) cpu_unit_udx);
1485 # endif
1486 sim_debug (DBG_DEBUG, & scu_dev,
1487 "interrupt set for CPU %d SCU %d\n",
1488 cpu_unit_udx, scu_unit_idx);
1489 # else
1490
1491 # if defined(ROUND_ROBIN)
1492 cpus[cpu_unit_udx].isRunning = true;
1493 # endif
1494 cpus[cpu_unit_udx].events.XIP[scu_unit_idx] = true;
1495 sim_debug (DBG_DEBUG, & scu_dev, "interrupt set for CPU %d SCU %d\n", cpu_unit_udx, scu_unit_idx);
1496 sim_debug (DBG_INTR, & scu_dev,
1497 "XIP set for SCU %d\n", scu_unit_idx);
1498 # endif
1499 }
1500 }
1501 }
1502 #endif
1503 }
1504
1505 t_stat scu_smic (uint scu_unit_idx, uint UNUSED cpu_unit_udx,
1506 uint UNUSED cpu_port_num, word36 rega)
1507 {
1508 #if defined(TESTING)
1509 cpu_state_t * cpup = _cpup;
1510 #endif
1511 #if defined(THREADZ) || defined(LOCKLESS)
1512 lock_scu ();
1513 #endif
1514
1515
1516 if (getbits36_1 (rega, 35))
1517 {
1518 for (uint i = 0; i < 16; i ++)
1519 {
1520 if (getbits36_1 (rega, i))
1521 scu [scu_unit_idx].cells [i + 16] = 1;
1522 }
1523 char pcellb [N_CELL_INTERRUPTS + 1];
1524 sim_debug (DBG_TRACE, & scu_dev,
1525 "SMIC low: Unit %u Cells: %s\n",
1526 scu_unit_idx, pcells (scu_unit_idx, pcellb));
1527 }
1528 else
1529 {
1530 for (uint i = 0; i < 16; i ++)
1531 {
1532 if (getbits36_1 (rega, i))
1533 scu [scu_unit_idx].cells [i] = 1;
1534 }
1535 char pcellb [N_CELL_INTERRUPTS + 1];
1536 sim_debug (DBG_TRACE, & scu_dev,
1537 "SMIC high: Unit %d Cells: %s\n",
1538 scu_unit_idx, pcells (scu_unit_idx, pcellb));
1539 }
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565 dump_intr_regs ("smic", scu_unit_idx);
1566 deliver_interrupts (scu_unit_idx);
1567 #if defined(THREADZ) || defined(LOCKLESS)
1568 unlock_scu ();
1569 #endif
1570 return SCPE_OK;
1571 }
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602 t_stat scu_sscr (cpu_state_t * cpup, uint scu_unit_idx, UNUSED uint cpu_unit_udx,
1603 UNUSED uint cpu_port_num, word18 addr,
1604 word36 rega, word36 regq)
1605 {
1606 sim_debug (DBG_DEBUG, & scu_dev, "sscr SCU unit %o\n", scu_unit_idx);
1607
1608
1609
1610 if (scu_unit_idx >= scu_dev.numunits)
1611 {
1612
1613 sim_warn ("%s: scu_unit_idx out of range %d\n",
1614 __func__, scu_unit_idx);
1615 return SCPE_OK;
1616 }
1617
1618
1619
1620
1621 uint function = (addr >> 3) & 07;
1622
1623
1624
1625 if (config_switches [scu_unit_idx].mode != MODE_PROGRAM)
1626 {
1627 sim_warn ("%s: SCU mode is 'MANUAL', not 'PROGRAM' -- sscr "
1628 "not allowed to set switches.\n",
1629 __func__);
1630
1631
1632 return SCPE_OK;
1633 }
1634
1635
1636
1637 switch (function)
1638 {
1639 case 00000:
1640 {
1641 #if defined(THREADZ) || defined(LOCKLESS)
1642 lock_scu ();
1643 #endif
1644 scu [scu_unit_idx].id = (word4) getbits36_4 (regq, 50 - 36);
1645 scu [scu_unit_idx].mode_reg = getbits36_18 (regq, 54 - 36);
1646 #if defined(THREADZ) || defined(LOCKLESS)
1647 unlock_scu ();
1648 #endif
1649 }
1650 break;
1651
1652 case 00001:
1653
1654 {
1655 sim_debug (DBG_DEBUG, & scu_dev,
1656 "sscr 1 %d A: %012"PRIo64" Q: %012"PRIo64"\n",
1657 scu_unit_idx, rega, regq);
1658 #if defined(THREADZ) || defined(LOCKLESS)
1659 lock_scu ();
1660 #endif
1661 scu_t * up = scu + scu_unit_idx;
1662 for (int maskab = 0; maskab < 2; maskab ++)
1663 {
1664 word9 mask = ((maskab ? regq : rega) >> 27) & 0777;
1665 if (mask & 01)
1666 {
1667 up -> mask_enable [maskab] = 0;
1668 sim_debug (DBG_DEBUG, & scu_dev,
1669 "sscr %u mask disable %d\n",
1670 scu_unit_idx, maskab);
1671 }
1672 else
1673 {
1674 up -> mask_enable [maskab] = 1;
1675 sim_debug (DBG_DEBUG, & scu_dev,
1676 "sscr %u mask enable %d\n",
1677 scu_unit_idx, maskab);
1678 for (int pn = 0; pn < N_SCU_PORTS; pn ++)
1679 {
1680 if ((2 << (N_SCU_PORTS - 1 - pn)) & mask)
1681 {
1682 up -> mask_assignment [maskab] = (uint) pn;
1683 break;
1684 }
1685 }
1686
1687 }
1688 sim_debug (DBG_INTR, & scu_dev,
1689 "SCU%u SSCR1 mask %c enable set to %u assigned to "
1690 "port %u\n",
1691 scu_unit_idx, 'a' + maskab, up->mask_enable[maskab],
1692 up->mask_assignment[maskab]);
1693 }
1694
1695
1696
1697
1698
1699 up -> lower_store_size = (rega >> 24) & 07;
1700 up -> cyclic = (regq >> 8) & 0177;
1701 up -> nea = (rega >> 6) & 0377;
1702 up -> onl = (rega >> 20) & 017;
1703 up -> interlace = (rega >> 5) & 1;
1704 up -> lwr = (rega >> 4) & 1;
1705 up -> port_enable [0] = (rega >> 3) & 01;
1706 up -> port_enable [1] = (rega >> 2) & 01;
1707 up -> port_enable [2] = (rega >> 1) & 01;
1708 up -> port_enable [3] = (rega >> 0) & 01;
1709 up -> port_enable [4] = (regq >> 3) & 01;
1710 up -> port_enable [5] = (regq >> 2) & 01;
1711 up -> port_enable [6] = (regq >> 1) & 01;
1712 up -> port_enable [7] = (regq >> 0) & 01;
1713
1714 #if defined(THREADZ) || defined(LOCKLESS)
1715 unlock_scu ();
1716 #endif
1717
1718
1719 break;
1720 }
1721
1722 case 00002:
1723
1724
1725
1726
1727
1728
1729
1730 {
1731 #if defined(THREADZ) || defined(LOCKLESS)
1732 lock_scu ();
1733 #endif
1734 uint port_num = (addr >> 6) & 07;
1735 sim_debug (DBG_DEBUG, & scu_dev, "Set mask register port %d to "
1736 "%012"PRIo64",%012"PRIo64"\n",
1737 port_num, rega, regq);
1738
1739
1740 int mask_num = -1;
1741 uint n_masks_found = 0;
1742 for (int p = 0; p < N_ASSIGNMENTS; p ++)
1743 {
1744
1745 if (scu [scu_unit_idx].mask_enable [p] == 0)
1746 continue;
1747
1748 if (scu [scu_unit_idx ].mask_assignment [p] == port_num)
1749 {
1750 if (n_masks_found == 0)
1751 mask_num = p;
1752 n_masks_found ++;
1753 }
1754 }
1755
1756 if (! n_masks_found)
1757 {
1758
1759 sim_debug (DBG_WARN, & scu_dev,
1760 "%s: No masks assigned to cpu on port %d\n",
1761 __func__, port_num);
1762 #if defined(THREADZ) || defined(LOCKLESS)
1763 unlock_scu ();
1764 #endif
1765 return SCPE_OK;
1766 }
1767
1768 if (n_masks_found > 1)
1769 {
1770
1771 sim_debug (DBG_WARN, & scu_dev,
1772 "%s: Multiple masks assigned to cpu on port %d\n",
1773 __func__, port_num);
1774 }
1775
1776
1777
1778 scu [scu_unit_idx].exec_intr_mask [mask_num] = 0;
1779 scu [scu_unit_idx].exec_intr_mask [mask_num] |=
1780 ((word32) getbits36_16(rega, 0) << 16);
1781 scu [scu_unit_idx].exec_intr_mask [mask_num] |=
1782 getbits36_16(regq, 0);
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792 sim_debug (DBG_TRACE, & scu_dev,
1793 "SSCR Set mask unit %u port %u mask_num %u "
1794 "mask 0x%08x\n",
1795 scu_unit_idx, port_num, mask_num,
1796 scu [scu_unit_idx].exec_intr_mask [mask_num]);
1797 dump_intr_regs ("sscr set mask", scu_unit_idx);
1798 scu [scu_unit_idx].mask_enable [mask_num] = 1;
1799 sim_debug (DBG_INTR, & scu_dev,
1800 "SCU%u SSCR2 exec_intr mask %c set to 0x%08x"
1801 " and enabled.\n",
1802 scu_unit_idx, 'a' + mask_num,
1803 scu[scu_unit_idx].exec_intr_mask[mask_num]);
1804
1805 deliver_interrupts (scu_unit_idx);
1806 #if defined(THREADZ) || defined(LOCKLESS)
1807 unlock_scu ();
1808 #endif
1809 }
1810 break;
1811
1812 case 00003:
1813 {
1814 #if defined(THREADZ) || defined(LOCKLESS)
1815 lock_scu ();
1816 #endif
1817 for (uint i = 0; i < 16; i ++)
1818 {
1819 scu [scu_unit_idx].cells [i] =
1820 getbits36_1 (rega, i) ? 1 : 0;
1821 scu [scu_unit_idx].cells [i + 16] =
1822 getbits36_1 (regq, i) ? 1 : 0;
1823 }
1824 char pcellb [N_CELL_INTERRUPTS + 1];
1825 sim_debug (DBG_TRACE, & scu_dev,
1826 "SSCR Set int. cells: Unit %u Cells: %s\n",
1827 scu_unit_idx, pcells (scu_unit_idx, pcellb));
1828 sim_debug (DBG_INTR, & scu_dev,
1829 "SCU%u SSCR3 Set int. cells %s\n",
1830 scu_unit_idx, pcells (scu_unit_idx, pcellb));
1831 dump_intr_regs ("sscr set interrupt cells", scu_unit_idx);
1832 deliver_interrupts (scu_unit_idx);
1833 #if defined(THREADZ) || defined(LOCKLESS)
1834 unlock_scu ();
1835 #endif
1836 }
1837 break;
1838
1839 case 00004:
1840 case 00005:
1841 {
1842
1843 word16 b0_15 = (word16) getbits36_16 (cpu.rA, 20);
1844 word36 b16_51 = cpu.rQ;
1845 uint64 new_clk = (((uint64) b0_15) << 36) | b16_51;
1846 #if defined(THREADZ) || defined(LOCKLESS)
1847 lock_scu ();
1848 #endif
1849 scu [scu_unit_idx].user_correction =
1850 (int64) (new_clk - set_SCU_clock (cpup, scu_unit_idx));
1851 #if defined(THREADZ) || defined(LOCKLESS)
1852 unlock_scu ();
1853 #endif
1854
1855 }
1856 break;
1857
1858 case 00006:
1859 case 00007:
1860
1861
1862 sim_warn ("sscr set unit mode register\n");
1863
1864 return SCPE_OK;
1865
1866 default:
1867 sim_warn ("sscr unhandled code\n");
1868
1869 return SCPE_OK;
1870
1871 }
1872 return SCPE_OK;
1873 }
1874
1875 t_stat scu_rscr (cpu_state_t * cpup, uint scu_unit_idx, uint cpu_unit_udx, word18 addr,
1876 word36 * rega, word36 * regq)
1877 {
1878
1879
1880 if (scu_unit_idx >= scu_dev.numunits)
1881 {
1882 sim_warn ("%s: scu_unit_idx out of range %d\n",
1883 __func__, scu_unit_idx);
1884 return SCPE_OK;
1885 }
1886
1887
1888
1889
1890 uint function = (addr >> 3) & 07;
1891
1892
1893
1894
1895
1896 switch (function)
1897 {
1898 case 00000:
1899 {
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911 * rega = 0;
1912
1913 * regq = 0;
1914 #if defined(THREADZ) || defined(LOCKLESS)
1915 lock_scu ();
1916 #endif
1917 putbits36_4 (regq, 50 - 36, scu [scu_unit_idx].id);
1918 putbits36_18 (regq, 54 - 36, scu [scu_unit_idx].mode_reg);
1919 #if defined(THREADZ) || defined(LOCKLESS)
1920 unlock_scu ();
1921 #endif
1922 break;
1923 }
1924
1925 case 00001:
1926 {
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957 sim_debug (DBG_DEBUG, & scu_dev, "rscr 1 %d\n", scu_unit_idx);
1958 #if defined(THREADZ) || defined(LOCKLESS)
1959 lock_scu ();
1960 #endif
1961 scu_t * up = scu + scu_unit_idx;
1962 word9 maskab [2];
1963 for (int i = 0; i < 2; i ++)
1964 {
1965 if (up -> mask_enable [i])
1966 {
1967 maskab [i] = (2 << (N_SCU_PORTS - 1 -
1968 up -> mask_assignment [i])) & 0777;
1969 }
1970 else
1971 maskab [i] = 0001;
1972 }
1973
1974 int scu_port_num = -1;
1975
1976
1977 for (int pn = 0; pn < N_SCU_PORTS; pn ++)
1978 {
1979 for (int sn = 0; sn < N_SCU_SUBPORTS; sn ++)
1980 {
1981 if (cables->scu_to_cpu[scu_unit_idx][pn][sn].in_use &&
1982 cables->scu_to_cpu[scu_unit_idx][pn][sn].cpu_unit_idx ==
1983 cpu_unit_udx)
1984 {
1985 scu_port_num = pn;
1986 goto gotit;
1987 }
1988 }
1989 }
1990 gotit:;
1991 if (scu_port_num < 0)
1992 {
1993 #if defined(THREADZ) || defined(LOCKLESS)
1994 unlock_scu ();
1995 #endif
1996 sim_warn ("%s: can't find cpu port in the snarl of cables; "
1997 "scu_unit_no %d, cpu_unit_udx %d\n",
1998 __func__, scu_unit_idx, cpu_unit_udx);
1999 return SCPE_OK;
2000 }
2001
2002
2003 word36 a, q;
2004
2005 a = 0;
2006
2007 putbits36_9 (& a, 0, maskab [0]);
2008 putbits36_3 (& a, 9, (word3) up -> lower_store_size);
2009 putbits36_4 (& a, 12, (word4) up -> onl);
2010 putbits36_4 (& a, 16, (word4) scu_port_num);
2011 putbits36_1 (& a, 21, (word1) config_switches[scu_unit_idx].mode);
2012 putbits36_8 (& a, 22, (word8) up -> nea);
2013 putbits36_1 (& a, 30, (word1) up -> interlace);
2014 putbits36_1 (& a, 31, (word1) up -> lwr);
2015
2016
2017
2018
2019
2020 putbits36_1 (& a, 32, (word1) up -> port_enable [0]);
2021 putbits36_1 (& a, 33, (word1) up -> port_enable [1]);
2022 putbits36_1 (& a, 34, (word1) up -> port_enable [2]);
2023 putbits36_1 (& a, 35, (word1) up -> port_enable [3]);
2024 * rega = a;
2025
2026 q = 0;
2027 putbits36_9 (& q, 0, maskab [1]);
2028
2029 putbits36_7 (& q, 57-36, (word7) up -> cyclic & MASK7);
2030
2031
2032 putbits36_1 (& q, 32, (word1) up -> port_enable [4]);
2033 putbits36_1 (& q, 33, (word1) up -> port_enable [5]);
2034 putbits36_1 (& q, 34, (word1) up -> port_enable [6]);
2035 putbits36_1 (& q, 35, (word1) up -> port_enable [7]);
2036 * regq = q;
2037
2038 #if defined(THREADZ) || defined(LOCKLESS)
2039 unlock_scu ();
2040 #endif
2041 sim_debug (DBG_DEBUG, & scu_dev,
2042 "rscr 1 %d A: %012"PRIo64" Q: %012"PRIo64"\n",
2043 scu_unit_idx, * rega, * regq);
2044 break;
2045 }
2046
2047 case 00002:
2048 {
2049 uint port_num = (addr >> 6) & MASK3;
2050 #if defined(THREADZ) || defined(LOCKLESS)
2051 lock_scu ();
2052 #endif
2053 scu_t * up = scu + scu_unit_idx;
2054 uint mask_contents = 0;
2055 if (up -> mask_assignment [0] == port_num)
2056 {
2057 mask_contents = up -> exec_intr_mask [0];
2058 }
2059 else if (up -> mask_assignment [1] == port_num)
2060 {
2061 mask_contents = up -> exec_intr_mask [1];
2062 }
2063 mask_contents &= MASK32;
2064
2065 * rega = 0;
2066 putbits36 (rega, 0, 16, (mask_contents >> 16) & MASK16);
2067 putbits36 (rega, 32, 1, up -> port_enable [0]);
2068 putbits36 (rega, 33, 1, up -> port_enable [1]);
2069 putbits36 (rega, 34, 1, up -> port_enable [2]);
2070 putbits36 (rega, 35, 1, up -> port_enable [3]);
2071
2072 * regq = 0;
2073 putbits36 (rega, 0, 16, (mask_contents >> 0) & MASK16);
2074 putbits36 (regq, 32, 1, up -> port_enable [4]);
2075 putbits36 (regq, 33, 1, up -> port_enable [5]);
2076 putbits36 (regq, 34, 1, up -> port_enable [6]);
2077 putbits36 (regq, 35, 1, up -> port_enable [7]);
2078
2079 #if defined(THREADZ) || defined(LOCKLESS)
2080 unlock_scu ();
2081 #endif
2082 sim_debug (DBG_TRACE, & scu_dev,
2083 "RSCR mask unit %u port %u assigns %u %u mask 0x%08x\n",
2084 scu_unit_idx, port_num, up -> mask_assignment [0],
2085 up -> mask_assignment [1],
2086 mask_contents);
2087 }
2088 break;
2089
2090 case 00003:
2091 {
2092 #if defined(THREADZ) || defined(LOCKLESS)
2093 lock_scu ();
2094 #endif
2095 scu_t * up = scu + scu_unit_idx;
2096
2097
2098 for (uint i = 0; i < N_CELL_INTERRUPTS; i ++)
2099 {
2100 word1 cell = up -> cells [i] ? 1 : 0;
2101 if (i < 16)
2102 putbits36_1 (rega, i, cell);
2103 else
2104 putbits36_1 (regq, i - 16, cell);
2105 }
2106 #if defined(THREADZ) || defined(LOCKLESS)
2107 unlock_scu ();
2108 #endif
2109 }
2110 break;
2111
2112 case 00004:
2113 case 00005:
2114 {
2115 uint64 clk = set_SCU_clock (cpup, scu_unit_idx);
2116 cpu.rQ = clk & 0777777777777;
2117 cpu.rA = (clk >> 36) & 0177777;
2118 #if defined(TESTING)
2119 HDBGRegAW ("rscr get clock");
2120 HDBGRegQW ("rscr get clock");
2121 #endif
2122 }
2123 break;
2124
2125 case 00006:
2126 case 00007:
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
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175 * rega = 0;
2176 * regq = 0;
2177 }
2178 break;
2179
2180 default:
2181 sim_warn ("rscr %o\n", function);
2182 return SCPE_OK;
2183 }
2184 return SCPE_OK;
2185 }
2186
2187
2188
2189
2190
2191 int scu_cioc (uint cpu_unit_udx, uint scu_unit_idx, uint scu_port_num,
2192 uint expander_command, uint sub_mask)
2193 {
2194
2195
2196
2197 #if defined(TESTING)
2198 cpu_state_t * cpup = _cpup;
2199 sim_debug (DBG_DEBUG, & scu_dev,
2200 "scu_cioc: Connect from %o sent to "
2201 "unit %o port %o exp %o mask %03o\n",
2202 cpu_unit_udx, scu_unit_idx, scu_port_num,
2203 expander_command, sub_mask);
2204 #endif
2205 #if defined(THREADZ) || defined(LOCKLESS)
2206 lock_scu ();
2207 #endif
2208 struct ports * portp = & scu [scu_unit_idx].ports [scu_port_num];
2209
2210 int rc = 0;
2211 if (! scu [scu_unit_idx].port_enable [scu_port_num])
2212 {
2213 sim_debug (DBG_ERR, & scu_dev,
2214 "scu_cioc: Connect sent to disabled port; dropping\n");
2215 sim_debug (DBG_ERR, & scu_dev,
2216 "scu_cioc: scu_unit_idx %u scu_port_num %u\n",
2217 scu_unit_idx, scu_port_num);
2218 rc = 1;
2219 goto done;
2220 }
2221
2222 if (expander_command == 1)
2223 {
2224 for (uint i = 0; i < N_SCU_SUBPORTS; i++)
2225 {
2226 portp->subport_enables [i] = !! (sub_mask & (0200u >> i));
2227 }
2228 goto done;
2229 }
2230
2231 if (expander_command == 2)
2232 {
2233 int cnt = 0;
2234 int val = -1;
2235 for (uint i = 0; i < N_SCU_SUBPORTS; i++)
2236 {
2237 portp->xipmask [i] = !! (sub_mask & (0200u >> i));
2238 if (portp->xipmask [i])
2239 {
2240 val = (int) i;
2241 cnt ++;
2242 }
2243 }
2244 if (cnt > 1)
2245 {
2246 sim_warn ("xip mask cnt > 1\n");
2247 val = -1;
2248 }
2249 portp->xipmaskval = val;
2250 goto done;
2251 }
2252
2253 if (portp -> type == ADEV_IOM)
2254 {
2255 int iom_unit_idx = portp->dev_idx;
2256 #if defined(THREADZ) || defined(LOCKLESS)
2257 unlock_scu ();
2258 # if !defined(IO_ASYNC_PAYLOAD_CHAN) && !defined(IO_ASYNC_PAYLOAD_CHAN_THREAD)
2259 lock_iom ();
2260 lock_libuv ();
2261 # endif
2262 iom_interrupt (scu_unit_idx, (uint) iom_unit_idx);
2263 # if !defined(IO_ASYNC_PAYLOAD_CHAN) && !defined(IO_ASYNC_PAYLOAD_CHAN_THREAD)
2264 unlock_libuv ();
2265 unlock_iom ();
2266 # endif
2267 return 0;
2268 #else
2269 if (sys_opts.iom_times.connect <= 0)
2270 {
2271 iom_interrupt (scu_unit_idx, (uint) iom_unit_idx);
2272 goto done;
2273 }
2274 else
2275 {
2276
2277
2278
2279 sim_debug (DBG_INFO, & scu_dev,
2280 "scu_cioc: Queuing an IOM in %d cycles "
2281 "(for the connect channel)\n",
2282 sys_opts.iom_times.connect);
2283
2284 iom_dev.units[iom_unit_idx].u3 = (int32) scu_unit_idx;
2285 iom_dev.units[iom_unit_idx].u4 = (int32) iom_unit_idx;
2286 int rc;
2287 if ((rc = sim_activate (& iom_dev.units [iom_unit_idx],
2288 sys_opts.iom_times.connect)) != SCPE_OK)
2289 {
2290 sim_warn ("sim_activate failed (%d)\n", rc);
2291 goto done;
2292 }
2293 goto done;
2294 }
2295 #endif
2296 }
2297 else if (portp -> type == ADEV_CPU)
2298 {
2299
2300
2301 if (portp->is_exp)
2302 {
2303 for (uint sn = 0; sn < N_SCU_SUBPORTS; sn ++)
2304 {
2305 if (portp->subport_enables[sn])
2306 {
2307 if (! cables->
2308 scu_to_cpu[scu_unit_idx][scu_port_num][sn].in_use)
2309 {
2310 sim_warn ("Can't find CPU to interrupt\n");
2311 continue;
2312 }
2313 uint cpu_unit_udx = cables->
2314 scu_to_cpu[scu_unit_idx][scu_port_num][sn].cpu_unit_idx;
2315 setG7fault ((uint) cpu_unit_udx, FAULT_CON, fst_zero);
2316 }
2317 }
2318 }
2319 else
2320 {
2321 if (! cables->scu_to_cpu[scu_unit_idx][scu_port_num][0].in_use)
2322 {
2323 sim_warn ("Can't find CPU to interrupt\n");
2324 rc = 1;
2325 goto done;
2326 }
2327 uint cpu_unit_udx =
2328 cables->scu_to_cpu[scu_unit_idx][scu_port_num][0].cpu_unit_idx;
2329 setG7fault ((uint) cpu_unit_udx, FAULT_CON, fst_zero);
2330 }
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353 goto done;
2354 }
2355 else
2356 {
2357 sim_debug (DBG_ERR, & scu_dev,
2358 "scu_cioc: Connect sent to not-an-IOM or CPU; dropping\n");
2359 rc = 1;
2360 goto done;
2361 }
2362 done:
2363 #if defined(THREADZ) || defined(LOCKLESS)
2364 unlock_scu ();
2365 #endif
2366 return rc;
2367 }
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379 int scu_set_interrupt (uint scu_unit_idx, uint inum)
2380 {
2381 #if defined(TESTING)
2382 cpu_state_t * cpup = _cpup;
2383 #endif
2384 const char* moi = "SCU::interrupt";
2385
2386 if (inum >= N_CELL_INTERRUPTS)
2387 {
2388 sim_debug (DBG_WARN, & scu_dev,
2389 "%s: Bad interrupt number %d\n", moi, inum);
2390 return 1;
2391 }
2392
2393 #if defined(THREADZ) || defined(LOCKLESS)
2394 lock_scu ();
2395 #endif
2396 scu [scu_unit_idx].cells [inum] = 1;
2397 dump_intr_regs ("scu_set_interrupt", scu_unit_idx);
2398 deliver_interrupts (scu_unit_idx);
2399 #if defined(THREADZ) || defined(LOCKLESS)
2400 unlock_scu ();
2401 #endif
2402 return 0;
2403 }
2404
2405
2406
2407
2408
2409
2410
2411 uint scu_get_highest_intr (uint scu_unit_idx)
2412 {
2413 #if defined(TESTING)
2414 cpu_state_t * cpup = _cpup;
2415 #endif
2416 #if defined(THREADZ) || defined(LOCKLESS)
2417 lock_scu ();
2418 #endif
2419
2420 for (int inum = 0; inum < N_CELL_INTERRUPTS; inum ++)
2421 {
2422 for (uint pima = 0; pima < N_ASSIGNMENTS; pima ++)
2423 {
2424 if (scu [scu_unit_idx].mask_enable [pima] == 0)
2425 continue;
2426 uint mask = scu [scu_unit_idx].exec_intr_mask [pima];
2427 uint port = scu [scu_unit_idx].mask_assignment [pima];
2428
2429
2430 if (scu[scu_unit_idx].ports[port].type != ADEV_CPU ||
2431 cpus[current_running_cpu_idx].scu_port[scu_unit_idx] != port)
2432 continue;
2433 if (scu [scu_unit_idx].cells [inum] &&
2434 (mask & (1u << (31 - inum))) != 0)
2435 {
2436 sim_debug (DBG_TRACE, & scu_dev,
2437 "scu_get_highest_intr inum %d pima %u mask 0%011o port %u cells 0%011o\n",
2438 inum, pima, mask, port, scu [scu_unit_idx].cells [inum]);
2439 scu [scu_unit_idx].cells [inum] = false;
2440 dump_intr_regs ("scu_get_highest_intr", scu_unit_idx);
2441 deliver_interrupts (scu_unit_idx);
2442 #if defined(THREADZ) || defined(LOCKLESS)
2443 unlock_scu ();
2444 #endif
2445 return (uint) inum * 2;
2446 }
2447 }
2448 }
2449 #if defined(THREADZ) || defined(LOCKLESS)
2450 unlock_scu ();
2451 #endif
2452 return 1;
2453 }
2454
2455 t_stat scu_reset_unit (UNIT * uptr, UNUSED int32 value,
2456 UNUSED const char * cptr,
2457 UNUSED void * desc)
2458 {
2459 uint scu_unit_idx = (uint) (uptr - scu_unit);
2460 scu_unit_reset ((int) scu_unit_idx);
2461 return SCPE_OK;
2462 }
2463
2464 void scu_init (void)
2465 {
2466
2467
2468 for (int u = 0; u < N_SCU_UNITS_MAX; u ++)
2469 {
2470 for (int p = 0; p < N_SCU_PORTS; p ++)
2471 {
2472 for (int s = 0; s < N_SCU_SUBPORTS; s ++)
2473 {
2474 scu[u].ports[p].dev_port[s] = -1;
2475 scu[u].ports[p].subport_enables[s] = false;
2476 scu[u].ports[p].xipmask[s] = false;
2477
2478 scu[u].ports[p].xipmaskval = N_SCU_SUBPORTS;
2479 }
2480 scu[u].ports[p].type = ADEV_NONE;
2481 scu[u].ports[p].is_exp = false;
2482 }
2483
2484
2485
2486
2487 scu [u].id = 02l;
2488 scu [u].mode_reg = 0;
2489 scu [u].elapsed_days = 0;
2490 }
2491
2492 }
2493
2494 t_stat scu_rmcm (uint scu_unit_idx, uint cpu_unit_udx, word36 * rega,
2495 word36 * regq)
2496 {
2497 #if defined(TESTING)
2498 cpu_state_t * cpup = _cpup;
2499 #endif
2500 scu_t * up = scu + scu_unit_idx;
2501
2502
2503 * rega = 0;
2504 * regq = 0;
2505
2506
2507
2508 int scu_port_num = -1;
2509
2510
2511 for (int pn = 0; pn < N_SCU_PORTS; pn ++)
2512 {
2513 for (int sn = 0; sn < N_SCU_SUBPORTS; sn ++)
2514 {
2515 if (cables->scu_to_cpu[scu_unit_idx][pn][sn].in_use &&
2516 cables->scu_to_cpu[scu_unit_idx][pn][sn].cpu_unit_idx ==
2517 cpu_unit_udx)
2518 {
2519 scu_port_num = pn;
2520 goto gotit;
2521 }
2522 }
2523 }
2524
2525 gotit:;
2526
2527
2528
2529 if (scu_port_num < 0)
2530 {
2531 sim_warn ("%s: can't find cpu port in the snarl of cables; "
2532 "scu_unit_no %d, cpu_unit_udx %d\n",
2533 __func__, scu_unit_idx, cpu_unit_udx);
2534 sim_debug (DBG_ERR, & scu_dev,
2535 "%s: can't find cpu port in the snarl of cables; "
2536 "scu_unit_no %d, cpu_unit_udx %d\n",
2537 __func__, scu_unit_idx, cpu_unit_udx);
2538
2539 return SCPE_OK;
2540 }
2541
2542
2543
2544
2545
2546
2547
2548
2549 sim_debug (DBG_TRACE, & scu_dev, "rmcm selected scu port %u\n",
2550 scu_port_num);
2551 #if defined(THREADZ) || defined(LOCKLESS)
2552 lock_scu ();
2553 #endif
2554 uint mask_contents = 0;
2555 if (up -> mask_assignment [0] == (uint) scu_port_num)
2556 {
2557 mask_contents = up -> exec_intr_mask [0];
2558 sim_debug (DBG_TRACE, & scu_dev, "rmcm got mask %011o from pima A\n",
2559 mask_contents);
2560 }
2561 else if (up -> mask_assignment [1] == (uint) scu_port_num)
2562 {
2563 mask_contents = up -> exec_intr_mask [1];
2564 sim_debug (DBG_TRACE, & scu_dev, "rmcm got mask %011o from pima B\n",
2565 mask_contents);
2566 }
2567 mask_contents &= MASK32;
2568
2569 * rega = 0;
2570 putbits36_16 (rega, 0, (mask_contents >> 16) & MASK16);
2571 putbits36_1 (rega, 32, (word1) up -> port_enable [0]);
2572 putbits36_1 (rega, 33, (word1) up -> port_enable [1]);
2573 putbits36_1 (rega, 34, (word1) up -> port_enable [2]);
2574 putbits36_1 (rega, 35, (word1) up -> port_enable [3]);
2575
2576 * regq = 0;
2577 putbits36_16 (regq, 0, (mask_contents >> 0) & MASK16);
2578 putbits36_1 (regq, 32, (word1) up -> port_enable [4]);
2579 putbits36_1 (regq, 33, (word1) up -> port_enable [5]);
2580 putbits36_1 (regq, 34, (word1) up -> port_enable [6]);
2581 putbits36_1 (regq, 35, (word1) up -> port_enable [7]);
2582
2583 #if defined(THREADZ) || defined(LOCKLESS)
2584 unlock_scu ();
2585 #endif
2586 sim_debug (DBG_TRACE, & scu_dev,
2587 "RMCM returns %012"PRIo64" %012"PRIo64"\n",
2588 * rega, * regq);
2589 dump_intr_regs ("rmcm", scu_unit_idx);
2590 return SCPE_OK;
2591 }
2592
2593 t_stat scu_smcm (uint scu_unit_idx, uint cpu_unit_udx, word36 rega, word36 regq)
2594 {
2595 #if defined(TESTING)
2596 cpu_state_t * cpup = _cpup;
2597 #endif
2598 sim_debug (DBG_TRACE, & scu_dev,
2599 "SMCM SCU unit %d CPU unit %d A %012"PRIo64" Q %012"PRIo64"\n",
2600 scu_unit_idx, cpu_unit_udx, rega, regq);
2601
2602 scu_t * up = scu + scu_unit_idx;
2603
2604
2605
2606 int scu_port_num = -1;
2607
2608
2609 for (int pn = 0; pn < N_SCU_PORTS; pn ++)
2610 {
2611 for (int sn = 0; sn < N_SCU_SUBPORTS; sn ++)
2612 {
2613 if (cables->scu_to_cpu[scu_unit_idx][pn][sn].in_use &&
2614 cables->scu_to_cpu[scu_unit_idx][pn][sn].cpu_unit_idx ==
2615 cpu_unit_udx)
2616 {
2617 scu_port_num = pn;
2618 goto gotit;
2619 }
2620 }
2621 }
2622 gotit:;
2623
2624
2625
2626 if (scu_port_num < 0)
2627 {
2628 sim_warn ("%s: can't find cpu port in the snarl of cables; "
2629 "scu_unit_no %d, cpu_unit_udx %d\n",
2630 __func__, scu_unit_idx, cpu_unit_udx);
2631 return SCPE_OK;
2632 }
2633
2634 sim_debug (DBG_TRACE, & scu_dev, "SMCM SCU port num %d\n", scu_port_num);
2635
2636
2637
2638
2639
2640
2641
2642
2643 uint imask =
2644 ((uint) getbits36_16(rega, 0) << 16) |
2645 ((uint) getbits36_16(regq, 0) << 0);
2646 #if defined(THREADZ) || defined(LOCKLESS)
2647 lock_scu ();
2648 #endif
2649 if (up -> mask_assignment [0] == (uint) scu_port_num)
2650 {
2651 up -> exec_intr_mask [0] = imask;
2652 sim_debug (DBG_TRACE, & scu_dev, "SMCM intr mask 0 set to %011o\n",
2653 imask);
2654 }
2655 else if (up -> mask_assignment [1] == (uint) scu_port_num)
2656 {
2657 up -> exec_intr_mask [1] = imask;
2658 sim_debug (DBG_TRACE, & scu_dev, "SMCM intr mask 1 set to %011o\n",
2659 imask);
2660 }
2661
2662 scu [scu_unit_idx].port_enable [0] = (uint) getbits36_1 (rega, 32);
2663 scu [scu_unit_idx].port_enable [1] = (uint) getbits36_1 (rega, 33);
2664 scu [scu_unit_idx].port_enable [2] = (uint) getbits36_1 (rega, 34);
2665 scu [scu_unit_idx].port_enable [3] = (uint) getbits36_1 (rega, 35);
2666 scu [scu_unit_idx].port_enable [4] = (uint) getbits36_1 (regq, 32);
2667 scu [scu_unit_idx].port_enable [5] = (uint) getbits36_1 (regq, 33);
2668 scu [scu_unit_idx].port_enable [6] = (uint) getbits36_1 (regq, 34);
2669 scu [scu_unit_idx].port_enable [7] = (uint) getbits36_1 (regq, 35);
2670
2671 dump_intr_regs ("smcm", scu_unit_idx);
2672 deliver_interrupts (scu_unit_idx);
2673 #if defined(THREADZ) || defined(LOCKLESS)
2674 unlock_scu ();
2675 #endif
2676
2677 return SCPE_OK;
2678 }