*M* ECBPOST POST COMPLETION OF AN EVENT IN AN EVENT CONTROL BLOCK.
         DEF      ECBPOST:          XDELTA LABEL FOR ECBPOST MODULE.
ECBPOST: EQU      %
*
*P*      NAME:    ECBPOST
*P*
*P*      PURPOSE: TO 'POST' AN EVENT CONTROL BLOCK; I.E., TO RECORD
*P*               THE COMPLETION OF AN EVENT, PLUS ITS COMPLETION
*P*               STATUS, IN A TWO-WORD EVENT CONTROL BLOCK IN SOME
*P*               (NOT NECESSARILY THE CURRENT) USER'S SPACE.
*P*
*P*  DESCRIPTION: ECBPOST POSTS THE EVENT CONTROL BLOCK IN ONE OF
*P*               THREE WAYS --
*P*               1.  IF THERE IS AN ENTRY ON THE USER'S WAIT-LIST
*P*                 FOR THE ECB, IT IS MARKED POSTED ON THE WAITLIST;
*P*                 THE USER IS AWAKENED IF IN AN ECBCHECK-INITIATED
*P*                 SLEEP STATE & ENOUGH ECBS HAVE BEEN POSTED NOW.
*P*               2.  IF THE USER IS READY-TO-RUN, THE ECB IS POSTED
*P*                 DIRECTLY IN THE USER'S CORE.
*P*               3.  OTHERWISE, A DO-LIST ENTRY IS MADE FOR LATER
*P*                 POSTING BY ANOTHER ECBPOST ENTRY POINT.
*P*
UFLAGS   SET      1                 GET DEFINITIONS OF UH:FLG BITS.
BITS     SET      1                 GET DEFINITIONS OF XN,YN,MN.
         SYSTEM   UTS
         PCC      0
         PAGE
         DEF      ECBPOST     ENTRY WHEN USER HAS NO 4-WORD BLOCK.
         DEF      ECBPOST1    ENTRY WHEN USER SUPPLIES 4-WD BLOCK.
         DEF      T:ECBSTORE  ENTRY FROM SCHEDULER (DEFERRED POST).
*
         REF      E:WU        = SCHEDULER EVENT TO WAKE UP USER.
         REF      ECBGBLK     ROUTINE GETS A FOUR-WORD BLOCK.
         REF      J:JIT       INPUT WORD 0 =0 MEANS UNMAPPED NOW.
         REF      JCMAP       INPUT USER'S MAP IN JIT.
         REF      JJAC        INPUT USER'S ACCESS PROT IN JIT.
         REF      J:JAC       INPUT ACCESS PROTECTION FOR CURR USER.
         REF      JOVVPA      = WA OF FIRST PAGE IN USER MAP.
         REF      NPMC        <= THIS IN MAP MEANS NOT USER'S PAGE.
         REF      NB31TO0     MASKS
         REF      SW          = SCHEDULER STATE (ASLEEP).
         REF      T:DOLISTR   ROUTINE RETURN FROM DEFERRED POST.
         REF      T:RUE       ROUTINE TO REPURT EVENT ON A USER.
         REF      U:MISC      BITS 0-7 INPUT NUMBER OF ECBS WAITED ON
*,*                               OUTPUT DECREMENTED IF ECB ON UH:WL.
         REF      UB:US       INPUT CURRENT STATE OF USER
         REF      UH:DL       OUTPUT POST-LATER BLOCK CHAINED ON IT.
         REF      UH:FLG      INPUT RTR BIT TESTED.
         REF      UH:WL       INPUT CHAIN OF WAITED-ON ECBS.
         REF      UX:JIT      INPUT PAGE# OF JIT IF NOT CURRENT USER.
         PAGE
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
*
*        TABLE SYMBOLS FOR ECB
*
ECBP     EQU      BT31TO0+32
ECBW     EQU      BT31TO0+31
NECBW    EQU      NB31TO0+31
ECBI     EQU      BT31TO0+30
NECBI    EQU      NB31TO0+30
WECB     EQU      0
ECBCC    EQU      1
*
*        TABLE SYMBOLS FOR WAIT LIST/DO LIST ECB BLOCK
*
ECBBLINK EQU      0
ECBBADDR EQU      1
ECBBP    EQU      ECBP
WECBB    EQU      2
ECBBMULT EQU      10
ECBBC    EQU      BT31TO0+28
ECBBCC   EQU      3
ECBBLENG EQU      4
ECBBECB  EQU      1
         PAGE
*F*      NAME:    ECBPOST
*F*      PURPOSE: ECBPOST POSTS COMPLETION OF AN EVENT CONTROL BLOCK
*F*               FOR A USER.
*F*  DESCRIPTION: (SEE ECBPOST MODULE DESCRIPTION).
*F*               IF DO-LIST POSTING IS NECESSARY AND NO BLOCKS ARE
*F*               AVAILABLE, THE CALLER IS NOTIFIED AND MUST RESUBMIT
*F*               THE POST REQUEST.
*F*
*F*      NAME:    ECBPOST1
*F*      PURPOSE: ECBPOST1 POSTS COMPLETION OF AN EVENT CONTROL BLOCK
*F*               FOR A USER.  THE CALLER OF ECBPOST1 ALSO SUPPLIES
*F*               A FOUR-WORD BLOCK, TO ENSURE SUCCESSFUL POSTING
*F*               IN ALL CASES.
*F*  DESCRIPTION: (SEE ECBPOST MODULE DESCRIPTION).
*F*
*D*      NAME:    ECBPOST
*D*      ENTRY:   ECBPOST1
*D*      REGISTERS: R7 FOUR-WORD BLOCK ADDRESS (ECBPOST1 ONLY)
*D*                    (PRESERVED)
*D*                 R8 USER NUMBER OF USER OWNING ECB (PRESERVED)
*D*                 R9 COMPLETION CODE VALUE (PRESERVED).
*D*                R10 VIRTUAL ADDRESS OF ECB IN.
*D*                    OUT: ZERO IF SUCCESS, ONE IF FAILURE.
*D*                R11 LINK (PRESERVED).
*D*               ALL OTHER REGISTERS PRESERVED.
*D*      CALL:    BAL,R11 ECBPOST
*D*      INTERFACE: CALLS ECBGBLK, T:RUE, MAP, UNMAP.
*D*      ENVIRONMENT: MASTER MAPPED OR UNMAPPED.
*D*               IF CALLED UNMAPPED, MAY BE REAL-EXTENDED ON EXIT
*D*               EVEN IF NOT ON ENTRY.
*D*               RETURNS ENABLED.
*D*      INPUT:   UH:WL => CHAIN OF 4-WD BLOCKS FOR WAITED-ON ECBS.
*D*               UB:US = CURRENT SCHEDULER STATE OF USER.
*D*               U:MISC = # OF ECBS WAITED ON.
*D*      OUTPUT:  UH:WL BLOCK MAY BE UPDATED.
*D*               UB:US MAY BE CHANGED FROM SW.
*D*               U:MISC MAY BE DECREMENTED.
*D*               UH:DL MAY HAVE A POST-LATER ENTRY ADDED.
*D*               R10=>ECB MAY HAVE BEEN CHANGED IN USER MEMORY.
*D*               R10 CHANGED TO REFLECT SUCCESS OR FAILURE.
*D*               4-WORD BLOCK MAY HAVE BEEN GOTTEN.
*D*               CC SET ZERO FOR SUCCESS,
*D*                   NONZERO FOR NEEDED 4-WD BLOCK & COULDNT GET.
*D*  DESCRIPTION: ECBPOST LOOKS FOR THE ECB ON UH:WL (WAITED-ON).
*D*               IF FOUND, IT IS MARKED 'POSTED' IN THE WAIT-LIST
*D*               BLOCK FOR LATER POSTING BY ECBCHECK. THE USER'S
*D*               U:MISC IS DECREMENTED BY THE MULTIPLICITY OF THE
*D*               ECB AS SPECIFIED IN THE FOUR-WORD BLOCK.
*D*               IF IT GOES TO ZERO, THE USER IS AWAKENED.
*D*               IF NOT ON UH:WL AND THE USER IS READY-TO-RUN, THE
*D*               ECB IS FOUND BY GOING THRU THE USER'S MAP IN THE
*D*               JIT AND IS POSTED IF ITS ACCESS IS 00.
*D*               IF THE USER IS NOT READY-TO-RUN, A FOUR-WORD BLOCK
*D*               IS GOTTEN IF NECESSARY AND PLACED ON UH:DL CHAIN
*D*               FOR LATER POSTING.
*D*                (IF NO BLOCK CAN BE GOTTEN, THE CALLER IS TOLD)
*D*
ECBPOST  EQU      %
         PUSH     7,R1              SAVE R1-R7
         LI,R7    0                 MUST ALLOCATE BLOCK
         B        ECBP003
ECBPOST1 EQU      %
         PUSH     7,R1              SAVE R1-R7
ECBP003  LW,R6    R8                R6= USER NUMBER OWNING ECB.
         AND,R10  M17               R10= ECB ADDRESS WITHOUT GARBAGE.
         LH,R1    UH:WL,R6
         BEZ      ECBP040           ---> USER HAS NO ACTIVE WAITLIST.
         LW,R4    R10               R4/R5= ECB ADDRESS AND
         LW,R5    M24                      MASK FOR SELECTIVE COMPARE
ECBP010  SLS,R1   +1                R1= WA(WAITLIST BLOCK.
         CS,R4    ECBBADDR,R1       IS THIS OUR ECB ON WL...
         BE       ECBP300           ---> YES. POST ON WAITLIST.
         LW,R1    ECBBLINK,R1       NO.
         AND,R1   M16               IF MORE WAITLIST,
         BNEZ     ECBP010           ---> TRY AGAIN.
ECBP040  LH,R2    UH:FLG,R6         NOW LOOK FOR USER IN CORE.
         CI,R2    RTR               IS USER IN CORE...
         BANZ     ECBP200           ---> YES. POST IN CORE.
*        B                          NO. MUST POST ON DOLIST.
         PAGE
         LW,R2    R7                DID USER SUPPLY BLOCK...
         BNEZ     ECBP060           ---> YES.
         BAL,R1   ECBGBLK           NO. TRY TO GET ONE.
         BEZ      ECBP910           ---> CANT GET. ERROR #1.
ECBP060  EQU      %
         STW,R10  ECBBADDR,R2       PUT ECB ADDR IN BLOCK.
         STW,R9   ECBBCC,R2         PUT COMPLETION CODE IN TOO.
         LI,R4    ECBBECB           'POST-AN-ECB' TYPE BLOCK.
ECBP100  EQU      %                 ** PUT A BLOCK ON DOLIST.
         SLS,R4   +16               GET BLOCK TYPE ALIGNED.
         LW,R5    L(X'FF7FFFFF')    PRESERVE NOT-TO-RLS FLAG.
         STS,R4   ECBBLINK,R2       PRIO=0,,,FLINK=0.
         DISABLE
         LH,R4    UH:DL,R6          GET USER'S DOLIST HEAD.
         LI,R5    X'FFF'
         STS,R4   0,R2              THIS ONE GOES TO HEAD.
         SLS,R2   -1                (DOUBLEWORD ADDR CHAINING)
         LS,R4    R2
         STH,R4   UH:DL,R6
         ENABLE
ECBP900  BAL,R10  ECBP950           **  NO-ERROR RETURN. R10=0
ECBP910  BAL,R10  ECBP950           *** ERROR #1 RETURN. R10=1
ECBP950  PULL     7,R1              RESTORE USER REGISTERS.
         AI,R10   -ECBP910          SET R10 AND CC.
         B        *R11              RETURN TO USER.
         PAGE
*A*      WE ASSUME HERE (NOT NECESSARILY OBVIOUSLY) THAT
*A*        HAVING FOUND THAT A USER IS READY-TO-RUN, THEN AS
*A*        LONG AS WE REMAIN IN MASTER MODE AND DO NOT VOLUN-
*A*        TARILY SURRENDER CONTROL, IT IS TRUE THAT:
*A*      1.  NOBODY ELSE WILL MAKE THE USER NOT READY-TO-RUN.
*A*      2.  THE USER'S MAP AND ACCESS PROTECTION IN THE JIT WILL
*A*          NOT BE CHANGED BY ANYBODY ELSE.
*A*      3.  IF A PAGE HAS 'ALL-ACCESS' PROTECTION AND IS NOT
*A*          FPMC OR NPMC IN THE USER'S JIT MAP, THEN THE CORRE-
*A*          SPONDING PHYSICAL PAGE IS SAFE TO STORE INTO.
*A*      AND WE ASSUME THIS IS TRUE EVEN IF WE INTERRUPTED THE USER.
*
ECBP200  EQU      %                 ** POST ECB IN CORE.
         LW,R2    J:JIT             R2 = 0 IF WE WERE UNMAPPED.
         UNMAP                        GO UNMAPPED. (& EXTENDED-ADDR)
         LW,R1    R2                R1 = 0 IF WE WERE UNMAPPED.
         LW,R3    R10               R3= VWA(ECB WORD 0)
         SCS,R3   -9                R3(0-8)=PAGEDISP, (24-31)=PAGE#
         LW,R5    R10
         AI,R5    +1                R5= VWA(ECB WORD 1)
         AND,R5   M17                 (INCASE ECBADDR=1FFFF)
         CI,R5    JOVVPA            IS ADDRESS BELOW USER...
         BLE      ECBP270           ---> YES. BAD NEWS.
         SLS,R5   -9                R5= PAGE# OF WORD ! OF ECB.
         LOAD,R10 UX:JIT,R6
         SLS,R10  +9                R10= REAL WA(USER'S JIT)
         AI,R10   JCMAP             R10= REAL WA(USER'S MAP)
         LOAD,R4  *R10,R5           R4= REAL PAGE#(ECB WORD 1)
ECBP220  LOAD,R2  *R10,R5           R2= REAL PAGE#(ECB WORD 1 THEN 0)
         CI,R2    NPMC              DOES USER HAVE THIS PAGE TRULY...
         BLE      ECBP270           ---> NO.
         LI,R6    3
         AND,R6   R5                R6=DISPL OF PAGE IN J:JAC BYTE
         LB,R6    L(X'C0300C03'),R6 R6= MASK FOR THIS DISPLACEMENT.
         SCS,R5   -2                R5= BYTE# IN J:JAC
         AI,R10   JJAC-JCMAP        R10= REAL WA(USER'S J:JAC)
         CB,R6    *R10,R5           IS PAGE ALL-ACCESS...
         BANZ     ECBP270           ---> NO.
         SCS,R5   +2                RESTORE PAGE#.
         AI,R10   JCMAP-JJAC        RESTORE R10.
         CS,R5    R3                NEED WE CHECK ANOTHER PAGE...
         BE       ECBP240           ---> NO.
         BDR,R5   ECBP220           ---> YES.
*
ECBP240  LW,R5    R3                R5(0-8)=PAGEDISP OF WORD0.
         AW,R5    Y008              R5(0-8)=PAGEDISP OF WORD1.
         SLD,R2   +9                R2= REAL WA(ECB WORD 0).
         SLD,R4   +9                R4= REAL WA(ECB WORD 1).
         LW,R6    0,2+2*WECB        GET ECB FLAG WORD.
         OR,R6    ECBP              SET 'POSTED'.
         AND,R6   NECBI             CLEAR 'INITIALIZED'.
         STW,R6   0,2+2*WECB        PUT IT BACK.
         STW,R9   0,2+2*ECBCC       STORE USER-GIVEN COMP. CODE.
ECBP270  AI,R1    0
         BEZ      %+2               GO BACK MAPPED IF WE WERE MAPPED..
         MAP
         LW,R6    R8                R6= USER NUMBER AGAIN.
         B        ECBP400           ---> FREE USER BLOCK IF ANY.
         PAGE
ECBP300  EQU      %                 ** POST ECB ON WAITLIST.
         LW,R2    WECBB,R1          GET WAITLIST BLOCK FLAGWORD.
         OR,R2    ECBBP             SAY TO POST ECB.
         STW,R2   WECBB,R1          PUT IT BACK.
         STW,R9   ECBBCC,R1         SAVE USER-SUPPLIED POST CODE.
         CW,R2    ECBBC             IS M:CHECKECB NOW HAPPENING...
         BANZ     ECBP400           ---> YES. IT'LL FIX UP.
         LI,R3    ECBBMULT          NO. WE MUST WAKE UP USER MAYBE.
         LB,R3    *R1,R3            GET WAIT-COUNT OF THIS ECB.
         BEZ      ECBP400           ---> IF NONE, DON'T.
         DISABLE                    (( TRUBBLES IF TWO POSTS ))
         LB,R2    UB:US,R6          WAKE HIM UP.
         CI,R2    SW                BUT NOT IF HE ISN'T ASLEEP.
         BNE      ECBP400
         LW,R5    R6                R5= USER NUMBER FOR T:RUE.
         AI,R5    U:MISC            R5= WA(USER'S U:MISC)
         MTB,-1   *R5               REDUCE WAITING COUNT
         BEZ      %+3                 ==> GO IF ZERO
         BDR,R3   %-2               BY POSTEE'S WAITCOUNT.
         B        ECBP400           ---> STILL WAITING.
         LW,R5    R6
         LI,R6    E:WU
         PUSH     10,R7             SAVE REST OF REGS.
         BAL,R11  T:RUE             WAKE UP USER.
         PULL     10,R7             RESTORE REST OF REGS.
         LW,R6    R8                R6= USER NUMBER AGAIN.
ECBP400  EQU      %                 ** FREE USER-GIVEN BLOCK.
         ENABLE
         LW,R2    R7                DID USER SUPPLY BLOCK...
         BEZ      ECBP900           ---> NO. ALL DONE.
         LI,R4    7                 'SPECIAL-ACTION' TYPE BLOCK
         LI,R3    T:DOLISTR         AND ROUTINE FOR IT IS
         STW,R3   1,R2              JUST THE BLOCK-FREER.
         B        ECBP100           ---> GO CHAIN TO USER'S DOLIST.
         PAGE
*F*      NAME:    T:ECBSTORE
*F*      PURPOSE: T:ECBSTORE POSTS AN EVENT CONTROL BLOCK FOR THE
*F*               CURRENT USER.  IT IS CALLED AS A DO-LIST ROUTINE.
*F*  DESCRIPTION: T:ECBSTORE IS SUPPLIED THE VIRTUAL ADDRESS OF AN
*F*               ECB AND A COMPLETION CODE FOR IT IN A FOUR-WORD
*F*               BLOCK. IF THE ADDRESS IS IN USER ALL-ACCESS SPACE,
*F*               THE ECB IS MARKED 'POSTED' AND THE COMPLETION CODE
*F*               IS STORED INTO THE ECB.
*F*
*D*      NAME:    T:ECBSTORE
*D*      REGISTERS: R4 USER NUMBER (PRESERVED).
*D*                 R5 DA(FOUR-WORD BLOCK) (PRESERVED).
*D*                 R6/R7 FIRST DOUBLEWORD OF BLOCK (DESTROYED).
*D*                ALL OTHER REGISTERS VOLATILE.
*D*      CALL:    B T:ECBSTORE  (MUST RETURN TO T:DOLISTR)
*D*      ENVIRONMENT: MASTER MAPPED.
*D*               INTERRUPT INHIBITS PRESERVED.
*D*      INPUT:   R5 = DA(FOUR-WORD BLOCK).
*D*               R7 = WORD 1 OF BLOCK (VIRTUAL ADDRESS OF ECB).
*D*               BLOCK WORD 3 (COMPLETION CODE TO BE STORED).
*D*               J:JAC ACCESS PROTECTION FOR USER.
*D*      OUTPUT:  ECB WORD 0 IS SET 'POSTED', UNSET 'INIT','WAITING'.
*D*               ECB WORD 1 CONTAINS COMPLETION CODE.
T:ECBSTORE EQU    %
         LW,R6    R7                SAVE VWA OF ECB IN R6.
         AI,R7    1                 INCR TO SECOND WORD OF ECB.
         AND,R7   MASKS+17          DISCARD HIGH-ORDER GARBAGE.
         CI,R7    JOVVPA            IS ECB IN USER'S SPPACE...
         BLE      T:DOLISTR         ---> NO. DON'T BOTHER TO POST.
T:ECBS10 SLS,R7   -9                R7= PAGE# OF ECB.
         LI,R3    3
         AND,R3   R7                R3= ACCESS BYTE INDEX.
         LB,R3    L(X'C0300C03'),R3 R3= MASK FOR TESTING ACCESS.
         SCS,R7   -2                R7= ACCESS BYTE NUMBER.
         CB,R3    J:JAC,R7          IS THIS PAGE ALL-ACCESS...
         BANZ     T:DOLISTR         ---> NO. DON'T POST ECB.
         SCS,R7   +11                 GET R7 BACK AGAIN.
         CS,R7    R6                DOES ECB CROSS PAGE BOUND...
         BE       T:ECBS20          ---> NO.
         BDR,R7   T:ECBS10          ---> YES. TEST OTHER PAGE.
T:ECBS20 LD,R8    2,R5              ECB OK. GET COMPLETION CODE
         STW,R9   ECBCC,R6          AND PUT INTO ECB.
         LW,R8    WECB,R6           GET FLAG WORD OF ECB.
         AND,R8   NECBW             RESET 'WAITING'
         AND,R8   NECBI              AND  'INITIALIZED'
         OR,R8    ECBP              AND SET 'POSTED'.
         STW,R8   WECB,R6
         B        T:DOLISTR
         END

