[v2] arm: Enable FPU for M-profile

Message ID 20260616111125.96293-1-christophe.lyon@arm.com
State New
Headers
Series [v2] arm: Enable FPU for M-profile |

Commit Message

Christophe Lyon June 16, 2026, 11:11 a.m. UTC
  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  <christophe.lyon@arm.com>

	* libgloss/arm/cpu-init/rdimon-aem.S: Enable full FPU access on
	M-profile.
---
 libgloss/arm/cpu-init/rdimon-aem.S | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
  

Comments

Christophe Lyon June 19, 2026, 1:06 p.m. UTC | #1
Hi,

On 6/16/26 13:11, Christophe Lyon wrote:
> 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  <christophe.lyon@arm.com>
> 
> 	* libgloss/arm/cpu-init/rdimon-aem.S: Enable full FPU access on
> 	M-profile.

Sorry I had forgotten to 'git add' libgloss/arm/crt0.S where I enabled 
the call to _rdimon_hw_init_hook for M-profile too. I've just sent v3 
with that:
https://sourceware.org/pipermail/newlib/2026/022488.html

Thanks

Christophe

> ---
>   libgloss/arm/cpu-init/rdimon-aem.S | 28 +++++++++++++++++++++++++---
>   1 file changed, 25 insertions(+), 3 deletions(-)
> 
> diff --git a/libgloss/arm/cpu-init/rdimon-aem.S b/libgloss/arm/cpu-init/rdimon-aem.S
> index c960924d4..c8640632a 100644
> --- a/libgloss/arm/cpu-init/rdimon-aem.S
> +++ b/libgloss/arm/cpu-init/rdimon-aem.S
> @@ -25,9 +25,10 @@
>   
>   /* This file gives a basic initialisation of a Cortex-A series core.  It is
>      the bare minimum required to get Cortex-A core running with a semihosting
> -   interface.  For M-profile we only define a hardfault handler, required to
> -   prevent the simulator from entering into an infinite loop.  The comments
> -   below apply to A-profile only.
> +   interface.  For M-profile we define a hardfault handler, required to
> +   prevent the simulator from entering into an infinite loop and we enable
> +   the FPU when __ARM_FP is set.
> +   The comments below apply to A-profile only.
>   
>      It sets up a basic 1:1 phsyical address to virtual address mapping;
>      turns the MMU on; enables branch prediction; activates any integrated
> @@ -542,6 +543,27 @@ page_tables:
>        PT7(0x1c0e)
>   
>   #elif  (__ARM_ARCH_PROFILE == 'M')
> +    .syntax	unified
> +    .thumb
> +
> +    @ CPU Initialisation
> +    .globl	_rdimon_hw_init_hook
> +    .type	_rdimon_hw_init_hook, %function
> +
> +_rdimon_hw_init_hook:
> +    /* Enable FPU for M-profile only .  */
> +#if __ARM_FP
> +    /* Read CPACR */
> +    ldr	r0, =0xE000ED88
> +    ldr	r1, [R0]
> +    /* Enable full access to CP10 and CP11.  */
> +    orr	r1, r1, #(0xFF << 20)
> +    str	r1, [R0]
> +    dsb
> +    isb
> +#endif
> +    bx	lr
> +
>       /* On M-profile, call abort in case of hardfault: this causes the simulator to
>          abort execution instead of going into an infinite loop.  */
>       .section .hardfault_handler_addr, "a"
  

Patch

diff --git a/libgloss/arm/cpu-init/rdimon-aem.S b/libgloss/arm/cpu-init/rdimon-aem.S
index c960924d4..c8640632a 100644
--- a/libgloss/arm/cpu-init/rdimon-aem.S
+++ b/libgloss/arm/cpu-init/rdimon-aem.S
@@ -25,9 +25,10 @@ 
 
 /* This file gives a basic initialisation of a Cortex-A series core.  It is
    the bare minimum required to get Cortex-A core running with a semihosting
-   interface.  For M-profile we only define a hardfault handler, required to
-   prevent the simulator from entering into an infinite loop.  The comments
-   below apply to A-profile only.
+   interface.  For M-profile we define a hardfault handler, required to
+   prevent the simulator from entering into an infinite loop and we enable
+   the FPU when __ARM_FP is set.
+   The comments below apply to A-profile only.
 
    It sets up a basic 1:1 phsyical address to virtual address mapping;
    turns the MMU on; enables branch prediction; activates any integrated
@@ -542,6 +543,27 @@  page_tables:
      PT7(0x1c0e)
 
 #elif  (__ARM_ARCH_PROFILE == 'M')
+    .syntax	unified
+    .thumb
+
+    @ CPU Initialisation
+    .globl	_rdimon_hw_init_hook
+    .type	_rdimon_hw_init_hook, %function
+
+_rdimon_hw_init_hook:
+    /* Enable FPU for M-profile only .  */
+#if __ARM_FP
+    /* Read CPACR */
+    ldr	r0, =0xE000ED88
+    ldr	r1, [R0]
+    /* Enable full access to CP10 and CP11.  */
+    orr	r1, r1, #(0xFF << 20)
+    str	r1, [R0]
+    dsb
+    isb
+#endif
+    bx	lr
+
     /* On M-profile, call abort in case of hardfault: this causes the simulator to
        abort execution instead of going into an infinite loop.  */
     .section .hardfault_handler_addr, "a"