add/re-enable at_wini debug output
[minix3.git] / servers / is / dmp_kernel.c
blob2ac0f3dafe2bc62f56d69625010cc54368dc19bb
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/sys_config.h>
8 #include "../../kernel/const.h"
9 #include "../../kernel/config.h"
10 #include "../../kernel/debug.h"
11 #include "../../kernel/type.h"
12 #include "../../kernel/proc.h"
13 #include "../../kernel/ipc.h"
15 #define click_to_round_k(n) \
16 ((unsigned) ((((unsigned long) (n) << CLICK_SHIFT) + 512) / 1024))
18 /* Declare some local dump procedures. */
19 FORWARD _PROTOTYPE( char *proc_name, (int proc_nr) );
20 FORWARD _PROTOTYPE( char *s_traps_str, (int flags) );
21 FORWARD _PROTOTYPE( char *s_flags_str, (int flags) );
22 FORWARD _PROTOTYPE( char *p_rts_flags_str, (int flags) );
24 /* Some global data that is shared among several dumping procedures.
25 * Note that the process table copy has the same name as in the kernel
26 * so that most macros and definitions from proc.h also apply here.
28 PUBLIC struct proc proc[NR_TASKS + NR_PROCS];
29 PUBLIC struct priv priv[NR_SYS_PROCS];
30 PUBLIC struct boot_image image[NR_BOOT_PROCS];
32 /*===========================================================================*
33 * timing_dmp *
34 *===========================================================================*/
35 PUBLIC void timing_dmp()
37 #if ! DEBUG_TIME_LOCKS
38 printf("Enable the DEBUG_TIME_LOCKS definition in src/kernel/config.h\n");
39 #else
40 static struct lock_timingdata timingdata[TIMING_CATEGORIES];
41 int r, c, f, skipped = 0, printed = 0, maxlines = 23, x = 0;
42 static int offsetlines = 0;
44 if ((r = sys_getlocktimings(&timingdata[0])) != OK) {
45 report("IS","warning: couldn't get copy of lock timings", r);
46 return;
49 for(c = 0; c < TIMING_CATEGORIES; c++) {
50 int b;
51 if (!timingdata[c].lock_timings_range[0] || !timingdata[c].binsize)
52 continue;
53 x = printf("%-*s: misses %lu, resets %lu, measurements %lu: ",
54 TIMING_NAME, timingdata[c].names,
55 timingdata[c].misses,
56 timingdata[c].resets,
57 timingdata[c].measurements);
58 for(b = 0; b < TIMING_POINTS; b++) {
59 int w;
60 if (!timingdata[c].lock_timings[b])
61 continue;
62 x += (w = printf(" %5d: %5d", timingdata[c].lock_timings_range[0] +
63 b*timingdata[c].binsize,
64 timingdata[c].lock_timings[b]));
65 if (x + w >= 80) { printf("\n"); x = 0; }
67 if (x > 0) printf("\n");
69 #endif
72 /*===========================================================================*
73 * kmessages_dmp *
74 *===========================================================================*/
75 PUBLIC void kmessages_dmp()
77 struct kmessages kmess; /* get copy of kernel messages */
78 char print_buf[KMESS_BUF_SIZE+1]; /* this one is used to print */
79 int start; /* calculate start of messages */
80 int r;
82 /* Try to get a copy of the kernel messages. */
83 if ((r = sys_getkmessages(&kmess)) != OK) {
84 report("IS","warning: couldn't get copy of kmessages", r);
85 return;
88 /* Try to print the kernel messages. First determine start and copy the
89 * buffer into a print-buffer. This is done because the messages in the
90 * copy may wrap (the kernel buffer is circular).
92 start = ((kmess.km_next + KMESS_BUF_SIZE) - kmess.km_size) % KMESS_BUF_SIZE;
93 r = 0;
94 while (kmess.km_size > 0) {
95 print_buf[r] = kmess.km_buf[(start+r) % KMESS_BUF_SIZE];
96 r ++;
97 kmess.km_size --;
99 print_buf[r] = 0; /* make sure it terminates */
100 printf("Dump of all messages generated by the kernel.\n\n");
101 printf("%s", print_buf); /* print the messages */
104 /*===========================================================================*
105 * monparams_dmp *
106 *===========================================================================*/
107 PUBLIC void monparams_dmp()
109 char val[1024];
110 char *e;
111 int r;
113 /* Try to get a copy of the boot monitor parameters. */
114 if ((r = sys_getmonparams(val, sizeof(val))) != OK) {
115 report("IS","warning: couldn't get copy of monitor params", r);
116 return;
119 /* Append new lines to the result. */
120 e = val;
121 do {
122 e += strlen(e);
123 *e++ = '\n';
124 } while (*e != 0);
126 /* Finally, print the result. */
127 printf("Dump of kernel environment strings set by boot monitor.\n");
128 printf("\n%s\n", val);
131 /*===========================================================================*
132 * irqtab_dmp *
133 *===========================================================================*/
134 PUBLIC void irqtab_dmp()
136 int i,r;
137 struct irq_hook irq_hooks[NR_IRQ_HOOKS];
138 int irq_actids[NR_IRQ_VECTORS];
139 struct irq_hook *e; /* irq tab entry */
141 if ((r = sys_getirqhooks(irq_hooks)) != OK) {
142 report("IS","warning: couldn't get copy of irq hooks", r);
143 return;
145 if ((r = sys_getirqactids(irq_actids)) != OK) {
146 report("IS","warning: couldn't get copy of irq mask", r);
147 return;
150 #if 0
151 printf("irq_actids:");
152 for (i= 0; i<NR_IRQ_VECTORS; i++)
153 printf(" [%d] = 0x%08x", i, irq_actids[i]);
154 printf("\n");
155 #endif
157 printf("IRQ policies dump shows use of kernel's IRQ hooks.\n");
158 printf("-h.id- -proc.nr- -irq nr- -policy- -notify id-\n");
159 for (i=0; i<NR_IRQ_HOOKS; i++) {
160 e = &irq_hooks[i];
161 printf("%3d", i);
162 if (e->proc_nr_e==NONE) {
163 printf(" <unused>\n");
164 continue;
166 printf("%10d ", e->proc_nr_e);
167 printf(" (%02d) ", e->irq);
168 printf(" %s", (e->policy & IRQ_REENABLE) ? "reenable" : " - ");
169 printf(" %d", e->notify_id);
170 if (irq_actids[e->irq] & (1 << i))
171 printf("masked");
172 printf("\n");
174 printf("\n");
177 /*===========================================================================*
178 * image_dmp *
179 *===========================================================================*/
180 PUBLIC void image_dmp()
182 int m, i,j,r;
183 struct boot_image *ip;
184 static char ipc_to[BITCHUNK_BITS*2];
186 if ((r = sys_getimage(image)) != OK) {
187 report("IS","warning: couldn't get copy of image table", r);
188 return;
190 printf("Image table dump showing all processes included in system image.\n");
191 printf("---name-- -nr- -flags- -traps- -sq- ----pc- -stack- -ipc_to[0]--------\n");
192 for (m=0; m<NR_BOOT_PROCS; m++) {
193 ip = &image[m];
194 for (i=j=0; i < BITCHUNK_BITS; i++, j++) {
195 ipc_to[j] = (ip->ipc_to & (1<<i)) ? '1' : '0';
196 if (i % 8 == 7) ipc_to[++j] = ' ';
198 ipc_to[j] = '\0';
199 printf("%8s %4d %s %s %3d %7lu %7lu %s\n",
200 ip->proc_name, ip->proc_nr,
201 s_flags_str(ip->flags), s_traps_str(ip->trap_mask),
202 ip->priority, (long)ip->initial_pc, ip->stksize, ipc_to);
204 printf("\n");
207 /*===========================================================================*
208 * sched_dmp *
209 *===========================================================================*/
210 PUBLIC void sched_dmp()
212 struct proc *rdy_head[NR_SCHED_QUEUES];
213 struct kinfo kinfo;
214 register struct proc *rp;
215 vir_bytes ptr_diff;
216 int r;
218 /* First obtain a scheduling information. */
219 if ((r = sys_getschedinfo(proc, rdy_head)) != OK) {
220 report("IS","warning: couldn't get copy of process table", r);
221 return;
223 /* Then obtain kernel addresses to correct pointer information. */
224 if ((r = sys_getkinfo(&kinfo)) != OK) {
225 report("IS","warning: couldn't get kernel addresses", r);
226 return;
229 /* Update all pointers. Nasty pointer algorithmic ... */
230 ptr_diff = (vir_bytes) proc - (vir_bytes) kinfo.proc_addr;
231 for (r=0;r<NR_SCHED_QUEUES; r++)
232 if (rdy_head[r] != NIL_PROC)
233 rdy_head[r] =
234 (struct proc *)((vir_bytes) rdy_head[r] + ptr_diff);
235 for (rp=BEG_PROC_ADDR; rp < END_PROC_ADDR; rp++)
236 if (rp->p_nextready != NIL_PROC)
237 rp->p_nextready =
238 (struct proc *)((vir_bytes) rp->p_nextready + ptr_diff);
240 /* Now show scheduling queues. */
241 printf("Dumping scheduling queues.\n");
243 for (r=0;r<NR_SCHED_QUEUES; r++) {
244 rp = rdy_head[r];
245 if (!rp) continue;
246 printf("%2d: ", r);
247 while (rp != NIL_PROC) {
248 printf("%3d ", rp->p_nr);
249 rp = rp->p_nextready;
251 printf("\n");
253 printf("\n");
256 /*===========================================================================*
257 * kenv_dmp *
258 *===========================================================================*/
259 PUBLIC void kenv_dmp()
261 struct kinfo kinfo;
262 struct machine machine;
263 int r;
264 if ((r = sys_getkinfo(&kinfo)) != OK) {
265 report("IS","warning: couldn't get copy of kernel info struct", r);
266 return;
268 if ((r = sys_getmachine(&machine)) != OK) {
269 report("IS","warning: couldn't get copy of kernel machine struct", r);
270 return;
273 printf("Dump of kinfo and machine structures.\n\n");
274 printf("Machine structure:\n");
275 printf("- pc_at: %3d\n", machine.pc_at);
276 printf("- ps_mca: %3d\n", machine.ps_mca);
277 printf("- processor: %3d\n", machine.processor);
278 printf("- vdu_ega: %3d\n", machine.vdu_ega);
279 printf("- vdu_vga: %3d\n\n", machine.vdu_vga);
280 printf("Kernel info structure:\n");
281 printf("- code_base: %5u\n", kinfo.code_base);
282 printf("- code_size: %5u\n", kinfo.code_size);
283 printf("- data_base: %5u\n", kinfo.data_base);
284 printf("- data_size: %5u\n", kinfo.data_size);
285 printf("- proc_addr: %5u\n", kinfo.proc_addr);
286 printf("- kmem_base: %5u\n", kinfo.kmem_base);
287 printf("- kmem_size: %5u\n", kinfo.kmem_size);
288 printf("- bootdev_base: %5u\n", kinfo.bootdev_base);
289 printf("- bootdev_size: %5u\n", kinfo.bootdev_size);
290 printf("- ramdev_base: %5u\n", kinfo.ramdev_base);
291 printf("- ramdev_size: %5u\n", kinfo.ramdev_size);
292 printf("- params_base: %5u\n", kinfo.params_base);
293 printf("- params_size: %5u\n", kinfo.params_size);
294 printf("- nr_procs: %3u\n", kinfo.nr_procs);
295 printf("- nr_tasks: %3u\n", kinfo.nr_tasks);
296 printf("- release: %.6s\n", kinfo.release);
297 printf("- version: %.6s\n", kinfo.version);
298 #if DEBUG_LOCK_CHECK
299 printf("- relocking: %d\n", kinfo.relocking);
300 #endif
301 printf("\n");
304 PRIVATE char *s_flags_str(int flags)
306 static char str[10];
307 str[0] = (flags & PREEMPTIBLE) ? 'P' : '-';
308 str[1] = '-';
309 str[2] = (flags & BILLABLE) ? 'B' : '-';
310 str[3] = (flags & SYS_PROC) ? 'S' : '-';
311 str[4] = '-';
312 str[5] = '\0';
314 return str;
317 PRIVATE char *s_traps_str(int flags)
319 static char str[10];
320 str[0] = (flags & (1 << ECHO)) ? 'E' : '-';
321 str[1] = (flags & (1 << SEND)) ? 'S' : '-';
322 str[2] = (flags & (1 << RECEIVE)) ? 'R' : '-';
323 str[3] = (flags & (1 << SENDREC)) ? 'B' : '-';
324 str[4] = (flags & (1 << NOTIFY)) ? 'N' : '-';
325 str[5] = '\0';
327 return str;
330 /*===========================================================================*
331 * privileges_dmp *
332 *===========================================================================*/
333 PUBLIC void privileges_dmp()
335 register struct proc *rp;
336 static struct proc *oldrp = BEG_PROC_ADDR;
337 register struct priv *sp;
338 int r, i, n = 0;
340 /* First obtain a fresh copy of the current process and system table. */
341 if ((r = sys_getprivtab(priv)) != OK) {
342 report("IS","warning: couldn't get copy of system privileges table", r);
343 return;
345 if ((r = sys_getproctab(proc)) != OK) {
346 report("IS","warning: couldn't get copy of process table", r);
347 return;
350 printf("\n--nr-id-name---- -flags- -traps- grants -ipc_to-- -system calls--\n");
352 for (rp = oldrp; rp < END_PROC_ADDR; rp++) {
353 if (isemptyp(rp)) continue;
354 if (++n > 23) break;
355 if (proc_nr(rp) == IDLE) printf("(%2d) ", proc_nr(rp));
356 else if (proc_nr(rp) < 0) printf("[%2d] ", proc_nr(rp));
357 else printf(" %2d ", proc_nr(rp));
358 r = -1;
359 for (sp = &priv[0]; sp < &priv[NR_SYS_PROCS]; sp++)
360 if (sp->s_proc_nr == rp->p_nr) { r ++; break; }
361 if (r == -1 && ! (rp->p_rts_flags & SLOT_FREE)) {
362 sp = &priv[USER_PRIV_ID];
364 printf("(%02u) %-7.7s %s %s %7d",
365 sp->s_id, rp->p_name,
366 s_flags_str(sp->s_flags), s_traps_str(sp->s_trap_mask),
367 sp->s_grant_entries);
368 for (i=0; i < NR_SYS_PROCS; i += BITCHUNK_BITS) {
369 printf(" %04x", get_sys_bits(sp->s_ipc_to, i));
372 printf(" ");
373 for (i=0; i < NR_SYS_CALLS; i += BITCHUNK_BITS) {
374 printf(" %04x", sp->s_k_call_mask[i/BITCHUNK_BITS]);
376 printf("\n");
379 if (rp == END_PROC_ADDR) rp = BEG_PROC_ADDR; else printf("--more--\r");
380 oldrp = rp;
384 /*===========================================================================*
385 * sendmask_dmp *
386 *===========================================================================*/
387 PUBLIC void sendmask_dmp()
389 register struct proc *rp;
390 static struct proc *oldrp = BEG_PROC_ADDR;
391 int r, i,j, n = 0;
393 /* First obtain a fresh copy of the current process table. */
394 if ((r = sys_getproctab(proc)) != OK) {
395 report("IS","warning: couldn't get copy of process table", r);
396 return;
399 printf("\n\n");
400 printf("Sendmask dump for process table. User processes (*) don't have [].");
401 printf("\n");
402 printf("The rows of bits indicate to which processes each process may send.");
403 printf("\n\n");
405 #if DEAD_CODE
406 printf(" ");
407 for (j=proc_nr(BEG_PROC_ADDR); j< INIT_PROC_NR+1; j++) {
408 printf("%3d", j);
410 printf(" *\n");
412 for (rp = oldrp; rp < END_PROC_ADDR; rp++) {
413 if (isemptyp(rp)) continue;
414 if (++n > 20) break;
416 printf("%8s ", rp->p_name);
417 if (proc_nr(rp) == IDLE) printf("(%2d) ", proc_nr(rp));
418 else if (proc_nr(rp) < 0) printf("[%2d] ", proc_nr(rp));
419 else printf(" %2d ", proc_nr(rp));
421 for (j=proc_nr(BEG_PROC_ADDR); j<INIT_PROC_NR+2; j++) {
422 if (isallowed(rp->p_sendmask, j)) printf(" 1 ");
423 else printf(" 0 ");
425 printf("\n");
427 if (rp == END_PROC_ADDR) { printf("\n"); rp = BEG_PROC_ADDR; }
428 else printf("--more--\r");
429 oldrp = rp;
430 #endif
433 PRIVATE char *p_rts_flags_str(int flags)
435 static char str[10];
436 str[0] = (flags & NO_PRIORITY) ? 's' : '-';
437 str[1] = (flags & SENDING) ? 'S' : '-';
438 str[2] = (flags & RECEIVING) ? 'R' : '-';
439 str[3] = (flags & SIGNALED) ? 'I' : '-';
440 str[4] = (flags & SIG_PENDING) ? 'P' : '-';
441 str[5] = (flags & P_STOP) ? 'T' : '-';
442 str[6] = (flags & NO_PRIV) ? 'p' : '-';
443 str[7] = '\0';
445 return str;
448 /*===========================================================================*
449 * proctab_dmp *
450 *===========================================================================*/
451 #if (CHIP == INTEL)
452 PUBLIC void proctab_dmp()
454 /* Proc table dump */
456 register struct proc *rp;
457 static struct proc *oldrp = BEG_PROC_ADDR;
458 int r, n = 0;
459 phys_clicks text, data, size;
461 /* First obtain a fresh copy of the current process table. */
462 if ((r = sys_getproctab(proc)) != OK) {
463 report("IS","warning: couldn't get copy of process table", r);
464 return;
467 printf("\n-nr-----gen---endpoint-name--- -prior-quant- -user----sys----size-rts flags\n");
469 for (rp = oldrp; rp < END_PROC_ADDR; rp++) {
470 if (isemptyp(rp)) continue;
471 if (++n > 23) break;
472 text = rp->p_memmap[T].mem_phys;
473 data = rp->p_memmap[D].mem_phys;
474 size = rp->p_memmap[T].mem_len
475 + ((rp->p_memmap[S].mem_phys + rp->p_memmap[S].mem_len) - data);
476 if (proc_nr(rp) == IDLE) printf("(%2d) ", proc_nr(rp));
477 else if (proc_nr(rp) < 0) printf("[%2d] ", proc_nr(rp));
478 else printf(" %2d ", proc_nr(rp));
479 printf(" %5d %10d ", _ENDPOINT_G(rp->p_endpoint), rp->p_endpoint);
480 printf("%-8.8s %02u/%02u %02d/%02u %6lu %6lu %5uK %s",
481 rp->p_name,
482 rp->p_priority, rp->p_max_priority,
483 rp->p_ticks_left, rp->p_quantum_size,
484 rp->p_user_time, rp->p_sys_time,
485 click_to_round_k(size),
486 p_rts_flags_str(rp->p_rts_flags));
487 if (rp->p_rts_flags & (SENDING|RECEIVING)) {
488 printf(" %-7.7s", proc_name(_ENDPOINT_P(rp->p_getfrom_e)));
490 printf("\n");
492 if (rp == END_PROC_ADDR) rp = BEG_PROC_ADDR; else printf("--more--\r");
493 oldrp = rp;
495 #endif /* (CHIP == INTEL) */
497 /*===========================================================================*
498 * memmap_dmp *
499 *===========================================================================*/
500 PUBLIC void memmap_dmp()
502 register struct proc *rp;
503 static struct proc *oldrp = proc;
504 int r, n = 0;
505 phys_clicks size;
507 /* First obtain a fresh copy of the current process table. */
508 if ((r = sys_getproctab(proc)) != OK) {
509 report("IS","warning: couldn't get copy of process table", r);
510 return;
513 printf("\n-nr/name--- --pc-- --sp-- -----text----- -----data----- ----stack----- --size-\n");
514 for (rp = oldrp; rp < END_PROC_ADDR; rp++) {
515 if (isemptyp(rp)) continue;
516 if (++n > 23) break;
517 size = rp->p_memmap[T].mem_len
518 + ((rp->p_memmap[S].mem_phys + rp->p_memmap[S].mem_len)
519 - rp->p_memmap[D].mem_phys);
520 printf("%3d %-7.7s%7lx%7lx %4x %4x %4x %4x %4x %4x %4x %4x %4x %5uK\n",
521 proc_nr(rp),
522 rp->p_name,
523 (unsigned long) rp->p_reg.pc,
524 (unsigned long) rp->p_reg.sp,
525 rp->p_memmap[T].mem_vir, rp->p_memmap[T].mem_phys, rp->p_memmap[T].mem_len,
526 rp->p_memmap[D].mem_vir, rp->p_memmap[D].mem_phys, rp->p_memmap[D].mem_len,
527 rp->p_memmap[S].mem_vir, rp->p_memmap[S].mem_phys, rp->p_memmap[S].mem_len,
528 click_to_round_k(size));
530 if (rp == END_PROC_ADDR) rp = proc;
531 else printf("--more--\r");
532 oldrp = rp;
535 /*===========================================================================*
536 * proc_name *
537 *===========================================================================*/
538 PRIVATE char *proc_name(proc_nr)
539 int proc_nr;
541 if (proc_nr == ANY) return "ANY";
542 return cproc_addr(proc_nr)->p_name;