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 sun4d_nmi(struct pt_regs
*regs
)
48 printk("Aieee: sun4d NMI received!\n");
49 printk("you lose buddy boy...\n");
54 static void instruction_dump(unsigned long *pc
)
58 if((((unsigned long) pc
) & 3))
61 for(i
= -3; i
< 6; i
++)
62 printk("%c%08lx%c",i
?' ':'<',pc
[i
],i
?' ':'>');
66 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
67 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
69 void die_if_kernel(char *str
, struct pt_regs
*regs
)
71 static int die_counter
;
81 printk("%s(%d): %s [#%d]\n", current
->comm
, task_pid_nr(current
), str
, ++die_counter
);
85 __SAVE
; __SAVE
; __SAVE
; __SAVE
;
86 __SAVE
; __SAVE
; __SAVE
; __SAVE
;
87 __RESTORE
; __RESTORE
; __RESTORE
; __RESTORE
;
88 __RESTORE
; __RESTORE
; __RESTORE
; __RESTORE
;
91 struct reg_window
*rw
= (struct reg_window
*)regs
->u_regs
[UREG_FP
];
93 /* Stop the back trace when we hit userland or we
94 * find some badly aligned kernel stack. Set an upper
95 * bound in case our stack is trashed and we loop.
99 (((unsigned long) rw
) >= PAGE_OFFSET
) &&
100 !(((unsigned long) rw
) & 0x7)) {
101 printk("Caller[%08lx]: %pS\n", rw
->ins
[7],
102 (void *) rw
->ins
[7]);
103 rw
= (struct reg_window
*)rw
->ins
[6];
106 printk("Instruction DUMP:");
107 instruction_dump ((unsigned long *) regs
->pc
);
108 if(regs
->psr
& PSR_PS
)
113 void do_hw_interrupt(struct pt_regs
*regs
, unsigned long type
)
118 /* Sun OS's puke from bad traps, Linux survives! */
119 printk("Unimplemented Sparc TRAP, type = %02lx\n", type
);
120 die_if_kernel("Whee... Hello Mr. Penguin", regs
);
123 if(regs
->psr
& PSR_PS
)
124 die_if_kernel("Kernel bad trap", regs
);
126 info
.si_signo
= SIGILL
;
128 info
.si_code
= ILL_ILLTRP
;
129 info
.si_addr
= (void __user
*)regs
->pc
;
130 info
.si_trapno
= type
- 0x80;
131 force_sig_info(SIGILL
, &info
, current
);
134 void do_illegal_instruction(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
137 extern int do_user_muldiv (struct pt_regs
*, unsigned long);
141 die_if_kernel("Kernel illegal instruction", regs
);
143 printk("Ill instr. at pc=%08lx instruction is %08lx\n",
144 regs
->pc
, *(unsigned long *)regs
->pc
);
146 if (!do_user_muldiv (regs
, pc
))
149 info
.si_signo
= SIGILL
;
151 info
.si_code
= ILL_ILLOPC
;
152 info
.si_addr
= (void __user
*)pc
;
154 send_sig_info(SIGILL
, &info
, current
);
157 void do_priv_instruction(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
163 die_if_kernel("Penguin instruction from Penguin mode??!?!", regs
);
164 info
.si_signo
= SIGILL
;
166 info
.si_code
= ILL_PRVOPC
;
167 info
.si_addr
= (void __user
*)pc
;
169 send_sig_info(SIGILL
, &info
, current
);
172 /* XXX User may want to be allowed to do this. XXX */
174 void do_memaccess_unaligned(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
179 if(regs
->psr
& PSR_PS
) {
180 printk("KERNEL MNA at pc %08lx npc %08lx called by %08lx\n", pc
, npc
,
181 regs
->u_regs
[UREG_RETPC
]);
182 die_if_kernel("BOGUS", regs
);
183 /* die_if_kernel("Kernel MNA access", regs); */
187 instruction_dump ((unsigned long *) regs
->pc
);
188 printk ("do_MNA!\n");
190 info
.si_signo
= SIGBUS
;
192 info
.si_code
= BUS_ADRALN
;
193 info
.si_addr
= /* FIXME: Should dig out mna address */ (void *)0;
195 send_sig_info(SIGBUS
, &info
, current
);
198 extern void fpsave(unsigned long *fpregs
, unsigned long *fsr
,
199 void *fpqueue
, unsigned long *fpqdepth
);
200 extern void fpload(unsigned long *fpregs
, unsigned long *fsr
);
202 static unsigned long init_fsr
= 0x0UL
;
203 static unsigned long init_fregs
[32] __attribute__ ((aligned (8))) =
204 { ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
205 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
206 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
207 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL };
209 void do_fpd_trap(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
212 /* Sanity check... */
214 die_if_kernel("Kernel gets FloatingPenguinUnit disabled trap", regs
);
216 put_psr(get_psr() | PSR_EF
); /* Allow FPU ops. */
219 if(last_task_used_math
== current
)
221 if(last_task_used_math
) {
222 /* Other processes fpu state, save away */
223 struct task_struct
*fptask
= last_task_used_math
;
224 fpsave(&fptask
->thread
.float_regs
[0], &fptask
->thread
.fsr
,
225 &fptask
->thread
.fpqueue
[0], &fptask
->thread
.fpqdepth
);
227 last_task_used_math
= current
;
229 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
231 /* Set initial sane state. */
232 fpload(&init_fregs
[0], &init_fsr
);
237 fpload(&init_fregs
[0], &init_fsr
);
240 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
242 set_thread_flag(TIF_USEDFPU
);
246 static unsigned long fake_regs
[32] __attribute__ ((aligned (8)));
247 static unsigned long fake_fsr
;
248 static unsigned long fake_queue
[32] __attribute__ ((aligned (8)));
249 static unsigned long fake_depth
;
251 extern int do_mathemu(struct pt_regs
*, struct task_struct
*);
253 void do_fpe_trap(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
261 struct task_struct
*fpt
= last_task_used_math
;
263 struct task_struct
*fpt
= current
;
265 put_psr(get_psr() | PSR_EF
);
266 /* If nobody owns the fpu right now, just clear the
267 * error into our fake static buffer and hope it don't
268 * happen again. Thank you crashme...
273 if (!test_tsk_thread_flag(fpt
, TIF_USEDFPU
)) {
275 fpsave(&fake_regs
[0], &fake_fsr
, &fake_queue
[0], &fake_depth
);
276 regs
->psr
&= ~PSR_EF
;
279 fpsave(&fpt
->thread
.float_regs
[0], &fpt
->thread
.fsr
,
280 &fpt
->thread
.fpqueue
[0], &fpt
->thread
.fpqdepth
);
282 printk("Hmm, FP exception, fsr was %016lx\n", fpt
->thread
.fsr
);
285 switch ((fpt
->thread
.fsr
& 0x1c000)) {
286 /* switch on the contents of the ftt [floating point trap type] field */
289 printk("IEEE_754_exception\n");
292 case (2 << 14): /* unfinished_FPop (underflow & co) */
293 case (3 << 14): /* unimplemented_FPop (quad stuff, maybe sqrt) */
294 ret
= do_mathemu(regs
, fpt
);
298 printk("sequence_error (OS bug...)\n");
301 printk("hardware_error (uhoh!)\n");
304 printk("invalid_fp_register (user error)\n");
306 #endif /* DEBUG_FPU */
308 /* If we successfully emulated the FPop, we pretend the trap never happened :-> */
310 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
313 /* nope, better SIGFPE the offending process... */
316 clear_tsk_thread_flag(fpt
, TIF_USEDFPU
);
319 /* The first fsr store/load we tried trapped,
320 * the second one will not (we hope).
322 printk("WARNING: FPU exception from kernel mode. at pc=%08lx\n",
324 regs
->pc
= regs
->npc
;
328 die_if_kernel("Too many Penguin-FPU traps from kernel mode",
333 fsr
= fpt
->thread
.fsr
;
334 info
.si_signo
= SIGFPE
;
336 info
.si_addr
= (void __user
*)pc
;
338 info
.si_code
= __SI_FAULT
;
339 if ((fsr
& 0x1c000) == (1 << 14)) {
341 info
.si_code
= FPE_FLTINV
;
343 info
.si_code
= FPE_FLTOVF
;
345 info
.si_code
= FPE_FLTUND
;
347 info
.si_code
= FPE_FLTDIV
;
349 info
.si_code
= FPE_FLTRES
;
351 send_sig_info(SIGFPE
, &info
, fpt
);
353 last_task_used_math
= NULL
;
355 regs
->psr
&= ~PSR_EF
;
360 void handle_tag_overflow(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
366 die_if_kernel("Penguin overflow trap from kernel mode", regs
);
367 info
.si_signo
= SIGEMT
;
369 info
.si_code
= EMT_TAGOVF
;
370 info
.si_addr
= (void __user
*)pc
;
372 send_sig_info(SIGEMT
, &info
, current
);
375 void handle_watchpoint(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
379 printk("Watchpoint detected at PC %08lx NPC %08lx PSR %08lx\n",
383 panic("Tell me what a watchpoint trap is, and I'll then deal "
384 "with such a beast...");
387 void handle_reg_access(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
393 printk("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n",
396 info
.si_signo
= SIGBUS
;
398 info
.si_code
= BUS_OBJERR
;
399 info
.si_addr
= (void __user
*)pc
;
401 force_sig_info(SIGBUS
, &info
, current
);
404 void handle_cp_disabled(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
409 info
.si_signo
= SIGILL
;
411 info
.si_code
= ILL_COPROC
;
412 info
.si_addr
= (void __user
*)pc
;
414 send_sig_info(SIGILL
, &info
, current
);
417 void handle_cp_exception(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
423 printk("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n",
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_hw_divzero(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
439 info
.si_signo
= SIGFPE
;
441 info
.si_code
= FPE_INTDIV
;
442 info
.si_addr
= (void __user
*)pc
;
444 send_sig_info(SIGFPE
, &info
, current
);
447 #ifdef CONFIG_DEBUG_BUGVERBOSE
448 void do_BUG(const char *file
, int line
)
450 // bust_spinlocks(1); XXX Not in our original BUG()
451 printk("kernel BUG at %s:%d!\n", file
, line
);
455 /* Since we have our mappings set up, on multiprocessors we can spin them
456 * up here so that timer interrupts work during initialization.
459 extern void sparc_cpu_startup(void);
463 extern void thread_info_offsets_are_bolixed_pete(void);
465 /* Force linker to barf if mismatched */
466 if (TI_UWINMASK
!= offsetof(struct thread_info
, uwinmask
) ||
467 TI_TASK
!= offsetof(struct thread_info
, task
) ||
468 TI_EXECDOMAIN
!= offsetof(struct thread_info
, exec_domain
) ||
469 TI_FLAGS
!= offsetof(struct thread_info
, flags
) ||
470 TI_CPU
!= offsetof(struct thread_info
, cpu
) ||
471 TI_PREEMPT
!= offsetof(struct thread_info
, preempt_count
) ||
472 TI_SOFTIRQ
!= offsetof(struct thread_info
, softirq_count
) ||
473 TI_HARDIRQ
!= offsetof(struct thread_info
, hardirq_count
) ||
474 TI_KSP
!= offsetof(struct thread_info
, ksp
) ||
475 TI_KPC
!= offsetof(struct thread_info
, kpc
) ||
476 TI_KPSR
!= offsetof(struct thread_info
, kpsr
) ||
477 TI_KWIM
!= offsetof(struct thread_info
, kwim
) ||
478 TI_REG_WINDOW
!= offsetof(struct thread_info
, reg_window
) ||
479 TI_RWIN_SPTRS
!= offsetof(struct thread_info
, rwbuf_stkptrs
) ||
480 TI_W_SAVED
!= offsetof(struct thread_info
, w_saved
))
481 thread_info_offsets_are_bolixed_pete();
483 /* Attach to the address space of init_task. */
484 atomic_inc(&init_mm
.mm_count
);
485 current
->active_mm
= &init_mm
;
487 /* NOTE: Other cpus have this done as they are started
This page took 0.056906 seconds and 6 git commands to generate.