Index: trunk/softs/giet_tsar/stdio.c
===================================================================
--- trunk/softs/giet_tsar/stdio.c	(revision 743)
+++ trunk/softs/giet_tsar/stdio.c	(revision 744)
@@ -1,6 +1,6 @@
 ////////////////////////////////////////////////////////////////////////////////////////
 // File : stdio.c
-// Written by Alain Greiner 
-// Date : janvier 2014 
+// Written by Alain Greiner
+// Date : janvier 2014
 //
 // This file defines various functions that can be used by applications to access
@@ -112,6 +112,6 @@
 // Memcopy taken from MutekH.
 ////////////////////////////////////////////////////////////////////////////////////////
-in_drivers void* _memcpy( void*        _dst, 
-                          const void*  _src, 
+in_drivers void* _memcpy( void*        _dst,
+                          const void*  _src,
                           unsigned int size )
 {
@@ -120,5 +120,5 @@
     if ( ! ((unsigned int)dst & 3) && ! ((unsigned int)src & 3) )
     {
-        while (size > 3) 
+        while (size > 3)
         {
             *dst++ = *src++;
@@ -130,5 +130,5 @@
     unsigned char *csrc = (unsigned char*)src;
 
-    while (size--) 
+    while (size--)
     {
         *cdst++ = *csrc++;
@@ -141,5 +141,4 @@
 in_drivers void  _extended_memcpy( unsigned int dst_cluster,
                                    unsigned int dst_address,
-                                   unsigned int src_cluster,
                                    unsigned int src_address,
                                    unsigned int length )
@@ -205,5 +204,5 @@
 {
     asm volatile(
-            "mfc0   $8,     $12         \n"  
+            "mfc0   $8,     $12         \n"
             "ori    $8,     $8,     1   \n"
             "mtc0   $8,     $12         \n"
@@ -260,5 +259,5 @@
 
 ////////////////////////////////////////////////////////////////////////////
-// This function makes a physical read access to a 32 bits word in memory, 
+// This function makes a physical read access to a 32 bits word in memory,
 // after a temporary paddr extension.
 ////////////////////////////////////////////////////////////////////////////
@@ -273,5 +272,5 @@
             "mtc0    $3,        $12           \n"     /* IRQ disabled     */
 
-            "mtc2    %2,        $24           \n"     /* PADDR_EXT <= msb */   
+            "mtc2    %2,        $24           \n"     /* PADDR_EXT <= msb */
             "lw      %0,        0(%1)         \n"     /* value <= *paddr  */
             "mtc2    $0,        $24           \n"     /* PADDR_EXT <= 0   */
@@ -285,5 +284,5 @@
 }
 ////////////////////////////////////////////////////////////////////////////
-// This function makes a physical read access to a single byte in memory, 
+// This function makes a physical read access to a single byte in memory,
 // after a temporary paddr extension.
 ////////////////////////////////////////////////////////////////////////////
@@ -298,5 +297,5 @@
             "mtc0    $3,        $12           \n"     /* IRQ disabled     */
 
-            "mtc2    %2,        $24           \n"     /* PADDR_EXT <= msb */   
+            "mtc2    %2,        $24           \n"     /* PADDR_EXT <= msb */
             "lb      %0,        0(%1)         \n"     /* value <= *paddr  */
             "mtc2    $0,        $24           \n"     /* PADDR_EXT <= 0   */
@@ -310,10 +309,10 @@
 }
 ////////////////////////////////////////////////////////////////////////////
-// This function makes a physical write access to a 32 bits word in memory, 
+// This function makes a physical write access to a 32 bits word in memory,
 // after a temporary DTLB address extension.
 ////////////////////////////////////////////////////////////////////////////
-in_drivers void _word_extended_write( unsigned int  cluster, 
+in_drivers void _word_extended_write( unsigned int  cluster,
                                       unsigned int  address,
-                                      unsigned int  word ) 
+                                      unsigned int  word )
 {
     int sr = _sr_read();
@@ -323,7 +322,7 @@
             "mtc0    $3,        $12           \n"     /* IRQ disabled     */
 
-            "mtc2    %2,        $24           \n"     /* PADDR_EXT <= msb */   
+            "mtc2    %2,        $24           \n"     /* PADDR_EXT <= msb */
             "sw      %0,        0(%1)         \n"     /* *paddr <= value  */
-            "mtc2    $0,        $24           \n"     /* PADDR_EXT <= 0   */   
+            "mtc2    $0,        $24           \n"     /* PADDR_EXT <= 0   */
 
             "sync                             \n"
@@ -335,10 +334,10 @@
 }
 ////////////////////////////////////////////////////////////////////////////
-// This function makes a physical write access to single byte in memory, 
+// This function makes a physical write access to single byte in memory,
 // after a temporary DTLB de-activation and address extension.
 ////////////////////////////////////////////////////////////////////////////
-in_drivers void _byte_extended_write( unsigned int  cluster, 
+in_drivers void _byte_extended_write( unsigned int  cluster,
                                       unsigned int  address,
-                                      unsigned char byte ) 
+                                      unsigned char byte )
 {
     int sr = _sr_read();
@@ -348,7 +347,7 @@
             "mtc0    $3,        $12           \n"     /* IRQ disabled     */
 
-            "mtc2    %2,        $24           \n"     /* PADDR_EXT <= msb */   
+            "mtc2    %2,        $24           \n"     /* PADDR_EXT <= msb */
             "sb      %0,        0(%1)         \n"     /* *paddr <= value  */
-            "mtc2    $0,        $24           \n"     /* PADDR_EXT <= 0   */   
+            "mtc2    $0,        $24           \n"     /* PADDR_EXT <= 0   */
 
             "sync                             \n"
@@ -361,5 +360,5 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////
-// Exit (suicide) after printing message on TTY0 
+// Exit (suicide) after printing message on TTY0
 ///////////////////////////////////////////////////////////////////////////////////////
 in_drivers void _exit()
@@ -418,6 +417,6 @@
 //  - If there is only one terminal, it is supposed to be shared, and used by
 //    all processors: a lock must be taken before display.
-//  - If there is several terminals, and the number of processors is smaller 
-//    than the number of terminals, there is one terminal per processor, but 
+//  - If there is several terminals, and the number of processors is smaller
+//    than the number of terminals, there is one terminal per processor, but
 //    the TTY index is not equal to the proc_id, due to cluster indexing policy:
 //    proc_id = cluster_xy * NB_PROCS_MAX + local_id (with cluster_xy = x << Y_WIDTH + y)
@@ -434,6 +433,6 @@
 // returns  the number of characters that have been actually written.
 ///////////////////////////////////////////////////////////////////////////////////////
-in_drivers int _tty_write( char*           buffer, 
-                           unsigned int    length, 
+in_drivers int _tty_write( char*           buffer,
+                           unsigned int    length,
                            unsigned int    channel )
 {
@@ -464,5 +463,5 @@
 // and returns 1 if the register is full.
 ///////////////////////////////////////////////////////////////////////////////////////
-in_drivers int _tty_read( char*          buffer, 
+in_drivers int _tty_read( char*          buffer,
                           unsigned int   channel )
 {
@@ -493,5 +492,5 @@
 // This function displays a 32 bits unsigned int as an hexa string on TTY0.
 ///////////////////////////////////////////////////////////////////////////////
-in_drivers void _tty_putx(unsigned int val) 
+in_drivers void _tty_putx(unsigned int val)
 {
     static const char HexaTab[] = "0123456789ABCDEF";
@@ -503,6 +502,6 @@
     buf[10] = 0;
 
-    for (c = 0; c < 8; c++) 
-    { 
+    for (c = 0; c < 8; c++)
+    {
         buf[9 - c] = HexaTab[val & 0xF];
         val = val >> 4;
@@ -514,5 +513,5 @@
 // This function displays a 32 bits unsigned int as a decimal string on TTY0.
 ///////////////////////////////////////////////////////////////////////////////
-in_drivers void _tty_putd( unsigned int val ) 
+in_drivers void _tty_putd( unsigned int val )
 {
     static const char DecTab[] = "0123456789";
@@ -523,12 +522,12 @@
     buf[10] = 0;
 
-    for (i = 0; i < 10; i++) 
-    {
-        if ((val != 0) || (i == 0)) 
+    for (i = 0; i < 10; i++)
+    {
+        if ((val != 0) || (i == 0))
         {
             buf[9 - i] = DecTab[val % 10];
             first = 9 - i;
         }
-        else 
+        else
         {
             break;
@@ -540,5 +539,5 @@
 
 //////////////////////////////////////////////////////////////////////////////
-// This function try to take the hardwired lock protecting exclusive access 
+// This function try to take the hardwired lock protecting exclusive access
 // to TTY terminal identified by the channel argument.
 // It returns only when the lock has been successfully taken.
@@ -552,5 +551,5 @@
 
 //////////////////////////////////////////////////////////////////////////////
-// This function releases the hardwired lock protecting exclusive access 
+// This function releases the hardwired lock protecting exclusive access
 // to TTY terminal identified by the channel argument.
 //////////////////////////////////////////////////////////////////////////////
@@ -577,5 +576,5 @@
     // check TTY channel
     l           = (proc_id % NB_PROCS_MAX);
-    x           = (proc_id / NB_PROCS_MAX) >> Y_WIDTH; 
+    x           = (proc_id / NB_PROCS_MAX) >> Y_WIDTH;
     y           = (proc_id / NB_PROCS_MAX) & ((1<<Y_WIDTH) - 1);
     channel = (x * Y_SIZE + y) * NB_PROCS_MAX + l;
@@ -600,5 +599,5 @@
 //  The <DEL> character is interpreted, and previous characters can be
 //  cancelled. All others characters are ignored.
-//  When the <LF> or <CR> character is received, the string is converted 
+//  When the <LF> or <CR> 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.
@@ -624,5 +623,5 @@
     // check TTY channel
     l           = (proc_id % NB_PROCS_MAX);
-    x           = (proc_id / NB_PROCS_MAX) >> Y_WIDTH; 
+    x           = (proc_id / NB_PROCS_MAX) >> Y_WIDTH;
     y           = (proc_id / NB_PROCS_MAX) & ((1<<Y_WIDTH) - 1);
     channel = (x * Y_SIZE + y) * NB_PROCS_MAX + l;
@@ -702,5 +701,5 @@
 
     // compute TTY channel :
-    // if the number of TTY channels is smaller 
+    // if the number of TTY channels is smaller
     // than the number of clusters, use TTY_0_0
     // else, TTY channel <= cluster index
@@ -711,25 +710,25 @@
     else
     {
-        x           = (proc_id / NB_PROCS_MAX) >> Y_WIDTH; 
+        x           = (proc_id / NB_PROCS_MAX) >> Y_WIDTH;
         y           = (proc_id / NB_PROCS_MAX) & ((1<<Y_WIDTH) - 1);
         channel     = (x * Y_SIZE + y);
     }
 
-    // take the TTY lock 
+    // take the TTY lock
     _tty_get_lock( channel );
 
 printf_text:
 
-    while (*format) 
+    while (*format)
     {
         unsigned int i;
         for (i = 0; format[i] && format[i] != '%'; i++)
             ;
-        if (i) 
+        if (i)
         {
             _tty_write( format, i, channel );
             format += i;
         }
-        if (*format == '%') 
+        if (*format == '%')
         {
             format++;
@@ -762,5 +761,5 @@
                 break;
             case ('d'):             // decimal signed integer
-                if (val < 0) 
+                if (val < 0)
                 {
                     val = -val;
@@ -768,5 +767,5 @@
                 }
             case ('u'):             // decimal unsigned integer
-                for( i=0 ; i<10 ; i++) 
+                for( i=0 ; i<10 ; i++)
                 {
                     buf[9-i] = HexaTab[val % 10];
@@ -778,5 +777,5 @@
             case ('x'):             // hexadecimal integer
                 _tty_write( "0x", 2, channel );
-                for( i=0 ; i<8 ; i++) 
+                for( i=0 ; i<8 ; i++)
                 {
                     buf[7-i] = HexaTab[val % 16U];
@@ -858,10 +857,10 @@
 //////////////////////////////////////////////////////////////////////////////////////////
 // The block size is 512 bytes.
-// The functions below use the three variables _ioc_lock _ioc_done, 
+// The functions below use the three variables _ioc_lock _ioc_done,
 // and _ioc_status for synchronisation.
 // - As the IOC component can be used by several programs running in parallel,
 // the _ioc_lock variable guaranties exclusive access to the device.
 // The _ioc_read() and _ioc_write() functions use atomic LL/SC to get the lock.
-// and set _ioc_lock to a non zero value. 
+// and set _ioc_lock to a non zero value.
 // The _ioc_write() and _ioc_read() functions are blocking, polling the _ioc_lock
 // variable until the device is available.
@@ -873,5 +872,5 @@
 // reset the _ioc_done variable to zero, and releases the _ioc_lock variable.
 ///////////////////////////////////////////////////////////////////////////////////////
-//  If USE_RAMDISK is set, we access a "virtual" block device controler  implemented 
+//  If USE_RAMDISK is set, we access a "virtual" block device controler  implemented
 //  as a memory-mapped segment in cluster [0,0] at address seg_ramdisk_base.
 //  The tranfer being fully synchronous, the IOC interrupt is not activated.
@@ -879,10 +878,10 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////
-// This blocking function is used by the _ioc_read() and _ioc_write() functions 
+// This blocking function is used by the _ioc_read() and _ioc_write() functions
 // to get _ioc_lock using LL/SC.
 ///////////////////////////////////////////////////////////////////////////////////////
 in_drivers void _ioc_get_lock()
 {
-    register unsigned int*  plock = (unsigned int*)&_ioc_lock;          
+    register unsigned int*  plock = (unsigned int*)&_ioc_lock;
 
     asm volatile (
@@ -890,7 +889,7 @@
             "ll     $2,     0(%0)       \n" // $2 <= _ioc_lock
             "bnez   $2,     1b          \n" // retry  if busy
-            "li     $3,     1           \n" // prepare argument for sc  
+            "li     $3,     1           \n" // prepare argument for sc
             "sc     $3,     0(%0)       \n" // try to set _ioc_busy
-            "beqz   $3,     1b          \n" // retry if not atomic 
+            "beqz   $3,     1b          \n" // retry if not atomic
             ::"r"(plock) :"$2","$3");
 }
@@ -903,6 +902,6 @@
 // - ext    : cluster index for the memory buffer
 ///////////////////////////////////////////////////////////////////////////////////////
-in_drivers void _ioc_write( size_t   lba, 
-                            void*    buffer, 
+in_drivers void _ioc_write( size_t   lba,
+                            void*    buffer,
                             size_t   count,
                             size_t   ext )
@@ -923,5 +922,5 @@
                           src_address,
                           count*512 );
-        
+
         _ioc_status = BLOCK_DEVICE_WRITE_SUCCESS;
         _ioc_done   = 1;
@@ -946,6 +945,6 @@
 // - ext    : cluster index for the memory buffer
 ///////////////////////////////////////////////////////////////////////////////////////
-in_drivers void _ioc_read( size_t   lba, 
-                           void*    buffer, 
+in_drivers void _ioc_read( size_t   lba,
+                           void*    buffer,
                            size_t   count,
                            size_t   ext )
@@ -995,6 +994,6 @@
 {
     // waiting for completion
-    while (_ioc_done == 0)  asm volatile("nop"); 
-    
+    while (_ioc_done == 0)  asm volatile("nop");
+
     // reset synchronisation variables
     _ioc_done = 0;
@@ -1028,5 +1027,5 @@
 //  FRAME_BUFFER
 //////////////////////////////////////////////////////////////////////////////////////
-// The _fb_sync_write & _fb_sync_read functions use a memcpy strategy to implement 
+// The _fb_sync_write & _fb_sync_read functions use a memcpy strategy to implement
 // the transfer between a data buffer and the frame buffer.
 // They are blocking until completion of the transfer.
@@ -1041,6 +1040,6 @@
 // - ext    : cluster_xy for the user buffer
 //////////////////////////////////////////////////////////////////////////////////////
-in_drivers void _fb_sync_write( unsigned int  offset, 
-                                unsigned int  buffer, 
+in_drivers void _fb_sync_write( unsigned int  offset,
+                                unsigned int  buffer,
                                 unsigned int  length,
                                 unsigned int  ext )
@@ -1049,7 +1048,6 @@
     unsigned int  src_cluster = ext;
     unsigned int  dst_address = (unsigned int)&seg_fbf_base + offset;
-    unsigned int  dst_cluster = (X_IO << Y_WIDTH) | Y_IO;  // cluster_xy for I/O
-
-    _extended_memcpy( dst_cluster,
+
+    _extended_memcpy( CLUSTER_IO,
                       dst_address,
                       src_cluster,
@@ -1066,6 +1064,6 @@
 // - ext    : cluster_xy for the user buffer
 //////////////////////////////////////////////////////////////////////////////////////
-in_drivers void  _fb_sync_read( unsigned int  offset, 
-                                unsigned int  buffer, 
+in_drivers void  _fb_sync_read( unsigned int  offset,
+                                unsigned int  buffer,
                                 unsigned int  length,
                                 unsigned int  ext )
@@ -1074,9 +1072,8 @@
     unsigned int  dst_cluster = ext;
     unsigned int  src_address = (unsigned int)&seg_fbf_base + offset;
-    unsigned int  src_cluster = (X_IO << Y_WIDTH) | Y_IO;  // cluster_xy for I/O
 
     _extended_memcpy( dst_cluster,
                       dst_address,
-                      src_cluster,
+                      CLUSTER_IO,
                       src_address,
                       length );
@@ -1093,15 +1090,15 @@
     //int*         mmc_address = (int*)&seg_mmc_base;
     unsigned int cluster_xy  = _procid() / NB_PROCS_MAX;
-    
+
     _tty_printf( "WRITE ERROR signaled by Memory Cache in cluster %x\n", cluster_xy );
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////
-// Release a software spin-lock 
+// Release a software spin-lock
 ///////////////////////////////////////////////////////////////////////////////////////
 in_drivers void _release_lock(size_t index)
 
 {
-    if( index >= NB_LOCKS ) 
+    if( index >= NB_LOCKS )
     {
         _tty_get_lock( 0 );
@@ -1110,5 +1107,5 @@
         _exit();
     }
-    
+
     _spin_lock[index] = 0;
 }
@@ -1132,12 +1129,12 @@
 
     register int   delay = ((_proctime() +_procid()) & 0xF) << 4;
-    register int * plock = (int *) &_spin_lock[index];          
+    register int * plock = (int *) &_spin_lock[index];
 
     asm volatile ("_locks_llsc:             \n"
                   "ll   $2,    0(%0)        \n"     // $2 <= _locks_lock
                   "bnez $2,    _locks_delay \n"     // random delay if busy
-                  "li   $3,    1            \n"     // prepare argument for sc  
+                  "li   $3,    1            \n"     // prepare argument for sc
                   "sc   $3,    0(%0)        \n"     // try to set _locks_busy
-                  "bnez $3,    _locks_ok    \n"     // exit if atomic 
+                  "bnez $3,    _locks_ok    \n"     // exit if atomic
                   "_locks_delay:            \n"
                   "move $4,    %1           \n"     // $4 <= delay
@@ -1155,7 +1152,7 @@
 // - barrier_count[index] <= N
 // - barrier_lock[index]  <= 0
-// All tasks try to initialize the barrier, but the initialisation 
+// All tasks try to initialize the barrier, but the initialisation
 // is done by only one task, using LL/SC instructions.
-// This cooperative initialisation is questionnable, 
+// This cooperative initialisation is questionnable,
 // because the barrier can ony be initialised once...
 //////////////////////////////////////////////////////////////////////////////////////
@@ -1176,12 +1173,12 @@
     // parallel initialisation using atomic instructions LL/SC
     asm volatile ("_barrier_init_test:              \n"
-                  "ll   $2,     0(%0)               \n" // read barrier_value 
+                  "ll   $2,     0(%0)               \n" // read barrier_value
                   "bnez $2,     _barrier_init_done  \n"
                   "move $3,     %3                  \n"
                   "sc   $3,     0(%0)               \n" // try to write barrier_value
                   "beqz $3,     _barrier_init_test  \n"
-                  "move $3, %3                      \n" 
+                  "move $3, %3                      \n"
                   "sw   $3, 0(%1)                   \n" // barrier_count <= barrier_value
-                  "move $3, $0                      \n" // 
+                  "move $3, $0                      \n" //
                   "sw   $3, 0(%2)                   \n" // barrier_lock <= 0
                   "_barrier_init_done:          \n"
@@ -1190,9 +1187,9 @@
 
 //////////////////////////////////////////////////////////////////////////////////////
-// This blocking function uses a busy_wait technics (on the barrier_lock value), 
-// because the GIET does not support dynamic scheduling/descheduling of tasks. 
+// This blocking function uses a busy_wait technics (on the barrier_lock value),
+// because the GIET does not support dynamic scheduling/descheduling of tasks.
 // The barrier state is actually defined by two variables:
 // _barrier_count[index] define the number of particpants that are waiting
-// _barrier_lock[index] define the bool variable whose value is polled 
+// _barrier_lock[index] define the bool variable whose value is polled
 // The last participant change the value of _barrier_lock[index] to release the barrier...
 // There is at most 16 independant barriers, and an error is returned
@@ -1201,7 +1198,7 @@
 in_drivers void _barrier_wait(unsigned int index)
 {
-    register int*   pcount      = (int*)&_barrier_count[index];     
+    register int*   pcount      = (int*)&_barrier_count[index];
     register int    count;
-    int             lock        = _barrier_lock[index];     
+    int             lock        = _barrier_lock[index];
 
     if ( index >= NB_BARRIERS )
@@ -1212,5 +1209,5 @@
         _exit();
     }
-    
+
     // parallel decrement _barrier_count[index] using atomic instructions LL/SC
     // input : pointer on _barrier_count[index]
@@ -1238,5 +1235,5 @@
         while ( lock == _barrier_lock[index] );
     }
-} 
+}
 
 
