]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/xpr.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
28 * Revision 1.1.1.1 1998/09/22 21:05:32 wsanchez
29 * Import of Mac OS X kernel (~semeria)
31 * Revision 1.1.1.1 1998/03/07 02:25:57 wsanchez
32 * Import of OSF Mach kernel (~mburg)
34 * Revision 1.2.46.1 1997/09/22 17:41:21 barbou
35 * MP+RT: protect cpu_number() usage against preemption.
38 * Revision 1.2.25.5 1996/07/31 09:56:06 paire
39 * Merged with nmk20b7_shared (1.2.41.1)
42 * Revision 1.2.41.1 1996/04/15 14:35:12 bernadat
43 * Keep interrupts disabled while accessing XPR_TIMESTAMP.
46 * Revision 1.2.25.4 1995/02/24 15:22:42 alanl
47 * DIPC: Merge from nmk17b2 to nmk18b8.
48 * Notes: Restore portable locks package, derived from nmk17b2.
51 * Revision 1.2.28.3 1994/12/09 22:25:16 dwm
52 * mk6 CR801 - merge up from nmk18b4 to nmk18b7
53 * * Rev 1.2.25.2 1994/10/21 18:30:41 joe
55 * [1994/12/09 21:10:59 dwm]
57 * Revision 1.2.28.2 1994/11/10 06:15:29 dwm
58 * mk6 CR764 - s/spinlock/simple_lock/ (name change only)
59 * [1994/11/10 05:58:48 dwm]
61 * Revision 1.2.28.1 1994/11/04 10:10:56 dwm
62 * mk6 CR668 - 1.3b26 merge
63 * * Revision 1.2.5.7 1994/05/06 18:54:13 tmt
64 * Merge in DEC Alpha changes to osc1.3b19.
65 * include <mach/machine/vm_types.h>
68 * [1994/11/04 09:39:17 dwm]
70 * Revision 1.2.25.1 1994/09/23 02:32:39 ezf
71 * change marker to not FREE
72 * [1994/09/22 21:38:29 ezf]
74 * Revision 1.2.22.1 1994/06/09 14:14:11 dswartz
76 * [1994/06/09 14:08:38 dswartz]
78 * Revision 1.2.5.5 1993/08/12 20:16:51 bernard
79 * Last pass for ANSI prototypes - CR#9523
80 * [1993/08/12 15:43:24 bernard]
82 * Revision 1.2.5.4 1993/08/02 17:26:05 rod
83 * ANSI prototypes: zap explicit include of machine/setjmp.h. CR #9523.
84 * [1993/08/01 13:36:31 rod]
86 * Revision 1.2.5.3 1993/07/27 18:09:05 rod
87 * Add ANSI prototypes. CR #9523.
88 * [1993/07/27 14:33:23 rod]
90 * Revision 1.2.5.2 1993/06/09 02:39:13 gm
91 * CR9176 - ANSI C violations: trailing tokens on CPP
92 * directives, extra semicolons after decl_ ..., asm keywords
93 * [1993/06/07 19:07:51 jeffc]
95 * Added to OSF/1 R1.3 from NMK15.0.
96 * [1993/06/02 21:15:13 jeffc]
98 * Revision 1.2 1993/04/19 16:31:21 devrcs
99 * Added void to fcns that still needed it.
102 * Revision 1.1 1992/09/30 02:10:39 robert
109 * Revision 2.9.5.2 92/03/03 16:20:57 jeffreyh
111 * [92/02/24 13:24:44 jeffreyh]
113 * Revision 2.9.5.1 92/02/18 19:13:03 jeffreyh
114 * Added an xpr_search function to which you can give
115 * a selection function.
116 * [92/02/11 08:13:23 bernadat]
118 * Revision 2.9.4.1 92/02/13 18:53:47 jeffreyh
119 * Added an xpr_search function to which you can give
120 * a selection function.
121 * [92/02/11 08:13:23 bernadat]
123 * Revision 2.9.3.1 92/02/11 17:19:59 jeffreyh
124 * Added an xpr_search function to which you can give
125 * a selection function.
126 * [92/02/11 08:13:23 bernadat]
128 * Revision 2.9.2.1 92/02/11 08:13:23 bernadat
129 * Added an xpr_search function to which you can give
130 * a selection function.
133 * Revision 2.9 91/10/09 16:11:50 af
134 * Removed xpr_save. Modified xpr_dump to make it useful
135 * for dumping xpr buffers in user space tasks.
138 * Turned on xprenable by default. xprbootstrap now preserves
139 * the original contents of the buffer if xprenable is off.
142 * Revision 2.8 91/08/28 11:14:56 jsb
143 * Fixed xprbootstrap to zero the allocate memory.
146 * Revision 2.7 91/05/18 14:34:37 rpd
147 * Added xprenable and other minor changes so that the xpr buffer
148 * may be examined after a spontaneous reboot.
150 * Fixed the initialization check in xpr.
154 * Revision 2.6 91/05/14 16:50:09 mrt
155 * Correcting copyright
157 * Revision 2.5 91/03/16 14:53:24 rpd
158 * Updated for new kmem_alloc interface.
161 * Revision 2.4 91/02/05 17:31:13 mrt
162 * Changed to new Mach copyright
163 * [91/02/01 16:21:17 mrt]
165 * Revision 2.3 90/09/09 14:33:04 rpd
166 * Use decl_simple_lock_data.
169 * Revision 2.2 89/11/29 14:09:21 af
170 * Added xpr_dump() to print on console the content of the buffer,
171 * only valid for KDB usage.
174 * MACH_KERNEL: include sys/cpu_number.h instead of machine/cpu.h.
178 * Revision 2.1 89/08/03 15:49:11 rwd
181 * Revision 2.2 88/12/19 02:48:30 mwyoung
182 * Fix include file references.
183 * [88/11/22 02:17:01 mwyoung]
185 * Separate initialization into two phases.
186 * [88/11/22 01:13:11 mwyoung]
188 * 6-Jan-88 Michael Young (mwyoung) at Carnegie-Mellon University
189 * Eliminate use of arg6 in order to allow a more shapely event structure.
191 * 30-Dec-87 David Golub (dbg) at Carnegie-Mellon University
194 * 7-Dec-87 Richard Sanzi (sanzi) at Carnegie-Mellon University
195 * Added xpr_save() routine.
200 * Mach Operating System
201 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
202 * All Rights Reserved.
204 * Permission to use, copy, modify and distribute this software and its
205 * documentation is hereby granted, provided that both the copyright
206 * notice and this permission notice appear in all copies of the
207 * software, derivative works or modified versions, and any portions
208 * thereof, and that both notices appear in supporting documentation.
210 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
211 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
212 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
214 * Carnegie Mellon requests users of this software to return to
216 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
217 * School of Computer Science
218 * Carnegie Mellon University
219 * Pittsburgh PA 15213-3890
221 * any improvements or extensions that they make and grant Carnegie Mellon
222 * the rights to redistribute these changes.
224 #include <mach_kdb.h>
226 * xpr silent tracing circular buffer.
231 #include <mach/machine/vm_types.h>
232 #include <kern/xpr.h>
233 #include <kern/lock.h>
234 #include <kern/spl.h>
235 #include <kern/cpu_number.h>
236 #include <kern/misc_protos.h>
237 #include <kern/thread.h>
238 #include <vm/vm_kern.h>
242 * After a spontaneous reboot, it is desirable to look
243 * at the old xpr buffer. Assuming xprbootstrap allocates
244 * the buffer in the same place in physical memory and
245 * the reboot doesn't clear memory, this should work.
246 * xprptr will be reset, but the saved value should be OK.
247 * Just set xprenable false so the buffer isn't overwritten.
250 decl_simple_lock_data(,xprlock
)
251 boolean_t xprenable
= TRUE
; /* Enable xpr tracing */
252 int nxprbufs
= 0; /* Number of contiguous xprbufs allocated */
253 int xprflags
= 0; /* Bit mask of xpr flags enabled */
254 struct xprbuf
*xprbase
; /* Pointer to circular buffer nxprbufs*sizeof(xprbuf)*/
255 struct xprbuf
*xprptr
; /* Currently allocated xprbuf */
256 struct xprbuf
*xprlast
; /* Pointer to end of circular buffer */
268 register struct xprbuf
*x
;
270 /* If we aren't initialized, ignore trace request */
271 if (!xprenable
|| (xprptr
== 0))
273 /* Guard against all interrupts and allocate next buffer. */
276 simple_lock(&xprlock
);
278 if (xprptr
>= xprlast
) {
282 /* Save xprptr in allocated memory. */
283 *(struct xprbuf
**)xprlast
= xprptr
;
284 simple_unlock(&xprlock
);
285 x
->timestamp
= XPR_TIMESTAMP
;
293 mp_disable_preemption();
294 x
->cpuinfo
= cpu_number();
295 mp_enable_preemption();
305 simple_lock_init(&xprlock
, ETAP_MISC_XPR
);
307 return; /* assume XPR support not desired */
309 /* leave room at the end for a saved copy of xprptr */
310 size
= nxprbufs
* sizeof(struct xprbuf
) + sizeof xprptr
;
312 kr
= kmem_alloc_wired(kernel_map
, &addr
, size
);
313 if (kr
!= KERN_SUCCESS
)
314 panic("xprbootstrap");
318 * If xprenable is set (the default) then we zero
319 * the buffer so xpr_dump doesn't encounter bad pointers.
320 * If xprenable isn't set, then we preserve
321 * the original contents of the buffer. This is useful
322 * if memory survives reboots, so xpr_dump can show
323 * the previous buffer contents.
326 (void) memset((void *) addr
, 0, size
);
329 xprbase
= (struct xprbuf
*) addr
;
330 xprlast
= &xprbase
[nxprbufs
];
331 xprptr
= xprbase
; /* setting xprptr enables tracing */
339 xprflags
|= xprinitial
;
343 #include <ddb/db_output.h>
346 * Prototypes for functions called from the debugger
358 extern jmp_buf_t
*db_recover
;
361 * Print current content of xpr buffers (KDB's sake)
362 * Use stack order to make it understandable.
364 * Called as "!xpr_dump" this dumps the kernel's xpr buffer.
365 * Called with arguments, it can dump xpr buffers in user tasks,
366 * assuming they use the same format as the kernel.
375 struct xprbuf
*last
, *ptr
;
376 register struct xprbuf
*x
;
388 if (base
== xprbase
) {
390 simple_lock(&xprlock
);
394 ptr
= * (struct xprbuf
**) last
;
397 if (_setjmp(db_recover
= &db_jmpbuf
) == 0)
398 for (x
= ptr
, i
= 0; i
< nbufs
; i
++) {
405 db_printf("<%d:%x:%x> ", x
- base
, x
->cpuinfo
, x
->timestamp
);
406 db_printf(x
->msg
, x
->arg1
,x
->arg2
,x
->arg3
,x
->arg4
,x
->arg5
);
410 if (base
== xprbase
) {
411 simple_unlock(&xprlock
);
417 * dump xpr table with a selection criteria.
418 * argument number "arg_index" must equal "value"
428 register struct xprbuf
*x
;
438 simple_lock(&xprlock
);
441 if (_setjmp(db_recover
= &db_jmpbuf
) == 0)
442 for (x
= *(struct xprbuf
**)xprlast
; n
--; ) {
450 if (*((&x
->arg1
)+arg_index
) != value
)
453 db_printf("<%d:%d:%x> ", x
- xprbase
,
454 x
->cpuinfo
, x
->timestamp
);
455 db_printf(x
->msg
, x
->arg1
,x
->arg2
,x
->arg3
,x
->arg4
,x
->arg5
);
459 simple_unlock(&xprlock
);
462 #endif /* MACH_KDB */