root/arch/alpha/kernel/traps.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. die_if_kernel
  2. do_entArith
  3. do_entIF
  4. do_entUna
  5. do_entSys
  6. trap_init

   1 /*
   2  * kernel/traps.c
   3  *
   4  * (C) Copyright 1994 Linus Torvalds
   5  */
   6 
   7 /*
   8  * This file initializes the trap entry points
   9  */
  10 
  11 #include <linux/sched.h>
  12 #include <linux/tty.h>
  13 
  14 #include <asm/unaligned.h>
  15 
  16 void die_if_kernel(char * str, struct pt_regs * regs, long err)
     /* [previous][next][first][last][top][bottom][index][help] */
  17 {
  18         long i;
  19         unsigned long sp;
  20         unsigned int * pc;
  21 
  22         if (regs->ps & 8)
  23                 return;
  24         printk("%s(%d): %s %ld\n", current->comm, current->pid, str, err);
  25         sp = (unsigned long) (regs+1);
  26         printk("pc = %lx ps = %04lx\n", regs->pc, regs->ps);
  27         printk("rp = %lx sp = %lx\n", regs->r26, sp);
  28         printk("r0=%lx r1=%lx r2=%lx r3=%lx\n",
  29                 regs->r0, regs->r1, regs->r2, regs->r3);
  30         printk("r8=%lx\n", regs->r8);
  31         printk("r16=%lx r17=%lx r18=%lx r19=%lx\n",
  32                 regs->r16, regs->r17, regs->r18, regs->r19);
  33         printk("r20=%lx r21=%lx r22=%lx r23=%lx\n",
  34                 regs->r20, regs->r21, regs->r22, regs->r23);
  35         printk("r24=%lx r25=%lx r26=%lx r27=%lx\n",
  36                 regs->r24, regs->r25, regs->r26, regs->r27);
  37         printk("r28=%lx r29=%lx r30=%lx\n",
  38                 regs->r28, regs->gp, sp);
  39         printk("Code:");
  40         pc = (unsigned int *) regs->pc;
  41         for (i = -3; i < 6; i++)
  42                 printk("%c%08x%c",i?' ':'<',pc[i],i?' ':'>');
  43         printk("\n");
  44         for (i = 0 ; i < 5000000000 ; i++)
  45                 /* pause */;
  46         halt();
  47 }
  48 
  49 asmlinkage void do_entArith(unsigned long summary, unsigned long write_mask,
     /* [previous][next][first][last][top][bottom][index][help] */
  50         unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5,
  51         struct pt_regs regs)
  52 {
  53         printk("Arithmetic trap: %02lx %016lx\n", summary, write_mask);
  54         die_if_kernel("Arithmetic fault", &regs, 0);
  55         send_sig(SIGFPE, current, 1);
  56 }
  57 
  58 asmlinkage void do_entIF(unsigned long type, unsigned long a1, unsigned long a2,
     /* [previous][next][first][last][top][bottom][index][help] */
  59         unsigned long a3, unsigned long a4, unsigned long a5,
  60         struct pt_regs regs)
  61 {
  62         extern int ptrace_cancel_bpt (struct task_struct *who);
  63 
  64         die_if_kernel("Instruction fault", &regs, type);
  65         switch (type) {
  66               case 0: /* breakpoint */
  67                 if (ptrace_cancel_bpt(current)) {
  68                         regs.pc -= 4;   /* make pc point to former bpt */
  69                 }
  70                 if (current->flags & PF_PTRACED)
  71                   current->blocked &= ~(1 << (SIGTRAP - 1));
  72                 send_sig(SIGTRAP, current, 1);
  73                 break;
  74 
  75               case 1: /* bugcheck */
  76               case 2: /* gentrap */
  77               case 3: /* FEN fault */
  78               case 4: /* opDEC */
  79                 send_sig(SIGILL, current, 1);
  80                 break;
  81 
  82               default:
  83                 panic("do_entIF: unexpected instruction-fault type");
  84         }
  85 }
  86 
  87 /*
  88  * entUna has a different register layout to be reasonably simple. It
  89  * needs access to all the integer registers (the kernel doesn't use
  90  * fp-regs), and it needs to have them in order for simpler access.
  91  *
  92  * Due to the non-standard register layout (and because we don't want
  93  * to handle floating-point regs), we disallow user-mode unaligned
  94  * accesses (we'd need to do "verify_area()" checking, as well as
  95  * do a full "ret_from_sys_call" return).
  96  *
  97  * Oh, btw, we don't handle the "gp" register correctly, but if we fault
  98  * on a gp-register unaligned load/store, something is _very_ wrong
  99  * in the kernel anyway..
 100  */
 101 struct allregs {
 102         unsigned long regs[32];
 103         unsigned long ps, pc, gp, a0, a1, a2;
 104 };
 105 
 106 asmlinkage void do_entUna(void * va, unsigned long opcode, unsigned long reg,
     /* [previous][next][first][last][top][bottom][index][help] */
 107         unsigned long a3, unsigned long a4, unsigned long a5,
 108         struct allregs regs)
 109 {
 110         static int cnt = 0;
 111 
 112         if (regs.ps & 8)
 113                 do_exit(SIGSEGV);
 114         if (++cnt < 5)
 115                 printk("Unaligned trap at %016lx: %p %lx %ld\n",
 116                         regs.pc, va, opcode, reg);
 117         /* $16-$18 are PAL-saved, and are offset by 19 entries */
 118         if (reg >= 16 && reg <= 18)
 119                 reg += 19;
 120         switch (opcode) {
 121                 case 0x28: /* ldl */
 122                         *(reg+regs.regs) = (int) ldl_u(va);
 123                         return;
 124                 case 0x29: /* ldq */
 125                         *(reg+regs.regs) = ldq_u(va);
 126                         return;
 127                 case 0x2c: /* stl */
 128                         stl_u(*(reg+regs.regs), va);
 129                         return;
 130                 case 0x2d: /* stq */
 131                         stq_u(*(reg+regs.regs), va);
 132                         return;
 133         }
 134         printk("Bad unaligned kernel access at %016lx: %p %lx %ld\n",
 135                 regs.pc, va, opcode, reg);
 136         do_exit(SIGSEGV);
 137 }
 138 
 139 /*
 140  * DEC means people to use the "retsys" instruction for return from
 141  * a system call, but they are clearly misguided about this. We use
 142  * "rti" in all cases, and fill in the stack with the return values.
 143  * That should make signal handling etc much cleaner.
 144  *
 145  * Even more horribly, DEC doesn't allow system calls from kernel mode.
 146  * "Security" features letting the user do something the kernel can't
 147  * are a thinko. DEC palcode is strange. The PAL-code designers probably
 148  * got terminally tainted by VMS at some point.
 149  */
 150 asmlinkage long do_entSys(unsigned long a0, unsigned long a1, unsigned long a2,
     /* [previous][next][first][last][top][bottom][index][help] */
 151         unsigned long a3, unsigned long a4, unsigned long a5, struct pt_regs regs)
 152 {
 153         if (regs.r0 != 112)
 154           printk("<sc %ld(%lx,%lx,%lx)>", regs.r0, a0, a1, a2);
 155         return -1;
 156 }
 157 
 158 extern asmlinkage void entMM(void);
 159 extern asmlinkage void entIF(void);
 160 extern asmlinkage void entArith(void);
 161 extern asmlinkage void entUna(void);
 162 extern asmlinkage void entSys(void);
 163 
 164 void trap_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 165 {
 166         unsigned long gptr;
 167 
 168         /*
 169          * Tell PAL-code what global pointer we want in the kernel..
 170          */
 171         __asm__("br %0,___tmp\n"
 172                 "___tmp:\tldgp %0,0(%0)"
 173                 : "=r" (gptr));
 174         wrkgp(gptr);
 175 
 176         wrent(entArith, 1);
 177         wrent(entMM, 2);
 178         wrent(entIF, 3);
 179         wrent(entUna, 4);
 180         wrent(entSys, 5);
 181 }

/* [previous][next][first][last][top][bottom][index][help] */