From 321e891823737cbcc6e3031d3b16f5bc8a395d64 Mon Sep 17 00:00:00 2001 From: ericQiang Date: Fri, 15 Sep 2023 16:59:03 +0800 Subject: [PATCH 1/2] protect floating point registers before enter interrupt function, then the floating point calculation will be safe in interrupt function. --- libcpu/arm/cortex-a/context_gcc.S | 8 ++++++-- libcpu/arm/cortex-a/start_gcc.S | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/libcpu/arm/cortex-a/context_gcc.S b/libcpu/arm/cortex-a/context_gcc.S index da6e6507df2..087c4fe14b3 100644 --- a/libcpu/arm/cortex-a/context_gcc.S +++ b/libcpu/arm/cortex-a/context_gcc.S @@ -97,7 +97,9 @@ rt_hw_context_switch: tst r6, #(1<<30) beq 1f vstmdb sp!, {d0-d15} - vstmdb sp!, {d16-d31} +#ifdef RT_USING_VFPD32 /*there art 32 double float registers to save*/ + vstmdb sp!, {d16-d31} @ save the upper 16 registers +#endif vmrs r5, fpscr stmfd sp!, {r5} 1: @@ -237,7 +239,9 @@ rt_hw_context_switch_exit: beq 1f ldmfd sp!, {r5} vmsr fpscr, r5 - vldmia sp!, {d16-d31} +#ifdef RT_USING_VFPD32 /*there art 32 double float registers to restore*/ + vldmia sp!, {d16-d31} @ restore the upper 16 registers +#endif vldmia sp!, {d0-d15} 1: #endif diff --git a/libcpu/arm/cortex-a/start_gcc.S b/libcpu/arm/cortex-a/start_gcc.S index 606620ecfc4..8d22145da48 100644 --- a/libcpu/arm/cortex-a/start_gcc.S +++ b/libcpu/arm/cortex-a/start_gcc.S @@ -458,13 +458,30 @@ vector_irq: #else stmfd sp!, {r0-r12,lr} +#ifdef RT_USING_FPU + vstmdb sp!, {d0-d15} +#ifdef RT_USING_VFPD32 /*there art 32 double float registers to save*/ + vstmdb sp!, {d16-d31} @ save the upper 16 registers +#endif + vmrs r5, fpscr + stmfd sp!, {r5} +#endif bl rt_interrupt_enter bl rt_hw_trap_irq bl rt_interrupt_leave - /* if rt_thread_switch_interrupt_flag set, jump to - * rt_hw_context_switch_interrupt_do and don't return */ +#ifdef RT_USING_FPU + ldmfd sp!, {r5} + vmsr fpscr, r5 +#ifdef RT_USING_VFPD32 /*there art 32 double float registers to restore*/ + vldmia sp!, {d16-d31} @ restore the upper 16 registers +#endif + vldmia sp!, {d0-d15} +#endif + + @ if rt_thread_switch_interrupt_flag set, jump to + @ rt_hw_context_switch_interrupt_do and don't return ldr r0, =rt_thread_switch_interrupt_flag ldr r1, [r0] cmp r1, #1 From 4725cd948eb64368e44944b63291490446d02d41 Mon Sep 17 00:00:00 2001 From: ericQiang Date: Fri, 15 Sep 2023 17:22:26 +0800 Subject: [PATCH 2/2] fix the indent spaces --- libcpu/arm/cortex-a/start_gcc.S | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libcpu/arm/cortex-a/start_gcc.S b/libcpu/arm/cortex-a/start_gcc.S index 8d22145da48..1c8e833dfd0 100644 --- a/libcpu/arm/cortex-a/start_gcc.S +++ b/libcpu/arm/cortex-a/start_gcc.S @@ -459,12 +459,12 @@ vector_irq: #else stmfd sp!, {r0-r12,lr} #ifdef RT_USING_FPU - vstmdb sp!, {d0-d15} + vstmdb sp!, {d0-d15} #ifdef RT_USING_VFPD32 /*there art 32 double float registers to save*/ - vstmdb sp!, {d16-d31} @ save the upper 16 registers + vstmdb sp!, {d16-d31} @ save the upper 16 registers #endif - vmrs r5, fpscr - stmfd sp!, {r5} + vmrs r5, fpscr + stmfd sp!, {r5} #endif bl rt_interrupt_enter