patch-1.3.44 linux/arch/sparc/kernel/traps.c

Next file: linux/arch/sparc/kernel/wof.S
Previous file: linux/arch/sparc/kernel/time.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.43/linux/arch/sparc/kernel/traps.c linux/arch/sparc/kernel/traps.c
@@ -1,4 +1,4 @@
-/*
+/* $Id: traps.c,v 1.18 1995/11/25 00:58:47 davem Exp $
  * arch/sparc/kernel/traps.c
  *
  * Copyright 1995 David S. Miller (davem@caip.rutgers.edu)
@@ -21,6 +21,35 @@
 #include <asm/kdebug.h>
 
 void
+syscall_trace_entry(struct pt_regs *regs)
+{
+	printk("%s[%d]: sys[%d](%d, %d, %d, %d) ",
+	       current->comm, current->pid,
+	       regs->u_regs[UREG_G1], regs->u_regs[UREG_I0],
+	       regs->u_regs[UREG_I1], regs->u_regs[UREG_I2],
+	       regs->u_regs[UREG_I3]);
+	return;
+}
+
+void
+syscall_trace_exit(struct pt_regs *regs)
+{
+	printk("retvals[%d,%d] at pc<%08lx>\n",
+	       regs->u_regs[UREG_I0], regs->u_regs[UREG_I1],
+	       regs->pc, regs->npc);
+	return;
+}
+
+void
+do_cwp_assertion_failure(struct pt_regs *regs, unsigned long psr)
+{
+	printk("CWP return from trap assertion fails:\n");
+	printk("Current psr %08lx, new psr %08lx\n", psr, regs->psr);
+	show_regs(regs);
+	panic("bogus CWP");
+}
+
+void
 do_hw_interrupt(unsigned long type, unsigned long psr, unsigned long pc)
 {
 
@@ -37,7 +66,11 @@
 {
 	printk("Illegal instruction at PC %08lx NPC %08lx PSR %08lx\n",
 	       pc, npc, psr);
-	halt();
+	if(psr & PSR_PS)
+		panic("Kernel illegal instruction, how are ya!");
+	current->tss.sig_address = pc;
+	current->tss.sig_desc = SUBSIG_ILLINST;
+	send_sig(SIGILL, current, 1);
 	return;
 }
 
@@ -47,17 +80,25 @@
 {
 	printk("Privileged instruction at PC %08lx NPC %08lx PSR %08lx\n",
 	       pc, npc, psr);
-	halt();
+	current->tss.sig_address = pc;
+	current->tss.sig_desc = SUBSIG_PRIVINST;
+	send_sig(SIGILL, current, 1);
 	return;
 }
 
+/* XXX User may want to be allowed to do this. XXX */
+
 void
 do_memaccess_unaligned(struct pt_regs *regs, unsigned long pc, unsigned long npc,
 		       unsigned long psr)
 {
 	printk("Unaligned memory access at PC %08lx NPC %08lx PSR %08lx\n",
 	       pc, npc, psr);
-	halt();
+	if(regs->psr & PSR_PS)
+		panic("Kernel does unaligned memory access, yuck!");
+	current->tss.sig_address = pc;
+	current->tss.sig_desc = SUBSIG_PRIVINST;
+	send_sig(SIGBUS, current, 1);
 	return;
 }
 
@@ -65,19 +106,123 @@
 do_fpd_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,
 		       unsigned long psr)
 {
-	printk("Floating Point Disabled trap at PC %08lx NPC %08lx PSR %08lx\n",
-	       pc, npc, psr);
-	halt();
-	return;
+	/* Sanity check... */
+	if(psr & PSR_PS)
+		panic("FPE disabled trap from kernel, die die die...");
+
+	put_psr(get_psr() | PSR_EF);    /* Allow FPU ops. */
+	if(last_task_used_math == current) {
+		/* No state save necessary */
+		regs->psr |= PSR_EF;
+		return;
+	}
+	if(last_task_used_math) {
+		/* Other processes fpu state, save away */
+		__asm__ __volatile__("st %%fsr, [%0]\n\t" : :
+				     "r" (&current->tss.fsr) : "memory");
+
+		/* Save away the floating point queue if necessary. */
+		if(current->tss.fsr & 0x2000)
+			__asm__ __volatile__("mov 0x0, %%g2\n\t"
+					     "1: std %%fq, [%2 + %%g2]\n\t"
+					     "st %%fsr, [%0]\n\t"
+					     "ld [%0], %%g3\n\t"
+					     "andcc %%g3, %1, %%g0\n\t"
+					     "bne 1b\n\t"
+					     "add %%g2, 0x8, %%g2\n\t"
+					     "srl %%g2, 0x3, %%g2\n\t"
+					     "st %%g2, [%3]\n\t" : :
+					     "r" (&current->tss.fsr), "r" (0x2000),
+					     "r" (&current->tss.fpqueue[0]),
+					     "r" (&current->tss.fpqdepth) :
+					     "g2", "g3", "memory");
+		else
+			current->tss.fpqdepth = 0;
+
+		__asm__ __volatile__("std %%f0, [%0 + 0x00]\n\t"
+				     "std %%f2, [%0 + 0x08]\n\t"
+				     "std %%f4, [%0 + 0x10]\n\t"
+				     "std %%f6, [%0 + 0x18]\n\t"
+				     "std %%f8, [%0 + 0x20]\n\t"
+				     "std %%f10, [%0 + 0x28]\n\t"
+				     "std %%f12, [%0 + 0x30]\n\t"
+				     "std %%f14, [%0 + 0x38]\n\t"
+				     "std %%f16, [%0 + 0x40]\n\t"
+				     "std %%f18, [%0 + 0x48]\n\t"
+				     "std %%f20, [%0 + 0x50]\n\t"
+				     "std %%f22, [%0 + 0x58]\n\t"
+				     "std %%f24, [%0 + 0x60]\n\t"
+				     "std %%f26, [%0 + 0x68]\n\t"
+				     "std %%f28, [%0 + 0x70]\n\t"
+				     "std %%f30, [%0 + 0x78]\n\t" : :
+				     "r" (&current->tss.float_regs[0]) :
+				     "memory");
+	}
+	last_task_used_math = current;
+	if(current->used_math) {
+		/* Restore the old state. */
+		__asm__ __volatile__("ldd [%0 + 0x00], %%f0\n\t"
+				     "ldd [%0 + 0x08], %%f2\n\t"
+				     "ldd [%0 + 0x10], %%f4\n\t"
+				     "ldd [%0 + 0x18], %%f6\n\t"
+				     "ldd [%0 + 0x20], %%f8\n\t"
+				     "ldd [%0 + 0x28], %%f10\n\t"
+				     "ldd [%0 + 0x30], %%f12\n\t"
+				     "ldd [%0 + 0x38], %%f14\n\t"
+				     "ldd [%0 + 0x40], %%f16\n\t"
+				     "ldd [%0 + 0x48], %%f18\n\t"
+				     "ldd [%0 + 0x50], %%f20\n\t"
+				     "ldd [%0 + 0x58], %%f22\n\t"
+				     "ldd [%0 + 0x60], %%f24\n\t"
+				     "ldd [%0 + 0x68], %%f26\n\t"
+				     "ldd [%0 + 0x70], %%f28\n\t"
+				     "ldd [%0 + 0x78], %%f30\n\t"
+				     "ld  [%1], %%fsr\n\t" : :
+				     "r" (&current->tss.float_regs[0]),
+				     "r" (&current->tss.fsr));
+	} else {
+		/* Set initial sane state. */
+		auto unsigned long init_fsr = 0x0UL;
+		auto unsigned long init_fregs[32] __attribute__ ((aligned (8))) =
+		{ ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
+		  ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
+		  ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
+		  ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL };
+		__asm__ __volatile__("ldd [%0 + 0x00], %%f0\n\t"
+				     "ldd [%0 + 0x08], %%f2\n\t"
+				     "ldd [%0 + 0x10], %%f4\n\t"
+				     "ldd [%0 + 0x18], %%f6\n\t"
+				     "ldd [%0 + 0x20], %%f8\n\t"
+				     "ldd [%0 + 0x28], %%f10\n\t"
+				     "ldd [%0 + 0x30], %%f12\n\t"
+				     "ldd [%0 + 0x38], %%f14\n\t"
+				     "ldd [%0 + 0x40], %%f16\n\t"
+				     "ldd [%0 + 0x48], %%f18\n\t"
+				     "ldd [%0 + 0x50], %%f20\n\t"
+				     "ldd [%0 + 0x58], %%f22\n\t"
+				     "ldd [%0 + 0x60], %%f24\n\t"
+				     "ldd [%0 + 0x68], %%f26\n\t"
+				     "ldd [%0 + 0x70], %%f28\n\t"
+				     "ldd [%0 + 0x78], %%f30\n\t"
+				     "ld  [%1], %%fsr\n\t" : :
+				     "r" (&init_fregs[0]),
+				     "r" (&init_fsr) : "memory");
+		current->used_math = 1;
+	}
 }
 
 void
 do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,
 		       unsigned long psr)
 {
-	printk("Floating Point Exception at PC %08lx NPC %08lx PSR %08lx\n",
-	       pc, npc, psr);
-	halt();
+	if(psr & PSR_PS)
+		panic("FPE exception trap from kernel, die die die...");
+	/* XXX Do something real... XXX */
+	regs->psr &= ~PSR_EF;
+	last_task_used_math = (struct task_struct *) 0;
+	current->tss.sig_address = pc;
+	current->tss.sig_desc = SUBSIG_FPERROR; /* as good as any */
+	send_sig(SIGFPE, current, 1);
 	return;
 }
 
@@ -87,7 +232,11 @@
 {
 	printk("Tag overflow trap at PC %08lx NPC %08lx PSR %08lx\n",
 	       pc, npc, psr);
-	halt();
+	if(psr & PSR_PS)
+		panic("KERNEL tag overflow trap, wowza!");
+	current->tss.sig_address = pc;
+	current->tss.sig_desc = SUBSIG_TAG; /* as good as any */
+	send_sig(SIGEMT, current, 1);
 	return;
 }
 
@@ -97,7 +246,9 @@
 {
 	printk("Watchpoint detected at PC %08lx NPC %08lx PSR %08lx\n",
 	       pc, npc, psr);
-	halt();
+	if(psr & PSR_PS)
+		panic("Tell me what a watchpoint trap is, and I'll then deal "
+		      "with such a beast...");
 	return;
 }
 
@@ -112,16 +263,6 @@
 }
 
 void
-handle_iacc_error(struct pt_regs *regs, unsigned long pc, unsigned long npc,
-		       unsigned long psr)
-{
-	printk("Instruction Access Error at PC %08lx NPC %08lx PSR %08lx\n",
-	       pc, npc, psr);
-	halt();
-	return;
-}
-
-void
 handle_cp_disabled(struct pt_regs *regs, unsigned long pc, unsigned long npc,
 		       unsigned long psr)
 {
@@ -152,16 +293,6 @@
 }
 
 void
-handle_dacc_error(struct pt_regs *regs, unsigned long pc, unsigned long npc,
-		       unsigned long psr)
-{
-	printk("Data Access Error at PC %08lx NPC %08lx PSR %08lx\n",
-	       pc, npc, psr);
-	halt();
-	return;
-}
-
-void
 handle_hw_divzero(struct pt_regs *regs, unsigned long pc, unsigned long npc,
 		       unsigned long psr)
 {
@@ -171,33 +302,9 @@
 	return;
 }
 
-void
-handle_dstore_error(struct pt_regs *regs, unsigned long pc, unsigned long npc,
-		       unsigned long psr)
+void do_ast(struct pt_regs *regs)
 {
-	printk("Data Store Error at PC %08lx NPC %08lx PSR %08lx\n",
-	       pc, npc, psr);
-	halt();
-	return;
-}
-
-void
-handle_dacc_mmu_miss(struct pt_regs *regs, unsigned long pc, unsigned long npc,
-		       unsigned long psr)
-{
-	printk("Data Access MMU-Miss Exception at PC %08lx NPC %08lx PSR %08lx\n",
-	       pc, npc, psr);
-	halt();
-	return;
-}
-
-void
-handle_iacc_mmu_miss(struct pt_regs *regs, unsigned long pc, unsigned long npc,
-		       unsigned long psr)
-{
-	printk("Instruction Access MMU-Miss Exception at PC %08lx NPC %08lx PSR %08lx\n",
-	       pc, npc, psr);
-	halt();
+	panic("Don't know how to handle AST traps yet ;-(\n");
 	return;
 }
 
@@ -214,8 +321,6 @@
 unsigned int thiscpus_tbr;
 int thiscpus_mid;
 
-/* #define SMP_TESTING */
-
 void
 trap_init(void)
 {
@@ -227,12 +332,12 @@
 		return;
 	}
 	if(sparc_cpu_model != sun4m) {
-		printk("trap_init: Multiprocessor on a non-sun4m! Aieee...\n");
-		printk("trap_init: Cannot continue, bailing out.\n");
+		prom_printf("trap_init: Multiprocessor on a non-sun4m! Aieee...\n");
+		prom_printf("trap_init: Cannot continue, bailing out.\n");
 		prom_halt();
 	}
 	/* Ok, we are on a sun4m with multiple cpu's */
-	printk("trap_init: Multiprocessor detected, initiating CPU-startup. cpus=%d\n",
+	prom_printf("trap_init: Multiprocessor detected, initiating CPU-startup. cpus=%d\n",
 	       linux_num_cpus);
 	linux_smp_still_initting = 1;
 	ctx_reg.which_io = 0x0;  /* real ram */
@@ -250,23 +355,14 @@
 			thiscpus_mid = linux_cpus[i].mid;
 			thiscpus_tbr = (unsigned int)
 				percpu_table[cpuid].trap_table;
-#ifdef SMP_TESTING
-			printk("thiscpus_tbr = %08x\n", thiscpus_tbr);
-			printk("About to fire up cpu %d mid %d cpuid %d\n", i,
-			       linux_cpus[i].mid, cpuid);
-#endif
 			prom_startcpu(linux_cpus[i].prom_node, &ctx_reg, 0x0,
 				      (char *) sparc_cpu_startup);
-			printk("Waiting for cpu %d to start up...\n", i);
+			prom_printf("Waiting for cpu %d to start up...\n", i);
 			while(percpu_table[cpuid].cpu_is_alive == 0) {
 				static int counter = 0;
 				counter++;
-				if(counter>200) {
-#ifdef SMP_TESTING
-					printk("UGH, CPU would not start up ;-( \n");
-#endif
+				if(counter>200)
 					break;
-				}
 				__delay(200000);
 			}
 		}

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this