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