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