This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Force consecutive operation when using asm volatile macro
Jari Kuusisto <jari.h.kuusisto@gmail.com> writes:
> Here's an example function from uC/OS where the critical section asm
> macro code seems not to work as expected (but with critical section
> function it works).
It might help to see how it fails. That said...
> #define OS_ENTER_CRITICAL() asm volatile("mfmsr
> %0":"=r"(cpu_sr));asm volatile("mtspr 81,r0")
> #define OS_EXIT_CRITICAL() asm volatile("mtmsr %0"::"r"(cpu_sr))
...there is nothing in these asm statements which tells the compiler
that it can't schedule instructions across them. The asm statements
say that the asm must not be deleted, but they don't say anything
about running before or after any other instructions.
Depending upon your requirements, it may suffice to simply say
asm volatile("mfmsr %" : "=r" : : "memory");
asm volatile("mtspr 81,r0" : : : "memory");
and
asm volatile("mtmsr %0" : : "r" (cpu_sr) : "memory");
Ian