RWPI
If more than one application runs concurrently through an operating system, they must share the RAM memory. To make this possible, you can build your applications for position-independent data, RWPI (Read-Write Position Independent). RWPI applies only to data in RAM memory.
An application built for RWPI reserves one machine register for use as a base register for all RAM data accesses. This register is locked and cannot be used for anything else. The memory attribute for this memory area with its static base register is __sbrel, and becomes the default memory. To declare variables that are not position-independent, for example shared data and semaphores, use the memory attributes __data16, __data24, and __data32.
The static base register SB must be initialized before the RWPI program module is called. By default, the static base register is R12 if you are also using ROPI and R13 otherwise (or the highest available register if R13 has been locked for other purposes).
Limitations
There are some limitations to bear in mind when using RWPI:
Constant pointers to
__sbrelobjects cannot be used__sbrelobjects cannot be declaredconst.
Creating the RWPI module
To compile an application with position-independent data, use the compiler command line option --rwpi.
Caution
To specify RWPI in the IDE, choose Project>Options>General Options>Target> Read-write data.
When you link the application, all read-write data must be placed in a common block, tagged movable, with the static base register SB. For example:
define movable block SBREL with static base SB, alignment = 4
{ rw section .sbrel*, rw section __DLIB_PERTHREAD }The section __DLIB_PERTHREAD must be placed in RWPI memory (up to 256 Kbytes anywhere in data32 memory).