--ILTBootImpl.mesa --Created by -- JFung.PASA 19-Dec-83 11:35:03 --last edited by -- JFung.PASA 19-Dec-83 13:55:39 DIRECTORY CmFile, Display, Environment, Event, Exec, File, FileTypes, FileTransfer, FormSW, Heap, Inline, LispToolOps, OthelloOps, Process, Put, Runtime, Space, String, TemporaryBooting, Time, Token, Tool, ToolDriver, ToolWindow, UserInput, Version, Volume, Window; ILTBootImpl: PROGRAM IMPORTS Display, File, FormSW, Heap, Inline, LispToolOps, OthelloOps, Process, Put, Runtime, Space, String, TemporaryBooting, Time, Tool, ToolDriver, UserInput, Version, Volume, Window EXPORTS LispToolOps = BEGIN OPEN ILT: LispToolOps, OthelloOps; -- TYPEs Indicator: TYPE = {off, left, right}; VolHints: TYPE = RECORD [names: SEQUENCE length: CARDINAL OF LONG STRING]; SizeHints: TYPE = RECORD [names: SEQUENCE length: CARDINAL OF CARDINAL]; DataHandle: TYPE = LONG POINTER TO Data; Data: TYPE = MACHINE DEPENDENT RECORD [ -- Message subwindow stuff msgSW(0): Window.Handle _ NIL, -- File subwindow stuff fileSW(2): Window.Handle _ NIL, -- Form subwindow stuff -- Note: enumerateds and booleans must be word boundary -- aligned as addresses for them must be generated --formSW: Window.Handle _ NIL, paramSW(4): Window.Handle _ NIL, commandSW(6): Window.Handle _ NIL, busy(8): BOOLEAN _ FALSE, -- command is running destVolName(9): LONG STRING _ NIL, srcVolName(11): LONG STRING _ NIL, connection(13): FileTransfer.Connection _ NIL, indicator(15): Indicator _ left]; active: BOOLEAN _ FALSE; copyWH: Window.Handle _ NIL; debug: BOOLEAN _ FALSE; toolData: DataHandle _ NIL; formDisplay: ToolWindow.DisplayProcType _ NIL; indicatorBox: Window.Box = [[10, 10], [16, 16]]; volume: Volume.ID _ Volume.nullID; BootStuff: PUBLIC PROCEDURE = BEGIN IF toolData = NIL THEN toolData _ Heap.systemZone.NEW[Data _ []]; IF debug THEN { Put.Line[ILT.toolData.fileSW, "MakeTool...."L]; Process.Pause[Process.SecondsToTicks[5]]; }; IF ILT.Confirm[] THEN copyWH _ MakeTool[]; END; --BootStuff ClearCommandSubwindow: PROCEDURE = BEGIN item: FormSW.ItemHandle; FOR i: CARDINAL _ 0, i + 1 UNTIL (item _ FormSW.FindItem[toolData.commandSW, i]) = NIL DO item.flags.invisible _ TRUE ENDLOOP; FormSW.Display[toolData.commandSW]; toolData.indicator _ left; formDisplay _ Window.GetDisplayProc[toolData.commandSW]; [] _ Window.SetDisplayProc[toolData.commandSW, DisplayEmpty]; END; --ClearCommandSubwindow ClearFileSubwindow: PROCEDURE = BEGIN item: FormSW.ItemHandle; FOR i: CARDINAL _ 0, i + 1 UNTIL (item _ FormSW.FindItem[toolData.fileSW, i]) = NIL DO item.flags.invisible _ TRUE ENDLOOP; FormSW.Display[toolData.fileSW]; --formDisplay _ Window.GetDisplayProc[toolData.fileSW]; END; --ClearFileSubwindow ClearMsgSubwindow: PROCEDURE = BEGIN item: FormSW.ItemHandle; FOR i: CARDINAL _ 0, i + 1 UNTIL (item _ FormSW.FindItem[toolData.msgSW, i]) = NIL DO item.flags.invisible _ TRUE ENDLOOP; FormSW.Display[toolData.msgSW]; --formDisplay _ Window.GetDisplayProc[toolData.msgSW]; END; --ClearMsgSubwindow ClearSubWindows: PROCEDURE = BEGIN --ClearFileSubwindow; ClearMsgSubwindow; END; --ClearSubWindows CloseVolume: PUBLIC PROC [vID: Volume.ID] RETURNS [vOpen: BOOLEAN] = BEGIN IF vOpen THEN {Volume.Close[vID]; vOpen _ FALSE; } END; << ClientTransition: ToolWindow.TransitionProcType = -- This procedure is called whenever the system determines that this -- Tool's state is undergoing a user invoked transition. -- In this Example we demonstrate a technique that minimizes the memory -- requirements for a Tool that is inactive. BEGIN SELECT TRUE FROM old = inactive => BEGIN IF toolData = NIL THEN toolData _ Heap.systemZone.NEW[Data _ []]; active _ TRUE; END; new = inactive => BEGIN IF toolData # NIL THEN BEGIN FormSW.Destroy[toolData.paramSW]; FormSW.Destroy[toolData.commandSW]; Heap.systemZone.FREE[@toolData]; END; --ToolDriver.RemoveSWs[tool: "LispTool"L]; active _ FALSE; END; ENDCASE END; --ClientTransition >> DisplayCommandSubwindow: PROCEDURE = BEGIN item: FormSW.ItemHandle; toolData.indicator _ off; [] _ Window.SetDisplayProc[toolData.commandSW, formDisplay]; FormSW.Display[toolData.commandSW]; FOR i: CARDINAL _ 0, i + 1 UNTIL (item _ FormSW.FindItem[toolData.commandSW, i]) = NIL DO item.flags.invisible _ FALSE ENDLOOP; FormSW.Display[toolData.commandSW]; END; --DisplayCommandSubwindow DisplayEmpty: ToolWindow.DisplayProcType = BEGIN ENABLE UNWIND => NULL; IF ~toolData.busy THEN RETURN; DisplayIndicator[window]; END; DisplayIndicator: ToolWindow.DisplayProcType = { pattern: ARRAY [0..1] OF ARRAY [0..8) OF WORD; SELECT toolData.indicator FROM left => { pattern _ [ [ 111000B, 052000B, 034000B, 177000B, 034000B, 052000B, 111000B, 000000B], [ 000222B, 000124B, 000070B, 000376B, 000070B, 000124B, 000222B, 000000B]]; Display.Bitmap[ window, indicatorBox, [@pattern, , 0], 16, Display.replaceFlags]}; right => { pattern _ [ [ 000222B, 000124B, 000070B, 000376B, 000070B, 000124B, 000222B, 000000B], [ 111000B, 052000B, 034000B, 177000B, 034000B, 052000B, 111000B, 000000B]]; Display.Bitmap[ window, indicatorBox, [@pattern, , 0], 16, Display.replaceFlags]}; ENDCASE}; --DisplayIndicator DoInstall: UserInput.PeriodicProcType = BEGIN ClearMsgSubwindow; IF debug THEN { Put.Line[toolData.fileSW, "Start Install ....."L]; Process.Pause[Process.SecondsToTicks[5]]; }; ClearCommandSubwindow; DisplayIndicator[toolData.commandSW]; toolData.busy _ TRUE; IF Retrieve[] THEN BEGIN Put.Line[toolData.fileSW, "\n Boot destination volume?"L]; IF ILT.Confirm[] THEN TemporaryBooting.BootButton[]; END; DisplayCommandSubwindow; toolData.busy _ FALSE; END; --DoInstall FormSWBoot: FormSW.ProcType = BEGIN IF debug THEN { Put.Line[toolData.fileSW, "FormSWCopyProc...."L]; Process.Pause[Process.SecondsToTicks[5]]; }; [] _ UserInput.CreatePeriodicNotify[ proc: DoInstall, window: sw, rate: 0]; END; --FormSWBoot FormSWQuit: FormSW.ProcType = BEGIN IF toolData # NIL THEN BEGIN Tool.Destroy[copyWH]; Heap.systemZone.FREE[@toolData]; END; END; --FormSWQuit FormSWVolHintsProc: FormSW.MenuProcType = BEGIN RETURN[ hints: DESCRIPTOR[ @ILT.toolData.volHints[0], ILT.toolData.volHints.length], freeHintsProc: HintsNoLongerBusy, replace: TRUE]; END; HintsNoLongerBusy: FormSW.FreeHintsProcType = BEGIN END; InvertIndicator: PROC [] = BEGIN ENABLE UNWIND => NULL; pattern: ARRAY [0..1] OF ARRAY [0..8) OF WORD; IF ~toolData.busy THEN RETURN; SELECT toolData.indicator FROM left => { pattern _ [ [ 000222B, 000124B, 000070B, 000376B, 000070B, 000124B, 000222B, 000000B], [ 111000B, 052000B, 034000B, 177000B, 034000B, 052000B, 111000B, 000000B]]; Display.Bitmap[ toolData.commandSW, indicatorBox, [@pattern, , 0], 16, Display.replaceFlags]; toolData.indicator _ right}; right => { pattern _ [ [ 111000B, 052000B, 034000B, 177000B, 034000B, 052000B, 111000B, 000000B], [ 000222B, 000124B, 000070B, 000376B, 000070B, 000124B, 000222B, 000000B]]; Display.Bitmap[ toolData.commandSW, indicatorBox, [@pattern, , 0], 16, Display.replaceFlags]; toolData.indicator _ left}; off => toolData.indicator _ left; ENDCASE; END; MakeCommands: FormSW.ClientItemsProcType = BEGIN OPEN FormSW; tabs: ARRAY [0..2) OF CARDINAL _ [0, 60]; nItems: CARDINAL = 2; items _ AllocateItemDescriptor[nItems]; items[0] _ CommandItem[tag: "Start"L, place: newLine, proc: FormSWBoot]; items[1] _ CommandItem[tag: "Quit"L, place: newLine, proc: FormSWQuit]; SetTagPlaces[items, DESCRIPTOR[tabs], FALSE]; RETURN[items, TRUE]; END; --MakeCommands MakeParams: FormSW.ClientItemsProcType = BEGIN OPEN FormSW; i, nVols: CARDINAL; tabs: ARRAY [0..4) OF CARDINAL _ [0, 30, 60, 75]; nItems: CARDINAL = 2; items _ AllocateItemDescriptor[nItems]; nVols _ ILT.ListLogicalVolumes[]; String.Copy[toolData.destVolName, ILT.toolData.volHints[0]]; FOR i IN [0..nVols) DO IF String.Equivalent[ILT.toolData.volHints[i], "Lisp"L] THEN BEGIN String.Replace[ @toolData.destVolName, ILT.toolData.volHints[i], Heap.systemZone]; EXIT; END; ENDLOOP; String.Copy[toolData.srcVolName, ILT.toolData.volHints[0]]; FOR i IN [0..nVols) DO IF String.Equivalent[ILT.toolData.volHints[i], "Lisp"L] THEN BEGIN String.Replace[ @toolData.srcVolName, ILT.toolData.volHints[i], Heap.systemZone]; EXIT; END; ENDLOOP; items[0] _ StringItem[ tag: "Source Volume"L, place: newLine, string: @toolData.srcVolName, inHeap: TRUE, menuProc: FormSWVolHintsProc]; items[1] _ StringItem[ tag: "Dest. Volume"L, string: @toolData.destVolName, inHeap: TRUE, menuProc: FormSWVolHintsProc]; SetTagPlaces[items, DESCRIPTOR[tabs], FALSE]; RETURN[items, TRUE] END; --MakeParams MakeSWs: Tool.MakeSWsProc = BEGIN addresses: ARRAY [0..4) OF ToolDriver.Address; logName: STRING _ [20]; Tool.UnusedLogName[unused: logName, root: "CopyOption.log"L]; toolData.msgSW _ Tool.MakeMsgSW[window: window, lines: 1]; toolData.paramSW _ Tool.MakeFormSW[window: window, formProc: MakeParams]; toolData.commandSW _ Tool.MakeFormSW[ window: window, formProc: MakeCommands]; --note: logName is compulsory, else it bombs toolData.fileSW _ Tool.MakeFileSW[window: window, name: logName]; --Supervisor.AddDependency[client: agent, implementor: Event.toolWindow]; -- do the ToolDriver stuff addresses _ [ [name: "msgSW"L, sw: toolData.msgSW], --[name: "formSW"L, sw: toolData.formSW], [name: "ParamSW"L, sw: toolData.paramSW], [ name: "CmdSW"L, sw: toolData.commandSW], [ name: "fileSW"L, sw: toolData.fileSW]]; ToolDriver.NoteSWs[ tool: "Boot Options"L, subwindows: DESCRIPTOR[addresses]]; END; --MakeSWs MakeTool: PROCEDURE RETURNS [wh: Window.Handle] = BEGIN heraldName: STRING _ [80]; String.AppendString[heraldName, "XSIS:Xerox Remote Boot Option"L]; String.AppendString[heraldName, " of "L]; Time.Append[heraldName, Time.Unpack[Runtime.GetBcdTime[]]]; heraldName.length _ heraldName.length - 3; String.AppendString[heraldName, " on Pilot Version "L]; Version.Append[heraldName]; RETURN[ Tool.Create[ makeSWsProc: MakeSWs, initialState: default, --clientTransition: ClientTransition, name: heraldName]]; --initialBox: [ --place: sw.BitmapPlace[[10, hisBox.dims.h]], --dims: [hisBox.dims.w - 20, 180]]]; END; --MakeTool Retrieve: PROC[] RETURNS [BOOLEAN] = BEGIN OPEN OthelloOps; base: LONG POINTER _ NIL; bufferPages: Space.PageCount = 100; created: BOOLEAN _ FALSE; destCap: File.Capability; destVolumeID: Volume.ID _ Volume.nullID; destVolumeOpen: BOOLEAN _ FALSE; firstPage: File.PageNumber; freePages: Volume.PageCount; pageCount: INTEGER _ 0; space: Space.Handle _ Space.nullHandle; srcCap: File.Capability; srcVolumeID: Volume.ID _ Volume.nullID; srcVolumeOpen: BOOLEAN _ FALSE; uCodeSize: File.PageCount _ 0; volSize: Volume.PageCount _ 0; Cleanup: PROC = BEGIN IF debug THEN { Put.Line[toolData.fileSW, "Enter Cleanup....."L]; Process.Pause[Process.SecondsToTicks[5]]; }; IF space # Space.nullHandle THEN BEGIN IF debug THEN { Put.Line[toolData.fileSW, "space # null handle..."L]; Process.Pause[Process.SecondsToTicks[5]]; }; Space.Delete[space]; space _ Space.nullHandle; END; --CloseVolume[]; END; --Cleanup Put.Line[toolData.fileSW, "Will copy Source Volume boot file into Dest. Volume and boot Dest. Volume"L]; Put.Line[toolData.fileSW, "Confirm to continue?"L]; IF ~ILT.Confirm[] THEN RETURN[FALSE]; [srcVolumeID, srcVolumeOpen] _ ILT.GetVolumeID[toolData.srcVolName]; IF srcVolumeID = Volume.nullID THEN RETURN[FALSE]; [destVolumeID, destVolumeOpen] _ ILT.GetVolumeID[toolData.destVolName]; IF destVolumeID = Volume.nullID THEN RETURN[FALSE]; IF String.Equivalent[toolData.srcVolName, toolData.destVolName] THEN BEGIN Put.Line[toolData.msgSW, " Source Volume equals Destination Volume"]; RETURN[FALSE]; END; [volSize, freePages] _ Volume.GetAttributes[srcVolumeID]; Put.Text[toolData.fileSW, " \n Source Volume size = "L]; Put.LongDecimal[toolData.fileSW, volSize]; Put.Line[toolData.fileSW, " pages"L]; Put.Text[toolData.fileSW, " Free pages on source volume = "L]; Put.LongDecimal[toolData.fileSW, freePages]; Put.CR[toolData.fileSW]; [volSize, freePages] _ Volume.GetAttributes[destVolumeID]; Put.Text[toolData.fileSW, " \n Destination Volume size = "L]; Put.LongDecimal[toolData.fileSW, volSize]; Put.Line[toolData.fileSW, " pages"L]; Put.Text[toolData.fileSW, " Free pages on destination volume = "L]; Put.LongDecimal[toolData.fileSW, freePages]; Put.CR[toolData.fileSW]; [srcCap, firstPage] _ GetVolumeBootFile[srcVolumeID, hardMicrocode]; [destCap, firstPage] _ GetVolumeBootFile[destVolumeID, hardMicrocode]; IF destCap = File.nullCapability THEN BEGIN IF debug THEN { Put.Line[ILT.toolData.fileSW, " = nullCapability...."L]; Process.Pause[Process.SecondsToTicks[5]]; }; destCap _ File.Create[destVolumeID, 0, FileTypes.tUntypedFile]; END ELSE BEGIN IF debug THEN { Put.Line[ILT.toolData.fileSW, " MakeUnbootable.."L]; Process.Pause[Process.SecondsToTicks[5]]; }; MakeUnbootable[ destCap, hardMicrocode, firstPage ! TemporaryBooting.InvalidParameters => BEGIN Put.Text[ILT.toolData.msgSW, "Warning: trouble making unbootable"L]; CONTINUE; END]; END; IF srcCap = File.nullCapability THEN uCodeSize _ 0 ELSE uCodeSize _ File.GetSize[srcCap]; Put.Text[toolData.fileSW, " Source boot file size = "]; Put.LongDecimal[toolData.fileSW, uCodeSize]; Put.Text[toolData.fileSW, " pages; "]; Put.LongDecimal[toolData.fileSW, uCodeSize*512]; Put.Line[toolData.fileSW, " bytes."]; < { Put.Line[toolData.fileSW, " File.Unknown!"L]; Cleanup[]; GOTO noGood}]; IF debug THEN { Put.Line[toolData.fileSW, "SetSize...."L]; Process.Pause[Process.SecondsToTicks[10]]; }; File.SetSize[destCap, uCodeSize ! Volume.Unknown => { Put.Line[toolData.fileSW, " Volume.Unknown!"L]; Cleanup[]; GOTO noGood}];>> IF debug THEN { Put.Line[toolData.fileSW, "SetSize...."L]; Process.Pause[Process.SecondsToTicks[10]]; }; File.SetSize[destCap, uCodeSize ! Volume.InsufficientSpace => { Put.Line[toolData.fileSW, " Not enough room on dest. volume!"L]; Cleanup[]; GOTO noGood}]; IF debug THEN { Put.Line[toolData.fileSW, "Create...."L]; Process.Pause[Process.SecondsToTicks[10]]; }; space _ Space.Create[bufferPages, Space.virtualMemory]; IF debug THEN { Put.Line[toolData.fileSW, "Map...."L]; Process.Pause[Process.SecondsToTicks[5]]; }; Space.Map[space]; IF debug THEN { Put.Line[toolData.fileSW, "CreateUniformSwapUnits...."L]; Process.Pause[Process.SecondsToTicks[5]]; }; Space.CreateUniformSwapUnits[size: 16, parent: space]; IF debug THEN { Put.Line[toolData.fileSW, "LongPointer...."L]; Process.Pause[Process.SecondsToTicks[5]]; }; base _ Space.LongPointer[space]; FOR windowPage: Space.PageOffset _ 0, windowPage + bufferPages WHILE windowPage < Inline.LowHalf[uCodeSize] DO Space.CopyIn[space, [srcCap, windowPage]]; Space.CopyOut[space, [destCap, windowPage]]; pageCount _ pageCount + bufferPages; Put.Text[toolData.msgSW, "Pages transfered: "]; Put.Decimal[toolData.msgSW, pageCount]; Put.CR[toolData.msgSW]; InvertIndicator[]; ENDLOOP; IF debug THEN { Put.Line[toolData.fileSW, "Cleanup...."L]; Process.Pause[Process.SecondsToTicks[5]]; }; Cleanup[]; IF debug THEN { Put.Text[toolData.fileSW, "SetVolumeBootFile..."L]; Process.Pause[Process.SecondsToTicks[5]]; }; SetVolumeBootFile[destCap, hardMicrocode, 0]; IF debug THEN { Put.Text[toolData.fileSW, "MakePermanent..."L]; Process.Pause[Process.SecondsToTicks[5]]; }; File.MakePermanent[destCap]; IF debug THEN { Put.Text[toolData.fileSW, "MakeBootable..."L]; Process.Pause[Process.SecondsToTicks[5]]; }; MakeBootable[ destCap, hardMicrocode, 0 ! TemporaryBooting.InvalidParameters => BEGIN Put.Text[toolData.msgSW, "Warning: trouble making bootable"L]; CONTINUE; END]; Put.Line[toolData.fileSW, " installed."L]; IF debug THEN { Put.Text[toolData.fileSW, "SetPhysicalVolumeBootFile..."L]; Process.Pause[Process.SecondsToTicks[5]]; }; SetPhysicalVolumeBootFile[destCap, hardMicrocode, 0]; destVolumeOpen _ CloseVolume[destVolumeID]; srcVolumeOpen _ CloseVolume[srcVolumeID]; RETURN[TRUE]; EXITS noGood => RETURN[FALSE]; END; --Retrieve END...ILTBootImpl.mesa