Merge tag 'devicetree-fixes-for-4.15' of git://git.kernel.org/pub/scm/linux/kernel...
[sfrench/cifs-2.6.git] / arch / cris / kernel / traps.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *  linux/arch/cris/traps.c
4  *
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.
8  *
9  *  Copyright (C) 2000-2007 Axis Communications AB
10  *
11  *  Authors:   Bjorn Wesen
12  *             Hans-Peter Nilsson
13  *
14  */
15
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
23
24 #include <asm/pgtable.h>
25 #include <linux/uaccess.h>
26 #include <arch/system.h>
27
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
39 static int kstack_depth_to_print = 24;
40
41 void (*nmi_handler)(struct pt_regs *);
42
43 void show_trace(unsigned long *stack)
44 {
45         unsigned long addr, module_start, module_end;
46         extern char _stext[], _etext[];
47         int i;
48
49         pr_err("\nCall Trace: ");
50
51         i = 1;
52         module_start = VMALLOC_START;
53         module_end = VMALLOC_END;
54
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;
62                 }
63                 stack++;
64
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                  */
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
84                 }
85         }
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
103 void
104 show_stack(struct task_struct *task, unsigned long *sp)
105 {
106         unsigned long *stack, addr;
107         int i;
108
109         /*
110          * debugging aid: "show_stack(NULL);" prints a
111          * back trace.
112          */
113
114         if (sp == NULL) {
115                 if (task)
116                         sp = (unsigned long*)task->thread.ksp;
117                 else
118                         sp = (unsigned long*)rdsp();
119         }
120
121         stack = sp;
122
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;
135                 }
136                 stack++;
137                 pr_err("%08lx ", addr);
138         }
139         show_trace(sp);
140 }
141
142 #if 0
143 /* displays a short stack trace */
144
145 int
146 show_stack(void)
147 {
148         unsigned long *sp = (unsigned long *)rdusp();
149         int i;
150
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;
155 }
156 #endif
157
158 void set_nmi_handler(void (*handler)(struct pt_regs *))
159 {
160         nmi_handler = handler;
161         arch_enable_nmi();
162 }
163
164 #ifdef CONFIG_DEBUG_NMI_OOPS
165 void oops_nmi_handler(struct pt_regs *regs)
166 {
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.  */
174 }
175
176 static int __init oops_nmi_register(void)
177 {
178         set_nmi_handler(oops_nmi_handler);
179         return 0;
180 }
181
182 __initcall(oops_nmi_register);
183
184 #endif
185
186 /*
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.
190  */
191 void watchdog_bite_hook(struct pt_regs *regs)
192 {
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);
202 #endif
203 }
204
205 /* This is normally the Oops function. */
206 void die_if_kernel(const char *str, struct pt_regs *regs, long err)
207 {
208         if (user_mode(regs))
209                 return;
210
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
219
220         oops_enter();
221         handle_BUG(regs);
222
223         pr_err("Linux %s %s\n", utsname()->release, utsname()->version);
224         pr_err("%s: %04lx\n", str, err & 0xffff);
225
226         show_registers(regs);
227
228         oops_exit();
229         oops_in_progress = 0;
230         pr_err("\n"); /* Flush mtdoops.  */
231
232 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
233         reset_watchdog();
234 #endif
235         do_exit(SIGSEGV);
236 }
237
238 void __init trap_init(void)
239 {
240         /* Nothing needs to be done */
241 }