fix compiler warning
[minix.git] / kernel / utility.c
blobfa31cf3fe779e3d004585adc9a9dc39760d7a3a9
1 /* This file contains a collection of miscellaneous procedures:
2 * minix_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>
12 #include <string.h>
14 #include <minix/sysutil.h>
15 #include <minix/sys_config.h>
17 /*===========================================================================*
18 * panic *
19 *===========================================================================*/
20 PUBLIC void panic(what, mess,nr)
21 char *what;
22 char *mess;
23 int nr;
25 /* This function is for when a library call wants to panic.
26 * The library call calls printf() and tries to exit a process,
27 * which isn't applicable in the kernel.
29 minix_panic(mess, nr);
32 /*===========================================================================*
33 * minix_panic *
34 *===========================================================================*/
35 PUBLIC void minix_panic(mess,nr)
36 char *mess;
37 int nr;
39 /* The system has run aground of a fatal kernel error. Terminate execution. */
40 if (minix_panicing++) {
41 arch_monitor();
44 if (mess != NULL) {
45 kprintf("kernel panic: %s", mess);
46 if(nr != NO_NUM)
47 kprintf(" %d", nr);
48 kprintf("\n");
51 kprintf("kernel: ");
52 util_stacktrace();
54 /* Abort MINIX. */
55 minix_shutdown(NULL);
59 /* Include system printf() implementation named kprintf() */
61 #define printf kprintf
62 #include "../lib/sysutil/kprintf.c"
64 /*===========================================================================*
65 * kputc *
66 *===========================================================================*/
67 PUBLIC void kputc(c)
68 int c; /* character to append */
70 /* Accumulate a single character for a kernel message. Send a notification
71 * to the output driver if an END_OF_KMESS is encountered.
73 if (c != END_OF_KMESS) {
74 if (do_serial_debug) {
75 if(c == '\n')
76 ser_putc('\r');
77 ser_putc(c);
79 kmess.km_buf[kmess.km_next] = c; /* put normal char in buffer */
80 if (kmess.km_size < sizeof(kmess.km_buf))
81 kmess.km_size += 1;
82 kmess.km_next = (kmess.km_next + 1) % _KMESS_BUF_SIZE;
83 } else {
84 int p, outprocs[] = OUTPUT_PROCS_ARRAY;
85 if(!(minix_panicing || do_serial_debug)) {
86 for(p = 0; outprocs[p] != NONE; p++) {
87 if(isokprocn(outprocs[p]) && !isemptyn(outprocs[p])) {
88 send_sig(outprocs[p], SIGKMESS);
93 return;