         PCC      0                                                             
         SYSTEM   SIG9P                                                         
         SYSTEM   OPTIONS                                                       
         SPACE    2                                                             
*                                                                               
*                                                                               
*                                                                               
         DEF      MMO4                                                          
         DEF      MMO4EXIT                                                      
         DEF      MMCHECK,MMEXEC,MMICHK,MMPOST                                  
         DEF      MMRECB,MMRISEG,MMROLL                                         
         DEF      MMSTOP                                                        
OLAYFLAG EQU      'MMO4'                                                        
         PSYS     0                                                             
         SYSTEM   CPRMON                                                        
MMO4     RES      0                                                             
         TITLE    '** MMO4 **'                                                  
         TITLE    '** MMO4 - SUBR TO INTERFACE WITH MMEXEC **'                  
*******************                                                             
*     MMROLL      *    SUBR TO REQUEST MEMORY FROM MMEXEC VIA                   
*     MMRISEG     *      ECB, RETURNS TO CALLER WHEN POSTED.                    
*******************                                                             
*                                                                               
* ENTRY  R3       # OF PAGES REQUIRED                                           
*        R6       SD ADDRESS AND AST FLAGS                                      
*        R12      AST ADDRESS (SEG ROLLIN ONLY)                                 
*        BAL,R8   MMROLL            PAGES IN GENERAL ENTRY                      
* OR     BAL,R8   MMRISEG           ROLLIN SEG PROVIDED                         
*                                       R6=SD ADDRESS                           
* EXIT   +1       ERROR EXIT, ECB NOR CREATED, R15=TYC                          
*        +2       NORMAL EXIT                                                   
* REGISTERS USED: R0                                                            
*          SAVED: R1-R15                                                        
* STACK WORDS:    15                                                            
* SUBROUTINES:    MMRECB,MMSTART,MMICHK                                         
*                                                                               
MMRISEG  PUSH     15,R1             SAVE REGISTERS                              
         LW,R7    R12               SWAP AST ADDRESS INTO R7                    
         LI,R3    MMRECB3               CLASS=MMRECB3                           
         B        MMROLL1                                                       
MMROLL   PUSH     15,R1             SAVE CALLER REGISTERS                       
         LI,R7    0                 NO AST ADDRESS                              
         AND,R3   M8                    R3=PR,CLASS FILED FOR                   
         AI,R3    MMRECB1               SET CLASS TO MMROLL                     
MMROLL1  BAL,R8   MMRDS             RELEASE SEGMENT ACQUIRED                    
         LB,R4    TCBPOINT          SET R4=TASKID OF CURRENT TASK               
         LB,R5    STILMID,R4            R5=LMID OF CURRENT TASK                 
         BAL,R8   MMRECB            CALL SUBR TO CREATE THE ECB                 
         B        MMROLL2               ERROR, NO ECB                           
         BAL,R8   MMSTART               START MMEXEC, ADJ PRIO                  
         BAL,R8   MMICHK            WAIT FOR MMEXEC TO POST ECB                 
         B        MMROLLER              BUSY NOT POSSIBLE                       
         BAL,R8   MMSDS             ACQUIRE SEGMENT AGAIN                       
         PULL     15,R1             RESTORE REGISTERS                           
         AI,R8    1                     NORMAL EXIT                             
         B        OLAYEXIT              RETRY MEM ACQUISITION                   
MMROLL2  BAL,R8   MMSDS             REACQUIRE SD                                
         PULL     15,R1                                                         
         B        OLAYEXIT              ERROR EXIT                              
         TITLE    '** MMO4 - SUBR TO CHECK MEM REQ ECB **'                      
*******************                                                             
*    MMCHECK      *    SUBR TO 'CHECK' MM ECBS                                  
*******************                                                             
*                                                                               
* ENTRY  R2       ECB ID                                                        
*        R3       FPT ID                                                        
*        BAL,R8   MMCHECK                                                       
* EXIT   +1       BUSY (NOT USED)                                               
*        +2       NORMAL, ECB POSTED                                            
*                                                                               
* REGISTERS USED: R0-R1,R5-R15                                                  
*          SAVED: R2-R4                                                         
* STACK WORDS:    1                                                             
* SUBROUTINES:    EMWAIT,EMDELECB                                               
*                                                                               
MMICHK   LI,R3    0                 INTERNAL CHECK ENTRY, SET                   
         LB,R4    TCBPOINT          R3=0(FPT ADR),R4=TASK ID                    
         LW,R1    XECBCHK               SET CHK BIT                             
         STS,R1   ECBFPT,R2                                                     
MMCHECK  PUSH     R8                SAVE EXIT                                   
         BAL,R8   EMWAIT                                                        
         B        MMCKER1               BUSY EXIT, ERROR                        
         CI,R15   TYC100            ECB DELETED OR DETATCHED                    
         BE       MMCKX                 YES, EXIT                               
         BAL,R8   EMDELECB          DELETE THE ECB                              
         B        MMCKER1               ERROR                                   
         ENABLE                                                                 
MMCKX    PULL     R8                                                            
         AI,R8    1                                                             
         B        OLAYEXIT                                                      
         TITLE    '** MMO4 - MEMORY MANAGEMENT EXECUTIVE TASK **'               
*******************                                                             
*    MMEXEC       *                 MEMORY MANAGEMENT EXECUTIVE                 
*******************                                                             
*                                                                               
*        MEMORY MANAGEMENT EXECUTIVE CONTROLS THE ACQUISITION                   
*                 OF  PAGES OF MEMORY WHEN THE SYSTEM BECOMES                   
*                 SATURATED. MMEXEC RUNS MAPPED.                                
*                                                                               
*                 MMEXEC IS DORMANT UNTIL A TASK CANNOT ACQUIRE                 
*                 MEMORY FROM THE FREE PAGES.  THIS TASK CREATES                
*                 AN ECB FROM ITSELF TO MMEXEC REQUESTING MEMORY.               
*                 ALL SUBSEQUENT MEMORY ACQUISITIONS WHICH CANNOT               
*                 BE SATISFIED WITH FREE PAGES, OR WHICH ARE OF                 
*                 EQUAL  OR LOWER PRIORITY THAN THOSE QUEUED TO                 
*                 MMEXEC ALSO CREATE ECBS.  THE MEM EXEC WILL                   
*                 CREATE ECBS CHAINED FROM ROLLED OUT TASKS                     
*                 TO ITSELF WHENEVER A TASK IS ROADBLOCKED DUE                  
*                 TO AN ACTIVE SEGMENT BEING ROLLED OUT.  LONG                  
*                 WAIT TASKS ARE THE ONLY EXCEPTION.  THE ECBS                  
*                 ARE CREATED BY MMEXEC BUT NOT PUT IN THE R-CHAIN              
*                 UNTIL THE TASK LEAVES THE WAIT STATE.  ALL LW                 
*                 TASKS BAL TO MMRILW TO CHAIN THE ECB WHEN THEY                
*                 LEAVE  THE WAIT STATE.  INACTIVE SEGMENTS                     
*                 WHICH ARE ROLLED OUT ARE LEFT ON THE FILE                     
*                 UNTIL ACTIVATED BY A USING TASK, AT WHICH                     
*                 TIME THE ECB FOR ROLL-IN IS CREATED.  THE                     
*                 PREFMODE CAL ALSO CREATES AN ECB CHAINED FROM                 
*                 THE TASK DOING THE CAL TO MMEXEC TO RECOVER                   
*                 THE PREFERRED PARTITION.  THESE                               
*                 ECB TYPES AND THEIR CONTENT ARE DESCRIBED BELOW               
*                                                                               
*                 MMEXEC STOPS WHEN IT IS 'ROADBLOCKED'. STARTS                 
*                 ARE DONE WHENEVER THE R-ECB CHAIN HEAD IS                     
*                 CHANGED.  ALSO, THE PRIORITY OF MMEXEC IS                     
*                 ALWAYS ALTERED TO EQUAL THE R-ECB CHAIN                       
*                 HEAD.  STARTS ARE DONE WHENEVER PAGES ARE                     
*                 RELEASED OR SEGMENTS DEACTIVATED.                             
*                                                                               
*                 MMEXEC RUNS CONTINUALLY UNTIL THE ECB CHAIN                   
*                 AGAIN BECOMES EMPTY, AT WHICH TIME IT STOPS                   
*                 AND RETURNS TO THE DORMANT STATE.                             
*                                                                               
*        ROLL99   IS RE-ENT COUNTER FOR ROLLOUT ALGORITM SCAN                   
*                 IF IT IS INCREMENTED, THE ROLL-OUT SCAN IS                    
*                 RE-INITIALIZED.  MUST BE INCR ON STM PAGE RELEASES,           
*                 DEACTIVATES, LONG WAITS, UNLOCKS AND LOCKS                    
*                 ALSO INCR IF ECB AT HEAD OF CHAIN IS REMOVED                  
*                                                                               
*                 ECB FORMAT:                                                   
*        ECBDATA  AST ADDRESS FOR ROLL-IN, 0, OR RMPT INDEX                     
*        ECBFPT   FLAGS                                                         
*        ECBSECB  S-TASK ID AND LINK, UNLESS DETATCHED BY                       
*                 TASK TERMINATION (MMABNM)                                     
*        ECBRECB  R-TASK ID AND LINK TO MMEXEC UNTIL POSTED                     
*        ECBPC    PRIO OF S-TASK, MEM REQ TYPE AND # PAGES NEEDED               
*                 FOR POSTING OR PROCESSING                                     
*        ECBENDAC NOT USED                                                      
*        ECBCOMPL TYPE COMPLETION WORD                                          
*        ECBT     ECB TYPE, 7 MEMORY REQUEST                                    
*                                                                               
*        CLASS    BYTE0 IS MEM REQUEST TYPE AS FOLLOWS:                         
*        MMRECB1  CREATED BY TASKS UNABLE TO GET MEMORY FOR A                   
*                 NEW REQUIREMENT, CONTAINS # OF PAGES NEEDED                   
*                 IS POSTED WHEN MMTPAGES IS ADEQUATE AND IT IS                 
*                 THE HIGHEST PRIORITY REQUEST.  S-TASK IS                      
*                 REQUESTING TASK.                                              
*        MMRECB2  CREATED BY MMEXEC AFTER ROLLING OUT A TASK                    
*                 TO ACTIVATE ROLL-IN.  S-TASK IS ROLLED OUT TASK.              
*                 # PAGES IS = 0                                                
*                 IS DELETED WHEN TASK BECOMES FULLY RESIDENT.                  
*        MMRECB3  CREATED BY TASKS WHEN ACTIVATING A SEGMENT                    
*                 WHICH WAS ROLLED OUT WHILE INACTIVE.  CONTAINS                
*                 TASKID, PRIORITY AND AST ADDRESS. # PAGES IS IN               
*                 SEG DESCR. POSTED WHEN SEGMENT IS ROLLED IN.                  
*                 S-TASK IS ACTIVATING TASK.                                    
*        MMRECB4  SEGMENT ROLL-IN INITIATED BY MMEXEC.  # PAGES=0               
*                 INCLUDES AST ADDRESS.  S-TASK IS TASK BEING                   
*                 ROLLED IN.  MMRECB2'S ARE CONVERTED TO MMRECB4'S              
*                 WHEN THE MMRECB2 IS TOP OF CHAIN AND A ROLLED                 
*                 OUT SEGMENT IS FOUND.  THE PAGES ARE ACQUIRED,                
*                 ROLL-IN READ IS DONE, AND THE ECB REVERTS TO                  
*                 A TYPE 2.                                                     
*                 MMEXEC CORRECTS THE # OF PAGES REQUIRED                       
*                 IN ECB TYPES 3 AND 4 FROM FEEDBACK FROM                       
*                 THE ERROR EXIT FROM MMGP                                      
*        MMRECB5  CREATED BY PREFMODE CAL IN ORDER TO RECOVER                   
*                 THE MEMORY IN A PREFERRED PARTITION WHICH HAS                 
*                 BEEN IN THE STM MODE.  IS POSTED BY MEM EXEC                  
*                 WHEN HE HAS SUCESSFULLY RECOVERED ALL PAGES                   
*                 OR TIMES OUT TRYING.                                          
*                 PAGE COUNT IS ORIGINALLY ZERO, SET TO ONE WHEN                
*                 MMEXEC CANNOT GET A NEW STM PAGE FOR MOVE.                    
*                                                                               
*        SDSTATE  STATE OF SEGMENT, ROLL-OUT STATES ARE:                        
*                 4 - BEING ROLLED OUT DS=1                                     
*                 5 - ROLLED OUT    DS=0                                        
*                 6 - BEING ROLLED IN DS=1                                      
*                                                                               
*        PAGE FLAGS GIVE REAL MEMORY AND FILE STATUS                            
*        PAGE NEVER ACTIVATED,      RPP=0,ROL=0                                 
*        PAGE ROLLED, REAL RELSD    RPP=0,ROL=1                                 
*        PAGE NOT ROLLED            RPP=1,ROL=0                                 
*        PAGE ROLLED, REAL NOT RLS  RPP=1,ROL=1                                 
         PAGE                                                                   
MMEXEC   DISABLE                                                                
         LW,R2    LMIRECB+MMLMID    ANY ECB'S                                   
         BNEZ     MMEXGO                YES, BEGIN ROLLOUTS                     
         LW,R1    XSTIPR                MOVE MMEXEC DOWN TO                     
         STS,R1   STIPRIO+MMTID         X'FFFF' WHILE IDLE                      
         LI,R4    MMTID                 R4=MM TASK ID                           
         XPSD,0   TMDQ                                                          
MMEXSTOP ENABLE                                                                 
         BAL,R8   MMSTOP                                                        
         B        MMEXEC                                                        
*                                                                               
MMEXGO   LW,R0    ECBSECB,R2        ECB FOR TERMINATED TASK                     
         BNEZ     MMEXTPR               NO, TEST PRIORITY                       
         ENABLE                                                                 
         BAL,R8   EMDELECB              YES, DELETE IT                          
         B        MMEXCRSH              ERROR                                   
         ENABLE                                                                 
         B        MMEXEC                                                        
*                                                                               
MMEXTPR  LW,R1    XSTIPR            ADJUST MMEXEC PRIO TO NEXT                  
         LB,R4    TCBPOINT              ECB                                     
         LW,R0    ECBPC,R2                                                      
         CS,R0    STIPRIO,R4            EQUAL TO FIRST ECB                      
         BE       MMEXCKPG              YES                                     
         STS,R0   STIPRIO,R4            NO, ALTER EXECUTION                     
         XPSD,0   TMDQ                  PRIORITY                                
         ENABLE                                                                 
         BAL,R8   TMRDLTRG              TRIGGER DISPATCHER                      
         B        MMEXEC                AND CONTINUE                            
*                                                                               
MMEXCKPG LW,R0    ECBPC,R2          ARE THERE ENOUGH PAGES                      
         AND,R0   M8                    AVAILABLE FOR ECB                       
         BEZ      MMEXTCLS              ZERO, TEST CLASS                        
         CW,R0    MMTPAGES              NON-0, CMPR TO FREE PGS                 
         BLE      MMEXTCLS          ENUF-PROCEED OR POST ECB                    
MMEXROUT ENABLE                                                                 
         BAL,R8   MMRSLCT           NO, SELECT A ROLLOUT SEGMENT                
         B        MMEXEC                +1 RETURN, NO ROLLOUT NOW               
*                                       +2, R6=SD SELECTED                      
         BAL,R8   MMROUT            CALL ROLL-OUT SUBR                          
         B        MMEXEC                ROLL DONE, RECHECK ECB                  
*                                                                               
MMEXTCLS LW,R12   ECBDATA,R2        TEST ECB FOR AST ADDR                       
         BEZ      MMEXTEST              NO AST IDENTIFIED, TYPE 2               
         CI,R12   X'FF'                 IS IT RMPT OR AST                       
         BLE      MMEXTEST              RMPT                                    
         LW,R6    *R12                  AST GVN, COMPR 'SDNPCNT'                
         LI,R1    SDNPCNT               WITH FREE PGS                           
         LB,R0    *R6,R1                (=#PAGES NEEDED FOR SEG)                
         CW,R0    MMTPAGES              ENOUGH?                                 
         BG       MMEXROUT              NOT ENOUGH, ROLL-OUT                    
*                                                                               
MMEXTEST LW,R1    XECBINP           SET THE ECB IN PROCESS                      
         STS,R1   ECBFPT,R2                                                     
         ENABLE                                                                 
         LW,R0    ECBPC,R2          IS THE ECB ROLLIN                           
         CI,R0    MMRECB1               OR USER REQUEST                         
         BANZ     MMEXPOST              USER, POST IT                           
         CI,R0    MMRECB5               PREFERRED PART RECOVERY                 
         BANZ     MMEXPREF              YES                                     
         BAL,R8   MMROLLIN          ROLL-IN SEGMENT                             
         B        MMEXEC                DONE, NO POSTING                        
*                                       DONE, POSTING REQUIRED                  
MMEXPOST ENABLE                     POST THE ECB                                
         LW,R6    TYCWNORM              NORMAL TYC                              
MMEXPTYC EQU      %                                                             
         BAL,R8   EMPOST                                                        
         B        MMEXCRSH              ERROR                                   
         B        MMEXEC            CONTINUE                                    
*                                                                               
MMEXPREF LW,R7    R12               RECOVER PREFERRED PARTITION                 
         BAL,R8   MMRPREF               R7=RMPT INDEX                           
         B        MMEXEC                NOT DONE, SCAN AGAIN                    
         LI,R6    0                 CLEAR TYC WORD                              
         STB,R15  R6                SETUP CORRECT TYC                           
         B        MMEXPTYC          EXIT                                        
*                                                                               
MMROLLER EQU      %                                                             
MMCKER1  EQU      %                                                             
MMPOSTER EQU      %                                                             
MMREER   EQU      %                                                             
MMEXCRSH CRASH    'ERROR IN MMEXEC'     MEMORY MGMT EXEC CRASH                  
         TITLE    '** MMO4 - SUBR TO STOP MMEXEC **'                            
*******************                                                             
*    MMSTOP       *    SUBR TO STOP MMEXEC                                      
*******************                                                             
*                                                                               
* ENTRY  BAL,R8   MMSTOP                                                        
* EXIT   +1       TASK STARTED AGAIN                                            
*                                                                               
* REGISTERS USED: NONE                                                          
*          SAVED: R0-R15                                                        
* STACK WORDS:    3                                                             
* SUBROUTINES:    TMRDLTRG                                                      
*                                                                               
MMSTOP   PUSH     3,R7              SAVE RETURN AND R7,R11                      
         LI,R7    MMTID             SET THE STOP BIT                            
         LB,R8    STISTAT,R7                                                    
         OR,R8    XSTISTOP                                                      
         STB,R8   STISTAT,R7                                                    
         BAL,R8   TMRDLTRG          TRIGGER THE DISP                            
         PULL     3,R7                                                          
         B        OLAYEXIT                                                      
         TITLE    '** MMO4 - SUBR TO SELECT ROLL-OUT SEGMENT **'                
*******************                                                             
*    MMRSLCT      *    SUBROUTINE TO SELECT THE NEXT SEGMENT FOR                
*******************      ROLL OUT                                               
*                                                                               
* ENTRY  BAL,R8   MMRSLCT                                                       
* EXIT   +1       NO ROLL-OUT NOW                                               
*        +2       SEGMENT SELECTED,                                             
*        R4       TASK ID (HIGHEST PR SEG USER)                                 
*        R5       LMID (HIGHEST PR SEG USER)                                    
*        R7       STCB ADDRESS OF TASK                                          
*        R10      ROLL99                                                        
*                                                                               
* REGISTERS USED: R0-R12,R14                                                    
*          SAVED: R13,R15                                                       
* STACK WORDS:    8                                                             
* SUBROUTINES:    TMDQ,TMRDLTRG,MMSTOP,MMRECB                                   
*                 MMRSTASK-MMRSTGO,MMRSNXT, INTERNAL SUBRS                      
* NOTES:          DS WILL BE SET IN SD,                                         
*                 'RD' WILL BE SET IN USING TASKS AST,                          
*                 REGISTER USAGE IS AS FOLLOWS:                                 
*        R0 - WORK                  R8 - LINK                                   
*        R1 - WORK                  R9 - LINK                                   
*        R2 - WORK                  R10- ROLL99 VALUE                           
*        R3 - LEVEL OF ROLL-OUT     R11- INACT VS ACT SEG SWITCH                
*        R4 - TASK ID BEING ROLLED  R12- AST ADDRESS                            
*        R5 - LMID BEING ROLLED     R13-                                        
*        R6 - SD BEING ROLLED/TEST  R14- REAL PAGE ADDR                         
*        R7 - STCB ADDRESS          R15-                                        
*                                                                               
*        R3,R4,R5,R6,R7,R8,R9,R10,R11 SAVED EVERY EXIT                          
*                 FOR CONTINUATION OF ROLL-OUT AT NEXT ENTRY                    
*                 FROM LAST SEG VS RESTART.  IF ROLL99 CHANGES                  
*                 THE SCAN IS ALWAYS RESTARTED FROM FREE PAGES.                 
         PAGE                                                                   
*                                                                               
*        +1 EXIT  NO ECB IN R-ECB CHAIN                                         
*                                                                               
MMRSEX1  ENABLE                                                                 
         AI,R10   -1                FORCE ROLL99 TO CAUSE                       
         STW,R10  MMRSRGSV+R10-R3       RETRY ON NEXT ENTRY                     
         PULL     R8                                                            
         B        *R8               ERROR EXIT                                  
*                                                                               
*        +1 EXIT  CHECK FREE PAGES BUT DO NOT FORCE RESCAN                      
*                 WORKS LIKE SUBR TO MMRSLCT SUBR. FOR CONTINUATION             
MMRSEX2  LCFI     MMRSREGS          SAVE REGISTERS                              
         STM,R3   MMRSRGSV                                                      
         PULL     R8                                                            
         B        *R8                                                           
*                                                                               
*        +2 EXIT  SEGMENT FOUND EXIT, WORKS LIKE SUBR                           
*                 TO MMRSLCT SUBR. FOR CONTINUATION OF ROLL-OUT                 
*                 SCAN                                                          
MMRSX    LCFI     MMRSREGS          SAVE LOCATION FOR NEXT                      
         STM,R3   MMRSRGSV                                                      
         PULL     R8                                                            
         AI,R8    1                     SET TO GOOD EXIT                        
         B        *R8               EXIT                                        
*                                                                               
*        ENTRY POINT                                                            
*                                                                               
MMRSLCT  PUSH     R8                SAVE EXIT                                   
         LCFI     MMRSREGS          LOAD UP ENVIRONMENT                         
         LM,R3    MMRSRGSV               FROM LAST ENTRY                        
         CW,R10   ROLL99            RE-DO SCAN FROM TOP DUE TO                  
         BE       *R8                   CHANGE OF STATUS                        
MMRSST99 LW,R10   ROLL99            SAVE THE RE-TRY COUNT                       
         ENABLE                                                                 
         LW,R0    TASK99            INITIALIZE TASK REENT COUNT                 
         STW,R0   MMTSK99                                                       
         LI,R3    0                 SET UP TO SCAN FROM THE                     
*                                       BEGINNING                               
         PAGE                                                                   
*                                                                               
*        BEGIN SCANNING ALL TASKS AT THE NEXT ROLL-OUT                          
*                 LEVEL                                                         
*                                                                               
MMRSCAN  LI,R4    0                     R4=CHAIN HEAD LOC                       
         STW,R3   MMRLEVEL              SAVE LEVEL FOR TYPEOUT                  
*                                                                               
         EXU      %+1,R3            LEVEL SWITCH                                
         DO       #SWAP=0                                                       
         B        MMRSPAGE          0-FREE PAGES ONLY                           
         B        MMRSBKGI          1-BACKGROUND, INACTIVE SEGS                 
         B        MMRSLWI           3-LONG WAIT, INACTIVE SEGS                  
         B        MMRSLWA           4-LONG WAIT, ACTIVE SEGS                    
         B        MMRSRTI           5-REQUESTING TASK, INACTIVE SEGS            
         B        MMRSNRMI          6-NORMAL TASKS, INACTIVE SEGS               
         B        MMRSOLAY          7-OVERLAY PAGES                             
         B        MMRSBKGA            BACKGROUND, ACTIVE SEGS                   
         B        MMRSENTA          8-ENTERING ACTIVE TASKS                     
         B        MMRSNRMA          9-NORMAL TASKS, ACTIVE SEGS                 
         B        MMRSERR2          10-OVER MAXIMUM, ERROR                      
         FIN      #SWAP=0                                                       
         DO       #SWAP                                                         
         B        MMRSPAGE          0-FREE PAGES                                
         B        MMRSLWI           1-LONG WAIT-INACTIVE                        
         B        MMRSLWA           2-LONG WAIT-ACTIVE                          
         B        MMRSNRMI          3-NORMAL TASKS-INACTIVE                     
         B        MMRSOLAY          4-OVERLAY PAGES                             
         B        MMRSTSTI          5-TIME SLICED TERMINAL INPUT                
         B        MMRSTSBL          6-TIME SLICED BLOCKED                       
         B        MMRSNRMA          7-NORMAL ACTIVE                             
         B        MMRSTSQS          8-TIME SLICED - OVER QSWAP                  
         B        MMRSERR2          9-OVER  MAX                                 
*                                                                               
         FIN      #SWAP                                                         
         PAGE                                                                   
*                                                                               
*        FREE PAGE LEVEL                                                        
*                                                                               
MMRSPAGE DISABLE                    CHECK ECB HEAD VS FREE PAGES                
         LW,R2    LMIRECB+MMLMID        GET FIRST R-ECB                         
         BEZ      MMRSEX1               ECB GONE, EXIT +1                       
         LW,R8    ECBPC,R2              LOWER BYTE OF CLASS=# PGS               
         AND,R8   M8                                                            
         BNEZ     MMRSPAG1              IF ZERO, # PAGES IN SD                  
         LW,R12   ECBDATA,R2            IS AST PROVIDED                         
         BEZ      MMRSEX1               NO AST, EXIT TO EXEC TO                 
         LW,R6    *R12                  COMPUTE PAGES REQ'D                     
         LI,R1    SDNPCNT               IF AST PROVEDED, GET #                  
         LB,R8    *R6,R1                PAGES FROM 'SDNPCNT'                    
MMRSPAG1 CW,R8    MMTPAGES              AND COMPARE TO TOTAL                    
         BLE      MMRSEX1               FREE PAGES AVAIL,EXIT +1                
         ENABLE                                                                 
         B        MMRSUPLV          RAISE THE LEVEL                             
*                                                                               
         SPACE    3                                                             
         DO       #SWAP=0                                                       
*        BACKGROUND  ROLL-OUT LEVEL                                             
*                                                                               
MMRSBKGI LI,R11   0                 SET TO INACTIVE SEGMENTS                    
         B        MMRSBKG                                                       
MMRSBKGA LI,R11   1                 SET TO ACTIVE SEGMENTS                      
MMRSBKG  EQU      %                                                             
         LI,R4    0                 RESET TO SCAN FROM TOP                      
MMRSBKGB EQU      %                                                             
         BAL,R8   MMRSNXT           FETCH NEXT TASK                             
         B        MMRSUPLV              END OF CHAIN                            
         LW,R8    STIPRIO,R4        IS THIS TASK BACKGROUND                     
         AND,R8   XSTIPR                                                        
         CW,R8    XSTIPR                (PRIORITY = FFFF)                       
         BNE      MMRSUPLV              NO END OF BKG                           
         BAL,R9   MMRSTASK          ROLL OUT SEGMENTS IN TASK                   
         B        MMRSST99              RE-SCAN                                 
         B        MMRSBKGB          ANY MORE BKG TASKS                          
         FIN      #SWAP=0                                                       
         PAGE                                                                   
*                                                                               
*        LONG WAIT TASKS ROLL-OUT LEVELS,                                       
*                                                                               
MMRSLWI  LI,R11   0                 SET TO INACTIVE SEGMENTS                    
         B        MMRSLW                                                        
         DO       #SWAP                                                         
MMRSTSTI EQU      %                                                             
MMRSTSBL EQU      %                                                             
         FIN      #SWAP                                                         
MMRSLWA  LI,R11   1                 SET TO  ACTIVE SEGMENTS                     
MMRSLW   BAL,R8   MMRSNXT           FETCH NEXT TASK                             
         B        MMRSUPLV              END OF CHAIN                            
         CW,R7    XSTILW                IS TASK LONG WAIT                       
         DO       #SWAP=0                                                       
         BAZ      MMRSLW                NO, GO TO NEXT TASK                     
         ELSE     #SWAP=0                                                       
         BAZ      MMRSLW02                                                      
         FIN      #SWAP=0                                                       
MMRSLW01 EQU      %                                                             
         DO       #SWAP                                                         
         LW,R1    ECBSECB,R2        SETUP TO SEE IF WE HAVE                     
         LB,R1    R1                SELECTED THE TASK WHO IS                    
         LW,R1    LMISDT,R1         REQUESTING THE MEMORY                       
         CB,R4    R1                IF SO THEN DO NOT ROLL HIM                  
         BE       MMRSLW            SELECT ANOTHER                              
         FIN      #SWAP                                                         
         BAL,R9   MMRSTGO           DO SEGMENTS IN  LW TASK                     
         B        MMRSST99              +1 RE-ENT COUNT CHANGE                  
         B        MMRSLW                +2 NEXT TASK                            
         DO       #SWAP                                                         
MMRSLW02 EQU      %                                                             
         CW,R7    XLWTIBL           IS HE TERM IN OR BLOCKED                    
         BANZ     MMRSLW01          B IF YES                                    
         B        MMRSLW                                                        
*                                                                               
         FIN      #SWAP                                                         
         PAGE                                                                   
         DO       #SWAP=0                                                       
*                                                                               
*        REQUESTING TASK ROLL OUT LEVEL                                         
*                                                                               
MMRSRTI  LI,R11   0                 SET INACTIVE SEGMENTS                       
         DISABLE                                                                
         LW,R2    LMIRECB+MMLMID    IS THIS TASK IN THE                         
         BEZ      MMRSEX1               REQUESTING LOAD MODULE                  
         LW,R5    ECBSECB,R2            SET R4,R5 TO                            
         ENABLE                         IF TASK TERMS NOW, EH                   
         LB,R5    R5                                                            
         LW,R4    LMISDT,R5             REQUESTING TASK                         
         LB,R4    R4                                                            
         LW,R7    STITCB,R4         SET UP TCB POINTER AND FLAGS                
         BAL,R9   MMRSTASK          ROLL OUT ITS INACTIVE SEGMENTS              
         B        MMRSST99              RE-SCAN                                 
         B        MMRSUPLV              GO TO NEXT LEVEL                        
         FIN      #SWAP=0                                                       
         SPACE    3                                                             
*                                                                               
*        NORMAL TASK ROLL-OUT LEVEL                                             
*                                                                               
MMRSNRMI LI,R11   0                 SET TO INACTIVE SEGMENTS                    
         B        MMRSNORM                                                      
MMRSNRMA LI,R11   1                 SET TO ACTIVE SEGMENTS                      
MMRSNORM BAL,R8   MMRSNXT           FETCH NEXT TASK                             
         B        MMRSUPLV              END OF CHAIN                            
         DO       #SWAP=0                                                       
         CW,R7    XSTILW                BYPASS LONG WAIT                        
         ELSE     #SWAP=0                                                       
         CW,R7    XLWTIBL           BYPASS L-WAIT,TERMINAL-IN,BLOCKED           
         FIN      #SWAP=0                                                       
         BANZ     MMRSNORM                                                      
         BAL,R9   MMRSTASK          ROLL OUT SEGMENTS IN TASK                   
         B        MMRSST99              +1 RE-ENT COUNT CHANGE                  
         B        MMRSNORM              +2 NEXT TASK                            
         SPACE    3                                                             
*                                                                               
*        OVERLAY PAGES LEVEL                                                    
*                                                                               
MMRSOLAY BAL,R8   OMANFP            FREE A PAGE                                 
         B        MMRSUPLV          NONE, NEXT LEVEL                            
         BAL,R8   MMRSEX2           EXIT TO TRY FREE PAGES NOW                  
         B        MMRSOLAY              THEN TRY FOR MORE OVERLAYS              
         PAGE                                                                   
         DO       #SWAP=0                                                       
*                                                                               
*        ENTERING ACTIVE TASKS                                                  
*                                                                               
MMRSENTA EQU      %                                                             
         DISABLE                                                                
         LW,R2    LMIRECB+MMLMID    GET CURRENT WORK ITEM                       
         BEZ      MMRSEX1           ECB GONE  EXIT+1                            
         LW,R8    ECBSECB,R2        GET REQUESTING TASK ID                      
         ENABLE                                                                 
         LB,R1    R8                TASK ID                                     
         LH,R1    LMISTAT,R1        FLAGE                                       
         CI,R1    LMIBKG            IS IT BACKGROUND                            
         BAZ      MMRSUPLV          NO-START ROLL ON ACTIVE TASKS               
         BAL,R8   MMSTOP            WAIT FOR MEMORY ENVIRONMENT CHANGE          
         B        MMRSST99          RESCAN FROM TOP                             
         FIN      #SWAP=0                                                       
*                                                                               
         SPACE    3                                                             
         DO       #SWAP                                                         
*                                                                               
*        TIME-SLICED SWAPPING TAKES PLACE HERE                                  
*                                                                               
*                                                                               
MMRSTSQS EQU      %                                                             
         LI,R11   1                 SET TO ACTIVE SEGMENTS                      
MMRSTS1  EQU      %                                                             
         BAL,R8   MMRSNXT           FETCH NEXT TASK                             
         B        MMRSUPLV          END OF CHAIN -- UP THE LEVEL                
         LB,R0    STISTAT,R4        IS THIS TASK TIME-SLICED                    
         CI,R0    STISLICE          IF NOT THEN                                 
         BAZ      MMRSTS1           GET NEXT ONE                                
         LB,R0    STIQMAX,R4        HAS THIS TASK EXCEEDED HIS                  
         CW,R0    QMAX              IN-CORE QUANTUM                             
         BL       MMRSTS1           B IF NO                                     
MMRSTS2  EQU      %                                                             
         BAL,R9   MMRSTASK          ROLL OUT THIS TASK                          
         B        MMRSST99          RESCAN                                      
         B        MMRSTS1           GO FOR NEXT ONE                             
*                                                                               
         FIN      #SWAP                                                         
         PAGE                                                                   
*                                                                               
*        MAXIMUM ROLL-OUT SYSTEM SATURATED                                      
*                                                                               
         DO       #SWAP=0                                                       
MMRSERR2 LCFI     3                 SET UP TYPE FPT IN REGS (0-2)               
         LM,R0    MMRSFPT2                                                      
         LCFI     5                 TEXT IN REGS (R4-R9 MAX)                    
         LM,R4    MMRSMSG2                                                      
         CAL1,2   R0                                                            
         BAL,R8   MMSTOP                WAIT FOR A CHANGE OF                    
         B        MMRSST99              STATUS AND CONTINUE                     
MMRSFPT2 GEN,8,24 X'02',0                                                       
         DATA     X'80000010'                                                   
         DATA     R4                                                            
MMRSMSG2 EQU      %                                                             
         DATA,1   18,X'5A',X'5A','M'   BANG BANG                                
         TEXT     'EMORY SATURATED'                                             
         ELSE     #SWAP=0                                                       
MMRSERR2 EQU      %                                                             
         BAL,R8   MMSTOP            WAIT FOR CHANGE IN STATUS                   
         B        MMRSST99          RESCAN                                      
*                                                                               
         FIN      #SWAP=0                                                       
         PAGE                                                                   
*                                                                               
*        INCREASE ROLL-OUT LEVEL TO A HIGHER LEVEL                              
*                                                                               
MMRSUPLV ENABLE                     MAKE SURE ENABLED                           
         CW,R10   ROLL99            ANY CHANGE IN STATUS                        
         BNE      MMRSST99              YES                                     
         AI,R3    1                     NO, INCREASE LEVEL                      
         B        MMRSCAN               AND CONTINUE                            
         PAGE                                                                   
*                                                                               
*        FIND NEXT TASK AT THIS LEVEL                                           
*                                                                               
MMRSNXT  DISABLE                    CHECK FOR STICHANGE SINCE                   
         LW,R2    LMIRECB+MMLMID    REFRESH ECB POINTER                         
         LW,R0    TASK99            LAST TASK PROCESSING IN                     
         CW,R0    MMTSK99           CASE R4 TASK HAS BEEN DELETED               
         BE       MMRSNX2           NO,CHAIN ON                                 
         LI,R4    0                 YES, START OVER IN TASK                     
         STW,R0   MMTSK99           RESET COUNT                                 
MMRSNX2  LB,R4    STIRNXT,R4        FETCH NWEXT HIGHER PRIO TASKS               
         ENABLE                     AND CHECK IT                                
         CI,R4    0                 END OF CHAIN?                               
         BEZ      *R8               END OF THIS PASS                            
         CI,R4    MMTID             DO NOT ROLL                                 
         BLE      MMRSNXT           TRY NEXT IF SYSTEM TASK                     
         LW,R7    STITCB,R4             R7=STITCB ENTRY FOR TASK                
         LB,R5    STILMID,R4            R5=LMI OF TASK                          
         LH,R0    LMISTAT,R5                                                    
         CI,R0    LMISEC            IS IT A PRIMARY                             
         BAZ      MMRSNXT           B IF YES - SKIP ROLOUT                      
         LW,R0    LMIPCB,R5             MAPPED                                  
         CW,R0    XSTCBMAP              IF NOT, DON'T ROLL                      
         BAZ      MMRSNXT                                                       
         LW,R0    STIPRIO,R4            SET PRIORITY FOR TYPEOUT                
         CW,R0    XSTIDSO           IS TASK IN MM CAL (DSO>0)                   
         BANZ     MMRSNXT           YES, DON'T ROLL                             
         LH,R0    R0                                                            
         STW,R0   MMRPRIO                                                       
         AI,R8    1                 EXIT TASK FOUND                             
         B        *R8                                                           
         TITLE    '** MMO4 - ROUTINE TO ROLL-OUT A TASK **'                     
*                                                                               
*        MMRSTASK SUBR TO ROLL OUT A TASK                                       
*                                                                               
MMRSTASK CI,R11   0                 IS LEVEL INACTIVE SEGS ONLY                 
         BE       MMRSTGO               YES, DON'T COMPARE PRIO                 
MMRSTTST DISABLE                                                                
         LW,R2    LMIRECB+MMLMID    FETCH THE HIGHEST PRIO                      
         BEZ      MMRSEX1               NO ECB, EXIT +1                         
         LW,R0    ECBPC,R2              R8=PRIO                                 
         LW,R1    XSTIPR                R1=PR  MASK                             
         CS,R0    STIPRIO,R4            TASK TO BE ROLLED                       
         BL       MMRSTGO               REQUEST HIGHER PRIO                     
         DO       #SWAP                                                         
         BNE      MMRSNX4           B IF LOWER PRIORITY-AND STOP                
         LB,R0    STISTAT,R4        IS THE CANDIDATE TIME-SLICED                
         CI,R0    STISLICE          IF NOT THEN WE STOP                         
         BAZ      MMRSNX4           F IF NOT TIME SLICED                        
         LW,R1    ECBSECB,R2        NOW CHECK IF HIGHEST WORK ITEM              
         LB,R1    R1                IS FOR A TIME-SLICED TASK                   
         LW,R1    LMISDT,R1         GET TASKS ID                                
         LB,R1    R1                IN R1                                       
         CW,R1    R4                IF CANIDATE IS ROLLEE SKIP IT               
         BE       MMRSTET           FIND NEXT TASK                              
         LB,R0    STISTAT,R4        NOW CHECK IF CANIDATE IS                    
         CI,R0    STIROLLD          ALREADY ROLLED IF SO THEN                   
         BANZ     MMRSTGO           ROLL HIM SOME MORE - B IF ROLLED            
         LB,R0    STISTAT,R1        IF IT IS THEN CHECK HIS QSWAP               
         CI,R0    STISLICE          IF NOT CONTINUE ROLLING                     
         BAZ      MMRSTGO           G IF NOT TIME-SLICED                        
         LB,R0    STIQMAX,R4        HAS NEW CANDIDATE EXCEEDED QMAX             
         CW,R0    QMAX              IF YES ROLL HIM IF NO SELECT                
         BGE      MMRSTGO           ANOTHER - B IF EXCEEDED                     
         B        MMRSTET           SELECT ANOTHER                              
*                                                                               
MMRSNX4  EQU      %                                                             
         FIN      #SWAP                                                         
         LW,R0    TASK99            CHECK TASK REENT COUNT BEFOR STOP           
         CW,R0    MMTSK99                                                       
         BNE      *R9                                                           
         CW,R10   ROLL99                                                        
         BNE      *R9               CHANGED START OVER                          
         ENABLE                                                                 
         BAL,R8   MMSTOP                STOP MMEXEC UNTIL  A HIGHER             
         B        *R9                   RE-SCAN EXIT                            
MMRSTGO  ENABLE                     SCAN TASK SEGMENTS                          
MMRSTPOK LW,R12   STCBAST,R7        SET R12=AST                                 
         BEZ      MMRSTET               NONE, EXIT END OF TASK                  
MMRSDOS  DISABLE                    TEST THE NEXT SEGMENT FOR                   
         CW,R10   ROLL99                ROLL-OUT, CHANGE IN                     
         BNE      *R9                   STATUS, YES, +1 EXIT                    
         LW,R8    TASK99            IF ANY TASKS HAVE BEEN DELETED FROM         
         CW,R8    MMTSK99           ST, ABORT SCAN AND RETRY                    
         BNE      *R9                                                           
         LW,R6    *R12              SET R6=NEXT SD ADDRESS                      
         BLEZ     MMRSTNXS              UNUSED OR 'BUSY'                        
         LW,R8    SDMMC,R6              IS DS ALREADY SET                       
         BLZ      MMRSTNXS              YES, SKIP SEGMENT                       
         LI,R1    SDFLAGS               R1=OFFSET TO FLAGS                      
         LH,R8    *R6,R1                R8=FLAGS                                
         CI,R8    SDRAC                 'RAC'                                   
         BANZ     MMRSTNXS              YES, SKIP SEGMENT                       
         AND,R8   XSDTYPE               JOB RESERVED PAGES,                     
         CI,R8    SDTYPE6               IF YES, SKIP IT FOR ROLL                
         BE       MMRSTNXS              OUT                                     
         LI,R2    SDTLOCK               LOCKED BY ONE OR MORE                   
         LB,R8    *R6,R2                TASKS                                   
         BNEZ     MMRSTNXS              YES, TRY NEXT SEG                       
         LI,R2    SDTACT                R2=OFFSET TO ACTIVE                     
         CW,R6    XASTACT           IS THE SEGMENT ACTIVE WRT                   
         BAZ      MMRSTNA               THIS TASK, NO                           
         CI,R11   0                     ROLLING ACTIVE SEGMENTS                 
         BE       MMRSTNXS              NO                                      
         EOR,R6   XASTACT               YES, RESET ACTIVE FLAG                  
         OR,R6    XASTRD                AND SET ROLL DEACTIVATED                
         STW,R6   *R12                  STORE INTO AST                          
         MTB,-1   *R6,R2            DECREMENT ACTIVE COUNT, IF                  
         BEZ      MMRSTSIA              0, ROLLOUT PRIO HAS                     
         ENABLE                         TASK ROADBLOCKED BUT                    
MMRSZSD  EQU      %                                                             
         LI,R6    0                     SEG NOT SELECTED, SET                   
         B        MMRSNECB              R6=0 AND CHECK FOR ECB                  
*                                       TYPE 2 REQUIREMENT                      
MMRSTNA  MTB,0    *R6,R2            INACTIVE, IS IT ACTIVE                      
         BNEZ     MMRSTNXS              TO ANY TASK, YES                        
         LH,R2    *R6,R1                NO, TEST STATE                          
         AND,R2   XSDSTATE                                                      
         SLS,R2   -SDSTSHF                                                      
         EXU      %+1,R2            BRANCH ON SD STATE                          
         B        MMRSTYP0               0 - BEING INITIATED                    
         B        MMRSTYP0               1 - ERASED                             
         B        MMRSTZNP              2 - INACTIVE                            
         B        MMEXCRSH              3 - ACTIVE                              
         B        MMEXCRSH              4 - BEING ROLLED OUT                    
         B        MMRSTLK                5 - ROLLED OUT                         
         B        MMEXCRSH              6 - BEING ROLLED IN                     
         B        MMRSTSDS               7 - BEING LOADED                       
MMRSTYP0 EQU      %                                                             
         OR,R6    XASTRD            SET IN CASE SEG HAS PAGES                   
         B        MMRSTZNP                                                      
MMRSTLK  EQU      %                                                             
         LI,R2    SDRPCNT           CHECK IF ONLY TWO PAGES                     
         LB,R8    *R6,R2            AND SKIP IF SO - MOST LIKLY                 
         CI,R8    2                 IT IS A READ TO A TELETYPE                  
         BLE      MMRSTRA           B IF LESS THAN 3 PAGES                      
         B        MMRSTRIT          ROLL IT SOME MORE                           
MMRSTSIA LH,R8    *R6,R1            SET THE SEGMENT STATE TO                    
         AND,R8   XSDSTMSK              INACTIVE IN CASE NO                     
         AI,R8    SDSTATE2              REAL PAGES PRESENT                      
         STH,R8   *R6,R1                ELSE WILLBE SET TO                      
*                                       BEING ROLLED OUT                        
MMRSTZNP LI,R2    SDNPCNT           ZERO PAGES REQUIRED COUNT                   
         LI,R8    0                                                             
         STB,R8   *R6,R2                                                        
MMRSTSDS LI,R2    SDRPCNT           ANY REAL PAGES IN THIS                      
         LB,R8    *R6,R2                SEGMENT                                 
         BNEZ     MMRSTRIT          B IF YES -- ROLL IT                         
MMRSTRA  EQU      %                                                             
         CI,R11   0                 ROLLING ACTIVE SEGS                         
         BE       MMRSTNXS          B IF NO - SKIP ANY ECB CHECKS               
         B        MMRSZSD           SET SEG NOT SELECTED -CHECK ECB             
MMRSTRIT EQU      %                                                             
         LI,R2    SDVPCNT           OFFSET TO VIRT. PAGE COUNT                  
         LB,R8    *R6,R2            GET VIRTUAL PAGE COUNT                      
         LI,R2    SDRPCNT           OFFSET TO REAL PAGE COUNT                   
         LB,R2    *R6,R2            GET CURRENT PAGES IN SEG                    
         SW,R8    R2                THIS IS HOW MANY SHOULD BE IN SEG           
         LI,R2    SDNPCNT           OFFSET TO PAGES ROLLED OUT                  
         STB,R8   *R6,R2            SET UP AS NEW PAGES NEEDED                  
*THE ABOVE SEQUENCE OF CODE IS AN APPROXIMATION TO THE NUMBER                   
*OF PAGES THAT ARE NEEDED TO ROLL IN THIS SEGMENT.                              
         LH,R8    *R6,R1            CHANGE SEGMENT TO BE ROLLED                 
         AND,R8   XSDSTMSK              TO BEING-ROLLED-OUT                     
         AI,R8    SDSTATE4              STATE                                   
         STH,R8   *R6,R1                                                        
         LW,R1    XSDDS             SET THE DS BIT IN SEGMENT TO                
         STS,R1   SDMMC,R6              BE ROLLED OUT                           
         STW,R6   *R12              UPDATA AST SD POINTER                       
         ENABLE                                                                 
         CW,R6    XASTRD            WAS AN ACTIVE SEGMENT SELECTED              
         BAZ      MMRSTX                NO, EXIT                                
MMRSNECB EQU      %                                                             
         LH,R8    LMISTAT,R5                                                    
         CI,R8    LMIT                                                          
         BANZ     MMRSCKR6          B IF TASK IS TERMINATING:                   
*                                   NO ECB, NO ROLLED-OUT FLAG                  
*                                                                               
         DO       #SWAP=0                                                       
         CW,R7    XSTILW            WAS USING TASK LONG WAIT                    
         ELSE                                                                   
         CW,R7    XLWTIBL           L-WAIT,TERMINAL IN OR BLOCKED               
         FIN      #SWAP=0                                                       
         BANZ     MMRSCECB              WAIT', NO ROADBLOCK                     
         DISABLE                                                                
         LB,R8    STISTAT,R4            NORMAL, SET ROLLED                      
         DO       #SWAP                                                         
         CI,R8    STISLICE          TIME-SLICED                                 
         BAZ      MMRSX01           B IF NO - DO NOT PUT ON SWAP QUEUE          
         CI,R8    STIROLLD+STISWAP  SKIP IF ALREADY ROLLED/SWAPPED              
         BANZ     MMRSX03           SWAPPED LOGIC                               
         OR,R8    XSTISWAP          SET SWAPPED STATE                           
         B        MMRSX02                                                       
MMRSX01  EQU      %                                                             
         FIN      #SWAP                                                         
         OR,R8    XSTIROLL              ROADBLOCK                               
MMRSX02  EQU      %                                                             
         STB,R8   STISTAT,R4                                                    
MMRSX03  EQU      %                                                             
         ENABLE                                                                 
MMRSCECB LW,R2    LMISECB,R5            ALREADY CREATED                         
MMRSXECB EQU      %                                                             
         BEZ      MMRSGECB              NONE, CREATE ONE                        
         LW,R8    ECBCTL,R2             ONE THERE, IS IT ROLL-IN                
         AND,R8   XECBTYPE              TYPE                                    
         CI,R8    ECBTMM                                                        
         BNE      MMRSFECB          B IF NO                                     
         LW,R8    ECBPC,R2          TEST CLASS                                  
         CI,R8    MMRECB2           IS IT A ROLLIN TYPE                         
         BANZ     MMRSCKR6          B IF YES - NO MORE NEEDED                   
MMRSFECB EQU      %                                                             
         LW,R2    ECBSECB,R2        GET NEXT ONE IN CHAIN                       
         AND,R2   M24               MASK                                        
         B        MMRSXECB          CHECK NEXT ONE                              
MMRSGECB PUSH     7,R1              CREATE A ROLL-IN TRIGGERING                 
         LI,R3    MMRECB2               ECB                                     
         LI,R7    0                     R7=NO AST FOR NOW                       
MMRSRECB BAL,R8   MMRECB                ECB FOR THE TASK                        
         B        MMRSTER1              ERROR, NO ECB                           
         PULL     7,R1                  RESTORE REGISTERS                       
MMRSCKR6 CI,R6    0                 WAS SEGMENT SELECTED                        
         BE       MMRSTNXS              NO, CONTINUE                            
MMRSTX   ENABLE                                                                 
         BAL,R8   MMRSX             EXIT WITH R6=SD SELECTED                    
         AI,R9    -1                    RE EXECUTE ENTRY                        
         B        *R9                                                           
MMRSTNXS ENABLE                     ADVANCE TO NEXT SEGMENT                     
         AI,R12   1                     INCR AST ADDRESS                        
         MTB,-1   R12                   DECR AST COUNT                          
         BNEZ     MMRSDOS               NOT DONE, CONTINUE                      
MMRSTET  AI,R9    1                     INCR EXIT                               
         B        *R9                   +2 EXIT                                 
MMRSTER1 LCFI     3                 WAIT FOR ONE USER INTERVAL                  
         LM,R0    MMRSSTIM              AND RETRY                               
         CAL1,7   R0                                                            
         B        MMRSRECB                                                      
MMRSSTIM DATA     X'44800000'       STIMER FPT, CODE=44, P0=1                   
         DATA     X'00080011'           P13,F3,F7                               
         DATA     1                     INTERVAL IN USER UNITS                  
         TITLE    '** MMO4 - SUBR TO CREATE A ME REQ ECB **'                    
*******************                                                             
*     MMRECB      *    SUBR TO CREATE A MEM REQUEST ECB                         
*******************                                                             
*                                                                               
*ENTRY   R3       ECB CLASS:    MMRECB#,PAGES                                   
*        R4       TASK ID (SOLICITING)                                          
*        R5       LMID OF SOLICITING TASK                                       
*        R7       AST ADDRESS (CLASS MMRECB3 ONLY)                              
*        BAL,R8   MMRECB                                                        
* EXITS  +1       ERROR, NO ECB CREATED                                         
*        +2       NORMAL, R2=ECB ADDRESS                                        
* REGISTERS USED: R0,R1,R2,R5,R7,R15                                            
*          SAVED: R3,R4,R6,R8-R14                                               
* STACK WORDS:    1                                                             
* SUBROUTINES:    EMGETECB,EMARECB                                              
*                                                                               
MMRECB   PUSH     R8                                                            
         BAL,R8   EMGETEM           GET AN ECB                                  
         B        MMRE2                 NO TSPACE, ERROR                        
         AND,R7   M17               STORE AST ADDRESS IN DATA WORD              
         STW,R7   ECBDATA,R2            (NOT TSPACE LINK)                       
         LW,R0    STIPRIO,R4            ADD TASK PRIORITY                       
         AND,R0   XSTIPR                                                        
         AND,R3   XECBCL                                                        
         AW,R3    R0                                                            
         STW,R3   ECBPC,R2              STORE PRIO,CLASS WORD                   
         LI,R7    ECBT                  SET TYPE TO MEM REQUEST                 
         LI,R8    ECBTMM                                                        
         STH,R8   *R2,R7                                                        
         CI,R3    MMRECB2           DO NOT CHAIN ROLLIN TYPE                    
         BAZ      MMRE0             ECBS IF THE STASK IS NOT                    
         DISABLE                                                                
         LB,R0    STISTAT,R4        ROADBLOCKED, IT MUST BE A LONG              
         DO       #SWAP                                                         
         CI,R0    STISWAP           SWAPPED                                     
         BANZ     MMRE3             B IF YES - SET UP SWAP-IN TIME              
         FIN      #SWAP                                                         
         CI,R0    STIROLLD          WAIT TASK AND IT WILL DO THE                
         BAZ      MMRE1             CHAINING WHEN IT BECOMES ACTIVE             
         ENABLE                                                                 
MMRE0    LI,R7    ECBRTID           SET RESPONSIBLE TASK TO MMEXEC              
         LI,R5    MMLMID                                                        
         STB,R5   *R2,R7                                                        
         DO       #SWAP                                                         
         LB,R0    STISTAT,R4        BUT ONLY FOR TIME SLICED TASKS              
         CI,R0    STISLICE                                                      
         BAZ      MMRE0A            B IF NOT TIME-SLICED                        
         BAL,R8   EMARECBX                                                      
         B        MMREER            CHAINING ERROR                              
         B        MMRE1                                                         
MMRE0A   EQU      %                                                             
         FIN      #SWAP                                                         
         BAL,R8   EMARECB           CHAIN THE ECB TO MMEXEC                     
         B        MMREER                R-LINKING PROBLEM                       
MMRE1    PULL     R8                EXIT                                        
         ENABLE                                                                 
         AI,R8    1                                                             
         B        OLAYEXIT                                                      
MMRE2    PULL     R8                ERROR EXIT                                  
         B        OLAYEXIT                                                      
         DO       #SWAP                                                         
MMRE3    EQU      %                                                             
         LW,R0    TTICKS            GET TOTAL TICKS                             
         AW,R0    QSWAP             ADD SWAP IN TIME QUANTUM                    
         STW,R0   ECBTIME,R2        SETUP SWAP-IN THRESHOLD                     
         B        MMRE1             DO NOT CHAIN ECB - DISPATCHER               
*                                   WILL DO IT WHEN ITS TIME                    
         FIN      #SWAP                                                         
         TITLE    '** MMO4 - SUBR TO POST MEM REQ ECB **'                       
*******************                                                             
*    MMPOST       *    SUBR TO POST MEM REQUEST ECB                             
*******************                                                             
* ENTRY  PER ECB SPECS                                                          
* EXIT   PER ECB SPECS                                                          
*                                                                               
MMPOST   PUSH     R8                SAVE EXIT                                   
         DISABLE                                                                
         LW,R8    ECBSECB,R2        S-TASK TERMINATED                           
         BEZ      MMPOST1               YES                                     
         LW,R4    R7                    SAVE R7                                 
         BAL,R8   EMRRECB           REMOVE FROM MMEXEC CHAIN                    
         B        MMPOSTER          CRASH                                       
         ENABLE                                                                 
         DO       #SWAP                                                         
         LW,R4    ECBSECB,R2        SET UP TO GET TASKS ID                      
         LB,R4    R4                HIS TASK ID                                 
         LW,R4    LMISDT,R4                                                     
         LB,R4    R4                NOW WE HAVE IT                              
         LI,R8    0                                                             
         STB,R8   STIQMAX,R4        GIVE HIM ANOTHER IN-CORE QUANTUM            
         FIN      #SWAP                                                         
         LW,R7    R4                    RESTORE R7                              
         BAL,R8   EMPOSTYC          POST THE ECB                                
MMPOSTX  PULL     R8                                                            
         AI,R8    1                 SET TO GOOD EXIT                            
         B        OLAYEXIT                                                      
MMPOST1  BAL,R8   EMDELECB          DELETE THE ECB                              
         B        MMPOSTER               ERROR                                  
         ENABLE                                                                 
         B        MMPOSTX                                                       
OLAYEXIT EQU      %                                                             
MMO4EXIT B        *R8               COMMON EXIT                                 
         OLAYEND                                                                
         END                                                                    
