*M*      SEGLD    M:SEGLD CAL PROCESSOR
*P*
*P*      NAME:    SEGLD
*P*
*P*      PURPOSE: TO PROCESS THE M:SEGLD CAL.
*P*
*P*      DESCRIPTION:  THE M:SEGLD CAL CAUSES A SPECIFIED OVERLAY TO
*P*               BE LOADED INTO CORE STORAGE.  BOTH THE DATA AND
*P*               PROCEDURE SECTIONS OF THE SEGMENT ARE BROUGHT IN
*P*               UNLESS THEY ALREADY RESIDE IN CORE.
*P*
*P*               SEGLD IS INCLUDED IN THE MISOV OVERLAY.  THE OVERLAY
*P*               IS CALLED FROM ALTCP.
*P*
*P*               THE CODE IN SEGLD IS EXECUTED MAPPED AND IN THE
*P*               MASTER MODE.
*P*
         PAGE
SEGLD:   EQU      %
BITS     SET      1                 GET DEFINITIONS OF XN,YN,MN.
UFLAGS   SET      1
         SYSTEM   UTS
*
*
         DEF      SEGLD:            FOR PATCHING PURPOSES
         DEF      SEGLD             MODULE ENTRY POINT
*
*
*
*        MODULE REFS
*
         REF      DEBUGSEG          FOR OVERLAY SNAPS AND MODIFIES
         REF      DELTAGO           CURRENTLY UNUSED
         REF      FPMC              TO INSURE FULL MEMORY ALLOCATION
         REF      J:ASSIGN          FOR PPSWAP, BUF LIMIT CHECKS AND
*,*                                  DEBUG FILE
         REF      J:DCBLINK         POINTS TO DCB NAME TABLE.
         REF      J:DLL             VP# OF FIRST DATA PAGE
         REF      J:PLL             VP# OF FIRST PROCEDURE PAGE
         REF      J:PUL             VP# OF LAST PROCEDURE PAGE
         REF      J:RNST            RUN STATUS
         REF      J:TREE            WORD ADDR OF THE TREE TABLE
         REF      JB:LMAP           USER'S VIRTUAL PAGE CHAIN
         REF      JB:PCP            # OF PAGES OF PROCEDURE
         REF      JX:CMAP           USER'S PHYSICAL PAGE MAP
         REF      MSRRDWT           TO READ THE OVERLAY SEGMENT
         REF      OPNSEG            TO OPEN M:SGLD DCB TO THE LOAD MODULE
         REF      S:CUN             CURRENT USER'S #
         REF      SPPBASE           CURRENTLY UNUSED
         REF      T:ABORTM          TO GIVE USER B5-XX ERR MSG
         REF      T:GNVPI           TO GET PAGES NEEDED BY OVERLAY
         REF      T:RVPI            TO RELEASE PAGES NOT NEEDED BY OVERLAY
         REF      TRAPEXIT          SEGLD EXIT
         REF      UH:FLG            TO SET PPSWAP FLAG
         REF      XN2               MASK
         REF      YC                MASK
         REF      YFFF              MASK
         REF      Y6                MASK
         PAGE
*                 SYMBOLIC REGISTER DEFINITIONS.
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
SR1      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
         PAGE
*                 IMMEDIATE CONSTANTS USED BY MONITOR.
K0       EQU      0
K1       EQU      1
K2       EQU      2
K3       EQU      3
K4       EQU      4
K5       EQU      5
KA       EQU      10
KB       EQU      11
KF       EQU      15
         PAGE
TREEBAD  EQU      1
CIRCTREE EQU      2
BIGD     EQU      3
BIGP     EQU      4
BADB     EQU      5
SANSPAGE EQU      6
SADPAGE  EQU      7
K11      DATA,2   11,0
SGLDCB   GEN,8,24 S:NUMC('M:SGLD')+1,BA(%+1)  USED BY CBS INSTRUCTION
         TEXTC    'M:SGLD'            TO LOOK FOR M:SGLD DCB NAME.
         PAGE
*F*
*F*      NAME:    SEGLD
*F*
*F*      PURPOSE: TO LOAD AN OVERLAY SEGMENT FOR A NON-SHARED PROGRAM.
*F*
*F*      DESCRIPTION:  IF THE M:SGLD DCB IS CLOSED, IT IS OPENED.  THE
*F*               TREE TABLE IS SEARCHED FOR THE REQUESTED SEGMENT.  IF
*F*               NOT FOUND THE USER IS ABORTED.
*F*
*F*               IF THE SEGMENT IS FOUND, AND NOT IN CORE, MEMORY IS
*F*               ALLOCATED FOR THE SEGMENT AND ITS BACKWARD PATH, WHICH
*F*               IS THEN READ INTO CORE.
*F*
*D*      NAME:    SEGLD
*D*
*D*      CALL:    OVERTO MISOV,SEGLD#
*D*                   ENTERED FROM ALTCP
*D*
*D*      INPUT:   R6= FPT WORD 0. (Y008 SET IF REPL. INSTRUCTION)
*D*               R7=> FPT WORD 1.
*D*               SR2=> SEGMENT NAME TEXTC.
*D*
*D*      DESCRIPTION:  THE DCB TABLE IS SEARCHED FOR THE M:SGLD DCB.
*D*               IF NOT FOUND, THE PROGRAM IS NOT OVERLAID AND CONTROL
*D*               RETURNS TO THE USER.
*D*
SEGLD    EQU      %
         LI,R3    J:DCBLINK
FNDNAM2  LW,R3    0,R3                ANY (MORE) DCBS...
         BEZ      MSEGLDEX          --->NO. MUST NOT BE OVERLAID.
FNDNAM3  AI,R3    1                 R3=>DCB NAME.
BA@R3    LB,R1    *R3
         BEZ      FNDNAM2           --->NOT NAME; LINK OR END.
         ANLZ,R4  BA@R3             R4= BA(DCB NAME)
         SLS,R1   -2
         AW,R3    R1
         AI,R3    1                 R3=>DCB ADDR.
         LW,R5    SGLDCB
         CBS,R4   0                   IS THIS M:SGLD DCB...
         BNE      FNDNAM3           --->NO.
*                                   YES. R3=>M:SGLD ADDRESS.
         PUSH     2,R6                SAVE FPTW0, =>FPTW1.
         LI,10    0                 INITIALIZE SEG COUNT
         PUSH     2,9               MAKE HOLE IN STACK FOR:
*                                    # OF SEGMENTS
*                                    LAST PROC. PG / LAST DATA PAGE
*D*
*D*               IF M:SGLD IS CLOSED, IT IS OPENED.  IF ANY ERROR
*D*               SHOULD OCCUR ON THE OPEN, THE USER IS ABORTED WITH
*D*               ERROR CODE B1-00.
*D*                        R3=>SGLDADDR, SR2=>SEGNAME, 4 REGS PUSHED.
         LW,R6    0,R3              R6= M:SGLD DCB ADDRESS.
         LW,R1    Y002
         CW,R1    0,R6
         BANZ     NOOPN
         LW,R7    TSTACK
         AI,R7    1                 R7=>M:OPEN FPT +1.
         LCI      6                   NOTE: STAKTOP IS WORD OF ZERO.
         LM,D4    OPN                 COPY M:OPEN FPT TO
         PSM,D4   TSTACK              STACK.
         LI,SR1   X'14'             SR1= M:OPEN FPT CODE.
         OVERLAY  OPNSEG,0
         BUMP     -6,D4               CLEAR FPT OUT OF STACK.
         LB,SR3   SR3                 DID THE OPEN SUCCEED...
         BNEZ     EREXIT            *****>NO. ERROR.
NOOPN    EQU      %
*D*
*D*               A CHECK IS MADE TO DETERMINE IF THE TREE IS ALL
*D*               WITHIN THE PROCEDURE PART OF THE USER'S CORE.
*D*                                 SR2=>SEGNAME. 4 REGS PUSHED.
         LW,R2    J:TREE
         AW,R2    0,R2
         SLS,R2   -9                R2= PAGE# OF END OF TREE.
TREELOOP CLM,R2   J:PLL               SEE IF TREE IS IN PROCEDURE.
         BCS,9    BADTREE           *****> NO. ERROR.
         BE       TREEOK            --->ALL OK; DOWN TO PP START.
         LB,R3    JB:LMAP,R2
         BDR,R3   %+2               ---> 00/01 (NONE OR SADPAGE)
         B        BADTREE           *****> ARE ILLEGAL IN TREE.
         BDR,R2   TREELOOP          --->CHECK ALL TREE PAGES.
*E*      ERROR:   B1-01
*E*      MESSAGE: TREE RECORD IS INCOMPLETE
TREEOK   EQU      %
*D*
*D*               THE TREE TABLE IS SEARCHED FOR SEGMENTS IN CORE, AS
*D*               INDICATED BY BIT 0 OF WORD 3 SET IN THE SEGMENT TREE
*D*               ENTRY.  BIT 0 IS RESET, INDICATING OUT OF CORE, BUT
*D*               BIT 1 IS SET.  AS A RESULT ALL SEGMENTS IN THE TREE
*D*               TABLE ARE MARKED AS BEING OUT OF CORE IN BIT 0, WHILE
*D*               A RECORD OF SEGMENTS ACTUALLY IN CORE IS KEPT IN BIT
*D*               1.  THIS PREVENTS HAVING TO RE-READ THE SEGMENTS
*D*               IN THE CASE THEY ARE NEEDED.
*D*
         LW,R1    J:TREE
         LW,R2    J:TREE
         AI,R1    K4                R1=> WORD3 OF 1ST TREE ENTRY.
         AW,R2    0,R2              R2= TREE END + 1.
MEMLOP   INT,D1   0,R1              BIT 0-3 -> CC   BITS 16-31 -> D2
         BCR,8    %+2               NOT IN CORE-RESET BOTH BITS 0 & 1
         OR,D2    Y4                IN CORE; RESET BIT 0 AND SET BIT 1
         STW,D2   0,R1
         AI,10    1                 COMPUTE #SEGS FOR CIRCTREE CHECKS
         AI,R1    11                PRINT TO NEXT SEGMENT
         CW,R1    R2                HAVE WE REACHED THE END OF THE TREE
         BL       MEMLOP            NO
         STW,10   *TSTACK           SAVE SEG COUNT ON TREE
         LW,R1    J:TREE
         AI,R1    K1
*D*
*D*               THE TREE IS SEARCHED FOR THE REQUESTED SEGMENT NAME.
*D*               IF NOT FOUND THE USER IS ABORTED WITH ERROR CODE
*D*               B1-00.
*D*
*                 R1 = 1ST ENTRY OF TREE
*                 R2 = TREE END + 1
KEYLOOP  AI,R1    KB
         CW,R1    R2
         BGE      EREXIT
         LB,R4    *R1
         CB,R4    *SR2
         BNE      KEYLOOP
         LB,D1    *R1,R4
         CB,D1    *SR2,R4
         BNE      KEYLOOP
         BDR,R4   %-3
         LW,SR2   R1                ADDRESS OF ENTRY IN TREE TABLE
*D*
*D*               IF THE SEGMENT IS FOUND, THAT SEGMENT (AND ALL ITS
*D*               FORWARD LINKS) IS CHECKED TO SEE IF IT WAS
*D*               PREVIOUSLY IN CORE (WORD 3, BIT 1 IS SET).  IF SO,
*D*               IT IS MARKED CURRENTLY IN CORE (WORD 3, BIT 0 SET).
*D*
         LW,D2    YC
         CW,D2    3,R1              IS REQ SEG IN CORE
         BAZ      CHKSEG            NO, NEITHER ARE SUBLINK
         LI,3     KA                TREE TABLE
         AI,1     -1
NXTBRNCH STS,D2   4,R1              MARK SEG IN
         BDR,10   %+2
         B        CIRCSEG           CIRCULAR TREE
         LH,R1    *R1,R3            FLINK
         BEZ      CHKSEG1           NONE LEFT
         BLZ      BADTREE
         AW,R1    J:TREE
         CW,1     2                 OFF THE END YET
         BGE      BADTREE           YES
         CW,D2    4,R1
         BANZ     NXTBRNCH
         LI,R3    9
         LH,1     *1,3              BACK LINK TO
         BLZ      BADTREE
         CW,1     2                 END OF TREE CHECK
         BGE      BADTREE           BAD LINK
         AW,R1    J:TREE
         AI,1     1                 POINT TO 1ST WORD OF TREE ENTRY
*D*
*D*               MEMSET0 IS CALLED TO INSURE FULL MEMORY ALLOCATION
*D*               FOR THE SEGMENT AND ALL ITS BACKWARD PATH.
*D*
CHKSEG   EQU      %
         LI,2     5                 SET UP DATA ALLOCATION
         LI,3     J:DLL             LIMITS DWD
         BAL,11   MEMSET0
         LI,2     7
         LI,3     J:PLL             NOW DO PROCEDURE
         BAL,11   MEMSET0
*D*
*D*               AT THIS POINT USER MEMORY IS ALLOCATED TO THE HIGHEST PG
*D*               OF DATA AND PP OF THE HIGHEST SEGMENT TO BE READ INTO
*D*               CORE (OR WHICH IS ALREADY IN).
*D*
*D*               THE SEGMENT IS MARKED IN CORE (BIT 0, WORD 3)
*D*
*                 R1 = WA(TREE TABLE FOR HIGHEST SEG THAT IS TO
*                               REMAIN IN CORE)
CHKSEG1  EQU      %
         LW,D2    Y8
         LW,R1    SR2
         STS,D2   3,R1              MARK IT IN
*D*
*D*               IF THE SEGMENT WAS NOT PREVIOUSLY IN CORE (BIT 1, WORD 3)
*D*               IT IS NOW READ VIA THE RDSEG  SUBROUTINE.
*D*
         INT,D2   3,R1              WAS IT PREVIOUSLY IN
         BCS,4    SEGIN
         LI,R1    K3
         BAL,SR4  RDSEG
         LI,R1    K5
         BAL,SR4  RDSEG
         LI,0     0
         LW,1     Y2
         STS,0    J:ASSIGN
*D*
*D*               THE BACKWARD LINK IS OBTAINED AND THE NEXT SEG IS READ IN.
*D*
SEGIN    LW,R1    SR2               RESTORE SEGMENT ADDRESS
         INT,D2   3,R1              GET BACKWARD LINK
         AI,D2    0                 IS THERE ONE
         BNE      NXTSEG            YES-READ IT IF NOT IN CORE
*D*
*D*               THE PURE PROCEDURE SWAP FLAG IS SET IN UH:FLG AND
*D*               CONTROL RETURNS TO THE USER VIA T:SELFDESTRUCT.
*D*
         PULL     4,R6
         LW,4     S:CUN
         LH,15    UH:FLG,4
         OR,15    X10               SET PPSWAP
         STH,15   UH:FLG,4
         CW,R6    Y008              IS THERE A REPLACED INSTRUCTION..
         BAZ      SEGLDX0           --->NO.
         AI,R7    -3
         OVERLAY  DEBUGSEG,1          YES. GO FIX IT UP.
         LW,4     S:CUN
         LH,15    UH:FLG,4
SEGLDX0  EQU      %
         CI,15    DELA              DELTA ASSOCIATED?
         BAZ      SEGLDX1           NO
*
         CI,15    TIC               BUT IF IT'S CMD PROC SEGLD-ING,
         BANZ     SEGLDX1           ---> DON'T GO TO DELTA.
         LW,1     TSTACK            BUMP THE USER ADDRESS
         AI,1     -17               IN TSTACK ENVIRONMENT
         AND,1    XN2               TO BE
         MTW,1    0,1               CALL+1.
         LI,10    SPPBASE+X'F'      R10= DELTA'S SEGLD ENTRY POINT.
         DESTRUCT DELTAGO         -----> GO TO DELTA.
SEGLDX1  EQU      %
MSEGLDEX DESTRUCT TRAPEXIT          --->RETURN IF NO DELTA.
*                                   *TSTACK = SEGMENT # COUNT
NXTSEG   LW,SR2   J:TREE
         AI,SR2   K1
         AW,SR2   D2
         MTW,-1   *TSTACK           COUNT SEGMENTS
         BGZ      CHKSEG1           NO LOOP YET
         B        CIRCSEG           TOO MANY
         PAGE
*F*
*F*      NAME:    RDSEG
*F*
*F*      PURPOSE: TO READ A SPECIFIED PROTECTION TYPE OF AN
*F*               OVERLAY SEGMENT INTO CORE.
*F*
*F*      DESCRIPTION:  A KEY TO READ THE SPECIFIED PROTECTION TYPE IS
*F*               BUILT IN THE SEGMENT ENTRY OF THE TREE RECORD. A READ
*F*               FPT IS BUILT IN TSTACK AND THE MSRRDWT ROUTINE IS
*F*               CALLED TO READ THE RECORD.
*F*
*F*               IF THERE ARE ENTRIES IN THE CLOBBER TABLE FOR THIS
*F*               SEGMENT THEY ARE MOVED FROM THE CLOBBER TABLE TO THE
*F*               USER'S PROGRAM.
*F*
*D*      NAME:    RDSEG
*D*
*D*      INPUT:   SR2 = WA(SEGMENT ENTRY IN TREE TABLE)
*D*               R1 = 3 TO READ DATA
*D*                  = 5 TO READ PROCEDURE
*D*
*D*      CALL:    BAL,SR4  RDSEG
*D*
*D*      DESCRIPTION:  A KEY TO READ THE REQUESTED PROTECTION TYPE
*D*               IS BUILT IN THE SEGMENT ENTRY OF THE TREE.
*D*
RDSEG    EQU      %
         MTB,1    *SR2
         LB,R2    *SR2
         STB,R1   *SR2,R2
*D*
*D*               IF THE BYTE COUNT IS ZERO THERE IS NOTHING TO READ
*D*               AND CONTROL RETURNS TO THE CALLING ROUTINE.
*D*
         AI,R1    2                 =5 IF DATA   =7 IF PROCEDURE
         LW,D3    *SR2,R1           SIZE/LOC WORD
         INT,D4   D3                D4 = DA(LOC)
         SLS,D3   -13               D3 = BYTE COUNT
         AND,D3   =X'7FFF8'
         BEZ      RDSEGX1           NOTHING TO READ
*D*
*D*               A CHECK IS MADE TO DETERMINE IF THE LIMIT SPECIFIED
*D*               IN THE TREE ENTRY FOR THIS SEGMENT IS WITHIN THE
*D*               OVERALL LIMITS SPECIFIED IN THE HEAD RECORD.  IF NOT
*D*               THE USER IS ABORTED WITH ERROR CODE B1-05.
*D*
         SLS,D4   1                 BUF ADDR
         LW,7     D4
         SLS,7    -9                FORM PAGE NUMBER
*
*                 *TSTACK-1   BITS 0-15 = LAST PROCEDURE PAGE
*                             BITS 16-31 = LAST DATA PAGE
*
*                 INDEX FOR DATA = -1       INDEX FOR PROCEDURE = -2
*
         AI,1     -3                =2 IF DATA   =4 IF PROCEDURE
         SLS,1    -1                =1 IF DATA   =2 IF PROCEDURE
         LCW,1    1
         CLM,7    J:DLL+2,1         J:DLL=J:PLL+2
         BCS,9    BADBUF            NO, ABORT HIM
*E*
*E*      ERROR:   B1-05
*E*      MESSAGE: BUFFER IS BAD IN THE SEGLD DCB
*E*
         LW,2     14                NOW CHECK END OF BUFFER
         AI,2     -1
         SLS,2    -2
         AW,2     15                LAST WORD OF BUFFER
         SLS,2    -9
         CH,2     *TSTACK,1         CHECK PAGE # TO BE IN USER
         BG       BADBUF
*E*
*E*      ERROR:   B1-05
*E*      MESSAGE: BUFFER IS BAD IN THE SEGLD DCB
*E*
*D*
*D*               A READ FPT IS BUILT IN THE REGISTERS AND PUSHED INTO
*D*               TSTACK.  THE MSRRDWT ROUTINE IN IORT IS CALLED TO READ
*D*               THE SPECIFIED RECORD.
*D*
         STH,7    2                 R2=LAST PAGE/FIRST PAGE
         XW,D3    D4
         PUSH     2
RD1      EQU      %
         PUSH     SR4
         LW,R7    TSTACK
         LI,SR1   16
         LW,D2    READ
         LW,R0    SR2
         LW,1     Y6
         STS,1    J:ASSIGN          SUPPRESS BUF LIMIT CHKS
         LI,R1    K0
         PUSH     7,D2
         BAL,SR4  MSRRDWT
         PULL     7,D2
         PULL     SR4
         LB,SR3   SR3
         BEZ      RD2
         CI,SR3   X'43'
         BE       RD4               NO SUCH KEY
         CI,SR3   X'07'
         BNE      EREXIT            LOOKS LIKE A SERIOUS ERROR
         B        RD2               IGNORE LOST DATA
RD4      MTB,0    2
         BNEZ     RD25              MISSING PAGED PAGE
         LH,7     2                 TRY PAGED TYPE; GET 1ST PAGE#
         LW,8     SR2
         AI,8     -1
         SW,8     J:TREE
         DH,8     K11               FORM ENTRY # OF SEGMENT
         CI,8     255
         BG       MANYSEG           TOO MANY PAGED SEGMENTS
         STH,8    7
         SH,2     2                 COMPUTE # OF RECORDS TO READ
         AI,2     1                 =END PAGE - START PAGE + 1
         SLS,2    24                SET FLAG AND CONUNTER
         MTB,3    7
         XW,7     *0
         PUSH     7
         LW,3     14                SAVE LAST PARTIAL SIZE
         SLS,3    2                 BA(START)
         AW,3     15                BA(END)
         AND,3    MASKS+11          DISP INTO PAGE
         BNEZ     RD1
         LI,3     X'800'            0 => FULL PAGE READ
         B        RD1
RD2      MTB,0    2
         BEZ      RD3               NOT AN 85 TYPE MODULE
         AI,2     X'100'            SET READ OCCURRED FLAG
RD25     MTW,1    *0                INC PG NR PORTION OF KEY
         STB,2    J:RNST            CLEAR ERROR FROM 43 ABN
         AI,D3    X'200'            INCR BUF
         AND,D3   =X'1FE00'
         LI,15    2048              SET BUFFER SIZE
         MTB,-1   2                 COUNT DOWN # PAGES TO READ
         LB,7     2                 IF LAST PAGE, USE PARTIAL BUFFER
         BDR,7    RD1               NOT LAST
         STW,3    15                SET LAST READ SIZE
         BGZ      RD1
         AI,2     0                 CHECK IF AT LEAST ONE READ.
         BLE      EREXIT            ERROR IF NOT.
         PULL     2
         STW,2    *0
*D*
*D*               IF THERE IS NO DEBUG PAGE (BUILT BY RUNNER) CONTROL
*D*               RETURNS TO THE CALLING ROUTINE.
*D*
RD3      EQU      %
         PULL     12                R12 = LAST PG/FIRST PAGE
         LI,2     X'10000'          IF NO DEBUG PAGE, WE ARE DONE.
         CW,2     J:ASSIGN
         BAZ      RDSEGX1
*D*
*D*               OTHERWISE, THE ADDRESS OF THE CLOBBER TABLE AND THE
*D*               NUMBER OF ENTRIES IN THE CLOBBER TABLE FOR THIS SEGMENNT
*D*               ARE OBTAINED FROM WORD 10 OF THE TREE TABLE ENTRY
*D*
         SLD,12   -16               MAKE DWD FOR CLM
         SLS,13   -16
         PUSH     3,5
*                 SR2 = ADDR OF SEG. ENTRY IN TREE
*                 WORD 10 OF SEG ENTRY IN TREE:
*                     BITS0-15 = # OF ENTRIES
*                     BITS 16-31 = ADDRESS OF 1ST ENTRY
         LW,7     YFFF
         LI,R2    10
         INT,R2   *SR2,R2           R2 = # OF ENTRIES IN CLOBBER TABLEE
*                                   R3 = DW(1ST ENTRY)
MODLOP   CI,R2    K0
         BLE      RDSEGX
         AI,R2    -2
*D*
*D*               THE CLOBBER TABLE ENTRY IS OBTAINED FROM THE
*D*               DEBUG PAGE.
*D*
         LD,D3    *R2,R3            D3 = LOCATION
*                                   D4 = MODIFY VALUE OR DEBUG CAL
         LI,6     X'1FFFF'          EXTRACT ADDRESS
         AND,6    D3                OF CHANGE
         SLS,6    -9                ITS PAGE #
         CLM,6    12                IS IT IN THIS RECORD (MAYBE)
         BCS,9    MODLOP            NO, JUST TRY NEXT ONE
*D*
*D*               IF IT IS A MODIFY ENTRY, THE DATA OR INSTRUCTION
*D*               IN THE USER'S PROGRAM IS SIMPLY REPLACED.
*D*
         LW,6     D4                MODIFY VALUE OR DEBUG CAL
         CS,6     DBCAL             IS IT DEBUG CAL
         BNE      MD4               NO-MODIFY-REPLACE INSTRUCTION
         CW,D4    *D3               HAS INST BEEN REPLACED
         BE       MODLOP            YES
*D*
*D*               IF IT IS DEBUG, THE DEBUG CAL REPLACES THE INSTRUCTION
*D*               IN THE USER'S PROGRAM AND THE REPLACED INSTRUCTION IS
*D*               PUT IN WORD 5 OF THE FPT.
*D*
         XW,D4    *D3               NO-SET DEBUG CAL; D4 = PREVIOUS INST.
         AND,6    M17               ADDRESS OF DEBUG FPT
MD3      AI,6     5                 ADDR FOR REPLACED INST. IN FPT
         LW,5     6                 CHECK THAT FPT IS IN DEBUG PAGE
         SLS,5    -9
         CW,5     J:PUL
         BNE      MODLOP
         STW,D4   0,6               REPLACED INST. TO FPT WORD 5
         LW,6     -5,6              WORD 0 OF FPT
         AND,6    M17               IS IT CHAINED
         BNEZ     MD3               YES-REPLACED INST. TO ALL OF CHAIN
         B        MODLOP            NO-GET NEXT ENTRY IN CLOBBER TABLE
MD4      EQU      %
         STW,D4   *D3               REPLACE IF MODIFY
         B        MODLOP
RDSEGX   EQU      %
         PULL     3,5
RDSEGX1  MTB,-1   *SR2              BECAUSE WE BUMPED IT TO BUILD KEY
         B        *SR4              EXIT
         PAGE
*F*
*F*      NAME:    MEMSET0
*F*
*F*      PURPOSE: TO INSURE FULL MEMORY ALLOCATION FOR THE SEGMENT AND
*F*               ALL ITS BACKWARD PATH.
*F*
*F*      DESCRIPTION:
*F*               ALL THE PAGES BETWEEN THE LOWER LIMIT AND THE LAST
*F*               PAGE IN THE SEGMENT ARE OBTAINED.
*F*
*F*               ALL THE PAGES FOLLOWING THE LAST PAGE OF THE SEGMENT
*F*               THROUGH THE UPPER LIMIT OF THE AREA ARE RELEASED.
*F*
*D*      NAME:    MEMSET0
*D*
*D*      CALL:    BAL,11            MEMSET0
*D*
*D*      INPUT:   R1 = WA(TREE TABLE ENTRY)
*D*               R2 = 5 (INDEX TO DATA SIZE/LOC WORD FOR SEGMENT)
*D*                           OR
*D*               R2 = 7 (INDEX TO PROCEDURE SIZE/LOC WORD FOR SEGMENT)
*D*
*D*               R3 = WA(J:DLL)  OR  WA(J:PLL)
*D*
*D*      OUTPUT:  *TSTACK-1   BITS 0-15 = LAST PROCEDURE PAGE
*D*                           BITS 16-31 = LAST DATA PAGE
*D*
*D*      DESCRIPTION:  THE LAST DATA/PROCEDURE PAGE IS STORED IN
*D*               *TSTACK-1.
*D*
MEMSET0  LW,12    *1,2              GET SIZE/LOC WORD FOR SEGMENT
         SLD,12   -16               R12 = DW SIZE
         SLS,13   -16               R13 = DA(LOCATION)
         AW,12    13                END ADDRESS
         AI,12    -1
         SLS,12   -8                END PAGE#
         CLM,12   *3                IS IT LEGAL
         BCS,9    BIG
*                 FORM INDEX TO STORE INTO TOP OF STACK
         AI,2     -3                =2 IF DATA     =4 IF PROCEDURE
         SLS,2    -1                =1 IF DATA     =2 IF PROCEDURE
         LCW,2    2                 =-1 IF DATA    =-2 IF PROCEDURE
         STH,12   *TSTACK,2
         LW,2     12                PUT END PAGE IN 2 FOR MEMSET
*
*                 R2 = END PAGE (FROM TREE)
*                 *R3 = J:DLL OR J:PLL
*                 *R3+1 = J:DUL OR J:PUL
*D*
*D*               ALL THE PAGES BETWEEN THE LOWER LIMIT AND THE LAST
*D*               PAGE IN THE SEGMENT ARE OBTAINED.
*D*
MEMSET   EQU      %
         PSW,11   TSTACK            SAVE RETURN
         LCI      2
         PSM,0    TSTACK
         PSW,6    TSTACK
         LW,7     Y2
         STS,7    J:ASSIGN          SET SWAP PP WHILE GETTING PAGES
         LI,6     1                 NUMBER OF PAGES FOR M
         LW,7     *3                LOWER LIMIT
         LI,1     0                 INDICATING GET OPERATION
         BAL,10   MEM1
*D*
*D*               ALL THE PAGES FOLLOWING THE LAST PAGE OF THE SEGMENT
*D*               THROUGH THE UPPER LIMIT OF THE AREA ARE RELEASED.
*D*
*                 NOTE THAT R7 HAS BUMPED SO NOW IS EQUAL TO THE
*                 FIRST PAGE FOLLOWING THE END OF THE SEGMENT.
*
         LI,1     1                 INDICATING RELEASE
         LW,2     *3,1              GET WHERE TO STOP
         LI,10    X'10000'
         CW,10    J:ASSIGN          IS THERE DEBUG PG
         BCR,4    %+4               NO PAGE
         CI,3     J:PLL             ARE WE DOING PROCEDURE
         BNE      %+2               NO, DEBUG PAGE IS IN PROCEDURE
         AI,2     -1                YES, DONT RELEASE IT
         CW,2     7                 BUMP OVER PAGE YET
         BL       MEMDONE           YEP, QUIT
         BAL,10   MEM1
MEMDONE  EQU      %
         LI,0     0
         LW,1     Y2
         STS,0    J:ASSIGN          RESET SWAP PP FLAG
         PLW,6    TSTACK
         LCI      2
         PLM,0    TSTACK
         PLW,11   TSTACK
         B        *11               RETURN
*
*                 R7 = 1ST PAGE TO GET/RELEASE
*                 R2 = LAST PAGE TO GET/RELEASE
*
MEM1     EQU      %
        LOAD,15 JX:CMAP,7
         CI,D4    FPMC              HAVE THE PAGE
         EXU      ACTION,1          IF GET, MUST NOT BE CVM PAGE
*                                   IF RELEASE, FPMC IS OK
         LCI      3
         PSM,1    TSTACK
         MTB,1    JB:PCP              TO PASS MM MAX PAGES TEST
         BAL,11   GETFREE,1         IF GET, T:GVNVPI
*                                   IF RELEASE, T:RVPI
         BCS,15   NOPAGE            DIDN'T DO OPERATION
         LCI      3
         PLM,1    TSTACK            RESTORE
         MTB,-1   JB:PCP            RESET COUNT
MEM2     EQU      %
         AI,7     1
         CW,7     2                 FINISHED
         BLE      MEM1              NO
         B        *10               YES, RETURN
*
*
ACTION   BNE      CHKSAD
         BE       MEM2
*
GETFREE  B        T:GNVPI
         B        T:RVPI
*
*
*
CHKSAD   EQU      %
         LB,D4    JB:LMAP,7         GOT WITH SAD CAL
         CI,D4    1
         BNE      MEM2              NO, ALL OK
         LI,14    SADPAGE
         B        ABORTIT
*E*
*E*      ERROR:   B1-07
*E*      MESSAGE: PAGE ACQUIRED BY CVM ENCOUNTERED
*E*
         PAGE
*
*        SEGLD ERROR EXITS
*
MANYSEG  LI,14    8
         B        ABORTIT           TOO MANY PAGED SEGMENTS
*E*
*E*      ERROR:   B1-08
*E*      MESSAGE: PAGED LOAD MODULE GREATER THAN 255 SEGMENTS
*E*
NOPAGE   EQU      %
         MTB,-1   JB:PCP            RESET COUNT
         LI,14    SANSPAGE
         B        ABORTIT
*E*
*E*      ERROR:   B1-06
*E*      MESSAGE: OUT OF PHYSICAL PAGES
*E*
CIRCSEG  EQU      %
         LI,14    CIRCTREE
         B        ABORTIT
*E*
*E*      ERROR:   B1-02
*E*      MESSAGE: TREE RECORD IS CIRCULAR
*E*
BIG      EQU      %
         LI,14    BIGP
         CI,3     J:PLL             IS THIS RIGHT
         BE       ABORTIT           YES
*E*
*E*      ERROR:   B1-04
*E*      MESSAGE: PP AREA IS LARGER THAN RESERVED BY HEAD
*E*
         LI,14    BIGD
         B        ABORTIT
*E*
*E*      ERROR:   B1-03
*E*      MESSAGE: DATA AREA IS LARGER THAN RESERVED BY HEAD
*E*
BADTREE  EQU      %
         LI,14    TREEBAD
         B        ABORTIT
*E*
*E*      ERROR:   B1-01
*E*      MESSAGE: TREE RECORD IS INCOMPLETE
*E*
EREXIT   EQU      %
         LI,14    0
         B        ABORTIT
*E*
*E*      ERROR:   B1-00
*E*      MESSAGE: CAN'T FIND THAT OVERLAY SEGMENT
*E*
*
BADBUF   EQU      %
         LI,14    BADB
ABORTIT  EQU      %
         SCS,14   -8
         AI,14    X'B1'
         B        T:ABORTM
*
OPN      DATA     X'F000001',10,2,2,1
         DATA     X'10000'
READ     DATA     X'3C000010'
DBCAL    DATA     X'04300000'
         END

