xiaoxiang781216 commented on PR #19123: URL: https://github.com/apache/nuttx/pull/19123#issuecomment-4686236979
> ## Summary > On ARMv7-M and ARMv8-M, the exception return path in `arm_exception.S` writes PSP/MSP from the HW exception frame pointer (`r0`), ignoring any software modification to `REG_R13` in the saved register context. This means signal handlers that adjust SP (e.g., a managed runtime unwinding past a trampoline frame) have their SP change silently discarded. > > **Root cause:** Hardware determines the final SP from the physical location of the HW exception frame (`PSP + frame_size`), not from the software-saved SP value. The existing code does `msr psp, r0` where `r0` points to the HW frame, so the restored SP is always `r0 + frame_size` regardless of what `regs[REG_R13]` says. > could you point out POSIX spec which describe this behavior? > **Fix:** Add optional HW frame relocation (`CONFIG_ARMV7M_SP_CONTEXT_RESTORE` / `CONFIG_ARMV8M_SP_CONTEXT_RESTORE`, both default `n`) that compares the desired SP with the implied SP. If they differ, the HW exception frame is copied to `(desired_SP - frame_size)` so hardware exception return produces the correct final SP. > the interrupt handle becomes much slow when enabling CONFIG_ARMVxM_SP_CONTEXT_RESTORE. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
