nuttx/arch/arm/src
xuxingliang cdd8032cb9 arch/armv8-m: Fix IRQ number corruption in exception_direct with O2 optimization
When compiling with O2 optimization, the compiler optimizes the code
in a way that causes irq variable to be corrupted. The getipsr()
function reads IPSR into r0, but the subsequent inline assembly that
sets FPSCR also uses r0 without declaring it as clobbered. This causes
the compiler to reuse r0 for the immediate value (0x40000), overwriting
the IRQ number read from IPSR.

The issue manifests as:
- getipsr() correctly reads IPSR (e.g., 0xf for IRQ 15)
- Compiler optimizes and reuses r0 for ARM_FPSCR_LTPSIZE_NONE (0x40000)
- irq variable gets the wrong value 0x40000 instead of actual IRQ number
- This leads to assertion failures in irq_dispatch due to invalid IRQ

Root cause analysis from disassembly:
  mrs r0, IPSR          ; Read IPSR to r0
  mov.w r0, #262144     ; Compiler overwrites r0 with 0x40000!
  vmsr fpscr, r0        ; Set FPSCR
  str r0, [sp, #4]      ; Store corrupted 0x40000 as irq
  ...
  ldr r0, [sp, #4]      ; Load corrupted value
  bl irq_dispatch       ; Call with wrong IRQ number 0x40000

Fix by adding r0 to the clobber list in the inline assembly, which
forces the compiler to save irq value before using r0 for FPSCR setup.

This issue only occurs at O2 optimization level and affects ARMv8-M
architecture with FPU enabled.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-12-29 19:15:21 +08:00
..
a1x arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
am335x arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
arm arm: replace all nxsched_suspend/resume_*** with nxsched_switch_context 2025-09-25 16:40:23 +08:00
armv6-m armv-m/syscall:use cfi to debug syscall 2025-12-24 09:49:52 +08:00
armv7-a arch/arm: Fix the arm timer's maximum delay to be a 64-bit integer. 2025-11-24 19:43:07 +08:00
armv7-m armv-m/syscall:use cfi to debug syscall 2025-12-24 09:49:52 +08:00
armv7-r arch/arm: Fix the arm timer's maximum delay to be a 64-bit integer. 2025-11-24 19:43:07 +08:00
armv8-m arch/armv8-m: Fix IRQ number corruption in exception_direct with O2 optimization 2025-12-29 19:15:21 +08:00
armv8-r arch/armv8-r: use -mfpu=fpv5-sp-d16 for SP-only Cortex-R52 targets 2025-12-08 21:09:05 +08:00
at32 sched/sleep: replace all Signal-based sleep implement to Scheduled sleep 2025-10-17 14:05:02 +08:00
c5471 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
cmake arch/armv8-r: use -mfpu=fpv5-sp-d16 for SP-only Cortex-R52 targets 2025-12-08 21:09:05 +08:00
common armv-m/syscall:use cfi to debug syscall 2025-12-24 09:49:52 +08:00
csk6 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
cxd32xx arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
cxd56xx arch: cxd56xx: Fix failure to get RTC time in multi-core environment 2025-11-20 20:56:05 +08:00
dm320 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
efm32 sched/sleep: replace all Signal-based sleep implement to Scheduled sleep 2025-10-17 14:05:02 +08:00
eoss3 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
fvp-v8r-aarch32
gd32f4 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
goldfish arch/arm: Simplify arm_cpu_boot. 2025-11-17 10:25:37 +08:00
imx1 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
imx6 arch/arm: Simplify arm_cpu_boot. 2025-11-17 10:25:37 +08:00
imx9 arm/imx9: Replace spinlock/sched_lock with spin_lock_irqsave_nopreempt 2025-11-04 22:46:15 +08:00
imxrt sched/sched: Remove nxsched_alarm_expiration 2025-12-22 21:17:13 +08:00
kinetis arm/kinetis: Fix warning 2025-12-10 11:40:36 +01:00
kl arch/arm/src/kl: CMake build implemented for NXP KL Series Arm MCUs 2025-12-02 02:42:55 +08:00
lc823450 arm/lc823450: Use clock_systime_ticks() to access system ticks 2025-11-13 18:40:16 -03:00
lpc17xx_40xx sched/sleep: replace all Signal-based sleep implement to Scheduled sleep 2025-10-17 14:05:02 +08:00
lpc31xx sched/sleep: replace all Signal-based sleep implement to Scheduled sleep 2025-10-17 14:05:02 +08:00
lpc43xx sched/sched: Remove nxsched_alarm_expiration 2025-12-22 21:17:13 +08:00
lpc54xx sched/sched: Remove nxsched_alarm_expiration 2025-12-22 21:17:13 +08:00
lpc214x arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
lpc2378 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
max326xx arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
mcx-nxxx arch/arm/src/mcx-nxxx/CMakeLists.txt: Aligned Cmake with Make 2025-06-03 10:07:39 -03:00
moxart arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
mps mps3-an547:support protect mode 2025-12-18 22:19:44 +08:00
mx8mp sched/sleep: replace all Signal-based sleep implement to Scheduled sleep 2025-10-17 14:05:02 +08:00
nrf52 sched/sched: Remove nxsched_alarm_expiration 2025-12-22 21:17:13 +08:00
nrf53 sched/sched: Remove nxsched_alarm_expiration 2025-12-22 21:17:13 +08:00
nrf91 sched/sched: Remove nxsched_alarm_expiration 2025-12-22 21:17:13 +08:00
nuc1xx arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
phy62xx arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
qemu arch/arm: Simplify arm_cpu_boot. 2025-11-17 10:25:37 +08:00
ra4 arch/ra4: Add PWM driver support for RA4M1 2025-11-17 09:01:31 -03:00
rp23xx rp2040,rp23xx,rp23xx-rv: allow up to 32 PIO instructions 2025-12-15 18:01:27 +01:00
rp2040 rp2040,rp23xx,rp23xx-rv: allow up to 32 PIO instructions 2025-12-15 18:01:27 +01:00
rtl8720c sched/sleep: replace all Signal-based sleep implement to Scheduled sleep 2025-10-17 14:05:02 +08:00
s32k1xx arm/s32k1xx: Replace spinlock/sched_lock with spin_lock_irqsave_nopreempt 2025-11-04 22:46:15 +08:00
s32k3xx arm/s32k3xx: Replace spinlock/sched_lock with spin_lock_irqsave_nopreempt 2025-11-04 22:46:15 +08:00
sam34 timers/oneshot: Remove all callback and args. 2025-11-18 13:02:29 +01:00
sama5 timers/oneshot: Remove all callback and args. 2025-11-18 13:02:29 +01:00
samd2l2 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
samd5e5 timers/oneshot: Remove all callback and args. 2025-11-18 13:02:29 +01:00
samv7 arch/arm/src/samv7/Kconfig: allow 0 in MCANx_RXFIFOx_SIZE 2025-12-04 16:32:39 +01:00
stm32 timers/oneshot: Remove all callback and args. 2025-11-18 13:02:29 +01:00
stm32f0l0g0 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
stm32f7 sched/sched: Remove nxsched_alarm_expiration 2025-12-22 21:17:13 +08:00
stm32h5 arch/arm/stm32h5: Add RS-485 support to serial driver 2025-12-06 11:35:53 -03:00
stm32h7 sched/sched: Remove nxsched_alarm_expiration 2025-12-22 21:17:13 +08:00
stm32l4 arch/arm/src/stm32l4: Removed repeated addition of CONFIG_STM32L4_IWDG 2025-12-03 08:36:06 +08:00
stm32l5 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
stm32u5 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
stm32wb timers/oneshot: Remove all callback and args. 2025-11-18 13:02:29 +01:00
stm32wl5 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
str71x arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
tiva sched/sleep: replace all Signal-based sleep implement to Scheduled sleep 2025-10-17 14:05:02 +08:00
tlsr82 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
tms570 arch/init: call up_color_intstack before up_irq_enable 2025-10-14 17:42:01 +08:00
xmc4 sched/sched: Remove nxsched_alarm_expiration 2025-12-22 21:17:13 +08:00
.gitignore
CMakeLists.txt
Makefile toolchain/arm: Fix link parameter error 2025-07-11 09:13:03 -03:00