-- File: AltoRamLocked.mesa,  Last Edit: HGM  March 3, 1981  5:24 AM

-- This module must be locked in LOW memory.  SilentBoot kills the bank registers.

DIRECTORY
  AltoHardware USING [BankRegister, BankRegisters],
  ImageDefs USING [CleanupItem, CleanupReason, AddCleanupProcedure],
  AltoRam USING [SilentBoot];

AltoRamLocked: PROGRAM IMPORTS ImageDefs, AltoRam EXPORTS AltoRam =
  BEGIN

  -- This is used to move the Ethernet+Display+MRT tasks back into the ROM so
  --    things won't go haywire when Bravo or FTP loads the RAM later on.
  -- We leave normally unused (extra Ethernet) tasks in the RAM since
  --    Mesa does a StartIO to reset things and that wakes them up.
  calmBlv: WORD ← 177620B;
  runningBlv: WORD ← 177776B;

  DoSilentBoot: PUBLIC PROCEDURE [blv: WORD] =
    BEGIN runningBlv ← blv; DoSilentBootInternal[blv]; END;

  cleanupItem: ImageDefs.CleanupItem ← [, 17B, Broom];
  Broom: PROCEDURE [why: ImageDefs.CleanupReason] =
    BEGIN
    SELECT why FROM
      OutLd => DoSilentBootInternal[calmBlv]; -- Going to Debugger
      InLd => DoSilentBootInternal[runningBlv]; -- Comming back from Debugger
      Finish, Abort => UnBoot[]; -- going back to exec
      ENDCASE => NULL;
    END;

  UnBoot: PUBLIC PROCEDURE = BEGIN DoSilentBoot[calmBlv]; END;

  DoSilentBootInternal: PROCEDURE [blv: WORD] =
    BEGIN
    display: AltoHardware.BankRegister;
    display ← AltoHardware.BankRegisters[DWT];
    AltoRam.SilentBoot[blv];
    AltoHardware.BankRegisters[DWT] ← display;
    END;

  ImageDefs.AddCleanupProcedure[@cleanupItem];
  END.