I'm working on a port of the MIT/Intel Cilk runtime for ARM
and am trying to put together a binary package that runs on both the original Raspberry Pi and new Pi 2B. The difficulty is that the Pi 2B needs a DSB Data Synchronization Barrier instruction to manage the multi-core hardware whereas the original PI doesn't have this instruction. Currently I make the definition
#define __cilkrts_fence() __asm__ volatile ("DSB")
in the runtime source and everything works fine on the Pi 2B. This is binary equivalent to
#define __cilkrts_fence() __asm__ volatile (".word 0xf57ff04f")
which again works fine on the Pi 2B and has the advantage that it can be compiled by the assembler in ARMv6 mode. Not surprisingly the resulting binary gives an "Illegal instruction" trap when run on the original Pi. Therefore, I need to insert code that tests the cpuid register and makes a relative branch to skip past the DSB instruction if the cpuid is ARMv6. Logically the code should function as
if cpuid != ARMv6 then DSB
and be written in inline assembler. While I expect this is simple enough, I'm a complete noob at ARM assembler and would appreciate any help offered.