source: trunk/minix/servers/is/dmp_kernel.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

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