Google
 

Trailing-Edge - PDP-10 Archives - BB-H311D-RM - monitor-sources/postld.mac
There are 51 other files named postld.mac in the archive. Click here to see a list.
; UPD ID= 4830, SNARK:<6.MONITOR>POSTLD.MAC.24,  17-Sep-84 10:44:54 by PURRETTA
;Update copyright notice
; UPD ID= 3814, SNARK:<6.MONITOR>POSTLD.MAC.23,  29-Feb-84 16:53:39 by LEACHE
;TCO 6.1969 - Put swapmon in second 256K so can be loaded with resmon.
; UPD ID= 3697, SNARK:<6.MONITOR>POSTLD.MAC.22,  15-Feb-84 21:08:58 by MURPHY
;Load above physical 256k.
; UPD ID= 3674, SNARK:<6.MONITOR>POSTLD.MAC.21,   8-Feb-84 14:53:20 by MURPHY
;Fix some bugs, count link-time pages.
; UPD ID= 3635, SNARK:<6.MONITOR>POSTLD.MAC.20,   1-Feb-84 22:09:47 by MURPHY
;Ever more 6.1525 - Add psect for extended code.
; UPD ID= 2808, SNARK:<6.MONITOR>POSTLD.MAC.19,   9-Aug-83 11:47:05 by MURPHY
;Add section 0 code psect.
; UPD ID= 2620, SNARK:<6.MONITOR>POSTLD.MAC.18,  21-Jun-83 15:34:20 by MURPHY
;Shuffle psects
; UPD ID= 2578, SNARK:<6.MONITOR>POSTLD.MAC.17,  13-Jun-83 17:06:22 by MURPHY
;TCO 6.1678 - Produce listing of new PSECT origins.
; UPD ID= 2572, SNARK:<6.MONITOR>POSTLD.MAC.16,   8-Jun-83 16:07:07 by MOSER
;TCO 6.1639 <= Overflow TO <CR>? PSECT Overflow
; UPD ID= 2562, SNARK:<6.MONITOR>POSTLD.MAC.15,   7-Jun-83 17:02:05 by MURPHY
;More 6.1525 - Move BUGPTRs and BUGSTRINGs to ext section; elim BUGSTF.
;Flush HIDSYF - assume symbols always hidden.
; UPD ID= 2482, SNARK:<6.MONITOR>POSTLD.MAC.14,  17-May-83 17:47:52 by MURPHY
;Ditto.
; UPD ID= 2470, SNARK:<6.MONITOR>POSTLD.MAC.13,  16-May-83 17:22:30 by MURPHY
;More TCO 6.1525 - Report boundaries for ERVAR, etc.
; UPD ID= 2436, SNARK:<6.MONITOR>POSTLD.MAC.11,   6-May-83 10:58:59 by LOMARTIRE
;TCO 6.1627 - Move FFF into STG so it's size can be changed easier
; UPD ID= 2225, SNARK:<6.MONITOR>POSTLD.MAC.10,   8-Apr-83 17:55:26 by MURPHY
;TCO 6.1525 - Implement RSE, NRE, etc.
; UPD ID= 2196, SNARK:<6.MONITOR>POSTLD.MAC.9,   7-Apr-83 23:48:37 by MURPHY
;Make POSTCD upper limit be BGSTR.
; UPD ID= 2186, SNARK:<6.MONITOR>POSTLD.MAC.8,   7-Apr-83 21:07:30 by MURPHY
;Make free page count not include POSTLD.
; UPD ID= 2185, SNARK:<6.MONITOR>POSTLD.MAC.7,   7-Apr-83 20:52:40 by MURPHY
;Allow POSTCD to overlay NPVAR.
; UPD ID= 1875, SNARK:<6.MONITOR>POSTLD.MAC.6,  24-Feb-83 23:05:09 by MURPHY
;Allow BGPTR and BGCOD to overlap NPVAR if not keeping them.
; UPD ID= 376, SNARK:<6.MONITOR>POSTLD.MAC.5,   2-Feb-82 13:31:41 by PAETZOLD
;TCO 5.1714 - Fix code so that BUGSTRINGS.TXT knows difference between
; BUGHLT, BUGCHK, and BUGINF
; UPD ID= 1457, SNARK:<5.MONITOR>POSTLD.MAC.4,  20-Jan-81 09:36:38 by DONAHUE
;TCO 5.1235 - add label BUGD:
; UPD ID= 796, SNARK:<5.MONITOR>POSTLD.MAC.3,  24-Jul-80 10:56:19 by HALL
;DEFINE FFF HERE SO THAT IT CAN BE THE LAST THING IN RSDAT
; UPD ID= 421, SNARK:<5.MONITOR>POSTLD.MAC.2,  11-Apr-80 13:51:20 by HALL
;CHANGES TO WRITE-PROTECT RESIDENT MONITOR
;	ADD RSDAT PSECT TO PEND INVOCATION
;	ADD RSDAT PSECT TO ARGUMENTS FOR SSAVE JSYS
;<4.1.MONITOR>POSTLD.MAC.16,  8-Nov-79 06:36:56, EDIT BY R.ACE
;<R.ACE>POSTLD.MAC.1,  7-Nov-79 12:25:39, EDIT BY R.ACE
;MAKE POSTLD TYPE NAME AND VERSION #
;<4.MONITOR>POSTLD.MAC.15, 30-Oct-79 11:37:18, EDIT BY MILLER
;<4.MONITOR>POSTLD.MAC.14, 30-Oct-79 10:31:48, EDIT BY MILLER
;GET SYS TIME AND DATE FROM FDB OF VERSIO.MAC
;<4.MONITOR>POSTLD.MAC.13, 20-Aug-79 02:45:20, EDIT BY GILBERT
;Re-implement BUGSTF and HIDSYM conditionals after edit 12.
;<4.MONITOR>POSTLD.MAC.12, 17-Aug-79 03:40:47, EDIT BY GILBERT
;TCO 4.2408: MAKE TYPEOUT FORMAT EASIER TO READ, ADD VARIOUS CHECKS TO
;SEE IF THE MONITOR WILL RUN, DISPLAY ALL PSECTS INCLUDING POSTCD.
;<4.MONITOR>POSTLD.MAC.11, 15-Jun-79 01:38:41, EDIT BY GILBERT
;REMOVE CODE TO GET AROUND MACRO BUG WHICH IS NOW FIXED.
;<4.MONITOR>POSTLD.MAC.10,  9-Apr-79 14:29:33, EDIT BY DBELL
;TCO 4.2227 - FIX SSEG MACRO WHICH SOMETIMES FAILED TO SAVE A PAGE.
;<4.MONITOR>POSTLD.MAC.9,  6-Mar-79 09:43:00, EDIT BY KONEN
;UPDATE COPYRIGHT FOR RELEASE 4
;<4.MONITOR>POSTLD.MAC.8, 18-Jan-79 13:35:19, EDIT BY GILBERT
;REALLY FIX BUG IF SYMBOL TABLE STARTS ON SAME PAGE THAT INCOD ENDS.
;<4.MONITOR>POSTLD.MAC.6, 15-Jan-79 07:46:33, EDIT BY GILBERT
;More TCO 4.1255:
;	Re-arrange the PSECTs.
;	Fix bug if symbol table starts in same page that INCOD ends.
;<4.MONITOR>POSTLD.MAC.5,  8-Jan-79 06:56:36, EDIT BY GILBERT
;TCO 4.2155 - Implement hidden symbol tables:
;	Make PSECT end names uniform.
;	Remove all symbol table processing code.
;	Clean up PSECT overlap typeout and teach about new PSECT order.
;<4.MONITOR>POSTLD.MAC.4, 22-Jun-78 16:25:36, EDIT BY MILLER
;ADD AN "XPUNGE"
;<1BOSACK>POSTLD.MAC.1001, 15-Jun-78 15:36:36, EDIT BY BOSACK
;<1BOSACK>POSTLD.MAC.1000,  1-Jun-78 21:06:27, EDIT BY BOSACK
;CHANGES FOR MORE PSECTS
;<4.MONITOR>POSTLD.MAC.2, 14-Jun-78 06:41:41, Edit by JBORCHEK
;ADD BUGSTF FLAG TO PUT BUGSTRINGS IN MONITOR VAS
;<3A.MONITOR>POSTLD.MAC.7,  7-Mar-78 18:54:08, EDIT BY BOSACK
;<3A.MONITOR>POSTLD.MAC.6,  7-Mar-78 18:34:40, EDIT BY BOSACK
;<3A.MONITOR>POSTLD.MAC.5,  7-Mar-78 18:33:50, EDIT BY BOSACK
;OUTPUT TYPE OF BUGXXX IN BUGXXX LISTING
;<3A.MONITOR>POSTLD.MAC.4, 23-Jan-78 20:56:36, EDIT BY BOSACK
;<3A.MONITOR>POSTLD.MAC.3, 23-Jan-78 20:36:30, EDIT BY BOSACK
;MOVE BUGSTRINGS/POINTERS TO OVERLAP SWP PAGE VARS
;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY  BE  USED
;OR COPIED ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT  (C)  DIGITAL  EQUIPMENT  CORPORATION  1976, 1984.
;ALL RIGHTS RESERVED.


	SEARCH PROLOG
	TTITLE (POSTLD,, - POST-LOADING ONE-SHOT INIT)

;***** A%VFST is the presumed start of BOOT.  Nothing above this limit
;***** will be loaded from the EXE file.  It would be better if this
;***** value were obtained from the BOOT assembly, but that is not
;***** linked with the monitor build.  Hence, this must be changed
;***** manually if BOOT grows.  There is a warning in BOOT if A%VFST changes.

A%VFST=:750000
DDTPGA=:POSTCD			;A GOOD PLACE FOR MDDT VARIABLES IN SYMSEC
DDTPG==:DDTPGA/PGSIZ
SYMPAD==200			;NUMBER WORDS FOR SYMTAB GROWTH
SEC1==1			;LOCAL SECTION 1
PENCOD=:<SEC1,,1000>		;PHYSICAL LOCATION OF ENCOD

EXT <NBUGP,SYMMV1,SYMMV2,SYMMV3,FREMEM>


NPDL==100			;SIZE OF LOCAL PDL
.NSTAB==^D8			;NUMBER SPACES PER TAB


DEFINE TMSG ($MSG)<
	HRROI T1,[ASCIZ \$MSG\]
	PSOUT>

DEFINE FMSG ($MSG)<
	HRROI T2,[ASCIZ \$MSG\]
	SETZ T3,
	SOUT>

DEFINE SSOUT <
	SETZ T3,
	SOUT>

DEFINE JSERR <
	CALL JSEX0>

DEFINE JSHLT <
	CALL JSHLT0>
;GET FINAL VALUE OF LOAD PC'S

DEFINE PEND(PSECT),<
    IRP PSECT,<
	.PSECT PSECT
	PSECT'Z=:.-1
	PSECT'L==:PSECT'Z_-PGSFT
	.ENDPS PSECT
    >
>

PEND <RSCOD,SZCOD,INCOD,RSDAT,PPVAR,RSVAR>
PEND <NRCOD,BGSTR,BGPTR,NRVAR,ERCOD,ENCOD>

;LOAD POSTLD WHERE IT WILL GET OVERLAYED BY RUNTIME STORAGE

	.ENDPS RSCOD
	.PSECT POSTCD
POSTLD::			;TAG AT RELATIVE 0 IN POSTLD

PENCDZ=:PENCOD+ENCODZ-ENCOD	;END OF PENCOD

;TABLE OF PSEUDO-PSECTS.  THESE ARE DEFINED AT ASSEMBLY TIME.

DEFINE PP (NAME)<POINT 7,[ASCIZ /NAME/]>

PPSECT:	PP PSVAR
	PP JSVAR
	PP NPVAR
	PP ERVAR
	PP ENVAR
	PP EPVAR
NPPSEC==.-PPSECT
;START HERE AT COMPLETION OF LOADING

SYSG0:	MOVE P,[IOWD NPDL,PDL]
	SETZM T3		;ASSUME MON: IS KNOWN
	HRROI T1,[ASCIZ /MON/]
	STDEV			;SEE IF MON: IS DEFINED
	 ADDI T3,1		;NOT
	MOVX T1,GJ%OLD!GJ%SHT	;GET THE SOURCE FILE
	HRRO T2,[[ASCIZ /MON:VERSIO.MAC/]
		 [ASCIZ /VERSIO.MAC/]](T3)
	GTJFN			;GET HANDLE
	 ERJMP [HRROI T1,[ASCIZ /
%VERSIO.MAC not found. Current time and date used
/]
		PSOUT
		GTAD		;GET TIME AND DATE
		JRST SYSG00]	;AND PROCEED
	MOVEI T2,T2		;WHERE TO PUT DATE AND TIME WORD
	MOVEI T3,1		;ONE WORD IS ALL WE NEED
	RFTAD			;GET TIME AND DATE WORD
	RLJFN			;RELEASE JFN OF FILE
	 NOP
	MOVE T1,T2		;STASH WORD IN T1
SYSG00:	MOVEM T1,SYSTAD		;REMEMBER IT IN SWPMON

;Put symbol table pointers in MONEDV.

	MOVE T1,.JBSYM		;GET SYMBOL POINTER
	MOVEM T1,MONEDV+.EDSYM	;PUT IN EDV
	MOVE T1,.JBUSY		;SAME FOR UNDEFINED POINTER
	MOVEM T1,MONEDV+.EDUSY	;PUT IN EDV

	HLRE T1,.JBSYM		;GET LENGTH OF SYMBOL TABLE
	MOVN T1,T1		;MAKE POSITIVE
	HRRZ T2,.JBSYM		;GET BEGINNING
	ADDI T1,-1(T2)		;COMPUTE LAST USED
	HRRZM T1,SYMLU		;REMEMBER IT
	SKIPL T1,.JBUSY		;FIRST USED IF UNDEFINED SYMBOLS
	HRRZ T1,.JBSYM		;GET FIRST USED
	HRRZM T1,SYMFU		;REMEMBER IT TOO
	MOVE T1,SYMLU		;COMPUTE TOTAL LENGTH
	SUB T1,SYMFU
	MOVEM T1,SYMTL
	SETZM FPAGES		;NO FREE PAGES YET
	SETZM LTPGS		;DITTO LINK-TIME PAGES
	SETZM NOVRFL		;NO OVERFLOWS YET
	HRROI T1,[ASCIZ/
/]
	PSOUT			;SKIP A LINE
	HRROI T1,TSVN		;TYPE SYSTEM NAME AND VERSION #
	PSOUT
	HRROI T1,[ASCIZ /

Monitor address space:

    Psect               Start       End    Length      Free  	Limit
/]
	PSOUT
	; ..
	; ..

;DEFINE LOCAL MACRO FOR SPACE PRINTOUTS
;ARGS:
;  1. Name of psect
;  2. Name of next psect; ignored if arg 5 used
;  3. Beginning of psect - default to value of psect name symbol
;  4. End of psect - default to psect'Z
;  5. Address of next psect - default to value of symbol in arg 2.
;  6. Limit of this psect - default to next psect.

;Leaves free page count in AC2 for possible summing to FPAGES.

$NAME==0
$PBGN==1
$PEND==2
$PNEX==3
$PLIM==4

DEFINE PRPSC($PSECT,$NEXT,$BEGA,$ENDA,$NEXTA,$LIMIT)<
	MOVEI P2,[POINT 7,[ASCIZ \$PSECT\]
	   IFNB <$BEGA>,<MOVE P1,$BEGA>
	   IFB <$BEGA>,<MOVE P1,[$PSECT]>
	   IFNB <$ENDA>,<MOVE T2,$ENDA>
	   IFB <$ENDA>,<MOVE T2,[$PSECT'Z]>
	   IFNB <$NEXTA>,<MOVE T2,$NEXTA>
	   IFB <$NEXTA>,<MOVE T2,[$NEXT]>
	   IFNB <$LIMIT>,<
		POINT 7,[ASCIZ \$LIMIT\]>
	   IFB <$LIMIT>,<0>]
	CALL PRPSBR
   >
POSTL1:
;COMPUTE LENGTH OF BUGSTRING AND BUGPTRS

	MOVE T3,[BGPTRZ-BGPTR+PGSIZ-1]
	ANDX T3,-PGSIZ
	MOVEM T3,BUGLEN
	MOVE T3,[BGSTRZ-BGSTR+PGSIZ-1]
	ANDX T3,-PGSIZ
	ADDM T3,BUGLEN		;SAVE IT FOR LATER

	SETZM PSIDX		;INIT INDEX TO PSECT TABLES
	MOVE T2,PSIDX
	MOVEI T1,1000		;FIRST PSECT ORIGIN
	MOVEM T1,PSORG(T2)	;SET IT

	PRPSC (RSCOD,SZCOD)
	ADDM T2,FPAGES
	ADDM T2,LTPGS		;counts in link-time free pages
	PRPSC (SZCOD,INCOD)
	ADDM T2,FPAGES
	ADDM T2,LTPGS		;counts in link-time free pages
	PRPSC (INCOD,RSDAT)
	ADDM T2,FPAGES
	ADDM T2,LTPGS		;counts in link-time free pages
	PRPSC (RSDAT,PPVAR)
	ADDM T2,FPAGES

;COMPUTE END OF SYMBOL TABLE

	MOVE T2,PSIDX
	MOVE T1,PSORG(T2)	;CURRENT ORIGIN
	ADDI T1,200		;SOME PAD
	HLRE T3,.JBSYM
	SUB T1,T3		;ADD LENGTH
	HLRE T3,.JBUSY
	SUB T1,T3		;ADD LENGTH OF UNDEF SYMTAB
	MOVEM T1,SYTEND		;SAVE IT

	PRPSC (PPVAR,RSVAR)
	ADDM T2,FPAGES
	PRPSC (RSVAR,NRVAR)
	ADDM T2,FPAGES
	PRPSC (NRVAR,PSVAR)
	ADDM T2,FPAGES
	PRPSC (PSVAR,JSVAR)
	ADDM T2,FPAGES
	PRPSC (JSVAR,NRCOD)
	ADDM T2,FPAGES

;Compute NRCOD origin.  It must start above preceding PSECTs and
;leave sufficient room for the bug strings and pointers.
;The bug strings and pointers go before NRCOD and overlay the
;various storage psects but must start above the symbol table end.

POSTL2:
	MOVE T2,PSIDX
	MOVE T1,PSORG(T2)	;GET CURRENT ORIGIN
	SUB T1,BUGLEN		;SEE WHERE BUG STUFF WOULD START
	MOVEM T1,BUGORG		;POSSIBLE BUG ORIGIN
	CAML T1,SYTEND		;OVERLAP SYMBOL TABLE?
	IFSKP.
	  MOVE T1,SYTEND	;YES. COMPUTE NEW ORIGIN BASED ON SYMTAB
	  ADDI T1,PGSIZ-1
	  ANDX T1,-PGSIZ	;ROUND UP TO NEXT PAGE BOUNDARY
	  MOVEM T1,BUGORG	;THIS BECOMES BUG ORIGIN
	  ADD T1,BUGLEN
	  MOVEM T1,PSORG(T2)	;THIS BECOMES NEXT ORIGIN
	ENDIF.

	MOVE T1,[NPVAR]
	CAMLE T1,[ERCOD]
	MOVE T1,[ERCOD]
	MOVEM T1,MNENC		;COMPUTE LOWER OF NPVAR, ERCOD
	PRPSC (NRCOD,,,,MNENC,<Lower of NPVAR, ERCOD>)
	ADDM T2,FPAGES

;See if NPVAR will end within section 0.  If not, set its origin
;lower so that the overlap will be with NRCOD.

	MOVE T2,PSIDX
	MOVE T3,PSORG(T2)	;save current boundary, end of NRCOD
	MOVEM T3,MNENC
	MOVE T3,[NPVARZ-NPVAR+PGSIZ-1]
	ANDX T3,-PGSIZ
	MOVE T1,[1,,0]
	SUB T1,T3		;MAX NPVAR ORIGIN
	CAML T1,PSORG(T2)	;OVERLAP?
	IFSKP.
	  EXCH T1,PSORG(T2)	;YES, SET NEXT ORIGIN LOWER
	  SUB T1,PSORG(T2)	;COMPUTE DIFFERENCE
	  MOVEM T1,NPOVL	;SAVE OVERLAP AMOUNT
	ENDIF.
	PRPSC (NPVAR,<Section 0 end>,,,[1000000],777777)
	ADDM T2,FPAGES

	MOVE T2,PSIDX
	MOVE T1,[777777-PSTEND+POSTCD] ;COMPUTE POSTCD ORIGIN
	ANDX T1,-PGSIZ		;ROUND DOWN TO PAGE BOUNDARY
	MOVEM T1,PSORG(T2)	;SET IT
	PRPSC (POSTCD,<Section 0 end>,,[PSTEND],[1000000],777777)

	MOVE T2,PSIDX
	MOVEI T1,1000		;TO NEW SECTION
	MOVEM T1,PSORG(T2)

	TMSG <

There are >
	MOVE T2,FPAGES
	CALL OCTOUT
	TMSG < (octal) free pages in section 0.

>
POSTL3:
	TMSG <

Extended variables section:
>
	PRPSC (ERVAR,ENVAR)
	PRPSC (ENVAR,EPVAR)
	PRPSC (EPVAR,<Section end>,,,<[RESSEC+1,,0]>,<End of section>)
	TMSG <
>

	TMSG <
Symbol Section:
>
	PRPSC (<Loaded symbols >,,SYMFU,SYMLU,BUGORG,BGSTR)
	MOVEM T2,FPAGES
	ADDM T2,LTPGS		;counts in link-time free pages
	MOVNI T1,1		;FLUSH PSECT FROM TABLE
	ADDM T1,PSIDX
	MOVE T2,PSIDX
	MOVE T1,BUGORG
	MOVEM T1,PSORG(T2)	;SET BUG ORIGIN

	PRPSC (BGSTR,BGPTR)
	ADDM T2,FPAGES
	ADDM T2,LTPGS		;counts in link-time free pages
	PRPSC (BGPTR,NRCOD,,,,NRCOD)
	ADDM T2,FPAGES
	ADDM T2,LTPGS		;counts in link-time free pages

;Compute highest ERCOD origin.
;ENCOD must end below POSTLD, ERCOD must end below BOOT and below
;ENCOD.

	MOVE T1,[POSTCD_-PGSFT]		;POSTCD PAGE
	MOVE T3,T1
	LSH T3,PGSFT		;CONVERT TO ADDRESS
	MOVEM T3,MAXCOD		;SAVE LIMIT OF LOADED CODE
	SUB T1,[<ENCODZ-ENCOD+PGSIZ-1>_-PGSFT] ;LENGTH IN PAGES OF ENCOD
	CAMLE T1,[A%VFST_-PGSFT] ;BELOW BOOT?
	MOVE T1,[A%VFST_-PGSFT]	;NO, USE BOOT
	MOVE T3,T1
	LSH T3,PGSFT		;CONVERT TO ADDRESS
	MOVEM T3,MAXERC		;THIS IS UPPER LIMIT OF ERCOD
	SUB T1,[<ERCODZ-ERCOD+PGSIZ-1>_-PGSFT] ;LENGTH IN PAGES OF ERCOD
	LSH T1,PGSFT
	MOVE T2,PSIDX
	EXCH T1,PSORG(T2)	;SET ORIGIN
	ADDI T1,^D8		;ALLOW FOR TEMP CST MAPPING AT STARTUP
	MOVE T3,MNENC		;MINIMUM END OF NRCOD
	CAMG T3,PSORG(T2)	;ABOVE ERCOD START?
	CAMLE T1,PSORG(T2)	;ABOVE PREVIOUS PSECT?
	IFNSK.
	  TMSG <
%An overlap exists which cannot be automatically corrected.
>
	ENDIF.
	MOVEI T1,NRCOD+SYMPAD	;PICK RUNTIME SYMTAB LOC, ALLOW GROWTH DOWN
	MOVEM T1,RSTFU		;SET BEGINNING
	ADD T1,SYMTL
	MOVEM T1,RSTLU		;SET END
	PRPSC (<Runtime symbols>,,RSTFU,RSTLU,[ERCOD-10000],ERCOD-10000)
	ADDM T2,FPAGES
	ADDM T2,LTPGS		;counts in link-time free pages
	MOVE T1,RSTLU
	ADDI T1,PGSIZ-1		;COMPUTE FIRST FREE PHYSICAL PAGE
	ANDX T1,-PGSIZ
	MOVEM T1,FREMEM
	MOVNI T1,1		;FLUSH 1 PSECT FROM TABLE
	ADDM T1,PSIDX
	PRPSC (ERCOD,,,,MAXERC,<Lower of BOOT, ENCOD>)
	ADDM T2,FPAGES
	ADDM T2,LTPGS		;counts in link-time free pages
	PRPSC (ENCOD,POSTCD)
	ADDM T2,FPAGES
	ADDM T2,LTPGS		;counts in link-time free pages

	TMSG <

There are >
	MOVE T2,LTPGS
	CALL OCTOUT
	TMSG < (octal) free pages in the linked image.

>
POSTL4:
	SKIPG NOVRFL		;OVERFLOWS?
	IFSKP.
	  TMSG <
? >
	  MOVEI T1,.PRIOU
	  MOVE T2,NOVRFL
	  MOVEI T3,^D10
	  NOUT%
	   NOP
	  TMSG < PSECT overflow(s) detected.
>
	ENDIF.

;SETUP CONSTANTS TO MOVE SYMBOL TABLE AT STARTUP

	HRLZ T1,SYMFU
	HRR T1,RSTFU		;BLT PTR, MOVE TO RSTFU
	SUB T1,[SYMPAD,,SYMPAD]	;ALLOW PAD
	MOVEM T1,SYMMV1
	MOVE T1,RSTLU
	MOVEM T1,SYMMV2
	MOVE T1,RSTFU
	SUB T1,SYMFU		;COMPUTE AMOUNT MOVED TO ADJUST POINTERS
	MOVEM T1,SYMMV3

;Init MMAP to make virtual=physical for known psects.

	MOVE T1,[0,,RSDATZ]
	CALL SETMMP		;DO RESIDENT DATA AND CODE
	MOVE T1,[RSVAR,,RSVARZ]
	CALL SETMMP
	HRLZ T1,RSTFU		;RUNTIME SYMBOLS
	HRR T1,RSTLU
	MOVEM T1,SYTBBP		;SAVE BOUNDARIES FOR LOCK/UNLOCK
	CALL SETMMP
	MOVE T1,[ERCOD,,ERCODZ]	;DDT AMONG OTHER THINGS
	CALL SETMMP

	TMSG <A potential set of new PSECT origins will be written into LNKNEW.CCL
and PARNEW.MAC.
>
	SKIPG T2,NPOVL		;SECTION 0 OVERFLOW?
	IFSKP.
	  TMSG <
Note however, that even this set of origins will overflow section 0.
The configuration size must therefore be reduced.
There will be an overlap of NPVAR and NRCOD of >
	  MOVEI T1,.PRIOU
	  MOVEI T3,^D8
	  NOUT
	   NOP
	  TMSG < (octal) words.

>
	ENDIF.
POSTL5:
	HRROI T1,[ASCIZ /LNKNEW.CCL/]
	CALL OUTFIL
	IFNSK.
	  TMSG <%Failed to write new psect origin file: >
	  JSERR
	  JRST POST8
	ENDIF.
	MOVEM T1,LNKJFN		;FILE FOR NEW PSECT ORIGINS
	HRROI T1,[ASCIZ /PARNEW.MAC/]
	CALL OUTFIL
	IFNSK.
	  TMSG <%Failed to write new psect origin file: >
	  JSERR
	  JRST POST8
	ENDIF.
	MOVEM T1,PARJFN		;FILE FOR NEW PSEUDO-PSECT ORIGINS

	FMSG <
;PSECT origins for monitor >
	HRROI T2,TSVN
	SOUT
	FMSG <

>

	MOVE T1,LNKJFN
	FMSG <
;PSECT origins for monitor >
	HRROI T2,TSVN
	SOUT
	FMSG <

>

	MOVEI Q1,0		;INIT PSEC ORIGIN
     DO.
	CAML Q1,PSIDX		;STILL WITHIN USED RANGE?
	EXIT.			;DONE
	BLCAL. SKPPSC,<PSNAM(Q1)> ;SKIP IF REAL PSECT
      IFSKP.
	MOVE T1,LNKJFN	;WRITE TO LINK FILE
	FMSG </SET:>
	MOVE T2,PSNAM(Q1)	;NAME
	SOUT
	MOVEI T2,":"
	BOUT
      ELSE.
	MOVE T1,PARJFN		;WRITE TO MACRO PARAMETER FILE
	SETZ T3,		;FORMAT LINE FOR MACRO
	MOVE T2,PSNAM(Q1)
	SOUT			;NAME
	HRROI T2,[ASCIZ /=:/]
	SOUT
      ENDIF.
	MOVE T2,PSORG(Q1)	;ORIGIN
	MOVEI T3,^D8
	NOUT
	 JSERR			;REPORT FAILURE
	FMSG <
>
	AOJA Q1,TOP.		;DO ALL PSECTS
     ENDDO.
	MOVE T1,LNKJFN		;WRITE STANDARD LINK FILE STUFF
	FMSG </SYMSEG:PSECT:RSDAT/UPTO:>
	MOVE T2,BUGORG
	SUBI T2,1
	MOVEI T3,^D8
	NOUT
	 NOP
	FMSG <
>
	MOVE T1,LNKJFN
	CLOSF
	 NOP
	MOVE T1,PARJFN
	CLOSF
	 NOP
POST8:	TMSG <
>
	JRST POST9		;CONTINUE
;WORK ROUTINE FOR PRPSC

; $NAME==0
; $PBGN==1
; $PEND==2
; $PNEX==3
; $PLIM==4

PRPSBR:	SAVEAC <Q1,P1,P3>
	MOVE Q1,PSIDX		;CURRENT PSECT TABLE INDEX
	MOVEI P3,0		;INIT COLUMN COUNTER
	HRROI T1,[ASCIZ /
    /]
	CALL TYPSTR
	MOVE T1,$NAME(P2)	;NAME OF PSECT
	MOVEM T1,PSNAM(Q1)	;SAVE IT FOR TEXT FILE
	CALL TYPSTR
	MOVEI T1," "
     DO.
	CAIL P3,^D22
	JRST ENDLP.
	PBOUT			;TAB TO COL 22
	AOJA P3,TOP.
     ENDDO.
	XCT $PBGN(P2)		;GET BEGINNING ADR
	MOVE T2,P1
	CALL OCTOUC
	XCT $PEND(P2)		;GET END ADR
	CALL OCTOUC
	SUBM T2,P1
	EXCH T2,P1
	ADDI T2,1
	MOVEM T2,PSORG+1(Q1)	;SAVE LENGTH
	CALL OCTOUC

	MOVE T2,PSORG+1(Q1)	;ROUND LENGTH UP TO PAGE BOUNDARY
	ADDI T2,PGSIZ-1
	ANDX T2,-PGSIZ
	ADD T2,PSORG(Q1)	;COMPUTE ORIGIN OF NEXT PSECT
	MOVEM T2,PSORG+1(Q1)	;SAVE IT

	XCT $PNEX(P2)		;GET NEXT ADDRESS
	SUB T2,P1
	SUBI T2,1
	CALL OCTOUC
	HRROI T1,[ASCIZ \	\]
	PSOUT%
	MOVE T1,$PLIM(P2)
	SKIPE T1
	CALL TYPSTR
	HRROI T1,[ASCIZ \	**** OVERFLOW ****\]
	SKIPL T2
	IFSKP.
	  PSOUT%
	  AOS NOVRFL
	ENDIF.
	ASH T2,-9
	AOS PSIDX		;STEP TO NEXT PSECT ENTRY
	RET
;TYPE STRING AND COUNT COLUMNS
; T1/ POINTER TO ASCIZ STRING
; P3/ COLUMN COUNTER - UPDATED ON RETURN

TYPSTR:	SAVEAC <T2,P1,P2>
	MOVE P1,T1
	HLRZ T1,P1
	CAIN T1,-1
	HRLI P1,(POINT 7,0)
	MOVE P2,P1		;SAVE COPY
      DO.
	ILDB T1,P1
	JUMPE T1,ENDLP.
	CAIE T1,.CHTAB
	IFSKP.
	  MOVE T1,P3
	  IDIVI T1,.NSTAB	;NUMBER SPACES PER TAB
	  ADDI T1,1		;STEP TO NEXT TAB STOP
	  IMULI T1,.NSTAB
	  JRST TOP.
	ENDIF.
	AOJA P3,TOP.		;COUNT BYTES
     ENDDO.
	MOVE T1,P2
	PSOUT			;NOW TYPE IT
	RET
;SKIP IF PSECT NAME IS NOT IN LIST OF PSEUDO-PSECTS
; PNM - BYTE POINTER TO PSECT NAME

SKPPSC:	BLSUB. <PNM>
	SAVET
	MOVSI T4,-NPPSEC	;NUMBER OF PSEUDO PSECTS
      DO.
	MOVE T1,PNM
	MOVE T2,PPSECT(T4)
	CALL STCMP
	IFSKP.
	  RET			;IN LIST, THEREFORE NOT REAL PSECT
	ENDIF.
	AOBJN T4,TOP.		;CHECK ALL OF LIST
      ENDDO.
	RETSKP			;NOT FOUND IN LIST, THEREFORE A REAL PSECT

	ENDBS.

;STRING COMPARE - SKIP IF STRINGS EQUAL
; T1/ STRING POINTER
; T2/ STRING POINTER

STCMP:	SAVEAC <T3,T4>
      DO.
	ILDB T3,T1
	ILDB T4,T2
	CAME T3,T4
	RET			;NOT EQUAL
	JUMPN T3,TOP.
      ENDDO.
	RETSKP			;STRING BOTH ENDED, THEREFORE EQUAL

;SETUP POINTERS IN MMAP.
; T1/ FIRST VA, LAST VA
;	CALL SETMMP
; RETURNS +1 ALWAYS

SETMMP:	HLRZ T4,T1		;FIRST VA
	LSH T4,-PGSFT		;MAKE PAGE NUMBER
	HRRZ T3,T1		;LAST VA
	LSH T3,-PGSFT
	MOVE T1,IMMPTR
	IOR T1,T4		;MAKE POINTER TO SAME PHYS PAGE
      DO.
	CAMLE T4,T3		;BEYOND LAST?
	EXIT.			;YES
	MOVEM T1,MMAP(T4)	;PUT POINTER IN MMAP
	ADDI T1,1		;BUMP POINTER
	AOJA T4,TOP.
      ENDDO.
	RET
;SET ENTRY VECTOR AND START ADDRESS

POST9:	MOVEI 1,.FHSLF
	MOVE 2,[JRST EVGO]	;MAIN START LOCATION
	HRRM 2,.JBSA
	SEVEC
	; ..


;DUMP BUG STRINGS TO FILE, SETUP BUGTABLE IN SWPMON

BUGSR3:	MOVX T1,GJ%FOU+GJ%SHT
	HRROI 2,[ASCIZ /BUGSTRINGS.TXT/]
	GTJFN
	IFJE.
	  JSERR
	  JRST BUGEND		;FORGET ABOUT BUGS
	ENDIF.
	PUSH P,T1		;SAVE JFN
	MOVE T2,T1		;JFN IN T2
	TMSG <Writing sorted bug list to file >
	MOVEI T1,.PRIOU		;TO TERMINAL
	POP P,T2		;FILE DESCRIBED BY THIS JFN
	SETZ T3,		;USUAL TEXT
	JFNS			;TYPE THE FILESPEC
	MOVE T1,T2		;JFN TO T1 FOR OPENF
	MOVE 2,[7B5+1B20]
	OPENF
	IFJE.
	  JSERR
	  JRST BUGEND		;FORGET ABOUT BUG FILE
	ENDIF.
	SETZ 3,
	HRROI 2,TSVN		;SYSTEM VERSION TEXT
	SOUT
	HRROI 2,[ASCIZ /
BUGHLT and BUGCHK names and descriptions

/]
	SOUT
;SORT THE BUG TABLE BY SIXBIT NAME

	MOVSI 7,-NBUGP
	JUMPE 7,BUGEND		;NO BUGPOINTERS LOADED?
BUGSR4:	MOVSI 5,-NBUGP(7)	;SCAN FROM HERE TO END
	HRRI 5,0(7)
	HRLOI 3,377777		;INITIAL MINIMUM
BUGSR1:	HLRZ 6,BGPTR(5)		;BUG ADDRESS
	JUMPE 6,BUGSR2		;IGNORE ZEROS
BUGSR5:	MOVE 2,1(6)		;GET NEXT WORD FROM BLOCK
	TLNN 2,770000		;FOUND THE SIXBIT NAME?
	AOJA 6,BUGSR5		;NO, LOOP BACK UNTIL FOUND
	TXC 2,1B0		;SO COMPARE WORKS ON SIXBIT NAME
	CAML 2,3		;MIN SO FAR?
	JRST BUGSR2		;NO
	MOVE 3,2		;YES, REMEMBER THIS VALUE
	MOVEI 4,0(5)		;AND LOCATION
BUGSR2:	AOBJN 5,BUGSR1
	CAMN 3,[377777,,777777]	;FOUND A MIN?
	JRST BUGD		;NO, NOTHING BUT ZEROS LEFT
	MOVE 6,BGPTR(4)		;INTERCHANGE MIN WITH TOP OF TABLE
	EXCH 6,BGPTR(7)
	MOVEM 6,BGPTR(4)
	AOBJN 7,BUGSR4		;(ALWAYS JUMP)
;PRINT STRINGS TO BUGSTRINGS.TXT

BUGD:	MOVSI 7,-NBUGP		;LOOP OVER ALL OF THE MESSAGES
BUGD1:	MOVE 6,BGPTR(7)		;TABLE ENTRY
	HLRZ 2,6		;ADDRESS
BUGD2:	MOVE 3,1(2)		;GET NEXT WORD FROM BLOCK
	TLNN 3,770000		;FOUND THE SIXBIT NAME YET?
	AOJA 2,BUGD2		;NO, LOOP UNTIL IT IS FOUND
BUGD4:	SETZ 2,			;NOW TYPE OUT NAME
	LSHC 2,6		;GET NEXT CHARACTER
	ADDI 2," "		;MAKE IT ASCII
	BOUT			;OUTPUT IT
	JUMPN 3,BUGD4		;LOOP UNTIL NAME IS FINISHED
	HLRZ 3,6		;GET ADDRESS
	HRRZ 3,(3)		;GET BUGXXX ADDRESS
	HRROI 2,[ASCIZ /	[UNK] /]
	CAIN 3,BUGHLT		;BUGHLT?
	HRROI 2,[ASCIZ /	[HLT] /]
	CAIN 3,BGCCHK		;BUGCHK
	HRROI 2,[ASCIZ /	[CHK] /]
	CAIN 3,BGCINF		;BUGINF?
	HRROI 2,[ASCIZ /	[INF] /]
	MOVEI 3,0
	SOUT			;OUTPUT DESCRIPTION
	HRROI 2,0(6)
	SETZ 3,
	SOUT			;PRINT THE STRING
	HRROI 2,[ASCIZ /
/]
	SOUT
	AOBJN 7,BUGD1
	CLOSF			;CLOSE BUGSTRINGS.TXT
	JFCL
;CREATE THE EXE FILE CONTAINING THE MONITOR

BUGEND:	SETZ T1,		;MAKE PRIVATE SECTION 1
	MOVX T2,<.FHSLF,,SEC1>
	MOVX T3,<SM%RD!SM%WR!SM%EX+1>
	SMAP%
	IFJER.
	  TMSG <
?Can't create section 1, >
	  CALL JSERM
	  HALTF
	ENDIF.

;Move ENCOD to section 1 so that it will be loaded into physical
;section 1 by BOOT.

	BLCAL. XBLT$,<[ENCOD],[PENCOD],[ENCODZ-ENCOD]>

;Map NRCOD into section 1

	MOVE T1,[.FHSLF,,NRCOD/PGSIZ] ;SOURCE IN NRCOD IN SEC 0
	MOVE T2,[.FHSLF,,<SEC1,,NRCOD>/PGSIZ] ;DEST IS SEC1
	MOVE T3,[PM%CNT!PM%RD!PM%WR!PM%EX!PM%EPN+NRCODL-NRCODP+1]
	PMAP%
	IFJE.
	  TMSG <?Can't move NRCOD to section 1 because: >
	  JSERR
	  HALTF
	ENDIF.

	MOVX A,GJ%FOU+GJ%SHT	;GET NEXT VERSION OF MONITOR FILE
	HRROI B,MONSNM		;GET NAME TO SAVE AS
	GTJFN
	IFJE.
	  TMSG <?Can't make EXE file because: >
	  JSERR
	  HALTF			;NOTHING ELSE TO DO
	ENDIF.
	PUSH P,A
	TMSG <
Saving monitor as >
	MOVEI A,101
	HRRZ B,0(P)
	SETZ C,
	JFNS
	MOVE A,SYMFU		;BEGINNING OF SYMBOL TABLE
	MOVEI B,INCODZ		;END OF INIT CODE
	IORI B,777		;END OF THAT PAGE
	CAMLE A,B		;SYMS ON SAME PAGE AS INCOD?
	JRST BUGEN2		;NO, PROCEED
	AOS A,B			;YES, START AT FIRST PAGE AFTER INIT CODE
	MOVEM A,SYMFU		;STORE FOR SSEG MACRO BELOW

BUGEN2:	POP P,A
	HRLI A,.FHSLF		;CONSTRUCT  FORKH,,JFN  FOR SSAVE
	MOVEI B,1(P)		;BUILD SSAVE LIST ON STACK

DEFINE SSEG($START,$END)<
	XLIST
	..NSG==..NSG+2		;;COUNT STACK WORDS USED
	MOVN C,$END		;;GET LAST ADDRESS OF A REGION
	LSH C,-PGSFT		;;GET ENDING PAGE NUMBER
	MOVE D,$START		;;AND THE FIRST ADDRESS OF THE REGION
	LSH D,-PGSFT		;;AND BEGINNING PAGE NUMBER
	ADD C,D			;;COMPUTE NUMBER PAGES
	HRL C,C			;;PUT COUNT IN LEFT HALF
	HRRI C,SS%CPY!SS%RD!SS%EXE!SS%EPN
	PUSH P,C		;;BUILD BLOCK - COUNT, FLAGS
	PUSH P,D		;; - FIRST PAGE
	LIST
>
;USE THE ABOVE MACRO TO GENERATE AN ARGUMENT LIST ON THE STACK

	..NSG==0

	SSEG([EXP 0],[EXP RSCODZ])
	SSEG([EXP SZCOD],[EXP SZCODZ])
	SSEG([EXP INCOD],[EXP INCODZ])
	SSEG([EXP RSDAT],[EXP RSDATZ])
	SSEG(SYMFU,SYMLU)
	SSEG([EXP BGSTR],[EXP BGPTRZ])
	SSEG([EXP ERCOD],[EXP ERCODZ])
	SSEG([EXP PENCOD],[EXP PENCDZ])
	SSEG(<[SEC1,,NRCOD]>,<[SEC1,,NRCODZ]>)


SAVEND:	PUSH P,[0]		;TERMINATE LIST WITH 0
	SETZ C,
	SSAVE
	SUB P,[XWD ..NSG+1,..NSG+1] ;FLUSH ARG LIST FROM STACK
	TMSG <
>				;NOTE SUCCESSFUL COMPLETION
;ALL USEFUL STUFF HAS BEEN WRITTEN, FLUSH THIS ADR SPACE

	SETO T1,
	MOVE T2,[.FHSLF,,1]	;FLUSH PAGES 1-777
	MOVE T3,[1B0+777]
	MOVE 16,[CLRPRG,,5]	;THIS CODE WILL VANISH IN THE CLEARING,
	BLT 16,16		;SO PUT THE CLEAR LOOP IN THE AC'S
	JRST 5

CLRPRG:	PHASE 5
	PMAP
	HALTF
	JRST .-1
	DEPHASE
;JSYS ERROR

JSERM:	SAVET
	JRST JSERM0

JSEX0:	SAVET
	HRROI 1,[ASCIZ /
?JSYS ERROR: /]
	PSOUT
JSERM0:	MOVEI 1,101		;PRINT ERROR STRING ON PRIMARY OUTPUT,
	HRLOI 2,400000		; THIS FORK ,, LAST ERROR
	SETZ 3,
	ERSTR
	 JFCL
	 JFCL
	HRROI 1,[ASCIZ /
/]
	PSOUT
	RET

JSHLT0:	CALL JSEX0
	HALTF

OCTOUT:	SKIPA T3,[FLD(8,NO%RDX)]	;FREE FORMAT
OCTOUC:	MOVX 3,NO%LFL+FLD(12,NO%COL)+FLD(8,NO%RDX)	;10 COLUMNS
	MOVEI T1,.PRIOU		;PRIMARY OUTPUT
	NOUT
	 JSERR
	RET

;GTJFN AND OPEN FILE
;T1/ PTR TO ASCIZ FILE NAME

OUTFIL:	STKVAR <NAM,JFN>
	MOVE T2,T1
	MOVEM T2,NAM
	MOVX T1,GJ%FOU!GJ%SHT
	GTJFN
	IFJER.
	  RET
	ENDIF.
	MOVEM T1,JFN		;SAVE JFN
	MOVE T2,[FLD(7,OF%BSZ)+OF%WR]
	OPENF
	IFJER.
	  MOVE T1,JFN
	  RLJFN
	   NOP
	  RET
	ENDIF.
	RETSKP
;XBLT from,to,count

XBLT$:	BLSUB. <XBFRM,XBTO,XBCNT>
	SAVET
	MOVE T1,XBCNT
	MOVE T2,XBFRM
	MOVE T3,XBTO
	EXTEND T1,[XBLT]
	IFJER.
	  TMSG <
?XBLT failure, >
	  CALL JSERM
	  HALTF
	ENDIF.
	RET

SYMFU:	BLOCK 1			;FIRST WORD OF SYMBOL TABLE
SYMLU:	BLOCK 1			;LAST WORD OF SYMBOL TABLE
SYMTL:	BLOCK 1			;TOTAL LENGTH OF SYMTAB
RSTFU:	BLOCK 1			;RUNTIME SYMBOL TABLE LOC
RSTLU:	BLOCK 1			;LAST WORD OF RUNTIME SYMBOL TABLE
FPAGES:	BLOCK 1			;FREE PAGE COUNT
LTPGS:	BLOCK 1			;FREE PAGES AT LINK TIME
BUGLEN:	BLOCK 1			;BUGSTRING+BUGPTR
BUGORG:	BLOCK 1			;COMPUTED BUG ORIGIN
NPOVL:	BLOCK 1			;NUMBER OF PAGES OF UNAVOIDABLE OVERLAP
NOVRFL:	BLOCK 1				;COUNT OF OVERFLOWS
MNENC:	BLOCK 1			;COMPUTED BOUNDARY
MAXCOD:	BLOCK 1			;LIMIT BELOW BOOT AND POSTCD
MAXERC:	BLOCK 1			;MAX END OF ERCOD
LNKJFN:	BLOCK 1			;JFN FOR NEW LINK CCL FILE
PARJFN:	BLOCK 1			;JFN FOR NEW PARAMETER FILE
SYTEND:	BLOCK 1			;COMPUTED SYM TABLE END
PSIDX:	BLOCK 1			;RUNNING INDEX TO PSECT TABLES
NPSEC==40			;MAX NUMBER PSECTS HANDLED
PSNAM:	BLOCK NPSEC		;PSECT NAMES
PSORG:	BLOCK NPSEC		;PSECT ORIGINS
PDL:	BLOCK NPDL


	TNXEND

PSTEND:	END SYSG0