This commit was manufactured by cvs2svn to create tag 'before-xenU'.
[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 #include <linux/kexec.h>
22 #include <linux/crash_dump.h>
23
24 int panic_timeout = 900;
25 int panic_on_oops = 1;
26 int tainted;
27 unsigned int crashed;
28 int crash_dump_on;
29 void (*dump_function_ptr)(const char *, const struct pt_regs *) = 0;
30
31 EXPORT_SYMBOL(panic_timeout);
32 EXPORT_SYMBOL(dump_function_ptr);
33
34 struct notifier_block *panic_notifier_list;
35
36 EXPORT_SYMBOL(panic_notifier_list);
37
38 static int __init panic_setup(char *str)
39 {
40         panic_timeout = simple_strtoul(str, NULL, 0);
41         return 1;
42 }
43 __setup("panic=", panic_setup);
44
45 static long no_blink(long time)
46 {
47         return 0;
48 }
49
50 /* Returns how long it waited in ms */
51 long (*panic_blink)(long time);
52 EXPORT_SYMBOL(panic_blink);
53
54 /**
55  *      panic - halt the system
56  *      @fmt: The text string to print
57  *
58  *      Display a message, then perform cleanups.
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         dump_stack();
78         if (crashdump_func())
79                 BUG();
80         bust_spinlocks(0);
81
82         /* If we have crashed, perform a kexec reboot, for dump write-out */
83         crash_machine_kexec();
84
85         notifier_call_chain(&panic_notifier_list, 0, buf);
86         
87 #ifdef CONFIG_SMP
88         smp_send_stop();
89 #endif
90
91         notifier_call_chain(&panic_notifier_list, 0, buf);
92
93         if (!panic_blink)
94                 panic_blink = no_blink;
95
96         if (panic_timeout > 0)
97         {
98                 /*
99                  * Delay timeout seconds before rebooting the machine. 
100                  * We can't use the "normal" timers since we just panicked..
101                  */
102                 printk(KERN_EMERG "Rebooting in %d seconds..",panic_timeout);
103 #ifdef CONFIG_KEXEC
104  {              
105                 struct kimage *image;
106                 image = xchg(&kexec_image, 0);
107                 if (image) {
108                         printk(KERN_EMERG "by starting a new kernel ..\n");
109                         mdelay(panic_timeout*1000);
110                         machine_kexec(image);
111                 }
112  }
113 #endif
114                 for (i = 0; i < panic_timeout*1000; ) {
115                         touch_nmi_watchdog();
116                         i += panic_blink(i);
117                         mdelay(1);
118                         i++;
119                 }
120                 /*
121                  *      Should we run the reboot notifier. For the moment Im
122                  *      choosing not too. It might crash, be corrupt or do
123                  *      more harm than good for other reasons.
124                  */
125                 machine_restart(NULL);
126         }
127 #ifdef __sparc__
128         {
129                 extern int stop_a_enabled;
130                 /* Make sure the user can actually press Stop-A (L1-A) */
131                 stop_a_enabled = 1;
132                 printk(KERN_EMERG "Press Stop-A (L1-A) to return to the boot prom\n");
133         }
134 #endif
135 #if defined(CONFIG_ARCH_S390)
136         disabled_wait(caller);
137 #endif
138         local_irq_enable();
139         for (i = 0;;) {
140                 i += panic_blink(i);
141                 mdelay(1);
142                 i++;
143         }
144 }
145
146 EXPORT_SYMBOL(panic);
147
148 /**
149  *      print_tainted - return a string to represent the kernel taint state.
150  *
151  *  'P' - Proprietary module has been loaded.
152  *  'F' - Module has been forcibly loaded.
153  *  'S' - SMP with CPUs not designed for SMP.
154  *  'R' - User forced a module unload.
155  *  'M' - Machine had a machine check experience.
156  *  'B' - System has hit bad_page.
157  *
158  *      The string is overwritten by the next call to print_taint().
159  */
160  
161 const char *print_tainted(void)
162 {
163         static char buf[20];
164         if (tainted) {
165                 snprintf(buf, sizeof(buf), "Tainted: %c%c%c%c%c%c",
166                         tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G',
167                         tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
168                         tainted & TAINT_UNSAFE_SMP ? 'S' : ' ',
169                         tainted & TAINT_FORCED_RMMOD ? 'R' : ' ',
170                         tainted & TAINT_MACHINE_CHECK ? 'M' : ' ',
171                         tainted & TAINT_BAD_PAGE ? 'B' : ' ');
172         }
173         else
174                 snprintf(buf, sizeof(buf), "Not tainted");
175         return(buf);
176 }
177 EXPORT_SYMBOL(print_tainted);
178
179 void add_taint(unsigned flag)
180 {
181         tainted |= flag;
182 }
183 EXPORT_SYMBOL(add_taint);
184
185 int check_tainted(void)
186 {
187         return tainted;
188 }
189 EXPORT_SYMBOL_GPL(check_tainted);
190