Index: trunk/hal/tsar_mips32/core/hal_uspace.c
===================================================================
--- trunk/hal/tsar_mips32/core/hal_uspace.c	(revision 407)
+++ trunk/hal/tsar_mips32/core/hal_uspace.c	(revision 425)
@@ -29,8 +29,11 @@
 #include <hal_irqmask.h>
 
+#include <printk.h>
+#include <thread.h>
+
 ///////////////////////////////////////////
 void hal_copy_from_uspace( void     * k_dst,
                            void     * u_src,
-                           uint32_t   size )
+                           uint32_t   size )  
 {
     uint32_t save_sr;
@@ -136,5 +139,4 @@
 {
     uint32_t save_sr;
-
     uint32_t src = (uint32_t)u_src;
     uint32_t dst = (uint32_t)k_dst;
@@ -142,5 +144,5 @@
     hal_disable_irq( &save_sr );
 
-    // loop on characters while ( (character != NUL) and (count < size ) 
+    // loop on characters while ( (character != NUL) and (count < size ) )
     asm volatile(
         ".set noreorder             \n"
@@ -148,12 +150,12 @@
         "move   $12,   %1           \n"   /* $12 <= u_src                   */
         "move   $13,   %2           \n"   /* $13 <= k_dst                   */
-        "mfc2   $15,   $1           \n"   /* $15 <= MMU_MODE                */
-        "ori    $14,   $15,  0x7    \n"   /* $14 <= mode DTLB on            */
+        "mfc2   $15,   $1           \n"   /* $15 <= mode DTLB and ITLB off  */
+        "ori    $14,   $15,  0x4    \n"   /* $14 <= mode DTLB on            */
         "1:                         \n"
         "mtc2   $14,   $1			\n"   /* MMU_MODE <= DTLB ON            */
         "lb     $10,   0($12)       \n"   /* read char from user space      */
-        "mtc2   $15,   $1			\n"   /* restore MMU_MODE               */
+        "mtc2   $15,   $1			\n"   /* restore DTLB and ITLB off      */
 	    "sb	    $10,   0($13)       \n"   /* store char to kernel space     */
-        "beq    $13,   $0,   2f     \n"   /* exit if char = 0               */
+        "beq    $10,   $0,   2f     \n"   /* exit if char = 0               */
         "addi   $11,   $11, -1      \n"   /* decrement count                */
         "addi   $12,   $12,  1      \n"   /* increment u_src pointer        */
@@ -178,5 +180,4 @@
 {
     uint32_t save_sr;
-
     uint32_t src = (uint32_t)k_src;
     uint32_t dst = (uint32_t)u_dst;
@@ -190,12 +191,12 @@
         "move   $12,   %1           \n"   /* $12 <= k_src                   */
         "move   $13,   %2           \n"   /* $13 <= u_dst                   */
-        "mfc2   $15,   $1           \n"   /* $15 <= MMU_MODE                */
-        "ori    $14,   $15,  0x7    \n"   /* $14 <= mode DTLB on            */
+        "mfc2   $15,   $1           \n"   /* $15 <= mode DTLB and ITLB off  */
+        "ori    $14,   $15,  0x4    \n"   /* $14 <= mode DTLB on            */
         "1:                         \n"
         "lb     $10,   0($12)       \n"   /* read char from kernel space    */
         "mtc2   $14,   $1			\n"   /* MMU_MODE <= DTLB ON            */
 	    "sb	    $10,   0($13)       \n"   /* store char to user space       */
-        "mtc2   $15,   $1			\n"   /* restore MMU_MODE               */
-        "beq    $13,   $0,   2f     \n"   /* exit if char == 0              */
+        "mtc2   $15,   $1			\n"   /* restore DTLB and ITLB off      */
+        "beq    $10,   $0,   2f     \n"   /* exit if char == 0              */
         "addi   $11,   $11, -1      \n"   /* decrement count                */
         "addi   $12,   $12,  1      \n"   /* increment k_src pointer        */
@@ -219,6 +220,5 @@
     uint32_t save_sr;
     uint32_t count = 0;
-
-    uint32_t str = (uint32_t)u_str;
+    uint32_t str   = (uint32_t)u_str;
 
     hal_disable_irq( &save_sr ); 
@@ -226,14 +226,14 @@
         asm volatile(
         ".set noreorder             \n"
-        "ori    $13,   %1,   0      \n"   /* $13 <= str                     */
-        "mfc2   $15,   $1           \n"   /* $15 <= MMU_MODE                */
-        "ori    $14,   $15,  0x7    \n"   /* $14 <= mode DTLB on            */
-        "mtc2   $14,   $1			\n"   /* MMU_MODE <= DTLB ON            */
+        "move   $13,   %1           \n"   /* $13 <= str                     */
+        "mfc2   $15,   $1           \n"   /* $15 <= DTLB and ITLB off       */
+        "ori    $14,   $15,  0x4    \n"   /* $14 <= mode DTLB on            */
         "1:                         \n"
+        "mtc2   $14,   $1			\n"   /* set DTLB on                    */
         "lb	    $12,   0($13)       \n"   /* read char from user space      */
+        "mtc2   $15,   $1			\n"   /* set DTLB off                   */
         "addi   $13,   $13,  1      \n"   /* increment address              */
         "bne    $12,   $0,   1b     \n"   /* loop until NUL found           */
         "addi	%0,    %0,   1      \n"   /* increment count                */
-        "mtc2   $15,   $1			\n"   /* restore MMU_MODE               */
         ".set reorder               \n"
         : "+r"(count) 
