Index: trunk/hal/tsar_mips32/core/hal_switch.S
===================================================================
--- trunk/hal/tsar_mips32/core/hal_switch.S	(revision 407)
+++ trunk/hal/tsar_mips32/core/hal_switch.S	(revision 408)
@@ -37,4 +37,6 @@
 hal_do_cpu_switch:
 
+    /* save old thread context */
+ 
     move    $26,   $4                  /* $26 <= ctx_old */
 
@@ -49,5 +51,4 @@
     sw      $6,    6*4($26)         
     sw      $7,    7*4($26)         
-
     sw      $8,    8*4($26)         
     sw      $9,    9*4($26)         
@@ -58,5 +59,4 @@
     sw      $14,  14*4($26)         
     sw      $15,  15*4($26)         
-
     sw      $16,  16*4($26)         
     sw      $17,  17*4($26)         
@@ -67,5 +67,4 @@
     sw      $22,  22*4($26)         
     sw      $23,  23*4($26)         
-
     sw      $24,  24*4($26)         
     sw      $25,  25*4($26)         
@@ -91,6 +90,6 @@
 	sw      $27,  33*4($26)           /* save c2_mode to slot 33 */
 
-    sync                            
-
+    /* restore new thread context */
+ 
     move    $26,   $5                  /* $26 <= ctx_new */
 
@@ -105,5 +104,4 @@
     lw      $6,    6*4($26)         
     lw      $7,    7*4($26)         
-
     lw      $8,    8*4($26)         
     lw      $9,    9*4($26)         
@@ -114,5 +112,4 @@
     lw      $14,  14*4($26)         
     lw      $15,  15*4($26)         
-
 	lw      $16,  16*4($26)         
 	lw      $17,  17*4($26)         
@@ -123,5 +120,4 @@
     lw      $22,  22*4($26)         
     lw      $23,  23*4($26)         
-
     lw      $24,  24*4($26)         
     lw      $25,  25*4($26)         
@@ -149,35 +145,20 @@
     mtc0	$26,  $12                  /* restore c0_sr from slot 34 */
 
+    sync                            
+
     jr      $31                        /* return to caller */
     nop
 
 #---------------------------------------------------------------------------------
-# The hal_do_cpu_save()function makes the following assumptions:
+# The hal_do_cpu_save()function makes the following assumption:
 # - register $4 contains a pointer on the target thread context.
-# - register $5 contains the target thread descriptor pointer.
-# - register $6 contains the offset to add to stack pointer.
 #---------------------------------------------------------------------------------
 hal_do_cpu_save:
 
-    move    $26,  $4                  /* $26 <= context */
-
-    move    $27,  $5
-	sw      $27,  35*4($26)           /* save child thread to slot 35 */
-
-    add     $27,  $6,  $29
-    sw      $27,  29*4($26)           /* save (sp_29 + offset) to slot 29 */
-
-    mfc0    $27,  $12               
-	sw      $27,  34*4($26)           /* save c0_sr to slot 34 */
-
-	mfc2    $27,  $0                
-	sw      $27,  32*4($26)           /* save c2_ptpr to slot 32 */
-
-	mfc2    $27,  $1                
-	sw      $27,  33*4($26)           /* save c2_mode to slot 33 */
-
-    mfc0    $27,   $14              
+    move    $26,  $4                  /* $26 <= &context */
+
+    mfc0    $27,  $14               
     sw      $27,   0*4($26)           /* save c0_epc to slot 0 */
- 
+
     sw      $1,    1*4($26)         
     sw      $2,    2*4($26)         
@@ -187,5 +168,4 @@
     sw      $6,    6*4($26)         
     sw      $7,    7*4($26)         
-
     sw      $8,    8*4($26)         
     sw      $9,    9*4($26)         
@@ -196,5 +176,4 @@
     sw      $14,  14*4($26)         
     sw      $15,  15*4($26)         
-
     sw      $16,  16*4($26)         
     sw      $17,  17*4($26)         
@@ -205,18 +184,25 @@
     sw      $22,  22*4($26)         
     sw      $23,  23*4($26)         
-
     sw      $24,  24*4($26)         
-    sw      $25,  25*4($26)         
-
+    sw      $25,  25*4($26)
+         
     mfhi    $27                     
-    sw      $27,  26*4($26)           /* save hi to slot 26 */
-
+    sw      $27,  26*4($26)           /* save hi      to slot 26 */
     mflo    $27                     
-    sw      $27,  27*4($26)           /* save lo to slot 27 */
-
-    sw      $28,  28*4($26)           /* save gp to slot 28 */
-
-    sw      $30,  30*4($26)           /* save s8 to slot 30 */
-    sw      $31,  31*4($26)           /* save ra to slot 31 */
+    sw      $27,  27*4($26)           /* save lo      to slot 27 */
+
+    sw      $28,  28*4($26)           /* save gp      to slot 28 */
+    sw      $29,  29*4($26)           /* save sp      to slot 29 */
+    sw      $30,  30*4($26)           /* save s8      to slot 30 */
+    sw      $31,  31*4($26)           /* save ra      to slot 31 */
+
+	mfc2    $27,  $0                
+	sw      $27,  32*4($26)           /* save c2_ptpr to slot 32 */
+	mfc2    $27,  $1                
+	sw      $27,  33*4($26)           /* save c2_mode to slot 33 */
+    mfc0    $27,  $12              
+	sw      $27,  34*4($26)           /* save c0_sr   to slot 34 */
+    mfc0    $27,  $4, 2              
+	sw      $27,  35*4($26)           /* save c0_th   to slot 35 */
 
     sync
