a script to decode stack traces.
[minix3.git] / kernel / utility.c
blob8835692720d0297ba0536f4efc442ef3f9e2d734
1 /* This file contains a collection of miscellaneous procedures:
2 * panic: abort MINIX due to a fatal error
3 * kprintf: (from lib/sysutil/kprintf.c)
4 * kputc: buffered putc used by kernel kprintf
5 */
7 #include "kernel.h"
8 #include "proc.h"
10 #include <unistd.h>
11 #include <signal.h>
13 /*===========================================================================*
14 * panic *
15 *===========================================================================*/
16 PUBLIC void panic(mess,nr)
17 _CONST char *mess;
18 int nr;
20 /* The system has run aground of a fatal kernel error. Terminate execution. */
21 static int panicking = 0;
22 if (panicking ++) return; /* prevent recursive panics */
24 if (mess != NULL) {
25 kprintf("\nKernel panic: %s", mess);
26 if (nr != NO_NUM) kprintf(" %d", nr);
27 kprintf("\n");
30 /* Abort MINIX. */
31 prepare_shutdown(RBT_PANIC);
35 /* Include system printf() implementation named kprintf() */
37 #define printf kprintf
38 #include "../lib/sysutil/kprintf.c"
39 #define END_OF_KMESS 0
41 /*===========================================================================*
42 * kputc *
43 *===========================================================================*/
44 PUBLIC void kputc(c)
45 int c; /* character to append */
47 /* Accumulate a single character for a kernel message. Send a notification
48 * to the output driver if an END_OF_KMESS is encountered.
50 if (c != END_OF_KMESS) {
51 if (do_serial_debug) {
52 if(c == '\n')
53 ser_putc('\r');
54 ser_putc(c);
57 kmess.km_buf[kmess.km_next] = c; /* put normal char in buffer */
58 if (kmess.km_size < KMESS_BUF_SIZE)
59 kmess.km_size += 1;
60 kmess.km_next = (kmess.km_next + 1) % KMESS_BUF_SIZE;
61 } else {
62 int p, outprocs[] = OUTPUT_PROCS_ARRAY;
63 for(p = 0; outprocs[p] != NONE; p++) {
64 if(isokprocn(outprocs[p]) && !isemptyn(outprocs[p])) {
65 send_sig(outprocs[p], SIGKMESS);