	.TITLE RSX DATA CHANNEL HANDLER
/
/   9 JUN 77 (     PDH) CONTINUE THE CONVERSION
/  25 MAY 77 (001; PDH) BEGIN CONVERSION FROM LP.38 HANDLER
/
/ THE FOLLOWING CAL PARAMETER BLOCKS ARE USED TO QUEUE REQUESTS FOR
/ DATA CHANNEL SERVICE:

/
/	CPB	3600	HANDLER INFORMATION (HINF)
/		EVA	(300076 => I, O, NO DIRECTORY)
/		LUN

/
/	CPB	2400	ATTACH DATA CHANNEL DEVICE
/		EVA
/		LUN
/
/	CPB	2600	READ (RECEIVE DATA FROM EXTERNAL DEVICE)
/		EVA
/		LUN
/		MODE
/		BUFFER
/		COUNT
/
/	CPB	2700	WRITE (SEND DATA TO EXTERNAL DEVICE)

/		EVA

/		LUN

/		MODE
/		BUFFER
/
/	CPB	3000	GET BLOCK OF DATA
/		EVA
/		LUN
/		BUFFER
/		COUNT
/
/	CPB	3100	PUT BLOCK OF DATA
/		EVA
/		LUN
/		BUFFER
/		COUNT
/
/	CPB	2500	DETACH DATA CHANNEL DEVICE

/		EVA
/		LUN
/
	.EJECT
/ THE REQUESTOR'S EVENT VARIABLE IS CLEARED (ZEROED) WHEN THE REQUEST

/ IS QUEUED BY THE "QUEUE I/O" DIRECTIVE.  IF THE REQUEST CAN BE 

/ PERFORMED, THE EVENT VARIABLE IS SET TO ONE (+1) UPON COMPLETION.

/ IF THE REQUEST CANNOT BE PERFORMED, THE EVENT VARIABLE IS SET TO ONE 

/ OF THE FOLLOWING NEGATIVE VALUES:

/

/	 -6 -- ILLEGAL REQUEST FUNCTION

/	 -7 -- ILLEGAL DATA MODE

/	-16 -- ILLEGAL OUTPUT HEADER WORD-PAIR-COUNT (<1)

/	-24 -- LUN HAS BEEN REASSIGNED WHILE REQUEST WAS IN QUEUE
/	-30 -- OUT-OF-PARTITION TRANSFER (NORMAL MODE)
/	-203 - ILLEGAL TO ATTACH OR DETACH FROM OTHER THAN TASK LEVEL
/
	.EJECT

X12=12		/AUTO-INCREMENT REG 12

X13=13		/AUTO-INCREMENT REG 13
X17=17		/AUTO-INCREMENT REG 17 (USED TO SET REQUESTOR'S EV)
X10=10		/ FETCH STL NODE ADDR FOLLOWING DMTQ

R1=101		/RE-ENTRANT REGISTER ONE

R2=102		/RE-ENTRANT REGISTER TWO

R3=103		/RE-ENTRANT REGISTER THREE
R4=104		/RE-ENTRANT REGISTER FOUR

NADD=107	/NODE ADDITION ROUTINE ENTRY POINT

SNAM=123	/NAME SCAN ROUTINE ENTRY POINT

POOL=240	/LISTHEAD FOR POOL OF EMPTY NODES

PDVL=252	/LISTHEAD FOR PHYSICAL DEVICE LIST

ALAD=325	/ATTACH LUN & DEVICE ENTRY POINT

DLAD=332	/DETACH LUN & DEVICE ENTRY POINT
DQRQ=337	/DE-QUEUE REQUEST ENTRY POINT

VAJX=342	/VERIFY & ADJUST ENTRY POINT

IOCD=345	/DECLARE I/O REQUEST COMPLETE ENTRY POINT

DMTQ=361	/DETACH & EMPTY QUEUE ENTRY POINT
D.TG=10		/POSITION OF TRIGGER EVENT VARIABLE IN PDVL NODE
/
IDX=ISZ		/ INDEX POINTER (SKIP NOT EXPECTED)
SET=ISZ		/ SET FLAG TO NON-ZERO VALUE
INC=ISZ		/ INCREMENT POSITIVE COUNTER (SKIP NEVER INTENDED)
.INH=705522	/ INHIBIT INTERRUPTS
.ENB=705521	/ ENABLE  INTERRUPTS
/
/  WHEN USING A ROUTINE TO SIMULATE AN EXTERNAL DEVICE,
/  IT IS NECESSARY TO JUMPER PIN C12S TO PIN D24K SO THAT
/  THE 'DCJOG' INSTRUCTION CAN FUNCTION.
/
DCSF=702701		/ SKIP ON DATA CHANNEL DEVICE FLAG
DCCF=702721		/ CLEAR FLAG
DCRD=702741		/ SELECT READ (INPUT)
DCWT=702761		/ SELECT WRITE (OUTPUT)
DIRD=702712		/ DIAGNOSTIC READ DATA CHANNEL BUFFER
				/ (PROBABLY DOES NOT WORK)
DIWT=702704		/ DIAGNOSTIC WRITE (LOAD) DATA CHANNEL BUFFER
DCAPI=76		/ API TRAP ADDRESS
DCWC=32			/ WORD COUNT REGISTER
DCCA=33			/ CURRENT ADDRESS REGISTER
DCJOG=702504		/ SIMULATE EXTERNAL DEVICE
/
	.EJECT
/ HANDLER INITIALIZATION

/
DC	LAC	(PDVL	/SCAN PHYSICAL DEVICE LIST FOR NODE
	DAC*	(R1)	/FOR THIS DEVICE.
	LAC	(HNAM
	DAC*	(R2)
	JMS*	(SNAM	/(R1, R2, R6, X17, XR, & AC ARE ALTERED)
			/NODE FOUND?
	CAL	(10)	/NO -- EXIT
	DAC	PDVNA	/SAVE PDVL NODE ADDRESS
	AAC	+D.TG	/AND
	DAC	PDVTA	/TRIGGER EVENT VARIABLE ADDRESS ADDRESS.
/
	CAL	CCPB	/CONNECT INTERRUPT LINE
	LAC	EV	/CONNECT OKAY?

	SPA

	CAL	(10)	/NO -- EXIT
	LAC	(TG	/YES -- SET TRIGGER EVENT VARIABLE ADDRESS
	DAC*	PDVTA	/IN PHYSICAL DEVICE NODE
	AND	(070000	/DETERMINE "XR-ADJ"

	TCA
	DAC	XADJ
/***
/***   HERE IS WHERE ONE WOULD CLEAR THE DEVICE, IF APPROPRIATE
/***
/

/ WAIT FOR TASK TO BE TRIGGERED BY 'QUEUE I/O' DIRECTIVE OR BY 'ABORT'

/ TO SIGNAL THAT A REQUEST HAS BEEN QUEUED.

/
WFTGR	CAL	WFTCPB	/WAIT FOR TRIGGER EVENT VARIABLE TO BE SET
/

/ THE TASK HAS BEEN TRIGGERED -- PICK A REQUEST FROM QUEUE (IF ANY)

/

	DZM	TG	/CLEAR TRIGGER
PQ	LAC	PDVNA	/DEQUE A REQUEST
	DAC*	(R1)
	JMS*	(DQRQ)	/(R1, R2, R4, R5, R6, XR, & AC ARE ALTERED)
/			/R1 NOW CONTAINS PDVL NODE ADDR
/			/R2 NOW CONTAINS I/O REQ NODE ADDR

			/WAS A REQUEST FOUND?

	JMP	WFTGR	/NO -- WAIT FOR TRIGGER

	DAC	RN	/YES -- SAVE ADDRESS OF REQUEST NODE
	TAD	XADJ	/SETUP XR TO ACCESS NODE
	PAX
/
	.EJECT
/  THE FORMAT OF AN I/O REQUEST NODE (RN) IS AS FOLLOWS:
/
/	 (0) FORWARD LINKAGE
/	 (1) BACKWARD LINKAGE
/	 (2) REQUESTOR'S STL NODE ADDRESS
/	 (3) NORMAL/EXEC MODE INDICATOR
/	 (4) TASK PRIORITY (TO BE CHANGED!)
/	 (5) I/O FUNCTION CODE IN BITS 9-17, AND
/	     LUN IN BITS 0-8.
/	 (6) CPB WD 1 -- EVENT VARIABLE ADDRESS
/	 (7) CPB WD 3 -- (UNIQUE TO CAL)
/	(10) CPB WD 4 -- (UNIQUE TO CAL)
/	(11) CPB WD 5 -- (NIQUE TO CAL)
/
/  IF AN I/O REQUEST IS QUEUED BY AN INTERRUPT SERVICE ROUTINE, ZERO IS
/  USED IN PLACE OF AN STL NODE ADDRESS.
/
/  IF AN I/O REQUEST IS QUEUED BY A "NORMAL MODE" TASK, ITS PARTITION
/  BLOCK ADDRESS IS SET IN THE MODE INDICATOR.  FOR AN "EXEC MODE" TASK,
/  THE MODE INDICATOR IS SET TO ZERO.
/
	LAC	5,X	/FETCH CAL FUNCTION CODE

	AND	(777)

	SAD	(017)	/ABORT REQUEST?

	JMP	ABORT	/YES -- ABORT TASK I/O

	SAD	(777)	/NO -- EXIT (DEASSIGNED) REQUEST?
	JMP	DAEX	/YES -- DETACH & EXIT
	SAD	(26	/ READ REQUEST?
	JMP	READ
	SAD	(27	/ WRITE REQ?
	JMP	WRITE	/YUP
	SAD	(30	/ GET REQUEST?
	JMP	GET
	SAD	(31	/ PUT REQUEST?
	JMP	PUT
	SAD	(36	/HINF CODE REQ?
	JMP	HINF
	SAD	(34
	JMP	CLOSE
	CLL!RAR		/SEARCH ATTACH DETACH IN COMMON
	SAD	(12	/24/2 AND 25/2  ARE 12

	JMP	ATTACH	/GO DO EITHER
ILFUNC	LAW	-6	/NO -- UNIMPLEMENTED FUNCTION -- SET
	JMP	SEV	/EVENT VARIABLE TO -6
/
	.EJECT

/ ABORT ALL I/O INITIATED BY THE INDICATED TASK.

/
ABORT	XOR	5,X	/ABORT IS AN ILLEGAL FUNCTION FOR ALL TASKS
	SZA		/ EXCEPT 'IORD' WHO SETS LUN=0
	JMP	ILFUNC
	JMS*	(DMTQ	/ R1 AND R2 SET UP FOR THIS CALL
	JMP	SP1	/DONE.
/
/
/  ATTACH TO  OR  DETACH FROM A TASK
/
ATTACH	SNL!CLA		/ SKIP IF DETACH
	AAC	ALAD-DLAD / MAKE UP ADDR FOR ALAD OR DLAD
	AAC	DLAD	/ FOR JMS TO ACTION
	DAC	TEMP1	/ TEMPORARY FOR JMS*
	JMS*	TEMP1	/ CALL ATTACH OR DETACH
/			/ R1 AND R2 ALREADY SET UP
	JMP	SEV	/NO -- SET REQUESTOR'S EVENT VARIABLE TO -24 OR -203
SP1	CLA!IAC		/YES -- SET REQUESTOR'S EVENT VARIABLE TO +1
	JMP	SEV
/
/
/ RETURN HANDLER INFORMATION IN EVENT VARIABLE

/
HINF	LAC	(300076		/ INPUT AND/OR OUTPUT, NO DIRECTORY
	JMP	SEV
/
	.EJECT
READ	JMP	SP1
	.EJECT
WRITE	LAC	7,X		/ GET MODE OF I/O REQUEST
	DAC	MI		/ AND SAVE IT
	AND	(777776		/ IF DATA MODE IS OTHER THAN 0 (IOPS BINARY)
	SNA			/ OR 1 (IMAGE BINARY), SET REQUESTOR'S
	JMP	MODEOK		/ EVENT VARIABLE TO -7.
ILMODE	LAW	-7
	JMP	SEV
/
MODEOK	LAC	10,X		/ GET USER BUFFER ADDRESS
	DAC*	(R3
	DAC	TEMP1		/ SAVE UN-ADJUSTED BASE FOR SECOND JMS
	CLA!IAC
	DAC*	(R4
	JMS*	(VAJX		/ (R3, R5, XR, AC ARE ALTERED)
				/ IS BEGINNING ADDRESS OK?
	JMP	ERR30		/ NO -- SET REQUESTOR'S EVENT VARIABLE TO -30
/**
/**  BEGINNING ADDRESS IS OK.  REAL (ADJUSTED TO 17-BITS) ADDRESS OF
/**  LINE BUFFER IS IN R3, AND MAY BE MOVED TO APPROPRIATE LOCATION.
/**
	LAC*	(R3
	DAC	SEVRN		/ HANDY TEMPORARY LOCATION
	LAC*	SEVRN
	LRS	10
	AND	(776		/ GET LINE LENGTH IN WORDS
	DAC*	(R4
/
	AAC	-2		/ IF FEWER THAN 2 WORDS,
	SMA			/ SET REQUESTOR'S EVENT VARIABLE TO -16
	JMP	.+3
ILSIZE	LAW	-16
	JMP	SEV
/
	LAC	TEMP1		/ VERIFY LINE SIZE (NORMAL MODE).
	DAC*	(R3		/ R2 & R4 ARE SETUP.
	JMS*	(VAJX		/ (R3, R5, XR, AC ARE ALTERED)
				/ IS LINE SIZE OK?
	JMP	ERR30		/ NO -- SET REQUESTOR'S EVENT VARIALBE TO -30
/
/**  LINE SIZE IS OK.  WORD COUNT IS IN R4 TO BE USED AS APPROPRIATE.
/**  REAL (ADJUSTED TO 17-BITS) ADDRESS OF LINE BUFFER IS AGAIN IN R3.
/**
	DZM	EV		/ CLEAR INTERNAL EVENT VARIABLE
/**
/**  PERFORM REQUIRED I/O OPERATION
/**
	JMS	WFAB		/ WAIT FOR I/O TO COMPLETE,
	JMP	SP1		/ THEN SET REQUESTOR'S EVENT VARIABLE TO +1
/
	.EJECT
GET	JMP	SP1
	.EJECT
PUT	JMP	SP1
	.EJECT
CLOSE	JMP	SP1
/
/
/
/
/
/
ERR30	LAW	-30

/

/  COMMON TERMINATION OF NON-PRINTING REQUESTS

/
SEV	JMS	SEVRN	/SET EVENT VARIABLE, DECLARE SIGNIFICANT
	JMP	PQ	/EVENT, RETURN NODE, PICK NEXT REQ.
/
/ WFAB -- SUBROUTINE TO WAIT FOR EVENT VARIABLE TO BE SET AND THEN TO

/ CHECK THE TRIGGER EVENT VARIABLE TO SEE IF AN ABORT REQUEST SHOULD

/ BE PROCESSED.

/
WFAB	0

	CAL	WFECPB	/WAITFOR EV TO BE SET.

	LAC	TG	/IS BIT 2 OF THE TRIGGER SET?

	RTL

	SMA

	JMP*	WFAB	/NO -- RETURN

/

/ DE-QUEUE THE ABORT REQUEST.

/

	DZM	TG

	LAC	PDVNA	/PHYSICAL DEVICE NODE ADR

	DAC*	(R1)

	JMS*	(DQRQ)	/(R1, R2, R4, R5, XR & AC ARE ALTERED).

			/WAS A REQUEST FOUND?

	JMP*	WFAB	/NO -- SHOULD NEVER RETURN HERE.

	DAC	RN	/YES -- SAVE NODE ADR

	DAC*	(R2)

	LAC	PDVNA	/PHYSICAL DEVICE NODE ADR

	DAC*	(R1)

	JMS*	(DMTQ)	/DETACH LUN & DEVICE, IF NECESSARY, AND THEN

			/EMPTY THE REQUEST QUEUE OF ALL I/O REQUESTS

			/MADE BY THE TASK BEING ABORTED. (R1, R2, R3,

			/R5, R6, X10, X11, X12, XR & AC ARE ALTERED).
	JMS	SEVRN	/SET REQUESTER'S ('IORD'S') EV, DECRE-

			/MENT THE I/O PENDING COUNT, AND RETURN NODE TO POOL.

	JMP*	WFAB
/
	.EJECT
/ SEVRN -- SUBROUTINE TO SET THE REQUESTOR'S EVENT VARIABLE TO

/ THE QUANTITY IN AC, DECLARE A SIGNIFICANT EVENT, DECREMENT I/O

/ TRANSFERS PENDING COUNT (NORMAL MODE), AND RETURN REQUEST NODE

/ TO THE POOL.

/

SEVRN	0

	PAL		/SAVE EV VALUE

	LAC	RN	/REQUEST NODE ADR

	TAD	XADJ

	PAX

	LAC	6,X	/REQUESTER'S EV

	SNA

	JMP	NOSET	/NONE SPECIFIED

	TAD	XADJ

	PAX

	PLA

	DAC	0,X	/SET EV

/

NOSET	LAC	RN	/DECLARE I/O REQUEST COMPLETED (DECREMENT

	DAC*	(R2)	/TRANSFERS PENDING COUNT).

	JMS*	(IOCD)	/(R5, XR, & AC ARE ALTERED)

/

	LAC	(401000)/DECLARE A SIGNIFICANT EVENT

	ISA

/

	LAC	(POOL)	/RETURN REQUEST NODE TO POOL

	DAC*	(R1)

			/(R2 IS ALREADY SETUP)

	JMS*	(NADD)

/

	JMP*	SEVRN	/EXIT 'SEVRN' SUBROUTINE

/

/ EXIT REQUEST (FROM TASK "...REA")

/
DAEX	LAC	(POOL)	/RETURN REQUEST NODE TO POOL

	DAC*	(R1)

	LAC	RN

	DAC*	(R2)
	JMS*	(NADD)
	CAL	DCPB	/DISSCCCONNECT
/
	ISZ	PDVTA	/CLEAR ASSIGN INHIBIT FLAG IN PDVL NODE

	.INH

	DZM*	PDVTA

	.ENB
	CAL	(10)	/EXIT
/
	.EJECT
/ INTERRUPT SERVICE ROUTINE

/
INT	0			/ INTERRUPT ENTRY POINT
	DBA			/ ENTER INDEX (PAGE) MODE
	DAC	ACBF		/ SAVE AC
	DCCF			/ CLEAR FLAG
	SET	EV		/ SET INTERNAL EVENT VARIABLE
	LAC	(401000		/ DECLARE A SIGNIFICANT EVENT
	ISA
	LAC	ACBF		/ RESTORE AC
	DBR			/ RETURN TO INTERRUPTED PROGRAM
	JMP*	INT

/

XADJ	0	/XR ADJUST CONSTANT TO SUBTRACT PAGE BITS

ACBF	0	/AC BUFFER

CABF	0	/INITIAL CURRENT ADDRESS BUFFER

EV	0	/EVENT VARIABLE

MI	0	/MODE INDICATOR

RN	0	/ADDRESS OF REQUEST NODE PICKED FROM QUEUE

TG	0	/TRIGGER EVENT VARIABLE

/

PDVNA	0	/PHYSICAL DEVICE NODE ADDRESS

PDVTA	0	/ADDRESS OF ADR OF TRIGGER EV IN PHY DEV NODE

/

TEMP1	0

/

WFTCPB	20		/WAIT FOR TRIGGER

	TG
CCPB	11	/CONNECT CPB

	EV

	16

	INT

/
DCPB	12	/DISCONNECT CPB

	0

	16

	INT

/
WFECPB	20	/WAIT FOR EVENT VARIABLE CPB

	EV
/
HNAM	.SIXBT	'DC@@@@'	/ DEVICE NAME (HANDLER TASK NAME IS 'DC....')
	.END	DC
