1 /* ===-- assembly.h - libUnwind assembler support macros -------------------=== 2 * 3 * The LLVM Compiler Infrastructure 4 * 5 * This file is dual licensed under the MIT and the University of Illinois Open 6 * Source Licenses. See LICENSE.TXT for details. 7 * 8 * ===----------------------------------------------------------------------=== 9 * 10 * This file defines macros for use in libUnwind assembler source. 11 * This file is not part of the interface of this library. 12 * 13 * ===----------------------------------------------------------------------=== 14 */ 15 16 #ifndef UNWIND_ASSEMBLY_H 17 #define UNWIND_ASSEMBLY_H 18 19 #if defined(__powerpc64__) 20 #define SEPARATOR ; 21 #define PPC64_OFFS_SRR0 0 22 #define PPC64_OFFS_CR 272 23 #define PPC64_OFFS_XER 280 24 #define PPC64_OFFS_LR 288 25 #define PPC64_OFFS_CTR 296 26 #define PPC64_OFFS_VRSAVE 304 27 #define PPC64_OFFS_FP 312 28 #define PPC64_OFFS_V 824 29 #ifdef _ARCH_PWR8 30 #define PPC64_HAS_VMX 31 #endif 32 #elif defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__) 33 #define SEPARATOR @ 34 #elif defined(__arm64__) 35 #define SEPARATOR %% 36 #else 37 #define SEPARATOR ; 38 #endif 39 40 #define GLUE2(a, b) a ## b 41 #define GLUE(a, b) GLUE2(a, b) 42 #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) 43 44 #if defined(__APPLE__) 45 46 #define SYMBOL_IS_FUNC(name) 47 #define EXPORT_SYMBOL(name) 48 #define HIDDEN_SYMBOL(name) .private_extern name 49 #define NO_EXEC_STACK_DIRECTIVE 50 51 #elif defined(__ELF__) 52 53 #if defined(__arm__) 54 #define SYMBOL_IS_FUNC(name) .type name,%function 55 #else 56 #define SYMBOL_IS_FUNC(name) .type name,@function 57 #endif 58 #define EXPORT_SYMBOL(name) 59 #define HIDDEN_SYMBOL(name) .hidden name 60 61 #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ 62 defined(__linux__) 63 #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits 64 #else 65 #define NO_EXEC_STACK_DIRECTIVE 66 #endif 67 68 #elif defined(_WIN32) 69 70 #define SYMBOL_IS_FUNC(name) \ 71 .def name SEPARATOR \ 72 .scl 2 SEPARATOR \ 73 .type 32 SEPARATOR \ 74 .endef 75 #define EXPORT_SYMBOL2(name) \ 76 .section .drectve,"yn" SEPARATOR \ 77 .ascii "-export:", #name, "\0" SEPARATOR \ 78 .text 79 #define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name) 80 #define HIDDEN_SYMBOL(name) 81 82 #define NO_EXEC_STACK_DIRECTIVE 83 84 #else 85 86 #error Unsupported target 87 88 #endif 89 90 #define DEFINE_LIBUNWIND_FUNCTION(name) \ 91 .globl SYMBOL_NAME(name) SEPARATOR \ 92 EXPORT_SYMBOL(name) SEPARATOR \ 93 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 94 SYMBOL_NAME(name): 95 96 #define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name) \ 97 .globl SYMBOL_NAME(name) SEPARATOR \ 98 HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \ 99 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 100 SYMBOL_NAME(name): 101 102 #if defined(__arm__) 103 #if !defined(__ARM_ARCH) 104 #define __ARM_ARCH 4 105 #endif 106 107 #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5 108 #define ARM_HAS_BX 109 #endif 110 111 #ifdef ARM_HAS_BX 112 #define JMP(r) bx r 113 #else 114 #define JMP(r) mov pc, r 115 #endif 116 #endif /* __arm__ */ 117 118 #endif /* UNWIND_ASSEMBLY_H */ 119