1 // SPDX-License-Identifier: GPL-2.0
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
9 * Copyright (C) 2000-2007 Axis Communications AB
11 * Authors: Bjorn Wesen
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>
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
);
36 #define handle_BUG(regs)
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
[];
49 pr_err("\nCall Trace: ");
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
);
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
79 if (i
&& ((i
% 8) == 0))
81 pr_err("[<%08lx>] ", addr
);
89 * These constants are for searching for possible module text
90 * segments. MODULE_RANGE is a guess of how much space is likely
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.
104 show_stack(struct task_struct
*task
, unsigned long *sp
)
106 unsigned long *stack
, addr
;
110 * debugging aid: "show_stack(NULL);" prints a
116 sp
= (unsigned long*)task
->thread
.ksp
;
118 sp
= (unsigned long*)rdsp();
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)
127 if (i
&& ((i
% 8) == 0))
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
);
137 pr_err("%08lx ", addr
);
143 /* displays a short stack trace */
148 unsigned long *sp
= (unsigned long *)rdusp();
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
]);
158 void set_nmi_handler(void (*handler
)(struct pt_regs
*))
160 nmi_handler
= handler
;
164 #ifdef CONFIG_DEBUG_NMI_OOPS
165 void oops_nmi_handler(struct pt_regs
*regs
)
168 oops_in_progress
= 1;
170 show_registers(regs
);
171 oops_in_progress
= 0;
173 pr_err("\n"); /* Flush mtdoops. */
176 static int __init
oops_nmi_register(void)
178 set_nmi_handler(oops_nmi_handler
);
182 __initcall(oops_nmi_register
);
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
196 show_registers(regs
);
201 show_registers(regs
);
205 /* This is normally the Oops function. */
206 void die_if_kernel(const char *str
, struct pt_regs
*regs
, long err
)
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.
223 pr_err("Linux %s %s\n", utsname()->release
, utsname()->version
);
224 pr_err("%s: %04lx\n", str
, err
& 0xffff);
226 show_registers(regs
);
229 oops_in_progress
= 0;
230 pr_err("\n"); /* Flush mtdoops. */
232 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
238 void __init
trap_init(void)
240 /* Nothing needs to be done */