Reformat.
[linux-2.6/linux-mips.git] / kernel / panic.c
blob10cfaa18b4ea21cabf7a56f226ded3cfc4fdd4a3
1 /*
2 * linux/kernel/panic.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
7 /*
8 * This function is used through-out the kernel (including mm and fs)
9 * to indicate a major problem.
11 #include <linux/config.h>
12 #include <linux/sched.h>
13 #include <linux/delay.h>
14 #include <linux/reboot.h>
15 #include <linux/notifier.h>
16 #include <linux/init.h>
17 #include <linux/sysrq.h>
18 #include <linux/interrupt.h>
20 asmlinkage void sys_sync(void); /* it's really int */
22 int panic_timeout;
23 int panic_on_oops;
24 int tainted;
26 struct notifier_block *panic_notifier_list;
28 static int __init panic_setup(char *str)
30 panic_timeout = simple_strtoul(str, NULL, 0);
31 return 1;
33 __setup("panic=", panic_setup);
35 /**
36 * panic - halt the system
37 * @fmt: The text string to print
39 * Display a message, then perform cleanups. Functions in the panic
40 * notifier list are called after the filesystem cache is flushed (when possible).
42 * This function never returns.
45 NORET_TYPE void panic(const char * fmt, ...)
47 static char buf[1024];
48 va_list args;
49 #if defined(CONFIG_ARCH_S390)
50 unsigned long caller = (unsigned long) __builtin_return_address(0);
51 #endif
53 bust_spinlocks(1);
54 va_start(args, fmt);
55 vsnprintf(buf, sizeof(buf), fmt, args);
56 va_end(args);
57 printk(KERN_EMERG "Kernel panic: %s\n",buf);
58 if (in_interrupt())
59 printk(KERN_EMERG "In interrupt handler - not syncing\n");
60 else if (!current->pid)
61 printk(KERN_EMERG "In idle task - not syncing\n");
62 else
63 sys_sync();
64 bust_spinlocks(0);
66 #ifdef CONFIG_SMP
67 smp_send_stop();
68 #endif
70 notifier_call_chain(&panic_notifier_list, 0, buf);
72 if (panic_timeout > 0)
75 * Delay timeout seconds before rebooting the machine.
76 * We can't use the "normal" timers since we just panicked..
78 printk(KERN_EMERG "Rebooting in %d seconds..",panic_timeout);
79 mdelay(panic_timeout*1000);
81 * Should we run the reboot notifier. For the moment Im
82 * choosing not too. It might crash, be corrupt or do
83 * more harm than good for other reasons.
85 machine_restart(NULL);
87 #ifdef __sparc__
89 extern int stop_a_enabled;
90 /* Make sure the user can actually press L1-A */
91 stop_a_enabled = 1;
92 printk(KERN_EMERG "Press L1-A to return to the boot prom\n");
94 #endif
95 #if defined(CONFIG_ARCH_S390)
96 disabled_wait(caller);
97 #endif
98 local_irq_enable();
99 for (;;)
104 * print_tainted - return a string to represent the kernel taint state.
106 * 'P' - Proprietary module has been loaded.
107 * 'F' - Module has been forcibly loaded.
108 * 'S' - SMP with CPUs not designed for SMP.
110 * The string is overwritten by the next call to print_taint().
113 const char *print_tainted(void)
115 static char buf[20];
116 if (tainted) {
117 snprintf(buf, sizeof(buf), "Tainted: %c%c%c",
118 tainted & TAINT_PROPRIETARY_MODULE ? 'P' : 'G',
119 tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
120 tainted & TAINT_UNSAFE_SMP ? 'S' : ' ');
122 else
123 snprintf(buf, sizeof(buf), "Not tainted");
124 return(buf);