         TITLE    'ECBINIT - EVENT CONTROL BLOCK INITIALIZATION'
         PCC      0
         REF      MASKS
MONPROC  SET      1
         SYSTEM   UTS
         DEF      ECBINIT
         REF      J:JAC
         REF      J:DCBLINK
         REF      JOVVP
         REF      S:CUN
         REF      UB:NECB
         REF      M2
         REF      M17
         PAGE
NOACCESS EQU      3
*
*        TABLE SYMBOLS FOR ECB
*
ECBP     EQU      BT31TO0+32
ECBW     EQU      BT31TO0+31
ECBI     EQU      BT31TO0+30
ECBU     EQU      BT31TO0+29
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
***********************************************************************
*                                                                     *
*        ECBINIT                                                      *
*          -INITIALIZE A SYSTEM-CONTROLLED EVENT CONTROL BLOCK (ECB)  *
*                                                                     *
*        ENTRY POINT                                                  *
*          ECBINIT                                                    *
*                                                                     *
*        INPUT                                                        *
*          R11 - RETURN ADDRESS                                       *
*          R10 - VIRTUAL ADDRESS OF ECB                               *
*          R9  - COMPLETION CODE INITIALIZATION VALUE                 *
*                                                                     *
*        OUTPUT                                                       *
*          R10 - ZERO, INITIALIZATION COMPLETE                        *
*                ONE,  ECBI ALREADY SET                               *
*                TWO,  ECBW SET                                       *
*                THREE,ERRONEOUS ADDRESS OF ECB                       *
*          CC  - INDICATE WHETHER R10 IS ZERO OR NON-ZERO             *
*                                                                     *
*        REGISTER USAGE                                               *
*          R10 ALTERED, ALL OTHERS PRESERVED                          *
*                                                                     *
***********************************************************************
         SPACE    2
ECBINIT  EQU      %
         PUSH     3,R1              SAVE R1-R3
         LI,R1    0                 POINT TO FIRST WORD OF ECB
         AND,R10  MASKS+17          REMOVE EXTRANEOUS BITS
ECBI010  EQU      %
         LI,R2    0                 CLEAR R2
         LW,R3    R10               FETCH VIRTUAL ADDRESS OF ECB
         AW,R3    R1                BUMP TO ADDRESS TO CHECK
         SLS,R3   -9                ROUND ADDRESS TO RELATIVE VIRT. PAGE
         CI,R3    JOVVP             IS ADDRESS IN RESIDENT MONITOR
         BL       ECBI090           YES, DON'T ACCEPT
         SCD,R2   -4                DIVIDE BY 16 WITH REMAINDER IN R2
         SCS,R2   5                 DOUBLE AND RIGHT JUSTIFY REMAINDER
         LW,R3    J:JAC,R3          FETCH ACCESS WORD REFERENCING PAGE
         SLD,R2   2,R2              EXTRACT ACCESS CODE
         AND,R2   M2                  FOR PAGE IN QUESTION
         BEZ      ECBI030           ACCESS ZERO, OK
         B        ECBI090           ACCESS CODE NON-ZERO, ERROR
ECBI030  EQU      %
         CI,R1    1                 CHECKED BOTH ECB WORDS
         BE       ECBI040           YES
         LI,R1    1                 NO, GO CHECK
         B        ECBI010             SECOND WORD
ECBI040  EQU      %
         LW,R1    R10
         LW,R2    ECBW              IS ECB WAITING
         AND,R2   WECB,R1
         BNEZ     ECBI092           YES, ERROR
         DISABLE
         LW,R2    ECBI              HAS ECB BEEN INITIALIZED
         AND,R2   WECB,R1
         BNEZ     ECBI094           YES, ERROR
         LW,R2    ECBI              SET INITIALIZATION BIT
         OR,R2    WECB,R1
         STW,R2   WECB,R1
         ENABLE
         LW,R2    NECBP             RESET POST BIT
         AND,R2   WECB,R1
         STW,R2   WECB,R1
         STW,R9   ECBCC,R1          STORE INITIALIZATION COMPLETION CODE
         LW,R2    ECBU              IS IT USER ECB
         AND,R2   WECB,R1
         BNEZ     ECBI045           YES
         LW,R1    S:CUN             ADD ONE TO NUMBER OF
         MTB,1    UB:NECB,R1          OUTSTANDING SYSTEM ECBS
ECBI045  EQU      %
         LI,R10   0                 INDICATE INITIALIZATION COMPLETE
         B        ECBI098           RETURN
ECBI090  EQU      %
         LI,R10   3                 INDICATE ECB ADDRESS ERROR
         B        ECBI098
ECBI092  EQU      %
         LI,R10   2                 INDICATE ECB ALREADY WAITING
         B        ECBI098
ECBI094  EQU      %
         ENABLE
         LI,R10   1                 INDICATE ECB ALREADY INITIALIZED
ECBI098  EQU      %
         PULL     3,R1              RESTORE REGS
         AI,R10   0                 SET CONDITION CODES WRT R10
         B        *R11              RETURN
         PAGE
         END

