*        704727   SIGMA 5/7         BPM M:INIT2
         SYSTEM   SIG7FDP
MODE     EQU      1
         DO       MODE=1
SD       EQU      1
         ELSE
SD       EQU      0
         FIN
CFU      EQU      1
MREF     EQU      1
BPMLIB   EQU      0                 1=BUILD BPM LIB UNDER CP-V
*BPMLIB=1 MUST BE USED ONLY WITH MODE=1 AND THEN JUST TO
*FORM A LOADER TO USE IN BUILDING BPM LIBRARIES UNDER CP-V.
         CSECT    1
         DEF      MCI2
MCI2     EQU      %
         REF      M2,M3,M4,M5,M6,M7,M8,M15,M16,M17,M20,M32,MN1,MN2,;
                  MN3,MN4,MN8,MN9,MN16,M826,MSKFTYPE,Y1,Y2,Y4,Y8,Y01,;
                  Y02,Y08,Y0C,Y0F,Y001,Y002,Y004,Y008,Y00C,;
                  Y001F,Y00FFFF,Y0001,Y0002,Y0003,Y0004,Y0005,Y0006,;
                  Y0007,Y0008,Y000B,;
                  Y0301,Y0303,Y0343,Y0304,Y0405,Y0502,;
                  Y00FF,YFF00FFFF,Y000F,YFFF0FFFF,TXF:,TXM:,;
                  TXLIB,TX6F4:,TXASTL,TXHEAD,;
                  HEADWD,TXTREE,STK2,RFDFSTK2,PASSCODE
         REF      M11
         REF      READBILI,2BNUM,3BNUM,12BNUM,4BNUM,GBYTE,GETSEG
         REF      BLANKER,BINTOHEX
         DEF      INIT2
         REF      ER8,ER9
         REF      DECLSTK,DECLSTK1,DECLBAS,RFDFBAS,RFDFSTK,;
                  RFDFSTK1,EXPRSTK,EXPRSTK1,EXPRBAS,BSEG1,BSEG2,;
                  CSEG1,CSEG2,CROM1,CROM2,CRFDF1,CRFDF2,CURBYTE,;
                  RCDSIZE,SEQNUM,SEVLEV,XSL,LASTCARD,BUF,BUF2,;
                  BFR,TEMPPTR,TREEPTR,FCOUNT,FTABLE,;
                  ERRTAB,ERRSTK,TCBSIZE,TCBPTR,FTAB,RSEG00,;
                  RSEG01,RSEG10,RREL00,RREL01,RREL10,CSEG00,;
                  CREL00,CREL01,CREL10,MAX00,;
                  MAX01,MAX10,DLOC,PLOC,SLOC,LOC,START,LOCCT,;
                  LOADBAS,MODBAS,RELDBAS,MBIAS,FBIAS,BIAS,;
                  RDIG,MODSIZ,NOTLLM,MAXRFDF,MAXEXPR,TOPOMEM,;
                  OPENEF,READEF
         REF      PBUF
         REF      PRINT,USID,LOCWD
         REF      NXTAVPG
         REF      TEMPSIZE,DECLSIZE,EXPRDIS,;
                  RFLOADIS,RFDFDIS,NXROMDIS,SBLNKDIS,ROM1DIS,;
                  TMPSZDIS,NUNSTDIS,00DIS,01DIS,10DIS,NRWACCT,;
                  TREESIZE,TREEDIS,BIASDIS,LOWLIMDS,FCOMDIS,;
                  ERRDIS,LMNDIS,USACTDIS,LMPASS,LMEXPDIS,;
                  RDACT1,ROMSIZE,TCBBLNK
         REF      FCOMSIZ
         REF      READLM,WRITELM,CLOSE,M:LL,M:EF,M:LM,M:DIC
         REF      XMEM3X,XMKEY
         REF      XMRKEY
         REF      RFLDMODS,BREFBIT,RFLDTBSZ
         REF      DOREFPTR,TXS:OVRL
         REF      ER15,ER16,ER17,ER18,ER19,ER1A,ER1B
         DO       MODE~=0
         REF      J:JIT
         FIN
         DO       MODE=1
         REF      J:EUP
         REF      CHKLM
         REF      CORELIB
         REF      M:FVP
         FIN
         REF      CODE
         REF      CFUPTR
         DO       SD=1
         REF      SYMBOLTB,SYMTOP
         FIN
         PAGE
         REF      MESSAGE
BGEZ     EQU      X'681'
BE       EQU      X'683'
BNEZ     EQU      X'693'
BGE      EQU      X'681'
BL       EQU      X'691'
BAZ      EQU      X'684'
BCR8     EQU      X'688'
BCR10    EQU      X'68A'
BLE      EQU      X'682'
BEZ      EQU      X'683'
*        QUIT     ERROR,CONDITION
QUIT     CNAME
         PROC
LF       EQU      %
         DO       NUM(AF)=3
         DO       AF(2)~=0
         GEN,12,20  AF(2),%+4+MODE
         FIN
         STW,AF(3) CODE
         ELSE
         DO       AF(2)~=0
         GEN,12,20  AF(2),%+3+MODE
         FIN
         FIN
         LI,R3    AF(1)
         DO       MODE=1
         LI,R4    AF(3)=SR3
         FIN
         B        MESSAGE
         PEND
*        SNAP     FROM,TO,TEXT1,TEXT2
SNAP     CNAME
         PROC
LF       CAL1,3   %+1
         DATA     0,AF(1),AF(2),AF(3),AF(4),X'02000000'
         PEND
         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 FOR LOADER.
K0       EQU      0
K1       EQU      1
K2       EQU      2
K3       EQU      3
K4       EQU      4
K5       EQU      5
K6       EQU      6
K7       EQU      7
K8       EQU      8
K9       EQU      9
KA       EQU      X'A'
KB       EQU      X'B'
KC       EQU      X'C'
KD       EQU      X'D'
KE       EQU      X'E'
KF       EQU      X'F'
K10      EQU      X'10'
K11      EQU      X'11'
K12      EQU      X'12'
K16      EQU      X'16'
K17      EQU      X'17'
K19      EQU      X'19'
K1C      EQU      X'1C'
K1E      EQU      X'1E'
K1F      EQU      X'1F'
K20      EQU      X'20'
K22      EQU         X'22'
K24      EQU      X'24'
K26      EQU      X'26'
K39      EQU      X'39'
K3C      EQU      X'3C'
K3F      EQU      X'3F'
K40      EQU      X'40'
K43      EQU      X'43'
K6C      EQU      X'6C'
K78      EQU      X'78'
K80      EQU      X'80'
KF0      EQU      X'F0'
KF1      EQU      X'F1'
KF2      EQU      X'F2'
KFF      EQU      X'FF'
K100     EQU      X'100'
K120     EQU      X'120'
K1FF     EQU      X'1FF'
K200     EQU      X'200'
K202     EQU      X'202'
K220     EQU      X'220'                                                727
K256     EQU      X'256'
K400     EQU      X'400'
K800     EQU      X'800'
KC00     EQU      X'C00'
K1000    EQU      X'1000'
K2000    EQU      X'2000'
K3FFF    EQU      X'3FFF'
K4000    EQU      X'4000'
K4100    EQU      X'4100'
K4110    EQU      X'4110'
K7FFF    EQU      X'7FFF'
KFF00   EQU      X'FF00'
K8000    EQU      X'8000'
K1FFFF   EQU      X'1FFFF'
K20000   EQU      X'20000'
KN1      EQU      -1
KN2      EQU      -2
KN3      EQU      -3
KN4      EQU      -4
KN8      EQU      -8
KN16     EQU      -16
KN100    EQU      -100
KN200    EQU      -X'200'
KN400    EQU      -X'400'
KTE      EQU      'E'
KTR      EQU      'R'
         PAGE
*                                   INIT2 CALCULATES THE SIZE OF THE
*                                   LOAD MODULE AND LAYS OUT STACK
*                                   AND BUFFER AREAS FOR PASS2.
INIT2    EQU      %
         PSW,SR4  *R0
         DO       MODE=1
*                                RELEASE ALL COMMON PAGES, IF ANY.
*                                (THESE USED TO BE EXPRESSION
*                                STACK AREA).
         LW,7     J:EUP
         SLS,7    9
         AW,7     M:FVP
         CAL1,8   7
         BCS,8    %+3
         AI,7     -X'200'
         B        %-3
         FIN
         LI,R4    K0
         STW,R4   CSEG1
CALCSIZE EQU      %
*                                   CALCULATES THE SIZE OF THE TCB AND
*                                   ASSOCIATED TABLES.
         LW,R4    LOCWD
         CI,R4    K2000
         BANZ     CALCSIZ2
         LI,SR1   TCBBLNK+14
         LW,R4    LOCCT
         AI,R4    ERRDIS
         INT,R6   *R4
         LH,R6    *R4
         STW,R6   ERRSTK
         STW,R7   ERRTAB
         AW,SR1   R6
         AW,SR1   R7
         STW,SR1  TEMPPTR
         AI,R4    8-7               TMPSZDIS-ERRDIS
         LH,R6    *R4
         AW,SR1   R6
         LW,R3    SR1
         LW,D4    LOCWD
         CI,D4    K40
         BAZ      XNOM100
         AI,SR1   KFF
         AND,SR1  MN8
         B        TCBFIX
XNOM100  EQU      %
         CI,D4    K20
         BAZ      SETTCBSIZE
         AI,SR1   X'F'
         AND,SR1  MN4
TCBFIX   EQU      %
         LW,R7    SR1
         SW,SR1   R3
         AI,SR1   1
         AND,SR1  MN1
         SLS,SR1  15
         AWM,SR1  00DIS,R1
         LW,SR1   R7
SETTCBSIZE EQU    %
         STW,SR1  TCBSIZE
         PAGE
*                                   ACCOUNT FOR DCB TABLE SIZE
*                                   IN 01 IF BPM OR 10 IF CP-V.
CALCSIZ2 EQU      %
         LI,SR1   0
         LI,R3    0
         LW,R6    LOCWD
         CI,R6    K10               IS IT LIBRARY
         BANZ     FINDLGSTPATH
         LW,SR1   FCOUNT            NO.
         DO       MODE=0[BPMLIB=1
         BNEZ     YESDCBS
         ELSE
         BEZ      NODCBS
         FIN
         DO       CFU=1
         LW,D4    CFUPTR            CFUPTR>0 & FCOUNT>2
         BEZ      YESDCBS           IMPLIES DCBS.
         CI,SR1   K2
         BG       YESDCBS
         LW,D4    RFDFBAS
         LI,R6    K0
         LW,R7    Y0401             M:* IS THE ONLY DCB & MUST
         STW,R7   *D4               BE REMOVED (CHANGE TO SREF)
         AI,D4    K3
         STB,R6   *D4                 SET TYPE=0,
         STW,R6   FCOUNT              FCOUNT=0,
         STW,R6   10DIS,R1            AND 10 SIZE IN ROOT'S TREE=0.
         LW,R6    LOCWD
         B        NOTREE
NODCBS   EQU      %
         FIN
         DO       MODE=1
         STW,SR1  10DIS,R1
         FIN
NOTREE   AI,R3    X'C'            NO DCBS IMPLIES ROOT ONLY.
         B        BOUNDM1XX
YESDCBS  EQU      %
*                                   IN R3 WE ACCUMULATE THE SIZE OF THE
*                                   01 PROTECTION TYPE IN CASE WE HAVE
*                                   TO ACCOUNT FOR A BOUND OF M10 ORM100
         AI,SR1   4
         AND,SR1  MN1
         SLS,SR1  15
         DO       MODE=0[BPMLIB=1
         AWM,SR1  01DIS,R1
         LW,R3    SR1
         SLS,R3   -15
         ELSE
         AW,SR1   10DIS,R1
         AW,SR1   Y00FF
         AND,SR1  YFF00FFFF
         STW,SR1  10DIS,R1
         FIN
         LW,R7    -1,R1
         SW,R7    R1
         AW,R3    R7
         AI,R3    2
         CI,R7    KC
         BLE      BOUNDM1XX         NO OVERLAY IF ONLY ROOT.
         CW,R6    RFLDMODS          IS REF OR BREF SPECIFIED
         BAZ      BOUNDM1XX         BRANCH IF NO REF LOAD REQUIREMENTS.
         SLS,R7   -1                APPROX REF LD ENTRIES = 5.5/SEGMENT
         MTW,0    RFLDTBSZ
         BEZ      %+2               USE SPECIFIED VALUE IF SUPPLIED
         LW,R7    RFLDTBSZ
         SLS,R7   2                 ASSUME 4-WDS PER ENTRY IN RFLDTABLE
         CW,R6    BREFBIT
         BAZ      %+2
         SLS,R7   -1                RFLDTABLE SIZE IS 2 WDS PER ENTRY
         AI,R7    X'16'
         STW,R7   RFLDTBSZ          SET SIZE OF REF LOADING
         AI,R7    X'A'
         SLS,R7   15
         AWM,R7   01DIS,R1
         SLS,R7   -15
         AW,R3    R7
         LI,R7    K100
         STS,R7   LOCWD             *  *  *   FORCE LMN 'ABS'   *  *  *
BOUNDM1XX EQU     %
         LW,SR1   R3
         LW,R7    LOCWD
         CI,R7    X'20'
         BAZ      NOTM10
         AI,SR1   X'F'
         AND,SR1  MN4
         B        ADJUST01
NOTM10   CI,R7    X'40'
         BAZ      FINDLGSTPATH
         AI,SR1   X'FF'
         AND,SR1  MN8
ADJUST01 EQU      %
         SW,SR1   R3                COMPUTE DIFFERENCE AND AUGMENT 01.
         AI,SR1   1
         AND,SR1  MN1
         SLS,SR1  15
         AWM,SR1  01DIS,R1
*                                   THIS ROUTINE GOES THROUGH THE TREE
*                                   STRUCTURE FINDING THE LONGEST PATH
*                                   OF EACH PROTECTION TYPE.
FINDLGSTPATH EQU   %
         LI,R7    K0
         LCI      K8
         STM,R7   SR1
         LW,D4    R1
         BAL,SR4  GETSIZ
ADDSIZ   AW,D1    R5
         AW,D2    R6
         AW,D3    R7
         CW,D4    R1
         BNE      ADDSIZ2
         BAL,SR4  COMLNK
         B        ADDSIZ1
ADDSIZ2  CW,R5    MAX00
         BLE      %+2
         STW,R5   MAX00
         CW,R6    MAX01
         BLE      %+2
         STW,R6   MAX01
         CW,R7    MAX10
         BLE      %+2
         STW,R7   MAX10
ADDSIZ1  AI,D4    SBLNKDIS
         LH,R4    *D4
         BNEZ     SBLNK
         LW,R4    *D4
         AND,R4   M16
         BNEZ     OVLNK
         AI,D4    KN1
BKLNK    BAL,SR4  COMLNK
         LW,R4    *D4                                                   727
         AND,R4   M16
         BEZ      CALCSIZ3
BKLNK2   SW,D1    R5
         SW,D2    R6
         SW,D3    R7
         LW,D4    R4
         AW,D4    R1
         BAL,SR4  GETSIZ
         AI,D4    SBLNKDIS
         LW,R4    *D4
         AND,R4   M16
         BNEZ     SUBSIZ
         AI,D4    3-4               ROM1DIS-SBLNKDIS
         B        BKLNK
SBLNK    LW,D4    R4
         AW,D4    R1
         BAL,SR4  GETSIZ
         B        ADDSIZ
COMLNK   CW,SR1   D1
         BGE      %+2
         STW,D1   SR1
         CW,SR2   D2
         BGE      %+2
         STW,D2   SR2
         CW,SR3   D3
         BGE      %+2
         STW,D3   SR3
         B        *SR4
OVLNK    BAL,SR4  COMLNK
SUBSIZ   SW,D1    R5
         SW,D2    R6
         SW,D3    R7
         B        SBLNK
GETSIZ   AI,D4    00DIS
         LW,R5    *D4
         SLS,R5   -15
         AI,D4    7-5               01DIS-00DIS
         LW,R6    *D4
         SLS,R6   -15
         AI,D4    9-7               10DIS,01DIS
         LW,R7    *D4
         SLS,R7   -15
         AI,D4    -9                -10DIS
         B        *SR4
*                                   THIS SECTION ROUNDS THE SIZES UP
*                                   TO FULL PAGES. IT ALSO PICKS UP
*                                   THE BIAS OR USES BACKGROUND
*                                   LOWER LIMIT AND CHECKS TO SEE
*                                   IF PROGRAM CAN FIT IN ANY
*                                   MACHINE. CONTROL SIZE TO SETBIAS
*                                   OR CALSIZ4.
CALCSIZ3 LI,R5    K3
         LW,R7    LOCWD
         CI,R7    X'80'
         BANZ     %+2
         AW,SR1   FCOMSIZ
         DO       MODE+BPMLIB=1
         LI,R6    0
         LW,R7    Y4
         STS,R6   CORELIB
         LH,R7    CORELIB
         BLEZ     %+3
         SLS,R7   1
         AW,SR1   R7
         FIN
         LI,R7    K0
         LI,R4    DLOC-1
CALCSIZ5 LW,R6    SR1-1,R5
         AI,R6    K1FF
         AND,R6   MN9
         STW,R6   *R4,R5
         DO       MODE=0[BPMLIB=1
         AW,R7    R6
         FIN
         BDR,R5   CALCSIZ5
         LW,R6    LOCCT
         AI,R6    LOWLIMDS
         DO       MODE=0[BPMLIB=1
         LW,R6    *R6
         FIN
         LW,R5    LOCCT
         LW,R4    BIASDIS,R5
         DO       MODE=0
         BEZ      SETBIAS
         AW,R7    R4
         CI,R7    K1FFFF
         BLE      CALCSIZ4
         QUIT     ER9,,R4
         ELSE
         B        CALCSIZ4
         FIN
ALLMEM   LI,R4    K3
*                                   ALLMEM EXPECTS THE SIZE OF THE
*                                   THESE SECTIONS IN R5, 6 AND 7. IT
*                                   ALLOCATES BUFFERS DOWN FROM THE
*                                   ADDRESS IN D4 IN THE ORDER 10,
*                                   01, 00. IT THEN ALLOCATES REL. DICT.
*                                   BUFFERS IN THE SAME ORDER IF
*                                   NECESSARY.
ALLMEM1  SW,D4    R4,R4
          STW,D4  *D3,R4
         SLS,D4   2
         XW,D4    *D3,R4
         BDR,R4   ALLMEM1
         AI,D3    46-43
         LW,R4    LOCWD
         CI,R4    K100
         BANZ     *SR4
         LI,R4    K3
ALLMEM2  LW,D2    R4,R4
         AI,D2    K7
         SLS,D2   -3
         SW,D4    D2
         STW,D4   *D3,R4
          SLS,D4   2
         XW,D4     *D3,R4
         BDR,R4   ALLMEM2
         B        *SR4
*                                   THE BIAS IS ROUNDED DOWN TO A
*                                   PAGE BOUNDARY.
SETBIAS  AND,R6   MN9
         STW,R6   BIASDIS,R5
         LW,R4    R6
*                                   DLOC, PLOC & SLOC. THE THREE LOCATION
*                                   COUNTERS ARE INITIALIZED AND BUFFERS
*                                   ARE ESTABLISHED FOR LOADING THE
*                                   ROOT SEGMENT AND THE LONGEST
*                                   OTHER SEGMENT FROM THE TOP OF
*                                   MEMORY DOWNWARD.
CALCSIZ4 AND,R4   MN9
         STW,R4   LOADBAS
         LCI      3
         LM,R5    DLOC              SAVE SIZES FOR GENERAL
         STM,R5   BUF               ALLOCATION SUMMARY.
         XW,R4    DLOC
         AW,R4    DLOC
         DO       MODE+BPMLIB=1
         XW,R4    SLOC              DCB NAME TABLE FOLLOWS
         AW,R4    SLOC                00 CSECTS FOR CP-V
         FIN
         XW,R4    PLOC
         AW,R4    PLOC
         DO       MODE+BPMLIB=1
         STW,R4   NXTAVPG
         FIN
         DO       MODE=0[BPMLIB=1
         XW,R4    SLOC
         AW,R4    SLOC
         STW,R4   NXTAVPG
         FIN
         LCI      3
         LM,R5    DLOC              SAVE BASE ADDRESSES FOR GENERSL
         STM,R5   BUF+3             ALLOCATION SUMMARY(OUTPUT BY 'ALL').
         LW,D4    R1
         BAL,SR4  GETSIZ
         LW,D4    TOPOMEM
         LI,D3    RSEG00-1
         BAL,SR4  ALLMEM
         CI,D4    0
         BGEZ     ALLCATE
         LCW,D4   D4
         QUIT     ER15,,D4
*                                   SPACE IS ALLOCATED FOR THE MAXIMUM
*                                   REF/DEF AND EXPR STACK FROM LOW
*                                   MEMORY UP, AND THE DOUBLE WORDS
*                                   ARE CALCULATED.
ALLCATE  EQU      %
         LW,R5    MAX00
         LW,R6    MAX01
         LW,R7    MAX10
         AI,D3    49-46             CSEG00-RREL00
         BAL,SR4  ALLMEM
         INT,R5   RFDFSTK+1
         AND,R5   M15
         LCW,R5   R5
         MSP,R5   RFDFSTK
         LW,R5    RFDFSTK
         AND,R5   M17
         STW,R5   RFDFSTK
         LW,R5    MAXRFDF
         AW,R5    RFDFBAS
         CI,R5    K1
         BANZ     %+2
         AI,R5    K1
         STW,R5   EXPRSTK
         AI,R5    K1
         STW,R5   EXPRBAS
         DO       MODE=1
         LW,R5    YFFFF8
         STW,R5   EXPRSTK+1
         LW,R5    RFDFBAS
         LW,R6    EXPRBAS
         SW,R6    R5
         AW,R6    MAXEXPR
         SLS,R6   2
         BAL,SR4  CHKLM
         FIN
         LW,R6    LOCWD
         CI,R6    K100
         BAZ      %+3
         LW,R5    CSEG00
         B        %+2
         LW,R5    CREL00
         DO       MODE=1
         SLS,R5   -11
         LW,R7    J:EUP
         SW,R7    R5
         AI,R7    1
         AW,R7    M:GCP
         CAL1,8   7
         BCS,8    EXMEM0
         CI,R6    X'4000'           WAS PAGE OPTION SPECIFIED
         BANZ     EXMEM0
         LW,R3    LOCCT
         LCI      2
         LM,R4    10,R3
         CD,R4    TXM:MON           FORCE EXTENDED MEMORY MODE IF
         BNE      EXMEM6            LOADING THE CP-V MONITOR
EXMEM0   EQU      %
         DO       MREF=1
         LI,D3    X'4000'           SET TREE'S 00LOC FOR
         LW,D4    M16               EVERY SUBLINK
         LW,R7    R1                OF ROOT = X'4000'
         INT,D1   SBLNKDIS,R7
         CI,D1    K0                SO CALCLOC IN EVL
         BEZ      EXMEM4            WILL USE PROPER
         AW,R7    D1                SEG BASE
EXMEM2   STS,D3   00DIS,R7          FOR INITIALIZING
         INT,D2   SBLNKDIS,R7       BIAS, LOC, & FBIAS.
         LW,R7    R1
         AW,R7    D2
         CI,D2    K0
         BNE      EXMEM2
         FIN
EXMEM4   BAL,SR4  XMEM
EXMEM6   EQU      %
         LW,R6    LOCWD
         ELSE
         SLS,R5   -2
         SW,R5    EXPRBAS
         CW,R5    M15
         BLE      %+2
         LW,R5    M15
         CW,R5    MAXEXPR
         BG       EXSTKPTR
*                                   IF NOT ENOUGH ROOM FOR THE EXPR.
*                                   STACK GO INTO EXTENDED MEMORY
*                                   MODE.
         BAL,SR4  XMEM
         LW,R6    LOCWD
         LI,R5    KN400              ASSUME TWO PAGES NEEDED FOR XMEM
         CI,R6    K100              IS THE 'ABS' BIT ON
         BAZ      %+2               NO
         LI,R5    KN200             YES, THEN ONLY ONE PAGE IS NEEDED
         AW,R5    TOPOMEM
         SW,R5    EXPRBAS
         CW,R5    M15
         BLE      %+2
         LW,R5    M15
EXSTKPTR AI,R5    K8000
         SLS,R5   16
         AI,R5    K8000
         STW,R5   EXPRSTK1
         FIN
*                                   TRACE REF/DEF STACK FOR S:OVRLY
*                                   IF IN BREF MODE
         CW,R6    BREFBIT
         DO       SD=0
         BAZ      IN2EXIT
         ELSE
         BAZ      SDKRD16
         FIN
         LW,R6    TXS:OVRL
         LW,R7    TXS:OVRL+1
         LW,R5    RFDFBAS
NEXTREF  LB,D2    *R5
         AW,R5    D2
         CW,R6    -2,R5
         BNE      NEXTREF
         CW,R7    -1,R5
         BNE      NEXTREF
         STW,R5   DOREFPTR
         DO       SD=1
SDKRD16  MTW,0    SYMBOLTB          FORM IST
         BLZ      IN2EXIT    NO
         LCI      2
         PSM,R1   *R0
         LW,R1    LOCWD
         CI,R1    X'4000'           XMEM MODE
         BANZ     SDKRD20           YES
         LW,R2    CREL00
         CI,R1    X'100'            ABS
         BAZ      %+2               NO
         LW,R2    CSEG00
         SLS,R2   -2                FIRST NON AVIAL WORD NON XMEM
         B        SDKRD9
SDKRD20  LW,R2    TOPOMEM
         AI,R2    -X'200'
         CI,R1    X'100'            ABS
         BANZ     %+2               YES-JUST ONE PAGE XMEM BUFFER
         AI,R2    -X'200'           NO-TWO PAGE XMEM BUFFER
SDKRD9   STW,R2   SYMTOP            FIRST NOW AVIALABLE WORD
         STW,R2   SYMBOLTB          INTIALIZE IST BUFFER ADDRESS
         STW,R2   BSEG2
         LCI      2
         PLM,R1   *R0
         FIN
IN2EXIT  EQU      %
         PLW,SR4  *R0
         B        *SR4
         PAGE
*                                   EXTENDED MEMORY MODE CHECKS TO
*                                   SEE THAT THERE IS AT LEAST 1 PAGE
*                                   (2 IF NOT ABS) ABOVE THE EXPRSTACK.
*                                   IF SO IT OPENS M:DIC  TO THE
*                                   EXTENDED MEMORY FILE "ID X". IT
*                                   THEN REALLOCATES THE BUFFERS TO
*                                   YIELD ONLY THOSE WITH EACH EQUAL
*                                   TO THE GREATER OF THE TWO PREVIOUSLY
*                                   ALLOCATED FOR EACH PROTECTION TYPE
*                                   (ROOT AND OTHER SEGMENT). THIS IS
*                                   TO ALLOW PUTTING THE SEGMENTS
*                                   TOGETHER AT THE END OF LOADING.
XMEM     PSW,SR4  *R0
         DO       MODE=1
         CI,R6    X'10'
         QUIT     X'2D',BAZ         CANNOT FORM LIB LMN IN XMEM
         LW,R6    LOCCT
         LW,D4    1,R6              ROMT POINTER
         SW,D4    2,R6              TREET POINTER
         CI,D4    X'B00'            TREE SIZE FOR 256 SEGS
         BLE      XMEM1
         DH,D4    Y000B
         QUIT     X'30',,D4         NO MORE THAN 256 SEGS ALLOWED
XMEM1    EQU      %
         CAL1,1   SETXERR
         LI,R7    1
         SW,SR1   R7
         QUIT     ER16,BGEZ
         BEZ      %+3
         AW,SR1   M:FCP
         CAL1,8   SR1
         INT,D4   00DIS,R1          BASE ADDR OF ROOT'S DATA FOR CP-V
         SLS,D4   -8
         ELSE
         LW,D4    TOPOMEM
         SLS,D4   -9
         FIN
         AW,D4    Y03
         STW,D4   XMKEY             KEY OF INITIAL CORE IMAGE RECORD
         DO       MODE=0
         STW,D4   XMRKEY
         FIN
         LW,R6    TOPOMEM
         DO       MODE=1
         AI,R6    KN200+K2          USE 1 PAGING BUFFER AT TOPOMEM
         LI,R7    K1FF
         LI,D4    0
         STW,D4   *R6,R7            CLEAR FIRST PAGE IN XMEM BUFFER
         BDR,R7   %-1
         STW,D4   *R6
         ELSE
         AI,R6    XMPL-XMPLX        ALLOW ROOM FOR M:DIC OPEN FPT
         LW,R7    EXPRBAS
         AW,R7    MAXEXPR
         CW,R6    R7                 WILL EXPRESSION STACK FIT
         BGE      XMEM0
         SW,R7    R6
         QUIT     ER17,,R7
XMEM0    EQU      %
         FIN
         DO       MODE~=0
         LI,R7    X'4100'           SET XMEM AND ABS BITS
         STS,R7   LOCWD
         LW,R6    LOCCT
         STS,R7   *R6
         ELSE
         LI,R7    X'4000'
         STS,R7   LOCWD
         LI,R7    XMPLX-XMPL
         LW,R4    XMPL-1,R7
         STW,R4   *R6,R7
         BDR,R7   %-2
         LW,R7    USID
         STS,R7   10,R6
         CAL1,1   1,R6
         FIN
         LI,R5    XMESS
         CAL1,2   PRINT
         LW,D4    R1
         BAL,SR4  GETSIZ
         CW,R5    MAX00
         BGE      %+2
         LW,R5    MAX00
         CW,R6    MAX01
         BGE      %+2
         LW,R6    MAX01
         CW,R7    MAX10
         BGE      %+2
         LW,R7    MAX10
         LW,D4    TOPOMEM
         LI,D3    RSEG00-1
         BAL,SR4  ALLMEM
         CI,D4    0
         BGEZ     XMEM2
         LCW,D4   D4
         QUIT     ER18,,D4
XMEM2    EQU      %
         DO       MODE=0
         AW,R6    R7
         AW,R6    R5
         CI,R6    K1000        ASSURE UNIQUE PAGES BETWEEN RELDIC AND LM
*                                   IF SUM OF MAX SIZES<8K,NO OVERLAP
*                                   POSSIBLE FOR REL.DIC. PAGE.
         BGE      XMEM1
         LW,R4    RSEG10
         AND,R4   M11
         AI,R4    4
         LCW,R4   R4
         AWM,R4   RREL00
         AWM,R4   RREL01
         AWM,R4   RREL10
XMEM1    LCI      6
         ELSE
         LCI      3
         FIN
         LM,R5    RSEG00
         STM,R5   CSEG00
         PLW,SR4  *R0
         B        *SR4
         DO       MODE=0
         REF      XMEMEOFX
XMPL     GEN,8,24 X'14',M:DIC
         DATA     X'CF000001'                                           727
         DATA     XMEM3X,XMEMEOFX,10,2,2,8
         DATA     X'01000101',X'030000E7',X'02010002'                   727
         RES      2
XMPLX    EQU      %
         FIN
Y03      DATA     X'03000000'
Y0401    DATA     X'04010000'
         DO       MODE=1
YFFFF8   DATA     X'FFFF8000'
M:FCP    GEN,8,24 X'D',0
M:GCP    GEN,8,24 X'C',0
         BOUND    8
TXM:MON  TEXTC    'M:MON'
SETXERR  GEN,8,24 6,M:LM
         DATA     X'80000000'
         DATA     XMEM3X
         FIN
XMESS    TEXTC    ' EXTENDED MEMORY MODE.'
         END

