2 * ARM-specific unwind definitions. These are taken from the ARM EHABI
7 _URC_OK = 0, /* operation completed successfully */
8 _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
10 _URC_HANDLER_FOUND = 6,
11 _URC_INSTALL_CONTEXT = 7,
12 _URC_CONTINUE_UNWIND = 8,
13 _URC_FAILURE = 9, /* unspecified failure of some kind */
14 _URC_FATAL_PHASE1_ERROR = _URC_FAILURE
15 } _Unwind_Reason_Code;
17 typedef uint32_t _Unwind_State;
19 static const _Unwind_State _US_VIRTUAL_UNWIND_FRAME = 0;
20 static const _Unwind_State _US_UNWIND_FRAME_STARTING = 1;
21 static const _Unwind_State _US_UNWIND_FRAME_RESUME = 2;
22 #else // GCC fails at knowing what a constant expression is
23 # define _US_VIRTUAL_UNWIND_FRAME 0
24 # define _US_UNWIND_FRAME_STARTING 1
25 # define _US_UNWIND_FRAME_RESUME 2
28 typedef struct _Unwind_Context _Unwind_Context;
30 typedef uint32_t _Unwind_EHT_Header;
32 struct _Unwind_Exception
34 uint64_t exception_class;
35 void (*exception_cleanup)(_Unwind_Reason_Code, struct _Unwind_Exception *);
36 /* Unwinder cache, private fields for the unwinder's use */
44 /* init reserved1 to 0, then don't touch */
46 /* Propagation barrier cache (valid after phase 1): */
50 uint32_t bitpattern[5];
52 /* Cleanup cache (preserved over cleanup): */
55 uint32_t bitpattern[4];
57 /* Pr cache (for pr's benefit): */
60 /** function start address */
62 /** pointer to EHT entry header word */
63 _Unwind_EHT_Header *ehtp;
64 /** additional data */
68 /** Force alignment of next item to 8-byte boundary */
72 /* Unwinding functions */
73 _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *ucbp);
74 void _Unwind_Resume(struct _Unwind_Exception *ucbp);
75 void _Unwind_Complete(struct _Unwind_Exception *ucbp);
76 void _Unwind_DeleteException(struct _Unwind_Exception *ucbp);
77 void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context*);
82 _UVRSR_NOT_IMPLEMENTED = 1,
91 } _Unwind_VRS_RegClass;
99 } _Unwind_VRS_DataRepresentation;
101 _Unwind_VRS_Result _Unwind_VRS_Get(_Unwind_Context *context,
102 _Unwind_VRS_RegClass regclass,
104 _Unwind_VRS_DataRepresentation representation,
106 _Unwind_VRS_Result _Unwind_VRS_Set(_Unwind_Context *context,
107 _Unwind_VRS_RegClass regclass,
109 _Unwind_VRS_DataRepresentation representation,
112 /* Return the base-address for data references. */
113 extern unsigned long _Unwind_GetDataRelBase(struct _Unwind_Context *);
115 /* Return the base-address for text references. */
116 extern unsigned long _Unwind_GetTextRelBase(struct _Unwind_Context *);
117 extern unsigned long _Unwind_GetRegionStart(struct _Unwind_Context *);
119 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *,
121 extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
122 extern _Unwind_Reason_Code
123 _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
126 * The next set of functions are compatibility extensions, implementing Itanium
127 * ABI functions on top of ARM ones.
130 #define _UA_SEARCH_PHASE 1
131 #define _UA_CLEANUP_PHASE 2
132 #define _UA_HANDLER_FRAME 4
133 #define _UA_FORCE_UNWIND 8
135 static inline unsigned long _Unwind_GetGR(struct _Unwind_Context *context, int reg)
138 _Unwind_VRS_Get(context, _UVRSC_CORE, reg, _UVRSD_UINT32, &val);
141 static inline void _Unwind_SetGR(struct _Unwind_Context *context, int reg, unsigned long val)
143 _Unwind_VRS_Set(context, _UVRSC_CORE, reg, _UVRSD_UINT32, &val);
145 static inline unsigned long _Unwind_GetIP(_Unwind_Context *context)
147 // Low bit store the thumb state - discard it
148 return _Unwind_GetGR(context, 15) & ~1;
150 static inline void _Unwind_SetIP(_Unwind_Context *context, unsigned long val)
152 // The lowest bit of the instruction pointer indicates whether we're in
153 // thumb or ARM mode. This is assumed to be fixed throughout a function,
154 // so must be propagated when setting the program counter.
155 unsigned long thumbState = _Unwind_GetGR(context, 15) & 1;
156 _Unwind_SetGR(context, 15, (val | thumbState));
159 /** GNU API function that unwinds the frame */
160 _Unwind_Reason_Code __gnu_unwind_frame(struct _Unwind_Exception*, struct _Unwind_Context*);
163 #define DECLARE_PERSONALITY_FUNCTION(name) \
164 _Unwind_Reason_Code name(_Unwind_State state,\
165 struct _Unwind_Exception *exceptionObject,\
166 struct _Unwind_Context *context);
168 #define BEGIN_PERSONALITY_FUNCTION(name) \
169 _Unwind_Reason_Code name(_Unwind_State state,\
170 struct _Unwind_Exception *exceptionObject,\
171 struct _Unwind_Context *context)\
174 uint64_t exceptionClass = exceptionObject->exception_class;\
178 default: return _URC_FAILURE;\
179 case _US_VIRTUAL_UNWIND_FRAME:\
181 actions = _UA_SEARCH_PHASE;\
184 case _US_UNWIND_FRAME_STARTING:\
186 actions = _UA_CLEANUP_PHASE;\
187 if (exceptionObject->barrier_cache.sp == _Unwind_GetGR(context, 13))\
189 actions |= _UA_HANDLER_FRAME;\
193 case _US_UNWIND_FRAME_RESUME:\
195 return continueUnwinding(exceptionObject, context);\
199 _Unwind_SetGR (context, 12, (unsigned long)exceptionObject);\
201 #define CALL_PERSONALITY_FUNCTION(name) name(state,exceptionObject,context)