upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / kernel / panic.c
1 /*
2  *  linux/kernel/panic.c
3  *
4  *  Copyright (C) 1991, 1992  Linus Torvalds
5  */
6
7 /*
8  * This function is used through-out the kernel (including mm and fs)
9  * to indicate a major problem.
10  */
11 #include <linux/config.h>
12 #include <linux/module.h>
13 #include <linux/sched.h>
14 #include <linux/delay.h>
15 #include <linux/reboot.h>
16 #include <linux/notifier.h>
17 #include <linux/init.h>
18 #include <linux/sysrq.h>
19 #include <linux/interrupt.h>
20 #include <linux/nmi.h>
21 #ifdef CONFIG_KEXEC
22 #include <linux/kexec.h>
23 #endif
24
25 int panic_timeout = 900;
26 int panic_on_oops = 1;
27 int tainted;
28 void (*dump_function_ptr)(const char *, const struct pt_regs *) = 0;
29
30 EXPORT_SYMBOL(panic_timeout);
31 EXPORT_SYMBOL(dump_function_ptr);
32
33 struct notifier_block *panic_notifier_list;
34
35 EXPORT_SYMBOL(panic_notifier_list);
36
37 static int __init panic_setup(char *str)
38 {
39         panic_timeout = simple_strtoul(str, NULL, 0);
40         return 1;
41 }
42 __setup("panic=", panic_setup);
43
44 static long no_blink(long time)
45 {
46         return 0;
47 }
48
49 /* Returns how long it waited in ms */
50 long (*panic_blink)(long time);
51 EXPORT_SYMBOL(panic_blink);
52
53 /**
54  *      panic - halt the system
55  *      @fmt: The text string to print
56  *
57  *      Display a message, then perform cleanups. Functions in the panic
58  *      notifier list are called after the filesystem cache is flushed (when possible).
59  *
60  *      This function never returns.
61  */
62  
63 NORET_TYPE void panic(const char * fmt, ...)
64 {
65         long i;
66         static char buf[1024];
67         va_list args;
68 #if defined(CONFIG_ARCH_S390)
69         unsigned long caller = (unsigned long) __builtin_return_address(0);
70 #endif
71
72         bust_spinlocks(1);
73         va_start(args, fmt);
74         vsnprintf(buf, sizeof(buf), fmt, args);
75         va_end(args);
76         printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
77         if (crashdump_func())
78                 BUG();
79         bust_spinlocks(0);
80
81         notifier_call_chain(&panic_notifier_list, 0, buf);
82         
83 #ifdef CONFIG_SMP
84         smp_send_stop();
85 #endif
86
87         notifier_call_chain(&panic_notifier_list, 0, buf);
88
89         if (!panic_blink)
90                 panic_blink = no_blink;
91
92         if (panic_timeout > 0)
93         {
94                 /*
95                  * Delay timeout seconds before rebooting the machine. 
96                  * We can't use the "normal" timers since we just panicked..
97                  */
98                 printk(KERN_EMERG "Rebooting in %d seconds..",panic_timeout);
99 #ifdef CONFIG_KEXEC
100  {              
101                 struct kimage *image;
102                 image = xchg(&kexec_image, 0);
103                 if (image) {
104                         printk(KERN_EMERG "by starting a new kernel ..\n");
105                         mdelay(panic_timeout*1000);
106                         machine_kexec(image);
107                 }
108  }
109 #endif
110                 for (i = 0; i < panic_timeout*1000; ) {
111                         touch_nmi_watchdog();
112                         i += panic_blink(i);
113                         mdelay(1);
114                         i++;
115                 }
116                 /*
117                  *      Should we run the reboot notifier. For the moment Im
118                  *      choosing not too. It might crash, be corrupt or do
119                  *      more harm than good for other reasons.
120                  */
121                 machine_restart(NULL);
122         }
123 #ifdef __sparc__
124         {
125                 extern int stop_a_enabled;
126                 /* Make sure the user can actually press L1-A */
127                 stop_a_enabled = 1;
128                 printk(KERN_EMERG "Press L1-A to return to the boot prom\n");
129         }
130 #endif
131 #if defined(CONFIG_ARCH_S390)
132         disabled_wait(caller);
133 #endif
134         local_irq_enable();
135         for (i = 0;;) {
136                 i += panic_blink(i);
137                 mdelay(1);
138                 i++;
139         }
140 }
141
142 EXPORT_SYMBOL(panic);
143
144 /**
145  *      print_tainted - return a string to represent the kernel taint state.
146  *
147  *  'P' - Proprietary module has been loaded.
148  *  'F' - Module has been forcibly loaded.
149  *  'S' - SMP with CPUs not designed for SMP.
150  *  'R' - User forced a module unload.
151  *  'M' - Machine had a machine check experience.
152  *  'B' - System has hit bad_page.
153  *
154  *      The string is overwritten by the next call to print_taint().
155  */
156  
157 const char *print_tainted(void)
158 {
159         static char buf[20];
160         if (tainted) {
161                 snprintf(buf, sizeof(buf), "Tainted: %c%c%c%c%c%c",
162                         tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G',
163                         tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
164                         tainted & TAINT_UNSAFE_SMP ? 'S' : ' ',
165                         tainted & TAINT_FORCED_RMMOD ? 'R' : ' ',
166                         tainted & TAINT_MACHINE_CHECK ? 'M' : ' ',
167                         tainted & TAINT_BAD_PAGE ? 'B' : ' ');
168         }
169         else
170                 snprintf(buf, sizeof(buf), "Not tainted");
171         return(buf);
172 }
173
174 void add_taint(unsigned flag)
175 {
176         tainted |= flag;
177 }
178 EXPORT_SYMBOL(add_taint);