(DEFINE-FILE-INFO READTABLE "INTERLISP" PACKAGE "INTERLISP" BASE 10)
(FILECREATED " 1-Sep-87 15:24:35" |{MCS:MCS:STANFORD}<LANE>ETHERBOOT.;9| 16549  

      changes to%:  (VARS ETHERBOOTCOMS ETHERBOOTFILES)
                    (FNS ETHERBOOT SENDSIMPLEDATA SENDSPPDATA)
                    (RECORDS ETHERBOOTPACKET)

      previous date%: "31-Aug-87 15:29:47" |{MCS:MCS:STANFORD}<LANE>ETHERBOOT.;1|)


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

(PRETTYCOMPRINT ETHERBOOTCOMS)

(RPAQQ ETHERBOOTCOMS ((* Lisp-based Ethernet Boot server, requires ETHERRECORDS and EXPORTS.ALL to 
                         compile)
                      (FNS ETHERBOOT SENDSIMPLEDATA SENDSPPDATA CACHE.BOOT.FILES)
                      (VARS ETHERBOOTFILES BOOTREQUESTTYPES)
                      (ADDVARS (BOOTFILEDIRECTORIES {CORE} {DSK})
                             (BOOTFILECACHETYPES DB GERM))
                      (INITVARS (BOOTFILECACHEDIRECTORY '{CORE}))
                      (DECLARE%: DONTCOPY (RECORDS ETHERBOOTPACKET ETHERBOOTFILE BOOTREQUESTTYPE)
                             (MACROS LOADNSHOSTNUMBER)
                             (CONSTANTS (ETHERBOOTPACKETTYPE 9)
                                    (BOOTSERVERSOCKET 10)
                                    (SIMPLEREQUEST 1)
                                    (SIMPLEDATA 2)
                                    (SPPREQUEST 3))
                             (GLOBALVARS BOOTFILEDIRECTORIES ETHERBOOTFILES BOOTREQUESTTYPES 
                                    BOOTFILECACHETYPES BOOTFILECACHEDIRECTORY))))



(* Lisp-based Ethernet Boot server, requires ETHERRECORDS and EXPORTS.ALL to compile)

(DEFINEQ

(ETHERBOOT
  [LAMBDA (LOGFILE)                                          (* ; "Edited  1-Sep-87 13:09 by cdl")

    (DECLARE (SPECVARS . T))
    (LET
     (XIP NSOCKET BOOTFILE BOOTSTREAM BOOTREQUESTTYPE FILENUMBER ETHERBOOTFILE)
     (DECLARE (SPECVARS . T))
     (RESETLST
      [RESETSAVE NIL `(CLOSENSOCKET ,(SETQ NSOCKET (OPENNSOCKET BOOTSERVERSOCKET 'ACCEPT]
      (do
       (DISCARDXIPS NSOCKET)
       (if LOGFILE
           then (printout LOGFILE "Listening ..." T))
       (RESETLST
        [RESETSAVE NIL `(RELEASE.XIP %, (SETQ XIP (GETXIP NSOCKET T]
        (if (SETQ BOOTREQUESTTYPE (FASSOC (with ETHERBOOTPACKET XIP ETHERBOOTREQUESTTYPE)
                                         BOOTREQUESTTYPES))
            then (SETQ FILENUMBER (with ETHERBOOTPACKET XIP ETHERBOOTFILENUMBER))
                 (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 `(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 XIP 
                                                                           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:" %, (with ETHERBOOTPACKET XIP 
                                                                           ETHERBOOTREQUESTTYPE)
                        T])

(SENDSIMPLEDATA
  [LAMBDA (BOOTSTREAM DESTHOST DESTSOCKET PACKET LOGFILE)    (* ; "Edited  1-Sep-87 12:40 by cdl")

    (LET (NSOCKET)
         (DECLARE (SPECVARS NSOCKET))
         (if LOGFILE
             then (printout LOGFILE "Packets"))
         (RESETLST
          [RESETSAVE NIL `(CLOSENSOCKET ,(SETQ NSOCKET (OPENNSOCKET]
          (LET (XIP LENGTH (PACKETCOUNT (GETFILEINFO BOOTSTREAM 'SIZE))
                    (BYTECOUNT (GETFILEINFO BOOTSTREAM 'LENGTH))
                    (COUNTER 0))
               (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)
                     (with ETHERBOOTPACKET PACKET (XIPAPPEND.WORD XIP ETHERBOOTBFNHI 1)
                           (XIPAPPEND.WORD XIP ETHERBOOTBFNMID 2)
                           (XIPAPPEND.WORD XIP ETHERBOOTBFNLOW 3))
                     (XIPAPPEND.WORD XIP PACKETNUMBER 4)
                     (to BYTESPERPAGE 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 \XIPOVLEN 10))
                                          (if (GREATERP PACKETNUMBER PACKETCOUNT)
                                              then 0
                                            elseif [AND (EQP PACKETNUMBER PACKETCOUNT)
                                                        (NOT (ZEROP (SETQ LENGTH (IMOD BYTECOUNT 
                                                                                       BYTESPERPAGE]
                                              then LENGTH
                                            else BYTESPERPAGE]
                     (SENDXIP NSOCKET XIP)
                     (BLOCK])

(SENDSPPDATA
  [LAMBDA (BOOTSTREAM DESTHOST DESTSOCKET PACKET LOGFILE)    (* ; "Edited  1-Sep-87 12:32 by cdl")

    (DECLARE (SPECVARS . T))
    (LET (INPUTSTREAM OUTPUTSTREAM)
         (DECLARE (SPECVARS . T))
         (RESETLST [RESETSAVE NIL `(SPP.CLOSE ,(SETQ INPUTSTREAM (SPP.OPEN DESTHOST DESTSOCKET NIL 
                                                                        NIL '(EOM.ON.FORCEOUTPUT
                                                                              T]
                (with SPPSTREAM (SETQ OUTPUTSTREAM (SPPOUTPUTSTREAM INPUTSTREAM))
                      (with SPPCON SPP.CONNECTION            (* Switch to negotiated connection id)
                            (SETQ SPPDESTID (with ETHERBOOTPACKET PACKET ETHERBOOTSPPDESTID)))
                                                             (* Send SYS packet to establish
                                                             (Dove fix))
                      (\SPP.SENDPKT SPP.CONNECTION (\SPP.SYSPKT SPP.CONNECTION 0)))
                (if LOGFILE
                    then (printout LOGFILE "Packets"))
                (bind (DECADE ← 0) for I to (SUB1 (GETFILEINFO BOOTSTREAM 'SIZE)) as COUNTER
                   from 0 do (COPYBYTES BOOTSTREAM OUTPUTSTREAM BYTESPERPAGE)
                             (FORCEOUTPUT 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" InstallerNSDove.boot 2852128801)
                       ("Dove Simple Net Exec" SimpleNetExecDove.boot 2852128824)
                       ("Dove Configuration Utility" SysConfigOfflineDove.boot 2852128825)
                       ("Dove Installer" InstallerNSDove.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

(ACCESSFNS ETHERBOOTPACKET [(ETHERBOOTBASE (with XIP DATUM XIPCONTENTS))
                            (ETHERBOOTFILENUMBER (with ETHERBOOTPACKET DATUM (PLUS (LSH 
                                                                                       ETHERBOOTBFNHI 
                                                                                        32)
                                                                                   (LSH 
                                                                                      ETHERBOOTBFNMID 
                                                                                        16)
                                                                                   ETHERBOOTBFNLOW]
                           (BLOCKRECORD ETHERBOOTBASE ((ETHERBOOTREQUESTTYPE WORD)
                                                       (ETHERBOOTBFNHI WORD)
                                                       (ETHERBOOTBFNMID WORD)
                                                       (ETHERBOOTBFNLOW WORD)
                                                       (ETHERBOOTSPPDESTID WORD))))

(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 COPYRIGHT ("Stanford University" 1985 1986 1987))
(DECLARE%: DONTCOPY
  (FILEMAP (NIL (1703 11321 (ETHERBOOT 1713 . 5761) (SENDSIMPLEDATA 5763 . 8161) (SENDSPPDATA 8163 . 
10030) (CACHE.BOOT.FILES 10032 . 11319)))))
STOP