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