This is called in USER mode whenever OS_Exit or OS_ExitAndDie is called. It should restore all handlers to their previous values and then call OS_Exit to pass to the previous handler.
R13 may be undefined, either avoid the use of R13 in the handler or provide your own stack space.