]>
Commit | Line | Data |
---|---|---|
1ddba025 | 1 | /* |
1da177e4 LT |
2 | * linux/arch/cris/traps.c |
3 | * | |
1ddba025 JN |
4 | * Here we handle the break vectors not used by the system call |
5 | * mechanism, as well as some general stack/register dumping | |
1da177e4 | 6 | * things. |
1ddba025 JN |
7 | * |
8 | * Copyright (C) 2000-2007 Axis Communications AB | |
1da177e4 LT |
9 | * |
10 | * Authors: Bjorn Wesen | |
1ddba025 | 11 | * Hans-Peter Nilsson |
1da177e4 LT |
12 | * |
13 | */ | |
14 | ||
15 | #include <linux/init.h> | |
16 | #include <linux/module.h> | |
421d0852 | 17 | #include <linux/utsname.h> |
b17b0153 | 18 | #include <linux/sched/debug.h> |
421d0852 JN |
19 | #ifdef CONFIG_KALLSYMS |
20 | #include <linux/kallsyms.h> | |
21 | #endif | |
1ddba025 | 22 | |
1da177e4 | 23 | #include <asm/pgtable.h> |
7c0f6ba6 | 24 | #include <linux/uaccess.h> |
b1a154db | 25 | #include <arch/system.h> |
1da177e4 | 26 | |
1ddba025 JN |
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 | ||
1da177e4 LT |
38 | static int kstack_depth_to_print = 24; |
39 | ||
1ddba025 | 40 | void (*nmi_handler)(struct pt_regs *); |
059163ca | 41 | |
421d0852 | 42 | void show_trace(unsigned long *stack) |
1da177e4 LT |
43 | { |
44 | unsigned long addr, module_start, module_end; | |
45 | extern char _stext, _etext; | |
46 | int i; | |
47 | ||
421d0852 | 48 | pr_err("\nCall Trace: "); |
1da177e4 | 49 | |
1ddba025 JN |
50 | i = 1; |
51 | module_start = VMALLOC_START; | |
52 | module_end = VMALLOC_END; | |
1da177e4 | 53 | |
421d0852 | 54 | while (((long)stack & (THREAD_SIZE - 1)) != 0) { |
1ddba025 | 55 | if (__get_user(addr, stack)) { |
1da177e4 LT |
56 | /* This message matches "failing address" marked |
57 | s390 in ksymoops, so lines containing it will | |
58 | not be filtered out by ksymoops. */ | |
421d0852 | 59 | pr_err("Failing address 0x%lx\n", (unsigned long)stack); |
1da177e4 LT |
60 | break; |
61 | } | |
62 | stack++; | |
63 | ||
1ddba025 JN |
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))) { | |
421d0852 JN |
75 | #ifdef CONFIG_KALLSYMS |
76 | print_ip_sym(addr); | |
77 | #else | |
1ddba025 | 78 | if (i && ((i % 8) == 0)) |
421d0852 JN |
79 | pr_err("\n "); |
80 | pr_err("[<%08lx>] ", addr); | |
1ddba025 | 81 | i++; |
421d0852 | 82 | #endif |
1ddba025 JN |
83 | } |
84 | } | |
1da177e4 LT |
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 | ||
1ddba025 | 102 | void |
1da177e4 LT |
103 | show_stack(struct task_struct *task, unsigned long *sp) |
104 | { | |
1ddba025 JN |
105 | unsigned long *stack, addr; |
106 | int i; | |
1da177e4 LT |
107 | |
108 | /* | |
109 | * debugging aid: "show_stack(NULL);" prints a | |
110 | * back trace. | |
111 | */ | |
112 | ||
1ddba025 | 113 | if (sp == NULL) { |
1da177e4 LT |
114 | if (task) |
115 | sp = (unsigned long*)task->thread.ksp; | |
116 | else | |
117 | sp = (unsigned long*)rdsp(); | |
118 | } | |
119 | ||
1ddba025 | 120 | stack = sp; |
1da177e4 | 121 | |
421d0852 | 122 | pr_err("\nStack from %08lx:\n ", (unsigned long)stack); |
1ddba025 JN |
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)) | |
421d0852 | 127 | pr_err("\n "); |
1ddba025 | 128 | if (__get_user(addr, stack)) { |
1da177e4 LT |
129 | /* This message matches "failing address" marked |
130 | s390 in ksymoops, so lines containing it will | |
131 | not be filtered out by ksymoops. */ | |
421d0852 | 132 | pr_err("Failing address 0x%lx\n", (unsigned long)stack); |
1da177e4 LT |
133 | break; |
134 | } | |
135 | stack++; | |
421d0852 | 136 | pr_err("%08lx ", addr); |
1ddba025 | 137 | } |
1da177e4 LT |
138 | show_trace(sp); |
139 | } | |
140 | ||
1ddba025 JN |
141 | #if 0 |
142 | /* displays a short stack trace */ | |
059163ca | 143 | |
1ddba025 JN |
144 | int |
145 | show_stack(void) | |
059163ca | 146 | { |
1ddba025 JN |
147 | unsigned long *sp = (unsigned long *)rdusp(); |
148 | int i; | |
149 | ||
421d0852 | 150 | pr_err("Stack dump [0x%08lx]:\n", (unsigned long)sp); |
1ddba025 | 151 | for (i = 0; i < 16; i++) |
421d0852 | 152 | pr_err("sp + %d: 0x%08lx\n", i*4, sp[i]); |
1ddba025 | 153 | return 0; |
059163ca | 154 | } |
1ddba025 | 155 | #endif |
059163ca | 156 | |
421d0852 | 157 | void set_nmi_handler(void (*handler)(struct pt_regs *)) |
1ddba025 JN |
158 | { |
159 | nmi_handler = handler; | |
160 | arch_enable_nmi(); | |
059163ca MS |
161 | } |
162 | ||
163 | #ifdef CONFIG_DEBUG_NMI_OOPS | |
421d0852 | 164 | void oops_nmi_handler(struct pt_regs *regs) |
059163ca | 165 | { |
1ddba025 JN |
166 | stop_watchdog(); |
167 | oops_in_progress = 1; | |
421d0852 | 168 | pr_err("NMI!\n"); |
1ddba025 JN |
169 | show_registers(regs); |
170 | oops_in_progress = 0; | |
421d0852 JN |
171 | oops_exit(); |
172 | pr_err("\n"); /* Flush mtdoops. */ | |
059163ca MS |
173 | } |
174 | ||
421d0852 | 175 | static int __init oops_nmi_register(void) |
059163ca | 176 | { |
1ddba025 JN |
177 | set_nmi_handler(oops_nmi_handler); |
178 | return 0; | |
059163ca MS |
179 | } |
180 | ||
181 | __initcall(oops_nmi_register); | |
182 | ||
183 | #endif | |
184 | ||
1ddba025 JN |
185 | /* |
186 | * This gets called from entry.S when the watchdog has bitten. Show something | |
25985edc | 187 | * similar to an Oops dump, and if the kernel is configured to be a nice |
1ddba025 JN |
188 | * doggy, then halt instead of reboot. |
189 | */ | |
421d0852 | 190 | void watchdog_bite_hook(struct pt_regs *regs) |
1da177e4 | 191 | { |
1ddba025 JN |
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); | |
1da177e4 | 201 | #endif |
1ddba025 | 202 | } |
1da177e4 | 203 | |
1ddba025 | 204 | /* This is normally the Oops function. */ |
421d0852 | 205 | void die_if_kernel(const char *str, struct pt_regs *regs, long err) |
1da177e4 | 206 | { |
1ddba025 JN |
207 | if (user_mode(regs)) |
208 | return; | |
1da177e4 | 209 | |
1ddba025 JN |
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 | |
1da177e4 | 218 | |
421d0852 | 219 | oops_enter(); |
1ddba025 JN |
220 | handle_BUG(regs); |
221 | ||
421d0852 JN |
222 | pr_err("Linux %s %s\n", utsname()->release, utsname()->version); |
223 | pr_err("%s: %04lx\n", str, err & 0xffff); | |
1ddba025 JN |
224 | |
225 | show_registers(regs); | |
226 | ||
421d0852 | 227 | oops_exit(); |
1ddba025 | 228 | oops_in_progress = 0; |
421d0852 | 229 | pr_err("\n"); /* Flush mtdoops. */ |
1ddba025 JN |
230 | |
231 | #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY | |
232 | reset_watchdog(); | |
233 | #endif | |
234 | do_exit(SIGSEGV); | |
1da177e4 | 235 | } |
059163ca | 236 | |
421d0852 | 237 | void __init trap_init(void) |
059163ca | 238 | { |
1ddba025 | 239 | /* Nothing needs to be done */ |
059163ca | 240 | } |