Page 1 of 1

SYSTEM.LDREG

Posted: Fri Feb 04, 2022 9:07 am
by gray
The Astrobe RISC5 compiler creates erroneous code in the following case:

Code: Select all

PROCEDURE P;
  VAR i: INTEGER;
BEGIN
  i := 0;
  SYSTEM.LDREG(i, 13)
END P;
The procedure compiles without error message, but the code created is:

Code: Select all

4400000DH  MOV   r4,  r0, 13
Evidently, the target register number must be a constant, as with SYSTEM.REG, where the compiler does complain. As I understand it, r4 is targeted because the stack-local address of i is 4 (SP + 4).

I am completely out of my depth here, but I think the corresponding case in ORP.StandProc should read:

Code: Select all

IF (npar = nap) OR ((pno IN {0, 1, 4, 10, 11}) & (nap = (npar + 1))) OR ((pno = 9) & (nap = 4)) THEN
  CASE pno OF
  (* ... *)
  | 14: (* LDREG *)
    CheckConst(x); CheckInt(x); ORG.LDREG(x, y)
  END
END

Re: SYSTEM.LDREG

Posted: Fri Feb 04, 2022 10:23 am
by cfbsoftware
That particular section of code is taken 'as is' from the Project Oberon source code. As far as I am aware LDREG is an 'undocumented feature' in the RISC5 compiler - I have only seen it mentioned without explanation in some example code. Hence, you should make no assumptions about what it should or shouldn't do. Note that some SYSTEM functions (particularly undocumented ones) typically are less well protected from 'user' errors.

However, don't let me deter you from experimenting. Try switching the parameters and see what happens ...

Re: SYSTEM.LDREG

Posted: Wed Jun 14, 2023 1:08 pm
by gray
Just re-reading some old forum posts... and it occurred to me that, undocumented or not, SYSTEM.LDREG is arguably the most central feature of the compiler. Without it, the system would not even boot. See the bootloader, it's literally the first instruction the system executes. :)

Re: SYSTEM.LDREG

Posted: Sat Jun 17, 2023 4:41 am
by gray
SYSTEM.LDREG is also used in Oberon.Mod, and its sibling SYSTEM.REG in Kernel.Mod, Modules.Mod, System.Mod, as well as in the bootloader. SYSTEM.H, probably another undocumented feature, is used in Kernel.Mod. Hence, without undocumented features, no Oberon system as we know it.

Re: SYSTEM.LDREG

Posted: Sat Jun 17, 2023 11:12 pm
by cfbsoftware
Refer to the discussion titled [Oberon] List of extensions for Project Oberon compiler on the ETH Oberon Mailing list for more information related to "undocumented features" in Project Oberon.