Index: branches/reconfiguration/modules/dspin_router/caba/source/include/dspin_router.h
===================================================================
--- branches/reconfiguration/modules/dspin_router/caba/source/include/dspin_router.h	(revision 947)
+++ branches/reconfiguration/modules/dspin_router/caba/source/include/dspin_router.h	(revision 994)
@@ -84,7 +84,4 @@
     DspinOutput<flit_width>     *p_out;
 
-    // reconfiguration port
-    sc_in<uint32_t>             *p_recovery_cfg;
-
     // constructor / destructor
     DspinRouter( sc_module_name  name,
@@ -95,5 +92,6 @@
                  const size_t    in_fifo_depth,
                  const size_t    out_fifo_depth,
-                 const bool      broadcast_supported = false );
+                 const bool      broadcast_supported = false,
+                 const bool      configuration_supported = false );
 
     ~DspinRouter();
@@ -107,4 +105,8 @@
         bool                 eop;
     } internal_flit_t;
+
+    // reconfiguration port
+    // port binding is performed with the bind_recovery_port() function
+    sc_in<uint32_t>             *p_recovery_cfg;
 
     // registers
@@ -135,19 +137,15 @@
     void    transition();
     void    genMoore();
+
     int     xfirst_route( size_t xdest, size_t ydest );
+    int     recovery_route( size_t xdest, size_t ydest );
     int     route( sc_uint<flit_width> data );
+
     int     broadcast_route( int iter, int source, sc_uint<flit_width> data );
     bool    is_broadcast( sc_uint<flit_width> data );
+    sc_uint<flit_width> compute_broadcast_header( int source );
 
-    // fault-recovery methods
     bool    is_destination_blackhole( size_t xdest, size_t ydest, int bhpos );
-    int     recovery_route( size_t xdest, size_t ydest );
-
-    public:
-
-    inline void set_disable_mask( int mask )
-    {
-        m_disable_mask = mask;
-    }
+    int     blackhole_position();
 
     inline bool is_network_recovery_enable()
@@ -161,10 +159,17 @@
     }
 
-    inline int blackhole_position()
+    inline bool is_reconfigurable()
     {
-        return (p_recovery_cfg->read() & 0xF);
+        return (p_recovery_cfg != NULL);
     }
 
-    void bind_recovery_port( sc_core::sc_signal<uint32_t> &s );
+    public:
+
+    inline void set_disable_mask( int mask )
+    {
+        m_disable_mask = mask;
+    }
+
+    void bind_recovery_port(sc_signal<uint32_t> &s);
 
     void print_trace();
Index: branches/reconfiguration/modules/dspin_router/caba/source/src/dspin_router.cpp
===================================================================
--- branches/reconfiguration/modules/dspin_router/caba/source/src/dspin_router.cpp	(revision 947)
+++ branches/reconfiguration/modules/dspin_router/caba/source/src/dspin_router.cpp	(revision 994)
@@ -60,5 +60,6 @@
                              const size_t   in_fifo_depth,
                              const size_t   out_fifo_depth,
-                             const bool     broadcast_supported)
+                             const bool     broadcast_supported,
+                             const bool     configuration_supported)
     : soclib::caba::BaseModule(name),
 
@@ -67,4 +68,5 @@
       p_in( alloc_elems<DspinInput<flit_width> >("p_in", 5) ),
       p_out( alloc_elems<DspinOutput<flit_width> >("p_out", 5) ),
+      p_recovery_cfg(NULL),
 
       r_alloc_out( alloc_elems<sc_signal<bool> >("r_alloc_out", 5)),
@@ -116,5 +118,7 @@
         }
 
-        p_recovery_cfg = NULL;
+        if (configuration_supported) {
+            p_recovery_cfg = new sc_core::sc_in<uint32_t> ("p_recovery_cfg");
+        }
     } //  end constructor
 
@@ -122,5 +126,26 @@
     tmpl(/**/)::~DspinRouter()
     {
-        if ( p_recovery_cfg != NULL ) delete p_recovery_cfg;
+        if ( is_reconfigurable() ) delete p_recovery_cfg;
+    }
+
+    ///////////////////////////////////////////////////
+    tmpl(int)::blackhole_position()
+    {
+        if ( is_reconfigurable() ) {
+            return p_recovery_cfg->read() & 0xF;
+        }
+        return BH_NONE;
+    }
+
+    ///////////////////////////////////////////////////
+    tmpl(void)::bind_recovery_port(sc_signal<uint32_t> &s)
+    {
+        if (!is_reconfigurable()) {
+            std::cerr << "Error in " << name()
+                      << ": router configuration not supported." << std::endl
+                      << "Enable it during router instantiation." << std::endl;
+            exit(1);
+        }
+        (*p_recovery_cfg)(s);
     }
 
@@ -135,50 +160,42 @@
 
     ///////////////////////////////////////////////////
-    tmpl(void)::bind_recovery_port( sc_core::sc_signal<uint32_t> &s )
-    {
-        if (p_recovery_cfg == NULL) {
-            p_recovery_cfg = new sc_core::sc_in<uint32_t> ("p_recovery_cfg");
-        }
-        (*p_recovery_cfg)(s);
-    }
-
-    ///////////////////////////////////////////////////
     tmpl(bool)::is_destination_blackhole( size_t xdest, size_t ydest, int bhpos )
     {
         size_t xhole, yhole;
-        if (bhpos == BH_N) {
-            xhole = m_local_x;
-            yhole = m_local_y - 1;
-        }
-        else if (bhpos == BH_NW) {
-            xhole = m_local_x + 1;
-            yhole = m_local_y - 1;
-        }
-        else if (bhpos == BH_W) {
-            xhole = m_local_x + 1;
-            yhole = m_local_y;
-        }
-        else if (bhpos == BH_SW) {
-            xhole = m_local_x + 1;
-            yhole = m_local_y + 1;
-        }
-        else if (bhpos == BH_S) {
-            xhole = m_local_x;
-            yhole = m_local_y + 1;
-        }
-        else if (bhpos == BH_SE) {
-            xhole = m_local_x - 1;
-            yhole = m_local_y + 1;
-        }
-        else if (bhpos == BH_E) {
-            xhole = m_local_x - 1;
-            yhole = m_local_y;
-        }
-        else if (bhpos == BH_NE) {
-            xhole = m_local_x - 1;
-            yhole = m_local_y - 1;
-        }
-        else {
-            return false;
+        switch (bhpos) {
+            case BH_N:
+                xhole = m_local_x;
+                yhole = m_local_y - 1;
+                break;
+            case BH_NW:
+                xhole = m_local_x + 1;
+                yhole = m_local_y - 1;
+                break;
+            case BH_W:
+                xhole = m_local_x + 1;
+                yhole = m_local_y;
+                break;
+            case BH_SW:
+                xhole = m_local_x + 1;
+                yhole = m_local_y + 1;
+                break;
+            case BH_S:
+                xhole = m_local_x;
+                yhole = m_local_y + 1;
+                break;
+            case BH_SE:
+                xhole = m_local_x - 1;
+                yhole = m_local_y + 1;
+                break;
+            case BH_E:
+                xhole = m_local_x - 1;
+                yhole = m_local_y;
+                break;
+            case BH_NE:
+                xhole = m_local_x - 1;
+                yhole = m_local_y - 1;
+                break;
+            default:
+                return false;
         }
 
@@ -300,31 +317,28 @@
         size_t xdest = (size_t)(data >> m_x_shift) & m_x_mask;
         size_t ydest = (size_t)(data >> m_y_shift) & m_y_mask;
-        if ( p_recovery_cfg != NULL )
-        {
-            if (blackhole_position() != BH_NONE )
+        if ( blackhole_position() != BH_NONE )
+        {
+            // reroute the request if its destination is the blackhole (this
+            // is to implement the segment recovery mechanism)
+            if ( is_destination_blackhole(xdest, ydest, blackhole_position()) )
             {
-                // reroute the request if its destination is the blackhole (this
-                // is to implement the segment recovery mechanism)
-                if (is_destination_blackhole(xdest, ydest, blackhole_position()))
-                {
-                    int dir = migration_route();
+                int dir = migration_route();
 
 #if SOCLIB_MODULE_DEBUG
-                    std::cout << "<" << name() << "> migration: "
-                              << "route request to DIR = " << dir << std::endl;
+                std::cout << "<" << name() << "> migration: "
+                          << "route request to DIR = " << dir << std::endl;
 #endif
-                    return dir;
-                }
-
-                if (is_network_recovery_enable())
-                {
-                    int dir = recovery_route(xdest, ydest);
+                return dir;
+            }
+
+            if (is_network_recovery_enable())
+            {
+                int dir = recovery_route(xdest, ydest);
 
 #if SOCLIB_MODULE_DEBUG
-                    std::cout << "<" << name() << "> network recovery: "
-                              << "route request to DIR = " << dir << std::endl;
+                std::cout << "<" << name() << "> network recovery: "
+                          << "route request to DIR = " << dir << std::endl;
 #endif
-                    return dir;
-                }
+                return dir;
             }
         }
@@ -332,49 +346,115 @@
     }
 
-    //////////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////
     tmpl(int)::broadcast_route(int step, int source, sc_uint<flit_width> data)
     {
-        int    sel  = REQ_NOP;
-        size_t xmin = (data >> (flit_width - 5 )) & 0x1F;
-        size_t xmax = (data >> (flit_width - 10)) & 0x1F;
-        size_t ymin = (data >> (flit_width - 15)) & 0x1F;
-        size_t ymax = (data >> (flit_width - 20)) & 0x1F;
+        const size_t lx   = m_local_x;
+        const size_t ly   = m_local_y;
+        const size_t xmin = (data >> (flit_width - 5 )) & 0x1F;
+        const size_t xmax = (data >> (flit_width - 10)) & 0x1F;
+        const size_t ymin = (data >> (flit_width - 15)) & 0x1F;
+        const size_t ymax = (data >> (flit_width - 20)) & 0x1F;
+        const int    bh   = blackhole_position();
+        int  sel = REQ_NOP;
+        bool ew  = ((data & 0x2) != 0);
 
         switch(source) {
         case REQ_LOCAL :
-            if      ( step == 1 )   sel = REQ_NORTH;
-            else if ( step == 2 )   sel = REQ_SOUTH;
-            else if ( step == 3 )   sel = REQ_EAST;
-            else if ( step == 4 )   sel = REQ_WEST;
+            if      ( step == 1 ) sel = REQ_NORTH;
+            else if ( step == 2 ) sel = REQ_SOUTH;
+            else if ( step == 3 ) {
+                if ( (bh == BH_N) && (lx != 0) && (ly != 1) ) {
+                    sel = REQ_NOP;
+                    break;
+                }
+                sel = REQ_EAST;
+            }
+            else if ( step == 4 ) {
+                if ( (bh == BH_NE) && (lx != 1) && (ly != 1) ) {
+                    sel = REQ_NOP;
+                    break;
+                }
+                sel = REQ_WEST;
+            }
         break;
         case REQ_NORTH :
-            if      ( step == 1 )   sel = REQ_SOUTH;
-            else if ( step == 2 )   sel = REQ_LOCAL;
-            else if ( step == 3 )   sel = REQ_NOP;
-            else if ( step == 4 )   sel = REQ_NOP;
+            if      ( step == 1 ) sel = REQ_SOUTH;
+            else if ( step == 2 ) sel = REQ_LOCAL;
+            else if ( step == 3 ) {
+                if ( bh == BH_SW ) {
+                    sel = REQ_EAST;
+                    break;
+                }
+                sel = REQ_NOP;
+            }
+            else if ( step == 4 ) {
+                if ( (bh == BH_SE) && (ew || (lx == 1)) ) {
+                    sel = REQ_WEST;
+                    break;
+                }
+                sel = REQ_NOP;
+            }
         break;
         case REQ_SOUTH :
-            if      ( step == 1 )   sel = REQ_NORTH;
-            else if ( step == 2 )   sel = REQ_LOCAL;
-            else if ( step == 3 )   sel = REQ_NOP;
-            else if ( step == 4 )   sel = REQ_NOP;
+            if      ( step == 1 ) sel = REQ_NORTH;
+            else if ( step == 2 ) sel = REQ_LOCAL;
+            else if ( step == 3 ) {
+                if ( bh == BH_NW ) {
+                    sel = REQ_EAST;
+                    break;
+                }
+                if ( (bh == BH_NE) && ((lx == 1) || (ly == 1)) ) {
+                    sel = REQ_WEST;
+                    break;
+                }
+                sel = REQ_NOP;
+            }
+            else if ( step == 4 ) sel = REQ_NOP;
         break;
         case REQ_EAST :
-            if      ( step == 1 )   sel = REQ_WEST;
-            else if ( step == 2 )   sel = REQ_NORTH;
-            else if ( step == 3 )   sel = REQ_SOUTH;
-            else if ( step == 4 )   sel = REQ_LOCAL;
+            if ( step == 1 ) {
+                if ( (bh == BH_NE) && (lx != 1) && (ly != 1) ) {
+                    sel = REQ_NOP;
+                    break;
+                }
+                sel = REQ_WEST;
+            }
+            else if ( step == 2 ) sel = REQ_NORTH;
+            else if ( step == 3 ) sel = REQ_SOUTH;
+            else if ( step == 4 ) sel = REQ_LOCAL;
         break;
         case REQ_WEST :
-            if      ( step == 1 )   sel = REQ_EAST;
-            else if ( step == 2 )   sel = REQ_NORTH;
-            else if ( step == 3 )   sel = REQ_SOUTH;
-            else if ( step == 4 )   sel = REQ_LOCAL;
+            if ( step == 1 ) {
+                if ( (bh == BH_N) && (ly != 1) ) {
+                    sel = REQ_NOP;
+                    break;
+                }
+                if ( (bh == BH_S) && !ew ) {
+                    sel = REQ_NOP;
+                    break;
+                }
+                sel = REQ_EAST;
+            }
+            else if ( step == 2 ) sel = REQ_NORTH;
+            else if ( step == 3 ) sel = REQ_SOUTH;
+            else if ( step == 4 ) sel = REQ_LOCAL;
         break;
         }
-        if      ( (sel == REQ_NORTH) && !(m_local_y < ymax) )   sel = REQ_NOP;
-        else if ( (sel == REQ_SOUTH) && !(m_local_y > ymin) )   sel = REQ_NOP;
-        else if ( (sel == REQ_EAST ) && !(m_local_x < xmax) )   sel = REQ_NOP;
-        else if ( (sel == REQ_WEST ) && !(m_local_x > xmin) )   sel = REQ_NOP;
+
+        if      ( (sel == REQ_NORTH) && !(ly < ymax) ) sel = REQ_NOP;
+        else if ( (sel == REQ_SOUTH) && !(ly > ymin) ) sel = REQ_NOP;
+        else if ( (sel == REQ_EAST ) && !(lx < xmax) ) sel = REQ_NOP;
+        else if ( (sel == REQ_WEST ) && !(lx > xmin) ) sel = REQ_NOP;
+
+#if 0
+        /* This code can be used if we want to inhibit requests to the
+         * blackhole. However, it is not strictly necessary because the
+         * blackhole will consume the request and will do nothing with it */
+
+        if      ( (sel == REQ_NORTH) && (bh == BH_S) ) sel = REQ_NOP;
+        else if ( (sel == REQ_SOUTH) && (bh == BH_N) ) sel = REQ_NOP;
+        else if ( (sel == REQ_EAST ) && (bh == BH_W) ) sel = REQ_NOP;
+        else if ( (sel == REQ_WEST ) && (bh == BH_E) ) sel = REQ_NOP;
+#endif
 
         return sel;
@@ -382,7 +462,48 @@
 
     /////////////////////////////////////////////////////////
-    tmpl(inline bool)::is_broadcast(sc_uint<flit_width> data)
+    tmpl(bool)::is_broadcast(sc_uint<flit_width> data)
     {
         return ( (data & 0x1) != 0);
+    }
+
+    /////////////////////////////////////////////////////////
+    tmpl(sc_uint<flit_width>)::compute_broadcast_header(int source)
+    {
+        const int bh = blackhole_position();
+        sc_uint<flit_width> header = r_fifo_in[source].read().data;
+        sc_uint<flit_width> mask = 0x2;
+        switch (source) {
+            case REQ_LOCAL:
+                if ( bh != BH_NONE ) {
+                    header |= mask;
+                }
+                break;
+            case REQ_EAST:
+                if ( (bh == BH_NE) || (bh == BH_E) ) {
+                    header |= mask;
+                }
+                break;
+            case REQ_WEST:
+                if ( (bh == BH_NW) || (bh == BH_W) || (bh == BH_SW) ) {
+                    header |= mask;
+                }
+                break;
+
+            /* Make sure that the EW bit is not set when it shouldn't.
+             * This can arrive if an initiator or a local interconnect uses
+             * the broadcast header reserved bits internally and don't reset
+             * them */
+            case REQ_NORTH:
+                if ( (bh == BH_NW) || (bh == BH_N) || (bh == BH_NE) ) {
+                    header &= ~mask;
+                }
+                break;
+            case REQ_SOUTH:
+                if ( (bh == BH_SW) || (bh == BH_S) || (bh == BH_SE) ) {
+                    header &= ~mask;
+                }
+                break;
+        }
+        return header;
     }
 
@@ -414,5 +535,19 @@
         };
 
+        const char* bh_str[] =
+        {
+            "BH_NONE",
+            "BH_N",
+            "BH_NE",
+            "BH_E",
+            "BH_SE",
+            "BH_S",
+            "BH_SW",
+            "BH_W",
+            "BH_NW"
+        };
+
         std::cout << "DSPIN_ROUTER " << name();
+        std::cout << " / bh = " << bh_str[blackhole_position()];
 
         for( size_t i = 0 ; i < 5 ; i++)  // loop on input ports
@@ -517,7 +652,18 @@
                              m_broadcast_supported )          // broadcast
                         {
+                            if ( r_fifo_in[i].read().eop )
+                            {
+                                std::cout << "ERROR in DSPIN_ROUTER " << name()
+                                          << " : broadcast packet must be 2 flits" << std::endl;
+                                exit(1);
+                            }
+
+                            internal_flit_t header;
+                            header.eop  = false;
+                            header.data = compute_broadcast_header(i);
+
                             fifo_in_read[i] = true;
-                            req_in[i]       = broadcast_route(1, i, r_fifo_in[i].read().data);
-                            r_buf_in[i]     = r_fifo_in[i].read();
+                            req_in[i]       = broadcast_route(1, i, header.data);
+                            r_buf_in[i]     = header;
                             r_index_in[i]   = req_in[i];
                             if( req_in[i] == REQ_NOP ) r_fsm_in[i] = INFSM_REQ_SECOND;
