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

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