]>
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_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@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
52 * xpr silent tracing circular buffer.
55 #include <mach/machine/vm_types.h>
57 #include <kern/lock.h>
59 #include <kern/cpu_number.h>
60 #include <kern/misc_protos.h>
61 #include <kern/thread.h>
62 #include <vm/vm_kern.h>
66 * After a spontaneous reboot, it is desirable to look
67 * at the old xpr buffer. Assuming xprbootstrap allocates
68 * the buffer in the same place in physical memory and
69 * the reboot doesn't clear memory, this should work.
70 * xprptr will be reset, but the saved value should be OK.
71 * Just set xprenable false so the buffer isn't overwritten.
74 decl_simple_lock_data(,xprlock
)
75 boolean_t xprenable
= TRUE
; /* Enable xpr tracing */
76 int nxprbufs
= 0; /* Number of contiguous xprbufs allocated */
77 int xprflags
= 0; /* Bit mask of xpr flags enabled */
78 struct xprbuf
*xprbase
; /* Pointer to circular buffer nxprbufs*sizeof(xprbuf)*/
79 struct xprbuf
*xprptr
; /* Currently allocated xprbuf */
80 struct xprbuf
*xprlast
; /* Pointer to end of circular buffer */
92 register struct xprbuf
*x
;
94 /* If we aren't initialized, ignore trace request */
95 if (!xprenable
|| (xprptr
== 0))
97 /* Guard against all interrupts and allocate next buffer. */
100 simple_lock(&xprlock
);
102 if (xprptr
>= xprlast
) {
106 /* Save xprptr in allocated memory. */
107 *(struct xprbuf
**)xprlast
= xprptr
;
108 simple_unlock(&xprlock
);
109 x
->timestamp
= XPR_TIMESTAMP
;
117 mp_disable_preemption();
118 x
->cpuinfo
= cpu_number();
119 mp_enable_preemption();
129 simple_lock_init(&xprlock
, 0);
131 return; /* assume XPR support not desired */
133 /* leave room at the end for a saved copy of xprptr */
134 size
= nxprbufs
* sizeof(struct xprbuf
) + sizeof xprptr
;
136 kr
= kmem_alloc_wired(kernel_map
, &addr
, size
);
137 if (kr
!= KERN_SUCCESS
)
138 panic("xprbootstrap");
142 * If xprenable is set (the default) then we zero
143 * the buffer so xpr_dump doesn't encounter bad pointers.
144 * If xprenable isn't set, then we preserve
145 * the original contents of the buffer. This is useful
146 * if memory survives reboots, so xpr_dump can show
147 * the previous buffer contents.
150 (void) memset((void *) addr
, 0, size
);
153 xprbase
= (struct xprbuf
*) addr
;
154 xprlast
= &xprbase
[nxprbufs
];
155 xprptr
= xprbase
; /* setting xprptr enables tracing */
163 xprflags
|= xprinitial
;
167 #include <ddb/db_output.h>
170 * Prototypes for functions called from the debugger
182 extern jmp_buf_t
*db_recover
;
185 * Print current content of xpr buffers (KDB's sake)
186 * Use stack order to make it understandable.
188 * Called as "!xpr_dump" this dumps the kernel's xpr buffer.
189 * Called with arguments, it can dump xpr buffers in user tasks,
190 * assuming they use the same format as the kernel.
199 struct xprbuf
*last
, *ptr
;
200 register struct xprbuf
*x
;
212 if (base
== xprbase
) {
214 simple_lock(&xprlock
);
218 ptr
= * (struct xprbuf
**) last
;
221 if (_setjmp(db_recover
= &db_jmpbuf
) == 0)
222 for (x
= ptr
, i
= 0; i
< nbufs
; i
++) {
229 db_printf("<%d:%x:%x> ", x
- base
, x
->cpuinfo
, x
->timestamp
);
230 db_printf(x
->msg
, x
->arg1
,x
->arg2
,x
->arg3
,x
->arg4
,x
->arg5
);
234 if (base
== xprbase
) {
235 simple_unlock(&xprlock
);
241 * dump xpr table with a selection criteria.
242 * argument number "arg_index" must equal "value"
252 register struct xprbuf
*x
;
262 simple_lock(&xprlock
);
265 if (_setjmp(db_recover
= &db_jmpbuf
) == 0)
266 for (x
= *(struct xprbuf
**)xprlast
; n
--; ) {
274 if (*((&x
->arg1
)+arg_index
) != value
)
277 db_printf("<%d:%d:%x> ", x
- xprbase
,
278 x
->cpuinfo
, x
->timestamp
);
279 db_printf(x
->msg
, x
->arg1
,x
->arg2
,x
->arg3
,x
->arg4
,x
->arg5
);
283 simple_unlock(&xprlock
);
286 #endif /* MACH_KDB */