Index: soft/giet_vm/giet_libs/stdio.h
===================================================================
--- soft/giet_vm/giet_libs/stdio.h	(revision 267)
+++ soft/giet_vm/giet_libs/stdio.h	(revision 295)
@@ -18,6 +18,6 @@
 #define SYSCALL_TIMER_START       0x04
 #define SYSCALL_TIMER_STOP        0x05
-#define SYSCALL_FREE_06           0x06
-#define SYSCALL_FREE_07           0x07
+#define SYSCALL_TTY_GET_LOCK      0x06
+#define SYSCALL_TTY_RELEASE_LOCK  0x07
 #define SYSCALL_HEAP_INFO         0x08
 #define SYSCALL_LOCAL_TASK_ID     0x09
@@ -32,5 +32,5 @@
 #define SYSCALL_FB_SYNC_READ      0x11
 #define SYSCALL_THREAD_ID         0x12
-#define SYSCALL_TTY_LOCK          0x13
+#define SYSCALL_FREE_13           0x13
 #define SYSCALL_FREE_14           0x14
 #define SYSCALL_FREE_15           0x15
@@ -99,120 +99,331 @@
 
 //////////////////////////////////////////////////////////////////////////
-// MIPS32 related system calls 
-//////////////////////////////////////////////////////////////////////////
-
-extern int giet_procid();
-
-extern int giet_proctime();
-
-//////////////////////////////////////////////////////////////////////////
-// TTY device related system calls 
-//////////////////////////////////////////////////////////////////////////
-
-extern int giet_tty_putc(char byte);
-
-extern int giet_tty_puts(char* buf);
-
-extern int giet_tty_putw(unsigned int val);
-
-extern int giet_tty_getc_no_irq(char* byte);
-
-extern int giet_tty_getc(char* byte);
-
-extern int giet_tty_gets(char* buf, unsigned int bufsize);
-
-extern int giet_tty_getw(unsigned int* val);
-
-extern int giet_tty_printf(char* format,...);
-
-//////////////////////////////////////////////////////////////////////////
-// TIMER device related system calls 
-//////////////////////////////////////////////////////////////////////////
-
-extern int giet_timer_start();
-
-extern int giet_timer_stop();
+//////////////////////////////////////////////////////////////////////////
+//               MIPS32 related system calls 
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+//             TTY device related system calls 
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////////
+// This function is a modified version of the mutek_printf().
+// It uses a private terminal allocated to the calling task in the boot.
+// ("use_tty" argument in xml mapping), and does not take the TTY lock.
+// It calls several times the _tty_write system function.
+// Only a limited number of formats are supported:
+//   - %d : signed decimal
+//   - %u : unsigned decimal
+//   - %x : 32 bits hexadecimal
+//   - %l : 64 bits hexadecimal
+//   - %c : char
+//   - %s : string
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_tty_printf( char* format, ... );
+
+//////////////////////////////////////////////////////////////////////////
+// This function is a modified version of the mutek_printf().
+// It uses the kernel TTY0 as a shared terminal, and it takes the
+// TTY lock to get exclusive access during the format display.
+// It calls several times the _tty_write system function.
+// Only a limited number of formats are supported:
+//   - %d : signed decimal
+//   - %u : unsigned decimal
+//   - %x : 32 bits hexadecimal
+//   - %l : 64 bits hexadecimal
+//   - %c : char
+//   - %s : string
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_shr_printf( char* format, ... );
+
+//////////////////////////////////////////////////////////////////////////
+// This blocking function fetches a single character from the private
+// terminal allocated to the calling task in the boot.
+// It uses the TTY_RX_IRQ interrupt, and the associated kernel buffer.
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_tty_getc( char* byte );
+
+//////////////////////////////////////////////////////////////////////////
+// This blocking function fetches a string from the private terminal 
+// allocated to the calling task to a fixed length buffer.
+// The terminal index must be defined in the task context in the boot.
+// It uses the TTY_RX_IRQ interrupt, and the associated kernel buffer.
+// - Up to (bufsize - 1) characters (including the non printable characters)
+//   are copied into buffer, and the string is completed by a NUL character.
+// - The <LF> character is interpreted, and the function close the string
+//   with a NUL character if <LF> is read.
+// - The <DEL> character is interpreted, and the corresponding character(s) 
+//   are removed from the target buffer.
+// - It does not provide an echo.
+// In case or error returned by syscall, it makes a giet_exit().
+/////////////////////////////////////////////////////////////////////////
+extern void giet_tty_gets( char* buf, unsigned int bufsize );
+
+/////////////////////////////////////////////////////////////////////////
+// This blocking function fetches a string of decimal characters (most
+// significant digit first) to build a 32-bit unsigned integer from
+// the private TTY terminal allocated to the calling task. 
+// The terminal index must be defined in the task context in the boot.
+// It uses the TTY_RX_IRQ interrupt, and the associated kernel buffer.
+// - The non-blocking system function _tty_read is called several times,
+//   and the decimal characters are written in a 32 characters buffer 
+//   until a <LF> character is read.
+// - It ignores non-decimal characters, and displays an echo 
+//   system function) for each decimal character.
+// - The <DEL> character is interpreted, and previous characters can be cancelled. 
+// - When the <LF> character is received, the string is converted to an
+//   unsigned int value. If the number of decimal digit is too large for the 32
+//   bits range, the zero value is returned.
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_tty_getw( unsigned int* val );
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+//                TIMER device related system calls 
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////////
+// This function activates the private user timer allocated 
+// to the calling task in the boot phase.
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_timer_start();
+
+//////////////////////////////////////////////////////////////////////////
+// This function stops the private user timer allocated 
+// to the calling task.
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_timer_stop();
  
 //////////////////////////////////////////////////////////////////////////
-// Frame buffer device related system calls 
-//////////////////////////////////////////////////////////////////////////
-
-extern int giet_fb_sync_read( unsigned int offset, 
-                              void*        buffer, 
+//////////////////////////////////////////////////////////////////////////
+//                Frame buffer device related system calls 
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////////
+// This blocking function use a memory copy strategy to transfer data 
+// from the frame buffer device in kernel space to an user buffer.
+//     offset : offset (in bytes) in the frame buffer
+//     buffer : base address of the user buffer
+//     length : number of bytes to be transfered
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_fb_sync_read( unsigned int offset, 
+                               void*        buffer, 
+                               unsigned int length );
+
+//////////////////////////////////////////////////////////////////////////
+// This blocking function use a memory copy strategy to transfer data 
+// from a user buffer to the frame buffer device in kernel space.
+//     offset : offset (in bytes) in the frame buffer
+//     buffer : base address of the memory buffer
+//     length : number of bytes to be transfered
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_fb_sync_write( unsigned int offset, 
+                                void*        buffer, 
+                                unsigned int length );
+
+//////////////////////////////////////////////////////////////////////////
+// This function initializes the two chbuf SRC an DST used by the CMA 
+// controller and activates the CMA channel allocated to the calling task.
+// - buf0   : first user buffer virtual address
+// - buf1   : second user buffer virtual address
+// - length : buffer size (bytes)
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_fb_cma_init( void*        buf0, 
+                              void*        buf1,
                               unsigned int length );
 
-extern int giet_fb_sync_write(unsigned int offset, 
-                              void*        buffer, 
-                              unsigned int length);
-
-extern int giet_fb_cma_init(  void*        buf0, 
-                              void*        buf1,
-                              unsigned int length);
-
-extern int giet_fb_cma_write(unsigned int buf_id);
-
-extern int giet_fb_cma_stop();
-
-//////////////////////////////////////////////////////////////////////////
-// Network controller related system calls 
-//////////////////////////////////////////////////////////////////////////
-
-extern int giet_nic_cma_start();
-
-extern int giet_nic_cma_stop();
-
-//////////////////////////////////////////////////////////////////////////
-// FAT related system calls 
-//////////////////////////////////////////////////////////////////////////
-
+//////////////////////////////////////////////////////////////////////////
+// This function initializes the two chbuf SRC an DST used by the CMA 
+// controller and activates the CMA channel allocated to the calling task.
+// - buf0   : first user buffer virtual address
+// - buf0   : second user buffer virtual address
+// - length : buffer size (bytes)
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_fb_cma_write( unsigned int buf_id );
+
+//////////////////////////////////////////////////////////////////////////
+// This function desactivates the CMA channel allocated to the task.
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_fb_cma_stop();
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+//                  NIC related system calls 
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////////
+// This function initializes the memory chbuf used by the CMA controller, 
+// activates the NIC channel allocated to the calling task, 
+// and activates the two CMA channels.
+// - tx     : RX channel if 0 / TX channel if non 0
+// - buf0   : first user buffer virtual address
+// - buf1   : second user buffer virtual address
+// - length : buffer size (bytes)
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_nic_cma_start();
+
+//////////////////////////////////////////////////////////////////////////
+// This function desactivates the NIC channel and the two CMA channels
+// allocated to the calling task.
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_nic_cma_stop();
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+//               FAT related system calls 
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////////
+// Open a file identified by a pathname, and contained in the system FAT.
+// The read/write flags are not supported yet: no effect.
+// Return -1 in case or error.
+//////////////////////////////////////////////////////////////////////////
 extern int giet_fat_open(  const char*  pathname,
                            unsigned int flags );
 
-extern int giet_fat_read(  unsigned int fd,
-                           void*        buffer,
-                           unsigned int count,
-                           unsigned int offset );
-
-extern int giet_fat_write( unsigned int fd,
-                           void*        buffer,
-                           unsigned int count,
-                           unsigned int offset );
-
-extern int giet_fat_lseek( unsigned int fd,
-                           unsigned int offset,
-                           unsigned int whence );
-
-extern int giet_fat_fstat( unsigned int fd );
-
-extern int giet_fat_close( unsigned int fd );
-
-//////////////////////////////////////////////////////////////////////////
-// Miscelaneous system calls
-//////////////////////////////////////////////////////////////////////////
-
-extern int giet_vobj_get_vbase( char*         vspace_name, 
-                                char*         vobj_name, 
-                                unsigned int  vobj_type, 
-                                unsigned int* vobj_vaddr);
-
-extern int giet_procnumber();
-
+///////////////////////////////////////////////////////////////////////////////////
+// Read "count" sectors from a file identified by "fd", skipping "offset"
+// sectors in file, and writing into the user "buffer". 
+// The user buffer base address shoulb be 64 bytes aligned.
+// In case or error returned by syscall, it makes a giet_exit().
+///////////////////////////////////////////////////////////////////////////////////
+extern void giet_fat_read(  unsigned int fd,
+                            void*        buffer,
+                            unsigned int count,
+                            unsigned int offset );
+
+///////////////////////////////////////////////////////////////////////////////////
+// Write "count" sectors from a file identified by "fd", skipping "offset"
+// sectors in file, and reading from the user "buffer". 
+// The user buffer base address shoulb be 64 bytes aligned.
+// In case or error returned by syscall, it makes a giet_exit().
+///////////////////////////////////////////////////////////////////////////////////
+extern void giet_fat_write( unsigned int fd,
+                            void*        buffer,
+                            unsigned int count,
+                            unsigned int offset );
+
+///////////////////////////////////////////////////////////////////////////////////
+// Change the lseek file pointer value for a file identified by "fd".
+// In case or error returned by syscall, it makes a giet_exit().
+///////////////////////////////////////////////////////////////////////////////////
+extern void giet_fat_lseek( unsigned int fd,
+                            unsigned int offset,
+                            unsigned int whence );
+
+///////////////////////////////////////////////////////////////////////////////////
+// Returns general informations of a file identified by "fd". 
+// (Only the file_size in sectors for this moment)
+///////////////////////////////////////////////////////////////////////////////////
+extern void giet_fat_fstat( unsigned int fd );
+
+//////////////////////////////////////////////////////////////////////////
+// Close a file identified by "fd".
+//////////////////////////////////////////////////////////////////////////
+extern void giet_fat_close( unsigned int fd );
+
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+//                    Miscelaneous system calls
+//////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////////
+// This function returns the processor identifier.
+//////////////////////////////////////////////////////////////////////////
+extern int giet_procid();
+
+//////////////////////////////////////////////////////////////////////////
+// This function returns the local processor time.
+//////////////////////////////////////////////////////////////////////////
+extern int giet_proctime();
+
+//////////////////////////////////////////////////////////////////////////
+// This functions returns the local task id.
+// If processor has n tasks the local task index is ranging from 0 to n-1
+//////////////////////////////////////////////////////////////////////////
+extern int giet_proc_task_id();
+
+//////////////////////////////////////////////////////////////////////////
+// This functions returns the global task id, (unique in the system).
+//////////////////////////////////////////////////////////////////////////
+extern int giet_global_task_id(); 
+
+//////////////////////////////////////////////////////////////////////////
+// This functions returns the thread index of the task in its vspace.
+//////////////////////////////////////////////////////////////////////////
+extern int giet_thread_id(); 
+
+//////////////////////////////////////////////////////////////////////////
+// This function returns a pseudo-random value derived from the processor 
+// cycle count. This value is comprised between 0 & 65535.
+/////////////////////////////////////////////////////////////////////////
+extern int giet_rand();
+
+//////////////////////////////////////////////////////////////////////////
+// This function stops execution of the calling task with a TTY message, 
+// the user task is descheduled and becomes not runable. 
+// It does not consume processor cycles anymore.
+//////////////////////////////////////////////////////////////////////////
 extern void giet_exit();
 
-extern int giet_context_switch();
-
-extern int giet_proc_task_id();
-
-extern int giet_heap_info( unsigned int* vaddr, 
-                           unsigned int* size );
-
-extern int giet_global_task_id();
-
-extern int giet_thread_id();
-
+//////////////////////////////////////////////////////////////////////////
+// This function uses the giet_exit() system call
+// and kill the calling task if the condition is false.
+//////////////////////////////////////////////////////////////////////////
 extern void giet_assert( unsigned int, 
                          char* string );
 
-extern int giet_rand();
+//////////////////////////////////////////////////////////////////////////
+// This function writes in argument "vobj_vaddr" the virtual base address 
+// of a vobj (defined in the mapping_info data structure), identified by 
+// the two arguments "vspace_name" and "vobj_name".
+// In case or error returned by syscall, it makes a giet_exit().
+// ( vobj not defined or wrong vspace )
+//////////////////////////////////////////////////////////////////////////
+extern void giet_vobj_get_vbase( char*         vspace_name, 
+                                 char*         vobj_name, 
+                                 unsigned int* vobj_vaddr);
+
+//////////////////////////////////////////////////////////////////////////
+// This function returns in the "buffer" argument the number of processors 
+// in the cluster specified by the "cluster_xy" argument.
+// In case or error returned by syscall, it makes a giet_exit().
+//////////////////////////////////////////////////////////////////////////
+extern void giet_procnumber( unsigned int cluster_xy,
+                             unsigned int buffer );
+
+//////////////////////////////////////////////////////////////////////////
+// The user task calling this function is descheduled and
+// the processor is allocated to another task.
+//////////////////////////////////////////////////////////////////////////
+extern void giet_context_switch();
+
+//////////////////////////////////////////////////////////////////////////
+// This function returns the base address and size of the task's heap
+//////////////////////////////////////////////////////////////////////////
+extern void giet_heap_info( unsigned int* vaddr, 
+                            unsigned int* size );
+
 
 #endif
