1 1.1 joerg /* ===-- assembly.h - compiler-rt assembler support macros -----------------=== 2 1.1 joerg * 3 1.1 joerg * The LLVM Compiler Infrastructure 4 1.1 joerg * 5 1.1 joerg * This file is dual licensed under the MIT and the University of Illinois Open 6 1.1 joerg * Source Licenses. See LICENSE.TXT for details. 7 1.1 joerg * 8 1.1 joerg * ===----------------------------------------------------------------------=== 9 1.1 joerg * 10 1.1 joerg * This file defines macros for use in compiler-rt assembler source. 11 1.1 joerg * This file is not part of the interface of this library. 12 1.1 joerg * 13 1.1 joerg * ===----------------------------------------------------------------------=== 14 1.1 joerg */ 15 1.1 joerg 16 1.1 joerg #ifndef COMPILERRT_ASSEMBLY_H 17 1.1 joerg #define COMPILERRT_ASSEMBLY_H 18 1.1 joerg 19 1.1 joerg #if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__) 20 1.1 joerg #define SEPARATOR @ 21 1.1 joerg #else 22 1.1 joerg #define SEPARATOR ; 23 1.1 joerg #endif 24 1.1 joerg 25 1.1 joerg #if defined(__APPLE__) 26 1.1.1.2 joerg #define HIDDEN(name) .private_extern name 27 1.1 joerg #define LOCAL_LABEL(name) L_##name 28 1.1.1.2 joerg // tell linker it can break up file at label boundaries 29 1.1.1.2 joerg #define FILE_LEVEL_DIRECTIVE .subsections_via_symbols 30 1.1 joerg #define SYMBOL_IS_FUNC(name) 31 1.1.1.4 joerg #define CONST_SECTION .const 32 1.1.1.4 joerg 33 1.1.1.2 joerg #elif defined(__ELF__) 34 1.1.1.4 joerg 35 1.1.1.2 joerg #define HIDDEN(name) .hidden name 36 1.1 joerg #define LOCAL_LABEL(name) .L_##name 37 1.1 joerg #define FILE_LEVEL_DIRECTIVE 38 1.1.1.2 joerg #if defined(__arm__) 39 1.1.1.2 joerg #define SYMBOL_IS_FUNC(name) .type name,%function 40 1.1.1.2 joerg #else 41 1.1.1.2 joerg #define SYMBOL_IS_FUNC(name) .type name,@function 42 1.1.1.2 joerg #endif 43 1.1.1.4 joerg #define CONST_SECTION .section .rodata 44 1.1.1.4 joerg 45 1.1.1.4 joerg #else // !__APPLE__ && !__ELF__ 46 1.1.1.4 joerg 47 1.1.1.4 joerg #define HIDDEN(name) 48 1.1.1.2 joerg #define LOCAL_LABEL(name) .L ## name 49 1.1.1.4 joerg #define FILE_LEVEL_DIRECTIVE 50 1.1.1.2 joerg #define SYMBOL_IS_FUNC(name) \ 51 1.1.1.2 joerg .def name SEPARATOR \ 52 1.1.1.3 joerg .scl 2 SEPARATOR \ 53 1.1.1.2 joerg .type 32 SEPARATOR \ 54 1.1.1.2 joerg .endef 55 1.1.1.4 joerg #define CONST_SECTION .section .rdata,"rd" 56 1.1.1.2 joerg 57 1.1.1.2 joerg #endif 58 1.1.1.2 joerg 59 1.1.1.4 joerg #if defined(__arm__) 60 1.1.1.2 joerg #if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5 61 1.1.1.2 joerg #define ARM_HAS_BX 62 1.1.1.2 joerg #endif 63 1.1.1.2 joerg #if !defined(__ARM_FEATURE_CLZ) && \ 64 1.1.1.2 joerg (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__))) 65 1.1.1.2 joerg #define __ARM_FEATURE_CLZ 66 1.1.1.2 joerg #endif 67 1.1.1.2 joerg 68 1.1.1.2 joerg #ifdef ARM_HAS_BX 69 1.1.1.2 joerg #define JMP(r) bx r 70 1.1.1.2 joerg #define JMPc(r, c) bx##c r 71 1.1.1.2 joerg #else 72 1.1.1.2 joerg #define JMP(r) mov pc, r 73 1.1.1.2 joerg #define JMPc(r, c) mov##c pc, r 74 1.1.1.2 joerg #endif 75 1.1.1.3 joerg 76 1.1.1.4 joerg // pop {pc} can't switch Thumb mode on ARMv4T 77 1.1.1.4 joerg #if __ARM_ARCH >= 5 78 1.1.1.4 joerg #define POP_PC() pop {pc} 79 1.1.1.4 joerg #else 80 1.1.1.4 joerg #define POP_PC() \ 81 1.1.1.4 joerg pop {ip}; \ 82 1.1.1.4 joerg JMP(ip) 83 1.1.1.4 joerg #endif 84 1.1.1.4 joerg 85 1.1.1.3 joerg #if __ARM_ARCH_ISA_THUMB == 2 86 1.1.1.3 joerg #define IT(cond) it cond 87 1.1.1.3 joerg #define ITT(cond) itt cond 88 1.1.1.3 joerg #else 89 1.1.1.3 joerg #define IT(cond) 90 1.1.1.3 joerg #define ITT(cond) 91 1.1.1.3 joerg #endif 92 1.1.1.3 joerg 93 1.1.1.3 joerg #if __ARM_ARCH_ISA_THUMB == 2 94 1.1.1.3 joerg #define WIDE(op) op.w 95 1.1.1.3 joerg #else 96 1.1.1.3 joerg #define WIDE(op) op 97 1.1.1.3 joerg #endif 98 1.1 joerg #endif 99 1.1 joerg 100 1.1.1.2 joerg #define GLUE2(a, b) a##b 101 1.1 joerg #define GLUE(a, b) GLUE2(a, b) 102 1.1 joerg #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) 103 1.1 joerg 104 1.1 joerg #ifdef VISIBILITY_HIDDEN 105 1.1.1.2 joerg #define DECLARE_SYMBOL_VISIBILITY(name) \ 106 1.1.1.2 joerg HIDDEN(SYMBOL_NAME(name)) SEPARATOR 107 1.1 joerg #else 108 1.1 joerg #define DECLARE_SYMBOL_VISIBILITY(name) 109 1.1 joerg #endif 110 1.1 joerg 111 1.1.1.2 joerg #define DEFINE_COMPILERRT_FUNCTION(name) \ 112 1.1.1.2 joerg FILE_LEVEL_DIRECTIVE SEPARATOR \ 113 1.1.1.2 joerg .globl SYMBOL_NAME(name) SEPARATOR \ 114 1.1.1.2 joerg SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 115 1.1.1.2 joerg DECLARE_SYMBOL_VISIBILITY(name) \ 116 1.1 joerg SYMBOL_NAME(name): 117 1.1 joerg 118 1.1.1.4 joerg #define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \ 119 1.1.1.4 joerg FILE_LEVEL_DIRECTIVE SEPARATOR \ 120 1.1.1.4 joerg .globl SYMBOL_NAME(name) SEPARATOR \ 121 1.1.1.4 joerg SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 122 1.1.1.4 joerg DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \ 123 1.1.1.4 joerg .thumb_func SEPARATOR \ 124 1.1.1.4 joerg SYMBOL_NAME(name): 125 1.1.1.4 joerg 126 1.1.1.2 joerg #define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \ 127 1.1.1.2 joerg FILE_LEVEL_DIRECTIVE SEPARATOR \ 128 1.1.1.2 joerg .globl SYMBOL_NAME(name) SEPARATOR \ 129 1.1.1.2 joerg SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 130 1.1.1.2 joerg HIDDEN(SYMBOL_NAME(name)) SEPARATOR \ 131 1.1 joerg SYMBOL_NAME(name): 132 1.1 joerg 133 1.1.1.2 joerg #define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \ 134 1.1.1.2 joerg .globl name SEPARATOR \ 135 1.1.1.2 joerg SYMBOL_IS_FUNC(name) SEPARATOR \ 136 1.1.1.2 joerg HIDDEN(name) SEPARATOR \ 137 1.1 joerg name: 138 1.1 joerg 139 1.1.1.2 joerg #define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \ 140 1.1.1.2 joerg .globl SYMBOL_NAME(name) SEPARATOR \ 141 1.1.1.2 joerg SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ 142 1.1 joerg .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR 143 1.1 joerg 144 1.1.1.2 joerg #if defined(__ARM_EABI__) 145 1.1.1.2 joerg #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \ 146 1.1 joerg DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name) 147 1.1 joerg #else 148 1.1.1.2 joerg #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) 149 1.1 joerg #endif 150 1.1 joerg 151 1.1 joerg #ifdef __ELF__ 152 1.1.1.2 joerg #define END_COMPILERRT_FUNCTION(name) \ 153 1.1.1.2 joerg .size SYMBOL_NAME(name), . - SYMBOL_NAME(name) 154 1.1 joerg #else 155 1.1 joerg #define END_COMPILERRT_FUNCTION(name) 156 1.1 joerg #endif 157 1.1 joerg 158 1.1 joerg #endif /* COMPILERRT_ASSEMBLY_H */ 159