*M* ECBINIT INITIALIZE A SYSTEM-CONTROLLED EVENT CONTROL BLOCK (ECB)
         DEF      ECBINIT:          XDELTA LABEL FOR ECBINIT MODULE.
ECBINIT: EQU      %
*
*P*      NAME:    ECBINIT
*P*      PURPOSE: TO SET UP INITIAL CONDITIONS IN A TWO-WORD
*P*               EVENT CONTROL BLOCK FOR THE CURRENT USER.
*P*  DESCRIPTION: ECBINIT INITIALIZES AN EVENT CONTROL BLOCK BY --
*P*               SETTING THE ECBI BIT IN WORD 0 ('INITIALIZED')
*P*               CLEARING THE ECBP BIT  ('NOT POSTED')
*P*               CLEARING THE ECBW BIT  ('NOT BEING WAITED ON')
*P*               STORING A CALLER-SUPPLIED INITIAL COMPLETION
*P*                 CODE INTO WORD 1 OF THE ECB.
*P*               AN ERROR RETURN IS MADE IF THE ECB IS NOT IN THE
*P*               USER'S ALL-ACCESS SPACE.
*
         SYSTEM   UTS
         PCC      0
*
*
*
         DEF      ECBINIT     ENTRY TO INITIALIZE AN ECB
*
         REF      BT31TO0     MASKS
         REF      J:JAC       INPUT ACCESS PROTECTION OF USER'S PAGES
         REF      JOVVPA      = WA OF FIRST PAGE IN USER MAP.
         REF      M17         MASK
         REF      NB31TO0     MASKS
         PAGE
*
*        TABLE SYMBOLS FOR ECB
*
ECBP     EQU      BT31TO0+32
ECBW     EQU      BT31TO0+31
ECBI     EQU      BT31TO0+30
NECBW    EQU      NB31TO0+31
NECBP    EQU      NB31TO0+32
WECB     EQU      0
ECBCC    EQU      1
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
*D*      NAME:    ECBINIT
*D*
*D*      REGISTERS: R9 COMPLETION CODE INIT VALUE (PRESERVED).
*D*                R10 INPUT VIRTUAL ADDRESS OF ECB.
*D*                    OUTPUT ZERO (OKAY) OR TYPE OF FAILURE.
*D*                R11 LINK REGISTER (PRESERVED).
*D*               ALL OTHER REGISTERS PRESERVED.
*D*      CALL:    BAL,R11 ECBINIT
*D*      ENVIRONMENT: MASTER MAPPED.
*D*               RETURNS ENABLED.
*D*      INPUT:   R10 VIRTUAL ADDRESS OF ECB.
*D*               J:JAC ACCESS-PROTECTION OF USER VIRTUAL PAGES.
*D*      OUTPUT:  R10 = 0 OKAY.
*D*                   NOT ZERO, ERROR CODE FOR ECB ADDRESS BAD.
*D*
ECBINIT  EQU      %
         PUSH     2,R6              PRESERVE WORKING REGISTERS.
         LW,R7    R10               GET ECB ADDRESS.
         AI,R7    +1                GET TO SECOND WORD.
         AND,R7   M17               GET ECB ADDRESS ONLY.
         CI,R7    JOVVPA            IS IT BELOW USER AREA...
         BLE      ECBI930           ---> YES.  ERROR #3.
1I30     SLS,R7   -9                R7= VIRTUAL PAGE #.
         LI,R6    3
         AND,R6   R7                R6= DISPL IN AC BYTE.
         LB,R6    L(X'C0300C03'),R6   = AC MASK.
         SCS,R7   -2                R7= AC BYTE INDEX.
         CB,R6    J:JAC,R7          IS THIS PAGE (00) ACCESS...
         BANZ     ECBI930           ---> NO.  ERROR #3.
         SCS,R7   +11               R7= WA(PAGE) AGAIN.
         CS,R7    R10               SAME PAGE AS WORD 0 OF ECB...
         BE       1I40              ---> YES. ECB ALL IN (00).
         BDR,R7   1I30              ---> NO. CHECK OTHER PAGE TOO.
*
1I40     LW,R7    R10               R7= ECB ADDRESS AGAIN.
         DISABLE
         LW,R6    WECB,R7           R6= ECB FLAG WORD.
         OR,R6    ECBI               SET  'ECB IS INITIALIZED'.
         AND,R6   NECBP             CLEAR 'ECB HAS BEEN POSTED'.
         AND,R6   NECBW             CLEAR 'ECB IS ON WAITLIST'.
         STW,R6   WECB,R7           AND STORE IT BACK.
         STW,R9   ECBCC,R7          SET INITIAL COMP CODE INTO ECB.
         ENABLE
         LI,R10   0                 *** NO-ERROR RETURN. R10=0.
*
ECBI100  PULL     2,R6              RESTORE WORKING REGISTERS.
         B        *R11              ---> RETURN TO CALLER.
*
*E*      ERROR:   4A-05.
*E*      MESSAGE: EVENT CONTROL BLOCK IS IN PROTECTED MEMORY.
*E*      DESCRIPTION: AN EVENT CONTROL BLOCK IS NOT IN USER'S
*E*               ALL-ACCESS SPACE.
ECBI930  LW,R10   L(X'0A00004A')    *** ERROR RETURN. R10= ERROR.
         B        ECBI100
         END

