add swifi to the build/install.
[minix.git] / servers / is / dmp_kernel.c
blob8c0ea2b53d3e0462aa72f79c41cbbb458f03f9f1
1 /* Debugging dump procedures for the kernel. */
3 #include "inc.h"
4 #include <timers.h>
5 #include <ibm/interrupt.h>
6 #include <minix/endpoint.h>
7 #include <minix/sysutil.h>
8 #include <minix/sys_config.h>
9 #include "../../kernel/const.h"
10 #include "../../kernel/config.h"
11 #include "../../kernel/debug.h"
12 #include "../../kernel/type.h"
13 #include "../../kernel/proc.h"
14 #include "../../kernel/ipc.h"
16 #define LINES 22
18 #define PRINTRTS(rp) { \
19 char *procname = ""; \
20 printf(" %s", p_rts_flags_str(rp->p_rts_flags)); \
21 if (rp->p_rts_flags & RTS_SENDING) \
22 procname = proc_name(_ENDPOINT_P(rp->p_sendto_e)); \
23 else if (rp->p_rts_flags & RTS_RECEIVING) \
24 procname = proc_name(_ENDPOINT_P(rp->p_getfrom_e)); \
25 printf(" %-7.7s", procname); \
28 static int pagelines;
30 #define PROCLOOP(rp, oldrp) \
31 pagelines = 0; \
32 for (rp = oldrp; rp < END_PROC_ADDR; rp++) { \
33 oldrp = BEG_PROC_ADDR; \
34 if (isemptyp(rp)) continue; \
35 if (++pagelines > LINES) { oldrp = rp; printf("--more--\n"); break; }\
36 if (proc_nr(rp) == IDLE) printf("(%2d) ", proc_nr(rp)); \
37 else if (proc_nr(rp) < 0) printf("[%2d] ", proc_nr(rp)); \
38 else printf(" %2d ", proc_nr(rp));
40 #define click_to_round_k(n) \
41 ((unsigned) ((((unsigned long) (n) << CLICK_SHIFT) + 512) / 1024))
43 /* Declare some local dump procedures. */
44 FORWARD _PROTOTYPE( char *proc_name, (int proc_nr) );
45 FORWARD _PROTOTYPE( char *s_traps_str, (int flags) );
46 FORWARD _PROTOTYPE( char *s_flags_str, (int flags) );
47 FORWARD _PROTOTYPE( char *p_rts_flags_str, (int flags) );
48 FORWARD _PROTOTYPE( char *boot_flags_str, (int flags) );
50 /* Some global data that is shared among several dumping procedures.
51 * Note that the process table copy has the same name as in the kernel
52 * so that most macros and definitions from proc.h also apply here.
54 PUBLIC struct proc proc[NR_TASKS + NR_PROCS];
55 PUBLIC struct priv priv[NR_SYS_PROCS];
56 PUBLIC struct boot_image image[NR_BOOT_PROCS];
58 /*===========================================================================*
59 * timing_dmp *
60 *===========================================================================*/
61 PUBLIC void timing_dmp()
63 static struct util_timingdata timingdata[TIMING_CATEGORIES];
64 int r, c, f, skipped = 0, printed = 0, maxlines = 23, x = 0;
65 static int offsetlines = 0;
67 if ((r = sys_getlocktimings(&timingdata[0])) != OK) {
68 report("IS","warning: couldn't get copy of lock timings", r);
69 return;
72 for(c = 0; c < TIMING_CATEGORIES; c++) {
73 int b;
74 if (!timingdata[c].lock_timings_range[0] || !timingdata[c].binsize)
75 continue;
76 x = printf("%-*s: misses %lu, resets %lu, measurements %lu: ",
77 TIMING_NAME, timingdata[c].names,
78 timingdata[c].misses,
79 timingdata[c].resets,
80 timingdata[c].measurements);
81 for(b = 0; b < TIMING_POINTS; b++) {
82 int w;
83 if (!timingdata[c].lock_timings[b])
84 continue;
85 x += (w = printf(" %5d: %5d", timingdata[c].lock_timings_range[0] +
86 b*timingdata[c].binsize,
87 timingdata[c].lock_timings[b]));
88 if (x + w >= 80) { printf("\n"); x = 0; }
90 if (x > 0) printf("\n");
94 /*===========================================================================*
95 * kmessages_dmp *
96 *===========================================================================*/
97 PUBLIC void kmessages_dmp()
99 struct kmessages kmess; /* get copy of kernel messages */
100 char print_buf[_KMESS_BUF_SIZE+1]; /* this one is used to print */
101 int start; /* calculate start of messages */
102 int r;
104 /* Try to get a copy of the kernel messages. */
105 if ((r = sys_getkmessages(&kmess)) != OK) {
106 report("IS","warning: couldn't get copy of kmessages", r);
107 return;
110 /* Try to print the kernel messages. First determine start and copy the
111 * buffer into a print-buffer. This is done because the messages in the
112 * copy may wrap (the kernel buffer is circular).
114 start = ((kmess.km_next + _KMESS_BUF_SIZE) - kmess.km_size) % _KMESS_BUF_SIZE;
115 r = 0;
116 while (kmess.km_size > 0) {
117 print_buf[r] = kmess.km_buf[(start+r) % _KMESS_BUF_SIZE];
118 r ++;
119 kmess.km_size --;
121 print_buf[r] = 0; /* make sure it terminates */
122 printf("Dump of all messages generated by the kernel.\n\n");
123 printf("%s", print_buf); /* print the messages */
126 /*===========================================================================*
127 * monparams_dmp *
128 *===========================================================================*/
129 PUBLIC void monparams_dmp()
131 char val[1024];
132 char *e;
133 int r;
135 /* Try to get a copy of the boot monitor parameters. */
136 if ((r = sys_getmonparams(val, sizeof(val))) != OK) {
137 report("IS","warning: couldn't get copy of monitor params", r);
138 return;
141 /* Append new lines to the result. */
142 e = val;
143 do {
144 e += strlen(e);
145 *e++ = '\n';
146 } while (*e != 0);
148 /* Finally, print the result. */
149 printf("Dump of kernel environment strings set by boot monitor.\n");
150 printf("\n%s\n", val);
153 /*===========================================================================*
154 * irqtab_dmp *
155 *===========================================================================*/
156 PUBLIC void irqtab_dmp()
158 int i,r;
159 struct irq_hook irq_hooks[NR_IRQ_HOOKS];
160 int irq_actids[NR_IRQ_VECTORS];
161 struct irq_hook *e; /* irq tab entry */
163 if ((r = sys_getirqhooks(irq_hooks)) != OK) {
164 report("IS","warning: couldn't get copy of irq hooks", r);
165 return;
167 if ((r = sys_getirqactids(irq_actids)) != OK) {
168 report("IS","warning: couldn't get copy of irq mask", r);
169 return;
172 #if 0
173 printf("irq_actids:");
174 for (i= 0; i<NR_IRQ_VECTORS; i++)
175 printf(" [%d] = 0x%08x", i, irq_actids[i]);
176 printf("\n");
177 #endif
179 printf("IRQ policies dump shows use of kernel's IRQ hooks.\n");
180 printf("-h.id- -proc.nr- -irq nr- -policy- -notify id-\n");
181 for (i=0; i<NR_IRQ_HOOKS; i++) {
182 e = &irq_hooks[i];
183 printf("%3d", i);
184 if (e->proc_nr_e==NONE) {
185 printf(" <unused>\n");
186 continue;
188 printf("%10d ", e->proc_nr_e);
189 printf(" (%02d) ", e->irq);
190 printf(" %s", (e->policy & IRQ_REENABLE) ? "reenable" : " - ");
191 printf(" %d", e->notify_id);
192 if (irq_actids[e->irq] & (1 << i))
193 printf("masked");
194 printf("\n");
196 printf("\n");
199 /*===========================================================================*
200 * boot_flags_str *
201 *===========================================================================*/
202 PRIVATE char *boot_flags_str(int flags)
204 static char str[10];
205 str[0] = (flags & PROC_FULLVM) ? 'V' : '-';
206 str[1] = '\0';
208 return str;
211 /*===========================================================================*
212 * image_dmp *
213 *===========================================================================*/
214 PUBLIC void image_dmp()
216 int m, i,j,r;
217 struct boot_image *ip;
219 if ((r = sys_getimage(image)) != OK) {
220 report("IS","warning: couldn't get copy of image table", r);
221 return;
223 printf("Image table dump showing all processes included in system image.\n");
224 printf("---name- -nr- ----pc- flags -qs- -queue- -stack-\n");
225 for (m=0; m<NR_BOOT_PROCS; m++) {
226 ip = &image[m];
227 printf("%8s %4d %7lu %5s %4d %7d %7lu\n",
228 ip->proc_name, ip->proc_nr, (long)ip->initial_pc,
229 boot_flags_str(ip->flags), ip->quantum, ip->priority, ip->stksize);
231 printf("\n");
235 /*===========================================================================*
236 * kenv_dmp *
237 *===========================================================================*/
238 PUBLIC void kenv_dmp()
240 struct kinfo kinfo;
241 struct machine machine;
242 int r;
243 if ((r = sys_getkinfo(&kinfo)) != OK) {
244 report("IS","warning: couldn't get copy of kernel info struct", r);
245 return;
247 if ((r = sys_getmachine(&machine)) != OK) {
248 report("IS","warning: couldn't get copy of kernel machine struct", r);
249 return;
252 printf("Dump of kinfo and machine structures.\n\n");
253 printf("Machine structure:\n");
254 printf("- pc_at: %3d\n", machine.pc_at);
255 printf("- ps_mca: %3d\n", machine.ps_mca);
256 printf("- processor: %3d\n", machine.processor);
257 printf("- vdu_ega: %3d\n", machine.vdu_ega);
258 printf("- vdu_vga: %3d\n\n", machine.vdu_vga);
259 printf("Kernel info structure:\n");
260 printf("- code_base: %5u\n", kinfo.code_base);
261 printf("- code_size: %5u\n", kinfo.code_size);
262 printf("- data_base: %5u\n", kinfo.data_base);
263 printf("- data_size: %5u\n", kinfo.data_size);
264 printf("- proc_addr: %5u\n", kinfo.proc_addr);
265 printf("- bootdev_base: %5u\n", kinfo.bootdev_base);
266 printf("- bootdev_size: %5u\n", kinfo.bootdev_size);
267 printf("- ramdev_base: %5u\n", kinfo.ramdev_base);
268 printf("- ramdev_size: %5u\n", kinfo.ramdev_size);
269 printf("- nr_procs: %3u\n", kinfo.nr_procs);
270 printf("- nr_tasks: %3u\n", kinfo.nr_tasks);
271 printf("- release: %.6s\n", kinfo.release);
272 printf("- version: %.6s\n", kinfo.version);
273 printf("\n");
276 /*===========================================================================*
277 * s_flags_str *
278 *===========================================================================*/
279 PRIVATE char *s_flags_str(int flags)
281 static char str[10];
282 str[0] = (flags & PREEMPTIBLE) ? 'P' : '-';
283 str[1] = (flags & BILLABLE) ? 'B' : '-';
284 str[2] = (flags & DYN_PRIV_ID) ? 'D' : '-';
285 str[3] = (flags & SYS_PROC) ? 'S' : '-';
286 str[4] = (flags & CHECK_IO_PORT) ? 'I' : '-';
287 str[5] = (flags & CHECK_IRQ) ? 'Q' : '-';
288 str[6] = (flags & CHECK_MEM) ? 'M' : '-';
289 str[7] = '\0';
291 return str;
294 /*===========================================================================*
295 * s_traps_str *
296 *===========================================================================*/
297 PRIVATE char *s_traps_str(int flags)
299 static char str[10];
300 str[0] = (flags & (1 << SEND)) ? 'S' : '-';
301 str[1] = (flags & (1 << SENDA)) ? 'A' : '-';
302 str[2] = (flags & (1 << RECEIVE)) ? 'R' : '-';
303 str[3] = (flags & (1 << SENDREC)) ? 'B' : '-';
304 str[4] = (flags & (1 << NOTIFY)) ? 'N' : '-';
305 str[5] = '\0';
307 return str;
310 /*===========================================================================*
311 * privileges_dmp *
312 *===========================================================================*/
313 PUBLIC void privileges_dmp()
315 register struct proc *rp;
316 static struct proc *oldrp = BEG_PROC_ADDR;
317 register struct priv *sp;
318 int r, i, n = 0;
320 /* First obtain a fresh copy of the current process and system table. */
321 if ((r = sys_getprivtab(priv)) != OK) {
322 report("IS","warning: couldn't get copy of system privileges table", r);
323 return;
325 if ((r = sys_getproctab(proc)) != OK) {
326 report("IS","warning: couldn't get copy of process table", r);
327 return;
330 printf("-nr- -id- -name-- -flags- traps grants -ipc_to-- -kernel calls-\n");
332 PROCLOOP(rp, oldrp)
333 r = -1;
334 for (sp = &priv[0]; sp < &priv[NR_SYS_PROCS]; sp++)
335 if (sp->s_proc_nr == rp->p_nr) { r ++; break; }
336 if (r == -1 && !isemptyp(rp)) {
337 sp = &priv[USER_PRIV_ID];
339 printf("(%02u) %-7.7s %s %s %7d",
340 sp->s_id, rp->p_name,
341 s_flags_str(sp->s_flags), s_traps_str(sp->s_trap_mask),
342 sp->s_grant_entries);
343 for (i=0; i < NR_SYS_PROCS; i += BITCHUNK_BITS) {
344 printf(" %04x", get_sys_bits(sp->s_ipc_to, i));
347 printf(" ");
348 for (i=0; i < NR_SYS_CALLS; i += BITCHUNK_BITS) {
349 printf(" %04x", sp->s_k_call_mask[i/BITCHUNK_BITS]);
351 printf("\n");
356 /*===========================================================================*
357 * p_rts_flags_str *
358 *===========================================================================*/
359 PRIVATE char *p_rts_flags_str(int flags)
361 static char str[10];
362 str[0] = (flags & RTS_PROC_STOP) ? 's' : '-';
363 str[1] = (flags & RTS_SENDING) ? 'S' : '-';
364 str[2] = (flags & RTS_RECEIVING) ? 'R' : '-';
365 str[3] = (flags & RTS_SIGNALED) ? 'I' : '-';
366 str[4] = (flags & RTS_SIG_PENDING) ? 'P' : '-';
367 str[5] = (flags & RTS_P_STOP) ? 'T' : '-';
368 str[6] = (flags & RTS_NO_PRIV) ? 'p' : '-';
369 str[7] = '\0';
371 return str;
374 /*===========================================================================*
375 * proctab_dmp *
376 *===========================================================================*/
377 #if (CHIP == INTEL)
378 PUBLIC void proctab_dmp()
380 /* Proc table dump */
382 register struct proc *rp;
383 static struct proc *oldrp = BEG_PROC_ADDR;
384 int r, n = 0;
385 phys_clicks text, data, size;
387 /* First obtain a fresh copy of the current process table. */
388 if ((r = sys_getproctab(proc)) != OK) {
389 report("IS","warning: couldn't get copy of process table", r);
390 return;
393 printf("\n-nr-----gen---endpoint-name--- -prior-quant- -user----sys-rtsflags-from/to-\n");
395 PROCLOOP(rp, oldrp)
396 text = rp->p_memmap[T].mem_phys;
397 data = rp->p_memmap[D].mem_phys;
398 size = rp->p_memmap[T].mem_len
399 + ((rp->p_memmap[S].mem_phys + rp->p_memmap[S].mem_len) - data);
400 printf(" %5d %10d ", _ENDPOINT_G(rp->p_endpoint), rp->p_endpoint);
401 printf("%-8.8s %02u/%02u %02d/%02u %6lu %6lu ",
402 rp->p_name,
403 rp->p_priority, rp->p_max_priority,
404 rp->p_ticks_left, rp->p_quantum_size,
405 rp->p_user_time, rp->p_sys_time);
406 PRINTRTS(rp);
407 printf("\n");
410 #endif /* (CHIP == INTEL) */
412 /*===========================================================================*
413 * procstack_dmp *
414 *===========================================================================*/
415 PUBLIC void procstack_dmp()
417 /* Proc table dump, with stack */
419 register struct proc *rp;
420 static struct proc *oldrp = BEG_PROC_ADDR;
421 int r, n = 0;
423 /* First obtain a fresh copy of the current process table. */
424 if ((r = sys_getproctab(proc)) != OK) {
425 report("IS","warning: couldn't get copy of process table", r);
426 return;
429 printf("\n-nr-rts flags-- --stack--\n");
431 PROCLOOP(rp, oldrp)
432 PRINTRTS(rp);
433 sys_sysctl_stacktrace(rp->p_endpoint);
437 /*===========================================================================*
438 * memmap_dmp *
439 *===========================================================================*/
440 PUBLIC void memmap_dmp()
442 register struct proc *rp;
443 static struct proc *oldrp = proc;
444 int r, n = 0;
445 phys_clicks size;
447 /* First obtain a fresh copy of the current process table. */
448 if ((r = sys_getproctab(proc)) != OK) {
449 report("IS","warning: couldn't get copy of process table", r);
450 return;
453 printf("\n-nr/name--- --pc-- --sp-- -text---- -data---- -stack--- -cr3-\n");
454 PROCLOOP(rp, oldrp)
455 size = rp->p_memmap[T].mem_len
456 + ((rp->p_memmap[S].mem_phys + rp->p_memmap[S].mem_len)
457 - rp->p_memmap[D].mem_phys);
458 printf("%-7.7s%7lx %8lx %4x %4x %4x %4x %5x %5x %8lx\n",
459 rp->p_name,
460 (unsigned long) rp->p_reg.pc,
461 (unsigned long) rp->p_reg.sp,
462 rp->p_memmap[T].mem_phys, rp->p_memmap[T].mem_len,
463 rp->p_memmap[D].mem_phys, rp->p_memmap[D].mem_len,
464 rp->p_memmap[S].mem_phys, rp->p_memmap[S].mem_len,
465 rp->p_seg.p_cr3);
469 /*===========================================================================*
470 * proc_name *
471 *===========================================================================*/
472 PRIVATE char *proc_name(proc_nr)
473 int proc_nr;
475 struct proc *p;
476 if (proc_nr == ANY) return "ANY";
477 if (proc_nr == NONE) return "NONE"; /* bogus */
478 if (proc_nr < -NR_TASKS || proc_nr >= NR_PROCS) return "BOGUS";
479 p = cproc_addr(proc_nr);
480 if (isemptyp(p)) return "EMPTY"; /* bogus */
481 return p->p_name;