In the CMSIS definitions for gcc you can find something like this:
static __INLINE void __DMB(void) { __ASM volatile ("dmb"); }
My question is: what use does a memory barrier have if it does not declare “memory” in the clobber list?
Is it an error in the core_cm3.h or is there a reason why gcc should behave correctly without any additional help?
I did some testing with gcc 4.5.2 (built with LTO). If I compile this code:
using
arm-none-eabi-gcc -Os -mcpu=cortex-m3 -mthumb -c dmb.c, then fromarm-none-eabi-objdump -d dmb.oI get this:It is obvious that
__DBM()only inserts thedmbinstruction and it takesDMB2()to actually force the compiler to flush the values cached in the registers.I guess I found a CMSIS bug.