Index: trunk/kernel/kern/process.c
===================================================================
--- trunk/kernel/kern/process.c	(revision 527)
+++ trunk/kernel/kern/process.c	(revision 564)
@@ -1,4 +1,4 @@
 /*
- * process.c - process related management
+ * process.c - process related functions definition.
  *
  * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
@@ -43,5 +43,9 @@
 #include <string.h>
 #include <scheduler.h>
-#include <remote_spinlock.h>
+#include <busylock.h>
+#include <queuelock.h>
+#include <remote_queuelock.h>
+#include <rwlock.h>
+#include <remote_rwlock.h>
 #include <dqdt.h>
 #include <cluster.h>
@@ -114,5 +118,5 @@
 
     // get parent_pid
-    parent_pid = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
+    parent_pid = hal_remote_l32( XPTR( parent_cxy , &parent_ptr->pid ) );
 
 #if DEBUG_PROCESS_REFERENCE_INIT
@@ -132,5 +136,6 @@
     // initialize vmm as empty 
     error = vmm_init( process );
-    assert( (error == 0) , "cannot initialize VMM\n" );
+
+assert( (error == 0) , "cannot initialize VMM\n" );
  
 #if (DEBUG_PROCESS_REFERENCE_INIT & 1)
@@ -138,5 +143,5 @@
 if( DEBUG_PROCESS_REFERENCE_INIT )
 printk("\n[DBG] %s : thread %x in process %x / vmm empty for process %x / cycle %d\n", 
-__FUNCTION__, CURRENT_THREAD->trdid, parent_pid , cycle );
+__FUNCTION__, CURRENT_THREAD->trdid, parent_pid , pid, cycle );
 #endif
 
@@ -160,7 +165,4 @@
 __FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, txt_id, cycle );
 #endif
-
-
-
         // build path to TXT_RX[i] and TXT_TX[i] chdevs
         snprintf( rx_path , 40 , "/dev/external/txt%d_rx", txt_id );
@@ -175,6 +177,6 @@
                            &stdin_id );
 
-        assert( (error == 0) , "cannot open stdin pseudo file" );
-        assert( (stdin_id == 0) , "stdin index must be 0" );
+assert( (error == 0) , "cannot open stdin pseudo file" );
+assert( (stdin_id == 0) , "stdin index must be 0" );
 
 #if (DEBUG_PROCESS_REFERENCE_INIT & 1)
@@ -225,5 +227,5 @@
     {
         // get extended pointer on stdin pseudo file in parent process
-        file_xp = (xptr_t)hal_remote_lwd( XPTR( parent_cxy , &parent_ptr->fd_array.array[0] ) );
+        file_xp = (xptr_t)hal_remote_l64( XPTR( parent_cxy , &parent_ptr->fd_array.array[0] ) );
 
         // get extended pointer on parent process TXT chdev
@@ -234,8 +236,8 @@
         chdev_ptr = GET_PTR( chdev_xp );
  
-        // get TXT terminal index
-        txt_id = hal_remote_lw( XPTR( chdev_cxy , &chdev_ptr->channel ) );
-
-        // attach process to TXT[txt_id]
+        // get parent process TXT terminal index
+        txt_id = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) );
+
+        // attach child process to parent process TXT terminal
         process_txt_attach( process , txt_id ); 
 
@@ -246,18 +248,18 @@
 
     // initialize specific inodes root and cwd
-    process->vfs_root_xp = (xptr_t)hal_remote_lwd( XPTR( parent_cxy,
+    process->vfs_root_xp = (xptr_t)hal_remote_l64( XPTR( parent_cxy,
                                                          &parent_ptr->vfs_root_xp ) );
-    process->vfs_cwd_xp  = (xptr_t)hal_remote_lwd( XPTR( parent_cxy,
+    process->vfs_cwd_xp  = (xptr_t)hal_remote_l64( XPTR( parent_cxy,
                                                          &parent_ptr->vfs_cwd_xp ) );
     vfs_inode_remote_up( process->vfs_root_xp );
     vfs_inode_remote_up( process->vfs_cwd_xp );
 
-    remote_rwlock_init( XPTR( local_cxy , &process->cwd_lock ) );
+    remote_rwlock_init( XPTR( local_cxy , &process->cwd_lock ), LOCK_PROCESS_CWD );
 
 #if (DEBUG_PROCESS_REFERENCE_INIT & 1)
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_REFERENCE_INIT )
-printk("\n[DBG] %s : thread %x / fd_array for process %x / cycle %d\n", 
-__FUNCTION__ , CURRENT_THREAD , pid , cycle );
+printk("\n[DBG] %s : thread %x in process %x / set fd_array for process %x / cycle %d\n", 
+__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid , cycle );
 #endif
 
@@ -265,5 +267,5 @@
     xlist_root_init( XPTR( local_cxy , &process->children_root ) );
     process->children_nr     = 0;
-    remote_spinlock_init( XPTR( local_cxy , &process->children_lock ) );
+    remote_queuelock_init( XPTR( local_cxy , &process->children_lock ), LOCK_PROCESS_CHILDREN );
 
     // reset semaphore / mutex / barrier / condvar list roots 
@@ -272,5 +274,5 @@
     xlist_root_init( XPTR( local_cxy , &process->barrier_root ) );
     xlist_root_init( XPTR( local_cxy , &process->condvar_root ) );
-    remote_spinlock_init( XPTR( local_cxy , &process->sync_lock ) );
+    remote_queuelock_init( XPTR( local_cxy , &process->sync_lock ), LOCK_PROCESS_USERSYNC );
 
     // register new process in the local cluster manager pref_tbl[]
@@ -284,12 +286,13 @@
     cluster_process_copies_link( process );
 
-    // reset th_tbl[] array as empty in process descriptor
+    // initialize th_tbl[] array and associated threads
     uint32_t i;
-    for( i = 0 ; i < CONFIG_THREAD_MAX_PER_CLUSTER ; i++ )
+
+    for( i = 0 ; i < CONFIG_THREADS_MAX_PER_CLUSTER ; i++ )
 	{
         process->th_tbl[i] = NULL;
     }
     process->th_nr  = 0;
-    spinlock_init( &process->th_lock );
+    rwlock_init( &process->th_lock , LOCK_PROCESS_THTBL );
 
 	hal_fence();
@@ -298,6 +301,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_REFERENCE_INIT )
-printk("\n[DBG] %s : thread %x exit / process %x / cycle %d\n", 
-__FUNCTION__ , CURRENT_THREAD , pid , cycle );
+printk("\n[DBG] %s : thread %x in process %x exit for process %x / cycle %d\n", 
+__FUNCTION__, CURRENT_THREAD->trdid, parent_pid, pid, cycle );
 #endif
 
@@ -315,16 +318,20 @@
 
     // initialize PID, REF_XP, PARENT_XP, and STATE
-    local_process->pid        = hal_remote_lw(  XPTR( ref_cxy , &ref_ptr->pid ) );
-    local_process->parent_xp  = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->parent_xp ) );
+    local_process->pid        = hal_remote_l32(  XPTR( ref_cxy , &ref_ptr->pid ) );
+    local_process->parent_xp  = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->parent_xp ) );
     local_process->ref_xp     = reference_process_xp;
     local_process->owner_xp   = reference_process_xp;
     local_process->term_state = 0;
 
-#if DEBUG_PROCESS_COPY_INIT 
+#if DEBUG_PROCESS_COPY_INIT
+thread_t * this = CURRET_THREAD;  
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_COPY_INIT )
-printk("\n[DBG] %s : thread %x enter for process %x\n",
-__FUNCTION__ , CURRENT_THREAD , local_process->pid );
-#endif
+printk("\n[DBG] %s : thread %x in process %x enter for process %x / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, local_process->pid, cycle );
+#endif
+
+// check user process
+assert( (local_process->pid != 0), "PID cannot be 0" );
 
     // reset local process vmm
@@ -336,6 +343,6 @@
 
     // reset vfs_root_xp / vfs_bin_xp / vfs_cwd_xp fields
-    local_process->vfs_root_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_root_xp ) );
-    local_process->vfs_bin_xp  = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_bin_xp ) );
+    local_process->vfs_root_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_root_xp ) );
+    local_process->vfs_bin_xp  = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_bin_xp ) );
     local_process->vfs_cwd_xp  = XPTR_NULL;
 
@@ -343,5 +350,6 @@
     xlist_root_init( XPTR( local_cxy , &local_process->children_root ) );
     local_process->children_nr   = 0;
-    remote_spinlock_init( XPTR( local_cxy , &local_process->children_lock ) );
+    remote_queuelock_init( XPTR( local_cxy , &local_process->children_lock ),
+                           LOCK_PROCESS_CHILDREN );
 
     // reset children_list (not used in a process descriptor copy)
@@ -354,12 +362,13 @@
     xlist_root_init( XPTR( local_cxy , &local_process->condvar_root ) );
 
-    // reset th_tbl[] array as empty
+    // initialize th_tbl[] array and associated fields
     uint32_t i;
-    for( i = 0 ; i < CONFIG_THREAD_MAX_PER_CLUSTER ; i++ )
+    for( i = 0 ; i < CONFIG_THREADS_MAX_PER_CLUSTER ; i++ )
 	{
         local_process->th_tbl[i] = NULL;
     }
     local_process->th_nr  = 0;
-    spinlock_init( &local_process->th_lock );
+    rwlock_init( &local_process->th_lock , LOCK_PROCESS_THTBL );
+
 
     // register new process descriptor in local cluster manager local_list
@@ -374,6 +383,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_COPY_INIT )
-printk("\n[DBG] %s : thread %x exit for process %x\n",
-__FUNCTION__ , CURRENT_THREAD , local_process->pid );
+printk("\n[DBG] %s : thread %x in process %x exit for process %x / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, local_process->pid, cycle );
 #endif
 
@@ -399,6 +408,6 @@
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_DESTROY )
-printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD , pid , local_cxy , cycle );
+printk("\n[DBG] %s : thread %x in process %x enter for process %x in cluster %x / cycle %d\n",
+__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, pid, local_cxy, cycle );
 #endif
 
@@ -423,15 +432,14 @@
 
         // remove process from children_list
-        remote_spinlock_lock( children_lock_xp );
+        remote_queuelock_acquire( children_lock_xp );
         xlist_unlink( XPTR( local_cxy , &process->children_list ) );
 	    hal_remote_atomic_add( children_nr_xp , -1 );
-        remote_spinlock_unlock( children_lock_xp );
-
-    // release the process PID to cluster manager
-    cluster_pid_release( pid );
-
-    }
-
-    // FIXME close all open files and update dirty [AG]
+        remote_queuelock_release( children_lock_xp );
+
+        // release the process PID to cluster manager
+        cluster_pid_release( pid );
+    }
+
+    // FIXME close all open files and synchronize dirty [AG]
 
     // decrease refcount for bin file, root file and cwd file
@@ -449,6 +457,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_DESTROY )
-printk("\n[DBG] %s : thread %x exit / destroyed process %x in cluster %x / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD , pid, local_cxy, cycle );
+printk("\n[DBG] %s : thread %x in process %x exit / process %x in cluster %x / cycle %d\n",
+__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, pid, local_cxy, cycle );
 #endif
 
@@ -491,4 +499,8 @@
     remote_nr = 0;
 
+// check calling thread can yield
+assert( (client->busylocks == 0),
+"cannot yield : busylocks = %d\n", client->busylocks );
+
 #if DEBUG_PROCESS_SIGACTION
 uint32_t cycle = (uint32_t)hal_get_cycles();
@@ -517,6 +529,6 @@
 
     // The client thread send parallel RPCs to all remote clusters containing
-    // target process copies, wait all responses, and then handles directly the
-    // threads in local cluster, when required.
+    // target process copies, wait all responses, and then handles directly 
+    // the threads in local cluster, when required.
     // The client thread allocates a - shared - RPC descriptor in the stack,
     // because all parallel, non-blocking, server threads use the same input 
@@ -529,6 +541,6 @@
     thread_block( client_xp , THREAD_BLOCKED_RPC );
 
-    // take the lock protecting the copies
-    remote_spinlock_lock( lock_xp );
+    // take the lock protecting process copies
+    remote_queuelock_acquire( lock_xp );
 
     // initialize shared RPC descriptor
@@ -573,5 +585,5 @@
 
     // release the lock protecting process copies
-    remote_spinlock_unlock( lock_xp );
+    remote_queuelock_release( lock_xp );
 
     // restore IRQs
@@ -620,5 +632,5 @@
     thread_t          * target;         // pointer on target thread 
     thread_t          * this;           // pointer on calling thread 
-    uint32_t            ltid;           // index in process th_tbl
+    uint32_t            ltid;           // index in process th_tbl[]
     cxy_t               owner_cxy;      // target process owner cluster
     uint32_t            count;          // requests counter
@@ -628,16 +640,21 @@
     this = CURRENT_THREAD;
 
+#if DEBUG_PROCESS_SIGACTION
+pid_t pid = process->pid;
+uint32_t cycle = (uint32_t)hal_get_cycles();
+if( DEBUG_PROCESS_SIGACTION < cycle )
+printk("\n[DBG] %s : thread %x in process %x enter for process %x in cluster %x / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle );
+#endif
+
+// check target process is an user process
+assert( ( process->pid != 0 ),
+"target process must be an user process" );
+
     // get target process owner cluster
     owner_cxy = CXY_FROM_PID( process->pid );
 
-#if DEBUG_PROCESS_SIGACTION
-uint32_t cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_PROCESS_SIGACTION < cycle )
-printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
-__FUNCTION__ , this , process->pid , local_cxy , cycle );
-#endif
-
     // get lock protecting process th_tbl[]
-    spinlock_lock( &process->th_lock );
+    rwlock_rd_acquire( &process->th_lock );
 
     // loop on target process local threads 
@@ -680,7 +697,8 @@
 
     // release lock protecting process th_tbl[]
-    spinlock_unlock( &process->th_lock );
-
-    // wait acknowledges 
+    rwlock_rd_release( &process->th_lock );
+
+    // busy waiting acknowledges 
+    // TODO this could be improved...
     while( 1 )
     {
@@ -695,6 +713,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_SIGACTION < cycle )
-printk("\n[DBG] %s : thread %x exit for process %x in cluster %x / cycle %d\n",
-__FUNCTION__ , this , process->pid , local_cxy , cycle );
+printk("\n[DBG] %s : thread %x in process %x exit for process %x in cluster %x / cycle %d\n",
+__FUNCTION__, this, this->process->pid, pid, local_cxy , cycle );
 #endif
 
@@ -719,12 +737,17 @@
 
 #if DEBUG_PROCESS_SIGACTION
+pid_t pid = process->pid;
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_SIGACTION < cycle )
-printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
-__FUNCTION__ , this , process->pid , local_cxy , cycle );
-#endif
+printk("\n[DBG] %s : thread %x n process %x enter for process %x in cluster %x / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle );
+#endif
+
+// check target process is an user process
+assert( ( process->pid != 0 ),
+"target process must be an user process" );
 
     // get lock protecting process th_tbl[]
-    spinlock_lock( &process->th_lock );
+    rwlock_rd_acquire( &process->th_lock );
 
     // loop on target process local threads                       
@@ -739,5 +762,5 @@
             target_xp = XPTR( local_cxy , target );
 
-            // main thread and client thread should not be blocked
+            // main thread and client thread should not be deleted
             if( ((ltid != 0) || (owner_cxy != local_cxy)) &&         // not main thread
                 (client_xp) != target_xp )                           // not client thread
@@ -750,11 +773,11 @@
 
     // release lock protecting process th_tbl[]
-    spinlock_unlock( &process->th_lock );
+    rwlock_rd_release( &process->th_lock );
 
 #if DEBUG_PROCESS_SIGACTION
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_SIGACTION < cycle )
-printk("\n[DBG] %s : thread %x exit for process %x in cluster %x / cycle %d\n",
-__FUNCTION__ , this , process->pid , local_cxy , cycle );
+printk("\n[DBG] %s : thread %x in process %x exit for process %x in cluster %x / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle );
 #endif
 
@@ -773,12 +796,17 @@
 
 #if DEBUG_PROCESS_SIGACTION
+pid_t pid = process->pid;
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_SIGACTION < cycle )
-printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
-__FUNCTION__ , this , process->pid , local_cxy , cycle );
-#endif
+printk("\n[DBG] %s : thread %x in process %x enter for process %x in cluster %x / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, pid, local_cxy , cycle );
+#endif
+
+// check target process is an user process
+assert( ( process->pid != 0 ),
+"target process must be an user process" );
 
     // get lock protecting process th_tbl[]
-    spinlock_lock( &process->th_lock );
+    rwlock_rd_acquire( &process->th_lock );
 
     // loop on process threads to unblock all threads
@@ -798,11 +826,11 @@
 
     // release lock protecting process th_tbl[]
-    spinlock_unlock( &process->th_lock );
+    rwlock_rd_release( &process->th_lock );
 
 #if DEBUG_PROCESS_SIGACTION
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_SIGACTION < cycle )
-printk("\n[DBG] %s : thread %x exit for process %x in cluster %x / cycle %d\n",
-__FUNCTION__ , this , process->pid , local_cxy , cycle );
+printk("\n[DBG] %s : thread %x in process %x exit for process %x in cluster %x / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, pid, local_cxy, cycle );
 #endif
 
@@ -818,6 +846,14 @@
     cluster_t * cluster = LOCAL_CLUSTER;
 
+#if DEBUG_PROCESS_GET_LOCAL_COPY
+thread_t * this = CURRENT_THREAD;
+uint32_t cycle = (uint32_t)hal_get_cycles();
+if( DEBUG_PROCESS_GET_LOCAL_COPY < cycle )
+printk("\n[DBG] %s : thread %x in cluster %x enter for process %x in cluster %x / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, pid, local_cxy, cycle );
+#endif
+
     // get lock protecting local list of processes
-    remote_spinlock_lock( XPTR( local_cxy , &cluster->pmgr.local_lock ) );
+    remote_queuelock_acquire( XPTR( local_cxy , &cluster->pmgr.local_lock ) );
 
     // scan the local list of process descriptors to find the process
@@ -836,5 +872,5 @@
 
     // release lock protecting local list of processes
-    remote_spinlock_unlock( XPTR( local_cxy , &cluster->pmgr.local_lock ) );
+    remote_queuelock_release( XPTR( local_cxy , &cluster->pmgr.local_lock ) );
 
     // allocate memory for a new local process descriptor
@@ -859,8 +895,8 @@
 
 #if DEBUG_PROCESS_GET_LOCAL_COPY
-uint32_t cycle = (uint32_t)hal_get_cycles();
+cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_GET_LOCAL_COPY < cycle )
-printk("\n[DBG] %s : enter in cluster %x / pid %x / process %x / cycle %d\n",
-__FUNCTION__ , local_cxy , pid , process_ptr , cycle );
+printk("\n[DBG] %s : thread %x in cluster %x exit in cluster %x / process %x / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, local_cxy, process_ptr, cycle );
 #endif
 
@@ -883,9 +919,9 @@
 
     // get pointers on parent process
-    parent_xp  = (xptr_t)hal_remote_lwd( XPTR( process_cxy , &process_ptr->parent_xp ) );
+    parent_xp  = (xptr_t)hal_remote_l64( XPTR( process_cxy , &process_ptr->parent_xp ) );
     parent_cxy = GET_CXY( parent_xp );
     parent_ptr = GET_PTR( parent_xp );
 
-    return hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
+    return hal_remote_l32( XPTR( parent_cxy , &parent_ptr->pid ) );
 }
 
@@ -899,5 +935,5 @@
     uint32_t fd;
 
-    remote_spinlock_init( XPTR( local_cxy , &process->fd_array.lock ) );
+    remote_queuelock_init( XPTR( local_cxy , &process->fd_array.lock ), LOCK_PROCESS_FDARRAY );
 
     process->fd_array.current = 0;
@@ -909,21 +945,4 @@
     }
 }
-
-//////////////////////////////
-bool_t process_fd_array_full( void )
-{
-    // get extended pointer on reference process
-    xptr_t ref_xp = CURRENT_THREAD->process->ref_xp;
-
-    // get reference process cluster and local pointer
-    process_t * ref_ptr = GET_PTR( ref_xp );
-    cxy_t       ref_cxy = GET_CXY( ref_xp );
-
-    // get number of open file descriptors from reference fd_array
-    uint32_t current = hal_remote_lw( XPTR( ref_cxy , &ref_ptr->fd_array.current ) );
-
-	return ( current >= CONFIG_PROCESS_FILE_MAX_NR );
-}
-
 /////////////////////////////////////////////////
 error_t process_fd_register( process_t * process,
@@ -933,4 +952,5 @@
     bool_t    found;
     uint32_t  id;
+    uint32_t  count;
     xptr_t    xp;
 
@@ -941,5 +961,5 @@
 
     // take lock protecting reference fd_array
-	remote_spinlock_lock( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) );
+	remote_queuelock_acquire( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) );
 
     found   = false;
@@ -947,11 +967,22 @@
     for ( id = 0; id < CONFIG_PROCESS_FILE_MAX_NR ; id++ )
     {
-        xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) );
+        xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) );
         if ( xp == XPTR_NULL )
         {
+            // update reference fd_array
+            hal_remote_s64( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) , file_xp );
+	        count = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->fd_array.current ) ) + 1;
+            hal_remote_s32( XPTR( ref_cxy , &ref_ptr->fd_array.current ) , count );
+
+            // update local fd_array copy if required
+            if( ref_cxy != local_cxy )
+            {
+                process->fd_array.array[id] = file_xp;
+                process->fd_array.current   = count;
+            }
+
+            // exit
+			*fdid = id;
             found = true;
-            hal_remote_swd( XPTR( ref_cxy , &ref_ptr->fd_array.array[id] ) , file_xp );
-	        hal_remote_atomic_add( XPTR( ref_cxy , &ref_ptr->fd_array.current ) , 1 );
-			*fdid = id;
             break;
         }
@@ -959,5 +990,5 @@
 
     // release lock protecting reference fd_array
-	remote_spinlock_unlock( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) );
+	remote_queuelock_release( XPTR( ref_cxy , &ref_ptr->fd_array.lock ) );
 
     if ( !found ) return -1;
@@ -970,4 +1001,5 @@
 {
     xptr_t  file_xp;
+    xptr_t  lock_xp;
 
     // access local copy of process descriptor
@@ -981,12 +1013,18 @@
         process_t * ref_ptr = GET_PTR( ref_xp );
 
+        // build extended pointer on lock protecting reference fd_array
+        lock_xp = XPTR( ref_cxy , &ref_ptr->fd_array.lock );
+
+        // take lock protecting reference fd_array
+	    remote_queuelock_acquire( lock_xp );
+
         // access reference process descriptor
-        file_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->fd_array.array[fdid] ) );
+        file_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->fd_array.array[fdid] ) );
 
         // update local fd_array if found
-        if( file_xp != XPTR_NULL )
-        {
-            process->fd_array.array[fdid] = file_xp;
-        }
+        if( file_xp != XPTR_NULL )  process->fd_array.array[fdid] = file_xp;
+        
+        // release lock protecting reference fd_array
+	    remote_queuelock_release( lock_xp );
     }
 
@@ -1011,10 +1049,10 @@
 
     // get the remote lock protecting the src fd_array
-	remote_spinlock_lock( XPTR( src_cxy , &src_ptr->lock ) );
+	remote_queuelock_acquire( XPTR( src_cxy , &src_ptr->lock ) );
 
     // loop on all fd_array entries
     for( fd = 0 ; fd < CONFIG_PROCESS_FILE_MAX_NR ; fd++ )
 	{
-		entry = (xptr_t)hal_remote_lwd( XPTR( src_cxy , &src_ptr->array[fd] ) );
+		entry = (xptr_t)hal_remote_l64( XPTR( src_cxy , &src_ptr->array[fd] ) );
 
 		if( entry != XPTR_NULL )
@@ -1024,12 +1062,30 @@
 
 			// copy entry in destination process fd_array
-			hal_remote_swd( XPTR( dst_cxy , &dst_ptr->array[fd] ) , entry );
+			hal_remote_s64( XPTR( dst_cxy , &dst_ptr->array[fd] ) , entry );
 		}
 	}
 
     // release lock on source process fd_array
-	remote_spinlock_unlock( XPTR( src_cxy , &src_ptr->lock ) );
+	remote_queuelock_release( XPTR( src_cxy , &src_ptr->lock ) );
 
 }  // end process_fd_remote_copy()
+
+
+////////////////////////////////////
+bool_t process_fd_array_full( void )
+{
+    // get extended pointer on reference process
+    xptr_t ref_xp = CURRENT_THREAD->process->ref_xp;
+
+    // get reference process cluster and local pointer
+    process_t * ref_ptr = GET_PTR( ref_xp );
+    cxy_t       ref_cxy = GET_CXY( ref_xp );
+
+    // get number of open file descriptors from reference fd_array
+    uint32_t current = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->fd_array.current ) );
+
+	return ( current >= CONFIG_PROCESS_FILE_MAX_NR );
+}
+
 
 ////////////////////////////////////////////////////////////////////////////////////
@@ -1043,22 +1099,16 @@
 {
     ltid_t         ltid;
-    reg_t          save_sr;
     bool_t         found = false;
  
-
-    assert( (process != NULL) , "process argument is NULL" );
-
-    assert( (thread != NULL) , "thread argument is NULL" );
-
-    // take lock protecting th_tbl, depending on thread type:
-    // we don't want to use a descheduling policy for idle thread initialisation
-    if ( thread->type == THREAD_IDLE ) {
-        spinlock_lock_busy( &process->th_lock , &save_sr );
-    } else {
-        spinlock_lock( &process->th_lock );
-    }
-
-    // search a free slot in th_tbl[] 
-    for( ltid = 0 ; ltid < CONFIG_THREAD_MAX_PER_CLUSTER ; ltid++ )
+// check arguments
+assert( (process != NULL) , "process argument is NULL" );
+assert( (thread != NULL) , "thread argument is NULL" );
+
+    // get the lock protecting th_tbl for all threads
+    // but the idle thread executing kernel_init (cannot yield)
+    if( thread->type != THREAD_IDLE ) rwlock_wr_acquire( &process->th_lock );
+
+    // scan kth_tbl
+    for( ltid = 0 ; ltid < CONFIG_THREADS_MAX_PER_CLUSTER ; ltid++ )
     {
         if( process->th_tbl[ltid] == NULL )
@@ -1079,13 +1129,9 @@
     }
 
-    // release lock protecting th_tbl
-    hal_fence();
-    if( thread->type == THREAD_IDLE ) {
-        spinlock_unlock_busy( &process->th_lock , save_sr );
-    } else {
-        spinlock_unlock( &process->th_lock );
-    }
-
-    return (found) ? 0 : ENOMEM;
+    // get the lock protecting th_tbl for all threads
+    // but the idle thread executing kernel_init (cannot yield)
+    if( thread->type != THREAD_IDLE ) rwlock_wr_release( &process->th_lock );
+
+    return (found) ? 0 : 0xFFFFFFFF;
 
 }  // end process_register_thread()
@@ -1096,5 +1142,6 @@
     uint32_t count;  // number of threads in local process descriptor
 
-    assert( (thread != NULL) , "thread argument is NULL" );
+// check argument
+assert( (thread != NULL) , "thread argument is NULL" );
 
     process_t * process = thread->process;
@@ -1102,11 +1149,16 @@
     // get thread local index
     ltid_t  ltid = LTID_FROM_TRDID( thread->trdid );
-
-    // take lock protecting th_tbl
-    spinlock_lock( &process->th_lock );
-
+    
+    // the lock depends on thread user/kernel type, because we cannot
+    // use a descheduling policy for the lock protecting the kth_tbl
+
+    // get the lock protecting th_tbl[]
+    rwlock_wr_acquire( &process->th_lock );
+
+    // get number of kernel threads
     count = process->th_nr;
 
-    assert( (count > 0) , "process th_nr cannot be 0\n" );
+// check th_nr value
+assert( (count > 0) , "process kth_nr cannot be 0\n" );
 
     // remove thread from th_tbl[]
@@ -1114,7 +1166,6 @@
     process->th_nr = count-1;
 
-    // release lock protecting th_tbl
-    hal_fence();
-    spinlock_unlock( &process->th_lock );
+    // release lock protecting kth_tbl
+    rwlock_wr_release( &process->th_lock );
 
     return (count == 1);
@@ -1141,12 +1192,13 @@
 
     // get parent process PID and extended pointer on .elf file
-    parent_pid = hal_remote_lw (XPTR( parent_process_cxy , &parent_process_ptr->pid));
-    vfs_bin_xp = hal_remote_lwd(XPTR( parent_process_cxy , &parent_process_ptr->vfs_bin_xp));
-
-    // check parent process is the reference process
-    ref_xp = hal_remote_lwd( XPTR( parent_process_cxy , &parent_process_ptr->ref_xp ) );
-
-    assert( (parent_process_xp == ref_xp ) ,
-    "parent process must be the reference process\n" );
+    parent_pid = hal_remote_l32 (XPTR( parent_process_cxy , &parent_process_ptr->pid));
+    vfs_bin_xp = hal_remote_l64(XPTR( parent_process_cxy , &parent_process_ptr->vfs_bin_xp));
+
+    // get extended pointer on reference process
+    ref_xp = hal_remote_l64( XPTR( parent_process_cxy , &parent_process_ptr->ref_xp ) );
+
+// check parent process is the reference process
+assert( (parent_process_xp == ref_xp ) ,
+"parent process must be the reference process\n" );
 
 #if DEBUG_PROCESS_MAKE_FORK
@@ -1195,6 +1247,4 @@
 #endif
 
-    // give TXT ownership to child process
-    process_txt_set_ownership( XPTR( local_cxy , process ) );
 
     // copy VMM from parent descriptor to child descriptor
@@ -1218,6 +1268,7 @@
 #endif
 
-    // parent process gives TXT ownership to child process if required
-    if( process_txt_is_owner(parent_process_xp) ) 
+    // if parent_process is INIT, or if parent_process is the TXT owner,
+    // the child_process becomes the owner of its TXT terminal
+    if( (parent_pid == 1) || process_txt_is_owner( parent_process_xp ) )
     {
         process_txt_set_ownership( XPTR( local_cxy , process ) );
@@ -1226,7 +1277,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_MAKE_EXEC < cycle )
-printk("\n[DBG] %s : thread %x in process %x gives TXT from parent %x to child %x / cycle %d\n",
-__FUNCTION__ , CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid,
-parent_pid, new_pid, cycle );
+printk("\n[DBG] %s : thread %x in process %x / child takes TXT ownership / cycle %d\n",
+__FUNCTION__ , CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, cycle );
 #endif
 
@@ -1249,10 +1299,9 @@
     }
 
-    // check main thread LTID
-    assert( (LTID_FROM_TRDID(thread->trdid) == 0) ,
-    "main thread must have LTID == 0\n" );
-
-//#if( DEBUG_PROCESS_MAKE_FORK & 1 )
-#if DEBUG_PROCESS_MAKE_FORK 
+// check main thread LTID
+assert( (LTID_FROM_TRDID(thread->trdid) == 0) ,
+"main thread must have LTID == 0\n" );
+
+#if( DEBUG_PROCESS_MAKE_FORK & 1 )
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_MAKE_FORK < cycle )
@@ -1289,8 +1338,8 @@
 
     // register process in parent children list
-    remote_spinlock_lock( children_lock_xp );
+    remote_queuelock_acquire( children_lock_xp );
 	xlist_add_last( children_root_xp , XPTR( local_cxy , &process->children_list ) );
 	hal_remote_atomic_add( children_nr_xp , 1 );
-    remote_spinlock_unlock( children_lock_xp );
+    remote_queuelock_release( children_lock_xp );
 
     // return success
@@ -1341,5 +1390,5 @@
     // open the file identified by <path>
     file_xp = XPTR_NULL;
-    file_id = -1;
+    file_id = 0xFFFFFFFF;
 	error   = vfs_open( process,
 	                    path,
@@ -1442,5 +1491,6 @@
 uint32_t cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_ZERO_CREATE < cycle )
-printk("\n[DBG] %s : thread %x enter / cycle %d\n", __FUNCTION__, CURRENT_THREAD, cycle );
+printk("\n[DBG] %s : enter / cluster %x / cycle %d\n",
+__FUNCTION__, local_cxy, cycle );
 #endif
 
@@ -1452,17 +1502,19 @@
     process->term_state = 0;
 
-    // reset th_tbl[] array as empty
+    // reset th_tbl[] array and associated fields
     uint32_t i;
-    for( i = 0 ; i < CONFIG_THREAD_MAX_PER_CLUSTER ; i++ )
+    for( i = 0 ; i < CONFIG_THREADS_MAX_PER_CLUSTER ; i++ )
 	{
         process->th_tbl[i] = NULL;
     }
     process->th_nr  = 0;
-    spinlock_init( &process->th_lock );
+    rwlock_init( &process->th_lock , LOCK_PROCESS_THTBL );
+
 
     // reset children list as empty
     xlist_root_init( XPTR( local_cxy , &process->children_root ) );
-    remote_spinlock_init( XPTR( local_cxy , &process->children_lock ) );
     process->children_nr = 0;
+    remote_queuelock_init( XPTR( local_cxy , &process->children_lock ),
+                           LOCK_PROCESS_CHILDREN );
 
 	hal_fence();
@@ -1471,10 +1523,11 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_PROCESS_ZERO_CREATE < cycle )
-printk("\n[DBG] %s : thread %x exit / cycle %d\n", __FUNCTION__, CURRENT_THREAD, cycle );
+printk("\n[DBG] %s : exit / cluster %x / cycle %d\n",
+__FUNCTION__, local_cxy, cycle );
 #endif
 
 }  // end process_zero_init()
 
-//////////////////////////
+////////////////////////////////
 void process_init_create( void )
 {
@@ -1498,15 +1551,18 @@
 	process = process_alloc(); 
 	
-    assert( (process != NULL),
-    "no memory for process descriptor in cluster %x\n", local_cxy  );
+// check memory allocator
+assert( (process != NULL),
+"no memory for process descriptor in cluster %x\n", local_cxy  );
 
     // get PID from local cluster
     error = cluster_pid_alloc( process , &pid );
 
-    assert( (error == 0),
-    "cannot allocate PID in cluster %x\n", local_cxy );
-
-    assert( (pid == 1) ,
-    "process INIT must be first process in cluster 0\n" );
+// check PID allocator 
+assert( (error == 0),
+"cannot allocate PID in cluster %x\n", local_cxy );
+
+// check PID value
+assert( (pid == 1) ,
+"process INIT must be first process in cluster 0\n" );
 
     // initialize process descriptor / parent is local process_zero
@@ -1514,4 +1570,10 @@
                             pid,
                             XPTR( local_cxy , &process_zero ) );  
+
+#if(DEBUG_PROCESS_INIT_CREATE & 1)
+if( DEBUG_PROCESS_INIT_CREATE < cycle )
+printk("\n[DBG] %s : thread %x in process %x initialized process descriptor\n",
+__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
+#endif
 
     // open the file identified by CONFIG_PROCESS_INIT_PATH
@@ -1525,13 +1587,25 @@
 	                    &file_id );
 
-	assert( (error == 0),
-    "failed to open file <%s>\n", CONFIG_PROCESS_INIT_PATH );
-
-    // register "code" and "data" vsegs as well as entry-point
+assert( (error == 0),
+"failed to open file <%s>\n", CONFIG_PROCESS_INIT_PATH );
+
+#if(DEBUG_PROCESS_INIT_CREATE & 1)
+if( DEBUG_PROCESS_INIT_CREATE < cycle )
+printk("\n[DBG] %s : thread %x in process %x open .elf file decriptor\n",
+__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
+#endif
+
+   // register "code" and "data" vsegs as well as entry-point
     // in process VMM, using information contained in the elf file.
 	error = elf_load_process( file_xp , process );
 
-	assert( (error == 0),
-    "cannot access .elf file <%s>\n", CONFIG_PROCESS_INIT_PATH );
+assert( (error == 0),
+"cannot access .elf file <%s>\n", CONFIG_PROCESS_INIT_PATH );
+
+#if(DEBUG_PROCESS_INIT_CREATE & 1)
+if( DEBUG_PROCESS_INIT_CREATE < cycle )
+printk("\n[DBG] %s : thread %x in process %x registered code/data vsegs in VMM\n",
+__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
+#endif
 
     // get extended pointers on process_zero children_root, children_lock
@@ -1539,9 +1613,19 @@
     xptr_t children_lock_xp = XPTR( local_cxy , &process_zero.children_lock );
 
+    // take lock protecting kernel process children list
+    remote_queuelock_acquire( children_lock_xp );
+
     // register process INIT in parent local process_zero 
-    remote_spinlock_lock( children_lock_xp );
 	xlist_add_last( children_root_xp , XPTR( local_cxy , &process->children_list ) );
 	hal_atomic_add( &process_zero.children_nr , 1 );
-    remote_spinlock_unlock( children_lock_xp );
+
+    // release lock protecting kernel process children list
+    remote_queuelock_release( children_lock_xp );
+
+#if(DEBUG_PROCESS_INIT_CREATE & 1)
+if( DEBUG_PROCESS_INIT_CREATE < cycle )
+printk("\n[DBG] %s : thread %x in process %x registered init process in parent\n",
+__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
+#endif
 
     // select a core in local cluster to execute the main thread
@@ -1560,9 +1644,15 @@
                                 &thread );
 
-	assert( (error == 0),
-    "cannot create main thread for <%s>\n", CONFIG_PROCESS_INIT_PATH );
-
-    assert( (thread->trdid == 0),
-    "main thread must have index 0 for <%s>\n", CONFIG_PROCESS_INIT_PATH );
+assert( (error == 0),
+"cannot create main thread for <%s>\n", CONFIG_PROCESS_INIT_PATH );
+
+assert( (thread->trdid == 0),
+"main thread must have index 0 for <%s>\n", CONFIG_PROCESS_INIT_PATH );
+
+#if(DEBUG_PROCESS_INIT_CREATE & 1)
+if( DEBUG_PROCESS_INIT_CREATE < cycle )
+printk("\n[DBG] %s : thread %x in process %x created main thread\n",
+__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid );
+#endif
 
     // activate thread
@@ -1618,23 +1708,23 @@
 
     // get PID and state
-    pid   = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
-    state = hal_remote_lw( XPTR( process_cxy , &process_ptr->term_state ) );
+    pid   = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
+    state = hal_remote_l32( XPTR( process_cxy , &process_ptr->term_state ) );
 
     // get PPID
-    parent_xp  = hal_remote_lwd( XPTR( process_cxy , &process_ptr->parent_xp ) );
+    parent_xp  = hal_remote_l64( XPTR( process_cxy , &process_ptr->parent_xp ) );
     parent_cxy = GET_CXY( parent_xp );
     parent_ptr = GET_PTR( parent_xp );
-    ppid       = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
+    ppid       = hal_remote_l32( XPTR( parent_cxy , &parent_ptr->pid ) );
 
     // get number of threads
-    th_nr      = hal_remote_lw( XPTR( process_cxy , &process_ptr->th_nr ) );
+    th_nr      = hal_remote_l32( XPTR( process_cxy , &process_ptr->th_nr ) );
 
     // get pointers on owner process descriptor
-    owner_xp  = hal_remote_lwd( XPTR( process_cxy , &process_ptr->owner_xp ) );
+    owner_xp  = hal_remote_l64( XPTR( process_cxy , &process_ptr->owner_xp ) );
     owner_cxy = GET_CXY( owner_xp );
     owner_ptr = GET_PTR( owner_xp );
 
     // get extended pointer on TXT_RX file descriptor attached to process
-    txt_file_xp = hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->fd_array.array[0] ) );
+    txt_file_xp = hal_remote_l64( XPTR( owner_cxy , &owner_ptr->fd_array.array[0] ) );
 
     assert( (txt_file_xp != XPTR_NULL) ,
@@ -1650,9 +1740,9 @@
                        XPTR( txt_chdev_cxy , txt_chdev_ptr->name ) );
     
-    txt_owner_xp = (xptr_t)hal_remote_lwd( XPTR( txt_chdev_cxy, 
+    txt_owner_xp = (xptr_t)hal_remote_l64( XPTR( txt_chdev_cxy, 
                                                  &txt_chdev_ptr->ext.txt.owner_xp ) );
     
     // get process .elf name
-    elf_file_xp   = hal_remote_lwd( XPTR( process_cxy , &process_ptr->vfs_bin_xp ) );
+    elf_file_xp   = hal_remote_l64( XPTR( process_cxy , &process_ptr->vfs_bin_xp ) );
     elf_file_cxy  = GET_CXY( elf_file_xp );
     elf_file_ptr  = (vfs_file_t *)GET_PTR( elf_file_xp );
@@ -1718,11 +1808,11 @@
     xptr_t      lock_xp;      // extended pointer on list lock in chdev
 
-    // check process is in owner cluster
-    assert( (CXY_FROM_PID( process->pid ) == local_cxy) ,
-    "process descriptor not in owner cluster" );
-
-    // check terminal index
-    assert( (txt_id < LOCAL_CLUSTER->nb_txt_channels) ,
-    "illegal TXT terminal index" );
+// check process is in owner cluster
+assert( (CXY_FROM_PID( process->pid ) == local_cxy) ,
+"process descriptor not in owner cluster" );
+
+// check terminal index
+assert( (txt_id < LOCAL_CLUSTER->nb_txt_channels) ,
+"illegal TXT terminal index" );
 
     // get pointers on TXT_RX[txt_id] chdev
@@ -1735,8 +1825,12 @@
     lock_xp = XPTR( chdev_cxy , &chdev_ptr->ext.txt.lock );
 
+    // get lock protecting list of processes attached to TXT
+    remote_busylock_acquire( lock_xp );
+
     // insert process in attached process list
-    remote_spinlock_lock( lock_xp );
     xlist_add_last( root_xp , XPTR( local_cxy , &process->txt_list ) );
-    remote_spinlock_unlock( lock_xp );
+
+    // release lock protecting list of processes attached to TXT
+    remote_busylock_release( lock_xp );
 
 #if DEBUG_PROCESS_TXT
@@ -1765,9 +1859,9 @@
     process_cxy = GET_CXY( process_xp );
     process_ptr = GET_PTR( process_xp );
-
-    // check process descriptor in owner cluster
-    process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
-    assert( (CXY_FROM_PID( process_pid ) == process_cxy ) ,
-    "process descriptor not in owner cluster" );
+    process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
+
+// check process descriptor in owner cluster
+assert( (CXY_FROM_PID( process_pid ) == process_cxy ) ,
+"process descriptor not in owner cluster" );
 
     // release TXT ownership (does nothing if not TXT owner)
@@ -1775,5 +1869,5 @@
 
     // get extended pointer on process stdin file
-    file_xp = (xptr_t)hal_remote_lwd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
+    file_xp = (xptr_t)hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
 
     // get pointers on TXT_RX chdev
@@ -1785,12 +1879,16 @@
     lock_xp = XPTR( chdev_cxy , &chdev_ptr->ext.txt.lock );
 
+    // get lock protecting list of processes attached to TXT
+    remote_busylock_acquire( lock_xp );
+
     // unlink process from attached process list
-    remote_spinlock_lock( lock_xp );
     xlist_unlink( XPTR( process_cxy , &process_ptr->txt_list ) );
-    remote_spinlock_unlock( lock_xp );
+
+    // release lock protecting list of processes attached to TXT
+    remote_busylock_release( lock_xp );
 
 #if DEBUG_PROCESS_TXT
 uint32_t cycle  = (uint32_t)hal_get_cycles();
-uint32_t txt_id = hal_remote_lw( XPTR( chdev_cxy , &chdev_ptr->channel ) );
+uint32_t txt_id = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) );
 if( DEBUG_PROCESS_TXT < cycle )
 printk("\n[DBG] %s : thread %x in process %x detached process %x from TXT %d / cycle %d\n",
@@ -1815,5 +1913,5 @@
     process_cxy = GET_CXY( process_xp );
     process_ptr = GET_PTR( process_xp );
-    process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
+    process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
 
     // check owner cluster
@@ -1822,5 +1920,5 @@
 
     // get extended pointer on stdin pseudo file
-    file_xp = hal_remote_lwd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
+    file_xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
 
     // get pointers on TXT chdev
@@ -1830,9 +1928,9 @@
 
     // set owner field in TXT chdev
-    hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , process_xp );
+    hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , process_xp );
 
 #if DEBUG_PROCESS_TXT
 uint32_t cycle  = (uint32_t)hal_get_cycles();
-uint32_t txt_id = hal_remote_lw( XPTR( txt_cxy , &txt_ptr->channel ) );
+uint32_t txt_id = hal_remote_l32( XPTR( txt_cxy , &txt_ptr->channel ) );
 if( DEBUG_PROCESS_TXT < cycle )
 printk("\n[DBG] %s : thread %x in process %x give TXT %d to process %x / cycle %d\n",
@@ -1868,5 +1966,5 @@
     process_cxy = GET_CXY( process_xp );
     process_ptr = GET_PTR( process_xp );
-    process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
+    process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
 
     // check owner cluster
@@ -1875,5 +1973,5 @@
 
     // get extended pointer on stdin pseudo file
-    file_xp = hal_remote_lwd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
+    file_xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
 
     // get pointers on TXT chdev
@@ -1883,6 +1981,6 @@
 
     // get extended pointer on TXT_RX owner and TXT channel
-    owner_xp = hal_remote_lwd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) );
-    txt_id   = hal_remote_lw ( XPTR( txt_cxy , &txt_ptr->channel ) );
+    owner_xp = hal_remote_l64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) );
+    txt_id   = hal_remote_l32 ( XPTR( txt_cxy , &txt_ptr->channel ) );
 
     // transfer ownership only if process is the TXT owner
@@ -1894,5 +1992,5 @@
 
         // get lock
-        remote_spinlock_lock( lock_xp );
+        remote_busylock_acquire( lock_xp );
 
         if( process_get_ppid( process_xp ) != 1 )           // process is not KSH
@@ -1908,12 +2006,12 @@
                 {
                     // release lock
-                    remote_spinlock_unlock( lock_xp );
+                    remote_busylock_release( lock_xp );
 
                     // set owner field in TXT chdev 
-                    hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
+                    hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
 
 #if DEBUG_PROCESS_TXT
 cycle   = (uint32_t)hal_get_cycles();
-uint32_t ksh_pid = hal_remote_lw( XPTR( current_cxy , &current_ptr->pid ) );
+uint32_t ksh_pid = hal_remote_l32( XPTR( current_cxy , &current_ptr->pid ) );
 if( DEBUG_PROCESS_TXT < cycle )
 printk("\n[DBG] %s : thread %x in process %x release TXT %d to KSH %x / cycle %d\n",
@@ -1926,5 +2024,5 @@
  
             // release lock
-            remote_spinlock_unlock( lock_xp );
+            remote_busylock_release( lock_xp );
 
             // PANIC if KSH not found
@@ -1945,12 +2043,12 @@
                 {
                     // release lock
-                    remote_spinlock_unlock( lock_xp );
+                    remote_busylock_release( lock_xp );
 
                     // set owner field in TXT chdev 
-                    hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
+                    hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
 
 #if DEBUG_PROCESS_TXT
 cycle   = (uint32_t)hal_get_cycles();
-uint32_t new_pid = hal_remote_lw( XPTR( current_cxy , &current_ptr->pid ) );
+uint32_t new_pid = hal_remote_l32( XPTR( current_cxy , &current_ptr->pid ) );
 if( DEBUG_PROCESS_TXT < cycle )
 printk("\n[DBG] %s : thread %x in process %x release TXT %d to process %x / cycle %d\n",
@@ -1963,8 +2061,8 @@
 
             // release lock
-            remote_spinlock_unlock( lock_xp );
+            remote_busylock_release( lock_xp );
 
             // no more owner for TXT if no other process found
-            hal_remote_swd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , XPTR_NULL );
+            hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , XPTR_NULL );
 
 #if DEBUG_PROCESS_TXT
@@ -1993,6 +2091,6 @@
 
 
-//////////////////////////////////////////////////
-uint32_t process_txt_is_owner( xptr_t process_xp )
+////////////////////////////////////////////////
+bool_t process_txt_is_owner( xptr_t process_xp )
 {
     // get local pointer and cluster of process in owner cluster
@@ -2000,11 +2098,11 @@
     process_t * process_ptr = GET_PTR( process_xp );
 
-    // check owner cluster
-    pid_t process_pid = hal_remote_lw( XPTR( process_cxy , &process_ptr->pid ) );
-    assert( (process_cxy == CXY_FROM_PID( process_pid )) ,
-    "process descriptor not in owner cluster\n" );
+// check calling thread execute in target process owner cluster
+pid_t process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
+assert( (process_cxy == CXY_FROM_PID( process_pid )) ,
+"process descriptor not in owner cluster\n" );
 
     // get extended pointer on stdin pseudo file
-    xptr_t file_xp = hal_remote_lwd( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
+    xptr_t file_xp = hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
 
     // get pointers on TXT chdev
@@ -2014,5 +2112,5 @@
 
     // get extended pointer on TXT_RX owner process 
-    xptr_t owner_xp = hal_remote_lwd( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) );
+    xptr_t owner_xp = hal_remote_l64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) );
 
     return (process_xp == owner_xp);
@@ -2027,5 +2125,5 @@
     chdev_t *   txt_rx_ptr = GET_PTR( txt_rx_xp );
 
-    return (xptr_t)hal_remote_lwd( XPTR( txt_rx_cxy , &txt_rx_ptr->ext.txt.owner_xp ) );
+    return (xptr_t)hal_remote_l64( XPTR( txt_rx_cxy , &txt_rx_ptr->ext.txt.owner_xp ) );
 
 }  // end process_txt_get_owner()
@@ -2045,5 +2143,4 @@
     xptr_t      txt0_xp;
     xptr_t      txt0_lock_xp;
-    reg_t       txt0_save_sr;    // save SR to take TXT0 lock in busy mode
     
     assert( (txt_id < LOCAL_CLUSTER->nb_txt_channels) ,
@@ -2068,8 +2165,8 @@
 
     // get lock on attached process list
-    remote_spinlock_lock( lock_xp );
+    remote_busylock_acquire( lock_xp );
 
     // get TXT0 lock in busy waiting mode
-    remote_spinlock_lock_busy( txt0_lock_xp , &txt0_save_sr );
+    remote_busylock_acquire( txt0_lock_xp );
 
     // display header
@@ -2085,8 +2182,8 @@
 
     // release TXT0 lock in busy waiting mode
-    remote_spinlock_unlock_busy( txt0_lock_xp , txt0_save_sr );
+    remote_busylock_release( txt0_lock_xp );
 
     // release lock on attached process list
-    remote_spinlock_unlock( lock_xp );
+    remote_busylock_release( lock_xp );
 
 }  // end process_txt_display
