FreeBSD/Linux Kernel Cross Reference
sys/kern/xpr.c
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: xpr.c,v $
29 * Revision 2.13 93/05/15 18:56:18 mrt
30 * machparam.h -> machspl.h
31 *
32 * Revision 2.12 93/01/14 17:37:26 danner
33 * Proper spl typing.
34 * [92/12/01 af]
35 *
36 * Revision 2.11 92/08/03 17:40:31 jfriedl
37 * removed silly prototypes
38 * [92/08/02 jfriedl]
39 *
40 * Revision 2.10 92/05/21 17:17:12 jfriedl
41 * tried prototypes.
42 * [92/05/20 jfriedl]
43 *
44 * 16-May-92 Jeffrey Friedl (jfriedl) at Carnegie-Mellon University
45 * Added void to fcns that still needed it.
46 * Revision 2.9 91/10/09 16:11:50 af
47 * Removed xpr_save. Modified xpr_dump to make it useful
48 * for dumping xpr buffers in user space tasks.
49 * [91/09/20 rpd]
50 *
51 * Turned on xprenable by default. xprbootstrap now preserves
52 * the original contents of the buffer if xprenable is off.
53 * [91/09/18 rpd]
54 *
55 * Revision 2.8 91/08/28 11:14:56 jsb
56 * Fixed xprbootstrap to zero the allocate memory.
57 * [91/08/18 rpd]
58 *
59 * Revision 2.7 91/05/18 14:34:37 rpd
60 * Added xprenable and other minor changes so that the xpr buffer
61 * may be examined after a spontaneous reboot.
62 * [91/05/03 rpd]
63 * Fixed the initialization check in xpr.
64 * Fixed xpr_dump.
65 * [91/04/02 rpd]
66 *
67 * Revision 2.6 91/05/14 16:50:09 mrt
68 * Correcting copyright
69 *
70 * Revision 2.5 91/03/16 14:53:24 rpd
71 * Updated for new kmem_alloc interface.
72 * [91/03/03 rpd]
73 *
74 * Revision 2.4 91/02/05 17:31:13 mrt
75 * Changed to new Mach copyright
76 * [91/02/01 16:21:17 mrt]
77 *
78 * Revision 2.3 90/09/09 14:33:04 rpd
79 * Use decl_simple_lock_data.
80 * [90/08/30 rpd]
81 *
82 * Revision 2.2 89/11/29 14:09:21 af
83 * Added xpr_dump() to print on console the content of the buffer,
84 * only valid for KDB usage.
85 * [89/11/12 af]
86 *
87 * MACH_KERNEL: include sys/cpu_number.h instead of machine/cpu.h.
88 * Clean up comments.
89 * [88/12/19 dbg]
90 *
91 * Revision 2.1 89/08/03 15:49:11 rwd
92 * Created.
93 *
94 * Revision 2.2 88/12/19 02:48:30 mwyoung
95 * Fix include file references.
96 * [88/11/22 02:17:01 mwyoung]
97 *
98 * Separate initialization into two phases.
99 * [88/11/22 01:13:11 mwyoung]
100 *
101 * 6-Jan-88 Michael Young (mwyoung) at Carnegie-Mellon University
102 * Eliminate use of arg6 in order to allow a more shapely event structure.
103 *
104 * 30-Dec-87 David Golub (dbg) at Carnegie-Mellon University
105 * Delinted.
106 *
107 * 7-Dec-87 Richard Sanzi (sanzi) at Carnegie-Mellon University
108 * Added xpr_save() routine.
109 *
110 */
111 #include <mach_kdb.h>
112 /*
113 * xpr silent tracing circular buffer.
114 */
115 #include <kern/xpr.h>
116 #include <kern/lock.h>
117 #include <kern/cpu_number.h>
118 #include <machine/machspl.h>
119 #include <vm/vm_kern.h>
120
121
122 /*
123 * After a spontaneous reboot, it is desirable to look
124 * at the old xpr buffer. Assuming xprbootstrap allocates
125 * the buffer in the same place in physical memory and
126 * the reboot doesn't clear memory, this should work.
127 * xprptr will be reset, but the saved value should be OK.
128 * Just set xprenable false so the buffer isn't overwritten.
129 */
130
131 decl_simple_lock_data(, xprlock)
132
133 boolean_t xprenable = TRUE; /* Enable xpr tracing */
134 int nxprbufs = 0; /* Number of contiguous xprbufs allocated */
135 int xprflags = 0; /* Bit mask of xpr flags enabled */
136 struct xprbuf *xprbase; /* Pointer to circular buffer nxprbufs*sizeof(xprbuf)*/
137 struct xprbuf *xprptr; /* Currently allocated xprbuf */
138 struct xprbuf *xprlast; /* Pointer to end of circular buffer */
139
140 /*VARARGS1*/
141 void xpr(msg, arg1, arg2, arg3, arg4, arg5)
142 char *msg;
143 int arg1, arg2, arg3, arg4, arg5;
144 {
145 register spl_t s;
146 register struct xprbuf *x;
147
148 /* If we aren't initialized, ignore trace request */
149 if (!xprenable || (xprptr == 0))
150 return;
151 /* Guard against all interrupts and allocate next buffer. */
152 s = splhigh();
153 simple_lock(&xprlock);
154 x = xprptr++;
155 if (xprptr >= xprlast) {
156 /* wrap around */
157 xprptr = xprbase;
158 }
159 /* Save xprptr in allocated memory. */
160 *(struct xprbuf **)xprlast = xprptr;
161 simple_unlock(&xprlock);
162 splx(s);
163 x->msg = msg;
164 x->arg1 = arg1;
165 x->arg2 = arg2;
166 x->arg3 = arg3;
167 x->arg4 = arg4;
168 x->arg5 = arg5;
169 x->timestamp = XPR_TIMESTAMP;
170 x->cpuinfo = cpu_number();
171 }
172
173 void xprbootstrap()
174 {
175 vm_offset_t addr;
176 vm_size_t size;
177 kern_return_t kr;
178
179 simple_lock_init(&xprlock);
180 if (nxprbufs == 0)
181 return; /* assume XPR support not desired */
182
183 /* leave room at the end for a saved copy of xprptr */
184 size = nxprbufs * sizeof(struct xprbuf) + sizeof xprptr;
185
186 kr = kmem_alloc_wired(kernel_map, &addr, size);
187 if (kr != KERN_SUCCESS)
188 panic("xprbootstrap");
189
190 if (xprenable) {
191 /*
192 * If xprenable is set (the default) then we zero
193 * the buffer so xpr_dump doesn't encounter bad pointers.
194 * If xprenable isn't set, then we preserve
195 * the original contents of the buffer. This is useful
196 * if memory survives reboots, so xpr_dump can show
197 * the previous buffer contents.
198 */
199
200 bzero((char *) addr, size);
201 }
202
203 xprbase = (struct xprbuf *) addr;
204 xprlast = &xprbase[nxprbufs];
205 xprptr = xprbase; /* setting xprptr enables tracing */
206 }
207
208 int xprinitial = 0;
209
210 void xprinit()
211 {
212 xprflags |= xprinitial;
213 }
214
215 #if MACH_KDB
216 #include <machine/setjmp.h>
217
218
219 extern void db_printf();
220 extern jmp_buf_t *db_recover;
221
222 /*
223 * Print current content of xpr buffers (KDB's sake)
224 * Use stack order to make it understandable.
225 *
226 * Called as "!xpr_dump" this dumps the kernel's xpr buffer.
227 * Called with arguments, it can dump xpr buffers in user tasks,
228 * assuming they use the same format as the kernel.
229 */
230 void xpr_dump(base, nbufs)
231 struct xprbuf *base;
232 int nbufs;
233 {
234 jmp_buf_t db_jmpbuf;
235 jmp_buf_t *prev;
236 struct xprbuf *last, *ptr;
237 register struct xprbuf *x;
238 int i;
239 spl_t s;
240
241 if (base == 0) {
242 base = xprbase;
243 nbufs = nxprbufs;
244 }
245
246 if (nbufs == 0)
247 return;
248
249 if (base == xprbase) {
250 s = splhigh();
251 simple_lock(&xprlock);
252 }
253
254 last = base + nbufs;
255 ptr = * (struct xprbuf **) last;
256
257 prev = db_recover;
258 if (_setjmp(db_recover = &db_jmpbuf) == 0)
259 for (x = ptr, i = 0; i < nbufs; i++) {
260 if (--x < base)
261 x = last - 1;
262
263 if (x->msg == 0)
264 break;
265
266 db_printf("<%d:%x:%x> ", x - base, x->cpuinfo, x->timestamp);
267 db_printf(x->msg, x->arg1,x->arg2,x->arg3,x->arg4,x->arg5);
268 }
269 db_recover = prev;
270
271 if (base == xprbase) {
272 simple_unlock(&xprlock);
273 (void) splx(s);
274 }
275 }
276 #endif MACH_KDB
Cache object: 45d9641d4377d86e636678adf39a0d65
|