2009-10-28 01:49:50 +08:00
|
|
|
/* ===-- assembly.h - compiler-rt assembler support macros -----------------===
|
|
|
|
*
|
|
|
|
* The LLVM Compiler Infrastructure
|
|
|
|
*
|
2010-11-17 06:13:33 +08:00
|
|
|
* This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
* Source Licenses. See LICENSE.TXT for details.
|
2009-10-28 01:49:50 +08:00
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*
|
|
|
|
* This file defines macros for use in compiler-rt assembler source.
|
|
|
|
* This file is not part of the interface of this library.
|
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMPILERRT_ASSEMBLY_H
|
|
|
|
#define COMPILERRT_ASSEMBLY_H
|
|
|
|
|
|
|
|
#if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
|
|
|
|
#define SEPARATOR @
|
|
|
|
#else
|
|
|
|
#define SEPARATOR ;
|
2010-01-19 06:19:25 +08:00
|
|
|
#endif
|
2009-10-28 01:49:50 +08:00
|
|
|
|
2010-01-19 06:19:25 +08:00
|
|
|
#if defined(__APPLE__)
|
2014-05-19 02:39:10 +08:00
|
|
|
#define HIDDEN(name) .private_extern name
|
2011-04-20 01:50:09 +08:00
|
|
|
#define LOCAL_LABEL(name) L_##name
|
2014-05-13 01:38:36 +08:00
|
|
|
// tell linker it can break up file at label boundaries
|
2014-05-16 14:16:21 +08:00
|
|
|
#define FILE_LEVEL_DIRECTIVE .subsections_via_symbols
|
2014-01-15 07:31:23 +08:00
|
|
|
#define SYMBOL_IS_FUNC(name)
|
2014-12-10 10:36:22 +08:00
|
|
|
#define CONST_SECTION .const
|
2014-10-05 04:11:10 +08:00
|
|
|
|
2016-06-23 06:09:42 +08:00
|
|
|
#define NO_EXEC_STACK_DIRECTIVE
|
|
|
|
|
2014-05-19 02:39:15 +08:00
|
|
|
#elif defined(__ELF__)
|
2014-10-05 04:11:10 +08:00
|
|
|
|
2014-05-19 02:39:10 +08:00
|
|
|
#define HIDDEN(name) .hidden name
|
2011-04-20 01:50:09 +08:00
|
|
|
#define LOCAL_LABEL(name) .L_##name
|
2014-01-15 07:31:23 +08:00
|
|
|
#define FILE_LEVEL_DIRECTIVE
|
2014-05-16 14:16:21 +08:00
|
|
|
#if defined(__arm__)
|
|
|
|
#define SYMBOL_IS_FUNC(name) .type name,%function
|
|
|
|
#else
|
|
|
|
#define SYMBOL_IS_FUNC(name) .type name,@function
|
|
|
|
#endif
|
2014-12-10 10:36:22 +08:00
|
|
|
#define CONST_SECTION .section .rodata
|
2014-10-05 04:11:10 +08:00
|
|
|
|
2016-06-23 06:09:42 +08:00
|
|
|
#if defined(__GNU__) || defined(__ANDROID__) || defined(__FreeBSD__)
|
|
|
|
#define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
|
|
|
|
#else
|
|
|
|
#define NO_EXEC_STACK_DIRECTIVE
|
|
|
|
#endif
|
|
|
|
|
2014-10-05 04:11:10 +08:00
|
|
|
#else // !__APPLE__ && !__ELF__
|
|
|
|
|
2014-12-10 10:36:22 +08:00
|
|
|
#define HIDDEN(name)
|
2014-05-19 02:39:15 +08:00
|
|
|
#define LOCAL_LABEL(name) .L ## name
|
2014-10-07 10:39:13 +08:00
|
|
|
#define FILE_LEVEL_DIRECTIVE
|
2014-05-19 02:39:15 +08:00
|
|
|
#define SYMBOL_IS_FUNC(name) \
|
|
|
|
.def name SEPARATOR \
|
2014-06-21 09:41:21 +08:00
|
|
|
.scl 2 SEPARATOR \
|
2014-05-19 02:39:15 +08:00
|
|
|
.type 32 SEPARATOR \
|
|
|
|
.endef
|
2014-12-10 10:36:22 +08:00
|
|
|
#define CONST_SECTION .section .rdata,"rd"
|
2014-10-07 10:39:13 +08:00
|
|
|
|
2016-06-23 06:09:42 +08:00
|
|
|
#define NO_EXEC_STACK_DIRECTIVE
|
|
|
|
|
2009-10-28 01:49:50 +08:00
|
|
|
#endif
|
|
|
|
|
2014-01-24 21:39:51 +08:00
|
|
|
#if defined(__arm__)
|
2014-05-16 14:16:21 +08:00
|
|
|
#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
|
|
|
|
#define ARM_HAS_BX
|
|
|
|
#endif
|
2016-12-08 02:41:07 +08:00
|
|
|
#if !defined(__ARM_FEATURE_CLZ) && __ARM_ARCH_ISA_THUMB != 1 && \
|
|
|
|
(__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))
|
2014-05-16 14:16:21 +08:00
|
|
|
#define __ARM_FEATURE_CLZ
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ARM_HAS_BX
|
|
|
|
#define JMP(r) bx r
|
2014-07-21 04:00:26 +08:00
|
|
|
#define JMPc(r, c) bx##c r
|
2014-05-16 14:16:21 +08:00
|
|
|
#else
|
|
|
|
#define JMP(r) mov pc, r
|
|
|
|
#define JMPc(r, c) mov##c pc, r
|
|
|
|
#endif
|
2014-07-27 10:01:20 +08:00
|
|
|
|
2015-08-21 08:25:37 +08:00
|
|
|
// pop {pc} can't switch Thumb mode on ARMv4T
|
|
|
|
#if __ARM_ARCH >= 5
|
|
|
|
#define POP_PC() pop {pc}
|
|
|
|
#else
|
|
|
|
#define POP_PC() \
|
|
|
|
pop {ip}; \
|
|
|
|
JMP(ip)
|
|
|
|
#endif
|
|
|
|
|
2017-03-25 01:06:00 +08:00
|
|
|
/*
|
|
|
|
* Determine actual [ARM][THUMB[1][2]] ISA using compiler predefined macros:
|
|
|
|
* - for '-mthumb -march=armv6' compiler defines '__thumb__'
|
|
|
|
* - for '-mthumb -march=armv7' compiler defines '__thumb__' and '__thumb2__'
|
|
|
|
*/
|
|
|
|
#if defined(__thumb2__)
|
|
|
|
#define USE_THUMB_2 1
|
|
|
|
#elif defined(__thumb__)
|
|
|
|
#define USE_THUMB_1 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_THUMB_1) && defined(USE_THUMB_2)
|
|
|
|
#error "USE_THUMB_1 and USE_THUMB_2 can't be defined together."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_THUMB_1) || defined(USE_THUMB_1)
|
|
|
|
#define USE_THUMB_PROLOGUE 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_THUMB_2)
|
2014-07-27 10:01:20 +08:00
|
|
|
#define IT(cond) it cond
|
|
|
|
#define ITT(cond) itt cond
|
2017-03-25 01:06:00 +08:00
|
|
|
#define WIDE(op) op.w
|
2014-07-27 10:01:20 +08:00
|
|
|
#else
|
|
|
|
#define IT(cond)
|
|
|
|
#define ITT(cond)
|
2014-07-27 10:01:24 +08:00
|
|
|
#define WIDE(op) op
|
|
|
|
#endif
|
2017-03-25 01:06:00 +08:00
|
|
|
#endif /* defined(__arm__) */
|
2014-05-16 14:16:21 +08:00
|
|
|
|
|
|
|
#define GLUE2(a, b) a##b
|
2011-04-20 05:22:14 +08:00
|
|
|
#define GLUE(a, b) GLUE2(a, b)
|
|
|
|
#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
|
|
|
|
|
2012-02-11 00:41:46 +08:00
|
|
|
#ifdef VISIBILITY_HIDDEN
|
2014-05-16 14:16:21 +08:00
|
|
|
#define DECLARE_SYMBOL_VISIBILITY(name) \
|
2014-05-19 02:39:10 +08:00
|
|
|
HIDDEN(SYMBOL_NAME(name)) SEPARATOR
|
2010-01-19 06:19:34 +08:00
|
|
|
#else
|
2011-08-23 05:49:47 +08:00
|
|
|
#define DECLARE_SYMBOL_VISIBILITY(name)
|
|
|
|
#endif
|
|
|
|
|
2014-05-16 14:16:21 +08:00
|
|
|
#define DEFINE_COMPILERRT_FUNCTION(name) \
|
|
|
|
FILE_LEVEL_DIRECTIVE SEPARATOR \
|
|
|
|
.globl SYMBOL_NAME(name) SEPARATOR \
|
|
|
|
SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
|
|
|
|
DECLARE_SYMBOL_VISIBILITY(name) \
|
2009-10-28 01:49:50 +08:00
|
|
|
SYMBOL_NAME(name):
|
|
|
|
|
2014-10-04 08:18:59 +08:00
|
|
|
#define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \
|
|
|
|
FILE_LEVEL_DIRECTIVE SEPARATOR \
|
|
|
|
.globl SYMBOL_NAME(name) SEPARATOR \
|
|
|
|
SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
|
2014-10-07 10:39:13 +08:00
|
|
|
DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \
|
2014-10-07 11:00:17 +08:00
|
|
|
.thumb_func SEPARATOR \
|
2014-10-04 08:18:59 +08:00
|
|
|
SYMBOL_NAME(name):
|
|
|
|
|
2014-05-16 14:16:21 +08:00
|
|
|
#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
|
|
|
|
FILE_LEVEL_DIRECTIVE SEPARATOR \
|
|
|
|
.globl SYMBOL_NAME(name) SEPARATOR \
|
|
|
|
SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
|
2014-05-19 02:39:10 +08:00
|
|
|
HIDDEN(SYMBOL_NAME(name)) SEPARATOR \
|
2009-10-28 01:49:50 +08:00
|
|
|
SYMBOL_NAME(name):
|
|
|
|
|
2014-05-16 14:16:21 +08:00
|
|
|
#define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \
|
|
|
|
.globl name SEPARATOR \
|
|
|
|
SYMBOL_IS_FUNC(name) SEPARATOR \
|
2014-05-19 02:39:10 +08:00
|
|
|
HIDDEN(name) SEPARATOR \
|
2010-01-19 06:19:20 +08:00
|
|
|
name:
|
|
|
|
|
2014-05-16 14:16:21 +08:00
|
|
|
#define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \
|
|
|
|
.globl SYMBOL_NAME(name) SEPARATOR \
|
|
|
|
SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
|
2016-10-29 07:37:50 +08:00
|
|
|
DECLARE_SYMBOL_VISIBILITY(SYMBOL_NAME(name)) SEPARATOR \
|
2011-04-20 01:51:24 +08:00
|
|
|
.set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR
|
|
|
|
|
2014-05-16 14:16:21 +08:00
|
|
|
#if defined(__ARM_EABI__)
|
|
|
|
#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \
|
2011-04-20 01:51:24 +08:00
|
|
|
DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name)
|
|
|
|
#else
|
2014-05-16 14:16:21 +08:00
|
|
|
#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)
|
2011-04-20 01:51:24 +08:00
|
|
|
#endif
|
|
|
|
|
2014-01-24 02:31:46 +08:00
|
|
|
#ifdef __ELF__
|
2014-05-16 14:16:21 +08:00
|
|
|
#define END_COMPILERRT_FUNCTION(name) \
|
|
|
|
.size SYMBOL_NAME(name), . - SYMBOL_NAME(name)
|
2014-01-24 02:31:46 +08:00
|
|
|
#else
|
|
|
|
#define END_COMPILERRT_FUNCTION(name)
|
|
|
|
#endif
|
|
|
|
|
2009-10-28 01:49:50 +08:00
|
|
|
#endif /* COMPILERRT_ASSEMBLY_H */
|