         TITLE    '**** T:DSMNT ****'
*M*      T:DSMNT  GENERALIZED RESOURCE MANAGEMENT FINAL CLEANUP LOGIC
*P*      NAME: T:DSMNT
*P*      PURPOSE: RELEASE ALL RESOURCES STILL ALLOCATED TO A TERMINATING
*P*       USER. OUTPUT DISMOUNT MESSAGES FOR TAPES AND DEVICE PACKS.
         DEF      T:DSMNT:          FOR PATCHING
T:DSMNT: RES
BITS     SET      1
         SYSTEM   UTS
*
*
*
*
*
*
         PAGE
*                 SYMBOLIC REGISTER DEF'S.
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
SR1      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
         PAGE
*        DEF
         DEF      T:DSMT            CLEAN UP RESOURCES AT JOB END
         PAGE
*        REFS
         REF      ANSFLGS           RESET ANS FLAGS
         REF      AVRFLGS           RESET AVR FLGS
         REF      ASPIN             RESET J:ASPIN
         REF      AVRFNMT           CLEAR OUT ANS FILENAME
         REF      AVRID             CHECK DEVICE OWNERSHIP
         REF      AVRNOU            CHECK LAST USER OF DRIVE
         REF      AVRTBL            CLEAR FLAGS, TYPE SN
         REF      AVRTBLNE          KNOW WHERE THE TABLE STOPS
         REF      AVRTBLSIZ         KNOW WHERE THE TAPES STOP
         REF      BATAPE            DCTX TO/FROM AVRX
         REF      DCT16             DEVICE NAME IN EBCDIC
         REF      DCT23             MOC SLAVE LINE FLAGS
         REF      DCT4              RELEASE THE RIGHT RESOURCE TYPE
         REF      DCTSIZ            KNOW WHERE THE TABLES STOP
         REF      DEALL             RELEASE RESOURCE
         REF      DHHIT             CHECK DEVICE OWNERSHIP
         REF      DOUBLEZERO        KNOWN ZEROES
         REF      GETRAT            DEVICE TYPE TO RESOURCE TYPE
         REF      HOWALO            KNOW WHOSE TO GIVE BACK
         REF      J:AMR             RELEASE ASSIGN MERGE GRANULE
         REF      J:JIT             BATCH GETS DIFFERENT TREATMENT
         REF      JB:MAX            RELEASE BATCH RESOURCES
         REF,1    JB:PNR            CLEAR BATCH PARTITION
         REF,1    JB:SLNK           RELEASE UNUSED SHARED REQUESTS
         REF,1    JB:XLNK           RELEASE TABLE SPACE
         REF      LSERIAL           RELEASE TABLE SPACE
         REF      MSROCTY           TYPE DISN`MOUNT MESSAGE
         REF      PL:JIF            CLEAR BATCH PARTITION
         REF      PLB:MIN           CLEAR BATCH PARTITION
         REF      PLB:USR           CLEAR BATCH PARTITION
         REF      PLD:ACT           CLEAR BATCH PARTITION
         REF      PLH:FLG           CLEAR BATCH PARTITION
         REF      PLH:SID           CLEAR BATCH PARTITION
         REF      RAT:DCT4          DCTX TO RESOURCE TYPE
         REF      RBG               RELEASE ASSIGN-MERGE GRANULE
         REF      RSERIAL           RELEASE UNUSED SHARED REQUESTS
         REF      RSETSPIN          RESET S:XSPIN FOR LAST USER ON DRIVE
         REF      S:CUN             KNOW WHO WE ARE
         REF      S:MBSF            KICK THE BATCH SCHEDULER
         REF      SH:RBCU           RELEASE BATCH RESOURCES
         REF      SV:RSIZ           CLEAR BATCH PARTITION
         REF      XA                DIVIDE BY TEN IN SIXBACK
         REF      X1000FFFF         CLEAR AVRTBL FLAGS (EXCEPT SCRATCH)
         REF      Y18               6WORD MBS TO CLEAR ANS FILENAME
         PAGE
T:DSMT   RES      0
         PUSH     7,R5
         LW,SR1   J:AMR
         BEZ      %+2
         BAL,SR4  RBG
         LW,7     TSTACK
         AI,7     2
         LI,6     7
         BUMP     11,R4             SET UP BUFFER
         LW,D4    CKMESS-1,6
         STW,D4   *7,6
         BDR,6    %-2
         LW,D4    Y8
         STW,D4   -1,7
         AI,R7    1
         STW,R7   -1,7              BUFF
         AI,R7    -2                PLIST
         LI,R5    J:JIT
         LI,SR1   2
*
*
         LI,3     -1
         LI,2     0                 DCTX
CKFF     AI,2     1
         CI,2     DCTSIZ
         BG       DONE
         CI,2     BATAPE+AVRTBLSIZ
         BE       CKPULL
         BG       PACK
         CI,2     BATAPE
         BL       CKJD              DEALLOC AND RESET SPIN
*        TAPE
         AI,3     1                 AVRX
         LW,0     S:CUN
         CH,0     AVRID,3
         BE       CKF1
         B        CKFF
*PACK LOGIC
*                                   FINISHED
CKPULL   RES     0
         BUMP     -11,R4
PACK     AI,3     1
         CI,2     BATAPE+AVRTBLNE
         BGE      CKJD
*        2-DCT     3-AVR
         LI,14    0
SPO      BAL,11   DHHIT
         BAZ      SP1               NO
         BAL,11   ASPIN             RSET ASPIN AND LOAD 15
         MTH,-1   AVRNOU,3
         BNEZ     SP1               NO RELEASE
         LD,D1    AVRTBL,3
         AND,D2   M16               CLEAR FLAGS
         STD,D1   AVRTBL,3          CLEAR NOU  DEV PACK
*        FIN OUT WHERE TO RELEASE
         BAL,11   HOWALO            RESET SPIN AND HOW ALLO IN 0
         BAL,11   RAT:DCT4          1=RATX
         MTH,0    AVRID,3           LOCKED?
         BLEZ     COUNTIT           LOCKED OR SHARED
         LC       J:JIT
         BCR,12   SP1               BATCH EXCL-DO'T COUNT
COUNTIT  RES      0
         MTH,-1   *0,1
SP1      LW,15    S:CUN
         CH,15    AVRID,3
         BNE      %+2
         STH,14   AVRID,3
         AI,2     1
         B        PACK
DONE     RES      0                 ALL DONE WITH SPIN'S
         LI,7     0
         LC       J:JIT
         BCS,12   SP2
         LI,5     JB:PNR
         LB,5     0,5
         STB,7    PLB:USR,5         ZAP USER #
         STD,7    PLD:ACT,5         ZAP ACCOUNT
         STH,7    PLH:SID,5         ZAP ID
         LH,7     PLH:FLG,5         RESET JOB DEPENDENT FLAGS
         AND,7    PL:JIF            JOB INDEPENDENT FLAGS MASK
         STH,7    PLH:FLG,5
         MI,R5    SV:RSIZ+1
        LI,7     0
         STB,7    PLB:MIN,R5       CLEAR EXCLSIVE LINK
         LI,7     SV:RSIZ
RELRES   LB,5     JB:MAX,7
         CI,7     1
         BNE      %+4
         MTB,0    JB:MAX
         BNEZ     %+2
         SLS,5    -1
         AND,5    M7
         LCW,5    5
         AH,5     SH:RBCU,7
         STH,5    SH:RBCU,7
         BDR,7    RELRES            - NEXT RES REL
         LI,5     JB:SLNK-BA(LSERIAL)
SCABORT  RES      0                 TYPE NOT FOUND GO ON
SERIAL   LW,6     5
J11      LB,5     LSERIAL,6
         BEZ      SERIALE
         LB,4     RSERIAL,5         TYPE
         BAL,11   GETRAT
         MTH,-1   SH:RBCU,1         FIND
         B        SERIAL
SERIALE  RES      0
         LI,5     JB:XLNK           NOW CHAIN BOTH X&S TO FREE CHAIN
         LB,5     0,5               ARE THERE ANY
         STB,5    LSERIAL,6         LINK BOTH TOGETHER
         LW,5     6
         LB,6     LSERIAL,5         FIND END OF CHAIN
         BNEZ     %-2
         LI,6     JB:SLNK           GET HEAD
         LB,6     0,6
         BEZ      SP2               NONE ATALL
         WD,0     X'37'             DISABLE
         LB,7     LSERIAL           HEAD OF FREE ENTRIES
         STB,7    LSERIAL,5         LINK NEW CHAIN
         STB,6    LSERIAL           NEW HEAD
         WD,0     X'27'             ENABLE
SP2      EQU      %
         STW,11   S:MBSF            SET MBS FLAG
CNM      EQU      1                 SET=1 IF TP SLAVE LINES SUPPORTED
         DO       CNM
*
*        RELEASE ANY SLAVE LINES OWNED BY THIS USER
*
         SREF     MODE5             COC SLAVE LINE FLAGS
         SREF     COC               TO CK FOR A NON-COC SYSTEM
         SREF     LB:UN             USER # OF LINE OWNER
         SREF     KILLIO            CLEANS UP COC TABLES FOR SLAVE LINE
         SREF     LNOL              #LINES IN SYSTEM -1
         SREF     MOCIOP            TO CK FOR MOC LINE SUPPORT
         SREF     TTP               TO CK FOR NON-TP SYSTEM
*
SLVLNCT  EQU      X'C0'             SLAVE LINE CURRENT TYPE MASK
MOCMNEM  EQU      'MO'              MOC SLAVE LINE DEVICE TYPE CODE
*
         LI,R0    TTP               CK IF THIS IS A TP SYSTEM
         BEZ      GETOUT            B, IF NOT; SKIP SLAVE LINE CKS
         LW,SR2   S:CUN             GET CURRENT USER#
         LI,R0    0                 INITIALIZE R0
         LI,R2    COC               CK IF THIS IS A COC SYSTEM
         BEZ      CKMOC             B, IF NOT; CK FOR TP MOC SUPPORT
         LI,2     LNOL-1            #LINES IN SYSTEM -1
CLEAR10  EQU      %
         LC       MODE5,2
         BCR,8    CLEAR20           NOT SLAVE, OK
         CB,SR2   LB:UN,2           BELONG TO THIS GUY
         BNE      CLEAR20           NO, OK
         BAL,11   KILLIO            YES, CLEAR TABLES
         WD,0     X'37'             DISABLE
         LB,5     MODE5,2           SET LINE TYPE TO DEFAULT
         LW,6     5
         SLS,6    6
         LI,R7    SLVLNCT           GET SLAVE LINE CURRENT TYPE MASK
         STS,6    5
         STB,5    MODE5,2
         STB,0    LB:UN,2           SET LINE STATE=FREE
         WD,0     X'27'             ENABLE
CLEAR20  AI,2     -1
         BGEZ     CLEAR10
CKMOC    EQU      %
         LI,R2    MOCIOP            CK IF TP MOC SUPPORT EXISTS
         BEZ      GETOUT            B, IF NOT; FINISHED HERE
         LI,R2    DCTSIZ            MAX DCT INDEX
GETMNEM  EQU      %
         LD,R6    DCT16,R2          GET CANNED DEVICE MNEMONIC
         SLD,R6   8                 1ST 2 CHARACTERS NOW IN R6
         AND,R6   M16               ISOLATE THEM
         CI,R6    MOCMNEM           SEE IF IT'S MNEMONIC FOR MOC LN
         BNE      CKINDEX           B, IF NOT & SEE IF WE'RE THROUGH
         LI,R5    2
         LH,SR4   DCT23,R2          GET CNM MOC LINE SWITCHES
         CB,SR2   SR4,R5            SEE IF CURRENT USER OWNS LINE
         BNE      CKINDEX           B, IF HE DOESN'T; NOTHING TO RELEASE
         STB,R0   SR4,R5            SET LINE STATE=FREE
         AI,R5    1                 POINT TO MOC SLAVE LINE FLAGS
         LB,R6    SR4,R5            GET UM
         SLS,R6   6                 ADJUST DEFAULT BITS
         LI,R7    SLVLNCT           GET SLAVE LINE CURRENT TYPE MASK
         STS,R6   SR4               SET CURRENT TYPE=DEFAULT
         STH,SR4  DCT23,R2          RESTORE MOC SLAVE LINE FLAGS
CKINDEX  EQU      %
         BDR,R2   GETMNEM
GETOUT   EQU      %
         FIN
         PULL     7,R5
         DESTRUCT
         PAGE
* SIXBACK RETURNS A SIX CHARACTER SERIAL #
* R2=HASHED SERIAL #
* SR1-SR2=EBCDIC SIX CHARACTER SERIAL # LEFT JUSTIFIED
* CALL: BAL,SR4   SIXPACK
*
SIXBACK  EQU      %
         PUSH      4,R3
         SLD,R2   -20
         SLS,R3   -12
         LW,R5    R3
         LI,R6    6
SIXBACK1 EQU      %
         SLD,R2   -2
         SLS,R3   -26
         LI,R4    0
         DW,R4    XA
         OR,R3    R4
         BEZ      %+2
         AI,R3    X'80'
         AI,R3    X'40'
         SLD,SR1  -8
         STB,R3   SR1
         BDR,R6   SIXBACK1
         PULL     4,R3
         B        *SR4
         PAGE
CKF1     RES     0
         LD,D3    DOUBLEZERO
         LW,1     3
         LD,D1    AVRTBL,1
         STH,D3   AVRID,R1
         STB,D3   AVRFLGS,1
         CW,D2    Y1                SCRATCH
         BANZ     SCRCLR            YES
         STD,D3   AVRTBL,R1
         STW,D1   9,R7              REEL NR
*                                   TYPE OUT
         LI,8     X'1F'             BUFFER SIZE
         LC       ANSFLGS,1
         STB,D3   ANSFLGS,R1
         BCR,X'C' CKF11             NOT ANS
         MI,R1    6*4               AVRFNMT INDEX
         AI,R1    BA(AVRFNMT)       ADDRESS OF ENTRY
         OR,R1    Y18               SIX WORD TABE
         MBS,0    BA(DOUBLEZERO)    CLEAR NAME
         XW,2     12                UNHASH ANS SERIAL #
         BAL,11   SIXBACK
         LW,2     12                RESTORE DCTX
         LCI      2
         STM,8    9,7
         LI,8     X'21'
*                 BUFFER SIZE FOR ANS TAPES
CKF11    EQU      %
         LD,D1    DCT16,R2          * NAME OF THAT GUY.
         STB,8    13                BUFFER SIZE
         STW,13   2,7
CKXX     RES      0
         PUSH     7,R1
*O*      MESSAGE: NDD DISMOUNT AND SAVE REEL XXXX(XX)
*O*      MEANING: JOB TERMINATED WITHOUT DISMOUNTING THE TAPE OR PACK.
*O*      ACTION: REWIND AND REMOVE THE TAPE UNLESS REQUIRED FOR NEXT JOB.
         BAL,11   MSROCTY           TYPE
         PULL     7,R1
CKJD     RES      0
*           2=DCTX
         BAL,11   DHHIT
         BAZ      CKFF              NO
         BAL,11   RSETSPIN          RESET SPIN BITS
         LB,4     DCT4,2            TYPE
         BAL,15   DEALL             DEALLOCATE O AND G
         B        CKFF              LOOP
SCRCLR  RES   0
         AND,D2   X1000FFFF
         STD,D1   AVRTBL,R1
         B        CKJD              DONT TYPE
CKMESS   RES      0
         DATA     X'1FC1F0F0'       #A00
         TEXT     ' DISMOUNT AND SAVE REEL'
         END

