Standalone BootLoader format
One day I will get it clear, hope.
Tomas, I admit that the description in the book is not sufficiently clear when it comes to nuances like that. But it’s really all very simple. You just have to separate the notion of a standalone program and the bootloader (a special standalone program). Only what the boot loader (BootLoad.Mod) does with the addresses 12, 16, 20, 24 is special. And this is also the reason why BootLoad.Mod CANNOT declare any global variables -> it would mess with these values. Just remember this one thing: standalone programs always have their global variables start at absolute memory address 8. Always! In fact, if you look at the compiler (ORG.GetSB), you will see that if version = 0 (=standalone program), you have the line IF version = 0 THEN Put1(Mov, RH, 0, VarOrg0) (*VarOrg0 = 0*) and, because ORP.dc = 8 for standalone programs (see ORP.Module), you can see that the compiler ALWAYS places ANY global variables of ANY standalone program at absolute address 8 or higher.. The bootloader is the ONLY standalone program which in fact fills the memory locations 0, 8, 12, 16, 20, 24, … etc by reading a file (the boot file). And this is why the bootloader cannot itself declare any global variables. There would be a conflict. All other standalone programs CAN declare global variables. And if a standalone program (i.e. its code section) happens to be loaded to absolute address zero, the code in ORG.Open sees to it that there are at least 6 words within the code section starting at address at 8 that can, in fact, be used for global vars. So in fact, you are “hijacking" the code section to be used as global variables for standalone programs starting at address 0. It’s a hack, but that’s how PO 2013 has decided to implement it. Which is why on Oberon on RISC-V I have chosen a completely different approach. There, standalone programs do in fact have their own "data section” (just like a regular module loaded by the module loader) and also, the boot loader (or any other standalone program) can in fact be a pre-linked binary. This makes it possible to write bootloaders that consist of several modules, for examples modules which implement networking.
Andreas, Another exercise. Same standalone moudule, now compiled with Oberon-0 compiler. (* Standalone module booted over serial, with BRAM loader *) MODULE* Counter; VAR x, y, z: INTEGER; BEGIN LED(1); z := 0; REPEAT LED(z); x := 1000; REPEAT y := 1000; REPEAT y := y-1 UNTIL y = 0; x := x-1 UNTIL x = 0; z := z+1 UNTIL FALSE END Counter. (* BRAM Loader sets MTOrg = 20H; MemLim = 0E7EF0H; stackOrg = 80000H; SYSTEM.LDREG(SP, stackOrg); *) (* Stack SP := SP-4, save LINK reg *) 0 4EE90004 SUB SP SP 4 1 AFE00000 STW LNK SP 0 (* LED(1), mem[-60] := 1*) 2 40000001 MOV R0 R0 1 3 5100FFC4 MOV R1 R0 -60 4 A0100000 STW R0 R1 0 (* z := 0, mem[SB+8] := R0 *) 5 40000000 MOV R0 R0 0 (* Static base SB := mem[0+6] *) 6 8D000006 LDW SB R0 6 7 A0D00008 STW R0 SB 8 ... (* x := 1000, mem[SB+0] := R0 *) 11 400003E8 MOV R0 R0 1000 12 A0D00000 STW R0 SB 0 (* y := 1000, mem[SB+4] := R0 *) 13 400003E8 MOV R0 R0 1000 14 A0D00004 STW R0 SB 4 ... (* Restore and branch to LINK reg *) 31 8FE00000 LDW LNK SP 0 32 4EE80004 ADD SP SP 4 33 C700000F B LNK Why we initialise SB from mem[6] ??? Any limits on globals here??? -- Tomas Kral <thomas.kral@email.cz>
On Tue, 12 May 2020 21:34:36 +0200 Andreas Pirklbauer <andreas_pirklbauer@yahoo.com> wrote:
In fact, if you look at the compiler (ORG.GetSB), you will see that if version = 0 (=standalone program), you have the line
IF version = 0 THEN Put1(Mov, RH, 0, VarOrg0) (*VarOrg0 = 0*)
and, because ORP.dc = 8 for standalone programs (see ORP.Module),
(* my current version *) MODULE ORP; (*N. Wirth 1.7.97 / 4.4.2017 ... IF sym = ORS.times THEN version := 0; Texts.Write(W, "*"); ORS.Get(sym) ELSE version := 1 END ; Check(ORS.semicolon, "no ;"); level := 0; dc := 0; (* <=== *) (* newer version *) MODULE ORP; (*N. Wirth 1.7.97 / which one??? ... IF sym = ORS.times THEN version := 0; dc := 8; (* <=== *)Texts.Write(W, "*"); ORS.Get(sym) ELSE dc := 0; version := 1 END ; In my current version I miss dc := 8, so it seems. -- Tomas Kral <thomas.kral@email.cz>
participants (2)
-
Andreas Pirklbauer -
Tomas Kral