SPRUI03E June 2015 – January 2023
The $DPR_BYTE(sym), $DPR_HWORD(sym), or $DPR_WORD(sym) operator can be applied in the source operand of a MVKL or MVKH instruction to load the DP-relative offset of a symbol's address into a register. These operators are used by the compiler when accessing data objects that are not within the signed 15-bit offset range that is needed for using the DP-relative addressing mode.
EABI requires that all sections that are accessed via DP-relative addressing be grouped together. The linker then uses the address of the first section in that group as the "static base" whose value is attached to the symbol __c6xabi_DSBT_BASE. DP-relative addressing then implicitly incorporates the value of __c6xabi_DSBT_BASE into the resolution of the referenced symbol. In the examples that follow, "static_base" in the comments indicates the location of this static base. See Chapter 4 of the The C6000 Embedded Application Binary Interface Application Report (SPRAB89) for more details about data allocation and addressing.
For example, suppose the compiler needs to access a 32-bit aligned data object called 'xyz' that is defined in the .far section. The compiler must assume that the .far section is too far away from the base of the .bss section (whose address the runtime library's boot routine has loaded into the DP register), so using DP-relative addressing mode to access 'xyz' directly is not possible. Instead, the compiler will use a MVKL/MVKH/LDW sequence of instructions:
MVKL $DPR_WORD(xyz),A0 ; load (xyz - static_base)/4 into A0
MVKH $DPR_WORD(xyz),A0
LDW *+DP[A0],A1 ; load *xyz into A1
This sequence of instructions is also referred to as far DP-relative addressing. The LDW instruction uses a scaled version of DP-relative indexed addressing. Similar to the $DPR_WORD(sym) operator, the $DPR_BYTE(sym) operator is provided to facilitate far DP-relative addressing of 8-bit data objects:
MVKL $DPR_BYTE(xyz),A0 ; load (xyz - static_base) into A0
MVKH $DPR_BYTE(xyz),A0
LDB *+DP[A0],A1 ; load *xyz into A1
The $DPR_HWORD(sym) operator is provided to facilitate far DP-relative addressing of 16-bit data objects:
MVKL $DPR_HWORD(xyz),A0 ; load (xyz - static_base)/2 into A0
MVKH $DPR_HWORD(xyz),A0
LDH *+DP[A0],A1 ; load *xyz into A1
If the data being accessed is within range of the anticipated value of the DP (assuming the static base is loaded into the DP before the MVK instructions are used), then a more efficient way to access the data can be to use MVK instructions. For example, the compiler can compute the address of an 8-bit data object in the .bss section:
MVK $DPR_BYTE(_char_X),A4 ; load (_char_X - static_base) into A4
ADD DP,A4,A4 ; compute address of _char_X
Similarly, the compiler can compute the address of a 16-bit data object that is defined in the .bss section:
MVK $DPR_HWORD(_short_X),A4 ; load (_short_X - static_base)/2 into A4
ADD DP,A4,A4 ; compute address of _short_X
It can also compute a 32-bit data object that is defined in the .bss section:
MVK $DPR_WORD(_int_X),A4 ; load (_int_X - static_base)/4 into A4
ADD DP,A4,A4 ; compute address of _int_X