master
1/* Copyright (C) 1997-2025 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 <https://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 __ASSEMBLER__
25
26/* CFI directive for return address. */
27#define cfi_negate_ra_state .cfi_negate_ra_state
28
29/* Syntactic details of assembler. */
30
31#define ASM_SIZE_DIRECTIVE(name) .size name,.-name
32
33/* Guarded Control Stack support. */
34#define CHKFEAT_X16 hint 40
35#define MRS_GCSPR(x) mrs x, s3_3_c2_c5_1
36#define GCSPOPM(x) sysl x, #3, c7, c7, #1
37#define GCSSS1(x) sys #3, c7, c7, #2, x
38#define GCSSS2(x) sysl x, #3, c7, c7, #3
39
40/* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */
41#define FEATURE_1_AND 0xc0000000
42#define FEATURE_1_BTI 1
43#define FEATURE_1_PAC 2
44#define FEATURE_1_GCS 4
45
46/* Add a NT_GNU_PROPERTY_TYPE_0 note. */
47#define GNU_PROPERTY(type, value) \
48 .section .note.gnu.property, "a"; \
49 .p2align 3; \
50 .word 4; \
51 .word 16; \
52 .word 5; \
53 .asciz "GNU"; \
54 .word type; \
55 .word 4; \
56 .word value; \
57 .word 0; \
58 .text
59
60/* Add GNU property note with the supported features to all asm code
61 where sysdep.h is included. */
62GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC|FEATURE_1_GCS)
63
64/* Define an entry point visible from C. */
65#define ENTRY(name) \
66 .globl C_SYMBOL_NAME(name); \
67 .type C_SYMBOL_NAME(name),%function; \
68 .p2align 6; \
69 C_LABEL(name) \
70 cfi_startproc; \
71 bti c; \
72 CALL_MCOUNT
73
74/* Define an entry point visible from C. */
75#define ENTRY_ALIGN(name, align) \
76 .globl C_SYMBOL_NAME(name); \
77 .type C_SYMBOL_NAME(name),%function; \
78 .p2align align; \
79 C_LABEL(name) \
80 cfi_startproc; \
81 bti c; \
82 CALL_MCOUNT
83
84/* Define an entry point visible from C with a specified alignment and
85 pre-padding with NOPs. This can be used to ensure that a critical
86 loop within a function is cache line aligned. Note this version
87 does not adjust the padding if CALL_MCOUNT is defined. */
88
89#define ENTRY_ALIGN_AND_PAD(name, align, padding) \
90 .globl C_SYMBOL_NAME(name); \
91 .type C_SYMBOL_NAME(name),%function; \
92 .p2align align; \
93 .rep padding - 1; /* -1 for bti c. */ \
94 nop; \
95 .endr; \
96 C_LABEL(name) \
97 cfi_startproc; \
98 bti c; \
99 CALL_MCOUNT
100
101#undef END
102#define END(name) \
103 cfi_endproc; \
104 ASM_SIZE_DIRECTIVE(name)
105
106/* If compiled for profiling, call `mcount' at the start of each function. */
107#ifdef PROF
108# define CALL_MCOUNT \
109 str x30, [sp, #-80]!; \
110 cfi_adjust_cfa_offset (80); \
111 cfi_rel_offset (x30, 0); \
112 stp x0, x1, [sp, #16]; \
113 cfi_rel_offset (x0, 16); \
114 cfi_rel_offset (x1, 24); \
115 stp x2, x3, [sp, #32]; \
116 cfi_rel_offset (x2, 32); \
117 cfi_rel_offset (x3, 40); \
118 stp x4, x5, [sp, #48]; \
119 cfi_rel_offset (x4, 48); \
120 cfi_rel_offset (x5, 56); \
121 stp x6, x7, [sp, #64]; \
122 cfi_rel_offset (x6, 64); \
123 cfi_rel_offset (x7, 72); \
124 mov x0, x30; \
125 bl mcount; \
126 ldp x0, x1, [sp, #16]; \
127 cfi_restore (x0); \
128 cfi_restore (x1); \
129 ldp x2, x3, [sp, #32]; \
130 cfi_restore (x2); \
131 cfi_restore (x3); \
132 ldp x4, x5, [sp, #48]; \
133 cfi_restore (x4); \
134 cfi_restore (x5); \
135 ldp x6, x7, [sp, #64]; \
136 cfi_restore (x6); \
137 cfi_restore (x7); \
138 ldr x30, [sp], #80; \
139 cfi_adjust_cfa_offset (-80); \
140 cfi_restore (x30);
141#else
142# define CALL_MCOUNT /* Do nothing. */
143#endif
144
145/* Local label name for asm code. */
146#ifndef L
147# define L(name) .L##name
148#endif
149
150/* Since C identifiers are not normally prefixed with an underscore
151 on this system, the asm identifier `syscall_error' intrudes on the
152 C name space. Make sure we use an innocuous name. */
153#define syscall_error __syscall_error
154#define mcount _mcount
155
156#endif /* __ASSEMBLER__ */
157
158#endif /* _AARCH64_SYSDEP_H */