| 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( |
| 60 | char *msg, |
| 61 | int arg1, |
| 62 | int arg2, |
| 63 | int arg3, |
| 64 | int arg4, |
| 65 | int arg5) |
| 66 | { |
| 67 | spl_t s; |
| 68 | struct xprbuf *x; |
| 69 | |
| 70 | |
| 71 | if (!xprenable || (xprptr == 0)) |
| 72 | return; |
| 73 | |
| 74 | s = splhigh(); |
| 75 | simple_lock(&xprlock); |
| 76 | x = xprptr++; |
| 77 | if (xprptr >= xprlast) { |
| 78 | |
| 79 | xprptr = xprbase; |
| 80 | } |
| 81 | |
| 82 | *(struct xprbuf **)xprlast = xprptr; |
| 83 | simple_unlock(&xprlock)((void)(&xprlock)); |
| 84 | splx(s); |
| 85 | x->msg = msg; |
| 86 | x->arg1 = arg1; |
| 87 | x->arg2 = arg2; |
| 88 | x->arg3 = arg3; |
| 89 | x->arg4 = arg4; |
| 90 | x->arg5 = arg5; |
| 91 | x->timestamp = XPR_TIMESTAMP(0); |
| 92 | x->cpuinfo = cpu_number()(0); |
| 93 | } |
| 94 | |
| 95 | void xprbootstrap(void) |
| 96 | { |
| 97 | vm_offset_t addr; |
| 98 | vm_size_t size; |
| 99 | kern_return_t kr; |
| 100 | |
| 101 | simple_lock_init(&xprlock); |
| 102 | if (nxprbufs == 0) |
| 103 | return; |
| 104 | |
| 105 | |
| 106 | size = nxprbufs * sizeof(struct xprbuf) + sizeof xprptr; |
| 107 | |
| 108 | kr = kmem_alloc_wired(kernel_map, &addr, size); |
| 109 | if (kr != KERN_SUCCESS0) |
| 110 | panic("xprbootstrap"); |
| 111 | |
| 112 | if (xprenable) { |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | memset((void *) addr, 0, size); |
| 123 | } |
| 124 | |
| 125 | xprbase = (struct xprbuf *) addr; |
| 126 | xprlast = &xprbase[nxprbufs]; |
| 127 | xprptr = xprbase; |
| 128 | } |
| 129 | |
| 130 | int xprinitial = 0; |
| 131 | |
| 132 | void xprinit(void) |
| 133 | { |
| 134 | xprflags |= xprinitial; |
| 135 | } |
| 136 | |
| 137 | #if MACH_KDB1 |
| 138 | #include <machine/setjmp.h> |
| 139 | #include <ddb/db_output.h> |
| 140 | |
| 141 | extern jmp_buf_t *db_recover; |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | void xpr_dump( |
| 152 | struct xprbuf *base, |
| 153 | int nbufs) |
| 154 | { |
| 155 | jmp_buf_t db_jmpbuf; |
| 156 | jmp_buf_t *prev; |
| 157 | struct xprbuf *last, *ptr; |
| 158 | struct xprbuf *x; |
| 159 | int i; |
| 160 | spl_t s = s; |
| Assigned value is garbage or undefined |
| 161 | |
| 162 | if (base == 0) { |
| 163 | base = xprbase; |
| 164 | nbufs = nxprbufs; |
| 165 | } |
| 166 | |
| 167 | if (nbufs == 0) |
| 168 | return; |
| 169 | |
| 170 | if (base == xprbase) { |
| 171 | s = splhigh(); |
| 172 | simple_lock(&xprlock); |
| 173 | } |
| 174 | |
| 175 | last = base + nbufs; |
| 176 | ptr = * (struct xprbuf **) last; |
| 177 | |
| 178 | prev = db_recover; |
| 179 | if (_setjmp(db_recover = &db_jmpbuf) == 0) |
| 180 | for (x = ptr, i = 0; i < nbufs; i++) { |
| 181 | if (--x < base) |
| 182 | x = last - 1; |
| 183 | |
| 184 | if (x->msg == 0) |
| 185 | break; |
| 186 | |
| 187 | db_printf("<%d:%x:%x> ", x - base, x->cpuinfo, x->timestamp); |
| 188 | db_printf(x->msg, x->arg1,x->arg2,x->arg3,x->arg4,x->arg5); |
| 189 | } |
| 190 | db_recover = prev; |
| 191 | |
| 192 | if (base == xprbase) { |
| 193 | simple_unlock(&xprlock)((void)(&xprlock)); |
| 194 | (void) splx(s); |
| 195 | } |
| 196 | } |
| 197 | #endif /* MACH_KDB */ |