]>
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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
31 * Revision 1.1.1.1 1998/09/22 21:05:32 wsanchez
32 * Import of Mac OS X kernel (~semeria)
34 * Revision 1.1.1.1 1998/03/07 02:25:57 wsanchez
35 * Import of OSF Mach kernel (~mburg)
37 * Revision 1.2.46.1 1997/09/22 17:41:21 barbou
38 * MP+RT: protect cpu_number() usage against preemption.
41 * Revision 1.2.25.5 1996/07/31 09:56:06 paire
42 * Merged with nmk20b7_shared (1.2.41.1)
45 * Revision 1.2.41.1 1996/04/15 14:35:12 bernadat
46 * Keep interrupts disabled while accessing XPR_TIMESTAMP.
49 * Revision 1.2.25.4 1995/02/24 15:22:42 alanl
50 * DIPC: Merge from nmk17b2 to nmk18b8.
51 * Notes: Restore portable locks package, derived from nmk17b2.
54 * Revision 1.2.28.3 1994/12/09 22:25:16 dwm
55 * mk6 CR801 - merge up from nmk18b4 to nmk18b7
56 * * Rev 1.2.25.2 1994/10/21 18:30:41 joe
58 * [1994/12/09 21:10:59 dwm]
60 * Revision 1.2.28.2 1994/11/10 06:15:29 dwm
61 * mk6 CR764 - s/spinlock/simple_lock/ (name change only)
62 * [1994/11/10 05:58:48 dwm]
64 * Revision 1.2.28.1 1994/11/04 10:10:56 dwm
65 * mk6 CR668 - 1.3b26 merge
66 * * Revision 1.2.5.7 1994/05/06 18:54:13 tmt
67 * Merge in DEC Alpha changes to osc1.3b19.
68 * include <mach/machine/vm_types.h>
71 * [1994/11/04 09:39:17 dwm]
73 * Revision 1.2.25.1 1994/09/23 02:32:39 ezf
74 * change marker to not FREE
75 * [1994/09/22 21:38:29 ezf]
77 * Revision 1.2.22.1 1994/06/09 14:14:11 dswartz
79 * [1994/06/09 14:08:38 dswartz]
81 * Revision 1.2.5.5 1993/08/12 20:16:51 bernard
82 * Last pass for ANSI prototypes - CR#9523
83 * [1993/08/12 15:43:24 bernard]
85 * Revision 1.2.5.4 1993/08/02 17:26:05 rod
86 * ANSI prototypes: zap explicit include of machine/setjmp.h. CR #9523.
87 * [1993/08/01 13:36:31 rod]
89 * Revision 1.2.5.3 1993/07/27 18:09:05 rod
90 * Add ANSI prototypes. CR #9523.
91 * [1993/07/27 14:33:23 rod]
93 * Revision 1.2.5.2 1993/06/09 02:39:13 gm
94 * CR9176 - ANSI C violations: trailing tokens on CPP
95 * directives, extra semicolons after decl_ ..., asm keywords
96 * [1993/06/07 19:07:51 jeffc]
98 * Added to OSF/1 R1.3 from NMK15.0.
99 * [1993/06/02 21:15:13 jeffc]
101 * Revision 1.2 1993/04/19 16:31:21 devrcs
102 * Added void to fcns that still needed it.
105 * Revision 1.1 1992/09/30 02:10:39 robert
112 * Revision 2.9.5.2 92/03/03 16:20:57 jeffreyh
114 * [92/02/24 13:24:44 jeffreyh]
116 * Revision 2.9.5.1 92/02/18 19:13:03 jeffreyh
117 * Added an xpr_search function to which you can give
118 * a selection function.
119 * [92/02/11 08:13:23 bernadat]
121 * Revision 2.9.4.1 92/02/13 18:53:47 jeffreyh
122 * Added an xpr_search function to which you can give
123 * a selection function.
124 * [92/02/11 08:13:23 bernadat]
126 * Revision 2.9.3.1 92/02/11 17:19:59 jeffreyh
127 * Added an xpr_search function to which you can give
128 * a selection function.
129 * [92/02/11 08:13:23 bernadat]
131 * Revision 2.9.2.1 92/02/11 08:13:23 bernadat
132 * Added an xpr_search function to which you can give
133 * a selection function.
136 * Revision 2.9 91/10/09 16:11:50 af
137 * Removed xpr_save. Modified xpr_dump to make it useful
138 * for dumping xpr buffers in user space tasks.
141 * Turned on xprenable by default. xprbootstrap now preserves
142 * the original contents of the buffer if xprenable is off.
145 * Revision 2.8 91/08/28 11:14:56 jsb
146 * Fixed xprbootstrap to zero the allocate memory.
149 * Revision 2.7 91/05/18 14:34:37 rpd
150 * Added xprenable and other minor changes so that the xpr buffer
151 * may be examined after a spontaneous reboot.
153 * Fixed the initialization check in xpr.
157 * Revision 2.6 91/05/14 16:50:09 mrt
158 * Correcting copyright
160 * Revision 2.5 91/03/16 14:53:24 rpd
161 * Updated for new kmem_alloc interface.
164 * Revision 2.4 91/02/05 17:31:13 mrt
165 * Changed to new Mach copyright
166 * [91/02/01 16:21:17 mrt]
168 * Revision 2.3 90/09/09 14:33:04 rpd
169 * Use decl_simple_lock_data.
172 * Revision 2.2 89/11/29 14:09:21 af
173 * Added xpr_dump() to print on console the content of the buffer,
174 * only valid for KDB usage.
177 * MACH_KERNEL: include sys/cpu_number.h instead of machine/cpu.h.
181 * Revision 2.1 89/08/03 15:49:11 rwd
184 * Revision 2.2 88/12/19 02:48:30 mwyoung
185 * Fix include file references.
186 * [88/11/22 02:17:01 mwyoung]
188 * Separate initialization into two phases.
189 * [88/11/22 01:13:11 mwyoung]
191 * 6-Jan-88 Michael Young (mwyoung) at Carnegie-Mellon University
192 * Eliminate use of arg6 in order to allow a more shapely event structure.
194 * 30-Dec-87 David Golub (dbg) at Carnegie-Mellon University
197 * 7-Dec-87 Richard Sanzi (sanzi) at Carnegie-Mellon University
198 * Added xpr_save() routine.
203 * Mach Operating System
204 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
205 * All Rights Reserved.
207 * Permission to use, copy, modify and distribute this software and its
208 * documentation is hereby granted, provided that both the copyright
209 * notice and this permission notice appear in all copies of the
210 * software, derivative works or modified versions, and any portions
211 * thereof, and that both notices appear in supporting documentation.
213 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
214 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
215 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
217 * Carnegie Mellon requests users of this software to return to
219 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
220 * School of Computer Science
221 * Carnegie Mellon University
222 * Pittsburgh PA 15213-3890
224 * any improvements or extensions that they make and grant Carnegie Mellon
225 * the rights to redistribute these changes.
227 #include <mach_kdb.h>
229 * xpr silent tracing circular buffer.
234 #include <mach/machine/vm_types.h>
235 #include <kern/xpr.h>
236 #include <kern/lock.h>
237 #include <kern/spl.h>
238 #include <kern/cpu_number.h>
239 #include <kern/misc_protos.h>
240 #include <kern/thread.h>
241 #include <vm/vm_kern.h>
245 * After a spontaneous reboot, it is desirable to look
246 * at the old xpr buffer. Assuming xprbootstrap allocates
247 * the buffer in the same place in physical memory and
248 * the reboot doesn't clear memory, this should work.
249 * xprptr will be reset, but the saved value should be OK.
250 * Just set xprenable false so the buffer isn't overwritten.
253 decl_simple_lock_data(,xprlock
)
254 boolean_t xprenable
= TRUE
; /* Enable xpr tracing */
255 int nxprbufs
= 0; /* Number of contiguous xprbufs allocated */
256 int xprflags
= 0; /* Bit mask of xpr flags enabled */
257 struct xprbuf
*xprbase
; /* Pointer to circular buffer nxprbufs*sizeof(xprbuf)*/
258 struct xprbuf
*xprptr
; /* Currently allocated xprbuf */
259 struct xprbuf
*xprlast
; /* Pointer to end of circular buffer */
271 register struct xprbuf
*x
;
273 /* If we aren't initialized, ignore trace request */
274 if (!xprenable
|| (xprptr
== 0))
276 /* Guard against all interrupts and allocate next buffer. */
279 simple_lock(&xprlock
);
281 if (xprptr
>= xprlast
) {
285 /* Save xprptr in allocated memory. */
286 *(struct xprbuf
**)xprlast
= xprptr
;
287 simple_unlock(&xprlock
);
288 x
->timestamp
= XPR_TIMESTAMP
;
296 mp_disable_preemption();
297 x
->cpuinfo
= cpu_number();
298 mp_enable_preemption();
308 simple_lock_init(&xprlock
, ETAP_MISC_XPR
);
310 return; /* assume XPR support not desired */
312 /* leave room at the end for a saved copy of xprptr */
313 size
= nxprbufs
* sizeof(struct xprbuf
) + sizeof xprptr
;
315 kr
= kmem_alloc_wired(kernel_map
, &addr
, size
);
316 if (kr
!= KERN_SUCCESS
)
317 panic("xprbootstrap");
321 * If xprenable is set (the default) then we zero
322 * the buffer so xpr_dump doesn't encounter bad pointers.
323 * If xprenable isn't set, then we preserve
324 * the original contents of the buffer. This is useful
325 * if memory survives reboots, so xpr_dump can show
326 * the previous buffer contents.
329 (void) memset((void *) addr
, 0, size
);
332 xprbase
= (struct xprbuf
*) addr
;
333 xprlast
= &xprbase
[nxprbufs
];
334 xprptr
= xprbase
; /* setting xprptr enables tracing */
342 xprflags
|= xprinitial
;
346 #include <ddb/db_output.h>
349 * Prototypes for functions called from the debugger
361 extern jmp_buf_t
*db_recover
;
364 * Print current content of xpr buffers (KDB's sake)
365 * Use stack order to make it understandable.
367 * Called as "!xpr_dump" this dumps the kernel's xpr buffer.
368 * Called with arguments, it can dump xpr buffers in user tasks,
369 * assuming they use the same format as the kernel.
378 struct xprbuf
*last
, *ptr
;
379 register struct xprbuf
*x
;
391 if (base
== xprbase
) {
393 simple_lock(&xprlock
);
397 ptr
= * (struct xprbuf
**) last
;
400 if (_setjmp(db_recover
= &db_jmpbuf
) == 0)
401 for (x
= ptr
, i
= 0; i
< nbufs
; i
++) {
408 db_printf("<%d:%x:%x> ", x
- base
, x
->cpuinfo
, x
->timestamp
);
409 db_printf(x
->msg
, x
->arg1
,x
->arg2
,x
->arg3
,x
->arg4
,x
->arg5
);
413 if (base
== xprbase
) {
414 simple_unlock(&xprlock
);
420 * dump xpr table with a selection criteria.
421 * argument number "arg_index" must equal "value"
431 register struct xprbuf
*x
;
441 simple_lock(&xprlock
);
444 if (_setjmp(db_recover
= &db_jmpbuf
) == 0)
445 for (x
= *(struct xprbuf
**)xprlast
; n
--; ) {
453 if (*((&x
->arg1
)+arg_index
) != value
)
456 db_printf("<%d:%d:%x> ", x
- xprbase
,
457 x
->cpuinfo
, x
->timestamp
);
458 db_printf(x
->msg
, x
->arg1
,x
->arg2
,x
->arg3
,x
->arg4
,x
->arg5
);
462 simple_unlock(&xprlock
);
465 #endif /* MACH_KDB */