ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / cris / kernel / traps.c
1 /* $Id: traps.c,v 1.7 2003/07/04 08:27:52 starvik Exp $
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-2002 Axis Communications AB
10  *
11  *  Authors:   Bjorn Wesen
12  *             Hans-Peter Nilsson
13  *
14  */
15
16 #include <linux/init.h>
17 #include <asm/pgtable.h>
18 #include <asm/uaccess.h>
19
20 static int kstack_depth_to_print = 24;
21
22 void show_trace(unsigned long * stack)
23 {
24         unsigned long addr, module_start, module_end;
25         extern char _stext, _etext;
26         int i;
27
28         printk("\nCall Trace: ");
29
30         i = 1;
31         module_start = VMALLOC_START;
32         module_end = VMALLOC_END;
33
34         while (((long) stack & (THREAD_SIZE-1)) != 0) {
35                 if (__get_user (addr, stack)) {
36                         /* This message matches "failing address" marked
37                            s390 in ksymoops, so lines containing it will
38                            not be filtered out by ksymoops.  */
39                         printk ("Failing address 0x%lx\n", (unsigned long)stack);
40                         break;
41                 }
42                 stack++;
43
44                 /*
45                  * If the address is either in the text segment of the
46                  * kernel, or in the region which contains vmalloc'ed
47                  * memory, it *may* be the address of a calling
48                  * routine; if so, print it so that someone tracing
49                  * down the cause of the crash will be able to figure
50                  * out the call path that was taken.
51                  */
52                 if (((addr >= (unsigned long) &_stext) &&
53                      (addr <= (unsigned long) &_etext)) ||
54                     ((addr >= module_start) && (addr <= module_end))) {
55                         if (i && ((i % 8) == 0))
56                                 printk("\n       ");
57                         printk("[<%08lx>] ", addr);
58                         i++;
59                 }
60         }
61 }
62
63 /*
64  * These constants are for searching for possible module text
65  * segments. MODULE_RANGE is a guess of how much space is likely
66  * to be vmalloced.
67  */
68
69 #define MODULE_RANGE (8*1024*1024)
70
71 /*
72  * The output (format, strings and order) is adjusted to be usable with
73  * ksymoops-2.4.1 with some necessary CRIS-specific patches.  Please don't
74  * change it unless you're serious about adjusting ksymoops and syncing
75  * with the ksymoops maintainer.
76  */
77
78 void 
79 show_stack(struct task_struct *task, unsigned long *sp)
80 {
81         unsigned long *stack, addr;
82         int i;
83
84         /*
85          * debugging aid: "show_stack(NULL);" prints a
86          * back trace.
87          */
88
89         if(sp == NULL) {
90                 if (task)
91                         sp = (unsigned long*)task->thread.ksp;
92                 else
93                         sp = (unsigned long*)rdsp();
94         }
95
96         stack = sp;
97
98         printk("\nStack from %08lx:\n       ", (unsigned long)stack);
99         for(i = 0; i < kstack_depth_to_print; i++) {
100                 if (((long) stack & (THREAD_SIZE-1)) == 0)
101                         break;
102                 if (i && ((i % 8) == 0))
103                         printk("\n       ");
104                 if (__get_user (addr, stack)) {
105                         /* This message matches "failing address" marked
106                            s390 in ksymoops, so lines containing it will
107                            not be filtered out by ksymoops.  */
108                         printk ("Failing address 0x%lx\n", (unsigned long)stack);
109                         break;
110                 }
111                 stack++;
112                 printk("%08lx ", addr);
113         }
114         show_trace(sp);
115 }
116
117 #if 0
118 /* displays a short stack trace */
119
120 int 
121 show_stack()
122 {
123         unsigned long *sp = (unsigned long *)rdusp();
124         int i;
125         printk("Stack dump [0x%08lx]:\n", (unsigned long)sp);
126         for(i = 0; i < 16; i++)
127                 printk("sp + %d: 0x%08lx\n", i*4, sp[i]);
128         return 0;
129 }
130 #endif
131
132 void dump_stack(void)
133 {
134         show_stack(NULL, NULL);
135 }
136
137 EXPORT_SYMBOL(dump_stack);
138
139 void __init 
140 trap_init(void)
141 {
142         /* Nothing needs to be done */
143 }