Skip to content

Commit 69e5bf3

Browse files
committed
[libc] Add support for MVE to Arm startup code
In order to have MVE support, the same bits of the CPACR register that enable the floating-point extension must be set.
1 parent e1f8690 commit 69e5bf3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

libc/startup/baremetal/arm/start.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,23 @@ 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'
134+
#if __ARM_ARCH_PROFILE == 'M' && \
135+
(defined(__ARM_FP) || defined(__ARM_FEATURE_MVE))
136+
// Enable FPU and MVE. They can't be enabled independently: the two are
137+
// governed by the same bits in CPACR.
137138
// Based on
138139
// https://developer.arm.com/documentation/dui0646/c/Cortex-M7-Peripherals/Floating-Point-Unit/Enabling-the-FPU
139-
// Set CPACR cp10 and cp11
140+
// Set CPACR cp10 and cp11.
140141
auto cpacr = (volatile uint32_t *const)0xE000ED88;
141142
*cpacr |= (0xF << 20);
142143
__dsb(0xF);
143144
__isb(0xF);
144-
#elif __ARM_ARCH_PROFILE == 'A' || __ARM_ARCH_PROFILE == 'R'
145+
#elif (__ARM_ARCH_PROFILE == 'A' || __ARM_ARCH_PROFILE == 'R') && \
146+
defined(__ARM_FP)
147+
// Enable FPU.
145148
// Based on
146149
// https://developer.arm.com/documentation/dui0472/m/Compiler-Coding-Practices/Enabling-NEON-and-FPU-for-bare-metal
147-
// Set CPACR cp10 and cp11
150+
// Set CPACR cp10 and cp11.
148151
uint32_t cpacr = __arm_rsr("p15:0:c1:c0:2");
149152
cpacr |= (0xF << 20);
150153
__arm_wsr("p15:0:c1:c0:2", cpacr);
@@ -154,7 +157,6 @@ namespace LIBC_NAMESPACE_DECL {
154157
__asm__ __volatile__("vmrs %0, FPEXC" : "=r"(fpexc) : :);
155158
fpexc |= (1 << 30);
156159
__asm__ __volatile__("vmsr FPEXC, %0" : : "r"(fpexc) :);
157-
#endif
158160
#endif
159161

160162
// Perform the equivalent of scatterloading

0 commit comments

Comments
 (0)