Skip to content

Commit 78f0a56

Browse files
committed
[libc] Enable the FPU in Arm startup code
This patch enables the FPU in Arm startup code, which is required to run tests on Arm configurations with hardware floating-point support.
1 parent 85c7827 commit 78f0a56

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

libc/startup/baremetal/arm/start.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,28 @@ namespace LIBC_NAMESPACE_DECL {
131131
__arm_wsr("CPSR_c", 0x13); // SVC
132132
#endif
133133

134+
#ifdef __ARM_FP
135+
// Enable FPU
136+
#if __ARM_ARCH_PROFILE == 'M'
137+
// Set CPACR cp10 and cp11
138+
auto cpacr = (volatile uint32_t *const)0xE000ED88;
139+
*cpacr |= (0xF << 20);
140+
__dsb(0xF);
141+
__isb(0xF);
142+
#elif __ARM_ARCH_PROFILE == 'A' || __ARM_ARCH_PROFILE == 'R'
143+
// Set CPACR cp10 and cp11
144+
uint32_t cpacr = __arm_rsr("p15:0:c1:c0:2");
145+
cpacr |= (0xF << 20);
146+
__arm_wsr("p15:0:c1:c0:2", cpacr);
147+
// Set FPEXC.EN
148+
uint32_t fpexc;
149+
__asm__ __volatile__("vmrs %0, FPEXC" : "=r"(fpexc) : :);
150+
fpexc |= (1 << 30);
151+
__asm__ __volatile__("vmsr FPEXC, %0" : : "r"(fpexc) :);
152+
__isb(0xF);
153+
#endif
154+
#endif
155+
134156
// Perform the equivalent of scatterloading
135157
LIBC_NAMESPACE::memcpy(__data_start, __data_source,
136158
reinterpret_cast<uintptr_t>(__data_size));

0 commit comments

Comments
 (0)