         PCC      0                                                             
         SYSTEM   SIG9P                                                         
         SYSTEM   OPTIONS                                                       
         SPACE    2                                                             
*                                                                               
*                                                                               
*                                                                               
         DEF      MMO5                                                          
         DEF      MMO5EXIT                                                      
         DEF      MMABNM,MMRFILE,MMROLLIN,MMROUT                                
         DEF      MMRREAD,MMRRFILE,MMRWRITE                                     
OLAYFLAG EQU      'MMO5'                                                        
         PSYS     0                                                             
         SYSTEM   CPRMON                                                        
MMO5     RES      0                                                             
MMRINDX  SET      MMROLTAB+1                                                    
MMRENDX  SET      MMROLTAB+2                                                    
MMRMAPLG SET      MMROLTAB+3                                                    
MMRLOOP  SET      MMROLTAB+4                                                    
MMROLMAP SET      MMROLTAB+5                                                    
         TITLE    '** MMO5 - ROLL OUT SUBROUTINE **'                            
*******************                                                             
*     MMROUT      *    SUBR TO ROLLOUT A SEGMENT                                
*******************                                                             
*                                                                               
* ENTRY  R6       SEGMENT DESCRIPTOR ADDRESS                                    
*        R4       TASK ID OF TASK BEING ROLLED                                  
*        BAL,R8   MMROUT                                                        
* EXIT   +1       SEGMENT ROLLED OUT IF POSSIBLE                                
*                                                                               
* REGISTERS USED: R0-R3,R9-R15                                                  
*          SAVED: R4-R8                                                         
* STACK WORDS:    5                                                             
* SUBROUTINES:    LOADMAP,MMRFILE,MMRWRITE,MMSETVPN,MMRP                        
*                                                                               
MMROUT   PUSH     5,R4              SAVE REGISTERS                              
         AND,R6   M17               SET MMEXEC TO USE SEG                       
         OR,R6    XASTAFAD          A, FA, DS                                   
*                                                                               
         DISABLE                                                                
         STW,R6   MMAST                 STORE INTO AST                          
         LB,R4    TCBPOINT          SET DSO                                     
         LI,R1    STIDSO                                                        
         STS,R1   STIPRIO,R4        SET DSO (ALWAYS MMEXEC HERE)                
         ENABLE                                                                 
*                                                                               
         BAL,R8   LOADMAP           LOAD UP THE MAP                             
         BAL,R8   MMRFILE           GET FILE SPACE FOR SEGMENT                  
         B        MMROUTER              NONE AVAIL                              
         BAL,R8   MMRWRITE          WRITE THE PAGES                             
         B        MMROUTER              IO ERROR                                
         MTW,1    ROLL98            INCREMENT ACTIVITY COUNT                    
         BAL,R8   MMSETVPN          SET UP ARGUMENTS AND                        
         BAL,R8   MMRP                  RELEASE REAL PAGES                      
         B        MMROUTER              ERROR                                   
         LI,R1    SDFLAGS           SET STATE TO ROLLED OUT                     
         LH,R8    *R6,R1                                                        
         AND,R8   XSDSTMSK                                                      
         AI,R8    SDSTATE5                                                      
         STH,R8   *R6,R1                                                        
         LI,R8    0                 GET RID OF SEGMENT TO MMEXEC                
         STW,R8   MMAST                                                         
         LW,R8    SDMMC,R6          REMOVE 'DS'                                 
         EOR,R8   XSDDS                                                         
         STW,R8   SDMMC,R6                                                      
*                                                                               
         PULL     5,R4              RESTORE REGISTERS                           
         B        OLAYEXIT                                                      
MMROUTER EQU      %                                                             
MMRICRSH EQU      %                                                             
MMABNMCR EQU      %                                                             
         CRASH    'MMO5'                                                        
         TITLE    '** MMO5 - ROLL-IN SEGMENT/TASK SUBROUTINE **'                
*******************                                                             
*    MMROLLIN     *    SUBR TO ROLL-IN A TASK                                   
*******************                                                             
*                                                                               
* ENTRY  R2       ECB ID                                                        
*        R4       TASK ID                                                       
*        R5       LMID                                                          
*        BAL,R8   MMROLLIN                                                      
* EXIT   +1       NO ECB POST REQUIRED                                          
*        +2       POST THE ECB                                                  
* REGISTERS USED: R0-R1,R6-R15                                                  
*          SAVED: R4,R5                                                         
* STACK WORDS:    1                                                             
* SUBROUITNES:    EMRSECB,EMDELECB,MMSETVPN,MMGP,MMRREAD                        
*                                                                               
MMROLLIN PUSH     R8                SAVE EXIT                                   
*                                                                               
MMRIN0   DISABLE                    RECHECK THAT HIGHEST PRIO                   
         LW,R7    LMIRECB+MMLMID        ECB HAS NOT CHANGED                     
         AND,R7   M24                                                           
         BEZ      MMRINX1               YES, EXIT                               
         AND,R2   M24                   = ONE BEING PROCESSED                   
         CW,R7    R2                                                            
         BNE      MMRIN9                NO, EXIT                                
         LW,R0    ECBPC,R2          IS THE ECB FOR A SEGMENT                    
         CI,R0    MMRECB3+MMRECB4       ROLLIN                                  
         BANZ     MMRIN3                YES                                     
*                                   **** SCAN TASK FOR ROLL-IN                  
*                                        REQUIREMENTS *******                   
         LW,R5    ECBSECB,R2        SET R4=TASK ID                              
         LB,R5    R5                    R5=LMID                                 
         LW,R4    LMISDT,R5                                                     
         LB,R4    R4                                                            
         LW,R7    STITCB,R4                                                     
         LW,R12   STCBAST,R7                                                    
MMRIN1   LW,R6    *R12              LOOK FOR A SEGMENT WHICH                    
         CW,R6    XASTRD                WAS ACTIVE AND ROLLED                   
         BANZ     MMRIN2                FOUND, ROLL IT IN                       
         AI,R12   1                                                             
         MTB,-1   R12                                                           
         BNEZ     MMRIN1                                                        
*                                   **** TASK NOW ROLLED IN ****                
*                                                                               
         LW,R0    ECBSECB,R2            TSK TERMINATED                          
         BEZ      MMRINX0               YES                                     
         DISABLE                                                                
         BAL,R8   EMRSECB           DETATCH ECB FR S-TASK                       
         B        MMRICRSH              ERROR                                   
*        ENABLE           *****TEMP PATCH......                                 
         DISABLE                                                                
         LB,R0    STISTAT,R4        START TASK NOW RESIDENT                     
         AND,R0   XSTINROL                                                      
         STB,R0   STISTAT,R4                                                    
         DO       #SWAP                                                         
         LI,R0    0                 CLEAR EXECUTION TIME COUNTER                
         STB,R0   STIQMAX,R4        AND GIVE HIM A NEW TIME                     
         LW,R0    QMIN              QUANTUM SO HE CAN EXECUTE                   
         STB,R0   STIQMIN,R4                                                    
         FIN      #SWAP                                                         
         ENABLE                                                                 
MMRINX0  BAL,R8   EMDELECB          NOW DELETE THE ECB                          
         B        MMRICRSH                                                      
         ENABLE                                                                 
         B        MMRINX1           EXIT, NO POST                               
*                                   **** CONVERT ECB-2 TO ECB-4                 
*                                        FOR SEGMENT FOUND ****                 
MMRIN2   AND,R12  M24               STORE AST ADDRESS INTO ECB                  
         STW,R12  ECBDATA,R2                                                    
         LI,R1    MMRECB4               AND SET THE TYPE 4                      
         STS,R1   ECBPC,R2              INDICATION SEGMENT ROLLIN               
         ENABLE                                                                 
         B        MMRIN4                GO ROLL IT IN                           
*                                   **** ROLL-IN A SEGMENT ****                 
*                                                                               
MMRIN3   LW,R12   ECBDATA,R2        SET R12=AST ADDRESS                         
         LW,R6    *R12                  R6=SD ADDRESS                           
MMRIN4   DISABLE                    TEST THE CURRENT STATE OF                   
*                                       SEGMENT AND TASK                        
         LW,R8    ECBSECB,R2            TASK TERMINATING                        
         BEZ      MMRIN9                YES, FORGET IT                          
         LW,R8    SDMMC,R6              'DS' SET NOW                            
         BLZ      MMRIN10               YES                                     
         LI,R1    SDFLAGS               SEGMENT STATE                           
         LH,R7    *R6,R1                                                        
         AND,R7   XSDSTATE                                                      
         SLS,R7   -SDSTSHF                                                      
         EXU      %+1,R7                BRANCH ON STATE                         
         B        MMRICRSH              0 - BEING INITIATED                     
         B        MMRICRSH              1 - ERASED                              
         B        MMRIN6                2 - INACTIVE                            
         B        MMRIN7                3 - ACTIVE                              
         B        MMRICRSH              4 - BEING ROLLED OUT                    
         B        MMRIN5                5 - ROLLED OUT                          
         B        MMRICRSH              6 - BEING ROLLED IN                     
         B        MMRICRSH              7 - BEING LOADED                        
*                                                                               
MMRIN5   LH,R8    *R6,R1            INITIATE ROLL IN, FIRST                     
         AND,R8   XSDSTMSK              SET THE STATE TO                        
         AI,R8    SDSTATE6              BEING ROLLED IN                         
         STH,R8   *R6,R1                                                        
         LW,R1    XSDDS                 SET 'DS'                                
         STS,R1   SDMMC,R6                                                      
         ENABLE                                                                 
         BAL,R8   MMSETVPN          SET UP ARGUMENT TO GET REAL PAGES           
         BAL,R8   MMGP                  FOR THE SEGMENT                         
         B        MMRIN8                REAL PAGES INADEQUATE                   
         LI,R7    STIDSO            SET DISP SKIP OVERRIDE FOR MMEXEC           
         STS,R7   STIPRIO+MMTID                                                 
         LW,R0    R6                    SET MM TO USE SEGMENT                   
         AND,R0   M24                                                           
         OR,R0    XASTAFAD          A, FA, DS                                   
         STW,R0   MMAST                                                         
         BAL,R8   LOADMAP                                                       
         PUSH     R2                SAVE ECB ID                                 
         BAL,R8   MMRREAD           READ THE SEGMENT                            
         B        MMRICRSH              ERROR                                   
         PULL     R2                RESTORE ECB ID                              
         LW,R12   ECBDATA,R2            R12=AST RESTORE                         
         LI,R1    SDFLAGS               R1=OFFSET TO FLAGS                      
         DISABLE                                                                
         LW,R8    SDMMC,R6          REMOVE 'DS'                                 
         AND,R8   XSDNDS                                                        
         STW,R8   SDMMC,R6                                                      
         LI,R8    0                 ZERO AST NOW, DONE                          
         STW,R8   MMAST                                                         
MMRIN6   LH,R8    *R6,R1            SET THE SEGMENT STATE TO                    
         AND,R8   XSDSTMSK              ACTIVE                                  
         AI,R8    SDSTATE3                                                      
         STH,R8   *R6,R1                                                        
MMRIN7   LI,R1    SDTACT            INCREMENT ACTIVE TASK                       
         MTB,1    *R6,R1                                                        
         OR,R6    XASTAFA               SET ACTIVE AND FIRST                    
         AND,R6   XASTNRD               ACTIVE ON IN AST                        
         STW,R6   *R12                  TURN OFF 'RD'                           
         LI,R1    SDNPCNT           OFFSET T REQUIRED PAGES                     
         LI,R0    0                                                             
         STB,R0   *R6,R1            CLEAR NEED FR MORE PAGES                    
         ENABLE                                                                 
         LW,R0    ECBPC,R2          TEST TYPE OF MEMORY REQUEST                 
         CI,R0    MMRECB3               TYPE 3'S ARE TO BE POSTED               
         BANZ     MMRINX2               EXIT +2                                 
         AND,R0   XMMNRE4               REMOVE 4 FROM MEM REQ                   
         STW,R0   ECBPC,R2              AND LOOK FOR MORE SEGS                  
         B        MMRIN0                WHICH NEED ROLL IN                      
MMRINX2  ENABLE                     EXIT +2                                     
         PULL     R8                                                            
         AI,R8    1                                                             
         B        OLAYEXIT                                                      
MMRIN8   CI,R15   TYCA4             TYC=REAL PAGES NOT AVAIL                    
         BNE      MMRICRSH              NO, ERROR                               
         LW,R8    SDMMC,R6          REMOVE 'DS' AND                             
         EOR,R8   XSDDS                 CHANGE THE STATE                        
         STW,R8   SDMMC,R6              BACK TO ROLLED OUT                      
         LI,R1    SDFLAGS                                                       
         LH,R8    *R6,R1                                                        
         AND,R8   XSDSTMSK                                                      
         AI,R8    SDSTATE5                                                      
         STH,R8   *R6,R1                                                        
MMRIN9   LW,R0    ECBFPT,R2         REMOVE IN-PROCESS                           
         AND,R0   XECBNINP                                                      
         STW,R0   ECBFPT,R2                                                     
MMRINX1  ENABLE                     EXIT +1                                     
         PULL     R8                                                            
         B        OLAYEXIT                                                      
MMRIN10  ENABLE                     WAIT FOR 'DS' TO GO AWAY                    
         LW,R0    STIPRIO+MMTID     RESET DSO FIELD FOR                         
         AND,R0   XSTINDSO           MMEXEC TASK.                               
         STW,R0   STIPRIO+MMTID                                                 
         LW,R0    R6                                                            
         AND,R0   M24                                                           
         OR,R0    XASTAFA                                                       
         STW,R0   MMAST                                                         
         BAL,R8   LOADMAP                                                       
         B        MMRIN0                                                        
         TITLE    '** MMO5 - SUBR, ABN MEMORY REQ ECBS  **'                     
*******************                                                             
*    MMABNM       *    ABNORMAL ECB SUBR, MM                                    
*******************                                                             
*                                                                               
* ENTRY  FROM EMWAIT ONLY AT TASK TERMINATION, DELFPT CAN NOT                   
*        OCCUR SINCE CALLER DOES NOT GET CONTROL BETWEEN                        
*        CREATION OF MMECBS AND POSTING                                         
* EXIT   PER ABNORMAL SUBR SPECS                                                
*                                                                               
MMABNM   PUSH     R8                SAVE EXIT                                   
         DISABLE                                                                
         LW,R0    ECBFPT,R2         FETCH ECB FLAGS                             
         CW,R0    XECBBUSY              POSTED                                  
         BAZ      MMABN0                YES                                     
         CW,R0    XECBINP               IN PROCESS                              
         BANZ     MMABN2                YES,                                    
         LW,R8    ECBRECB,R2            CHAINED TO MMEXEC                       
         BEZ      MMABN2                NO MUST BE IN POSTING                   
         LW,R0    LMIRECB+MMLMID    REMOVING CHAIN HEAD                         
         LW,R1    M24                                                           
         CS,R0    R2                                                            
         BNE      %+2                                                           
         MTW,1    ROLL99                                                        
         BAL,R8   EMRRECB           REMOVE FROM MMEXEC CHAIN                    
         B        MMABNMCR                                                      
MMABN0   ENABLE                                                                 
         BAL,R8   EMDELECB          DELETE THE ECB                              
         B        MMABNMCR              ERROR                                   
         ENABLE                                                                 
MMABN1   LI,R15   TYC100            SET DELETED/DETATCHED                       
         PULL     R8                                                            
         AI,R8    1                                                             
         B        OLAYEXIT                                                      
MMABN2   OR,R0    XECBDP            SET 'DP'                                    
         STW,R0   ECBFPT,R2                                                     
         DISABLE                                                                
         BAL,R8   EMRSECB           DETATCH FROM TASK                           
         B        MMABNMCR                                                      
         ENABLE                                                                 
         B        MMABN1                                                        
         TITLE    '** MMO5 - GET ROLL-OUT FILE SPACE **'                        
MMRFILE  PUSH     R8                                                            
         LW,R5    R6                SDADDRESS                                   
         AI,R5    SDFIXED           OFFSET TO ACI IMAGE                         
         LI,R1    SDACICNT                                                      
         LB,R1    *R6,R1            GET # OF ACI WORDS                          
         AW,R5    R1                YEILDS ADDRESS OF FLAG IMAGE                
         LB,R1    *R5               GET FIRST FLAG BYTE                         
         CI,R1    SDFSA             FILE SPACE ALLOCATED                        
         BAZ      MMRF02            B IF NO                                     
MMRF01   PULL     R8                NORMAL EXIT                                 
         AI,R8    1                                                             
         B        OLAYEXIT                                                      
*                                                                               
MMRF02   LI,R4    SDVPCNT           OFFSET TO VIRTUAL PAGE COUNT                
         LB,R4    *R6,R4            GET VIRTUAL PAGE COUNT                      
         AI,R4    3                 ROUND UP                                    
         SLS,R4   -2                YEILDS # OF WORDS IN FLAG IMAGE             
         AW,R4    R5                R4 NOW POINTS TO FILE IMAGE                 
         LI,R1    0                 INDEX                                       
         LI,R7    SDVPCNT           OFFSET TO VIRTUAL PAGE COUNT                
         LB,R9    *R6,R7            GET VIRTUAL PAGE COUNT                      
         LI,R10   SDFSA             FILE SPACE ALLOCATED BIT                    
MMRF03   BAL,R8   MMRGFS            GET FILE SPACE                              
         B        MMRF04            ERROR NO SPACE                              
         STH,R14  *R4,R1            SET SECTOR NUMBER                           
         LB,R0    *R5,R1            FLAG BYTE                                   
         OR,R0    R10               SET FILE SPACE ALLOCATED                    
         STB,R0   *R5,R1            SET IN SD                                   
         ENABLE                                                                 
         AI,R1    1                 BUMP INDEX                                  
         BDR,R9   MMRF03            B FOR NEXT PAGE                             
         B        MMRF01            B TO TAKE NORMAL EXIT                       
MMRF04   BAL,R8   MMRRFILE          RELEASE FILE SPACE                          
         PULL     R8                                                            
         B        OLAYEXIT          ERROR EXIT                                  
         TITLE    '** MMO5 - GET PAGE OF ROLL-OUT SPACE **'                     
*                 EXITS DISABLED                                                
*                 EXITS TO LINK+1 IF FILE EXTENT ACQUIRED                       
*                 EXITS TO LINK IF NO FILE SPACE                                
*                 EXITS WITH R14 SET TO STARTING SECTOR                         
*                      ADDRESS (RELATIVE TO CK AREA)                            
MMRGFS   EQU      %                                                             
         PUSH     5,R1                                                          
         LW,R2    MMRMAPLG          LENGTH OF BIT MAP IN WORDS                  
         STW,R2   MMRLOOP           SET LOOP COUNT                              
MMRGFS00 LW,R5    Y8                BIT FOR CHECKING MAP                        
         LI,R3    0                                                             
         DISABLE                                                                
         MTW,1    MMRGF:RE          RE-ENT COUNT                                
         LW,R0    MMRGF:RE          ESTABLISH RE-ENT COUNT                      
         LW,R2    MMRINDX           GET CURRENT POINTER                         
         CW,R2    MMRENDX           IS IT PAST END OF TABLE                     
         BL       MMRGFS01          B IF NO                                     
         LI,R2    0                 SET CURRENT INDEX TO ZERO                   
         STW,R2   MMRINDX           RESET CURRENT POINTER                       
MMRGFS01 EQU      %                                                             
         SLD,R2   -5                R2 = WORD INDEX R3 = BIT INDEX              
         SLS,R3   -27               POSITION BIT INDEX                          
         LCW,R3   R3                COMPLEMENT FOR RIGHT SHIFT                  
         SLS,R5   0,R3              POSITION SEARCH BIT                         
         AI,R3    32                YEILDS LOOP COUNT                           
         ENABLE                                                                 
         DISABLE                                                                
         CW,R0    MMRGF:RE          WERE WE REENTERED                           
         BE       MMRGFS03          B IF NO                                     
MMRGFS02 ENABLE                                                                 
         B        MMRGFS00          B TO START OVER                             
MMRGFS03 EQU      %                                                             
         CS,R5    MMROLMAP,R2        IS THIS EXTENT ALLOCATED                   
         BNE      MMRGFS04          B IF NOO                                    
         MTW,1    MMRINDX           BUMP CURRENT POINTER                        
         SLS,R5   -1                MOVE SEARCH BIT                             
         BDR,R3   MMRGFS03          CHENK NEXT EXTENT                           
         ENABLE                                                                 
         MTW,-1   MMRLOOP           LHENCK LOOP COUNT                           
         BGZ      MMRGFS00          B FOR MORE                                  
         PULL     5,R1              NO FILE SPACE EXIT                          
         B        *R8                                                           
MMRGFS04 EQU      %                                                             
         STS,R5   MMROLMAP,R2       SET MAP BIT ON (EXTENT USED)                
         LCW,R3   R3                                                            
         AI,R3    32                YEILDS BIT OFFSET                           
         SLS,R2   5                 TIMES 32                                    
         AW,R3    R2                                                            
         LI,R2    1                                                             
         MH,R3    MMROLTAB,R2       TIMES # OF SECTORS PER PAGE                 
         STW,R3   R14               FOR EXIT PARAMETER                          
         PULL      5,R1                                                         
         AI,R8    1                                                             
         B        *R8               NORMAL EXIT                                 
         TITLE    '** MMO5 - RELEASE ROLL-OUT FILE SPACE **'                    
MMRRFILE EQU      %                                                             
         PUSH     8,R1                                                          
         LW,R5    R6                SD ADDRESS                                  
         AI,R5    SDFIXED           OFFSET TO ACI IMAGE                         
         LI,R1    SDACICNT          OFFSET TO ACI COUNT                         
         LB,R1    *R6,R1            GET # OF ACI WORDS                          
         AW,R5    R1                YEILDS ADDRESS OF FLAG IMAGE                
         LI,R4    SDVPCNT           OFFST TO VIRTUAL PAGE COUNT                 
         LB,R4    *R6,R4            GET VIRTUAL PAGE COUNT                      
         LW,R3    R4                SAVE FOR LOOP COUNT                         
         AI,R4    3                 ROUND UP                                    
         SLS,R4   -2                YEILDS # OF WORDS IN FLAG IMAGE             
         AW,R4    R5                YEILDS ADDRESS OF FILE IMAGE                
         LI,R2    0                 LOOP INDEX                                  
*                                   R2 HAS LOOP INDEX                           
*                                   R3 HAS LOOP COUNT                           
*                                   R4 HAS POINTER TO FILE IMAGE                
*                                   R5 HAS POINTER TO FLAG IMAGE                
*                                   R6 HAS POINTER TO SD                        
MMRRFS01 EQU      %                                                             
         DISABLE                                                                
         LB,R0    *R5,R2            GET FLAG BYTE                               
         CI,R0    SDFSA             DOES THIS PAGE HAVE A FILE EXTENT           
         BAZ      MMRRFS02          B IF NO                                     
         LH,R14   *R4,R2            GET STARTING SECTOR #                       
         BAL,R8   MMRRFS            RELEASE ONE EXTENT                          
         EOR,R0   XSDFSA            RESET FILE SPACE FLAG                       
         STB,R0   *R5,R2            RESTORE IN SD                               
MMRRFS02 EQU      %                                                             
         ENABLE                                                                 
         AI,R2    1                 MOVE TO NEXT PAGE                           
         BDR,R3   MMRRFS01          B FOR NEXT PAGE                             
         LW,R0    MMRMAPLG          GET LEGTH OF MAP TABLE                      
         STW,R0   MMRLOOP           SET FOR GET EXTENT ROUTINE                  
         PULL     8,R1                                                          
         B        OLAYEXIT          EXIT                                        
*                                                                               
*                                                                               
MMRRFS   EQU      %                                                             
         PUSH     4,R0                                                          
         LI,R1    1                 OFFSET TO #SECTORS PER PAGE                 
         DH,R14   MMROLTAB,R1       GIVES EXTENT #                              
         LW,R2    R14                                                           
         SCD,R2   -5                RE HAS WORD INDEX                           
         SLS,R3   -27               R3 HAS BIT INDEX                            
         LW,R1    Y8                BIT FOR MAP FLAG                            
         LCW,R3   R3                FOR RIGHT SHIFT                             
         SLS,R1   0,R3              POSITION BIT                                
         LI,R0    0                 FOR STORING ZERO BIT                        
         STS,R0   MMROLMAP,R2       RESET BIT FLAG                              
         PULL     4,R0              RESTORE REGS                                
         B        *R8               EXIT                                        
         TITLE    '** MMO5 - MMRREAD ROUTINE **'                                
***************                                                                 
*   MMRREAD   *                                                                 
***************                                                                 
*                                                                               
*   ROUTINE READS THE SPECIFIED SEGMENT FROM THE RAD                            
*   ROUTINE RETURNS +2 NORMALLY, +1 OTHERWISE (R15=TYC)                         
*                                                                               
*   ROUTINE SAVES R6,R8                                                         
*                                                                               
*   AT ENTRY:     R6    SEGMENT DESCRIPTOR                                      
*                 R8    LINK                                                    
*                                                                               
*                                                                               
MMRREAD  RES      0                                                             
         PUSH     R8                SAVE LINK                                   
         BAL,R5   MMRRWS1           GET ADDRESSES OF TABLES                     
MMRR1    RES      0                                                             
         LI,R13   0                 SET SUM OF PAGES= 0                         
         LB,R9    *R2,R1            GET FLAGS ENTRY FOR THIS PAGE               
         CI,R9    SDROL             IS ROL SET                                  
         BANZ     MMRR2             YES,  BRANCH                                
         AI,R1    1                 INCREMENT INDEX                             
MMRR1B   CW,R1    R0                NO, ARE WE DONE                             
         BLE      MMRR1             NOT DONE                                    
         PULL     R8                DONE                                        
         AI,R8    1                                                             
         B        OLAYEXIT          NORMAL EXIT (+2)                            
*                                                                               
*                                                                               
*                                                                               
MMRR2    RES      0                                                             
         CI,R9    SDRPP             IS REAL PAGE PRESENT                        
         BAZ      MMRRER            NOT PRESENT, ERROR                          
         LW,R10   R1                PRESENT, SAVE CURRENT INDEX                 
         LH,R14   *R3,R1            GET RELATIVE RAD ADDR                       
         AND,R14  M16               MASK                                        
         LW,R8    R14               MOVE TO R8                                  
MMRR3    RES      0                                                             
         AI,R13   1                 INCR NO OF PAGES TO READ                    
         AI,R1    1                 INCREMENT RELATIVE PAGE NR                  
         MTH,0    MMROLTAB                                                      
         BNEZ     MMRR4             B IF SECTOR SIZE DOES NOT EVENLY            
*                                   DIVIDE PAGE SIZE.  MUST READ PAGE           
*                                   BY PAGE.  OTHERWISE, TRY TO READ            
*                                   A CONTIGUOUS BLOCK OF PAGES                 
         CW,R1    R0                IS THIS LAST PAGE+1                         
         BG       MMRR4             YES. READ ACCUMULATED PAGES                 
         LW,R9    R8                SAVE CURRENT PAGE DISK ADDR                 
*   CHECK TO SEE IF THE NEXT PAGE IS TO BE READ                                 
         LB,R5    *R2,R1            GET FLAGS ENTRY                             
         CI,R5    SDROL             IS IT ROLLED OUT                            
         BAZ      MMRR4             NO, READ UP TO THIS PAGE                    
         CI,R5    SDRPP             IS REAL PAGE PRESENT                        
         BAZ      MMRRER            NO, ERROR                                   
*   CHECK TO SEE IF THIS PAGE IS CONTIGUOUS ON THE                              
*   RAD WITH THE PREVIOUS PAGE.                                                 
         LH,R8    *R3,R1            RELATIVE RAD ADDR.                          
         AND,R8   M16               MASK                                        
         AW,R9    R15               ADD NO OF SECTORS PER PAGE                  
         CW,R9    R8                COMPARE TO CURRENT SECT. NO.                
         BE       MMRR3             CONTIGUOUS, GET NEXT                        
*                                                                               
*   RAD OR CORE NOT CONTIGUOUS, NOW READ.                                       
MMRR4    RES      0                                                             
*   R13= NO OF PAGES TO READ                                                    
*   R14= RELATIVE SECTOR TO START READING                                       
*   R10= INDEX OF VIRTUAL PAGE TO START READING INTO                            
         CI,R13   0                                                             
         BE       MMRR1B            B IF NOTHING TO READ                        
         LW,R8    R10               SAVE FIRST PAGE NR                          
         LI,R4    FCRRAD            'READ' FUNCTION CODE                        
         BAL,R5   MMRRWS2           DO THE READ                                 
         B        MMRRER            ERROR, TAKE ERROR EXIT                      
         XW,R1    R8                EXCHANGE FIRST AND LAST PAGE NRS            
         LI,R4    X'F7'             ALL BITS EXCEPT SDROL                       
MMRR4A   RES      0                                                             
         LB,R5    *R2,R1            GET PAGE FLAGS                              
         AND,R5   R4                RESET ROLLED OUT FLAG                       
         STB,R5   *R2,R1                                                        
         AI,R1    1                 POINT TO NEXT PAGE                          
         CW,R1    R8                                                            
         BL       MMRR4A            B IF THIS PAGE WAS JUST READ                
         B        MMRR1B            CONTINUE                                    
*                                                                               
*                                                                               
*   ERROR EXIT FROM MMRREAD SUBROUTINE                                          
MMRRER   RES      0                                                             
         PULL     R8                RESTORE LINK                                
         B        OLAYEXIT          ERROR EXIT (+1)                             
         TITLE    '** MMO5 - MMRWRITE ROUTINE **'                               
****************                                                                
*   MMRWRITE   *                                                                
****************                                                                
*                                                                               
*   ROUTINE WRITES THE SPECIFIED SEGMENT TO THE RAD.                            
*   ROUTINE RETURNS +2 NORMALLY, +1 OTHERWISE                                   
*                                                                               
*   ROUTINE SAVES R6,R8                                                         
*                                                                               
*   AT ENTRY:     R6   SEGMENT DESCRIPTOR ADDRESS                               
*                 R8   LINK                                                     
*                                                                               
*                                                                               
MMRWRITE RES      0                                                             
         PUSH     R8                SAVE LINK                                   
         BAL,R5   MMRRWS1           GET ADDRESSES OF TABLES                     
MMRW1    RES      0                                                             
         LI,R13   0                 SUM OF PAGES= 0                             
         LB,R9    *R2,R1            GET FLAGS ENTRY FOR THIS PAGE               
         CI,R9    SDRPP             IS REAL PAGE PRESENT                        
         BAZ      MMRW2             NO, BRANCH                                  
         CI,R9    SDROL             YES, IS IT ROLLED OUT                       
         BANZ     MMRW2             YES. SKIP IT                                
         LW,R5    0,R6              NO, GET MAP IMAGE ADDRESS                   
         DO       #SIGMA9M                                                      
         LH,R5    *R5,R1            GET REAL PAGE NR                            
         ELSE     #SIGMA9M                                                      
         LB,R5    *R5,R1            GET REAL PAGE NR                            
         FIN      #SIGMA9M                                                      
         MTB,0    IOLOCK,R5                                                     
         BEZ      MMRW4             B IF PAGE NOT I/O LOCKED                    
MMRW2    RES      0                                                             
         AI,R1    1                 INCREMENT TABLES INDEX                      
MMRW3    RES      0                                                             
         CW,R1    R0                COMPARE INDEX TO MAX                        
         BLE      MMRW1             NOT DONE                                    
         PULL     R8                RESTORE LINK                                
         AI,R8    1                                                             
         B        OLAYEXIT          NORMAL EXIT                                 
*                                                                               
*                                                                               
*                                                                               
MMRW4    RES      0                                                             
         LW,R10   R1                SAVE INDEX TO VIRTUAL PAGE                  
         LH,R14   *R3,R1            GET RELATIVE RAD ADDR                       
         AND,R14  M16               MASK                                        
         LW,R8    R14               MOVE TO R8                                  
MMRW5    RES      0                                                             
         LW,R5    0,R6              GET MAP IMAGE ADDRESS                       
         DO       #SIGMA9M                                                      
         LH,R5    *R5,R1            GET REAL PAGE NR                            
         ELSE     #SIGMA9M                                                      
         LB,R5    *R5,R1            GET REAL PAGE NR                            
         FIN      #SIGMA9M                                                      
         MTB,0    IOLOCK,R5                                                     
         BNEZ     MMRW6             B IF PAGE IS IO LOCKED.                     
*        IO LOCKED PAGES MAY BE WRITTEN OUT IN ORDER TO                         
*        AVOID BREAKING A ROLLOUT TRANSFER.  THIS SPEEDS UP                     
*        THE ROLLOUT, SINCE BREAKING AN OTHERWISE CONTINUOUS                    
*        TRANSFER LOSES A DISK REVOLUTION.  THE IO LOCKED PAGE                  
*        IS NOT MARKED AS ROLLED, HOWEVER, SO IT WILL NOT BE                    
*        ROLLED BACK IN LATER.                                                  
         LB,R5    *R2,R1            GET PAGE FLAGS                              
         OR,R5    XSDROL            SET ROLLED FLAG                             
         STB,R5   *R2,R1            PUT FLAGS BACK                              
MMRW6    RES      0                                                             
         AI,R13   1                 INCREMENT NR OF PAGES TO WRITE              
         AI,R1    1                 INCREMENT RELATIVE PAGE NR                  
         MTH,0    MMROLTAB                                                      
         BNEZ     MMRW7             B IF SECTOR SIZE DOES NOT EVENLY            
*                                   DIVIDE PAGE SIZE.  MUST WRITE PAGE          
*                                   BY PAGE.  OTHERWISE, TRY TO WRITE           
*                                   A CONTIGUOUS BLOCK OF PAGES                 
         CW,R1    R0                                                            
         BG       MMRW7             B IF PAST LAST PAGE                         
         LW,R9    R8                SAVE CURRENT PAGE DISK ADDR                 
*   CHECK TO SEE IF THE NEXT PAGE IS TO BE WRITTEN                              
         LB,R5    *R2,R1            GET NEXT FLAGS ENTRY                        
         CI,R5    SDRPP             IS REAL PAGE PRESENT                        
         BAZ      MMRW7             NO, WRITE PAGES TO NOW                      
         CI,R5    SDROL             YES, IS PAGE ROLLED OUT                     
         BANZ     MMRW7             YES, GO TO WRITE                            
*   CHECK TO SEE IF THIS PAGE IS CONTIGUOUS WITH                                
*   PREVIOUS PAGE ON RAD.                                                       
         LH,R8    *R3,R1            GET REL RAD ADDR                            
         AND,R8   M16                                                           
         AW,R9    R15               ADD NO OF SECTORS PER PAGE                  
         CW,R9    R8                COMPARE TO CURRENT SECTOR                   
         BE       MMRW5             CONTIGUOUS, BRANCH                          
MMRW7    RES      0                 WRITE                                       
         CI,R13   0                                                             
         BE       MMRW3             B IF NOTHING TO WRITE                       
         LI,R4    FCWRAD            FUNCTION CODE FOR WRITE                     
         BAL,R5   MMRRWS2           GO TO READ/WRITE SUBR.                      
         B        MMRWER            ERROR IN I/O                                
         B        MMRW3             CONTINUE                                    
*                                                                               
*                                                                               
*   ERROR EXIT FROM MMRWRITE ROUTINE                                            
MMRWER   RES      0                                                             
         PULL     R8                RESTORE LINK                                
         B        OLAYEXIT          ERROR RETURN (+1)                           
         PAGE                                                                   
*                                                                               
*   SUBROUTINE TO GET ADDRESSES                                                 
*                                                                               
MMRRWS1  RES      0                                                             
*   GET NO. OF SECTORS PER PAGE                                                 
         LI,R1    1                                                             
         LH,R15   MMROLTAB,R1       GET NR SECTORS PER PAGE                     
*   GET NO OF VIRTUAL PAGES IN THE SEGMENT IN R0                                
         LI,R1    SDVPCNT                                                       
         LB,R0    *R6,R1            NO OF VIRTUAL PAGES IN SEG.                 
         AI,R0    -1                LAST VALID INDEX                            
*   GET ADDRESS OF FLAGS IMAGE TABLE IN R2                                      
         LI,R1    SDACICNT                                                      
         LB,R2    *R6,R1            ACI COUNT                                   
         AW,R2    R6                                                            
         AI,R2    SDACCIMG          ADDR OF FLAGS IMAGE TABLE                   
*   GET ADDRESS OF FILE IMAGE TABLE IN R3                                       
         LW,R3    R0                                                            
         SLS,R3   -2                                                            
         AI,R3    1                 R3=NO OF WORDS IN FLAGS TABLE               
         AW,R3    R2                ADDRESS OF FLAGS IMAGE TABLE                
*   INITIALIZE INDEX INTO TABLES                                                
         LI,R1    0                                                             
         B        0,R5              RETURN                                      
         PAGE                                                                   
*                                                                               
*   SUBROUTINE USED BY MMRREAD AND MMRWRITE TO READ/WRITE                       
*                                                                               
*   AT ENTRY:     R4   FUNCION CODE                                             
*                 R10  INDEX OF PAGE TO START I/O FROM                          
*                 R13  NO. OF PAGES TO READ/WRITE                               
*                 R14  RELATIVE SECTOR TO BEGIN READ/WRITE                      
*                                                                               
MMRRWS2  RES      0                                                             
         LW,R12   R13               NO OF PAGES TO READ/WRITE                   
         AND,R12  M5                R12= REMAINING PAGES                        
         SLS,R13  -5                DIVIDE BY MAX PAGES PER I/0                 
*   R13= NO. OF TIMES TO WRITE 32 PAGES                                         
*   R12= NO. OF PAGES TO WRITE THE LAST TIME                                    
MMRRWS2A RES      0                                                             
         AI,R13   -1                DECREMENT LOOP COUNTER                      
         BLZ      MMRRWS2B          OUTPUT THE REMAINDER                        
         LI,R11   16384*4           SET MAX BYTE COUNT                          
         B        MMRRWS2C                                                      
MMRRWS2B CI,R12   0                                                             
         BE       1,R5              DONE, EXIT                                  
         SLS,R12  11                CONVERT PAGES TO BYTES                      
         LW,R11   R12               MOVE BYTE COUNT TO R11                      
         LI,R12   0                 SET REMAINDER = 0                           
MMRRWS2C RES      0                                                             
*   BUILD CALL TO CALLQ                                                         
         PUSH     16,R0                                                         
         LW,R1    SDMMCCS,R6            R1=VIRTUAL BASE ADDR                    
         SLS,R1   -9                    R1=VIRTUAL BASE PAGE                    
         AND,R1   M8                    REMOVE HIGH ORDER BITS                  
         AW,R10   R1                ADD CURRENT INDEX WHICH                     
*                                    GIVES PAGE TO START I/0.                   
         SLS,R10  11                CONVERT TO BYTE ADDRESS                     
         LI,R1    CKINDEX           AREA INDEX FOR CK                           
         LI,R6    CKINDEX           SET INDEX FOR CK AREA                       
         BAL,R5   CVTAREA           GET SEEK ADDR IN R12, R7 = DCT INDX         
         B        MMRRWS2E            RETURN ERROR                              
*                                                                               
         LI,R15   -1                FLAG FOR NO REENTRANCE CHECK                
         LW,R8    CUPCOD4           CLEANUP CODE                                
         BAL,R5   CALLQ             DO THE I/O                                  
         B        MMRRWS2D          ERROR, R6 = ERROR CODE                      
         PULL     16,R0                                                         
         SLS,R15  5                 # SECTORS PER 32 PAGES                      
         AW,R14   R15               R14=NEW REL. RAD ADDR                       
         SLS,R15  -5                SHIFT BACK                                  
         AI,R10   32                R10=NEW RELATIVE PAGE                       
         B        MMRRWS2A          DO NEXT WRITE                               
*                                                                               
*                                                                               
*   ERROR PROCESSOR FOR 'CVTAREA'                                               
MMRRWS2E RES      0                                                             
         LW,R6    R15               COPY TYC FOR FOLLOWING CODE                 
*                                                                               
*   ERROR RETURN FROM CALLQ                                                     
MMRRWS2D RES      0                                                             
         DISABLE                                                                
         STW,R6   TEMP                                                          
         PULL     16,R0             RESTORE REGS                                
         LW,R15   TEMP              ERROR CODE TO R15                           
         ENABLE                                                                 
         B        0,R5              ERROR RETURN                                
OLAYEXIT EQU      %                                                             
MMO5EXIT B        *R8               COMMON EXIT                                 
         OLAYEND                                                                
         END                                                                    
