Comment 0 for bug 1658362

Revision history for this message
Daniel Böhmer (dboehmer) wrote :

The following function

__attribute__((always_inline))
__STATIC_INLINE void storeR12normally()
{
   register uint32_t __rf __ASM("r12");
   __rf = (uint32_t)testFunc;
   __ASM volatile ("svc 0" : SVC_Out0 : SVC_In0 : SVC_CL2);
}

results in the following assembly:

   register uint32_t r asm("r12");
   r = (uint32_t)testFunc;
 8000368: 4b04 ldr r3, [pc, #16] ; (800037c <main+0x18>)
 800036a: 469c mov ip, r3
   asm volatile ("svc 0" : : "r"(r) : "r0","r1");
 800036c: df00 svc 0

The address of the function testFunc() is stored in register 12 (ip) as wanted.

However, when I try to put the same code in a templated function, the assembly is not correct anymore:

template<void(*F)()>
__attribute__((always_inline))
__STATIC_INLINE void storeR12template()
{
   register uint32_t r asm("r12");
   r = (uint32_t)F;
   asm volatile ("svc 0" : : "r"(r) : "r0","r1");
}

results in:
   register uint32_t r asm("r12");
   r = (uint32_t)F;
 800036e: 4c03 ldr r4, [pc, #12] ; (800037c <main+0x18>)
   asm volatile ("svc 0" : : "r"(r) : "r0","r1");
 8000370: df00 svc 0

The value is only loaded into r4 and not moved to r12 anymore.

I am using GCC 6.2 2016q4 (binary release) with the c++11 option and:
-mfpu=fpv4-sp-d16 -mfloat-abi=hard -mcpu=cortex-m4 -ffunction-sections -mthumb

compiled on a 64bit intel core i5-3230

Thank you,
Best regards
Daniel - <email address hidden>