New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARM Cortex-M4 stack offset when not using Floating point register sharing #22977
Comments
@PierreAronnax Thanks for providing a detailed analysis on the problem. Since you have already provided a workable solution, would you be willing to open a pull request for the fix? or do you want the maintainers to do it?
cc @ioannisg |
Thanks for the bug report, @PierreAronnax , I 'll take a look as soon as possible. Yeap, feel free to open a bug-fix PR as well. |
@stephanosio @ioannisg |
Hi @PierreAronnax , first, thanks again for the investigation, here. I believe we, eventually, need to make sure the Zephyr boot sequence needs to initialize all core Cortex-M components, we should perhaps open an issue for that. In the mean time, I am going to take a look at your PR and see if we can fix (at least) the issue you report here for v2.2.0 release. |
BTW, this is not only applicable to Cortex-M4, but also to every Cortex-M with FP extension |
Upon reset, the CONTROL.FPCA bit is, normally, cleared. However, it might be left un-cleared by firmware running before Zephyr boot, for example when Zephyr image is loaded by another image. We must clear this bit to prevent errors in exception unstacking. This caused stack offset when booting from a build-in EFM32GG bootloader Fixes zephyrproject-rtos#22977 Signed-off-by: Luuk Bosma <l.bosma@interay.com>
Upon reset, the CONTROL.FPCA bit is, normally, cleared. However, it might be left un-cleared by firmware running before Zephyr boot, for example when Zephyr image is loaded by another image. We must clear this bit to prevent errors in exception unstacking. This caused stack offset when booting from a build-in EFM32GG bootloader Fixes #22977 Signed-off-by: Luuk Bosma <l.bosma@interay.com>
Upon reset, the CONTROL.FPCA bit is, normally, cleared. However, it might be left un-cleared by firmware running before Zephyr boot, for example when Zephyr image is loaded by another image. We must clear this bit to prevent errors in exception unstacking. This caused stack offset when booting from a build-in EFM32GG bootloader Fixes zephyrproject-rtos#22977 Signed-off-by: Luuk Bosma <l.bosma@interay.com>
Describe the bug
While developing a project based on the EFM32GG11B420F2048 using Zephyr RTOS we frequently noticed instability of our applications, usually resulting in 'usage faults'. The instability however was only occurring when booting the application via the build-in UART bootloader. Running the same binary from Eclipse using a debugger did not show the problem.
After investigation we discovered that the current stack pointer of all our threads were outside the allocated stack area immediately when entering the thread.
We have found the cause of this issue: floating-point context is active and Zephyr does not disables it.
Our project does not have CONFIG_FLOAT set, and therefore Zephyr does not initialize the Floating Point Status and Control Register. But it also doesn’t de-initialize these registers, leaving them unchanged. The build-in UART bootloader seems to initialize these registers before Zephyr is running.
After booting without the bootloader the CONTROL register has a value of 2, while after booting from the bootloader the CONTROL register has a value of 6.
CONTROL register bit 2 FPCA is set. Clearing this bit fixes this issue.
CONTROL register
To Reproduce
main.c
prj.conf
west build -b efm32gg_stk3701a application/name
west flash
When you don't have this board or don't have this bootloader, simulate the bug by changing arch/arm/core/prep_c.c line 140 into
Console output:
Observe that 308 is outside 256.
Expected behavior
Console output:
Observe that 236 is inside 256.
Impact
Showstopper as every application crashes when we don't erase the bootloader or don't use the debugger.
Environment
Additional context
I believe this issue is not only limit to my processor but impacts every ARM with a FPU.
As a workarround use the following prj.conf
As this clears the flag in arch_switch_to_main_thread
Or change arch/arm/core/prep_c.c line 140 into
But that probably needs more processor checks and register de-initialization.
The text was updated successfully, but these errors were encountered: