cancel
Showing results for 
Search instead for 
Did you mean: 

How do I properly exit from the fault handler?

KMaen
Associate III

I am currently using STM32F746. I am trying to exit from a MemManage fault handler back to the instruction which triggered the fault (I am trying something hacky that properly resolves the cause of the fault inside the handler so going back to the original program point makes sense).

When entering the handler, the previous context (e.g., PC, CPSR..) are saved in the stack so I thought restoring those would make me go back to the original point.

However, I cannot properly restore the xPSR, and I think because of that things are not working as expected. I tried something like "MSR apsr, r12" and "MSR xpsr, r12", but instead of fully restoring the xPSR, it seems like it is only restoring the flags of the xPSR (and not the GE and the mode bits).

Also what is weird is that my xPSR inside the handler looks something like 0x610e0004, which does not make sense to me. I thought the last five bit should be in the form of 1xxxx in binary, from https://heyrick.eu/armwiki/The_Status_register.

Why is the last five bits 00100, which seems invalid to me, and how can I restore the xPSR properly to go back to the previous execution state?

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
turboscrew
Senior III

I vaguely recall that ARM knows how to return. You just need to fix the problem and return from exception.

The return code in LR tells where to find the stack frame (on which stack), and in which mode to return to.

View solution in original post

4 REPLIES 4
turboscrew
Senior III

I vaguely recall that ARM knows how to return. You just need to fix the problem and return from exception.

The return code in LR tells where to find the stack frame (on which stack), and in which mode to return to.

KMaen
Associate III

I found from a document (http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/Babefdjc.html) that what you said is true. However, weirdly when I try to "bx lr" with lr holding the EXC_RETURN such as 0xfffffff9, the GDB complains "Cannot access memory at address 0xfffffff9" and halts. I am not sure if it is my GDB or if my CPU is actually trying to jump to that weird address instead of restoring the context. Any ideas of how can this be resolved?

I found from a document (http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/Babefdjc.html) that what you said is true. However, weirdly when I try to "bx lr" with lr holding the EXC_RETURN such as 0xfffffff9, the GDB complains "Cannot access memory at address 0xfffffff9" and halts. I am not sure if it is my GDB or if my CPU is actually trying to jump to that weird address instead of restoring the context. Any ideas of how can this be resolved?

KMaen
Associate III

I think this was an issue with the GDB. Without GDB it worked.