unwind.s : Since I have tested the gcc, I was unable to find the way of handling exception in C++. After some searches I discovered that the unwind function has not been wrote for our machine. So, here it is : When unwind is called, the stack is in this state +--------------------------------------------------+ 0 |return address of the exception calling function | +--------------------------------------------------+ 4 |address of the catch routine | +--------------------------------------------------+ 8 And A5 points on the following (the stack will go there when UNLK A5 will be performed) : +--------------------------------------------------+ 0 |return address of the previous routine | +--------------------------------------------------+ 4 the goal is to return from the previous function. For example : A() -> B() -> unwind() the exception occurs in B() but since unwind() is called, unwind should not return to B() but to A() which is the previous function. Also, the return address is not the same than if B() performs normally but the address of the catch routine in A(). when the B() function has been called the normal code is : link A5,count ; A5 is the previous SP and SP now points on the parameters ... code unlk A5 ; SP is restored to the A5 address rts XDEF ___unwind_function ___unwind_function: move.l (A7)+,A0 ; pop the B() return address into A0 (trash) move.l (A7)+,A1 ; pop the catch address into A1 (keep) unlk A5 ; restore the stack like when we entered into B() move.l (A7)+,A0 ; pop the A() return address into A0 (trash) move.l A1,-(A7) ; push the A() catch address into the stack RTS ; Go to the catch routine To try this I have created a small project with a simple script file named compile, use the -S option if you want to see what is going inside. Since the GNU optimizer plays a lot with the stack, I have been unable to make an unwind.cc file instead of unwind.s. Author: Dominique Lorre Le Fabary, Bât C 4 Allée des Peupliers 13100 Aix-en-Provence FRANCE Distribution: Under the GNU Library General Public License joined in the archive. Since unwind.s is intended to be a part of G++, I have considered that this was the correct form of distribution. unwind.s -- exceptions handling for g++ Copyright © 1996 Dominique Lorre This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.