Blame view

arch/cris/kernel/traps.c 5.12 KB
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
1
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
   *  linux/arch/cris/traps.c
   *
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
4
5
   *  Here we handle the break vectors not used by the system call
   *  mechanism, as well as some general stack/register dumping
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6
   *  things.
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
7
8
   *
   *  Copyright (C) 2000-2007 Axis Communications AB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
10
   *
   *  Authors:   Bjorn Wesen
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
11
   *             Hans-Peter Nilsson
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
12
13
14
15
16
   *
   */
  
  #include <linux/init.h>
  #include <linux/module.h>
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
17
18
19
20
  #include <linux/utsname.h>
  #ifdef CONFIG_KALLSYMS
  #include <linux/kallsyms.h>
  #endif
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
21

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
23
  #include <asm/pgtable.h>
  #include <asm/uaccess.h>
b1a154dbf   David Howells   Disintegrate asm/...
24
  #include <arch/system.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25

1ddba0257   Jesper Nilsson   CRIS: Minor gener...
26
27
28
29
30
31
32
33
34
35
  extern void arch_enable_nmi(void);
  extern void stop_watchdog(void);
  extern void reset_watchdog(void);
  extern void show_registers(struct pt_regs *regs);
  
  #ifdef CONFIG_DEBUG_BUGVERBOSE
  extern void handle_BUG(struct pt_regs *regs);
  #else
  #define handle_BUG(regs)
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
  static int kstack_depth_to_print = 24;
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
37
  void (*nmi_handler)(struct pt_regs *);
059163cab   Mikael Starvik   [PATCH] CRIS upda...
38

421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
39
  void show_trace(unsigned long *stack)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
42
43
  {
  	unsigned long addr, module_start, module_end;
  	extern char _stext, _etext;
  	int i;
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
44
45
  	pr_err("
  Call Trace: ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46

1ddba0257   Jesper Nilsson   CRIS: Minor gener...
47
48
49
  	i = 1;
  	module_start = VMALLOC_START;
  	module_end = VMALLOC_END;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50

421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
51
  	while (((long)stack & (THREAD_SIZE - 1)) != 0) {
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
52
  		if (__get_user(addr, stack)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
54
55
  			/* This message matches "failing address" marked
  			   s390 in ksymoops, so lines containing it will
  			   not be filtered out by ksymoops.  */
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
56
57
  			pr_err("Failing address 0x%lx
  ", (unsigned long)stack);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
58
59
60
  			break;
  		}
  		stack++;
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
61
62
63
64
65
66
67
68
69
70
71
  		/*
  		 * If the address is either in the text segment of the
  		 * kernel, or in the region which contains vmalloc'ed
  		 * memory, it *may* be the address of a calling
  		 * routine; if so, print it so that someone tracing
  		 * down the cause of the crash will be able to figure
  		 * out the call path that was taken.
  		 */
  		if (((addr >= (unsigned long)&_stext) &&
  		     (addr <= (unsigned long)&_etext)) ||
  		    ((addr >= module_start) && (addr <= module_end))) {
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
72
73
74
  #ifdef CONFIG_KALLSYMS
  			print_ip_sym(addr);
  #else
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
75
  			if (i && ((i % 8) == 0))
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
76
77
78
  				pr_err("
         ");
  			pr_err("[<%08lx>] ", addr);
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
79
  			i++;
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
80
  #endif
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
81
82
  		}
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  }
  
  /*
   * These constants are for searching for possible module text
   * segments. MODULE_RANGE is a guess of how much space is likely
   * to be vmalloced.
   */
  
  #define MODULE_RANGE (8*1024*1024)
  
  /*
   * The output (format, strings and order) is adjusted to be usable with
   * ksymoops-2.4.1 with some necessary CRIS-specific patches.  Please don't
   * change it unless you're serious about adjusting ksymoops and syncing
   * with the ksymoops maintainer.
   */
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
99
  void
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100
101
  show_stack(struct task_struct *task, unsigned long *sp)
  {
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
102
103
  	unsigned long *stack, addr;
  	int i;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
105
106
107
108
  
  	/*
  	 * debugging aid: "show_stack(NULL);" prints a
  	 * back trace.
  	 */
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
109
  	if (sp == NULL) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
111
112
113
114
  		if (task)
  			sp = (unsigned long*)task->thread.ksp;
  		else
  			sp = (unsigned long*)rdsp();
  	}
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
115
  	stack = sp;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
116

421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
117
118
119
  	pr_err("
  Stack from %08lx:
         ", (unsigned long)stack);
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
120
121
122
123
  	for (i = 0; i < kstack_depth_to_print; i++) {
  		if (((long)stack & (THREAD_SIZE-1)) == 0)
  			break;
  		if (i && ((i % 8) == 0))
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
124
125
  			pr_err("
         ");
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
126
  		if (__get_user(addr, stack)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127
128
129
  			/* This message matches "failing address" marked
  			   s390 in ksymoops, so lines containing it will
  			   not be filtered out by ksymoops.  */
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
130
131
  			pr_err("Failing address 0x%lx
  ", (unsigned long)stack);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
132
133
134
  			break;
  		}
  		stack++;
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
135
  		pr_err("%08lx ", addr);
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
136
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
137
138
  	show_trace(sp);
  }
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
139
140
  #if 0
  /* displays a short stack trace */
059163cab   Mikael Starvik   [PATCH] CRIS upda...
141

1ddba0257   Jesper Nilsson   CRIS: Minor gener...
142
143
  int
  show_stack(void)
059163cab   Mikael Starvik   [PATCH] CRIS upda...
144
  {
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
145
146
  	unsigned long *sp = (unsigned long *)rdusp();
  	int i;
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
147
148
  	pr_err("Stack dump [0x%08lx]:
  ", (unsigned long)sp);
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
149
  	for (i = 0; i < 16; i++)
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
150
151
  		pr_err("sp + %d: 0x%08lx
  ", i*4, sp[i]);
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
152
  	return 0;
059163cab   Mikael Starvik   [PATCH] CRIS upda...
153
  }
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
154
  #endif
059163cab   Mikael Starvik   [PATCH] CRIS upda...
155

421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
156
  void set_nmi_handler(void (*handler)(struct pt_regs *))
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
157
158
159
  {
  	nmi_handler = handler;
  	arch_enable_nmi();
059163cab   Mikael Starvik   [PATCH] CRIS upda...
160
161
162
  }
  
  #ifdef CONFIG_DEBUG_NMI_OOPS
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
163
  void oops_nmi_handler(struct pt_regs *regs)
059163cab   Mikael Starvik   [PATCH] CRIS upda...
164
  {
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
165
166
  	stop_watchdog();
  	oops_in_progress = 1;
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
167
168
  	pr_err("NMI!
  ");
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
169
170
  	show_registers(regs);
  	oops_in_progress = 0;
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
171
172
173
  	oops_exit();
  	pr_err("
  "); /* Flush mtdoops.  */
059163cab   Mikael Starvik   [PATCH] CRIS upda...
174
  }
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
175
  static int __init oops_nmi_register(void)
059163cab   Mikael Starvik   [PATCH] CRIS upda...
176
  {
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
177
178
  	set_nmi_handler(oops_nmi_handler);
  	return 0;
059163cab   Mikael Starvik   [PATCH] CRIS upda...
179
180
181
182
183
  }
  
  __initcall(oops_nmi_register);
  
  #endif
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
184
185
  /*
   * This gets called from entry.S when the watchdog has bitten. Show something
25985edce   Lucas De Marchi   Fix common misspe...
186
   * similar to an Oops dump, and if the kernel is configured to be a nice
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
187
188
   * doggy, then halt instead of reboot.
   */
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
189
  void watchdog_bite_hook(struct pt_regs *regs)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
190
  {
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
191
192
193
194
195
196
197
198
199
  #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
  	local_irq_disable();
  	stop_watchdog();
  	show_registers(regs);
  
  	while (1)
  		; /* Do nothing. */
  #else
  	show_registers(regs);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
200
  #endif
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
201
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
202

1ddba0257   Jesper Nilsson   CRIS: Minor gener...
203
  /* This is normally the Oops function. */
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
204
  void die_if_kernel(const char *str, struct pt_regs *regs, long err)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
205
  {
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
206
207
  	if (user_mode(regs))
  		return;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208

1ddba0257   Jesper Nilsson   CRIS: Minor gener...
209
210
211
212
213
214
215
216
  #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
  	/*
  	 * This printout might take too long and could trigger
  	 * the watchdog normally. If NICE_DOGGY is set, simply
  	 * stop the watchdog during the printout.
  	 */
  	stop_watchdog();
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
217

421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
218
  	oops_enter();
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
219
  	handle_BUG(regs);
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
220
221
222
223
  	pr_err("Linux %s %s
  ", utsname()->release, utsname()->version);
  	pr_err("%s: %04lx
  ", str, err & 0xffff);
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
224
225
  
  	show_registers(regs);
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
226
  	oops_exit();
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
227
  	oops_in_progress = 0;
421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
228
229
  	pr_err("
  "); /* Flush mtdoops.  */
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
230
231
232
233
234
  
  #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
  	reset_watchdog();
  #endif
  	do_exit(SIGSEGV);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
235
  }
059163cab   Mikael Starvik   [PATCH] CRIS upda...
236

421d08525   Jesper Nilsson   CRIS: Use KALLSYM...
237
  void __init trap_init(void)
059163cab   Mikael Starvik   [PATCH] CRIS upda...
238
  {
1ddba0257   Jesper Nilsson   CRIS: Minor gener...
239
  	/* Nothing needs to be done */
059163cab   Mikael Starvik   [PATCH] CRIS upda...
240
  }