Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
922 Views

Missing volatile keyword in hwlib inline assembler functions (armclang).

Hi,

 

It seems that some inline assembler functions in the hwlib are not working correctly when compiled with armclang compiler with moderate optimization level (-O2).

 

As an example lets take a helper function from "alt_cache.c" file:

 

static __inline __attribute__((always_inline)) void sctlr_write_helper(uint32_t sctlr)

{

#if defined(__ARMCOMPILER_VERSION)

__asm("MCR p15, 0, %[sctlr], c1, c0, 0" : : [sctlr] "r" (sctlr));

#elif defined(__ARMCC_VERSION)

__asm("MCR p15, 0, sctlr, c1, c0, 0");

#else

__asm("MCR p15, 0, %0, c1, c0, 0" : : "r" (sctlr));

#endif

}

 

The armclang inline assembler requires the "volatile" keyword to be used like this:

 

static __inline __attribute__((always_inline)) void sctlr_write_helper(uint32_t sctlr)

{

#if defined(__ARMCOMPILER_VERSION)

__asm volatile ("MCR p15, 0, %[sctlr], c1, c0, 0" : : [sctlr] "r" (sctlr));

#elif defined(__ARMCC_VERSION)

__asm("MCR p15, 0, sctlr, c1, c0, 0");

#else

__asm("MCR p15, 0, %0, c1, c0, 0" : : "r" (sctlr));

#endif

}

 

Here is the link to the ARM documentation:

https://developer.arm.com/docs/100067/latest/armclang-inline-assembler/inline-assembly-statements-wi...

 

 

 

0 Kudos
0 Replies