]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/aarch64/sysdep.h
d3ff68589597cd58297a8630c9f9d45fb741988d
[thirdparty/glibc.git] / sysdeps / aarch64 / sysdep.h
1 /* Copyright (C) 1997-2019 Free Software Foundation, Inc.
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
17 <http://www.gnu.org/licenses/>. */
18
19 #ifndef _AARCH64_SYSDEP_H
20 #define _AARCH64_SYSDEP_H
21
22 #include <sysdeps/generic/sysdep.h>
23
24 #ifdef __LP64__
25 # define AARCH64_R(NAME) R_AARCH64_ ## NAME
26 # define PTR_REG(n) x##n
27 # define PTR_LOG_SIZE 3
28 # define DELOUSE(n)
29 #else
30 # define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME
31 # define PTR_REG(n) w##n
32 # define PTR_LOG_SIZE 2
33 # define DELOUSE(n) mov w##n, w##n
34 #endif
35
36 #define PTR_SIZE (1<<PTR_LOG_SIZE)
37
38 #ifdef __ASSEMBLER__
39
40 /* Syntactic details of assembler. */
41
42 #define ASM_SIZE_DIRECTIVE(name) .size name,.-name
43
44 /* Define an entry point visible from C. */
45 #define ENTRY(name) \
46 .globl C_SYMBOL_NAME(name); \
47 .type C_SYMBOL_NAME(name),%function; \
48 .align 4; \
49 C_LABEL(name) \
50 cfi_startproc; \
51 CALL_MCOUNT
52
53 /* Define an entry point visible from C. */
54 #define ENTRY_ALIGN(name, align) \
55 .globl C_SYMBOL_NAME(name); \
56 .type C_SYMBOL_NAME(name),%function; \
57 .p2align align; \
58 C_LABEL(name) \
59 cfi_startproc; \
60 CALL_MCOUNT
61
62 /* Define an entry point visible from C with a specified alignment and
63 pre-padding with NOPs. This can be used to ensure that a critical
64 loop within a function is cache line aligned. Note this version
65 does not adjust the padding if CALL_MCOUNT is defined. */
66
67 #define ENTRY_ALIGN_AND_PAD(name, align, padding) \
68 .globl C_SYMBOL_NAME(name); \
69 .type C_SYMBOL_NAME(name),%function; \
70 .p2align align; \
71 .rep padding; \
72 nop; \
73 .endr; \
74 C_LABEL(name) \
75 cfi_startproc; \
76 CALL_MCOUNT
77
78 #undef END
79 #define END(name) \
80 cfi_endproc; \
81 ASM_SIZE_DIRECTIVE(name)
82
83 /* If compiled for profiling, call `mcount' at the start of each function. */
84 #ifdef PROF
85 # define CALL_MCOUNT \
86 str x30, [sp, #-80]!; \
87 cfi_adjust_cfa_offset (80); \
88 cfi_rel_offset (x30, 0); \
89 stp x0, x1, [sp, #16]; \
90 cfi_rel_offset (x0, 16); \
91 cfi_rel_offset (x1, 24); \
92 stp x2, x3, [sp, #32]; \
93 cfi_rel_offset (x2, 32); \
94 cfi_rel_offset (x3, 40); \
95 stp x4, x5, [sp, #48]; \
96 cfi_rel_offset (x4, 48); \
97 cfi_rel_offset (x5, 56); \
98 stp x6, x7, [sp, #64]; \
99 cfi_rel_offset (x6, 64); \
100 cfi_rel_offset (x7, 72); \
101 mov x0, x30; \
102 bl mcount; \
103 ldp x0, x1, [sp, #16]; \
104 cfi_restore (x0); \
105 cfi_restore (x1); \
106 ldp x2, x3, [sp, #32]; \
107 cfi_restore (x2); \
108 cfi_restore (x3); \
109 ldp x4, x5, [sp, #48]; \
110 cfi_restore (x4); \
111 cfi_restore (x5); \
112 ldp x6, x7, [sp, #64]; \
113 cfi_restore (x6); \
114 cfi_restore (x7); \
115 ldr x30, [sp], #80; \
116 cfi_adjust_cfa_offset (-80); \
117 cfi_restore (x30);
118 #else
119 # define CALL_MCOUNT /* Do nothing. */
120 #endif
121
122 /* Local label name for asm code. */
123 #ifndef L
124 # define L(name) .L##name
125 #endif
126
127 /* Load or store to/from a pc-relative EXPR into/from R, using T.
128 Note R and T are register numbers and not register names. */
129 #define LDST_PCREL(OP, R, T, EXPR) \
130 adrp x##T, EXPR; \
131 OP PTR_REG (R), [x##T, #:lo12:EXPR]; \
132
133 /* Load or store to/from a got-relative EXPR into/from R, using T.
134 Note R and T are register numbers and not register names. */
135 #define LDST_GLOBAL(OP, R, T, EXPR) \
136 adrp x##T, :got:EXPR; \
137 ldr PTR_REG (T), [x##T, #:got_lo12:EXPR]; \
138 OP PTR_REG (R), [x##T];
139
140 /* Load an immediate into R.
141 Note R is a register number and not a register name. */
142 #ifdef __LP64__
143 # define MOVL(R, NAME) \
144 movz PTR_REG (R), #:abs_g3:NAME; \
145 movk PTR_REG (R), #:abs_g2_nc:NAME; \
146 movk PTR_REG (R), #:abs_g1_nc:NAME; \
147 movk PTR_REG (R), #:abs_g0_nc:NAME;
148 #else
149 # define MOVL(R, NAME) \
150 movz PTR_REG (R), #:abs_g1:NAME; \
151 movk PTR_REG (R), #:abs_g0_nc:NAME;
152 #endif
153
154 /* Since C identifiers are not normally prefixed with an underscore
155 on this system, the asm identifier `syscall_error' intrudes on the
156 C name space. Make sure we use an innocuous name. */
157 #define syscall_error __syscall_error
158 #define mcount _mcount
159
160 #endif /* __ASSEMBLER__ */
161
162 #endif /* _AARCH64_SYSDEP_H */