2 * arch/sparc/kernel/traps.c
9 * I hate traps on the sparc, grrr...
12 #include <linux/sched.h> /* for jiffies */
13 #include <linux/kernel.h>
14 #include <linux/signal.h>
15 #include <linux/smp.h>
16 #include <linux/kdebug.h>
17 #include <linux/export.h>
19 #include <asm/delay.h>
20 #include <asm/ptrace.h>
21 #include <asm/oplib.h>
23 #include <asm/pgtable.h>
24 #include <asm/unistd.h>
25 #include <asm/traps.h>
30 /* #define TRAP_DEBUG */
32 static void instruction_dump(unsigned long *pc)
36 if((((unsigned long) pc) & 3))
39 for(i = -3; i < 6; i++)
40 printk("%c%08lx%c",i?' ':'<',pc[i],i?' ':'>');
44 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
45 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
47 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
49 static int die_counter;
59 printk("%s(%d): %s [#%d]\n", current->comm, task_pid_nr(current), str, ++die_counter);
61 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
63 __SAVE; __SAVE; __SAVE; __SAVE;
64 __SAVE; __SAVE; __SAVE; __SAVE;
65 __RESTORE; __RESTORE; __RESTORE; __RESTORE;
66 __RESTORE; __RESTORE; __RESTORE; __RESTORE;
69 struct reg_window32 *rw = (struct reg_window32 *)regs->u_regs[UREG_FP];
71 /* Stop the back trace when we hit userland or we
72 * find some badly aligned kernel stack. Set an upper
73 * bound in case our stack is trashed and we loop.
77 (((unsigned long) rw) >= PAGE_OFFSET) &&
78 !(((unsigned long) rw) & 0x7)) {
79 printk("Caller[%08lx]: %pS\n", rw->ins[7],
81 rw = (struct reg_window32 *)rw->ins[6];
84 printk("Instruction DUMP:");
85 instruction_dump ((unsigned long *) regs->pc);
86 if(regs->psr & PSR_PS)
91 void do_hw_interrupt(struct pt_regs *regs, unsigned long type)
96 /* Sun OS's puke from bad traps, Linux survives! */
97 printk("Unimplemented Sparc TRAP, type = %02lx\n", type);
98 die_if_kernel("Whee... Hello Mr. Penguin", regs);
101 if(regs->psr & PSR_PS)
102 die_if_kernel("Kernel bad trap", regs);
104 info.si_signo = SIGILL;
106 info.si_code = ILL_ILLTRP;
107 info.si_addr = (void __user *)regs->pc;
108 info.si_trapno = type - 0x80;
109 force_sig_info(SIGILL, &info, current);
112 void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
118 die_if_kernel("Kernel illegal instruction", regs);
120 printk("Ill instr. at pc=%08lx instruction is %08lx\n",
121 regs->pc, *(unsigned long *)regs->pc);
124 info.si_signo = SIGILL;
126 info.si_code = ILL_ILLOPC;
127 info.si_addr = (void __user *)pc;
129 send_sig_info(SIGILL, &info, current);
132 void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
138 die_if_kernel("Penguin instruction from Penguin mode??!?!", regs);
139 info.si_signo = SIGILL;
141 info.si_code = ILL_PRVOPC;
142 info.si_addr = (void __user *)pc;
144 send_sig_info(SIGILL, &info, current);
147 /* XXX User may want to be allowed to do this. XXX */
149 void do_memaccess_unaligned(struct pt_regs *regs, unsigned long pc, unsigned long npc,
154 if(regs->psr & PSR_PS) {
155 printk("KERNEL MNA at pc %08lx npc %08lx called by %08lx\n", pc, npc,
156 regs->u_regs[UREG_RETPC]);
157 die_if_kernel("BOGUS", regs);
158 /* die_if_kernel("Kernel MNA access", regs); */
162 instruction_dump ((unsigned long *) regs->pc);
163 printk ("do_MNA!\n");
165 info.si_signo = SIGBUS;
167 info.si_code = BUS_ADRALN;
168 info.si_addr = /* FIXME: Should dig out mna address */ (void *)0;
170 send_sig_info(SIGBUS, &info, current);
173 static unsigned long init_fsr = 0x0UL;
174 static unsigned long init_fregs[32] __attribute__ ((aligned (8))) =
175 { ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
176 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
177 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
178 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL };
180 void do_fpd_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,
183 /* Sanity check... */
185 die_if_kernel("Kernel gets FloatingPenguinUnit disabled trap", regs);
187 put_psr(get_psr() | PSR_EF); /* Allow FPU ops. */
190 if(last_task_used_math == current)
192 if(last_task_used_math) {
193 /* Other processes fpu state, save away */
194 struct task_struct *fptask = last_task_used_math;
195 fpsave(&fptask->thread.float_regs[0], &fptask->thread.fsr,
196 &fptask->thread.fpqueue[0], &fptask->thread.fpqdepth);
198 last_task_used_math = current;
200 fpload(¤t->thread.float_regs[0], ¤t->thread.fsr);
202 /* Set initial sane state. */
203 fpload(&init_fregs[0], &init_fsr);
208 fpload(&init_fregs[0], &init_fsr);
211 fpload(¤t->thread.float_regs[0], ¤t->thread.fsr);
213 set_thread_flag(TIF_USEDFPU);
217 static unsigned long fake_regs[32] __attribute__ ((aligned (8)));
218 static unsigned long fake_fsr;
219 static unsigned long fake_queue[32] __attribute__ ((aligned (8)));
220 static unsigned long fake_depth;
222 void do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,
230 struct task_struct *fpt = last_task_used_math;
232 struct task_struct *fpt = current;
234 put_psr(get_psr() | PSR_EF);
235 /* If nobody owns the fpu right now, just clear the
236 * error into our fake static buffer and hope it don't
237 * happen again. Thank you crashme...
242 if (!test_tsk_thread_flag(fpt, TIF_USEDFPU)) {
244 fpsave(&fake_regs[0], &fake_fsr, &fake_queue[0], &fake_depth);
245 regs->psr &= ~PSR_EF;
248 fpsave(&fpt->thread.float_regs[0], &fpt->thread.fsr,
249 &fpt->thread.fpqueue[0], &fpt->thread.fpqdepth);
251 printk("Hmm, FP exception, fsr was %016lx\n", fpt->thread.fsr);
254 switch ((fpt->thread.fsr & 0x1c000)) {
255 /* switch on the contents of the ftt [floating point trap type] field */
258 printk("IEEE_754_exception\n");
261 case (2 << 14): /* unfinished_FPop (underflow & co) */
262 case (3 << 14): /* unimplemented_FPop (quad stuff, maybe sqrt) */
263 ret = do_mathemu(regs, fpt);
267 printk("sequence_error (OS bug...)\n");
270 printk("hardware_error (uhoh!)\n");
273 printk("invalid_fp_register (user error)\n");
275 #endif /* DEBUG_FPU */
277 /* If we successfully emulated the FPop, we pretend the trap never happened :-> */
279 fpload(¤t->thread.float_regs[0], ¤t->thread.fsr);
282 /* nope, better SIGFPE the offending process... */
285 clear_tsk_thread_flag(fpt, TIF_USEDFPU);
288 /* The first fsr store/load we tried trapped,
289 * the second one will not (we hope).
291 printk("WARNING: FPU exception from kernel mode. at pc=%08lx\n",
293 regs->pc = regs->npc;
297 die_if_kernel("Too many Penguin-FPU traps from kernel mode",
302 fsr = fpt->thread.fsr;
303 info.si_signo = SIGFPE;
305 info.si_addr = (void __user *)pc;
307 info.si_code = __SI_FAULT;
308 if ((fsr & 0x1c000) == (1 << 14)) {
310 info.si_code = FPE_FLTINV;
312 info.si_code = FPE_FLTOVF;
314 info.si_code = FPE_FLTUND;
316 info.si_code = FPE_FLTDIV;
318 info.si_code = FPE_FLTRES;
320 send_sig_info(SIGFPE, &info, fpt);
322 last_task_used_math = NULL;
324 regs->psr &= ~PSR_EF;
329 void handle_tag_overflow(struct pt_regs *regs, unsigned long pc, unsigned long npc,
335 die_if_kernel("Penguin overflow trap from kernel mode", regs);
336 info.si_signo = SIGEMT;
338 info.si_code = EMT_TAGOVF;
339 info.si_addr = (void __user *)pc;
341 send_sig_info(SIGEMT, &info, current);
344 void handle_watchpoint(struct pt_regs *regs, unsigned long pc, unsigned long npc,
348 printk("Watchpoint detected at PC %08lx NPC %08lx PSR %08lx\n",
352 panic("Tell me what a watchpoint trap is, and I'll then deal "
353 "with such a beast...");
356 void handle_reg_access(struct pt_regs *regs, unsigned long pc, unsigned long npc,
362 printk("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n",
365 info.si_signo = SIGBUS;
367 info.si_code = BUS_OBJERR;
368 info.si_addr = (void __user *)pc;
370 force_sig_info(SIGBUS, &info, current);
373 void handle_cp_disabled(struct pt_regs *regs, unsigned long pc, unsigned long npc,
378 info.si_signo = SIGILL;
380 info.si_code = ILL_COPROC;
381 info.si_addr = (void __user *)pc;
383 send_sig_info(SIGILL, &info, current);
386 void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long npc,
392 printk("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n",
395 info.si_signo = SIGILL;
397 info.si_code = ILL_COPROC;
398 info.si_addr = (void __user *)pc;
400 send_sig_info(SIGILL, &info, current);
403 void handle_hw_divzero(struct pt_regs *regs, unsigned long pc, unsigned long npc,
408 info.si_signo = SIGFPE;
410 info.si_code = FPE_INTDIV;
411 info.si_addr = (void __user *)pc;
413 send_sig_info(SIGFPE, &info, current);
416 #ifdef CONFIG_DEBUG_BUGVERBOSE
417 void do_BUG(const char *file, int line)
419 // bust_spinlocks(1); XXX Not in our original BUG()
420 printk("kernel BUG at %s:%d!\n", file, line);
422 EXPORT_SYMBOL(do_BUG);
425 /* Since we have our mappings set up, on multiprocessors we can spin them
426 * up here so that timer interrupts work during initialization.
431 extern void thread_info_offsets_are_bolixed_pete(void);
433 /* Force linker to barf if mismatched */
434 if (TI_UWINMASK != offsetof(struct thread_info, uwinmask) ||
435 TI_TASK != offsetof(struct thread_info, task) ||
436 TI_FLAGS != offsetof(struct thread_info, flags) ||
437 TI_CPU != offsetof(struct thread_info, cpu) ||
438 TI_PREEMPT != offsetof(struct thread_info, preempt_count) ||
439 TI_SOFTIRQ != offsetof(struct thread_info, softirq_count) ||
440 TI_HARDIRQ != offsetof(struct thread_info, hardirq_count) ||
441 TI_KSP != offsetof(struct thread_info, ksp) ||
442 TI_KPC != offsetof(struct thread_info, kpc) ||
443 TI_KPSR != offsetof(struct thread_info, kpsr) ||
444 TI_KWIM != offsetof(struct thread_info, kwim) ||
445 TI_REG_WINDOW != offsetof(struct thread_info, reg_window) ||
446 TI_RWIN_SPTRS != offsetof(struct thread_info, rwbuf_stkptrs) ||
447 TI_W_SAVED != offsetof(struct thread_info, w_saved))
448 thread_info_offsets_are_bolixed_pete();
450 /* Attach to the address space of init_task. */
451 atomic_inc(&init_mm.mm_count);
452 current->active_mm = &init_mm;
454 /* NOTE: Other cpus have this done as they are started