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>
17 #include <linux/export.h>
19 #include <asm/delay.h>
20 #include <asm/system.h>
21 #include <asm/ptrace.h>
22 #include <asm/oplib.h>
24 #include <asm/pgtable.h>
25 #include <asm/unistd.h>
26 #include <asm/traps.h>
31 /* #define TRAP_DEBUG */
33 static void instruction_dump(unsigned long *pc
)
37 if((((unsigned long) pc
) & 3))
40 for(i
= -3; i
< 6; i
++)
41 printk("%c%08lx%c",i
?' ':'<',pc
[i
],i
?' ':'>');
45 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
46 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
48 void die_if_kernel(char *str
, struct pt_regs
*regs
)
50 static int die_counter
;
60 printk("%s(%d): %s [#%d]\n", current
->comm
, task_pid_nr(current
), str
, ++die_counter
);
64 __SAVE
; __SAVE
; __SAVE
; __SAVE
;
65 __SAVE
; __SAVE
; __SAVE
; __SAVE
;
66 __RESTORE
; __RESTORE
; __RESTORE
; __RESTORE
;
67 __RESTORE
; __RESTORE
; __RESTORE
; __RESTORE
;
70 struct reg_window32
*rw
= (struct reg_window32
*)regs
->u_regs
[UREG_FP
];
72 /* Stop the back trace when we hit userland or we
73 * find some badly aligned kernel stack. Set an upper
74 * bound in case our stack is trashed and we loop.
78 (((unsigned long) rw
) >= PAGE_OFFSET
) &&
79 !(((unsigned long) rw
) & 0x7)) {
80 printk("Caller[%08lx]: %pS\n", rw
->ins
[7],
82 rw
= (struct reg_window32
*)rw
->ins
[6];
85 printk("Instruction DUMP:");
86 instruction_dump ((unsigned long *) regs
->pc
);
87 if(regs
->psr
& PSR_PS
)
92 void do_hw_interrupt(struct pt_regs
*regs
, unsigned long type
)
97 /* Sun OS's puke from bad traps, Linux survives! */
98 printk("Unimplemented Sparc TRAP, type = %02lx\n", type
);
99 die_if_kernel("Whee... Hello Mr. Penguin", regs
);
102 if(regs
->psr
& PSR_PS
)
103 die_if_kernel("Kernel bad trap", regs
);
105 info
.si_signo
= SIGILL
;
107 info
.si_code
= ILL_ILLTRP
;
108 info
.si_addr
= (void __user
*)regs
->pc
;
109 info
.si_trapno
= type
- 0x80;
110 force_sig_info(SIGILL
, &info
, current
);
113 void do_illegal_instruction(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
119 die_if_kernel("Kernel illegal instruction", regs
);
121 printk("Ill instr. at pc=%08lx instruction is %08lx\n",
122 regs
->pc
, *(unsigned long *)regs
->pc
);
124 if (!do_user_muldiv (regs
, pc
))
127 info
.si_signo
= SIGILL
;
129 info
.si_code
= ILL_ILLOPC
;
130 info
.si_addr
= (void __user
*)pc
;
132 send_sig_info(SIGILL
, &info
, current
);
135 void do_priv_instruction(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
141 die_if_kernel("Penguin instruction from Penguin mode??!?!", regs
);
142 info
.si_signo
= SIGILL
;
144 info
.si_code
= ILL_PRVOPC
;
145 info
.si_addr
= (void __user
*)pc
;
147 send_sig_info(SIGILL
, &info
, current
);
150 /* XXX User may want to be allowed to do this. XXX */
152 void do_memaccess_unaligned(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
157 if(regs
->psr
& PSR_PS
) {
158 printk("KERNEL MNA at pc %08lx npc %08lx called by %08lx\n", pc
, npc
,
159 regs
->u_regs
[UREG_RETPC
]);
160 die_if_kernel("BOGUS", regs
);
161 /* die_if_kernel("Kernel MNA access", regs); */
165 instruction_dump ((unsigned long *) regs
->pc
);
166 printk ("do_MNA!\n");
168 info
.si_signo
= SIGBUS
;
170 info
.si_code
= BUS_ADRALN
;
171 info
.si_addr
= /* FIXME: Should dig out mna address */ (void *)0;
173 send_sig_info(SIGBUS
, &info
, current
);
176 static unsigned long init_fsr
= 0x0UL
;
177 static unsigned long init_fregs
[32] __attribute__ ((aligned (8))) =
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,
181 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL };
183 void do_fpd_trap(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
186 /* Sanity check... */
188 die_if_kernel("Kernel gets FloatingPenguinUnit disabled trap", regs
);
190 put_psr(get_psr() | PSR_EF
); /* Allow FPU ops. */
193 if(last_task_used_math
== current
)
195 if(last_task_used_math
) {
196 /* Other processes fpu state, save away */
197 struct task_struct
*fptask
= last_task_used_math
;
198 fpsave(&fptask
->thread
.float_regs
[0], &fptask
->thread
.fsr
,
199 &fptask
->thread
.fpqueue
[0], &fptask
->thread
.fpqdepth
);
201 last_task_used_math
= current
;
203 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
205 /* Set initial sane state. */
206 fpload(&init_fregs
[0], &init_fsr
);
211 fpload(&init_fregs
[0], &init_fsr
);
214 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
216 set_thread_flag(TIF_USEDFPU
);
220 static unsigned long fake_regs
[32] __attribute__ ((aligned (8)));
221 static unsigned long fake_fsr
;
222 static unsigned long fake_queue
[32] __attribute__ ((aligned (8)));
223 static unsigned long fake_depth
;
225 extern int do_mathemu(struct pt_regs
*, struct task_struct
*);
227 void do_fpe_trap(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
235 struct task_struct
*fpt
= last_task_used_math
;
237 struct task_struct
*fpt
= current
;
239 put_psr(get_psr() | PSR_EF
);
240 /* If nobody owns the fpu right now, just clear the
241 * error into our fake static buffer and hope it don't
242 * happen again. Thank you crashme...
247 if (!test_tsk_thread_flag(fpt
, TIF_USEDFPU
)) {
249 fpsave(&fake_regs
[0], &fake_fsr
, &fake_queue
[0], &fake_depth
);
250 regs
->psr
&= ~PSR_EF
;
253 fpsave(&fpt
->thread
.float_regs
[0], &fpt
->thread
.fsr
,
254 &fpt
->thread
.fpqueue
[0], &fpt
->thread
.fpqdepth
);
256 printk("Hmm, FP exception, fsr was %016lx\n", fpt
->thread
.fsr
);
259 switch ((fpt
->thread
.fsr
& 0x1c000)) {
260 /* switch on the contents of the ftt [floating point trap type] field */
263 printk("IEEE_754_exception\n");
266 case (2 << 14): /* unfinished_FPop (underflow & co) */
267 case (3 << 14): /* unimplemented_FPop (quad stuff, maybe sqrt) */
268 ret
= do_mathemu(regs
, fpt
);
272 printk("sequence_error (OS bug...)\n");
275 printk("hardware_error (uhoh!)\n");
278 printk("invalid_fp_register (user error)\n");
280 #endif /* DEBUG_FPU */
282 /* If we successfully emulated the FPop, we pretend the trap never happened :-> */
284 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
287 /* nope, better SIGFPE the offending process... */
290 clear_tsk_thread_flag(fpt
, TIF_USEDFPU
);
293 /* The first fsr store/load we tried trapped,
294 * the second one will not (we hope).
296 printk("WARNING: FPU exception from kernel mode. at pc=%08lx\n",
298 regs
->pc
= regs
->npc
;
302 die_if_kernel("Too many Penguin-FPU traps from kernel mode",
307 fsr
= fpt
->thread
.fsr
;
308 info
.si_signo
= SIGFPE
;
310 info
.si_addr
= (void __user
*)pc
;
312 info
.si_code
= __SI_FAULT
;
313 if ((fsr
& 0x1c000) == (1 << 14)) {
315 info
.si_code
= FPE_FLTINV
;
317 info
.si_code
= FPE_FLTOVF
;
319 info
.si_code
= FPE_FLTUND
;
321 info
.si_code
= FPE_FLTDIV
;
323 info
.si_code
= FPE_FLTRES
;
325 send_sig_info(SIGFPE
, &info
, fpt
);
327 last_task_used_math
= NULL
;
329 regs
->psr
&= ~PSR_EF
;
334 void handle_tag_overflow(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
340 die_if_kernel("Penguin overflow trap from kernel mode", regs
);
341 info
.si_signo
= SIGEMT
;
343 info
.si_code
= EMT_TAGOVF
;
344 info
.si_addr
= (void __user
*)pc
;
346 send_sig_info(SIGEMT
, &info
, current
);
349 void handle_watchpoint(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
353 printk("Watchpoint detected at PC %08lx NPC %08lx PSR %08lx\n",
357 panic("Tell me what a watchpoint trap is, and I'll then deal "
358 "with such a beast...");
361 void handle_reg_access(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
367 printk("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n",
370 info
.si_signo
= SIGBUS
;
372 info
.si_code
= BUS_OBJERR
;
373 info
.si_addr
= (void __user
*)pc
;
375 force_sig_info(SIGBUS
, &info
, current
);
378 void handle_cp_disabled(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
383 info
.si_signo
= SIGILL
;
385 info
.si_code
= ILL_COPROC
;
386 info
.si_addr
= (void __user
*)pc
;
388 send_sig_info(SIGILL
, &info
, current
);
391 void handle_cp_exception(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
397 printk("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n",
400 info
.si_signo
= SIGILL
;
402 info
.si_code
= ILL_COPROC
;
403 info
.si_addr
= (void __user
*)pc
;
405 send_sig_info(SIGILL
, &info
, current
);
408 void handle_hw_divzero(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
413 info
.si_signo
= SIGFPE
;
415 info
.si_code
= FPE_INTDIV
;
416 info
.si_addr
= (void __user
*)pc
;
418 send_sig_info(SIGFPE
, &info
, current
);
421 #ifdef CONFIG_DEBUG_BUGVERBOSE
422 void do_BUG(const char *file
, int line
)
424 // bust_spinlocks(1); XXX Not in our original BUG()
425 printk("kernel BUG at %s:%d!\n", file
, line
);
427 EXPORT_SYMBOL(do_BUG
);
430 /* Since we have our mappings set up, on multiprocessors we can spin them
431 * up here so that timer interrupts work during initialization.
436 extern void thread_info_offsets_are_bolixed_pete(void);
438 /* Force linker to barf if mismatched */
439 if (TI_UWINMASK
!= offsetof(struct thread_info
, uwinmask
) ||
440 TI_TASK
!= offsetof(struct thread_info
, task
) ||
441 TI_EXECDOMAIN
!= offsetof(struct thread_info
, exec_domain
) ||
442 TI_FLAGS
!= offsetof(struct thread_info
, flags
) ||
443 TI_CPU
!= offsetof(struct thread_info
, cpu
) ||
444 TI_PREEMPT
!= offsetof(struct thread_info
, preempt_count
) ||
445 TI_SOFTIRQ
!= offsetof(struct thread_info
, softirq_count
) ||
446 TI_HARDIRQ
!= offsetof(struct thread_info
, hardirq_count
) ||
447 TI_KSP
!= offsetof(struct thread_info
, ksp
) ||
448 TI_KPC
!= offsetof(struct thread_info
, kpc
) ||
449 TI_KPSR
!= offsetof(struct thread_info
, kpsr
) ||
450 TI_KWIM
!= offsetof(struct thread_info
, kwim
) ||
451 TI_REG_WINDOW
!= offsetof(struct thread_info
, reg_window
) ||
452 TI_RWIN_SPTRS
!= offsetof(struct thread_info
, rwbuf_stkptrs
) ||
453 TI_W_SAVED
!= offsetof(struct thread_info
, w_saved
))
454 thread_info_offsets_are_bolixed_pete();
456 /* Attach to the address space of init_task. */
457 atomic_inc(&init_mm
.mm_count
);
458 current
->active_mm
= &init_mm
;
460 /* NOTE: Other cpus have this done as they are started