;<134-TENEX>POSTLD.MAC;16    19-Jun-80 15:52:27    EDIT BY LYNCH
; AND MAKE ENTRY VECTOR KNOW ABOUT 140 CHANGE.
;<134-TENEX>POSTLD.MAC;16    17-Jun-80 17:06:43    EDIT BY LYNCH
; MAKE OVERFLOW OF KIUPTS VISIBLE.
;<134-TENEX>POSTLD.MAC;14    17-Jun-80 08:31:55    EDIT BY LYNCH
; MADE HASH TABLE STOP AT SWPMON (FOR TENEX INSTEAD OF TOPS20!)
;<134-TENEX>POSTLD.MAC;11    30-May-80 22:27:34    EDIT BY PETERS
; Don't flush no-output symbols (else we lose all the stuff in PARAMS)
;DSK:<PEFMON>POSTLD.MAC;14 13-May-80 17:51:13, Edit by FRENCH
;MERGED 134-TENEX AND SRI VERSION FOR FAST SYMBOL DIDDLING AND
;GOOD BOUNDRY CHECKING
;<134-TENEX>POSTLD.MAC;5    22-Jan-79 20:27:35    EDIT BY PLUMMER
;1 New version from BBN, with a few SRI local mods.
;<135-TENEX>POSTLD.MAC.120, 19-Nov-78 13:02:22, EDIT BY JBORCHEK
;REMOVE DEFINITION OF DDT. IS IN EDDT
;[BBN-TENEXD]<135-TENEX>POSTLD.MAC.119,  7-Jul-78 11:51:47, Ed: PLUMMER
;[BBN-TENEXD]<ITP>POSTLD.MAC.121, 22-Jun-78 14:35:02, Ed: PLUMMER
; MAKE SWPF BE END OF SWPMON RATHER THAN SWPMA0+LH(.JBHRL), WHICH INCLUDES
; THE SYMBOL TABLE.
;[BBN-TENEXD]<ITP>POSTLD.MAC.119, 22-Jun-78 11:21:25, Ed: PLUMMER
; Check overlaps with High Storage area
; Flush AC definitions which come out of PROLOG
;[BBN-TENEXD]<135-TENEX>POSTLD.MAC.118, 18-May-78 15:57:05, Ed: ALLEN
;[BBN-TENEXD]<135-TENEX>POSTLD.MAC.117,  7-May-78 22:57:54, EDIT BY PLUMMER
; Merge
;[BBN-TENEXD]<135-DEBUG>POSTLD.MAC.117,  1-May-78 11:15:00, EDIT BY PLUMMER
; MAKE STORAGE OVERLAP MESSAGES GIVE BATCH ERRORS IF APPROPRIATE
;<135-TENEX>POSTLD.MAC.116    12-Jan-78 22:57:33    EDIT BY PLUMMER
; FIX BUG AT END OF PLD2 -- PMAP COUNT OPTION NOT ON TENEX
;<135-TENEX>POSTLD.MAC.115    15-Nov-77 00:43:34    EDIT BY PLUMMER
; ADD WARNING IF POSTLD TOO BIG
; CRLF AFTER NAME OF MONSYMS FILE PRINTED
;<135-TENEX>POSTLD.MAC.111    28-Aug-77 20:35:41    EDIT BY ALLEN
;<135-TENEX>POSTLD.MAC.110    27-Aug-77 14:31:18    EDIT BY ALLEN
;<135-TENEX>POSTLD.MAC.109    27-Aug-77 14:20:42    EDIT BY ALLEN
;<135-TENEX>POSTLD.MAC.108    27-Aug-77 12:11:22    EDIT BY ALLEN
;<135-TENEX>POSTLD.MAC.107    27-Aug-77 12:10:48    EDIT BY ALLEN
;<135-TENEX>POSTLD.MAC.106    27-Aug-77 12:04:48    EDIT BY ALLEN
;<135-TENEX>POSTLD.MAC.105    27-Aug-77 12:02:56    EDIT BY ALLEN
;<135-TENEX>POSTLD.MAC.104    27-Aug-77 11:53:56    EDIT BY ALLEN
;<135-TENEX>POSTLD.MAC.103    26-Aug-77 17:38:23    EDIT BY OPERATOR
;<135-TENEX>POSTLD.MAC.102    26-Aug-77 16:18:42    EDIT BY ALLEN
;<135-TENEX>POSTLD.MAC.101    26-Aug-77 15:58:03    EDIT BY ALLEN
; ADOPT SYMBOL CRUNCHING STRATEGY OF TOPS20 POSTLD
;<135-TENEX>POSTLD.MAC.99    25-Aug-77 17:54:22    EDIT BY ALLEN
;<135-TENEX>POSTLD.MAC.98    11-Aug-77 10:07:19    EDIT BY ALLEN
; DON'T ASK WHETHER TO REMOVE SYMBOLS -- JUST DO IT
;<135-TENEX>POSTLD.MAC.97    11-Aug-77 09:39:18    EDIT BY ALLEN
; FIXES TO PMAPS FOR OPERATION UNDER TOPS20. ALSO VECTOR PREVIOUSLY AT 100
; NOW AT 140
;<135-TENEX>POSTLD.MAC;96    27-May-76 13:19:42    EDIT BY PLUMMER
;<AIM>POSTLD.MAC;3    27-May-76 12:55:13    EDIT BY PLUMMER
; HASH TABLE USED TO MAKE SYMBOL CRUNCHER FAST
;<135-TENEX>POSTLD.MAC;95    22-JAN-76 16:36:09    EDIT BY ROSENBERG
; REPLACE THE TEXT "SWP VARS" WITH "SWP PAGE VARS" WHERE LATTER INTENDED
;<135-TENEX>POSTLD.MAC;94     8-JAN-76 12:29:30    EDIT BY ROSENBERG
; SET "STADMN" (IN LOGJS) TO DATE POSTLD IS BEING RUN
;<135-TENEX>POSTLD.MAC;93     5-DEC-75 13:53:43    EDIT BY ROSENBERG
; REPLACE THE LIST OF MODULES (CONSIDERED FOR SYMBOL DELETION)
; WITH A CALL TO THE "%TENX%" MACRO DEFINED IN PROLOG
;<134-TENEX>POSTLD.MAC;92     5-AUG-75 11:40:33    EDIT BY CLEMENTS
; CHANGE "P2" TO "PATCH2", TO AVOID CONFLICT WITH NEW AC NAME
;<134-TENEX>POSTLD.MAC;91     8-APR-75 22:32:58    EDIT BY CLEMENTS
; SYMBOL DELETER KNOWS JSYS WAS SPLIT UP
;<134-TENEX>POSTLD.MAC;90    13-MAR-75 21:55:13    EDIT BY PLUMMER
; BADSPOT READER APPENDS TO DRMBBT AS ASSEMBLED AND IGNORES DUPLICATES
;<134-TENEX>POSTLD.MAC;89    12-MAR-75 22:40:30    EDIT BY PLUMMER
;<134-TENEX>POSTLD.MAC;88    12-MAR-75 22:17:14    EDIT BY PLUMMER
;<134-TENEX>POSTLD.MAC;87    12-MAR-75 22:07:51    EDIT BY PLUMMER
; ADDED DRUM BAD SPOTS FROM FILE FEATURE
;<133-TENEX>POSTLD.MAC;86     3-OCT-74 13:19:55    EDIT BY CLEMENTS
; MAKE SYMBOL CRUNCHER HALF-KILL LOCALS 0-777 AND ALL 20-777 .
;<133-TENEX>POSTLD.MAC;85    25-SEP-74 14:05:59    EDIT BY CLEMENTS
; REMOVED UPDATING VERSIO.MAC FROM POSTLOD. NOW DONE BY NEWVER.SAV.
;  MUST BE DONE MANUALLY. THIS IS AN ADDED JOB FOR THE SYSTEM GURU, BUT
;  IT SAVES VERSION NUMBERS FOR LOADS THAT YOU DECIDE TO SCRAP.
;<TENEX-132>POSTLD.MAC;83     9-MAY-74 19:35:47    EDIT BY CLEMENTS

	SEARCH PROLOG,STENEX,MACSYM

	TITLE POSTLD


;DEFS EXPECTED TO BE FOUND IN MONSYM

T1==1
T2==2
T3==3
T4==4

.PRIOU==101
.FHSLF==400000

	BLOCK 40	;LEAVE SOME SPACE AFTER LAST PROG
RESEND:			;DEFINES END OF CODE, SYMTAB MOVED TO HERE

	SWAPCD
SWPF:			; DEFINE SWAPPABLE PATCH SPACE


	LOC 4000	;GET THIS CODE OUT OF THE WAY

;POST-LOADING ONE-SHOT INIT

DEFINE JSERR <
	JSP T2,JSEX0>

;BIT DEFINITIONS IN SYMBOL TABLE ENTRIES

SYMDOB==1B0			;DELETE OUTPUT
SYMDIB==1B1			;DELETE INPUT
SYMLOC==1B2			;LOCAL
SYMGLO==1B3			;GLOBAL
SYMBLK==SYMLOC!SYMGLO		;BLOCK
;NO BITS - PROGRAM NAME

;VARIOUS DEFS FROM TOPS20 PROLOG
PGSFT==^D9
EXTERN	.JBHRL,.JBREL,.JBSA,.JBFF,.JBSYM,.JBUSY

	INTERN RESEND,SWPF

	EXTERN MONCOR,SYSGO1,WMST,SWPSTP,SWPCOR,DDTX,SWCEND,SVN,SVNUM
	EXTERN PATCH2

SYSG0:	MOVE P,[IOWD 40,PDL]
	JRST SYSG1		;1 Ignore maps

	MOVSI 1,100001		; OLD FILE & STRING SHORT FORM
	HRROI 2,[ASCIZ /MAP.MAP/]
	GTJFN			; GET JFN FOR LOADER MAP
	 JRST NOMAP		; NONE
	PUSH P,1		; SAVE IT
	MOVE 1,SVNUM
	HRLI 1,400001		; FOR OUTPUT & STRING SHORT FORM
	HRROI 2,[SYSNAM(<ASCIZ \LOADER-MAP.>,<\>)]
	GTJFN			; GET JFN FOR LOADER-MAP.SYSTEM
	 JRST [	POP P,1
		RLJFN
		 JFCL
		JRST NOMAP]
	MOVE 2,1
	POP P,1
	RNAMF			; RENAME MAP
	 JFCL
	MOVE 1,2
	RLJFN
NOMAP:	 JRST [	HRROI 1,[ASCIZ /
Loader map not renamed.
/]
		PSOUT
		JRST .+1]
SYSG1:				;1
;;;;;;;	PUSHJ P,SMDSKA		;SETUP DSK RELOAD ADDRESSES
	MOVEI T2,SWPF		;END OF SWAPPABLE MON
	HRRM T2,.JBHRL		;MAKE IT BE DEFINED END OF HISEG
	HRRZ T2,.JBHRL
	SUBI T2,1
	LSH T2,-PGSFT
	MOVEM T2,SWCEND
	MOVEI 1,101
	MOVEI 3,^D8
	NOUT
	JFCL
	HRROI 1,[ASCIZ / is last page of swappable code.
/]
	PSOUT

; PRINT SPACE REMAINING BETWEEN BOUNDARIES

	hrroi 1,[asciz /
Space remaining between monitor map areas:
/]
	psout
	hrroi 1,[asciz /
Resident variables and resident monitor = /]
	psout
	movei 2,resma0
	subi 2,resvlc##
	call octot
	hrroi 1,[asciz /
Per-processor storage and swappable variable storage = /]
	psout
	movei 2,nresbg
	subi 2,pprma
	subi 2,nrspg*1000
	call octot
	hrroi 1,[asciz /
Swappable variable storage and dump buffer storage = /]
	psout
	movei 2,ioxbuf
	subi 2,nreslc##
	call octot
	hrroi 1,[asciz /
Dump buffer storage and bug table storage = /]
	psout
	movei 2,bugtab
	subi 2,ioxbuf
	subi 2,ndump*1000
	call octot
	hrroi 1,[asciz /
Bug table storage and swappable monitor = /]
	psout
	movei 2,swpma0
	subi 2,bugtab
	subi 2,sbugtf
	call octot
	hrroi 1,[asciz /
Swappable monitor and disk bit table = /]
	psout
	movei 2,dskfct
	hlrz 3,.jbhrl
	addi 3,swpma0
	sub 2,3
	call octot
	hrroi 1,[asciz /
Disk bit table and swappable page variables = /]
	psout
	movei 2,nrplbg
	subi 2,dskfct
	subi 2,dskbsz##
	call octot
	hrroi 1,[asciz /
Swappable page variables and mddt = /]
	psout
	movei 2,mddt
	subi 2,nrploc##
	call octot
	hrroi 1,[asciz /
Jsb storage and jfn storage = /]
	psout
	movei 2,jfnpc0
	subi 2,jsbloc##
	call octot
	hrroi 1,[asciz /
Psb storage and ac blocks = /]
	psout
	movei 2,uacb
	subi 2,tsbloc##
	call octot
	CALL CRLF
	GTAD
	SETCM 2,1
	JUMPE 2,[ HRROI 1,[ASCIZ /
The system doesn't have the time and date!
/]
		  PSOUT
		  JRST NOTIME]
	ANDCMI 1,-1		;ZERO OUT TIME OF DAY (IN RH OF AC1)
;;	SUB 1,STADMN
;;	ADDM 1,STADMN		;MAKE MINIMUM GTAD = NOW
;;	ADDM 1,STADMX		;AND INCREASE STADMX  BY THE SAME AMOUNT
NOTIME:	JRST RRS		;DO COMPRESSIONS

OCTOT:	MOVEI 1,101
	MOVEI 3,8
	NOUT
	 JFCL
	RET


;REMOVE REDUNDANT SYMBOLS FROM TABLE
;SYMTAB IS SCANNED.  EACH SYMBOL TO BE RETAINED IS ENTERRED INTO
; THE (TEMPORARY) HASH TABLE WITH A "VALUE" OF ITS POSITION IN THE
; MAIN SYMTAB.  SUBSEQUENT NAMES ARE LOOKED UP IN THE HASH TABLE
; TO SEE F THE SYMBOL HAS ALREADY BEEN SEEN; IF SO, THE ORIGINAL
; OCCURRENCE IS GLOBALIZED AND THE CURRENT ONE DELETED.
; SYMBOLS BEGINNING OR ENDING WITH  $  OR  %  ARE DELETED BECAUSE THEY WERE
;  MOST LIKELY GENERATED BY MACROS, ETC.

;AC USAGE:

SP=7	; SCAN POINTER
CT=10	; COUNTER
X=11	; USED IN HASHING
HP=12	; HASH TABLE POINTER
HC=13	; HASH TABLE COUNTDOWN
HO=14	; HASH TABLE ORIGIN
HL=15	; HASH TABLE LENGTH

RRS:	HRROI T1,[ASCIZ /

Symbol table length as assembled = /]
	PSOUT
	CALL LENOUT		; PRINT THE LENGTH IN OCTAL
	CALL CRLF

	SETZM NAMFCT#		; INIT COUNTERS OF
	SETZM LCLFCT#		; SYMBOLS FLUSHED
	SETZM DUPFCT#		; FOR VARIOUS REASONS

	HLRE HL,.JBSYM		; # WORDS IN SYMTAB (2 * # SYMBOLS)
	MOVNS HL		; MAKE HASH TABLE TWICE AS BIG
	HRRZ HO,.JBSYM		; SYMTAB IS HIGHEST THING IN MEMORY
	ADDI HO,<1_PGSFT>(HL)	; ROUND UP TO FIRST FREE PAGE ADDRESS
	ANDI HO,-1_PGSFT	; AND SAVE THAT AS HAST TABLE ORIGIN
	HRLZ T1,HO		; SETUP TO CLEAR IT
	HRRI T1,1(HO)
	HRRZ T2,HL
	ASH T2,1		; TWO WORD ENTRIES
	ADD T2,HO		; LAST ADDRESS PLUS ONE
	TRNE T2,400000		; DON'T OVERFLOW INTO SWPMON.
	 MOVEI T2,400000
	MOVE HL,T2		; GET A COPY OF THE END ADDRESS PLUS ONE
	SUB HL,HO		; RECOMPUTE # OF WORDS IN HASH TABLE
	ASH HL,-1		; NUMBER OF ENTRIES
	SETZM -1(T1)		; CLEAR FIRST WORD
	BLT T1,-1(T2)		; CLEAR REST OF TABLE

; MAIN SCAN -- DECIDE IF SYMBOL SHOULD BE DELETED.  0 IT IF SO.

RRS09:	SKIPL SP,.JBSYM		; GET SYMTAB POINTER, SKIP THE AOBJP
RRS1:	AOBJP SP,RRS8		; JUMP IF DONE
	MOVE T1,0(SP)		; GET RADIX 50 SYMBOL

;;;;;;;	TXZ T1,<SYMDIB!SYMDOB!SYMGLO!SYMLOC> ; CLEAR FLAGS
	TLZ T1,(SYMDIB!SYMDOB!SYMGLO!SYMLOC) ;SO DON'T NEED MACSYM

	IDIVI T1,50		; GET LAST CHARACTER
	CAIE T2,<RADIX50 0,$>	; CHECK FOR ENDING IN $
	CAIN T2,<RADIX50 0,%>	; OR %
	 JRST [	SETZM 0(SP)	; YES. DELETE IT.
		AOS NAMFCT	; COUNT UP STATISTICS CELL
		AOBJN SP,RRS1]	; GO LOOK AT NEXT
	JUMPE T1,RRS0		; JUMP IF SINGLE CHARACTER SYMBOL
	IDIVI T1,50		; GET NEXT CHARACTER
	JUMPN T1,.-1		; JUMP IF NOT LEFT MOST ONE
	CAIE T2,<RADIX50 0,$>	; CHECK FOR BEGINNING WITH $
	CAIN T2,<RADIX50 0,%>	; OR %
	 JRST [	SETZM 0(SP)	; DELETE IT
		AOS NAMFCT	; COUNT IT
		AOBJN SP,RRS1]	; TRY NEXT

RRS0:	MOVE T1,0(SP)		; GET SYMBOL AGAIN

;;;;;;;	TXCE T1,SYMBLK		; PROGRAM NAME OR
;;;;;;;	TXCN T1,SYMBLK		; BLOCK NAME?
	TLCE T1,(SYMBLK)	;SO DON'T NEED MACSYM
	TLCN T1,(SYMBLK)

	 AOBJN SP,RRS1		; YES, KEEP SYMBOL (ALWAYS JUMP)
;	SKIPN LOCSF		; FLUSH LOCAL SYMBOLS?
;	TXNN T1,SYMLOC		; AND THIS IS A LOCAL?

;;;;;;;	TXNE T1,SYMDIB!SYMDOB	;1 OR NO-INPUT/NO-OUTPUT SYMBOL?
	TLNE T1,(SYMDIB)	;SO DON'T NEED MACSYM

	 JRST [	SETZM 0(SP)	; YES.  DELETE THIS SYMBOL
		AOS LCLFCT	; COUNT STATISTICS CELL
		AOBJN SP,RRS1]	; ALWAYS JUMP
	SKIPL T2,1(SP)		; GET VALUE
	CAIL T2,1000		; VALUE 0-777?
	 JRST RRS4		; NO
	CAIL T2,20		; 0-17 RANGE?
	 JRST RRS2		; NO.  20-777

;;;;;;;	TXNN T1,SYMGLO		; GLOBAL AC NAME?
	TLNN T1,(SYMGLO)	; SO DON'T NEED MACSYM

	 AOBJN SP,RRS1		; NO.  LET IT ALONE (ALWAYS JUMPS)
	JRST RRS4		; YES.  PROCESS NORMALLY.
RRS2:
;;;;;;;	TXO T1,SYMDOB		; MAKE NO-OUTPUT.
	TLO T1,(SYMDOB)		; SO DON'T NEED MACSYM

	MOVEM T1,0(SP)		; AND STORE BACK

; HERE SYMBOL AT 0,1(SP) IS TO BE RETAINED IF FIRST OCCURENCE OR
; DELETED IF 2ND,... WITH THE FIRST OCCURENCE GETTING GLOBALIZED

RRS4:	MOVE X,T1		; COPY OF SYMBOL NAME

;;;;;;;	TXZ X,<SYMDIB!SYMDOB!SYMLOC!SYMGLO>	; FLUSH BITS
	TLZ X,(SYMDIB!SYMDOB!SYMLOC!SYMGLO)	; SO DON'T NEED MACSYM

	MULI X,400003		; HASH IT
	ROTC X,7		; SOME MORE
	XOR X,X+1		; STILL MORE
	LSH X,-1		; FLUSH SIGN BIT
	IDIV X,HL		; RELATIVE PROBE TO HP (=X+1)
	ASH HP,1		; DOUBLE FOR 2-WORD ENTRIES
	ADD HP,HO		; FORM ABSOLUTE PROBE

	MOVE HC,HL		; INIT THE COUNTDOWN
RRS5:	SKIPN T3,0(HP)		; FREE SLOT?
	 JRST [;;;;;;;	TXZ T1,<SYMLOC!SYMGLO>
			TLZ T1,(SYMLOC!SYMGLO) ;SO DONT NEED MACSYM

		MOVEM T1,0(HP)	; ENTER IN HASH TABLE (1ST TIME SEEN)
		HRRZM SP,1(HP)	; VALUE IS LOCATION IN SYMTAB
		AOBJN SP,RRS1]	; MOVE ON TO NEXT SYMBOL
	MOVE T4,1(HP)		; LOC OF ORIGINAL DEF IN SYMTAB
	CAME T2,1(T4)		; COMPARE VALUES
	 JRST RRS6		; DIFFERENT.  DON'T BOTHER WITH NAMES
	XOR T3,T1		; COMPARE NAMES

;;;;;;;	TXNN T3,<-1-<SYMDIB!SYMDOB!SYMLOC!SYMGLO>>	; BUT NOT BITS
	TDNN T3,[-1-<SYMDIB!SYMDOB!SYMLOC!SYMGLO>]	;SO DON'T NEED MACSYM

	 JRST [	SETZM 0(SP)	; ANOTHER OCCURENCE OF SYM -- KILL IT
		AOS DUPFCT	; COUNT STATISTICS
		MOVE T4,0(HP)	; GET COPY IN HASH TABLE

;;;;;;;		TXOE T4,SYMGLO	; ALREADY GLOBALIZED?
		TLOE T4,(SYMGLO) ;SO DON'T NEED MACSYM

		 AOBJN SP,RRS1	; YES.  AVOID PAGE FAULT.  ALWAYS JUMPS.
		MOVEM T4,@1(HP)	; STORE BACK INTO MAIN SYMTAB
		MOVEM T4,0(HP)	; AND HASH TABLE WITH FLAG SET
		AOBJN SP,RRS1]	; AND MOVE ON
RRS6:	SUBI HP,2		; COLLISION, TRY NET SLOT
	CAML HP,HO		; NEED TO RING POINTER?
	 JRST .+3		; NO
	ADD HP,HL		; NOTE 2-WORD ENTRIES
	ADD HP,HL
	SOJG HC,RRS5		; GO SEE IF THIS IS RIGHT
	HRROI T1,[ASCIZ /
? Symbol table too big to crunch
/]
	PSOUT
	HALTF


;SYMTAB NOW READY TO BE COMPACTED.

RRS8:	MOVE 1,.JBSYM
	MOVEM 1,SWPSTP		;PUT POINTER WHERE WMST WILL SEE IT
	JSP 4,WMST		;WRITE SYMBOL TABLE ONTO FILE
	CALL CRLF
	CALL CRLF
	SETZM SWPSTP
	MOVE T2,NAMFCT
	CALL OCTOUT
	HRROI T1,[ASCIZ / Symbols beginning or ending with $ or % flushed.
/]
	PSOUT
	MOVE T2,LCLFCT
	CALL OCTOUT
	HRROI T1,[ASCIZ / Local or no-input symbols flushed.
/]
	PSOUT
	MOVE T2,DUPFCT
	CALL OCTOUT
	HRROI T1,[ASCIZ / Duplicate symbols flushed.
/]
	PSOUT

RRS9:	MOVE SP,.JBSYM		;SCAN TABLE AND COMPACT
	MOVEI 6,0(SP)		;WILL BE NEW TABLE POINTER
SS5:	SKIPN T1,0(SP)		;DELETED?
	JRST SS4		;YES
	MOVEM T1,0(6)
	MOVE T1,1(SP)
	MOVEM T1,1(6)
	ADD 6,[-2,,2]		;MOVE TO NEW POSITION
SS4:	AOBJN SP,.+1
	AOBJN SP,SS5
	HLLM 6,.JBSYM		;STORE NEW COUNT
	HRLM 6,.JBSA		;STORE NEW END
	HRRM 6,.JBFF
	HRREI CT,-MAXSYM(6)	; BEGIN TO COMPUTE AMOUNT OF OVERLAP IF ANY
	ADDI CT,RESEND		; SHOULD BE ABLE TO DO THIS IN ABOVE INSTRUCTION
				; BUT MACRO BLOWS UP!!
	HRRZ T1,.JBSYM		; ORIGIN OF SYMBOL TABLE
	SUBI CT,(T1)		; COMPLETE OVERLAP COMPUTATION
	HRROI T1,[ASCIZ /

Removing symbols for:
/]
	PSOUT
	SETZM FORCE#		; DON'T USE EXTRA FORCE YET
	MOVSI 16,-NPNMS		;SETUP TO REMOVE CERTAIN PRG SYMBOLS
SR1:	SKIPGE PNAMES+1(16)	;THIS AN ALWAYS REMOVE?
	JUMPLE CT,SR3		; NO, IF NO OVERLAP, THEN DONE
	CALL CSS		;STILL ALWAYS REMOVE OR STILL OVERLAP
	AOBJN 16,.+1
	AOBJN 16,SR1
	JUMPLE CT,SR3
	HRROI T1,[ASCIZ /
% /]
	PSOUT
	MOVE T2,CT
	ASH T2,-1
	CALL DECOUT		; PRINT T2 AS DECIMAL
	HRROI T1,[ASCIZ /. TOO MANY SYMBOLS (ABOVE MAXSYM).
  ADD MORE MODULES TO PN TABLE AND REBUILD.  KILLING THE FOLLOWING
  PROGRAM BLOCKS IN ORDER TO MAKE A USEFUL MONITOR IMAGE:
/]
	PSOUT

	SETOM FORCE#		; INDICATE BIG HAMMER MODE IN EFFECT
	MOVSI 16,-NPNMS		; SET TO SCAN PROGRAM NAME TABLE AGAIN
SR2:	JUMPLE CT,SR3		; GET OUT IF ENOUGH SPACE NOW
	SKIPGE PNAMES+1(16)	; DELETED ON FIRST PASS?
	 CALL CSS		; NO.  DO IT NOW.
	AOBJN 16,.+1
	AOBJN 16,SR2
	JUMPLE CT,SR3		; AVOID ERROR MSG IF WE WON
	HRROI T1,[ASCIZ /
? SYMBOL TABLE CANNOT BE MADE TO FIT.  (SOMETHING IS VERY WRONG!)
/]
	PSOUT
  	HALTF

SR3:	CALL FIXLEN		;FIXUP LENGTH OF PROGRAM BLOCKS

;MOVE SYMBOL TABLE FROM END OF HIGHSEG TO END OF LOWSEG

	MOVEI T1,RESEND		;SETUP NEW LOC OF SYMTAB
	HLRE T2,.JBUSY		;GET LENGTH OF UNDEF SYMTAB
	JUMPGE T2,PLD2		;JUMP IF NO UNDEF TABLE
	HRLZ T3,.JBUSY		;SETUP BLT PTR - SOURCE
	HRRM T1,.JBUSY		;STORE NEW LOC OF USY
	HRR T3,T1		;BLT PTR - DEST
	SUB T1,T2		;CALC FINAL ADR (ORG-(-LENGTH))
	BLT T3,-1(T1)		;MOVE UNDEF SYMTAB TO RES AREA
PLD2:	HLRE T2,.JBSYM		;GET LENGTH OF SYMTAB
	HRLZ T3,.JBSYM		;SET BLT PTR - SOURCE
	HRRM T1,.JBSYM		;STORE NEW LOC OF SYMTAB
	HRR T3,T1		;BLT PTR - DEST
	SUB T1,T2		;CALC FINAL ADR (ORG-(-LENGTH))
	BLT T3,-1(T1)		;MOVE SYMTAB TO RES AREA
	HRRZM T1,.JBFF		;SET END OF LOW CODE
	HRLM T1,.JBSA
	HRROI T1,[ASCIZ /
Final symbol table length = /]
	PSOUT
	CALL LENOUT
	CALL CRLF

;REMOVE PAGES AFTER SWPMON WHERE SYMTAB AND HASH TABLE WERE

	SETO T1,
	MOVE T2,SWCEND
	ADD T2,[.FHSLF,,1]	;START WITH PAGE AFTER SWCEND
	MOVEI T3,1000		; TO TOP OF MEMORY
	SUBI T3,0(T2)		;COMPUTE NUMBER PAGES
;;;;	HRLI T3,(PM%CNT)
	PMAP
	ADDI T2,1	;FOR TENEX
	SOJG T3,.-2	;FOR TENEX

FIXSYM:	MOVE 1,.JBSYM
	MOVEM 1,36
	MOVE 1,.JBUSY
	MOVEM 1,32
	MOVEM 1,SAVE32##	; PUT IN SEMI-CONSTANT
	HLRZ 1,.JBHRL		; GET HIGH SEG BREAK
	ADDI 1,SWPMA0		; BASE PLUS LENGTH
	IORI 1,1777		; MOVE TO 1K BOUND
	MOVEM 1,.JBREL		; SET .JBREL
	SETZM .JBHRL
	MOVEI 2,DDTX		;START OF EDDT
	ADDI 2,777
	LSH 2,-^D9
	MOVEM 2,MONCOR		;END OF MONITOR CORE
	MOVE 2,[JRST DDTX]	;SETUP EDDT DISPATCH
	MOVEM 2,140
	MOVEI 2,146		; BUT POINT TO START FOR PRODUCTION SYSTEMS.
	HRRM 2,.JBSA
	MOVEI 1,400000
	SEVEC

;SORT THE BUG TABLE BY BUG ADDRESS

	MOVSI 7,-NBUGP
BUGSR4:	MOVSI 5,-NBUGP(7)	;SCAN FROM HERE TO END
	HRRI 5,0(7)
	MOVSI 3,1		;INITIAL MIN
BUGSR1:	HLRZ 1,STRBGP(5)	;BUG ADDRESS
	JUMPE 1,BUGSR2		;IGNORE ZEROS
	CAML 1,3		;MIN SO FAR?
	JRST BUGSR2		;NO
	MOVEI 3,0(1)		;YES, REMEMBER VALUE
	MOVEI 4,0(5)		;AND LOCATION
BUGSR2:	AOBJN 5,BUGSR1
	TLNE 3,-1		;FOUND A MIN?
	JRST BUGSR3		;NO, NOTHING BUT ZEROS LEFT
	MOVE 1,STRBGP(4)	;INTERCHANGE MIN WITH TOP OF TABLE
	EXCH 1,STRBGP(7)
	MOVEM 1,STRBGP(4)
	AOBJN 7,BUGSR4

;DUMP BUG TABLE AND STRINGS TO FILES

BUGSR3:	MOVEI 7,0(7)
	MOVNM 7,NBUGTP		;SAVE NEG OF NUMBER OF PTRS
	HRRZ 1,SVNUM		; USE SYSTEM VERSION NUMBER
	HRLI 1,(1B0+1B17)	; FOR OUTPUT AND STRING SHORT FORM
	HRROI 2,[SYSNAM(<ASCIZ \BUGSTRINGS.>,<\>)]
	GTJFN
	0
	MOVE 2,[7B5+1B20]
	OPENF
	0
	SETZ 3,
	HRROI 2,SVN		;SYSTEM VERSION TEXT
	SOUT
	HRROI 2,[ASCIZ /
BUGHLT, BUGCHK, AND BUGNTE LOCATIONS AND DESCRIPTIONS

/]
	SOUT
	MOVEI 5,STRBGP		;MOVE AND COMPACT STRINGS TO
	SUB 5,NBUGTP		;AREA IMMEDIATELY AFTER POINTERS
	MOVEI 4,1(5)		;CLEAR THE AREA FIRST
	HRLI 4,0(5)
	SETZM 0(5)
	BLT 4,STRBGP+SBUGTF-1
	HRLZ 7,NBUGTP
BUGD1:	MOVE 6,STRBGP(7)	;TABLE ENTRY?
	HLRZ 2,6		;ADDRESS
	MOVE 3,[1B2+6B17+10B35]	;OCTAL PRINT, USE EXACTLY 6 COLUMNS
	NOUT
	0
	MOVEI 2," "
	BOUT
	HRROI 2,0(6)
	SETZ 3,
	SOUT			;PRINT THE STRING
	HRROI 2,[ASCIZ /
/]
	SOUT

	HRRM 5,STRBGP(7)	;SET NEW ADDRESS OF STRING
BUGD3:	MOVE 2,0(6)		;MOVE STRING TO COMPACTING AREA
	MOVEM 2,0(5)
	ADDI 5,1
	TRNE 2,177B34		;UNTIL (LAST) CHAR OF 0 ENCOUNTERED
	AOJA 6,BUGD3
BUGD2:	AOBJN 7,BUGD1
	CLOSF
	0
	MOVE 1,SVNUM
	HRLI 1,(1B0+1B17)
	HRROI 2,[SYSNAM(<ASCIZ \BUGTABLE.>,<\>)]
	GTJFN
	0
	MOVE 2,[44B5+1B20]
	OPENF
	0
	MOVE 2,NBUGTP		;COUNT GOES OUT FIRST
	BOUT
	HRLZ 7,NBUGTP
	MOVE 2,STRBGP(7)
	SUBI 2,STRBGP		;MAKE STRING POINTERS RELATIVE
	BOUT
	AOBJN 7,.-3
	MOVM 7,NBUGTP
	HRLI 7,-SBUGTF(7)
	MOVE 2,STRBGP(7)
	BOUT			;OUTPUT STRINGS
	AOBJN 7,.-2
	CLOSF
	0


SYSG01:	MOVE 3,.JBSYM		;MOVE POINTER TO EXEC DDT LOCATION
	MOVEM 3,36
	MOVEM 3,SAVE36##	;PUT IN SEMI-CONSTANT
	HRRZ 3,.JBFF		;END OF SYMTAB
	ADDI 3,777		;ADJUST TO NEXT PAGE BOUNDARY
	LSH 3,-^D9		;NUMBER OF FIRST PAGE AFTER SYMTAB
	MOVEM 3,SWPCOR
	MOVEM 3,RCADDT##	;PUT IN SEMI-CONSTANT
	HRROI 1,[ASCIZ /
SWPCOR= /]
	PSOUT
	MOVEI 1,101
	MOVE 2,3
	MOVEI 3,^D8
	NOUT
	0
	HRROI 1,[ASCIZ /
/]
	PSOUT
IFN KIFLG,<
	MOVEI 2,PPRMPG		; START OF GOD'S AREA
	SUBI 2,NUPT		; TAKE AWAY KI UPT SPACE
	SUB 2,SWPCOR
	JUMPGE 2,SWPOK
	HRROI 1,[ASCIZ /
Too many KIUPTS - reduce NUPT by /]
	PSOUT
	MOVEI 1,101
	MOVNS 2
	MOVEI 3,12
	NOUT
	 0
	HRROI 1,[ASCIZ /
/]
	PSOUT
SWPOK:
>
	SETO 1,
	MOVE 4,SWPCOR
	SUBI 4,SWPMP0
	HRLZS 4
	HRR 4,SWPCOR
	MOVSI 2,400000
	SETZ 3,
	HRR 2,4
	PMAP
	AOBJN 4,.-2
	MOVEI 4,PATCH2
	LSH 4,-^D9		;FIRST PAGE OF RES MON
	MOVNI 4,-2(4)
	HRLZS 4
	HRRI 4,2
	MOVE 16,[CLRPRG,,5]
	BLT 16,16
	JRST 5

CLRPRG:	PHASE 5
	SETZ 3,
	HRR 2,4
	PMAP
	AOBJN 4,.-2
	HALTF
	JRST .-1
DEPHASE

;PROGRAM AND BLOCK NAMES TO FLUSH LOCAL SYMS

	DEFINE PN (NAME,NSTRNG,WHEN<-1>),<
	IFLE WHEN,<
	RADIX50 0,NAME
	XWD WHEN,[ASCIZ /NAME/]
>>

; THE MACRO "%TENX%" CONTAINS THE LIST OF TENEX MODULES IN THE ORDER
; IN WHICH THEIR SYMBOLS ARE TO BE DELETED TO REDUCE THE SIZE OF THE
; SYMBOL TABLE. EACH ENTRY HAS THREE ARGUMENTS, AS FOLLOWS:
; FIRST ARGUMENT: MODULE (OR BLOCK) NAME
; SECOND ARGUMENT: NOT USED HERE (USED TO DEFINE BUGSTRING SYMBOLS)
; THIRD ARGUMENT: +1 MEANS DON'T DELETE ANY SYMBOLS FROM THIS MODULE
;                          (OR BLOCK)
;                  0 MEANS DELETE ALL SYMBOLS (BOTH LOCAL AND GLOBAL)
;                          FROM THIS MODULE, WHETHER OR NOT IT IS
;                          NECESSARY TO REDUCE THE SIZE OF THE SYMBOL
;                          TABLE
;                 -1 MEANS DELETE ONLY LOCAL SYMBOLS FROM THIS MODULE,
;                          AND ONLY DO IT IF IT IS NECESSARY TO REDUCE
;                          THE SIZE OF THE SYMBOL TABLE

PNAMES:	%TENX%(PN)
NPNMS==.-PNAMES

;REMOVE LOCAL SYMBOLS FROM BLOCK OR PROGRAM
;INDEX TO PNAMES TABLE GIVEN IN 16, # REQUIRED TO BE DELETED IN CT
;CALLED WITH CALL CSS

CSS:	HRRO T1,PNAMES+1(16)	;GET ASCIZ OF NAME
	PSOUT			;SO WE KNOW WHAT WAS CRUNCHED
	MOVE SP,.JBSYM		;SCAN WHOLE TABLE
	MOVE 6,SP		;REMEMBER START OF CURRENT PRG
CSS1:	MOVE T1,0(SP)

;;;;;;;	TXCE T1,<SYMBLK>	; PROGRAM NAME?
;;;;;;;	TXCN T1,<SYMBLK>	; OR BLOCK NAME?
	TLCE T1,(SYMBLK)	;SO DON'T NEED MACSYM
	TLCN T1,(SYMBLK)

	 JRST CSS2		;YES
CSS3:	AOBJN SP,.+1
	AOBJN SP,CSS1		;KEEP SCANNING TABLE
	HRROI T1,[ASCIZ / - NOT FOUND
/]
	PSOUT
	RET

CSS2:
;;;;;;;	TXZ T1,<SYMDIB!SYMDOB!SYMGLO!SYMLOC>	; CLEAR TYPE BITS
	TLZ T1,(SYMDIB!SYMDOB!SYMGLO!SYMLOC)	;SO DONT NEED MACSYM

	CAMN T1,PNAMES(16)	;DESIRED NAME?
	 JRST CSS4		;YES
	MOVE 6,SP		;NO, REMEMBER LOC OF END OF BLOCK
	ADD 6,[2,,2]
	JRST CSS3

;FOUND DESIRED BLOCK, NOW REMOVE LOCAL SYMBOLS

CSS4:	MOVE 5,6
CSS6:	CAMN 5,SP		;SCANNED WHOLE BLOCK?
	JRST CSS8		;YES
	SKIPE FORCE		; FORCING PROGRAM BLOCKS OUT
	 JRST CSS7
	MOVE T1,0(5)		;GET NEXT SYMBOL
	SKIPGE PNAMES+1(16)	;FLUSHING ALL SYMS THIS PGM, OR

;;;;;;;	TXNE T1,<SYMLOC>	;LOCAL?
	TLNE T1,(SYMLOC)	;SO DONT NEED MACSYM

CSS7:	 SOJA CT,[SOJG CT,CSS5	;ELIMINATED EXCESS SYMBOLS YET?
		SKIPN FORCE
		SKIPL PNAMES+1(16) ;YES, REMOVING ALL OF PGR BLOCK?
		JRST CSS5	;YES, KEEP REMOVING
		ADD 5,[2,,2]	;YES
		JRST CSS8]	;FINISH UP
	MOVEM T1,0(6)		;NOT LOCAL, MOVE IT
	MOVE T1,1(5)
	MOVEM T1,1(6)		;MOVE VALUE
	ADD 6,[2,,2]		;UPDATE 'TO' POINTER
CSS5:	ADD 5,[2,,2]		;UPDATE 'FROM' POINTER
	JRST CSS6

CSS8:	MOVSI T1,0(5)		;MOVE REST OF TABLE WITH BLT
	HRRI T1,0(6)
	HLRE T2,5		;COMPUTE NEW END OF TABLE
	MOVEI T3,0(6)		;AS AMOUNT LEFT TO MOVE PLUS
	SUB T3,T2		;CURRENT 'TO' LOCATION
	BLT T1,-1(T3)		;MOVE REST OF TABLE
	MOVEM T3,.JBFF		;UPDATE LOWER CORE
	HRLM T3,.JBSA
	HRRZ T2,.JBSYM		;CALC NEW LENGTH AS
	SUB T2,T3		;BEG-END
	HRLM T2,.JBSYM
CSSRET: CALL CRLF		;1
	RET

;JSYS ERROR

JSEX0:	HRROI T1,[ASCIZ /
?JSYS ERROR: /]
	PSOUT
	MOVEI T1,.PRIOU		;PRINT ERROR STRING ON PRIMARY OUTPUT,
	HRLOI T2,.FHSLF		; THIS FORK ,, LAST ERROR
	SETZ T3,
	ERSTR
	 JFCL
	 JFCL
	CALL CRLF
	HALTF

LENOUT:	HLRE T2,.JBSYM		; LENGTH OF SYMBOL TALBE
	MOVMS T2		; AS A POSTIVE NUMBER
	; FALL INTO OCTOUT

OCTOUT:	SKIPA T3,[^D8]		; OCTAL OUTPUT TO PRIMARY
DECOUT:	MOVEI T3,^D10		; DECIMAL OUTPUT TO PRIMARY
	MOVEI T1,.PRIOU		;OCTAL OUTPUT TO PRIMARY
	NOUT
	 JSERR
	RET


CRLF:	HRROI T1,[ASCIZ /
/]
	PSOUT
	RET

;ROUTINE TO FIXUP LENGTH OF PROGRAM BLOCKS--LH OF 'VALUE' WORD OF 
;PROGRAM NAME

FIXLEN:	HRRZ SP,.JBSYM		;COMPUTE TOP OF SYMTAB
	HLRE T1,.JBSYM
	SUB SP,T1
	SUBI SP,2		;POINT TO FIRST PRG NAME
	HRRZ 6,.JBSYM		;SETUP BOTTOM OF SYMTAB FOR COMPARES
	MOVE 5,SP		;GET START OF THIS BLOCK

;	MOVX T1,<SYMBLK>	;BITS--BOTH OFF FOR PRG BLOCK
	HRLZI T1,(SYMBLK)	;SO DON'T NEED MACSYM

FIXLE1:	SUBI 5,2		;GET TO NEXT SYMBOL
	CAML 5,6		;END OF TABLE?
	TDNN T1,0(5)		;OR PROG NAME?
	JRST FIXLE2		;YES
	JRST FIXLE1		;NO, KEEP LOOKING

FIXLE2:	MOVE T2,SP		;COMPUTE  NEG LENGTH = THIS-LAST
	SUBM 5,T2
	HRLM T2,1(SP)		;PUT IN LENGTH FIELD OF LAST BLOCK
	MOVEM 5,SP		;START NEXT BLOCK
	CAML SP,6		;END OF TABLE?
	JRST FIXLE1		;NO, DO NEXT BLOCK
	RET			;YES, DONE


	LIT

NBUGTP:	0		;NUMBER OF BUG TABLE POINTERS
PDL:	BLOCK 40

	LIT
	VAR

DEFINE OVFMSG(S,N)<PRINTX S N>
IFG .-STRBGP,<OVFMSG(<? POSTLD OVERLAPS BUG AREA BY >,\<.-STRBGP>)>

	END SYSG0

