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         printk("%s(%d): %s %ld\n", current->comm, current->pid, str, err);
  23         sp = (unsigned long) (regs+1);
  24         if (regs->ps & 8)
  25                 sp = rdusp();
  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         if (regs->ps & 8)
  40                 return;
  41         printk("Code:");
  42         pc = (unsigned int *) regs->pc;
  43         for (i = -3; i < 6; i++)
  44                 printk("%c%08x%c",i?' ':'<',pc[i],i?' ':'>');
  45         printk("\n");
  46         for (i = 0 ; i < 5000000000 ; i++)
  47                 /* pause */;
  48         halt();
  49 }
  50 
  51 asmlinkage void do_entArith(unsigned long summary, unsigned long write_mask,
     /* [previous][next][first][last][top][bottom][index][help] */
  52         unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5,
  53         struct pt_regs regs)
  54 {
  55         printk("Arithmetic trap: %02lx %016lx\n", summary, write_mask);
  56         die_if_kernel("Arithmetic fault", &regs, 0);
  57         send_sig(SIGFPE, current, 1);
  58 }
  59 
  60 asmlinkage void do_entIF(unsigned long type, unsigned long a1, unsigned long a2,
     /* [previous][next][first][last][top][bottom][index][help] */
  61         unsigned long a3, unsigned long a4, unsigned long a5,
  62         struct pt_regs regs)
  63 {
  64         die_if_kernel("Instruction fault", &regs, type);
  65         send_sig(SIGILL, current, 1);
  66 }
  67 
  68 /*
  69  * entUna has a different register layout to be reasonably simple. It
  70  * needs access to all the integer registers (the kernel doesn't use
  71  * fp-regs), and it needs to have them in order for simpler access.
  72  *
  73  * Due to the non-standard register layout (and because we don't want
  74  * to handle floating-point regs), we disallow user-mode unaligned
  75  * accesses (we'd need to do "verify_area()" checking, as well as
  76  * do a full "ret_from_sys_call" return).
  77  *
  78  * Oh, btw, we don't handle the "gp" register correctly, but if we fault
  79  * on a gp-register unaligned load/store, something is _very_ wrong
  80  * in the kernel anyway..
  81  */
  82 struct allregs {
  83         unsigned long regs[32];
  84         unsigned long ps, pc, gp, a0, a1, a2;
  85 };
  86 
  87 asmlinkage void do_entUna(void * va, unsigned long opcode, unsigned long reg,
     /* [previous][next][first][last][top][bottom][index][help] */
  88         unsigned long a3, unsigned long a4, unsigned long a5,
  89         struct allregs regs)
  90 {
  91         static int cnt = 0;
  92 
  93         if (regs.ps & 8)
  94                 do_exit(SIGSEGV);
  95         if (++cnt < 5)
  96                 printk("Unaligned trap at %016lx: %p %lx %ld\n",
  97                         regs.pc, va, opcode, reg);
  98         /* $16-$18 are PAL-saved, and are offset by 19 entries */
  99         if (reg >= 16 && reg <= 18)
 100                 reg += 19;
 101         switch (opcode) {
 102                 case 0x28: /* ldl */
 103                         *(reg+regs.regs) = (int) ldl_u(va);
 104                         return;
 105                 case 0x29: /* ldq */
 106                         *(reg+regs.regs) = ldq_u(va);
 107                         return;
 108                 case 0x2c: /* stl */
 109                         stl_u(*(reg+regs.regs), va);
 110                         return;
 111                 case 0x2d: /* stq */
 112                         stq_u(*(reg+regs.regs), va);
 113                         return;
 114         }
 115         printk("Bad unaligned kernel access at %016lx: %p %lx %ld\n",
 116                 regs.pc, va, opcode, reg);
 117         do_exit(SIGSEGV);
 118 }
 119 
 120 /*
 121  * DEC means people to use the "retsys" instruction for return from
 122  * a system call, but they are clearly misguided about this. We use
 123  * "rti" in all cases, and fill in the stack with the return values.
 124  * That should make signal handling etc much cleaner.
 125  *
 126  * Even more horribly, DEC doesn't allow system calls from kernel mode.
 127  * "Security" features letting the user do something the kernel can't
 128  * are a thinko. DEC palcode is strange. The PAL-code designers probably
 129  * got terminally tainted by VMS at some point.
 130  */
 131 asmlinkage long do_entSys(unsigned long a0, unsigned long a1, unsigned long a2,
     /* [previous][next][first][last][top][bottom][index][help] */
 132         unsigned long a3, unsigned long a4, unsigned long a5, struct pt_regs regs)
 133 {
 134         printk("<sc %ld(%lx,%lx,%lx)>", regs.r0, a0, a1, a2);
 135         return -1;
 136 }
 137 
 138 extern asmlinkage void entMM(void);
 139 extern asmlinkage void entIF(void);
 140 extern asmlinkage void entArith(void);
 141 extern asmlinkage void entUna(void);
 142 extern asmlinkage void entSys(void);
 143 
 144 void trap_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 145 {
 146         unsigned long gptr;
 147 
 148         /*
 149          * Tell PAL-code what global pointer we want in the kernel..
 150          */
 151         __asm__("br %0,___tmp\n"
 152                 "___tmp:\tldgp %0,0(%0)"
 153                 : "=r" (gptr));
 154         wrkgp(gptr);
 155 
 156         wrent(entArith, 1);
 157         wrent(entMM, 2);
 158         wrent(entIF, 3);
 159         wrent(entUna, 4);
 160         wrent(entSys, 5);
 161 }

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