MONPROC  SET      1
         SYSTEM   UTS
         LOCAL    HSC
BUFF:    RES
         DEF      BUFF:             PATCHING DEF
         PCC      0
*M*      BUFF     GET AND RELEASE MPOOL AND CPOOL BUFFERS
*P*
*P*      NAME:    BUFF
*P*      PURPOSE: TO OBTAIN AND RELEASE MONITOR AND SYMBIONT
*P*               BUFFERS.
*P*      DESCRIPTION:  THE BUFFERS ARE MAINTAINED IN THREADED
*P*               LISTS AND ARE OBTAINED AND RETURNED TO THE
*P*               HEAD OF THE LIST.
         PAGE
*                 SYMBOLIC 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
SR1      EQU      8
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
         PAGE
         REF      SCBPOOLIM
         REF      BUFLIMS
         REF      MPOOLIM
         REF      M17
         REF      MPOOL,CPOOL
         SREF     C:MPOOL
         DEF      GSC               GET SYMBIONT CONTEXT BUFFER
         DEF      GMB               GET MONITOR BUFFER
         DEF      RSC               RELEASE SYMBIONT CONTEXT BUFFER
         DEF      RMB               RELEASE MONITOR BUFFER
*F*      NAME:    GSC
*F*      PURPOSE: TO OBTAIN A SYMBIONT CONTEXT BUFFER.
*F*      DESCRIPTION:  THE BUFFER AT THE HEAD OF THE CPOOL CHAIN
*F*               IS UNLINKED AND ITS ADDRESS RETURNED IN R14.
GSC      LI,R2    CPOOL             HEAD OF SYMB CONTEXT BUFFER POOL
         LI,1     SCBPOOLIM         SYMB BUFR LIMIT
         B        GB00              CONTINUE
*F*      NAME:    GMB
*F*      PURPOSE: TO OBTAIN A MONITOR BUFFER.
*F*      DESCRIPTION:  THE BUFFER AT THE HEAD OF THE MPOOL CHAIN
*F*               IS UNLINKED AND ITS ADDRESS RETURNED IN R14.
GMB      LI,R2    MPOOL             HEAD OF MONITOR BUFFER POOL
         LI,1     MPOOLIM           INDEX TO MPOOL LIMITS
GB00     DISABLE                    DISABLE INTERRUPTS TO BREAK
*                                   BUFFER CHAIN
         LW,D3    0,R2              AVAILABLE BUFFER ADDRESS
         AND,D3   M17
         BEZ      GB01              NONE AVAILABLE
         CLM,14   BUFLIMS,1         CHECK FOR LEGAL BUFFER ADDRESS
         BCR,9    GB05C
*S*      SCREECH CODE: 19
*S*      REPORTED BY:  BUFF,IOQ
*S*      MESSAGE:  INVALID BUFFER ADDRESS PASSED FOR RELEASE.
*S*      REGISTERS: IF CALLED FROM BUFF:
*S*               2=ADDRESS OF BUFFER CHAIN HEAD.
*S*               11=LINK REGISTER
*S*               14=BUFFER ADDRESS
*S*               IF CALLED FROM CHAINCHK IN IOQ;
*S*               4,5=MPOOL BUFFER ADDRESS
*S*               9=LINK REGISTER FOR CHAINCHK
*S*               IF CALLED FROM REQCOM IN IOQ;
*S*               6,14=MPOOL BUFFER ADDRESS
*S*      REMARKS: AS YOU CAN SEE THIS SCREECH CAN OCCUR IN
*S*               BUFF OR IN IOQ.  EXAMINE THE REGISTERS TO
*S*               DETERMINE WHICH.
SC1900   EQU      %                 SOFTWARE CHECK 19-00 MAY
         DEF      SC1900            BE CALLED FROM IOQ
GB05     SCREECH  X'19'
GB05C    EQU      %
         LW,R0    *D3               NEXT AVAIL BUFFER
         STW,R0   0,R2              TO AVAIL BUFFER
         CI,2     MPOOL
         BNE      %+2
         MTW,1    C:MPOOL           COUNT MPOOL USAGE FOR STATS
GB01     ENABLE                     ENABLE INTERRUPTS
         AI,D3    0
         B        *SR4              EXIT
         PAGE
*F*      NAME:    RSC
*F*      PURPOSE: TO RETURN A SYMBIONT CONTEXT BUFFER.
*F*      DESCRIPTION:  THE BUFFER ADDRESS IN R14 IS ATTACHED TO
*F*               THE HEAD OF THE CPOOL CHAIN.
RSC      LI,R2    CPOOL             HEAD OF SYMB CONTEXT BUFFER POOL
         LI,1     SCBPOOLIM
         B        RB00              CONTINUE
*F*      NAME:    RMB
*F*      PURPOSE: TO RETURN A MONITOR BUFFER.
*F*      DESCRIPTION:  THE BUFFER ADDRESS IN R14 IS ATTACHED TO
*F*               THE HEAD OF THE MPOOL CHAIN.
RMB      LI,R2    MPOOL             MONITOR BUFFER POOL HEAD
         LI,1     MPOOLIM
RB00     EQU      %
         AND,14   M17
         CLM,14   BUFLIMS,1         CHECK LEGALITY OF BUFFER
*                                   BEING RELEASED
         BCR,9    %+2
         BCS,9    GB05              BRANCH IF ILLEGAL
         DISABLE
*                                   BUFFER CHAIN
         CI,2     MPOOL
         BNE      %+2
         MTW,-1   C:MPOOL           COUNT MPOOL USAGE FOR STATS
         LW,R0    0,R2              NEXT AVAIL BUFFER
         STW,D3   0,R2              RELEASE BUFFER
         STW,R0   *D3               CHAIN RELEASED TO NEXT AVAIL BUFFER
         B        ENBSR4            ENABLE & EXIT
         REF      ENBSR4
         END

