Startup Commands

Purpose

Part of the run-time error recovery strategy is to restart the whole system, in case all else fails. In this case, also the control program should start from scratch automatically.

Approach

Oberon.Call executes a command, passed as string ModuleName.CommandName. Upon system reload from the SD card, the body of Oberon.mod calls OnStartup.Load, which reads the file onstartup.cfg, containing strings that can be passed to Oberon.Call. A configuration tool, CfgTool.mod, offers commands to manage this file.

OnStartup.mod

MODULE OnStartup;
    
  CONST CfgFileName = "onstartup.cfg";
  
  PROCEDURE Load*(call: CallProc);
    VAR
      cmd: ARRAY 48 OF CHAR;
      res: INTEGER;
  BEGIN
    f := Files.Old(CfgFileName);
    IF f # NIL THEN
      Files.Set(r, f, 0);
      Files.ReadString(r, cmd);
      WHILE ~r.eof DO
        Texts.WriteString(W, " "); Texts.WriteString(W, cmd); Texts.WriteLn(W);
        call(cmd, res);
        IF res # 0 THEN
          Texts.WriteString(W, "error: "); Texts.WriteInt(W, res, 3); Texts.WriteLn(W)
        END;
        Files.ReadString(r, cmd)
      END
    END;
    Files.Close(f)
  END Load;
  
END OnStartup.

The call procedure is passed to OnStartup.Load as parameter to avoid cyclic imports.

The body of Oberon.mod calls OnStartup.Load as part of the system load process:

MODULE Oberon;
(* ... *)
BEGIN
  (* ... *)
  Texts.WriteString(W, "On-startup loading..."); Texts.WriteLn(W);
  OnStartup.Load(Call);
  Texts.WriteString(W, "...done"); Texts.WriteLn(W);
  (* ... *)
END Oberon.

Demo

With the demo module for the trap handling, if we add TestTraps.Run to the onstartup.cfg file, and then start the program, we get this output in the Astrobe console:

...
TRAP 6 at pos 368 in TestTraps at 000110D8

Starting scheduler
start p1
p1      3976
p1      4975

TRAP 6 at pos 368 in TestTraps at 000110D8

RESTART

Oberon RTS 2020-07-23
Based on Embedded Oberon 2019-07-01
RISC5 processor:  7-1-1.0-13
System Control Reg:  00010002
On-startup loading...
 TestTraps.Run
...done
Starting scheduler
start p1
p1      5982
p1      6982
...