1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 // 8 // C++ ABI Level 1 ABI documented at: 9 // https://github.com/ARM-software/abi-aa/blob/main/ehabi32/ehabi32.rst 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef __ARM_EHABI_UNWIND_H__ 14 #define __ARM_EHABI_UNWIND_H__ 15 16 typedef uint32_t _Unwind_State; 17 18 static const _Unwind_State _US_VIRTUAL_UNWIND_FRAME = 0; 19 static const _Unwind_State _US_UNWIND_FRAME_STARTING = 1; 20 static const _Unwind_State _US_UNWIND_FRAME_RESUME = 2; 21 static const _Unwind_State _US_ACTION_MASK = 3; 22 /* Undocumented flag for force unwinding. */ 23 static const _Unwind_State _US_FORCE_UNWIND = 8; 24 25 typedef uint32_t _Unwind_EHT_Header; 26 27 struct _Unwind_Control_Block; 28 typedef struct _Unwind_Control_Block _Unwind_Control_Block; 29 #define _Unwind_Exception _Unwind_Control_Block /* Alias */ 30 typedef uint8_t _Unwind_Exception_Class[8]; 31 32 struct _Unwind_Control_Block { 33 _Unwind_Exception_Class exception_class; 34 void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Control_Block*); 35 36 /* Unwinder cache, private fields for the unwinder's use */ 37 struct { 38 uint32_t reserved1; /* init reserved1 to 0, then don't touch */ 39 uint32_t reserved2; 40 uint32_t reserved3; 41 uint32_t reserved4; 42 uint32_t reserved5; 43 } unwinder_cache; 44 45 /* Propagation barrier cache (valid after phase 1): */ 46 struct { 47 uint32_t sp; 48 uint32_t bitpattern[5]; 49 } barrier_cache; 50 51 /* Cleanup cache (preserved over cleanup): */ 52 struct { 53 uint32_t bitpattern[4]; 54 } cleanup_cache; 55 56 /* Pr cache (for pr's benefit): */ 57 struct { 58 uint32_t fnstart; /* function start address */ 59 _Unwind_EHT_Header* ehtp; /* pointer to EHT entry header word */ 60 uint32_t additional; 61 uint32_t reserved1; 62 } pr_cache; 63 64 long long int :0; /* Enforce the 8-byte alignment */ 65 } __attribute__((__aligned__(8))); 66 67 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)( 68 _Unwind_State state, _Unwind_Exception *exceptionObject, 69 struct _Unwind_Context *context); 70 71 #ifdef __cplusplus 72 extern "C" { 73 #endif 74 75 // 76 // The following are the base functions documented by the C++ ABI 77 // 78 #ifdef __USING_SJLJ_EXCEPTIONS__ 79 extern _Unwind_Reason_Code 80 _Unwind_SjLj_RaiseException(_Unwind_Exception *exception_object); 81 extern void _Unwind_SjLj_Resume(_Unwind_Exception *exception_object); 82 #else 83 extern _Unwind_Reason_Code 84 _Unwind_RaiseException(_Unwind_Exception *exception_object); 85 extern void _Unwind_Resume(_Unwind_Exception *exception_object); 86 #endif 87 extern void _Unwind_DeleteException(_Unwind_Exception *exception_object); 88 89 typedef enum { 90 _UVRSC_CORE = 0, /* integer register */ 91 _UVRSC_VFP = 1, /* vfp */ 92 _UVRSC_WMMXD = 3, /* Intel WMMX data register */ 93 _UVRSC_WMMXC = 4, /* Intel WMMX control register */ 94 _UVRSC_PSEUDO = 5 /* Special purpose pseudo register */ 95 } _Unwind_VRS_RegClass; 96 97 typedef enum { 98 _UVRSD_UINT32 = 0, 99 _UVRSD_VFPX = 1, 100 _UVRSD_UINT64 = 3, 101 _UVRSD_FLOAT = 4, 102 _UVRSD_DOUBLE = 5 103 } _Unwind_VRS_DataRepresentation; 104 105 typedef enum { 106 _UVRSR_OK = 0, 107 _UVRSR_NOT_IMPLEMENTED = 1, 108 _UVRSR_FAILED = 2 109 } _Unwind_VRS_Result; 110 111 extern void _Unwind_Complete(_Unwind_Exception* exception_object); 112 113 extern _Unwind_VRS_Result 114 _Unwind_VRS_Get(_Unwind_Context *context, _Unwind_VRS_RegClass regclass, 115 uint32_t regno, _Unwind_VRS_DataRepresentation representation, 116 void *valuep); 117 118 extern _Unwind_VRS_Result 119 _Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass, 120 uint32_t regno, _Unwind_VRS_DataRepresentation representation, 121 void *valuep); 122 123 extern _Unwind_VRS_Result 124 _Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass, 125 uint32_t discriminator, 126 _Unwind_VRS_DataRepresentation representation); 127 128 #if defined(_LIBUNWIND_UNWIND_LEVEL1_EXTERNAL_LINKAGE) 129 #define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 extern 130 #else 131 #define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 static __inline__ 132 #endif 133 134 // These are de facto helper functions for ARM, which delegate the function 135 // calls to _Unwind_VRS_Get/Set(). These are not a part of ARM EHABI 136 // specification, thus these function MUST be inlined. Please don't replace 137 // these with the "extern" function declaration; otherwise, the program 138 // including this <unwind.h> header won't be ABI compatible and will result in 139 // link error when we are linking the program with libgcc. 140 141 _LIBUNWIND_EXPORT_UNWIND_LEVEL1 142 uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, int index) { 143 uintptr_t value = 0; 144 _Unwind_VRS_Get(context, _UVRSC_CORE, (uint32_t)index, _UVRSD_UINT32, &value); 145 return value; 146 } 147 148 _LIBUNWIND_EXPORT_UNWIND_LEVEL1 149 void _Unwind_SetGR(struct _Unwind_Context *context, int index, 150 uintptr_t value) { 151 _Unwind_VRS_Set(context, _UVRSC_CORE, (uint32_t)index, _UVRSD_UINT32, &value); 152 } 153 154 _LIBUNWIND_EXPORT_UNWIND_LEVEL1 155 uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) { 156 // remove the thumb-bit before returning 157 return _Unwind_GetGR(context, 15) & (~(uintptr_t)0x1); 158 } 159 160 _LIBUNWIND_EXPORT_UNWIND_LEVEL1 161 void _Unwind_SetIP(struct _Unwind_Context *context, uintptr_t value) { 162 uintptr_t thumb_bit = _Unwind_GetGR(context, 15) & ((uintptr_t)0x1); 163 _Unwind_SetGR(context, 15, value | thumb_bit); 164 } 165 166 #ifdef __cplusplus 167 } 168 #endif 169 170 #endif // __ARM_EHABI_UNWIND_H__ 171