This source file includes following definitions.
- _send_sig
- die
- _exception
- show_stack
- trap_init
- breakpoint_c
- handle_unaligned_c
- handle_illegal_c
- handle_supervisor_instr
- handle_diverror_c
- unhandled_exception
- handle_trap_1_c
- handle_trap_2_c
- handle_trap_3_c
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 #include <linux/sched.h>
  14 #include <linux/sched/debug.h>
  15 #include <linux/kernel.h>
  16 #include <linux/signal.h>
  17 #include <linux/export.h>
  18 #include <linux/mm.h>
  19 #include <linux/ptrace.h>
  20 
  21 #include <asm/traps.h>
  22 #include <asm/sections.h>
  23 #include <linux/uaccess.h>
  24 
  25 static DEFINE_SPINLOCK(die_lock);
  26 
  27 static void _send_sig(int signo, int code, unsigned long addr)
  28 {
  29         force_sig_fault(signo, code, (void __user *) addr);
  30 }
  31 
  32 void die(const char *str, struct pt_regs *regs, long err)
  33 {
  34         console_verbose();
  35         spin_lock_irq(&die_lock);
  36         pr_warn("Oops: %s, sig: %ld\n", str, err);
  37         show_regs(regs);
  38         spin_unlock_irq(&die_lock);
  39         
  40 
  41 
  42 
  43         do_exit(err);
  44 }
  45 
  46 void _exception(int signo, struct pt_regs *regs, int code, unsigned long addr)
  47 {
  48         if (!user_mode(regs))
  49                 die("Exception in kernel mode", regs, signo);
  50 
  51         _send_sig(signo, code, addr);
  52 }
  53 
  54 
  55 
  56 
  57 
  58 int kstack_depth_to_print = 48;
  59 
  60 void show_stack(struct task_struct *task, unsigned long *stack)
  61 {
  62         unsigned long *endstack, addr;
  63         int i;
  64 
  65         if (!stack) {
  66                 if (task)
  67                         stack = (unsigned long *)task->thread.ksp;
  68                 else
  69                         stack = (unsigned long *)&stack;
  70         }
  71 
  72         addr = (unsigned long) stack;
  73         endstack = (unsigned long *) PAGE_ALIGN(addr);
  74 
  75         pr_emerg("Stack from %08lx:", (unsigned long)stack);
  76         for (i = 0; i < kstack_depth_to_print; i++) {
  77                 if (stack + 1 > endstack)
  78                         break;
  79                 if (i % 8 == 0)
  80                         pr_emerg("\n       ");
  81                 pr_emerg(" %08lx", *stack++);
  82         }
  83 
  84         pr_emerg("\nCall Trace:");
  85         i = 0;
  86         while (stack + 1 <= endstack) {
  87                 addr = *stack++;
  88                 
  89 
  90 
  91 
  92 
  93 
  94 
  95 
  96                 if (((addr >= (unsigned long) _stext) &&
  97                      (addr <= (unsigned long) _etext))) {
  98                         if (i % 4 == 0)
  99                                 pr_emerg("\n       ");
 100                         pr_emerg(" [<%08lx>]", addr);
 101                         i++;
 102                 }
 103         }
 104         pr_emerg("\n");
 105 }
 106 
 107 void __init trap_init(void)
 108 {
 109         
 110 }
 111 
 112 
 113 asmlinkage void breakpoint_c(struct pt_regs *fp)
 114 {
 115         
 116 
 117 
 118 
 119 
 120         fp->ea -= 4;
 121         _exception(SIGTRAP, fp, TRAP_BRKPT, fp->ea);
 122 }
 123 
 124 #ifndef CONFIG_NIOS2_ALIGNMENT_TRAP
 125 
 126 asmlinkage void handle_unaligned_c(struct pt_regs *fp, int cause)
 127 {
 128         unsigned long addr = RDCTL(CTL_BADADDR);
 129 
 130         cause >>= 2;
 131         fp->ea -= 4;
 132 
 133         if (fixup_exception(fp))
 134                 return;
 135 
 136         if (!user_mode(fp)) {
 137                 pr_alert("Unaligned access from kernel mode, this might be a hardware\n");
 138                 pr_alert("problem, dump registers and restart the instruction\n");
 139                 pr_alert("  BADADDR 0x%08lx\n", addr);
 140                 pr_alert("  cause   %d\n", cause);
 141                 pr_alert("  op-code 0x%08lx\n", *(unsigned long *)(fp->ea));
 142                 show_regs(fp);
 143                 return;
 144         }
 145 
 146         _exception(SIGBUS, fp, BUS_ADRALN, addr);
 147 }
 148 #endif 
 149 
 150 
 151 asmlinkage void handle_illegal_c(struct pt_regs *fp)
 152 {
 153         fp->ea -= 4;
 154         _exception(SIGILL, fp, ILL_ILLOPC, fp->ea);
 155 }
 156 
 157 
 158 asmlinkage void handle_supervisor_instr(struct pt_regs *fp)
 159 {
 160         fp->ea -= 4;
 161         _exception(SIGILL, fp, ILL_PRVOPC, fp->ea);
 162 }
 163 
 164 
 165 asmlinkage void handle_diverror_c(struct pt_regs *fp)
 166 {
 167         fp->ea -= 4;
 168         _exception(SIGFPE, fp, FPE_INTDIV, fp->ea);
 169 }
 170 
 171 
 172 asmlinkage void unhandled_exception(struct pt_regs *regs, int cause)
 173 {
 174         unsigned long addr = RDCTL(CTL_BADADDR);
 175 
 176         cause /= 4;
 177 
 178         pr_emerg("Unhandled exception #%d in %s mode (badaddr=0x%08lx)\n",
 179                         cause, user_mode(regs) ? "user" : "kernel", addr);
 180 
 181         regs->ea -= 4;
 182         show_regs(regs);
 183 
 184         pr_emerg("opcode: 0x%08lx\n", *(unsigned long *)(regs->ea));
 185 }
 186 
 187 asmlinkage void handle_trap_1_c(struct pt_regs *fp)
 188 {
 189         _send_sig(SIGUSR1, 0, fp->ea);
 190 }
 191 
 192 asmlinkage void handle_trap_2_c(struct pt_regs *fp)
 193 {
 194         _send_sig(SIGUSR2, 0, fp->ea);
 195 }
 196 
 197 asmlinkage void handle_trap_3_c(struct pt_regs *fp)
 198 {
 199         _send_sig(SIGILL, ILL_ILLTRP, fp->ea);
 200 }