2 * arch/sparc/kernel/traps.c
4 * Copyright 1995, 2008 David S. Miller (davem@davemloft.net)
5 * Copyright 2000 Jakub Jelinek (jakub@redhat.com)
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>
18 #include <asm/delay.h>
19 #include <asm/system.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 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
);
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
);
123 if (!do_user_muldiv (regs
, pc
))
126 info
.si_signo
= SIGILL
;
128 info
.si_code
= ILL_ILLOPC
;
129 info
.si_addr
= (void __user
*)pc
;
131 send_sig_info(SIGILL
, &info
, current
);
134 void do_priv_instruction(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
140 die_if_kernel("Penguin instruction from Penguin mode??!?!", regs
);
141 info
.si_signo
= SIGILL
;
143 info
.si_code
= ILL_PRVOPC
;
144 info
.si_addr
= (void __user
*)pc
;
146 send_sig_info(SIGILL
, &info
, current
);
149 /* XXX User may want to be allowed to do this. XXX */
151 void do_memaccess_unaligned(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
156 if(regs
->psr
& PSR_PS
) {
157 printk("KERNEL MNA at pc %08lx npc %08lx called by %08lx\n", pc
, npc
,
158 regs
->u_regs
[UREG_RETPC
]);
159 die_if_kernel("BOGUS", regs
);
160 /* die_if_kernel("Kernel MNA access", regs); */
164 instruction_dump ((unsigned long *) regs
->pc
);
165 printk ("do_MNA!\n");
167 info
.si_signo
= SIGBUS
;
169 info
.si_code
= BUS_ADRALN
;
170 info
.si_addr
= /* FIXME: Should dig out mna address */ (void *)0;
172 send_sig_info(SIGBUS
, &info
, current
);
175 static unsigned long init_fsr
= 0x0UL
;
176 static unsigned long init_fregs
[32] __attribute__ ((aligned (8))) =
177 { ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
178 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
179 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
180 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL };
182 void do_fpd_trap(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
185 /* Sanity check... */
187 die_if_kernel("Kernel gets FloatingPenguinUnit disabled trap", regs
);
189 put_psr(get_psr() | PSR_EF
); /* Allow FPU ops. */
192 if(last_task_used_math
== current
)
194 if(last_task_used_math
) {
195 /* Other processes fpu state, save away */
196 struct task_struct
*fptask
= last_task_used_math
;
197 fpsave(&fptask
->thread
.float_regs
[0], &fptask
->thread
.fsr
,
198 &fptask
->thread
.fpqueue
[0], &fptask
->thread
.fpqdepth
);
200 last_task_used_math
= current
;
202 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
204 /* Set initial sane state. */
205 fpload(&init_fregs
[0], &init_fsr
);
210 fpload(&init_fregs
[0], &init_fsr
);
213 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
215 set_thread_flag(TIF_USEDFPU
);
219 static unsigned long fake_regs
[32] __attribute__ ((aligned (8)));
220 static unsigned long fake_fsr
;
221 static unsigned long fake_queue
[32] __attribute__ ((aligned (8)));
222 static unsigned long fake_depth
;
224 extern int do_mathemu(struct pt_regs
*, struct task_struct
*);
226 void do_fpe_trap(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
234 struct task_struct
*fpt
= last_task_used_math
;
236 struct task_struct
*fpt
= current
;
238 put_psr(get_psr() | PSR_EF
);
239 /* If nobody owns the fpu right now, just clear the
240 * error into our fake static buffer and hope it don't
241 * happen again. Thank you crashme...
246 if (!test_tsk_thread_flag(fpt
, TIF_USEDFPU
)) {
248 fpsave(&fake_regs
[0], &fake_fsr
, &fake_queue
[0], &fake_depth
);
249 regs
->psr
&= ~PSR_EF
;
252 fpsave(&fpt
->thread
.float_regs
[0], &fpt
->thread
.fsr
,
253 &fpt
->thread
.fpqueue
[0], &fpt
->thread
.fpqdepth
);
255 printk("Hmm, FP exception, fsr was %016lx\n", fpt
->thread
.fsr
);
258 switch ((fpt
->thread
.fsr
& 0x1c000)) {
259 /* switch on the contents of the ftt [floating point trap type] field */
262 printk("IEEE_754_exception\n");
265 case (2 << 14): /* unfinished_FPop (underflow & co) */
266 case (3 << 14): /* unimplemented_FPop (quad stuff, maybe sqrt) */
267 ret
= do_mathemu(regs
, fpt
);
271 printk("sequence_error (OS bug...)\n");
274 printk("hardware_error (uhoh!)\n");
277 printk("invalid_fp_register (user error)\n");
279 #endif /* DEBUG_FPU */
281 /* If we successfully emulated the FPop, we pretend the trap never happened :-> */
283 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
286 /* nope, better SIGFPE the offending process... */
289 clear_tsk_thread_flag(fpt
, TIF_USEDFPU
);
292 /* The first fsr store/load we tried trapped,
293 * the second one will not (we hope).
295 printk("WARNING: FPU exception from kernel mode. at pc=%08lx\n",
297 regs
->pc
= regs
->npc
;
301 die_if_kernel("Too many Penguin-FPU traps from kernel mode",
306 fsr
= fpt
->thread
.fsr
;
307 info
.si_signo
= SIGFPE
;
309 info
.si_addr
= (void __user
*)pc
;
311 info
.si_code
= __SI_FAULT
;
312 if ((fsr
& 0x1c000) == (1 << 14)) {
314 info
.si_code
= FPE_FLTINV
;
316 info
.si_code
= FPE_FLTOVF
;
318 info
.si_code
= FPE_FLTUND
;
320 info
.si_code
= FPE_FLTDIV
;
322 info
.si_code
= FPE_FLTRES
;
324 send_sig_info(SIGFPE
, &info
, fpt
);
326 last_task_used_math
= NULL
;
328 regs
->psr
&= ~PSR_EF
;
333 void handle_tag_overflow(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
339 die_if_kernel("Penguin overflow trap from kernel mode", regs
);
340 info
.si_signo
= SIGEMT
;
342 info
.si_code
= EMT_TAGOVF
;
343 info
.si_addr
= (void __user
*)pc
;
345 send_sig_info(SIGEMT
, &info
, current
);
348 void handle_watchpoint(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
352 printk("Watchpoint detected at PC %08lx NPC %08lx PSR %08lx\n",
356 panic("Tell me what a watchpoint trap is, and I'll then deal "
357 "with such a beast...");
360 void handle_reg_access(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
366 printk("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n",
369 info
.si_signo
= SIGBUS
;
371 info
.si_code
= BUS_OBJERR
;
372 info
.si_addr
= (void __user
*)pc
;
374 force_sig_info(SIGBUS
, &info
, current
);
377 void handle_cp_disabled(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
382 info
.si_signo
= SIGILL
;
384 info
.si_code
= ILL_COPROC
;
385 info
.si_addr
= (void __user
*)pc
;
387 send_sig_info(SIGILL
, &info
, current
);
390 void handle_cp_exception(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
396 printk("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n",
399 info
.si_signo
= SIGILL
;
401 info
.si_code
= ILL_COPROC
;
402 info
.si_addr
= (void __user
*)pc
;
404 send_sig_info(SIGILL
, &info
, current
);
407 void handle_hw_divzero(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
412 info
.si_signo
= SIGFPE
;
414 info
.si_code
= FPE_INTDIV
;
415 info
.si_addr
= (void __user
*)pc
;
417 send_sig_info(SIGFPE
, &info
, current
);
420 #ifdef CONFIG_DEBUG_BUGVERBOSE
421 void do_BUG(const char *file
, int line
)
423 // bust_spinlocks(1); XXX Not in our original BUG()
424 printk("kernel BUG at %s:%d!\n", file
, line
);
426 EXPORT_SYMBOL(do_BUG
);
429 /* Since we have our mappings set up, on multiprocessors we can spin them
430 * up here so that timer interrupts work during initialization.
435 extern void thread_info_offsets_are_bolixed_pete(void);
437 /* Force linker to barf if mismatched */
438 if (TI_UWINMASK
!= offsetof(struct thread_info
, uwinmask
) ||
439 TI_TASK
!= offsetof(struct thread_info
, task
) ||
440 TI_EXECDOMAIN
!= offsetof(struct thread_info
, exec_domain
) ||
441 TI_FLAGS
!= offsetof(struct thread_info
, flags
) ||
442 TI_CPU
!= offsetof(struct thread_info
, cpu
) ||
443 TI_PREEMPT
!= offsetof(struct thread_info
, preempt_count
) ||
444 TI_SOFTIRQ
!= offsetof(struct thread_info
, softirq_count
) ||
445 TI_HARDIRQ
!= offsetof(struct thread_info
, hardirq_count
) ||
446 TI_KSP
!= offsetof(struct thread_info
, ksp
) ||
447 TI_KPC
!= offsetof(struct thread_info
, kpc
) ||
448 TI_KPSR
!= offsetof(struct thread_info
, kpsr
) ||
449 TI_KWIM
!= offsetof(struct thread_info
, kwim
) ||
450 TI_REG_WINDOW
!= offsetof(struct thread_info
, reg_window
) ||
451 TI_RWIN_SPTRS
!= offsetof(struct thread_info
, rwbuf_stkptrs
) ||
452 TI_W_SAVED
!= offsetof(struct thread_info
, w_saved
))
453 thread_info_offsets_are_bolixed_pete();
455 /* Attach to the address space of init_task. */
456 atomic_inc(&init_mm
.mm_count
);
457 current
->active_mm
= &init_mm
;
459 /* NOTE: Other cpus have this done as they are started