This commit was manufactured by cvs2svn to create tag
[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/syscalls.h>
20 #include <linux/interrupt.h>
21 #include <linux/nmi.h>
22 #ifdef CONFIG_KEXEC
23 #include <linux/kexec.h>
24 #endif
25
26 int panic_timeout;
27 int panic_on_oops;
28 int tainted;
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 int netdump_mode = 0;
46 EXPORT_SYMBOL_GPL(netdump_mode);
47
48 /**
49  *      panic - halt the system
50  *      @fmt: The text string to print
51  *
52  *      Display a message, then perform cleanups. Functions in the panic
53  *      notifier list are called after the filesystem cache is flushed (when possible).
54  *
55  *      This function never returns.
56  */
57  
58 NORET_TYPE void panic(const char * fmt, ...)
59 {
60         static char buf[1024];
61         va_list args;
62 #if defined(CONFIG_ARCH_S390)
63         unsigned long caller = (unsigned long) __builtin_return_address(0);
64 #endif
65
66         bust_spinlocks(1);
67         va_start(args, fmt);
68         vsnprintf(buf, sizeof(buf), fmt, args);
69         va_end(args);
70
71         printk(KERN_EMERG "Kernel panic: %s\n",buf);
72         if (netdump_func)
73                 BUG();
74         if (in_interrupt())
75                 printk(KERN_EMERG "In interrupt handler - not syncing\n");
76         else if (!current->pid)
77                 printk(KERN_EMERG "In idle task - not syncing\n");
78         else
79                 sys_sync();
80         bust_spinlocks(0);
81
82         notifier_call_chain(&panic_notifier_list, 0, buf);
83         
84 #ifdef CONFIG_SMP
85         smp_send_stop();
86 #endif
87
88         if (panic_timeout > 0) {
89                 int i;
90                 /*
91                  * Delay timeout seconds before rebooting the machine. 
92                  * We can't use the "normal" timers since we just panicked..
93                  */
94                 printk(KERN_EMERG "Rebooting in %d seconds..",panic_timeout);
95 #ifdef CONFIG_KEXEC
96 {               
97                 struct kimage *image;
98                 image = xchg(&kexec_image, 0);
99                 if (image) {
100                         printk(KERN_EMERG "by starting a new kernel ..\n");
101                         mdelay(panic_timeout*1000);
102                         machine_kexec(image);
103                 }
104  }
105 #endif
106                 for (i = 0; i < panic_timeout; i++) {
107                         touch_nmi_watchdog();
108                         mdelay(1000);
109                 }
110                 /*
111                  *      Should we run the reboot notifier. For the moment Im
112                  *      choosing not too. It might crash, be corrupt or do
113                  *      more harm than good for other reasons.
114                  */
115                 machine_restart(NULL);
116         }
117 #ifdef __sparc__
118         {
119                 extern int stop_a_enabled;
120                 /* Make sure the user can actually press L1-A */
121                 stop_a_enabled = 1;
122                 printk(KERN_EMERG "Press L1-A to return to the boot prom\n");
123         }
124 #endif
125 #if defined(CONFIG_ARCH_S390)
126         disabled_wait(caller);
127 #endif
128         local_irq_enable();
129         for (;;)
130                 ;
131 }
132
133 EXPORT_SYMBOL(panic);
134
135 /**
136  *      print_tainted - return a string to represent the kernel taint state.
137  *
138  *  'P' - Proprietary module has been loaded.
139  *  'F' - Module has been forcibly loaded.
140  *  'S' - SMP with CPUs not designed for SMP.
141  *
142  *      The string is overwritten by the next call to print_taint().
143  */
144  
145 const char *print_tainted(void)
146 {
147         static char buf[20];
148         if (tainted) {
149                 snprintf(buf, sizeof(buf), "Tainted: %c%c%c",
150                         tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G',
151                         tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
152                         tainted & TAINT_UNSAFE_SMP ? 'S' : ' ');
153         }
154         else
155                 snprintf(buf, sizeof(buf), "Not tainted");
156         return(buf);
157 }