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