tags:

views:

233

answers:

2

GCC documentation states in 6.30 Declaring Attributes of Functions:

naked

Use this attribute on the ARM, AVR, IP2K, RX and SPU ports to indicate that the specified function does not need prologue/epilogue sequences generated by the compiler. It is up to the programmer to provide these sequences. The only statements that can be safely included in naked functions are asm statements that do not have operands. All other statements, including declarations of local variables, if statements, and so forth, should be avoided. Naked functions should be used to implement the body of an assembly function, while allowing the compiler to construct the requisite function declaration for the assembler.

Can I safely call functions using C syntax from naked functions, or only by using asm?

A: 
The only statements that can be safely included in naked functions are 
asm statements that do not have operands. All other statements, including 
declarations of local variables, if statements, and so forth, should be avoided.

Based on the description you already gave, I would assume that even function calls are not suitable for the "naked" keyword.

Jerry
+1  A: 

If the only thing you do in the naked function is call another function you can just use a single JMP machine code instruction.

The function you jump to will have a valid prologue and it should return directly to the caller of the naked function since JMP doesn't push a return address on the stack.

Alexandre Jasmin
I asked my question, because in source of FreeRTOS for AVR I have seen the followingvoid vPortYield( void ) __attribute__ ( ( naked ) );void vPortYield( void ){ portSAVE_CONTEXT(); vTaskSwitchContext(); portRESTORE_CONTEXT(); asm volatile ( "ret" );}portSAVE_CONTEXT() and portRESTORE_CONTEXT() are macroses with asm but vTaskSwitchContext is a function.
Art Spasky