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
6 #include "kernel/kernel.h"
7 #include "arch_proto.h"
9 #include <minix/syslib.h>
15 #include <minix/sys_config.h>
17 #define ARE_PANICING 0xDEADC0FF
19 /*===========================================================================*
21 *===========================================================================*/
22 void panic(const char *fmt
, ...)
25 /* The system has run aground of a fatal kernel error. Terminate execution. */
26 if (kinfo
.minix_panicing
== ARE_PANICING
) {
29 kinfo
.minix_panicing
= ARE_PANICING
;
31 printf("kernel panic: ");
37 printf("kernel on CPU %d: ", cpuid
);
41 if(get_cpulocal_var(proc_ptr
)) {
42 printf("current process : ");
43 proc_stacktrace(get_cpulocal_var(proc_ptr
));
51 /*===========================================================================*
53 *===========================================================================*/
55 int c
; /* character to append */
57 /* Accumulate a single character for a kernel message. Send a notification
58 * to the output drivers if an END_OF_KMESS is encountered.
60 if (c
!= END_OF_KMESS
) {
61 int maxblpos
= sizeof(kmess
.kmess_buf
) - 2;
63 if (kinfo
.do_serial_debug
) {
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
))
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);
78 } else if (!(kinfo
.minix_panicing
|| kinfo
.do_serial_debug
)) {
83 /*===========================================================================*
85 *===========================================================================*/
87 int e
; /* error code */
89 panic("_exit called from within the kernel, should not happen. (err %i)", e
);