[PATCH] arm: Enable FPU for M-profile

Christophe Lyon <[email protected]> Thu, 11 Jun 2026 23:25:19 +0200
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Before using the FPU, we must grant access to it.  This helps when
running the GCC testsuite on a simluator where FPU access is not
granted by default.

This patch grants full access, we may want to consider granting only
unpriviledged access later.

2026-05-29  Christophe Lyon  <[email protected]>

	* libgloss/arm/crt0.S: Enable full FPU access on M-profile.
	* newlib/libc/sys/arm/crt0.S: Likewise.
---
 libgloss/arm/crt0.S        | 13 +++++++++++++
 newlib/libc/sys/arm/crt0.S | 13 +++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/libgloss/arm/crt0.S b/libgloss/arm/crt0.S
index b9e768007..0bec14e91 100644
--- a/libgloss/arm/crt0.S
+++ b/libgloss/arm/crt0.S
@@ -366,6 +366,19 @@
 
 #endif
 #endif
+
+	/* Enable FPU for M-profile only .  */
+#if defined (THUMB_VXM) && __ARM_FP
+	/* Read CPACR */
+	ldr r0, =0xE000ED88
+	ldr r1, [R0]
+	/* Enable full access to CP10 and CP11.  */
+	orr r1, r1, #(0xF << 20)
+	str r1, [R0]
+	dsb
+	isb
+#endif
+
 	/* Zero the memory in the .bss section.  */
 	movs 	a2, #0			/* Second arg: fill value.  */
 	mov	fp, a2			/* Null frame pointer.  */
diff --git a/newlib/libc/sys/arm/crt0.S b/newlib/libc/sys/arm/crt0.S
index 51e86d549..4c775fbbb 100644
--- a/newlib/libc/sys/arm/crt0.S
+++ b/newlib/libc/sys/arm/crt0.S
@@ -353,6 +353,19 @@
 
 #endif
 #endif
+
+	/* Enable FPU for M-profile only .  */
+#if defined (THUMB_VXM) && __ARM_FP
+	/* Read CPACR */
+	ldr r0, =0xE000ED88
+	ldr r1, [R0]
+	/* Enable full access to CP10 and CP11.  */
+	orr r1, r1, #(0xF << 20)
+	str r1, [R0]
+	dsb
+	isb
+#endif
+
 	/* Zero the memory in the .bss section.  */
 	movs 	a2, #0			/* Second arg: fill value.  */
 	mov	fp, a2			/* Null frame pointer.  */
-- 
2.34.1