Google
 

Trailing-Edge - PDP-10 Archives - BB-D351B-SM - sources/dispat.p11
There are 2 other files named dispat.p11 in the archive. Click here to see a list.
.SBTTL	DISPATCHER
;
; THIS SECTION CONTAINS THE DISPATCHER.  IT DISTRIBUTES CPU
;  TIME AMONG THE TASKS ON A "NON-PREEMPTIVE" BASIS.
;  THAT IS, A TASK MUST DELIBERATELY RELINQUISH CONTROL BY
;  CALLING "WAIT" BEFORE ANOTHER TASK CAN GET CONTROL.
;
; IN ADDITION, THE ONCE-PER-CLOCK-TICK SUBROUTINES ARE CALLED
;  FROM HERE, AS ARE THE ONCE-PER-SECOND SUBROUTINES.
;
; IF A TASK TAKES TOO MUCH TIME, THE CLOCK TICK INTERRUPT WILL
;  ISSUE A STOPCODE, SO EACH TASK CALLS "WAIT" AFTER ONLY
;  A LITTLE PROCESSING.  
;
.REPT 0


                          COPYRIGHT (c) 1980, 1979
            DIGITAL EQUIPMENT CORPORATION, maynard, mass.

THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
ONLY  IN  ACCORDANCE  WITH  THE  TERMS  OF  SUCH  LICENSE AND WITH THE
INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR  ANY  OTHER
COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
TRANSFERRED.

THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE  WITHOUT  NOTICE
AND  SHOULD  NOT  BE  CONSTRUED  AS  A COMMITMENT BY DIGITAL EQUIPMENT
CORPORATION.

DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR  RELIABILITY  OF  ITS
SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.

.ENDR
;
;
;
;		REVISION HISTORY
;
;
; 4(001) BS	ADD VERSION NUMBER
;
;
VDISPT=001
;
VEDIT=VEDIT+VDISPT
;
;
;
;
;
;
;
;
; SUBROUTINE TO WAIT UNTIL THE CONDITION SPECIFIED IN THE
;  TCB HAS BEEN SATISFIED.
;
WAIT:	TRACE	TRCDSP,DSPTCB	;TRACE CALL TO "WAIT FOR EVENT"
	MOV	DSPTCB,R5	;GET POINTER TO TCB
	MOV	(SP)+,TCPC(R5)	;SAVE PROGRAM COUNTER
	MOV	SP,TCSP(R5)	;SAVE STACK POINTER
	MFPS	TCPS(R5)	;SAVE PS REGISTER
	CLR	DSPTCB		;NO LONGER RUNNING A TASK
	MOV	#PDL,SP		;SWITCH TO DISPATCHER STACK
	CLR	-(SP)		;SET UP STACK AS THOUGH FROM AN INTERRUPT
	MOV	#DISPATCH,-(SP)	;SO WE CAN CLEAR THE "T" BIT
	RTI			;DISMISS THE "INTERRUPT", I.E.,
				; BRANCH TO DISPATCHER
;
; THIS IS THE MAIN ENTRY POINT AND THE RECYCLE POINT.
;
DISPATCH:
	MOV	TCBP1,R5	;GET HIGHEST PRIORITY TASKS
				; (I.E., BSC DRIVERS)
11$:	TST	R5		;ANY (MORE) TCBS?
	BEQ	12$		;NO.
	JSR	PC,DISP		;YES, TRY TO DISPATCH IT
	MOV	TCHAIN(R5),R5	;GET NEXT TCB
	BR	11$		;TRY TO DISPATCH IT
;
12$:	MOV	TCBP2,R5	;GET MEDIUM PRIORITY TCBS
				; (I.E., DL10 DRIVER)
13$:	TST	R5		;ANY (MORE) TCBS?
	BEQ	14$		;NO.
	JSR	PC,DISP		;YES, TRY TO DISPATCH IT
	MOV	TCHAIN(R5),R5	;GET NEXT TCB
	BR	13$		;TRY TO DISPATCH IT
;
14$:	MOV	TCBP3,R5	;GET LOWEST PRIORITY TCBS
				; (I.E., XLATE TASKS AND IDLE TASK)
15$:	TST	R5		;ANY MORE TCBS?
	BEQ	16$		;NO.
	JSR	PC,DISP		;YES, TRY TO DISPATCH IT
	MOV	TCHAIN(R5),R5	;GET NEXT TCB
	BR	15$		;AND DO IT, TOO.
;
; HERE IF ALL TASKS ARE WAITING.
;
16$:	JSR	PC,DSPIDL	;DO IDLE TIME CODE
	BR	DISPATCH	; AND CHECK ALL TCBS AGAIN.
;
;
; SUBROUTINE TO TEST A TCB TO SEE IF THE TASK IS DISPATCHABLE.
;  IF THE TASK IS DISPATCHABLE WE DISPATCH TO IT, OTHERWISE
;  WE RETURN.
;
DISP:	BIT	#EBWAIT,(R5)	;IS TASK WAITING?
	BNE	11$		;YES.
	MOV	R5,DSPTCB	;NO, REMEMBER THE TCB
	TRACE	TRCDSP,DSPTCB	;TRACE DISPATCHING OF TASK
	TRACE	TRCDSP,DSPCLK	; AND ITS TIME
	MOV	TCSP(R5),SP	;LOAD THE TASK'S STACK
	MOV	TCPS(R5),-(SP)	; AT TASK'S PRIORITY LEVEL
	MOV	TCPC(R5),-(SP)	;CREATE A PSEUDO-INTERRUPT
	RTI			;GO RUN THE TASK.
;
; HERE IF THE TASK IS NOT DISPATCHABLE.  TRY TO MAKE IT SO.
; CHECK FOR TASK WAITING FOR CHUNKS
;
11$:	BIT	#EBFCHK,(R5)	;IS TASK WAITING FOR CHUNKS?
	BEQ	12$		;NO.
	TST	CHFREC		;YES, ANY LEFT?
	BEQ	12$		;NO, LET TASK KEEP WAITING
	BIC	#EBFCHK!EBWAIT,(R5) ;YES, RESTART TASK
	BR	DISP		;GO RUN IT.
;
; HERE IF THE TASK CANNOT BE MADE DISPATCHABLE
;
12$:	RTS	PC		;RETURN TO DISPATCHER MAIN LOOP
;
;
; SUBROUTINE CALLED BY THE DISPATCHER WHEN ALL TASKS ARE WAITING.
;
DSPIDL:	INC	DSPMTY		;NOTE DISPATCHER IDLE CYCLE
	BVC	11$		;BRANCH IF NO OVERFLOW
	STOPCD	WDG		;CLOCK HAS STOPPED TICKING
11$:	CMP	DSPCLK,JIFCLK	;IS THE DISPATCHER CLOCK UP TO DATE?
	BNE	12$		;NO.
	RTS	PC		;YES, CHECK ALL TASKS AGAIN.
;
; HERE WHEN THE CLOCK HAS TICKED.
;
12$:	INC	DSPCLK		;INCREMENT DISPATCHER CLOCK
	CMP	DSPCLK,JIFCLK	;ARE WE BEHIND?
	BNE	17$		;YES, TAKE SHORT PATH.
	MOV	TCBP1,R5	;GET HIGH PRIORITY TASKS
	JSR	PC,DSPUDC	;UPDATE THEIR CLOCKS
	MOV	TCBP2,R5	;GET MEDIUM PRIORITY TASKS
	JSR	PC,DSPUDC	;UPDATE THEIR CLOCKS
	MOV	TCBP3,R5	;GET LOW PRIORITY TASKS
	JSR	PC,DSPUDC	;UPDATE THEIR CLOCKS
	JSR	PC,DSPDQT	;DO ONCE-A-TICK DQ11 CODE
.IF NDF,FT2020 ;IF NOT ON A 2020
	TST	DLGONE		;DO WE HAVE A DL10?
	BNE	13$		;NO.
.ENDC ;END IF NDF,FT2020
	JSR	PC,DSPDLT	;YES, DO ONCE-A-TICK CODE
13$:	INC	DSPSEC		;INCREMENT SECOND COUNTER
	CMP	DSPSEC,#JIFSEC	;REACHED ONE SECOND?
	BNE	17$		;NO.
	CLR	DSPSEC		;YES, CLEAR SECONDS COUNTER
	INC	DSPUPT		;INCREMENT UP TIME
	ADC	DSPUPT+2	;ADD CARRY TO HIGH-ORDER WORD
.IF NDF,FT2020 ;IF NOT ON A 2020
	TST	DLGONE		;DO WE HAVE A DL10?
;	BEQ	16$		;YES.
	BEQ	23$		;YES
	CMP	DLGNTM,#DLGNWT	;NO, HAVE WE WAITED LONG ENOUGH?
	BEQ	14$		;YES.
	INC	DLGNTM		;NO, WE HAVE WAITED ANOTHER SECOND
	BR	15$		;KEEP WAITING.

23$:	TST	TGFLAG		;IS TGHA BEINGING RUN
	BEQ	16$		;NO, CONTINUE AS BEFORE
	CMP	TGCNT, #5	;YES, CHECK FOR 5 SECONDS
	BLT	16$		;NOT 5 SECONDS, JUST UPDATE STATUS
;	BR	14$		;5 SECONDS EXPIRED, REINITIALIZE


;
; HERE ONCE A SECOND AFTER THE DL10 HAS BEEN GONE FOR
;  A WHILE.
;
14$:	JSR	PC,INITDL	;TRY TO INITIALIZE THE DL10
15$:	BR	17$		;WAIT UNTIL NEXT SECOND
;
.ENDC ;END IF NDF,FT2020

; HERE ONCE A SECOND IF THE DL10 IS PRESENT.
;
16$:	JSR	PC,DSPDLS	;DO ONCE-A-SECOND DL10 CODE
17$:	RTS	PC		;RETURN.
;
;
; SUBROUTINE TO UPDATE THE CLOCKS IN A LIST OF TASKS
;
DSPUDC:
11$:	TST	R5		;ANY TASKS?
	BNE	12$		;YES.
	RTS	PC		;NO, DONE WITH THIS LIST
;
12$:	TST	TCTIM(R5)	;HAS THIS TASK A TIMER?
	BEQ	13$		;NO.
	DEC	TCTIM(R5)	;YES, DECREMENT IT.
	BNE	13$		;BRANCH IF TIME NOT YET UP
	BIT	#EBTIME,(R5)	;IS TASK WAITING FOR TIMER?
	BEQ	13$		;NO, IGNORE IT.
	BIC	#EBTIME!EBWAIT,(R5) ;MAYBE, NO LONGER WAITING.
13$:	MOV	TCHAIN(R5),R5	;GET NEXT TCB
	BR	11$		; AND TEST IT.
;