]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/i386/sdt_isa.h
xnu-1504.15.3.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 #define DTRACE_LAB(p, n) \
44 "__dtrace_probeDOLLAR" DTRACE_TOSTRING(__LINE__) DTRACE_STRINGIFY(_##p##___##n)
45
46 #define DTRACE_LABEL(p, n) \
47 ".section __DATA, __data\n\t" \
48 ".globl " DTRACE_LAB(p, n) "\n\t" \
49 DTRACE_LAB(p, n) ":" ".quad 1f""\n\t" \
50 ".text" "\n\t" \
51 "1:"
52 #else
53 #define DTRACE_LAB(p, n) \
54 "__dtrace_probe$" DTRACE_TOSTRING(__LINE__) DTRACE_STRINGIFY(_##p##___##n)
55
56 #define DTRACE_LABEL(p, n) \
57 ".section __DATA, __data\n\t" \
58 ".globl " DTRACE_LAB(p, n) "\n\t" \
59 DTRACE_LAB(p, n) ":" ".long 1f""\n\t" \
60 ".text" "\n\t" \
61 "1:"
62 #endif
63 #else /* !KERNEL */
64 #define DTRACE_LABEL(p, n) \
65 "__dtrace_probe$" DTRACE_TOSTRING(__LINE__) DTRACE_STRINGIFY(_##p##___##n) ":" "\n\t"
66 #endif /* !KERNEL */
67
68 #ifdef DTRACE_CALL_TEST
69
70 #define DTRACE_CALL(p,n) \
71 DTRACE_LABEL(p,n) \
72 DTRACE_CALL_INSN(p,n)
73
74 #else
75
76 #define DTRACE_CALL(p,n) \
77 DTRACE_LABEL(p,n) \
78 DTRACE_NOPS
79
80 #endif
81
82 #ifdef __x86_64__
83
84 #define DTRACE_NOPS \
85 "nop" "\n\t" \
86 "nop" "\n\t" \
87 "nop" "\n\t"
88
89 #define DTRACE_CALL_INSN(p,n) \
90 "call _dtracetest" DTRACE_STRINGIFY(_##p##_##n) "\n\t"
91
92 #define ARG1_EXTENT 1
93 #define ARGS2_EXTENT 2
94 #define ARGS3_EXTENT 3
95 #define ARGS4_EXTENT 4
96 #define ARGS5_EXTENT 5
97 #define ARGS6_EXTENT 6
98 #define ARGS7_EXTENT 7
99 #define ARGS8_EXTENT 8
100 #define ARGS9_EXTENT 10
101 #define ARGS10_EXTENT 10
102
103 #define DTRACE_CALL0ARGS(provider, name) \
104 asm volatile ( \
105 DTRACE_CALL(provider, name) \
106 );
107
108 #define DTRACE_CALL1ARG(provider, name) \
109 asm volatile ("movq\t0x0(%0),%%rdi" "\n\t" \
110 DTRACE_CALL(provider, name) \
111 : \
112 : "r" (__dtrace_args) \
113 : "memory", "rdi" \
114 );
115
116 #define DTRACE_CALL2ARGS(provider, name) \
117 asm volatile ("movq\t0x0(%0),%%rdi" "\n\t" \
118 "movq\t0x8(%0),%%rsi" "\n\t" \
119 DTRACE_CALL(provider, name) \
120 : \
121 : "r" (__dtrace_args) \
122 : "memory", "rdi", "rsi" \
123 );
124
125 #define DTRACE_CALL3ARGS(provider, name) \
126 asm volatile ("movq\t0x0(%0),%%rdi" "\n\t" \
127 "movq\t0x8(%0),%%rsi" "\n\t" \
128 "movq\t0x10(%0),%%rdx" "\n\t" \
129 DTRACE_CALL(provider, name) \
130 : \
131 : "r" (__dtrace_args) \
132 : "memory", "rdi", "rsi", "rdx" \
133 );
134
135 #define DTRACE_CALL4ARGS(provider, name) \
136 asm volatile ("movq\t0x0(%0),%%rdi" "\n\t" \
137 "movq\t0x8(%0),%%rsi" "\n\t" \
138 "movq\t0x10(%0),%%rdx" "\n\t" \
139 "movq\t0x18(%0),%%rcx" "\n\t" \
140 DTRACE_CALL(provider, name) \
141 : \
142 : "r" (__dtrace_args) \
143 : "memory", "rdi", "rsi", "rdx", "rcx" \
144 );
145
146 #define DTRACE_CALL5ARGS(provider, name) \
147 asm volatile ("movq\t0x0(%0),%%rdi" "\n\t" \
148 "movq\t0x8(%0),%%rsi" "\n\t" \
149 "movq\t0x10(%0),%%rdx" "\n\t" \
150 "movq\t0x18(%0),%%rcx" "\n\t" \
151 "movq\t0x20(%0),%%r8" "\n\t" \
152 DTRACE_CALL(provider, name) \
153 : \
154 : "r" (__dtrace_args) \
155 : "memory", "rdi", "rsi", "rdx", "rcx", "r8" \
156 );
157
158 #define DTRACE_CALL6ARGS(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 "movq\t0x28(%0),%%r9" "\n\t" \
165 DTRACE_CALL(provider, name) \
166 : \
167 : "r" (__dtrace_args) \
168 : "memory", "rdi", "rsi", "rdx", "rcx", "r8", "r9" \
169 );
170
171 #define DTRACE_CALL7ARGS(provider, name) \
172 asm volatile ("subq\t$0x8,%%rsp" "\n\t" \
173 "movq\t0x0(%0),%%rdi" "\n\t" \
174 "movq\t0x8(%0),%%rsi" "\n\t" \
175 "movq\t0x10(%0),%%rdx" "\n\t" \
176 "movq\t0x18(%0),%%rcx" "\n\t" \
177 "movq\t0x20(%0),%%r8" "\n\t" \
178 "movq\t0x28(%0),%%r9" "\n\t" \
179 "movq\t0x30(%0),%%rax" "\n\t" \
180 "movq\t%%rax,0x0(%%rsp)" "\n\t" \
181 DTRACE_CALL(provider, name) \
182 "addq\t$0x8,%%rsp" "\n\t" \
183 : \
184 : "r" (__dtrace_args) \
185 : "memory", "rdi", "rsi", "rdx", "rcx", "r8", "r9", "rax" \
186 );
187
188 #endif // __x86_64__
189
190 #ifdef __i386__
191
192 #define DTRACE_NOPS \
193 "nop" "\n\t" \
194 "leal 0(%%esi), %%esi" "\n\t"
195
196 #define DTRACE_CALL_INSN(p,n) \
197 "call _dtracetest" DTRACE_STRINGIFY(_##p##_##n) "\n\t"
198
199 #define ARG1_EXTENT 1
200 #define ARGS2_EXTENT 2
201 #define ARGS3_EXTENT 4
202 #define ARGS4_EXTENT 4
203 #define ARGS5_EXTENT 8
204 #define ARGS6_EXTENT 8
205 #define ARGS7_EXTENT 8
206 #define ARGS8_EXTENT 8
207 #define ARGS9_EXTENT 12
208 #define ARGS10_EXTENT 12
209
210 /*
211 * Because this code is used in the kernel, we must not touch any floating point
212 * or specialized registers. This leaves the following registers:
213 *
214 * eax ; volatile, safe to use
215 * ebx ; PIC register, gcc error when used
216 * ecx ; volatile, safe to use
217 * edx ; volatile, safe to use
218 * esi ; non-volatile, otherwise safe to use
219 * edi ; non-volatile, otherwise safe to use
220 *
221 * Using any of the non volatile register causes a spill to stack which is almost
222 * certainly a net performance loss. Also, note that the array ref (__dtrace_args)
223 * consumes one free register. If all three of the volatile regs are used for load/store,
224 * the compiler will spill a register to hold the array ref.
225 *
226 * The end result is that we only pipeline two loads/stores at a time. Blech.
227 */
228
229 #define DTRACE_CALL0ARGS(provider, name) \
230 asm volatile ( \
231 DTRACE_CALL(provider, name) \
232 "# eat trailing nl +tabfrom DTRACE_CALL" \
233 : \
234 : \
235 );
236
237 #define DTRACE_CALL1ARG(provider, name) \
238 asm volatile ("subl\t$0x10,%%esp" "\n\t" \
239 "movl\t0x0(%0),%%eax" "\n\t" \
240 "movl\t%%eax,0x0(%%esp)" "\n\t" \
241 DTRACE_CALL(provider, name) \
242 "addl\t$0x10,%%esp" \
243 : \
244 : "r" (__dtrace_args) \
245 : "memory", "eax" \
246 );
247
248 #define DTRACE_CALL2ARGS(provider, name) \
249 asm volatile ("subl\t$0x10,%%esp" "\n\t" \
250 "movl\t0x0(%0),%%eax" "\n\t" \
251 "movl\t0x4(%0),%%edx" "\n\t" \
252 "movl\t%%eax,0x0(%%esp)" "\n\t" \
253 "movl\t%%edx,0x4(%%esp)" "\n\t" \
254 DTRACE_CALL(provider, name) \
255 "addl\t$0x10,%%esp" \
256 : \
257 : "r" (__dtrace_args) \
258 : "memory", "eax", "edx" \
259 );
260
261 #define DTRACE_CALL3ARGS(provider, name) \
262 asm volatile ("subl\t$0x10,%%esp" "\n\t" \
263 "movl\t0x0(%0),%%eax" "\n\t" \
264 "movl\t0x4(%0),%%edx" "\n\t" \
265 "movl\t%%eax,0x0(%%esp)" "\n\t" \
266 "movl\t%%edx,0x4(%%esp)" "\n\t" \
267 "movl\t0x8(%0),%%eax" "\n\t" \
268 "movl\t%%eax,0x8(%%esp)" "\n\t" \
269 DTRACE_CALL(provider, name) \
270 "addl\t$0x10,%%esp" \
271 : \
272 : "r" (__dtrace_args) \
273 : "memory", "eax", "edx" \
274 );
275
276 #define DTRACE_CALL4ARGS(provider, name) \
277 asm volatile ("subl\t$0x10,%%esp" "\n\t" \
278 "movl\t0x0(%0),%%eax" "\n\t" \
279 "movl\t0x4(%0),%%edx" "\n\t" \
280 "movl\t%%eax,0x0(%%esp)" "\n\t" \
281 "movl\t%%edx,0x4(%%esp)" "\n\t" \
282 "movl\t0x8(%0),%%eax" "\n\t" \
283 "movl\t0xC(%0),%%edx" "\n\t" \
284 "movl\t%%eax,0x8(%%esp)" "\n\t" \
285 "movl\t%%edx,0xC(%%esp)" "\n\t" \
286 DTRACE_CALL(provider, name) \
287 "addl\t$0x10,%%esp" \
288 : \
289 : "r" (__dtrace_args) \
290 : "memory", "eax", "edx" \
291 );
292
293 #define DTRACE_CALL5ARGS(provider, name) \
294 asm volatile ("subl\t$0x20,%%esp" "\n\t" \
295 "movl\t0x0(%0),%%eax" "\n\t" \
296 "movl\t0x4(%0),%%edx" "\n\t" \
297 "movl\t%%eax,0x0(%%esp)" "\n\t" \
298 "movl\t%%edx,0x4(%%esp)" "\n\t" \
299 "movl\t0x8(%0),%%eax" "\n\t" \
300 "movl\t0xC(%0),%%edx" "\n\t" \
301 "movl\t%%eax,0x8(%%esp)" "\n\t" \
302 "movl\t%%edx,0xC(%%esp)" "\n\t" \
303 "movl\t0x10(%0),%%eax" "\n\t" \
304 "movl\t%%eax,0x10(%%esp)" "\n\t" \
305 DTRACE_CALL(provider, name) \
306 "addl\t$0x20,%%esp" \
307 : \
308 : "r" (__dtrace_args) \
309 : "memory", "eax", "edx" \
310 );
311
312 #define DTRACE_CALL6ARGS(provider, name) \
313 asm volatile ("subl\t$0x20,%%esp" "\n\t" \
314 "movl\t0x0(%0),%%eax" "\n\t" \
315 "movl\t0x4(%0),%%edx" "\n\t" \
316 "movl\t%%eax,0x0(%%esp)" "\n\t" \
317 "movl\t%%edx,0x4(%%esp)" "\n\t" \
318 "movl\t0x8(%0),%%eax" "\n\t" \
319 "movl\t0xC(%0),%%edx" "\n\t" \
320 "movl\t%%eax,0x8(%%esp)" "\n\t" \
321 "movl\t%%edx,0xC(%%esp)" "\n\t" \
322 "movl\t0x10(%0),%%eax" "\n\t" \
323 "movl\t0x14(%0),%%edx" "\n\t" \
324 "movl\t%%eax,0x10(%%esp)" "\n\t" \
325 "movl\t%%edx,0x14(%%esp)" "\n\t" \
326 DTRACE_CALL(provider, name) \
327 "addl\t$0x20,%%esp" \
328 : \
329 : "r" (__dtrace_args) \
330 : "memory", "eax", "edx" \
331 );
332
333 #define DTRACE_CALL7ARGS(provider, name) \
334 asm volatile ("subl\t$0x20,%%esp" "\n\t" \
335 "movl\t0x0(%0),%%eax" "\n\t" \
336 "movl\t0x4(%0),%%edx" "\n\t" \
337 "movl\t%%eax,0x0(%%esp)" "\n\t" \
338 "movl\t%%edx,0x4(%%esp)" "\n\t" \
339 "movl\t0x8(%0),%%eax" "\n\t" \
340 "movl\t0xC(%0),%%edx" "\n\t" \
341 "movl\t%%eax,0x8(%%esp)" "\n\t" \
342 "movl\t%%edx,0xC(%%esp)" "\n\t" \
343 "movl\t0x10(%0),%%eax" "\n\t" \
344 "movl\t0x14(%0),%%edx" "\n\t" \
345 "movl\t%%eax,0x10(%%esp)" "\n\t" \
346 "movl\t%%edx,0x14(%%esp)" "\n\t" \
347 "movl\t0x18(%0),%%eax" "\n\t" \
348 "movl\t%%eax,0x18(%%esp)" "\n\t" \
349 DTRACE_CALL(provider, name) \
350 "addl\t$0x20,%%esp" \
351 : \
352 : "r" (__dtrace_args) \
353 : "memory", "eax", "edx" \
354 );
355
356 #define DTRACE_CALL8ARGS(provider, name) \
357 asm volatile ("subl\t$0x20,%%esp" "\n\t" \
358 "movl\t0x0(%0),%%eax" "\n\t" \
359 "movl\t0x4(%0),%%edx" "\n\t" \
360 "movl\t%%eax,0x0(%%esp)" "\n\t" \
361 "movl\t%%edx,0x4(%%esp)" "\n\t" \
362 "movl\t0x8(%0),%%eax" "\n\t" \
363 "movl\t0xC(%0),%%edx" "\n\t" \
364 "movl\t%%eax,0x8(%%esp)" "\n\t" \
365 "movl\t%%edx,0xC(%%esp)" "\n\t" \
366 "movl\t0x10(%0),%%eax" "\n\t" \
367 "movl\t0x14(%0),%%edx" "\n\t" \
368 "movl\t%%eax,0x10(%%esp)" "\n\t" \
369 "movl\t%%edx,0x14(%%esp)" "\n\t" \
370 "movl\t0x18(%0),%%eax" "\n\t" \
371 "movl\t0x1C(%0),%%edx" "\n\t" \
372 "movl\t%%eax,0x18(%%esp)" "\n\t" \
373 "movl\t%%edx,0x1C(%%esp)" "\n\t" \
374 DTRACE_CALL(provider, name) \
375 "addl\t$0x20,%%esp" \
376 : \
377 : "r" (__dtrace_args) \
378 : "memory", "eax", "edx" \
379 );
380
381 #define DTRACE_CALL9ARGS(provider, name) \
382 asm volatile ("subl\t$0x30,%%esp" "\n\t" \
383 "movl\t0x0(%0),%%eax" "\n\t" \
384 "movl\t0x4(%0),%%edx" "\n\t" \
385 "movl\t%%eax,0x0(%%esp)" "\n\t" \
386 "movl\t%%edx,0x4(%%esp)" "\n\t" \
387 "movl\t0x8(%0),%%eax" "\n\t" \
388 "movl\t0xC(%0),%%edx" "\n\t" \
389 "movl\t%%eax,0x8(%%esp)" "\n\t" \
390 "movl\t%%edx,0xC(%%esp)" "\n\t" \
391 "movl\t0x10(%0),%%eax" "\n\t" \
392 "movl\t0x14(%0),%%edx" "\n\t" \
393 "movl\t%%eax,0x10(%%esp)" "\n\t" \
394 "movl\t%%edx,0x14(%%esp)" "\n\t" \
395 "movl\t0x18(%0),%%eax" "\n\t" \
396 "movl\t0x1C(%0),%%edx" "\n\t" \
397 "movl\t%%eax,0x18(%%esp)" "\n\t" \
398 "movl\t%%edx,0x1C(%%esp)" "\n\t" \
399 "movl\t0x20(%0),%%eax" "\n\t" \
400 "movl\t%%eax,0x20(%%esp)" "\n\t" \
401 DTRACE_CALL(provider, name) \
402 "addl\t$0x30,%%esp" \
403 : \
404 : "r" (__dtrace_args) \
405 : "memory", "eax", "edx" \
406 );
407
408 #define DTRACE_CALL10ARGS(provider, name) \
409 asm volatile ("subl\t$0x30,%%esp" "\n\t" \
410 "movl\t0x0(%0),%%eax" "\n\t" \
411 "movl\t0x4(%0),%%edx" "\n\t" \
412 "movl\t%%eax,0x0(%%esp)" "\n\t" \
413 "movl\t%%edx,0x4(%%esp)" "\n\t" \
414 "movl\t0x8(%0),%%eax" "\n\t" \
415 "movl\t0xC(%0),%%edx" "\n\t" \
416 "movl\t%%eax,0x8(%%esp)" "\n\t" \
417 "movl\t%%edx,0xC(%%esp)" "\n\t" \
418 "movl\t0x10(%0),%%eax" "\n\t" \
419 "movl\t0x14(%0),%%edx" "\n\t" \
420 "movl\t%%eax,0x10(%%esp)" "\n\t" \
421 "movl\t%%edx,0x14(%%esp)" "\n\t" \
422 "movl\t0x18(%0),%%eax" "\n\t" \
423 "movl\t0x1C(%0),%%edx" "\n\t" \
424 "movl\t%%eax,0x18(%%esp)" "\n\t" \
425 "movl\t%%edx,0x1C(%%esp)" "\n\t" \
426 "movl\t0x20(%0),%%eax" "\n\t" \
427 "movl\t0x24(%0),%%edx" "\n\t" \
428 "movl\t%%eax,0x20(%%esp)" "\n\t" \
429 "movl\t%%edx,0x24(%%esp)" "\n\t" \
430 DTRACE_CALL(provider, name) \
431 "addl\t$0x30,%%esp" \
432 : \
433 : "r" (__dtrace_args) \
434 : "memory", "eax", "edx" \
435 );
436
437 #endif // __i386__
438
439 #endif /* _MACH_I386_SDT_ISA_H */