Assuming you are using the arm-bcm2708hardfp-linux-gnueabi-* tools (used for building the Linux kernel) and you're linking against libgcc, you:
- need to add -mhard-float and -mfpu=vfp to your build flags (actually -mhard-float is the default)
- need to ensure that both .c and .s files are compiled using the same flags. Usually, Makefiles will use as directly for .s files, but if you just use gcc with exactly the same options as for .c files, it will figure out what it needs to do
- need to include the following code in your .s startup file, before you jump to your 'main'
- Code: Select all
@ enable the FPU
mrc p15, 0, r0, c1, c0, 2
orr r0, r0, #0x300000 /* single precision */
orr r0, r0, #0xC00000 /* double precision */
mcr p15, 0, r0, c1, c0, 2
mov r0, #0x40000000
(thanks go to DWelch for this code)
You should now be able to use float types and floating point math in your c code without triggering undefined instruction exceptions.