Index: soft/giet_vm/giet_libs/stdio.c
===================================================================
--- soft/giet_vm/giet_libs/stdio.c	(revision 689)
+++ soft/giet_vm/giet_libs/stdio.c	(revision 709)
@@ -11,5 +11,5 @@
 
 //////////////////////////////////////////////////////////////////////////////
-/////////////////////  MIPS32     related system calls ///////////////////////
+//                     MIPS32 related system calls 
 //////////////////////////////////////////////////////////////////////////////
 
@@ -49,59 +49,102 @@
 
 //////////////////////////////////////////////////////////////////////////////
-///////////////////// Task related  system calls /////////////////////////////
+//                    Threads related  system calls
 //////////////////////////////////////////////////////////////////////////////
 
-////////////////////////////////
-unsigned int giet_proc_task_id() 
-{
-    return (unsigned int)sys_call( SYSCALL_LOCAL_TASK_ID, 
-                                   0, 0, 0, 0 );
-}
-
-//////////////////////////////////
-unsigned int giet_global_task_id() 
-{
-    return (unsigned int)sys_call( SYSCALL_GLOBAL_TASK_ID, 
-                                   0, 0, 0, 0 );
-}
-
-/////////////////////////////
-unsigned int giet_thread_id() 
-{
-    return (unsigned int)sys_call( SYSCALL_THREAD_ID, 
-                                   0, 0, 0, 0 );
-}
-
-//////////////////////////////
-void giet_exit( char* string ) 
-{
-    sys_call( SYSCALL_EXIT,
+#define THREAD_CMD_PAUSE     0
+#define THREAD_CMD_RESUME    1
+#define THREAD_CMD_CONTEXT   2
+
+//////////////////////////////////////////////////////////
+int giet_pthread_create( pthread_t*       buffer,
+                         pthread_attr_t*  attr,
+                         void*            function,
+                         void*            arg )
+{
+    return sys_call( SYSCALL_PTHREAD_CREATE,
+                     (unsigned int)buffer,
+                     (unsigned int)attr,
+                     (unsigned int)function,
+                     (unsigned int)arg );
+}              
+
+//////////////////////////////////////
+void giet_pthread_exit( void* string ) 
+{
+    sys_call( SYSCALL_PTHREAD_EXIT,
               (unsigned int)string,
               0, 0, 0 );
 }
 
-/////////////////////////////////////////
-void giet_assert( unsigned int condition,
-                  char*        string )
-{
-    if ( condition == 0 ) giet_exit( string );
-}
-
-//////////////////////////
-void giet_context_switch() 
-{
-    sys_call( SYSCALL_CTX_SWITCH,
+////////////////////////////////////////
+int giet_pthread_join( pthread_t  trdid,
+                       void**     ptr )
+{
+    return sys_call( SYSCALL_PTHREAD_JOIN,
+                     trdid,
+                     (unsigned int)ptr,
+                     0, 0 );
+}
+
+///////////////////////////////////////
+int giet_pthread_kill( pthread_t trdid,
+                       int       signal )
+{
+    return sys_call( SYSCALL_PTHREAD_KILL,
+                     trdid,
+                     signal,
+                     0, 0 );
+}
+
+/////////////////////////
+void giet_pthread_yield() 
+{
+    sys_call( SYSCALL_PTHREAD_YIELD,
               0, 0, 0, 0 );
 }
 
-////////////////////////
-void giet_tasks_status()
-{
-    sys_call( SYSCALL_TASKS_STATUS,
-              0, 0, 0, 0 );
-}
+/////////////////////////////////////////////////
+void giet_pthread_assert( unsigned int condition,
+                          char*        string )
+{
+    if ( condition == 0 ) giet_pthread_exit( string );
+}
+
+//////////////////////////////////////////////
+int giet_pthread_pause( char*     vspace_name,
+                        char*     thread_name )
+{
+    return sys_call( SYSCALL_PTHREAD_CONTROL,
+                     THREAD_CMD_PAUSE,
+                     (unsigned int) vspace_name,
+                     (unsigned int) thread_name,
+                     0 );
+}
+
+///////////////////////////////////////////////
+int giet_pthread_resume( char*     vspace_name,
+                         char*     thread_name )
+{
+    return sys_call( SYSCALL_PTHREAD_CONTROL,
+                     THREAD_CMD_RESUME,
+                     (unsigned int) vspace_name,
+                     (unsigned int) thread_name,
+                     0 );
+}
+
+///////////////////////////////////////////////
+int giet_pthread_context( char*     vspace_name,
+                          char*     thread_name )
+{
+    return sys_call( SYSCALL_PTHREAD_CONTROL,
+                     THREAD_CMD_CONTEXT,
+                     (unsigned int) vspace_name,
+                     (unsigned int) thread_name,
+                     0 );
+}
+
 
 //////////////////////////////////////////////////////////////////////////////
-///////////////////// Applications  system calls /////////////////////////////
+//                    Applications related system calls 
 //////////////////////////////////////////////////////////////////////////////
 
@@ -122,6 +165,13 @@
 }
 
+///////////////////////////////
+void giet_applications_status()
+{
+    sys_call( SYSCALL_APPS_STATUS,
+              0, 0, 0, 0 );
+}
+
 //////////////////////////////////////////////////////////////////////////////
-///////////////////// Coprocessors  system calls  ////////////////////////////
+//                    Coprocessors related system calls
 //////////////////////////////////////////////////////////////////////////////
 
@@ -134,5 +184,5 @@
                    (unsigned int)coproc_info,
                    0, 0 ) )  
-        giet_exit("error in giet_coproc_alloc()");
+        giet_pthread_exit("error in giet_coproc_alloc()");
 }
 
@@ -143,5 +193,5 @@
                    coproc_reg_index,
                    0, 0, 0 ) )  
-        giet_exit("error in giet_coproc_release()");
+        giet_pthread_exit("error in giet_coproc_release()");
 }
 
@@ -154,5 +204,5 @@
                    (unsigned int)desc,
                    0, 0 ) ) 
-        giet_exit("error in giet_coproc_channel_init()");
+        giet_pthread_exit("error in giet_coproc_channel_init()");
 }
 
@@ -163,5 +213,5 @@
                    coproc_reg_index,
                    0, 0, 0 ) ) 
-        giet_exit("error in giet_coproc_run()");
+        giet_pthread_exit("error in giet_coproc_run()");
 }
 
@@ -171,10 +221,10 @@
     if ( sys_call( SYSCALL_COPROC_COMPLETED,
                    0, 0, 0, 0 ) ) 
-        giet_exit("error in giet_coproc_completed");
+        giet_pthread_exit("error in giet_coproc_completed");
 }
 
 
 //////////////////////////////////////////////////////////////////////////////
-/////////////////////  TTY device related system calls ///////////////////////
+//                    TTY device related system calls 
 //////////////////////////////////////////////////////////////////////////////
 
@@ -184,5 +234,5 @@
     if ( sys_call( SYSCALL_TTY_ALLOC,
                    shared,
-                   0, 0, 0 ) )  giet_exit("error in giet_tty_alloc()");
+                   0, 0, 0 ) )  giet_pthread_exit("error in giet_tty_alloc()");
 }
 
@@ -516,5 +566,5 @@
     if (ret)
     {
-        giet_exit("ERROR in giet_tty_printf()");
+        giet_pthread_exit("error in giet_tty_printf()");
     }
 } // end giet_tty_printf()
@@ -532,5 +582,5 @@
                       0xFFFFFFFF,          // channel index from task context
                       0);
-        if ( ret < 0 ) giet_exit("error in giet_tty_getc()");
+        if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getc()");
     }
     while (ret != 1); 
@@ -556,5 +606,5 @@
                            0xFFFFFFFF,        // channel index from task context
                            0);
-            if ( ret < 0 ) giet_exit("error in giet_tty_gets()");
+            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()");
         } 
         while (ret != 1);
@@ -578,5 +628,5 @@
                                 0XFFFFFFFF,        // channel index from task context
                                 0 );
-                if ( ret < 0 ) giet_exit("error in giet_tty_gets()");
+                if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()");
             }
         }
@@ -595,5 +645,5 @@
                             0XFFFFFFFF,        // channel index from task context
                             0 );
-            if ( ret < 0 ) giet_exit("error in giet_tty_gets()");
+            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_gets()");
      
         }
@@ -628,5 +678,5 @@
                             0xFFFFFFFF,    // channel index from task context
                             0); 
-            if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
+            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
         } 
         while (ret != 1);
@@ -644,5 +694,5 @@
                             0xFFFFFFFF,    // channel index from task context
                             0 );
-            if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
+            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
         }
         else if (string_byte == 0x0A)                     // LF character 
@@ -662,5 +712,5 @@
                                 0xFFFFFFFF,    // channel index from task context
                                 0 );
-                if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
+                if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
             }
         }
@@ -701,5 +751,5 @@
                             0xFFFFFFFF,    // channel index from task context
                             0 );
-            if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
+            if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
         }
         // echo character '0'
@@ -710,5 +760,5 @@
                         0xFFFFFFFF,    // channel index from task context
                         0 );
-        if ( ret < 0 ) giet_exit("error in giet_tty_getw()");
+        if ( ret < 0 ) giet_pthread_exit("error in giet_tty_getw()");
 
         // return 0 value 
@@ -719,5 +769,5 @@
 
 //////////////////////////////////////////////////////////////////////////////////
-/////////////////////  TIMER related system calls //////////////////////////////// 
+//                     TIMER related system calls  
 //////////////////////////////////////////////////////////////////////////////////
 
@@ -726,5 +776,5 @@
 {
     if ( sys_call( SYSCALL_TIM_ALLOC,
-                   0, 0, 0, 0 ) ) giet_exit("error in giet_timer_alloc()");
+                   0, 0, 0, 0 ) ) giet_pthread_exit("error in giet_timer_alloc()");
 }
 
@@ -734,5 +784,5 @@
     if ( sys_call( SYSCALL_TIM_START,
                    period,
-                   0, 0, 0 ) ) giet_exit("error in giet_timer_start()");
+                   0, 0, 0 ) ) giet_pthread_exit("error in giet_timer_start()");
 }
 
@@ -741,10 +791,10 @@
 {
     if ( sys_call( SYSCALL_TIM_STOP,
-                   0, 0, 0, 0 ) ) giet_exit("error in giet_timer_stop()");
+                   0, 0, 0, 0 ) ) giet_pthread_exit("error in giet_timer_stop()");
 }
 
 
 //////////////////////////////////////////////////////////////////////////////////
-///////////////  Frame buffer device related system calls  ///////////////////////
+//                   Frame buffer related system calls  
 //////////////////////////////////////////////////////////////////////////////////
 
@@ -753,5 +803,5 @@
 {
     if ( sys_call( SYSCALL_FBF_CMA_ALLOC, 
-                   0, 0, 0, 0 ) )    giet_exit("error in giet_fbf_cma_alloc()");
+                   0, 0, 0, 0 ) )    giet_pthread_exit("error in giet_fbf_cma_alloc()");
 }
 
@@ -766,5 +816,5 @@
                    (unsigned int)buf1_vbase,
                    (unsigned int)sts0_vaddr, 
-                   (unsigned int)sts1_vaddr ) )   giet_exit("error in giet_fbf_cma_init_buf()");
+                   (unsigned int)sts1_vaddr ) )   giet_pthread_exit("error in giet_fbf_cma_init_buf()");
 }
 
@@ -774,5 +824,5 @@
     if ( sys_call( SYSCALL_FBF_CMA_START,
                    length, 
-                   0, 0, 0 ) )   giet_exit("error in giet_fbf_cma_start()");
+                   0, 0, 0 ) )   giet_pthread_exit("error in giet_fbf_cma_start()");
 }
 
@@ -782,5 +832,5 @@
     if ( sys_call( SYSCALL_FBF_CMA_DISPLAY,
                    buffer, 
-                   0, 0, 0 ) )   giet_exit("error in giet_fbf_cma_display()");
+                   0, 0, 0 ) )   giet_pthread_exit("error in giet_fbf_cma_display()");
 }
 
@@ -789,5 +839,5 @@
 {
     if ( sys_call( SYSCALL_FBF_CMA_STOP, 
-                   0, 0, 0, 0 ) )    giet_exit("error in giet_fbf_cma_stop()");
+                   0, 0, 0, 0 ) )    giet_pthread_exit("error in giet_fbf_cma_stop()");
 }
 
@@ -801,5 +851,5 @@
                    (unsigned int)buffer, 
                    length, 
-                   0 ) )  giet_exit("error in giet_fbf_sync_write()");
+                   0 ) )  giet_pthread_exit("error in giet_fbf_sync_write()");
 }
 
@@ -813,130 +863,114 @@
                    (unsigned int)buffer, 
                    length, 
-                   0 ) )   giet_exit("error in giet_fbf_sync_read()");
+                   0 ) )   giet_pthread_exit("error in giet_fbf_sync_read()");
 }
 
 
 //////////////////////////////////////////////////////////////////////////////////
-/////////////////////// NIC related system calls /////////////////////////////////
+//                      NIC related system calls  
 //////////////////////////////////////////////////////////////////////////////////
 
-////////////////////////////////////////////////////
-unsigned int giet_nic_rx_alloc( unsigned int xmax,
-                                unsigned int ymax )
-{
-    int channel = sys_call( SYSCALL_NIC_ALLOC,
-                            1, 
-                            xmax,
-                            ymax,
-                            0 );
-    if ( channel < 0 ) giet_exit("error in giet_nic_rx_alloc()");
-
-    return (unsigned int)channel;
-}
-
-////////////////////////////////////////////////////
-unsigned int giet_nic_tx_alloc( unsigned int xmax,
-                                unsigned int ymax )
-{
-    int channel = sys_call( SYSCALL_NIC_ALLOC,
-                            0,
-                            xmax,
-                            ymax,
-                            0 );
-    if ( channel < 0 ) giet_exit("error in giet_nic_tx_alloc()");
-
-    return (unsigned int)channel;
-}
-
-//////////////////////////////////////////////
-void giet_nic_rx_start( unsigned int channel )
+//////////////////////////////////////////
+void giet_nic_rx_alloc( unsigned int xmax,
+                        unsigned int ymax )
+{
+    if ( sys_call( SYSCALL_NIC_ALLOC,
+                   1,                    // RX
+                   xmax,
+                   ymax,
+                   0 ) ) giet_pthread_exit("error in giet_nic_rx_alloc()");
+}
+
+//////////////////////////////////////////
+void giet_nic_tx_alloc( unsigned int xmax,
+                        unsigned int ymax )
+{
+    if ( sys_call( SYSCALL_NIC_ALLOC,
+                   0,                    // TX
+                   xmax,
+                   ymax,
+                   0 ) ) giet_pthread_exit("error in giet_nic_tx_alloc()");
+}
+
+////////////////////////
+void giet_nic_rx_start()
 {
     if ( sys_call( SYSCALL_NIC_START,
-                   1,
-                   channel,
-                   0, 0 ) ) giet_exit("error in giet_nic_rx_start()");
-}
-
-//////////////////////////////////////////////
-void giet_nic_tx_start( unsigned int channel )
+                   1,                    // RX
+                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_start()");
+}
+
+////////////////////////
+void giet_nic_tx_start()
 {
     if ( sys_call( SYSCALL_NIC_START,
-                   0, 
-                   channel,
-                   0, 0 ) ) giet_exit("error in giet_nic_tx_start()");
-}
-
-///////////////////////////////////////////////////////////
-void giet_nic_rx_move( unsigned int channel, void* buffer )
+                   0,                    // TX
+                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_start()");
+}
+
+/////////////////////////////////////
+void giet_nic_rx_move( void* buffer )
 {
     if ( sys_call( SYSCALL_NIC_MOVE,
-                   1,
-                   channel, 
+                   1,                    // RX
                    (unsigned int)buffer,
-                   0 ) )  giet_exit("error in giet_nic_rx_move()");
-}
-
-///////////////////////////////////////////////////////////
-void giet_nic_tx_move( unsigned int channel, void* buffer )
+                   0, 0 ) )  giet_pthread_exit("error in giet_nic_rx_move()");
+}
+
+/////////////////////////////////////
+void giet_nic_tx_move( void* buffer )
 {
     if ( sys_call( SYSCALL_NIC_MOVE,
-                   0,
-                   channel, 
+                   0,                    // TX
                    (unsigned int)buffer,
-                   0 ) )  giet_exit("error in giet_nic_tx_move()");
-}
-
-/////////////////////////////////////////////
-void giet_nic_rx_stop( unsigned int channel )
+                   0, 0 ) )  giet_pthread_exit("error in giet_nic_tx_move()");
+}
+
+///////////////////////
+void giet_nic_rx_stop()
 {
     if ( sys_call( SYSCALL_NIC_STOP,
-                   1, 
-                   channel,
-                   0, 0 ) ) giet_exit("error in giet_nic_rx_stop()");
-}
-
-/////////////////////////////////////////////
-void giet_nic_tx_stop( unsigned int channel )
+                   1,                    // RX
+                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stop()");
+}
+
+///////////////////////
+void giet_nic_tx_stop()
 {
     if ( sys_call( SYSCALL_NIC_STOP,
-                   0, 
-                   channel,
-                   0, 0 ) ) giet_exit("error in giet_nic_tx_stop()");
-}
-
-//////////////////////////////////////////////
-void giet_nic_rx_stats( unsigned int channel )
+                   0,                   // TX
+                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stop()");
+}
+
+////////////////////////
+void giet_nic_rx_stats()
 {
     if ( sys_call( SYSCALL_NIC_STATS,
-                   1, 
-                   channel,
-                   0, 0 ) ) giet_exit("error in giet_nic_rx_stats()");
-}
-
-//////////////////////////////////////////////
-void giet_nic_tx_stats( unsigned int channel )
+                   1,                   // RX
+                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_stats()");
+}
+
+////////////////////////
+void giet_nic_tx_stats()
 {
     if ( sys_call( SYSCALL_NIC_STATS,
-                   0, 
-                   channel,
-                   0, 0 ) ) giet_exit("error in giet_nic_tx_stats()");
-}
-
-//////////////////////////////////////////////
-void giet_nic_rx_clear( unsigned int channel )
+                   0,                   // TX
+                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_stats()");
+}
+
+////////////////////////
+void giet_nic_rx_clear()
 {
     if ( sys_call( SYSCALL_NIC_CLEAR,
-                   1, 
-                   channel,
-                   0, 0 ) ) giet_exit("error in giet_nic_rx_clear()");
-}
-
-//////////////////////////////////////////////
-void giet_nic_tx_clear( unsigned int channel )
+                   1,                   // RX
+                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_rx_clear()");
+}
+
+////////////////////////
+void giet_nic_tx_clear()
 {
     if ( sys_call( SYSCALL_NIC_CLEAR,
-                   0, 
-                   channel,
-                   0, 0 ) ) giet_exit("error in giet_nic_tx_clear()");
+                   0,                   // TX
+                   0, 0, 0 ) ) giet_pthread_exit("error in giet_nic_tx_clear()");
 }
 
@@ -944,5 +978,5 @@
 
 ///////////////////////////////////////////////////////////////////////////////////
-///////////////////// FAT related system calls ////////////////////////////////////
+//                   FAT related system calls
 ///////////////////////////////////////////////////////////////////////////////////
 
@@ -984,5 +1018,5 @@
                      (unsigned int)buffer,
                      count,
-                     0 ); 
+                     0 );      // no physical addressing required
 }
 
@@ -996,5 +1030,5 @@
                      (unsigned int)buffer,
                      count,
-                     0 ); 
+                     0 );      // no physical addressing required
 }
 
@@ -1068,5 +1102,5 @@
 
 //////////////////////////////////////////////////////////////////////////////////
-///////////////////// Miscellaneous system calls /////////////////////////////////
+//                      Miscellaneous system calls
 //////////////////////////////////////////////////////////////////////////////////
 
@@ -1080,5 +1114,5 @@
                    (unsigned int)y_size, 
                    (unsigned int)nprocs, 
-                   0 ) )  giet_exit("ERROR in giet_procs_number()");
+                   0 ) )  giet_pthread_exit("error in giet_procs_number()");
 }
 
@@ -1092,5 +1126,5 @@
                    (unsigned int) vobj_name,
                    (unsigned int) vbase,
-                   0 ) )  giet_exit("ERROR in giet_vobj_get_vbase()");
+                   0 ) )  giet_pthread_exit("error in giet_vobj_get_vbase()");
 }
 
@@ -1104,5 +1138,5 @@
                    (unsigned int) vobj_name,
                    (unsigned int) length,
-                   0 ) )  giet_exit("ERROR in giet_vobj_get_length()");
+                   0 ) )  giet_pthread_exit("error in giet_vobj_get_length()");
 }
 
@@ -1113,9 +1147,9 @@
                      unsigned int  y ) 
 {
-    if ( sys_call( SYSCALL_HEAP_INFO, 
-                   (unsigned int)vaddr, 
-                   (unsigned int)length, 
-                   x,
-                   y ) )  giet_exit("ERROR in giet_heap_info()");
+    sys_call( SYSCALL_HEAP_INFO, 
+              (unsigned int)vaddr, 
+              (unsigned int)length, 
+              x,
+              y );
 }
 
@@ -1129,5 +1163,5 @@
                    (unsigned int)px,
                    (unsigned int)py,
-                   0 ) )  giet_exit("ERROR in giet_get_xy()");
+                   0 ) )  giet_pthread_exit("error in giet_get_xy()");
 }
 
