assemblyglobal-variablesabipowerpc

PowerPC r13 Register Small Data Pointer Example in C Source Code


The r13 in ppc it's the Small data area pointer register.

What is an example in a C Source code that will use this register?


Solution

  • You're looking to make the compiler use .sdata or .sbss for global data variables.  A simple program with a global variable and the proper compile options should do it.

    From gcc for RS6000 / PowerPC:

    https://gcc.gnu.org/onlinedocs/gcc/RS_002f6000-and-PowerPC-Options.html

    -msdata=eabi
    

    On System V.4 and embedded PowerPC systems, put small initialized const global and static data in the .sdata2 section, which is pointed to by register r2. Put small initialized non-const global and static data in the .sdata section, which is pointed to by register r13. Put small uninitialized global and static data in the .sbss section, which is adjacent to the .sdata section. The -msdata=eabi option is incompatible with the -mrelocatable option. The -msdata=eabi option also sets the -memb option

    -msdata=sysv
    

    On System V.4 and embedded PowerPC systems, put small global and static data in the .sdata section, which is pointed to by register r13. Put small uninitialized global and static data in the .sbss section, which is adjacent to the .sdata section. The -msdata=sysv option is incompatible with the -mrelocatable option.

    -msdata=default
    -msdata
    

    On System V.4 and embedded PowerPC systems, if -meabi is used, compile code the same as -msdata=eabi, otherwise compile code the same as -msdata=sysv.

    -msdata=data
    

    On System V.4 and embedded PowerPC systems, put small global data in the .sdata section. Put small uninitialized global data in the .sbss section. Do not use register r13 to address small data however. This is the default behavior unless other -msdata options are used.

    -G num
    

    On embedded PowerPC systems, put global and static items less than or equal to num bytes into the small data or BSS sections instead of the normal data or BSS section. By default, num is 8. The -G num switch is also passed to the linker. All modules should be compiled with the same -G num value.