If a stack overflow trap occures, I would like the controller to:
开发者_StackOverflow社区- send a message to inform the user that a stack overflow occured
- do a reset when the message has been sent
I wonder if it is a good idea to reset the Stack Pointer before starting this exception handling to be sure that the procedure will be done without messing up memory or is there a better way to handle this exception?
The stack overflow exception doesn't mean anything is wrong yet as far as I recall from my days programming the early C167s (from which the xe166 comes I think). It just means you are right at the end of the stack. Indeed with sufficient jiggery pokery you can use the stack overflow and stack underflow exceptions to "page" a larger stack in and out of main memory!
So, if you can assure yourself that the exception handler needs no further stack then you could get away without resetting the SP. You're likely to be calling some functions from it though I imagine, in which case having some free stack space might be useful :)
Your comment regarding "messed up stack" is not quite the issue - once the stack pointer has reached the end, any further stack usage messes up other things which may be data your exception code is going to rely on. It sounds like you must guarantee a reset takes place, but it you start clobbering memory with an errant SP, you can't predict what might happen.
So, if it's a remotely critical system, find a way to afford the memory for an "emergency stack" then point the SP to that before proceeding with your exception handler.
精彩评论