*        704730   SIGMA 5/7         BPM M:EVLOAD
***********************************************************************
*M*      EVL      FORMS THE CORE IMAGE FOR A LOAD MODULE.
***********************************************************************
*P*      NAME:    EVL
*P*      PURPOSE: ENTRY/EXIT FROM PS2.
*P*               EVALUATES EXPRESSIONS FROM PS1 AND CORE EXPRESSIONS
*P*                    FROM LOAD MODULES.
*P*               FORMS CORE IMAGE AND RELOCATION DICTIONARY GOING
*P*                    THROUGH EXTENDED MEMORY MODE LOGIC.
*P*               BUILDS REFERENCE LOADING TABLE.
*P*      DESCRIPTION: EVL IS ENTERED FROM PS2 ONCE FOR EACH SEGMENT,
*P*               BEGINNING WITH THE SUBLINKS,TO THE OVERLAY LINKS,AND
*P*               BACK DOWN TOWARD THE ROOT. IT HAS TWO ENTRY POINTS,
*P*               EVEXPRS AND LOADSEG. PS2 FIRST CALLS EVEXPRS(OR
*P*               EVEXSQZ IF IN EXTENDED MEMORY MODE) TO EVALUATE ALL
*P*               EXPRESSIONS FOR THIS SEGMENT WHICH WERE FORMED DURING
*P*               THE FIRST PASS. IT THEN CALLS LOADSEG TO ACTUALLY
*P*               FORM THE CORE IMAGE AND RELOCATION DICTIONARY BY
*P*               REPROCESSING THE OBJECT LANGUAGE OF A ROM OR READING
*P*               IN AND RELOCATING THE CORE IMAGE OF A LOAD MODULE.
*P*      REFERENCE: THE OVERLAY LOADER TECHNICAL MANUAL CONTAINS A
*P*               MORE DETAILED DESCRIPTION AND FLOW CHARTS.
***********************************************************************
         PCC      0
         SYSTEM   SIG7FDP
MODE     EQU      1
         DO       MODE=1
SD       EQU      1
         ELSE
SD       EQU      0
         FIN
         CSECT    1
         DEF      EVEXPRS           ENTRY POINT FOR EVALUATING A
*,*                                 PATH'S EXPRESSIONS.
         DEF      LOADSEG           ENTRY POINT FOR FORMING THE
*,*                                 LOAD IMAGE.
         DEF      MCEV
MCEV     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      M5
         REF      M6
         REF      M7
         REF      M15
         REF      M16
         REF      M17
         REF      M30
         REF      M32
         REF      MN2
         REF      MN16
         REF      X8
         REF      Y4
         REF      Y8
         REF      Y03
         REF      Y08
         REF      Y0F
         REF      Y68
         REF      YFF
         REF      Y001
         REF      Y002
         REF      Y004
         REF      Y008
         REF      Y00C
         REF      Y018
         REF      Y048
         REF      Y0004
         REF      Y0005
         REF      Y0006
         REF      Y0007
         REF      Y000B
         REF      Y000C
         REF      Y000F
         REF      Y0343
         REF      MSKFTYPE          EQUAL TO ABSOLUTE X'F0000'
         REF      TXLIB             TEXTC ':LIB'
         REF      SYMBOLTB          SET ZERO IF NO INTERNAL SYMBOL TBL
         REF      SYMTOP            TOP LOCATION OF INTERNAL SYMBOL TBL
         REF      TXBLNK            A WORD OF BLANKS
         REF      ER1X              UNEXPECTED EOF ERROR ROUTINE
         REF      ERAX              ILLEGAL ROM LANGUAGE ERR ROUTINE
         REF      ERB               BAD START ADDRESS-ERR CODE
         REF      ERC               UNEXPECTED ROM END-ERR CODE
         REF      ERD               ZERO REPEAT LOAD COUNT-ERR CODE
         REF      ERE               IMPROPER BOUND-ERR CODE
         REF      ERF               ILLEGAL ORG-ERR CODE
         REF      ER19              NO ROOM FOR LIB CORE IMAGE
         REF      ER1A              NO ROOM FOR LIB RELOCATION DICT.
         REF      ER1B              NO ROOM FOR NEW EXPRESSION
         REF      BLANKER           ROUTINE TO FILL PBUF WITH BLANKS
         REF      READBILI          READS A RECORD FROM M:EF
         REF      MESSAGE           PRINTS AN ERROR MESSAGE & ERROR CODE
         REF      GBYTE             RETURN NEXT BYTE OF ELEMENT FILE
         REF      EXPRES            TEMP STORE FOR EXPRESSIONS
         REF      GBYTE0            CHECK FIRST BYTE OF ELEMENT FILE
         REF      IOMSG             IO ERROR MESSAGER
         REF      SETEF             SET ERR,ABN IN M:EF
         REF      EFNAME            PLACE TO PUT NAME OF EF
         REF      2BNUM             RETURN NEXT 2 BYTES OF ELEMENT FILE
         REF      3BNUM             RETURN NEXT 3 BYTES OF ELEMENT FILE
         REF      4BNUM             RETURN NEXT 4 BYTES OF ELEMENT FILE
         REF      12BNUM            RETURN NEXT 1 OR 2 BYTE DECLARATION
*,*                                 NUMBER FROM ELEMENT FILE
         REF      DECLSTK           DECLARATION STACK SPD
         REF      DECLSTK1          2ND WORD OF DECLSTK SPD
         REF      DECLBAS           BASE OF DECLARATION STACK
         REF      RFDFBAS           BASE OF REF/DEF STACK
         REF      EXPRSTK           SPD FOR EXPRESSION STACK
         REF      EXPRSTK1          2ND WORD OF EXPRSTK SPD
         REF      EXPRBAS           BASE OF EXPRESSION STACK
         REF      BSEG1             TEMPORARY SEGMENT NUMBER
         REF      BSEG2             BASE OF LARGEST INTERNAL SYMB TBL
         REF      CSEG1             DISPLACEMENT FROM BEGINNING OF TREE
*,*                 TABLES TO BEGINNING OF TREE FOR CURRENT SEGMENT.
         REF      CSEG2             TEMP. STORAGE FOR SEGMENT NUMBER
         REF      CROM1             CURRENT ROM POINTER-DISPLACEMENT
*,*                 FROM START OF ROM TABLE TO CURRENT ROM
         REF      CURBYTE           DISPLACEMENT INTO CARD IMAGE
*,*                                 BEING READ BY GBYTE.
         REF      RCDSIZE           SIZE OF ROM RECORD READ BY GBYTE
         REF      SEQNUM            ACTUAL SEQUENCE NUMBER OF RECORD
*,*                                 JUST READ BY GBYTE.
         REF      SEVLEV            SEVERITY LEVEL OF LOAD MODULE
         REF      LASTCARD          FLAG SET FOR LAST CARD OF ROM
         REF      BUF               USED AS ROM INPUT BUFFER BY
*,*                 BY PS1 & EVL. USED AS OUTPUT BUFFER BY FIN,WRT.
         REF      BUF2              USED TO BUILD AN EXPRESSION
*,*                 FROM LOAD RELOCATABLE LOAD ITEM. USED IN WRT.
         REF      TREEPTR           POINTER TO LOADER-BUILT TREE TBL
         REF      RSEG00            POINTER TO ROOT SEGMENT TYPE 00
         REF      RSEG01            POINTER TO ROOT SEGMENT TYPE 01
         REF      RREL00            POINTER TO ROOT SEGMENT'S
*,*                 RELOCATION DICTIONARY FOR PROTECTION TYPE 00
         REF      CSEG00            POINTER TO CURRENT SEGMENT
*,*                                 FOR PROTECTION TYPE 00
         REF      CREL00            POINTER TO CURRENT SEGMENT'S
*,*                 RELOCATION DICTIONARY FOR PROTECTION TYPE 01
         REF      LOC               LOAD LOCATION COUNTER
         REF      START             LOAD MODULE START ADDRESS
         REF      LOCCT             ADDRESS OF LOCCT
         REF      LOADBAS           ACTUAL LOAD BIAS USED
         REF      MODBAS            USED FOR MERGING CORE IMAGE
*,*                                 RECORD INTO XMEM BUFFERS. SEE EVL.
         REF      RELDBAS           BASE OF RELOCATION DICTIONARY
*,*                                 FOR CORE IMAGE LIBRARY.
         REF      MBIAS             START OF ORIGINAL REF/DEF STACK
         REF      FBIAS             USED FOR PAGED LOAD MODULES,
*,*                 ADDRESS POINTING INTO CORE IMAGE BUFFERS.
         REF      BIAS              EQUIVALENT OF ORG TO EXECUTION
*,*                                 ADDRESS OF START OF ROM.
         REF      RDIG              RELOCATION DIGIT
         REF      MODSIZ            ARS FROM M:EF AFTER READING
*,*                                 RELOCATION DICTIONARY.
         REF      TOPOMEM           LAST AVAILABLE ADDRESS
         REF      OPENEF            OPEN PLIST FOR M:EF
         REF      LOCWD             FIRST WORD OF THE LOCCT,
*,*                                 CONTAINING PARAMETER BITS.
         REF      XMKEY             1 IF LIB. LMN IS BEING LOADED
         REF      PBUF              EXTENDED MEMORY MODE KEY USED
*,*                                 WRITE CORE IMAGE RECORDS.
         REF      PLIB              FLAG WHICH GETS SET IF THE
*,*                 ADDITION OF A CORE EXPRESSION WOULD CAUSE THE
*,*                 EXPRESSION STACK TO OVERWRITE A CORE IMAGE
*,*                 BUFFER ABOVE IT.
         REF      RFLDSG            SEGMENT NUMBER WHERE DEF IS
*,*                                 DEFINED IN BREF MODE.
         REF      EXPRDIS           DISPLACEMENT FROM START OF TREE
*,*                                 TO EXPRESSION STACK DESCRIPTOR
         REF      RFLOADIS          DISPLACEMENT FROM START OF TREE
*,*                                 TO SIZE OF REF/BREF TABLES
         REF      RFDFDIS           DISPLACEMENT FROM START OF TREE
*,*                                 TO REF/DEF STACK DESCRIPTOR.
         REF      NXROMDIS          DISPLACEMENT FROM START OF ROMT
*,*                                 TO FLAG WORD FOR LAST ROM.
         REF      ROM1DIS           DISPLACEMENT FROM START OF TREE
*,*                                 TO ROM POINTER FIELD.
         REF      00DIS             DISPLACEMENT FROM START OF TREE
*,*                                 TO 00 TYPE DESCRIPTOR WORD.
         REF      01DIS             DISPLACEMENT FROM START OF TREE
*,*                                 TO 01 TYPE DESCRIPTOR WORD.
         REF      01SIZ             FOR SPECIAL CSECT IN MERGING
*,*                                 LIBRARY LMNS. SEE ALLL.
         REF      TREESIZE          SIZE OF A TREE TABLE ENTRY
         REF      TREEDIS           DISPLACEMENT FROM START OF LOCCT
*,*                                 TO TREE TABLE DISPLACEMENT.
         REF      LIBER             I/O ERROR HANDLER FOR M:EF
         REF      FIRSTF            POINTER INTO REF/DEF STACK
*,*                                 FOR 1ST FORWARD REFERENCE.
         REF      LASTF             POINTER INTO REF/DEF STACK
*,*                                 FOR LAST FORWARD REFERENCE.
         REF      XCSEG1            RETAINS CURRENT SEGMENT TO
*,*                 PERMIT ALTERNATE USE OF CSEG1 FOR XMEM.
         REF      DECLCHK           ROUTINE TO TEST VALIDITY OF
*,*                                 A DECLARATION NUMBER.
         REF      CODE              LOADER ERROR CODE AFTER AN ERROR.
         REF      M:LM              DCB FOR WRITING LOAD MODULE
         REF      M:EF              DCB FOR READING ELEMENT FILES
         REF      RLOC              LOAD LOCATION COUNTER FOR
*,*                                 RELOCATION DICTIONARIES.
         REF      BREFBIT           BREF FLAG IN LOCWD
         REF      DOREFPTR          IN BREF MODE, POINTER TO
*,*                                 S:OVRLY IN REF/DEF STACK.
         REF      RFLDMODS          REF AND BREF FLAGS IN LOCWD
         REF      RFLDTBSZ          REF COUNT FROM LOCCT
         REF      BREFERR           COUNT OF REFS OVERFLOWING BREF TABLE
         REF      WRITELM           FPT USED TO WRITE LOAD MODULE
         REF      CLOSE             GENERAL M:CLOSE *R5 FPT
         REF      PRINT             M:PRINT *R5 FPT.
         REF      BITMASKS          ORDERED TABLE OF MASKS
         REF      TEMPR1            SCRATCH STORAGE TO AVIOD PUSHES
         REF      VAL%SW            COUNT OF # OF OVERLAY-CAUSING
*,*                                 REFS IF IN REF OR BREF MODE.
         DO       MODE=1
         REF      MREFLAG           SET NON-ZERO IN IN1 IF
*,*                                 LOADING IN MREF MODE.
         REF      MREFTAB           POINTS TO VALUE WORD OF DEF
*,*                 ENTRY IN REF/DEF STACK DEFINING MREF TABLE.
         REF      TOVBALPSD         POINTS TO VALUE WORD OF DEF
*,*                 ENTRY IN REF/DEF STACK DEFINING T:OVBALPSD
         REF      TOVBPSD           POINTS TO VALUE WORD OF DEF
*,*                 ENTRY IN REF/DEF STACK DEFINING T:OVBPSD
         REF      BINSRT            FAST SEARCH FOR ROOT RFDF STK
         REF      FASTSRCH          FLAG FOR SORT TABLE O.K.
         REF      RDPTRS            START OF BINARY SORT TABLE
         REF      TSTACK            TEMP STACK
         REF      TXTREE            DUMMY RECORD MAKING ROOM FOR LIB COREIMAGE
         REF      READBIL0          READ THE FIRST RECORD
         REF      UNSATFLG          FOR GETTING LIBRARY NAME
         REF      UNSATTBL          FOR GETTING LIBRARY NAMES
         FIN
         PAGE
BGEZ     EQU      X'681'
BE       EQU      X'683'
BNEZ     EQU      X'693'
BGE      EQU      X'681'
BL       EQU      X'691'
BLZ      EQU      X'691'
BAZ      EQU      X'684'
BCR8     EQU      X'688'
BCR10    EQU      X'68A'
BLE      EQU      X'682'
BEZ      EQU      X'683'
BNE      EQU      X'693'
*        QUIT     ERROR,CONDITION
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
*        SNAP     FROM,TO,TEXT1,TEXT2
SNAP     CNAME
         PROC
LF       CAL1,3   %+1
         DATA     0,AF(1),AF(2),AF(3),AF(4),X'02000000'
         PEND
         PAGE
*                 SYMBOLIC REGISTER DEFINITIONS.
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
SR1      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
         PAGE
*                 IMMEDIATE CONSTANTS FOR LOADER.
K0       EQU      0
K1       EQU      1
K2       EQU      2
K3       EQU      3
K4       EQU      4
K5       EQU      5
K6       EQU      6
K7       EQU      7
K8       EQU      8
K9       EQU      9
KA       EQU      X'A'
KB       EQU      X'B'
KC       EQU      X'C'
KD       EQU      X'D'
KE       EQU      X'E'
KF       EQU      X'F'
K10      EQU      X'10'
K11      EQU      X'11'
K12      EQU      X'12'
K13      EQU      X'13'
K16      EQU      X'16'
K17      EQU      X'17'
K19      EQU      X'19'
K1C      EQU      X'1C'
K1E      EQU      X'1E'
K1F      EQU      X'1F'
K20      EQU      X'20'
K22      EQU         X'22'
K24      EQU      X'24'
K26      EQU      X'26'
K39      EQU      X'39'
K3C      EQU      X'3C'
K3F      EQU      X'3F'
K40      EQU      X'40'
K43      EQU      X'43'
K6C      EQU      X'6C'
K78      EQU      X'78'
K80      EQU      X'80'
KF0      EQU      X'F0'
KF1      EQU      X'F1'
KF2      EQU      X'F2'
KFF      EQU      X'FF'
K100     EQU      X'100'
K120     EQU      X'120'
K1FF     EQU      X'1FF'
K200     EQU      X'200'
K202     EQU      X'202'
K256     EQU      X'256'
K800     EQU      X'800'
KC00     EQU      X'C00'
K2000    EQU      X'2000'
K3FFF    EQU      X'3FFF'
K4000    EQU      X'4000'
K7FFF    EQU      X'7FFF'
KFF00   EQU      X'FF00'
K8000    EQU      X'8000'
K1FE00   EQU      X'1FE00'
K1FFFF   EQU      X'1FFFF'
K20000   EQU      X'20000'
KN1      EQU      -1
KN2      EQU      -2
KN3      EQU      -3
KN4      EQU      -4
KN8      EQU      -8
KN16     EQU      -16
KN100    EQU      -100
KN200    EQU      -X'200'
KN3FE    EQU      -X'3FE'
KN400    EQU      -X'400'
KTE      EQU      'E'
KTR      EQU      'R'
         PAGE
*                                   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
         LW,R7    D1
         AW,R7    R6
         AI,R7    -1
         STW,R7   EXPRES            SAVE EXPR ADDR
         STW,SR1  0,R7              CLEAR RESOLUTION WORD
         LW,R7    R6
         SLS,R7   2
         AI,R7    1
*                                   THIS IS THE GENERAL EXPRESSION
*                                   CONTROL BYTE DECODER.
EVWHATEC AI,R7    K1
         LB,D2    0,R7
         BE       EVWHATEC
         CI,D2    K2
         BE       EVEXPEND
         BL       EVADCON
         LW,R4    D2
         SLS,R4   -2
         CI,R4    KC
         BE       EVCHGRES
         BG       AABS
         B        EVGETVAL
*                                   ADD CONSTANT.
EVADCON  AW,SR1   *D1,R6
EVINCWD  AI,D1    K1
         B        EVWHATEC
*                                   CHANGE RESOLUTION.
EVCHGRES LW,R5    EXPRES            RES WORD
         AI,R5    -2                DISP FOR WHATRES
         LI,R3    K3                NEW RESOLUTION
         AND,R3   D2
         LCI      2                                                     4730
         PSM,R1   *R0                                                   4730
         BAL,SR4  WHATRES
         LW,R2    R3                NO SHIFT IF WAS ABS
         SW,R2    R3
         SLS,SR1  0,R2
         LI,R1    0
         STW,R1   *EXPRES           SET NEW RESOLTUION
         MTB,1    *EXPRES,R3
NEXTEC   LCI      2                                                     4730
         PLM,R1   *R0                                                   4730
         B        EVWHATEC
AABS     LI,R4    K3                RESOLUTION
         AND,R4   D2
         CI,D2    K8
         BAZ      %+2               ADD OR SUBTRACT
         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
         LH,R4    *R6
         CI,R4    X'40'                                                 730
         BANZ     EVEXPUN1                                              730
*                                   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 POINTER
         AW,R4    R1                TREE ADDR
         LW,R4    RFDFDIS,R4        STACK ADDR
         AND,R4   M16
         SLS,R4   1
         AW,R4    R5
         LW,R5    Y001
         CW,R5    0,R4
         BANZ     EVEXPUN1
         STS,R5   0,R4
         STW,SR1  1,R4
         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                ADDING RESOLUTION
         AND,SR2  D2
         BAL,SR4  WHATRES           VALUES RESOLUTION
         LW,R2    SR2               NO SHIFT IF ABS
         LW,R4    -2,R5             DECLS VALUE
         SW,R2    SR2
         SLS,R4   0,R2
         SCS,D2   -4                MAKE BDR WORD FOR
         AI,D2    100                ADD/SUBTRACT TEST
         BDR,D2   %+2
         LCW,R4   R4                SUBTRACT
         AW,SR1   R4
         LW,R4    -1,R5             MIX THE RESOLUTIONS
         SLS,R2   3
         SLS,R4   0,R2
         LW,R5    *EXPRES           EXPRESSIONS CURRENT RESOLUTION
         LI,R2    KN4
EVFIXRES LB,R1    R5,R2
         LB,D3    R6,R2
         BDR,D2   %+2
         LCW,R1   R1
         AW,D3    R1
         STB,D3   R6,R2
         BIR,R2   EVFIXRES
         STW,R5   *EXPRES
         LCI      K2
         PLM,R1   *R0
         B        EVINCWD
*                                   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.
EVEXPRS  PSW,SR4  *R0
EVEXPRS1 LI,SR2   K0
         LW,R5    CSEG1
         AW,R5    R1                TTREE SEGMENT ADDR
         LW,SR3   EXPRDIS,R5        EXPR START/SIZE
         LH,R6    SR3               SIZE IN WDS
         AND,SR3  M16               DWD ADDR
         SLS,SR3  1
         AW,SR3   R6                END
         LW,R6    EXPRBAS
         BAL,SR4  %+3               SET RETURN FROM EVEXP
         LB,R7    *R6
         AW,R6    R7
         CW,R6    SR3
         BL       EVEXP             MORE TO DO
         CW,SR2   Y008
         BANZ     EVEXPRS1
EVEXEN   PLW,SR4  *R0
         B        *SR4
         SPACE    10
         PAGE
*                                   LOAD SEG MAKES THE SECOND PASS AT
*                                   THE OBJECT LANGUAGE AND FROM THE
*                                   CORE IMAGE OF THE LOAD MODULE.
YEES     DATA     X'EEEEEEEE'
LOADSEG  PSW,SR4  *R0
         LW,R4    LOCWD
         CI,R4    X'4100'
         BANZ     ZREL
*                                   THE RELOCATION DICTIONARY IS
*                                   INITIALIZED TO E'S (ABS) IN THE ROOT
*                                   SEGMENT AND O'S IN HIGHER SEGMENTS.
         LW,R4    CREL00
         LW,R5    CSEG00
         LI,R6    0
         LW,R7    CSEG1
         BNEZ     ZREL1
         LW,R6    YEES
         LW,R4    RREL00
         LW,R5    RSEG00
ZREL1    SLD,R4   -2
         SW,R5    R4
         AI,R4    -1
         STW,R6   *R4,R5
         BDR,R5   %-1
ZREL     EQU      %
         LW,R7    CSEG1             INITIALIZE
         AI,R7    RFDFDIS           FORWARD
         LW,R7    *R7,R1            REFERENCE
         LH,R3    R7                BOUNDARIES.
         AND,R7   M16
         SLS,R7   1
         STW,R7   FIRSTF
         AND,R3   M16
         AW,R7    R3
         STW,R7   LASTF
*                                   THIS LOGIC CONTROLS THE READING AND
*                                   LOADING OF ALL THE FILES FOR THIS
*                                   SEGMENT. WE INITIALIZE TO THE 1ST
*                                   FILE IN THE SEGMENT, LOAD IT, CHECK
*                                   FOR ANOTHER ROM IN THE SAME FILE.
*                                   IF THERE IS ONE WE LOAD IT AND
*                                   PROCEED. IF NOT GO TO THE NEXT FILE.
*                                   IF THE FILES ARE FROM THE LIBRARY WE
*                                   AVOID UNNECESSARY OPENS AND CLOSES.
FIRSTROM LW,R4    CSEG1
         AI,R4    ROM1DIS
         LW,R4    *R1,R4
         LH,R4    R4
NEXTROM  STW,R4   CROM1
         BAL,SR4  LOCROM
CALLP1   LCI      K3
         PSM,R1   *R0
         BAL,SR4  LP1
         LCI      K3
         PLM,R1   *R0
NUTHER   BAL,SR4  READBILI
         B        NEWROM
         BAL,SR4  CHECKROM
         B        CALLP1
NEWROM   EQU      %
         LI,R5    M:EF
         CAL1,1   CLOSE
GETROM   LW,R4    CROM1
         AI,R4    NXROMDIS
         LW,R5    *R4,R2
         AI,R4    7-2               ROMSIZE-NXROMDIS
         CI,R5    X'40'
         BANZ     NEXTROM
         PLW,SR4  *R0
         B        *SR4
         PAGE
*                                   THIS ROUTINE OPENS M:EF TO THE FILE
*                                   SPECIFIED IN THE ROM TABLE UNLESS
*                                    WE HAVE ANOTHER LIBRARY ROUTINE
*                                   IN THE SAME ACCOUNT #.
LOCROM   PSW,SR4  *R0
         LW,D1    M:EF
         CW,D1    Y002
         BAZ      LOCROM1
CLOCROM  LI,R5    M:EF
         CAL1,1   CLOSE
LOCROM1  LI,D1    OPENEF+8
         BAL,SR4  LOADOPL
         LI,SR1   LIBER             ERR/ABN ADDR
         CAL1,1   OPENEF
LOCROM2  RES
         BAL,SR4  READBIL0
         B        ER1X
         B        CHCKROM1
         SPACE    10
*                                   THIS ROUTINE MOVES THE NAME,
*                                   ACCOUNT # AND PASSWORD FROM THE
*                                   ROM TABLE TO THE OPEN PLIST. IF
*                                   THE ROM IS IN A LIBRARY THE FILE
*                                   NAME :LIB IS USED INSTEAD.
LOADOPL  PSW,SR4  *R0
         LW,D2    CROM1
         AW,D2    R2
         LW,R7    D2
         LW,R7    2,R7
         CI,R7    2
         BAZ      %+3
         LI,R6    2
         B        %+2
         LI,R6    1
         LI,R7    3
         STS,R6   OPENEF+1
         LI,R7    K3
         BAL,SR4  MOVER
         MTW,1    D1
         LI,R7    K2
         BAL,SR4  MOVER
         MTW,1    D1
         LI,R7    K2
         BAL,SR4  MOVER
         PLW,SR4  *R0
         LW,R7    EFNAME+2          CHECK IF FROM LIBRARY
         CI,R7    K20
         BAZ      *SR4
         SLS,R7   -2                GET UNSAT INDEX
         AND,R7   M3
         LB,R6    UNSATFLG,R7
         AND,R6   M6                GET UNSAT DISP
         AW,R6    UNSATTBL          ADDR OF NAME
         LC       UNSATFLG,R7       IF THERE'S NO NAME
         BCS,8    %+2               USE :LIB
         LI,R6    TXLIB
         LCI      3
         LM,R6    0,R6
         STM,R6   EFNAME
         B        *SR4
         SPACE    10
MOVER    LW,R6    *D2
         STW,R6   *D1
         MTW,1    D1
         MTW,1    D2
         BDR,R7   MOVER
         B        *SR4
         PAGE
*                                   THIS ROUTINE VERIFIES THE 1ST WORD
*                                   OF THE FIRST CARD OR READER. IF THE
*                                   TYPE IS NOT -C WE HAVE A LIBRARY
*                                   LOAD MODULE.
CHECKROM PSW,SR4  *R0
CHCKROM1 BAL,SR4  GBYTE0
         BCS,8    ADLDMD
         PLW,SR4  *R0
         B        *SR4
         PAGE
*                                   THIS ROUTINE READS IN THE CORE IMAGE
*                                   OF THE LIBRARY LOAD MODULE RELOCATES
*                                   IT AND EVALUATES ANY CORE EXP-
*                                    RESSIONS PERTAINING TO IT.
ADLDMD   EQU      %
         LW,D3    R1
*                                   FIND THE DUMMY CONTROL SECTION
*                                   INSERTED IN FRONT OF THIS MODULES
*                                   REF/DEF ENTRIES.
         BAL,SR4  DCS2
         STW,R5   FIRSTF
         LW,R1    D3
         PSW,R5   *R0                                                   730
         LW,D3    CSEG1
         STW,D3   XCSEG1
         LW,D3    *R5
         AND,D3   Y00C
         SLS,D3   -22
         LW,SR1   *R5
         AND,SR1  M16
         BNEZ     %+3
         PLW,R5   *R0
*                                   IN CASE THE MODULE IS ONLY DEFS.
*
         B        COREXP2+1
         SLS,SR1  1
         LW,R3    *R5               IF CSEC1 SPECIFIED & P.T.
         AND,R3   Y002                OF THIS LIBLMN = 0,
         SLS,R3   -21                 BIT 10 OF R/D ENTRY =1.
*                                   CALCULATE THE RELOCATION BIAS.
         LW,D4    1,R5
         INT,R7   BUF+2
         SLS,R7   1
         SW,R7    D4
         LCW,R7   R7
         STW,R7   MBIAS
*                                   CALCULATE THE ADDRESS IN THE APPROP-
*                                   RIATE BUFFER TO READ THE CORE IMAGE
*                                   INTO = CSEC VALUE-SEG BASE +
*                                   BUFFER.
         LW,R6    CSEG1
         CI,R3    K1                UNLESS THIS IS LIB LMN
         BNE      %+3                 OF P.T. 0 WITH CSEC1
         LI,D3    0                   SPECIFIED, USE ITS
         B        %+2                 ACTUAL PROTECTION TYPE
*                                     FOR READING RECORDS.
         LW,R3    D3
         CI,R6    0
         BE       %+4
         LW,R7    CSEG00,R3         PICK UP PROPER CSEG
         LW,D1    CREL00,R3         (R3 CONTAINS PROTECTION TYPE)
         B        %+3
         LW,R7    RSEG00,R3
         LW,D1    RREL00,R3
         SLS,R7   -2
         STW,R7   FBIAS
         SLS,D1   -2
         SLS,D3   1
         AW,R6    D3
         AI,R6    00DIS
         INT,D2   *R6,R1
         SLS,D2   1
         STW,D2   BIAS
         LW,R4    D4
         SW,R4    D2
         AW,R4    R7
         LW,SR3   R4
         LW,SR4   LOCWD
         CI,SR4   K4000
*                                   IN EXTENDED MEMORY WE HAVE TO READ
*                                   THE IMAGE IN ABOVE THE EXPR STACK
*                                   IF THERE IS ROOM AND PUT EACH WORD
*                                   THRU THE XMEM LOGIC TO INSURE
*                                   THE RIGHT PAGE(S) BEING IN THE
*                                   XMEM BUFFERS.
         BAZ      ADXM1
         LW,R4    EXPRSTK
         AI,R4    1
         LW,R5    TOPOMEM
         AI,R5    KN3FE
         CI,SR4   K100
         BAZ      %+2
         AI,R5    K200
         LW,R6    SR1
         SLS,R6   -3
         AW,R6    SR1
         SW,R5    R6
         CW,R5    R4
*E*      ERROR:   0200-19
*E*      MESSAGE: NO ROOM TO READ LIBRARY CORE IMAGE.
*E*      DESCRIPTION: THERE IS NOT ENOUGH MEMORY TO READ IN THE
*E*               LIBRARY'S CORE IMAGE RECORD.
         QUIT     ER19,BGE,R6
         AW,R6    R4                CHECK THE BINARY SEARCH TABLE
         AI,R6    511               PLUS BUFFER PAGE
         CW,R6    RDPTRS
         BLE      %+2
         DATA     FASTSRCH          WILL: TURN IT OFF
ADXM1    STW,R4   MODBAS
         LW,R5    CROM1
         AW,R5    R2
         MTB,1    *R5
         LW,R6    2,R5              SAVE 3RD WD OF ROMT ENTRY
         PSW,R6   *R0
         LB,R6    *R5
         AI,D3    K3
         STB,D3   *R5,R6
         LW,R6    SR1
         SLS,R6   3                 GET ROOM FOR BOTH PARTS
         CI,SR4   K4000             IF EXTENDED MEMORY
         BAZ      %+3               SO THAT WRFDFXM WORKS RIGHT
         AW,R6    SR1
         AI,R6    7                 AND BTD
         SLS,R6   -1
         DO       MODE=1
         MTW,0    MREFLAG           IF LOADING MONITOR
         BEZ      ADXM6             USE RFDFSTK
         LW,R4    RFDFBAS
         STW,R4   MODBAS
         CAL1,1   WRFDFXM
ADXM6    RES
         XW,R4    R5
         BAL,11   CHKLM
         XW,R4    R5
         REF      CHKLM
         FIN
*                                   READ THE IMAGE IN.
         CAL1,1   READLIB           READ VIA M:EF
         LB,R6    *R5
         AI,D3    KN1
         STB,D3   *R5,R6
         LI,R6    K0
         LW,R7    D4
         SW,R7    D2
         DW,R6    X8
         AW,R7    D1
         SLS,R6   -1
*                                   IF NOT XMEM AND NOT ABS READ THE
*                                   REL DICT INTO ITS BUFFER.
*                                   IF XMEM READ IT IN ABOVE THE CORE
*                                   IMAGE. IF ABS READ IT IN ABOVE THE
*                                   EXPR STACK.
         LW,D1    LOCWD
         CI,D1    K4000
         BAZ      ADXM2
         LW,R7    MODBAS
         AW,R7    SR1
         B        READRLD
ADXM2    CI,D1    K100
         BAZ      READRLD
         LW,R7    EXPRSTK
         AI,R7    K1
         SLS,SR1  -2
         AW,R7    SR1
         SLS,R7   2
         CW,R7    CSEG00
*E*      ERROR:   0200-1A
*E*      MESSAGE: NO ROOM TO READ LIBRARY RELOCATION DICTIONARY
*E*      DESCRIPTION: THERE IS NOT ENOUGH MEMORY TO READ THE LIBRARY'S
*E*               RELOCATION DICTIONARY.
*E*      REGISTERS: SR1 HAS THE SIZE OF THE LIBRARY'S RELOCATION DICT.
         QUIT     ER1A,BLE,SR1
         SLS,R7   -2
         SW,R7    SR1
READRLD  EQU      %
         PSW,R4   *R0
         LW,R4    M:EF+13           GET SIZE FROM DCB
         SLS,R4   -3                IN BYTES OF RELOC DICT
         PSW,R4   *R0               SAVE FOR A WHILE
         AW,R4    R6                WHILE WE GET THE BUFFER [AGES
         MTB,0    *R7,R4
         AI,4     -2048
         BGZ      %-2
         MTB,0    *R7
         PLW,R4   *R0
*                                   READ THE REL DICT.
         CAL1,1   READREL
         PLW,R4   *R0
         PLW,D1   *R0               RESTORE 3RD WD OF ROMT ENTRY
         STW,D1   2,R5
         MTB,-1   *R5
         STW,R7   RELDBAS
         LW,R7    M:EF+13
         AW,R7    R6
         STW,R7   MODSIZ
         AI,R6    KN1
         STW,R6   RDIG
*                                   RELOCATE THE IMAGE.
         BAL,SR4  RELOCATE
         LW,R4    SR3
         LW,D1    LOCWD
         CI,D1    K4000
         BAZ      ADXM3X
*                                   IF XMEM MOVE EACH WORD OF THE
*                                   RELOCATED IMAGE INTO THE XMEM
*                                   BUFFER.
         LW,SR2   M:EF+13           GET # WORDS OF IMAGE
         SLS,SR2  1
         LW,D1    MODBAS
         LI,R5    0
ADXM4    LW,R7    R4
         BAL,SR4  XMEM
         LW,D2    *D1,R5
         STW,D2   *R6
         AI,R5    1
         AI,R4    1
         CW,R5    SR2
         BL       ADXM4
         DO       MODE=0
*                                   IF XMEM, MOVE THE REL DIGITS TO THE
*                                   XMEM REL DICT BUFFER.
ADXM3    LW,R7    LOCWD
         CI,R7    K100              IS LOAD MODULE BEING GENERATED 'ABS'
         BANZ     ADXM3X            YES
         LW,R7    SR3               NO
         SLS,R7   2
         PSW,R1   *R0
         BAL,SR4  FNDRELDG          FIND CORE LOCATION FOR NEXT REL-DIC
         PLW,R1   *R0
         SLS,R6   -1
         SLS,R7   2
         LW,SR3   R7                MAKE CORE LOCATION A BYTE ADDRESS
         OR,SR3   R6
         LW,R4    RELDBAS
         SLS,R4   2
         AW,R4    RDIG              GET BYTE ADDRESS OF INPUT BUFFER
         LW,D1    MODSIZ
         AW,D1    SR3               ESTABLISH LOOP LIMIT
ADXM3I   LW,R7    SR3
         SLS,R7   -2                WORD LOC OF NEXT REL-DICT ITEM
         BAL,SR4  XMEM
         DATA     0                 SPECIFY REL-DICT TO XMEM
         AI,R4    1
         LB,D2    0,R4              GET NEXT BYTE OF LIBR REL-DICT
         LI,R7    K3
         AND,R7   SR3               BYTE OFFSET OF DESTINATION ADDRESS
         STB,D2   *R6,R7            PUT AWAY TWO DIGITS OF REL-DIC INFO
         AI,SR3   1                 BUMP CORE BYTE ADDRESS
         CW,SR3   D1
         BLE      ADXM3I
         ELSE
         MTW,0    MREFLAG
         BEZ      ADXM3X
         LW,R5    EXPRSTK
         SW,R5    RFDFBAS
         SLS,R5   2                 SIZE OF BUFFER
         CAL1,1   RRFDFXM            REPLACE RFDFSTK
         FIN
*                                   FROM THE DUMMY LOAD MODULE CONTROL
*                                   SECTION GET THE BOUNDS OF THE EXPR
*                                   STACK AND EVALUATE THE CORE
*                                   EXPRESSIONS. ADJUST THE RELOCATION
*                                   DIGIT ACCORDING TO THE CORE EXPR.
ADXM3X   PLW,R5   *R0
         PSW,R2   *R0                                                   730
         LW,R6    CSEG1
         AW,R6    R1                                                    730
         INT,R6   EXPRDIS,R6
         SLS,R7   1                                                     730
         LW,R6    2,R5                                                  730
         LH,SR3   R6                                                    730
         BEZ      COREXP2
         AND,R6   M16                                                   730
         AW,R6    R7                                                    730
         AW,SR3   R6                                                    730
COREXP   LW,D3    *R6                                                   730
         CW,D3    Y004                                                  730
         BAZ      COREXP1                                               730
         PSW,R5   *R0                                                   730
         BAL,SR4  EVEXP1                                                730
         PLW,R5   *R0                                                   730
         LH,R7    *R6                                                   730
         AND,R7   M6                                                    730
         AI,R7    -2                                                    730
         LW,R2    *R6,R7                                                730
         LW,D2    R6
         AW,D2    R7
         AI,D2    K2                SAVE ADDR OF WORD1 IN D2 FOR WHATRES
         AW,R2    1,R5
         LCI      5
         PSM,R6   *R0
         PSW,R1   *R0                                                   730
         LW,R6    *R5
         SLS,R6   -22
         AND,R6   M2
         LW,SR3   R6
         SLS,R6   1
         AI,R6    5
         AW,R6    CSEG1
         INT,R7   *R6,R1
         SLS,R7   1
         SW,R2    R7
         AI,SR3   CSEG00
         LW,R1    *SR3
         SLS,R1   -2                                                    730
         AW,R2    R1                                                    730
         LW,R7    LOCWD
         CI,R7    K100              IS LOAD MODULE BEING GENERATED 'ABS'
         BANZ     COREXP0           YES  -  REL-DICT DOES'T EXIST
         LI,R7    K1FFFF
         AND,R7   R2
         SLS,R7   2                 PHYS LOC OF LOAD ITEM IN BYTES
         BAL,SR4  FNDRELDG          GET PHYSICAL ADDRESS OF RELOC DIGIT
         LI,R1    K7
         SW,R1    R6                ADJUST DIGIT OFFSET FOR SHIFT COUNT
         SLS,R1   2
         DO       MODE=0
         BAL,SR4  XMEM
         DATA     0                 SPECIFY REL-DICT TO XMEM
         ELSE
         LW,R6    R7
         FIN
         LI,SR4   KF                SET UP DIGIT SELECT MASK
         LI,SR3   KE                COMPARE CHAR IS THE DIGIT 'E' (ABS)
         SLD,SR3  0,R1              SHIFT MASK AND DIGIT FOR COMPARISON
         CS,SR3   0,R6
         BNE      COREXP0           B IF DIGIT IS NOT E (ABSOLUTE)
         LCI      5
         PSM,R1   *R0
         LW,R5    D2
         BAL,SR4  WHATRES+1         GO PICK UP RESOLUTION IN R2
         B        COREXPA           B IF RES. IS MIXED OR NONE
         LCI      5
         PLM,R1   *R0
         LI,SR4   KF
         LW,SR3   R2
         SLD,SR3  0,R1              SHIFT RELOCATION DIGIT
         STS,SR3  0,R6
         B        COREXP0
COREXPA  EQU      %
         LCI      5
         PLM,R1   *R0
COREXP0  EQU      %
         BAL,SR3  STOREFLDN                                             730
         PLW,R1   *R0                                                   730
         LCI      5
         PLM,R6   *R0
COREXP1  LB,R7    *R6                                                   730
         AW,R6    R7                                                    730
         CW,R6    SR3                                                   730
         BNE      COREXP                                                730
COREXP2  EQU      %
         PLW,R2   *R0                                                   730
         PLW,SR4  *R0
         B        NEWROM
READLIB  GEN,8,24 X'10',M:EF
         DATA     X'7C000010'
         DATA     LIBERR,X'80000004',X'80000006',X'80000005',0
WRFDFXM  GEN,8,24 17,M:LM
         DATA     X'38000070'
         PZE      *RFDFBAS
         PZE      *R6
         PZE      TXTREE
RRFDFXM  GEN,8,24 16,M:LM
         DATA     X'38000010'
         PZE      *RFDFBAS
         PZE      *R5
         PZE      TXTREE
*E*      ERROR: 0200-2F
*E*      MESSAGE: ABNORMAL I/O READING LIB LMN
*E*      DESCRIPTION: AN ABNORMAL CONDITION OCCURRED WHILE READING
*E*               A LIBRARY LOAD MODULE.
*E*      REGISTERS: SR3 HAS THE SYSTEM I/O ERROR INFORMATION.
LIBERR   QUIT X'2F',,SR3            ABNORMAL I/O READING LIB LMN
*                                   THIS ROUTINE RELOCATES MODSIZ*2
*                                   WORDS STARTING AT MODBAS ACCORDING
*                                   TO THE RELOCATION DIGITS AT BYTE
*                                   RDIG WORD RELODBAS.
RELOCATE LW,D2    MODBAS
         LW,D1    RELDBAS
         LW,R4    RDIG
         LI,R5    KN1
NEXTRCD  AI,R4    K1
         CW,R4    MODSIZ
         BGE      *SR4
         LI,D4    K0
         LB,R6    *D1,R4
         SLS,R6   -4
NXTLDITM AI,R5    K1
         CI,R6    KE
         BE       NEXTRCD1
         CI,R6    K3
         BG       %+3
         LW,D3    MBIAS
         B        RELADD
         AND,R6   M3
         LW,SR2   *D2,R5
         CI,R6    K2
         BG       %+3
         LW,D3    MBIAS
         SLS,D3   -1
         B        RELAHALF,R6
NEXTRCD1 MTB,0    D4
         BNEZ     NEXTRCD
         MTB,1    D4
         LB,R6    *D1,R4
         AND,R6   M4
         B        NXTLDITM
RELADD   SLS,D3   15
         LW,SR2   *D2,R5
         SLD,SR1  13,R6
         AW,SR2   D3
         LCW,R6   R6
         SLD,SR1  -13,R6
         STW,SR2  *D2,R5
         B        NEXTRCD1
RELAHALF B        LEFTH
         B        RIGHTH
         B        BOTHHS
LEFTH    SLS,D3   16
         AW,SR2   D3
         B        RIGHTH3
RIGHTH   SLS,D3   16
RIGHTH2  SLD,SR1  16
         AW,SR2   D3
         SLD,SR1  -16
RIGHTH3  STW,SR2  *D2,R5
         B        NEXTRCD1
BOTHHS   SLS,D3   16
         AW,SR2   D3
         B        RIGHTH2
READREL  GEN,8,24 X'10',M:EF
         DATA     X'3C000010'
         DATA     X'80000007',X'80000004',X'80000005',X'80000006'
         PAGE
LP1      EQU      %
*                                   THIS IS THE OBJECT LANGUAGE PROCESSO
*                                   IT READS ONE OBJECT MODULE, FORMS
*                                   IMAGE AND RELOCATION DICTIONARY
*                                   AND RETURNS.
         PSW,SR4  *R0
         LW,D1    RFDFBAS
         LW,D2    DECLBAS
         LW,D3    R1
         LW,R1    DECLBAS
         SW,R1    DECLSTK
         MSP,R1   DECLSTK
         BAL,SR4  DCS2
         STW,R5   FIRSTF
         LW,R2    DECLSTK
         STW,R7   *R2
         LW,R5    CSEG1
         STW,R5   XCSEG1
*                                   THE OBJECT CONTROL BYTES ARE FETCHED
*                                   AND THE APPROPRIATE ROUTINE IS
*                                   CALLED.
LDR1     BAL,SR4  GBYTE
         CI,R5    X'20'
         BGE      LITEM             LOAD ITEM
         LH,R1    ITEMV,R5
         BNEZ     MCEV,R1
         B        ERAX
ITEMV    DO1      16
         DATA     0
IV       CNAME
         PROC
         ORG,2    HA(ITEMV)+CF(2)
         DATA,2   AF-MCEV
         PEND
         IV,0     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    DSTART
         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
*
*
*E*      ERROR: 0200-0F
*E*      MESSAGE: ILLEGAL ORG
*E*      DESCRIPTION: AN ORIGIN WAS GENERATED HAVING NO RESOLUTION OR
*E*               WAS NOT WITHIN THE LOAD MODULE (ASSEMBLER OR
*E*               COMPILER ERROR, OR VIOLATION OF LOADER DSECT
*E*               RESTRICTIONS).
*E*      REGISTERS: SR4 HAS LAST SUBROUTINE LINK ADDRESS
ERFX     QUIT     ERF,,SR4
*E*      ERROR: 0200-0B
*E*      MESSAGE: BAD START ADDRESS
*E*      DESCRIPTION: A START ADDRESS WAS GIVEN WHICH WAS EITHER NOT
*E*               ON A WORD BOUNDARY OR NOT WITHIN THE LOAD MODULE.
*E*      REGISTERS: SR1 HAS THE START ADDRESS.
ERBX     QUIT     ERB,,SR1
         PAGE
SD11     BAL,11   12BNUM
         BAL,11   GBYTE
         B        LDR1
SD12     EQU      %
         DO       SD=1
         LW,R3    LOCWD
         CW,R3    Y08               INHIBIT LOCAL SYMBOL TABLE BUILDING
         BANZ     SDKRD14           YES
         MTW,0    SYMBOLTB          FORM IST
         BGEZ     SDKRD0            YES
SDKRD14  EQU      %
         FIN
         BAL,11   GBYTE             NO-SKIP THE LOAD ITEMS
         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
         DO       SD=1
SDKRD0   EQU      %
         LW,R3    SYMBOLTB
         AI,R3    -3                BASE OF NEW ENTRY
         CW,R3    EXPRSTK           ROOM FOR NEW ENTRY
         BG       SDKRD15           YES
         LI,R1    -1
         STW,R1   SYMBOLTB          NO-SET NO IST GENERATION
         B        SDKRD14              SKIP THIS AND FURTHER IST ENTRYS
SDKRD15  LI,R5    0
         STW,R5   0,R3
         STW,R5   1,R3              CLEAN OUT NAME FIELD
         PSW,R7   *R0
         LW,R7    R3                COPY INDEX SO GBYTE WONT CLOBBER IT
         BAL,SR4  GBYTE             GO-GET TYPE AND RESOLUTION
         SLS,R5   24
         STW,R5   2,R7              TYPE AND RESOL. INTO ENTRY
         BAL,SR4  GBYTE             GO-GET NAME LENGTH
         CI,R5    0
         BNE      %+2
         B        ERAX              ERROR-NAME LENGTH ZERO
         CI,R5    63
         BLE      %+2
         B        ERAX              ERROR-NAME LENGTH GT 63 BYTES
         STB,R5   *R7               TEXTC OF NAME FIELD
         LW,D4    R5
         CI,D4    7
         BLE      %+2
         LI,D4    7                 ALLOW NO MORE THAN 7 CHARS IN NAME
         LI,R6    1
SDKRD1   BAL,SR4  GBYTE
         STB,R5   *R7,R6
         AI,R6    1
         BDR,D4   GBYTE             PUT 1ST 7 CHARS IN NAME FIELD
         LB,R6    *R7
         AI,R6    -7                MORE THAN 7 CHARS IN NAME
         BLEZ     SDKRD2            NO
         BAL,SR4  GBYTE             YES-BURN REMAINING CHARS
         BDR,R6   GBYTE
SDKRD2   LW,R1    SYMBOLTB
         LW,R5    M30               DO NOT CHECK TYPE
         LW,R3    R7                COPY INDEX BACK INTO R3
         PLW,R7   *R0
SDKRD3   CW,R1    SYMTOP            CHECKED ALL ENTRIES
         BGE      SDKRD6            YES
         LW,R4    0,R3
         CS,R4    0,R1              COUNT AND 3 CHARS MATCH
         BE       SDKRD5            YES
SDKRD4   AI,R1    3                 ADVANCE TO NEXT ENTRY
         B        SDKRD3
SDKRD5   LW,R4    1,R3
         CW,R4    1,R1              LAST 4 CHARS SAME
         BNE      SDKRD4            NO
         BAL,SR4  EXPRSKP           YES-SKIP EXPRESSION
         B        LDR1              GET NEXT LOAD ITEM
SDKRD6   LW,R7    SYMBOLTB
         AI,R7    -1                DESTINATION
         PSW,R3   *R0       SAVE NEW ENTRY BASE
         BAL,SR4  EXPRIN            GO-EVALUATE EXPRESSION
         PLW,R3   *R0               RESTORE BASE OF NEW ENTRY
         CI,SR3   0                 VALUE DEFINED
         BE       SDKRD11           YES
         LW,R1    Y8                NO-SET UNDEFINED ENTRY CODE
         STW,R1   2,R3                 AT 3RD WORD OF ENTRY
         B        SDKRD13
SDKRD11  LI,R5    SR2+1-3           SET AT R7
         BAL,SR4  WHATRES           GO GET RESOUTION IN R2
         B        SDKRD12           CONSTANT
         LW,R1    2,R3
         SLS,R1   -24
         AND,R1   M3                GET RESOLUTION OF IST ENTRY
         SW,R2    R1                GET SHIFT COUNT
         SLS,SR1  0,R2              SHIFT TO RESOLUTION OF ENTRY
         OR,SR1   2,R3
         STW,SR1  2,R3              PACK TOGETHER TYPE,RES,VALUE
         LW,R1    Y4
         STS,R1   0,R3              SET LOCATION SYMBOL CODE
         B        SDKRD13
SDKRD12  STW,SR1  2,R3              PUT CONSTANT VALUE IN ENTRY
         LW,R1    Y8
         STS,R1   0,R3              SET CONSTANT CODE
SDKRD13  LW,R1    EXPRSTK
         CI,SR3   0                 EXP STK POINTER AT TRUE SIZE
         BNE      SDKRD7            YES
         LI,R2    4                 NO-ADD SIZE OF ENTRY NOT IN STACK
         LB,R2    *EXPRSTK,R2
         AW,R1    R2
SDKRD7   CW,R1    R3                ROOM FOR NEW ENTRY IN IST
         BL       SDKRD8            YES
         LI,R1    -1
         STW,R1   SYMBOLTB          NO-SET NO IST GENERATION
         B        LDR1              GET NEXT LOAD ITEM
SDKRD8   MTW,-3   SYMBOLTB          POINT TO BASE OF NEW ENTRY
         B        LDR1              GET NEXT LOAD ITEM
         FIN
         PAGE
DPNAM    RES                        DECLARE PRIMARY REFERENCE:
DSNAM    RES                        DECLARE SECONDARY REFERENCE:
*                                   DECLARE DEF NAME: LOCATE THE NAME,
*                                     DECLARE IT AND MAP IT.
DDNAM    BAL,SR4  LOCRFDF
         PSW,R7   DECLSTK
         B        LDR1
         SPACE    10
*                                   ORIGIN: EVALUATE THE DEFINING
*                                     EXPRESSION.
ORG      BAL,SR4  EXPRIN
         CI,SR3   K0
*                                   IT MUST BE EVALUATABLE.
         BNE      ERFX
         LI,R5    SR3-3
         BAL,SR4  WHATRES
*                                   IT MUST HAVE RESOLUTION.
         B        ERFX
         SLS,SR1  0,R2
         STW,SR1  RLOC
*                                   DETERMINE WHICH SEGMENT AND
*                                   PROTECTION TYPE THE ORG VALUE IS IN.
         LW,R5    CSEG1
         BAL,SR4  WHICHPP
         B        CALCLOCC
         LI,R5    K0
         BAL,SR4  WHICHPP
         B        CALCLOCR
         B        ERFX
CALCLOCR LI,R6    RSEG00
         B        CALCLOC
CALCLOCC LI,R6    CSEG00
*                                   THE LOCATION COUNTER EQUALS ORG
*                                   VALUE - SEG BASE + BUFFER ADDRESS
*                                   IN BYTES.
CALCLOC  EQU      %
         STW,R5   XCSEG1            SAVE SEGMENT NO. FOR LOAD ITEMS
*                                   IN XMEM (IN CASE OF NON-ROOT DSECT).
         LW,R4    LOCCT
         AI,R4    TREEDIS
         AW,R5    *R4
         LI,R4    K3
         SW,R4    R2
         AI,R5    TREESIZE
         SLS,R2   1
         SW,R5    R2
         LW,R5    *R5
         AND,R5   M16
         DO       MODE=0
         SLS,R5   3
         ELSE
         SLS,R5   1
         STW,R5   BIAS              SAVE SEG BASE FOR XMEM
         SLS,R5   2
         FIN
         LCW,R5   R5
         AW,R5    *R6,R4
         AW,R5    SR1
         STW,R5   LOC
         DO       MODE=1
         LW,R5    *R6,R4
         SLS,R5   -2
         STW,R5   FBIAS             SAVE BUFFER ADDR FOR XMEM
         FIN
         B        LDR1
*                                   THIS ROUTINE CHECKS THE VALUE IN SR1
*                                   TO FIND OUT WHICH PROTECTION TYPE
*                                   OF A SEGMENT THE VALUE IS IN,
*                                   IF ANY. RETURN IS +1 IF NONE, +2
*                                   IF FOUND.
WHICHPP  LW,R4    LOCCT
         LW,R4    TREEDIS,R4
         AW,R4    R5
         AI,R4    00DIS
         LI,R2    K3
WHICHPP1 INT,R6   *R4
         LW,R6    *R4
         SLS,R6   -16
         SLD,R6   3
         AW,R6    R7
         AI,R6    -1
         CLR,R6   SR1
         BCR,9    WHICHPP2
         AI,R4    K2
         BDR,R2   WHICHPP1
         AI,SR4   K1
WHICHPP2 B        *SR4
         SPACE    10
*                                   DEFINE FIELD: FETCH THE LOCATION
*                                     AND WIDTH.
FIELD    BAL,SR4  GBYTE
         LW,R6    R5
         BAL,SR4  GBYTE
         LW,R7    LOCWD
         CI,R7    K100
         BANZ     RELFLD2N
*                                   IF THE LOCATION IS RIGHT ADJUSTED
*                                   THE REL DIGIT WILL BE 0, 1, 2 OR 3.
*                                   INITIALIZE IT TO ZERO NOW. IF IT
*                                   IS EVEN TO BIT 15 THE DIGIT WILL BE
*                                   8, 9 OR A. OTHERWISE E FOR ABSOLUTE.
         LW,R7    R6
         AND,R7   M4
         CI,R7    KF
         BNE      RE
         LW,R7    LOC
         CI,R7    K1
         BANZ     RE
         AND,R7   M2
         LW,R4    R6
         SLS,R4   -4
         SLS,R4   1
         AND,R4   M2
         EOR,R7   R4
         BEZ      RELFLD1
         CI,R5    K10
         BE       R9
         LI,R4    0
         B        RELFLD2
RELFLD1  CI,R5    K10
         BE       R8
RE       LI,R4    KE
         B        RELFLD2
R9       LI,R4    K9
         B        RELFLD2
R8       LI,R4    K8
RELFLD2  STW,R4   RDIG
RELFLD2N EQU      %
*                                   A DESTINATION WORD IS FOUND FOR
*                                   THE EXPRESSION ABOUT TO BE READ.
*                                   ITS FORM IS:
*                                       BITS 0-7 FIELD WIDTH
*                                       BITS 8-14 BIT WITHIN THE WORD.
*                                       BITS 15-31 LOCATION OF WORD.
         LW,R2    LOC
         LI,R3    K0
         SLD,R2   -2
         SLS,R3   -27
         AW,R3    R6
         AI,R3    KN256
KN256    EQU      -256
TESTFLD  BGEZ     FORMCW
         AI,R2    KN1
         AI,R3    K20
         B        TESTFLD
FORMCW   SLS,R3   17
         OR,R2    R3
         STB,R5   R2
         LW,R7    R2
         PSW,R2   *R0
*                                   THE EXPRESSION DEFINING THE FIELD
*                                   IS EVALUATED.
         BAL,SR4  EXPRIN
         PLW,R2   *R0
         CI,SR3   K0
         BNE      FIELDEX           EXPRESSION DID NOT YIELD A VALUE
         LW,R7    LOCWD
         CI,R7    K100
         BANZ     STOREFLDN
*                                   IF THE EXPRESSION DID NOT YIELD A
*                                   VALUE (IT WAS IN TERMS OF A PREF)
*                                   LEAVE THE CORE EXPRESSION IN THE
*                                   STACK AND EXIT.
*                                   THIS LOGIC CALCULATES THE CORRECT
*                                   RELOCATION DIGIT ACCORDING TO THE
*                                   RIGHTMOST BIT OF THE FIELD (PRE-
*                                   VIOUSLY CONSIDERED WITH THE RESULT
*                                   SAVED IN RDIG), THE RESOLUTION OF
*                                   THE EXPRESSION AND ANY DIGIT
*                                   ALREADY ASSOCIATED WITH THE WORD IN
*                                   QUESTION.
RELFLD3  EQU      %
         PSW,R2   *R0
         AND,R2   M17
         SLS,R2   2
         LW,R7    R2
         LW,R2    RDIG
         BEZ      %+2
         AI,R7    2
         BAL,SR4  FNDRELDG
         SLS,R6   2
         LI,R5    SR2-2
         LI,R2    K0
         BAL,SR4  WHATRES
         B        %+2
         B        ADJR
         CI,R2    K0
*                                   IF THE EXPRESSION HAS NO RESOLUTION
*                                   THE WORD IS ABS.
         BE       RELFLD4
*                                   IF THE RESOLUTION IS MIXED THE
*                                   MODULE IS NOT RELOCATABLE AND IS
*                                   FORCED TO BE ABSOLUTE.
SETABS   LI,R5    K100
         LCI      8
         PSM,SR1  *R0
         BAL,SR4  BLANKER
         LW,R4    LOCCT
         STS,R5   *R4
         STS,R5   LOCWD
         LCI      11
         LM,R5    ABSMESS
         STM,R5   PBUF
         LW,R5    1,R4              ADDR TO ROMT
         AW,R5    CROM1             R5 POINTS TO CURRENT ROM NAME
         LCI      2
         LM,R5    *R5
         STM,R5   PBUF+11
         LI,R5    K40
         STB,R5   PBUF+11
         LI,R5    PBUF
         CAL1,2   PRINT
         LCI      8
         PLM,SR1  *R0
         B        STOREFLD
ABSMESS  DATA     X'5340D3D6'
         TEXT     'AD MODULE FORCED ABS WHEN PROCESSING ROM'
RELFLD4  LI,R5    KE
         B        PUTDIGIT
*                                   THE EXPRESSION HAS RESOLUTION.
ADJR     LW,R5    RDIG
         CI,R5    KE
*                                   THE FIELD WAS NOT ON A WORD OR
*                                   HALF WORD BOUNDARY - THE WORD IS
*                                   ABS.
         BE       SETABS
         CI,R5    K0
         BNE      RELHALF
*                                   THE FIELD WAS ON A WORD BOUNDARY.
*                                   THE RELOCATION DIGIT IS THE
*                                   RESOLUTION.
         AW,R5    R2
         B        PUTDIGIT
RELHALF  EQU      %
*                                   THE FIELD WAS ON A HALF WORD
*                                   BOUNDARY WITH A WIDTH OF 16 BITS.
*                                   CHECK THE DIGIT ALREADY ASSOCIATED
*                                   WITH THE WORD IN CASE BOTH
*                                   HALVES NEED TO BE RELOCATED. ALSO
*                                   THE RESOLUTION MUST BE DOUBLE
*                                   WORD.
         DO       MODE=0
         LCI      2
         PSM,R6   *R0
         BAL,SR4  XMEM
         DATA     0                 SUPPLY ZERO AS RELDICT FLAG FOR XMEM
         LW,D1    *R6
         LCI      2
         PLM,R6   *R0
         ELSE
         LW,D1    *R7
         FIN
         SLS,D1   -28,R6
         AND,D1   M4
         CI,D1    K0
         BE       CHKDIGIT
         CI,D1    K8
         BL       SETABS
         BE       RD9
         CI,D1    K9
         BE       RD8
         B        CHKDIGIT
RD9      CI,R5    K9
         BE       RA
         B        CHKDIGIT
RD8      CI,R5    K8
         BNE      CHKDIGIT
RA       LI,R5    KA
CHKDIGIT EQU      %
         CI,R2    3                 WAS EXPR. DBLWORD RESOLUTION
         BL       NOTDBLWD          NO
         CI,R5    3                 IS IT A DBLWD. FIELD
         BGE      PUTDIGIT          YES, EVERYTING IS A-OK
         B        SETABS            ...SORRY ABOUT THAT.
NOTDBLWD CW,R2    R5                DOES RESOLUTION MATCH EXPRESSION
         BNE      SETABS            NO.
*                                   THE RELOCATION DIGIT IS STORED AWAY-
*                                   THROUGH EXTENDED MEMORY LOGIC IF
*                                   NECESSARY.
PUTDIGIT LW,R4    R5
         LI,R5    KF
         LCW,R6   R6
         SLD,R4   28,R6
         DO       MODE=0
PUTDIGX  BAL,SR4  XMEM
         DATA     0                 SUPPLY ZERO AS RELDICT FLAG FOR XMEM
         STS,R4   *R6
         ELSE
PUTDIGX  STS,R4   *R7
         FIN
STOREFLD LI,SR3   0                                                     730
         PLW,R2   *R0                                                   730
STOREFLDN EQU     %
*                                   THE DESTINATION WORD IS DECODED
*                                   AND THE FIELD ADDED TO THE
*                                   APPROPRIATE BITS OF THE APPROPRIATE
*                                   WORD(S).
         LCI      3
         PSM,D1   *R0
         LB,R1    R2
         LH,R4    R2
         SLS,R4   -1
         AND,R4   M5                ENDING BIT # MODULO 32
         AI,R4    1                 # OF BITS POSSIBLE IN 1ST FIELD WORD
         LI,SR2   0
         LCW,R7   R4                SHIFT CNT FROM BIT 31 TO...
         SLD,SR1  0,R7              ...ALIGN ITEM TO FIELD POSITION
FLDLOP1  EQU      %
         CW,R1    R4                WILL FIELD FIT IN THIS WORD
         BLE      FLDLOP2           YEP
         LW,D2    BITMASKS,R4       GET # OF BITS FOR THIS PART OF MASK
         SW,R1    R4                # OF BITS REMAINING IN FIELD
         LI,R4    32                # POSSIBLE IN NEXT GO-ROUND
         B        FLDLOP3
FLDLOP2  EQU      %
         LW,D2    BITMASKS,R1       GET CORRECT # OF BITS FOR FIELD
         LI,R1    0
FLDLOP3  EQU      %
         CI,R7    -32               SHOULD WE SHIFT AT ALL
         BE       STORFLD           NOPE
         SCS,D2   0,R7              ALIGN MASK FOR FIELD
STORFLD  LW,D4    D2
         LI,D3    K0
         LW,R7    R2
         BAL,SR4  XMEM
         AND,D4   0,R6
         AD,SR1   D3
         LW,D1    SR2
         STS,D1   0,R6
         AI,R2    KN1
         LW,SR2   SR1
         LI,SR1   K0
         AI,R1    0                 ARE WE DONE WITH THIS FIELD
         BLEZ     FLDRET2           INDEED WE ARE
         LCW,R7   R4                NOPE-GET NEXT SHIFT CNT AND...
         B        FLDLOP1           ...PICK UP NEXT PART OF FIELD
FLDRET2  EQU      %
         LCI      K3
         PLM,D1   *R0
         CI,SR3   0                                                     730
         BNE      *SR3                                                  730
         LW,R1    LOCWD
         CW,R1    RFLDMODS          CHECK FOR BREF OR REF LOADING MODE
         DO       MODE=1
         BANZ     FLDRET4
         MTW,0    MREFLAG
         BEZ      FIELDEX
         MTW,0    RFLDSG
         BLZ      FIELDEX
         B        %+3
FLDRET4  EQU      %
         FIN
*                                   IF REFERENCE LOADING WAS
*                                   SPECIFIED WE HAVE TO CALCULATE
*                                   THE PLIST AND PUT EACH WORD
*                                   THROUGH EXTENDED MEMORY LOGIC.
         MTW,0    RFLDSG            CAN REF'D WORD INDUCE AN OVERLAY
         BEZ      FIELDEX           BRANCH IF IT CAN'T
REFLOAD  EQU      %
         LW,R5    D3
         LW,SR3   RFLOADIS,R5       GET NEXT AVAIL SLOT IN REF LOAD TBL
         LW,SR2   RFLDSG
         LW,R7    LOC
         SLS,R7   -2
         AI,R7    -1                R7=LDR LOC OF WD WITH INTER-SEG REF
         BAL,SR4  XMEM              GET MEMORY PAGE CONTAINING THIS LOC
         CW,R1    BREFBIT           IS BREF LOADING MODE IN EFFECT
         BANZ     BREFMODE           YES - BRANCH TO BREF LDTBL LOGIC
         DO       MODE=1
         MTW,0    MREFLAG
         BNEZ     MREFMODE
         FIN
         AW,SR2   TREEPTR
         AI,SR2   1                                                     729
         AW,SR3   Y048                                                  729
         XW,SR3   *R6
         LW,SR4   RLOC
         SLS,SR4  -2                                                    729
         AW,SR4   Y68
         LI,R1    4                 SET R1 FOR A 4 WD ENTRY IN RFLDTBL
         LW,SR1   Y018
         B        BLDLDTBL           GO PUT ENTRY INTO REF LD TABLE
BREFMODE LB,R1    *R6               BREF LOADING MODE
         AND,R1   M7                GET OP CODE OF INSTR HAVING REF
         CI,R1    X'64'
         BL       NOBRANCH          AND VERIFY THAT IT IS A BRANCH
         CI,R1    X'6A'
         BG       NOBRANCH
         BE       CHKBAL            CHECK FOR BAL,0
         SLS,R1   -1
         CI,R1    X'33'
         BE       NOBRANCH
BRANCH   EQU      %
         LW,SR4   Y7FF
         LS,SR3   *R6               BUILD INSTR FOR WD HAVING REFERENCE
         XW,SR3   *R6               REPLACE REFERENCING WORD
         DH,SR2   Y000B
         SCS,SR2  -12               COMPOSE PARAMETER WD FOR REF LD TBL
         LS,SR3   SR2
         LW,SR2   SR3
         LW,R1    DOREFPTR          POINT R1 AT M:DO IN REF/DEF STACK
         LW,SR1   -4,R1             GET S:OVRLY LOC FROM VALUE WORD
         SLS,SR1  -2                CONVERT TO WORD ADDRESS
         OR,SR1   Y6A               COMPOSE 'BAL,R0   S:OVRLY'
         LI,R1    2                 SET R1 FOR 2 WORD ENTRY IN TABLE
         DO       MODE=1
         B        BLDLDTBL
MREFMODE EQU      %                 MREF LOADING MODE
         DH,SR2   Y000B
         SCS,SR2  -8                COMPOSE SEG#,0,0,ADDR
         INT,SR4  *R6
         AW,SR2   SR4
         LW,SR1   Y0F               COMPOSE XPSD T:OVBALPSD
         LB,R1    *R6                 OR XPSD T:OVBPSD INSTR
         AND,R1   M7
         CI,R1    X'6A'
         BNE      NONBAL
         LI,R1    1
         LB,SR4   *R6,R1            REG FROM THE BAL INSTR
         SCS,SR4  -16
         AW,SR2   SR4               SEG#,REG,0,ADDR
         LW,R4    TOVBALPSD
         B        %+2
NONBAL   LW,R4    TOVBPSD
         AW,R4    RFDFBAS
         LW,R7    1,R4              RESOLUTION
         LW,R4    *R4               VALUE
         LI,R1    K5
         CW,R7    MREFRES-1,R1      SHIFT VALUE WD OF
         BE       %+2               T:OVBALPSD OR T:OVBPSD
         BDR,R1   %-2               ACCORDING TO RESOLUTION
         EXU      MREFSLS-1,R1
         AW,SR1   R4
         LI,R1    2                 FOR 2 WD ENTRY IN MREF TABLE
*                                   CHECK FOR IDENTICAL MREF
*                                   TABLE ENTRY & USE IF FOUND.
         LW,R4    RFLOADIS,R5
         CW,R4    RFLDTBSZ          CK FOR MREF TABLE OVERFLOW
         BGE      REFOVFLW
         LW,R7    LOADBAS           START OF DATA
         XW,R7    BIAS
         PSW,R7   *R0               SAVE BIAS, FBIAS & XCSEG1
         LW,R7    RSEG00            & GIVE NEW VALUES FOR READING
         SLS,R7   -2                A WD OF THE MREF TABLE.
         XW,R7    FBIAS
         PSW,R7   *R0
         LI,R7    0
         XW,R7    XCSEG1
         PSW,R7   *R0
         LW,R7    MREFTAB
         AW,R7    RFDFBAS
         LW,R7    *R7               START OF MREF TABLE
         SW,R7    BIAS
         AW,R7    FBIAS
DONTDUP  AI,R7    K1
         PSW,R7   *R0
         BAL,SR4  XMEM              SEARCH FOR AN ENTRY WHOSE 2ND
         PLW,R7   *R0               WD LOOKS LIKE SR2.
         LW,R4    R7
         AI,R4    KN1
         SW,R4    FBIAS
         AW,R4    BIAS
         CW,R4    SR3               SR3=CURRENT POSITION IN TABLE
         BE       MREFSTOR
         LW,SR4   *R6
         CW,SR4   SR2
         BE       USEOLD
         AI,R4    K2
         CW,R4    RFLOADIS,R5
         BL       DONTDUP
         LW,R7    R4
         AI,R7    K1
         SW,R7    BIAS
         AW,R7    FBIAS
         PSW,R7   *R0
         BAL,SR4  XMEM
         PLW,R7   *R0
MREFSTOR STW,SR2  *R6               ADD NEW ENTRY TO MREF TABLE.
         AI,R7    KN1               WD 2: SEG#,REG OR 0,0,ADDR
         BAL,SR4  XMEM
         STW,SR1  *R6               WD 1: XPSD T:OVB....
         MTW,2    RFLOADIS,R5       UPDATE POINTER TO NEXT ENTRY
USEOLD   LW,R7    LOC
         SLS,R7   -2
         AI,R7    KN1
         LCI      3
         PLM,SR1  *R0
         STW,SR1  BIAS
         STW,SR2  FBIAS
         STW,SR3  XCSEG1
         BAL,SR4  XMEM
         LI,SR3   K0
         LW,SR4   MN16
         LS,SR3   *R6               REPLACE ORIGINAL REFERENCING WD
         AW,SR3   R4                REQUIRING MREF TABLE ENTRY W/
         STW,SR3  *R6               NEW WD REFERENCING MREF TABLE.
         B        FIELDEX
         FIN
BLDLDTBL LW,R4    RFLOADIS,R5
         CW,R4    RFLDTBSZ          CHECK FOR RF LOAD TABLE OVERFLOW
         BGE      REFOVFLW
         INT,R7   01DIS,R5          TABL ADDR REL. TO LOADER IN R4
         SLS,R7   1
         SW,R4    R7
         DO       MODE=1
         XW,R7    BIAS              USE  ROOT 01 BASE FOR XMEM
         PSW,R7   *R0               AND SAVE CURRENT SEG BASE
         FIN
         LW,R7    RSEG01
         SLS,R7   -2
         AW,R4    R7
         DO       MODE=1
         XW,R7    FBIAS             USE  RSEG01 BASE FOR XMEM
         PSW,R7   *R0               AND SAVE CURRENT BUFFER BASE
         FIN
         AWM,R1   RFLOADIS,R5       UPDATE ENTRY POS OF REF LOAD TABLE
         MTW,1    VAL%SW            BUMP COUNT OF OVERLAY-CAUSING REFS
         AI,R4    -1                DECR R4 FOR VECTOR ADDRESSING
         LI,R5    0
         XW,R5    XCSEG1            SAVE CURRENT SEG NO.  AND
         PSW,R5   *R0               SET FOR UPDATING THE ROOT
RFLDTAB  EQU      %
         LW,R7    R4
         AW,R7    R1
         LW,R5    R7,R1             R5 = NEXT WORD OF ENTRY
         BAL,SR4  XMEM
         STW,R5   *R6
         BDR,R1   RFLDTAB
         DO       MODE=1
         LCI      3
         PLM,R5   *R0               RESTORE PREVIOUS XMEM VARIABLES
         STW,R5   BIAS
         STW,R6   FBIAS
         STW,R7   XCSEG1
         ELSE
         PLW,R5   *R0
         STW,R5   XCSEG1
         FIN
*                                   THE FIELD ROUTINE EXIT.
FIELDEX  LB,R1    RCDSIZE           ARE WE IN BUF OR BUF2
         BEZ      LDR1              BUF
         PLW,R2   *R0               RESTORE CURBYTE
         STW,R2   CURBYTE
         MTB,-1   RCDSIZE           AND RCDSIZE
         PLW,SR4  *R0
         B        *SR4
         SPACE    2
CHKBAL   EQU      %                 TEST FOR A BAL,0 IN BREF MODE
         LH,R1    *R6
         SLS,R1   -4
         AND,R1   M4                GET REGISTER FIELD OF BAL
         BNEZ     BRANCH            ALL IS A-OK
*E*      ERROR:   0200-34
*E*      MESSAGE: BAL TO AN OVERLAY ON REGISTER ZERO DETECTED IN
*E*               BREF MODE.
*E*      DESCRIPTION: BAL ON REGISTER ZERO DETECTED IN BREF MODE
         QUIT     X'34'
Y6A      DATA     X'6A000000'
Y7FF     DATA     X'7FF00000'
         DO       MODE=1
MREFRES  DATA     X'01000000'
         DATA     X'00010000'
         DATA     X'00000100'
         DATA     X'00000001'
         DATA     X'00000000'
MREFSLS  SLS,R4   -2
         SLS,R4   -1
         SLS,R4   0
         SLS,R4   1
         SLS,R4   0
         FIN
NOBRANCH LI,R1    X'10000'         BUMP COUNT OF NON-BRANCHING REF'S
         B        %+2
REFOVFLW LI,R1    1                BUMP COUNT OF REF'S OVERFLOWING TABLE
         AWM,R1   BREFERR
         B        FIELDEX
         SPACE    10
*                                   DEFINE FORWARD REFERENCE AND HOLD:
*                                   THE 2 BYTE FREF # IS FETCHED
*                                   AND THE ENTRY IS LOCATED IN THE
*                                   REF/DEF STACK AND MARKED "HELD"
*                                   WITH A HIGH-ORDER F. THE DEFINING
*                                   EXPRESSION IS IGNORED.
DFREFH   BAL,SR4  2BNUM
         BAL,SR4  CHKFREF
         AI,R5    K3
         LI,R4    X'F0'
         STB,R4   *R5
         BAL,SR4  EXPRSKP
         B        LDR1
         SPACE    10
*                                   DEFINE FORWARD REFERENCE: SAME AS
*                                     ABOVE EXCEPT A HIGH ORDER FF
*                                     MARKS THE ENTRY "USED".
DFREF    BAL,SR4  2BNUM
         BAL,SR4  CHKFREF
         AI,R5    K3
         LI,R7    KFF
         STB,R7   *R5
         BAL,SR4  EXPRSKP
         B        LDR1
         SPACE    10
*                                   DEFINE DUMMY SECTION: THE DECLAR-
*                                     ATION # IS FETCHED AND THE
*                                     DSECT IS DECLARED. THE SIZE AND
*                                     PROTECTION ARE SKIPPED.
DDSECT   BAL,SR4  12BNUM
         LW,R7    *D2,R7
DCS3     PSW,R7   DECLSTK
         BAL,SR4  3BNUM
         B        LDR1
         SPACE    10
*                                   DEFINE DEF: THE DECLARATION # AND
*                                     EXPRESSION ARE IGNORED.
DDEF     BAL,SR4  12BNUM
         BAL,SR4  EXPRSKP
         B        LDR1
         SPACE    10
*                                   DECLARE CONTROL SECTION 0: THE SIZE
*                                     AND PROTECTION ARE IGNORED. THE
*                                     0TH ENTRY OF THE DECLARATION
*                                     STACK IS PICKED UP AND THE
*                                     CONTROL SECTION IS MAPPED.
DCS0     BAL,SR4  3BNUM
         B        LDR1
         SPACE    10
PSECT    RES
*                                   DECLARE CONTROL SECTION: THE NEXT
*                                     CONTROL SECTION IN THE REF/DEF
*                                     STACK IS LOCATED AND CHANGED
*                                     FROM TYPE 4 TO 6 SO IT WONT BE USE
*                                     AGAIN. THE CONTROL SECTION IS
*                                     DECLARED,MAPPED, AND THE SIZE AND
*                                     PROTECTION IGNORED.
DCS      LI,SR4   K0
DCS2     LW,R6    CSEG1
         BEZ      NORMALCS          ITS THE ROOT!!!
         AI,SR4   0                 LOOKING FOR DUMMY CSECT0
         BNEZ     NORMALCS          YES - ITS STILL IN CORRECT SEG
         LW,R7    LOCWD
         CI,R7    X'80'             ARE WE TO MOVE CSECT0 TO ROOT
         BAZ      NORMALCS          NO
         PSW,SR4  *R0
         BAL,SR4  GBYTE             GET PROT TYPE
         PLW,SR4  *R0
         MTW,-1   CURBYTE           BACK UP SCANNER
         CI,R5    X'C0'             IS IT 00
         BANZ     NORMALCS          NO
         LI,R6    4                 SIZE OF MOVED CSECT0 ENTRIES
         STW,R6   TEMPR1            KEEP FOR LATER
         LI,R6    0                 USE ROOT SEG TO FIND CSECT
         B        %+3
NORMALCS EQU      %
         LI,R5    3                 SIZE OF NORMAL CSECT0 ENTRIES
         STW,R5   TEMPR1
         PSW,R6   *R0               SAVE SEG #
         AI,R6    RFDFDIS
         INT,R5   *D3,R6
         SLS,R5   1
         STW,R5   R1
DCS1     LW,R6    0,R5
         LB,R7    R6
         AW,R5    R7
         CW,R7    TEMPR1            IS ENTRY THE CORRECT LENGTH
         BNE      DCS1              NO
         AND,R6   Y000F
         CW,R6    Y0004
         BE       %+3
         CW,R6    Y000C
         BNE      DCS1
         DO       MODE=1
         MTW,0    MREFLAG
         BEZ      DCS18
         LW,R6    RFDFBAS           IF CURRENT CSECT ENTRY
         AW,R6    MREFTAB            IS FOR THE MREF TABLE,
         AI,R6    KN1                FLAG IT TYPE=6 AND
         SW,R5    R7                 PROCEED TO NEXT ENTRY.
         CW,R6    R5                OTHERWISE, FLAG AND USE
         BNE      DCS19              CURRENT ENTRY.
         LW,R6    R7
         LW,R7    Y0006
         STS,R7   *R5
         SW,R5    R6
         B        DCS1
DCS18    EQU      %
         FIN
         SW,R5    R7
DCS19    EQU      %
         LW,R7    Y0006
         STS,R7   *R5
         LW,R7    R5
         SW,R7    R1
         PLW,R6   *R0               GET BACK SEG #
         STH,R6   R7
         AI,SR4   0
         BEZ      DCS3              DECLARE/SKIP3
         B        *SR4
         SPACE    10
*                                   DEFINE START: THE EXPR DEFINING
*                                     THE START ADDRESS IS EVALUATED AND
*                                     SAVED.
DSTART   BAL,SR4  EXPRIN
         LI,R5    SR2-2
         BAL,SR4  WHATRES
         B        ERBX
         SLS,SR1  -2,R2             SHIFT TO WORD RESOLUTION
         STW,SR1  START
         B        LDR1
         SPACE    10
*                                   MODULE END: THE SECURITY LEVEL IS
*                                     CHECKED. ALSO THIS MUST BE THE
*                                     LAST CARD OF THE MODULE.
MODEND   BAL,SR4  GBYTE
         CW,R5    SEVLEV
         BLE      %+2
         STW,R5   SEVLEV
         LW,R1    LASTCARD
         QUIT     ERC,BNEZ
*                                   LP1 EXITS.
         DO       SD=1
         MTW,0    SYMBOLTB          FORM IST
         BLZ      SDKRD10           NO
         LW,R6    SYMTOP
         SW,R6    SYMBOLTB          WRITE OUT IST
         BEZ      SDKRD10           NO
         SLS,R6   2                 BYTES IN IST
         LW,R7    LOCCT
         AI,R7    3
         LW,R7    *R7               ((LOCCT)+3)+(CROM1)=ADDRESS OF...
         AW,R7    CROM1                 TEXTC ROM NAME
         MTB,1    *R7
         LB,R1    *R7
         LI,R2    X'10'             IST CODE
         LB,SR4   *R7,R1            SAVE EOROMS BYTE
         STB,R2   *R7,R1            AT END OF IST KEY
         LW,R5    SYMBOLTB          IST BUFFER ADDRESS
         CAL1,1   WRITELM           GO-WRITE THE IST RECORD
         STB,SR4  *R7,R1            SAVE EOROMS BYTE
         MTB,-1   *R7               RESTORE THE ROM FILE NAME
         LW,R1    SYMBOLTB
         CW,R1    BSEG2
         BGE      %+2
         STW,R1   BSEG2             KEEP LARGEST IST SIZE
         LW,R1    SYMTOP
         STW,R1   SYMBOLTB          RESET IST
SDKRD10  EQU      %
         FIN
         PLW,SR4  *R0
         B        *SR4
         SPACE    10
         PAGE
*                                   REPEAT LOAD: THE REPEAT COUNT IS
*                                     FETCHED. THE NEXT BYTE IS
*                                     INTERUPTED AND THE APPROXIMATE
*                                     LOAD ITEM ROUTINE IS ENTERED.
RLOAD    BAL,SR4  2BNUM
         LW,SR2   R7
         QUIT     ERD,BNEZ
*E*      ERROR: 0200-0D
*E*      MESSAGE: REPEAT LOAD IS ZERO
*E*      DESCRIPTION: REPEAT COUNT OF ZERO ON REPEAT LOAD
*E*               (ASSEMBLER OR COMPILER ERROR).
*
         BAL,SR4  GBYTE
         B        %+2
LITEM    LI,SR2   1
         LW,R1    R5
         SLS,R1   -4
         LB,R1    LITV,R1
         BNEZ     LITV,R1
         B        ERAX
LITV     GEN,8,8,8,8 0,0,0,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
         PAGE
*                                   LOAD ABSOLUTE ITEM:
LABS     EQU      %-LITV
         CI,R5    X'44'             ABS, 4 BYTES
         BNE      LABS10            NOPE
         LW,R7    LOCWD
         CI,R7    K100              IS THIS 'ABS'
         BAZ      LABS10            NO-USE  OLD SLOW PATH
         LW,R7    LOC
         CI,R7    3                 ON A WORD BOUNDARY
         BANZ     LABS10            NOPE
         BAL,SR4  4BNUM             GET THE VALUE
         LW,D4    R7                SAVE IT
LABSQ    LW,R7    LOC
         SLS,R7   -2
         BAL,SR4  XMEM
         STW,D4   0,R6
         MTW,4    LOC               ADVANCE LOCATION COUNTERS
         MTW,4    RLOC
         BDR,SR2  LABSQ
         B        LDR1
LABS10   EQU      %
LABS1    LCI      K3
         PSM,D1   *R0
         AND,R5   M4
         BNEZ     LABS2
*                                   0 BYTES IMPLIES 16
         LI,R5    K10
LABS2    LW,R7    R5
         PSW,R7   *R0
         LI,R6    K0
*                                   THE BYTES ARE FETCHED AND PUT INTO
*                                   D1-D4 IN CASES OF A REPEAT LOAD.
LABS3    BAL,SR4  GBYTE
         STB,R5   D1,R6
         AI,R6    K1
         BDR,R7   GBYTE
LABS4    LW,R7    *TSTACK
         STB,R7   SR2
         LI,R5    K0
LABS5    RES
*                                   EACH BYTE IS STORED INTO THE BUFFER
*                                   THROUGH THE EXTENDED MEMORY LOGIC.
         LW,R7    LOC
         SLS,R7   -2
         BAL,SR4  XMEM
         SLS,R6   2
         LI,R7    3
         LS,R6    LOC
         LB,R2    D1,R5
         STB,R2   0,R6
         LW,R4    LOCWD
         CI,R4    K100
         BANZ     LABS6
*                                   UNLESS ABS WAS SPECIFIED THE
*                                   RELOCATION DIGIT (E FOR ABS) IS
*                                   PLACED IN THE BUFFER.
         PSW,R5   *R0
         LW,R7    LOC
         BAL,SR4  FNDRELDG
         LI,R5    KF
         LCW,R6   R6
         SLS,R6   2
         SLS,R5   28,R6
         DO       MODE=0
         PSW,R6   *R0
         BAL,SR4  XMEM
         DATA     0                 SUPPLY ZERO AS RELDICT FLAG FOR XMEM
         PLW,R7   *R0
         ELSE
         XW,R7    R6
         FIN
         AND,R5   *R6
         BNEZ     LABS6-1
         LI,R4    KE
         LI,R5    KF
         SLD,R4   28,R7
         STS,R4   *R6
         PLW,R5   *R0
LABS6    MTW,1    LOC
         MTW,1    RLOC
         AI,R5    K1
         MTB,-1   SR2
*                                   REPEAT FOR THE SPECIFIED # OF BYTES.
         BNEZ     LABS5
*                                   REPEAT FOR THE REPEAT LOAD COUNT.
         BDR,SR2  LABS4
         PLW,R7   *R0
         LCI      K3
         PLM,D1   *R0
         B        LDR1
         PAGE
*                                   LOAD LONG FORM RELOCATABLE: THE CODE
*                                     BITS ARE DECODED AND THE DECLAR-
*                                     ATION # PICKED UP. A FIELD TYPE
*                                     EXPRESSION IS CREATED IN BUF2. THE
*                                     4-BYTE LOAD ITEM IS STORED INTO
*                                     THE BUFFER AND THE FIELD LOGIC IS
*                                     CALLED TO ADD THE VALUE OF THE
*                                     DECLARATION.
LLREL    EQU      %-LITV
         LI,R4    K20
         LI,R6    3
         AND,R6   R5
         CI,R5    K4
         BAZ      %+2
         LI,R4    K24
         OR,R4    R6
         STW,R4   BUF2
         CI,R5    K8
         BANZ     LLREL4
         BAL,SR4  2BNUM
LLREL6   SLS,R7   16
         LW,R5    BUF2
         CI,R5    K4
         BANZ     LLREL9
         LW,R4    DECLSTK1
         AND,R4   M15
         CI,R4    K100
         BG       %+2
         SLS,R7   8
LLREL9   AI,R7    X'200'            EXPR END
         STW,R7   BUF2+1
         CI,R5    X'22'             IS THIS LIKELY A QUICK ONE
         BE       LQREL1            MEBBE
LLREL10  RES
         LI,R5    K13
         SW,R5    R6
         AI,R5    X'FF00'
         SLS,R5   8
         STS,R5   BUF2
         BAL,SR4  4BNUM
         LW,R4    R7
LLREL7   LW,R7    LOC
         CI,R7    K3
         QUIT     ERE,BAZ,R7
*E*      ERROR: 0200-0E
*E*      MESSAGE: IMPROPER BOUND
*E*      DESCRIPTION: A SHORT OR LONG RELOCATABLE ITEM WAS NOT ON
*E*               A WORD BOUNDARY.
*E*      REGISTERS: R7 HAS BYTE ADDRESS OF LOAD ITEM.
*
*
         SLS,R7   -2
         BAL,SR4  XMEM
         STW,R4   0,R6
         MTW,4    LOC
         MTW,4    RLOC
         PSW,SR2  *R0
         PSW,R4   *R0
         BAL,SR4  FIELDFB
         PLW,R4   *R0
         PLW,SR2  *R0
         BDR,SR2  LLREL7
         B        LDR1
LLREL4   BAL,SR4  GBYTE
LLREL8   LW,R7    R5
         B        LLREL6
         SPACE    10
LQREL1   EQU      %                 ACCELERATED LOAD RELOCATEABLE
         CI,SR2   1                 IS THIS A REPEAT LOAD
         BNE      LLREL10           YEP: USE NORMAL LOGIC
         LW,R4    LOCWD
         CI,R4    K100              IS ABS SPECIFIED
         BAZ      LLREL10           NOPE: AND WE DON'T BUILD REL. DICTS
         LW,R7    LOC
         SLS,R7   -2
         BAL,SR4  XMEM
         BAL,SR4  4BNUM
         STW,R7   0,R6              PUT AWAY ABS PART OF CORE EXPR.
         LW,R6    LOC
         MTW,4    LOC
         MTW,4    RLOC              BUMP LOCATION COUNTERS
         SLS,R6   -2
         LI,R7    X'113E'           CODE FOR 17 BITS, BIT POS. 31
         SLS,R7   16
         OR,R7    R6                BUILD CORE EXPRESSION POINTER
         LI,R2    BA(BUF2)+2
         XW,R2    CURBYTE
         MTB,1    RCDSIZE           SET FLAG
         LI,R1    LDR1              RETURN IF EXIT THRU FIELDFB1
         LCI      2
         PSM,R1   *R0
         PSW,R7   *R0
         BAL,SR4  EXPRIN            EVALUATE EXPRESSION
         PLW,R7   *R0
         CI,SR3   0                 DID EXPR. YIELD A VALUE
         BNE      LQRELXIT          NOPE
         BAL,SR4  XMEM
         LI,R4    X'1FFFF'
         AND,R4   0,R6              GET ADDR FIELD
         AW,R4    SR1               ADD ON VALUE OF DECLARATION
         LI,R5    X'1FFFF'
         STS,R4   0,R6              AND PUT IT BACK
         LW,R1    LOCWD
         CW,R1    RFLDMODS          IF THIS REF OR BREF
         BANZ     CHKOVL
         MTW,0    MREFLAG           IN MREF MODE
         BEZ      LQRELXIT          NOPE
         MTW,0    RFLDSG
         BGEZ     REFLOAD
         B        LQRELXIT
CHKOVL   EQU      %
         MTW,0    RFLDSG            CAN REF'D WORD CAUSE AN OVERLAY
         BNEZ     REFLOAD           YES
LQRELXIT EQU      %
         LCI      2
         PLM,R2   *R0
         STW,R3   CURBYTE
         MTB,-1   RCDSIZE
         B        LDR1
*                                   LOAD SHORT FORM RELOCATABLE: THE
*                                     DIFFERENCE BETWEEN THE SHORT AND
*                                     LONG FORM ARE ALLOWED FOR AND
*                                     THE LONG FORM LOGIC IS USED.
LSREL    EQU      %-LITV
         LI,R4    K22
         CI,R5    K40
         BAZ      %+2
         LI,R4    K26
         STW,R4   BUF2
         AND,R5   M6
         LI,R6    K2
         B        LLREL8
         PAGE
*                                   THIS ROUTINE SWITCHES PARAMETERS SO
*                                   GBYTE WILL FETCH BYTES FROM BUF2
*                                   RATHER THAN FROM THE NEXT BYTES IN
*                                   THE CARD IMAGE BUFFER.
FIELDFB  PSW,SR4  *R0
         MTB,1    RCDSIZE
         LI,R2    BA(BUF2)
         XW,R2    CURBYTE
         PSW,R2   *R0
         B        FIELD
         PAGE
*                                   THIS ROUTINE EVALUATES AN EXPRESSION
*                                   IN THE OBJECT LANGUAGE. IT INITIAL-
*                                   IZES A STACK ENTRY JUST ABOVE THE
*                                   EXPR. STACK WITH THE GIVEN
*                                   DESTINATION WORD (R7),A 0 RESOLUTION
*                                   AND A 03430000 1ST WORD (3 WORD
*                                   ENTRY, CORE EXPRESSION, 3 WORDS TO
*                                   THE 1ST VALUE ENTRY, NO CONTROL
*                                   BYTES).
EXPRIN   PSW,SR4  *R0
         LW,SR2   LOCWD             GET FLAG FOR NO BUILDING
         SCS,SR2  -5                IF NOT A LIBRARY
         OR,SR2   Y4
         LW,SR3   MREFLAG
         BEZ      %+2
         LW,SR3   Y8                SEE GETVAL
         STW,SR3  RFLDSG
         LI,SR1   K0                INITIALIZE VALUE
         LI,SR3   K0
         LW,D4    EXPRSTK
         AI,D4    K3
         STW,D4   EXPRES            SAVE MIDDLE POINTER
         STW,SR1  *EXPRES           CLEAR EXPRESSIONS RESOLUTION
         BDR,SR2  EXPRIN1
         AI,D4    KN1
         STW,R7   *D4
         LW,R6    Y0343
         AI,D4    KN1
         STW,R6   *D4
         LI,R6    K1
*                                   FETCH AN EXPRESSION CONTROL BYTE.
EXPRIN1  BAL,SR4  GBYTE
         CI,R5    K0
         BE       EXPRIN1
         BDR,SR2  WHATEC
PUTBYTE  AI,R6    K1
         CI,R6    3
         BANZ     PUTBYTE1
*                                   IF THERE IS NOT ENOUGH ROOM FOR
*                                   THE CONTROL BYTE MOVE THE WORDS
*                                   IN THE EXPRESSION UP.
         LW,R7    EXPRES
         LB,R1    *D4               SIZE OF EXPRESSION
         AW,R1    R7                LESS FIXED PART SIZE
         SW,R1    D4                IS HOW MUCH TO MOVE
         LW,R4    -1,R7             LESS ONE
         XW,R4    0,R7
         AI,R7    1
         BDR,R1   %-2
         STW,R4   0,R7
         MTW,1    EXPRES            ADJUST POINTER
         MTH,1    *D4               INC. DISP
         MTB,1    *D4               INC. # OF WDS IN EXPR
*                                   SAVE THE CONTROL BYTE.
PUTBYTE1 STB,R5   *D4,R6
*                                   CALL THE APPROPRIATE ROUTINE.
WHATEC   RES
         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: FETCH THE
*                                     DECLARATION # AND GET ITS VALUE.
ADDECL1  STW,R5   TEMPR1            SAVE EC BYTE FOR GETVAL
         BAL,SR4  12BNUM
         LW,R1    TEMPR1
         BAL,SR4  DECLCHK
         LW,R7    *D2,R7
         B        GETVAL
SBDECL1  EQU      ADDECL1
*                                   ADD FORWARD REFERENCE: FETCH THE
*                                     FORWARD REFERENCE #, LOCATE IT AND
*                                     GET ITS VALUE.
ADFREF1  STW,R5   TEMPR1            SAVE EC BYTE FOR GETVAL
         BAL,SR4  2BNUM
         LW,R1    TEMPR1
         PSW,R6   *R0
         BAL,SR4  CHKFREF
         PLW,R6   *R0
         B        GETVAL
SBFREF1  EQU      ADFREF1
*                                   ADD CONSTANT: FETCH THE CONSTANT AND
*                                     ADD IT TO THE EXP ACCUMULATOR
ADCON1   BAL,SR4  4BNUM
         AW,SR1   R7
*                                   THIS ROUTINE SAVES THE CONSTANT
*                                     OR DECLARATION IN THE EXPRESSION
*                                     ENTRY BEING BUILT.
PTWRD    RES
         BDR,SR2  EXPRIN1
         LB,R1    *D4
         MTB,1    *D4
         STW,R7   *D4,R1
         B        EXPRIN1
ADDABS   EQU      %
*                                   ADD ABS: ADD OR SUBTRACT A 1 TO THE
*                                     APPROPRIATE RESOLUTION BYTE OF THE
*                                     EXPRESSION.
         LI,R1    K3
         AND,R1   R5                RESOLUTION
         CI,R5    K8                ADD OR AUBTRACT
         BAZ      %+2
         MTB,-2   *EXPRES,R1
         MTB,1    *EXPRES,R1
         B        EXPRIN1
SUBABS   EQU      ADDABS
*                                   CHANGE RESOLUTION: DETERMINE THE
*                                     CURRENT RESOLUTION OF THE EXPR
*                                     AND SHIFT IT TO THE DESIRED
*                                     RESOLUTION.
CHGRES1  LI,R7    K3
         AND,R7   R5                NEW RES
         LW,R5    EXPRES            CURRENT RES ADDR
         AI,R5    -2
         BAL,SR4  WHATRES
         LW,R2    R7                NO SHIFT FOR ABS
         SW,R2    R7
         SLS,SR1  0,R2
         LI,R2    0                 SET NEW RESOLUTION
         STW,R2   *EXPRES
         MTB,1    *EXPRES,R7
         B        EXPRIN1
*                                   EXPRESSION END:
EXPREND1 RES
         CI,SR3   0
         BNE      EXPREND3
*                                   EXPRESSION HAS A VALUE, PICK UP
*                                   RESOLUTION TO RETURN TO CALLER.
         BDR,SR2  EXPREND15         IF LIBRARY, DONT PUT
         LW,R5    EXPRES            NONSTANDARD RELOCATION
         AI,R5    -2                IN THE RELOCATION DIXTIONARY
         BAL,SR4  WHATRES
         LW,R1    *EXPRES           CHECK IF MIXED OR REAL ABS
         AI,R1    0                 IF MIXED, SAVE EXPR
         BNEZ     EXPREND3
         AI,R4    -2                MUST BE POSITIVE RESOLUTION
         BGZ      EXPREND3
EXPREND15 LW,SR2  *EXPRES
         B        EXPREND2
*                                   EXPRESSION DOES NOT HAVE A VALUE-
*                                   PUSH IT INTO THE STACK.
EXPREND3 RES
         BDR,SR2  EXPREND2          DONT BOTHER
         LB,SR3   *D4
         MSP,SR3  EXPRSTK
         DO       MODE=0
         QUIT     ER1B,BCR10
*E*      ERROR: 0200-1B
*E*      MESSAGE: NO ROOM FOR NEW EXPRESSION
*E*      DESCRIPTION: THE EXPRESSION STACK HAS OVERFLOWED.
         ELSE
         BCR,10   MSPGOOD           B IF NO STACK OVERFLOW
         MTW,0    PLIB              HAS MESSAGE BEEN PRINTED
         BNEZ     MSPGOOD
         LI,R5    NOCORE
         CAL1,2   PRINT
         MTW,1    PLIB
MSPGOOD  EQU      %
         FIN
         LH,R6    *D4                                                   730
         CI,R6    X'40'                                                 730
         BAZ      EXPREND4
*                                   ADJUST THE LOC IN THE DESTINATION
*                                   WORD TO BE RELATIVE TO THE BASE OF
*                                   THE MODULE.
         AND,R6   M6                                                    730
         AI,R6    -2                                                    730
         LW,R5    *D4,R6                                                730
         LW,R4    CSEG00
         SLS,R4   -2                                                    730
         SW,R5    R4                                                    730
         LW,R4    D3
         LW,R4    00DIS,R4
         AND,R4   M16                                                   730
         SLS,R4   1                                                     730
         AW,R5    R4                                                    730
         STW,R5   *D4,R6                                                730
EXPREND4 SLS,SR3  16
         LW,R6    CSEG1
         AW,R6    D3
         AWM,SR3  EXPRDIS,R6
EXPREND2 PLW,SR4  *R0
         B        *SR4
*                                   THIS ROUTINE SKIPS OVER AN
*                                   EXPRESSION. IT ASSSUMES THE
*                                   EXPRESSION IS VALID
EXPRSKP  PSW,SR4  *R0
EXPRSKP1 BAL,SR4  GBYTE
         CI,R5    X'10'
         BANZ     GBYTE             SUBABS,CHGRES,ADDABS
         LI,SR4   EXPRSKP1          SET RETURN
         CI,R5    4
         BL       %+3               END, ADDCON
         BAZ      12BNUM            ADDECL,SBDECL
         B        2BNUM             ADFREF,SBFREF
         AI,R5    -1
         BGZ      EXPREND2          END
         BEZ      4BNUM             ADDABS
         B        EXPRSKP1          ZERO (PADDING)
D27F     DATA     X'27F'
         DO       MODE=1
NOCORE   TEXTC    ' CORE EXPRESSIONS SUPPRESSED.'
         FIN
         PAGE
*                                   THIS ROUTINE RUNS THRU THE REF/DEF
*                                   STACK LOOKING FOR A FORWARD REF
*                                   WITH THE NUMBER AGREEING WITH
*                                   R7. A DECLARATION STACK TYPE
*                                   POINTER IS RETURNED IN R7.
CHKFREF  EQU      %
         LW,R5    FIRSTF
         LI,R3    0
CHKFLOOP LW,R6    *R5
         AND,R6   MSKFTYPE
         CW,R6    Y0005
         BNE      CHKFREF2
         LW,R6    R5
         AI,R6    K3
         LB,R4    *R6
         CI,R4    X'FF'
         BE       CHKFREF2
         MTW,0    R3
         BNEZ     CHKFREF1
         STW,R5   FIRSTF
         LI,R3    -1
CHKFREF1 EQU      %
         LW,R6    *R6
         AND,R6   BITMASKS+28       (M28)
         CW,R7    R6
         BE       FREFIN
CHKFREF2 LB,R6    *R5
         AW,R5    R6
         CW,R5    LASTF
         BL       CHKFLOOP
FREFIN   LW,R6    CSEG1
         STW,R5   R7
         AI,R6    RFDFDIS
         LW,R6    *D3,R6
         AND,R6   M16
         SLS,R6   1
         SW,R7    R6
         LW,R6    CSEG1
         STH,R6   R7
         B        *SR4
         PAGE
*                                   THIS ROUTINE PICKS UP THE VALUE OF
*                                   THE REF/DEF ENTRY POINTED TO BY
*                                   R7, SHIFTS IT TO THE CORRECT RESOL-
*                                   UTION AND ADDS IT TO THE EXPR
*                                   ACCUMULATOR.
GETVAL   LCI      2
         PSM,R6   *R0
         LH,R5    R7
         LW,R6    LOCWD
         AND,R6   RFLDMODS
         DO       MODE=1
         CW,R6    MREFLAG
         BCR,7    NORFLD+1
         ELSE
         BEZ      NORFLD+1
         FIN
GETVALA  PSW,R5   *R0
*                                   IF REF-LOADING WAS SPECIFIED THE
*                                   SEGMENT IN WHICH THE DEF IS IN
*                                   IS SAVED IN RFLDSG IF IT IS THE
*                                   HIGHEST SO FAR.
         INT,R6   R7                                                    729
         AW,R6    D3                                                    729
         LW,R6    RFDFDIS,R6                                            729
         SLS,R6   1                                                     729
         AW,R6    R7                                                    729
         LB,R5    *R6                                                   729
         CI,R5    3
         BEZ      NORFLD                                                729
         LW,R5    *R6                                                   729
         CW,R5    Y0007
         BANZ     NORFLD
         AND,R5   M16                                                   729
         SLS,R5   -2
         DO       MODE=1
         MTW,0    MREFLAG
         BEZ      GETVALB
         CI,R5    K0
         BE       NORFLD
         CW,R5    CSEG1             FOR MREF LOADING, SET RFLDSG
         BE       NORFLD            AS FOLLOWS:
         LW,R4    LOCCT              =SEG# OF CALLED SEG IF DEF
         AI,R4    TREEDIS             IS NOT IN ROOT,
         LW,R7    R5                  NOT IN UMOV, AND
         AW,R7    *R4                 NOT IN SEG BEING FORMED
         LW,R4    *R7               (OTHERWISE, = -1)
         CW,R4    TXUMOV
         BNE      GETVAL6
         LW,R4    1,R7
         LW,R5    YFF
         CS,R4    TXUMOV+1
         BNE      GETVAL6
         B        NORFLD
         FIN
GETVALB  CW,R5    CSEG1
         BLE      NORFLD
         CW,R5    RFLDSG
         BLE      NORFLD
GETVAL6  STW,R5   RFLDSG
NORFLD   EQU      %
         PLW,R5   *R0                                                   729
         LW,R4    LOCCT
         AW,R5    TREEDIS,R4
         LW,R5    RFDFDIS,R5
         SLS,R5   1
         LI,R4    1
         AH,R5    *TSTACK,R4
         LW,R4    0,R5
         CW,R4    Y001
         BANZ     GETVAL1
*                                   THE REF/DEF HAS NOT BEEN DEFINED.
         STW,R4   SR3
         LCI      2
         PLM,R6   *R0
         B        PTWRD
*                                   GO PICK UP THE VALUE.
GETVAL1  RES
         LW,R7    1,R5
         PSW,R1   *R0
*                                   DETERMINE ITS RESOLUTION.
         BAL,SR4  WHATRES
         B        GETVAL4
         PLW,R1   *R0
*                                   SHIFT VALUE TO DESIRED RESOLUTION
*                                   AND CHANGE EXPR RESOLUTION
*                                   ACCORDINGLY.
GETVAL3  LW,R6    R1
         AND,R6   M2
         SW,R2    R6
         SLS,R7   0,R2
         LW,R6    -1,R5
         SLS,R2   3
         SLS,R6   0,R2
         CI,R1    K8                ADD OR SUBTRACT
         BAZ      %+2
         LCW,R6   R6
         AWM,R6   *EXPRES
GETVAL2  CI,R1    K8
         BAZ      %+2
         LCW,R7   R7
         AW,SR1   R7
         LCI      2
         PLM,R6   TSTACK
         B        PTWRD
*
GETVAL4  PLW,R1   TSTACK
         B        GETVAL2
TXUMOV   TEXTC    'UMOV'
         PAGE
WHATRES  AI,R5    K3
*                                   THIS ROUTINE DETERMINES THE
*                                   RESOLUTION OF A REF/DEF. RETURN
*                                   IS +1 IF NONE OR MIXED,+2 WITH
*                                   0,1,2 OR 3 IF IT HAS RESOLUTION.
         LI,R2    KN4
         LW,R1    -1,R5
         LB,R4    R1
         SLS,R1   8
         BNEZ     %+2
         BIR,R2   %-3
         AI,R1    0
         BNEZ     WHATRES5          ABS
         AI,R4    1
         CI,R4    X'FD'             MUST BE 1 OR FF
         BANZ     WHATRES5
         AI,R2    K4
         AI,SR4   K1
WHATRES5 B        *SR4
         PAGE
*                                   THIS ROUTINE READS A NAME FROM
*                                   THE OBJECT STREAM, LOCATES THE REF/
*                                   DEF ENTRY AND RETURNS A DECLARATION
*                                   STACK TYPE POINTER IN R7.
LOCRFDF  PSW,SR4  *R0
*                                   READ THE NAME IN ABOVE EXPR STACK.
         BAL,SR4  GBYTE
         LW,D4    EXPRSTK
         AI,D4    K1
         LW,R6    R5
         SLS,R5   -2                BLANK PAD FOR SEARCH
         LW,R7    TXBLNK
         STW,R7   *D4,R5
         STB,R6   *D4               SET BYTE COUNT
         LI,R7    K1
LOCRFDF1 BAL,SR4  GBYTE
         STB,R5   *D4,R7
         AI,R7    K1
         BDR,R6   GBYTE
*                                   INITIALIZE THE SEARCH BOUNDARIES.
         LW,R2    CSEG1
LOCRFDF4 STW,R2   CSEG2
         CW,R2    FASTSRCH          DO WE HAVE ROOT AND SORT TABLE
         BCS,7    LOCRFDF5          NO..ALAS
         BAL,SR4  BINSRT
         LW,R5    R7                ADJUST REGISTERS
         BCS,8    LOCRFDF6          FOUND IT..FORTUNATELY
         B        LOCRFDF7          SCREWED UP SOMEWHERE
LOCRFDF5 RES
         AI,R2    RFDFDIS
         LW,R5    *D3,R2
         LH,R4    R5
         AND,R5   M16
         SLS,R5   1
         AW,R4    R5
         STW,R4   TEMPR1
         LM,R3    *D4               CHECK TWO WORDS FAST
LOCLOOP  EQU      %
         CW,R3    3,R5
         BNE      LOCRFDF3
         LB,R6    *R5
         AI,R6    -4
         BGZ      %+3
         BEZ      LOCRFDF6          ONE WORD TEXTC
         B        LOCRFDF3          TOO FEW
         CW,R4    4,R5              IS WORD TWO RIGHT
         BNE      LOCRFDF3           NO
         LW,R7    R5
         AI,R7    K3
LOCRFDF2 LW,R2    *D4,R6
         CW,R2    *R7,R6
         BNE      LOCRFDF3
         BDR,R6   LOCRFDF2
LOCRFDF6 RES
*                                 FOUND IT, RETURN POINTER.
         LW,R7    R5
         LW,R6    CSEG2
         AI,R6    RFDFDIS
         LW,R6    *D3,R6
         SLS,R6   1
         SW,R7    R6
         LW,R2    CSEG2
         STH,R2   R7
         PLW,SR4  *R0
         B        *SR4
*                                   LOOP UNTIL FOUND.
LOCRFDF3 LB,R6    *R5
         AW,R5    R6
         CW,R5    TEMPR1
         BL       LOCLOOP
LOCRFDF7 RES
         LW,R2    CSEG2
*
*E*      ERROR: 0200-2C
*E*      MESSAGE: CANNOT FIND REF/DEF NAME IN STACK
*E*      DESCRIPTION: THE LOADER ENCOUNTERED A NEW REF/DEF NAME
*E*               DURING ITS SECOND PASS.
*E*      REGISTERS: R3 HAS BYTE COUNT AND 1ST THREE CHARACTERS OF NAME
         QUIT     X'2C',BNEZ,R3     CANNOT FIND REF/DEF NAME IN STACK
*                                 GET BACK LINK
         AI,R2    ROM1DIS
         LW,R2    *D3,R2
         AND,R2   M16
         B        LOCRFDF4
         PAGE
*                                   THIS ROUTINE ACCEPTS A POINTER TO
*                                   A BUFFER LOC IN R7 AND RETURNS
*                                   POINTERS TO THE CORRESPONDING
*                                   RELOCATION DIGIT, WORD IN R7, DIGIT
*                                   IN R6.
FNDRELDG LW,R4    LOCWD
         CI,R4    K100
         BANZ     *SR4
         PSW,SR4  *R0
         LI,R4    RSEG00-1
         BAL,SR4  WHATPP
         LI,R4    CSEG00-1
         BAL,SR4  WHATPP
         B        ERFX
WHATPP   EQU      %
         LI,R1    K3
WHATPP1  CW,R7    *R4,R1
         BGE      CALCREL
         BDR,R1   WHATPP1
         B        *SR4
CALCREL  LI,R6    K0
         SW,R7    *R4,R1
         SLS,R7   -2
         SCD,R6   -3
         SCS,R6   3
         AI,R4    76-73             CREL00-CSEG00
         LW,R4    *R4,R1
         SLS,R4   -2
         AW,R7    R4
         PLW,SR4  *R0
         B        *SR4
         PAGE
*                                   THIS ROUTINE HAS AN INPUT IN R6 A
*                                   VIRTUAL BUFFER ADDRESS. RETURNS IN
*                                   R7 A PHYSICAL ADDRESS AFTER INSURING
*                                   THAT THE CORRECT PAGE IS IN MEMORY.
*                                   IT IS USED BOTH FOR LOAD ITEMS AND
*                                   RELOCATION DIGITS. XMEM KEYS ARE OF
*                                   THE FORM 03,00, SEG#, VIRTUAL PAGE#.
         DEF      XMRDERR
XMEM     EQU      %
         LW,R6    R7
         LW,R3    LOCWD
         CI,R3    K4000
         BAZ      XMEM5             NO,OUT.
         LCI      2
         PSM,R4   *R0
         AND,R7   M17
         DO       MODE=1
         SW,R7    FBIAS
         AW,R7    BIAS
         STW,R7   R6
         FIN
         SLS,R7   -9
         LW,R5    XCSEG1            SEGMENT NO.(SAVED AT ORG).
         DO       MODE=1
         DH,R5    Y000B             (CONVERT FROM SEG'S DISP IN
*                                     TREE TO ACTUAL SEG NO.)
         AI,R5    X'300'
         STH,R5   R7
         ELSE
         SLS,R5   8
         AW,R5    Y03
         OR,R7    R5
         FIN
         LW,R4    TOPOMEM
         DO       MODE=0
         MTW,K0   *SR4              IS ENTRY FOR PAGE OF RELOC DICT
         BNEZ     XMEM1              NO
XMEM1R   AI,R4    KN400+K2          SET R4 TO BUFFER OF RELDICT
         CW,R7    XMRKEY            IS PAGE OF REQUESTED WORD IN CORE
         BE       XMEM3X             YES
         ANLZ,R5  %-2
         B        XMEMIO
         FIN
XMEM1    AI,R4    KN200+K2          WORD REQUESTED FOR LOAD MODULE
         CW,R7    XMKEY             IS PAGE CONTAINING THIS WORD IN CORE
         BE       XMEM3X
         LI,R5    XMKEY
XMEMIO   LCI      3
         PSM,SR1  *R0
         CAL1,1   XMWRT             WRITE OUT CURRENT BUFFER
         STW,R7   XMKEY             UPDATE KEY
         CAL1,1   XMRD
XMEM3    LCI      3
         PLM,SR1  *R0
XMEM3X   LI,R5    K1FE00
         STS,R4   R6
XMEM4    LCI      2
         PLM,R4   *R0
XMEM5    EQU      %
         DO       MODE=0
         MTW,K0   *SR4              WAS XMEM ENTERED FOR RELOC DICT
         BNEZ     *SR4               NO
         AI,SR4   1                  YES, ADJUST LINKAGE
         FIN
         B        *SR4
XMRDERR  LI,R5    K1FF        RETURN IS MADE TO HERE IF A READ ERROR
         LI,SR2   0           OCCURS. THIS LOGIC ASSUMES THAT THE ERROR
         STW,SR2  *R4,R5      WAS CAUSED BY SPECIFYING A KEY THAT DOES
         BDR,R5   %-1         NOT EXIST.
         STW,SR2  *R4         INITIALIZE BUFFER TO ZERO
         B        XMEM3
         DO       MODE=1
XMWRT    GEN,8,24 X'11',M:LM
         ELSE
XMWRT    GEN,8,24 X'11',M:DIC
         FIN
         DATA     X'38000050'
         DATA     X'80000004',X'800',X'80000005'
         DO       MODE=1
XMRD     GEN,8,24 X'10',M:LM
         ELSE
XMRD     GEN,8,24 X'10',M:DIC
         FIN
         DATA     X'38000010'
         DATA     X'80000004',X'800',X'80000005'
Y030402  DATA     X'03040200'
         END

