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