         DEF      IOQ
OC       EQU      2
*        704879   SIGMA 5/7         BPM M:IOQS
MONPROC  SET      1
DISCBPROC SET     1                                                     DISCB
         SYSTEM UTS
NWIO     SET      1
*
SYMBFLAG SET      1                 SYMBIONT VERSION
DUALFLAG SET      1                 DUAL-ACCESS VERSION
DEFER    EQU      0                 DONT DEFER START/CLEANUP
         PAGE
*
*   EXTERNAL DEFINITIONS
         DEF      MSGOUT
         DEF      QUEUE,QUEUE1,NEWQ
         DEF      IOINT,OCINT,IOSST,IOSCU
         DEF      OCQUEUE
         DEF      RESCHED
*
         DEF      CTRIG,INTSIM
*
         DEF      MSG2,MSG3,MSG4,MSG5,MSG7,MSG9,MSG9A
         DEF      FORCEIO
         DEF      RC20,RC21
         PAGE
*
*   EXTERNAL REFERENCES
*
         REF      IOQ1,IOQ2,IOQ3,IOQ4,IOQ5,IOQ6,IOQ7,IOQ8
         REF      IOQ9,IOQ10,IOQ11,IOQ12,IOQ13,IOQ14
*
         REF      DCT1,DCT2,DCT3,DCT4,DCT5,DCT6,DCT8
         REF      DCT9,DCT10,DCT11,DCT12,DCT13,DCT15
         REF      DCT14,DCT17,DCT18,DCT1A,DCT1P
         REF      DCT16
         REF      YFFFF
         REF      UB:PRIO           USER CURRENT PRIO
         REF      OCDCT
         REF      C:NOQ             PM CELL FOR LACK OF Q COUNT
         REF      RAS,RASCU         RAS PRE / POST PROCESSING POINTS
         REF      DCT19,DCT20,DCT21
*
         SREF     CTINT,CTGL,CTWD,SACT
*
         REF      CIT1,CIT2,CIT3,CIT4,CIT5,CIT6
*
         REF      YFF,XFF,XF,M17,X3,X7F,Y1,M16,M8
  REF  Y04,Y8,Y03,Y01,XFB
         REF      Y02,XE7,Y08,Y4,X7,Y2
         REF      X44
         REF      M15
         REF      M22,M21,M19
         REF      YE,Y00FE
         REF      Y06,C:RTRW
         REF      Y05
*
         REF      CJOB,QFREE,DCTSIZ,IOCLOCK,IOPSD,OCPSD
         REF      BTDBIT,CFUBIT
         REF      TB:FLGS
         REF      JOVVPA
WABLK    EQU      BLK
         REF      MBGBIT,MPOOL,MAXBQ
*
         REF      KEYINBUF,ALLOQ
         REF      TEMP
*
         REF      CTFLAGS,IOCTQ
         REF      TPACCESS,DCACCESS,DPACCESS
*
         REF      DSCCVT
         REF      ERRLOG,TIME
         REF      E:IC
         REF      IOQ15
         REF      T:RUE
         REF      T:SSE
         REF      JOVVP
         REF      JIT,DID,DCT24
         REF      IOSERCK
         REF      S:CUN
         REF      E:IP
         REF      T:REG
         REF      T:GJOBSTRT
         REF      JXCMAP
         REF      RCVPSD
         REF      REGIPSD
RTPRIO   EQU      X'C0'
         REF      DEVCTCHK
         REF      M11
         REF      COCIO
         REF      CURBQ
         REF      CTOC
         REF      CTACT
         REF      J:JIT
         REF      M:OC              MONITOR DCB FOR USER->OC
         REF      BUFLIMS,MPOOLIM,SC1900
         REF      ECBPOST1,ECBFBLK
         REF      IOQ16
         REF      J:RWECB
         SREF     RTIOSTRT,RTINT,RTCU,RTTO
         DEF      CC3FAIL
*                                                                      *
         REF      PFSRIO
*
IOQ      EQU      %
ORIG     EQU      %
         PAGE
*
*   REGISTER DEFINITIONS
*
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
R8       EQU      8
R9       EQU      9
R10      EQU      10
R11      EQU      11
R12      EQU      12
R13      EQU      13
R14      EQU      14
R15      EQU      15
         PAGE
*
*    BASIC INPUT/OUTPUT ROUTINES
*
*    NEWQ: NORMAL ENTRY (LATER WILL BE QUEUE)
*    QOVL: OVERLAY ENTRY
*
*    R12 HAS FC, PRI, NRT, DCT - 8,8,8,8
*    R13 HAS DATA CHAIN,CMND CHAIN,BYTE ADR OF BUF - 1,1,6,24
*    R14 HAS SIZE OF BUFFER IN BYTES - 0,16
*    R15 HAS SEEK ADDR (LEFT JUST.) - 32
*    R0 HAS TRIG. ADDR, END-ACTION ADDR - 8,0,17
*    R1 HAS END-ACTION INFO - 32
*
*        BAL,R11  (ENTRY)
*        RETURN IF DEVICE MARKED DOWN
*        NORMAL RETURN
*
*
*    QUEUE: DCB ENTRY (NO END-ACTION)
*    QUEUE1: DCB ENTRY (END-ACTION)
*
*    R8 HAS FC, DCB ADDR - 8,0,17
*
*    FOR QUEUE1 - R9 HAS END-ACTION ADDR
*                 R10 HAS END-ACTION INFO
*
*        BAL,R11  (ENTRY)
*
*    SAVES R5 - R11
         PAGE
*
*        FRONTEND - PROVIDES SCHEDULER INTERFACE FOR I/O REQUESTS
*                   FROM MAPPED USERS.  A CHECK IS MADE TO SEE IF
*                   THE USER HAS MORE THAN THE ALLOWED NUMBER OF
*                   I/O REQUESTS ALREADY IN PROGRESS BEFORE PERMITTING
*                   ANOTHER TO BE ENQUEUED.  THE USER IS BLOCKED
*                   BY PLACING HIM IN 'SIOMF'.
*
*                   THE USER MASTER FUNCTION COUNT IS INCREMENTED
*                   BEFORE THE USERS I/O IS INITIATED.
*
*                   FOR MAPPED REQUESTS, THE REAL RETURN FROM IOQ(R11)
*                   IS SAVED IN THE MAPPED TSTACK AND A DUMMY RETURN
*                   TO THE BACKEND OF FRONTEND IS SET IN R11.
*
*        CALLING SEQUENCE:
*
*        BAL,R2   FRONTEND
*        B        <PROPER BACKEND ENTRY>
*        B        <PROPER RECYLCE ENTRY>      FOR IOMF UNBLOCK
*        ....     ......            NORMAL EXIT IS TO BAL+3
*
*
*
IOUNMAP  :PSD     (IA,1Q2),(WK,1),(INH)
FRONTEND EQU      %
         LB,R4    CJOB              ASSUME UNMAPPED
         LW,3     JIT               IF NO SYSID MUST BE MONITOR
         BEZ      SKREG2            YES IT IS
*                                   MAPPED USER MAKING THIS REQUEST
*
         REF      J:DCBLINK
         MTW,1    C:RTRW            INCREMENT I/O COUNT
         LC       J:DCBLINK         GET NEWQNW/NEWQNWM FLAGS
         BCR,8    CHECKMF           NOT NW OR NWM
         LI,R3    0                 ZAPPER FOR FLAGS
         STB,R3   J:DCBLINK         CLEARE THEM
         BCR,4    %+2               NEWQNW
         LI,3     X'FF'             SET MAGIC USER NO FOR NEWQNWM
         PUSH     R11               SAVE REAL RETURN IN MAPPED STACK
         LI,R11   1Q3               SET RETURN TO BACKEND OF FRONTEND
         B        SKREG2            AND GO GET A QUEUE ENTRY
CHECKMF  RES      0
         LW,3     S:CUN
         REF      UB:MF,SL:BXMF,SL:OXMF
         REF      SL:IOTA
         LW,4     SL:IOTA           GET DING
         AWM,4    J:CTIME           ADD IT IN
         REF      J:CTIME
         LB,4     JIT               FETCH USER TYPE BITS
         LB,3     UB:MF,3           GET MASTER FUNCTION COUNT
         SLS,4    -6                ISOLATE USER TYPE TO USE AS INDEX
         EXU,0    IPREGV,4          EXECUTE PROPER INSTRUCTION
         BL       SKIPREG           LESS THAN LIMIT, SKIP REG
         PUSH     6
         PUSH     11
         LI,6     E:IP              REPORT
         BAL,11   T:REG               I/O PERMISSION REQUEST
         PULL     11
         PULL     6
         B        1,R2              RETURN IN IOMF BLOCK
IPREGV   CW,3     SL:BXMF           BATCH - USER TYPE = 0
         B        SKIPREG           GHOST - USER TYPE = 1
         CW,3     SL:OXMF           ONLINE  USER TYPE = 2
SKIPREG  LW,3     S:CUN             GET USER NO
         MTB,1    UB:MF,3           INCREMENT MASTER FUNCTION COUNT
*
SKREG    RES      0
         PUSH     R11               SAVE REAL RETURN
         LW,R11   R2                SET RETURN TO BACKEND POINTER
SKREG1   LB,4     UB:PRIO,3         GET USER PRIORITY
SKREG2   LPSD,0   IOUNMAP           UNMAP AND DISABLE
1Q2      PUSH     7,R5              SAVE NON VOLATILES
         LW,R6    R3                MOVE USER NUMBER FOR GETQ
*
*        GET A QUEUE ENTRY FOR THIS REQUEST
*
*        DRIVES ALL I/O IF NONE ARE AVAILABLE
*
*        R4 = PRIORITY (IN)
*        R6 = USER NUMBER (IN)
*        R12 = DCT INDEX (IN)
*
*        R3 = IOQ INDEX (OUT)
*
*
GETQ     RES      0
         LB,R3    QFREE             GET FREE ENTRY HEAD
         BEZ      GQ10              EMPTY, DRIVE ALL I/O
         STB,R4   IOQ14,R3          SAVE PRIORITY
         STB,R12  IOQ7,R3           AND DCT INDEX
         MTW,1    CURBQ             INCREMENT CURRENT BACKGROUND ENTRIES
GQ40     LB,R5    IOQ2,R3           FLINK
         STB,R5   QFREE             SET HEAD TO NEXT FREE ENTRY
         STB,R6   IOQ15,R3          PUT AWAY USER NUMBER
         ENABLE                                  ** ENABLE **
         B        2,R2              RETURN SKIPPING +2
GQ10     LI,R3    DCTSIZ            DRIVE I/O FOR ALL DEVICES
         MTW,1    C:NOQ             COUNT NUMBER OF TIMES THERE ARE NONE
GQ11     PUSH     16,R0             SAVE ALL REGS
         INT,R1   R3                GET DCT INDEX INTO REG FOR DRIVEIO
         BAL,R2   FORCEIO           FORCE
         PULL     16,R0             RESTORE REGS
         BDR,R3   GQ11              CONTINUE
         DISABLE                                    **DISABLE**
         B        GETQ              TRY AGAIN
1Q1      RES      0
*
         MAP                        GO MAPPED FOR REG
         PUSH     6
         LI,6     0                 DCB ADDRESS OF ZERO FOR NEWQ
         XPSD,0   REGIPSD           REPORT TO SCHEDULER
         PULL     6                 RESTORE REG
1Q3      MAP                        * GO MAPPED FOR HIS JIT
         PULL     11                * RESTORE REAL RETURN
         LB,R2    DCT4,R2           * GET DEVICE TYPE INDEX
         LI,R1    DCACCESS          * ASSUME PUB RAD
         LC       TB:FLGS,R2        * GET DEVICE ATTRIBUTE FLAGS
         BCR,8    1Q4               * NOT TAPE OR DISC,NO ACCOUNTING
         BCR,4    INCTP             * TAPE ACCESS
         BCR,3    INCDC             * RAD ACCESS
*                                   * PACK ACCESS
         AI,R1    DPACCESS-TPACCESS **
INCTP    AI,R1    TPACCESS-DCACCESS **
INCDC    EQU      %                 **
         MTW,+1   J:JIT,R1          * ACCOUNT FOR IT
1Q4      RES      0
BISR4    RES      0
         B        *11
*
         PAGE
         DEF      NEWQNWM
NEWQNWM  EQU      %                 NO WAIT MAPPED ENTRY
         LW,3     Y4
         STS,3    J:DCBLINK
NEWQNW   EQU      %
         DEF      NEWQNW
         LW,R3    Y8
         STS,R3   J:DCBLINK
*
NEWQ     EQU      %                 NORMAL ENTRY (LATER WILL BE QUEUE)
*
*
Q10      EQU      %
         AND,R12  DCT%MASK%2        CLEAN UP DCT FOR 7275
         REF      DCT%MASK%2
         LW,3     DCT%MASK
         AND,R3   R12
         LC       DCT24,R3          IS CAL1,1 DIAG USE BIT SET
         BCS,4    BISR4             YES, ERROR EXIT
         LC       DCT3,R3           LOOK AT DEVICE DOWN BIT
         BCR,2    Q11               DEVICE NOT PARTITIONED
         LB,R2    DCT15,R3          IS THIS A REAL-TIME IOEX CALL?
         BNEZ     Q11               YES
         LW,R3    S:CUN             DEV.DOWN, GET SYS ID
         CW,R3    DID               IS THIS A DIAG USER
         BNE      BISR4             NO, ERROR EXIT IF DOWN
Q11      AI,R11   1                 INC RETURN ADDR
*
         BAL,2    FRONTEND          UTS INTERFACE
         B        1Q1               POINTER TO NEWQ BACKEND OF FRONTEND
         B        FRONTEND          REPEAT FRONTEND IF IOMF UNBLOCK
*
*                             BUILD Q ENTRY
         LI,2     0
         STW,R2   IOQ16,R3          NO ECB FOR NEWQ I/O.
         SLS,R12  -8
         STB,R12  IOQ10,R3          MAX TRIES
         STB,R12  IOQ11,R3          TRY COUNT
         SLS,R12  -8
         CB,R12   IOQ14,R3          CHECK AGAINST ASSUMED
         BG       %+2               LOWER
         STB,R12  IOQ14,R3          PRIORITY
         SLS,R12  -8
         LW,R8    R15               GET DISK ADDRESS INTO REG FOR DSCCVT
         LI,R15   0                 NO MBG BIT
Q13      RES      0                 MERGE POINT FOR QUEUE AND NEWQ
         STB,R12  IOQ4,R3           FUNCTION CODE
         STB,R12  IOQ5,R3           CURRENT FUNCTION STEP
         STW,R13  IOQ8,R3           BUF ADDR
         STH,R14  IOQ9,R3           BYTE COUNT
         BAL,11   DSCCVT            CONVERT TO SEEK
         STW,8    IOQ12,R3          STORE SEEK
         STD,R0   IOQ13,R3          END-ACTION DATA
         STW,R2   IOQ6,R3           DCB AND FUNCTION
*
Q15      EQU      %
         LB,R1    IOQ7,3            GET DCT INDEX
         BNEZ     Q151              OK, NON-ZERO
SC17     SCREECH  X'17'             BAD DCT
Q151     RES      0
         CLM,R1   RBLIMS
         BCR,9    RBQCK
         REF      RBLIMS
         SREF     RBQCK
Q15A     EQU      %
         DO       DUALFLAG
         LB,R7    DCT3,R1           EXTRACT DCT ACCESS KEY
         AND,R7   X3                ..
         AH,R15   IOQINIT,R7        SET IOQ ACCESS KEY
         FIN
         STB,R15  IOQ3,R3           SAVE REQUEST SWITCHES
         LB,9     IOQ15,3           GET USER NUMBER
         BEZ      Q15AA             ZERO, UNMAPPED I/O
         INT,R7   IOQ8,R3           IS THIS A USER COMMAND LIST
         BCS,4+8  Q15AA             YES, SKIP CHAINCHK
         BAL,9    CHAINCHK          NO, USER, CONVERT BUF ADR
Q15AA    EQU      %
         LB,R4    DCT2,R1           GET CHANNEL INDEX
*                             LINK ENTRY INTO Q
         LB,R8    IOQ14,R3          GET PRIORITY OF ENTRY
*
         LI,R11   X'F0000'          MASK FOR COMPARE SELECTIVE(YFFFF)
*
         LB,R2    DCT22,R1          GET SUBTYPE
         BEZ      Q20               NOT A DISC
         LI,R2    1                 SET INDEX
         LW,R10   IOQ12,R3          GET SEEK ADDRESS
Q20      DISABLE                                *** DISABLE ***
         LB,R7    CIT2,R4           GET TAIL OF QUEUE
         BNE      Q28               NOT EMPTY
         STB,R3   CIT1,R4           Q WAS EMPTY
         STB,R3   CIT2,R4
         STB,R7   IOQ1,R3
         B        Q27
Q29      B        Q30               DEVICE, AT THE RIGHT SPOT
         CS,R10   IOQ12,R7          CHECK CYLINDER
         BL       Q26A              LOWEST NUMBERED FIRST
         CB,R8    IOQ14,R7          CHECK PRIO AGAIN
         BE       Q30               SAME
         CW,R10   IOQ12,R7          CHECK DISK ADDR
         BE       Q30               SAME, CANT INVERT; PUT KINK IN Q
         B        Q26A              KEEP GOING
Q26      CB,R1    IOQ7,R7           SAME DEVICE
         BE       Q29,R2            YES, SWITCH ON DEVICE/DISK
Q26A     LB,R6    IOQ1,R7           BLINK
         BNE      Q28A              GOT ANOTHER
         STB,R3   CIT1,R4           SET NEW HEAD
         STB,R6   IOQ1,R3           SET NEW BLINK
         STB,R3   IOQ1,R7           MAKE PREVIOS BLINK TO CURRENT
Q27      STB,R7   IOQ2,R3           SET CURRENT FLINK
         B        Q40               DONE
Q28A     LB,R7    IOQ1,R7           GET NEXT
Q28      CB,R8    IOQ14,R7          CHECK PRIO
         BLE      Q26               TRY TO INVERT
Q30      LB,R6    IOQ2,R7           INSERT
         BNEZ     %+2               CHECK FOR TAIL
         STB,R3   CIT2,R4           SET NEW TAIL
         STB,R6   IOQ2,R3           SET CURRENT FLINK
         STB,R7   IOQ1,R3           SET CURRENT BLINK
         STB,R3   IOQ2,R7           SET PREV BLINK TO CURRENT
         BEZ      %+2               CHECK FOR TAIL
         STB,R3   IOQ1,R6           NO, SET NEXT BLINK TO CURRENT
*
Q40      ENABLE                                             **ENABLE**
*
*                             CALL SERVICE DEVICE
Q50      STB,R1   *TSTACK           SAVE DCT INDEX IN RETURN
         BAL,R2   DRIVEIO           CALL I/O SCHEDULER WITH CJOB PRI
         LB,R2    *TSTACK           RESTORE DCT INDEX
*                             RETURN TO CALLER
Q51      EQU      %
         DEF      Q51,Q15A
         LCI      7                 RESTORE NON-VOLATILE REGS
         DEF      PL5BSR4
PL5BSR4  PLM,5    TSTACK
         B       *11
         PAGE
*
*        THIS ROUTINE CHECKS THE REQUEST FOR OVERLAPPING A PAGE
*        BOUNDARY (IF A USER REQUEST). IF IT OVERLAPS, A NONITOR
*        BUFFER IS ACQUIRED AND THE OPERATION IS DIVIDED INTO
*        PAGE SIZE OR SMALLER CHUNKS AND THE REQUEST IS FLAGGED
*        AS A DATA CHAIN. IT ALSO CONVERTS THE BUFFER ADDRESS FROM
*        VIRTUAL TO PHYSICAL. IF THE OPERATION IS TO RAD, DISC OR
*
*
*
*        R2       COUNT OF COMMAND PAIRS IN CHAIN
*        R3       Q ENTRY
*        R4       WA OF MONITOR BUFFER CONTINUING DATA CHAIN
*        R9       LINK
*        R13      BYTE COUNT
*        R14      WA OF VIRTUAL PAGE
*        R15      BA OF PHYSICAL PAGE
*
CHAINCHK EQU      %
         LW,6     IOQ8,3            GET BUFFER ADDRESS
         AND,6    M19               SCRUB TO VIRTUAL BYTE ADDRESS
         STW,6    IOQ8,3
         SLD,6    -11               GET PAGE NUMBER
         CI,6     JOVVP             IS THE BUFFER IN THE MONITOR
         BL       *9                YES GET OUT
         BAL,1    MAP               GO MAPPED TO SEE USER JIT
         LOAD,6   JX:CMAP,6         VIRTUAL TO PHYSICAL
         REF      JX:CMAP
         SLD,6    11                MAKE BYTE ADDRESS AGAIN
         LW,13    IOQ8,3            GET BUFFER ADDRESS
         LH,14    IOQ9,3            AND BYTE COUNT
         AND,13   M11               SCRUB PAGE DISP INTO BUFFER
*                                   R13 CONTAINS IOQ8 UPON ENTRY
         AH,13    IOQ9,3            ADD BYTE COUNT
         BLEZ     CHAIN             32K BYTES OR GREATER
         AI,13    -2048             CHECK FOR CROSSING PAGE
         BG       CHAIN             YES
         STW,6    IOQ8,3            STORE PHYSICAL BUFFER ADR
CHNEX    BAL,1    UNMAP             GO UNMAPPED AGAIN
         LB,1     IOQ7,3            RESTORE DCT INDEX TO R1
         B        *9                RETURN
*
*        DATA CHAIN IS NEEDED
*
CHAIN    DISABLE                    ***  DISABLE   ***
         LW,4     MPOOL             GET A MONITOR BUFFER(34 WDS)
         BNEZ     CH21              GOT ONE
         ENABLE                     ***  ENABLE  ***
         B        CHAIN             GO TRY AGAIN
CH21     LW,5     0,4               GET POINTER TO NEXT MBUF
         BEZ      CH22
         CLM,5    BUFLIMS+MPOOLIM+MPOOLIM   CHECK MPOOL WITHIN LIMITS
         BCS,9    SC1900            SOFTWARE CHECK 19-00
CH22     CLM,4    BUFLIMS+MPOOLIM+MPOOLIM
         BCS,9    SC1900            SOFTWARE CHECK 19-00
         STW,5    MPOOL             MAKE IT THE NEW HEAD
         ENABLE                     ***  ENABLE  ***
         SLS,4    -1                MAKE DOUBLEWORD ADR
         OR,4     Y8                SET DATA CHAIN BIT
         LW,5     IOQ8,3            GET BUFFER VIRTUAL ADDRESS
         STW,4    IOQ8,3            SAVE POINTER TO DATA CHAIN
         AND,14   M16               SCRUB BYTE COUNT
*                                   R14 CONTAINS BYTE COUNT UPON ENTRY
         LCW,7    6                 FIND REMAINING BYTES IN PAGE
         AND,7    M11               SCRUB
         BNE      %+2               NOT ON PAGE BOUNDARY
         LI,7     2048              WHOLE PAGE
         SW,14    7                 ACCOUNT FOR FIRST PAGE
         STD,6    0,4               STORE FIRST COMMAND PAIR
         SLS,5    -11               VIRTUAL PAGE OF BUFFER START
         LI,7     X'800'            ALL BUT FIRST AND LAST GET COUNT OF 2048
CH50     AI,5     1                 BUMP TO NEXT PAGE
         AI,4     1                  AND NEXT COMMAND POSITION
         LOAD,6   JX:CMAP,5         VIRTUAL TO PHYSICAL
         SLS,6    11                BYTE ADDRESS
         AI,14    -2048             COUNT FOR THIS COMMAND
         BLEZ     CH55              LAST COMMAND
         STD,6    0,4               STORE COMMAND
         B        CH50              CONTINUE
CH55     AW,7     14                CORRECT BYTE COUNT
         STD,6    0,4               AND STORE LAST COMMAND
         SW,4     IOQ8,3            CALCULATE NO OF COMMANDS
         AI,4     1                 IN DATA CHAIN
         STH,4    IOQ9,3            AND SAVE IN IOQ9
         BAL,1    UNMAP             UNMAPPED AGAIN
         LB,1     IOQ7,3            RESTORE DCT INDEX
*
         LI,0     2
         CB,0     IOQ4,3
         BNE      BISR2
         LB,6     DCT4,1            GET DEVICE TYPE
         LB,0     TB:FLGS,6         CHECK REVERSE BIT(=> 9 TRACK)
         CI,0     4
         BAZ      BISR2
*
*        WE HAVE A READ BACKWARD DATA CHAINED ON A 9T DRIVE
*        THE COMMAND LIST AND EACH PAIR IN IT MUST BE
*        INVERTED BECAUSE 9T HARDWARE ACTUALLY READS BACKWARD.
*        7T READ BACKWARD IS SOFTWARE SIMULATED
*        R2       HIGH INDEX
*        R4       COUNT
*        R5       LOW INDEX
*        R7       DA OF COMMAND LIST
*        R12-R15  TEMP
*
         LW,2     4                 COMPUTE NO OF PASSES NEEDED
*                                   TO INVERT
         AI,4     1                 THE COMMAND LIST
         SLS,4    -1
         AI,2     -1
         SLS,2    1
         LW,7     IOQ8,3            GET DA OF COMMAND LIST
         AND,7    M21
         LI,5     0                 LOW INDEX
CH60     EQU      %
         LD,12    *5,7
         LD,14    *2,7
         AI,12    -1
         AI,14    -1
         AW,12    13                INVERT EACH COMMAND PAIR
         AW,14    15
         STD,14   *5,7              AND INVERT THEIR POSITIONS
         STD,12   *2,7
         AI,2     -2
         AI,5     2
         BDR,4    CH60
*
BISR2    RES      0
         B        *9
         DO       DUALFLAG
IOQINIT  DATA,2   0,1,2,4           INITIAL IOQ KEYS FOR DUAL-ACCESS
         FIN
         PAGE
*
*        CHECK DA IN R8 FOR VALIDITY
*        CC = 0 IF OK
*        CC .NE. 0 OF NOT OK
*        LINK R11
*        NO VOLATILE REGS
         DEF      PVCHKDA
         DEF      CHKDA
*
CHKDA    EQU      %
         DEF      CHKDAQ
         PUSH     3,4               SAVE 4,5,6
         LI,6     CHKDA1            SET INTERNAL RETURN
CHKDAQ   EQU      %                                                     DISCB
         LH,R4    R8                GET DCT INDEX + POSIIBLE SECTOR ADR
PVCHKDA  EQU      %
         AND,R4   DCT%MASK          SCRUB OF EXTRA BITS
         BEZ      CHKDA2            ERROR                               DISCB
         CI,4     DCTSIZ            CHECK FOR LEGAL                     DISCB
         BG       CHKDA2            NO                                  DISCB
         LB,R4    DCT22,R4          GET SUBTYPE                         DISCB
         BEZ      CHKDA2            NOT A DISC                          DISCB
         LSECTA,R5   R8             REL SECTOR IN 5                     DISCB
         CW,5     DISCLIMS,4        COMPARE
         BGE      CHKDA2            BAD
         LCI      15                SET CC
         B        0,6               RETURN
CHKDA2   LCI      0                 ERROR
         B        0,6               RETURN
CHKDA1   STCF     11                SAVE CC
         PULL     3,4               RESTORE REGS
         LCF      11                RESTORE CC
         B        *11               RETURN
*
         REF      DCT%MASK
         REF      DISCLIMS
         REF      DCT22
*
         PAGE
*
*
*        ENTRY WITH DCB
*
QUEUE1   LW,R0    R9                MOVE END ACTION ADDRESS
         B        QD4
QUEUE    LI,R0    0
QD4      LW,R1    R10               MOVE END ACTION INFO
         LI,R2    X'1FFFF'          MASK FOR DCB ADDREjj
         AND,R2   R8                EXTRACT FROM ARGUMENT
         LW,R3    FCN,R2            CHECK FOR FUNCTION COUNT
         AND,R3   YFF               NON-ZERO
         BEZ      BISR4             NO, GET OUT
*
         LI,R15   3                 EXTRACT ASN
         AND,R15  ASN,R2            FROM DCB.
         CI,R15   CFUBIT            CHECK FOR FILE ASSIGNMENT.
         BE       QD30              ---> YES.
         LW,R12   DSI,R2            NOT FILE.
         LI,R13   X'BF00'           CHECK DEVICE TYPE.
         CS,R12   L(X'9000')        IS IT COC...
         BE       COCIO             ---> YES.
         CI,R12   X'8000'           NOT FILE; NOT COC. TEST OPLABEL BIT.
         AND,R12  XFF                 (EXTRACT DCT INDEX)
         BANZ     QD31              ---> NOT OPLABEL.
         SUA      X'32'           -----> OPLABEL IMPOSSIBLE W/ OPEN DCB.
QD30     INT,R12  CDA,R2            FILE DCB.
         AND,R12  DCT%MASK          R12= DCT INDEX.
*
QD31     CI,R2    JOVVPA            IS DCB IN THE MONITOR...
         BL       QD33              ---> YES. ALREADY REAL ADDRESS.
         SLD,R2   -9                TRANSLATE
         LOAD,R2  JX:CMAP,R2        VIRTUAL TO PHYSICAL
         SLD,R2   +9                DCB ADDRESS.
QD33     EQU      %
         LW,R13   R2                SAVE TRANSLATED DCB ADDRESS
         LW,R14   J:RWECB           GET ECB ADDRESS (IF ANY) INTO R14.
         BAL,R2   FRONTEND          SCHEDULER INTERFACE AND GETQ
         B        1Q3               POINTER TO QUEUE BACKEND OF FRONTEND
         B        QD4               RECYCLE IF IOMF UNBLOCK
*                                   RETURNS UNMAPPED WITH R4=PRIO
*                                                    AND  R6=USER
*        UNMAP
*
         LW,R2    R13               RESTORE PHYSICAL DCB ADDRESS
         AND,R8   YFF               EXTRACT OLD FUNCTION CODE
         OR,R2    R8                MERGE WITH PHYS DCB ADDRESS
*
*                                   BUILD Q ENTRY
*
*
         AND,R14  M17               GET ECB ADDRESS ONLY.
         BEZ      %+2               ---> NO ECB.
         MTB,+1   *R14                ECB. BUMP I/O COUNT IN 4-WD BLK.
         STW,R14  IOQ16,R3          PUT ECB ADDRESS INTO Q ENTRY.
         LW,R13   QBUF,R2           GET WORD ADDRESS OF BUFFER
         AND,R13  M22               SCRUB OFF FCN
         SLS,R13  2                 CONVERT TO BYTE ADDRESS
         LI,R7    X'C0'             MASK FOR HBTD
         AND,R7   0,R2              EXTRACT FROM DCB
         BEZ      QD51A             NONE, SHORT CUT
         SLS,R7   BTDBIT-31         ALIGN
         OR,R13   R7                MERGE
QD51A    LW,R14   WABLK,R2          GET RECORD SIZE
         SCS,R14  15                RIGHT ALIGN
         AND,R14  M15               SCRUB
         BNE      %+2
         LI,R14   X'8000'           0 => 32K BYTES
*
         LI,R7    BANRA             INDEX TO NRA (NRT)
         LB,R10   *R2,R7            GET NRT FROM DCB
         STB,R10  IOQ10,R3          NUMBER OF TRIES
         STB,R10  IOQ11,R3          TRY COUNT
*
*
*                             CONVERT FUNCTION CODE
         LB,R5    R2                GET FUNCTION CODE
         LB,R7    IOQ7,R3           GET DCT
         AI,R15   -1                CHECK FOR FILE ASSIGNMENT
         BEZ      OLDTNEWFC         YES, NO MBG BIT
         LW,R15   0,R2              EXTRACT MBG BIT
         SCS,R15  MBGBIT+6          FROM DCB
         AND,R15  X20               SCRUB AND PASS TO Q13
*
*        AT THIS POINT, MOST DCB INFORMATION HAS BEEN MOVED
*        INTO REGISTERS IN ESSENTIALLY THE SAME FORMAT AS A
*        NEWQ CALL.
*
*        R0 = END ACTION ADDRESS
*        R1 = END ACTION INFORMATION
*        R13 = BUFFER (BYTE ADDRESS)
*        R14 = BYTE COUNT
*        R8 = DISC ADDRESS
*        R15 = MBG BIT (IF APPROPRIATE)
*        R12 = FUNCTION CODE FOR HANDLER
*        R2 = OLD FUNCTION CODE, DCB PHYSICAL ADDRESS (8,24)
*
*
OLDTNEWFC RES     0                 5=OLD,7=DCT,6NG
*                                   9=RA,5=NEW FC
         LB,R7    DCT4,R7           GET TYPE
         CI,R7    X'10'             TEST FOR RESOURCE TYPE
         BLE      QD49              NO
         LB,R6    TB:FLGS,R7        GET TYPE FLAGS FOR ADDED DEVICE
         SLD,R6   -6                6= BITS 0,1 OF TB:FLGS
         SLS,R7   3                 LEFT ALIGN REV BIT
         SLD,R6   1                 MERGE TO FORM INDEX ON GENERIC TYPES
         LB,R7    GENERIC,R6        TRANSLATE
QD49     EQU      %
         LB,R6    TYPCOR,R7         TABLE OFFSET
         CI,R6    BA(MTCOR)-BA(TYPCOR) CHECK FOR TAPE
         BE       QD50              YES
         AND,R5   X7                USE 3 BITS FOR OTHERS
         B        QD60
QD50     CI,R5    8                 IS IT POSITION OP
         BAZ      QD52              NO
         AND,R5   XF                YES, MASK
         AI,R6    22                INDEX TO POS OPS
         B        QD60
QD52     CI,R7    8                 IS IT 9T
         BNE      QD56              NO
         AND,R5   X44               YES, MASK DIRECTION, R/W BITS
         AI,R5    X'22'             ADD PACKED, BINARY BITS
QD56     LI,R7    X'60'
         AND,R7   R5                MASK DIREC, PACK BITS
         SLS,R7   -2
         AND,R5   X7                READ/WRITE BITS
         OR,R5    R7                COMBINE
*
QD60     AW,R6    R5                SET INDEX IN COR TABLE
         LB,R12   TYPCOR,R6         CONVERT TO HANDLER FUNCTION CODE
         LW,R8    CDA,R2            GET SEEK ADDRESS
         B        Q13               MERGE WITH NEWQ PATH
*
*        TABLE TO CONVERT TB:FLGS CONTENT TO GENERIC TYPE INDEX
*
GENERIC  DATA,1   1,1,6,6,9,8,11,11
*
*
*
*    FUNCTION CODE CONVERSION TABLES
*
:COR     CNAME
         PROC
LF       GEN,8    BA(AF(1))-BA(TYPCOR)
         PEND
*
TYPCOR   EQU      %
         :COR     TYCOR             NULL
         :COR     TYCOR             TY
         :COR     PTCOR             PR
         :COR     PTCOR             PP
         :COR     CRCOR             CR
         :COR     CPCOR             CP
         :COR     CRCOR             LP
         :COR     DCCOR             DC
         :COR     MTCOR             9T
         :COR     MTCOR             7T
         :COR     MTCOR             MT
         :COR     TYCOR             DP
         :COR     MOCOR             MOC TYPE DEVICES
         :COR     TYCOR
         :COR     TYCOR
         :COR     TYCOR
*
         BOUND    4
*
TYCOR    DATA,1   0,0,0,0,1,1,1,1   TY
*
PTCOR    DATA,1   8,4,0,4,1,5,3,5   PR,PP
*
CRCOR    DATA,1   2,2,0,0,1,1,3,3   CR,LP
*
CPCOR    DATA,1   0,0,1,1,0,0,1,1   CP
*
DCCOR    DATA,1   0,0,0,0,4,4,4,4   DC
*
MTCOR    DATA,1   13,13,10,10,14,14,11,11      7 TRACK
         DATA,1   13,13,00,00,14,14,01,01
         DATA,1   15,15,12,12,14,14,11,11
         DATA,1   15,15,02,02,14,14,01,01
*
         DATA,1   5,4,7,6,8,3,0,0   MT POSITION
*
MOCOR    DATA,1   0,X'80',0,X'80',0,X'80',0,X'80'  MO
*
         LOCAL    QUEUE
QUEUE    EQU      NEWQ
         PAGE
         SPACE
*        9/1/71 J PODOLSKY .. DUAL-ACCESS INPUT/OUTPUT SCHEDULER.
*
*        DRIVEIO .. TO DRIVE I/O WITH CURRENT JOB PRIORITY.
*        DRIVEIO1 . TO DRIVE I/O WITH PRIORITY IN R0.
*        FORCEIO .. TO DRIVE I/O WITH PRIORITY X'FF' (LOWEST PRI).
*        CALLING SEQUENCE ..
*
*                 ...      ...         PRIORITY IN R0 (FOR DRIVEIO1)
*                 ...      ...         DCT INDEX IN R1
*                 BAL,R2   <NAME>      CALL DRIVEIO OR FORCEIO
*
         DEF      DRIVEIO           CALLED EXTERNALLY BY RTROOT
         SPACE
DRIVEIO  LB,R0    CJOB              NORMAL ENTRY - SET CURRENT JOB PRI
DRIVEIO1 CI,R0    RTPRIO            CHECK FOR BACKGROUND CALL
         BL       %+2               IF SO, TREAT THIS CALL AS I/O FORCE
FORCEIO  LI,R0    X'FF'             SINCE BKGD PRI IS BELOW CONTROL TASK
         PUSH     2
         LB,2     DCT2,1
DSERV    DISABLE                    DEVICE SERVICE CHECK, INHIBIT
         LB,R8    DCT5,R1           GET DEVICE STATUS SWITCHES(2)
         CI,R8    X'88'             IS DEVICE BUSY OR KEY-IN PENDING.
         BANZ     CLOCKIO           YES, SERVICE CLOCK & CHECK TIMEOUT
         CI,R8    X'40'             NO, IS CLEANUP OPERATION PENDING.
         BANZ     CLEANUP           YES, DO IT, PRIORITY PERMITTING
         PAGE
         SPACE
IOSCHED  ENABLE                     MAIN I/O SCHEDULING ALGORITHM
IOSCHED1 DISABLE                    RELEASE ANY PENDING INTERRUPTS
         LB,R3    CIT1,R2           GET HEAD OF CHANNEL QUEUE
         BEZ      SCHEDXIT          ARE THERE ANY PENDING REQUESTS.
         LB,R5    CIT3,R2           YES, GET SUBCHANNEL STATUS BYTE
         SLS,R5   -4                FORM INDEX FROM BUSY/HOLD FLAGS
IOSCHED2 INT,R8   SELECTAB,R5       GET SCHEDULING KEY & COMPARE MASK
         BCS,8    SCHEDHLD          CHECK CHANNEL HOLD IF SPECIFIED
IOSCHED3 CB,R8    IOQ3,R3           ELSE SCAN QUEUE FOR FREE REQUEST
         BANZ     NEXTQUE           THAT IS STARTABLE ON AVAILABLE S.C.
         DO       DEFER
         CB,R0    IOQ14,R3          COMPARE REQUEST/SCHEDULER PRIORITIES
         BL       DEFER2            SCHEDULER HIGHER, MUST DEFER SERVICE
         FIN
REQSTRT  LW,R10   R3                PRIORITY OK, SAVE CURRENT IOQ INDEX
         LB,R1    IOQ7,R3           GET INDEX OF DEVICE FOR THIS REQUEST
         LB,R4    DCT5,R1           CHECK DEVICE STATE FOR AVAILABILITY
         SCS,R4   -5                ISOLATE BUSY/CLEANUP/INTEROP FLAGS
         CW,R4    Y4                AND CHECK FOR DEVICE KEYIN PENDING
         EXU      REQSERV,R4        GO IF CLEANUP, NO GO IF BUSY/KEYIN
         DO       DUALFLAG
         LB,R4    IOQ3,R3           START OR INTEROP, R3 HAS REQUEST
         AND,R4   X7                EXTRACT 3-BIT IOQ ACCESS KEY
         CH,R5    ACCHECK,R4        ARE REQUIRED SUBCHANNELS AVAILABLE.
         BAZ      STARTIO           YES, START I/O ACTIVITY FOR REQUEST
         BL       SCHEDXIT          NO, ARE BOTH SUBCHANNELS REQUIRED.
         ELSE
         LI,R4    0                 SINGLE-ACCESS ONLY, FORCE KEY TO 0
         B        STARTIO           GO DIRECTLY TO STARTIO
         FIN
REQNSTRT INT,R3   R10               NO, RESTORE CURRENT IOQ INDEX
         BCS,8    CHANBLK           IF SUBCHANNEL HELD, BLOCK IT OUT.
NEXTQUE  LB,R3    IOQ2,R3           OTHERWISE, CONTINUE QUEUE SCAN
         BNEZ     IOSCHED3          ARE THERE ANY MORE REQUESTS.
SCHEDXIT ENABLE                     NO, REMOVE INTERRUPT INHIBITS
         PULL     2
         B        0,2
         PAGE
         SPACE
SCHEDHLD AI,R8    SCCHECK           SUBCHANNEL HELD OR BOTH BUSY, CHECK
         EXU     *R8                IF BOTH BUSY (FCN=0), EXIT SCHEDULER
         OR,R3    Y8                HELD - REQUEST INDEX IN R3 - FLAG
         B        REQSTRT           ATTEMPT SERVICE OF HOLDING REQUEST
         DO       DUALFLAG
CHANBLK  LB,R4    IOQ3,R3           HELD SUBCHANNEL BLOCKED, EXTRACT KEY
         AND,R4   X3                ..
         AH,R5    ACCHECK,R4        SET REQUIRED SUBCHANNELS UNAVAILABLE
         B        IOSCHED2          RE-SCHEDULE WITH NEW CHANNEL STATUS
         ELSE
CHANBLK  EQU      SCHEDXIT          SINGLE-ACCESS CHANNEL BLOCKED
         FIN
         SPACE
SCCHECK  B        SCHEDXIT          FUNCTION 0 .. BOTH SUBCHANNELS BUSY
         LB,R3    CIT5,R2           FUNCTION 1 .. SUBCHANNEL 1 HELD
         DO       DUALFLAG
         LB,R3    CIT6,R2           FUNCTION 2 .. SUBCHANNEL 2 HELD
         FIN
         SPACE
REQSERV  BANZ     REQNSTRT          0 .. NO START IF KEY-IN PENDING
         LB,R3    DCT6,R1           1 .. INTER-OP, GET WAITING REQUEST
         B        CLEANUP1          2 .. CLEANUP PENDING, PROCESS
INVAL    DATA     0                 3 .. NO SUCH ANIMAL .. S.C. 40
         B        REQNSTRT          4 .. DEVICE BUSY, NO GO
         SPACE
         DO       DUALFLAG
ACCHECK  GEN,16   X'C'              000 .. BOTH SUBCHANNELS REQUIRED
         GEN,16   X'8'              001 .. SUBCHANNEL 1 REQUIRED
         GEN,16   X'4'              010 .. SUBCHANNEL 2 REQUIRED
         GEN,16   X'0'              011 .. UNDEFINED ACCESS KEY
         GEN,16   X'0'              100 .. UNASSIGNED DUAL-ACCESS DEVICE
         FIN
         BOUND    4
         PAGE
         SPACE
*        SELECTAB .. CENTRAL SCHEDULING DECISION TABLE.  AN ENTRY IN
*        THIS TABLE IS SELECTED ACCORDING TO THE VALUE OF CIT3 BITS
*        0 THRU 3 (SUBCHANNEL 'BUSY' & 'HOLD' FLAGS).  TABLE FORMAT:
*
*             BIT  0         AT LEASE ONE SUBCHANNEL IDLE-HELD OR
*                            BOTH SUBCHANNELS BUSY
*             BITS 4-15      IF BIT 0 IS 1, THIS IS A SPECIAL FUNCTION
*                            CODE, WITH 0 = BOTH SC'S BUSY, 1 = SC1
*                            HELD, & 2 = SC2 HELD.  IF BIT 0 IS 0,
*                            THIS IS A COMPARE MASK FOR THE IOQ ACCESS
*                            KEY.  BIT 8 WILL ALWAYS BE 1, WITH BIT 14
*                            1 IF SC2 BUSY & BIT 15 1 IF SC1 BUSY.
*             BITS 16-19     USED BY 'ASSIGNSC' TO SELECT SUBCHANNEL
*             BITS 24-31     CIT CHECK MASK (INVERSE OF CIT3(0-3))
         SPACE
SELECT   COM,1,3,12,3,1,12 AF(1),0,AF(2),AF(3),AF(4),(%-SELECTAB||15)**4
         SPACE
SELECTAB SELECT   0,X'80',-3,1      0 .. I-F/I-F .. UNRESTRICTED CHANNEL
         SELECT   1,2,-3,0          1 .. I-F/I-H .. SCHEDULE HELD SC2
         SELECT   1,1,-2,0          2 .. I-H/I-F .. SCHEDULE HELD SC1
         SELECT   1,1,0,0           3 .. I-H/I-H .. BOTH HELD, SC1 FIRST
         SELECT   0,X'82',-3,0      4 .. I-F/B-F .. SCHEDULE SC1 ONLY
         SELECT   0,X'82',-3,0      5 .. I-F/B-H .. LIKEWISE - SC1 ONLY
         SELECT   1,1,0,0           6 .. I-H/B-F .. SCHEDULE HELD SC1
         SELECT   1,1,0,0           7 .. I-H/B-H .. SAME AS ABOVE - SC1
         SELECT   0,X'81',-2,0      8 .. B-F/I-F .. SCHEDULE IF DUAL-ACC
         SELECT   1,2,0,0           9 .. B-F/I-H .. SCHEDULE HELD SC2
         SELECT   0,X'81',-2,0      A .. B-H/I-F .. SC2 AVAIL IF DUAL-AC
         SELECT   1,2,0,0           B .. B-H/I-H .. SUBCHANNEL 2 HELD
         SELECT   1,0,0,0           C .. B-F/B-F .. BOTH BUSY, NOTHING
         SELECT   1,0,0,0           D .. B-F/B-H .. CAN BE SCHEDULED.
         SELECT   1,0,0,0           E .. B-H/B-F .. NOTE: I=IDLE, B=BUSY
         SELECT   1,0,0,0           F .. B-H/B-H .. AND F=FREE, H=HELD
         PAGE
         SPACE
*        CLOCKIO .. PERFORM I/O TIMEOUT CHECK FOR SCHEDULER.  IF TIME
*        EXCEEDED AND TIME-OUT INCREMENT IS NON-ZERO, FOLLOWING WILL
*        HAPPEN, DEPENDING ON DCT STATUS INFORMATION:
*
*        1.  DEVICE BUSY-MANUAL.  IF STILL IN MANUAL STATE, OPERATOR
*            WILL BE NOTIFIED.  IF NOW IN AUTOMATIC STATE, TIMEOUT
*            WILL BE SET FOR I/O NOW IN PROGRESS.
*        2.  DEVICE BUSY, NOT MANUAL.  I/O WILL BE HALTED AND CLEANUP
*            REQUEST SET.
*        3.  DEVICE KEY-IN PENDING.  OPERATOR WILL BE NOTIFIED WITH
*            'PLEASE RESPOND' MESSAGE.
*
*        R1 HAS DCT INDEX UPON ENTRY TO CLOCKIO.
         SPACE
CLOCKIO  LW,R10   DCT11,R1          GET EXPECTED COMPLETION TIME
         CW,R10   IOCLOCK           HAVE WE EXCEEDED TIME LIMIT.
         BGE      IOSCHED           NO, RETURN TO SERVICE CHANNEL
         LB,R9    DCT18,R1          YES, IS TIME-OUT INCREMENT ZERO.
         BEZ      IOSCHED           YES, NO LIMIT, IGNORE TIMEOUT
         LH,R10   DCT1,R1           NO, PROBABLY WILL NEED I/O ADDRESS
         CI,R8    2                 WAS DEVICE MANUAL LAST TIME.
         BAZ      CLOCKOUT          NO, TIMED OUT I/O OR EXPECTED KEY-IN
         LI,R13   MSG1              YES, SET UP 'MANUAL' MESSAGE
         LCI      0
         TIO,R11  *R10              STATUS OF I/O
         BCS,2    CC3FAIL           BUS/PARITY RESULTS UNKNOWN
         AND,R11  Y1                EXTRACT MANUAL/AUTOMATIC FLAG
         BCR,11   TYPEMSG           TYPE MSG IF STATUS AVAIL & MANUAL
         AW,R9    IOCLOCK           DEVICE NOW AUTO OR INDETERMINATE
         STW,R9   DCT11,R1          SET TIMEOUT FOR I/O NOW IN PROGRESS
         MTB,-2   DCT5,R1           RESET DEVICE-MANUAL INDICATOR
         B        IOSCHED           RETURN TO SERVICE CHANNEL QUEUE
         PAGE
         SPACE
CLOCKOUT LC       DCT5,R1           IS DEVICE BUSY, OR IS KEYIN PENDING.
         BCR,8    TYPERSP           NOT BUSY, KEYIN; 'PLEASE RESPOND'
         BCR,1    CLOCKXIT          DEVICE IS BUSY, IS IT DATA TRANSFER.
         LCI      0
         TDV,R8   *R10              GET TDV
         BCS,2    CC3FAIL           BUS/PARITY RESULTS UNKNOWN
         STCF     DCT20,R1          SAVE CONDITIONS
         STD,R8   DCT13,R1          SAVE TDV STATUS
*        LCI      0              NOTE CC3 STILL RESET FROM AFTER TDV.
         HIO,R11  *R10              HALT IT
         BCS,2    CC3FAIL           BUS/PARITY RESULTS UNKNOWN
         STCF     DCT19,R1          PUT HIO CC'S IN AIO SLOT
         AND,R11  YFFFF             CLEAR BYTE COUNT
         OR,R11   R10               MERGE IN DEVICE ADDRESS
         STW,R11  DCT12,R1          SAVE HIO STATUS IN AIO SLOT
         LCI      0
         TIO,R11  *R10              STATUS OF I/O
         BCS,2    CC3FAIL           BUS/PARITY RESULTS UNKNOWN
         LH,R11   R11               AND SAVE
         STH,R11  DCT21,R1          TIO STATUS
         LB,R9    DCT3,R1           GET DEVICE SWITCHES(1)
         OR,R9    X10               SET I/O TIMEOUT FLAG
         STB,R9   DCT3,R1           ..
CLOCKXIT LI,R5    DSERV             SET RETURN FROM 'INTSIM'
         SPACE    5
*                 .
*                 .                 ENTER 'INTSIM' TO CLEAN UP 'BUSY'
*                 .                 DEVICE AND SET CLEANUP PENDING.
*                 .                 SET CHANNEL NOT BUSY.  RETURN TO
*               . . .               'CLEANUP' TO TYPE 'TIMED OUT'
*                ...                MESSAGE (PRIORITY PERMITTING,
*                 .                 OF COURSE).
         PAGE
         SPACE
*        INTSIM .. ROUTINE TO SET DEVICE IN CLEANUP-PENDING STATE
*        FOLLOWING AN I/O HALT.  CALLING SEQUENCE ..
*
*                 BAL,R5   INTSIM      DCT INDEX PASSED IN R1
*                 ...      ...         USES REGISTERS 6 THRU 9
*
*        THE FOLLOWING ACTIONS WILL BE TAKEN:
*
*        1.  DEVICE STATE SWITCHED FROM 'BUSY' TO 'CLEANUP-PENDING'
*        2.  IF DATA TRANSFER WAS SET, 'SUBCHANNEL-BUSY' IS RESET.
*
*        NOTE: NO INDICATORS FOR RECOVERY -- SUCH AS 'TIMED-OUT' -- ARE
*        SET BY INTSIM.  THERE MAY BE FUTURE ENHANCEMENTS TO ALLOW
*        FOR SOME KIND OF RECOVERY ATTEMPT AFTER I/O HALT, BUT CUR-
*        RENTLY THE ONLY MODULES USING INTSIM, OUTSIDE OF 'SERDEV',
*        ARE THE PFSR AND RTROOT ROUTINES.
         SPACE
INTSIM   LB,R8    DCT5,R1           GET DCT SWITCHES(2)
         AND,R8   X7F               RESET DEVICE BUSY FLAG
         OR,R8    X40               SET CLEANUP PENDING FLAG
         CI,R8    X'10'             WAS THERE DATA TRANSFER.
         BAZ      INTSEXIT          NO, SKIP CHANNEL STATUS RESET
         LB,R6    DCT2,R1           YES, GET CIT INDEX (DON'T USE R2)
         LB,R9    CIT3,R6           GET CHANNEL STATUS FLAGS
         DO       DUALFLAG
         LB,R7    DCT6,R1           GET INDEX OF REQUEST USING DEVICE
         LB,R7    IOQ3,R7           EXTRACT 3-BIT IOQ ACCESS KEY
         AND,R7   X3                ..
         EOR,R9   CBFLAGS,R7        RESET SUBCHANNEL BUSY INDICATOR
         ELSE
         EOR,R9   CBFLAGS           SINGLE-ACCESS IMPLEMENTATION
         FIN
         STB,R9   CIT3,R6           RESTORE CHANNEL STATUS
INTSEXIT STB,R8   DCT5,R1           RESTORE DEVICE SWITCHES(2)
         LW,R5    R5                IS THIS A REAL-TIME IOEX CALL?
         BLZ      0,R5              YES, RETURN
         DISABLE
         LB,6     DCT14,1           GET FORWARD LINK
         LB,7     DCT15,1           GET BACK LINK
         STB,7    DCT15,6           AND CROSS LINK THEM
         STB,6    DCT14,7
         LI,7     0                 ZAP
         STB,7    DCT14,1           ANY
         STB,7    DCT15,1           GARBAGE
         B        0,R5              RETURN TO CALLING PROGRAM
         PAGE
         SPACE
*        I/O SCHEDULER CONTROL TASK DEFER ROUTINES.
*
*        DEFER1 .. DEFER TO CONTROL TASK, RETURN TO IOSCHED.
*        DEFER2 .. DEFER TO CONTROL TASK, RETURN TO SCHEDXIT.
         SPACE
         DO       DEFER
DEFER1   LI,R11   IOSCHED           ENTRY FROM CLEANUP, SET RETURN
         B        DEFER3            GO SET CONTROL TASK FUNCTION
DEFER2   LI,R11   SCHEDXIT          ENTRY FROM I/O SCHEDULER, SET RETURN
DEFER3   LB,R7    IOQ7,R3           GET DEVICE ASSOCIATED WITH REQUEST
         LB,R8    DCT5,R7           GET DEVICE SWITCH BYTE 2
         CI,R8    4                 IS CONTROL TASK ALREADY SET.
         BANZ    *R11               YES, TAKE DEFER EXIT NOW
         MTB,4    DCT5,R7           NO, SIGNAL CONTROL TASK FUNCTION
         LW,R8    R7                SET CONTROL WORD EQUAL TO DCT INDEX
         B        CTRIG1            GO SET CONTROL TASK FUNCTION
         FIN
         PAGE
         SPACE
*        CTRIG .. TRIGGER CONTROL TASK ROUTINE.
*        CALLING SEQUENCE ..
*
*                 ...      ...         CONTROL TASK FUNCTION WORD IN R8
*                 BAL,R11  CTRIG       CALL TO STACK IN 'IOCTQ'
*
*        NO VULNERABLE REGISTERS.  RETURNS WITH INTERRUPTS ENABLED.
*        NOTE: MAY USE 'CTRIG1' IF ALREADY DISABLED UPON ENTRY.
         SPACE
TP30     LD,R8    KEYINBUF          GET MESSAGE FROM KEYIN BUFFER
         SCD,R8   -24               ALIGN ADDRESS FOR SEARCH
         LI,R1    DCTSIZ+DCTSIZ+1   INITIAL INDEX
         CW,R9    DCT16,R1          CHECK ONE
         BE       TP31              GOT IT
         AI,R1    -2                BACK UP AN ENTRY
         BGZ      %-3               CONTINUE
TP30A    LW,R8    Y03               SPECIAL ENTRY FOR KEYIN EA
CTRIG    DISABLE                    SET ALL INTERRUPT INHIBITS
CTRIG1   PSW,R8   IOCTQ             PUSH CONTROL WORD INTO C.T. STACK
         LI,R8    1                 SET FLAG FOR CONTROL TASK PROCESSOR
         OR,R8    CTFLAGS           ..
         STW,R8   CTFLAGS           ..
         LI,R8    CTINT             IS THERE INTERRUPT FOR CONTROL TASK.
         BEZ      CTOCINT           NO, GO TRIGGER CONSOLE INTERRUPT
         LW,R8    CTGL              YES, GET GROUP LEVEL OF INTERRUPT
         WD,R8   *CTWD              TRIGGER CONTROL TASK LEVEL
         B        ENBSR4            RETURN TO CALLING PROGRAM
         SPACE
CTOCINT  LI,R8    X'10'             SELECT OPERATOR CONSOLE INTERRUPT
         WD,R8    X'1700'           TRIGGER FOR CONTROL TASK
         MTW,1    CTOC              AND FLAG INTERRUPT HANDLER
         SPACE
ENBSR4   ENABLE                     REMOVE INTERRUPT INHIBITS **ENABLE**
         B       *R11               RETURN TO CALLING PROGRAM
         SPACE
         DEF      ENBSR4            CATCH-ALL NAME FOR ENABLE EXIT
         PAGE
         SPACE
*        STARTIO .. INITIATE I/O ACTIVITY FOR A REQUEST.
*        AT THIS POINT, THERE IS A STARTABLE REQUEST IN R3.  THE DEVICE
*        ACTIVITY COUNTER IS SET IN R14 AND INTERRUPTS ARE ENABLED.
*        THE I/O HANDLER PRE-PROCESSOR IS CALLED UNLESS USER COMMAND
*        LIST IS SPECIFIED.  HANDLER RETURN IS TO 'IOSST'.
*        REGISTER SETUP FOR I/O HANDLER:
*
*        R0  ..  DOUBLEWORD ADDRESS OF COMMAND LIST
*        R1  ..  PRIORITY, CIT CHECK MASK, DCT INDEX (8,4,20)
*        R2  ..  FLAGS, SERDEV EXIT, CIT INDEX (3,10,19)
*        R3  ..  REQUEST IOQ INDEX
*        R4  ..  HANDLER FLAGS, SUBCHANNEL ALLOCATION CODE (8,24)
*        R10 ..  DEVICE OPERATION TABLE ('DOT') FOR 'IOSST'
*        R14 ..  DEVICE ACTIVITY COUNT FOR RE-ENTRANCY CHECK
*        R15 ..  NOT USED - SAVED FOR FUTURE EXPANSION
*
         SPACE
STARTIO  LH,R14   DCT10,R1          START, SET DEVICE ACTIVITY COUNTER
         ENABLE                     RUN HANDLER & INITIAL START ENABLED
         STB,9    2
         STB,R0   R1                SAVE PRIORITY & MASK IN R1(0-11)
         LW,R6    DCT8,R1           GET HANDLER PRE-PROCESSOR ADDRESS
         INT,R7   IOQ8,R3           IS USER COMMAND LIST SPECIFIED.
         BCR,4    0,R6              NO, CALL I/O HANDLER, RETURN 'IOSST'
         DO       DUALFLAG
         BCR,2    %+2               YES, IS OPERATION RESTRICTED TO SC1.
         LB,R4    SSCFORCE,R4       YES, FORCE TO SC1 IF UNALLOCATED.
         FIN
         LW,0     IOQ8,3
         AND,0    M21
         LH,R8    IOQ9,R3           GET I/O TIMEOUT INCREMENT
         LI,R9    0                 SET NULL RE-TRY & FOLLOW-ON CODES
         B        IOSTRT            GO TO ENTRY DISABLE POINT
         SPACE
IOSST    AND,R0   M16               HANDLER RETURN, MASK COMMAND LIST
         LB,R7    IOQ5,R3           GET CURRENT FUNCTION STEP INDEX
         INT,R8  *R10,R7            GET 'DOT' INFORMATION FROM HANDLER
         AND,R8   XFF               MASK TIMEOUT INCREMENT IN BYTE 2
         PAGE
         SPACE
*        IOSTRT .. INITIATE I/O ACTIVITY ON COMPLETED COMMAND LIST.
*        REGISTER SETUP IS AS IN STARTIO, WITH R8 CONTAINING THE
*        TIMEOUT INCREMENT (IN 5-SECOND INTERVALS) FOR THE OPERATION
*        AND R9 CONTAINING THE RE-TRY & FOLLOW-ON OPERATIONS.  THE
*        OBJECTIVE IS TO GET THE I/O GOING AS SOON AS POSSIBLE; THUS,
*        THE FRANTIC CODE AT THE BEGINNING.
         SPACE
IOSTRT   DISABLE                    DISABLE POINT, START CRITICAL CODE
         CH,R14   DCT10,R1          HAS START/CLEANUP BEEN SCHEDULED.
         BNE      RESCHED           YES, RE-ENTERED, ABORT I/O START
         LI,R14   0                 SET FOR NO MESSAGE
         LB,R5    CIT3,R2           NO PRE-EMPT, GET CHANNEL STATUS
         LB,R10   IOQ3,R3           AND GET REQUEST SWITCH BYTE
         DO       DUALFLAG
         EXU      CHANTEST,R4       SELECT RELEVANT STATUS IF ASSIGNED
         FIN
         CB,5     2
         BANZ     RESCHED           YES, ABORT START, BACK TO IOSCHED
IOSTRT1  STB,R8   DCT18,R1          NO, SAVE I/O TIMEOUT INTERVAL COUNT
         STH,R9   DCT17,R1          SAVE RE-TRY & FOLLOW-ON CODES
         LB,R9    DCT5,R1           GET DEVICE SWITCH BYTE 2
         AND,R9   X7                RESET STATE FLAGS & DATA XFER BIT
         DO       DUALFLAG
         EXU      IOALOAD,R4        GET DEVICE I/O ADDRESS IN R6
         ELSE
         LH,R6    DCT1,R1           SINGLE-ACCESS ONLY, GET I/O ADDRESS
         FIN
         REF      DCT25
         MTW,1    DCT25,R1          BUMP THE NUMBER OF SIO'S ATTEMPTED
         LCI      0
         SIO,R12  0,R6              ATTEMPT I/O START ON THIS ADR.
         BCS,2    CC3FAIL           BUS/PARITY RESULTS UNKNOWN
         STCF     DCT19,R1          SAVE SIO CONDITION CODES
         BCS,12   IOREJECT          IF IT FAILED, EXIT TO ANALYZE FAULT
         LB,R7    DCT15,R1          IS THIS A REAL-TIME IOEX REQUEST?
         BEZ      IOSTRT5           NO, CONTINUE
         LI,R7    IOSTRT3           YES, SET RETURN FROM RTROOT
         B        RTIOSTRT          SPECIAL PROCESSING IN RTROOT
IOSTRT5  EQU      %
         DO       DUALFLAG
         STH,R6   DCT1,R1           ACCEPTED, SET 'ACTIVE' I/O ADDRESS
         FIN
         LB,7     DCT14             GET HEAD
         STB,1    DCT14             MAKE CURRENT REQUEST NEW HEAD
         STB,7    DCT14,1           LINK TO REST OF CHAIN
         STB,1    DCT15,7           AND BACK LINK
         LC       R13               CHECK FOR DEVICE 'MANUAL' OR 'AUTO'
         BCS,1    IOSTRT3           AUTOMATIC, CONTINUE PROCESSING
         LB,R7    DCT4,R1           MANUAL, SPECIAL TEST FOR PAPER TAPE
         EOR,R7   X3                IS DEVICE PAPER READER/PUNCH (2/3).
         BDR,R7   IOSTRT2           NO, DEVICE IS DEFINITELY MANUAL.
         LCI      0
         TDV,R13  0,R6              GET TDV STATUS
         BCS,2    CC3FAIL           BUS/PARITY RESULTS UNKNOWN
         PAGE
         SPACE
         SLS,R13  3,R7              CHECK BIT 2 = PUNCH, BIT 3 = READER
         CI,R13   0                 IS SPECIFIED SUB-UNIT MANUAL.
         BGE      IOSTRT3           NO, OTHER ONE MUST BE - IGNORE IT
IOSTRT2  AI,R9    2                 MANUAL, SET FLAG IN DCT SWITCHES
         LI,R14   MSG1              SET UP TO OUTPUT 'MANUAL' MESSAGE
         LI,R8    3                 AND SET 15-SECOND TIME-OUT INCREMENT
IOSTRT3  AW,R8    IOCLOCK           ADD CURRENT I/O CLOCK TO TIMEOUT
         STW,R8   DCT11,R1          SAVE I/O DEADLINE VALUE IN DCT
         AI,R9    X'80'             SET DEVICE TO 'BUSY' MODE
         LC       R4                GET I/O HANDLER PRE-PROCESSOR FLAGS
         BCS,8    RELEASSC          IS SUBCHANNEL RELEASE SPECIFIED.
         BCR,2    IOSTRT4           NO, IS SUBCHANNEL TO BE HELD.
         OR,R5    CHFLAGS,R4        YES, SET APPROPRIATE HOLD FLAGS.
         EXU      CHSAVE,R4         SAVE REQUEST INDEX IN CIT5 OR CIT6
IOSTRT4  OR,R5    CBFLAGS,R4        SET APPROPRIATE SUBCHANNEL(S) BUSY
         AI,R9    X'10'             AND SET DEVICE 'DATA-TRANSFER' BIT
IOSTEX   LW,R6    IOQ6,R3           IS THIS A DCB I/O REQUEST.
         BEZ      IOSTEX2           NO, SKIP DCB INITIALIZATION
IOSTEX1  LI,R12   3                 YES, GET 2-BIT ASSIGNMENT MASK
         AND,R12  0,R6              EXTRACT ASN FROM DCB WORD ZERO
         CI,R12   CFUBIT            IS I/O BEING DONE FOR FILE.
         BE       IOSTEX2           YES, DO NOT RESET 'TYC' FIELD
         LW,R13   Y00FE             NO, SET 7-BIT 'TYC' FIELD TO ZERO
         STS,R12  2,R6              ..
IOSTEX2  STB,R3   DCT6,R1           LINK THIS REQUEST TO DEVICE
         STB,R5   CIT3,R2           SAVE CHANNEL STATUS FLAGS
         STB,R9   DCT5,R1           AND DEVICE STATUS BYTE 2
         AI,R10   X'80'             SET REQUEST BUSY IN IOQ3 SWITCHES
IOSTEX3  STB,R10  IOQ3,R3           RESTORE UPDATE IOQ3 SWITCH BYTE
         MTH,1    DCT10,R1          UPDATE DEVICE ACTIVITY COUNTER
         LC       4                 GET FLAGS
         BCR,8    IOSTEX35          IS SUBCHANNEL RELEASE SPECIFIED
         BCR,4    IOSTEX35          WAS FCN DECREMENTED
         LI,5     IOSTEX35          SET RETURN ADDRESS
         PUSH     9,R13             SAVE REGS LIKE REQCOM
         LW,4     IOQ6,3            GET DCB ADDRESS
         LB,5     IOQ15,3           AND USER NUMBER
         LI,0     0                 ZAP USER NUMBER
         STW,0    IOQ6,3
         STB,0    IOQ15,3           SO WE REPORT ONLY ONCE
         XW,0     IOQ16,3           GET & ZERO USER ECB/EA POINTER.
         LW,3     0                 GET TO RIGHT REG FOR RC28.
         B        RC28              WADE INTO END OF REQCOM
IOSTEX35 EQU      %
         ENABLE                     REMOVE INTERRUPT INHIBITS
         LB,R0    R1                RESTORE PRIORITY CODE INTO R0
         LW,R13   R14               IS THERE ANY MESSAGE TO BE OUTPUT.
         BEZ      %+2               NO, DON'T ASK FOR ANY TYPEOUT
         BAL,R5   MSGOUT            YES, PASS MESSAGE INDEX IN R13
         LC       DCT5,R1           WAS CLEANUP SET BY I/O START.
         BCR,4    IOSCHED1          NO, RE-ENTER SCHEDULER FOR MORE I/O
         B        DSERV             YES, CHECK DEVICE PRIOR TO SCHEDULER
         SPACE
RELEASSC BCR,4    IOSTEX            SUBCHANNEL RELEASE, DECR FCN COUNT.
         LW,R6    IOQ6,R3           YES, REQUEST COMPLETE (E.G., REWIND)
         BEZ      IOSTEX2           IS THERE A DCB FOR THIS REQUEST.
         LB,R7    IOQ10,R3          YES, GET MAX RECOVERY TRIES
         CB,R7    IOQ11,R3          HAVE WE ALREADY DONE A RE-TRY.
         BNE      IOSTEX1           YES, DON'T DECREMENT FCN COUNT
         LI,R7    BAFCN             NO, SET POINTER TO FUNCTION COUNT
         MTB,-1  *R6,R7             DECREMENT ACTIVE FUNCTION COUNT
         B        IOSTEX1           RETURN TO FINISH UP I/O START
         PAGE
         SPACE
         DO       DUALFLAG
CHANTEST NOP                        SUBCHANNEL ASSIGNMENT CHECK LIST
         AND,2    =X'A0FFFFFF'
         AND,2    =X'50FFFFFF'
         B        FORCESC           011 .. DUAL-ACCESS RESTRICTED TO SC1
         B        ASSIGNSC          100 .. UNASSIGNED DUAL-ACCESS
         SPACE
IOALOAD  LH,R6    DCT1P,R1          LOAD I/O ADDRESS: 00 = BOTH SC'S
         LH,R6    DCT1P,R1          01 .. ON SC1 .. PRIMARY I/O ADDRESS
         LH,R6    DCT1A,R1          10 .. ON SC2 .. SECONDARY ADDRESS
         FIN
         SPACE
CHSAVE   STB,R3   CIT5,R2           SAVE HOLDING REQUEST - BOTH SC'S
         DO       DUALFLAG
         STB,R3   CIT5,R2           01 .. HOLD ON SUBCHANNEL 1
         STB,R3   CIT6,R2           10 .. HOLD ON SUBCHANNEL 2
         FIN
         SPACE
CBFLAGS  DATA     X'C0'             SUBCHANNEL BUSY FLAGS: 00 = BOTH
         DO       DUALFLAG
         DATA     X'80'             01 .. SUBCHANNEL 1 ONLY
         DATA     X'40'             10 .. SUBCHANNEL 2 ONLY
         FIN
         SPACE
CHFLAGS  DATA     X'30'             SUBCHANNEL HOLD FLAGS: 00 = BOTH
         DO       DUALFLAG
         DATA     X'20'             01 .. SUBCHANNEL 1 HELD
         DATA     X'10'             10 .. SUBCHANNEL 2 HELD
         SPACE
SSCFORCE DATA     X'00010200'       ALLOCATION CODE TRANSLATION TABLE
         DATA     X'03000000'       TO FORCE DUAL-ACCESS TO S.C. 1 ONLY
         FIN
         PAGE
         SPACE
*        FORCESC .. FORCE DUAL-ACCESS TO SUBCHANNEL 1 OPERATION.
*        ASSIGNSC .. ROUTINE TO DETERMINE SUBCHANNEL ASSIGNMENT FOR
*        A NEW OPERATION ON A DUAL-ACCESS DEVICE.  ASSIGNMENT HAS
*        BEEN DELAYED TO 'IOSTRT' TIME IN ORDER TO AVOID RE-SCHEDULING
*        DUE TO PRE-EMPTION OF THE SUBCHANNEL BY A HIGHER-PRIORITY
*        TASK.  ALGORITHM WORKS AS FOLLOWS:
*
*        1.  IF NEITHER SUBCHANNEL IS AVAILABLE (NOT BUSY, NOT HELD),
*            THE I/O SCHEDULER IS RE-ENTERED.
*        2.  IF ONE AND ONLY ONE SUBCHANNEL IS AVAILABLE, THAT SUB-
*            CHANNEL IS TAKEN BY DEFAULT.
*        3.  IF BOTH SUBCHANNELS ARE AVAILABLE, THE 'PREFERRED' BIT
*            IS EXTRACTED FROM THE CIT STATUS AND IS USED TO SELECT
*            THE SUBCHANNEL TO BE USED.  THE BIT IS THEN INVERTED.
         SPACE
         DO       DUALFLAG
FORCESC  LI,R4    1                 DUAL-ACCESS DEVICE FORCED TO SC1
         AI,R10   -3                FORCE IOQ ACCESS KEY TO 001
         CI,R5    X'A0'             IS SUBCHANNEL 1 IDLE AND FREE.
         BAZ      IOSTRT1           YES, RETURN TO START I/O ON SC1
         B        IOSTEX3           NO, RE-SCHEDULE WITH NEW ACCESS KEY
         SPACE
ASSIGNSC SCS,R5   -3                R4 KEY = 100: UNASSIGNED DUAL-ACCESS
         LH,R6    SELECTAB,R5       GET RIGHT HALFWORD OF SELECTAB ENTRY
         BGEZ     SCHEDXIT          IS ANY SUBCHANNEL IDLE & FREE.
         SAD,R6   -13               YES, SET UP SUBCHANNEL SELECT DATA:
         AND,R7   Y8                SC1|-3/0, SC2|-2/0, EITHER|-3/1**31
         AD,R4    R6                SELECT, INVERT 'PREFERRED' IF EITHER
         SCS,R5   3                 RESTORE (POSSIBLY NEW) CIT STATUS
         LI,R11   7                 MOVE SUBCHANNEL INDEX TO IOQ3
         LS,R10   R4                TO FORM NEW IOQ ACCESS KEY
         B        IOSTRT1           AND RETURN TO CONTINUE I/O START
         FIN
         PAGE
         SPACE
*        IOREJECT .. PROCESS REJECTED 'SIO' INSTRUCTION.  ACTION TO
*        BE TAKEN IS A FUNCTION OF CONDITION CODE STATUS AS FOLLOWS:
*
*        01 .. SIMPLE SIO REJECTION.  REVERSE IOQ ACCESS KEY IF DEVICE
*              IS DUAL-ACCESS AND DEVICE IS 'RESERVED' -- A CONDITION
*              NORMALLY UNEXPECTED BUT MAY OCCUR AFTER SPECIAL I/O,
*              SUCH AS SYSTEM START-UP OR RECOVERY.
*        10 .. SELECTOR IOP BUSY WITH ANOTHER CONTROLLER OR CON-
*              TROLLER BUSY WITH ANOTHER DEVICE.  SET 'SIO-FAIL'
*              BIT IN DCT3 AND CLEANUP PENDING.
*        11 .. DEVICE ADDRESS NOT RECOGNIZED.  SET 'SIO-FAIL' AND
*              CLEANUP PENDING.
         SPACE
IOREJECT LW,12   0                  NON-OP DEVICE LEAVES GARBAGE
         STCF     12                SIO REJECTED SAVE CC
         STD,R12  DCT13,R1          SAVE SIO STATUS IN DCT
         LB,R6    DCT3,R1           GET DEVICE STATUS BYTE 1
         DO       DUALFLAG
         LI,R7    3                 SET ACCESS KEY COMPARE MASK
         EOR,R13  Y4                AND CHECK FOR DEVICE STATUS '10'
         CW,R13   YE                IS DEVICE STATUS 'RESERVED' (10)
         CS,R6    R7                AND IS DEVICE DUAL-ACCESS (KEY=11).
         BCS,15   SIOFAIL           AND IS SIO CC1 ZERO (STATUS AVAIL).
         EOR,R10  R7                YES, RE-SCHEDULE ON OTHER CONTROLLER
         B        IOSTEX3           BY INVERTING IOQ ACCESS KEY.
         FIN
         SPACE
SIOFAIL  AI,R6    8                 DEVICE NOT STARTABLE, SET FAIL BIT
         STB,R6   DCT3,R1           ..
         AI,R9    X'50'             SET CLEANUP PENDING, DATA TRANSFER
         B        IOSTEX            FINISH UP I/O START & EXIT
         PAGE
*
IOINT    EQU      %
*
*    I/O INTERRUPT RECEIVER
*
*    PSD HAS CC=0
*
         STW,1    TEMP              SAVE FOR LATER PUSH
         LI,1     19                OPEN
         MSP,1    TSTACK             STACK
         LI,1     -15               REG 0
         AW,1     TSTACK             STACK LOC
         XW,1     TEMP              RESTORE REGS
         LCI      0                 STACK
         STM,0    *TEMP              'EM
         LI,3     -1
         LD,0     IOPSD             STACK
         STD,0    *TEMP,3            CONTROL INFO
         ENABLE                     LET 'EM COME
         LCI      0
         AIO,1    0                 ACKNOWLEDGE
         BCS,2    CC3FAIL           BUS PARITY RESULTS UNKNOWN
         STCF     R3                SAVE AIO CC STATUS
         BCR,8    IO7               BRANCH IF OK
         MTW,1    UNEXP             ELSE, COUNT UNEXP INTS
         REF      UNEXP
         B        IO70              DON'T LOG UNRECOGNIZED
IO62     STH,7    15                SET MSG HEADER
         LW,R0    TIME              ERROR
         LW,R2    R3                RECORD
         SLS,R2   -8
         LI,R6    R15               ADDRESS OF ERROR RECORD
        AW,R6     Y4              TELL ERROR LOGGER NOT TO CALL IOQ
         BAL,5    ERRLOG            LOG THE GLITCH
RTRET2   EQU      %                 EXTERNAL RETURN FROM RTROOT(IOEX)
         DEF      RTRET2
IO70     LI,2     X'20'             CLEAR IO LEVEL
         DISABLE
         WD,2     X'1200'           CLEAR I/O LEVEL
         B        T:PULLE           AND PULLEXIT
IO7      MTW,1    INTCNT            COUNT 'EM UP
         LI,2     X'FFFF'
         AND,2    1                 DEVICE ADDR
         DISABLE                    DISABLE WHILE HANDLING CHAIN
         LB,7     DCT14             GET HEAD
IO75     CH,2     DCT1,7            CHECK DEVICE ADDRESS
         BNE      IO76              NO
         LB,6     DCT14,7           YES, DEQUEUE IT
         LB,5     DCT15,7           BACK LINK
         LI,8     0
         STB,8    DCT14,7           ZAP ANY GARBAGE
         STB,8    DCT15,7           IN FLINK AN BLINK
         STB,5    DCT15,6           CROSS LINK
         STB,6    DCT14,5           REMAINING ENTRIES
         B        IO10
IO76     LB,7     DCT14,7           FLINK TO NEXT DEVICE
         BNE      IO75              WITH I/O IN PROGRESS
         LI,7     DCTSIZ            TOLOOK IT UP
IO71     CH,2     DCT1,7
         BNE      IO8               NOT YET FOUND
IO10     EQU      %
         LC       DCT5,R7           TEST DEVICE BUSY BIT
         BCS,8    IO14              DEVICE WAS BUSY
*
*        DEVICE WAS NOT BUSY - SEE IF NOT BUSY INT IS POSSIBLE
*
         INT,R11  DCT9,R7           GET DCT NINE ENTRY
         BCS,4    IO14              GO ON - NOT BUSY INT'S OKAY
         LB,R9    DCT4,R7           GET TYPE FLAGS
         CI,R9    X'10'             IS A COC TYPE DEVICE
         BE       COC:SCR           YEP - CRASH SYSTEM
         MTB,0    DCT15,R7          CHECK FOR PRE- EMPTED
         BEZ      IO12              NO, MIGHT BE AVR
         LW,R6    DCT12,R7          GET ENTRY ADDRESS
         BLZ      RTINT             IF A REAL-TIME IOEX INTERRUPT
         LI,R11   IO70              SET RETURN
         MTW,-1   INTCNT            ONE LESS INTERRUPT
         LI,R5    J:JIT
         B        0,R6              GO TO DEVICE INTERRUPT HANDLER
IO12     CW,1     Y4                CHK DEVICE END
         BAZ      IO8               NO
         REF      BATAPE,AVRTBLSIZ
         CI,7     BATAPE+AVRTBLSIZ-1 MAKE SURE NOT PACK
         BG       IO50              LOG ERR IF AVR PACK
         LW,8     Y02               ASSUME AVR
         OR,8     7                 COMBINE DCT
         LI,11    IO22              SET RETURN
         B        CTRIG             TRIGGER CONTROL TASK
IO8      BDR,7    IO71              TRY NEXT ENTRY
*
*        CAN'T FIND THE DEVICE OR IT WASNT BUSY, LOG
*        AN ERROR RECORD.
*
IO50     LI,7     X'1304'           CODE/COUNT
         MTW,-1   INTCNT            DECREMENT COUNTER
         B        IO62              LOG ERROR
IO14     EQU      %
         STW,1    DCT12,7           SAVE AIO INFO
RTRET1   EQU      %                 EXTERNAL RETURN FROM RTROOT(IOEX)
         DEF      RTRET1
         LB,R6    DCT5,R7           GET DEVICE FLAGS
         AND,R6   X7F               STRIP DEVICE BUSY
         OR,R6    X40               SET CLEANUP PENDING
         STB,R6   DCT5,R7           REPLACE IT
         ENABLE                     ******   ENABLE *******
         LB,R3    R3                POSITION AIO CONDITION CODES
         STB,3    DCT19,7           SAVE
         LCI      0
         TIO,3    0,2               STATUS OF I/O
         BCS,2    CC3FAIL           BUS/PARITY RESULTS UNKNOWN
         LH,3     3
         STH,3    DCT21,7           SAVE IN DCT
         LCI      0
         TDV,2    0,2               GET TDV STATUS
         BCS,2    CC3FAIL           BUS/PARITY RESULTS UNKNOWN
         STCF     DCT20,7           SAVE STATUS & CC
         STD,2    DCT13,7           SAVE THE INFO IN DCT
*
*        DCT9 WORD IS IN R11 - BIT 1 INDICATES NOT BUSY INT GOES
*        STRAIGHT THRU TO CLEANUP FRONM HERE
*
         INT,R11  DCT9,R7           BUSY?
         BCS,4    IO20              YEP - GO ON
         CI,6     X'10'             DATA XFER
         BAZ      IO20              NOPE
         LB,5     DCT2,7            CIT INDEX
         LB,4     CIT3,5            CIT SWITCHES
         DO       DUALFLAG
         LB,R3    DCT6,R7           GET IOQ INDEX
         LB,R3    IOQ3,R3           GET IOQ SWITCHES
         AND,R3   X3                EXTRACT ACCESS KEY
         EOR,R4   CBFLAGS,R3        SET SUBCHANNEL(S) NOT BUSY
         ELSE
         EOR,R4   CBFLAGS           SET SINGLE-ACCESS NOT BUSY
         FIN
         STB,4    CIT3,5
IO20     EQU      %                 READY TO EXIT INTERRUPT HANDLER
*  EXECUTE SPECIAL END ACTION FROM R1 HERE
IO22     LI,6     X'20'             CLEAR
         WD,6     X'1200'            IO LEVEL
         LW,R1    R7                GET DCT FOR SCHEDULER
         BAL,R2   DRIVEIO           CALL I/O SCHEDULER
IO30     MTW,-1   INTCNT            COUNT 'EM DOWN
         BNEZ     T:PULLE
         BAL,11   SACT
         LI,11    0
         XW,11    INTFLG            SEE RC28 IN REQCOM
         BEZ      SSE0
         B        T:SSE
         REF      SSE0,T:PULLE,INTCNT,INTFLG,SQHD
         PAGE
*
*        THE COC DEVICE HAS JUST INTERRUPTED ON AN UNUSUAL END
*        THATS IMPOSSIBLE BUT HERE WE ARE
*
COC:SCR  SCREECH  X'2B'
         PAGE
         SPACE
*        CLEANUP  - DO POST-PROCESSING, PRIORITY PERMITTING.
*        CLEANUP1 - DO POST-PROCESSING, REGARDLESS OF PRIORITY.
*
*        IF PRIORITY PERMITS, THE DEVICE ACTIVITY COUNT IS SET IN R14,
*        INTERRUPTS ARE ENABLED, AND THE REQUEST CURRENTLY BEING SER-
*        VICED BY THE DEVICE IS PROCESSED BY THE I/O HANDLER, WITH
*        THE DEVICE RETURNED TO THE 'FREE', 'INTER-OP', OR 'KEYIN-
*        PENDING' STATE, AS APPLICABLE.  REGISTER SETUP:
*
*        R1  ..  PRIORITY, DCT INDEX (8,24)
*        R2  ..  FLAGS, SERDEV EXIT, CIT INDEX (3,10,19)
*        R3  ..  SCRATCH, IOQ INDEX (8,24)
*        R12 ..  FLAGS RETURNED FROM HANDLER:
*                BIT 16 .. RE-TRY SEQUENCE
*                BIT 17 .. FOLLOW-ON SEQUENCE
*                BIT 18 .. INTER-OPERATIVE REQUEST
*                BIT 19 .. KEY-IN PENDING (NORMAL)
*                BIT 20 .. KEY-IN PENDING (SPECIAL)
*                BIT 21 .. CONTINUE CHANNEL HOLD
*                BYTE 3 .. TYPE OF COMPLETION
*        R13 ..  MESSAGE TO BE TYPED (0 IF NONE)
*        R14 ..  DEVICE ACTIVITY COUNT
*        R15 ..  NOT USED - RESERVED FOR FUTURE SYSTEMS
         SPACE
         DO       DEFER
CLEANUP  LB,R3    DCT6,R1           SERVICE CLEANUP-PENDING, GET REQUEST
         CB,R0    IOQ14,R3          IS REQUEST PRIORITY BELOW SCHEDULER.
         BL       DEFER1            YES, DEFER CLEANUP, RETURN IOSCHED
         ELSE
CLEANUP  RES      0
         FIN
CLEANUP1 LH,R14   DCT10,R1          NO, SET DEVICE ACTIVITY COUNTER
         LB,R3    DCT6,R1           PRE-EMPT REQUEST INDEX
         ENABLE                     RUN I/O HANDLER IN ENABLED STATE
         STB,R0   R1                SAVE PRIORITY OF SCHEDULER CALL
         LB,R5    DCT15,R1          IS THIS A REAL-TIME IOEX CLEANUP?
         BNEZ     RTCU              YES, BY-PASS HANDLER POST-PROCESSOR
         LW,R5    DCT9,R1           GET I/O HANDLER CLEANUP ENTRY
         LB,15    IOQ15,3
         CW,15    DID               IS IT DIAG USR
         BNE      0,5               NO
         CW,5     Y2                IS IT DIAG REQ
         BAZ      0,5               NO
         BAL,9    IOSERCK
         NOP
         PAGE
         SPACE
IOSCU    DISABLE                    RETURN FROM HANDLER POST-PROCESSOR
         CH,R14   DCT10,R1          WAS START/CLEANUP RE-ENTERED.
         BNE      RESCHED           YES, CLEANUP HAS ALREADY BEEN DONE
         MTH,1    DCT10,R1          NO, INCREMENT ACTIVITY COUNT
         LB,R4    DCT3,R1           RESET TIMEOUT/SIO-FAIL IN DCT3
         AND,R4   XE7               ..
         STB,R4   DCT3,R1           ..
         LB,R5    IOQ3,R3           GET REQUEST SWITCH BYTE
         LI,R4    0                 EXTRACT ASSIGNMENT CODE FROM IOQ3
         LS,R4    X3                ..
         LB,R8    DCT5,R1           SET UP SWITCHES(2) IN R8
         AND,R8   =X'15'            SAVE DATA-XFER, CONTROL-TASK, MODE
         LB,R9    CIT3,R2           GET CHANNEL STATUS FLAGS
         CW,R9    CHFLAGS,R4        IS SUBCHANNEL CURRENTLY BEING HELD.
         BAZ      IOSCCHK           NO, CONTINUE CLEANUP CHECKS
         ANLZ,R6  CHSAVE,R4         YES, GET CIT HOLD TABLE ADDRESS
         LB,R7    0,R6              GET INDEX OF HOLDING REQUEST
         CI,R12   X'400'            IS SUBCHANNEL TO REMAIN HELD.
         EOR,R7   R3                OR IS IT HELD FOR DIFFERENT REQUEST.
         BCS,7    IOSCCHK           YES, CANNOT RELEASE HOLD NOW.
         EOR,R9   CHFLAGS,R4        NO, RESET SUBCHANNEL HOLD FLAG(S).
         STB,R9   CIT3,R2           ..
         STB,R7   0,R6              CLEAR SUBCHANNEL HOLD REQUEST INDEX
IOSCCHK  CI,R12   X'D800'           IS THERE ANY ADDITIONAL ACTIVITY.
         BAZ      REQCOM            NO, REQUEST COMPLETE, END-ACTION
         CI,R12   X'1800'           YES, IS KEY-IN REQUIRED.
         BANZ     IOKEYIN           YES, GO TO KEY-IN PROCESSOR.
         AI,R5    -X'80'            NO, RESET REQUEST 'BUSY' FLAG
         STB,R5   IOQ3,R3           SO THAT REQUEST MAY BE STARTED
         PAGE
         SPACE
         LH,R10   DCT17,R1          GET RETRY/FOLLOW-ON CODES
         CI,R12   X'8000'           IS RE-TRY FLAG SET BY HANDLER.
         BAZ      IOFOLLOW          NO, FOLLOW-ON, PRESUMABLY NO ERROR
         MTB,-1   IOQ11,R3          YES, RE-TRY, DECREMENT RE-TRY COUNT
         BNC      REQERR            NO MORE ATTEMPTS - ERROR COMPLETIOM
         SLS,R10  -8                RE-TRY OK, GET HANDLER FUNCTION CODE
IOFOLLOW STB,R10  IOQ5,R3           SAVE CODE AS NEXT FUNCTION STEP
         CI,R12   X'2000'           IS INTER-OPERATION REQUESTED.
         BAZ      %+2               NO, SEQUENCE IS 'INTERRUPTABLE'
         AI,R8    X'20'             YES, SET DEVICE INTER-OPERATION MODE
         LI,R13   0                 NO MSG FOR RE-TRY/FOLLOW-ON
IOSCEXIT STB,R8   DCT5,R1           SAVE UPDATED DCT SWITCHES(2)
IOCUEXIT ENABLE                     NOW PERMIT INTERRUPTS TO FIRE
         CI,R13   0                 IS MESSAGE TO BE OUTPUT.
         BEZ      RESTPRI           NO, SKIP CALL TO MESSAGE QUEUE
         BAL,R5   MSGOUT            YES, CALL TO OUTPUT MSG IN R13
RESCHED  RES      0
RESTPRI  LB,R0    R1                RESTORE SCHEDULER PRIORITY
         B        IOSCHED           RE-ENTER SCHED
         SPACE
         DO       0
IOKEYIN  LI,R9    CTINT             KEY-IN, DOES CONTROL TASK EXIST.
         B        SETKEYIN          NOT FOR U.T.S. -- BRANCH
*        THIS BRANCH WILL BE REMOVED WHEN CTINT IS DEF'ED AS 0 OR
*        AS THE CONTROL TASK INTERRUPT
         BEZ      SETKEYIN          NO, FOREGROUND NO PROBLEM
         LB,R9    IOQ14,R3          YES, GET REQUEST PRIORITY
         CI,R9    CTINT-X'50'       IS IT ABOVE CONTROL TASK PRIORITY.
         BL       REQERR            YES, COMPLETE REQUEST IN ERROR
         ELSE
IOKEYIN  RES      0
         FIN
SETKEYIN AI,R8    8                 NO, OK, SET DEVICE KEY-IN PENDING
         LD,R10   DCT13,R1          GET TDV STATUS INFORMATION
         STH,R12  R11               SAVE FLAGS, TYC WITH TDV INFO
         STD,R10  DCT13,R1          ..
         LI,R10   6                 SET 30 SECOND TIME-OUT INTERVAL
         AW,R10   IOCLOCK           ..
         STW,R10  DCT11,R1          ..
         B        IOSCEXIT          GO RESTORE DCT SWITCHES & EXIT
         PAGE
*        REQCOM - REQUEST COMPLETE
*
*
*    R1,R3,R4 SET AS FOR CLEANUP
*
*    R10 HAS CCA
*    R11 HAS RBC
*    R12 HAS TYC
*
*        BAL,R5   REQCOM
*
*    R13 TO R4 WILL BE SAVED        *
*
REQERR   LI,R12   8                 ERROR-FORCE ENTRY FROM 'IOSCU'
         B        %+2               ..
REQCOM   LI,R13   0                 REQUEST COMPLETE, NO MSG
         STB,R8   DCT5,R1           SAVE DCT SWITCHES
         LI,R5    IOCUEXIT          SET RETURN ADDRESS IN R5
REQCOM1  PUSH     9,R13             SAVE REGS
         LB,R0    DCT5,R1           GET DCT SWITCHES (2)
         LW,R4    IOQ6,R3           DCB
         BEZ      RC20              NO DCB
         AND,R12  XFF               MASK TYC
         CI,R12   8                 IS IT ERROR
         BNE      RC3               NO
         CW,R4    Y04               READ OR WRITE
         BAZ      %+2               READ
         LI,R12   9                 WRITE
RC3      RES      0
         LI,R6    0                 CLEAR REG FOR RESETTING EGV
         LI,R15   X'F'              EXTRACT ASN
         AND,R15  0,R4              FROM DCB
         CI,R15   3                 CHECK FOR DEVICE
         BNE      RC4               NO DONT CLOBBER
         LI,R5    4                 DISP TO NRT
         LB,R7    IOQ11,R3          GET REAL NUMBER REMAINING
         STB,R7   *R4,R5            TRANSFER TO DCB
         LI,R7    X'20000'          SET BIN BIT IN DCB ACCORDING TO
         CI,R0    1                 TO THE BIN BIT IN DCT5
         BAZ      %+2
         LI,R6    X'20000'
         STS,R6   0,R4
RC4      EQU      %
         LI,R13   X'3F'             MASK FOR TYC
         SLD,R12  17                ALIGN MASK AND TYC
         CS,R12   TYC,R4            TEST FOR NEW PEAK VALUE
         BLE      RC5               DONT CHANGE, PREVIOUS PEAK
         STS,R12  TYC,R4            SAVE NEW VALUE
RC5      LCW,R13  Y01               DECREMENT FUNCTION COUNT
         AWM,R13  FCN,R4            IN DCB.
         LW,R7    IOQ16,R3          IF AN ECB IS ASSOCIATED
         BEZ      RC6               WITH THIS REQUEST,
         SLS,R12  +7                UPDATE THE TYC IN
         CS,R12   2,R7              THE 4-WORD BLOCK
         BLE      RC6               IF NEW TYC IS BIGGER.
         STS,R12  2,R7
RC6      EQU      %
         LI,R7    X'1000'
         STS,R6   0,R4              CLEAR EGV
         CI,R15   2
         BLE      RC10              YES, DO NOT STORE ARS
         LH,R8    IOQ9,R3           BYTE COUNT.
         LW,R5    IOQ8,R3
         BGEZ     RC9  BRANCH IF NO DATA CHAINING
         AND,R5   M21
         LD,R10   DCT13,R1          GET STATUS
         SW,R10   R5                TAKE NUMBER OF COMMANDS USED
         AI,R10   1                 TO COMPUTE ARS
         AND,R10  M16               SCRUB COMMAND COUNT
         LI,R9    0                 CLEAR ACCUMULATOR FOR COUNT
RC7      AD,R8    0,5               ADD COUNT FROM ONE AOMMND
         AI,R5    1                 GET NEXT COMMAND
         BDR,R10  RC7               DO ALL ACTIVE COMMANDS
         LW,R8    R9                TOTAL COUNT OF BYTES IN R8 NOW.
RC9      EQU      %
         SW,R8    R11               COMPUTE ARS = BC - RBC.
         LI,R9    X'7FFF'             15 BIT MASK.
         SLD,R8   17                POSITION ARS AND MASK.
         STS,R8   ARS,R4            STORE ARS IN DCB.
         LW,R6    IOQ16,R3          IF AN ECB IS ASSOCIATED
         BEZ      RC10              WITH THIS REQUEST,
         SLD,R8   -17               UPDATE THE RECORD SIZE IN
         AWM,R8   2,R6              THE 4-WORD BLOCK.
*                             TEST TO RELEASE BUFFER
RC10     CI,R15   CFUBIT            DOES ASN = FILE
         BE       RC15              YES
         CW,R4    Y08               IS IT POSITION OPERATION
         BANZ     RC14              YES, DO NOT RELEASE
         CW,R4    Y04               IS IT READ OP
         BAZ      RC14              YES, DO NOT RELEASE
         LB,R8    IOQ3,R3           IOQ SWITCHES
         CI,R8    X'20'             IS MON BUF USED
         BAZ      RC14              NO
         LW,R14   IOQ8,R3           YES, GET BUFFER ADDR
         SLS,R14  -2                MAKE WORD ADDR
         LW,R8    MPOOL             NEXT AVAIL BUF
         CLM,14   BUFLIMS+MPOOLIM+MPOOLIM   CHECK MPOOL WITHIN LIMITS
         BCS,9    SC1900            SOFTWARE CHECK 19-00
         STW,R14  MPOOL             RELEASED BUF TO HEAD
         STW,R8   *R14              NEXT AVAIL TO RELEASED BUF
*
RC14     EQU      %
         CI,R15   3                 IS IT DEVICE
         BNE      RC15              NO - STILL NOT DIAG CAL
         INT,R11  5,R4              TEST FOR DIAG BIT
         BCR,2    RC15              NO
*  DIAG RETURN -
         LW,R7    DCT12,R1          AIO STATUS
         SLS,7    -16               SAVE ONLY STATUS
         LD,R8    DCT13,R1          TDV STATUS
         LH,R10   DCT1,R1           DEVICE ADDRESS
         AND,10   M11
         LCI      0
         TIO,11   *10               STATUS OF I/O
         BCS,2    CC3FAIL           BUS/PARITY RESULTS UNKNOWN
         LW,10    11
         LCI      4
         STM,7    15,4              SAVE IN DCB
RC15     EQU      %
         LD,R10   IOQ13,R3
         XW,R10   R11               EAI IN R10, E-A ADDR IN R11
         LW,R8    IOQ6,R3           DCB ADDR
         B        RC21
*                                   COMPLETION INFO IF NO DCB
RC20     STB,R12  R11               TYC
         LW,R12   R11               TYC, RBC
         LD,R13   DCT13,R1          CCA
         LD,R10   IOQ13,R3          END-ACTION INFO
         LW,R14   R11               EAI IN R14
         XW,R11   R10               MIGHT AS WELL GETEA REGS COMP.
RC21     RES      0
         LW,R15   IOQ8,R3           BUF ADDR
         CI,R0    1                 CHECK FOR BIN BIT IN DCT5
         BAZ      RC22
         OR,R15   Y02               SET BIN FOR NEWQ
*                             RELEASE Q ENTRY
RC22     EQU      %
         LW,R6    IOQ8,R3           DATA CHAIN
         BGEZ     RC23              NO
         SLS,R6   1                 TO BUILD DATA CHAIN
         LW,R7    MPOOL             RELEASE BUFFER
         CLM,6    BUFLIMS+MPOOLIM+MPOOLIM   CHECK MPOOL WITHIN LIMITS
         BCS,9    SC1900            SOFTWARE CHECK 19-00
         STW,R6   MPOOL
         STW,R7   0,R6
*
RC23     EQU      %
         LB,6     IOQ2,3            FLINK
         LB,R7    IOQ1,R3           BLINK
         BEZ      RC24              FIRST ENTRY
         STB,R6   IOQ2,R7           CUR FLINK TO PREV FLINK
         B        %+2
RC24     STB,R6   CIT1,R2           CUR FLINK TO HEAD
         AI,R6    0                 TEST FLINK
         BEZ      RC26              LAST ENTRY
         STB,R7   IOQ1,R6           CUR BLINK TO NEXT BLINK
         B        %+2
RC26     STB,R7   CIT2,R2           CUR BLINK TO TAIL
*
         LB,R7    QFREE             HEAD OF FREE ENTRIES
         STB,R7   IOQ2,R3           TO FLINK
         STB,R3   QFREE             CUR IS NEW HEAD
*
         MTW,-1   CURBQ             YES, DEC NO. B'GRND ENTRIES
         LB,5     IOQ15,3
         LB,R7    IOQ7,R3           GET DCT INDEX FOR POSSIBLE E A
         LW,R3    IOQ16,R3          GET USER ECB/EA POINTER.
         ENABLE
*
         AND,R11  M22               IS THERE END ACTION
*
         BEZ      RC28
         PUSH     3,R3              SAVE ECB,DCB,USER#.
         LW,R6    R15               BUF ADDR
         BLEZ     %+2
         AND,R6   M22
         SLS,R6   -2                MAKE WORD ADDR
         BAL,R11  *R11              GO TO END-ACTION RECEIVER
         PULL     3,R3              RESTORE ECB,DCB,USER#.
RC28     CI,5     X'FF'
         BAZ      RC30
         BE       RC30              NEWQNW
         LW,R7    R3                DID USER SPECIFY ECB OR EA?
         BEZ      RC29              --> NO.
         MTB,-1   *R7               ARE ALL PHYSICAL I/O'S DONE?
         BNEZ     RC29              --> NO.
         LW,R8    3,R7              IS CAL COMPLETED YET?
         BGEZ     RC29              --> NO.
         LW,R8    R5                R8= USER#.
         LW,R9    2,R7              R9= TYC/RBC FOR ECB INFO WORD.
         LW,R10   1,R7              R10=ECB ADDRESS.
         BAL,R11  ECBPOST1            POST THE ECB.
         LW,R2    R7                WAS 4-WORD BLOCK STILL NEEDED?
         BLZ      RC29              --> YES.
         BAL,R1   ECBFBLK           NO.  FREE THE BLOCK.
RC29     RES      0
         LW,R1    R4                GET DCB ADDRESS
         LI,6     E:IC              REPORT I/O COMPLETE
         STW,6    INTFLG
         BAL,11   T:RUE
RC30     PULL     9,R13             RESTORE REGS
         B        0,R5
*
*
*
CC3FAIL  EQU      %
         RD,R11   X'31D'            GET LAST BRANCH REG.
         SCREECH  X'2A'             AND QUIT
*
*
         PAGE
*
OCINT    EQU      %
*
*    CONSOLE INTERRUPT RECEIVER
*
*        PSD HAS CC=6
*
         PSM,R13  TSTACK            SAVE 13,14,15,0,1,2
         LD,R0    OCPSD             GET PSD
         BAL,R2   T:SAVE            SAVE STANDARD ENV
OCT10    LCW,R8   CTOC              WAS TASK TRIGGERED
         BNEZ     OCT20             YES
         LW,R8    Y01               CODE FOR KEYIN
         BAL,R11  CTRIG             TRIGGER CONTROL TASK
         B        OCT10
OCT20    AWM,R8   CTOC              CLEAR TRIGGER FLAG
         MTW,0    CTACT             IS CONTROL TASK ACTIVE
         BEZ      OCT40             NO
OCT30    LI,R2    X'10'
OCT35    WD,R2    X'1200'           ARM AND ENABLE (CLEAR)
         B        T:SSE             TO SSE TO POINT OF INTERRUPT
OCT40    MTW,1    CTACT             SET CONTROL TASK ACTIVE
         LI,R2    X'10'
         WD,R2    X'1200'           CLEAR OC LEVEL
         PAGE
*
CTIOP    EQU      %                 CONTROL TASK I/O PROCESSOR
*
*    CALLED BY CONTROL TASK OR CONTROL TASK SIMULATOR
*    EXECUTES FUNCTIONS FOUND IN CONTROL TASK I/O STACK
*
*        BAL,R11  CTIOP
*
*    USES ALL REGS
*
*
TP5      DISABLE                                            **DISABLE**
*
         PLW,R8   IOCTQ             GET NEXT FUNCTION
         BCS,2    TP90              STACK EMPTY
*
         ENABLE                                             **ENABLE**
*
         LB,R7    R8                GET CODE
         LB,R7    TPBASE,R7         GET DISP TO ENTRY POINT
         B        TPBASE,R7         SWITCH TO IT
*
:TP      CNAME    0
         PROC
LF       GEN,8    AF(1)-TPBASE
         PEND
*
*
TPBASE   :TP      TP10              0 => DEVICE FUNCTION
         :TP      TP20              1 => CONSOLE INTERRUPT
         :TP      TP40              2 => AVR
         :TP      TP50              3 => KEYIN MSG IN BUF
         :TP      TP60              4 => CHECK ALL DEVICES
         :TP      TP70              5 => PFSR I/O RESTART
         BOUND    4
*
         DO       DEFER             CONTROL TASK DEFERRED CLEANUP
TP10     LW,R1    R8                SET DCT INDEX
*
         DISABLE                                            **DISABLE**
*
         LB,R9    DCT5,R1           GET DCT SWITCHES
         AND,R9   XFB               RESET CONTROL TASK BIT
         STB,R9   DCT5,R1           RESTORE SWITCHES
*
         ENABLE                                             **ENABLE**
*
         BAL,R2   FORCEIO           SERVICE DEVICE WITH PRI X'FF'
         B        TP5
         ELSE
TP10     RES      0
         FIN
*
TP20     LI,R1    TP25              MESSAGE ADDRESS
         BAL,R11  OCWRITE           OUTPUT NL-BANG
         LI,R13   BA(KEYINBUF)      BUFFER ADDRESS
         LI,R0    TP30              END ACTION ROUTINE
         LI,R14   72                SIZE
         LW,R12   TP26              SET FUN AND PRIO
         BAL,R11  QUEUE
         NOP
         B        TP5
*
*
TP25     DATA     X'02155A00'       TEXTC NL-BANG
TP26     GEN,8,8,8,8 0,X'F0',15,OCDCT
*
TP40     EQU      %
         LI,R15   X'FF'
         AND,R15  R8                DCTX
         LI,R14   X'70000'          ALLYCAT COMMAND INDEX
         BAL,R4   ALLOQ
         B        TP5
*
TP50     EQU      %
         LD,0     KEYIN
         BAL,10   T:GJOBSTRT        SEE IF WE CAN START UP KEYIN
         BCR,8    TP5
         LI,R1    3                 LATER MESSAGE
         BAL,11   OCQC
         B        TP5
*
         BOUND    8
KEYIN    TEXTC    'KEYIN'
*                             TIME-OUT TEST, ALL BUSY DEVICES
TP60     LI,R1    DCTSIZ
TP62     EQU      %
         LB,R8    DCT5,R1           DCT SWITCHES
         CI,R8    X'88'             DEV BUSY OR KEYIN PENDING
         BAZ      TP63
         PUSH     R1
         BAL,R2   FORCEIO           YES, FORCE I/O WITH PRIORITY X'FF'
         PULL     R1
         B        TP64
TP63     EQU      %
         LB,R8    DCT15,R1          PRE-EMPTED DEVICE?
         BNEZ     TP65              YES, GO CHECK IT
TP64     EQU      %
         BDR,R1   TP62              DO NEXT
         STW,R1   DEVCTCHK          CLEAR FLAG
         B        TP5
*
*
TP65     EQU      %                 CHECK FOR POSSIBLE IOEX TIMEOUT
         LW,R6    DCT12,R1          INTERRUPT EXPECTED?
         BGEZ     TP64              NO
         LB,R8    DCT18,R1          TIME-OUT REQUESTED?
         BEZ      TP64              NO
         LW,R8    DCT11,R1          OVERDUE TIME VALUE
         CW,R8    IOCLOCK           ARE WE OVERDUE?
         BGE      TP64              NO
         BAL,R11  RTTO              REAL-TIME (IOEX) TIME-OUT PROCESSING
         B        TP64
*
*
TP70     EQU      %
         LI,R1    PFSRMES
         BAL,R11  OCWRITE           WRITE 'POWER FAIL-SAFE' ON OC
         BAL,R11  PFSRIO            RESTART I/O AFTER PFSR
         B        TP5
*
NL       EQU      '
'               NEW LINE X'15'
ZER      EQU      ' '
ZEROS    EQU      ZER,ZER,ZER,ZER,ZER,ZER,ZER
PFSRMES  TEXTC    ZEROS,NL,'POWER FAIL-SAFE',NL
TP90     LI,R2    0
         DO       SYMBFLAG
         LI,3     X'100'            IS SYMFLAG SET
         CW,3     CTFLAGS
         BAZ      TP91              NO
         STS,2    CTFLAGS           YES-SET FLAG OFF
         ENABLE                     AND START SYMBIONTS
         BAL,11   SACT
         B        TP5
TP91     EQU      %
         FIN
         LI,R3    1
         STS,R2   CTFLAGS           RESET FLAG
*
         LI,R1    X'1001'
         CW,R1    CTFLAGS
         BAZ      OCT60
         ENABLE
         B        CTIOP
OCT60    LI,R1    0
         STW,R1   CTACT
         ENABLE
         B        T:SSE
         PAGE
TP33     DISABLE                            ***** DISABLE *****
         OR,R1    YFF               SET PRIORITY
         LB,R8    DCT5,R1           GET DCT SWITCHES
         CI,R8    8                 CHECK FOR KEYIN PENDING
         BAZ      TP32              ERROR NO
         AI,R8    -8                RESET KEYIN PENDING
         STB,R8   DCT5,R1           RESTORE SWITCHED
         LB,R3    DCT6,R1           GET IOQ INDEX
         LB,R8    IOQ3,R3           GET REQUEST SWITCHES
         AI,R8    -X'80'            RESET BUSY BIT
         STB,R8   IOQ3,R3           STORE REQUEST SWITCHES
         LD,R8    DCT13,R1          GET TDV STATUS
         LH,R12   R9                GET HANDLER FLAGS
         LB,R8    DCT4,R1           GET TYPE
         CI,R8    8
         BL       KEYDV
         CI,R8    10
         BG       KEYDV
         LB,R8    IOQ5,R3           GET FUNCTION
         CI,R8    8                 REWIND
         BNE      KEYDV
         MTB,-1   IOQ11,R3          DECREMENT RETRY COUNT
KEYDV    PUSH     11                SAVE END ACTION RETURN
         LB,2     KEYTV,R2          TRANSLATE
         B        KEYDV,R2          SWITCH
KEYTV    DATA,1   0,CKEYN-KEYDV,RKEYN-KEYDV,EKEYN-KEYDV
CKEYN    CI,R12   X'800'            CHECK FOR CONTINUE ALLOWED
         BANZ     RKEYN             NO, TREAT AS R
         LI,R11   0                 RBC 0
         LI,R12   1                 NORMAL TYC
CKEYN1   LB,R2    DCT2,R1           GET CIT INDEX
         BAL,R5   REQCOM1           REQUEST COMPLETE
RKEYN    ENABLE                             ***** ENABLE *****
         BAL,R2   FORCEIO
         PULL     11                RESTORE EA RETURN
         B        ENBSR4            RETURN
EKEYN    LI,R12   8                 ERROR
         B        CKEYN1
         PAGE
TYPERSP  LI,R13   MSG6              WAITING KEYIN
TYPEMSG  LI,R10   10                TIME IN
         AW,R10   IOCLOCK           CURRENT TIME
         STW,R10  DCT11,R1          TIME OUT
         LB,R3    DCT6,R1           Q PNTR
         ENABLE
         LI,R5    IOSCHED           FORCE RETURN
*
MSGOUT   EQU      %                 IO MESSAGE OUTPUT
*
*    R1 HAS DCT INDEX
*    R3 HAS IOQ INDEX
*    R13 HAS MESSAGE ADDR (WORD)
*
*        BAL,R5   MSGOUT
*
*    SAVES ALL REGS
*
         PUSH     10,R11            SAVE R11-R4
         LW,R12   Y06               FUNCTION
         LW,R15   R1                DCT INDEX
         LW,R1    R13               MESSAGE ADDRESS
         BAL,R11  OCWRITE1          WRITE IT
         PULL     10,R11            RESTORE REGS
         B        *R5               RETURN
*
MSG1     TEXTC    ' MANUAL
'
MSG2     TEXTC    ' ERROR
'
MSG3     TEXTC    ' TIMED OUT
'
MSG4     TEXTC    ' NOT OPERATIONAL
'
MSG5     TEXTC    ' WRITE PROTECTED
'
MSG6     TEXTC    ' PLEASE RESPOND
'
MSG7     TEXTC    ' CODE DISC ERR
'
MSG9     TEXTC    ' REQ RETRY
'
MSG9A    TEXTC    ' INCONSISTENT STATUS
'
         PAGE
*
DEVKEYN  DATA,1   0,'C','R','E'
NDEVKEYN EQU      3
TP31     SLS,R1   -1                DCTINDEX
         LB,R7    R8                CHECK SYNTAX
         CI,R7    ','               COMMA
         BNE      TP32              ERROR
         LI,R2    NDEVKEYN          NUMBER OF DEVICE KEYINS
         LH,R8    R8                GET COMMAND BYTE
         CB,R8    DEVKEYN,R2        CHECK IT
         BE       TP33              GOT IT
         BDR,R2   %-2               TRY MORE
TP32     ENABLE                            ***** ENABLE *****
         LI,R1    4                 EH MESSAGE
OCWRITE  RES      0
OCQC     LI,R7    0                 CANNED MESSAGE
OCQUEUE  EQU      %
*
*    R1 HAS MESSAGE CODE
*    R7 HAS DCT INDEX (0 MEANS CANNED)
*
*        BAL,R11  OCQUEUE
*
*    SAVES R5-R11
*
         LW,R12   Y01               SET ASSUMED FUNCTION CODE
         LW,R15   R7                SET DCT INDEX
         BEZ      %+2               ASSUMPTION IS RIGHT
         LW,R12   Y02               SET TO WRITE WITH DEVICE NAME
         CI,R1    NMSG              CHECK FOR RECOGNIZED MESSAGE
         BG       OCWRITE1          NO
         LB,R1    MSGBASE,R1        TRANSLATE CODE TO ADDRESS
         AI,R1    MSGBASE           ADD BASE ADDRESS FOR MESSAGES
OCWRITE1 LI,R0    0                 SET NO END ACTION
OC22     LB,R2    CJOB              PRIORITY
         SLS,R2   16
         OR,R12   R2
         AI,R12   OCDCT             DCTX OF OC DEVICE
OC23     LB,R14   *R1               BYTE COUNT FOR MESSAGE
         ANLZ,R13 OC23              GET BYTE ADDRESS TO R13
         AI,R11   -1                FIX RETURN
         AI,R13   1                 SKIP COUNT
         B        QUEUE             OUTPUT MSG
MSG      CNAME    0
         PROC
LF       GEN,8    AF(1)-MSGBASE
         PEND
MSGBASE  MSG      OC53              0 => EH MESSAGE
         MSG      OC53              1 => EH MESSAGE
         MSG      OC51              2 => AVRERR MESSAGE
         MSG      OC52              3 => LATER MESSAGE
         MSG      OC53              4 => EH MESSAGE
         MSG      OC60              5 => AVAIL
         MSG      OC53              6 => ???
         MSG      OC53              7 => ???
         MSG      OC70              8 => SYMB NOT ACTIVE
         MSG      OC71              9 => SYMB ACTIVE
         MSG      OC72              10=> SYMB NOT SUSP
         MSG      OC73              11=> NOT AVAIL
         MSG      OC74              12=> SYMB NOT SUSPENDED
         MSG      OC75              13=> SYMB TERMINATED
NMSG     EQU      BA(%)-BA(MSGBASE)
         BOUND    4
OC51     RES      0
         TEXTC    '
!!AVRERR
'
OC52     RES      0
         DATA,1   8,X'15',5,'L','A','T','E','R',X'15',0,0,0
OC53     RES      0
         TEXTC    '
  EH? 
'
*
OC60     TEXTC    ' AVAIL
'         DEVICE
*
         DO       SYMBFLAG
OC70     TEXTC    ' SYMB NOT ACTIVE
'  SYMBIONT
OC71     RES      0
         TEXTC    ' SYMB ACTIVE
'
OC72     RES      0
         TEXTC    ' SYMB NOT SUSP
'
OC73     RES      0
         TEXTC    ' SYMB NOT AVAIL
'
OC74     RES      0
         TEXTC    ' SYMB SUSPENDED
'
OC75     RES      0
         DATA     X'1040C4C9'       CNT,' DI'
         TEXT     'SC BLOCK BAD'
         DATA     X'15000000'
         FIN
*
         LOCAL
*
         END

