Index: kernel/arch/ppc32/src/exception.S
===================================================================
--- kernel/arch/ppc32/src/exception.S	(revision beb16cfab60e9cad4457c189c54a916ace701046)
+++ kernel/arch/ppc32/src/exception.S	(revision 087129655518818663e2409b7ecc056ac1470f17)
@@ -31,6 +31,6 @@
 #include <arch/mm/page.h>
 #include <arch/istate_struct.h>
+#include <arch/stack.h>
 #include <align.h>
-#include <arch/stack.h>
 
 .section K_UNMAPPED_TEXT_START, "ax"
@@ -45,22 +45,19 @@
 	mtsprg2 sp
 	
-	# check whether SP is in kernel
-	
-	andis. sp, sp, 0x8000
+	# check whether the previous mode was user or kernel
+	
+	mfsrr1 sp # use sp as a temporary register to hold SRR1
+	andi. sp, sp, MSR_PR 
 	bne 1f
-	
-		# stack is in user-space
-		
-		mfsprg0 sp
-	
-	b 2f
-	
-	1:
-	
-		# stack is in kernel
+		# previous mode was kernel
 		
 		mfsprg2 sp
 		subis sp, sp, 0x8000
-	
+	b 2f
+	
+	1:
+		# previous mode was user
+		
+		mfsprg0 sp
 	2:
 	
@@ -266,4 +263,7 @@
 	
 	mfsrr1 r5
+
+	andi. r5, r5, MSR_PR
+
 	andi. r5, r5, MSR_FP
 	mfmsr r12
