1 /* Debugging dump procedures for the kernel. */
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 /*===========================================================================*
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");
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
);
49 for(c
= 0; c
< TIMING_CATEGORIES
; c
++) {
51 if (!timingdata
[c
].lock_timings_range
[0] || !timingdata
[c
].binsize
)
53 x
= printf("%-*s: misses %lu, resets %lu, measurements %lu: ",
54 TIMING_NAME
, timingdata
[c
].names
,
57 timingdata
[c
].measurements
);
58 for(b
= 0; b
< TIMING_POINTS
; b
++) {
60 if (!timingdata
[c
].lock_timings
[b
])
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");
72 /*===========================================================================*
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 */
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
);
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
;
94 while (kmess
.km_size
> 0) {
95 print_buf
[r
] = kmess
.km_buf
[(start
+r
) % KMESS_BUF_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 /*===========================================================================*
106 *===========================================================================*/
107 PUBLIC
void monparams_dmp()
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
);
119 /* Append new lines to the result. */
126 /* Finally, print the result. */
127 printf("Dump of kernel environment strings set by boot monitor.\n");
128 printf("\n%s\n", val
);
131 /*===========================================================================*
133 *===========================================================================*/
134 PUBLIC
void irqtab_dmp()
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
);
145 if ((r
= sys_getirqactids(irq_actids
)) != OK
) {
146 report("IS","warning: couldn't get copy of irq mask", r
);
151 printf("irq_actids:");
152 for (i
= 0; i
<NR_IRQ_VECTORS
; i
++)
153 printf(" [%d] = 0x%08x", i
, irq_actids
[i
]);
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
++) {
162 if (e
->proc_nr_e
==NONE
) {
163 printf(" <unused>\n");
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
))
177 /*===========================================================================*
179 *===========================================================================*/
180 PUBLIC
void image_dmp()
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
);
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
++) {
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
] = ' ';
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
);
207 /*===========================================================================*
209 *===========================================================================*/
210 PUBLIC
void sched_dmp()
212 struct proc
*rdy_head
[NR_SCHED_QUEUES
];
214 register struct proc
*rp
;
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
);
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
);
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
)
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
)
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
++) {
247 while (rp
!= NIL_PROC
) {
248 printf("%3d ", rp
->p_nr
);
249 rp
= rp
->p_nextready
;
256 /*===========================================================================*
258 *===========================================================================*/
259 PUBLIC
void kenv_dmp()
262 struct machine machine
;
264 if ((r
= sys_getkinfo(&kinfo
)) != OK
) {
265 report("IS","warning: couldn't get copy of kernel info struct", r
);
268 if ((r
= sys_getmachine(&machine
)) != OK
) {
269 report("IS","warning: couldn't get copy of kernel machine struct", r
);
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
);
299 printf("- relocking: %d\n", kinfo
.relocking
);
304 PRIVATE
char *s_flags_str(int flags
)
307 str
[0] = (flags
& PREEMPTIBLE
) ? 'P' : '-';
309 str
[2] = (flags
& BILLABLE
) ? 'B' : '-';
310 str
[3] = (flags
& SYS_PROC
) ? 'S' : '-';
317 PRIVATE
char *s_traps_str(int flags
)
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' : '-';
330 /*===========================================================================*
332 *===========================================================================*/
333 PUBLIC
void privileges_dmp()
335 register struct proc
*rp
;
336 static struct proc
*oldrp
= BEG_PROC_ADDR
;
337 register struct priv
*sp
;
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
);
345 if ((r
= sys_getproctab(proc
)) != OK
) {
346 report("IS","warning: couldn't get copy of process table", r
);
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;
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
));
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
));
373 for (i
=0; i
< NR_SYS_CALLS
; i
+= BITCHUNK_BITS
) {
374 printf(" %04x", sp
->s_k_call_mask
[i
/BITCHUNK_BITS
]);
379 if (rp
== END_PROC_ADDR
) rp
= BEG_PROC_ADDR
; else printf("--more--\r");
384 /*===========================================================================*
386 *===========================================================================*/
387 PUBLIC
void sendmask_dmp()
389 register struct proc
*rp
;
390 static struct proc
*oldrp
= BEG_PROC_ADDR
;
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
);
400 printf("Sendmask dump for process table. User processes (*) don't have [].");
402 printf("The rows of bits indicate to which processes each process may send.");
407 for (j
=proc_nr(BEG_PROC_ADDR
); j
< INIT_PROC_NR
+1; j
++) {
412 for (rp
= oldrp
; rp
< END_PROC_ADDR
; rp
++) {
413 if (isemptyp(rp
)) continue;
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 ");
427 if (rp
== END_PROC_ADDR
) { printf("\n"); rp
= BEG_PROC_ADDR
; }
428 else printf("--more--\r");
433 PRIVATE
char *p_rts_flags_str(int flags
)
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' : '-';
448 /*===========================================================================*
450 *===========================================================================*/
452 PUBLIC
void proctab_dmp()
454 /* Proc table dump */
456 register struct proc
*rp
;
457 static struct proc
*oldrp
= BEG_PROC_ADDR
;
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
);
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;
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",
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
)));
492 if (rp
== END_PROC_ADDR
) rp
= BEG_PROC_ADDR
; else printf("--more--\r");
495 #endif /* (CHIP == INTEL) */
497 /*===========================================================================*
499 *===========================================================================*/
500 PUBLIC
void memmap_dmp()
502 register struct proc
*rp
;
503 static struct proc
*oldrp
= proc
;
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
);
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;
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",
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");
535 /*===========================================================================*
537 *===========================================================================*/
538 PRIVATE
char *proc_name(proc_nr
)
541 if (proc_nr
== ANY
) return "ANY";
542 return cproc_addr(proc_nr
)->p_name
;