Google
 

Trailing-Edge - PDP-10 Archives - AP-4178E-RM - swskit-sources/phyp4.mac
There are 52 other files named phyp4.mac in the archive. Click here to see a list.
;<3.SM10-RELEASE-3>PHYP4.MAC.79,  3-Apr-78 18:49:52, Edit by MCLEAN
;FIX ATNXIT NOT TO CLEAR CHANNEL ON TRANSFERING DRIVE
;<3A.MONITOR>PHYP4.MAC.79,  8-Mar-78 23:58:51, Edit by MCLEAN
;CLEAR DRIVE AT ATNXIT
;<2BOSACK>PHYP4.MAC.77, 24-Feb-78 01:25:42, EDIT BY BOSACK
;CHANGE DEVICE/DATA ERROR FLAGGING
;<2BOSACK>PHYP4.MAC.76, 15-Feb-78 02:09:13, EDIT BY BOSACK
;<4.MONITOR>PHYP4.MAC.76,  1-Feb-78 14:52:23, Edit by MCLEAN
;FIX FOR NEW PHYUDB CALLING SEQ
;<2BOSACK>PHYP4.MAC.75, 30-Jan-78 02:37:06, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.74, 27-Jan-78 02:14:45, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.73, 25-Jan-78 03:46:02, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.72, 25-Jan-78 03:40:58, EDIT BY BOSACK
;REORGANIZED DISK PHYSICAL PARAMETER TREATMENT
;CHANGED LATOPT TO USE UDB FOR PHYSICAL PARAMETERS
;MINOR (10USEC ON A 2050) SPEEDUPS
;<2BOSACK>PHYP4.MAC.71, 15-Jan-78 20:50:53, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.70, 15-Jan-78 20:47:30, EDIT BY BOSACK
;CHANGES FOR RM03 ECC DIFFERENCES
;<3-MONITOR>PHYP4.MAC.69,  9-Nov-77 09:56:46, EDIT BY KIRSCHEN
;MORE COPYRIGHT UPDATING...
;<2BOSACK>PHYP4.MAC.68, 13-Oct-77 00:32:37, EDIT BY BOSACK
;COMMAND STACK LATOPT IMPROVEMENTS, HW BUG FIX
;<3-MONITOR>PHYP4.MAC.67, 12-Oct-77 14:09:18, EDIT BY KIRSCHEN
;UPDATE COPYRIGHT FOR RELEASE 3
;<2BOSACK>PHYP4.MAC.66, 15-Sep-77 05:16:22, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.65, 13-Sep-77 03:33:26, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.64, 10-Sep-77 20:57:25, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.63,  9-Sep-77 21:47:54, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.62,  9-Sep-77 12:29:29, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.61,  6-Sep-77 04:43:11, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.60,  6-Sep-77 01:55:07, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.59,  5-Sep-77 06:35:35, EDIT BY BOSACK
;ALLOW LATOPT TO SKIP HEAD OF TWQ TO DO COMMAND STACKING
;<2BOSACK>PHYP4.MAC.58,  2-Sep-77 23:18:02, EDIT BY BOSACK
;<3-MONITOR>PHYP4.MAC.57, 26-Aug-77 15:24:43, Edit by MCLEAN
;FIX RP4UP TO DO WRITE PROTECT CORRECTLY
;<3-MONITOR>PHYP4.MAC.56, 24-Aug-77 22:13:12, EDIT BY BOSACK
;MORE TCO 1849
;<3-MONITOR>PHYP4.MAC.55, 23-Aug-77 18:45:34, EDIT BY BOSACK
;<3-MONITOR>PHYP4.MAC.54, 22-Aug-77 14:54:27, EDIT BY BOSACK
;UPDATE PGM AND WLK BITS ON ONLINE INTERRUPT
;<3-MONITOR>PHYP4.MAC.53, 21-Aug-77 00:30:19, Edit by MCLEAN
;<3-MONITOR>PHYP4.MAC.52, 20-Aug-77 22:59:11, Edit by MCLEAN
;<3-MONITOR>PHYP4.MAC.51, 19-Aug-77 23:10:53, Edit by MCLEAN
;<3-MONITOR>PHYP4.MAC.50, 19-Aug-77 22:10:44, Edit by MCLEAN
;<3-MONITOR>PHYP4.MAC.49, 19-Aug-77 22:07:20, Edit by MCLEAN
;FIX RP4SI1 FOR RM03
;<SM10-MONITOR>PHYP4.MAC.48, 12-Aug-77 11:27:14, Edit by MCLEAN
;ADD RM03 SUPPORT
;<2BOSACK>PHYP4.MAC.47, 12-Aug-77 02:20:54, EDIT BY BOSACK
;TCO 1849 - FIX SEEK ERROR RECOVERY, IT TENDS TO FORGET THE IORB
;<2BOSACK>PHYP4.MAC.46, 28-Jul-77 03:16:00, EDIT BY BOSACK
;FIX SEEK ERROR RECOVERY TO NOT CALL ZAP/CLRCHL AND FLAG ERROR ON INT
;<3-MONITOR>PHYP4.MAC.45,  2-May-77 18:47:47, EDIT BY HURLEY
;<2BOSACK>PHYP4.MAC.44,  2-Apr-77 19:54:02, EDIT BY BOSACK
;<3-MONITOR>PHYP4.MAC.43,  5-Feb-77 00:20:11, Edit by MCLEAN
;CORRECT DEFINITIONS OF DR.SN AND DR.ER2
;<3-MONITOR>PHYP4.MAC.42, 27-Dec-76 17:36:00, EDIT BY HURLEY
;<3-MONITOR>PHYP4.MAC.41, 27-Dec-76 17:27:53, EDIT BY HURLEY
;<2BOSACK>PHYP4.MAC.40, 23-Dec-76 12:01:25, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.39, 19-Dec-76 16:17:13, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.38, 19-Dec-76 16:15:11, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.37, 19-Dec-76 14:41:52, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.36, 13-Dec-76 16:33:04, EDIT BY BOSACK
;TCO 1684 - CHECK HOME BLOCKS ON OFFLINE/ONLINE TRANSITION
;<2-MONITOR>PHYP4.MAC.35, 23-Nov-76 19:11:45, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.34,  1-Nov-76 20:23:52, EDIT BY BOSACK
;TEST IS.IER IN ERROR RECOVERY
;<2BOSACK>PHYP4.MAC.33, 18-Oct-76 18:09:10, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.32,  6-Sep-76 07:17:27, EDIT BY BOSACK
;DETECT STUCK SECTOR COUNTER AT INITIALIZE
;<2BOSACK>PHYP4.MAC.30,  6-Aug-76 04:11:59, EDIT BY BOSACK
;READ REGISTERS BEFORE CLEARING DEVICE AT END OF ECC CORRECTED ERR
;<2BOSACK>PHYP4.MAC.29,  5-Aug-76 01:26:01, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.28,  4-Aug-76 14:58:00, EDIT BY BOSACK
;CATCH ERRORS IN SECOND PART OF ECC RECOVERY
;<2BOSACK>PHYP4.MAC.27, 28-Jul-76 03:56:12, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.26, 28-Jul-76 02:06:28, EDIT BY BOSACK
;<2BOSACK>PHYP4.MAC.25, 28-Jul-76 01:55:11, EDIT BY BOSACK
;HERE BEGINS LATENCY EDITS
;<1B-MONITOR>PHYP4.MAC.24,  7-MAY-76 18:41:43, EDIT BY BOSACK
;TCO 1283 - ELIMINATE POSSIBLE RACE DURING DUAL PORT OPERATION
;<1B-MONITOR>PHYP4.MAC.23,  3-MAY-76 11:42:45, EDIT BY BOSACK
;<1B-MONITOR>PHYP4.MAC.22, 13-APR-76 19:37:19, EDIT BY BOSACK
;<2MONITOR>PHYP4.MAC.21, 30-MAR-76 03:44:25, EDIT BY BOSACK
;<2MONITOR>PHYP4.MAC.20, 30-MAR-76 03:17:27, EDIT BY BOSACK
;TCO 1270 - ADD RP05/6 SUPPORT
;<2MONITOR>PHYP4.MAC.19, 19-JAN-76 12:24:11, EDIT BY MURPHY
;<PHYSIO>PHYP4.MAC.35, 19-DEC-75 02:03:43, EDIT BY BOSACK
;<PHYSIO>PHYP4.MAC.29, 20-NOV-75 21:52:50, EDIT BY BOSACK


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

	SEARCH PROLOG,SERCOD	;SYSTEM PARAMETERS
	TTITLE (PHYP4,,< - DEVICE DEPENDENT CODE FOR RP04 DISKS>)
	SUBTTL T.HESS, T WACHS/TAH/TW/LB 2 JULY 75

	SEARCH PHYPAR		;PARAMETERS
	ENTRY RP4DSP		;FOR LIBRARY SEARCH
	SUBTTL PARAMETERS

;DRIVE REGISTERS

DO.DRC==(0B5)			;DRIVE CONTROL REGISTER
DO.SR==(1B5)			;STATUS REGISTER
DO.ER==(2B5)			;ERROR REGISTER
DO.AS==(4B5)			;ATTENTION SUMMARY
DO.DA==(5B5)			;DESIRED ADDRESS (TRACK/SECTOR)
DO.DT==(6B5)			;DRIVE TYPE
DO.LA==(7B5)			;LOOK AHEAD
DO.SN==(10B5)			;DRIVE SERIAL NUMBER
DO.OF==(11B5)			;OFFSET REGISTER
DO.DC==(12B5)			;DESIRED CYLINDER
DO.ER3==(15B5)			;ERROR REGISTER # 3
DO.ECP==(16B5)			;ECC POSITION
DO.ECB==(17B5)			;ECC BURST (PATTERN)

;DRIVE FUNCTIONS

DF.UNL==3			;UNLOAD
DF.SEK==5			;SEEK
DF.RCL==7			;RECALIBRATE
DF.CLR==11			;DRIVE CLEAR
DF.REL==13			;RELEASE (DUAL PORT)
DF.OFS==15			;OFFSET POSITION
DF.RTC==17			;RETURN TO CENTERLINE
DF.PST==21			;READIN PRESET
DF.ACK==23			;PACK ACKNOWLEDGE
DF.SRC==31			;SEARCH
DF.WRT==61			;WRITE DATA
DF.WTF==63			;WRITE FORMAT
DF.RED==71			;READ DATA
DF.RDF==73			;READ FORMAT

F22==100			;22-SECTOR MODE (SOFTWARE ONLY)
ERETRY==200			;ERROR RETRY (ECC FIXED 1ST PART) SOFTWARE ONLY
DXES==200000			;DISABLE STOP ON ERROR

;BITS IN CONTROL REGISTER

CR.DVA==4000			;DEVICE AVAILABLE - FOR DUAL PORT
;DRIVE STATUS REGISTER

DS.ATA==1B20			;ATTENTION
DS.ERR==1B21			;ERROR
DS.PIP==1B22			;POSITION IN PROGRESS
DS.MOL==1B23			;MEDIA ON LINE
DS.WRL==1B24			;WRITE LOCKED
DS.LST==1B25			;LAST SECTOR TRANSFERRED
DS.PGM==1B26			;PROGRAMMABLE (DUAL PORT)
DS.DPR==1B27			;DRIVE PRESENT
DS.DRY==1B28			;DRIVE READY
DS.VV==1B29			;VOLUME VALID

DS.GUD==DS.MOL!DS.DPR!DS.DRY!DS.VV
DS.MSK==DS.GUD!DS.ATA!DS.ERR!DS.PIP!DS.WRL	;MASK OF STATUS BITS TO CONSIDER

;DRIVE ERROR REGISTER

ER.DCK==1B20			;DRIVE CHECK
ER.UNS==1B21			;DRIVE UNSAFE
ER.OPI==1B22			;OPERATION INCOMPLETE
ER.DTE==1B23			;DRIVE TIMING ERROR
ER.WLE==1B24			;WRITE LOCK ERROR
ER.IAE==1B25			;INVALID ADDRESS ERROR
ER.AOE==1B26			;ADDRESS OVERFLOW ERROR
ER.CRC==1B27			;HEADER CRC ERROR
ER.HCE==1B28			;HEADER COMPARE ERROR
ER.ECH==1B29			;ECC HARD ERROR
ER.WCF==1B30			;WRITE CLOCK FAILURE
ER.FER==1B31			;FORMAT ERROR
ER.CPE==1B32			;CONTROL BUS PARITY ERROR
ER.RMR==1B33			;REGISTER MODIFICATION REFUSED
ER.ILR==1B34			;ILLEGAL REGISTER
ER.ILF==1B35			;ILLEGAL FUNCTION
ER.OFS==ER.DCK!ER.FER!ER.CRC!ER.HCE ;ERRORS ON WHICH TO TRY OFFSET

;OFFSET REGISTER

OF.F22==1B23			;22-SECTOR MODE
OF.ECI==1B24			;ERROR CORRECTION CODE INHIBIT

;ERROR REGISTER 3 STATUS BITS

E3.OCL==1B20			;OFF CYLINDER
E3.SKI==1B21			;SEEK INCOMPLETE
	SUBTTL ERROR RECOVERY/REPORTING DEFINITIONS
;RETRY COUNTS
POSCNT==3			;NUMBER OF TIMES TO RETRY ON POSITION FAILURE
DEVCNT==3			;RETRIES ON DEVICE ERROR (NOT DATA OR HEADER) BEFORE RECALIBRATE
				; MUST BE AT LEAST 3

RCLCNT==3			;RECALIBRATES AFTER DEVCNT TRIES (TIMES FOR COMPLETE CYCLE)
;STATUS BITS IN LH(UDBERR)
ES.HRD==1B0			;HARD ERROR
ES.ECC==1B1			;ECC-CORRECTED ERROR
ES.DAT==1B2			;DATA ERROR
ES.HDR==1B3			;HEADER ERROR
ES.DEV==1B4			;DEVICE ERROR (NEITHER DATA NOR HEADER)
ES.POS==1B5			;POSITIONING ERROR
ES.FER==1B6			;FORMAT ERROR (20-SECTOR PACK IN 22-SECT. MODE, ETC)


;UDB EXTENSIONS

RP.CNI==UDBDDP			;CONI OF RH GOES HERE
RP.CRC==RP.CNI+1		;DATAI RH CONTROL REGISTER
RP.DBF==RP.CRC+1		;DATAI RH DATA REGISTER
RP.CYL==RP.DBF+1		;NUMBER OF CYLINDERS PER UNIT
RP.SCL==RP.CYL+1		;NUMBER OF SECTORS PER CYLINDER
RP.SSF==RP.SCL+1		;NUMBER OF SECTORS PER SURFACE
RP.USU==RP.SSF+1		;NUMBER OF USEC PER LA REG UNIT
RP.USF==RP.USU+1		;SSF * 64 (LA REG UNITS)
RP.LST==RP.USF+1		;START OF LAST PAGE ON A CYLINDER

RP.REG==RP.LST+1		;DRIVE REGISTERS GO HERE

DR.CRC==0			;CONTROL REGISTER
DR.ST==1			;STATUS
DR.ER==2			;ERROR
DR.MT==3			;MAINTENANCE
DR.ATA==4			;ATTENTION SUMMARY
DR.DA==5			;DESIRED ADDRESS
DR.DT==6			;DRIVE TYPE
DR.LA==7			;LOOK AHEAD
DR.SN==10			;SERIAL NUMBER
DR.OF==11			;OFFSET
DR.DC==12			;DESIRED CYLINDER
DR.CA==13			;CURRENT ADDRESS
DR.ER2==14			;ERROR REGISTER # 2
DR.ER3==15			;ERROR REGISTER # 3
DR.ECP==16			;ECC POSITION
DR.ECB==17			;ECC BURST

L.RP4==RP.REG+20		;LENGTH OF RP04 UDB
;DISPATCH TABLE
RP4DSP:	JRST RP4INI		;0 - INITIATION
	JRST RP4SIO		;1 - START I/O
	JRST RP4INT		;2 - HANDLE INTERRUPT
	JRST RP4ERR		;3 - ERROR RECOVERY
	JRST RP4HNG		;4 - HUNG DEVICE
	JRST RP4CNV		;5 - CONVERT BLK # TO CYLINDER/SURF-SEC
	JRST RP4LTM		;6 - LATENCY COMPUTATION
	JRST RP4POS		;7 - START POSITIONING
	JRST RP4ATN		;10- ATTENTION INTERRUPT
	JRST RP4PRQ		;11- SKIP IF POSITIONING REQUIREDD
	JRST RP4STK		;12- STACK SECOND TRANSFER COMMAND

;DUMMIES

RP4HNG:	RET

;DISKS ARE CHECKED BY CALLING CNV AND CHECKING UDBPS1

RP4PRQ:	RETSKP		;IF ASKED, SAY ALWAYS

;TRANSLATION FROM MASSBUS TYPE TO INTERNAL BLOCKTYPE

XTYPE:	XWD .UTRP4,TY.RP4
	XWD .UTRP5,TY.RP5
	XWD .UTRP6,TY.RP6
	XWD .UTRM3,TY.RM3

NXTYPE==.-XTYPE
	SUBTTL INITIATION

;C(Q2) := UNIT NUMBER

RP4INI:	SAVEQ
	MOVE T3,[RP4DSP,,L.RP4]	;DISPATCH,,LENGTH
	CALL PHYUDB		;SET UP UDB
	RET			;RETURN IF NO SPACE
	MOVSI T2,DO.DT		;READ DRIVE TYPE REGISTER
	CALL RDREG		; ...
	ANDI T1,777		;MASK TO JUST DRIVE TYPE
	MOVSI T2,-NXTYPE	;SEARCH TABLE FOR INTERNAL UNIT TYPE
INI1:	MOVE T3,XTYPE(T2)	;GET TYPE WORD
	CAIN T1,(T3)		;MATCH?
	JRST INI2		;YES
	AOBJN T2,INI1		;NO - ANY LEFT
	BUG(HLT,RP4UNF,<PHYP4 - UNIT TYPE NOT FOUND:>,T1)
INI2:	HLRZ T1,T3		;FOUND - GET INTERNAL TYPE CODE
	MOVE T4,T1		;COPY FOR UDB BUILD LATER
	MOVSI T2,-NDSKUT	;SEARCH TO FIND PHYSICAL PARAM TABLE
INI3:	CAMN T1,DSKUTP(T2)	;MATCH?
	JRST INI4		;YES
	AOBJN T2,INI3		;NO - LOOP
	BUG(HLT,RP4PNF,<PHYP4 - DISK PHYSICAL PARAMETERS NOT FOUND>)
INI4:	MOVE T2,DSKSIZ(T2)	;GET POINTER TO PHYSICAL PARAMETER TABLE
	MOVEM T2,UDBSIZ(P3)	;SAVE IN UDB
	MOVE T3,CYLUNT(T2)	;GET NUMBER OF CYLINDERS
	MOVEM T3,RP.CYL(P3)	;SAVE COPY
	MOVE T3,SECCYL(T2)	;GET SECTORS PER CYLINDER
	MOVEM T3,RP.SCL(P3)	;SAVE
	SUB T3,SECPAG(T2)	;COMPUTE START OF LAST PAGE ON A CYL
	MOVEM T3,RP.LST(P3)	;SAVE
	MOVE T3,SECSRF(T2)	;GET SECTORS PER SURFACE
	MOVEM T3,RP.SSF(P3)	;SAVE
	LSH T3,6		;COMPUTE LATOPT UNITS PER SURF
	MOVEM T3,RP.USF(P3)	;SAVE
	MOVE T3,USSECU(T2)	;GET USEC PER LATOPT UNIT
	MOVEM T3,RP.USU(P3)	;SAVE
	MOVSI T2,DO.SR		;READ STATUS REGISTER
	CALL RDREG
	TLO T4,(US.PRQ)		;INDICATE POSITIONING REQUIRED
	TRNE T1,DS.WRL		;WRITE LOCKED?
	TLO T4,(US.WLK)		;YES - INDICATE IN STATUS
	TRNE T1,DS.PGM		;DUAL PORT IN PROGRAMMABLE MODE?
	TLO T4,(US.PGM)		;YES - INDICATE IN UNIT STATUS
	TRNN T1,DS.MOL		;MEDIA ON LINE?
	TLO T4,(US.OFS)		;SET OFF-LINE
	IORM T4,UDBSTS(P3)	;SET UP STATUS AND CONFIGURATION
	TRNN T1,DS.VV		;VOLUME VALID?
	CALL RP4UP		;NO - ACK NOW
	MOVSI T2,DO.SN		;SERIAL REGISTER
	CALL RDREG		;READ IT
	MOVEM T1,UDBDSN(P3)	;SAVE DRIVE SERIAL NUMBER
	MOVSI T2,DO.LA		;CHECK FOR STUCK SECTOR COUNTER
	CALL RDREG
	MOVE T4,T1		;SAVE FIRST VALUE
	MOVEI Q1,^D100000	;MAXIMUM NUMBER OF TIME TO TRY
INI5:	MOVSI T2,DO.LA		;NOW TRY FOR A DIFFERENT VALUE
	CALL RDREG
	CAME T1,T4		;STILL THE SAME?
	RET			;NO - RETURN
	SOJGE Q1,INI5		;YES - TRY AGAIN
	MOVE T1,CDBADR(P1)	;GET CHANNEL ADDRESS
	MOVE T2,UDBAKA(P3)	;AND UNIT ADDRESS
	BUG(CHK,RP4SSC,<PHYP4 - STUCK SECTOR COUNTER>,<T1,T2>)
	RET			;RETURN
	SUBTTL START I/O

;C(P4) := IORB , C(P3) := UDB , C(P3) := CDB

RP4SIO:	SAVEQ			;SAVE REGISTERS
	HRRZ T3,UDBERR(P3)	;GET FUNCTION IF ERROR RECOVERY
	JUMPN T3,RP4SI1		;ERROR RECOVERY?
	LDB T3,IRYFCN		;GET FCN
	CAILE T3,MXRP4F		;CHECK MAXIMUM LEGAL
	BUG(HLT,RP4FEX,<PHYP4 - ILLEGAL FUNCTION>)
RP4SI1:	HLRZ Q1,RP4FCN(T3)	;TRANSLATE TO HARDWARE BITS
	TRZ Q1,(XFRFLG)		;MASK
	CALL RP4CON		;CONNECT TO DRIVE
	 RET			;UNIT DOWN (MARKED OFL)
				;RETURNS T2 := CYLINDER , T3 = REMAINDER
	CALL GTHWSC		;GET HW FORMAT SURF/SEC IN T4
	HRLI T2,DO.DC		;SET DESIRED CYLINDER
	CALL WTREG		;WRITE IN REGISTER

	MOVSI T2,DO.OF		;OFFSET REGISTER
	TRZE Q1,F22		;IF 22-SECTOR MODE
	TROA T2,OF.ECI+OF.F22	; THEN CLEAR FMT22 IN OFFSET REGISTER
	TRNE Q1,DXES		;IF NOT STOPPING ON ERROR
	TRCA T2,OF.ECI		; CLEAR OFFSET , SET ECI
	TRNN Q1,10		;IF WRITING
	CALL WTREG		; THEN CLEAR OFFSET REGISTER

	MOVE T2,T4		;GET DISK ADDRESS
	HRLI T2,DO.DA		;DESIRED ADDRESS REGISTER
	JRST CHSTRT		;START CHANNEL & GIVE GOOD RETURN
;ROUTINE TO STACK A SECOND TRANSFER COMMAND

RP4STK:	LDB T1,IRYFCN		;GET FUNCTION
	CAILE T1,MXEXFN		;LEGAL?
	BUG(HLT,RP4IF2,<PHYP4 - ILLEGAL FUNCTION AT STKIO>)
	HLRZ Q1,RP4FCN(T1)	;GET HW FUNCTION
	TRZ Q1,(XFRFLG)		;MASK
	CALL PHYBLK		;GET UNIT RELATIVE ADDRESS
	CALL RP4CV1		;GET CYL,SECTOR WITHIN CYL IN T2,T3
	MOVEM T3,UDBPS2(P3)	;UPDATE SECTOR
	CALL GTHWSC		;GET HWFMT ADDRESS IN T4
	MOVE T2,T4		;COPY
	HRLI T2,DO.DA		;BUILD DATAO WORD
	CALLRET CHSTRT		;GO STACK THE COMMAND
;ROUTINE TO CONNECT TO A DESIRED UNIT

RP4CON:	MOVSI T2,DO.DRC		;READ CONTROL REGISTER - SIEZE PORT
	CALL RDREG		; IF IN A/B MODE
	TRNN T1,CR.DVA		;PORT AVAILABLE?
	JRST RP4CN2		;NO
	MOVSI T2,DO.SR		;STATUS REGISTER
	CALL RDREG		;GO READ IT
	ANDI T1,DS.MSK		;MASK OUT DON'T CARES
	CAIE T1,DS.GUD		;DRIVE OK?
	JRST RPCERR		;CONNECT ERROR
	MOVSI T1,(US.WLK)	;CLEAR WRITE LOCKED
RP4CN1:	TLO T1,(US.OFS)		;CLEAR OFFLINE AND UNSAFE
	ANDCAM T1,UDBSTS(P3)	; ...
	CALL PHYBLK		;GET PHYSICAL DISK BLOCK
	HLRZ T1,UDBERP(P3)	;GET BLOCKS DONE
	TRNE Q1,ERETRY
	ADD T2,T1		; START AT 1ST BLOCK NOT READ
	MOVE T1,Q1		;COPY FUNCTION WORD
	CALL RP4CV1		;GET CYLINDER AND SECTOR WITHIN CYLINDER
	MOVEM T2,UDBPS1(P3)	;SAVE CYLINDER
	MOVEM T3,UDBPS2(P3)	;SAVE SURFACE, SECTOR
	RETSKP			;SKIP RETURN

;HERE IF A DUAL PORT DRIVE IS IN USE ON THE OTHER PORT

RP4CN2:	MOVSI T1,(US.OFS)	;INDICATE OFFLINE (BUT NO NEED TO CHECK
	IORM T1,UDBSTS(P3)	;HOME BLOCKS)
	RET			;CONSIDER REQUESTING PORT INTERRUPT HERE

;HERE IF WE DIDN'T GET NICE STATUS - CHECK WRITE LOCKED

RPCERR:	LDB T3,IRYFCN		;GET FCN
	CAIE T3,IRFWRT		;CHECK WRITING
	CAIN T3,IRFWTF		; OR WRITE FORMAT
	JRST RPCER1		;YES - CHECK ON-LINE
	CAIE T1,DS.GUD+DS.WRL	;NO - WRITE LOCKED?
	JRST RPCER1		;NO - SOMETHING ELSE
	MOVEI T1,0		;YES - DONT CLEAR WLK
	JRST RP4CN1		;AND CONTINUE
RPCER1:	TRNN T1,DS.MOL		;MEDIA ON LINE?
	JRST [MOVSI T3,(US.OFS)	;NO -SET OFF LINE
		 JRST RPCER3]
	TRNE T1,DS.VV		;YES - VOLUME VALID?
	JRST RPCER2		;YES - SOMETHING ELSE IS WRONG
	MOVSI T1,(US.CHB!US.OIR)	;VOLUME CHANGED - MAY NEED TO CHECK HB
	SKIPL UDBSTR(P3)	;UNIT IN STR?
	IORM T1,UDBSTS(P3)	;YES - MUST CHECK HOME BLOCKS
	CALL RP4UP		;ACK DRIVE
	JRST RP4CON		;AND TRY IT NOW

RPCER2:	CALL RP4RDR		;READ ALL REGISTERS
	CALL RP4CLR		;CLEAR DRIVE
SETUNS:	MOVEI T3,0		;ACCUMULATE STATUS HERE
	MOVE T1,RP.REG+DR.ER(P3) ;GET ERROR REGISTER
	TRNE T1,ER.UNS		;FILE UNSAFE?
	TLO T3,(US.OFS)		;OFF-LINE + UNSAFE
	MOVE T1,RP.REG+DR.ST(P3) ;GET STATUS REGISTER
	TRNE T1,DS.WRL		;WRITE LOCKED?
	TLO T3,(US.WLK)		;YES.
RPCER3:	IORM T3,UDBSTS(P3)	;SET IN STATUS
	RET			;ERROR RETURN
;HERE TO DISCONNECT FROM A DUAL PORT DRIVE

RP4DIS:	MOVSI T1,(US.PGM)	;IS THIS A VARIABLE DUAL PORT
	TDNN T1,UDBSTS(P3)	;DISK?
	RET			;NO.
	MOVE T2,[DO.DRC+DF.REL]	;DRIVE CONTROL REG, RELEASE PORT
	CALL WTREG		;SEND TO DRIVE
	RET

;HERE TO DETERMINE THE CYLINDER ASSOCIATED WITH AN IORB

;P3/ UDB
;P4/ IORB
;	CALL RP4CNV	;ENTERED BY CALL UDSCNV
;RETURNS+1(ALWAYS):
;T2/ CYLINDER (UDBPS1)
;T3/ SECTOR WITHIN CYLINDER (UDBPS2)

RP4CNV:	CALL PHYBLK		;GET UNIT RELATIVE BLOCK ADDRESS
	LDB T1,IRYFCN		;GET FUNCTION FROM IORB
	CAIG T1,MXEXFN		;GREATER THAN MAXIMUM EXTERNAL FUNCTION?
	SKIPN T1,RP4FCN(T1)	;OR HAVE NULL TABLE ENTRY?
	BUG(HLT,RP4IFC,<PHYP4 - ILLEGAL FUNCTION AT CNV>) ;YES TO EITHER
	HLRZS T1		;GET FUNCTION CODE AND FLAGS
	TRZ T1,(XFRFLG)		;MASK
RP4CV1:	HRRZ T3,RP.SCL(P3)	;GET SECTORS PER CYLINDER
;	TRNE T1,F22		;22 SECTOR MODE?
;	HRRZ T3,...		;GET SECTORS PER CYL IN 22 SEC MODE
	IDIVI T2,(T3)		;CONVERT
	RET

;VERY SPECIAL PURPOSE COMMON CODE TO TRANSLATE SECTOR WITHIN CYL
;IN T3 INTO HWFMT SURF/SECT ADDR IN T4

GTHWSC:	HRRZ T4,RP.SSF(P3)	;GET SECTORS PER SURFACE
;	TRNE Q1,F22		;22 SECTOR MODE?
;	HRRZ T4,....		;GET SECTORS PER SURFACE IN 22 SECTOR
	IDIVI T3,(T4)		;GET SURFACE AND SECTOR
	DPB T3,[POINT 5,T4,27]	; SET T4 TO DESIRED ADDRESS
	RET
SUBTTL LATENCY OPTIMIZATION

;HERE TO DETERMINE WHICH TRANSFER REQUEST TO THIS UNIT HAS
;THE SMALLEST LATENCY GREATER THAN A SPECIFIED MINIMUM.

;P1/ CDB
;P3/ UDB
;T1/ MINIMUM LATENCY IN MICROSECONDS (0 FOR COMMAND STACK COMPUTATION)
;	CALL UDSLTM(CDB)
;RETURNS+1:
;NO REQUESTS AVAILABLE
;RETURNS+2:
;T1/ LATENCY OF CLOSEST REQUEST GREATER THAN SPECIFIED MINIMUM (USEC)
;T2/ PREDECESSOR OF IORB CORRESPONDING TO TIME IN T1
;T3/ IORB CORRESPONDING TO TIME IN T1

;IF COMMAND STACKING COMPUTATION WAS REQUESTED, THE DISK IS ASSUMED TO
;BE ONE PAGE BEYOND THE CURRENT TRANSFER

;CLOBBERS P4,P5,P6

;REGISTER USAGE:
;T3/ MINIMUM LATENCY,,CURRENT UNIT POSITION
;T4/ BEST LATENCY SO FAR,,PREDECESSOR TO CURRENT IORB
;P4/ CURRENT IORB
;P5/ PREDECESSOR TO BEST IORB,,BEST IORB SO FAR

;NOTE:	IF THE ONLY REQUESTS AVAILABLE ARE BETWEEN THE CURRENT UNIT
;	POSITION AND THE MINIMUM LATENCY THRESHOLD, THE LATENCY OF
;	THE CLOSEST SUCH REQUEST IS RETURNED PLUS ONE REVOLUTION.
;	THIS ELIMINATES THE SPECIAL CASE CHECKS IN SCHLTM.

RP4LTM:	JUMPE T1,RP4LT6		;COMMAND STACKING COMPUTATION?
	HRRZ T2,RP.USU(P3)	;GET TIME PER 1/64. SECTOR UNIT
	IDIVI T1,(T2)		;CONVERT TIME TO UNITS
	HRLO P4,T1		;SAVE AND INITIALIZE CURRENT POSITION
	MOVEI T4,3		;MAXIMUM NUMBER OF TIMES TO READ POSITION
RP4LT1:	MOVSI T2,DO.LA		;READ LOOKAHEAD REGISTER
	CALL RDREG		; ...
	ANDI T1,3777		;MASK UNDEFINED BITS
	CAIN T1,(P4)		;SAME AS LAST READING?
	JRST RP4LT2		;YES - USE IT
	HRR P4,T1		;NO - SAVE THIS ONE
	SOJG T4,RP4LT1		;LOOP
RP4LT2:	MOVE T3,P4		;SAVE MIN LATENCY,,CURRENT POSITION
	HRROI T4,UDBTWQ(P3)	;INITIALIZE BEST LATENCY,,PREDECESSOR
	TLNN T3,-1		;IF STACKING,
	HRR T4,IRBLNK(T4)	;EXCLUDE HEAD
	SETZB P4,P5		;INITIALIZE CURRENT AND BEST IORBS
RP4LT3:	HRRZ P4,IRBLNK(T4)	;SET CURRENT FROM PREDECESSOR
	JUMPE P4,RP4LT5		;END OF LIST?
	CALL PHYBLK		;NO - GET UNIT RELATIVE ADDRESS
	MOVE T1,T2		;COPY
	HRRZ T2,RP.SCL(P3)	;GET SECTOR PER CYLINDER
	IDIVI T1,(T2)		;GET SECTOR WITHIN CYLINDER
	MOVE T1,T2		;COPY
	HRRZ T2,RP.SSF(P3)	;GET SECTORS PER SURFACE
	IDIVI T1,(T2)		;GET SECTOR WITHIN SURFACE
	MOVE T1,T2		;AS REMAINDER
	LSH T1,^D6		;CONVERT TO 1/64. SECTOR UNITS
	SUBI T1,(T3)		;COMPUTE DISTANCE TO THIS REQUEST
	SKIPGE T1		;IF NEGATIVE,
	ADD T1,RP.USF(P3)	;GET ABSOLUTE DISTANCE
	HLRZ T2,T3		;GET MINIMUM LATENCY SPECIFIED
	CAMGE T1,T2		;IS THIS REQUEST GREATER?
	ADD T1,RP.USF(P3)	;NO - MUST DO IT ONE REVOLUTION LATER
	HLRZ T2,T4		;COMPARE TO BEST LATENCY SO FAR
	CAML T1,T2		;LESS?
	JRST RP4LT4		;NO - DO NEXT REQUEST
	HRL T4,T1		;YES - SAVE AS CURRENT BEST LAT
	MOVE P5,P4		;COPY CURRENT IORB
	HRL P5,T4		;COPY PREDECESSOR IORB
	JUMPE T1,RP4LT5		;IF ZERO LATENCY, CAN DO NO BETTER
	MOVEI P6,^D7		;RESET NUMBER OF REQUESTS TO SCAN
RP4LT4:	HRR T4,P4		;PREDECESSOR BECOMES CURRENT IORB
	SOJG P6,RP4LT3		;LOOK AT NEXT IORB
RP4LT5:	JUMPE P5,RP4LTE		;IF NONE FOUND, ERROR
	HLRZ T1,T4		;GET BEST LATENCY FOUND
	HRRZ T2,RP.USU(P3)	;GET USEC PER UNIT
	IMULI T1,(T2)		;CONVERT BACK TO MICROSECONDS
	HLRZ T2,P5		;GET PREDECESSOR TO BEST IORB
	HRRZ T3,P5		;GET BEST IORB
	RETSKP

;HERE WHEN COMMAND STACKING COMPUTATION IS REQUESTED

RP4LT6:	MOVE T1,UDBPS2(P3)	;GET CURRENT SECTOR
	CAMN T1,RP.LST(P3)	;LAST PAGE ON A CYLINDER?
	RET			;YES - DONT
	ADDI T1,4		;ASSUME DISK IS AT THE NEXT PAGE
	HRRZ T2,RP.SSF(P3)	;GET SECTORS PER SURFACE
	IDIVI T1,(T2)		;COMPUTE ROTATIONAL POSITION
	LSH T2,^D6		;CONVERT TO HWFMT
	MOVE P4,T2		;COPY RESULT
	JRST RP4LT2		;JOIN COMMON CODE

RP4LTE:	BUG(HLT,RP4LTF,<PHYP4 - FAILED TO FIND TWQ ENTRY AT RP4LTM>)
	RET
	SUBTTL POSTION REQUEST

;C(P4) := IORB , C(P3) := UDB , C(P1) := CDB

RP4POS:	HLRZ Q1,RP4FCN+IRFSEK	;GET OP CODE FOR SEEK
	CALL RP4CON		;SEE IF DRIVE THERE AND CONNECT
	 RET			;ERROR RETURN
	HRLI T2,DO.DC		;C(T2) := DESIRED CYLINDER
RP4MOV:	PUSH P,T2		;SAVE ARGUMENT
	MOVSI T2,DO.OF		;CLEAR OFFSET REGISTER
	CALL WTREG		;...
	MOVSI T2,DO.DA		;CLEAR POSSIBLE ILLEGAL
	CALL WTREG		; SECTOR FROM DESIRED ADDRESS
	POP P,T2		;RESTORE DESIRED CYLINDER
	JRST CHSTRT		;START CHANNEL & SKIP RETURN
	SUBTTL INTERRUPT PROCESSING

;ROUTINE TO HANDLE ATTENTION INTERRUPTS

RP4ATN:	MOVSI T2,DO.SR		;SET TO READ STATUS REGISTER
	CALL RDREG		;...
	TRNN T1,DS.MOL		;MEDIA ON-LINE?
	JRST RP4OFL		;NO - OFF-LINE INTERRUPT.
	TRNN T1,DS.VV		;YES - VOLUME VALID?
	JRST RP4ATF		;NO - FREE INTERRUPT (ON-LINE)
	MOVE T2,UDBSTS(P3)	;YES, GET STATUS OF DRIVE
	TLNN T2,(US.ACT)	;EXPECTING AN INTERRUPT FROM THIS DRIVE?
	JRST ATNXIT		;NO - IGNORE IT
	CALL SETIRB		;GET ACTIVE IORB(PRESERVES T1)
	SKIPE T2,UDBERR(P3)	;IN ERROR RECOVERY?
	JRST ERRATN		;YES, HAVE TO USE A DISPATCH ADDRESS
	TRNE T1,DS.ERR		;NO, ERROR?
	JRST RP4ATE		;YES

;HERE ON INTERRUPT WITH NO ERRORS
RP4ATD:	AOS UDBSEK(P3)		;NOTE SEEK
	PUSH P,Q1		;PRESERVE REG
	SKIPE UDBERR(P3)	;IF IN ERROR RECOVERY AND JUST WON,
	CALL SFTSEK		;READ THE REGISTERS NOW - AT END
	 JFCL
	POP P,Q1		;RECOVER Q1
	TLO Q1,-1		;SET FLAG FOR UPPER LEVEL
	CALL PHYPDN		;INFORM PHYSIO
ATNX0:	MOVEI P4,0		;NO SPECIFIC IORB TO RETURN
ATNXIT:	MOVEI T2,1		;POSITION BIT
	HRRZ T1,UDBAKA(P3)	;GET CURRENT CHANNEL ADDRESS
	ROT T2,(T1)		;THE BIT
	HRLI T2,DO.AS		;BUILD DATAO
	CALL WTREG		;WRITE ATTENTION SUMMARY REGISTER
	HRRZ T3,UDBAKA(P3)	;GET THE UNIT # OF DRIVE IN ERROR
	CAMN T3,CDBXFR(P1)	;IS IT THE TRANSFERRING DRIVE?
	RET			;YES -- SOMEONE ELSE WANTS TO LOOK AT IT FIRST
	CALLRET RP4CLR		;CLEAR DRIVE AND BACK TO CHANNEL


RP4ATE:	HRRZ T3,UDBAKA(P3)	;ERROR - GET UNIT #
	CAMN T3,CDBXFR(P1)	;SAME UNIT AS TRANSFER?
	JRST ATNX0		;YES - ERROR ON XFERING UNIT (IGNORE)
				; WILL HANDLE LATER IN XFER INTERRUPT CODE

;HERE IF AN ERROR ON A NON-TRANSFERRING DRIVE
	CALL RP4RDR		;READ ALL DRIVE REGISTERS
	MOVE T1,RP.REG+DR.ST(P3) ;GET STATUS REGISTER
	MOVE T2,RP.REG+DR.ER3(P3) ;GET ERROR REGISTER 3
	MOVE T3,RP.REG+DR.ER(P3) ;GET ERROR REGISTER
	TRNE T2,E3.SKI		;SEEK INCOMPLETE,
	TRNE T3,ER.UNS		; AND NOT UNSAFE?
	JRST RP4AT2		;NO - JUST SEEK ERROR
	TRNN T1,DS.DRY		;YES, DRIVE READY?
	JRST ATNX0		;NO - UNIT STILL DOING RECAL, WAIT 
				;RECALIBRATE DONE, FALL INTO POSITIONING ERROR CODE

RP4AT2:	MOVSI T1,(ES.POS)	;INDICATE A POSITION ERROR
	IORM T1,UDBERR(P3)	;IN RECOVERY STATE WORD
	CALL RP4CDA		;CLEAR DA & DC
	MOVSI T1,(IS.ERR)	;FLAG ERROR IN IORB
	IORM T1,IRBSTS(P4)	; ...
	TLO P4,-1		;SET SEEK ERROR FLAG
	CALLRET RP4CLR		;RESET DEVICE AND RETURN TO CHANNEL
;HERE ON FREE INTERRUPT (PACK CAME ON LINE)
RP4ATF:	MOVSI T1,(US.OFS)	;CLEAR OFF-LINE
	ANDCAM T1,UDBSTS(P3)	; AND FILE UNSAFE BITS
	MOVSI T1,(US.CHB!US.OIR) ;MAY NEED TO CHECK HOME BLOCKS
	SKIPL UDBSTR(P3)	; ...
	IORM T1,UDBSTS(P3)	;MUST CHECK HOME BLOCKS
	CALL RP4UP		;ISSUE PACK ACK
	TLO Q1,-1		;SET FLAG FOR UPPER LEVEL
	JRST PHYONL		;INFORM PHYSIO

;HERE ON ATTENTION INTERRUPT IF DRIVE IS IN ERROR RECOVERY
ERRATN:	MOVE T1,UDBERR(P3)	;GET FUNCTION BEING PERFORMED
	SKIPL T1,RP4FCN(T1)	;GET DISPATCH ADDRESS
	JRST (T1)		;GO PROCESS THE INTERRUPT
	JRST ATNX0		;DATA TRANSFER FUNCTION - DEFER


;HERE FOR INTERRUPTS OTHER THAN ATTENTION
RP4INT:	CALL SETIRB		;SET UP IORB INTO P4
	HRRZ T1,UDBERR(P3)	;GET FUNCTION IF ERR RECOV
	SKIPN T1		;IN ERROR RECOVERY?
	LDB T1,IRYFCN		;GET FCN CODE
	CAIG T1,MXRP4F		;CHECK IF LEGAL
	SKIPL T1,RP4FCN(T1)	;GET TABLE ENTRY
	BUG(HLT,RP4ILF,<PHYP4 - ILLEGAL FUNCTION ON INTERRUPT>)
	JRST 0(T1)		;THE LEAP OF FAITH
	SUBTTL READ/WRITE INTERRUPTS

RP4RED:
RP4WRT:	MOVSI T2,DO.OF		;CLEAR ECI
	TRNE T1,DXES		; IF THEY WERE ON (NEXT TO LAST TRY)
	CALL WTREG
	MOVSI T2,DO.SR		;READ THE STATUS REGISTER
	CALL RDREG		;...
	TRNN T1,DS.ERR		;ANY ERROR?
	CALL CKERR		;CHECK CHANNEL ERRORS ALSO
	 JRST RP4DER		;YES - GO DECODE
	CALL PHYCNT		;GET LENGTH OF TRANSFER
	LSH T1,-7		;AS BLOCKS
	LDB T2,IRYFCN		;GET FUNCTION CODE
	CAIN T2,IRFRED		;READ?
	ADDM T1,UDBRED(P3)	;YES
	CAIN T2,IRFWRT		;WRITE?
	ADDM T1,UDBWRT(P3)	; YES
	SKIPE UDBERR(P3)	;WAS DRIVE BEING ERROR-RECOVERED?
	CALL RP4RDR		;YES, READ REGISTERS AT SUCCESS
	MOVSI T1,(CS.AC2)	;IF STACKED COMMAND ACTIVE
	TDNN T1,CDBSTS(P1)	;DONT RELEASE PORT
	CALL RP4DIS		;DISCONNECT IF DUAL PORT DRIVE
	RETSKP

;HERE IF ERROR DETECTED ON DATA XFER

RP4DER:	CALL RP4RDR		;READ ALL DRIVE REGISTERS
				;AND FALL INTO RP4IER

;HERE ON ALL INTERRUPT DETECTED TRANSFER ERRORS

RP4IER:	MOVSI T1,(IS.ERR)
	IORM T1,IRBSTS(P4)
	CALL RP4CLR		;CLEAR THE DRIVE
	RET

;HERE ON INTERRUPT AFTER LAST PART OF XFER DONE (ECC FIXED 1ST PART)
RP4ECF:	MOVSI T2,DO.SR		;READ THE STATUS REGISTER
	CALL RDREG
	TRNE T1,DS.ERR		;ERROR?
	JRST RP4DER		;YES, GO HANDLE IT
	CALL RP4RDR		;GET REGISTERS AT SUCCESS
	CALL RP4IER		;NO, NOW TELL PHYSIO ABOUT THE ERROR
	MOVSI T1,(ES.ECC)	;INDICATE AN ECC ERROR
	IORM T1,UDBERR(P3)	; IN THE ERROR WORD
	RET
	SUBTTL ERROR RECOVERY CODE, ENTERED BY PHYSIO ON ERROR
REPEAT 0,<
ENTERED BY PHYSIO WHEN IS.ERR IS ON IN THE IORB, WITH UDBERP SET UP.
ON THE FIRST ERROR THE STATUS WILL BE READ INTO THE ERROR BLOCK
ERROR RECOVERY WILL BE ATTEMPTED, AND A NON-SKIP RETURN TO PHYSIO
INDICATES THAT ERROR RECOVERY IS IN PROGRESS.
A SKIP-RETURN INDICATES THAT ERROR RECOVERY IS DONE (HARD ERROR)

IF ENTERED BY PHYSIO WITH IS.ERR OFF IN THE IORB, JUST READ THE FINAL
STATUS (SOFT, SO WE RECOVERED) INTO THE ERROR BLOCK, AND SKIP-RETURN
>

RP4ERR:	SAVEQ			;SAVE ACCUMULATORS
	HRRZ Q1,UDBERP(P3)	;GET ERROR BLOCK (IF PRESENT)
	MOVE Q2,UDBSTS(P3)	;Q2 CONTAINS STATUS,
	AOS Q3,UDBERC(P3)	;AND Q3 HAS THE RETRY COUNTER
	SOJN Q3,NOT1ST		;GO IF NOT THE FIRST TIME

;HERE ON FIRST ERROR, SAVE DRIVE AND CHANNEL REGISTERS
	JUMPE Q1,ERR1		;IF NO ERROR BLOCK, CANT SAVE REGISTERS
	HRLI T1,RP.REG(P3)	;BUILD BLT POI