Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12612 Discussions

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

alemannia
Beginner
1,661 Views

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-within-a-function/volatile

 

 

 

0 Kudos
0 Replies
Reply