]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/xpr.c
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
60 * xpr silent tracing circular buffer.
63 #include <mach/machine/vm_types.h>
65 #include <kern/lock.h>
67 #include <kern/cpu_number.h>
68 #include <kern/misc_protos.h>
69 #include <kern/thread.h>
70 #include <vm/vm_kern.h>
74 * After a spontaneous reboot, it is desirable to look
75 * at the old xpr buffer. Assuming xprbootstrap allocates
76 * the buffer in the same place in physical memory and
77 * the reboot doesn't clear memory, this should work.
78 * xprptr will be reset, but the saved value should be OK.
79 * Just set xprenable false so the buffer isn't overwritten.
82 decl_simple_lock_data(,xprlock
)
83 boolean_t xprenable
= TRUE
; /* Enable xpr tracing */
84 int nxprbufs
= 0; /* Number of contiguous xprbufs allocated */
85 int xprflags
= 0; /* Bit mask of xpr flags enabled */
86 struct xprbuf
*xprbase
; /* Pointer to circular buffer nxprbufs*sizeof(xprbuf)*/
87 struct xprbuf
*xprptr
; /* Currently allocated xprbuf */
88 struct xprbuf
*xprlast
; /* Pointer to end of circular buffer */
100 register struct xprbuf
*x
;
102 /* If we aren't initialized, ignore trace request */
103 if (!xprenable
|| (xprptr
== 0))
105 /* Guard against all interrupts and allocate next buffer. */
108 simple_lock(&xprlock
);
110 if (xprptr
>= xprlast
) {
114 /* Save xprptr in allocated memory. */
115 *(struct xprbuf
**)xprlast
= xprptr
;
116 simple_unlock(&xprlock
);
117 x
->timestamp
= XPR_TIMESTAMP
;
125 mp_disable_preemption();
126 x
->cpuinfo
= cpu_number();
127 mp_enable_preemption();
137 simple_lock_init(&xprlock
, 0);
139 return; /* assume XPR support not desired */
141 /* leave room at the end for a saved copy of xprptr */
142 size
= nxprbufs
* sizeof(struct xprbuf
) + sizeof xprptr
;
144 kr
= kmem_alloc_wired(kernel_map
, &addr
, size
);
145 if (kr
!= KERN_SUCCESS
)
146 panic("xprbootstrap");
150 * If xprenable is set (the default) then we zero
151 * the buffer so xpr_dump doesn't encounter bad pointers.
152 * If xprenable isn't set, then we preserve
153 * the original contents of the buffer. This is useful
154 * if memory survives reboots, so xpr_dump can show
155 * the previous buffer contents.
158 (void) memset((void *) addr
, 0, size
);
161 xprbase
= (struct xprbuf
*) addr
;
162 xprlast
= &xprbase
[nxprbufs
];
163 xprptr
= xprbase
; /* setting xprptr enables tracing */
171 xprflags
|= xprinitial
;
175 #include <ddb/db_output.h>
178 * Prototypes for functions called from the debugger
190 extern jmp_buf_t
*db_recover
;
193 * Print current content of xpr buffers (KDB's sake)
194 * Use stack order to make it understandable.
196 * Called as "!xpr_dump" this dumps the kernel's xpr buffer.
197 * Called with arguments, it can dump xpr buffers in user tasks,
198 * assuming they use the same format as the kernel.
207 struct xprbuf
*last
, *ptr
;
208 register struct xprbuf
*x
;
220 if (base
== xprbase
) {
222 simple_lock(&xprlock
);
226 ptr
= * (struct xprbuf
**) last
;
229 if (_setjmp(db_recover
= &db_jmpbuf
) == 0)
230 for (x
= ptr
, i
= 0; i
< nbufs
; i
++) {
237 db_printf("<%d:%x:%x> ", x
- base
, x
->cpuinfo
, x
->timestamp
);
238 db_printf(x
->msg
, x
->arg1
,x
->arg2
,x
->arg3
,x
->arg4
,x
->arg5
);
242 if (base
== xprbase
) {
243 simple_unlock(&xprlock
);
249 * dump xpr table with a selection criteria.
250 * argument number "arg_index" must equal "value"
260 register struct xprbuf
*x
;
270 simple_lock(&xprlock
);
273 if (_setjmp(db_recover
= &db_jmpbuf
) == 0)
274 for (x
= *(struct xprbuf
**)xprlast
; n
--; ) {
282 if (*((&x
->arg1
)+arg_index
) != value
)
285 db_printf("<%d:%d:%x> ", x
- xprbase
,
286 x
->cpuinfo
, x
->timestamp
);
287 db_printf(x
->msg
, x
->arg1
,x
->arg2
,x
->arg3
,x
->arg4
,x
->arg5
);
291 simple_unlock(&xprlock
);
294 #endif /* MACH_KDB */