1 /* Header file for the ARM EABI unwinder 2 Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 3 Contributed by Paul Brook 4 5 This file is free software; you can redistribute it and/or modify it 6 under the terms of the GNU General Public License as published by the 7 Free Software Foundation; either version 2, or (at your option) any 8 later version. 9 10 In addition to the permissions in the GNU General Public License, the 11 Free Software Foundation gives you unlimited permission to link the 12 compiled version of this file into combinations with other programs, 13 and to distribute those combinations without any restriction coming 14 from the use of this file. (The General Public License restrictions 15 do apply in other respects; for example, they cover modification of 16 the file, and distribution when not linked into a combine 17 executable.) 18 19 This file is distributed in the hope that it will be useful, but 20 WITHOUT ANY WARRANTY; without even the implied warranty of 21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 General Public License for more details. 23 24 You should have received a copy of the GNU General Public License 25 along with this program; see the file COPYING. If not, write to 26 the Free Software Foundation, 51 Franklin Street, Fifth Floor, 27 Boston, MA 02110-1301, USA. */ 28 29 /* Language-independent unwinder header public defines. This contains both 30 ABI defined objects, and GNU support routines. */ 31 32 #ifndef UNWIND_ARM_H 33 #define UNWIND_ARM_H 34 35 #define __ARM_EABI_UNWINDER__ 1 36 37 #ifndef __ARM_STATIC_INLINE 38 #define __ARM_STATIC_INLINE static inline 39 #endif 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 typedef unsigned _Unwind_Word __attribute__((__mode__(__word__))); 45 typedef signed _Unwind_Sword __attribute__((__mode__(__word__))); 46 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__))); 47 typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__))); 48 typedef _Unwind_Word _uw; 49 typedef unsigned _uw64 __attribute__((mode(__DI__))); 50 typedef unsigned _uw16 __attribute__((mode(__HI__))); 51 typedef unsigned _uw8 __attribute__((mode(__QI__))); 52 53 typedef enum 54 { 55 _URC_OK = 0, /* operation completed successfully */ 56 _URC_FOREIGN_EXCEPTION_CAUGHT = 1, 57 _URC_END_OF_STACK = 5, 58 _URC_HANDLER_FOUND = 6, 59 _URC_INSTALL_CONTEXT = 7, 60 _URC_CONTINUE_UNWIND = 8, 61 _URC_FAILURE = 9 /* unspecified failure of some kind */ 62 } 63 _Unwind_Reason_Code; 64 65 typedef enum 66 { 67 _US_VIRTUAL_UNWIND_FRAME = 0, 68 _US_UNWIND_FRAME_STARTING = 1, 69 _US_UNWIND_FRAME_RESUME = 2, 70 _US_ACTION_MASK = 3, 71 _US_FORCE_UNWIND = 8, 72 _US_END_OF_STACK = 16 73 } 74 _Unwind_State; 75 76 /* Provided only for for compatibility with existing code. */ 77 typedef int _Unwind_Action; 78 #define _UA_SEARCH_PHASE 1 79 #define _UA_CLEANUP_PHASE 2 80 #define _UA_HANDLER_FRAME 4 81 #define _UA_FORCE_UNWIND 8 82 #define _UA_END_OF_STACK 16 83 #define _URC_NO_REASON _URC_OK 84 85 typedef struct _Unwind_Control_Block _Unwind_Control_Block; 86 typedef struct _Unwind_Context _Unwind_Context; 87 typedef _uw _Unwind_EHT_Header; 88 89 90 /* UCB: */ 91 92 struct _Unwind_Control_Block 93 { 94 unsigned exception_class __attribute__((__mode__(__DI__))); 95 void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Control_Block *); 96 /* Unwinder cache, private fields for the unwinder's use */ 97 struct 98 { 99 _uw reserved1; /* Forced unwind stop fn, 0 if not forced */ 100 _uw reserved2; /* Personality routine address */ 101 _uw reserved3; /* Saved callsite address */ 102 _uw reserved4; /* Forced unwind stop arg */ 103 _uw reserved5; 104 } 105 unwinder_cache; 106 /* Propagation barrier cache (valid after phase 1): */ 107 struct 108 { 109 _uw sp; 110 _uw bitpattern[5]; 111 } 112 barrier_cache; 113 /* Cleanup cache (preserved over cleanup): */ 114 struct 115 { 116 _uw bitpattern[4]; 117 } 118 cleanup_cache; 119 /* Pr cache (for pr's benefit): */ 120 struct 121 { 122 _uw fnstart; /* function start address */ 123 _Unwind_EHT_Header *ehtp; /* pointer to EHT entry header word */ 124 _uw additional; /* additional data */ 125 _uw reserved1; 126 } 127 pr_cache; 128 long long int :0; /* Force alignment to 8-byte boundary */ 129 }; 130 131 /* Virtual Register Set*/ 132 133 typedef enum 134 { 135 _UVRSC_CORE = 0, /* integer register */ 136 _UVRSC_VFP = 1, /* vfp */ 137 _UVRSC_FPA = 2, /* fpa */ 138 _UVRSC_WMMXD = 3, /* Intel WMMX data register */ 139 _UVRSC_WMMXC = 4 /* Intel WMMX control register */ 140 } 141 _Unwind_VRS_RegClass; 142 143 typedef enum 144 { 145 _UVRSD_UINT32 = 0, 146 _UVRSD_VFPX = 1, 147 _UVRSD_FPAX = 2, 148 _UVRSD_UINT64 = 3, 149 _UVRSD_FLOAT = 4, 150 _UVRSD_DOUBLE = 5 151 } 152 _Unwind_VRS_DataRepresentation; 153 154 typedef enum 155 { 156 _UVRSR_OK = 0, 157 _UVRSR_NOT_IMPLEMENTED = 1, 158 _UVRSR_FAILED = 2 159 } 160 _Unwind_VRS_Result; 161 162 /* Frame unwinding state. */ 163 typedef struct 164 { 165 /* The current word (bytes packed msb first). */ 166 _uw data; 167 /* Pointer to the next word of data. */ 168 _uw *next; 169 /* The number of bytes left in this word. */ 170 _uw8 bytes_left; 171 /* The number of words pointed to by ptr. */ 172 _uw8 words_left; 173 } 174 __gnu_unwind_state; 175 176 typedef _Unwind_Reason_Code (*personality_routine) (_Unwind_State, 177 _Unwind_Control_Block *, _Unwind_Context *); 178 179 _Unwind_VRS_Result _Unwind_VRS_Set(_Unwind_Context *, _Unwind_VRS_RegClass, 180 _uw, _Unwind_VRS_DataRepresentation, 181 void *); 182 183 _Unwind_VRS_Result _Unwind_VRS_Get(_Unwind_Context *, _Unwind_VRS_RegClass, 184 _uw, _Unwind_VRS_DataRepresentation, 185 void *); 186 187 _Unwind_VRS_Result _Unwind_VRS_Pop(_Unwind_Context *, _Unwind_VRS_RegClass, 188 _uw, _Unwind_VRS_DataRepresentation); 189 190 191 /* Support functions for the PR. */ 192 #define _Unwind_Exception _Unwind_Control_Block 193 typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__))); 194 195 void * _Unwind_GetLanguageSpecificData (_Unwind_Context *); 196 _Unwind_Ptr _Unwind_GetRegionStart (_Unwind_Context *); 197 198 /* These two should never be used. */ 199 _Unwind_Ptr _Unwind_GetDataRelBase (_Unwind_Context *); 200 _Unwind_Ptr _Unwind_GetTextRelBase (_Unwind_Context *); 201 202 /* Interface functions: */ 203 _Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Control_Block *ucbp); 204 void __attribute__((noreturn)) _Unwind_Resume(_Unwind_Control_Block *ucbp); 205 _Unwind_Reason_Code _Unwind_Resume_or_Rethrow (_Unwind_Control_Block *ucbp); 206 207 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) 208 (int, _Unwind_Action, _Unwind_Exception_Class, 209 _Unwind_Control_Block *, struct _Unwind_Context *, void *); 210 _Unwind_Reason_Code _Unwind_ForcedUnwind (_Unwind_Control_Block *, 211 _Unwind_Stop_Fn, void *); 212 /* @@@ Use unwind data to perform a stack backtrace. The trace callback 213 is called for every stack frame in the call chain, but no cleanup 214 actions are performed. */ 215 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (_Unwind_Context *, void *); 216 _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, 217 void*); 218 219 _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *); 220 void _Unwind_Complete(_Unwind_Control_Block *ucbp); 221 void _Unwind_DeleteException (_Unwind_Exception *); 222 223 _Unwind_Reason_Code __gnu_unwind_frame (_Unwind_Control_Block *, 224 _Unwind_Context *); 225 _Unwind_Reason_Code __gnu_unwind_execute (_Unwind_Context *, 226 __gnu_unwind_state *); 227 228 /* Decode an R_ARM_TARGET2 relocation. */ 229 static inline _Unwind_Word _Unwind_decode_target2(_Unwind_Word ptr)230 _Unwind_decode_target2 (_Unwind_Word ptr) 231 { 232 _Unwind_Word tmp; 233 234 tmp = *(_Unwind_Word *) ptr; 235 /* Zero values are always NULL. */ 236 if (!tmp) 237 return 0; 238 239 #if defined(linux) || defined(__NetBSD__) || defined(__FreeBSD__) 240 /* Pc-relative indirect. */ 241 tmp += ptr; 242 tmp = *(_Unwind_Word *) tmp; 243 #elif defined(__symbian__) 244 /* Absolute pointer. Nothing more to do. */ 245 #else 246 /* Pc-relative pointer. */ 247 tmp += ptr; 248 #endif 249 return tmp; 250 } 251 252 __ARM_STATIC_INLINE _Unwind_Word _Unwind_GetGR(_Unwind_Context * context,int regno)253 _Unwind_GetGR (_Unwind_Context *context, int regno) 254 { 255 _uw val; 256 _Unwind_VRS_Get (context, _UVRSC_CORE, regno, _UVRSD_UINT32, &val); 257 return val; 258 } 259 260 __ARM_STATIC_INLINE void _Unwind_SetGR(_Unwind_Context * context,int regno,_Unwind_Word val)261 _Unwind_SetGR (_Unwind_Context *context, int regno, _Unwind_Word val) 262 { 263 _Unwind_VRS_Set (context, _UVRSC_CORE, regno, _UVRSD_UINT32, &val); 264 } 265 266 #ifndef __FreeBSD__ 267 /* Return the address of the instruction, not the actual IP value. */ 268 #define _Unwind_GetIP(context) \ 269 (_Unwind_GetGR (context, 15) & ~(_Unwind_Word)1) 270 271 #define _Unwind_GetIPInfo(context, ip_before_insn) \ 272 (*ip_before_insn = 0, _Unwind_GetGR (context, 15) & ~(_Unwind_Word)1) 273 274 /* The dwarf unwinder doesn't understand arm/thumb state. We assume the 275 landing pad uses the same instruction set as the call site. */ 276 #define _Unwind_SetIP(context, val) \ 277 _Unwind_SetGR (context, 15, val | (_Unwind_GetGR (context, 15) & 1)) 278 #else 279 _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *); 280 _Unwind_Ptr _Unwind_GetIPInfo (struct _Unwind_Context *, int *); 281 void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr); 282 #endif 283 284 #ifdef __cplusplus 285 } /* extern "C" */ 286 #endif 287 288 #endif /* defined UNWIND_ARM_H */ 289