]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/kdebug.h
xnu-792.22.5.tar.gz
[apple/xnu.git] / bsd / sys / kdebug.h
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
8f6c56a5
A
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
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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
9bccf70c 38#include <sys/appleapiopts.h>
1c79356b
A
39#include <sys/cdefs.h>
40__BEGIN_DECLS
41
9bccf70c
A
42#ifdef __APPLE_API_UNSTABLE
43
1c79356b 44#include <mach/clock_types.h>
55e303ae 45#include <stdint.h>
1c79356b
A
46#if defined(KERNEL_BUILD)
47#include <kdebug.h>
48#endif /* KERNEL_BUILD */
49
50/*
51 * types of faults that vm_fault handles
52 * and creates trace entries for
53 */
54#define DBG_ZERO_FILL_FAULT 1
55#define DBG_PAGEIN_FAULT 2
56#define DBG_COW_FAULT 3
57#define DBG_CACHE_HIT_FAULT 4
58
59
60/* The debug code consists of the following
61*
62* ----------------------------------------------------------------------
63*| | | |Func |
64*| Class (8) | SubClass (8) | Code (14) |Qual(2)|
65* ----------------------------------------------------------------------
66* The class specifies the higher level
67*/
68
69/* The Function qualifiers */
70#define DBG_FUNC_START 1
71#define DBG_FUNC_END 2
72#define DBG_FUNC_NONE 0
73
74
75/* The Kernel Debug Classes */
4452a7af
A
76#define DBG_MACH 1
77#define DBG_NETWORK 2
78#define DBG_FSYSTEM 3
79#define DBG_BSD 4
80#define DBG_IOKIT 5
81#define DBG_DRIVERS 6
82#define DBG_TRACE 7
1c79356b 83#define DBG_DLIL 8
91447636 84#define DBG_SECURITY 9
4452a7af
A
85#define DBG_MISC 20
86#define DBG_DYLD 31
87#define DBG_QT 32
88#define DBG_APPS 33
89#define DBG_MIG 255
1c79356b
A
90
91/* **** The Kernel Debug Sub Classes for Mach (DBG_MACH) **** */
4452a7af 92#define DBG_MACH_EXCP_KTRAP_x86 0x02 /* Kernel Traps on x86 */
1c79356b
A
93#define DBG_MACH_EXCP_DFLT 0x03 /* Data Translation Fault */
94#define DBG_MACH_EXCP_IFLT 0x04 /* Inst Translation Fault */
95#define DBG_MACH_EXCP_INTR 0x05 /* Interrupts */
96#define DBG_MACH_EXCP_ALNG 0x06 /* Alignment Exception */
4452a7af 97#define DBG_MACH_EXCP_UTRAP_x86 0x07 /* User Traps on x86 */
1c79356b
A
98#define DBG_MACH_EXCP_FP 0x08 /* FP Unavail */
99#define DBG_MACH_EXCP_DECI 0x09 /* Decrementer Interrupt */
4452a7af 100#define DBG_MACH_CHUD 0x0A /* CHUD */
1c79356b
A
101#define DBG_MACH_EXCP_SC 0x0C /* System Calls */
102#define DBG_MACH_EXCP_TRACE 0x0D /* Trace exception */
55e303ae 103#define DBG_MACH_EXCP_EMUL 0x0E /* Instruction emulated */
1c79356b
A
104#define DBG_MACH_IHDLR 0x10 /* Interrupt Handlers */
105#define DBG_MACH_IPC 0x20 /* Inter Process Comm */
106#define DBG_MACH_VM 0x30 /* Virtual Memory */
107#define DBG_MACH_SCHED 0x40 /* Scheduler */
108#define DBG_MACH_MSGID_INVALID 0x50 /* Messages - invalid */
91447636 109#define DBG_MACH_LOCKS 0x60 /* new lock APIs */
1c79356b
A
110
111/* Codes for Scheduler (DBG_MACH_SCHED) */
112#define MACH_SCHED 0x0 /* Scheduler */
113#define MACH_STACK_ATTACH 0x1 /* stack_attach() */
114#define MACH_STACK_HANDOFF 0x2 /* stack_handoff() */
115#define MACH_CALL_CONT 0x3 /* call_continuation() */
116#define MACH_CALLOUT 0x4 /* callouts */
117#define MACH_STACK_DETACH 0x5
0b4e3aa0 118#define MACH_MAKE_RUNNABLE 0x6 /* make thread runnable */
9bccf70c
A
119#define MACH_PROMOTE 0x7 /* promoted due to resource */
120#define MACH_DEMOTE 0x8 /* promotion undone */
55e303ae 121#define MACH_PREBLOCK_MUTEX 0x9 /* preblocking on mutex */
1c79356b
A
122
123/* **** The Kernel Debug Sub Classes for Network (DBG_NETWORK) **** */
124#define DBG_NETIP 1 /* Internet Protocol */
125#define DBG_NETARP 2 /* Address Resolution Protocol */
126#define DBG_NETUDP 3 /* User Datagram Protocol */
127#define DBG_NETTCP 4 /* Transmission Control Protocol */
128#define DBG_NETICMP 5 /* Internet Control Message Protocol */
129#define DBG_NETIGMP 6 /* Internet Group Management Protocol */
130#define DBG_NETRIP 7 /* Routing Information Protocol */
131#define DBG_NETOSPF 8 /* Open Shortest Path First */
132#define DBG_NETISIS 9 /* Intermediate System to Intermediate System */
133#define DBG_NETSNMP 10 /* Simple Network Management Protocol */
134#define DBG_NETSOCK 11 /* Socket Layer */
135
136/* For Apple talk */
137#define DBG_NETAARP 100 /* Apple ARP */
138#define DBG_NETDDP 101 /* Datagram Delivery Protocol */
139#define DBG_NETNBP 102 /* Name Binding Protocol */
140#define DBG_NETZIP 103 /* Zone Information Protocol */
141#define DBG_NETADSP 104 /* Name Binding Protocol */
142#define DBG_NETATP 105 /* Apple Transaction Protocol */
143#define DBG_NETASP 106 /* Apple Session Protocol */
144#define DBG_NETAFP 107 /* Apple Filing Protocol */
145#define DBG_NETRTMP 108 /* Routing Table Maintenance Protocol */
146#define DBG_NETAURP 109 /* Apple Update Routing Protocol */
55e303ae 147#define DBG_NETIPSEC 128 /* IPsec Protocol */
1c79356b
A
148
149/* **** The Kernel Debug Sub Classes for IOKIT (DBG_IOKIT) **** */
4452a7af
A
150#define DBG_IOWORKLOOP 1 /* Work from work loop */
151#define DBG_IOINTES 2 /* Interrupt event source */
152#define DBG_IOCLKES 3 /* Clock event source */
153#define DBG_IOCMDQ 4 /* Command queue latencies */
154#define DBG_IOMCURS 5 /* Memory Cursor */
155#define DBG_IOMDESC 6 /* Memory Descriptors */
156#define DBG_IOPOWER 7 /* Power Managerment */
157
158/* **** 8-32 reserved for internal IOKit usage **** */
159
160#define DBG_IOSTORAGE 32 /* Storage layers */
161#define DBG_IONETWORK 33 /* Network layers */
162#define DBG_IOKEYBOARD 34 /* Keyboard */
163#define DBG_IOHID 35 /* HID Devices */
164#define DBG_IOAUDIO 36 /* Audio */
165#define DBG_IOSERIAL 37 /* Serial */
166#define DBG_IOTTY 38 /* TTY layers */
167#define DBG_IOSAM 39 /* SCSI Architecture Model layers */
168#define DBG_IOPARALLELATA 40 /* Parallel ATA */
169#define DBG_IOPARALLELSCSI 41 /* Parallel SCSI */
170#define DBG_IOSATA 42 /* Serial-ATA */
171#define DBG_IOSAS 43 /* SAS */
172#define DBG_IOFIBRECHANNEL 44 /* FiberChannel */
173#define DBG_IOUSB 45 /* USB */
174#define DBG_IOBLUETOOTH 46 /* Bluetooth */
175#define DBG_IOFIREWIRE 47 /* FireWire */
176#define DBG_IOINFINIBAND 48 /* Infiniband */
177#define DBG_IOCPUPM 49 /* CPU Power Management */
178
179/* Backwards compatibility */
180#define DBG_IOPOINTING DBG_IOHID /* OBSOLETE: Use DBG_IOHID instead */
181#define DBG_IODISK DBG_IOSTORAGE /* OBSOLETE: Use DBG_IOSTORAGE instead */
1c79356b
A
182
183/* **** The Kernel Debug Sub Classes for Device Drivers (DBG_DRIVERS) **** */
4452a7af
A
184#define DBG_DRVSTORAGE 1 /* Storage layers */
185#define DBG_DRVNETWORK 2 /* Network layers */
186#define DBG_DRVKEYBOARD 3 /* Keyboard */
187#define DBG_DRVHID 4 /* HID Devices */
188#define DBG_DRVAUDIO 5 /* Audio */
189#define DBG_DRVSERIAL 7 /* Serial */
190#define DBG_DRVSAM 8 /* SCSI Architecture Model layers */
191#define DBG_DRVPARALLELATA 9 /* Parallel ATA */
192#define DBG_DRVPARALLELSCSI 10 /* Parallel SCSI */
193#define DBG_DRVSATA 11 /* Serial ATA */
194#define DBG_DRVSAS 12 /* SAS */
195#define DBG_DRVFIBRECHANNEL 13 /* FiberChannel */
196#define DBG_DRVUSB 14 /* USB */
197#define DBG_DRVBLUETOOTH 15 /* Bluetooth */
198#define DBG_DRVFIREWIRE 16 /* FireWire */
199#define DBG_DRVINFINIBAND 17 /* Infiniband */
200
201/* Backwards compatibility */
202#define DBG_DRVPOINTING DBG_DRVHID /* OBSOLETE: Use DBG_DRVHID instead */
203#define DBG_DRVDISK DBG_DRVSTORAGE /* OBSOLETE: Use DBG_DRVSTORAGE instead */
1c79356b
A
204
205/* **** The Kernel Debug Sub Classes for the DLIL Layer (DBG_DLIL) **** */
206#define DBG_DLIL_STATIC 1 /* Static DLIL code */
207#define DBG_DLIL_PR_MOD 2 /* DLIL Protocol Module */
208#define DBG_DLIL_IF_MOD 3 /* DLIL Interface Module */
209#define DBG_DLIL_PR_FLT 4 /* DLIL Protocol Filter */
210#define DBG_DLIL_IF_FLT 5 /* DLIL Interface FIlter */
211
212/* The Kernel Debug Sub Classes for File System */
213#define DBG_FSRW 1 /* reads and writes to the filesystem */
9bccf70c 214#define DBG_DKRW 2 /* reads and writes to the disk */
55e303ae
A
215#define DBG_FSVN 3 /* vnode operations (inc. locking/unlocking) */
216#define DBG_FSLOOOKUP 4 /* namei and other lookup-related operations */
1c79356b
A
217
218/* The Kernel Debug Sub Classes for BSD */
219#define DBG_BSD_EXCP_SC 0x0C /* System Calls */
55e303ae
A
220#define DBG_BSD_AIO 0x0D /* aio (POSIX async IO) */
221#define DBG_BSD_SC_EXTENDED_INFO 0x0E /* System Calls, extended info */
1c79356b
A
222
223/* The Kernel Debug Sub Classes for DBG_TRACE */
224#define DBG_TRACE_DATA 0
225#define DBG_TRACE_STRING 1
226
4452a7af
A
227/* The Kernel Debug Sub Classes for DBG_MISC */
228#define DBG_EVENT 0x10
229#define DBG_BUFFER 0x20
230
9bccf70c
A
231/* The Kernel Debug Sub Classes for DBG_DYLD */
232#define DBG_DYLD_STRING 5
233
234/* The Kernel Debug modifiers for the DBG_DKRW sub class */
235#define DKIO_DONE 0x01
236#define DKIO_READ 0x02
237#define DKIO_ASYNC 0x04
238#define DKIO_META 0x08
239#define DKIO_PAGING 0x10
240
4452a7af
A
241/* The Kernel Debug Modifiers for the DBG_IOCPUPM sub-class */
242#define DCPM_PSTATE 0x0001
243#define DCPM_IDLE_CSTATE 0x0002
244#define DCPM_IDLE_HALT 0x0003
245#define DCPM_IDLE_LOOP 0x0004
246
1c79356b
A
247/**********************************************************************/
248
249#define KDBG_CODE(Class, SubClass, code) (((Class & 0xff) << 24) | ((SubClass & 0xff) << 16) | ((code & 0x3fff) << 2))
250
251#define KDBG_MIGCODE(msgid) ((DBG_MIG << 24) | (((msgid) & 0x3fffff) << 2))
252
253#define MACHDBG_CODE(SubClass, code) KDBG_CODE(DBG_MACH, SubClass, code)
254#define NETDBG_CODE(SubClass, code) KDBG_CODE(DBG_NETWORK, SubClass, code)
255#define FSDBG_CODE(SubClass, code) KDBG_CODE(DBG_FSYSTEM, SubClass, code)
256#define BSDDBG_CODE(SubClass, code) KDBG_CODE(DBG_BSD, SubClass, code)
257#define IOKDBG_CODE(SubClass, code) KDBG_CODE(DBG_IOKIT, SubClass, code)
258#define DRVDBG_CODE(SubClass, code) KDBG_CODE(DBG_DRIVERS, SubClass, code)
259#define TRACEDBG_CODE(SubClass,code) KDBG_CODE(DBG_TRACE, SubClass, code)
260#define MISCDBG_CODE(SubClass,code) KDBG_CODE(DBG_MISC, SubClass, code)
261#define DLILDBG_CODE(SubClass,code) KDBG_CODE(DBG_DLIL, SubClass, code)
91447636 262#define SECURITYDBG_CODE(SubClass,code) KDBG_CODE(DBG_SECURITY, SubClass, code)
9bccf70c 263#define DYLDDBG_CODE(SubClass,code) KDBG_CODE(DBG_DYLD, SubClass, code)
55e303ae 264#define QTDBG_CODE(SubClass,code) KDBG_CODE(DBG_QT, SubClass, code)
91447636 265#define APPSDBG_CODE(SubClass,code) KDBG_CODE(DBG_APPS, SubClass, code)
4452a7af 266#define CPUPM_CODE(code) IOKDBG_CODE(DBG_IOCPUPM, code)
1c79356b
A
267
268/* Usage:
269* kernel_debug((KDBG_CODE(DBG_NETWORK, DNET_PROTOCOL, 51) | DBG_FUNC_START),
270* offset, 0, 0, 0,0)
271*
272* For ex,
273*
274* #include <sys/kdebug.h>
275*
276* #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP,1)
277*
278*
279* void
280* ip_init()
281* {
282* register struct protosw *pr;
283* register int i;
284*
285* KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_START, 0,0,0,0,0)
286* --------
287* KERNEL_DEBUG(DBG_NETIPINIT, 0,0,0,0,0)
288* --------
289* KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_END, 0,0,0,0,0)
290* }
291*
292
293*/
294
295extern unsigned int kdebug_enable;
9bccf70c
A
296#define KDEBUG_ENABLE_TRACE 0x1
297#define KDEBUG_ENABLE_ENTROPY 0x2
298#define KDEBUG_ENABLE_CHUD 0x4
299
1c79356b
A
300#define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \
301do { \
302 if (kdebug_enable) \
303 kernel_debug(x,a,b,c,d,e); \
304} while(0)
305
0b4e3aa0
A
306#define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \
307do { \
308 if (kdebug_enable) \
309 kernel_debug1(x,a,b,c,d,e); \
310} while(0)
311
1c79356b
A
312extern void kernel_debug(unsigned int debugid, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5);
313
314extern void kernel_debug1(unsigned int debugid, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5);
315
91447636
A
316/*
317 * LP64todo - for some reason these are problematic
318 */
4452a7af 319struct proc;
91447636
A
320extern void kdbg_trace_data(struct proc *proc, long *arg_pid);
321
322extern void kdbg_trace_string(struct proc *proc, long *arg1, long *arg2, long *arg3, long *arg4);
323
1c79356b
A
324#if KDEBUG
325
326#define KERNEL_DEBUG(x,a,b,c,d,e) \
327do { \
328 if (kdebug_enable) \
329 kernel_debug(x,a,b,c,d,e); \
330} while(0)
331
332#define KERNEL_DEBUG1(x,a,b,c,d,e) \
333do { \
334 if (kdebug_enable) \
335 kernel_debug1(x,a,b,c,d,e); \
336} while(0)
337
91447636
A
338#define __kdebug_only
339
1c79356b
A
340#else
341
342#define KERNEL_DEBUG(x,a,b,c,d,e)
343#define KERNEL_DEBUG1(x,a,b,c,d,e)
344
91447636 345#define __kdebug_only __unused
1c79356b
A
346#endif
347
9bccf70c 348#endif /* __APPLE_API_UNSTABLE */
1c79356b
A
349__END_DECLS
350
351
91447636 352#ifdef PRIVATE
9bccf70c 353#ifdef __APPLE_API_PRIVATE
1c79356b
A
354/*
355 * private kernel_debug definitions
356 */
357
358typedef struct {
55e303ae 359uint64_t timestamp;
1c79356b
A
360unsigned int arg1;
361unsigned int arg2;
362unsigned int arg3;
363unsigned int arg4;
364unsigned int arg5; /* will hold current thread */
365unsigned int debugid;
366} kd_buf;
367
91447636
A
368#define KDBG_TIMESTAMP_MASK 0x00ffffffffffffffULL
369#define KDBG_CPU_MASK 0x0f00000000000000ULL
370#define KDBG_CPU_SHIFT 56
1c79356b
A
371
372/* Debug Flags */
373#define KDBG_INIT 0x1
374#define KDBG_NOWRAP 0x2
375#define KDBG_FREERUN 0x4
376#define KDBG_WRAPPED 0x8
377#define KDBG_USERFLAGS (KDBG_FREERUN|KDBG_NOWRAP|KDBG_INIT)
378#define KDBG_PIDCHECK 0x10
379#define KDBG_MAPINIT 0x20
380#define KDBG_PIDEXCLUDE 0x40
91447636 381#define KDBG_LOCKINIT 0x80
1c79356b
A
382
383typedef struct {
384 unsigned int type;
385 unsigned int value1;
386 unsigned int value2;
387 unsigned int value3;
388 unsigned int value4;
389
390} kd_regtype;
391
392typedef struct
393{
394 int nkdbufs;
395 int nolog;
396 int flags;
397 int nkdthreads;
9bccf70c 398 int bufid;
1c79356b
A
399} kbufinfo_t;
400
401typedef struct
402{
403 unsigned int thread;
404 int valid;
405 char command[20];
406} kd_threadmap;
407
408#define KDBG_CLASSTYPE 0x10000
409#define KDBG_SUBCLSTYPE 0x20000
410#define KDBG_RANGETYPE 0x40000
411#define KDBG_TYPENONE 0x80000
412#define KDBG_CKTYPES 0xF0000
413
414#define KDBG_RANGECHECK 0x100000
415#define KDBG_VALCHECK 0x200000 /* Check up to 4 individual values */
416
417#define KDBG_BUFINIT 0x80000000
418
419/* Control operations */
420#define KDBG_EFLAGS 1
421#define KDBG_DFLAGS 2
422#define KDBG_ENABLE 3
423#define KDBG_SETNUMBUF 4
424#define KDBG_GETNUMBUF 5
425#define KDBG_SETUP 6
426#define KDBG_REMOVE 7
427#define KDBG_SETREGCODE 8
428#define KDBG_GETREGCODE 9
429#define KDBG_READTRACE 10
430#define KDBG_PIDTR 11
431#define KDBG_THRMAP 12
432#define KDBG_PIDEX 14
433#define KDBG_SETRTCDEC 15
9bccf70c 434#define KDBG_KDGETENTROPY 16
1c79356b
A
435
436/* Minimum value allowed when setting decrementer ticks */
437#define KDBG_MINRTCDEC 2500
438
439
440/* PCSAMPLES control operations */
441#define PCSAMPLE_DISABLE 1
442#define PCSAMPLE_SETNUMBUF 2
443#define PCSAMPLE_GETNUMBUF 3
444#define PCSAMPLE_SETUP 4
445#define PCSAMPLE_REMOVE 5
446#define PCSAMPLE_READBUF 6
447#define PCSAMPLE_SETREG 7
448#define PCSAMPLE_COMM 8
449
450#define MAX_PCSAMPLES 1000000 /* Maximum number of pc's in a single buffer */
451
452
453extern unsigned int pcsample_enable;
454
455typedef struct
456{
457 int npcbufs;
458 int bufsize;
459 int enable;
91447636
A
460 unsigned int pcsample_beg;
461 unsigned int pcsample_end;
1c79356b
A
462} pcinfo_t;
463
9bccf70c 464#endif /* __APPLE_API_PRIVATE */
91447636 465#endif /* PRIVATE */
1c79356b
A
466
467#endif /* !BSD_SYS_KDEBUG_H */