SYSTEM.LDREG

General discussions about using the Astrobe IDE to program the FPGA RISC5 cpu used in Project Oberon 2013
Post Reply
gray
Posts: 108
Joined: Tue Feb 12, 2019 2:59 am
Location: Mauritius

SYSTEM.LDREG

Post by gray » Fri Feb 04, 2022 9:07 am

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

cfbsoftware
Site Admin
Posts: 492
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: SYSTEM.LDREG

Post by cfbsoftware » Fri Feb 04, 2022 10:23 am

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 ...

gray
Posts: 108
Joined: Tue Feb 12, 2019 2:59 am
Location: Mauritius

Re: SYSTEM.LDREG

Post by gray » Wed Jun 14, 2023 1:08 pm

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. :)

gray
Posts: 108
Joined: Tue Feb 12, 2019 2:59 am
Location: Mauritius

Re: SYSTEM.LDREG

Post by gray » Sat Jun 17, 2023 4:41 am

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.

cfbsoftware
Site Admin
Posts: 492
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: SYSTEM.LDREG

Post by cfbsoftware » Sat Jun 17, 2023 11:12 pm

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.

Post Reply