Index: trunk/hal/tsar_mips32/core/hal_uspace.c
===================================================================
--- trunk/hal/tsar_mips32/core/hal_uspace.c	(revision 626)
+++ trunk/hal/tsar_mips32/core/hal_uspace.c	(revision 637)
@@ -32,7 +32,7 @@
 ///////////////////////////////////////////////////////////////////////////////////////
 // This function moves <size> bytes from a source buffer in user virtual space,
-// defined by the <u_src> argument, to a destination kernel buffer, defined by the
-// <k_cxy> and <k_dst> arguments.
-// It works in a critical section, as it modifies briefly two CP2 registers:
+// defined by the <u_src_ptr> argument, to a destination kernel buffer, defined by the
+// <k_dst_xp> argument.
+// It works in a critical section, as it modifies two CP2 registers:
 // It activates briefly the DATA_MMU by writing into the CP2_MODE register to access the
 // user buffer, and modifies the CP2_DATA_EXT register to access the kernel buffer.
@@ -41,18 +41,18 @@
 // If the buffers are not aligned, it moves all data byte per byte.
 ///////////////////////////////////////////////////////////////////////////////////////
-// @ k_cxy    : cluster of destination kernel buffer
-// @ k_dst    : pointer on destination kernel buffer
-// @ u_src    : pointer on source user buffer
+// @ k_dst_xp  : extended pointer on destination kernel buffer
+// @ u_src_ptr : pointer on source user buffer
 // @ size     : number of bytes to move
 ///////////////////////////////////////////////////////////////////////////////////////
-void hal_copy_from_uspace( cxy_t      k_cxy,
-                           void     * k_dst,
-                           void     * u_src,
+void hal_copy_from_uspace( xptr_t     k_dst_xp,
+                           void     * u_src_ptr,
                            uint32_t   size )  
 {
     uint32_t save_sr;
-	uint32_t words;                        // number of words (if buffers aligned)
-    uint32_t src = (uint32_t)u_src;
-    uint32_t dst = (uint32_t)k_dst;
+	uint32_t words;                            // number of words (if buffers aligned)
+    uint32_t src = (uint32_t)u_src_ptr;
+    uint32_t dst = (uint32_t)GET_PTR( k_dst_xp );
+    uint32_t cxy = (uint32_t)GET_CXY( k_dst_xp );
+    
  
 #if DEBUG_HAL_USPACE
@@ -61,5 +61,5 @@
 if( cycle > DEBUG_HAL_USPACE )
 printk("\n[%s] thread[%x,%x] enter / %d bytes / u_buf(%x,%x) -> k_buf(%x,%x) / cycle %d\n", 
-__FUNCTION__, this->process->pid, this->trdid, size, local_cxy, u_src, k_cxy, k_dst, cycle );
+__FUNCTION__, this->process->pid, this->trdid, size, local_cxy, src, cxy, dst, cycle );
 #endif
 
@@ -80,7 +80,7 @@
                   "ori    $13,   $12,   0x4	  \n"   /* $13 <= MMU_MODE with DTLB  */
 
-                  /* save old MMU_DATA_EXT and set k_cxy in it                    */
+                  /* save old MMU_DATA_EXT and set cxy in it                      */
                   "mfc2   $16,   $24          \n"   /* $16 <= old MMU_DATA_EXT    */
-                  "mtc2   %4,    $24          \n"   /* MMU_DATA_EXT <= k_cxy      */
+                  "mtc2   %4,    $24          \n"   /* MMU_DATA_EXT <= cxy        */
 
                   /* transfer one word per iteration in first loop if aligned     */
@@ -118,5 +118,5 @@
                   ".set reorder               \n"
                   : 
-                  : "r"(src) , "r"(dst) , "r"(words) , "r"(size) , "r"(k_cxy)
+                  : "r"(src) , "r"(dst) , "r"(words) , "r"(size) , "r"(cxy)
                   : "$8","$9","$10","$11","$12","$13","$14","$15","$16","memory" );
 
@@ -128,5 +128,5 @@
 if( cycle > DEBUG_HAL_USPACE )
 printk("\n[%s] thread[%x,%x] moved %d bytes / u_buf(%x,%x) -> k_buf(%x,%x) / cycle %d\n", 
-__FUNCTION__, this->process->pid, this->trdid, size, local_cxy, u_src, k_cxy, k_dst, cycle );
+__FUNCTION__, this->process->pid, this->trdid, size, local_cxy, src, cxy, dst, cycle );
 #endif
 
@@ -135,7 +135,7 @@
 ///////////////////////////////////////////////////////////////////////////////////////
 // This function moves <size> bytes from a source kernel buffer, defined by the
-// <k_cxy> and <k_src> arguments, to a destination buffer in user virtual space,
-// defined by the <u_dst> argument.
-// It works in a critical section, as it modifies briefly two CP2 registers:
+// <k_src_xp> argument, to a destination buffer in user virtual space, defined by 
+// the <u_dst_ptr> argument.
+// It works in a critical section, as it modifies two CP2 registers:
 // It activates briefly the DATA_MMU by writing into the CP2_MODE register to access the
 // user buffer, and modifies the CP2_DATA_EXT register to access the kernel buffer.
@@ -144,18 +144,17 @@
 // If the buffers are not aligned, it moves all data byte per byte.
 ///////////////////////////////////////////////////////////////////////////////////////
-// @ k_cxy    : cluster of destination kernel buffer
-// @ k_dst    : pointer on destination kernel buffer
-// @ u_src    : pointer on source user buffer
-// @ size     : number of bytes to move
-///////////////////////////////////////////////////////////////////////////////////////
-void hal_copy_to_uspace( cxy_t      k_cxy,
-                         void     * k_src,
-                         void     * u_dst,
+// @ u_dst_ptr : pointer on destination user buffer
+// @ k_src_xp  : extended pointer on source kernel buffer
+// @ size      : number of bytes to move
+///////////////////////////////////////////////////////////////////////////////////////
+void hal_copy_to_uspace( void     * u_dst_ptr,
+                         xptr_t     k_src_xp,
                          uint32_t   size )
 {
     uint32_t save_sr;
-	uint32_t words;                   // number of words (if buffers aligned)
-    uint32_t src = (uint32_t)k_src;
-    uint32_t dst = (uint32_t)u_dst;
+	uint32_t words;                           // number of words (if buffers aligned)
+    uint32_t dst = (uint32_t)u_dst_ptr;
+    uint32_t src = (uint32_t)GET_PTR( k_src_xp );
+    uint32_t cxy = (uint32_t)GET_CXY( k_src_xp );
 
 #if DEBUG_HAL_USPACE
@@ -164,5 +163,5 @@
 if( cycle > DEBUG_HAL_USPACE )
 printk("\n[%s] thread[%x,%x] enter / %d bytes / k_buf(%x,%x) -> u_buf(%x,%x) / cycle %d\n", 
-__FUNCTION__, this->process->pid, this->trdid, size, k_cxy, k_src, local_cxy, u_dst, cycle );
+__FUNCTION__, this->process->pid, this->trdid, size, cxy, src, local_cxy, dst, cycle );
 #endif
 
@@ -183,7 +182,7 @@
                   "ori    $13,   $12,   0x4	  \n"   /* $13 <= MMU_MODE with DTLB  */
 
-                  /* save old MMU_DATA_EXT and set k_cxy in it                    */
+                  /* save old MMU_DATA_EXT and set cxy in it                      */
                   "mfc2   $16,   $24          \n"   /* $16 <= old MMU_DATA_EXT    */
-                  "mtc2   %4,    $24          \n"   /* MMU_DATA_EXT <= k_cxy      */
+                  "mtc2   %4,    $24          \n"   /* MMU_DATA_EXT <= cxy        */
 
                   /* transfer one word per iteration in first loop if aligned     */
@@ -221,5 +220,5 @@
                   ".set reorder               \n"
                   : 
-                  : "r"(src) , "r"(dst) , "r"(words) , "r"(size) , "r"(k_cxy)
+                  : "r"(src) , "r"(dst) , "r"(words) , "r"(size) , "r"(cxy)
                   : "$8","$9","$10","$11","$12","$13","$14","$15","$16","memory" );
 
@@ -231,32 +230,40 @@
 if( cycle > DEBUG_HAL_USPACE )
 printk("\n[%s] thread[%x,%x] moved %d bytes / k_buf(%x,%x) -> u_buf(%x,%x) / cycle %d\n", 
-__FUNCTION__, this->process->pid, this->trdid, size, k_cxy, k_src, local_cxy, u_dst, cycle );
+__FUNCTION__, this->process->pid, this->trdid, size, cxy, src, local_cxy, dst, cycle );
 #endif
 
 }  // end hal_copy_to_uspace()
 
-//////////////////////////////////////////////
-void hal_strcpy_from_uspace( char     * k_dst,
-                             char     * u_src,
+/////////////////////////////////////////////////
+void hal_strcpy_from_uspace( xptr_t     k_dst_xp,
+                             char     * u_src_ptr,
                              uint32_t   size )
 {
     uint32_t save_sr;
-    uint32_t src = (uint32_t)u_src;
-    uint32_t dst = (uint32_t)k_dst;
+    uint32_t src = (uint32_t)u_src_ptr;
+    uint32_t dst = (uint32_t)GET_PTR( k_dst_xp );
+    uint32_t cxy = (uint32_t)GET_CXY( k_dst_xp );
 
     hal_disable_irq( &save_sr );
 
     // loop on characters while ( (character != NUL) and (count < size ) )
+
     asm volatile(
         ".set noreorder             \n"
+
+        /* save old MMU_DATA_EXT and set cxy in it                          */
+        "mfc2   $16,   $24          \n"   /* $16 <= old MMU_DATA_EXT        */
+        "mtc2   %3,    $24          \n"   /* MMU_DATA_EXT <= cxy            */
+
         "move   $11,   %0           \n"   /* $11 <= count == size           */
         "move   $12,   %1           \n"   /* $12 <= u_src                   */
         "move   $13,   %2           \n"   /* $13 <= k_dst                   */
-        "mfc2   $15,   $1           \n"   /* $15 <= mode DTLB and ITLB off  */
-        "ori    $14,   $15,  0x4    \n"   /* $14 <= mode DTLB on            */
+        "mfc2   $15,   $1           \n"   /* $15 <= MMU_MODE                */
+        "ori    $14,   $15,  0x4    \n"   /* $14 <= MMU_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 DTLB and ITLB off      */
+        "mtc2   $15,   $1			\n"   /* MMU_MODE <= DTLB OFF           */
 	    "sb	    $10,   0($13)       \n"   /* store char to kernel space     */
         "beq    $10,   $0,   2f     \n"   /* exit if char = 0               */
@@ -268,8 +275,12 @@
         "2:                         \n"
         "nop                        \n"
+
+        /* restore old MMU_DATA_EXT register                                */
+        "mtc2   $16,   $24          \n"   /* MMU_DATA_EXT <= $16            */
+
         ".set reorder               \n"
         : 
-        : "r"(size),"r"(src),"r"(dst)
-        : "$10","$11","$12","$13","$14","$15" );
+        : "r"(size) , "r"(src) , "r"(dst) , "r"(cxy)
+        : "$10","$11","$12","$13","$14","$15","$16" );
         
     hal_restore_irq( save_sr ); 
@@ -277,40 +288,52 @@
 } // hal_strcpy_from_uspace()
 
-////////////////////////////////////////////
-void hal_strcpy_to_uspace( char     * u_dst,
-                           char     * k_src,
+////////////////////////////////////////////////
+void hal_strcpy_to_uspace( char     * u_dst_ptr,
+                           xptr_t     k_src_xp,
                            uint32_t   size )
 {
     uint32_t save_sr;
-    uint32_t src = (uint32_t)k_src;
-    uint32_t dst = (uint32_t)u_dst;
+    uint32_t dst = (uint32_t)u_dst_ptr;
+    uint32_t src = (uint32_t)GET_PTR( k_src_xp );
+    uint32_t cxy = (uint32_t)GET_CXY( k_src_xp );
 
     hal_disable_irq( &save_sr );
 
     // loop on characters while ( (character != NUL) and (count < size) ) 
+
     asm volatile(
         ".set noreorder             \n"
+
+        /* save old MMU_DATA_EXT and set cxy in it                          */
+        "mfc2   $16,   $24          \n"   /* $16 <= old MMU_DATA_EXT        */
+        "mtc2   %3,    $24          \n"   /* MMU_DATA_EXT <= cxy            */
+
         "move   $11,   %0           \n"   /* $11 <= count == size           */
         "move   $12,   %1           \n"   /* $12 <= k_src                   */
         "move   $13,   %2           \n"   /* $13 <= u_dst                   */
-        "mfc2   $15,   $1           \n"   /* $15 <= mode DTLB and ITLB off  */
-        "ori    $14,   $15,  0x4    \n"   /* $14 <= mode DTLB on            */
+        "mfc2   $15,   $1           \n"   /* $15 <= MMU_MODE                */
+        "ori    $14,   $15,  0x4    \n"   /* $14 <= MMU_MODE modified       */
+
         "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 DTLB and ITLB off      */
+        "mtc2   $15,   $1			\n"   /* MMU_MODE <= DTLB 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        */
-        "beq    $11,   $0,   2f     \n"   /* exit if count == size          */
+        "beq    $11,   $0,   2f     \n"   /* exit if count == 0             */
         "addi   $13,   $13,  1      \n"   /* increment u_src pointer        */
         "j                   1b     \n"   /* jump to next iteration         */
         "2:                         \n"
         "nop                        \n"
+
+        /* restore old MMU_DATA_EXT register                                */
+        "mtc2   $16,   $24          \n"   /* MMU_DATA_EXT <= $16            */
+
         ".set reorder               \n"
         :
-        : "r"(size),"r"(src),"r"(dst)
-        : "$10","$11","$12","$13","$14","$15" );
+        : "r"(size) , "r"(src) , "r"(dst) , "r"(cxy)
+        : "$10","$11","$12","$13","$14","$15","$16" );
         
     hal_restore_irq( save_sr ); 
