***********************************************************
*M*      TQROOT   TP QUEUE MANAGER ROOT                   *
***********************************************************
*P*
*P*      NAME:    TQROOT, TP QUEUE MANAGER ROOT
*P*
*P*      PURPOSE: TQROOT IS THE RESIDENT PORTION OF THE
*P*               QUEUE MANAGER.  IT CONTAINS THE ROUTINES
*P*               WHICH ACCESS THE QUEUE PHYSICAL WORK
*P*               PAGES; INITIATE UNMAPPED I/O FOR THE
*P*               QUEUE FILE; PERFORM CHAINING AND DECHAINING
*P*               FUNCTIONS; AND PROCESS QUEUE I/O END ACTION.
*P*
*P*      DESCRIPTION:  MOST OF THE ROUTINES IN TQROOT RUN IN
*P*               MASTER, UNMAPPED MODE.  THE MAP AND UNMAP
*P*               CALLS ARE MADE IF NECESSARY.  ROUTINES
*P*               GENERALLY RETURN IN MASTER, MAPPED MODE.
*P*
*P*               THE CHAINING/DECHAINING ROUTINES MAY BE
*P*               CALLED WITH INTERRUPTS INHIBITED (CURRENTLY NONE
*P*               OF THE QUEUE MANAGER ROUTINES DO SO).  THE
*P*               TQMAP AND TQUNMAP CALLS CHANGE THE MODE
*P*               WITHOUT CHANGING THE INHIBIT STATE, SO THAT
*P*               CHAINING COULD TAKE PLACE WITH INTERRUPTS
*P*               DISABLED.  THE CHAINING/DECHAINING ROUTINES RETURN
*P*               IN WHATEVER STATE THEY WERE CALLED FROM (I. E.
*P*               EITHER MAPPED OR UNMAPPED).
*P*
*P*      REFERENCES:  XEROX CP-V SYSTEM PROGRAMMING REFERENCE MANUAL
*P*               (90 31 13) DESCRIBES THE QUEUE MANAGER CALS
*P*               AND THEIR FPTS.
*P*
*P*               THE TP QUEUE MANAGER INTERNAL SPECIFICATION
*P*               (703232) CONTAINS PROGRAM AND ROUTINE
*P*               DESCRIPTIONS FOR THE QUEUE MANAGER.
*P*
*P*               THE MODULE LISTING OF SYSTEM LP:TPOQ CONTAINS
*P*               DESCRIPTIONS AND DRAWINGS OF ALL THE INTERNAL
*P*               QUEUE MANAGER TABLES AND THE QUEUE FILE BLOCKS.
*P*
         PCC      0
         TITLE    '****TQ ROOT SEGMENT***'
         SYSTEM   UTS
         SYSTEM   TP:TPO
         SYSTEM   LP:TPOQ
*
*   DEFS FOR ROUTINES IN TQROOT
*
         DEF      TQCHAIN           ADD TO END OF CHAIN
         DEF      TQCHAINC          ADD TO CHAIN BASED ON CRITERIA
         DEF      TQDCHAIN          REMOVE FROM TOP OF CHAIN
         DEF      TQDCHAINA         REMOVE SPECIFIED ELEMENT FROM CHAIN
         DEF      TQDCHAINC         REMOVE FROM CHAIN BASED ON CRITERIA
         DEF      TQUEUEA           QUEUE I/O END ACTION ROUTINE
         DEF      TQIOREJECT        ERROR RETURN FROM NEWQ
         DEF      TQMOVEBSZ         ZERO BYTE STRINGS IN REAL PAGES
         DEF      TQSETBLOCK        UPDATE QUEUE STATISTICS
         DEF      T:GETID           GET TRANSACTION ID
         DEF      TQHSKPICB         INITIALIZE AN ICB ENTRY
         DEF      TQNEWQ            CALL NEWQ FOR QUEUE I/O
         DEF      TQCHKBIT1         INITIALIZE AND CHECK FPT BIT
         DEF      TQCHKBIT          CHECK NEXT FPT BIT
         DEF      TQGETBYTE         GET BYTE FROM REAL PAGE
         DEF      TQGETHWORD        GET HALFWORD FROM REAL PAGE
         DEF      TQGETWORD         GET WORD FROM REAL PAGE
         DEF      TQGETFIELD        GET FIELD FROM REAL PAGE
         DEF      TQLOADF           GET ADDRESS FROM REAL PAGE
         DEF      TQSETBYTE         STORE BYTE IN REAL PAGE
         DEF      TQSETHWORD        STORE HALFWORD IN REAL PAGE
         DEF      TQSETWORD         STORE WORD IN REAL PAGE
         DEF      TQSETFIELD        STORE FIELD IN REAL PAGE
         DEF      TQSTOREF          STORE ADDRESS IN REAL PAGE
         DEF      TQMOVEBS          MOVE BYTE STRINGS IN REAL PAGES
         DEF      TQCBYTE           COMPARE BYTE STRINGS IN REAL PAGES
*
*  REFS TO MONITOR SERVICES
*
         REF      CC1RST            RETURN WITH CC1=0
         REF      CC1SET            RETURN WITH CC1=1
         REF      MISOVSEG          OVERLAY FOR GET TIME SERVICE
         REF      NEWQ              PERFORM QUEUE I/O
         REF      T:RUE             REPORT USER EVENT
         REF      TQMAP             MAP AND KEEP CURRENT ENABLE/
*,*                                 DISABLE STATE
         REF      TQUNMAP           UNMAP AND KEEP CURRENT ENABLE/
*,*                                 DISABLE STATE
*
*  REFS TO MONITOR TABLES AND CONSTANTS
*
         REF      E:UQA             UNQUEUE FOR ACCESS EVENT
         REF      J:DCBLINK         ADDRESS OF DCB TABLE
         REF      J:ASSIGN          TP AUTHORIZATION FLAG IN BIT 9
         REF      J:BASE            ADDRESS OF USER REGISTERS
         REF      JX:CMAP           USER REAL PAGES
         REF      J:JIT             ADDRESS OF USER JIT
         REF      MTIME#            ENTRY FOR M:TIME SERVICE
         REF      X0                CONSTANT OF ZEROS
         REF      Y008              M:TIME TUN FLAG
*
         GENREFS
CSTMBR   EQU      NB31TO0+32        BIT 0 (OFF)
CSTMBS   EQU      BT31TO0+32        BIT 0 (ON)
*
         DEF      TQROOT:           XDELTA SYMBOL
*
TQROOT:  EQU      %
*
TESTTQROOT SET    1
         TITLE    'TQCHAIN....FORWARD  CHAINING,END OF CHAIN'
*DO*                                               *
*D*                                                *
****************************************************
*                                                  *
*              NAME:  TQCHAIN                      *
*                                                  *
*             ADDS AN  ELEMENT TO THE TAIL OF A    *
*              FORWARD CHAIN...                    *
*                                                  *
*              CALL:                               *
*                                                  *
*              ENTERED VIA BAL,R0  TQCHAIN         *
*                                                  *
*              INPUT: R5 = CHAIN HEADER            *
*                     R9 = ADDRESS OF LINK WORD    *
*                     R5, BIT 0 = 0, CHAIN REAL    *
*                               = 1, CHAIN VIRTUAL *
*                                                  *
*              OUTPUT: CC 4 = 0, SUCCESSFUL CHAIN  *
*                           = 1, ALREADY CHAINED   *
*                        R9, BYTE 0 MODIFIED       *
*                            BYTES 1-3 UNCHANGED   *
*                                                  *
****************************************************
*FIN*
         PAGE
*DO*
*D*
*
*        PREFACE: THE CHAINING AND DECHAINING ROUTINES IN
*                 TQROOT PREFORM CHAINING ON A STANDARD FORWARD
*                 CHAIN.  A STANDARD FORWARD CHAIN HAS A TWO WORD
*                 HEADER OF THE FOLLOWING FORMAT:
*
*                          ------------------------------------------
*                 WORD 0   | ADDR. OF LINK OF 1ST ELEMENT ON CHAIN  |
*                 (HEAD)   ------------------------------------------
*
*                          ------------------------------------------
*                 WORD 1   | ADDR. OF LINK OF LAST ELEMENT ON CHAIN |
*                 (TAIL)   ------------------------------------------
*
*                 EACH ELEMENT ON THE CHAIN IS LINKED TO THE NEXT
*                 ELEMENT ON THE CHAIN THROUGH A LINK WORD.  BIT 0
*                 OF THE LINK WORD IS SET TO 1 TO INDICATE THAT
*                 THE ELEMENT IS CHAINED.
*
*        DESCRIPTION:  IF THE ELEMENT IS NOT ALREADY CHAINED, TQCHAIN
*                 TESTS TO DETERMINE IF THE CHAIN IS EMPTY.  IF SO,
*                 THE HEAD AND TAIL OF THE CHAIN ARE SET TO POINT TO
*                 THE NEW ELEMENT.  IF THE CHAIN IS NOT EMPTY, THE
*                 LAST ENTRY IN THE CHAIN (POINTED TO BY WORD 1) IS
*                 SET TO POINT TO THE NEW ELEMENT, AND THE TAIL
*                 (WORD 1) OF THE CHAIN UPDATED TO POINT TO THE NEW
*                 ELEMENT AS WELL.
*
*                 FINALLY, THE LINK WORD OF THE NEW ELEMENT IS
*                 CLEARED TO INDICATE THE LAST ELEMENT ON THE CHAIN,
*                 AND BIT 0 OF ITS LINK WORD IS TURNED ON TO INDICATE
*                 THAT IT IS CHAINED.
*
*FIN*
*
TQCHAIN  EQU      %
         PUSH     2,R0
         BAL,R0   TQCHAINCOM        FRONTEND LOGIC
         LW,D3    1,R5              TAIL OF CHAIN LINK WD PTR
         BEZ      TQCHAIN8          EMPTY CHAIN
         STW,R9   *D3               STORE PTR TO CHAINING
*                                    WORD INTO CURRENT TAIL
         STS,D4   *D3               SET CHAINED BIT
TQCHAIN6 EQU      %
         STW,R9   1,R5              NEW ELEMENT AS TAIL OF CHAIN
         STW,D4   *R9               ZERO FOR TAIL OF CHAIN LINK & CHAINED BIT
         B        TQCHAINYES
TQCHAIN8 EQU      %                 EMPTY CHAIN
         STW,R9   0,R5              STORE ELEMENT AS CHAIN HEAD
*                                   AND CHAIN TAIL
         B        TQCHAIN6
TQCHAINCOM EQU    %                 COMMON ENTRY FOR CHAINING
         PUSH     4,D1
         LW,D1    J:JIT             SAVE ENTRY MODE
         CI,R5    0                 CHECK FOR CHAINING
*                                   IN REAL
         BGE      TQCHAINR          YES
         BAL,R1   TQMAP             CHAIN IN VIRTUAL
         B        TQCHAINCOM2
TQCHAINR EQU      %
         BAL,R1   TQUNMAP           CHAIN IN REAL
TQCHAINCOM2 EQU   %
         LW,R1    D1
         AND,R5   CSTMBR            MASK CHAIN HEADER
         LW,D4    *R9               TEST FOR ALREADY CHAINED
         BL       TQCHAINNO         YES
         LW,D4    CSTMBS
         B        *R0
*
TQCHAINYES EQU    %
         LCFI     0                 SUCCESSFUL EXIT
         B        TQCHAINEXIT
*
TQCHAINNO EQU     %
         LCI      1                 UNSUCCESSFUL EXIT
TQCHAINEXIT EQU   %
         STCF     R9
         CI,R1    0                 EXIT IN ENTRY MODE
         BE       TQCHAINEXIT2
         BAL,R1   TQMAP             CALLED IN VIRTUAL
TQCHAINEXIT1 EQU  %
         PULL     4,D1
         PULL     2,R0
         LCF      R9
         B        *R0
TQCHAINEXIT2 EQU  %
         BAL,R1   TQUNMAP           CALLED IN REAL
         B        TQCHAINEXIT1
         TITLE    'TQCHAINC...CHAINING WITH CRITERIA'
*DO*                                                        *
*D*                                                         *
*************************************************************
*                                                           *
*                 NAME:  TQCHAINC                           *
*                                                           *
*                 ADDS AN ELEMENT TO A CHAIN PRECEDING      *
*                 A SPECIFIED ELEMENT BASED ON CONDITIONAL  *
*                 CRITERIA TEST SPECIFIED BY THE CALLER     *
*                   IF A MATCH IS NOT FOUND, THE ELEMENT    *
*                   IS PLACED ON THE TAIL OF THE CHAIN      *
*                                                           *
*                 CALL:                                     *
*                                                           *
*                   ENTERED VIA  BAL,R0   TQCHAINC          *
*                                                           *
*                 INPUT: R5 = CHAIN HEADER                  *
*                        R7 = DISPLACEMENT OF CRITERION WORD*
*                             FROM LINK WORD                *
*                        R8 = CONDITIONAL BRANCH INSTRUC-   *
*                             TION FOR CRITERION TEST       *
*                              (WITH THE ADDRESS = 0)       *
*                        R9 = ADDRESS OF THE LINK WORD      *
*                        R5, BIT 0 = 0, CHAIN REAL          *
*                                  = 1, CHAIN VIRTUAL       *
*                        R11 = CRITERIA MASK                *
*                                                           *
*                 OUTPUT: CC 4 = 0, SUCCESSFUL CHAINING     *
*                              = 1, UNSUCCESSFUL            *
*                                                           *
*                 R6,R9,R10 MODIFIED                        *
*                                                           *
*************************************************************
*FIN*
         PAGE
*DO*
*D*
*        DESCRIPTION:  CHAINING BY CRITERIA CAUSES THE CHAINING
*                 ONTO A STANDARD FORWARD CHAIN TO BE DONE IN
*                 SOME SPECIFIC ORDER (E. G. IN ASCENDING ORDER
*                 OF THE CRITERIA WORD).  THIS ROUTINE DOES A
*                 COMPARE SELECTIVE OF THE CRITERIA WORD IN THE NEW
*                 ELEMENT WITH THE CRITERIA WORD IN THE CURRENTLY
*                 CHAINED ELEMENTS, THEN EXECUTES THE CONDITIONAL
*                 BRANCH TEST INPUT BY THE CALLER.  WHEN THE BRANCH
*                 IS SATISFIED, THE NEW ELEMENT IS CHAINED IN FRONT
*                 OF THE ELEMENT WHICH IS ALREADY CHAINED AND WHICH
*                 SATISFIED THE CONDITION SPECIFIED.  IF A MATCH IS
*                 NOT FOUND, THE ELEMENT IS CHAINED AT THE TAIL OF
*                 THE CHAIN.
*
*FIN*
*
TQCHAINC EQU      %
         PUSH     2,R0
         BAL,R0   TQCHAINCOM        FRONT END LOGIC
         LW,D1    0,R5              LOOK AT CHAIN HEADER
         BEZ      TQCHAIN8          EMPTY CHAIN
         LW,D2    CSTMBR            SET UP MASKS
         LW,D4    CSTMBR
         LW,R6    R9
         LW,R9    CSTMBS
         AI,R8    TQCHAINC6         ADDRESS FOR CONDITIONAL
*                                   BRANCH SATISFACTION
         LW,D3    R5
         LW,R10   *R6,R7            CRITERIA WORD IN NEW ELEMENT
TQCHAINC2 EQU     %
         CS,R10   *D1,R7            COMPARE WITH CRITERIA WORD OF
*                                   CHAINED ELEMENT
         EXU      R8                EXECUTE CONDITIONAL BRANCH
         LS,D1    *D1               NOT SATISFIED, CHECK NEXT
*                                   ELEMENT ON THE CHAIN
         BEZ      TQCHAINC4         REACHED END OF THE CHAIN
         LS,D3    *D3               KEEP TRACK OF THIS ELEMENT
         B        TQCHAINC2         TEST NEXT ELEMENT
*
TQCHAINC4 EQU     %
*                                   END OF CHAIN, NO MATCH
*                                   CHAIN ELEMENT TO TAIL OF CHAIN
         LS,D1    *D3               D1 = ADDRESS OF LINK WORD OF
*                                   PREVIOUSTAIL
         STW,R6   *D1               ADD NEW ELEMENT TO TAIL
         STS,R9   *D1               CSET CHAINED BIT,PREVIOUS TAIL
         STW,R9   *R6               LINK=0,SET CHAINED
         STW,R6   1,R5              NEW ELEMENT TO CHAIN TAIL
         B        TQCHAINYES        SUCCESSFUL RETURN
*
TQCHAINC6 EQU     %
         LW,R7    CSTMBR            MATCH FOUND,CHAIN NEW ELEMENT
*                                   PRECEDING THE MATCH
         STS,R6   *D3
         STW,D1   *R6               SET LINK IN NEW ELEMENT
         STS,R9   *R6               SET CHAINED BIT
         B        TQCHAINYES        SUCCESSFUL RETURN
         TITLE    'TQDCHAIN..DECHAIN ELEMENT FROM TOP OF CHAIN'
*DO*
*D*
***************************************************************
*                                                             *
*                 NAME:  TQDCHAIN                             *
*                                                             *
*                 DECHAINS ENTRIES FROM THE TOP OF A          *
*                 STANDARD FORWARD CHAIN...                   *
*                                                             *
*                 CALL:                                       *
*                                                             *
*                 ENTERED VIA   BAL,R0  TQDCHAIN              *
*                                                             *
*                 INPUT: R5 = ADDRESS OF CHAIN HEADER         *
*                        R5, BIT 0 = 0, DECHAIN REAL          *
*                                  = 1, DECHAIN VIRTUAL       *
*                                                             *
*                 OUTPUT: R9 = ADDRESS OF DECHAINED ELEMENT'S *
*                                   LINK WORD                 *
*                         CC 4 = 0, SUCCESSFUL DECHAINING     *
*                              = 1, UNSUCCESSFUL DECHAIN      *
*                                                             *
***************************************************************
*
*
*        DESCRIPTION:  TQDCHAIN OPERATES ON A STANDARD FORWARD CHAIN.
*                 SEE TQCHAIN FOR THE DESCRIPTION OF THE CHAIN
*                 FORMAT.
*
*                 TQDCHAIN DECHAINS THE ENTRY FROM THE HEAD OF THE
*                 CHAIN, STORES ITS FORWARD POINTER AS THE NEW HEAD
*                 OF THE CHAIN, AND IF IT WAS THE ONLY ELEMENT ON THE
*                 CHAIN, ZEROS THE TAIL OF THE CHAIN AS WELL.
*
*                 BIT 0 OF THE LINK WORD IN THE ELEMENT JUST DECHAINED
*                 IS SET TO 0 TO INDICATE THAT IT IS NO LONGER ON
*                 ANY CHAIN.
*
*                 IF THE CHAIN IS EMPTY, THE CONDITION CODES ARE
*                 SET TO INDICATE UNSUCCESSFUL DECHAINING.
*
*FIN*
*
TQDCHAIN EQU      %
         PUSH     2,R0
         BAL,R0   TQDCHAINCOM       FRONT END LOGIC
         LW,R9    0,R5              GET CHAIN HEADER
         LS,D1    *R9               TEST IF ONLY ONE ENTRY CHAINED
         BNEZ     TQDCHAIN2         NO
         STW,D1   1,R5              YES, ZERO TAIL IN HEADER
TQDCHAIN2 EQU     %
         STW,D1   0,R5              STORE EITHER ZERO OR ADDRESS
*                                   OF 2ND ELEMENT AS NEW HEAD
         B        TQDCHAINA8
*
*
TQDCHAINCOM EQU   %                 COMMON DECHAINING LOGIC
         PUSH     4,D1
         LW,D1    J:JIT
         CI,R5    0                 TEST FOR DECHAINING REAL OR VIRTUAL
         BGE      TQDCHAINR         DECHAINING IN REAL
         BAL,R1   TQMAP
         B        TQDCHAINCOM2
TQDCHAINR EQU     %
         BAL,R1   TQUNMAP
TQDCHAINCOM2 EQU  %
         LW,R1    D1
         AND,R5   CSTMBR
         LW,D2    CSTMBR
         LW,D1    0,R5              CHECK FOR AN EMPTY CHAIN
         BEZ      TQCHAINNO         YES, UNSUCCESSFUL EXIT
         B        *R0
         TITLE    'TQDCHAINA...DECHAIN SPECIFIED ELEMENT'
*DO*
*D*
**************************************************************
*                                                            *
*                 NAME:  TQDCHAINA                           *
*                                                            *
*                 DECHAINS SPECIFIED ELEMENT FROM A          *
*                 STANDARD FORWARD CHAIN                     *
*                                                            *
*                 CALL:                                      *
*                                                            *
*                 ENTERED VIA   BAL,R0 TQDCHAINA             *
*                                                            *
*                 INPUT: R5 = ADDRESS OF CHAIN HEADER        *
*                        R5, BIT 0 = 0, DECHAIN REAL         *
*                                  = 1. DECHAIN VIRTUAL      *
*                        R9 = ADDRESS OF LINK WORD OF ELEMENT*
*                                   TO DECHAIN               *
*                                                            *
*                 OUTPUT: CC 4 = 0, SUCCESSFUL  DECHAINING   *
*                              = 1, UNSUCCESSFUL DECHAINING  *
*                                   R9, BYTE 0 MODIFIED      *
*                                      BYTE 1-3 UNCHANGED    *
*                                                            *
**************************************************************
*
*        DESCRIPTION:  THE CHAIN IS SEARCHED FOR THE ELEMENT
*                 SPECIFIED BY R9.  IF FOUND, ITS LINK IS STORED
*                 INTO THE LINK WORD OF THE ELEMENT WHICH WAS
*                 POINTING TO IT (OR INTO THE CHAIN HEADER).  IF
*                 THIS WAS THE ONLY ELEMENT ON THE CHAIN, THE TAIL
*                 IS ZEROED.
*
*                 IF THE SPECIFIED ELEMENT IS NOT FOUND, THE
*                 CONDITION CODES ARE SET TO INDICATE UNSUCCESSFUL
*                 DECHAINING.
*
*FIN*
*
TQDCHAINA EQU     %
         PUSH     2,R0
         BAL,R0   TQDCHAINCOM       COMMON DECHAINING LOGIC
         LW,D3    R5                CHAIN HEADER
TQDCHAINA2 EQU    %
         CW,D1    R9                COMPARE WITH LINK TO DECHAIN
         BE       TQDCHAINA4        FOUND
         LW,D3    D1                KEEP ELEMENT POINTING TO ONE
*                                   UNDER TEST
         LS,D1    *D1               GET TO NEXT ELEMENT ON THE CHAIN
         BNEZ     TQDCHAINA2        SEE IF THIS IS THE ONE
*                                   REACHED END OF THE CHAIN
         B        TQCHAINNO            UNSUCCESSFUL EXIT
TQDCHAINA4 EQU    %
         LS,D1    *D1               GET LINK FROM MATCHING ELEMENT
         STS,D1   *D3               STORE AS NEW LINK TO REMOVE
*                                   THIS ELEMENT FROM THE CHAIN OR
*                                   AS NEW HEAD IN THE HEADER
         BNEZ     TQDCHAINA8        TEST FOR ELEMENT WAS TAIL OF CHAIN
         CW,D3    R5                YES, WAS IT THE ONLY ENTRY
         BNE      TQDCHAINA6        NO, IF BRANCH
         STW,D1   1,R5              YES, ZERO TAIL IN HEADER
         B        TQDCHAINA8
TQDCHAINA6 EQU    %
         STW,D3   1,R5              STORE PRECEDING ENTRY AS NEW TAIL OF CHAIN
TQDCHAINA8 EQU    %
         STW,D1   *R9               RESET CHAINED BIT IN DECHAINED ELEMENT
         B        TQCHAINYES
         TITLE    'TQDCHAINC...DECHAINING WITH CRITERIA'
*DO*
*D*
**************************************************************
*                                                            *
*                 NAME:  TQDCHAINC                           *
*                                                            *
*                 DECHAIN ENTRIES BASED ON CRITERIA FROM     *
*                 A STANDARD FORWARD CHAIN...                *
*                                                            *
*                 CALL:                                      *
*                                                            *
*                 ENTERED VIA  BAL,R0  TQDCHAINC             *
*                                                            *
*                 INPUT: R2= -1,SEARCH FOR LINK WITHOUT      *
*                            DECHAINING                      *
*                        R5 = ADDRESS OF CHAIN HEADER        *
*                        R7 = DISPLACEMENT OF CRITERIA FROM  *
*                                   LINK WORD                *
*                        R8 = BRANCH INSTRUCTION             *
*                              (WITH THE ADDRESS = 0)        *
*                        R10 = CRITERIA                      *
*                        R11 = CRITERIA MASK                 *
*                        R5, BIT 0 = 0, DECHAIN REAL         *
*                                  = 1, DECHAIN VIRTUAL      *
*                                                            *
*                 OUTPUT: R9 = ADDRESS OF DECHAINED LINK     *
*                         CC 4 = 0, SUCCESSFUL DECHAINING    *
*                              = 1, UNSUCCESSFUL DECHAINING  *
*                                                            *
**************************************************************
*
*FIN*
         PAGE
*DO*
*D*
*        DESCRIPTION:  TQDCHAINC COMPARES THE CRITERIA WORD
*                 SPECIFIED BY THE CALLER (IN R10) WITH THE
*                 CORRESPONDING WORD IN EACH ELEMENT ON THE CHAIN.
*                 IF THE BRANCH CONDITION GIVEN BY THE USER IS
*                 SATISFIED, AND DECHAINING IS SPECIFIED, THE
*                 ELEMENT IS DECHAINED AS PREVIOUSLY DESCRIBED.
*                 IF ONLY A SEARCH WAS REQUESTED, THE ELEMENT
*                 REMAINS ON THE CHAIN.
*
*                 THE ADDRESS OF THE REQUESTED LINK IS RETURNED IN
*                 R9, OR IF THE REQUIRED ELEMENT IS NOT FOUND, THE
*                 CONDITION CODES ARE SET TO INDICATE UNSUCCESSFUL
*                 DECHAINING.
*
*FIN*
*
TQDCHAINC EQU     %
         PUSH     2,R0
         BAL,R0   TQDCHAINCOM       COMMON DECHAINING LOGIC
         LW,D3    R5                ADDRESS OF CHAIN HEADER
         LW,D4    CSTMBR
         AI,R8    TQDCHAINC6        COMPLETE SATISFIED BRANCH INSTRUCTION
TQDCHAINC2 EQU    %
         CS,R10   *D1,R7            COMPARE FOR MATCH TEST
         EXU      R8
         LS,D1    *D1               NO, KEEP LOOKING
         BEZ      TQCHAINNO         REACHED END OF CHAIN
         LS,D3    *D3               KEEP TRACK OF PRECEDING ELEMENT
         B        TQDCHAINC2        CHECK NEXT ENTRY
TQDCHAINC6 EQU    %
         LW,R9    D1                ADD OF ENTRY LINKED TO MATCHING ONE
         CI,R2    -1                CHECK FOR SEARCHING ONLY
         BE       TQCHAINYES        YES, EXIT WITH LINK POINTER
         LW,D1    *D1               LINK WORD IN ELEMENT DECHAINING
         STS,D1   *D3               LINK FORWARD ELEMENT TO PRECEDING
*                                   ELEMENT TO CLOSE THE CHAIN
         AND,D1   CSTMBR            RESET CHAINED BIT
         BNEZ     TQDCHAINA8        BRANCH IF NOT LAST ELEMENT CHAINED
         CW,D3    R5                IS IT AT THE HEAD OF THE CHAIN
         BNE      TQDCHAINA6        BRANCH IF NOT
         STW,D1   1,R5              ZERO TAIL OF HEADER
         B        TQDCHAINA8
         TITLE    'QUEUE I/O END-ACTION AND MISCELLANEOUS FCNS'
         PAGE
*****************************************************************
*D*
*D*      NAME:    TQUEUEA, QUEUE I/O END ACTION
*D*
*D*      CALL:    THE ADDRESS OF THIS ROUTINE IS PASSED TO NEWQ
*D*               FOR ENTRY AT END ACTION.
*D*
*D*      INPUT:   R14 = END ACTION INFORMATION (IN THIS CASE THE
*D*                     USER NUMBER OF THE USER FOR WHOM QUEUE I/O
*D*                     HAS BEEN DONE).
*D*
*D*               R12 = TYC OF THE I/O JUST COMPLETED.
*D*
*D*      DESCRIPTION:  THIS ROUTINE RE-AWAKENS THE QUEUE USER WHO
*D*               IS WAITING FOR I/O TO BE COMPLETED.
*D*
*****************************************************************
TQUEUEA  EQU      %
         PUSH     SR4               SAVE RETURN
         LW,R5    D3                EAI = USER NUMBER
         LB,R2    D1                TYC
         ST,R2    Q:CC              INTO TTP TABLE
         LI,R6    E:UQA             RE-AWAKEN USER
         BAL,SR4  T:RUE
         PULL     SR4
         B        *SR4
*
*S*********************************************************
*S*      SCREECH CODE: 34           CALLED FROM TQNEWQ
*S*      MESSAGE: TRANSACTION PROCESSING FAILURE
*S*
*S*      REMARKS: A TP FAILURE FROM TQIOREJECT CAN ONLY
*S*               OCCUR ON THE 'DEVICE MARKED DOWN' RETURN
*S*               FROM NEWQ (IN IOQ). TP CANNOT CONTINUE IF
*S*               IT CAN NO LONGER ACCESS THE DEVICE CONTAINING
*S*               THE QUEUE FILE.
*S*********************************************************
*
TQIOREJECT EQU    %
*                                   PROVIDE FOR UNIMPLEMENTED DEV DOWN
         SCREECH  QSCREECH
         PAGE
*D*
*D*      NAME:    TQMOVEBSZ, ZERO A BYTE STRING IN REAL MEMORY
*D*
*D*      CALL:    ENTERED VIA  BAL,R0   TQMOVEBSZ
*D*
*D*      INPUT:   R1 = BYTE COUNT AND REAL BYTE ADDRESS OF DESTINATION
*D*
*D*      OUTPUT:  R1 = RESULT OF MBS,0
*D*
*D*      DESCRIPTION:  THIS ROUTINE GOES UNMAPPED THEN EXECUTES
*D*               THE MOVE BYTE STRING OF ZEROS.  THE RETURN TO
*D*               THE USER IS MAPPED.
*D*
TQMOVEBSZ EQU     %                 SET BYTE  STRING TO ZERO
         LW,SR4   R1
         UNMAP
         LW,R1    SR4
         MBS,0    BA(X0)
         LW,SR4   R1
         MAP
         LW,R1    SR4
         B        *R0
         PAGE
*D*
*D*      NAME:    TQSETBLOCK, UPDATE CONTROL BLOCK STATISTICS
*D*
*D*      CALL:    ENTERED VIA  BAL,R0   TQSETBLOCK
*D*
*D*      INPUT:   R4 = 1, INCREMENT THE SPECIFIED ITEM
*D*                  = 2, DECREMENT THE SPECIFIED ITEM
*D*
*D*               CONDITION CODES SPECIFY THE DESIRED ITEM
*D*                  = 0, THE NUMBER OF ENTRIES QUEUED
*D*                  = 1, THE NUMBER OF ENTRIES IN-PROGRESS
*D*                  = 2, THE NUMBER OF ENTRIES MARKED FAILED
*D*                  = 3, THE NUMBER OF INDEX BLOCKS IN USE
*D*
*D*      DESCRIPTION:  THE QUEUE CONTROL BLOCK IS UPDATED AS
*D*               DETERMINED FROM THE CONDITION CODES AND R4
*D*               SETTING.  IF THE CALL IS TO INCREMENT THE NUMBER
*D*               OF ENTRIES QUEUED, A CHECK IS MADE TO DETERMINE
*D*               IF THIS IS THE HIGHEST NUMBER QUEUED SO FAR.  IF
*D*               SO, THE MAXIMUM ENTRY COUNTER AND ASSOCIATED TIME
*D*               OF DAY ARE UPDATED.  THE HIGHEST TID QUEUED IS
*D*               UPDATED IF NECESSARY, AND THE ROUTINE EXITS.
*D*
TQSETBLOCK EQU    %                 MAINTAIN STATS IN CONTROL BLOCK 1
         STCF     R0
         PUSH     16,R0
         LW,R6    Q:CONT(A)         PTR TO CONTROL BLOCK 1
         UNMAP
         LB,R7    R0
         SLS,R7   -4
         EXU      TQSETBLOCKE,R7
         LW,SR1   *R6,R5
         CI,R4    1
         BANZ     TQSETBLOCK2
         AI,SR1   -1
         B        TQSETBLOCK4
TQSETBLOCK2 EQU   %
         AI,SR1   1
TQSETBLOCK4 EQU   %
         STW,SR1  *R6,R5
         CI,R7    0
         BNE      TQSETBLOCKEXIT
         L,R1     CONTSATINC,R6     SATURATION INCREMENT
         LI,R5    CONTSAT(I)
         LW,SR2   *R6,R5
         CI,R4    1
         BANZ     TQSETBLOCK5
         SW,SR2   R1
         B        TQSETBLOCK5A
TQSETBLOCK5 EQU   %
         AW,SR2   R1
TQSETBLOCK5A EQU  %
         STW,SR2  *R6,R5
         LI,5     CONTMAX(I)        UPDATE MAX ENTRIES
         LW,SR4   *R6,R5
         CW,SR1   SR4
         BL       TQSETBLOCK7
         STW,SR1  *R6,R5
**********GET TIME OF DAY
         MAP
         PUSH     R6
         PUSH     SR3
         PUSH     8,SR1             FORMAT STACK FOR TIM OUTPUT
         LI,R6    0                 4-WD BLK NOT NEEDED
         LI,R7    SR1               ADDRESS OF FPT WD 1
         OR,R7    Y008              TUN FLAG
         DO       QSIM=0
         OVERLAY  MISOVSEG,MTIME#
         FIN
         PULL     8,SR1             RESTORE STACK, SR1 & SR2 = TIME
*                                   FOR QUEUE PURPOSES
         PULL     SR3               TID
         PULL     R6
         UNMAP
         LI,R5    CONTMAXTIME(I)
         STW,SR1  *R6,R5
         AI,R5    1
         STW,SR2  *R6,R5
TQSETBLOCK7 EQU   %
         LI,R5    CONTTID(I)
         LW,SR1   *R6,R5
         LI,SR2   -1
         CS,SR1   SR3
         BGE      TQSETBLOCKEXIT
         STW,SR3  *R6,R5
TQSETBLOCKEXIT EQU %
         LW,SR1   QWRITEF(M)
         LW,SR2   SR1
         LI,R5    QWRITEF(I)
         STS,SR1  *R6,R5
TQROOTEXIT EQU    %
         MAP
         PULL     16,R0
         B        *R0
TQSETBLOCKE EQU   %
         LI,R5    CONTENTRIES(I)
         LI,R5    CONTPROC(I)
         LI,R5    CONTFAILED(I)
         LI,R5    CONTINDEXES(I)
         SPACE    3
         PAGE
*D*
*D*      NAME:    TQNEWQ, PERFORM UNMAPPED I/O THROUGH NEWQ
*D*
*D*      CALL:    ENTERED VIA  BAL,R6   TQNEWQ
*D*
*D*      INPUT:   R0 = END ACTION ADDRESS (TQUEUEA)
*D*               R1 = END ACTION INFORMATION (CURRENT USER NUMBER)
*D*               R12 = FUNCTION CODE, PRIORITY, # RETRIES, DCT INDEX
*D*               R13 = REAL BYTE ADDRESS OF THE QUEUE PAGE
*D*               R14 = BYTE COUNT (2048)
*D*               R15 = QUEUE DISK ADDRESS (GENERALIZED FORMAT)
*D*
*D*      DESCRIPTION:  THIS ROUTINE GOES UNMAPPED THEN CALLS NEWQ
*D*               (IN IOQ) TO ISSUE THE I/O REQUEST.  A DEVICE
*D*               DOWN RETURN FROM NEWQ GIVES A SOFTWARE CHECK 34-00.
*D*               ON THE NORMAL RETURN, THE ROUTINE GOES MAPPED AND
*D*               EXITS.
*D*
TQNEWQ   EQU      %
         LW,R5    R1                SAVE EAI
         UNMAP                      UNMAPPED I/O
         LW,R1    R5
         BAL,SR4  NEWQ
         B        TQIOREJECT
         MAP
         B        *R6
         PAGE
*D*
*D*      NAME:    TQHSKPICB, INITIALIZE AN INDEX CONTROL BLOCK ENTRY
*D*
*D*      CALL:    ENTERED VIA  BAL,R0   TQHSKPICB
*D*
*D*      INPUT:   SR2 = BLOCK NUMBER OF THE EMPTIED INDEX BLOCK
*D*               R7 = MPOOL BUFFER ADDRESS
*D*
*D*      DESCRIPTION:  THE INDEX CONTROL BLOCK (ICB) IS SEARCHED
*D*               FOR THE GIVEN BLOCK NUMBER.  IF IT IS NOT FOUND,
*D*               THE INDEX BLOCK IS ASSUMED NOT TO BE AT THE HEAD
*D*               OF THE CHAIN OF INDEX BLOCKS FOR ANY PARTICULAR
*D*               HASH ENTRY AND THE ROUTINE EXITS.  IF THE BLOCK
*D*               NUMBER IS FOUND, ITS ENTRY IS UPDATED TO THE
*D*               FLINK (FORWARD LINK) OF THAT BLOCK.  (ZERO IF
*D*               NO OTHER BLOCKS ARE ON THIS CHAIN, OR THE NEW
*D*               HEAD OF BLOCKS ON THIS CHAIN)
*D*
TQHSKPICB EQU     %
         PUSH     16,R0             HSKP INDEX CONTROL BLOCK
         UNMAP
         LI,R2    QICBENTS          # ENTRIES IN ICB
         LI,R5    ICBHASH(I)
         L,R6     Q:INXCONTROL
TQHICB1  EQU      %
         LW,R3    *R6,R5
         CW,R3    SR2               SR2= BLOCK # NEWLY EMPTIED BLOCK
         BNE      TQHICB4
         LW,R3    QPOOLFLINKI(I),R7 BLOCK'S FORWARD LINK
         STW,R3   *R6,R5
         B        TQSETBLOCKEXIT    SET WRITE REQUIRED AND EXIT
TQHICB4  EQU      %
         AI,R5    1                 STEP TO NEXT ENTRY
         BDR,R2   TQHICB1
         B        TQROOTEXIT        RELEASED BLOCK NOT CHAIN HEADER
         PAGE
*D*
*D*      NAME:    T:GETID, GET THE NEXT AVAILABLE TRANSACTION ID
*D*
*D*      CALL:    ENTERED FROM ALTCP VIA  BAL,SR4   T:GETID
*D*
*D*      OUTPUT:  THE CURRENT TRANSACTION ID IS PLACED IN THE
*D*               USER REGISTER SR1 (IN TSTACK).
*D*
*D*               CONDITION CODES = 0, VALID TRANSACTION ID
*D*                               = 8, INVALID TRANSACTION ID
*D*
*D*      DESCRIPTION:  WITH THE INTERRUPTS INHIBITED, THE CURRENT
*D*               TID IS LOADED AND INCREMENTED IF NON-ZERO.
*D*               THE INTERRUPTS ARE THEN ENABLED AND THE TID
*D*               IS PLACED IN THE USER REGISTER SR1.  THE USERS
*D*               CONDITION CODES ARE SET TO ZERO IF THE TID IS
*D*               VALID, OR NON-ZERO IF THE TID IS INVALID.  AN
*D*               INVALID TID (I. E. ZERO TID) INDICATES THAT THE
*D*               QUEUE IS NOT OPEN FOR PROCESSING.
*D*
T:GETID  EQU      %
         DISABLE
         LWORD,R3 Q:TID
*                                   R3= NEXT TRAN ID
         BEZ      TGETIDZ           IF IT IS VALID (NON-ZERO),
         MTWORD,1 Q:TID             INCREMENT IT.
TGETIDZ  EQU      %
         ENABLE
         LW,R2    TSTACK            RETURN ID OR ZERO
         STW,R3   -15+SR1,R2        TO CALLER'S SR1.
         AI,R3    0                 IF TID VALID,
         BNEZ     CC1RST            RETURN WITH CC1=0,
         B        CC1SET            ELSE WITH CC1 = 1.
         PAGE
*                                   REAL MEMORY ACCESSING LOGIC
*D*
*D*      NAME:    TQGETBYTE, GET BYTE FROM REAL PAGE
*D*
*D*      CALL:    ENTERED VIA  BAL,R0  TQGETBYTE
*D*                            BAL,R0  TQGETHWORD
*D*                            BAL,R0  TQGETWORD
*D*                            BAL,R0  TQGETFIELD
*D*                            BAL,R0  TQLOADF
*D*
*D*      ENTRY:   TQGETHWORD, GET HALFWORD FROM REAL PAGE
*D*
*D*      ENTRY:   TQGETWORD, GET WORD FROM REAL PAGE
*D*
*D*      ENTRY:   TQGETFIELD, GET FIELD FROM REAL PAGE
*D*
*D*      ENTRY:   TQLOADF, GET ADDRESS (24-BITS) FROM REAL PAGE
*D*
*D*      INPUT:   R5 = INDEX VALUE OF ITEM TO GET
*D*               R6 = BASE ADDRESS (REAL)
*D*               D4 = MASK FOR LOAD SELECTIVE (TQGETFIELD)
*D*
*D*      OUTPUT:  D4 = LOADED VALUE
*D*               D3 = LOADED VALUE AFTER LOAD SELECTIVE (TQGETFIELD)
*D*                                                      (TQLOADF)
*D*               D4 = M24 AFTER TQLOADF
*D*
*D*               CONDITION CODES: RESULT OF NORMAL LOAD INSTRUCTIONS
*D*
*D*      DESCRIPTION:  PERFORMS AN UNMAPPED LB, LH, LW, OR LS
*D*               INSTRUCTION WITH THE ADDRESS *R6,R5
*D*
         PAGE
*D*      NAME:    TQSETBYTE, STORE BYTE INTO REAL PAGE
*D*
*D*      CALL:    ENTERED VIA  BAL,R0  TQSETBYTE
*D*                            BAL,R0  TQSETHWORD
*D*                            BAL,R0  TQSETWORD
*D*                            BAL,R0  TQSETFIELD
*D*                            BAL,R0  TQSTOREF
*D*
*D*      ENTRY:   TQSETHWORD, STORE HALFWORD INTO REAL PAGE
*D*
*D*      ENTRY:   TQSETWORD, STORE WORD INTO REAL PAGE
*D*
*D*      ENTRY:   TQSETFIELD, STORE FIELD INTO REAL PAGE
*D*
*D*      ENTRY:   TQSTOREF, STORE ADDRESS (24-BITS) INTO REAL PAGE
*D*
*D*      INPUT:   R5 = INDEX VALUE OF ITEM TO STORE
*D*               R6 = BASE ADDRESS (REAL)
*D*               D3 = VALUE TO BE STORED
*D*               D4 = MASK FOR STORE SELECTIVE (TQSETFIELD)
*D*
*D*      DESCRIPTION:  PERFORMS AN UNMAPPED STB, STH, STW, OR STS
*D*               INSTRUCTION WITH THE ADDRESS *R6,R5
*D*
*D*      NOTES:   FOR TQGETFIELD, THE MASK IN D4 MUST BE POSITIONED
*D*               PROPERLY FOR THE BITS DESIRED.
*D*
*D*               FOR TQSETFIELD, BOTH THE MASK AND THE ITEM (IN D3
*D*               AND D4) MUST BE POSITIONED PROPERLY TO THE BITS
*D*               DESIRED.
*D*
*D*               FOR TQLOADF AND TQSTOREF, THE MASK (M24) IS LOADED
*D*               IN THE ROUTINE ITSELF.
*D*
         PAGE
TQGETBYTE EQU     %
         UNMAP
         LB,D4    *R6,R5
         B        TQSET#GET
TQSETBYTE EQU     %
         UNMAP
         STB,D3   *R6,R5
         B        TQSET#GET1
TQSETHWORD EQU    %
         UNMAP
         STH,D3   *R6,R5
         B        TQSET#GET1
TQGETHWORD EQU    %
         UNMAP
         LH,D4    *R6,R5
         B        TQSET#GET
TQGETWORD EQU     %
         UNMAP
         LW,D4    *R6,R5
         B        TQSET#GET
TQSETWORD EQU     %
         UNMAP
         STW,D3   *R6,R5
         B        TQSET#GET1
TQLOADF  EQU      %
         LW,D4    CSTMAP
         B        TQGETFIELD
TQSTOREF EQU      %
         LW,D4    CSTMAP
         B        TQSETFIELD
TQGETFIELD EQU    %
         UNMAP
         LI,D3    0
         LS,D3    *R6,R5
         B        TQSET#GET
         PAGE
TQSETFIELD EQU    %
         UNMAP
         STS,D3   *R6,R5
         B        TQSET#GET1
*D*
*D*      NAME:    TQMOVEBS, MOVE BYTE STRINGS IN REAL PAGES
*D*
*D*      CALL:    ENTERED VIA   BAL,R0  TQMOVEBS
*D*                             BAL,R0  TQCBYTE
*D*
*D*      ENTRY:   TQCBYTE, COMPARE BYTE STRINGS IN REAL PAGES
*D*
*D*      INPUT:   D3 = REAL BYTE ADDRESS OF SOURCE BYTE STRING
*D*               D4 = COUNT, REAL BYTE ADDRESS OF DESTINATION
*D*
*D*      OUTPUT:  D3 AND D4 = RESULT OF NORMAL MBS OR CBS INSTRUCTION
*D*               CONDITION CODES: RESULT OF NORMAL MBS OR CBS
*D*
*D*      DESCRIPTION:  PERFORMS AN UNMAPPED MBS,D3 0 OR CBS,D3 0
*D*               AND RETURNS TO THE USER WITH RESULTS OF THE
*D*               INSTRUCTION.
*D*
TQMOVEBS EQU      %
         UNMAP
         MBS,D3   0
         B        TQSET#GET
TQCBYTE  EQU      %
         UNMAP
         CBS,D3   0
TQSET#GET EQU     %
         STCF     R0
TQSET#GET1 EQU    %
         MAP
         LC       R0
         B        *R0
         PAGE
*D*
*D*      NAME:    TQCHKBIT1, INITIALIZE AND CHECK FPT PARAMETER
*D*
*D*      CALL:    ENTERED VIA  BAL,R2  TQCHKBIT1
*D*                            BAL,R2  TQCHKBIT
*D*
*D*      ENTRY:   TQCHKBIT, CHECK NEXT FPT PARAMETER
*D*
*D*
*D*      INPUT:   R7 = ADDRESS OF WORD 1 OF THE FPT
*D*               R1 = CURRENT INDEX INTO FPT (TQCHKBIT)
*D*               D1 = WORD 1 OF FPT POSITIONED TO LAST TESTED
*D*                    PARAMETER (TQCHKBIT)
*D*
*D*      OUTPUT:  R1 = INDEX TO NEXT FPT PARAMETER
*D*               D1 = FPT WORD 1 POSITIONED TO LAST TESTED PARAMETER
*D*               D3 = THE PARAMETER FROM THE FPT IF PRESENT
*D*
*D*      DESCRIPTION:  IF THE PARAMETER PRESENCE FLAG IS OFF, THE
*D*               ROUTINE EXITS TO THE CALLER AT CALL+1.  IF THE
*D*               FLAG IS ON, THE PARAMETER IS SELECTED FROM THE FPT
*D*               WITH INDIRECT ADDRESSING APPLIED AS NECESSARY,
*D*               AND THE ROUTINE RETURNS TO THE CALLER AT CALL+2.
*D*               IN EITHER CASE, EXIT REGISTERS ALLOW SUBSEQUENT
*D*               CALLS TO THE ROUTINE FOR THE NEXT PARAMETER
*D*               PRESENCE TEST.
*D*
TQCHKBIT1 EQU     %                 GET OPTIONAL FPT PARAMETERS
*                 ENTERED VIA  BAL,R2  TQCHKBIT1,TQCHKBIT
*                 VOLATILE REGISTERS: R1,D1,D3
         LW,D1    0,R7
         LI,R1    X'80001'
TQCHKBIT EQU      %
         SLS,D1   1
         BEV      0,R2              NOT PRESENT , RETURN IN LINE
         LW,D3    *R7,R1            GET PARAMETER
         BGEZ     TQCHKBIT2
         CI,D3    X'1FFF0'          INDIRECT, CHECK FOR REGISTER
         BANZ     %+2               NO
         AW,D3    J:BASE            TSTACK REGISTER ADDRESS
         LW,D3    *D3
TQCHKBIT2 EQU     %
         BIR,R1   1,R2              RETURN TO CALL+2
         END

