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