1 // -*- C++ -*- ARM specific Exception handling support routines.
2 // Copyright (C) 2004, 2005, 2008, 2009, 2010, 2011
3 // Free Software Foundation, Inc.
5 // This file is part of GCC.
7 // GCC is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3, or (at your option)
12 // GCC is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
27 #include "unwind-cxx.h"
29 #ifdef __ARM_EABI_UNWINDER__
31 using namespace __cxxabiv1
;
34 // Given the thrown type THROW_TYPE, exception object UE_HEADER and a
35 // type CATCH_TYPE to compare against, return whether or not there is
36 // a match and if so, update *THROWN_PTR_P to point to either the
37 // type-matched object, or in the case of a pointer type, the object
38 // pointed to by the pointer.
40 extern "C" __cxa_type_match_result
41 __cxa_type_match(_Unwind_Exception
* ue_header
,
42 const std::type_info
* catch_type
,
43 bool is_reference
__attribute__((__unused__
)),
47 = __is_gxx_forced_unwind_class(ue_header
->exception_class
);
48 bool foreign_exception
49 = !forced_unwind
&& !__is_gxx_exception_class(ue_header
->exception_class
);
50 bool dependent_exception
51 = __is_dependent_exception(ue_header
->exception_class
);
52 __cxa_exception
* xh
= __get_exception_header_from_ue(ue_header
);
53 __cxa_dependent_exception
*dx
= __get_dependent_exception_from_ue(ue_header
);
54 const std::type_info
* throw_type
;
58 throw_type
= &typeid(abi::__forced_unwind
);
59 else if (foreign_exception
)
60 throw_type
= &typeid(abi::__foreign_exception
);
63 if (dependent_exception
)
64 xh
= __get_exception_header_from_obj (dx
->primaryException
);
65 throw_type
= xh
->exceptionType
;
66 // We used to require the caller set the target of thrown_ptr_p,
67 // but that's incorrect -- the EHABI makes no such requirement
68 // -- and not all callers will set it. Fortunately callers that
69 // do initialize will always pass us the value we calculate
70 // here, so there's no backwards compatibility problem.
71 thrown_ptr
= __get_object_from_ue (ue_header
);
74 __cxa_type_match_result result
= ctm_succeeded
;
76 // Pointer types need to adjust the actual pointer, not
77 // the pointer to pointer that is the exception object.
78 // This also has the effect of passing pointer types
79 // "by value" through the __cxa_begin_catch return value.
80 if (throw_type
->__is_pointer_p())
82 thrown_ptr
= *(void**) thrown_ptr
;
83 // We need to indicate the indirection to our caller.
84 result
= ctm_succeeded_with_ptr_to_base
;
87 if (catch_type
->__do_catch(throw_type
, &thrown_ptr
, 1))
89 *thrown_ptr_p
= thrown_ptr
;
96 // ABI defined routine called at the start of a cleanup handler.
98 __cxa_begin_cleanup(_Unwind_Exception
* ue_header
)
100 __cxa_eh_globals
*globals
= __cxa_get_globals();
101 __cxa_exception
*header
= __get_exception_header_from_ue(ue_header
);
102 bool native
= __is_gxx_exception_class(header
->unwindHeader
.exception_class
);
107 header
->propagationCount
++;
108 // Add it to the chain if this is the first time we've seen this
110 if (header
->propagationCount
== 1)
112 header
->nextPropagatingException
= globals
->propagatingExceptions
;
113 globals
->propagatingExceptions
= header
;
118 // Remember the exception object, so end_cleanup can return it.
119 // These cannot be stacked, so we must abort if we already have
120 // a propagating exception.
121 if (globals
->propagatingExceptions
)
123 globals
->propagatingExceptions
= header
;
129 // Do the work for __cxa_end_cleanup. Returns the currently propagating
131 extern "C" _Unwind_Exception
*
132 __gnu_end_cleanup(void)
134 __cxa_exception
*header
;
135 __cxa_eh_globals
*globals
= __cxa_get_globals();
137 header
= globals
->propagatingExceptions
;
139 // Check something hasn't gone horribly wrong.
143 if (__is_gxx_exception_class(header
->unwindHeader
.exception_class
))
145 header
->propagationCount
--;
146 if (header
->propagationCount
== 0)
148 // Remove exception from chain.
149 globals
->propagatingExceptions
= header
->nextPropagatingException
;
150 header
->nextPropagatingException
= NULL
;
154 globals
->propagatingExceptions
= NULL
;
156 return &header
->unwindHeader
;
160 // Assembly wrapper to call __gnu_end_cleanup without clobbering
161 // function arguments to _Unwind_Resume.
162 asm (".global __cxa_end_cleanup\n"
163 " .type __cxa_end_cleanup, \"function\"\n"
164 "__cxa_end_cleanup:\n"
165 " stw .d2t2 B9, *B15--[10]\n"
166 " stw .d2t2 B8, *+B15[9]\n"
167 " stw .d2t2 B7, *+B15[8]\n"
168 " stw .d2t2 B6, *+B15[7]\n"
169 " stw .d2t2 B5, *+B15[6]\n"
170 " stw .d2t2 B4, *+B15[5]\n"
171 " stw .d2t1 A9, *+B15[4]\n"
172 " stw .d2t1 A8, *+B15[3]\n"
173 " stw .d2t1 A7, *+B15[2]\n"
174 " stw .d2t1 A6, *+B15[1]\n"
175 #ifdef _TMS320C6400_PLUS
176 " callp .s2 (__gnu_end_cleanup), B3\n"
177 #elif defined(_TMS320C6400)
178 " call .s2 (__gnu_end_cleanup)\n"
179 " addkpc .s2 1f, B3, 0\n"
183 " call .s2 (__gnu_end_cleanup)\n"
189 " ldw .d2t1 *+B15[1], A6\n"
190 " ldw .d2t1 *+B15[2], A7\n"
191 " ldw .d2t1 *+B15[3], A8\n"
192 " ldw .d2t1 *+B15[4], A9\n"
193 " ldw .d2t2 *+B15[5], B4\n"
194 " ldw .d2t2 *+B15[6], B5\n"
195 " ldw .d2t2 *+B15[7], B6\n"
196 " ldw .d2t2 *+B15[8], B7\n"
197 " ldw .d2t2 *+B15[9], B8\n"
198 " ldw .d2t2 *++B15[10], B9\n"
199 " b .s2 _Unwind_Resume\n"
202 // Assembly wrapper to call __gnu_end_cleanup without clobbering r1-r3.
203 // Also push r4 to preserve stack alignment.
205 asm (" .pushsection .text.__cxa_end_cleanup\n"
206 " .global __cxa_end_cleanup\n"
207 " .type __cxa_end_cleanup, \"function\"\n"
209 "__cxa_end_cleanup:\n"
210 " push\t{r1, r2, r3, r4}\n"
211 " bl\t__gnu_end_cleanup\n"
212 " pop\t{r1, r2, r3, r4}\n"
213 " bl\t_Unwind_Resume @ Never returns\n"
216 asm (" .pushsection .text.__cxa_end_cleanup\n"
217 " .global __cxa_end_cleanup\n"
218 " .type __cxa_end_cleanup, \"function\"\n"
219 "__cxa_end_cleanup:\n"
220 " stmfd\tsp!, {r1, r2, r3, r4}\n"
221 " bl\t__gnu_end_cleanup\n"
222 " ldmfd\tsp!, {r1, r2, r3, r4}\n"
223 " bl\t_Unwind_Resume @ Never returns\n"