- simplify findhole() for use for 1 page only
[minix.git] / kernel / utility.c
blob0e3ac6ca2ed8fa8efd26e4e88a964296470c35e8
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++) {
42 if (mess != NULL) {
43 kprintf("kernel panic: %s", mess);
44 if(nr != NO_NUM)
45 kprintf(" %d", nr);
46 kprintf("\n");
49 kprintf("kernel: ");
50 util_stacktrace();
53 /* Abort MINIX. */
54 minix_shutdown(NULL);
58 /* Include system printf() implementation named kprintf() */
60 #define printf kprintf
61 #include "../lib/sysutil/kprintf.c"
63 /*===========================================================================*
64 * kputc *
65 *===========================================================================*/
66 PUBLIC void kputc(c)
67 int c; /* character to append */
69 /* Accumulate a single character for a kernel message. Send a notification
70 * to the output driver if an END_OF_KMESS is encountered.
72 if (c != END_OF_KMESS) {
73 if (do_serial_debug) {
74 if(c == '\n')
75 ser_putc('\r');
76 ser_putc(c);
78 kmess.km_buf[kmess.km_next] = c; /* put normal char in buffer */
79 if (kmess.km_size < sizeof(kmess.km_buf))
80 kmess.km_size += 1;
81 kmess.km_next = (kmess.km_next + 1) % _KMESS_BUF_SIZE;
82 } else {
83 int p, outprocs[] = OUTPUT_PROCS_ARRAY;
84 if(!(minix_panicing || do_serial_debug)) {
85 for(p = 0; outprocs[p] != NONE; p++) {
86 if(isokprocn(outprocs[p]) && !isemptyn(outprocs[p])) {
87 send_sig(outprocs[p], SIGKMESS);
92 return;