Index: trunk/kernel/kern/thread.h
===================================================================
--- trunk/kernel/kern/thread.h	(revision 407)
+++ trunk/kernel/kern/thread.h	(revision 408)
@@ -34,4 +34,5 @@
 #include <spinlock.h>
 #include <core.h>
+#include <chdev.h>
 #include <cluster.h>
 #include <process.h>
@@ -96,5 +97,4 @@
 #define THREAD_BLOCKED_RPC       0x0200  /*! thread wait RPC completion               */
 
-#define THREAD_BLOCKED_DEV_QUEUE 0x2000  /*! thread DEV wait queue                    */
 #define THREAD_BLOCKED_DEV_ISR   0x4000  /*! thread DEV wait ISR                      */
 
@@ -132,5 +132,5 @@
  * thread is registered in the local copy of the process descriptor.
  *
- * WARNING : Don't modify the first 4 fields order, as this order is used by the
+ * WARNING : Don't modify the first 3 fields order, as this order is used by the
  * hal_kentry assembly code for the TSAR architecture.
  **************************************************************************************/
@@ -140,6 +140,7 @@
 typedef struct thread_s
 {
-	void              * cpu_context;     /*! used for context switch                  */
-	void              * fpu_context;     /*! used for dynamic FPU allocation          */
+	void              * cpu_context;     /*! pointer on CPU context switch            */
+	void              * fpu_context;     /*! pointer on FPU context switch            */
+    void              * uzone;           /*! pointer on uzone for hal_kentry          */
 
 	intptr_t            k_stack_base;    /*! kernel stack base address                */
@@ -172,6 +173,6 @@
 
     uint32_t            flags;           /*! bit vector of flags                      */
-    volatile uint32_t   blocked;         /*! bit vector of blocking causes            */
-    volatile uint32_t   signals;         /*! bit vector of (KILL / SUICIDE) signals   */
+    uint32_t            signals;         /*! bit vector of (KILL / SUICIDE) signals   */
+    uint32_t            blocked;         /*! bit vector of blocking causes            */
 
 	error_t             errno;           /*! errno value set by last system call      */
@@ -189,5 +190,7 @@
 	list_entry_t        sched_list;      /*! member of threads attached to same core  */
 
-    uint32_t            dev_channel;     /*! device channel for a DEV thread          */
+    chdev_t           * chdev;           /*! chdev pointer (for a DEV thread only)    */
+
+    reg_t               save_sr;         /*! used by sched_yield() function           */
 
     ioc_command_t       ioc_cmd;         /*! IOC device generic command               */
@@ -222,9 +225,9 @@
 
 /***************************************************************************************
- * This function allocates memory for a user thread descriptor in the local cluster,
- * and initializes it from information contained in the arguments.
- * It is used by the "pthread_create" system call.
- * The CPU context is initialized from scratch, and the "loadable" field is set.
- * The new thread is attached to the core specified in the <attr> argument.
+ * This function is used by the pthread_create() system call to create a "new" thread
+ * in an existing process. It allocates memory for an user thread descriptor in the
+ * local cluster, and initializes it from information contained in the arguments.
+ * The CPU context is initialized from scratch. If required by the <attr> argument,
+ * the new thread is attached to the core specified in <attr>.
  * It is registered in the local process descriptor specified by the <pid> argument.
  * The thread descriptor pointer is returned to allow the parent thread to register it
@@ -246,9 +249,9 @@
 
 /***************************************************************************************
- * This function is used by the fork() system call to create the child process main 
- * thread. It allocates memory for an user thread descriptor in the local cluster,
- * and initializes it from information contained in the calling thread descriptor.
+ * This function is used by the sys_fork() system call to create the "child" thread
+ * in the local cluster. It allocates memory for a thread descriptor, and initializes
+ * it from the "parent" thread descriptor defined by the <parent_thread_xp> argument.
  * The new thread is attached to the core that has the lowest load in local cluster.
- * It is registered in the child process descriptor defined by the <process> argument.
+ * It is registered in the "child" process defined by the <child_process> argument.
  * This new thread inherits its user stack from the parent thread, as it uses the
  * Copy-On-Write mechanism to get a private stack when required.
@@ -256,23 +259,22 @@
  * the Copy-On-Write mechanism cannot be used for kernel segments (because kernel 
  * uses physical addressing on some architectures).
- * The CPU and FPU execution contexts are created and linked to the new thread,
- * but the actual context copy is NOT done. The THREAD_BLOCKED_GLOBAL bit is set,
- * and the thread must be explicitely unblocked later to make the new thread runable.
- ***************************************************************************************
- * @ process      : local pointer on owner process descriptor.
- * @ stack_base   : user stack base address (from parent).
- * @ stack_size   : user stack size (from parent).
- * @ new_thread   : [out] address of buffer for new thread descriptor pointer.
- * @ returns 0 if success / returns ENOMEM if error.
- **************************************************************************************/
-error_t thread_user_fork( process_t * process,
-                          intptr_t    stack_base,
-                          uint32_t    stack_size,
-                          thread_t ** new_thread );
+ * The CPU and FPU execution contexts are created and linked to the new thread.
+ * but the actual context copy is NOT done, and must be done by by the sys_fork(). 
+ * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated to start.
+ ***************************************************************************************
+ * @ parent_thread_xp  : extended pointer on parent thread descriptor.
+ * @ child_process     : local pointer on child process descriptor.
+ * @ child_thread      : [out] address of buffer for child thread descriptor pointer.
+ * @ returns 0 if success / returns -1 if error.
+ **************************************************************************************/
+error_t thread_user_fork( xptr_t      parent_thread_xp,
+                          process_t * child_process,
+                          thread_t ** child_thread );
 
 /***************************************************************************************
  * This function allocates memory for a kernel thread descriptor in the local cluster,
- * and initializes it from arguments values, calling the thread_kernel_init() function,
- * that also allocates and initializes the CPU context.
+ * and initializes it from arguments values. 
+ * It is called by kernel_init() to statically create all DEV server threads
+ * It is also called to dynamically create RPC threads when required.
  * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.
  ***************************************************************************************
@@ -291,6 +293,7 @@
 
 /***************************************************************************************
- * This function initializes an existing kernel thread descriptor from arguments values.
+ * This function initializes an existing thread descriptor from arguments values.
  * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start.
+ * It is called by the kernel_init() function to initialize the IDLE thread.
  ***************************************************************************************
  * @ thread   : pointer on existing thread descriptor.
