]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/aarch64/sysdep.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / aarch64 / sysdep.h
CommitLineData
2b778ceb 1/* Copyright (C) 1997-2021 Free Software Foundation, Inc.
554066b8
MS
2
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
554066b8 18
389d1f1b
SE
19#ifndef _AARCH64_SYSDEP_H
20#define _AARCH64_SYSDEP_H
21
554066b8
MS
22#include <sysdeps/generic/sysdep.h>
23
389d1f1b
SE
24#ifdef __LP64__
25# define AARCH64_R(NAME) R_AARCH64_ ## NAME
26# define PTR_REG(n) x##n
27# define PTR_LOG_SIZE 3
45b1e17e
SN
28# define PTR_ARG(n)
29# define SIZE_ARG(n)
389d1f1b
SE
30#else
31# define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME
32# define PTR_REG(n) w##n
33# define PTR_LOG_SIZE 2
45b1e17e
SN
34# define PTR_ARG(n) mov w##n, w##n
35# define SIZE_ARG(n) mov w##n, w##n
389d1f1b
SE
36#endif
37
38#define PTR_SIZE (1<<PTR_LOG_SIZE)
39
c9476771
SN
40#ifndef __ASSEMBLER__
41/* Strip pointer authentication code from pointer p. */
42static inline void *
43strip_pac (void *p)
44{
45 register void *ra asm ("x30") = (p);
46 asm ("hint 7 // xpaclri" : "+r"(ra));
47 return ra;
48}
d174ec24
SN
49
50/* This is needed when glibc is built with -mbranch-protection=pac-ret
51 with a gcc that is affected by PR target/94891. */
52# if HAVE_AARCH64_PAC_RET
53# undef RETURN_ADDRESS
54# define RETURN_ADDRESS(n) strip_pac (__builtin_return_address (n))
55# endif
c9476771
SN
56#endif
57
554066b8
MS
58#ifdef __ASSEMBLER__
59
60/* Syntactic details of assembler. */
61
62#define ASM_SIZE_DIRECTIVE(name) .size name,.-name
63
91181954
SD
64/* Branch Target Identitication support. */
65#define BTI_C hint 34
66#define BTI_J hint 36
67
1be3d6eb
SN
68/* Return address signing support (pac-ret). */
69#define PACIASP hint 25
70#define AUTIASP hint 29
71
91181954
SD
72/* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */
73#define FEATURE_1_AND 0xc0000000
74#define FEATURE_1_BTI 1
75#define FEATURE_1_PAC 2
76
77/* Add a NT_GNU_PROPERTY_TYPE_0 note. */
78#define GNU_PROPERTY(type, value) \
79 .section .note.gnu.property, "a"; \
80 .p2align 3; \
81 .word 4; \
82 .word 16; \
83 .word 5; \
84 .asciz "GNU"; \
85 .word type; \
86 .word 4; \
87 .word value; \
88 .word 0; \
89 .text
90
91/* Add GNU property note with the supported features to all asm code
92 where sysdep.h is included. */
1be3d6eb
SN
93#if HAVE_AARCH64_BTI && HAVE_AARCH64_PAC_RET
94GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC)
95#elif HAVE_AARCH64_BTI
91181954
SD
96GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI)
97#endif
98
554066b8 99/* Define an entry point visible from C. */
62216a0a
MS
100#define ENTRY(name) \
101 .globl C_SYMBOL_NAME(name); \
102 .type C_SYMBOL_NAME(name),%function; \
34f0d01d 103 .p2align 6; \
62216a0a
MS
104 C_LABEL(name) \
105 cfi_startproc; \
91181954 106 BTI_C; \
554066b8
MS
107 CALL_MCOUNT
108
14d941e4
MS
109/* Define an entry point visible from C. */
110#define ENTRY_ALIGN(name, align) \
111 .globl C_SYMBOL_NAME(name); \
112 .type C_SYMBOL_NAME(name),%function; \
113 .p2align align; \
114 C_LABEL(name) \
115 cfi_startproc; \
91181954 116 BTI_C; \
14d941e4
MS
117 CALL_MCOUNT
118
4499bb3e
MS
119/* Define an entry point visible from C with a specified alignment and
120 pre-padding with NOPs. This can be used to ensure that a critical
121 loop within a function is cache line aligned. Note this version
122 does not adjust the padding if CALL_MCOUNT is defined. */
123
124#define ENTRY_ALIGN_AND_PAD(name, align, padding) \
125 .globl C_SYMBOL_NAME(name); \
126 .type C_SYMBOL_NAME(name),%function; \
127 .p2align align; \
91181954 128 .rep padding - 1; /* -1 for bti c. */ \
4499bb3e
MS
129 nop; \
130 .endr; \
131 C_LABEL(name) \
132 cfi_startproc; \
91181954 133 BTI_C; \
4499bb3e
MS
134 CALL_MCOUNT
135
554066b8 136#undef END
62216a0a
MS
137#define END(name) \
138 cfi_endproc; \
554066b8
MS
139 ASM_SIZE_DIRECTIVE(name)
140
141/* If compiled for profiling, call `mcount' at the start of each function. */
142#ifdef PROF
62216a0a 143# define CALL_MCOUNT \
efbe665c
SN
144 str x30, [sp, #-80]!; \
145 cfi_adjust_cfa_offset (80); \
146 cfi_rel_offset (x30, 0); \
147 stp x0, x1, [sp, #16]; \
148 cfi_rel_offset (x0, 16); \
149 cfi_rel_offset (x1, 24); \
150 stp x2, x3, [sp, #32]; \
151 cfi_rel_offset (x2, 32); \
152 cfi_rel_offset (x3, 40); \
153 stp x4, x5, [sp, #48]; \
154 cfi_rel_offset (x4, 48); \
155 cfi_rel_offset (x5, 56); \
156 stp x6, x7, [sp, #64]; \
157 cfi_rel_offset (x6, 64); \
158 cfi_rel_offset (x7, 72); \
159 mov x0, x30; \
62216a0a 160 bl mcount; \
efbe665c
SN
161 ldp x0, x1, [sp, #16]; \
162 cfi_restore (x0); \
163 cfi_restore (x1); \
164 ldp x2, x3, [sp, #32]; \
165 cfi_restore (x2); \
166 cfi_restore (x3); \
167 ldp x4, x5, [sp, #48]; \
168 cfi_restore (x4); \
169 cfi_restore (x5); \
170 ldp x6, x7, [sp, #64]; \
171 cfi_restore (x6); \
172 cfi_restore (x7); \
173 ldr x30, [sp], #80; \
174 cfi_adjust_cfa_offset (-80); \
175 cfi_restore (x30);
554066b8
MS
176#else
177# define CALL_MCOUNT /* Do nothing. */
178#endif
179
180/* Local label name for asm code. */
181#ifndef L
182# define L(name) .L##name
183#endif
184
389d1f1b
SE
185/* Load or store to/from a pc-relative EXPR into/from R, using T.
186 Note R and T are register numbers and not register names. */
187#define LDST_PCREL(OP, R, T, EXPR) \
188 adrp x##T, EXPR; \
189 OP PTR_REG (R), [x##T, #:lo12:EXPR]; \
9188b681 190
389d1f1b
SE
191/* Load or store to/from a got-relative EXPR into/from R, using T.
192 Note R and T are register numbers and not register names. */
193#define LDST_GLOBAL(OP, R, T, EXPR) \
194 adrp x##T, :got:EXPR; \
195 ldr PTR_REG (T), [x##T, #:got_lo12:EXPR]; \
196 OP PTR_REG (R), [x##T];
9188b681 197
6cd380dd
WB
198/* Load an immediate into R.
199 Note R is a register number and not a register name. */
200#ifdef __LP64__
201# define MOVL(R, NAME) \
202 movz PTR_REG (R), #:abs_g3:NAME; \
203 movk PTR_REG (R), #:abs_g2_nc:NAME; \
204 movk PTR_REG (R), #:abs_g1_nc:NAME; \
205 movk PTR_REG (R), #:abs_g0_nc:NAME;
206#else
207# define MOVL(R, NAME) \
208 movz PTR_REG (R), #:abs_g1:NAME; \
209 movk PTR_REG (R), #:abs_g0_nc:NAME;
210#endif
211
554066b8
MS
212/* Since C identifiers are not normally prefixed with an underscore
213 on this system, the asm identifier `syscall_error' intrudes on the
214 C name space. Make sure we use an innocuous name. */
215#define syscall_error __syscall_error
216#define mcount _mcount
217
218#endif /* __ASSEMBLER__ */
389d1f1b
SE
219
220#endif /* _AARCH64_SYSDEP_H */