*M*      S:OVRLYR M:SEGLD LIBRARY ROUTINE
*P*
*P*      NAME:    S:OVRLYR
*P*
*P*      PURPOSE: TO LOAD OVERLAYS FOR PROGRAMS LOADED WITH THE
*P*               BREF OPTION.
*P*
*P*      DESCRIPTION:  S:OVRLYR IS A SUBROUTINE THAT IS INCLUDED WITH
*P*               ALL STANDARD RELEASED LIBRARIES.
*P*
*P*               THIS MODULE IS INCLUDED WITH ALL PROGRAMS LOADED WITH
*P*               THE BREF OPTION OF THE LOADER.  ALL BRANCHING
*P*               INSTRUCTIONS WITHIN THE PROGRAM THAT REFERENCE AN
*P*               EXTERNAL DEFINITION IN ANOTHER SEGMENT ARE REPLACED
*P*               WITH A BAL TO S:OVRLY.  S:OVRLYR INSURES THAT THE
*P*               SEGMENT IS IN CORE AND BRANCHES TO THE REFERENCED
*P*               INSTRUCTION.
*P*
         PAGE
         SYSTEM SIG7
*
FMT      COM,1,7,4,3,17 AFA(1),CF(2),CF(3),AF(2),AF(1)
*
*
*        MODULE DEFS
*
         DEF      S:OVRLY           MODULE ENTRY POINT
*
*        MODULE REFS
*
TCBADR   EQU      X'27'             TCB ADDRESS
JITREE   EQU      X'28'             TREE ADDRESS
*
TREE     EQU      11                LOC OF TREE POINTER WITHIN THE TCB
OUTINFLG EQU      3                 BIAS INTO TREE FOR OUT-IN CORE FLAG
*
R0       EQU      0
R1       EQU      1
         PAGE
*F*
*F*      NAME:    S:OVRLY
*F*
*F*      PURPOSE: TO LOAD AN OVERLAY FOR A PROGRAM LOADED WITH
*F*               THE 'BREF' OPTION.
*F*
*F*      DESCRIPTION: IF THE OVERLAY IS NOT CURRENTLY IN CORE, AN
*F*               M:SEGLD CAL IS ISSUED.  S:OVRLY THEN BRANCHES TO
*F*               THE REFERENCED INSTRUCTION.
*F*
*D*      NAME:    S:OVRLY
*D*
*D*      CALL:    BAL,0  S:OVRLYR
*D*               SEG#/BRANCH ADDRESS
*D*
*D*      INPUT:   *R0 = SEG#/BRANCH ADDRESS
*D*
*D*      OUTPUT:  R0 = TCB ADDRESS
*D*
*D*      DESCRIPTION:  A BRANCH INSTRUCTION TO THE REFERENCED ROUTINE
*D*               IS BUILT FROM THE INPUT PARAMETER.
*D*
S:OVRLY  EQU %
         STCF     TEMP              SACE
         STW,R1   TEMP+1
         LW,R0    *R0               GET PARAMETER WORD FROM RFLD TABLE
         LW,R1    MASK
         STS,R0   EXIT              BUILD INSTRUCTION FOR EXIT
         AND,R1   EXIT
*D*
*D*               THE SEGMENT NUMBER IS USED AS AN INDEX INTO THE
*D*               TREE TABLE TO ACCESS THE ADDRESS OF THE TEXTC
*D*               SEGMENT NAME.
*D*
         EOR,R1    R0               GET TREE INDEX FROM PARAMETER
         MI,R0    11**12            MAKE IT A DISPLACEMENT INTO TREE
         AI,R0    1
         AW,0     X'8C00'+JITREE
         LW,1     X'8C00'+TCBADR
         XW,R0    R1                R0=TCBPTR R1=SPECIFIC TREE SEG
*D*
*D*               THE SEGMENT IS ALREADY IN CORE IF BIT 0 OF WORD 3
*D*               IN THE TREE TABLE ENTRY FOR THIS SEGMENT IS SET.
*D*
         MTW,0    OUTINFLG,R1
         BLZ      %+2               IGNORE SEGLD IN IN-CORE FLAG IS SET
*D*
*D*               IF THE SEGMENT IS NOT IN CORE AN M:SEGLD CAL IS ISSUED.
*D*
         CAL1,8   SEGLD
         LW,R1    TEMP+1            RESTORE
         LC       TEMP
*D*
*D*               CONTROL THEN RETURNS TO THE USER PROGRAM AT THE
*D*               REFERENCED ROUTINE.
*D*
EXIT     FMT,X'68' 0                SKELETON BRANCH FOR EXIT TO USER
*
MASK     FMT   *X'1FFFF',7      FOR STORING ALL BUT OP CODE AND REG
*
SEGLD    FMT,1    0                 FPT FOR SEGLD CAL
         FMT      *R1
TEMP     RES      2                 TEMPORARU STOREGE
         END

