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