2 * linux/arch/cris/traps.c
4 * Here we handle the break vectors not used by the system call
5 * mechanism, as well as some general stack/register dumping
8 * Copyright (C) 2000, 2001, 2002, 2003 Axis Communications AB
10 * Authors: Bjorn Wesen
15 #include <linux/init.h>
16 #include <linux/sched.h>
17 #include <linux/kernel.h>
18 #include <linux/string.h>
19 #include <linux/errno.h>
20 #include <linux/ptrace.h>
21 #include <linux/timer.h>
23 #include <asm/uaccess.h>
25 #include <asm/system.h>
26 #include <asm/segment.h>
28 #include <asm/pgtable.h>
30 int kstack_depth_to_print = 24;
32 void show_trace(unsigned long * stack)
34 unsigned long addr, module_start, module_end;
35 extern char _stext, _etext;
38 printk("\nCall Trace: ");
41 module_start = VMALLOC_START;
42 module_end = VMALLOC_END;
44 while (((long) stack & (THREAD_SIZE-1)) != 0) {
45 if (__get_user (addr, stack)) {
46 /* This message matches "failing address" marked
47 s390 in ksymoops, so lines containing it will
48 not be filtered out by ksymoops. */
49 printk ("Failing address 0x%lx\n", (unsigned long)stack);
55 * If the address is either in the text segment of the
56 * kernel, or in the region which contains vmalloc'ed
57 * memory, it *may* be the address of a calling
58 * routine; if so, print it so that someone tracing
59 * down the cause of the crash will be able to figure
60 * out the call path that was taken.
62 if (((addr >= (unsigned long) &_stext) &&
63 (addr <= (unsigned long) &_etext)) ||
64 ((addr >= module_start) && (addr <= module_end))) {
65 if (i && ((i % 8) == 0))
67 printk("[<%08lx>] ", addr);
73 void show_trace_task(struct task_struct *tsk)
75 /* TODO, this is not really useful since its called from
76 * SysRq-T and we don't have a keyboard.. :)
82 * These constants are for searching for possible module text
83 * segments. MODULE_RANGE is a guess of how much space is likely
87 #define MODULE_RANGE (8*1024*1024)
90 * The output (format, strings and order) is adjusted to be usable with
91 * ksymoops-2.4.1 with some necessary CRIS-specific patches. Please don't
92 * change it unless you're serious about adjusting ksymoops and syncing
93 * with the ksymoops maintainer.
97 show_stack(unsigned long *sp)
99 unsigned long *stack, addr;
103 * debugging aid: "show_stack(NULL);" prints a
108 sp = (unsigned long*)rdsp();
112 printk("\nStack from %08lx:\n ", (unsigned long)stack);
113 for(i = 0; i < kstack_depth_to_print; i++) {
114 if (((long) stack & (THREAD_SIZE-1)) == 0)
116 if (i && ((i % 8) == 0))
118 if (__get_user (addr, stack)) {
119 /* This message matches "failing address" marked
120 s390 in ksymoops, so lines containing it will
121 not be filtered out by ksymoops. */
122 printk ("Failing address 0x%lx\n", (unsigned long)stack);
126 printk("%08lx ", addr);
132 /* displays a short stack trace */
137 unsigned long *sp = (unsigned long *)rdusp();
139 printk("Stack dump [0x%08lx]:\n", (unsigned long)sp);
140 for(i = 0; i < 16; i++)
141 printk("sp + %d: 0x%08lx\n", i*4, sp[i]);
147 show_registers(struct pt_regs * regs)
149 /* We either use rdusp() - the USP register, which might not
150 correspond to the current process for all cases we're called,
151 or we use the current->thread.usp, which is not up to date for
152 the current process. Experience shows we want the USP
154 unsigned long usp = rdusp();
156 printk("IRP: %08lx SRP: %08lx DCCR: %08lx USP: %08lx MOF: %08lx\n",
157 regs->irp, regs->srp, regs->dccr, usp, regs->mof );
158 printk(" r0: %08lx r1: %08lx r2: %08lx r3: %08lx\n",
159 regs->r0, regs->r1, regs->r2, regs->r3);
160 printk(" r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",
161 regs->r4, regs->r5, regs->r6, regs->r7);
162 printk(" r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",
163 regs->r8, regs->r9, regs->r10, regs->r11);
164 printk("r12: %08lx r13: %08lx oR10: %08lx\n",
165 regs->r12, regs->r13, regs->orig_r10);
166 printk("R_MMU_CAUSE: %08lx\n", (unsigned long)*R_MMU_CAUSE);
167 printk("Process %s (pid: %d, stackpage=%08lx)\n",
168 current->comm, current->pid, (unsigned long)current);
171 * When in-kernel, we also print out the stack and code at the
172 * time of the fault..
174 if (! user_mode(regs)) {
177 show_stack((unsigned long*)usp);
179 /* Dump kernel stack if the previous dump wasn't one. */
184 if(regs->irp < PAGE_OFFSET)
187 /* Often enough the value at regs->irp does not point to
188 the interesting instruction, which is most often the
189 _previous_ instruction. So we dump at an offset large
190 enough that instruction decoding should be in sync at
191 the interesting point, but small enough to fit on a row
192 (sort of). We point out the regs->irp location in a
193 ksymoops-friendly way by wrapping the byte for that
194 address in parentheses. */
195 for(i = -12; i < 12; i++)
198 if(__get_user(c, &((unsigned char*)regs->irp)[i])) {
200 printk(" Bad IP value.");
205 printk("(%02x) ", c);
213 /* Called from entry.S when the watchdog has bitten
214 * We print out something resembling an oops dump, and if
215 * we have the nice doggy development flag set, we halt here
216 * instead of rebooting.
218 extern void reset_watchdog(void);
219 extern void stop_watchdog(void);
222 watchdog_bite_hook(struct pt_regs *regs)
224 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
227 show_registers(regs);
228 while(1) /* nothing */;
230 show_registers(regs);
234 void dump_stack(void)
239 /* This is normally the 'Oops' routine */
241 die_if_kernel(const char * str, struct pt_regs * regs, long err)
246 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
247 /* This printout might take too long and trigger the
248 * watchdog normally. If we're in the nice doggy
249 * development mode, stop the watchdog during printout.
254 printk("%s: %04lx\n", str, err & 0xffff);
256 show_registers(regs);
258 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
267 /* Nothing needs to be done */