171 lines · c
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-exception6//7//8// C++ ABI Level 1 ABI documented at:9// https://github.com/ARM-software/abi-aa/blob/main/ehabi32/ehabi32.rst10//11//===----------------------------------------------------------------------===//12 13#ifndef __ARM_EHABI_UNWIND_H__14#define __ARM_EHABI_UNWIND_H__15 16typedef uint32_t _Unwind_State;17 18static const _Unwind_State _US_VIRTUAL_UNWIND_FRAME = 0;19static const _Unwind_State _US_UNWIND_FRAME_STARTING = 1;20static const _Unwind_State _US_UNWIND_FRAME_RESUME = 2;21static const _Unwind_State _US_ACTION_MASK = 3;22/* Undocumented flag for force unwinding. */23static const _Unwind_State _US_FORCE_UNWIND = 8;24 25typedef uint32_t _Unwind_EHT_Header;26 27struct _Unwind_Control_Block;28typedef struct _Unwind_Control_Block _Unwind_Control_Block;29#define _Unwind_Exception _Unwind_Control_Block /* Alias */30typedef uint8_t _Unwind_Exception_Class[8];31 32struct _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 67typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(68 _Unwind_State state, _Unwind_Exception *exceptionObject,69 struct _Unwind_Context *context);70 71#ifdef __cplusplus72extern "C" {73#endif74 75//76// The following are the base functions documented by the C++ ABI77//78#ifdef __USING_SJLJ_EXCEPTIONS__79extern _Unwind_Reason_Code80 _Unwind_SjLj_RaiseException(_Unwind_Exception *exception_object);81extern void _Unwind_SjLj_Resume(_Unwind_Exception *exception_object);82#else83extern _Unwind_Reason_Code84 _Unwind_RaiseException(_Unwind_Exception *exception_object);85extern void _Unwind_Resume(_Unwind_Exception *exception_object);86#endif87extern void _Unwind_DeleteException(_Unwind_Exception *exception_object);88 89typedef 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 97typedef enum {98 _UVRSD_UINT32 = 0,99 _UVRSD_VFPX = 1,100 _UVRSD_UINT64 = 3,101 _UVRSD_FLOAT = 4,102 _UVRSD_DOUBLE = 5103} _Unwind_VRS_DataRepresentation;104 105typedef enum {106 _UVRSR_OK = 0,107 _UVRSR_NOT_IMPLEMENTED = 1,108 _UVRSR_FAILED = 2109} _Unwind_VRS_Result;110 111extern void _Unwind_Complete(_Unwind_Exception* exception_object);112 113extern _Unwind_VRS_Result114_Unwind_VRS_Get(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,115 uint32_t regno, _Unwind_VRS_DataRepresentation representation,116 void *valuep);117 118extern _Unwind_VRS_Result119_Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,120 uint32_t regno, _Unwind_VRS_DataRepresentation representation,121 void *valuep);122 123extern _Unwind_VRS_Result124_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 extern130#else131#define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 static __inline__132#endif133 134// These are de facto helper functions for ARM, which delegate the function135// calls to _Unwind_VRS_Get/Set(). These are not a part of ARM EHABI136// specification, thus these function MUST be inlined. Please don't replace137// these with the "extern" function declaration; otherwise, the program138// including this <unwind.h> header won't be ABI compatible and will result in139// link error when we are linking the program with libgcc.140 141_LIBUNWIND_EXPORT_UNWIND_LEVEL1142uintptr_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_LEVEL1149void _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_LEVEL1155uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) {156 // remove the thumb-bit before returning157 return _Unwind_GetGR(context, 15) & (~(uintptr_t)0x1);158}159 160_LIBUNWIND_EXPORT_UNWIND_LEVEL1161void _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 __cplusplus167}168#endif169 170#endif // __ARM_EHABI_UNWIND_H__171