Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / cris / kernel / traps.c
blobd4bc80469218b60662e9ef293cfebb29f6dce6b6
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * linux/arch/cris/traps.c
5 * Here we handle the break vectors not used by the system call
6 * mechanism, as well as some general stack/register dumping
7 * things.
9 * Copyright (C) 2000-2007 Axis Communications AB
11 * Authors: Bjorn Wesen
12 * Hans-Peter Nilsson
16 #include <linux/init.h>
17 #include <linux/module.h>
18 #include <linux/utsname.h>
19 #include <linux/sched/debug.h>
20 #ifdef CONFIG_KALLSYMS
21 #include <linux/kallsyms.h>
22 #endif
24 #include <asm/pgtable.h>
25 #include <linux/uaccess.h>
26 #include <arch/system.h>
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);
33 #ifdef CONFIG_DEBUG_BUGVERBOSE
34 extern void handle_BUG(struct pt_regs *regs);
35 #else
36 #define handle_BUG(regs)
37 #endif
39 static int kstack_depth_to_print = 24;
41 void (*nmi_handler)(struct pt_regs *);
43 void show_trace(unsigned long *stack)
45 unsigned long addr, module_start, module_end;
46 extern char _stext[], _etext[];
47 int i;
49 pr_err("\nCall Trace: ");
51 i = 1;
52 module_start = VMALLOC_START;
53 module_end = VMALLOC_END;
55 while (((long)stack & (THREAD_SIZE - 1)) != 0) {
56 if (__get_user(addr, stack)) {
57 /* This message matches "failing address" marked
58 s390 in ksymoops, so lines containing it will
59 not be filtered out by ksymoops. */
60 pr_err("Failing address 0x%lx\n", (unsigned long)stack);
61 break;
63 stack++;
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.
73 if (((addr >= (unsigned long)_stext) &&
74 (addr <= (unsigned long)_etext)) ||
75 ((addr >= module_start) && (addr <= module_end))) {
76 #ifdef CONFIG_KALLSYMS
77 print_ip_sym(addr);
78 #else
79 if (i && ((i % 8) == 0))
80 pr_err("\n ");
81 pr_err("[<%08lx>] ", addr);
82 i++;
83 #endif
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.
94 #define MODULE_RANGE (8*1024*1024)
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.
103 void
104 show_stack(struct task_struct *task, unsigned long *sp)
106 unsigned long *stack, addr;
107 int i;
110 * debugging aid: "show_stack(NULL);" prints a
111 * back trace.
114 if (sp == NULL) {
115 if (task)
116 sp = (unsigned long*)task->thread.ksp;
117 else
118 sp = (unsigned long*)rdsp();
121 stack = sp;
123 pr_err("\nStack from %08lx:\n ", (unsigned long)stack);
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))
128 pr_err("\n ");
129 if (__get_user(addr, stack)) {
130 /* This message matches "failing address" marked
131 s390 in ksymoops, so lines containing it will
132 not be filtered out by ksymoops. */
133 pr_err("Failing address 0x%lx\n", (unsigned long)stack);
134 break;
136 stack++;
137 pr_err("%08lx ", addr);
139 show_trace(sp);
142 #if 0
143 /* displays a short stack trace */
146 show_stack(void)
148 unsigned long *sp = (unsigned long *)rdusp();
149 int i;
151 pr_err("Stack dump [0x%08lx]:\n", (unsigned long)sp);
152 for (i = 0; i < 16; i++)
153 pr_err("sp + %d: 0x%08lx\n", i*4, sp[i]);
154 return 0;
156 #endif
158 void set_nmi_handler(void (*handler)(struct pt_regs *))
160 nmi_handler = handler;
161 arch_enable_nmi();
164 #ifdef CONFIG_DEBUG_NMI_OOPS
165 void oops_nmi_handler(struct pt_regs *regs)
167 stop_watchdog();
168 oops_in_progress = 1;
169 pr_err("NMI!\n");
170 show_registers(regs);
171 oops_in_progress = 0;
172 oops_exit();
173 pr_err("\n"); /* Flush mtdoops. */
176 static int __init oops_nmi_register(void)
178 set_nmi_handler(oops_nmi_handler);
179 return 0;
182 __initcall(oops_nmi_register);
184 #endif
187 * This gets called from entry.S when the watchdog has bitten. Show something
188 * similar to an Oops dump, and if the kernel is configured to be a nice
189 * doggy, then halt instead of reboot.
191 void watchdog_bite_hook(struct pt_regs *regs)
193 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
194 local_irq_disable();
195 stop_watchdog();
196 show_registers(regs);
198 while (1)
199 ; /* Do nothing. */
200 #else
201 show_registers(regs);
202 #endif
205 /* This is normally the Oops function. */
206 void die_if_kernel(const char *str, struct pt_regs *regs, long err)
208 if (user_mode(regs))
209 return;
211 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
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.
217 stop_watchdog();
218 #endif
220 oops_enter();
221 handle_BUG(regs);
223 pr_err("Linux %s %s\n", utsname()->release, utsname()->version);
224 pr_err("%s: %04lx\n", str, err & 0xffff);
226 show_registers(regs);
228 oops_exit();
229 oops_in_progress = 0;
230 pr_err("\n"); /* Flush mtdoops. */
232 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
233 reset_watchdog();
234 #endif
235 do_exit(SIGSEGV);
238 void __init trap_init(void)
240 /* Nothing needs to be done */