I got a design problem in the code which I need to solve, and thought I could get nice ideas here.
Each task in the OS has its own dedicated stack. (The OS was internally written here).
When a failure occur in any of the tasks, the task calls an Error Handler Function which handles the error.
The problem is that the Error Handler Function uses ~1KB due to local variables, and therefore it causes a stack overflow to the stack of the Task which called the Error Handler function.
Increasing the size of each Task's Stack is not something that can be afforded.
How would you handle this situation?
I thought of dedicating the Error Handler Function its own stack.
But perhaps something in the flow should be changed?
The routine that handles death situations must understand that the death may have happened because of limited resources, therefore it needs all the memory pre-allocated when OS starts.
You need to take few steps back and redesign the software.. at least the error handling. And why are there "unexpected" case values? Sounds like a really poorly designed software.
Maybe you need an error handler for your error handler.. haha. (seriously don't do that)
I cannot comment on the asm because I don't know what the processor is.
If you have an exception handling routine, you do not want to return stack back to where it was. If it happened as a part of structured exception handling, such as try/catch, the handling function should unroll the stack and jump to the "catch" part. If not, it is supposed to kill the process and thereby destroy the stack.