Re: [PATCH v2] arm: Enable FPU for M-profile

Christophe Lyon <[email protected]> Fri, 19 Jun 2026 15:06:14 +0200
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
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  <[email protected]>
> 
> 	* 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"