]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/sparc/kernel/traps_32.c
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/sched/debug.h>
14 #include <linux/kernel.h>
15 #include <linux/signal.h>
16 #include <linux/smp.h>
17 #include <linux/kdebug.h>
18 #include <linux/export.h>
20 #include <asm/delay.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 __noreturn
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
);
62 add_taint(TAINT_DIE
, LOCKDEP_NOW_UNRELIABLE
);
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
);
125 info
.si_signo
= SIGILL
;
127 info
.si_code
= ILL_ILLOPC
;
128 info
.si_addr
= (void __user
*)pc
;
130 send_sig_info(SIGILL
, &info
, current
);
133 void do_priv_instruction(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
139 die_if_kernel("Penguin instruction from Penguin mode??!?!", regs
);
140 info
.si_signo
= SIGILL
;
142 info
.si_code
= ILL_PRVOPC
;
143 info
.si_addr
= (void __user
*)pc
;
145 send_sig_info(SIGILL
, &info
, current
);
148 /* XXX User may want to be allowed to do this. XXX */
150 void do_memaccess_unaligned(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
155 if(regs
->psr
& PSR_PS
) {
156 printk("KERNEL MNA at pc %08lx npc %08lx called by %08lx\n", pc
, npc
,
157 regs
->u_regs
[UREG_RETPC
]);
158 die_if_kernel("BOGUS", regs
);
159 /* die_if_kernel("Kernel MNA access", regs); */
163 instruction_dump ((unsigned long *) regs
->pc
);
164 printk ("do_MNA!\n");
166 info
.si_signo
= SIGBUS
;
168 info
.si_code
= BUS_ADRALN
;
169 info
.si_addr
= /* FIXME: Should dig out mna address */ (void *)0;
171 send_sig_info(SIGBUS
, &info
, current
);
174 static unsigned long init_fsr
= 0x0UL
;
175 static unsigned long init_fregs
[32] __attribute__ ((aligned (8))) =
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,
179 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL };
181 void do_fpd_trap(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
184 /* Sanity check... */
186 die_if_kernel("Kernel gets FloatingPenguinUnit disabled trap", regs
);
188 put_psr(get_psr() | PSR_EF
); /* Allow FPU ops. */
191 if(last_task_used_math
== current
)
193 if(last_task_used_math
) {
194 /* Other processes fpu state, save away */
195 struct task_struct
*fptask
= last_task_used_math
;
196 fpsave(&fptask
->thread
.float_regs
[0], &fptask
->thread
.fsr
,
197 &fptask
->thread
.fpqueue
[0], &fptask
->thread
.fpqdepth
);
199 last_task_used_math
= current
;
201 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
203 /* Set initial sane state. */
204 fpload(&init_fregs
[0], &init_fsr
);
209 fpload(&init_fregs
[0], &init_fsr
);
212 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
214 set_thread_flag(TIF_USEDFPU
);
218 static unsigned long fake_regs
[32] __attribute__ ((aligned (8)));
219 static unsigned long fake_fsr
;
220 static unsigned long fake_queue
[32] __attribute__ ((aligned (8)));
221 static unsigned long fake_depth
;
223 void do_fpe_trap(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
231 struct task_struct
*fpt
= last_task_used_math
;
233 struct task_struct
*fpt
= current
;
235 put_psr(get_psr() | PSR_EF
);
236 /* If nobody owns the fpu right now, just clear the
237 * error into our fake static buffer and hope it don't
238 * happen again. Thank you crashme...
243 if (!test_tsk_thread_flag(fpt
, TIF_USEDFPU
)) {
245 fpsave(&fake_regs
[0], &fake_fsr
, &fake_queue
[0], &fake_depth
);
246 regs
->psr
&= ~PSR_EF
;
249 fpsave(&fpt
->thread
.float_regs
[0], &fpt
->thread
.fsr
,
250 &fpt
->thread
.fpqueue
[0], &fpt
->thread
.fpqdepth
);
252 printk("Hmm, FP exception, fsr was %016lx\n", fpt
->thread
.fsr
);
255 switch ((fpt
->thread
.fsr
& 0x1c000)) {
256 /* switch on the contents of the ftt [floating point trap type] field */
259 printk("IEEE_754_exception\n");
262 case (2 << 14): /* unfinished_FPop (underflow & co) */
263 case (3 << 14): /* unimplemented_FPop (quad stuff, maybe sqrt) */
264 ret
= do_mathemu(regs
, fpt
);
268 printk("sequence_error (OS bug...)\n");
271 printk("hardware_error (uhoh!)\n");
274 printk("invalid_fp_register (user error)\n");
276 #endif /* DEBUG_FPU */
278 /* If we successfully emulated the FPop, we pretend the trap never happened :-> */
280 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
283 /* nope, better SIGFPE the offending process... */
286 clear_tsk_thread_flag(fpt
, TIF_USEDFPU
);
289 /* The first fsr store/load we tried trapped,
290 * the second one will not (we hope).
292 printk("WARNING: FPU exception from kernel mode. at pc=%08lx\n",
294 regs
->pc
= regs
->npc
;
298 die_if_kernel("Too many Penguin-FPU traps from kernel mode",
303 fsr
= fpt
->thread
.fsr
;
304 info
.si_signo
= SIGFPE
;
306 info
.si_addr
= (void __user
*)pc
;
308 info
.si_code
= __SI_FAULT
;
309 if ((fsr
& 0x1c000) == (1 << 14)) {
311 info
.si_code
= FPE_FLTINV
;
313 info
.si_code
= FPE_FLTOVF
;
315 info
.si_code
= FPE_FLTUND
;
317 info
.si_code
= FPE_FLTDIV
;
319 info
.si_code
= FPE_FLTRES
;
321 send_sig_info(SIGFPE
, &info
, fpt
);
323 last_task_used_math
= NULL
;
325 regs
->psr
&= ~PSR_EF
;
330 void handle_tag_overflow(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
336 die_if_kernel("Penguin overflow trap from kernel mode", regs
);
337 info
.si_signo
= SIGEMT
;
339 info
.si_code
= EMT_TAGOVF
;
340 info
.si_addr
= (void __user
*)pc
;
342 send_sig_info(SIGEMT
, &info
, current
);
345 void handle_watchpoint(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
349 printk("Watchpoint detected at PC %08lx NPC %08lx PSR %08lx\n",
353 panic("Tell me what a watchpoint trap is, and I'll then deal "
354 "with such a beast...");
357 void handle_reg_access(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
363 printk("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n",
366 info
.si_signo
= SIGBUS
;
368 info
.si_code
= BUS_OBJERR
;
369 info
.si_addr
= (void __user
*)pc
;
371 force_sig_info(SIGBUS
, &info
, current
);
374 void handle_cp_disabled(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
379 info
.si_signo
= SIGILL
;
381 info
.si_code
= ILL_COPROC
;
382 info
.si_addr
= (void __user
*)pc
;
384 send_sig_info(SIGILL
, &info
, current
);
387 void handle_cp_exception(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
393 printk("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n",
396 info
.si_signo
= SIGILL
;
398 info
.si_code
= ILL_COPROC
;
399 info
.si_addr
= (void __user
*)pc
;
401 send_sig_info(SIGILL
, &info
, current
);
404 void handle_hw_divzero(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
409 info
.si_signo
= SIGFPE
;
411 info
.si_code
= FPE_INTDIV
;
412 info
.si_addr
= (void __user
*)pc
;
414 send_sig_info(SIGFPE
, &info
, current
);
417 #ifdef CONFIG_DEBUG_BUGVERBOSE
418 void do_BUG(const char *file
, int line
)
420 // bust_spinlocks(1); XXX Not in our original BUG()
421 printk("kernel BUG at %s:%d!\n", file
, line
);
423 EXPORT_SYMBOL(do_BUG
);
426 /* Since we have our mappings set up, on multiprocessors we can spin them
427 * up here so that timer interrupts work during initialization.
432 extern void thread_info_offsets_are_bolixed_pete(void);
434 /* Force linker to barf if mismatched */
435 if (TI_UWINMASK
!= offsetof(struct thread_info
, uwinmask
) ||
436 TI_TASK
!= offsetof(struct thread_info
, task
) ||
437 TI_FLAGS
!= offsetof(struct thread_info
, flags
) ||
438 TI_CPU
!= offsetof(struct thread_info
, cpu
) ||
439 TI_PREEMPT
!= offsetof(struct thread_info
, preempt_count
) ||
440 TI_SOFTIRQ
!= offsetof(struct thread_info
, softirq_count
) ||
441 TI_HARDIRQ
!= offsetof(struct thread_info
, hardirq_count
) ||
442 TI_KSP
!= offsetof(struct thread_info
, ksp
) ||
443 TI_KPC
!= offsetof(struct thread_info
, kpc
) ||
444 TI_KPSR
!= offsetof(struct thread_info
, kpsr
) ||
445 TI_KWIM
!= offsetof(struct thread_info
, kwim
) ||
446 TI_REG_WINDOW
!= offsetof(struct thread_info
, reg_window
) ||
447 TI_RWIN_SPTRS
!= offsetof(struct thread_info
, rwbuf_stkptrs
) ||
448 TI_W_SAVED
!= offsetof(struct thread_info
, w_saved
))
449 thread_info_offsets_are_bolixed_pete();
451 /* Attach to the address space of init_task. */
453 current
->active_mm
= &init_mm
;
455 /* NOTE: Other cpus have this done as they are started