]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/kdebug.h
xnu-124.13.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
100
101/* **** The Kernel Debug Sub Classes for Network (DBG_NETWORK) **** */
102#define DBG_NETIP 1 /* Internet Protocol */
103#define DBG_NETARP 2 /* Address Resolution Protocol */
104#define DBG_NETUDP 3 /* User Datagram Protocol */
105#define DBG_NETTCP 4 /* Transmission Control Protocol */
106#define DBG_NETICMP 5 /* Internet Control Message Protocol */
107#define DBG_NETIGMP 6 /* Internet Group Management Protocol */
108#define DBG_NETRIP 7 /* Routing Information Protocol */
109#define DBG_NETOSPF 8 /* Open Shortest Path First */
110#define DBG_NETISIS 9 /* Intermediate System to Intermediate System */
111#define DBG_NETSNMP 10 /* Simple Network Management Protocol */
112#define DBG_NETSOCK 11 /* Socket Layer */
113
114/* For Apple talk */
115#define DBG_NETAARP 100 /* Apple ARP */
116#define DBG_NETDDP 101 /* Datagram Delivery Protocol */
117#define DBG_NETNBP 102 /* Name Binding Protocol */
118#define DBG_NETZIP 103 /* Zone Information Protocol */
119#define DBG_NETADSP 104 /* Name Binding Protocol */
120#define DBG_NETATP 105 /* Apple Transaction Protocol */
121#define DBG_NETASP 106 /* Apple Session Protocol */
122#define DBG_NETAFP 107 /* Apple Filing Protocol */
123#define DBG_NETRTMP 108 /* Routing Table Maintenance Protocol */
124#define DBG_NETAURP 109 /* Apple Update Routing Protocol */
125
126/* **** The Kernel Debug Sub Classes for IOKIT (DBG_IOKIT) **** */
127#define DBG_IOSCSI 1 /* SCSI */
128#define DBG_IODISK 2 /* Disk layers */
129#define DBG_IONETWORK 3 /* Network layers */
130#define DBG_IOKEYBOARD 4 /* Keyboard */
131#define DBG_IOPOINTING 5 /* Pointing Devices */
132#define DBG_IOAUDIO 6 /* Audio */
133#define DBG_IOFLOPPY 7 /* Floppy */
134#define DBG_IOSERIAL 8 /* Serial */
135#define DBG_IOTTY 9 /* TTY layers */
136#define DBG_IOWORKLOOP 10 /* Work from work loop */
137#define DBG_IOINTES 11 /* Interrupt event source */
138#define DBG_IOCLKES 12 /* Clock event source */
139#define DBG_IOCMDQ 13 /* Command queue latencies */
140#define DBG_IOMCURS 14 /* Memory Cursor */
141#define DBG_IOMDESC 15 /* Memory Descriptors */
142
143/* **** The Kernel Debug Sub Classes for Device Drivers (DBG_DRIVERS) **** */
144#define DBG_DRVSCSI 1 /* SCSI */
145#define DBG_DRVDISK 2 /* Disk layers */
146#define DBG_DRVNETWORK 3 /* Network layers */
147#define DBG_DRVKEYBOARD 4 /* Keyboard */
148#define DBG_DRVPOINTING 5 /* Pointing Devices */
149#define DBG_DRVAUDIO 6 /* Audio */
150#define DBG_DRVFLOPPY 7 /* Floppy */
151#define DBG_DRVSERIAL 8 /* Serial */
152#define DBG_DRVSPLT 9
153
154/* **** The Kernel Debug Sub Classes for the DLIL Layer (DBG_DLIL) **** */
155#define DBG_DLIL_STATIC 1 /* Static DLIL code */
156#define DBG_DLIL_PR_MOD 2 /* DLIL Protocol Module */
157#define DBG_DLIL_IF_MOD 3 /* DLIL Interface Module */
158#define DBG_DLIL_PR_FLT 4 /* DLIL Protocol Filter */
159#define DBG_DLIL_IF_FLT 5 /* DLIL Interface FIlter */
160
161/* The Kernel Debug Sub Classes for File System */
162#define DBG_FSRW 1 /* reads and writes to the filesystem */
163
164/* The Kernel Debug Sub Classes for BSD */
165#define DBG_BSD_EXCP_SC 0x0C /* System Calls */
166
167/* The Kernel Debug Sub Classes for DBG_TRACE */
168#define DBG_TRACE_DATA 0
169#define DBG_TRACE_STRING 1
170
171/**********************************************************************/
172
173#define KDBG_CODE(Class, SubClass, code) (((Class & 0xff) << 24) | ((SubClass & 0xff) << 16) | ((code & 0x3fff) << 2))
174
175#define KDBG_MIGCODE(msgid) ((DBG_MIG << 24) | (((msgid) & 0x3fffff) << 2))
176
177#define MACHDBG_CODE(SubClass, code) KDBG_CODE(DBG_MACH, SubClass, code)
178#define NETDBG_CODE(SubClass, code) KDBG_CODE(DBG_NETWORK, SubClass, code)
179#define FSDBG_CODE(SubClass, code) KDBG_CODE(DBG_FSYSTEM, SubClass, code)
180#define BSDDBG_CODE(SubClass, code) KDBG_CODE(DBG_BSD, SubClass, code)
181#define IOKDBG_CODE(SubClass, code) KDBG_CODE(DBG_IOKIT, SubClass, code)
182#define DRVDBG_CODE(SubClass, code) KDBG_CODE(DBG_DRIVERS, SubClass, code)
183#define TRACEDBG_CODE(SubClass,code) KDBG_CODE(DBG_TRACE, SubClass, code)
184#define MISCDBG_CODE(SubClass,code) KDBG_CODE(DBG_MISC, SubClass, code)
185#define DLILDBG_CODE(SubClass,code) KDBG_CODE(DBG_DLIL, SubClass, code)
186
187/* Usage:
188* kernel_debug((KDBG_CODE(DBG_NETWORK, DNET_PROTOCOL, 51) | DBG_FUNC_START),
189* offset, 0, 0, 0,0)
190*
191* For ex,
192*
193* #include <sys/kdebug.h>
194*
195* #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP,1)
196*
197*
198* void
199* ip_init()
200* {
201* register struct protosw *pr;
202* register int i;
203*
204* KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_START, 0,0,0,0,0)
205* --------
206* KERNEL_DEBUG(DBG_NETIPINIT, 0,0,0,0,0)
207* --------
208* KERNEL_DEBUG(DBG_NETIPINIT | DBG_FUNC_END, 0,0,0,0,0)
209* }
210*
211
212*/
213
214extern unsigned int kdebug_enable;
215#define KERNEL_DEBUG_CONSTANT(x,a,b,c,d,e) \
216do { \
217 if (kdebug_enable) \
218 kernel_debug(x,a,b,c,d,e); \
219} while(0)
220
221extern void kernel_debug(unsigned int debugid, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5);
222
223extern void kernel_debug1(unsigned int debugid, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4, unsigned int arg5);
224
225#if KDEBUG
226
227#define KERNEL_DEBUG(x,a,b,c,d,e) \
228do { \
229 if (kdebug_enable) \
230 kernel_debug(x,a,b,c,d,e); \
231} while(0)
232
233#define KERNEL_DEBUG1(x,a,b,c,d,e) \
234do { \
235 if (kdebug_enable) \
236 kernel_debug1(x,a,b,c,d,e); \
237} while(0)
238
239#else
240
241#define KERNEL_DEBUG(x,a,b,c,d,e)
242#define KERNEL_DEBUG1(x,a,b,c,d,e)
243
244#endif
245
246__END_DECLS
247
248
249#ifdef KERNEL_PRIVATE
250/*
251 * private kernel_debug definitions
252 */
253
254typedef struct {
255mach_timespec_t timestamp;
256unsigned int arg1;
257unsigned int arg2;
258unsigned int arg3;
259unsigned int arg4;
260unsigned int arg5; /* will hold current thread */
261unsigned int debugid;
262} kd_buf;
263
264#define KDBG_THREAD_MASK 0x7fffffff
265#define KDBG_CPU_MASK 0x80000000
266
267/* Debug Flags */
268#define KDBG_INIT 0x1
269#define KDBG_NOWRAP 0x2
270#define KDBG_FREERUN 0x4
271#define KDBG_WRAPPED 0x8
272#define KDBG_USERFLAGS (KDBG_FREERUN|KDBG_NOWRAP|KDBG_INIT)
273#define KDBG_PIDCHECK 0x10
274#define KDBG_MAPINIT 0x20
275#define KDBG_PIDEXCLUDE 0x40
276
277typedef struct {
278 unsigned int type;
279 unsigned int value1;
280 unsigned int value2;
281 unsigned int value3;
282 unsigned int value4;
283
284} kd_regtype;
285
286typedef struct
287{
288 int nkdbufs;
289 int nolog;
290 int flags;
291 int nkdthreads;
292} kbufinfo_t;
293
294typedef struct
295{
296 unsigned int thread;
297 int valid;
298 char command[20];
299} kd_threadmap;
300
301#define KDBG_CLASSTYPE 0x10000
302#define KDBG_SUBCLSTYPE 0x20000
303#define KDBG_RANGETYPE 0x40000
304#define KDBG_TYPENONE 0x80000
305#define KDBG_CKTYPES 0xF0000
306
307#define KDBG_RANGECHECK 0x100000
308#define KDBG_VALCHECK 0x200000 /* Check up to 4 individual values */
309
310#define KDBG_BUFINIT 0x80000000
311
312/* Control operations */
313#define KDBG_EFLAGS 1
314#define KDBG_DFLAGS 2
315#define KDBG_ENABLE 3
316#define KDBG_SETNUMBUF 4
317#define KDBG_GETNUMBUF 5
318#define KDBG_SETUP 6
319#define KDBG_REMOVE 7
320#define KDBG_SETREGCODE 8
321#define KDBG_GETREGCODE 9
322#define KDBG_READTRACE 10
323#define KDBG_PIDTR 11
324#define KDBG_THRMAP 12
325#define KDBG_PIDEX 14
326#define KDBG_SETRTCDEC 15
327
328/* Minimum value allowed when setting decrementer ticks */
329#define KDBG_MINRTCDEC 2500
330
331
332/* PCSAMPLES control operations */
333#define PCSAMPLE_DISABLE 1
334#define PCSAMPLE_SETNUMBUF 2
335#define PCSAMPLE_GETNUMBUF 3
336#define PCSAMPLE_SETUP 4
337#define PCSAMPLE_REMOVE 5
338#define PCSAMPLE_READBUF 6
339#define PCSAMPLE_SETREG 7
340#define PCSAMPLE_COMM 8
341
342#define MAX_PCSAMPLES 1000000 /* Maximum number of pc's in a single buffer */
343
344
345extern unsigned int pcsample_enable;
346
347typedef struct
348{
349 int npcbufs;
350 int bufsize;
351 int enable;
352 unsigned long pcsample_beg;
353 unsigned long pcsample_end;
354} pcinfo_t;
355
356#endif /* KERNEL_PRIVATE */
357
358#endif /* !BSD_SYS_KDEBUG_H */