Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[sfrench/cifs-2.6.git] / arch / cris / kernel / traps.c
1 /*
2  *  linux/arch/cris/traps.c
3  *
4  *  Here we handle the break vectors not used by the system call
5  *  mechanism, as well as some general stack/register dumping
6  *  things.
7  *
8  *  Copyright (C) 2000-2007 Axis Communications AB
9  *
10  *  Authors:   Bjorn Wesen
11  *             Hans-Peter Nilsson
12  *
13  */
14
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/utsname.h>
18 #include <linux/sched/debug.h>
19 #ifdef CONFIG_KALLSYMS
20 #include <linux/kallsyms.h>
21 #endif
22
23 #include <asm/pgtable.h>
24 #include <linux/uaccess.h>
25 #include <arch/system.h>
26
27 extern void arch_enable_nmi(void);
28 extern void stop_watchdog(void);
29 extern void reset_watchdog(void);
30 extern void show_registers(struct pt_regs *regs);
31
32 #ifdef CONFIG_DEBUG_BUGVERBOSE
33 extern void handle_BUG(struct pt_regs *regs);
34 #else
35 #define handle_BUG(regs)
36 #endif
37
38 static int kstack_depth_to_print = 24;
39
40 void (*nmi_handler)(struct pt_regs *);
41
42 void show_trace(unsigned long *stack)
43 {
44         unsigned long addr, module_start, module_end;
45         extern char _stext[], _etext[];
46         int i;
47
48         pr_err("\nCall Trace: ");
49
50         i = 1;
51         module_start = VMALLOC_START;
52         module_end = VMALLOC_END;
53
54         while (((long)stack & (THREAD_SIZE - 1)) != 0) {
55                 if (__get_user(addr, stack)) {
56                         /* This message matches "failing address" marked
57                            s390 in ksymoops, so lines containing it will
58                            not be filtered out by ksymoops.  */
59                         pr_err("Failing address 0x%lx\n", (unsigned long)stack);
60                         break;
61                 }
62                 stack++;
63
64                 /*
65                  * If the address is either in the text segment of the
66                  * kernel, or in the region which contains vmalloc'ed
67                  * memory, it *may* be the address of a calling
68                  * routine; if so, print it so that someone tracing
69                  * down the cause of the crash will be able to figure
70                  * out the call path that was taken.
71                  */
72                 if (((addr >= (unsigned long)_stext) &&
73                      (addr <= (unsigned long)_etext)) ||
74                     ((addr >= module_start) && (addr <= module_end))) {
75 #ifdef CONFIG_KALLSYMS
76                         print_ip_sym(addr);
77 #else
78                         if (i && ((i % 8) == 0))
79                                 pr_err("\n       ");
80                         pr_err("[<%08lx>] ", addr);
81                         i++;
82 #endif
83                 }
84         }
85 }
86
87 /*
88  * These constants are for searching for possible module text
89  * segments. MODULE_RANGE is a guess of how much space is likely
90  * to be vmalloced.
91  */
92
93 #define MODULE_RANGE (8*1024*1024)
94
95 /*
96  * The output (format, strings and order) is adjusted to be usable with
97  * ksymoops-2.4.1 with some necessary CRIS-specific patches.  Please don't
98  * change it unless you're serious about adjusting ksymoops and syncing
99  * with the ksymoops maintainer.
100  */
101
102 void
103 show_stack(struct task_struct *task, unsigned long *sp)
104 {
105         unsigned long *stack, addr;
106         int i;
107
108         /*
109          * debugging aid: "show_stack(NULL);" prints a
110          * back trace.
111          */
112
113         if (sp == NULL) {
114                 if (task)
115                         sp = (unsigned long*)task->thread.ksp;
116                 else
117                         sp = (unsigned long*)rdsp();
118         }
119
120         stack = sp;
121
122         pr_err("\nStack from %08lx:\n       ", (unsigned long)stack);
123         for (i = 0; i < kstack_depth_to_print; i++) {
124                 if (((long)stack & (THREAD_SIZE-1)) == 0)
125                         break;
126                 if (i && ((i % 8) == 0))
127                         pr_err("\n       ");
128                 if (__get_user(addr, stack)) {
129                         /* This message matches "failing address" marked
130                            s390 in ksymoops, so lines containing it will
131                            not be filtered out by ksymoops.  */
132                         pr_err("Failing address 0x%lx\n", (unsigned long)stack);
133                         break;
134                 }
135                 stack++;
136                 pr_err("%08lx ", addr);
137         }
138         show_trace(sp);
139 }
140
141 #if 0
142 /* displays a short stack trace */
143
144 int
145 show_stack(void)
146 {
147         unsigned long *sp = (unsigned long *)rdusp();
148         int i;
149
150         pr_err("Stack dump [0x%08lx]:\n", (unsigned long)sp);
151         for (i = 0; i < 16; i++)
152                 pr_err("sp + %d: 0x%08lx\n", i*4, sp[i]);
153         return 0;
154 }
155 #endif
156
157 void set_nmi_handler(void (*handler)(struct pt_regs *))
158 {
159         nmi_handler = handler;
160         arch_enable_nmi();
161 }
162
163 #ifdef CONFIG_DEBUG_NMI_OOPS
164 void oops_nmi_handler(struct pt_regs *regs)
165 {
166         stop_watchdog();
167         oops_in_progress = 1;
168         pr_err("NMI!\n");
169         show_registers(regs);
170         oops_in_progress = 0;
171         oops_exit();
172         pr_err("\n"); /* Flush mtdoops.  */
173 }
174
175 static int __init oops_nmi_register(void)
176 {
177         set_nmi_handler(oops_nmi_handler);
178         return 0;
179 }
180
181 __initcall(oops_nmi_register);
182
183 #endif
184
185 /*
186  * This gets called from entry.S when the watchdog has bitten. Show something
187  * similar to an Oops dump, and if the kernel is configured to be a nice
188  * doggy, then halt instead of reboot.
189  */
190 void watchdog_bite_hook(struct pt_regs *regs)
191 {
192 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
193         local_irq_disable();
194         stop_watchdog();
195         show_registers(regs);
196
197         while (1)
198                 ; /* Do nothing. */
199 #else
200         show_registers(regs);
201 #endif
202 }
203
204 /* This is normally the Oops function. */
205 void die_if_kernel(const char *str, struct pt_regs *regs, long err)
206 {
207         if (user_mode(regs))
208                 return;
209
210 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
211         /*
212          * This printout might take too long and could trigger
213          * the watchdog normally. If NICE_DOGGY is set, simply
214          * stop the watchdog during the printout.
215          */
216         stop_watchdog();
217 #endif
218
219         oops_enter();
220         handle_BUG(regs);
221
222         pr_err("Linux %s %s\n", utsname()->release, utsname()->version);
223         pr_err("%s: %04lx\n", str, err & 0xffff);
224
225         show_registers(regs);
226
227         oops_exit();
228         oops_in_progress = 0;
229         pr_err("\n"); /* Flush mtdoops.  */
230
231 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
232         reset_watchdog();
233 #endif
234         do_exit(SIGSEGV);
235 }
236
237 void __init trap_init(void)
238 {
239         /* Nothing needs to be done */
240 }