xref: /linux/tools/testing/selftests/arm64/bti/assembler.h (revision feafee284579d29537a5a56ba8f23894f0463f3d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2019  Arm Limited
4  * Original author: Dave Martin <Dave.Martin@arm.com>
5  */
6 
7 #ifndef ASSEMBLER_H
8 #define ASSEMBLER_H
9 
10 #define NT_GNU_PROPERTY_TYPE_0	5
11 #define GNU_PROPERTY_AARCH64_FEATURE_1_AND	0xc0000000
12 
13 /* Bits for GNU_PROPERTY_AARCH64_FEATURE_1_BTI */
14 #define GNU_PROPERTY_AARCH64_FEATURE_1_BTI	(1U << 0)
15 #define GNU_PROPERTY_AARCH64_FEATURE_1_PAC	(1U << 1)
16 
17 .macro startfn name:req
18 	.globl \name
19 \name:
20 	.macro endfn
21 		.size \name, . - \name
22 		.type \name, @function
23 		.purgem endfn
24 	.endm
25 .endm
26 
27 .macro emit_aarch64_feature_1_and
28 	.pushsection .note.gnu.property, "a"
29 	.align	3
30 	.long	2f - 1f
31 	.long	6f - 3f
32 	.long	NT_GNU_PROPERTY_TYPE_0
33 1:	.string	"GNU"
34 2:
35 	.align	3
36 3:	.long	GNU_PROPERTY_AARCH64_FEATURE_1_AND
37 	.long	5f - 4f
38 4:
39 #if BTI
40 	.long	GNU_PROPERTY_AARCH64_FEATURE_1_PAC | \
41 		GNU_PROPERTY_AARCH64_FEATURE_1_BTI
42 #else
43 	.long	0
44 #endif
45 5:
46 	.align	3
47 6:
48 	.popsection
49 .endm
50 
51 .macro paciasp
52 	hint	0x19
53 .endm
54 
55 .macro autiasp
56 	hint	0x1d
57 .endm
58 
59 .macro __bti_
60 	hint	0x20
61 .endm
62 
63 .macro __bti_c
64 	hint	0x22
65 .endm
66 
67 .macro __bti_j
68 	hint	0x24
69 .endm
70 
71 .macro __bti_jc
72 	hint	0x26
73 .endm
74 
75 .macro bti what=
76 	__bti_\what
77 .endm
78 
79 #endif /* ! ASSEMBLER_H */
80