Google
 

Trailing-Edge - PDP-10 Archives - AP-4172F-BM - 3a-sources/qsrque.mac
There are 44 other files named qsrque.mac in the archive. Click here to see a list.
TITLE	QSRQUE  --  Batch Queue Message Handlers for QUASAR
SUBTTL	Larry Samberg  Chuck O'Toole /CER 6 Jan 77




;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1974, 1975, 1976, 1977, 1978 BY
;	DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.

	SEARCH	QSRMAC		;PARAMETER FILE

	PROLOGUE(QSRQUE)	;GENERATE THE NECESSARY SYMBOLS


COMMENT\

	STOPCDs found in QSRQUE

BDN	BAD DEVICE NAME INTERNALLY GENERATED
CRD	CREATE REJECTED DEFER DATA
CRL	CREATE REJECTED LOGOUT DATA
CRM	CREATE REJECTED MODIFY
CRS	CREATE REJECTED SPOOLING DATA
NBR	NEXTJOB'ING BAD REQUEST

\
SUBTTL	Queue Headers and Module Storage

	INTERN	TBLHDR
	INTERN	NQUEUE

;BUILD THE QUEUE HEADERS

TBLHDR:	QUEHDR
	NQUEUE==<.-TBLHDR>/QHSIZE

LSTITN:	BLOCK	1			;LAST ITN ASSIGNED
LISSIZ:	BLOCK	1			;NUMBER OF PAGES NEEDED FOR LAST
					; COMPLETE QUEUE LISTING
THSPSB:	BLOCK	1			;ADDRESS OF THE PSB OF THE
					;SENDER OF THE CURRENT MESSAGE
					;FILLED IN BY VALMSG
MSGPDB:	BLOCK	IPCHSZ			;PDB SPACE FOR "NEXT", "ABORT",
					; AND "LISTANSWER"

MSGMSG:	BLOCK	ABO.SZ			;RESERVE THE SPACE FOR THE MESSAGES
SUBTTL	Queue Database Initialization

Q$INIT::PUSHJ	P,I$NOW##		;GET NOW
	MOVEM	S1,LSTITN		;AND SAVE IT AS LAST ITN
	ZERO	LISSIZ			;START WITH A CLEAN SLATE
	POPJ	P,			;RETURN
SUBTTL	Batch and Spooling Message Handlers

;THE MESSAGE HANDLERS ARE TOP LEVEL ROUTINES WHICH PROCESS THE
;	VARIOUS MESSAGES THAT ARE SENT TO QUASAR.  THEY ARE
;	CALLED DIRECTLY OUT OF THE MAIN PROCESSING LOOP WITH
;	ACCUMULATOR "M" POINTING TO THE FIRST WORD OF THE MESSAGE.
;	THE MESSAGE HANDLERS HAVE FULL USE OF ALL ACCUMULATORS
;	EXCEPTING "M" AND THE "P" REGS.

	INTERN	Q$RELEASE	;FUNCTION 2  --  RELEASE
	INTERN	Q$CHECKPOINT	;FUNCTION 3  --  CHECKPOINT
	INTERN	Q$REQUEUE	;FUNCTION 4  --  REQUEUE
	INTERN	Q$NEXTJOB	;FUNCTION 5  --  NEXTJOB(*)
	INTERN	Q$ABORT		;FUNCTION 6  --  ABORT(*)
	INTERN	Q$CREATE	;FUNCTION 7  --  CREATE
	INTERN	Q$LIST		;FUNCTION 10 --  LIST
	INTERN	Q$MODIFY	;FUNCTION 11 --  MODIFY
	INTERN	Q$KILL		;FUNCTION 12 --  KILL
	INTERN	Q$LANSWER	;FUNCTION 13 --  LISTANSWER(*)
				;FUNCTION 14 --  TEXT(*)
	INTERN	Q$DEFER		;FUNCTION 16 --  DEFER

;SOME IPCC MESSAGES ARE SENT TO QUASAR FROM THE MONITOR EXEC PROCESS.
;	THEY ARE TREATED IN THE SAME MANNER AS USER GENERATED
;	CALLS (I.E. ACCUMULATOR "M" POINTS TO THE MESSAGE)

	INTERN	Q$SPOOL		;SPOOLING FILE REQUEST -- FUNCTION .IPCSU (26)
	INTERN	Q$LOGOUT	;LOGOUT OF A JOB       -- FUNCTION .IPCSL (27)

;(*) NEXTJOB, ABORT, LISTANSWER, AND TEXT ARE SENT BY QUASAR
;	THESE ARE NOT CALLED FROM THE MAIN LOOP BUT RATHER:
;
;	NEXTJOB   IS CALLED FROM THE SCHEDULING ROUTINES
;	ABORT	  IS CALLED FROM THE KILL FUNCTION
;	LANSWER	  IS CALLED FROM THE LIST FUNCTION
;	TEXT	  IS HANDLED BY THE MAIN LOOP ITSELF
;
;IF .QIFNC IS SET IN THE OPERATION FIELD OF A MESSAGE, THE CALL IS
;	CONSIDERED INTERNAL, AND SPECIAL HANDLING OR INTERPRETATION
;	OF THE VARIOUS FIELDS IN THE MESSAGE, (PARTICULARLY THE
;	OTHER 17 BITS OF THE TYPE FIELD) MAY OCCUR.  ANY SPECIAL
;	HANDLING OF THIS FORM WILL BE DESCRIBED IN THE ROUTINE
;	HEADER COMMENTS.  IF .QIFNC IS SET THE REST OF THE TYPE FIELD
;	DOES NOT HAVE TO REFLECT THE MESSAGE TYPE SINCE IF Q$CREATE
;	RECEIVES AN INTERNAL CALL, THE MESSAGE IS OBVIOUSLY A CREATE
;	MESSAGE.
SUBTTL	RELEASE  --  Function 2

;THE RELEASE MESSAGE IS SENT TO QUASAR BY ONE OF THE KNOWN SYSTEM
;	COMPONENTS TO RELEASE A JOB FROM THE QUEUE.

Q$RELEASE:
	MOVEI	T1,REL.SZ		;LOAD MINIMUM SIZE
	PUSHJ	P,VALMSG		;VALIDATE THE MESSAGE
	SKIPE	G$ERR##			;DID VALMSG SET THE ERROR FLAGS
	  POPJ	P,			;YES, REJECT THIS MESSAGE
	MOVE	T1,REL.IT(M)		;GET THE TASKS ITN
	PUSHJ	P,SRHUSE		;SEARCH THE USE QUEUE
	PJUMPE	T1,E$SNY##		;NOT FOUND
	MOVE	AP,T1			;COPY ENTRY ADR INTO AP
	MOVE	T1,G$SND##		;GET PID OF SENDER
	CAME	T1,.QEPID(AP)		;DOES HE REALLY OWN THE REQ?
	  PJRST	E$SNY##			;NO, GIVE "NOT YOURS" ERROR
	MOVE	T1,THSPSB		;GET ADDRESS OF HIS PSB
	PUSHJ	P,S$RUSE##		;TELL SCHED ABOUT REMOVAL
	PUSH	P,AP			;SAVE AP FIRST
	PUSHJ	P,S$RELE##		;RELEASE THE REQUEST
	POP	P,AP			;RESTORE REQUEST ADDRESS
	LOAD	S1,.QESTN(AP),QE.DPA	;GET THE DISK ADDRESS
	PUSHJ	P,F$RLRQ##		;AND RELS SPACE
	$COUNT	(MREL)
	MOVEI	H,HDRUSE		;LOAD ADR OF USE HEADER
	PJRST	M$RFRE##		;AND RETURN THE ENTRY
SUBTTL	CHECKPOINT  --  Function 3

;A CHECKPOINT MESSAGE IS SENT PERIODICALLY BY THE VARIOUS
;	KNOWN PROCESSORS.  THE CHECKPOINT OPERATIONS CONSISTS
;	OF UPDATING THE INCORE AND DISK ENTRIES WITH THE
;	CHECKPOINT INFORMATION PROVIDED.

Q$CHECKPOINT:
	MOVEI	T1,CHE.SZ		;LOAD MINIMUM MESSAGE SIZE
	PUSHJ	P,VALMSG		;VALIDATE THE MESSAGE
	SKIPE	G$ERR##			;DID VALMSG SET THE ERROR FLAGS
	  POPJ	P,			;YES, REJECT THIS MESSAGE
	MOVE	T1,CHE.IT(M)		;GET THE SPECIFIED ITN
	PUSHJ	P,SRHUSE		;SEARCH THE USE QUEUE
	PJUMPE	T1,E$SNY##		;NOT THERE!!
	MOVE	T2,G$SND##		;GET PID OF SENDER
	CAME	T2,.QEPID(T1)		;DOES HE OWN IT?
	  PJRST	E$SNY##			;NO, GIVE AN ERROR
	LOAD	S1,.QESTN(T1),QE.DPA	;GET THE DPA
	PUSHJ	P,F$RDRQ##		;READ THE REQUEST
	MOVE	AP,S1			;SAVE PAGE ADR IN AP
	HRRI	S2,.EQCHK(S1)		;AND PLACE TO PUT IT
	HRLI	S2,CHE.IN(M)		;FIRST OF THE INFORMATION WORDS
	BLT	S2,.EQCHK+<EQCKSZ-1>(S1)  ;AND BLT IT
	PUSHJ	P,F$WRRQ##		;WRITE IT OUT
	LOAD	S2,.QESTN(T1),QE.DPA	;GET PREVIOUS DPA
	STORE	S1,.QESTN(T1),QE.DPA	;STORE NEW DPA
	MOVE	S1,S2			;GET OLD DPA INTO S1
	PUSHJ	P,F$RLRQ##		;AND RELEASE IT
	$COUNT	(MCHK)
	ADR2PG	AP			;MAKE A PAGE NUMBER
	PJRST	M$RELP##		;RELEASE THE PAGE AND RETURN
SUBTTL	REQUEUE  --  Function 4

;THE REQUEUE FUNCTION IS SENT BY A KNOWN COMPONENT USUALLY
;	DUE TO OPERATOR REQUEST.  THE REQUEUE MESSAGE CONTAINS
;	THE SAME CHECKPOINT INFORMATION BUT HAS AN AFTER PARAMETER.
;
;REQUEUE PERFORMS THE FOLLOWING FUNCTIONS:
;	1)  CHECKPOINT THE ENTRY
;	2)  MOVE THE ENTRY FROM THE USE QUEUE TO THE 
;	    APPROPRIATE PROCESSING QUEUE
;	3)  RELEASE THE JOB FROM THE PSB

Q$REQUEUE:
	MOVEI	T1,REQ.SZ		;MINIMUM SIZE OF THE MESSAGE
	PUSHJ	P,VALMSG		;VALIDATE THE SIZE OF IT
	SKIPE	G$ERR##			;IS IT OK
	  POPJ	P,			;NO, RETURN NOW
	PUSHJ	P,Q$CHECKPOINT		;DO A CHECKPOINT FIRST
	SKIPE	G$ERR##			;DID CHECKPOINT REJECT THE REQUEST
	  POPJ	P,			;YES, SO WILL I
	MOVE	T1,REQ.IT(M)		;GET THE ITN OF THE TASK
	PUSHJ	P,SRHUSE		;LOCATE IN THE USE QUEUE
	MOVE	AP,T1			;SAVE FOR EVENTUAL MOVE
	ZERO	.QEPID(AP)		;CLEAR THE INTERLOCK
	LOAD	H,.QESTN(AP),QE.RQP	;GET RELATIVE QUEUE POINTER
	ADDI	H,TBLHDR		;AND MAKE ADDRESS OF QUE HDR
	SKIPN	S1,REQ.AF(M)		;IS THERE A /AFTER PARAMETER?
	JRST	REQU.1			;NO, CONTINUE NORMALLY
	MOVEI	H,HDRAFT		;YES, LOAD ADDRESS OF AFTER HEADER
	PUSHJ	P,I$AFT##		;GET AFTER TIME
	MOVEM	S1,.QECRE(AP)		;AND STORE IN ENTRY

REQU.1:	MOVE	S1,H			;PUT DESTINATION QUE IN S1
	MOVEI	H,HDRUSE		;LOAD H WITH SOURCE QUEUE
	PUSHJ	P,M$MOVE##		;MOVE THE ENTRY
	$COUNT	(MREQ)
	MOVE	T1,THSPSB		;LOAD THE PSB ADDRESS
	PJRST	S$RUSE##		;AND NOTIFY THE SCHEDULER
SUBTTL	NEXTJOB  --  Function 5

;NEXTJOB IS CALLED BY THE SCHEDULING ROUTINES IN QSRSCH WHEN
;	AN ENTRY IS READY TO BE SCHEDULED FOR A KNOWN SYSTEM
;	COMPONENT.
;
;NEXTJOB IS CALLED AS FOLLOWS:
;	AP = ADDRESS OF THE ENTRY IN THE PROCESSING QUEUE (EG LPT QUEUE)
;	T1 = ADDRESS OF THE PSB TO SCHEDULE IT FOR
;	H  = ADDRESS OF THE QUEUE HEADER OF THE PROCESSING QUEUE
;
;NEXTJOB PERFORMS THE FOLLOWING FUNCTIONS:
;	1)  MOVE ENTRY FROM PROCESSING QUEUE TO "USE" QUEUE
;	2)  READ THE QUEUE REQUEST FROM DISK
;	3)  INCLUDE THE CHANGABLE DATA
;	4)  SEND THE REQUEST TO THE PROCESSOR

Q$NEXTJOB:
	$COUNT	(MNXT)			;COUNT NEXTJOBS
	MOVEI	S1,HDRUSE		;LOAD DESTINATION QUEUE HDR
	PUSHJ	P,M$MOVE##		;AND MOVE THE ENTRY
	MOVE	S1,PSBPID(T1)		;PID OF THE PROCESSOR
	MOVEM	S1,.QEPID(AP)		;STORE THE INUSE NAME
	MOVE	S1,PSBPDV(T1)		;GET THE PROCESSING DEVICE
	MOVEM	S1,.QEDEV(AP)		;AND INCLUDE THE DEVICE

;NOW, READ IN THE PAGE AND SEND IT TO THE CORRECT PROCESSOR

	LOAD	S1,.QESTN(AP),QE.DPA	;GET THE DPA
	PUSHJ	P,F$RDRQ##		;READ THE REQUEST
	SKIPN	0(S1)			;DO A SMALL VALIDITY CHECK
	  STOPCD(NBR,FATAL)		;++NEXTJOB'ING BAD REQUEST
	MOVEI	T1,.QONEX		;GET NEXTJOB FUNCTION
	STORE	T1,.MSTYP(S1),MS.TYP	;AND STORE IT IN THE MESSAGE
	LOAD	T1,.QEITN(AP)		;NOW MAKE SURE ITN EXISTS
	STORE	T1,.EQITN(S1)		;STORE IT
	LOAD	T1,.QECRE(AP)		;CREATION TIME
	STORE	T1,.EQAFT(S1)		;STORE THAT AS WELL
	LOAD	T1,.QESEQ(AP),QE.SEQ	;THE SEQUENCE NUMBER
	STORE	T1,.EQSEQ(S1),EQ.SEQ	;AND THAT
	LOAD	T1,.QEPRT(AP),DV.STN	;GET STATION NUMBER FOR REQUEST
	STORE	T1,.EQSEQ(S1),EQ.DSN	;SET PROPERLY FOR BATCON
	HRLI	T1,.QELM1(AP)		;MOVE LIMIT WORDS FROM INTERNAL
	HRRI	T1,.EQLM1(S1)		;TO EXTERNAL REQUEST
	BLT	T1,.EQLM5(S1)		;FOR EXTRA DEFAULTED VALUES
	MOVX	T1,IP.CFV		;GET PAGE-MODE BIT
	MOVEM	T1,MSGPDB+.IPCFL	;PUT IT IN THE FLAG WORD
	MOVE	T1,.QEPID(AP)		;GET PROCESSORS PID
	MOVEM	T1,MSGPDB+.IPCFR	;STORE RECEIVERS PID
	ADR2PG	S1			;MAKE A PAGE NUMBER
	HRLI	S1,1000			;AND THE SIZE
	MOVEM	S1,MSGPDB+.IPCFP	;SAVE IT
	MOVEI	AP,MSGPDB		;ADDRESS OF PDB
	PJRST	C$SEND##		;SHIP THE MESSAGE AND RETURN
SUBTTL	ABORT  --  Function 6

;ABORT IS CALLED BY THE "KILL" HANDLER WHEN THE JOB IN QUESTION IS
;	IN THE USE QUEUE.  CALL "ABORT" WITH T1 POINTING TO THE
;	USE QUEUE ENTRY.  ABORT SIMPLY SENDS AN ABORT MESSAGE
;	TO THE PROCESSOR INTERLOCKING THE JOB.

Q$ABORT:
	MOVEI	AP,MSGPDB		;LOAD ADR OF THE PDB
	MOVEI	T3,MSGMSG		;LOAD ADR OF THE MESSAGE
	ZERO	.IPCFL(AP)		;NO FLAGS
	LOAD	T4,.QEPID(T1)		;GET THE PROCESSOR'S PID
	MOVEM	T4,.IPCFR(AP)		;STORE AS RECEIVER
	MOVE	T4,[ABO.SZ,,MSGMSG]	;LOAD SIZE,,ADR
	MOVEM	T4,.IPCFP(AP)		;AND STORE IT
	MOVE	T4,[ABO.SZ,,.QOABO]	;LOAD THE MESSAGE HDR
	STORE	T4,.MSTYP(T3)		;AND STORE IT
	LOAD	T4,.QEITN(T1)		;GET THE ITN
	STORE	T4,ABO.IT(T3)		;STORE IN ABORT MESSAGE
	MOVX	T4,ABOUSR		;"ABORTED BY USER"
	STORE	T4,ABO.CD(T3)		;STORE THE CODE
	LOAD	T4,G$SID##		;GET ID OF SENDER
	STORE	T4,ABO.ID(T3)		;AND STORE IN THE MESSAGE
	PJRST	C$SEND##		;AND SEND IT
SUBTTL	CREATE  --  Function 7

;THE CREATE MESSAGE IS SENT TO QUASAR BY ANY UNKNOWN COMPONENT
;	TO PLACE SOMETHING IN ONE OF THE PROCESSING QUEUES.
;IF THIS IS AN INTERNAL CALL (I.E. .QIFNC IS SET) THEN THE LOW-ORDER
;	17 BITS OF THE FUNCTION FIELD ARE TAKEN TO BE THE DPA IF THE
;	REQUEST IS ALREADY FAILSOFT, AND IF THIS FIELD IS NON-ZERO,
;	THE REQUEST IS NOT WRITTEN OUT.
Q$CREATE:
	PUSHJ	P,.SAVE3##		;SAVE P1 THRU P3
	LOAD	T1,.MSTYP(M),MS.CNT	;GET LENGTH OF MESSAGE
	CAIGE	T1,EQHSIZ		;MUST BE AT LEAST EQHSIZ
	  PJRST	E$MTS##			;INDICATE MESSAGE TOO SHORT
	LOAD	T1,.EQLEN(M),EQ.LOH	;MUST CHECK HEADER SIZE AS WELL
	CAIGE	T1,EQHSIZ		;THAT IS ALSO THE MINIMUM VALUE
	  PJRST	E$MTS##			;TOO BAD, GIVE MESSAGE TOO SHORT
	LOAD	S1,.EQRDV(M)		;GET SIXBIT DEVICE QUEUED TO
	LOAD	S2,.EQSEQ(M),EQ.DSN	;CALLERS STATION NUMBER
	PUSHJ	P,I$MIDS##		;CREATE INTERNAL DEVICE SPEC
	PJUMPE	S1,E$IFD##		;JUMP IF ILLEGALLY FORMED
	MOVE	P1,S1			;SAVE FOR LATER COPY
	PUSHJ	P,Q$FHDR		;FIND THE QUEUE HEADER
	SKIPN	H,S1			;LOAD INTO H AND SKIP
	PJRST	E$UQS##			;UNKNOWN QUEUE SPECIFIED
	LOAD	P3,.MSTYP(M),MS.TYP	;GET THE TYPE FIELD
	TXNE	P3,.QIFNC		;IS IT INTERNAL?
	 SKIPN	T1,.EQITN(M)		;YES, LOAD OLD ITN IF NON-ZERO
	  AOS	T1,LSTITN		;GET A NEW ITN
	STORE	T1,.EQITN(M)		;AND STORE IN MSG FOR LATER
	LOAD	T1,.QHPAG(H),QH.SCH	;BASE OF SCHEDULING ENTRIES
	PUSHJ	P,SCHDEF(T1)		;GO FILL THE DEFAULTS FOR THIS QUEUE
	SKIPE	G$ERR##			;DID IT GET PAST THE CHECKS
	  POPJ	P,			;NO, SCHDEF REJECTED IT!!
CREA.1:	PUSH	P,H			;SAVE "REAL" QUEUE HEADER
	MOVE	S1,.EQAFT(M)		;GET THE AFTER PARAMETER
	TXNE	P3,.QIFNC		;IS IT INTERNAL?
	  JRST	CREA.2			;YES, JUST USE WHAT WE'VE GOT
	CAMGE	S1,G$NOW##		;NO, IS IT BEFORE NOW?
	  MOVE	S1,G$NOW##		;YES, USE NOW.  THIS DISALLOWS
	MOVEM	S1,.EQAFT(M)		;/AFT:YESTERDAY TO GIVE HI-PRIO
CREA.2:	CAMLE	S1,G$NOW##		;IS IT IN THE FUTURE?
	  MOVEI	H,HDRAFT		;YES, PUT ENTRY IN AFTER QUEUE
	PUSHJ	P,M$GFRE##		;GET A FREE CELL

				;"CREATE" IS CONTINUED ON NEXT PAGE
				;CONTINUED FROM PREVIOUS PAGE

	MOVE	S1,P3			;COPY THE MESSAGE TYPE
	TXZE	S1,.QIFNC		;IS IT INTERNAL?
	  JUMPN	S1,CREA.3		;YES, IF DPA EXISTS, DON'T FAILSOFT
	MOVE	S1,M			;NO, GET THE ADDRESS
	PUSHJ	P,F$WRRQ##		;AND FAILSOFT IT
CREA.3:	STORE	S1,.QESTN(AP),QE.DPA	;STORE THE DISK ADDRESS
	POP	P,S1			;GET "REAL" QUEUE HEADER
	SUBI	S1,TBLHDR		;MAKE AN RQP
	STORE	S1,.QESTN(AP),QE.RQP	;AND SAVE RQP IN ENTRY
	LOAD	P2,.EQSPC(M),EQ.NUM	;GET NUMBER OF FILES IN THE REQUEST
	LOAD	T1,.EQITN(M)		;GET THE ITN
	STORE	T1,.QEITN(AP)		;AND STORE IT
	LOAD	T1,.EQJOB(M)		;GET JOB NAME
	STORE	T1,.QEJOB(AP)		;STORE IT
	MOVE	S1,M			;POINT S1 TO THE EQ
	PUSHJ	P,I$EQQE##		;MOVE INFO FROM EQ TO QE
	LOAD	T1,.EQSEQ(M),EQ.SEQ	;GET EXT SEQ NUMBER
	STORE	T1,.QESEQ(AP),QE.SEQ	;STORE IT
	LOAD	T1,.EQSEQ(M),EQ.PRI	;GET THE PRIORITY FIELD
	STORE	T1,.QESEQ(AP),QE.PRI	;STORE IT
	LOAD	T1,.EQSEQ(M),EQ.RDE	;GET RDE FLAG
	STORE	T1,.QESEQ(AP),QE.RDE	;AND MOVE IT
	LOAD	T1,.EQSEQ(M),EQ.SPL	;GET SPL BIT
	STORE	T1,.QESEQ(AP),QE.SPL	;AND STORE IT IN THE QE
	LOAD	T1,.EQSPC(M),EQ.PRO	;GET THE PROTECTION FIELD
	STORE 	T1,.QEPRT(AP),QE.PRO	;STORE IT
	LOAD	T1,.EQDED(M)		;GET DEADLINE
	STORE	T1,.QEDED(AP)		;STORE IT
	LOAD	T1,P1,DV.DMD		;GET DEVICE MODIFIERS FROM I$MIDS
	STORE	T1,.QEPRT(AP),QE.DMD	;SAVE FOR SCHEDULER
	MOVSI	T1,.EQLM1(M)		;SOURCE OF 5 LIMIT WORDS
	HRRI	T1,.QELM1(AP)		;DESTINATION OF 5 LIMIT WORDS
	BLT	T1,.QELM5(AP)		;BLT THEM ACROSS
	LOAD	T1,.EQAFT(M)		;GET CREATE OR AFTER TIME
	STORE	T1,.QECRE(AP)		;AND STORE IT
	ZERO	.QEPID(AP)		;ZERO THE PID
	LOAD	S1,.EQLEN(M),EQ.LOH	;NOW FIND THE FIRST FILE IN THE REQUEST
	ADDI	S1,(M)			;FIND FIRST FP AREA
	LOAD	S2,.FPSIZ(S1),FP.FHD	;LENGTH OF THE FIRST FP
	ADDI	S1,(S2)			;S1 = FIRST FD AREA
	PUSHJ	P,I$FSTR##		;EXTRACT THE FILE STRUCTURE FROM THE FD
	STORE	S1,.QESTR(AP)		;STORE FOR SCHEDULER
	LOAD	T1,.QESEQ(AP),QE.RDE	;GET THE JOBS RDE BIT
	JUMPE	T1,CREA.4		;NOT RDE, CONTINUE
	MOVEI	H,HDRRDE-TBLHDR		;GET RQP FOR RDE QUEUE
	STORE	H,.QESTN(AP),QE.RQP	;STORE IT
	ADDI	H,TBLHDR		;POINT TO RDE QUEUE


				;"CREATE" IS CONTINUED ON THE NEXT PAGE
				;CONTINUED FROM THE PREVIOUS PAGE

CREA.4:	LOAD	T1,.QHPAG(H),QH.SCH	;GET BASE OF SCHED VECTOR
	PUSHJ	P,SCHLNK(T1)		;AND LINK IN THE REQUEST
	$COUNT	(SCRE)			;NUMBER OF SUCCESSFUL CREATES
	SKIPN	G$ACK##			;DOES CALLER WANT ACKNOWLEDGEMENT
	  POPJ	P,			;NO, ALL DONE
	MOVE	S1,P1			;GET IDS OF REQUEST
	PUSHJ	P,I$MSDN##		;MAKE PRINTABLE SIXBIT DEVICE
	PUSHJ	P,G$CSIX##		;PUT IT INTO THE STRING
	MOVEI	S1,":"			;ISOLATE THE QUEUE NAME
	PUSHJ	P,G$CCHR##		;NOW HAVE DEV:
	MOVE	S1,.QEJOB(AP)		;THE JOB NAME
	PUSHJ	P,G$CSIX##		;ADD THAT TO THE DEVICE
	MOVEI	S1,[ASCIZ\=/Seq:\]
	PUSHJ	P,G$CSTG##		;ADD SOME MORE TEXT
	LOAD	S1,.QESEQ(AP),QE.SEQ	;GET THE SEQUENCE NUMBER
	PUSHJ	P,G$CDEC##		;THAT IS A DECIMAL NUMBER
	LOAD	S1,.QESTN(AP),QE.RQP	;GET RELATIVE QUEUE POINTER
	LOAD	S1,TBLHDR+.QHTYP(S1),QH.TYP	;GET QUEUE TYPE
	CAIN	S1,.QHTIP		;INPUT QUEUE
	  JRST	CREA.5			;YES, GIVE ANOTHER MESSAGE
	MOVEI	S1,[ASCIZ\/Limit:\]	;TELL REQUEST LIMIT
	PUSHJ	P,G$CSTG##		;APPEND
	LOAD	S1,.QELM2(AP),QE.PGS	;GET REQUEST LIMIT IN UNITS
	PUSHJ	P,G$CDEC##		;PROBABLY OUGHT TO TRY /FEET/PAGES
	MOVEI	S1,[ASCIZ/, /]		;ALIGNMENT
	PUSHJ	P,G$CSTG##		;ADD THAT
	MOVE	S1,P2			;GET THE NUMBER OF FILES IN THE REQUEST
	MOVEI	S2,[ASCIZ/ File/]	;STRING TO PLURALIZE
	PUSHJ	P,TYPPLR		;DO THE RIGHT THING
	JRST	CREA.6			;SEND THE ACK AND RETURN


				;"CREATE" IS CONTINUED ON THE NEXT PAGE
				;CONTINUED FROM THE PREVIOUS PAGE


CREA.5:	MOVEI	S1,[ASCIZ\/Time:\]	;TIME LIMIT
	PUSHJ	P,G$CSTG##		;APPEND
	LOAD	T1,.QELM2(AP),QE.TIM	;NUMBER OF SECONDS REQUESTED
	IDIVI	T1,^D3600		;HOURS IN T1
	IDIVI	T2,^D60			;MINUTES IN T2, SECONDS IN T3
	MOVE	S1,T1			;GET HOURS
	PUSHJ	P,G$CDEC##		;OUTPUT THAT
	MOVEI	S1,":"			;TIME ALIGNMENT
	PUSHJ	P,G$CCHR##		;ISOLATE PARTS
	MOVEI	S1,"0"			;IN CASE .LT.10
	CAIGE	T2,^D10			;NEED THE LEADING ZERO
	  PUSHJ	P,G$CCHR##		;YES, MAKE THE OUTPUT PRETTY
	MOVE	S1,T2			;GET MINUTES
	PUSHJ	P,G$CDEC##		;OUTPUT IT
	MOVEI	S1,":"			;TIME ALIGNMENT
	PUSHJ	P,G$CCHR##		;ISOLATE PARTS
	MOVEI	S1,"0"			;IN CASE .LT.10
	CAIGE	T3,^D10			;NEED THE LEADING ZERO
	  PUSHJ	P,G$CCHR##		;YES, MAKE THE OUTPUT PRETTY
	MOVE	S1,T3			;GET SECONDS
	PUSHJ	P,G$CDEC##		;AND ADD THAT

IFN INPCOR,<
	MOVEI	S1,[ASCIZ\/Core:\]	;NOW TYPE CORE VALUE
	PUSHJ	P,G$CSTG##		;APPEND
	LOAD	S1,.QELM2(AP),QE.COR	;GET THE VALUE
	PUSHJ	P,G$CDEC##		;OUTPUT THE NUMBER
	MOVEI	S1,"P"			;THAT NUMBER WAS IN PAGES
	PUSHJ	P,G$CCHR##		;SINCE LEAVING THAT OFF MEANS "K"
>  ;END IFN INPCOR

CREA.6:	MOVX	S1,TX.MOR		;INFORMATIONAL, MORE TO COME
	PJRST	G$MSND##		;SEND THE "ACK" AND RETURN
SUBTTL	LIST  --  Function 10

;THE PRIMARY PURPOSE OF THIS ROUTINE IS TO VALIDATE A LIST
;	REQUEST.  ONCE THIS IS DONE, THE LIST-ANSWER ROUTINE
;	(Q$LANSWER) DOES THE REST.

Q$LIST:
	LOAD	T1,.MSTYP(M),MS.CNT	;GET THE MESSAGE SIZE
	CAIGE	T1,LIS.SZ		;BIG ENOUGH?
	  PJRST	E$MTS##			;INDICATE MESSAGE TOO SHORT
	$COUNT	(MLST)			;NUMBER OF LIST MESSAGES
	LOAD	T1,LIS.QN(M)		;GET THE QUEUE NAME
	JUMPE	T1,Q$LANSWER		;ZERO INDICATES ALL QUEUES
	MOVE	S1,T1			;COPY FOR CONVERSION
	ZERO	S2			;DON'T CARE ABOUT STATION
	PUSHJ	P,I$MIDS##		;CONVERT TO INTERNAL FORM
	PJUMPE	S1,E$IFD##		;GIVE ERROR IF MALFORMED
	PUSHJ	P,Q$FHDR		;FIND THE HEADER
	SKIPN	T1,S1			;COPY HDR ADR INTO T1
	PJRST	E$UQS##			;AND LOSE IF UNKNOWN QUEUE
	LOAD	T2,.QHTYP(S1),QH.LST	;GET "LISTABLE" BIT
	PJUMPE	T2,E$CLQ##		;LOSE IF NOT SET
	JRST	Q$LANSWER		;AND GIVE HIM THE LISTING
SUBTTL	MODIFY  --  Function 11

;THE MODIFY MESSAGE IS SENT TO QUASAR BY ANY UNKNOWN COMPONENT TO CHANGE
;	THE PARAMETERS OF A REQUEST IN A PROCESSING OR AFTER QUEUE
;MODIFY PREFORMS THE FOLLOWING FUNCTIONS:
;	1 ) VALIDATE THE ARGUMENTS
;	2 ) BUILD A TEMPORARY QUEUE OF REQUESTS THAT MATCH
;	3 ) PERFORM THE MODIFY REQUEST ON EACH ELEMENT OF THE TEMPORARY QUEUE
;	4 ) CALL Q$CREATE FOR THE RESULTANT MODIFIED REQUEST
Q$MODIFY:
	PUSHJ	P,.SAVE4##		;SAVE P1-P4
	$COUNT	(MMOD)			;NUMBER OF MODIFY MESSAGES
	LOAD	P1,.MSTYP(M),MS.CNT	;GET THE COUNT FIELD
	CAIGE	P1,MOD.SZ		;TOO SMALL
	  PJRST	E$MTS##			;INDICATE MESSAGE TOO SHORT
	LOAD	S1,MOD.QN(M)		;GET THE QUEUE NAME
	ZERO	S2			;DON'T CARE ABOUT STATION
	PUSHJ	P,I$MIDS##		;CONVERT TO INTERNAL FORM
	PJUMPE	S1,E$IFD##		;GIVE ERROR IF MALFORMED
	PUSHJ	P,Q$FHDR		;FIND THE QUEUE HEADER
	SKIPN	H,S1			;PUT INTO H
	PJRST	E$UQS##			;NONE FOUND, FORGET IT

;BEFORE ACTUAL PROCESSING, CHECK THE REQUEST FOR INVALID LENGTHS AND GROUPS

	ADDI	P1,(M)			;P1 = FIRST WORD NOT IN THE MESSAGE
	MOVEI	P2,MOD.FG(M)		;P2 = THE FIRST GROUP HEADER
MODI.1:	CAIG	P1,MOD.GN(P2)		;OFF THE END OF THE MESSAGE
	  JRST	MODI.2			;YES, NOW BEGIN PROCESSING
	LOAD	P3,MOD.GN(P2),MODGPN	;GET THE GROUP NUMBER
	LOAD	P4,MOD.GN(P2),MODGLN	;AND NUMBER OF GROUP ELEMENTS
	PJUMPE	P4,E$BMG##		;CANNOT BE ZERO
	ADDI	P4,(P2)			;P4 = NEXT GROUP HEADER
	CAIG	P3,NGROUP		;INVALID GROUP NUMBER
	 CAIGE	P1,(P4)			;OR INVALID LENGTH
	  PJRST	E$BMG##			;YES, BAD MESSAGE FORMAT
	MOVEI	P2,(P4)			;POINT TO THE NEXT GROUP
	JRST	MODI.1			;CONTINUE FOR ALL PROVIDED GROUPS

;HAVING VERIFIED THE LENGTHS, BEGIN FINDING THE SPECIFIED REQUESTS

MODI.2:	PUSH	P,G$ACK##		;SAVE CALLERS "ACK" STATUS
	ZERO	G$ACK##			;SO DON'T GET MESSAGES FROM CREATE
	ZERO	MODI.C+0		;ZERO NUMBER OF REQUESTS MODIFIED
	SETOM	MODI.C+1		;INITIALLY, DON'T PRINT NUMBER OF FILES
	ZERO	MODI.C+2		;NOT CANCELLING JOBS
	ZERO	MODHDR+.QHLNK		;CLEAR LINKS OF FAKE HEADER
	PUSHJ	P,MODSET		;SET UP ARGUMENTS FOR FNDREQ
	PUSHJ	P,FNDREQ		;FIND REQUESTS IN REQUESTED QUEUE
	MOVEM	S1,MODI.C+3		;START COUNTING PROTECTION FAILURES
	PUSHJ	P,MODSET		;RESET THE ARGUMENTS
	MOVEI	H,HDRAFT		;BUT THIS TIME USE THE AFTER QUEUE
	PUSHJ	P,FNDREQ		;FIND ANY THERE
	ADDM	S1,MODI.C+3		;MORE PROTECTION FAILURES
	MOVEM	M,MODI.A		;SAVE ORIGINAL MESSAGE ADDRESS
				;"MODIFY" IS CONTINUED ON THE NEXT PAGE
				;CONTINUED FROM PREVIOUS PAGE

;NOW, FLUSH THE TEMPORARY QUEUE, MODIFYING, RE-CREATING AS WE GO

MODI.3:	LOAD	AP,MODHDR+.QHLNK,QH.PTF	;GET THE TOP OF THE TEMPORARY QUEUE
	JUMPE	AP,MODI.6		;PROCESSED THEM ALL (OR NONE)
	LOAD	H,.QESTN(AP),QE.RQP	;GET THE RELATIVE QUEUE POINTER
	ADDI	H,TBLHDR		;MAKE A REAL POINTER OUT OF IT
	LOAD	S1,.QESTN(AP),QE.DPA	;GET THE RETREIVAL POINTER
	PUSHJ	P,F$RDRQ##		;READ IN THE ORIGINAL REQUEST
	MOVEM	S1,MODI.B		;SAVE FOR LATER RELEASE
	MOVE	AP,S1			;ARGUMENT FOR MODIFIER ROUTINES
	MOVE	M,MODI.A		;GET MODIFY MESSAGE BACK
	LOAD	P1,.MSTYP(M),MS.CNT	;NOW LOOP FOR ALL GROUP HEADERS
	ADDI	P1,(M)			;P1 = FIRST WORD NOT IN THE MESSAGE
	MOVEI	P2,MOD.FG(M)		;P2 = THE FIRST GROUP
MODI.4:	CAIG	P1,MOD.GN(P2)		;OFF THE END OF THE MESSAGE
	  JRST	MODI.5			;YES, DONE WITH THIS MATCH
	LOAD	P3,MOD.GN(P2),MODGPN	;GET THE GROUP NUMBER
	MOVEI	S1,(P2)			;ARGUMENT FOR MODIFIERS
	PUSHJ	P,@GRPDIS(P3)		;CALL THE PROPER MODIFIER FOR THIS GROUP
	LOAD	P3,MOD.GN(P2),MODGLN	;ADJUST FOR THE NEXT GROUP
	ADDI	P2,(P3)			;P2 = THE NEXT GROUP
	JRST	MODI.4			;CONTINUE FOR ALL GROUPS PROVIDED

;HERE AFTER ALL GROUP MODIFIES HAVE BEEN DONE, LINK IN THE NEW REQUEST

MODI.5:	MOVE	M,MODI.B		;ARGUMENT FOR CREATE = MODIFIED REQUEST
	MOVX	T1,.QIFNC		;THIS IS AN INTERNAL CALL
	STORE	T1,.MSTYP(M),MS.TYP	;SET FOR Q$CREATE
	PUSHJ	P,Q$CREATE		;PUT MODIFIED REQUEST BACK IN PLACE
	SKIPE	G$ERR##			;DID THE CREATE WORK
	  STOPCD(CRM,FATAL)		;++CREATE REJECTED MODIFY
	LOAD	AP,MODHDR+.QHLNK,QH.PTF	;GET OLD QUEUE ENTRY BACK
	LOAD	S1,.QESTN(AP),QE.DPA	;THE RETREIVAL POINTER
	PUSHJ	P,F$RLRQ##		;RELEASE OLD FAILSOFT COPY
	MOVEI	H,MODHDR		;POINT TO THE TEMPORARY QUEUE
	PUSHJ	P,M$DLNK##		;REMOVE ENTRY ALREADY MODIFIED
	LOAD	H,.QEPID(AP)		;QUEUE THIS ENTRY CAME FROM (PROC, OF AFTER)
	PUSHJ	P,M$PFRE##		;RETURN TO PROPER FREE LIST
	MOVE	AP,MODI.B		;ADDRESS OF OLD FAILSOFT COPY
	ADR2PG	AP			;MAKE A PAGE NUMBER
	PUSHJ	P,M$RELP##		;NO LONGER NEED IT
	JRST	MODI.3			;GET ANY OTHER MATCHING REQUESTS

;NOW, GENERATE "ACK" AND RETURN TO THE CALLER

MODI.6:	POP	P,G$ACK##		;RESTORE "ACK" STATUS
	MOVEI	T1,MODI.C		;ARGUMENT BLOCK FOR BLDKMS
	MOVEI	T2,[ASCIZ/ Modified/]	;TEXT TO APPEND
	PJRST	BLDKMS			;BUILD KILL/MODIFY STRING AND RETURN
; SUBROUTINES USED BY MODIFY

;ROUTINE CALL BE MODIFY LOOP TO SET UP ARGUMENTS FOR FNDREQ

MODSET:	MOVNI	T1,1			;INDICATE MODIFY REQUEST
	MOVEI	T2,MOD.RQ(M)		;RDB FOR KILL/MODIFY
	MOVE	T3,H			;NEED AN RQP
	SUBI	T3,TBLHDR		;SO GENERATE ONE FOR THIS QUEUE
	MOVEI	T4,MODS.1		;SUBROUTINE TO CALL FOR MATCHES
	POPJ	P,			;RETURN FOR CALL TO FNDREQ

;HERE WHEN FNDREQ FINDS A MATCH FOR THE MODIFY BLOCK, ACCUMULATE IN THE TEMP QUEUE

MODS.1:	STORE	H,.QEPID(AP)		;SAVE QUEUE THAT CONTAINED THIS ENTRY
	PUSHJ	P,M$DLNK##		;REMOVE FROM PROCESSING OR AFTER QUEUE
	MOVEI	H,MODHDR		;POINT TO THE TEMPORARY QUEUE
	PUSHJ	P,M$ELNK##		;LINK IN AT THE END
	AOS	MODI.C+0		;INCREMENT COUNT OF MODIFIED REQS
	POPJ	P,			;RETURN FOR NEXT MATCH


;THE DISPATCH TABLE FOR GROUP MODIFIES

GRPDIS:	EXP	MAJMOD			;GROUP 0 = MAJOR QUEUE PARAMETERS
	EXP	GRPMOD			;GROUP 1 = QUEUE DEPENDENT PARAMETERS
	EXP	MODFIL			;GROUP 2 = FILE-SPECIFIC PARAMETERS
NGROUP==<.-GRPDIS>-1			;HIGHEST KNOWN GROUP NUMBER

GRPMOD:	LOAD	P3,.QHPAG(H),QH.SCH	;GET SCHEDULING BASE
	PJRST	SCHMOD(P3)		;DO QUEUE DEPENDENT MODIFY
MODFIL:	SKIPGE	MODI.C+1		;ALREADY HERE ONCE
	  SETZM	MODI.C+1		;NO, START COUNTING FILES MODIFIED
	PUSHJ	P,FILMOD		;DO THE MODIFY
	ADDM	S1,MODI.C+1		;ADD NUMBER OF FILES THAT MATCHED
	POPJ	P,			;GET ANOTHER GROUP

MODHDR:	BLOCK	QHSIZE			;HEADER FOR THE TEMPORARY QUEUE

MODI.A:	BLOCK	1			;ORIGINAL 'M'
MODI.B:	BLOCK	1			;WHERE REQUEST HAS BEEN READ BY FAILSOFT
MODI.C:	BLOCK	4			;ARGUMENT BLOCK FOR BLDKMS
SUBTTL	KILL  --  Function 12

;THE KILL MESSAGE IS SENT TO QUASAR BY ANY UNKNOWN COMPONENT TO
;	DELETE AN ENTRY FROM A QUEUE.
;KILL PERFORMS THE FOLLOWING FUNCTIONS:
;	1) VALIDATE THE ARGUMENTS
;	2) LOOP THROUGH THE USE QUEUE ABORTING MATCHES.
;	3) LOOP THROUGH THE PROCESSING QUEUE DELETING MATCHES.
;	4) LOOP THROUGH THE AFTER QUEUE DELETING MATCHES.

Q$KILL:	PUSHJ	P,.SAVE3##		;SAVE P1-P3
	$COUNT	(MKIL)			;NUMBER OF KILL MESSAGES
	LOAD	T1,.MSTYP(M),MS.CNT	;GET MESSAGE SIZE
	CAIGE	T1,KIL.SZ		;BIG ENOUGH?
	  PJRST	E$MTS##			;INDICATE MESSAGE TOO SHORT
	LOAD	S1,KIL.QN(M)		;GET THE QUEUE NAME
	ZERO	S2			;DON'T CARE ABOUT STATION
	PUSHJ	P,I$MIDS##		;CONVERT TO INTERNAL FORM
	PJUMPE	S1,E$IFD##		;GIVE ERROR IF MALFORMED
	PUSHJ	P,Q$FHDR		;AND FIND THE QUEUE HEADER
	SKIPN	H,S1			;LOAD HDR ADR INTO H
	PJRST	E$UQS##			;UNKNOWN QUEUE SPECIFIED
	MOVE	P3,S1			;GET ADR OF QUE HDR
	SUBI	P3,TBLHDR		;AND MAKE AN RQP FROM IT
	ZERO	P1			;INDICATE KILL REQUEST
	MOVEI	P2,KIL.RQ(M)		;REQUEST DESCR BLOCK FOR FNDREQ
	ZERO	KILL.A+0		;ZERO NUMBER KILLED
	SETOM	KILL.A+1		;DON'T COUNT FILES
	ZERO	KILL.A+2		;NUMBER CANCELLED

;NOW, SETUP AND LOOP THRU THE NECESSARY QUEUES

KILL.1:	PUSH	P,H			;SAVE PROCESSING QUEUE HDR
	MOVE	T4,[P1,,T1]		;MOVE PERMENANT ARGS TO REAL ARGS
	BLT	T4,T3			;COPY P1 - P3
	MOVEI	T4,KILL.9		;SUBROUTINE TO CALL
	MOVEI	H,HDRUSE		;LOAD ADR OF USE QUEUE HDR
	PUSHJ	P,FNDREQ		;FIND A MATCHING REQUEST
	MOVEM	S1,KILL.A+3		;START COUNTING PROT FAILURES
	MOVE	T4,[P1,,T1]		;NEED ARGUMENTS AGAIN
	BLT	T4,T3			;SO MOVE THEM
	MOVEI	T4,KILL.8		;NEW ROUTINE TO CALL
	POP	P,H			;GET ADR OF PROCESSING Q HDR
	PUSHJ	P,FNDREQ		;AND CHECK IT
	ADDM	S1,KILL.A+3		;COUNT PROTECTION FAILURES
	MOVEI	H,HDRAFT		;LOAD ADR OF AFT HEADER
	MOVE	T4,[P1,,T1]		;ONE MORE TIME
	BLT	T4,T3			;BUT NOW FNDREQ IS USABLE BY Q$MODIFY
	MOVEI	T4,KILL.8		;SAME PLACE FOR THE AFTER QUEUE
	PUSHJ	P,FNDREQ		;LOOP THRU THE AFTER QUEUE
	ADDM	S1,KILL.A+3		;MORE PROTECTION FAILURES
	MOVEI	T1,KILL.A		;ARGUMENT BLOCK FOR BLDKMS
	MOVEI	T2,[ASCIZ/ Killed/]	;TEXT TO APPEND
	PJRST	BLDKMS			;BUILD KILL/MODIFY STRING AND RETURN
; SUBROUTINES USED DURING KILL

;FOLLOWING ARE THE CO-ROUTINES (SORT OF) WHICH ARE CALLED BY FNDREQ
;
;ROUTINE TO ACTUALLY TAKE A REQUEST OUT OF A PROCESSING QUEUE OR THE
;	AFTER QUEUE.

KILL.8:	AOS	KILL.A+0		;INCREMENT KILL COUNT
	MOVE	T1,AP			;COPY CELL ADDRESS
	LOAD	T2,.QESEQ(AP),QE.SPL	;DOES REQ CONTAIN SPOOLED FILES?
	JUMPN	T2,KIL.8A		;YES, SET RDE AND RETURN
	LOAD	S1,.QESTN(AP),QE.DPA	;NO, GET DISK ADDRESS
	PUSHJ	P,F$RLRQ##		;RELEASE THE DISK REQUEST
	PUSHJ	P,M$RFRE##		;RELEASE THE QUEUE ENTRY
	POPJ	P,			;AND RETURN TO KILLUP

KIL.8A:	SAVE	H			;SAVE THE QUEUE HEADER
	PUSHJ	P,SETRDE		;SET THE RDE BIT IN QE AND EQ
	MOVEI	S1,HDRRDE		;GET THE RDE HEADER
	PJRST	M$MOVE##		;AND MOVE THE REQUEST

;ROUTINE TO CAUSE AN ABORT MESSAGE TO BE SENT TO A KNOWN COMPONENT
;	ON A KILL OF A JOB IN THE USE QUEUE.

KILL.9:	SAVE	AP			;SAVE CALLERS AP
	MOVE	T1,AP			;GET ADR OF QE AREA
	PUSHJ	P,SETRDE		;SET RDE IN BOTH .EQ AND .QE
	MOVE	T1,AP			;LOAD ARGUMENT FOR ABORT
	AOS	KILL.A+2		;INCREMENT ABORTED COUNT
	PJRST	Q$ABORT			;SEND THE ABORT AND RETURN


KILL.A:	BLOCK	4			;ARGUMENT BLOCK FOR BLDKMS
SUBTTL	LISTANSWER  --  Function 13

;LISTANSWER IS CALLED TO SEND AN ANSWER BACK ON A LIST REQUEST.
;	CALL WITH T1 CONTAINING ADDRESS OF QUEUE HEADER FOR THE
;	QUEUE TO BE LISTED, OR ZERO IF ALL QUEUES ARE TO BE LISTED.

Q$LANSWER:
	PUSHJ	P,.SAVE2##		;SAVE P1 AND P2
	PUSHJ	P,I$NOIN##		;DON'T ALLOW INTERRUPTS
	MOVE	S1,LISSIZ		;GET SIZE OF LAST COMPL LISTING
	SKIPE	P1,T1			;DOES HE JUST WANT A PARTIC. Q?
	LOAD	S1,.QHPAG(T1),QH.NTL	;YES, GET IT'S NUMBER
	ADDI	S1,1			;PAD IT A LITTLE
	PUSHJ	P,M$PCNT##		;SEE IF WE CAN GET IT
	PJUMPE	S1,E$CBL##		;NO, LOSE NOW!
	MOVX	S1,TX.NMS		;NO MESSAGE FLAG
	SKIPE	G$ACK##			;DOES USER WANT AN ACK?
	PUSHJ	P,G$MSND##		;YES, SEND IT
	MOVE	T2,[LANS.A,,LANS.A+1]	;SETUP A BLT POINTER
	CLEARM	LANS.A			;CLEAR PAGE SEQ NUMBER
	BLT	T2,LANS.Z		;AND CLEAR THE OTHER LOCALS
	PUSH	P,[EXP LANEND]		;PLACE TO GO BEFORE RETURNING
	JUMPE	P1,LANS.1		;JUMP IF HE WANTS ALL QUEUES

	PUSHJ	P,LANQUE		;DO THE LISTING
	MOVE	S1,LANS.A		;GET NUMBER OF PAGES NEEDED
	STORE	S1,.QHPAG(P1),QH.NTL	;SAVE IT FOR NEXT TIME
	POPJ	P,			;AND RETURN

LANS.1:	MOVEI	P2,0			;START AT QUEUE 0
LANS.2:	CAIL	P2,NQUEUE		;GOT THEM ALL?
	JRST	LANS.3			;YUP, FINISH UP AND RETURN
	MOVE	P1,P2			;NO, GET QUEUE NUMBER
	IMULI	P1,QHSIZE		;CONVERT TO OFFSET
	ADDI	P1,TBLHDR		;GET ADDRESS IN P1
	LOAD	T2,.QHTYP(P1),QH.LST	;GET "LISTABLE" BIT
	SKIPE	T2			;SKIP IF NOT SET
	PUSHJ	P,LANQUE		;ELSE LIST THE QUEUE
	AOJA	P2,LANS.2		;AND LOOP

LANS.3:	MOVE	S1,LANS.A		;GET NUMBER OF PAGES NEEDED
	MOVEM	S1,LISSIZ		;SAVE FOR NEXT TIME
	POPJ	P,			;AND RETURN
;HERE TO LIST QUEUE WHOSE HEADER ADDRESS IS IN P1
LANQUE:	PUSHJ	P,.SAVE2##		;SAVE P1 AND P2
	MOVE	P2,P1			;GET ADR OF Q HDR
	SUBI	P2,TBLHDR		;MAKE AN RQP
	MOVEI	H,HDRUSE		;START WITH USE QUEUE
	LOAD	T1,.QHLNK(H),QH.PTF	;GET ADDRESS OF FIRST
	JUMPE	T1,LANQ.3		;NONE, GO DO AFT QUEUE

LANQ.1:	LOAD	T2,.QESTN(T1),QE.RQP	;GET RQP FROM REQUEST
	CAME	P2,T2			;CORRECT QUEUE?
	JRST	LANQ.2			;NO, GET NEXT ENTRY
	LOAD	T2,.QESEQ(T1),QE.RDE	;GET THE RDE BIT
	JUMPN	T2,LANQ.2		;REQUEST DOESN'T EXIST!!
	PUSHJ	P,LANMSG		;YES, GET SPACE
	PUSHJ	P,LANMOV		;MOVE COMMON STUFF
	MOVE	T2,.QECRE(T1)		;GET CREATION TIME
	CAIN	H,HDRAFT		;IS THIS THE AFTER QUEUE?
	MOVEM	T2,LST.AF(AP)		;YES, STORE IT
	MOVE	T2,.QEDEV(T1)		;GET PROCESSING DEVICE
	CAIN	H,HDRUSE		;IS THIS THE USE QUEUE?
	MOVEM	T2,LST.PV(AP)		;YES, STORE IT
LANQ.2:	LOAD	T1,.QELNK(T1),QE.PTN	;GET PTR TO NEXT ENTRY
	JUMPN	T1,LANQ.1		;AND LOOP
LANQ.3:	CAIN	H,HDRAFT		;E-O-LIST, WERE WE DOING AFT?
	JRST	LANQ.4			;YES, GO DO THE EXTERNAL QUEUE
	MOVEI	H,HDRAFT		;NO, DO THE AFTER
	LOAD	T1,.QHLNK(H),QH.PTF	;GET PTR TO FIRST
	JUMPN	T1,LANQ.1		;GO TO IT

;HERE TO LIST THE EXTERNAL QUEUE
LANQ.4:	MOVE	H,P1			;GET ADDRESS OF HEADER
	LOAD	T1,.QHLNK(H),QH.PTF	;GET POINTER TO FIRST
	JUMPE	T1,.POPJ##		;DONE IF NONE

LANQ.5:	PUSHJ	P,LANMSG		;GET SOME SPACE
	PUSHJ	P,LANMOV		;MOVE COMMON STUFF
	LOAD	T1,.QELNK(T1),QE.PTN	;GET POINTER TO NEXT
	JUMPN	T1,LANQ.5		;AND LOOP OVER WHOLE QUEUE
	POPJ	P,			;WE ARE DONE!!


				;"LISTANSWER" IS CONTINUED ON NEXT PAGE
;HERE AT THE END OF LIST, TO TERMINATE THE LAST PAGE AND FORCE IT OUT
LANEND:	PUSHJ	P,LANMSG		;GET SOME SPACE (AVOID BOUNDRY PROBLEMS)
	MOVE	T1,LANS.B		;GET CURRENT PAGE NUMBER
	PG2ADR	T1			;MAKE IT AN ADDRESS
	MOVX	T2,1B0			;LOAD BIT ZERO
	IORM	T2,.MSTYP(T1)		;SET "LAST PAGE" FLAG
	PJRST	LANSND			;AND SEND THE LAST PAGE


;SUBROUTINE TO MOVE COMMON STUFF FROM ENTRY TO LISTANSWER.
;	T1=ENTRY	AP=ANSWER
LANMOV:	MOVE	T2,.QEJOB(T1)		;GET JOB NAME
	MOVEM	T2,LST.JB(AP)		;STORE IN ANSWER
	MOVE	T2,.QESTR(T1)		;GET STRUCTURE CONTAINING THE REQUEST
	MOVEM	T2,LST.ST(AP)		;STORE FOR LISTER
	LOAD	T2,.QESEQ(T1),QE.SEQ	;GET SEQUENCE FIELD
	STORE	T2,LST.SQ(AP),LS.SEQ	;AND STORE IN ANSWER
	LOAD	T2,.QEPRT(T1),QE.PRO	;GET PROTECTION OF REQUEST
	STORE	T2,LST.SQ(AP),LS.PRO	;AND STORE IT
	MOVE	T2,.QEOID(T1)		;THE OWNER ID
	MOVEM	T2,LST.OI(AP)		;AND STORE
	MOVSI	T2,.QELM1(T1)		;POINT TO LIMIT WORDS
	HRRI	T2,LST.LM(AP)		;AND MAKE A BLT POINTER
	BLT	T2,LST.LM+4(AP)		;AND B