This source file includes following definitions.
- iom_build_addr_map
- iom_addr_map_changed
- iom_interlace_addr
- iom_map_addr
- iom_cache_purge
- iom_core_read
- iom_core_read2
- iom_core_write
- iom_core_write2
- iom_core_read_lock
- iom_core_write_unlock
- iom_action
- iom_show_mbx
- iom_show_units
- iom_set_units
- iom_show_config
- iom_set_config
- iom_reset_unit
- iom_unit_reset_idx
- iom_reset
- iom_boot_store
- init_memory_iom
- boot_svc
- iom_boot
- mbxLoc
- status_service
- build_AUXPTW_address
- build_DDSPTW_address
- fetch_DDSPTW
- build_IDSPTW_address
- fetch_IDSPTW
- build_LPWPTW_address
- fetch_LPWPTW
- iom_direct_data_service
- iom_indirect_data_service
- tdcw_chan_mode
- update_chan_mode
- write_LPW
- iom_advance_lpw
- iom_continue_channel
- dumpDCW
- dumpLPW
- fetch_and_parse_LPW
- unpack_DCW
- pack_DCW
- pack_LPW
- fetch_and_parse_PCW
- fetch_and_parse_DCW
- peek_list_word
- iom_peek_next_dcw
- send_general_interrupt
- iom_fault
- iom_list_service
- doPayloadChannel
- doWrapAroundChan
- doConnectChan
- send_marker_interrupt
- send_special_interrupt
- send_terminate_interrupt
- iom_interrupt
- chan_thread_main
- iom_thread_main
- iom_init
- do_boot
- iomProcess
- iomChar
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
544
545
546
547
548
549
550
551
552 #include "dps8.h"
553 #include "dps8_cpu.h"
554 #include "dps8_rt.h"
555 #include "dps8_priv.h"
556 #include "dps8_sys.h"
557 #include "dps8_faults.h"
558 #include "dps8_scu.h"
559 #include "dps8_iom.h"
560 #include "dps8_cable.h"
561 #include "dps8_console.h"
562 #include "dps8_fnp2.h"
563 #include "dps8_utils.h"
564 #include "dps8_cache.h"
565 #if defined(LOCKLESS)
566 # include "threadz.h"
567 #endif
568
569 #define DBG_CTR 1
570
571
572
573
574
575
576
577
578 #define N_IOM_UNITS 1
579
580 #define IOM_UNIT_IDX(uptr) ((uptr) - iom_unit)
581
582 #define IOM_SYSTEM_FAULT_CHAN 1U
583 #define IOM_CONNECT_CHAN 2U
584 #define IOM_WAC_CHAN 4U
585 #define IOM_SPECIAL_STATUS_CHAN 6U
586
587 iom_chan_data_t iom_chan_data[N_IOM_UNITS_MAX][MAX_CHANNELS];
588
589 typedef enum iom_status_t
590 {
591 iomStatNormal = 0,
592 iomStatLPWTRO = 1,
593 iomStat2TDCW = 2,
594 iomStatBoundaryError = 3,
595 iomStatAERestricted = 4,
596 iomStatIDCWRestricted = 5,
597 iomStatCPDiscrepancy = 6,
598 iomStatParityErr = 7
599 } iom_status_t;
600
601 enum config_sw_OS_t
602 {
603 CONFIG_SW_STD_GCOS,
604 CONFIG_SW_EXT_GCOS,
605 CONFIG_SW_MULTICS
606 };
607
608 enum config_sw_model_t
609 {
610 CONFIG_SW_MODEL_IOM,
611 CONFIG_SW_MODEL_IMU
612 };
613
614
615 enum config_sw_bootload_device_e { CONFIG_SW_BLCT_CARD, CONFIG_SW_BLCT_TAPE };
616
617
618
619
620
621
622 #define IOM_MAP_UNIT 16384u
623 #define IOM_MAP_UNITS (MEM_SIZE_MAX / IOM_MAP_UNIT)
624 #define IOM_ZONE_SZ (MEM_SIZE_MAX / 4u)
625
626 typedef struct
627 {
628
629
630
631 word12 configSwIomBaseAddress;
632
633
634
635
636
637
638
639
640
641
642
643
644 word9 configSwMultiplexBaseAddress;
645
646 enum config_sw_model_t config_sw_model;
647
648
649 enum config_sw_OS_t config_sw_OS;
650
651
652 enum config_sw_bootload_device_e configSwBootloadCardTape;
653
654
655 word6 configSwBootloadMagtapeChan;
656
657
658 word6 configSwBootloadCardrdrChan;
659
660
661
662
663
664
665
666
667 word3 configSwBootloadPort;
668
669
670
671
672 uint configSwPortAddress[N_IOM_PORTS];
673
674
675 uint configSwPortInterface[N_IOM_PORTS];
676
677
678 uint configSwPortEnable[N_IOM_PORTS];
679
680
681 uint configSwPortSysinitEnable[N_IOM_PORTS];
682
683
684 uint configSwPortHalfsize[N_IOM_PORTS];
685
686 uint configSwPortStoresize[N_IOM_PORTS];
687
688
689
690
691
692
693 bool useMap;
694 bool addrMapValid;
695 bool addrMapWarned;
696 int addrMap[IOM_MAP_UNITS];
697 int8_t addrMapPort[IOM_MAP_UNITS];
698
699
700
701
702 iom_status_t iomStatus;
703
704 uint invokingScuUnitIdx;
705
706 coreLockState_t iomCoreLockState;
707
708
709 word36 wacData[2];
710 word36 wacStatus;
711
712 } iom_unit_data_t;
713
714 static iom_unit_data_t iom_unit_data[N_IOM_UNITS_MAX];
715
716 typedef enum iomSysFaults_t
717 {
718
719 iomNoFlt = 000,
720 iomIllChanFlt = 001,
721
722 iomIllSrvReqFlt = 002,
723
724
725
726 iomBndryVioFlt = 003,
727 iom256KFlt = 004,
728
729 iomLPWTRPConnFlt = 005,
730
731
732 iomNotPCWFlt = 006,
733 iomCP1Flt = 007,
734
735
736
737
738
739
740 iomIllTalCChnFlt = 013,
741
742
743
744 iomPTWFlagFault = 015,
745
746
747 iomNoPortFault = 017,
748
749 } iomSysFaults_t;
750
751 typedef enum iomFaultServiceRequest
752 {
753
754 iomFsrFirstList = (1 << 2) | 2,
755 iomFsrList = (1 << 2) | 0,
756 iomFsrStatus = (2 << 2) | 0,
757 iomFsrIntr = (3 << 2) | 0,
758 iomFsrSPIndLoad = (4 << 2) | 0,
759 iomFsrDPIndLoad = (4 << 2) | 1,
760 iomFsrSPIndStore = (5 << 2) | 0,
761 iomFsrDPIndStore = (5 << 2) | 1,
762 iomFsrSPDirLoad = (6 << 2) | 0,
763 iomFsrDPDirLoad = (6 << 2) | 1,
764 iomFsrSPDirStore = (7 << 2) | 0,
765 iomFsrDPDirStore = (7 << 2) | 1
766 } iomFaultServiceRequest;
767
768 #if defined(IO_THREADZ)
769 __thread uint this_iom_idx;
770 __thread uint this_chan_num;
771 #endif
772
773 #if defined(TESTING)
774 static char * cmdNames [] =
775 {
776 "Request Status",
777 "",
778 "Rd Ctrlr Mem",
779 "Rd 9 Rcrd",
780 "",
781 "Rd Bin Rcrd",
782 "Initiate Rd Data Xfer",
783 "",
784 "",
785 "",
786 "",
787 "Wr 9 Rcrd",
788 "",
789 "Wr Bin Rcrd",
790 "Initiate Wr Data Xfer",
791 "",
792 "Release Ctlr",
793 "",
794 "RdStatReg",
795 "",
796 "",
797 "Read",
798 "",
799 "",
800 "Seek 512",
801 "",
802 "MTP Wr Mem",
803 "Write ASCII",
804 "",
805 "",
806 "",
807 "",
808 "Reset Status",
809 "Set 6250 CPI",
810 "Restore",
811 "",
812 "Forward Skip Rcrd",
813 "Forward Skip File",
814 "Backward Skip Rcrd",
815 "Backspace File",
816 "Request Status",
817 "Reset Dev Stat/Alert",
818 "",
819 "",
820 "",
821 "Write EOF",
822 "",
823 "Survey Devs/ReadID",
824 "Set 800 BPI",
825 "Set 556 BPI",
826 "",
827 "Set File Permit",
828 "Set 200 BPI",
829 "Set 1600 CPI",
830 "",
831 "",
832 "Rewind",
833 "",
834 "Rewind/Unload",
835 "",
836 "",
837 "",
838 "",
839 "",
840 };
841 #endif
842
843
844 static void iom_build_addr_map (uint iom_unit_idx)
845 {
846 iom_unit_data_t * p = iom_unit_data + iom_unit_idx;
847 for (uint u = 0; u < IOM_MAP_UNITS; u ++)
848 {
849 p->addrMap[u] = -1;
850 p->addrMapPort[u] = -1;
851 }
852 for (uint port = 0; port < N_IOM_PORTS; port ++)
853 {
854 if (! p->configSwPortEnable[port])
855 continue;
856 struct iom_to_scu_s * c = & cables->iom_to_scu[iom_unit_idx][port];
857 if (! c->in_use || c->scu_unit_idx >= MEM_SIZE_MAX / IOM_ZONE_SZ)
858 continue;
859 if (p->useMap && p->configSwPortInterface[port])
860 sim_warn ("IOM%c port %u: port interlace is not modelled; "
861 "mapped as not interlaced\r\n",
862 'A' + iom_unit_idx, port);
863 uint size = 32768u << (p->configSwPortStoresize[port] & 7u);
864 if (p->configSwPortHalfsize[port])
865 size /= 2;
866 uint base = size * p->configSwPortAddress[port];
867 for (uint off = 0; off < size; off += IOM_MAP_UNIT)
868 {
869 uint addr = base + off;
870 if (addr >= MEM_SIZE_MAX)
871 break;
872 uint u = addr / IOM_MAP_UNIT;
873 if (p->addrMap[u] >= 0)
874 {
875 if (p->useMap)
876 sim_warn ("IOM%c port %u: addresses from %08o are already "
877 "on port %d\r\n", 'A' + iom_unit_idx, port, addr,
878 p->addrMapPort[u]);
879 break;
880 }
881 p->addrMap[u] = (int) (c->scu_unit_idx * IOM_ZONE_SZ + off);
882 p->addrMapPort[u] = (int8_t) port;
883 }
884 }
885 p->addrMapValid = true;
886 }
887
888
889 void iom_addr_map_changed (uint iom_unit_idx)
890 {
891 if (iom_unit_idx < N_IOM_UNITS_MAX)
892 iom_unit_data[iom_unit_idx].addrMapValid = false;
893 }
894
895
896
897
898
899
900
901
902
903
904
905
906 static uint iom_interlace_addr (uint iom_unit_idx, uint port, word24 addr)
907 {
908 iom_unit_data_t * p = iom_unit_data + iom_unit_idx;
909 uint scu_unit_idx = cables->iom_to_scu[iom_unit_idx][port].scu_unit_idx;
910 scu_t * up = scu + scu_unit_idx;
911 uint size = 32768u << (p->configSwPortStoresize[port] & 7u);
912 if (p->configSwPortHalfsize[port])
913 size /= 2;
914 uint base_wds = size * p->configSwPortAddress[port];
915 uint scu_base_wds = base_wds % (4u << 20);
916 uint scu_addr = scu_base_wds + (addr - base_wds);
917 uint lower_wds = (1u << up->lower_store_size) * 32768u;
918 uint stride_wds = lower_wds > (2u << 20) ? (2u << 20) : lower_wds;
919 uint store = (scu_addr >> 1) & 1;
920 uint word = ((scu_addr >> 2) << 1) | (scu_addr & 1);
921 if (scu_addr >= 2 * lower_wds || word >= lower_wds)
922 return scu_unit_idx * IOM_ZONE_SZ + (addr - base_wds) % IOM_ZONE_SZ;
923 uint home_store = up->lwr ? 1 - store : store;
924 uint home = home_store * stride_wds + word;
925 return scu_unit_idx * IOM_ZONE_SZ + (home + (4u << 20) - scu_base_wds) % (4u << 20);
926 }
927
928
929
930
931 uint iom_map_addr (uint iom_unit_idx, word24 addr)
932 {
933 iom_unit_data_t * p = iom_unit_data + iom_unit_idx;
934 if (! p->useMap)
935 return addr;
936 if (! p->addrMapValid)
937 iom_build_addr_map (iom_unit_idx);
938 uint u = addr / IOM_MAP_UNIT;
939 int base = u < IOM_MAP_UNITS ? p->addrMap[u] : -1;
940 if (base < 0)
941 {
942 if (! p->addrMapWarned)
943 {
944 sim_warn ("IOM%c: address %08o is on no enabled port; "
945 "used unmapped\r\n", 'A' + iom_unit_idx, addr);
946 p->addrMapWarned = true;
947 }
948 return addr;
949 }
950 uint port = (uint) p->addrMapPort[u];
951 struct iom_to_scu_s * c = & cables->iom_to_scu[iom_unit_idx][port];
952 if (scu[c->scu_unit_idx].interlace)
953 return iom_interlace_addr (iom_unit_idx, port, addr);
954 return (uint) base + addr % IOM_MAP_UNIT;
955 }
956
957
958
959
960
961
962 static void iom_cache_purge (word24 addr)
963 {
964 cachePurgeAll (addr);
965 }
966
967 void iom_core_read (uint iom_unit_idx, word24 addr, word36 *data, UNUSED const char * ctx)
968 {
969 addr = (word24) iom_map_addr (iom_unit_idx, addr);
970 #if defined(LOCKLESS)
971 # if !defined(SUNLINT)
972 word36 v;
973 LOAD_ACQ_CORE_WORD(v, addr);
974 * data = v & DMASK;
975 # endif
976 #else
977 * data = M[addr] & DMASK;
978 #endif
979 }
980
981 void iom_core_read2 (uint iom_unit_idx, word24 addr, word36 *even, word36 *odd, UNUSED const char * ctx)
982 {
983 word24 addr1 = (word24) iom_map_addr (iom_unit_idx, (addr + 1) & MASK24);
984 addr = (word24) iom_map_addr (iom_unit_idx, addr);
985 #if defined(LOCKLESS)
986 # if !defined(SUNLINT)
987 word36 v;
988 LOAD_ACQ_CORE_WORD(v, addr);
989 * even = v & DMASK;
990 LOAD_ACQ_CORE_WORD(v, addr1);
991 * odd = v & DMASK;
992 # endif
993 #else
994 * even = M[addr] & DMASK;
995 * odd = M[addr1] & DMASK;
996 #endif
997 }
998
999 void iom_core_write (uint iom_unit_idx, word24 addr, word36 data, UNUSED const char * ctx)
1000 {
1001 addr = (word24) iom_map_addr (iom_unit_idx, addr);
1002 #if defined(LOCKLESS)
1003 LOCK_CORE_WORD(addr, & iom_unit_data[iom_unit_idx].iomCoreLockState);
1004 # if !defined(SUNLINT)
1005 STORE_REL_CORE_WORD(addr, data);
1006 # endif
1007 #else
1008 M[addr] = data & DMASK;
1009 #endif
1010 iom_cache_purge (addr);
1011 }
1012
1013 void iom_core_write2 (uint iom_unit_idx, word24 addr, word36 even, word36 odd, UNUSED const char * ctx)
1014 {
1015 word24 addr1 = (word24) iom_map_addr (iom_unit_idx, (addr + 1) & MASK24);
1016 addr = (word24) iom_map_addr (iom_unit_idx, addr);
1017 #if defined(LOCKLESS)
1018 LOCK_CORE_WORD(addr, & iom_unit_data[iom_unit_idx].iomCoreLockState);
1019 # if !defined(SUNLINT)
1020 STORE_REL_CORE_WORD(addr, even);
1021 # endif
1022 LOCK_CORE_WORD(addr1, & iom_unit_data[iom_unit_idx].iomCoreLockState);
1023 # if !defined(SUNLINT)
1024 STORE_REL_CORE_WORD(addr1, odd);
1025 # endif
1026 #else
1027 M[addr] = even;
1028 M[addr1] = odd;
1029 #endif
1030 iom_cache_purge (addr);
1031 iom_cache_purge (addr1);
1032 }
1033
1034 void iom_core_read_lock (uint iom_unit_idx, word24 addr, word36 *data, UNUSED const char * ctx)
1035 {
1036 addr = (word24) iom_map_addr (iom_unit_idx, addr);
1037 #if defined(LOCKLESS)
1038 LOCK_CORE_WORD(addr, & iom_unit_data[iom_unit_idx].iomCoreLockState);
1039 # if !defined(SUNLINT)
1040 word36 v;
1041 LOAD_ACQ_CORE_WORD(v, addr);
1042 * data = v & DMASK;
1043 # endif
1044 #else
1045 * data = M[addr] & DMASK;
1046 #endif
1047 }
1048
1049 void iom_core_write_unlock (uint iom_unit_idx, word24 addr, word36 data, UNUSED const char * ctx)
1050 {
1051 addr = (word24) iom_map_addr (iom_unit_idx, addr);
1052 #if defined(LOCKLESS)
1053 # if !defined(SUNLINT)
1054 STORE_REL_CORE_WORD(addr, data);
1055 # endif
1056 #else
1057 M[addr] = data & DMASK;
1058 #endif
1059 iom_cache_purge (addr);
1060 }
1061
1062 static t_stat iom_action (UNIT *up)
1063 {
1064
1065 uint scu_unit_idx = (uint) (up -> u3);
1066 uint iom_unit_idx = (uint) (up -> u4);
1067 iom_interrupt (scu_unit_idx, iom_unit_idx);
1068 return SCPE_OK;
1069 }
1070
1071 static UNIT iom_unit[N_IOM_UNITS_MAX] = {
1072 #if defined(NO_C_ELLIPSIS)
1073 { UDATA (iom_action, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1074 { UDATA (iom_action, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1075 { UDATA (iom_action, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1076 { UDATA (iom_action, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL }
1077 #else
1078 [0 ... N_IOM_UNITS_MAX - 1] = {
1079 UDATA (iom_action, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL
1080 }
1081 #endif
1082 };
1083
1084 static t_stat iom_show_mbx (UNUSED FILE * st,
1085 UNUSED UNIT * uptr, UNUSED int val,
1086 UNUSED const void * desc)
1087 {
1088 return SCPE_OK;
1089 }
1090
1091 static t_stat iom_show_units (UNUSED FILE * st, UNUSED UNIT * uptr, UNUSED int val, UNUSED const void * desc)
1092 {
1093 sim_printf ("Number of IOM units in system is %d\r\n", iom_dev.numunits);
1094 return SCPE_OK;
1095 }
1096
1097 static t_stat iom_set_units (UNUSED UNIT * uptr, UNUSED int value, const char * cptr, UNUSED void * desc)
1098 {
1099 if (! cptr)
1100 return SCPE_ARG;
1101 int n = atoi (cptr);
1102 if (n < 1 || n > N_IOM_UNITS_MAX)
1103 return SCPE_ARG;
1104
1105
1106
1107 iom_dev.numunits = (unsigned) n;
1108 return SCPE_OK;
1109 }
1110
1111 static t_stat iom_show_config (UNUSED FILE * st, UNIT * uptr, UNUSED int val,
1112 UNUSED const void * desc)
1113 {
1114 uint iom_unit_idx = (uint) IOM_UNIT_IDX (uptr);
1115 if (iom_unit_idx >= iom_dev.numunits)
1116 {
1117 sim_printf ("error: Invalid unit number %lu\r\n", (unsigned long) iom_unit_idx);
1118 return SCPE_ARG;
1119 }
1120
1121 sim_printf ("IOM unit number %lu\r\n", (unsigned long) iom_unit_idx);
1122 iom_unit_data_t * p = iom_unit_data + iom_unit_idx;
1123
1124 char * os = "<out of range>";
1125 switch (p -> config_sw_OS)
1126 {
1127 case CONFIG_SW_STD_GCOS:
1128 os = "Standard GCOS";
1129 break;
1130 case CONFIG_SW_EXT_GCOS:
1131 os = "Extended GCOS";
1132 break;
1133 case CONFIG_SW_MULTICS:
1134 os = "Multics";
1135 break;
1136 }
1137 char * blct = "<out of range>";
1138 switch (p -> configSwBootloadCardTape)
1139 {
1140 case CONFIG_SW_BLCT_CARD:
1141 blct = "CARD";
1142 break;
1143 case CONFIG_SW_BLCT_TAPE:
1144 blct = "TAPE";
1145 break;
1146 }
1147
1148 sim_printf ("Allowed Operating System: %s\r\n", os);
1149 sim_printf ("IOM Base Address: %03o(8)\r\n", p -> configSwIomBaseAddress);
1150 sim_printf ("Multiplex Base Address: %04o(8)\r\n", p -> configSwMultiplexBaseAddress);
1151 sim_printf ("Bootload Card/Tape: %s\r\n", blct);
1152 sim_printf ("Bootload Tape Channel: %02o(8)\r\n", p -> configSwBootloadMagtapeChan);
1153 sim_printf ("Bootload Card Channel: %02o(8)\r\n", p -> configSwBootloadCardrdrChan);
1154 sim_printf ("Bootload Port: %02o(8)\r\n", p -> configSwBootloadPort);
1155 sim_printf ("Port Address: ");
1156 int i;
1157 for (i = 0; i < N_IOM_PORTS; i ++)
1158 sim_printf (" %03o", p -> configSwPortAddress[i]);
1159 sim_printf ("\r\n");
1160 sim_printf ("Port Interlace: ");
1161 for (i = 0; i < N_IOM_PORTS; i ++)
1162 sim_printf (" %3o", p -> configSwPortInterface[i]);
1163 sim_printf ("\r\n");
1164 sim_printf ("Port Enable: ");
1165 for (i = 0; i < N_IOM_PORTS; i ++)
1166 sim_printf (" %3o", p -> configSwPortEnable[i]);
1167 sim_printf ("\r\n");
1168 sim_printf ("Port Sysinit Enable: ");
1169 for (i = 0; i < N_IOM_PORTS; i ++)
1170 sim_printf (" %3o", p -> configSwPortSysinitEnable[i]);
1171 sim_printf ("\r\n");
1172 sim_printf ("Port Halfsize: ");
1173 for (i = 0; i < N_IOM_PORTS; i ++)
1174 sim_printf (" %3o", p -> configSwPortHalfsize[i]);
1175 sim_printf ("\r\n");
1176 sim_printf ("Port Storesize: ");
1177 for (i = 0; i < N_IOM_PORTS; i ++)
1178 sim_printf (" %3o", p -> configSwPortStoresize[i]);
1179 sim_printf ("\r\n");
1180 sim_printf ("Use port map: %s\r\n", p -> useMap ? "yes" : "no");
1181
1182 return SCPE_OK;
1183 }
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205 static config_value_list_t cfg_model_list[] =
1206 {
1207 { "iom", CONFIG_SW_MODEL_IOM },
1208 { "imu", CONFIG_SW_MODEL_IMU }
1209 };
1210
1211 static config_value_list_t cfg_os_list[] =
1212 {
1213 { "gcos", CONFIG_SW_STD_GCOS },
1214 { "gcosext", CONFIG_SW_EXT_GCOS },
1215 { "multics", CONFIG_SW_MULTICS },
1216 { NULL, 0 }
1217 };
1218
1219 static config_value_list_t cfg_boot_list[] =
1220 {
1221 { "card", CONFIG_SW_BLCT_CARD },
1222 { "tape", CONFIG_SW_BLCT_TAPE },
1223 { NULL, 0 }
1224 };
1225
1226 static config_value_list_t cfg_base_list[] =
1227 {
1228 { "multics", 014 },
1229 { "multics1", 014 },
1230 { "multics2", 020 },
1231 { "multics3", 024 },
1232 { "multics4", 030 },
1233 { NULL, 0 }
1234 };
1235
1236 static config_value_list_t cfg_size_list[] =
1237 {
1238 { "32", 0 },
1239 { "64", 1 },
1240 { "128", 2 },
1241 { "256", 3 },
1242 { "512", 4 },
1243 { "1024", 5 },
1244 { "2048", 6 },
1245 { "4096", 7 },
1246 { "32K", 0 },
1247 { "64K", 1 },
1248 { "128K", 2 },
1249 { "256K", 3 },
1250 { "512K", 4 },
1251 { "1024K", 5 },
1252 { "2048K", 6 },
1253 { "4096K", 7 },
1254 { "1M", 5 },
1255 { "2M", 6 },
1256 { "4M", 7 },
1257 { NULL, 0 }
1258 };
1259
1260 static config_value_list_t cfg_on_off[] =
1261 {
1262 { "off", 0 },
1263 { "on", 1 },
1264 { "disable", 0 },
1265 { "enable", 1 },
1266 { NULL, 0 }
1267 };
1268
1269 static config_list_t iom_config_list[] =
1270 {
1271 { "model", 1, 0, cfg_model_list },
1272 { "os", 1, 0, cfg_os_list },
1273 { "boot", 1, 0, cfg_boot_list },
1274 { "iom_base", 0, 07777, cfg_base_list },
1275 { "multiplex_base", 0, 0777, NULL },
1276 { "tapechan", 0, 077, NULL },
1277 { "cardchan", 0, 077, NULL },
1278 { "scuport", 0, 07, NULL },
1279 { "port", 0, N_IOM_PORTS - 1, NULL },
1280 { "addr", 0, 7, NULL },
1281 { "interlace", 0, 1, NULL },
1282 { "enable", 0, 1, NULL },
1283 { "initenable", 0, 1, NULL },
1284 { "halfsize", 0, 1, NULL },
1285 { "store_size", 0, 7, cfg_size_list },
1286 { "usemap", 0, 1, cfg_on_off },
1287 { NULL, 0, 0, NULL }
1288 };
1289
1290 static t_stat iom_set_config (UNIT * uptr, UNUSED int value, const char * cptr, UNUSED void * desc)
1291 {
1292 uint iom_unit_idx = (uint) IOM_UNIT_IDX (uptr);
1293 if (iom_unit_idx >= iom_dev.numunits)
1294 {
1295 sim_printf ("error: %s: Invalid unit number %ld\r\n", __func__, (long) iom_unit_idx);
1296 return SCPE_ARG;
1297 }
1298
1299 iom_unit_data_t * p = iom_unit_data + iom_unit_idx;
1300
1301 static uint port_num = 0;
1302
1303 config_state_t cfg_state = { NULL, NULL };
1304
1305 iom_addr_map_changed (iom_unit_idx);
1306 for (;;)
1307 {
1308 int64_t v;
1309 int rc = cfg_parse (__func__, cptr, iom_config_list, & cfg_state, & v);
1310
1311 if (rc == -1)
1312 break;
1313
1314 if (rc == -2)
1315 {
1316 cfg_parse_done (& cfg_state);
1317 continue;
1318 }
1319 const char * name = iom_config_list[rc].name;
1320
1321 if (strcmp (name, "model") == 0)
1322 {
1323 p -> config_sw_model = (enum config_sw_model_t) v;
1324 continue;
1325 }
1326
1327 if (strcmp (name, "os") == 0)
1328 {
1329 p -> config_sw_OS = (enum config_sw_OS_t) v;
1330 continue;
1331 }
1332
1333 if (strcmp (name, "boot") == 0)
1334 {
1335 p -> configSwBootloadCardTape = (enum config_sw_bootload_device_e) v;
1336 continue;
1337 }
1338
1339 if (strcmp (name, "iom_base") == 0)
1340 {
1341 p -> configSwIomBaseAddress = (word12) v;
1342 continue;
1343 }
1344
1345 if (strcmp (name, "multiplex_base") == 0)
1346 {
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363 p -> configSwMultiplexBaseAddress = (word9) v;
1364 continue;
1365 }
1366
1367 if (strcmp (name, "tapechan") == 0)
1368 {
1369 p -> configSwBootloadMagtapeChan = (word6) v;
1370 continue;
1371 }
1372
1373 if (strcmp (name, "cardchan") == 0)
1374 {
1375 p -> configSwBootloadCardrdrChan = (word6) v;
1376 continue;
1377 }
1378
1379 if (strcmp (name, "scuport") == 0)
1380 {
1381 p -> configSwBootloadPort = (word3) v;
1382 continue;
1383 }
1384
1385 if (strcmp (name, "port") == 0)
1386 {
1387 port_num = (uint) v;
1388 continue;
1389 }
1390
1391 if (strcmp (name, "addr") == 0)
1392 {
1393 p -> configSwPortAddress[port_num] = (uint) v;
1394 continue;
1395 }
1396
1397 if (strcmp (name, "interlace") == 0)
1398 {
1399 p -> configSwPortInterface[port_num] = (uint) v;
1400 continue;
1401 }
1402
1403 if (strcmp (name, "enable") == 0)
1404 {
1405 p -> configSwPortEnable[port_num] = (uint) v;
1406 continue;
1407 }
1408
1409 if (strcmp (name, "initenable") == 0)
1410 {
1411 p -> configSwPortSysinitEnable[port_num] = (uint) v;
1412 continue;
1413 }
1414
1415 if (strcmp (name, "halfsize") == 0)
1416 {
1417 p -> configSwPortHalfsize[port_num] = (uint) v;
1418 continue;
1419 }
1420
1421 if (strcmp (name, "store_size") == 0)
1422 {
1423 p -> configSwPortStoresize[port_num] = (uint) v;
1424 continue;
1425 }
1426
1427 if (strcmp (name, "usemap") == 0)
1428 {
1429 p -> useMap = v != 0;
1430 continue;
1431 }
1432
1433 sim_printf ("error: %s: Invalid cfg_parse rc <%ld>\r\n", __func__, (long) rc);
1434 cfg_parse_done (& cfg_state);
1435 return SCPE_ARG;
1436 }
1437 cfg_parse_done (& cfg_state);
1438 return SCPE_OK;
1439 }
1440
1441 static t_stat iom_reset_unit (UNIT * uptr, UNUSED int32 value, UNUSED const char * cptr,
1442 UNUSED void * desc)
1443 {
1444 uint iom_unit_idx = (uint) (uptr - iom_unit);
1445 iom_unit_reset_idx (iom_unit_idx);
1446 return SCPE_OK;
1447 }
1448
1449 static MTAB iom_mod[] =
1450 {
1451 {
1452 MTAB_XTD | MTAB_VUN | \
1453 MTAB_NMO | MTAB_NC,
1454 0,
1455 "MBX",
1456 NULL,
1457 NULL,
1458 iom_show_mbx,
1459 NULL,
1460 NULL
1461 },
1462 {
1463 MTAB_XTD | MTAB_VUN | \
1464 MTAB_NMO | MTAB_VALR,
1465 0,
1466 "CONFIG",
1467 "CONFIG",
1468 iom_set_config,
1469 iom_show_config,
1470 NULL,
1471 NULL
1472 },
1473 {
1474 MTAB_XTD | MTAB_VUN | \
1475 MTAB_NMO | MTAB_VALR,
1476 0,
1477 (char *) "RESET",
1478 (char *) "RESET",
1479 iom_reset_unit,
1480 NULL,
1481 (char *) "reset IOM unit",
1482 NULL
1483 },
1484 {
1485 MTAB_XTD | MTAB_VDV | \
1486 MTAB_NMO | MTAB_VALR,
1487 0,
1488 "NUNITS",
1489 "NUNITS",
1490 iom_set_units,
1491 iom_show_units,
1492 "Number of IOM units in the system",
1493 NULL
1494 },
1495 {
1496 0, 0, NULL, NULL, 0, 0, NULL, NULL
1497 }
1498 };
1499
1500 static DEBTAB iom_dt[] =
1501 {
1502 { "NOTIFY", DBG_NOTIFY, NULL },
1503 { "INFO", DBG_INFO, NULL },
1504 { "ERR", DBG_ERR, NULL },
1505 { "WARN", DBG_WARN, NULL },
1506 { "DEBUG", DBG_DEBUG, NULL },
1507 { "TRACE", DBG_TRACE, NULL },
1508 { "ALL", DBG_ALL, NULL },
1509 { NULL, 0, NULL }
1510 };
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522 t_stat iom_unit_reset_idx (uint iom_unit_idx)
1523 {
1524 if (iom_unit_idx < N_IOM_UNITS_MAX)
1525 iom_build_addr_map (iom_unit_idx);
1526 return SCPE_OK;
1527 }
1528
1529 static t_stat iom_reset (UNUSED DEVICE * dptr)
1530 {
1531
1532
1533 for (uint iom_unit_idx = 0; iom_unit_idx < iom_dev.numunits; iom_unit_idx ++)
1534 {
1535 iom_unit_reset_idx (iom_unit_idx);
1536 }
1537 return SCPE_OK;
1538 }
1539
1540 static t_stat boot_svc (UNIT * unitp);
1541 static UNIT boot_channel_unit[N_IOM_UNITS_MAX] = {
1542 #if defined(NO_C_ELLIPSIS)
1543 { UDATA (& boot_svc, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1544 { UDATA (& boot_svc, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1545 { UDATA (& boot_svc, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1546 { UDATA (& boot_svc, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL }
1547 #else
1548 [0 ... N_IOM_UNITS_MAX - 1] = {
1549 UDATA (& boot_svc, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL
1550 }
1551 #endif
1552 };
1553
1554
1555
1556
1557
1558 static void iom_boot_store (uint iom_unit_idx, word24 addr, word36 data)
1559 {
1560 uint real = iom_map_addr (iom_unit_idx, addr);
1561 M[real] = data;
1562 iom_cache_purge ((word24) real);
1563 }
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579 static void init_memory_iom (uint iom_unit_idx)
1580 {
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593 word12 base = iom_unit_data[iom_unit_idx].configSwIomBaseAddress;
1594
1595
1596
1597
1598
1599 word36 pi_base = (((word36) iom_unit_data[iom_unit_idx].configSwMultiplexBaseAddress) << 3) |
1600 (((word36) (iom_unit_data[iom_unit_idx].configSwIomBaseAddress & 07700U)) << 6) ;
1601 word3 iom_num = ((word36) iom_unit_data[iom_unit_idx].configSwMultiplexBaseAddress) & 3;
1602 word36 cmd = 5;
1603 word36 dev = 0;
1604
1605
1606 word36 imu = iom_unit_data[iom_unit_idx].config_sw_model == CONFIG_SW_MODEL_IMU ? 1 : 0;
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617 enum config_sw_bootload_device_e bootdev = iom_unit_data[iom_unit_idx].configSwBootloadCardTape;
1618
1619 word6 bootchan;
1620 if (bootdev == CONFIG_SW_BLCT_CARD)
1621 bootchan = iom_unit_data[iom_unit_idx].configSwBootloadCardrdrChan;
1622 else
1623 bootchan = iom_unit_data[iom_unit_idx].configSwBootloadMagtapeChan;
1624
1625
1626
1627
1628
1629 word36 dis0 = 0616200;
1630
1631 iom_boot_store (iom_unit_idx, 010 + 2 * iom_num + 0, (imu << 34) | dis0);
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643 iom_boot_store (iom_unit_idx, 010 + 2 * iom_num + 1, 0);
1644
1645
1646
1647
1648 iom_boot_store (iom_unit_idx, 030 + 2 * iom_num, dis0);
1649
1650
1651
1652
1653
1654 word24 base_addr = (word24) base << 6;
1655 iom_boot_store (iom_unit_idx, base_addr + 7, ((word36) base_addr << 18) | 02000002);
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665 iom_boot_store (iom_unit_idx, base_addr + 010, 040000);
1666
1667
1668
1669
1670 word24 mbx = base_addr + 4u * bootchan;
1671 iom_boot_store (iom_unit_idx, mbx, 03020003);
1672
1673
1674
1675
1676 iom_boot_store (iom_unit_idx, 4, 030 << 18);
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687 iom_boot_store (iom_unit_idx, mbx + 2, ((word36)base_addr << 18));
1688
1689
1690
1691
1692 iom_boot_store (iom_unit_idx, 0, 0720201);
1693
1694
1695
1696
1697
1698 word3 port = iom_unit_data[iom_unit_idx].configSwBootloadPort;
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721 iom_boot_store (iom_unit_idx, 1, ((word36) (bootchan) << 27) | port);
1722
1723
1724
1725
1726 iom_boot_store (iom_unit_idx, 2, ((word36) base_addr << 18) | (pi_base) | iom_num);
1727
1728
1729
1730
1731 iom_boot_store (iom_unit_idx, 3, (cmd << 30) | (dev << 24) | 0700000);
1732 }
1733
1734 static t_stat boot_svc (UNIT * unitp)
1735 {
1736 uint iom_unit_idx = (uint) (unitp - boot_channel_unit);
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748 for (int port_num = 0; port_num < N_SCU_PORTS; port_num ++)
1749 {
1750 if (! cables->iom_to_scu[iom_unit_idx][port_num].in_use)
1751 continue;
1752 uint scu_unit_idx = cables->iom_to_scu[iom_unit_idx][port_num].scu_unit_idx;
1753 scu_unit_reset ((int) scu_unit_idx);
1754 }
1755
1756
1757 init_memory_iom (iom_unit_idx);
1758
1759
1760 startRemoteConsole ();
1761
1762
1763 startFNPListener ();
1764
1765
1766
1767 if (! cables->iom_to_scu[iom_unit_idx][0].in_use)
1768 {
1769 sim_warn ("boot iom can't find a SCU\r\n");
1770 return SCPE_ARG;
1771 }
1772 uint scu_unit_idx = cables->iom_to_scu[iom_unit_idx][0].scu_unit_idx;
1773 iom_interrupt (scu_unit_idx, iom_unit_idx);
1774
1775
1776
1777
1778 return SCPE_OK;
1779 }
1780
1781 static t_stat iom_boot (int unitNum, UNUSED DEVICE * dptr)
1782 {
1783 if (unitNum < 0 || unitNum >= (int) iom_dev.numunits)
1784 {
1785 sim_printf ("%s: Invalid unit number %d\r\n", __func__, unitNum);
1786 return SCPE_ARG;
1787 }
1788
1789 boot_svc (& boot_channel_unit[unitNum]);
1790 return SCPE_OK;
1791 }
1792
1793 DEVICE iom_dev =
1794 {
1795 "IOM",
1796 iom_unit,
1797 NULL,
1798 iom_mod,
1799 N_IOM_UNITS,
1800 10,
1801 8,
1802 1,
1803 8,
1804 8,
1805 NULL,
1806 NULL,
1807 iom_reset,
1808 iom_boot,
1809 NULL,
1810 NULL,
1811 NULL,
1812 DEV_DEBUG,
1813 0,
1814 iom_dt,
1815 NULL,
1816 NULL,
1817 NULL,
1818 NULL,
1819 NULL,
1820 NULL,
1821 NULL
1822 };
1823
1824 static uint mbxLoc (uint iom_unit_idx, uint chan)
1825 {
1826
1827
1828 word12 base = iom_unit_data[iom_unit_idx].configSwIomBaseAddress;
1829 word24 base_addr = ((word24) base) << 6;
1830 word24 mbx = base_addr + 4 * chan;
1831
1832
1833 return mbx;
1834 }
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910 static int status_service (uint iom_unit_idx, uint chan, bool marker)
1911 {
1912 #if defined(TESTING)
1913 cpu_state_t * cpup = _cpup;
1914 #endif
1915 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
1916
1917
1918
1919
1920 word36 word1, word2;
1921 word1 = 0;
1922 putbits36_12 (& word1, 0, p -> stati);
1923
1924
1925
1926 putbits36_1 (& word1, 13, marker ? 1 : 0);
1927 putbits36_2 (& word1, 14, 0);
1928 putbits36_1 (& word1, 16, p -> initiate ? 1 : 0);
1929 putbits36_1 (& word1, 17, 0);
1930 putbits36_3 (& word1, 18, (word3) p -> chanStatus);
1931
1932 putbits36_3 (& word1, 21, 0);
1933
1934
1935
1936
1937 putbits36_6 (& word1, 30, p -> recordResidue);
1938
1939 word2 = 0;
1940
1941
1942
1943
1944
1945 putbits36_3 (& word2, 18, p -> charPos);
1946 putbits36_1 (& word2, 21, p -> isRead ? 1 : 0);
1947 putbits36_12 (& word2, 24, p -> tallyResidue);
1948
1949
1950
1951
1952
1953
1954 uint chanloc = mbxLoc (iom_unit_idx, chan);
1955 word24 scwAddr = chanloc + IOM_MBX_SCW;
1956 word36 scw;
1957 iom_core_read_lock (iom_unit_idx, scwAddr, & scw, __func__);
1958 word18 addr = getbits36_18 (scw, 0);
1959 uint lq = getbits36_2 (scw, 18);
1960 uint tally = getbits36_12 (scw, 24);
1961
1962 sim_debug (DBG_DEBUG, & iom_dev, "%s: Status: 0%012"PRIo64" 0%012"PRIo64"\r\n",
1963 __func__, word1, word2);
1964 if (lq == 3)
1965 {
1966 sim_debug (DBG_WARN, &iom_dev,
1967 "%s: SCW for channel %d has illegal LQ\r\n",
1968 __func__, chan);
1969 lq = 0;
1970 }
1971 iom_core_write2 (iom_unit_idx, addr, word1, word2, __func__);
1972
1973
1974 if (tally > 0 || (tally == 0 && lq != 0))
1975 {
1976 switch (lq)
1977 {
1978 case 0:
1979
1980 if (tally != 0)
1981 {
1982 tally --;
1983 addr += 2;
1984 }
1985 break;
1986
1987 case 1:
1988
1989 if (tally % 8 == 1 )
1990 addr -= 8;
1991 else
1992 addr += 2;
1993 tally --;
1994 break;
1995
1996 case 2:
1997
1998 if (tally % 32 == 1 )
1999 addr -= 32;
2000 else
2001 addr += 2;
2002 tally --;
2003 break;
2004 }
2005
2006
2007 if (tally & ~07777U)
2008 {
2009 sim_debug (DBG_WARN, & iom_dev,
2010 "%s: Tally SCW address 0%o under/over flow\r\n",
2011 __func__, tally);
2012 tally &= 07777;
2013 }
2014
2015 putbits36_12 (& scw, 24, (word12) tally);
2016 putbits36_18 (& scw, 0, addr);
2017 }
2018
2019 iom_core_write_unlock (iom_unit_idx, scwAddr, scw, __func__);
2020
2021
2022 return 0;
2023 }
2024
2025 static word24 UNUSED build_AUXPTW_address (uint iom_unit_idx, int chan)
2026 {
2027
2028
2029
2030
2031
2032
2033
2034
2035 word12 IOMBaseAddress = iom_unit_data[iom_unit_idx].configSwIomBaseAddress;
2036 word24 addr = (((word24) IOMBaseAddress) & MASK12) << 6;
2037 addr |= ((uint) chan & MASK6) << 2;
2038 addr |= 03;
2039 return addr;
2040 }
2041
2042 static word24 build_DDSPTW_address (word18 PCW_PAGE_TABLE_PTR, word8 pageNumber)
2043 {
2044
2045
2046
2047
2048
2049
2050
2051
2052 if (PCW_PAGE_TABLE_PTR & 3)
2053 sim_warn ("%s: pcw_ptp %#o page_no %#o\r\n", __func__, PCW_PAGE_TABLE_PTR, pageNumber);
2054 word24 addr = (((word24) PCW_PAGE_TABLE_PTR) & MASK18) << 6;
2055 addr |= pageNumber;
2056 return addr;
2057 }
2058
2059
2060
2061 static void fetch_DDSPTW (uint iom_unit_idx, int chan, word18 addr)
2062 {
2063 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2064 word24 pgte = build_DDSPTW_address (p -> PCW_PAGE_TABLE_PTR,
2065 (addr >> 10) & MASK8);
2066 iom_core_read (iom_unit_idx, pgte, (word36 *) & p -> PTW_DCW, __func__);
2067 if ((p -> PTW_DCW & 0740000777747) != 04llu)
2068 sim_warn ("%s: chan %ld addr %#llo pgte %08llo ptw %012llo\r\n",
2069 __func__, (long)chan, (unsigned long long)addr,
2070 (unsigned long long)pgte, (unsigned long long)p -> PTW_DCW);
2071 }
2072
2073 static word24 build_IDSPTW_address (word18 PCW_PAGE_TABLE_PTR, word1 seg, word8 pageNumber)
2074 {
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090 word24 addr = (((word24) PCW_PAGE_TABLE_PTR) & MASK18) << 6;
2091 addr += (((word24) seg) & 01) << 8;
2092 addr += pageNumber;
2093 return addr;
2094 }
2095
2096
2097
2098 static void fetch_IDSPTW (uint iom_unit_idx, int chan, word18 addr)
2099 {
2100 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2101 word24 pgte = build_IDSPTW_address (p -> PCW_PAGE_TABLE_PTR,
2102 p -> SEG,
2103 (addr >> 10) & MASK8);
2104 iom_core_read (iom_unit_idx, pgte, (word36 *) & p -> PTW_DCW, __func__);
2105 if ((p -> PTW_DCW & 0740000777747) != 04llu)
2106 sim_warn ("%s: chan %d addr %#o ptw %012llo\r\n",
2107 __func__, chan, addr, (unsigned long long)p -> PTW_DCW);
2108 }
2109
2110 static word24 build_LPWPTW_address (word18 PCW_PAGE_TABLE_PTR, word1 seg, word8 pageNumber)
2111 {
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127 word24 addr = (((word24) PCW_PAGE_TABLE_PTR) & MASK18) << 6;
2128 addr += (((word24) seg) & 01) << 8;
2129 addr += pageNumber;
2130 return addr;
2131 }
2132
2133 static void fetch_LPWPTW (uint iom_unit_idx, uint chan)
2134 {
2135 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2136 word24 addr = build_LPWPTW_address (p -> PCW_PAGE_TABLE_PTR,
2137 p -> SEG,
2138 (p -> LPW_DCW_PTR >> 10) & MASK8);
2139 iom_core_read (iom_unit_idx, addr, (word36 *) & p -> PTW_LPW, __func__);
2140 if ((p -> PTW_LPW & 0740000777747) != 04llu)
2141 sim_warn ("%s: chan %d addr %#o ptw %012llo\r\n",
2142 __func__, chan, addr, (unsigned long long)p -> PTW_LPW);
2143 }
2144
2145
2146
2147
2148 void iom_direct_data_service (uint iom_unit_idx, uint chan, word24 daddr, word36 * data,
2149 iom_direct_data_service_op op)
2150 {
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2164
2165 if (p -> masked)
2166 return;
2167
2168 if (p -> PCW_63_PTP && p -> PCW_64_PGE)
2169 {
2170 fetch_DDSPTW (iom_unit_idx, (int) chan, daddr);
2171 daddr = ((uint) getbits36_14 (p -> PTW_DCW, 4) << 10) | (daddr & MASK10);
2172 }
2173
2174 if (op == direct_store)
2175 iom_core_write (iom_unit_idx, daddr, * data, __func__);
2176 else if (op == direct_load)
2177 iom_core_read (iom_unit_idx, daddr, data, __func__);
2178 else if (op == direct_read_clear)
2179 {
2180 iom_core_read_lock (iom_unit_idx, daddr, data, __func__);
2181 iom_core_write_unlock (iom_unit_idx, daddr, 0, __func__);
2182 }
2183 }
2184
2185
2186
2187
2188
2189
2190 void iom_indirect_data_service (uint iom_unit_idx, uint chan, word36 * data, uint * cnt, bool write) {
2191 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2192
2193 if (p->masked)
2194 return;
2195
2196
2197
2198 p->initiate = false;
2199
2200 uint tally = p->DDCW_TALLY;
2201 uint daddr = p->DDCW_ADDR;
2202 if (tally == 0) {
2203 tally = 4096;
2204 }
2205 p->tallyResidue = (word12) tally;
2206
2207 if (write) {
2208 uint c = * cnt;
2209 while (p->tallyResidue) {
2210 if (c == 0)
2211 break;
2212
2213 if (! IS_IONTP (p)) {
2214 if (p->PCW_63_PTP && p->PCW_64_PGE) {
2215 fetch_IDSPTW (iom_unit_idx, (int) chan, daddr);
2216 word24 addr = ((word24) (getbits36_14 (p -> PTW_DCW, 4) << 10)) | (daddr & MASK10);
2217 iom_core_write (iom_unit_idx, addr, * data, __func__);
2218 } else {
2219 if (daddr > MASK18) {
2220 sim_warn ("%s 256K ovf\r\n", __func__);
2221 daddr &= MASK18;
2222 }
2223
2224
2225
2226 uint daddr2 = daddr | (uint) p->ADDR_EXT << 18;
2227 iom_core_write (iom_unit_idx, daddr2, * data, __func__);
2228 }
2229 }
2230 daddr ++;
2231 data ++;
2232 p->tallyResidue --;
2233 c --;
2234 }
2235 } else {
2236 uint c = 0;
2237 while (p -> tallyResidue) {
2238 if (IS_IONTP (p)) {
2239 * data = 0;
2240 } else {
2241 if (p -> PCW_63_PTP && p -> PCW_64_PGE) {
2242 fetch_IDSPTW (iom_unit_idx, (int) chan, daddr);
2243 word24 addr = ((word24) (getbits36_14 (p -> PTW_DCW, 4) << 10)) | (daddr & MASK10);
2244 iom_core_read (iom_unit_idx, addr, data, __func__);
2245 } else {
2246
2247 if (daddr > MASK18) {
2248 sim_warn ("%s 256K ovf\r\n", __func__);
2249 daddr &= MASK18;
2250 }
2251
2252
2253
2254 uint daddr2 = daddr | (uint) p -> ADDR_EXT << 18;
2255 iom_core_read (iom_unit_idx, daddr2, data, __func__);
2256 }
2257 }
2258 daddr ++;
2259 p->tallyResidue --;
2260 data ++;
2261 c ++;
2262 }
2263 * cnt = c;
2264 }
2265 }
2266
2267
2268
2269
2270
2271 static int tdcw_chan_mode (int mode, word1 pdta, word1 pdcw, word1 rel)
2272 {
2273 switch (mode)
2274 {
2275 case cm1:
2276 if (pdta)
2277 {
2278 mode = cm2;
2279 break;
2280 }
2281 if (pdcw)
2282 if (rel)
2283 mode = cm4;
2284 else
2285 mode = cm3b;
2286 else
2287 if (rel)
2288 mode = cm3a;
2289 else
2290 mode = cm2;
2291 break;
2292
2293 case cm2:
2294 if (pdcw)
2295 if (rel)
2296 mode = cm4;
2297 else
2298 mode = cm3b;
2299 else
2300 if (rel)
2301 mode = cm3a;
2302 else
2303 mode = cm2;
2304 break;
2305
2306 case cm3a:
2307 if (pdcw)
2308 mode = cm4;
2309 break;
2310
2311 case cm3b:
2312 if (rel)
2313 mode = cm4;
2314 break;
2315
2316 case cm4:
2317 mode = cm5;
2318 break;
2319
2320 case cm5:
2321 break;
2322
2323 case cm1e:
2324 {
2325 if (pdcw)
2326 mode = cm2e;
2327 }
2328 break;
2329
2330 case cm2e:
2331 break;
2332 }
2333 return mode;
2334 }
2335
2336 static void update_chan_mode (uint iom_unit_idx, uint chan, bool tdcw)
2337 {
2338 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2339 if (chan == IOM_CONNECT_CHAN)
2340 {
2341 p -> chanMode = cm1;
2342 return;
2343 }
2344
2345 if (! tdcw)
2346 {
2347 if (p -> PCW_64_PGE == 0)
2348 {
2349 if (p -> LPW_20_AE == 0)
2350 {
2351 p -> chanMode = cm1e;
2352 }
2353 else
2354 {
2355 p -> chanMode = cm2e;
2356 }
2357
2358 }
2359 else
2360 {
2361 if (p -> LPW_20_AE == 0)
2362 {
2363 if (p -> LPW_23_REL == 0)
2364 {
2365 p -> chanMode = cm1;
2366 }
2367 else
2368 {
2369 p -> chanMode = cm3a;
2370 }
2371
2372 }
2373 else
2374 {
2375 if (p -> LPW_23_REL == 0)
2376 {
2377 p -> chanMode = cm3b;
2378 }
2379 else
2380 {
2381 p -> chanMode = cm4;
2382 }
2383
2384 }
2385 }
2386 }
2387 else
2388 {
2389 p -> chanMode = tdcw_chan_mode (p -> chanMode, p -> TDCW_32_PDTA,
2390 p -> TDCW_33_PDCW, p -> TDCW_35_REL);
2391 }
2392 }
2393
2394 static void write_LPW (uint iom_unit_idx, uint chan)
2395 {
2396 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2397
2398 uint chanLoc = mbxLoc (iom_unit_idx, chan);
2399 iom_core_write (iom_unit_idx, chanLoc + IOM_MBX_LPW, p -> LPW, __func__);
2400
2401
2402
2403 if (chan != IOM_CONNECT_CHAN)
2404 {
2405 iom_core_write (iom_unit_idx, chanLoc + IOM_MBX_LPWX, p -> LPWX, __func__);
2406 }
2407 }
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421 void iom_advance_lpw (uint iom_unit_idx, uint chan)
2422 {
2423 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2424 p -> LPW_DCW_PTR = (p -> LPW_DCW_PTR + 1u) & MASK18;
2425 putbits36_18 ((word36 *) & p -> LPW, 0, p -> LPW_DCW_PTR);
2426 write_LPW (iom_unit_idx, chan);
2427 }
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461 int iom_continue_channel (uint iom_unit_idx, uint chan)
2462 {
2463 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2464 struct iom_to_ctlr_s * d = & cables->iom_to_ctlr[iom_unit_idx][chan];
2465
2466 if ((! d->in_use) || (! d->iom_cmd))
2467 {
2468 sim_warn ("%s: channel %d not in use\r\n", __func__, chan);
2469 return -1;
2470 }
2471
2472
2473
2474 bool ptro, send, uff;
2475 int rc = iom_list_service (iom_unit_idx, chan, & ptro, & send, & uff);
2476 if (rc < 0)
2477 {
2478 sim_warn ("%s: list service failed for channel %d\r\n", __func__, chan);
2479 return -2;
2480 }
2481
2482
2483
2484
2485
2486
2487
2488 if (uff)
2489 {
2490 sim_warn ("%s: iom_list_service returned uff=%o for channel %d (proceeding)\r\n",
2491 __func__, uff, chan);
2492 }
2493
2494 if (! send)
2495 {
2496 sim_warn ("%s: iom_list_service returned send=%o for channel %d\r\n", __func__, send, chan);
2497 return -4;
2498 }
2499
2500
2501
2502
2503 if (! IS_IDCW (p))
2504 {
2505 sim_warn ("%s: expected IDCW, got non-IDCW for channel %d\r\n",
2506 __func__, chan);
2507 return -5;
2508 }
2509
2510
2511 p -> isPCW = false;
2512 p -> tallyResidue = 0;
2513 p -> isRead = true;
2514 p -> charPos = 0;
2515 p -> chanStatus = chanStatNormal;
2516
2517
2518
2519
2520
2521 int rc2 = d->iom_cmd (iom_unit_idx, chan);
2522
2523 if (rc2 < 0)
2524 {
2525 sim_warn ("%s: iom_cmd failed for channel %d\r\n", __func__, chan);
2526
2527 return -6;
2528 }
2529
2530 if (rc2 == IOM_CMD_DISCONNECT)
2531 {
2532
2533 return -7;
2534 }
2535
2536
2537
2538 send_marker_interrupt (iom_unit_idx, (int) chan);
2539 return 0;
2540 }
2541
2542 #if defined(TESTING)
2543 void dumpDCW (word36 DCW, word1 LPW_23_REL) {
2544 static char * charCtrls[4] =
2545 { "terminate", "undefined", "proceed", "marker" };
2546 static char * chanCmds[16] =
2547 { "record", "undefined", "nondata", "undefined",
2548 "undefined", "undefined", "multirecord", "undefined",
2549 "character", "undefined", "undefined", "undefined",
2550 "undefined", "undefined", "undefined", "undefined"
2551 };
2552 word3 DCW_18_20_CP = getbits36_3 (DCW, 18);
2553
2554 if (DCW_18_20_CP == 07) {
2555 word6 IDCW_DEV_CMD = getbits36_6 (DCW, 0);
2556 word6 IDCW_DEV_CODE = getbits36_6 (DCW, 6);
2557
2558
2559
2560
2561
2562
2563 word2 IDCW_CHAN_CTRL = getbits36_2 (DCW, 22);
2564 word6 IDCW_CHAN_CMD = getbits36_6 (DCW, 24);
2565 word6 IDCW_COUNT = getbits36_6 (DCW, 30);
2566 sim_printf ("// IDCW %012llo\r\n", DCW);
2567 sim_printf ("// cmd %02o %s\r\n", IDCW_DEV_CMD, cmdNames[IDCW_DEV_CMD]);
2568 sim_printf ("// dev code %02o\r\n", IDCW_DEV_CODE);
2569 sim_printf ("// ctrl %o (%s)\r\n", IDCW_CHAN_CTRL, charCtrls[IDCW_CHAN_CTRL]);
2570 sim_printf ("// chancmd %o (%s)\r\n", IDCW_CHAN_CMD, IDCW_CHAN_CMD < 16 ? chanCmds[IDCW_CHAN_CMD] : "unknown");
2571 sim_printf ("// count %o\r\n", IDCW_COUNT);
2572 } else {
2573 word18 TDCW_DATA_ADDRESS = getbits36_18 (DCW, 0);
2574 word1 TDCW_31_SEG = getbits36_1 (DCW, 31);
2575 word1 TDCW_32_PDTA = getbits36_1 (DCW, 32);
2576 word1 TDCW_33_PDCW = getbits36_1 (DCW, 33);
2577 word1 TDCW_33_EC = getbits36_1 (DCW, 33);
2578 word1 TDCW_34_RES = getbits36_1 (DCW, 34);
2579 word1 TDCW_35_REL = getbits36_1 (DCW, 35);
2580
2581 word12 DDCW_TALLY = getbits36_12 (DCW, 24);
2582 word18 DDCW_ADDR = getbits36_18 (DCW, 0);
2583 word2 DDCW_22_23_TYPE = getbits36_2 (DCW, 22);
2584 static char * types[4] = { "IOTD", "IOTP", "TDCW", "IONTP" };
2585 if (DDCW_22_23_TYPE == 2) {
2586 sim_printf ("// TDCW (2) %012llo\r\n", DCW);
2587 sim_printf ("// dcw ptr %06o\r\n", TDCW_DATA_ADDRESS);
2588 sim_printf ("// seg %o\r\n", TDCW_31_SEG);
2589 sim_printf ("// pdta %o\r\n", TDCW_32_PDTA);
2590 sim_printf ("// pdcw %o\r\n", TDCW_33_PDCW);
2591 sim_printf ("// ec %o\r\n", TDCW_33_EC);
2592 sim_printf ("// res %o\r\n", TDCW_34_RES);
2593 sim_printf ("// rel %o\r\n", TDCW_35_REL);
2594 } else {
2595 sim_printf ("// %s (%o) %012llo\r\n", types[DDCW_22_23_TYPE], DDCW_22_23_TYPE, DCW);
2596 sim_printf ("// tally %04o\r\n", DDCW_TALLY);
2597 sim_printf ("// addr %02o\r\n", DDCW_ADDR);
2598 sim_printf ("// cp %o\r\n", getbits36_3 (DCW, 18));
2599 }
2600 }
2601 }
2602
2603 static void dumpLPW (uint iom_unit_idx, uint chan) {
2604 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2605 char updateCase;
2606 if (p->LPW_21_NC)
2607 updateCase = 'c';
2608 else if (p->LPW_22_TAL)
2609 updateCase = 'b';
2610 else
2611 updateCase = 'a';
2612 static char * chanName[64] = {
2613 "0.",
2614 "1.",
2615 "Connect",
2616 "3.",
2617 "4.",
2618 "5.",
2619 "6.",
2620 "7.",
2621 "8.",
2622 "9.",
2623 "MTP Tape",
2624 "IPC Disk",
2625 "MPC Disk",
2626 "Card reader",
2627 "Card punch",
2628 "Printer",
2629 "FNP",
2630 "FNP",
2631 "FNP",
2632 "FNP",
2633 "FNP",
2634 "FNP",
2635 "FNP",
2636 "FNP",
2637 "24.",
2638 "25.",
2639 "ABSI",
2640 "27.",
2641 "28.",
2642 "29.",
2643 "Console",
2644 "31.",
2645 "Socket",
2646 "Socket",
2647 "Socket",
2648 "Socket",
2649 "Socket",
2650 "Socket",
2651 "Socket",
2652 "39.",
2653 "40.",
2654 "41.",
2655 "42.",
2656 "43.",
2657 "44.",
2658 "45.",
2659 "46.",
2660 "47.",
2661 "48.",
2662 "49.",
2663 "50.",
2664 "51.",
2665 "52.",
2666 "53.",
2667 "54.",
2668 "55.",
2669 "56.",
2670 "57.",
2671 "58.",
2672 "59.",
2673 "60.",
2674 "61.",
2675 "62.",
2676 "63."
2677 };
2678 sim_printf ("// %s channel LPW %012llo (case %c)\r\n", chanName[chan], p->LPW, updateCase);
2679 sim_printf ("// DCW pointer %06o\r\n", p->LPW_DCW_PTR);
2680 sim_printf ("// RES %o\r\n", p->LPW_18_RES);
2681 sim_printf ("// REL %o\r\n", p->LPW_19_REL);
2682 sim_printf ("// AE %o\r\n", p->LPW_20_AE);
2683 sim_printf ("// NC 21 %o\r\n", p->LPW_21_NC);
2684 sim_printf ("// TAL 22 %o\r\n", p->LPW_22_TAL);
2685 sim_printf ("// REL %o\r\n", p->LPW_23_REL);
2686 sim_printf ("// TALLY %04o\r\n", p->LPW_TALLY);
2687 sim_printf ("// \r\n");
2688 }
2689 #endif
2690
2691 static void fetch_and_parse_LPW (uint iom_unit_idx, uint chan)
2692 {
2693 #if defined(TESTING)
2694 cpu_state_t * cpup = _cpup;
2695 #endif
2696 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2697 uint chanLoc = mbxLoc (iom_unit_idx, chan);
2698
2699 iom_core_read (iom_unit_idx, chanLoc + IOM_MBX_LPW, (word36 *) & p -> LPW, __func__);
2700 sim_debug (DBG_DEBUG, & iom_dev,
2701 "%s: lpw %08o %012"PRIo64"\r\n", __func__, chanLoc + IOM_MBX_LPW, p->LPW);
2702
2703 p -> LPW_DCW_PTR = getbits36_18 (p -> LPW, 0);
2704 p -> LPW_18_RES = getbits36_1 (p -> LPW, 18);
2705 p -> LPW_19_REL = getbits36_1 (p -> LPW, 19);
2706 p -> LPW_20_AE = getbits36_1 (p -> LPW, 20);
2707 p -> LPW_21_NC = getbits36_1 (p -> LPW, 21);
2708 p -> LPW_22_TAL = getbits36_1 (p -> LPW, 22);
2709 p -> LPW_23_REL = getbits36_1 (p -> LPW, 23);
2710 p -> LPW_TALLY = getbits36_12 (p -> LPW, 24);
2711
2712 if (chan == IOM_CONNECT_CHAN)
2713 {
2714 p -> LPWX = 0;
2715 p -> LPWX_BOUND = 0;
2716 p -> LPWX_SIZE = 0;
2717 }
2718 else
2719 {
2720 iom_core_read (iom_unit_idx, chanLoc + IOM_MBX_LPWX, (word36 *) & p -> LPWX, __func__);
2721 p -> LPWX_BOUND = getbits36_18 (p -> LPWX, 0);
2722 p -> LPWX_SIZE = getbits36_18 (p -> LPWX, 18);
2723 }
2724 update_chan_mode (iom_unit_idx, chan, false);
2725 }
2726
2727 static void unpack_DCW (uint iom_unit_idx, uint chan)
2728 {
2729 #if defined(TESTING)
2730 cpu_state_t * cpup = _cpup;
2731 #endif
2732 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2733 p -> DCW_18_20_CP = getbits36_3 (p -> DCW, 18);
2734
2735 if (IS_IDCW (p))
2736 {
2737 p -> IDCW_DEV_CMD = getbits36_6 (p -> DCW, 0);
2738 p -> IDCW_DEV_CODE = getbits36_6 (p -> DCW, 6);
2739 p -> IDCW_AE = getbits36_6 (p -> DCW, 12);
2740 if (p -> LPW_23_REL)
2741 p -> IDCW_EC = 0;
2742 else
2743 p -> IDCW_EC = getbits36_1 (p -> DCW, 21);
2744 if (p -> IDCW_EC)
2745 p -> SEG = 1;
2746 p -> IDCW_CHAN_CTRL = getbits36_2 (p -> DCW, 22);
2747 p -> IDCW_CHAN_CMD = getbits36_6 (p -> DCW, 24);
2748 p -> IDCW_COUNT = getbits36_6 (p -> DCW, 30);
2749 p->recordResidue = p->IDCW_COUNT;
2750 #if defined(TESTING)
2751 sim_debug (DBG_DEBUG, & iom_dev,
2752 "%s: IDCW %012llo cmd %02o (%s) dev %02o ctrl %o chancmd %o\r\n",
2753 __func__, p->DCW, p->IDCW_DEV_CMD, cmdNames[p->IDCW_DEV_CMD],
2754 p->IDCW_DEV_CODE, p->IDCW_CHAN_CTRL, p->IDCW_CHAN_CMD);
2755 #endif
2756 }
2757 else
2758 {
2759 p -> TDCW_DATA_ADDRESS = getbits36_18 (p -> DCW, 0);
2760 p -> TDCW_31_SEG = getbits36_1 (p -> DCW, 31);
2761 p -> TDCW_32_PDTA = getbits36_1 (p -> DCW, 32);
2762 p -> TDCW_33_PDCW = getbits36_1 (p -> DCW, 33);
2763 p -> TDCW_33_EC = getbits36_1 (p -> DCW, 33);
2764 p -> TDCW_34_RES = getbits36_1 (p -> DCW, 34);
2765 p -> TDCW_35_REL = getbits36_1 (p -> DCW, 35);
2766 p -> DDCW_TALLY = getbits36_12 (p -> DCW, 24);
2767 p -> DDCW_ADDR = getbits36_18 (p -> DCW, 0);
2768 p -> DDCW_22_23_TYPE = getbits36_2 (p -> DCW, 22);
2769 sim_debug (DBG_DEBUG, & iom_dev,
2770 "%s: TDCW/DDCW %012llo tally %04o addr %06o type %o\r\n",
2771 __func__, p->DCW, p->DDCW_TALLY, p->DDCW_ADDR, p->DDCW_22_23_TYPE);
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793 }
2794 }
2795
2796 static void pack_DCW (uint iom_unit_idx, uint chan)
2797 {
2798
2799 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2800 putbits36_3 ((word36 *) & p -> DCW, 18, p -> DCW_18_20_CP);
2801 }
2802
2803 static void pack_LPW (uint iom_unit_idx, uint chan)
2804 {
2805 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2806 putbits36_18 ((word36 *) & p-> LPW, 0, p -> LPW_DCW_PTR);
2807 putbits36_1 ((word36 *) & p-> LPW, 18, p -> LPW_18_RES);
2808 putbits36_1 ((word36 *) & p-> LPW, 19, p -> LPW_19_REL);
2809 putbits36_1 ((word36 *) & p-> LPW, 20, p -> LPW_20_AE);
2810 putbits36_1 ((word36 *) & p-> LPW, 21, p -> LPW_21_NC);
2811 putbits36_1 ((word36 *) & p-> LPW, 22, p -> LPW_22_TAL);
2812 putbits36_1 ((word36 *) & p-> LPW, 23, p -> LPW_23_REL);
2813 putbits36_12 ((word36 *) & p-> LPW, 24, p -> LPW_TALLY);
2814 putbits36_18 ((word36 *) & p-> LPWX, 0, p -> LPWX_BOUND);
2815 putbits36_18 ((word36 *) & p-> LPWX, 18, p -> LPWX_SIZE);
2816 }
2817
2818 static void fetch_and_parse_PCW (uint iom_unit_idx, uint chan)
2819 {
2820 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2821
2822 iom_core_read2 (iom_unit_idx, p -> LPW_DCW_PTR, (word36 *) & p -> PCW0, (word36 *) & p -> PCW1, __func__);
2823 p -> PCW_CHAN = getbits36_6 (p -> PCW1, 3);
2824 p -> PCW_AE = getbits36_6 (p -> PCW0, 12);
2825 p -> PCW_21_MSK = getbits36_1 (p -> PCW0, 21);
2826 p -> PCW_PAGE_TABLE_PTR = getbits36_18 (p -> PCW1, 9);
2827 p -> PCW_63_PTP = getbits36_1 (p -> PCW1, 27);
2828 p -> PCW_64_PGE = getbits36_1 (p -> PCW1, 28);
2829 p -> PCW_65_AUX = getbits36_1 (p -> PCW1, 29);
2830 if (p -> PCW_65_AUX)
2831 sim_warn ("PCW_65_AUX\r\n");
2832 p -> DCW = p -> PCW0;
2833 unpack_DCW (iom_unit_idx, chan);
2834 }
2835
2836 static void fetch_and_parse_DCW (uint iom_unit_idx, uint chan, UNUSED bool read_only)
2837 {
2838 #if defined(TESTING)
2839 cpu_state_t * cpup = _cpup;
2840 #endif
2841 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2842 word24 addr = p -> LPW_DCW_PTR & MASK18;
2843
2844 sim_debug (DBG_DEBUG, & iom_dev, "%s: addr %08o\r\n", __func__, addr);
2845 switch (p -> chanMode)
2846 {
2847
2848 case cm1:
2849 case cm1e:
2850 {
2851 iom_core_read (iom_unit_idx, addr, (word36 *) & p -> DCW, __func__);
2852 }
2853 break;
2854
2855
2856 case cm2e:
2857 {
2858
2859
2860 addr += ((word24) p -> LPWX_BOUND << 1);
2861 iom_core_read (iom_unit_idx, addr, (word36 *) & p -> DCW, __func__);
2862 }
2863 break;
2864
2865 case cm2:
2866 case cm3b:
2867 {
2868 sim_warn ("fetch_and_parse_DCW LPW paged\r\n");
2869 }
2870 break;
2871
2872 case cm3a:
2873 case cm4:
2874 case cm5:
2875 {
2876 fetch_LPWPTW (iom_unit_idx, chan);
2877
2878
2879 word24 addr_ = ((word24) (getbits36_14 (p -> PTW_LPW, 4) << 10)) | ((p -> LPW_DCW_PTR) & MASK10);
2880 iom_core_read (iom_unit_idx, addr_, (word36 *) & p -> DCW, __func__);
2881 }
2882 break;
2883 }
2884 unpack_DCW (iom_unit_idx, chan);
2885
2886 if (IS_IDCW (p))
2887 sim_debug (DBG_DEBUG, & iom_dev,
2888 "%s: chan %d idcw: dev_cmd %#o dev_code %#o ae %#o ec %d control %#o chan_cmd %#o data %#o\r\n",
2889 __func__, p -> PCW_CHAN, p -> IDCW_DEV_CMD, p -> IDCW_DEV_CODE, p -> IDCW_AE,
2890 p -> IDCW_EC, p -> IDCW_CHAN_CTRL, p -> IDCW_CHAN_CMD, p -> IDCW_COUNT);
2891 else
2892 if (p -> DDCW_22_23_TYPE == 02)
2893 sim_debug (DBG_DEBUG, & iom_dev,
2894 "%s: chan %d tdcw: address %#o seg %d pdta %d pdcw/ec %d res %d rel %d\r\n",
2895 __func__, p -> PCW_CHAN, p -> TDCW_DATA_ADDRESS, p -> TDCW_31_SEG,
2896 p -> TDCW_32_PDTA, p -> TDCW_33_PDCW, p -> TDCW_34_RES, p -> TDCW_35_REL);
2897 else
2898 sim_debug (DBG_DEBUG, & iom_dev,
2899 "%s: chan %d ddcw: address %#o char_pos %#o type %#o tally %#o\r\n",
2900 __func__, p -> PCW_CHAN, p -> DDCW_ADDR, p -> DCW_18_20_CP,
2901 p -> DDCW_22_23_TYPE, p -> DDCW_TALLY);
2902 }
2903
2904
2905
2906
2907
2908
2909
2910 static int peek_list_word (uint iom_unit_idx, uint chan, int mode, word18 addr, word36 * data)
2911 {
2912 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2913 switch (mode)
2914 {
2915 case cm1:
2916 case cm1e:
2917 iom_core_read (iom_unit_idx, addr, data, __func__);
2918 return 0;
2919
2920 case cm2e:
2921 iom_core_read (iom_unit_idx, (word24) addr + ((word24) p -> LPWX_BOUND << 1), data, __func__);
2922 return 0;
2923
2924 case cm3a:
2925 case cm4:
2926 case cm5:
2927 {
2928 word36 ptw;
2929 word24 pgte = build_LPWPTW_address (p -> PCW_PAGE_TABLE_PTR, p -> SEG,
2930 (addr >> 10) & MASK8);
2931 iom_core_read (iom_unit_idx, pgte, & ptw, __func__);
2932 if ((ptw & 0740000777747) != 04llu)
2933 return -1;
2934 iom_core_read (iom_unit_idx,
2935 ((word24) (getbits36_14 (ptw, 4) << 10)) | (addr & MASK10),
2936 data, __func__);
2937 return 0;
2938 }
2939
2940 default:
2941 return -1;
2942 }
2943 }
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958 int iom_peek_next_dcw (uint iom_unit_idx, uint chan, word36 * dcw)
2959 {
2960 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
2961 int mode = p -> chanMode;
2962 word18 addr = p -> LPW_DCW_PTR;
2963 word1 res = p -> LPW_18_RES;
2964 word36 w;
2965
2966 if (peek_list_word (iom_unit_idx, chan, mode, addr, & w) != 0)
2967 return -1;
2968 if (getbits36_3 (w, 18) != 07 && getbits36_2 (w, 22) == 02)
2969 {
2970 word1 seg = getbits36_1 (w, 31);
2971 word1 pdta = getbits36_1 (w, 32);
2972 word1 pdcw = getbits36_1 (w, 33);
2973 word1 tres = getbits36_1 (w, 34);
2974 word1 rel = getbits36_1 (w, 35);
2975 res |= tres;
2976 if (seg || (res && pdcw))
2977 return -1;
2978 mode = tdcw_chan_mode (mode, pdta, pdcw, rel);
2979 addr = getbits36_18 (w, 0);
2980 if (peek_list_word (iom_unit_idx, chan, mode, addr, & w) != 0)
2981 return -1;
2982 if (getbits36_3 (w, 18) != 07 && getbits36_2 (w, 22) == 02)
2983 return -1;
2984 }
2985 if (getbits36_3 (w, 18) == 07 && res)
2986 return -1;
2987 * dcw = w;
2988 return 0;
2989 }
2990
2991
2992
2993
2994
2995
2996
2997
2998 int send_general_interrupt (uint iom_unit_idx, uint chan, enum iomImwPics pic)
2999 {
3000 #if defined(TESTING)
3001 cpu_state_t * cpup = _cpup;
3002 #endif
3003 uint imw_addr;
3004 uint chan_group = chan < 32 ? 1 : 0;
3005 uint chan_in_group = chan & 037;
3006
3007 uint iomUnitNum =
3008 iom_unit_data[iom_unit_idx].configSwMultiplexBaseAddress & 3u;
3009 uint interrupt_num = iomUnitNum | (chan_group << 2) | ((uint) pic << 3);
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020 uint pi_base = iom_unit_data[iom_unit_idx].configSwMultiplexBaseAddress & ~3u;
3021 imw_addr = (pi_base << 3) | interrupt_num;
3022
3023 sim_debug (DBG_DEBUG, & iom_dev,
3024 "%s: IOM %c, channel %d (%#o), level %d; "
3025 "Interrupt %d (%#o).\r\n",
3026 __func__, iomChar (iom_unit_idx), chan, chan, pic, interrupt_num,
3027 interrupt_num);
3028 word36 imw;
3029 iom_core_read_lock (iom_unit_idx, imw_addr, &imw, __func__);
3030
3031
3032
3033
3034
3035 putbits36_1 (& imw, chan_in_group, 1);
3036 iom_core_write_unlock (iom_unit_idx, imw_addr, imw, __func__);
3037 return scu_set_interrupt (iom_unit_data[iom_unit_idx].invokingScuUnitIdx, interrupt_num);
3038 }
3039
3040 static void iom_fault (uint iom_unit_idx, uint chan, UNUSED const char * who,
3041 iomFaultServiceRequest req,
3042 iomSysFaults_t signal)
3043 {
3044 #if defined(TESTING)
3045 cpu_state_t * cpup = _cpup;
3046 #endif
3047
3048
3049
3050 if (! tandd_io_mode ())
3051 sim_warn ("iom_fault %s: IOM %c channel %o, fault %o\r\n", who,
3052 'A' + iom_unit_idx, chan, (uint) signal);
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079 sim_debug (DBG_DEBUG, & iom_dev,
3080 "%s: chan %d %s req %#o signal %#o\r\n",
3081 __func__, chan, who, req, signal);
3082
3083 word36 faultWord = 0;
3084 putbits36_9 (& faultWord, 9, (word9) chan);
3085 putbits36_5 (& faultWord, 18, (word5) req);
3086
3087 putbits36_6 (& faultWord, 30, (word6) signal);
3088
3089 uint chanloc = mbxLoc (iom_unit_idx, IOM_SYSTEM_FAULT_CHAN);
3090
3091 word36 lpw;
3092 iom_core_read (iom_unit_idx, chanloc + IOM_MBX_LPW, & lpw, __func__);
3093
3094 word36 scw;
3095 iom_core_read (iom_unit_idx, chanloc + IOM_MBX_SCW, & scw, __func__);
3096
3097 word36 dcw;
3098 iom_core_read_lock (iom_unit_idx, chanloc + IOM_MBX_DCW, & dcw, __func__);
3099
3100
3101
3102
3103
3104 iom_core_write (iom_unit_idx, (dcw >> 18) & MASK18, faultWord, __func__);
3105
3106 uint tally = dcw & MASK12;
3107 if (tally > 1)
3108 {
3109 dcw -= 01llu;
3110 dcw += 01000000llu;
3111 }
3112 else
3113 dcw = scw;
3114 iom_core_write_unlock (iom_unit_idx, chanloc + IOM_MBX_DCW, dcw, __func__);
3115
3116 send_general_interrupt (iom_unit_idx, IOM_SYSTEM_FAULT_CHAN, imwSystemFaultPic);
3117 }
3118
3119
3120
3121
3122
3123
3124 int iom_list_service (uint iom_unit_idx, uint chan,
3125 bool * ptro, bool * sendp, bool * uffp)
3126 {
3127 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
3128
3129
3130
3131 bool isConnChan = chan == IOM_CONNECT_CHAN;
3132 * ptro = false;
3133 bool uff = false;
3134 bool send = false;
3135
3136
3137
3138
3139
3140
3141
3142 if (p -> lsFirst)
3143 {
3144
3145
3146 fetch_and_parse_LPW (iom_unit_idx, chan);
3147 p -> wasTDCW = false;
3148 p -> SEG = 0;
3149 }
3150
3151
3152
3153
3154 if (isConnChan)
3155 {
3156
3157
3158
3159 if (p -> LPW_21_NC == 0 && p -> LPW_22_TAL == 0)
3160 {
3161 iom_fault (iom_unit_idx, IOM_CONNECT_CHAN, __func__,
3162 p -> lsFirst ? iomFsrFirstList : iomFsrList,
3163 iomIllTalCChnFlt);
3164 return -1;
3165 }
3166
3167 if (p -> LPW_21_NC == 0 && p -> LPW_22_TAL == 1)
3168 {
3169
3170
3171
3172 if (p -> LPW_TALLY == 0)
3173 {
3174 iom_fault (iom_unit_idx, IOM_CONNECT_CHAN, __func__,
3175 p -> lsFirst ? iomFsrFirstList : iomFsrList,
3176 iomIllTalCChnFlt);
3177 return -1;
3178 }
3179
3180 if (p -> LPW_TALLY > 1)
3181 {
3182
3183
3184 if (p -> LPW_20_AE == 0 &&
3185 (((word36) p -> LPW_DCW_PTR) + ((word36) p -> LPW_TALLY)) >
3186 01000000llu)
3187 {
3188 iom_fault (iom_unit_idx, IOM_CONNECT_CHAN, __func__,
3189 p -> lsFirst ? iomFsrFirstList : iomFsrList,
3190 iom256KFlt);
3191 return -1;
3192 }
3193 }
3194 else if (p -> LPW_TALLY == 1)
3195 * ptro = true;
3196 }
3197 else
3198 * ptro = true;
3199
3200
3201
3202
3203
3204 fetch_and_parse_PCW (iom_unit_idx, chan);
3205
3206
3207 if (IS_NOT_IDCW (p))
3208 {
3209 iom_fault (iom_unit_idx, IOM_CONNECT_CHAN, __func__,
3210 p -> lsFirst ? iomFsrFirstList : iomFsrList,
3211 iomNotPCWFlt);
3212 return -1;
3213 }
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226 send = true;
3227
3228 goto D;
3229 }
3230
3231
3232
3233
3234
3235 if (p -> LPW_21_NC == 0 && p -> LPW_22_TAL == 0)
3236 {
3237
3238
3239 if (p -> LPW_20_AE == 0 &&
3240 (((word36) p -> LPW_DCW_PTR) + ((word36) p -> LPW_TALLY)) >
3241 01000000llu)
3242 {
3243 iom_fault (iom_unit_idx, IOM_CONNECT_CHAN, __func__,
3244 p -> lsFirst ? iomFsrFirstList : iomFsrList,
3245 iom256KFlt);
3246 return -1;
3247 }
3248 }
3249 else if (p -> LPW_21_NC == 0 && p -> LPW_22_TAL == 1)
3250 {
3251 A:;
3252
3253
3254
3255
3256
3257
3258
3259
3260 if (p -> LPW_TALLY == 0 && p -> LPW_22_TAL)
3261 {
3262 sim_warn("%s: setting uff for chan %d because LPW_TALLY was 0. LPW=%llo.\r\n",
3263 __func__, chan, p -> LPW);
3264 uff = true;
3265 }
3266 else if (p -> LPW_TALLY > 1)
3267 {
3268
3269
3270
3271 if (p -> LPW_20_AE == 0 &&
3272 (((word36) p -> LPW_DCW_PTR) + ((word36) p -> LPW_TALLY)) >
3273 01000000llu)
3274 {
3275 iom_fault (iom_unit_idx, IOM_CONNECT_CHAN, __func__,
3276 p -> lsFirst ? iomFsrFirstList : iomFsrList,
3277 iom256KFlt);
3278 return -1;
3279 }
3280 }
3281 }
3282
3283
3284
3285
3286 fetch_and_parse_DCW (iom_unit_idx, chan, false);
3287
3288
3289
3290 if (p -> lsFirst)
3291 p -> LPWX_SIZE = p -> LPW_DCW_PTR;
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302 if (IS_TDCW (p))
3303 {
3304
3305 if (p -> wasTDCW)
3306 {
3307 sim_warn("%s: setting uff for chan %d because p->wasTDCW was %d\r\n",
3308 __func__, chan, p->wasTDCW);
3309 uff = true;
3310 goto uffSet;
3311 }
3312 p -> wasTDCW = true;
3313
3314
3315
3316 p -> LPW_DCW_PTR = p -> TDCW_DATA_ADDRESS;
3317
3318
3319
3320
3321 p -> LPW_20_AE |= p -> TDCW_33_EC;
3322 p -> LPW_18_RES |= p -> TDCW_34_RES;
3323 p -> LPW_23_REL |= p -> TDCW_35_REL;
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356 if (p -> TDCW_31_SEG)
3357 sim_warn ("TDCW_31_SEG\r\n");
3358
3359 update_chan_mode (iom_unit_idx, chan, true);
3360
3361
3362 p->LPW_TALLY = ((word12) (((word12s) p->LPW_TALLY) - 1)) & MASK12;
3363
3364 pack_LPW (iom_unit_idx, chan);
3365
3366
3367
3368 if (p -> LPW_18_RES && p -> TDCW_33_EC)
3369 {
3370 sim_warn("%s: setting uff for chan %d because p->LPW_18_RES and p->TDCW_33_EC were set\r\n",
3371 __func__, chan);
3372 uff = true;
3373 goto uffSet;
3374 }
3375
3376 goto A;
3377 }
3378 else if (IS_IDCW (p))
3379 {
3380
3381
3382 if (p -> LPW_18_RES)
3383 {
3384
3385 sim_warn("%s: setting uff for chan %d because LPW_18_RES was %o\r\n",
3386 __func__, chan, p->LPW_18_RES);
3387 uff = true;
3388
3389 }
3390 else
3391 {
3392
3393
3394 send = true;
3395 }
3396 p -> LPWX_SIZE = p -> LPW_DCW_PTR;
3397 goto D;
3398 }
3399
3400 p -> wasTDCW = false;
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426 if (uff)
3427 {
3428 uffSet:;
3429
3430 p -> DCW_18_20_CP = 07u;
3431 pack_DCW (iom_unit_idx, chan);
3432 }
3433
3434
3435
3436
3437
3438
3439
3440
3441 send = true;
3442
3443
3444
3445 D:;
3446
3447
3448
3449 * uffp = uff;
3450 * sendp = send;
3451
3452
3453
3454 if (p -> LPW_21_NC == 0)
3455 {
3456
3457 if (isConnChan)
3458 p -> LPW_DCW_PTR = (p -> LPW_DCW_PTR + 2u) & MASK18;
3459 else
3460 p -> LPW_DCW_PTR = (p -> LPW_DCW_PTR + 1u) & MASK18;
3461
3462 p->LPW_TALLY = ((word12) (((word12s) p->LPW_TALLY) - 1)) & MASK12;
3463 pack_LPW (iom_unit_idx, chan);
3464 }
3465
3466
3467 if (p -> DDCW_22_23_TYPE == 07u || p -> lsFirst)
3468 {
3469
3470
3471
3472
3473 write_LPW (iom_unit_idx, chan);
3474 }
3475 else
3476 {
3477 if (p -> LPW_21_NC == 0 ||
3478 (IS_TDCW (p)))
3479 {
3480
3481
3482
3483
3484 write_LPW (iom_unit_idx, chan);
3485 }
3486 }
3487
3488 p -> lsFirst = false;
3489
3490
3491 return 0;
3492 }
3493
3494
3495
3496 static int doPayloadChannel (uint iomUnitIdx, uint chan) {
3497 #if defined(TESTING)
3498 cpu_state_t * cpup = _cpup;
3499 sim_debug (DBG_DEBUG, & iom_dev, "%s: Payload channel %c%02o\r\n", __func__, iomChar (iomUnitIdx), chan);
3500 #endif
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518 iom_chan_data_t * p = & iom_chan_data[iomUnitIdx][chan];
3519
3520 #if defined(TESTING)
3521 word36 PCW_DCW = p->DCW;
3522 word1 PCW_LPW_23_REL = p->LPW_23_REL;
3523 #endif
3524 p -> chanMode = cm1;
3525 p -> LPW_18_RES = 0;
3526 p -> LPW_20_AE = 0;
3527 p -> LPW_23_REL = 0;
3528
3529 unpack_DCW (iomUnitIdx, chan);
3530
3531 p->isPCW = true;
3532
3533
3534
3535 struct iom_to_ctlr_s * d = & cables->iom_to_ctlr[iomUnitIdx][chan];
3536
3537
3538
3539
3540 if (d->chan_type != chan_type_CPI && p -> IDCW_DEV_CMD == 051) {
3541 p->stati = 04501;
3542 send_terminate_interrupt (iomUnitIdx, chan);
3543 return 0;
3544 }
3545
3546 if ((!d->in_use) || (!d->iom_cmd)) {
3547 p -> stati = 06000;
3548 #if defined(POLTS_TESTING)
3549 if (chan == 014) if_sim_debug (DBG_TRACE, & iom_dev) sim_printf \
3550 ("// terminate 10. ctrl == 0 in chan %d (%o) DCW\r\n", chan, chan);
3551 #endif
3552 goto terminate;
3553 }
3554
3555
3556
3557
3558
3559 p -> ADDR_EXT = p -> PCW_AE;
3560
3561 p -> lsFirst = true;
3562
3563 p -> tallyResidue = 0;
3564 p -> isRead = true;
3565 p -> charPos = 0;
3566
3567
3568
3569 p -> initiate = true;
3570 p -> chanStatus = chanStatNormal;
3571
3572
3573
3574
3575 int rc = d->iom_cmd (iomUnitIdx, chan);
3576
3577 if (rc < 0) {
3578 p -> dev_code = getbits36_6 (p -> DCW, 6);
3579 #if defined(POLTS_TESTING)
3580 if (chan == 014) if_sim_debug (DBG_TRACE, & iom_dev) \
3581 sim_printf ("// terminate 9. ctrl == 0 in chan %d (%o) DCW\r\n", chan, chan);
3582 #endif
3583 goto terminate;
3584 }
3585
3586 if (IS_IDCW (p) && p->IDCW_CHAN_CTRL == CHAN_CTRL_MARKER) {
3587 send_marker_interrupt (iomUnitIdx, (int) chan);
3588 }
3589
3590 if (rc == IOM_CMD_DISCONNECT) {
3591 #if defined(POLTS_TESTING)
3592 if (chan == 014) if_sim_debug (DBG_TRACE, & iom_dev) sim_printf \
3593 ("// terminate 8. ctrl == 0 in chan %d (%o) DCW\r\n", chan, chan);
3594 #endif
3595 goto terminate;
3596 }
3597
3598 if (p->masked) {
3599 #if defined(POLTS_TESTING)
3600 if (chan == 014) if_sim_debug (DBG_TRACE, & iom_dev) sim_printf \
3601 ("// terminate 7. ctrl == 0 in chan %d (%o) DCW\r\n", chan, chan);
3602 #endif
3603 goto terminate;
3604 }
3605
3606 bool ptro, send, uff;
3607 bool terminate = false;
3608 p->isPCW = false;
3609
3610 #if defined(TESTING)
3611 bool first = true;
3612 #endif
3613
3614 (void)terminate;
3615 bool idcw_terminate = p -> IDCW_CHAN_CTRL == CHAN_CTRL_TERMINATE;
3616 do {
3617 int rc2 = iom_list_service (iomUnitIdx, chan, & ptro, & send, & uff);
3618 if (rc2 < 0) {
3619
3620 sim_warn ("%s list service failed\r\n", __func__);
3621 return -1;
3622 }
3623 if (uff) {
3624
3625 #if defined(POLTS_TESTING)
3626 if (chan == 014) if_sim_debug (DBG_TRACE, & iom_dev) \
3627 sim_printf ("// terminate 6. ctrl == 0 in chan %d (%o) DCW\r\n", chan, chan);
3628 #endif
3629 goto terminate;
3630 }
3631
3632 if (! send) {
3633 sim_warn ("%s nothing to send\r\n", __func__);
3634 return 1;
3635 }
3636
3637 #if defined(TESTING)
3638 # if defined(POLTS_TESTING)
3639 if (iomUnitIdx == 1 && chan == 020)
3640 # endif
3641 if_sim_debug (DBG_TRACE, & iom_dev) {
3642 if (first) {
3643 first = false;
3644 dumpLPW (iomUnitIdx, chan);
3645 sim_printf ("// DCW list dump: \r\n");
3646 dumpDCW (PCW_DCW, PCW_LPW_23_REL);
3647 for (int i = 0; i < 8; i ++)
3648 dumpDCW (M[p->LPW_DCW_PTR - 1 + i], p->LPW_23_REL);
3649 sim_printf ("// \r\n");
3650 }
3651 }
3652 #endif
3653
3654
3655
3656
3657
3658
3659 if (IS_IDCW (p)) {
3660 idcw_terminate = p -> IDCW_CHAN_CTRL == CHAN_CTRL_TERMINATE;
3661 if (p -> LPW_23_REL == 0 && p -> IDCW_EC == 1)
3662 p -> ADDR_EXT = getbits36_6 (p -> DCW, 12);
3663
3664
3665 p -> tallyResidue = 0;
3666 p -> isRead = true;
3667 p -> charPos = 0;
3668 p -> chanStatus = chanStatNormal;
3669 }
3670
3671
3672
3673 rc2 = d->iom_cmd (iomUnitIdx, chan);
3674
3675 if (rc2 < 0) {
3676 p -> dev_code = getbits36_6 (p -> DCW, 6);
3677 #if defined(POLTS_TESTING)
3678 if (chan == 014) if_sim_debug (DBG_TRACE, & iom_dev) \
3679 sim_printf ("// terminate 5. ctrl == 0 in chan %d (%o) DCW\r\n", chan, chan);
3680 #endif
3681 goto terminate;
3682 }
3683
3684 if (rc2 == IOM_CMD_DISCONNECT) {
3685 terminate = true;
3686 #if defined(POLTS_TESTING)
3687 if (chan == 014) if_sim_debug (DBG_TRACE, & iom_dev) sim_printf \
3688 ("// terminate 4. ctrl == 0 in chan %d (%o) DCW\r\n", chan, chan);
3689 #endif
3690 }
3691
3692 if (rc2 == IOM_CMD_PENDING)
3693 goto pending;
3694
3695
3696 if (IS_IDCW (p) && p->IDCW_CHAN_CTRL == CHAN_CTRL_TERMINATE && p->IDCW_CHAN_CMD == CHAN_CMD_NONDATA) {
3697 #if defined(POLTS_TESTING)
3698 if (chan == 014) if_sim_debug (DBG_TRACE, & iom_dev) \
3699 sim_printf ("// terminate 1. ctrl == 0 in chan %d (%o) DCW\r\n", chan, chan);
3700 #endif
3701 goto terminate;
3702 }
3703
3704 if (IS_IOTD (p) && idcw_terminate && rc2 != IOM_CMD_RESIDUE) {
3705 #if defined(POLTS_TESTING)
3706
3707
3708 if (chan == 014) if_sim_debug (DBG_TRACE, & iom_dev) \
3709 sim_printf ("// terminate 2. ctrl == 0 in chan %d (%o) DCW\r\n", chan, chan);
3710 #endif
3711 goto terminate;
3712 }
3713
3714
3715
3716 if (IS_NOT_IDCW (p) && rc2 == IOM_CMD_RESIDUE) {
3717 if (p->recordResidue)
3718 p->recordResidue --;
3719 if (p->recordResidue == 0)
3720 goto terminate;
3721 }
3722 } while (! terminate);
3723
3724 terminate:;
3725 #if defined(POLTS_TESTING)
3726 if (iomUnitIdx == 1 && chan == 020) sim_printf ("stati %04o\r\n", p->stati);
3727 #endif
3728 send_terminate_interrupt (iomUnitIdx, chan);
3729 return 0;
3730
3731 pending:;
3732 return 0;
3733 }
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776 static void doWrapAroundChan (uint iom_unit_idx, word36 pcw0) {
3777 #if defined(TESTING)
3778 cpu_state_t * cpup = _cpup;
3779 #endif
3780 iom_unit_data_t * u = & iom_unit_data[iom_unit_idx];
3781 word18 addrField = getbits36_18 (pcw0, 0);
3782 uint src = getbits36_3 (pcw0, 21);
3783 word1 mod = getbits36_1 (pcw0, 24);
3784 word1 aec = getbits36_1 (pcw0, 26);
3785 uint action = getbits36_3 (pcw0, 27);
3786 uint testChan = getbits36_6 (pcw0, 30);
3787
3788 sim_debug (DBG_DEBUG, & iom_dev,
3789 "%s: IOM %c PCW %012llo src %o mod %o aec %o action %o chan %02o\r\n",
3790 __func__, iomChar (iom_unit_idx), (unsigned long long) pcw0,
3791 src, mod, aec, action, testChan);
3792
3793 switch (action) {
3794 case 4:
3795 case 5:
3796 u->wacData[action - 4] = pcw0;
3797 return;
3798 case 6:
3799 u->wacStatus = pcw0;
3800 return;
3801 case 7:
3802 u->wacStatus = (word36) testChan;
3803 return;
3804 case 3:
3805 sim_warn ("%s: WAC forced parity error not implemented\r\n", __func__);
3806 return;
3807 default:
3808 break;
3809 }
3810
3811 bool dbl = action == 2;
3812 word24 addr = addrField;
3813 if (aec)
3814 addr = (word24) ((getbits36_6 (pcw0, 12) << 18) | addrField);
3815
3816
3817 word36 bus = (word36) testChan;
3818
3819 switch (src) {
3820 case 6:
3821 if (dbl) {
3822 addr &= ~1u;
3823 iom_core_read2 (iom_unit_idx, addr, & u->wacData[0], & u->wacData[1], __func__);
3824 } else if (mod) {
3825 iom_core_read_lock (iom_unit_idx, addr, & u->wacData[action], __func__);
3826 iom_core_write_unlock (iom_unit_idx, addr, 0, __func__);
3827 } else {
3828 iom_core_read (iom_unit_idx, addr, & u->wacData[action], __func__);
3829 }
3830 putbits36_1 (& bus, 1, 1);
3831 putbits36_1 (& bus, 2, dbl ? 1 : 0);
3832 break;
3833
3834 case 7:
3835 if (dbl) {
3836 addr &= ~1u;
3837 iom_core_write2 (iom_unit_idx, addr, u->wacData[0], u->wacData[1], __func__);
3838 } else {
3839 iom_core_write (iom_unit_idx, addr, u->wacData[action], __func__);
3840 }
3841 putbits36_1 (& bus, 1, 1);
3842 putbits36_1 (& bus, 2, dbl ? 1 : 0);
3843 break;
3844
3845 case 3:
3846 send_general_interrupt (iom_unit_idx, testChan, (enum iomImwPics) getbits36_3 (pcw0, 13));
3847 break;
3848
3849 case 2: {
3850 word36 scw;
3851 uint mbx = mbxLoc (iom_unit_idx, testChan);
3852 iom_core_read (iom_unit_idx, mbx + 2, & scw, __func__);
3853 iom_core_write (iom_unit_idx, getbits36_18 (scw, 0), u->wacStatus, __func__);
3854 }
3855 return;
3856
3857 default:
3858 sim_warn ("%s: WAC service request %o not implemented (PCW %012llo)\r\n",
3859 __func__, src, (unsigned long long) pcw0);
3860 return;
3861 }
3862 u->wacStatus = bus;
3863 }
3864
3865 static int doConnectChan (uint iom_unit_idx) {
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877 #if defined(TESTING)
3878 cpu_state_t * cpup = _cpup;
3879 #endif
3880 sim_debug (DBG_DEBUG, & iom_dev, "%s: Connect channel\r\n", __func__);
3881 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][IOM_CONNECT_CHAN];
3882 p -> lsFirst = true;
3883 #if defined(TESTING) && defined(POLTS_TESTING)
3884 bool first = true;
3885 #endif
3886 bool ptro, send, uff;
3887 do {
3888
3889 int rc = iom_list_service (iom_unit_idx, IOM_CONNECT_CHAN, & ptro, & send, & uff);
3890 if (rc < 0) {
3891 if (! tandd_io_mode ())
3892 sim_warn ("connect channel connect failed\r\n");
3893 return -1;
3894 }
3895 if (uff) {
3896 sim_warn ("connect channel ignoring uff\r\n");
3897 }
3898 if (! send) {
3899 sim_warn ("connect channel nothing to send\r\n");
3900 } else {
3901 #if defined(xTESTING)
3902 if_sim_debug (DBG_TRACE, & iom_dev) {
3903 if (first) {
3904 first = false;
3905 sim_printf ("// CIOC %lld\r\n", cpu.cycleCnt);
3906 dumpLPW (iom_unit_idx, IOM_CONNECT_CHAN);
3907 sim_printf ("// PCW %012llo %012llo\r\n", p->PCW0, p->PCW1);
3908 sim_printf ("// Chan info %04o\r\n", p->PCW_CHAN);
3909 sim_printf ("// Addr ext %02o\r\n", p->PCW_AE);
3910 sim_printf ("// 111 %o\r\n", getbits36_3 (p->PCW0, 18));
3911 sim_printf ("// M %o\r\n", p->PCW_21_MSK);
3912 sim_printf ("// Chan info %08o\r\n", getbits36_14 (p->PCW0, 22));
3913 sim_printf ("// Pg Tbl Ptr %06o\r\n", p->PCW_PAGE_TABLE_PTR);
3914 sim_printf ("// PTP %o\r\n", p->PCW_63_PTP);
3915 sim_printf ("// PGE %o\r\n", p->PCW_64_PGE);
3916 sim_printf ("// AUX %o\r\n", p->PCW_65_AUX);
3917 sim_printf ("//\r\n");
3918 }
3919 }
3920 #endif
3921
3922
3923
3924 if (p -> PCW_CHAN == IOM_WAC_CHAN &&
3925 ! cables->iom_to_ctlr[iom_unit_idx][IOM_WAC_CHAN].in_use) {
3926 doWrapAroundChan (iom_unit_idx, p -> PCW0);
3927 continue;
3928 }
3929
3930
3931 iom_chan_data_t * q = & iom_chan_data[iom_unit_idx][p -> PCW_CHAN];
3932
3933 q -> PCW0 = p -> PCW0;
3934 q -> PCW1 = p -> PCW1;
3935 q -> PCW_CHAN = p -> PCW_CHAN;
3936 q -> PCW_AE = p -> PCW_AE;
3937 q -> PCW_PAGE_TABLE_PTR = p -> PCW_PAGE_TABLE_PTR;
3938 q -> PCW_63_PTP = p -> PCW_63_PTP;
3939 q -> PCW_64_PGE = p -> PCW_64_PGE;
3940 q -> PCW_65_AUX = p -> PCW_65_AUX;
3941 q -> PCW_21_MSK = p -> PCW_21_MSK;
3942 q -> DCW = p -> DCW;
3943
3944 sim_debug (DBG_DEBUG, & iom_dev, "%s: PCW %012llo %012llo chan %02o\r\n", __func__, q->PCW0, q->PCW1, q->PCW_CHAN);
3945
3946 q -> masked = p -> PCW_21_MSK;
3947 if (q -> masked) {
3948 if (q -> in_use)
3949 sim_warn ("%s: chan %d masked while in use\r\n", __func__, p -> PCW_CHAN);
3950 q -> in_use = false;
3951 q -> start = false;
3952 } else {
3953 if (q -> in_use)
3954 sim_warn ("%s: chan %d connect while in use\r\n", __func__, p -> PCW_CHAN);
3955 q -> in_use = true;
3956 q -> start = true;
3957 #if defined(IO_THREADZ)
3958 setChnConnect (iom_unit_idx, p -> PCW_CHAN);
3959 #else
3960 # if !defined(IO_ASYNC_PAYLOAD_CHAN) && !defined(IO_ASYNC_PAYLOAD_CHAN_THREAD)
3961 doPayloadChannel (iom_unit_idx, p -> PCW_CHAN);
3962 # endif
3963 # if defined(IO_ASYNC_PAYLOAD_CHAN_THREAD)
3964 pthread_cond_signal (& iomCond);
3965 # endif
3966 #endif
3967 }
3968 }
3969 } while (! ptro);
3970 return 0;
3971 }
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983 int send_marker_interrupt (uint iom_unit_idx, int chan)
3984 {
3985 if (iom_chan_data [iom_unit_idx] [chan] . masked)
3986 return(0);
3987 status_service (iom_unit_idx, (uint) chan, true);
3988 return send_general_interrupt (iom_unit_idx, (uint) chan, imwMarkerPic);
3989 }
3990
3991
3992
3993
3994
3995
3996
3997
3998 int send_special_interrupt (uint iom_unit_idx, uint chan, uint devCode,
3999 word8 status0, word8 status1)
4000 {
4001
4002 uint chanloc = mbxLoc (iom_unit_idx, IOM_SPECIAL_STATUS_CHAN);
4003
4004 if (iom_chan_data [iom_unit_idx] [chan] . masked)
4005 return(0);
4006
4007 #if defined(LOCKLESS)
4008 lock_iom();
4009 #endif
4010
4011
4012
4013
4014
4015
4016 word36 lpw;
4017 iom_core_read (iom_unit_idx, chanloc + IOM_MBX_LPW, & lpw, __func__);
4018
4019 word36 scw;
4020 iom_core_read (iom_unit_idx, chanloc + IOM_MBX_SCW, & scw, __func__);
4021
4022 word36 dcw;
4023 iom_core_read_lock (iom_unit_idx, chanloc + IOM_MBX_DCW, & dcw, __func__);
4024
4025 word36 status = 0400000000000ull;
4026 status |= (((word36) chan) & MASK6) << 27;
4027 status |= (((word36) devCode) & MASK8) << 18;
4028 status |= (((word36) status0) & MASK8) << 9;
4029 status |= (((word36) status1) & MASK8) << 0;
4030 iom_core_write (iom_unit_idx, (dcw >> 18) & MASK18, status, __func__);
4031
4032 uint tally = dcw & MASK12;
4033 if (tally > 1)
4034 {
4035 dcw -= 01llu;
4036 dcw += 01000000llu;
4037 }
4038 else
4039 dcw = scw;
4040 iom_core_write_unlock (iom_unit_idx, chanloc + IOM_MBX_DCW, dcw, __func__);
4041
4042 #if defined(LOCKLESS)
4043 unlock_iom();
4044 #endif
4045
4046 send_general_interrupt (iom_unit_idx, IOM_SPECIAL_STATUS_CHAN, imwSpecialPic);
4047 return 0;
4048 }
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059 int send_terminate_interrupt (uint iom_unit_idx, uint chan)
4060 {
4061 if (iom_chan_data [iom_unit_idx] [chan] . masked)
4062 return 0;
4063 status_service (iom_unit_idx, chan, false);
4064 if (iom_chan_data [iom_unit_idx] [chan] . in_use == false)
4065 sim_warn ("%s: chan %d not in use\r\n", __func__, chan);
4066 iom_chan_data [iom_unit_idx] [chan] . in_use = false;
4067 send_general_interrupt (iom_unit_idx, chan, imwTerminatePic);
4068 return 0;
4069 }
4070
4071 void iom_interrupt (uint scu_unit_idx, uint iom_unit_idx)
4072 {
4073 cpu_state_t * cpup = _cpup;
4074 sim_debug (DBG_DEBUG, & iom_dev,
4075 "%s: IOM %c starting. [%"PRId64"] %05o:%08o\r\n",
4076 __func__, iomChar (iom_unit_idx), cpu.cycleCnt, cpu.PPR.PSR, cpu.PPR.IC);
4077
4078 iom_unit_data[iom_unit_idx].invokingScuUnitIdx = scu_unit_idx;
4079
4080 #if defined(IO_THREADZ)
4081 setIOMInterrupt (iom_unit_idx);
4082 iomDoneWait (iom_unit_idx);
4083 #else
4084 int ret = doConnectChan (iom_unit_idx);
4085
4086 sim_debug (DBG_DEBUG, & iom_dev,
4087 "%s: IOM %c finished; doConnectChan returned %d.\r\n",
4088 __func__, iomChar (iom_unit_idx), ret);
4089 #endif
4090
4091 }
4092
4093 #if defined(IO_THREADZ)
4094 void * chan_thread_main (void * arg)
4095 {
4096 uint myid = (uint) * (int *) arg;
4097 this_iom_idx = (uint) myid / MAX_CHANNELS;
4098 this_chan_num = (uint) myid % MAX_CHANNELS;
4099
4100
4101
4102 set_cpu_idx (0);
4103
4104 sim_msg ("\rIOM %c Channel %u thread created\r\n", this_iom_idx + 'a', this_chan_num);
4105 # if defined(TESTING)
4106 printPtid(pthread_self());
4107 # endif
4108 if (realtime_ok) {
4109 set_realtime_priority (pthread_self(), realtime_max_priority() - 1);
4110 check_realtime_priority (pthread_self(), realtime_max_priority() - 1);
4111 } else {
4112 # if !defined(__QNX__)
4113 (void)sim_os_set_thread_priority (PRIORITY_ABOVE_NORMAL);
4114 # endif
4115 }
4116
4117 setSignals ();
4118 while (1)
4119 {
4120
4121 chnConnectWait ();
4122
4123 doPayloadChannel (this_iom_idx, this_chan_num);
4124 chnConnectDone ();
4125 }
4126 }
4127
4128 void * iom_thread_main (void * arg)
4129 {
4130 int myid = * (int *) arg;
4131 this_iom_idx = (uint) myid;
4132
4133
4134
4135 set_cpu_idx (0);
4136
4137 sim_printf("IOM %c thread created\r\n", 'a' + myid);
4138
4139 setSignals ();
4140 while (1)
4141 {
4142
4143 iomInterruptWait ();
4144
4145 int ret = doConnectChan (this_iom_idx);
4146
4147 sim_debug (DBG_DEBUG, & iom_dev,
4148 "%s: IOM %c finished; doConnectChan returned %d.\r\n",
4149 __func__, iomChar (myid), ret);
4150 iomInterruptDone ();
4151 }
4152 }
4153 #endif
4154
4155
4156
4157
4158
4159
4160
4161 void iom_init (void)
4162 {
4163
4164 }
4165
4166 #if defined(PANEL68)
4167 void do_boot (void)
4168 {
4169 boot_svc (& boot_channel_unit[0]);
4170 }
4171 #endif
4172
4173 #if defined(IO_ASYNC_PAYLOAD_CHAN) || defined(IO_ASYNC_PAYLOAD_CHAN_THREAD)
4174 void iomProcess (void)
4175 {
4176 for (uint i = 0; i < N_IOM_UNITS_MAX; i++)
4177 for (uint j = 0; j < MAX_CHANNELS; j++)
4178 {
4179 iom_chan_data_t * p = &iom_chan_data [i] [j];
4180 if (p -> start)
4181 {
4182 p -> start = false;
4183 doPayloadChannel (i, j);
4184 }
4185 }
4186 }
4187 #endif
4188
4189 char iomChar (uint iomUnitIdx)
4190 {
4191 return (iom_unit_data[iomUnitIdx].configSwMultiplexBaseAddress & 3) + 'A';
4192 }