Google
 

Trailing-Edge - PDP-10 Archives - AP-D543V_SB - rttrp.mac
There are 11 other files named rttrp.mac in the archive. Click here to see a list.
TITLE	RTTRP - REAL TIME TRAPPING ROUTINES - V2100
SUBTTL P. HURLEY/PFC/JE  TS  22 AUG 78
	SEARCH	F,S
	$RELOC
	$HIGH



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

		;RTTRP IS A COMPLETELY REENTRANT UUO CALLABLE
		;FROM ALL PI LEVELS TO CHAIN AND UNCHAIN DEVICES
		;ONTO THE MONITOR DEVICE CHAINS.
		;IT ALSO PROVIDES THE CAPABILITY OF ALLOWING AN
		;INTERRUPT FROM ANY DEVICE TO TRANSFER PROGRAM
		;CONTROL TO A USER PROGRAM AT INTERRUPT LEVEL
		;IN RESPONSE TO THAT INTERRUPT.
		;RTTRP TAKES CARE OF ALL CONTEXT SWITCHING WHICH
		;IS NECESSARY AND CHANGING THE  RELOCATION AND
		;PROTECTION REGISTER,  THUS PERMITTING MORE THAN
		;ONE JOB AT A TIME TO BE CONTROLING DEVICES ON THE
		;INTERRUPT LEVELS WITHOUT STOPPING TIME SHARING.

	ENTRY	RTTRP
	INTERNAL APRCHK,MRELTB,RTREL,RTBSIZ
	EXTERNAL RTBLK,CHNTAB,RTOFST,RTTRPN,DSMTAB,.CPRTT,TRPFLG,STOTAC
	EXTERNAL MRTRPN,JOBPFI,JBTRTD,JOBPD1,MJOBN
	EXTERNAL JBTSTS,PION,PIOFF,JOBCNI
	EXTERNAL APRER9,APRPTS
	EXTERNAL MPTRP2,TIME,.CPUPT,.CPTMF,.CPCKF,XI.RQC,.CPCHL
	EXTERNAL .C0LUC,.C0CN1,.C0DTO,CPOPJ1
	INTERN	CHAINT,RTLINK,SAV61,SAV41,BLKENB
; RIGHT HALF OF S - ERROR BIT DEFINITIONS

	E35==1B35	;PI CHANNEL NOT AVAILABLE, USED BY MONITOR FOR BLKI/O
	E34==1B34	;PI CHANNEL NOT CURRENTLY AVAILABLE FOR BLKI/O
	E33==1B33	;TRAP ADDRESS OUT OF BOUNDS
	E32==1B32	;ERROR ADDRESS OUT OF BOUNDS
	E31==1B31	;BLKADR OR POINTER WORD OUT OF BOUNDS
	E30==1B30	;SYNTAX ERROR IN FORMAT, NO CONSO OR BLKI/O INSTRUCTION
	E29==1B29	;NO MORE RT BLOCKS LEFT
	E28==1B28	;JOB NOT LOCKED IN CORE
	E27==1B27	;ILLEGAL AC USED AT INTERRUPT LEVEL CALL
	E26==1B26	;DEVICE ALREADY IN USE BY ANOTHER JOB
	E25==1B25	;JOB SET TO RUN ON CPU1 ONLY - TEMPORARILY NOT SUPPORTED
	E24==1B24	;JOB DOES NOT HAVE PRIVILEGES

;LEFT HALF OF S BIT DEFINITIONS

	INDBIT==1	;INDIRECT BIT SET IN CONSO INSTRUCTION
	CNSO==2		;CONSO INSTRUCTION
	RTINT==4	;UUO ENTERED FROM INTERRUPT LEVEL
	BLKIO==10	;BLKI/O TO GO ON CHANNEL
	NOREM==20	;DO NOT REMOVE DEVICES FROM CHAINS BEFORE LINKING
			; ANOTHER DEVICE ONTO THE CHAIN
	NOSAV==40	;EXEC MODE TRAPPING, DON'T DO CONTEXT SWITCH
	VECTOR==100	;DEVICE INTERRUPTS BY EXECUTING AN INTERRUPT VECTOR
	EPTREL==200	;INTERRUPT INSTRUCTION IS TO BE STORED RELATIVE TO THE EPT

;CHNTAB LEFT HALF BIT DEFINITIONS

	BLKENB==1	;BLKI/O INSTRUCTIONS ALLOWED ON THIS CHANNEL
	BINUSE==2	;BLKI/O INSTRUCTION IN USE PRESENTLY ON THIS CHANNEL
	BLKSAV==4	;BLKI/O INSTRUCTION BEING REPLACED BY ANOTHER BLKI/O
	BM1==400000	;CHANNEL CAN CURRENTLY BE USED FOR BLKI/O

REPEAT 0,<
;AC DEFINITIONS - *** CHANGED TO STANDARD ON JUNE 1, 1971

	IWD=U		;BLKI/O IOWD
	BLK=F		;BLKI/O INSTRUCTION
	RTB=T4		;RT BLOCK BASE ADDRESS
	PIAC=P1		;PI CHANNEL NUMBER
	TRP=P2		;TRAP ADDRESS
	INS=W		;CONSO INSTRUCTION
	ENB=M		;ENABLE BITS

	RTUUO=17	;THESE TWO AC'S CANNOT BE USED IN CALLS FROM INTERRUPT LEVEL
	RTUUO1=16	;RTUUO CONTAINS USER PC, AND RTUUO1 IS A SCRATCH
>
IFN P4-17,<	PRINTX	?P4 MUST REMAIN AS AC 17
>
IFN P3-16,<	PRINTX	?P3 MUST REMAIN AS AC 16
>

;OTHER DEFINITIONS

	RTUUON==57	;UUO CALLI NUMBER
	USER==10000	;USER MODE BIT
	USRIOT==4000	;USER IOT PRIVELEGE BIT
	RTUSE==1000	;REAL TIME BLOCK IS BEING USED
	VECUSE==2000	;RTBLK IN USE BY A VECTOR INTERRUPT DEVICE
			; NOT ON THE CONSO CHAIN
	WAKUUO==73	;WAKE UUO CALLI NUMBER
	JSRMOD==1	;DO JSR TO TRPADR WITH NO CONTEXT SWITCH
	VTRMOD==2	;IF DEVICE DOES VECTORED INTERRUPTS
	EPTMOD==4	;IF THE INTERRUPT JSR INSTRUCTION IS TO BE STORED RELATIVE
			; TO THE EPT
;REAL TIME BLOCK DEFINITIONS AND FORMAT

	RTCNSO==0	;CONSO DEV,BITS		;CHAIN INSTRUCTION
	RTJRST==1	;JRST NXTDEV		;CONTINUE ON IN CHAIN
	RTBLKO==2	;BLKO DEV,POINTR	;IF NO BLKI/O THEN JRST .+3
	RJRST1==3	;JRST .+2		;BLKI/O COUNTED OUT
	RTJEN==4	;JEN @CHN		;DISMISS INTERRUPT
	RTJSR==5	;JSR SAV'PI		;SAVE THE AC'S
	RTJSP==6	;JSP J,TRPGO		;SAVE THE STATE OF THE MACHINE
	TABST==RTJSP+1
	ENBTAB==7	;APR CONO BITS
	RELTAB==10	;RELOCATION-PROTECTION TABLE
	UENBTB==11	;USER APR INTERRUPT ENABLE BITS
	TRPTAB==12	;USER TRAP ADDRESS
	JADRTB==13	;JBTADR VALUE FOR THIS JOB
	APRTAB==14	;XWD R, APRTRP
	JOBTB==15	;XWD DEV CODE, JOB #
	PITAB==16	;XWD 0,PI CHANNEL
	DISMTB==17	;JRST CHAND'PI

	ENBTB1==:ENBTAB-TABST
	RELTB1==:RELTAB-TABST
	UENBT1==:UENBTB-TABST
	TRPTB1==:TRPTAB-TABST
	JADRT1==:JADRTB-TABST
	APRTB1==:APRTAB-TABST
	JOBTB1==:JOBTB-TABST
	PITB1==:PITAB-TABST
	DISMT1==:DISMTB-TABST
		IFN ENBTB1,<PRINTX ENBTAB MUST BE THE FIRST ENTRY IN TABLE
>
	MRELTB==-RELTAB
	RTBSIZ==20	;REAL TIME BLOCK SIZE

;DESCRIPTION OF TABLES USED BY RTTRP

	;JBTRDT = COUNT OF REAL TIME DEVICES ON INTERRUPT SYSTEM FOR EACH JOB
		;JBTRTD IS INDEXED BY JOB NUMBER

	;CUSETB = COUNT OF REAL TIME DEVICES ON EACH PI CHANNEL
		;CUSETB IS INDEXED BY PI NUMBER MINUS 1

	;CHNTAB = XWD STATUS,CH'PI
		;STATUS DESCRIBES STATE OF CHANNEL  IE BEING USED BY BLKI INSTRUCTION
		;CH'PI IS THE ADDRESS OF THE CHANNEL ROUTINE FOR THAT LEVEL
		;CHNTAB IS INDEXED BY PI NUMBER MINUS 1

	;DSMTAB = XWD JSRADR,DISMIS ADR
		;JSR ADR = ADDRESS OF CHANNEL ROUTINE TO SAVE THE AC'S
		;DISMIS ADR IS THE ADDRESS OF CHANNEL DISMISS ROUTINE
		;DSMTAB IS INDEXED BY PI NUMBER MINUS 1

	;CHAINT = C(CH'PI+1)
		;THIS IS USED TO RESTORE THE PI CHAINS TO ORIGINAL
		;STATE DURING A 140 OR A 143 RESTART
		;CHAINT IS INDEXED BY PI NUMBER MINUS 1
	;RTTRP IS THE ENTRY POINT FROM UUOCON DURING A CALL
	;FROM A USER ON LEVEL 8 (I.E. NORMAL TIME SHARING).

	;RTTRP1 IS THE ENTRY POINT FROM A UUO GIVEN FROM
	;A PROGRAM RUNNING AT PRIORITY INTERRUPT LEVEL

	;J = JOB #
	;R = JBTADR(J)
	;T1  = CONTENTS OF UUO AC
	;RTUUO= RETURN ADDRESS IF ENTERED FROM INTERRUPT LEVEL
	INTERN	FTPRV

RTTRP:	PUSHJ	P,SAVE3##	;SAVE P1-P3
	PUSH	P,M		;SAVE THE UUO AC
	SETZ	S,		;INITIALIZE FLAG REGISTER
IFN FTPRV,<
	MOVE	T2,JBTPRV##(J)	;GET USER PRIVELEGE BITS
	TLNN	T2,PVRTT	;DOES THE USER HAVE THE PROPER PRIVELEGES
	TRO	S,E24		;NO, SET THE ERROR BIT>
IFN FTLOCK,<			;LOCK UUO FEATURE?
	PUSHJ	P,LOKCHK##	;JOB LOCKED IN CORE?
IFN FTKA10,<
	  SKIPA			;YES, MUST BE TO DO RTTRP
>
IFN FTKI10!FTKL10,<
	  PUSHJ	P,LOKEVC##	;ALSO MUST BE LCOKED IN EVM ON KI10
>
>
	  TRO	S,E28		;NO, SET ERROR BIT
IFN FTMS,<			;DUAL CPU?
	PUSHJ	P,CHKCPU##	;IS JOB ON CPU1 ONLY?
	  TRO	S,E25		;YES, SET ERROR BIT
				;NO, FORCE JOB TO CPU0 ONLY
>
	PUSHJ	P,GETTAC##	;SET UP T1 AGAIN
;HERE AT INTERRUPT LEVEL TO DO RTTRP UUO
	SKIPA	P1,[15]		;FIRST NONUSABLE AC
RTTRP1:	SETZ	P1,		;NO AC AT INTERRUPT LEVEL
	HRRZ	P2,T1		;ADDRESS OF ARG LIST
	MOVS	U,R		;GET LENGTH OF USER LOW SEGMENT
	CAILE	P2,JOBPFI	;IS ADR ABOVE PROTECTED AREA
	CAILE	P2,(U)		;YES, IS ADR BELOW TOP OF USER AREA
	JRST	[CAIL P2,(P1)	;VALID AC?
		 JRST ERR30	;NO
		 JRST .+1]	;YES
IFN FTKI10!FTKL10,<
	SKPCPU(IL)		;HARDWARE WILL RELOCATE IF KI10
>
	HRLI	T1,R		;ADD RELOCATION AC TO T1 TO PICK UP ARGS
	EXCTUX	<HLRE	P1,@T1>	;PICK UP PI CHANNEL #
	JUMPE	P1,REMOVE	;IF NO PI CHANNEL THEN REMOVE DEVICE
	JUMPG	P1,RTTRP2	;IS THIS A REGULAR RTTRP CALL
	MOVNS	P1		;NO, GET POSITIVE PI LEVEL
	TLO	S,NOREM		;NOTE THAT NO DEVICES ARE TO BE REMOVED
RTTRP2:	CAIGE	P1,7		;IS PI OUT OF BOUNDS
	SKIPN	CHNTAB-1(P1)	;IS CHANNEL LEGAL FOR RTTRP USE
	TRO	S,E35		;NO, SET ERROR BIT
	EXCTUX	<HRRZ	P2,@T1>	;GET TRAP ADDRESS
	CAILE	P2,JOBPFI	;IS THIS ABOVE THE PROTECTED AREA?
	CAILE	P2,(U)		;IS THIS LESS THAN TOP OF CORE AREA?
	TRO	S,E33		;NO, SET PROPER ERROR BIT
	HRRI	T1,1(T1)	;MAKE T1 POINT TO NEXT ARGUMENT
	EXCTUX	<HRRZ	M,@T1>	;GET APR TRAP ADDRESS
	CAILE	M,JOBPFI	;IS IT ABOVE PROTECTED AREA
	CAILE	M,(U)		;AND BELOW TOP OF CORE AREA?
	TRO	S,E32		;NO, SET ERROR BIT
	EXCTUX	<HLL	M,@T1>	;GET LEFT HALF OF SECOND WORD
	TLNE	M,JSRMOD	;IS THIS AN EXEC MODE TRAPPING REQUEST
	TLO	S,NOSAV		;YES, REMEMBER IT
	TLNE	M,VTRMOD	;WAS VECTORED INTERRUPT MODE SPECIFIED?
	TLO	S,VECTOR	;YES, REMEMBER THAT
	TLNE	M,EPTMOD	;INTERRUPT INSTRUCTION TO BE STORED RELATIVE TO THEE EPT?
	TLO	S,EPTREL	;YES, REMEMBER THAT
	HRRI	T1,1(T1)	;T1 NOW POINTS TO THIRD ARGUMENT
	EXCTUX	<HLRZ	T2,@T1>	;PICK UP INTERRUPT INSTRUCTION
	TRZ	T2,77400	;ZERO OUT DEVICE CODE
	TRZE	T2,17		;INDEX FIELD SHOULD ALSO BE ZERO
	TRO	S,E30		;IT ISN'T, SET ERROR BIT
	TRZE	T2,20		;IS THE INDIRECT BIT ON
	TLO	S,INDBIT	;YES, NOTE THAT FACT
	CAIE	T2,(CONSO)	;IS THIS A CONSO INSTRUCTION?
	JRST	BLKINS		;NO, TRY FOR BLKI/O INSTRUCTION
				;FALL THROUGH TO NEXT PAGE
	TLO	S,CNSO		;MARK THAT THIS IS A CONSO INSTRUCTION
	TLNN	S,INDBIT	;IS THIS AN INDIRECTION CALL
	JRST	RTTRP3		;NO
	EXCTUX	<HRRZ	T2,@T1>	;YES, PICK UP INSTRUCTION
	CAILE	T2,JOBPFI	;CHECK IF IT IS IN BOUNDS
	CAILE	T2,(U)		;ABOVE LOWER LIMIT AND BELOW UPPER LIMIT?
	TRO	S,E30		;NO, SET ERROR BIT
RTTRP3:	EXCTUX	<MOVE	P3,@T1>	;PICK UP INSTRUCTION AGAIN
	TLZE	S,INDBIT	;IS THE INDIRECT BIT SET
	ADDI	P3,(R)		;YES, RELOCATE ONCE
	HRRI	T1,1(T1)	;MAKE T1 POINT TO NEXT ARGUMENT
	EXCTUX	<HLRZ	T2,@T1>	;GET INSTRUCTION PART OF ARG
	JUMPE	T2,BLKRET	;IF IT IS ZERO THEN FORGET IT
	TRZ	T2,77400	;ZERO OUT DEVICE CODE
	TRZE	T2,37		;INDEX OR INDIRECT BITS ON
	TRO	S,E30		;YES, ERROR

	;BLKI/O INSTRUCTION, CHECK BOUNDRY CONDITIONS

BLKINS:	TRZ	T2,100		;COMMON BIT TO BLKI AND BLKO
	TLNN	S,INDBIT	;INDIRECT BIT SET
	CAIE	T2,(BLKI)	;BLKI OR BLKO
	JRST	VECINS		;NO, MAYBE VECTORED INTERRUPT
	EXCTUX	<HRRZ	T2,@T1>	;GET BLKADR
	CAILE	T2,JOBPFI	;CHECK BOUNDRY CONDITIONS
	CAILE	T2,(U)		;ABOVE LOWER BOUND AND BELOW UPPER BOUND?
	JRST	ERR31		;NO, GO SET ERROR BIT
	HLL	T2,T1		;SET UP FOR RELOCATION
	EXCTUX	<MOVE	T3,@T2>	;PICK UP BLOCK ADDRESS AND WORD COUNT
	HLRO	T4,T3		;GET NEGATIVE WORD COUNT
	MOVNS	T4		;MAKE IT POSITIVE
	ADDI	T4,(T3)		;CALCULATE END OF BLOCK
	CAILE	T4,JOBPFI	;CHECK BOUNDS
	CAILE	T4,(U)		;UPPER AND LOWER BOUNDS OK?
	JRST	ERR31		;NO, GO SET ERROR BIT
	MOVEI	T4,1(T3)	;GET START OF BLOCK
	CAILE	T4,JOBPFI	;IS IT IN BOUNDS
	CAILE	T4,(U)		;UPPER AND LOWER BOUNDS OK?
	JRST	ERR31		;NO,GO SET ERROR BIT
	EXCTUX	<MOVE	F,@T1>	;SAVE BLKI/O INSTRUCTION FOR LATER
	ADDI	F,(R)		;RELOCATE BLKI/O INSTRUCTION
	EXCTUX	<HRRZ	T2,@T1>	;GET ADDRESS OF WORD COUNT, START ADR
	ADDI	T2,(R)		;RELOCATE IT
	MOVE	U,(T2)		;LOAD U WITH THE IOWD FOR BLKI/O
	ADDI	U,(R)		;RELOCATE IT
	MOVEM	U,(T2)		;SET UP RELOCATED IOWD IN USER AREA
	TLO	S,BLKIO		;NOTE THAT A BLKI/O IS TO BE DONE
	JRST	BLKRET		;GO GET RT BLOCK

ERR31:	TROA	S,E31		;SET ERROR BIT 31
ERR30:	TRO	S,E30		;SET ERROR BIT 30
	JRST	ERROR		; GO RETURN TO USER

VECINS:	TLNN	S,INDBIT	;INDIRECT BIT SPECIFIED?
	TLNN	S,VECTOR	;AND WAS VECTOR TYPE INTERRUPT REQUESTED?
	JRST	ERR30		;ERROR
	EXCTUX	<MOVE	F,@T1>	;EXEC VIRTUAL ADDRESS OF THE INTERRUPT VECTOR
	TLNN	S,EPTREL	;IS ADDRESS RELATIVE TO THE EPT?
	JRST	BLKRET		;NO, USER SPECIFIED THE EVA OF IRP VECTOR
	TRNE	F,MPGSIZ##	;MUST BE LESS THAN PAGSIZ
	JRST	ERR31		;NOT, THE EPT IS ONLY A PAGE LONG
	ADD	F,.C0TOS##	;RELOCATE BY ADDRESS OF THE EPT
;FALL INTO BLKRET
	;ARRIVE HERE AFTER PROCESSING ARGUMENT LIST.
	;IF THERE ARE ANY ERRORS SO FAR, DON'T GO ON.
	;AT THIS POINT THERE ARE FOUR AC'S SET UP:
	;F=INTERRUPT INSTRUCTION(CONSO OR BLKI/O),
	;M=APR INFO (XWD ENABLE,APRTRP),
	;P1=PI CHANNEL NUMBER, AND P2=TRAP ADDRESS

BLKRET:	TRNE	S,-1		;ANY ERRORS YET?
	JRST	ERROR		;YES, DONT GO ANY FURTHER

	;AT THIS POINT THE ARGUMENT LIST HAS BEEN VERIFIED, NOW
	;TRY TO OBTAIN A FREE REAL TIME BLOCK.

	CONO	PI,PIOFF	;LOCK OUT HIGHER PRIORITY INTERRUPTS
	SKIPE	T4,RTLINK	;IS THE FREE LIST EMPTY?
	MOVE	T4,@RTLINK	;NO, GET FIRST FREE BLOCK
	EXCH	T4,RTLINK	;STORE NEW POINTER IN RTLINK
	CONO	PI,PION
	JUMPE	T4,NORTBL	;ANY BLOCKS?
				;FALL THROUGH TO NEXT SECTION

	;THE RT BLOCK HAS BEEN OBTAINED.
	;NOW AN INTERRLOCK IS SET ( JOBTB(RTBLK) = XWD  DEV-CODE,0)
	;TO PREVENT THE SAME DEVICE FROM BEING PUT ON OR TAKEN OFF
	;OTHER CHANNELS DURING THE TIME IT TAKES TO COMPLETE THE
	;CHAINING OF THIS RT BLOCK.

	TLNN	S,CNSO		;IS THERE A CONSO INSTRUCTION
	MOVE	P3,F		;NO, SET P3 UP PROPERLY
	LDB	T3,[POINT 7,P3,9]	; GET DEV CODE
	IORI	T3,RTUSE	; MARK THAT RTBLOCK IS BEING USED
	HRLZM	T3,JOBTB(T4)	;STORE DEV CODE IN RT BLOCK FOR INTERLOCK
	MOVE	T2,[XWD MRTRPN,RTBLK]	;SET UP COUNTER AC

	;CHKDEV MAKES SURE THAT THERE ARE NO OTHER OCCURENCES OF THIS DEVICE
	;ON ANY OTHER CHANNELS EXCEPT WHEN OWNED BY THIS JOB

CHKDEV:	HLRZ	T1,JOBTB(T2)	;GET DEV CODE
	CAMN	T1,T3		;IS THIS THE SAME AS CURRENT DEVICE
	JRST	CHKDV2		;YES, GO SEE IF LEGAL
CHKDV1:	HRRI	T2,RTBSIZ-1(T2)	;LOOK AT NEXT BLOCK
	AOBJN	T2,CHKDEV	;LOOP BACK FOR REST OF CHECKS
	TLNE	S,VECTOR	;VECTOR INTERRUPT DEVICE?
	JRST	CHKDV4		;YES
	TLNN	S,CNSO		;CONSO INSTRUCTION?
	JRST	NOCNSO		;NO, GO SET UP BLKI/O INSTRUCTION
CHKDV4:	CONO	PI,PIOFF	;POSSIBLE RACE CONDITIONS HERE
	SKIPG	T1,CHNTAB-1(P1);ENABLED FOR BLKI/O
	TLZA	T1,400000	;YES, CLEAR BLKI/O BIT
	TLNN	T1,BINUSE	;IS THERE A BLKI/O OPERATION IN USE
	AOSA	CUSETB-1(P1)	;NO, COUNT UP CONSO IN USE TABLE
	JRST	ERR35		;CHANNEL BEING USED, GIVE BACK RT F
	MOVEM	T1,CHNTAB-1(P1);RESTORE NEW CHANNEL STATUS WORD
	CONO	PI,PION		;TURN PI SYSTEM BACK ON
				;FALL THROUGH TO LOADRB
	;THE RT BLOCK HAS BEEN OBTAINED, AND THE CHANNEL HAS BEEN SECURED
	;NOW THE RT BLOCK CAN BE SET UP
	;T4 CONTAINS THE START ADDRESS OF THE RT BLOCK
	;P1 CONTAINS PI#

LOADRB:
IFN FTKI10!FTKL10,<
	TLZ	M,-1
>
IFN FTKA10,<
	HRLI	M,R		;PUT RELOCATION IN APRTRP ADR
>
	MOVEM	M,APRTAB(T4)	;STORE IN APRTRP TABLE
	MOVEM	R,JADRTB(T4)	;STORE JBTADR VALUE IN TABLE
	MOVEM	P1,PITAB(T4)	;SAVE PI NUMBER
	SKIPN	T1,TRPFLG	;ARE WE AT INTERRUPT LEVEL
	SKIPA	T2,.C0CN1	;NO, GET USER ENABLE BITS
	SKIPA	T2,UENBT1(T1)	;YES, GET USER ENABLE BITS FROM T4
	SKIPA	T3,.C0LUC	;GET CONO BITS FOR APR
	SKIPA	T3,ENBTB1(T1)	;GET APR CONO BITS
	SKIPA	T1,.C0DTO	;NO, USE KT10A VALUE
	MOVE	T1,RELTB1(T1)	;YES, USE CURRENT INTERRUPT LEVEL VALUE
	MOVEM	T1,RELTAB(T4)	;STORE FOR INTERRUPT LEVEL USE
	HRRZM	T3,ENBTAB(T4)	;STORE APR CONO BITS
IFN FTKL10,<
	TRO	T2,LP.NXM!LP.IOF  ;KL10 BITS FOR NXM AND PAGE FAIL
>

IFN FTKI10,<
	TRO	T2,IP.IOF!IP.NXM  ;KI10 BITS FOR NXM AND PAGE FAIL
>

IFN FTKA10,<
	TRO	T2,AP.POV!AP.ABK!AP.ILM!AP.NXM  ;SET PDL, ILM, AND NXM AND ADRBRK
>
	HRRZM	T2,UENBTB(T4)	;STORE FOR LATER USE
	MOVSI	T1,(JRST)	;SET UP JRST CHAND'PI
	HRR	T1,DSMTAB-1(P1)	;FOR INTERRUPT LEVEL USE
	MOVEM	T1,DISMTB(T4)	;STORE IT IN TABLE
	HLRZ	T1,DSMTAB-1(P1)	;GET JSR ADDRESS
	HRLI	T1,(JSR)	;SET UP INSTRUCTION PART
	MOVEM	T1,RTJSR(T4)	;STORE IN RTBLK
	MOVE	T1,[JSP J,TRPGO##]
	MOVEM	T1,RTJSP(T4)	;SET UP JSP INSTRUCTION IN RT BLOCK
	HRLI	P2,USER+USRIOT	;TURN ON USER MODE AND USER IOT MODE BITS
	MOVEM	P2,TRPTAB(T4)	;STORE TRAP ADDRESS
	HRRZ	T1,CHNTAB-1(P1)	;GET CHANNEL ADDRESS
	ADDI	T1,1		;T1 = CHANX+1
	HRLI	T4,(JRST)	;SET UP JRST T4
	LDB	T2,[POINT 7,P3,9]	;GET DEVICE CODE
	TLNN	S,NOREM		;SHOULD WE REMOVE ANY DEVICES?
	JSP	T3,REMDEV	;GO REMOVE ALL DEVICES WITH THIS CODE FOR THIS JOB
	AOS	JBTRTD(J)	;COUNT UP REAL TIME DEVICE COUNT
	MOVSI	T3,(JSR)	;SET UP JSR TO TRPADR
	HRR	T3,TRPTAB(T4)	;GET USER TRAP ADDRESS
	ADDI	T3,(R)		;RELOCATE IT
	TLNE	S,VECTOR	;VECTORED MODE TRAPPING?
	JRST	VECST1		;YES, SETUP RTBLK FOR THAT STYLE OF RTTRP
	MOVEM	T3,RJRST1(T4)	;STORE IT IN RT BLOCK
	MOVSI	T3,(JEN @)	;SET UP JEN @ CHN
	HRR	T3,CHNTAB-1(P1)	;GET CHANNEL RETURN ADDRESS
	MOVEM	T3,RTJEN(T4)	;STORE IN JEN ADDRESS
	TLNN	S,CNSO		;CONSO OR BLKI/O
	JRST	BLKSET		;BLKI/O, GO SET UP PI LOCATIONS
	MOVEM	P3,RTCNSO(T4)	;STORE THE CONSO INSTRUCTION
	MOVSI	T2,(JRST)	;SET UP JRST INSTRUCTION
	HRRI	T2,RTJSR(T4)	;GET ADDRESS OF JSR SAVCHN
	TLNE	S,NOSAV		;EXEC MODE TRAPPING
	HRRI	T2,RJRST1(T4)	;YES, GET ADR OF JSR TRPADR
	MOVEM	T2,RTBLKO(T4)	;STORE IT IN RT BLOCK
	TLNE	S,BLKIO		;IS THERE A BLKI/O TO GO ON
	JRST	BLKST1		;YES, GO DO IT
RTRET1:	CONO	PI,PIOFF	;PI MUST BE OFF NOW
	MOVE	T2,(T1)		;PICK UP FIRST JRST OF CHAIN
	MOVEM	T4,(T1)		;CHANGE IT TO JRST RTBLK
	MOVEM	T2,RTJRST(T4)	;SET UP JRST NXTDEV INSTRUCTION
RTRET2:	HRRM	J,JOBTB(T4)	;COMPLETE RT BLOCK SET UP
	CONO	PI,PION		;INTERRLOCK REMOVED
RTRET:	TLNE	S,RTINT		;ARE WE AT INTERRUPT LEVEL
	AOSA	P4		;YES, ADD ONE TO RETURN
	AOSA	-1(P)		;NO, ADD ONE TO RETURN
	JRST	2,@P4		;RETURN
	MOVSI	T2,USRIOT	;SET USER IOT PRIVELEGE BIT
	IORM	T2,JOBPD1(R)	;IN USER RETURN ADDRESS
	POP	P,M		;RESTORE M
	POPJ	P,		;RETURN
;ODD PEICES AND ROUTINES

NOCNSO:	CONO	PI,PIOFF	;ROUTINE TO MARK A BLKI/O IN PROGRESS
	SKIPL	T1,CHNTAB-1(P1);ARE BLKI/O INSTRUCTIONS ALLOWED
	JRST	NCNSO1		;NO, SEE IF ONLY RESETTING BLKI/O POINTR
	TLC	T1,400000!BINUSE	;MARK THAT BLKI/O IS IN USE
	MOVEM	T1,CHNTAB-1(P1);STORE NEW CHANNEL STATUS WORD
	CONO	PI,PION
	JRST	LOADRB		;GO SET UP RT BLOCK

NCNSO1:	TLNN	T1,BINUSE	;IS THERE ALREADY A BLOCK IN OR OUT GOING
	JRST	ERR34		;NO, THEN THIS IS AN ERROR
	TLO	T1,BLKSAV	;YES, THEN WE ARE ONLY CHANGING POINTER'S
	MOVEM	T1,CHNTAB-1(P1)	;STORE NEW VALUE
	CONO	PI,PION		;TURN ON PI SYSTEM
	JRST	LOADRB		;GO SET UP RT BLOCK

BLKST1:	MOVEM	F,RTBLKO(T4)	;STORE BLKI/O INSTRUCTION
	TLNN	S,NOSAV		;EXEC MODE TRAPPING?
	MOVEM	T2,RJRST1(T4)	;STORE JRST RTJSR
	JRST	RTRET1		;GO SET UP CONSO CHAIN

VECST1:	MOVSI	T1,VECUSE	;INDICATE VECTORED INTERRUPT DEVICE
	IORM	T1,JOBTB(T4)	; THEREFORE NO CONSO INSTRUCTION ON THE SKIP CHAIN
	MOVSI	T1,(EXCH T1,)	;SETUP TO COPY INTERRUPT PC TO
	HRRI	T1,RTCNSO(T4)	; TO CH'N
	MOVEM	T1,RTJRST(T4)	;STORE "EXCH T1,RTBLK"
	MOVSI	T1,(MOVEM T1,)	;INT PC IS IN T1,
	HRR	T1,CHNTAB-1(P1)	; SETUP TO STORE IT IN CH'N
	MOVEM	T1,RTBLKO(T4)	;STORE "MOVEM T1,CH'N" IN RTBLK
	MOVSI	T1,(SKIPA T1,)	;SETUP INSTRUCTION TO RESTORE T1
	TLNE	S,NOSAV		;IF EXEC MOVE TRAPPING,
	MOVSI	T1,(MOVE T1,)	;SET TO RESTORE T1 AND FALL INTO JSR TRPADR
	HRRI	T1,RTCNSO(T4)	; ..
	MOVEM	T1,RJRST1(T4)	;SETUP INSTRUCTION TO RESTORE T1 IN RTBLK
	MOVEM	T3,RTJEN(T4)	;STORE "JSR TRPADR"
	MOVSI	T1,(JEN @)
	HRRI	T1,RTCNSO(T4)
	TLNE	S,NOSAV		;IFF EXEC MODE RTTRPING
	MOVEM	T1,RTJSR(T4)
	MOVSI	T1,(JSR)	;NOW, SETUP THE JSR TO THE RTBLK
	HRRI	T1,RTCNSO(T4)	; AS THE VECTORED INTERRUPT INSTRUCTION
	MOVEM	T1,(F)		;STORE THAT AT THE VECTOR ADDRESS
	JRST	RTRET2		;COMPLETE RTBLK AND RETURN TO THE USER
CHKDV2:	CAIN	T4,(T2)		;IS THIS DEVICE CODE OK?
	JRST	CHKDV1		;YES, GO BACK AND LOOK AT THE REST
	HRRZ	T1,JOBTB(T2)	;CHECK TO SEE IF THIS IS OUR JOB
	CAIN	J,(T1)		;IS IT US?
	JRST	CHKDV1		;YES, THEN IT IS OK.
	TRO	S,E26		;NO, SET ERROR BIT
CHKDV3:	SETZM	JOBTB(T4)	;ZERO OUT DEVICE CODE
	MOVEI	T1,(T4)		;GET BLOCK START ADDRESS
	CONO	PI,PIOFF	;PUT IT BACK ON FREE LIST
	EXCH	T1,RTLINK	;GET NEXT ENTRY ON LIST
	MOVEM	T1,(T4)		;PUT IT IN FIRST WORD OF CURRENT BLOCK
	CONO	PI,PION		;LET INTERRUPTS COME AGAIN
ERROR:	TLNN	S,RTINT		;ARE WE AT INTERRUPT LEVEL
	JRST	ERROR1		;NO, GO DISMISS PROPERLY
	ADDI	R,-1(P4)	;GET ADDR OF UUO IN USER AREA
	LDB	T1,[POINT 4,(R),12]	;GET USER AC NUMBER
	HRRZM	S,(T1)		;STORE THE ERROR BITS IN USER AC
	JRST	2,@P4		;RETURN
ERROR1:	POP	P,M		;RESTORE UUO AC
	MOVE	T1,S		;PUT ERROR CODE IN T1
	JRST	STOTAC		;GO STORE T1 IN USER AC

ERR34:	TROA	S,E34		;SET ERROR BIT 34
ERR35:	TRO	S,E35		;SET ERROR BIT 35
	CONO	PI,PION		;TURN PI SYSTEM BACK ON
	JRST	CHKDV3		;GO CLEAN UP AND RETURN

NORTBL:	TRO	S,E29		;SET THE ERROR BIT
	JRST	ERROR		;GO GIVE ERROR RETURN

BLKSET:	MOVSI	T1,(JSR)	;SET UP 40+2*N+1
	HRR	T1,CHNTAB-1(P1)	;GET CH'PI ADDRESS
	HRRZ	T2,P1		;GET CHANNEL NUMBER
	LSH	T2,1		;MULTIPLY IT BY 2
	MOVEM	T1,.EPIL##+1(T2)	;STORE JSR INSTRUCTION IN TRAP LOCATION
	MOVSI	T3,(JRST)	;SET UP JRST TO RT BLOCK
	HRRI	T3,RTJSR(T4)	;GET START OF RT BLOCK CODE
	TLNE	S,NOSAV		;EXEC MODE TRAPING
	HRRI	T3,RJRST1(T4)	;YES, GET ADR OF "JSR TRPADR" INSTRUCTION
	MOVEM	T3,1(T1)	;STORE INSTRUCTION IN CH'PI + 1
	CONO	PI,PIOFF
	MOVEM	F,.EPIL##(T2)	;STORE BLKI/O INSTRUCTION IN TRAP LOC
	HRRM	J,JOBTB(T4)	;REMOVE INTERLOCK
	CONO	PI,PION
	JRST	RTRET		;GO RETURN TO USER
	;ENTERED BY INTERRUPT LEVEL UUO FROM LOC 41 WITH JSP RTUUO,UUOHND

	;DECODE UUO, AND IF IT IS LEGAL GO EXECUTE IT
	;OTHERWISE DISMIS THE INTERRUPT
	;THE FASTEST METHOD OF DISMISSING IS TO EXECUTE AN INSTRUCTION
	;WHICH TRAPS TO LOC 60 (IE OPCODE 100). THIS BYPASSES THE UUO DECODING.

	;*** ACS 16 AND 17 SHOULD NOT BE SYMBOLIC IN THIS ROUTINE
	;***SINCE THEY ARE DOCUMENTED AS 16 AND CANNOT IF SYMBOLIC
	;***NAMES ARE CHANGED
UUOHND::LDB	16,[POINT 4,RTMUUO##,12]	;PICK UP UUO AC
	CAIN	16,17		;IS THIS AN ILLEGAL USER AC?
	JRST	UUOHD3		;YES, GO GIVE IMMMEDIATE ERROR RETURN
	MOVE	T1,(16)		;LOAD T1 WITH USER'S AC
	SKIPL	J,TRPFLG	;GET RT BLOCK INDEX REGISTER
	JRST	MPTRP2+1	;IF RT BLOCK RELEASED GO DISMISS
	LDB	T2,[POINT 9,RTMUUO##,8]	;GET UUO NUMBER
	MOVE	R,JADRT1(J)	;LOAD PROTECTION-RELOCATION
	CAIE	T2,47		;CALLI UUO?
	JRST	MPTRP2+1	;NO,DISMIS
	HRRZ	J,JOBTB1(J)	;LOAD J WITH JOB NUMBER
	HRRZ	T2,RTMUUO##	;PICK UP CALLI #
	XCT	@MPTRP2+1	;SET UP P
	AOBJN	P,.+1		;SKIP CONI APR INFORMATION
	CAIE	T2,RTUUON	;IS IT A RTTRP UUO?
	JRST	UUOHD2		;TRY OTHER LEGAL UUOS
UUOHD1:	MOVSI	S,RTINT		;SET INTERRUPT LEVEL UUO BIT
	CAIN	16,16		; RTUUO AND RTUUO1 ARE ILLEGAL
	TROA	S,E27		;YES, ERROR
	JRST	RTTRP1		;NO, GO EXECUTE UUO
	HRRZM	S,(16)		;STORE ERROR CODE
	JRST	2,@17		;GIVE ERROR RETURN


UUOHD3:	MOVE	T1,17		;SAVE CONTENTS OF RETURN AC
	MOVEI	17,E27		;SET ERROR BIT IN AC RTUUO
	JRST	2,@T1		;GIVE ERROR RETURN
	EXTERN	WAKEUP

UUOHD2:	CAIE	T2,WAKUUO	;IS THIS A WAKE UUO ?
	JRST	MPTRP2+1	;NO,DISMIS(OR CHECK FOR OTHER LEGAL UUOS)
	MOVEI	T2,WAKEUP	;SET UP FOR UUO DISPATCH
UUODPT:	CAIE	16,16		;IS THIS AN ILLEGAL UUO AC (UUODPT= UUO DISPATCH ENTRY) ?
	PUSHJ	P,(T2)		;DISPATCH TO UUO
	JRST	2,@17		;ERROR RETURN
	AOS	17		;NORMAL SKIP RETURN
	JRST	2,@17		;RETURN TO CALLER
REMOVE:	TRNE	S,E24+E25	;ANY ERRORS SO FAR?
	JRST	ERROR		;YES, DON'T CONTINUE
	HRRI	T1,2(T1)	;MAKE T1 POINT TO INSTRUCTION ARG
	EXCTUX	<LDB T2,[POINT 7,@T1,9]>  ;PICK UP DEVICE CODE
	JSP	T3,REMDEV	;GO REMOVE ALL DEVICES WITH THIS CODE
	JRST	RTRET		;GO RETURN TO USER

	;REMDEV REMOVES ALL INSTANCES OF A DEVICE WITH THE CORRECT
	;JOB NUMBER FROM THE CHAINS
	;CALLING SEQUENCE:
	;	MOVE T2,DEVCODE
	;	JSP T3,REMDEV
	;AC'S T1, W, U, AND T4 ARE PRESERVED

REMDEV:	CONO	PI,PION		;COULD BE ENTERED WITH PI OFF
	MOVE	P2,[XWD MRTRPN,RTBLK]	;SET UP COUNTER AC
REMDV1:	LDB	M,[POINT 7,JOBTB(P2),17]	;GET DEVICE CODE
	CAMN	M,T2		;IS IT A MATCH
	JRST	REMDV3		;YES, GO REMOVE IT FROM CHAIN
REMDV2:	CONO	PI,PI.ON	;CAN GET HERE WITH PI SYSTEM OFF
	HRRI	P2,RTBSIZ-1(P2)	;GO ON TO NEXT BLOCK
	AOBJN	P2,REMDV1	;LOOP BACK FOR REST OF BLOCKS
	JRST	(T3)		;NO DEVICES, GO RETURN

REMDV3:	CONO	PI,PIOFF	;GAURD AGAINST THE RACE CONDITION
	LDB	M,[POINT 7,JOBTB(P2),17]	;GET DEVICE CODE AGAIN
	CAME	M,T2		;IS IT STILL THE SAME?
	JRST	REMDEV		;NO, GO TRY AGAIN
	MOVE	M,JOBTB(P2)	;GET JOB NUMBER
	CAIE	J,(M)		;IS THIS OUR JOB?
	JRST	REMDV2		;NO, GO BACK FOR ANOTHER TRY
	PUSH	P,T2		;SAVE DEVICE CODE
	HRRZS	JOBTB(P2)	;SET INTERLOCK
	TLNE	M,VECUSE	;VECTORED INTERRUPT DEVICE?
	JRST	CHFND0		;YES, NO CONSO'S ON THE SKIP CHAIN
	CONO	PI,PION		;FINISHED STICKY AREA
	HRRZ	P1,PITAB(P2)	;GET PI CHANNEL NUMBER
	MOVE	T2,CHNTAB-1(P1);GET CHANNEL STATUS WORD
	TLNE	T2,BINUSE	;IS THIS A BLKI/O CASE
	JRST	BLKREM		;YES, GO REMOVE THAT
CHLPB:	CONO	PI,PION		;ENTERED WITH PI OFF SOMETIMES
	MOVSI	T2,(JRST)	;SET UP CHAIN INSTRUCTION TO LOOK FOR
	HRRI	T2,(P2)		;GET ADDRESS OF BLOCK
	HRRZ	M,CHNTAB-1(P1)	;GET CHANNEL ADDRESS
CHLOOP:	CAMN	T2,1(M)		;IS THIS THE RIGHT CHAIN ENTRY?
	JRST	CHFND		;YES, GO REMOVE IT
	HRRZ	M,1(M)		;POINT TO NEXT CONSO ELEMENT
	JRST	CHLOOP		;GO BACK FOR MORE
	;ENTERED AFTER FINDING THIS DEVICE
CHFND:	CONO	PI,PIOFF	;GUARD AGAINST INTERRUPTS FROM ABOVE
	CAME	T2,1(M)		;IS IT STILL A MATCH?
	JRST	CHLPB		;NO, GO TRY AGAIN
	MOVE	T2,1(P2)	;GET NEXT CHAIN LINK
	MOVEM	T2,1(M)		;CUT THIS RT BLOCK OUT OF CHAIN
CHFND0:	CONO	PI,PION		;ALLOW INTERRUPTS PENDING TO GO
	CONO	PI,PIOFF
	SOSE	CUSETB-1(P1)	;DECREMENT COUNT OF CONSO'S
	JRST	CHFND1		;STILL MORE CONSO'S ON CHAIN
	MOVE	T2,CHNTAB-1(P1);GET CHANNEL STATUS WORD
	TLNE	T2,BLKENB	;BLKI/O ALLOWED
	TLO	T2,400000	;YES, MARK THAT THIS CHANNEL IS FREE
	MOVEM	T2,CHNTAB-1(P1);STORE NEW STATUS WORD
CHFND1:	CONO	PI,PION		;TURN ON PI SYSTEM AGAIN
CLRRTB:	HRRZ	T2,TRPFLG	;GET RT BLOCK POINTER ADDRESS
	CAIE	T2,RTJSP+1(P2)	;IS THIS THE BLOCK THAT IS BEING REMOVED?
	JRST	CLRRT1		;NO
	HRRZ	M,DSMTAB-1(P1)	;GET ADDRESS OF DISMISS ROUTINE
	HRRZI	M,RTOFST(M)	;ADD IN RELTAB OFSET
	MOVE	T2,RELTAB(P2)	;GET RELOC/PROTECTION
	MOVEM	T2,RELTB1(M)	;STORE IN PI LEVEL AREA
	MOVE	T2,UENBTB(P2)	;GET ENABLE BITS
	MOVEM	T2,UENBT1(M)	;STORE IN PI LEVEL AREA
	MOVEM	M,TRPFLG	;STORE NEW TRPFLG WORD
CLRRT1:	MOVEI	T2,(P2)		;PICK UP RT BLOCK ADDRESS
	CONO	PI,PIOFF
	SETZM	JOBTB(P2)	;CLEAR OUT DEV CODE
	EXCH	T2,RTLINK	;PUT THIS BLOCK BACK ON LIST
	MOVEM	T2,(P2)		;SET UP REST OF LINKS
	CONO	PI,PION
	SOS	JBTRTD(J)	;COUNT DOWN RT DEVICE COUNT
	POP	P,T2		;RESTORE DEVICE CODE
	JRST	REMDV2		;ALL FINISHED
	;ENTER HERE TO REMOVE A BLKI/O FROM A PI LOCATION
BLKREM:	TLNE	T2,BLKSAV	;ARE WE JUST RESETTING POINTER WORD
	JRST	BLKRM1		;YES, DON'T REMOVE BLKI/O
	MOVEI	T2,.EPIL##(P1)	;GET PROPER PI LOCATION
	ADD	T2,P1		;40 + 2*N
	HRLI	M,(JSR)		;SET UP JSR CHAN
	HRR	M,CHNTAB-1(P1)	;GET CHAN ADDRESS
	MOVEM	M,(T2)		;STORE IN 40+2*N
	HRLI	M,(JEN @)	;SET UP ORIGINAL CHANNEL STATUS
	MOVEM	M,1(M)		;T4+1 = JEN @ T4
	CONO	PI,PIOFF	;TURN OFF PI
	MOVE	M,CHNTAB-1(P1)	;GET STATUS WORD
	TLC	M,400000+BINUSE	;SET THAT CHANNEL IS FREE
	MOVEM	M,CHNTAB-1(P1);STORE NEW STATUS WORD
	CONO	PI,PION
	JRST	CLRRTB		;GO CLEAN UP RT BLOCK

BLKRM1:	MOVSI	T2,BLKSAV	;CLEAR OUT BIT
	ANDCAM	T2,CHNTAB-1(P1)
	JRST	CLRRTB		;GO CLEAN UP
	;RTREL IS CALLED BY RESET TO REMOVE ALL DEVICES FROM
	;THE PI CHANNELS.
	;BEFORE REMOVING ANY DEVICE A CONO DEV,0 IS EXECUTED

RTREL:	MOVEI  T1,777		;ARE THERE ANY DEVICES ON PI LEVELS
	TDNN	T1,JBTRTD(J)	;CHECK RIGHT HALF ONLY
	POPJ	P,		;NO, RETURN
	MOVEI	T1,RTTRPN	;SET UP COUNTER
	MOVEI	T2,RTBLK	;SET UP TO LOOK FOR DEVICES
RTREL1:	SKIPE	T3,JOBTB(T2)	;ANY JOB USING THIS BLOCK
	JRST	RTREL3		;YES, GO SEE IF IT IS THIS JOB
RTREL2:	MOVEI	T2,RTBSIZ(T2)	;GET NEXT ENTRY
	SOJG	T1,RTREL1	;GO LOOK AT OTHER ENTRIES
	JRST	RTREL		;GO RETURN

RTREL3:	CAIE	J,(T3)		;IS THIS US?
	JRST	RTREL2		;NO, GO LOOK AT REST OF BLOCKS
	HLRZ	T2,T3		;GET DEVICE NUMBER
	ANDI	T2,177		;CLEAR RTUSE BIT
	MOVSI	T3,(CONO)	;SET UP TO DO A CONO DEV,0
	DPB	T2,[POINT 7,T3,9]
IFN FTKL10,<
	CAIN	T2,<TIM>_-2	;IF KL10 INTERVAL TIMER
	TRO	T3,420000	;CLEAR TIMER AND THE DONE FLAG
>
	CAILE	T2,1		;DON'T CONO 0 TO PI OR APR
	XCT	T3		;CONO DEV,0
	JSP	T3,REMDEV	;REMOVE THE DEVICE FROM THE CHAIN
	JRST	RTREL		;GO LOOK AT REST OF BLOCKS
	;CALLED DURING AN APR TRAP AT REAL TIME INTERRUPT LEVEL
APRCHK:
	PUSH	P,J		;SAVE J
	MOVE	J,.CPRTT(P4)	;SET UP PROPER INDEX FOR RT BLOCK
	XCT	.CPHCT##(P4)	;CLOCK?
	JRST	APRCK		;NO, GO SERVICE OTHER INTS
APRCK3:
IFN FTMS,<

	SKPCPU	(0)
	JRST	APRCKA		;NO, CPU1 SHOULD NOT INCREMENT SYSTEM VARIABLES
>;END FTMS COND
	AOS	TIME		;YES, INCREMENT TIME OF DAY
	SOS	HNGTIM##	;DECR HUNG TIME FOR SYSTEM
APRCKA:	AOS	.CPUPT(P4)	;AND SYSTEM UP TIME
	SETOM	.CPTMF(P4)	;SET TIMEF FOR LEVEL 7 SCHEDULER
	SETOM	.CPCKF(P4)	;NOTE THAT THE CLOCK TICKED
	CONO	PI,XI.RQC	;CAUSE AN INTERRUPT ON LEVEL 7
	CONSZ	APR,@UENBT1(J)	;USER ENABLED FOR ANY INTERRUPTS
	JRST	APRCK1		;YES, GO TRAP TO HIM
	XCT	.CPCCF##(P4)	;CLEAR CLOCK FLAG
	JRST	JPOPJ##		;RESTORE J AND RETURN

APRCK1:	XCT	.CPCCF##(P4)	;CLEAR CLOCK FLAG
APRCK:	EXCH	T1,@.CPCHL(P4)	;GET PC
	TLNN	T1,USRMOD	;USER MODE PC?
	CONSZ	APR,@.CPILM##(P4)	;NO,ILLEGAL MEM REF (HARDWARE GLITCH)?
	JRST	APRCK5		;YES, ERROR IS USER GENERATED
	CONSZ	APR,@.CPEME##(P4)	;ERROR WORTH BOTHERING ABOUT?
	JRST	APRER9		;YES, LET EXEC WORRY ABOUT IT
	JRST	APRCK2		;NO,DISMISS
APRCK5:	SKIPL	.CPRTT(P4)	;ANY RT BLOCK FOR THIS DEVICE
	JRST	APRCK4		;NO, DISMIS THE INTERRUPT
	PUSH	P,R		;SAVE R
	PUSH	P,T1		;SAVE TAC1
	PUSH	P,T2		;AND TAC2
	PUSHJ	P,APRPTS	;GO GET POINTER TO USER MODE ERROR PC
	MOVE	R,JADRT1(J)	;GET RELOCATION VALUE
	XCT	.CPUEH##(P4)	;READ IN APR STATUS BITS
	EXCTXU	<MOVEM T1,@APRTB1(J)>	;STORE OLD PC IN TRAP ADDRESS
	HRR	T1,APRTB1(J)	;GET TRAP ADDRESS
	HRRI	T1,1(T1)	;ADD ONE TO IT
	MOVEM	T1,@T2		;SET UP NEW PC (EVEN IF NOT APRCHL PC)
	POP	P,T2		;RESTORE T2
	POP	P,T1		;RESTORE T1
	POP	P,R		;RESTORE R
APRCK2:	TLZ	T1,440140	;CLEAR OUT ERROR BITS
	EXCH	T1,@.CPCHL(P4)	;RESTORE NEW PC
	CONO	APR,@.CPIEF##(P4)  ;CLEAR APR
	JRST	JPOPJ		;RESTORE J AND DISMISS

APRCK4:	MOVEI	T1,MPTRP2+1	;SET UP TO DISMISS THE INTERRUPT
	JRST	APRCK2		;GO RETURN TO ABSOLUTE LOC 61
;VARIABLE STORAGE ALLOCATION
	$LOW
RTLINK:	Z		;POINTER TO FIRST FREE BLOCK ON LIST
SAV41:	BLOCK	2		;AREA TO SAVE 41 AND 61
	SAV61=SAV41+1
CUSETB:	BLOCK	6		;AREA FOR COUNTERS OF NUMBERS OF CONSO'S ON THE CHAINS
CHAINT:	BLOCK	6		;AREA FOR CHN'PI + 1 VALUES
	$LIT
	END