*        704726   SIGMA 5/7         BPM M:PASS1
***********************************************************************
*M*      PS1      LOADER'S FIRST PASS
***********************************************************************
*P*      NAME:    PS1
*P*      PURPOSE: ENTRY/EXIT FROM LDR.
*P*               READS AND PROCESSES ROMS AND LOAD MODULES,COLLECTION
*P*                    THE INFORMATION NECESSARY TO ASCERTAIN SIZES OF
*P*                    CONTROL SECTIONS AND MAXIMUM STACKS.
*P*               SATISFIES PREFS FROM LIBRARIES.
*P*               WRITES OUT INTERIM STACKS.
*P*      DESCRIPTION: PS1 CONSISTS OF FOUR MAJOR PARTS: THE MAIN LOOP,
*P*               THE OBJECT MODULE DECODER(LP1),THE LOAD MODULE
*P*               PROCESSOR(ADLDMD),AND THE LIBRARIAN(SATREF). STARTING
*P*               WITH THE ROOT SEGMENT AND PROCEEDING ALONG A PATH,THE
*P*               HEAD RECORD OF EACH INPUT FILE NAMED IN THE ROM TABLE
*P*               FOR THIS SEGMENT IS READ AND CONTROL DIRECTED TO
*P*               ADLDMD OR LP1,DEPENDING UPON WETHER THE FILE IS KEYED
*P*               OR NOT.
*P*               LP1 LOOKS AT ALL DECLARATIONS (CONTROL SECTIONS
*P*               AND NAMES) AND ALL DEFINITIONS(DEFS AND FORWARD REFS).
*P*               IT IGNORES ALL OTHER LOAD ITMES. EVERY DECLARATION
*P*               RESULTS IN CREATING AN ENTRY IN THE REF/DEF STACK AND
*P*               AN ENTRY IN THE DECLARATION STACK WHICH POINTS TO IT.
*P*               EVERY DEFINITION RESULTS IN CREATING AN ENTRY IN THE
*P*               EXPRESSION STACK WHOSE DESTINATION IS THE REF/DEF
*P*               STACK ENTRY WHICH IS BEING DEFINED. THE REF/DEF STACK
*P*               MAY GAIN ONE OR MORE ENTRIES AS A RESULT OF A
*P*               DEFINITION WHOSE DEFINING EXPRESSION INVOLVES AN
*P*               UNKNOWN FORWARD REFERENCE.
*P*               A LOAD MODULE MY BE ENCOUNTERED AS A RESULT OF EITHER
*P*               AN EF SPECIFICATION OR SATISFYING A PREF FROM A LIB.
*P*               IN EITHER CASE,ADLDMD HAS AT ITS DISPOSAL A HEADER,A
*P*               TREE,A REF/DEF STACK,AN EXPRESSION STACK,AND THE CORE
*P*               IMAGE RELOCATION DICTIONARY FOR ONE(AND ONLY ONE)
*P*               PROTECTION TYPE. USING THE SPACE JUST ABOVE THE
*P*               REF/DEF STACK,PS1 READS THE TREE RECORD TO DETERMINE
*P*               THE REF/DEF STACK STACK. THE EXPRESSION STACK IS READ
*P*               IN JUST BELOW THE CURRENT EXPRESSION STACK AND
*P*               INVERTED AND ALL EXPRESSIONS ARE MARKED UNEVALUATED.
*P*               ALL CORE EXPRESSIONS IN THE LOAD MODULE HAVE THEIR
*P*               DESTINATIONS CHANGED TO BE RELATIVE TO THE BASE OF
*P*               THE LOAD MODULE. THE REF/DEF STACK IS READ IN BELOW
*P*               THE EXPRESSION STACK,AND EACH ENTRY IS MERGED INTO
*P*               THE LARGE REF/DEF STACK.
*P*               THE SATISFY-REFERENCE LOGIC WORKS AS FOLLOWS: AFTER
*P*               EACH SEGMENT'S ELEMENT FILES HAVE BEEN READ AND ITS
*P*               REF/DEF STACK BUILT,SATREF IS CALLED TO SATISFY THE
*P*               SEGMENT'S PREFS BY SEARCHING THE SPECIFIED LIBRARIES.
*P*               THUS IT ATTEMPTS TO SATISFY ALL THE PREFS IT CAN IN
*P*               A LOWER SEGMENT BEFORE STARTING TO BUILD THE REF/DEF
*P*               STACK FOR A HIGHER SEGMENT. THE ASSOCIATION OF A CORE
*P*               LIBRARY IS TRIGGERED BY ONE OF TWO CONDITIONS:
*P*               1- A PREF TO 9INITIAL(FORTRAN) OR 9DBINIT(FORT DEBUG)
*P*               2- THE PRESENCE OF A :PN IN THE UNSAT LIST ON THE
*P*                  !LOAD CARD.
*P*      REFERENCE: THE OVERLAY LOADER TECHNICAL MANUAL HAS A MORE
*P*               DETAILED DESCRIPTION AND FLOW CHARTS.
***********************************************************************
         SYSTEM   SIG7FDP
MODE     EQU      1
CFU      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      MCP1              MODULE BASE ADDRESS
MCP1     EQU      %
*K* MXX DEFINES A RIGHT-JUSTIFIED MASK OF 'XX' BITS
*K* MNXX DEFINES A LEFT-JUSTIFIED MASK OF 'XX' BITS
*K* XNNNN DEFINES A RIGHT-JUSTIFIED MASK OF VALUE X'NNNN'
*K* YNNNN DEFINES A LEFT-JUSTIFIED MASK OF X'NNNN'
         REF      M2
         REF      M3
         REF      M4
         REF      M6
         REF      M8
         REF      M15
         REF      M16
         REF      M17
         REF      M20
         REF      MN3
         REF      MN9
         REF      MN16
         REF      MSKFTYPE          SYMBOL EQU'D TO X'F0000'
         REF      Y4
         REF      Y8
         REF      Y01
         REF      Y001
         REF      Y002
         REF      Y004
         REF      Y008
         REF      Y00C
         REF      Y1
         REF      Y00FFFF
         REF      Y0001
         REF      Y0002
         REF      Y0003
         REF      Y0004
         REF      Y0005
         REF      Y0006
         REF      Y0007
         REF      Y0008
         REF      Y000B
         REF      Y000C
         REF      Y0303
         REF      Y0304
         REF      Y0405
         REF      Y00FF
         REF      YFF00FFFF
         REF      Y000F
         REF      YFFF0FFFF
         REF      TXF:              HAS 'F:' IN BYTES 1,2
         REF      TXM:              HAS 'M:' IN BYTES 1,2
         REF      TXLIB             TEXTC ':LIB'
         REF      TX6F4:            TEXTC 'F4:' W/BYTE COUNT=6
         REF      TXTREE            TEXTC 'TREE' W/TRAILING ZEROES
         REF      READBILI          ROUTINE TO READ A RECORD THRU M:EF
         REF      2BNUM             RETURNS NEXT 2 BYTES OF E.F.
         REF      3BNUM             RETURNS NEXT 3 BYTES OF E.F
         REF      12BNUM            READS NEXT 1 OR 2 BYTES OF E.F.,
*,*                                 DEPENDING ON # OF DECLARATIONS.
         REF      4BNUM             RETURNS NEXT 4 BYTES OF E.F.
         REF      GBYTE             RETURNS NEXT BYTE OF E.F.
         REF      GBYTE0            CHECK  FIRST WORD  IF ELEMENT FILE
         REF      RCDSIZE           END OF CURRENT EF RECORD
         REF      READBIL0          CHECK EF TYPE BY GETTING 1ST RECORD
         REF      SATREF            GET STUFF FROM LIBRARIES FOR PREFS
         REF      GETSEG            SUBROUTINE USED TO CHASE DOWN
*,*                                 A LMN'S TREE STRUCTURE
         REF      DECLSTK           THE DECLARATION STACK SPD
         REF      DECLSTK1          WORD 1 OF DECLARATION STACK SPD
         REF      DECLBAS           CURRENT BASE ADDRESS OF DECLSTK
         REF      RFDFBAS           CURRENT BASE ADDRESS OF RFDFSTK
         REF      RFDFSTK           THE REF/DEF STACK SPD
         REF      RFDFSTK1          WORD 1 OF REF/DEF STACK SPD
         REF      EXPRSTK           THE EXPRESSION STACK SPD
         REF      EXPRSTK1          WORD 1 OF DECLARATION STACK SPD
         REF      EXPRBAS           CURRENT BASE ADDRESS OF DECLSTK
         REF      BSEG1             TEMPORARY HOLDER FOR SEGMENT NO.
         REF      CSEG1             DISPLACEMENT FROM TREE START TO
*,*                                 CURRENT SEGMENT'S ENTRY
         REF      CSEG2             TEMPORARY STORAGE FOR SEGMENT NO.
*,*                                 DURING REF/DEF STACK SEARCHES
         REF      CROM1             DISPLACEMENT FROM ROM TABLE START
*,*                                 TO CURRENT ROM ENTRY
         REF      CRFDF1            DISPLACEMENT FROM RFDFBAS TO
*,*                                 RFDFSTK ENTRY DURING EXPRSTK SQUEEZ
         REF      EXPRES            TEMP SAVE FOR ADDR OF RES WORD OF  EXPRESSIO
         REF      LOADBAS           ZERO BIAS TEST
         REF      CURBYTE           DISPLACEMENT INTO CARD IMAGE
*,*                                 BEING READ BY GBYTE.
         REF      SEVLEV            SEVERITY LEVEL OF LOAD MODULE
         REF      LASTCARD          FLAG SET FOR LAST CARD OF ROM
         REF      BUF               INPUT BUFFER FOR READING ROM
         REF      FCOUNT            SIZE OF DCB NAME TABLE
         REF      RSEG00            POINTER TO ROOT SEGMENT TYPE 00
         REF      DLOC              EXECUTION LOCATION COUNTER FOR
*,*                                 00 PROTECTION TYPE
         REF      LOCCT             ADDRESS OF LOCCT TABLE
         REF      MAXRFDF           SIZE OF RFDFSTK FOR LONGEST PATH
         REF      MAXEXPR           SIZE OF EXPRSTK FOR LONGEST PATH
         REF      OPENEF            OPEN PLIST FOR M:EF
         REF      LIB               SET TO 1 IF A LIBRARY LOAD
*,*                                 MODULE IS BEING PROCESSED
         REF      LOCWD             WORD 0 OF LOCCT (FLAGS)
         REF      EXPRDIS           DISPLACEMENT IN TREE TABLE TO
*,*                                 EXPRSTK DESCRIPTOR
         REF      RFDFDIS           DISPLACEMENT IN TREE TABLE TO
*,*                                 RFDFSTK DESCRIPTOR
         REF      NXROMDIS          DISPLACEMENT IN ROM TABLE TO
*,*                                 WORD HOLDING 'LAST ROM' FLAGS
         REF      SBLNKDIS          DISPLACEMENT IN TREE TABLE TO
*,*                                 SUBLINK FIELD
         REF      ROM1DIS           DISPLACEMENT IN TREE TABLE TO
*,*                                 ROM POINTER FIELD
         REF      00DIS             DISPLACEMENT IN TREE TO 00
*,*                                 PROTECTION TYPE DESCRIPTOR
         REF      TREESIZE          SIZE OF A TREE TABLE ENTRY
*,*                                 (11 WORDS)
         DEF      CALLP1            ENTRY POOINT FOR SAT
         REF      WRITELM           PLIST FOR WRITING M:LM
         REF      CLOSE             GENERAL PURPOSE M:CLOSE FPT
         REF      M:EF              DCB FOR READING ELEMENT FILES
         REF      READEF            PLIST FOR READING M:EF
         DEF      PASS1             ENTRY POINT FOR PASS1
*,*                                 (SAME AS MCP1)
         REF      ER11              ERROR CODE FOR SEVERITY LEVEL
*,*                                 EXCEEDED
         REF      ER8               ERROR CODE FOR STACK OVERFLOW
         REF      ERC               ERROR CODE FOR UNEXPECTED END
*,*                                 OF ROM
         REF      ER14              ERROR CODE FOR ILLEGAL DUMMY
*,*                                 SECTION
         REF      TXM:STAR          TEXTC FOR 'M:*'
         REF      MXRFDFSG          USED IN FINDING PATH WITH LONGEST
*,*                                 REF/DEF STACK
         REF      ER22              ERROR CODE FOR NO ROOM TO READ
*,*                                 LIBRARY REF/DEF STACK
         REF      PBUF              USED AS GENERAL GARBAGE BUFFER
*,*                                 IN PASS1
         REF      CSECFLG           FLAG SET IF SPECIAL CSECT USED
*,*                                 IN MERGING LIBRARY LMN'S.
         REF      FCOMSIZ           SIZE OF FORTRAN BLANK COMMON
         REF      LIBER             USED TO HANDLE I/O ERRORS ON M:EF
         REF      RELPAGE           1ST PAGE ADDRESS OF LIB. REF/DEF
*,*                                 STACK. USED IN FREEING LIB. REF/DEF
*,*                                 STACK PAGES AFTER USE.
         REF      M:FVP             FPT FOR M:FVP.
         REF      LIBEXPR           POINTER TO 2ND WORD OF LIBRARY
*,*                                 LMN'S SPECIAL EXPRSTK ENTRY.
         REF      SYMTOP            POINTS TO 1ST WORD OF EXPRSTK OF
*,*                                 ELEMENT FILE BEING PROCESSED
*,*                                 DURING EXPRESSION STACK SQUEEZE.
         DO       MODE=1
         REF      CORELIB           FLAG SET IF REF TO 9INITIAL OR
*,*                                 9DBINIT WAS ENCOUNTERED
         REF      M:XX              USED TO SATISFY PREF'S TO M:XX
         REF      M:UC              USED TO SATISFY PREF'S TO M:UC
         REF      MREFLAG           WILL BE NON-ZERO IF LOADING THE
*,*                                 MONITOR IN MREF MODE.
         REF      MREFTAB           DISPLACEMENT TO VALUE WORD OF
*,*                                 RFDFSTK ENTRY FOR MREF TABLE
         REF      RFLDTBSZ          REF/BREF COUNT FROM LOCCT
         REF      Y05
         REF      BINSRT            SEARCH ENTRY TO FAST SEARCH
         FIN
         REF      KICKOUT           POINTS TO LIB. LMN'S SPECIAL REF/DEF
*,*                                 ENTRY DURING EXPRSTK SQUEEZ.
         REF      FIRSTF            POINTER TO 1ST FORWARD REFERENCE
*,*                                 IN REF/DEF STACK
         REF      LASTF             POINTER TO LAST FORWARD REFERENCE
*,*                                 IN REF/DEF STACK
         REF      DECLCHK           ROUTINE TO TEST THE VALIDITY OF
*,*                                 A DECLARATION NUMBER.
         REF      CODE              HOLDING TANK FOR LOADER ERROR
*,*                                 CODES WHEN LOADER IS ABORTING
         REF      ER1X              UNEXPECTED END OF FILE ERROR
*,*                                 REPORTING ROUTINE
         REF      ERAX              ILLEGAL ROM LANGUAGE ERROR
*,*                                 REPORTING ROUTINE.
         REF      Y006
         REF      TEMPR1            SCRATCH STORAGE USED TO AVOID
*,*                                 PUSHES IN CRITICAL CODE.
         REF      FASTSRCH          FLAG = 0 IF USING BINARY SEARCH
*,*                                 OF REF/DEF STACK.
         REF      RDPTRS            ORDERED LIST OF POINTERS INTO THE
*,*                                 REF/DEF STACK USED BY THE BINARY SEARCH
         REF      RDSYMS            NO. OF ENTRIES IN RDPTRS
         REF      BINSRT1           THE BINARY SEARCH SUBROUTINE
         PAGE
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'
BNC      EQU      X'688'
         REF      MESSAGE           ROUTINE TO PRINT ERROR MESSAGE
*,*                                 AND ERROR CODE ON LOADER ERRORS.
         REF      IOMSG             MESSAGER FOR IO ERRORS
*        QUIT     ERROR,CONDITION,OUTPUT
QUIT     CNAME
         PROC
LF       EQU      %
         DO       NUM(AF)=3
         DO       AF(2)~=0
         GEN,12,20  AF(2),%+4
         FIN
         STW,AF(3) CODE
         ELSE
         DO       AF(2)~=0
         GEN,12,20  AF(2),%+3
         FIN
         FIN
         LI,R3    AF(1)
         DO       MODE=1&AF(3)=SR3
         B        IOMSG
         ELSE
         B        MESSAGE
         FIN
         PEND
SNAPIT   CNAME
         PROC
LF       CAL1,3   %+1
         DATA     0
         GEN,1,31 AFA(1),AF(1)
         GEN,1,31 AFA(2),AF(2)
         DATA     AF(3),AF(4)
         NOP
         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'
K15      EQU      X'15'
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'
K30      EQU      X'30'
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'
KFF      EQU      X'FF'
K100     EQU      X'100'
K120     EQU      X'120'
K1FF     EQU      X'1FF'
K200     EQU      X'200'
K202     EQU      X'202'
K256     EQU      X'256'
K800     EQU      X'800'
KC00     EQU      X'C00'
K2000    EQU      X'2000'
K3FFF    EQU      X'3FFF'
K7FFF    EQU      X'7FFF'
K8000    EQU      X'8000'
K10000   EQU      X'10000'
K1FFFF   EQU      X'1FFFF'
K20000   EQU      X'20000'
K30000   EQU      X'30000'
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'
KTE      EQU      'E'
KTR      EQU      'R'
         PAGE
MESP     CNAME
         PROC
         AWM,CF(2)  EXPRSTK1
         LCW,CF(2)  CF(2)
         AW,CF(2) EXPRSTK
         STW,CF(2) EXPRSTK
         CW,CF(2) RFDFSTK
         BG       %+3
         LI,R3    ER8
         B        MESSAGE
         SW,CF(2) RDSYMS            DONT CLOBBER THE CORT TABLE EITHER
         AI,CF(2) -511              +PAGE SPACE
         CW,CF(2) RDPTRS
         BG       %+2
         DATA     FASTSRCH          WITHOUT DISCONTINUING IT
         PEND
         SPACE    10
MRSP     CNAME
         PROC
         MSP,CF(2)  RFDFSTK
         LW,CF(2)  RFDFSTK
         AND,CF(2) M17
         STW,CF(2)  RFDFSTK
         CW,CF(2)  EXPRSTK
         BL       %+3
         LI,R3    ER8
         B        MESSAGE
         AI,CF(2) 511               LEAVE A SPACER PAGE
         CW,CF(2) RDPTRS            BEFORE RUNNING INTO SORT TABLE
         BL       %+2
         DATA     FASTSRCH
         PEND
         PAGE
PASS1    EQU      %
         PSW,SR4  *R0
*                                   INITIALIZE TO THE ROOT SEGMENT.
FIRSTSEG LI,D1    K0
         STW,D1   CSEG1
         STW,D1   BSEG1
         DO       MODE=1
         MTW,0    MREFLAG
         BE       FIRSTSEG8         OTHER THAN CPV SYSGEN,BRANCH
         STW,D1   DLOC              FOR CSECT ALLOCATION
         FIN
FIRSTSEG8 EQU     %
         B        RFDFPTR
*                                   PICK UP THE SEGMENTS FIRST ROM
*                                   TABLE ENTRY.
*
FIRSTROM LW,R4    CSEG1
         AI,R4    ROM1DIS
         LW,R4    *R1,R4
         LH,R4    R4
*
NEXTROM  STW,R4   CROM1
         B        LOCROM            GO OPEN THE ELEMANT FILE
*                                    RETURNS TO LOCROMX
LOCROMX  LI,SR4   NEWROM            EXIT FOR NONLIBRARY CALL
CALLP1   PSW,SR4  *R0
         BAL,SR4  READBIL0          READ FIRST RECORD
         B        ER1X              BAD STUFF
         BAL,SR4  CHECKROM
         B        PULLEXIT
CLP1     LCI      3                 OBJECT, PROCESS IT
         PSM,R1   *R0
         BAL,SR4  LP1
         LCI      K3
         PLM,R1   *R0
*
*                                   CHECK FOR ANOTHER ROM IN THE SAME
*                                   FILE, RETURN +1 IF NO MORE, ELSE +2.
NUTHER   BAL,SR4  READBILI
         B        PULLEXIT
         BAL,SR4  CHECKROM
         B        NUTHER
         BAL,SR4  MONSQZ            SQUEEZE AFTER EACH ROM IF M:MON
         B        CLP1              THEN READ THE OBJECT
*                                   CLOSE THE ELEMENT FILE. CHECK THE
*                                   ROM TABLE FOR MORE FILES IN
*                                   THIS SEGMENT.
*
NEWROM   EQU      %
         LI,R5    M:EF
NEWROM1  CAL1,1   CLOSE
         BAL,SR4  MONSQZ            SQUEEZE EXPR STK IN M:MON
         LW,R4    CROM1
         AI,R4    NXROMDIS
         LW,R5    *R4,R2
         AI,R4    7-2               ROMSIZE-NXROMDIS
         CI,R5    X'40'
         BANZ     NEXTROM
*                                   SATISFY PREF'S
         BAL,SR4  SATREF
*                                   PURSUE OVERLAY STRUCTURE
*
         LI,R5    X'8000'           SET OVERLAY BASE FOR M:MON
         STW,R5   DLOC              IF WERE NOT IN THE ROOT
         LI,R5    BSEG1
         LI,R4    CSEG1
         LW,D1    CSEG1
         BAL,SR4  GETSEG
*                                   SUB-LINK
         B        RFDFPTR
*                                   OVERLAY-LINK
         B        OLP2
*                                   BACK TO ROOT-SEG
         LI,R4    K0
         STW,R4   CSEG1
         B        OLP2
*                                   THIS ROUTINE ESTABLISHES THE REF/
*                                   DEF AND EXPRESSION STACK ADDRESSES
*                                   IN THE TREE TABLE AND FORCES THE
*                                   STACK TO AN EVEN BOUNDARY FOR EACH
*                                   SEGMENT.
*
RFDFPTR  LW,R4    CSEG1
         AI,R4    RFDFDIS
         CI,R4    RFDFDIS
         BNEZ     %+3
         LW,R6    RFDFBAS
         B        RFDFPTR1
         LW,R6    RFDFSTK
         AI,R6    K1
         CI,R6    K1
         BAZ      RFDFPTR1
         AI,R6    K1
         LI,R7    K1
         MRSP,R7
RFDFPTR1 STW,R6   CRFDF1            SET START IN CASE M:MON
         SLS,R6   -1
         LW,R7    M16
         STS,R6   *R1,R4
*
         LW,R5    CSEG1
         AI,R5    EXPRDIS
         LW,R6    EXPRSTK
         AI,R6    KN1
         CI,R6    K1
         BAZ      RFDFPTR2
         LW,R7    Y018
         STW,R7   *R6
         AI,D1    EXPRDIS
         LI,R7    X'10000'
         AWM,R7   *D1,R1
         AI,R6    KN1
         LI,R7    K1
         MESP,R7
RFDFPTR2 RES
         STW,R6   SYMTOP            DONT SQUEEZE ROOT IN OVERLAYS
         SLS,R6   -1                DW ADDR
         STW,R6   *R1,R5
         B        FIRSTROM
Y018     DATA     X'01800000'
         DO       MODE=1
TXMREF   TEXTC    'MREF'
MREFEXPR DATA     X'04032202'
MREFCBS  GEN,8,24 5,BA(TXMREF)
         FIN
*                                   WRITE OUT  REF/DEF STACK IF NOT ROOT
*                                   SEGMENT AND INVERT AND WRITE OUT
*                                   EXPRESSION STACK. SAVE MAX REF/DEF
*                                   AND EXPR STACK SIZE FOR PASS 2
*                                   MEMORY ALLOCATION
*
OLP2     XW,D1    CSEG1
OLP23    EQU      %
         LW,R7    CSEG1
         BNEZ     CHKPREF           CHECK FOR PREFS IN HIGHER SEGMENT
OLP234   EQU      %
         AW,R7    R1
         MTB,1    *R7
         LB,R6    *R7
         LI,R5    K0
         STB,R5   *R7,R6
         LW,R5    CSEG1
         AI,R5    RFDFDIS
         LW,R5    *R5,R1
         LH,R6    R5
         SLS,R6   2
        SLS,R5   1
         LW,R4    RFDFSTK1
         AND,R4   M15
         CW,R4    MAXRFDF
         BLE      %+4
         STW,R4   MAXRFDF
         LW,R4    CSEG1
         STW,R4   MXRFDFSG
         LW,R4    CSEG1
         BEZ      OLP29
         CAL1,1   WRITELM
         SLS,R6   -2
         LCW,R6   R6
         MSP,R6   RFDFSTK
         LW,R5    RFDFSTK
         AND,R5   M17
         STW,R5   RFDFSTK
OLP29    LI,R5    K1
         LB,R6    *R7
         STB,R5   *R7,R6
         LW,R5    CSEG1
         AI,R5    EXPRDIS
         LW,R5    *R5,R1
         LH,R6    R5
         AND,R5   M16
         SLS,R5   1
         SW,R5    R6
         LW,D4    R5
         AI,D4    K1
         LW,SR3   R6
         BEZ      OLP2G
OLP27   LW,D3    *R5,R6
         XW,D3    *D4
         STW,D3   *R5,R6
         AI,D4    1
         AI,R6    -1
         ANLZ,D2  OLP27
         CW,D2    D4
         BG       OLP27
OLP2G    EQU      %
         AI,R5    K1
         LW,R6    SR3
         SLS,R6   2
         CAL1,1   WRITELM
         MTB,-1   *R7
         LW,R4    EXPRSTK1
         AND,R4   M15
         CW,R4    MAXEXPR
         BLE      %+2
         STW,R4   MAXEXPR
         SLS,R6  -2
         LCW,R6   R6
         MESP,R6
         LW,D2    CSEG1
         CI,D1    K0
         BNE      OLP25
         AI,D2    SBLNKDIS
         LW,R6    CSEG1
         BNEZ     OLP26
STANDARD EQU      %
*                                   THIS ROUTINE SEARCHES THE REF/DEF
*                                   STACK FOR PREF'S TO AN F: OR M:
*                                   NAME.
         LW,D2    LOCWD
         CI,D2    X'10'
         BANZ     OVRGAP
         MTW,0    LOADBAS           IF ZERO BIAS, NO LOADER DCBS
         BEZ      OVRGAP
         LW,D2    RFDFSTK
         AI,D2    1
         INT,R7   6,R1
         LW,D1    6,R1
         LH,D1    D1
         SLS,R7   1
         AW,D1    R7
         LW,R7    RFDFBAS
NXTABS   EQU      %
         LB,R6    *R7
         CI,R6    X'03'
         BE       NAKITUP1
         LW,R6    Y00FFFF
         AND,R6   3,R7
         CW,R6    TXF:
         BE       FNDFILE0
         CW,R6    TXM:
         BE       ADDCBTBL
         LI,SR1   7
         CW,SR1   SEVLEV
         BLE      NAKITUP1          IF SEVLEV IS LESS THAN 7,
         LW,R6    0,R7              CHECK FOR NON-DCB PREFS
         AND,R6   Y000F
         CW,R6    Y0002
         BNE      NAKITUP1
         STW,SR1  SEVLEV
         B        NAKITUP1
*                                   IF ONE IS FOUND THE PREF IS CHANGED
*                                   TO A 01 PROTECTION TYPE DUMMY
*                                   SECTION TO-BE-BUILT WITH X'8'
*                                   DOUBLE WORDS AND THE SIZE IS
*                                   ACCOUNTED FOR IN THE TREE TABLE.
ADDCBTBL EQU      %
         DO       MODE=1
         LCI      2
         LM,8     3,7
         LI,6     2
         CD,8     SPECDCBS-2,6
         BE       SPECREF
         BDR,6    %-2
         DO       CFU=1
         CW,8     TXM:STAR          THE M* DCB IS A SPECIAL
         BNE      FNDFILE0            CASE CONSISTING OF 41 WDS
         LI,R6    K2                  OF ZEROES
         AWM,R6   FCOUNT
         LI,R6    X'15'
         B        FNDFILE3
         FIN
         FIN
FNDFILE0 EQU      %
         AI,R7    3
         LB,R6    *R7
         BNEZ     %+3
         AI,R7    KN3
         B        NAKITUP1          SKIP IF A 'TRANSPARENT' DEF
         AI,R6    8                 SIZE DCBTABLE ENTRY IS
*                                   NO OF TEXT WORDS+1 WORD DCB POINTER
         SLS,R6   -2
         AI,R7    KN3
         LW,SR1   Y000F
         AND,SR1  0,R7
         CW,SR1   Y0002             CHECK FOR A PREF
         BE       %+3
         CW,SR1   Y0003             OR A DSECT
         BNE      NAKITUP1          DO NOT ADD ANYTHING ELSE TO TABLE
         AWM,R6   FCOUNT            NO, ALLOW ROOM IN DCB NAME TABLE
         CW,SR1   Y0002             IS IT A PREF
         BNE      NAKITUP1
FNDFILE1 EQU      %
         DO       MODE+BPMLIB=1
         LI,R6    X'1A'             34 WORDS FOR CP-V (FOR EXPIRE)
         ELSE
         LI,R6    X'18'             30 WORDS FOR BPM
         FIN
         DO       MODE=1
         DO       CFU=1
FNDFILE3 EQU      %
         FIN
         FIN
         OR,R6    0,R7
         DO       MODE=0[BPMLIB=1
         OR,R6    Y004B
         ELSE
         OR,R6    Y008B
         FIN
         STW,R6   0,R7
         SLS,R6   16
         DO       MODE=0[BPMLIB=1
          PSW,R7  *R0
         BAL,SR4  TM100
         PLW,R7   *R0
         AWM,R6   7,R1              01 SIZE
         ELSE
         AWM,R6   9,R1
         FIN
NAKITUP1 LB,R6    *R7
         AW,R7    R6
         CW,R7    D1
         BL       NXTABS
OVRGAP   EQU      %
         PLW,SR4  *R0
         B        *SR4
OLP25    AI,D2    SBLNKDIS
         INT,R6   *D2,R1
         CW,R7    D1
         BE       OLP24
OLP26    AI,D2    3-4               ROM1DIS-SBLNKDIS
         INT,R6   *D2,R1
         STW,R7   CSEG1
         B        OLP23
OLP24    STW,D1   CSEG1
         B        RFDFPTR
         DO       MODE=1
SPECREF  EQU      %                 IF A PREF TO M:XX OR M:UC
         LW,SR1   Y000F
         AND,SR1  0,R7
         CW,SR1   Y0002             SKIP IF NOT A PREF
         BNE      NAKITUP1
         EXU      VALDCB-1,6        CHANGE TO DEF BY SATISFYING
         STW,8    1,R7              FROM :J0
         LW,8     DEFWD
         STW,8    0,R7
         LI,8     X'100'
         STW,8    2,R7
         B        NAKITUP1
VALDCB   LI,8     M:UC
         LI,8     M:XX
DEFWD    DATA     X'05100001'
         FIN
         DO       MODE~=0
Y008B    DATA     X'8B0000'
         BOUND    8
SPECDCBS TEXTC    'M:UC'
         TEXTC    'M:XX'
         FIN
         PAGE
*                                   THIS ROUTINE CHECKS FOR PREFS IN
*                                   HIGHER SEGMENTS UNLESS SEVLEV IS >= 7
CHKPREF  EQU      %
         LI,R6    7
         CW,R6    SEVLEV
         BLE      OLP234
         LW,R5    CSEG1
         AI,R5    RFDFDIS
         LW,R5    *R5,R1
         LH,R6    R5
         SLS,R5   1
         AW,R6    R5
CHKPREF1 LW,R4    0,R5
         AND,R4   Y000F
         CW,R4    Y0002
         BE       CHKPREF2          FOUND A PREF - UPDATE SEVLEV
         LB,R4    *R5
         AW,R5    R4
         CW,R5    R6
         BL       CHKPREF1
         B        OLP234
CHKPREF2 LI,R6    7
         STW,R6   SEVLEV
         B        OLP234
         PAGE
         DO       MODE=1
*                                   THIS ROUTINE DECODES AND EVALUATES
*                                   AN EXPRESSION IF IT IS NOT ALREADY
*                                   MARKED AS EVALUATED. R6 POINTS TO
*                                   THE EXPRESSION. SR2 IS SET TO Y008
*                                   IF THE EXPRESSION IS SUCCESSFULLY
*                                   EVALUATED.
EVEXP    LW,R7    0,R6
         CW,R7    Y00C                                                  730
         BANZ     *SR4
EVEXP1   PSW,SR4  *R0                                                   730
         LI,SR1   K0
         LH,D1    *R6
         AND,D1   M6
         LCW,D1   D1
         LW,R7    D1
         AW,R7    R6
         AI,R7    K1                POINT TO RESOLUTION
         STW,R7   EXPRES            SAVE FOR FUTURE USE
         STW,SR1  0,R7              CLEAR THE RESOLUTION WORD
         LI,R7    K1
         LI,D4    K3
*                                   THIS IS THE GENERAL EXPRESSION
*                                   CONTROL BYTE DECODER.
EVWHATEC AI,R7    K1
         BDR,D4   %+3               BECAUSE STACK IS FLIPPED
         AI,R7    KN8
         LI,D4    4
         LB,D2    *R6,R7
         BE       EVWHATEC
         CI,D2    K2
         BE       EVEXPEND
         BL       EVADCON
         LW,R4    D2
         SLS,R4   -2
         CI,R4    KC
         BL       EVGETVAL
         BE       EVCHGRES
         BG       AABS
*                                   ADD CONSTANT.
EVADCON  AW,SR1   *D1,R6
EVINCWD  AI,D1    KN1
         B        EVWHATEC
*                                   CHANGE RESOLUTION.
EVCHGRES LW,R5    EXPRES            ADDR OF RES WORD
         AI,R5    -2                FOR WHATRES
         LI,R3    K3                NEW RESOLUTIN
         AND,R3   D2
         LCI      2                                                     4730
         PSM,R1   *R0                                                   4730
         BAL,SR4  WHATRES
         LW,R2    R3                NO SHIFT IF ABS
         SW,R2    R3
         SLS,SR1  0,R2
         LI,R1    0                 CLEAR AND SET RESOLUTION
         STW,R1   *EXPRES
         MTB,1    *EXPRES,R3
NEXTEC1  LCI      2                                                     4730
         PLM,R1   *R0                                                   4730
         B        EVWHATEC
AABS     LI,R4    3
         AND,R4   D2                GET RESOLUTION
         CI,D2    8                 ADD OR SUBTRACT
         BAZ      %+2
         MTB,-2   *EXPRES,R4
         MTB,1    *EXPRES,R4
         B        EVWHATEC
EVEXPEND LW,SR2   Y008
*                                   EXPRESSION END. THE EXPRESSION
*                                   IS MARKED EVALUATED.
         STS,SR2  0,R6
*                                   THE VALUE OF THE EXPRESSION AND
*                                   THE RESOLUTION ARE INSERTED INTO
*                                   THE ENTRY IN THE REF/DEF STACK
*                                   IF IT IS NOT A CORE EXPRESSION AND
*                                   THE REF/DEF ENTRY IS MARKED DEFINED.
         LW,R7    EXPRES
         INT,R4   1,R7              DESTINATION
         AW,R4    R1
         LW,R4    RFDFDIS,R4         STACK INFO
         AND,R4   M16
         SLS,R4   1
         AW,R4    R5
         LW,R5    Y001
         CW,R5    0,R4
         BANZ     EVEXPUN1
         STS,R5   0,R4              MARK EVALLUATED
         STW,SR1  1,R4              SET VALUE
         LW,R5    0,R7              AND RESOLUTION
         STW,R5   2,R4
*                                   EXIT.
EVEXPUN1 PLW,SR4  *R0
         B        *SR4
*                                   THIS ROUTINE PICKS UP THE VALUE OF
*                                   A REF/DEF ENTRY POINTED TO BY AN
*                                   EXPRESSION. IF THE DEF DOES NOT
*                                   HAVE A VALUE THE EXPRESSION IS STILL
*                                   UNDEFINED. THE VALUE IS SHIFTED
*                                   TO THE APPROPRIATE RESOLUTION
*                                   ACCORDING TO THE RESOLUTION OF
*                                   THE DEF. THE RESOLUTION OF THE
*                                   EXPRESSION IS ADJUSTED APPROPRIATELY
EVGETVAL INT,R4   *D1,R6
         AW,R4    R1
         LW,R4    RFDFDIS,R4
         AND,R4   M16
         SLS,R4   1
         AW,R5    R4
         LW,SR4   0,R5
         CW,SR4   Y001
         BAZ      EVEXPUN1          NOT EVALUATED, GIVE UP
         LCI      K2
         PSM,R1   *R0
         LI,SR2   K3                GET RESOLUTION
         AND,SR2  D2
         BAL,SR4  WHATRES
         LW,R2    SR2               SET ABS (NO SHIFT)
         LW,R4    1,R5              GET VALUE
         SW,R2    SR2
         SLS,R4   0,R2
         SCS,D2   -4                PUT SUBTRACT BIT IN SIGN
         AI,D2    100               MAKE BDR TAKE IF NOT NEG
         BDR,D2   %+2
         LCW,R4   R4
         AW,SR1   R4
         LW,R4    2,R5              GET RESOLUTION
         SLS,R2   3                 SHIFT IT TO NEW VALUE
         SLS,R4   0,R2
         LI,R2    KN4
         LW,R3    *EXPRES           EXPR CURRENT RESOLUTION
EVFIXRES EQU      %
         LB,R1    R5,R2
         LB,D3    R4,R2
         BDR,D2   %+2
         LCW,R1   R1
         AW,D3    R1
         STB,D3   R4,R2
         BIR,R2   EVFIXRES
         STW,R3   *EXPRES
         LCI      K2
         PLM,R1   *R0
         B        EVINCWD
         PAGE
*                                   THIS ROUTINE DETERMINES RESOLUTION
*                                   OF A REF/DEF (POINTED TO BY R5).
*                                   RETURNS TO *SR4 IF MIXED OR 0
*                                   TO *SR4+1 IF BT,HW,WD,DW
*                                   WITH 0,1,2,3 RESP. IN R2
WHATRES  RES
         LI,R2    KN4
         LW,R1    2,R5
         LB,R4    R1
         SLS,R1   8
         BNEZ     %+2
         BIR,R2   %-3
         AI,R1    0
         BNEZ     WHATRES5
         AI,R4    1
         CI,R4    X'FD'
         BANZ     WHATRES5
         AI,R2    K4
         AI,SR4   1
WHATRES5 B        *SR4
*                                   THIS ROUTINE GOES THRU THE EXPRESSIO
*                                   STACK ATTEMPTING TO EVALUATE EACH
*                                   EXPRESSION IN ORDER. THE PROCESS
*                                   IS REPEATED UNTIL A PASS THRU THE
*                                   STACK HAS BEEN MADE WITH NO
*                                   EXPRESSIONS EVALUATED.
*                                   NOTE: EXPR STK IS FLIPPED.
MONSQZ   MTW,0    MREFLAG           ONLY FOR M:MON (MUST BE ALL DATA)
         BEZ      *SR4
         PSW,SR4  *R0
         LW,R4    CRFDF1            START OF NEW RFDF STK ENTRIES
NEXTSEGB RES
         LW,R5    0,R4              RESET THE 'FF' HIGH-ORDER USED
         AND,R5   Y0007             BYTES OF ALL FORWARD REFS
         CI,R5    X'50000'
         BNE      NEXTSEG8
         AI,R4    K3
         STB,R5   *R4
         AI,R4    1
         B        NEXTSEGA
DCSECTE  MTB,-3   R5                IF COUNT ISNT 3, IS PROLLY
         BNEZ     NEXT              DSECT
         LW,R6    R4                SAVE ADDR FOR LIB SECTS
         B        DCSECTS
*
DCSECT6  INT,SR4  0,R6              SIZE OF THE WHOLE THING
         STS,SR4  0,R4              SET IN SYSGEN ONE
         LW,R5    1,R6              ADDR
         STW,R5   DLOC
         B        DCSECT6S
NEXTSEG8 RES
         CI,R5    X'30000'          ALLOCATE ALL 00 SECTS
         BE       DCSECT2
         CI,R5    X'60000'
         BE       DCSECT6           GET LIBRARY CSECTS TOO
         CI,R5    X'40000'
         BNE      NEXT
         LW,R5    1,R4              TYPE 04, IF VALUE FIELD IS NONZERO
         BNEZ     NEXT              ALLOCATION HAS ALREADY BEEN MADE
DCSECT2  LW,R5    0,R4
         CW,R5    Y00C              ONLY TYPE 00
         BANZ     NEXT
         CW,R5    Y001
         BANZ     DCSECTE
         INT,SR4  0,R4              GET SIZE
DCSECT6S LI,R5    K100
         STW,R5   2,R4              SET WORD RESOLUTION
         LW,R5    Y001
         STS,R5   0,R4              EVALUATED
DCSECTS  LW,R5    DLOC              AND VALUE
         STW,R5   1,R4
         SLS,SR4  1
         AWM,SR4  DLOC
NEXT     RES
         LB,R5    *R4
         AW,R4    R5
NEXTSEGA RES
         CW,R4    RFDFSTK
         BL       NEXTSEGB
         STW,R4   CRFDF1            SET NEW START
EVEXPRS1 LI,SR2   K0
         LW,R6    SYMTOP
         BAL,SR4  %+3               SET RETURN
         LB,R7    *R6
         SW,R6    R7
         CW,R6    EXPRSTK
         BG       EVEXP
         CW,SR2   Y008
         BANZ     EVEXPRS1
         PAGE
*                                   SQUEEZ EXAMINES THIS EF'S EXPR
*                                   STACK REMOVING THOSE DEFINING
*                                   EXPRESSIONS FOR DEFS AND FWD REFS
*                                   (HAVING CORRES. ENTRIES IN THE R/D
*                                   STACK) WHICH HAVE BEEN EVALUATED BY
*                                   EVEXSQZ. NOTE THAT CORE EXPRS ARE
*                                   RETAINED AS WELL AS ALL UNEVALUATED
*                                   EXPR ENTRIES.
*                                   NOTE: EXPR STK IS FLIPPED
SQUEEZ   EQU      %
         LI,R6    0
         STW,R6   KICKOUT
         LW,R6    SYMTOP            BASE OF THIS EF'S EXPRSTK
         B        SQZADV1
*                                   SQUEEZE OUT THIS ENTRY.
SQZADV   SLS,R4   -8
         AWM,R4   KICKOUT           NO. OF WORDS REGAINED
         SW,R6    R4                ADVANCE TO NEXT ENTRY
SQZADV1  CW,R6    EXPRSTK
         BLE      SQZEXIT           END OF EF'S   STACK
         LH,R4    *R6
         CI,R4    K384
         BE       SQZLIB
         CI,R4    K80
         BANZ     SQZADV            CHECK NEXT ENTRY
*                                   UNEVALUATED ENTRIES MUST BE MOVED
*                                     INTO SQUEEZED STACK
SQZMOVE  SLS,R4   -8
SQZMOVE1 SW,R6    R4
         LW,R5    KICKOUT           ANY MOVEMENT
         BEZ      SQZADV1           NO
         AW,R5    R6
         LW,SR1   *R6,R4
         STW,SR1  *R5,R4
         BDR,R4   %-2
         B        SQZADV1           R5 & R6 ALREADY POINT TO NXT ENTRIES
*                                   THE SPECIAL EXPR ENTRY SAYS A LIB
*                                   LMN'S STACK HAS BEEN FOUND.
SQZLIB   EQU      %
         LW,R3    -1,R6             DISP OF SPECIAL REF/DEF ENTRY
         AW,R3    RFDFBAS
         LW,D2    2,R3              EXPR DISP FIELD OF SPECIAL R/D ENTRY
         SW,D2    KICKOUT             FOR LIB LMN MUST BE DECREMENTED BY
         STW,D2   2,R3                VALUE IN KICKOUT
         SLS,D2   -16               SIZE OF LIB LMN'S EXPR STACK
         LCW,D2   D2
         AW,D2    R6                D2 POINTS TO END OF LIB LMN'S STACK
         LI,D3    K0                INITIALIZE CNT OF ENTRIES SQUEEZED
*                                     FROM LIB LMN'S EXPR STACK
*                                     LMN'S STACK
         AI,D2    KN3               INCLUDE SPECIAL ENTRY IN STACK
         B        %+4               SANS TEST
SQZLIB2  EQU      %
         LH,R4    *R6
         CI,R4    K80
         BANZ     SQZLIB6
         SLS,R4   -8                CURRENT ENTRY HAS NOT BEEN EVALUATED
         SW,R6    R4                  AND MUST BE RETAINED AS PART OF
         LW,R5    KICKOUT
         BEZ      SQZLIB4
         AW,R5    R6
         LW,SR1   *R6,R4
         STW,SR1  *R5,R4
         BDR,R4   %-2
SQZLIB4  EQU      %
         CW,R6    D2                HAS END OF LIB LMN'S STACK BEEN HIT
         BNE      SQZLIB2             NO
         SLS,D3   16
         LW,D2    2,R3              EXPR SIZE FIELD OF SPECIAL R/D ENTRY
         SW,D2    D3                  FOR LIB LMN MUST BE DECREMENTED BY
*                                     VALUE IN D3
         BNEZ     %+2               TO AVOID PROBLEMS IN MAPER, MUST NOT
         LI,D2    K384                ALLOW RES WD TO BECOME ZERO
         STW,D2   2,R3
         AI,D2    -X'10000'         SCRUB K384 IF THERES NOTHING LEFT
         BGEZ     SQZADV1
         MTW,3    KICKOUT
         B        SQZADV1           END OF THIS LIB LMN'S STACK SQUEEZE
SQZLIB6  EQU      %
         SLS,R4   -8                CURRENT ENTRY HAS BEEN EVALUATED.
         AW,D3    R4                D3 = CNT OF REMOVED ENTRIES
*                                   FROM LIB'S STACK
         SW,R6    R4
         AWM,R4   KICKOUT
         B        SQZLIB4
*                                   BEFORE EXITING, VARIOUS TREE TABLE
*                                   POINTERS MUST BE ADJUSTED.
SQZEXIT  EQU      %
         LW,D1    KICKOUT           ADJUST STACK POINTER
         AWM,D1   EXPRSTK           DOUBLEWORD AND
         LCW,D1   D1                EXPR WORD ENTRY IN TREE
         AWM,D1   EXPRSTK1
         SLS,D1   16
         LW,R6    CSEG1              ADJUST PROPER COUNTER
         AW,R6    R1
         AWM,D1   EXPRDIS,R6
         LW,D1    EXPRSTK           RELEASE  UNUSED  PAGES
         AW,D1    M:FVP
         AI,D1    -512
         CAL1,8   D1
         BCR,8    %-2
PULLEXIT RES
SQZEND   PLW,SR4  *R0
         B        *SR4
K384     EQU      X'0384'
         FIN
         PAGE
*                                   THIS ROUTINE OPENS M:EF TO THE
*                                   APPROPRIATE FILE (DISC OR LABELED
*                                   TAPE). IT THEN READS THE 1ST RECORD
*                                   (1ST CARD OR 'HEAD' AND GOES
*                                   TO CHECKROM.)
LOCROM   RES                         RETURNS TO LOCROMX
         LW,D2    CROM1
         AW,D2    R2
         LI,R6    K2
         CW,R6    *D2,R6
         BANZ     %+2
         LI,R6    K1
         LI,R7    3
         STS,R6   OPENEF+1
         LI,D1    OPENEF+8
         BAL,SR4  MOVER
         MTW,1    D1
         LI,R7    K2
         BAL,SR4  MOVER
         MTW,1    D1
         LI,R7    K2
         BAL,SR4  MOVER
*
LOCROM3  EQU      %
         LI,SR1   LIBER             SET ERR/ABN ADDR
         CAL1,1   OPENEF
         DO       MODE=1
         MTW,0    MREFLAG           IF MREF MODE,
         BEZ      LOCROM3B            UPON FINDING ROM GPHGP
         MTW,0    MREFTAB           FORCE CSECT & DEF
         BNEZ     LOCROM3B          R/D ENTRIES & EXPR
         LW,R3    MREFCBS           IS IT ROMNAME 'MREF'
         CBS,R3   BA(OPENEF+8)-BA(TXMREF)
         BNE      LOCROM3B
         LCI      6
         PSM,R2   *R0
         LW,R2    RFLDTBSZ
         AWM,R2   RFLDTBSZ          2 WDS PER MREF TABLE ENTRY
         SLS,R2   16
         AWM,R2   00DIS,R1
*                                   BUILD CSECT & DEF ENTRIES
*                                     FOR MREF
         SLS,R2   -16               SIZE IN DOUBLEWDS
         AW,R2    Y0304             CSECT:  WD 0
         LW,R7    RFDFSTK
         LI,R3    K0                        WD 1, VALUE WD
         LI,R4    K1                        WD 2, RES
         LI,R5    K8
         MRSP,R5
         LW,R5    Y0008
         AWM,R5   RFDFDIS,R1        UPDATE R/D SIZE IN TREE
         LCI      3
         STM,R2   1,R7              ADD CSECT ENTRY TO R/D STK
         AI,R7    K2
         LW,R2    Y05               DEF:  WD 0
         LW,R5    TXMREF                  WDS 3-4, NAME
         LW,R6    TXMREF+1
         LCI      5
         STM,R2   2,R7              ADD DEF ENTRY TO R/D STK
         LW,D4    R7                PUT IN SORT TABLE
         AI,D4    5
         MTW,0    FASTSRCH
         BNEZ     %+2
         BAL,SR4  BINSRT1
         LW,R7    D4
         AI,R7    -5
         SW,R7    RFDFBAS
         STW,R7   MREFTAB           SAVE POINTER TO VALUE WD.
         LW,R5    MREFEXPR          ADD DEFINING EXPR
         LW,R4    R7                FOR THE MREF DEF TO
         AI,R4    K2                THE EXPR STK.
         LI,R3    K100
         LW,R2    R7
         AI,R2    KN1
         LW,R7    EXPRSTK
         LI,R6    4
         MESP,R6
         LW,R6    Y0004
         AWM,R6   EXPRDIS,R1
         LCI      4
         STM,R2   -4,R7
         LCI      6
         PLM,R2   *R0
LOCROM3B EQU      %
         FIN
         B        LOCROMX           GO PROCESSIT
*                                   THIS ROUTINE USES GBYTE TO RUN THE
*                                   APPROPRIATE CHECKS ON THE RECORD
*                                   READ (SEQUENCE,CHECKSUM,ETC.). THEN
*                                   IF THE 1ST BYTE IS NOT -C (ROM) IT
*                                   CALLS ADLDMD, ELSE RETURNS.
*
CHECKROM PSW,SR4  *R0
CHCKROM1 BAL,SR4  GBYTE0
         BCS,8    ADLDMD
         PLW,SR4  *R0
         AI,SR4   K1
         B        *SR4
         PAGE
*                                   THIS ROUTINE 1ST READS THE TREE OF
*                                   THE LOAD MODULE IN RIGHT ABOVE THE
*                                   REF/DEF STACK.
ADLDMD   EQU      %
         PSW,R2   *R0
         LI,R5    K0
         STW,R5   CSECFLG
         LI,R5    K1
         STW,R5   LIB
         LI,R5    PBUF
         MTB,4    *R5
         LB,R7    *R5
         LI,R6    K4
         LB,D1    TXTREE,R6
         STB,D1   *R5,R7
         BDR,R7   %+1
         BDR,R6   %-3
         LW,R4    RFDFSTK
         AI,R4    K1
         LI,R6    K30
         DO       MODE=1
         REF      CHKLM             ROUTINE USED TO ALLOCATE BUFFER
*,*                                 PAGES FOR READING LOAD MODULES
         XW,R4    R5
         BAL,11   CHKLM
         XW,R5    R4
         FIN
         CAL1,1   READEF
*                                   IT THEN READS IN THE EXPRESSION
*                                   STACK TO ITS APPROPRIATE PLACE
*                                   AND INVERTS IT.
         LW,D2    R4
         LCI      3
         LM,SR1   1,R4
         STM,SR1  *R5
         MTB,1    *R5
         AI,D2    EXPRDIS+1
         LB,R6    *R5
         LI,R7    K1
         STB,R7   *R5,R6
         LW,D1    *D2
         LW,R4    CSEG1
         AI,R4    EXPRDIS
         AND,D1   MN16
         BNEZ     %+3
         LW,R4    EXPRSTK
         B        NOEXPR
         AW,D1    Y0003             ADD SPECIAL EXPR ENTRY SIZE TO TREE
         AWM,D1   *R4,R1
         SLS,D1   -14
         LW,R6    D1
         LI,D1    K3                SIZE OF SPECIAL EXPR STACK ENTRY
         MESP,D1
         LW,R4    EXPRSTK
         LW,SR2   Y038402           PREFACE LIB LMN'S EXPR STACK WITH
         STW,SR2  2,R4                SPECIAL 3-WD ENTRY
         LI,SR2   K100                (SIZE=3, DISP=4, EVALUATED)
         STW,SR2  0,R4              WD RESOLUTION
         LW,SR2   R4
         AI,SR2   K1
         STW,SR2  LIBEXPR           SAVE PTR TO SECOND WD OF ENTRY
         LH,D1    *D2
         LW,R4    EXPRSTK
         SW,R4    D1
         MESP,D1
         LH,D1    *D2                                                   726
         CI,R6    0
         BE       NOEXPR
         DO       MODE=1
         XW,R4    R5
         BAL,11   CHKLM
         XW,R5    R4
         FIN
         CAL1,1   READEF
NOEXPR   EQU      %
         LH,R6    *D2
         LW,SR2   R4
         LW,SR4   SR2
         AW,SR4   R6
         LW,SR3   SR2
         AI,SR3   KN1
         LH,R6    *D2                                                   726
         BEZ      ADLDMD1                                               726
ADLDMD2  LW,SR1   *SR2
ADLDMD3  XW,SR1   *SR3,R6
         STW,SR1  *SR2
         BIR,SR2  %+1
         BDR,R6   %+1
         ANLZ,R7  ADLDMD3
         CW,R7    SR2
         BG       ADLDMD2
*                                   ALL EXPRESSIONS ARE MASKED AS
*                                   UNEVALUATED.
         AI,SR4   KN1
         LW,SR2   SR4
CLREXPR  LI,R6    K0
         LW,R7    Y008
         STS,R6   *SR4
         LW,SR1   *SR4                                                  726
         CW,SR1   Y004                                                  726
         BAZ      CLREXPR1                                              726
*                                   IF THE EXPRESSION IS A CORE
*                                   EXPRESSION THE DESTINATION WORD
*                                   IS ADJUSTED TO BE RELATIVE TO THE
*                                   LOAD  MODULE BASE.
         LH,R7    *SR4                                                  726
         AND,R7   M6                                                    726
         AI,R7    -2                                                    726
         LCW,R7   R7                                                    726
         LW,SR1   *SR4,R7                                               726
         LW,R6    BUF+2
         AND,R6   M16                                                   726
         SLS,R6   1                                                     726
         SW,SR1   R6                                                    726
         STW,SR1  *SR4,R7                                               726
CLREXPR1 LB,SR1   *SR4                                                  726
         SW,SR4   SR1
         CW,SR4   SR3
         BG       CLREXPR
*                                   IT THEN READ IN THE REF/DEF STACK
*                                   IMMEDIATELY BELOW THE EXPRESSION
*                                   STACK.
ADLDMD1  AI,D2    -2
         LH,D3    *D2
         SW,R4    D3
         LW,R6    RFDFSTK
         AI,R6    X'11'             STACK+1+C FOR TREE + 3 FOR CONT.SECT
         CW,R6    R4                IS THERE ROOM TO READ THE RFDF.
         QUIT     ER22,BL,D3
         CW,R6    RDPTRS            HAVE WE RUN INTO SORT TABLE
         BL       %+2               NO, NOT YET
         DATA     FASTSRCH          YES, SO TURN OFF BINARY SEARCH
         LI,R7    K0
         LB,R6    *R5
         STB,R7   *R5,R6
         LW,R6    D3
         SLS,R6   2
         DO       MODE=1
         XW,4     5
         BAL,11   CHKLM
         XW,5     4
         FIN
         CAL1,1   READEF
         MTB,-1   *R5
*                                   A SPECIAL CONTROL SECTION IS ADDED
*                                   TO THE FRONT OF THE REF/DEF STACK.
*                                   THIS CONTROL SECTION WILL REFLECT
*                                   THE SIZE OF THE ENTIRE MODULE
*                                   AND IN PLACE OF A VALUE WILL HAVE
*                                   THE RELATIVE POSITION AND # OF
*                                   WORDS OF THIS MODULE EXPRESSION
*                                   STACK.
         LW,R7    R4                SAVE BEGINNING PAGE ADDRESS OF
         AI,R7    K200+KN3
         AND,R7   MN9               LIBRARY REF/DEF STACK FOR RELEASE
         STW,R7   RELPAGE
         LW,R6    0,R5              IF NAME IS :P0-:P9
         LI,R7    X'FFFF0'          WE HAVE A CORE LIBRARY
         CS,R6    TX:PO
         BNE      NCADLM            TISNT
         LI,R7    X'FFFF'
         STS,R6   CORELIB           PUT NAME IN CORELIB FOR INCLUSION IN HEAD
         LW,R5    BUF+7             HEAD IS IN BUF..
         AI,R5    7+X'4000'**3      AND WE NEED SIZE IN CORELIB
         SLS,R5   -3                IN DWDS IN LEFT HALF
         LC       CORELIB
         STH,R5   CORELIB           WITH LOADED BIT (Y4)
         BCS,8    FNDSIZ2           UNLESS THIS IS A LIBRARY
         BCR,4    FNDSIZ2           OR WE'VE BEEN HERE BEFORE
*E*      ERROR:   0200-16
*E*      MESSAGE: TOO MANY CORE LIBRARIES
*E*      DESCRIPTION: ONLY ONE CORE LIBRARY IS PERMITTED
         QUIT     X'16'
NCADLM   RES
         AI,R4    KN3               SPACE FOR SPECIAL ENTRY
         LW,R7    Y0304
         STW,R7   *R4
         LW,R7    CSEG1
         AI,R7    EXPRDIS                                               726
         LW,R7    *R1,R7                                                726
         AND,R7   M16                                                   726
         SLS,R7   1                                                     726
         LW,D4    EXPRSTK
         SW,D4    R7                                                    726
         LCW,D4   D4                                                    726
         AI,D4    1                                                     726
         SW,D4    D1                                                    726
         STH,D1   D4                                                    726
         STW,D4   2,R4                                                  726
         LI,R7    K0                                                    726
         STW,R7   1,R4
         AI,D2    KN1
FNDSIZ   LH,D4    *D2                                                   726
         BNEZ     FNDSIZ1
         AI,R7    K1
         AI,D2    K2
         CI,R7    K3
         BNE      FNDSIZ
         B        FNDSIZ2
TX:PO    TEXTC    ':P0'
FNDSIZ1  SLS,R7   22
         OR,R7    D4
         STS,R7   *R4
FNDSIZ2  LW,SR3   R4
         LI,SR1   KN3
         LW,D1    RFDFDIS,R1
         AND,D1   M16
         SLS,D1   1
         LW,R5    LIBEXPR           SAVE PTR TO SECOND WD OF ENTRY
         BEZ      ADRFDF              TO POINT TO SPECIAL REF/DEF
         LW,D4    RFDFSTK1            CONTROL SECTION
         AND,D4   M15
         STW,D4   *R5
         LI,R5    K0
         STW,R5   LIBEXPR
*                                   ADRFDF TAKES EACH REF/DEF ENTRY
*                                   AND ADDS IT TO THE REF/DEF STACK,
*                                   THEN CHANGES ALL THE EXPRESSION
*                                   STACK POINTERS TO AGREE WITH
*                                   THE NEW RELATIVE LOCATION OF THE
*                                   ENTRY IN THE REF/DEF STACK. IN
*                                   MOST CASES (NON-SYSGEN GENERATED
*                                   LOAD MODULES) THIS IS MERELY
*                                   A MATTER OF FOLLWOING A CHAIN
*                                   FROM THE REF/DEF ENTRY THRU
*                                   THE EXPRESSION STACK.
ADRFDF   LW,D3    R1
         LW,D4    RFDFSTK
         LB,R4    *SR3
         LW,R6    SR3
         AI,R6    KN1
*                                   MOVE THE ENTRY TO THE TOP OF THE
*                                   REF/DEF STACK.
ADRFDF2  LW,R5    *R6,R4
         STW,R5   *D4,R4
         BDR,R4   ADRFDF2
         AI,D4    K1
ADLDMD4  LI,R4    K0
         LI,R5    BUF
         LB,R5    *R5
         CI,R5    X'83'
         BE       %+3
         LW,R5    Y001
         STS,R4   *D4
         LW,R2    *D4
         AND,R2   Y0007
         CW,R2    Y0005
         BNE      %+4
*                                   IF ITS A FORWARD REFERENCE MARK
*                                   IT 'USED'.
         LW,R5    Y0007
         STS,R5   *D4
         B        ADCSEC2
         CI,R2    K0
*                                   FLAG AND ADD DEF'S.
         BE       LIBDEF
         LB,R2    *D4
         CI,R2    1
         BE       NEXTRFDF
         CI,R2    K3
*                                   ADD PREF'S AND REF'S
         BNE      ADRFDF3
         LW,R2    CSECFLG
*                                   LEAVE ALL BUT THE SPECIAL CONTROL
*                                   SECTION AS THEY ARE. THEY HAVE
*                                   TYPE 06 (USED CONTROL SECTION SO
*                                   PASS 2 WILL NOT SEE THEM).
         BNEZ     ADCSEC
*                                   ACCOUNT FOR THE SPECIAL CSECT SIZE.
         MTW,1    CSECFLG
         LW,R4    Y0014                                                 726
         LW,R5    Y0017                                                 726
         STS,R4   *D4
         LW,R6    D4                INITIALIZE
         LW,R3    CSEG1
         AI,R3    RFDFDIS           FORWARD REFERENCE
         LW,R3    *R3,R1
         AND,R3   M16               SEARCH BOUNDARIES.
         SLS,R3   1
         SW,R6    R3
         STW,R6   FIRSTF
         STW,R6   LASTF
         INT,R4   *D4
         SLS,R4   -6
         AND,R4   M2
         LW,R6    LOCWD
         CI,R6    X'1000'
         BAZ      ADLDMD7
         CI,R4    K0                IF CSEC1 SPECIFIED AND
         BNE      ADLDMD7             P.T. =0, FORCE CORE
         LW,R4    *D4                 IMAGE REC INTO P.T. 01,
         EOR,R4   Y006                AND FORCE P.T. OF R/D
         STW,R4   *D4                 ENTRY = 1.  ALSO SET
         LI,R4    K1                  BIT 10 OF ENTRY = 1.
ADLDMD7  EQU      %
         SLS,R5   17
         LW,R6    R5
         SLS,R6   -1
         BAL,SR4  TM100
         LW,R2    CSEG1
         AI,R2    00DIS
         SLS,R4   1
         AW,R2    R4
         AWM,R6   *R2,R1
         B        ADCSEC2
*                                   ADD THE CONTROL SECTION TO THE
*                                   STACK
ADCSEC   LW,R2    LOCWD
         CI,R2    X'1000'
         BAZ      ADCSEC2
         LW,R2    *D4
         AND,R2   Y00C
         BNEZ     ADCSEC2
         LW,R5    Y004
         STS,R5   *D4
ADCSEC2  LB,R2    *D4
         MRSP,R2
         LB,R2    *D4
*                                   INSURE MAX RFDF IS O.K.
         BAL,SR4  CHKMRF
         SLS,R2   16
         LW,R4    CSEG1
         AI,R4    RFDFDIS
         LW,R7    *R4,R1
         AWM,R2   *R4,R1
         SLS,R7   -16
         LW,R2    CSEG1
         SLS,R2   16
         AW,R7    R2
         LW,SR4   SR2
         LW,R4    D4
         B        WHEXSTK
*                                   FLAG LDEF'S
LIBDEF   EQU      %
         LI,R5    3
         LI,R4    1                 MARK LIB DEFS INITIALLY UNUSED
         STS,R4   *D4
ADRFDF3  LW,R2    CSEG1
*                                   IF THE NAME IS ALREADY IN THE
*                                   REF/DEF STACK PICK UP A POINTER
*                                   TO IT, OTHERWISE ADD IT TO THE
*                                   STACK AND RETURN THE POINTER.
         LW,D2    RFDFSTK
         BAL,SR4  CHKRFDF
         LH,R5    R7
         AW,R5    R1
         INT,R5   RFDFDIS,R5
         SLS,R5   1
         LW,R2    R7
         AND,R2   M16
         AW,R5    R2
         LW,R4     D4
         LI,SR4   K1
         AND,SR4  *D4
         STS,SR4  *R5
         LW,R2    RFDFSTK
         SW,R2    D2
         LH,D4    *D4
         AND,D4   M4
         CI,D4    KB                IS THIS A LOADER-BUILT DCB
         BNE      CHKTY3
         LW,D4    YFFF0FFFF         YES--FORCE AN SREF SO THE LOADER
         AND,D4   *R5               WON'T PROCESS IT AGAIN
         AI,D4    K10000
         STW,D4   *R5
         B        ADRFDF4
CHKTY3   EQU      %
         CI,D4    K3                IS IT A DSECT (TYPE 03)
         BNE      ADRFDF4           NO
         LB,D4    BUF               IS THIS REF/DEF STACK CHAINED
         CI,D4    X'82'             (I.E. LIBRARY LMN?)
         BNE      NOCHAIN           NO
         LW,SR4   1,R4              YES, SO FIX UP THE EXPRSTK NOW,
         LCW,R6   SR4               BEFORE WE HAVE TO ZERO OUT THE
         BEZ      NOCHAIN           ...VALUE WORD OF THIS DSECT AND
         LW,SR4   *SR2,R6           GO AND CLOBBER THE CHAIN.
         STW,R7   *SR2,R6           POINT EXPRESSION AT REF/DEF ENTRY
         B        %-4
NOCHAIN  EQU      %
         LI,D4    K0                AND INITIALIZE VALUE FIELD
         STW,D4   1,R5              OF ENTRY WITH ZERO
         LW,D4    LOCWD
         CI,D4    X'1000'
         BAZ      ADRFDF4
         LW,D4    *R5
         AND,D4   Y00C
         BNEZ     ADRFDF4
         LW,D4    Y004
         STS,D4   *R5
ADRFDF4  BAL,SR4  CHKMRF
         LW,SR4   SR2
*                                   "81" FOR A TYPE MEANS SYSGEN
*                                   GENERATED IT. "82" MEANS THE LOADER
*                                   DID AND THE STACKS ARE CHAINED.
WHEXSTK  EQU      %
         LB,R5    BUF               GET LOAD MODULE TYPE
         CI,R5    X'82'
         BNE      OLEXSTK
         LW,R5    1,R4
          LCW,R4   R5
          BEZ      NEXTRFDF
         LW,R5    *SR2,R4
         STW,R7   *SR2,R4
         B        %-4
*                                   THIS LOGIC DECODES OLD   (SYSGEN)
*                                   EXPRESSIONS AND SEES IF THEY WERE
*                                   POINTING TO THIS REF/DEF ENTRY.
*                                   IF SO THE POINTER IS CORRECTED.
OLEXSTK  AW,R7    Y8
         CW,SR2   EXPRSTK
         BE       NEXTRFDF                                              726
FXEXPPTR LH,D4    *SR2
         AND,D4   M6
         LW,R5    SR2
         SW,R5    D4
         LW,D4    R5
         AI,D4    K2
         LW,D2    *D4
         CW,SR1   D2
         BNE      %+2
         STW,R7   *D4
         LW,R6    SR2
         SLS,R6   2
         AI,R6    K2
NEXTEC   LB,D3    0,R6
         CI,D3    K1
         BL       ADCONST1
         BE       ADCONST
         CI,D3    K2
         BE       EXPREND
         CI,D3    K30
         BGE      ADCONST1
         LW,D3    *R5
         CW,SR1   D3
         BNE      ADCONST
         STW,R7   *R5
ADCONST  AI,R5    KN1
ADCONST1 AI,R6    K1
         CI,R6    K3
         BANZ     NEXTEC
         AI,R6    KN8
         B        NEXTEC
EXPREND  LB,R6    *SR2
         SW,SR2   R6
         CW,SR2   EXPRSTK
         BG       FXEXPPTR
NEXTRFDF LW,SR2   SR4
NXTRFDF1 LB,R4    *SR3
         AW,SR3   R4
         AW,SR1   R4
         CW,SR3   RELPAGE           HAVE WE PROCESSED A FULL PAGE?
         BL       NXTRFDF2          NO,KEEP GOING
         LW,R5    RELPAGE           YE,RELEASE PAGE OF REF/DEF STACK
         AI,R5    KN200             ALREADY PROCESSED.
         AW,R5    M:FVP
         PSW,SR1  *R0
         CAL1,8   R5
         PLW,SR1  *R0
         LI,R5    X'200'
         AWM,R5   RELPAGE           SAVE ADDRESS FOR NEXT PAGE RELEASE.
NXTRFDF2 EQU      %
         CW,SR3   EXPRSTK
         BL       ADRFDF
ADLDMDEX PLW,R2   *R0
         LI,R5    0
         STW,R5   LIB
         PLW,SR4  *R0
         B        *SR4
*                                   THIS ROUTINE ADD R2, THE SIZE
*                                   OF THE CURRENT REF/DEF ENTRY,
*                                   TO MAX RFDF IF THE CURRENT
*                                   SEGMENT IS ON THE PATH WITH THE
*                                   LONGEST REF/DEF STACK.
CHKMRF   EQU      %
         LW,R5    CSEG1
         BEZ      ADDMRD
         LW,R5    MXRFDFSG
CHKMRF1  CW,R5    CSEG1
         BE       ADDMRD
         AI,R5     3
         LW,R5    *R5,R1
         AND,R5   M16
         BEZ      *SR4
         B        CHKMRF1
ADDMRD   AWM,R2   MAXRFDF
         B        *SR4
Y0014    DATA     X'140000'                                             726
Y0017    DATA     X'170000'                                             726
Y038402  DATA     X'03840200'       SPECIAL EXPR ENTRY CONTROL WORD
         PAGE
*
*        LP1
*
LP1      EQU      %
*                                   THIS ROUTINE PROCESSES AN OBJECT
*                                   MODULE, DECODING THE OBJECT
*                                   LANGUAGE AND BUILDING THE
*                                   NECESSARY ENTRIES IN THE REF/
*                                   DEF AND EXPR STACK FOR PASS 2.
         PSW,SR4  *R0
         LW,D1    CSEG1
         AI,D1    RFDFDIS
         LW,D1    *D1,R1
         AND,D1   M16
         SLS,D1   1
         LW,D2    DECLBAS
         LW,D3    R1
*                                   MAKE A REF/DEF ENTRY FOR CSEC
*                                   0 AND DECLARE IT.
         LW,R4    RFDFSTK
         AI,R4    K1
         LI,R1    K3
         MRSP,R1
         LW,R5    CSEG1
         AI,R5    RFDFDIS
         AW,R5    D3
         MTH,3    *R5
         LW,R5    Y0304
         LI,R6    0
         LI,R7    K0
         LCI      K3
         STM,R5   *R4
         LW,R1    DECLBAS
         SW,R1    DECLSTK
         MSP,R1   DECLSTK
         LW,R1    RFDFSTK
         AI,R1    KN2
         LW,R2    CSEG1
         SW,R1    D1
         STH,R2   R1
         LW,R2    DECLSTK
         STW,R1   *R2
         AND,R1   M16
         STW,R1   FIRSTF            INITIALIZE FORWARD REFERENCE BOUNDS.
         STW,R1   LASTF
*                                   THIS ROUTINE FETCHES AN OBJECT
*                                   MODULE CONTROL BYTE AND BRANCHES
*                                   TO THE APPROPRIATE ROUTINE.
LDR1     BAL,SR4 GBYTE
         CI,R5    K20               SKIP LOAD ITEMS
         BGE      LSKIP
         LH,R1    ITEMV,R5          ELSE GO TO PROPER ROUTINE
         BNEZ     MCP1,R1
         B        ERAX
ITEMV    DO1      16
         DATA     0
IV       CNAME
         PROC
         ORG,2    HA(ITEMV)+CF(2)
         DATA,2   AF-MCP1
         PEND
         IV,0     ORG+1             SHOULD BE B LDR1
         IV,3     DDNAM
         IV,4     ORG
         IV,5     DPNAM
         IV,6     DSNAM
         IV,7     FIELD
         IV,8     DFREF
         IV,9     DDSECT
         IV,10    DDEF
         IV,11    DCS0
         IV,12    DCS
         IV,13    DSTRT
         IV,14    MODEND
         IV,15    RLOAD
         IV,16    DFREFH
         IV,17    SD11
         IV,18    SD12
         IV,19    SD13
         IV,25    DDSECT
         IV,30    PSECT
         ORG      ITEMV+16
         LW,R4    1,R5              GET VALUE
         PAGE
SD11     BAL,11   GBYTE
         BAL,11   12BNUM
         B        LDR1
SD12     BAL,11   GBYTE
         BAL,11   SKNAME
         BAL,11   EXPRSKP
         B        LDR1
SD13     BAL,11   SKNAME
         BAL,11   2BNUM
         B        LDR1
SKNAME   PSW,11   *R0
         BAL,11   GBYTE
         LW,D4    R5
         BAL,11   GBYTE
         BDR,D4   GBYTE
         PLW,11   *R0
         B        *11
         PAGE
*                                   DECLARE DEF NAME: ENTER THE NAME
*                                                      AND DECLARATION.
DDNAM    LI,R4    K0
         BAL,SR4  ENNAM
         BAL,SR4  ENDECL
         B        LDR1
         SPACE    10
DSTRT    RES                        DEFINE START: SKIP EXPR UNTIL PASS2
*                                   ORIGIN:  SKIP THE EXPRESSION
*                                              UNTIL PASS 2.
ORG      BAL,SR4  EXPRSKP
         B        LDR1
         SPACE    10
*                                   DECLARE PREF NAME: ENTER NAME AND
*                                                       DECLARATION
DPNAM    LW,R4    Y0002
         BAL,SR4  ENNAM
         BAL,SR4  ENDECL
         B        LDR1
         SPACE    10
*                                   DECLARE SREF NAME: ENTER NAME
*                                                     AND DECLARATION.
DSNAM    LW,R4    Y0001
         BAL,SR4  ENNAM
         BAL,SR4  ENDECL
         B        LDR1
         SPACE    10
*                                   FIELD:  SKIP SIZE AND LOC,
*                                            SKIP EXPRESSION.
FIELD    BAL,SR4  2BNUM
         BAL,SR4  EXPRSKP
         B        LDR1
         SPACE    10
*                                   DEFINE FORWARD REF AND HOLD:
*                                     FIND FORWARD REF AND FLAG IT
*                                     WITH A X'F0' IN THE HIGH ORDER
*                                     BYTE SO WE CAN RELEASE IT AT
*                                     MODULE END. THE EXPRESSION IS
*                                     READ AND ADDED TO THE EXPR STACK.
DFREFH   BAL,SR4  2BNUM
         BAL,SR4  CHKFREF
         AI,R5    3
         LI,R6    X'F0'
         STB,R6   *R5
         MTW,1    RSEG00            FLAG THE DFREFH EXPR FOR EXPRIN
         BAL,SR4  EXPRIN
         LI,R6    0
         STW,R6   RSEG00            RESET FLAG
         B        LDR1
         SPACE    10
*                                   DEFINE FORWARD REF: THE FORWARD
*                                     REF IS LOCATED, MARKED 'USED'
*                                     WITH A X'FF' IN THE HIGH ORDER
*                                     BYTE AND THE DEFINING EXPRESSION
*                                     IS ADDED.
DFREF    BAL,SR4  2BNUM
         BAL,SR4  CHKFREF
         AI,R5    K3
         LI,R6    KFF
         STB,R6   *R5
         BAL,SR4  EXPRIN
         B        LDR1
         SPACE    10
*                                   DEFINE DUMMY SECTION: THE DECLAR-
*                                     ATION # IS FETCHED, THE DSECT
*                                     IS DECLARED, TH TYPE AND SIZE
*                                     ARE FETCHED AND THE SIZE
*                                     ACCOUNTED FOR.
DDSECT   EQU      %
         PSW,R5   *R0               SAVE CONTROL BYTE
         BAL,SR4  12BNUM            GET DSECT'S NAME NUMBER
         PSW,R7   *R0               SAVE IT FOR A BIT
         BAL,SR4  DECLCHK
         LW,R6    *D2,R7
         LW,R7    R6
         BAL,SR4  ENDECL
         BAL,SR4  3BNUM
*
* THIS LOGIC TESTS FOR THE SPECIAL DSECT HANDLING FLAG WHICH
* CAN BE SET BY THE COMBINATION OF OPTIONS: (PERM,LIB) & (ABS),
* OR EXPLICITLY BY USING THE (DREF) OPTION WITH LYNX.
* IF WE ARE BUILDING A LIBRARY WITH THIS FLAG SET, DSECTS ARE
* CHANGED TO PREF'S TO PERMIT PROPER HANDLING OF DSECTS
* (LABELLED COMMON) IN LIBRARIES.
*
         LW,R4    LOCWD
         CW,R4    Y01               SPECIAL DSECT HANDLING?
         BAZ      DDSEC1            NO
         CI,4     X'10'             LIB?
         BAZ      DDSEC1            NO
         INT,R4   R6                BREAK DOWN REF/DEF ENTRY POINTER
         AI,R4    RFDFDIS           SEG'S REF/DEF STACK BASE
         LW,R4    *D3,R4            GET BASE ADDR.
         AND,R4   M16               ZAP SIZE
         SLS,R4   1                 MAKE WORD ADDR.
         AW,R4    R5                ADD DISP TO ENTRY
         STW,R4   D4                SAVE REF/DEF POINTER
         LW,R4    Y0002             PREF TYPE
         LW,R5    Y000F
         STS,R4   *D4               CHANGE ENTRY TYPE TO PREF
         LI,R4    -2
         MSP,R4   *0                CLEAR JUNK FROM TSTACK
         B        LDR1              THAT'S ALL FOLKS
DDSEC1   EQU      %                 HERE TO PROCEED NORMALLY
         BAL,SR4  FIXSIZE
         LCI      2
         PLM,R5   *R0               GET BACK CNTRL BYTE, NAME # OF DSECT
         CI,R5    X'19'             IS THIS DSECT MENAT FOR THE ROOT
         BNE      LDR1              NO, NOT PARTICULARLY
         MTW,0    CSEG1             YES: IS THIS ALREADY THE ROOT
         BEZ      LDR1              YEP, NO HASSLE.
         PSW,R6   *R0               SAVE NAME # ONE MORE TIME
         LB,R5    *R4               GET # OF WORDS IN ENTRY
         AI,R4    -1
         LW,R6    *R4,R5
         STW,R6   *RFDFSTK,R5       MAKE COPY OF ENTRY ABOVE RFDFSTK
         BDR,R5   %-2
         LI,R6    0
         LW,R7    M20
         STS,R6   1,R4              ZAP TYPE & SIZE OF PREV. ENTRY
         STW,R7   3,R4              GARBAGE RESOL. MAKES MAPER IGNORE IT
         AI,R4    4                 LAST BUT NOT LEAST...
         STB,R6   *R4               ZAP BYTE COUNT OF NAME
         LI,SR4   %+3               RTN ADDR FOR RSEG
         PSW,SR4  *R0
         B        RSEG              MOVE DSECT ENTRY DOWN TO ROOT
         LI,R6    RFDFDIS
         INT,R4   *D3,R6            GET ROOT'S RFDFSTK INFO FROM TREE
         LB,R6    *D4               WD CNT OF ENTRY WE JUST MOVED TO ROOT
         SW,R4    R6                GET FORMER ROOT STACK SIZE
         SLS,R5   1                 WA(RFDFSTK BASE)
         AW,R4    R5                POINTER TO NEW LOCATION OF DSECT ENTRY
         PLW,R6   *R0               GET BACK DSECT'S NAME NUMBER
         STW,R4   *D2,R6            ...AND CHANGE PTRS FOR NAME...
         STW,R4   *DECLSTK          ...AND DSECT DECLARATIONS
         B        LDR1
         PAGE
*                                   THIS ROUTINE CHECKS THE  REF/DEF
*                                   ENTRY POINTED TO BY THE DECLAR-
*                                   ATION # GIVEN. IF ANYTHING OTHER
*                                   THAN A CSECT OR DSECT THE TYPE IS
*                                   CHANGED TO DSECT.
FIXSIZE  INT,R4   R6
         STW,R4   D4
         AI,R4    RFDFDIS
         LW,R4    *D3,R4
         AND,R4   M16
         SLS,R4   1
         AW,R4    R5
         LH,R6    *R4
         AND,R6   M4
         CI,R6    4
         BE       FIXSIZE5
         CI,R6    3
         BE       FIXSIZE5
         CI,R6    X'C'
         BE       FIXSIZE5
         LW,R5    *R4
         AND,R5   YFF               SCRUB OFF ALL BUT COUNT BYTE
         CI,R6    8                 IF ITS A DOUBLE DEF, SOMEONE
         BNE      %+2               BLEW IT, SO MARK IT SPECIALLY...
         OR,R5    Y002              ...SO THE MAPER CAN TELL 'EM.
         OR,R5    Y0003             SET TYPE=DSECT
         STW,R5   *R4
*                                   THE SIZE AND PROTECTION TYPE ARE
*                                   FOUND AND CHECKED.
FIXSIZE5 EQU      %
         AI,R7    K7
         LI,R6    K0
         SLD,R6   10
         LW,R5    LOCWD
         CI,R5    X'1000'
         BAZ      %+2
         LI,R6    1
         CI,R6    2
         BL       %+2
         LI,R6    1
         LB,R5    *R4
         CI,R5    3
         BE       FIXSIZE7
         LW,R5    3,R4
         DO       MODE+BPMLIB=1
         LB,SR2   R5
         CI,SR2   2
         BLE      FIXSIZE7
         FIN
         CW,R5    TX6F4:
         BNE      %+2
         LI,R6    0
         DO       MODE+BPMLIB=1
         AND,R5   Y00FFFF
         CW,R5    TXF:
         BE       %+3
         CW,R5    TXM:
         BNE      FIXSIZE7
         LI,R6    2                 CHNG PROT. TYPE TO 10 IF DCB DSECT
         FIN
FIXSIZE7 EQU      %
         SLS,R7   -3
         SLD,R6   22
         LI,R5    K0
         LW,R7    Y00C
         CS,R6    *R4
         BE       FIXSIZE6
         LW,R7    M16
         LS,R7    *R4
*                                   ALL DSECTS WITH THE SAME NAME MUST
*                                   HAVE THE SAME PROTECTION TYPE.
         BEZ      FIXSIZE6
         LW,R6    3,R4
         LW,R7    4,R4
         SLD,R6   8
*E*      ERROR:   0200-14
*E*      MESSAGE: ILL. DSECT
*E*      DESCRIPTION: TWO DUMMY SECTIONS HAVING THE SAME NAME BUT
*E*               DIFFERENT PROTECTION TYPES WERE ENCOUNTERED.
*E*      REGISTERS: R6 HAS 1ST FOUR CHARACTERS OF DSECT NAME.
         QUIT     ER14,,R6
FIXSIZE6 EQU      %
         LW,R7    M16
         CS,R6    *R4
         BLE      FIXSIZE1
*                                   INSERT PROTECTION TYPE IN ENTRY.
         STS,R6   R5
         INT,R1   *R4
         SW,R5    R1
         SLS,R5   16
         AW,R7    Y00C
         STS,R6   *R4
         LB,SR2   *R4
         CI,SR2   3
         BE       FIXSIZE1
FIXSIZE3 EQU      %
         LW,R7    3,R4
         CW,R7    TX6F4:
         BNE      FIXSIZE1
*                                   IF 1ST BLANK COMMON; SAVE SIZE.
         SLS,R6   1
         AND,R6   M17
         STW,R6   FCOMSIZ
FIXSIZE1 EQU      %
FIXSIZE2 LW,R6    R5
         PSW,SR4  *R0
         BAL,SR4  TM100
         PLW,SR4  *R0
         LB,R5    *R4
         CI,R5    3
         BE       %+4
         LW,R5    3,R4
         CW,R5    TX6F4:
         BE       *SR4
*                                   IF NOT BLANK COMMON ACCOUNT FOR
*                                   SIZE OF C OR DSECT IN TREE.
FIXSIZE4 EQU      %
         LW,R5    R6
         LI,R6    K0
         LW,R7    Y00C
         LS,R6    *R4
         SLS,R6   -21
         LCI      2
         PLM,R1   *R0
         LCI      2
         PSM,R1   *R0
         CI,R1    X'19'             ARE WE PROCESSING A ROOT DSECT
         BE       %+2               YES, SO TALLY IN ROOT SEG
         AW,R6    D4
         AI,R6    00DIS
         LW,R7    *D3,R6
         AW,R7    R5
*E*      ERROR:   0200-31
*E*      MESSAGE: LMN'S SIZE TOO BIG
*E*      DESCRIPTION: THE DOUBLEWORD SIZE OF A PROTECTION TYPE OF A
*E*               LOAD MODULE DOES NOT FIT IN THE TREE TABLE HALFWORD.
         QUIT     X'31',BNC
         STW,R7   *D3,R6
         B        *SR4
*                                   THIS ROUTINE ADJUSTS THE SIZE UP
*                                   ACCORDING TO M10 OR M100. INPUT IS
*                                   IN R6 IN LEFT HALF OF WORD IN
*                                   # OF DOUBLE WORDS.
TM100    EQU      %                 IF PSECT,ADJUST SIZE UP
         LW,R7    *R4                 TO M200 FOR PAGE.
         AND,R7   Y000F
         CW,R7    Y000C             PSECT
         BNE      TM100B            NO
         AW,R6    Y00FF             ASSUME MAXIMUM HOLE SIZE
         B        TM1
TM100B   EQU      %
         LW,R7    LOCWD
         CI,R7    K40
         BAZ      TM10
         AW,R6    Y007F
         AND,R6   YFF80FFFF
TM10     CI,R7    K20
         BAZ      TM1
         AW,R6    Y0007
         AND,R6   YFFF8FFFF
TM1      B        *SR4
YFF      DATA     X'FF000000'
Y007F    DATA     X'7F0000'
YFF80FFFF  DATA   X'FF80FFFF'
YFFF8FFFF DATA    X'FFF8FFFF'
         SPACE    10
*                                    DEFINE DEF: FETCH THE DECLAR-
*                                     ATION # AND ADD THE DEFINING
*                                     EXPRESSION.
DDEF     BAL,SR4  12BNUM
         BAL,SR4  DECLCHK
         LW,R7    *D2,R7
         BAL,SR4  EXPRIN
         B        LDR1
         SPACE    10
*                                   AND SIZE AND FIX ENTRY.(DECLAR # 0)
*                                   DECLARE CONTROL SECT 0: FETCH TYPE
DCS0     LW,R6    *D2
         BAL,SR4  3BNUM
         BAL,SR4  FIXSIZE
         B        LDR1
         SPACE    10
*                                   PSECT:  BUILD CSECT
*                                     ENTRY WITH WD 0, BIT 10 = 1
PSECT    LW,R5    Y030C
         B        DCS1
Y030C    DATA     X'030C0000'
         SPACE    10
DCS      LW,R5    Y0304
DCS1     LW,R6    CSEG1
*                                    DECLARE CONTROL SECTION: ENTER
*                                     DECLARATION, MAKE 3 WORD ENTRY
*                                     IN REF/DEF STACK, FETCH TYPE
*                                     AND SIZE AND FIX ENTRY.
         BEZ      NORMALCS          ITS THE ROOT
         LW,R7    LOCWD
         CI,R7    X'80'             ARE WE TO MOVE CSECT0 TO ROOT
         BAZ      NORMALCS          NO
         PSW,R5   *R0               HANG ON FOR A BIT
         BAL,SR4  GBYTE             GET PROT TYPE
         MTW,-1   CURBYTE           BACK UP SCANNER
         CI,R5    X'C0'             IS PROT TYPE 00
         BAZ      %+3               YES
         PLW,R5   *R0               NOPE
         B        NORMALCS
         PLW,R5   *R0
         BAL,SR4  ROOTCS            MOVE CSECT0 TO ROOT
         B        DCS2
NORMALCS EQU      %
         LW,R4    RFDFSTK
         AI,R4    K1
         LW,R7    R4
         SW,R7    D1
         STH,R6   R7
         PSW,R5   *R0
         BAL,SR4  ENDECL
         PLW,R5   *R0
         LI,R6    K3
         MRSP,R6
         LW,R6    CSEG1
         AI,R6    RFDFDIS
         AW,R6    D3
         MTH,3    *R6
         LI,R6    0
         LI,R7    K0
         LW,R4    RFDFSTK
         AI,R4    -2
         LCI      K3
         STM,R5   *R4
DCS2     EQU      %
         LW,R6    DECLSTK
         LW,R6    *R6
         BAL,SR4  3BNUM
         BAL,SR4  FIXSIZE
         B        LDR1
         PAGE
ROOTCS   EQU      %
         PSW,SR4  *R0
         PSW,R5   *R0
         AI,D1    4                 BUMP BASE OF CURRENT SEG'S STACK
         LI,R4    RFDFDIS
         LW,R5    *D3,R4            REF/DEF POINTER FOR ROOT SEG
         LH,R4    R5                GET SIZE
         AND,R5   M16               AND DA(BASE)
         SLS,R5   1                 MAKE THAT A WORD ADDR.
         AW,R4    R5                POINT TO END OF ROOT STACK
         LW,R7    RFDFSTK           POINTER TO CURRENT END OF STACK
         AI,R7    1
         SW,R7    R4                # OF WORDS TO MOVE
         AI,R4    -1                SO'S BDR LOOP WILL WORK
         LW,R5    R4
         AI,R5    4
MOVECS   LW,SR4   *R4,R7
         STW,SR4  *R5,R7            MOVE EVERYTHING UP 4 WDS
         BDR,R7   MOVECS
         PLW,R5   *R0               GET BACK WD1 OF ENTRY
         MTB,1    R5                MAKE WORD COUNT = 4
         LI,R6    0
         LI,R7    0
         LCI      3
         STM,R5   1,R4              INSERT NEW CSECT ENTRY INTO ROOT STK.
         LI,R4    RFDFDIS+RFDFDIS
         LH,R7    *D3,R4            DISP TO NEW ROOT CSECT ENTRY
         MTH,4    *D3,R4            BUMP ROOT RFDFSTK SIZE
         BAL,SR4  ENDECL            ENTER DECLARATION FOR ROOT SEG
         MTW,4    MAXRFDF           ALLOW FOR LONGER MAX PATH LENGTH
         LI,R4    4
         MRSP,4
         LW,R4    D3
         LW,R4    -1,R4             POINT TO END OF TREE TABLES
         LI,R6    17
         AW,R6    D3                POINT TO REF/DEF ENTRY FOR 1ST SEG
         B        %+3
         MTW,2    *R6               BUMP STACK BASE FOR EACH SEGMENT
         AI,R6    TREESIZE          POINT TO NEXT TREE TABLE ENTRY
         CW,R6    R4
         BL       %-3               GO TO IT
         PLW,SR4  *R0
         B        *SR4
         SPACE    10
*                                   MODULE END: FETCH SEVERITY LEVEL
*                                               AND CHECK.
MODEND   BAL,SR4  GBYTE
         LW,R1    LOCCT
         LH,R1    *R1
         AND,R1   M8
         CW,R1    R5
*E*      ERROR:   0200-11
*E*      MESSAGE: SEV. LEV. EXCEEDED
*E*      DESCRIPTION: A ROM WAS ENCOUNTERED WITH A SEVERITY LEVEL
*E*               GREATER THAN THAT SPECIFIED AS THE MAXIMUM.
*E*      REGISTERS: R5 HAS THE SEVERITY LEVEL.
         QUIT     ER11,BGE,R5
         CW,R5    SEVLEV
         BLE      %+2
         STW,R5   SEVLEV
*                                   SHOULD BE LAST CARD.
         LW,R1    LASTCARD
*E*      ERROR:   0200-0C
*E*      MESSAGE: UNEXPECTED ROM END
*E*      DESCRIPTION: MODULE END WAS GIVEN ON SOME RECORD OF THE ROM
*E*               OTHER THAN THE LAST (ASSEMBLER OR COMPILER ERROR).
         QUIT     ERC,BNEZ
*                                   LP1 EXIT.
         PLW,SR4  *R0
         B        *SR4
         SPACE    10
*                                   REPEAT LOAD: FETCH REPEAT COUNT,
*                                     FETCH NEXT BYTE AND TRANSFER
*                                     TO ROUTINE FOR APPROPRIATE
*                                     LOAD TIME.
RLOAD    BAL,SR4  2BNUM
         LW,SR1   R7
         BAL,SR4  GBYTE
LSKIP    SCS,R5   -4
         LB,R1    %+3,R5
         BNEZ     LSKIP,R1
         B        ERAX
         DATA     0
         GEN,8,8,8,8 LABS,LLREL,0,0
         GEN,8,8,8,8 LSREL,LSREL,LSREL,LSREL
         GEN,8,8,8,8 LSREL,LSREL,LSREL,LSREL
*
LABS     EQU      %-LSKIP
         LB,R6    R5
         SLS,R6   -4
         BNEZ     %+2
         LI,R6    K10               SKIP BYTE COUNT IN RIGHT NIBBLE
NBNUM    AW,R6    CURBYTE
         STW,R6   CURBYTE
         SW,R6    RCDSIZE
         BLEZ     LDR1
         BAL,SR4  GBYTE
         BDR,R6   NBNUM
         B        LDR1
*
LSREL    EQU      %-LSKIP
         LI,R6    4
         B        NBNUM
LLREL    EQU      %-LSKIP
         LI,R6    6                 SKIP 1OR2 BYTE DECL# + 4BYTES
         LC       R5
         BCR,8    NBNUM
         BDR,R6   NBNUM
         PAGE
*                                   THIS ROUTINE DECODES AN EXPRESSION AND
*                                   MAKES AN ENTRY IN THE EXPR STACK. R7
*                                   HAS THE REF/DEF STACK POINTER.
EXPRIN   PSW,SR4  *R0
         LI,SR2   K0
*                                   FIRST INITIALIZE THE ENTRY TO 030300
*                                   DEST 0.
         LW,D4    EXPRSTK
         AI,D4    KN3
         STW,D4   EXPRES            SAVE  FOR FUTURE  USE
         STW,SR2  *D4
         AI,D4    K1
         STW,R7   *D4
         LW,R6    Y0303
         AI,D4    K1
         STW,R6   *D4
         LI,R6    K1                BYTE POINTER
EXPRIN1  BAL,SR4  GBYTE             GET THE EC
         CI,R5    K0
         BE       EXPRIN1
PUTBYTE  AI,R6    K1                PUT EC AWAY
         CI,R6    3                 DO WE NEED A NEW WORD  FOR ECS
         BANZ     PUTBYTE1          NO.
         LW,R7    EXPRES            INDEX FOR MOVE
         LB,R1    *D4
         AW,R1    R7                #WORDS TO MOVE
         SW,R1    D4                LESS ONE
         LW,R4    1,R7
         XW,R4    0,R7              MOVE EM
         AI,R7    -1
         BDR,R1   %-2
         STW,R4   0,R7
         MTW,-1   EXPRES            ADJJUST POINTER
         MTB,1    *D4               INC. # OF WDS IN EXPR
         MTH,1    *D4               INC. DISP
         AI,R6    KN8               GOING BACKWARDS
*                                   THE EC BYTE IS SAVED.
PUTBYTE1 STB,R5   *D4,R6
*                                   AND INTERPRETED.
         CI,R5    K2
         BE       EXPREND1
         BL       ADCON1
         LW,R1    R5
         SLS,R1   -2
         CI,R1    K8
         BE       ADDECL1
         CI,R1    K9
         BE       ADFREF1
         CI,R1    KA
         BE       SBDECL1
         CI,R1    KB
         BE       SBFREF1
         CI,R1    KC
         BE       CHGRES1
         CI,R1    KD
         BE       ADDABS
         CI,R1    KE
         BE       SUBABS
         B        ERAX
*                                   ADD DECLARATION: THE 1 OR 2 BYTE
*                                     DECLARATION # FETCHED. THE DECLAR-
*                                     ATION STACK ENTRY IS SAVED.
ADDECL1  BAL,SR4  12BNUM
         BAL,SR4  DECLCHK
         LW,R7    *D2,R7
         B        PTWRD
SBDECL1  EQU      ADDECL1
*                                   ADD FORWARD REF: THE FORWARD REF #
*                                     IS FOUND. THE FORWARD REF IS
*                                     LOCATED IN THE REF/DEF STACK OR
*                                     ADDED IF NOT PRESENT AND THE
*                                     POINTER TO IT IS SAVED.
ADFREF1  BAL,SR4  2BNUM
         BAL,SR4  CHKFREF
         LW,D4    EXPRSTK           RESTORE POINTER TO EXPR
         AI,D4    KN1
         MTW,0    RSEG00            IS THIS A DFREFH EXPRESSION
         BEZ      PTWRD             BRANCH IF NOT
         LW,R3    Y002              OTHERWISE. . .
         STS,R3   *R5               SET BIT 10 OF THE FREF R/D ENTRY FOR SQZ
         B        PTWRD
SBFREF1  EQU      ADFREF1
*                                   ADD CONSTANT: THE 4-BYTE CONSTANT IS
*                                     SAVED.
ADCON1   BAL,SR4  4BNUM
*                                   THIS ROUTINE SAVES A CONSTANT IN
*                                   REF/DEF POINTER IN THE EXPRESSION.
PTWRD    RES
         LB,R1    *D4
         MTB,1    *D4
         LCW,R1   R1
         STW,R7   *D4,R1
         B        EXPRIN1
SUBABS   RES
*                                   ADD ABSOLUTE: THE RESOLUTION FROM
*                                     THE BYTE IS DETERMINDED AND ADDED
*                                     TO THE RESOLUTION WORD.
ADDABS   RES
         LI,R1    K3                GET RESOLUTION
         AND,R1   R5
         CI,R5    K8                PLUS OR MINUS
         BAZ      %+2
         MTB,-2   *EXPRES,R1        MIINUS
         MTB,1    *EXPRES,R1        PLUS
         B        EXPRIN1
*                                   CHANGE RESOLUTION: IS IGNORED.
CHGRES1  EQU      EXPRIN1
*                                   EXPRESSION END: THE EXPRESSION
*                                     IS ADDED TO THE STACK AND THE
*                                     ROUTINE EXITS.
EXPREND1 RES
         LB,R7    *D4
         LW,R1    CSEG1
         AI,R1    EXPRDIS
         STW,R7   R2
         SLS,R2   16
         AWM,R2   *D3,R1
         MESP,R7
EXPREND2 PLW,SR4  *R0
         B        *SR4
*                                   EXPRSKP SKIPS OVER AN EXPRESSION
*                                   RATHER THAN ADDING AN ENTRY. A
EXPRSKP  PSW,SR4  *R0
EXPRSKP1 BAL,SR4  GBYTE
*                                   THE SIMPLENESS OF THIS LOGIC
*                                   PERMITS ERRORS TO PASS. BUT
*                                   IF THEY DONT CAUSE ERRORS SOON
*                                   PASS2 WILL CATCH THEM
         CI,R5    X'10'
         BANZ     GBYTE             1100XX,1101XX,1110XX,1111XX
         LI,SR4   EXPRSKP1          SET RETURN FOR SKIPPING BYTES
         CI,R5    4
         BL       %+3               000001,000010
         BAZ      12BNUM            1000XX,1010XX AND ERRORS
         B        2BNUM             1001XX,1011XX AND ERRORS
         BDR,R5   EXPREND2          ALL DONE
         B        4BNUM
         PAGE
*                                   THIS ROUTINE ENTERS DEF,S- AND
*
*                                   THIS ROUTINE SEARCHES THE REF/DEF
*                                   STACK FOR A GIVEN FORWARD REF #.
*                                   IF IT IS NOT PRESENT THE FORWARD
*                                   REF IS ADDED.
*                 R7 CONTAINS FREF NO, RETURNS PTR TO ENTRY IN R7
*                 AND ABS LOC. IN R5
CHKFREF  EQU      %
         PSW,R6   *R0
         LW,R4    CSEG1
         AI,R4    RFDFDIS
         LW,R5    *D3,R4
         AND,R5   M16
         SLS,R5   1
         PSW,R5   *R0    SAVE CSEGS R/D BASE
         AWM,R5   FIRSTF    CONVERT FORWARD SEARCH BOUNDS TO ADDRESSES.
         AWM,R5   LASTF
         LW,R5    FIRSTF
         LI,R3    0                 SET FORWARD FLAG
CHKFLOOP LW,R6    *R5
         AND,R6   MSKFTYPE
         CW,R6    Y0005
         BNE      CHKFREF2
         LW,R6    R5
         AI,R6    K3
         LB,D4    *R6               HAS THIS FORWARD BEEN
         CI,D4    X'FF'             DEFINED.
         BE       CHKFREF2
         MTW,0    R3                NO,IS THIS THE FIRST NON-DEFINED.
         BNEZ     CHKFREF1
         STW,R5   FIRSTF            YES.UPDATE LOWER BOUND ON SEARCH.
         LI,R3    -1                SET FLAG.
CHKFREF1 LW,D4    *R6
         AND,D4   M28               IS THIS THE FORWARD WE'RE
         CW,R7    D4                LOOKING FOR.
         BE       FREFIN
CHKFREF2 LB,R6    *R5
         AW,R5    R6
         CW,R5    LASTF
         BLE      CHKFLOOP
*                                   FREF IS NOT PRESENT -ADD IT.
FREFNIN  LW,R4    RFDFSTK
         AI,R4    K1
         LW,R5    R4
         LI,R1    K4
         MRSP,R1
         LW,D4    CSEG1
         AI,D4    RFDFDIS
         AW,D4    D3
         MTH,4    *D4
         LW,D4    Y0405
         STW,D4   *R4
         STW,R4   LASTF             UPDATE UPPER BOUND ON SEARCH.
         LW,D4    CSEG1
         AI,R4    K1
         STW,D4   *R4
         AI,R4    K1
         LI,R6    K0
         STW,R6   *R4
         AI,R4    K1
         STW,R7   *R4
*                                   FREF IS (AT LEAST NOW) IN-RETURN
*                                   POINTER.
FREFIN   EQU      %
         STW,R5   R7
         PLW,R6   *R0               GET CSEG R/D BASE.
         LCW,R3   R6
         AWM,R3   FIRSTF            CONVERT BOUNDS TO DISPLACEMENTS.
         AWM,R3   LASTF
         SW,R7    R6
         LW,R6    CSEG1
         STH,R6   R7
         PLW,R6   *R0
         B        *SR4
M28      DATA     X'FFFFFFF'
         PAGE
*                                   ENTRY POINT FROM ADD LOAD MODULE
*                                   TO LOCATE OR ADD A REF/DEF ENTRY.
CHKRFDF  PSW,SR4  *R0
         LW,D1    R1
         AI,D1    RFDFDIS
         LW,D1    *D1,R2
         AND,D1   M16
         SLS,D1   1
         LW,R5    D4                SET ENTRY SIZE CORRECTLY
         LW,R5    3,R5              FOR SLOW SEARCH
         AW,R5    Y1
         SLS,R5   -26
         STB,R5   *D4
         AI,D4    3                 POINT TO NAME
         B        CHKRFDF1
*                                   P-REF NAMES INTO THE REF/DEF STACK
*                                   IF THEY ARE NOT ALREADY PRESENT. R4
*                                   TELLS WHICH KIND OF ENTRY WE HAVE
*                                   (0-DEF,1-SREF,2-PREF). R7 WILL
*                                   RETURN A POINTER TO THE ENTRY.
ENNAM    PSW,SR4  *R0
*                                   THE NAME IS MOVED TO THE 3RD WORD
*                                   ABOVE THE REF/DEF STACK LEAVING
*                                   ROOM FOR THE FIXED 3 WORDS.
         PSW,R4   *R0
         BAL,SR4  GBYTE
         LW,D4    RFDFSTK
         AI,D4    K4
         STB,R5   *D4
         LW,R6    R5
         LI,R7    K1
ENNAM1   BAL,SR4  GBYTE
         STB,R5   *D4,R7
         AI,R7    K1
         BDR,R6   GBYTE
         PLW,R4   *R0
*                                   THE REST OF THE ENTRY IS SET UP.
         LW,R7    D4                GET AN INDEX REG
         STW,R6   -1,R7             CLEAR RESOLUTION
         LW,R2    CSEG1
         STW,R2   -2,R7
         LB,R1    *D4
         AI,R1    16
         SLS,R1   -2
         STB,R1   R4
         STW,R4   -3,R7
*                                   THE STACK SEARCH IS INITIALIZED.
CHKRFDF1 STW,R2   CSEG2
         LI,R5    ' '               BLANK PAD NAME FOR SORT/SEARCH
         LB,R4    *D4               COUNT
         AI,R4    1
         CI,R4    3
         BAZ      %+3
         STB,R5   *D4,R4
         B        %-4
         DO       MODE=1
         MTW,0    CSEG2             ARE SEARCHING THE ROOT
         BNEZ     %+3               NOPE
         MTW,0    FASTSRCH          ARE WE IN FAST SEARCH MODE
         BEZ      BINSCH            YES: USE BINARY SEARCH
LINSCH   EQU      %
         FIN
         AI,R2    RFDFDIS
         LW,R5    *D3,R2
         LH,R4    R5
         AND,R5   M16
         SLS,R5   1
         AW,R4    R5
         LW,R3    *D4
         STW,R4   TEMPR1
RFDFLOOP EQU      %
         CW,R3    3,R5
         BNE      CHKRFDF3
         LB,R6    *R5               CHECK ALL THE WORDS
         AI,R6    -4                UNLESS THERE IS ONLY ONE
         BGZ      %+3
         BEZ      FOUND1            ONLY ONE
         B        CHKRFDF4          TOO FEW, WE BLEW IT SOMEWHERE
         LW,R7    R5
         AI,R7    K3
CHKRNAME LW,R2    *R7,R6
         CW,R2    *D4,R6
         BNE      CHKRFDF3
         BDR,R6   CHKRNAME
FOUND1   EQU      %
         MTW,0    MREFLAG           ARE WE IN MREF MODE
         BNEZ     NAMEOK            YES: SKIP THE DISPL. DEF CHECK
         LW,R2    LOCWD
         CW,R2    Y4                ARE WE IN BREF MODE
         BAZ      NAMEOK            NO, SO SKIP ALL THIS GARBAGE
         MTW,0    LIB               IS THIS A LIB WE'RE LOADING
         BNEZ     CHKDFCM           YEP: DISPL. DEF DOESN'T MAKE SENSE
         LH,R2    *R5
         AND,R2   M3                GET ENTRY TYPE
         BNEZ     NAMEOK            COULDN'T BE A DISPLACED DEF
         LI,R2    X'FFFC'           MASK FOR DISPLACEMENT FIELD
         AND,R2   *R5               IS THIS A DISPLACED DEF
         BEZ      NAMEOK            NO, SO WE REALLY 'FOUND' IT
         SLS,R2   -2                ALIGN SEGMENT DISPLACENENT
         CW,R2    CSEG1             WAS SYMBOL FROM CURRENT SEG.
         BE       NAMEOK            YEP
         LW,R6    CSEG1
CHKDISP  AI,R6    ROM1DIS
         LW,R6    *D3,R6            GET BACKLINK FROM TREE
         AND,R6   M16
         BEZ      ENNAM6            BACK TO THE ROOT, STOP
         CW,R2    R6                DID SYMBOL COME FROM THIS PATH
         BNE      CHKDISP           WELL, NOT SO FAR...
NAMEOK   EQU      %                 FAR OUT: SYMBOL CAME FROM CURRENT PATH
         LW,R2    LIB
         BEZ      XXXX
CHKDFCM  EQU      %
         LB,R2    BUF
         CI,R2    X'83'
         BNE      XXXX
* DEFCOM OUTPUT HERE, MERGE ENTRY INTO STACK
         LW,R2    Y0007
         AND,R2   0,R5
         BEZ      XXXX
         LW,R2    D4
         LW,R6    Y000F
         AND,R6   -3,R2
         CW,R6    Y000B             IS THIS A LOADER-BUILT DCB
         BNE      NLDRDCB
         PLW,SR4  *R0               YES - DO NOT ADD IT TO THE STACK
         B        NXTRFDF1          (FROM A DEFCOM LMN)
NLDRDCB  EQU      %
         LW,R6    -1,R2
         STW,R6   2,R5
         LW,R6    -2,R2
         STW,R6   1,R5
         LW,SR4   Y001
         STS,SR4  0,R5
XXXX     EQU      %
         LW,R2    CSEG2
         AI,D4    KN3
         LH,R6    *D4
         AND,R6   M3
         BEZ      DEF
         CI,R6    K3
         BE       DSEC
*                                   WE HAVE A REF.
         LH,R7    *R5
         AND,R7   M3
*                                   WE FOUND A DEF-MARK IT USED.
         BEZ      SUDEF
         CI,R7    K1
         BNE      RETPTR
*                                   IF WE FOUND A SREF CHANGE ITS TYPE
*                                   TO WHAT WE HAVE (SREF OR PREF).
         LW,R7    Y0007
         STH,R6   R6
         STS,R6   *R5
         B        RETPTR
SUDEF    LI,R7    K2
         STS,R7   *R5
*                                   RETURN WITH A POINTER-THE LEFT HALF
*                                   IS  SEGMENT # AND THE RIGHT IS THE
*                                   RELATIVE DISPLACEMENT OF THE ENTRY
*                                   IN THAT SEGMENTS REF/DEF STACK.
RETPTR   LW,R7    R5
         LW,R6    R2
         AI,R6    RFDFDIS
         LW,R6    *D3,R6
         SLS,R6   1
         SW,R7    R6
         STH,R2   R7
         PLW,SR4  *R0
         B        *SR4
*                                   WE HAVE A DSEC. ZERO TYPE AND BYTE
*                                   COUNT OF FOUND ENTRY TO MAKE IT
*                                   'TRANSPARENT' TO FURTHER SEARCH.
DSEC     EQU      %
         MTW,0    CSEG1             ARE WE LOADING THE ROOT
         BNEZ     RETPTR            NO: WE CAN'T HANDLE MOVING DSECT
         LW,R7    Y001              YES: SO SET DEFINED BIT HERE
         STS,R7   *D4               AND THEN PROCEED TO ZAP PREVIOUS...
         LI,R6    0                 ENTRY SO'S EVL'LL KNOW WHAT TO LOAD
         LW,R7    M20
         STS,R6   *R5
         STW,R7   2,R5              MAKE RES NON-STD (WON'T
*                                   APPEAR IN MAP)
         AI,R5    K3
         STB,R6   *R5
         MTW,0    FASTSRCH          ARE WE USING BINARY SEARCH
         BNEZ     DONTLOOK          NO
         STW,D4   0,R3              REPLACE OLD SORT TABLE POINTER
         MTW,3    0,R3              R3 HAS BEEN PRESERVED SINCE SEARCH
DONTLOOK EQU      %                 AND EVERYTHING IS PEACHY
         AI,R5    -3                BACK UP TO 1ST WD. OF ENTRY
         SW,R5    RFDFBAS           OLD REF/DEF POINTER VALUE
         LW,R7    D4
         SW,R7    RFDFBAS           DISPLACEMENT PTR TO NEW ENTRY
         LW,R6    EXPRBAS
XPRCHEK  EQU      %
         LH,R3    *R6
         AND,R3   M6                DISPL. TO 1ST ARG OF EXPRESSION
         LCW,R3   R3                (THE STACK IS INVERTED)
         CW,R5    *R6,R3            IF WE FIND AN EXPR. IN TERMS OF...
         BNE      %+2               ...THE OLD ENTRY, CHANGE IT TO...
         STW,R7   *R6,R3            ...POINT TO THE NEW ENTRY.
         LB,R3    *R6               DISPL TO NEXT EXPRSTK ENTRY
         SW,R6    R3                MOVE TO NEXT ENTRY
         CW,R6    SR2               HAVE WE PASSED CURRENT END OF STACK
         BG       XPRCHEK           NO-KEEP ON LOOKING
         B        ENNAM4
*                                   WE HAVE A DEF HERE
DEF      LH,R6    *R5
         AND,R6   M3
*                                   WE FOUND A DEF - DOUBLE DEF.
         BEZ      DUBDEF
         CI,R6    K2
         BG       RETPTR
*                                   WE FOUND A REF-MAKE IT A DEF AND
*                                   MARK IT USED.
         LH,R6    *R5
         AND,R6   MN3
         STH,R6   *R5
         LW,R7    CSEG1
         SLS,R7   2                                                     726
         STS,R7   *R5                                                   726
         DO       MODE=1
         LW,R6    CORELIB           CHECK FOR DEF TO 9INITIAL OR 9DBINITIAL
         BLEZ     SUDEF             B IF CORELIB IS NOT TO BE LOADED
         CW,R6    Y4
         BANZ     SUDEF             B IF CORELIB HAS ALREADY BEEN LOADED
         AI,D4    K3
         LCI      2
         LM,R6    *D4
         AI,D4    KN3
         CD,R6    TX9INITIA
         BE       %+3
         CD,R6    TX9DBINIT
         BNE      SUDEF
         CW,R6    CORELIB           IS DEF SAME AS REF'D NAME IN CORELIB
         BNE      SUDEF             IF NOT, LEAVE CORELIB TRIGGER ON
         LW,R7    Y8
         STS,R7   CORELIB
         FIN
         B        SUDEF
*                                   FLAG THE DEF AS A DDEF UNLESS IT
*                                   CAME FROM THE LIBRARY.
DUBDEF   EQU      %
         LW,R7    LIB
         BEZ      DUBDEF2
         LI,R6    0                 SINCE ORIGINAL DEF CAME
         LI,R7    K1                FROM PRIMARY, NON-LIB INPUT,
         STS,R6   *D4               TURN LIB BIT OFF.
         B        RETPTR
DUBDEF2  EQU      %
         LW,R7    Y0008
         STS,R7   *R5
*                                   SEVERITY LEVEL IS AT LEAST 4 NOW.
         LI,R7    K4
         CW,R7    SEVLEV
         BLE      RETPTR
         STW,R7   SEVLEV
         B        RETPTR
*                                   THIS ROUTINE MOVES ALL M: AND F:
*                                   NAMES TO THE ROOT SEGMENT (TO FORCE
*                                   DCB'S INTO THE ROOT). IT INSURES
*                                   THAT THE ENTRY HAS AN EVEN # OF
*                                   WORDS.
CHKINSRT LW,R6    *D4
         AND,R6   Y00FFFF
         LI,R7    K2
CHECK:   CW,R6    TXF:-1,R7
         BE       RSEG
         BDR,R7   CHECK:
         LW,R6    *D4
         CW,R6    TX6F4:
         DO       MODE=0
         BNE      ENNAM3
         ELSE
         BE       RSEG
         LW,R6    CORELIB
         BNEZ     ENNAM3
         LW,R6    D4
         LW,R2    -3,R6
         AND,R2   MSKFTYPE          TYPE OF NEW ENTRY
         CW,R2    Y0001
         BE       ENNAM3            B IF AN SREF
         LCI      2
         LM,R6    *D4
         CD,R6    TX9INITIA
         BE       %+3
         CD,R6    TX9DBINIT
         BNE      ENNAM3
         STW,R6   CORELIB
         CI,R2    0
         BNE      ENNAM3            B IF NOT A DEF
         LW,R7    Y8
         STS,R7   CORELIB           SET IT DEF.
         FIN
RSEG     MTW,0    CSEG1             IF ALREADY IN ROOTS STACK
         BEZ      ENNAM3            DONT MOVE ANYTHING
         LW,D4    RFDFSTK
         AI,D4    K1
         LB,R2    *D4
         LI,R4    RFDFDIS
         LW,R5    *D3,R4
         LH,R4    R5
         AND,R5   M16
         SLS,R5   1
         AW,R4    R5
         CI,R4    1                 FREE WORD IF STACK IS ODD NOW
         BAZ      %+2
         AI,R2    -1
         CI,R2    1                 MUST MOVE STACKS TO EVEN LOCS
         BAZ      %+2
         AI,R2    1
         AWM,R2   MAXRFDF
         MTW,0    CSEG1
         BEZ      %+3
         AW,D1    R2                ADJUST CURRENT POINTER IF NOT ROOT
         AWM,R2   CRFDF1            AND IN CASE WERE LOADING M:MON
         LW,R7    D4
         AW,R7    R2
         AI,R4    KN1
         LW,R5    R4
         AW,R5    R2
         SW,R7    R4
         LB,R6    *D4
INSRFDF1 LW,SR4   *R4,R7
         STW,SR4  *R5,R7
         BDR,R7   INSRFDF1
         AI,D4    KN1
         AW,D4    R2
INSRFDF2 LW,R7    *D4,R6
         STW,R7   *R4,R6
         BDR,R6   INSRFDF2
         LW,D4    R4
         AI,D4    4                 POINT TO NAME
         LW,R4    D3
         LW,R4    -1,R4
         LI,R6    17
         AW,R6    D3
         STW,R2   TEMPR1            SAVE HOLE SIZE
         SLS,R2   -1
         B        %+3
FIXBASES AWM,R2   *R6
         AI,R6    TREESIZE
         CW,R6    R4
         BL       FIXBASES
         LW,R2    FASTSRCH
         BNEZ     %+2
         BAL,SR4  BINSRT1
         AI,D4    -3                BACK TO START
         LW,R7    D4
         SW,R7    RFDFBAS
         LW,R2    TEMPR1            RESTORE HOLE SIZE
         LI,R6    K0
         B        ENNAM5
*                                   THIS IS THE LOOP IN THE REF/DEF
*                                   SEARCH.
CHKRFDF3 LB,R6    *R5
CHKRFDF4 EQU      %
         QUIT     X'33',BNEZ
*E*      ERROR: 0200-33
*E*      MESSAGE: BAD ENTRY IN LIBRARY REF/DEF STACK
*E*      DESCRIPTION: A ZERO-LENGTH ENTRY HAS BEEN ENCOUNTERED IN
*E*               THE REF/DEF STACK (PROBABLY A MALFORMED LIBRARY).
         AW,R5    R6
         CW,R5    TEMPR1
         BL       RFDFLOOP
*                                   IF THIS STACK IS EXHAUSTED CHECK FOR
*                                   SEGMENTS BELOW IT.
ENNAM6   RES
         LW,R2    CSEG2
         BEZ      ENNAM2
         AI,R2    ROM1DIS
         LW,R2    *D3,R2
         AND,R2   M16
         B        CHKRFDF1
ENNAM2   LW,R2    CSEG1
         STW,R2   CSEG2
         LW,R6    D4
         LW,R7    -3,R6
         AND,R7   Y0007
         CI,R7    X'30000'
         BNE      CHKINSRT
         LW,R7    Y001              MARK LIBRARY DSECTS AS 'DEFINED'
         STS,R7   -3,R6
         B        CHKINSRT
*                                   NOT IN THE REF/DEF STACK ADD IT
*                                   AND RETURN POINTER.
ENNAM3   AI,D4    KN3
ENNAM4   LW,R7    RFDFSTK
         AI,R7    K1
         SW,R7    D1
         LW,R6    CSEG2
         STH,R6   R7
         LB,R2    *D4
ENNAM5   RES
         MRSP,R2
         AI,R6    RFDFDIS
         LB,R2    *D4
         SLS,R2   16
         AWM,R2   *D3,R6
         PLW,SR4  *R0
         B        *SR4
         PAGE
         DO       MODE=1
BINSCH   EQU      %                 BINARY SEARCH OF RFDFSTK
         LI,SR4   %+4
         MTW,0    CSEG1             ARE WE IN THE ROOT
         BEZ      BINSRT1           YES, ADD ENTRY
         B        BINSRT            STICK IT IN OR FIND
         LW,R5    R7                THE ONE THAT'S THERE
         BCS,8    FOUND1            IT WAS..
         B        ENNAM2            WASN'T
         FIN
         PAGE
*                                   THIS ROUTINE PUSHED A DECLARATION
*                                   INTO THE DECLARATION STACK. IF A
*                                   STACK OVERFLOW OCCURS IT MOVES ALL
*                                   OTHER STACKS UP AND INCREASES THE
*                                   DECLARATION STACK BY X'40' WORDS.
*                                   THEN IT REPUSHES.
ENDECL   EQU      %
         PSW,R7   DECLSTK
         BCR,8    PUSHOK
         PSW,6    *0
DCSTKOVF LW,R1    EXPRSTK
         SW,R1    RFDFSTK
         CI,R1    K40
         BL       STOVF1
         LW,R1    RDPTRS
         SW,R1    RFDFSTK           DID WE RUN INTO SORT TABLE?
         CI,R1    K40               OR ARE WE ABOUT TO?
         BG       %+2               NOPE: LOTS OF ROOM
         DATA     FASTSRCH          YES: TAKE  S OUT OF FAST MODE
         LI,R1    K40
STOVF1   LW,R2    R1
         LW,R4    RFDFSTK1
         AND,R4   M15
         LW,R5    RFDFBAS
         AW,R5    R1
         LW,R6    RFDFBAS
         AI,R6    KN1
         AI,R5    KN1
STKMOVE  LW,D4    *R6,R4
         STW,D4   *R5,R4
         BDR,R4   STKMOVE
         MTW,0    FASTSRCH          IS THERE A SORT TABLE TO UPDATE
         BNEZ     NOTSOFAST         NO
         LW,R4    RDSYMS            UPDATE ALL POINTERS IN REF/DEF...
         AI,R4    -1                ...STACK SORT TABLE
         AWM,R2   *RDPTRS,R4
         BDR,R4   %-1
         AWM,R2   *RDPTRS
NOTSOFAST EQU     %
         SLS,R2   16
         AWM,R2   DECLSTK1
         LCW,R2   R2
         AWM,R2   RFDFSTK1
         AWM,R1   D1
         AWM,R1   RFDFSTK
         AWM,R1   RFDFBAS
         AWM,R1   CRFDF1            FOR LOADING M:MON
         LW,R6    D3
         SLS,R1   -1
         LI,R2    KN1
STKMOVE1 AWM,R1   RFDFDIS,R6
         AI,R6    TREESIZE
         CW,R6    *D3,R2
         BL       STKMOVE1
         PLW,6    *0
         B        ENDECL
PUSHOK   EQU      %
         B        *SR4
MOVER    LW,R6    *D2
         STW,R6   *D1
         MTW,1    D1
         MTW,1    D2
         BDR,R7   MOVER
         B        *SR4
Y004B    DATA,4   X'4B0000'
         BOUND    8
TX9INITIA DATA    X'08F9C9D5'
         TEXT     'ITIA'
TX9DBINIT TEXTC   '9DBINIT'
         END

