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/smp_lock.h>
17 #include <linux/kdebug.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>
28 /* #define TRAP_DEBUG */
30 struct trap_trace_entry
{
35 void syscall_trace_entry(struct pt_regs
*regs
)
37 printk("%s[%d]: ", current
->comm
, task_pid_nr(current
));
38 printk("scall<%d> (could be %d)\n", (int) regs
->u_regs
[UREG_G1
],
39 (int) regs
->u_regs
[UREG_I0
]);
42 void syscall_trace_exit(struct pt_regs
*regs
)
46 void sun4m_nmi(struct pt_regs
*regs
)
48 unsigned long afsr
, afar
;
50 printk("Aieee: sun4m NMI received!\n");
51 /* XXX HyperSparc hack XXX */
52 __asm__
__volatile__("mov 0x500, %%g1\n\t"
53 "lda [%%g1] 0x4, %0\n\t"
55 "lda [%%g1] 0x4, %1\n\t" :
56 "=r" (afsr
), "=r" (afar
));
57 printk("afsr=%08lx afar=%08lx\n", afsr
, afar
);
58 printk("you lose buddy boy...\n");
63 void sun4d_nmi(struct pt_regs
*regs
)
65 printk("Aieee: sun4d NMI received!\n");
66 printk("you lose buddy boy...\n");
71 static void instruction_dump(unsigned long *pc
)
75 if((((unsigned long) pc
) & 3))
78 for(i
= -3; i
< 6; i
++)
79 printk("%c%08lx%c",i
?' ':'<',pc
[i
],i
?' ':'>');
83 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
84 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
86 void die_if_kernel(char *str
, struct pt_regs
*regs
)
88 static int die_counter
;
98 printk("%s(%d): %s [#%d]\n", current
->comm
, task_pid_nr(current
), str
, ++die_counter
);
100 add_taint(TAINT_DIE
);
102 __SAVE
; __SAVE
; __SAVE
; __SAVE
;
103 __SAVE
; __SAVE
; __SAVE
; __SAVE
;
104 __RESTORE
; __RESTORE
; __RESTORE
; __RESTORE
;
105 __RESTORE
; __RESTORE
; __RESTORE
; __RESTORE
;
108 struct reg_window
*rw
= (struct reg_window
*)regs
->u_regs
[UREG_FP
];
110 /* Stop the back trace when we hit userland or we
111 * find some badly aligned kernel stack. Set an upper
112 * bound in case our stack is trashed and we loop.
116 (((unsigned long) rw
) >= PAGE_OFFSET
) &&
117 !(((unsigned long) rw
) & 0x7)) {
118 printk("Caller[%08lx]: %pS\n", rw
->ins
[7],
119 (void *) rw
->ins
[7]);
120 rw
= (struct reg_window
*)rw
->ins
[6];
123 printk("Instruction DUMP:");
124 instruction_dump ((unsigned long *) regs
->pc
);
125 if(regs
->psr
& PSR_PS
)
130 void do_hw_interrupt(struct pt_regs
*regs
, unsigned long type
)
135 /* Sun OS's puke from bad traps, Linux survives! */
136 printk("Unimplemented Sparc TRAP, type = %02lx\n", type
);
137 die_if_kernel("Whee... Hello Mr. Penguin", regs
);
140 if(regs
->psr
& PSR_PS
)
141 die_if_kernel("Kernel bad trap", regs
);
143 info
.si_signo
= SIGILL
;
145 info
.si_code
= ILL_ILLTRP
;
146 info
.si_addr
= (void __user
*)regs
->pc
;
147 info
.si_trapno
= type
- 0x80;
148 force_sig_info(SIGILL
, &info
, current
);
151 void do_illegal_instruction(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
154 extern int do_user_muldiv (struct pt_regs
*, unsigned long);
158 die_if_kernel("Kernel illegal instruction", regs
);
160 printk("Ill instr. at pc=%08lx instruction is %08lx\n",
161 regs
->pc
, *(unsigned long *)regs
->pc
);
163 if (!do_user_muldiv (regs
, pc
))
166 info
.si_signo
= SIGILL
;
168 info
.si_code
= ILL_ILLOPC
;
169 info
.si_addr
= (void __user
*)pc
;
171 send_sig_info(SIGILL
, &info
, current
);
174 void do_priv_instruction(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
180 die_if_kernel("Penguin instruction from Penguin mode??!?!", regs
);
181 info
.si_signo
= SIGILL
;
183 info
.si_code
= ILL_PRVOPC
;
184 info
.si_addr
= (void __user
*)pc
;
186 send_sig_info(SIGILL
, &info
, current
);
189 /* XXX User may want to be allowed to do this. XXX */
191 void do_memaccess_unaligned(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
196 if(regs
->psr
& PSR_PS
) {
197 printk("KERNEL MNA at pc %08lx npc %08lx called by %08lx\n", pc
, npc
,
198 regs
->u_regs
[UREG_RETPC
]);
199 die_if_kernel("BOGUS", regs
);
200 /* die_if_kernel("Kernel MNA access", regs); */
204 instruction_dump ((unsigned long *) regs
->pc
);
205 printk ("do_MNA!\n");
207 info
.si_signo
= SIGBUS
;
209 info
.si_code
= BUS_ADRALN
;
210 info
.si_addr
= /* FIXME: Should dig out mna address */ (void *)0;
212 send_sig_info(SIGBUS
, &info
, current
);
215 extern void fpsave(unsigned long *fpregs
, unsigned long *fsr
,
216 void *fpqueue
, unsigned long *fpqdepth
);
217 extern void fpload(unsigned long *fpregs
, unsigned long *fsr
);
219 static unsigned long init_fsr
= 0x0UL
;
220 static unsigned long init_fregs
[32] __attribute__ ((aligned (8))) =
221 { ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
222 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
223 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
224 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL };
226 void do_fpd_trap(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
229 /* Sanity check... */
231 die_if_kernel("Kernel gets FloatingPenguinUnit disabled trap", regs
);
233 put_psr(get_psr() | PSR_EF
); /* Allow FPU ops. */
236 if(last_task_used_math
== current
)
238 if(last_task_used_math
) {
239 /* Other processes fpu state, save away */
240 struct task_struct
*fptask
= last_task_used_math
;
241 fpsave(&fptask
->thread
.float_regs
[0], &fptask
->thread
.fsr
,
242 &fptask
->thread
.fpqueue
[0], &fptask
->thread
.fpqdepth
);
244 last_task_used_math
= current
;
246 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
248 /* Set initial sane state. */
249 fpload(&init_fregs
[0], &init_fsr
);
254 fpload(&init_fregs
[0], &init_fsr
);
257 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
259 set_thread_flag(TIF_USEDFPU
);
263 static unsigned long fake_regs
[32] __attribute__ ((aligned (8)));
264 static unsigned long fake_fsr
;
265 static unsigned long fake_queue
[32] __attribute__ ((aligned (8)));
266 static unsigned long fake_depth
;
268 extern int do_mathemu(struct pt_regs
*, struct task_struct
*);
270 void do_fpe_trap(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
278 struct task_struct
*fpt
= last_task_used_math
;
280 struct task_struct
*fpt
= current
;
282 put_psr(get_psr() | PSR_EF
);
283 /* If nobody owns the fpu right now, just clear the
284 * error into our fake static buffer and hope it don't
285 * happen again. Thank you crashme...
290 if (!test_tsk_thread_flag(fpt
, TIF_USEDFPU
)) {
292 fpsave(&fake_regs
[0], &fake_fsr
, &fake_queue
[0], &fake_depth
);
293 regs
->psr
&= ~PSR_EF
;
296 fpsave(&fpt
->thread
.float_regs
[0], &fpt
->thread
.fsr
,
297 &fpt
->thread
.fpqueue
[0], &fpt
->thread
.fpqdepth
);
299 printk("Hmm, FP exception, fsr was %016lx\n", fpt
->thread
.fsr
);
302 switch ((fpt
->thread
.fsr
& 0x1c000)) {
303 /* switch on the contents of the ftt [floating point trap type] field */
306 printk("IEEE_754_exception\n");
309 case (2 << 14): /* unfinished_FPop (underflow & co) */
310 case (3 << 14): /* unimplemented_FPop (quad stuff, maybe sqrt) */
311 ret
= do_mathemu(regs
, fpt
);
315 printk("sequence_error (OS bug...)\n");
318 printk("hardware_error (uhoh!)\n");
321 printk("invalid_fp_register (user error)\n");
323 #endif /* DEBUG_FPU */
325 /* If we successfully emulated the FPop, we pretend the trap never happened :-> */
327 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
330 /* nope, better SIGFPE the offending process... */
333 clear_tsk_thread_flag(fpt
, TIF_USEDFPU
);
336 /* The first fsr store/load we tried trapped,
337 * the second one will not (we hope).
339 printk("WARNING: FPU exception from kernel mode. at pc=%08lx\n",
341 regs
->pc
= regs
->npc
;
345 die_if_kernel("Too many Penguin-FPU traps from kernel mode",
350 fsr
= fpt
->thread
.fsr
;
351 info
.si_signo
= SIGFPE
;
353 info
.si_addr
= (void __user
*)pc
;
355 info
.si_code
= __SI_FAULT
;
356 if ((fsr
& 0x1c000) == (1 << 14)) {
358 info
.si_code
= FPE_FLTINV
;
360 info
.si_code
= FPE_FLTOVF
;
362 info
.si_code
= FPE_FLTUND
;
364 info
.si_code
= FPE_FLTDIV
;
366 info
.si_code
= FPE_FLTRES
;
368 send_sig_info(SIGFPE
, &info
, fpt
);
370 last_task_used_math
= NULL
;
372 regs
->psr
&= ~PSR_EF
;
377 void handle_tag_overflow(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
383 die_if_kernel("Penguin overflow trap from kernel mode", regs
);
384 info
.si_signo
= SIGEMT
;
386 info
.si_code
= EMT_TAGOVF
;
387 info
.si_addr
= (void __user
*)pc
;
389 send_sig_info(SIGEMT
, &info
, current
);
392 void handle_watchpoint(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
396 printk("Watchpoint detected at PC %08lx NPC %08lx PSR %08lx\n",
400 panic("Tell me what a watchpoint trap is, and I'll then deal "
401 "with such a beast...");
404 void handle_reg_access(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
410 printk("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n",
413 info
.si_signo
= SIGBUS
;
415 info
.si_code
= BUS_OBJERR
;
416 info
.si_addr
= (void __user
*)pc
;
418 force_sig_info(SIGBUS
, &info
, current
);
421 void handle_cp_disabled(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
426 info
.si_signo
= SIGILL
;
428 info
.si_code
= ILL_COPROC
;
429 info
.si_addr
= (void __user
*)pc
;
431 send_sig_info(SIGILL
, &info
, current
);
434 void handle_cp_exception(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
440 printk("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n",
443 info
.si_signo
= SIGILL
;
445 info
.si_code
= ILL_COPROC
;
446 info
.si_addr
= (void __user
*)pc
;
448 send_sig_info(SIGILL
, &info
, current
);
451 void handle_hw_divzero(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
456 info
.si_signo
= SIGFPE
;
458 info
.si_code
= FPE_INTDIV
;
459 info
.si_addr
= (void __user
*)pc
;
461 send_sig_info(SIGFPE
, &info
, current
);
464 #ifdef CONFIG_DEBUG_BUGVERBOSE
465 void do_BUG(const char *file
, int line
)
467 // bust_spinlocks(1); XXX Not in our original BUG()
468 printk("kernel BUG at %s:%d!\n", file
, line
);
472 /* Since we have our mappings set up, on multiprocessors we can spin them
473 * up here so that timer interrupts work during initialization.
476 extern void sparc_cpu_startup(void);
480 extern void thread_info_offsets_are_bolixed_pete(void);
482 /* Force linker to barf if mismatched */
483 if (TI_UWINMASK
!= offsetof(struct thread_info
, uwinmask
) ||
484 TI_TASK
!= offsetof(struct thread_info
, task
) ||
485 TI_EXECDOMAIN
!= offsetof(struct thread_info
, exec_domain
) ||
486 TI_FLAGS
!= offsetof(struct thread_info
, flags
) ||
487 TI_CPU
!= offsetof(struct thread_info
, cpu
) ||
488 TI_PREEMPT
!= offsetof(struct thread_info
, preempt_count
) ||
489 TI_SOFTIRQ
!= offsetof(struct thread_info
, softirq_count
) ||
490 TI_HARDIRQ
!= offsetof(struct thread_info
, hardirq_count
) ||
491 TI_KSP
!= offsetof(struct thread_info
, ksp
) ||
492 TI_KPC
!= offsetof(struct thread_info
, kpc
) ||
493 TI_KPSR
!= offsetof(struct thread_info
, kpsr
) ||
494 TI_KWIM
!= offsetof(struct thread_info
, kwim
) ||
495 TI_REG_WINDOW
!= offsetof(struct thread_info
, reg_window
) ||
496 TI_RWIN_SPTRS
!= offsetof(struct thread_info
, rwbuf_stkptrs
) ||
497 TI_W_SAVED
!= offsetof(struct thread_info
, w_saved
))
498 thread_info_offsets_are_bolixed_pete();
500 /* Attach to the address space of init_task. */
501 atomic_inc(&init_mm
.mm_count
);
502 current
->active_mm
= &init_mm
;
504 /* NOTE: Other cpus have this done as they are started