unicorn icon indicating copy to clipboard operation
unicorn copied to clipboard

arm: Add missing hflag update after writing xpsr

Open wuetj opened this issue 3 months ago • 0 comments

This adds a missing hflag update after updating the xpsr. Currently when using an Arm Cortex-M CPU, which does not feature ARM_FEATURE_M_SECURITY, the EXC_RETURN interrupt is not triggered. After some debugging it turns out the v7m_handler_mode condition here is never true: https://github.com/unicorn-engine/unicorn/blob/c24c9ebe773ce6fbecb0e39f68ffb23b7326b17f/qemu/target/arm/translate.c#L827-L830 v7m_handler_mode is evaluated based on the HANDLER flag which is set when rebuilding hflags: https://github.com/unicorn-engine/unicorn/blob/c24c9ebe773ce6fbecb0e39f68ffb23b7326b17f/qemu/target/arm/helper.c#L11592-L11594 Since setting IPSR using uc_reg_write does not rebuild hflags, qemu doesn't realize that it's currently in an exception and returning from an exception causes a hard fault. This fixes this by rebuilding hflags after updating xPSR. This doesn't matter for processors with the security feature since the condition is always true in that case. I've updated the test to catch this.

wuetj avatar Nov 26 '25 20:11 wuetj