This source file includes following definitions.
- disk_show_nunits
- disk_set_nunits
- disk_show_type
- disk_set_type
- dsk_show_device_name
- dsk_set_device_name
- signal_disk_ready
- disk_set_ready
- unloadDisk
- loadDisk
- disk_reset
- disk_attach
- disk_init
- diskSeek64
- diskSeek512
- diskSeekSpecial
- diskRead
- diskWrite
- readStatusRegister
- diskRdCtrlReg
- read_configuration
- read_and_clear_statistics
- dsk_iom_cmd
- ipc_show_nunits
- ipc_set_nunits
- ipc_show_device_name
- ipc_set_device_name
- msp_show_nunits
- msp_set_nunits
- msp_show_device_name
- msp_set_device_name
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 #include <stdio.h>
36
37 #include "dps8.h"
38 #include "dps8_iom.h"
39 #include "dps8_disk.h"
40 #include "dps8_sys.h"
41 #include "dps8_cable.h"
42 #include "dps8_cpu.h"
43 #include "dps8_faults.h"
44 #include "dps8_scu.h"
45 #include "../simh/sim_disk.h"
46 #include "dps8_utils.h"
47
48 #if defined(LOCKLESS)
49 # include "threadz.h"
50 #endif
51
52 #define DBG_CTR 1
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 struct diskType_t diskTypes[] = {
145 { "3381", 451350, 0, false, seek_512, 512, 0 },
146 { "d500", 618640, 1, false, seek_64, 64, 200 },
147 { "d451", 616360, 1, true, seek_64, 64, 154 },
148 { "d400", 309320, 1, true, seek_64, 64, 84 },
149 { "d190", 239723, 1, true, seek_64, 64, 84 },
150 { "d181", 72000, 1, true, seek_64, 64, 0 },
151 { "d501", 1075200, 1, false, seek_64, 64, 201 },
152 { "3380", 225675, 0, false, seek_512, 512, 0 },
153 };
154 #define N_DISK_TYPES (sizeof (diskTypes) / sizeof (struct diskType_t))
155
156 static uint tAndDCapac[N_DISK_TYPES] = { 451860, 639920, 619400, 312360, 242250, 72360, 1077760, 225675 };
157
158 #define M3381_SECTORS (1770*255)
159
160
161
162
163
164
165
166
167
168
169
170
171
172 #define N_DISK_UNITS 2
173
174 struct dsk_state dsk_states [N_DSK_UNITS_MAX];
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 #if defined(POLTS_DISK_TESTING)
250 static int nCmds = 0;
251 #endif
252
253 #define UNIT_FLAGS ( UNIT_FIX | UNIT_ATTABLE | UNIT_ROABLE | \
254 UNIT_DISABLE | UNIT_IDLE | DKUF_F_STD )
255 UNIT dsk_unit[N_DSK_UNITS_MAX] = {
256 #if defined(NO_C_ELLIPSIS)
257 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
258 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
259 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
260 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
261 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
262 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
263 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
264 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
265 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
266 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
267 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
268 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
269 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
270 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
271 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
272 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
273 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
274 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
275 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
276 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
277 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
278 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
279 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
280 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
281 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
282 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
283 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
284 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
285 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
286 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
287 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
288 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
289 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
290 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
291 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
292 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
293 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
294 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
295 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
296 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
297 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
298 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
299 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
300 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
301 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
302 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
303 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
304 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
305 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
306 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
307 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
308 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
309 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
310 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
311 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
312 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
313 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
314 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
315 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
316 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
317 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
318 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
319 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
320 { UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL }
321 #else
322 [0 ... N_DSK_UNITS_MAX-1] = {
323 UDATA ( NULL, UNIT_FLAGS, M3381_SECTORS), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL
324 }
325 #endif
326 };
327
328 #define DSK_UNIT_IDX(uptr) ((uptr) - dsk_unit)
329
330 static DEBTAB disk_dt[] =
331 {
332 { "TRACE", DBG_TRACE, NULL },
333 { "NOTIFY", DBG_NOTIFY, NULL },
334 { "INFO", DBG_INFO, NULL },
335 { "ERR", DBG_ERR, NULL },
336 { "WARN", DBG_WARN, NULL },
337 { "DEBUG", DBG_DEBUG, NULL },
338 { "ALL", DBG_ALL, NULL },
339 { NULL, 0, NULL }
340 };
341
342 static t_stat disk_show_nunits (UNUSED FILE * st, UNUSED UNIT * uptr, UNUSED int val, UNUSED const void * desc)
343 {
344 sim_printf("Number of DISK units in system is %d\r\n", dsk_dev . numunits);
345 return SCPE_OK;
346 }
347
348 static t_stat disk_set_nunits (UNUSED UNIT * uptr, UNUSED int32 value, const char * cptr, UNUSED void * desc)
349 {
350 if (! cptr)
351 return SCPE_ARG;
352 int n = atoi (cptr);
353 if (n < 1 || n > N_DSK_UNITS_MAX)
354 return SCPE_ARG;
355 dsk_dev . numunits = (uint32) n;
356 return SCPE_OK;
357 }
358
359 static t_stat disk_show_type (UNUSED FILE * st, UNUSED UNIT * uptr, UNUSED int val, UNUSED const void * desc)
360 {
361 int diskUnitIdx = (int) DSK_UNIT_IDX (uptr);
362 if (diskUnitIdx < 0 || diskUnitIdx >= N_DSK_UNITS_MAX)
363 {
364 sim_printf ("error: Invalid unit number %ld\r\n", (long) diskUnitIdx);
365 return SCPE_ARG;
366 }
367
368 sim_printf("type : %s", diskTypes[dsk_states[diskUnitIdx].typeIdx].typename);
369
370 return SCPE_OK;
371 }
372
373 static t_stat disk_set_type (UNUSED UNIT * uptr, UNUSED int32 value, const char * cptr, UNUSED void * desc)
374 {
375 int diskUnitIdx = (int) DSK_UNIT_IDX (uptr);
376 if (diskUnitIdx < 0 || diskUnitIdx >= N_DSK_UNITS_MAX)
377 {
378 sim_printf ("error: Invalid unit number %ld\r\n", (long) diskUnitIdx);
379 return SCPE_ARG;
380 }
381
382 uint i;
383 for (i = 0; i < N_DISK_TYPES; i++)
384 {
385 if (strcasecmp (cptr, diskTypes[i].typename) == 0)
386 break;
387 }
388 if (i >= N_DISK_TYPES)
389 {
390 sim_printf ("Disk type %s unrecognized, expected one of "
391 "%s %s %s %s %s %s %s %s\r\n",
392 cptr,
393 diskTypes[0].typename,
394 diskTypes[1].typename,
395 diskTypes[2].typename,
396 diskTypes[3].typename,
397 diskTypes[4].typename,
398 diskTypes[5].typename,
399 diskTypes[6].typename,
400 diskTypes[7].typename);
401 return SCPE_ARG;
402 }
403 dsk_states[diskUnitIdx].typeIdx = i;
404 dsk_unit[diskUnitIdx].capac = (t_addr) diskTypes[i].capac;
405 dsk_states[diskUnitIdx].tAndDCapac = tAndDCapac[i];
406 return SCPE_OK;
407 }
408
409 static t_stat dsk_show_device_name (UNUSED FILE * st, UNIT * uptr,
410 UNUSED int val, UNUSED const void * desc)
411 {
412 int n = (int) DSK_UNIT_IDX (uptr);
413 if (n < 0 || n >= N_DSK_UNITS_MAX)
414 return SCPE_ARG;
415 sim_printf("name : %s", dsk_states[n].device_name);
416 return SCPE_OK;
417 }
418
419 static t_stat dsk_set_device_name (UNIT * uptr, UNUSED int32 value,
420 const char * cptr, UNUSED void * desc)
421 {
422 int n = (int) DSK_UNIT_IDX (uptr);
423 if (n < 0 || n >= N_DSK_UNITS_MAX)
424 return SCPE_ARG;
425 if (cptr)
426 {
427 strncpy (dsk_states[n].device_name, cptr, MAX_DEV_NAME_LEN-1);
428 dsk_states[n].device_name[MAX_DEV_NAME_LEN-1] = 0;
429 }
430 else
431 dsk_states[n].device_name[0] = 0;
432 return SCPE_OK;
433 }
434
435
436
437
438
439
440
441 t_stat signal_disk_ready (uint dsk_unit_idx) {
442
443 if (! sim_is_running)
444 return SCPE_OK;
445
446
447
448
449
450
451
452
453
454
455
456
457
458 uint ctlr_unit_idx = cables->dsk_to_ctlr[dsk_unit_idx].ctlr_unit_idx;
459 enum ctlr_type_e ctlr_type = cables->dsk_to_ctlr[dsk_unit_idx].ctlr_type;
460 if (ctlr_type != CTLR_T_MSP && ctlr_type != CTLR_T_IPC) {
461
462 if (ctlr_type != CTLR_T_NONE) {
463 sim_warn ("loadDisk lost\r\n");
464 return SCPE_ARG;
465 }
466 return SCPE_OK;
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 for (uint ctlr_port_num = 0; ctlr_port_num < MAX_CTLR_PORTS; ctlr_port_num ++) {
508 if (ctlr_type == CTLR_T_MSP) {
509 if (cables->msp_to_iom[ctlr_unit_idx][ctlr_port_num].in_use) {
510 uint iom_unit_idx = cables->msp_to_iom[ctlr_unit_idx][ctlr_port_num].iom_unit_idx;
511 uint chan_num = cables->msp_to_iom[ctlr_unit_idx][ctlr_port_num].chan_num;
512 uint dev_code = cables->dsk_to_ctlr[dsk_unit_idx].dev_code;
513
514 send_special_interrupt (iom_unit_idx, chan_num, dev_code, 0x40, 01 );
515 return SCPE_OK;
516 }
517 } else {
518 if (cables->ipc_to_iom[ctlr_unit_idx][ctlr_port_num].in_use) {
519 uint iom_unit_idx = cables->ipc_to_iom[ctlr_unit_idx][ctlr_port_num].iom_unit_idx;
520 uint chan_num = cables->ipc_to_iom[ctlr_unit_idx][ctlr_port_num].chan_num;
521 uint dev_code = cables->dsk_to_ctlr[dsk_unit_idx].dev_code;
522
523 send_special_interrupt (iom_unit_idx, chan_num, dev_code, 0x40, 01 );
524 return SCPE_OK;
525 }
526 }
527 }
528 return SCPE_ARG;
529
530 }
531
532 static t_stat disk_set_ready (UNIT * uptr, UNUSED int32 value,
533 UNUSED const char * cptr,
534 UNUSED void * desc)
535 {
536 long disk_unit_idx = DSK_UNIT_IDX (uptr);
537 if (disk_unit_idx >= (long) dsk_dev.numunits)
538 {
539 sim_warn ("%s: error: Invalid unit number %ld\r\n", __func__, (long) disk_unit_idx);
540 return SCPE_ARG;
541 }
542 return signal_disk_ready ((uint) disk_unit_idx);
543 }
544
545 t_stat unloadDisk (uint dsk_unit_idx) {
546 if (dsk_unit [dsk_unit_idx] . flags & UNIT_ATT) {
547 t_stat stat = sim_disk_detach (& dsk_unit [dsk_unit_idx]);
548 if (stat != SCPE_OK) {
549 sim_warn ("%s: sim_disk_detach returned %ld\r\n", __func__, (long) stat);
550 return SCPE_ARG;
551 }
552 }
553 return signal_disk_ready ((uint) dsk_unit_idx);
554 }
555
556 t_stat loadDisk (uint dsk_unit_idx, const char * disk_filename, bool ro) {
557 if (ro)
558 dsk_unit[dsk_unit_idx].flags |= MTUF_WRP;
559 else
560 dsk_unit[dsk_unit_idx].flags &= ~ MTUF_WRP;
561 t_stat stat = attach_unit (& dsk_unit [dsk_unit_idx], disk_filename);
562 if (stat != SCPE_OK) {
563 sim_printf ("%s: sim_disk_attach returned %d\r\n", __func__, stat);
564 return stat;
565 }
566 return signal_disk_ready ((uint) dsk_unit_idx);
567 }
568
569 #define UNIT_WATCH UNIT_V_UF
570
571 static MTAB disk_mod[] =
572 {
573 #if !defined(SPEED)
574 { UNIT_WATCH, 1, "WATCH", "WATCH", 0, 0, NULL, NULL },
575 { UNIT_WATCH, 0, "NOWATCH", "NOWATCH", 0, 0, NULL, NULL },
576 #endif
577 {
578 MTAB_dev_value,
579 0,
580 "NUNITS",
581 "NUNITS",
582 disk_set_nunits,
583 disk_show_nunits,
584 "Number of DISK units in the system",
585 NULL
586 },
587 {
588 MTAB_unit_value_show,
589 0,
590 "TYPE",
591 "TYPE",
592 disk_set_type,
593 disk_show_type,
594 "disk type",
595 "D500, D451, D400, D190, D181, D501, 3380, 3381",
596 },
597 {
598 MTAB_XTD | MTAB_VUN | MTAB_VALR | MTAB_NC,
599 0,
600 "NAME",
601 "NAME",
602 dsk_set_device_name,
603 dsk_show_device_name,
604 "Set the device name",
605 NULL
606 },
607 {
608 MTAB_XTD | MTAB_VUN | MTAB_NMO | MTAB_VALR,
609 0,
610 "READY",
611 "READY",
612 disk_set_ready,
613 NULL,
614 NULL,
615 NULL
616 },
617 MTAB_eol
618 };
619
620 static t_stat disk_reset (UNUSED DEVICE * dptr)
621 {
622 return SCPE_OK;
623 }
624
625 static t_stat disk_attach (UNIT *uptr, CONST char *cptr)
626 {
627 int diskUnitIdx = (int) DSK_UNIT_IDX (uptr);
628 if (diskUnitIdx < 0 || diskUnitIdx >= N_DSK_UNITS_MAX)
629 {
630 sim_printf ("error: Invalid unit number %ld\r\n", (long) diskUnitIdx);
631 return SCPE_ARG;
632 }
633
634 return loadDisk ((uint) diskUnitIdx, cptr, false);
635 }
636
637
638 DEVICE dsk_dev = {
639 "DISK",
640 dsk_unit,
641 NULL,
642 disk_mod,
643 N_DISK_UNITS,
644 10,
645 24,
646 1,
647 8,
648 36,
649 NULL,
650 NULL,
651 disk_reset,
652 NULL,
653 disk_attach,
654 NULL ,
655 NULL,
656 DEV_DEBUG,
657 0,
658 disk_dt,
659 NULL,
660 NULL,
661 NULL,
662 NULL,
663 NULL,
664 NULL,
665 NULL
666 };
667
668
669
670
671
672
673
674 void disk_init (void)
675 {
676
677 (void)memset (dsk_states, 0, sizeof (dsk_states));
678
679 for (uint i = 0; i < N_DSK_UNITS_MAX; i ++)
680 dsk_states [i].tAndDCapac = tAndDCapac [dsk_states [i].typeIdx];
681 #if defined(LOCKLESS)
682 # if defined(__FreeBSD__)
683 pthread_mutexattr_t scu_attr;
684 pthread_mutexattr_init (& scu_attr);
685 pthread_mutexattr_settype (& scu_attr, PTHREAD_MUTEX_ADAPTIVE_NP);
686 # endif
687 for (uint i = 0; i < N_DSK_UNITS_MAX; i ++)
688 {
689 # if defined(__FreeBSD__)
690 pthread_mutex_init (& dsk_states[i].dsk_lock, & scu_attr);
691 # else
692 pthread_mutex_init (& dsk_states[i].dsk_lock, NULL);
693 # endif
694 }
695 #endif
696 }
697
698 static iom_cmd_rc_t diskSeek64 (uint devUnitIdx, uint iomUnitIdx, uint chan)
699 {
700 iom_chan_data_t * p = & iom_chan_data[iomUnitIdx][chan];
701 struct dsk_state * disk_statep = & dsk_states[devUnitIdx];
702
703 uint typeIdx = disk_statep->typeIdx;
704 if (diskTypes[typeIdx].seekSize != seek_64)
705 sim_warn ("%s: disk%u sent a SEEK_64 but is 512 sized\r\n", __func__, typeIdx);
706
707 uint tally = p->DDCW_TALLY;
708
709
710
711 if (tally != 1)
712 {
713 sim_printf ("disk seek dazed by tally %d != 1\r\n", tally);
714 p->stati = 04510;
715 return IOM_CMD_ERROR;
716 }
717
718 word36 seekData[1];
719 uint count;
720 iom_indirect_data_service (iomUnitIdx, chan, seekData, &count, false);
721
722 p->initiate = true;
723 if (count != 1)
724 sim_warn ("%s: count %d not 1\r\n", __func__, count);
725
726 #if defined(POLTS_DISK_TESTING)
727 if_sim_debug (DBG_TRACE, & dsk_dev) { sim_printf ("// Seek address %012"PRIo64"\r\n", seekData[0]); }
728 #endif
729
730
731
732
733
734
735 seekData[0] &= MASK21;
736 if (seekData[0] >= diskTypes[typeIdx].capac)
737 {
738 disk_statep->seekValid = false;
739 p->stati = 04304;
740 return IOM_CMD_ERROR;
741 }
742 disk_statep->seekValid = true;
743 disk_statep->seekPosition = (uint) seekData[0];
744 p->stati = 04000;
745 return IOM_CMD_PROCEED;
746 }
747
748 static int diskSeek512 (uint devUnitIdx, uint iomUnitIdx, uint chan)
749 {
750 iom_chan_data_t * p = & iom_chan_data[iomUnitIdx][chan];
751 struct dsk_state * disk_statep = & dsk_states[devUnitIdx];
752 uint typeIdx = disk_statep->typeIdx;
753 if (diskTypes[typeIdx].seekSize != seek_512)
754 sim_warn ("%s: disk%u sent a SEEK_512 but is 64 sized\r\n", __func__, typeIdx);
755
756 uint tally = p->DDCW_TALLY;
757
758
759
760 if (tally != 1)
761 {
762 sim_printf ("disk seek dazed by tally %d != 1\r\n", tally);
763
764
765
766 tally = 1;
767 }
768
769 word36 seekData[1];
770 uint count;
771 iom_indirect_data_service (iomUnitIdx, chan, seekData, &count, false);
772
773 p->initiate = true;
774 if (count != 1)
775 sim_warn ("%s: count %d not 1\r\n", __func__, count);
776
777 seekData[0] &= MASK21;
778 if (seekData[0] >= diskTypes[typeIdx].capac)
779 {
780 disk_statep->seekValid = false;
781 p->stati = 04304;
782 return -1;
783 }
784 disk_statep->seekValid = true;
785 disk_statep->seekPosition = (uint)seekData[0];
786 p->stati = 04000;
787 return 0;
788 }
789
790 static iom_cmd_rc_t diskSeekSpecial (uint devUnitIdx, uint iomUnitIdx, uint chan)
791 {
792 iom_chan_data_t * p = & iom_chan_data[iomUnitIdx][chan];
793 struct dsk_state * disk_statep = & dsk_states[devUnitIdx];
794
795
796
797
798 uint tally = p->DDCW_TALLY;
799
800
801
802 if (tally != 1)
803 {
804 sim_printf ("disk seek dazed by tally %d != 1\r\n", tally);
805
806
807
808 tally = 1;
809 }
810
811 word36 seekData[1];
812 uint count;
813 iom_indirect_data_service (iomUnitIdx, chan, seekData, &count, false);
814
815 p->initiate = true;
816 if (count != 1)
817 sim_warn ("%s: count %d not 1\r\n", __func__, count);
818
819 #if defined(POLTS_DISK_TESTING)
820 if_sim_debug (DBG_TRACE, & dsk_dev)
821 {
822 sim_printf ("// Seek address %012"PRIo64"\r\n", seekData[0]);
823 }
824 #endif
825
826 seekData[0] &= MASK21;
827 if (seekData[0] >= disk_statep->tAndDCapac)
828 {
829 p->stati = 04304;
830 disk_statep->seekValid = false;
831
832 return IOM_CMD_ERROR;
833 }
834 disk_statep->seekValid = true;
835 disk_statep->seekPosition = (uint) seekData[0];
836 p->stati = 04000;
837 return IOM_CMD_PROCEED;
838 }
839
840 static int diskRead (uint devUnitIdx, uint iomUnitIdx, uint chan)
841 {
842 iom_chan_data_t * p = & iom_chan_data[iomUnitIdx][chan];
843 UNIT * unitp = & dsk_unit[devUnitIdx];
844 struct dsk_state * disk_statep = & dsk_states[devUnitIdx];
845 uint typeIdx = disk_statep->typeIdx;
846 uint sectorSizeWords = diskTypes[typeIdx].sectorSizeWords;
847 uint sectorSizeBytes = ((36 * sectorSizeWords) / 8);
848
849 if (! unitp->fileref) {
850 p->stati = 04240;
851 #if defined(POLTS_TESTING)
852 if (chan == 014)
853 if_sim_debug (DBG_TRACE, & dsk_dev) sim_printf ("// diskRead device offline\r\n");
854 #endif
855 return -1;
856 }
857 if (! disk_statep->seekValid) {
858 p->stati = 04510;
859 disk_statep->seekValid = false;
860 #if defined(POLTS_TESTING)
861 if (chan == 014)
862 if_sim_debug (DBG_TRACE, & dsk_dev) sim_printf ("// diskRead seek invalid\r\n");
863 #endif
864 return IOM_CMD_ERROR;
865 }
866 uint tally = p->DDCW_TALLY;
867 if (tally == 0)
868 {
869 tally = 4096;
870 }
871
872 int rc = fseek (unitp->fileref,
873 (long) ((long)disk_statep->seekPosition * (long)sectorSizeBytes),
874 SEEK_SET);
875 if (rc)
876 {
877 sim_warn ("%s: fseek (read) returned %d, errno %d\r\n", __func__, rc, errno);
878 p->stati = 04202;
879 #if defined(POLTS_TESTING)
880 if (chan == 014)
881 if_sim_debug (DBG_TRACE, & dsk_dev) sim_printf ("// diskRead seek incomplete\r\n");
882 #endif
883 return -1;
884 }
885
886
887
888
889
890
891
892 uint tallySectors = (tally + sectorSizeWords - 1) /
893 sectorSizeWords;
894 uint tallyWords = tallySectors * sectorSizeWords;
895
896 uint p72ByteCnt = (tallyWords * 36) / 8;
897 uint8 diskBuffer[p72ByteCnt];
898 (void)memset (diskBuffer, 0, sizeof (diskBuffer));
899
900 (void)fflush (unitp->fileref);
901 rc = (int) fread (diskBuffer, sectorSizeBytes,
902 tallySectors,
903 unitp->fileref);
904
905 if (rc == 0)
906 {
907 if (ferror (unitp->fileref))
908 {
909 p->stati = 04202;
910
911 #if defined(POLTS_TESTING)
912 if (chan == 014)
913 if_sim_debug (DBG_TRACE, & dsk_dev) sim_printf ("// diskRead seek incomplete2\r\n");
914 #endif
915 return -1;
916 }
917
918
919
920 }
921 disk_statep->seekPosition += tallySectors;
922
923 uint wordsProcessed = 0;
924 word36 buffer[tally];
925 for (uint i = 0; i < tally; i ++)
926 {
927 word36 w;
928 extractWord36FromBuffer (diskBuffer, p72ByteCnt, & wordsProcessed,
929 & w);
930 buffer[i] = w;
931 }
932 iom_indirect_data_service (iomUnitIdx, chan, buffer,
933 & wordsProcessed, true);
934 p->stati = 04000;
935 #if defined(POLTS_TESTING)
936 if (chan == 014)
937 if_sim_debug (DBG_TRACE, & dsk_dev) sim_printf ("// diskRead ok\r\n");
938 #endif
939 return 0;
940 }
941
942 static int diskWrite (uint devUnitIdx, uint iomUnitIdx, uint chan)
943 {
944 iom_chan_data_t * p = & iom_chan_data[iomUnitIdx][chan];
945 UNIT * unitp = & dsk_unit[devUnitIdx];
946 struct dsk_state * disk_statep = & dsk_states[devUnitIdx];
947 uint typeIdx = disk_statep->typeIdx;
948 uint sectorSizeWords = diskTypes[typeIdx].sectorSizeWords;
949 uint sectorSizeBytes = ((36 * sectorSizeWords) / 8);
950
951 if (! unitp->fileref) {
952 p->stati = 04240;
953 return -1;
954 }
955
956 if (! disk_statep->seekValid) {
957 p->stati = 04510;
958 disk_statep->seekValid = false;
959 return IOM_CMD_ERROR;
960 }
961
962 uint tally = p->DDCW_TALLY;
963
964 if (tally == 0)
965 {
966 tally = 4096;
967 }
968
969 int rc = fseek (unitp->fileref,
970 (long) ((long)disk_statep->seekPosition * (long)sectorSizeBytes),
971 SEEK_SET);
972 if (rc)
973 {
974 sim_printf ("fseek (read) returned %d, errno %d\r\n", rc, errno);
975 p->stati = 04202;
976 return -1;
977 }
978
979
980
981
982
983
984
985 uint tallySectors = (tally + sectorSizeWords - 1) /
986 sectorSizeWords;
987 uint tallyWords = tallySectors * sectorSizeWords;
988 uint p72ByteCnt = (tallyWords * 36) / 8;
989 uint8 diskBuffer[p72ByteCnt];
990 (void)memset (diskBuffer, 0, sizeof (diskBuffer));
991 uint wordsProcessed = 0;
992
993 word36 buffer[tally];
994 iom_indirect_data_service (iomUnitIdx, chan, buffer,
995 & wordsProcessed, false);
996 wordsProcessed = 0;
997 for (uint i = 0; i < tally; i ++)
998 {
999 insertWord36toBuffer (diskBuffer, p72ByteCnt, & wordsProcessed,
1000 buffer[i]);
1001 }
1002
1003 rc = (int) fwrite (diskBuffer, sectorSizeBytes,
1004 tallySectors,
1005 unitp->fileref);
1006 (void)fflush (unitp->fileref);
1007
1008 if (rc != (int) tallySectors)
1009 {
1010 sim_printf ("fwrite returned %d, errno %d\r\n", rc, errno);
1011 p->stati = 04202;
1012 p->chanStatus = chanStatIncorrectDCW;
1013 return -1;
1014 }
1015
1016 disk_statep->seekPosition += tallySectors;
1017
1018 p->stati = 04000;
1019 return 0;
1020 }
1021
1022 static int readStatusRegister (uint devUnitIdx, uint iomUnitIdx, uint chan)
1023 {
1024 iom_chan_data_t * p = & iom_chan_data[iomUnitIdx][chan];
1025 UNIT * unitp = & dsk_unit[devUnitIdx];
1026
1027 uint tally = p->DDCW_TALLY;
1028
1029
1030
1031 if (tally != 2 && tally != 4 && tally != 6)
1032 {
1033 sim_warn ("%s: RSR expected tally of 2, 4 or 6, is %d\r\n",
1034 __func__, tally);
1035 }
1036 if (tally == 0)
1037 {
1038 tally = 4096;
1039 }
1040
1041
1042
1043
1044 #if defined(TESTING)
1045 sim_warn ("Need status register data format\r\n");
1046 #endif
1047 word36 buffer[tally];
1048 (void)memset (buffer, 0, sizeof (buffer));
1049 #if defined(POLTS_DISK_TESTING)
1050 buffer[0] = nCmds;
1051 #endif
1052 uint wordsProcessed = tally;
1053 iom_indirect_data_service (iomUnitIdx, chan, buffer,
1054 & wordsProcessed, true);
1055 p->charPos = 0;
1056 p->stati = 04000;
1057 if (! unitp->fileref)
1058 p->stati = 04240;
1059 return 0;
1060 }
1061
1062 static int diskRdCtrlReg (uint dev_unit_idx, uint iom_unit_idx, uint chan) {
1063 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
1064 UNIT * unitp = & dsk_unit[dev_unit_idx];
1065 p->charPos = 0;
1066 p->stati = 04000;
1067 if (! unitp->fileref)
1068 p->stati = 04240;
1069 return 0;
1070 }
1071
1072 static int read_configuration (uint dev_unit_idx, uint iom_unit_idx, uint chan)
1073 {
1074 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
1075 UNIT * unitp = & dsk_unit[dev_unit_idx];
1076
1077 uint tally = p->DDCW_TALLY;
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
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145 uint ctlr_unit_idx = get_ctlr_idx (iom_unit_idx, chan);
1146 struct ctlr_to_dev_s * dev_p;
1147 if (cables->iom_to_ctlr[iom_unit_idx][chan].ctlr_type == CTLR_T_IPC)
1148 dev_p = cables->ipc_to_dsk[ctlr_unit_idx];
1149 else
1150 dev_p = cables->msp_to_dsk[ctlr_unit_idx];
1151
1152
1153 word36 buffer[tally];
1154 (void)memset (buffer, 0, sizeof (buffer));
1155 putbits36_9 (& buffer[0], 0, 0x12);
1156 putbits36_9 (& buffer[0], 9, 1);
1157 putbits36_9 (& buffer[0], 18, '1');
1158 putbits36_9 (& buffer[0], 27, 'a');
1159
1160 for (word9 dev_num = 0; dev_num < N_DEV_CODES; dev_num ++)
1161 {
1162 if (! dev_p[dev_num].in_use)
1163 continue;
1164 uint dsk_unit_idx = dev_p[dev_num].unit_idx;
1165
1166
1167 word9 dau_type = (word9) diskTypes[dsk_states[dsk_unit_idx].typeIdx].dau_type;
1168 putbits36_9 (& buffer[1+dev_num], 0, dau_type);
1169 putbits36_9 (& buffer[1+dev_num], 9, dev_num);
1170 putbits36_9 (& buffer[1+dev_num], 18, 0);
1171 putbits36_9 (& buffer[1+dev_num], 27, dev_num);
1172 }
1173
1174 uint wordsProcessed = tally;
1175 iom_indirect_data_service (iom_unit_idx, chan, buffer,
1176 & wordsProcessed, true);
1177 p->charPos = 0;
1178 p->stati = 04000;
1179 if (! unitp->fileref)
1180 p->stati = 04240;
1181 return 0;
1182 }
1183
1184 static int read_and_clear_statistics (uint dev_unit_idx, uint iom_unit_idx, uint chan)
1185 {
1186 #if defined(TESTING)
1187 cpu_state_t * cpup = _cpup;
1188 #endif
1189 iom_chan_data_t * p = & iom_chan_data[iom_unit_idx][chan];
1190 UNIT * unitp = & dsk_unit[dev_unit_idx];
1191
1192 sim_debug (DBG_NOTIFY, & dsk_dev, "Read %d\r\n", dev_unit_idx);
1193
1194 p->charPos = 0;
1195 p->stati = 04000;
1196 if (! unitp->fileref)
1197 p->stati = 04240;
1198 return 0;
1199 }
1200
1201
1202
1203
1204
1205
1206
1207
1208 iom_cmd_rc_t dsk_iom_cmd (uint iomUnitIdx, uint chan) {
1209 #if defined(POLTS_DISK_TESTING)
1210 nCmds ++;
1211 #endif
1212 #if defined(TESTING)
1213 cpu_state_t * cpup = _cpup;
1214 #endif
1215 iom_chan_data_t * p = & iom_chan_data[iomUnitIdx][chan];
1216 uint ctlr_unit_idx = get_ctlr_idx (iomUnitIdx, chan);
1217 uint devUnitIdx;
1218
1219 #if defined(POLTS_DISK_TESTING)
1220 if (chan == 014) {if_sim_debug (DBG_TRACE, & dsk_dev) { dumpDCW (p->DCW, 0); }}
1221 #endif
1222 if (cables->iom_to_ctlr[iomUnitIdx][chan].ctlr_type == CTLR_T_IPC)
1223 devUnitIdx = cables->ipc_to_dsk[ctlr_unit_idx][p->IDCW_DEV_CODE].unit_idx;
1224 else if (cables->iom_to_ctlr[iomUnitIdx][chan].ctlr_type == CTLR_T_MSP)
1225 devUnitIdx = cables->msp_to_dsk[ctlr_unit_idx][p->IDCW_DEV_CODE].unit_idx;
1226 else {
1227 sim_warn ("%s: Can't find controller (%d)\r\n", __func__, cables->iom_to_ctlr[iomUnitIdx][chan].ctlr_type);
1228 return IOM_CMD_ERROR;
1229 }
1230
1231 UNIT * unitp = & dsk_unit[devUnitIdx];
1232 struct dsk_state * disk_statep = & dsk_states[devUnitIdx];
1233
1234 iom_cmd_rc_t rc = IOM_CMD_PROCEED;
1235
1236 #if defined(LOCKLESS)
1237 lock_ptr (& dsk_states->dsk_lock);
1238 #endif
1239
1240
1241 if (p->DCW_18_20_CP == 7) {
1242
1243 disk_statep->io_mode = disk_no_mode;
1244 switch (p->IDCW_DEV_CMD) {
1245 case 000:
1246 #if defined(POLTS_DISK_TESTING)
1247
1248 #endif
1249 #if !defined(POLTS_DISK_TESTING)
1250 if_sim_debug (DBG_TRACE, & dsk_dev) {
1251 sim_printf ("// Disk Request Status\r\n");
1252 }
1253 #endif
1254
1255 p->stati = 04000;
1256 if (! unitp->fileref)
1257 p->stati = 04240;
1258 break;
1259
1260 case 016:
1261 #if defined(POLTS_DISK_TESTING)
1262 if (chan == 014)
1263 #endif
1264 if_sim_debug (DBG_TRACE, & dsk_dev) {
1265 sim_printf ("// Disk Read And Clear Statistics\r\n");
1266 }
1267 disk_statep->io_mode = disk_rd_clr_stats;
1268 p->recordResidue --;
1269 p->stati = 04000;
1270 if (! unitp->fileref)
1271 p->stati = 04240;
1272 break;
1273
1274 case 022:
1275 #if defined(POLTS_DISK_TESTING)
1276 if (chan == 014)
1277 #endif
1278 if_sim_debug (DBG_TRACE, & dsk_dev) {
1279 sim_printf ("// Disk Read Status Register\r\n");
1280 }
1281 disk_statep->io_mode = disk_rd_status_reg;
1282 p->recordResidue --;
1283 p->stati = 04000;
1284 if (! unitp->fileref)
1285 p->stati = 04240;
1286 break;
1287
1288 case 024:
1289 #if defined(POLTS_DISK_TESTING)
1290 if (chan == 014)
1291 #endif
1292 if_sim_debug (DBG_TRACE, & dsk_dev) {
1293 sim_printf ("// Disk Read Configuration\r\n");
1294 }
1295 disk_statep->io_mode = disk_rd_config;
1296 p->recordResidue --;
1297 p->stati = 04000;
1298 if (! unitp->fileref)
1299 p->stati = 04240;
1300 break;
1301
1302 case 025:
1303 #if defined(POLTS_DISK_TESTING)
1304 if (chan == 014)
1305 #endif
1306 if_sim_debug (DBG_TRACE, & dsk_dev) {
1307 sim_printf ("// Disk Read\r\n");
1308 }
1309 disk_statep->io_mode = disk_rd;
1310 p->recordResidue --;
1311 p->stati = 04000;
1312 if (! unitp->fileref)
1313 p->stati = 04240;
1314 break;
1315
1316 case 026:
1317 #if defined(POLTS_DISK_TESTING)
1318 if (chan == 014)
1319 #endif
1320 if_sim_debug (DBG_TRACE, & dsk_dev) {
1321 sim_printf ("// Disk Read Control Register\r\n");
1322 }
1323 disk_statep->io_mode = disk_rd_ctrl_reg;
1324 p->recordResidue --;
1325 p->stati = 04000;
1326 if (! unitp->fileref)
1327 p->stati = 04240;
1328 break;
1329
1330 case 030:
1331 #if defined(POLTS_DISK_TESTING)
1332 if (chan == 014)
1333 #endif
1334 if_sim_debug (DBG_TRACE, & dsk_dev) {
1335 sim_printf ("// Disk Seek 512\r\n");
1336 }
1337 disk_statep->io_mode = disk_seek_512;
1338 p->recordResidue --;
1339 p->stati = 04000;
1340 if (! unitp->fileref)
1341 p->stati = 04240;
1342 break;
1343
1344 case 031:
1345 case 033:
1346 #if defined(POLTS_DISK_TESTING)
1347 if (chan == 014)
1348 #endif
1349 if_sim_debug (DBG_TRACE, & dsk_dev) {
1350 sim_printf ("// Disk Write\r\n");
1351 }
1352 disk_statep->io_mode = disk_wr;
1353 p->recordResidue --;
1354 p->stati = 04000;
1355 if (! unitp->fileref)
1356 p->stati = 04240;
1357 break;
1358
1359 case 034:
1360 #if defined(POLTS_DISK_TESTING)
1361 if (chan == 014)
1362 #endif
1363 if_sim_debug (DBG_TRACE, & dsk_dev) {
1364 sim_printf ("// Disk Seek 64\r\n");
1365 }
1366 disk_statep->io_mode = disk_seek_64;
1367 p->recordResidue --;
1368 p->stati = 04000;
1369 if (! unitp->fileref)
1370 p->stati = 04240;
1371 break;
1372
1373 case 036:
1374
1375 #if defined(POLTS_DISK_TESTING)
1376 if (chan == 014)
1377 #endif
1378 if_sim_debug (DBG_TRACE, & dsk_dev) {
1379 sim_printf ("// Disk Special Seek\r\n");
1380 }
1381 disk_statep->io_mode = disk_special_seek;
1382 p->recordResidue --;
1383 p->stati = 04000;
1384 if (! unitp->fileref)
1385 p->stati = 04240;
1386 break;
1387
1388 case 040:
1389 #if defined(POLTS_DISK_TESTING)
1390 if (chan == 014)
1391 #endif
1392 if_sim_debug (DBG_TRACE, & dsk_dev) {
1393 sim_printf ("// Disk Reset Status\r\n");
1394 }
1395 p->stati = 04000;
1396
1397 p->recordResidue --;
1398 p->initiate = false;
1399 p->isRead = false;
1400
1401 if (p->IDCW_DEV_CODE == 077) {
1402 p->stati = 04502;
1403 #if defined(LOCKLESS)
1404 unlock_ptr (& dsk_states->dsk_lock);
1405 #endif
1406 return IOM_CMD_DISCONNECT;
1407 }
1408 if (! unitp->fileref)
1409 p->stati = 04240;
1410 break;
1411
1412 case 042:
1413 #if defined(POLTS_DISK_TESTING)
1414 if (chan == 014)
1415 #endif
1416 if_sim_debug (DBG_TRACE, & dsk_dev) {
1417 sim_printf ("// Disk Restore\r\n");
1418 }
1419 p->stati = 04000;
1420
1421 p->recordResidue --;
1422 p->initiate = false;
1423 if (! unitp->fileref)
1424 p->stati = 04240;
1425
1426 disk_statep->seekValid = false;
1427
1428 break;
1429
1430 case 072:
1431 #if defined(POLTS_DISK_TESTING)
1432 if (chan == 014)
1433 #endif
1434 if_sim_debug (DBG_TRACE, & dsk_dev) {
1435 sim_printf ("// Disk Set Standby\r\n");
1436 }
1437 p->stati = 04000;
1438 if (! unitp->fileref)
1439 p->stati = 04240;
1440 break;
1441
1442 default:
1443 #if defined(POLTS_DISK_TESTING)
1444 if (chan == 014)
1445 #endif
1446 if_sim_debug (DBG_TRACE, & dsk_dev) {
1447 sim_printf ("// Disk unknown command %o\r\n", p->IDCW_DEV_CMD);
1448 }
1449 p->stati = 04501;
1450 p->chanStatus = chanStatIncorrectDCW;
1451 if (p->IDCW_DEV_CMD != 051)
1452 sim_warn ("%s: Unrecognized device command %02o\r\n", __func__, p->IDCW_DEV_CMD);
1453 rc = IOM_CMD_ERROR;
1454 goto done;
1455 }
1456 goto done;
1457 }
1458
1459
1460 switch (disk_statep->io_mode) {
1461 case disk_no_mode:
1462 #if defined(POLTS_DISK_TESTING)
1463 if (chan == 014)
1464 #endif
1465 if_sim_debug (DBG_TRACE, & dsk_dev) {
1466 sim_printf ("// Disk IOT No Mode\r\n");
1467 }
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480 goto done;
1481
1482 case disk_rd_clr_stats: {
1483 #if defined(POLTS_DISK_TESTING)
1484 if (chan == 014)
1485 #endif
1486 if_sim_debug (DBG_TRACE, & dsk_dev) {
1487 sim_printf ("// Disk IOT Rd And Clr Stats\r\n");
1488 }
1489 int rc1 = read_and_clear_statistics (devUnitIdx, iomUnitIdx, chan);
1490 if (rc1) {
1491 rc = IOM_CMD_ERROR;
1492 goto done;
1493 }
1494 }
1495 break;
1496
1497 case disk_rd_status_reg: {
1498 #if defined(POLTS_DISK_TESTING)
1499 if (chan == 014)
1500 #endif
1501 if_sim_debug (DBG_TRACE, & dsk_dev) {
1502 sim_printf ("// Disk IOT Rd Status Reg\r\n");
1503 }
1504 int rc1 = readStatusRegister (devUnitIdx, iomUnitIdx, chan);
1505 if (rc1) {
1506 rc = IOM_CMD_ERROR;
1507 goto done;
1508 }
1509 }
1510 break;
1511
1512 case disk_rd_config: {
1513 #if defined(POLTS_DISK_TESTING)
1514 if (chan == 014)
1515 #endif
1516 if_sim_debug (DBG_TRACE, & dsk_dev) {
1517 sim_printf ("// Disk IOT Rd Config\r\n");
1518 }
1519
1520 int rc1 = read_configuration (devUnitIdx, iomUnitIdx, chan);
1521 if (rc1) {
1522 rc = IOM_CMD_ERROR;
1523 goto done;
1524 }
1525 }
1526 break;
1527
1528 case disk_rd: {
1529 #if defined(POLTS_DISK_TESTING)
1530 if (chan == 014)
1531 #endif
1532 if_sim_debug (DBG_TRACE, & dsk_dev) {
1533 sim_printf ("// Disk IOT Read\r\n");
1534 }
1535 int rc1 = diskRead (devUnitIdx, iomUnitIdx, chan);
1536 if (rc1) {
1537 rc = IOM_CMD_ERROR;
1538 goto done;
1539 }
1540 }
1541 break;
1542
1543 case disk_rd_ctrl_reg: {
1544 #if defined(POLTS_DISK_TESTING)
1545 if (chan == 014)
1546 #endif
1547 if_sim_debug (DBG_TRACE, & dsk_dev) {
1548 sim_printf ("// Disk IOT Read Control Register\r\n");
1549 }
1550 int rc1 = diskRdCtrlReg (devUnitIdx, iomUnitIdx, chan);
1551 if (rc1) {
1552 rc = IOM_CMD_ERROR;
1553 goto done;
1554 }
1555 }
1556 break;
1557
1558 case disk_seek_512: {
1559 #if defined(POLTS_DISK_TESTING)
1560 if (chan == 014)
1561 #endif
1562 if_sim_debug (DBG_TRACE, & dsk_dev) {
1563 sim_printf ("// Disk IOT Seek 512\r\n");
1564 }
1565 int rc1 = diskSeek512 (devUnitIdx, iomUnitIdx, chan);
1566 if (rc1) {
1567 rc = IOM_CMD_ERROR;
1568 goto done;
1569 }
1570 }
1571 break;
1572
1573 case disk_wr: {
1574 #if defined(POLTS_DISK_TESTING)
1575 if (chan == 014)
1576 #endif
1577 if_sim_debug (DBG_TRACE, & dsk_dev) {
1578 sim_printf ("// Disk IOT Write\r\n");
1579 }
1580 int rc1 = diskWrite (devUnitIdx, iomUnitIdx, chan);
1581 if (rc1) {
1582 rc = IOM_CMD_ERROR;
1583 goto done;
1584 }
1585 }
1586 break;
1587
1588 case disk_seek_64: {
1589 #if defined(POLTS_DISK_TESTING)
1590 if (chan == 014)
1591 #endif
1592 if_sim_debug (DBG_TRACE, & dsk_dev) {
1593 sim_printf ("// Disk IOT Seek 64\r\n");
1594 }
1595 int rc1 = diskSeek64 (devUnitIdx, iomUnitIdx, chan);
1596 if (rc1) {
1597 rc = IOM_CMD_ERROR;
1598 goto done;
1599 }
1600 }
1601 break;
1602
1603 case disk_special_seek: {
1604 #if defined(POLTS_DISK_TESTING)
1605 if (chan == 014)
1606 #endif
1607 if_sim_debug (DBG_TRACE, & dsk_dev) {
1608 sim_printf ("// Disk IOT special seek\r\n");
1609 }
1610 iom_cmd_rc_t rc1 = diskSeekSpecial (devUnitIdx, iomUnitIdx, chan);
1611 if (rc1) {
1612 rc = IOM_CMD_ERROR;
1613 goto done;
1614 }
1615 }
1616 break;
1617 }
1618
1619 done:
1620 #if defined(LOCKLESS)
1621 unlock_ptr (& dsk_states->dsk_lock);
1622 #endif
1623 return rc;
1624 }
1625
1626
1627
1628
1629
1630
1631
1632
1633 #define IPC_UNIT_IDX(uptr) ((uptr) - ipc_unit)
1634 #define N_IPC_UNITS 1
1635
1636 static struct ipc_state
1637 {
1638 char device_name[MAX_DEV_NAME_LEN];
1639 } ipc_states[N_IPC_UNITS_MAX];
1640
1641 UNIT ipc_unit[N_IPC_UNITS_MAX] = {
1642 #if defined(NO_C_ELLIPSIS)
1643 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1644 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1645 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1646 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1647 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1648 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1649 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1650 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1651 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1652 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1653 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1654 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1655 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1656 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1657 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1658 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL }
1659 #else
1660 [0 ... N_IPC_UNITS_MAX-1] = {
1661 UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL
1662 }
1663 #endif
1664 };
1665
1666 static t_stat ipc_show_nunits (UNUSED FILE * st, UNUSED UNIT * uptr,
1667 UNUSED int val, UNUSED const void * desc)
1668 {
1669 sim_printf("Number of IPC units in system is %d\r\n", ipc_dev.numunits);
1670 return SCPE_OK;
1671 }
1672
1673 static t_stat ipc_set_nunits (UNUSED UNIT * uptr, UNUSED int32 value,
1674 const char * cptr, UNUSED void * desc)
1675 {
1676 if (! cptr)
1677 return SCPE_ARG;
1678 int n = atoi (cptr);
1679 if (n < 0 || n > N_DSK_UNITS_MAX)
1680 return SCPE_ARG;
1681 ipc_dev.numunits = (uint32) n;
1682 return SCPE_OK;
1683 }
1684
1685 static t_stat ipc_show_device_name (UNUSED FILE * st, UNIT * uptr,
1686 UNUSED int val, UNUSED const void * desc)
1687 {
1688 int n = (int) IPC_UNIT_IDX (uptr);
1689 if (n < 0 || n >= N_IPC_UNITS_MAX)
1690 return SCPE_ARG;
1691 if (ipc_states[n].device_name[0] != 0)
1692 sim_printf("name : %s", ipc_states[n].device_name);
1693 else
1694 sim_printf("name : default");
1695 return SCPE_OK;
1696 }
1697
1698 static t_stat ipc_set_device_name (UNIT * uptr, UNUSED int32 value,
1699 const char * cptr, UNUSED void * desc)
1700 {
1701 int n = (int) IPC_UNIT_IDX (uptr);
1702 if (n < 0 || n >= N_IPC_UNITS_MAX)
1703 return SCPE_ARG;
1704 if (cptr)
1705 {
1706 strncpy (ipc_states[n].device_name, cptr, MAX_DEV_NAME_LEN-1);
1707 ipc_states[n].device_name[MAX_DEV_NAME_LEN-1] = 0;
1708 }
1709 else
1710 ipc_states[n].device_name[0] = 0;
1711 return SCPE_OK;
1712 }
1713
1714 static MTAB ipc_mod[] =
1715 {
1716 {
1717 MTAB_dev_value,
1718 0,
1719 "NUNITS",
1720 "NUNITS",
1721 ipc_set_nunits,
1722 ipc_show_nunits,
1723 "Number of DISK units in the system",
1724 NULL
1725 },
1726 {
1727 MTAB_XTD | MTAB_VUN | MTAB_VALR | MTAB_NC,
1728 0,
1729 "NAME",
1730 "NAME",
1731 ipc_set_device_name,
1732 ipc_show_device_name,
1733 "Set the device name",
1734 NULL
1735 },
1736 MTAB_eol
1737 };
1738
1739 DEVICE ipc_dev =
1740 {
1741 "IPC",
1742 ipc_unit,
1743 NULL,
1744 ipc_mod,
1745 N_IPC_UNITS,
1746 10,
1747 24,
1748 1,
1749 8,
1750 36,
1751 NULL,
1752 NULL,
1753 NULL,
1754 NULL,
1755 NULL,
1756 NULL ,
1757 NULL,
1758 0,
1759 0,
1760 NULL,
1761 NULL,
1762 NULL,
1763 NULL,
1764 NULL,
1765 NULL,
1766 NULL,
1767 NULL
1768 };
1769
1770
1771
1772
1773
1774
1775
1776
1777 #define MSP_UNIT_IDX(uptr) ((uptr) - msp_unit)
1778 #define N_MSP_UNITS 1
1779
1780 struct msp_state_s msp_states [N_MSP_UNITS_MAX];
1781
1782 UNIT msp_unit[N_MSP_UNITS_MAX] =
1783 {
1784 #if defined(NO_C_ELLIPSIS)
1785 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1786 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1787 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1788 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1789 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1790 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1791 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1792 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1793 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1794 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1795 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1796 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1797 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1798 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1799 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL },
1800 { UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL }
1801 #else
1802 [0 ... N_MSP_UNITS_MAX-1] = {
1803 UDATA (NULL, 0, 0), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL
1804 }
1805 #endif
1806 };
1807
1808 static t_stat msp_show_nunits (UNUSED FILE * st, UNUSED UNIT * uptr,
1809 UNUSED int val, UNUSED const void * desc)
1810 {
1811 sim_printf("Number of MSP units in system is %d\r\n", msp_dev.numunits);
1812 return SCPE_OK;
1813 }
1814
1815 static t_stat msp_set_nunits (UNUSED UNIT * uptr, UNUSED int32 value,
1816 const char * cptr, UNUSED void * desc)
1817 {
1818 if (! cptr)
1819 return SCPE_ARG;
1820 int n = atoi (cptr);
1821 if (n < 0 || n > N_DSK_UNITS_MAX)
1822 return SCPE_ARG;
1823 msp_dev.numunits = (uint32) n;
1824 return SCPE_OK;
1825 }
1826
1827 static t_stat msp_show_device_name (UNUSED FILE * st, UNIT * uptr,
1828 UNUSED int val, UNUSED const void * desc)
1829 {
1830 int n = (int) MSP_UNIT_IDX (uptr);
1831 if (n < 0 || n >= N_MSP_UNITS_MAX)
1832 return SCPE_ARG;
1833 if (msp_states[n].device_name[0] != 0)
1834 sim_printf("name : %s", msp_states[n].device_name);
1835 else
1836 sim_printf("name : default");
1837 return SCPE_OK;
1838 }
1839
1840 static t_stat msp_set_device_name (UNIT * uptr, UNUSED int32 value,
1841 const char * cptr, UNUSED void * desc)
1842 {
1843 int n = (int) MSP_UNIT_IDX (uptr);
1844 if (n < 0 || n >= N_MSP_UNITS_MAX)
1845 return SCPE_ARG;
1846 if (cptr)
1847 {
1848 strncpy (msp_states[n].device_name, cptr, MAX_DEV_NAME_LEN-1);
1849 msp_states[n].device_name[MAX_DEV_NAME_LEN-1] = 0;
1850 }
1851 else
1852 msp_states[n].device_name[0] = 0;
1853 return SCPE_OK;
1854 }
1855
1856 static MTAB msp_mod[] =
1857 {
1858 {
1859 MTAB_dev_value,
1860 0,
1861 "NUNITS",
1862 "NUNITS",
1863 msp_set_nunits,
1864 msp_show_nunits,
1865 "Number of DISK units in the system",
1866 NULL
1867 },
1868 {
1869 MTAB_XTD | MTAB_VUN | \
1870 MTAB_VALR | MTAB_NC,
1871 0,
1872 "NAME",
1873 "NAME",
1874 msp_set_device_name,
1875 msp_show_device_name,
1876 "Set the device name",
1877 NULL
1878 },
1879 MTAB_eol
1880 };
1881
1882 DEVICE msp_dev =
1883 {
1884 "MSP",
1885 msp_unit,
1886 NULL,
1887 msp_mod,
1888 N_MSP_UNITS,
1889 10,
1890 24,
1891 1,
1892 8,
1893 36,
1894 NULL,
1895 NULL,
1896 NULL,
1897 NULL,
1898 NULL,
1899 NULL ,
1900 NULL,
1901 0,
1902 0,
1903 NULL,
1904 NULL,
1905 NULL,
1906 NULL,
1907 NULL,
1908 NULL,
1909 NULL,
1910 NULL
1911 };