]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/i386/sdt_isa.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / mach / i386 / sdt_isa.h
1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #ifndef _MACH_I386_SDT_ISA_H
28 #define _MACH_I386_SDT_ISA_H
29
30 /*
31 * Only define when testing. This makes the calls into actual calls to
32 * test functions.
33 */
34 /* #define DTRACE_CALL_TEST */
35
36 #define DTRACE_STRINGIFY(s) #s
37 #define DTRACE_TOSTRING(s) DTRACE_STRINGIFY(s)
38 #if defined(KERNEL)
39 /*
40 * For the kernel, set an explicit global label so the symbol can be located
41 */
42 #ifdef __x86_64__
43
44 #define DTRACE_LABEL(p, n) \
45 ".pushsection __DATA, __sdt_cstring, cstring_literals\n\t" \
46 "1: .ascii \"" DTRACE_STRINGIFY(p##___) "\\0\"\n\t" \
47 "2: .ascii \"" DTRACE_STRINGIFY(n) "\\0\"\n\t" \
48 ".popsection" "\n\t" \
49 ".pushsection __DATA, __sdt, regular, live_support\n\t" \
50 ".p2align 3\n\t" \
51 "l3_%=:\n\t" \
52 ".quad 4f" "\n\t" \
53 ".quad 1b" "\n\t" \
54 ".quad 2b" "\n\t" \
55 ".popsection" "\n\t" \
56 "4:"
57 #else
58
59 #define DTRACE_LABEL(p, n) \
60 ".pushsection __DATA, __sdt_cstring, cstring_literals\n\t" \
61 "1: .ascii \"" DATA_STRINGIFY(p##___) "\\0\"\n\t" \
62 "2: .ascii \"" DATA_STRINGIFY(n) "\\0\"\n\t" \
63 ".popsection" "\n\t" \
64 ".pushsection __DATA, __sdt, regular, live_support\n\t" \
65 ".p2align 3\n\t" \
66 "l3_%=:\n\t" \
67 ".long 4f""\n\t" \
68 ".long 1b""\n\t" \
69 ".long 2b""\n\t" \
70 ".popsection" "\n\t" \
71 "4:"
72 #endif
73 #else /* !KERNEL */
74 #define DTRACE_LABEL(p, n) \
75 "__dtrace_probe$" DTRACE_TOSTRING(%=__LINE__) DTRACE_STRINGIFY(_##p##___##n) ":" "\n\t"
76 #endif /* !KERNEL */
77
78 #ifdef DTRACE_CALL_TEST
79
80 #define DTRACE_CALL(p, n) \
81 DTRACE_LABEL(p,n) \
82 DTRACE_CALL_INSN(p,n)
83
84 #else
85
86 #define DTRACE_CALL(p, n) \
87 DTRACE_LABEL(p,n) \
88 DTRACE_NOPS
89
90 #endif
91
92 #ifdef __x86_64__
93
94 #define DTRACE_NOPS \
95 "nop" "\n\t" \
96 "nop" "\n\t" \
97 "nop" "\n\t"
98
99 #define DTRACE_CALL_INSN(p, n) \
100 "call _dtracetest" DTRACE_STRINGIFY(_##p##_##n) "\n\t"
101
102 #define ARG1_EXTENT 1
103 #define ARGS2_EXTENT 2
104 #define ARGS3_EXTENT 3
105 #define ARGS4_EXTENT 4
106 #define ARGS5_EXTENT 5
107 #define ARGS6_EXTENT 6
108 #define ARGS7_EXTENT 7
109 #define ARGS8_EXTENT 8
110 #define ARGS9_EXTENT 9
111 #define ARGS10_EXTENT 10
112
113 #define DTRACE_CALL0ARGS(provider, name) \
114 asm volatile ( \
115 DTRACE_CALL(provider, name) \
116 : \
117 : \
118 );
119
120 #define DTRACE_CALL1ARG(provider, name) \
121 asm volatile ("movq\t0x0(%0),%%rdi" "\n\t" \
122 DTRACE_CALL(provider, name) \
123 : \
124 : "r" (__dtrace_args) \
125 : "memory", "rdi" \
126 );
127
128 #define DTRACE_CALL2ARGS(provider, name) \
129 asm volatile ("movq\t0x0(%0),%%rdi" "\n\t" \
130 "movq\t0x8(%0),%%rsi" "\n\t" \
131 DTRACE_CALL(provider, name) \
132 : \
133 : "r" (__dtrace_args) \
134 : "memory", "rdi", "rsi" \
135 );
136
137 #define DTRACE_CALL3ARGS(provider, name) \
138 asm volatile ("movq\t0x0(%0),%%rdi" "\n\t" \
139 "movq\t0x8(%0),%%rsi" "\n\t" \
140 "movq\t0x10(%0),%%rdx" "\n\t" \
141 DTRACE_CALL(provider, name) \
142 : \
143 : "r" (__dtrace_args) \
144 : "memory", "rdi", "rsi", "rdx" \
145 );
146
147 #define DTRACE_CALL4ARGS(provider, name) \
148 asm volatile ("movq\t0x0(%0),%%rdi" "\n\t" \
149 "movq\t0x8(%0),%%rsi" "\n\t" \
150 "movq\t0x10(%0),%%rdx" "\n\t" \
151 "movq\t0x18(%0),%%rcx" "\n\t" \
152 DTRACE_CALL(provider, name) \
153 : \
154 : "r" (__dtrace_args) \
155 : "memory", "rdi", "rsi", "rdx", "rcx" \
156 );
157
158 #define DTRACE_CALL5ARGS(provider, name) \
159 asm volatile ("movq\t0x0(%0),%%rdi" "\n\t" \
160 "movq\t0x8(%0),%%rsi" "\n\t" \
161 "movq\t0x10(%0),%%rdx" "\n\t" \
162 "movq\t0x18(%0),%%rcx" "\n\t" \
163 "movq\t0x20(%0),%%r8" "\n\t" \
164 DTRACE_CALL(provider, name) \
165 : \
166 : "r" (__dtrace_args) \
167 : "memory", "rdi", "rsi", "rdx", "rcx", "r8" \
168 );
169
170 #define DTRACE_CALL6ARGS(provider, name) \
171 asm volatile ("movq\t0x0(%0),%%rdi" "\n\t" \
172 "movq\t0x8(%0),%%rsi" "\n\t" \
173 "movq\t0x10(%0),%%rdx" "\n\t" \
174 "movq\t0x18(%0),%%rcx" "\n\t" \
175 "movq\t0x20(%0),%%r8" "\n\t" \
176 "movq\t0x28(%0),%%r9" "\n\t" \
177 DTRACE_CALL(provider, name) \
178 : \
179 : "r" (__dtrace_args) \
180 : "memory", "rdi", "rsi", "rdx", "rcx", "r8", "r9" \
181 );
182
183 #define DTRACE_CALL7ARGS(provider, name) \
184 asm volatile ("subq\t$0x8,%%rsp" "\n\t" \
185 "movq\t0x0(%0),%%rdi" "\n\t" \
186 "movq\t0x8(%0),%%rsi" "\n\t" \
187 "movq\t0x10(%0),%%rdx" "\n\t" \
188 "movq\t0x18(%0),%%rcx" "\n\t" \
189 "movq\t0x20(%0),%%r8" "\n\t" \
190 "movq\t0x28(%0),%%r9" "\n\t" \
191 "movq\t0x30(%0),%%rax" "\n\t" \
192 "movq\t%%rax,0x0(%%rsp)" "\n\t" \
193 DTRACE_CALL(provider, name) \
194 "addq\t$0x8,%%rsp" "\n\t" \
195 : \
196 : "r" (__dtrace_args) \
197 : "memory", "rdi", "rsi", "rdx", "rcx", "r8", "r9", "rax" \
198 );
199
200 #define DTRACE_CALL8ARGS(provider, name) \
201 asm volatile ("subq\t$0x10,%%rsp" "\n\t" \
202 "movq\t0x0(%0),%%rdi" "\n\t" \
203 "movq\t0x8(%0),%%rsi" "\n\t" \
204 "movq\t0x10(%0),%%rdx" "\n\t" \
205 "movq\t0x18(%0),%%rcx" "\n\t" \
206 "movq\t0x20(%0),%%r8" "\n\t" \
207 "movq\t0x28(%0),%%r9" "\n\t" \
208 "movq\t0x30(%0),%%rax" "\n\t" \
209 "movq\t%%rax,0x0(%%rsp)" "\n\t" \
210 "movq\t0x38(%0),%%rax" "\n\t" \
211 "movq\t%%rax,0x8(%%rsp)" "\n\t" \
212 DTRACE_CALL(provider, name) \
213 "addq\t$0x10,%%rsp" "\n\t" \
214 : \
215 : "r" (__dtrace_args) \
216 : "memory", "rdi", "rsi", "rdx", "rcx", "r8", "r9", "rax" \
217 );
218
219 #endif // __x86_64__
220
221 #ifdef __i386__
222
223 #define DTRACE_NOPS \
224 "nop" "\n\t" \
225 "leal 0(%%esi), %%esi" "\n\t"
226
227 #define DTRACE_CALL_INSN(p, n) \
228 "call _dtracetest" DTRACE_STRINGIFY(_##p##_##n) "\n\t"
229
230 #define ARG1_EXTENT 1
231 #define ARGS2_EXTENT 2
232 #define ARGS3_EXTENT 4
233 #define ARGS4_EXTENT 4
234 #define ARGS5_EXTENT 8
235 #define ARGS6_EXTENT 8
236 #define ARGS7_EXTENT 8
237 #define ARGS8_EXTENT 8
238 #define ARGS9_EXTENT 12
239 #define ARGS10_EXTENT 12
240
241 /*
242 * Because this code is used in the kernel, we must not touch any floating point
243 * or specialized registers. This leaves the following registers:
244 *
245 * eax ; volatile, safe to use
246 * ebx ; PIC register, gcc error when used
247 * ecx ; volatile, safe to use
248 * edx ; volatile, safe to use
249 * esi ; non-volatile, otherwise safe to use
250 * edi ; non-volatile, otherwise safe to use
251 *
252 * Using any of the non volatile register causes a spill to stack which is almost
253 * certainly a net performance loss. Also, note that the array ref (__dtrace_args)
254 * consumes one free register. If all three of the volatile regs are used for load/store,
255 * the compiler will spill a register to hold the array ref.
256 *
257 * The end result is that we only pipeline two loads/stores at a time. Blech.
258 */
259
260 #define DTRACE_CALL0ARGS(provider, name) \
261 asm volatile ( \
262 DTRACE_CALL(provider, name) \
263 "# eat trailing nl +tabfrom DTRACE_CALL" \
264 : \
265 : \
266 );
267
268 #define DTRACE_CALL1ARG(provider, name) \
269 asm volatile ("subl\t$0x10,%%esp" "\n\t" \
270 "movl\t0x0(%0),%%eax" "\n\t" \
271 "movl\t%%eax,0x0(%%esp)" "\n\t" \
272 DTRACE_CALL(provider, name) \
273 "addl\t$0x10,%%esp" \
274 : \
275 : "r" (__dtrace_args) \
276 : "memory", "eax" \
277 );
278
279 #define DTRACE_CALL2ARGS(provider, name) \
280 asm volatile ("subl\t$0x10,%%esp" "\n\t" \
281 "movl\t0x0(%0),%%eax" "\n\t" \
282 "movl\t0x4(%0),%%edx" "\n\t" \
283 "movl\t%%eax,0x0(%%esp)" "\n\t" \
284 "movl\t%%edx,0x4(%%esp)" "\n\t" \
285 DTRACE_CALL(provider, name) \
286 "addl\t$0x10,%%esp" \
287 : \
288 : "r" (__dtrace_args) \
289 : "memory", "eax", "edx" \
290 );
291
292 #define DTRACE_CALL3ARGS(provider, name) \
293 asm volatile ("subl\t$0x10,%%esp" "\n\t" \
294 "movl\t0x0(%0),%%eax" "\n\t" \
295 "movl\t0x4(%0),%%edx" "\n\t" \
296 "movl\t%%eax,0x0(%%esp)" "\n\t" \
297 "movl\t%%edx,0x4(%%esp)" "\n\t" \
298 "movl\t0x8(%0),%%eax" "\n\t" \
299 "movl\t%%eax,0x8(%%esp)" "\n\t" \
300 DTRACE_CALL(provider, name) \
301 "addl\t$0x10,%%esp" \
302 : \
303 : "r" (__dtrace_args) \
304 : "memory", "eax", "edx" \
305 );
306
307 #define DTRACE_CALL4ARGS(provider, name) \
308 asm volatile ("subl\t$0x10,%%esp" "\n\t" \
309 "movl\t0x0(%0),%%eax" "\n\t" \
310 "movl\t0x4(%0),%%edx" "\n\t" \
311 "movl\t%%eax,0x0(%%esp)" "\n\t" \
312 "movl\t%%edx,0x4(%%esp)" "\n\t" \
313 "movl\t0x8(%0),%%eax" "\n\t" \
314 "movl\t0xC(%0),%%edx" "\n\t" \
315 "movl\t%%eax,0x8(%%esp)" "\n\t" \
316 "movl\t%%edx,0xC(%%esp)" "\n\t" \
317 DTRACE_CALL(provider, name) \
318 "addl\t$0x10,%%esp" \
319 : \
320 : "r" (__dtrace_args) \
321 : "memory", "eax", "edx" \
322 );
323
324 #define DTRACE_CALL5ARGS(provider, name) \
325 asm volatile ("subl\t$0x20,%%esp" "\n\t" \
326 "movl\t0x0(%0),%%eax" "\n\t" \
327 "movl\t0x4(%0),%%edx" "\n\t" \
328 "movl\t%%eax,0x0(%%esp)" "\n\t" \
329 "movl\t%%edx,0x4(%%esp)" "\n\t" \
330 "movl\t0x8(%0),%%eax" "\n\t" \
331 "movl\t0xC(%0),%%edx" "\n\t" \
332 "movl\t%%eax,0x8(%%esp)" "\n\t" \
333 "movl\t%%edx,0xC(%%esp)" "\n\t" \
334 "movl\t0x10(%0),%%eax" "\n\t" \
335 "movl\t%%eax,0x10(%%esp)" "\n\t" \
336 DTRACE_CALL(provider, name) \
337 "addl\t$0x20,%%esp" \
338 : \
339 : "r" (__dtrace_args) \
340 : "memory", "eax", "edx" \
341 );
342
343 #define DTRACE_CALL6ARGS(provider, name) \
344 asm volatile ("subl\t$0x20,%%esp" "\n\t" \
345 "movl\t0x0(%0),%%eax" "\n\t" \
346 "movl\t0x4(%0),%%edx" "\n\t" \
347 "movl\t%%eax,0x0(%%esp)" "\n\t" \
348 "movl\t%%edx,0x4(%%esp)" "\n\t" \
349 "movl\t0x8(%0),%%eax" "\n\t" \
350 "movl\t0xC(%0),%%edx" "\n\t" \
351 "movl\t%%eax,0x8(%%esp)" "\n\t" \
352 "movl\t%%edx,0xC(%%esp)" "\n\t" \
353 "movl\t0x10(%0),%%eax" "\n\t" \
354 "movl\t0x14(%0),%%edx" "\n\t" \
355 "movl\t%%eax,0x10(%%esp)" "\n\t" \
356 "movl\t%%edx,0x14(%%esp)" "\n\t" \
357 DTRACE_CALL(provider, name) \
358 "addl\t$0x20,%%esp" \
359 : \
360 : "r" (__dtrace_args) \
361 : "memory", "eax", "edx" \
362 );
363
364 #define DTRACE_CALL7ARGS(provider, name) \
365 asm volatile ("subl\t$0x20,%%esp" "\n\t" \
366 "movl\t0x0(%0),%%eax" "\n\t" \
367 "movl\t0x4(%0),%%edx" "\n\t" \
368 "movl\t%%eax,0x0(%%esp)" "\n\t" \
369 "movl\t%%edx,0x4(%%esp)" "\n\t" \
370 "movl\t0x8(%0),%%eax" "\n\t" \
371 "movl\t0xC(%0),%%edx" "\n\t" \
372 "movl\t%%eax,0x8(%%esp)" "\n\t" \
373 "movl\t%%edx,0xC(%%esp)" "\n\t" \
374 "movl\t0x10(%0),%%eax" "\n\t" \
375 "movl\t0x14(%0),%%edx" "\n\t" \
376 "movl\t%%eax,0x10(%%esp)" "\n\t" \
377 "movl\t%%edx,0x14(%%esp)" "\n\t" \
378 "movl\t0x18(%0),%%eax" "\n\t" \
379 "movl\t%%eax,0x18(%%esp)" "\n\t" \
380 DTRACE_CALL(provider, name) \
381 "addl\t$0x20,%%esp" \
382 : \
383 : "r" (__dtrace_args) \
384 : "memory", "eax", "edx" \
385 );
386
387 #define DTRACE_CALL8ARGS(provider, name) \
388 asm volatile ("subl\t$0x20,%%esp" "\n\t" \
389 "movl\t0x0(%0),%%eax" "\n\t" \
390 "movl\t0x4(%0),%%edx" "\n\t" \
391 "movl\t%%eax,0x0(%%esp)" "\n\t" \
392 "movl\t%%edx,0x4(%%esp)" "\n\t" \
393 "movl\t0x8(%0),%%eax" "\n\t" \
394 "movl\t0xC(%0),%%edx" "\n\t" \
395 "movl\t%%eax,0x8(%%esp)" "\n\t" \
396 "movl\t%%edx,0xC(%%esp)" "\n\t" \
397 "movl\t0x10(%0),%%eax" "\n\t" \
398 "movl\t0x14(%0),%%edx" "\n\t" \
399 "movl\t%%eax,0x10(%%esp)" "\n\t" \
400 "movl\t%%edx,0x14(%%esp)" "\n\t" \
401 "movl\t0x18(%0),%%eax" "\n\t" \
402 "movl\t0x1C(%0),%%edx" "\n\t" \
403 "movl\t%%eax,0x18(%%esp)" "\n\t" \
404 "movl\t%%edx,0x1C(%%esp)" "\n\t" \
405 DTRACE_CALL(provider, name) \
406 "addl\t$0x20,%%esp" \
407 : \
408 : "r" (__dtrace_args) \
409 : "memory", "eax", "edx" \
410 );
411
412 #define DTRACE_CALL9ARGS(provider, name) \
413 asm volatile ("subl\t$0x30,%%esp" "\n\t" \
414 "movl\t0x0(%0),%%eax" "\n\t" \
415 "movl\t0x4(%0),%%edx" "\n\t" \
416 "movl\t%%eax,0x0(%%esp)" "\n\t" \
417 "movl\t%%edx,0x4(%%esp)" "\n\t" \
418 "movl\t0x8(%0),%%eax" "\n\t" \
419 "movl\t0xC(%0),%%edx" "\n\t" \
420 "movl\t%%eax,0x8(%%esp)" "\n\t" \
421 "movl\t%%edx,0xC(%%esp)" "\n\t" \
422 "movl\t0x10(%0),%%eax" "\n\t" \
423 "movl\t0x14(%0),%%edx" "\n\t" \
424 "movl\t%%eax,0x10(%%esp)" "\n\t" \
425 "movl\t%%edx,0x14(%%esp)" "\n\t" \
426 "movl\t0x18(%0),%%eax" "\n\t" \
427 "movl\t0x1C(%0),%%edx" "\n\t" \
428 "movl\t%%eax,0x18(%%esp)" "\n\t" \
429 "movl\t%%edx,0x1C(%%esp)" "\n\t" \
430 "movl\t0x20(%0),%%eax" "\n\t" \
431 "movl\t%%eax,0x20(%%esp)" "\n\t" \
432 DTRACE_CALL(provider, name) \
433 "addl\t$0x30,%%esp" \
434 : \
435 : "r" (__dtrace_args) \
436 : "memory", "eax", "edx" \
437 );
438
439 #define DTRACE_CALL10ARGS(provider, name) \
440 asm volatile ("subl\t$0x30,%%esp" "\n\t" \
441 "movl\t0x0(%0),%%eax" "\n\t" \
442 "movl\t0x4(%0),%%edx" "\n\t" \
443 "movl\t%%eax,0x0(%%esp)" "\n\t" \
444 "movl\t%%edx,0x4(%%esp)" "\n\t" \
445 "movl\t0x8(%0),%%eax" "\n\t" \
446 "movl\t0xC(%0),%%edx" "\n\t" \
447 "movl\t%%eax,0x8(%%esp)" "\n\t" \
448 "movl\t%%edx,0xC(%%esp)" "\n\t" \
449 "movl\t0x10(%0),%%eax" "\n\t" \
450 "movl\t0x14(%0),%%edx" "\n\t" \
451 "movl\t%%eax,0x10(%%esp)" "\n\t" \
452 "movl\t%%edx,0x14(%%esp)" "\n\t" \
453 "movl\t0x18(%0),%%eax" "\n\t" \
454 "movl\t0x1C(%0),%%edx" "\n\t" \
455 "movl\t%%eax,0x18(%%esp)" "\n\t" \
456 "movl\t%%edx,0x1C(%%esp)" "\n\t" \
457 "movl\t0x20(%0),%%eax" "\n\t" \
458 "movl\t0x24(%0),%%edx" "\n\t" \
459 "movl\t%%eax,0x20(%%esp)" "\n\t" \
460 "movl\t%%edx,0x24(%%esp)" "\n\t" \
461 DTRACE_CALL(provider, name) \
462 "addl\t$0x30,%%esp" \
463 : \
464 : "r" (__dtrace_args) \
465 : "memory", "eax", "edx" \
466 );
467
468 #endif // __i386__
469
470 #endif /* _MACH_I386_SDT_ISA_H */