Forums » Programming with the ECS » Oberon »
Best option to include static data
Added by Runar Tenfjord about 1 year ago
I am in the process of porting a library I developed for the XDS compiler
and are having great success in adapting to ECS Oberon-2.
The XDS compiler has some specific quirks related to only partial support
64bit types and the optimizer triggering random errors. Otherwise it is excellent,
produce very fast code, so it is a pity this is abandoned and still stuck in the 1990s.
I have found ECS Obeton-2 to be very stable and complete during the conversion work
and now about 600 automatic tests are passing.
I was wondering how best to support adding static data to a library?
Specific I have some code ported from the Ryu floating point conversion
library by Ulf Adams which includes large precomputed floating point
array data.
The XDS compiler has support for typed constants and arrays
perhaps inherited from Modula-2.
I know this is commonly solved in Oberon code by filling in the
tables at runtime. I see also Project Oberon has an undocumented
feature with $ delimited string constants, but this is untyped and
maybe considered a hack.
My concern is that I want to use this with code on an MCU,
this will eat up my memory.
Ideally this data should therefore be placed in flash memory.
This should be solved in C++ code file or an assembly code file?
Replies (2)
RE: Best option to include static data - Added by Florian Negele about 1 year ago
The Oberon compiler unfortunately does not provide static initialisation and requires intitialising an array at runtime. The C++ compiler is not capable yet of expressing static arrays so the only way at the moment is to add an assembly file instead:
.const static_data .byte 1, 2 .byte 3, 4
You can then access this section using a external forward declaration in Oberon:
VAR ^ table ["static_data"]: ARRAY 2 OF RECORD a, b: UNSIGNED8 END;
What kind of MCU are you having in mind? Depending on the target architecture you might have to use a code section rather than a constant section in order to make sure that the data ends up in flash memory. If this is an Harvard architecture, you even have to use special instructions to read from the flash memory instead.
RE: Best option to include static data - Added by Runar Tenfjord about 1 year ago
Excellent. That would work.
I was thinking about an STM32 type MCU.
I see this is not supported yet by any runtime.
The idea was then to adapt the startup code for the RPI and
maybe get ARM semihosting to work for debugging.
This have worked nicely with the QEMU emulator for testing
purposes and also on real hardware with CLANG.