1 | /* |
2 | * Copyright (c) 2007 Apple Inc. All rights reserved. |
3 | * |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
5 | * |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License |
8 | * Version 2.0 (the 'License'). You may not use this file except in |
9 | * compliance with the License. The rights granted to you under the License |
10 | * may not be used to create, or enable the creation or redistribution of, |
11 | * unlawful or unlicensed copies of an Apple operating system, or to |
12 | * circumvent, violate, or enable the circumvention or violation of, any |
13 | * terms of an Apple operating system software license agreement. |
14 | * |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. |
17 | * |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and |
24 | * limitations under the License. |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
27 | */ |
28 | /* |
29 | * @OSF_COPYRIGHT@ |
30 | */ |
31 | /* |
32 | * Mach Operating System |
33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University |
34 | * All Rights Reserved. |
35 | * |
36 | * Permission to use, copy, modify and distribute this software and its |
37 | * documentation is hereby granted, provided that both the copyright |
38 | * notice and this permission notice appear in all copies of the |
39 | * software, derivative works or modified versions, and any portions |
40 | * thereof, and that both notices appear in supporting documentation. |
41 | * |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. |
45 | * |
46 | * Carnegie Mellon requests users of this software to return to |
47 | * |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
49 | * School of Computer Science |
50 | * Carnegie Mellon University |
51 | * Pittsburgh PA 15213-3890 |
52 | * |
53 | * any improvements or extensions that they make and grant Carnegie Mellon |
54 | * the rights to redistribute these changes. |
55 | */ |
56 | |
57 | #ifndef _ARM_ASM_H_ |
58 | #define _ARM_ASM_H_ |
59 | |
60 | #ifdef __arm64__ |
61 | |
62 | #include <arm/arch.h> |
63 | |
64 | /* There is another definition of ALIGN for .c sources */ |
65 | #ifdef __ASSEMBLER__ |
66 | #define ALIGN 2 |
67 | #endif /* ASSEMBLER */ |
68 | |
69 | #ifndef FALIGN |
70 | #define FALIGN ALIGN |
71 | #endif |
72 | |
73 | #define LB(x,n) n |
74 | #if __STDC__ |
75 | #ifndef __NO_UNDERSCORES__ |
76 | #define LCL(x) L ## x |
77 | #define EXT(x) _ ## x |
78 | #define LEXT(x) _ ## x ## : |
79 | #else |
80 | #define LCL(x) .L ## x |
81 | #define EXT(x) x |
82 | #define LEXT(x) x ## : |
83 | #endif |
84 | #define LBc(x,n) n ## : |
85 | #define LBb(x,n) n ## b |
86 | #define LBf(x,n) n ## f |
87 | #else /* __STDC__ */ |
88 | #ifndef __NO_UNDERSCORES__ |
89 | #define LCL(x) L/**/x |
90 | #define EXT(x) _/**/x |
91 | #define LEXT(x) _/**/x/**/: |
92 | #else /* __NO_UNDERSCORES__ */ |
93 | #define LCL(x) .L/**/x |
94 | #define EXT(x) x |
95 | #define LEXT(x) x/**/: |
96 | #endif /* __NO_UNDERSCORES__ */ |
97 | #define LBc(x,n) n/**/: |
98 | #define LBb(x,n) n/**/b |
99 | #define LBf(x,n) n/**/f |
100 | #endif /* __STDC__ */ |
101 | |
102 | #define String .asciz |
103 | #define Value .word |
104 | #define Times(a,b) (a*b) |
105 | #define Divide(a,b) (a/b) |
106 | |
107 | #ifdef __ASSEMBLER__ |
108 | #if MACH_KDB |
109 | #include <ddb/stab.h> |
110 | /* |
111 | * This pseudo-assembler line is added so that there will be at least |
112 | * one N_SO entry in the symbol stable to define the current file name. |
113 | */ |
114 | #endif /* MACH_KDB */ |
115 | |
116 | /* |
117 | * Multiline macros must use .macro syntax for now, |
118 | * as there is no ARM64 statement separator. |
119 | */ |
120 | .macro ENTRY |
121 | .align FALIGN |
122 | .globl _$0 |
123 | _$0 : |
124 | .endmacro |
125 | |
126 | .macro ENTRY2 |
127 | .align FALIGN |
128 | .globl _$0 |
129 | .globl _$1 |
130 | _$0 : |
131 | _$1 : |
132 | .endmacro |
133 | |
134 | .macro READ_THREAD |
135 | mrs $0, TPIDR_EL1 |
136 | .endmacro |
137 | |
138 | .macro BRANCH_EXTERN |
139 | b _$0 |
140 | .endmacro |
141 | |
142 | .macro CALL_EXTERN |
143 | bl _$0 |
144 | .endmacro |
145 | |
146 | .macro MOV64 |
147 | movk $0, #((($1) >> 48) & 0x000000000000FFFF), lsl #48 |
148 | movk $0, #((($1) >> 32) & 0x000000000000FFFF), lsl #32 |
149 | movk $0, #((($1) >> 16) & 0x000000000000FFFF), lsl #16 |
150 | movk $0, #((($1) >> 00) & 0x000000000000FFFF), lsl #00 |
151 | .endmacro |
152 | |
153 | .macro MOV32 |
154 | movz $0, #((($1) >> 16) & 0x000000000000FFFF), lsl #16 |
155 | movk $0, #((($1) >> 00) & 0x000000000000FFFF), lsl #00 |
156 | .endmacro |
157 | |
158 | .macro ARM64_STACK_PROLOG |
159 | #if __has_feature(ptrauth_returns) |
160 | pacibsp |
161 | #endif |
162 | .endmacro |
163 | |
164 | .macro ARM64_STACK_EPILOG |
165 | #if __has_feature(ptrauth_returns) |
166 | retab |
167 | #else |
168 | ret |
169 | #endif |
170 | .endmacro |
171 | |
172 | /** |
173 | * Push a stack frame. |
174 | * |
175 | * Most callers should invoke ARM64_STACK_PROLOG first, since otherwise this will |
176 | * push an unsigned return address onto the stack. |
177 | */ |
178 | #define PUSH_FRAME \ |
179 | stp fp, lr, [sp, #-16]! %% \ |
180 | mov fp, sp %% |
181 | |
182 | /** |
183 | * Pop the most recent stack frame. |
184 | * |
185 | * Note: if the complementary PUSH_FRAME was not preceded by ARM64_STACK_PROLOG, |
186 | * then this operation could load an attacker-controlled return address from |
187 | * memory! Either add ARM64_STACK_PROLOG, or use POP_FRAME_WITHOUT_LR if there |
188 | * are no plans to ever use the popped LR. |
189 | */ |
190 | #define POP_FRAME \ |
191 | mov sp, fp %% \ |
192 | ldp fp, lr, [sp], #16 %% |
193 | |
194 | /** |
195 | * Pop the most recent stack frame, but do not update LR. |
196 | * |
197 | * This macro is intended for situations like kernel entry, where the caller |
198 | * doesn't actually need to preserve LR, but wants to push a stack frame |
199 | * anyway for the benefit of unwinders. |
200 | */ |
201 | #define POP_FRAME_WITHOUT_LR \ |
202 | mov sp, fp %% \ |
203 | ldp fp, xzr, [sp], #16 %% |
204 | |
205 | #define EXT(x) _ ## x |
206 | |
207 | #ifdef XNU_KERNEL_PRIVATE |
208 | .macro PANIC_UNIMPLEMENTED |
209 | bl EXT(panic_unimplemented) |
210 | .endmacro |
211 | #endif |
212 | |
213 | #else /* NOT __ASSEMBLER__ */ |
214 | |
215 | /* These defines are here for .c files that wish to reference global symbols |
216 | * within __asm__ statements. |
217 | */ |
218 | #ifndef __NO_UNDERSCORES__ |
219 | #define CC_SYM_PREFIX "_" |
220 | #else |
221 | #define CC_SYM_PREFIX "" |
222 | #endif /* __NO_UNDERSCORES__ */ |
223 | #endif /* __ASSEMBLER__ */ |
224 | |
225 | #ifdef __ASSEMBLER__ |
226 | |
227 | # define BRANCH_EXTERN(x) b EXT(x) |
228 | |
229 | #endif /* __ASSEMBLER__ */ |
230 | |
231 | #endif /* __arm64__ */ |
232 | |
233 | #endif /* _ARM_ASM_H_ */ |
234 | |