]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/arm/sdt_isa.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / mach / arm / sdt_isa.h
1 /*
2 * Copyright (c) 2007 Apple Inc. All rights reserved.
3 */
4 /*
5 * CDDL HEADER START
6 *
7 * The contents of this file are subject to the terms of the
8 * Common Development and Distribution License, Version 1.0 only
9 * (the "License"). You may not use this file except in compliance
10 * with the License.
11 *
12 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
13 * or http://www.opensolaris.org/os/licensing.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 *
17 * When distributing Covered Code, include this CDDL HEADER in each
18 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
19 * If applicable, add the following below this CDDL HEADER, with the
20 * fields enclosed by brackets "[]" replaced with your own identifying
21 * information: Portions Copyright [yyyy] [name of copyright owner]
22 *
23 * CDDL HEADER END
24 */
25 /*
26 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 */
29
30 #ifndef _MACH_ARM_SDT_ISA_H
31 #define _MACH_ARM_SDT_ISA_H
32
33 /*
34 * Only define when testing. This makes the calls into actual calls to
35 * test functions.
36 */
37 /* #define DTRACE_CALL_TEST */
38
39 #define DTRACE_STRINGIFY(s) #s
40 #define DTRACE_TOSTRING(s) DTRACE_STRINGIFY(s)
41
42 #if defined(KERNEL)
43 /*
44 * For the kernel, set an explicit global label so the symbol can be located
45 */
46 #ifdef __arm__
47
48 #define DTRACE_LABEL(p, n) \
49 ".pushsection __DATA, __sdt_cstring, cstring_literals\n\t" \
50 "1: .ascii \"" DTRACE_STRINGIFY(p##___) "\\0\"\n\t" \
51 "2: .ascii \"" DTRACE_STRINGIFY(n) "\\0\"\n\t" \
52 ".popsection" "\n\t" \
53 ".pushsection __DATA, __sdt, regular, live_support\n\t" \
54 ".p2align 2\n\t" \
55 "l3_%=:\n\t" \
56 ".long 4f""\n\t" \
57 ".long 1b""\n\t" \
58 ".long 2b""\n\t" \
59 ".popsection" "\n\t" \
60 "4:"
61 #else /* __arm64__ */
62
63 #define DTRACE_LABEL(p, n) \
64 ".pushsection __DATA, __sdt_cstring, cstring_literals\n\t" \
65 "1: .ascii \"" DTRACE_STRINGIFY(p##___) "\\0\"\n\t" \
66 "2: .ascii \"" DTRACE_STRINGIFY(n) "\\0\"\n\t" \
67 ".popsection" "\n\t" \
68 ".pushsection __DATA, __sdt, regular, live_support\n\t" \
69 ".p2align 3\n\t" \
70 "l3_%=:\n\t" \
71 ".quad 4f""\n\t" \
72 ".quad 1b""\n\t" \
73 ".quad 2b""\n\t" \
74 ".popsection" "\n\t" \
75 "4:"
76 #endif
77 #else /* !KERNEL */
78 #define DTRACE_LABEL(p, n) \
79 "__dtrace_probe$" DTRACE_TOSTRING(%=__LINE__) DTRACE_STRINGIFY(_##p##___##n) ":" "\n\t"
80 #endif /* !KERNEL */
81
82 #ifdef DTRACE_CALL_TEST
83
84 #define DTRACE_CALL(p, n) \
85 DTRACE_LABEL(p,n) \
86 DTRACE_CALL_INSN(p,n)
87
88 #else /* !DTRACE_CALL_TEST */
89
90 #define DTRACE_CALL(p, n) \
91 DTRACE_LABEL(p,n) \
92 DTRACE_NOPS
93
94 #endif /* !DTRACE_CALL_TEST */
95
96 #if defined(__arm__)
97
98 #define DTRACE_NOPS \
99 "nop" "\n\t"
100
101 #define DTRACE_CALL_INSN(p, n) \
102 "blx _dtracetest" DTRACE_STRINGIFY(_##p##_##n) "\n\t"
103
104 #ifdef __thumb__
105 #define DTRACE_ALLOC_STACK(n) \
106 "sub sp, #" #n "\n\t"
107 #define DTRACE_DEALLOC_STACK(n) \
108 "add sp, #" #n "\n\t"
109 #else
110 #define DTRACE_ALLOC_STACK(n) \
111 "sub sp, sp, #" #n "\n\t"
112 #define DTRACE_DEALLOC_STACK(n) \
113 "add sp, sp, #" #n "\n\t"
114 #endif
115
116 #define ARG1_EXTENT 1
117 #define ARGS2_EXTENT 2
118 #define ARGS3_EXTENT 3
119 #define ARGS4_EXTENT 4
120 #define ARGS5_EXTENT 5
121 #define ARGS6_EXTENT 6
122 #define ARGS7_EXTENT 7
123 #define ARGS8_EXTENT 8
124 #define ARGS9_EXTENT 9
125 #define ARGS10_EXTENT 10
126
127 #define DTRACE_CALL0ARGS(provider, name) \
128 asm volatile ( \
129 DTRACE_CALL(provider, name) \
130 "# eat trailing nl+tab from DTRACE_CALL" \
131 : \
132 : \
133 );
134
135 #define DTRACE_CALL1ARG(provider, name) \
136 asm volatile ("ldr r0, [%0]" "\n\t" \
137 DTRACE_CALL(provider, name) \
138 : \
139 : "l" (__dtrace_args) \
140 : "memory", "r0" \
141 );
142
143 #define DTRACE_CALL2ARGS(provider, name) \
144 asm volatile ("ldr r1, [%0, #4]" "\n\t" \
145 "ldr r0, [%0]" "\n\t" \
146 DTRACE_CALL(provider, name) \
147 : \
148 : "l" (__dtrace_args) \
149 : "memory", "r0", "r1" \
150 );
151
152 #define DTRACE_CALL3ARGS(provider, name) \
153 asm volatile ("ldr r2, [%0, #8]" "\n\t" \
154 "ldr r1, [%0, #4]" "\n\t" \
155 "ldr r0, [%0]" "\n\t" \
156 DTRACE_CALL(provider, name) \
157 : \
158 : "l" (__dtrace_args) \
159 : "memory", "r0", "r1", "r2" \
160 );
161
162 #define DTRACE_CALL4ARGS(provider, name) \
163 asm volatile ("ldr r3, [%0, #12]" "\n\t" \
164 "ldr r2, [%0, #8]" "\n\t" \
165 "ldr r1, [%0, #4]" "\n\t" \
166 "ldr r0, [%0]" "\n\t" \
167 DTRACE_CALL(provider, name) \
168 : \
169 : "l" (__dtrace_args) \
170 : "memory", "r0", "r1", "r2", "r3" \
171 );
172
173 /*
174 * One of our ARM32 ABIs (armv7k) mandates that the stack be aligned to 16 bytes.
175 * We currently apply this constraint to all ARM32 DTRACE_CALL macros; hence the
176 * macros below will overallocate for some ABIs.
177 */
178 #define DTRACE_CALL5ARGS(provider, name) \
179 asm volatile ( \
180 DTRACE_ALLOC_STACK(16) \
181 "ldr r0, [%0, #16]" "\n\t" \
182 "str r0, [sp]" "\n\t" \
183 "ldr r3, [%0, #12]" "\n\t" \
184 "ldr r2, [%0, #8]" "\n\t" \
185 "ldr r1, [%0, #4]" "\n\t" \
186 "ldr r0, [%0]" "\n\t" \
187 DTRACE_CALL(provider, name) \
188 DTRACE_DEALLOC_STACK(16) \
189 : \
190 : "l" (__dtrace_args) \
191 : "memory", "r0", "r1", "r2", "r3" \
192 );
193
194 #define DTRACE_CALL6ARGS(provider, name) \
195 asm volatile ( \
196 DTRACE_ALLOC_STACK(16) \
197 "ldr r1, [%0, #20]" "\n\t" \
198 "ldr r0, [%0, #16]" "\n\t" \
199 "str r1, [sp, #4]" "\n\t" \
200 "str r0, [sp]" "\n\t" \
201 "ldr r3, [%0, #12]" "\n\t" \
202 "ldr r2, [%0, #8]" "\n\t" \
203 "ldr r1, [%0, #4]" "\n\t" \
204 "ldr r0, [%0]" "\n\t" \
205 DTRACE_CALL(provider, name) \
206 DTRACE_DEALLOC_STACK(16) \
207 : \
208 : "l" (__dtrace_args) \
209 : "memory", "r0", "r1", "r2", "r3" \
210 );
211
212 #define DTRACE_CALL7ARGS(provider, name) \
213 asm volatile ( \
214 DTRACE_ALLOC_STACK(16) \
215 "ldr r2, [%0, #24]" "\n\t" \
216 "ldr r1, [%0, #20]" "\n\t" \
217 "ldr r0, [%0, #16]" "\n\t" \
218 "str r2, [sp, #8]" "\n\t" \
219 "str r1, [sp, #4]" "\n\t" \
220 "str r0, [sp]" "\n\t" \
221 "ldr r3, [%0, #12]" "\n\t" \
222 "ldr r2, [%0, #8]" "\n\t" \
223 "ldr r1, [%0, #4]" "\n\t" \
224 "ldr r0, [%0]" "\n\t" \
225 DTRACE_CALL(provider, name) \
226 DTRACE_DEALLOC_STACK(16) \
227 : \
228 : "l" (__dtrace_args) \
229 : "memory", "r0", "r1", "r2", "r3" \
230 );
231
232 #define DTRACE_CALL8ARGS(provider, name) \
233 asm volatile ( \
234 DTRACE_ALLOC_STACK(16) \
235 "ldr r3, [%0, #28]" "\n\t" \
236 "ldr r2, [%0, #24]" "\n\t" \
237 "ldr r1, [%0, #20]" "\n\t" \
238 "ldr r0, [%0, #16]" "\n\t" \
239 "str r3, [sp, #12]" "\n\t" \
240 "str r2, [sp, #8]" "\n\t" \
241 "str r1, [sp, #4]" "\n\t" \
242 "str r0, [sp]" "\n\t" \
243 "ldr r3, [%0, #12]" "\n\t" \
244 "ldr r2, [%0, #8]" "\n\t" \
245 "ldr r1, [%0, #4]" "\n\t" \
246 "ldr r0, [%0]" "\n\t" \
247 DTRACE_CALL(provider, name) \
248 DTRACE_DEALLOC_STACK(16) \
249 : \
250 : "l" (__dtrace_args) \
251 : "memory", "r0", "r1", "r2", "r3" \
252 );
253
254 #define DTRACE_CALL9ARGS(provider, name) \
255 asm volatile ( \
256 DTRACE_ALLOC_STACK(32) \
257 "ldr r0, [%0, #32]" "\n\t" \
258 "str r0, [sp, #16]" "\n\t" \
259 "ldr r3, [%0, #28]" "\n\t" \
260 "ldr r2, [%0, #24]" "\n\t" \
261 "ldr r1, [%0, #20]" "\n\t" \
262 "ldr r0, [%0, #16]" "\n\t" \
263 "str r3, [sp, #12]" "\n\t" \
264 "str r2, [sp, #8]" "\n\t" \
265 "str r1, [sp, #4]" "\n\t" \
266 "str r0, [sp]" "\n\t" \
267 "ldr r3, [%0, #12]" "\n\t" \
268 "ldr r2, [%0, #8]" "\n\t" \
269 "ldr r1, [%0, #4]" "\n\t" \
270 "ldr r0, [%0]" "\n\t" \
271 DTRACE_CALL(provider, name) \
272 DTRACE_DEALLOC_STACK(32) \
273 : \
274 : "l" (__dtrace_args) \
275 : "memory", "r0", "r1", "r2", "r3" \
276 );
277
278 #define DTRACE_CALL10ARGS(provider, name) \
279 asm volatile ( \
280 DTRACE_ALLOC_STACK(32) \
281 "ldr r1, [%0, #36]" "\n\t" \
282 "ldr r0, [%0, #32]" "\n\t" \
283 "str r1, [sp, #20]" "\n\t" \
284 "str r0, [sp, #16]" "\n\t" \
285 "ldr r3, [%0, #28]" "\n\t" \
286 "ldr r2, [%0, #24]" "\n\t" \
287 "ldr r1, [%0, #20]" "\n\t" \
288 "ldr r0, [%0, #16]" "\n\t" \
289 "str r3, [sp, #12]" "\n\t" \
290 "str r2, [sp, #8]" "\n\t" \
291 "str r1, [sp, #4]" "\n\t" \
292 "str r0, [sp]" "\n\t" \
293 "ldr r3, [%0, #12]" "\n\t" \
294 "ldr r2, [%0, #8]" "\n\t" \
295 "ldr r1, [%0, #4]" "\n\t" \
296 "ldr r0, [%0]" "\n\t" \
297 DTRACE_CALL(provider, name) \
298 DTRACE_DEALLOC_STACK(32) \
299 : \
300 : "l" (__dtrace_args) \
301 : "memory", "r0", "r1", "r2", "r3" \
302 );
303
304 #elif defined(__arm64__)
305
306 #define DTRACE_NOPS \
307 "nop" "\n\t"
308
309
310 #define DTRACE_CALL_INSN(p, n) \
311 "bl _dtracetest" DTRACE_STRINGIFY(_##p##_##n) "\n\t"
312
313 #define DTRACE_ALLOC_STACK(n) \
314 "sub sp, sp, #" #n "\n\t"
315 #define DTRACE_DEALLOC_STACK(n) \
316 "add sp, sp, #" #n "\n\t"
317
318 #define ARG1_EXTENT 1
319 #define ARGS2_EXTENT 2
320 #define ARGS3_EXTENT 3
321 #define ARGS4_EXTENT 4
322 #define ARGS5_EXTENT 5
323 #define ARGS6_EXTENT 6
324 #define ARGS7_EXTENT 7
325 #define ARGS8_EXTENT 8
326 #define ARGS9_EXTENT 9
327 #define ARGS10_EXTENT 10
328
329 #define DTRACE_CALL0ARGS(provider, name) \
330 asm volatile ( \
331 DTRACE_CALL(provider, name) \
332 "# eat trailing nl+tab from DTRACE_CALL" \
333 : \
334 : \
335 );
336
337 #define DTRACE_CALL1ARG(provider, name) \
338 asm volatile ("ldr x0, [%0]" "\n\t" \
339 DTRACE_CALL(provider, name) \
340 : \
341 : "r" (__dtrace_args) \
342 : "memory", "x0" \
343 );
344
345 #define DTRACE_CALL2ARGS(provider, name) \
346 asm volatile ("ldp x0, x1, [%0]" "\n\t" \
347 DTRACE_CALL(provider, name) \
348 : \
349 : "r" (__dtrace_args) \
350 : "memory", "x0", "x1" \
351 );
352
353 #define DTRACE_CALL3ARGS(provider, name) \
354 asm volatile ("ldr x2, [%0, #16]" "\n\t" \
355 "ldp x0, x1, [%0]" "\n\t" \
356 DTRACE_CALL(provider, name) \
357 : \
358 : "r" (__dtrace_args) \
359 : "memory", "x0", "x1", "x2" \
360 );
361
362 #define DTRACE_CALL4ARGS(provider, name) \
363 asm volatile ("ldp x2, x3, [%0, #16]" "\n\t" \
364 "ldp x0, x1, [%0]" "\n\t" \
365 DTRACE_CALL(provider, name) \
366 : \
367 : "r" (__dtrace_args) \
368 : "memory", "x0", "x1", "x2", "x3" \
369 );
370
371 #define DTRACE_CALL5ARGS(provider, name) \
372 asm volatile ("ldr x4, [%0, #32]" "\n\t" \
373 "ldp x2, x3, [%0, #16]" "\n\t" \
374 "ldp x0, x1, [%0]" "\n\t" \
375 DTRACE_CALL(provider, name) \
376 : \
377 : "r" (__dtrace_args) \
378 : "memory", "x0", "x1", "x2", "x3", "x4" \
379 );
380
381 #define DTRACE_CALL6ARGS(provider, name) \
382 asm volatile ("ldp x4, x5, [%0, #32]" "\n\t" \
383 "ldp x2, x3, [%0, #16]" "\n\t" \
384 "ldp x0, x1, [%0]" "\n\t" \
385 DTRACE_CALL(provider, name) \
386 : \
387 : "r" (__dtrace_args) \
388 : "memory", "x0", "x1", "x2", "x3", "x4", "x5" \
389 );
390
391 #define DTRACE_CALL7ARGS(provider, name) \
392 asm volatile ("ldr x6, [%0, #48]" "\n\t" \
393 "ldp x4, x5, [%0, #32]" "\n\t" \
394 "ldp x2, x3, [%0, #16]" "\n\t" \
395 "ldp x0, x1, [%0]" "\n\t" \
396 DTRACE_CALL(provider, name) \
397 : \
398 : "r" (__dtrace_args) \
399 : "memory", "x0", "x1", "x2", "x3", "x4", "x5", "x6" \
400 );
401
402 #define DTRACE_CALL8ARGS(provider, name) \
403 asm volatile ("ldp x6, x7, [%0, #48]" "\n\t" \
404 "ldp x4, x5, [%0, #32]" "\n\t" \
405 "ldp x2, x3, [%0, #16]" "\n\t" \
406 "ldp x0, x1, [%0]" "\n\t" \
407 DTRACE_CALL(provider, name) \
408 : \
409 : "r" (__dtrace_args) \
410 : "memory", "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7" \
411 );
412
413 /* Keep stack 16 byte aligned per ABI requirements */
414 #define DTRACE_CALL9ARGS(provider, name) \
415 asm volatile ( \
416 DTRACE_ALLOC_STACK(16) \
417 "ldr x0, [%0, #64]" "\n\t" \
418 "str x0, [sp]" "\n\t" \
419 "ldp x6, x7, [%0, #48]" "\n\t" \
420 "ldp x4, x5, [%0, #32]" "\n\t" \
421 "ldp x2, x3, [%0, #16]" "\n\t" \
422 "ldp x0, x1, [%0]" "\n\t" \
423 DTRACE_CALL(provider, name) \
424 DTRACE_DEALLOC_STACK(16) \
425 : \
426 : "r" (__dtrace_args) \
427 : "memory", "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7" \
428 );
429
430 #define DTRACE_CALL10ARGS(provider, name) \
431 asm volatile ( \
432 DTRACE_ALLOC_STACK(16) \
433 "ldp x0, x1, [%0, #64]" "\n\t" \
434 "stp x0, x1, [sp]" "\n\t" \
435 "ldp x6, x7, [%0, #48]" "\n\t" \
436 "ldp x4, x5, [%0, #32]" "\n\t" \
437 "ldp x2, x3, [%0, #16]" "\n\t" \
438 "ldp x0, x1, [%0]" "\n\t" \
439 DTRACE_CALL(provider, name) \
440 DTRACE_DEALLOC_STACK(16) \
441 : \
442 : "r" (__dtrace_args) \
443 : "memory", "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7" \
444 );
445
446 #endif /* __arm__ */
447
448 #endif /* _MACH_ARM_SDT_ISA_H */