root/arch/sparc/kernel/traps.c

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

DEFINITIONS

This source file includes following definitions.
  1. syscall_trace_entry
  2. syscall_trace_exit
  3. do_cwp_assertion_failure
  4. do_hw_interrupt
  5. do_illegal_instruction
  6. do_priv_instruction
  7. do_memaccess_unaligned
  8. do_fpd_trap
  9. do_fpe_trap
  10. handle_tag_overflow
  11. handle_watchpoint
  12. handle_reg_access
  13. handle_cp_disabled
  14. handle_bad_flush
  15. handle_cp_exception
  16. handle_hw_divzero
  17. do_ast
  18. trap_init
  19. die_if_kernel

   1 /* $Id: traps.c,v 1.18 1995/11/25 00:58:47 davem Exp $
   2  * arch/sparc/kernel/traps.c
   3  *
   4  * Copyright 1995 David S. Miller (davem@caip.rutgers.edu)
   5  */
   6 
   7 /*
   8  * I hate traps on the sparc, grrr...
   9  */
  10 
  11 #include <linux/sched.h>  /* for jiffies */
  12 #include <linux/kernel.h>
  13 
  14 #include <asm/delay.h>
  15 #include <asm/system.h>
  16 #include <asm/ptrace.h>
  17 #include <asm/oplib.h>
  18 #include <asm/page.h>
  19 #include <asm/pgtable.h>
  20 #include <asm/mp.h>
  21 #include <asm/kdebug.h>
  22 
  23 void
  24 syscall_trace_entry(struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
  25 {
  26         printk("%s[%d]: sys[%d](%d, %d, %d, %d) ",
  27                current->comm, current->pid,
  28                regs->u_regs[UREG_G1], regs->u_regs[UREG_I0],
  29                regs->u_regs[UREG_I1], regs->u_regs[UREG_I2],
  30                regs->u_regs[UREG_I3]);
  31         return;
  32 }
  33 
  34 void
  35 syscall_trace_exit(struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
  36 {
  37         printk("retvals[%d,%d] at pc<%08lx>\n",
  38                regs->u_regs[UREG_I0], regs->u_regs[UREG_I1],
  39                regs->pc, regs->npc);
  40         return;
  41 }
  42 
  43 void
  44 do_cwp_assertion_failure(struct pt_regs *regs, unsigned long psr)
     /* [previous][next][first][last][top][bottom][index][help] */
  45 {
  46         printk("CWP return from trap assertion fails:\n");
  47         printk("Current psr %08lx, new psr %08lx\n", psr, regs->psr);
  48         show_regs(regs);
  49         panic("bogus CWP");
  50 }
  51 
  52 void
  53 do_hw_interrupt(unsigned long type, unsigned long psr, unsigned long pc)
     /* [previous][next][first][last][top][bottom][index][help] */
  54 {
  55 
  56   printk("Unimplemented Sparc TRAP, type = %02lx psr = %08lx pc = %08lx\n",
  57          type, psr, pc);
  58   halt();
  59 
  60   return;
  61 }
  62 
  63 void
  64 do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
     /* [previous][next][first][last][top][bottom][index][help] */
  65                        unsigned long psr)
  66 {
  67         printk("Illegal instruction at PC %08lx NPC %08lx PSR %08lx\n",
  68                pc, npc, psr);
  69         if(psr & PSR_PS)
  70                 panic("Kernel illegal instruction, how are ya!");
  71         current->tss.sig_address = pc;
  72         current->tss.sig_desc = SUBSIG_ILLINST;
  73         send_sig(SIGILL, current, 1);
  74         return;
  75 }
  76 
  77 void
  78 do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
     /* [previous][next][first][last][top][bottom][index][help] */
  79                        unsigned long psr)
  80 {
  81         printk("Privileged instruction at PC %08lx NPC %08lx PSR %08lx\n",
  82                pc, npc, psr);
  83         current->tss.sig_address = pc;
  84         current->tss.sig_desc = SUBSIG_PRIVINST;
  85         send_sig(SIGILL, current, 1);
  86         return;
  87 }
  88 
  89 /* XXX User may want to be allowed to do this. XXX */
  90 
  91 void
  92 do_memaccess_unaligned(struct pt_regs *regs, unsigned long pc, unsigned long npc,
     /* [previous][next][first][last][top][bottom][index][help] */
  93                        unsigned long psr)
  94 {
  95         printk("Unaligned memory access at PC %08lx NPC %08lx PSR %08lx\n",
  96                pc, npc, psr);
  97         if(regs->psr & PSR_PS)
  98                 panic("Kernel does unaligned memory access, yuck!");
  99         current->tss.sig_address = pc;
 100         current->tss.sig_desc = SUBSIG_PRIVINST;
 101         send_sig(SIGBUS, current, 1);
 102         return;
 103 }
 104 
 105 void
 106 do_fpd_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,
     /* [previous][next][first][last][top][bottom][index][help] */
 107                        unsigned long psr)
 108 {
 109         /* Sanity check... */
 110         if(psr & PSR_PS)
 111                 panic("FPE disabled trap from kernel, die die die...");
 112 
 113         put_psr(get_psr() | PSR_EF);    /* Allow FPU ops. */
 114         if(last_task_used_math == current) {
 115                 /* No state save necessary */
 116                 regs->psr |= PSR_EF;
 117                 return;
 118         }
 119         if(last_task_used_math) {
 120                 /* Other processes fpu state, save away */
 121                 __asm__ __volatile__("st %%fsr, [%0]\n\t" : :
 122                                      "r" (&current->tss.fsr) : "memory");
 123 
 124                 /* Save away the floating point queue if necessary. */
 125                 if(current->tss.fsr & 0x2000)
 126                         __asm__ __volatile__("mov 0x0, %%g2\n\t"
 127                                              "1: std %%fq, [%2 + %%g2]\n\t"
 128                                              "st %%fsr, [%0]\n\t"
 129                                              "ld [%0], %%g3\n\t"
 130                                              "andcc %%g3, %1, %%g0\n\t"
 131                                              "bne 1b\n\t"
 132                                              "add %%g2, 0x8, %%g2\n\t"
 133                                              "srl %%g2, 0x3, %%g2\n\t"
 134                                              "st %%g2, [%3]\n\t" : :
 135                                              "r" (&current->tss.fsr), "r" (0x2000),
 136                                              "r" (&current->tss.fpqueue[0]),
 137                                              "r" (&current->tss.fpqdepth) :
 138                                              "g2", "g3", "memory");
 139                 else
 140                         current->tss.fpqdepth = 0;
 141 
 142                 __asm__ __volatile__("std %%f0, [%0 + 0x00]\n\t"
 143                                      "std %%f2, [%0 + 0x08]\n\t"
 144                                      "std %%f4, [%0 + 0x10]\n\t"
 145                                      "std %%f6, [%0 + 0x18]\n\t"
 146                                      "std %%f8, [%0 + 0x20]\n\t"
 147                                      "std %%f10, [%0 + 0x28]\n\t"
 148                                      "std %%f12, [%0 + 0x30]\n\t"
 149                                      "std %%f14, [%0 + 0x38]\n\t"
 150                                      "std %%f16, [%0 + 0x40]\n\t"
 151                                      "std %%f18, [%0 + 0x48]\n\t"
 152                                      "std %%f20, [%0 + 0x50]\n\t"
 153                                      "std %%f22, [%0 + 0x58]\n\t"
 154                                      "std %%f24, [%0 + 0x60]\n\t"
 155                                      "std %%f26, [%0 + 0x68]\n\t"
 156                                      "std %%f28, [%0 + 0x70]\n\t"
 157                                      "std %%f30, [%0 + 0x78]\n\t" : :
 158                                      "r" (&current->tss.float_regs[0]) :
 159                                      "memory");
 160         }
 161         last_task_used_math = current;
 162         if(current->used_math) {
 163                 /* Restore the old state. */
 164                 __asm__ __volatile__("ldd [%0 + 0x00], %%f0\n\t"
 165                                      "ldd [%0 + 0x08], %%f2\n\t"
 166                                      "ldd [%0 + 0x10], %%f4\n\t"
 167                                      "ldd [%0 + 0x18], %%f6\n\t"
 168                                      "ldd [%0 + 0x20], %%f8\n\t"
 169                                      "ldd [%0 + 0x28], %%f10\n\t"
 170                                      "ldd [%0 + 0x30], %%f12\n\t"
 171                                      "ldd [%0 + 0x38], %%f14\n\t"
 172                                      "ldd [%0 + 0x40], %%f16\n\t"
 173                                      "ldd [%0 + 0x48], %%f18\n\t"
 174                                      "ldd [%0 + 0x50], %%f20\n\t"
 175                                      "ldd [%0 + 0x58], %%f22\n\t"
 176                                      "ldd [%0 + 0x60], %%f24\n\t"
 177                                      "ldd [%0 + 0x68], %%f26\n\t"
 178                                      "ldd [%0 + 0x70], %%f28\n\t"
 179                                      "ldd [%0 + 0x78], %%f30\n\t"
 180                                      "ld  [%1], %%fsr\n\t" : :
 181                                      "r" (&current->tss.float_regs[0]),
 182                                      "r" (&current->tss.fsr));
 183         } else {
 184                 /* Set initial sane state. */
 185                 auto unsigned long init_fsr = 0x0UL;
 186                 auto unsigned long init_fregs[32] __attribute__ ((aligned (8))) =
 187                 { ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
 188                   ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
 189                   ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
 190                   ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL };
 191                 __asm__ __volatile__("ldd [%0 + 0x00], %%f0\n\t"
 192                                      "ldd [%0 + 0x08], %%f2\n\t"
 193                                      "ldd [%0 + 0x10], %%f4\n\t"
 194                                      "ldd [%0 + 0x18], %%f6\n\t"
 195                                      "ldd [%0 + 0x20], %%f8\n\t"
 196                                      "ldd [%0 + 0x28], %%f10\n\t"
 197                                      "ldd [%0 + 0x30], %%f12\n\t"
 198                                      "ldd [%0 + 0x38], %%f14\n\t"
 199                                      "ldd [%0 + 0x40], %%f16\n\t"
 200                                      "ldd [%0 + 0x48], %%f18\n\t"
 201                                      "ldd [%0 + 0x50], %%f20\n\t"
 202                                      "ldd [%0 + 0x58], %%f22\n\t"
 203                                      "ldd [%0 + 0x60], %%f24\n\t"
 204                                      "ldd [%0 + 0x68], %%f26\n\t"
 205                                      "ldd [%0 + 0x70], %%f28\n\t"
 206                                      "ldd [%0 + 0x78], %%f30\n\t"
 207                                      "ld  [%1], %%fsr\n\t" : :
 208                                      "r" (&init_fregs[0]),
 209                                      "r" (&init_fsr) : "memory");
 210                 current->used_math = 1;
 211         }
 212 }
 213 
 214 void
 215 do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,
     /* [previous][next][first][last][top][bottom][index][help] */
 216                        unsigned long psr)
 217 {
 218         if(psr & PSR_PS)
 219                 panic("FPE exception trap from kernel, die die die...");
 220         /* XXX Do something real... XXX */
 221         regs->psr &= ~PSR_EF;
 222         last_task_used_math = (struct task_struct *) 0;
 223         current->tss.sig_address = pc;
 224         current->tss.sig_desc = SUBSIG_FPERROR; /* as good as any */
 225         send_sig(SIGFPE, current, 1);
 226         return;
 227 }
 228 
 229 void
 230 handle_tag_overflow(struct pt_regs *regs, unsigned long pc, unsigned long npc,
     /* [previous][next][first][last][top][bottom][index][help] */
 231                        unsigned long psr)
 232 {
 233         printk("Tag overflow trap at PC %08lx NPC %08lx PSR %08lx\n",
 234                pc, npc, psr);
 235         if(psr & PSR_PS)
 236                 panic("KERNEL tag overflow trap, wowza!");
 237         current->tss.sig_address = pc;
 238         current->tss.sig_desc = SUBSIG_TAG; /* as good as any */
 239         send_sig(SIGEMT, current, 1);
 240         return;
 241 }
 242 
 243 void
 244 handle_watchpoint(struct pt_regs *regs, unsigned long pc, unsigned long npc,
     /* [previous][next][first][last][top][bottom][index][help] */
 245                        unsigned long psr)
 246 {
 247         printk("Watchpoint detected at PC %08lx NPC %08lx PSR %08lx\n",
 248                pc, npc, psr);
 249         if(psr & PSR_PS)
 250                 panic("Tell me what a watchpoint trap is, and I'll then deal "
 251                       "with such a beast...");
 252         return;
 253 }
 254 
 255 void
 256 handle_reg_access(struct pt_regs *regs, unsigned long pc, unsigned long npc,
     /* [previous][next][first][last][top][bottom][index][help] */
 257                        unsigned long psr)
 258 {
 259         printk("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n",
 260                pc, npc, psr);
 261         halt();
 262         return;
 263 }
 264 
 265 void
 266 handle_cp_disabled(struct pt_regs *regs, unsigned long pc, unsigned long npc,
     /* [previous][next][first][last][top][bottom][index][help] */
 267                        unsigned long psr)
 268 {
 269         printk("Co-Processor disabled trap at PC %08lx NPC %08lx PSR %08lx\n",
 270                pc, npc, psr);
 271         halt();
 272         return;
 273 }
 274 
 275 void
 276 handle_bad_flush(struct pt_regs *regs, unsigned long pc, unsigned long npc,
     /* [previous][next][first][last][top][bottom][index][help] */
 277                        unsigned long psr)
 278 {
 279         printk("Unimplemented FLUSH Exception at PC %08lx NPC %08lx PSR %08lx\n",
 280                pc, npc, psr);
 281         halt();
 282         return;
 283 }
 284 
 285 void
 286 handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long npc,
     /* [previous][next][first][last][top][bottom][index][help] */
 287                        unsigned long psr)
 288 {
 289         printk("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n",
 290                pc, npc, psr);
 291         halt();
 292         return;
 293 }
 294 
 295 void
 296 handle_hw_divzero(struct pt_regs *regs, unsigned long pc, unsigned long npc,
     /* [previous][next][first][last][top][bottom][index][help] */
 297                        unsigned long psr)
 298 {
 299         printk("Divide By Zero Exception at PC %08lx NPC %08lx PSR %08lx\n",
 300                pc, npc, psr);
 301         halt();
 302         return;
 303 }
 304 
 305 void do_ast(struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 306 {
 307         panic("Don't know how to handle AST traps yet ;-(\n");
 308         return;
 309 }
 310 
 311 /* Since we have our mappings set up, on multiprocessors we can spin them
 312  * up here so that timer interrupts work during initialization.
 313  */
 314 
 315 extern void sparc_cpu_startup(void);
 316 
 317 extern int linux_num_cpus;
 318 extern pgd_t *lnx_root;
 319 
 320 int linux_smp_still_initting;
 321 unsigned int thiscpus_tbr;
 322 int thiscpus_mid;
 323 
 324 void
 325 trap_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 326 {
 327         struct linux_prom_registers ctx_reg;
 328         int i;
 329 
 330         if(linux_num_cpus == 1) {
 331                 printk("trap_init: Uniprocessor detected.\n");
 332                 return;
 333         }
 334         if(sparc_cpu_model != sun4m) {
 335                 prom_printf("trap_init: Multiprocessor on a non-sun4m! Aieee...\n");
 336                 prom_printf("trap_init: Cannot continue, bailing out.\n");
 337                 prom_halt();
 338         }
 339         /* Ok, we are on a sun4m with multiple cpu's */
 340         prom_printf("trap_init: Multiprocessor detected, initiating CPU-startup. cpus=%d\n",
 341                linux_num_cpus);
 342         linux_smp_still_initting = 1;
 343         ctx_reg.which_io = 0x0;  /* real ram */
 344         ctx_reg.phys_addr = (char *) (((unsigned long) lnx_root) - PAGE_OFFSET);
 345         ctx_reg.reg_size = 0x0;
 346         /* This basically takes every cpu, loads up our Linux context table
 347          * into it's context table pointer register, inits it at the low level
 348          * and then makes it spin in an endless loop...
 349          */
 350         for(i=0; i<linux_num_cpus; i++) {
 351                 if((linux_cpus[i].mid & (~8)) != 0x0) {
 352                         static int cpuid = 0;
 353                         cpuid = (linux_cpus[i].mid & (~8));
 354                         percpu_table[cpuid].cpu_is_alive = 0;
 355                         thiscpus_mid = linux_cpus[i].mid;
 356                         thiscpus_tbr = (unsigned int)
 357                                 percpu_table[cpuid].trap_table;
 358                         prom_startcpu(linux_cpus[i].prom_node, &ctx_reg, 0x0,
 359                                       (char *) sparc_cpu_startup);
 360                         prom_printf("Waiting for cpu %d to start up...\n", i);
 361                         while(percpu_table[cpuid].cpu_is_alive == 0) {
 362                                 static int counter = 0;
 363                                 counter++;
 364                                 if(counter>200)
 365                                         break;
 366                                 __delay(200000);
 367                         }
 368                 }
 369         }
 370 
 371         linux_smp_still_initting = 1;
 372 
 373         return;
 374 }
 375 
 376 void
 377 die_if_kernel(char * str, struct pt_regs * regs, long err)
     /* [previous][next][first][last][top][bottom][index][help] */
 378 {
 379   return;
 380 }

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