blob: 07b08f94bd81606c7e7970c804653169af50913d [file] [log] [blame]
Saleem Abdulrasool17552662015-04-24 19:39:17 +00001/* ===-- 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
Martin Storsjo8338b0a2018-01-02 22:11:30 +000019#if defined(__powerpc64__)
20#define SEPARATOR ;
Martin Storsjo6518fcb2018-01-16 20:54:10 +000021#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
Martin Storsjo8338b0a2018-01-02 22:11:30 +000032#elif defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
Saleem Abdulrasool17552662015-04-24 19:39:17 +000033#define SEPARATOR @
34#elif defined(__arm64__)
35#define SEPARATOR %%
36#else
37#define SEPARATOR ;
38#endif
39
Saleem Abdulrasool17552662015-04-24 19:39:17 +000040#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__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000045
Saleem Abdulrasool17552662015-04-24 19:39:17 +000046#define SYMBOL_IS_FUNC(name)
Martin Storsjo6038ed32017-10-22 19:39:26 +000047#define HIDDEN_SYMBOL(name) .private_extern name
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000048#define NO_EXEC_STACK_DIRECTIVE
49
Saleem Abdulrasool17552662015-04-24 19:39:17 +000050#elif defined(__ELF__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000051
Saleem Abdulrasool17552662015-04-24 19:39:17 +000052#if defined(__arm__)
53#define SYMBOL_IS_FUNC(name) .type name,%function
54#else
55#define SYMBOL_IS_FUNC(name) .type name,@function
56#endif
Martin Storsjo6038ed32017-10-22 19:39:26 +000057#define HIDDEN_SYMBOL(name) .hidden name
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000058
Manoj Guptad8b79152017-05-16 20:18:57 +000059#if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
60 defined(__linux__)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000061#define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
Saleem Abdulrasool17552662015-04-24 19:39:17 +000062#else
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000063#define NO_EXEC_STACK_DIRECTIVE
64#endif
65
Martin Storsjo6038ed32017-10-22 19:39:26 +000066#elif defined(_WIN32)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000067
Saleem Abdulrasool17552662015-04-24 19:39:17 +000068#define SYMBOL_IS_FUNC(name) \
69 .def name SEPARATOR \
70 .scl 2 SEPARATOR \
71 .type 32 SEPARATOR \
72 .endef
Martin Storsjo6038ed32017-10-22 19:39:26 +000073#define HIDDEN_SYMBOL(name)
Saleem Abdulrasool85e5b232016-08-05 21:35:28 +000074
75#define NO_EXEC_STACK_DIRECTIVE
76
Martin Storsjo6038ed32017-10-22 19:39:26 +000077#else
78
79#error Unsupported target
80
Saleem Abdulrasool17552662015-04-24 19:39:17 +000081#endif
82
83#define DEFINE_LIBUNWIND_FUNCTION(name) \
84 .globl SYMBOL_NAME(name) SEPARATOR \
85 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
86 SYMBOL_NAME(name):
87
88#define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name) \
89 .globl SYMBOL_NAME(name) SEPARATOR \
Martin Storsjo6038ed32017-10-22 19:39:26 +000090 HIDDEN_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \
Saleem Abdulrasool17552662015-04-24 19:39:17 +000091 SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
92 SYMBOL_NAME(name):
93
94#if defined(__arm__)
95#if !defined(__ARM_ARCH)
96#define __ARM_ARCH 4
97#endif
98
99#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
100#define ARM_HAS_BX
101#endif
102
103#ifdef ARM_HAS_BX
104#define JMP(r) bx r
105#else
106#define JMP(r) mov pc, r
107#endif
108#endif /* __arm__ */
109
110#endif /* UNWIND_ASSEMBLY_H */