also be able to run benchmarks from packages.
[minix.git] / kernel / utility.c
blob07989df5eba3280df2e87af19a90fe96864be569
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>
13 #include <minix/sys_config.h>
15 /*===========================================================================*
16 * panic *
17 *===========================================================================*/
18 PUBLIC void panic(char *what, char *mess,int nr)
20 /* This function is for when a library call wants to panic.
21 * The library call calls printf() and tries to exit a process,
22 * which isn't applicable in the kernel.
24 minix_panic(mess, nr);
27 /*===========================================================================*
28 * minix_panic *
29 *===========================================================================*/
30 PUBLIC void minix_panic(char *mess,int nr)
32 /* The system has run aground of a fatal kernel error. Terminate execution. */
33 if (minix_panicing++) {
34 arch_monitor();
37 if (mess != NULL) {
38 kprintf("kernel panic: %s", mess);
39 if(nr != NO_NUM)
40 kprintf(" %d", nr);
41 kprintf("\n");
44 kprintf("kernel: ");
45 util_stacktrace();
47 /* Abort MINIX. */
48 minix_shutdown(NULL);
52 /* Include system printf() implementation named kprintf() */
54 #define printf kprintf
55 #include "../lib/sysutil/kprintf.c"
57 /*===========================================================================*
58 * kputc *
59 *===========================================================================*/
60 PUBLIC void kputc(c)
61 int c; /* character to append */
63 /* Accumulate a single character for a kernel message. Send a notification
64 * to the output driver if an END_OF_KMESS is encountered.
66 if (c != END_OF_KMESS) {
67 if (do_serial_debug) {
68 if(c == '\n')
69 ser_putc('\r');
70 ser_putc(c);
72 kmess.km_buf[kmess.km_next] = c; /* put normal char in buffer */
73 if (kmess.km_size < sizeof(kmess.km_buf))
74 kmess.km_size += 1;
75 kmess.km_next = (kmess.km_next + 1) % _KMESS_BUF_SIZE;
76 } else {
77 int p, outprocs[] = OUTPUT_PROCS_ARRAY;
78 if(!(minix_panicing || do_serial_debug)) {
79 for(p = 0; outprocs[p] != NONE; p++) {
80 if(isokprocn(outprocs[p]) && !isemptyn(outprocs[p])) {
81 send_sig(outprocs[p], SIGKMESS);
86 return;