Skip to content

Cortex-M cores: pendSV handler need to modify the auto stacked XPSR value to clear LDM/STM progress #3842

@RockySong

Description

@RockySong

If pendSV is serviced during an LDM/STM instruction, which is interruptible and uses XPSR "ICI/IT" bitfield to save load/store progress, it may causes INVSTATE type hardfault when CPU finally returns to nlr_jump().
This is because on exception return, the Cortex-M core is expecting to resume LDM/STM when it sees the valid progress information in unstacked ICI/IT field of XPSR register
However, pendSV returns to nlr_jump(). So there is no LDM/STM instruction and the Cortex-M CPU generates hardfault with INVSTATE.
My workaround, insert below instructions in the beginning of PendSV_Handler:
"mov r2, #0x01000000 \n"
"str r2, [sp, #28] \n" // modify stacked XPSR to make sure possible LDM/STM progress is cleared

So when nlr_jump() is entered, it always has XPSR unstacked to a "clean" state.

Note: This may have something to do with the INVSTATE hardfault found in openMV project.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy