(FILECREATED " 5-Sep-85 17:15:34" {ERIS}<LISPCORE>SOURCES>DOVEDISK.;35 28282  

      changes to:  (FNS \DOVE.XFERDISK)

      previous date: " 5-Sep-85 15:04:05" {ERIS}<LISPCORE>SOURCES>DOVEDISK.;34)


(* Copyright (c) 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT DOVEDISKCOMS)

(RPAQQ DOVEDISKCOMS [(FNS \DISKDOVEINIT \DOVE.ACTONVMEMFILE \DOVE.ACTONVMEMPAGE \DOVE.XFERDISK 
			  \DoveDisk.CopyByteSwappedLabel \DoveDisk.ExecuteIOCB 
			  \DoveDisk.HandleMajorError \DoveDisk.Init \DoveDisk.InitIOCB 
			  \DoveDisk.Initiate \DoveDisk.TryRecalibrate \DoveDisk.WaitForHandlerStopped)
		     (DECLARE: EVAL@COMPILE DONTCOPY (FILES (SOURCE)
							    DOVEDECLS)
			       (COMS * DOVEDISKDECLS))
		     (GLOBALVARS \DoveDisk.IOCBPage)
		     (DECLARE: DONTEVAL@LOAD DOCOPY (P (\DISKDOVEINIT])
(DEFINEQ

(\DISKDOVEINIT
  [LAMBDA NIL                                                (* edited: "17-Jul-85 16:37")
    (for I in (QUOTE (\DISKTYPE \CONTROLLERTYPE \DLDISKSHAPE.SECTORSPERCYLINDER 
				\DLDISKSHAPE.SECTORSPERHEAD \DLDISKSHAPE.HEADSPERDRIVE 
				\IOCBSCRATCHLABEL))
       do (\LOCKVAR I))
    (for I in (QUOTE (\DOVE.ACTONVMEMFILE \DOVE.ACTONVMEMPAGE \DOVE.XFERDISK 
					  \DoveDisk.CopyByteSwappedLabel \DoveDisk.ExecuteIOCB 
					  \DoveDisk.HandleMajorError \DoveDisk.Init 
					  \DoveDisk.InitIOCB \DoveDisk.Initiate 
					  \DoveDisk.TryRecalibrate \DoveDisk.WaitForHandlerStopped))
       do (\LOCKFN I])

(\DOVE.ACTONVMEMFILE
  [LAMBDA (FILEPAGE BUFFER NPAGES WRITEFLAG)                 (* mpl "20-Jun-85 12:07")
                                                             (* Pilot page is zero-based, vmem page is one-base)
    (FRPTQ NPAGES (\DOVE.ACTONVMEMPAGE (SUB1 FILEPAGE)
				       BUFFER WRITEFLAG)
	   (SETQ BUFFER (\ADDBASE BUFFER WORDSPERPAGE))
	   (add FILEPAGE 1])

(\DOVE.ACTONVMEMPAGE
  [LAMBDA (FILEPAGE BUFFER WRITEFLAG)                        (* mpl "10-Aug-85 21:11")

          (* This fn brings in a page of the VMEM file. It scans over the bad page table, which contains a loose mapping of 
	  logical pages to physical pages.)


    (PROG ((LINKBASE (LOCF (fetch DLVMEMFILEINFO of \IOCBPAGE)))
	   (I (IQUOTIENT (IDIFFERENCE (INDEXF (fetch FLOPPYIOCBSTART))
				      (INDEXF (fetch DLVMEMFILEINFO)))
			 3)))
          (replace (PilotDiskLabel FilePageLo) of (\ADDBASE \IOCBPAGE \FAULTLABEL)
	     with (ADD1 FILEPAGE))
          (replace (PilotDiskLabel BootLinkA) of (\ADDBASE \IOCBPAGE \FAULTLABEL) with 0)
          (replace (PilotDiskLabel BootLinkB) of (\ADDBASE \IOCBPAGE \FAULTLABEL) with 0)
      LP  [COND
	    ([OR (IGREATERP (fetch DLFIRSTFILEPAGE of (fetch DLNEXTRUN of LINKBASE))
			    FILEPAGE)
		 (EQ 0 (fetch DLFIRSTFILEPAGE of (fetch DLNEXTRUN of LINKBASE]

          (* * If we're on the last page of a run, we've got to update the boot link)


	      [COND
		([EQ FILEPAGE (SUB1 (fetch DLFIRSTFILEPAGE of (fetch DLNEXTRUN of LINKBASE]
		  (replace (PilotDiskLabel BootLinkA) of (\ADDBASE \IOCBPAGE \FAULTLABEL)
		     with (fetch DLVMCYL of (fetch DLNEXTRUN of LINKBASE)))
		  (replace (PilotDiskLabel BootLinkB) of (\ADDBASE \IOCBPAGE \FAULTLABEL)
		     with (LOGOR (LLSH (fetch DLVMHEAD of (fetch DLNEXTRUN of LINKBASE))
				       8)
				 (fetch DLVMSECTOR of (fetch DLNEXTRUN of LINKBASE]
	      (COND
		((EQ (\DOVE.XFERDISK (fetch DLVMCYL of LINKBASE)
				     (fetch DLVMHEAD of LINKBASE)
				     (IPLUS (IDIFFERENCE FILEPAGE (fetch DLFIRSTFILEPAGE
								     of LINKBASE))
					    (fetch DLVMSECTOR of LINKBASE))
				     BUFFER WRITEFLAG (\ADDBASE \IOCBPAGE \FAULTLABEL))
		     (QUOTE OK))
		  (RETURN))
		(T (\MP.ERROR 93 "HARD DISK ERROR IN SWAPPER"]
          (SETQ LINKBASE (fetch DLNEXTRUN of LINKBASE))
          (COND
	    ((EQ 0 I)
	      (RAID)
	      (RETURN)))
          (SETQ I (SUB1 I))
          (GO LP])

(\DOVE.XFERDISK
  [LAMBDA (CYL HD SEC BUFFER MODE LABEL RUNLENGTH NORAIDFLG)
                                                             (* hts: " 5-Sep-85 17:12")
    (DECLARE (GLOBALVARS \IOCBPAGE \DLDISKSHAPE.HEADSPERDRIVE \DLDISKSHAPE.SECTORSPERHEAD)
	     (CONSTANTS \IOCBSCRATCHLABEL \DoveDisk.ReadCmd \DoveDisk.VerifyCmd \DoveDisk.WriteCmd))
    (SETQ HD (IPLUS HD (IQUOTIENT SEC \DLDISKSHAPE.SECTORSPERHEAD)))
    (SETQ SEC (IREMAINDER SEC \DLDISKSHAPE.SECTORSPERHEAD))
    (SETQ CYL (IPLUS CYL (IQUOTIENT HD \DLDISKSHAPE.HEADSPERDRIVE)))
    (SETQ HD (IREMAINDER HD \DLDISKSHAPE.HEADSPERDRIVE))
    [\CLEARWORDS \IOCBPAGE (SUB1 (INDEXF (fetch (Dove.DiskIOCB DOBBase]
    (with Dove.DiskIOCB \IOCBPAGE (SETQ Header.Cylinder CYL)
	  (SETQ Header.Head HD)
	  (SETQ Header.Sector SEC)
	  [SETQ LabelPtr (COND
	      (LABEL LABEL)
	      (T (\ADDBASE \IOCBPAGE \IOCBSCRATCHLABEL]
	  (SETQ DataPtr BUFFER)
	  (SETQ HeaderCmd \DoveDisk.VerifyCmd)
	  (SELECTQ MODE
		   (VRR (SETQ LabelCmd \DoveDisk.ReadCmd)
			(SETQ DataCmd \DoveDisk.ReadCmd))
		   (VVR (SETQ LabelCmd \DoveDisk.VerifyCmd)
			(SETQ DataCmd \DoveDisk.ReadCmd))
		   (VVW (SETQ LabelCmd \DoveDisk.VerifyCmd)
			(SETQ DataCmd \DoveDisk.WriteCmd))
		   (VWW (SETQ LabelCmd \DoveDisk.WriteCmd)
			(SETQ DataCmd \DoveDisk.WriteCmd))
		   (T (SETQ LabelCmd \DoveDisk.WriteCmd)
		      (SETQ DataCmd \DoveDisk.WriteCmd))
		   (NIL (SETQ LabelCmd \DoveDisk.ReadCmd)
			(SETQ DataCmd \DoveDisk.ReadCmd))
		   (PROGN (RAID "Invalid MODE")))
	  (SETQ IncDataPtr NIL)
	  (SETQ RetryStrategy 10)
	  (SETQ PageCount (OR (SMALLP RUNLENGTH)
			      1)))
    (SELECTC (\DoveDisk.ExecuteIOCB \IOCBPAGE)
	     (\DoveDisk.NoError (QUOTE OK))
	     (\DoveDisk.VerifyError (QUOTE VERIFYERROR))
	     (PROGN (COND
		      ((OR (EQ MODE (QUOTE VRR))
			   (EQ MODE (QUOTE VVR)))
			(QUOTE READERROR))
		      (T (QUOTE WRITEERROR])

(\DoveDisk.CopyByteSwappedLabel
  [LAMBDA (FROMPTR TOPTR)                                    (* MPL "16-Jun-85 14:25")

          (* * This atrocity is due to the IOP's byteswapping mess)


    (for I from 0 to 9 do (\PUTBASE TOPTR I (\DoveIO.ByteSwap (\GETBASE FROMPTR I])

(\DoveDisk.ExecuteIOCB
  [LAMBDA (IOCB)                                             (* mpl " 3-Aug-85 21:17")

          (* * This function attempts to execute a disk IOCB)


    (DECLARE (GLOBALVARS \DoveIORegion)
	     (CONSTANTS \Dove.DiskFCBOffset \DoveIO.ByteFALSE \DoveIO.ByteTRUE))
    (PROG (FCBPtr DOBPtr (TriesLeft 16)
		  (TriedRecalibrate NIL))
          (SETQ FCBPtr (\ADDBASE \DoveIORegion \Dove.DiskFCBOffset))
          (SETQ DOBPtr (LOCF (fetch (Dove.DiskIOCB DOBBase) of IOCB)))

          (* * Gotta try at least once...)


      DoItAgain
          [COND
	    ((EQ 0 (SETQ TriesLeft (SUB1 TriesLeft)))
	      (RETURN (\DoveIO.ByteSwap (fetch (Dove.DOB LastError.BS) of DOBPtr]
          (\DoveDisk.Initiate IOCB NIL)
          [COND
	    ((EQ (fetch (Dove.DiskIOCB LabelCmd) of IOCB)
		 \DoveDisk.ReadCmd)
	      (\DoveDisk.CopyByteSwappedLabel (LOCF (fetch (Dove.DOB Label.FileID) of DOBPtr))
					      (fetch (Dove.DiskIOCB LabelPtr) of IOCB]
          (COND
	    ((EQ (fetch (Dove.DiskIOCB HError) of IOCB)
		 \DoveIO.ByteFALSE)
	      (RETURN \DoveDisk.NoError)))
          (COND
	    ((NEQ (fetch (Dove.DiskFCB HandlerState) of FCBPtr)
		  \DoveDisk.NormalHandlerState)
	      (\DoveDisk.HandleMajorError IOCB)
	      (GO DoItAgain)))
          (replace (Dove.DiskIOCB HStopHandlerOnCompletion) of IOCB with \DoveIO.ByteTRUE)
          (COND
	    ((EQ TriesLeft 8)
	      (\DoveDisk.TryRecalibrate IOCB)
	      (SETQ TriedRecalibrate T)))
          (GO DoItAgain])

(\DoveDisk.HandleMajorError
  [LAMBDA (IOCB)                                             (* mpl "15-Jul-85 09:10")
    (DECLARE (GLOBALVARS \DoveIORegion)
	     (CONSTANTS \DoveIO.ByteTRUE \DoveIO.ByteFALSE \Dove.DiskFCBOffset))
    (\DoveDisk.WaitForHandlerStopped)
    (with Dove.DiskIOCB IOCB (SETQ HStopHandlerOnCompletion \DoveIO.ByteTRUE)
	  (SETQ HOnlyDOBFromController \DoveIO.ByteFALSE)
	  (SETQ HInProgress \DoveIO.ByteFALSE)
	  (SETQ HComplete \DoveIO.ByteFALSE)
	  (SETQ HDOBError \DoveIO.ByteFALSE)
	  (SETQ HDMATimedOut \DoveIO.ByteFALSE))
    (replace (Dove.DiskFCB HandlerState) of (\ADDBASE \DoveIORegion \Dove.DiskFCBOffset)
       with \DoveDisk.NormalHandlerState)
    (\DoveIO.NotifyIOP (fetch (Dove.DiskFCB WorkMask) of (\ADDBASE \DoveIORegion \Dove.DiskFCBOffset))
		       )
    (\DoveDisk.WaitForHandlerStopped)
    (with Dove.DiskIOCB IOCB (SETQ HStopHandlerOnCompletion \DoveIO.ByteTRUE)
	  (SETQ HOnlyDOBFromController \DoveIO.ByteFALSE)
	  (SETQ HInProgress \DoveIO.ByteFALSE)
	  (SETQ HComplete \DoveIO.ByteFALSE)
	  (SETQ HDOBError \DoveIO.ByteFALSE)
	  (SETQ HDMATimedOut \DoveIO.ByteFALSE])

(\DoveDisk.Init
  [LAMBDA NIL                                                (* mpl " 6-Aug-85 13:04")

          (* * This fn is analagous to \DL.DISKINIT, the function which initializes the disk head on the DLion)


    (DECLARE (GLOBALVARS \DISKTYPE \CONTROLLERTYPE \DLDISKSHAPE.SECTORSPERCYLINDER 
			 \DLDISKSHAPE.SECTORSPERHEAD \DLDISKSHAPE.HEADSPERDRIVE \IOCBSCRATCHLABEL)
	     (CONSTANTS \Dove.VmemPageRunTableOffset \Dove.DiskFCBOffset))

          (* * We already know what kind of controller...)


    (SETQQ \CONTROLLERTYPE \ST506)

          (* * No real limit on the number of different disk drives now...)


    (SETQQ \DISKTYPE \SEAGATE)

          (* * Initialize drive parameters)


    (with Dove.DCB (LOCF (fetch (Dove.DiskFCB DCB0Base) of (\ADDBASE \DoveIORegion 
								     \Dove.DiskFCBOffset)))
	  (SETQ \DLDISKSHAPE.HEADSPERDRIVE HeadsPerCylinder)
	  (SETQ \DLDISKSHAPE.SECTORSPERHEAD SectorsPerTrack)
	  (SETQ \DLDISKSHAPE.SECTORSPERCYLINDER (ITIMES HeadsPerCylinder SectorsPerTrack)))

          (* * The VMEM table is built in the IORegion now. Copy it from the IORegion to where the disk code expects to find 
	  it.)


    (\CLEARWORDS \IOCBPAGE WORDSPERPAGE)
    (\BLT (LOCF (fetch (IOCBPAGE DLVMEMFILEINFO) of \IOCBPAGE))
	  (\ADDBASE \DoveIORegion \Dove.VmemPageRunTableOffset)
	  128)

          (* * This fn is in DISKDLION. It sets up the DOB chain that the fault handler will use and the file system currently
	  uses.)


    (\DL.INIT.DOB.CHAIN)
    NIL])

(\DoveDisk.InitIOCB
  [LAMBDA (IOCBPtr JustRecalibrate?)                         (* mpl " 3-Aug-85 19:26")
    (DECLARE (GLOBALVARS \DoveIORegion)
	     (CONSTANTS \Dove.DiskFCBOffset \DoveIO.ByteFALSE \DoveIO.ByteTRUE 
			\DoveDisk.DefaultDrive&ControllerStatus \DoveDisk.DefaultWriteEndCount 
			\DoveDisk.CRC \DoveDisk.NoError \DoveDisk.RestoreOp \DoveDisk.VerifyCmd 
			\DoveDisk.NoopCmd \DoveDisk.ReadCmd \DoveDisk.WriteCmd \DoveDisk.ReadLabelOp 
			\DoveDisk.WriteLabelAndDataOp \DoveDisk.ReadDataOp \DoveDisk.WriteDataOp 
			\DoveDisk.VerifyDataOp \DoveDisk.Read \DoveDisk.Write \DoveDisk.NoOperation 
			\DoveDisk.FromLisp \DoveDisk.ToLisp))

          (* * This fn is used to fill in all the fields for an IOCB. The Dove disk software wasn't very well designed, so 
	  there's lots of redundancy here)


    (PROG ((DOBBase (LOCF (fetch (Dove.DiskIOCB DOBBase) of IOCBPtr)))
	   [DCBBase (LOCF (fetch (Dove.DiskFCB DCB0Base) of (\ADDBASE \DoveIORegion 
								      \Dove.DiskFCBOffset]
	   (DiskOp NIL))
          (\DoveDisk.CopyByteSwappedLabel (fetch (Dove.DiskIOCB LabelPtr) of IOCBPtr)
					  (LOCF (fetch (Dove.DOB Label.FileID) of DOBBase)))
          (\DoveIO.MakeOpieAddress (LOCF (fetch (Dove.DiskIOCB HDataPtr) of IOCBPtr))
				   (fetch (Dove.DiskIOCB DataPtr) of IOCBPtr))
          (replace (Dove.DiskIOCB HComplementDOB) of IOCBPtr with T)
          (with Dove.DiskIOCB IOCBPtr (SETQ HEtch 0)         (* Etch=1 means etch 2)
		(SETQ HUseLEDS NIL)
		(SETQ HDiagnosticCommand NIL)
		(SETQ HHalt NIL)
		(SETQ HIncDataPtr IncDataPtr)
		(SETQ HDMATimedOut \DoveIO.ByteFALSE)
		(SETQ HError \DoveIO.ByteFALSE)
		(SETQ HDOBError \DoveIO.ByteFALSE)
		(SETQ HInProgress \DoveIO.ByteFALSE)
		(SETQ HComplete \DoveIO.ByteFALSE)
		(SETQ HOnlyDOBFromController \DoveIO.ByteFALSE)
		(SETQ HStopHandlerOnCompletion \DoveIO.ByteTRUE)
		(SETQ HPageCount (\DoveIO.ByteSwap PageCount)))
          (with Dove.DOB DOBBase (SETQ Zero1 0)
		(SETQ Zero2 0)
		(SETQ Zero3 0)
		(SETQ Zero4 0)
		(SETQ Zero5 0)
		(SETQ Zero6 0)
		(SETQ Drive&ControllerStatus \DoveDisk.DefaultDrive&ControllerStatus)
		[SETQ NegativeSectorCount.BS (\DoveIO.ByteSwap (ADD1 (LOGXOR MAX.SMALLP
									     (fetch (Dove.DiskIOCB
										      PageCount)
										of IOCBPtr]
		(SETQ WriteEndCount \DoveDisk.DefaultWriteEndCount)
		(SETQ StartingSectorOnTrack 0)
		(SETQ ECCSyndromeA 0)
		(SETQ ECCSyndromeB 0)
		(SETQ ECCFlag \DoveDisk.CRC)
		(SETQ CurrentCylinder.BS (\DoveIO.ByteSwap 65535))
		(SETQ Header.Cylinder.BS (\DoveIO.ByteSwap (fetch (Dove.DiskIOCB Header.Cylinder)
							      of IOCBPtr)))
		(SETQ Header.Head (fetch (Dove.DiskIOCB Header.Head) of IOCBPtr))
		(SETQ Header.Sector (fetch (Dove.DiskIOCB Header.Sector) of IOCBPtr))
		(SETQ LabelError.BS (\DoveIO.ByteSwap \DoveDisk.NoError))
		(SETQ HeaderError.BS (\DoveIO.ByteSwap \DoveDisk.NoError))
		(SETQ DataError.BS (\DoveIO.ByteSwap \DoveDisk.NoError))
		(SETQ LastError.BS (\DoveIO.ByteSwap \DoveDisk.NoError))
		(SETQ ReducedWriteCylinder.BS (fetch (Dove.DCB ReduceWriteCurrentCylinder.BS)
						 of DCBBase))
		(SETQ PrecompensationCylinder.BS (fetch (Dove.DCB PrecompensationCylinder.BS)
						    of DCBBase))
		(SETQ SectorsPerTrack (fetch (Dove.DCB SectorsPerTrack) of DCBBase))
		(SETQ HeadsPerCylinder (fetch (Dove.DCB HeadsPerCylinder) of DCBBase))
		(SETQ CylindersPerDrive.BS (fetch (Dove.DCB CylindersPerDrive.BS) of DCBBase)))
          [COND
	    (JustRecalibrate? (replace (Dove.DOB Operation) of DOBBase with \DoveDisk.RestoreOp)
			      (SETQ DiskOp \DoveDisk.RestoreOp))
	    (T (with Dove.DiskIOCB IOCBPtr (SETQ DiskOp (COND
			 ((EQ HeaderCmd \DoveDisk.VerifyCmd)
			   (SELECTC LabelCmd
				    (\DoveDisk.ReadCmd (SELECTC DataCmd
								(\DoveDisk.NoopCmd 
									    \DoveDisk.ReadLabelOp)
								(\DoveDisk.ReadCmd 
								     \DoveDisk.ReadLabelAndDataOp)
								(PROGN NIL)))
				    (\DoveDisk.WriteCmd (COND
							  ((EQ DataCmd \DoveDisk.WriteCmd)
							    \DoveDisk.WriteLabelAndDataOp)
							  (T NIL)))
				    (\DoveDisk.VerifyCmd (SELECTC DataCmd
								  (\DoveDisk.NoopCmd 
									     \DoveDisk.ReadDataOp)
								  (\DoveDisk.ReadCmd 
									     \DoveDisk.ReadDataOp)
								  (\DoveDisk.WriteCmd 
									    \DoveDisk.WriteDataOp)
								  (\DoveDisk.VerifyCmd 
									   \DoveDisk.VerifyDataOp)
								  (PROGN NIL)))
				    (PROGN NIL]
          (COND
	    ((NOT DiskOp)
	      (RETURN T)))
          (replace (Dove.DOB Operation) of DOBBase with DiskOp)
          (replace (Dove.DiskIOCB HStopHandlerOnCompletion) of IOCBPtr with \DoveIO.ByteTRUE)

          (* * HDataCommandTransfer is a FLAG, but the damned record package won't believe it.)


          [with Dove.DiskIOCB IOCBPtr (SELECTC DiskOp
					       (\DoveDisk.ReadDataOp (SETQ HDataCommandTransfer 1)
								     (SETQ HDataCommandDirection 
								       \DoveDisk.ToLisp)
								     (SETQ HDataXferDirection 
								       \DoveDisk.Read))
					       (\DoveDisk.ReadLabelAndDataOp (SETQ 
									     HDataCommandTransfer 1)
									     (SETQ 
									    HDataCommandDirection 
									       \DoveDisk.ToLisp)
									     (SETQ HDataXferDirection 
									       \DoveDisk.Read))
					       (\DoveDisk.WriteDataOp (SETQ HDataCommandTransfer 1)
								      (SETQ HDataCommandDirection 
									\DoveDisk.FromLisp)
								      (SETQ HDataXferDirection 
									\DoveDisk.Write))
					       (\DoveDisk.WriteLabelAndDataOp (SETQ 
									     HDataCommandTransfer 1)
									      (SETQ 
									    HDataCommandDirection 
									       \DoveDisk.FromLisp)
									      (SETQ 
									       HDataXferDirection 
										\DoveDisk.Write))
					       (PROGN (SETQ HDataCommandTransfer 0)
						      (SETQ HDataXferDirection \DoveDisk.NoOperation]
          (RETURN NIL])

(\DoveDisk.Initiate
  [LAMBDA (IOCBPtr JustRecalibrate?)                         (* mpl "31-Jul-85 21:30")
    (DECLARE (GLOBALVARS \DoveIORegion)
	     (CONSTANTS \Dove.DiskFCBOffset \DoveIO.ByteFALSE \DoveIO.ByteTRUE))

          (* * This one actually makes it all happen)


    (PROG ((InvalidOp NIL)
	   [DCBBase (LOCF (fetch (Dove.DiskFCB DCB0Base) of (\ADDBASE \DoveIORegion 
								      \Dove.DiskFCBOffset]
	   (ShortIOCBPtr (\LOLOC IOCBPtr))
	   (Completion NIL))
          (replace (Dove.DCB Recalibrate) of DCBBase with JustRecalibrate?)
          (\DoveIO.MakeOpieAddress (LOCF (fetch (Dove.DiskIOCB IOPNext) of IOCBPtr))
				   NIL)
          (with Dove.DiskIOCB IOCBPtr (SETQ Try 1)
		(SETQ HStopHandlerOnCompletion \DoveIO.ByteTRUE))
          (SETQ InvalidOp (\DoveDisk.InitIOCB IOCBPtr JustRecalibrate?))

          (* * Now, diddle with the IOREgion)


          [COND
	    (InvalidOp (with Dove.DiskIOCB IOCBPtr (SETQ HError \DoveIO.ByteTRUE)
			     (SETQ Completion (QUOTE INVALIDOPERATION))
			     (SETQ HComplete \DoveIO.ByteTRUE)
			     (RETURN Completion]

          (* * Fix up the IOCB so it's the first and the last)


          (replace (Dove.DiskIOCB MesaNext) of IOCBPtr with 0)
          (with Dove.DCB DCBBase (SETQ MesaHead ShortIOCBPtr)
		(SETQ MesaTail ShortIOCBPtr))
          (replace (Dove.DiskIOCB HNextIOCB) of IOCBPtr with 0)
          (\DoveIO.LockMem \DoveIO.OVERWRITEIFNIL [IPLUS \Dove.DiskFCBOffset
							 (INDEXF (fetch (Dove.DiskFCB DCB0Base)))
							 (INDEXF (fetch (Dove.DCB HandlerMesaNext]
			   (\DoveIO.ByteSwap ShortIOCBPtr)
			   (fetch (Dove.DiskFCB LockMask) of (\DoveFCBAt \Dove.DiskFCBOffset)))
          (replace (Dove.DiskIOCB HComplete) of IOCBPtr with \DoveIO.ByteFALSE)
          (replace (Dove.DiskFCB StartHandlerForMesa) of (\DoveFCBAt \Dove.DiskFCBOffset)
	     with 65535)
          (\DoveIO.NotifyIOP (fetch (Dove.DiskFCB WorkMask) of (\ADDBASE \DoveIORegion 
									 \Dove.DiskFCBOffset)))
          (repeatuntil (EQ \DoveIO.ByteTRUE (fetch (Dove.DiskIOCB HComplete) of IOCBPtr)))
          (replace (Dove.DCB Recalibrate) of DCBBase with NIL)
          (RETURN (fetch (Dove.DiskIOCB HError) of IOCBPtr])

(\DoveDisk.TryRecalibrate
  [LAMBDA (IOCB)                                             (* mpl "16-Jul-85 12:54")
    (DECLARE (GLOBALVARS \DoveIORegion)
	     (CONSTANTS \Dove.DiskFCBOffset))
    (PROG [OLDCMD (DOBBase (LOCF (fetch (Dove.DiskIOCB DOBBase) of IOCB]
          (SETQ OLDCMD (fetch (Dove.DOB Operation) of DOBBase))
          (\DoveDisk.Initiate IOCB T)
          (replace (Dove.DOB Operation) of DOBBase with OLDCMD])

(\DoveDisk.WaitForHandlerStopped
  [LAMBDA NIL                                                (* mpl "15-Jul-85 09:17")
    (to 30000 do (COND
		   ((NEQ (fetch (Dove.DiskFCB HandlerStoppedForMesa) of (\ADDBASE \DoveIORegion 
									      \Dove.DiskFCBOffset))
			 \DoveIO.ByteFALSE)
		     (RETURN)))
       finally (RAID])
)
(DECLARE: EVAL@COMPILE DONTCOPY 
(FILESLOAD (SOURCE)
	   DOVEDECLS)


(RPAQQ DOVEDISKDECLS ((CONSTANTS \DoveDisk.CRC \DoveDisk.DefaultDrive&ControllerStatus 
				 \DoveDisk.DefaultWriteEndCount \DoveDisk.NoError 
				 \DoveDisk.VerifyError \IOCBSCRATCHLABEL \FAULTLABEL 
				 \DoveDisk.NormalHandlerState)
		      (CONSTANTS \DoveDisk.WriteLabelAndDataOp \DoveDisk.WriteDataOp 
				 \DoveDisk.VerifyDataOp \DoveDisk.ReadLabelAndDataOp 
				 \DoveDisk.ReadLabelOp \DoveDisk.RestoreOp \DoveDisk.ReadDataOp 
				 \DoveDisk.ReadDiagnosticOp \DoveDisk.FormatTracksOp)
		      (CONSTANTS \DoveDisk.Execute \DoveDisk.FromLisp \DoveDisk.NoOperation 
				 \DoveDisk.NoopCmd \DoveDisk.Read \DoveDisk.ReadCmd \DoveDisk.ToLisp 
				 \DoveDisk.VerifyCmd \DoveDisk.Write \DoveDisk.WriteCmd)
		      (RECORDS Dove.DCB Dove.DOB Dove.DiskFCB Dove.DiskIOCB PilotDiskLabel)))
(DECLARE: EVAL@COMPILE 

(RPAQQ \DoveDisk.CRC 1)

(RPAQQ \DoveDisk.DefaultDrive&ControllerStatus 52824)

(RPAQQ \DoveDisk.DefaultWriteEndCount 255)

(RPAQQ \DoveDisk.NoError 0)

(RPAQQ \DoveDisk.VerifyError 35)

(RPAQQ \IOCBSCRATCHLABEL 95)

(RPAQQ \FAULTLABEL 110)

(RPAQQ \DoveDisk.NormalHandlerState 0)

(CONSTANTS \DoveDisk.CRC \DoveDisk.DefaultDrive&ControllerStatus \DoveDisk.DefaultWriteEndCount 
	   \DoveDisk.NoError \DoveDisk.VerifyError \IOCBSCRATCHLABEL \FAULTLABEL 
	   \DoveDisk.NormalHandlerState)
)
(DECLARE: EVAL@COMPILE 

(RPAQQ \DoveDisk.WriteLabelAndDataOp 4)

(RPAQQ \DoveDisk.WriteDataOp 3)

(RPAQQ \DoveDisk.VerifyDataOp 7)

(RPAQQ \DoveDisk.ReadLabelAndDataOp 6)

(RPAQQ \DoveDisk.ReadLabelOp 5)

(RPAQQ \DoveDisk.RestoreOp 0)

(RPAQQ \DoveDisk.ReadDataOp 2)

(RPAQQ \DoveDisk.ReadDiagnosticOp 8)

(RPAQQ \DoveDisk.FormatTracksOp 1)

(CONSTANTS \DoveDisk.WriteLabelAndDataOp \DoveDisk.WriteDataOp \DoveDisk.VerifyDataOp 
	   \DoveDisk.ReadLabelAndDataOp \DoveDisk.ReadLabelOp \DoveDisk.RestoreOp 
	   \DoveDisk.ReadDataOp \DoveDisk.ReadDiagnosticOp \DoveDisk.FormatTracksOp)
)
(DECLARE: EVAL@COMPILE 

(RPAQQ \DoveDisk.Execute 2)

(RPAQQ \DoveDisk.FromLisp 0)

(RPAQQ \DoveDisk.NoOperation 3)

(RPAQQ \DoveDisk.NoopCmd 0)

(RPAQQ \DoveDisk.Read 0)

(RPAQQ \DoveDisk.ReadCmd 1)

(RPAQQ \DoveDisk.ToLisp 1)

(RPAQQ \DoveDisk.VerifyCmd 3)

(RPAQQ \DoveDisk.Write 1)

(RPAQQ \DoveDisk.WriteCmd 2)

(CONSTANTS \DoveDisk.Execute \DoveDisk.FromLisp \DoveDisk.NoOperation \DoveDisk.NoopCmd 
	   \DoveDisk.Read \DoveDisk.ReadCmd \DoveDisk.ToLisp \DoveDisk.VerifyCmd \DoveDisk.Write 
	   \DoveDisk.WriteCmd)
)
[DECLARE: EVAL@COMPILE 

(BLOCKRECORD Dove.DCB ((MesaHead WORD)
		       (HandlerMesaNext WORD)
		       (MesaTail WORD)
		       (BlockMesaQueue WORD)
		       (IOPHead WORD)
		       (IOPHeadHi WORD)
		       (IOPNext WORD)
		       (IOPNextHi WORD)
		       (IOPTail WORD)
		       (IOPTailHi WORD)
		       (BlockIOPQueue WORD)
		       (CurrentDriveMask BYTE)
		       (DiskCommand BYTE)
		       (MesaClientCondition 3 WORD)
		       (IOPClientCondition 3 WORD)
		       (CurrentIOCB 2 WORD)
		       (Recalibrate FLAG)
		       (DiskMisc BITS 15)
		       (NIL BYTE)
		       (DriveType BYTE)
		       (SectorsPerTrack BYTE)
		       (HeadsPerCylinder BYTE)
		       (CylindersPerDrive.BS WORD)
		       (ReduceWriteCurrentCylinder.BS WORD)
		       (PrecompensationCylinder.BS WORD)))

(BLOCKRECORD Dove.DOB ((ECCSyndromeA WORD)
		       (ECCSyndromeB WORD)
		       (NegativeSectorCount.BS WORD)
		       (SectorsPerTrack BYTE)
		       (Zero1 BYTE)
		       (HeadsPerCylinder BYTE)
		       (Zero2 BYTE)
		       (CylindersPerDrive.BS WORD)
		       (StartingSectorOnTrack BYTE)
		       (Zero3 BYTE)
		       (ReducedWriteCylinder.BS WORD)
		       (PrecompensationCylinder.BS WORD)
		       (WriteEndCount BYTE)
		       (Zero4 BYTE)
		       (HeaderError.BS WORD)
		       (LabelError.BS WORD)
		       (DataError.BS WORD)
		       (LastError.BS WORD)
		       (CurrentCylinder.BS WORD)
		       (ECCFlag BYTE)
		       (Zero5 BYTE)                          (* These fields are switched around to byteswap them)
		       (Header.Cylinder.BS WORD)
		       (Header.Sector BYTE)
		       (Header.Head BYTE)
		       (Reserved1 WORD)
		       (Reserved2 WORD)
		       (Drive&ControllerStatus WORD)
		       (Operation BYTE)
		       (Zero6 BYTE)
		       (NegativeFormatTrackCount.BS WORD)
		       (Label.FileID 5 WORD)
		       (Label.FilePageLo WORD)
		       (Label.FilePageHi BITS 7)
		       (Label.PageZeroAttributes BITS 9)
		       (Label.AttributesInAllPages WORD)
		       (Label.Unused 2 WORD)))

(BLOCKRECORD Dove.DiskFCB ((DiskTCB 15 WORD)
			   (DiskDMATCB 15 WORD)
			   (ConditionDMAWork.BS WORD)
			   (ConditionDMADone.BS WORD)
			   (ConditionWork.BS WORD)
			   (WorkMask WORD)
			   (LockMask WORD)
			   (MesaCleanupRequest WORD)
			   (IOPCleanupRequest WORD)
			   (HandlerStoppedForMesa WORD)
			   (HandlerStoppedForIOP WORD)
			   (HandlerStoppedForMesaCleanup WORD)
			   (HandlerStoppedForIOPCleanup WORD)
			   (StartHandlerForMesa WORD)
			   (StartHandlerForIOP WORD)
			   (HandlerState WORD)
			   (CurrentClient BYTE)
			   (ClientsToTest BYTE)
			   (NumPossibleClients BYTE)
			   (LastDriveMask BYTE)
			   (CurrentDrivePtr WORD)
			   (StatusRegister BYTE)
			   (CommandRegister BYTE)
			   (TaskRetryCount BYTE)
			   (BadInterruptReason BYTE)
			   (DMAStatusRegister BYTE)
			   (BadDMAInterruptReason BYTE)
			   (UnexpectedDiskInterruptCount WORD)
			   (UnexpectedDiskDMAInterruptCount WORD)
			   (DCB0Base 25 WORD)
			   (DCB1Base 25 WORD)
			   (DCB2Base 25 WORD)
			   (DCB3Base 25 WORD)))

(BLOCKRECORD Dove.DiskIOCB ((Header.Cylinder WORD)
			    (Header.Head BYTE)
			    (Header.Sector BYTE)
			    (LabelPtr FULLXPOINTER)
			    (DataPtr FULLXPOINTER)
			    (IncDataPtr FLAG)
			    (NIL BITS 1)
			    (HeaderCmd BITS 2)
			    (LabelCmd BITS 2)
			    (DataCmd BITS 2)
			    (RetryStrategy BYTE)
			    (PageCount WORD)
			    (DeviceStatus 2 WORD)
			    (DiskHeader 2 WORD)
			    (DeviceHandle WORD)
			    (MesaNext WORD)
			    (IOPNext 2 WORD)
			    (OpType BITS 2)
			    (LabelFixupType BITS 2)
			    (LabelFixupTry BITS 12)
			    (Try WORD)
			    (Command WORD)
			    (RunLength WORD)
			    (PageLocalization WORD)
			    (NIL 14 WORD)
			    (HDataPtr 2 WORD)
			    (HDataCommandTransfer FLAG)
			    (NIL BITS 6)
			    (HDataCommandDirection BITS 1)
			    (HIncDataPtr FLAG)
			    (HComplementDOB FLAG)
			    (HEtch BITS 1)
			    (NIL BITS 2)
			    (HUseLEDS FLAG)
			    (HHalt FLAG)
			    (HDiagnosticCommand FLAG)
			    (HPageCount WORD)
			    (HStopHandlerOnCompletion BYTE)
			    (HOnlyDOBFromController BYTE)
			    (HError BYTE)
			    (HDOBError BYTE)
			    (HControllerError BYTE)
			    (HDMAError BYTE)
			    (HComplete BYTE)
			    (HInProgress BYTE)
			    (HDataXferDirection BYTE)
			    (HDMATimedOut BYTE)
			    (HNextIOCB 2 WORD)
			    (DOBBase 33 WORD)))

(BLOCKRECORD PilotDiskLabel ((FileID 2 WORD)
			     (NIL 3 WORD)
			     (FilePageLo WORD)
			     (FilePageHi WORD)
			     (NIL WORD)
			     (BootLinkA WORD)
			     (BootLinkB WORD)))
]
)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS \DoveDisk.IOCBPage)
)
(DECLARE: DONTEVAL@LOAD DOCOPY 
(\DISKDOVEINIT)
)
(PUTPROPS DOVEDISK COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (823 20896 (\DISKDOVEINIT 833 . 1503) (\DOVE.ACTONVMEMFILE 1505 . 1916) (
\DOVE.ACTONVMEMPAGE 1918 . 4288) (\DOVE.XFERDISK 4290 . 6408) (\DoveDisk.CopyByteSwappedLabel 6410 . 
6719) (\DoveDisk.ExecuteIOCB 6721 . 8407) (\DoveDisk.HandleMajorError 8409 . 9644) (\DoveDisk.Init 
9646 . 11258) (\DoveDisk.InitIOCB 11260 . 17582) (\DoveDisk.Initiate 17584 . 20025) (
\DoveDisk.TryRecalibrate 20027 . 20518) (\DoveDisk.WaitForHandlerStopped 20520 . 20894)))))
STOP