]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
1c79356b A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
ff6e181a A |
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. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
1c79356b | 12 | * |
ff6e181a A |
13 | * The Original Code and all software distributed under the License are |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
ff6e181a A |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
1c79356b A |
20 | * |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | /* | |
24 | * @OSF_COPYRIGHT@ | |
25 | */ | |
1c79356b A |
26 | /* |
27 | * Mach Operating System | |
28 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University | |
29 | * All Rights Reserved. | |
30 | * | |
31 | * Permission to use, copy, modify and distribute this software and its | |
32 | * documentation is hereby granted, provided that both the copyright | |
33 | * notice and this permission notice appear in all copies of the | |
34 | * software, derivative works or modified versions, and any portions | |
35 | * thereof, and that both notices appear in supporting documentation. | |
36 | * | |
37 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
38 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
39 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
40 | * | |
41 | * Carnegie Mellon requests users of this software to return to | |
42 | * | |
43 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
44 | * School of Computer Science | |
45 | * Carnegie Mellon University | |
46 | * Pittsburgh PA 15213-3890 | |
47 | * | |
48 | * any improvements or extensions that they make and grant Carnegie Mellon | |
49 | * the rights to redistribute these changes. | |
50 | */ | |
51 | #include <mach_kdb.h> | |
52 | /* | |
53 | * xpr silent tracing circular buffer. | |
54 | */ | |
55 | ||
1c79356b A |
56 | #include <mach/machine/vm_types.h> |
57 | #include <kern/xpr.h> | |
58 | #include <kern/lock.h> | |
59 | #include <kern/spl.h> | |
60 | #include <kern/cpu_number.h> | |
61 | #include <kern/misc_protos.h> | |
62 | #include <kern/thread.h> | |
63 | #include <vm/vm_kern.h> | |
64 | #include <string.h> | |
65 | ||
66 | /* | |
67 | * After a spontaneous reboot, it is desirable to look | |
68 | * at the old xpr buffer. Assuming xprbootstrap allocates | |
69 | * the buffer in the same place in physical memory and | |
70 | * the reboot doesn't clear memory, this should work. | |
71 | * xprptr will be reset, but the saved value should be OK. | |
72 | * Just set xprenable false so the buffer isn't overwritten. | |
73 | */ | |
74 | ||
75 | decl_simple_lock_data(,xprlock) | |
76 | boolean_t xprenable = TRUE; /* Enable xpr tracing */ | |
77 | int nxprbufs = 0; /* Number of contiguous xprbufs allocated */ | |
78 | int xprflags = 0; /* Bit mask of xpr flags enabled */ | |
79 | struct xprbuf *xprbase; /* Pointer to circular buffer nxprbufs*sizeof(xprbuf)*/ | |
80 | struct xprbuf *xprptr; /* Currently allocated xprbuf */ | |
81 | struct xprbuf *xprlast; /* Pointer to end of circular buffer */ | |
82 | ||
83 | void | |
84 | xpr( | |
91447636 A |
85 | const char *msg, |
86 | long arg1, | |
87 | long arg2, | |
88 | long arg3, | |
89 | long arg4, | |
90 | long arg5) | |
1c79356b A |
91 | { |
92 | spl_t s; | |
93 | register struct xprbuf *x; | |
94 | ||
95 | /* If we aren't initialized, ignore trace request */ | |
96 | if (!xprenable || (xprptr == 0)) | |
97 | return; | |
98 | /* Guard against all interrupts and allocate next buffer. */ | |
99 | ||
100 | s = splhigh(); | |
101 | simple_lock(&xprlock); | |
102 | x = xprptr++; | |
103 | if (xprptr >= xprlast) { | |
104 | /* wrap around */ | |
105 | xprptr = xprbase; | |
106 | } | |
107 | /* Save xprptr in allocated memory. */ | |
108 | *(struct xprbuf **)xprlast = xprptr; | |
109 | simple_unlock(&xprlock); | |
110 | x->timestamp = XPR_TIMESTAMP; | |
111 | splx(s); | |
112 | x->msg = msg; | |
113 | x->arg1 = arg1; | |
114 | x->arg2 = arg2; | |
115 | x->arg3 = arg3; | |
116 | x->arg4 = arg4; | |
117 | x->arg5 = arg5; | |
118 | mp_disable_preemption(); | |
119 | x->cpuinfo = cpu_number(); | |
120 | mp_enable_preemption(); | |
121 | } | |
122 | ||
123 | void | |
124 | xprbootstrap(void) | |
125 | { | |
126 | vm_offset_t addr; | |
127 | vm_size_t size; | |
128 | kern_return_t kr; | |
129 | ||
91447636 | 130 | simple_lock_init(&xprlock, 0); |
1c79356b A |
131 | if (nxprbufs == 0) |
132 | return; /* assume XPR support not desired */ | |
133 | ||
134 | /* leave room at the end for a saved copy of xprptr */ | |
135 | size = nxprbufs * sizeof(struct xprbuf) + sizeof xprptr; | |
136 | ||
137 | kr = kmem_alloc_wired(kernel_map, &addr, size); | |
138 | if (kr != KERN_SUCCESS) | |
139 | panic("xprbootstrap"); | |
140 | ||
141 | if (xprenable) { | |
142 | /* | |
143 | * If xprenable is set (the default) then we zero | |
144 | * the buffer so xpr_dump doesn't encounter bad pointers. | |
145 | * If xprenable isn't set, then we preserve | |
146 | * the original contents of the buffer. This is useful | |
147 | * if memory survives reboots, so xpr_dump can show | |
148 | * the previous buffer contents. | |
149 | */ | |
150 | ||
151 | (void) memset((void *) addr, 0, size); | |
152 | } | |
153 | ||
154 | xprbase = (struct xprbuf *) addr; | |
155 | xprlast = &xprbase[nxprbufs]; | |
156 | xprptr = xprbase; /* setting xprptr enables tracing */ | |
157 | } | |
158 | ||
159 | int xprinitial = 0; | |
160 | ||
161 | void | |
162 | xprinit(void) | |
163 | { | |
164 | xprflags |= xprinitial; | |
165 | } | |
166 | ||
167 | #if MACH_KDB | |
168 | #include <ddb/db_output.h> | |
169 | ||
170 | /* | |
171 | * Prototypes for functions called from the debugger | |
172 | */ | |
173 | void | |
174 | xpr_dump( | |
175 | struct xprbuf *base, | |
176 | int nbufs); | |
177 | ||
178 | void | |
179 | xpr_search( | |
180 | int arg_index, | |
181 | int value); | |
182 | ||
183 | extern jmp_buf_t *db_recover; | |
184 | ||
185 | /* | |
186 | * Print current content of xpr buffers (KDB's sake) | |
187 | * Use stack order to make it understandable. | |
188 | * | |
189 | * Called as "!xpr_dump" this dumps the kernel's xpr buffer. | |
190 | * Called with arguments, it can dump xpr buffers in user tasks, | |
191 | * assuming they use the same format as the kernel. | |
192 | */ | |
193 | void | |
194 | xpr_dump( | |
195 | struct xprbuf *base, | |
196 | int nbufs) | |
197 | { | |
198 | jmp_buf_t db_jmpbuf; | |
199 | jmp_buf_t *prev; | |
200 | struct xprbuf *last, *ptr; | |
201 | register struct xprbuf *x; | |
202 | int i; | |
203 | spl_t s; | |
204 | ||
205 | if (base == 0) { | |
206 | base = xprbase; | |
207 | nbufs = nxprbufs; | |
208 | } | |
209 | ||
210 | if (nbufs == 0) | |
211 | return; | |
212 | ||
213 | if (base == xprbase) { | |
214 | s = splhigh(); | |
215 | simple_lock(&xprlock); | |
216 | } | |
217 | ||
218 | last = base + nbufs; | |
219 | ptr = * (struct xprbuf **) last; | |
220 | ||
221 | prev = db_recover; | |
222 | if (_setjmp(db_recover = &db_jmpbuf) == 0) | |
223 | for (x = ptr, i = 0; i < nbufs; i++) { | |
224 | if (--x < base) | |
225 | x = last - 1; | |
226 | ||
227 | if (x->msg == 0) | |
228 | break; | |
229 | ||
230 | db_printf("<%d:%x:%x> ", x - base, x->cpuinfo, x->timestamp); | |
231 | db_printf(x->msg, x->arg1,x->arg2,x->arg3,x->arg4,x->arg5); | |
232 | } | |
233 | db_recover = prev; | |
234 | ||
235 | if (base == xprbase) { | |
236 | simple_unlock(&xprlock); | |
237 | splx(s); | |
238 | } | |
239 | } | |
240 | ||
241 | /* | |
242 | * dump xpr table with a selection criteria. | |
243 | * argument number "arg_index" must equal "value" | |
244 | */ | |
245 | ||
246 | void | |
247 | xpr_search( | |
248 | int arg_index, | |
249 | int value) | |
250 | { | |
251 | jmp_buf_t db_jmpbuf; | |
252 | jmp_buf_t *prev; | |
253 | register struct xprbuf *x; | |
254 | spl_t s; | |
255 | int n; | |
256 | ||
257 | if (!nxprbufs) | |
258 | return; | |
259 | ||
260 | n = nxprbufs; | |
261 | ||
262 | s = splhigh(); | |
263 | simple_lock(&xprlock); | |
264 | ||
265 | prev = db_recover; | |
266 | if (_setjmp(db_recover = &db_jmpbuf) == 0) | |
267 | for (x = *(struct xprbuf **)xprlast ; n--; ) { | |
268 | if (--x < xprbase) | |
269 | x = xprlast - 1; | |
270 | ||
271 | if (x->msg == 0) { | |
272 | break; | |
273 | } | |
274 | ||
275 | if (*((&x->arg1)+arg_index) != value) | |
276 | continue; | |
277 | ||
278 | db_printf("<%d:%d:%x> ", x - xprbase, | |
279 | x->cpuinfo, x->timestamp); | |
280 | db_printf(x->msg, x->arg1,x->arg2,x->arg3,x->arg4,x->arg5); | |
281 | } | |
282 | db_recover = prev; | |
283 | ||
284 | simple_unlock(&xprlock); | |
285 | splx(s); | |
286 | } | |
287 | #endif /* MACH_KDB */ |