Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12367 Discussions

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

alemannia
Beginner
1,033 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-wi...

 

 

 

0 Kudos
0 Replies
Reply