]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/kdebug.h
xnu-792.12.6.tar.gz
[apple/xnu.git] / bsd / sys / kdebug.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30
31 /* Copyright (c) 1997 Apple Computer, Inc. All rights reserved.
32 *
33 * kdebug.h - kernel_debug definitions
34 *
35 */
36
37 #ifndef BSD_SYS_KDEBUG_H
38 #define BSD_SYS_KDEBUG_H
39
40 #include <sys/appleapiopts.h>
41 #include <sys/cdefs.h>
42 __BEGIN_DECLS
43
44 #ifdef __APPLE_API_UNSTABLE
45
46 #include <mach/clock_types.h>
47 #include <stdint.h>
48 #if defined(KERNEL_BUILD)
49 #include <kdebug.h>
50 #endif /* KERNEL_BUILD */
51
52 /*
53 * types of faults that vm_fault handles
54 * and creates trace entries for
55 */
56 #define DBG_ZERO_FILL_FAULT 1
57 #define DBG_PAGEIN_FAULT 2
58 #define DBG_COW_FAULT 3
59 #define DBG_CACHE_HIT_FAULT 4
60
61
62 /* The debug code consists of the following
63 *
64 * ----------------------------------------------------------------------
65 *| | | |Func |
66 *| Class (8) | SubClass (8) | Code (14) |Qual(2)|
67 * ----------------------------------------------------------------------
68 * The class specifies the higher level
69 */
70
71 /* The Function qualifiers */
72 #define DBG_FUNC_START 1
73 #define DBG_FUNC_END 2
74 #define DBG_FUNC_NONE 0
75
76
77 /* The Kernel Debug Classes */
78 #define DBG_MACH 1
79 #define DBG_NETWORK 2
80 #define DBG_FSYSTEM 3
81 #define DBG_BSD 4
82 #define DBG_IOKIT 5
83 #define DBG_DRIVERS 6
84 #define DBG_TRACE 7
85 #define DBG_DLIL 8
86 #define DBG_SECURITY 9
87 #define DBG_MISC 20
88 #define DBG_DYLD 31
89 #define DBG_QT 32
90 #define DBG_APPS 33
91 #define DBG_MIG 255
92
93 /* **** The Kernel Debug Sub Classes for Mach (DBG_MACH) **** */
94 #define DBG_MACH_EXCP_DFLT 0x03 /* Data Translation Fault */
95 #define DBG_MACH_EXCP_IFLT 0x04 /* Inst Translation Fault */
96 #define DBG_MACH_EXCP_INTR 0x05 /* Interrupts */
97 #define DBG_MACH_EXCP_ALNG 0x06 /* Alignment Exception */
98 #define DBG_MACH_EXCP_TRAP 0x07 /* Traps */
99 #define DBG_MACH_EXCP_FP 0x08 /* FP Unavail */
100 #define DBG_MACH_EXCP_DECI 0x09 /* Decrementer Interrupt */
101 #define DBG_MACH_EXCP_SC 0x0C /* System Calls */
102 #define DBG_MACH_EXCP_TRACE 0x0D /* Trace exception */
103 #define DBG_MACH_EXCP_EMUL 0x0E /* Instruction emulated */
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 */
109 #define DBG_MACH_LOCKS 0x60 /* new lock APIs */
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
118 #define MACH_MAKE_RUNNABLE 0x6 /* make thread runnable */
119 #define MACH_PROMOTE 0x7 /* promoted due to resource */
120 #define MACH_DEMOTE 0x8 /* promotion undone */
121 #define MACH_PREBLOCK_MUTEX 0x9 /* preblocking on mutex */
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 */
147 #define DBG_NETIPSEC 128 /* IPsec Protocol */
148
149 /* **** The Kernel Debug Sub Classes for IOKIT (DBG_IOKIT) **** */
150 #define DBG_IOSCSI 1 /* SCSI */
151 #define DBG_IODISK 2 /* Disk layers */
152 #define DBG_IONETWORK 3 /* Network layers */
153 #define DBG_IOKEYBOARD 4 /* Keyboard */
154 #define DBG_IOPOINTING 5 /* Pointing Devices */
155 #define DBG_IOAUDIO 6 /* Audio */
156 #define DBG_IOFLOPPY 7 /* Floppy */
157 #define DBG_IOSERIAL 8 /* Serial */
158 #define DBG_IOTTY 9 /* TTY layers */
159 #define DBG_IOWORKLOOP 10 /* Work from work loop */
160 #define DBG_IOINTES 11 /* Interrupt event source */
161 #define DBG_IOCLKES 12 /* Clock event source */
162 #define DBG_IOCMDQ 13 /* Command queue latencies */
163 #define DBG_IOMCURS 14 /* Memory Cursor */
164 #define DBG_IOMDESC 15 /* Memory Descriptors */
165 #define DBG_IOPOWER 16 /* Power Managerment */
166
167 /* **** The Kernel Debug Sub Classes for Device Drivers (DBG_DRIVERS) **** */
168 #define DBG_DRVSCSI 1 /* SCSI */
169 #define DBG_DRVDISK 2 /* Disk layers */
170 #define DBG_DRVNETWORK 3 /* Network layers */
171 #define DBG_DRVKEYBOARD 4 /* Keyboard */
172 #define DBG_DRVPOINTING 5 /* Pointing Devices */
173 #define DBG_DRVAUDIO 6 /* Audio */
174 #define DBG_DRVFLOPPY 7 /* Floppy */
175 #define DBG_DRVSERIAL 8 /* Serial */
176 #define DBG_DRVSPLT 9
177
178 /* **** The Kernel Debug Sub Classes for the DLIL Layer (DBG_DLIL) **** */
179 #define DBG_DLIL_STATIC 1 /* Static DLIL code */
180 #define DBG_DLIL_PR_MOD 2 /* DLIL Protocol Module */
181 #define DBG_DLIL_IF_MOD 3 /* DLIL Interface Module */
182 #define DBG_DLIL_PR_FLT 4 /* DLIL Protocol Filter */
183 #define DBG_DLIL_IF_FLT 5 /* DLIL Interface FIlter */
184
185 /* The Kernel Debug Sub Classes for File System */
186 #define DBG_FSRW 1 /* reads and writes to the filesystem */
187 #define DBG_DKRW 2 /* reads and writes to the disk */
188 #define DBG_FSVN 3 /* vnode operations (inc. locking/unlocking) */
189 #define DBG_FSLOOOKUP 4 /* namei and other lookup-related operations */
190
191 /* The Kernel Debug Sub Classes for BSD */
192 #define DBG_BSD_EXCP_SC 0x0C /* System Calls */
193 #define DBG_BSD_AIO 0x0D /* aio (POSIX async IO) */
194 #define DBG_BSD_SC_EXTENDED_INFO 0x0E /* System Calls, extended info */
195
196 /* The Kernel Debug Sub Classes for DBG_TRACE */
197 #define DBG_TRACE_DATA 0
198 #define DBG_TRACE_STRING 1
199
200 /* The Kernel Debug Sub Classes for DBG_DYLD */
201 #define DBG_DYLD_STRING 5
202
203 /* The Kernel Debug modifiers for the DBG_DKRW sub class */
204 #define DKIO_DONE 0x01
205 #define DKIO_READ 0x02
206 #define DKIO_ASYNC 0x04
207 #define DKIO_META 0x08
208 #define DKIO_PAGING 0x10
209
210 /**********************************************************************/
211
212 #define KDBG_CODE(Class, SubClass, code) (((Class & 0xff) << 24) | ((SubClass & 0xff) << 16) | ((code & 0x3fff) << 2))
213
214 #define KDBG_MIGCODE(msgid) ((DBG_MIG << 24) | (((msgid) & 0x3fffff) << 2))
215
216 #define MACHDBG_CODE(SubClass, code) KDBG_CODE(DBG_MACH, SubClass, code)
217 #define NETDBG_CODE(SubClass, code) KDBG_CODE(DBG_NETWORK, SubClass, code)
218 #define FSDBG_CODE(SubClass, code) KDBG_CODE(DBG_FSYSTEM, SubClass, code)
219 #define BSDDBG_CODE(SubClass, code) KDBG_CODE(DBG_BSD, SubClass, code)
220 #define IOKDBG_CODE(SubClass, code) KDBG_CODE(DBG_IOKIT, SubClass, code)
221 #define DRVDBG_CODE(SubClass, code) KDBG_CODE(DBG_DRIVERS, SubClass, code)
222 #define TRACEDBG_CODE(SubClass,code) KDBG_CODE(DBG_TRACE, SubClass, code)
223 #define MISCDBG_CODE(SubClass,code) KDBG_CODE(DBG_MISC, SubClass, code)
224 #define DLILDBG_CODE(SubClass,code) KDBG_CODE(DBG_DLIL, SubClass, code)
225 #define SECURITYDBG_CODE(SubClass,code) KDBG_CODE(DBG_SECURITY, SubClass, code)
226 #define DYLDDBG_CODE(SubClass,code) KDBG_CODE(DBG_DYLD, SubClass, code)
227 #define QTDBG_CODE(SubClass,code) KDBG_CODE(DBG_QT, SubClass, code)
228 #define APPSDBG_CODE(SubClass,code) KDBG_CODE(DBG_APPS, SubClass, code)
229
230 /* Usage:
231 * kernel_debug((KDBG_CODE(DBG_NETWORK, DNET_PROTOCOL, 51) | DBG_FUNC_START),
232 * offset, 0, 0, 0,0)
233 *
234 * For ex,
235 *
236 * #include <sys/kdebug.h>
237 *
238 * #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP,1)
239 *
240 *
241 * void
242 * ip_init()
243 * {
244 * register struct protosw *pr;
245 * register int i;
246 *
247 * KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_START, 0,0,0,0,0)
248 * --------
249 * KERNEL_DEBUG(DBG_NETIPINIT, 0,0,0,0,0)
250 * --------
251 * KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_END, 0,0,0,0,0)
252 * }
253 *
254
255 */
256
257 extern unsigned int kdebug_enable;
258 #define KDEBUG_ENABLE_TRACE 0x1
259 #define KDEBUG_ENABLE_ENTROPY 0x2
260 #define KDEBUG_ENABLE_CHUD 0x4
261
262 #define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \
263 do { \
264 if (kdebug_enable) \
265 kernel_debug(x,a,b,c,d,e); \
266 } while(0)
267
268 #define KERNEL_DEBUG_CONSTANT1(x,a,b,c,d,e) \
269 do { \
270 if (kdebug_enable) \
271 kernel_debug1(x,a,b,c,d,e); \
272 } while(0)
273
274 extern void kernel_debug(unsigned int debugid, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5);
275
276 extern void kernel_debug1(unsigned int debugid, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5);
277
278 /*
279 * LP64todo - for some reason these are problematic
280 */
281 extern void kdbg_trace_data(struct proc *proc, long *arg_pid);
282
283 extern void kdbg_trace_string(struct proc *proc, long *arg1, long *arg2, long *arg3, long *arg4);
284
285 #if KDEBUG
286
287 #define KERNEL_DEBUG(x,a,b,c,d,e) \
288 do { \
289 if (kdebug_enable) \
290 kernel_debug(x,a,b,c,d,e); \
291 } while(0)
292
293 #define KERNEL_DEBUG1(x,a,b,c,d,e) \
294 do { \
295 if (kdebug_enable) \
296 kernel_debug1(x,a,b,c,d,e); \
297 } while(0)
298
299 #define __kdebug_only
300
301 #else
302
303 #define KERNEL_DEBUG(x,a,b,c,d,e)
304 #define KERNEL_DEBUG1(x,a,b,c,d,e)
305
306 #define __kdebug_only __unused
307 #endif
308
309 #endif /* __APPLE_API_UNSTABLE */
310 __END_DECLS
311
312
313 #ifdef PRIVATE
314 #ifdef __APPLE_API_PRIVATE
315 /*
316 * private kernel_debug definitions
317 */
318
319 typedef struct {
320 uint64_t timestamp;
321 unsigned int arg1;
322 unsigned int arg2;
323 unsigned int arg3;
324 unsigned int arg4;
325 unsigned int arg5; /* will hold current thread */
326 unsigned int debugid;
327 } kd_buf;
328
329 #define KDBG_TIMESTAMP_MASK 0x00ffffffffffffffULL
330 #define KDBG_CPU_MASK 0x0f00000000000000ULL
331 #define KDBG_CPU_SHIFT 56
332
333 /* Debug Flags */
334 #define KDBG_INIT 0x1
335 #define KDBG_NOWRAP 0x2
336 #define KDBG_FREERUN 0x4
337 #define KDBG_WRAPPED 0x8
338 #define KDBG_USERFLAGS (KDBG_FREERUN|KDBG_NOWRAP|KDBG_INIT)
339 #define KDBG_PIDCHECK 0x10
340 #define KDBG_MAPINIT 0x20
341 #define KDBG_PIDEXCLUDE 0x40
342 #define KDBG_LOCKINIT 0x80
343
344 typedef struct {
345 unsigned int type;
346 unsigned int value1;
347 unsigned int value2;
348 unsigned int value3;
349 unsigned int value4;
350
351 } kd_regtype;
352
353 typedef struct
354 {
355 int nkdbufs;
356 int nolog;
357 int flags;
358 int nkdthreads;
359 int bufid;
360 } kbufinfo_t;
361
362 typedef struct
363 {
364 unsigned int thread;
365 int valid;
366 char command[20];
367 } kd_threadmap;
368
369 #define KDBG_CLASSTYPE 0x10000
370 #define KDBG_SUBCLSTYPE 0x20000
371 #define KDBG_RANGETYPE 0x40000
372 #define KDBG_TYPENONE 0x80000
373 #define KDBG_CKTYPES 0xF0000
374
375 #define KDBG_RANGECHECK 0x100000
376 #define KDBG_VALCHECK 0x200000 /* Check up to 4 individual values */
377
378 #define KDBG_BUFINIT 0x80000000
379
380 /* Control operations */
381 #define KDBG_EFLAGS 1
382 #define KDBG_DFLAGS 2
383 #define KDBG_ENABLE 3
384 #define KDBG_SETNUMBUF 4
385 #define KDBG_GETNUMBUF 5
386 #define KDBG_SETUP 6
387 #define KDBG_REMOVE 7
388 #define KDBG_SETREGCODE 8
389 #define KDBG_GETREGCODE 9
390 #define KDBG_READTRACE 10
391 #define KDBG_PIDTR 11
392 #define KDBG_THRMAP 12
393 #define KDBG_PIDEX 14
394 #define KDBG_SETRTCDEC 15
395 #define KDBG_KDGETENTROPY 16
396
397 /* Minimum value allowed when setting decrementer ticks */
398 #define KDBG_MINRTCDEC 2500
399
400
401 /* PCSAMPLES control operations */
402 #define PCSAMPLE_DISABLE 1
403 #define PCSAMPLE_SETNUMBUF 2
404 #define PCSAMPLE_GETNUMBUF 3
405 #define PCSAMPLE_SETUP 4
406 #define PCSAMPLE_REMOVE 5
407 #define PCSAMPLE_READBUF 6
408 #define PCSAMPLE_SETREG 7
409 #define PCSAMPLE_COMM 8
410
411 #define MAX_PCSAMPLES 1000000 /* Maximum number of pc's in a single buffer */
412
413
414 extern unsigned int pcsample_enable;
415
416 typedef struct
417 {
418 int npcbufs;
419 int bufsize;
420 int enable;
421 unsigned int pcsample_beg;
422 unsigned int pcsample_end;
423 } pcinfo_t;
424
425 #endif /* __APPLE_API_PRIVATE */
426 #endif /* PRIVATE */
427
428 #endif /* !BSD_SYS_KDEBUG_H */