Index: trunk/softs/giet_tsar/stdio.c
===================================================================
--- trunk/softs/giet_tsar/stdio.c	(revision 631)
+++ trunk/softs/giet_tsar/stdio.c	(revision 743)
@@ -22,5 +22,4 @@
 // - NB_PROCS_MAX    : max number of processor per cluster
 // - NB_TTY_CHANNELS : max number of TTY channels
-// - USE_EXT_IO      : use external peripherals if not zero
 //
 // The follobing base addresses must be defined in the ldscript
@@ -36,6 +35,6 @@
 #endif
 
-#if !defined(USE_EXT_IO)
-#error: you must define USE_EXT_IO in the hard_config.h file
+#if !defined(X_IO) || !defined(Y_IO)
+#error: you must define X_IO and Y_IO in the hard_config.h file
 #endif
 
@@ -68,7 +67,4 @@
 #endif
 
-
-
-
 #define NB_LOCKS      256
 #define NB_BARRIERS   16
@@ -82,10 +78,9 @@
 
 struct plouf;
-
-extern struct plouf seg_tty_base;
-extern struct plouf seg_fbf_base;
-extern struct plouf seg_ioc_base;
-extern struct plouf seg_mmc_base;
-extern struct plouf seg_ramdisk_base;
+extern volatile struct plouf seg_tty_base;
+extern volatile struct plouf seg_fbf_base;
+extern volatile struct plouf seg_ioc_base;
+extern volatile struct plouf seg_mmc_base;
+extern volatile struct plouf seg_ramdisk_base;
 
 ////////////////////////////////////////////////////////////////////////////////////////
@@ -93,10 +88,10 @@
 ////////////////////////////////////////////////////////////////////////////////////////
 
-in_unckdata int volatile    _ioc_lock    = 0;
-in_unckdata int volatile    _ioc_done    = 0;
-in_unckdata int volatile    _ioc_status;
-
-in_unckdata char volatile   _tty_get_buf[NB_TTY_CHANNELS];
-in_unckdata int volatile    _tty_get_full[NB_TTY_CHANNELS] = { [0 ... NB_TTY_CHANNELS-1] = 0 };
+static in_unckdata int volatile  _ioc_lock    = 0;
+static in_unckdata int volatile  _ioc_done    = 0;
+static in_unckdata int volatile  _ioc_status;
+
+static in_unckdata char volatile _tty_get_buf[NB_TTY_CHANNELS];
+static in_unckdata int volatile  _tty_get_full[NB_TTY_CHANNELS] = { [0 ... NB_TTY_CHANNELS-1] = 0 };
 
 ////////////////////////////////////////////////////////////////////////////////////////
@@ -104,7 +99,7 @@
 ////////////////////////////////////////////////////////////////////////////////////////
 
-in_unckdata int volatile    _barrier_value[NB_BARRIERS]  = { [0 ... NB_BARRIERS-1] = 0 };
-in_unckdata int volatile    _barrier_count[NB_BARRIERS]  = { [0 ... NB_BARRIERS-1] = 0 };
-in_unckdata int volatile    _barrier_lock[NB_BARRIERS]   = { [0 ... NB_BARRIERS-1] = 0 };
+static in_unckdata int volatile  _barrier_value[NB_BARRIERS] = { [0 ... NB_BARRIERS-1] = 0 };
+static in_unckdata int volatile  _barrier_count[NB_BARRIERS] = { [0 ... NB_BARRIERS-1] = 0 };
+static in_unckdata int volatile  _barrier_lock[NB_BARRIERS]  = { [0 ... NB_BARRIERS-1] = 0 };
 
 ////////////////////////////////////////////////////////////////////////////////////////
@@ -112,5 +107,5 @@
 ////////////////////////////////////////////////////////////////////////////////////////
 
-in_unckdata int volatile    _spin_lock[NB_LOCKS] =    { [0 ... NB_LOCKS-1] = 0 };
+static in_unckdata int volatile  _spin_lock[NB_LOCKS] = { [0 ... NB_LOCKS-1] = 0 };
 
 ////////////////////////////////////////////////////////////////////////////////////////
@@ -189,5 +184,5 @@
 // Returns the number of processsors controled by the GIET
 ////////////////////////////////////////////////////////////////////////////////////////
-in_drivers unsigned int _procnumber()
+in_drivers inline unsigned int _procnumber()
 {
     return (unsigned int)(NB_PROCS_MAX * X_SIZE * Y_SIZE);
@@ -205,23 +200,42 @@
 }
 ////////////////////////////////////////////////////////////////////////////////////////
+// Access CP0 and enable IRQs
+////////////////////////////////////////////////////////////////////////////////////////
+in_drivers inline void _it_enable()
+{
+    asm volatile(
+            "mfc0   $8,     $12         \n"  
+            "ori    $8,     $8,     1   \n"
+            "mtc0   $8,     $12         \n"
+            ::: "$8");
+}
+////////////////////////////////////////////////////////////////////////////////////////
 // Access CP0 and mask IRQs
 ////////////////////////////////////////////////////////////////////////////////////////
-in_drivers void _it_mask()
-{
-    int tmp;
-    asm volatile("mfc0  %0, $12"    : "=r" (tmp) );
-    asm volatile("ori   %0, %0, 1"  : "=r" (tmp) );
-    asm volatile("mtc0  %0, $12"    : "=r" (tmp) );
-}
-////////////////////////////////////////////////////////////////////////////////////////
-// Access CP0 and enable IRQs
-////////////////////////////////////////////////////////////////////////////////////////
-in_drivers void _it_enable()
-{
-    int tmp;
-    asm volatile("mfc0  %0, $12"    : "=r" (tmp) );
-    asm volatile("addi  %0, %0, -1" : "=r" (tmp) );
-    asm volatile("mtc0  %0, $12"    : "=r" (tmp) );
-}
+in_drivers inline void _it_disable()
+{
+    asm volatile(
+            "li     $9,     0xFFFFFFFE  \n"
+            "mfc0   $8,     $12         \n"
+            "and    $8,     $8,     $9  \n"
+            "mtc0   $8,     $12         \n"
+            ::: "$8","$9");
+}
+
+////////////////////////////////////////////////////////////////////////////////////////
+// Access CP0 and mask IRQs
+////////////////////////////////////////////////////////////////////////////////////////
+in_drivers inline void _sr_write(int sr)
+{
+    asm volatile("mtc0  %0, $12        \n" : /* no outputs */ : "r" (sr));
+}
+
+in_drivers inline int _sr_read()
+{
+    int ret;
+    asm volatile("mfc0  %0, $12        \n" : "=r" (ret));
+    return ret;
+}
+
 //////////////////////////////////////////////////////////////////////
 // Invalidate all cache lines corresponding to a memory buffer.
@@ -249,12 +263,12 @@
 // after a temporary paddr extension.
 ////////////////////////////////////////////////////////////////////////////
-in_drivers unsigned int _word_extended_read( unsigned int  cluster,
-                                             unsigned int  address )
-{
-    unsigned int value;
+in_drivers volatile unsigned int _word_extended_read( unsigned int cluster,
+                                                      unsigned int address )
+{
+    int sr = _sr_read();
+    volatile unsigned int value;
     asm volatile(
             "li      $3,        0xFFFFFFFE    \n"
-            "mfc0    $2,        $12           \n"
-            "and     $3,        $2, $3        \n"
+            "and     $3,        %3,     $3    \n"
             "mtc0    $3,        $12           \n"     /* IRQ disabled     */
 
@@ -263,11 +277,9 @@
             "mtc2    $0,        $24           \n"     /* PADDR_EXT <= 0   */
 
-            "li      $3,        0x00000001    \n"
-            "mfc0    $2,        $12           \n"
-            "or      $3,        $3, $2        \n"
-            "mtc0    $3,        $12           \n"     /* IRQ enabled      */
             : "=r" (value)
-            : "r" (address), "r" (cluster)
-            : "$2", "$3" );
+            : "r" (address), "r" (cluster), "r" (sr)
+            : "$2", "$3", "memory" );
+
+    _sr_write(sr);
     return value;
 }
@@ -276,12 +288,12 @@
 // after a temporary paddr extension.
 ////////////////////////////////////////////////////////////////////////////
-in_drivers unsigned char _byte_extended_read( unsigned int  cluster,
-                                              unsigned int  address )
-{
-    unsigned int value;
+in_drivers volatile unsigned char _byte_extended_read( unsigned int  cluster,
+                                                       unsigned int  address )
+{
+    int sr = _sr_read();
+    volatile unsigned char value;
     asm volatile(
             "li      $3,        0xFFFFFFFE    \n"
-            "mfc0    $2,        $12           \n"
-            "and     $3,        $2, $3        \n"
+            "and     $3,        %3,     $3    \n"
             "mtc0    $3,        $12           \n"     /* IRQ disabled     */
 
@@ -290,12 +302,10 @@
             "mtc2    $0,        $24           \n"     /* PADDR_EXT <= 0   */
 
-            "li      $3,        0x00000001    \n"
-            "mfc0    $2,        $12           \n"
-            "or      $3,        $3, $2        \n"
-            "mtc0    $3,        $12           \n"     /* IRQ enabled      */
             : "=r" (value)
-            : "r" (address), "r" (cluster)
-            : "$2", "$3" );
-    return (unsigned char)value;
+            : "r" (address), "r" (cluster), "r" (sr)
+            : "$2", "$3", "memory" );
+
+    _sr_write(sr);
+    return value;
 }
 ////////////////////////////////////////////////////////////////////////////
@@ -307,8 +317,8 @@
                                       unsigned int  word ) 
 {
+    int sr = _sr_read();
     asm volatile(
             "li      $3,        0xFFFFFFFE    \n"
-            "mfc0    $2,        $12           \n"
-            "and     $3,        $2, $3        \n"
+            "and     $3,        %3,     $3    \n"
             "mtc0    $3,        $12           \n"     /* IRQ disabled     */
 
@@ -317,11 +327,10 @@
             "mtc2    $0,        $24           \n"     /* PADDR_EXT <= 0   */   
 
-            "li      $3,        0x00000001    \n"
-            "mfc0    $2,        $12           \n"
-            "or      $3,        $2, $3        \n"
-            "mtc0    $3,        $12           \n"     /* IRQ enabled      */
+            "sync                             \n"
             :
-            : "r" (word), "r" (address), "r" (cluster)
-            : "$2", "$3");
+            : "r" (word), "r" (address), "r" (cluster), "r" (sr)
+            : "$2", "$3", "memory");
+
+    _sr_write(sr);
 }
 ////////////////////////////////////////////////////////////////////////////
@@ -333,8 +342,8 @@
                                       unsigned char byte ) 
 {
+    int sr = _sr_read();
     asm volatile(
             "li      $3,        0xFFFFFFFE    \n"
-            "mfc0    $2,        $12           \n"
-            "and     $3,        $2, $3        \n"
+            "and     $3,        %3,     $3    \n"
             "mtc0    $3,        $12           \n"     /* IRQ disabled     */
 
@@ -343,11 +352,10 @@
             "mtc2    $0,        $24           \n"     /* PADDR_EXT <= 0   */   
 
-            "li      $3,        0x00000001    \n"
-            "mfc0    $2,        $12           \n"
-            "or      $3,        $2, $3        \n"
-            "mtc0    $3,        $12           \n"     /* IRQ enabled      */
+            "sync                             \n"
             :
-            : "r" (byte), "r" (address), "r" (cluster)
-            : "$2", "$3");
+            : "r" (byte), "r" (address), "r" (cluster), "r" (sr)
+            : "$2", "$3", "memory");
+
+    _sr_write(sr);
 }
 
@@ -417,8 +425,4 @@
 //  - If the computed tty_id is larger than NB_TTY_CHANNELS, an error is returned.
 ///////////////////////////////////////////////////////////////////////////////////////
-//  If USE_EXT_IO is set, we use the TTY controler implemented in cluster_io
-//  (x = X_SIZE-1 / y = Y_SIZE), which requires and extended address access. 
-//  If USE_EXT_IO not set, we use the single channel TTY contrÃŽler in cluster (0,0).
-///////////////////////////////////////////////////////////////////////////////////////
 
 ///////////////////////////////////////////////////////////////////////////////////////
@@ -434,31 +438,17 @@
                            unsigned int    channel )
 {
-    unsigned int    base       = (unsigned int)&seg_tty_base + channel*TTY_SPAN*4;
-    unsigned int    nwritten   = 0;
-    unsigned int    cluster_io = ((X_SIZE-1)<<Y_WIDTH) + Y_SIZE;
+    unsigned int    base     = (unsigned int)&seg_tty_base + channel*TTY_SPAN*4;
+    unsigned int    nwritten = 0;
     unsigned int    status;
-    unsigned int	i;
+    unsigned int    i;
 
     for ( i=0 ; i < length ; i++ )
     {
-        if( USE_EXT_IO )    // extended addressing to reach cluster_io
+        status = _word_extended_read( CLUSTER_IO, base + TTY_STATUS*4 );
+        if ( (status & 0x2) == 0x2 ) break;
+        else
         {
-            status = _word_extended_read( cluster_io, base + TTY_STATUS*4 );
-            if ( (status & 0x2) == 0x2 ) break;
-            else
-            {
-                _byte_extended_write( cluster_io, base + TTY_WRITE*4 , buffer[i] );
-                nwritten++;
-            }
-        }
-        else                // direct addressing to cluster(0,0)
-        {
-            char* tty = (char*)base;
-            if ( (tty[TTY_STATUS*4] & 0x2) == 0x2 )  break;
-            else
-            {
-                tty[TTY_WRITE*4] = buffer[i]; // write character
-                nwritten++;
-            }
+            _byte_extended_write( CLUSTER_IO, base + TTY_WRITE*4 , buffer[i] );
+            nwritten++;
         }
     }
@@ -477,35 +467,14 @@
                           unsigned int   channel )
 {
-    unsigned int    base       = (unsigned int)&seg_tty_base + channel*TTY_SPAN*4;
-    unsigned int    cluster_io = ((X_SIZE-1)<<Y_WIDTH) + Y_SIZE;
-    unsigned int    status;
-
-    if( USE_EXT_IO )
-    {
-        status = _word_extended_read( cluster_io, base + TTY_STATUS*4 );
-        if ( (status & 0x1) == 0x1 )
-        {
-            buffer[0] = (char)_word_extended_read( cluster_io, base + TTY_READ*4 );
-            return 1;
-        }
-        else
-        {
-            return 0;
-        }
-    }
-    else
-    {
-        char* tty = (char*)base;
-
-        if((tty[TTY_STATUS*4] & 0x1) == 0x1)
-        {
-            buffer[0] = tty[TTY_READ*4];
-            return 1;
-        }
-        else
-        {
-            return 0;
-        }
-    }
+    unsigned int base    = (unsigned int)&seg_tty_base + channel*TTY_SPAN*4;
+    unsigned int status;
+
+    status = _word_extended_read( CLUSTER_IO, base + TTY_STATUS*4 );
+    if ( (status & 0x1) == 0x1 )
+    {
+        buffer[0] = (char)_word_extended_read( CLUSTER_IO, base + TTY_READ*4 );
+        return 1;
+    }
+    return 0;
 }
 
@@ -550,5 +519,5 @@
     char buf[11];
     unsigned int i;
-    unsigned int first;
+    unsigned int first = 0;
 
     buf[10] = 0;
@@ -577,16 +546,7 @@
 in_drivers void _tty_get_lock( unsigned int channel )
 {
-    if ( USE_EXT_IO )  // extended addressing to cluster_io
-    {
-        unsigned int    cluster_io = ((X_SIZE-1)<<Y_WIDTH) + Y_SIZE;
-        unsigned int    address    = (unsigned int)&seg_tty_base 
-                                     + ((TTY_CONFIG + channel*TTY_SPAN)*4);
-        while ( _word_extended_read( cluster_io, address ) ) asm volatile("nop");
-    }
-    else               // direct addressing to cluster(0,0)
-    {
-        unsigned int* tty = (unsigned int *) &seg_tty_base;
-        while ( tty[channel * TTY_SPAN + TTY_CONFIG] ) asm volatile("nop"); 
-    }
+    unsigned int base = (unsigned int)&seg_tty_base;
+    unsigned int offset = (TTY_CONFIG + channel*TTY_SPAN) << 2;
+    while ( _word_extended_read( CLUSTER_IO, base + offset ) );
 }
 
@@ -597,16 +557,7 @@
 in_drivers void _tty_release_lock( unsigned int channel )
 {
-    if ( USE_EXT_IO )  // extended addressing to cluster_io
-    {
-        unsigned int    cluster_io = ((X_SIZE-1)<<Y_WIDTH) + Y_SIZE;
-        unsigned int    address    = (unsigned int)&seg_tty_base 
-                                     + ((TTY_CONFIG + channel*TTY_SPAN)*4);
-        _word_extended_write( cluster_io, address, 0 );
-    }
-    else               // direct addressing to cluster(0,0)
-    {
-        unsigned int* tty_address = (unsigned int *) &seg_tty_base;
-        tty_address[channel * TTY_SPAN + TTY_CONFIG] = 0;
-    }
+    unsigned int base    = (unsigned int)&seg_tty_base;
+    unsigned int offset  = (TTY_CONFIG + channel*TTY_SPAN) << 2;
+    _word_extended_write( CLUSTER_IO, base + offset, 0 );
 }
 
@@ -860,18 +811,8 @@
 in_drivers void _tty_isr_indexed(size_t index)
 {
-    if ( USE_EXT_IO )   // extended addressing to TTY in cluster_io
-    {
-        unsigned int  cluster = ((X_SIZE-1)<<Y_WIDTH) + Y_SIZE;
-        unsigned int  base    = (unsigned int)&seg_tty_base +
-                                ((index*TTY_SPAN + TTY_READ)*4); 
-
-        _tty_get_buf[index] = (char)_word_extended_read( cluster, base );
-    }
-    else                // direct addressing to TTY in cluster(0,0)
-    {
-        char* tty = (char*)&seg_tty_base + index*TTY_SPAN*4;
-
-        _tty_get_buf[index] = tty[TTY_READ*4];	// save character and reset IRQ
-    }
+    unsigned int base = (unsigned int)&seg_tty_base;
+    unsigned int offset = (index*TTY_SPAN + TTY_READ) << 2;
+
+    _tty_get_buf[index] = _byte_extended_read(CLUSTER_IO, base + offset);
     _tty_get_full[index] = 1;               // signals character available
 }
@@ -932,8 +873,4 @@
 // reset the _ioc_done variable to zero, and releases the _ioc_lock variable.
 ///////////////////////////////////////////////////////////////////////////////////////
-//  If USE_EXT_IO is set, we use the IOC controler implemented in cluster_io
-//  (x = X_SIZE-1 / y = Y_SIZE), which requires and extended address access. 
-//  If USE_EXT_IO not set, we use the IOC contrÃŽler in cluster (0,0).
-//
 //  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.
@@ -947,13 +884,14 @@
 in_drivers void _ioc_get_lock()
 {
-    register unsigned int*	plock = (unsigned int*)&_ioc_lock;			
-
-    asm volatile ("_ioc_llsc:			    \n"
-                  "ll   $2,    0(%0)		    \n"	// $2 <= _ioc_lock
-                  "bnez $2,    _ioc_llsc	    \n" // retry  if busy
-                  "li   $3,    1   		    \n"	// prepare argument for sc  
-                  "sc   $3,    0(%0)       	    \n" // try to set _ioc_busy
-                  "beqz $3,    _ioc_llsc   	    \n" // retry if not atomic 
-                  ::"r"(plock):"$2","$3");
+    register unsigned int*  plock = (unsigned int*)&_ioc_lock;          
+
+    asm volatile (
+            "1:                         \n"
+            "ll     $2,     0(%0)       \n" // $2 <= _ioc_lock
+            "bnez   $2,     1b          \n" // retry  if busy
+            "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 
+            ::"r"(plock) :"$2","$3");
 }
 
@@ -988,28 +926,15 @@
         _ioc_status = BLOCK_DEVICE_WRITE_SUCCESS;
         _ioc_done   = 1;
-    }
-    else if ( USE_EXT_IO )   // extended addressing to cluster_io
-    {
-        unsigned int    cluster = ((X_SIZE-1)<<Y_WIDTH) + Y_SIZE;
-        unsigned int    base    = (unsigned int)&seg_ioc_base;
-
-        _word_extended_write( cluster, base + BLOCK_DEVICE_BUFFER*4,     (unsigned int)buffer );
-        _word_extended_write( cluster, base + BLOCK_DEVICE_BUFFER_EXT*4, ext );
-        _word_extended_write( cluster, base + BLOCK_DEVICE_COUNT*4,      count );
-        _word_extended_write( cluster, base + BLOCK_DEVICE_LBA*4,        lba );
-        _word_extended_write( cluster, base + BLOCK_DEVICE_IRQ_ENABLE*4, 1 );
-        _word_extended_write( cluster, base + BLOCK_DEVICE_OP*4,         BLOCK_DEVICE_WRITE );
-    }
-    else                // direct addressing to cluster(0,0)
-    {
-        unsigned int* ioc = (unsigned int*)&seg_ioc_base;
-
-        ioc[BLOCK_DEVICE_BUFFER]     = (unsigned int)buffer;
-        ioc[BLOCK_DEVICE_BUFFER_EXT] = ext;
-        ioc[BLOCK_DEVICE_COUNT]      = count;
-        ioc[BLOCK_DEVICE_LBA]        = lba;
-        ioc[BLOCK_DEVICE_IRQ_ENABLE] = 1;
-        ioc[BLOCK_DEVICE_OP]         = BLOCK_DEVICE_WRITE;
-    }
+
+        return;
+    }
+
+    unsigned int base = (unsigned int)&seg_ioc_base;
+    _word_extended_write( CLUSTER_IO, base + BLOCK_DEVICE_BUFFER*4,     (unsigned int)buffer );
+    _word_extended_write( CLUSTER_IO, base + BLOCK_DEVICE_BUFFER_EXT*4, ext );
+    _word_extended_write( CLUSTER_IO, base + BLOCK_DEVICE_COUNT*4,      count );
+    _word_extended_write( CLUSTER_IO, base + BLOCK_DEVICE_LBA*4,        lba );
+    _word_extended_write( CLUSTER_IO, base + BLOCK_DEVICE_IRQ_ENABLE*4, 1 );
+    _word_extended_write( CLUSTER_IO, base + BLOCK_DEVICE_OP*4,         BLOCK_DEVICE_WRITE );
 }
 
@@ -1044,28 +969,20 @@
         _ioc_status = BLOCK_DEVICE_READ_SUCCESS;
         _ioc_done   = 1;
-    }
-    else if ( USE_EXT_IO )   // extended addressing to cluster_io
-    {
-        unsigned int    cluster = ((X_SIZE-1)<<Y_WIDTH) + Y_SIZE;
-        unsigned int    base    = (unsigned int)&seg_ioc_base;
-
-        _word_extended_write( cluster, base + BLOCK_DEVICE_BUFFER*4,     (unsigned int)buffer );
-        _word_extended_write( cluster, base + BLOCK_DEVICE_BUFFER_EXT*4, ext );
-        _word_extended_write( cluster, base + BLOCK_DEVICE_COUNT*4,      count );
-        _word_extended_write( cluster, base + BLOCK_DEVICE_LBA*4,        lba );
-        _word_extended_write( cluster, base + BLOCK_DEVICE_IRQ_ENABLE*4, 1 );
-        _word_extended_write( cluster, base + BLOCK_DEVICE_OP*4,         BLOCK_DEVICE_READ );
-    }
-    else                // direct addressing to cluster(0,0)
-    {
-        unsigned int* ioc = (unsigned int*)&seg_ioc_base;
-
-        ioc[BLOCK_DEVICE_BUFFER]     = (unsigned int)buffer;
-        ioc[BLOCK_DEVICE_BUFFER_EXT] = ext;
-        ioc[BLOCK_DEVICE_COUNT]      = count;
-        ioc[BLOCK_DEVICE_LBA]        = lba;
-        ioc[BLOCK_DEVICE_IRQ_ENABLE] = 1;
-        ioc[BLOCK_DEVICE_OP]         = BLOCK_DEVICE_READ;
-    }
+
+        return;
+    }
+
+    const unsigned int base = (unsigned int)&seg_ioc_base;
+    _word_extended_write( CLUSTER_IO, base + BLOCK_DEVICE_BUFFER*4,     (unsigned int)buffer );
+    _word_extended_write( CLUSTER_IO, base + BLOCK_DEVICE_BUFFER_EXT*4, ext );
+    _word_extended_write( CLUSTER_IO, base + BLOCK_DEVICE_COUNT*4,      count );
+    _word_extended_write( CLUSTER_IO, base + BLOCK_DEVICE_LBA*4,        lba );
+    _word_extended_write( CLUSTER_IO, base + BLOCK_DEVICE_IRQ_ENABLE*4, 1 );
+    _word_extended_write( CLUSTER_IO, base + BLOCK_DEVICE_OP*4,         BLOCK_DEVICE_READ );
+}
+
+in_drivers inline unsigned int _ioc_get_blocksize() {
+    const unsigned int base = (unsigned int)&seg_ioc_base;
+    return _word_extended_read( CLUSTER_IO, base + BLOCK_DEVICE_BLOCK_SIZE*4 );
 }
 
@@ -1102,18 +1019,8 @@
 in_drivers void _ioc_isr()
 {
-    if ( USE_EXT_IO )  // extended addressing to cluster_io
-    {
-        unsigned int    cluster = ((X_SIZE-1)<<Y_WIDTH) + Y_SIZE;
-        unsigned int    base    = (unsigned int)&seg_ioc_base;
-
-        _ioc_status = _word_extended_read( cluster, base + BLOCK_DEVICE_STATUS*4 );
-    }
-    else               // direct addressing to cluster(Ã ,0)
-    {
-        unsigned int* ioc = (unsigned int*)&seg_ioc_base;
-    
-        _ioc_status = ioc[BLOCK_DEVICE_STATUS];	// save status & reset IRQ
-    }
-    _ioc_done   = 1;	   // signals completion
+    unsigned int base = (unsigned int)&seg_ioc_base;
+
+    _ioc_status = _word_extended_read( CLUSTER_IO, base + BLOCK_DEVICE_STATUS*4 );
+    _ioc_done   = 1;       // signals completion
 }
 
@@ -1142,5 +1049,5 @@
     unsigned int  src_cluster = ext;
     unsigned int  dst_address = (unsigned int)&seg_fbf_base + offset;
-    unsigned int  dst_cluster = ((X_SIZE-1)<<Y_WIDTH) + Y_SIZE;  // cluster_xy for I/O
+    unsigned int  dst_cluster = (X_IO << Y_WIDTH) | Y_IO;  // cluster_xy for I/O
 
     _extended_memcpy( dst_cluster,
@@ -1167,5 +1074,5 @@
     unsigned int  dst_cluster = ext;
     unsigned int  src_address = (unsigned int)&seg_fbf_base + offset;
-    unsigned int  src_cluster = ((X_SIZE-1)<<Y_WIDTH) + Y_SIZE;  // cluster_xy for I/O
+    unsigned int  src_cluster = (X_IO << Y_WIDTH) | Y_IO;  // cluster_xy for I/O
 
     _extended_memcpy( dst_cluster,
@@ -1184,5 +1091,5 @@
 in_drivers void _mmc_isr()
 {
-    int*         mmc_address = (int*)&seg_mmc_base;
+    //int*         mmc_address = (int*)&seg_mmc_base;
     unsigned int cluster_xy  = _procid() / NB_PROCS_MAX;
     
@@ -1225,11 +1132,11 @@
 
     register int   delay = ((_proctime() +_procid()) & 0xF) << 4;
-    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
+    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  
-                  "sc   $3,    0(%0)       	\n" 	// try to set _locks_busy
+                  "sc   $3,    0(%0)        \n"     // try to set _locks_busy
                   "bnez $3,    _locks_ok    \n"     // exit if atomic 
                   "_locks_delay:            \n"
@@ -1239,5 +1146,5 @@
                   "beqz $4,    _locks_loop  \n"     // test end delay
                   "j           _locks_llsc  \n"     // retry
-                  "_locks_ok:			\n"
+                  "_locks_ok:           \n"
                   ::"r"(plock),"r"(delay):"$2","$3","$4");
 }
@@ -1255,8 +1162,7 @@
 in_drivers void _barrier_init(unsigned int index, unsigned int value)
 {
-
-    register int* pinit 	= (int*)&_barrier_value[index];
-    register int* pcount 	= (int*)&_barrier_count[index];
-    register int* plock  	= (int*)&_barrier_lock[index];
+    register int* pinit     = (int*)&_barrier_value[index];
+    register int* pcount    = (int*)&_barrier_count[index];
+    register int* plock     = (int*)&_barrier_lock[index];
 
     if ( index >= NB_BARRIERS )
@@ -1269,15 +1175,15 @@
 
     // parallel initialisation using atomic instructions LL/SC
-    asm volatile ("_barrier_init_test:          	\n"
-                  "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" 
-                  "sw   $3,	0(%1)			        \n"	// barrier_count <= barrier_value
+    asm volatile ("_barrier_init_test:              \n"
+                  "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" 
+                  "sw   $3, 0(%1)                   \n" // barrier_count <= barrier_value
                   "move $3, $0                      \n" // 
-                  "sw   $3,	0(%2)			        \n"	// barrier_lock <= 0
-                  "_barrier_init_done:			\n"
+                  "sw   $3, 0(%2)                   \n" // barrier_lock <= 0
+                  "_barrier_init_done:          \n"
                   ::"r"(pinit),"r"(pcount),"r"(plock),"r"(value):"$2","$3");
 }
@@ -1295,8 +1201,7 @@
 in_drivers void _barrier_wait(unsigned int index)
 {
-    register int* 	pcount 		= (int*)&_barrier_count[index];		
-    register int  	count;
-
-    int 	       lock 		= _barrier_lock[index];		
+    register int*   pcount      = (int*)&_barrier_count[index];     
+    register int    count;
+    int             lock        = _barrier_lock[index];     
 
     if ( index >= NB_BARRIERS )
@@ -1311,9 +1216,9 @@
     // input : pointer on _barrier_count[index]
     // output : count = _barrier_count[index] (before decrementation)
-    asm volatile ("_barrier_decrement:          		\n"
-                  "ll   %0,     0(%1)           		\n"
-                  "addi $3,     %0,     -1      		\n"
-                  "sc   $3,     0(%1)           		\n"
-                  "beqz $3,     _barrier_decrement		\n"
+    asm volatile ("_barrier_decrement:                  \n"
+                  "ll   %0,     0(%1)                   \n"
+                  "addi $3,     %0,     -1              \n"
+                  "sc   $3,     0(%1)                   \n"
+                  "beqz $3,     _barrier_decrement      \n"
                   :"=&r"(count)
                   :"r"(pcount)
@@ -1323,5 +1228,5 @@
     // and the barrier_lock variable, waking up all other waiting tasks
 
-    if ( count == 1 ) 	 // last task
+    if ( count == 1 )    // last task
     {
         _barrier_count[index] = _barrier_value[index];
@@ -1329,7 +1234,7 @@
         _barrier_lock[index]   = (lock == 0) ? 1 : 0;
     }
-    else 		// other tasks
-    {
-        while ( lock == _barrier_lock[index] ) 	asm volatile("nop");
+    else        // other tasks
+    {
+        while ( lock == _barrier_lock[index] );
     }
 } 
