1 /* Debugging dump procedures for the kernel. */
5 #include <ibm/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
];
64 int r
, c
, f
, skipped
= 0, printed
= 0, maxlines
= 23, x
= 0;
65 static int offsetlines
= 0;
67 if ((r
= sys_getlocktimings(&timingdata
[0])) != OK
) {
68 report("IS","warning: couldn't get copy of lock timings", r
);
72 for(c
= 0; c
< TIMING_CATEGORIES
; c
++) {
74 if (!timingdata
[c
].lock_timings_range
[0] || !timingdata
[c
].binsize
)
76 x
= printf("%-*s: misses %lu, resets %lu, measurements %lu: ",
77 TIMING_NAME
, timingdata
[c
].names
,
80 timingdata
[c
].measurements
);
81 for(b
= 0; b
< TIMING_POINTS
; b
++) {
83 if (!timingdata
[c
].lock_timings
[b
])
85 x
+= (w
= printf(" %5d: %5d", timingdata
[c
].lock_timings_range
[0] +
86 b
*timingdata
[c
].binsize
,
87 timingdata
[c
].lock_timings
[b
]));
88 if (x
+ w
>= 80) { printf("\n"); x
= 0; }
90 if (x
> 0) printf("\n");
94 /*===========================================================================*
96 *===========================================================================*/
97 PUBLIC
void kmessages_dmp()
99 struct kmessages kmess
; /* get copy of kernel messages */
100 char print_buf
[_KMESS_BUF_SIZE
+1]; /* this one is used to print */
101 int start
; /* calculate start of messages */
104 /* Try to get a copy of the kernel messages. */
105 if ((r
= sys_getkmessages(&kmess
)) != OK
) {
106 report("IS","warning: couldn't get copy of kmessages", r
);
110 /* Try to print the kernel messages. First determine start and copy the
111 * buffer into a print-buffer. This is done because the messages in the
112 * copy may wrap (the kernel buffer is circular).
114 start
= ((kmess
.km_next
+ _KMESS_BUF_SIZE
) - kmess
.km_size
) % _KMESS_BUF_SIZE
;
116 while (kmess
.km_size
> 0) {
117 print_buf
[r
] = kmess
.km_buf
[(start
+r
) % _KMESS_BUF_SIZE
];
121 print_buf
[r
] = 0; /* make sure it terminates */
122 printf("Dump of all messages generated by the kernel.\n\n");
123 printf("%s", print_buf
); /* print the messages */
126 /*===========================================================================*
128 *===========================================================================*/
129 PUBLIC
void monparams_dmp()
135 /* Try to get a copy of the boot monitor parameters. */
136 if ((r
= sys_getmonparams(val
, sizeof(val
))) != OK
) {
137 report("IS","warning: couldn't get copy of monitor params", r
);
141 /* Append new lines to the result. */
148 /* Finally, print the result. */
149 printf("Dump of kernel environment strings set by boot monitor.\n");
150 printf("\n%s\n", val
);
153 /*===========================================================================*
155 *===========================================================================*/
156 PUBLIC
void irqtab_dmp()
159 struct irq_hook irq_hooks
[NR_IRQ_HOOKS
];
160 int irq_actids
[NR_IRQ_VECTORS
];
161 struct irq_hook
*e
; /* irq tab entry */
163 if ((r
= sys_getirqhooks(irq_hooks
)) != OK
) {
164 report("IS","warning: couldn't get copy of irq hooks", r
);
167 if ((r
= sys_getirqactids(irq_actids
)) != OK
) {
168 report("IS","warning: couldn't get copy of irq mask", r
);
173 printf("irq_actids:");
174 for (i
= 0; i
<NR_IRQ_VECTORS
; i
++)
175 printf(" [%d] = 0x%08x", i
, irq_actids
[i
]);
179 printf("IRQ policies dump shows use of kernel's IRQ hooks.\n");
180 printf("-h.id- -proc.nr- -irq nr- -policy- -notify id-\n");
181 for (i
=0; i
<NR_IRQ_HOOKS
; i
++) {
184 if (e
->proc_nr_e
==NONE
) {
185 printf(" <unused>\n");
188 printf("%10d ", e
->proc_nr_e
);
189 printf(" (%02d) ", e
->irq
);
190 printf(" %s", (e
->policy
& IRQ_REENABLE
) ? "reenable" : " - ");
191 printf(" %d", e
->notify_id
);
192 if (irq_actids
[e
->irq
] & (1 << i
))
199 /*===========================================================================*
201 *===========================================================================*/
202 PRIVATE
char *boot_flags_str(int flags
)
205 str
[0] = (flags
& PROC_FULLVM
) ? 'V' : '-';
211 /*===========================================================================*
213 *===========================================================================*/
214 PUBLIC
void image_dmp()
217 struct boot_image
*ip
;
219 if ((r
= sys_getimage(image
)) != OK
) {
220 report("IS","warning: couldn't get copy of image table", r
);
223 printf("Image table dump showing all processes included in system image.\n");
224 printf("---name- -nr- ----pc- flags -qs- -queue- -stack-\n");
225 for (m
=0; m
<NR_BOOT_PROCS
; m
++) {
227 printf("%8s %4d %7lu %5s %4d %7d %7lu\n",
228 ip
->proc_name
, ip
->proc_nr
, (long)ip
->initial_pc
,
229 boot_flags_str(ip
->flags
), ip
->quantum
, ip
->priority
, ip
->stksize
);
235 /*===========================================================================*
237 *===========================================================================*/
238 PUBLIC
void kenv_dmp()
241 struct machine machine
;
243 if ((r
= sys_getkinfo(&kinfo
)) != OK
) {
244 report("IS","warning: couldn't get copy of kernel info struct", r
);
247 if ((r
= sys_getmachine(&machine
)) != OK
) {
248 report("IS","warning: couldn't get copy of kernel machine struct", r
);
252 printf("Dump of kinfo and machine structures.\n\n");
253 printf("Machine structure:\n");
254 printf("- pc_at: %3d\n", machine
.pc_at
);
255 printf("- ps_mca: %3d\n", machine
.ps_mca
);
256 printf("- processor: %3d\n", machine
.processor
);
257 printf("- vdu_ega: %3d\n", machine
.vdu_ega
);
258 printf("- vdu_vga: %3d\n\n", machine
.vdu_vga
);
259 printf("Kernel info structure:\n");
260 printf("- code_base: %5u\n", kinfo
.code_base
);
261 printf("- code_size: %5u\n", kinfo
.code_size
);
262 printf("- data_base: %5u\n", kinfo
.data_base
);
263 printf("- data_size: %5u\n", kinfo
.data_size
);
264 printf("- proc_addr: %5u\n", kinfo
.proc_addr
);
265 printf("- bootdev_base: %5u\n", kinfo
.bootdev_base
);
266 printf("- bootdev_size: %5u\n", kinfo
.bootdev_size
);
267 printf("- ramdev_base: %5u\n", kinfo
.ramdev_base
);
268 printf("- ramdev_size: %5u\n", kinfo
.ramdev_size
);
269 printf("- nr_procs: %3u\n", kinfo
.nr_procs
);
270 printf("- nr_tasks: %3u\n", kinfo
.nr_tasks
);
271 printf("- release: %.6s\n", kinfo
.release
);
272 printf("- version: %.6s\n", kinfo
.version
);
276 /*===========================================================================*
278 *===========================================================================*/
279 PRIVATE
char *s_flags_str(int flags
)
282 str
[0] = (flags
& PREEMPTIBLE
) ? 'P' : '-';
283 str
[1] = (flags
& BILLABLE
) ? 'B' : '-';
284 str
[2] = (flags
& DYN_PRIV_ID
) ? 'D' : '-';
285 str
[3] = (flags
& SYS_PROC
) ? 'S' : '-';
286 str
[4] = (flags
& CHECK_IO_PORT
) ? 'I' : '-';
287 str
[5] = (flags
& CHECK_IRQ
) ? 'Q' : '-';
288 str
[6] = (flags
& CHECK_MEM
) ? 'M' : '-';
294 /*===========================================================================*
296 *===========================================================================*/
297 PRIVATE
char *s_traps_str(int flags
)
300 str
[0] = (flags
& (1 << SEND
)) ? 'S' : '-';
301 str
[1] = (flags
& (1 << SENDA
)) ? 'A' : '-';
302 str
[2] = (flags
& (1 << RECEIVE
)) ? 'R' : '-';
303 str
[3] = (flags
& (1 << SENDREC
)) ? 'B' : '-';
304 str
[4] = (flags
& (1 << NOTIFY
)) ? 'N' : '-';
310 /*===========================================================================*
312 *===========================================================================*/
313 PUBLIC
void privileges_dmp()
315 register struct proc
*rp
;
316 static struct proc
*oldrp
= BEG_PROC_ADDR
;
317 register struct priv
*sp
;
320 /* First obtain a fresh copy of the current process and system table. */
321 if ((r
= sys_getprivtab(priv
)) != OK
) {
322 report("IS","warning: couldn't get copy of system privileges table", r
);
325 if ((r
= sys_getproctab(proc
)) != OK
) {
326 report("IS","warning: couldn't get copy of process table", r
);
330 printf("-nr- -id- -name-- -flags- traps grants -ipc_to-- -kernel calls-\n");
334 for (sp
= &priv
[0]; sp
< &priv
[NR_SYS_PROCS
]; sp
++)
335 if (sp
->s_proc_nr
== rp
->p_nr
) { r
++; break; }
336 if (r
== -1 && !isemptyp(rp
)) {
337 sp
= &priv
[USER_PRIV_ID
];
339 printf("(%02u) %-7.7s %s %s %7d",
340 sp
->s_id
, rp
->p_name
,
341 s_flags_str(sp
->s_flags
), s_traps_str(sp
->s_trap_mask
),
342 sp
->s_grant_entries
);
343 for (i
=0; i
< NR_SYS_PROCS
; i
+= BITCHUNK_BITS
) {
344 printf(" %04x", get_sys_bits(sp
->s_ipc_to
, i
));
348 for (i
=0; i
< NR_SYS_CALLS
; i
+= BITCHUNK_BITS
) {
349 printf(" %04x", sp
->s_k_call_mask
[i
/BITCHUNK_BITS
]);
356 /*===========================================================================*
358 *===========================================================================*/
359 PRIVATE
char *p_rts_flags_str(int flags
)
362 str
[0] = (flags
& RTS_PROC_STOP
) ? 's' : '-';
363 str
[1] = (flags
& RTS_SENDING
) ? 'S' : '-';
364 str
[2] = (flags
& RTS_RECEIVING
) ? 'R' : '-';
365 str
[3] = (flags
& RTS_SIGNALED
) ? 'I' : '-';
366 str
[4] = (flags
& RTS_SIG_PENDING
) ? 'P' : '-';
367 str
[5] = (flags
& RTS_P_STOP
) ? 'T' : '-';
368 str
[6] = (flags
& RTS_NO_PRIV
) ? 'p' : '-';
374 /*===========================================================================*
376 *===========================================================================*/
378 PUBLIC
void proctab_dmp()
380 /* Proc table dump */
382 register struct proc
*rp
;
383 static struct proc
*oldrp
= BEG_PROC_ADDR
;
385 phys_clicks text
, data
, size
;
387 /* First obtain a fresh copy of the current process table. */
388 if ((r
= sys_getproctab(proc
)) != OK
) {
389 report("IS","warning: couldn't get copy of process table", r
);
393 printf("\n-nr-----gen---endpoint-name--- -prior-quant- -user----sys-rtsflags-from/to-\n");
396 text
= rp
->p_memmap
[T
].mem_phys
;
397 data
= rp
->p_memmap
[D
].mem_phys
;
398 size
= rp
->p_memmap
[T
].mem_len
399 + ((rp
->p_memmap
[S
].mem_phys
+ rp
->p_memmap
[S
].mem_len
) - data
);
400 printf(" %5d %10d ", _ENDPOINT_G(rp
->p_endpoint
), rp
->p_endpoint
);
401 printf("%-8.8s %02u/%02u %02d/%02u %6lu %6lu ",
403 rp
->p_priority
, rp
->p_max_priority
,
404 rp
->p_ticks_left
, rp
->p_quantum_size
,
405 rp
->p_user_time
, rp
->p_sys_time
);
410 #endif /* (CHIP == INTEL) */
412 /*===========================================================================*
414 *===========================================================================*/
415 PUBLIC
void procstack_dmp()
417 /* Proc table dump, with stack */
419 register struct proc
*rp
;
420 static struct proc
*oldrp
= BEG_PROC_ADDR
;
423 /* First obtain a fresh copy of the current process table. */
424 if ((r
= sys_getproctab(proc
)) != OK
) {
425 report("IS","warning: couldn't get copy of process table", r
);
429 printf("\n-nr-rts flags-- --stack--\n");
433 sys_sysctl_stacktrace(rp
->p_endpoint
);
437 /*===========================================================================*
439 *===========================================================================*/
440 PUBLIC
void memmap_dmp()
442 register struct proc
*rp
;
443 static struct proc
*oldrp
= proc
;
447 /* First obtain a fresh copy of the current process table. */
448 if ((r
= sys_getproctab(proc
)) != OK
) {
449 report("IS","warning: couldn't get copy of process table", r
);
453 printf("\n-nr/name--- --pc-- --sp-- -text---- -data---- -stack--- -cr3-\n");
455 size
= rp
->p_memmap
[T
].mem_len
456 + ((rp
->p_memmap
[S
].mem_phys
+ rp
->p_memmap
[S
].mem_len
)
457 - rp
->p_memmap
[D
].mem_phys
);
458 printf("%-7.7s%7lx %8lx %4x %4x %4x %4x %5x %5x %8lx\n",
460 (unsigned long) rp
->p_reg
.pc
,
461 (unsigned long) rp
->p_reg
.sp
,
462 rp
->p_memmap
[T
].mem_phys
, rp
->p_memmap
[T
].mem_len
,
463 rp
->p_memmap
[D
].mem_phys
, rp
->p_memmap
[D
].mem_len
,
464 rp
->p_memmap
[S
].mem_phys
, rp
->p_memmap
[S
].mem_len
,
469 /*===========================================================================*
471 *===========================================================================*/
472 PRIVATE
char *proc_name(proc_nr
)
476 if (proc_nr
== ANY
) return "ANY";
477 if (proc_nr
== NONE
) return "NONE"; /* bogus */
478 if (proc_nr
< -NR_TASKS
|| proc_nr
>= NR_PROCS
) return "BOGUS";
479 p
= cproc_addr(proc_nr
);
480 if (isemptyp(p
)) return "EMPTY"; /* bogus */