         TITLE    'TASK AND ECB MANAGEMENT SUBS, TMGETPR'                       
         SYSTEM   SIG9P                                                         
         SYSTEM   OPTIONS                                                       
*                                                                               
*        OVERLAY MADE UP OF MISC ECB AND TASK MANAGEMENT SUBS                   
*                 OF FREQUENT BUT NOT HIGHEST UTILIZATION                       
*                                                                               
*        TMGETPR                                                                
*        TMGETIDS                                                               
*        TMGETJID,TMFINDJ                                                       
*        TMGETTID,TMFINDT                                                       
*        EMBLDECB                                                               
*        EMDATAI                                                                
*        EMDATAO                                                                
*        EMARECB                                                                
         DEF      A:TMGETP                                                      
         DEF      TMGETIDS          FIND JOB AND TASK IDS                       
         DEF      TMFINDJ,TMGETJID                                              
         DEF      TMFINDT,TMGETTID                                              
         DO       #ECB                                                          
         DEF      EMBLDECB                                                      
         DEF      EMDATAI                                                       
         DEF      EMDATAO                                                       
         DEF      EMARECB                                                       
         DEF      EMARECBX                                                      
         FIN      #ECB                                                          
         DEF      2ETMX8                                                        
OLAYFLAG EQU 'TMGE'                                                             
         SYSTEM   CPRMON                                                        
2ETM8P1  AI,R8    1                 INCREMENT EXIT                              
2ETMX8   B        *R8                                                           
2ETMX8WP PULL     R8                EXIT TO R8 WITH PULL                        
         B        2ETMX8                                                        
         TITLE    'TASK MANAGEMENT SUBR - FETCH PRIORITY FPT  TMGETPR'          
******************                                                              
*    TMGETPR     *       SUBROUTINE TO FETCH PRIORITY FROM AN FPT               
******************                                                              
*                                                                               
* ENTRY  R2       FPT ADDRESS                                                   
*        BAL,R8   TMGETPR                                                       
* EXIT   +1       EXIT, R0=PRIORITY                                             
*                                                                               
* REGISTERS USED: R0,R5,R7,R14                                                  
*           SAVED: R1-R4,R6,R8,R10-R13,R15                                      
* STACK WORDS:0                                                                 
* SUBROUTINES: GETFPTN                                                          
*                                                                               
*                                                                               
TMGETPR  RES      0                                                             
A:TMGETP EQU      TMGETPR                                                       
         LW,R7    R15               SAVE CURRENT TYC                            
         LI,R15   FPTPRIO               PRIORITY                                
         BAL,R5   GETPSI            FETCH PRIORITY                              
         B        TMGETP1               NOT PRESENT-                            
         LW,R0    R15                   OK-LOAD INTO R0                         
         B        TMGETP2                                                       
TMGETP1  LB,R5    TCBPOINT              DEFAULT TO PRIORITY OF CURRENT          
         LW,R0    STIPRIO,R5                 TASK                               
         LH,R0    R0                                                            
TMGETP2  LW,R15   R7                RESTORE R15                                 
         AND,R0   M16                                                           
         B        2ETMX8            EXIT                                        
         TITLE    'COMBINED JOB AD TASK ID FETCH'                               
*******************                                                             
*    TMGETIDS     *                                                             
*******************                                                             
*                                                                               
* ENTRY  BAL,R8   TMGETIDS          SAME AS BELOW FOR REGS                      
* EXIT   +1       ERROR IN ONE OF TWO LOOKUPS                                   
*        +2       BOTH LOOKUPS SUCESSFUL, REGS PER BELOW                        
*                                                                               
TMGETIDS PUSH     R8                SAVE EXIT                                   
         BAL,R8   TMGETJID          FETCH JOB ID                                
         B        2ETMX8WP              EXIT +1                                 
         BAL,R8   TMGETTID          FET TASK ID                                 
         B        2ETMX8WP              EXIT, +1                                
         PULL     R8                                                            
         B        2ETM8P1           EXIT +2                                     
         TITLE    'TASK MANAGEMENT SUBR - FIND A JOB BY NAME'                   
******************                                                              
*    TMFINDJ     *                                                              
*    TMGETJID    *       SUBROUTINE TO GET ID OF JOB NAMED IN P11 AND           
******************            P12 OF A STANDARD FPT, DEFAULT IS THE             
*                             CURRENT JOB.                                      
* ENTRY: R3       FPT ADDRESS                                                   
*        BAL,R8   TMGETJID                                                      
* ALTERNATE ENTRY:  R3 NOT USED, INSTEAD                                        
*        R10,R11  JOB NAME                                                      
*        BAL,R8   TMFINDJ     EXITS ARE THE SAME                                
* EXITS: +1       JOB NAME NOT VALID, R15=X'63'                                 
*        +2       GOOD EXIT, R6= JOB ID                                         
*                            R7= JCB                                            
* REGISTERS USED: R0,R7,R6,R14,R15    IF ERRORS                                 
*           SAVED: R1-R5, R8-R13,   R15 IF GOOD                                 
* STACK WORDS: 5                                                                
* SUBROUTINES: GETFPTN                                                          
* NOTES: TRAPS TO CALLER                                                        
*                                                                               
TMFINDJ  PUSH     3,R3              ALTERNATE ENTRY, R10-R11=JOB NAME           
         LI,R3    0                 SET NO FPT                                  
         LW,R4    R15                                                           
         PUSH     2,R10                                                         
         B        TMGETJ0                                                       
TMGETJID PUSH     3,R3                                                          
         LW,R4    R15               SAVE TYC                                    
         LI,R15   FPTJNAME          GET JOB NAME IN R10,R11                     
         BAL,R5   GETFPTNS                                                      
         B        TMGETJ5               NOT PROVIDED, DEFAULT                   
         PUSH     2,R10                                                         
         LW,R10   R15                                                           
         BEZ      TMGETJ6               BINARY ZERO IS ALSO DEFAULT             
         LI,R15   FPTJNAME+1                                                    
         BAL,R5   GETFPTN                                                       
         LW,R15   BLANKS                                                        
         LW,R11   R15                                                           
*                                                                               
TMGETJ0  LB,R6    SJI3              SEARCH SJI FOR JOB NAME                     
*                                                                               
TMGETJ1  CD,R10   SJI2,R6           JOB NAME =                                  
         BE       TMGETJ2               YES                                     
TMGETJ1A BDR,R6   TMGETJ1               NO-CONTINUE                             
         LI,R4    TYC63                 NOT FOUND, SET TYC                      
         B        TMGETJ3               LEAVE EXIT TO ERROR                     
*                                                                               
TMGETJ2  LW,R7    SJI1,R6           SET R7=JCB                                  
         LW,R0    0,R7                                                          
         CI,R3    0                 ANY FPT                                     
         BE       TMGETJ2A          NO                                          
         LB,R5    *R3               GET FPT CODE                                
         AND,R5   M7                CLEAR INDIRECT                              
         CI,R5    X'64'             IS IT A KJOB                                
         BE       TMGETJ2B          YES,SKIP TERM CHECK                         
TMGETJ2A RES      0                                                             
         CW,R0    XJCBJTM           JOB IN TERMINATION?                         
         BANZ     TMGETJ1A              YES-ILLEGAL                             
TMGETJ2B RES      0                                                             
         CW,R0    XJCBJST           JOB IN INITIATION?                          
         BANZ     TMGETJ1A              YES-ILLEGAL                             
         AI,R8    1                 SET GOOD EXIT                               
TMGETJ3  PULL     2,R10                 RESTORE R10-R11                         
TMGETJ4  LW,R15   R4                    RESTORE TYC                             
         PULL     3,R3              RESTORE R3-R5                               
         B        2ETMX8            EXIT                                        
*                                                                               
TMGETJ6  PULL     2,R10             ZERO FILL DEFAULT                           
TMGETJ5  LB,R6    TCBPOINT          DEFAULT TO CURRENT TASKS JOB                
         LB,R6    STIJID,R6             R6=JOB ID                               
         LW,R7    SJI1,R6               R7=JCB ADDRESS                          
         AI,R8    1                     GOOD EXIT                               
         B        TMGETJ4                                                       
         TITLE    'TASK MANAGEMENT SUBR - FIND A TASK BY NAME'                  
******************                                                              
*    TMGETTID    *       SUBROUTINE TO GET ID OF TASK/LOAD MODULE NAMED         
******************            IN P3-P4 OF A STANDARD FPT- DEFAULT IS            
*                             CURRENT TASK/LOAD MODULE                          
* ENTRY: R3       FPT ID                                                        
*        R6       JOB ID                                                        
*        BAL,R8   TMGETTID                                                      
* ALTERNATE ENTRY:  R3 NOT USED, INSTEAD                                        
*        R10,R11  TASK NAME                                                     
*        BAL,R8   TMFINDT     EXITS THE SAME                                    
* EXIT   *1       TASK NAME NOT VALID, R15=X'62'                                
*        +2       GOOD EXIT, R4=TASK ID, R5=LMID, R6=JOB ID, R7=JCB             
*                 NOTE: R4=0 IF LOAD MODULE IS PRIMARY                          
* REGISTERS USED: R0,R4,R5,R9,R14,R15    IF ERRORS, R6-R7 IF DEFAULT            
*           SAVED: R1-R3,R8,R10-R13,R15 IF GOOD                                 
* STACK WORDS: 2                                                                
* SUBROUTINES: GETFPTN                                                          
* NOTES: TRAPS TO CALLER                                                        
*                                                                               
TMFINDT  PUSH     2,R10             ALTERNATE ENTRY, R10-R11=TASK NAME          
         LW,R9    R15                                                           
         B        TMGETT0                                                       
TMGETTID LW,R9    R15               SAVE TYC                                    
         LI,R15   FPTTNAME          GET THE TASK NAME IN R10-R11                
         BAL,R5   GETFPTNS                                                      
         B        TMGETT5               NOT PROVIDED, DEFAULT                   
         PUSH     2,R10                                                         
         LW,R10   R15                                                           
         BEZ      TMGETT7               ZERO FILL DEFAULTS                      
         LI,R15   FPTTNAME+1                                                    
         BAL,R5   GETFPTN                                                       
         LW,R15   BLANKS                (IF 2ND WORD NOT PRESENT, BLANK         
         LW,R11   R15                                                           
*                                                                               
TMGETT0  LB,R5    LMI#              SEARCH LMI FOR TASK NAME                    
         CD,R10   ZEROS             REJECT TASK ID OF ALL ZEROS                 
         BE       TMGETT6                                                       
TMGETT1  CD,R10   LMINAME,R5        TASK NAMES =                                
         BNE      TMGETT2               NO                                      
         LW,R0    LMIJID,R5         JOB ID =                                    
         CB,R6    R0                                                            
         BNE      TMGETT2               NO                                      
         LH,R0    LMISTAT,R5        TERMINATING?                                
         CI,R0    LMIT+LMIPPL+LMISPL   IF TERMINATING OR PUBLIB,                
         BAZ      TMGETT3           IGNORE.  B IF FOUND                         
TMGETT2  BDR,R5   TMGETT1                                                       
TMGETT6  PULL     2,R10             SEARCH FAILED, TASK NAME NOT                
         LI,R15   TYC62                 DEFINED                                 
         B        2ETMX8            EXIT                                        
TMGETT3  LW,R15   R9                                                            
         LW,R4    LMISDT,R5         R5= LMID OF MATCH, SET                      
         LB,R4    R4                R4= TASK ID OF MATCH                        
         PULL     2,R10                                                         
         B        2ETM8P1           EXIT TO GOOD EXIT                           
TMGETT7  PULL     2,R10             ZERO FILL DEFAULT                           
TMGETT5  LW,R15   R9                                                            
         LB,R4    TCBPOINT              R4=TASK ID                              
         LB,R5    STILMID,R4            R5=LOAD MODULE ID                       
         LB,R6    STIJID,R4             R6=JOB ID                               
         LW,R7    SJI1,R6               R7=JCB ADDRESS                          
         B        2ETM8P1           TAKE GOOD EXIT                              
         TITLE    'ECB MANAGEMENT - CREATE STANDARD ECB     EMBLDECB'           
******************                                                              
*    EMBLDECB    *       SUBROUTINE TO BUILD AN ECB FROM A STANDARD FPT         
******************                                                              
*                                                                               
* ENTRY: R3       FPT ADDRESS                                                   
*        BAL,R8   EMBLDECB                                                      
* EXITS: +1       ERROR  R15=TYC   X'66' NO TSPACE                              
*                        NO ECB    X'61' INVALID END ACTION INTERRUPT           
*                                  X'FE' ABORT TASK                             
*                                  X'64' EA FROM SECONDARY                      
*                                  X'8B' INVALID EA BAL OR SIGNAL ADDR.         
*        +2       NORMAL R15=ENTRY VALUE                                        
*                        R2=ECB ID                                              
* REGISTERS USED: R0,R1,R2,R8,R9,R14,R15 IF ERRORS                              
*           SAVED: R3-R7, R10-R13, R15 IF NO ERRORS                             
* STACK WORDS: 6                                                                
* SUBROUTINES: EMGETECB, EMDELECB, TMGETPR, GETFPTN, CKENACT                    
*              EMGETFPT                                                         
* NOTES: ECB CONTENT BUSY, DP, CHK, FPT ADDR, S-TASK ID, S-ECB CHAIN,           
*                 PRIORITY, CLASS, END-ACTION, TIME                             
*        EXITS ENABLED.                                                         
         DO       #ECB                                                          
EMBLDECB PUSH     5,R4              SAVE REGISTERS AND TYC                      
         LW,R6    R15                                                           
         LB,R4    TCBPOINT          SET R4=TASK ID                              
         BAL,R8   EMGETECB          GET AN ECB                                  
         B        EMBLDEG               NO SPACE                                
         LI,R0    EMBLDEE           SAVE CALLERS TRAP                           
         PUSH     R0                                                            
*                                                                               
         BAL,R8   EMGETFPT          GET THE FPT ADDRESS AS                      
         AND,R0   M17                   ISOLATE                                 
         AWM,R0   ECBFPT,R2             ADD TO ECB                              
*                                                                               
         LW,R0    0,R3              IS THE FPT EXTENDED?                        
         CW,R0    XFPTP0                                                        
         BAZ      EMBLDEH               NO, STUFF DEFAULTS                      
         LW,R0    1,R3              GET PARAMETER WORD                          
EMBLDE1  CI,R0    FPTF3                 IF F3=1, VALIDATE AND SET CHK           
         BAZ      EMBLDE2                                                       
         CI,R0    FPTF8             WAIT AND DELETE-ON-POST                     
         BANZ     EMBLDED                NOT LEGAL                              
         BIFPRIM  EMBLDED               ERROR, SERVICE W/ WAIT                  
         LW,R7    XECBCHK                                                       
         STS,R7   ECBFPT,R2                                                     
*                                                                               
EMBLDE2  BAL,R8   TMGETPR           FETCH PRIORITY                              
         LW,R7    R0                    SAVE TEMPORARILY                        
*                                                                               
         LI,R15   FPTCLASS          FETCH CLASS                                 
         BAL,R5   GETFPTN                                                       
         LI,R15   ECBCL                 NOT PROVIDED, DEFAULT                   
         STH,R7   R15               COMBINE AND STORE                           
         STW,R15  ECBPC,R2              PRIORITY/CLASS                          
*                                                                               
         BAL,R4   CKENACTS          FETCH END ACTION                            
         B        EMBLDEF               ERROR                                   
         LB,R4    TCBPOINT          RESTORE R4 TO TASK ID                       
         STW,R15  ECBENDAC,R2           STORE INTO ECB                          
*                                                                               
         LI,R15   FPTTIME           FETCH TIME                                  
         BAL,R5   GETFPTN                                                       
         B        EMBLDE3               NOT USED, R15=0                         
         LB,R0    *R3                                                           
         AND,R0   M7                R0= FPT CODE                                
         CI,R0    X'44'             IS THIS AN STIMER CALL                      
         BNE      EMBLDE22          NO, TIME IS AN INTERVAL                     
         LW,R0    1,R3              GET FPT WORD 1                              
         CI,R0    FPTF1             TEST FOR THRESHOLD OR INTERVAL TIME         
         BANZ     EMBLDE24          B IF THRESHOLD VALUE                        
EMBLDE22 RES      0                 R15 CONTAINS TIME INTERVAL                  
         AW,R15   K:UTIME                                                       
         BNEZ     %+2                                                           
         AI,R15   1                                                             
EMBLDE24 RES      0                                                             
         STW,R15  ECBTIME,R2                                                    
         LW,R0    STITIME,R4        IF THE PRIMARY TASK HAS NO TIME             
         BEZ      EMBLDE4           CURRENTLY, USE THIS ONE, IF                 
         SW,R0    R15               NOT COMPARE THE TIMES AND USE               
         BLZ      EMBLDE3           THE MOST CRITICAL                           
EMBLDE4  STW,R15  STITIME,R4        SET A NEW CRITICAL TIME                     
*                                                                               
EMBLDE3  LW,R15   R6                                                            
         PULL     R0                RESTORE CALLERS TRAP                        
         PULL     5,R4              RESTORE REGISTERS AND EXIT                  
         B        2ETM8P1           EXIT TO GOOD EXIT                           
*                                                                               
EMBLDED  LI,R15   TYC6B             SET TYC=X'6 ', ILLEGAL WAIT                 
         B        EMBLDEF                                                       
EMBLDEE  LI,R15   TYCTRAP           SET TYC=FD ON TRAP                          
*                                                                               
EMBLDEF  PULL     R0                RESTORE                                     
         LB,R4    TCBPOINT                                                      
*                                                                               
         BAL,R8   EMDELECB          DELETE THE ECB                              
         B        %+1                   ERROR                                   
         ENABLE                                                                 
EMBLDEG  PULL     5,R4              RESTORE REGS AND EXIT                       
         B        2ETMX8            EXIT                                        
EMBLDEH  LW,R0    STIPRIO,R4        SET THE PRIO,CLASS FIELDS                   
         OR,R0    XECBCL                TO DEFAULTS                             
         STW,R0   ECBPC,R2                                                      
         B        EMBLDE3               EXIT                                    
         TITLE    'ECB MANAGEMENT SUBR - INPUT TO ECB DATA EMDATAI'             
******************                                                              
*    EMDATAI     *       SUBROUTINE TO PROCESS A DATA AREA INTO AN ECB          
******************                                                              
*                                                                               
* ENTRY: R2       ECB ID                                                        
*        R3       FPT ADDRESS                                                   
*        BAL,R8   EMDATAI                                                       
*                                                                               
* EXIT   +1       ERROR, R15=ERROR CODE, X'66'-NO TSPACE                        
*        +2       NORMAL                                                        
* REGISTERS USED: R0,R8,R14,R15 IF AN ERROR                                     
*           SAVED: R1-R7,R9-R13, R15 IF NO ERRORS                               
* STACK WORDS: 7                                                                
* SUBROUTINES: GETFPTN, GETTEMP, IMCKADP                                        
* NOTES: TRAPS TO CALLER                                                        
EMDATAI  PUSH     7,R5              SAVE REGS                                   
         LW,R6    R15                   AND TYC                                 
         LI,R15   FPTDATAI          FETCH DATA-IN PARAMETER                     
         BAL,R5   GETFPTNS                                                      
         B        EMDATI3               NONE PRESENT                            
         LB,R7    *R15                  TEST LENGTH > 127                       
         BEZ      EMDATI3               ZERO LENGTH =NO DATA                    
         CI,R7    128                   YES ERROR                               
         BGE      EMDATI4                                                       
         LW,R11   Y2                    TEST DATA AREA LEGALITY                 
         LW,R9    R15                   FOR READ                                
         LW,R10   R7                         R9=FIRST ADR                       
         AW,R10   R15                        R10=LAST ADR                       
         AI,R10   -1                                                            
         BAL,R8   TMCKADP                    R11=ACCESS REQD                    
         B        EMDATI4               ERROR                                   
*                                                                               
*                                   GET TSPACE FOR DATA                         
         BAL,R8   GETTEMP               CALL SUBR TO GET TSPACE                 
         B        EMDATI6               NO SPACE                                
         LW,R0    ECBDATA,R2        LINK TSPAC TO ECB                           
         STW,R7   ECBDATA,R2            ECB-> NEW DATA-> PREV DATA              
         STW,R0   0,R7                                                          
*                                                                               
         ENABLE                                                                 
*                                                                               
         B        EMDATI2                                                       
EMDATI1  LW,R0    *R15              MOVE THE DATA FROM THE CALLERS              
         STW,R0   0,R7                  AREA TO TSPACE                          
EMDATI2  AI,R7    1                                                             
         AI,R15   1                                                             
         MTB,-1   R7                                                            
         BNEZ     EMDATI1                                                       
*                                                                               
EMDATI3  LW,R15   R6                GOOD EXIT                                   
         PULL     7,R5                                                          
         B        2ETM8P1           EXIT TO GOOD EXIT                           
*                                                                               
EMDATI4  LI,R6    TYC8D             INVALID DATA AREA                           
         LW,R15   R6                ERROR EXIT                                  
EMDATI6  PULL     7,R5                                                          
         B        2ETMX8            EXIT                                        
         TITLE    'ECB MANAGEMENT SUBR - OUTPUT FROM ECB DATA. EMDATAO'         
******************                                                              
*    EMDATAO     *       SUBROUTINE TO REMOVE A DATA AREA TO USERS              
******************            RECIEVE AREA                                      
*                                                                               
* ENTRY: R2       ECB ID                                                        
*        R3       FPT ADDRESS                                                   
*        R4       TASK ID                                                       
*        BAL,R8   EMDATAO                                                       
* EXITS: +1       ERROR, R15=TYC                                                
*        +2       NORMAL                                                        
*                                                                               
* REGISTERS USED: R0,R8,R9-R10,R14,R15                                          
*            SAVED: R1-R7,R11-R13                                               
* STACK WORDS: 7                                                                
* SUBROUTINES: GETFPTN,TMCKADP,RELTEMP                                          
*                                                                               
EMDATAO  LW,R0    STITCB,R4         IF TASK IS TERMINATING,                     
         CW,R0    XSTIT             DO NOT MOVE OUTPUT DATA                     
         BANZ     2ETM8P1                                                       
         PUSH     7,R5                                                          
         LW,R6    R15                                                           
         LI,R15   FPTDATAO          DID CALLER PROVIDE A DATA AREA?             
         BAL,R5   GETFPTNS                                                      
         B        EMDATO4               NO-LET DATA AREA RELEASE W/ ECB         
         CW,R15   Y8                    LENGTH >127?                            
         BANZ     EMDATO5                    YES-ERROR IN LENGTH                
         LW,R9    R15                   VALIDATE AREA ADDRESSES                 
         LB,R10   R15                        R9=FIRST                           
         BEZ      EMDATO4               LENGTH=0, NO DATA                       
         AW,R10   R15                        R10=LAST                           
         AI,R10   -1                                                            
         LI,R11   0                          R11=ACCESS (WRITE)                 
         LB,R14   R15                       R14=AREA LENGTH (USER)              
         LW,R15   R6                        R15=TYC AGAIN                       
         BAL,R8   TMCKADP                                                       
         B        EMDATO6                    BAD AREA ADDRESS                   
*                                       AREA IS AOK                             
         LW,R7    ECBDATA,R2        DOES ECB HAVE DATA ATTACHED                 
         BNEZ     EMDATO1               NES                                     
         STW,R7   *R9                   NO-ZERO ZEROTH WORD OF                  
         B        EMDATO4               USERS AREA                              
*                                   MOVE DATA TO USERS AREA                     
EMDATO1  LW,R0    R7                    FIRST STORE LENGTH IN ZEROTH            
         AND,R0   YFF                                                           
         STW,R0   *R9                   WORD                                    
         LB,R0    R7                                                            
         CW,R0    R14                   THEN SET MOVE COUNT=SMALLEST            
         BL       EMDATO3               LENGTH                                  
         LW,R0    R14                                                           
         B        EMDATO3                                                       
EMDATO2  LW,R10   0,R7                  MOVE WORDS                              
         STW,R10  *R9                                                           
EMDATO3  AI,R7    1                                                             
         AI,R9    1                                                             
         BDR,R0   EMDATO2                                                       
*                                                                               
         LW,R7    ECBDATA,R2        DETATCH AND RELEASE DATA AREA               
         LW,R0    0,R7                                                          
         DISABLE                                                                
         STW,R0   ECBDATA,R2                                                    
         BAL,R8   RELTEMP               EXITS ENABLED                           
*                                                                               
EMDATO4  LW,R15   R6                                                            
         PULL     7,R5                                                          
         B        2ETM8P1           EXIT TO GOOD EXIT                           
*                                                                               
EMDATO5  LW,R15   R6                                                            
EMDATO6  LI,R15   TYC8D                 LET DATA AREA BE DELETED WITH           
         PULL     7,R5                  THE ECB                                 
         B        2ETMX8            EXIT                                        
         TITLE    'ECB MANAGEMENT SUBR - ADD AN ECB TO R-CHAIN EMARECB'         
******************                                                              
*    EMARECB     *       SUBROUTINE TO CHAIN THE ECB TO AN R-TASK               
******************            INCLUDING POSTING POLL ECBS                       
*                                                                               
*        BAL,R8   EMARECB           STANDARD ENTRY TO ADD AN                    
*                           ECB TO THE END OF PRIORITY GROUP.                   
*                                                                               
*        BAL,R8   EMARECBX          ALTERNATE ENTRY USED BY MEMORY              
*                          MANAGEMENT TO ADD AN ECB TO THE END OF               
*                          THE PRIORITY GROUP.                                  
*                                                                               
*   AT ENTRY:                                                                   
*        R2       ECB ID                                                        
*                                                                               
* EXITS: +1       ERROR, R15=ERROR CODE                                         
*        +2       NORMAL RETURN                                                 
*                                                                               
* REGISTERS USED: R0,R1,R8,R15 IF ERROR                                         
*           SAVED: R2-R7,R9-R14, R15 IF NO ERROR                                
* STACK WORDS:7                                                                 
* SUBROUTINES: TMABRTT                                                          
*                                                                               
EMARECBX EQU      %                                                             
         OR,R8    Y01               SET CHAIN AFTER FLAG                        
EMARECB  PUSH     7,R2                                                          
*                                                                               
         LI,R4    ECBRTID           SET R4 TO R-TASK ID                         
         LB,R4    *R2,R4                                                        
         LW,R1    XECBPR            PRIORITY MASK                               
         LW,R3    M24               ADDRESS MASK                                
         DISABLE                                                                
*                                                                               
         LH,R0    LMISTAT,R4        ENTRY USED?                                 
         BEZ      EMAREE2                                                       
*                                                                               
         CI,R0    LMIT                       TERMINATION OR IS GOING TO         
         BANZ     EMAREE2                    BE TERMINATED. USER ERROR.         
         LW,R0    LMIRECB,R4        ADD 1 TO THE R-TASKS R-ECB COUNT            
         MTB,1    R0                    AND COMPARE IT TO THE MAXIMUM           
         LB,R6    R0                    R-ECBS ALLOWED. IF GREATER,             
         CB,R6    LMIMAXR,R4            ABORT THE R-TASK AND GIVE               
         BG       EMAREE3               ERROR CODE TO CALLER.                   
         LB,R7    R8                GET CHAIN AFTER FLAG                        
         LW,R6    ECBCTL,R2         GET ECB TYPE                                
         CI,R6    ECBTMM            IS IT A MM ECB                              
         BNE      %+2               NO, LEAVE 'CA' AS IS                        
         EOR,R7   X1                YES, REVERSE 'CA'                           
*   R7 IS NOW A FLAG USED IN CHAINING THE NEW ECB                               
*   AS FOLLOWS:                                                                 
*   R7=0  CHAIN AFTER (NEW ECBS AT END OF PRIORITY GROUP)                       
*         USED BY MM FOR TIME-SLICED TASKS AND ALL OTHER SERVICES               
*   R7=1  CHAIN BEFORE (NEW ECBS AT HEAD OF PRIORITY GROUP)                     
*         USED FOR ALL MM ECBS EXCEPT TIME-SLICED TASKS.                        
         LI,R5    0                 SET PREVIOUS ECB= 0                         
         STW,R0   LMIRECB,R4                                                    
         LW,R6    LMIRECB,R4                                                    
         LW,R0    ECBPC,R2          GET PRIO OF ECB TO ADD                      
         B        EMARE2                                                        
*                                                                               
EMARE1   LW,R5    R6                    SET R5 TO PREVIOUS ECB AND              
         LW,R6    ECBRECB,R6            R6 TO NEW NEXT ECB                      
EMARE2   EQU      %                                                             
         CS,R2    R6                IS THE ECB ALREADY IN THE CHAIN             
         BE       EMARE2A           B IF YES - SOMEBODY ALREADY DID IT          
         CW,R6    M24               END OF CHAIN                                
         BAZ      EMARE3                YES                                     
         CS,R0    ECBPC,R6              PRIORITY HIGHER OR EQUAL TO             
         B        %+1,R7            SELECT COMPARE ON CHAIN AFTER FLAG          
         BGE      EMARE1            USE THIS BRANCH FOR CHAIN AFTER             
         BG       EMARE1                NEW ECB, YES KEEP GOING                 
         B        EMARE3            CHAIN IT HERE                               
EMARE2A  EQU      %                                                             
         LW,R0    LMIRECB,R4        DECR COUNT AND KEEP GOINT                   
         MTB,-1   R0                SOMEOTHER TASK HAS                          
         STW,R0   LMIRECB,R4        CHAINED IT                                  
         B        EMARE5                (MMEXEC & LW TASKS)                     
EMARE3   CW,R5    M24               ADD BEING DONE BEFORE                       
         BAZ      EMARE4            CHAIN HEAD? YES                             
         STB,R4   R6                CHAIN THE NEW ECB TO THE NEXT               
         STW,R6   ECBRECB,R2            AND PREVIOUS TO THE NEW                 
         LW,R0    ECBRECB,R5                                                    
         LB,R1    R0                                                            
         STB,R1   R2                                                            
         STW,R2   ECBRECB,R5                                                    
         B        EMARE5                                                        
*                                                                               
EMARE4   LB,R0    R6                CHAIN THE LMI TO THE NEW ECB,               
         STB,R0   R2                    AND THE NEW ECB TO THE OLD              
         STW,R2   LMIRECB,R4            CHAIN HEAD.                             
         STB,R4   R6                                                            
         STW,R6   ECBRECB,R2                                                    
*                                                                               
EMARE5   ENABLE                                                                 
         LI,R3    ECBT              CHECK THE NEW R-ECB                         
         LH,R0    *R2,R3                FOR A SIGNAL TYPE                       
         CI,R0    ECBTSIG                                                       
         BNE      EMARE10           NO, DON'T LOOK FOR POLL                     
*   THE ECB IS A SIGNAL.  SEARCH FOR A POLL ECB AND POST IT IF                  
*   ONE IS FOUND.                                                               
         LI,R1    ECBCLASS          SET R1=OFFSET TO CLASS HALFWORD             
         DISABLE                                                                
         LW,R6    LMISECB,R4        SEARCH S-ECB CHAIN FOR POLL ECB             
EMARE6   AND,R6   M24                   END OF CHAIN??                          
         BEZ      EMARE8                                                        
         LH,R0    *R6,R3                IS THE ECB TYPE POLL?                   
         CI,R0    ECBTPOLL                                                      
         BNE      EMARE7                     NO                                 
         LH,R0    *R6,R1                DO THE CLASS FIELDS MATCH?              
         CH,R0    *R2,R1                                                        
         BAZ      EMARE7                     NO                                 
         LW,R0    ECBFPT,R6             IS IT POSTED?                           
         CW,R0    XECBBUSY                   YES                                
         BAZ      EMARE7                                                        
         CW,R0    XECBPOST              IS IT IN POST                           
         BANZ     EMARE7                     YES                                
         OR,R0    XECBPOST              SET IN POST                             
         STW,R0   ECBFPT,R6                                                     
         LW,R0    ECBFPT,R2         SET THE SIGNAL IN-PROCESS                   
         OR,R0    XECBINP                                                       
         STW,R0   ECBFPT,R2                                                     
         ENABLE                                                                 
         PUSH     R2                                                            
         XW,R6    R2                SET R2 TO THE ECB TO BE                     
         LI,R0    TYCNORM              POSTED, R6=TYC WORD                      
         STB,R0   R6                    X'01'+ECB ID                            
         BAL,R8   POLLPOST                                                      
         B        EMAREA                                                        
         PULL     R2                                                            
         B        EMARE8                                                        
EMARE7   LW,R6    ECBSECB,R6        CONTINUE POLL SEARCH IN S-CHAIN             
         B        EMARE6                                                        
EMARE8   ENABLE                                                                 
EMARE10  LW,R0    LMISDT,R4         GET STIINDEX                                
         LB,R4    R0                                                            
         BEZ      EMARE11           MUST BE PRIMARY                             
         DISABLE                                                                
         LB,R0    STISTAT,R4        GET STATUS                                  
         CW,R0    XSTISUSP          IS IT IN SUPER STOP                         
         BAZ      EMARE11           NO                                          
         EOR,R0   XSTISUSP          RESET IT                                    
         STB,R0   STISTAT,R4                                                    
*                                                                               
        DO1      #MULTDSP                                                       
         XPSD,0   TMDQ              QUEUE TO TO0                                
         BAL,R8   TMTPRIO           TRIG DISP IF NEC                            
*                                                                               
EMARE11  ENABLE                                                                 
         PULL     7,R2              RESTORE REGS                                
         B        2ETM8P1           EXIT TO GOOD EXIT                           
EMAREA   PULL     R2                RESTORE ECB ADDRESS AND                     
         B        EMARE5                RESCAN                                  
*                                                                               
EMAREE3  ENABLE                     R-TASK R-ECBS EXCEEDED,                     
         LW,R4    R3                    ABORT IT                                
         BAL,R8   TMABRTT                                                       
EMAREE2  LI,R15   TYC62             R-TASK ID NOT VALID FOR SOME                
EMAREE   PULL     7,R2              ERROR EXIT                                  
         B        2ETMX8                                                        
         FIN      #ECB                                                          
         OLAYEND                                                                
         END                                                                    
