2009-08-17 09:34 AM
Returning from nested exceptions.
2011-05-17 04:20 AM
Hi!
I just ran into a small problem - at the end of an exception handler, I have to decide whether to return using the process stack or the main stack. I also need to select handler mode or thread mode. So far, in my kernel, I only have an SVC handler, so I will always return to thread mode and process stack. However when supporting nested interrupts I need to keep track myself if there are any lower-priority exceptions pending to know how to return. So I need to maintain a counter of nested exceptions. Is this the way it should be or have I misunderstood something? Best Regards and TIA, Marcus2011-05-17 04:20 AM
The common simple case is simple. All exceptions and interrupts return to whatever was interrupted. A normal bx lr or C/C++ subroutine return always works. No special s/w games are required. Nested interrupts et al work just fine.
However, if you need to return elsewhere you need to set SP such that r0-r3 & r12, lr, pc & xPSW are restored. Set r5-11 if needed. Then set lr=FFFFFF?? then bx lr. Set ?? for the stack and protection mode you need. (You may set any r0-r12 to the magic value and bx the magic value register.)2011-05-17 04:20 AM
Some good example on SVC, PENDV and working with EXEC return values can be found in the freeRTOS port for the cortex. More particular in the file port.c
Perhaps you can take look into to brighten you idea's. Guy2011-05-17 04:20 AM
Apparently, I did not read the Exception Return chapter of the Architecture Reference Manual carefully enough; back to school! ;) Thanks to both of you. I'll also take a look at the FreeRTOS port.
EDIT: I see now how the LR register is set properly by the PushStack operation during the exception extry. From there it is clear that a bx lr will cut it! [ This message was edited by: marcus.johansson on 17-08-2009 22:08 ]