]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/kdebug.h
9a76fbc8011f8b43a6e1629ff6b206f04b91624b
[apple/xnu.git] / bsd / sys / kdebug.h
1 /*
2 * Copyright (c) 2000-2010 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 /* Copyright (c) 1997 Apple Computer, Inc. All rights reserved.
30 *
31 * kdebug.h - kernel_debug definitions
32 *
33 */
34
35 #ifndef BSD_SYS_KDEBUG_H
36 #define BSD_SYS_KDEBUG_H
37
38 #include <sys/appleapiopts.h>
39 #include <sys/cdefs.h>
40 __BEGIN_DECLS
41
42 #ifdef __APPLE_API_UNSTABLE
43
44 #include <mach/clock_types.h>
45 #include <stdint.h>
46 #if defined(KERNEL_BUILD)
47 #include <kdebug.h>
48 #endif /* KERNEL_BUILD */
49
50 #ifdef XNU_KERNEL_PRIVATE
51 #include <stdint.h>
52 #include <mach/branch_predicates.h>
53 #endif
54
55 /*
56 * types of faults that vm_fault handles
57 * and creates trace entries for
58 */
59 #define DBG_ZERO_FILL_FAULT 1
60 #define DBG_PAGEIN_FAULT 2
61 #define DBG_COW_FAULT 3
62 #define DBG_CACHE_HIT_FAULT 4
63 #define DBG_NZF_PAGE_FAULT 5
64 #define DBG_GUARD_FAULT 6
65 #define DBG_PAGEINV_FAULT 7
66 #define DBG_PAGEIND_FAULT 8
67
68
69 /* The debug code consists of the following
70 *
71 * ----------------------------------------------------------------------
72 *| | | |Func |
73 *| Class (8) | SubClass (8) | Code (14) |Qual(2)|
74 * ----------------------------------------------------------------------
75 * The class specifies the higher level
76 */
77
78 /* The Function qualifiers */
79 #define DBG_FUNC_START 1
80 #define DBG_FUNC_END 2
81 #define DBG_FUNC_NONE 0
82
83
84 /* The Kernel Debug Classes */
85 #define DBG_MACH 1
86 #define DBG_NETWORK 2
87 #define DBG_FSYSTEM 3
88 #define DBG_BSD 4
89 #define DBG_IOKIT 5
90 #define DBG_DRIVERS 6
91 #define DBG_TRACE 7
92 #define DBG_DLIL 8
93 #define DBG_SECURITY 9
94 #define DBG_CORESTORAGE 10
95 #define DBG_CG 11
96 #define DBG_MISC 20
97 #define DBG_DYLD 31
98 #define DBG_QT 32
99 #define DBG_APPS 33
100 #define DBG_LAUNCHD 34
101 #define DBG_PERF 37
102 #define DBG_MIG 255
103
104 /* **** The Kernel Debug Sub Classes for Mach (DBG_MACH) **** */
105 #define DBG_MACH_EXCP_KTRAP_x86 0x02 /* Kernel Traps on x86 */
106 #define DBG_MACH_EXCP_DFLT 0x03 /* Data Translation Fault */
107 #define DBG_MACH_EXCP_IFLT 0x04 /* Inst Translation Fault */
108 #define DBG_MACH_EXCP_INTR 0x05 /* Interrupts */
109 #define DBG_MACH_EXCP_ALNG 0x06 /* Alignment Exception */
110 #define DBG_MACH_EXCP_UTRAP_x86 0x07 /* User Traps on x86 */
111 #define DBG_MACH_EXCP_FP 0x08 /* FP Unavail */
112 #define DBG_MACH_EXCP_DECI 0x09 /* Decrementer Interrupt */
113 #define DBG_MACH_CHUD 0x0A /* CHUD */
114 #define DBG_MACH_EXCP_SC 0x0C /* System Calls */
115 #define DBG_MACH_EXCP_TRACE 0x0D /* Trace exception */
116 #define DBG_MACH_EXCP_EMUL 0x0E /* Instruction emulated */
117 #define DBG_MACH_IHDLR 0x10 /* Interrupt Handlers */
118 #define DBG_MACH_IPC 0x20 /* Inter Process Comm */
119 #define DBG_MACH_VM 0x30 /* Virtual Memory */
120 #define DBG_MACH_LEAKS 0x31 /* alloc/free */
121 #define DBG_MACH_SCHED 0x40 /* Scheduler */
122 #define DBG_MACH_MSGID_INVALID 0x50 /* Messages - invalid */
123 #define DBG_MACH_LOCKS 0x60 /* new lock APIs */
124 #define DBG_MACH_PMAP 0x70 /* pmap */
125 #define DBG_MACH_MP 0x90 /* MP related */
126
127 /* Codes for Scheduler (DBG_MACH_SCHED) */
128 #define MACH_SCHED 0x0 /* Scheduler */
129 #define MACH_STACK_ATTACH 0x1 /* stack_attach() */
130 #define MACH_STACK_HANDOFF 0x2 /* stack_handoff() */
131 #define MACH_CALL_CONT 0x3 /* call_continuation() */
132 #define MACH_CALLOUT 0x4 /* callouts */
133 #define MACH_STACK_DETACH 0x5
134 #define MACH_MAKE_RUNNABLE 0x6 /* make thread runnable */
135 #define MACH_PROMOTE 0x7 /* promoted due to resource */
136 #define MACH_DEMOTE 0x8 /* promotion undone */
137 #define MACH_IDLE 0x9 /* processor idling */
138 #define MACH_STACK_DEPTH 0xa /* stack depth at switch */
139 #define MACH_MOVED 0xb /* did not use original scheduling decision */
140 #define MACH_FAIRSHARE_ENTER 0xc /* move to fairshare band */
141 #define MACH_FAIRSHARE_EXIT 0xd /* exit fairshare band */
142 #define MACH_FAILSAFE 0xe /* tripped fixed-pri/RT failsafe */
143 #define MACH_BLOCK 0xf /* thread block */
144 #define MACH_WAIT 0x10 /* thread wait assertion */
145 #define MACH_GET_URGENCY 0x14 /* Urgency queried by platform */
146 #define MACH_URGENCY 0x15 /* Urgency (RT/BG/NORMAL) communicated
147 * to platform
148 */
149 #define MACH_REDISPATCH 0x16 /* "next thread" thread redispatched */
150 #define MACH_REMOTE_AST 0x17 /* AST signal issued to remote processor */
151
152 #define MACH_SCHED_LPA_BROKEN 0x18 /* last_processor affinity broken in choose_processor */
153 #define MACH_DEEP_IDLE 0x19 /* deep idle on master processor */
154
155 /* Codes for pmap (DBG_MACH_PMAP) */
156 #define PMAP__CREATE 0x0
157 #define PMAP__DESTROY 0x1
158 #define PMAP__PROTECT 0x2
159 #define PMAP__PAGE_PROTECT 0x3
160 #define PMAP__ENTER 0x4
161 #define PMAP__REMOVE 0x5
162 #define PMAP__NEST 0x6
163 #define PMAP__UNNEST 0x7
164 #define PMAP__FLUSH_TLBS 0x8
165 #define PMAP__UPDATE_INTERRUPT 0x9
166 #define PMAP__ATTRIBUTE_CLEAR 0xa
167
168 /* **** The Kernel Debug Sub Classes for Network (DBG_NETWORK) **** */
169 #define DBG_NETIP 1 /* Internet Protocol */
170 #define DBG_NETARP 2 /* Address Resolution Protocol */
171 #define DBG_NETUDP 3 /* User Datagram Protocol */
172 #define DBG_NETTCP 4 /* Transmission Control Protocol */
173 #define DBG_NETICMP 5 /* Internet Control Message Protocol */
174 #define DBG_NETIGMP 6 /* Internet Group Management Protocol */
175 #define DBG_NETRIP 7 /* Routing Information Protocol */
176 #define DBG_NETOSPF 8 /* Open Shortest Path First */
177 #define DBG_NETISIS 9 /* Intermediate System to Intermediate System */
178 #define DBG_NETSNMP 10 /* Simple Network Management Protocol */
179 #define DBG_NETSOCK 11 /* Socket Layer */
180
181 /* For Apple talk */
182 #define DBG_NETAARP 100 /* Apple ARP */
183 #define DBG_NETDDP 101 /* Datagram Delivery Protocol */
184 #define DBG_NETNBP 102 /* Name Binding Protocol */
185 #define DBG_NETZIP 103 /* Zone Information Protocol */
186 #define DBG_NETADSP 104 /* Name Binding Protocol */
187 #define DBG_NETATP 105 /* Apple Transaction Protocol */
188 #define DBG_NETASP 106 /* Apple Session Protocol */
189 #define DBG_NETAFP 107 /* Apple Filing Protocol */
190 #define DBG_NETRTMP 108 /* Routing Table Maintenance Protocol */
191 #define DBG_NETAURP 109 /* Apple Update Routing Protocol */
192 #define DBG_NETIPSEC 128 /* IPsec Protocol */
193
194 /* **** The Kernel Debug Sub Classes for IOKIT (DBG_IOKIT) **** */
195 #define DBG_IOINTC 0 /* Interrupt controller */
196 #define DBG_IOWORKLOOP 1 /* Work from work loop */
197 #define DBG_IOINTES 2 /* Interrupt event source */
198 #define DBG_IOCLKES 3 /* Clock event source */
199 #define DBG_IOCMDQ 4 /* Command queue latencies */
200 #define DBG_IOMCURS 5 /* Memory Cursor */
201 #define DBG_IOMDESC 6 /* Memory Descriptors */
202 #define DBG_IOPOWER 7 /* Power Managerment */
203 #define DBG_IOSERVICE 8 /* Matching etc. */
204
205 /* **** 9-32 reserved for internal IOKit usage **** */
206
207 #define DBG_IOSTORAGE 32 /* Storage layers */
208 #define DBG_IONETWORK 33 /* Network layers */
209 #define DBG_IOKEYBOARD 34 /* Keyboard */
210 #define DBG_IOHID 35 /* HID Devices */
211 #define DBG_IOAUDIO 36 /* Audio */
212 #define DBG_IOSERIAL 37 /* Serial */
213 #define DBG_IOTTY 38 /* TTY layers */
214 #define DBG_IOSAM 39 /* SCSI Architecture Model layers */
215 #define DBG_IOPARALLELATA 40 /* Parallel ATA */
216 #define DBG_IOPARALLELSCSI 41 /* Parallel SCSI */
217 #define DBG_IOSATA 42 /* Serial-ATA */
218 #define DBG_IOSAS 43 /* SAS */
219 #define DBG_IOFIBRECHANNEL 44 /* FiberChannel */
220 #define DBG_IOUSB 45 /* USB */
221 #define DBG_IOBLUETOOTH 46 /* Bluetooth */
222 #define DBG_IOFIREWIRE 47 /* FireWire */
223 #define DBG_IOINFINIBAND 48 /* Infiniband */
224 #define DBG_IOCPUPM 49 /* CPU Power Management */
225 #define DBG_IOGRAPHICS 50 /* Graphics */
226 #define DBG_HIBERNATE 51 /* hibernation related events */
227
228
229 /* Backwards compatibility */
230 #define DBG_IOPOINTING DBG_IOHID /* OBSOLETE: Use DBG_IOHID instead */
231 #define DBG_IODISK DBG_IOSTORAGE /* OBSOLETE: Use DBG_IOSTORAGE instead */
232
233 /* **** The Kernel Debug Sub Classes for Device Drivers (DBG_DRIVERS) **** */
234 #define DBG_DRVSTORAGE 1 /* Storage layers */
235 #define DBG_DRVNETWORK 2 /* Network layers */
236 #define DBG_DRVKEYBOARD 3 /* Keyboard */
237 #define DBG_DRVHID 4 /* HID Devices */
238 #define DBG_DRVAUDIO 5 /* Audio */
239 #define DBG_DRVSERIAL 7 /* Serial */
240 #define DBG_DRVSAM 8 /* SCSI Architecture Model layers */
241 #define DBG_DRVPARALLELATA 9 /* Parallel ATA */
242 #define DBG_DRVPARALLELSCSI 10 /* Parallel SCSI */
243 #define DBG_DRVSATA 11 /* Serial ATA */
244 #define DBG_DRVSAS 12 /* SAS */
245 #define DBG_DRVFIBRECHANNEL 13 /* FiberChannel */
246 #define DBG_DRVUSB 14 /* USB */
247 #define DBG_DRVBLUETOOTH 15 /* Bluetooth */
248 #define DBG_DRVFIREWIRE 16 /* FireWire */
249 #define DBG_DRVINFINIBAND 17 /* Infiniband */
250 #define DBG_DRVGRAPHICS 18 /* Graphics */
251 #define DBG_DRVSD 19 /* Secure Digital */
252 #define DBG_DRVNAND 20 /* NAND drivers and layers */
253 #define DBG_SSD 21 /* SSD */
254 #define DBG_DRVSPI 22 /* SPI */
255
256 /* Backwards compatibility */
257 #define DBG_DRVPOINTING DBG_DRVHID /* OBSOLETE: Use DBG_DRVHID instead */
258 #define DBG_DRVDISK DBG_DRVSTORAGE /* OBSOLETE: Use DBG_DRVSTORAGE instead */
259
260 /* **** The Kernel Debug Sub Classes for the DLIL Layer (DBG_DLIL) **** */
261 #define DBG_DLIL_STATIC 1 /* Static DLIL code */
262 #define DBG_DLIL_PR_MOD 2 /* DLIL Protocol Module */
263 #define DBG_DLIL_IF_MOD 3 /* DLIL Interface Module */
264 #define DBG_DLIL_PR_FLT 4 /* DLIL Protocol Filter */
265 #define DBG_DLIL_IF_FLT 5 /* DLIL Interface FIlter */
266
267 /* The Kernel Debug Sub Classes for File System (DBG_FSYSTEM) */
268 #define DBG_FSRW 1 /* reads and writes to the filesystem */
269 #define DBG_DKRW 2 /* reads and writes to the disk */
270 #define DBG_FSVN 3 /* vnode operations (inc. locking/unlocking) */
271 #define DBG_FSLOOOKUP 4 /* namei and other lookup-related operations */
272 #define DBG_JOURNAL 5 /* journaling operations */
273 #define DBG_IOCTL 6 /* ioctl to the disk */
274 #define DBG_BOOTCACHE 7 /* bootcache operations */
275 #define DBG_HFS 8 /* HFS-specific events; see bsd/hfs/hfs_kdebug.h */
276 #define DBG_EXFAT 0xE /* ExFAT-specific events; see the exfat project */
277 #define DBG_MSDOS 0xF /* FAT-specific events; see the msdosfs project */
278
279 /* The Kernel Debug Sub Classes for BSD */
280 #define DBG_BSD_PROC 0x01 /* process/signals related */
281 #define DBG_BSD_EXCP_SC 0x0C /* System Calls */
282 #define DBG_BSD_AIO 0x0D /* aio (POSIX async IO) */
283 #define DBG_BSD_SC_EXTENDED_INFO 0x0E /* System Calls, extended info */
284 #define DBG_BSD_SC_EXTENDED_INFO2 0x0F /* System Calls, extended info */
285
286
287 /* The Codes for BSD subcode class DBG_BSD_PROC */
288 #define BSD_PROC_EXIT 1 /* process exit */
289 #define BSD_PROC_FRCEXIT 2 /* Kernel force termination */
290
291 /* The Kernel Debug Sub Classes for DBG_TRACE */
292 #define DBG_TRACE_DATA 0
293 #define DBG_TRACE_STRING 1
294 #define DBG_TRACE_INFO 2
295
296 /* The Kernel Debug Sub Classes for DBG_CORESTORAGE */
297 #define DBG_CS_IO 0
298
299 /* Sub-class codes for CoreGraphics (DBG_CG) are defined in its component. */
300
301 /* The Kernel Debug Sub Classes for DBG_MISC */
302 #define DBG_EVENT 0x10
303 #define DBG_BUFFER 0x20
304
305 /* The Kernel Debug Sub Classes for DBG_DYLD */
306 #define DBG_DYLD_STRING 5
307
308 /* The Kernel Debug modifiers for the DBG_DKRW sub class */
309 #define DKIO_DONE 0x01
310 #define DKIO_READ 0x02
311 #define DKIO_ASYNC 0x04
312 #define DKIO_META 0x08
313 #define DKIO_PAGING 0x10
314 #define DKIO_THROTTLE 0x20
315 #define DKIO_PASSIVE 0x40
316 #define DKIO_NOCACHE 0x80
317
318 /* Kernel Debug Sub Classes for Applications (DBG_APPS) */
319 #define DBG_APP_LOGINWINDOW 0x03
320 #define DBG_APP_SAMBA 0x80
321
322
323 /**********************************************************************/
324
325 #define KDBG_CODE(Class, SubClass, code) (((Class & 0xff) << 24) | ((SubClass & 0xff) << 16) | ((code & 0x3fff) << 2))
326
327 #define KDBG_MIGCODE(msgid) ((DBG_MIG << 24) | (((msgid) & 0x3fffff) << 2))
328
329 #define MACHDBG_CODE(SubClass, code) KDBG_CODE(DBG_MACH, SubClass, code)
330 #define NETDBG_CODE(SubClass, code) KDBG_CODE(DBG_NETWORK, SubClass, code)
331 #define FSDBG_CODE(SubClass, code) KDBG_CODE(DBG_FSYSTEM, SubClass, code)
332 #define BSDDBG_CODE(SubClass, code) KDBG_CODE(DBG_BSD, SubClass, code)
333 #define IOKDBG_CODE(SubClass, code) KDBG_CODE(DBG_IOKIT, SubClass, code)
334 #define DRVDBG_CODE(SubClass, code) KDBG_CODE(DBG_DRIVERS, SubClass, code)
335 #define TRACEDBG_CODE(SubClass,code) KDBG_CODE(DBG_TRACE, SubClass, code)
336 #define MISCDBG_CODE(SubClass,code) KDBG_CODE(DBG_MISC, SubClass, code)
337 #define DLILDBG_CODE(SubClass,code) KDBG_CODE(DBG_DLIL, SubClass, code)
338 #define SECURITYDBG_CODE(SubClass,code) KDBG_CODE(DBG_SECURITY, SubClass, code)
339 #define DYLDDBG_CODE(SubClass,code) KDBG_CODE(DBG_DYLD, SubClass, code)
340 #define QTDBG_CODE(SubClass,code) KDBG_CODE(DBG_QT, SubClass, code)
341 #define APPSDBG_CODE(SubClass,code) KDBG_CODE(DBG_APPS, SubClass, code)
342 #define CPUPM_CODE(code) IOKDBG_CODE(DBG_IOCPUPM, code)
343
344 #define KMEM_ALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 0)
345 #define KMEM_ALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 1)
346 #define KMEM_FREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 2)
347 #define KMEM_FREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 3)
348 #define ZALLOC_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 4)
349 #define ZALLOC_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 5)
350 #define ZFREE_CODE MACHDBG_CODE(DBG_MACH_LEAKS, 6)
351 #define ZFREE_CODE_2 MACHDBG_CODE(DBG_MACH_LEAKS, 7)
352
353 #define PMAP_CODE(code) MACHDBG_CODE(DBG_MACH_PMAP, code)
354
355
356 /* Usage:
357 * kernel_debug((KDBG_CODE(DBG_NETWORK, DNET_PROTOCOL, 51) | DBG_FUNC_START),
358 * offset, 0, 0, 0,0)
359 *
360 * For ex,
361 *
362 * #include <sys/kdebug.h>
363 *
364 * #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP,1)
365 *
366 *
367 * void
368 * ip_init()
369 * {
370 * register struct protosw *pr;
371 * register int i;
372 *
373 * KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_START, 0,0,0,0,0)
374 * --------
375 * KERNEL_DEBUG(DBG_NETIPINIT, 0,0,0,0,0)
376 * --------
377 * KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_END, 0,0,0,0,0)
378 * }
379 *
380
381 */
382
383 extern unsigned int kdebug_enable;
384 #define KDEBUG_ENABLE_TRACE 0x1
385 #define KDEBUG_ENABLE_ENTROPY 0x2
386 #define KDEBUG_ENABLE_CHUD 0x4
387 #define KDEBUG_ENABLE_PPT 0x8
388
389 /*
390 * Infer the supported kernel debug event level from config option.
391 * Use (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) as a guard to protect
392 * unaudited debug code.
393 */
394 #define KDEBUG_LEVEL_NONE 0
395 #define KDEBUG_LEVEL_IST 1
396 #define KDEBUG_LEVEL_STANDARD 2
397 #define KDEBUG_LEVEL_FULL 3
398
399 #if NO_KDEBUG
400 #define KDEBUG_LEVEL KDEBUG_LEVEL_NONE
401 #elif IST_KDEBUG
402 #define KDEBUG_LEVEL KDEBUG_LEVEL_IST
403 #elif KDEBUG
404 #define KDEBUG_LEVEL KDEBUG_LEVEL_FULL
405 #else
406 #define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD
407 #endif
408
409 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
410 #ifdef XNU_KERNEL_PRIVATE
411 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \
412 do { \
413 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
414 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
415 (uintptr_t)d,(uintptr_t)e); \
416 } while(0)
417
418 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \
419 do { \
420 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
421 kernel_debug1(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
422 (uintptr_t)d,(uintptr_t)e); \
423 } while(0)
424 #else /* XNU_KERNEL_PRIVATE */
425 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \
426 do { \
427 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
428 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
429 (uintptr_t)d,(uintptr_t)e); \
430 } while(0)
431
432 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \
433 do { \
434 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
435 kernel_debug1(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
436 (uintptr_t)d,(uintptr_t)e); \
437 } while(0)
438 #endif /* XNU_KERNEL_PRIVATE */
439 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
440 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) do { } while(0)
441 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) do { } while(0)
442 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
443
444 /*
445 * Specify KDEBUG_PPT to indicate that the event belongs to the
446 * limited PPT set.
447 */
448 #define KDEBUG_COMMON (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_ENTROPY|KDEBUG_ENABLE_CHUD|KDEBUG_ENABLE_PPT)
449 #define KDEBUG_TRACE (KDEBUG_ENABLE_TRACE|KDEBUG_ENABLE_ENTROPY|KDEBUG_ENABLE_CHUD)
450 #define KDEBUG_PPT (KDEBUG_ENABLE_PPT)
451
452 /*
453 * KERNEL_DEBUG_CONSTANT_IST events provide an audited subset of
454 * tracepoints for userland system tracing tools.
455 */
456 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST)
457 #ifdef XNU_KERNEL_PRIVATE
458 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) \
459 do { \
460 if (__improbable(kdebug_enable & type)) \
461 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
462 (uintptr_t)d,(uintptr_t)e); \
463 } while(0)
464 #else /* XNU_KERNEL_PRIVATE */
465 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) \
466 do { \
467 if (kdebug_enable & type) \
468 kernel_debug(x,(uintptr_t)a,(uintptr_t)b,(uintptr_t)c, \
469 (uintptr_t)d,(uintptr_t)e); \
470 } while(0)
471 #endif /* XNU_KERNEL_PRIVATE */
472 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
473 #define KERNEL_DEBUG_CONSTANT_IST(type,x,a,b,c,d,e) do { } while(0)
474 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
475
476 #if NO_KDEBUG
477 #define __kdebug_constant_only __unused
478 #endif
479
480 extern void kernel_debug(
481 uint32_t debugid,
482 uintptr_t arg1,
483 uintptr_t arg2,
484 uintptr_t arg3,
485 uintptr_t arg4,
486 uintptr_t arg5);
487
488 extern void kernel_debug1(
489 uint32_t debugid,
490 uintptr_t arg1,
491 uintptr_t arg2,
492 uintptr_t arg3,
493 uintptr_t arg4,
494 uintptr_t arg5);
495
496
497 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL)
498 #ifdef XNU_KERNEL_PRIVATE
499 #define KERNEL_DEBUG(x,a,b,c,d,e) \
500 do { \
501 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
502 kernel_debug((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
503 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
504 } while(0)
505
506 #define KERNEL_DEBUG1(x,a,b,c,d,e) \
507 do { \
508 if (__improbable(kdebug_enable & ~KDEBUG_ENABLE_PPT)) \
509 kernel_debug1((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
510 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
511 } while(0)
512
513 #define __kdebug_only
514 #else /* !XNU_KERNEL_PRIVATE */
515 #define KERNEL_DEBUG(x,a,b,c,d,e) \
516 do { \
517 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
518 kernel_debug((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
519 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
520 } while(0)
521
522 #define KERNEL_DEBUG1(x,a,b,c,d,e) \
523 do { \
524 if (kdebug_enable & ~KDEBUG_ENABLE_PPT) \
525 kernel_debug1((uint32_t)x, (uintptr_t)a, (uintptr_t)b, \
526 (uintptr_t)c, (uintptr_t)d, (uintptr_t)e); \
527 } while(0)
528 #endif /* XNU_KERNEL_PRIVATE */
529 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
530 #define KERNEL_DEBUG(x,a,b,c,d,e) do {} while (0)
531 #define KERNEL_DEBUG1(x,a,b,c,d,e) do {} while (0)
532
533 #define __kdebug_only __unused
534 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */
535
536 #ifdef KERNEL_PRIVATE
537 #include <mach/boolean.h>
538 struct proc;
539 extern void kdbg_trace_data(struct proc *proc, long *arg_pid);
540
541 extern void kdbg_trace_string(struct proc *proc, long *arg1, long *arg2, long *arg3, long *arg4);
542
543 extern void kdbg_dump_trace_to_file(const char *);
544 void start_kern_tracing(unsigned int, boolean_t);
545 struct task;
546 extern void kdbg_get_task_name(char*, int, struct task *task);
547 void disable_wrap(uint32_t *old_slowcheck, uint32_t *old_flags);
548 void enable_wrap(uint32_t old_slowcheck, boolean_t lostevents);
549 void release_storage_unit(int cpu, uint32_t storage_unit);
550 int allocate_storage_unit(int cpu);
551
552 void trace_handler_map_ctrl_page(uintptr_t addr, unsigned long ctrl_page_size, unsigned long storage_size, unsigned long kds_ptr_size);
553 void trace_handler_map_bufinfo(uintptr_t addr, unsigned long size);
554 void trace_handler_unmap_bufinfo(void);
555 void trace_handler_map_buffer(int index, uintptr_t addr, unsigned long size);
556 void trace_handler_unmap_buffer(int index);
557 void trace_set_timebases(uint64_t tsc, uint64_t ns);
558
559
560 #endif /* KERNEL_PRIVATE */
561
562
563 #endif /* __APPLE_API_UNSTABLE */
564 __END_DECLS
565
566
567 #ifdef PRIVATE
568 #ifdef __APPLE_API_PRIVATE
569 /*
570 * private kernel_debug definitions
571 */
572
573 typedef struct {
574 uint64_t timestamp;
575 uintptr_t arg1;
576 uintptr_t arg2;
577 uintptr_t arg3;
578 uintptr_t arg4;
579 uintptr_t arg5; /* will hold current thread */
580 uint32_t debugid;
581 #if defined(__LP64__)
582 uint32_t cpuid;
583 uintptr_t unused;
584 #endif
585 } kd_buf;
586
587 #if !defined(__LP64__)
588 #define KDBG_TIMESTAMP_MASK 0x00ffffffffffffffULL
589 #define KDBG_CPU_MASK 0xff00000000000000ULL
590 #define KDBG_CPU_SHIFT 56
591 static inline void
592 kdbg_set_cpu(kd_buf *kp, int cpu)
593 {
594 kp->timestamp = (kp->timestamp & KDBG_TIMESTAMP_MASK) |
595 (((uint64_t) cpu) << KDBG_CPU_SHIFT);
596 }
597 static inline int
598 kdbg_get_cpu(kd_buf *kp)
599 {
600 return (int) (((kp)->timestamp & KDBG_CPU_MASK) >> KDBG_CPU_SHIFT);
601 }
602 static inline void
603 kdbg_set_timestamp(kd_buf *kp, uint64_t thetime)
604 {
605 kp->timestamp = thetime & KDBG_TIMESTAMP_MASK;
606 }
607 static inline uint64_t
608 kdbg_get_timestamp(kd_buf *kp)
609 {
610 return kp->timestamp & KDBG_TIMESTAMP_MASK;
611 }
612 static inline void
613 kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu)
614 {
615 kp->timestamp = (thetime & KDBG_TIMESTAMP_MASK) |
616 (((uint64_t) cpu) << KDBG_CPU_SHIFT);
617 }
618 #else
619 #define KDBG_TIMESTAMP_MASK 0xffffffffffffffffULL
620 static inline void
621 kdbg_set_cpu(kd_buf *kp, int cpu)
622 {
623 kp->cpuid = cpu;
624 }
625 static inline int
626 kdbg_get_cpu(kd_buf *kp)
627 {
628 return kp->cpuid;
629 }
630 static inline void
631 kdbg_set_timestamp(kd_buf *kp, uint64_t thetime)
632 {
633 kp->timestamp = thetime;
634 }
635 static inline uint64_t
636 kdbg_get_timestamp(kd_buf *kp)
637 {
638 return kp->timestamp;
639 }
640 static inline void
641 kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu)
642 {
643 kdbg_set_timestamp(kp, thetime);
644 kdbg_set_cpu(kp, cpu);
645 }
646 #endif
647
648 /* 2^16 bits (8 kilobytes), one for each possible class/subclass combination */
649 #define KDBG_TYPEFILTER_BITMAP_SIZE ( (256 * 256) / 8 )
650
651 /* Debug Flags */
652 #define KDBG_INIT 0x001
653 #define KDBG_NOWRAP 0x002
654 #define KDBG_FREERUN 0x004
655 #define KDBG_WRAPPED 0x008
656 #define KDBG_USERFLAGS (KDBG_FREERUN|KDBG_NOWRAP|KDBG_INIT)
657 #define KDBG_PIDCHECK 0x010
658 #define KDBG_MAPINIT 0x020
659 #define KDBG_PIDEXCLUDE 0x040
660 #define KDBG_LOCKINIT 0x080
661 #define KDBG_LP64 0x100
662
663 typedef struct {
664 unsigned int type;
665 unsigned int value1;
666 unsigned int value2;
667 unsigned int value3;
668 unsigned int value4;
669
670 } kd_regtype;
671
672 typedef struct
673 {
674 int nkdbufs;
675 int nolog;
676 int flags;
677 int nkdthreads;
678 int bufid;
679 } kbufinfo_t;
680
681 typedef struct {
682 uintptr_t thread;
683 int valid;
684 char command[20];
685 } kd_threadmap;
686
687
688 typedef struct {
689 int version_no;
690 int thread_count;
691 uint64_t TOD_secs;
692 uint32_t TOD_usecs;
693 } RAW_header;
694
695 #define RAW_VERSION0 0x55aa0000
696 #define RAW_VERSION1 0x55aa0101
697
698
699 #define KDBG_CLASSTYPE 0x10000
700 #define KDBG_SUBCLSTYPE 0x20000
701 #define KDBG_RANGETYPE 0x40000
702 #define KDBG_TYPENONE 0x80000
703 #define KDBG_CKTYPES 0xF0000
704
705 #define KDBG_RANGECHECK 0x100000
706 #define KDBG_VALCHECK 0x200000 /* Check up to 4 individual values */
707
708 #define KDBG_TYPEFILTER_CHECK ((uint32_t) 0x400000) /* Check class and subclass against a bitmap */
709
710 #define KDBG_BUFINIT 0x80000000
711
712 /* Control operations */
713 #define KDBG_EFLAGS 1
714 #define KDBG_DFLAGS 2
715 #define KDBG_ENABLE 3
716 #define KDBG_SETNUMBUF 4
717 #define KDBG_GETNUMBUF 5
718 #define KDBG_SETUP 6
719 #define KDBG_REMOVE 7
720 #define KDBG_SETREGCODE 8
721 #define KDBG_GETREGCODE 9
722 #define KDBG_READTRACE 10
723 #define KDBG_PIDTR 11
724 #define KDBG_THRMAP 12
725 #define KDBG_PIDEX 14
726 #define KDBG_SETRTCDEC 15
727 #define KDBG_KDGETENTROPY 16
728
729 /* Minimum value allowed when setting decrementer ticks */
730 #define KDBG_MINRTCDEC 2500
731
732 #endif /* __APPLE_API_PRIVATE */
733 #endif /* PRIVATE */
734
735 #endif /* !BSD_SYS_KDEBUG_H */