make includes fix from trunk
[minix.git] / servers / is / dmp_kernel.c
blob962f650aec64495a5eb6dc822e864f13bc5fa24f
1 /* Debugging dump procedures for the kernel. */
3 #include "inc.h"
4 #include <timers.h>
5 #include <machine/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, x = 0;
66 if ((r = sys_getlocktimings(&timingdata[0])) != OK) {
67 printf("IS: warning: couldn't get copy of lock timings: %d\n", r);
68 return;
71 for(c = 0; c < TIMING_CATEGORIES; c++) {
72 int b;
73 if (!timingdata[c].lock_timings_range[0] || !timingdata[c].binsize)
74 continue;
75 x = printf("%-*s: misses %lu, resets %lu, measurements %lu: ",
76 TIMING_NAME, timingdata[c].names,
77 timingdata[c].misses,
78 timingdata[c].resets,
79 timingdata[c].measurements);
80 for(b = 0; b < TIMING_POINTS; b++) {
81 int w;
82 if (!timingdata[c].lock_timings[b])
83 continue;
84 x += (w = printf(" %5d: %5d", timingdata[c].lock_timings_range[0] +
85 b*timingdata[c].binsize,
86 timingdata[c].lock_timings[b]));
87 if (x + w >= 80) { printf("\n"); x = 0; }
89 if (x > 0) printf("\n");
93 /*===========================================================================*
94 * kmessages_dmp *
95 *===========================================================================*/
96 PUBLIC void kmessages_dmp()
98 struct kmessages kmess; /* get copy of kernel messages */
99 char print_buf[_KMESS_BUF_SIZE+1]; /* this one is used to print */
100 int start; /* calculate start of messages */
101 int r;
103 /* Try to get a copy of the kernel messages. */
104 if ((r = sys_getkmessages(&kmess)) != OK) {
105 printf("IS: warning: couldn't get copy of kmessages: %d\n", r);
106 return;
109 /* Try to print the kernel messages. First determine start and copy the
110 * buffer into a print-buffer. This is done because the messages in the
111 * copy may wrap (the kernel buffer is circular).
113 start = ((kmess.km_next + _KMESS_BUF_SIZE) - kmess.km_size) % _KMESS_BUF_SIZE;
114 r = 0;
115 while (kmess.km_size > 0) {
116 print_buf[r] = kmess.km_buf[(start+r) % _KMESS_BUF_SIZE];
117 r ++;
118 kmess.km_size --;
120 print_buf[r] = 0; /* make sure it terminates */
121 printf("Dump of all messages generated by the kernel.\n\n");
122 printf("%s", print_buf); /* print the messages */
125 /*===========================================================================*
126 * monparams_dmp *
127 *===========================================================================*/
128 PUBLIC void monparams_dmp()
130 char val[1024];
131 char *e;
132 int r;
134 /* Try to get a copy of the boot monitor parameters. */
135 if ((r = sys_getmonparams(val, sizeof(val))) != OK) {
136 printf("IS: warning: couldn't get copy of monitor params: %d\n", r);
137 return;
140 /* Append new lines to the result. */
141 e = val;
142 do {
143 e += strlen(e);
144 *e++ = '\n';
145 } while (*e != 0);
147 /* Finally, print the result. */
148 printf("Dump of kernel environment strings set by boot monitor.\n");
149 printf("\n%s\n", val);
152 /*===========================================================================*
153 * irqtab_dmp *
154 *===========================================================================*/
155 PUBLIC void irqtab_dmp()
157 int i,r;
158 struct irq_hook irq_hooks[NR_IRQ_HOOKS];
159 int irq_actids[NR_IRQ_VECTORS];
160 struct irq_hook *e; /* irq tab entry */
162 if ((r = sys_getirqhooks(irq_hooks)) != OK) {
163 printf("IS: warning: couldn't get copy of irq hooks: %d\n", r);
164 return;
166 if ((r = sys_getirqactids(irq_actids)) != OK) {
167 printf("IS: warning: couldn't get copy of irq mask: %d\n", r);
168 return;
171 #if 0
172 printf("irq_actids:");
173 for (i= 0; i<NR_IRQ_VECTORS; i++)
174 printf(" [%d] = 0x%08x", i, irq_actids[i]);
175 printf("\n");
176 #endif
178 printf("IRQ policies dump shows use of kernel's IRQ hooks.\n");
179 printf("-h.id- -proc.nr- -irq nr- -policy- -notify id- -masked-\n");
180 for (i=0; i<NR_IRQ_HOOKS; i++) {
181 e = &irq_hooks[i];
182 printf("%3d", i);
183 if (e->proc_nr_e==NONE) {
184 printf(" <unused>\n");
185 continue;
187 printf("%10d ", e->proc_nr_e);
188 printf(" (%02d) ", e->irq);
189 printf(" %s", (e->policy & IRQ_REENABLE) ? "reenable" : " - ");
190 printf(" %4d", e->notify_id);
191 if (irq_actids[e->irq] & e->id)
192 printf(" masked");
193 printf("\n");
195 printf("\n");
198 /*===========================================================================*
199 * boot_flags_str *
200 *===========================================================================*/
201 PRIVATE char *boot_flags_str(int flags)
203 static char str[10];
204 str[0] = (flags & PROC_FULLVM) ? 'V' : '-';
205 str[1] = '\0';
207 return str;
210 /*===========================================================================*
211 * image_dmp *
212 *===========================================================================*/
213 PUBLIC void image_dmp()
215 int m, r;
216 struct boot_image *ip;
218 if ((r = sys_getimage(image)) != OK) {
219 printf("IS: warning: couldn't get copy of image table: %d\n", r);
220 return;
222 printf("Image table dump showing all processes included in system image.\n");
223 printf("---name- -nr- flags -qs- -queue- -stack-\n");
224 for (m=0; m<NR_BOOT_PROCS; m++) {
225 ip = &image[m];
226 printf("%8s %4d %5s %4d %7d %7lu\n",
227 ip->proc_name, ip->proc_nr,
228 boot_flags_str(ip->flags), ip->quantum, ip->priority, ip->stksize);
230 printf("\n");
234 /*===========================================================================*
235 * kenv_dmp *
236 *===========================================================================*/
237 PUBLIC void kenv_dmp()
239 struct kinfo kinfo;
240 struct machine machine;
241 int r;
242 if ((r = sys_getkinfo(&kinfo)) != OK) {
243 printf("IS: warning: couldn't get copy of kernel info struct: %d\n", r);
244 return;
246 if ((r = sys_getmachine(&machine)) != OK) {
247 printf("IS: warning: couldn't get copy of kernel machine struct: %d\n", r);
248 return;
251 printf("Dump of kinfo and machine structures.\n\n");
252 printf("Machine structure:\n");
253 printf("- pc_at: %3d\n", machine.pc_at);
254 printf("- ps_mca: %3d\n", machine.ps_mca);
255 printf("- processor: %3d\n", machine.processor);
256 printf("- vdu_ega: %3d\n", machine.vdu_ega);
257 printf("- vdu_vga: %3d\n\n", machine.vdu_vga);
258 printf("Kernel info structure:\n");
259 printf("- code_base: %5u\n", kinfo.code_base);
260 printf("- code_size: %5u\n", kinfo.code_size);
261 printf("- data_base: %5u\n", kinfo.data_base);
262 printf("- data_size: %5u\n", kinfo.data_size);
263 printf("- proc_addr: %5u\n", kinfo.proc_addr);
264 printf("- bootdev_base: %5u\n", kinfo.bootdev_base);
265 printf("- bootdev_size: %5u\n", kinfo.bootdev_size);
266 printf("- ramdev_base: %5u\n", kinfo.ramdev_base);
267 printf("- ramdev_size: %5u\n", kinfo.ramdev_size);
268 printf("- nr_procs: %3u\n", kinfo.nr_procs);
269 printf("- nr_tasks: %3u\n", kinfo.nr_tasks);
270 printf("- release: %.6s\n", kinfo.release);
271 printf("- version: %.6s\n", kinfo.version);
272 printf("\n");
275 /*===========================================================================*
276 * s_flags_str *
277 *===========================================================================*/
278 PRIVATE char *s_flags_str(int flags)
280 static char str[10];
281 str[0] = (flags & PREEMPTIBLE) ? 'P' : '-';
282 str[1] = (flags & BILLABLE) ? 'B' : '-';
283 str[2] = (flags & DYN_PRIV_ID) ? 'D' : '-';
284 str[3] = (flags & SYS_PROC) ? 'S' : '-';
285 str[4] = (flags & CHECK_IO_PORT) ? 'I' : '-';
286 str[5] = (flags & CHECK_IRQ) ? 'Q' : '-';
287 str[6] = (flags & CHECK_MEM) ? 'M' : '-';
288 str[7] = '\0';
290 return str;
293 /*===========================================================================*
294 * s_traps_str *
295 *===========================================================================*/
296 PRIVATE char *s_traps_str(int flags)
298 static char str[10];
299 str[0] = (flags & (1 << SEND)) ? 'S' : '-';
300 str[1] = (flags & (1 << SENDA)) ? 'A' : '-';
301 str[2] = (flags & (1 << RECEIVE)) ? 'R' : '-';
302 str[3] = (flags & (1 << SENDREC)) ? 'B' : '-';
303 str[4] = (flags & (1 << NOTIFY)) ? 'N' : '-';
304 str[5] = '\0';
306 return str;
309 /*===========================================================================*
310 * privileges_dmp *
311 *===========================================================================*/
312 PUBLIC void privileges_dmp()
314 register struct proc *rp;
315 static struct proc *oldrp = BEG_PROC_ADDR;
316 register struct priv *sp;
317 int r, i;
319 /* First obtain a fresh copy of the current process and system table. */
320 if ((r = sys_getprivtab(priv)) != OK) {
321 printf("IS: warning: couldn't get copy of system privileges table: %d\n", r);
322 return;
324 if ((r = sys_getproctab(proc)) != OK) {
325 printf("IS: warning: couldn't get copy of process table: %d\n", r);
326 return;
329 printf("-nr- -id- -name-- -flags- traps grants -ipc_to-- -kernel calls-\n");
331 PROCLOOP(rp, oldrp)
332 r = -1;
333 for (sp = &priv[0]; sp < &priv[NR_SYS_PROCS]; sp++)
334 if (sp->s_proc_nr == rp->p_nr) { r ++; break; }
335 if (r == -1 && !isemptyp(rp)) {
336 sp = &priv[USER_PRIV_ID];
338 printf("(%02u) %-7.7s %s %s %7d",
339 sp->s_id, rp->p_name,
340 s_flags_str(sp->s_flags), s_traps_str(sp->s_trap_mask),
341 sp->s_grant_entries);
342 for (i=0; i < NR_SYS_PROCS; i += BITCHUNK_BITS) {
343 printf(" %04x", get_sys_bits(sp->s_ipc_to, i));
346 printf(" ");
347 for (i=0; i < NR_SYS_CALLS; i += BITCHUNK_BITS) {
348 printf(" %04x", sp->s_k_call_mask[i/BITCHUNK_BITS]);
350 printf("\n");
355 /*===========================================================================*
356 * p_rts_flags_str *
357 *===========================================================================*/
358 PRIVATE char *p_rts_flags_str(int flags)
360 static char str[10];
361 str[0] = (flags & RTS_PROC_STOP) ? 's' : '-';
362 str[1] = (flags & RTS_SENDING) ? 'S' : '-';
363 str[2] = (flags & RTS_RECEIVING) ? 'R' : '-';
364 str[3] = (flags & RTS_SIGNALED) ? 'I' : '-';
365 str[4] = (flags & RTS_SIG_PENDING) ? 'P' : '-';
366 str[5] = (flags & RTS_P_STOP) ? 'T' : '-';
367 str[6] = (flags & RTS_NO_PRIV) ? 'p' : '-';
368 str[7] = '\0';
370 return str;
373 /*===========================================================================*
374 * proctab_dmp *
375 *===========================================================================*/
376 #if (CHIP == INTEL)
377 PUBLIC void proctab_dmp()
379 /* Proc table dump */
381 register struct proc *rp;
382 static struct proc *oldrp = BEG_PROC_ADDR;
383 int r;
384 phys_clicks text, data, size;
386 /* First obtain a fresh copy of the current process table. */
387 if ((r = sys_getproctab(proc)) != OK) {
388 printf("IS: warning: couldn't get copy of process table: %d\n", r);
389 return;
392 printf("\n-nr-----gen---endpoint-name--- -prior-quant- -user----sys-rtsflags-from/to-\n");
394 PROCLOOP(rp, oldrp)
395 text = rp->p_memmap[T].mem_phys;
396 data = rp->p_memmap[D].mem_phys;
397 size = rp->p_memmap[T].mem_len
398 + ((rp->p_memmap[S].mem_phys + rp->p_memmap[S].mem_len) - data);
399 printf(" %5d %10d ", _ENDPOINT_G(rp->p_endpoint), rp->p_endpoint);
400 printf("%-8.8s %5u %5lu %6lu %6lu ",
401 rp->p_name,
402 rp->p_priority,
403 rp->p_quantum_size_ms,
404 rp->p_user_time, rp->p_sys_time);
405 PRINTRTS(rp);
406 printf("\n");
409 #endif /* (CHIP == INTEL) */
411 /*===========================================================================*
412 * procstack_dmp *
413 *===========================================================================*/
414 PUBLIC void procstack_dmp()
416 /* Proc table dump, with stack */
418 register struct proc *rp;
419 static struct proc *oldrp = BEG_PROC_ADDR;
420 int r;
422 /* First obtain a fresh copy of the current process table. */
423 if ((r = sys_getproctab(proc)) != OK) {
424 printf("IS: warning: couldn't get copy of process table: %d\n", r);
425 return;
428 printf("\n-nr-rts flags-- --stack--\n");
430 PROCLOOP(rp, oldrp)
431 PRINTRTS(rp);
432 sys_sysctl_stacktrace(rp->p_endpoint);
436 /*===========================================================================*
437 * memmap_dmp *
438 *===========================================================================*/
439 PUBLIC void memmap_dmp()
441 register struct proc *rp;
442 static struct proc *oldrp = proc;
443 int r;
444 phys_clicks size;
446 /* First obtain a fresh copy of the current process table. */
447 if ((r = sys_getproctab(proc)) != OK) {
448 printf("IS: warning: couldn't get copy of process table: %d\n", r);
449 return;
452 printf("\n-nr/name--- --pc-- --sp-- -text---- -data---- -stack--- -cr3-\n");
453 PROCLOOP(rp, oldrp)
454 size = rp->p_memmap[T].mem_len
455 + ((rp->p_memmap[S].mem_phys + rp->p_memmap[S].mem_len)
456 - rp->p_memmap[D].mem_phys);
457 printf("%-7.7s%7lx %8lx %4x %4x %4x %4x %5x %5x %8lx\n",
458 rp->p_name,
459 (unsigned long) rp->p_reg.pc,
460 (unsigned long) rp->p_reg.sp,
461 rp->p_memmap[T].mem_phys, rp->p_memmap[T].mem_len,
462 rp->p_memmap[D].mem_phys, rp->p_memmap[D].mem_len,
463 rp->p_memmap[S].mem_phys, rp->p_memmap[S].mem_len,
464 rp->p_seg.p_cr3);
468 /*===========================================================================*
469 * proc_name *
470 *===========================================================================*/
471 PRIVATE char *proc_name(proc_nr)
472 int proc_nr;
474 struct proc *p;
475 if (proc_nr == ANY) return "ANY";
476 if (proc_nr == NONE) return "NONE"; /* bogus */
477 if (proc_nr < -NR_TASKS || proc_nr >= NR_PROCS) return "BOGUS";
478 p = cproc_addr(proc_nr);
479 if (isemptyp(p)) return "EMPTY"; /* bogus */
480 return p->p_name;