1 /* $Id: traps.c,v 1.64 2000/09/03 15:00:49 anton Exp $
2 * arch/sparc/kernel/traps.c
4 * Copyright 1995 David S. Miller (davem@caip.rutgers.edu)
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/kallsyms.h>
15 #include <linux/signal.h>
16 #include <linux/smp.h>
17 #include <linux/smp_lock.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/kdebug.h>
26 #include <asm/unistd.h>
27 #include <asm/traps.h>
29 /* #define TRAP_DEBUG */
31 struct trap_trace_entry
{
37 struct trap_trace_entry trapbuf
[1024];
39 void syscall_trace_entry(struct pt_regs
*regs
)
41 printk("%s[%d]: ", current
->comm
, current
->pid
);
42 printk("scall<%d> (could be %d)\n", (int) regs
->u_regs
[UREG_G1
],
43 (int) regs
->u_regs
[UREG_I0
]);
46 void syscall_trace_exit(struct pt_regs
*regs
)
50 void sun4m_nmi(struct pt_regs
*regs
)
52 unsigned long afsr
, afar
;
54 printk("Aieee: sun4m NMI received!\n");
55 /* XXX HyperSparc hack XXX */
56 __asm__
__volatile__("mov 0x500, %%g1\n\t"
57 "lda [%%g1] 0x4, %0\n\t"
59 "lda [%%g1] 0x4, %1\n\t" :
60 "=r" (afsr
), "=r" (afar
));
61 printk("afsr=%08lx afar=%08lx\n", afsr
, afar
);
62 printk("you lose buddy boy...\n");
67 void sun4d_nmi(struct pt_regs
*regs
)
69 printk("Aieee: sun4d NMI received!\n");
70 printk("you lose buddy boy...\n");
75 void instruction_dump (unsigned long *pc
)
79 if((((unsigned long) pc
) & 3))
82 for(i
= -3; i
< 6; i
++)
83 printk("%c%08lx%c",i
?' ':'<',pc
[i
],i
?' ':'>');
87 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
88 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
90 void die_if_kernel(char *str
, struct pt_regs
*regs
)
92 static int die_counter
;
102 printk("%s(%d): %s [#%d]\n", current
->comm
, current
->pid
, str
, ++die_counter
);
105 __SAVE
; __SAVE
; __SAVE
; __SAVE
;
106 __SAVE
; __SAVE
; __SAVE
; __SAVE
;
107 __RESTORE
; __RESTORE
; __RESTORE
; __RESTORE
;
108 __RESTORE
; __RESTORE
; __RESTORE
; __RESTORE
;
111 struct reg_window
*rw
= (struct reg_window
*)regs
->u_regs
[UREG_FP
];
113 /* Stop the back trace when we hit userland or we
114 * find some badly aligned kernel stack. Set an upper
115 * bound in case our stack is trashed and we loop.
119 (((unsigned long) rw
) >= PAGE_OFFSET
) &&
120 !(((unsigned long) rw
) & 0x7)) {
121 printk("Caller[%08lx]", rw
->ins
[7]);
122 print_symbol(": %s\n", rw
->ins
[7]);
123 rw
= (struct reg_window
*)rw
->ins
[6];
126 printk("Instruction DUMP:");
127 instruction_dump ((unsigned long *) regs
->pc
);
128 if(regs
->psr
& PSR_PS
)
133 void do_hw_interrupt(struct pt_regs
*regs
, unsigned long type
)
138 /* Sun OS's puke from bad traps, Linux survives! */
139 printk("Unimplemented Sparc TRAP, type = %02lx\n", type
);
140 die_if_kernel("Whee... Hello Mr. Penguin", regs
);
143 if(regs
->psr
& PSR_PS
)
144 die_if_kernel("Kernel bad trap", regs
);
146 info
.si_signo
= SIGILL
;
148 info
.si_code
= ILL_ILLTRP
;
149 info
.si_addr
= (void __user
*)regs
->pc
;
150 info
.si_trapno
= type
- 0x80;
151 force_sig_info(SIGILL
, &info
, current
);
154 void do_illegal_instruction(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
157 extern int do_user_muldiv (struct pt_regs
*, unsigned long);
161 die_if_kernel("Kernel illegal instruction", regs
);
163 printk("Ill instr. at pc=%08lx instruction is %08lx\n",
164 regs
->pc
, *(unsigned long *)regs
->pc
);
166 if (!do_user_muldiv (regs
, pc
))
169 info
.si_signo
= SIGILL
;
171 info
.si_code
= ILL_ILLOPC
;
172 info
.si_addr
= (void __user
*)pc
;
174 send_sig_info(SIGILL
, &info
, current
);
177 void do_priv_instruction(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
183 die_if_kernel("Penguin instruction from Penguin mode??!?!", regs
);
184 info
.si_signo
= SIGILL
;
186 info
.si_code
= ILL_PRVOPC
;
187 info
.si_addr
= (void __user
*)pc
;
189 send_sig_info(SIGILL
, &info
, current
);
192 /* XXX User may want to be allowed to do this. XXX */
194 void do_memaccess_unaligned(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
199 if(regs
->psr
& PSR_PS
) {
200 printk("KERNEL MNA at pc %08lx npc %08lx called by %08lx\n", pc
, npc
,
201 regs
->u_regs
[UREG_RETPC
]);
202 die_if_kernel("BOGUS", regs
);
203 /* die_if_kernel("Kernel MNA access", regs); */
207 instruction_dump ((unsigned long *) regs
->pc
);
208 printk ("do_MNA!\n");
210 info
.si_signo
= SIGBUS
;
212 info
.si_code
= BUS_ADRALN
;
213 info
.si_addr
= /* FIXME: Should dig out mna address */ (void *)0;
215 send_sig_info(SIGBUS
, &info
, current
);
218 extern void fpsave(unsigned long *fpregs
, unsigned long *fsr
,
219 void *fpqueue
, unsigned long *fpqdepth
);
220 extern void fpload(unsigned long *fpregs
, unsigned long *fsr
);
222 static unsigned long init_fsr
= 0x0UL
;
223 static unsigned long init_fregs
[32] __attribute__ ((aligned (8))) =
224 { ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
225 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
226 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
227 ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL };
229 void do_fpd_trap(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
232 /* Sanity check... */
234 die_if_kernel("Kernel gets FloatingPenguinUnit disabled trap", regs
);
236 put_psr(get_psr() | PSR_EF
); /* Allow FPU ops. */
239 if(last_task_used_math
== current
)
241 if(last_task_used_math
) {
242 /* Other processes fpu state, save away */
243 struct task_struct
*fptask
= last_task_used_math
;
244 fpsave(&fptask
->thread
.float_regs
[0], &fptask
->thread
.fsr
,
245 &fptask
->thread
.fpqueue
[0], &fptask
->thread
.fpqdepth
);
247 last_task_used_math
= current
;
249 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
251 /* Set initial sane state. */
252 fpload(&init_fregs
[0], &init_fsr
);
257 fpload(&init_fregs
[0], &init_fsr
);
260 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
262 current_thread_info()->flags
|= _TIF_USEDFPU
;
266 static unsigned long fake_regs
[32] __attribute__ ((aligned (8)));
267 static unsigned long fake_fsr
;
268 static unsigned long fake_queue
[32] __attribute__ ((aligned (8)));
269 static unsigned long fake_depth
;
271 extern int do_mathemu(struct pt_regs
*, struct task_struct
*);
273 void do_fpe_trap(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
281 struct task_struct
*fpt
= last_task_used_math
;
283 struct task_struct
*fpt
= current
;
285 put_psr(get_psr() | PSR_EF
);
286 /* If nobody owns the fpu right now, just clear the
287 * error into our fake static buffer and hope it don't
288 * happen again. Thank you crashme...
293 if(!(task_thread_info(fpt
)->flags
& _TIF_USEDFPU
)) {
295 fpsave(&fake_regs
[0], &fake_fsr
, &fake_queue
[0], &fake_depth
);
296 regs
->psr
&= ~PSR_EF
;
299 fpsave(&fpt
->thread
.float_regs
[0], &fpt
->thread
.fsr
,
300 &fpt
->thread
.fpqueue
[0], &fpt
->thread
.fpqdepth
);
302 printk("Hmm, FP exception, fsr was %016lx\n", fpt
->thread
.fsr
);
305 switch ((fpt
->thread
.fsr
& 0x1c000)) {
306 /* switch on the contents of the ftt [floating point trap type] field */
309 printk("IEEE_754_exception\n");
312 case (2 << 14): /* unfinished_FPop (underflow & co) */
313 case (3 << 14): /* unimplemented_FPop (quad stuff, maybe sqrt) */
314 ret
= do_mathemu(regs
, fpt
);
318 printk("sequence_error (OS bug...)\n");
321 printk("hardware_error (uhoh!)\n");
324 printk("invalid_fp_register (user error)\n");
326 #endif /* DEBUG_FPU */
328 /* If we successfully emulated the FPop, we pretend the trap never happened :-> */
330 fpload(¤t
->thread
.float_regs
[0], ¤t
->thread
.fsr
);
333 /* nope, better SIGFPE the offending process... */
336 task_thread_info(fpt
)->flags
&= ~_TIF_USEDFPU
;
339 /* The first fsr store/load we tried trapped,
340 * the second one will not (we hope).
342 printk("WARNING: FPU exception from kernel mode. at pc=%08lx\n",
344 regs
->pc
= regs
->npc
;
348 die_if_kernel("Too many Penguin-FPU traps from kernel mode",
353 fsr
= fpt
->thread
.fsr
;
354 info
.si_signo
= SIGFPE
;
356 info
.si_addr
= (void __user
*)pc
;
358 info
.si_code
= __SI_FAULT
;
359 if ((fsr
& 0x1c000) == (1 << 14)) {
361 info
.si_code
= FPE_FLTINV
;
363 info
.si_code
= FPE_FLTOVF
;
365 info
.si_code
= FPE_FLTUND
;
367 info
.si_code
= FPE_FLTDIV
;
369 info
.si_code
= FPE_FLTRES
;
371 send_sig_info(SIGFPE
, &info
, fpt
);
373 last_task_used_math
= NULL
;
375 regs
->psr
&= ~PSR_EF
;
380 void handle_tag_overflow(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
386 die_if_kernel("Penguin overflow trap from kernel mode", regs
);
387 info
.si_signo
= SIGEMT
;
389 info
.si_code
= EMT_TAGOVF
;
390 info
.si_addr
= (void __user
*)pc
;
392 send_sig_info(SIGEMT
, &info
, current
);
395 void handle_watchpoint(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
399 printk("Watchpoint detected at PC %08lx NPC %08lx PSR %08lx\n",
403 panic("Tell me what a watchpoint trap is, and I'll then deal "
404 "with such a beast...");
407 void handle_reg_access(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
413 printk("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n",
416 info
.si_signo
= SIGBUS
;
418 info
.si_code
= BUS_OBJERR
;
419 info
.si_addr
= (void __user
*)pc
;
421 force_sig_info(SIGBUS
, &info
, current
);
424 void handle_cp_disabled(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
429 info
.si_signo
= SIGILL
;
431 info
.si_code
= ILL_COPROC
;
432 info
.si_addr
= (void __user
*)pc
;
434 send_sig_info(SIGILL
, &info
, current
);
437 void handle_cp_exception(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
443 printk("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n",
446 info
.si_signo
= SIGILL
;
448 info
.si_code
= ILL_COPROC
;
449 info
.si_addr
= (void __user
*)pc
;
451 send_sig_info(SIGILL
, &info
, current
);
454 void handle_hw_divzero(struct pt_regs
*regs
, unsigned long pc
, unsigned long npc
,
459 info
.si_signo
= SIGFPE
;
461 info
.si_code
= FPE_INTDIV
;
462 info
.si_addr
= (void __user
*)pc
;
464 send_sig_info(SIGFPE
, &info
, current
);
467 #ifdef CONFIG_DEBUG_BUGVERBOSE
468 void do_BUG(const char *file
, int line
)
470 // bust_spinlocks(1); XXX Not in our original BUG()
471 printk("kernel BUG at %s:%d!\n", file
, line
);
475 /* Since we have our mappings set up, on multiprocessors we can spin them
476 * up here so that timer interrupts work during initialization.
479 extern void sparc_cpu_startup(void);
481 int linux_smp_still_initting
;
482 unsigned int thiscpus_tbr
;
487 extern void thread_info_offsets_are_bolixed_pete(void);
489 /* Force linker to barf if mismatched */
490 if (TI_UWINMASK
!= offsetof(struct thread_info
, uwinmask
) ||
491 TI_TASK
!= offsetof(struct thread_info
, task
) ||
492 TI_EXECDOMAIN
!= offsetof(struct thread_info
, exec_domain
) ||
493 TI_FLAGS
!= offsetof(struct thread_info
, flags
) ||
494 TI_CPU
!= offsetof(struct thread_info
, cpu
) ||
495 TI_PREEMPT
!= offsetof(struct thread_info
, preempt_count
) ||
496 TI_SOFTIRQ
!= offsetof(struct thread_info
, softirq_count
) ||
497 TI_HARDIRQ
!= offsetof(struct thread_info
, hardirq_count
) ||
498 TI_KSP
!= offsetof(struct thread_info
, ksp
) ||
499 TI_KPC
!= offsetof(struct thread_info
, kpc
) ||
500 TI_KPSR
!= offsetof(struct thread_info
, kpsr
) ||
501 TI_KWIM
!= offsetof(struct thread_info
, kwim
) ||
502 TI_REG_WINDOW
!= offsetof(struct thread_info
, reg_window
) ||
503 TI_RWIN_SPTRS
!= offsetof(struct thread_info
, rwbuf_stkptrs
) ||
504 TI_W_SAVED
!= offsetof(struct thread_info
, w_saved
))
505 thread_info_offsets_are_bolixed_pete();
507 /* Attach to the address space of init_task. */
508 atomic_inc(&init_mm
.mm_count
);
509 current
->active_mm
= &init_mm
;
511 /* NOTE: Other cpus have this done as they are started