Index: c/src/lib/libcpu/powerpc/ChangeLog
===================================================================
--- c/src/lib/libcpu/powerpc/ChangeLog	(revision 698c33623e4adf511338b82a32a29a1455443461)
+++ c/src/lib/libcpu/powerpc/ChangeLog	(revision 464ba4d0406ea55c4a5f3b684ba8750ce46927b0)
@@ -1,2 +1,9 @@
+2007-12-05	Till Straumann <strauman@slac.stanford.edu>
+
+	* new-exceptions/raw_exception.c, new-exceptions/raw_exception.h:
+	Added typedef for exception classes (classic, critical, ...
+	synchronous / asynchronous). ppc_vector_is_valid() now returns
+	the appropriate class.
+
 2007-12-05	Till Straumann <strauman@slac.stanford.edu>
 
Index: c/src/lib/libcpu/powerpc/new-exceptions/raw_exception.c
===================================================================
--- c/src/lib/libcpu/powerpc/new-exceptions/raw_exception.c	(revision 698c33623e4adf511338b82a32a29a1455443461)
+++ c/src/lib/libcpu/powerpc/new-exceptions/raw_exception.c	(revision 464ba4d0406ea55c4a5f3b684ba8750ce46927b0)
@@ -98,5 +98,5 @@
 #if ( defined(mpc860) || defined(mpc821) || defined(__ppc_generic) )
 
-static int mpc860_vector_is_valid(rtems_vector vector)
+static ppc_raw_exception_category mpc860_vector_is_valid(rtems_vector vector)
 {
   switch(vector) {
@@ -125,6 +125,6 @@
   case ASM_8XX_PERIFBREAK_VECTOR:
   case ASM_8XX_DEVPORT_VECTOR:
-    return 1;
-  default: return 0;
+    return PPC_EXC_CLASSIC;
+  default: return PPC_EXC_INVALID;
   }
 }
@@ -133,5 +133,5 @@
 #if (defined(mpc555) || defined(mpc505) || defined(__ppc_generic))
 
-static int mpc5xx_vector_is_valid(rtems_vector vector)
+static ppc_raw_exception_category mpc5xx_vector_is_valid(rtems_vector vector)
 {
   switch (current_ppc_cpu) {
@@ -160,12 +160,12 @@
         case ASM_5XX_MEBREAK_VECTOR:
         case ASM_5XX_NMEBREAK_VECTOR:
-          return 1;
+          return PPC_EXC_CLASSIC;
         default: 
-          return 0;
+          return PPC_EXC_INVALID;
       }
     default:
       printk("Please complete libcpu/powerpc/shared/new-exceptions/raw_exception.c\n");
       printk("current_ppc_cpu = %x\n", current_ppc_cpu);
-      return 0;
+      return PPC_EXC_INVALID;
   }
 }
@@ -173,21 +173,30 @@
 
 #if ( defined(ppc405) || defined(__ppc_generic) )
-static int ppc405_vector_is_valid(rtems_vector vector)
-
-{
-  switch(vector) {
-  case ASM_RESET_VECTOR: /* fall through */
-  case ASM_MACH_VECTOR:
+static ppc_raw_exception_category ppc405_vector_is_valid(rtems_vector vector)
+
+{
+ppc_raw_exception_category rval = PPC_EXC_INVALID;
+  switch(vector) {
+  case ASM_EXT_VECTOR:
+  case ASM_BOOKE_PIT_VECTOR:
+
+  	rval |= PPC_EXC_ASYNC;
+
+	/* fall through */
   case ASM_PROT_VECTOR:
   case ASM_ISI_VECTOR:
-  case ASM_EXT_VECTOR:
   case ASM_ALIGN_VECTOR:
   case ASM_PROG_VECTOR:
   case ASM_SYS_VECTOR:
-  case ASM_BOOKE_PIT_VECTOR:
   case ASM_BOOKE_ITLBMISS_VECTOR:
   case ASM_BOOKE_DTLBMISS_VECTOR:
-    return 1;
-  default: return 0;
+
+  	return rval | PPC_EXC_CLASSIC;
+
+  case ASM_RESET_VECTOR: /* fall through */
+  	rval |= PPC_EXC_ASYNC;
+  case ASM_MACH_VECTOR:
+    return rval | PPC_EXC_405_CRITICAL;
+  default: return PPC_EXC_INVALID;
   }
 }
@@ -196,5 +205,5 @@
 #if defined(PPC_HAS_60X_VECTORS) /* 60x style cpu types */
 
-static int altivec_vector_is_valid(rtems_vector vector)
+static ppc_raw_exception_category altivec_vector_is_valid(rtems_vector vector)
 {
 	if ( ppc_cpu_has_altivec() ) {
@@ -202,13 +211,13 @@
 			case ASM_60X_VEC_VECTOR:
 			case ASM_60X_VEC_ASSIST_VECTOR:
-				return 1;
+				return PPC_EXC_CLASSIC;
 			default:
 				break;
 		}
 	}
-  return 0;
-}
-
-static int mpc750_vector_is_valid(rtems_vector vector)
+  return PPC_EXC_INVALID;
+}
+
+static ppc_raw_exception_category mpc750_vector_is_valid(rtems_vector vector)
 
 {
@@ -228,10 +237,10 @@
   case ASM_60X_SYSMGMT_VECTOR:
   case ASM_60X_ITM_VECTOR:
-    return 1;
-  default: return 0;
-  }
-}
-
-static int PSIM_vector_is_valid(rtems_vector vector)
+    return PPC_EXC_CLASSIC;
+  default: return PPC_EXC_INVALID;
+  }
+}
+
+static ppc_raw_exception_category PSIM_vector_is_valid(rtems_vector vector)
 {
   switch(vector) {
@@ -245,11 +254,11 @@
   case ASM_FLOAT_VECTOR:
   case ASM_DEC_VECTOR:
-    return 1;
+    return PPC_EXC_CLASSIC;
   case ASM_SYS_VECTOR:
-    return 0;
+    return PPC_EXC_INVALID;
   case ASM_TRACE_VECTOR:
-    return 1;
+    return PPC_EXC_CLASSIC;
   case ASM_60X_PERFMON_VECTOR:
-    return 0;
+    return PPC_EXC_INVALID;
   case ASM_60X_IMISS_VECTOR: /* fall through */
   case ASM_60X_DLMISS_VECTOR:
@@ -257,12 +266,12 @@
   case ASM_60X_ADDR_VECTOR:
   case ASM_60X_SYSMGMT_VECTOR:
-    return 1;
+    return PPC_EXC_CLASSIC;
   case ASM_60X_ITM_VECTOR:
-    return 0;
-  }
-  return 0;
-}
-
-static int mpc603_vector_is_valid(rtems_vector vector)
+    return PPC_EXC_INVALID;
+  }
+  return PPC_EXC_INVALID;
+}
+
+static ppc_raw_exception_category mpc603_vector_is_valid(rtems_vector vector)
 {
   switch(vector) {
@@ -278,7 +287,7 @@
   case ASM_SYS_VECTOR:
   case ASM_TRACE_VECTOR:
-    return 1;
+    return PPC_EXC_CLASSIC;
   case ASM_60X_PERFMON_VECTOR:
-    return 0;
+    return PPC_EXC_INVALID;
   case ASM_60X_IMISS_VECTOR: /* fall through */
   case ASM_60X_DLMISS_VECTOR:
@@ -286,12 +295,12 @@
   case ASM_60X_ADDR_VECTOR:
   case ASM_60X_SYSMGMT_VECTOR:
-    return 1;
+    return PPC_EXC_CLASSIC;
   case ASM_60X_ITM_VECTOR:
-    return 0;
-  }
-  return 0;
-}
-
-static int mpc604_vector_is_valid(rtems_vector vector)
+    return PPC_EXC_INVALID;
+  }
+  return PPC_EXC_INVALID;
+}
+
+static ppc_raw_exception_category mpc604_vector_is_valid(rtems_vector vector)
 {
   switch(vector) {
@@ -308,26 +317,42 @@
   case ASM_TRACE_VECTOR:
   case ASM_60X_PERFMON_VECTOR:
-    return 1;
+    return PPC_EXC_CLASSIC;
   case ASM_60X_IMISS_VECTOR: /* fall through */
   case ASM_60X_DLMISS_VECTOR:
   case ASM_60X_DSMISS_VECTOR:
-    return 0;
+    return PPC_EXC_INVALID;
   case ASM_60X_ADDR_VECTOR: /* fall through */
   case ASM_60X_SYSMGMT_VECTOR:
-    return 1;
+    return PPC_EXC_CLASSIC;
   case ASM_60X_ITM_VECTOR:
-    return 0;
-  }
-  return 0;
-}
-
-static int e500_vector_is_valid(rtems_vector vector)
-{
+    return PPC_EXC_INVALID;
+  }
+  return PPC_EXC_INVALID;
+}
+
+static ppc_raw_exception_category e500_vector_is_valid(rtems_vector vector)
+{
+ppc_raw_exception_category rval = PPC_EXC_INVALID;
+
 	switch (vector) {
-	case ASM_RESET_VECTOR:
 	case ASM_MACH_VECTOR:
+		return PPC_EXC_E500_MACHCHK;
+
+	case ASM_BOOKE_CRIT_VECTOR:
+	case ASM_BOOKE_WDOG_VECTOR:
+		rval |= PPC_EXC_ASYNC;
+		/* fall thru */
+	case ASM_TRACE_VECTOR:
+		return rval | PPC_EXC_BOOKE_CRITICAL;
+
+	case ASM_EXT_VECTOR:
+	case ASM_DEC_VECTOR:
+	case ASM_BOOKE_FIT_VECTOR:
+		rval |= PPC_EXC_ASYNC;
+
+		/* fall thru */
+
 	case ASM_PROT_VECTOR:
 	case ASM_ISI_VECTOR:
-	case ASM_EXT_VECTOR:
 	case ASM_ALIGN_VECTOR:
 	case ASM_PROG_VECTOR:
@@ -335,48 +360,43 @@
 	case ASM_SYS_VECTOR:
 	case /* APU unavailable      */ 0x0b:
-	case ASM_DEC_VECTOR:
+
 	case ASM_60X_DLMISS_VECTOR:
 	case ASM_60X_DSMISS_VECTOR:
-	case ASM_TRACE_VECTOR:
 	case ASM_60X_VEC_VECTOR:
 	case ASM_60X_PERFMON_VECTOR:
 
-	case 0x13 /*ASM_BOOKE_FIT_VECTOR*/:
-	case 0x14 /*ASM_BOOKE_WDOG_VECTOR*/:
 	case /* emb FP data          */ 0x15:
 	case /* emb FP round         */ 0x16:
-		return 1;
+		return rval | PPC_EXC_CLASSIC;
 	default:
 		break;
 	}
-	return 0;
+	return PPC_EXC_INVALID;
 }
 
 #endif /* 60x style cpu types */
 
-int ppc_vector_is_valid(rtems_vector vector)
-{
+ppc_raw_exception_category ppc_vector_is_valid(rtems_vector vector)
+{
+ppc_raw_exception_category rval = PPC_EXC_INVALID;
+
      switch (current_ppc_cpu) {
 #if defined(PPC_HAS_60X_VECTORS)
 	case PPC_7400:
-            if ( altivec_vector_is_valid(vector) )
-                return 1;
+            if ( ( rval = altivec_vector_is_valid(vector)) )
+                return rval;
             /* else fall thru */
         case PPC_750:
-            if (!mpc750_vector_is_valid(vector)) {
-                return 0;
-            }
+            rval = mpc750_vector_is_valid(vector);
             break;
         case PPC_7455:   /* Kate Feng */
         case PPC_7457: 
-            if ( altivec_vector_is_valid(vector) )
-                return 1;
+            if ( ( rval = altivec_vector_is_valid(vector) ) )
+                return rval;
             /* else fall thru */
         case PPC_604:
         case PPC_604e:
         case PPC_604r:
-            if (!mpc604_vector_is_valid(vector)) {
-                return 0;
-            }
+            rval = mpc604_vector_is_valid(vector);
             break;
         case PPC_603:
@@ -390,38 +410,26 @@
         case PPC_e300c2:
         case PPC_e300c3:
-            if (!mpc603_vector_is_valid(vector)) {
-                return 0;
-            }
+            rval = mpc603_vector_is_valid(vector);
             break;
         case PPC_PSIM:
-            if (!PSIM_vector_is_valid(vector)) {
-                return 0;
-            }
+            rval = PSIM_vector_is_valid(vector);
             break;
 		case PPC_8540:
-			if ( !e500_vector_is_valid(vector) ) {
-				return 0;
-			}
+			rval = e500_vector_is_valid(vector);
 			break;
 #endif
 #if ( defined(mpc555) || defined(mpc505) || defined(__ppc_generic) )
         case PPC_5XX:
-            if (!mpc5xx_vector_is_valid(vector)) {
-                return 0;
-            }
+            rval = mpc5xx_vector_is_valid(vector);
             break;
 #endif
 #if ( defined(mpc860) || defined(mpc821) || defined(__ppc_generic) )
         case PPC_860:
-            if (!mpc860_vector_is_valid(vector)) {
-                return 0;
-            }
+            rval = mpc860_vector_is_valid(vector);
             break;
 #endif
 #if ( defined(ppc405) || defined(__ppc_generic) )
         case PPC_405:
-            if (!ppc405_vector_is_valid(vector)) {
-                return 0;
-            }
+            rval = ppc405_vector_is_valid(vector);
             break;
 #endif
@@ -430,7 +438,11 @@
                    "libcpu/powerpc/new-exceptions/raw_exception.c\n"
                    "current_ppc_cpu = %x\n", current_ppc_cpu);
-            return 0;
+            return PPC_EXC_INVALID;
      }
-     return 1;
+	 /* set ASYNC flag for all CPU flavors EE and DEC */
+	 if ( ASM_EXT_VECTOR == rval || ASM_DEC_VECTOR == rval ) {
+	 	rval |= PPC_EXC_ASYNC;
+	 }
+     return rval;
 }
 
@@ -439,5 +451,5 @@
     rtems_interrupt_level k;
 
-    if (!ppc_vector_is_valid(except->hdl.vector)) {
+    if ( PPC_EXC_INVALID == ppc_vector_is_valid(except->hdl.vector) ) {
       printk("ppc_set_exception: vector %d is not valid\n",
               except->hdl.vector);
@@ -478,5 +490,5 @@
 	int i;
 
-	if (!ppc_vector_is_valid(except->hdl.vector)){
+	if ( PPC_EXC_INVALID == ppc_vector_is_valid(except->hdl.vector) ) {
 		return 0;
 	}
@@ -501,5 +513,5 @@
   rtems_interrupt_level k;
 
-  if (!ppc_vector_is_valid(except->hdl.vector)){
+  if ( PPC_EXC_INVALID == ppc_vector_is_valid(except->hdl.vector) ) {
     return 0;
   }
@@ -557,5 +569,5 @@
 
 	for (i=0; i < config->exceptSize; i++) {
-		if (!ppc_vector_is_valid(raw_except_table[i].hdl.vector)){
+		if ( PPC_EXC_INVALID == ppc_vector_is_valid(raw_except_table[i].hdl.vector) ) {
 			continue;
 		}
Index: c/src/lib/libcpu/powerpc/new-exceptions/raw_exception.h
===================================================================
--- c/src/lib/libcpu/powerpc/new-exceptions/raw_exception.h	(revision 698c33623e4adf511338b82a32a29a1455443461)
+++ c/src/lib/libcpu/powerpc/new-exceptions/raw_exception.h	(revision 464ba4d0406ea55c4a5f3b684ba8750ce46927b0)
@@ -360,4 +360,17 @@
 
 /*
+ * Exceptions of different categories use different SRR registers
+ * to save machine state (:-()
+ */
+typedef enum {
+	PPC_EXC_INVALID        = 0,
+	PPC_EXC_CLASSIC        = 1,
+	PPC_EXC_405_CRITICAL   = 2,
+	PPC_EXC_BOOKE_CRITICAL = 3,
+	PPC_EXC_E500_MACHCHK   = 4,
+	PPC_EXC_ASYNC          = 0x10000,
+} ppc_raw_exception_category;
+
+/*
  * C callable function enabling to set up one raw idt entry
  */
@@ -376,6 +389,7 @@
 /*
  * C callable function enabling to check if vector is valid
- */
-extern int ppc_vector_is_valid(rtems_vector vector);
+ * and returns category.
+ */
+extern ppc_raw_exception_category ppc_vector_is_valid(rtems_vector vector);
 
 /*
