1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | #include <string.h> |
31 | |
32 | #include <kern/debug.h> |
33 | #include <kern/xpr.h> |
34 | #include <kern/lock.h> |
35 | #include "cpu_number.h" |
36 | #include <machine/machspl.h> |
37 | #include <vm/vm_kern.h> |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | decl_simple_lock_data(, xprlock)struct simple_lock_data_empty xprlock; |
50 | |
51 | boolean_t xprenable = TRUE((boolean_t) 1); |
52 | int nxprbufs = 0; |
53 | int xprflags = 0; |
54 | struct xprbuf *xprbase; |
55 | struct xprbuf *xprptr; |
56 | struct xprbuf *xprlast; |
57 | |
58 | |
59 | void xpr(msg, arg1, arg2, arg3, arg4, arg5) |
60 | char *msg; |
61 | int arg1, arg2, arg3, arg4, arg5; |
62 | { |
63 | spl_t s; |
64 | struct xprbuf *x; |
65 | |
66 | |
67 | if (!xprenable || (xprptr == 0)) |
68 | return; |
69 | |
70 | s = splhigh(); |
71 | simple_lock(&xprlock); |
72 | x = xprptr++; |
73 | if (xprptr >= xprlast) { |
74 | |
75 | xprptr = xprbase; |
76 | } |
77 | |
78 | *(struct xprbuf **)xprlast = xprptr; |
79 | simple_unlock(&xprlock)((void)(&xprlock)); |
80 | splx(s); |
81 | x->msg = msg; |
82 | x->arg1 = arg1; |
83 | x->arg2 = arg2; |
84 | x->arg3 = arg3; |
85 | x->arg4 = arg4; |
86 | x->arg5 = arg5; |
87 | x->timestamp = XPR_TIMESTAMP(0); |
88 | x->cpuinfo = cpu_number()(0); |
89 | } |
90 | |
91 | void xprbootstrap(void) |
92 | { |
93 | vm_offset_t addr; |
94 | vm_size_t size; |
95 | kern_return_t kr; |
96 | |
97 | simple_lock_init(&xprlock); |
98 | if (nxprbufs == 0) |
99 | return; |
100 | |
101 | |
102 | size = nxprbufs * sizeof(struct xprbuf) + sizeof xprptr; |
103 | |
104 | kr = kmem_alloc_wired(kernel_map, &addr, size); |
105 | if (kr != KERN_SUCCESS0) |
106 | panic("xprbootstrap"); |
107 | |
108 | if (xprenable) { |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | memset((void *) addr, 0, size); |
119 | } |
120 | |
121 | xprbase = (struct xprbuf *) addr; |
122 | xprlast = &xprbase[nxprbufs]; |
123 | xprptr = xprbase; |
124 | } |
125 | |
126 | int xprinitial = 0; |
127 | |
128 | void xprinit(void) |
129 | { |
130 | xprflags |= xprinitial; |
131 | } |
132 | |
133 | #if MACH_KDB1 |
134 | #include <machine/setjmp.h> |
135 | #include <ddb/db_output.h> |
136 | |
137 | extern jmp_buf_t *db_recover; |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | void xpr_dump(base, nbufs) |
148 | struct xprbuf *base; |
149 | int nbufs; |
150 | { |
151 | jmp_buf_t db_jmpbuf; |
152 | jmp_buf_t *prev; |
153 | struct xprbuf *last, *ptr; |
154 | struct xprbuf *x; |
155 | int i; |
156 | spl_t s = s; |
| Assigned value is garbage or undefined |
157 | |
158 | if (base == 0) { |
159 | base = xprbase; |
160 | nbufs = nxprbufs; |
161 | } |
162 | |
163 | if (nbufs == 0) |
164 | return; |
165 | |
166 | if (base == xprbase) { |
167 | s = splhigh(); |
168 | simple_lock(&xprlock); |
169 | } |
170 | |
171 | last = base + nbufs; |
172 | ptr = * (struct xprbuf **) last; |
173 | |
174 | prev = db_recover; |
175 | if (_setjmp(db_recover = &db_jmpbuf) == 0) |
176 | for (x = ptr, i = 0; i < nbufs; i++) { |
177 | if (--x < base) |
178 | x = last - 1; |
179 | |
180 | if (x->msg == 0) |
181 | break; |
182 | |
183 | db_printf("<%d:%x:%x> ", x - base, x->cpuinfo, x->timestamp); |
184 | db_printf(x->msg, x->arg1,x->arg2,x->arg3,x->arg4,x->arg5); |
185 | } |
186 | db_recover = prev; |
187 | |
188 | if (base == xprbase) { |
189 | simple_unlock(&xprlock)((void)(&xprlock)); |
190 | (void) splx(s); |
191 | } |
192 | } |
193 | #endif /* MACH_KDB */ |