This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Function to save ALL registers to stack



Hi all,

Is there a way in CCE v3 to get the functionality of __attribute__ ( naked ) of GCC?  The compiler user guide says quite clearly it doesn't support it.

Ideally I would like an ISR function to save ALL the registers to the stack instead of only the ones the ISR thinks it's using.  This is obviously for context switching in an RTOS.

Thanks,

Dan.

  • Were you able to create or find some reference code for saving all the registers to the stack?

    -DG

  • I did not find an equivalent of getting GCC's __attribute__ ( naked ).  According to the post below, the TI MSP430 compiler does not support "naked" functions.

    http://e2e.ti.com/support/development_tools/compiler/f/343/t/102208.aspx#359147

    What I ended up doing was using an assembly file to push all the registers to stack, then call a C function, and then pop the registers.  Use push/call/pop for MSP430, and pushm/calla/popm for MSP430X.  The downside is that some registers are saved twice, first by the assembly routine, then by C routine.

    You can look at the MSP430 and MSP430X ports for FreeRTOS (in the FreeRTOS\Source\Portable\... folders) for such an implementation.

    FreeRTOS homepage: http://www.freertos.org

    Latest FreeRTOS download: http://sourceforge.net/projects/freertos/files/FreeRTOS/

    Good luck,

    Dan.

  • The naked attribute doesn't make any sense for normal C code. Its only use is when writing startup code in C or when used with inline assembly.
    The tight integration of inlien assembly into C code under GCC makes it useful if you don't want to add plain assembly files to your project under GCC.

    However, under IAR or GCC, it is better to write the function you need directly in assembly language.

    Remember, things like processor registers or stack pointers are not in the scope of the C language. And so intentional saving of registers or changing the stack for mulithreading is nothing that can be done with C language at all.

    For thread switching, I strongly suggest going for assembly code. Really.
    I did it myself, and ended up in a 100% assembly function for the switching ISR (even though I did it in inline assembly under MSPGCC).

**Attention** This is a public forum