4.5 Enabling FPU for bare-metal

If the compiler knows that an FPU is available, for example if you use the --cpu option to specify a processor with an FPU, then the compiler might introduce FPU instructions into your code.

These instructions can be introduced even if you are not deliberately performing any floating-point operations.
If you want to build an image that does not use any FPU instructions, and does not require that the FPU be enabled, you can use the --fpu=none option when building all your source files.
When targeting bare-metal and compiling for a processor with an FPU, you must enable the FPU in your startup code before you can execute FPU instructions. See the Technical Reference Manual for your processor.
For example, the following startup code enables FPU hardware for a Cortex-M3 processor (TBD: Need code for M3):
__asm void StartHere(void)
{
MRC p15,0,r0,c1,c0,2    // Read CP Access register
ORR r0,r0,#0x00f00000   // Enable full access to NEON/VFP (Coprocessors 10 and 11)
MCR p15,0,r0,c1,c0,2    // Write CP Access register
ISB
MOV r0,#0x40000000      // Switch on the VFP and NEON hardware
MSR FPEXC,r0            // Set EN bit in FPEXC
IMPORT __main
B __main                // Enter normal C run-time environment & library start-up
}
To compile this code:
armcc -c --cpu=Cortex-M3 main.c
armlink --entry=StartHere main.o
Related tasks
4.4 Selecting the target processor at compile time
Related reference
7.29 --cpu=name compiler option
7.70 --fpu=name compiler option
Related information
--startup=symbol, --no_startup linker option
Non-ConfidentialPDF file icon PDF versionARM DUI0375F
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.