         PCC      0                                                             
         SYSTEM   SIG9P                                                         
         SYSTEM   OPTIONS                                                       
*                                                                               
*        OVERLAY MADE UP OF MISC ECB AND TASK MANAGEMENT SUBS                   
*                 OF THE HIGHEST UTILIZATION                                    
*                                                                               
*        TMTYC15S,TMTYC15,TMTYC,TMTYCB.TMTYCS                                   
*        TMCKADR,TMVADR                                                         
*        TMCKADP                                                                
*        EMGETECB                                                               
*        EMGETFPT                                                               
*        EMWAIT                                                                 
*        CKENACT,CKENACTS,CKENACT1,CKENACT2,CKINTLAB,CKINTADR                   
         DEF      A:TMTYC                                                       
         DEF      TMTYCS,TMTYCB,TMTYC15,TMTYC15S                                
         DEF      TMVADR,TMCKADR,TMGRA                                          
         DEF      TMCKADP                                                       
         DO       #ECB                                                          
         DEF      EMGETECB,EMGETEM                                              
         DEF      EMGETFPT                                                      
         FIN      #ECB                                                          
         DEF      EMWAIT                                                        
         DEF      CKENACTS,CKENACT,CKENACT1,CKENACT2,;                          
                  CKINTLAB,CKINTADR                                             
         DEF      1ETMX8,1ETMXR5,1ETMXR4,1ETMXR4E                               
OLAYFLAG EQU      'TMTY'                                                        
         SYSTEM   CPRMON                                                        
         SPACE    2                                                             
1ETMX8   B        *R8                                                           
1ETMXR5  B        0,R5                                                          
1ETMXR4  B        1,R4                                                          
1ETMXR4E B        0,R4                                                          
         TITLE    '** TMTYC - TASK AND ECB MANAGEMNET SUBROUTINES **'           
         TITLE    '** TMTYC - STORE COMPLETION STATUS IN FPT **'                
******************                                                              
*    TMTYC       *       SUBROUTINES TO STORE P10 COMPLETION STATUS IN          
*    TMTYC15     *            FPT                                               
******************                                                              
* ENTRY: R3       FPT ADDRESS, BOTH ENTRY POINTS                                
*        BAL,R8   TMTYCB            SET BUSY (R9=TYCWBUSY)                      
*        -OR-                                                                   
*        R9       COMPLETION WORD                                               
*        BAL,R8   TMTYC                                                         
*        BAL,R8   TMTYCS            FOR STANDARD FPT'S                          
*        - OR-                                                                  
*        R15      TYC                                                           
*        BAL,R8   TMTYC15                                                       
*        BAL,R8   TMTYC15S          FOR STANDARD FPT'S                          
* EXIT:  +1                                                                     
* REGISTERS USED: R0,R5,R8,R9,R14,R15 IF ERROR                                  
*           SAVED: R1-R7,R10-R13,R15 IF NO ERROR                                
* STACK WORDS: 2                                                                
* SUBROUTINES: GETFPTN                                                          
*                                                                               
TMTYCB   LW,R9    TYCWBUSY          SET COMPL WORD TO BUSY                      
TMTYCS   LW,R0    0,R3              CHECK P0                                    
         CW,R0    XFPTP0                                                        
         BAZ      1ETMX8                NO TYC, EXIT                            
         B        TMTYC                 STORE COMPL WORD                        
TMTYC15S LW,R0    0,R3              STANDARD FPT ENTRY, CHECK                   
         CW,R0    XFPTP0                FOR EXTENDED FPT                        
         BAZ      1ETMX8                NO, EXIT                                
TMTYC15  LI,R9    0                 SETUP R9=TYC IN BYTE 0                      
         STB,R15  R9                                                            
TMTYC    RES      0                                                             
A:TMTYC  EQU      TMTYC                                                         
         LB,R5    TCBPOINT          GET CALLERS TASK ID                         
         LW,R0    STITCB,R5         DO NOT POST TO FPT IF TASK                  
         CW,R0    XSTIT             IN TERMINATION                              
         BANZ     1ETMX8                                                        
         LI,R15   FPTTYC            GET ADDRESS OF P10                          
         BAL,R5   GETFPTN                                                       
         B        TMTYC1                NO P10                                  
         XW,R9    R14                   VALIDATE THE ADDRESS                    
         LW,R5    R8                    SAVE EXIT                               
         BAL,R8   TMVADR                GOOD?                                   
         B        TMTYC2                NO, DO TRAP '50'                        
         CI,R0    0                     WRITABLE?                               
         BNE      TMTYC2                NO                                      
         STW,R14  *R9                   STORE TYC                               
*                                                                               
         LB,R15   R14               RESTORE TYC                                 
         B        1ETMXR5           EXIT                                        
TMTYC2   LI,R15   TYCTRAP           SET TYPE COMPL TO BADCAL                    
         B        1ETMXR5           EXIT                                        
TMTYC1   LB,R15   R9                RESTORE TYC                                 
         B        1ETMX8            EXIT                                        
         TITLE    '** TMTYC - VALIDATE AN ADDRESS **'                           
******************                                                              
*    TMCKADR     *       SUBROUTINE TO CHECK AN ADDRESS. OPTIONALLY             
*    TMVADR      *          CONVERTS THE ADDRESS TO REAL.                       
******************                                                              
*                                                                               
* ENTRY  R9       ADDRESS TO TEST                                               
*        BAL,R8   TMCKADR           CONVERTS TO REAL IF VIRTUAL                 
*  -OR-  BAL,R8   TMVADR            NO CONVERSION                               
* EXIT:  +1       ERROR, R15= TYC   X'8B'                                       
*        +2       ADDRESS IS GOOD, R0 =ACCESS CODE (CC3&CC4=LRA) BYTE 0         
*                                  R9 =REAL ADDRESS                             
*                                                                               
* REGISTERS USED:  R0,R9,R15    IF ERRORS                                       
*           SAVED: R1-R8,R10-R14, R15 IF NO ERRORS                              
*                                                                               
* STACK WORDS: 1                                                                
*                                                                               
* SUBROUTINES: TMGRA                                                            
*                                                                               
TMVADR   RES      0                 VERIFY ADDRESS, DONT CONVERT                
         PUSH     R8                                                            
         BAL,R8   TMGRA             GET REAL ADDRESS                            
         PULL     R8                                                            
         B        TMCKAD2           BRANCH TO ANALYZE RESULTS                   
*                                                                               
TMCKADR  RES      0                 VERIFY AND CONVERT ADDRESS                  
         PUSH     R8                                                            
         BAL,R8   TMGRA             GET REAL ADDRESS                            
         PULL     R8                                                            
         LW,R9    R0                                                            
         AND,R9   M24               GET CONVERTED ADDRESS IN R9                 
*                                                                               
TMCKAD2  CI,R9    16                                                            
         BL       TMCKAD12          ERROR IF REGISTER                           
         BIFRBM   TMCKAD3                                                       
         BIFMU    TMCKAD3                                                       
         LCF      R0                                                            
         BCR,1    TMCKAD11          B IF NOT NO-ACCESS                          
         BCR,2    TMCKAD11          B IF NOT NO-ACCESS                          
         B        TMCKAD12          B TO SET NO-ACCESS ERROR CODE               
TMCKAD3  LCF      R0                                                            
         BCR,1    TMCKAD10          B IF NOT NO-ACCESS                          
         BCR,2    TMCKAD10          B IF NOT NO-ACCESS                          
         B        TMCKAD13          B TO SET SYSER CODE                         
*                                                                               
TMCKAD10 LI,R0    0                 FORCE TO ALL-ACCESS                         
TMCKAD11 AND,R0   Y3                TRIM UNNEEDED BITS                          
         AI,R8    1                 SKIP RETURN                                 
         B        1ETMX8                                                        
*                                                                               
TMCKAD12 CI,R15   TYC8B                                                         
         BG       1ETMX8            B IF ALREADY MORE SERIOUS ERROR             
         LI,R15   TYC8B             SET ACCESS PROTECTION ERROR                 
         B        1ETMX8                                                        
TMCKAD13 LI,R15   TYCSYSER          SET SYSER.  MONITOR IS                      
         B        1ETMX8            NOT ALLOWED TO MAKE THIS MISTAKE.           
         TITLE    '** TMTYC - GET REAL ADDRESS **'                              
******************                                                              
*    TMGRA       *                  SUBROUTINE TO GET REAL ADDRESS              
******************                  AND ACCESS PROTECTION CODE                  
*                                                                               
* ENTRY: R9 = ADDRESS TO CONVERT                                                
*        BAL,R8   TMGRA                                                         
*                                                                               
* EXIT:  R0 BYTE 0 = ACCESS CODE AS FROM LRA INSTRUCTION                        
*        R0 BYTES 1-3 = CONVERTED ADDRESS                                       
*        R9 MASKED TO 17-BIT ADDRESS                                            
*                                                                               
* REGISTERS SAVED: 1-8,10-15                                                    
*                                                                               
* STACK: NONE IF MAPPED SIGMA9 TASK                                             
*        2 IF UNMAPPED TASK                                                     
*        5 IF MAPPED TASK, NOT SIGMA9                                           
*                                                                               
* SUBROUTINES: NONE                                                             
*                                                                               
TMGRA    RES      0                                                             
         AND,R9   M17                                                           
         LW,R0    R9                ANY ACCESS                                  
         CI,R0    16                                                            
         BL       1ETMX8            B IF IN REGISTERS                           
         BIFMAP   TMGRA20                                                       
         BIFMU    1ETMX8                                                        
         BIFRBM   1ETMX8                                                        
         PUSH     2,R6                                                          
         LW,R6    K:FGDBG1          FOREGROUND START                            
         LW,R7    K:UNAVBG          FOREGROUND END+1                            
         AI,R7    -1                                                            
         CLM,R9   R6                                                            
         BCR,9    TMGRA19           B IF ADDRESS IS IN BOUNDS                   
         OR,R0    Y1                CALL IT READ AND EXECUTE                    
TMGRA19  PULL     2,R6                                                          
         B        1ETMX8            EXIT                                        
*                                                                               
TMGRA20  RES      0                 GET REAL ADDRESS FOR MAPPED TASK            
         DO       #SIGMA9                                                       
         LCFI     8                 INDICATES WORD ADDRESSING                   
         LRA,R0   R9                                                            
         STCF     R0                                                            
         AND,R0   TMGRA21           GET RID OF EXTRANEOUS BITS                  
         B        1ETMX8            EXIT                                        
*                                                                               
TMGRA21  DATA     X'30FFFFFF'                                                   
*                                                                               
         ELSE     #SIGMA9                                                       
*                                                                               
         OR,R0    Y1                NO MAP, ACCESS READ AND EXECUTE             
         CW,R9    STVM                                                          
         BL       1ETMX8            B IF ADDRESS IS IN MONITOR MEMORY           
         PUSH     5,R1                                                          
         LB,R1    TCBPOINT          USER STI INDEX                              
         LW,R4    STITCB,R1         USER STCB ADDRESS                           
         LW,R1    STCBACI,R4        USER ACCESS CODES IMAGE                     
         LW,R2    R9                                                            
         SLS,R2   -8                                                            
         LW,R3    R2                                                            
         AND,R3   X6                BIT DISPLACEMENT IN BYTE                    
         SLS,R2   -3                BYTE DISPLACEMENT IN ACI                    
         LB,R0    *R1,R2                                                        
         SLS,R0   22,R3             SHIFT TO NORMAL POSITION                    
         AND,R0   Y3                MASK CORRECT BITS                           
         LW,R1    STCBAST,R4        USER SEGMENT TABLE                          
         LB,R3    R1                NUMBER OF ENTRIES                           
         BEZ      TMGRA26           B IF NONE                                   
TMGRA22  LW,R2    0,R1                                                          
         CW,R2    XASTACT                                                       
         BAZ      TMGRA25           B IF INACTIVE SEGMENT                       
         LW,R4    SDMMCCS,R2                                                    
         AND,R4   M24               START ADDRESS OF SEGMENT                    
         LI,R5    SDVPCNT                                                       
         LB,R5    *R2,R5            NR PAGES IN SEGMENT                         
         SLS,R5   9                 NR WORDS IN SEGMENT                         
         AW,R5    R4                                                            
         MTW,-1   R5                END ADDRESS OF SEGMENT                      
         CLM,R9   R4                                                            
         BCS,9    TMGRA24           B IF ADDRESS NOT IN THIS SEGMENT            
         LW,R5    R9                                                            
         SW,R5    R4                WORD DISPLACEMENT OF ADDR INTO SEG          
         SLS,R5   -9                CONVERT TO PAGE DISPLACEMENT                
         LW,R2    0,R2              START OF MAP IMAGE                          
         DO       #SIGMA9M                                                      
         LH,R5    *R2,R5            REAL PAGE NUMBER                            
         ELSE     #SIGMA9M                                                      
         LB,R5    *R2,R5            REAL PAGE NUMBER                            
         FIN      #SIGMA9M                                                      
         SLS,R5   9                 CONVERT TO WORD ADDRESS OF PAGE             
         OR,R0    R5                MERGE WITH ACCESS CODE                      
         LW,R5    R9                                                            
         AND,R5   M9                DISPLACEMENT OF ADDRESS IN PAGE             
         OR,R0    R5                MERGE INTO ACCESS, PAGE ADDRESS             
         PULL     5,R1                                                          
         B        1ETMX8                                                        
*                                                                               
TMGRA24  BCS,1    TMGRA26           B IF START OF SEG IS PAST                   
*                                   DESIRED ADDRESS, SINCE AST IS               
*                                   ORDERED BY STARTING ADDRESS                 
TMGRA25  AI,R1    1                 POINT TO NEXT AST ENTRY                     
         AI,R3    -1                DECREMENT NR OF AST ENTRIES                 
         BGZ      TMGRA22           B FOR NEXT AST ENTRY                        
TMGRA26  PULL     5,R1                                                          
         LW,R0    R9                ADDRESS NOT IN A SEGMENT.                   
         OR,R0    Y3                NO ACCESS                                   
         B        1ETMX8                                                        
         FIN      #SIGMA9                                                       
         TITLE    '** TMTYC - VALIDATE ADDRESS RANGE **'                        
******************                                                              
*    TMCKADP     *                                                              
******************                                                              
*                                                                               
* ENTRY: R9       LOWER ADDRESS IN RANGE TO BE CHECKED                          
*        R10      UPPER ADDRESS IN RANGE TO BE CHECKED                          
*        R11      ACCESS REQUIRED, BITS 2-3=00  READ,EXECUTE,WRITE              
*                                          =01  READ,EXECUTE                    
*                                          =10, READ                            
*        BAL,R8   TMCKADP                                                       
* EXITS: +1       ERROR, R15=X'8B' ADDRESS ERROR                                
*        +2       ALL ADDRESSES IN RANGE ARE GOOD                               
*                 R9-R10 ARE MASKED TO OMIT NON-ADDRESS BITS                    
* REGISTERS USED: R8, R15 IF ERRORS (R0 BY TMCKADR)                             
*           SAVED: R1-R14,       R15 IF GOOD                                    
* STACK WORDS: 2                                                                
* SUBROUTINES: TMCKADR                                                          
*                                                                               
*                                                                               
TMCKADP  PUSH     2,R8                                                          
         AND,R9   M17               ISOLATE ADDRESS FOR COMPARISON              
         AND,R10  M17                                                           
*                                                                               
TMCKAP1  BAL,R8   TMVADR            TEST ADDRESS IN R9                          
         B        TMCKAP7               NO-ACCESS                               
         CW,R0    R11                   ACCESS SUFFICIENT?                      
         BG       TMCKAP7               NO                                      
         BIFREAL  TMCKAP2           UNMAPPED?                                   
*                                                                               
         AI,R9    512               MAPPED-CHECK AT LEAST ONCE/PAGE             
         AND,R9   FFFFFE00              ADVANCE 9 TO BASE ADDRESS OF            
         CW,R9    R10                   NEXT PAGE, IF GTR THAN LAST             
         BG       TMCKAP9               ADDRESS OF RANGE (R10), THE             
         B        TMCKAP1               LAST PAGE TESTED WAS LAST TEST          
*                                       REQUIRED, RANGE IS AOK.                 
TMCKAP2  CW,R9    R10               UNMAPPED-HAS LAST ADDRESS OF RANGE          
         BE       TMCKAP9               BEEN DONE? YES-GOOD EXIT                
         LW,R9    R10                   NO-DO IT                                
         B        TMCKAP1                                                       
*                                                                               
TMCKAP7  CI,R15   TYC8B             ERROR EXIT                                  
         BG       TMCKAP8               SET TYC AND RETURN +1                   
         LI,R15   TYC8B                                                         
TMCKAP8  PULL     2,R8                                                          
         B        1ETMX8            EXIT                                        
*                                                                               
TMCKAP9  PULL     2,R8              TAKE GOOD EXIT, +2                          
         AI,R8    1                                                             
         B        1ETMX8            EXIT                                        
         TITLE    '** TMTYC -  CREATE A NEW ECB **'                             
******************                                                              
*    EMGETECB    *       SUBROUTINE TO CREATE A NEW ECB LINKED TO THE           
******************            CURRENT TASKS S-CHAIN                             
* ENTRY  BAL,R8   EMGETECB                                                      
* EXITS: +1       ERROR  R15=TYC   X'66' TSPACE NOT AVAILABLE                   
*                                  X'FE' MAX S-ECB EXCEEDED                     
*        +2       NORMAL R15=ENTRY VALUE                                        
*                        R2 =ECB ID                                             
* REGISTERS USED:  R0,R2, ALWAYS, R15 ON ERROR EXIT                             
*           SAVED: R1,R3-R14 ALWAYS, R15 ON GOOD EXIT                           
* STACK WORDS: 5                                                                
* SUBROUTINES: GETTEMP                                                          
* NOTES: ECB ACQUIRED IS ALL ZERO EXCEPT FOR BUSY, S-TASK ID AND                
*                 S-ECB CHAIN                                                   
*        EXITS ENABLED.                                                         
*                                                                               
         DO       #ECB                                                          
         BOUND    4                                                             
EMGETEM  PUSH     5,R7              ALT ENTRY FOR CREATING ECBS                 
         LW,R2    R5                    CHAINED TO LMI IN R5 VS                 
         B        EMGETE0               CURRENT TASK                            
EMGETECB PUSH     5,R7              SAVE REGISTERS 7-11                         
         LB,R2    TCBPOINT          LOCATE S-ECB CONTROLS IN CURRENT            
         LB,R2    STILMID,R2            TASKS LMI                               
*                                                                               
EMGETE0  DISABLE                                                                
         LW,R8    LMISECB,R2        INCREMENT COUNT AND COMPARE TO              
         MTB,1    R8                    MAXIMUM                                 
         LB,R9    LMIMAXS,R2                                                    
         CB,R9    R8                                                            
         BGE      EMGETE2               OK                                      
         LI,R15   TYCABORT          ABORT CURRENT TASK/LOAD MODULE,             
EMGETE1  ENABLE                                                                 
*                                                                               
         PULL     5,R7                                                          
         B        1ETMX8                ERROR EXIT                              
*                                                                               
EMGETE2  RES      0                                                             
         ENABLE                                                                 
*                                                                               
         LI,R7    ECBSIZE                                                       
         BAL,R8   GETTEMP                                                       
         B        EMGETE1           +1  ERROR-NO TSPACE, R15=TYC                
*                                   +2  NORMAL                                  
         LI,R0    0                 ZERO THE ECB JUST ACQUIRED                  
         LI,R9    7                                                             
         STW,R0   *R9,R7                                                        
         BDR,R9   %-1                                                           
         STW,R0   0,R7                                                          
         LW,R9    LMISECB,R2        GET COUNT, PREV-CHAIN-HEAD                  
         LB,R0    R9                                                            
         AI,R0    1                 INCREMENT COUNT                             
         CB,R0    LMIMAXS,R2        COMPARE TO MAXIMUM                          
         BG       EMGETE3           GREATER, ABORT THE CALLER                   
         STB,R0   R7                    COUNT, NEW-CHAIN-HEAD                   
         STW,R7   LMISECB,R2            INTO LMI                                
         STB,R2   R9                                                            
         STW,R9   ECBSECB,R7            INTO NEW-ECB                            
         ENABLE                                                                 
*                                                                               
         LW,R2    R7                SWAP ECB ADDRESS INTO R2                    
         LW,R0    XECBBUSY          SET BUSY                                    
         STW,R0   ECBFPT,R2                                                     
         PULL     5,R7                                                          
         AI,R8    1                     GOOD EXIT                               
         B        1ETMX8                                                        
EMGETE3  RES      0                                                             
         BAL,R8   RELTEMP           RELEASE THE TSPACE                          
         LI,R15   TYCABORT          SET TYC TO ABORT TASK                       
         B        EMGETE1           EXIT                                        
         FIN      #ECB                                                          
         TITLE    '** TMTYC - GET ORIGNAL FPT ADR **'                           
******************                                                              
*    EMGETFPT    *       SUBROUTINE TO GET THE ORIGINAL FPT ADDRESS             
******************                                                              
*                                                                               
* ENTRY  R2       ECB ID                                                        
*        R3       FPT ADDRESS (IN RTS IF REG)                                   
*        BAL,R8   EMGETFPT                                                      
* EXIT   +1                                                                     
*                                                                               
* REGISTERS USED:  R0,R8,                                                       
*           SAVED: R1-R7,R9-R15                                                 
* STACK WORDS: 2                                                                
* SUBROUTINES: NONE                                                             
*                                                                               
         DO       #ECB                                                          
EMGETFPT PUSH     2,R6                                                          
         LW,R0    R3                TEST TO SEE IF FPT ADDRESS WAS A            
         AND,R0   M17                                                           
         LB,R7    TCBPOINT              REGISTER                                
         SLS,R7   1                                                             
         LW,R7    STIRTSB,R7            SET R6,R7= ADDRESS OF R0 IN RTS         
         AND,R7   M17                                                           
         LW,R6    R7                         AND RTSB, WORD0 RESP.              
         AI,R6    -CAL1PUSH                                                     
         CLM,R3   R6                    WITHIN RTS?                             
         BCS,9    EMGETF1               NO- NORMAL FPT ADDRESS                  
         SW,R0    R6                                                            
EMGETF1  PULL     2,R6                  R0=ADDRESS TO STORE IN ECB,             
         B        1ETMX8            EXIT                                        
         FIN      #ECB                                                          
         TITLE    '** TMTYC - WAIT FOR ECB POSTINB **'                          
******************                                                              
*    EMWAIT      *       SUBROUTINE TO CONTROL WAIT STATES                      
******************                                                              
*                                                                               
* ENTRY: R2       ECB ADDRESS                                                   
*        R3       CURRENT FPT ADDRESS (CHECK, DELFPT OR ORIGINAL SERVIC         
*                   REQUEST IF WITH WAIT, OR ZERO IF NO FPT)                    
*        BAL,R8   EMWAIT                                                        
* EXITS: +1       ECB IS BUSY, CHECK OR DELFPT WITH A BUSY ADDRESS IS           
*                   THE ENVIRONMENT.                                            
*                   R15 = BUSY ADDRESS                                          
*        +2       ECB IS POSTED, R15=TYC                                        
* REGISTERS USED: R0, R8, R15                                                   
*           SAVED: R1-R7,R9-R14                                                 
* STACK WORDS: 13                                                               
* SUBROUTINES: GETFPTN,SERDEV,TMRDLTRG,ABNORMAL SUBR.                           
*                                                                               
EMWAIT   PUSH     13,R1                                                         
*                                       R2=ECB ID                               
*                                       R3=FPT ADDRESS OR 0                     
         DO       #ECB                                                          
EMWAIT1  LW,R6    ECBCTL,R2             R4=TASK ID                              
         AND,R6   XECBTYPE              R6=ECB TYPE                             
         LI,R1    0                     R1=FPT CODE OR 0                        
         CW,R3    M17               SET ADDITIONAL REGS                         
         BAZ      EMWAIT2                                                       
         LB,R1    *R3                                                           
         AND,R1   M7                    REMOVE INDIRECT BIT                     
EMWAIT2  LB,R4    TCBPOINT                                                      
EMWAIT3  LW,R0    ECBFPT,R2         ECB POSTED?                                 
         CW,R0    XECBBUSY                                                      
         BANZ     EMWAIT6               NO                                      
         ELSE     #ECB                                                          
EMWAIT1  RES      0                                                             
         LI,R15   0                 CLEAR TYC                                   
         LI,R1    0                 R1=FPT CODE                                 
         CW,R3    M17               SET ADDITIONAL REGS                         
         BAZ      EMWAIT2                                                       
         LB,R1    *R3                                                           
         AND,R1   M7                                                            
EMWAIT2  LB,R4    TCBPOINT                                                      
         LB,R5    IOQ4              NO OF Q ENTRIES                             
         CW,R2    IOQECB,R5         THIS IT                                     
         BE       EMWAIT6           YES                                         
         BDR,R5   %-2                                                           
         FIN      #ECB                                                          
EMWAIT4  PULL     13,R1             RESTORE REGS AND SET R15                    
         DO       #ECB                                                          
         LW,R0    ECBCOMPL,R2           TO TYC                                  
         LB,R15   R0                                                            
         FIN      #ECB                                                          
         B        EMWAIT5A              EXIT                                    
EMWAIT5  PULL     13,R1                                                         
EMWAIT5A AI,R8    1                 ADVANCE PAST BUSY EXIT                      
         B        1ETMX8            EXIT                                        
*                                                                               
EMWAIT6  CI,R1    X'47'             IS ABNORMAL SUBR CALL REQUIRED?             
         BE       EMWAIT8               DELFPT- ENTER R15 =01                   
         LW,R0    STITCB,R4             TERMINATING       =FC                   
         CW,R0    XSTIT                 ABORTING          =FE                   
         BAZ      EMWAITA               NO ABNORMAL SUBR REQUIRED               
         LB,R5    STILMID,R4        SEE IF NORMAL OR ABNORMAL                   
         LH,R0    LMISTAT,R5            TERMINATION                             
         CI,R0    LMIA                                                          
         BAZ      EMWAIT7                                                       
         LI,R15   TYCABORT                                                      
         B        EMWAIT9                                                       
EMWAIT7  LI,R15   TYCTERM                                                       
         B        EMWAIT9                                                       
EMWAIT8  LI,R15   TYCNORM                                                       
EMWAIT9  RES      0                                                             
         DO       #ECB                                                          
         LW,R0    ECBFPT,R2         GET ECB WORD 1                              
         CW,R0    XECBPOST          IS IT IN POST                               
         BAZ      EMWAIT91          NO                                          
         CW,R0    XECBBUSY          YES, IS POSTING DONE                        
         BANZ     EMWAITA           NO, ECB IS STILL BUSY                       
EMWAIT91 RES      0                 POSTING IS COMPLETE                         
         LB,R5    EMABNX,R6                                                     
         LW,R0    EMABNB,R5                                                     
         BAL,R8   *R0                   ENTER ABNORMAL SUBROUTINE               
         ELSE     #ECB                                                          
         BAL,R8   FMABORT                                                       
         FIN      #ECB                                                          
         B        EMWAITA            +1 RETURN, ECB BUSY                        
         CI,R15   TYC100             +2 RETURN, ECB POSTED OR                   
         BE       EMWAIT5               DELETED, TYC=100 IS DELETE              
         B        EMWAIT1               R2,R3 MUST BE SAVED                     
*                                                                               
EMWAITA  CI,R1    X'29'             ECB IS BUSY, TEST TO SEE IF THE             
         BE       EMWAITB               EMWAIT BUSY EXIT SHOULD BE USED         
         CI,R1    X'41'                                                         
         BE       EMWAITB1                                                      
         CI,R1    X'42'                                                         
         BE       EMWAITB1                                                      
         CI,R1    X'47'                                                         
         BNE      EMWAITC                                                       
EMWAITB  LI,R15   FPTBUSY               CHECK OR DELFPT- BUSY PROVIDED?         
         BAL,R5   GETFPTN                                                       
         B        EMWAITC               NO- CONTINUE                            
EMWAITB1 RES      0                                                             
         DO       #ECB                                                          
         DISABLE                        PROVIDED, TAKE EMWAIT BUSY EXIT         
         LW,R0    ECBFPT,R2             FIRST RESET CHK                         
         AND,R0   XECBNCHK                                                      
         STW,R0   ECBFPT,R2                                                     
         ENABLE                                                                 
         FIN      #ECB                                                          
         AND,R15  M17                                                           
         PULL     13,R1             BUSY EXIT                                   
         B        1ETMX8            EXIT                                        
*                                                                               
EMWAITC  RES      0                                                             
         DO       #ECB                                                          
         BIFSEC   EMWAITI           SECONDARY TASK?                             
*                                                                               
*                                   PRIMARY TASK WAIT LOGIC                     
*                                                                               
         LW,R5    R6                    CHECK LEGALITY OF WAIT                  
         SLS,R5   -3                    ECB TYPE IS INDEX TO BIT                
         LB,R0    EMWAITF,R5            TABLE, FIRST GET BYTE, THEN             
         LW,R5    R6                    TEST BIT. IF 1, WAIT IS NOT             
         AND,R5   M3                    LEGAL, ABORT CALLER                     
         CB,R0    EMWAITM,R5                                                    
         BAZ      EMWAITD                                                       
         LI,R15   TYCABORT              SET ABORT CODE AND TAKE ERROR           
         B        EMWAIT5               EXIT                                    
         FIN      #ECB                                                          
EMWAITD  PUSH     2,R2              PRIMARY TASK WAIT,                          
         LH,R1    DCT7              DO CALLS ON SERDEV                          
EMWAITE  PUSH     R1                                                            
         BAL,R2   SERDEV            SERVICE DEVICE, R1= DCT INDEX               
         PULL     R1                                                            
         BDR,R1   EMWAITE           SERVICE NEXT DEVICE                         
         PULL     2,R2                  RESTORE R2,R3                           
         WAIT                                                                   
         B        EMWAIT1               RECHECK ECB                             
*                                                                               
*                                   SECONDARY TASK WAIT LOGIC                   
*                                                                               
         DO       #ECB                                                          
EMWAITI  CI,R1    X'40'                                                         
         BNE      EMWAITI1          B IF NOT WAITALL                            
         LW,R0    STITCB,R4         WAITALL, GET FLAGS                          
         CW,R0    XSTIT             IS TASK IN TERMINATION                      
         BAZ      EMWAITB1          NO, GO TO BUSY EXIT                         
EMWAITI1 RES      0                 WAIT FOR COMPLETION                         
         LW,R11   XSTICA                R11='CA' AND 'LW' FLAGS                 
         DO       #ROLL                                                         
*                                                                               
         DO       #SWAP                                                         
         LB,R7    TCBPOINT          GET STI INDEX                               
         LB,R7    STISTAT,R7        GET STATUS                                  
         CI,R7    STISLICE          IS IT TIME SLICED                           
         BAZ      EMWAITI4          NO                                          
         CI,R6    IO1               IS IT I/O ECB                               
         BE       EMWAITI2          YES                                         
*                                   BLOCK IT                                    
         OR,R11   XSTIBLK           SET TASK BLOCKED                            
EMWAITIA DISABLE                    DON'T LET MMEXEC TRIG YET                   
         LB,R4    TCBPOINT          GET STI INDEX                               
         BAL,R8   MMSWAP            GO CHECK FOR SWAP                           
         B        %+1               NO                                          
         B        EMWAITK                                                       
         FIN      #SWAP                                                         
*                                                                               
EMWAITI2 EQU      %                                                             
*                                                                               
         DO       #TJE                                                          
         LB,R7    IOQ4              NO OF Q ENTRIES                             
         DISABLE                                                                
         CW,R2    IOQECB,R7         IS IT THIS ONE                              
         BE       EMWAITI3          YES                                         
         BDR,R7   %-2                                                           
         B        EMWAITK           NOT GOING                                   
*                                                                               
EMWAITI3 LB,R7    IOQ7,R7           GET DCT INDEX                               
         LB,R7    DCT4,R7           GET DEVICE TYPE                             
         CI,R7    1                 TELETYPE                                    
         BNE      EMWAITK           NO                                          
         OR,R11   XSTITINP          SET TERMINAL INPUT                          
         B        EMWAITIA          GO GET MMEXIC GOING                         
         FIN      #TJE                                                          
*                                                                               
EMWAITI4 EQU      %                                                             
*                                                                               
         CI,R1    0                     ANY FPT?                                
         BE       EMWAITK               NO, BYPASS LW LOGIC                     
         LW,R0    1,R3                                                          
         CI,R0    FPTF0             SET LONG WAIT IF CURRENT                    
         BAZ      EMWAITK           FPT HAS F0 SET                              
         OR,R11   XSTILW                                                        
         LI,R7    MMTID                 R7=MEM EXEC ID                          
         LW,R5    STITCB,R7             R5=MM STCB                              
         LW,R10   STCBRDL,R5            R10=LEVEL BITS                          
         LH,R5    R10                   R5=GROUP CODE                           
         LI,R9    STISTRT               R9=START BIT                            
         FIN      #ROLL                                                         
EMWAITK  RES      0                                                             
         DISABLE                                                                
         LW,R0    ECBFPT,R2             RECHECK BUSY                            
         CW,R0    XECBBUSY                                                      
         BAZ      EMWAITK2              POSTED NOW                              
         OR,R0    XECBWD                STILL BUSY- SET DISPATCHER              
         STW,R0   ECBFPT,R2             WAIT CONTROLS                           
         STS,R11  STITCB,R4                                                     
         MTB,1    STICOUNT,R4                                                   
         DO       #ROLL                                                         
         CW,R11   XSTILW                                                        
         BAZ      EMWAITK1                                                      
         MTW,1    ROLL99                CHANGE STATUS OF ROLLOUT                
         STS,R9   STIPRIO,R7                                                    
         MTW,1    TDTRIG            SET SOFTWARE TRIGGER FLAG                   
         WD,R10   0,R5                  TRIGGER DISP                            
         ENABLE                                                                 
         LB,R0    STICOUNT,R4           HAS WAIT BEEN SATISIFIED                
         BEZ      EMWAIT3               YES, RECHECK ECB                        
         FIN      #ROLL                                                         
EMWAITK1 ENABLE                         TRIGGER THE DISPATCHER LEVEL            
*                                                                               
         BAL,R8   TMRDLTRG              AND WAIT                                
         B        EMWAIT3               RECHECK BUSY                            
EMWAITK2 ENABLE                         NOT BUSY, ENABLE,                       
         B        EMWAIT4               THEN GO TO EXIT LOGIC                   
         TITLE    '** TMTYC - ECB ABNORMAL CONTROLS **'                         
EMWAITZ  CRASH    'ECB ERR'                                                     
*                                                                               
*        ECB ABNORMAL CONDITION SUBROUTINE INDEX TABLE                          
*                                                                               
EMABNX   DATA,1   0           +ECB TYPE   0  ILLEGAL                            
         DATA,1   1           YIELDS      1  I/O                                
         DATA,1   2           INDEX INTO  2  SIGNAL                             
         DATA,1   3           EMABNB      3  STIMER                             
         DATA,1   4                       4  POLL                               
         DATA,1   5                       5  INIT                               
         DATA,1   6                       6  ENQ                                
         DATA,1   7                       7  MEM REQUEST                        
         DATA,1   6                       8  STDLB-ENQ ABNM                     
*                                                                               
*        ECB ABNORMAL CONDITION SUBROUTINE BRANCH TABLE                         
*                                                                               
EMABNB   B        EMWAITZ               0    CRASH                              
         B        FMABORT               1    1-IO                               
         B        SIGABNM               2    2-SIGNAL                           
         B        STIMABNM              3    3-STIMER                           
         B        POLLABNM              4    4-POLL                             
         B        PINTABNM              5    5-INIT                             
         B        ENQABNM               6    6,8-ENQ,STDLB                      
         DO       #ROLL                                                         
         B        MMABNM                7    7-MEM REQ                          
         ELSE                                                                   
         B        EMWAITZ                                                       
         FIN      #ROLL                                                         
*                                                                               
*        ECB WAIT LEGALITY TABLE    ONE BIT/ ECB TYPE                           
*                                                                               
EMWAITM  DATA     X'80402010',X'80402010'                                       
*        1 BIT MEANS ILLEGAL TYPE   0,1,2,3,4,5,6,7,8,-                         
EMWAITF  GEN,1,1,1,1,1,1,1,1,1,7    1,0,1,0,1,1,1,1,1,0                         
         FIN      #ECB                                                          
         TITLE    '** TMTYC - CHECK END ACTION **'                              
******************                                                              
*    CKENACT     *       SUBROUTINE TO FETCH, TEST AND CONVERT END-             
******************            ACTION INTERRUPT.                                 
* ENTRY: R3       FPT ADDRESS                                                   
*        R15      N, POSITION OF END-ACTION PARAMETER                           
*        BAL,R4   CKENACT                                                       
* ALTERNATE ENTRIES                                                             
*        R3       FPT ADDRESS                                                   
*        BAL,R4   CKENACTS          FETCHES EA FROM 9TH PARAMETER               
*                                                                               
*        R15      INTERRUPT LABEL, BITS 16-31    (0-15 IGNORED)                 
*        BAL,R4   CKINTLAB         EXITS ARE THE SAME                           
*                                                                               
*        R15      INTERRUPT ADDRESS,  BITS 16-31 (0-15 IGNORED)                 
*        BAL,R4   CKINTADR         EXITS ARE THE SAME                           
*                                                                               
*        R15      I AND END-ACTION WORD                                         
*        BAL,R4   CKENACT1         EXITS ARE THE SAME-ALLOWS SECONDARY          
* -OR-   BAL,R4   CKENACT2         TASK IN EXECUTION                            
*                                                                               
* EXITS: +1       ERROR, R15 = TYC                                              
*        +2       GOOD EXIT- R15=0 IF PARM NOT PRESENT                          
*                               =NON-ZERO IF PRESENT                            
*                   IF INTERRUPT: BYTE 0=GROUP,1=PRIO,2-3=LEVEL,R14=PRI         
*                   IF SIGNAL   : BYTE 0=X'7F',1-3 = ADDRESS                    
*                   IF BAL      : BYTE 0=X'FF',1-3 = ADDRESS                    
*                            R14=PRIORITY IN BYTE 3                             
*                                                                               
* REGISTERS USED: R0,R4,R5,R14,R15                                              
*           SAVED: R1-R3,R6-R13                                                 
* STACK WORDS: 2                                                                
* SUBROUTINES: GETFPTN, TMCKADR,                                                
*                                                                               
CKENACTS LI,R15   FPTENDAC          SET 9TH PARM, STD FPT                       
CKENACT  BAL,R5   GETFPTN           FETCH END ACTION                            
         B        1ETMXR4               EXIT AOK, PARM NOT USED, R15=0          
         CI,R15   0                                                             
         BE       1ETMXR4           VALUE OF 0 OK FOR END-ACT. WORD             
CKENACT2 EQU      %                 R15=END ACTION ENTRY                        
CKENACT1 AND,R15  C001FFFF          ISOLATE I AND ADDRESS BITS                  
         LB,R0    R15               GET I FLAGS                                 
         CI,R0    X'C0'                 I=3  SIGNAL ADDRESS                     
         BE       CKENACT3                                                      
         CI,R0    X'40'                                                         
         BANZ     CKINTADR              I=1  INTERRUPT ADDRESS                  
         BG       CKINTLAB              I=2  INTERRUPT LABEL                    
*                                       I=0  BAL ADDRESS                        
         BIFRBM   CKENACT5          RBM CAN DO ANY END ACTION                   
         BIFMAP   CKENACTE              OTHERWISE ONLY REAL                     
CKENACT5 EQU      %                                                             
         PUSH     2,R8              BAL TYPE END-ACTION                         
         AND,R15  M17                                                           
         LW,R9    R15                   VALIDATE EA ADDRESS AS IN               
         BAL,R8   TMVADR                PRIMARY TASK                            
         B        CKENACTB              NO                                      
         CW,R0    Y1                    YES- READ AND EXECUTE?                  
         BG       CKENACTB              NO                                      
         LI,R0    X'FF'                 YES-AOK                                 
         B        CKENACT4                                                      
*                                                                               
CKENACT3 EQU      %                 SIGNAL TYPE END ACTION,                     
         BIFRBM   CKENACT7              RBM CAN DO BAL, ELSE                    
         BIFMAP   CKENACTE              ONLY REAL USERS LGL                     
CKENACT7 EQU      %                                                             
         PUSH     2,R8                  SAVE REGS                               
         AND,R15  M17                   ISOLATE ADDRESS                         
         LW,R9    R15                   VALIDATE AS IN PRIMARY TASK             
         BAL,R8   TMVADR                WITH WRITABLE ACCESS                    
         B        CKENACTB                                                      
         CI,R0    0                                                             
         BNE      CKENACTB                                                      
         LI,R0    X'7F'                                                         
*                                                                               
CKENACT4 STB,R0   R15               SET FLAG BYTE IN BYTE0, R15                 
         PULL     2,R8                  PULL REGS AND TAKE GOOD EXIT            
         B        1ETMXR4                                                       
CKENACTB PULL     2,R8              ADDRESS ERROR                               
CKENACTA LI,R15   TYC61                 RESTORE REGS                            
         B        1ETMXR4E              ERROR EXIT                              
*                                                                               
*                                                                               
CKENACTE LI,R15   TYC64             SET INVALID END ACT                         
         B        1ETMXR4E                                                      
*                                                                               
*                                                                               
*                                                                               
CKINTLAB LI,R5    1                 INTERRUPT LABEL                             
         LH,R15   R15,R5                RELOAD R15 GET  SIGN EXTENSION          
         LH,R5    INTLB1                FIND LABEL IN LABEL TABLE AND           
         CH,R15   INTLB1,R5             GET ADDRESS                             
         BE       CKENACT6                                                      
         BDR,R5   %-2                                                           
         B        CKENACTA              NOT FOUND                               
CKENACT6 LH,R15   INTLB2,R5             R15= INTERRUPT ADDRESS                  
*                                                                               
CKINTADR AND,R15  M16               ISOLATE ADDRESS                             
         CI,R15   X'50'                 LESS THAN 50 IS ILLEGAL                 
         BL       CKENACTA              ERROR                                   
         LW,R0    K:HIINT                                                       
         AND,R0   M16                                                           
         CW,R15   R0                                                            
         BG       CKENACTA                                                      
         DO       #550                                                          
         CI,R15   X'5E'                                                         
         BL       CKENACTC          B IF IN INTERNAL GROUP                      
         LI,R0    X'F'                                                          
         AND,R0   R15               GET LAST HEX DIGIT                          
         CI,R0    X'B'                                                          
         BG       CKENACTA          B IF IN THE '550 HOLES'                     
         FIN                        #550                                        
*                                   ALLOW ANY OTHER INTERRUPT,                  
CKENACTC EQU      %                                                             
         STW,R4   R0                R0=RETURN ADDRESS                           
         LI,R5    0                                                             
         LW,R4    R15               R4= INT. ADDRESS                            
         STW,R4   R14                                                           
         AI,R14   -X'4F'            R14=REL. ADD. OF INT.                       
         AI,R4    -X'50'                                                        
         SLD,R4   -4                                                            
         SCS,R5   4                 R4=GROUP CODE,  R5=LEVEL BIT                
         CI,R4    0                 IS IT GROUP ZERO                            
         BE       CKENACT9          YES - SPECIAL CASE                          
         AI,R4    1                 STEP TO PROPER GROUP CODE                   
CKENACT8 LI,R15   X'8000'                                                       
         LCW,R5   R5                                                            
         SLS,R15  0,R5              SHIFT LEVEL BIT TO PROPER PLACE             
         STB,R4   R15               STORE GROUP CODE                            
         LI,R5    1                                                             
         STB,R14  R15,R5            STORE REL. ADD. IN BYTE 1                   
         LW,R4    R0                TAKE GOOD EXIT                              
         B        1ETMXR4           EXIT                                        
CKENACT9 AI,R5    -2                                                            
         B        CKENACT8                                                      
         OLAYEND                                                                
         END                                                                    
