NOTICE: The Processors Wiki will End-of-Life in December of 2020. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.

Call conv attribute

From Texas Instruments Wiki
Jump to: navigation, search

The MSP430 TI compiler release 16.12.0.STS has a new function attribute to specify calling convention along with a new ROM calling convention.

The call_conv attribute can be used to specify the calling convention for function calls. This is intended for allowing IAR and TI compilers to link against the same ROM image if it was generated using the new cc_rom calling convention.

Currently the implementation only supports linking against ROM images built with IAR’s compiler using their ROM calling convention implementation. The TI Compiler currently does not support generating cc_rom ROM images.

The new attribute can be applied to functions, function pointers, and function typedefs.

The attribute is applied to a function with GCC attribute syntax, as follows:

   __attribute__((call_conv("cc_rom")))

The attribute accepts "cc_rom" or "cc_norm" (the default calling convention).

Some examples:

   #define __cc_rom __attribute__((call_conv("cc_rom"))) 

   __cc_rom void rom_func(void)
   {
      ...
   }
   typedef __cc_rom void (rom_func_t)(void);

   int main()
   {
      rom_func();

      rom_func_t *fp = (rom_func_t*)0x1234; 
      fp();

      ((void (__cc_rom *)(void))0x2468)();

      void (__cc_rom *rom_func_ptr)(void); 
      rom_func_ptr = &rom_func;
      rom_func_ptr();
   }

For IAR/TI compatibility with your calling conventions, be aware of the following restrictions on parameter passing.

  • All parameters combined must fit in registers. Parameters may not be passed on the stack.
  • Only scalar parameters are allowed. Do not pass structs.
  • Do not pass function pointers, enums, or doubles.
  • For single registers, use R12,13,14,15 in that order.
  • For register pairs, use R12:R13 or R14:R15 in that order.
  • For register quads, use R12:R13:R14:R15.
  • For MSP430, always use CALL/RET.
  • For MSP430x always uses CALLA/RETA.
  • For save-on-call registers, use R11-R15.
  • For save-on-entry registers, use R4-R10.