	.TITLE *** TDV EXIT QUEUE PROCESSOR ***
/
/COPYRIGHT (C) 1975
/DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
/
/THIS SOFTWARE IS FURNISHED UNDER A LICENSE FOR USE ONLY
/ON A SINGLE COMPUTER SYSTEM AND MAY BE COPIED ONLY WITH
/THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS
/SOFTWARE, OR ANY OTHER COPIES THEREOF, MAY NOT BE PRO-
/VIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON
/EXCEPT FOR USE ON SUCH SYSTEM AND TO ONE WHO AGREES TO
/THESE LICENSE TERMS.  TITLE TO AND OWNERSHIP OF THE
/SOFTWARE SHALL AT ALL TIMES REMAIN IN DEC.
/
/THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE
/WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED AS A COM-
/MITMENT BY DIGITAL EQUIPMENT CORPORATION.
/
/DEC ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY
/OF ITS SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DEC.
	.TITLE *** EDIT LEGEND ***
 
/ 000	17-MAR-76 (RCHM)	INITIAL IMPLEMENTATION COMPLETE.
/ 001	26-MAR-76 (RCHM)	MODIFY TO USE NEW OVERLAY	/(001)
/				TERMINAL I/O PROTOCOL.		/(001)
/ 002	20-APR-76 (RCHM)	MAKE SURE THAT ON TASK EXIT THE	/(002)
/				PARTITION SELECTION CRITERIA	/(002)
/				GETS RESET TO THE DEFAULT, I.E.	/(002)
/				PSC = 0 (DELTA) PSC+1 = 1400 (8)/(002)
/ 003	14-MAY-76 (RCHM)	JOB STATE 6 IS GETTING SET TOO	/(142)
/				OFTEN, I.E. ON TNTERM MESSAGES.	/(142)
	.TITLE *** MACROS USED BY TDV EXIT QUEUE PROCESSOR ***
/
/ MACRO WHICH DEFINES ACTIVE TASK LIST ENTRIES
/ THIS ALSO DEFINES ALL BITS FOR EACH FLAG WORD.
/
	.DEFIN ATLOFF
A.FP=0				/FORWARD LINKAGE
A.BP=1				/BACKWARD LINKAGE
A.N1=2				/TASK NAME
A.N2=3				/TASK NAME
A.TP=4				/TASK PRIORITY
A.PB=5				/PARTITION BLOCK ADDRESS
A.SN=6				/STL NODE ADDRESS
A.TS=7				/FLAGS AND TASK STATUS.
A.RA=10				/START OR RESUMPTION ADDRESS.
A.EV=11				/EVENT VARIABLE ADDRESS
				/TASK IS LOADING OR IN 'WAITFOR'
/
/ DEFINE A.TS BIT EXTRACTION MASKS.
/
A.ETLF=400000			/EXTRACT TASK LOADING FLAG.
A.ETNR=400			/EXTRACT TASK NOT TO BE RESCHEDULED.
A.EDRP=200			/EXTRACT TASK IS DISK RESIDENT AND
				/NEEDS PARTITION.
A.EPSD=100			/EXTRACT PARTITION IS AVAILABLE, SETUP
				/DISK READ REQUEST.
A.EWEV=40			/EXTRACT WAITING FOR EVENT VARIABLE.
A.ERSR=20			/EXTRACT TASK READY FOR STARTING OR
				/RESUMPTION.
A.ERXR=10			/TASK ACTIVE, IF INTERRUPTED RESTORE
				/REGISTERS.
A.ESS=4				/EXTRACT TASK HAS SELF SUSPENDED.
A.ETSS=2			/TASK STOPPED FOR TIME SLICING.
/
/ DEFINE A.RA BIT EXTRACTION MASKS.
/
A.ELC=400000			/EXTRACT LINK CONTENTS.
A.EPB=200000			/EXTRACT PAGE/BANK INDICATOR.
A.EEN=100000			/EXTRACT EXEC/NORMAL MODE.
A.ERA=77777			/EXTRACT RESUMPTION ADDRESS.
	.DEFIN ATLOFF
	.ENDM
	.ENDM
/
/ MACRO WHICH DEFINES SYSTEM TASK LIST ENTRIES
/ THIS ALSO DEFINES ALL BITS FOR EACH FLAG WORD.
/
	.DEFIN STLOFF
S.FP=0			/FORWARD LINKAGE.
S.BP=1				/BACKWARD LINKAGE.
S.N1=2				/TASK NAME
S.N2=3				/TASK NAME
S.DP=4				/FLAGS AND DEFAULT PRIORITY.
S.PB=5				/PARTITION BLOCK ADDRESS
S.DA=6				/DISK ADDRESS AND UNIT.
S.DB=7				/RESIDENT CODE LENGTH (DISK TRANSFER)
S.TS=10				/TASK SIZE.
S.EP=11				/TASK ENTRY POINT.
/
/ DEFINE S.DP BIT EXTRACTION MASKS.
/
S.ETA=400000			/EXTRACT TASK ACTIVE
S.EROX=200000			/EXTRACT REMOVE ON EXIT.
S.ETDI=100000			/EXTRACT TASK DISABLED.
S.EFIX=40000			/EXTRACT TASK FIXED IN CORE.
S.EPLC=20000			/EXTRACT PARTITION LOST IN RECONFIG.
S.ERCP=10000			/EXTRACT RECONFIGURATION IN PROGRESS.
S.ETEX=4000			/EXTRACT TASK HAS EXITTED.
S.EDP=1777			/EXTRACT DEFAULT PRIORITY.
/
/ DEFINE S.TS BIT EXTRACTION MASKS.
/
S.ETS=777400			/EXTRACT TASK SIZE.
S.ERD=200			/EXTRACT RELOCATE DISABLE.
S.EXM=140			/EXTRACT XVM MODE.
S.EIOT=20			/EXTRACT IOT PERMISSION.
/
/ DEFINE S.EP BIT EXTRACTION MASKS.
/
S.ELC=400000			/EXTRACT LINK CONTENTS.
S.EPB=200000			/EXTRACT PAGE/BANK INDICATOR.
S.EEN=100000			/EXTRACT EXEC/NORMAL MODE.
S.EEP=77777			/EXTRACT ENTRY POINT ADDRESS.
	.DEFIN STLOFF
	.ENDM
	.ENDM
/
/ DEFINE OFFSETS FOR TASK TERMINATION NOTICE.
/
/ THIS MACRO ALSO DEFINES THE OFFSETS FOR THOSE WORDS USED BY THE
/ MULTI-ACCESS EXIT QUE PROCESSOR.
/
	.DEFIN TNTOFF
T.FP=0				/FORWARD POINTER
T.BP=1				/BACKWARD POINTER
T.N1=2				/TASK NAME
T.N2=3				/TASK NAME
T.TI=4				/TERMINATION INDICATOR
T.PC=5				/PC AT TERMINATION OR
T.TP=5				/TRANSFER PENDING COUNT.
T.AC=6				/AC AT TERMINATION OR NOTHING.
T.XR=7				/XR AT TERMINATION OR NOTHING.
T.U1=10				/UNUSED.
T.U2=11				/UNUSED OR
T.EC=11				/TDV EXIT CODE.
/
/ DEFINE VALUES FOR T.TI
/
T.MPE=1				/MEMORY PROTECT ERROR.
T.NEXM=2			/NONEXISTEND MEMORY REFERENCE.
T.BCAL=3			/BAD CAL.
T.N0TP=4			/NON ZERO TRANSFER PENDING COUNT.
/
/ DEFINE TASK TERMINATION FLAG VALUE FOR T.EC.
/
T.TNTN=1			/T.EC=TNTN IF TERMINATION NOTICE NODE ON
				/TDV.EQ.
	.DEFIN TNTOFF
	.ENDM
	.ENDM
/
/ MACRO TO DEFINE OFFSETS INTO THE USER CONTEXT AREA.
/
	.DEFIN UCAOFF
U.JSW=0				/OFFSET TO JOB STATUS WORD.
U.MAEV=1			/OFFSET TO EVENT VARIABLE
U.MAMTE=2			/OFFSET TO MARK TIME EVENT VARIABLE.
U.OEV=3				/OFFSET TO OVERLAY EVENT VARIABLE.
U.DSK=4				/OFFSET TO DISK NAME
U.DUN=5				/OFFSET TO DISK UNIT NUMBER
U.UFD=6				/OFFSET TO UFD NAME.
U.CTSK=7			/OFFSET TO CURRENT TASK NAME
U.PSC=11			/OFFSET TO PARTITION SELECTION CRITERIA.
U.ULOF=14			/OFFSET TO USER NUMBER AND LUN OFFSET.
U.TTYN=15			/OFFSET TO USER TERMINAL NUMBER.
U.TB=16				/OFFSET TO USER TERMINAL BUFFER.
U.CPB=62			/OFFSET TO MULTI-ACCESS CPB.
U.SSM=74			/SECONDS SINCE MIDNIGHT INTO STATE 11
				/ OR 12 (HUNG ON PARTITION)
U.TW=75				/TOTAL TIME IN SECONDS SPENT IN STATE 11
				/ OR 12.
U.OVID=76			/OVERLAY IDENTIFIER (LAST OVERLAY CALLED)
U.CKS=77			/CHECKSUM OF INPUT BUFFER FOR TIMED READ.
U.LEN=100			/LENGTH OF UCA.
	.DEFIN UCAOFF
	.ENDM
	.ENDM
	.TITLE *** GLOBALS AND EQUATES ***
 
/ GLOBALS INTO TDV.
 
	.GLOBL EXIT	/ ENTRY POINT INTO EXIT QUEUE PROCESSOR.
	.GLOBL TTY.UC	/ TTYN TO UCA MAPPING TABLE.
	.GLOBL TDVTYP	/ OVERLAY TERMINAL I/O ROUTINE.		/(001)
	STLOFF
	TNTOFF
	ATLOFF
	UCAOFF
TDV.EQ=217		/ EXIT QUEUE LIST HEAD.
NDEL=112		/ POINTER TO NODE DELETE ROUTINE.
ECLA=641000		/ EAE CLEAR THE AC INSTRUCTION.
.INH=705522
.ENB=705521
R1=101			/GENERAL REGISTER #1.
R2=102			/GENERAL REGISTER #2.
X10=10			/AUTOINCREMENT REGISTER 10.
X12=12			/AUTOINCREMENT REGISTER 12.
X13=13			/AUTOINCREMENT REGISTER 13.
NADD=107		/ENTRY POINT TO REENTRANT "ADD NODE TO DEQUE" SUBR.
POOL=240		/LISTHEAD OF THE EMPTY NODES DEQUE.
	.TITLE *** EXIT NODE PROCESSOR ***
 
EXIT	XX		/ ENTRY POINT.
	LAC (.)		/ CALCULATE INDEXING FUDGE FACTOR.
	AND (70000)
	CMA!IAC
	DAC E.ADJ	/ STORE ADJUSTMENT FACTOR FOR LATER USE.
 
/
/ MAIN PROCESSING LOOP.
/
E.MAIN	LAC* (TDV.EQ+1)	/ FETCH NODES IN TIME SEQUENCE FROM EARLIEST TO
	SAD (TDV.EQ)	/ LATEST. ANY NODES ON LIST?
	JMP* EXIT	/ NO, RETURN TO THE POLLER.
	DAC E.NODE	/ SAVE THE NODE ADDRESS.
	TAD E.ADJ	/ CALCULATE THE INDEXING VERSION OF THE NODE
	DAC E.XNODE	/ ADDRESS AND SAVE IT.
 
/ WE HAVE A NODE FROM THE EXIT QUEUE. REMOVE IT FROM THE QUEUE.
 
	LAC E.NODE	/ FETCH THE ABSOLUTE NODE ADDRESS.
	DAC* (R1)
	JMS* (NDEL)	/ DELETE THIS NODE.
	LAC E.XNODE	/ SET UP TO ACCESS THE EXIT QUEUE NODE.
	PAX
	LAC T.EC,X	/ FETCH THE EXIT CODE. 0 => EXIT NODE
	SZA		/ 1 => TNTERM NODE.
	JMP E.TNTR	/ TNTERM NODE, GO PROCESS IT.
	JMS USRN	/ GET THE UCA ADDRESS FROM TTY.UC.
	LAC E.XUCA	/ PREPARE TO ACCESS THE UCA.
	PAX
								/(002)
	LAC U.PSC,X	/ SHOULD THE PARTITION SELECTION BE	/(002)
	SPA		/ RESET? AC >= 0 IF YES.		/(002)
	JMP E.0010	/ NO, GLOBAL PARTITION SELECTION ACTIVE./(002)
	DZM U.PSC,X	/ SET UP FOR DELTA PARTITION FIT.	/(002)
	LAC (1400)	/ SET UP FOR A DELTA OF 1400 (8) WORDS.	/(002)
	DAC U.PSC+1,X						/(002)
								/(002)
E.0010	LAC U.JSW,X	/ CHECK TO SEE WHAT KIND OF JOB		/(002)
	SAD (5)		/ JUST QUIT. 5 AND 10 ARE SYSTEM STATES.
	SKP
	SAD (10)
	SKP
	JMP E.REM	/ ALL OTHERS REQUIRE A REMOVE TO BE INVOKED.
 
/ A TASK REQUIRING ONLY THE REMOVAL OF IT'S STL NODE HAS EXITTED. DO SO.
 
	LAC E.XNODE	/ FETCH THE STL NODE ADDRESS FROM THE EXIT
	PAX		/ NODE.
	LAC A.SN,X	/ GET STL NODE ADDRESS.
	DAC CHCT	/ USE THE CHARACTER COUNT AS A TEMPORARY.
	DAC* (R1)	/ SET UP FOR NDEL.
	JMS* (NDEL)
	LAC CHCT	/ FETCH STL NODE ADDRESS.
	JMS FREEUP	/ RETURN NODE TO THE POOL.
	JMP RETURN	/ GO SET UP STATE 6 AND RETURN NOTICE NODE TO 
			/ THE POOL.
	.EJECT
 
/ SET UP FOR REMOVAL OF THE TASK'S DISK SPACE AND STL NODE BY AUTORM.
 
E.REM	LAC E.XNOD	/ SET UP TO ACCESS EXIT NODE.
	PAX
	LAC A.SN,X	/ FETCH STL NODE ADDRESS.
	TAD E.ADJ	/ CALCULATE ADJUSTMENT FACTOR.
	PAX		/ SET UP TO ACCESS STL.
	.INH		/ CLOBBER THE STL NODE.
	DZM S.N1,X	///CLEAR THE NAME FIELD.
	DZM S.N2,X	///
.X=S.EROX!S.ETDI!S.EPLC!S.ETEX
	LAC (.X)	///MAKE SURE THAT THIS TASK NEVER RUNS AGAIN.
	.ENB		///
	DAC S.DP,X	///
	CAL REQATO	/ REQUEST AUTORM.
	JMP RETURN	/ RETURN EXIT NODE TO POOL AND SET UP STATE 6.
	.TITLE *** TNTERM MESSAGE PROCESSOR ***
E.TNTR	JMS USRN	/ CALCULATE UCA ADDR FROM TTY NUMBER IN NAME.
	LAC E.NODE	/ FETCH TNTERM NOTICE NODE ADDRESS.
	IAC		/ AND SET UP X10 TO FETCH NODE ADDRESS.
	DAC*	(X10)
/
	DZM	CHCT	/CLEAR CHARACTER COUNT
	LAC	(LINE+1)	/SETUP X13 TO FILL LINE
	DAC*	(X13)
/
	ISZ* (X10)	/ MOVE POINTER INTO NODE SO THAT THE REST
	ISZ* (X10)	/ OF THE FETCHES WILL WORK PROPERLY.
	LAC E.XUCA	/ PREPARE TO FETCH THE CURRENT TASK NAME
	PAX		/ FROM THE UCA.
	LAC U.CTSK,X	/ FETCH THE FIRST HALF OF THE NAME.
	DAC MES1+2	/ SET UP FOR 6 BIT CONVERSION.
	LAC U.CTSK+1,X	/ FETCH THE SECOND HALF OF THE NAME.
	DAC MES1+3	/ SET UP FOR 6 BIT CONVERSION.
	LAC	(MES1)
	JMS	PSM
/
	LAC*	X10	/FETCH TERMINATION INDICATOR
	SAD	(1)	/IF 1, MEMORY PROTECT VIOLATION
	JMP	TT1
	SAD	(2)	/IF 2, NONEXISTENT MEMORY REFERENCE
	JMP	TT2
	SAD	(3)	/IF 3, BAD CAL ADDRESS
	JMP	TT3
	SAD	(4)	/IF 4, NON-0 TRANSFERS PENDING COUNT.
	JMP	TT4
	JMP	RETURN	/UNDEFINED INDICATOR. IGNORE REQUEST.
/
TT1	LAC	(MES2)	/PACK "MEM PROTECT ERR, PC = X XXXXX"
	SKP
TT2	LAC	(MES3)	/PACK "NONEX MEM REF, PC = X XXXXX"
	JMS	PSM
/
	LAC*	X10
	JMS	PPC
/
	LAC	(MES6)	/PACK ", AC = XXXXXX"
	JMS	PSM
	LAC*	X10
	JMS	POW
/
	LAC	(MES7)	/PACK ", XR = XXXXXX"
	JMS	PSM
	LAC*	X10
	JMS	POW
/
	JMP	WRITE
/
TT3	LAC	(MES4)	/PACK "BAD CAL AT PC = X XXXXX"
	JMS	PSM
	LAC*	X10
	JMS	PPC
	JMP	WRITE
/
TT4	LAC	(MES8)	/PACK "ABORTED; YET TRANSFERS PENDING COUNT
	JMS	PSM	/ = XXXXXX"
	LAC*	X10
	JMS	POW
/
WRITE	LAC	(015)	/TERMINATE LINE
	JMS	PSC
	LAC	(012)
	JMS	PSC
	CLA
	JMS	PSC
	LAC	CHCT
	RCR
	SWHA
	TAD	(001003)
	DAC	LINE
/
	LAC E.XUCA	/ FETCH THE TTY NUMBER FROM THE UCA.
	PAX
	LAC U.TTYN,X	/ FETCH THE TERMINAL NUMBER.		/(001)
	DAC CHCT	/ SAVE IT TEMPORARILY.			/(001)
	JMS* TDVTYP	/ PRINT THE CONSTRUCTED MESSAGE.	/(001)
	LAC CHCT	/ FETCH TERMINAL NUMBER.		/(001)
	LAC (LINE)	/ FETCH MESSAGE ADDRESS.		/(001)
	LAC (3)		/ FETCH MODE.				/(001)
	JMP RET.N	/ RETURN NODE TO POOL.			/(003)
			/ JOB STATE 6 WILL HAVE TO WAIT FOR THE	/(003)
			/ EXIT NODE TO HIT THE LIST.		/(003)
/
RETURN	LAC E.XUCA	/ SET THE JOB INTO STATE 6 FOR NEXT COMMAND.
	PAX
	LAC (6)		/ FETCH JOB STATE INDICATOR.
	DAC U.JSW,X	/ JOB STATE INDICATOR NOW SET FOR NEXT READ.
RET.N	LAC E.NODE	/ FETCH ADDRESS OF NODE TO BE RETURNED.	/(003)
	JMS FREEUP	/ RETURN NODE TO THE POOL.
	JMP E.MAIN	/ GO CHECK FOR ANOTHER NODE.
/
/ PSM -- SUBROUTINE TO PACK .SIXBT MESSAGE WHOSE ADDRESS IS IN AC
/
PSM	0
	AAC	-1
	DAC*	(X12)
/
PSM1	LAC*	X12
	SAD	(-1)
	JMP*	PSM
	JMS	PSW
	JMP	PSM1
/
/
/ PSW -- SUBROUTINE TO PACK THE .SIXBT WORD IN AC
/
PSW	0
	LMQ
	JMS	PSWS
	JMS	PSWS
	JMS	PSWS
	JMP*	PSW
/
PSWS	0
	CLA
	LLS	6
	SNA
	JMP*	PSWS
	XOR	(40)
	TAD	(40)
	JMS	PSC
	JMP*	PSWS
/
/ POW -- SUBROUTINE TO PACK THE OCTAL WORD IN AC
/
POW	0
	LMQ
	LAW	-6
	DAC	POWC
/
POW1	CLA
	LLS	3
	XOR	(60)
	JMS	PSC
	ISZ	POWC
	JMP	POW1
	JMP*	POW
/
POWC	0
/
/ PPC -- SUBROUTINE TO PACK THE "PC" IN AC
/
PPC	0
	LMQ
	LAW	-5
	DAC	PPCC
/
	CLA
	LLS	3
	XOR	(60)
	JMS	PSC
	LAC	(040)
	JMS	PSC
/
PPC1	CLA
	LLS	3
	XOR	(60)
	JMS	PSC
	ISZ	PPCC
	JMP	PPC1
	JMP*	PPC
/
PPCC	0
/
/ PSC -- SUBROUTINE TO PACK THE SEVEN BIT CHARACTER IN AC
/
PSC	0
	DAC*	X13
	ISZ	CHCT
	JMP*	PSC
/
CHCT	0	/CHARACTER COUNT
E.ADJ	0		/ INDEXING FUDGE FACTOR.
E.NODE	0		/ EXIT NODE ABSOLUTE ADDRESS.
E.XNODE	0		/ EXIT NODE INDEXING CONSTANT.
E.UCA	0		/ UCA ABSOLUTE ADDRESS.
E.XUCA	0		/ UCA INDEXING CONSTANT.
 
REQATO	01
	0
	.SIXBT "AUTORM"
	0
/
MES1	.SIXBT	/*** "@------", /
	-1
MES2	.SIXBT	"MEM PROTECT ERR, PC = "
	-1
MES3	.SIXBT	"NONEX MEM REF, PC = "
	-1
MES4	.SIXBT	"BAD CAL AT PC = "
	-1
MES6	.SIXBT	", AC = "
	-1
MES7	.SIXBT	", XR = "
	-1
MES8	.SIXBT	"ABORTED; YET TRANSFERS PENDING COUNT = "
	-1
/
LINE	002003
	000000
	.BLOCK 130
/
	.TITLE *** UTILITY SUBROUTINES ***
 
/ CALCULATE THE UCA ADDRESS FROM THE TTY NUMBER FETCHED FROM THE TASK
/ NAME, SECOND HALF.
 
USRN	XX
	LAC T.N2,X	/ ASSUMES XR SET UP TO FETCH FROM EXIT NODE.
	CLQ!LRS 3
	RTR
	RAR!CLL
	LRS 3
	ECLA!LLS 6
	TAD TTY.UC
	DAC E.UCA
	LAC* E.UCA
	DAC E.UCA
	TAD E.ADJ
	DAC E.XUCA
	JMP* USRN
 
/ SUPROUTINE TO RETURN A NODE TO THE POOL. NODE ADDRESS IN AC UPON ENTRY.
 
FREEUP	XX
	DAC* (R2)
	LAC (POOL)
	DAC* (R1)
	JMS* (NADD)
	JMP* FREEUP
	.END
