diff options
Diffstat (limited to 'arch/m32r/kernel/traps.c')
-rw-r--r-- | arch/m32r/kernel/traps.c | 332 |
1 files changed, 332 insertions, 0 deletions
diff --git a/arch/m32r/kernel/traps.c b/arch/m32r/kernel/traps.c new file mode 100644 index 000000000000..01922271d17e --- /dev/null +++ b/arch/m32r/kernel/traps.c | |||
@@ -0,0 +1,332 @@ | |||
1 | /* | ||
2 | * linux/arch/m32r/kernel/traps.c | ||
3 | * | ||
4 | * Copyright (C) 2001, 2002 Hirokazu Takata, Hiroyuki Kondo, | ||
5 | * Hitoshi Yamamoto | ||
6 | */ | ||
7 | |||
8 | /* $Id$ */ | ||
9 | |||
10 | /* | ||
11 | * 'traps.c' handles hardware traps and faults after we have saved some | ||
12 | * state in 'entry.S'. | ||
13 | */ | ||
14 | #include <linux/config.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/kallsyms.h> | ||
18 | #include <linux/stddef.h> | ||
19 | #include <linux/ptrace.h> | ||
20 | #include <linux/mm.h> | ||
21 | #include <asm/page.h> | ||
22 | #include <asm/processor.h> | ||
23 | |||
24 | #include <asm/system.h> | ||
25 | #include <asm/uaccess.h> | ||
26 | #include <asm/io.h> | ||
27 | #include <asm/atomic.h> | ||
28 | |||
29 | #include <asm/smp.h> | ||
30 | |||
31 | #include <linux/module.h> | ||
32 | |||
33 | asmlinkage void alignment_check(void); | ||
34 | asmlinkage void ei_handler(void); | ||
35 | asmlinkage void rie_handler(void); | ||
36 | asmlinkage void debug_trap(void); | ||
37 | asmlinkage void cache_flushing_handler(void); | ||
38 | |||
39 | #ifdef CONFIG_SMP | ||
40 | extern void smp_reschedule_interrupt(void); | ||
41 | extern void smp_invalidate_interrupt(void); | ||
42 | extern void smp_call_function_interrupt(void); | ||
43 | extern void smp_ipi_timer_interrupt(void); | ||
44 | extern void smp_flush_cache_all_interrupt(void); | ||
45 | |||
46 | /* | ||
47 | * for Boot AP function | ||
48 | */ | ||
49 | asm ( | ||
50 | " .section .eit_vector4,\"ax\" \n" | ||
51 | " .global _AP_RE \n" | ||
52 | " .global startup_AP \n" | ||
53 | "_AP_RE: \n" | ||
54 | " .fill 32, 4, 0 \n" | ||
55 | "_AP_EI: bra startup_AP \n" | ||
56 | " .previous \n" | ||
57 | ); | ||
58 | #endif /* CONFIG_SMP */ | ||
59 | |||
60 | extern unsigned long eit_vector[]; | ||
61 | #define BRA_INSN(func, entry) \ | ||
62 | ((unsigned long)func - (unsigned long)eit_vector - entry*4)/4 \ | ||
63 | + 0xff000000UL | ||
64 | |||
65 | void set_eit_vector_entries(void) | ||
66 | { | ||
67 | extern void default_eit_handler(void); | ||
68 | extern void system_call(void); | ||
69 | extern void pie_handler(void); | ||
70 | extern void ace_handler(void); | ||
71 | extern void tme_handler(void); | ||
72 | extern void _flush_cache_copyback_all(void); | ||
73 | |||
74 | eit_vector[0] = 0xd0c00001; /* seth r0, 0x01 */ | ||
75 | eit_vector[1] = BRA_INSN(default_eit_handler, 1); | ||
76 | eit_vector[4] = 0xd0c00010; /* seth r0, 0x10 */ | ||
77 | eit_vector[5] = BRA_INSN(default_eit_handler, 5); | ||
78 | eit_vector[8] = BRA_INSN(rie_handler, 8); | ||
79 | eit_vector[12] = BRA_INSN(alignment_check, 12); | ||
80 | eit_vector[16] = 0xff000000UL; | ||
81 | eit_vector[17] = BRA_INSN(debug_trap, 17); | ||
82 | eit_vector[18] = BRA_INSN(system_call, 18); | ||
83 | eit_vector[19] = 0xff000000UL; | ||
84 | eit_vector[20] = 0xff000000UL; | ||
85 | eit_vector[21] = 0xff000000UL; | ||
86 | eit_vector[22] = 0xff000000UL; | ||
87 | eit_vector[23] = 0xff000000UL; | ||
88 | eit_vector[24] = 0xff000000UL; | ||
89 | eit_vector[25] = 0xff000000UL; | ||
90 | eit_vector[26] = 0xff000000UL; | ||
91 | eit_vector[27] = 0xff000000UL; | ||
92 | eit_vector[28] = BRA_INSN(cache_flushing_handler, 28); | ||
93 | eit_vector[29] = 0xff000000UL; | ||
94 | eit_vector[30] = 0xff000000UL; | ||
95 | eit_vector[31] = 0xff000000UL; | ||
96 | eit_vector[32] = BRA_INSN(ei_handler, 32); | ||
97 | eit_vector[64] = BRA_INSN(pie_handler, 64); | ||
98 | #ifdef CONFIG_MMU | ||
99 | eit_vector[68] = BRA_INSN(ace_handler, 68); | ||
100 | eit_vector[72] = BRA_INSN(tme_handler, 72); | ||
101 | #endif /* CONFIG_MMU */ | ||
102 | #ifdef CONFIG_SMP | ||
103 | eit_vector[184] = (unsigned long)smp_reschedule_interrupt; | ||
104 | eit_vector[185] = (unsigned long)smp_invalidate_interrupt; | ||
105 | eit_vector[186] = (unsigned long)smp_call_function_interrupt; | ||
106 | eit_vector[187] = (unsigned long)smp_ipi_timer_interrupt; | ||
107 | eit_vector[188] = (unsigned long)smp_flush_cache_all_interrupt; | ||
108 | eit_vector[189] = 0; | ||
109 | eit_vector[190] = 0; | ||
110 | eit_vector[191] = 0; | ||
111 | #endif | ||
112 | _flush_cache_copyback_all(); | ||
113 | } | ||
114 | |||
115 | void __init trap_init(void) | ||
116 | { | ||
117 | set_eit_vector_entries(); | ||
118 | |||
119 | /* | ||
120 | * Should be a barrier for any external CPU state. | ||
121 | */ | ||
122 | cpu_init(); | ||
123 | } | ||
124 | |||
125 | int kstack_depth_to_print = 24; | ||
126 | |||
127 | void show_trace(struct task_struct *task, unsigned long *stack) | ||
128 | { | ||
129 | unsigned long addr; | ||
130 | |||
131 | if (!stack) | ||
132 | stack = (unsigned long*)&stack; | ||
133 | |||
134 | printk("Call Trace: "); | ||
135 | while (!kstack_end(stack)) { | ||
136 | addr = *stack++; | ||
137 | if (__kernel_text_address(addr)) { | ||
138 | printk("[<%08lx>] ", addr); | ||
139 | print_symbol("%s\n", addr); | ||
140 | } | ||
141 | } | ||
142 | printk("\n"); | ||
143 | } | ||
144 | |||
145 | void show_stack(struct task_struct *task, unsigned long *sp) | ||
146 | { | ||
147 | unsigned long *stack; | ||
148 | int i; | ||
149 | |||
150 | /* | ||
151 | * debugging aid: "show_stack(NULL);" prints the | ||
152 | * back trace for this cpu. | ||
153 | */ | ||
154 | |||
155 | if(sp==NULL) { | ||
156 | if (task) | ||
157 | sp = (unsigned long *)task->thread.sp; | ||
158 | else | ||
159 | sp=(unsigned long*)&sp; | ||
160 | } | ||
161 | |||
162 | stack = sp; | ||
163 | for(i=0; i < kstack_depth_to_print; i++) { | ||
164 | if (kstack_end(stack)) | ||
165 | break; | ||
166 | if (i && ((i % 4) == 0)) | ||
167 | printk("\n "); | ||
168 | printk("%08lx ", *stack++); | ||
169 | } | ||
170 | printk("\n"); | ||
171 | show_trace(task, sp); | ||
172 | } | ||
173 | |||
174 | void dump_stack(void) | ||
175 | { | ||
176 | unsigned long stack; | ||
177 | |||
178 | show_trace(current, &stack); | ||
179 | } | ||
180 | |||
181 | EXPORT_SYMBOL(dump_stack); | ||
182 | |||
183 | static void show_registers(struct pt_regs *regs) | ||
184 | { | ||
185 | int i = 0; | ||
186 | int in_kernel = 1; | ||
187 | unsigned long sp; | ||
188 | |||
189 | printk("CPU: %d\n", smp_processor_id()); | ||
190 | show_regs(regs); | ||
191 | |||
192 | sp = (unsigned long) (1+regs); | ||
193 | if (user_mode(regs)) { | ||
194 | in_kernel = 0; | ||
195 | sp = regs->spu; | ||
196 | printk("SPU: %08lx\n", sp); | ||
197 | } else { | ||
198 | printk("SPI: %08lx\n", sp); | ||
199 | } | ||
200 | printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)", | ||
201 | current->comm, current->pid, 0xffff & i, 4096+(unsigned long)current); | ||
202 | |||
203 | /* | ||
204 | * When in-kernel, we also print out the stack and code at the | ||
205 | * time of the fault.. | ||
206 | */ | ||
207 | if (in_kernel) { | ||
208 | printk("\nStack: "); | ||
209 | show_stack(current, (unsigned long*) sp); | ||
210 | |||
211 | printk("\nCode: "); | ||
212 | if (regs->bpc < PAGE_OFFSET) | ||
213 | goto bad; | ||
214 | |||
215 | for(i=0;i<20;i++) { | ||
216 | unsigned char c; | ||
217 | if (__get_user(c, &((unsigned char*)regs->bpc)[i])) { | ||
218 | bad: | ||
219 | printk(" Bad PC value."); | ||
220 | break; | ||
221 | } | ||
222 | printk("%02x ", c); | ||
223 | } | ||
224 | } | ||
225 | printk("\n"); | ||
226 | } | ||
227 | |||
228 | DEFINE_SPINLOCK(die_lock); | ||
229 | |||
230 | void die(const char * str, struct pt_regs * regs, long err) | ||
231 | { | ||
232 | console_verbose(); | ||
233 | spin_lock_irq(&die_lock); | ||
234 | bust_spinlocks(1); | ||
235 | printk("%s: %04lx\n", str, err & 0xffff); | ||
236 | show_registers(regs); | ||
237 | bust_spinlocks(0); | ||
238 | spin_unlock_irq(&die_lock); | ||
239 | do_exit(SIGSEGV); | ||
240 | } | ||
241 | |||
242 | static __inline__ void die_if_kernel(const char * str, | ||
243 | struct pt_regs * regs, long err) | ||
244 | { | ||
245 | if (!user_mode(regs)) | ||
246 | die(str, regs, err); | ||
247 | } | ||
248 | |||
249 | static __inline__ void do_trap(int trapnr, int signr, const char * str, | ||
250 | struct pt_regs * regs, long error_code, siginfo_t *info) | ||
251 | { | ||
252 | if (user_mode(regs)) { | ||
253 | /* trap_signal */ | ||
254 | struct task_struct *tsk = current; | ||
255 | tsk->thread.error_code = error_code; | ||
256 | tsk->thread.trap_no = trapnr; | ||
257 | if (info) | ||
258 | force_sig_info(signr, info, tsk); | ||
259 | else | ||
260 | force_sig(signr, tsk); | ||
261 | return; | ||
262 | } else { | ||
263 | /* kernel_trap */ | ||
264 | if (!fixup_exception(regs)) | ||
265 | die(str, regs, error_code); | ||
266 | return; | ||
267 | } | ||
268 | } | ||
269 | |||
270 | #define DO_ERROR(trapnr, signr, str, name) \ | ||
271 | asmlinkage void do_##name(struct pt_regs * regs, long error_code) \ | ||
272 | { \ | ||
273 | do_trap(trapnr, signr, 0, regs, error_code, NULL); \ | ||
274 | } | ||
275 | |||
276 | #define DO_ERROR_INFO(trapnr, signr, str, name, sicode, siaddr) \ | ||
277 | asmlinkage void do_##name(struct pt_regs * regs, long error_code) \ | ||
278 | { \ | ||
279 | siginfo_t info; \ | ||
280 | info.si_signo = signr; \ | ||
281 | info.si_errno = 0; \ | ||
282 | info.si_code = sicode; \ | ||
283 | info.si_addr = (void __user *)siaddr; \ | ||
284 | do_trap(trapnr, signr, str, regs, error_code, &info); \ | ||
285 | } | ||
286 | |||
287 | DO_ERROR( 1, SIGTRAP, "debug trap", debug_trap) | ||
288 | DO_ERROR_INFO(0x20, SIGILL, "reserved instruction ", rie_handler, ILL_ILLOPC, regs->bpc) | ||
289 | DO_ERROR_INFO(0x100, SIGILL, "privilege instruction", pie_handler, ILL_PRVOPC, regs->bpc) | ||
290 | |||
291 | extern int handle_unaligned_access(unsigned long, struct pt_regs *); | ||
292 | |||
293 | /* This code taken from arch/sh/kernel/traps.c */ | ||
294 | asmlinkage void do_alignment_check(struct pt_regs *regs, long error_code) | ||
295 | { | ||
296 | mm_segment_t oldfs; | ||
297 | unsigned long insn; | ||
298 | int tmp; | ||
299 | |||
300 | oldfs = get_fs(); | ||
301 | |||
302 | if (user_mode(regs)) { | ||
303 | local_irq_enable(); | ||
304 | current->thread.error_code = error_code; | ||
305 | current->thread.trap_no = 0x17; | ||
306 | |||
307 | set_fs(USER_DS); | ||
308 | if (copy_from_user(&insn, (void *)regs->bpc, 4)) { | ||
309 | set_fs(oldfs); | ||
310 | goto uspace_segv; | ||
311 | } | ||
312 | tmp = handle_unaligned_access(insn, regs); | ||
313 | set_fs(oldfs); | ||
314 | |||
315 | if (!tmp) | ||
316 | return; | ||
317 | |||
318 | uspace_segv: | ||
319 | printk(KERN_NOTICE "Killing process \"%s\" due to unaligned " | ||
320 | "access\n", current->comm); | ||
321 | force_sig(SIGSEGV, current); | ||
322 | } else { | ||
323 | set_fs(KERNEL_DS); | ||
324 | if (copy_from_user(&insn, (void *)regs->bpc, 4)) { | ||
325 | set_fs(oldfs); | ||
326 | die("insn faulting in do_address_error", regs, 0); | ||
327 | } | ||
328 | handle_unaligned_access(insn, regs); | ||
329 | set_fs(oldfs); | ||
330 | } | ||
331 | } | ||
332 | |||