<> <> <> <> <> DIRECTORY Basics USING [LongDiv, LongMult], BootFile USING [Location], BootChannel USING [Create, Operation, Handle, transferCleanup, transferWait], GermPrivate USING [ AllocateMDS, Error ], MiniEthernetDefs USING [ActivateDriver, SendPacket, RecvPacket, KillDriver], MPCodes USING [germDeviceError, germFunnyPacket, germNoServer, germTimeout, Code], PrincOps USING [bytesPerPage, PageCount, wordsPerPage], PrincOpsUtils USING [AddressForPageNumber], ProcessorFace USING [GetClockPulses, microsecondsPerHundredPulses], PupTypes USING [PupAddress, PupSocketID, PupType, Pair, miscSrvSoc]; BootChannelEther: PROGRAM IMPORTS RemainingChannels: BootChannel, Basics, GermPrivate, MiniEthernetDefs, PrincOpsUtils, ProcessorFace EXPORTS BootChannel = { <<>> <> <> CantActivateDriver: MPCodes.Code = MPCodes.germDeviceError; NoBootServerResponded: MPCodes.Code = MPCodes.germNoServer; NextPacketDidntArrive: MPCodes.Code = MPCodes.germTimeout; FunnySizePacket: MPCodes.Code = MPCodes.germFunnyPacket; FunnySequenceNumber: MPCodes.Code = MPCodes.germFunnyPacket; DeviceError: MPCodes.Code = MPCodes.germDeviceError; pAllocateNext: LONG POINTER; -- allocator for items in first 64K. bfn: CARDINAL; -- boot file number. iocb: LONG POINTER; bufferLength: CARDINAL = 300; fudge: CARDINAL = 25; -- must be bigger than encapsulation and pup overhead totalBufferLength: CARDINAL = bufferLength + fudge; buffer: LONG POINTER TO ARRAY (0..totalBufferLength] OF WORD; countTotalBuffer: PrincOps.PageCount = (totalBufferLength + PrincOps.wordsPerPage - 1) / PrincOps.wordsPerPage; mySocket: PupTypes.PupSocketID = LOOPHOLE[ProcessorFace.GetClockPulses[]]; him: PupTypes.PupAddress; anyBootServer: PupTypes.PupAddress = [[0], [0], PupTypes.miscSrvSoc]; pulsesPerSecond: CARDINAL = Basics.LongDiv[100*1000000, ProcessorFace.microsecondsPerHundredPulses]; recvStarted: BOOL; receiveSeqNumber: CARDINAL; Create: PUBLIC PROC [pLocation: POINTER TO BootFile.Location, operation: BootChannel.Operation, dFirst64KStorage: LONG DESCRIPTOR FOR ARRAY OF WORD] RETURNS [handle: BootChannel.Handle] = { pAllocateNext _ BASE[dFirst64KStorage]; -- reset first 64K allocator IF pLocation.deviceType = ethernet THEN { bfn _ pLocation.bootFileNumber; SELECT operation FROM read => NULL; ENDCASE => GermPrivate.Error[DeviceError]; StartRecving[bfn]; handle _ EFTPGetClump; } ELSE -- not anything I implement. Pass it on. handle _ RemainingChannels.Create[pLocation, operation, dFirst64KStorage]; }; StartRecving: PROC [bfn: CARDINAL] = { bytes: INTEGER; id: PupTypes.Pair; type: PupTypes.PupType; timeout: LONG CARDINAL; Timer: PROC RETURNS [BOOL] = {RETURN [TimeoutHasExpired[timeout]]}; iocb _ Allocate[ --SIZE[MiniEthernetDefs.iocb]--16]; buffer _ LONG[GermPrivate.AllocateMDS[countTotalBuffer]]; IF ~MiniEthernetDefs.ActivateDriver[buffer, bufferLength, iocb, TRUE] THEN GermPrivate.Error[CantActivateDriver]; him _ [[0], [0], [0, 0]]; recvStarted _ FALSE; receiveSeqNumber _ 0; THROUGH [0..15) DO MiniEthernetDefs.SendPacket[ anyBootServer, mySocket, bootFileSend, [0, bfn], NIL, 0]; timeout _ SetTimeout[2]; -- will try 15 times at 2-second intervals <> [bytes, id, type] _ MiniEthernetDefs.RecvPacket[ @him, mySocket, buffer + fudge, bufferLength, Timer]; IF bytes < 0 THEN LOOP; IF type # eData THEN LOOP; IF bytes # PrincOps.bytesPerPage THEN GermPrivate.Error[FunnySizePacket]; <> SendAck[]; RETURN; REPEAT FINISHED => GermPrivate.Error[NoBootServerResponded]; ENDLOOP; }; EFTPGetClump: BootChannel.Handle = { <> where: LONG POINTER _ PrincOpsUtils.AddressForPageNumber[page]; bytes: INTEGER; id: PupTypes.Pair; type: PupTypes.PupType; timeout: LONG CARDINAL; Timer: PROC RETURNS [BOOL] = {RETURN [TimeoutHasExpired[timeout]]}; IF count = BootChannel.transferWait THEN RETURN; <> IF count = BootChannel.transferCleanup THEN { StopRecving[bfn]; RETURN }; -- transfers done. Shutdown the booter. THROUGH [0..count) DO DO <> timeout _ SetTimeout[30]; -- time out in 30 seconds [bytes, id, type] _ MiniEthernetDefs.RecvPacket[ @him, mySocket, where, PrincOps.wordsPerPage, Timer]; IF bytes < 0 THEN GermPrivate.Error[NextPacketDidntArrive]; IF type # eData THEN LOOP; IF bytes # PrincOps.bytesPerPage THEN GermPrivate.Error[FunnySizePacket]; SELECT id.b FROM receiveSeqNumber + 1 => EXIT; receiveSeqNumber => { -- Booter lost our ack SendAck[]; LOOP; }; ENDCASE => GermPrivate.Error[FunnySequenceNumber]; ENDLOOP; where _ where + PrincOps.wordsPerPage; receiveSeqNumber _ receiveSeqNumber + 1; SendAck[]; ENDLOOP; }; StopRecving: PROC [bfn: CARDINAL] = { bytes: INTEGER; id: PupTypes.Pair; type: PupTypes.PupType; timeout: LONG CARDINAL; Timer: PROC RETURNS [BOOL] = {RETURN [TimeoutHasExpired[timeout]]}; DO timeout _ SetTimeout[30]; -- time out in 30 seconds <> [bytes, id, type] _ MiniEthernetDefs.RecvPacket[ @him, mySocket, buffer + fudge, bufferLength, Timer]; IF bytes < 0 THEN GermPrivate.Error[NextPacketDidntArrive]; SELECT TRUE FROM (type = eData AND id.b = receiveSeqNumber) => { <> SendAck[]; LOOP; }; (type = eData AND id.b = receiveSeqNumber + 1) => { <> receiveSeqNumber _ receiveSeqNumber + 1; SendAck[]; LOOP; }; (type = eEnd AND id.b = receiveSeqNumber + 1) => { receiveSeqNumber _ receiveSeqNumber + 1; SendAck[]; EXIT; }; ENDCASE => GermPrivate.Error[FunnySequenceNumber]; ENDLOOP; MiniEthernetDefs.KillDriver[]; <> <> }; SendAck: PROC = { MiniEthernetDefs.SendPacket[ him, mySocket, eAck, [0, receiveSeqNumber], NIL, 0]; }; SetTimeout: PROC [timeout: CARDINAL --seconds--] RETURNS [timer: LONG CARDINAL] = { RETURN [ProcessorFace.GetClockPulses[] + Basics.LongMult[timeout, pulsesPerSecond]]; }; TimeoutHasExpired: PROC [timer: LONG CARDINAL] RETURNS [BOOL] = { RETURN [LOOPHOLE[ProcessorFace.GetClockPulses[]-timer, INT] >= 0]; }; <> Allocate: PROC [size: CARDINAL] RETURNS [lp: LONG POINTER] = { pAllocateNext _ (lp _ pAllocateNext) + LONG[((size + 15)/16)*16]; }; }. LOG Time: February 7, 1980 2:28 PM By: Knutsen and Murray Action: Create file from BootChannelDisk of February 6, 1980 2:43 PM Buffer unscrambling: February 8, 1980 12:12 AM Discard Tail: February 8, 1980 1:08 AM Time: February 8, 1980 12:12 AM By: Knutsen and Murray Action: Buffer unscrambling Time: February 8, 1980 1:08 AM By: Knutsen and Murray Action: Discard trailing garbage on end of boot file (bcd for the loader?) Time: February 8, 1980 10:21 PM By: Forrest Action: Put MP hack to show page 0 Time: February 9, 1980 11:11 AM By: Knutsen Action: Loop when page 0 seen second time Time: February 9, 1980 1:34 PM By: Knutsen Action: Fudge in extra space before buffer Time: February 9, 1980 2:39 PM By: Knutsen Action: display packet seq number in cursor Time: February 9, 1980 1:34 PM By: Knutsen/HGM Action: Undo fudge Time: February 14, 1980 5:23 PM By: McJones Action: New Boot.Location, faces, etc. Time: April 17, 1980 10:14 PM By: Luniewski Action: AllocateMDSPages -> AllocateMDS Time: April 22, 1980 5:37 PM By: McJones Action: Add avoidCleanup: TRUE to ActivateDriver call Time: June 23, 1980 2:37 PM By: McJones Action: OISProcessorFace=>ProcessorFace February 25, 1983 3:51 pm Taft Use real-time clock for timeout, not spin loop! Time: October 31, 1983 3:20 pm By: Birrell Action: Conversion to 5.0