xref: /freebsd/contrib/arm-optimized-routines/string/aarch64/asmdefs.h (revision 5f4c09dd85bff675e0ca63c55ea3c517e0fddfcc)
1 /*
2  * Macros for asm code.  AArch64 version.
3  *
4  * Copyright (c) 2019-2023, Arm Limited.
5  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
6  */
7 
8 #ifndef _ASMDEFS_H
9 #define _ASMDEFS_H
10 
11 /* Branch Target Identitication support.  */
12 #define BTI_C		hint	34
13 #define BTI_J		hint	36
14 /* Return address signing support (pac-ret).  */
15 #define PACIASP		hint	25; .cfi_window_save
16 #define AUTIASP		hint	29; .cfi_window_save
17 
18 /* GNU_PROPERTY_AARCH64_* macros from elf.h.  */
19 #define FEATURE_1_AND 0xc0000000
20 #define FEATURE_1_BTI 1
21 #define FEATURE_1_PAC 2
22 
23 /* Add a NT_GNU_PROPERTY_TYPE_0 note.  */
24 #define GNU_PROPERTY(type, value)	\
25   .section .note.gnu.property, "a";	\
26   .p2align 3;				\
27   .word 4;				\
28   .word 16;				\
29   .word 5;				\
30   .asciz "GNU";				\
31   .word type;				\
32   .word 4;				\
33   .word value;				\
34   .word 0;				\
35   .text
36 
37 /* If set then the GNU Property Note section will be added to
38    mark objects to support BTI and PAC-RET.  */
39 #ifndef WANT_GNU_PROPERTY
40 #define WANT_GNU_PROPERTY 1
41 #endif
42 
43 #if WANT_GNU_PROPERTY
44 /* Add property note with supported features to all asm files.  */
45 GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC)
46 #endif
47 
48 #define ENTRY_ALIGN(name, alignment)	\
49   .global name;		\
50   .type name,%function;	\
51   .align alignment;		\
52   name:			\
53   .cfi_startproc;	\
54   BTI_C;
55 
56 #define ENTRY(name)	ENTRY_ALIGN(name, 6)
57 
58 #define ENTRY_ALIAS(name)	\
59   .global name;		\
60   .type name,%function;	\
61   name:
62 
63 #define END(name)	\
64   .cfi_endproc;		\
65   .size name, .-name;
66 
67 #define L(l) .L ## l
68 
69 #ifdef __ILP32__
70   /* Sanitize padding bits of pointer arguments as per aapcs64 */
71 #define PTR_ARG(n)  mov w##n, w##n
72 #else
73 #define PTR_ARG(n)
74 #endif
75 
76 #ifdef __ILP32__
77   /* Sanitize padding bits of size arguments as per aapcs64 */
78 #define SIZE_ARG(n)  mov w##n, w##n
79 #else
80 #define SIZE_ARG(n)
81 #endif
82 
83 /* Compiler supports SVE instructions  */
84 #ifndef HAVE_SVE
85 # if __aarch64__ && (__GNUC__ >= 8 || __clang_major__ >= 5)
86 #   define HAVE_SVE 1
87 # else
88 #   define HAVE_SVE 0
89 # endif
90 #endif
91 
92 #endif
93