1 /* Debugging dump procedures for the kernel. */
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"
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); \
30 #define PROCLOOP(rp, oldrp) \
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 /*===========================================================================*
60 *===========================================================================*/
61 PUBLIC
void timing_dmp()
63 static struct util_timingdata timingdata
[TIMING_CATEGORIES
];
66 if ((r
= sys_getlocktimings(&timingdata
[0])) != OK
) {
67 printf("IS: warning: couldn't get copy of lock timings: %d\n", r
);
71 for(c
= 0; c
< TIMING_CATEGORIES
; c
++) {
73 if (!timingdata
[c
].lock_timings_range
[0] || !timingdata
[c
].binsize
)
75 x
= printf("%-*s: misses %lu, resets %lu, measurements %lu: ",
76 TIMING_NAME
, timingdata
[c
].names
,
79 timingdata
[c
].measurements
);
80 for(b
= 0; b
< TIMING_POINTS
; b
++) {
82 if (!timingdata
[c
].lock_timings
[b
])
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 /*===========================================================================*
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 */
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
);
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
;
115 while (kmess
.km_size
> 0) {
116 print_buf
[r
] = kmess
.km_buf
[(start
+r
) % _KMESS_BUF_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 /*===========================================================================*
127 *===========================================================================*/
128 PUBLIC
void monparams_dmp()
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
);
140 /* Append new lines to the result. */
147 /* Finally, print the result. */
148 printf("Dump of kernel environment strings set by boot monitor.\n");
149 printf("\n%s\n", val
);
152 /*===========================================================================*
154 *===========================================================================*/
155 PUBLIC
void irqtab_dmp()
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
);
166 if ((r
= sys_getirqactids(irq_actids
)) != OK
) {
167 printf("IS: warning: couldn't get copy of irq mask: %d\n", r
);
172 printf("irq_actids:");
173 for (i
= 0; i
<NR_IRQ_VECTORS
; i
++)
174 printf(" [%d] = 0x%08x", i
, irq_actids
[i
]);
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
++) {
183 if (e
->proc_nr_e
==NONE
) {
184 printf(" <unused>\n");
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
)
198 /*===========================================================================*
200 *===========================================================================*/
201 PRIVATE
char *boot_flags_str(int flags
)
204 str
[0] = (flags
& PROC_FULLVM
) ? 'V' : '-';
210 /*===========================================================================*
212 *===========================================================================*/
213 PUBLIC
void image_dmp()
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
);
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
++) {
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
);
234 /*===========================================================================*
236 *===========================================================================*/
237 PUBLIC
void kenv_dmp()
240 struct machine machine
;
242 if ((r
= sys_getkinfo(&kinfo
)) != OK
) {
243 printf("IS: warning: couldn't get copy of kernel info struct: %d\n", r
);
246 if ((r
= sys_getmachine(&machine
)) != OK
) {
247 printf("IS: warning: couldn't get copy of kernel machine struct: %d\n", r
);
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
);
275 /*===========================================================================*
277 *===========================================================================*/
278 PRIVATE
char *s_flags_str(int flags
)
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' : '-';
293 /*===========================================================================*
295 *===========================================================================*/
296 PRIVATE
char *s_traps_str(int flags
)
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' : '-';
309 /*===========================================================================*
311 *===========================================================================*/
312 PUBLIC
void privileges_dmp()
314 register struct proc
*rp
;
315 static struct proc
*oldrp
= BEG_PROC_ADDR
;
316 register struct priv
*sp
;
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
);
324 if ((r
= sys_getproctab(proc
)) != OK
) {
325 printf("IS: warning: couldn't get copy of process table: %d\n", r
);
329 printf("-nr- -id- -name-- -flags- traps grants -ipc_to-- -kernel calls-\n");
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
));
347 for (i
=0; i
< NR_SYS_CALLS
; i
+= BITCHUNK_BITS
) {
348 printf(" %04x", sp
->s_k_call_mask
[i
/BITCHUNK_BITS
]);
355 /*===========================================================================*
357 *===========================================================================*/
358 PRIVATE
char *p_rts_flags_str(int flags
)
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' : '-';
373 /*===========================================================================*
375 *===========================================================================*/
377 PUBLIC
void proctab_dmp()
379 /* Proc table dump */
381 register struct proc
*rp
;
382 static struct proc
*oldrp
= BEG_PROC_ADDR
;
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
);
392 printf("\n-nr-----gen---endpoint-name--- -prior-quant- -user----sys-rtsflags-from/to-\n");
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 ",
403 rp
->p_quantum_size_ms
,
404 rp
->p_user_time
, rp
->p_sys_time
);
409 #endif /* (CHIP == INTEL) */
411 /*===========================================================================*
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
;
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
);
428 printf("\n-nr-rts flags-- --stack--\n");
432 sys_sysctl_stacktrace(rp
->p_endpoint
);
436 /*===========================================================================*
438 *===========================================================================*/
439 PUBLIC
void memmap_dmp()
441 register struct proc
*rp
;
442 static struct proc
*oldrp
= proc
;
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
);
452 printf("\n-nr/name--- --pc-- --sp-- -text---- -data---- -stack--- -cr3-\n");
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",
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
,
468 /*===========================================================================*
470 *===========================================================================*/
471 PRIVATE
char *proc_name(proc_nr
)
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 */