Hi,
I'm trying to implement a context switcher for the Cortex M4F using SysTick and PenSV. On loading a new task and returning from an exceptions, I need to set the EXC_RETURN value based on whether or not the loaded task had a FPU stack frame.
The problem is, on entry the compiler automatically pushes registers R4 and LR onto the stack and pop them out on exit. Additionally, if I declare other non-static local variables within the exception, more registers are also pushed onto the stack on exception entry and popped on exit.
Since EXC_RETURN, initially stored in LR register, now need to be retrieved from the stack at exception exit rather than from the LR register, this causes the problem: in order to modify EXC_RETURN during the exception, I need to change it at its stack location, but since an unknown number of registers could be pushed onto the stack after it on exception entry, I can't known for sure its offset from the latest stack pointer location.
So far the only solution I came up with is to look at generated code, count the number of registers pushed onto the stack after EXC_RETURN and offset the pointer accordingly, but this method can break easily if code within the exception is changed and different number of registers are pushed onto the stack after EXC_RETURN
Any help would be greatly appreciated
Thanks!
I'm trying to do something similar, in effect. But I am trying to force the processor out of handler mode without a return from the interrupt involving EXC_RETURN. In other words, I want the processor to handle an interrupt, but during the interrupt I need a mechanism to return the processor back to a normal state where all interrupts can be handled as if no interrupt is currently being handled.
Sorry if this is a little off topic, but I have not found much information about this online or in documentation.