TITLE OVRLAY - OVERLAY HANDLER FOR LINK
SUBTTL D.M.NIXON/DMN/JLd/JNG/MCHC/DZN/PY/PAH/HD/JBS/TARL 28-May-86
DEFINE CPYRGT <
ASCIZ /
;COPYRIGHT (c) DIGITAL EQUIPMENT CORPORATION 1973,1986. ALL RIGHTS RESERVED.
/ > ;[214]
;COPYRIGHT (c) DIGITAL EQUIPMENT CORPORATION 1973,1986. ALL RIGHTS RESERVED.
;[214]
;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED
;ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE
;INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY OTHER
;COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
;OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY
;TRANSFERRED.
;THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE
;AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT
;CORPORATION.
;DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS
;SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.
CUSTVR==0 ;CUSTOMER VERSION
DECVER==5 ;DEC VERSION
DECMVR==1 ;DEC MINOR VERSION
DECEVR==214 ;DEC EDIT VERSION
ENTRY .OVRLA,.OVRLU
INTERN %OVRLA
%OVRLA==<BYTE(3)CUSTVR(9)DECVER(6)DECMVR(18)DECEVR>
COMMENT \
THIS ROUTINE PRESERVES ALL ACCS EXCEPT 0 AND 1 WHICH IT DESTROYS FREELY.
\
SEARCH OVRPAR ;OVERLAY FILE DEFINITIONS
SALL

SUBTTL REVISION HISTORY
;START OF VERSION 1
;1 INITIAL VERSION
;2 ADD FUNCTION CALLS TO RNT, IFS & CBC
;3 FIX VARIOUS BUGS IN MANUAL CALLS
;4 MAKE IT REENTRANT (TWO SEGMENT VERSION)
;5 REDUCE SIZE OF OVERHEAD TABLES
;6 SUPPORT DDT SYMBOLS
;START OF VERSION 1A
;7 JLd 17-Jan-75 SPR 10-14994
; Fix explicit calls to initialize the overlay list
; when necessary.
;10 CHANGE GETCUR TO USER PC OF PUSHJ RATHER THAN ADDRESS OF ARGBLOCK
; THIS IS FOR COBOL WHICH CONSTRUCTS ARG BLOCK IN LIBOL
;11 JLd 26-Mar-75 SPR 10-15706
; Make relocatable overlays work with all multiple calls:
; Unrelocate EXTTAB when the overlay is removed.
;12 JLd 27-Mar-75 SPR 10-15706
; Cause the symbol table to be kept even if core must
; be expanded.
;13 JNG 26-Jun-75 SPR 10-16380
; Move symbol table before getting core for an absolute link
; to avoid problems when trying to move up the symbols.
;14 JNG 27-Jun-75
; Fix bug introduced by edit 10. Clean up some code.
;15 JNG 29-Jun-75
; Edit 11 inserted an instruction into the range of a
; JUMPN T2,.-3 ... oops!!!
;16 JNG 2-Jul-75 SPR 10-15993
; Try harder to shrink when we have more core than we need.
;17 JNG 5-Aug-75 SPR 10-15734
; Reset ADDCOR and SIZCOR after calling MOVSYM,
; which destroys them.
;START OF VERSION 1B
;20 JNG 8-Oct-75
; If a manual call comes from the high segment, pretend it is
; from the ROOT so COBDDT will work properly.
;START OF VERSION 2 (TOPS-20 ONLY)
;21 DMN 13-Nov-75
; Make overlays work on TENEX

;START OF VERSION 2C -- FROM NOW ON, MAJOR & MINOR VERSIONS SAME AS LINK
;22 JNG 10-Feb-76
; Make OVRLAY's version correspond to LINK. Clean
; up the listing. Fix a minor bug in edit 21.
;23 JNG 10-Feb-76 SPR 18030
; Make sure we have CORE before reading in a relocatable overlay
; into other than its intended address and symbols are in core.
;24 JNG 10-Feb-76 SPR 18030
; Try harder to keep symbols in core when debugging, even if
; this means expanding core.
;25 JNG 22-Feb-76 SPR 18572
; Fix some minor bugs in non-TTY log file handling, and in the
; INIOVL manual call subroutine.
; Edits 26 and 27 were not used
;START OF VERSION 3A
;30 JNG 20-Jun-76
; Release on both TOPS-10 and TOPS-20 as OVRLAY version 3A(30)
;START OF VERSION 4
;31 JNG 27-Feb-77 SPR 10-21893
; Allow a call to INIOVL with no args to just read in the
; symbol table & do other initialization that is not normally
; done until the first overlay is read in.
;32 JNG 10-Apr-77
; Keep the symbol table up to date always if symbols are
; available due to load-time switches. Never look at the
; initial .JBSYM or .JBDDT to decide what to do.
;33 JNG 10-Apr-77 SPR 10-22407
; Make OVRLAY assemble with FTLOG=0.
;34 JNG 10-Apr-77 SPR 10-22436
; Make OVRLAY work with FTRELOC=0.
;35 JNG 10-Apr-77
; Set up reference lists correctly when link comes into core.
;36 JNG 10-Apr-77
; Save the PPN around the LOOKUP in OVRLAY.
;37 MCHC 20-SEP-77
; Don't output version change message if the change is from zero.

;START OF VERSION 4A
;40 DZN 15-Sep-78
; On TOPS-20, if DDT exists, set its internal symbol table pointer
; whenever we change .JBSYM.
;41 DZN 5-Oct-78
; Use new NAME% form of JSYS names to avoid conflicts with user-defined
; globals.
;42 DZN 5-Oct-78
; Change FTENEX conditional to TOPS20 to be consistent with the rest
; of LINK. Use proper mnemonics for JSYS arguments. Some code cleanup.
;43 DZN 13-Oct-78
; Fix link deletion problems. Make REMOV. take only a single argument,
; and delete that link and all of its inferiors (otherwise lost links
; result). Allow RUNOV. to delete the calling link as documented. Also
; remove OVLAOC message (use OVLARC instead).
;44 DZN 15-Oct-78
; Fix argument checking for calls to manual subroutines. This involves
; allowing all double and single precision argument types to work,
; making the OVLIAT message fatal and not type junk, and getting
; the correct user PC (see edit 10).
;45 DZN 15-Oct-78
; Fix PDL overflow if many calls to RUNOV. RUNOV. now unbinds back
; through the return PC on the stack, allowing replacement of links
; at the same level to succeed without the PDL overflow.
;46 JNG 15-Jun-79
; Use 7.01 GETTABs if available to find overlay file.
;47 DZN 25-Jul-79
; Clean up the listing for release.
;50 DZN 27-Aug-79
; Release on both TOPS-10 and TOPS-20 as version 4A(50).

;START OF VERSION 4B
;51 DZN 12-Nov-79 SPR 20-13384
; Fix forward reference to local label TIME, which subsequently drags
; in and defines the TIME JSYS.
;52-54 Superceded in Edit 5(100).
;55 PY 5-Jan-81
; Fix off-by-one bug when relocating overlays which have pointers to
; other nodes which are not relocated.
;56-100 Reserved for maintenance.
;START OF VERSION 5
;100 DZN 8-Feb-80
; Implement writable overlays for use by Fortran's SAVE statement.
; . On initialization, detect a potentially writable overlaid program and
; open nnnOVL.TMP.
; . Move overlay file definitions to OVRPAR.MAC for use by OVRLAY and
; LINK.
; Bugs fixes as a consequence of this edit:
; . File names, extensions, or SFD names longer than 6 characters in calls
; to INIOVL or LOGOVL could result in a badly parsed file specification
; or worse.
; . Closing the log file with CALL LOGOVL() never freed the buffer space
; because ROT was used as the FUNCT. function code rather than F.ROT.
; . [0,0] is not suppressed when a file specification is printed.
; . On TOPS-20, a CORE UUO is done even if UUO simulation is completely
; turned off.
;101 PAH 2-Feb-81
;
; Save and restore T0 over the I/O call just before RP1.
;
;102 PAH 2-Jun-82
;
; Set GJ%SHT in GTJFN call at TMPINI under TOPS-20 and
; put the source/destination designator in the right AC.
;103 PAH 3-Jun-82
;
; Correct typo in %OUTZ, change SIN% to SOUT%.
;
;104 HD 15-Jun-82
; Handle byte string descriptors that may be passed by
; FORTRAN 77 programs as file or link names on TOPS-20.
;
;105 HD 15-Jun-82
; Be sure to set writable bit when opening .LOG file.
;
;106 HD 22-Jun-82
; Futher work on edit 104.
;107 HD 2-JUL-82
; Make POSCKH save the ACs it uses. Some routines that call it exspect
; the ACs to be preserved
;200 HD 10-DEC-82
; Make calls to overlay handler work when passed double precision
; variables
;201 HD 16-DEC-82
; Set the number of buffers for .FILOP in LOGINI to the default number
; by changing .FONBF in the arg list at LFOWRT to -1.
;202 PAH 6-Jan-83
; Update copyright notices, clean up listing for release.
;203 PAH 11-Jan-83
; Embed ASCII copyright notice.
;204 PAH 20-Jan-83
; Shorten embedded copyright notice.
;205 HD 1-Feb-83
; Fix edit 201. It should ask for default number of output buffers only
; by putting -1,,0 in .FONBF at LFOWRT.
;206 JBS 25-Jul-83
; Make dummy edit for TOPS-10 OVRLAY - two lines were swapped in
; the released version at RLO7.
;207 TARL 28-Aug-83
; Fix problem with running virtual with overlays. OVRLAY could
; request a transfer that wouldn't fit in physical memory, and
; PFH can't split up FILOP. IOWDs. Make OVRLAY check for amount
; of memory allowed to use, and split up its request to fit
; in this size. This should also prove to be a slight performance
; win. TOPS-10 only.
;210 JBS 24-Oct-83
; Set FO.PRV in all FILOP. blocks so privileged users (JACCT and [1,2])
; can run overlaid programs when pathed into another PPN. TOPS-10 only.
;211 HD 21-Nov-83
; Check error return status for FUNCT. call at OVINI2 and make sure it
; doesn't loop if there is not enough memory available.
;212 PY 6-Sep-84
; Open the log file as 7 bit on TOPS-20.
;213 HD 17-Mar-85 SPR 10-35120
; Put data for LOGOVL at lable LFOWRT in the low segment.
;214 HD 28-May-86
; New coporate copywrite statement.

SUBTTL DEFINITIONS -- OPDEFs
;THE FOLLOWING OPDEFS CONTROL THE SELECTION OF THE TEMPORARY FILE WHEN WRITABLE
;OVERLAYS ARE USED. THE INPUT ROUTINES WILL READ FROM EITHER THE OVERLAY OR
;TEMPORARY FILE BASED ON THE SIGN OF THE UBLOCK FLAG. THESE OPDEFS SIMPLIFY THE
;SETTING AND TESTING OF THAT FLAG.
OPDEF SETTMP [HRROS UBLOCK] ;[100] USE TEMPORARY FILE IN I/O ROUTINES
OPDEF CLRTMP [HRRZS UBLOCK] ;[100] GO BACK TO OVERLAY FILE IN I/O ROUTINES
OPDEF SKIPT [SKIPL UBLOCK] ;[100] SKIP IF I/O FROM TEMPORARY FILE
OPDEF SKIPNT [SKIPGE UBLOCK] ;[100] SKIP IF I/O NOT FROM TEMPORARY FILE
OPDEF PJRST [JUMPA 17,] ;[100] SHOW PJRST'S CORRECTLY IN DDT

SUBTTL PRINCIPLE ENTRY POINT
;CALLS TO ROUTINES IN INFERIOR LINKS ARE CHANGED BY LINK TO:
;
; PUSHJ P,<EXTTAB BLOCK> ;NEED NOT ACTUALLY BE PUSHJ
;
;THE EXTTAB BLOCK FOR A ROUTINE THEN CONTAINS A JSP T1,.OVRLA THAT COMES HERE.
;IF THE LINK BEING CALLED IS ALREADY IN MEMORY AND THE ROUTINE HAS BEEN CALLED
;BEFORE, WE SIMPLY JUMP TO THE ROUTINE. OTHERWISE, THE CORRECT LINK AND ITS PATH
;ARE BROUGHT IN FIRST.
;
;ALL INTER-LINK CALLS EXECUTE THE CODE HERE, SO IT SHOULD BE AS FAST AS
;POSSIBLE. SELF-MODIFYING CODE IS USED FOR THIS.
SEGMENT LOW
CPYRGT
'.OVRLA'
.OVRLA:
;************* REPLACE
JRST SETINI ;INITIALIZE FIRST TIME
;************* BY
; MOVE T0,JT.FLG(T1) ;GET 1ST WORD OF ARG BLOCK
;************* AFTER FIRST TIME
JUMPGE T0,OVRL1 ;NOT KNOWN TO BE IN CORE
HRRZ T1,JT.ADR(T1) ;GET ADDRESS
JRST @(T1) ;GO TO IT
SEGMENT HIGH
SETINI: PUSH P,T1 ;[100] SAVE CALLER PC
PUSHJ P,OVINI ;[100] ZERO MEMORY AND SET UP OVERLAY FILE
POP P,T1 ;[100] RESTORE PC
PJRST .OVRLA ;[100] TRY AGAIN

SUBTTL CHECK PATH -- Determine Links To Delete
;CP0 READS IN A SPECIFIED LINK AND THOSE LINKS ON ITS PATH. THIS IS DONE IN THE
;FOLLOWING STEPS:
;
; 1. DETERMINE THE FIRST DIFFERENCE BETWEEN THE PATH CURRENTLY IN MEMORY AND
; THE PATH REQUIRED FOR THE DESIRED LINK.
; 2. DELETE ALL LINKS FROM THE FIRST DIFFERENCE DOWN.
; 3. READ IN THE NEW LINKS REQUERED TO COMPLETE THE SPECIFIED PATH. RELOCATE
; EACH LINK AS NECESSARY.
; 4. PERFORM 'OTHER' RELOCATION (EFFECTS ON OTHER LINKS WHEN A LINK IS
; RELOCATED) ONCE ALL LINKS IN THE PATH ARE ALL IN.
; 5. READ IN THE SYMBOL TABLE IF NECESSARY, AND RELOCATE IT IF NECESSARY. ON
; TOPS-10, MOVE THE SYMBOL TABLE TOWARD LOWER ADDRESSES AS FAR AS POSSIBLE
; TO CONSERVE MEMORY.
CP0: SPUSH <P1,P2,L> ;[100] GET MORE ACS
PUSHJ P,RP0 ;[100] READ THE PREAMBLE
MOVE P1,FSTLNK ;GET BASE OF INCORE LINKS
HLRZ P2,PH+PH.FPT ;[100] POINTER TO LIST OF WHAT WE NEED
HRRZ T1,PH+PH.FPT ;[100] BLOCK # WE NEED
CAME T1,UBLOCK ;SAME AS CURRENT?
PUSHJ P,[PUSHJ P ,%USETU ;NO, SET ON IT
PJRST %INB] ;READ IT
CP1: HRRZ T0,CS.FPT(P1) ;GET NEXT LINK CONTROL SEC IN CORE (BYPASS 0)
JUMPE T0,CP3 ;FIRST TIME ONLY ROOT THERE
HRLZ P1,P1 ;SAVE LAST GOOD PTR
HRR P1,T0 ;RESET LINK PTR
MOVE T1,INBFR(P2) ;GET LINK # WE WANT
HRRZ T0,CS.NUM(P1) ;LINK# WE HAVE
JRST CP1B ;BYPASS TEST FOR ROOT

SUBTTL CHECK PATH -- Delete Old Links
;HERE TO DELETE ALL NOW-UNNECESSARY LINKS.
CP2: PUSH P,P1 ;SAVE FIRST DIFF
HRRZ P1,P1 ;CLEAR PREV
PUSHJ P,DELPTH ;[43] DELETE ALL OLD LINKS
POP P,P1
HLRZ P1,P1 ;GET LAST GOOD ONE
;HERE TO READ IN THE REST OF THE DESIRED PATH. THIS IS DONE IN REVERSE ORDER
;SINCE WE ONLY HAVE ONE BUFFER. 'OTHER' RELOCATION MUST WAIT UNTIL ALL LINKS ARE
;IN MEMORY.
CP3: PUSHJ P,GTLNK ;GET IT
MOVE P1,THSLNK ;GET POINTER TO NEW LINK
HRRZ T1,PH+PH.BPT ;[100] GET ADDRESS OF BACK POINTER LIST
CAME T1,UBLOCK ;CURRENTLY IN CORE?
PUSHJ P,[PUSHJ P ,%USETU ;NO, SET ON IT
PJRST %INB] ;READ IT
HLRZ P2,PH+PH.BPT ;[100]
ANDI T1,177 ;OFFSET IN THIS BUFFER
MOVE T0,INBFR(P2) ;WHOM IT SHOULD BE LINKED TO
TRNE T0,-1 ;IF LAST HALF WORD IS NULL
TLZA T0,-1 ;NO, SO CLEAR LEFT
HLRZ T0,T0 ;YES, USE LEFT HALF
HLRZ T1,CS.BPT(P1) ;GET BACK LINK
HRRZ T1,CS.NUM(T1) ;WHOM IT IS LINKED TO
CAMN T1,T0 ;SAME?
JRST CP4 ;YES, RETURN
PUSHJ P,RP0 ;GET THIS PREAMBLE
HLRZ P1,CS.BPT(P1) ;RESET P1 TO POINT TO FATHER
JRST CP3 ;AND READ IN LINK
;ROUTINE TO DELETE A LINK. THIS IMPLIES DELETING ALL OF ITS INFERIORS (THE
;PATH) TOO. IF WE TRY TO DELETE THE CURRENT LINK (THE ONE THAT CALLED US),
;GIVE ?OVLARC.
;
;CALL:
; P1/ CONTROL BLOCK ADDR OF LINK TO START AT
;DESTROYS P1.
DELPTH: MOVEM P1,THSLNK ;[43] SET UP LINK FOR GBLNK
SKIPN OKOVLC ;[43] OK TO DELETE THE CALLER'S LINK
CAME P1,CURLNK ;[43] OR NOT THE CALLER'S LINK?
SKIPA ;[43] YES--DELETE THIS LINK
JRST E$$ARC ;[100] NO--ATTEMPT TO REMOVE CALLER
HRRZ P1,CS.FPT(P1) ;[43] ADVANCE TO NEXT WHILE WE CAN
PUSHJ P,GBLNK ;[43] GIVE BACK THE LINK
JUMPN P1,DELPTH ;[43] FREE MORE IF ANY
POPJ P, ;[43] ALL DONE