cancel
Showing results for 
Search instead for 
Did you mean: 

Returning from nested exceptions.

marcus2399
Associate II
Posted on August 17, 2009 at 18:34

Returning from nested exceptions.

4 REPLIES 4
marcus2399
Associate II
Posted on May 17, 2011 at 13:20

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,

Marcus

picguy
Associate II
Posted on May 17, 2011 at 13:20

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.)

guyvo67
Associate II
Posted on May 17, 2011 at 13:20

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

http://www.freertos.org/

Perhaps you can take look into to brighten you idea's.

Guy

marcus2399
Associate II
Posted on May 17, 2011 at 13:20

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 ]