(FILECREATED "15-Jan-87 13:39:40" {MCS:MCS:STANFORD}<LANE>ETHERBOOT.LSP;16        

      changes to:  (VARS ETHERBOOTCOMS)

      previous date: "14-Jan-87 09:30:05" {MCS:MCS:STANFORD}<LANE>ETHERBOOT.LSP;15)


(* Copyright (c) 1985, 1986, 1987 by Stanford University. All rights reserved.)

(PRETTYCOMPRINT ETHERBOOTCOMS)

(RPAQQ ETHERBOOTCOMS ((FNS ETHERBOOT SENDSIMPLEDATA SENDSPPDATA CACHE.BOOT.FILES)
			(VARS ETHERBOOTFILES BOOTREQUESTTYPES)
			(ADDVARS (BOOTFILEDIRECTORIES {CORE} {DSK})
				 (BOOTFILECACHETYPES DB GERM))
			(INITVARS (BOOTFILECACHEDIRECTORY '{CORE}))
			(DECLARE: DONTCOPY (RECORDS ETHERBOOTFILE BOOTREQUESTTYPE)
				  (MACROS LOADNSHOSTNUMBER)
				  (CONSTANTS (ETHERBOOTPACKETTYPE 9)
					     (BOOTSERVERSOCKET 10)
					     (SIMPLEREQUEST 1)
					     (SIMPLEDATA 2)
					     (SPPREQUEST 3))
				  (GLOBALVARS BOOTFILEDIRECTORIES ETHERBOOTFILES BOOTREQUESTTYPES 
					      BOOTFILECACHETYPES BOOTFILECACHEDIRECTORY))))
(DEFINEQ

(ETHERBOOT
  [LAMBDA (LOGFILE)                                          (* cdl "14-Jan-87 09:29")
    (DECLARE (SPECVARS . T))
    (LET (XIP NSOCKET BOOTFILE BOOTSTREAM BOOTREQUESTTYPE FILENUMBER ETHERBOOTFILE)
         (DECLARE (SPECVARS . T))
         (RESETLST
	   [RESETSAVE NIL (BQUOTE (DISCARDXIPS , (SETQ NSOCKET (OPENNSOCKET 
										 BOOTSERVERSOCKET
										      'ACCEPT]
	   (do
	     (if LOGFILE
		 then (printout LOGFILE "Listening ..." T))
	     (RESETLST
	       [RESETSAVE NIL (BQUOTE (RELEASE.XIP , (SETQ XIP (GETXIP NSOCKET T]
	       (if (SETQ BOOTREQUESTTYPE (FASSOC (\GETBASE (with XIP XIP XIPCONTENTS)
								   0)
						       BOOTREQUESTTYPES))
		   then (SETQ FILENUMBER
			    (for D to 3 as N from 32 by -16
			       sum (LSH (\GETBASE (with XIP XIP XIPCONTENTS)
							D)
					    N)))
			  (if [SETQ ETHERBOOTFILE (for BOOTFILE in ETHERBOOTFILES
							 thereis (with ETHERBOOTFILE BOOTFILE
									   (EQP BOOTFILENUMBER 
										  FILENUMBER]
			      then (with
				       ETHERBOOTFILE ETHERBOOTFILE
				       (if LOGFILE
					   then (printout LOGFILE (DATE)
							    ,
							    (with BOOTREQUESTTYPE BOOTREQUESTTYPE 
								    REQUESTDESCRIPTION)
							    , "Request for" , BOOTFILEDESCRIPTION , 
							    "from"
							    ,
							    (with XIP XIP XIPSOURCENSADDRESS)
							    T))
				       (if (SETQ BOOTFILE (FINDFILE BOOTFILENAME NIL 
									  BOOTFILEDIRECTORIES))
					   then [RESETLST
						    [RESETSAVE NIL
								 (BQUOTE
								   (CLOSEF? ,
									      (SETQ BOOTSTREAM
										(OPENSTREAM
										  BOOTFILE
										  'INPUT]
						    (if LOGFILE
							then (printout LOGFILE "Opened" ,
									 (FULLNAME BOOTSTREAM)
									 T))
						    (NLSETQ (with XIP XIP
								      (with BOOTREQUESTTYPE 
									      BOOTREQUESTTYPE
									      (APPLY* REQUESTFN 
										       BOOTSTREAM 
										    XIPSOURCEHOST 
										  XIPSOURCESOCKET 
										      XIPCONTENTS 
											NSOCKET 
											LOGFILE]
						  (if LOGFILE
						      then (printout LOGFILE T "Closed" ,
								       (FULLNAME BOOTSTREAM)
								       T))
					 elseif LOGFILE
					   then (printout LOGFILE "Error, File Not Found:" , 
							    BOOTFILENAME T)))
			    elseif LOGFILE
			      then (printout LOGFILE "Error, Unknown File Number:" , FILENUMBER T))
		 elseif LOGFILE
		   then (printout LOGFILE "Error, Unknown Request Type:" ,
				    (\GETBASE (with XIP XIP XIPCONTENTS)
						0)
				    T])

(SENDSIMPLEDATA
  [LAMBDA (BOOTSTREAM DESTHOST DESTSOCKET CONTENTS NSOCKET LOGFILE)
                                                             (* cdl "14-Jan-87 09:21")
    (LET (XIP LENGTH (PACKETCOUNT (GETFILEINFO BOOTSTREAM 'SIZE))
	      (BYTECOUNT (GETFILEINFO BOOTSTREAM 'LENGTH))
	      (COUNTER 0))
         (if LOGFILE
	     then (printout LOGFILE "Packets"))
         (for PACKETNUMBER to (ADD1 PACKETCOUNT)
	    do (if LOGFILE
		     then (printout LOGFILE , PACKETNUMBER))
		 (with XIP (SETQ XIP (CREATE.PACKET.EXCHANGE.XIP NSOCKET DESTHOST DESTSOCKET 
								       ETHERBOOTPACKETTYPE))
			 (SETQ XIPTYPE ETHERBOOTPACKETTYPE))
		 (XIPAPPEND.WORD XIP SIMPLEDATA 0)
		 (for OFFSET to 3 do (XIPAPPEND.WORD XIP (\GETBASE CONTENTS OFFSET)
							     OFFSET))
		 (XIPAPPEND.WORD XIP PACKETNUMBER 4)
		 (to 512 as OFFSET from 10 as old COUNTER by 1
		    do (XIPAPPEND.BYTE XIP (if (LESSP COUNTER BYTECOUNT)
						   then (BIN BOOTSTREAM)
						 else 0)
					   OFFSET))
		 [with XIP XIP (SETQ XIPLENGTH
			   (PLUS (CONSTANT (PLUS 30 10))
				   (if (GREATERP PACKETNUMBER PACKETCOUNT)
				       then 0
				     elseif [AND (EQP PACKETNUMBER PACKETCOUNT)
						     (NOT (ZEROP (SETQ LENGTH (IMOD BYTECOUNT 
											    512]
				       then LENGTH
				     else 512]
		 (SENDXIP NSOCKET XIP)
		 (BLOCK])

(SENDSPPDATA
  [LAMBDA (BOOTSTREAM DESTHOST DESTSOCKET CONTENTS NSOCKET LOGFILE)
                                                             (* cdl "14-Jan-87 09:28")
    (DECLARE (SPECVARS . T))
    (LET (INPUTSTREAM OUTPUTSTREAM)
         (DECLARE (SPECVARS . T))
         (RESETLST [RESETSAVE NIL (BQUOTE (SPP.CLOSE , (SETQ INPUTSTREAM (SPP.OPEN 
											 DESTHOST 
										       DESTSOCKET]
		     (with STREAM (SETQ OUTPUTSTREAM (SPPOUTPUTSTREAM INPUTSTREAM))
			     (REPLACEFIELD '(SPPCON 16 (BITS . 15))
					     F1
					     (\GETBASE CONTENTS 4)))
		     (if LOGFILE
			 then (printout LOGFILE "Packets"))
		     (bind (DECADE ← 0) for I to (SUB1 (GETFILEINFO BOOTSTREAM
									      'SIZE))
			as COUNTER from 0
			do (COPYBYTES BOOTSTREAM OUTPUTSTREAM 512)
			     (SPP.SENDEOM OUTPUTSTREAM)
			     (if (EQ COUNTER 10)
				 then (SETQ COUNTER 0)
					(ADD1VAR DECADE)
					(if LOGFILE
					    then (printout LOGFILE , DECADE "0")))
			finally (COPYBYTES BOOTSTREAM OUTPUTSTREAM)))
         (if LOGFILE
	     then (printout LOGFILE T "SPP Stream closed"])

(CACHE.BOOT.FILES
  [LAMBDA (TYPES)                                            (* cdl "24-Sep-86 15:31")
    (bind FILE TOFILE for ETHERBOOTFILE in ETHERBOOTFILES
       do (with ETHERBOOTFILE ETHERBOOTFILE (if (AND (EQMEMB (U-CASE (FILENAMEFIELD
										   BOOTFILENAME
										   'EXTENSION))
								       (OR TYPES BOOTFILECACHETYPES)
								       )
							     [NOT (INFILEP (SETQ TOFILE
										 (PACKFILENAME
										   'NAME
										   BOOTFILENAME
										   'DIRECTORY
										   
									   BOOTFILECACHEDIRECTORY]
							     (SETQ FILE (FINDFILE BOOTFILENAME 
										      NIL 
									      BOOTFILEDIRECTORIES)))
						    then (COPYFILE FILE TOFILE)
							   (PRINTOUT T FILE T])
)

(RPAQQ ETHERBOOTFILES (("Standard DLion Ethernet Initial Microcode" EtherInitial.db 2852126720)
			 ("Standard DLion Diagnostic Microcode" MoonBoot.db 2852126728)
			 ("Standard DLion Mesa Microcode" Mesa.db 2852126736)
			 ("Standard DLion Germ" DLion.germ 2852126744)
			 ("Standard DLion Boot File" SimpleNetExecDLion.boot 2852126752)
			 ("Standard DLion Diagnostics Boot File" EIDiskDLion.boot 2852127232)
			 ("Standard DLion Installer Boot File" InstallerNSDLion.boot 2852127234)
			 ("Alternate DLion Ethernet Initial Microcode" EtherInitialAlt.db 2852126721)
			 ("Alternate DLion Mesa Microcode" Mesa.db 2852126738)
			 ("Alternate DLion Germ" DLion.germ 2852126746)
			 ("Alternate DLion Boot File" InstallerNSDLion.boot 2852126754)
			 ("Standard TriDLion Diagnostic Microcode" Moonboot.db 2852126729)
			 ("Standard TriDLion Mesa Microcode" TridentRavenMesa.db 2852126737)
			 ("Standard TriDLion Germ" TriDlion.germ 2852126745)
			 ("Standard TriDLion Boot File" SimpleNetExecTriDlion.boot 2852126753)
			 ("Alternate TriDLion Mesa Microcode" TridentRavenMesa.db 2852126739)
			 ("Alternate TriDLion Germ" TriDlion.germ 2852126747)
			 ("Alternate TriDLion Boot File" InstallerNSTriDlion.boot 2852126753)
			 ("Standard Dove Ethernet Initial Microcode" EtherInitialDove.db 2852128768)
			 ("Standard Dove Diagnostic Microcode" MoonRise.db 2852128776)
			 ("Standard Dove Mesa Microcode" MesaDove.db 2852128784)
			 ("Standard Dove Germ" Dove.germ 2852128792)
			 ("Standard Dove Boot File" SimpleNetExecDove.boot 2852128800)
			 ("Alternate Dove Ethernet Initial Microcode" EtherInitialDove.db 2852128769)
			 ("Alternate Dove Diagnostic Microcode" MoonRise.db 2852128777)
			 ("Alternate Dove Mesa Microcode" MesaDove.db 2852128785)
			 ("Alternate Dove Germ" Dove.germ 2852128793)
			 ("Alternate Dove Boot File" LispInstallerDove.boot 2852128801)
			 ("Dove Simple Net Exec" SimpleNetExecDove.boot 2852128824)
			 ("Dove Configuration Utility" SysConfigOfflineDove.boot 2852128825)
			 ("Dove Installer" LispInstallerDove.boot 2852128826)
			 ("Dove Diagnostics Utility" DiagDiskUtilDove.boot 2852128828)
			 ("Dove Rigid Disk Diagnostics Utility" DiagRDDove.boot 2852128829)
			 ("Dove Ethernet Diagnostics Utility" DiagEtherDove.boot 2852128830)
			 ("Dove Keyboard & Display Diagnostics Utility" KDMDove.boot 2852128831)))

(RPAQQ BOOTREQUESTTYPES ((1 Simple SENDSIMPLEDATA)
			   (3 SPP SENDSPPDATA)))

(ADDTOVAR BOOTFILEDIRECTORIES {CORE} {DSK})

(ADDTOVAR BOOTFILECACHETYPES DB GERM)

(RPAQ? BOOTFILECACHEDIRECTORY '{CORE})
(DECLARE: DONTCOPY 
[DECLARE: EVAL@COMPILE 

(RECORD ETHERBOOTFILE (BOOTFILEDESCRIPTION BOOTFILENAME BOOTFILENUMBER))

(RECORD BOOTREQUESTTYPE (REQUESTTYPE REQUESTDESCRIPTION REQUESTFN))
]

(DECLARE: EVAL@COMPILE 
(PUTPROPS LOADNSHOSTNUMBER MACRO (= . \LOADNSHOSTNUMBER))
)

(DECLARE: EVAL@COMPILE 

(RPAQQ ETHERBOOTPACKETTYPE 9)

(RPAQQ BOOTSERVERSOCKET 10)

(RPAQQ SIMPLEREQUEST 1)

(RPAQQ SIMPLEDATA 2)

(RPAQQ SPPREQUEST 3)

(CONSTANTS (ETHERBOOTPACKETTYPE 9)
	   (BOOTSERVERSOCKET 10)
	   (SIMPLEREQUEST 1)
	   (SIMPLEDATA 2)
	   (SPPREQUEST 3))
)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS BOOTFILEDIRECTORIES ETHERBOOTFILES BOOTREQUESTTYPES BOOTFILECACHETYPES 
	    BOOTFILECACHEDIRECTORY)
)
)
(PUTPROPS ETHERBOOT.LSP COPYRIGHT ("Stanford University" 1985 1986 1987))
STOP