Changed logic checking for valid device.
[minix3.git] / kernel / utility.c
blob111fdea9385f84e2232574c8cad153be4ccd8acd
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",NO_NUM);
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 ser_putc(c);
53 kmess.km_buf[kmess.km_next] = c; /* put normal char in buffer */
54 if (kmess.km_size < KMESS_BUF_SIZE)
55 kmess.km_size += 1;
56 kmess.km_next = (kmess.km_next + 1) % KMESS_BUF_SIZE;
57 } else {
58 int p, outprocs[] = OUTPUT_PROCS_ARRAY;
59 for(p = 0; outprocs[p] != NONE; p++) {
60 if(isokprocn(outprocs[p]) && !isemptyn(outprocs[p])) {
61 send_sig(outprocs[p], SIGKMESS);