~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/sparc/kernel/traps.c

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.14 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.57 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.138 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.193 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* $Id: traps.c,v 1.64 2000/09/03 15:00:49 anton Exp $
  2  * arch/sparc/kernel/traps.c
  3  *
  4  * Copyright 1995 David S. Miller (davem@caip.rutgers.edu)
  5  * Copyright 2000 Jakub Jelinek (jakub@redhat.com)
  6  */
  7 
  8 /*
  9  * I hate traps on the sparc, grrr...
 10  */
 11 
 12 #include <linux/config.h>
 13 #include <linux/sched.h>  /* for jiffies */
 14 #include <linux/kernel.h>
 15 #include <linux/signal.h>
 16 #include <linux/smp.h>
 17 #include <linux/smp_lock.h>
 18 
 19 #include <asm/delay.h>
 20 #include <asm/system.h>
 21 #include <asm/ptrace.h>
 22 #include <asm/oplib.h>
 23 #include <asm/page.h>
 24 #include <asm/pgtable.h>
 25 #include <asm/kdebug.h>
 26 #include <asm/unistd.h>
 27 #include <asm/traps.h>
 28 
 29 /* #define TRAP_DEBUG */
 30 
 31 struct trap_trace_entry {
 32         unsigned long pc;
 33         unsigned long type;
 34 };
 35 
 36 int trap_curbuf = 0;
 37 struct trap_trace_entry trapbuf[1024];
 38 
 39 void syscall_trace_entry(struct pt_regs *regs)
 40 {
 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]);
 44 }
 45 
 46 void syscall_trace_exit(struct pt_regs *regs)
 47 {
 48 }
 49 
 50 void sun4m_nmi(struct pt_regs *regs)
 51 {
 52         unsigned long afsr, afar;
 53 
 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"
 58                              "mov 0x600, %%g1\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");
 63         show_regs(regs);
 64         prom_halt();
 65 }
 66 
 67 void sun4d_nmi(struct pt_regs *regs)
 68 {
 69         printk("Aieee: sun4d NMI received!\n");
 70         printk("you lose buddy boy...\n");
 71         show_regs(regs);
 72         prom_halt();
 73 }
 74 
 75 void instruction_dump (unsigned long *pc)
 76 {
 77         int i;
 78         
 79         if((((unsigned long) pc) & 3))
 80                 return;
 81 
 82         for(i = -3; i < 6; i++)
 83                 printk("%c%08lx%c",i?' ':'<',pc[i],i?' ':'>');
 84         printk("\n");
 85 }
 86 
 87 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
 88 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
 89 
 90 void die_if_kernel(char *str, struct pt_regs *regs)
 91 {
 92         static int die_counter;
 93         int count = 0;
 94 
 95         /* Amuse the user. */
 96         printk(
 97 "              \\|/ ____ \\|/\n"
 98 "              \"@'/ ,. \\`@\"\n"
 99 "              /_| \\__/ |_\\\n"
100 "                 \\__U_/\n");
101 
102         printk("%s(%d): %s [#%d]\n", current->comm, current->pid, str, ++die_counter);
103         show_regs(regs);
104 
105         __SAVE; __SAVE; __SAVE; __SAVE;
106         __SAVE; __SAVE; __SAVE; __SAVE;
107         __RESTORE; __RESTORE; __RESTORE; __RESTORE;
108         __RESTORE; __RESTORE; __RESTORE; __RESTORE;
109 
110         {
111                 struct reg_window *rw = (struct reg_window *)regs->u_regs[UREG_FP];
112 
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.
116                  */
117                 while(rw                                        &&
118                       count++ < 30                              &&
119                       (((unsigned long) rw) >= PAGE_OFFSET)     &&
120                       !(((unsigned long) rw) & 0x7)) {
121                         printk("Caller[%08lx]\n", rw->ins[7]);
122                         rw = (struct reg_window *)rw->ins[6];
123                 }
124         }
125         printk("Instruction DUMP:");
126         instruction_dump ((unsigned long *) regs->pc);
127         if(regs->psr & PSR_PS)
128                 do_exit(SIGKILL);
129         do_exit(SIGSEGV);
130 }
131 
132 void do_hw_interrupt(unsigned long type, unsigned long psr, unsigned long pc)
133 {
134         siginfo_t info;
135 
136         if(type < 0x80) {
137                 /* Sun OS's puke from bad traps, Linux survives! */
138                 printk("Unimplemented Sparc TRAP, type = %02lx\n", type);
139                 die_if_kernel("Whee... Hello Mr. Penguin", current->thread.kregs);
140         }       
141 
142         if(psr & PSR_PS)
143                 die_if_kernel("Kernel bad trap", current->thread.kregs);
144 
145         info.si_signo = SIGILL;
146         info.si_errno = 0;
147         info.si_code = ILL_ILLTRP;
148         info.si_addr = (void *)pc;
149         info.si_trapno = type - 0x80;
150         force_sig_info(SIGILL, &info, current);
151 }
152 
153 void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
154                             unsigned long psr)
155 {
156         extern int do_user_muldiv (struct pt_regs *, unsigned long);
157         siginfo_t info;
158 
159         if(psr & PSR_PS)
160                 die_if_kernel("Kernel illegal instruction", regs);
161 #ifdef TRAP_DEBUG
162         printk("Ill instr. at pc=%08lx instruction is %08lx\n",
163                regs->pc, *(unsigned long *)regs->pc);
164 #endif
165         if (!do_user_muldiv (regs, pc))
166                 return;
167 
168         info.si_signo = SIGILL;
169         info.si_errno = 0;
170         info.si_code = ILL_ILLOPC;
171         info.si_addr = (void *)pc;
172         info.si_trapno = 0;
173         send_sig_info(SIGILL, &info, current);
174 }
175 
176 void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
177                          unsigned long psr)
178 {
179         siginfo_t info;
180 
181         if(psr & PSR_PS)
182                 die_if_kernel("Penguin instruction from Penguin mode??!?!", regs);
183         info.si_signo = SIGILL;
184         info.si_errno = 0;
185         info.si_code = ILL_PRVOPC;
186         info.si_addr = (void *)pc;
187         info.si_trapno = 0;
188         send_sig_info(SIGILL, &info, current);
189 }
190 
191 /* XXX User may want to be allowed to do this. XXX */
192 
193 void do_memaccess_unaligned(struct pt_regs *regs, unsigned long pc, unsigned long npc,
194                             unsigned long psr)
195 {
196         siginfo_t info;
197 
198         if(regs->psr & PSR_PS) {
199                 printk("KERNEL MNA at pc %08lx npc %08lx called by %08lx\n", pc, npc,
200                        regs->u_regs[UREG_RETPC]);
201                 die_if_kernel("BOGUS", regs);
202                 /* die_if_kernel("Kernel MNA access", regs); */
203         }
204 #if 0
205         show_regs (regs);
206         instruction_dump ((unsigned long *) regs->pc);
207         printk ("do_MNA!\n");
208 #endif
209         info.si_signo = SIGBUS;
210         info.si_errno = 0;
211         info.si_code = BUS_ADRALN;
212         info.si_addr = /* FIXME: Should dig out mna address */ (void *)0;
213         info.si_trapno = 0;
214         send_sig_info(SIGBUS, &info, current);
215 }
216 
217 extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
218                    void *fpqueue, unsigned long *fpqdepth);
219 extern void fpload(unsigned long *fpregs, unsigned long *fsr);
220 
221 static unsigned long init_fsr = 0x0UL;
222 static unsigned long init_fregs[32] __attribute__ ((aligned (8))) =
223                 { ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
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 
228 void do_fpd_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,
229                  unsigned long psr)
230 {
231         /* Sanity check... */
232         if(psr & PSR_PS)
233                 die_if_kernel("Kernel gets FloatingPenguinUnit disabled trap", regs);
234 
235         put_psr(get_psr() | PSR_EF);    /* Allow FPU ops. */
236         regs->psr |= PSR_EF;
237 #ifndef CONFIG_SMP
238         if(last_task_used_math == current)
239                 return;
240         if(last_task_used_math) {
241                 /* Other processes fpu state, save away */
242                 struct task_struct *fptask = last_task_used_math;
243                 fpsave(&fptask->thread.float_regs[0], &fptask->thread.fsr,
244                        &fptask->thread.fpqueue[0], &fptask->thread.fpqdepth);
245         }
246         last_task_used_math = current;
247         if(current->used_math) {
248                 fpload(&current->thread.float_regs[0], &current->thread.fsr);
249         } else {
250                 /* Set initial sane state. */
251                 fpload(&init_fregs[0], &init_fsr);
252                 current->used_math = 1;
253         }
254 #else
255         if(!current->used_math) {
256                 fpload(&init_fregs[0], &init_fsr);
257                 current->used_math = 1;
258         } else {
259                 fpload(&current->thread.float_regs[0], &current->thread.fsr);
260         }
261         current->flags |= PF_USEDFPU;
262 #endif
263 }
264 
265 static unsigned long fake_regs[32] __attribute__ ((aligned (8)));
266 static unsigned long fake_fsr;
267 static unsigned long fake_queue[32] __attribute__ ((aligned (8)));
268 static unsigned long fake_depth;
269 
270 extern int do_mathemu(struct pt_regs *, struct task_struct *);
271 
272 void do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,
273                  unsigned long psr)
274 {
275         static int calls;
276         siginfo_t info;
277         unsigned long fsr;
278         int ret = 0;
279 #ifndef CONFIG_SMP
280         struct task_struct *fpt = last_task_used_math;
281 #else
282         struct task_struct *fpt = current;
283 #endif
284         put_psr(get_psr() | PSR_EF);
285         /* If nobody owns the fpu right now, just clear the
286          * error into our fake static buffer and hope it don't
287          * happen again.  Thank you crashme...
288          */
289 #ifndef CONFIG_SMP
290         if(!fpt) {
291 #else
292         if(!(fpt->flags & PF_USEDFPU)) {
293 #endif
294                 fpsave(&fake_regs[0], &fake_fsr, &fake_queue[0], &fake_depth);
295                 regs->psr &= ~PSR_EF;
296                 return;
297         }
298         fpsave(&fpt->thread.float_regs[0], &fpt->thread.fsr,
299                &fpt->thread.fpqueue[0], &fpt->thread.fpqdepth);
300 #ifdef DEBUG_FPU
301         printk("Hmm, FP exception, fsr was %016lx\n", fpt->thread.fsr);
302 #endif
303 
304         switch ((fpt->thread.fsr & 0x1c000)) {
305         /* switch on the contents of the ftt [floating point trap type] field */
306 #ifdef DEBUG_FPU
307         case (1 << 14):
308                 printk("IEEE_754_exception\n");
309                 break;
310 #endif
311         case (2 << 14):  /* unfinished_FPop (underflow & co) */
312         case (3 << 14):  /* unimplemented_FPop (quad stuff, maybe sqrt) */
313                 ret = do_mathemu(regs, fpt);
314                 break;
315 #ifdef DEBUG_FPU
316         case (4 << 14):
317                 printk("sequence_error (OS bug...)\n");
318                 break;
319         case (5 << 14):
320                 printk("hardware_error (uhoh!)\n");
321                 break;
322         case (6 << 14):
323                 printk("invalid_fp_register (user error)\n");
324                 break;
325 #endif /* DEBUG_FPU */
326         }
327         /* If we successfully emulated the FPop, we pretend the trap never happened :-> */
328         if (ret) {
329                 fpload(&current->thread.float_regs[0], &current->thread.fsr);
330                 return;
331         }
332         /* nope, better SIGFPE the offending process... */
333                
334 #ifdef CONFIG_SMP
335         fpt->flags &= ~PF_USEDFPU;
336 #endif
337         if(psr & PSR_PS) {
338                 /* The first fsr store/load we tried trapped,
339                  * the second one will not (we hope).
340                  */
341                 printk("WARNING: FPU exception from kernel mode. at pc=%08lx\n",
342                        regs->pc);
343                 regs->pc = regs->npc;
344                 regs->npc += 4;
345                 calls++;
346                 if(calls > 2)
347                         die_if_kernel("Too many Penguin-FPU traps from kernel mode",
348                                       regs);
349                 return;
350         }
351 
352         fsr = fpt->thread.fsr;
353         info.si_signo = SIGFPE;
354         info.si_errno = 0;
355         info.si_addr = (void *)pc;
356         info.si_trapno = 0;
357         info.si_code = __SI_FAULT;
358         if ((fsr & 0x1c000) == (1 << 14)) {
359                 if (fsr & 0x10)
360                         info.si_code = FPE_FLTINV;
361                 else if (fsr & 0x08)
362                         info.si_code = FPE_FLTOVF;
363                 else if (fsr & 0x04)
364                         info.si_code = FPE_FLTUND;
365                 else if (fsr & 0x02)
366                         info.si_code = FPE_FLTDIV;
367                 else if (fsr & 0x01)
368                         info.si_code = FPE_FLTRES;
369         }
370         send_sig_info(SIGFPE, &info, fpt);
371 #ifndef CONFIG_SMP
372         last_task_used_math = NULL;
373 #endif
374         regs->psr &= ~PSR_EF;
375         if(calls > 0)
376                 calls=0;
377 }
378 
379 void handle_tag_overflow(struct pt_regs *regs, unsigned long pc, unsigned long npc,
380                          unsigned long psr)
381 {
382         siginfo_t info;
383 
384         if(psr & PSR_PS)
385                 die_if_kernel("Penguin overflow trap from kernel mode", regs);
386         info.si_signo = SIGEMT;
387         info.si_errno = 0;
388         info.si_code = EMT_TAGOVF;
389         info.si_addr = (void *)pc;
390         info.si_trapno = 0;
391         send_sig_info(SIGEMT, &info, current);
392 }
393 
394 void handle_watchpoint(struct pt_regs *regs, unsigned long pc, unsigned long npc,
395                        unsigned long psr)
396 {
397 #ifdef TRAP_DEBUG
398         printk("Watchpoint detected at PC %08lx NPC %08lx PSR %08lx\n",
399                pc, npc, psr);
400 #endif
401         if(psr & PSR_PS)
402                 panic("Tell me what a watchpoint trap is, and I'll then deal "
403                       "with such a beast...");
404 }
405 
406 void handle_reg_access(struct pt_regs *regs, unsigned long pc, unsigned long npc,
407                        unsigned long psr)
408 {
409         siginfo_t info;
410 
411 #ifdef TRAP_DEBUG
412         printk("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n",
413                pc, npc, psr);
414 #endif
415         info.si_signo = SIGBUS;
416         info.si_errno = 0;
417         info.si_code = BUS_OBJERR;
418         info.si_addr = (void *)pc;
419         info.si_trapno = 0;
420         force_sig_info(SIGBUS, &info, current);
421 }
422 
423 void handle_cp_disabled(struct pt_regs *regs, unsigned long pc, unsigned long npc,
424                         unsigned long psr)
425 {
426         siginfo_t info;
427 
428         info.si_signo = SIGILL;
429         info.si_errno = 0;
430         info.si_code = ILL_COPROC;
431         info.si_addr = (void *)pc;
432         info.si_trapno = 0;
433         send_sig_info(SIGILL, &info, current);
434 }
435 
436 void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long npc,
437                          unsigned long psr)
438 {
439         siginfo_t info;
440 
441 #ifdef TRAP_DEBUG
442         printk("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n",
443                pc, npc, psr);
444 #endif
445         info.si_signo = SIGILL;
446         info.si_errno = 0;
447         info.si_code = ILL_COPROC;
448         info.si_addr = (void *)pc;
449         info.si_trapno = 0;
450         send_sig_info(SIGILL, &info, current);
451 }
452 
453 void handle_hw_divzero(struct pt_regs *regs, unsigned long pc, unsigned long npc,
454                        unsigned long psr)
455 {
456         siginfo_t info;
457 
458         info.si_signo = SIGFPE;
459         info.si_errno = 0;
460         info.si_code = FPE_INTDIV;
461         info.si_addr = (void *)pc;
462         info.si_trapno = 0;
463         send_sig_info(SIGFPE, &info, current);
464 }
465 
466 #ifdef CONFIG_DEBUG_BUGVERBOSE
467 void do_BUG(const char *file, int line)
468 {
469         // bust_spinlocks(1);   XXX Not in our original BUG()
470         printk("kernel BUG at %s:%d!\n", file, line);
471 }
472 #endif
473 
474 /* Since we have our mappings set up, on multiprocessors we can spin them
475  * up here so that timer interrupts work during initialization.
476  */
477 
478 extern void sparc_cpu_startup(void);
479 
480 int linux_smp_still_initting;
481 unsigned int thiscpus_tbr;
482 int thiscpus_mid;
483 
484 void trap_init(void)
485 {
486         extern void thread_info_offsets_are_bolixed_pete(void);
487 
488         /* Force linker to barf if mismatched */
489         if (TI_UWINMASK    != offsetof(struct thread_info, uwinmask) ||
490             TI_TASK        != offsetof(struct thread_info, task) ||
491             TI_EXECDOMAIN  != offsetof(struct thread_info, exec_domain) ||
492             TI_FLAGS       != offsetof(struct thread_info, flags) ||
493             TI_CPU         != offsetof(struct thread_info, cpu) ||
494             TI_PREEMPT     != offsetof(struct thread_info, preempt_count) ||
495             TI_SOFTIRQ     != offsetof(struct thread_info, softirq_count) ||
496             TI_HARDIRQ     != offsetof(struct thread_info, hardirq_count) ||
497             TI_KSP         != offsetof(struct thread_info, ksp) ||
498             TI_KPC         != offsetof(struct thread_info, kpc) ||
499             TI_KPSR        != offsetof(struct thread_info, kpsr) ||
500             TI_KWIM        != offsetof(struct thread_info, kwim))
501                 thread_info_offsets_are_bolixed_pete();
502 
503         /* Attach to the address space of init_task. */
504         atomic_inc(&init_mm.mm_count);
505         current->active_mm = &init_mm;
506 
507         /* NOTE: Other cpus have this done as they are started
508          *       up on SMP.
509          */
510 }
511 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp