blob: 8cbd3853011b9e41e1de217eeb8f3adb33b874f9 [file] [log] [blame]
Daniel Dunbar7d504782009-10-27 17:49:50 +00001/* ===-- assembly.h - compiler-rt assembler support macros -----------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant5b791f62010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Daniel Dunbar7d504782009-10-27 17:49:50 +00007 *
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
Daniel Dunbar7d504782009-10-27 17:49:50 +000019#if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
Daniel Dunbar7d504782009-10-27 17:49:50 +000020#define SEPARATOR @
Daniel Dunbar7d504782009-10-27 17:49:50 +000021#else
Daniel Dunbar7d504782009-10-27 17:49:50 +000022#define SEPARATOR ;
Daniel Dunbar64a198d2010-01-18 22:19:25 +000023#endif
Daniel Dunbar7d504782009-10-27 17:49:50 +000024
Daniel Dunbar64a198d2010-01-18 22:19:25 +000025#if defined(__APPLE__)
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +000026#define HIDDEN(name) .private_extern name
Anton Korobeynikov16536102011-04-19 17:50:09 +000027#define LOCAL_LABEL(name) L_##name
Jonathan Roelofsb351c1a2014-05-12 17:38:36 +000028// tell linker it can break up file at label boundaries
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000029#define FILE_LEVEL_DIRECTIVE .subsections_via_symbols
Joerg Sonnenberger197568a2014-01-14 23:31:23 +000030#define SYMBOL_IS_FUNC(name)
Saleem Abdulrasooldd9b0342014-05-18 18:39:15 +000031#elif defined(__ELF__)
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +000032#define HIDDEN(name) .hidden name
Anton Korobeynikov16536102011-04-19 17:50:09 +000033#define LOCAL_LABEL(name) .L_##name
Joerg Sonnenberger197568a2014-01-14 23:31:23 +000034#define FILE_LEVEL_DIRECTIVE
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000035#if defined(__arm__)
36#define SYMBOL_IS_FUNC(name) .type name,%function
37#else
38#define SYMBOL_IS_FUNC(name) .type name,@function
39#endif
Saleem Abdulrasooldd9b0342014-05-18 18:39:15 +000040#else
41#define HIDDEN_DIRECTIVE(name)
42#define LOCAL_LABEL(name) .L ## name
43#define SYMBOL_IS_FUNC(name) \
44 .def name SEPARATOR \
Saleem Abdulrasoold0d16382014-06-21 01:41:21 +000045 .scl 2 SEPARATOR \
Saleem Abdulrasooldd9b0342014-05-18 18:39:15 +000046 .type 32 SEPARATOR \
47 .endef
48#define FILE_LEVEL_DIRECTIVE
Daniel Dunbar7d504782009-10-27 17:49:50 +000049#endif
50
Joerg Sonnenberger1f8cb3e2014-01-24 13:39:51 +000051#if defined(__arm__)
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000052#ifndef __ARM_ARCH
53#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || \
54 defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || \
55 defined(__ARM_ARCH_7EM__)
56#define __ARM_ARCH 7
57#endif
Joerg Sonnenberger1f8cb3e2014-01-24 13:39:51 +000058#endif
59
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000060#ifndef __ARM_ARCH
61#if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || \
62 defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || \
63 defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6ZM__)
64#define __ARM_ARCH 6
65#endif
66#endif
67
68#ifndef __ARM_ARCH
69#if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) || \
70 defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__)
71#define __ARM_ARCH 5
72#endif
73#endif
74
75#ifndef __ARM_ARCH
76#define __ARM_ARCH 4
77#endif
78
79#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
80#define ARM_HAS_BX
81#endif
82#if !defined(__ARM_FEATURE_CLZ) && \
83 (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))
84#define __ARM_FEATURE_CLZ
85#endif
86
87#ifdef ARM_HAS_BX
88#define JMP(r) bx r
Joerg Sonnenberger8f6cf702014-07-20 20:00:26 +000089#define JMPc(r, c) bx##c r
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +000090#else
91#define JMP(r) mov pc, r
92#define JMPc(r, c) mov##c pc, r
93#endif
Saleem Abdulrasoolb6690c32014-07-27 02:01:20 +000094
95#if __ARM_ARCH_ISA_THUMB == 2
96#define IT(cond) it cond
97#define ITT(cond) itt cond
98#else
99#define IT(cond)
100#define ITT(cond)
101#endif
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000102#endif
103
104#define GLUE2(a, b) a##b
Anton Korobeynikov3c519902011-04-19 21:22:14 +0000105#define GLUE(a, b) GLUE2(a, b)
106#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
107
Bob Wilsone67004e2012-02-10 16:41:46 +0000108#ifdef VISIBILITY_HIDDEN
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000109#define DECLARE_SYMBOL_VISIBILITY(name) \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000110 HIDDEN(SYMBOL_NAME(name)) SEPARATOR
Daniel Dunbarf665b322010-01-18 22:19:34 +0000111#else
Bob Wilson66cdd222011-08-22 21:49:47 +0000112#define DECLARE_SYMBOL_VISIBILITY(name)
113#endif
114
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000115#define DEFINE_COMPILERRT_FUNCTION(name) \
116 FILE_LEVEL_DIRECTIVE SEPARATOR \
117 .globl SYMBOL_NAME(name) SEPARATOR \
118 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
119 DECLARE_SYMBOL_VISIBILITY(name) \
Daniel Dunbar7d504782009-10-27 17:49:50 +0000120 SYMBOL_NAME(name):
121
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000122#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
123 FILE_LEVEL_DIRECTIVE SEPARATOR \
124 .globl SYMBOL_NAME(name) SEPARATOR \
125 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000126 HIDDEN(SYMBOL_NAME(name)) SEPARATOR \
Daniel Dunbar7d504782009-10-27 17:49:50 +0000127 SYMBOL_NAME(name):
128
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000129#define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \
130 .globl name SEPARATOR \
131 SYMBOL_IS_FUNC(name) SEPARATOR \
Saleem Abdulrasool9a614bd2014-05-18 18:39:10 +0000132 HIDDEN(name) SEPARATOR \
Daniel Dunbaref898582010-01-18 22:19:20 +0000133 name:
134
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000135#define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \
136 .globl SYMBOL_NAME(name) SEPARATOR \
137 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000138 .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR
139
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000140#if defined(__ARM_EABI__)
141#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000142 DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name)
143#else
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000144#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)
Anton Korobeynikov75e3c192011-04-19 17:51:24 +0000145#endif
146
Joerg Sonnenberger25468a2a2014-01-23 18:31:46 +0000147#ifdef __ELF__
Saleem Abdulrasoolda2c2ce2014-05-16 06:16:21 +0000148#define END_COMPILERRT_FUNCTION(name) \
149 .size SYMBOL_NAME(name), . - SYMBOL_NAME(name)
Joerg Sonnenberger25468a2a2014-01-23 18:31:46 +0000150#else
151#define END_COMPILERRT_FUNCTION(name)
152#endif
153
Daniel Dunbar7d504782009-10-27 17:49:50 +0000154#endif /* COMPILERRT_ASSEMBLY_H */