1 //===----------------------------------------------------------------------===//
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
8 // C++ ABI Level 1 ABI documented at:
9 // https://github.com/ARM-software/abi-aa/blob/main/ehabi32/ehabi32.rst
11 //===----------------------------------------------------------------------===//
13 #ifndef __ARM_EHABI_UNWIND_H__
14 #define __ARM_EHABI_UNWIND_H__
16 typedef uint32_t _Unwind_State
;
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;
25 typedef uint32_t _Unwind_EHT_Header
;
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];
32 struct _Unwind_Control_Block
{
33 _Unwind_Exception_Class exception_class
;
34 void (*exception_cleanup
)(_Unwind_Reason_Code
, _Unwind_Control_Block
*);
36 /* Unwinder cache, private fields for the unwinder's use */
38 uint32_t reserved1
; /* init reserved1 to 0, then don't touch */
45 /* Propagation barrier cache (valid after phase 1): */
48 uint32_t bitpattern
[5];
51 /* Cleanup cache (preserved over cleanup): */
53 uint32_t bitpattern
[4];
56 /* Pr cache (for pr's benefit): */
58 uint32_t fnstart
; /* function start address */
59 _Unwind_EHT_Header
* ehtp
; /* pointer to EHT entry header word */
64 long long int :0; /* Enforce the 8-byte alignment */
65 } __attribute__((__aligned__(8)));
67 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn
)(
68 _Unwind_State state
, _Unwind_Exception
*exceptionObject
,
69 struct _Unwind_Context
*context
);
76 // The following are the base functions documented by the C++ ABI
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
);
83 extern _Unwind_Reason_Code
84 _Unwind_RaiseException(_Unwind_Exception
*exception_object
);
85 extern void _Unwind_Resume(_Unwind_Exception
*exception_object
);
87 extern void _Unwind_DeleteException(_Unwind_Exception
*exception_object
);
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
;
103 } _Unwind_VRS_DataRepresentation
;
107 _UVRSR_NOT_IMPLEMENTED
= 1,
109 } _Unwind_VRS_Result
;
111 extern void _Unwind_Complete(_Unwind_Exception
* exception_object
);
113 extern _Unwind_VRS_Result
114 _Unwind_VRS_Get(_Unwind_Context
*context
, _Unwind_VRS_RegClass regclass
,
115 uint32_t regno
, _Unwind_VRS_DataRepresentation representation
,
118 extern _Unwind_VRS_Result
119 _Unwind_VRS_Set(_Unwind_Context
*context
, _Unwind_VRS_RegClass regclass
,
120 uint32_t regno
, _Unwind_VRS_DataRepresentation representation
,
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
);
128 #if defined(_LIBUNWIND_UNWIND_LEVEL1_EXTERNAL_LINKAGE)
129 #define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 extern
131 #define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 static __inline__
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.
141 _LIBUNWIND_EXPORT_UNWIND_LEVEL1
142 uintptr_t _Unwind_GetGR(struct _Unwind_Context
*context
, int index
) {
144 _Unwind_VRS_Get(context
, _UVRSC_CORE
, (uint32_t)index
, _UVRSD_UINT32
, &value
);
148 _LIBUNWIND_EXPORT_UNWIND_LEVEL1
149 void _Unwind_SetGR(struct _Unwind_Context
*context
, int index
,
151 _Unwind_VRS_Set(context
, _UVRSC_CORE
, (uint32_t)index
, _UVRSD_UINT32
, &value
);
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);
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
);
170 #endif // __ARM_EHABI_UNWIND_H__