Merge remote-tracking branch 'remotes/powerpc/topic/xive' into kvm-ppc-next
[linux/fpc-iii.git] / arch / cris / kernel / traps.c
bloba01636a12a6e87c46361591b69b1ebbaafb6728e
1 /*
2 * linux/arch/cris/traps.c
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.
8 * Copyright (C) 2000-2007 Axis Communications AB
10 * Authors: Bjorn Wesen
11 * Hans-Peter Nilsson
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
23 #include <asm/pgtable.h>
24 #include <linux/uaccess.h>
25 #include <arch/system.h>
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);
32 #ifdef CONFIG_DEBUG_BUGVERBOSE
33 extern void handle_BUG(struct pt_regs *regs);
34 #else
35 #define handle_BUG(regs)
36 #endif
38 static int kstack_depth_to_print = 24;
40 void (*nmi_handler)(struct pt_regs *);
42 void show_trace(unsigned long *stack)
44 unsigned long addr, module_start, module_end;
45 extern char _stext, _etext;
46 int i;
48 pr_err("\nCall Trace: ");
50 i = 1;
51 module_start = VMALLOC_START;
52 module_end = VMALLOC_END;
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;
62 stack++;
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.
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
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.
93 #define MODULE_RANGE (8*1024*1024)
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.
102 void
103 show_stack(struct task_struct *task, unsigned long *sp)
105 unsigned long *stack, addr;
106 int i;
109 * debugging aid: "show_stack(NULL);" prints a
110 * back trace.
113 if (sp == NULL) {
114 if (task)
115 sp = (unsigned long*)task->thread.ksp;
116 else
117 sp = (unsigned long*)rdsp();
120 stack = sp;
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;
135 stack++;
136 pr_err("%08lx ", addr);
138 show_trace(sp);
141 #if 0
142 /* displays a short stack trace */
145 show_stack(void)
147 unsigned long *sp = (unsigned long *)rdusp();
148 int i;
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;
155 #endif
157 void set_nmi_handler(void (*handler)(struct pt_regs *))
159 nmi_handler = handler;
160 arch_enable_nmi();
163 #ifdef CONFIG_DEBUG_NMI_OOPS
164 void oops_nmi_handler(struct pt_regs *regs)
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. */
175 static int __init oops_nmi_register(void)
177 set_nmi_handler(oops_nmi_handler);
178 return 0;
181 __initcall(oops_nmi_register);
183 #endif
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.
190 void watchdog_bite_hook(struct pt_regs *regs)
192 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
193 local_irq_disable();
194 stop_watchdog();
195 show_registers(regs);
197 while (1)
198 ; /* Do nothing. */
199 #else
200 show_registers(regs);
201 #endif
204 /* This is normally the Oops function. */
205 void die_if_kernel(const char *str, struct pt_regs *regs, long err)
207 if (user_mode(regs))
208 return;
210 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
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.
216 stop_watchdog();
217 #endif
219 oops_enter();
220 handle_BUG(regs);
222 pr_err("Linux %s %s\n", utsname()->release, utsname()->version);
223 pr_err("%s: %04lx\n", str, err & 0xffff);
225 show_registers(regs);
227 oops_exit();
228 oops_in_progress = 0;
229 pr_err("\n"); /* Flush mtdoops. */
231 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
232 reset_watchdog();
233 #endif
234 do_exit(SIGSEGV);
237 void __init trap_init(void)
239 /* Nothing needs to be done */