[Oberon] Standalone BootLoader format
Andreas Pirklbauer
andreas_pirklbauer at yahoo.com
Tue May 12 13:53:39 CEST 2020
> I don’t why ORP.Module sets dc := 8 to leave space for 7 entries.
Hi Jörg,
1) It’s actually not dc := 8 in ORP which leaves space for 7 entries.
What dc := 8 does is to simply set the address of the very *first*
variable of a standalone program (variable x in the example below)
at absolute memory address 8, leaving the 2 words at Mem[0] and
Mem[4] untouched.
MODULE* M;
VAR x: INTEGER; (*stored at absolute memory address 8*)
BEGIN x := 11
END M.
ORP.Compile M.Mod/s ~
ORTool.DecObj M.rsc ~
2) What leaves space for 7 entries is the code in ORG.Open, which
defines the *code* area of a standalone program as follows:
- code[0] contains the "B 7" jump, i.e. a branch to code[8]
- code[1] is set to 0 (this is unused currently)
- code[2] to code[7] start out as 0 (variable space)
- code[8] contains the first instruction of the standalone program
So, IF (the code area of) a standalone program HAPPENS to be
loaded at absolute address 0, then we have ADR(x) = ADR(code[2]).
0 E7000007 B 7 ; code[0]
1 00000000 MOV R0 R0 R0 ; code[1], unused
2 00000000 MOV R0 R0 R0 ; code[2], ADR(code[2]) = ADR(x)
3 00000000 MOV R0 R0 R0 ; code[3]
4 00000000 MOV R0 R0 R0 ; ..
5 00000000 MOV R0 R0 R0 ; ..
6 00000000 MOV R0 R0 R0 ; ..
7 00000000 MOV R0 R0 R0 ; code[7]
8 5E00FFC0 MOV SP R0 -64 ; first instruction of standalone prg
9 4000000B MOV R0 R0 11
10 41000000 MOV R1 R0 0
11 A0100008 STR R0 R1 8
12 40000000 MOV R0 R0 0
13 C7000000 B R0
Of course, the bootloader (BootLoad.Mod) is NOT loaded at absolute
address 0, but is rather placed in ROM at address -8192. So for the
bootloader, the six words code[2] to code[7] are set to zero and are
effectively wasted. This is not a big deal though.
If the bootloader HAD any global variables, they would be placed
at absolute memory addresses 8 upwards. But of course, it doesn’t
have any absolute variables, because the very task of the bootloader
is to overwrite the memory area starting at absolute address 0 with
the pre-linked binary of the inner core (Kernel, FileDir, Files, Modules).
This is, in fact, the reason why the bootloader does not HAVE any
global vartiables - they would be overwritten.
All this is explained in section 10 beginning at page 9 of:
http://github.com/andreaspirklbauer/Oberon-extended/blob/master/Documentation/The-Oberon-system-building-tools.pdf
Note: ORX.WriteCode M.rsc M.code ~ can be used to extract the code
section of a standalone program.
More information about the Oberon
mailing list