RS: fix for fix
[minix.git] / kernel / utility.c
blobaf2425e776bae2622fb89368c4412cf40e5d71f7
1 /* This file contains a collection of miscellaneous procedures:
2 * panic: abort MINIX due to a fatal error
3 * kputc: buffered putc used by kernel printf
4 */
6 #include "kernel.h"
7 #include "arch_proto.h"
9 #include <minix/syslib.h>
10 #include <unistd.h>
11 #include <stdarg.h>
12 #include <signal.h>
13 #include <string.h>
15 #include <minix/sys_config.h>
17 #define ARE_PANICING 0xDEADC0FF
19 /*===========================================================================*
20 * panic *
21 *===========================================================================*/
22 void panic(const char *fmt, ...)
24 va_list arg;
25 /* The system has run aground of a fatal kernel error. Terminate execution. */
26 if (kinfo.minix_panicing == ARE_PANICING) {
27 reset();
29 kinfo.minix_panicing = ARE_PANICING;
30 if (fmt != NULL) {
31 printf("kernel panic: ");
32 va_start(arg, fmt);
33 vprintf(fmt, arg);
34 printf("\n");
37 printf("kernel on CPU %d: ", cpuid);
38 util_stacktrace();
40 #if 0
41 if(get_cpulocal_var(proc_ptr)) {
42 printf("current process : ");
43 proc_stacktrace(get_cpulocal_var(proc_ptr));
45 #endif
47 /* Abort MINIX. */
48 minix_shutdown(NULL);
51 /*===========================================================================*
52 * kputc *
53 *===========================================================================*/
54 void kputc(c)
55 int c; /* character to append */
57 /* Accumulate a single character for a kernel message. Send a notification
58 * to the output driver if an END_OF_KMESS is encountered.
60 if (c != END_OF_KMESS) {
61 int maxblpos = sizeof(kmess.kmess_buf) - 2;
62 #ifdef DEBUG_SERIAL
63 if (kinfo.do_serial_debug) {
64 if(c == '\n')
65 ser_putc('\r');
66 ser_putc(c);
68 #endif
69 kmess.km_buf[kmess.km_next] = c; /* put normal char in buffer */
70 kmess.kmess_buf[kmess.blpos] = c;
71 if (kmess.km_size < sizeof(kmess.km_buf))
72 kmess.km_size += 1;
73 kmess.km_next = (kmess.km_next + 1) % _KMESS_BUF_SIZE;
74 if(kmess.blpos == maxblpos) {
75 memmove(kmess.kmess_buf,
76 kmess.kmess_buf+1, sizeof(kmess.kmess_buf)-1);
77 } else kmess.blpos++;
78 } else {
79 int p;
80 endpoint_t outprocs[] = OUTPUT_PROCS_ARRAY;
81 if(!(kinfo.minix_panicing || kinfo.do_serial_debug)) {
82 for(p = 0; outprocs[p] != NONE; p++) {
83 if(isokprocn(outprocs[p])) {
84 send_sig(outprocs[p], SIGKMESS);
89 return;