User guide

2.7 Read-write position independence
A program is Read-Write Position-Independent (RWPI) if all its read-write segments are position independent.
An RWPI segment is usually position-independent data (PID).
Select the RWPI option to avoid committing yourself to a particular location of data in memory. This is particularly
useful for data that must be multiply instantiated for reentrant routines.
2.7.1 Reentrant routines
A reentrant routine can be threaded by several processes at the same time. Each process has its own copy of the
read-write segments of the routine. Each copy is addressed by a different value of the static base register.
2.7.2 Register usage with RWPI
Register r9 is the static base, sb. It must point to the base address of the appropriate static data segments whenever
you call any externally visible routine.
You can use r9 for other purposes in a routine that does not use sb. If you do this you must save the contents of sb
on entry to your routine and restore it before exit. You must also restore it before any call to an external routine.
In all other respects the usage of registers is the same with or without RWPI (see Register roles and names).
2.7.3 Position-independent data addressing
An RWPI segment can be repositioned until it is first used. The address of a symbol in an RWPI segment is
calculated as follows:
1. The linker calculates a read-only offset from a fixed location in the segment. By convention, the fixed location is
the first byte of the lowest addressed RWPI segment of the program.
2. At runtime, this is used as an offset added to the contents of the static base register, sb.
2.7.4 Writing assembly language for RWPI
Construct references from a read-only segment to the RWPI segment by adding a fixed (read-only) offset to the
value of sb (see DCDO in the Directives Reference chapter in Assembler Guide).
Using the Procedure Call Standard
Copyright ?1999 2001 ARM Limited 2-10