[fpc-devel] Data memory section support for AVR

Christo Crause christo.crause at gmail.com
Fri Jun 18 12:29:10 CEST 2021


Compiler support for the data memory sections .progmem (flash memory) and
.eeprom was added. The compiler will generate the required low level
instructions to access the respective memory section automatically.  The
support covers both classic AVR architecture and the newer unified memory
architecture. Refer to attached patches for details.

The section support is combined with type checking to ensure consistent and
predictable behaviour.  The rules are (hopefully) designed according to the
Pascal language spirit.  The following rules and behaviour have been
implemented:
- A variable, constant or type can be associated with a section.  If the
section name is not recognized the current behaviour is followed.
- Read/write access to .eeprom space is supported, but only read access for
the .progmem space is provided (due to the paged erase/write semantics).
- The .progmem access is strictly enforced at declaration time, so only
true constants, string literals and typed constants (if writeableconst is
off) are allowed to be in .progmem space.  Any typed const variables could
also be allowed if required, since another access check is done in the code
generator step to catch write operations to .progmem.
- A local switch literalStringsInProgmem can be used to indicate storage of
string literals in code in .progmem space.
- Parameters to functions/procedures can also refer to sections, on the
callee side the appropriate access code will be generated.
- Type checking of parameters is extended to also compare section types.
- Some build-in conversions from a sectioned type to a regular type is
provided.  This is used when a sectioned type is passed to a procedure with
a regular parameter type (if a conversion is possible). This conversion
doesn't apply when passing pointers or references.
- A local switch convertSectionedStringsToTemp can be specified to
preconvert sectioned shortstrings to regular temporary shortstrings before
further processing.  This reduces the dependence of section specific helper
routines and may lead to smaller executable size in certain cases.  When
this switch is active, the only time a sectioned shortstring will not be
converted is when it is passed as a parameter to a procedure with a
matching sectioned parameter type.
- Section information is added to symbols stored in ppu files so that
sectioned types work across unit boundaries.
- Helper code has been added to the AVR controller units to provide the low
level access in the include files sectionhelpersh.inc and
sectionhelpers.inc.
  * These include files provide low level EEPROM access and shortstring
conversion and handling helpers for section specific data.
  * Added extra I/O registers and bit definitions required for EEPROM
simulation to avrsim unit.  Simulation of EEPROM access requires an updated
version of fp-avrsim.

More information and simple examples/syntax can be viewed here:
https://github.com/ccrause/freepascal/wiki/Better-support-for-address-spaces-in-FPC#usage
Test cases can be viewed here:
https://github.com/ccrause/freepascal/tree/sectionsupport-rtl/tests/test/avr

Review, comments, suggestions and ready for submission discussions would be
appreciated.

Best wishes,
Christo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20210618/e394e95e/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: compiler.patch
Type: text/x-patch
Size: 153630 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20210618/e394e95e/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rtl.patch
Type: text/x-patch
Size: 125133 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20210618/e394e95e/attachment-0003.bin>


More information about the fpc-devel mailing list