Index: /branches/MESI/communication/dspin_dhccp_param/caba/metadata/dspin_dhccp_param.sd
===================================================================
--- /branches/MESI/communication/dspin_dhccp_param/caba/metadata/dspin_dhccp_param.sd	(revision 670)
+++ /branches/MESI/communication/dspin_dhccp_param/caba/metadata/dspin_dhccp_param.sd	(revision 670)
@@ -0,0 +1,4 @@
+Module('caba:dspin_dhccp_param',
+	   classname = 'soclib::caba::DspinDhccpParam',
+	   header_files = ['../source/include/dspin_dhccp_param.h',]
+)
Index: /branches/MESI/communication/dspin_dhccp_param/caba/source/include/dspin_dhccp_param.h
===================================================================
--- /branches/MESI/communication/dspin_dhccp_param/caba/source/include/dspin_dhccp_param.h	(revision 670)
+++ /branches/MESI/communication/dspin_dhccp_param/caba/source/include/dspin_dhccp_param.h	(revision 670)
@@ -0,0 +1,430 @@
+/* -*- c++ -*-
+ * File         : dspin_dhccp_param.h
+ * Date         : 01/03/2013
+ * Copyright    : UPMC / LIP6
+ * Authors      : Cesar Fuguet
+ *
+ * SOCLIB_LGPL_HEADER_BEGIN
+ *
+ * This file is part of SoCLib, GNU LGPLv2.1.
+ *
+ * SoCLib is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 of the License.
+ *
+ * SoCLib is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with SoCLib; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ * SOCLIB_LGPL_HEADER_END
+ */
+
+
+#ifndef DSPIN_DHCCP_PARAMS_H
+#define DSPIN_DHCCP_PARAMS_H
+
+#include <inttypes.h>
+#include <assert.h>
+
+namespace soclib { namespace caba {
+
+/*
+ * L1 cache to Memory Cache command packets
+ *
+ * CLEANUP
+ *
+ * flit 1
+ * --------------------------------------------------------------------------------------------------------
+ * EOP:0 |    DEST    |   SRCID   | NLINE MSB(2 bits)| CONTAINS_DATA | WAY_INDEX(2 bits) | TYPE:0b1X | BC:0
+ *       |  (10 bits) | (14 bits) |                  |               |                   |           |
+ * --------------------------------------------------------------------------------------------------------
+ *                                                                                 | X: 0 DATA  |
+ *                                                                                 |    1 INST  |
+ * flit 2
+ * ----------------------------------------------------------------------------------------------
+ * EOP:0/1 |                                                                       NLINE(32 bits)
+ * ----------------------------------------------------------------------------------------------
+ *
+ * flit N for data
+ * ----------------------------------------------------------------------------------------------
+ * EOP:0/1 |                                                                       WDATA(32 bits)
+ * ----------------------------------------------------------------------------------------------
+ *
+ * MULTICAST ACKNOWLEDGEMENT
+ *
+ * flit 1
+ * ----------------------------------------------------------------------------------------------
+ * EOP:1 |     DEST(10 bits)     |       X(15 bits)       | UPDT_INDEX(4 bits) | TYPE:0b00 | BC:0
+ * ----------------------------------------------------------------------------------------------
+ */
+
+/*
+ * M2P command packets
+ *
+ * MULTICAST UPDATE
+ *
+ * flit 1
+ * ----------------------------------------------------------------------------------------------
+ * EOP:0 | DEST(14 bits) | X(4 bits) | MEMC_ID(14 bits) | UPDT_INDEX(4 bits) | TYPE:0b0X   | BC:0
+ * ----------------------------------------------------------------------------------------------
+ *                                                                           | X: 0 DATA   |
+ *                                                                           |    1 INST   |
+ * flit 2
+ * ----------------------------------------------------------------------------------------------
+ * EOP:0 | X | WORD_INDEX(4 bits)  |                                             NLINE (34 bits)
+ * ----------------------------------------------------------------------------------------------
+ *
+ * flit 3
+ * ----------------------------------------------------------------------------------------------
+ * EOP:0 | X(3 bits)  | BE(4 bits) |                                              WDATA(32 bits)
+ * ----------------------------------------------------------------------------------------------
+ *
+ * flit N
+ * ----------------------------------------------------------------------------------------------
+ * EOP:1 | X(3 bits)  | BE(4 bits) |                                              WDATA(32 bits)
+ * ----------------------------------------------------------------------------------------------
+ *
+ * MULTICAST INVALIDATE
+ *
+ * flit 1
+ * ------------------------------------------------------------------------------------------------------------------
+ * EOP:0 | DEST(14 bits) | X (3 bits) | IS_CONFIG (1 bit) | MEMC_ID(14 bits) | UPDT_INDEX(4 bits) | TYPE:0b1X  | BC:0
+ * ------------------------------------------------------------------------------------------------------------------
+ *                                                                                                | X: 0 DATA  |
+ *                                                                                                |    1 INST  |
+ * flit 2
+ * ----------------------------------------------------------------------------------------------
+ * EOP:1 | X(5 bits) |                                                           NLINE (34 bits)
+ * ----------------------------------------------------------------------------------------------
+ *
+ * BROADCAST INVALIDATE
+ *
+ * flit 1
+ *       | BOUNDING BOX(20 bits)            |
+ * ----------------------------------------------------------------------------------------------
+ * EOP:0 | XMIN   | XMAX   | YMIN   | YMAX  | MEMC_ID(14 bits) | NETWORK_RESERVED(4 bits) | BC:1
+ * ----------------------------------------------------------------------------------------------
+ *
+ * flit 2
+ * ----------------------------------------------------------------------------------------------
+ * EOP:1 |        X(5 bits)       |                                              NLINE (34 bits)
+ * ----------------------------------------------------------------------------------------------
+ *
+ * M2P clack commands
+ *
+ * CLEANUP ACKNOWLEDGEMENT
+ *
+ * flit 1
+ * ----------------------------------------------------------------------------------------------
+ * EOP:1 | DEST(14 bits) | X(5 bits) | SET_INDEX(16 bits) | WAY_INDEX(2 bits) | TYPE:0bX   | BC:0
+ * ----------------------------------------------------------------------------------------------
+ *                                                                            | X: 0 CLACK |
+ *                                                                            |      DATA  |
+ *                                                                            |    1 CLACK |
+ *                                                                            |      INST  |
+ *
+ */
+
+/*
+ * Utility MACROS
+ */
+#define GET_FIELD(x,y)\
+    case y: return ((x >> y##_SHIFT) & y##_MASK)
+
+#define SET_FIELD(x,y,z)\
+    case z: x |= ((y & z##_MASK) << z##_SHIFT);break
+
+class DspinDhccpParam
+{
+  public:
+
+    static const uint8_t  m2p_flit_width               = 40;
+    static const uint8_t  p2m_flit_width               = 33;
+    static const uint8_t  clack_flit_width             = 40;
+
+    static const uint8_t  UPDT_INDEX_WIDTH             = 4;
+    static const uint8_t  NLINE_WIDTH                  = 34;
+    static const uint8_t  SRCID_WIDTH                  = 14;
+    static const uint8_t  GLOBALID_WIDTH               = 10;
+    static const uint8_t  WORD_INDEX_WIDTH             = 4;
+    static const uint8_t  BE_WIDTH                     = 4;
+    static const uint8_t  DATA_WIDTH                   = 32;
+    static const uint8_t  SET_INDEX_WIDTH              = 6;
+    static const uint8_t  WAY_INDEX_WIDTH              = 2;
+    static const uint8_t  BROADCAST_BOX_WIDTH          = 20;
+    static const uint8_t  M2P_TYPE_WIDTH               = 2;
+    static const uint8_t  P2M_TYPE_WIDTH               = 2;
+    static const uint8_t  CLACK_TYPE_WIDTH             = 1;
+
+    static const uint8_t  P2M_TYPE_SHIFT               = 1;
+    static const uint64_t P2M_TYPE_MASK                = ((1ULL<<P2M_TYPE_WIDTH)-1);
+    static const uint8_t  P2M_EOP_SHIFT                = 32;
+    static const uint64_t P2M_EOP_MASK                 = 1;
+    static const uint8_t  P2M_BC_SHIFT                 = 0;
+    static const uint64_t P2M_BC_MASK                  = 1;
+
+    static const uint8_t  CLEANUP_DEST_SHIFT           = 22;
+    static const uint64_t CLEANUP_DEST_MASK            = ((1ULL<<GLOBALID_WIDTH)-1);
+    static const uint8_t  CLEANUP_SRCID_SHIFT          = 8;
+    static const uint64_t CLEANUP_SRCID_MASK           = ((1ULL<<SRCID_WIDTH)-1);
+    static const uint8_t  CLEANUP_NLINE_MSB_SHIFT      = 6;
+    static const uint64_t CLEANUP_NLINE_MSB_MASK       = ((1ULL<< 2)-1);
+    static const uint8_t  CLEANUP_WAY_INDEX_SHIFT      = 3;
+    static const uint64_t CLEANUP_WAY_INDEX_MASK       = ((1ULL<<WAY_INDEX_WIDTH)-1);
+    static const uint8_t  CLEANUP_NLINE_LSB_SHIFT      = 0;
+    static const uint64_t CLEANUP_NLINE_LSB_MASK       = ((1ULL<<32)-1);
+    static const uint8_t  CLEANUP_DATA_UPDT_SHIFT      = 0;
+    static const uint64_t CLEANUP_DATA_UPDT_MASK       = ((1ULL<<32)-1);
+    static const uint8_t  DATA_NO_SHARED_SHIFT         = 5;
+    static const uint64_t DATA_NO_SHARED_MASK          = 1;
+
+    static const uint8_t  MULTI_ACK_DEST_SHIFT         = CLEANUP_DEST_SHIFT;
+    static const uint64_t MULTI_ACK_DEST_MASK          = CLEANUP_DEST_MASK;
+    static const uint8_t  MULTI_ACK_UPDT_INDEX_SHIFT   = 3;
+    static const uint64_t MULTI_ACK_UPDT_INDEX_MASK    = ((1ULL<<UPDT_INDEX_WIDTH)-1);
+    
+    static const uint8_t  MULTI_ACK_UPDT_MISS_SHIFT    = 8;
+    static const uint64_t MULTI_ACK_UPDT_MISS_MASK     = 1;
+
+    static const uint8_t  M2P_TYPE_SHIFT               = 1;
+    static const uint64_t M2P_TYPE_MASK                = ((1ULL<<M2P_TYPE_WIDTH)-1);
+    static const uint8_t  M2P_EOP_SHIFT                = 39;
+    static const uint64_t M2P_EOP_MASK                 = 1;
+    static const uint8_t  M2P_BC_SHIFT                 = 0;
+    static const uint64_t M2P_BC_MASK                  = 1;
+
+    static const uint8_t  MULTI_INVAL_DEST_SHIFT       = 25;
+    static const uint64_t MULTI_INVAL_DEST_MASK        = ((1ULL<<SRCID_WIDTH)-1);
+    static const uint8_t  MULTI_INVAL_SRCID_SHIFT      = 7;
+    static const uint64_t MULTI_INVAL_SRCID_MASK       = ((1ULL<<SRCID_WIDTH)-1);
+    static const uint8_t  MULTI_INVAL_UPDT_INDEX_SHIFT = 3;
+    static const uint64_t MULTI_INVAL_UPDT_INDEX_MASK  = ((1ULL<<UPDT_INDEX_WIDTH)-1);
+    static const uint8_t  MULTI_INVAL_NLINE_SHIFT      = 0;
+    static const uint64_t MULTI_INVAL_NLINE_MASK       = ((1ULL<<NLINE_WIDTH)-1);
+    static const uint8_t  MULTI_INVAL_IS_CONFIG_SHIFT  = 21;
+    static const uint64_t MULTI_INVAL_IS_CONFIG_MASK   = 1;
+
+    static const uint8_t  MULTI_UPDT_DEST_SHIFT        = MULTI_INVAL_DEST_SHIFT;
+    static const uint64_t MULTI_UPDT_DEST_MASK         = MULTI_INVAL_DEST_MASK;
+    static const uint8_t  MULTI_UPDT_SRCID_SHIFT       = MULTI_INVAL_SRCID_SHIFT;
+    static const uint64_t MULTI_UPDT_SRCID_MASK        = MULTI_INVAL_SRCID_MASK;
+    static const uint8_t  CC_UPDT_IVT_INDEX_SHIFT  = MULTI_INVAL_UPDT_INDEX_SHIFT;
+    static const uint64_t CC_UPDT_IVT_INDEX_MASK   = MULTI_INVAL_UPDT_INDEX_MASK;
+    static const uint8_t  MULTI_UPDT_WORD_INDEX_SHIFT  = 34;
+    static const uint64_t MULTI_UPDT_WORD_INDEX_MASK   = ((1ULL<<WORD_INDEX_WIDTH)-1);
+    static const uint8_t  MULTI_UPDT_NLINE_SHIFT       = MULTI_INVAL_NLINE_SHIFT;
+    static const uint64_t MULTI_UPDT_NLINE_MASK        = MULTI_INVAL_NLINE_MASK;
+    static const uint8_t  MULTI_UPDT_BE_SHIFT          = 32;
+    static const uint64_t MULTI_UPDT_BE_MASK           = ((1ULL<<BE_WIDTH)-1);
+    static const uint8_t  MULTI_UPDT_DATA_SHIFT        = 0;
+    static const uint64_t MULTI_UPDT_DATA_MASK         = ((1ULL<<DATA_WIDTH)-1);
+
+    static const uint8_t  BROADCAST_BOX_SHIFT          = 19;
+    static const uint64_t BROADCAST_BOX_MASK           = ((1ULL<<BROADCAST_BOX_WIDTH)-1);
+    static const uint8_t  BROADCAST_SRCID_SHIFT        = 5;
+    static const uint64_t BROADCAST_SRCID_MASK         = MULTI_INVAL_SRCID_MASK;
+    static const uint8_t  BROADCAST_NLINE_SHIFT        = 0;
+    static const uint64_t BROADCAST_NLINE_MASK         = MULTI_INVAL_NLINE_MASK;
+
+    static const uint8_t  CLACK_TYPE_SHIFT             = 1;
+    static const uint64_t CLACK_TYPE_MASK              = ((1ULL<<CLACK_TYPE_WIDTH)-1);
+    static const uint8_t  CLACK_EOP_SHIFT              = 39;
+    static const uint64_t CLACK_EOP_MASK               = 1;
+    static const uint8_t  CLACK_BC_SHIFT               = 0;
+    static const uint64_t CLACK_BC_MASK                = 1;
+    static const uint8_t  CLACK_DEST_SHIFT             = 25;
+    static const uint64_t CLACK_DEST_MASK              = ((1ULL<<SRCID_WIDTH)-1);
+    static const uint8_t  CLACK_SET_SHIFT              = 4;
+    static const uint64_t CLACK_SET_MASK               = ((1ULL<<SET_INDEX_WIDTH)-1);
+    static const uint8_t  CLACK_WAY_SHIFT              = 2;
+    static const uint64_t CLACK_WAY_MASK               = ((1ULL<<WAY_INDEX_WIDTH)-1);
+
+    /*
+     * P2M command types
+     */
+    enum
+    {
+      TYPE_MULTI_ACK        = 0,
+      TYPE_CLEANUP_DATA     = 2,
+      TYPE_CLEANUP_INST     = 3
+    };
+
+    /*
+     * M2P command types
+     */
+    enum
+    {
+      TYPE_MULTI_UPDT       = 0,
+      TYPE_MULTI_UPDT_DATA  = TYPE_MULTI_UPDT,
+      TYPE_MULTI_UPDT_INST  = 1,
+      TYPE_MULTI_INVAL      = 2,
+      TYPE_MULTI_INVAL_DATA = TYPE_MULTI_INVAL,
+      TYPE_MULTI_INVAL_INST = 3
+    };
+
+    /*
+     * CLACK command types
+     */
+    enum
+    {
+      TYPE_CLACK      = 0,
+      TYPE_CLACK_DATA = TYPE_CLACK,
+      TYPE_CLACK_INST = 1
+    };
+
+    enum flit_field_e
+    {
+      P2M_TYPE,
+      P2M_EOP,
+      P2M_BC,
+
+      CLEANUP_DEST,
+      CLEANUP_SRCID,
+      CLEANUP_NLINE_MSB,
+      CLEANUP_WAY_INDEX,
+      CLEANUP_NLINE_LSB,
+      CLEANUP_DATA_UPDT,
+      DATA_NO_SHARED,
+
+      MULTI_ACK_DEST,
+      MULTI_ACK_UPDT_INDEX,
+      MULTI_ACK_UPDT_MISS,
+
+      M2P_TYPE,
+      M2P_EOP,
+      M2P_BC,
+
+      MULTI_INVAL_DEST,
+      MULTI_INVAL_SRCID,
+      MULTI_INVAL_UPDT_INDEX,
+      MULTI_INVAL_NLINE,
+      MULTI_INVAL_IS_CONFIG,
+
+      MULTI_UPDT_DEST,
+      MULTI_UPDT_SRCID,
+      CC_UPDT_IVT_INDEX,
+      MULTI_UPDT_WORD_INDEX,
+      MULTI_UPDT_NLINE,
+      MULTI_UPDT_BE,
+      MULTI_UPDT_DATA,
+
+      CLACK_TYPE,
+
+      CLACK_DEST,
+      CLACK_SET,
+      CLACK_WAY,
+
+      BROADCAST_BOX,
+      BROADCAST_SRCID,
+      BROADCAST_NLINE
+    };
+
+    static uint64_t dspin_get(uint64_t flit, flit_field_e field)
+    {
+      switch(field)
+      {
+        GET_FIELD(flit,P2M_TYPE);
+        GET_FIELD(flit,P2M_EOP);
+        GET_FIELD(flit,P2M_BC);
+        GET_FIELD(flit,CLEANUP_DEST);
+        GET_FIELD(flit,CLEANUP_SRCID);
+        GET_FIELD(flit,CLEANUP_NLINE_MSB);
+        GET_FIELD(flit,CLEANUP_WAY_INDEX);
+        GET_FIELD(flit,CLEANUP_NLINE_LSB);
+        GET_FIELD(flit,CLEANUP_DATA_UPDT);
+        GET_FIELD(flit,DATA_NO_SHARED);
+        GET_FIELD(flit,MULTI_ACK_DEST);
+        GET_FIELD(flit,MULTI_ACK_UPDT_INDEX);
+        GET_FIELD(flit,MULTI_ACK_UPDT_MISS);
+        GET_FIELD(flit,M2P_TYPE);
+        GET_FIELD(flit,M2P_EOP);
+        GET_FIELD(flit,M2P_BC);
+        GET_FIELD(flit,MULTI_INVAL_DEST);
+        GET_FIELD(flit,MULTI_INVAL_SRCID);
+        GET_FIELD(flit,MULTI_INVAL_UPDT_INDEX);
+        GET_FIELD(flit,MULTI_INVAL_NLINE);
+        GET_FIELD(flit,MULTI_INVAL_IS_CONFIG);
+        GET_FIELD(flit,MULTI_UPDT_DEST);
+        GET_FIELD(flit,MULTI_UPDT_SRCID);
+        GET_FIELD(flit,CC_UPDT_IVT_INDEX);
+        GET_FIELD(flit,MULTI_UPDT_WORD_INDEX);
+        GET_FIELD(flit,MULTI_UPDT_NLINE);
+        GET_FIELD(flit,MULTI_UPDT_BE);
+        GET_FIELD(flit,MULTI_UPDT_DATA);
+        GET_FIELD(flit,CLACK_TYPE);
+        GET_FIELD(flit,CLACK_DEST);
+        GET_FIELD(flit,CLACK_SET);
+        GET_FIELD(flit,CLACK_WAY);
+        GET_FIELD(flit,BROADCAST_BOX);
+        GET_FIELD(flit,BROADCAST_SRCID);
+        GET_FIELD(flit,BROADCAST_NLINE);
+
+        default: assert(false && "Incorrect DHCCP DSPIN field");
+      }
+    }
+
+    static void dspin_set(uint64_t &flit, uint64_t value, flit_field_e field)
+    {
+      switch(field)
+      {
+        SET_FIELD(flit,value,P2M_TYPE);
+        SET_FIELD(flit,value,P2M_EOP);
+        SET_FIELD(flit,value,P2M_BC);
+        SET_FIELD(flit,value,CLEANUP_DEST);
+        SET_FIELD(flit,value,CLEANUP_SRCID);
+        SET_FIELD(flit,value,CLEANUP_NLINE_MSB);
+        SET_FIELD(flit,value,CLEANUP_WAY_INDEX);
+        SET_FIELD(flit,value,CLEANUP_NLINE_LSB);
+        SET_FIELD(flit,value,CLEANUP_DATA_UPDT);
+        SET_FIELD(flit,value,DATA_NO_SHARED);
+        SET_FIELD(flit,value,MULTI_ACK_DEST);
+        SET_FIELD(flit,value,MULTI_ACK_UPDT_INDEX);
+        SET_FIELD(flit,value,MULTI_ACK_UPDT_MISS);
+        SET_FIELD(flit,value,M2P_TYPE);
+        SET_FIELD(flit,value,M2P_EOP);
+        SET_FIELD(flit,value,M2P_BC);
+        SET_FIELD(flit,value,MULTI_INVAL_DEST);
+        SET_FIELD(flit,value,MULTI_INVAL_SRCID);
+        SET_FIELD(flit,value,MULTI_INVAL_UPDT_INDEX);
+        SET_FIELD(flit,value,MULTI_INVAL_NLINE);
+        SET_FIELD(flit,value,MULTI_INVAL_IS_CONFIG);
+        SET_FIELD(flit,value,MULTI_UPDT_DEST);
+        SET_FIELD(flit,value,MULTI_UPDT_SRCID);
+        SET_FIELD(flit,value,CC_UPDT_IVT_INDEX);
+        SET_FIELD(flit,value,MULTI_UPDT_WORD_INDEX);
+        SET_FIELD(flit,value,MULTI_UPDT_NLINE);
+        SET_FIELD(flit,value,MULTI_UPDT_BE);
+        SET_FIELD(flit,value,MULTI_UPDT_DATA);
+        SET_FIELD(flit,value,CLACK_TYPE);
+        SET_FIELD(flit,value,CLACK_DEST);
+        SET_FIELD(flit,value,CLACK_SET);
+        SET_FIELD(flit,value,CLACK_WAY);
+        SET_FIELD(flit,value,BROADCAST_BOX);
+        SET_FIELD(flit,value,BROADCAST_SRCID);
+        SET_FIELD(flit,value,BROADCAST_NLINE);
+
+        default: assert(false && "Incorrect DHCCP DSPIN field");
+      }
+    }
+};
+
+#undef GET_FIELD
+#undef SET_FIELD
+
+}} // end namespace soclib::caba
+
+#endif
+// Local Variables:
+// tab-width: 2
+// c-basic-offset: 2
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=2:tabstop=2:softtabstop=2
Index: /branches/MESI/lib/generic_cache_tsar/include/generic_cache.h
===================================================================
--- /branches/MESI/lib/generic_cache_tsar/include/generic_cache.h	(revision 670)
+++ /branches/MESI/lib/generic_cache_tsar/include/generic_cache.h	(revision 670)
@@ -0,0 +1,852 @@
+/* -*- c++ -*-
+ *
+ * SOCLIB_LGPL_HEADER_BEGIN
+ *
+ * This file is part of SoCLib, GNU LGPLv2.1.
+ *
+ * SoCLib is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 of the License.
+ *
+ * SoCLib is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with SoCLib; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ * SOCLIB_LGPL_HEADER_END
+ *
+ * Copyright (c) UPMC, Lip6
+ *         Alain Greiner <alain.greiner@lip6.fr> July 2008
+ *
+ * Maintainers: alain
+ */
+
+////////////////////////////////////////////////////////////////////////////////
+// File         : generic_cache.h
+// Date         : 07/01/2012
+// Authors      : Alain Greiner
+/////////////////////////////////////////////////////////////////////////////////
+// This object is a generic, set associative, cache.
+// Each slot can be in three states: VALID, EMPTY or ZOMBI.
+// The ZOMBI state is used by cache coherence protocols to indicate
+// a pending cleanup request.
+// Hit if ( (matching tag) and (state == VALID).
+// The replacement policy is pseudo-LRU. The victim selection process cannot
+// fail if the ZOMBI state is not used. 
+// But it can fail if all ways are in ZOMBI state.
+/////////////////////////////////////////////////////////////////////////////////
+// Implementation note
+// The DATA part is implemented as an uint32_t array[nways*nsets*nwords].
+// The DIRECTORY part is implemented as an uint32_t array[nways*nsets].
+// All methods requiring a dual port RAM or cache modification using
+// an associative search have been deprecated.
+/////////////////////////////////////////////////////////////////////////////////
+// Constructor parameters are :
+// - std::string    &name
+// - size_t         nways   : number of associativity levels 
+// - size_t         nsets   : number of sets
+// - size_t         nwords  : number of words in a cache line
+// The nways, nsets, nwords parameters must be power of 2
+// The nsets parameter cannot be larger than 1024
+// The nways parameter cannot be larger than 16
+// The nwords parameter cannot be larger than 64
+/////////////////////////////////////////////////////////////////////////////////
+// Template parameter is :
+// - addr_t : address format to access the cache 
+/////////////////////////////////////////////////////////////////////////////////
+
+#ifndef SOCLIB_GENERIC_CACHE_H
+#define SOCLIB_GENERIC_CACHE_H
+
+#include <systemc>
+#include <cassert>
+#include "arithmetics.h"
+#include "static_assert.h"
+#include "mapping_table.h"
+#include <cstring>
+
+namespace soclib { 
+
+enum cache_slot_state_e
+{
+    CACHE_SLOT_STATE_INVALID,
+    CACHE_SLOT_STATE_EXCLUSIVE,
+    CACHE_SLOT_STATE_SHARED,
+    CACHE_SLOT_STATE_MODIFIED,
+    CACHE_SLOT_STATE_ZOMBI
+};
+
+//////////////////////////
+template<typename addr_t>
+class GenericCache 
+//////////////////////////
+{
+    typedef uint32_t    data_t;
+    typedef uint32_t    be_t;
+
+    data_t              *r_data ;
+    addr_t               *r_tag ;
+    int                 *r_state;
+    bool                *r_lru ;
+
+    size_t              m_ways;	
+    size_t              m_sets;	
+    size_t              m_words;
+
+    const soclib::common::AddressMaskingTable<addr_t>  m_x ;
+    const soclib::common::AddressMaskingTable<addr_t>  m_y ;
+    const soclib::common::AddressMaskingTable<addr_t>  m_z ;
+
+    //////////////////////////////////////////////////////////////
+    inline data_t &cache_data(size_t way, size_t set, size_t word)
+    {
+        return r_data[(way*m_sets*m_words)+(set*m_words)+word];
+    }
+
+    //////////////////////////////////////////////
+    inline addr_t &cache_tag(size_t way, size_t set)
+    {
+        return r_tag[(way*m_sets)+set];
+    }
+
+    //////////////////////////////////////////////
+    inline bool &cache_lru(size_t way, size_t set)
+    {
+        return r_lru[(way*m_sets)+set];
+    }
+    
+    //////////////////////////////////////////////
+    inline int &cache_state(size_t way, size_t set)
+    {
+        return r_state[(way*m_sets)+set];
+    }
+
+    
+    /////////////////////////////////////////////////
+    inline void cache_set_lru(size_t way, size_t set)
+    {
+	    size_t way2;
+
+        cache_lru(way, set) = true;
+
+	    for (way2 = 0; way2 < m_ways; way2++ ) 
+        {
+	        if (cache_lru(way2, set) == false) return;
+	    }
+ 	    // all lines are new -> they all become old 
+	    for (way2 = 0; way2 < m_ways; way2++ ) 
+        {
+	        cache_lru(way2, set) = false;
+	    }
+    }
+
+    ////////////////////////////////
+    inline data_t be2mask( be_t be )
+    {
+        data_t mask = 0;
+        if ( (be & 0x1) == 0x1 ) mask = mask | 0x000000FF;
+        if ( (be & 0x2) == 0x2 ) mask = mask | 0x0000FF00;
+        if ( (be & 0x4) == 0x4 ) mask = mask | 0x00FF0000;
+        if ( (be & 0x8) == 0x8 ) mask = mask | 0xFF000000;
+        return mask;
+    }
+
+public:
+
+    //////////////////////////////////////////
+    GenericCache(   const std::string   &name,
+                    size_t              nways, 
+                    size_t              nsets, 
+                    size_t              nwords)
+        : m_ways(nways),
+          m_sets(nsets),
+          m_words(nwords),
+
+#define l2 soclib::common::uint32_log2
+
+          m_x( l2(nwords), l2(sizeof(data_t))),
+          m_y( l2(nsets), l2(nwords) + l2(sizeof(data_t))),
+          m_z( 8*sizeof(addr_t) - l2(nsets) - l2(nwords) - l2(sizeof(data_t)),
+               l2(nsets) + l2(nwords) + l2(sizeof(data_t)))
+#undef l2
+    {
+        assert(IS_POW_OF_2(nways));
+        assert(IS_POW_OF_2(nsets));
+        assert(IS_POW_OF_2(nwords));
+        assert(nwords);
+        assert(nsets);
+        assert(nways);
+        assert(nwords <= 64);
+        assert(nsets <= 1024);
+        assert(nways <= 16);
+
+#ifdef GENERIC_CACHE_DEBUG
+std::cout << "constructing " << name << std::endl
+          << "- nways  = " << nways << std::endl
+          << "- nsets  = " << nsets << std::endl
+          << "- nwords = " << nwords << std::endl
+          << " m_x: " << m_x 
+          << " m_y: " << m_y
+          << " m_z: " << m_z
+          << std::endl;
+#endif
+
+        r_data    = new data_t[nways*nsets*nwords];
+        r_tag     = new addr_t[nways*nsets];
+        r_state   = new int[nways*nsets];
+        r_lru     = new bool[nways*nsets];
+    }
+
+    ////////////////
+    ~GenericCache()
+    {
+        delete [] r_data;
+        delete [] r_tag;
+        delete [] r_state;
+        delete [] r_lru;
+    }
+
+    ////////////////////
+    inline void reset( )
+    {
+        std::memset(r_data, 0, sizeof(*r_data)*m_ways*m_sets*m_words);
+        std::memset(r_tag, 0, sizeof(*r_tag)*m_ways*m_sets);
+        std::memset(r_state, CACHE_SLOT_STATE_INVALID, sizeof(*r_state)*m_ways*m_sets);
+        std::memset(r_lru, 0, sizeof(*r_lru)*m_ways*m_sets);
+    }
+
+    inline int get_cache_state(int way, int set)
+    {
+        return cache_state(way,set);
+    }
+    
+    /////////////////////////////////////////////////////////////////////
+    // Read a single 32 bits word.
+    // returns true if (matching tag) and (state == VALID) 
+    // Both data & directory are accessed. 
+    /////////////////////////////////////////////////////////////////////
+    inline bool read( addr_t 	ad, 
+                      data_t* 	dt)
+    {
+        const addr_t      tag  = m_z[ad];
+        const size_t      set  = m_y[ad];
+        const size_t      word = m_x[ad];
+
+        for ( size_t way = 0; way < m_ways; way++ ) 
+        {
+            if ( (tag == cache_tag(way, set))  
+                   && ( (cache_state(way, set) == CACHE_SLOT_STATE_EXCLUSIVE) or (cache_state(way, set) == CACHE_SLOT_STATE_MODIFIED) or (cache_state(way, set) == CACHE_SLOT_STATE_SHARED)) )
+            {
+                *dt = cache_data(way, set, word);
+                cache_set_lru(way, set);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    ////////////////////////////////////////////////////////////////////
+    // Read a single 32 bits word.
+    // returns true if (matching tag) and (state == VALID) 
+    // Both data & directory are accessed. 
+    // The selected way, set and word index are returned in case of hit.
+    /////////////////////////////////////////////////////////////////////
+    inline bool read( addr_t 	ad, 
+                      data_t* 	dt,
+                      size_t*   selway,
+                      size_t*   selset,
+                      size_t*   selword) 
+    {
+        const addr_t      tag  = m_z[ad];
+        const size_t      set  = m_y[ad];
+        const size_t      word = m_x[ad];
+
+        for ( size_t way = 0; way < m_ways; way++ ) 
+        {
+            if ( (tag == cache_tag(way, set)) and
+                 ( (cache_state(way, set) == CACHE_SLOT_STATE_EXCLUSIVE) or (cache_state(way, set) == CACHE_SLOT_STATE_MODIFIED) or (cache_state(way, set) == CACHE_SLOT_STATE_SHARED)) )
+            {
+                *selway  = way;
+                *selset  = set;
+                *selword = word;
+                *dt = cache_data(way, set, word);
+                cache_set_lru(way, set);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    ////////////////////////////////////////////////////////////////////
+    // Read a single 32 bits word when the ZOMBI state is used.
+    // Both data and directory are accessed.
+    // returns the access status in the state argument:
+    // - VALID : (matching tag) and (state == VALID) 
+    // - ZOMBI : (matching tag) and (state == ZOMBI) 
+    // - MISS  : no matching tag or EMPTY state
+    // If VALID or ZOMBI, the data, the way, set and word index are 
+    // returned in the other arguments.
+    ////////////////////////////////////////////////////////////////////
+    inline void read( addr_t    ad,
+                      data_t*   dt,
+                      size_t*   selway,
+                      size_t*   selset,
+                      size_t*   selword,
+                      int*      state ) 
+    {
+        const addr_t      tag  = m_z[ad];
+        const size_t      set  = m_y[ad];
+        const size_t      word = m_x[ad];
+
+        // default return values 
+        *state   = CACHE_SLOT_STATE_INVALID;
+        *selway  = 0;
+        *selset  = 0;
+        *selword = 0;
+        *dt      = 0;
+
+        for ( size_t way = 0; way < m_ways; way++ ) 
+        {
+            if ( tag == cache_tag(way, set) )  // matching tag
+            {
+
+                if ( cache_state(way, set) == CACHE_SLOT_STATE_EXCLUSIVE )
+                {
+                    *state   = CACHE_SLOT_STATE_EXCLUSIVE;
+                    *selway  = way;
+                    *selset  = set;
+                    *selword = word;
+                    *dt      = cache_data(way, set, word);
+                    cache_set_lru(way, set);
+                }
+                else if ( cache_state(way, set) == CACHE_SLOT_STATE_SHARED )
+                {
+                    *state   = CACHE_SLOT_STATE_SHARED;
+                    *selway  = way;
+                    *selset  = set;
+                    *selword = word;
+                    *dt      = cache_data(way, set, word);
+                    cache_set_lru(way, set);
+                }
+                else if ( cache_state(way, set) == CACHE_SLOT_STATE_MODIFIED )
+                {
+                    *state   = CACHE_SLOT_STATE_MODIFIED;
+                    *selway  = way;
+                    *selset  = set;
+                    *selword = word;
+                    *dt      = cache_data(way, set, word);
+                    cache_set_lru(way, set);
+                }
+                else if ( cache_state(way, set) == CACHE_SLOT_STATE_ZOMBI )
+                {
+                    *state   = CACHE_SLOT_STATE_ZOMBI;
+                    *selway  = way;
+                    *selset  = set;
+                    *selword = word;
+                }
+            }
+        }
+    }
+              
+    ////////////////////////////////////////////////////////////////////
+    // Read a single 32 bits word, without LRU update.
+    // returns true if (matching tag) and (state == VALID) 
+    // Both data & directory are accessed. 
+    // The selected way, set and word index are returned in case of hit.
+    /////////////////////////////////////////////////////////////////////
+    inline bool read_neutral( addr_t 	ad, 
+	            		      data_t* 	dt,
+			                  size_t*   selway,
+			                  size_t*   selset,
+			                  size_t*   selword) 
+    {
+        const addr_t      tag  = m_z[ad];
+        const size_t      set  = m_y[ad];
+        const size_t      word = m_x[ad];
+
+        for ( size_t way = 0; way < m_ways; way++ ) 
+        {
+            if ( (tag == cache_tag(way, set))  
+                   && ( (cache_state(way, set) == CACHE_SLOT_STATE_EXCLUSIVE) or (cache_state(way, set) == CACHE_SLOT_STATE_MODIFIED) or (cache_state(way, set) == CACHE_SLOT_STATE_SHARED)) )
+            {
+                *selway  = way;
+                *selset  = set;
+                *selword = word;
+                *dt = cache_data(way, set, word);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /////////////////////////////////////////////////////////////////////////////
+    // Read one or two 32 bits word.
+    // Both data & directory are accessed. 
+    // Hit if (matching tag) and (valid == true) and (zombi == false) 
+    // If the addressed word is not the last in the cache line,
+    // two successive words are returned.
+    // The selected way, set and first word index are returned in case of hit.
+    // This function is used by the cc_vcache to get a 64 bits page table entry.
+    /////////////////////////////////////////////////////////////////////////////
+    inline bool read( addr_t 	ad, 
+                      data_t* 	dt, 
+                      data_t*	dt_next,
+                      size_t*	selway,
+                      size_t*	selset,
+                      size_t*   selword)
+    {
+        const addr_t      tag  = m_z[ad];
+        const size_t      set  = m_y[ad];
+        const size_t      word = m_x[ad];
+
+        for ( size_t way = 0; way < m_ways; way++ ) 
+        {
+            if ( (tag == cache_tag(way, set))   
+                   && ( (cache_state(way, set) == CACHE_SLOT_STATE_EXCLUSIVE) or (cache_state(way, set) == CACHE_SLOT_STATE_MODIFIED) or (cache_state(way, set) == CACHE_SLOT_STATE_SHARED)) )
+            {
+                *dt      = cache_data(way, set, word);
+                if ( word+1 < m_words) 
+                {
+                    *dt_next = cache_data(way, set, word+1);
+                }
+                *selway  = way;
+                *selset  = set;
+                *selword = word;
+                cache_set_lru(way, set);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    ////////////////////////////////////////////////////////////////////
+    // Read one or two 32 bits word.
+    // Both data and directory are accessed.
+    // returns the access status in the state argument:
+    // - VALID : (matching tag) and (state == VALID) 
+    // - ZOMBI : (matching tag) and (state == ZOMBI) 
+    // - MISS  : no matching tag or EMPTY state
+    // If VALID or ZOMBI, the data, the way, set and word index are 
+    // returned in the other arguments.
+    ////////////////////////////////////////////////////////////////////
+    inline void read( addr_t    ad,
+                      data_t*   dt,
+                      data_t*   dt_next,
+                      size_t*   selway,
+                      size_t*   selset,
+                      size_t*   selword,
+                      int*      state ) 
+    {
+        const addr_t      tag  = m_z[ad];
+        const size_t      set  = m_y[ad];
+        const size_t      word = m_x[ad];
+
+        // default return values 
+        *state   = CACHE_SLOT_STATE_INVALID;
+        *selway  = 0;
+        *selset  = 0;
+        *selword = 0;
+        *dt      = 0;
+
+        for ( size_t way = 0; way < m_ways; way++ ) 
+        {
+            if ( tag == cache_tag(way, set) )  // matching tag
+            {
+
+                if ( cache_state(way, set) == CACHE_SLOT_STATE_EXCLUSIVE )
+                {
+                    *state   = CACHE_SLOT_STATE_EXCLUSIVE;
+                    *selway  = way;
+                    *selset  = set;
+                    *selword = word;
+                    *dt      = cache_data(way, set, word);
+                    if ( word+1 < m_words) 
+                    {
+                        *dt_next = cache_data(way, set, word+1);
+                    }
+                    cache_set_lru(way, set);
+                }
+
+                else if ( cache_state(way, set) == CACHE_SLOT_STATE_SHARED )
+                {
+                    *state   = CACHE_SLOT_STATE_SHARED;
+                    *selway  = way;
+                    *selset  = set;
+                    *selword = word;
+                    *dt      = cache_data(way, set, word);
+                    if ( word+1 < m_words) 
+                    {
+                        *dt_next = cache_data(way, set, word+1);
+                    }
+                    cache_set_lru(way, set);
+                }
+
+                else if ( cache_state(way, set) == CACHE_SLOT_STATE_MODIFIED )
+                {
+                    *state   = CACHE_SLOT_STATE_MODIFIED;
+                    *selway  = way;
+                    *selset  = set;
+                    *selword = word;
+                    *dt      = cache_data(way, set, word);
+                    if ( word+1 < m_words) 
+                    {
+                        *dt_next = cache_data(way, set, word+1);
+                    }
+                    cache_set_lru(way, set);
+                }
+
+                else if ( cache_state(way, set) == CACHE_SLOT_STATE_ZOMBI )
+                {
+                    *state   = CACHE_SLOT_STATE_ZOMBI;
+                    *selway  = way;
+                    *selset  = set;
+                    *selword = word;
+                }
+            }
+        }
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////
+    // Checks the cache state for a given address.
+    // Only the directory is accessed. 
+    // returns true if (matching tag) and (state == VALID) 
+    // The selected way, set and first word index are returned in case of hit.
+    // This function can be used when we need to access the directory
+    // while we write in the data part with a different address in the same cycle.
+    ///////////////////////////////////////////////////////////////////////////////
+    inline bool hit(  addr_t 	ad, 
+                      size_t*	selway,
+                      size_t*	selset,
+                      size_t*   selword)
+    {
+        const addr_t      tag  = m_z[ad];
+        const size_t      set  = m_y[ad];
+        const size_t      word = m_x[ad];
+
+        for ( size_t way = 0; way < m_ways; way++ ) 
+        {
+            if ( (tag == cache_tag(way, set)) 
+                   && ( (cache_state(way, set) == CACHE_SLOT_STATE_EXCLUSIVE) or (cache_state(way, set) == CACHE_SLOT_STATE_MODIFIED) or (cache_state(way, set) == CACHE_SLOT_STATE_SHARED)) )
+            {
+                *selway  = way;
+                *selset  = set;
+                *selword = word;
+                cache_set_lru(way, set);
+                return true;
+            }
+        }
+        return false;
+    }
+  
+    ///////////////////////////////////////////////////////////////////////////////
+    // Checks the cache state for a given address, when the ZOMBI state is used.
+    // Only the directory is accessed. 
+    // Returns the access status in the state argument:
+    // - VALID if (matching tag) and (state == VALID) 
+    // - ZOMBI if (matching tag) and (state == ZOMBI) 
+    // - EMPTY if no match or (state == EMPTY)
+    // The selected way, set and first word index are returned if not empty.
+    // This function can be used when we need to access the directory
+    // while we write in the data part with a different address in the same cycle.
+    ///////////////////////////////////////////////////////////////////////////////
+    inline void read_dir(  addr_t 	ad, 
+                           int*     state,
+                           size_t*	way,
+                           size_t*	set,
+                           size_t*  word)
+    {
+        const addr_t      ad_tag  = m_z[ad];
+        const size_t      ad_set  = m_y[ad];
+        const size_t      ad_word = m_x[ad];
+        for ( size_t _way = 0; _way < m_ways; _way++ ) 
+        {
+            if ( (ad_tag == cache_tag(_way, ad_set) ) and 
+                 (cache_state(_way, ad_set) != CACHE_SLOT_STATE_INVALID) ) 
+            {
+                *state = cache_state(_way, ad_set);
+                *way   = _way;
+                *set   = ad_set;
+                *word  = ad_word;
+                return;
+            }
+        }
+        
+        // return value if not (VALID or ZOMBI)
+        *state = CACHE_SLOT_STATE_INVALID;
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////
+    // Checks the cache state for a slot (set,way), when the ZOMBI state is used.
+    // Only the directory is accessed. 
+    // Returns the access status and the tag value in the state and tag argument.
+    ///////////////////////////////////////////////////////////////////////////////
+    inline void read_dir(  size_t 	way,
+                           size_t 	set,
+                           addr_t*   tag,
+                           int*     state )
+    {
+        *state = cache_state(way, set);
+        *tag   = cache_tag(way, set);
+    }
+
+    ////////////////////////////////////////////
+    inline addr_t get_tag(size_t way, size_t set)
+    {
+        return cache_tag(way, set);
+    }
+
+    ///////////////////////////////////////////////////////////////////
+    // This function writes a complete 32 bits word
+    // It does not use the directory and cannot miss.
+    //////////////////////////////////////////////////////////////////
+    inline void write(size_t 	way, 
+                      size_t 	set, 
+                      size_t 	word, 
+                      data_t 	data)
+    {
+       /**/ //std::cout << "write cache : way = "<<way<<" | set = "<<set<<" | word = "<<word<<" | data = "<<(uint32_t)data << std::endl;
+        cache_data(way, set, word) = data;
+        cache_set_lru(way, set);
+    }
+
+    ////////////////////////////////////////////////////////////////////////////
+    // this function writes up to 4 bytes, taking into account the byte enable.
+    // It does not use the directory and cannot miss.
+    ////////////////////////////////////////////////////////////////////////////
+    inline void write(size_t 	way, 
+                      size_t 	set, 
+                      size_t 	word, 
+                      data_t 	data, 
+                      be_t 	    be)
+    {
+        data_t mask = be2mask(be);
+        data_t prev = cache_data(way, set, word);
+        cache_data(way, set, word) = (mask & data) | (~mask & prev);
+        cache_set_lru(way, set);
+    }
+
+    //////////////////////////////////////////////////////////////////////////
+    // This function invalidates a cache line identified by the set and way.
+    // It returns true if the line was valid, and returns the line index.
+    //////////////////////////////////////////////////////////////////////////
+    inline bool inval(size_t 	way, 
+                      size_t 	set, 
+                      addr_t* 	nline)
+    {
+        if( (cache_state(way,set) == CACHE_SLOT_STATE_EXCLUSIVE) or  (cache_state(way,set) == CACHE_SLOT_STATE_MODIFIED) or (cache_state(way,set) == CACHE_SLOT_STATE_SHARED))
+        {
+            cache_state(way,set) = CACHE_SLOT_STATE_INVALID;
+            *nline = (data_t)cache_tag(way,set)* m_sets + set;
+            return true;
+        }
+        return false;
+    }
+
+    //////////////////////////////////////////////////////////////////////////////////
+    // This function selects a victim slot in an associative set.
+    // It cannot fail, as a slot in ZOMBI state is considered EMPTY.
+    // - we search first an EMPTY slot 
+    // - if no EMPTY slot, we search an OLD slot, using lru
+    // It returns the line index (Z + Y fields), the selected slot way and set, 
+    // and a Boolean indicating that a cleanup is requested.
+    //////////////////////////////////////////////////////////////////////////////////
+    inline bool victim_select(addr_t 	ad, 
+                              addr_t* 	victim, 
+                              size_t*   way, 
+                              size_t*   set)
+    {
+        bool   found   = false;
+        bool   cleanup = false;
+
+        *set = m_y[ad];
+        *way = 0;
+
+        // Search first empty slot 
+        for ( size_t _way = 0 ; _way < m_ways && !found ; _way++ )
+        {
+            if( ( cache_state(_way, *set) != CACHE_SLOT_STATE_EXCLUSIVE ) and ( cache_state(_way, *set) != CACHE_SLOT_STATE_SHARED ) and ( cache_state(_way, *set) != CACHE_SLOT_STATE_MODIFIED ))  // empty
+            {
+                found   = true;
+                cleanup = false;
+                *way    = _way;
+            }
+        }
+
+        // If no empty slot, search first  old slot (lru == false) 
+        if ( !found )
+        { 
+            for ( size_t _way = 0 ; _way < m_ways && !found ; _way++ )
+            {
+                if ( not cache_lru(_way, *set) )
+                {
+                    found   = true;
+                    cleanup = true;
+                    *way    = _way;
+                }
+            }
+        }
+
+        assert(found && "all ways can't be new at the same time");
+        *victim = (addr_t)((cache_tag(*way,*set) * m_sets) + *set);
+        return cleanup;
+    }
+
+    //////////////////////////////////////////////////////////////////////////////////
+    // This function selects a victim slot in an associative set.
+    // It can fail if all ways are in ZOMBI state.
+    // - we search first an EMPTY slot
+    // - if no empty slot, we search an OLD slot not in ZOMBI state,
+    // - if not found, we take the first not ZOMBI slot.
+    // It returns the line index (Z + Y fields), the selected slot way and set, 
+    // and two Boolean indicating success and a required cleanup.
+    //////////////////////////////////////////////////////////////////////////////////
+    inline void read_select(addr_t 	  ad, 
+                            addr_t*   victim, 
+                            size_t*   way, 
+                            size_t*   set,
+                            bool*     found,
+                            bool*     cleanup )
+    {
+        size_t _set = m_y[ad];
+
+        *found = false;
+
+        // Search first empty slot 
+        for ( size_t _way = 0 ; _way < m_ways && !(*found) ; _way++ )
+        {
+            if ( cache_state(_way, _set) == CACHE_SLOT_STATE_INVALID )
+            {
+                *found   = true;
+                *cleanup = false;
+                *way     = _way;
+                *set     = m_y[ad];
+                return;
+            }
+        }
+        //////////////////////////////////////////////////////////////
+        /*for ( size_t _way = 0 ; _way < m_ways && !(*found) ; _way++ )
+        {
+            if ( not cache_lru(_way, _set) and 
+                 (cache_state(_way, _set) != CACHE_SLOT_STATE_ZOMBI) and
+                 (cache_state(_way, _set) == CACHE_SLOT_STATE_VALID_NCC) )
+            {
+                *found   = true;
+                *cleanup = true;
+                *way     = _way;
+                *set     = m_y[ad];
+                *victim  = (addr_t)((cache_tag(*way,_set) * m_sets) + _set);
+                return;
+            }
+        }*/
+        // Search first not zombi old slot 
+        for ( size_t _way = 0 ; _way < m_ways && !(*found) ; _way++ )
+        {
+            if ( not cache_lru(_way, _set) and 
+                 (cache_state(_way, _set) != CACHE_SLOT_STATE_ZOMBI) )
+            {
+                *found   = true;
+                *cleanup = true;
+                *way     = _way;
+                *set     = m_y[ad];
+                *victim  = cache_tag(*way,_set) * m_sets + _set;
+                return;
+            }
+        }
+        // Search first not zombi slot
+        for ( size_t _way = 0 ; _way < m_ways && !(*found) ; _way++ )
+        {
+            if ( cache_state(_way, _set) != CACHE_SLOT_STATE_ZOMBI) 
+            {
+                *found   = true;
+                *cleanup = true;
+                *way    = _way;
+                *set     = m_y[ad];
+                *victim  = cache_tag(*way,_set) * m_sets + _set;
+                return;
+            }
+        }
+
+        // no slot found...
+        *found   = false;
+        *cleanup = false;
+    }
+
+    //////////////////////////////////////////////////////////////////
+    // This function write the directory part of a slot
+    // identified by the way & set, when using the ZOMBI state.
+    //////////////////////////////////////////////////////////////////
+    inline void write_dir( addr_t 	ad, 
+                           size_t 	way, 
+                           size_t 	set,
+                           int      state)
+    {
+        addr_t  tag     = m_z[ad];
+
+        assert( ( (state == CACHE_SLOT_STATE_EXCLUSIVE) or
+                  (state == CACHE_SLOT_STATE_SHARED) or
+                  (state == CACHE_SLOT_STATE_MODIFIED) or
+                  (state == CACHE_SLOT_STATE_INVALID) or
+                  (state == CACHE_SLOT_STATE_ZOMBI)) and
+        "illegal slot state argument in Generic Cache write_dir()");
+
+        assert( (way < m_ways) and
+        "too large way index argument in Generic Cache write_dir()");
+
+        assert( (set < m_sets) and
+        "too large set index argument in Generic Cache write_dir()");
+
+        cache_tag(way, set)   = tag;
+        cache_state(way, set) = state;
+
+        if ( (state == CACHE_SLOT_STATE_EXCLUSIVE) or (state == CACHE_SLOT_STATE_MODIFIED) or (state == CACHE_SLOT_STATE_SHARED) ) cache_set_lru(way, set);
+    }
+
+    //////////////////////////////////////////////////////////////////
+    // This function change the state of a slot
+    // identified by the way & set, when using the ZOMBI state.
+    // It does not affect the tag
+    //////////////////////////////////////////////////////////////////
+    inline void write_dir( size_t 	way, 
+                           size_t 	set,
+                           int      state)
+    {
+        assert( ( (state == CACHE_SLOT_STATE_EXCLUSIVE) or
+                  (state == CACHE_SLOT_STATE_SHARED) or
+                  (state == CACHE_SLOT_STATE_MODIFIED) or
+                  (state == CACHE_SLOT_STATE_INVALID) or
+                  (state == CACHE_SLOT_STATE_ZOMBI)) and
+        "illegal slot state argument in Generic Cache write_dir()");
+
+        assert( (way < m_ways) and
+        "too large way index argument in Generic Cache write_dir()");
+
+        assert( (set < m_sets) and
+        "too large set index argument in Generic Cache write_dir()");
+
+        cache_state(way, set) = state;
+
+        if ( (state == CACHE_SLOT_STATE_EXCLUSIVE) or (state == CACHE_SLOT_STATE_MODIFIED) or (state == CACHE_SLOT_STATE_SHARED) ) cache_set_lru(way, set);
+
+    }
+
+    
+};
+
+} // namespace soclib
+
+#endif
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: /branches/MESI/lib/generic_cache_tsar/metadata/generic_cache.sd
===================================================================
--- /branches/MESI/lib/generic_cache_tsar/metadata/generic_cache.sd	(revision 670)
+++ /branches/MESI/lib/generic_cache_tsar/metadata/generic_cache.sd	(revision 670)
@@ -0,0 +1,15 @@
+
+# -*- python -*-
+
+__version__ = "$Revision: 917 $"
+
+Module('caba:generic_cache_tsar',
+	classname = 'soclib::GenericCache',
+	header_files = ['../include/generic_cache.h',],
+	   tmpl_parameters = [
+	parameter.Type('addr_t'),
+	],
+	uses = [Uses('common:mapping_table'),
+			Uses('common:address_masking_table',
+				 data_t = parameter.Reference('addr_t')),],
+)
Index: /branches/MESI/modules/vci_cc_vcache_wrapper/caba/metadata/vci_cc_vcache_wrapper.sd
===================================================================
--- /branches/MESI/modules/vci_cc_vcache_wrapper/caba/metadata/vci_cc_vcache_wrapper.sd	(revision 670)
+++ /branches/MESI/modules/vci_cc_vcache_wrapper/caba/metadata/vci_cc_vcache_wrapper.sd	(revision 670)
@@ -0,0 +1,73 @@
+
+# -*- python -*-
+
+Module('caba:vci_cc_vcache_wrapper',
+	    classname = 'soclib::caba::VciCcVCacheWrapper',
+
+	    tmpl_parameters = [
+            parameter.Module('vci_param', default = 'caba:vci_param'),
+            parameter.Int('dspin_in_width'),
+            parameter.Int('dspin_out_width'),
+	        parameter.Module('iss_t')
+        ],
+
+	    header_files = [ '../source/include/vci_cc_vcache_wrapper.h' ],
+
+	    implementation_files = [ '../source/src/vci_cc_vcache_wrapper.cpp' ],
+
+	    uses = [
+            Uses('caba:base_module'),
+            Uses('common:mapping_table'),
+	        Uses('common:iss2'),
+	        Uses('caba:multi_write_buffer'),
+	        Uses('caba:generic_fifo'),
+	        Uses('caba:generic_cache_tsar',
+                addr_t = parameter.StringExt('sc_dt::sc_uint<%d> ', 
+                parameter.Reference('addr_size'))),
+            Uses('caba:generic_tlb', 
+                addr_t = parameter.StringExt('sc_dt::sc_uint<%d> ', 
+                parameter.Reference('addr_size'))),
+            Uses('common:address_masking_table', 
+                data_t = parameter.StringExt('sc_dt::sc_uint<%d> ', 
+                parameter.Reference('addr_size'))
+            ),
+			Uses('caba:dspin_dhccp_param'),
+        ],
+
+	    ports = [
+            Port('caba:vci_initiator', 'p_vci'),
+            Port('caba:dspin_input', 'p_dspin_m2p', 
+                  dspin_data_size = parameter.Reference('dspin_in_width')),
+            Port('caba:dspin_output', 'p_dspin_p2m', 
+                  dspin_data_size = parameter.Reference('dspin_out_width')),
+            Port('caba:dspin_input', 'p_dspin_clack', 
+                  dspin_data_size = parameter.Reference('dspin_in_width')),
+	        Port('caba:bit_in','p_irq', parameter.Constant('n_irq')),
+	        Port('caba:bit_in', 'p_resetn', auto = 'resetn'),
+	        Port('caba:clock_in', 'p_clk', auto = 'clock')
+        ],
+
+	    instance_parameters = [
+            parameter.Int('proc_id'),
+	        parameter.Module('mt', 'common:mapping_table'),
+	        parameter.Module('mc', 'common:mapping_table'),
+	        parameter.IntTab('initiator_rw_index'),
+	        parameter.IntTab('initiator_c_index'),
+	        parameter.IntTab('target_index'),
+    	    parameter.Int('itlb_ways'),
+    	    parameter.Int('itlb_sets'),
+    	    parameter.Int('dtlb_ways'),
+    	    parameter.Int('dtlb_sets'),
+    	    parameter.Int('icache_ways'),
+    	    parameter.Int('icache_sets'),
+    	    parameter.Int('icache_words'),
+    	    parameter.Int('dcache_ways'),
+    	    parameter.Int('dcache_sets'),
+    	    parameter.Int('dcache_words'),
+    	    parameter.Int('wbuf_nlines'),
+    	    parameter.Int('wbuf_nwords'),
+    	    parameter.Int('max_frozen_cycles')
+        ],
+)
+
+
Index: /branches/MESI/modules/vci_cc_vcache_wrapper/caba/source/include/vci_cc_vcache_wrapper.h
===================================================================
--- /branches/MESI/modules/vci_cc_vcache_wrapper/caba/source/include/vci_cc_vcache_wrapper.h	(revision 670)
+++ /branches/MESI/modules/vci_cc_vcache_wrapper/caba/source/include/vci_cc_vcache_wrapper.h	(revision 670)
@@ -0,0 +1,848 @@
+/* -*- c++ -*-
+ *
+ * File : vci_cc_vcache_wrapper.h
+ * Copyright (c) UPMC, Lip6, SoC
+ * Authors : Alain GREINER, Yang GAO
+ * Date : 27/11/2011
+ *
+ * SOCLIB_LGPL_HEADER_BEGIN
+ *
+ * This file is part of SoCLib, GNU LGPLv2.1.
+ *
+ * SoCLib is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 of the License.
+ *
+ * SoCLib is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with SoCLib; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ * SOCLIB_LGPL_HEADER_END
+ *
+ * Maintainers: cesar.fuguet-tortolero@lip6.fr
+ *              alexandre.joannou@lip6.fr
+ */
+
+#ifndef SOCLIB_CABA_VCI_CC_VCACHE_WRAPPER_H
+#define SOCLIB_CABA_VCI_CC_VCACHE_WRAPPER_H
+
+#include <inttypes.h>
+#include <systemc>
+#include "caba_base_module.h"
+#include "multi_write_buffer.h"
+#include "generic_fifo.h"
+#include "generic_tlb.h"
+#include "generic_cache.h"
+#include "vci_initiator.h"
+#include "dspin_interface.h"
+#include "dspin_dhccp_param.h"
+#include "mapping_table.h"
+#include "static_assert.h"
+#include "iss2.h"
+
+#define LLSC_TIMEOUT    10000
+
+namespace soclib {
+namespace caba {
+
+using namespace sc_core;
+
+////////////////////////////////////////////
+template<typename vci_param, 
+         size_t   dspin_in_width,
+         size_t   dspin_out_width,
+         typename iss_t>
+class VciCcVCacheWrapper
+////////////////////////////////////////////
+    : public soclib::caba::BaseModule
+{
+
+    typedef typename vci_param::fast_addr_t  paddr_t;
+
+    enum icache_fsm_state_e 
+    {
+        ICACHE_IDLE,
+        // handling XTN processor requests
+        ICACHE_XTN_TLB_FLUSH,
+        ICACHE_XTN_CACHE_FLUSH,
+        ICACHE_XTN_CACHE_FLUSH_GO,
+        ICACHE_XTN_TLB_INVAL,
+        ICACHE_XTN_CACHE_INVAL_VA,
+        ICACHE_XTN_CACHE_INVAL_PA,
+        ICACHE_XTN_CACHE_INVAL_GO,
+        // handling tlb miss
+        ICACHE_TLB_WAIT,
+        // handling cache miss
+        ICACHE_MISS_SELECT,
+        ICACHE_MISS_CLEAN,
+        ICACHE_MISS_WAIT,
+        ICACHE_MISS_DATA_UPDT,
+        ICACHE_MISS_DIR_UPDT,
+        // handling unc read
+        ICACHE_UNC_WAIT,
+        // handling coherence requests
+        ICACHE_CC_CHECK,
+        ICACHE_CC_UPDT,
+        ICACHE_CC_INVAL,
+    };
+
+    enum dcache_fsm_state_e 
+    {
+        DCACHE_IDLE,
+        // handling itlb & dtlb miss
+        DCACHE_TLB_MISS,
+        DCACHE_TLB_PTE1_GET,
+        DCACHE_TLB_PTE1_SELECT,
+        DCACHE_TLB_PTE1_UPDT,
+        DCACHE_TLB_PTE2_GET,
+        DCACHE_TLB_PTE2_SELECT,
+        DCACHE_TLB_PTE2_UPDT,
+        DCACHE_TLB_LR_UPDT,
+        DCACHE_TLB_LR_WAIT,
+        DCACHE_TLB_RETURN,
+	    // handling processor XTN requests
+        DCACHE_XTN_SWITCH,
+        DCACHE_XTN_SYNC,
+        DCACHE_XTN_IC_INVAL_VA,
+        DCACHE_XTN_IC_FLUSH,
+        DCACHE_XTN_IC_INVAL_PA,
+        DCACHE_XTN_IT_INVAL,
+        DCACHE_XTN_DC_FLUSH,
+        DCACHE_XTN_DC_FLUSH_DATA,
+        DCACHE_XTN_DC_FLUSH_GO,
+        DCACHE_XTN_DC_INVAL_VA,
+        DCACHE_XTN_DC_INVAL_PA,
+        DCACHE_XTN_DC_INVAL_END,
+        DCACHE_XTN_DC_INVAL_GO,
+        DCACHE_XTN_DC_INVAL_DATA,
+        DCACHE_XTN_DT_INVAL,
+        //handling dirty bit update
+        DCACHE_DIRTY_GET_PTE,
+        DCACHE_DIRTY_WAIT,
+	    // handling processor miss requests
+        DCACHE_MISS_SELECT,
+        DCACHE_MISS_CLEAN,
+        DCACHE_MISS_DATA,
+        DCACHE_MISS_WAIT,
+        DCACHE_MISS_DATA_UPDT,
+        DCACHE_MISS_DIR_UPDT,
+        // handling processor unc, ll and sc requests
+        DCACHE_UNC_WAIT,
+        DCACHE_LL_WAIT,
+        DCACHE_SC_WAIT,
+        // handling coherence requests
+        DCACHE_CC_CHECK,
+        DCACHE_CC_UPDT,
+        DCACHE_CC_INVAL,
+        DCACHE_CC_SEND_DATA,
+        // handling TLB inval (after a coherence or XTN request)
+        DCACHE_INVAL_TLB_SCAN,
+    };
+
+    enum cmd_fsm_state_e 
+    {
+        CMD_IDLE,
+        CMD_INS_MISS,
+        CMD_INS_UNC,
+        CMD_DATA_MISS,
+        CMD_DATA_UNC_READ,
+        CMD_DATA_UNC_WRITE,
+        CMD_DATA_LL,
+        CMD_DATA_SC,
+        CMD_DATA_CAS,
+    };
+
+    enum rsp_fsm_state_e 
+    {
+        RSP_IDLE,
+        RSP_INS_MISS,
+        RSP_INS_UNC,
+        RSP_DATA_MISS,
+        RSP_DATA_UNC,
+        RSP_DATA_LL,
+        RSP_DATA_WRITE,
+    };
+
+    enum cc_receive_fsm_state_e 
+    {
+        CC_RECEIVE_IDLE,
+        CC_RECEIVE_BRDCAST_HEADER,
+        CC_RECEIVE_BRDCAST_NLINE,
+        CC_RECEIVE_INS_INVAL_HEADER,
+        CC_RECEIVE_INS_INVAL_NLINE,
+        CC_RECEIVE_INS_UPDT_HEADER,
+        CC_RECEIVE_INS_UPDT_NLINE,
+        CC_RECEIVE_DATA_INVAL_HEADER,
+        CC_RECEIVE_DATA_INVAL_NLINE,
+        CC_RECEIVE_DATA_UPDT_HEADER,
+        CC_RECEIVE_DATA_UPDT_NLINE,
+    };
+
+    enum cc_send_fsm_state_e 
+    {
+        CC_SEND_IDLE,
+        CC_SEND_CLEANUP_1,
+        CC_SEND_CLEANUP_2,
+        CC_SEND_DATA_UPDT,
+        CC_SEND_MULTI_ACK_HEADER
+    };
+
+    /* transaction type, pktid field */
+    enum transaction_type_e
+    {
+        // b3 unused
+        // b2 READ / NOT READ
+        // if READ
+        //  b1 DATA / INS
+        //  b0 UNC / MISS
+        // else
+        //  b1 accÃšs table llsc type SW / other
+        //  b2 WRITE/CAS/LL/SC
+        TYPE_DATA_UNC               = 0x0,
+        TYPE_READ_DATA_MISS         = 0x1,
+        TYPE_READ_INS_UNC           = 0x2,
+        TYPE_READ_INS_MISS          = 0x3,
+        TYPE_WRITE                  = 0x4,
+        TYPE_CAS                    = 0x5,
+        TYPE_LL                     = 0x6,
+        TYPE_SC                     = 0x7
+    };
+
+    /* SC return values */
+    enum sc_status_type_e
+    {
+        SC_SUCCESS  =   0x00000000,
+        SC_FAIL     =   0x00000001
+    };
+
+    // cc_send_type
+    typedef enum 
+    {
+        CC_TYPE_CLEANUP,
+        CC_TYPE_MULTI_ACK,
+    } cc_send_t;
+
+    // cc_receive_type
+    typedef enum 
+    {
+        CC_TYPE_CLACK,
+        CC_TYPE_BRDCAST,
+        CC_TYPE_INVAL,
+        CC_TYPE_UPDT,
+    } cc_receive_t;
+
+    // TLB Mode : ITLB / DTLB / ICACHE / DCACHE
+    enum 
+    {
+        INS_TLB_MASK    = 0x8,
+        DATA_TLB_MASK   = 0x4,
+        INS_CACHE_MASK  = 0x2,
+        DATA_CACHE_MASK = 0x1,
+    };
+
+    // Error Type
+    enum mmu_error_type_e
+    {
+        MMU_NONE                      = 0x0000, // None
+        MMU_WRITE_PT1_UNMAPPED 	      = 0x0001, // Write & Page fault on PT1
+        MMU_WRITE_PT2_UNMAPPED 	      = 0x0002, // Write & Page fault on PT2
+        MMU_WRITE_PRIVILEGE_VIOLATION = 0x0004, // Write & Protected access in user mode
+        MMU_WRITE_ACCES_VIOLATION     = 0x0008, // Write to non writable page
+        MMU_WRITE_UNDEFINED_XTN       = 0x0020, // Write & undefined external access
+        MMU_WRITE_PT1_ILLEGAL_ACCESS  = 0x0040, // Write & Bus Error accessing PT1
+        MMU_WRITE_PT2_ILLEGAL_ACCESS  = 0x0080, // Write & Bus Error accessing PT2
+        MMU_WRITE_DATA_ILLEGAL_ACCESS = 0x0100, // Write & Bus Error in cache access
+        MMU_READ_PT1_UNMAPPED 	      = 0x1001, // Read & Page fault on PT1
+        MMU_READ_PT2_UNMAPPED 	      = 0x1002, // Read & Page fault on PT2
+        MMU_READ_PRIVILEGE_VIOLATION  = 0x1004, // Read & Protected access in user mode
+        MMU_READ_EXEC_VIOLATION       = 0x1010, // Read & Exec access to a non exec page
+        MMU_READ_UNDEFINED_XTN 	      = 0x1020, // Read & Undefined external access
+        MMU_READ_PT1_ILLEGAL_ACCESS   = 0x1040, // Read & Bus Error accessing PT1
+        MMU_READ_PT2_ILLEGAL_ACCESS   = 0x1080, // Read & Bus Error accessing PT2
+        MMU_READ_DATA_ILLEGAL_ACCESS  = 0x1100, // Read & Bus Error in cache access
+    };
+
+    // miss types for data cache
+    enum dcache_miss_type_e
+    {
+        PTE1_MISS,
+        PTE2_MISS,
+        PROC_MISS,
+    };
+
+//    enum transaction_type_d_e
+//    {
+//        // b0 : 1 if cached
+//        // b1 : 1 if instruction
+//        TYPE_DATA_UNC     = 0x0,
+//        TYPE_DATA_MISS    = 0x1,
+//        TYPE_INS_UNC      = 0x2,
+//        TYPE_INS_MISS     = 0x3,
+//    };
+
+    //////////////////MODIFIED////////////////
+    enum content_line_cache_status_e
+    {
+        LINE_EMPTY,
+        LINE_CACHE_IN_TLB,
+        LINE_CACHE_CONTAINS_PTD,
+    };
+    //////////////////////////////////////////
+
+public:
+    sc_in<bool>                                p_clk;
+    sc_in<bool>                                p_resetn;
+    sc_in<bool>                                p_irq[iss_t::n_irq];
+    soclib::caba::VciInitiator<vci_param>      p_vci;
+    soclib::caba::DspinInput<dspin_in_width>   p_dspin_m2p;
+    soclib::caba::DspinOutput<dspin_out_width> p_dspin_p2m;
+    soclib::caba::DspinInput<dspin_in_width>   p_dspin_clack;
+
+private:
+
+    // STRUCTURAL PARAMETERS
+    soclib::common::AddressDecodingTable<uint64_t, bool> m_cacheability_table;
+
+    const size_t                        m_srcid;
+    const size_t                        m_cc_global_id;
+    const size_t                        m_nline_width;
+    const size_t  						m_itlb_ways;
+    const size_t  						m_itlb_sets;
+    const size_t  						m_dtlb_ways;
+    const size_t  						m_dtlb_sets;
+    const size_t  						m_icache_ways;
+    const size_t  						m_icache_sets;
+    const paddr_t 						m_icache_yzmask;
+    const size_t  						m_icache_words;
+    const size_t  						m_dcache_ways;
+    const size_t  						m_dcache_sets;
+    const paddr_t 						m_dcache_yzmask;
+    const size_t  						m_dcache_words;
+    const size_t                        m_x_width;
+    const size_t                        m_y_width;
+    const size_t                        m_proc_id;
+    const uint32_t						m_max_frozen_cycles;
+    const size_t  						m_paddr_nbits;
+    uint32_t                            m_debug_start_cycle;
+    bool                                m_debug_ok;
+
+    ////////////////////////////////////////
+    // Communication with processor ISS
+    ////////////////////////////////////////
+    typename iss_t::InstructionRequest  m_ireq;
+    typename iss_t::InstructionResponse m_irsp;
+    typename iss_t::DataRequest         m_dreq;
+    typename iss_t::DataResponse        m_drsp;
+
+    /////////////////////////////////////////////
+    // debug variables 
+    /////////////////////////////////////////////
+    bool                                m_debug_previous_i_hit;
+    bool                                m_debug_previous_d_hit;
+    bool                                m_debug_activated;
+
+    ///////////////////////////////
+    // Software visible REGISTERS
+    ///////////////////////////////
+    sc_signal<uint32_t>     r_mmu_ptpr;             	// page table pointer register
+    sc_signal<uint32_t>     r_mmu_mode;             	// mmu mode register
+    sc_signal<uint32_t>     r_mmu_word_lo;          	// mmu misc data low
+    sc_signal<uint32_t>     r_mmu_word_hi;          	// mmu misc data hight
+    sc_signal<uint32_t>     r_mmu_ibvar;      	    	// mmu bad instruction address
+    sc_signal<uint32_t>     r_mmu_dbvar;              	// mmu bad data address
+    sc_signal<uint32_t>     r_mmu_ietr;                 // mmu instruction error type
+    sc_signal<uint32_t>     r_mmu_detr;                 // mmu data error type
+    uint32_t	            r_mmu_params;		        // read-only
+    uint32_t	            r_mmu_release;		        // read_only
+
+
+    //////////////////////////////
+    // ICACHE FSM REGISTERS
+    //////////////////////////////
+    sc_signal<int>          r_icache_fsm;               // state register
+    sc_signal<int>          r_icache_fsm_save;          // return state for coherence op
+    sc_signal<paddr_t>      r_icache_vci_paddr;      	// physical address
+    sc_signal<uint32_t>     r_icache_vaddr_save;        // virtual address from processor
+
+    // icache miss handling
+    sc_signal<size_t>       r_icache_miss_way;		    // selected way for cache update
+    sc_signal<size_t>       r_icache_miss_set;		    // selected set for cache update
+    sc_signal<size_t>       r_icache_miss_word;		    // word index ( cache update)
+    sc_signal<bool>         r_icache_miss_inval;        // coherence request matching a miss
+    sc_signal<bool>         r_icache_miss_clack;        // waiting for a cleanup acknowledge
+
+    // coherence request handling
+    sc_signal<size_t>       r_icache_cc_way;		    // selected way for cc update/inval
+    sc_signal<size_t>       r_icache_cc_set;		    // selected set for cc update/inval
+    sc_signal<size_t>       r_icache_cc_word;		    // word counter for cc update
+    sc_signal<bool>         r_icache_cc_need_write;     // activate the cache for writing
+
+    // coherence clack handling
+    sc_signal<bool>         r_icache_clack_req;         // clack request
+    sc_signal<size_t>       r_icache_clack_way;		    // clack way
+    sc_signal<size_t>       r_icache_clack_set;		    // clack set
+
+    // icache flush handling
+    sc_signal<size_t>       r_icache_flush_count;	    // slot counter used for cache flush
+
+    // communication between ICACHE FSM and VCI_CMD FSM
+    sc_signal<bool>         r_icache_miss_req;           // cached read miss
+    sc_signal<bool>         r_icache_unc_req;            // uncached read miss
+
+    // communication between ICACHE FSM and DCACHE FSM
+    sc_signal<bool>	        r_icache_tlb_miss_req;       // (set icache/reset dcache)
+    sc_signal<bool>         r_icache_tlb_rsp_error;      // tlb miss response error
+
+
+    // communication between ICACHE FSM and CC_SEND FSM
+    sc_signal<bool>         r_icache_cc_send_req;           // ICACHE cc_send request
+    sc_signal<int>          r_icache_cc_send_type;          // ICACHE cc_send request type
+    sc_signal<paddr_t>      r_icache_cc_send_nline;         // ICACHE cc_send nline
+    sc_signal<size_t>       r_icache_cc_send_way;           // ICACHE cc_send way
+    sc_signal<size_t>       r_icache_cc_send_updt_tab_idx;  // ICACHE cc_send update table index
+    
+    // Filp-Flop in ICACHE FSM for saving the cleanup victim request
+    sc_signal<bool>         r_icache_cleanup_victim_req; 
+    sc_signal<paddr_t>      r_icache_cleanup_victim_nline;
+
+    ///////////////////////////////
+    // DCACHE FSM REGISTERS
+    ///////////////////////////////
+    sc_signal<int>          r_dcache_fsm;               // state register
+    sc_signal<int>          r_dcache_fsm_cc_save;       // return state for coherence op
+    sc_signal<int>          r_dcache_fsm_scan_save;     // return state for tlb scan op
+    // registers written in P0 stage (used in P1 stage)
+    sc_signal<bool>         r_dcache_wbuf_req;          // WBUF must be written in P1 stage
+    sc_signal<bool>         r_dcache_updt_req;          // DCACHE must be updated in P1 stage
+    sc_signal<uint32_t>     r_dcache_save_vaddr;        // virtual address (from proc)
+    sc_signal<uint32_t>     r_dcache_save_wdata;        // write data (from proc)
+    sc_signal<uint32_t>     r_dcache_save_be;           // byte enable (from proc)
+    sc_signal<paddr_t>      r_dcache_save_paddr;        // physical address
+    sc_signal<size_t>       r_dcache_save_cache_way;	// selected way (from dcache)
+    sc_signal<size_t>       r_dcache_save_cache_set;	// selected set (from dcache)
+    sc_signal<size_t>       r_dcache_save_cache_word;	// selected word (from dcache)
+    // registers used by the Dirty bit sub-fsm
+    sc_signal<paddr_t>      r_dcache_dirty_paddr;       // PTE physical address
+    sc_signal<size_t>       r_dcache_dirty_way;	        // way to invalidate in dcache
+    sc_signal<size_t>       r_dcache_dirty_set;	        // set to invalidate in dcache
+    sc_signal<size_t>       r_dcache_dirty_state;	    // state to invalidate in dcache
+    sc_signal<size_t>       r_dcache_dirty_word;    
+
+    // communication between DCACHE FSM and VCI_CMD FSM
+    sc_signal<paddr_t>      r_dcache_vci_paddr;		    // physical address for VCI command
+    sc_signal<uint32_t>     r_dcache_vci_wdata;		    // write unc data for VCI command
+    sc_signal<bool>         r_dcache_vci_miss_req;      // read miss request
+    sc_signal<bool>         r_dcache_vci_unc_req;       // uncacheable request (read/write)
+    sc_signal<uint32_t>     r_dcache_vci_unc_be;        // uncacheable byte enable
+    sc_signal<uint32_t>     r_dcache_vci_unc_write;     // uncacheable data write request
+    sc_signal<bool>         r_dcache_vci_cas_req;       // atomic write request CAS
+    sc_signal<uint32_t>     r_dcache_vci_cas_old;       // previous data value for a CAS
+    sc_signal<uint32_t>     r_dcache_vci_cas_new;       // new data value for a CAS
+    sc_signal<bool>         r_dcache_vci_ll_req;        // atomic read request LL
+    sc_signal<bool>         r_dcache_vci_sc_req;        // atomic write request SC
+    sc_signal<uint32_t>     r_dcache_vci_sc_data;       // SC data (command)
+    sc_signal<int>          r_dcache_sc_state;          // sc success to modify locally
+    sc_signal<size_t>       r_dcache_sc_set;            // sc success to modify locally
+    sc_signal<size_t>       r_dcache_sc_way;            // sc success to modify locally
+
+    //RWT: local cas
+    sc_signal<int>          r_cas_cache_state;
+    sc_signal<size_t>       r_cas_local_way;
+    sc_signal<size_t>       r_cas_local_set;
+    sc_signal<size_t>       r_cas_local_word;
+
+    // register used for XTN inval
+    sc_signal<size_t>       r_dcache_xtn_way;		    // selected way (from dcache)
+    sc_signal<size_t>       r_dcache_xtn_set;		    // selected set (from dcache)
+
+    // handling dcache miss
+    sc_signal<int>	        r_dcache_miss_type;		    // depending on the requester
+    sc_signal<size_t>       r_dcache_miss_word;		    // word index for cache update
+    sc_signal<size_t>       r_dcache_miss_way;		    // selected way for cache update
+    sc_signal<size_t>       r_dcache_miss_set;		    // selected set for cache update
+    sc_signal<bool>         r_dcache_miss_inval;        // inval request matching a miss
+    sc_signal<bool>         r_dcache_miss_updt;         //  cc updt request matching a miss
+    sc_signal<bool>         r_dcache_miss_clack;        // waiting for a cleanup acknowledge
+
+    // handling coherence requests
+    sc_signal<size_t>       r_dcache_cc_way;		    // selected way for cc update/inval
+    sc_signal<size_t>       r_dcache_cc_set;		    // selected set for cc update/inval
+    sc_signal<int>          r_dcache_cc_state;          // state of selected cache slot
+    sc_signal<size_t>       r_dcache_cc_word;		    // word counter for cc update
+    sc_signal<bool>         r_dcache_cc_need_write;     // activate the cache for writing
+    sc_signal<paddr_t>      r_dcache_cc_inval_addr;     // address for a cleanup transaction
+    sc_signal<uint32_t>     r_dcache_cc_inval_data_cpt;  
+
+    // coherence clack handling
+    sc_signal<bool>         r_dcache_clack_req;         // clack request
+    sc_signal<size_t>       r_dcache_clack_way;		    // clack way
+    sc_signal<size_t>       r_dcache_clack_set;		    // clack set
+
+    // dcache flush handling
+    sc_signal<size_t>       r_dcache_flush_count;	    // slot counter used for cache flush
+
+    // ll response handling
+    sc_signal<size_t>       r_dcache_ll_rsp_count;	    // flit counter used for ll rsp
+
+    // used by the TLB miss sub-fsm
+    sc_signal<uint32_t>     r_dcache_tlb_vaddr;		    // virtual address for a tlb miss
+    sc_signal<bool>         r_dcache_tlb_ins;		    // target tlb (itlb if true)
+    sc_signal<paddr_t>      r_dcache_tlb_paddr;		    // physical address of pte
+    sc_signal<uint32_t>     r_dcache_tlb_pte_flags;	    // pte1 or first word of pte2
+    sc_signal<uint32_t>     r_dcache_tlb_pte_ppn;	    // second word of pte2
+    sc_signal<size_t>       r_dcache_tlb_cache_way;	    // selected way in dcache
+    sc_signal<size_t>       r_dcache_tlb_cache_set;	    // selected set in dcache
+    sc_signal<size_t>       r_dcache_tlb_cache_word;	// selected word in dcache
+    sc_signal<size_t>       r_dcache_tlb_way;		    // selected way in tlb
+    sc_signal<size_t>       r_dcache_tlb_set;		    // selected set in tlb
+
+    // ITLB and DTLB invalidation
+    sc_signal<paddr_t>      r_dcache_tlb_inval_line;	// line index
+    sc_signal<size_t>       r_dcache_tlb_inval_set;     // tlb set counter
+
+    // communication between DCACHE FSM and ICACHE FSM
+    sc_signal<bool>         r_dcache_xtn_req;           // xtn request (caused by processor)
+    sc_signal<int>          r_dcache_xtn_opcode;        // xtn request type
+
+    // Filp-Flop in DCACHE FSM for saving the cleanup victim request
+    sc_signal<bool>         r_dcache_cleanup_victim_req; 
+    sc_signal<bool>         r_dcache_cleanup_victim_line_dirty; 
+    sc_signal<bool>         r_dcache_cleanup_victim_line_no_shared; 
+    sc_signal<paddr_t>      r_dcache_cleanup_victim_nline;
+
+    // communication between DCACHE FSM and CC_SEND FSM
+    sc_signal<bool>         r_dcache_cc_send_req;           // DCACHE cc_send request
+    sc_signal<int>          r_dcache_cc_send_type;          // DCACHE cc_send request type
+    sc_signal<paddr_t>      r_dcache_cc_send_nline;         // DCACHE cc_send nline
+    sc_signal<size_t>       r_dcache_cc_send_way;           // DCACHE cc_send way
+    sc_signal<size_t>       r_dcache_cc_send_updt_tab_idx;  // DCACHE cc_send update table index
+    sc_signal<size_t>       r_dcache_cc_send_inval_is_config;  // DCACHE cc_send update table index
+    sc_signal<bool>         r_dcache_cc_send_multi_ack_miss;  // DCACHE cc_updt miss
+    
+    
+    // special registers for ODCCP/RWT
+    sc_signal<bool>         r_dcache_cc_cleanup_updt_data;          // Register for cleanup with data (wb updt)
+    sc_signal<bool>         r_dcache_cc_line_dirty;                 // Register for cleanup with data (wb updt)
+    sc_signal<bool>         r_dcache_cc_line_no_shared;             // Register for cleanup with data (wb updt)
+    sc_signal<bool>         r_dcache_miss_victim_no_coherence;      // Register for victim in no coherence mode
+    sc_signal<bool>         r_dcache_line_no_coherence;             // Register for line current in no coherence mode
+    sc_signal<bool>         r_dcache_dirty_save;             
+    sc_signal<uint32_t>     r_cc_send_cpt_word;
+    sc_signal<uint32_t>     r_dcache_miss_data_cpt;
+    sc_signal<paddr_t>      r_dcache_miss_data_addr;
+    sc_signal<uint32_t>     r_dcache_xtn_flush_data_cpt;
+    sc_signal<paddr_t>      r_dcache_xtn_flush_addr_data;
+    sc_signal<int>          r_dcache_xtn_state;
+    sc_signal<paddr_t>      r_dcache_xtn_data_addr;
+    sc_signal<uint32_t>     r_dcache_xtn_data_cpt;
+    sc_signal<bool>         r_dcache_updt_data_req;             
+    sc_signal<bool>         r_dcache_updt_dir_req;             
+    sc_signal<bool>         r_dcache_rsp_state;             
+    sc_signal<bool>         r_dcache_cas_islocal;            // cas is done locally 
+    
+
+    // dcache directory extension
+    ///////////////////////////MODIFIED///////////////////////////////////////////////////
+    //bool                    *r_dcache_in_tlb;           // copy exist in dtlb or itlb
+    //bool                    *r_dcache_contains_ptd;     // cache line contains a PTD
+    int                     *r_dcache_content_state; // content state of one cache line
+    //////////////////////////////////////////////////////////////////////////////////////
+
+    //MESI
+    sc_signal<bool>         r_icache_read_state;
+    sc_signal<bool>         r_dcache_read_state;
+    sc_signal<bool>         r_dcache_read_for_modify;     // a command intent to write
+    sc_signal<bool>         r_dcache_read_hit;            // a command intent to write hit in L1
+   
+     ///////////////////////////////////
+    // Physical address extension for data access
+    sc_signal<uint32_t>     r_dcache_paddr_ext;             // CP2 register (if vci_address > 32)
+
+    ///////////////////////////////////
+    // VCI_CMD FSM REGISTERS
+    ///////////////////////////////////
+    sc_signal<int>          r_vci_cmd_fsm;
+    sc_signal<size_t>       r_vci_cmd_min;      	        // used for write bursts
+    sc_signal<size_t>       r_vci_cmd_max;      	        // used for write bursts
+    sc_signal<size_t>       r_vci_cmd_cpt;    		        // used for write bursts
+    sc_signal<bool>         r_vci_cmd_imiss_prio;	        // round-robin between imiss & dmiss
+
+    ///////////////////////////////////
+    // VCI_RSP FSM REGISTERS
+    ///////////////////////////////////
+    sc_signal<int>          r_vci_rsp_fsm;
+    sc_signal<size_t>       r_vci_rsp_cpt;
+    sc_signal<bool>         r_vci_rsp_ins_error;
+    sc_signal<bool>         r_vci_rsp_data_error;
+    GenericFifo<uint32_t>   r_vci_rsp_fifo_icache;	        // response FIFO to ICACHE FSM
+    GenericFifo<uint32_t>   r_vci_rsp_fifo_dcache;	        // response FIFO to DCACHE FSM
+    
+
+    //RWT
+//    GenericFifo<bool>       r_vci_rsp_fifo_rpktid;
+
+    GenericFifo<uint32_t>   r_cc_send_data_fifo;   
+
+    ///////////////////////////////////
+    //  CC_SEND FSM REGISTER
+    ///////////////////////////////////
+    sc_signal<int>          r_cc_send_fsm;                  // state register
+    sc_signal<bool>         r_cc_send_last_client;          // 0 dcache / 1 icache
+
+    ///////////////////////////////////
+    //  CC_RECEIVE FSM REGISTER
+    ///////////////////////////////////
+    sc_signal<int>          r_cc_receive_fsm;               // state register
+    sc_signal<bool>         r_cc_receive_data_ins;          // request to : 0 dcache / 1 icache
+
+    // communication between CC_RECEIVE FSM and ICACHE FSM
+    sc_signal<bool>         r_cc_receive_icache_req;        // cc_receive to icache request
+    sc_signal<int>          r_cc_receive_icache_type;       // cc_receive type of request
+    sc_signal<size_t>       r_cc_receive_icache_way;        // cc_receive to icache way
+    sc_signal<size_t>       r_cc_receive_icache_set;        // cc_receive to icache set
+    sc_signal<size_t>       r_cc_receive_icache_updt_tab_idx;  // cc_receive update table index
+    sc_signal<paddr_t>      r_cc_receive_icache_nline;	    // cache line physical address
+
+    // communication between CC_RECEIVE FSM and DCACHE FSM
+    sc_signal<bool>         r_cc_receive_dcache_req;              // cc_receive to dcache request
+    sc_signal<int>          r_cc_receive_dcache_type;             // cc_receive type of request
+    sc_signal<size_t>       r_cc_receive_dcache_way;              // cc_receive to dcache way
+    sc_signal<size_t>       r_cc_receive_dcache_set;              // cc_receive to dcache set
+    sc_signal<size_t>       r_cc_receive_dcache_updt_tab_idx;     // cc_receive update table index
+    sc_signal<paddr_t>      r_cc_receive_dcache_nline;	          // cache line physical address
+    sc_signal<bool>         r_cc_receive_dcache_inval_is_config;  // inval from memcache is config
+    sc_signal<size_t>       r_cc_receive_dcache_srcid;            // cc_receive to dcache set
+    sc_signal<size_t>       r_cc_receive_brdcast;                 // is brdcast
+
+    ///////////////////////////////////
+    //  DSPIN CLACK INTERFACE REGISTER
+    ///////////////////////////////////
+    sc_signal<bool>         r_dspin_clack_req;
+    sc_signal<uint64_t>     r_dspin_clack_flit;
+    
+    //////////////////////////////////////////////////////////////////
+    // processor, write buffer, caches , TLBs
+    //////////////////////////////////////////////////////////////////
+
+    iss_t                       r_iss;
+    MultiWriteBuffer<paddr_t>	r_wbuf;
+    GenericCache<paddr_t>   	r_icache;
+    GenericCache<paddr_t>    	r_dcache;
+    GenericTlb<paddr_t>       	r_itlb;
+    GenericTlb<paddr_t>     	r_dtlb;
+
+    //////////////////////////////////////////////////////////////////
+    // llsc registration buffer
+    //////////////////////////////////////////////////////////////////
+
+    sc_signal<paddr_t>                     r_dcache_llsc_paddr;
+    sc_signal<uint32_t>                    r_dcache_llsc_key;
+    sc_signal<uint32_t>                    r_dcache_llsc_count;
+    sc_signal<bool>                        r_dcache_llsc_valid;
+
+    
+    sc_signal<bool>                        r_cache_frozen;
+
+    ////////////////////////////////
+    // Activity counters
+    ////////////////////////////////
+    uint32_t m_cpt_dcache_data_read;           // DCACHE DATA READ
+    uint32_t m_cpt_dcache_data_write;          // DCACHE DATA WRITE
+    uint32_t m_cpt_dcache_dir_read;            // DCACHE DIR READ
+    uint32_t m_cpt_dcache_dir_write;           // DCACHE DIR WRITE
+
+    uint32_t m_cpt_icache_data_read;           // ICACHE DATA READ
+    uint32_t m_cpt_icache_data_write;          // ICACHE DATA WRITE
+    uint32_t m_cpt_icache_dir_read;            // ICACHE DIR READ
+    uint32_t m_cpt_icache_dir_write;           // ICACHE DIR WRITE
+
+    uint32_t m_cpt_frz_cycles;	               // number of cycles where the cpu is frozen
+    uint32_t m_cpt_total_cycles;	           // total number of cycles
+
+    // Cache activity counters
+    uint32_t m_cpt_data_read;                  // total number of read data
+    uint32_t m_cpt_data_write;                 // total number of write data
+    uint32_t m_cpt_data_write_back;
+    uint32_t m_cpt_data_cleanup;
+    uint32_t m_cpt_data_sc;
+    uint32_t m_cpt_data_miss;                  // number of read miss
+    uint32_t m_cpt_ins_miss;                   // number of instruction miss
+    uint32_t m_cpt_unc_read;                   // number of read uncached
+    uint32_t m_cpt_write_cached;               // number of cached write
+    uint32_t m_cpt_ins_read;                   // number of instruction read
+    uint32_t m_cpt_ins_spc_miss;               // number of speculative instruction miss
+
+    uint32_t m_cost_write_frz;                 // number of frozen cycles related to write buffer
+    uint32_t m_cost_data_miss_frz;             // number of frozen cycles related to data miss
+    uint32_t m_cost_unc_read_frz;              // number of frozen cycles related to uncached read
+    uint32_t m_cost_ins_miss_frz;              // number of frozen cycles related to ins miss
+
+    uint32_t m_cpt_imiss_transaction;          // number of VCI instruction miss transactions
+    uint32_t m_cpt_dmiss_transaction;          // number of VCI data miss transactions
+    uint32_t m_cpt_unc_transaction;            // number of VCI uncached read transactions
+    uint32_t m_cpt_dunc_transaction;           // number of VCI uncached read transactions
+    uint32_t m_cpt_ll_transaction;             // number of VCI uncached read transactions
+    uint32_t m_cpt_write_transaction;          // number of VCI write transactions
+    uint32_t m_cpt_icache_unc_transaction;
+
+    uint32_t m_cost_imiss_transaction;         // cumulated duration for VCI IMISS transactions
+    uint32_t m_cost_dmiss_transaction;         // cumulated duration for VCI DMISS transactions
+    uint32_t m_cost_unc_transaction;           // cumulated duration for VCI UNC transactions
+    uint32_t m_cost_write_transaction;         // cumulated duration for VCI WRITE transactions
+    uint32_t m_cost_icache_unc_transaction;    // cumulated duration for VCI IUNC transactions
+    uint32_t m_length_write_transaction;       // cumulated length for VCI WRITE transactions
+
+    // TLB activity counters
+    uint32_t m_cpt_ins_tlb_read;               // number of instruction tlb read
+    uint32_t m_cpt_ins_tlb_miss;               // number of instruction tlb miss
+    uint32_t m_cpt_ins_tlb_update_acc;         // number of instruction tlb update
+    uint32_t m_cpt_ins_tlb_occup_cache;        // number of instruction tlb occupy data cache line
+    uint32_t m_cpt_ins_tlb_hit_dcache;         // number of instruction tlb hit in data cache
+
+    uint32_t m_cpt_data_tlb_read;              // number of data tlb read
+    uint32_t m_cpt_data_tlb_miss;              // number of data tlb miss
+    uint32_t m_cpt_data_tlb_update_acc;        // number of data tlb update
+    uint32_t m_cpt_data_tlb_update_dirty;      // number of data tlb update dirty
+    uint32_t m_cpt_data_tlb_hit_dcache;        // number of data tlb hit in data cache
+    uint32_t m_cpt_data_tlb_occup_cache;       // number of data tlb occupy data cache line
+    uint32_t m_cpt_tlb_occup_dcache;
+
+    uint32_t m_cost_ins_tlb_miss_frz;          // number of frozen cycles related to instruction tlb miss
+    uint32_t m_cost_data_tlb_miss_frz;         // number of frozen cycles related to data tlb miss
+    uint32_t m_cost_ins_tlb_update_acc_frz;    // number of frozen cycles related to instruction tlb update acc
+    uint32_t m_cost_data_tlb_update_acc_frz;   // number of frozen cycles related to data tlb update acc
+    uint32_t m_cost_data_tlb_update_dirty_frz; // number of frozen cycles related to data tlb update dirty
+    uint32_t m_cost_ins_tlb_occup_cache_frz;   // number of frozen cycles related to instruction tlb miss operate in dcache
+    uint32_t m_cost_data_tlb_occup_cache_frz;  // number of frozen cycles related to data tlb miss operate in dcache
+
+    uint32_t m_cpt_itlbmiss_transaction;       // number of itlb miss transactions
+    uint32_t m_cpt_itlb_ll_transaction;        // number of itlb ll acc transactions
+    uint32_t m_cpt_itlb_sc_transaction;        // number of itlb sc acc transactions
+    uint32_t m_cpt_dtlbmiss_transaction;       // number of dtlb miss transactions
+    uint32_t m_cpt_dtlb_ll_transaction;        // number of dtlb ll acc transactions
+    uint32_t m_cpt_dtlb_sc_transaction;        // number of dtlb sc acc transactions
+    uint32_t m_cpt_dtlb_ll_dirty_transaction;  // number of dtlb ll dirty transactions
+    uint32_t m_cpt_dtlb_sc_dirty_transaction;  // number of dtlb sc dirty transactions
+
+    uint32_t m_cost_itlbmiss_transaction;      // cumulated duration for VCI instruction TLB miss transactions
+    uint32_t m_cost_itlb_ll_transaction;       // cumulated duration for VCI instruction TLB ll acc transactions
+    uint32_t m_cost_itlb_sc_transaction;       // cumulated duration for VCI instruction TLB sc acc transactions
+    uint32_t m_cost_dtlbmiss_transaction;      // cumulated duration for VCI data TLB miss transactions
+    uint32_t m_cost_dtlb_ll_transaction;       // cumulated duration for VCI data TLB ll acc transactions
+    uint32_t m_cost_dtlb_sc_transaction;       // cumulated duration for VCI data TLB sc acc transactions
+    uint32_t m_cost_dtlb_ll_dirty_transaction; // cumulated duration for VCI data TLB ll dirty transactions
+    uint32_t m_cost_dtlb_sc_dirty_transaction; // cumulated duration for VCI data TLB sc dirty transactions
+
+    // coherence activity counters
+    uint32_t m_cpt_cc_update_icache;           // number of coherence update instruction commands
+    uint32_t m_cpt_cc_update_dcache;           // number of coherence update data commands
+    uint32_t m_cpt_cc_inval_icache;            // number of coherence inval instruction commands
+    uint32_t m_cpt_cc_inval_dcache;            // number of coherence inval data commands
+    uint32_t m_cpt_cc_broadcast;               // number of coherence broadcast commands
+
+    uint32_t m_cost_updt_data_frz;             // number of frozen cycles related to coherence update data packets
+    uint32_t m_cost_inval_ins_frz;             // number of frozen cycles related to coherence inval instruction packets
+    uint32_t m_cost_inval_data_frz;            // number of frozen cycles related to coherence inval data packets
+    uint32_t m_cost_broadcast_frz;             // number of frozen cycles related to coherence broadcast packets
+
+    uint32_t m_cpt_cc_cleanup_ins;             // number of coherence cleanup packets
+    uint32_t m_cpt_cc_cleanup_data;            // number of coherence cleanup packets
+    uint32_t m_cpt_cleanup_data_not_dirty;     // number of total cleanup data without extra data flits
+    uint32_t m_cpt_cleanup_data_dirty_word;    // number of total words dirty in cleanup data
+    uint32_t m_cpt_data_write_miss;            // number of total write miss
+    uint32_t m_cpt_data_write_on_zombi;        // number of frozen cycles related to blocked write on line NCC/CC ZOMBI
+    uint32_t m_cpt_data_write_on_zombi_ncc;    // number of frozen cycles related to blocked write on line NCC ZOMBI
+
+    uint32_t m_cpt_icleanup_transaction;       // number of instruction cleanup transactions
+    uint32_t m_cpt_dcleanup_transaction;       // number of instructinumber of data cleanup transactions
+    uint32_t m_cost_icleanup_transaction;      // cumulated duration for VCI instruction cleanup transactions
+    uint32_t m_cost_dcleanup_transaction;      // cumulated duration for VCI data cleanup transactions
+
+    uint32_t m_cost_ins_tlb_inval_frz;         // number of frozen cycles related to checking ins tlb invalidate
+    uint32_t m_cpt_ins_tlb_inval;              // number of ins tlb invalidate
+
+    uint32_t m_cost_data_tlb_inval_frz;        // number of frozen cycles related to checking data tlb invalidate
+    uint32_t m_cpt_data_tlb_inval;             // number of data tlb invalidate
+
+    // FSM activity counters
+    uint32_t m_cpt_fsm_icache     [64];
+    uint32_t m_cpt_fsm_dcache     [64];
+    uint32_t m_cpt_fsm_cmd        [64];
+    uint32_t m_cpt_fsm_rsp        [64];
+    uint32_t m_cpt_fsm_cc_receive [64];
+    uint32_t m_cpt_fsm_cc_send    [64];
+
+    uint32_t m_cpt_stop_simulation;		// used to stop simulation if frozen
+    bool     m_monitor_ok;		        // used to debug cache output  
+    uint32_t m_monitor_base;		    
+    uint32_t m_monitor_length;		    
+
+protected:
+    SC_HAS_PROCESS(VciCcVCacheWrapper);
+
+public:
+    VciCcVCacheWrapper(
+        sc_module_name                      name,
+        const int                           proc_id,
+        const soclib::common::MappingTable  &mtd,
+        const soclib::common::IntTab        &srcid,
+        const size_t                        cc_global_id,
+        const size_t                        itlb_ways,
+        const size_t                        itlb_sets,
+        const size_t                        dtlb_ways,
+        const size_t                        dtlb_sets,
+        const size_t                        icache_ways,
+        const size_t                        icache_sets,
+        const size_t                        icache_words,
+        const size_t                        dcache_ways,
+        const size_t                        dcache_sets,
+        const size_t                        dcache_words,
+        const size_t                        wbuf_nlines,
+        const size_t                        wbuf_nwords,
+        const size_t                        x_width,
+        const size_t                        y_width,
+        const uint32_t                      max_frozen_cycles,
+        const uint32_t                      debug_start_cycle,
+        const bool                          debug_ok );
+
+    ~VciCcVCacheWrapper();
+
+    void print_cpi();
+    void print_stats();
+    void clear_stats();
+    void print_trace(size_t mode = 0);
+    bool frozen();
+    void cache_monitor(paddr_t addr);
+    void start_monitor(paddr_t,paddr_t);
+    void stop_monitor();
+    inline void iss_set_debug_mask(uint v) 
+    {
+	    r_iss.set_debug_mask(v);
+    }
+
+private:
+    void transition();
+    void genMoore();
+
+    soclib_static_assert((int)iss_t::SC_ATOMIC == (int)vci_param::STORE_COND_ATOMIC);
+    soclib_static_assert((int)iss_t::SC_NOT_ATOMIC == (int)vci_param::STORE_COND_NOT_ATOMIC);
+};
+
+}}
+
+#endif /* SOCLIB_CABA_VCI_CC_VCACHE_WRAPPER_H */
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Index: /branches/MESI/modules/vci_cc_vcache_wrapper/caba/source/src/vci_cc_vcache_wrapper.cpp
===================================================================
--- /branches/MESI/modules/vci_cc_vcache_wrapper/caba/source/src/vci_cc_vcache_wrapper.cpp	(revision 670)
+++ /branches/MESI/modules/vci_cc_vcache_wrapper/caba/source/src/vci_cc_vcache_wrapper.cpp	(revision 670)
@@ -0,0 +1,6946 @@
+/* -*- c++ -*-
+ * File : vci_cc_vcache_wrapper.cpp
+ * Copyright (c) UPMC, Lip6, SoC
+ * Authors : Alain GREINER, Yang GAO
+ *
+ * SOCLIB_LGPL_HEADER_BEGIN
+ *
+ * This file is part of SoCLib, GNU LGPLv2.1.
+ *
+ * SoCLib is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 of the License.
+ *
+ * SoCLib is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with SoCLib; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ * SOCLIB_LGPL_HEADER_END
+ *
+ * Maintainers: cesar.fuguet-tortolero@lip6.fr
+ *              alexandre.joannou@lip6.fr
+ */
+
+#include <cassert>
+#include "arithmetics.h"
+#include "../include/vci_cc_vcache_wrapper.h"
+
+#define DEBUG_DCACHE		1
+#define DEBUG_ICACHE		1
+#define DEBUG_CMD   		0
+#define INSTRUMENTATION     1
+
+namespace soclib {
+namespace caba {
+
+namespace {
+const char *icache_fsm_state_str[] = {
+        "ICACHE_IDLE",
+
+        "ICACHE_XTN_TLB_FLUSH",
+        "ICACHE_XTN_CACHE_FLUSH",
+        "ICACHE_XTN_CACHE_FLUSH_GO",
+        "ICACHE_XTN_TLB_INVAL",
+        "ICACHE_XTN_CACHE_INVAL_VA",
+        "ICACHE_XTN_CACHE_INVAL_PA",
+        "ICACHE_XTN_CACHE_INVAL_GO",
+
+        "ICACHE_TLB_WAIT",
+
+        "ICACHE_MISS_SELECT",
+        "ICACHE_MISS_CLEAN",
+        "ICACHE_MISS_WAIT",
+        "ICACHE_MISS_DATA_UPDT",
+        "ICACHE_MISS_DIR_UPDT",
+
+        "ICACHE_UNC_WAIT",
+
+        "ICACHE_CC_CHECK",
+        "ICACHE_CC_UPDT",
+        "ICACHE_CC_INVAL",
+    };
+
+const char *dcache_fsm_state_str[] = {
+        "DCACHE_IDLE",
+
+        "DCACHE_TLB_MISS",
+        "DCACHE_TLB_PTE1_GET",
+        "DCACHE_TLB_PTE1_SELECT",
+        "DCACHE_TLB_PTE1_UPDT",
+        "DCACHE_TLB_PTE2_GET",
+        "DCACHE_TLB_PTE2_SELECT",
+        "DCACHE_TLB_PTE2_UPDT",
+        "DCACHE_TLB_LR_UPDT",
+        "DCACHE_TLB_LR_WAIT",
+        "DCACHE_TLB_RETURN",
+
+        "DCACHE_XTN_SWITCH",
+        "DCACHE_XTN_SYNC",
+        "DCACHE_XTN_IC_INVAL_VA",
+        "DCACHE_XTN_IC_FLUSH",
+        "DCACHE_XTN_IC_INVAL_PA",
+        "DCACHE_XTN_IT_INVAL",
+        "DCACHE_XTN_DC_FLUSH",
+        "DCACHE_XTN_DC_FLUSH_DATA",
+        "DCACHE_XTN_DC_FLUSH_GO",
+        "DCACHE_XTN_DC_INVAL_VA",
+        "DCACHE_XTN_DC_INVAL_PA",
+        "DCACHE_XTN_DC_INVAL_END",
+        "DCACHE_XTN_DC_INVAL_GO",
+        "DCACHE_XTN_DC_INVAL_DATA",
+        "DCACHE_XTN_DT_INVAL",
+
+        "DCACHE_DIRTY_GET_PTE",
+        "DCACHE_DIRTY_WAIT",
+
+        "DCACHE_MISS_SELECT",
+        "DCACHE_MISS_CLEAN",
+        "DCACHE_MISS_DATA",
+        "DCACHE_MISS_WAIT",
+        "DCACHE_MISS_DATA_UPDT",
+        "DCACHE_MISS_DIR_UPDT",
+
+        "DCACHE_UNC_WAIT",
+        "DCACHE_LL_WAIT",
+        "DCACHE_SC_WAIT",
+
+        "DCACHE_CC_CHECK",
+        "DCACHE_CC_UPDT",
+        "DCACHE_CC_INVAL",
+        "DCACHE_CC_SEND_DATA",
+
+        "DCACHE_INVAL_TLB_SCAN",
+    };
+
+const char *cmd_fsm_state_str[] = {
+        "CMD_IDLE",
+        "CMD_INS_MISS",
+        "CMD_INS_UNC",
+        "CMD_DATA_MISS",
+        "CMD_DATA_UNC_READ",
+        "CMD_DATA_UNC_WRITE",
+        "CMD_DATA_LL",
+        "CMD_DATA_SC",
+        "CMD_DATA_CAS",
+    };
+
+const char *vci_pktid_type_str[] = {
+        "TYPE_DATA_UNC",
+        "TYPE_READ_DATA_MISS",            
+        "TYPE_READ_INS_UNC",          
+        "TYPE_READ_INS_MISS",
+        "TYPE_WRITE",
+        "TYPE_CAS",
+        "TYPE_LL",
+        "TYPE_SC",
+    };
+
+const char *vci_cmd_type_str[] = {
+        "NOP or STORE_COND",
+        "READ",
+        "WRITE",
+        "LOCKED_READ"
+    };
+
+const char *rsp_fsm_state_str[] = {
+        "RSP_IDLE",
+        "RSP_INS_MISS",
+        "RSP_INS_UNC",
+        "RSP_DATA_MISS",
+        "RSP_DATA_UNC",
+        "RSP_DATA_LL",
+        "RSP_DATA_WRITE",
+    };
+
+const char *cc_receive_fsm_state_str[] = {
+        "CC_RECEIVE_IDLE",                 
+        "CC_RECEIVE_BRDCAST_HEADER",       
+        "CC_RECEIVE_BRDCAST_NLINE",        
+        "CC_RECEIVE_INS_INVAL_HEADER",     
+        "CC_RECEIVE_INS_INVAL_NLINE",      
+        "CC_RECEIVE_INS_UPDT_HEADER",      
+        "CC_RECEIVE_INS_UPDT_NLINE",       
+        "CC_RECEIVE_DATA_INVAL_HEADER",    
+        "CC_RECEIVE_DATA_INVAL_NLINE",     
+        "CC_RECEIVE_DATA_UPDT_HEADER",     
+        "CC_RECEIVE_DATA_UPDT_NLINE",      
+    };
+
+const char *cc_send_fsm_state_str[] = {
+        "CC_SEND_IDLE",
+        "CC_SEND_CLEANUP_1",
+        "CC_SEND_CLEANUP_2",
+        "CC_SEND_DATA_UPDT",
+        "CC_SEND_MULTI_ACK_HEADER",
+    };
+
+const char *cache_state_str[] = {
+        "CACHE_SLOT_STATE_INVALID",
+        "CACHE_SLOT_STATE_EXCLUSIVE",
+        "CACHE_SLOT_STATE_SHARED",
+        "CACHE_SLOT_STATE_MODIFIED",
+        "CACHE_SLOT_STATE_ZOMBI",
+    };
+}
+
+#define tmpl(...) \
+   template<typename vci_param, \
+            size_t   dspin_in_width, \
+            size_t   dspin_out_width, \
+            typename iss_t> __VA_ARGS__ \
+   VciCcVCacheWrapper<vci_param, dspin_in_width, dspin_out_width, iss_t>
+
+using namespace soclib::common;
+
+/////////////////////////////////
+tmpl(/**/)::VciCcVCacheWrapper(
+    sc_module_name 			name,
+    const int 				proc_id,
+    const MappingTable 	    &mtd,
+    const IntTab 	        &srcid,
+    const size_t 	        cc_global_id,
+    const size_t 			itlb_ways,
+    const size_t 			itlb_sets,
+    const size_t 			dtlb_ways,
+    const size_t 			dtlb_sets,
+    const size_t 			icache_ways,
+    const size_t 			icache_sets,
+    const size_t 			icache_words,
+    const size_t 			dcache_ways,
+    const size_t 			dcache_sets,
+    const size_t 			dcache_words,
+    const size_t 			wbuf_nlines,
+    const size_t 			wbuf_nwords,
+    const size_t			x_width,
+    const size_t			y_width,
+    const uint32_t			max_frozen_cycles,
+    const uint32_t			debug_start_cycle,
+    const bool				debug_ok )
+    : soclib::caba::BaseModule(name),
+
+      p_clk("p_clk"),
+      p_resetn("p_resetn"),
+      p_vci("p_vci"),
+      p_dspin_m2p("p_dspin_m2p"),
+      p_dspin_p2m("p_dspin_p2m"),
+      p_dspin_clack("p_dspin_clack"),
+
+      m_cacheability_table( mtd.getCacheabilityTable() ),
+      m_srcid( mtd.indexForId(srcid) ),
+      m_cc_global_id( cc_global_id ),
+      m_nline_width( vci_param::N - (uint32_log2(dcache_words)) - 2 ),
+      m_itlb_ways( itlb_ways ),
+      m_itlb_sets( itlb_sets ),
+      m_dtlb_ways( dtlb_ways ),
+      m_dtlb_sets( dtlb_sets ),
+      m_icache_ways( icache_ways ),
+      m_icache_sets( icache_sets ),
+      m_icache_yzmask( (~0)<<(uint32_log2(icache_words) + 2) ),
+      m_icache_words( icache_words ),
+      m_dcache_ways( dcache_ways ),
+      m_dcache_sets( dcache_sets ),
+      m_dcache_yzmask( (~0)<<(uint32_log2(dcache_words) + 2) ),
+      m_dcache_words( dcache_words ),
+      m_x_width( x_width ),
+      m_y_width( y_width ),
+      m_proc_id( proc_id ),
+      m_max_frozen_cycles( max_frozen_cycles ),
+      m_paddr_nbits( vci_param::N ),
+      m_debug_start_cycle( debug_start_cycle ),
+      m_debug_ok( debug_ok ),
+
+      r_mmu_ptpr("r_mmu_ptpr"),
+      r_mmu_mode("r_mmu_mode"),
+      r_mmu_word_lo("r_mmu_word_lo"),
+      r_mmu_word_hi("r_mmu_word_hi"),
+      r_mmu_ibvar("r_mmu_ibvar"),
+      r_mmu_dbvar("r_mmu_dbvar"),
+      r_mmu_ietr("r_mmu_ietr"),
+      r_mmu_detr("r_mmu_detr"),
+
+      r_icache_fsm("r_icache_fsm"),
+      r_icache_fsm_save("r_icache_fsm_save"),
+      r_icache_vci_paddr("r_icache_vci_paddr"),
+      r_icache_vaddr_save("r_icache_vaddr_save"),
+
+      r_icache_miss_way("r_icache_miss_way"),
+      r_icache_miss_set("r_icache_miss_set"),
+      r_icache_miss_word("r_icache_miss_word"),
+      r_icache_miss_inval("r_icache_miss_inval"),
+      r_icache_miss_clack("r_icache_miss_clack"),
+
+      r_icache_cc_way("r_icache_cc_way"),
+      r_icache_cc_set("r_icache_cc_set"),
+      r_icache_cc_word("r_icache_cc_word"),
+      r_icache_cc_need_write("r_icache_cc_need_write"),
+
+      r_icache_flush_count("r_icache_flush_count"),
+
+      r_icache_miss_req("r_icache_miss_req"),
+      r_icache_unc_req("r_icache_unc_req"),
+
+      r_icache_tlb_miss_req("r_icache_tlb_read_req"),
+      r_icache_tlb_rsp_error("r_icache_tlb_rsp_error"),
+
+      r_icache_cc_send_req("r_icache_cc_send_req"),
+      r_icache_cc_send_type("r_icache_cc_send_type"),
+      r_icache_cc_send_nline("r_icache_cc_send_nline"),
+      r_icache_cc_send_way("r_icache_cc_send_way"),
+      r_icache_cc_send_updt_tab_idx("r_icache_cc_send_updt_tab_idx"),
+ 
+      r_icache_cleanup_victim_req("r_icache_cleanup_victim_req"),
+      r_icache_cleanup_victim_nline("r_icache_cleanup_victim_nline"),
+
+
+      r_dcache_fsm("r_dcache_fsm"),
+      r_dcache_fsm_cc_save("r_dcache_fsm_cc_save"),
+      r_dcache_fsm_scan_save("r_dcache_fsm_scan_save"),
+
+      r_dcache_wbuf_req("r_dcache_wbuf_req"),
+      r_dcache_updt_data_req("r_dcache_updt_data_req"),
+      r_dcache_updt_dir_req("r_dcache_updt_dir_req"),
+      r_dcache_save_vaddr("r_dcache_save_vaddr"),
+      r_dcache_save_wdata("r_dcache_save_wdata"),
+      r_dcache_save_be("r_dcache_save_be"),
+      r_dcache_save_paddr("r_dcache_save_paddr"),
+      r_dcache_save_cache_way("r_dcache_save_cache_way"),
+      r_dcache_save_cache_set("r_dcache_save_cache_set"),
+      r_dcache_save_cache_word("r_dcache_save_cache_word"),
+
+      r_dcache_dirty_paddr("r_dcache_dirty_paddr"),
+      r_dcache_dirty_way("r_dcache_dirty_way"),
+      r_dcache_dirty_set("r_dcache_dirty_set"),
+
+      r_dcache_vci_paddr("r_dcache_vci_paddr"),
+      r_dcache_vci_wdata("r_dcache_vci_wdata"),
+      r_dcache_vci_miss_req("r_dcache_vci_miss_req"),
+      r_dcache_vci_unc_req("r_dcache_vci_unc_req"),
+      r_dcache_vci_unc_be("r_dcache_vci_unc_be"),
+      r_dcache_vci_unc_write("r_dcache_vci_unc_write"),
+      r_dcache_vci_cas_req("r_dcache_vci_cas_req"),
+      r_dcache_vci_cas_old("r_dcache_vci_cas_old"),
+      r_dcache_vci_cas_new("r_dcache_vci_cas_new"),
+      r_dcache_vci_ll_req("r_dcache_vci_ll_req"),
+      r_dcache_vci_sc_req("r_dcache_vci_sc_req"),
+      r_dcache_vci_sc_data("r_dcache_vci_sc_data"),
+
+      r_dcache_xtn_way("r_dcache_xtn_way"),
+      r_dcache_xtn_set("r_dcache_xtn_set"),
+
+      r_dcache_miss_type("r_dcache_miss_type"),
+      r_dcache_miss_word("r_dcache_miss_word"),
+      r_dcache_miss_way("r_dcache_miss_way"),
+      r_dcache_miss_set("r_dcache_miss_set"),
+      r_dcache_miss_inval("r_dcache_miss_inval"),
+
+      r_dcache_cc_way("r_dcache_cc_way"),
+      r_dcache_cc_set("r_dcache_cc_set"),
+      r_dcache_cc_word("r_dcache_cc_word"),
+      r_dcache_cc_need_write("r_dcache_cc_need_write"),
+
+      r_dcache_flush_count("r_dcache_flush_count"),
+
+      r_dcache_ll_rsp_count("r_dcache_ll_rsp_count"),
+
+      r_dcache_tlb_vaddr("r_dcache_tlb_vaddr"),
+      r_dcache_tlb_ins("r_dcache_tlb_ins"),
+      r_dcache_tlb_pte_flags("r_dcache_tlb_pte_flags"),
+      r_dcache_tlb_pte_ppn("r_dcache_tlb_pte_ppn"),
+//     r_dcache_tlb_cache_way("r_dcache_tlb_cache_way"),
+//     r_dcache_tlb_cache_set("r_dcache_tlb_cache_set"),
+//     r_dcache_tlb_cache_word("r_dcache_tlb_cache_word"),
+      r_dcache_tlb_way("r_dcache_tlb_way"),
+      r_dcache_tlb_set("r_dcache_tlb_set"),
+
+      r_dcache_tlb_inval_line("r_dcache_tlb_inval_line"),
+      r_dcache_tlb_inval_set("r_dcache_tlb_inval_set"),
+
+      r_dcache_xtn_req("r_dcache_xtn_req"),
+      r_dcache_xtn_opcode("r_dcache_xtn_opcode"),
+      
+      r_dcache_cleanup_victim_req("r_dcache_cleanup_victim_req"),
+      r_dcache_cleanup_victim_nline("r_dcache_cleanup_victim_nline"),
+  
+      r_dcache_cc_send_req("r_dcache_cc_send_req"),
+      r_dcache_cc_send_type("r_dcache_cc_send_type"),
+      r_dcache_cc_send_nline("r_dcache_cc_send_nline"),
+      r_dcache_cc_send_way("r_dcache_cc_send_way"),
+      r_dcache_cc_send_updt_tab_idx("r_dcache_cc_send_updt_tab_idx"),
+
+      r_vci_cmd_fsm("r_vci_cmd_fsm"),
+      r_vci_cmd_min("r_vci_cmd_min"),
+      r_vci_cmd_max("r_vci_cmd_max"),
+      r_vci_cmd_cpt("r_vci_cmd_cpt"),
+      r_vci_cmd_imiss_prio("r_vci_cmd_imiss_prio"),
+
+      r_vci_rsp_fsm("r_vci_rsp_fsm"),
+      r_vci_rsp_cpt("r_vci_rsp_cpt"),
+      r_vci_rsp_ins_error("r_vci_rsp_ins_error"),
+      r_vci_rsp_data_error("r_vci_rsp_data_error"),
+      r_vci_rsp_fifo_icache("r_vci_rsp_fifo_icache", 2),	// 2 words depth
+      r_vci_rsp_fifo_dcache("r_vci_rsp_fifo_dcache", 2),	// 2 words depth
+//      r_vci_rsp_fifo_rpktid("r_vci_rsp_fifo_rpktid", 2),    // 2 words depth
+      r_cc_send_data_fifo("r_cc_send_data_fifo", 16),
+
+      r_cc_send_fsm("r_cc_send_fsm"),
+      r_cc_send_last_client("r_cc_send_last_client"),
+
+      r_cc_receive_fsm("r_cc_receive_fsm"),
+      r_cc_receive_data_ins("r_cc_receive_data_ins"),
+
+      r_cc_receive_icache_req("r_cc_receive_icache_req"),
+      r_cc_receive_icache_type("r_cc_receive_icache_type"),
+      r_cc_receive_icache_way("r_cc_receive_icache_way"),
+      r_cc_receive_icache_set("r_cc_receive_icache_set"),
+      r_cc_receive_icache_updt_tab_idx("r_cc_receive_icache_updt_tab_idx"),
+      r_cc_receive_icache_nline("r_cc_receive_icache_nline"),
+
+      r_cc_receive_dcache_req("r_cc_receive_dcache_req"),
+      r_cc_receive_dcache_type("r_cc_receive_dcache_type"),
+      r_cc_receive_dcache_way("r_cc_receive_dcache_way"),
+      r_cc_receive_dcache_set("r_cc_receive_dcache_set"),
+      r_cc_receive_dcache_updt_tab_idx("r_cc_receive_dcache_updt_tab_idx"),
+      r_cc_receive_dcache_nline("r_cc_receive_dcache_nline"),
+      r_cc_receive_dcache_srcid("r_cc_receive_dcache_srcid"),
+
+      r_icache_read_state("r_icache_read_state"),
+      r_dcache_rsp_state("r_dcache_rsp_state"),
+
+      r_iss(this->name(), proc_id),
+      r_wbuf("wbuf", wbuf_nwords, wbuf_nlines, dcache_words ),
+      r_icache("icache", icache_ways, icache_sets, icache_words),
+      r_dcache("dcache", dcache_ways, dcache_sets, dcache_words),
+      r_itlb("itlb", proc_id, itlb_ways,itlb_sets,vci_param::N),
+      r_dtlb("dtlb", proc_id, dtlb_ways,dtlb_sets,vci_param::N)
+{
+    std::cout << "  - Building VciCcVcacheWrapper : " << name << std::endl;
+
+    assert( ((icache_words*vci_param::B) < (1<<vci_param::K)) and
+             "Need more PLEN bits.");
+
+    assert( (vci_param::T > 2) and ((1<<(vci_param::T-1)) >= (wbuf_nlines)) and
+             "Need more TRDID bits.");
+
+    assert( (icache_words == dcache_words) and
+             "icache_words and dcache_words parameters must be equal");
+
+    assert( (itlb_sets == dtlb_sets) and
+             "itlb_sets and dtlb_sets parameters must be etqual");
+
+    assert( (itlb_ways == dtlb_ways) and
+             "itlb_ways and dtlb_ways parameters must be etqual");
+
+    r_mmu_params = (uint32_log2(m_dtlb_ways)   << 29)   | (uint32_log2(m_dtlb_sets)   << 25) |
+                   (uint32_log2(m_dcache_ways) << 22)   | (uint32_log2(m_dcache_sets) << 18) |
+                   (uint32_log2(m_itlb_ways)   << 15)   | (uint32_log2(m_itlb_sets)   << 11) |
+                   (uint32_log2(m_icache_ways) << 8)    | (uint32_log2(m_icache_sets) << 4)  |
+                   (uint32_log2(m_icache_words<<2));
+
+    r_mmu_release = (uint32_t)(1 << 16) | 0x1;
+
+    ////////////////////MODIFIED///////////////////////////////
+    //r_dcache_in_tlb        = new bool[dcache_ways*dcache_sets];
+    //r_dcache_contains_ptd  = new bool[dcache_ways*dcache_sets];
+    r_dcache_content_state = new int  [dcache_ways*dcache_sets];
+    ///////////////////////////////////////////////////////////
+
+
+    SC_METHOD(transition);
+    dont_initialize();
+    sensitive << p_clk.pos();
+
+    SC_METHOD(genMoore);
+    dont_initialize();
+    sensitive << p_clk.neg();
+
+    typename iss_t::CacheInfo cache_info;
+    cache_info.has_mmu = true;
+    cache_info.icache_line_size = icache_words*sizeof(uint32_t);
+    cache_info.icache_assoc = icache_ways;
+    cache_info.icache_n_lines = icache_sets;
+    cache_info.dcache_line_size = dcache_words*sizeof(uint32_t);
+    cache_info.dcache_assoc = dcache_ways;
+    cache_info.dcache_n_lines = dcache_sets;
+    r_iss.setCacheInfo(cache_info);
+}
+
+/////////////////////////////////////
+tmpl(/**/)::~VciCcVCacheWrapper()
+/////////////////////////////////////
+{
+    ////////////MODIFIED/////////////
+    //delete [] r_dcache_in_tlb;
+    //delete [] r_dcache_contains_ptd;
+    delete [] r_dcache_content_state;
+    /////////////////////////////////
+    print_stats();
+}
+
+////////////////////////
+tmpl(void)::print_cpi()
+////////////////////////
+{
+    std::cout << name() << " CPI = "
+        << (float)m_cpt_total_cycles/(m_cpt_total_cycles - m_cpt_frz_cycles) << std::endl ;
+}
+
+////////////////////////////////////
+tmpl(void)::print_trace(size_t mode)
+////////////////////////////////////
+{
+    // b0 : write buffer trace
+    // b1 : write buffer verbose
+    // b2 : dcache trace
+    // b3 : icache trace
+    // b4 : dtlb trace
+    // b5 : itlb trace
+    std::cout << std::dec << "PROC " << name() << std::endl;
+
+    std::cout << "  " << m_ireq << std::endl;
+    std::cout << "  " << m_irsp << std::endl;
+    std::cout << "  " << m_dreq << std::endl;
+    std::cout << "  " << m_drsp << std::endl;
+
+    /**/std::cout << r_iss << std::endl;
+
+    std::cout << "  " << icache_fsm_state_str[r_icache_fsm.read()]
+              << " | " << dcache_fsm_state_str[r_dcache_fsm.read()]
+              << " | " << cmd_fsm_state_str[r_vci_cmd_fsm.read()]
+              << " | " << rsp_fsm_state_str[r_vci_rsp_fsm.read()]
+              << " | " << cc_receive_fsm_state_str[r_cc_receive_fsm.read()]
+              << " | " << cc_send_fsm_state_str[r_cc_send_fsm.read()]
+              << " | MMU = " << r_mmu_mode.read();
+    if (r_dcache_updt_data_req.read() ) std::cout << " | P1_UPDT";
+    if (r_dcache_wbuf_req.read() ) std::cout << " | P1_WBUF";
+    std::cout << std::endl;
+
+    if(mode & 0x01)
+    {
+        r_wbuf.printTrace((mode>>1)&1);
+    }
+    if(mode & 0x04)
+    {
+        std::cout << "  Data Cache" << std::endl;
+        //r_dcache.printTrace();
+    }
+    if(mode & 0x08)
+    {
+        std::cout << "  Instruction Cache" << std::endl;
+        //r_icache.printTrace();
+    }
+    if(mode & 0x10)
+    {
+        std::cout << "  Data TLB" << std::endl;
+        r_dtlb.printTrace();
+    }
+    if(mode & 0x20)
+    {
+        std::cout << "  Instruction TLB" << std::endl;
+        r_itlb.printTrace();
+    }
+}
+
+//////////////////////////////////////////
+tmpl(void)::cache_monitor( paddr_t addr )
+//////////////////////////////////////////
+{
+    bool        cache_hit;
+    size_t	    cache_way = 0;
+    size_t	    cache_set = 0;
+    size_t	    cache_word = 0;
+    uint32_t	cache_rdata = 0;
+
+    cache_hit = r_dcache.read_neutral( addr,
+                                       &cache_rdata,
+                                       &cache_way,
+                                       &cache_set,
+                                       &cache_word );
+
+    if ( cache_hit != m_debug_previous_d_hit )
+    {
+        std::cout << "Monitor PROC " << name()
+                  << " DCACHE at cycle " << std::dec << m_cpt_total_cycles
+                  << " / HIT = " << cache_hit 
+                  << " / PADDR = " << std::hex << addr
+                  << " / DATA = " << cache_rdata 
+                  << " / WAY = " << cache_way << std::endl;
+	    m_debug_previous_d_hit = cache_hit;
+    }
+
+    cache_hit = r_icache.read_neutral( addr,
+                                       &cache_rdata,
+                                       &cache_way,
+                                       &cache_set,
+                                       &cache_word );
+
+    if ( cache_hit != m_debug_previous_i_hit )
+    {
+        std::cout << "Monitor PROC " << name()
+                  << " ICACHE at cycle " << std::dec << m_cpt_total_cycles
+                  << " / HIT = " << cache_hit 
+                  << " / PADDR = " << std::hex << addr
+                  << " / DATA = " << cache_rdata 
+                  << " / WAY = " << cache_way << std::endl;
+	    m_debug_previous_i_hit = cache_hit;
+    }
+}
+
+
+////////////////////////
+tmpl(void)::print_stats()
+////////////////////////
+{
+    float run_cycles = (float)(m_cpt_total_cycles - m_cpt_frz_cycles);
+    std::cout << name() << std::endl
+        << "- CPI                     = " << std::dec <<(float)m_cpt_total_cycles/run_cycles << std::endl
+        << "- READ RATE               = " << (float)m_cpt_data_read/run_cycles << std::endl
+        << "- WRITE RATE              = " << (float)m_cpt_data_write/run_cycles << std::endl
+        << "- IMISS_RATE              = " << (float)m_cpt_ins_miss/m_cpt_ins_read << std::endl
+        << "- DMISS RATE              = " << (float)m_cpt_data_miss/(m_cpt_data_read-m_cpt_unc_read) << std::endl
+        << "- INS MISS COST           = " << (float)m_cost_ins_miss_frz/m_cpt_ins_miss << std::endl
+        << "- DATA MISS COST          = " << (float)m_cost_data_miss_frz/m_cpt_data_miss << std::endl
+        << "- WRITE COST              = " << (float)m_cost_write_frz/m_cpt_data_write << std::endl
+        << "- UNC COST                = " << (float)m_cost_unc_read_frz/m_cpt_unc_read << std::endl
+        << "- UNCACHED READ RATE      = " << (float)m_cpt_unc_read/m_cpt_data_read << std::endl
+        << "- CACHED WRITE RATE       = " << (float)m_cpt_write_cached/m_cpt_data_write << std::endl
+        << "- INS TLB MISS RATE       = " << (float)m_cpt_ins_tlb_miss/m_cpt_ins_tlb_read << std::endl
+        << "- DATA TLB MISS RATE      = " << (float)m_cpt_data_tlb_miss/m_cpt_data_tlb_read << std::endl
+        << "- ITLB MISS COST          = " << (float)m_cost_ins_tlb_miss_frz/m_cpt_ins_tlb_miss << std::endl
+        << "- DTLB MISS COST          = " << (float)m_cost_data_tlb_miss_frz/m_cpt_data_tlb_miss << std::endl
+        << "- ITLB UPDATE ACC COST    = " << (float)m_cost_ins_tlb_update_acc_frz/m_cpt_ins_tlb_update_acc << std::endl
+        << "- DTLB UPDATE ACC COST    = " << (float)m_cost_data_tlb_update_acc_frz/m_cpt_data_tlb_update_acc << std::endl
+        << "- DTLB UPDATE DIRTY COST  = " << (float)m_cost_data_tlb_update_dirty_frz/m_cpt_data_tlb_update_dirty << std::endl
+        << "- ITLB HIT IN DCACHE RATE = " << (float)m_cpt_ins_tlb_hit_dcache/m_cpt_ins_tlb_miss << std::endl
+        << "- DTLB HIT IN DCACHE RATE = " << (float)m_cpt_data_tlb_hit_dcache/m_cpt_data_tlb_miss << std::endl
+        //<< "- DCACHE FROZEN BY ITLB   = " << (float)m_cost_ins_tlb_occup_cache_frz/m_cpt_dcache_frz_cycles << std::endl
+        << "- DCACHE FOR TLB %        = " << (float)m_cpt_tlb_occup_dcache/(m_dcache_ways*m_dcache_sets) << std::endl
+        << "- NB CC BROADCAST         = " << m_cpt_cc_broadcast << std::endl
+        << "- NB CC UPDATE DATA       = " << m_cpt_cc_update_dcache << std::endl
+        << "- NB CC INVAL DATA        = " << m_cpt_cc_inval_dcache << std::endl
+        << "- NB CC INVAL INS         = " << m_cpt_cc_inval_icache << std::endl
+        << "- CC BROADCAST COST       = " << (float)m_cost_broadcast_frz/m_cpt_cc_broadcast << std::endl
+        << "- CC UPDATE DATA COST     = " << (float)m_cost_updt_data_frz/m_cpt_cc_update_dcache << std::endl
+        << "- CC INVAL DATA COST      = " << (float)m_cost_inval_data_frz/m_cpt_cc_inval_dcache << std::endl
+        << "- CC INVAL INS COST       = " << (float)m_cost_inval_ins_frz/m_cpt_cc_inval_icache << std::endl
+        << "- NB CC CLEANUP DATA      = " << m_cpt_cc_cleanup_data << std::endl
+        << "- NB CC CLEANUP INS       = " << m_cpt_cc_cleanup_ins << std::endl
+        << "- IMISS TRANSACTION       = " << (float)m_cost_imiss_transaction/m_cpt_imiss_transaction << std::endl
+        << "- DMISS TRANSACTION       = " << (float)m_cost_dmiss_transaction/m_cpt_dmiss_transaction << std::endl
+        << "- UNC TRANSACTION         = " << (float)m_cost_unc_transaction/m_cpt_unc_transaction << std::endl
+        << "- WRITE TRANSACTION       = " << (float)m_cost_write_transaction/m_cpt_write_transaction << std::endl
+        << "- NB WRITE TRANSACTION    = " << m_cpt_write_transaction << std::endl
+        << "- NB WRITE WORDS VCI      = " << m_length_write_transaction << std::endl
+        << "- NB WRITE PROC           = " << m_cpt_data_write << std::endl
+        << "- NB WRITE BACK           = " << m_cpt_data_write_back << std::endl
+        << "- NB WRITE BACK COHERENCE = " << m_cpt_data_cleanup << std::endl
+        << "- NB DATA SC              = " << m_cpt_data_sc << std::endl
+        << "- WRITE LENGTH            = " << (float)m_length_write_transaction/m_cpt_write_transaction << std::endl
+        << "- ITLB MISS TRANSACTION   = " << (float)m_cost_itlbmiss_transaction/m_cpt_itlbmiss_transaction << std::endl
+        << "- DTLB MISS TRANSACTION   = " << (float)m_cost_dtlbmiss_transaction/m_cpt_dtlbmiss_transaction << std::endl
+
+        << "- DMISS TRANSACTION       = " << m_cpt_dmiss_transaction << std::endl
+        << "- DUNC TRANSACTION        = " << m_cpt_dunc_transaction << std::endl
+        << "- LL TRANSACTION          = " << m_cpt_ll_transaction << std::endl
+        << "- WRITE DATA MISS         = " << m_cpt_data_write_miss << std::endl
+        << "- WRITE DATA ON ZOMBI     = " << m_cpt_data_write_on_zombi << std::endl
+        << "- WRITE DATA ON ZOMBI NCC = " << m_cpt_data_write_on_zombi_ncc << std::endl
+        << "- CLEANUP DATA NOT DIRTY  = " << m_cpt_cleanup_data_not_dirty << std::endl
+        << "- CLEANUP DATA DIRTY WORD = " << m_cpt_cleanup_data_dirty_word << std::endl;
+}
+
+////////////////////////
+tmpl(void)::clear_stats()
+////////////////////////
+{
+    m_cpt_dcache_data_read  = 0;
+    m_cpt_dcache_data_write = 0;
+    m_cpt_dcache_dir_read   = 0;
+    m_cpt_dcache_dir_write  = 0;
+    m_cpt_icache_data_read  = 0;
+    m_cpt_icache_data_write = 0;
+    m_cpt_icache_dir_read   = 0;
+    m_cpt_icache_dir_write  = 0;
+
+    m_cpt_frz_cycles        = 0;
+//    m_cpt_dcache_frz_cycles = 0;
+    m_cpt_total_cycles      = 0;
+
+//    m_cpt_read         = 0;
+//    m_cpt_write        = 0;
+    m_cpt_data_miss    = 0;
+    m_cpt_ins_miss     = 0;
+    m_cpt_unc_read     = 0;
+    m_cpt_write_cached = 0;
+    m_cpt_ins_read     = 0;
+
+    m_cost_write_frz     = 0;
+    m_cost_data_miss_frz = 0;
+    m_cost_unc_read_frz  = 0;
+    m_cost_ins_miss_frz  = 0;
+
+    m_cpt_imiss_transaction      = 0;
+    m_cpt_dmiss_transaction      = 0;
+    m_cpt_unc_transaction        = 0;
+    m_cpt_write_transaction      = 0;
+    m_cpt_icache_unc_transaction = 0;
+
+    m_cost_imiss_transaction      = 0;
+    m_cost_dmiss_transaction      = 0;
+    m_cost_unc_transaction        = 0;
+    m_cost_write_transaction      = 0;
+    m_cost_icache_unc_transaction = 0;
+    m_length_write_transaction    = 0;
+
+    m_cpt_ins_tlb_read       = 0;
+    m_cpt_ins_tlb_miss       = 0;
+    m_cpt_ins_tlb_update_acc = 0;
+
+    m_cpt_data_tlb_read         = 0;
+    m_cpt_data_tlb_miss         = 0;
+    m_cpt_data_tlb_update_acc   = 0;
+    m_cpt_data_tlb_update_dirty = 0;
+    m_cpt_ins_tlb_hit_dcache    = 0;
+    m_cpt_data_tlb_hit_dcache   = 0;
+    m_cpt_ins_tlb_occup_cache   = 0;
+    m_cpt_data_tlb_occup_cache  = 0;
+
+    m_cost_ins_tlb_miss_frz          = 0;
+    m_cost_data_tlb_miss_frz         = 0;
+    m_cost_ins_tlb_update_acc_frz    = 0;
+    m_cost_data_tlb_update_acc_frz   = 0;
+    m_cost_data_tlb_update_dirty_frz = 0;
+    m_cost_ins_tlb_occup_cache_frz   = 0;
+    m_cost_data_tlb_occup_cache_frz  = 0;
+
+    m_cpt_itlbmiss_transaction      = 0;
+    m_cpt_itlb_ll_transaction       = 0;
+    m_cpt_itlb_sc_transaction       = 0;
+    m_cpt_dtlbmiss_transaction      = 0;
+    m_cpt_dtlb_ll_transaction       = 0;
+    m_cpt_dtlb_sc_transaction       = 0;
+    m_cpt_dtlb_ll_dirty_transaction = 0;
+    m_cpt_dtlb_sc_dirty_transaction = 0;
+
+    m_cost_itlbmiss_transaction      = 0;
+    m_cost_itlb_ll_transaction       = 0;
+    m_cost_itlb_sc_transaction       = 0;
+    m_cost_dtlbmiss_transaction      = 0;
+    m_cost_dtlb_ll_transaction       = 0;
+    m_cost_dtlb_sc_transaction       = 0;
+    m_cost_dtlb_ll_dirty_transaction = 0;
+    m_cost_dtlb_sc_dirty_transaction = 0;
+
+//    m_cpt_cc_update_data = 0;
+//    m_cpt_cc_inval_ins   = 0;
+//    m_cpt_cc_inval_data  = 0;
+    m_cpt_cc_broadcast   = 0;
+
+    m_cost_updt_data_frz  = 0;
+    m_cost_inval_ins_frz  = 0;
+    m_cost_inval_data_frz = 0;
+    m_cost_broadcast_frz  = 0;
+
+    m_cpt_cc_cleanup_data = 0;
+    m_cpt_cc_cleanup_ins  = 0;
+
+    m_cpt_cleanup_data_not_dirty  = 0;
+    m_cpt_cleanup_data_dirty_word = 0;
+    m_cpt_data_write_miss = 0;
+    m_cpt_data_write_on_zombi = 0;
+    m_cpt_data_write_on_zombi_ncc = 0;
+
+}
+
+
+
+/////////////////////////
+tmpl(void)::transition()
+/////////////////////////
+{
+    if ( not p_resetn.read() )
+    {
+        r_iss.reset();
+        r_wbuf.reset();
+        r_icache.reset();
+        r_dcache.reset();
+        r_itlb.reset();
+        r_dtlb.reset();
+
+        r_dcache_fsm      = DCACHE_IDLE;
+        r_icache_fsm      = ICACHE_IDLE;
+        r_vci_cmd_fsm     = CMD_IDLE;
+        r_vci_rsp_fsm     = RSP_IDLE;
+        r_cc_receive_fsm  = CC_RECEIVE_IDLE;
+        r_cc_send_fsm     = CC_SEND_IDLE;
+
+        // reset data physical address extension
+        r_dcache_paddr_ext = 0;
+
+        // reset dcache directory extension
+        for (size_t i=0 ; i< m_dcache_ways*m_dcache_sets ; i++)
+        {
+            // MODIFIED
+            //r_dcache_in_tlb[i]        = false;
+            //r_dcache_contains_ptd[i]  = false;
+            r_dcache_content_state[i] = LINE_EMPTY;
+        }
+
+        // Response FIFOs and cleanup buffer
+        r_vci_rsp_fifo_icache.init();
+        r_vci_rsp_fifo_dcache.init();
+        r_cc_send_data_fifo.init();
+
+        // ICACHE & DCACHE activated
+        // ITLB & DTLB desactivated
+        r_mmu_mode = 0x3;
+
+	    // No request from ICACHE FSM to CMD FSM
+        r_icache_miss_req          = false;
+        r_icache_unc_req           = false;
+
+        // No request from ICACHE_FSM to DCACHE FSM
+        r_icache_tlb_miss_req      = false;
+
+        // No request from ICACHE_FSM to CC_SEND FSM
+        r_icache_cc_send_req       = false;
+
+        r_icache_clack_req         = false;
+
+        // No pending write in pipeline
+        r_dcache_wbuf_req          = false;
+
+        // No request from DCACHE_FSM to CMD_FSM
+        r_dcache_vci_miss_req      = false;
+        r_dcache_vci_unc_req       = false;
+        r_dcache_vci_cas_req       = false;
+        r_dcache_vci_ll_req        = false;
+        r_dcache_vci_sc_req        = false;
+
+        r_dcache_updt_data_req     = false;
+        r_dcache_updt_dir_req      = false;
+
+        // No processor XTN request pending
+        r_dcache_xtn_req           = false;
+
+        // No request from DCACHE FSM to CC_SEND FSM
+        r_dcache_cc_send_req       = false;
+        r_dcache_cc_send_inval_is_config = false;
+        r_dcache_clack_req         = false;
+
+        // No request from CC_RECEIVE FSM to ICACHE/DCACHE FSMs
+        r_cc_receive_icache_req    = false;
+        r_cc_receive_dcache_req    = false;
+
+        // last cc_send client was dcache
+        r_cc_send_last_client      = false;
+
+        // No pending cleanup after a replacement
+        r_icache_miss_clack        = false;
+        r_dcache_miss_clack        = false;
+
+        // No signalisation of a coherence request matching a pending miss
+        r_icache_miss_inval        = false;
+        r_dcache_miss_inval        = false;
+        r_dcache_miss_updt         = false;
+
+        r_dspin_clack_req          = false;
+
+        // No signalisation  of errors
+        r_vci_rsp_ins_error        = false;
+        r_vci_rsp_data_error       = false;
+
+        // Debug variables
+        m_debug_previous_i_hit     = false;
+        m_debug_previous_d_hit     = false;
+        m_debug_activated	       = false;
+
+        // SPECIAL REGISTERS ODCCP
+        r_dcache_cc_line_dirty  = false;
+        r_dcache_cc_line_no_shared = false;
+        r_dcache_miss_victim_no_coherence = false;
+        r_dcache_line_no_coherence = false;
+        r_cc_send_cpt_word = 0;
+        r_dcache_miss_data_cpt = 0;
+        r_dcache_miss_data_addr = 0;
+        r_dcache_xtn_data_cpt = 0;
+        r_dcache_xtn_flush_data_cpt = 0;
+        r_dcache_cc_inval_data_cpt = 0;
+
+        r_dcache_cleanup_victim_req = false;
+        r_dcache_cleanup_victim_line_dirty = false;
+
+        // activity counters
+        m_cpt_dcache_data_read  = 0;
+        m_cpt_dcache_data_write = 0;
+        m_cpt_dcache_dir_read   = 0;
+        m_cpt_dcache_dir_write  = 0;
+        m_cpt_icache_data_read  = 0;
+        m_cpt_icache_data_write = 0;
+        m_cpt_icache_dir_read   = 0;
+        m_cpt_icache_dir_write  = 0;
+
+        m_cpt_frz_cycles        = 0;
+        m_cpt_total_cycles      = 0;
+        m_cpt_stop_simulation   = 0;
+
+        m_cpt_data_miss         = 0;
+        m_cpt_data_write        = 0;
+        m_cpt_data_sc           = 0;
+        m_cpt_data_write_back   = 0;
+        m_cpt_data_cleanup      = 0;
+        m_cpt_cleanup_data_not_dirty = 0; 
+        m_cpt_ins_miss          = 0;
+        m_cpt_unc_read          = 0;
+        m_cpt_write_cached      = 0;
+        m_cpt_ins_read          = 0;
+
+        m_cost_write_frz        = 0;
+        m_cost_data_miss_frz    = 0;
+        m_cost_unc_read_frz     = 0;
+        m_cost_ins_miss_frz     = 0;
+
+        m_cpt_imiss_transaction = 0;
+        m_cpt_dmiss_transaction = 0;
+        m_cpt_unc_transaction   = 0;
+        m_cpt_write_transaction = 0;
+        m_cpt_icache_unc_transaction = 0;
+
+        m_cost_imiss_transaction      = 0;
+        m_cost_dmiss_transaction      = 0;
+        m_cost_unc_transaction        = 0;
+        m_cost_write_transaction      = 0;
+        m_cost_icache_unc_transaction = 0;
+        m_length_write_transaction    = 0;
+
+        m_cpt_ins_tlb_read       = 0;
+        m_cpt_ins_tlb_miss       = 0;
+        m_cpt_ins_tlb_update_acc = 0;
+
+        m_cpt_data_tlb_read         = 0;
+        m_cpt_data_tlb_miss         = 0;
+        m_cpt_data_tlb_update_acc   = 0;
+        m_cpt_data_tlb_update_dirty = 0;
+        m_cpt_ins_tlb_hit_dcache    = 0;
+        m_cpt_data_tlb_hit_dcache   = 0;
+        m_cpt_ins_tlb_occup_cache   = 0;
+        m_cpt_data_tlb_occup_cache  = 0;
+
+        m_cost_ins_tlb_miss_frz          = 0;
+        m_cost_data_tlb_miss_frz         = 0;
+        m_cost_ins_tlb_update_acc_frz    = 0;
+        m_cost_data_tlb_update_acc_frz   = 0;
+        m_cost_data_tlb_update_dirty_frz = 0;
+        m_cost_ins_tlb_occup_cache_frz   = 0;
+        m_cost_data_tlb_occup_cache_frz  = 0;
+
+    	m_cpt_ins_tlb_inval       = 0;
+    	m_cpt_data_tlb_inval      = 0;
+    	m_cost_ins_tlb_inval_frz  = 0;
+    	m_cost_data_tlb_inval_frz = 0;
+
+        m_cpt_cc_broadcast   = 0;
+
+   	    m_cost_updt_data_frz  = 0;
+   	    m_cost_inval_ins_frz  = 0;
+   	    m_cost_inval_data_frz = 0;
+   	    m_cost_broadcast_frz  = 0;
+
+   	    m_cpt_cc_cleanup_data = 0;
+   	    m_cpt_cc_cleanup_ins  = 0;
+
+        m_cpt_cleanup_data_not_dirty  = 0;
+        m_cpt_cleanup_data_dirty_word = 0;
+        m_cpt_data_write_miss = 0;
+        m_cpt_data_write_on_zombi = 0;
+        m_cpt_data_write_on_zombi_ncc = 0;
+
+        m_cpt_itlbmiss_transaction      = 0;
+        m_cpt_itlb_ll_transaction       = 0;
+        m_cpt_itlb_sc_transaction       = 0;
+        m_cpt_dtlbmiss_transaction      = 0;
+        m_cpt_dtlb_ll_transaction       = 0;
+        m_cpt_dtlb_sc_transaction       = 0;
+        m_cpt_dtlb_ll_dirty_transaction = 0;
+        m_cpt_dtlb_sc_dirty_transaction = 0;
+
+        m_cost_itlbmiss_transaction      = 0;
+        m_cost_itlb_ll_transaction       = 0;
+        m_cost_itlb_sc_transaction       = 0;
+        m_cost_dtlbmiss_transaction      = 0;
+        m_cost_dtlb_ll_transaction       = 0;
+        m_cost_dtlb_sc_transaction       = 0;
+        m_cost_dtlb_ll_dirty_transaction = 0;
+        m_cost_dtlb_sc_dirty_transaction = 0;
+/*
+        m_cpt_dcache_frz_cycles = 0;
+        m_cpt_read              = 0;
+        m_cpt_write             = 0;
+   	    m_cpt_cc_update_data = 0;
+   	    m_cpt_cc_inval_ins   = 0;
+   	    m_cpt_cc_inval_data  = 0;
+*/
+
+        for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_icache      [i]   = 0;
+        for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_dcache      [i]   = 0;
+        for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_cmd         [i]   = 0;
+        for (uint32_t i=0; i<32 ; ++i) m_cpt_fsm_rsp         [i]   = 0;
+
+        // init the llsc reservation buffer
+        r_dcache_llsc_valid = false;
+        m_monitor_ok = false;
+
+        return;
+    }
+
+    // Response FIFOs default values
+    bool       vci_rsp_fifo_icache_get   = false;
+    bool       vci_rsp_fifo_icache_put   = false;
+    uint32_t   vci_rsp_fifo_icache_data  = 0;
+
+    bool       vci_rsp_fifo_dcache_get   = false;
+    bool       vci_rsp_fifo_dcache_put   = false;
+    uint32_t   vci_rsp_fifo_dcache_data  = 0;
+    bool       vci_rsp_fifo_rpktid_get   = false;
+    bool       vci_rsp_fifo_rpktid_put   = false;
+    bool       vci_rsp_fifo_rpktid       = false;
+
+    // FIFO for cleanup data updt
+    bool       cleanup_data_updt_fifo_dcache_get   = false;
+    bool       cleanup_data_updt_fifo_dcache_put   = false;
+    uint32_t   cleanup_data_updt_fifo_dcache_data  = 0;
+
+    // updt fifo
+    bool       cc_receive_updt_fifo_get  = false;
+    bool       cc_receive_updt_fifo_put  = false;
+    uint32_t   cc_receive_updt_fifo_be   = 0;
+    uint32_t   cc_receive_updt_fifo_data = 0;
+    bool       cc_receive_updt_fifo_eop  = false;
+
+#ifdef INSTRUMENTATION
+    m_cpt_fsm_dcache     [r_dcache_fsm.read()    ] ++;
+    m_cpt_fsm_icache     [r_icache_fsm.read()    ] ++;
+    m_cpt_fsm_cmd        [r_vci_cmd_fsm.read()   ] ++;
+    m_cpt_fsm_rsp        [r_vci_rsp_fsm.read()   ] ++;
+    m_cpt_fsm_cc_send    [r_cc_send_fsm.read()   ] ++;
+    m_cpt_fsm_cc_receive [r_cc_receive_fsm.read()] ++;
+#endif
+
+    m_cpt_total_cycles++;
+
+    m_debug_activated = (m_cpt_total_cycles > m_debug_start_cycle) and m_debug_ok;
+
+    /////////////////////////////////////////////////////////////////////
+    // Get data and instruction requests from processor
+    ///////////////////////////////////////////////////////////////////////
+
+    r_iss.getRequests(m_ireq, m_dreq);
+
+    ////////////////////////////////////////////////////////////////////////////////////
+    //      ICACHE_FSM
+    //
+    // 1/ Coherence operations
+    //    They are handled as interrupts generated by the CC_RECEIVE FSM.
+    //    - There is a coherence request when r_tgt_icache_req is set.
+    //    They are taken in IDLE, MISS_WAIT, MISS_DIR_UPDT, UNC_WAIT, states.
+    //    - There is a cleanup ack request when r_cleanup_icache_req is set.
+    //    They are taken in IDLE, MISS_SELECT, MISS_CLEAN, MISS_WAIT,
+    //    MISS_DATA_UPDT, MISS_DIR_UPDT and UNC_WAIT states.
+    //    - For both types of requests, actions associated to the pre-empted state
+    //    are not executed. The DCACHE FSM goes to the proper sub-FSM (CC_CHECK
+    //    or CC_CLACK) to execute the requested coherence operation, and returns
+    //    to the pre-empted state.
+    //
+    // 2/ Processor requests
+    //    They are taken in IDLE state only. In case of cache miss, or uncacheable
+    //    instruction, the ICACHE FSM request a VCI transaction to CMD FSM,
+    //    using the r_icache_miss_req or r_icache_unc_req flip-flops. These
+    //    flip-flops are reset when the transaction starts.
+    //    - In case of miss the ICACHE FSM  goes to the ICACHE_MISS_SELECT state
+    //    to select a slot and possibly request a cleanup transaction to the CC_SEND FSM.
+    //    It goes next to the ICACHE_MISS_WAIT state waiting a response from RSP FSM,
+    //    The availability of the missing cache line is signaled by the response fifo,
+    //    and the cache update is done (one word per cycle) in the ICACHE_MISS_DATA_UPDT
+    //    and ICACHE_MISS_DIR_UPDT states.
+    //    - In case of uncacheable instruction, the ICACHE FSM goes to ICACHE_UNC_WAIT
+    //    to wait the response from the RSP FSM, through the response fifo.
+    //    The missing instruction is directly returned to processor in this state.
+    //
+    // 3/ TLB miss
+    //    In case of tlb miss, the ICACHE FSM request to the DCACHE FSM to update the
+    //    ITLB using the r_icache_tlb_miss_req flip-flop and the r_icache_tlb_miss_vaddr
+    //    register, and goes to the ICACHE_TLB_WAIT state.
+    //    The tlb update is entirely done by the DCACHE FSM (who becomes the owner
+    //    of ITLB until the update is completed, and reset r_icache_tlb_miss_req
+    //    to signal the completion.
+    //
+    // 4/ XTN requests
+    //    The DCACHE FSM signals XTN processor requests to ICACHE_FSM
+    //    using the r_dcache_xtn_req flip-flop.
+    //    The request opcode and the address to be invalidated are transmitted
+    //    in the r_dcache_xtn_opcode and r_dcache_save_wdata registers respectively.
+    //    The r_dcache_xtn_req flip-flop is reset by the ICACHE_FSM when the operation
+    //    is completed.
+    //
+    // 5/ Error Handling
+    //    The r_vci_rsp_ins_error flip-flop is set by the RSP FSM in case of bus error
+    //    in a cache miss or uncacheable read VCI transaction. Nothing is written
+    //    in the response fifo. This flip-flop is reset by the ICACHE-FSM.
+    ////////////////////////////////////////////////////////////////////////////////////////
+
+    // default value for m_irsp
+    m_irsp.valid       = false;
+    m_irsp.error       = false;
+    m_irsp.instruction = 0;
+
+    switch( r_icache_fsm.read() )
+    {
+    /////////////////
+    case ICACHE_IDLE:	// In this state, we handle processor requests, XTN requests,
+                        // and coherence requests with a fixed priority:
+                        // 1/ Coherence requests                        => ICACHE_CC_CHECK
+                        // 2/ XTN processor requests (from DCACHE FSM)  => ICACHE_XTN_*
+                        // 3/ tlb miss                                  => ICACHE_TLB_WAIT
+                        // 4/ cacheable read miss                       => ICACHE_MISS_SELECT
+                        // 5/ uncacheable read miss                     => ICACHE_UNC_REQ
+    {
+        // coherence clack interrupt
+        if ( r_icache_clack_req.read() )
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+
+        // coherence interrupt
+        if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+
+        // XTN requests sent by DCACHE FSM
+        // These request are not executed in this IDLE state, because
+        // they require access to icache or itlb, that are already accessed
+        if ( r_dcache_xtn_req.read() )
+        {
+            if ( (int)r_dcache_xtn_opcode.read() == (int)iss_t::XTN_PTPR )
+            {
+                r_icache_fsm         = ICACHE_XTN_TLB_FLUSH;
+            }
+            else if ( (int)r_dcache_xtn_opcode.read() == (int)iss_t::XTN_ICACHE_FLUSH)
+            {
+                r_icache_flush_count = 0;
+                r_icache_fsm         = ICACHE_XTN_CACHE_FLUSH;
+            }
+            else if ( (int)r_dcache_xtn_opcode.read() == (int)iss_t::XTN_ITLB_INVAL)
+            {
+                r_icache_fsm         = ICACHE_XTN_TLB_INVAL;
+            }
+            else if ( (int)r_dcache_xtn_opcode.read() == (int)iss_t::XTN_ICACHE_INVAL)
+            {
+                r_icache_fsm         = ICACHE_XTN_CACHE_INVAL_VA;
+            }
+            else if ( (int)r_dcache_xtn_opcode.read() == (int)iss_t::XTN_MMU_ICACHE_PA_INV)
+            {
+		        if (sizeof(paddr_t) <= 32)
+                {
+			        assert(r_mmu_word_hi.read() == 0 &&
+			        "illegal XTN request in ICACHE: high bits should be 0 for 32bit paddr");
+			        r_icache_vci_paddr = (paddr_t)r_mmu_word_lo.read();
+                }
+                else
+                {
+			        r_icache_vci_paddr = (uint64_t)r_mmu_word_hi.read() << 32 |
+				                         (paddr_t)r_mmu_word_lo.read();
+		        }
+                r_icache_fsm         = ICACHE_XTN_CACHE_INVAL_PA;
+            }
+            else
+            {
+               assert( false and
+               "undefined XTN request received by ICACHE FSM");
+            }
+            break;
+        } // end if xtn_req
+
+        // processor request
+        if ( m_ireq.valid )
+        {
+            bool	    cacheable;
+            paddr_t	    paddr;
+            bool        tlb_hit = false;
+            pte_info_t  tlb_flags;
+            size_t      tlb_way;
+            size_t      tlb_set;
+            paddr_t     tlb_nline;
+            uint32_t    cache_inst = 0;
+            size_t      cache_way;
+            size_t      cache_set;
+            size_t      cache_word;
+            int         cache_state = CACHE_SLOT_STATE_INVALID;
+
+            // We register processor request
+            r_icache_vaddr_save = m_ireq.addr;
+
+            // sytematic itlb access (if activated)
+            if ( r_mmu_mode.read() & INS_TLB_MASK )
+            {
+
+#ifdef INSTRUMENTATION
+m_cpt_ins_tlb_read++;
+#endif
+                tlb_hit = r_itlb.translate( m_ireq.addr,
+                                            &paddr,
+                                            &tlb_flags,
+                                            &tlb_nline,	// unused
+                                            &tlb_way,	// unused
+                                            &tlb_set );	// unused
+            }
+            else
+            {
+                paddr = (paddr_t)m_ireq.addr;
+            }
+
+            // systematic icache access (if activated)
+            if ( r_mmu_mode.read() & INS_CACHE_MASK )
+            {
+
+
+#ifdef INSTRUMENTATION
+m_cpt_icache_data_read++;
+m_cpt_icache_dir_read++;
+#endif
+                r_icache.read( paddr,
+                               &cache_inst,
+                               &cache_way,
+                               &cache_set,
+                               &cache_word,
+                               &cache_state );
+
+                assert( cache_state != CACHE_SLOT_STATE_MODIFIED && "an instruction line should not be in state MODIFIED!!");
+            }
+
+            // We compute cacheability and check access rights:
+            // - If MMU activated : cacheability is defined by the C bit in the PTE,
+            //   and the access rights are defined by the U and X bits in the PTE.
+            // - If MMU not activated : cacheability is defined by the segment table,
+            //   and there is no access rights checking
+
+            if ( not (r_mmu_mode.read() & INS_TLB_MASK) ) 	// tlb not activated:
+            {
+                // cacheability
+                if ( not (r_mmu_mode.read() & INS_CACHE_MASK) ) cacheable = false;
+                else     cacheable = m_cacheability_table[(uint64_t)m_ireq.addr];
+            }
+            else						        // itlb activated
+            {
+                if ( tlb_hit )	// ITLB hit
+                {
+                    // cacheability
+                    if ( not (r_mmu_mode.read() & INS_CACHE_MASK) ) cacheable = false;
+                    else  cacheable = tlb_flags.c;
+
+                    // access rights checking
+                    if ( not tlb_flags.u && (m_ireq.mode == iss_t::MODE_USER) )
+                    {
+                        r_mmu_ietr          = MMU_READ_PRIVILEGE_VIOLATION;
+                        r_mmu_ibvar         = m_ireq.addr;
+                        m_irsp.valid        = true;
+                        m_irsp.error        = true;
+                        m_irsp.instruction  = 0;
+                        break;
+                    }
+                    else if ( not tlb_flags.x )
+                    {
+                        r_mmu_ietr          = MMU_READ_EXEC_VIOLATION;
+                        r_mmu_ibvar         = m_ireq.addr;
+                        m_irsp.valid        = true;
+                        m_irsp.error        = true;
+                        m_irsp.instruction  = 0;
+                        break;
+                    }
+                }
+                else           // ITLB miss
+                {
+
+#ifdef INSTRUMENTATION
+m_cpt_ins_tlb_miss++;
+#endif
+                    r_icache_fsm          = ICACHE_TLB_WAIT;
+                    r_icache_tlb_miss_req = true;
+                    break;
+                }
+            } // end if itlb activated
+
+            // physical address registration
+            r_icache_vci_paddr   = paddr;
+
+            // Finally, we send the response to processor, and compute next state
+            if ( cacheable )
+            {
+                if (cache_state == CACHE_SLOT_STATE_INVALID)	    // cache miss
+                {
+
+#ifdef INSTRUMENTATION
+m_cpt_ins_miss++;
+#endif
+                    // we request a VCI transaction
+                    r_icache_fsm      = ICACHE_MISS_SELECT;
+#if DEBUG_ICACHE
+if ( m_debug_activated )
+std::cout << "  <PROC " << name() << " ICACHE_IDLE> READ MISS in icache" 
+          << " : PADDR = " << std::hex << paddr << std::endl;
+#endif
+                   r_icache_miss_req = true;
+                }
+                else if (cache_state == CACHE_SLOT_STATE_ZOMBI )	// pending cleanup
+                {
+                    // stalled until cleanup is acknowledged
+                    r_icache_fsm       = ICACHE_IDLE;
+                }
+                else			                            // cache hit
+                {
+
+#ifdef INSTRUMENTATION
+m_cpt_ins_read++;
+#endif
+                    // return instruction to processor
+                    m_irsp.valid       = true;
+                    m_irsp.instruction = cache_inst;
+                    r_icache_fsm       = ICACHE_IDLE;
+#if DEBUG_ICACHE
+if ( m_debug_activated )
+std::cout << "  <PROC " << name() << " ICACHE_IDLE> READ HIT in icache" 
+          << " : PADDR = " << std::hex << paddr << std::endl;
+#endif
+                }
+            }
+            else             	// non cacheable read
+            {
+                r_icache_unc_req  = true;
+                r_icache_fsm      = ICACHE_UNC_WAIT;
+
+#if DEBUG_ICACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " ICACHE_IDLE> READ UNCACHEABLE in icache" 
+              << " : PADDR = " << std::hex << paddr << std::endl;
+}
+#endif
+            }
+        }    // end if m_ireq.valid
+        break;
+    }
+    /////////////////////
+    case ICACHE_TLB_WAIT:	// Waiting the itlb update by the DCACHE FSM after a tlb miss
+                            // the itlb is udated by the DCACHE FSM, as well as the
+                            // r_mmu_ietr and r_mmu_ibvar registers in case of error.
+                            // the itlb is not accessed by ICACHE FSM until DCACHE FSM
+                            // reset the r_icache_tlb_miss_req flip-flop
+                            // external coherence request are accepted in this state.
+    {
+        // coherence clack interrupt
+        if ( r_icache_clack_req.read() )
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+
+        // coherence interrupt
+        if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+
+        if ( m_ireq.valid ) m_cost_ins_tlb_miss_frz++;
+
+        // DCACHE FSM signals response by reseting the request flip-flop
+        if ( not r_icache_tlb_miss_req.read() )
+        {
+            if ( r_icache_tlb_rsp_error.read() ) // error reported : tlb not updated
+            {
+                r_icache_tlb_rsp_error = false;
+                m_irsp.error             = true;
+                m_irsp.valid             = true;
+                r_icache_fsm             = ICACHE_IDLE;
+            }
+            else				// tlb updated : return to IDLE state
+            {
+                r_icache_fsm  = ICACHE_IDLE;
+            }
+        }
+        break;
+    }
+    //////////////////////////
+    case ICACHE_XTN_TLB_FLUSH:   	// invalidate in one cycle all non global TLB entries
+    {
+        r_itlb.flush();
+        r_dcache_xtn_req     = false;
+        r_icache_fsm         = ICACHE_IDLE;
+        break;
+    }
+    ////////////////////////////
+    case ICACHE_XTN_CACHE_FLUSH:	// Invalidate sequencially all cache lines, using
+                                    // r_icache_flush_count as a slot counter,
+                                	// looping in this state until all slots are visited.
+                                    // It can require two cycles per slot:
+                                    // We test here the slot state, and make the actual inval
+                                    // (if line is valid) in ICACHE_XTN_CACHE_FLUSH_GO state.
+                       		        // A cleanup request is generated for each valid line
+    {
+        // coherence clack interrupt
+        if ( r_icache_clack_req.read() )
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+
+        if ( not r_icache_cc_send_req.read() ) // blocked until previous cc_send request is sent
+        {
+            int       state;
+            paddr_t   tag;
+            size_t	  way = r_icache_flush_count.read()/m_icache_sets;
+            size_t	  set = r_icache_flush_count.read()%m_icache_sets;
+
+#ifdef INSTRUMENTATION
+m_cpt_icache_dir_read++;
+#endif
+            r_icache.read_dir( way,
+                               set,
+                               &tag,
+                               &state );
+
+            assert( (state == CACHE_SLOT_STATE_EXCLUSIVE or state == CACHE_SLOT_STATE_SHARED) 
+                     && "should be an instruction is in the state MODIFIED"); 
+
+            if ( state == CACHE_SLOT_STATE_EXCLUSIVE or state == CACHE_SLOT_STATE_SHARED)    // inval required
+            {
+                // request cleanup
+                r_icache_cc_send_req   = true;
+                r_icache_cc_send_nline = tag * m_icache_sets + set;
+                r_icache_cc_send_way   = way;
+                r_icache_cc_send_type  = CC_TYPE_CLEANUP;
+
+                // goes to ICACHE_XTN_CACHE_FLUSH_GO to make inval
+                r_icache_miss_way     = way;
+                r_icache_miss_set     = set;
+                r_icache_fsm          = ICACHE_XTN_CACHE_FLUSH_GO;
+            }
+            else if ( r_icache_flush_count.read() ==
+                      (m_icache_sets*m_icache_ways - 1) )  // last slot
+            {
+            	r_dcache_xtn_req = false;
+                m_drsp.valid     = true;
+                m_drsp.rdata     = false;
+            	r_icache_fsm 	 = ICACHE_IDLE;
+            }
+
+            // saturation counter, to have the same last slot condition
+            // in ICACHE_XTN_CACHE_FLUSH and ICACHE_XTN_CACHE_FLUSH_GO states
+            if ( r_icache_flush_count.read() < (m_icache_sets*m_icache_ways - 1) )
+            {
+                r_icache_flush_count = r_icache_flush_count.read() + 1;
+            }
+        }
+        break;
+    }
+    ///////////////////////////////
+    case ICACHE_XTN_CACHE_FLUSH_GO:	    // Switch slot state to ZOMBI for an XTN flush
+    {
+        size_t	  way = r_icache_miss_way.read();
+        size_t	  set = r_icache_miss_set.read();
+
+#ifdef INSTRUMENTATION
+m_cpt_icache_dir_write++;
+#endif
+
+        r_icache.write_dir( way,
+                            set,
+                            CACHE_SLOT_STATE_ZOMBI );
+
+        if ( r_icache_flush_count.read() ==
+                      (m_icache_sets*m_icache_ways - 1) )  // last slot
+        {
+         	r_dcache_xtn_req = false;
+            m_drsp.valid     = true;
+            m_drsp.rdata     = false;
+         	r_icache_fsm 	 = ICACHE_IDLE;
+        }
+        else
+        {
+            r_icache_fsm         = ICACHE_XTN_CACHE_FLUSH;
+        }
+        break;
+    }
+
+    //////////////////////////
+    case ICACHE_XTN_TLB_INVAL: 		// invalidate one TLB entry selected by the virtual address
+        				            // stored in the r_dcache_save_wdata register
+    {
+        r_itlb.inval(r_dcache_save_wdata.read());
+        r_dcache_xtn_req     = false;
+        r_icache_fsm         = ICACHE_IDLE;
+        break;
+    }
+    ///////////////////////////////
+    case ICACHE_XTN_CACHE_INVAL_VA:	// Selective cache line invalidate with virtual address
+                                    // requires 3 cycles (in case of hit on itlb and icache).
+					                // In this state, access TLB to translate virtual address
+        				            // stored in the r_dcache_save_wdata register.
+    {
+        paddr_t 	paddr;
+        bool    	hit;
+
+        // read physical address in TLB when MMU activated
+        if ( r_mmu_mode.read() & INS_TLB_MASK ) 	// itlb activated
+        {
+
+#ifdef INSTRUMENTATION
+m_cpt_ins_tlb_read++;
+#endif
+            hit = r_itlb.translate(r_dcache_save_wdata.read(),
+                                   &paddr);
+        }
+        else 						// itlb not activated
+        {
+            paddr 	= (paddr_t)r_dcache_save_wdata.read();
+            hit 	= true;
+        }
+
+        if ( hit )		// continue the selective inval process
+        {
+            r_icache_vci_paddr    = paddr;
+            r_icache_fsm          = ICACHE_XTN_CACHE_INVAL_PA;
+        }
+        else			// miss : send a request to DCACHE FSM
+        {
+
+#ifdef INSTRUMENTATION
+m_cpt_ins_tlb_miss++;
+#endif
+            r_icache_tlb_miss_req = true;
+	        r_icache_vaddr_save   = r_dcache_save_wdata.read();
+            r_icache_fsm          = ICACHE_TLB_WAIT;
+        }
+        break;
+    }
+    ///////////////////////////////
+    case ICACHE_XTN_CACHE_INVAL_PA:	// selective invalidate cache line with physical address
+                                    // require 2 cycles. In this state, we read directory
+                                    // with address stored in r_icache_vci_paddr register.
+    {
+        int         state;
+        size_t		way;
+        size_t		set;
+        size_t		word;
+
+#ifdef INSTRUMENTATION
+m_cpt_icache_dir_read++;
+#endif
+        r_icache.read_dir(r_icache_vci_paddr.read(),
+                          &state,
+                          &way,
+                          &set,
+                          &word);
+
+        assert( (state == CACHE_SLOT_STATE_EXCLUSIVE or state == CACHE_SLOT_STATE_SHARED) 
+                 && "should be an instruction is in the state MODIFIED"); 
+
+        if ( state == CACHE_SLOT_STATE_EXCLUSIVE or state == CACHE_SLOT_STATE_SHARED )	// inval to be done
+        {
+            r_icache_miss_way = way;
+            r_icache_miss_set = set;
+            r_icache_fsm      = ICACHE_XTN_CACHE_INVAL_GO;
+        }
+        else		// miss : acknowlege the XTN request and return
+        {
+            r_dcache_xtn_req = false;
+            r_icache_fsm     = ICACHE_IDLE;
+        }
+        break;
+    }
+    ///////////////////////////////
+    case ICACHE_XTN_CACHE_INVAL_GO:  // Switch slot to ZOMBI state for an XTN inval
+    {
+        if ( not r_icache_cc_send_req.read() )  // blocked until previous cc_send request not sent
+        {
+
+#ifdef INSTRUMENTATION
+m_cpt_icache_dir_write++;
+#endif
+            r_icache.write_dir( r_icache_miss_way.read(),
+                                r_icache_miss_set.read(),
+                                CACHE_SLOT_STATE_ZOMBI );
+
+            // request cleanup
+            r_icache_cc_send_req   = true;
+            r_icache_cc_send_nline = r_icache_vci_paddr.read() / (m_icache_words<<2);
+            r_icache_cc_send_way   = r_icache_miss_way.read();
+            r_icache_cc_send_type  = CC_TYPE_CLEANUP;
+
+            // acknowledge the XTN request and return
+            r_dcache_xtn_req      = false;
+            r_icache_fsm          = ICACHE_IDLE;
+        }
+        break;
+    }
+    ////////////////////////
+    case ICACHE_MISS_SELECT:       // Try to select a slot in associative set,
+                                   // if previous cleanup has been sent.
+                                   // Waiting in this state if no slot available.
+                                   // Set the r_icache_cleanup_req flip-flop
+                                   // and the r_icache_miss_clack flip-flop,
+                                   // when a cleanup is required
+    {
+        if (m_ireq.valid) m_cost_ins_miss_frz++;
+
+        // coherence clack interrupt
+        if ( r_icache_clack_req.read() )
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+
+        // coherence interrupt
+        if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+
+        bool        found;
+        bool        cleanup;
+        size_t  	way;
+        size_t  	set;
+        paddr_t 	victim;
+
+#ifdef INSTRUMENTATION
+m_cpt_icache_dir_read++;
+#endif
+        r_icache.read_select(r_icache_vci_paddr.read(),
+                             &victim,
+                             &way,
+                             &set,
+                             &found,
+                             &cleanup );
+        if ( found )
+        {
+            r_icache_miss_way     = way;
+            r_icache_miss_set     = set;
+
+            if ( cleanup )
+            {
+                if ( not r_icache_cc_send_req.read() )
+                {
+                    r_icache_cc_send_req    = true;
+                    r_icache_cc_send_nline  = victim;
+                    r_icache_cc_send_way    = way;
+                    r_icache_cc_send_type   = CC_TYPE_CLEANUP;    
+                }
+                else
+                {
+                    r_icache_cleanup_victim_req   = true;
+                    r_icache_cleanup_victim_nline = victim;
+                }
+
+                r_icache_miss_clack           = true;
+                r_icache_fsm                  = ICACHE_MISS_CLEAN;
+            }
+            else
+            {
+                r_icache_fsm          = ICACHE_MISS_WAIT;
+            }
+
+#if DEBUG_ICACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " ICACHE_MISS_SELECT> Select a slot:" << std::dec
+              << " / WAY = " << way
+              << " / SET = " << set;
+    if (cleanup) std::cout << " / VICTIM = " << std::hex << victim << std::endl;
+    else         std::cout << std::endl;
+}
+#endif
+        }
+        break;
+    }
+    ///////////////////////
+    case ICACHE_MISS_CLEAN:	         // switch the slot to zombi state
+    {
+        if (m_ireq.valid) m_cost_ins_miss_frz++;
+
+#ifdef INSTRUMENTATION
+m_cpt_icache_dir_write++;
+#endif
+        r_icache.write_dir( r_icache_miss_way.read(),
+                            r_icache_miss_set.read(),
+                            CACHE_SLOT_STATE_ZOMBI);
+#if DEBUG_ICACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " ICACHE_MISS_CLEAN> Switch to ZOMBI state" << std::dec
+              << " / WAY = " << r_icache_miss_way.read()
+              << " / SET = " << r_icache_miss_set.read() << std::endl;
+}
+#endif
+
+        r_icache_fsm = ICACHE_MISS_WAIT;
+        break;
+    }
+    //////////////////////
+    case ICACHE_MISS_WAIT:	  // waiting response from VCI_RSP FSM
+    {
+        if (m_ireq.valid) m_cost_ins_miss_frz++;
+
+        if ( r_icache_cleanup_victim_req.read() and not r_icache_cc_send_req.read() )
+        {
+            r_icache_cc_send_req        = true;
+            r_icache_cc_send_nline      = r_icache_cleanup_victim_nline;
+            r_icache_cc_send_way        = r_icache_miss_way;
+            r_icache_cc_send_type       = CC_TYPE_CLEANUP; 
+            r_icache_cleanup_victim_req = false;
+        }   
+
+        // coherence clack interrupt
+        if ( r_icache_clack_req.read() )
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+        
+        // coherence interrupt
+        if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read() and not r_icache_cleanup_victim_req.read() )
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+
+        if ( r_vci_rsp_ins_error.read() ) // bus error
+        {
+            r_mmu_ietr          = MMU_READ_DATA_ILLEGAL_ACCESS;
+            r_mmu_ibvar         = r_icache_vaddr_save.read();
+            m_irsp.valid        = true;
+            m_irsp.error        = true;
+            r_vci_rsp_ins_error = false;
+            r_icache_fsm        = ICACHE_IDLE;
+        }
+        else if ( r_vci_rsp_fifo_icache.rok() ) // response available
+        {
+            r_icache_miss_word = 0;
+            r_icache_fsm       = ICACHE_MISS_DATA_UPDT;
+        }
+        break;
+    }
+    ///////////////////////////
+    case ICACHE_MISS_DATA_UPDT:	  // update the cache (one word per cycle)
+    {
+        if ( m_ireq.valid ) m_cost_ins_miss_frz++;
+
+        if ( r_vci_rsp_fifo_icache.rok() )	// response available
+        {
+
+#ifdef INSTRUMENTATION
+m_cpt_icache_data_write++;
+#endif
+            r_icache.write( r_icache_miss_way.read(),
+                            r_icache_miss_set.read(),
+                            r_icache_miss_word.read(),
+                            r_vci_rsp_fifo_icache.read() );
+#if DEBUG_ICACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " ICACHE_MISS_DATA_UPDT> Write one word:"
+              << " WDATA = " << r_vci_rsp_fifo_icache.read()
+              << " WAY = " << r_icache_miss_way.read()
+              << " SET = " << r_icache_miss_set.read()
+              << " WORD = " << r_icache_miss_word.read() << std::endl;
+}
+#endif
+            vci_rsp_fifo_icache_get = true;
+            r_icache_miss_word = r_icache_miss_word.read() + 1;
+
+            if ( r_icache_miss_word.read() == m_icache_words-1 ) 	// last word
+            {
+                r_icache_fsm = ICACHE_MISS_DIR_UPDT;
+            }
+        }
+        break;
+    }
+    //////////////////////////
+    case ICACHE_MISS_DIR_UPDT:	// Stalled if a victim line has been evicted,
+                                // and the cleanup ack has not been received,
+                                // as indicated by r_icache_miss_clack.
+                                // - If no matching coherence request (r_icache_miss_inval)
+                                //   switch directory slot to VALID state.
+                                // - If matching coherence request, switch directory slot
+                                //   to ZOMBI state, and send a cleanup request.
+    {
+        if ( m_ireq.valid ) m_cost_ins_miss_frz++;
+
+        if ( r_icache_cleanup_victim_req.read() and not r_icache_cc_send_req.read() )
+        {
+            r_icache_cc_send_req        = true;
+            r_icache_cc_send_nline      = r_icache_cleanup_victim_nline;
+            r_icache_cc_send_way        = r_icache_miss_way;
+            r_icache_cc_send_type       = CC_TYPE_CLEANUP; 
+            r_icache_cleanup_victim_req = false;
+        }   
+
+        // coherence clack interrupt
+        if ( r_icache_clack_req.read() )
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+
+        // coherence interrupt
+        if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read() and not r_icache_cleanup_victim_req.read() )
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+
+        if ( not r_icache_miss_clack.read() ) // waiting cleanup acknowledge for victim line
+        {
+            if ( r_icache_miss_inval )    // Switch slot to ZOMBI state, and new cleanup
+            {
+                if ( not r_icache_cc_send_req.read() )
+                {
+                    r_icache_miss_inval    = false;
+                    // request cleanup
+                    r_icache_cc_send_req   = true;
+                    r_icache_cc_send_nline = r_icache_vci_paddr.read() / (m_icache_words<<2);
+                    r_icache_cc_send_way   = r_icache_miss_way.read();
+                    r_icache_cc_send_type  = CC_TYPE_CLEANUP;
+
+#ifdef INSTRUMENTATION
+m_cpt_icache_dir_write++;
+#endif
+
+                    r_icache.write_dir( r_icache_vci_paddr.read(),
+                                        r_icache_miss_way.read(),
+                                        r_icache_miss_set.read(),
+                                        CACHE_SLOT_STATE_ZOMBI );
+#if DEBUG_ICACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " ICACHE_MISS_DIR_UPDT> Switch cache slot to ZOMBI state"
+              << " PADDR = " << std::hex << r_icache_vci_paddr.read()
+              << " WAY = " << std::dec << r_icache_miss_way.read()
+              << " SET = " << r_icache_miss_set.read() << std::endl;
+}
+#endif
+                }
+                else
+                    break;
+            }
+            else                          // Switch slot to VALID state
+            {
+
+#ifdef INSTRUMENTATION
+m_cpt_icache_dir_write++;
+#endif
+
+                if( not r_icache_read_state.read() )
+                {
+                    r_icache.write_dir( r_icache_vci_paddr.read(),
+                                        r_icache_miss_way.read(),
+                                        r_icache_miss_set.read(),
+                                        CACHE_SLOT_STATE_EXCLUSIVE );
+                }
+                else
+                {
+                    r_icache.write_dir( r_icache_vci_paddr.read(),
+                                        r_icache_miss_way.read(),
+                                        r_icache_miss_set.read(),
+                                        CACHE_SLOT_STATE_SHARED);
+                }
+ 
+#if DEBUG_ICACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " ICACHE_MISS_DIR_UPDT> Switch cache slot to VALID state"
+              << " PADDR = " << std::hex << r_icache_vci_paddr.read()
+              << " STATE = " << std::dec << r_icache_read_state.read()
+              << " WAY = " << std::dec << r_icache_miss_way.read()
+              << " SET = " << r_icache_miss_set.read() << std::endl;
+}
+#endif
+            }
+
+            r_icache_fsm = ICACHE_IDLE;
+        }
+        break;
+    }
+    ////////////////////
+    case ICACHE_UNC_WAIT:	// waiting a response to an uncacheable read from VCI_RSP FSM
+    {
+        // coherence clack interrupt
+        if ( r_icache_clack_req.read() )
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+
+        // coherence interrupt
+        if ( r_cc_receive_icache_req.read() and not r_icache_cc_send_req.read())
+        {
+            r_icache_fsm = ICACHE_CC_CHECK;
+            r_icache_fsm_save = r_icache_fsm.read();
+            break;
+        }
+
+        if ( r_vci_rsp_ins_error.read() ) // bus error
+        {
+            r_mmu_ietr          = MMU_READ_DATA_ILLEGAL_ACCESS;
+            r_mmu_ibvar         = m_ireq.addr;
+            r_vci_rsp_ins_error = false;
+            m_irsp.valid        = true;
+            m_irsp.error        = true;
+            r_icache_fsm        = ICACHE_IDLE;
+        }
+        else if (r_vci_rsp_fifo_icache.rok() ) // instruction available
+        {
+            vci_rsp_fifo_icache_get = true;
+            r_icache_fsm            = ICACHE_IDLE;
+            if ( m_ireq.valid and
+                (m_ireq.addr == r_icache_vaddr_save.read()) ) // request unmodified
+            {
+                m_irsp.valid       = true;
+                m_irsp.instruction = r_vci_rsp_fifo_icache.read();
+            }
+        }
+        break;
+    }
+    /////////////////////
+    case ICACHE_CC_CHECK:   	// This state is the entry point of a sub-fsm
+                                // handling coherence requests.
+                                // if there is a matching pending miss, it is
+                                // signaled in the r_icache_miss_inval flip-flop.
+                                // The return state is defined in r_icache_fsm_save.
+    {
+        paddr_t  paddr = r_cc_receive_icache_nline.read() * m_icache_words * 4;
+        paddr_t  mask  = ~((m_icache_words<<2)-1);
+
+        // CLACK handler
+        // We switch the directory slot to EMPTY state
+        // and reset r_icache_miss_clack if the cleanup ack
+        // is matching a pending miss.
+        if ( r_icache_clack_req.read() )
+        {
+
+            if ( m_ireq.valid ) m_cost_ins_miss_frz++;
+
+#ifdef INSTRUMENTATION
+m_cpt_icache_dir_write++;
+#endif
+            r_icache.write_dir( 0,
+                                r_icache_clack_way.read(),
+                                r_icache_clack_set.read(),
+                                CACHE_SLOT_STATE_INVALID);
+
+            if ( (r_icache_miss_set.read() == r_icache_clack_set.read()) and
+                 (r_icache_miss_way.read() == r_icache_clack_way.read()) )
+            {
+                r_icache_miss_clack = false;
+            }
+
+            r_icache_clack_req = false;
+
+            // return to cc_save state
+            r_icache_fsm = r_icache_fsm_save.read();
+
+#if DEBUG_ICACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+        << " ICACHE_CC_CHECK>  CC_TYPE_CLACK slot returns to empty state"
+        << " set = " << r_icache_clack_set.read()
+        << " / way = " << r_icache_clack_way.read() << std::endl;
+}
+#endif
+
+            break;
+        }
+
+        // Match between MISS address and CC address
+        // note: In the same cycle we can handle a CLACK and a MISS match
+        // because the CLACK access the directory but the MISS match dont.
+        if (r_cc_receive_icache_req.read() and
+          ((r_icache_fsm_save.read() == ICACHE_MISS_SELECT  )  or
+           (r_icache_fsm_save.read() == ICACHE_MISS_WAIT    )  or
+           (r_icache_fsm_save.read() == ICACHE_MISS_DIR_UPDT)) and
+          ((r_icache_vci_paddr.read() & mask) == (paddr & mask)) ) // matching
+        {
+            // signaling the matching
+            r_icache_miss_inval     = true;
+
+            assert( r_cc_receive_icache_type.read() != CC_TYPE_UPDT && "must not be happened!!");
+            r_cc_receive_icache_req = false;
+            r_icache_fsm          = r_icache_fsm_save.read();
+
+#if DEBUG_ICACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " ICACHE_CC_CHECK> Coherence request matching a pending miss:"
+              << " PADDR = " << std::hex << paddr << std::endl;
+}
+#endif
+        }
+
+        assert ( not r_icache_cc_send_req.read() and "CC_SEND must be available in ICACHE_CC_CHECK");
+
+        // CC request handler
+
+        int	        state = 0;
+        size_t 	    way = 0;
+        size_t 	    set = 0;
+        size_t 	    word = 0;
+
+#ifdef INSTRUMENTATION
+m_cpt_icache_dir_read++;
+#endif
+        r_icache.read_dir(paddr,
+                          &state,
+                          &way,
+                          &set,
+                          &word);
+
+        r_icache_cc_way = way;
+        r_icache_cc_set = set;
+
+        assert( state != CACHE_SLOT_STATE_MODIFIED && "an instruction line should not be in MODIFIED state!!");
+
+        if ( state == CACHE_SLOT_STATE_EXCLUSIVE )            // hit
+        {
+            // need to update the cache state
+            if (r_cc_receive_icache_type.read() == CC_TYPE_UPDT)  // hit update
+            {
+                assert( false && " there is not cc updt for a inst line with protocol mesi");
+                r_icache_fsm           = ICACHE_CC_UPDT;
+            }
+            else if ( r_cc_receive_icache_type.read() == CC_TYPE_INVAL ) // hit inval
+            {
+                r_icache_fsm           = ICACHE_CC_INVAL;
+            }
+        }
+        else if ( state == CACHE_SLOT_STATE_SHARED )            // hit
+        {
+            assert( r_cc_receive_icache_type.read() != CC_TYPE_UPDT && "must not be happened!!");
+            r_icache_fsm           = ICACHE_CC_INVAL;
+        }
+        else                                      // miss
+        {
+
+            assert( r_cc_receive_icache_type.read() != CC_TYPE_UPDT && "must not be happened!!");
+            r_cc_receive_icache_req = false;
+            r_icache_fsm            = r_icache_fsm_save.read();
+        }
+#if DEBUG_ICACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " ICACHE_CC_CHECK> Coherence request received:"
+              << " PADDR = " << std::hex << paddr
+              << " / TYPE = " << std::dec << r_cc_receive_dcache_type.read()
+              << " / HIT = " << ((state == CACHE_SLOT_STATE_SHARED) or (state == CACHE_SLOT_STATE_EXCLUSIVE)) << std::endl;
+}
+#endif
+
+        break;
+    }
+    /////////////////////
+    case ICACHE_CC_INVAL:  	// hit inval : switch slot to ZOMBI state
+    {
+        assert (not r_icache_cc_send_req.read() &&
+                "ERROR in ICACHE_CC_INVAL: the r_icache_cc_send_req "
+                "must not be set");
+
+#ifdef INSTRUMENTATION
+m_cpt_icache_dir_read++;
+#endif
+
+        // Switch slot state to ZOMBI and send CLEANUP command 
+        r_icache.write_dir( r_icache_cc_way.read(),
+                            r_icache_cc_set.read(),
+                            CACHE_SLOT_STATE_ZOMBI );
+
+        // coherence request completed
+        r_icache_cc_send_req   = true;
+        r_icache_cc_send_nline = r_cc_receive_icache_nline.read();
+        r_icache_cc_send_way   = r_icache_cc_way.read();
+        r_icache_cc_send_type  = CC_TYPE_CLEANUP;
+
+        r_icache_fsm           = r_icache_fsm_save.read();
+
+#if DEBUG_ICACHE
+if ( m_debug_activated )
+{
+std::cout << "  <PROC " << name()
+          << " ICACHE_CC_INVAL> slot returns to ZOMBI state"
+          << " set = " << r_icache_cc_set.read()
+          << " / way = " << r_icache_cc_way.read() << std::endl;
+}
+#endif
+
+        break;
+    }
+    ////////////////////
+    case ICACHE_CC_UPDT:	// hit update : write one word per cycle
+    {
+        assert (not r_icache_cc_send_req.read() &&
+                "ERROR in ICACHE_CC_UPDT: the r_icache_cc_send_req "
+                "must not be set");
+
+        r_icache.write_dir( r_icache_cc_way.read(),
+                            r_icache_cc_set.read(),
+                            CACHE_SLOT_STATE_SHARED );
+
+#if DEBUG_ICACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " ICACHE_CC_UPDT>  "
+              << " set = " << r_icache_cc_set.read()
+              << " / way = " << r_icache_cc_way.read()
+              << " change the state to SHARED" << std::endl;
+}
+#endif
+
+            r_cc_receive_icache_req       = false;
+            // request multicast acknowledgement
+            r_icache_cc_send_req          = true;
+            r_icache_cc_send_nline        = r_cc_receive_icache_nline.read();
+            r_icache_cc_send_updt_tab_idx = r_cc_receive_icache_updt_tab_idx.read();
+            r_icache_cc_send_type         = CC_TYPE_MULTI_ACK;
+
+            r_icache_fsm                  = r_icache_fsm_save.read();
+
+            break;
+      }
+    } // end switch r_icache_fsm
+
+    ////////////////////////////////////////////////////////////////////////////////////
+    //      DCACHE FSM
+    //
+    // 1/ Coherence operations
+    //    They are handled as interrupts generated by the CC_RECEIVE FSM.
+    //    - There is a coherence request when r_tgt_dcache_req is set.
+    //    They are taken in IDLE, MISS_WAIT, MISS_DIR_UPDT, UNC_WAIT, LL_WAIT
+    //    and SC_WAIT states.
+    //    - There is a cleanup acknowledge request when r_cleanup_dcache_req is set.
+    //    They are taken in IDLE, MISS_SELECT, MISS_CLEAN, MISS_WAIT, MISS_DATA_UPDT,
+    //    MISS_DIR_UPDT, UNC_WAIT, LL_WAIT, SC_WAIT states.
+    //    - For both types of requests, actions associated to the pre-empted state
+    //    are not executed. The DCACHE FSM goes to the proper sub-FSM (CC_CHECK
+    //    or CC_CLACK) to execute the requested coherence operation, and returns
+    //    to the pre-empted state.
+    //
+    // 2/ TLB miss
+    //    The page tables are generally cacheable.
+    //    In case of miss in itlb or dtlb, the tlb miss is handled by a dedicated
+    //    sub-fsm (DCACHE_TLB_MISS state), that handle possible miss in DCACHE,
+    //    this sub-fsm implement the table-walk...
+    //
+    // 3/ processor requests
+    //    Processor requests are taken in IDLE state only.
+    //    The IDLE state implements a two stages pipe-line to handle write bursts:
+    //    - Both DTLB and DCACHE are accessed in stage P0 (if processor request valid).
+    //    - The registration in wbuf and the dcache update is done in stage P1
+    //      (if the processor request is a write).
+    //    The two r_dcache_wbuf_req and r_dcache_updt_data_req flip-flops define
+    //    the operations that must be done in P1 stage, and the access type
+    //    (read or write) to the DATA part of DCACHE depends on r_dcache_updt_data_req.
+    //    READ requests are delayed if a cache update is requested.
+    //    WRITE or SC requests can require a PTE Dirty bit update (in memory),
+    //    that is done (before handling the processor request) by a dedicated sub-fsm.
+    //    If a PTE is modified, both the itlb and dtlb are selectively, but sequencially
+    //    cleared by a dedicated sub_fsm (DCACHE_INVAL_TLB_SCAN state).
+    //
+    // 4/ Atomic instructions LL/SC
+    //    The LL/SC address are non cacheable (systematic access to memory).
+    //    The llsc buffer contains a registration for an active LL/SC operation
+    //    (with an address, a registration key, an aging counter and a valid bit).
+    //    - LL requests from the processor are transmitted as a one flit VCI command
+    //      (CMD_LOCKED_READ as CMD, and TYPE_LL as PKTID value). PLEN must
+    //      be 8 as the response is 2 flits long (data and registration key)
+    //    - SC requests from the processor are systematically transmitted to the
+    //      memory cache as 2 flits VCI command (CMD_STORE_COND as CMD, and TYPE_SC
+    //      as PKTID value).  The first flit contains the registration key, the second
+    //      flit contains the data to write in case of success.
+    //      The cache is not updated, as this is done in case of success by the
+    //      coherence transaction.
+    //
+    // 5/ Non cacheable access:
+    //    This component implement a strong order between non cacheable access
+    //    (read or write) : A new non cacheable VCI transaction starts only when
+    //    the previous non cacheable transaction is completed. Both cacheable and
+    //    non cacheable transactions use the write buffer, but the DCACHE FSM registers
+    //    a non cacheable write transaction posted in the write buffer by setting the
+    //    r_dcache_pending_unc_write flip_flop. All other non cacheable requests
+    //    are stalled until this flip-flop is reset by the VCI_RSP_FSM (when the
+    //    pending non cacheable write transaction completes).
+    //
+    // 6/ Error handling:
+    //    When the MMU is not activated, Read Bus Errors are synchronous events,
+    //    but Write Bus Errors are asynchronous events (processor is not frozen).
+    //    - If a Read Bus Error is detected, the VCI_RSP FSM sets the
+    //      r_vci_rsp_data_error flip-flop, without writing any data in the
+    //      r_vci_rsp_fifo_dcache FIFO, and the synchronous error is signaled
+    //      by the DCACHE FSM.
+    //    - If a Write Bus Error is detected, the VCI_RSP FSM  signals
+    //      the asynchronous error using the setWriteBerr() method.
+    //    When the MMU is activated bus error are rare events, as the MMU
+    //    checks the physical address before the VCI transaction starts.
+    ////////////////////////////////////////////////////////////////////////////////////////
+
+    // default value for m_drsp
+    m_drsp.valid = false;
+    m_drsp.error = false;
+    m_drsp.rdata = 0;
+    //if(m_cpt_total_cycles % 1000000 == 0 ) r_dcache.printTrace();
+
+    switch ( r_dcache_fsm.read() )
+    {
+    case DCACHE_IDLE: // There are 10 conditions to exit the IDLE state :
+                      // 1) ITLB/DTLB inval request (update)  => DCACHE_INVAL_TLB_SCAN
+                      // 2) Coherence request (TGT FSM)       => DCACHE_CC_CHECK
+                      // 3) ITLB miss request (ICACHE FSM)    => DCACHE_TLB_MISS
+                      // 4) XTN request (processor)           => DCACHE_XTN_*
+                      // 5) DTLB miss (processor)             => DCACHE_TLB_MISS
+                      // 6) Dirty bit update (processor)      => DCACHE_DIRTY_GET_PTE
+                      // 7) Cacheable read miss (processor)   => DCACHE_MISS_SELECT
+                      // 8) Uncacheable read (processor)      => DCACHE_UNC_WAIT
+                      // 9) LL access (processor)             => DCACHE_LL_WAIT
+                      // 10) SC access (processor)            => DCACHE_SC_WAIT
+                      //
+                      // There is a fixed priority to handle requests to DCACHE:
+                      //    1/ the ITLB/DTLB invalidate requests
+                      //    2/ the coherence requests,
+                      //    3/ the processor requests (including DTLB miss),
+                      //    4/ the ITLB miss requests,
+                      // The address space processor request are handled as follows:
+                      // - WRITE request is blocked if the Dirty bit mus be set.
+                      // If DTLB hit, the P1 stage is activated (writes WBUF, and
+                      // updates DCACHE if DCACHE hit) & processor request acknowledged.
+                      // - READ request generate a simultaneouss access to  DCACHE.DATA
+                      // and DCACHE.DIR, but is delayed if DCACHE update required.
+                      //
+                      // There is 4 configurations defining the access type to
+                      // DTLB, DCACHE.DATA, and DCACHE.DIR, depending on the
+                      // dreq.valid (dreq) and r_dcache_updt_data_req (updt) signals:
+                      //    dreq / updt / DTLB  / DCACHE.DIR / DCACHE.DATA /
+                      //     0   /  0   / NOP   / NOP        / NOP         /
+                      //     0   /  1   / NOP   / NOP        / WRITE       /
+                      //     1   /  0   / READ  / READ       / NOP         /
+                      //     1   /  1   / READ  / READ       / WRITE       /
+                      // Those two registers are set at each cycle from the 3 signals
+                      // updt_data_request, wbuf_request, wbuf_write_miss.
+    {
+        paddr_t     paddr;                          // physical address
+        pte_info_t 	tlb_flags;
+        size_t     	tlb_way;
+        size_t     	tlb_set;
+        paddr_t    	tlb_nline = 0;
+        size_t		cache_way;
+        size_t		cache_set;
+        size_t		cache_word;
+        uint32_t	cache_rdata = 0;
+        bool	    tlb_hit = false;
+        int	        cache_state = CACHE_SLOT_STATE_INVALID;
+
+        bool        tlb_inval_required = false;     // request TLB inval after cache update
+        bool        wbuf_write_miss    = false;     // miss a WBUF write request
+        bool        updt_data_request  = false;     // request DCACHE update in P1 stage
+        bool        updt_dir_request   = false;     // request DCACHE update in P1 stage
+        bool        wbuf_request       = false;     // request WBUF write in P1 stage
+
+
+        // physical address computation : systematic DTLB access (if activated)
+        if ( m_dreq.valid )
+        {
+
+            if ( r_mmu_mode.read() & DATA_TLB_MASK )  // DTLB activated
+            {
+                tlb_hit = r_dtlb.translate( m_dreq.addr,
+                                            &paddr,
+                                            &tlb_flags,
+                                            &tlb_nline,
+                                            &tlb_way,
+                                            &tlb_set );
+#ifdef INSTRUMENTATION
+m_cpt_data_tlb_read++;
+#endif
+            }
+            else                                    // identity mapping
+            {
+                paddr = (paddr_t)m_dreq.addr;
+                // we take into account the paddr extension
+                if (vci_param::N > 32) 
+                    paddr = paddr | ((uint64_t)(r_dcache_paddr_ext.read()) << 32);
+            }
+        } // end physical address computation
+
+        // systematic DCACHE access depending on r_dcache_updt_data_req (if activated)
+        if ( r_mmu_mode.read() & DATA_CACHE_MASK)
+        {
+            if( r_dcache_updt_dir_req.read() and r_dcache_updt_data_req.read())
+            {
+                r_dcache.write_dir( r_dcache_save_cache_way.read(),
+                                    r_dcache_save_cache_set.read(),
+                                    CACHE_SLOT_STATE_MODIFIED);
+
+                r_dcache.write( r_dcache_save_cache_way.read(),
+                                r_dcache_save_cache_set.read(),
+                                r_dcache_save_cache_word.read(),
+                                r_dcache_save_wdata.read(),
+                                r_dcache_save_be.read() );
+
+                //r_dcache_updt_dir_req  = false;
+                //r_dcache_updt_data_req = false;
+                //break;
+            }
+            else if ( m_dreq.valid and r_dcache_updt_data_req.read() and not r_dcache_updt_dir_req.read()) // read DIR and write DATA
+            {
+                r_dcache.read_dir( paddr,
+                                   &cache_state,
+                                   &cache_way,
+                                   &cache_set,
+                                   &cache_word );
+
+                r_dcache.write( r_dcache_save_cache_way.read(),
+                                r_dcache_save_cache_set.read(),
+                                r_dcache_save_cache_word.read(),
+                                r_dcache_save_wdata.read(),
+                                r_dcache_save_be.read() );
+#ifdef INSTRUMENTATION
+m_cpt_dcache_dir_read++;
+m_cpt_dcache_data_write++;
+#endif
+            }
+            else if ( m_dreq.valid and not r_dcache_updt_data_req.read() and not r_dcache_updt_dir_req.read() ) // read DIR and DATA
+            {
+                r_dcache.read( paddr,
+                               &cache_rdata,
+                               &cache_way,
+                               &cache_set,
+                               &cache_word,
+                               &cache_state );
+
+#ifdef INSTRUMENTATION
+m_cpt_dcache_dir_read++;
+m_cpt_dcache_data_read++;
+#endif
+            }
+            else if ( not m_dreq.valid and r_dcache_updt_data_req.read() and not r_dcache_updt_dir_req.read() ) // write DATA
+            {
+                r_dcache.write( r_dcache_save_cache_way.read(),
+                                r_dcache_save_cache_set.read(),
+                                r_dcache_save_cache_word.read(),
+                                r_dcache_save_wdata.read(),
+                                r_dcache_save_be.read() );
+#ifdef INSTRUMENTATION
+m_cpt_dcache_data_write++;
+#endif
+            }
+        } // end dcache access
+
+        // DCACHE update in P1 stage can require ITLB / DTLB inval or flush
+        if ( r_dcache_updt_data_req.read() )
+        {
+            size_t way = r_dcache_save_cache_way.read();
+            size_t set = r_dcache_save_cache_set.read();
+            // MODIFIED
+            //if ( r_dcache_in_tlb[way*m_dcache_sets+set] )
+            //{
+            if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_IN_TLB )
+            {
+                tlb_inval_required       = true;
+	            r_dcache_tlb_inval_set   = 0;
+	            r_dcache_tlb_inval_line  = r_dcache_save_paddr.read()>>
+                                           (uint32_log2(m_dcache_words<<2));
+                // MODIFIED RWT: DIRTY
+	            // r_dcache_in_tlb[way*m_dcache_sets+set] = false;
+                r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;
+            }
+            // MODIFIED
+            //else if ( r_dcache_contains_ptd[way*m_dcache_sets+set] )
+            //{
+            else if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_CONTAINS_PTD )
+            {
+                r_itlb.reset();
+                r_dtlb.reset();
+                // MODIFIED
+	            //r_dcache_contains_ptd[way*m_dcache_sets+set] = false;
+                r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;
+            }
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
+          << " Cache update in P1 stage" << std::dec
+          << " / WAY = " << r_dcache_save_cache_way.read()
+          << " / SET = " << r_dcache_save_cache_set.read()
+          << " / WORD = " << r_dcache_save_cache_word.read() << std::hex
+          << " / WDATA = " << r_dcache_save_wdata.read()
+          << " / BE = " << r_dcache_save_be.read() << std::endl;
+#endif
+        } // end test TLB inval
+
+        // Computing the response to processor,
+        // and the next value for r_dcache_fsm
+
+        // itlb/dtlb invalidation self-request
+        if ( tlb_inval_required )
+        {
+            r_dcache_fsm_scan_save = r_dcache_fsm.read();
+            r_dcache_fsm           = DCACHE_INVAL_TLB_SCAN;
+        }
+
+        // coherence clack request (from DSPIN CLACK)
+        else if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+        }
+        // coherence request (from CC_RECEIVE FSM)
+        else if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read() and not r_dcache_miss_updt.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+        }
+        // processor request (READ, WRITE, LL, SC, XTN_READ, XTN_WRITE)
+        // we don't take the processor request, and registers
+        // are frozen in case of wbuf_write_miss
+        else if ( m_dreq.valid )
+        {
+            r_dcache_miss_updt = false;
+            // register processor request and DCACHE response
+            r_dcache_save_vaddr      = m_dreq.addr;
+            r_dcache_save_be         = m_dreq.be;
+            r_dcache_save_wdata      = m_dreq.wdata;
+            r_dcache_save_paddr      = paddr;
+            r_dcache_save_cache_way  = cache_way;
+            r_dcache_save_cache_set  = cache_set;
+            r_dcache_save_cache_word = cache_word;
+
+            // READ XTN requests from processor
+            // They are executed in this DCACHE_IDLE state.
+            // The processor must not be in user mode
+            if (m_dreq.type == iss_t::XTN_READ)
+            {
+                int xtn_opcode = (int)m_dreq.addr/4;
+
+                // checking processor mode:
+                if (m_dreq.mode  == iss_t::MODE_USER)
+                {
+                    r_mmu_detr   = MMU_READ_PRIVILEGE_VIOLATION;
+                    r_mmu_dbvar  = m_dreq.addr;
+                    m_drsp.valid = true;
+                    m_drsp.error = true;
+                    m_drsp.rdata = 0;
+                    r_dcache_fsm = DCACHE_IDLE;
+                }
+                else
+                {
+                    switch( xtn_opcode )
+                    {
+                    case iss_t::XTN_INS_ERROR_TYPE:
+                        m_drsp.rdata = r_mmu_ietr.read();
+                        m_drsp.valid = true;
+                        m_drsp.error = false;
+                        break;
+
+                    case iss_t::XTN_DATA_ERROR_TYPE:
+                        m_drsp.rdata = r_mmu_detr.read();
+                        m_drsp.valid = true;
+                        m_drsp.error = false;
+                        break;
+
+                    case iss_t::XTN_INS_BAD_VADDR:
+                        m_drsp.rdata = r_mmu_ibvar.read();
+                        m_drsp.valid = true;
+                        m_drsp.error = false;
+                        break;
+
+                    case iss_t::XTN_DATA_BAD_VADDR:
+                        m_drsp.rdata = r_mmu_dbvar.read();
+                        m_drsp.valid = true;
+                        m_drsp.error = false;
+                        break;
+
+                    case iss_t::XTN_PTPR:
+                        m_drsp.rdata = r_mmu_ptpr.read();
+                        m_drsp.valid = true;
+                        m_drsp.error = false;
+                        break;
+
+                    case iss_t::XTN_TLB_MODE:
+                        m_drsp.rdata = r_mmu_mode.read();
+                        m_drsp.valid = true;
+                        m_drsp.error = false;
+                        break;
+
+                    case iss_t::XTN_MMU_PARAMS:
+                        m_drsp.rdata = r_mmu_params;
+                        m_drsp.valid = true;
+                        m_drsp.error = false;
+                        break;
+
+                    case iss_t::XTN_MMU_RELEASE:
+                        m_drsp.rdata = r_mmu_release;
+                        m_drsp.valid = true;
+                        m_drsp.error = false;
+                        break;
+
+                    case iss_t::XTN_MMU_WORD_LO:
+                        m_drsp.rdata = r_mmu_word_lo.read();
+                        m_drsp.valid = true;
+                        m_drsp.error = false;
+                        break;
+
+                    case iss_t::XTN_MMU_WORD_HI:
+                        m_drsp.rdata = r_mmu_word_hi.read();
+                        m_drsp.valid = true;
+                        m_drsp.error = false;
+                        break;
+
+                    case iss_t::XTN_DATA_PADDR_EXT:
+                        m_drsp.rdata = r_dcache_paddr_ext.read();
+                        m_drsp.valid = true;
+                        m_drsp.error = false;
+                        break;
+
+                    default:
+                        r_mmu_detr = MMU_READ_UNDEFINED_XTN;
+                        r_mmu_dbvar  = m_dreq.addr;
+                        m_drsp.valid = true;
+                        m_drsp.error = true;
+                        m_drsp.rdata = 0;
+                        break;
+                    } // end switch xtn_opcode
+                } // end else
+            } // end if XTN_READ
+
+            // Handling WRITE XTN requests from processor.
+            // They are not executed in this DCACHE_IDLE state
+            // if they require access to the caches or the TLBs
+            // that are already accessed.
+            // Caches can be invalidated or flushed in user mode,
+            // and the sync instruction can be executed in user mode
+            else if (m_dreq.type == iss_t::XTN_WRITE)
+            {
+                int xtn_opcode      = (int)m_dreq.addr/4;
+                r_dcache_xtn_opcode = xtn_opcode;
+
+                // checking processor mode:
+                if ( (m_dreq.mode  == iss_t::MODE_USER) &&
+                     (xtn_opcode != iss_t::XTN_SYNC) &&
+                     (xtn_opcode != iss_t::XTN_DCACHE_INVAL) &&
+                     (xtn_opcode != iss_t::XTN_DCACHE_FLUSH) &&
+                     (xtn_opcode != iss_t::XTN_ICACHE_INVAL) &&
+                     (xtn_opcode != iss_t::XTN_ICACHE_FLUSH) )
+                {
+                    r_mmu_detr   = MMU_WRITE_PRIVILEGE_VIOLATION;
+                    r_mmu_dbvar  = m_dreq.addr;
+                    m_drsp.valid = true;
+                    m_drsp.error = true;
+                    m_drsp.rdata = 0;
+                    r_dcache_fsm = DCACHE_IDLE;
+                }
+                else
+                {
+                    switch( xtn_opcode )
+                    {
+                    case iss_t::XTN_PTPR:   			// itlb & dtlb must be flushed
+                        r_dcache_xtn_req = true;
+                        r_dcache_fsm     = DCACHE_XTN_SWITCH;
+                        break;
+
+                    case iss_t::XTN_TLB_MODE:			// no cache or tlb access
+                        r_mmu_mode       = m_dreq.wdata;
+                        m_drsp.valid     = true;
+                        r_dcache_fsm     = DCACHE_IDLE;
+                        break;
+
+                    case iss_t::XTN_DTLB_INVAL:     		// dtlb access
+                        r_dcache_fsm     = DCACHE_XTN_DT_INVAL;
+                        break;
+
+                    case iss_t::XTN_ITLB_INVAL:     		// itlb access
+                        r_dcache_xtn_req = true;
+                        r_dcache_fsm     = DCACHE_XTN_IT_INVAL;
+                        break;
+
+                    case iss_t::XTN_DCACHE_INVAL:   		// dcache, dtlb & itlb access
+                        r_dcache_fsm     = DCACHE_XTN_DC_INVAL_VA;
+                        break;
+
+                    case iss_t::XTN_MMU_DCACHE_PA_INV:  	// dcache, dtlb & itlb access
+                        r_dcache_fsm     = DCACHE_XTN_DC_INVAL_PA;
+                        if (sizeof(paddr_t) <= 32)
+                        {
+                            assert(r_mmu_word_hi.read() == 0 &&
+                            "high bits should be 0 for 32bit paddr");
+                            r_dcache_save_paddr = (paddr_t)r_mmu_word_lo.read();
+                        }
+                        else
+                        {
+                            r_dcache_save_paddr = (uint64_t)r_mmu_word_hi.read() << 32 |
+                                                  (paddr_t)r_mmu_word_lo.read();
+                        }
+                        break;
+
+                    case iss_t::XTN_DCACHE_FLUSH:   	       // itlb and dtlb must be reset
+                        r_dcache_flush_count = 0;
+                        r_dcache_fsm     = DCACHE_XTN_DC_FLUSH;
+                        break;
+
+                    case iss_t::XTN_ICACHE_INVAL:   		// icache and itlb access
+                        r_dcache_xtn_req = true;
+                        r_dcache_fsm     = DCACHE_XTN_IC_INVAL_VA;
+                        break;
+
+                    case iss_t::XTN_MMU_ICACHE_PA_INV:		// icache access
+                        r_dcache_xtn_req = true;
+                        r_dcache_fsm     = DCACHE_XTN_IC_INVAL_PA;
+                        break;
+
+                    case iss_t::XTN_ICACHE_FLUSH:   		// icache access
+                        r_dcache_xtn_req = true;
+                        r_dcache_fsm     = DCACHE_XTN_IC_FLUSH;
+                        break;
+
+                    case iss_t::XTN_SYNC:           		// wait until write buffer empty
+                        r_dcache_fsm     = DCACHE_XTN_SYNC;
+                        break;
+
+                    case iss_t::XTN_MMU_WORD_LO: 		// no cache or tlb access
+                        r_mmu_word_lo    = m_dreq.wdata;
+                        m_drsp.valid     = true;
+                        r_dcache_fsm     = DCACHE_IDLE;
+                        break;
+
+                    case iss_t::XTN_MMU_WORD_HI: 		// no cache or tlb access
+                        r_mmu_word_hi    = m_dreq.wdata;
+                        m_drsp.valid     = true;
+                        r_dcache_fsm     = DCACHE_IDLE;
+                        break;
+
+                    case iss_t::XTN_MMU_LL_RESET:      // no cache or tlb access
+                        r_dcache_llsc_valid = false;
+                        m_drsp.valid     = true;
+                        r_dcache_fsm     = DCACHE_IDLE;
+                    break;
+
+                    case iss_t::XTN_DATA_PADDR_EXT:     // no cache or tlb access
+                        r_dcache_paddr_ext = m_dreq.wdata;
+                        m_drsp.valid       = true;
+                        r_dcache_fsm       = DCACHE_IDLE;
+                    break;
+
+	                case iss_t::XTN_ICACHE_PREFETCH:		// not implemented : no action
+	                case iss_t::XTN_DCACHE_PREFETCH:		// not implemented : no action
+                        m_drsp.valid     = true;
+                        r_dcache_fsm     = DCACHE_IDLE;
+		            break;
+
+                    default:
+                        r_mmu_detr   = MMU_WRITE_UNDEFINED_XTN;
+                        r_mmu_dbvar  = m_dreq.addr;
+                        m_drsp.valid = true;
+                        m_drsp.error = true;
+                        r_dcache_fsm = DCACHE_IDLE;
+                        break;
+                    } // end switch xtn_opcode
+                } // end else
+            } // end if XTN_WRITE
+
+            // Handling processor requests to address space (READ/WRITE/LL/SC)
+            // The dtlb and dcache can be activated or not.
+            // We compute the cacheability, and check processor request validity:
+            // - If DTLB not activated : cacheability is defined by the segment table,
+            //   and there is no access rights checking.
+            // - If DTLB activated : cacheability is defined by the C bit in the PTE,
+            //   and the U & W bits of the PTE are checked, as well as the DTLB hit.
+            //   Jumps to the TLB_MISS sub-fsm in case of dtlb miss.
+            else
+            {
+                bool	    valid_req;
+                bool	    cacheable;
+
+                if ( not (r_mmu_mode.read() & DATA_TLB_MASK) )		// dtlb not activated
+                {
+                    valid_req     = true;
+
+                    if ( not (r_mmu_mode.read() & DATA_CACHE_MASK) ) cacheable = false;
+                    else cacheable = m_cacheability_table[(uint64_t)m_dreq.addr];
+                }
+                else 							                   // dtlb activated
+                {
+                    if ( tlb_hit )					// tlb hit
+                    {
+                        // cacheability
+                        if ( not (r_mmu_mode.read() & DATA_CACHE_MASK) ) cacheable = false;
+                        else cacheable = tlb_flags.c;
+                        // access rights checking
+                        if ( not tlb_flags.u and (m_dreq.mode == iss_t::MODE_USER))
+                        {
+                            if ( (m_dreq.type == iss_t::DATA_READ) or
+                                 (m_dreq.type == iss_t::DATA_LL) )
+                            {
+                                r_mmu_detr = MMU_READ_PRIVILEGE_VIOLATION;
+                            }
+                            else
+                            {
+                                r_mmu_detr = MMU_WRITE_PRIVILEGE_VIOLATION;
+                            }
+                            valid_req    = false;
+                            r_mmu_dbvar  = m_dreq.addr;
+                            m_drsp.valid = true;
+                            m_drsp.error = true;
+                            m_drsp.rdata = 0;
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
+          << " HIT in dtlb, but privilege violation" << std::endl;
+#endif
+                        }
+                        else if ( not tlb_flags.w and
+                                  ((m_dreq.type == iss_t::DATA_WRITE) or
+                                   (m_dreq.type == iss_t::DATA_SC)) )
+                        {
+                            r_mmu_detr   = MMU_WRITE_ACCES_VIOLATION;
+                            valid_req    = false;
+                            r_mmu_dbvar  = m_dreq.addr;
+                            m_drsp.valid = true;
+                            m_drsp.error = true;
+                            m_drsp.rdata = 0;
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
+          << " HIT in dtlb, but writable violation" << std::endl;
+#endif
+                        }
+                        else
+                        {
+                            valid_req    = true;
+                        }
+                    }
+                    else						// tlb miss
+                    {
+                        valid_req            = false;
+                        r_dcache_tlb_vaddr   = m_dreq.addr;
+                        r_dcache_tlb_ins     = false;
+                        r_dcache_fsm         = DCACHE_TLB_MISS;
+                    }
+                }    // end DTLB activated
+
+                if ( valid_req ) 	// processor request is valid (after MMU check)
+                {
+                    // READ request
+                    // The read requests are taken only if there is no cache update.
+                    // We request a VCI transaction to CMD FSM if miss or uncachable
+
+                    if ( ((m_dreq.type == iss_t::DATA_READ))
+                          and not r_dcache_updt_dir_req.read() )
+                    {
+                        if ( cacheable )           	// cacheable read
+                        {
+                            if ( cache_state == CACHE_SLOT_STATE_INVALID )   // cache miss
+                            {
+#ifdef INSTRUMENTATION
+m_cpt_data_miss++;
+#endif
+                                r_dcache_vci_paddr    = paddr;
+                                r_dcache_vci_miss_req = true;
+                                r_dcache_read_for_modify = false;
+                                r_dcache_miss_type    = PROC_MISS;
+                                r_dcache_fsm          = DCACHE_MISS_SELECT;
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
+          << " READ MISS in dcache" 
+          << " / PADDR = " << std::hex << paddr << std::endl;
+#endif
+                            }
+                            else if (cache_state == CACHE_SLOT_STATE_ZOMBI ) // pending cleanup
+                            {
+                                // stalled until cleanup is acknowledged
+                                r_dcache_fsm   = DCACHE_IDLE;
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
+          << " Pending cleanup, stalled until cleanup acknowledge"
+          << " / PADDR = " << std::hex << paddr << std::endl;
+#endif
+                            }
+                            else 
+                            {
+                                if ( not r_dcache_updt_data_req.read() )  
+                                {
+#ifdef INSTRUMENTATION
+m_cpt_data_read++;
+#endif
+                                    // returns data to processor
+                                    m_drsp.valid   = true;
+                                    m_drsp.error   = false;
+                                    m_drsp.rdata   = cache_rdata;
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
+          << " READ HIT in dcache" 
+          << " / PADDR = " << std::hex << paddr << std::endl;
+#endif
+ 
+                                }
+                           }
+                        }
+                        else					// uncacheable read
+                        {
+                            r_dcache_vci_paddr      = paddr;
+                            r_dcache_vci_unc_be     = m_dreq.be;
+                            r_dcache_vci_unc_write  = false;
+                            r_dcache_vci_unc_req    = true;
+                            r_dcache_fsm            = DCACHE_UNC_WAIT;
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
+          << " READ UNCACHEABLE in dcache" 
+          << " / PADDR = " << std::hex << paddr << std::endl;
+#endif
+                        }
+                    } // end READ
+
+                    // LL request (non cachable)
+                    // We request a VCI LL transaction to CMD FSM and register
+                    // the LL/SC operation in llsc buffer.
+                    else if (m_dreq.type == iss_t::DATA_LL)
+                    {
+                        // register paddr in LLSC buffer
+                        r_dcache_llsc_paddr = paddr;
+                        r_dcache_llsc_count = LLSC_TIMEOUT;
+                        r_dcache_llsc_valid = true;
+
+                        // request an LL VCI transaction and go to DCACHE_LL_WAIT state
+                        r_dcache_vci_ll_req   = true;
+                        r_dcache_vci_paddr    = paddr;
+                        r_dcache_ll_rsp_count = 0;
+                        r_dcache_fsm          = DCACHE_LL_WAIT;
+                        /*ODCCP*/
+                        //std::cout << "LL on " << name() << " | paddr = " << std::hex << paddr << std::dec << " | at cycle : " << m_cpt_total_cycles << std::endl;
+
+                    }// end LL
+
+                    // WRITE request:
+                    // If the TLB is activated and the PTE Dirty bit is not set, we stall
+                    // the processor and set the Dirty bit before handling the write request,
+                    // going to the DCACHE_DIRTY_GT_PTE state.
+                    // If we don't need to set the Dirty bit, we can acknowledge
+                    // the processor request, as the write arguments (including the
+                    // physical address) are registered in r_dcache_save registers,
+                    // and the write will be done in the P1 pipeline stage.
+                    else if ( m_dreq.type == iss_t::DATA_WRITE and not r_dcache_updt_dir_req.read())
+                    {
+                        if ( (r_mmu_mode.read() & DATA_TLB_MASK )
+                              and not tlb_flags.d )		// Dirty bit must be set
+                        {
+                            // The PTE physical address is obtained from the nline value (dtlb),
+                            // and from the virtual address (word index)
+                            if ( tlb_flags.b )	// PTE1
+                            {
+                                r_dcache_dirty_paddr = (paddr_t)(tlb_nline*(m_dcache_words<<2)) |
+                                                       (paddr_t)((m_dreq.addr>>19) & 0x3c);
+                            }
+                            else		// PTE2
+                            {
+                                r_dcache_dirty_paddr = (paddr_t)(tlb_nline*(m_dcache_words<<2)) |
+                                                       (paddr_t)((m_dreq.addr>>9) & 0x38);
+                            }
+                        r_dcache_fsm      = DCACHE_DIRTY_GET_PTE;
+                    }
+                    else					// Write request accepted
+                    {
+#ifdef INSTRUMENTATION
+m_cpt_data_write++;
+#endif
+                        // cleaning llsc buffer if address matching
+                        if ( paddr == r_dcache_llsc_paddr.read() )
+                            r_dcache_llsc_valid = false;
+
+                        if (not cacheable) 
+                        {                            
+                            r_dcache_vci_paddr      = paddr;
+                            r_dcache_vci_wdata      = m_dreq.wdata;
+                            r_dcache_vci_unc_write  = true;
+                            r_dcache_vci_unc_be     = m_dreq.be;
+                            r_dcache_vci_unc_req    = true;
+                            r_dcache_fsm            = DCACHE_UNC_WAIT;
+                        }
+                        // activating P1 stage
+                        else if( cache_state == CACHE_SLOT_STATE_EXCLUSIVE ) 
+                        {
+                            updt_dir_request = true;
+                            updt_data_request = true;
+                            m_drsp.valid = true;
+                            m_drsp.rdata = 0;
+                        }
+                        else if( cache_state == CACHE_SLOT_STATE_MODIFIED ) 
+                        {
+                            updt_data_request = true;
+                            m_drsp.valid = true;
+                            m_drsp.rdata = 0;
+                        }
+                        else if( cache_state == CACHE_SLOT_STATE_SHARED ) 
+                        {
+                            r_dcache_miss_way        = cache_way;
+                            r_dcache_miss_set        = cache_set;
+                            r_dcache_vci_paddr       = paddr;
+                            r_dcache_vci_miss_req    = true;
+                            r_dcache_read_for_modify = true;
+                            r_dcache_read_hit        = true;
+                            r_dcache_miss_type       = PROC_MISS;
+                            r_dcache_fsm             = DCACHE_MISS_WAIT;
+                        }
+                        // We stall proc if a write request is on line ZOMBI
+                        // Invalidation from memcache on a non-coherent
+                        // line can cause cleanup_data. While sending this
+                        // cleanup the processor can do a write on the same
+                        // line. However there is no guarantee that the
+                        // memcache will receive transactions in the
+                        // correct order, ie it can handle writing before
+                        // cleanup and therefore overwrite the new value of
+                        // writing that is more current than the data
+                        // contained in the cleanup .
+                        // TODO : MAYBE NEED TO OPTIMIZE
+                        else if ( cache_state == CACHE_SLOT_STATE_ZOMBI )
+                        {
+                            r_dcache_fsm = DCACHE_IDLE;
+                        }
+                        else if ( cache_state == CACHE_SLOT_STATE_INVALID )
+                        {
+                            r_dcache_vci_paddr       = paddr;
+                            r_dcache_vci_miss_req    = true;
+                            r_dcache_miss_type       = PROC_MISS;
+
+                            r_dcache_fsm             = DCACHE_MISS_SELECT;
+                            r_dcache_read_for_modify = true; 
+                            r_dcache_read_hit        = false;
+                        }
+                        else
+                        {
+                            assert(false && "you forget something !!!");
+                        }
+                    }
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+std::cout << "  <PROC " << name() << " DCACHE_IDLE>"
+      << " WRITE REQ " 
+      << " / updt_data_request = " << updt_data_request
+      << " / cache_state = " << cache_state
+      << " / PADDR = " << std::hex << paddr << std::endl;
+#endif
+
+                } // end WRITE
+
+                // SC request:
+                // If the TLB is activated and the PTE Dirty bit is not set, we stall
+                // the processor and set the Dirty bit before handling the write request,
+                // going to the DCACHE_DIRTY_GT_PTE state.
+                // If we don't need to set the Dirty bit, we test the llsc buffer:
+                // If failure, we send a negative response to processor.
+                // If success, we request a SC transaction to CMD FSM and go
+                // to DCACHE_SC_WAIT state.
+                // We don't check a possible write hit in dcache, as the cache update
+                // is done by the coherence transaction induced by the SC...
+                else if ( m_dreq.type == iss_t::DATA_SC and not r_dcache_updt_dir_req.read())
+                {
+                    if ( (r_mmu_mode.read() & DATA_TLB_MASK )
+                          and not tlb_flags.d )			// Dirty bit must be set
+                    {
+                        // The PTE physical address is obtained from the nline value (dtlb),
+                        // and the word index (virtual address)
+                        if ( tlb_flags.b )	// PTE1
+                        {
+                            r_dcache_dirty_paddr = (paddr_t)(tlb_nline*(m_dcache_words<<2)) |
+                                                   (paddr_t)((m_dreq.addr>>19) & 0x3c);
+                        }
+                        else			// PTE2
+                        {
+                            r_dcache_dirty_paddr = (paddr_t)(tlb_nline*(m_dcache_words<<2)) |
+                                                   (paddr_t)((m_dreq.addr>>9) & 0x38);
+                        }
+                        r_dcache_fsm           = DCACHE_DIRTY_GET_PTE;
+                        }
+                        else					// SC request accepted
+                        {
+#ifdef INSTRUMENTATION
+m_cpt_data_sc++;
+#endif
+
+                            if( not r_dcache_updt_dir_req.read())
+                            {
+                                // checking local success
+                                if( r_dcache_llsc_valid.read() and
+                                    (r_dcache_llsc_paddr.read() == paddr) )  // local success
+                                {
+                                    // request an SC CMD and go to DCACHE_SC_WAIT state
+                                    r_dcache_vci_paddr   = paddr;
+                                    r_dcache_vci_sc_req  = true;
+                                    r_dcache_vci_sc_data = m_dreq.wdata;
+                                    r_dcache_fsm         = DCACHE_SC_WAIT;
+                                }
+                                else                                          // local fail
+                                {
+                                    m_drsp.valid = true;
+                                    m_drsp.error = false;
+                                    m_drsp.rdata = 0x1;
+                                }
+                            }
+                        }
+                    } // end SC
+                } // end valid_req
+            }  // end if read/write/ll/sc request
+        } // end processor request
+
+        // itlb miss request
+    	else if ( r_icache_tlb_miss_req.read() )
+        {
+            r_dcache_tlb_ins    = true;
+            r_dcache_tlb_vaddr  = r_icache_vaddr_save.read();
+            r_dcache_fsm        = DCACHE_TLB_MISS;
+        }
+
+        // Computing requests for P1 stage : r_dcache_wbuf_req & r_dcache_updt_data_req
+        r_dcache_updt_data_req = updt_data_request;
+        r_dcache_updt_dir_req  = updt_dir_request;
+        break;
+    }
+    /////////////////////
+    case DCACHE_TLB_MISS: // This is the entry point for the sub-fsm handling all tlb miss.
+                          // Input arguments are:
+                          // - r_dcache_tlb_vaddr
+                          // - r_dcache_tlb_ins (true when itlb miss)
+                          // The sub-fsm access the dcache to find the missing TLB entry,
+                          // and activates the cache miss procedure in case of miss.
+                          // It bypass the first level page table access if possible.
+                          // It uses atomic access to update the R/L access bits
+                          // in the page table if required.
+                          // It directly updates the itlb or dtlb, and writes into the
+                          // r_mmu_ins_* or r_mmu_data* error reporting registers.
+    {
+        uint32_t	ptba = 0;
+        bool		bypass;
+        paddr_t		pte_paddr;
+
+        // evaluate bypass in order to skip first level page table access
+        if ( r_dcache_tlb_ins.read() )				// itlb miss
+        {
+            bypass = r_itlb.get_bypass(r_dcache_tlb_vaddr.read(), &ptba);
+        }
+        else							// dtlb miss
+        {
+            bypass = r_dtlb.get_bypass(r_dcache_tlb_vaddr.read(), &ptba);
+        }
+
+        if ( not bypass )     // Try to read PTE1/PTD1 in dcache
+        {
+            pte_paddr = (((paddr_t)r_mmu_ptpr.read()) << (INDEX1_NBITS+2)) |
+                        ((((paddr_t)r_dcache_tlb_vaddr.read()) >> PAGE_M_NBITS) << 2);
+            r_dcache_tlb_paddr = pte_paddr;
+            r_dcache_fsm       = DCACHE_TLB_PTE1_GET;
+        }
+        else                  // Try to read PTE2 in dcache
+        {
+            pte_paddr = (paddr_t)ptba << PAGE_K_NBITS |
+                        (paddr_t)(r_dcache_tlb_vaddr.read()&PTD_ID2_MASK)>>(PAGE_K_NBITS-3);
+            r_dcache_tlb_paddr = pte_paddr;
+            r_dcache_fsm       = DCACHE_TLB_PTE2_GET;
+        }
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    if ( r_dcache_tlb_ins.read() )
+        std::cout << "  <PROC " << name() << " DCACHE_TLB_MISS> ITLB miss";
+    else
+        std::cout << "  <PROC " << name() << " DCACHE_TLB_MISS> DTLB miss";
+    std::cout << " / VADDR = " << std::hex << r_dcache_tlb_vaddr.read()
+              << " / ptpr  = " << (((paddr_t)r_mmu_ptpr.read()) << (INDEX1_NBITS+2))
+              << " / BYPASS = " << bypass
+              << " / PTE_ADR = " << pte_paddr << std::endl;
+}
+#endif
+
+        break;
+    }
+    /////////////////////////
+    case DCACHE_TLB_PTE1_GET:	// try to read a PT1 entry in dcache
+    {
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read() and not r_dcache_miss_updt.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        r_dcache_miss_updt = false;
+        uint32_t 	entry;
+        size_t		way;
+        size_t		set;
+        size_t		word;
+        int         cache_state;
+        r_dcache.read( r_dcache_tlb_paddr.read(),
+                       &entry,
+                       &way,
+                       &set,
+                       &word,
+                       &cache_state );
+#ifdef INSTRUMENTATION
+m_cpt_dcache_data_read++;
+m_cpt_dcache_dir_read++;
+#endif
+        if (( cache_state != CACHE_SLOT_STATE_INVALID ) and ( cache_state != CACHE_SLOT_STATE_ZOMBI ))
+        {
+            if ( not (entry & PTE_V_MASK) )	// unmapped
+            {
+                if ( r_dcache_tlb_ins.read() )
+                {
+                    r_mmu_ietr             = MMU_READ_PT1_UNMAPPED;
+                    r_mmu_ibvar            = r_dcache_tlb_vaddr.read();
+                    r_icache_tlb_miss_req  = false;
+                    r_icache_tlb_rsp_error = true;
+                }
+                else
+                {
+                    r_mmu_detr             = MMU_READ_PT1_UNMAPPED;
+                    r_mmu_dbvar            = r_dcache_tlb_vaddr.read();
+                    m_drsp.valid             = true;
+                    m_drsp.error             = true;
+                }
+                r_dcache_fsm          = DCACHE_IDLE;
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name() 
+              << " DCACHE_TLB_PTE1_GET> HIT in dcache, but unmapped"
+              << std::hex << " / paddr = " << r_dcache_tlb_paddr.read()
+              << std::dec << " / way = " << way
+              << std::dec << " / set = " << set
+              << std::dec << " / word = " << word
+              << std::hex << " / PTE1 = " << entry << std::endl;
+}
+#endif
+
+            }
+            else if( entry & PTE_T_MASK ) 	//  PTD : me must access PT2
+            {
+                // mark the cache line ac containing a PTD
+                //MODIFIED
+                //r_dcache_contains_ptd[m_dcache_sets*way+set] = true;
+                r_dcache_content_state[way*m_dcache_sets+set] = LINE_CACHE_CONTAINS_PTD;
+
+                // register bypass
+                if ( r_dcache_tlb_ins.read() )		// itlb
+                {
+                    r_itlb.set_bypass(r_dcache_tlb_vaddr.read(),
+                                      entry & ((1 << (m_paddr_nbits-PAGE_K_NBITS)) - 1),
+                                      r_dcache_tlb_paddr.read() / (m_icache_words<<2) );
+                }
+                else					// dtlb
+                {
+                    r_dtlb.set_bypass(r_dcache_tlb_vaddr.read(),
+                                      entry & ((1 << (m_paddr_nbits-PAGE_K_NBITS)) - 1),
+                                      r_dcache_tlb_paddr.read() / (m_dcache_words<<2) );
+                }
+                r_dcache_tlb_paddr =
+                    (paddr_t)(entry & ((1<<(m_paddr_nbits-PAGE_K_NBITS))-1)) << PAGE_K_NBITS |
+                    (paddr_t)(((r_dcache_tlb_vaddr.read() & PTD_ID2_MASK) >> PAGE_K_NBITS) << 3);
+                r_dcache_fsm       = DCACHE_TLB_PTE2_GET;
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name() 
+              << " DCACHE_TLB_PTE1_GET> HIT in dcache"
+              << std::hex << " / paddr = " << r_dcache_tlb_paddr.read()
+              << std::dec << " / way = " << way
+              << std::dec << " / set = " << set
+              << std::dec << " / word = " << word
+              << std::hex << " / PTD = " << entry << std::endl;
+}
+#endif
+            }
+            else			//  PTE1 :  we must update the TLB
+            {
+                // MODIFIED
+                //r_dcache_in_tlb[m_icache_sets*way+set] = true;
+                r_dcache_content_state[m_icache_sets*way+set] = LINE_CACHE_IN_TLB;
+                r_dcache_tlb_pte_flags  = entry;
+               //r_dcache_tlb_cache_way  = way;
+               //r_dcache_tlb_cache_set  = set;
+               //r_dcache_tlb_cache_word = word;
+                r_dcache_fsm            = DCACHE_TLB_PTE1_SELECT;
+
+                r_cas_cache_state = cache_state;
+                r_cas_local_way   = way;
+                r_cas_local_set   = set;
+                r_cas_local_word  = word;
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name() 
+              << " DCACHE_TLB_PTE1_GET> HIT in dcache"
+              << std::hex << " / paddr = " << r_dcache_tlb_paddr.read()
+              << std::dec << " / way = " << way
+              << std::dec << " / set = " << set
+              << std::dec << " / word = " << word
+              << std::hex << " / PTE1 = " << entry << std::endl;
+}
+#endif
+            }
+        }
+        else if ( cache_state == CACHE_SLOT_STATE_ZOMBI ) // pending cleanup
+        {
+            // stalled until cleanup is acknowledged
+            r_dcache_fsm   = DCACHE_TLB_PTE1_GET;
+        }
+        else		// we must load the missing cache line in dcache
+        {
+            r_dcache_vci_miss_req  = true;
+            r_dcache_read_for_modify = false;
+            r_dcache_vci_paddr     = r_dcache_tlb_paddr.read();
+            r_dcache_save_paddr    = r_dcache_tlb_paddr.read();
+            r_dcache_miss_type     = PTE1_MISS;
+            r_dcache_fsm           = DCACHE_MISS_SELECT;
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name() 
+              << " DCACHE_TLB_PTE1_GET> MISS in dcache:"
+              << " PTE1 address = " << std::hex << r_dcache_tlb_paddr.read() << std::endl;
+}
+#endif
+        }
+        break;
+    }
+    ////////////////////////////
+    case DCACHE_TLB_PTE1_SELECT:	// select a slot for PTE1
+    {
+        size_t 	way;
+        size_t 	set;
+
+        if ( r_dcache_tlb_ins.read() )
+        {
+            r_itlb.select( r_dcache_tlb_vaddr.read(),
+                           true,  // PTE1
+                           &way,
+                           &set );
+#ifdef INSTRUMENTATION
+m_cpt_ins_tlb_read++;
+#endif
+        }
+        else
+        {
+            r_dtlb.select( r_dcache_tlb_vaddr.read(),
+                           true,  // PTE1
+                           &way,
+                           &set );
+#ifdef INSTRUMENTATION
+m_cpt_data_tlb_read++;
+#endif
+        }
+        r_dcache_tlb_way = way;
+        r_dcache_tlb_set = set;
+        r_dcache_fsm     = DCACHE_TLB_PTE1_UPDT;
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    if ( r_dcache_tlb_ins.read() )
+        std::cout << "  <PROC " << name() 
+                  << " DCACHE_TLB_PTE1_SELECT> Select a slot in ITLB:";
+    else
+        std::cout << "  <PROC " << name() 
+                  << ".DCACHE_TLB_PTE1_SELECT> Select a slot in DTLB:";
+        std::cout << " way = " << std::dec << way
+                  << " / set = " << set << std::endl;
+}
+#endif
+        break;
+    }
+    //////////////////////////
+    case DCACHE_TLB_PTE1_UPDT:	// write a new PTE1 in tlb after testing the L/R bit
+                                // - if L/R bit already set, exit the sub-fsm.
+                                // - if not, we update the page table but we dont write
+                                //   neither in DCACHE, nor in TLB, as this will be done by
+                                //   the coherence mechanism.
+    {
+        paddr_t	  nline    = r_dcache_tlb_paddr.read() >> (uint32_log2(m_dcache_words)+2);
+        uint32_t  pte      = r_dcache_tlb_pte_flags.read();
+        bool	  pt_updt  = false;
+        bool	  local    = true;
+
+        // We should compute the access locality:
+        // The PPN MSB bits define the destination cluster index.
+        // The m_srcid MSB bits define the source cluster index.
+        // The number of bits to compare depends on the number of clusters,
+        // and can be obtained in the mapping table.
+        // As long as this computation is not done, all access are local.
+
+        if ( local )						// local access
+        {
+            if ( not ((pte & PTE_L_MASK) == PTE_L_MASK) ) // we must set the L bit
+            {
+                pt_updt                = true;
+                r_dcache_vci_cas_old    = pte;
+                r_dcache_vci_cas_new    = pte | PTE_L_MASK;
+                pte                    = pte | PTE_L_MASK;
+                r_dcache_tlb_pte_flags = pte;
+            }
+        }
+        else 							// remote access
+        {
+            if ( not ((pte & PTE_R_MASK) == PTE_R_MASK) ) // we must set the R bit
+            {
+                pt_updt                = true;
+                r_dcache_vci_cas_old    = pte;
+                r_dcache_vci_cas_new    = pte | PTE_R_MASK;
+                pte                    = pte | PTE_R_MASK;
+                r_dcache_tlb_pte_flags = pte;
+            }
+        }
+
+        if ( not pt_updt )					// update TLB and return
+        {
+            if ( r_dcache_tlb_ins.read() )
+            {
+                r_itlb.write( true,		// 2M page
+                              pte,
+                              0,		// argument unused for a PTE1
+                              r_dcache_tlb_vaddr.read(),
+                              r_dcache_tlb_way.read(),
+                              r_dcache_tlb_set.read(),
+                              nline );
+#ifdef INSTRUMENTATION
+m_cpt_ins_tlb_update_acc++;
+#endif
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name() 
+              << " DCACHE_TLB_PTE1_UPDT> write PTE1 in ITLB"
+              << " / set = " << std::dec << r_dcache_tlb_set.read()
+              << " / way = " << r_dcache_tlb_way.read() << std::endl;
+    r_itlb.printTrace();
+}
+#endif
+            }
+            else
+            {
+                r_dtlb.write( true,		// 2M page
+                              pte,
+                              0,		// argument unused for a PTE1
+                              r_dcache_tlb_vaddr.read(),
+                              r_dcache_tlb_way.read(),
+                              r_dcache_tlb_set.read(),
+                              nline );
+#ifdef INSTRUMENTATION
+m_cpt_data_tlb_update_acc++;
+#endif
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name() 
+              << " DCACHE_TLB_PTE1_UPDT> write PTE1 in DTLB"
+              << " / set = " << std::dec << r_dcache_tlb_set.read()
+              << " / way = " << r_dcache_tlb_way.read() << std::endl;
+    r_dtlb.printTrace();
+}
+#endif
+            }
+            r_dcache_fsm = DCACHE_TLB_RETURN;
+        }
+        else                            // update page table but not TLB
+        {
+            r_dcache_fsm = DCACHE_TLB_LR_UPDT;
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name() 
+              << " DCACHE_TLB_PTE1_UPDT> L/R bit update required"
+              << std::endl;
+}
+#endif
+        }
+        break;
+    }
+    /////////////////////////
+    case DCACHE_TLB_PTE2_GET:	// Try to get a PTE2 (64 bits) in the dcache
+    {
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read() and not r_dcache_miss_updt.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+        
+        r_dcache_miss_updt = false;
+        uint32_t 	pte_flags     = 0;
+        uint32_t 	pte_ppn       = 0;
+        size_t   	way           = 0;
+        size_t   	set           = 0;
+        size_t		word          = 0;
+        int         cache_state   = 0;
+
+        r_dcache.read( r_dcache_tlb_paddr.read(),
+                       &pte_flags,
+                       &pte_ppn,
+                       &way,
+                       &set,
+                       &word,
+                       &cache_state );
+#ifdef INSTRUMENTATION
+m_cpt_dcache_data_read++;
+m_cpt_dcache_dir_read++;
+#endif
+        if ((cache_state != CACHE_SLOT_STATE_INVALID) and (cache_state != CACHE_SLOT_STATE_ZOMBI))
+        {
+            if ( not (pte_flags & PTE_V_MASK) )	// unmapped
+            {
+                if ( r_dcache_tlb_ins.read() )
+                {
+                    r_mmu_ietr             = MMU_READ_PT2_UNMAPPED;
+                    r_mmu_ibvar            = r_dcache_tlb_vaddr.read();
+                    r_icache_tlb_miss_req  = false;
+                    r_icache_tlb_rsp_error = true;
+                }
+                else
+                {
+                    r_mmu_detr             = MMU_READ_PT2_UNMAPPED;
+                    r_mmu_dbvar            = r_dcache_tlb_vaddr.read();
+                    m_drsp.valid           = true;
+                    m_drsp.error           = true;
+                }
+                r_dcache_fsm               = DCACHE_IDLE;
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_TLB_PTE2_GET> HIT in dcache, but PTE unmapped"
+              << " PTE_FLAGS = " << std::hex << pte_flags
+              << " PTE_PPN = " << std::hex << pte_ppn << std::endl;
+}
+#endif
+            }
+            else				// mapped : we must update the TLB
+            {
+                // MODIFIED
+                //r_dcache_in_tlb[m_dcache_sets*way+set] = true;
+                r_dcache_content_state[m_dcache_sets*way+set] = LINE_CACHE_IN_TLB;
+                r_dcache_tlb_pte_flags  = pte_flags;
+                r_dcache_tlb_pte_ppn    = pte_ppn;
+               //r_dcache_tlb_cache_way  = way;
+               //r_dcache_tlb_cache_set  = set;
+               //r_dcache_tlb_cache_word = word;
+                r_dcache_fsm            = DCACHE_TLB_PTE2_SELECT;
+
+                r_cas_cache_state = cache_state;
+                r_cas_local_way   = way;
+                r_cas_local_set   = set;
+                r_cas_local_word  = word;
+         
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name() 
+              << " DCACHE_TLB_PTE2_GET> HIT in dcache:"
+              << " PTE_FLAGS = " << std::hex << pte_flags
+              << " PTE_PPN = " << std::hex << pte_ppn << std::endl;
+}
+#endif
+             }
+        }
+        else if ( cache_state == CACHE_SLOT_STATE_ZOMBI ) // pending cleanup
+        {
+            // stalled until cleanup is acknowledged
+            r_dcache_fsm   = DCACHE_TLB_PTE2_GET;
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name() 
+              << " DCACHE_TLB_PTE2_GET> ZOMBI in dcache: waiting cleanup ack"
+              << std::endl;
+}
+#endif
+        }
+        else            // we must load the missing cache line in dcache
+        {
+            r_dcache_fsm          = DCACHE_MISS_SELECT;
+            r_dcache_vci_miss_req = true;
+            r_dcache_read_for_modify = false;
+            r_dcache_vci_paddr    = r_dcache_tlb_paddr.read();
+            r_dcache_save_paddr   = r_dcache_tlb_paddr.read();
+            r_dcache_miss_type    = PTE2_MISS;
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_TLB_PTE2_GET> MISS in dcache:"
+              << " PTE address = " << std::hex << r_dcache_tlb_paddr.read() << std::endl;
+}
+#endif
+        }
+        break;
+    }
+    ////////////////////////////
+    case DCACHE_TLB_PTE2_SELECT:    // select a slot for PTE2
+    {
+        size_t way;
+        size_t set;
+
+        if ( r_dcache_tlb_ins.read() )
+        {
+            r_itlb.select( r_dcache_tlb_vaddr.read(),
+                           false,	// PTE2
+                           &way,
+                           &set );
+#ifdef INSTRUMENTATION
+m_cpt_ins_tlb_read++;
+#endif
+        }
+        else
+        {
+            r_dtlb.select( r_dcache_tlb_vaddr.read(),
+                           false,	// PTE2
+                           &way,
+                           &set );
+#ifdef INSTRUMENTATION
+m_cpt_data_tlb_read++;
+#endif
+        }
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    if ( r_dcache_tlb_ins.read() )
+        std::cout << "  <PROC " << name()
+                  << " DCACHE_TLB_PTE2_SELECT> Select a slot in ITLB:";
+    else
+        std::cout << "  <PROC " << name()
+                  << " DCACHE_TLB_PTE2_SELECT> Select a slot in DTLB:";
+        std::cout << " way = " << std::dec << way
+                  << " / set = " << set << std::endl;
+}
+#endif
+        r_dcache_tlb_way = way;
+        r_dcache_tlb_set = set;
+        r_dcache_fsm     = DCACHE_TLB_PTE2_UPDT;
+        break;
+    }
+    //////////////////////////
+    case DCACHE_TLB_PTE2_UPDT:	// write a new PTE2 in tlb after testing the L/R bit
+                                // - if L/R bit already set, exit the sub-fsm.
+                                // - if not, we update the page table but we dont write
+                                //   neither in DCACHE, nor in TLB, as this will be done by
+                                //   the coherence mechanism.
+    {
+        paddr_t	        nline     = r_dcache_tlb_paddr.read() >> (uint32_log2(m_dcache_words)+2);
+        uint32_t        pte_flags = r_dcache_tlb_pte_flags.read();
+        uint32_t        pte_ppn   = r_dcache_tlb_pte_ppn.read();
+        bool            pt_updt   = false;
+        bool            local     = true;
+
+        // We should compute the access locality:
+        // The PPN MSB bits define the destination cluster index.
+        // The m_srcid MSB bits define the source cluster index.
+        // The number of bits to compare depends on the number of clusters,
+        // and can be obtained in the mapping table.
+        // As long as this computation is not done, all access are local.
+
+        if ( local )						// local access
+        {
+            if ( not ((pte_flags & PTE_L_MASK) == PTE_L_MASK) ) // we must set the L bit
+            {
+                pt_updt                = true;
+                r_dcache_vci_cas_old   = pte_flags;
+                r_dcache_vci_cas_new   = pte_flags | PTE_L_MASK;
+                pte_flags              = pte_flags | PTE_L_MASK;
+		        r_dcache_tlb_pte_flags = pte_flags;
+            }
+        }
+        else                                                    // remote access
+        {
+            if ( not ((pte_flags & PTE_R_MASK) == PTE_R_MASK) ) // we must set the R bit
+            {
+                pt_updt                = true;
+                r_dcache_vci_cas_old   = pte_flags;
+                r_dcache_vci_cas_new   = pte_flags | PTE_R_MASK;
+                pte_flags              = pte_flags | PTE_R_MASK;
+		        r_dcache_tlb_pte_flags = pte_flags;
+            }
+        }
+
+        if ( not pt_updt )                       // update TLB
+        {
+            if ( r_dcache_tlb_ins.read() )
+            {
+                r_itlb.write( false,	// 4K page
+                              pte_flags,
+                              pte_ppn,
+                              r_dcache_tlb_vaddr.read(),
+                              r_dcache_tlb_way.read(),
+                              r_dcache_tlb_set.read(),
+                              nline );
+#ifdef INSTRUMENTATION
+m_cpt_ins_tlb_update_acc++;
+#endif
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_TLB_PTE2_UPDT> write PTE2 in ITLB"
+              << " / set = " << std::dec << r_dcache_tlb_set.read()
+              << " / way = " << r_dcache_tlb_way.read() << std::endl;
+    r_itlb.printTrace();
+}
+#endif
+            }
+            else
+            {
+                r_dtlb.write( false,	// 4K page
+                              pte_flags,
+                              pte_ppn,
+                              r_dcache_tlb_vaddr.read(),
+                              r_dcache_tlb_way.read(),
+                              r_dcache_tlb_set.read(),
+                              nline );
+#ifdef INSTRUMENTATION
+m_cpt_data_tlb_update_acc++;
+#endif
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_TLB_PTE2_UPDT> write PTE2 in DTLB"
+              << " / set = " << std::dec << r_dcache_tlb_set.read()
+              << " / way = " << r_dcache_tlb_way.read() << std::endl;
+    r_dtlb.printTrace();
+}
+#endif
+
+            }
+            r_dcache_fsm = DCACHE_TLB_RETURN;
+        }
+        else                                   // update page table but not TLB
+        {
+            r_dcache_fsm = DCACHE_TLB_LR_UPDT; 	// dcache and page table update
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_TLB_PTE2_UPDT> L/R bit update required" << std::endl;
+}
+#endif
+        }
+        break;
+    }
+    ////////////////////////
+    case DCACHE_TLB_LR_UPDT:        // request a CAS transaction to update L/R bit
+    {
+        uint32_t way  = r_cas_local_way.read();
+        uint32_t set  = r_cas_local_set.read();
+        uint32_t word = r_cas_local_word.read();
+        paddr_t nline = r_dcache_tlb_paddr.read() >> (uint32_log2(m_dcache_words)+2);
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_TLB_LR_UPDT> Update dcache: (L/R) bit" << std::endl;
+}
+#endif
+
+        if (r_cas_cache_state.read() == CACHE_SLOT_STATE_EXCLUSIVE or 
+            r_cas_cache_state.read() == CACHE_SLOT_STATE_MODIFIED)
+        {
+            r_dcache.write(way,
+                           set,
+                           word,
+                           r_dcache_vci_cas_new.read());
+
+            if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_IN_TLB )
+            {
+                r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;
+                r_dcache_tlb_inval_line  = nline;
+                r_dcache_tlb_inval_set   = 0;
+                r_dcache_fsm_scan_save   = DCACHE_TLB_RETURN;
+                r_dcache_fsm             = DCACHE_INVAL_TLB_SCAN;
+                break;
+            }
+
+            if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_CONTAINS_PTD )
+            {
+                r_itlb.reset();
+                r_dtlb.reset();
+                r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;
+
+#if DEBUG_DCACHE
+                if ( m_debug_activated )
+                {
+                    std::cout << "  <PROC " << name()
+                        << " DCACHE_TLB_LR_UPDT> Flush DTLB & ITLB" << std::endl;
+                }
+#endif
+            }
+
+            if(r_cas_cache_state.read() == CACHE_SLOT_STATE_EXCLUSIVE)
+            {
+                r_dcache.write_dir(way,
+                                   set,
+                                   CACHE_SLOT_STATE_MODIFIED);
+            }
+            
+
+
+            r_dcache_fsm = DCACHE_TLB_RETURN; 
+        }
+        else if(r_cas_cache_state.read() == CACHE_SLOT_STATE_SHARED)
+        {
+            // r_dcache_vci_cas_old & r_dcache_vci_cas_new registers are already set
+            r_dcache_vci_paddr = r_dcache_tlb_paddr.read();
+
+            // checking llsc reservation buffer
+            if ( r_dcache_llsc_paddr.read() == r_dcache_tlb_paddr.read() )
+                r_dcache_llsc_valid = false;
+
+            // request a CAS CMD and go to DCACHE_TLB_LR_WAIT state
+            r_dcache_vci_cas_req = true;
+            r_dcache_fsm         = DCACHE_TLB_LR_WAIT;
+        }
+        break;
+    }
+    ////////////////////////
+    case DCACHE_TLB_LR_WAIT:		// Waiting the response to SC transaction for DIRTY bit.
+                                    // We consume the response in rsp FIFO,
+                                    // and exit the sub-fsm, but we don't
+                                    // analyse the response, because we don't
+                                    // care if the L/R bit update is not done.
+                                    // We must take the coherence requests because
+                                    // there is a risk of dead-lock
+
+    {
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        if ( r_vci_rsp_data_error.read() ) 	// bus error
+        {
+            std::cout << "BUS ERROR in DCACHE_TLB_LR_WAIT state" << std::endl;
+            std::cout << "This should not happen in this state" << std::endl;
+            exit(0);
+        }
+	    else if ( r_vci_rsp_fifo_dcache.rok() ) // response available
+	    {
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_TLB_LR_WAIT> SC response received" << std::endl;
+}
+#endif
+            if (not r_vci_rsp_fifo_dcache.read() and r_dcache_rsp_state.read()) // in the response of cas, a flag which is added in the vci rpktid informs to modify the line locally. 
+            {
+                r_dcache.write( r_cas_local_way.read(),
+                                r_cas_local_set.read(),
+                                r_cas_local_word.read(),
+                                r_dcache_vci_cas_new.read());
+
+               //r_dcache.write_dir( r_cas_local_way.read(),
+               //                    r_cas_local_set.read(),
+               //                    CACHE_SLOT_STATE_MODIFIED );
+            }
+
+            vci_rsp_fifo_dcache_get = true;
+            r_dcache_fsm            = DCACHE_TLB_RETURN;
+        }
+        break;
+    }
+    ///////////////////////
+    case DCACHE_TLB_RETURN:		// return to caller depending on tlb miss type
+    {
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_TLB_RETURN> TLB MISS completed" << std::endl;
+}
+#endif
+        if ( r_dcache_tlb_ins.read() ) r_icache_tlb_miss_req = false;
+        r_dcache_fsm = DCACHE_IDLE;
+        break;
+    }
+    ///////////////////////
+    case DCACHE_XTN_SWITCH:		// The r_ptpr registers must be written,
+                                // and both itlb and dtlb must be flushed.
+                                // Caution : the itlb miss requests must be taken
+                                // to avoid dead-lock in case of simultaneous ITLB miss
+    {
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // itlb miss request
+        if ( r_icache_tlb_miss_req.read() )
+        {
+            r_dcache_tlb_ins    = true;
+            r_dcache_tlb_vaddr  = r_icache_vaddr_save.read();
+            r_dcache_fsm        = DCACHE_TLB_MISS;
+            break;
+        }
+
+        if ( not r_dcache_xtn_req.read() )
+        {
+            r_dtlb.flush();
+            r_mmu_ptpr   = m_dreq.wdata;
+            r_dcache_fsm = DCACHE_IDLE;
+            m_drsp.valid = true;
+        }
+        break;
+    }
+    /////////////////////
+    case DCACHE_XTN_SYNC:		// waiting until write buffer empty
+                                // The coherence request must be taken
+                                // as there is a risk of dead-lock
+    {
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        if ( r_wbuf.empty() )
+        {
+            m_drsp.valid   = true;
+            r_dcache_fsm = DCACHE_IDLE;
+        }
+        break;
+    }
+    ////////////////////////
+    case DCACHE_XTN_IC_FLUSH:		// Waiting completion of an XTN request to the ICACHE FSM
+    case DCACHE_XTN_IC_INVAL_VA:	// Caution : the itlb miss requests must be taken
+    case DCACHE_XTN_IC_INVAL_PA:	// because the XTN_ICACHE_INVAL request to icache
+    case DCACHE_XTN_IT_INVAL:		// can generate an itlb miss,
+                                    // and because it can exist a simultaneous ITLB miss
+    {
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // itlb miss request
+        if ( r_icache_tlb_miss_req.read() )
+        {
+            r_dcache_tlb_ins    = true;
+            r_dcache_tlb_vaddr  = r_icache_vaddr_save.read();
+            r_dcache_fsm        = DCACHE_TLB_MISS;
+            break;
+        }
+
+        // test if XTN request to icache completed
+        if ( not r_dcache_xtn_req.read() )
+        {
+            r_dcache_fsm = DCACHE_IDLE;
+            m_drsp.valid = true;
+        }
+        break;
+    }
+    /////////////////////////
+    case DCACHE_XTN_DC_FLUSH:	// Invalidate sequencially all cache lines, using
+                                // r_dcache_flush_count as a slot counter,
+                                // looping in this state until all slots have been visited.
+                                // It can require two cycles per slot:
+                                // We test here the slot state, and make the actual inval
+                                // (if line is valid) in DCACHE_XTN_DC_FLUSH_GO state.
+                                // A cleanup request is generated for each valid line.
+                                // returns to IDLE and flush TLBs when last slot
+    {
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        if ( not r_dcache_cc_send_req.read() ) // blocked until previous cc_send request is sent
+        {
+            int       state;
+            paddr_t   tag;
+            size_t    way = r_dcache_flush_count.read()/m_dcache_sets;
+            size_t    set = r_dcache_flush_count.read()%m_dcache_sets;
+
+#ifdef INSTRUMENTATION
+m_cpt_dcache_dir_read++;
+#endif
+            r_dcache.read_dir( way,
+                               set,
+                               &tag,
+                               &state );
+
+            if ( state == CACHE_SLOT_STATE_SHARED )
+            {
+                r_dcache_cc_line_no_shared = false;
+            }
+            else
+            {
+                r_dcache_cc_line_no_shared = true;
+            }
+
+            if ( state == CACHE_SLOT_STATE_EXCLUSIVE or state == CACHE_SLOT_STATE_SHARED )         // inval required
+            {
+                // request cleanup
+                r_dcache_cc_send_req   = true;
+                r_dcache_cc_send_nline = tag * m_dcache_sets + set;
+                r_dcache_cc_send_way   = way;
+                r_dcache_cc_send_type  = CC_TYPE_CLEANUP;
+
+                // goes to DCACHE_XTN_DC_FLUSH_GO to inval directory
+                r_dcache_miss_way     = way;
+                r_dcache_miss_set     = set;
+                r_dcache_cc_line_dirty = false;
+                r_dcache_fsm          = DCACHE_XTN_DC_FLUSH_GO;
+            }
+            else if ( state == CACHE_SLOT_STATE_MODIFIED)
+            {
+                // request cleanup
+                r_dcache_cc_send_req   = true;
+                r_dcache_cc_send_nline = tag * m_dcache_sets + set;
+                r_dcache_cc_send_way   = way;
+                r_dcache_cc_send_type  = CC_TYPE_CLEANUP;
+
+                // goes to DCACHE_XTN_DC_FLUSH_GO to inval directory
+                r_dcache_miss_way     = way;
+                r_dcache_miss_set     = set;
+                r_dcache_cc_line_dirty = true;
+                r_dcache_xtn_flush_addr_data = (tag * m_dcache_sets + set) * m_dcache_words * 4;
+                r_dcache_xtn_flush_data_cpt = 0;
+                r_dcache_fsm          = DCACHE_XTN_DC_FLUSH_DATA;
+            }
+            else if ( r_dcache_flush_count.read() == (m_dcache_sets*m_dcache_ways - 1) )  // last slot
+            {
+                r_dtlb.reset();
+                r_itlb.reset();
+                r_dcache_fsm = DCACHE_IDLE;
+                m_drsp.valid = true;
+            }
+
+            // saturation counter
+            if ( r_dcache_flush_count.read() < (m_dcache_sets*m_dcache_ways - 1) )
+                r_dcache_flush_count = r_dcache_flush_count.read() + 1;
+        }
+        break;
+    }
+
+    ////////////////////////////
+    case DCACHE_XTN_DC_FLUSH_DATA:
+    {
+        uint32_t rdata;
+        size_t   way;
+        size_t   set;
+        size_t   word;
+
+        r_dcache.read_neutral(r_dcache_xtn_flush_addr_data.read(),
+                              &rdata,
+                              &way,
+                              &set,
+                              &word);
+        if(r_cc_send_data_fifo.wok())
+        {
+            r_dcache_xtn_flush_addr_data = r_dcache_xtn_flush_addr_data.read() + 4;
+
+            cleanup_data_updt_fifo_dcache_put   = true;
+            cleanup_data_updt_fifo_dcache_data  = rdata;
+
+            r_dcache_xtn_flush_data_cpt = r_dcache_xtn_flush_data_cpt + 1;
+            if(r_dcache_xtn_flush_data_cpt.read() == (m_dcache_words - 1))
+            {
+                r_dcache_fsm = DCACHE_XTN_DC_FLUSH_GO;
+            }
+        }
+//       else if ( r_dcache_clack_req.read() )
+//       {
+//           r_dcache_fsm = DCACHE_CC_CHECK;
+//           r_dcache_fsm_cc_save = r_dcache_fsm.read();
+//           break;
+//       }
+        break;
+    }
+
+    ////////////////////////////
+    case DCACHE_XTN_DC_FLUSH_GO:    // Switch the cache slot to ZOMBI state
+                                    // and reset directory extension.
+                                    // returns to IDLE and flush TLBs when last slot
+    {
+        size_t way = r_dcache_miss_way.read();
+        size_t set = r_dcache_miss_set.read();
+
+        // MODIFIED
+        //r_dcache_in_tlb[m_dcache_sets*way+set]       = false;
+        //r_dcache_contains_ptd[m_dcache_sets*way+set] = false;
+        r_dcache_content_state[m_dcache_sets*way+set]  = LINE_EMPTY;
+
+#ifdef INSTRUMENTATION
+m_cpt_dcache_dir_write++;
+#endif
+
+        r_dcache.write_dir( way,
+                            set,
+                            CACHE_SLOT_STATE_ZOMBI );
+
+        if ( r_dcache_flush_count.read() ==
+             (m_dcache_sets*m_dcache_ways - 1) )  // last slot
+        {
+            r_dtlb.reset();
+            r_itlb.reset();
+            r_dcache_fsm = DCACHE_IDLE;
+            m_drsp.valid = true;
+        }
+        else
+        {
+            r_dcache_fsm = DCACHE_XTN_DC_FLUSH;
+        }
+        break;
+    }
+    /////////////////////////
+    case DCACHE_XTN_DT_INVAL: 	// handling processor XTN_DTLB_INVAL request
+    {
+        r_dtlb.inval(r_dcache_save_wdata.read());
+        r_dcache_fsm        = DCACHE_IDLE;
+        m_drsp.valid          = true;
+        break;
+    }
+    ////////////////////////////
+    case DCACHE_XTN_DC_INVAL_VA:  // selective cache line invalidate with virtual address
+                                  // requires 3 cycles: access tlb, read cache, inval cache
+                               	  // we compute the physical address in this state
+    {
+        paddr_t paddr;
+        bool    hit;
+
+        if ( r_mmu_mode.read() & DATA_TLB_MASK ) 	// dtlb activated
+        {
+
+#ifdef INSTRUMENTATION
+m_cpt_data_tlb_read++;
+#endif
+            hit = r_dtlb.translate( r_dcache_save_wdata.read(),
+                                    &paddr );
+        }
+        else 						// dtlb not activated
+        {
+            paddr = (paddr_t)r_dcache_save_wdata.read();
+            hit   = true;
+        }
+
+        if ( hit )		// tlb hit
+        {
+            r_dcache_save_paddr = paddr;
+            r_dcache_fsm      = DCACHE_XTN_DC_INVAL_PA;
+        }
+        else			// tlb miss
+       	{
+
+#ifdef INSTRUMENTATION
+m_cpt_data_tlb_miss++;
+#endif
+            r_dcache_tlb_ins    = false;		// dtlb
+            r_dcache_tlb_vaddr  = r_dcache_save_wdata.read();
+            r_dcache_fsm        = DCACHE_TLB_MISS;
+        }
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_XTN_DC_INVAL_VA> Compute physical address" << std::hex
+              << " / VADDR = " << r_dcache_save_wdata.read()
+              << " / PADDR = " << paddr << std::endl;
+}
+#endif
+
+        break;
+    }
+    ////////////////////////////
+    case DCACHE_XTN_DC_INVAL_PA:  // selective cache line invalidate with physical address
+                                  // requires 2 cycles: read cache / inval cache
+                                  // In this state we read dcache.
+    {
+        size_t		way;
+        size_t		set;
+        size_t		word;
+        int         state;
+
+#ifdef INSTRUMENTATION
+m_cpt_dcache_dir_read++;
+#endif
+        r_dcache.read_dir( r_dcache_save_paddr.read(),
+                           &state,
+                           &way,
+                           &set,
+                           &word );
+        if ((state != CACHE_SLOT_STATE_INVALID) and (state != CACHE_SLOT_STATE_ZOMBI))	// inval to be done
+        {
+            r_dcache_xtn_way       = way;
+            r_dcache_xtn_set       = set;
+            r_dcache_xtn_state     = state;
+            r_dcache_xtn_data_addr = r_dcache_save_paddr.read()&~0x3F;
+            
+            r_dcache_fsm = DCACHE_XTN_DC_INVAL_GO;
+            
+        }
+        else		// miss : nothing to do
+        {
+            r_dcache_fsm      = DCACHE_IDLE;
+            m_drsp.valid      = true;
+        }
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_XTN_DC_INVAL_PA> Test hit in dcache" << std::hex
+              << " / PADDR = " << r_dcache_save_paddr.read() << std::dec
+              << " / HIT = " << ((state == CACHE_SLOT_STATE_MODIFIED) or (state == CACHE_SLOT_STATE_SHARED) or (state == CACHE_SLOT_STATE_EXCLUSIVE))
+              << " / SET = " << set
+              << " / WAY = " << way << std::endl;
+    //r_dcache.printTrace();
+}
+#endif
+        break;
+    }
+    ////////////////////////////
+    case DCACHE_XTN_DC_INVAL_GO:  // In this state, we invalidate the cache line
+        			              // Blocked if previous cleanup not completed
+                                  // Test if itlb or dtlb inval is required
+    {
+        if ( not r_dcache_cc_send_req.read() ) // blocked until previous cc_send request is sent
+        {
+            int     state      = r_dcache_xtn_state.read();
+            size_t	way        = r_dcache_xtn_way.read();
+            size_t	set        = r_dcache_xtn_set.read();
+            paddr_t nline      = r_dcache_save_paddr.read() / (m_dcache_words<<2);
+
+#ifdef INSTRUMENTATION
+m_cpt_dcache_dir_write++;
+#endif
+            if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_IN_TLB )
+            {
+                r_dcache_tlb_inval_line = nline;
+                r_dcache_tlb_inval_set  = 0;
+                r_dcache_fsm_scan_save  = DCACHE_XTN_DC_INVAL_GO;
+                r_dcache_fsm            = DCACHE_INVAL_TLB_SCAN;
+                r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;
+                break;
+            }
+            else if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_CONTAINS_PTD)
+            {
+                r_itlb.reset();
+                r_dtlb.reset();
+                r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;
+            }
+
+            if ( state == CACHE_SLOT_STATE_SHARED )
+            {
+                r_dcache_cc_line_no_shared = false;
+            }
+            else
+            {
+                r_dcache_cc_line_no_shared = true;
+            }
+
+            if ((state == CACHE_SLOT_STATE_EXCLUSIVE) or (state == CACHE_SLOT_STATE_SHARED))// request cleanup
+            {
+                r_dcache_cc_send_req   = true;
+                r_dcache_cc_send_nline = nline;
+                r_dcache_cc_send_way   = way;
+                r_dcache_cc_send_type  = CC_TYPE_CLEANUP;
+                r_dcache_cc_line_dirty = false;
+                r_dcache.write_dir( way,
+                                    set,
+                                    CACHE_SLOT_STATE_ZOMBI );
+                r_dcache_fsm = DCACHE_XTN_DC_INVAL_END;
+            }
+            else if (state == CACHE_SLOT_STATE_MODIFIED)
+            {
+                r_dcache_xtn_data_cpt  = 0;
+                r_dcache_cc_send_req   = true;
+                r_dcache_cc_line_dirty = true;   //send data for a MODIFIED line
+                r_dcache_cc_send_nline = nline;
+                r_dcache_cc_send_way   = way;
+                r_dcache_cc_send_type  = CC_TYPE_CLEANUP;
+                r_dcache_fsm = DCACHE_XTN_DC_INVAL_DATA;
+            }
+            else
+            {
+                assert(false && "you forget something!!!");
+            }
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_XTN_DC_INVAL_GO> Actual dcache inval" << std::hex
+              << " / PADDR = " << r_dcache_save_paddr.read() << std::endl;
+}
+#endif
+	    }
+        break;
+    }
+
+    /*ODCCP*/
+    //////////////////////////////
+    case DCACHE_XTN_DC_INVAL_DATA:  	//A verifier
+    {
+
+        uint32_t rdata;
+        size_t   way;
+        size_t   set;
+        size_t   word;
+        r_dcache.read_neutral(r_dcache_xtn_data_addr.read(),
+                              &rdata,
+                              &way,
+                              &set,
+                              &word);
+        if(r_cc_send_data_fifo.wok())
+        {
+            r_dcache_xtn_data_addr = r_dcache_xtn_data_addr.read() + 4;
+
+            cleanup_data_updt_fifo_dcache_put   = true;
+            cleanup_data_updt_fifo_dcache_data  = rdata;
+
+            r_dcache_xtn_data_cpt = r_dcache_xtn_data_cpt.read() + 1;
+            if(r_dcache_xtn_data_cpt.read() == (m_dcache_words - 1))
+            {
+                r_dcache_fsm = DCACHE_XTN_DC_INVAL_END;
+                r_dcache.write_dir( way,
+                                    set,
+                                    CACHE_SLOT_STATE_ZOMBI );
+            }
+        }
+        break;
+    }
+
+    //////////////////////////////
+    case DCACHE_XTN_DC_INVAL_END:  	// send response to processor XTN request
+    {
+        r_dcache_fsm = DCACHE_IDLE;
+        m_drsp.valid = true;
+        break;
+    }
+    ////////////////////////
+    case DCACHE_MISS_SELECT:   // Try to select a slot in associative set
+                               // if previous cleanup has been sent.
+                               // Waiting in this state if no slot available
+                               // Set the r_dcache_cleanup_req flip-flop
+                               // and the r_dcache_miss_clack flip-flop
+                               // when a cleanup is required
+    {
+        if ( m_dreq.valid) m_cost_data_miss_frz++;
+
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+            bool     found      = false;
+            bool     cleanup    = false;
+            size_t   way        = 0;
+            size_t   set        = 0;
+            paddr_t  victim     = 0;
+            int      state;
+            bool     s_cleanup_line_dirty     = false;
+            bool     s_cleanup_line_no_shared = false;
+
+#ifdef INSTRUMENTATION
+m_cpt_dcache_dir_read++;
+#endif
+            r_dcache.read_select( r_dcache_save_paddr.read(),
+                                  &victim,
+                                  &way,
+                                  &set,
+                                  &found,
+                                  &cleanup );
+            state = r_dcache.get_cache_state(way,set);
+
+            if ( found )
+            {
+                r_dcache_miss_way = way;
+                r_dcache_miss_set = set;
+
+                if ( cleanup )
+                {
+                    r_dcache_miss_clack   = true;
+
+                    if ( state == CACHE_SLOT_STATE_SHARED )
+                    {
+                        s_cleanup_line_no_shared = false;
+                    }
+                    else
+                    {
+                        s_cleanup_line_no_shared = true;
+                    }
+
+                    if( (state == CACHE_SLOT_STATE_EXCLUSIVE) or (state == CACHE_SLOT_STATE_SHARED) )
+                    {
+                        s_cleanup_line_dirty = false;
+                        r_dcache_fsm          = DCACHE_MISS_CLEAN;
+                    }
+                    else if (state == CACHE_SLOT_STATE_MODIFIED)    
+                    {
+                        s_cleanup_line_dirty    = true;
+                        r_dcache_miss_data_addr = (victim*m_dcache_words)*4;
+                        r_dcache_miss_data_cpt = 0;
+                        r_dcache_fsm            = DCACHE_MISS_DATA;
+                    }
+
+                    if( not r_dcache_cc_send_req.read() )
+                    {
+                        // request cleanup
+                        r_dcache_cc_send_req        = true;
+                        r_dcache_cc_send_nline      = victim;
+                        r_dcache_cc_send_way        = way;
+                        r_dcache_cc_send_type       = CC_TYPE_CLEANUP;
+                        r_dcache_cc_line_dirty      = s_cleanup_line_dirty;
+                        r_dcache_cc_line_no_shared  = s_cleanup_line_no_shared;
+                    }
+                    else
+                    {
+                        r_dcache_cleanup_victim_nline           = victim;
+                        r_dcache_cleanup_victim_req             = true;
+                        r_dcache_cleanup_victim_line_dirty      = s_cleanup_line_dirty;
+                        r_dcache_cleanup_victim_line_no_shared  = s_cleanup_line_no_shared;
+                    }
+                }
+                else
+                {
+                    r_dcache_fsm          = DCACHE_MISS_WAIT;
+                }
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_MISS_SELECT> Select a slot:" << std::dec
+              << " / WAY = "   << way
+              << " / SET = "   << set
+              << " / PADDR = " << std::hex << r_dcache_save_paddr.read();
+    if(cleanup) std::cout << " / VICTIM = " << (victim*m_dcache_words*4) << std::endl;
+    else        std::cout << std::endl;
+}
+#endif
+            } // end found
+        break;
+    }
+    ///////////////////////
+    case DCACHE_MISS_DATA:
+    {
+        uint32_t rdata;
+        size_t way;
+        size_t set;
+        size_t word;
+
+        if( r_dcache_cleanup_victim_req.read() and not r_dcache_cc_send_req.read() )
+        {
+            r_dcache_cc_send_req        = true;
+            r_dcache_cc_send_type       = CC_TYPE_CLEANUP;
+            r_dcache_cc_send_nline      = r_dcache_cleanup_victim_nline.read();
+            r_dcache_cleanup_victim_req = false;
+            r_dcache_cc_line_dirty      = r_dcache_cleanup_victim_line_dirty.read();
+            r_dcache_cc_line_no_shared  = r_dcache_cleanup_victim_line_no_shared.read();
+            r_dcache_cc_send_way        = r_dcache_miss_way.read();
+        }
+
+        r_dcache.read_neutral(r_dcache_miss_data_addr,
+                              &rdata,
+                              &way,
+                              &set,
+                              &word);
+        if(r_cc_send_data_fifo.wok())
+        {
+            r_dcache_miss_data_addr = r_dcache_miss_data_addr.read() + 4;
+
+            cleanup_data_updt_fifo_dcache_put   = true;
+            cleanup_data_updt_fifo_dcache_data  = rdata;
+
+            r_dcache_miss_data_cpt = r_dcache_miss_data_cpt.read() + 1;
+            if (r_dcache_miss_data_cpt.read() == m_dcache_words-1 )
+            {
+                r_dcache_fsm = DCACHE_MISS_CLEAN;
+            }
+        }
+//       else if ( r_dcache_clack_req.read() )
+//       {
+//           r_dcache_fsm = DCACHE_CC_CHECK;
+//           r_dcache_fsm_cc_save = r_dcache_fsm.read();
+//           break;
+//       }
+
+        break;
+    }
+    ///////////////////////
+    case DCACHE_MISS_CLEAN:		// switch the slot to ZOMBI state
+                                // and possibly request itlb or dtlb invalidate
+    {
+        if ( m_dreq.valid) m_cost_data_miss_frz++;
+
+        size_t  way   = r_dcache_miss_way.read();
+        size_t  set   = r_dcache_miss_set.read();
+
+#ifdef INSTRUMENTATION
+m_cpt_dcache_dir_read++;
+#endif
+        r_dcache.write_dir( way,
+                            set,
+                            CACHE_SLOT_STATE_ZOMBI );
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_MISS_CLEAN> Switch to ZOMBI state" << std::dec
+              << " / way = "   << way
+              << " / set = "   << set << std::endl;
+}
+#endif
+        // if selective itlb & dtlb invalidate are required
+        // the miss response is not handled before invalidate completed
+        // MODIFIED
+        //if ( r_dcache_in_tlb[way*m_dcache_sets+set] )
+        //{
+        if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_IN_TLB )
+        {
+            //MODIFIED
+            //r_dcache_in_tlb[way*m_dcache_sets+set] = false;
+            r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;
+            if( not r_dcache_cleanup_victim_req.read() )
+            {
+                r_dcache_tlb_inval_line = r_dcache_cc_send_nline.read();
+            }
+            else
+            {
+                r_dcache_tlb_inval_line = r_dcache_cleanup_victim_nline.read();
+            }
+            r_dcache_tlb_inval_set   = 0;
+            r_dcache_fsm_scan_save   = DCACHE_MISS_WAIT;
+            r_dcache_fsm             = DCACHE_INVAL_TLB_SCAN;
+        }
+        // MODIFIED
+        //else if ( r_dcache_contains_ptd[way*m_dcache_sets+set] )
+        //{
+        else if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_CONTAINS_PTD )
+        {
+            r_itlb.reset();
+            r_dtlb.reset();
+            // MODIFIED
+            //r_dcache_contains_ptd[way*m_dcache_sets+set] = false;
+            r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;
+            r_dcache_fsm = DCACHE_MISS_WAIT;
+        }
+        else
+        {
+            r_dcache_fsm = DCACHE_MISS_WAIT;
+        }
+        break;
+    }
+    //////////////////////
+    case DCACHE_MISS_WAIT:	// waiting the response to a miss request from VCI_RSP FSM
+                            // This state is in charge of error signaling
+                            // There is 5 types of error depending on the requester
+    {
+        if ( m_dreq.valid) m_cost_data_miss_frz++;
+
+        if( r_dcache_cleanup_victim_req.read() and not r_dcache_cc_send_req.read() )
+        {
+            r_dcache_cc_send_req        = true;
+            r_dcache_cc_send_type       = CC_TYPE_CLEANUP;
+            r_dcache_cc_send_nline      = r_dcache_cleanup_victim_nline.read();
+            r_dcache_cleanup_victim_req = false;
+            r_dcache_cc_line_dirty      = r_dcache_cleanup_victim_line_dirty.read();
+            r_dcache_cc_line_no_shared  = r_dcache_cleanup_victim_line_no_shared.read();
+            r_dcache_cc_send_way        = r_dcache_miss_way.read();
+        }
+
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read() and not r_dcache_cleanup_victim_req.read() and not r_dcache_miss_updt.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        if ( r_vci_rsp_data_error.read() ) 			// bus error
+        {
+            switch ( r_dcache_miss_type.read() )
+            {
+                case PROC_MISS:
+                {
+                    r_mmu_detr            = MMU_READ_DATA_ILLEGAL_ACCESS;
+                    r_mmu_dbvar           = r_dcache_save_vaddr.read();
+                    m_drsp.valid            = true;
+                    m_drsp.error            = true;
+                    r_dcache_fsm          = DCACHE_IDLE;
+                    break;
+                }
+                case PTE1_MISS:
+                {
+                    if ( r_dcache_tlb_ins.read() )
+                    {
+                        r_mmu_ietr              = MMU_READ_PT1_ILLEGAL_ACCESS;
+                        r_mmu_ibvar             = r_dcache_tlb_vaddr.read();
+                        r_icache_tlb_miss_req   = false;
+                        r_icache_tlb_rsp_error  = true;
+                    }
+                    else
+                    {
+                        r_mmu_detr              = MMU_READ_PT1_ILLEGAL_ACCESS;
+                        r_mmu_dbvar             = r_dcache_tlb_vaddr.read();
+                        m_drsp.valid              = true;
+                        m_drsp.error              = true;
+                    }
+                    r_dcache_fsm                = DCACHE_IDLE;
+                    break;
+                }
+                case PTE2_MISS:
+                {
+                    if ( r_dcache_tlb_ins.read() )
+                    {
+                        r_mmu_ietr              = MMU_READ_PT2_ILLEGAL_ACCESS;
+                        r_mmu_ibvar             = r_dcache_tlb_vaddr.read();
+                        r_icache_tlb_miss_req   = false;
+                        r_icache_tlb_rsp_error  = true;
+                    }
+                    else
+                    {
+                        r_mmu_detr              = MMU_READ_PT2_ILLEGAL_ACCESS;
+                        r_mmu_dbvar             = r_dcache_tlb_vaddr.read();
+                        m_drsp.valid              = true;
+                        m_drsp.error              = true;
+                    }
+                    r_dcache_fsm                = DCACHE_IDLE;
+                    break;
+                }
+            } // end switch type
+            r_vci_rsp_data_error = false;
+        }
+        else if ( r_vci_rsp_fifo_dcache.rok() )		// valid response available
+        {
+            r_dcache_miss_word = 0;
+	        r_dcache_fsm       = DCACHE_MISS_DATA_UPDT;
+        }
+        break;
+    }
+    //////////////////////////
+    case DCACHE_MISS_DATA_UPDT:	  // update the dcache (one word per cycle)
+    {
+        if ( m_dreq.valid) m_cost_data_miss_frz++;
+
+        if ( r_vci_rsp_fifo_dcache.rok() )	// one word available
+        {
+#ifdef INSTRUMENTATION
+m_cpt_dcache_data_write++;
+#endif
+                r_dcache.write( r_dcache_miss_way.read(),
+                                r_dcache_miss_set.read(),
+                                r_dcache_miss_word.read(),
+                                r_vci_rsp_fifo_dcache.read() );
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_MISS_DATA_UPDT> Write one word:"
+              << " / DATA = "  << std::hex << r_vci_rsp_fifo_dcache.read()
+              << " / WAY = "   << std::dec << r_dcache_miss_way.read()
+              << " / SET = "   << r_dcache_miss_set.read()
+              << " / WORD = "  << r_dcache_miss_word.read() << std::endl;
+}
+#endif
+            vci_rsp_fifo_dcache_get = true;
+
+           // r_dcache_rsp_state = !r_vci_rsp_fifo_rpktid.read();//deduce the state (CC or NCC) from msb of pktid
+            vci_rsp_fifo_rpktid_get = true;
+
+
+            r_dcache_miss_word = r_dcache_miss_word.read() + 1;
+
+            if ( r_dcache_miss_word.read() == (m_dcache_words-1) ) // last word
+            {
+                r_dcache_fsm = DCACHE_MISS_DIR_UPDT;
+            }
+        }
+        break;
+    }
+    //////////////////////////
+    case DCACHE_MISS_DIR_UPDT:  // Stalled if a victim line has been evicted
+                                // and the cleanup ack has not been received,
+                                // as indicated by the r_dcache_miss clack.
+                                // - If no matching coherence request (r_dcache_inval_miss)
+                                //   switch directory slot to VALID state.
+                                // - If matching coherence request, switch directory slot
+                                //   to ZOMBI state, and send a cleanup request.
+    {
+        if ( m_dreq.valid) m_cost_data_miss_frz++;
+
+        if( r_dcache_cleanup_victim_req.read() and not r_dcache_cc_send_req.read() )
+        {
+            r_dcache_cc_send_req        = true;
+            r_dcache_cc_send_type       = CC_TYPE_CLEANUP;
+            r_dcache_cc_send_nline      = r_dcache_cleanup_victim_nline.read();
+            r_dcache_cleanup_victim_req = false;
+            r_dcache_cc_line_dirty      = r_dcache_cleanup_victim_line_dirty.read();
+            r_dcache_cc_line_no_shared  = r_dcache_cleanup_victim_line_no_shared.read();
+            r_dcache_cc_send_way        = r_dcache_miss_way.read();
+        }
+
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read() and not r_dcache_cleanup_victim_req.read() and not r_dcache_miss_updt.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        if ( not r_dcache_miss_clack.read() )  // waiting cleanup acknowledge
+        {
+            if ( r_dcache_miss_inval.read() ) // switch slot to ZOMBI state, and new cleanup
+            {
+                if ( not r_dcache_cc_send_req.read() ) // blocked until previous request sent
+                {
+                    r_dcache_miss_inval         = false;
+                    // request cleanup
+                    r_dcache_cc_send_req        = true;
+                    r_dcache_cc_send_nline      = r_dcache_save_paddr.read()/(m_dcache_words<<2);
+                    r_dcache_cc_send_way        = r_dcache_miss_way.read();
+                    r_dcache_cc_send_type       = CC_TYPE_CLEANUP;
+                    r_dcache_cc_line_dirty      = false;   // in case of miss inval, the cleanup is not with data.
+                    r_dcache_cc_line_no_shared  = r_dcache_rsp_state.read(); // the miss read rsp contents the state of this line 
+
+#ifdef INSTRUMENTATION
+m_cpt_dcache_dir_write++;
+#endif
+                    r_dcache.write_dir( r_dcache_save_paddr.read(),
+                                        r_dcache_miss_way.read(),
+                                        r_dcache_miss_set.read(),
+                                        CACHE_SLOT_STATE_ZOMBI );
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+std::cout << "  <PROC " << name()
+          << " DCACHE_MISS_DIR_UPDT> Switch slot to ZOMBI state"
+          << " PADDR = " << std::hex << r_dcache_save_paddr.read()
+          << " / WAY = "   << std::dec << r_dcache_miss_way.read()
+          << " / SET = "   << r_dcache_miss_set.read() << std::endl;
+#endif
+                }
+                else
+                    break;
+            }
+            else                              // switch slot to VALID state
+            {
+
+#ifdef INSTRUMENTATION
+m_cpt_dcache_dir_write++;
+#endif
+
+                size_t way = r_dcache_miss_way.read();
+                size_t set = r_dcache_miss_set.read();
+                if ( r_dcache_rsp_state.read())
+                {
+                    r_dcache.write_dir( r_dcache_save_paddr.read(),
+                                        r_dcache_miss_way.read(),
+                                        r_dcache_miss_set.read(),
+                                        CACHE_SLOT_STATE_EXCLUSIVE );
+                }
+                else
+                {
+                    r_dcache.write_dir( r_dcache_save_paddr.read(),
+                                        r_dcache_miss_way.read(),
+                                        r_dcache_miss_set.read(),
+                                        CACHE_SLOT_STATE_SHARED );
+                }
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+std::cout << "  <PROC " << name()
+          << " DCACHE_MISS_DIR_UPDT> Switch slot to VALID state"
+          << " r_dcache_rsp_state = " << r_dcache_rsp_state.read()
+          << " PADDR = " << std::hex << r_dcache_save_paddr.read()
+          << " / WAY = "   << std::dec << r_dcache_miss_way.read()
+          << " / SET = "   << r_dcache_miss_set.read() << std::endl;
+#endif
+                // reset directory extension
+
+            }
+            if      (r_dcache_miss_type.read()==PTE1_MISS) r_dcache_fsm = DCACHE_TLB_PTE1_GET;
+            else if (r_dcache_miss_type.read()==PTE2_MISS) r_dcache_fsm = DCACHE_TLB_PTE2_GET;
+            else                                           r_dcache_fsm = DCACHE_IDLE;
+        }
+        break;
+    }
+    /////////////////////
+    case DCACHE_UNC_WAIT:  // waiting a response to an uncacheable read
+    {
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        if ( r_vci_rsp_data_error.read() ) 	// bus error
+        {
+            if(r_dcache_vci_unc_write.read())
+                r_mmu_detr           = MMU_WRITE_DATA_ILLEGAL_ACCESS;
+            else
+                r_mmu_detr           = MMU_READ_DATA_ILLEGAL_ACCESS;
+            r_mmu_dbvar          = m_dreq.addr;
+            r_vci_rsp_data_error = false;
+            m_drsp.error         = true;
+            m_drsp.valid         = true;
+            r_dcache_fsm         = DCACHE_IDLE;
+            break;
+        }
+	    else if ( r_vci_rsp_fifo_dcache.rok() )     // data available
+	    {
+            // consume data
+            vci_rsp_fifo_dcache_get = true;
+            r_dcache_fsm            = DCACHE_IDLE;
+
+            // acknowledge the processor request if it has not been modified
+            if ( m_dreq.valid and (m_dreq.addr == r_dcache_save_vaddr.read()) )
+            {
+	            m_drsp.valid        = true;
+                m_drsp.error        = false;
+	            m_drsp.rdata        = r_vci_rsp_fifo_dcache.read();
+            }
+	    }
+        break;
+    }
+    /////////////////////
+    case DCACHE_LL_WAIT:    // waiting VCI response to a LL transaction
+    {
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        if ( r_vci_rsp_data_error.read() ) 	// bus error
+        {
+            r_mmu_detr           = MMU_READ_DATA_ILLEGAL_ACCESS;
+            r_mmu_dbvar          = m_dreq.addr;
+            r_vci_rsp_data_error = false;
+            m_drsp.error         = true;
+            m_drsp.valid         = true;
+            r_dcache_fsm         = DCACHE_IDLE;
+            break;
+        }
+	    else if ( r_vci_rsp_fifo_dcache.rok() )     // data available
+	    {
+            // consume data
+            vci_rsp_fifo_dcache_get = true;
+
+            if(r_dcache_ll_rsp_count.read() == 0) // first flit
+            {
+                // set key value in llsc reservation buffer
+                r_dcache_llsc_key     = r_vci_rsp_fifo_dcache.read();
+                r_dcache_ll_rsp_count = r_dcache_ll_rsp_count.read() + 1 ;
+            }
+            else                                  // last flit
+            {
+                // acknowledge the processor request if it has not been modified
+                if ( m_dreq.valid and (m_dreq.addr == r_dcache_save_vaddr.read()) )
+                {
+                    m_drsp.valid        = true;
+                    m_drsp.error        = false;
+                    m_drsp.rdata        = r_vci_rsp_fifo_dcache.read();
+                }
+                r_dcache_fsm = DCACHE_IDLE;
+            }
+	    }
+        break;
+    }
+    ////////////////////
+    case DCACHE_SC_WAIT:	// waiting VCI response to a SC transaction
+    {
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        if ( r_vci_rsp_data_error.read() ) 		// bus error
+        {
+            r_mmu_detr           = MMU_READ_DATA_ILLEGAL_ACCESS;
+            r_mmu_dbvar          = m_dreq.addr;
+            r_vci_rsp_data_error = false;
+            m_drsp.error         = true;
+            m_drsp.valid         = true;
+            r_dcache_fsm         = DCACHE_IDLE;
+            break;
+        }
+	    else if ( r_vci_rsp_fifo_dcache.rok() ) // response available
+	    {
+            // consume response
+            vci_rsp_fifo_dcache_get = true;
+            m_drsp.valid            = true;
+            m_drsp.rdata            = r_vci_rsp_fifo_dcache.read();
+            r_dcache_fsm            = DCACHE_IDLE;
+	    }
+        break;
+    }
+    //////////////////////////
+    case DCACHE_DIRTY_GET_PTE:		// This sub_fsm set the PTE Dirty bit in memory
+                                    // before handling a processor WRITE or SC request
+                                    // Input argument is r_dcache_dirty_paddr
+                                    // In this first state, we get PTE value in dcache
+                                    // and post a CAS request to CMD FSM
+    {
+        // get PTE in dcache
+        uint32_t pte;
+        size_t   way;
+        size_t   set;
+        size_t   word; // unused
+        int      state;
+
+#ifdef INSTRUMENTATION
+m_cpt_dcache_data_read++;
+m_cpt_dcache_dir_read++;
+#endif
+        r_dcache.read( r_dcache_dirty_paddr.read(),
+                       &pte,
+                       &way,
+                       &set,
+                       &word,
+                       &state );
+
+        assert( (state != CACHE_SLOT_STATE_INVALID and state != CACHE_SLOT_STATE_ZOMBI) and
+        "error in DCACHE_DIRTY_TLB_SET: the PTE should be in dcache" );
+
+        // request CAS transaction to CMD_FSM
+        r_dcache_dirty_way  = way;
+        r_dcache_dirty_set  = set;
+        r_dcache_dirty_word = word;
+        r_dcache_dirty_state = state;
+        r_dcache_vci_cas_new = pte | PTE_D_MASK;
+        // check llsc reservation buffer
+        if (r_dcache_llsc_paddr.read() == r_dcache_dirty_paddr.read() )
+            r_dcache_llsc_valid = false;
+
+        // request a CAS CMD and go to DCACHE_DIRTY_WAIT state
+        if (state == CACHE_SLOT_STATE_SHARED)
+        {
+            r_dcache_vci_cas_req = true;
+            r_dcache_vci_paddr   = r_dcache_dirty_paddr.read();
+            r_dcache_vci_cas_old = pte;
+        }
+
+        r_dcache_fsm         = DCACHE_DIRTY_WAIT;
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_DIRTY_GET_PTE> CAS request" << std::hex
+              << " / PTE_PADDR = " << r_dcache_dirty_paddr.read()
+              << " / PTE_VALUE = " << pte << std::dec
+              << " / SET = " << set
+              << " / WAY = " << way << std::endl;
+}
+#endif
+        break;
+    }
+    ///////////////////////
+    case DCACHE_DIRTY_WAIT:         // wait completion of CAS for PTE Dirty bit,
+                                    // and return to IDLE state when response is received.
+                                    // we don't care if the CAS is a failure:
+                                    // - if the CAS is a success, the coherence mechanism
+                                    //   updates the local copy.
+                                    // - if the CAS is a failure, we just retry the write.
+    {
+        uint32_t way  = r_dcache_dirty_way.read();
+        uint32_t set  = r_dcache_dirty_set.read();
+        uint32_t word = r_dcache_dirty_word.read();
+        paddr_t nline = r_dcache_dirty_paddr.read() / (m_dcache_words<<2);
+
+        // coherence clack request (from DSPIN CLACK)
+        if ( r_dcache_clack_req.read() )
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        // coherence request (from CC_RECEIVE FSM)
+        if ( r_cc_receive_dcache_req.read() and not r_dcache_cc_send_req.read())
+        {
+            r_dcache_fsm = DCACHE_CC_CHECK;
+            r_dcache_fsm_cc_save = r_dcache_fsm.read();
+            break;
+        }
+
+        if ( r_dcache_dirty_state == CACHE_SLOT_STATE_SHARED )
+        {
+            if ( r_vci_rsp_data_error.read() )	// bus error
+            {
+                std::cout << "BUS ERROR in DCACHE_DIRTY_WAIT state" << std::endl;
+                std::cout << "This should not happen in this state" << std::endl;
+                exit(0);
+            }
+            else if ( r_vci_rsp_fifo_dcache.rok() )	// response available
+            {
+                vci_rsp_fifo_dcache_get = true;
+                if( not r_vci_rsp_fifo_dcache.read() and r_dcache_rsp_state.read())  //cas success!!
+                {
+
+                    r_dcache.write( way,
+                                    set,
+                                    word,
+                                    r_dcache_vci_cas_new.read());
+
+                   //r_dcache.write_dir( way,
+                   //                    set,
+                   //                    CACHE_SLOT_STATE_MODIFIED );
+
+#if DEBUG_DCACHE
+                if ( m_debug_activated )
+                {
+                    std::cout << "  <PROC " << name()
+                        << " DCACHE_DIRTY_WAIT> state modified : " << CACHE_SLOT_STATE_MODIFIED << std::endl;
+                }
+#endif
+                    if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_IN_TLB )
+                    {
+                        r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;
+                        r_dcache_tlb_inval_line  = nline;
+                        r_dcache_tlb_inval_set   = 0;
+                        r_dcache_fsm_scan_save   = DCACHE_IDLE;
+                        r_dcache_fsm             = DCACHE_INVAL_TLB_SCAN;
+                        break;
+                    }
+        
+                    if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_CONTAINS_PTD )
+                    {
+                        r_itlb.reset();
+                        r_dtlb.reset();
+                        r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;
+                    }
+ 
+                }
+                r_dcache_fsm            = DCACHE_IDLE;
+            }
+        }
+        else
+        {
+            if( r_cas_cache_state == CACHE_SLOT_STATE_EXCLUSIVE)
+            {
+               r_dcache.write_dir( r_cas_local_way.read(),
+                                  r_cas_local_set.read(),
+                                  CACHE_SLOT_STATE_MODIFIED );
+
+            }
+            r_dcache.write(way,
+                           set,
+                           word,
+                           r_dcache_vci_cas_new.read());
+            //std::cout << "CAS local" << std::endl;
+            if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_IN_TLB )
+            {
+                r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;
+                r_dcache_tlb_inval_line  = nline;
+                r_dcache_tlb_inval_set   = 0;
+                r_dcache_fsm_scan_save   = DCACHE_IDLE;
+                r_dcache_fsm             = DCACHE_INVAL_TLB_SCAN;
+                break;
+            }
+
+            if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_CONTAINS_PTD )
+            {
+                r_itlb.reset();
+                r_dtlb.reset();
+                r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;
+
+#if DEBUG_DCACHE
+                if ( m_debug_activated )
+                {
+                    std::cout << "  <PROC " << name()
+                        << " DCACHE_DIRTY_WAIT> Flush DTLB & ITLB" << std::endl;
+                }
+#endif
+            }
+            r_dcache_fsm            = DCACHE_IDLE;
+        }
+        break;
+    }
+    /////////////////////
+    case DCACHE_CC_CHECK:   // This state is the entry point for the sub-FSM
+                            // handling coherence requests for DCACHE.
+                            // If there is a matching pending miss on the modified cache
+                            // line this is signaled in the r_dcache_miss inval flip-flop.
+                            // If the updated (or invalidated) cache line has copies in TLBs
+                            // these TLB copies are invalidated.
+                            // The return state is defined in r_dcache_fsm_cc_save
+    {
+        paddr_t  paddr = r_cc_receive_dcache_nline.read() * m_dcache_words * 4;
+        paddr_t  mask = ~((m_dcache_words<<2)-1);
+
+//#if DEBUG_DCACHE
+//if ( m_debug_activated )
+//{
+//    std::cout << "  <PROC " << name() << std::hex
+//              << " DCACHE_CC_CHECK> paddr = " << paddr
+//              << " r_dcache_vci_paddr = " << r_dcache_vci_paddr.read()
+//              << " mask = " << mask 
+//              << " (r_dcache_fsm_cc_save == DCACHE_MISS_WAIT) = " 
+//              << (r_dcache_fsm_cc_save == DCACHE_MISS_WAIT)
+//              << " (r_dcache_fsm_cc_save == DCACHE_MISS_DIR_UPDT) = " 
+//              << (r_dcache_fsm_cc_save == DCACHE_MISS_DIR_UPDT)
+//              << " ((r_dcache_vci_paddr.read() & mask) == (paddr & mask)) = " 
+//              << ((r_dcache_vci_paddr.read() & mask) == (paddr & mask))
+//              << std::dec <<std::endl;
+//}
+//#endif
+        // CLACK handler
+        // We switch the directory slot to EMPTY state and reset
+        // r_dcache_miss_clack if the cleanup ack is matching a pending miss.
+        if ( r_dcache_clack_req.read() )
+        {
+            if ( m_dreq.valid ) m_cost_data_miss_frz++;
+
+#ifdef INSTRUMENTATION
+m_cpt_dcache_dir_write++;
+#endif
+            r_dcache.write_dir( 0,
+                                r_dcache_clack_way.read(),
+                                r_dcache_clack_set.read(),
+                                CACHE_SLOT_STATE_INVALID);
+
+            if ( (r_dcache_miss_set.read() == r_dcache_clack_set.read()) and
+                 (r_dcache_miss_way.read() == r_dcache_clack_way.read()) )
+            {
+                  r_dcache_miss_clack = false;
+            }
+
+            r_dcache_clack_req = false;
+
+            // return to cc_save state
+            r_dcache_fsm = r_dcache_fsm_cc_save.read() ;
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_CC_CHECK> CC_TYPE_CLACK Switch slot to EMPTY state"
+              << " set = " << r_dcache_clack_set.read()
+              << " / way = " << r_dcache_clack_way.read() << std::endl;
+}
+#endif
+            break;
+        }
+
+        
+        // Match between MISS address and CC address
+        // note: In the same cycle we can handle a CLACK and a MISS match
+        // because the CLACK access the directory but the MISS match dont.
+        if (r_cc_receive_dcache_req.read() and  
+          ((r_dcache_fsm_cc_save == DCACHE_MISS_SELECT  )  or
+           (r_dcache_fsm_cc_save == DCACHE_MISS_WAIT    )  or
+           (r_dcache_fsm_cc_save == DCACHE_MISS_DIR_UPDT)) and
+          ((r_dcache_vci_paddr.read() & mask) == (paddr & mask)))
+        {
+
+            if(r_cc_receive_dcache_type.read() == CC_TYPE_BRDCAST and r_dcache_read_for_modify.read() and (r_dcache_miss_type.read() == PROC_MISS))
+            {
+                r_cc_receive_dcache_req = false;
+                r_dcache_fsm       = r_dcache_fsm_cc_save.read();
+            }
+            else 
+            {
+                r_dcache_miss_inval = false;
+                r_dcache_miss_updt  = true;
+                r_dcache_fsm        = r_dcache_fsm_cc_save.read();
+            }
+            // signaling matching
+  
+        //    if(r_cc_receive_dcache_type.read() == CC_TYPE_UPDT)
+        //    {
+        //        if(r_dcache_read_for_modify.read() and (r_dcache_miss_type == PROC_MISS))
+        //        {
+        //            r_dcache_miss_inval = false;
+        //            r_dcache_miss_updt = true;
+        //            r_dcache_fsm       = r_dcache_fsm_cc_save.read();
+        //        }
+        //        else
+        //        {
+        //           // r_dcache_cc_send_multi_ack_miss = true;
+        //            r_dcache_cc_send_multi_ack_miss = false;
+        //            r_dcache_miss_inval             = false;
+        //            r_dcache_cc_state               = CACHE_SLOT_STATE_INVALID;
+        //            r_dcache_fsm                    = DCACHE_CC_UPDT;
+        //        }
+        //    }
+        //    else
+        //    {
+        //        if(r_cc_receive_dcache_srcid.read() == m_srcid and r_cc_receive_brdcast.read() and (r_dcache_miss_type == PROC_MISS))
+        //        {
+        //            assert(r_dcache_read_for_modify.read() && "miss inval for a miss getm in type of brdcast, this is impossible!!");
+        //            r_dcache_miss_inval      = false;
+        //            r_cc_receive_dcache_req = false;
+        //        }
+        //        else if(not r_cc_receive_brdcast.read() and r_dcache_read_for_modify.read() and (r_dcache_miss_type == PROC_MISS))
+        //        {
+        //            r_dcache_miss_inval = false;
+        //            r_dcache_miss_updt  = true;
+        //        }
+        //        else 
+        //        {
+        //            r_cc_receive_dcache_req = false;
+        //            r_dcache_miss_inval = true;
+        //        }
+        //        r_dcache_fsm            = r_dcache_fsm_cc_save.read();
+        //    }
+
+#if DEBU//G_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_CC_CHECK> Coherence request matching a pending miss:"
+              << " PADDR = " << std::hex << paddr << std::endl;
+}
+#endif
+            break;
+        }
+
+
+        assert ( not r_dcache_cc_send_req.read() and "CC_SEND must be available in DCACHE_CC_CHECK" );
+
+        // CC request handler
+       
+        int    state = 0;
+        size_t way   = 0;
+        size_t set   = 0;
+        size_t word  = 0;
+
+#ifdef INSTRUMENTATION
+m_cpt_dcache_dir_read++;
+#endif
+        r_dcache.read_dir( paddr,
+                           &state,
+                           &way,
+                           &set,
+                           &word ); // unused
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_CC_CHECK> Coherence request received:"
+              << " PADDR = " << std::hex << paddr
+              << " / TYPE = " << std::dec << r_cc_receive_dcache_type.read()
+              << " / HIT = " << state << std::endl;
+}
+#endif
+        r_dcache_cc_state = state;
+        r_dcache_cc_way = way;
+        r_dcache_cc_set = set;
+        r_dcache_cc_inval_addr = (paddr &~0x3F);
+
+        if (state == CACHE_SLOT_STATE_EXCLUSIVE or state == CACHE_SLOT_STATE_MODIFIED)
+        {
+            if (r_cc_receive_dcache_type.read() == CC_TYPE_UPDT)  // hit update
+            {
+                r_dcache_fsm                    = DCACHE_CC_UPDT;
+                r_dcache_cc_send_multi_ack_miss = false;
+            }
+            else if ( r_cc_receive_dcache_type.read() == CC_TYPE_INVAL or r_cc_receive_dcache_type.read() == CC_TYPE_BRDCAST) // hit inval
+            {
+                r_dcache_fsm           = DCACHE_CC_INVAL;
+            }
+        }
+        else if (state == CACHE_SLOT_STATE_SHARED)
+        {
+            assert( r_cc_receive_dcache_type.read() != CC_TYPE_UPDT && "must not be happened!!");
+            r_dcache_fsm           = DCACHE_CC_INVAL;
+        }
+        else
+        {
+            if (r_cc_receive_dcache_type.read() == CC_TYPE_UPDT)  // miss update
+            {
+                r_dcache_fsm                    = DCACHE_CC_UPDT;
+                r_dcache_cc_send_multi_ack_miss = true;
+            }
+            else
+            { 
+                r_cc_receive_dcache_req = false;
+                r_dcache_fsm            = r_dcache_fsm_cc_save.read();
+            }
+        }
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_CC_CHECK> Coherence request received:"
+              << " PADDR = " << std::hex << paddr
+              << " / TYPE = " << std::dec << r_cc_receive_dcache_type.read()
+              << " / HIT = " << state << std::endl;
+}
+#endif
+        break;
+    }
+
+    /////////////////////
+    case DCACHE_CC_INVAL: // hit inval: switch slot to ZOMBI state and send a
+                          // CLEANUP after possible invalidation of copies in
+                          // TLBs
+    {
+        size_t way    = r_dcache_cc_way.read();
+        size_t set    = r_dcache_cc_set.read();
+        int    cache_state = r_dcache_cc_state.read();
+
+        if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_IN_TLB )
+        {
+            r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;//need to remember it was dirty for cleanup
+            r_dcache_dirty_save = true;
+            r_dcache_tlb_inval_line  = r_cc_receive_dcache_nline.read();
+            r_dcache_tlb_inval_set   = 0;
+            r_dcache_fsm_scan_save   = r_dcache_fsm.read();
+            r_dcache_fsm             = DCACHE_INVAL_TLB_SCAN;
+            break;
+        }
+        else if ( r_dcache_content_state[way*m_dcache_sets+set] == LINE_CACHE_CONTAINS_PTD )
+        {
+                r_itlb.reset();
+                r_dtlb.reset();
+                r_dcache_content_state[way*m_dcache_sets+set] = LINE_EMPTY;
+                r_dcache_dirty_save = true;
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_CC_INVAL> Flush DTLB & ITLB" << std::endl;
+}
+#endif
+        }
+        // If the line is coherente we send a classic CLEANUP
+        // If the type of inval request from Memcache is configuration
+        // (software), we send a classic CLEANUP
+        if (cache_state == CACHE_SLOT_STATE_SHARED or cache_state == CACHE_SLOT_STATE_EXCLUSIVE or r_cc_receive_dcache_inval_is_config.read()) 
+        {
+            r_cc_receive_dcache_req     = false;
+            r_dcache_fsm                = r_dcache_fsm_cc_save.read();
+            r_dcache.write_dir( way,
+                                set,
+                                CACHE_SLOT_STATE_ZOMBI );
+        }
+        else if (cache_state == CACHE_SLOT_STATE_MODIFIED and not r_cc_receive_dcache_inval_is_config.read())
+        {
+            r_dcache_cc_inval_data_cpt  = 0;
+            r_dcache_cc_line_dirty      = true; 
+            r_dcache_fsm                = DCACHE_CC_SEND_DATA;
+        }
+
+        if ( cache_state == CACHE_SLOT_STATE_SHARED )
+        {
+            r_dcache_cc_line_no_shared = false;
+        }
+        else
+        {
+            r_dcache_cc_line_no_shared = true;
+        }
+
+        assert (not r_dcache_cc_send_req.read() &&
+                "ERROR in DCACHE_CC_INVAL: the r_dcache_cc_send_req "
+                "must not be set");
+        // request multicast acknowledgement
+        r_dcache_cc_send_req = true;
+        r_dcache_cc_send_way = way;
+        r_dcache_cc_send_nline = r_cc_receive_dcache_nline.read();
+        r_dcache_cc_send_inval_is_config = r_cc_receive_dcache_inval_is_config.read();
+        r_dcache_cc_send_type = CC_TYPE_CLEANUP;
+        // MODIFIER POUR DIRTY BIT //
+        break;
+    }
+    
+    /////////////////////
+    case DCACHE_CC_SEND_DATA:
+    {
+
+        uint32_t rdata;
+        size_t   way;
+        size_t   set;
+        size_t   word;
+        r_dcache.read_neutral(r_dcache_cc_inval_addr.read(),
+                              &rdata,
+                              &way,
+                              &set,
+                              &word);
+        if(r_cc_send_data_fifo.wok())
+        {
+            r_dcache_cc_inval_addr = r_dcache_cc_inval_addr.read() + 4;
+
+            cleanup_data_updt_fifo_dcache_put   = true;
+            cleanup_data_updt_fifo_dcache_data  = rdata;
+
+            r_dcache_cc_inval_data_cpt = r_dcache_cc_inval_data_cpt.read() + 1;
+            if(r_dcache_cc_inval_data_cpt.read() == (m_dcache_words - 1))
+            {
+                r_cc_receive_dcache_req = false;
+                r_dcache_fsm            = r_dcache_fsm_cc_save.read();
+                if (r_cc_receive_dcache_type.read() == CC_TYPE_INVAL)  // hit update
+                {
+                    r_dcache.write_dir( r_dcache_cc_way.read(),
+                                        r_dcache_cc_set.read(),
+                                        CACHE_SLOT_STATE_ZOMBI );
+                }
+                else
+                {
+                    r_dcache.write_dir( r_dcache_cc_way.read(),
+                                        r_dcache_cc_set.read(),
+                                        CACHE_SLOT_STATE_SHARED );
+                }
+            }
+        }
+        break;
+    }
+    ///////////////////
+    case DCACHE_CC_UPDT:        // hit update: write one word per cycle,
+                                // after possible invalidation of copies in TLBs
+    {
+        size_t word         = r_dcache_cc_word.read();
+        size_t way          = r_dcache_cc_way.read();
+        size_t set          = r_dcache_cc_set.read();
+        int    cache_state  = r_dcache_cc_state.read();
+
+#if DEBUG_DCACHE
+if ( m_debug_activated )
+{
+    std::cout << "  <PROC " << name()
+              << " DCACHE_CC_UPDT> " << std::dec
+              << " / WAY = " << way
+              << " / SET = " << set
+              << " / state = " << cache_state
+              << " change the state to SHARED" << std::endl;
+}
+#endif
+       //assert ((not r_dcache_cc_send_req.read()) && (cache_state != CACHE_SLOT_STATE_SHARED) &&
+       //        "ERROR in DCACHE_CC_INVAL: the r_dcache_cc_send_req "
+       //        "must not be set");
+
+
+        r_dcache_fsm            = r_dcache_fsm_cc_save.read();
+        if( cache_state == CACHE_SLOT_STATE_EXCLUSIVE )
+        {
+            r_dcache.write_dir( r_dcache_cc_way.read(),
+                                r_dcache_cc_set.read(),
+                                CACHE_SLOT_STATE_SHARED );
+            r_cc_receive_dcache_req = false;
+        }
+        else if(cache_state == CACHE_SLOT_STATE_MODIFIED)
+        {
+            r_dcache_cc_inval_data_cpt  = 0;
+            r_dcache_cc_line_dirty      = true; 
+            r_dcache_fsm                = DCACHE_CC_SEND_DATA;
+        }
+        else
+        {
+            r_cc_receive_dcache_req = false;
+        }
+
+#ifdef INSTRUMENTATION
+m_cpt_dcache_data_write++;
+#endif
+
+        // request multicast acknowledgement
+        r_dcache_cc_send_req          = true;
+        r_dcache_cc_send_nline        = r_cc_receive_dcache_nline.read();
+        r_dcache_cc_send_updt_tab_idx = r_cc_receive_dcache_updt_tab_idx.read();
+        r_dcache_cc_send_type         = CC_TYPE_MULTI_ACK;
+
+        break;
+    }
+    ///////////////////////////
+    case DCACHE_INVAL_TLB_SCAN:     	// Scan sequencially all sets for both ITLB & DTLB
+                                        // It makes assumption: m_itlb_sets == m_dtlb_sets
+                                        // All ways are handled in parallel.
+                                        // We enter this state when a DCACHE line is modified,
+                                        // and there is a copy in itlb or dtlb.
+                                        // It can be caused by:
+                                        // - a coherence inval or updt transaction,
+                                        // - a line inval caused by a cache miss
+                                        // - a processor XTN inval request,
+                                        // - a WRITE hit,
+                                        // - a Dirty bit update
+                                        // Input arguments are:
+                                        // - r_dcache_tlb_inval_line
+                                        // - r_dcache_tlb_inval_set
+                                        // - r_dcache_fsm_scan_save
+    {
+        paddr_t	line = r_dcache_tlb_inval_line.read();
+        size_t  set  = r_dcache_tlb_inval_set.read();
+        size_t  way;
+        bool    ok;
+
+        for ( way = 0 ; way < m_itlb_ways ; way++ )
+        {
+            ok = r_itlb.inval( line, way, set );
+
+#if DEBUG_DCACHE
+if ( m_debug_activated and ok )
+{
+    std::cout << "  <PROC " << name()
+              << ".DCACHE_INVAL_TLB_SCAN> Invalidate ITLB entry:" << std::hex
+              << " line = " << line << std::dec
+              << " / set = " << set
+              << " / way = " << way << std::endl;
+}
+#endif
+        }
+
+        for ( way = 0 ; way < m_dtlb_ways ; way++ )
+        {
+            ok = r_dtlb.inval( line, way, set );
+
+#if DEBUG_DCACHE
+if ( m_debug_activated and ok )
+std::cout << "  <PROC " << name() << " DCACHE_INVAL_TLB_SCAN>"
+          << " Invalidate DTLB entry" << std::hex
+          << " / line = " << line << std::dec
+          << " / set = " << set
+          << " / way = " << way << std::endl;
+#endif
+        }
+
+        // return to the calling state when TLB inval completed
+        if ( r_dcache_tlb_inval_set.read() == (m_dtlb_sets-1) )
+        {
+            r_dcache_fsm = r_dcache_fsm_scan_save.read();
+        }
+        r_dcache_tlb_inval_set = r_dcache_tlb_inval_set.read() + 1;
+        break;
+    }
+    } // end switch r_dcache_fsm
+
+//if(r_dcache_miss_updt.read())
+//std::cout << "  <PROC " << name() 
+//          << " miss updt " << r_dcache_miss_updt.read() << std::endl;
+
+//std::cout << "  <PROC " << name() 
+//          << " get cache state " << r_dcache.get_cache_state(2,0) << std::endl;
+
+    ///////////////// llsc update ///////////////////////////////////////////////////////
+    if (r_dcache_llsc_valid.read()) r_dcache_llsc_count = r_dcache_llsc_count.read() - 1;
+    if (r_dcache_llsc_count.read() == 1) r_dcache_llsc_valid = false;
+
+    //////////////// test processor frozen //////////////////////////////////////////////
+    // The simulation exit if the number of consecutive frozen cycles
+    // is larger than the m_max_frozen_cycles (constructor parameter)
+    if ( (m_ireq.valid and not m_irsp.valid) or (m_dreq.valid and not m_drsp.valid) )
+    {
+        m_cpt_frz_cycles++; 		// used for instrumentation
+        m_cpt_stop_simulation++;	// used for debug
+        if ( m_cpt_stop_simulation > m_max_frozen_cycles )
+        {
+            std::cout << std::dec << "ERROR in CC_VCACHE_WRAPPER " << name() << std::endl
+                      << " stop at cycle " << m_cpt_total_cycles << std::endl
+                      << " frozen since cycle " << m_cpt_total_cycles - m_max_frozen_cycles
+                      << std::endl;
+                      r_iss.dump();
+            exit(1);
+        }
+    }
+    else
+    {
+        m_cpt_stop_simulation = 0;
+    }
+
+    /////////// execute one iss cycle /////////////////////////////////
+    {
+    uint32_t it = 0;
+    for (size_t i=0; i<(size_t)iss_t::n_irq; i++) if(p_irq[i].read()) it |= (1<<i);
+    r_iss.executeNCycles(1, m_irsp, m_drsp, it);
+    }
+
+    ////////////////////////////////////////////////////////////////////////////
+    // The VCI_CMD FSM controls the following ressources:
+    // - r_vci_cmd_fsm
+    // - r_vci_cmd_min
+    // - r_vci_cmd_max
+    // - r_vci_cmd_cpt
+    // - r_vci_cmd_imiss_prio
+    // - wbuf (reset)
+    // - r_icache_miss_req (reset)
+    // - r_icache_unc_req (reset)
+    // - r_dcache_vci_miss_req (reset)
+    // - r_dcache_vci_unc_req (reset)
+    // - r_dcache_vci_ll_req (reset)
+    // - r_dcache_vci_sc_req (reset in case of local sc fail)
+    // - r_dcache_vci_cas_req (reset)
+    //
+    // This FSM handles requests from both the DCACHE FSM & the ICACHE FSM.
+    // There are 8 request types, with the following priorities :
+    // 1 - Data Read Miss         : r_dcache_vci_miss_req and miss in the write buffer
+    // 2 - Data Read Uncachable   : r_dcache_vci_unc_req
+    // 3 - Instruction Miss       : r_icache_miss_req and miss in the write buffer
+    // 4 - Instruction Uncachable : r_icache_unc_req
+    // 5 - Data Write             : r_wbuf.rok()
+    // 6 - Data Linked Load       : r_dcache_vci_ll_req
+    // 7 - Data Store Conditionnal: r_dcache_vci_sc_req
+    // 8 - Compare And Swap       : r_dcache_vci_cas_req
+    //
+    // As we want to support several simultaneous VCI transactions, the VCI_CMD_FSM
+    // and the VCI_RSP_FSM are fully desynchronized.
+    //
+    // VCI formats:
+    // According to the VCI advanced specification, all read requests packets
+    // (data Uncached, Miss data, instruction Uncached, Miss instruction)
+    // are one word packets.
+    // For write burst packets, all words are in the same cache line,
+    // and addresses must be contiguous (the BE field is 0 in case of "holes").
+    // The sc command packet implements actually a compare-and-swap mechanism
+    // and the packet contains two flits.
+    ////////////////////////////////////////////////////////////////////////////////////
+
+
+    switch ( r_vci_cmd_fsm.read() )
+    {
+        //////////////
+        case CMD_IDLE:
+        {
+            // DCACHE read requests (r_dcache_vci_miss_req or r_dcache_vci_ll_req), and
+            // ICACHE read requests (r_icache_miss_req) require both a write_buffer access
+            // to check a possible pending write on the same cache line.
+            // As there is only one possible access per cycle to write buffer, we implement
+            // a round-robin priority between DCACHE and ICACHE for this access,
+            // using the r_vci_cmd_imiss_prio flip-flop.
+
+
+            // 1 - Data unc write
+            if ( r_dcache_vci_unc_req.read() and r_dcache_vci_unc_write.read())
+            {
+                r_vci_cmd_fsm        = CMD_DATA_UNC_WRITE;
+                r_dcache_vci_unc_req = false;
+//                m_cpt_dunc_transaction++;
+            }
+            // 2 data read miss
+            else if ( r_dcache_vci_miss_req.read() )
+            {
+                r_vci_cmd_fsm         = CMD_DATA_MISS;
+                r_dcache_vci_miss_req = false;
+                r_vci_cmd_imiss_prio  = true;
+                m_cpt_dmiss_transaction++;
+            }
+            // 3 - Data Read Uncachable
+            else if ( r_dcache_vci_unc_req.read() and not r_dcache_vci_unc_write.read() )
+            {
+                r_vci_cmd_fsm        = CMD_DATA_UNC_READ;
+                r_dcache_vci_unc_req = false;
+                m_cpt_dunc_transaction++;
+            }
+            // 4 - Data Linked Load
+            else if ( r_dcache_vci_ll_req.read() )
+            {
+                r_vci_cmd_fsm         = CMD_DATA_LL;
+                r_dcache_vci_ll_req   = false;
+                r_vci_cmd_imiss_prio  = true;
+                m_cpt_ll_transaction++;
+            }
+            // 5 - Instruction Miss
+            else if ( r_icache_miss_req.read() )
+            {
+                r_vci_cmd_fsm        = CMD_INS_MISS;
+                r_icache_miss_req    = false;
+                r_vci_cmd_imiss_prio = false;
+                m_cpt_imiss_transaction++;
+            }
+            // 6 - Instruction Uncachable
+            else if ( r_icache_unc_req.read() )
+            {
+                r_vci_cmd_fsm       = CMD_INS_UNC;
+                r_icache_unc_req    = false;
+                //m_cpt_iunc_transaction++;
+            }
+            // 7 - Data Store Conditionnal
+            else if ( r_dcache_vci_sc_req.read() )
+            {
+                r_vci_cmd_fsm           = CMD_DATA_SC;
+                r_dcache_vci_sc_req     = false;
+                r_vci_cmd_imiss_prio    = true;
+                r_vci_cmd_cpt           = 0;
+                //m_cpt_sc_transaction++;
+            }
+            // 8 - Compare And Swap
+            else if ( r_dcache_vci_cas_req.read() )
+            {
+                r_vci_cmd_fsm           = CMD_DATA_CAS;
+                r_dcache_vci_cas_req    = false;
+                r_vci_cmd_imiss_prio    = true;
+                r_vci_cmd_cpt           = 0;
+                //m_cpt_cas_transaction++;
+            }
+
+#if DEBUG_CMD
+if ( m_debug_activated )
+{
+std::cout << "  <PROC " << name() << " CMD_IDLE>"
+          << " / dmiss_req = " << dcache_miss_req
+          << " / imiss_req = " << icache_miss_req
+          << std::endl;
+}
+#endif
+            break;
+        }
+        ////////////////////
+        case CMD_DATA_SC:
+        case CMD_DATA_CAS:
+        {
+            // The CAS and SC VCI commands contain two flits
+            if ( p_vci.cmdack.read() )
+            {
+               r_vci_cmd_cpt = r_vci_cmd_cpt + 1;
+               if (r_vci_cmd_cpt == 1) r_vci_cmd_fsm = CMD_IDLE ;
+            }
+            break;
+        }
+        //////////////////
+        case CMD_INS_MISS:
+        case CMD_INS_UNC:
+        case CMD_DATA_MISS:
+        case CMD_DATA_UNC_READ:
+        case CMD_DATA_UNC_WRITE:
+        case CMD_DATA_LL:
+        {
+            // all read VCI commands contain one single flit
+            if ( p_vci.cmdack.read() ) {
+                r_vci_cmd_fsm = CMD_IDLE;
+            }
+            break;
+        }
+
+    } // end  switch r_vci_cmd_fsm
+
+    //////////////////////////////////////////////////////////////////////////
+    // The VCI_RSP FSM controls the following ressources:
+    // - r_vci_rsp_fsm:
+    // - r_vci_rsp_fifo_icache (push)
+    // - r_vci_rsp_fifo_dcache (push)
+    // - r_vci_rsp_data_error (set)
+    // - r_vci_rsp_ins_error (set)
+    // - r_vci_rsp_cpt
+    // - r_dcache_vci_sc_req (reset when SC response recieved)
+    //
+    // As the VCI_RSP and VCI_CMD are fully desynchronized to support several
+    // simultaneous VCI transactions, this FSM uses the VCI RPKTID field
+    // to identify the transactions.
+    //
+    // VCI vormat:
+    // This component checks the response packet length and accepts only
+    // single word packets for write response packets.
+    //
+    // Error handling:
+    // This FSM analyzes the VCI error code and signals directly the Write Bus Error.
+    // In case of Read Data Error, the VCI_RSP FSM sets the r_vci_rsp_data_error
+    // flip_flop and the error is signaled by the DCACHE FSM.
+    // In case of Instruction Error, the VCI_RSP FSM sets the r_vci_rsp_ins_error
+    // flip_flop and the error is signaled by the ICACHE FSM.
+    // In case of Cleanup Error, the simulation stops with an error message...
+    //////////////////////////////////////////////////////////////////////////
+
+    switch ( r_vci_rsp_fsm.read() )
+    {
+    //////////////
+    case RSP_IDLE:
+    {
+        if ( p_vci.rspval.read() )
+        {
+            r_vci_rsp_cpt = 0;
+            if      ( (p_vci.rpktid.read() & 0x7) ==  TYPE_DATA_UNC  )
+            {
+                r_vci_rsp_fsm = RSP_DATA_UNC;
+            }
+            else if ( (p_vci.rpktid.read() & 0x7) ==  TYPE_READ_DATA_MISS )
+            {
+                r_vci_rsp_fsm = RSP_DATA_MISS;
+            }
+            else if ( (p_vci.rpktid.read() & 0x7) ==  TYPE_READ_INS_UNC   )
+            {
+                r_vci_rsp_fsm = RSP_INS_UNC;
+            }
+            else if ( (p_vci.rpktid.read() & 0x7) ==  TYPE_READ_INS_MISS  )
+            {
+                r_vci_rsp_fsm = RSP_INS_MISS;
+            }
+            else if ( (p_vci.rpktid.read() & 0x7) ==  TYPE_WRITE          )
+            {
+                r_vci_rsp_fsm = RSP_DATA_MISS;
+            }
+            else if ( (p_vci.rpktid.read() & 0x7) ==  TYPE_CAS            )
+            {
+                r_vci_rsp_fsm = RSP_DATA_UNC;
+            }
+            else if ( (p_vci.rpktid.read() & 0x7) ==  TYPE_LL             )
+            {
+                r_vci_rsp_fsm = RSP_DATA_LL;
+            }
+            else if ( (p_vci.rpktid.read() & 0x7) == TYPE_SC             )
+            {
+                r_vci_rsp_fsm = RSP_DATA_UNC;
+            }
+            else
+            {
+                assert(false and "Unexpected VCI response");
+            }
+        }
+        break;
+    }
+        //////////////////
+        case RSP_INS_MISS:
+        {
+            if ( p_vci.rspval.read() )
+            {
+                if ( (p_vci.rerror.read()&0x1) != 0 )  // error reported
+                {
+                    r_vci_rsp_ins_error = true;
+                    if ( p_vci.reop.read() ) r_vci_rsp_fsm = RSP_IDLE;
+                }
+                else                                        // no error reported
+                {
+                    if ( r_vci_rsp_fifo_icache.wok() )
+                    {
+                        if ( r_vci_rsp_cpt.read() >= m_icache_words )
+                        {
+                            std::cout << "ERROR in VCI_CC_VCACHE " << name()
+                                      << " VCI response packet too long "
+                                      << " for instruction miss" << std::endl;
+                            exit(0);
+                        }
+                        r_vci_rsp_cpt                 = r_vci_rsp_cpt.read() + 1;
+                        vci_rsp_fifo_icache_put       = true,
+                        vci_rsp_fifo_icache_data      = p_vci.rdata.read();
+                        if ( p_vci.reop.read() )
+                        {
+                            if ( r_vci_rsp_cpt.read() != (m_icache_words - 1) )
+                            {
+                                std::cout << "ERROR in VCI_CC_VCACHE " << name()
+                                          << " VCI response packet too short" 
+                                          << " for instruction miss" << std::endl;
+                                exit(0);
+                            }
+                            r_icache_read_state = p_vci.rpktid.read() & 0x8;
+                            r_vci_rsp_fsm    = RSP_IDLE;
+                        }
+                    }
+                }
+            }
+            break;
+        }
+        /////////////////
+        case RSP_INS_UNC:
+        {
+            if (p_vci.rspval.read() )
+            {
+                assert( p_vci.reop.read() and
+                "illegal VCI response packet for uncachable instruction");
+
+                if ( (p_vci.rerror.read()&0x1) != 0 )  // error reported
+                {
+                    r_vci_rsp_ins_error = true;
+                    r_vci_rsp_fsm = RSP_IDLE;
+                }
+                else                                         // no error reported
+                {
+                    if ( r_vci_rsp_fifo_icache.wok())
+                    {
+                        vci_rsp_fifo_icache_put       = true;
+                        vci_rsp_fifo_icache_data      = p_vci.rdata.read();
+                        r_vci_rsp_fsm = RSP_IDLE;
+                    }
+                }
+            }
+            break;
+        }
+        ///////////////////
+        case RSP_DATA_MISS:
+        {
+            if ( p_vci.rspval.read() )
+            {
+                if ( (p_vci.rerror.read()&0x1) != 0 )  // error reported
+                {
+                    r_vci_rsp_data_error = true;
+                    if ( p_vci.reop.read() ) r_vci_rsp_fsm = RSP_IDLE;
+                }
+                else                                        // no error reported
+                {
+
+
+                    if ( r_vci_rsp_fifo_dcache.wok() )
+                    {
+                        assert( (r_vci_rsp_cpt.read() < m_dcache_words) and
+                        "The VCI response packet for data miss is too long");
+
+                        r_vci_rsp_cpt                 = r_vci_rsp_cpt.read() + 1;
+                        vci_rsp_fifo_dcache_put       = true,
+                        vci_rsp_fifo_dcache_data      = p_vci.rdata.read();
+
+                        if ( p_vci.reop.read() )
+                        {
+                            r_dcache_rsp_state = ((p_vci.rpktid.read() & 0x8) == 0x8);  // EXCLUSIVE = 0x8
+                            if (r_vci_rsp_cpt.read() != m_dcache_words - 1) std::cout << "assert on proc " << name() << std::endl;
+                            assert( (r_vci_rsp_cpt.read() == m_dcache_words - 1) and
+                            "The VCI response packet for data miss is too short");
+
+                            r_vci_rsp_fsm     = RSP_IDLE;
+                        }
+                    }
+                }
+            }
+            break;
+        }
+        //////////////////
+        case RSP_DATA_UNC:
+        {
+            if (p_vci.rspval.read() )
+            {
+                assert( p_vci.reop.read() and
+                "illegal VCI response packet for uncachable read data");
+
+                if ( (p_vci.rerror.read()&0x1) != 0 )  // error reported
+                {
+                    r_vci_rsp_data_error = true;
+                    r_vci_rsp_fsm = RSP_IDLE;
+                }
+                else                                         // no error reported
+                {
+                    if ( r_vci_rsp_fifo_dcache.wok())
+                    {
+                        r_dcache_rsp_state            = ((p_vci.rpktid.read() & 0x8) == 0x8);
+                        vci_rsp_fifo_dcache_put       = true;
+                        vci_rsp_fifo_dcache_data      = p_vci.rdata.read();
+                        r_vci_rsp_fsm = RSP_IDLE;
+                    }
+                }
+            }
+            break;
+        }
+        /////////////////
+        case RSP_DATA_LL:
+        {
+            if ( p_vci.rspval.read() )
+            {
+                if ( (p_vci.rerror.read()&0x1) != 0 )  // error reported
+                {
+                    r_vci_rsp_data_error = true;
+                    r_vci_rsp_fsm = RSP_IDLE;
+                    break;
+                }
+                if (r_vci_rsp_cpt.read() == 0) //first flit
+                {
+                    if(r_vci_rsp_fifo_dcache.wok())
+                    {
+                        assert(!p_vci.reop.read() &&
+                            "illegal VCI response packet for LL");
+                        vci_rsp_fifo_dcache_put  = true;
+                        vci_rsp_fifo_dcache_data = p_vci.rdata.read();
+                        r_vci_rsp_cpt            = r_vci_rsp_cpt.read() + 1;
+                    }
+                    break;
+                }
+                else // last flit
+                {
+                    if(r_vci_rsp_fifo_dcache.wok())
+                    {
+                        assert(p_vci.reop.read() &&
+                            "illegal VCI response packet for LL");
+                        vci_rsp_fifo_dcache_put  = true;
+                        vci_rsp_fifo_dcache_data = p_vci.rdata.read();
+                        r_vci_rsp_fsm            = RSP_IDLE;
+                    }
+                    break;
+                }
+            }
+            break;
+        }
+    } // end switch r_vci_rsp_fsm
+
+    /////////////////////////////////////////////////////////////////////////////////////
+    // The CC_SEND FSM is in charge of sending cleanups and the multicast
+    // acknowledgements on the coherence network. It has two clients (DCACHE FSM
+    // and ICACHE FSM) that are served with a round-robin priority.
+    // The CC_SEND FSM resets the r_*cache_cc_send_req request flip-flops as
+    // soon as the request has been sent.
+    /////////////////////////////////////////////////////////////////////////////////////
+    switch ( r_cc_send_fsm.read() )
+    {
+        ///////////////////////////
+        case CC_SEND_IDLE:
+        {
+            ///////////////////////////////////////////////////////
+            // handling round robin between icache and dcache :  //
+            // we first check for the last client and listen for //
+            // a request of the other, then update the client    //
+            // r_cc_send_last_client : 0 dcache / 1 icache
+            ///////////////////////////////////////////////////////
+            bool update_last_client = r_cc_send_last_client.read();
+            if ( r_cc_send_last_client.read() == 0 ) // last client was dcache
+            {
+                if (r_icache_cc_send_req.read()) // request from icache
+                    update_last_client = 1; // update last client to icache
+            }
+            else // last client was icache
+            {
+                if (r_dcache_cc_send_req.read()) // request from dcache
+                    update_last_client = 0; // update last client to dcache
+            }
+
+            // if there is an actual request
+            if (r_dcache_cc_send_req.read() or r_icache_cc_send_req.read())
+            {
+                // the new client is dcache and has a cleanup request
+                if      ( (update_last_client == 0) and 
+                          (r_dcache_cc_send_type.read() == CC_TYPE_CLEANUP))
+                    r_cc_send_fsm = CC_SEND_CLEANUP_1;
+
+                // the new client is dcache and has a multi acknowledgement request
+                else if ( (update_last_client == 0) and 
+                          (r_dcache_cc_send_type.read() == CC_TYPE_MULTI_ACK))
+                    r_cc_send_fsm = CC_SEND_MULTI_ACK_HEADER;
+
+                // the new client is icache and has a cleanup request
+                else if ( (update_last_client == 1) and 
+                          (r_icache_cc_send_type.read() == CC_TYPE_CLEANUP))
+                    r_cc_send_fsm = CC_SEND_CLEANUP_1;
+
+                // the new client is icache and has a multi acknowledgement request
+                else if ( (update_last_client == 1) and
+                        (r_icache_cc_send_type.read() == CC_TYPE_MULTI_ACK))
+                    r_cc_send_fsm = CC_SEND_MULTI_ACK_HEADER;
+
+                r_cc_send_last_client = update_last_client; //this flag should be here !!!!
+            }
+            break;
+        }
+        ///////////////////////////
+        case CC_SEND_CLEANUP_1:
+        {
+            // wait for the first flit to be consumed
+            if (p_dspin_p2m.read.read())
+            {
+                r_cc_send_fsm = CC_SEND_CLEANUP_2;
+                r_dcache_cc_send_inval_is_config = false;
+            }
+            break;
+        }
+        ///////////////////////////
+        case CC_SEND_CLEANUP_2:
+        {
+            // wait for the second flit to be consumed
+            if (p_dspin_p2m.read.read())
+            {
+                //std::cout << "CLEANUP send on line " << r_dcache_cc_send_nline.read() << std::endl;
+                if(r_dcache_cc_line_dirty.read() and (r_cc_send_last_client.read() == 0))//dcache request with data
+                {
+                    r_cc_send_cpt_word = 0;
+                    r_cc_send_fsm = CC_SEND_DATA_UPDT;
+                }
+                else
+                {
+                    if (r_cc_send_last_client.read() == 0) // dcache active request
+                    {
+                        r_dcache_cc_send_req = false; // reset dcache request
+                    }
+                    else // icache active request
+                    {
+                        r_icache_cc_send_req = false; // reset icache request
+                    }
+                    // go back to idle state
+                    r_cc_send_fsm = CC_SEND_IDLE;
+                }
+            }
+            break;
+        }
+        ///////////////////////////
+        case CC_SEND_DATA_UPDT:
+        {
+            if (p_dspin_p2m.read.read())
+            {
+                if(r_cc_send_data_fifo.rok())
+                {
+                    cleanup_data_updt_fifo_dcache_get = true;
+                    r_cc_send_cpt_word = r_cc_send_cpt_word.read() + 1;
+                    if (r_cc_send_cpt_word.read() == m_dcache_words-1)
+                        {
+                            r_dcache_cc_send_req = false;
+                            r_dcache_cc_line_dirty = false;
+                            r_cc_send_fsm = CC_SEND_IDLE;
+                        }
+                }
+            }
+            break;
+        }
+        ///////////////////////////
+        case CC_SEND_MULTI_ACK_HEADER:
+        {
+            // wait for the flit to be consumed
+            if(p_dspin_p2m.read.read())
+            {
+                if(r_cc_send_last_client.read() == 0 and r_dcache_cc_line_dirty == true) // dcache active request
+                {
+                    r_cc_send_cpt_word = 0;
+                    r_cc_send_fsm = CC_SEND_DATA_UPDT;
+                }
+                else if (r_cc_send_last_client.read() == 0 and r_dcache_cc_line_dirty == false) // dcache active request
+                {
+                    r_dcache_cc_send_req = false; // reset dcache request
+                    r_cc_send_fsm = CC_SEND_IDLE;
+                }
+                else // icache active request
+                {
+                    r_icache_cc_send_req = false; // reset icache request
+                    r_cc_send_fsm = CC_SEND_IDLE;
+                }
+                // go back to idle state
+            }
+            break;
+        }
+
+
+
+    } // end switch CC_SEND FSM
+
+    ///////////////////////////////////////////////////////////////////////////////
+    //  CC_RECEIVE  FSM
+    // This FSM receive all coherence packets on a DSPIN40 port.
+    // There is 5 packet types:
+    // - CC_DATA_INVAL : DCACHE invalidate request
+    // - CC_DATA_UPDT  : DCACHE update request (multi-words)
+    // - CC_INST_INVAL : ICACHE invalidate request
+    // - CC_INST_UPDT  : ICACHE update request (multi-words)
+    // - CC_BROADCAST  : Broadcast invalidate request (both DCACHE & ICACHE)
+    //////////////////////////////////////////////////////////////////////////////
+    switch( r_cc_receive_fsm.read() )
+    {
+        /////////////////////
+        case CC_RECEIVE_IDLE:
+        {
+            // a coherence request has arrived
+            if (p_dspin_m2p.write.read())
+            {
+                // initialize dspin received data
+                uint64_t receive_data = p_dspin_m2p.data.read();
+                // initialize coherence packet type
+                uint64_t receive_type = DspinDhccpParam::dspin_get(receive_data,
+                                            DspinDhccpParam::M2P_TYPE);
+                // test for a broadcast
+                if (DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::M2P_BC))
+                {
+                    r_cc_receive_fsm = CC_RECEIVE_BRDCAST_HEADER;
+                }
+                // test for a multi updt
+                else if (receive_type == DspinDhccpParam::TYPE_MULTI_UPDT_DATA) 
+                {
+                    r_cc_receive_fsm = CC_RECEIVE_DATA_UPDT_HEADER;
+                }
+                else if (receive_type == DspinDhccpParam::TYPE_MULTI_UPDT_INST)
+                {
+                    r_cc_receive_fsm = CC_RECEIVE_INS_UPDT_HEADER;
+                }
+                // test for a multi inval
+                else if (receive_type == DspinDhccpParam::TYPE_MULTI_INVAL_DATA)
+                {
+                    r_cc_receive_fsm = CC_RECEIVE_DATA_INVAL_HEADER;
+                }
+                else
+                {
+                    r_cc_receive_fsm = CC_RECEIVE_INS_INVAL_HEADER;
+                }
+            }
+            break;
+        }
+        ///////////////////////////////
+        case CC_RECEIVE_BRDCAST_HEADER:
+        {
+            // no actual data in the HEADER, just skip to second flit
+            uint64_t receive_data = p_dspin_m2p.data.read();
+            if (not (r_cc_receive_icache_req.read()) and 
+                not (r_cc_receive_dcache_req.read()))
+            {
+                r_cc_receive_dcache_srcid = DspinDhccpParam::dspin_get(receive_data,
+                                            DspinDhccpParam::BROADCAST_SRCID);
+            }
+            r_cc_receive_fsm = CC_RECEIVE_BRDCAST_NLINE;
+            break;
+        }
+        //////////////////////////////
+        case CC_RECEIVE_BRDCAST_NLINE:
+        {
+            // initialize dspin received data
+            uint64_t receive_data = p_dspin_m2p.data.read();
+            // wait for both dcache and icache to take the request
+            // TODO maybe we need to wait for both only to leave the state, but
+            // not to actually post a request to an available cache => need a
+            // flip_flop to check that ?
+            if (not (r_cc_receive_icache_req.read()) and 
+                not (r_cc_receive_dcache_req.read()) and
+                (p_dspin_m2p.write.read()))
+            {
+                // request dcache to handle the BROADCAST
+                r_cc_receive_dcache_req = true;
+                r_cc_receive_dcache_nline  = DspinDhccpParam::dspin_get(receive_data,
+                                             DspinDhccpParam::BROADCAST_NLINE);
+                r_cc_receive_dcache_type = CC_TYPE_BRDCAST;
+                // request icache to handle the BROADCAST
+                r_cc_receive_icache_req = true;
+                r_cc_receive_icache_nline  = DspinDhccpParam::dspin_get(receive_data,
+                                             DspinDhccpParam::BROADCAST_NLINE);
+                r_cc_receive_icache_type = CC_TYPE_INVAL;
+                // get back to idle state
+                r_cc_receive_fsm = CC_RECEIVE_IDLE;
+                break;
+            }
+            // keep waiting for the caches to accept the request
+            break;
+        }
+        /////////////////////////////
+        case CC_RECEIVE_DATA_INVAL_HEADER:
+        {
+            // initialize dspin received data
+            uint64_t receive_data = p_dspin_m2p.data.read();
+            if ( not r_cc_receive_dcache_req.read() )
+            {
+                // sample updt tab index in the HEADER, then skip to second flit
+                r_cc_receive_fsm = CC_RECEIVE_DATA_INVAL_NLINE;
+                r_cc_receive_dcache_inval_is_config = DspinDhccpParam::dspin_get(receive_data,
+                                                      DspinDhccpParam::MULTI_INVAL_IS_CONFIG);
+            }
+            break;
+        }
+        /////////////////////////////
+        case CC_RECEIVE_INS_INVAL_HEADER:
+        {
+            // sample updt tab index in the HEADER, then skip to second flit
+            r_cc_receive_fsm = CC_RECEIVE_INS_INVAL_NLINE;
+            break;
+        }
+        ////////////////////////////
+        case CC_RECEIVE_DATA_INVAL_NLINE:
+        {
+            // sample nline in the second flit
+            uint64_t receive_data = p_dspin_m2p.data.read();
+            // for data INVAL, wait for dcache to take the request
+            if (p_dspin_m2p.write.read()           and 
+                not r_cc_receive_dcache_req.read() )
+            {
+                // request dcache to handle the INVAL
+                r_cc_receive_dcache_req = true;
+                r_cc_receive_dcache_nline = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_INVAL_NLINE);
+                r_cc_receive_dcache_type = CC_TYPE_INVAL;
+                // get back to idle state
+                r_cc_receive_fsm = CC_RECEIVE_IDLE;
+                break;
+            }
+            break;
+        }
+        //////////////////////////////
+        case CC_RECEIVE_INS_INVAL_NLINE:
+        {
+            // sample nline in the second flit
+            uint64_t receive_data = p_dspin_m2p.data.read();
+            // for ins INVAL, wait for icache to take the request
+            if (p_dspin_m2p.write.read()           and 
+                not r_cc_receive_icache_req.read() )
+            {
+                // request icache to handle the INVAL
+                r_cc_receive_icache_req = true;
+                r_cc_receive_icache_nline = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_INVAL_NLINE);
+                r_cc_receive_icache_type = CC_TYPE_INVAL;
+                // get back to idle state
+                r_cc_receive_fsm = CC_RECEIVE_IDLE;
+                break;
+            }
+            break;
+        }
+        ////////////////////////////
+        case CC_RECEIVE_DATA_UPDT_HEADER:
+        {
+            // sample updt tab index in the HEADER, than skip to second flit
+            uint64_t receive_data = p_dspin_m2p.data.read();
+            // for data INVAL, wait for dcache to take the request and fifo to
+            // be empty
+            if (not r_cc_receive_dcache_req.read())
+            {
+                r_cc_receive_dcache_updt_tab_idx  = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::CC_UPDT_IVT_INDEX);
+                r_cc_receive_fsm = CC_RECEIVE_DATA_UPDT_NLINE;
+                break;
+            }
+            break;
+        }
+        ////////////////////////////
+        case CC_RECEIVE_INS_UPDT_HEADER:
+        {
+            // sample updt tab index in the HEADER, than skip to second flit
+            uint64_t receive_data = p_dspin_m2p.data.read();
+            // for ins INVAL, wait for icache to take the request and fifo to be
+            // empty
+            if (not r_cc_receive_icache_req.read())
+            {
+                r_cc_receive_icache_updt_tab_idx  = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::CC_UPDT_IVT_INDEX);
+                r_cc_receive_fsm = CC_RECEIVE_INS_UPDT_NLINE;
+                break;
+            }
+            // keep waiting for the correct cache to accept the request
+            break;
+        }
+        ///////////////////////////
+        case CC_RECEIVE_DATA_UPDT_NLINE:
+        {
+            // sample nline and word index in the second flit
+            uint64_t receive_data = p_dspin_m2p.data.read();
+            // for data INVAL, wait for dcache to take the request and fifo to
+            // be empty
+            if ( p_dspin_m2p.write.read() )
+            {
+                r_cc_receive_dcache_req = true;
+                r_cc_receive_dcache_nline  = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_NLINE);
+                r_cc_receive_dcache_type = CC_TYPE_UPDT;
+                // get back to idle state
+                r_cc_receive_fsm = CC_RECEIVE_IDLE;
+                break;
+            }
+            break;
+        }
+        ////////////////////////////
+        case CC_RECEIVE_INS_UPDT_NLINE:
+        {
+            // sample nline and word index in the second flit
+            uint64_t receive_data = p_dspin_m2p.data.read();
+            // for ins INVAL, wait for icache to take the request and fifo to be
+            // empty
+            if ( p_dspin_m2p.write.read() )
+            {
+                r_cc_receive_icache_req = true;
+                r_cc_receive_icache_nline  = DspinDhccpParam::dspin_get(receive_data,DspinDhccpParam::MULTI_UPDT_NLINE);
+                r_cc_receive_icache_type = CC_TYPE_UPDT;
+                // get back to idle state
+                r_cc_receive_fsm = CC_RECEIVE_IDLE;
+                break;
+            }
+            break;
+        }
+
+    } // end switch CC_RECEIVE FSM
+
+    ///////////////// DSPIN CLACK interface ///////////////
+    
+    uint64_t clack_type = DspinDhccpParam::dspin_get(r_dspin_clack_flit.read(),
+                                                     DspinDhccpParam::CLACK_TYPE);
+
+    size_t clack_way  = DspinDhccpParam::dspin_get(r_dspin_clack_flit.read(),
+                                                   DspinDhccpParam::CLACK_WAY);
+
+    size_t clack_set  = DspinDhccpParam::dspin_get(r_dspin_clack_flit.read(),
+                                                   DspinDhccpParam::CLACK_SET);
+
+    bool dspin_clack_get      = false;
+    bool dcache_clack_request = (clack_type == DspinDhccpParam::TYPE_CLACK_DATA);
+    bool icache_clack_request = (clack_type == DspinDhccpParam::TYPE_CLACK_INST);
+
+    if (r_dspin_clack_req.read())
+    {
+        // CLACK DATA: Send request to DCACHE FSM
+        if (dcache_clack_request and not r_dcache_clack_req.read()){
+            r_dcache_clack_req = true;
+            r_dcache_clack_way = clack_way & ((1ULL<<(uint32_log2(m_dcache_ways)))-1);
+            r_dcache_clack_set = clack_set & ((1ULL<<(uint32_log2(m_dcache_sets)))-1);
+            dspin_clack_get    = true;
+        }
+
+        // CLACK INST: Send request to ICACHE FSM
+        else if (icache_clack_request and not r_icache_clack_req.read()){
+            r_icache_clack_req = true;
+            r_icache_clack_way = clack_way & ((1ULL<<(uint32_log2(m_dcache_ways)))-1);
+            r_icache_clack_set = clack_set & ((1ULL<<(uint32_log2(m_icache_sets)))-1);
+            dspin_clack_get    = true;
+        }
+    }
+    else
+    {
+        dspin_clack_get = true;
+    }
+
+    if (dspin_clack_get)
+    {
+        r_dspin_clack_req  = p_dspin_clack.write.read();
+        r_dspin_clack_flit = p_dspin_clack.data.read();
+    }
+
+    ///////////////// Response FIFOs update  //////////////////////
+    r_vci_rsp_fifo_icache.update(vci_rsp_fifo_icache_get,
+                                 vci_rsp_fifo_icache_put,
+                                 vci_rsp_fifo_icache_data);
+
+    r_vci_rsp_fifo_dcache.update(vci_rsp_fifo_dcache_get,
+                                 vci_rsp_fifo_dcache_put,
+                                 vci_rsp_fifo_dcache_data);
+    //BUG pktid
+//    r_vci_rsp_fifo_rpktid.update(vci_rsp_fifo_rpktid_get,
+//                                 vci_rsp_fifo_rpktid_put,
+//                                 vci_rsp_fifo_rpktid);
+//
+    r_cc_send_data_fifo.update(cleanup_data_updt_fifo_dcache_get,
+                               cleanup_data_updt_fifo_dcache_put,
+                               cleanup_data_updt_fifo_dcache_data);
+
+} // end transition()
+
+///////////////////////
+tmpl(void)::genMoore()
+///////////////////////
+{
+
+    // VCI initiator command on the direct network
+    // it depends on the CMD FSM state
+
+    bool is_sc_or_cas  = (r_vci_cmd_fsm.read() == CMD_DATA_CAS) or
+                         (r_vci_cmd_fsm.read() == CMD_DATA_SC );
+
+    p_vci.pktid  = 0;
+    p_vci.srcid  = m_srcid;
+    p_vci.cons   = is_sc_or_cas; 
+    p_vci.contig = not is_sc_or_cas; 
+    p_vci.wrap   = false;
+    p_vci.clen   = 0;
+    p_vci.cfixed = false;
+
+    if ( m_monitor_ok ) {
+        if ( p_vci.cmdack.read() == true and p_vci.cmdval == true) {
+            if (((p_vci.address.read()) >= m_monitor_base) and 
+                ((p_vci.address.read()) < m_monitor_base + m_monitor_length) ) {
+                std::cout << "CC_VCACHE Monitor " << name() << std::hex
+                          << " Access type = " << vci_cmd_type_str[p_vci.cmd.read()] 
+                          << " Pktid type = " << vci_pktid_type_str[p_vci.pktid.read()]
+                          << " : address = " << p_vci.address.read()
+                          << " / be = " << p_vci.be.read(); 
+                if ( p_vci.cmd.read() == vci_param::CMD_WRITE ) {
+                    std::cout << " / data = " << p_vci.wdata.read();
+                }
+                std::cout << std::dec << std::endl;
+            }
+        }
+    }
+
+    switch ( r_vci_cmd_fsm.read() ) {
+
+    case CMD_IDLE:
+        p_vci.cmdval  = false;
+        p_vci.address = 0;
+        p_vci.wdata   = 0;
+        p_vci.be      = 0;
+        p_vci.trdid   = 0;
+        p_vci.pktid   = 0;
+        p_vci.plen    = 0;
+        p_vci.cmd     = vci_param::CMD_NOP;
+        p_vci.eop     = false;
+        break;
+
+    case CMD_INS_MISS:
+        p_vci.cmdval  = true;
+        p_vci.address = r_icache_vci_paddr.read() & m_icache_yzmask;
+        p_vci.wdata   = 0;
+        p_vci.be      = 0xF;
+        p_vci.trdid   = 0;
+        p_vci.pktid   = TYPE_READ_INS_MISS;
+        p_vci.plen    = m_icache_words<<2;
+        p_vci.cmd     = vci_param::CMD_READ;
+        p_vci.eop     = true;
+        break;
+
+    case CMD_INS_UNC:
+        p_vci.cmdval  = true;
+        p_vci.address = r_icache_vci_paddr.read() & ~0x3;
+        p_vci.wdata   = 0;
+        p_vci.be      = 0xF;
+        p_vci.trdid   = 0;
+        p_vci.pktid   = TYPE_READ_INS_UNC;
+        p_vci.plen    = 4;
+        p_vci.cmd     = vci_param::CMD_READ;
+        p_vci.eop     = true;
+        break;
+
+    case CMD_DATA_MISS:
+        p_vci.cmdval  = true;
+        p_vci.address = r_dcache_vci_paddr.read() & m_dcache_yzmask;
+        p_vci.wdata   = 0;
+        p_vci.be      = 0xF;
+        p_vci.trdid   = 0;
+        if(r_dcache_read_for_modify.read() and r_dcache_read_hit.read())
+            p_vci.pktid   = TYPE_WRITE + 0x8;
+        else if(r_dcache_read_for_modify.read() and not r_dcache_read_hit.read())
+            p_vci.pktid   = TYPE_WRITE;
+        else
+            p_vci.pktid   = TYPE_READ_DATA_MISS;
+        p_vci.plen    = m_dcache_words << 2;
+        p_vci.cmd     = vci_param::CMD_READ;
+        p_vci.eop     = true;
+        break;
+
+    case CMD_DATA_UNC_READ:
+        p_vci.cmdval  = true;
+        p_vci.address = r_dcache_vci_paddr.read() & ~0x3;
+        p_vci.wdata   = 0;
+        p_vci.be      = r_dcache_vci_unc_be.read();
+        p_vci.trdid   = 0;
+        p_vci.pktid   = TYPE_DATA_UNC;
+        p_vci.plen    = 4;
+        p_vci.cmd     = vci_param::CMD_READ;
+        p_vci.eop     = true;
+        break;
+
+    case CMD_DATA_UNC_WRITE:
+        p_vci.cmdval  = true;
+        p_vci.address = r_dcache_vci_paddr.read() & ~0x3;
+        p_vci.wdata   = r_dcache_vci_wdata.read();
+        p_vci.be      = r_dcache_vci_unc_be.read();
+        p_vci.trdid   = 0;
+        p_vci.pktid   = TYPE_DATA_UNC;
+        p_vci.plen    = 4;
+        p_vci.cmd     = vci_param::CMD_WRITE;
+        p_vci.eop     = true;
+        break;
+
+    case CMD_DATA_LL:
+        p_vci.cmdval  = true;
+        p_vci.address = r_dcache_vci_paddr.read() & ~0x3;
+        p_vci.wdata   = 0;
+        p_vci.be      = 0xF;
+        p_vci.trdid   = 0;
+        p_vci.pktid   = TYPE_LL;
+        p_vci.plen    = 8;
+        p_vci.cmd     = vci_param::CMD_LOCKED_READ;
+        p_vci.eop     = true;
+        break;
+
+    case CMD_DATA_SC:
+        p_vci.cmdval  = true;
+        p_vci.address = r_dcache_vci_paddr.read() & ~0x3;
+        if ( r_vci_cmd_cpt.read() == 0 ) p_vci.wdata = r_dcache_llsc_key.read();
+        else                             p_vci.wdata = r_dcache_vci_sc_data.read();
+        p_vci.be      = 0xF;
+        p_vci.trdid   = 0;
+        p_vci.pktid   = TYPE_SC;
+        p_vci.plen    = 8;
+        p_vci.cmd     = vci_param::CMD_NOP;
+        p_vci.eop     = (r_vci_cmd_cpt.read() == 1);
+        break;
+
+    case CMD_DATA_CAS:
+        p_vci.cmdval  = true;
+        p_vci.address = r_dcache_vci_paddr.read() & ~0x3;
+        if ( r_vci_cmd_cpt.read() == 0 ) p_vci.wdata = r_dcache_vci_cas_old.read();
+        else                             p_vci.wdata = r_dcache_vci_cas_new.read();
+        p_vci.be      = 0xF;
+        p_vci.trdid   = 0;
+        p_vci.pktid   = TYPE_CAS;
+        p_vci.plen    = 8;
+        p_vci.cmd     = vci_param::CMD_NOP;
+        p_vci.eop     = (r_vci_cmd_cpt.read() == 1);
+        break;
+    } // end switch r_vci_cmd_fsm
+
+    // VCI initiator response on the direct network
+    // it depends on the VCI_RSP FSM
+
+    switch (r_vci_rsp_fsm.read() )
+    {
+        case RSP_DATA_WRITE : p_vci.rspack = true; break;
+        case RSP_INS_MISS   : p_vci.rspack = r_vci_rsp_fifo_icache.wok(); break;
+        case RSP_INS_UNC    : p_vci.rspack = r_vci_rsp_fifo_icache.wok(); break;
+        case RSP_DATA_MISS  : p_vci.rspack = r_vci_rsp_fifo_dcache.wok(); break;
+        case RSP_DATA_UNC   : p_vci.rspack = r_vci_rsp_fifo_dcache.wok(); break;
+        case RSP_DATA_LL    : p_vci.rspack = r_vci_rsp_fifo_dcache.wok(); break;
+        case RSP_IDLE       : p_vci.rspack = false; break;
+    } // end switch r_vci_rsp_fsm
+
+    
+    // Send coherence packets on DSPIN P2M 
+    // it depends on the CC_SEND FSM 
+
+    uint64_t dspin_send_data = 0;
+    switch ( r_cc_send_fsm.read() )
+    {
+        //////////////////
+        case CC_SEND_IDLE:
+        {
+            p_dspin_p2m.write = false;
+            break;
+        }
+        ///////////////////////
+        case CC_SEND_CLEANUP_1:
+        {
+            // initialize dspin send data
+//             DspinDhccpParam::dspin_set(dspin_send_data,
+//                                       0,
+//                                       DspinDhccpParam::P2M_EOP);
+            DspinDhccpParam::dspin_set(dspin_send_data,
+                                       m_cc_global_id,
+                                       DspinDhccpParam::CLEANUP_SRCID);
+            DspinDhccpParam::dspin_set(dspin_send_data,
+                                       0,
+                                       DspinDhccpParam::P2M_BC);
+
+            if(r_cc_send_last_client.read() == 0) // dcache active request
+            {
+                uint64_t dest = (uint64_t) r_dcache_cc_send_nline.read() 
+                                >> (m_nline_width - m_x_width - m_y_width) 
+                                << (DspinDhccpParam::GLOBALID_WIDTH - m_x_width - m_y_width);
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           dest,
+                                           DspinDhccpParam::CLEANUP_DEST);
+
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           (r_dcache_cc_send_nline.read() & 0x300000000ULL)>>32,
+                                           DspinDhccpParam::CLEANUP_NLINE_MSB);
+
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           r_dcache_cc_send_way.read(),
+                                           DspinDhccpParam::CLEANUP_WAY_INDEX);
+
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           DspinDhccpParam::TYPE_CLEANUP_DATA,
+                                           DspinDhccpParam::P2M_TYPE);
+
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           (r_dcache_cc_line_no_shared.read() and (r_cc_send_last_client.read() == 0) and not r_dcache_cc_send_inval_is_config.read()),
+                                           DspinDhccpParam::DATA_NO_SHARED);
+            }
+            else                                // icache active request
+            {
+                uint64_t dest = (uint64_t) r_icache_cc_send_nline.read() 
+                                >> (m_nline_width - m_x_width - m_y_width) 
+                                << (DspinDhccpParam::GLOBALID_WIDTH - m_x_width - m_y_width);
+
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           dest,
+                                           DspinDhccpParam::CLEANUP_DEST);
+
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           (r_icache_cc_send_nline.read() & 0x300000000ULL)>>32,
+                                           DspinDhccpParam::CLEANUP_NLINE_MSB);
+
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           r_icache_cc_send_way.read(),
+                                           DspinDhccpParam::CLEANUP_WAY_INDEX);
+
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           DspinDhccpParam::TYPE_CLEANUP_INST,
+                                           DspinDhccpParam::P2M_TYPE);
+
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           0,
+                                           DspinDhccpParam::DATA_NO_SHARED);
+
+
+            }
+            // send flit
+            p_dspin_p2m.data  = dspin_send_data;
+            p_dspin_p2m.write = true;
+            p_dspin_p2m.eop   = false;
+            break;
+        }
+        ///////////////////////
+        case CC_SEND_CLEANUP_2:
+        {
+            // initialize dspin send data
+            if(r_cc_send_last_client.read() == 0) // dcache active request
+            {
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           r_dcache_cc_send_nline.read() & 0xFFFFFFFFULL,
+                                           DspinDhccpParam::CLEANUP_NLINE_LSB);
+            }
+            else                                  // icache active request
+            {
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           r_icache_cc_send_nline.read() & 0xFFFFFFFFULL,
+                                           DspinDhccpParam::CLEANUP_NLINE_LSB);
+            }
+            // send flit
+            p_dspin_p2m.data  = dspin_send_data;
+            p_dspin_p2m.write = true;
+            p_dspin_p2m.eop   = ! (r_dcache_cc_line_dirty.read() and (r_cc_send_last_client.read() == 0));
+            break;
+        }
+        ///////////////////////
+        case CC_SEND_DATA_UPDT:
+        {
+            DspinDhccpParam::dspin_set(dspin_send_data,
+                                       r_cc_send_data_fifo.read(),
+                                       DspinDhccpParam::CLEANUP_DATA_UPDT);
+            
+            p_dspin_p2m.data = dspin_send_data;
+            //std::cout << "genmoore CLEANUP DATA UPDT : dspin_send_data = " << std::hex << dspin_send_data << std::dec << std::endl;
+            p_dspin_p2m.write = true;
+            p_dspin_p2m.eop = (r_cc_send_cpt_word.read() == m_dcache_words-1);
+            break;
+        }
+        ///////////////////////
+        case CC_SEND_MULTI_ACK_HEADER:
+        {
+            // initialize dspin send data
+            DspinDhccpParam::dspin_set(dspin_send_data,
+                                       0,
+                                       DspinDhccpParam::P2M_BC);
+            DspinDhccpParam::dspin_set(dspin_send_data,
+                                       DspinDhccpParam::TYPE_MULTI_ACK,
+                                       DspinDhccpParam::P2M_TYPE);
+
+            if(r_cc_send_last_client.read() == 0) // dcache active request
+            {
+                uint64_t dest = (uint64_t) r_dcache_cc_send_nline.read() 
+                                >> (m_nline_width - m_x_width - m_y_width) 
+                                << (DspinDhccpParam::GLOBALID_WIDTH - m_x_width - m_y_width);
+ 
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           dest,
+                                           DspinDhccpParam::MULTI_ACK_DEST);
+
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           r_dcache_cc_send_multi_ack_miss.read(),
+                                           DspinDhccpParam::MULTI_ACK_UPDT_MISS);
+
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           r_dcache_cc_send_updt_tab_idx.read(),
+                                           DspinDhccpParam::MULTI_ACK_UPDT_INDEX);
+            }
+            else                                    // icache active request
+            {
+                uint64_t dest = (uint64_t) r_icache_cc_send_nline.read() 
+                                >> (m_nline_width - m_x_width - m_y_width) 
+                                << (DspinDhccpParam::GLOBALID_WIDTH - m_x_width - m_y_width);
+ 
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           dest,
+                                           DspinDhccpParam::MULTI_ACK_DEST);
+
+                DspinDhccpParam::dspin_set(dspin_send_data,
+                                           r_icache_cc_send_updt_tab_idx.read(),
+                                           DspinDhccpParam::MULTI_ACK_UPDT_INDEX);
+            }
+            // send flit
+            p_dspin_p2m.data  = dspin_send_data;
+            p_dspin_p2m.write = true;
+            p_dspin_p2m.eop   = not r_dcache_cc_line_dirty.read();
+
+            break;
+        }
+
+    } // end switch CC_SEND FSM
+
+    // Receive coherence packets
+    // It depends on the CC_RECEIVE FSM 
+    switch( r_cc_receive_fsm.read() )
+    {
+        /////////////////////
+        case CC_RECEIVE_IDLE:
+        {
+            p_dspin_m2p.read = false;
+            break;
+        }
+        ///////////////////////////////
+        case CC_RECEIVE_BRDCAST_HEADER:
+        {
+            p_dspin_m2p.read = true;
+            break;
+        }
+        //////////////////////////////
+        case CC_RECEIVE_BRDCAST_NLINE:
+        {
+            // TODO maybe we need to wait for both only to leave the state, but
+            // not to actually post a request to an available cache => need a
+            // flip_flop to check that ?
+            if (not (r_cc_receive_icache_req.read()) and not (r_cc_receive_dcache_req.read()))
+                p_dspin_m2p.read = true;
+            else
+                p_dspin_m2p.read = false;
+            break;
+        }
+        /////////////////////////////
+        case CC_RECEIVE_DATA_INVAL_HEADER:
+        {
+            p_dspin_m2p.read = not r_cc_receive_dcache_req.read();
+            break;
+        }
+        ////////////////////////////
+        case CC_RECEIVE_INS_INVAL_HEADER:
+        {
+            p_dspin_m2p.read = true;
+            break;
+        }
+        ////////////////////////////
+        case CC_RECEIVE_DATA_INVAL_NLINE:
+        {
+            p_dspin_m2p.read = not r_cc_receive_dcache_req.read();
+            break;
+        }
+        case CC_RECEIVE_INS_INVAL_NLINE:
+        {
+            p_dspin_m2p.read = not r_cc_receive_icache_req.read();
+            break;
+        }
+        ///////////////////////////
+        case CC_RECEIVE_DATA_UPDT_HEADER:
+        {
+            if (not r_cc_receive_dcache_req.read())
+                p_dspin_m2p.read = true;
+            else
+                p_dspin_m2p.read = false;
+            break;
+        }
+        ////////////////////////////
+        case CC_RECEIVE_INS_UPDT_HEADER:
+        {
+            if ( not r_cc_receive_icache_req.read()) 
+                p_dspin_m2p.read = true;
+            else
+                p_dspin_m2p.read = false;
+            break;
+        }
+        ///////////////////////////
+        case CC_RECEIVE_DATA_UPDT_NLINE:
+        case CC_RECEIVE_INS_UPDT_NLINE:
+        {
+            p_dspin_m2p.read = true;
+            break;
+        }
+    } // end switch CC_RECEIVE FSM
+
+
+    int clack_type = DspinDhccpParam::dspin_get(r_dspin_clack_flit.read(),
+                                                DspinDhccpParam::CLACK_TYPE);
+
+    bool dspin_clack_get      = false;
+    bool dcache_clack_request = (clack_type == DspinDhccpParam::TYPE_CLACK_DATA);
+    bool icache_clack_request = (clack_type == DspinDhccpParam::TYPE_CLACK_INST);
+
+    if (r_dspin_clack_req.read())
+    {
+        // CLACK DATA: wait if pending request to DCACHE FSM
+        if (dcache_clack_request and not r_dcache_clack_req.read())
+        {
+            dspin_clack_get = true;
+        }
+
+        // CLACK INST: wait if pending request to ICACHE FSM
+        else if (icache_clack_request and not r_icache_clack_req.read())
+        {
+            dspin_clack_get = true;
+        }
+    }
+    else
+    {
+        dspin_clack_get = true;
+    }
+
+    p_dspin_clack.read = dspin_clack_get; 
+} // end genMoore
+
+tmpl(void)::start_monitor(paddr_t base, paddr_t length)
+// This version of monitor print both Read and Write request
+{
+    m_monitor_ok        = true;
+    m_monitor_base      = base;
+    m_monitor_length    = length;
+}
+
+tmpl(void)::stop_monitor()
+{
+    m_monitor_ok        = false;
+}
+
+}}
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Index: /branches/MESI/modules/vci_mem_cache/caba/metadata/vci_mem_cache.sd
===================================================================
--- /branches/MESI/modules/vci_mem_cache/caba/metadata/vci_mem_cache.sd	(revision 670)
+++ /branches/MESI/modules/vci_mem_cache/caba/metadata/vci_mem_cache.sd	(revision 670)
@@ -0,0 +1,77 @@
+
+# -*- python -*-
+
+__id__ = "$Id: vci_mem_cache.sd 295 2013-02-14 15:05:05Z cfuguet $"
+__version__ = "$Revision: 295 $"
+
+Module('caba:vci_mem_cache',
+        classname = 'soclib::caba::VciMemCache',
+
+        tmpl_parameters = [
+            parameter.Module('vci_param_int', default = 'caba:vci_param',
+                cell_size = parameter.Reference('memc_cell_size_int')
+            ),
+            parameter.Module('vci_param_ext', default = 'caba:vci_param',
+                cell_size = parameter.Reference('memc_cell_size_ext')
+            ),
+            parameter.Int('dspin_in_width'),
+            parameter.Int('dspin_out_width'),
+        ],
+
+        header_files = [
+            '../source/include/vci_mem_cache.h',
+            '../source/include/xram_transaction.h',
+            '../source/include/mem_cache_directory.h',
+            '../source/include/update_tab.h'
+        ],
+
+        interface_files = [
+            '../../include/soclib/mem_cache.h', 
+        ],
+
+        implementation_files = [
+            '../source/src/vci_mem_cache.cpp'
+        ],
+
+        uses = [
+            Uses('caba:base_module'),
+            Uses('common:loader'),
+            Uses('common:mapping_table'),
+            Uses('caba:generic_fifo'),
+            Uses('caba:generic_llsc_global_table'),
+            Uses('caba:dspin_dhccp_param')
+        ],
+
+        ports = [
+            Port('caba:clock_in'     , 'p_clk'      , auto = 'clock' ),
+            Port('caba:bit_in'       , 'p_resetn'   , auto = 'resetn'),
+            Port('caba:vci_target'   , 'p_vci_tgt'),
+            Port('caba:vci_initiator', 'p_vci_ixr'),
+            Port('caba:dspin_input',
+                'p_dspin_p2m',
+                dspin_data_size = parameter.Reference('dspin_in_width')
+            ),
+            Port('caba:dspin_output',
+                'p_dspin_m2p',
+                dspin_data_size = parameter.Reference('dspin_out_width')
+            ),
+            Port('caba:dspin_output',
+                'p_dspin_clack',
+                dspin_data_size = parameter.Reference('dspin_out_width')
+            ),
+        ],
+
+        instance_parameters = [
+            parameter.Module('mtp', 'common:mapping_table'),
+            parameter.Module('mtc', 'common:mapping_table'),
+            parameter.Module('mtx', 'common:mapping_table'),
+            parameter.IntTab('vci_ixr_index'),
+            parameter.IntTab('vci_ini_index'),
+            parameter.IntTab('vci_tgt_index'),
+            parameter.IntTab('vci_tgt_index_cleanup'),
+            parameter.Int   ('nways'),
+            parameter.Int   ('nsets'),
+            parameter.Int   ('nwords'),
+            parameter.Int   ('heap_size'),
+        ],
+)
Index: /branches/MESI/modules/vci_mem_cache/caba/source/include/mem_cache_directory.h
===================================================================
--- /branches/MESI/modules/vci_mem_cache/caba/source/include/mem_cache_directory.h	(revision 670)
+++ /branches/MESI/modules/vci_mem_cache/caba/source/include/mem_cache_directory.h	(revision 670)
@@ -0,0 +1,752 @@
+#ifndef SOCLIB_CABA_MEM_CACHE_DIRECTORY_H
+#define SOCLIB_CABA_MEM_CACHE_DIRECTORY_H 
+
+#include <inttypes.h>
+#include <systemc>
+#include <cassert>
+#include "arithmetics.h"
+
+//#define RANDOM_EVICTION
+
+namespace soclib { namespace caba {
+
+enum mem_dir_entry_state_e 
+{
+  ENTRY_INVALID,
+  ENTRY_EXCLUSIVE,
+  ENTRY_SHARED,
+  ENTRY_LOCKED
+};
+
+  using namespace sc_core;
+
+  ////////////////////////////////////////////////////////////////////////
+  //                    A LRU entry 
+  ////////////////////////////////////////////////////////////////////////
+  class LruEntry {
+
+    public:
+
+      bool recent;            
+
+      void init()
+      {
+        recent=false;
+      }
+
+  }; // end class LruEntry
+
+  ////////////////////////////////////////////////////////////////////////
+  //                    An Owner
+  ////////////////////////////////////////////////////////////////////////
+  class Owner{
+    
+    public:
+    // Fields
+      bool      inst;       // Is the owner an ICache ?
+      size_t    srcid;      // The SRCID of the owner
+
+    ////////////////////////
+    // Constructors
+    ////////////////////////
+      Owner(bool   i_inst,
+            size_t i_srcid)
+      {
+        inst    = i_inst;
+        srcid   = i_srcid;
+      }
+
+      Owner(const Owner &a)
+      {
+        inst    = a.inst;
+        srcid   = a.srcid;
+      }
+
+      Owner()
+      {
+        inst    = false;
+        srcid   = 0;
+      }
+      // end constructors
+
+  }; // end class Owner
+
+
+  ////////////////////////////////////////////////////////////////////////
+  //                    A directory entry                               
+  ////////////////////////////////////////////////////////////////////////
+  class DirectoryEntry {
+
+    typedef uint32_t tag_t;
+
+    public:
+
+    //bool    valid;                  // entry valid
+    //bool    cache_coherent;         // WB or WT policy
+    size_t  state;
+    bool    is_cnt;                 // directory entry is in counter mode
+    bool    dirty;                  // entry dirty
+    bool    lock;                   // entry locked
+    tag_t   tag;                    // tag of the entry
+    size_t  count;                  // number of copies
+    Owner   owner;                  // an owner of the line 
+    size_t  ptr;                    // pointer to the next owner
+
+    DirectoryEntry()
+    {
+      //valid         = false;
+      //cache_coherent= false;
+      state         = ENTRY_INVALID;
+      is_cnt        = false;
+      dirty         = false;
+      lock          = false;
+      tag           = 0;
+      count         = 0;
+      owner.inst    = 0;
+      owner.srcid   = 0;
+      ptr           = 0;
+    }
+
+    DirectoryEntry(const DirectoryEntry &source)
+    {
+      //valid         = source.valid;
+      //cache_coherent= source.cache_coherent;
+      state         = source.state;
+      is_cnt        = source.is_cnt;
+      dirty         = source.dirty;
+      lock          = source.lock;
+      tag           = source.tag;
+      count         = source.count;
+      owner         = source.owner;
+      ptr           = source.ptr;
+    }          
+
+    /////////////////////////////////////////////////////////////////////
+    // The init() function initializes the entry 
+    /////////////////////////////////////////////////////////////////////
+    void init()
+    {
+      //valid     = false;
+      //cache_coherent = false;
+      state     = ENTRY_INVALID;
+      is_cnt    = false;
+      dirty     = false;
+      lock      = false;
+      count     = 0;
+    }
+
+    /////////////////////////////////////////////////////////////////////
+    // The copy() function copies an existing source entry to a target 
+    /////////////////////////////////////////////////////////////////////
+    void copy(const DirectoryEntry &source)
+    {
+      //valid	    = source.valid;
+      //cache_coherent = source.cache_coherent;
+      state     = source.state;
+      is_cnt    = source.is_cnt;
+      dirty	    = source.dirty;
+      lock	    = source.lock;
+      tag	    = source.tag;
+      count     = source.count;
+      owner     = source.owner;
+      ptr       = source.ptr;
+    }
+
+    ////////////////////////////////////////////////////////////////////
+    // The print() function prints the entry 
+    ////////////////////////////////////////////////////////////////////
+    void print()
+    {
+      std::cout //<< "Valid = " << valid 
+                //<< " ; COHERENCE = " << cache_coherent
+                << " STATE = " << state
+                << " ; IS COUNT = " << is_cnt 
+                << " ; Dirty = " << dirty 
+                << " ; Lock = " << lock 
+                << " ; Tag = " << std::hex << tag << std::dec 
+                << " ; Count = " << count 
+                << " ; Owner = " << owner.srcid 
+                << " " << owner.inst 
+                << " ; Pointer = " << ptr << std::endl;
+    }
+
+  }; // end class DirectoryEntry
+
+  ////////////////////////////////////////////////////////////////////////
+  //                       The directory  
+  ////////////////////////////////////////////////////////////////////////
+  class CacheDirectory {
+
+    typedef sc_dt::sc_uint<40> addr_t;
+    typedef uint32_t data_t;
+    typedef uint32_t tag_t;
+
+    private:
+
+    // Directory constants
+    size_t					m_ways;
+    size_t					m_sets;
+    size_t					m_words;
+    size_t					m_width;
+    uint32_t                lfsr;
+
+    // the directory & lru tables
+    DirectoryEntry 				**m_dir_tab;
+    LruEntry	 				**m_lru_tab;
+
+    public:
+
+    ////////////////////////
+    // Constructor
+    ////////////////////////
+    CacheDirectory( size_t ways, size_t sets, size_t words, size_t address_width)	 
+    {
+      m_ways  = ways; 
+      m_sets  = sets;
+      m_words = words;
+      m_width = address_width;
+      lfsr = -1;
+
+      m_dir_tab = new DirectoryEntry*[sets];
+      for ( size_t i=0; i<sets; i++ ) {
+        m_dir_tab[i] = new DirectoryEntry[ways];
+        for ( size_t j=0 ; j<ways ; j++) m_dir_tab[i][j].init();
+      }
+      m_lru_tab = new LruEntry*[sets];
+      for ( size_t i=0; i<sets; i++ ) {
+        m_lru_tab[i] = new LruEntry[ways];
+        for ( size_t j=0 ; j<ways ; j++) m_lru_tab[i][j].init();
+      }
+    } // end constructor
+
+    /////////////////
+    // Destructor
+    /////////////////
+    ~CacheDirectory()
+    {
+      for(size_t i=0 ; i<m_sets ; i++){
+        delete [] m_dir_tab[i];
+        delete [] m_lru_tab[i];
+      }
+      delete [] m_dir_tab;
+      delete [] m_lru_tab;
+    } // end destructor
+
+    /////////////////////////////////////////////////////////////////////
+    // The read() function reads a directory entry. In case of hit, the
+    // LRU is updated.
+    // Arguments :
+    // - address : the address of the entry 
+    // - way : (return argument) the way of the entry in case of hit
+    // The function returns a copy of a (valid or invalid) entry  
+    /////////////////////////////////////////////////////////////////////
+    DirectoryEntry read(const addr_t &address, size_t &way)
+    {
+
+#define L2 soclib::common::uint32_log2
+      const size_t set = (size_t)(address >> (L2(m_words) + 2)) & (m_sets - 1);
+      const tag_t  tag = (tag_t)(address >> (L2(m_sets) + L2(m_words) + 2));
+#undef L2
+
+      bool hit       = false;
+      for ( size_t i=0 ; i<m_ways ; i++ ) {
+        bool equal = ( m_dir_tab[set][i].tag == tag );
+        bool valid = (m_dir_tab[set][i].state != ENTRY_INVALID);
+        hit = equal && valid;
+        if ( hit ) {			
+          way = i;
+          break;
+        } 
+      }
+      if ( hit ) {
+        m_lru_tab[set][way].recent = true;
+        return DirectoryEntry(m_dir_tab[set][way]);
+      } else {
+        return DirectoryEntry();
+      }
+    } // end read()
+
+    /////////////////////////////////////////////////////////////////////
+    // The inval function invalidate an entry defined by the set and
+    // way arguments. 
+    /////////////////////////////////////////////////////////////////////
+    void inval( const size_t &way, const size_t &set )
+    {
+        m_dir_tab[set][way].init();
+    }
+
+    /////////////////////////////////////////////////////////////////////
+    // The read_neutral() function reads a directory entry, without
+    // changing the LRU
+    // Arguments :
+    // - address : the address of the entry 
+    // The function returns a copy of a (valid or invalid) entry  
+    /////////////////////////////////////////////////////////////////////
+    DirectoryEntry read_neutral( const addr_t &address, 
+                                 size_t*      ret_way,
+                                 size_t*      ret_set )
+    {
+
+#define L2 soclib::common::uint32_log2
+        size_t set = (size_t)(address >> (L2(m_words) + 2)) & (m_sets - 1);
+        tag_t  tag = (tag_t)(address >> (L2(m_sets) + L2(m_words) + 2));
+#undef L2
+
+        for ( size_t way = 0 ; way < m_ways ; way++ ) 
+        {
+            bool equal = ( m_dir_tab[set][way].tag == tag );
+            bool valid = (m_dir_tab[set][way].state != ENTRY_INVALID);
+            if ( equal and valid )
+            {
+                *ret_set = set;
+                *ret_way = way; 
+                return DirectoryEntry(m_dir_tab[set][way]);
+            }
+        } 
+        return DirectoryEntry();
+    } // end read_neutral()
+
+    /////////////////////////////////////////////////////////////////////
+    // The write function writes a new entry, 
+    // and updates the LRU bits if necessary.
+    // Arguments :
+    // - set : the set of the entry
+    // - way : the way of the entry
+    // - entry : the entry value
+    /////////////////////////////////////////////////////////////////////
+    void write( const size_t         &set, 
+                const size_t         &way, 
+                const DirectoryEntry &entry)
+    {
+      assert( (set<m_sets) 
+          && "Cache Directory write : The set index is invalid");
+      assert( (way<m_ways) 
+          && "Cache Directory write : The way index is invalid");
+
+      // update Directory
+      m_dir_tab[set][way].copy(entry);
+
+      // update LRU bits
+      bool all_recent = true;
+      for ( size_t i=0 ; i<m_ways ; i++ ) 
+      {
+          if ( i != way ) all_recent = m_lru_tab[set][i].recent && all_recent;
+      }
+      if ( all_recent ) 
+      {
+          for( size_t i=0 ; i<m_ways ; i++ ) m_lru_tab[set][i].recent = false;
+      } 
+      else 
+      {
+          m_lru_tab[set][way].recent = true;
+      }
+    } // end write()
+
+    /////////////////////////////////////////////////////////////////////
+    // The print() function prints a selected directory entry
+    // Arguments :
+    // - set : the set of the entry to print
+    // - way : the way of the entry to print
+    /////////////////////////////////////////////////////////////////////
+    void print(const size_t &set, const size_t &way)
+    {
+      std::cout << std::dec << " set : " << set << " ; way : " << way << " ; " ;
+      m_dir_tab[set][way].print();
+    } // end print()
+
+    /////////////////////////////////////////////////////////////////////
+    // The select() function selects a directory entry to evince.
+    // Arguments :
+    // - set   : (input argument) the set to modify
+    // - way   : (return argument) the way to evince
+    /////////////////////////////////////////////////////////////////////
+    DirectoryEntry select(const size_t &set, size_t &way)
+    {
+        assert( (set < m_sets) 
+          && "Cache Directory : (select) The set index is invalid");
+
+        // looking for an empty slot
+        for(size_t i=0; i<m_ways; i++)
+        {
+            if( m_dir_tab[set][i].state == ENTRY_INVALID )
+            {
+                way=i;
+                return DirectoryEntry(m_dir_tab[set][way]);
+            }
+        }
+
+#ifdef RANDOM_EVICTION
+        lfsr = (lfsr >> 1) ^ ((-(lfsr & 1)) & 0xd0000001);
+        way = lfsr % m_ways;
+        return DirectoryEntry(m_dir_tab[set][way]);
+#endif
+
+        // looking for a not locked and not recently used entry
+        for(size_t i=0; i<m_ways; i++)
+        {
+            if((not m_lru_tab[set][i].recent) && (not m_dir_tab[set][i].lock) && ( m_dir_tab[set][i].state != ENTRY_LOCKED))
+            {
+                way=i;
+                return DirectoryEntry(m_dir_tab[set][way]);
+            }
+        }
+
+        // looking for a locked not recently used entry
+        for(size_t i=0; i<m_ways; i++)
+        {
+            if( (not m_lru_tab[set][i].recent) && (m_dir_tab[set][i].lock) && ( m_dir_tab[set][i].state != ENTRY_LOCKED))
+            {
+                way=i;
+                return DirectoryEntry(m_dir_tab[set][way]);
+            }
+        }
+
+        // looking for a recently used entry not locked
+        for(size_t i=0; i<m_ways; i++)
+        {
+            if((m_lru_tab[set][i].recent) && (not m_dir_tab[set][i].lock) && ( m_dir_tab[set][i].state != ENTRY_LOCKED))
+            {
+                way=i;
+                return DirectoryEntry(m_dir_tab[set][way]);
+            }
+        }
+        
+        // select way 0 (even if entry is locked and recently used)
+        way = -1;
+        return DirectoryEntry(m_dir_tab[set][0]);
+    } // end select()
+
+    /////////////////////////////////////////////////////////////////////
+    // 		Global initialisation function
+    /////////////////////////////////////////////////////////////////////
+    void init()
+    {
+      for ( size_t set=0 ; set<m_sets ; set++ ) 
+      {
+        for ( size_t way=0 ; way<m_ways ; way++ ) 
+        {
+          m_dir_tab[set][way].init();
+          m_lru_tab[set][way].init();
+        }
+      }
+    } // end init()
+
+  }; // end class CacheDirectory
+
+  ///////////////////////////////////////////////////////////////////////
+  //                    A Heap Entry
+  ///////////////////////////////////////////////////////////////////////
+  class HeapEntry{
+
+    public:
+    // Fields of the entry
+      Owner     owner;
+      size_t    next;
+
+    ////////////////////////
+    // Constructor
+    ////////////////////////
+      HeapEntry()
+      :owner(false,0)
+      {
+        next = 0;
+      } // end constructor
+
+    ////////////////////////
+    // Constructor
+    ////////////////////////
+      HeapEntry(const HeapEntry &entry)
+      {
+        owner.inst  = entry.owner.inst;
+        owner.srcid = entry.owner.srcid;
+        next           = entry.next;
+      } // end constructor
+
+    /////////////////////////////////////////////////////////////////////
+    // The copy() function copies an existing source entry to a target 
+    /////////////////////////////////////////////////////////////////////
+      void copy(const HeapEntry &entry)
+      {
+        owner.inst     = entry.owner.inst;
+        owner.srcid    = entry.owner.srcid;
+        next           = entry.next;
+      } // end copy()
+
+    ////////////////////////////////////////////////////////////////////
+    // The print() function prints the entry 
+    ////////////////////////////////////////////////////////////////////
+      void print(){
+        std::cout 
+        << " -- owner.inst     : " << std::dec << owner.inst << std::endl
+        << " -- owner.srcid    : " << std::dec << owner.srcid << std::endl
+        << " -- next           : " << std::dec << next << std::endl;
+
+      } // end print()
+
+  }; // end class HeapEntry
+
+  ////////////////////////////////////////////////////////////////////////
+  //                        The Heap 
+  ////////////////////////////////////////////////////////////////////////
+  class HeapDirectory{
+    
+    private:
+    // Registers and the heap
+      size_t    ptr_free;
+      bool      full;
+      HeapEntry *m_heap_tab;
+
+    // Constants for debugging purpose
+      size_t    tab_size;
+
+    public:
+    ////////////////////////
+    // Constructor
+    ////////////////////////
+      HeapDirectory(uint32_t size){
+        assert(size>0 && "Memory Cache, HeapDirectory constructor : invalid size");
+        ptr_free    = 0;
+        full        = false;
+        m_heap_tab  = new HeapEntry[size];
+        tab_size    = size;
+      } // end constructor
+
+    /////////////////
+    // Destructor
+    /////////////////
+      ~HeapDirectory(){
+        delete [] m_heap_tab;
+      } // end destructor
+
+    /////////////////////////////////////////////////////////////////////
+    // 		Global initialisation function
+    /////////////////////////////////////////////////////////////////////
+      void init(){
+        ptr_free=0;
+        full=false;
+        for(size_t i=0; i< tab_size-1;i++){
+          m_heap_tab[i].next = i+1;
+        }
+        m_heap_tab[tab_size-1].next = tab_size-1;
+        return;
+      }
+
+    /////////////////////////////////////////////////////////////////////
+    // The print() function prints a selected directory entry
+    // Arguments :
+    // - ptr : the pointer to the entry to print
+    /////////////////////////////////////////////////////////////////////
+      void print(const size_t &ptr){
+        std::cout << "Heap, printing the entry : " << std::dec << ptr << std::endl;
+        m_heap_tab[ptr].print();
+      } // end print()
+
+    /////////////////////////////////////////////////////////////////////
+    // The print_list() function prints a list from selected directory entry
+    // Arguments :
+    // - ptr : the pointer to the first entry to print
+    /////////////////////////////////////////////////////////////////////
+      void print_list(const size_t &ptr){
+        bool end = false;
+        size_t ptr_temp = ptr;
+        std::cout << "Heap, printing the list from : " << std::dec << ptr << std::endl;
+        while(!end){
+            m_heap_tab[ptr_temp].print();
+            if(ptr_temp == m_heap_tab[ptr_temp].next) end = true;
+            ptr_temp = m_heap_tab[ptr_temp].next;
+        } 
+      } // end print_list()
+
+    /////////////////////////////////////////////////////////////////////
+    // The is_full() function return true if the heap is full.
+    /////////////////////////////////////////////////////////////////////
+      bool is_full(){
+        return full;
+      } // end is_full()
+
+    /////////////////////////////////////////////////////////////////////
+    // The next_free_ptr() function returns the pointer 
+    // to the next free entry.
+    /////////////////////////////////////////////////////////////////////
+      size_t next_free_ptr(){
+        return ptr_free;
+      } // end next_free_ptr()
+
+    /////////////////////////////////////////////////////////////////////
+    // The next_free_entry() function returns 
+    // a copy of the next free entry.
+    /////////////////////////////////////////////////////////////////////
+      HeapEntry next_free_entry(){
+        return HeapEntry(m_heap_tab[ptr_free]);
+      } // end next_free_entry()
+   
+    /////////////////////////////////////////////////////////////////////
+    // The write_free_entry() function modify the next free entry.
+    // Arguments :
+    // - entry : the entry to write
+    /////////////////////////////////////////////////////////////////////
+      void write_free_entry(const HeapEntry &entry){
+        m_heap_tab[ptr_free].copy(entry);
+      } // end write_free_entry()
+
+    /////////////////////////////////////////////////////////////////////
+    // The write_free_ptr() function writes the pointer
+    // to the next free entry
+    /////////////////////////////////////////////////////////////////////
+      void write_free_ptr(const size_t &ptr){
+        assert( (ptr<tab_size) && "HeapDirectory error : try to write a wrong free pointer");
+        ptr_free = ptr;
+      } // end write_free_ptr()
+
+    /////////////////////////////////////////////////////////////////////
+    // The set_full() function sets the full bit (to true).
+    /////////////////////////////////////////////////////////////////////
+      void set_full(){
+        full = true;
+      } // end set_full()
+
+    /////////////////////////////////////////////////////////////////////
+    // The unset_full() function unsets the full bit (to false).
+    /////////////////////////////////////////////////////////////////////
+      void unset_full(){
+        full = false;
+      } // end unset_full()
+
+    /////////////////////////////////////////////////////////////////////
+    // The read() function returns a copy of
+    // the entry pointed by the argument
+    // Arguments :
+    //  - ptr : the pointer to the entry to read
+    /////////////////////////////////////////////////////////////////////
+      HeapEntry read(const size_t &ptr){
+        assert( (ptr<tab_size) && "HeapDirectory error : try to write a wrong free pointer");
+        return HeapEntry(m_heap_tab[ptr]);
+      } // end read()
+
+    /////////////////////////////////////////////////////////////////////
+    // The write() function writes an entry in the heap
+    // Arguments :
+    //  - ptr : the pointer to the entry to replace
+    //  - entry : the entry to write
+    /////////////////////////////////////////////////////////////////////
+      void write(const size_t &ptr, const HeapEntry &entry){
+        assert( (ptr<tab_size) && "HeapDirectory error : try to write a wrong free pointer");
+        m_heap_tab[ptr].copy(entry);
+      } // end write()
+
+  }; // end class HeapDirectory
+
+  ////////////////////////////////////////////////////////////////////////
+  //                        Cache Data 
+  ////////////////////////////////////////////////////////////////////////
+  class CacheData 
+  {
+    private:
+      const uint32_t m_sets;
+      const uint32_t m_ways;
+      const uint32_t m_words;
+
+      uint32_t *** m_cache_data;
+
+    public:
+
+      ///////////////////////////////////////////////////////
+      CacheData(uint32_t ways, uint32_t sets, uint32_t words)
+        : m_sets(sets), m_ways(ways), m_words(words) 
+      {
+          m_cache_data = new uint32_t ** [ways];
+          for ( size_t i=0 ; i < ways ; i++ ) 
+          {
+              m_cache_data[i] = new uint32_t * [sets];
+          }
+          for ( size_t i=0; i<ways; i++ ) 
+          {
+              for ( size_t j=0; j<sets; j++ ) 
+              {
+                  m_cache_data[i][j] = new uint32_t [words];
+              }
+          }
+      }
+      ////////////
+      ~CacheData() 
+      {
+          for(size_t i=0; i<m_ways ; i++)
+          {
+              for(size_t j=0; j<m_sets ; j++)
+              {
+                  delete [] m_cache_data[i][j];
+              }
+          }
+          for(size_t i=0; i<m_ways ; i++)
+          {
+              delete [] m_cache_data[i];
+          }
+          delete [] m_cache_data;
+      }
+      //////////////////////////////////////////
+      uint32_t read ( const uint32_t &way,
+                      const uint32_t &set,
+                      const uint32_t &word) const 
+      {
+          assert((set  < m_sets ) && "Cache data error: Trying to read a wrong set" );
+          assert((way  < m_ways ) && "Cache data error: Trying to read a wrong way" );
+          assert((word < m_words) && "Cache data error: Trying to read a wrong word");
+
+          return m_cache_data[way][set][word];
+      }
+      //////////////////////////////////////////
+      void read_line( const uint32_t &way,
+                      const uint32_t &set,
+                      sc_core::sc_signal<uint32_t> * cache_line)
+      {
+          assert((set < m_sets ) && "Cache data error: Trying to read a wrong set" );
+          assert((way < m_ways ) && "Cache data error: Trying to read a wrong way" );
+
+          for (uint32_t word=0; word<m_words; word++)
+              cache_line[word].write(m_cache_data[way][set][word]);
+      }
+      /////////////////////////////////////////
+      void write ( const uint32_t &way,
+                   const uint32_t &set,
+                   const uint32_t &word,
+                   const uint32_t &data,
+                   const uint32_t &be = 0xF) 
+      {
+
+          assert((set  < m_sets ) && "Cache data error: Trying to write a wrong set" );
+          assert((way  < m_ways ) && "Cache data error: Trying to write a wrong way" );
+          assert((word < m_words) && "Cache data error: Trying to write a wrong word");
+          assert((be  <= 0xF    ) && "Cache data error: Trying to write a wrong be");
+
+          if (be == 0x0) return;
+
+          if (be == 0xF) 
+          {
+              m_cache_data[way][set][word] = data; 
+              return;
+          }
+
+          uint32_t mask = 0;
+          if  (be & 0x1) mask = mask | 0x000000FF;
+          if  (be & 0x2) mask = mask | 0x0000FF00;
+          if  (be & 0x4) mask = mask | 0x00FF0000;
+          if  (be & 0x8) mask = mask | 0xFF000000;
+
+          m_cache_data[way][set][word] = 
+              (data & mask) | (m_cache_data[way][set][word] & ~mask);
+      }
+  }; // end class CacheData
+
+}} // end namespaces
+
+#endif
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: /branches/MESI/modules/vci_mem_cache/caba/source/include/update_tab.h
===================================================================
--- /branches/MESI/modules/vci_mem_cache/caba/source/include/update_tab.h	(revision 670)
+++ /branches/MESI/modules/vci_mem_cache/caba/source/include/update_tab.h	(revision 670)
@@ -0,0 +1,466 @@
+#ifndef UPDATE_TAB_H_
+#define UPDATE_TAB_H_
+
+#include <inttypes.h>
+#include <systemc>
+#include <cassert>
+#include "arithmetics.h"
+
+////////////////////////////////////////////////////////////////////////
+//                  An update tab entry    
+////////////////////////////////////////////////////////////////////////
+class UpdateTabEntry {
+
+  typedef uint32_t size_t;
+  typedef sc_dt::sc_uint<40> addr_t;
+
+  public:
+
+  bool 	    valid;      // It is a valid pending transaction
+  bool	    update;     // It is an update transaction
+  bool      brdcast;    // It is a broadcast invalidate
+  bool      rsp;        // Response to the initiator required
+  bool      ack;        // Acknowledge to the CONFIG FSM required
+  size_t 	srcid;      // The srcid of the initiator which wrote the data
+  size_t 	trdid;      // The trdid of the initiator which wrote the data
+  size_t 	pktid;      // The pktid of the initiator which wrote the data
+  addr_t	nline;	    // The identifier of the cache line
+  size_t 	count;      // The number of acknowledge responses to receive
+
+  UpdateTabEntry()
+  {
+    valid	= false;
+    update  = false;
+    brdcast = false;
+    rsp     = false;
+    ack     = false;
+    srcid	= 0;
+    trdid	= 0;
+    pktid	= 0;
+    nline	= 0;
+    count	= 0;
+  }
+
+  UpdateTabEntry(bool   i_valid, 
+                 bool   i_update,
+                 bool   i_brdcast,
+                 bool   i_rsp,
+                 bool   i_ack,
+                 size_t i_srcid, 
+                 size_t i_trdid, 
+                 size_t i_pktid, 
+                 addr_t i_nline,
+                 size_t i_count) 
+  {
+    valid	= i_valid;
+    update	= i_update;
+    brdcast = i_brdcast;
+    rsp     = i_rsp;
+    ack     = i_ack;
+    srcid	= i_srcid;
+    trdid	= i_trdid;
+    pktid	= i_pktid;
+    nline	= i_nline;
+    count	= i_count;
+  }
+
+  UpdateTabEntry(const UpdateTabEntry &source)
+  {
+    valid   = source.valid;
+    update  = source.update;
+    brdcast = source.brdcast;
+    rsp     = source.rsp;
+    ack     = source.ack;
+    srcid   = source.srcid;
+    trdid   = source.trdid;
+    pktid   = source.pktid;
+    nline   = source.nline;
+    count   = source.count;
+  }
+
+  ////////////////////////////////////////////////////
+  // The init() function initializes the entry 
+  ///////////////////////////////////////////////////
+  void init()
+  {
+    valid  = false;
+    update = false;
+    brdcast= false;
+    rsp    = false;
+    ack    = false;
+    srcid  = 0;
+    trdid  = 0;
+    pktid  = 0;
+    nline  = 0;
+    count  = 0;
+  }
+
+  ////////////////////////////////////////////////////////////////////
+  // The copy() function copies an existing entry
+  // Its arguments are :
+  // - source : the update tab entry to copy
+  ////////////////////////////////////////////////////////////////////
+  void copy(const UpdateTabEntry &source)
+  {
+    valid  = source.valid;
+    update = source.update;
+    brdcast= source.brdcast;
+    rsp    = source.rsp;
+    ack    = source.ack  ;
+    srcid  = source.srcid;
+    trdid  = source.trdid;
+    pktid  = source.pktid;
+    nline  = source.nline;
+    count  = source.count;
+  }
+
+  ////////////////////////////////////////////////////////////////////
+  // The print() function prints the entry  
+  ////////////////////////////////////////////////////////////////////
+  void print()
+  {
+    std::cout << " val = " << std::dec << valid 
+              << " / updt = " << update 
+              << " / bc = " << brdcast
+              << " / rsp = " << rsp 
+              << " / ack = " << ack   
+              << " / count = " << count
+              << " / srcid = " << std::hex << srcid 
+              << " / trdid = " << trdid   
+              << " / pktid = " << pktid
+              << " / nline = " << nline  << std::endl;
+  }
+};
+
+////////////////////////////////////////////////////////////////////////
+//                        The update tab             
+////////////////////////////////////////////////////////////////////////
+class UpdateTab{
+
+  typedef uint64_t addr_t;
+
+  private:
+  size_t                      size_tab;
+  std::vector<UpdateTabEntry> tab;
+
+  public:
+
+  UpdateTab()
+    : tab(0)
+  {
+    size_tab=0;
+  }
+
+  UpdateTab(size_t size_tab_i)
+    : tab(size_tab_i)
+  {
+    size_tab=size_tab_i;
+  }
+
+  ////////////////////////////////////////////////////////////////////
+  // The size() function returns the size of the tab  
+  ////////////////////////////////////////////////////////////////////
+  const size_t size()
+  {
+    return size_tab;
+  }
+
+  ////////////////////////////////////////////////////////////////////
+  // The print() function diplays the tab content 
+  ////////////////////////////////////////////////////////////////////
+  void print()
+  {
+    std::cout << "UPDATE TABLE Content" << std::endl;
+    for(size_t i=0; i<size_tab; i++) 
+    {
+      std::cout << "[" << std::dec << i << "] ";
+      tab[i].print();
+    }
+    return;
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The init() function initializes the tab 
+  /////////////////////////////////////////////////////////////////////
+  void init()
+  {
+    for ( size_t i=0; i<size_tab; i++) tab[i].init();
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The reads() function reads an entry 
+  // Arguments :
+  // - entry : the entry to read
+  // This function returns a copy of the entry.
+  /////////////////////////////////////////////////////////////////////
+  UpdateTabEntry read (size_t entry)
+  {
+    assert(entry<size_tab && "Bad Update Tab Entry");
+    return UpdateTabEntry(tab[entry]);
+  }
+
+  ///////////////////////////////////////////////////////////////////////////
+  // The set() function writes an entry in the Update Table
+  // Arguments :
+  // - update : transaction type (bool)
+  // - srcid : srcid of the initiator
+  // - trdid : trdid of the initiator
+  // - pktid : pktid of the initiator
+  // - count : number of expected responses
+  // - index : (return argument) index of the selected entry
+  // This function returns true if the write successed (an entry was empty).
+  ///////////////////////////////////////////////////////////////////////////
+  bool set(const bool	update,
+           const bool   brdcast,
+           const bool   rsp,
+           const bool   ack,
+           const size_t srcid,
+           const size_t trdid,
+           const size_t pktid,
+           const addr_t nline,
+           const size_t count,
+           size_t       &index)
+  {
+    for ( size_t i=0 ; i<size_tab ; i++ ) 
+    {
+      if( !tab[i].valid ) 
+      {
+        tab[i].valid		= true;
+        tab[i].update		= update;
+        tab[i].brdcast      = brdcast;
+        tab[i].rsp          = rsp;
+        tab[i].ack          = ack;
+        tab[i].srcid		= (size_t) srcid;
+        tab[i].trdid		= (size_t) trdid;
+        tab[i].pktid		= (size_t) pktid;
+        tab[i].nline		= (addr_t) nline;
+        tab[i].count		= (size_t) count;
+        index			    = i;
+        return true;
+      }
+    }
+    return false;
+  } // end set()
+
+  /////////////////////////////////////////////////////////////////////
+  // The decrement() function decrements the counter for a given entry.
+  // Arguments :
+  // - index   : the index of the entry
+  // - counter : (return argument) value of the counter after decrement
+  // This function returns true if the entry is valid.
+  /////////////////////////////////////////////////////////////////////
+  bool decrement( const size_t index,
+                  size_t &counter ) 
+  {
+    assert((index<size_tab) && "Bad Update Tab Entry");
+    if ( tab[index].valid ) 
+    {
+      tab[index].count--;
+      counter = tab[index].count;
+      return true;
+    } 
+    else 
+    {
+      return false;
+    }
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The is_full() function returns true if the table is full
+  /////////////////////////////////////////////////////////////////////
+  bool is_full()
+  {
+    for(size_t i = 0 ; i < size_tab ; i++)
+    {
+      if(!tab[i].valid) return false;
+    }
+    return true;
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The is_not_empty() function returns true if the table is not empty
+  /////////////////////////////////////////////////////////////////////
+  bool is_not_empty()
+  {
+    for(size_t i = 0 ; i < size_tab ; i++)
+    {
+      if(tab[i].valid) return true;
+    }
+    return false;
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The need_rsp() function returns the need of a response
+  // Arguments :
+  // - index : the index of the entry
+  /////////////////////////////////////////////////////////////////////
+  bool need_rsp(const size_t index)
+  {
+    assert(index<size_tab && "Bad Update Tab Entry");
+    return tab[index].rsp;	
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The need_ack() function returns the need of an acknowledge
+  // Arguments :
+  // - index : the index of the entry
+  /////////////////////////////////////////////////////////////////////
+  bool need_ack(const size_t index)
+  {
+    assert(index<size_tab && "Bad Update Tab Entry");
+    return tab[index].ack;	
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The is_brdcast() function returns the transaction type
+  // Arguments :
+  // - index : the index of the entry
+  /////////////////////////////////////////////////////////////////////
+  bool is_brdcast(const size_t index)
+  {
+    assert(index<size_tab && "Bad Update Tab Entry");
+    return tab[index].brdcast;	
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The is_update() function returns the transaction type
+  // Arguments :
+  // - index : the index of the entry
+  /////////////////////////////////////////////////////////////////////
+  bool is_update(const size_t index)
+  {
+    assert(index<size_tab && tab[index].valid && "Bad Update Tab Entry");
+    return tab[index].update;	
+  }
+  /////////////////////////////////////////////////////////////////////
+  // The is_update() function returns the valid bit
+  // Arguments :
+  // - index : the index of the entry
+  /////////////////////////////////////////////////////////////////////
+  bool is_valid(const size_t index)
+  {
+    assert(index<size_tab && "Bad Update Tab Entry");
+    return tab[index].valid;	
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The srcid() function returns the srcid value
+  // Arguments :
+  // - index : the index of the entry
+  /////////////////////////////////////////////////////////////////////
+  size_t srcid(const size_t index)
+  {
+    assert(index<size_tab && "Bad Update Tab Entry");
+    return tab[index].srcid;	
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The count() function returns the count value
+  // Arguments :
+  // - index : the index of the entry
+  /////////////////////////////////////////////////////////////////////
+  size_t count(const size_t index)
+  {
+    assert(index<size_tab && "Bad Update Tab Entry");
+    return tab[index].count;	
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The trdid() function returns the trdid value
+  // Arguments :
+  // - index : the index of the entry
+  /////////////////////////////////////////////////////////////////////
+  size_t trdid(const size_t index)
+  {
+    assert(index<size_tab && "Bad Update Tab Entry");
+    return tab[index].trdid;	
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The pktid() function returns the pktid value
+  // Arguments :
+  // - index : the index of the entry
+  /////////////////////////////////////////////////////////////////////
+  size_t pktid(const size_t index)
+  {
+    assert(index<size_tab && "Bad Update Tab Entry");
+    return tab[index].pktid;	
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The nline() function returns the nline value
+  // Arguments :
+  // - index : the index of the entry
+  /////////////////////////////////////////////////////////////////////
+  addr_t nline(const size_t index)
+  {
+    assert(index<size_tab && "Bad Update Tab Entry");
+    return tab[index].nline;
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The search_inval() function returns the index of the entry in UPT
+  // Arguments :
+  // - nline : the line number of the entry in the directory
+  /////////////////////////////////////////////////////////////////////
+  bool search_inval(const addr_t nline,size_t &index)
+  {
+    size_t i ;
+
+    for (i = 0 ; i < size_tab ; i++)
+    {
+      //if ( (tab[i].nline == nline) and tab[i].valid and not tab[i].update )
+      if ( (tab[i].nline == nline) and tab[i].valid )
+      {
+        index = i ;
+        return true;
+      }
+    }
+    return false;
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The read_nline() function returns the index of the entry in UPT
+  // Arguments :
+  // - nline : the line number of the entry in the directory
+  /////////////////////////////////////////////////////////////////////
+  bool read_nline(const addr_t nline,size_t &index) 
+  {
+    size_t i ;
+
+    for (i = 0 ; i < size_tab ; i++)
+    {
+      if ( (tab[i].nline == nline) and tab[i].valid )
+      {
+        index = i ;
+        return true;
+      }
+    }
+    return false;
+  }
+
+  /////////////////////////////////////////////////////////////////////
+  // The clear() function erases an entry of the tab
+  // Arguments :
+  // - index : the index of the entry
+  /////////////////////////////////////////////////////////////////////       
+  void clear(const size_t index)
+  {
+    assert(index<size_tab && "Bad Update Tab Entry");
+    tab[index].valid=false;
+    return;	
+  }
+
+};
+
+#endif
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: /branches/MESI/modules/vci_mem_cache/caba/source/include/vci_mem_cache.h
===================================================================
--- /branches/MESI/modules/vci_mem_cache/caba/source/include/vci_mem_cache.h	(revision 670)
+++ /branches/MESI/modules/vci_mem_cache/caba/source/include/vci_mem_cache.h	(revision 670)
@@ -0,0 +1,1266 @@
+/* -*- c++ -*-
+ * File         : vci_mem_cache.h
+ * Date         : 26/10/2008
+ * Copyright    : UPMC / LIP6
+ * Authors      : Alain Greiner / Eric Guthmuller
+ *
+ * SOCLIB_LGPL_HEADER_BEGIN
+ *
+ * This file is part of SoCLib, GNU LGPLv2.1.
+ *
+ * SoCLib is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 of the License.
+ *
+ * SoCLib is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with SoCLib; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ * SOCLIB_LGPL_HEADER_END
+ *
+ * Maintainers: alain.greiner@lip6.fr 
+ *              eric.guthmuller@polytechnique.edu
+ *              cesar.fuguet-tortolero@lip6.fr
+ *              alexandre.joannou@lip6.fr
+ */
+
+#ifndef SOCLIB_CABA_MEM_CACHE_H
+#define SOCLIB_CABA_MEM_CACHE_H
+
+#include <inttypes.h>
+#include <systemc>
+#include <list>
+#include <cassert>
+#include "arithmetics.h"
+#include "alloc_elems.h"
+#include "caba_base_module.h"
+#include "vci_target.h"
+#include "vci_initiator.h"
+#include "generic_fifo.h"
+#include "mapping_table.h"
+#include "int_tab.h"
+#include "generic_llsc_global_table.h"
+#include "mem_cache_directory.h"
+#include "xram_transaction.h"
+#include "update_tab.h"
+#include "dspin_interface.h"
+#include "dspin_dhccp_param.h"
+
+#define TRT_ENTRIES      4      // Number of entries in TRT
+#define UPT_ENTRIES      4      // Number of entries in UPT
+#define IVT_ENTRIES      4      // Number of entries in IVT
+#define HEAP_ENTRIES     1024   // Number of entries in HEAP
+
+namespace soclib {  namespace caba {
+
+  using namespace sc_core;
+
+  template<typename vci_param_int, 
+           typename vci_param_ext,
+           size_t   dspin_in_width,
+           size_t   dspin_out_width>
+    class VciMemCache
+    : public soclib::caba::BaseModule
+    {
+      typedef typename vci_param_int::fast_addr_t  addr_t;
+      typedef typename sc_dt::sc_uint<64>          wide_data_t;
+      typedef uint32_t                             data_t;
+      typedef uint32_t                             tag_t;
+      typedef uint32_t                             be_t;
+      typedef uint32_t                             copy_t;
+
+      /* States of the TGT_CMD fsm */
+      enum tgt_cmd_fsm_state_e
+      {
+        TGT_CMD_IDLE,
+        TGT_CMD_READ,
+        TGT_CMD_WRITE,
+        TGT_CMD_CAS,
+        TGT_CMD_ERROR,
+        TGT_CMD_CONFIG
+      };
+
+      /* States of the TGT_RSP fsm */
+      enum tgt_rsp_fsm_state_e
+      {
+        TGT_RSP_CONFIG_IDLE,
+        TGT_RSP_TGT_CMD_IDLE,
+        TGT_RSP_READ_IDLE,
+        TGT_RSP_WRITE_IDLE,
+        TGT_RSP_CAS_IDLE,
+        TGT_RSP_XRAM_IDLE,
+        TGT_RSP_MULTI_ACK_IDLE,
+        TGT_RSP_CLEANUP_IDLE,
+        TGT_RSP_CONFIG,
+        TGT_RSP_TGT_CMD,
+        TGT_RSP_READ,
+        TGT_RSP_WRITE,
+        TGT_RSP_CLEANUP,
+        TGT_RSP_CAS,
+        TGT_RSP_XRAM,
+        TGT_RSP_MULTI_ACK
+      };
+
+      /* States of the DSPIN_TGT fsm */
+      enum cc_receive_fsm_state_e
+      {
+        CC_RECEIVE_IDLE,
+        CC_RECEIVE_CLEANUP,
+        CC_RECEIVE_CLEANUP_EOP,
+        CC_RECEIVE_MULTI_ACK
+      };
+
+      /* States of the CC_SEND fsm */
+      enum cc_send_fsm_state_e
+      {
+        CC_SEND_CONFIG_IDLE,
+        CC_SEND_WRITE_IDLE,
+        CC_SEND_XRAM_RSP_IDLE,
+        CC_SEND_CAS_IDLE,
+        CC_SEND_READ_IDLE,
+        CC_SEND_CONFIG_INVAL_HEADER,
+        CC_SEND_CONFIG_INVAL_NLINE,
+        CC_SEND_CONFIG_BRDCAST_HEADER,
+        CC_SEND_CONFIG_BRDCAST_NLINE,
+        CC_SEND_XRAM_RSP_INVAL_HEADER,
+        CC_SEND_XRAM_RSP_INVAL_NLINE,
+        CC_SEND_XRAM_RSP_BRDCAST_HEADER,
+        CC_SEND_XRAM_RSP_BRDCAST_NLINE,
+        CC_SEND_READ_BRDCAST_HEADER,
+        CC_SEND_READ_BRDCAST_NLINE,
+        CC_SEND_READ_MULTI_HEADER,
+        CC_SEND_READ_MULTI_NLINE,
+        CC_SEND_WRITE_BRDCAST_HEADER,
+        CC_SEND_WRITE_BRDCAST_NLINE,
+        CC_SEND_WRITE_INVAL_HEADER,
+        CC_SEND_WRITE_INVAL_NLINE,
+        CC_SEND_CAS_BRDCAST_HEADER,
+        CC_SEND_CAS_BRDCAST_NLINE,
+        CC_SEND_CAS_INVAL_HEADER,
+        CC_SEND_CAS_INVAL_NLINE
+      };
+
+      /* States of the MULTI_ACK fsm */
+      enum multi_ack_fsm_state_e
+      {
+        MULTI_ACK_IDLE,
+        MULTI_ACK_GET_DATA,
+        MULTI_ACK_IVT_LOCK,
+        MULTI_ACK_IVT_CLEAR,
+        MULTI_ACK_DIR_REQ,
+        MULTI_ACK_DIR_LOCK,
+        MULTI_ACK_DIR_UPDT,
+        MULTI_ACK_RSP,
+        MULTI_ACK_HEAP_REQ,
+        MULTI_ACK_HEAP_LOCK,
+        MULTI_ACK_HEAP_WRITE,
+        MULTI_ACK_WAIT
+      };
+
+      /* States of the CONFIG fsm */
+      enum config_fsm_state_e
+      {
+        CONFIG_IDLE,
+        CONFIG_LOOP,
+        CONFIG_WAIT,
+        CONFIG_RSP,
+        CONFIG_DIR_REQ,
+        CONFIG_DIR_ACCESS,
+        CONFIG_IVT_LOCK,
+        CONFIG_BC_SEND,
+        CONFIG_INVAL_SEND,
+        CONFIG_HEAP_REQ,
+        CONFIG_HEAP_SCAN,
+        CONFIG_HEAP_LAST,
+        CONFIG_TRT_LOCK,
+        CONFIG_TRT_SET,
+        CONFIG_PUT_REQ
+      };
+
+      /* States of the READ fsm */
+      enum read_fsm_state_e
+      {
+        READ_IDLE,
+        READ_DIR_REQ,
+        READ_DIR_LOCK,
+        READ_IVT_INVAL_LOCK,
+        READ_INVAL_HEAP_REQ,
+        READ_INVAL_HEAP_ERASE,
+        READ_INVAL_HEAP_LAST,
+        READ_IVT_UPDT_LOCK,
+        READ_WAIT,
+        READ_DIR_HIT, 
+        READ_HEAP_REQ,
+        READ_HEAP_LOCK,
+        READ_HEAP_WRITE,
+        READ_HEAP_ERASE,
+        READ_HEAP_LAST,
+        READ_RSP,
+        READ_TRT_LOCK,
+        READ_TRT_SET,
+        READ_TRT_REQ
+      };
+
+      /* States of the WRITE fsm */
+      enum write_fsm_state_e
+      {
+        WRITE_IDLE,
+        WRITE_NEXT,
+        WRITE_DIR_REQ,
+        WRITE_DIR_LOCK,
+        WRITE_DIR_HIT,
+        WRITE_HEAP_REQ,
+        WRITE_HEAP_ERASE,
+        WRITE_HEAP_LAST,
+        WRITE_RSP,
+        WRITE_MISS_TRT_LOCK,
+        WRITE_WAIT,
+        WRITE_MISS_TRT_SET,
+        WRITE_MISS_TRT_DATA,
+        WRITE_MISS_XRAM_REQ,
+        WRITE_INVAL_TRT_LOCK,
+        WRITE_INVAL_IVT_LOCK,
+        WRITE_DIR_INVAL,
+        WRITE_INVAL_CC_SEND,
+        WRITE_INVAL_XRAM_REQ
+      };
+
+      /* States of the IXR_RSP fsm */
+      enum ixr_rsp_fsm_state_e
+      {
+        IXR_RSP_IDLE,
+        IXR_RSP_ACK,
+        IXR_RSP_TRT_ERASE,
+        IXR_RSP_TRT_READ
+      };
+
+      /* States of the XRAM_RSP fsm */
+      enum xram_rsp_fsm_state_e
+      {
+        XRAM_RSP_IDLE,
+        XRAM_RSP_TRT_COPY,
+        XRAM_RSP_TRT_DIRTY,
+        XRAM_RSP_DIR_LOCK,
+        XRAM_RSP_DIR_UPDT,
+        XRAM_RSP_DIR_RSP,
+        XRAM_RSP_IVT_LOCK,
+        XRAM_RSP_INVAL_WAIT,
+        XRAM_RSP_INVAL,
+        XRAM_RSP_WRITE_DIRTY,
+        XRAM_RSP_HEAP_REQ,
+        XRAM_RSP_HEAP_ERASE,
+        XRAM_RSP_HEAP_LAST,
+        XRAM_RSP_ERROR_ERASE,
+        XRAM_RSP_ERROR_RSP
+      };
+
+      /* States of the IXR_CMD fsm */
+      enum ixr_cmd_fsm_state_e
+      {
+        IXR_CMD_READ_IDLE,
+        IXR_CMD_WRITE_IDLE,
+        IXR_CMD_CAS_IDLE,
+        IXR_CMD_XRAM_IDLE,
+        IXR_CMD_CLEANUP_IDLE,
+        IXR_CMD_CONFIG_IDLE,
+        IXR_CMD_READ_TRT,
+        IXR_CMD_WRITE_TRT,
+        IXR_CMD_CAS_TRT,
+        IXR_CMD_XRAM_TRT,
+        IXR_CMD_CLEANUP_TRT,
+        IXR_CMD_CONFIG_TRT,
+        IXR_CMD_READ_SEND,
+        IXR_CMD_WRITE_SEND,
+        IXR_CMD_CAS_SEND,
+        IXR_CMD_XRAM_SEND,
+        IXR_CMD_CLEANUP_DATA_SEND,
+        IXR_CMD_CONFIG_SEND
+      };
+
+      /* States of the CAS fsm */
+      enum cas_fsm_state_e
+      {
+        CAS_IDLE,
+        CAS_DIR_REQ,
+        CAS_DIR_LOCK,
+        CAS_DIR_HIT_READ,
+        CAS_DIR_HIT_COMPARE,
+        CAS_DIR_HIT_WRITE,
+        CAS_MULTI_INVAL_IVT_LOCK,
+        CAS_WAIT,
+        CAS_MULTI_INVAL_HEAP_LOCK,
+        CAS_MULTI_INVAL_REQ,
+        CAS_HEAP_NEXT,
+        CAS_HEAP_LAST,
+        CAS_BC_TRT_LOCK,
+        CAS_BC_IVT_LOCK,
+        CAS_BC_DIR_INVAL,
+        CAS_BC_CC_SEND,
+        CAS_BC_XRAM_REQ,
+        CAS_RSP_FAIL,
+        CAS_RSP_SUCCESS,
+        CAS_MISS_TRT_LOCK,
+        CAS_MISS_TRT_SET,
+        CAS_MISS_XRAM_REQ
+      };
+
+      /* States of the CLEANUP fsm */
+      enum cleanup_fsm_state_e
+      {
+        CLEANUP_IDLE,
+        CLEANUP_GET_NLINE,
+        CLEANUP_GET_DATA,
+        CLEANUP_DIR_REQ,
+        CLEANUP_DIR_LOCK,
+        CLEANUP_DIR_WRITE,
+        CLEANUP_LOCKED_IVT_LOCK,
+        CLEANUP_LOCKED_IVT_DECREMENT,
+        CLEANUP_LOCKED_IVT_CLEAR,   
+        CLEANUP_LOCKED_RSP,
+        CLEANUP_HEAP_REQ,
+        CLEANUP_HEAP_LOCK,
+        CLEANUP_HEAP_SEARCH,
+        CLEANUP_HEAP_CLEAN,
+        CLEANUP_HEAP_FREE,
+        CLEANUP_MISS_IVT_LOCK,
+        CLEANUP_MISS_IVT_DECREMENT,
+        CLEANUP_MISS_IVT_CLEAR,
+        CLEANUP_MISS_RSP,
+        CLEANUP_MISS_IXR_REQ,
+        CLEANUP_WAIT,
+        CLEANUP_SEND_CLACK
+      };
+
+      /* States of the ALLOC_DIR fsm */
+      enum alloc_dir_fsm_state_e
+      {
+        ALLOC_DIR_RESET,
+        ALLOC_DIR_READ,
+        ALLOC_DIR_WRITE,
+        ALLOC_DIR_CAS,
+        ALLOC_DIR_CLEANUP,
+        ALLOC_DIR_XRAM_RSP,
+        ALLOC_DIR_MULTI_ACK,
+        ALLOC_DIR_CONFIG
+      };
+
+      /* States of the ALLOC_TRT fsm */
+      enum alloc_trt_fsm_state_e
+      {
+        ALLOC_TRT_READ,
+        ALLOC_TRT_WRITE,
+        ALLOC_TRT_CAS,
+        ALLOC_TRT_XRAM_RSP,
+        ALLOC_TRT_IXR_RSP,
+        ALLOC_TRT_CLEANUP,
+        ALLOC_TRT_IXR_CMD,
+        ALLOC_TRT_CONFIG
+      };
+
+//      /* States of the ALLOC_UPT fsm */
+//      enum alloc_upt_fsm_state_e
+//      {
+//        ALLOC_UPT_WRITE,
+//        ALLOC_UPT_CAS,
+//        ALLOC_UPT_MULTI_ACK
+//      };
+//
+      /* States of the ALLOC_IVT fsm */
+      enum alloc_ivt_fsm_state_e
+      {
+        ALLOC_IVT_WRITE,
+        ALLOC_IVT_READ,
+        ALLOC_IVT_XRAM_RSP,
+        ALLOC_IVT_CLEANUP,
+        ALLOC_IVT_CAS,
+        ALLOC_IVT_CONFIG,
+        ALLOC_IVT_MULTI_ACK
+      };
+
+      /* States of the ALLOC_HEAP fsm */
+      enum alloc_heap_fsm_state_e
+      {
+        ALLOC_HEAP_RESET,
+        ALLOC_HEAP_READ,
+        ALLOC_HEAP_WRITE,
+        ALLOC_HEAP_CAS,
+        ALLOC_HEAP_CLEANUP,
+        ALLOC_HEAP_MULTI_ACK,
+        ALLOC_HEAP_XRAM_RSP,
+        ALLOC_HEAP_CONFIG
+      };
+
+      /* transaction type, pktid field */
+      enum transaction_type_e
+      {
+          // b3 unused
+          // b2 READ / NOT READ
+          // Si READ
+          //  b1 DATA / INS
+          //  b0 UNC / MISS
+          // Si NOT READ
+          //  b1 accÃšs table llsc type SW / other
+          //  b2 WRITE/CAS/LL/SC
+          TYPE_DATA_UNC               = 0x0,
+          TYPE_READ_DATA_MISS         = 0x1,
+          TYPE_READ_INS_UNC           = 0x2,
+          TYPE_READ_INS_MISS          = 0x3,
+          TYPE_WRITE                  = 0x4,
+          TYPE_CAS                    = 0x5,
+          TYPE_LL                     = 0x6,
+          TYPE_SC                     = 0x7
+      };
+
+      /* SC return values */
+      enum sc_status_type_e
+      {
+          SC_SUCCESS  =   0x00000000,
+          SC_FAIL     =   0x00000001
+      };
+
+      // debug variables 
+      bool                 m_debug;
+      size_t               m_debug_previous_valid;
+      size_t               m_debug_previous_count;
+      bool                 m_debug_previous_dirty;
+      data_t *             m_debug_previous_data;
+      data_t *             m_debug_data;
+
+      // instrumentation counters
+      uint32_t     m_cpt_cycles;        // Counter of cycles
+
+      // Counters accessible in software (not yet but eventually)
+      uint32_t     m_cpt_reset_count;    // Last cycle at which counters have been reset
+      uint32_t     m_cpt_read_local;     // Number of local READ transactions
+      uint32_t     m_cpt_read_remote;    // number of remote READ transactions
+      uint32_t     m_cpt_read_cost;      // Number of (flits * distance) for READs
+
+      uint32_t     m_cpt_write_local;    // Number of local WRITE transactions
+      uint32_t     m_cpt_write_remote;   // number of remote WRITE transactions
+      uint32_t     m_cpt_write_flits_local;  // number of flits for local WRITEs
+      uint32_t     m_cpt_write_flits_remote; // number of flits for remote WRITEs
+      uint32_t     m_cpt_write_cost;     // Number of (flits * distance) for WRITEs
+
+      uint32_t     m_cpt_ll_local;       // Number of local LL transactions
+      uint32_t     m_cpt_ll_remote;      // number of remote LL transactions
+      uint32_t     m_cpt_ll_cost;        // Number of (flits * distance) for LLs
+
+      uint32_t     m_cpt_sc_local;       // Number of local SC transactions
+      uint32_t     m_cpt_sc_remote;      // number of remote SC transactions
+      uint32_t     m_cpt_sc_cost;        // Number of (flits * distance) for SCs
+
+      uint32_t     m_cpt_cas_local;      // Number of local SC transactions
+      uint32_t     m_cpt_cas_remote;     // number of remote SC transactions
+      uint32_t     m_cpt_cas_cost;       // Number of (flits * distance) for SCs
+
+      uint32_t     m_cpt_update;         // Number of requests causing an UPDATE
+      uint32_t     m_cpt_update_local;   // Number of local UPDATE transactions
+      uint32_t     m_cpt_update_remote;  // Number of remote UPDATE transactions
+      uint32_t     m_cpt_update_cost;    // Number of (flits * distance) for UPDT
+
+      uint32_t     m_cpt_minval;         // Number of requests causing M_INV
+      uint32_t     m_cpt_minval_local;   // Number of local M_INV transactions
+      uint32_t     m_cpt_minval_remote;  // Number of remote M_INV transactions
+      uint32_t     m_cpt_minval_cost;    // Number of (flits * distance) for M_INV
+
+      uint32_t     m_cpt_binval;         // Number of BROADCAST INVAL
+
+      uint32_t     m_cpt_cleanup_local;  // Number of local CLEANUP transactions
+      uint32_t     m_cpt_cleanup_remote; // Number of remote CLEANUP transactions
+      uint32_t     m_cpt_cleanup_cost;   // Number of (flits * distance) for CLEANUPs
+
+      // Counters not accessible by software
+      uint32_t     m_cpt_read_miss;      // Number of MISS READ
+      uint32_t     m_cpt_write_miss;    // Number of MISS WRITE
+      uint32_t     m_cpt_write_dirty;   // Cumulated length for WRITE transactions
+      uint32_t     m_cpt_write_broadcast;// Number of BROADCAST INVAL because write
+
+      uint32_t     m_cpt_trt_rb;        // Read blocked by a hit in trt
+      uint32_t     m_cpt_trt_full;      // Transaction blocked due to a full trt
+      
+      uint32_t     m_cpt_read_fsm_dir_lock;        // wait DIR LOCK
+      uint32_t     m_cpt_read_fsm_n_dir_lock;      // NB DIR LOCK
+      uint32_t     m_cpt_write_fsm_dir_lock;       // wait DIR LOCK
+      uint32_t     m_cpt_write_fsm_n_dir_lock;     // NB DIR LOCK
+      uint32_t     m_cpt_xram_rsp_fsm_dir_lock;    // wait DIR LOCK
+      uint32_t     m_cpt_xram_rsp_fsm_n_dir_lock;  // NB DIR LOCK
+      uint32_t     m_cpt_cas_fsm_dir_lock;         // wait DIR LOCK
+      uint32_t     m_cpt_cas_fsm_n_dir_lock;       // NB DIR LOCK
+      uint32_t     m_cpt_cleanup_fsm_dir_lock;     // wait DIR LOCK
+      uint32_t     m_cpt_cleanup_fsm_n_dir_lock;   // NB DIR LOCK
+      
+      uint32_t     m_cpt_dir_unused;            // NB cycles DIR LOCK unused
+      uint32_t     m_cpt_read_fsm_dir_used;     // NB cycles DIR LOCK used
+      uint32_t     m_cpt_write_fsm_dir_used;    // NB cycles DIR LOCK used
+      uint32_t     m_cpt_cas_fsm_dir_used;      // NB cycles DIR LOCK used
+      uint32_t     m_cpt_xram_rsp_fsm_dir_used; // NB cycles DIR LOCK used
+      uint32_t     m_cpt_cleanup_fsm_dir_used;  // NB cycles DIR LOCK used
+
+      uint32_t     m_cpt_read_fsm_trt_lock;      // wait TRT LOCK
+      uint32_t     m_cpt_write_fsm_trt_lock;     // wait TRT LOCK
+      uint32_t     m_cpt_cas_fsm_trt_lock;       // wait TRT LOCK
+      uint32_t     m_cpt_xram_rsp_fsm_trt_lock;  // wait TRT LOCK
+      uint32_t     m_cpt_ixr_fsm_trt_lock;       // wait TRT LOCK
+      
+      uint32_t     m_cpt_read_fsm_n_trt_lock;      // NB TRT LOCK
+      uint32_t     m_cpt_write_fsm_n_trt_lock;     // NB TRT LOCK
+      uint32_t     m_cpt_cas_fsm_n_trt_lock;       // NB TRT LOCK
+      uint32_t     m_cpt_xram_rsp_fsm_n_trt_lock;  // NB TRT LOCK
+      uint32_t     m_cpt_ixr_fsm_n_trt_lock;       // NB TRT LOCK
+
+      uint32_t     m_cpt_read_fsm_trt_used;      // NB cycles TRT LOCK used
+      uint32_t     m_cpt_write_fsm_trt_used;     // NB cycles TRT LOCK used
+      uint32_t     m_cpt_cas_fsm_trt_used;       // NB cycles TRT LOCK used
+      uint32_t     m_cpt_xram_rsp_fsm_trt_used;  // NB cycles TRT LOCK used
+      uint32_t     m_cpt_ixr_fsm_trt_used;       // NB cycles TRT LOCK used
+      
+      uint32_t     m_cpt_trt_unused;            // NB cycles TRT LOCK unused
+
+      uint32_t     m_cpt_write_fsm_upt_lock;     // wait UPT LOCK
+      uint32_t     m_cpt_xram_rsp_fsm_upt_lock;  // wait UPT LOCK
+      uint32_t     m_cpt_multi_ack_fsm_upt_lock; // wait UPT LOCK
+      uint32_t     m_cpt_cleanup_fsm_ivt_lock;   // wait UPT LOCK
+      uint32_t     m_cpt_cas_fsm_upt_lock;       // wait UPT LOCK
+      
+      uint32_t     m_cpt_write_fsm_n_upt_lock;     // NB UPT LOCK
+      uint32_t     m_cpt_xram_rsp_fsm_n_upt_lock;  // NB UPT LOCK
+      uint32_t     m_cpt_multi_ack_fsm_n_upt_lock; // NB UPT LOCK
+      uint32_t     m_cpt_cleanup_fsm_n_upt_lock;   // NB UPT LOCK
+      uint32_t     m_cpt_cas_fsm_n_upt_lock;       // NB UPT LOCK
+      
+      uint32_t     m_cpt_write_fsm_upt_used;     // NB cycles UPT LOCK used
+      uint32_t     m_cpt_xram_rsp_fsm_upt_used;  // NB cycles UPT LOCK used
+      uint32_t     m_cpt_multi_ack_fsm_upt_used; // NB cycles UPT LOCK used
+      uint32_t     m_cpt_cleanup_fsm_ivt_used;   // NB cycles UPT LOCK used
+      uint32_t     m_cpt_cas_fsm_upt_used;       // NB cycles UPT LOCK used
+      
+      uint32_t     m_cpt_ivt_unused;            // NB cycles UPT LOCK unused
+      uint32_t     m_cpt_upt_unused;            // NB cycles UPT LOCK unused
+
+      uint32_t     m_cpt_read_fsm_heap_lock;     // wait HEAP LOCK
+      uint32_t     m_cpt_write_fsm_heap_lock;    // wait HEAP LOCK
+      uint32_t     m_cpt_cas_fsm_heap_lock;      // wait HEAP LOCK
+      uint32_t     m_cpt_cleanup_fsm_heap_lock;  // wait HEAP LOCK
+      uint32_t     m_cpt_xram_rsp_fsm_heap_lock; // wait HEAP LOCK
+      
+      uint32_t     m_cpt_read_fsm_n_heap_lock;     // NB HEAP LOCK
+      uint32_t     m_cpt_write_fsm_n_heap_lock;    // NB HEAP LOCK
+      uint32_t     m_cpt_cas_fsm_n_heap_lock;      // NB HEAP LOCK
+      uint32_t     m_cpt_cleanup_fsm_n_heap_lock;  // NB HEAP LOCK
+      uint32_t     m_cpt_xram_rsp_fsm_n_heap_lock; // NB HEAP LOCK
+      
+      uint32_t     m_cpt_read_fsm_heap_used;     // NB cycles HEAP LOCK used
+      uint32_t     m_cpt_write_fsm_heap_used;    // NB cycles HEAP LOCK used
+      uint32_t     m_cpt_cas_fsm_heap_used;      // NB cycles HEAP LOCK used
+      uint32_t     m_cpt_cleanup_fsm_heap_used;  // NB cycles HEAP LOCK used
+      uint32_t     m_cpt_xram_rsp_fsm_heap_used; // NB cycles HEAP LOCK used
+      
+      uint32_t     m_cpt_heap_unused;            // NB cycles HEAP LOCK unused
+
+      //RWT
+      uint32_t     m_cpt_cleanup_data;   
+      uint32_t     m_cpt_ncc_to_cc_read;         // NB change from NCC to CC caused by a READ
+      uint32_t     m_cpt_ncc_to_cc_write;        // NB change from NCC to CC caused by a WRITE
+      uint32_t     m_cpt_ncc_to_cc;              // NB change from NCC to CC
+
+      uint32_t     m_cpt_read_data_unc;
+      uint32_t     m_cpt_read_data_miss_CC;
+      uint32_t     m_cpt_read_ins_unc;
+      uint32_t     m_cpt_read_ins_miss;
+      uint32_t     m_cpt_read_ll_CC;
+      uint32_t     m_cpt_read_data_miss_NCC;
+      uint32_t     m_cpt_read_ll_NCC;
+      uint32_t     m_cpt_read_WTF;
+
+      uint32_t     m_cpt_update_flits;  // Number of flits for UPDATEs
+      uint32_t     m_cpt_inval_cost;    // Number of (flits * distance) for INVALs
+
+      uint32_t     m_cpt_get;
+      uint32_t     m_cpt_put;
+
+      size_t       m_prev_count;
+
+      protected:
+
+      SC_HAS_PROCESS(VciMemCache);
+
+      public:
+      sc_in<bool>                                 p_clk;
+      sc_in<bool>                                 p_resetn;
+      sc_in<bool>                                 p_irq;
+      soclib::caba::VciTarget<vci_param_int>      p_vci_tgt;
+      soclib::caba::VciInitiator<vci_param_ext>   p_vci_ixr;
+      soclib::caba::DspinInput<dspin_in_width>    p_dspin_p2m;
+      soclib::caba::DspinOutput<dspin_out_width>  p_dspin_m2p;
+      soclib::caba::DspinOutput<dspin_out_width>  p_dspin_clack;
+
+#if MONITOR_MEMCACHE_FSM == 1
+      sc_out<int> p_read_fsm; 
+      sc_out<int> p_write_fsm; 
+      sc_out<int> p_xram_rsp_fsm; 
+      sc_out<int> p_cas_fsm; 
+      sc_out<int> p_cleanup_fsm; 
+      sc_out<int> p_config_fsm; 
+      sc_out<int> p_alloc_heap_fsm; 
+      sc_out<int> p_alloc_dir_fsm; 
+      sc_out<int> p_alloc_trt_fsm; 
+      sc_out<int> p_alloc_upt_fsm; 
+      sc_out<int> p_alloc_ivt_fsm; 
+      sc_out<int> p_tgt_cmd_fsm; 
+      sc_out<int> p_tgt_rsp_fsm; 
+      sc_out<int> p_ixr_cmd_fsm; 
+      sc_out<int> p_ixr_rsp_fsm; 
+      sc_out<int> p_cc_send_fsm; 
+      sc_out<int> p_cc_receive_fsm; 
+      sc_out<int> p_multi_ack_fsm; 
+#endif
+
+      VciMemCache(
+          sc_module_name name,                                // Instance Name
+          const soclib::common::MappingTable &mtp,            // Mapping table INT network
+          const soclib::common::MappingTable &mtx,            // Mapping table RAM network
+          const soclib::common::IntTab       &srcid_x,        // global index RAM network
+          const soclib::common::IntTab       &tgtid_d,        // global index INT network
+          const size_t                       cc_global_id,    // global index CC network
+          const size_t                       x_width,         // X width in platform
+          const size_t                       y_width,         // Y width in platform
+          const size_t                       nways,           // Number of ways per set
+          const size_t                       nsets,           // Number of sets
+          const size_t                       nwords,          // Number of words per line
+          const size_t                       max_copies,      // max number of copies
+          const size_t                       heap_size=HEAP_ENTRIES,
+          const size_t                       trt_lines=TRT_ENTRIES, 
+          const size_t                       upt_lines=UPT_ENTRIES,     
+          const size_t                       ivt_lines=IVT_ENTRIES,     
+          const size_t                       debug_start_cycle=0,
+          const bool                         debug_ok=false );
+
+      ~VciMemCache();
+
+      void reset_counters();
+      void print_stats(bool activity_counters, bool stats);
+      void print_trace( size_t detailled = 0 );
+      void cache_monitor(addr_t addr);
+      void start_monitor(addr_t addr, addr_t length);
+      void stop_monitor();
+
+      private:
+
+      void transition();
+      void genMoore();
+      void check_monitor(addr_t addr, data_t data, bool read);
+      uint32_t req_distance(uint32_t req_srcid);
+      bool is_local_req(uint32_t req_srcid);
+      int  read_instrumentation(uint32_t regr, uint32_t & rdata);
+
+      // Component attributes
+      std::list<soclib::common::Segment> m_seglist;          // segments allocated 
+      size_t                             m_nseg;             // number of segments
+      soclib::common::Segment            **m_seg;            // array of segments pointers
+      size_t                             m_seg_config;       // config segment index
+      const size_t                       m_srcid_x;          // global index on RAM network
+      const size_t                       m_initiators;       // Number of initiators
+      const size_t                       m_heap_size;        // Size of the heap
+      const size_t                       m_ways;             // Number of ways in a set
+      const size_t                       m_sets;             // Number of cache sets
+      const size_t                       m_words;            // Number of words in a line
+      const size_t                       m_cc_global_id;     // global_index on cc network
+      const size_t                       m_xwidth;           // number of x bits in platform
+      const size_t                       m_ywidth;           // number of y bits in platform
+      size_t                             m_debug_start_cycle;
+      bool                               m_debug_ok;
+      uint32_t                           m_trt_lines;
+      TransactionTab                     m_trt;              // xram transaction table
+      uint32_t                           m_upt_lines;
+      UpdateTab                          m_upt;              // pending update
+      UpdateTab                          m_ivt;              // pending invalidate
+      CacheDirectory                     m_cache_directory;  // data cache directory
+      CacheData                          m_cache_data;       // data array[set][way][word]
+      HeapDirectory                      m_heap;             // heap for copies
+      size_t                             m_max_copies;       // max number of copies in heap
+      GenericLLSCGlobalTable
+      < 32  ,    // number of slots
+        4096,    // number of processors in the system
+        8000,    // registration life (# of LL operations)
+        addr_t >                         m_llsc_table;       // ll/sc registration table
+
+      // adress masks
+      const soclib::common::AddressMaskingTable<addr_t>   m_x;
+      const soclib::common::AddressMaskingTable<addr_t>   m_y;
+      const soclib::common::AddressMaskingTable<addr_t>   m_z;
+      const soclib::common::AddressMaskingTable<addr_t>   m_nline;
+
+      // broadcast address
+      uint32_t                           m_broadcast_boundaries;
+
+      // configuration interface constants
+      const uint32_t m_config_addr_mask;
+      const uint32_t m_config_regr_width;
+      const uint32_t m_config_func_width;
+      const uint32_t m_config_regr_idx_mask;
+      const uint32_t m_config_func_idx_mask;
+
+      // Fifo between TGT_CMD fsm and READ fsm
+      GenericFifo<addr_t>    m_cmd_read_addr_fifo;
+      GenericFifo<size_t>    m_cmd_read_length_fifo;
+      GenericFifo<size_t>    m_cmd_read_srcid_fifo;
+      GenericFifo<size_t>    m_cmd_read_trdid_fifo;
+      GenericFifo<size_t>    m_cmd_read_pktid_fifo;
+
+      // Fifo between TGT_CMD fsm and WRITE fsm
+      GenericFifo<addr_t>    m_cmd_write_addr_fifo;
+      GenericFifo<bool>      m_cmd_write_eop_fifo;
+      GenericFifo<size_t>    m_cmd_write_srcid_fifo;
+      GenericFifo<size_t>    m_cmd_write_trdid_fifo;
+      GenericFifo<size_t>    m_cmd_write_pktid_fifo;
+      GenericFifo<data_t>    m_cmd_write_data_fifo;
+      GenericFifo<be_t>      m_cmd_write_be_fifo;
+
+      // Fifo between TGT_CMD fsm and CAS fsm
+      GenericFifo<addr_t>    m_cmd_cas_addr_fifo;
+      GenericFifo<bool>      m_cmd_cas_eop_fifo;
+      GenericFifo<size_t>    m_cmd_cas_srcid_fifo;
+      GenericFifo<size_t>    m_cmd_cas_trdid_fifo;
+      GenericFifo<size_t>    m_cmd_cas_pktid_fifo;
+      GenericFifo<data_t>    m_cmd_cas_wdata_fifo;
+
+      // Fifo between CC_RECEIVE fsm and CLEANUP fsm
+      GenericFifo<uint64_t>  m_cc_receive_to_cleanup_fifo;
+      
+      // Fifo between CC_RECEIVE fsm and MULTI_ACK fsm
+      GenericFifo<uint64_t>  m_cc_receive_to_multi_ack_fifo;
+
+      // Buffer between TGT_CMD fsm and TGT_RSP fsm
+      // (segmentation violation response request)
+      sc_signal<bool>     r_tgt_cmd_to_tgt_rsp_req;
+
+      sc_signal<uint32_t> r_tgt_cmd_to_tgt_rsp_rdata;
+      sc_signal<size_t>   r_tgt_cmd_to_tgt_rsp_error;
+      sc_signal<size_t>   r_tgt_cmd_to_tgt_rsp_srcid;
+      sc_signal<size_t>   r_tgt_cmd_to_tgt_rsp_trdid;
+      sc_signal<size_t>   r_tgt_cmd_to_tgt_rsp_pktid;
+
+      sc_signal<addr_t>   r_tgt_cmd_config_addr;
+      sc_signal<size_t>   r_tgt_cmd_config_cmd;
+
+      //////////////////////////////////////////////////
+      // Registers controlled by the TGT_CMD fsm
+      //////////////////////////////////////////////////
+
+      sc_signal<int>         r_tgt_cmd_fsm;
+
+      ///////////////////////////////////////////////////////
+      // Registers controlled by the CONFIG fsm
+      ///////////////////////////////////////////////////////
+
+      sc_signal<int>      r_config_fsm;               // FSM state
+      sc_signal<bool>     r_config_lock;              // lock protecting exclusive access
+      sc_signal<int>      r_config_cmd;               // config request type  
+      sc_signal<addr_t>   r_config_address;           // target buffer physical address
+      sc_signal<size_t>   r_config_srcid;             // config request srcid
+      sc_signal<size_t>   r_config_trdid;             // config request trdid
+      sc_signal<size_t>   r_config_pktid;             // config request pktid
+      sc_signal<size_t>   r_config_cmd_lines;         // number of lines to be handled
+      sc_signal<size_t>   r_config_rsp_lines;         // number of lines not completed
+      sc_signal<size_t>   r_config_dir_way;           // DIR: selected way
+      sc_signal<bool>     r_config_dir_lock;          // DIR: locked entry
+      sc_signal<size_t>   r_config_dir_count;         // DIR: number of copies
+      sc_signal<bool>     r_config_dir_is_cnt;        // DIR: counter mode (broadcast)
+      sc_signal<size_t>   r_config_dir_copy_srcid;    // DIR: first copy SRCID
+      sc_signal<bool>     r_config_dir_copy_inst;     // DIR: first copy L1 type
+      sc_signal<size_t>   r_config_dir_ptr;           // DIR: index of next copy in HEAP
+      sc_signal<size_t>   r_config_dir_state;         // DIR: dir state 
+      sc_signal<size_t>   r_config_heap_next;         // current pointer to scan HEAP
+      sc_signal<size_t>   r_config_trt_index;         // selected entry in TRT
+      sc_signal<size_t>   r_config_ivt_index;         // selected entry in IVT 
+
+      // Buffer between CONFIG fsm and IXR_CMD fsm
+      sc_signal<bool>     r_config_to_ixr_cmd_req;    // valid request
+      sc_signal<size_t>   r_config_to_ixr_cmd_index;  // TRT index
+
+      // Buffer between CONFIG fsm and TGT_RSP fsm (send a done response to L1 cache)
+      sc_signal<bool>     r_config_to_tgt_rsp_req;    // valid request
+      sc_signal<bool>     r_config_to_tgt_rsp_error;  // error response
+      sc_signal<size_t>   r_config_to_tgt_rsp_srcid;  // Transaction srcid
+      sc_signal<size_t>   r_config_to_tgt_rsp_trdid;  // Transaction trdid
+      sc_signal<size_t>   r_config_to_tgt_rsp_pktid;  // Transaction pktid
+
+      // Buffer between CONFIG fsm and CC_SEND fsm (multi-inval / broadcast-inval)
+      sc_signal<bool>     r_config_to_cc_send_multi_req;    // multi-inval request
+      sc_signal<bool>     r_config_to_cc_send_brdcast_req;  // broadcast-inval request
+      sc_signal<addr_t>   r_config_to_cc_send_nline;        // line index
+      sc_signal<size_t>   r_config_to_cc_send_trdid;        // UPT index
+      GenericFifo<bool>   m_config_to_cc_send_inst_fifo;    // fifo for the L1 type
+      GenericFifo<size_t> m_config_to_cc_send_srcid_fifo;   // fifo for owners srcid
+
+      ///////////////////////////////////////////////////////
+      // Registers controlled by the READ fsm
+      ///////////////////////////////////////////////////////
+
+      sc_signal<int>      r_read_fsm;                 // FSM state
+      sc_signal<size_t>   r_read_copy;                // Srcid of the first copy
+      sc_signal<size_t>   r_read_copy_cache;          // Srcid of the first copy
+      sc_signal<bool>     r_read_copy_inst;           // Type of the first copy
+      sc_signal<tag_t>    r_read_tag;                 // cache line tag (in directory)
+      sc_signal<bool>     r_read_is_cnt;              // is_cnt bit (in directory)
+      sc_signal<bool>     r_read_lock;                // lock bit (in directory)
+      sc_signal<bool>     r_read_dirty;               // dirty bit (in directory)
+      sc_signal<size_t>   r_read_count;               // number of copies
+      sc_signal<size_t>   r_read_ptr;                 // pointer to the heap
+      sc_signal<data_t> * r_read_data;                // data (one cache line)
+      sc_signal<size_t>   r_read_way;                 // associative way (in cache)
+      sc_signal<size_t>   r_read_trt_index;           // Transaction Table index
+      sc_signal<size_t>   r_read_next_ptr;            // Next entry to point to
+      sc_signal<bool>     r_read_last_free;           // Last free entry
+      sc_signal<addr_t>   r_read_ll_key;              // LL key from llsc_global_table
+
+
+    
+      sc_signal<bool>     r_read_ll_done; 
+      sc_signal<bool>     r_read_need_block; 
+      sc_signal<size_t>   r_read_state; 
+      // Buffer between READ fsm and IXR_CMD fsm 
+      sc_signal<bool>     r_read_to_ixr_cmd_req;      // valid request
+      sc_signal<size_t>   r_read_to_ixr_cmd_index;    // TRT index
+
+      // Buffer between READ fsm and TGT_RSP fsm (send a hit read response to L1 cache)
+      sc_signal<bool>     r_read_to_tgt_rsp_req;      // valid request
+      sc_signal<size_t>   r_read_to_tgt_rsp_srcid;    // Transaction srcid
+      sc_signal<size_t>   r_read_to_tgt_rsp_trdid;    // Transaction trdid
+      sc_signal<size_t>   r_read_to_tgt_rsp_pktid;    // Transaction pktid
+      sc_signal<data_t> * r_read_to_tgt_rsp_data;     // data (one cache line)
+      sc_signal<size_t>   r_read_to_tgt_rsp_word;     // first word of the response
+      sc_signal<size_t>   r_read_to_tgt_rsp_length;   // length of the response
+      sc_signal<addr_t>   r_read_to_tgt_rsp_ll_key;   // LL key from llsc_global_table
+
+      //RWT: Buffer between READ fsm and CC_SEND fsm (send inval)
+      sc_signal<bool>     r_read_to_cc_send_req;
+      sc_signal<size_t>   r_read_to_cc_send_dest;
+      sc_signal<addr_t>   r_read_to_cc_send_nline;
+      sc_signal<bool>     r_read_to_cc_send_inst;
+      sc_signal<size_t>   r_read_to_cc_send_srcid;
+      sc_signal<size_t>   r_read_to_cc_send_ivt_index;
+      sc_signal<bool>     r_read_to_cc_send_multi_req; // multi inval
+      sc_signal<bool>     r_read_to_cc_send_brdcast_req;    // bd inval
+      sc_signal<bool>     r_read_to_cc_send_type;    //cc inval or cc updt      
+
+      //RWT: Buffer between READ fsm and CLEANUP fsm (wait for the data coming from L1 cache) 
+      sc_signal<bool>     r_read_to_cleanup_req;    // valid request
+      sc_signal<addr_t>   r_read_to_cleanup_nline;  // cache line index
+      sc_signal<size_t>   r_read_to_cleanup_srcid;
+      sc_signal<size_t>   r_read_to_cleanup_length;
+      sc_signal<size_t>   r_read_to_cleanup_first_word;
+      sc_signal<bool>     r_read_to_cleanup_cached_read;    
+      sc_signal<bool>     r_read_to_cleanup_is_ll;
+      sc_signal<addr_t>   r_read_to_cleanup_addr;
+      sc_signal<addr_t>   r_read_to_cleanup_ll_key;
+
+      sc_signal<bool>     r_read_to_multi_ack_req;    // valid request
+      sc_signal<addr_t>   r_read_to_multi_ack_nline;  // cache line index
+      sc_signal<size_t>   r_read_to_multi_ack_first_word;
+      sc_signal<bool>     r_read_to_multi_ack_length;    
+      sc_signal<addr_t>   r_read_to_multi_ack_ll_key;
+ 
+
+      GenericFifo<bool>   m_read_to_cc_send_inst_fifo;    // fifo for the L1 type
+      GenericFifo<size_t> m_read_to_cc_send_srcid_fifo;   // fifo for owners srcid
+
+
+
+      sc_signal<bool>     r_multi_ack_need_data;    // cc_updt rsp with data 
+      sc_signal<size_t>   r_multi_ack_data_index;   
+      sc_signal<size_t>   r_multi_ack_ivt_index;   
+      sc_signal<size_t>   r_multi_ack_set;   
+      sc_signal<size_t>   r_multi_ack_way;   
+      sc_signal<size_t>   r_multi_ack_count;   
+      sc_signal<bool>     r_multi_ack_rsp;    
+      sc_signal<bool>     r_multi_ack_rsp_shared;    
+
+      sc_signal<size_t>   r_multi_ack_copy;                // Srcid of the first copy
+      sc_signal<bool>     r_multi_ack_copy_inst;           // Type of the first copy
+      sc_signal<tag_t>    r_multi_ack_tag;                 // cache line tag (in directory)
+      sc_signal<bool>     r_multi_ack_lock;                // lock bit (in directory)
+      sc_signal<bool>     r_multi_ack_dirty;               // dirty bit (in directory)
+      sc_signal<data_t> * r_multi_ack_data;                // data (one cache line)
+      sc_signal<size_t>   r_multi_ack_to_tgt_rsp_word;     
+      sc_signal<size_t>   r_multi_ack_to_tgt_rsp_length;   
+      sc_signal<size_t>   r_multi_ack_to_tgt_ll_key;       
+
+      sc_signal<bool>     r_multi_ack_last_free;  
+      sc_signal<bool>     r_multi_ack_miss_updt;  
+      sc_signal<size_t>   r_multi_ack_next_ptr;  
+
+      sc_signal<bool>     r_read_shared;          // State of the cache slot after transaction
+
+
+      sc_signal<data_t> * r_debug_data;            // data (one cache line)
+      ///////////////////////////////////////////////////////////////
+      // Registers controlled by the WRITE fsm
+      ///////////////////////////////////////////////////////////////
+
+      sc_signal<int>      r_write_fsm;                // FSM state
+      sc_signal<size_t>   r_write_state;  
+      sc_signal<addr_t>   r_write_address;            // first word address
+      sc_signal<size_t>   r_write_word_index;         // first word index in line
+      sc_signal<size_t>   r_write_word_count;         // number of words in line
+      sc_signal<size_t>   r_write_srcid;              // transaction srcid
+      sc_signal<size_t>   r_write_trdid;              // transaction trdid
+      sc_signal<size_t>   r_write_pktid;              // transaction pktid
+      sc_signal<data_t> * r_write_data;               // data (one cache line)
+      sc_signal<be_t>   * r_write_be;                 // one byte enable per word
+      sc_signal<bool>     r_write_byte;               // (BE != 0X0) and (BE != 0xF)
+      sc_signal<bool>     r_write_is_cnt;             // is_cnt bit (in directory)
+      sc_signal<bool>     r_write_lock;               // lock bit (in directory)
+      sc_signal<tag_t>    r_write_tag;                // cache line tag (in directory)
+      sc_signal<size_t>   r_write_copy;               // first owner of the line
+      sc_signal<size_t>   r_write_copy_cache;         // first owner of the line
+      sc_signal<bool>     r_write_copy_inst;          // is this owner a ICache ?
+      sc_signal<size_t>   r_write_count;              // number of copies
+      sc_signal<size_t>   r_write_ptr;                // pointer to the heap
+      sc_signal<size_t>   r_write_next_ptr;           // next pointer to the heap
+      sc_signal<bool>     r_write_to_dec;             // need to decrement update counter
+      sc_signal<size_t>   r_write_way;                // way of the line
+      sc_signal<size_t>   r_write_trt_index;          // index in Transaction Table
+      sc_signal<size_t>   r_write_upt_index;          // index in Update Table
+      sc_signal<bool>     r_write_sc_fail;            // sc command failed
+      sc_signal<data_t>   r_write_sc_key;             // sc command key
+      sc_signal<bool>     r_write_bc_data_we;         // Write enable for data buffer
+      sc_signal<bool>     r_write_inval_trt_send;
+      sc_signal<bool>     r_write_data_we;
+ 
+      // Buffer between WRITE fsm and TGT_RSP fsm (acknowledge a write command from L1)
+      sc_signal<bool>     r_write_to_tgt_rsp_req;     // valid request
+      sc_signal<size_t>   r_write_to_tgt_rsp_srcid;   // transaction srcid
+      sc_signal<size_t>   r_write_to_tgt_rsp_trdid;   // transaction trdid
+      sc_signal<size_t>   r_write_to_tgt_rsp_pktid;   // transaction pktid
+      sc_signal<bool>     r_write_to_tgt_rsp_sc_fail; // sc command failed
+
+      // Buffer between WRITE fsm and IXR_CMD fsm 
+      sc_signal<bool>     r_write_to_ixr_cmd_req;     // valid request
+      sc_signal<size_t>   r_write_to_ixr_cmd_index;   // TRT index 
+
+      // Buffer between WRITE fsm and CC_SEND fsm (Update/Invalidate L1 caches)
+      sc_signal<bool>     r_write_to_cc_send_multi_req;     // valid multicast request
+      sc_signal<bool>     r_write_to_cc_send_brdcast_req;   // valid brdcast request
+      sc_signal<addr_t>   r_write_to_cc_send_nline;         // cache line index
+      sc_signal<size_t>   r_write_to_cc_send_trdid;         // index in Update Table
+      sc_signal<data_t> * r_write_to_cleanup_data;          // data (one cache line)
+      sc_signal<be_t>   * r_write_to_cleanup_be;            // word enable
+      sc_signal<size_t>   r_write_to_cc_send_count;         // number of words in line
+      sc_signal<size_t>   r_write_to_cc_send_index;         // index of first word in line
+      GenericFifo<bool>   m_write_to_cc_send_inst_fifo;     // fifo for the L1 type
+      GenericFifo<size_t> m_write_to_cc_send_srcid_fifo;    // fifo for srcids
+
+      // Buffer between WRITE fsm and MULTI_ACK fsm (Decrement UPT entry)
+      sc_signal<bool>     r_write_to_multi_ack_req;       // valid request
+      sc_signal<size_t>   r_write_to_multi_ack_upt_index; // index in update table
+
+      // RWT: Buffer between WRITE fsm and CLEANUP fsm (change slot state)
+      sc_signal<bool>     r_write_to_cleanup_req;         // valid request
+      sc_signal<addr_t>   r_write_to_cleanup_nline;       // cache line index
+
+      // RWT
+      sc_signal<bool>     r_write_coherent;               // cache slot state after transaction
+
+      //Buffer between WRITE fsm and CC_SEND fsm (INVAL for RWT)
+      sc_signal<bool>     r_write_to_cc_send_req;
+      sc_signal<size_t>   r_write_to_cc_send_dest;
+
+
+      /////////////////////////////////////////////////////////
+      // Registers controlled by MULTI_ACK fsm
+      //////////////////////////////////////////////////////////
+
+      sc_signal<int>      r_multi_ack_fsm;       // FSM state
+      sc_signal<size_t>   r_multi_ack_upt_index; // index in the Update Table
+      sc_signal<size_t>   r_multi_ack_srcid;     // pending write srcid
+      sc_signal<size_t>   r_multi_ack_trdid;     // pending write trdid
+      sc_signal<size_t>   r_multi_ack_pktid;     // pending write pktid
+      sc_signal<addr_t>   r_multi_ack_nline;     // pending write nline
+
+      // Buffer between MULTI_ACK fsm and TGT_RSP fsm (complete write/update transaction)
+      sc_signal<bool>     r_multi_ack_to_tgt_rsp_req;   // valid request
+      sc_signal<size_t>   r_multi_ack_to_tgt_rsp_srcid; // Transaction srcid
+      sc_signal<size_t>   r_multi_ack_to_tgt_rsp_trdid; // Transaction trdid
+      sc_signal<size_t>   r_multi_ack_to_tgt_rsp_pktid; // Transaction pktid
+
+      ///////////////////////////////////////////////////////
+      // Registers controlled by CLEANUP fsm
+      ///////////////////////////////////////////////////////
+
+      sc_signal<int>      r_cleanup_fsm;           // FSM state
+      sc_signal<size_t>   r_cleanup_srcid;         // transaction srcid
+      sc_signal<bool>     r_cleanup_inst;          // Instruction or Data ?
+      sc_signal<size_t>   r_cleanup_way_index;     // L1 Cache Way index
+      sc_signal<addr_t>   r_cleanup_nline;         // cache line index
+
+
+      sc_signal<copy_t>   r_cleanup_copy;          // first copy
+      sc_signal<copy_t>   r_cleanup_copy_cache;    // first copy
+      sc_signal<size_t>   r_cleanup_copy_inst;     // type of the first copy
+      sc_signal<copy_t>   r_cleanup_count;         // number of copies
+      sc_signal<size_t>   r_cleanup_ptr;           // pointer to the heap
+      sc_signal<size_t>   r_cleanup_prev_ptr;      // previous pointer to the heap
+      sc_signal<size_t>   r_cleanup_prev_srcid;    // srcid of previous heap entry
+      sc_signal<size_t>   r_cleanup_prev_cache_id; // srcid of previous heap entry
+      sc_signal<bool>     r_cleanup_prev_inst;     // inst bit of previous heap entry
+      sc_signal<size_t>   r_cleanup_next_ptr;      // next pointer to the heap
+      sc_signal<tag_t>    r_cleanup_tag;           // cache line tag (in directory)
+      sc_signal<bool>     r_cleanup_is_cnt;        // inst bit (in directory)
+      sc_signal<bool>     r_cleanup_lock;          // lock bit (in directory)
+      sc_signal<bool>     r_cleanup_dirty;         // dirty bit (in directory)
+      sc_signal<size_t>   r_cleanup_way;           // associative way (in cache)
+
+      sc_signal<size_t>   r_cleanup_locked_srcid;   // srcid of write rsp
+      sc_signal<size_t>   r_cleanup_locked_trdid;   // trdid of write rsp
+      sc_signal<size_t>   r_cleanup_locked_pktid;   // pktid of write rsp
+      sc_signal<size_t>   r_cleanup_locked_index;   // ivt index
+      sc_signal<bool>     r_cleanup_locked_is_updt; 
+
+      sc_signal<size_t>   r_cleanup_miss_srcid;   // srcid of write rsp
+      sc_signal<size_t>   r_cleanup_miss_trdid;   // trdid of write rsp
+      sc_signal<size_t>   r_cleanup_miss_pktid;   // pktid of write rsp
+      sc_signal<size_t>   r_cleanup_miss_index;   // ivt index
+      sc_signal<bool>     r_cleanup_miss_is_updt; 
+      sc_signal<bool>     r_cleanup_miss_need_rsp;      // write response required
+      sc_signal<bool>     r_cleanup_miss_need_ack;      // config acknowledge required
+
+
+      // Buffer between CLEANUP fsm and TGT_RSP fsm (acknowledge a write command from L1)
+      sc_signal<bool>     r_cleanup_to_tgt_rsp_req;   // valid request
+      sc_signal<size_t>   r_cleanup_to_tgt_rsp_srcid; // transaction srcid
+      sc_signal<size_t>   r_cleanup_to_tgt_rsp_trdid; // transaction trdid
+      sc_signal<size_t>   r_cleanup_to_tgt_rsp_pktid; // transaction pktid
+      sc_signal<addr_t>   r_cleanup_to_tgt_rsp_ll_key;
+
+      sc_signal<bool>     r_cleanup_to_tgt_rsp_type;
+      sc_signal<data_t> * r_cleanup_to_tgt_rsp_data;
+      sc_signal<size_t>   r_cleanup_to_tgt_rsp_length;
+      sc_signal<size_t>   r_cleanup_to_tgt_rsp_first_word;
+
+      sc_signal<data_t> * r_multi_ack_to_tgt_rsp_data;
+      ///////////////////////////////////////////////////////
+      // Registers controlled by CAS fsm
+      ///////////////////////////////////////////////////////
+
+      sc_signal<int>      r_cas_fsm;              // FSM state
+      sc_signal<data_t>   r_cas_wdata;            // write data word
+      sc_signal<data_t> * r_cas_rdata;            // read data word
+      sc_signal<uint32_t> r_cas_lfsr;             // lfsr for random introducing
+      sc_signal<size_t>   r_cas_cpt;              // size of command
+      sc_signal<copy_t>   r_cas_copy;             // Srcid of the first copy
+      sc_signal<copy_t>   r_cas_copy_cache;       // Srcid of the first copy
+      sc_signal<bool>     r_cas_copy_inst;        // Type of the first copy
+      sc_signal<size_t>   r_cas_count;            // number of copies
+      sc_signal<size_t>   r_cas_ptr;              // pointer to the heap
+      sc_signal<size_t>   r_cas_next_ptr;         // next pointer to the heap
+      sc_signal<bool>     r_cas_is_cnt;           // is_cnt bit (in directory)
+      sc_signal<bool>     r_cas_dirty;            // dirty bit (in directory)
+      sc_signal<size_t>   r_cas_way;              // way in directory
+      sc_signal<size_t>   r_cas_set;              // set in directory
+      sc_signal<data_t>   r_cas_tag;              // cache line tag (in directory)
+      sc_signal<size_t>   r_cas_trt_index;        // Transaction Table index
+      sc_signal<size_t>   r_cas_ivt_index;        // Update Table index
+      sc_signal<data_t> * r_cas_data;             // cache line data
+
+      sc_signal<bool>     r_cas_coherent;
+      sc_signal<size_t>   r_cas_state;
+
+      // Buffer between CAS fsm and IXR_CMD fsm (XRAM write)
+      sc_signal<bool>     r_cas_to_ixr_cmd_req;   // valid request
+      sc_signal<size_t>   r_cas_to_ixr_cmd_index; // TRT index 
+
+      // Buffer between CAS fsm and TGT_RSP fsm
+      sc_signal<bool>     r_cas_to_tgt_rsp_req;   // valid request
+      sc_signal<data_t>   r_cas_to_tgt_rsp_data;  // read data word
+      sc_signal<size_t>   r_cas_to_tgt_rsp_srcid; // Transaction srcid
+      sc_signal<size_t>   r_cas_to_tgt_rsp_trdid; // Transaction trdid
+      sc_signal<size_t>   r_cas_to_tgt_rsp_pktid; // Transaction pktid
+
+      // Buffer between CAS fsm and CC_SEND fsm (Update/Invalidate L1 caches)
+      sc_signal<bool>     r_cas_to_cc_send_multi_req;     // valid request
+      sc_signal<bool>     r_cas_to_cc_send_brdcast_req;   // brdcast request
+      sc_signal<addr_t>   r_cas_to_cc_send_nline;         // cache line index
+      sc_signal<size_t>   r_cas_to_cc_send_trdid;         // index in Update Table
+      sc_signal<data_t>   r_cas_to_cc_send_wdata;         // data (one word)
+      sc_signal<bool>     r_cas_to_cc_send_is_long;       // it is a 64 bits CAS
+      sc_signal<data_t>   r_cas_to_cc_send_wdata_high;    // data high (one word)
+      sc_signal<size_t>   r_cas_to_cc_send_index;         // index of the word in line
+      GenericFifo<bool>   m_cas_to_cc_send_inst_fifo;     // fifo for the L1 type
+      GenericFifo<size_t> m_cas_to_cc_send_srcid_fifo;    // fifo for srcids
+
+      sc_signal<bool>     r_cas_to_cleanup_req;    
+      sc_signal<addr_t>   r_cas_to_cleanup_nline;   
+      ////////////////////////////////////////////////////
+      // Registers controlled by the IXR_RSP fsm
+      ////////////////////////////////////////////////////
+
+      sc_signal<int>      r_ixr_rsp_fsm;                // FSM state
+      sc_signal<size_t>   r_ixr_rsp_trt_index;          // TRT entry index
+      sc_signal<size_t>   r_ixr_rsp_cpt;                // word counter
+
+      // Buffer between IXR_RSP fsm and CONFIG fsm  (response from the XRAM)
+      sc_signal<bool>     r_ixr_rsp_to_config_ack;      // one single bit   
+
+      // Buffer between IXR_RSP fsm and XRAM_RSP fsm  (response from the XRAM)
+      sc_signal<bool>   * r_ixr_rsp_to_xram_rsp_rok;    // one bit per TRT entry
+
+      ////////////////////////////////////////////////////
+      // Registers controlled by the XRAM_RSP fsm
+      ////////////////////////////////////////////////////
+
+      sc_signal<int>      r_xram_rsp_fsm;               // FSM state
+      sc_signal<size_t>   r_xram_rsp_trt_index;         // TRT entry index
+      TransactionTabEntry r_xram_rsp_trt_buf;           // TRT entry local buffer
+      sc_signal<bool>     r_xram_rsp_victim_inval;      // victim line invalidate
+      sc_signal<bool>     r_xram_rsp_victim_is_cnt;     // victim line inst bit
+      sc_signal<bool>     r_xram_rsp_victim_dirty;      // victim line dirty bit
+      sc_signal<size_t>   r_xram_rsp_victim_way;        // victim line way
+      sc_signal<size_t>   r_xram_rsp_victim_set;        // victim line set
+      sc_signal<addr_t>   r_xram_rsp_victim_nline;      // victim line index
+      sc_signal<copy_t>   r_xram_rsp_victim_copy;       // victim line first copy
+      sc_signal<copy_t>   r_xram_rsp_victim_copy_cache; // victim line first copy
+      sc_signal<bool>     r_xram_rsp_victim_copy_inst;  // victim line type of first copy
+      sc_signal<size_t>   r_xram_rsp_victim_count;      // victim line number of copies
+      sc_signal<size_t>   r_xram_rsp_victim_ptr;        // victim line pointer to the heap
+      sc_signal<data_t> * r_xram_rsp_victim_data;       // victim line data
+      sc_signal<size_t>   r_xram_rsp_ivt_index;         // IVT entry index
+      sc_signal<size_t>   r_xram_rsp_next_ptr;          // Next pointer to the heap
+      sc_signal<size_t>   r_xram_rsp_victim_state; 
+
+      // Buffer between XRAM_RSP fsm and TGT_RSP fsm  (response to L1 cache)
+      sc_signal<bool>     r_xram_rsp_to_tgt_rsp_req;    // Valid request
+      sc_signal<size_t>   r_xram_rsp_to_tgt_rsp_srcid;  // Transaction srcid
+      sc_signal<size_t>   r_xram_rsp_to_tgt_rsp_trdid;  // Transaction trdid
+      sc_signal<size_t>   r_xram_rsp_to_tgt_rsp_pktid;  // Transaction pktid
+      sc_signal<data_t> * r_xram_rsp_to_tgt_rsp_data;   // data (one cache line)
+      sc_signal<size_t>   r_xram_rsp_to_tgt_rsp_word;   // first word index
+      sc_signal<size_t>   r_xram_rsp_to_tgt_rsp_length; // length of the response
+      sc_signal<bool>     r_xram_rsp_to_tgt_rsp_rerror; // send error to requester
+      sc_signal<addr_t>   r_xram_rsp_to_tgt_rsp_ll_key; // LL key from llsc_global_table
+
+      // Buffer between XRAM_RSP fsm and CC_SEND fsm (Inval L1 Caches)
+      sc_signal<bool>     r_xram_rsp_to_cc_send_multi_req;     // Valid request
+      sc_signal<bool>     r_xram_rsp_to_cc_send_brdcast_req;   // Broadcast request
+      sc_signal<addr_t>   r_xram_rsp_to_cc_send_nline;         // cache line index;
+      sc_signal<size_t>   r_xram_rsp_to_cc_send_trdid;         // index of UPT entry
+      GenericFifo<bool>   m_xram_rsp_to_cc_send_inst_fifo;     // fifo for the L1 type
+      GenericFifo<size_t> m_xram_rsp_to_cc_send_srcid_fifo;    // fifo for srcids
+
+      // Buffer between XRAM_RSP fsm and IXR_CMD fsm 
+      sc_signal<bool>     r_xram_rsp_to_ixr_cmd_req;   // Valid request
+      sc_signal<size_t>   r_xram_rsp_to_ixr_cmd_index; // TRT index 
+
+      //RWT
+      sc_signal<bool>     r_xram_rsp_victim_coherent;      // victim's cache slot state
+      sc_signal<bool>     r_xram_rsp_coherent;             // coherence of the read
+      ////////////////////////////////////////////////////
+      // Registers controlled by the IXR_CMD fsm
+      ////////////////////////////////////////////////////
+
+      sc_signal<int>      r_ixr_cmd_fsm;
+      sc_signal<size_t>   r_ixr_cmd_word;              // word index for a put
+      sc_signal<size_t>   r_ixr_cmd_trdid;             // TRT index value     
+      sc_signal<addr_t>   r_ixr_cmd_address;           // address to XRAM
+      sc_signal<data_t> * r_ixr_cmd_wdata;             // cache line buffer
+      sc_signal<bool>     r_ixr_cmd_get;               // transaction type (PUT/GET)
+
+      ////////////////////////////////////////////////////
+      // Registers controlled by TGT_RSP fsm
+      ////////////////////////////////////////////////////
+
+      sc_signal<int>      r_tgt_rsp_fsm;
+      sc_signal<size_t>   r_tgt_rsp_cpt;
+      sc_signal<bool>     r_tgt_rsp_key_sent;
+
+      ////////////////////////////////////////////////////
+      // Registers controlled by CC_SEND fsm
+      ////////////////////////////////////////////////////
+
+      sc_signal<int>      r_cc_send_fsm;
+      sc_signal<size_t>   r_cc_send_cpt;
+      sc_signal<bool>     r_cc_send_inst;
+
+      ////////////////////////////////////////////////////
+      // Registers controlled by CC_RECEIVE fsm
+      ////////////////////////////////////////////////////
+
+      sc_signal<int>      r_cc_receive_fsm;
+
+      ////////////////////////////////////////////////////
+      // Registers controlled by ALLOC_DIR fsm
+      ////////////////////////////////////////////////////
+
+      sc_signal<int>      r_alloc_dir_fsm;
+      sc_signal<unsigned> r_alloc_dir_reset_cpt;
+
+      ////////////////////////////////////////////////////
+      // Registers controlled by ALLOC_TRT fsm
+      ////////////////////////////////////////////////////
+
+      sc_signal<int>      r_alloc_trt_fsm;
+
+      ////////////////////////////////////////////////////
+      // Registers controlled by ALLOC_UPT fsm
+      ////////////////////////////////////////////////////
+
+  //    sc_signal<int>      r_alloc_upt_fsm;
+
+      ////////////////////////////////////////////////////
+      // Registers controlled by ALLOC_IVT fsm
+      ////////////////////////////////////////////////////
+
+      sc_signal<int>      r_alloc_ivt_fsm;
+
+      ////////////////////////////////////////////////////
+      // Registers controlled by ALLOC_HEAP fsm
+      ////////////////////////////////////////////////////
+
+      sc_signal<int>      r_alloc_heap_fsm;
+      sc_signal<unsigned> r_alloc_heap_reset_cpt;
+
+
+      ////////////////////////////////////////////////////
+      // REGISTERS FOR ODCCP
+      ////////////////////////////////////////////////////
+
+      sc_signal<uint32_t>  r_cleanup_data_index;
+      sc_signal<uint32_t>  r_cleanup_trdid;
+      sc_signal<uint32_t>  r_cleanup_state;
+      sc_signal<uint32_t>  r_cleanup_pktid;
+      sc_signal<bool>      r_cleanup_coherent;
+      sc_signal<data_t>    *r_cleanup_data;
+      sc_signal<data_t>    *r_cleanup_old_data;
+      sc_signal<bool>      r_cleanup_contains_data;
+      
+      sc_signal<bool>      r_cleanup_ncc;
+      sc_signal<bool>      r_cleanup_to_ixr_cmd_ncc_l1_dirty;
+      sc_signal<bool>      r_xram_rsp_to_ixr_cmd_inval_ncc_pending;
+      
+      sc_signal<bool>      r_cleanup_to_ixr_cmd_req;
+      sc_signal<data_t>    *r_cleanup_to_ixr_cmd_data;
+      sc_signal<uint32_t>  r_cleanup_to_ixr_cmd_srcid;
+      sc_signal<uint32_t>  r_cleanup_to_ixr_cmd_index;
+      sc_signal<uint32_t>  r_cleanup_to_ixr_cmd_pktid;
+      sc_signal<addr_t>    r_cleanup_to_ixr_cmd_nline;
+    }; // end class VciMemCache
+
+}}
+
+#endif
+
+// Local Variables:
+// tab-width: 2
+// c-basic-offset: 2
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=2:tabstop=2:softtabstop=2
+
Index: /branches/MESI/modules/vci_mem_cache/caba/source/include/xram_transaction.h
===================================================================
--- /branches/MESI/modules/vci_mem_cache/caba/source/include/xram_transaction.h	(revision 670)
+++ /branches/MESI/modules/vci_mem_cache/caba/source/include/xram_transaction.h	(revision 670)
@@ -0,0 +1,492 @@
+#ifndef XRAM_TRANSACTION_H_
+#define XRAM_TRANSACTION_H_
+
+#include <inttypes.h>
+#include <systemc>
+#include <cassert>
+#include "arithmetics.h"
+
+#define DEBUG_XRAM_TRANSACTION 0
+
+////////////////////////////////////////////////////////////////////////
+//                  A transaction tab entry         
+////////////////////////////////////////////////////////////////////////
+
+class TransactionTabEntry 
+{
+    typedef sc_dt::sc_uint<64>    wide_data_t;
+    typedef sc_dt::sc_uint<40>    addr_t;
+    typedef uint32_t              data_t;
+    typedef uint32_t              be_t;
+
+    public:
+    bool 		        valid;     	    // entry valid 
+    bool 		        xram_read; 	    // read request to XRAM
+    addr_t   	        nline;    	    // index (zy) of the requested line
+    size_t 	            srcid;     	    // processor requesting the transaction
+    size_t 	            trdid;     	    // processor requesting the transaction
+    size_t 	            pktid;     	    // processor requesting the transaction
+    bool 		        proc_read;	    // read request from processor
+    size_t 	            read_length;    // length of the read (for the response)
+    size_t 	            word_index;    	// index of the first read word (for the response)
+    std::vector<data_t> wdata;          // write buffer (one cache line)
+    std::vector<be_t>   wdata_be;    	// be for each data in the write buffer
+    bool                rerror;         // error returned by xram
+    data_t              ll_key;         // LL key returned by the llsc_global_table
+    bool                config;         // transaction required by CONFIG FSM
+
+    /////////////////////////////////////////////////////////////////////
+    // The init() function initializes the entry 
+    /////////////////////////////////////////////////////////////////////
+    void init()
+    {
+        valid		= false;
+        rerror      = false;
+        config      = false;
+    }
+
+    /////////////////////////////////////////////////////////////////////
+    // The alloc() function initializes the vectors of an entry
+    // Its arguments are :
+    // - n_words : number of words per line in the cache
+    /////////////////////////////////////////////////////////////////////
+    void alloc(size_t n_words)
+    {
+        wdata_be.reserve( (int)n_words );
+        wdata.reserve( (int)n_words );
+        for(size_t i=0; i<n_words; i++)
+        {
+            wdata_be.push_back(0);
+            wdata.push_back(0);
+        }
+    }
+
+    ////////////////////////////////////////////////////////////////////
+    // The copy() function copies an existing entry
+    // Its arguments are :
+    // - source : the transaction tab entry to copy
+    ////////////////////////////////////////////////////////////////////
+    void copy(const TransactionTabEntry &source)
+    {
+        valid	    = source.valid;
+        xram_read 	= source.xram_read;
+        nline	    = source.nline;
+        srcid	    = source.srcid;
+        trdid	    = source.trdid;
+        pktid	    = source.pktid;
+        proc_read 	= source.proc_read;
+        read_length = source.read_length;
+        word_index	= source.word_index;
+        wdata_be.assign(source.wdata_be.begin(),source.wdata_be.end());
+        wdata.assign(source.wdata.begin(),source.wdata.end());
+        rerror      = source.rerror;
+        ll_key      = source.ll_key;
+        config      = source.config;
+    }
+
+    ////////////////////////////////////////////////////////////////////
+    // The print() function prints the entry 
+    ////////////////////////////////////////////////////////////////////
+    void print()
+    {
+        std::cout << "------- TRT entry -------" << std::endl;
+        std::cout << "valid       = " << valid        << std::endl;
+        std::cout << "xram_read   = " << xram_read    << std::endl;
+        std::cout << "nline       = " << std::hex << nline << std::endl;
+        std::cout << "srcid       = " << srcid        << std::endl;
+        std::cout << "trdid       = " << trdid        << std::endl;
+        std::cout << "pktid       = " << pktid        << std::endl;
+        std::cout << "proc_read   = " << proc_read    << std::endl;
+        std::cout << "read_length = " << read_length  << std::endl;
+        std::cout << "word_index  = " << word_index   << std::endl; 
+        for(size_t i=0; i<wdata_be.size() ; i++)
+        {
+            std::cout << "wdata_be[" << std::dec << i << "] = " 
+                      << std::hex << wdata_be[i] << std::endl;
+        }
+        for(size_t i=0; i<wdata.size() ; i++)
+        {
+            std::cout << "wdata[" << std::dec << i << "] = " 
+                      << std::hex << wdata[i] << std::endl;
+        }
+        std::cout << "rerror      = " << rerror       << std::endl;
+        std::cout << "ll_key      = " << ll_key       << std::endl;
+        std::cout << "config      = " << config       << std::endl;
+        std::cout << std::endl;
+    }
+
+    /////////////////////////////////////////////////////////////////////
+    // 		Constructors
+    /////////////////////////////////////////////////////////////////////
+
+    TransactionTabEntry()
+    {
+        wdata_be.clear();
+        wdata.clear();
+        valid  = false;
+        rerror = false;
+        config = false;
+    }
+
+    TransactionTabEntry(const TransactionTabEntry &source)
+    {
+        valid	    = source.valid;
+        xram_read	= source.xram_read;
+        nline	    = source.nline;
+        srcid	    = source.srcid;
+        trdid	    = source.trdid;
+        pktid	    = source.pktid;
+        proc_read	= source.proc_read;
+        read_length = source.read_length;
+        word_index	= source.word_index;
+        wdata_be.assign(source.wdata_be.begin(),source.wdata_be.end());
+        wdata.assign(source.wdata.begin(),source.wdata.end());	
+        rerror      = source.rerror;
+        ll_key      = source.ll_key;
+        config      = source.config;
+    }
+
+}; // end class TransactionTabEntry
+
+////////////////////////////////////////////////////////////////////////
+//                  The transaction tab                              
+////////////////////////////////////////////////////////////////////////
+class TransactionTab
+{
+    typedef sc_dt::sc_uint<64>    wide_data_t;
+    typedef sc_dt::sc_uint<40>    addr_t;
+    typedef uint32_t              data_t;
+    typedef uint32_t              be_t;
+
+    private:
+    const std::string tab_name;                // the name for logs
+    size_t            size_tab;                // the size of the tab
+
+    data_t be_to_mask(be_t be)
+    {
+        data_t ret = 0;
+        if ( be&0x1 ) {
+            ret = ret | 0x000000FF;
+        }
+        if ( be&0x2 ) {
+            ret = ret | 0x0000FF00;
+        }
+        if ( be&0x4 ) {
+            ret = ret | 0x00FF0000;
+        }
+        if ( be&0x8 ) {
+            ret = ret | 0xFF000000;
+        }
+        return ret;
+    }
+
+    public:
+    TransactionTabEntry *tab;       // The transaction tab
+
+    ////////////////////////////////////////////////////////////////////
+    //		Constructors
+    ////////////////////////////////////////////////////////////////////
+    TransactionTab()
+    {
+        size_tab=0;
+        tab=NULL;
+    }
+
+    TransactionTab(const std::string &name,
+                   size_t            n_entries, 
+                   size_t            n_words )
+    : tab_name( name ),
+      size_tab( n_entries ) 
+    {
+        tab = new TransactionTabEntry[size_tab];
+        for ( size_t i=0; i<size_tab; i++) 
+        {
+            tab[i].alloc(n_words);
+        }
+    }
+
+    ~TransactionTab()
+    {
+        delete [] tab;
+    }
+    /////////////////////////////////////////////////////////////////////
+    // The size() function returns the size of the tab
+    /////////////////////////////////////////////////////////////////////
+    size_t size()
+    {
+        return size_tab;
+    }
+    /////////////////////////////////////////////////////////////////////
+    // The init() function initializes the transaction tab entries
+    /////////////////////////////////////////////////////////////////////
+    void init()
+    {
+        for ( size_t i=0; i<size_tab; i++) 
+        {
+            tab[i].init();
+        }
+    }
+    /////////////////////////////////////////////////////////////////////
+    // The print() function prints a transaction tab entry
+    // Arguments :
+    // - index : the index of the entry to print
+    /////////////////////////////////////////////////////////////////////
+    void print(const size_t index)
+    {
+        assert( (index < size_tab) and
+        "MEMC ERROR: The selected entry is out of range in TRT write_data_mask()");
+
+        tab[index].print();
+        return;
+    }
+    /////////////////////////////////////////////////////////////////////
+    // The read() function returns a transaction tab entry.
+    // Arguments :
+    // - index : the index of the entry to read
+    /////////////////////////////////////////////////////////////////////
+    TransactionTabEntry read(const size_t index)
+    {
+        assert( (index < size_tab) and 
+        "MEMC ERROR: Invalid Transaction Tab Entry");
+
+        return tab[index];
+    }
+    /////////////////////////////////////////////////////////////////////
+    // The full() function returns the state of the transaction tab
+    // Arguments :
+    // - index : (return argument) the index of an empty entry 
+    // The function returns true if the transaction tab is full
+    /////////////////////////////////////////////////////////////////////
+    bool full(size_t &index)
+    {
+        for(size_t i=0; i<size_tab; i++)
+        {
+            if(!tab[i].valid)
+            {
+                index=i;
+                return false;	
+            }
+        }
+        return true;
+    }
+    /////////////////////////////////////////////////////////////////////
+    // The hit_read() function checks if an XRAM read transaction exists 
+    // for a given cache line.
+    // Arguments :
+    // - index : (return argument) the index of the hit entry, if there is 
+    // - nline : the index (zy) of the requested line
+    // The function returns true if a read request has already been sent
+    //////////////////////////////////////////////////////////////////////
+    bool hit_read(const addr_t nline,size_t &index)
+    {
+        for(size_t i=0; i<size_tab; i++)
+        {
+            if((tab[i].valid && (nline==tab[i].nline)) && (tab[i].xram_read)) 
+            {
+                index=i;
+                return true;	
+            }
+        }
+        return false;
+    }
+    ///////////////////////////////////////////////////////////////////////
+    // The hit_write() function looks if an XRAM write transaction exists 
+    // for a given line.
+    // Arguments :
+    // - nline : the index (zy) of the requested line
+    // The function returns true if a write request has already been sent
+    ///////////////////////////////////////////////////////////////////////
+    bool hit_write(const addr_t nline)
+    {
+        for(size_t i=0; i<size_tab; i++)
+        {
+            if(tab[i].valid && (nline==tab[i].nline) && !(tab[i].xram_read)) 
+            {
+                return true;	
+            }
+        }
+        return false;
+    }
+
+    ///////////////////////////////////////////////////////////////////////
+    // The hit_write() function looks if an XRAM write transaction exists 
+    // for a given line.
+    // Arguments :
+    // - index : (return argument) the index of the hit entry, if there is
+    // - nline : the index (zy) of the requested line
+    // The function returns true if a write request has already been sent
+    ///////////////////////////////////////////////////////////////////////
+    bool hit_write(const addr_t nline, size_t* index)
+    {
+        for(size_t i=0; i<size_tab; i++){
+            if(tab[i].valid && (nline==tab[i].nline) && !(tab[i].xram_read)) {
+                *index = i;
+                return true;	
+            }
+        }
+        return false;
+    }
+    /////////////////////////////////////////////////////////////////////
+    // The write_data_mask() function writes a vector of data (a line).
+    // The data is written only if the corresponding bits are set
+    // in the be vector. 
+    // Arguments :
+    // - index : the index of the request in the transaction tab
+    // - be   : vector of be 
+    // - data : vector of data
+    /////////////////////////////////////////////////////////////////////
+    void write_data_mask(const size_t index, 
+            const std::vector<be_t> &be, 
+            const std::vector<data_t> &data) 
+    {
+        assert( (index < size_tab) and
+        "MEMC ERROR: The selected entry is out of range in TRT write_data_mask()");
+
+        assert( (be.size()==tab[index].wdata_be.size()) and
+        "MEMC ERROR: Bad be size in TRT write_data_mask()");
+
+        assert( (data.size()==tab[index].wdata.size()) and
+        "MEMC ERROR: Bad data size in TRT write_data_mask()");
+
+        for(size_t i=0; i<tab[index].wdata_be.size() ; i++) 
+        {
+            tab[index].wdata_be[i] = tab[index].wdata_be[i] | be[i];
+            data_t mask = be_to_mask(be[i]);
+            tab[index].wdata[i] = (tab[index].wdata[i] & ~mask) | (data[i] & mask);
+        }
+    }
+    /////////////////////////////////////////////////////////////////////
+    // The set() function registers a transaction (read or write)
+    // to the XRAM in the transaction tab.
+    // Arguments :
+    // - index : index in the transaction tab
+    // - xram_read : transaction type (read or write a cache line)
+    // - nline : the index (zy) of the cache line
+    // - srcid : srcid of the initiator that caused the transaction
+    // - trdid : trdid of the initiator that caused the transaction
+    // - pktid : pktid of the initiator that caused the transaction
+    // - proc_read : does the initiator want a copy
+    // - read_length : length of read (in case of processor read)
+    // - word_index : index in the line (in case of single word read)
+    // - data : the data to write (in case of write)
+    // - data_be : the mask of the data to write (in case of write)
+    // - ll_key  : the ll key (if any) returned by the llsc_global_table
+    // - config  : transaction required by config FSM
+    /////////////////////////////////////////////////////////////////////
+    void set(const size_t index,
+            const bool xram_read,
+            const addr_t nline,
+            const size_t srcid,
+            const size_t trdid,
+            const size_t pktid,
+            const bool proc_read,
+            const size_t read_length,
+            const size_t word_index,
+            const std::vector<be_t> &data_be,
+            const std::vector<data_t> &data, 
+            const data_t ll_key = 0,
+            const bool config = false) 
+    {
+        assert( (index < size_tab) and
+        "MEMC ERROR: The selected entry is out of range in TRT set()");
+
+        assert( (data_be.size()==tab[index].wdata_be.size()) and 
+        "MEMC ERROR: Bad data_be argument in TRT set()");
+
+        assert( (data.size()==tab[index].wdata.size()) and 
+        "MEMC ERROR: Bad data argument in TRT set()");
+
+        tab[index].valid	        = true;
+        tab[index].xram_read        = xram_read;
+        tab[index].nline	        = nline;
+        tab[index].srcid	        = srcid;
+        tab[index].trdid	        = trdid;
+        tab[index].pktid	        = pktid;
+        tab[index].proc_read	    = proc_read;
+        tab[index].read_length	    = read_length;
+        tab[index].word_index	    = word_index;
+        tab[index].ll_key   	    = ll_key;
+        tab[index].config           = config;
+        for(size_t i=0; i<tab[index].wdata.size(); i++) 
+        {
+            tab[index].wdata_be[i]    = data_be[i];
+            tab[index].wdata[i]       = data[i];
+        }
+    }
+
+    /////////////////////////////////////////////////////////////////////
+    // The write_rsp() function writes two 32 bits words of the response 
+    // to a XRAM read transaction.
+    // The BE field in TRT is taken into account.
+    // Arguments :
+    // - index : index of the entry in TRT
+    // - word  : index of the 32 bits word in the line
+    // - data  : 64 bits value (first data right)
+    /////////////////////////////////////////////////////////////////////
+    void write_rsp(const size_t      index,
+                   const size_t      word,
+                   const wide_data_t data)
+    {
+        data_t  value;
+        data_t  mask;
+
+        assert( (index < size_tab) and
+        "MEMC ERROR: The selected entry is out of range in TRT write_rsp()");
+
+        assert( (word < tab[index].wdata_be.size()) and 
+        "MEMC ERROR: Bad word index in TRT write_rsp()");
+
+        assert( (tab[index].valid) and
+        "MEMC ERROR: TRT entry not valid in TRT write_rsp()");
+
+        assert( (tab[index].xram_read ) and
+        "MEMC ERROR: TRT entry is not a GET in TRT write_rsp()");
+
+        // first 32 bits word
+        value = (data_t)data;
+        mask  = be_to_mask(tab[index].wdata_be[word]);
+        tab[index].wdata[word] = (tab[index].wdata[word] & mask) | (value & ~mask);
+
+        // second 32 bits word
+        value = (data_t)(data>>32);
+        mask  = be_to_mask(tab[index].wdata_be[word+1]);
+        tab[index].wdata[word+1] = (tab[index].wdata[word+1] & mask) | (value & ~mask);
+    }
+    /////////////////////////////////////////////////////////////////////
+    // The erase() function erases an entry in the transaction tab.
+    // Arguments :
+    // - index : the index of the request in the transaction tab
+    /////////////////////////////////////////////////////////////////////
+    void erase(const size_t index)
+    {
+        assert( (index < size_tab) and 
+        "MEMC ERROR: The selected entry is out of range in TRT erase()");
+
+        tab[index].valid	= false;
+        tab[index].rerror   = false;
+    }
+    /////////////////////////////////////////////////////////////////////
+    // The is_config() function returns the config flag value.
+    // Arguments :
+    // - index : the index of the entry in the transaction tab
+    /////////////////////////////////////////////////////////////////////
+    bool is_config(const size_t index)
+    {
+        assert( (index < size_tab) and
+        "MEMC ERROR: The selected entry is out of range in TRT is_config()");
+
+        return tab[index].config;
+    }
+}; // end class TransactionTab
+
+#endif
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: /branches/MESI/modules/vci_mem_cache/caba/source/src/vci_mem_cache.cpp
===================================================================
--- /branches/MESI/modules/vci_mem_cache/caba/source/src/vci_mem_cache.cpp	(revision 670)
+++ /branches/MESI/modules/vci_mem_cache/caba/source/src/vci_mem_cache.cpp	(revision 670)
@@ -0,0 +1,11996 @@
+/* -*- c++ -*-
+*
+* File       : vci_mem_cache.cpp
+* Date       : 30/10/2008
+* Copyright  : UPMC / LIP6
+* Authors    : Alain Greiner / Eric Guthmuller
+*
+* SOCLIB_LGPL_HEADER_BEGIN
+*
+* This file is part of SoCLib, GNU LGPLv2.1.
+*
+                    break;
+* SoCLib is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as published
+* by the Free Software Foundation; version 2.1 of the License.
+*
+* SoCLib is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with SoCLib; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+* SOCLIB_LGPL_HEADER_END
+*
+* Maintainers: alain.greiner@lip6.fr
+*              eric.guthmuller@polytechnique.edu
+*              cesar.fuguet-tortolero@lip6.fr
+*              alexandre.joannou@lip6.fr
+*/
+
+#include "../include/vci_mem_cache.h"
+
+//////   debug services   /////////////////////////////////////////////////////////////
+// All debug messages are conditionned by two variables:
+// - compile time   : DEBUG_MEMC_*** : defined below
+// - execution time : m_debug  = (m_debug_ok) and (m_cpt_cycle > m_debug_start_cycle)
+///////////////////////////////////////////////////////////////////////////////////////
+
+#define DEBUG_MEMC_GLOBAL    0 // synthetic trace of all FSMs
+#define DEBUG_MEMC_CONFIG    1 // detailed trace of CONFIG FSM
+#define DEBUG_MEMC_READ      1 // detailed trace of READ FSM
+#define DEBUG_MEMC_WRITE     1 // detailed trace of WRITE FSM
+#define DEBUG_MEMC_CAS       1 // detailed trace of CAS FSM
+#define DEBUG_MEMC_IXR_CMD   1 // detailed trace of IXR_CMD FSM
+#define DEBUG_MEMC_IXR_RSP   1 // detailed trace of IXR_RSP FSM
+#define DEBUG_MEMC_XRAM_RSP  1 // detailed trace of XRAM_RSP FSM
+#define DEBUG_MEMC_CC_SEND   1 // detailed trace of CC_SEND FSM
+#define DEBUG_MEMC_MULTI_ACK 1 // detailed trace of MULTI_ACK FSM
+#define DEBUG_MEMC_TGT_CMD   1 // detailed trace of TGT_CMD FSM
+#define DEBUG_MEMC_TGT_RSP   1 // detailed trace of TGT_RSP FSM
+#define DEBUG_MEMC_CLEANUP   1 // detailed trace of CLEANUP FSM
+
+#define RANDOMIZE_CAS        1
+
+namespace soclib { namespace caba {
+
+    const char *tgt_cmd_fsm_str[] =
+    {
+        "TGT_CMD_IDLE",
+        "TGT_CMD_READ",
+        "TGT_CMD_WRITE",
+        "TGT_CMD_CAS",
+        "TGT_CMD_ERROR",
+        "TGT_CMD_CONFIG"
+    };
+    const char *tgt_rsp_fsm_str[] =
+    {
+        "TGT_RSP_CONFIG_IDLE",
+        "TGT_RSP_TGT_CMD_IDLE",
+        "TGT_RSP_READ_IDLE",
+        "TGT_RSP_WRITE_IDLE",
+        "TGT_RSP_CAS_IDLE",
+        "TGT_RSP_XRAM_IDLE",
+        "TGT_RSP_MULTI_ACK_IDLE",
+        "TGT_RSP_CLEANUP_IDLE",
+        "TGT_RSP_CONFIG",
+        "TGT_RSP_TGT_CMD",
+        "TGT_RSP_READ",
+        "TGT_RSP_WRITE",
+        "TGT_RSP_CLEANUP",
+        "TGT_RSP_CAS",
+        "TGT_RSP_XRAM",
+        "TGT_RSP_MULTI_ACK"
+    };
+    const char *cc_receive_fsm_str[] =
+    {
+        "CC_RECEIVE_IDLE",
+        "CC_RECEIVE_CLEANUP",
+        "CC_RECEIVE_CLEANUP_EOP",
+        "CC_RECEIVE_MULTI_ACK"
+    };
+    const char *cc_send_fsm_str[] =
+    {
+        "CC_SEND_CONFIG_IDLE",
+        "CC_SEND_WRITE_IDLE",
+        "CC_SEND_XRAM_RSP_IDLE",
+        "CC_SEND_CAS_IDLE",
+        "CC_SEND_READ_IDLE",
+        "CC_SEND_CONFIG_INVAL_HEADER",
+        "CC_SEND_CONFIG_INVAL_NLINE",
+        "CC_SEND_CONFIG_BRDCAST_HEADER",
+        "CC_SEND_CONFIG_BRDCAST_NLINE",
+        "CC_SEND_XRAM_RSP_INVAL_HEADER",
+        "CC_SEND_XRAM_RSP_INVAL_NLINE",
+        "CC_SEND_XRAM_RSP_BRDCAST_HEADER",
+        "CC_SEND_XRAM_RSP_BRDCAST_NLINE",
+        "CC_SEND_READ_BRDCAST_HEADER",
+        "CC_SEND_READ_BRDCAST_NLINE",
+        "CC_SEND_READ_MULTI_HEADER",
+        "CC_SEND_READ_MULTI_NLINE",
+        "CC_SEND_WRITE_BRDCAST_HEADER",
+        "CC_SEND_WRITE_BRDCAST_NLINE",
+        "CC_SEND_WRITE_INVAL_HEADER",
+        "CC_SEND_WRITE_INVAL_NLINE",
+        "CC_SEND_CAS_BRDCAST_HEADER",
+        "CC_SEND_CAS_BRDCAST_NLINE",
+        "CC_SEND_CAS_INVAL_HEADER",
+        "CC_SEND_CAS_INVAL_NLINE"
+    };
+    const char *multi_ack_fsm_str[] =
+    {
+        "MULTI_ACK_IDLE",
+        "MULTI_ACK_GET_DATA",
+        "MULTI_ACK_IVT_LOCK",
+        "MULTI_ACK_IVT_CLEAR",
+        "MULTI_ACK_DIR_REQ",
+        "MULTI_ACK_DIR_LOCK",
+        "MULTI_ACK_DIR_UPDT",
+        "MULTI_ACK_RSP",
+        "MULTI_ACK_HEAP_REQ",
+        "MULTI_ACK_HEAP_LOCK",
+        "MULTI_ACK_HEAP_WRITE",
+        "MULTI_ACK_WAIT"
+    };
+    const char *config_fsm_str[] =
+    {
+        "CONFIG_IDLE",
+        "CONFIG_LOOP",
+        "CONFIG_WAIT",
+        "CONFIG_RSP",
+        "CONFIG_DIR_REQ",
+        "CONFIG_DIR_ACCESS",
+        "CONFIG_IVT_LOCK",
+        "CONFIG_BC_SEND",
+        "CONFIG_INVAL_SEND",
+        "CONFIG_HEAP_REQ",
+        "CONFIG_HEAP_SCAN",
+        "CONFIG_HEAP_LAST",
+        "CONFIG_TRT_LOCK",
+        "CONFIG_TRT_SET",
+        "CONFIG_PUT_REQ"
+    };
+    const char *read_fsm_str[] =
+    {
+        "READ_IDLE",
+        "READ_DIR_REQ",
+        "READ_DIR_LOCK",
+        "READ_IVT_INVAL_LOCK",
+        "READ_INVAL_HEAP_REQ",
+        "READ_INVAL_HEAP_ERASE",
+        "READ_INVAL_HEAP_LAST",
+        "READ_IVT_UPDT_LOCK",
+        "READ_WAIT",
+        "READ_DIR_HIT", 
+        "READ_HEAP_REQ",
+        "READ_HEAP_LOCK",
+        "READ_HEAP_WRITE",
+        "READ_HEAP_ERASE",
+        "READ_HEAP_LAST",
+        "READ_RSP",
+        "READ_TRT_LOCK",
+        "READ_TRT_SET",
+        "READ_TRT_REQ"
+    };
+    const char *write_fsm_str[] =
+    {
+        "WRITE_IDLE",
+        "WRITE_NEXT",
+        "WRITE_DIR_REQ",
+        "WRITE_DIR_LOCK",
+        "WRITE_DIR_HIT",
+        "WRITE_HEAP_REQ",
+        "WRITE_HEAP_ERASE",
+        "WRITE_HEAP_LAST",
+        "WRITE_RSP",
+        "WRITE_MISS_TRT_LOCK",
+        "WRITE_WAIT",
+        "WRITE_MISS_TRT_SET",
+        "WRITE_MISS_TRT_DATA",
+        "WRITE_MISS_XRAM_REQ",
+        "WRITE_INVAL_TRT_LOCK",
+        "WRITE_INVAL_IVT_LOCK",
+        "WRITE_DIR_INVAL",
+        "WRITE_INVAL_CC_SEND",
+        "WRITE_INVAL_XRAM_REQ"
+    };
+    const char *ixr_rsp_fsm_str[] =
+    {
+        "IXR_RSP_IDLE",
+        "IXR_RSP_ACK",
+        "IXR_RSP_TRT_ERASE",
+        "IXR_RSP_TRT_READ"
+    };
+    const char *xram_rsp_fsm_str[] =
+    {
+        "XRAM_RSP_IDLE",
+        "XRAM_RSP_TRT_COPY",
+        "XRAM_RSP_TRT_DIRTY",
+        "XRAM_RSP_DIR_LOCK",
+        "XRAM_RSP_DIR_UPDT",
+        "XRAM_RSP_DIR_RSP",
+        "XRAM_RSP_IVT_LOCK",
+        "XRAM_RSP_INVAL_WAIT",
+        "XRAM_RSP_INVAL",
+        "XRAM_RSP_WRITE_DIRTY",
+        "XRAM_RSP_HEAP_REQ",
+        "XRAM_RSP_HEAP_ERASE",
+        "XRAM_RSP_HEAP_LAST",
+        "XRAM_RSP_ERROR_ERASE",
+        "XRAM_RSP_ERROR_RSP"
+    };
+    const char *ixr_cmd_fsm_str[] =
+    {
+        "IXR_CMD_READ_IDLE",
+        "IXR_CMD_WRITE_IDLE",
+        "IXR_CMD_CAS_IDLE",
+        "IXR_CMD_XRAM_IDLE",
+        "IXR_CMD_CLEANUP_IDLE",
+        "IXR_CMD_CONFIG_IDLE",
+        "IXR_CMD_READ_TRT",
+        "IXR_CMD_WRITE_TRT",
+        "IXR_CMD_CAS_TRT",
+        "IXR_CMD_XRAM_TRT",
+        "IXR_CMD_CLEANUP_TRT",
+        "IXR_CMD_CONFIG_TRT",
+        "IXR_CMD_READ_SEND",
+        "IXR_CMD_WRITE_SEND",
+        "IXR_CMD_CAS_SEND",
+        "IXR_CMD_XRAM_SEND",
+        "IXR_CMD_CLEANUP_DATA_SEND",
+        "IXR_CMD_CONFIG_SEND"
+    };
+    const char *cas_fsm_str[] =
+    {
+        "CAS_IDLE",
+        "CAS_DIR_REQ",
+        "CAS_DIR_LOCK",
+        "CAS_DIR_HIT_READ",
+        "CAS_DIR_HIT_COMPARE",
+        "CAS_DIR_HIT_WRITE",
+        "CAS_MULTI_INVAL_IVT_LOCK",
+        "CAS_WAIT",
+        "CAS_MULTI_INVAL_HEAP_LOCK",
+        "CAS_MULTI_INVAL_REQ",
+        "CAS_HEAP_NEXT",
+        "CAS_HEAP_LAST",
+        "CAS_BC_TRT_LOCK",
+        "CAS_BC_IVT_LOCK",
+        "CAS_BC_DIR_INVAL",
+        "CAS_BC_CC_SEND",
+        "CAS_BC_XRAM_REQ",
+        "CAS_RSP_FAIL",
+        "CAS_RSP_SUCCESS",
+        "CAS_MISS_TRT_LOCK",
+        "CAS_MISS_TRT_SET",
+        "CAS_MISS_XRAM_REQ"
+    };
+    const char *cleanup_fsm_str[] =
+    {
+        "CLEANUP_IDLE",
+        "CLEANUP_GET_NLINE",
+        "CLEANUP_GET_DATA",
+        "CLEANUP_DIR_REQ",
+        "CLEANUP_DIR_LOCK",
+        "CLEANUP_DIR_WRITE",
+        "CLEANUP_LOCKED_IVT_LOCK",
+        "CLEANUP_LOCKED_IVT_DECREMENT",
+        "CLEANUP_LOCKED_IVT_CLEAR",   
+        "CLEANUP_LOCKED_RSP",
+        "CLEANUP_HEAP_REQ",
+        "CLEANUP_HEAP_LOCK",
+        "CLEANUP_HEAP_SEARCH",
+        "CLEANUP_HEAP_CLEAN",
+        "CLEANUP_HEAP_FREE",
+        "CLEANUP_MISS_IVT_LOCK",
+        "CLEANUP_MISS_IVT_DECREMENT",
+        "CLEANUP_MISS_IVT_CLEAR",
+        "CLEANUP_MISS_RSP",
+        "CLEANUP_MISS_IXR_REQ",
+        "CLEANUP_WAIT",
+        "CLEANUP_SEND_CLACK"
+    };
+    const char *alloc_dir_fsm_str[] =
+    {
+        "ALLOC_DIR_RESET",
+        "ALLOC_DIR_READ",
+        "ALLOC_DIR_WRITE",
+        "ALLOC_DIR_CAS",
+        "ALLOC_DIR_CLEANUP",
+        "ALLOC_DIR_XRAM_RSP",
+        "ALLOC_DIR_MULTI_ACK",
+        "ALLOC_DIR_CONFIG"
+    };
+    const char *alloc_trt_fsm_str[] =
+    {
+        "ALLOC_TRT_READ",
+        "ALLOC_TRT_WRITE",
+        "ALLOC_TRT_CAS",
+        "ALLOC_TRT_XRAM_RSP",
+        "ALLOC_TRT_IXR_RSP",
+        "ALLOC_TRT_CLEANUP",
+        "ALLOC_TRT_IXR_CMD",
+        "ALLOC_TRT_CONFIG"
+    };
+//    const char *alloc_upt_fsm_str[] =
+//    {
+//        "ALLOC_UPT_WRITE",
+//        "ALLOC_UPT_CAS",
+//        "ALLOC_UPT_MULTI_ACK"
+//    };
+    const char *alloc_ivt_fsm_str[] =
+    {
+        "ALLOC_IVT_WRITE",
+        "ALLOC_IVT_READ",
+        "ALLOC_IVT_XRAM_RSP",
+        "ALLOC_IVT_CLEANUP",
+        "ALLOC_IVT_CAS",
+        "ALLOC_IVT_CONFIG",
+        "ALLOC_IVT_MULTI_ACK"
+    };
+    const char *alloc_heap_fsm_str[] =
+    {
+        "ALLOC_HEAP_RESET",
+        "ALLOC_HEAP_READ",
+        "ALLOC_HEAP_WRITE",
+        "ALLOC_HEAP_CAS",
+        "ALLOC_HEAP_CLEANUP",
+        "ALLOC_HEAP_MULTI_ACK",
+        "ALLOC_HEAP_XRAM_RSP",
+        "ALLOC_HEAP_CONFIG"
+    };
+
+#define tmpl(x) \
+    template<typename vci_param_int, \
+    typename vci_param_ext, \
+    size_t dspin_in_width,  \
+    size_t dspin_out_width> x \
+    VciMemCache<vci_param_int, vci_param_ext, dspin_in_width, dspin_out_width>
+
+    using namespace soclib::common;
+
+    ////////////////////////////////
+    //  Constructor
+    ////////////////////////////////
+
+    tmpl(/**/) ::VciMemCache(
+            sc_module_name      name,
+            const MappingTable  &mtp,              // mapping table for direct network
+            const MappingTable  &mtx,              // mapping table for external network
+            const IntTab        &srcid_x,          // global index on external network
+            const IntTab        &tgtid_d,          // global index on direct network
+            const size_t        cc_global_id,      // global index on cc network
+            const size_t        x_width,           // number of x bits in platform
+            const size_t        y_width,           // number of x bits in platform
+            const size_t        nways,             // number of ways per set
+            const size_t        nsets,             // number of associative sets
+            const size_t        nwords,            // number of words in cache line
+            const size_t        max_copies,        // max number of copies in heap
+            const size_t        heap_size,         // number of heap entries
+            const size_t        trt_lines,         // number of TRT entries
+            const size_t        upt_lines,         // number of UPT entries
+            const size_t        ivt_lines,         // number of IVT entries
+            const size_t        debug_start_cycle,
+            const bool          debug_ok)
+
+        : soclib::caba::BaseModule(name),
+
+        p_clk( "p_clk" ),
+        p_resetn( "p_resetn" ),
+        p_irq( "p_irq" ),
+        p_vci_tgt( "p_vci_tgt" ),
+        p_vci_ixr( "p_vci_ixr" ),
+        p_dspin_p2m( "p_dspin_p2m" ),
+        p_dspin_m2p( "p_dspin_m2p" ),
+        p_dspin_clack( "p_dspin_clack" ),
+
+        m_seglist( mtp.getSegmentList(tgtid_d) ),
+        m_nseg( 0 ),
+        m_srcid_x( mtx.indexForId(srcid_x) ),
+        m_initiators( 1 << vci_param_int::S ),
+        m_heap_size( heap_size ),
+        m_ways( nways ),
+        m_sets( nsets ),
+        m_words( nwords ),
+        m_cc_global_id( cc_global_id ),
+        m_xwidth(x_width),
+        m_ywidth(y_width),
+        m_debug_start_cycle( debug_start_cycle ),
+        m_debug_ok( debug_ok ),
+        m_trt_lines(trt_lines),
+        m_trt(this->name(), trt_lines, nwords),
+        m_upt_lines(upt_lines),
+        m_upt(upt_lines),
+        m_ivt(ivt_lines),
+        m_cache_directory(nways, nsets, nwords, vci_param_int::N),
+        m_cache_data(nways, nsets, nwords),
+        m_heap(m_heap_size),
+        m_max_copies( max_copies ),
+        m_llsc_table(),
+
+#define L2 soclib::common::uint32_log2
+        m_x(L2(m_words), 2),
+        m_y(L2(m_sets), L2(m_words) + 2),
+        m_z(vci_param_int::N - L2(m_sets) - L2(m_words) - 2, L2(m_sets) + L2(m_words) + 2),
+        m_nline(vci_param_int::N - L2(m_words) - 2, L2(m_words) + 2),
+#undef L2
+
+        // XMIN(5 bits) / XMAX(5 bits) / YMIN(5 bits) / YMAX(5 bits)
+        //   0b00000    /   0b11111    /   0b00000    /   0b11111
+        m_broadcast_boundaries(0x7C1F),
+
+        // CONFIG interface
+        m_config_addr_mask((1<<12)-1),
+
+        m_config_regr_width(7),
+        m_config_func_width(3),
+        m_config_regr_idx_mask((1<<m_config_regr_width)-1),
+        m_config_func_idx_mask((1<<m_config_func_width)-1),
+
+        //  FIFOs
+        m_cmd_read_addr_fifo("m_cmd_read_addr_fifo", 4),
+        m_cmd_read_length_fifo("m_cmd_read_length_fifo", 4),
+        m_cmd_read_srcid_fifo("m_cmd_read_srcid_fifo", 4),
+        m_cmd_read_trdid_fifo("m_cmd_read_trdid_fifo", 4),
+        m_cmd_read_pktid_fifo("m_cmd_read_pktid_fifo", 4),
+
+        m_cmd_write_addr_fifo("m_cmd_write_addr_fifo",8),
+        m_cmd_write_eop_fifo("m_cmd_write_eop_fifo",8),
+        m_cmd_write_srcid_fifo("m_cmd_write_srcid_fifo",8),
+        m_cmd_write_trdid_fifo("m_cmd_write_trdid_fifo",8),
+        m_cmd_write_pktid_fifo("m_cmd_write_pktid_fifo",8),
+        m_cmd_write_data_fifo("m_cmd_write_data_fifo",8),
+        m_cmd_write_be_fifo("m_cmd_write_be_fifo",8),
+
+        m_cmd_cas_addr_fifo("m_cmd_cas_addr_fifo",4),
+        m_cmd_cas_eop_fifo("m_cmd_cas_eop_fifo",4),
+        m_cmd_cas_srcid_fifo("m_cmd_cas_srcid_fifo",4),
+        m_cmd_cas_trdid_fifo("m_cmd_cas_trdid_fifo",4),
+        m_cmd_cas_pktid_fifo("m_cmd_cas_pktid_fifo",4),
+        m_cmd_cas_wdata_fifo("m_cmd_cas_wdata_fifo",4),
+
+        m_cc_receive_to_cleanup_fifo("m_cc_receive_to_cleanup_fifo", 4),
+        m_cc_receive_to_multi_ack_fifo("m_cc_receive_to_multi_ack_fifo", 4),
+
+        r_tgt_cmd_fsm("r_tgt_cmd_fsm"),
+
+        r_config_fsm( "r_config_fsm" ),
+
+        m_config_to_cc_send_inst_fifo( "m_config_to_cc_send_inst_fifo", 8 ),
+        m_config_to_cc_send_srcid_fifo( "m_config_to_cc_send_srcid_fifo", 8 ),
+
+        r_read_fsm( "r_read_fsm" ),
+
+        r_write_fsm( "r_write_fsm" ),
+
+        m_write_to_cc_send_inst_fifo("m_write_to_cc_send_inst_fifo",8),
+        m_write_to_cc_send_srcid_fifo("m_write_to_cc_send_srcid_fifo",8),
+
+        r_multi_ack_fsm("r_multi_ack_fsm"),
+
+        r_cleanup_fsm("r_cleanup_fsm"),
+
+        r_cas_fsm("r_cas_fsm"),
+
+        m_cas_to_cc_send_inst_fifo("m_cas_to_cc_send_inst_fifo",8),
+        m_cas_to_cc_send_srcid_fifo("m_cas_to_cc_send_srcid_fifo",8),
+
+        m_read_to_cc_send_inst_fifo("m_read_to_cc_send_inst_fifo",8),
+        m_read_to_cc_send_srcid_fifo("m_read_to_cc_send_srcid_fifo",8),
+
+        r_ixr_rsp_fsm("r_ixr_rsp_fsm"),
+        r_xram_rsp_fsm("r_xram_rsp_fsm"),
+
+        m_xram_rsp_to_cc_send_inst_fifo("m_xram_rsp_to_cc_send_inst_fifo",8),
+        m_xram_rsp_to_cc_send_srcid_fifo("m_xram_rsp_to_cc_send_srcid_fifo",8),
+
+        r_ixr_cmd_fsm("r_ixr_cmd_fsm"),
+
+        r_tgt_rsp_fsm("r_tgt_rsp_fsm"),
+
+        r_cc_send_fsm("r_cc_send_fsm"),
+        r_cc_receive_fsm("r_cc_receive_fsm"),
+
+        r_alloc_dir_fsm("r_alloc_dir_fsm"),
+        r_alloc_dir_reset_cpt("r_alloc_dir_reset_cpt"),
+        r_alloc_trt_fsm("r_alloc_trt_fsm"),
+//        r_alloc_upt_fsm("r_alloc_upt_fsm"),
+        r_alloc_ivt_fsm("r_alloc_ivt_fsm"),
+        r_alloc_heap_fsm("r_alloc_heap_fsm"),
+        r_alloc_heap_reset_cpt("r_alloc_heap_reset_cpt")
+#if MONITOR_MEMCACHE_FSM == 1
+        ,
+        p_read_fsm("p_read_fsm"), 
+        p_write_fsm("p_write_fsm"), 
+        p_xram_rsp_fsm("p_xram_rsp_fsm"), 
+        p_cas_fsm("p_cas_fsm"), 
+        p_cleanup_fsm("p_cleanup_fsm"), 
+        p_config_fsm("p_config_fsm"), 
+        p_alloc_heap_fsm("p_alloc_heap_fsm"), 
+        p_alloc_dir_fsm("p_alloc_dir_fsm"), 
+        p_alloc_trt_fsm("p_alloc_trt_fsm"), 
+        p_alloc_upt_fsm("p_alloc_upt_fsm"), 
+        p_alloc_ivt_fsm("p_alloc_ivt_fsm"), 
+        p_tgt_cmd_fsm("p_tgt_cmd_fsm"), 
+        p_tgt_rsp_fsm("p_tgt_rsp_fsm"), 
+        p_ixr_cmd_fsm("p_ixr_cmd_fsm"), 
+        p_ixr_rsp_fsm("p_ixr_rsp_fsm"), 
+        p_cc_send_fsm("p_cc_send_fsm"), 
+        p_cc_receive_fsm("p_cc_receive_fsm"),
+        p_multi_ack_fsm("p_multi_ack_fsm")
+#endif
+        {
+            std::cout << "  - Building VciMemCache : " << name << std::endl;
+
+            assert(IS_POW_OF_2(nsets));
+            assert(IS_POW_OF_2(nwords));
+            assert(IS_POW_OF_2(nways));
+            assert(nsets);
+            assert(nwords);
+            assert(nways);
+
+            // check Transaction table size
+            assert((uint32_log2(trt_lines) <= vci_param_ext::T) and
+                    "MEMC ERROR : Need more bits for VCI TRDID field");
+
+            // check internal and external data width
+            assert( (vci_param_int::B == 4 ) and
+                    "MEMC ERROR : VCI internal data width must be 32 bits");
+
+            assert( (vci_param_ext::B == 8) and
+                    "MEMC ERROR : VCI external data width must be 64 bits");
+
+            // Check coherence between internal & external addresses
+            assert( (vci_param_int::N == vci_param_ext::N) and
+                    "MEMC ERROR : VCI internal & external addresses must have the same width");
+
+            // Get the segments associated to the MemCache
+            std::list<soclib::common::Segment>::iterator seg;
+            size_t i = 0;
+
+            for(seg = m_seglist.begin(); seg != m_seglist.end() ; seg++)
+            {
+                std::cout << "    => segment " << seg->name()
+                    << " / base = " << std::hex << seg->baseAddress()
+                    << " / size = " << seg->size() << std::endl;
+                m_nseg++;
+            }
+
+            m_seg = new soclib::common::Segment*[m_nseg];
+
+            for(seg = m_seglist.begin() ; seg != m_seglist.end() ; seg++)
+            {
+                if ( seg->special() ) m_seg_config = i;
+                m_seg[i] = & (*seg);
+                i++;
+            }
+
+            // Allocation for IXR_RSP FSM
+            r_ixr_rsp_to_xram_rsp_rok  = new sc_signal<bool>[m_trt_lines];
+
+            // Allocation for XRAM_RSP FSM
+            r_xram_rsp_victim_data     = new sc_signal<data_t>[nwords];
+            r_xram_rsp_to_tgt_rsp_data = new sc_signal<data_t>[nwords];
+            //r_xram_rsp_to_ixr_cmd_data = new sc_signal<data_t>[nwords];
+
+            // Allocation for READ FSM
+            r_read_data                = new sc_signal<data_t>[nwords];
+            r_read_to_tgt_rsp_data     = new sc_signal<data_t>[nwords];
+
+            // Allocation for WRITE FSM
+            r_write_data               = new sc_signal<data_t>[nwords];
+            r_write_be                 = new sc_signal<be_t>[nwords];
+            r_write_to_cleanup_data    = new sc_signal<data_t>[nwords];
+            r_write_to_cleanup_be      = new sc_signal<be_t>[nwords];
+            //r_write_to_ixr_cmd_data    = new sc_signal<data_t>[nwords];
+
+            // Allocation for CAS FSM
+            //r_cas_to_ixr_cmd_data      = new sc_signal<data_t>[nwords];
+            r_cas_data                 = new sc_signal<data_t>[nwords];
+            r_cas_rdata                = new sc_signal<data_t>[2];
+
+            // Allocation for IXR_CMD FSM
+            r_ixr_cmd_wdata            = new sc_signal<data_t>[nwords];
+
+            // Allocation for RWT
+            r_multi_ack_data           = new sc_signal<data_t>[nwords];
+            r_debug_data               = new sc_signal<data_t>[nwords];
+            r_multi_ack_to_tgt_rsp_data  = new sc_signal<data_t>[nwords];
+            r_cleanup_data             = new sc_signal<data_t>[nwords];
+            r_cleanup_to_ixr_cmd_data  = new sc_signal<data_t>[nwords];
+            r_cleanup_to_tgt_rsp_data  = new sc_signal<data_t>[nwords];
+            r_cleanup_old_data         = new sc_signal<data_t>[nwords];
+
+            // Allocation for debug
+            m_debug_previous_data      = new data_t[nwords];
+            m_debug_data               = new data_t[nwords];
+
+            SC_METHOD(transition);
+            dont_initialize();
+            sensitive << p_clk.pos();
+
+            SC_METHOD(genMoore);
+            dont_initialize();
+            sensitive << p_clk.neg();
+        } // end constructor
+
+    /////////////////////////////////////////////////////
+    tmpl(void) ::cache_monitor(addr_t addr)
+        /////////////////////////////////////////////////////
+    {
+        size_t way = 0;
+        size_t set = 0;
+        DirectoryEntry entry = m_cache_directory.read_neutral(addr, &way, &set );
+
+        bool data_change = false;
+
+        if ( entry.state != ENTRY_INVALID )
+        {
+            for ( size_t word = 0 ; word<m_words ; word++ )
+            {
+                m_debug_data[word] = m_cache_data.read(way, set, word);
+                if ( (m_debug_previous_valid != ENTRY_INVALID) and 
+                        (m_debug_data[word] != m_debug_previous_data[word]) )
+                {
+                    data_change = true;
+                }
+            }
+        }
+
+        // print values if any change
+        if ( (entry.state != m_debug_previous_valid) or
+                ((entry.state != ENTRY_INVALID) and (entry.count != m_debug_previous_count)) or
+                ((entry.state != ENTRY_INVALID) and (entry.dirty != m_debug_previous_dirty)) or data_change )
+        {
+            std::cout << "Monitor MEMC " << name()
+                << " at cycle " << std::dec << m_cpt_cycles
+                << " for address " << std::hex << addr
+                << " / VAL = " << std::dec << (entry.state != ENTRY_INVALID)
+                << " / WAY = " << way
+                << " / COUNT = " << entry.count 
+                << " / DIRTY = " << entry.dirty
+                << " / DATA_CHANGE = " << data_change 
+                << std::endl;
+            std::cout << std::hex << "     /0:" << m_debug_data[0]
+                << "/1:" << m_debug_data[1]
+                << "/2:" << m_debug_data[2]
+                << "/3:" << m_debug_data[3]
+                << "/4:" << m_debug_data[4]
+                << "/5:" << m_debug_data[5]
+                << "/6:" << m_debug_data[6]
+                << "/7:" << m_debug_data[7]
+                << "/8:" << m_debug_data[8]
+                << "/9:" << m_debug_data[9]
+                << "/A:" << m_debug_data[10]
+                << "/B:" << m_debug_data[11]
+                << "/C:" << m_debug_data[12]
+                << "/D:" << m_debug_data[13]
+                << "/E:" << m_debug_data[14]
+                << "/F:" << m_debug_data[15]
+                << std::endl;
+        }
+        m_debug_previous_count = entry.count;
+        m_debug_previous_valid = entry.state;
+        m_debug_previous_dirty = entry.dirty;
+        for( size_t word=0 ; word<m_words ; word++ ) 
+            m_debug_previous_data[word] = m_debug_data[word];
+    }
+
+
+    /////////////////////////////////////////////////////
+    tmpl(uint32_t)::req_distance(uint32_t req_srcid)
+        /////////////////////////////////////////////////////
+    {
+        const uint32_t srcid_width = vci_param_int::S;
+        uint8_t self_x_srcid = m_cc_global_id >> (srcid_width - m_xwidth);
+        uint8_t self_y_srcid = (m_cc_global_id >> (srcid_width - m_ywidth)) & ((1 << m_xwidth) - 1);
+
+        uint8_t x_srcid = req_srcid >> (srcid_width - m_xwidth);
+        uint8_t y_srcid = (req_srcid >> (srcid_width - m_ywidth - m_xwidth)) & ((1 << m_xwidth) - 1);
+        return abs(self_x_srcid - x_srcid) + abs(self_y_srcid - y_srcid);
+    }
+
+
+    /////////////////////////////////////////////////////
+    tmpl(bool)::is_local_req(uint32_t req_srcid)
+        /////////////////////////////////////////////////////
+    {
+        return req_distance(req_srcid) == 0;
+    }
+
+    /////////////////////////////////////////////////////
+    tmpl(int)::read_instrumentation(uint32_t regr, uint32_t & rdata)
+    /////////////////////////////////////////////////////
+    {
+        int error = 0;
+
+        switch(regr)
+        {
+            ///////////////////////////////////////////////////////
+            //       DIRECT instrumentation registers            //
+            // Registers of 32 bits and therefore only LO is     //
+            // implemented.                                      //
+            //                                                   //
+            // The HI may be used in future implementations      //
+            ///////////////////////////////////////////////////////
+
+            // LOCAL
+
+            case MEMC_LOCAL_READ_LO   : rdata = m_cpt_read_local        ; break;
+            case MEMC_LOCAL_WRITE_LO  : rdata = m_cpt_write_flits_local ; break;
+            case MEMC_LOCAL_LL_LO     : rdata = m_cpt_ll_local          ; break;
+            case MEMC_LOCAL_SC_LO     : rdata = m_cpt_sc_local          ; break;
+            case MEMC_LOCAL_CAS_LO    : rdata = m_cpt_cas_local         ; break;
+            case MEMC_LOCAL_READ_HI   :
+            case MEMC_LOCAL_WRITE_HI  :
+            case MEMC_LOCAL_LL_HI     :
+            case MEMC_LOCAL_SC_HI     :
+            case MEMC_LOCAL_CAS_HI    : rdata = 0; break;
+
+            // REMOTE
+
+            case MEMC_REMOTE_READ_LO  : rdata = m_cpt_read_remote        ; break;
+            case MEMC_REMOTE_WRITE_LO : rdata = m_cpt_write_flits_remote ; break;
+            case MEMC_REMOTE_LL_LO    : rdata = m_cpt_ll_remote          ; break;
+            case MEMC_REMOTE_SC_LO    : rdata = m_cpt_sc_remote          ; break;
+            case MEMC_REMOTE_CAS_LO   : rdata = m_cpt_cas_remote         ; break;
+            case MEMC_REMOTE_READ_HI  :
+            case MEMC_REMOTE_WRITE_HI :
+            case MEMC_REMOTE_LL_HI    :
+            case MEMC_REMOTE_SC_HI    :
+            case MEMC_REMOTE_CAS_HI   : rdata = 0; break;
+
+            // COST
+
+            case MEMC_COST_READ_LO    : rdata = m_cpt_read_cost ; break;
+            case MEMC_COST_WRITE_LO   : rdata = m_cpt_write_cost; break;
+            case MEMC_COST_LL_LO      : rdata = m_cpt_ll_cost   ; break;
+            case MEMC_COST_SC_LO      : rdata = m_cpt_sc_cost   ; break;
+            case MEMC_COST_CAS_LO     : rdata = m_cpt_cas_cost  ; break;
+            case MEMC_COST_READ_HI    :
+            case MEMC_COST_WRITE_HI   :
+            case MEMC_COST_LL_HI      :
+            case MEMC_COST_SC_HI      :
+            case MEMC_COST_CAS_HI     : rdata = 0; break;
+
+            ///////////////////////////////////////////////////////
+            //       COHERENCE instrumentation registers         //
+            // Registers of 32 bits and therefore only LO is     //
+            // implemented.                                      //
+            //                                                   //
+            // The HI may be used in future implementations      //
+            ///////////////////////////////////////////////////////
+
+            // LOCAL
+
+            case MEMC_LOCAL_MUPDATE_LO  : rdata = m_cpt_update_local ; break;
+            case MEMC_LOCAL_MINVAL_LO   : rdata = m_cpt_minval_local ; break;
+            case MEMC_LOCAL_CLEANUP_LO  : rdata = m_cpt_cleanup_local; break;
+            case MEMC_LOCAL_MUPDATE_HI  :
+            case MEMC_LOCAL_MINVAL_HI   :
+            case MEMC_LOCAL_CLEANUP_HI  : rdata = 0; break;
+
+            // REMOTE
+
+            case MEMC_REMOTE_MUPDATE_LO : rdata = m_cpt_update_remote ; break;
+            case MEMC_REMOTE_MINVAL_LO  : rdata = m_cpt_minval_remote ; break;
+            case MEMC_REMOTE_CLEANUP_LO : rdata = m_cpt_cleanup_remote; break;
+            case MEMC_REMOTE_MUPDATE_HI :
+            case MEMC_REMOTE_MINVAL_HI  :
+            case MEMC_REMOTE_CLEANUP_HI : rdata = 0; break;
+
+            // COST
+
+            case MEMC_COST_MUPDATE_LO   : rdata = m_cpt_update_cost   ; break;
+            case MEMC_COST_MINVAL_LO    : rdata = m_cpt_minval_cost   ; break;
+            case MEMC_COST_CLEANUP_LO   : rdata = m_cpt_cleanup_cost  ; break;
+            case MEMC_COST_MUPDATE_HI   :
+            case MEMC_COST_MINVAL_HI    :
+            case MEMC_COST_CLEANUP_HI   : rdata = 0; break;
+
+            // TOTAL
+
+            case MEMC_TOTAL_MUPDATE_LO  : rdata = m_cpt_update ; break;
+            case MEMC_TOTAL_MINVAL_LO   : rdata = m_cpt_minval ; break;
+            case MEMC_TOTAL_BINVAL_LO   : rdata = m_cpt_binval ; break;
+            case MEMC_TOTAL_MUPDATE_HI  :
+            case MEMC_TOTAL_MINVAL_HI   :
+            case MEMC_TOTAL_BINVAL_HI   : rdata = 0; break;
+
+            // unknown register
+
+            default                     : error = 1;
+        }
+
+        return error;
+    }
+
+    //////////////////////////////////////////////////
+    tmpl(void)::print_trace( size_t detailed )
+    //////////////////////////////////////////////////
+    {
+        std::cout << "MEMC " << name() << std::endl;
+        std::cout << "  "  << tgt_cmd_fsm_str[r_tgt_cmd_fsm.read()]
+            << " | " << tgt_rsp_fsm_str[r_tgt_rsp_fsm.read()]
+            << " | " << read_fsm_str[r_read_fsm.read()]
+            << " | " << write_fsm_str[r_write_fsm.read()]
+            << " | " << cas_fsm_str[r_cas_fsm.read()]
+            << " | " << config_fsm_str[r_config_fsm.read()]
+            << " | " << cleanup_fsm_str[r_cleanup_fsm.read()] << std::endl;
+        std::cout << "  "  << cc_send_fsm_str[r_cc_send_fsm.read()]
+            << " | " << cc_receive_fsm_str[r_cc_receive_fsm.read()]
+            << " | " << multi_ack_fsm_str[r_multi_ack_fsm.read()]
+            << " | " << ixr_cmd_fsm_str[r_ixr_cmd_fsm.read()]
+            << " | " << ixr_rsp_fsm_str[r_ixr_rsp_fsm.read()]
+            << " | " << xram_rsp_fsm_str[r_xram_rsp_fsm.read()] << std::endl;
+        std::cout << "  "  << alloc_dir_fsm_str[r_alloc_dir_fsm.read()]
+            << " | " << alloc_trt_fsm_str[r_alloc_trt_fsm.read()]
+//            << " | " << alloc_upt_fsm_str[r_alloc_upt_fsm.read()]
+            << " | " << alloc_ivt_fsm_str[r_alloc_ivt_fsm.read()]
+            << " | " << alloc_heap_fsm_str[r_alloc_heap_fsm.read()] << std::endl;
+
+        if ( detailed ) m_trt.print(0);
+    }
+
+   
+    /////////////////////////////////////////
+    tmpl(void)::reset_counters()
+    /////////////////////////////////////////
+    {
+        m_cpt_reset_count        = m_cpt_cycles;
+        m_cpt_read_local         = 0;
+        m_cpt_read_remote        = 0;
+        m_cpt_read_cost          = 0;
+        m_cpt_write_local        = 0;
+        m_cpt_write_remote       = 0;
+        m_cpt_write_flits_local  = 0;
+        m_cpt_write_flits_remote = 0;
+        m_cpt_write_cost         = 0;
+        m_cpt_ll_local           = 0;
+        m_cpt_ll_remote          = 0;
+        m_cpt_ll_cost            = 0;
+        m_cpt_sc_local           = 0;
+        m_cpt_sc_remote          = 0;
+        m_cpt_sc_cost            = 0;
+        m_cpt_cas_local          = 0;
+        m_cpt_cas_remote         = 0;
+        m_cpt_cas_cost           = 0;
+        m_cpt_update             = 0;
+        m_cpt_update_local       = 0;
+        m_cpt_update_remote      = 0;
+        m_cpt_update_cost        = 0;
+        m_cpt_minval             = 0;
+        m_cpt_minval_local       = 0;
+        m_cpt_minval_remote      = 0;
+        m_cpt_minval_cost        = 0;
+        m_cpt_binval             = 0;
+        m_cpt_cleanup_local      = 0;
+        m_cpt_cleanup_remote     = 0;
+        m_cpt_cleanup_cost       = 0;
+        m_cpt_read_miss          = 0;
+        m_cpt_write_miss         = 0;
+        m_cpt_write_dirty        = 0;
+        m_cpt_trt_rb             = 0;
+        m_cpt_trt_full           = 0;
+        m_cpt_get                = 0;
+        m_cpt_put                = 0;
+        m_cpt_ncc_to_cc_read     = 0;
+        m_cpt_ncc_to_cc_write    = 0;
+        m_cpt_ncc_to_cc          = 0;
+    }
+
+
+    /////////////////////////////////////////
+    tmpl(void)::print_stats(bool activity_counters = true, bool stats = true)
+    {
+        std::cout << "**********************************" << std::dec << std::endl;
+        std::cout << "*** MEM_CACHE " << name() << std::endl;
+        std::cout << "**********************************" << std::dec << std::endl;
+        if (activity_counters) {
+            std::cout << "----------------------------------" << std::dec << std::endl;
+            std::cout << "---     Activity Counters      ---" << std::dec << std::endl;
+            std::cout << "----------------------------------" << std::dec << std::endl;
+            std::cout
+                << "[000] COUNTERS RESET AT CYCLE   = " << m_cpt_reset_count << std::endl
+                << "[001] NUMBER OF CYCLES          = " << m_cpt_cycles << std::endl
+                << std::endl
+                << "[002] LOCAL READ                = " << m_cpt_read_local << std::endl
+                << "[003] REMOTE READ               = " << m_cpt_read_remote << std::endl
+                << "[004] READ COST (FLITS * DIST)  = " << m_cpt_read_cost << std::endl
+                << std::endl
+                << "[005] LOCAL WRITE               = " << m_cpt_write_local << std::endl
+                << "[006] REMOTE WRITE              = " << m_cpt_write_remote << std::endl
+                << "[007] WRITE FLITS LOCAL         = " << m_cpt_write_flits_local << std::endl
+                << "[008] WRITE FLITS REMOTE        = " << m_cpt_write_flits_remote << std::endl
+                << "[009] WRITE COST (FLITS * DIST) = " << m_cpt_write_cost << std::endl
+                << std::endl
+                << "[010] LOCAL LL                  = " << m_cpt_ll_local << std::endl
+                << "[011] REMOTE LL                 = " << m_cpt_ll_remote << std::endl
+                << "[012] LL COST (FLITS * DIST)    = " << m_cpt_ll_cost << std::endl
+                << std::endl
+                << "[013] LOCAL SC                  = " << m_cpt_sc_local << std::endl
+                << "[014] REMOTE SC                 = " << m_cpt_sc_remote << std::endl
+                << "[015] SC COST (FLITS * DIST)    = " << m_cpt_sc_cost << std::endl
+                << std::endl
+                << "[016] LOCAL CAS                 = " << m_cpt_cas_local << std::endl
+                << "[017] REMOTE CAS                = " << m_cpt_cas_remote << std::endl
+                << "[018] CAS COST (FLITS * DIST)   = " << m_cpt_cas_cost << std::endl
+                << std::endl
+                << "[019] REQUESTS TRIG. UPDATE     = " << m_cpt_update << std::endl
+                << "[020] LOCAL UPDATE              = " << m_cpt_update_local << std::endl
+                << "[021] REMOTE UPDATE             = " << m_cpt_update_remote << std::endl
+                << "[022] UPDT COST (FLITS * DIST)  = " << m_cpt_update_cost << std::endl
+                << std::endl
+                << "[023] REQUESTS TRIG. M_INV      = " << m_cpt_minval << std::endl
+                << "[024] LOCAL M_INV               = " << m_cpt_minval_local << std::endl
+                << "[025] REMOTE M_INV              = " << m_cpt_minval_remote << std::endl
+                << "[026] M_INV COST (FLITS * DIST) = " << m_cpt_minval_cost << std::endl
+                << std::endl
+                << "[027] BROADCAT INVAL            = " << m_cpt_binval << std::endl
+                << std::endl
+                << "[028] LOCAL CLEANUP             = " << m_cpt_cleanup_local << std::endl
+                << "[029] REMOTE CLEANUP            = " << m_cpt_cleanup_remote << std::endl
+                << "[030] CLNUP COST (FLITS * DIST) = " << m_cpt_cleanup_cost << std::endl
+                << std::endl
+                << std::endl
+                << "[031] READ MISS                 = " << m_cpt_read_miss << std::endl
+                << "[032] WRITE MISS                = " << m_cpt_write_miss << std::endl
+                << "[033] WRITE DIRTY               = " << m_cpt_write_dirty << std::endl
+                << "[034] RD BLOCKED BY HIT IN TRT  = " << m_cpt_trt_rb << std::endl
+                << "[035] TRANS BLOCKED BY FULL TRT = " << m_cpt_trt_full << std::endl
+                << "[036] PUT (UNIMPLEMENTED)       = " << m_cpt_put << std::endl
+                << "[037] GET (UNIMPLEMENTED)       = " << m_cpt_get << std::endl
+                << "[038] WRITE BROADCAST           = " << m_cpt_write_broadcast << std::endl
+                << std::endl
+                << "[039] CLEANUP DATA (FLITS)      = " << m_cpt_cleanup_data * 16 << std::endl
+                << "[040] NCC TO CC (READ)          = " << m_cpt_ncc_to_cc_read << std::endl
+                << "[041] NCC TO CC (WRITE)         = " << m_cpt_ncc_to_cc_write << std::endl
+                << "[042] NCC TO CC (TOTAL)         = " << m_cpt_ncc_to_cc << std::endl
+                << std::endl;
+        }
+
+        if (stats) {
+            std::cout << "----------------------------------" << std::dec << std::endl;
+            std::cout << "---      Calculated Stats      ---" << std::dec << std::endl;
+            std::cout << "----------------------------------" << std::dec << std::endl;
+            std::cout
+                << "[100] READ TOTAL            = " << m_cpt_read_local + m_cpt_read_remote << std::endl
+                << "[101] READ RATE             = " << (double) (m_cpt_read_local + m_cpt_read_remote) / m_cpt_cycles << std::endl
+                << "[102] LOCAL READ RATE       = " << (double) m_cpt_read_local / m_cpt_cycles << std::endl
+                << "[103] REMOTE READ RATE      = " << (double) m_cpt_read_remote / m_cpt_cycles << std::endl
+                << "[104] READ MISS RATE        = " << (double) m_cpt_read_miss / (m_cpt_read_local + m_cpt_read_remote) << std::endl
+                << std::endl
+                << "[105] WRITE TOTAL           = " << m_cpt_write_local + m_cpt_write_remote << std::endl
+                << "[106] WRITE RATE            = " << (double) (m_cpt_write_local + m_cpt_write_remote) / m_cpt_cycles << std::endl
+                << "[107] LOCAL WRITE RATE      = " << (double) m_cpt_write_local / m_cpt_cycles << std::endl
+                << "[108] REMOTE WRITE RATE     = " << (double) m_cpt_write_remote / m_cpt_cycles << std::endl
+                << "[109] WRITE MISS RATE       = " << (double) m_cpt_write_miss / (m_cpt_write_local + m_cpt_write_remote) << std::endl
+                << "[110] WRITE BURST TOTAL     = " << m_cpt_write_flits_local + m_cpt_write_flits_remote << std::endl
+                << "[111] WRITE BURST AVERAGE   = " << (double) (m_cpt_write_flits_local + m_cpt_write_flits_remote) / (m_cpt_write_local + m_cpt_write_remote) << std::endl
+                << "[112] LOCAL WRITE BURST AV. = " << (double) m_cpt_write_flits_local / (m_cpt_write_local + m_cpt_write_remote) << std::endl
+                << "[113] REMOTE WRITE BURST AV = " << (double) m_cpt_write_flits_remote / (m_cpt_write_local + m_cpt_write_remote) << std::endl
+                << std::endl
+                << "[114] UPDATE RATE                = " << (double) m_cpt_update / m_cpt_cycles << std::endl
+                << "[115] AV. UPDATE PER UP REQ      = " << (double) (m_cpt_update_local + m_cpt_update_remote) / m_cpt_update << std::endl
+                << "[116] AV. LOC UPDT PER UP REQ    = " << (double) m_cpt_update_local / m_cpt_update << std::endl
+                << "[117] AV. REMOTE UPDT PER UP REQ = " << (double) m_cpt_update_remote / m_cpt_update << std::endl
+                << std::endl
+                << "[118] INVAL MULTICAST RATE  = " << (double) m_cpt_minval / m_cpt_cycles << std::endl
+                << "[119] AVE. INVAL PER M_INV  = " << (double) (m_cpt_minval_local + m_cpt_minval_remote) / m_cpt_minval << std::endl
+                << "[120] AV. LOC INV PER M_INV = " << (double) m_cpt_minval_local / m_cpt_minval << std::endl
+                << "[121] AV. REM INV PER M_INV = " << (double) m_cpt_minval_remote / m_cpt_minval << std::endl
+                << std::endl
+                << "[122] INVAL BROADCAST RATE  = " << (double) m_cpt_binval / m_cpt_cycles << std::endl
+                << "[123] WRITE DIRTY RATE      = " << (double) m_cpt_write_dirty / m_cpt_cycles << std::endl
+                << std::endl
+                << "[124] CLEANUP RATE          = " << (double) (m_cpt_cleanup_local + m_cpt_cleanup_remote) / m_cpt_cycles << std::endl
+                << "[125] LOCAL CLEANUP RATE    = " << (double) m_cpt_cleanup_local / m_cpt_cycles << std::endl
+                << "[126] REMOTE CLEANUP RATE   = " << (double) m_cpt_cleanup_remote / m_cpt_cycles << std::endl
+                << "[127] LL RATE               = " << (double) (m_cpt_ll_local + m_cpt_ll_remote) / m_cpt_cycles << std::endl
+                << "[128] LOCAL LL RATE         = " << (double) m_cpt_ll_local / m_cpt_cycles << std::endl
+                << "[129] REMOTE LL RATE        = " << (double) m_cpt_ll_remote / m_cpt_cycles << std::endl
+                << "[130] SC RATE               = " << (double) (m_cpt_sc_local + m_cpt_sc_remote) / m_cpt_cycles << std::endl
+                << "[131] LOCAL SC RATE         = " << (double) m_cpt_sc_local / m_cpt_cycles << std::endl
+                << "[132] REMOTE SC RATE        = " << (double) m_cpt_sc_remote / m_cpt_cycles << std::endl
+                << "[133] CAS RATE              = " << (double) (m_cpt_cas_local + m_cpt_cas_remote) / m_cpt_cycles << std::endl
+                << "[134] LOCAL CAS RATE        = " << (double) m_cpt_cas_local / m_cpt_cycles << std::endl
+                << "[135] REMOTE CAS RATE       = " << (double) m_cpt_cas_remote / m_cpt_cycles << std::endl
+                << std::endl
+                << std::endl;
+        }
+    }
+
+
+    /////////////////////////////////
+    tmpl(/**/) ::~VciMemCache()
+        /////////////////////////////////
+    {
+        delete [] m_seg;
+
+        delete [] r_ixr_rsp_to_xram_rsp_rok;
+        delete [] r_xram_rsp_victim_data;
+        delete [] r_xram_rsp_to_tgt_rsp_data;
+
+        delete [] r_read_data;
+        delete [] r_read_to_tgt_rsp_data;
+
+        delete [] r_write_data;
+        delete [] r_write_be;
+        delete [] r_write_to_cleanup_data;
+        delete [] r_write_to_cleanup_be;
+        delete [] r_cleanup_data;
+        delete [] r_multi_ack_data;
+        delete [] r_debug_data;
+        delete [] r_cleanup_to_ixr_cmd_data;
+        delete [] r_cleanup_to_tgt_rsp_data;
+        delete [] r_multi_ack_to_tgt_rsp_data;
+        delete [] r_cleanup_old_data;
+
+        delete [] r_cas_data;
+        delete [] r_cas_rdata;
+
+        delete [] r_ixr_cmd_wdata;
+        delete [] m_debug_previous_data;
+        delete [] m_debug_data;
+
+        print_stats();
+    }
+
+    //////////////////////////////////
+    tmpl(void) ::transition()
+        //////////////////////////////////
+    {
+        using soclib::common::uint32_log2;
+
+        // RESET
+        if(! p_resetn.read())
+        {
+
+            // Initializing FSMs
+            r_tgt_cmd_fsm    = TGT_CMD_IDLE;
+            r_config_fsm     = CONFIG_IDLE;
+            r_tgt_rsp_fsm    = TGT_RSP_READ_IDLE;
+            r_cc_send_fsm    = CC_SEND_XRAM_RSP_IDLE;
+            r_cc_receive_fsm = CC_RECEIVE_IDLE;
+            r_multi_ack_fsm  = MULTI_ACK_IDLE;
+            r_read_fsm       = READ_IDLE;
+            r_write_fsm      = WRITE_IDLE;
+            r_cas_fsm        = CAS_IDLE;
+            r_cleanup_fsm    = CLEANUP_IDLE;
+            r_alloc_dir_fsm  = ALLOC_DIR_RESET;
+            r_alloc_heap_fsm = ALLOC_HEAP_RESET;
+            r_alloc_trt_fsm  = ALLOC_TRT_READ;
+//            r_alloc_upt_fsm  = ALLOC_UPT_WRITE;
+            r_alloc_ivt_fsm  = ALLOC_IVT_WRITE;
+            r_ixr_rsp_fsm    = IXR_RSP_IDLE;
+            r_xram_rsp_fsm   = XRAM_RSP_IDLE;
+            r_ixr_cmd_fsm    = IXR_CMD_READ_IDLE;
+
+            m_debug                = false;
+            m_debug_previous_valid = false;
+            m_debug_previous_dirty = false;
+            m_debug_previous_count = 0;
+
+            //  Initializing Tables
+            m_trt.init();
+            m_upt.init();
+            m_ivt.init();
+            m_llsc_table.init();
+
+            // initializing FIFOs and communication Buffers
+
+            m_cmd_read_addr_fifo.init();
+            m_cmd_read_length_fifo.init();
+            m_cmd_read_srcid_fifo.init();
+            m_cmd_read_trdid_fifo.init();
+            m_cmd_read_pktid_fifo.init();
+
+            m_cmd_write_addr_fifo.init();
+            m_cmd_write_eop_fifo.init();
+            m_cmd_write_srcid_fifo.init();
+            m_cmd_write_trdid_fifo.init();
+            m_cmd_write_pktid_fifo.init();
+            m_cmd_write_data_fifo.init();
+
+            m_cmd_cas_addr_fifo.init()  ;
+            m_cmd_cas_srcid_fifo.init() ;
+            m_cmd_cas_trdid_fifo.init() ;
+            m_cmd_cas_pktid_fifo.init() ;
+            m_cmd_cas_wdata_fifo.init() ;
+            m_cmd_cas_eop_fifo.init()   ;
+
+            r_config_cmd  = MEMC_CMD_NOP;
+            r_config_lock = false;
+
+            m_config_to_cc_send_inst_fifo.init();
+            m_config_to_cc_send_srcid_fifo.init();
+
+            r_tgt_cmd_to_tgt_rsp_req = false;
+
+            r_read_to_tgt_rsp_req = false;
+            r_read_to_ixr_cmd_req = false;
+            r_read_to_cc_send_req = false;
+            r_read_to_cleanup_req = false;
+            r_read_to_multi_ack_req     = false;
+
+            m_read_to_cc_send_inst_fifo.init();
+            m_read_to_cc_send_srcid_fifo.init();
+
+            r_write_to_tgt_rsp_req          = false;
+            r_write_to_ixr_cmd_req          = false;
+            r_write_to_cc_send_multi_req    = false;
+            r_write_to_cc_send_brdcast_req  = false;
+            r_write_to_multi_ack_req        = false;
+
+            m_write_to_cc_send_inst_fifo.init();
+            m_write_to_cc_send_srcid_fifo.init();
+
+            r_cleanup_to_tgt_rsp_req      = false;
+
+            m_cc_receive_to_cleanup_fifo.init();
+
+            r_multi_ack_to_tgt_rsp_req     = false;
+
+            m_cc_receive_to_multi_ack_fifo.init();
+
+            r_cas_to_tgt_rsp_req          = false;
+            r_cas_cpt                     = 0    ;
+            r_cas_lfsr                    = -1   ;
+            r_cas_to_ixr_cmd_req          = false;
+            r_cas_to_cc_send_multi_req    = false;
+            r_cas_to_cc_send_brdcast_req  = false;
+            r_cas_to_cleanup_req          = false;
+
+            m_cas_to_cc_send_inst_fifo.init();
+            m_cas_to_cc_send_srcid_fifo.init();
+
+            for(size_t i=0; i<m_trt_lines ; i++)
+            {
+                r_ixr_rsp_to_xram_rsp_rok[i] = false;
+            }
+
+            r_xram_rsp_to_tgt_rsp_req          = false;
+            r_xram_rsp_to_cc_send_multi_req    = false;
+            r_xram_rsp_to_cc_send_brdcast_req  = false;
+            r_xram_rsp_to_ixr_cmd_req          = false;
+            r_xram_rsp_trt_index               = 0;
+
+            m_xram_rsp_to_cc_send_inst_fifo.init();
+            m_xram_rsp_to_cc_send_srcid_fifo.init();
+
+            r_alloc_dir_reset_cpt  = 0;
+            r_alloc_heap_reset_cpt = 0;
+
+            r_tgt_rsp_key_sent  = false;
+
+            // RWT
+            r_multi_ack_data_index     = 0;
+            r_cleanup_data_index       = 0;
+            r_cleanup_trdid            = 0;
+            r_cleanup_pktid            = 0;
+            r_cleanup_contains_data    = false;
+            r_cleanup_ncc              = false;
+            r_cleanup_to_ixr_cmd_ncc_l1_dirty    = false;
+            r_xram_rsp_to_ixr_cmd_inval_ncc_pending    = false;
+            r_cleanup_to_ixr_cmd_req   = false;
+            r_cleanup_to_ixr_cmd_srcid = 0;
+            r_cleanup_to_ixr_cmd_pktid = 0;
+            r_cleanup_to_ixr_cmd_nline = 0;
+            for (size_t word = 0; word < m_words; word ++)
+            {
+                r_cleanup_to_ixr_cmd_data[word] = 0;
+                r_cleanup_data[word] = 0;
+                r_multi_ack_data[word] = 0;
+                r_debug_data[word] = 0;
+            }
+
+
+            // Activity counters
+            m_cpt_reset_count        = 0;
+            m_cpt_cycles             = 0;
+            m_cpt_read_local         = 0;
+            m_cpt_read_remote        = 0;
+            m_cpt_read_cost          = 0;
+            m_cpt_write_local        = 0;
+            m_cpt_write_remote       = 0;
+            m_cpt_write_flits_local  = 0;
+            m_cpt_write_flits_remote = 0;
+            m_cpt_write_cost         = 0;
+            m_cpt_ll_local           = 0;
+            m_cpt_ll_remote          = 0;
+            m_cpt_ll_cost            = 0;
+            m_cpt_sc_local           = 0;
+            m_cpt_sc_remote          = 0;
+            m_cpt_sc_cost            = 0;
+            m_cpt_cas_local          = 0;
+            m_cpt_cas_remote         = 0;
+            m_cpt_cas_cost           = 0;
+            m_cpt_update             = 0;
+            m_cpt_update_local       = 0;
+            m_cpt_update_remote      = 0;
+            m_cpt_update_cost        = 0;
+            m_cpt_minval             = 0;
+            m_cpt_minval_local       = 0;
+            m_cpt_minval_remote      = 0;
+            m_cpt_minval_cost        = 0;
+            m_cpt_binval             = 0;
+            m_cpt_cleanup_local      = 0;
+            m_cpt_cleanup_remote     = 0;
+            m_cpt_cleanup_cost       = 0;
+
+            m_cpt_read_miss               = 0;
+            m_cpt_write_miss              = 0;
+            m_cpt_write_dirty             = 0;
+            m_cpt_write_broadcast         = 0;
+            m_cpt_trt_rb                  = 0;
+            m_cpt_trt_full                = 0;
+            m_cpt_get                     = 0;
+            m_cpt_put                     = 0;
+            m_cpt_dir_unused              = 0;
+            m_cpt_upt_unused              = 0;
+            m_cpt_ivt_unused              = 0;
+            m_cpt_heap_unused             = 0;
+            m_cpt_trt_unused              = 0;
+            m_cpt_read_fsm_n_dir_lock     = 0;
+            m_cpt_read_fsm_dir_lock       = 0;
+            m_cpt_read_fsm_dir_used       = 0;
+            m_cpt_read_fsm_trt_lock       = 0;
+            m_cpt_read_fsm_heap_lock      = 0;
+            m_cpt_write_fsm_dir_lock      = 0;
+            m_cpt_write_fsm_n_dir_lock    = 0;
+            m_cpt_write_fsm_upt_lock      = 0;
+            m_cpt_write_fsm_heap_lock     = 0;
+            m_cpt_write_fsm_dir_used      = 0;
+            m_cpt_write_fsm_trt_lock      = 0;
+            m_cpt_cas_fsm_n_dir_lock      = 0;
+            m_cpt_cas_fsm_dir_lock        = 0;
+            m_cpt_cas_fsm_upt_lock        = 0;
+            m_cpt_cas_fsm_heap_lock       = 0;
+            m_cpt_cas_fsm_trt_lock        = 0;
+            m_cpt_cas_fsm_dir_used        = 0;
+            m_cpt_xram_rsp_fsm_n_dir_lock = 0;
+            m_cpt_xram_rsp_fsm_dir_lock   = 0;
+            m_cpt_xram_rsp_fsm_trt_lock   = 0;
+            m_cpt_xram_rsp_fsm_upt_lock   = 0;
+            m_cpt_xram_rsp_fsm_heap_lock  = 0;
+            m_cpt_xram_rsp_fsm_dir_used   = 0;
+            m_cpt_cleanup_fsm_dir_lock    = 0;
+            m_cpt_cleanup_fsm_n_dir_lock  = 0;
+            m_cpt_cleanup_fsm_heap_lock   = 0;
+            m_cpt_cleanup_fsm_ivt_lock    = 0;
+            m_cpt_cleanup_fsm_dir_used    = 0;
+            m_cpt_ixr_fsm_trt_lock        = 0;
+            m_cpt_multi_ack_fsm_upt_lock  = 0;
+            m_cpt_read_data_unc           = 0;   
+            m_cpt_read_data_miss_CC       = 0;   
+            m_cpt_read_ins_unc            = 0;        
+            m_cpt_read_ins_miss           = 0;      
+            m_cpt_read_ll_CC              = 0;       
+            m_cpt_read_data_miss_NCC      = 0;        
+            m_cpt_read_ll_NCC             = 0;    
+            m_cpt_read_WTF                = 0;   
+            m_cpt_cleanup_data            = 0;      
+            m_cpt_ncc_to_cc_read          = 0;      
+            m_cpt_ncc_to_cc_write         = 0;       
+            m_cpt_ncc_to_cc               = 0;        
+            return;
+        }
+
+        bool    cmd_read_fifo_put = false;
+        bool    cmd_read_fifo_get = false;
+
+        bool    cmd_write_fifo_put = false;
+        bool    cmd_write_fifo_get = false;
+
+        bool    cmd_cas_fifo_put = false;
+        bool    cmd_cas_fifo_get = false;
+
+        bool    cc_receive_to_cleanup_fifo_get = false;
+        bool    cc_receive_to_cleanup_fifo_put = false;
+
+        bool    cc_receive_to_multi_ack_fifo_get = false;
+        bool    cc_receive_to_multi_ack_fifo_put = false;
+
+        bool    write_to_cc_send_fifo_put   = false;
+        bool    write_to_cc_send_fifo_get   = false;
+        bool    write_to_cc_send_fifo_inst  = false;
+        size_t  write_to_cc_send_fifo_srcid = 0;
+
+        bool    read_to_cc_send_fifo_put   = false;
+        bool    read_to_cc_send_fifo_get   = false;
+        bool    read_to_cc_send_fifo_inst  = false;
+        size_t  read_to_cc_send_fifo_srcid = 0;
+
+        bool    xram_rsp_to_cc_send_fifo_put   = false;
+        bool    xram_rsp_to_cc_send_fifo_get   = false;
+        bool    xram_rsp_to_cc_send_fifo_inst  = false;
+        size_t  xram_rsp_to_cc_send_fifo_srcid = 0;
+
+        bool   config_rsp_lines_incr          = false;
+        bool   config_rsp_lines_cleanup_decr  = false;
+        bool   config_rsp_lines_ixr_rsp_decr  = false;
+
+        bool    config_to_cc_send_fifo_put   = false;
+        bool    config_to_cc_send_fifo_get   = false;
+        bool    config_to_cc_send_fifo_inst  = false;
+        size_t  config_to_cc_send_fifo_srcid = 0;
+
+        bool    cas_to_cc_send_fifo_put   = false;
+        bool    cas_to_cc_send_fifo_get   = false;
+        bool    cas_to_cc_send_fifo_inst  = false;
+        size_t  cas_to_cc_send_fifo_srcid = 0;
+
+        m_debug = (m_cpt_cycles > m_debug_start_cycle) and m_debug_ok;
+
+#if DEBUG_MEMC_GLOBAL
+        if(m_debug)
+        {
+            std::cout
+                << "---------------------------------------------"           << std::dec << std::endl
+                << "MEM_CACHE "            << name()
+                << " ; Time = "            << m_cpt_cycles                                << std::endl
+                << " - TGT_CMD FSM    = "  << tgt_cmd_fsm_str[r_tgt_cmd_fsm.read()]       << std::endl
+                << " - TGT_RSP FSM    = "  << tgt_rsp_fsm_str[r_tgt_rsp_fsm.read()]       << std::endl
+                << " - CC_SEND FSM  = "    << cc_send_fsm_str[r_cc_send_fsm.read()]       << std::endl
+                << " - CC_RECEIVE FSM  = " << cc_receive_fsm_str[r_cc_receive_fsm.read()] << std::endl
+                << " - MULTI_ACK FSM  = "  << multi_ack_fsm_str[r_multi_ack_fsm.read()]   << std::endl
+                << " - READ FSM       = "  << read_fsm_str[r_read_fsm.read()]             << std::endl
+                << " - WRITE FSM      = "  << write_fsm_str[r_write_fsm.read()]           << std::endl
+                << " - CAS FSM        = "  << cas_fsm_str[r_cas_fsm.read()]               << std::endl
+                << " - CLEANUP FSM    = "  << cleanup_fsm_str[r_cleanup_fsm.read()]       << std::endl
+                << " - IXR_CMD FSM    = "  << ixr_cmd_fsm_str[r_ixr_cmd_fsm.read()]       << std::endl
+                << " - IXR_RSP FSM    = "  << ixr_rsp_fsm_str[r_ixr_rsp_fsm.read()]       << std::endl
+                << " - XRAM_RSP FSM   = "  << xram_rsp_fsm_str[r_xram_rsp_fsm.read()]     << std::endl
+                << " - ALLOC_DIR FSM  = "  << alloc_dir_fsm_str[r_alloc_dir_fsm.read()]   << std::endl
+                << " - ALLOC_TRT FSM  = "  << alloc_trt_fsm_str[r_alloc_trt_fsm.read()]   << std::endl
+             //   << " - ALLOC_UPT FSM  = "  << alloc_upt_fsm_str[r_alloc_upt_fsm.read()]   << std::endl
+                << " - ALLOC_HEAP FSM = "  << alloc_heap_fsm_str[r_alloc_heap_fsm.read()] << std::endl;
+        }
+#endif
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    TGT_CMD FSM
+        ////////////////////////////////////////////////////////////////////////////////////
+        // The TGT_CMD_FSM controls the incoming VCI command pakets from the processors,
+        // and dispatch these commands to the proper FSM through dedicated FIFOs.
+        //
+        // There are 5 types of commands accepted in the XRAM segment:
+        // - READ   : A READ request has a length of 1 VCI flit. It can be a single word
+        //            or an entire cache line, depending on the PLEN value => READ FSM
+        // - WRITE  : A WRITE request has a maximum length of 16 flits, and can only
+        //            concern words in a same line => WRITE FSM
+        // - CAS    : A CAS request has a length of 2 flits or 4 flits => CAS FSM
+        // - LL     : An LL request has a length of 1 flit => READ FSM
+        // - SC     : An SC request has a length of 2 flits. First flit contains the
+        //            acces key, second flit the data to write => WRITE FSM.
+        //
+        // The READ/WRITE commands accepted in the configuration segment are targeting
+        // configuration or status registers. They must contain one single flit.
+        // - For almost all addressable registers, the response is returned immediately. 
+        // - For MEMC_CMD_TYPE, the response is delayed until the operation is completed.
+        ////////////////////////////////////////////////////////////////////////////////////
+        switch(r_tgt_cmd_fsm.read())
+        {
+            //////////////////
+            case TGT_CMD_IDLE:     // waiting a VCI command (RAM or CONFIG)
+                if(p_vci_tgt.cmdval)
+                {
+
+#if DEBUG_MEMC_TGT_CMD
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " TGT_CMD_IDLE> Receive command from srcid "
+                            << std::hex << p_vci_tgt.srcid.read()
+                            << " / address " << std::hex << p_vci_tgt.address.read() << std::endl;
+#endif
+                    // checking segmentation violation
+                    addr_t      address  = p_vci_tgt.address.read();
+                    uint32_t    plen     = p_vci_tgt.plen.read();
+                    bool        found    = false;
+                    bool        config   = false;
+
+                    for (size_t seg_id = 0; (seg_id < m_nseg) && !found; seg_id++)
+                    {
+                        if (m_seg[seg_id]->contains(address) &&
+                                m_seg[seg_id]->contains(address + plen - vci_param_int::B) )
+                        {
+                            found = true;
+                            if ( m_seg[seg_id]->special() ) config = true;
+                        }
+                    }
+
+                    if (!found)                /////////// out of segment error
+                    {
+                        r_tgt_cmd_fsm   = TGT_CMD_ERROR;
+                    }
+                    else if ( config )              /////////// configuration command
+                    {
+                        if (!p_vci_tgt.eop.read()) r_tgt_cmd_fsm = TGT_CMD_ERROR;
+                        else                            r_tgt_cmd_fsm = TGT_CMD_CONFIG;
+                    }
+                    else                            //////////// memory access 
+                    {
+                        if ( p_vci_tgt.cmd.read() == vci_param_int::CMD_READ )
+                        {
+                            // check that the pktid is either :
+                            // TYPE_DATA_UNC
+                            // TYPE_READ_DATA_MISS
+                            // TYPE_READ_INS_UNC
+                            // TYPE_READ_INS_MISS
+                            // ==> bit2 must be zero with the TSAR encoding
+                            // ==> mask = 0b0100 = 0x4
+//                            assert( ((p_vci_tgt.pktid.read() & 0x4) == 0x0) and
+//                                    "The type specified in the pktid field is incompatible with the READ CMD");
+                            r_tgt_cmd_fsm = TGT_CMD_READ;
+                        }
+                        else if(p_vci_tgt.cmd.read() == vci_param_int::CMD_WRITE)
+                        {
+                          // check that the pktid is TYPE_WRITE
+                          // ==> TYPE_WRITE = X100 with the TSAR encoding
+                          // ==> mask = 0b0111 = 0x7
+                            r_tgt_cmd_fsm = TGT_CMD_WRITE;
+                        }
+                        else if(p_vci_tgt.cmd.read() == vci_param_int::CMD_LOCKED_READ)
+                        {
+                            // check that the pktid is TYPE_LL
+                            // ==> TYPE_LL = X110 with the TSAR encoding
+                            // ==> mask = 0b0111 = 0x7
+                            assert(((p_vci_tgt.pktid.read() & 0x7) == 0x6) and
+                                    "The type specified in the pktid field is incompatible with the LL CMD");
+                            r_tgt_cmd_fsm = TGT_CMD_READ;
+                        }
+                        else if(p_vci_tgt.cmd.read() == vci_param_int::CMD_NOP)
+                        {
+                            // check that the pktid is either :
+                            // TYPE_CAS
+                            // TYPE_SC
+                            // ==> TYPE_CAS = X101 with the TSAR encoding
+                            // ==> TYPE_SC  = X111 with the TSAR encoding
+                            // ==> mask = 0b0101 = 0x5
+                            assert(((p_vci_tgt.pktid.read() & 0x5) == 0x5) and
+                                    "The type specified in the pktid field is incompatible with the NOP CMD");
+
+                            if((p_vci_tgt.pktid.read() & 0x7) == TYPE_CAS) r_tgt_cmd_fsm = TGT_CMD_CAS;
+                            else                                           r_tgt_cmd_fsm = TGT_CMD_WRITE; 
+                        }
+                        else
+                        {
+                            r_tgt_cmd_fsm = TGT_CMD_ERROR;
+                        }
+                    }
+                }
+                break;
+
+                ///////////////////
+            case TGT_CMD_ERROR:  // response error must be sent
+
+                // wait if pending request
+                if(r_tgt_cmd_to_tgt_rsp_req.read()) break;
+
+                // consume all the command packet flits before sending response error
+                if ( p_vci_tgt.cmdval and p_vci_tgt.eop )
+                {
+                    r_tgt_cmd_to_tgt_rsp_srcid = p_vci_tgt.srcid.read();
+                    r_tgt_cmd_to_tgt_rsp_trdid = p_vci_tgt.trdid.read();
+                    r_tgt_cmd_to_tgt_rsp_pktid = p_vci_tgt.pktid.read();
+                    r_tgt_cmd_to_tgt_rsp_req   = true;
+                    r_tgt_cmd_to_tgt_rsp_error = 1;
+                    r_tgt_cmd_fsm              = TGT_CMD_IDLE;
+
+#if DEBUG_MEMC_TGT_CMD
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " TGT_CMD_ERROR> Segmentation violation:"
+                            << " address = " << std::hex << p_vci_tgt.address.read()
+                            << " / srcid = " << p_vci_tgt.srcid.read()
+                            << " / trdid = " << p_vci_tgt.trdid.read()
+                            << " / pktid = " << p_vci_tgt.pktid.read()
+                            << " / plen = " << std::dec << p_vci_tgt.plen.read() << std::endl;
+#endif
+
+                }
+                break;
+
+                ////////////////////
+            case TGT_CMD_CONFIG:    // execute config request and return response
+                {
+                    ///////////////////////////////////////////////////////////
+                    //  Decoding CONFIG interface commands                   //
+                    //                                                       //
+                    //  VCI ADDRESS                                          //
+                    //  ================================================     //
+                    //  GLOBAL | LOCAL | ... | FUNC_IDX | REGS_IDX | 00      //
+                    //   IDX   |  IDX  |     | (3 bits) | (7 bits) |         //
+                    //  ================================================     //
+                    //                                                       //
+                    //  For instrumentation : FUNC_IDX = 0b001               //
+                    //                                                       //
+                    //  REGS_IDX                                             //
+                    //  ============================================         //
+                    //       Z     |    Y      |    X     |   W              //
+                    //    (1 bit)  | (2 bits)  | (3 bits) | (1 bit)          //
+                    //  ============================================         //
+                    //                                                       //
+                    //  Z : DIRECT / COHERENCE                               //
+                    //  Y : SUBTYPE ( LOCAL, REMOTE, OTHER )                 //
+                    //  X : REGISTER INDEX                                   //
+                    //  W : HI / LO                                          //
+                    //                                                       //
+                    //  For configuration: FUNC_IDX = 0b000                  //
+                    //                                                       //
+                    //  REGS_IDX                                             //
+                    //  ============================================         //
+                    //             RESERVED             |    X     |         //
+                    //             (4 bits)             | (3 bits) |         //
+                    //  ============================================         //
+                    //                                                       //
+                    //  X : REGISTER INDEX                                   //
+                    //                                                       //
+                    //  For WRITE MISS error signaling: FUNC = 0x010         //
+                    //                                                       //
+                    //  REGS_IDX                                             //
+                    //  ============================================         //
+                    //             RESERVED             |    X     |         //
+                    //             (4 bits)             | (3 bits) |         //
+                    //  ============================================         //
+                    //                                                       //
+                    //  X : REGISTER INDEX                                   //
+                    //                                                       //
+                    ///////////////////////////////////////////////////////////
+
+                    addr_t addr_lsb = p_vci_tgt.address.read() &
+                                      m_config_addr_mask;
+
+                    addr_t cell = (addr_lsb / vci_param_int::B);
+
+                    size_t regr = cell &
+                                  m_config_regr_idx_mask;
+
+                    size_t func = (cell >> m_config_regr_width) &
+                                  m_config_func_idx_mask;
+
+                    bool     need_rsp; 
+                    int      error;  
+                    uint32_t rdata = 0;         // default value
+                    uint32_t wdata = p_vci_tgt.wdata.read();
+
+                    switch(func)
+                    {
+                        // memory operation
+                        case MEMC_CONFIG:
+                        {
+                            if ((p_vci_tgt.cmd.read() == vci_param_int::CMD_READ)         // get lock
+                                    and (regr == MEMC_LOCK))
+                            {
+                                rdata            = (uint32_t) r_config_lock.read();
+                                need_rsp         = true;
+                                error            = 0;
+                                r_config_lock    = true;
+                            }
+                            else if ((p_vci_tgt.cmd.read() == vci_param_int::CMD_WRITE)  // release lock
+                                    and (regr == MEMC_LOCK))
+                            {
+                                need_rsp      = true;
+                                error         = 0;
+                                r_config_lock = false;
+                            }
+                            else if ((p_vci_tgt.cmd.read() == vci_param_int::CMD_WRITE)   // set addr_lo
+                                    and (regr == MEMC_ADDR_LO))
+                            {
+                                assert( ((wdata % (m_words * vci_param_int::B)) == 0) and
+                                        "VCI_MEM_CACHE CONFIG ERROR: The buffer must be aligned on a cache line");
+
+                                need_rsp         = true;
+                                error            = 0;
+                                r_config_address = (r_config_address.read() & 0xFFFFFFFF00000000LL) |
+                                    ((addr_t)wdata);
+                            }
+                            else if ((p_vci_tgt.cmd.read() == vci_param_int::CMD_WRITE)   // set addr_hi
+                                    and (regr == MEMC_ADDR_HI))
+
+                            {
+                                need_rsp         = true;
+                                error            = 0;
+                                r_config_address = (r_config_address.read() & 0x00000000FFFFFFFFLL) |
+                                    (((addr_t) wdata) << 32);
+                            }
+                            else if ((p_vci_tgt.cmd.read() == vci_param_int::CMD_WRITE)   // set buf_lines
+                                    and (regr == MEMC_BUF_LENGTH))
+                            {
+                                need_rsp         = true;
+                                error            = 0;
+                                size_t lines     = wdata / (m_words << 2);
+                                if (wdata % (m_words << 2)) lines++;
+                                r_config_cmd_lines = lines;
+                                r_config_rsp_lines = 0;
+                            }
+                            else if ((p_vci_tgt.cmd.read() == vci_param_int::CMD_WRITE)   // set cmd type
+                                    and (regr == MEMC_CMD_TYPE))
+                            {
+                                need_rsp         = false;
+                                error            = 0;
+                                r_config_cmd     = wdata;
+
+                                // prepare delayed response from CONFIG FSM
+                                r_config_srcid   = p_vci_tgt.srcid.read();
+                                r_config_trdid   = p_vci_tgt.trdid.read();
+                                r_config_pktid   = p_vci_tgt.pktid.read();
+                            }
+                            else
+                            {
+                                need_rsp         = true;
+                                error            = 1;
+                            }
+
+                            break;
+                        }
+
+                        // instrumentation registers
+                        case MEMC_INSTRM:
+                        {
+                            need_rsp = true;
+
+                            if (p_vci_tgt.cmd.read() == vci_param_int::CMD_READ)
+                            {
+                                error = read_instrumentation(regr, rdata);
+                            }
+                            else
+                            {
+                                error = 1;
+                            }
+
+                            break;
+                        }
+
+                        //unknown function
+                        default:
+                        {
+                            need_rsp = true;
+                            error    = 1;
+
+                            break;
+                        }
+                    }
+
+                    if (need_rsp)
+                    {
+                        // blocked if previous pending request to TGT_RSP FSM
+                        if (r_tgt_cmd_to_tgt_rsp_req.read()) break;
+
+                        r_tgt_cmd_to_tgt_rsp_srcid = p_vci_tgt.srcid.read();
+                        r_tgt_cmd_to_tgt_rsp_trdid = p_vci_tgt.trdid.read();
+                        r_tgt_cmd_to_tgt_rsp_pktid = p_vci_tgt.pktid.read();
+                        r_tgt_cmd_to_tgt_rsp_req   = true;
+                        r_tgt_cmd_to_tgt_rsp_error = error;
+                        r_tgt_cmd_to_tgt_rsp_rdata = rdata;
+                    }
+
+                    r_tgt_cmd_fsm = TGT_CMD_IDLE;
+
+#if DEBUG_MEMC_TGT_CMD
+                    if (m_debug)
+                        std::cout << "  <MEMC " << name() << " TGT_CMD_CONFIG> Configuration request:"
+                            << " address = " << std::hex << p_vci_tgt.address.read()
+                            << " / func = " << func
+                            << " / regr = " << regr
+                            << " / rdata = " << rdata
+                            << " / wdata = " << p_vci_tgt.wdata.read()
+                            << " / need_rsp = " << need_rsp
+                            << " / error = " << error << std::endl;
+#endif
+                    break;
+                }
+
+#if 0
+            case TGT_CMD_CONFIG:    // execute config request and return response
+                {
+                    addr_t   seg_base = m_seg[m_seg_config]->baseAddress();
+                    addr_t   address  = p_vci_tgt.address.read();
+                    size_t   cell     = (address - seg_base)/vci_param_int::B;
+
+                    bool     need_rsp; 
+                    size_t   error;  
+                    uint32_t rdata = 0;         // default value
+                    uint32_t wdata = p_vci_tgt.wdata.read();     
+
+                    if ( (p_vci_tgt.cmd.read() == vci_param_int::CMD_READ)         // get lock
+                            and (cell == MEMC_LOCK) )
+                    {
+                        rdata            = (uint32_t)r_config_lock.read();
+                        need_rsp         = true;
+                        error            = 0;
+                        r_config_lock    = true;
+                    }
+                    else if ( (p_vci_tgt.cmd.read() == vci_param_int::CMD_WRITE)  // release lock
+                            and (cell == MEMC_LOCK))
+                    {
+                        need_rsp         = true;
+                        error            = 0;
+                        r_config_lock    = false;
+                    }
+                    else if ( (p_vci_tgt.cmd.read() == vci_param_int::CMD_WRITE)   // set addr_lo
+                            and (cell == MEMC_ADDR_LO))
+                    {
+                        assert( ((wdata % (m_words*vci_param_int::B)) == 0) and
+                                "VCI_MEM_CACHE CONFIG ERROR: The buffer must be aligned on a cache line");
+
+                        need_rsp         = true;
+                        error            = 0;
+                        r_config_address = (r_config_address.read() & 0xFFFFFFFF00000000LL) |
+                            ((addr_t)wdata);
+                    }
+                    else if ( (p_vci_tgt.cmd.read() == vci_param_int::CMD_WRITE)   // set addr_hi
+                            and (cell == MEMC_ADDR_HI))
+                    {
+                        need_rsp         = true;
+                        error            = 0;
+                        r_config_address = (r_config_address.read() & 0x00000000FFFFFFFFLL) |
+                            (((addr_t) wdata) << 32);
+                    }
+                    else if ( (p_vci_tgt.cmd.read() == vci_param_int::CMD_WRITE)   // set buf_lines
+                            and (cell == MEMC_BUF_LENGTH))
+                    {
+                        need_rsp         = true;
+                        error            = 0;
+                        size_t lines     = wdata / (m_words << 2);
+                        if (wdata % (m_words << 2)) lines++;
+                        r_config_cmd_lines  = lines;
+                        r_config_rsp_lines  = 0;
+                    }
+                    else if ( (p_vci_tgt.cmd.read() == vci_param_int::CMD_WRITE)   // set cmd type
+                            and (cell == MEMC_CMD_TYPE))
+                    {
+                        need_rsp         = false;
+                        error            = 0;
+                        r_config_cmd     = wdata;
+                        r_config_srcid   = p_vci_tgt.srcid.read();
+                        r_config_trdid   = p_vci_tgt.trdid.read();
+                        r_config_pktid   = p_vci_tgt.pktid.read();
+                    }
+                    else
+                    {
+                        need_rsp         = true;
+                        error            = 1;
+                    }
+
+                    if ( need_rsp )
+                    {
+                        // blocked if previous pending request to TGT_RSP FSM
+                        if ( r_tgt_cmd_to_tgt_rsp_req.read() ) break;
+
+                        r_tgt_cmd_to_tgt_rsp_srcid = p_vci_tgt.srcid.read();
+                        r_tgt_cmd_to_tgt_rsp_trdid = p_vci_tgt.trdid.read();
+                        r_tgt_cmd_to_tgt_rsp_pktid = p_vci_tgt.pktid.read();
+                        r_tgt_cmd_to_tgt_rsp_req   = true;
+                        r_tgt_cmd_to_tgt_rsp_error = error;
+                        r_tgt_cmd_to_tgt_rsp_rdata = rdata;
+                        r_tgt_cmd_fsm              = TGT_CMD_IDLE;
+                    }
+                    else
+                    {
+                        r_tgt_cmd_fsm              = TGT_CMD_IDLE;
+                    }
+
+#if DEBUG_MEMC_TGT_CMD
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " TGT_CMD_CONFIG> Configuration request:"
+                            << " address = " << std::hex << p_vci_tgt.address.read()
+                            << " / wdata = " << p_vci_tgt.wdata.read()
+                            << " / need_rsp = " << need_rsp
+                            << " / error = " << error << std::endl;
+#endif
+                    break;
+                }
+#endif                         // #if 0
+                //////////////////
+            case TGT_CMD_READ:    // Push a read request into read fifo
+
+                // check that the read does not cross a cache line limit.
+                if ( ((m_x[(addr_t) p_vci_tgt.address.read()]+ (p_vci_tgt.plen.read() >>2)) > 16) and
+                        (p_vci_tgt.cmd.read() != vci_param_int::CMD_LOCKED_READ))
+                {
+                    std::cout << "VCI_MEM_CACHE ERROR " << name() << " TGT_CMD_READ state"
+                        << " illegal address/plen for VCI read command" << std::endl;
+                    exit(0);
+                }
+                // check single flit
+                if(!p_vci_tgt.eop.read())
+                {
+                    std::cout << "VCI_MEM_CACHE ERROR " << name() << " TGT_CMD_READ state"
+                        << " read command packet must contain one single flit" << std::endl;
+                    exit(0);
+                } 
+                // check plen for LL
+                if ( (p_vci_tgt.cmd.read() == vci_param_int::CMD_LOCKED_READ) and 
+                        (p_vci_tgt.plen.read() != 8) )
+                {
+                    std::cout << "VCI_MEM_CACHE ERROR " << name() << " TGT_CMD_READ state"
+                        << " ll command packets must have a plen of 8" << std::endl;
+                    exit(0);
+                }
+
+                if ( p_vci_tgt.cmdval and m_cmd_read_addr_fifo.wok() )
+                {
+
+#if DEBUG_MEMC_TGT_CMD
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " TGT_CMD_READ> Push into read_fifo:"
+                            << " address = " << std::hex << p_vci_tgt.address.read()
+                            << " / srcid = " << p_vci_tgt.srcid.read()
+                            << " / trdid = " << p_vci_tgt.trdid.read()
+                            << " / pktid = " << p_vci_tgt.pktid.read()
+                            << " / plen = " << std::dec << p_vci_tgt.plen.read() << std::endl;
+#endif
+                    cmd_read_fifo_put = true;
+                    // <Activity counters>
+                    if (p_vci_tgt.cmd.read() == vci_param_int::CMD_LOCKED_READ) {
+                        if (is_local_req(p_vci_tgt.srcid.read())) m_cpt_ll_local++;
+                        else                                      m_cpt_ll_remote++;
+                        m_cpt_ll_cost += req_distance(p_vci_tgt.srcid.read()); // LL on a single word
+                    }
+                    else {
+                        if (is_local_req(p_vci_tgt.srcid.read())) m_cpt_read_local++;
+                        else                                      m_cpt_read_remote++;
+                        m_cpt_read_cost += m_words * req_distance(p_vci_tgt.srcid.read());
+                    }
+                    // </Activity counters>
+                    r_tgt_cmd_fsm = TGT_CMD_IDLE;
+                }
+                break;
+
+                ///////////////////
+            case TGT_CMD_WRITE:
+                if(p_vci_tgt.cmdval and m_cmd_write_addr_fifo.wok())
+                {
+
+#if DEBUG_MEMC_TGT_CMD
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " TGT_CMD_WRITE> Push into write_fifo:"
+                            << " address = " << std::hex << p_vci_tgt.address.read()
+                            << " / srcid = " << p_vci_tgt.srcid.read()
+                            << " / trdid = " << p_vci_tgt.trdid.read()
+                            << " / pktid = " << p_vci_tgt.pktid.read()
+                            << " / wdata = " << p_vci_tgt.wdata.read()
+                            << " / be = " << p_vci_tgt.be.read()
+                            << " / plen = " << std::dec << p_vci_tgt.plen.read() << std::endl;
+#endif
+                    cmd_write_fifo_put = true;
+                    // <Activity counters>
+                    if (p_vci_tgt.cmd.read() == vci_param_int::CMD_NOP) {
+                        m_cpt_sc_cost += req_distance(p_vci_tgt.srcid.read());
+                    }
+                    else {
+                        if (is_local_req(p_vci_tgt.srcid.read())) m_cpt_write_flits_local++;
+                        else                                      m_cpt_write_flits_remote++;
+                        m_cpt_write_cost += req_distance(p_vci_tgt.srcid.read());
+                    }
+                    // </Activity counters>
+
+                    if (p_vci_tgt.eop) {
+                        // <Activity counters>
+                        if (p_vci_tgt.cmd.read() == vci_param_int::CMD_NOP) {
+                            if (is_local_req(p_vci_tgt.srcid.read())) m_cpt_sc_local++;
+                            else                                      m_cpt_sc_remote++;
+
+                        }
+                        else {
+                            if (is_local_req(p_vci_tgt.srcid.read())) m_cpt_write_local++;
+                            else                                      m_cpt_write_remote++;
+                        }
+                        // </Activity counters>
+                        r_tgt_cmd_fsm = TGT_CMD_IDLE;
+                    }
+                }
+                break;
+                /////////////////
+            case TGT_CMD_CAS:
+                if((p_vci_tgt.plen.read() != 8) and (p_vci_tgt.plen.read() != 16))
+                {
+                    std::cout << "VCI_MEM_CACHE ERROR " << name() << " TGT_CMD_CAS state"
+                        << "illegal format for CAS command " << std::endl;
+                    exit(0);
+                }
+
+                if(p_vci_tgt.cmdval and m_cmd_cas_addr_fifo.wok())
+                {
+
+#if DEBUG_MEMC_TGT_CMD
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " TGT_CMD_CAS> Pushing command into cmd_cas_fifo:"
+                            << " address = " << std::hex << p_vci_tgt.address.read()
+                            << " srcid = " << p_vci_tgt.srcid.read()
+                            << " trdid = " << p_vci_tgt.trdid.read()
+                            << " pktid = " << p_vci_tgt.pktid.read()
+                            << " wdata = " << p_vci_tgt.wdata.read()
+                            << " be = " << p_vci_tgt.be.read()
+                            << " plen = " << std::dec << p_vci_tgt.plen.read() << std::endl;
+#endif
+                    cmd_cas_fifo_put = true;
+                    if (p_vci_tgt.eop) {
+                        // <Activity counters>
+                        if (is_local_req(p_vci_tgt.srcid.read())) m_cpt_cas_local++;
+                        else                                      m_cpt_cas_remote++;
+                        m_cpt_cas_cost += req_distance(p_vci_tgt.srcid.read());
+                        // </Activity counters>
+                        r_tgt_cmd_fsm = TGT_CMD_IDLE;
+                    }
+                }
+                break;
+        } // end switch tgt_cmd_fsm
+
+        /////////////////////////////////////////////////////////////////////////
+        //    MULTI_ACK FSM
+        /////////////////////////////////////////////////////////////////////////
+        // This FSM controls the response to the multicast update requests sent 
+        // by the memory cache to the L1 caches and update the UPT.
+        //
+        // - The FSM decrements the proper entry in UPT,
+        //   and clear the UPT entry when all responses have been received.
+        // - If required, it sends a request to the TGT_RSP FSM to complete
+        //   a pending  write transaction.
+        //
+        // All those multi-ack packets are one flit packet.
+        // The index in the UPT is defined in the TRDID field.
+        ////////////////////////////////////////////////////////////////////////
+
+        switch(r_multi_ack_fsm.read())
+        {
+            ////////////////////
+            case MULTI_ACK_IDLE: //TODO 
+                {
+                    bool multi_ack_fifo_rok = m_cc_receive_to_multi_ack_fifo.rok();
+
+                    uint64_t flit = m_cc_receive_to_multi_ack_fifo.read();
+
+                    if( not multi_ack_fifo_rok )
+                        break;
+
+                    size_t ivt_index    = DspinDhccpParam::dspin_get(flit,
+                                    DspinDhccpParam::MULTI_ACK_UPDT_INDEX);
+
+                    bool miss_updt    = DspinDhccpParam::dspin_get(flit,
+                                    DspinDhccpParam::MULTI_ACK_UPDT_MISS);
+
+                    bool eop = DspinDhccpParam::dspin_get(flit, DspinDhccpParam::P2M_EOP) == 0x1;
+
+                    cc_receive_to_multi_ack_fifo_get = true;
+
+                    assert((ivt_index < m_ivt.size()) and
+                            "VCI_MEM_CACHE ERROR in MULTI_ACK_IDLE : "
+                            "index too large for IVT");
+
+                    r_multi_ack_ivt_index = ivt_index;
+                    r_multi_ack_miss_updt = miss_updt;
+
+                    if( not eop)
+                    {
+                        r_multi_ack_fsm = MULTI_ACK_GET_DATA;
+                        r_multi_ack_need_data = true;
+                        r_multi_ack_data_index = 0;
+                    }
+                    else
+                    {
+                        r_multi_ack_fsm = MULTI_ACK_IVT_LOCK;
+                        r_multi_ack_need_data = false;
+                    }
+
+#if DEBUG_MEMC_MULTI_ACK
+                    if(m_debug)
+                    {
+                        if (multi_ack_fifo_rok)
+                        {
+                            std::cout << "  <MEMC " << name()
+                                << " MULTI_ACK_IDLE> Response for UPT entry "
+                                << (size_t)ivt_index 
+                                << " flit = " << std::hex << flit << std::endl;
+                        }
+                    }
+#endif
+                    break;
+                }
+                ////////////////////////////////
+            case MULTI_ACK_GET_DATA:
+                {
+                    if (m_cc_receive_to_multi_ack_fifo.rok())
+                    {
+                        uint64_t flit = m_cc_receive_to_multi_ack_fifo.read();
+
+                        uint32_t data = 
+                            DspinDhccpParam::dspin_get (flit, DspinDhccpParam::CLEANUP_DATA_UPDT);
+
+                        bool eop = DspinDhccpParam::dspin_get(flit, DspinDhccpParam::P2M_EOP) == 0x1;
+#if DEBUG_MEMC_CLEANUP
+                        if(m_debug)
+                        {
+                            std::cout
+                                << "  <MEMC "         << name()
+                                << " MULTI_ACK_GET_DATA> "
+                                << " / word = "    << std::dec << r_multi_ack_data_index.read()
+                                << " / data = " << std::hex << data
+                                << " / eop = " << std::hex << eop
+                                << std::endl;
+                        }
+#endif
+                        r_multi_ack_data[r_multi_ack_data_index.read()] = data;
+                        r_multi_ack_data_index                 = r_multi_ack_data_index.read() + 1;
+                        cc_receive_to_multi_ack_fifo_get       = true;
+                        assert (r_multi_ack_data_index.read() < m_words and "MEM_CACHE in CLEANUP_GET_DATA : too much flits in cleanup data updt");
+                        if (r_multi_ack_data_index.read() == (m_words - 1))
+                        {
+                            assert( eop && "the last word has been received in multi ack data");
+                            r_multi_ack_fsm       = MULTI_ACK_IVT_LOCK;
+                        }
+
+                    }
+                    break;
+                }
+                ////////////////////////
+            case MULTI_ACK_IVT_LOCK:
+                {
+                    if(r_alloc_ivt_fsm.read() != ALLOC_IVT_MULTI_ACK)  break;
+                    size_t index  = r_multi_ack_ivt_index.read();
+                    size_t count  = m_ivt.count(index);
+                    size_t nline  = m_ivt.nline(index);
+                    r_multi_ack_nline = nline;
+                    r_multi_ack_srcid = m_ivt.srcid(index);
+                    r_multi_ack_trdid = m_ivt.trdid(index);
+                    r_multi_ack_pktid = m_ivt.pktid(index);
+                    r_multi_ack_rsp   = m_ivt.need_rsp(index);
+                    //bool is_valid = m_ivt.is_valid(index);
+
+                    if(r_multi_ack_miss_updt.read())
+                    {
+                        r_multi_ack_fsm = MULTI_ACK_DIR_REQ;
+                    }                    
+                    else
+                    {
+                        bool is_updt  = m_ivt.is_update(index);
+                    
+                        assert(is_updt && "MULTI_ACK: is not an updt index for a multi ack rsp");
+                        assert(count == 1 && "there is only one copy in the memc");
+
+                        r_multi_ack_fsm = MULTI_ACK_IVT_CLEAR;
+
+#if DEBUG_MEMC_MULTI_ACK
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " MULTI_ACK_IVT_LOCK> Decrement the responses counter for UPT:"
+                            << " entry = "       << r_multi_ack_ivt_index.read()
+                            << " / count = " << std::dec << count << std::endl;
+#endif
+                    }
+                    break;
+                }
+                /////////////////////
+            case MULTI_ACK_IVT_CLEAR:
+                {
+                    if(r_alloc_ivt_fsm.read() != ALLOC_IVT_MULTI_ACK ) 
+                    {
+                        std::cout
+                            << "VCI_MEM_CACHE ERROR " << name()
+                            << " MULTI_ACK_IVT_LOCK state"
+                            << " bad IVT allocation" << std::endl;
+
+                        exit(0);
+                    }
+
+                    m_ivt.clear(r_multi_ack_ivt_index.read()); 
+                    r_multi_ack_fsm = MULTI_ACK_DIR_REQ;        
+            
+#if DEBUG_MEMC_MULTI_ACK
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " MULTI_ACK_IVT_CLEAR> IVT clear:"
+                            << " entry = "       << r_multi_ack_ivt_index.read()
+                            << std::endl;
+#endif
+                    break;
+                }
+                /////////////////////
+            case MULTI_ACK_DIR_REQ:   // Get the lock to the directory
+                {
+                    if(r_alloc_dir_fsm.read() != ALLOC_DIR_MULTI_ACK) break;
+
+                    r_multi_ack_fsm = MULTI_ACK_DIR_LOCK;
+                    //std::cout << " MEM_CACHE : CLEANUP_DIR_REQ" << std::endl;
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " MULTI_ACK_DIR_REQ> Requesting DIR lock" << std::endl;
+#endif
+
+                    break;
+                }
+                /////////////////////
+            case MULTI_ACK_DIR_LOCK: //updt data with the registers which have saved the set and way
+                {
+                    if(r_alloc_dir_fsm.read() != ALLOC_DIR_MULTI_ACK)
+                    {
+                        std::cout
+                            << "VCI_MEM_CACHE ERROR " << name()
+                            << " MULTI_ACK_DIR_LOCK state"
+                            << " bad DIR allocation" << std::endl;
+
+                        exit(0);
+                    }
+                    // Read the directory
+                    size_t way = 0;
+                    addr_t multi_ack_address = r_multi_ack_nline.read() * m_words * 4;
+                    bool match_ll = ((r_multi_ack_pktid.read() & 0x07) == TYPE_LL);
+                    DirectoryEntry entry     = m_cache_directory.read(multi_ack_address , way);
+                    r_multi_ack_tag          = entry.tag;
+                    r_multi_ack_dirty        = entry.dirty;
+                    r_multi_ack_lock         = entry.lock;
+                    r_multi_ack_way          = way;
+                    r_multi_ack_set          = m_y[(addr_t)(r_multi_ack_nline * m_words * 4)];
+                    r_multi_ack_count        = entry.count;
+                    r_multi_ack_copy         = entry.owner.srcid;
+                    r_multi_ack_copy_inst    = entry.owner.inst;
+
+#if DEBUG_MEMC_MULTI_ACK
+                    if(m_debug)
+                    {
+                        std::cout
+                            << "  <MEMC " << name()
+                            << " MULTI_ACK_DIR_LOCK> Test directory status: "
+                            << std::hex
+                            << " line = "         << multi_ack_address
+                            << " / hit = "        << entry.state
+                            << " / dir_id = "     << entry.owner.srcid
+                            << " / dir_ins = "    << entry.owner.inst
+                            << " / count = "      << entry.count
+                            << " / is_cnt = "     << entry.is_cnt
+                            << " pktid ="         << r_multi_ack_pktid.read()    
+                            << std::endl;
+                    }
+#endif
+                    assert( (entry.state == ENTRY_LOCKED) && "mutli rsp check the entry, the line is not locked!!!");
+                        
+                    if(r_multi_ack_miss_updt.read()) //cache L1 has sent the cleanup when it receives the cc_updt request,
+                    {
+                        if(not entry.count)
+                        {
+                            r_multi_ack_miss_updt = false;
+                        }
+                        r_multi_ack_fsm = MULTI_ACK_WAIT; 
+                    }
+                    else if( not entry.count or match_ll) // The line has been already evicted from cache L1
+                    {
+                        assert(((entry.count == 1) or (entry.count == 0)) && "multi ack for a ll request, count is 1");
+                        r_multi_ack_fsm        = MULTI_ACK_DIR_UPDT;
+                        //r_multi_ack_rsp_shared = false;
+                    }
+                    else
+                    {
+                        r_multi_ack_fsm        = MULTI_ACK_HEAP_REQ;
+                        //r_multi_ack_rsp_shared = true;
+                    }
+                    break;
+                }
+                /////////////
+            case MULTI_ACK_WAIT:   // release all locks and retry from beginning
+                {
+
+#if DEBUG_MEMC_MULTI_ACK
+                    if(m_debug)
+                    {
+                        std::cout << "  <MEMC " << name()
+                            << " MULTI_ACK_WAIT> Release all locks" << std::endl;
+                    }
+#endif
+                    r_multi_ack_fsm = MULTI_ACK_IVT_LOCK;
+                    break;
+                }
+                //////////////////
+            case MULTI_ACK_DIR_UPDT:
+                {
+                    if(r_alloc_dir_fsm.read() != ALLOC_DIR_MULTI_ACK)
+                    {
+                        std::cout
+                            << "VCI_MEM_CACHE ERROR " << name()
+                            << " MULTI_ACK_DIR_LOCK state"
+                            << " bad DIR allocation" << std::endl;
+
+                        exit(0);
+                    }
+
+                    bool match_ll = ((r_multi_ack_pktid.read() & 0x07) == TYPE_LL);
+
+                    if(r_multi_ack_need_data.read())
+                    {
+                        for(size_t word=0; word<m_words ; word++)
+                        {
+                            m_cache_data.write(r_multi_ack_way.read(), 
+                                               r_multi_ack_set.read(), 
+                                               word, 
+                                               r_multi_ack_data[word]);
+                        }
+                    }
+                    else
+                    {
+                        m_cache_data.read_line( r_multi_ack_way.read(),
+                                                r_multi_ack_set.read(),
+                                                r_multi_ack_data);
+                    }
+
+                    DirectoryEntry entry;
+                    entry.is_cnt         = false;
+                    entry.dirty          = r_multi_ack_dirty.read() or r_multi_ack_need_data.read();
+                    entry.tag            = r_multi_ack_tag.read();
+                    entry.lock           = r_multi_ack_lock.read();
+                    entry.ptr            = 0;
+
+                    if(match_ll)
+                    {
+                        entry.owner.srcid    = r_multi_ack_copy.read();
+                        entry.count          = r_multi_ack_count.read();
+                    }
+                    else
+                    {
+                        entry.owner.srcid    = r_multi_ack_srcid.read();
+                        entry.count          = 1;
+                    }
+
+
+                   // if( (r_multi_ack_pktid.read() & 0x07) == 0x03 or match_ll)
+                   // {
+                        entry.state          = ENTRY_SHARED; // MISS INST
+                   // }
+                   //  else
+                   //  {
+                   //     entry.state          = ENTRY_EXCLUSIVE; // MISS DATA 
+                   // }
+
+                    if((r_multi_ack_pktid.read() & 0x7) == 0x03) 
+                    {
+                        entry.owner.inst = true;
+                    }
+                    else
+                    {
+                        entry.owner.inst = false;
+                    }
+
+                    m_cache_directory.write(r_multi_ack_set.read(), r_multi_ack_way.read(), entry);
+                   
+                    assert( r_multi_ack_rsp.read() && "Multi ack: must be send the rsp"); 
+                    r_multi_ack_fsm      = MULTI_ACK_RSP;
+#if DEBUG_MEMC_MULTI_ACK
+                    if(m_debug)
+                    {
+                        std::cout << "  <MEMC " << name() << " MULTI_ACK_DIR_UPDT>"
+                            << " Cache update: "
+                            << " way = " << r_multi_ack_way.read()
+                            << " set = " << r_multi_ack_set.read()
+                            << " updt data = " << r_multi_ack_need_data.read()
+                            << std::endl;
+                    } 
+#endif
+                    break;
+                }
+                ///////////////////////
+            case MULTI_ACK_RSP:    // response to a previous read on the direct network
+                // wait if pending request to the TGT_RSP FSM
+                {
+                    if(r_multi_ack_to_tgt_rsp_req.read()) break;
+
+                    for(size_t i = 0; i<m_words; i++)
+                    {
+                        r_multi_ack_to_tgt_rsp_data[i] = r_multi_ack_data[i].read();
+                    }
+                    // no pending request
+                    r_multi_ack_to_tgt_rsp_req     = true;
+                    if( r_read_to_multi_ack_req.read() and (r_read_to_multi_ack_nline.read() == r_multi_ack_nline.read()))
+                    {
+                        r_multi_ack_to_tgt_rsp_word    = r_read_to_multi_ack_first_word.read();
+                        r_multi_ack_to_tgt_rsp_length  = r_read_to_multi_ack_length.read();
+                        r_read_to_multi_ack_req        = false;
+                    }
+                    else
+                    {
+                        r_multi_ack_to_tgt_rsp_word    = 0;
+                        r_multi_ack_to_tgt_rsp_length  = 16;
+                    }
+
+                    r_multi_ack_to_tgt_ll_key      = r_read_to_multi_ack_ll_key.read();
+                    r_multi_ack_to_tgt_rsp_srcid   = r_multi_ack_srcid.read();
+                    r_multi_ack_to_tgt_rsp_trdid   = r_multi_ack_trdid.read();
+
+                   // if(r_multi_ack_rsp_shared.read()) // rsp read with shared or exclusive state
+                   // {
+                        r_multi_ack_to_tgt_rsp_pktid = r_multi_ack_pktid.read();
+                   // }
+                   // else
+                   //{
+                   //    r_multi_ack_to_tgt_rsp_pktid = 0x08 + r_multi_ack_pktid.read();  
+                   //}
+
+                   r_multi_ack_fsm = MULTI_ACK_IDLE;
+
+#if DEBUG_MEMC_MULTI_ACK
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " MULTI_ACK_RSP>"
+                            << " Send a response to a previous read/ll request: "
+                            << " rsrcid = "   << std::hex << r_multi_ack_srcid.read()
+                            << " / r_read_to_multi_ack  = " << r_read_to_multi_ack_req.read()
+                            << " / word  = "  << r_read_to_multi_ack_first_word.read()
+                            << " / data0  = "  << r_multi_ack_data[0].read()
+                            << " / data1  = "  << r_multi_ack_data[1].read()
+                            << " / length  = " << r_read_to_multi_ack_length.read()
+                            << " / rtrdid = " << r_multi_ack_trdid.read()
+                            << " / rtrdid = " << r_multi_ack_trdid.read()
+                            << " / rpktid = " << r_multi_ack_pktid.read() << std::endl;
+#endif
+                    break;
+                }
+                ///////////////////
+            case MULTI_ACK_HEAP_REQ:    // Get the lock to the HEAP directory
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_MULTI_ACK)
+                    {
+                        r_multi_ack_fsm = MULTI_ACK_HEAP_LOCK;
+                    }
+#if DEBUG_MEMC_MULTI_ACK
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " MULTI_ACK_HEAP_REQ>"
+                            << " Requesting HEAP lock " << std::endl;
+#endif
+                    break;
+                }
+                ////////////////////
+            case MULTI_ACK_HEAP_LOCK:   // update the directory
+                // and prepare the HEAP update
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_MULTI_ACK and 
+                       r_alloc_dir_fsm.read() == ALLOC_DIR_MULTI_ACK)
+                    {
+                        if(r_multi_ack_need_data.read())
+                        {
+                            for(size_t word=0; word<m_words ; word++)
+                            {
+                                m_cache_data.write(r_multi_ack_way.read(), 
+                                                   r_multi_ack_set.read(), 
+                                                   word, 
+                                                   r_multi_ack_data[word]);
+                            }
+                        }
+                        else
+                        {
+                            m_cache_data.read_line( r_multi_ack_way.read(),
+                                                    r_multi_ack_set.read(),
+                                                    r_multi_ack_data);
+                        }
+
+                        bool go_cnt = m_heap.is_full();
+                        // update the cache directory
+                        DirectoryEntry entry;
+                        entry.state  = ENTRY_SHARED; // 2 copies in memc
+                        entry.is_cnt = go_cnt;
+                        entry.lock   = r_multi_ack_lock.read();
+                        assert(r_multi_ack_count.read() == 1 && "multi ack update dir, count = 1");
+                        entry.count  = r_multi_ack_count.read() + 1;
+                        entry.dirty  = r_multi_ack_dirty.read() or r_multi_ack_need_data.read();
+                        entry.tag    = r_multi_ack_tag.read();
+                        if(not go_cnt)         // Not entering counter mode
+                        {
+                            entry.owner.srcid      = r_multi_ack_copy.read();
+                            entry.owner.inst       = r_multi_ack_copy_inst.read();
+                            entry.ptr              = m_heap.next_free_ptr();   // set pointer on the heap
+
+                            HeapEntry heap_entry   = m_heap.next_free_entry();
+
+                            r_multi_ack_next_ptr   = heap_entry.next;
+                            r_multi_ack_last_free  = (heap_entry.next == m_heap.next_free_ptr());
+                            r_multi_ack_fsm        = MULTI_ACK_HEAP_WRITE; // add an entry in the HEAP
+                        }
+                        else                // Entering Counter mode
+                        {
+                            entry.owner.srcid    = 0;
+                            entry.owner.inst     = false;
+                            entry.ptr            = 0;
+                            r_multi_ack_fsm      = MULTI_ACK_RSP;
+                            
+                        }
+                        m_cache_directory.write(r_multi_ack_set.read(), r_multi_ack_way.read(), entry);
+
+#if DEBUG_MEMC_MULTI_ACK
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " MULTI_ACK_HEAP_LOCK> Update directory:"
+                                << " tag = " << std::hex << entry.tag
+                                << " set = " << std::dec << r_multi_ack_set.read()
+                                << " updt data = " << r_multi_ack_need_data.read()
+                                << " way = " << r_multi_ack_way.read()
+                                << " count = " << entry.count
+                                << std::endl;
+#endif
+                    }
+                    else
+                    {
+                        std::cout << "VCI_MEM_CACHE ERROR " << name() << " MULTI_ACK_HEAP_LOCK"
+                            << "Bad HEAP allocation"   << std::endl;
+                        exit(0);
+                    }
+                    break;
+                }
+                /////////////////////
+            case MULTI_ACK_HEAP_WRITE:       // add an entry in the heap
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_MULTI_ACK and 
+                       r_alloc_dir_fsm.read() == ALLOC_DIR_MULTI_ACK)
+                    {
+                        HeapEntry heap_entry;
+                        heap_entry.owner.srcid    = r_multi_ack_srcid.read();
+
+                        if( (r_multi_ack_pktid.read() & 0x07) == 0x03)
+                        {
+                            heap_entry.owner.inst     = 1;
+                        }
+                        else
+                        {
+                            heap_entry.owner.inst     = 0;
+                        }
+
+                        heap_entry.next           = m_heap.next_free_ptr();
+                        m_heap.write_free_entry(heap_entry);
+                        m_heap.write_free_ptr(r_multi_ack_next_ptr.read());
+                        if(r_multi_ack_last_free.read())  m_heap.set_full();
+
+                        r_multi_ack_fsm = MULTI_ACK_RSP;
+
+#if DEBUG_MEMC_MULTI_ACK
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " MULTI_ACK_HEAP_WRITE> Add an entry in the heap:"
+                                << " owner_id = " << std::hex << heap_entry.owner.srcid
+                                << " data 0 = "  << r_multi_ack_data[0].read()
+                                << " data 1 = "  << r_multi_ack_data[1].read()
+                                << " data 2 = "  << r_multi_ack_data[2].read()
+                                << " owner_ins = " << std::dec << heap_entry.owner.inst << std::endl;
+#endif
+                    }
+                    else
+                    {
+                        std::cout << "VCI_MEM_CACHE ERROR " << name() << " MULTI_ACK_HEAP_WRITE"
+                            << "Bad HEAP allocation" << std::endl;
+                        exit(0);
+                    }
+                    break;
+                }
+ 
+        } // end switch r_multi_ack_fsm
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    CONFIG FSM
+        ////////////////////////////////////////////////////////////////////////////////////
+        // The CONFIG FSM handles the VCI configuration requests (INVAL & SYNC).
+        // The target buffer can have any size, and there is one single command for
+        // all cache lines covered by the target buffer.
+        //
+        // An INVAL or SYNC configuration operation is defined by the following registers:
+        // - bool      r_config_cmd        : INVAL / SYNC / NOP
+
+        // - uint64_t  r_config_address    : buffer base address
+        // - uint32_t  r_config_cmd_lines  : number of lines to be handled
+        // - uint32_t  r_config_rsp_lines  : number of lines not completed
+
+        //
+        // For both INVAL and SYNC commands, the CONFIG FSM contains the loop handling 
+        //
+        // all cache lines covered by the buffer. The various lines of a given buffer
+        // can be pipelined: the CONFIG FSM does not wait the response for line (n) to send
+        // the command for line (n+1). It decrements the r_config_cmd_lines counter until 
+        // the last request has been registered in TRT (for a SYNC), or in IVT (for an INVAL).
+        // The r_config_rsp_lines counter contains the number of expected responses from
+        // CLEANUP FSM (inval) or from IXR_RSP FSM (sync). This register is incremented by
+        // the CONFIG FSM (each time a transaction is requested), and decremented by the
+        // CLEANUP or IXR_RSP FSMs(each time a response is received. As this register can
+        // be concurently accessed by those three FSMs, it is implemented as an [incr/decr]
+        // counter.
+        // 
+        // - INVAL request:
+        //   For each line, it access to the DIR. 
+        //   In case of miss, it does nothing, and a response is requested to TGT_RSP FSM. 
+        //   In case of hit, with no copies in L1 caches, the line is invalidated and
+        //   a response is requested to TGT_RSP FSM.
+        //   If there is copies, a multi-inval, or a broadcast-inval coherence transaction
+        //
+        //   is launched and registered in UPT. The multi-inval transaction completion
+        //   is signaled by the CLEANUP FSM by decrementing the r_config_rsp_lines counter.
+        //   The CONFIG INVAL response is sent only when the last line has been invalidated.
+        //   TODO : The target buffer address must be aligned on a cache line boundary.
+        //   This constraint can be released, but it requires to make 2 PUT transactions
+        //   for the first and the last line...
+        // 
+        // - SYNC request:
+        //   For each line, it access to the DIR. 
+        //   In case of miss, it does nothing, and a response is requested to TGT_RSP FSM. 
+        //   In case of hit, a PUT transaction is registered in TRT and a request is sent
+        //   to IXR_CMD FSM. The IXR_RSP FSM decrements the r_config_rsp_lines counter
+        //   when a PUT response is received.
+        //   The CONFIG SYNC response is sent only when the last PUT response is received.
+        //
+        // From the software point of view, a configuration request is a sequence
+        // of 6 atomic accesses in an uncached segment. A dedicated lock is used 
+        // to handle only one configuration command at a given time:
+        // - Read  MEMC_LOCK       : Get the lock
+        // - Write MEMC_ADDR_LO    : Set the buffer address LSB
+        // - Write MEMC_ADDR_HI    : Set the buffer address MSB
+        // - Write MEMC_BUF_LENGTH : set buffer length (bytes)
+        // - Write MEMC_CMD_TYPE   : launch the actual operation
+        // - WRITE MEMC_LOCK       : release the lock
+        ////////////////////////////////////////////////////////////////////////////////////
+
+        switch( r_config_fsm.read() )
+        {
+            /////////////////
+            case CONFIG_IDLE:  // waiting a config request 
+                {
+                    if ( r_config_cmd.read() != MEMC_CMD_NOP )  
+                    {
+                        r_config_fsm    = CONFIG_LOOP;
+
+#if DEBUG_MEMC_CONFIG
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " CONFIG_IDLE> Config Request received" 
+                                << " address = " << std::hex << r_config_address.read()
+                                << " / nlines = " << std::dec << r_config_cmd_lines.read()
+                                << " / type = " << r_config_cmd.read() << std::endl;
+#endif
+                    }
+                    break;
+                }
+                /////////////////
+            case CONFIG_LOOP:   // test last line to be handled 
+                {
+                    if ( r_config_cmd_lines.read() == 0 )
+                    {
+                        r_config_cmd = MEMC_CMD_NOP;
+                        r_config_fsm = CONFIG_WAIT;
+                    }
+                    else
+                    {
+                        r_config_fsm = CONFIG_DIR_REQ;
+                    }
+
+#if DEBUG_MEMC_CONFIG
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CONFIG_LOOP>" 
+                            << " address = " << std::hex << r_config_address.read()    
+                            << " / nlines = " << std::dec << r_config_cmd_lines.read() 
+                            << " / command = " << r_config_cmd.read() << std::endl;
+#endif
+                    break;
+                }
+                /////////////////
+            case CONFIG_WAIT:   // wait completion (last response) 
+                {
+                    if ( r_config_rsp_lines.read() == 0 )  // last response received
+                    {
+                        r_config_fsm = CONFIG_RSP;
+                    }
+
+#if DEBUG_MEMC_CONFIG
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CONFIG_WAIT>" 
+                            << " / lines to do = " << std::dec << r_config_rsp_lines.read() << std::endl;
+#endif
+                    break;
+                }
+                ////////////////
+            case CONFIG_RSP:  // request TGT_RSP FSM to return response 
+                {
+                    if ( not r_config_to_tgt_rsp_req.read() )
+                    {
+                        r_config_to_tgt_rsp_srcid  = r_config_srcid.read();
+                        r_config_to_tgt_rsp_trdid  = r_config_trdid.read();
+                        r_config_to_tgt_rsp_pktid  = r_config_pktid.read();
+                        r_config_to_tgt_rsp_error  = false;
+                        r_config_to_tgt_rsp_req    = true;
+                        r_config_fsm               = CONFIG_IDLE;
+
+#if DEBUG_MEMC_CONFIG
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " CONFIG_RSP> Request TGT_RSP FSM to return response:"
+                                << " error = " << r_config_to_tgt_rsp_error.read()
+                                << " / rsrcid = " << std::hex << r_config_srcid.read()
+                                << " / rtrdid = " << std::hex << r_config_trdid.read()
+                                << " / rpktid = " << std::hex << r_config_pktid.read() << std::endl;
+#endif
+                    }
+                    break;
+
+                }
+
+                ////////////////////
+            case CONFIG_DIR_REQ:  // Request directory lock
+                {
+                    if ( r_alloc_dir_fsm.read() == ALLOC_DIR_CONFIG )
+                    {
+                        r_config_fsm = CONFIG_DIR_ACCESS;
+                    }
+
+#if DEBUG_MEMC_CONFIG
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CONFIG_DIR_REQ>"
+                            << " Request DIR access" << std::endl;
+#endif
+                    break;
+                }
+                ///////////////////////
+            case CONFIG_DIR_ACCESS:   // Access directory and decode config command
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_CONFIG) and
+                            "MEMC ERROR in CONFIG_DIR_ACCESS state: bad DIR allocation");
+
+                    size_t way = 0;
+                    DirectoryEntry entry = m_cache_directory.read(r_config_address.read(), way);
+
+                    r_config_dir_way        = way;
+                    r_config_dir_copy_inst  = entry.owner.inst;
+                    r_config_dir_copy_srcid = entry.owner.srcid;
+                    r_config_dir_is_cnt     = entry.is_cnt;
+                    r_config_dir_count      = entry.count;
+                    r_config_dir_lock       = entry.lock;
+                    r_config_dir_ptr        = entry.ptr;
+                    r_config_dir_state      = entry.state;
+
+                    if ((entry.state == ENTRY_SHARED or entry.state == ENTRY_EXCLUSIVE) and                            // hit & inval command
+                            (r_config_cmd.read() == MEMC_CMD_INVAL)) 
+                    {
+                        r_config_fsm    = CONFIG_IVT_LOCK;
+                    }
+                    else if ( (entry.state == ENTRY_SHARED or entry.state == ENTRY_EXCLUSIVE) and                       // hit & sync command
+                            entry.dirty and (r_config_cmd.read() == MEMC_CMD_SYNC) )
+                    { 
+                        r_config_fsm = CONFIG_TRT_LOCK;
+                    }
+                    else if( entry.state == ENTRY_LOCKED)
+                    {   // wait for unlock 
+                        r_config_fsm = CONFIG_WAIT;
+                        
+                    }
+                    else
+                    {
+                        r_config_cmd_lines = r_config_cmd_lines.read() - 1;
+                        r_config_address   = r_config_address.read() + (m_words<<2);
+                        r_config_fsm       = CONFIG_LOOP;
+                    }
+
+#if DEBUG_MEMC_CONFIG
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CONFIG_DIR_ACCESS> Accessing directory: "
+                            << " address = " << std::hex << r_config_address.read()
+                            << " / hit = " << std::dec << (entry.state == ENTRY_SHARED or entry.state == ENTRY_EXCLUSIVE)
+                            << " / dirty = " << entry.dirty
+                            << " / count = " << entry.count
+                            << " / is_cnt = " << entry.is_cnt << std::endl;
+#endif
+                    break;
+                }
+                /////////////////////
+            case CONFIG_TRT_LOCK:      // enter this state in case of SYNC command
+                // to a dirty cache line 
+                // keep DIR lock, and try to get TRT lock
+                // return to LOOP state if TRT full
+                // reset dirty bit in DIR and register a PUT
+                // trabsaction in TRT if not full.
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_CONFIG) and
+                            "MEMC ERROR in CONFIG_TRT_LOCK state: bad DIR allocation");
+
+                    if ( r_alloc_trt_fsm.read() == ALLOC_TRT_CONFIG )
+                    {
+                        size_t index = 0;
+                        bool   wok   = not m_trt.full(index);
+
+                        if ( not wok )
+                        {
+                            r_config_fsm = CONFIG_LOOP;
+                        }
+                        else
+                        {
+                            size_t          way = r_config_dir_way.read();
+                            size_t          set = m_y[r_config_address.read()];
+
+                            // reset dirty bit in DIR
+                            DirectoryEntry  entry;
+                            entry.state       = r_config_dir_state.read();
+                            entry.dirty       = false;
+                            entry.tag         = m_z[r_config_address.read()];
+                            entry.is_cnt      = r_config_dir_is_cnt.read();
+                            entry.lock        = r_config_dir_lock.read();
+                            entry.ptr         = r_config_dir_ptr.read();
+                            entry.count       = r_config_dir_count.read();
+                            entry.owner.inst  = r_config_dir_copy_inst.read();
+                            entry.owner.srcid = r_config_dir_copy_srcid.read();
+                            m_cache_directory.write( set, way, entry );
+
+                            r_config_trt_index = index;
+                            r_config_fsm       = CONFIG_TRT_SET;
+                        }
+
+#if DEBUG_MEMC_CONFIG
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " CONFIG_TRT_LOCK> Access TRT: "
+                                << " wok = " << std::dec << wok
+                                << " index = " << index << std::endl;
+#endif
+                    }
+                    break;
+                }
+                ////////////////////
+            case CONFIG_TRT_SET:       // read data in cache
+                // and post a PUT request in TRT
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_CONFIG) and
+                            "MEMC ERROR in CONFIG_TRT_SET state: bad DIR allocation");
+
+                    assert( (r_alloc_trt_fsm.read() == ALLOC_TRT_CONFIG) and
+                            "MEMC ERROR in CONFIG_TRT_SET state: bad TRT allocation");
+
+                    // read data into cache
+                    size_t          way = r_config_dir_way.read();
+                    size_t          set = m_y[r_config_address.read()];
+                    std::vector<data_t> data_vector;
+                    data_vector.clear();
+                    for(size_t word=0; word<m_words; word++) 
+                    {
+                        uint32_t data = m_cache_data.read( way, set, word );
+                        data_vector.push_back( data );
+                    }
+
+                    // post the PUT request in TRT
+                    m_trt.set( r_config_trt_index.read(),
+                               false,                               // PUT transaction
+                               m_nline[r_config_address.read()],    // line index
+                               0,                                   // srcid:       unused
+                               0,                                   // trdid:       unused
+                               0,                                   // pktid:       unused
+                               false,                               // not proc_read
+                               0,                                   // read_length: unused
+                               0,                                   // word_index:  unused
+                               std::vector<be_t>(m_words,0xF),      // byte-enable:     unused 
+                               data_vector,                         // data to be written
+                               0,                                   // ll_key:          unused
+                               true );                              // requested by config FSM
+
+                    config_rsp_lines_incr = true;
+                    r_config_fsm = CONFIG_PUT_REQ;
+
+#if DEBUG_MEMC_CONFIG
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CONFIG_TRT_SET> PUT request in TRT:"
+                            << " address = " << std::hex << r_config_address.read()
+                            << " index = " << std::dec << r_config_trt_index.read() << std::endl;
+#endif
+                    break;
+                }
+                ////////////////////
+            case CONFIG_PUT_REQ:       // post PUT request to IXR_CMD_FSM
+                {
+                    if ( not r_config_to_ixr_cmd_req.read() )
+                    {
+                        r_config_to_ixr_cmd_req   = true;
+                        r_config_to_ixr_cmd_index = r_config_trt_index.read();
+
+                        // prepare next iteration
+                        r_config_cmd_lines              = r_config_cmd_lines.read() - 1;
+                        r_config_address                = r_config_address.read() + (m_words<<2);
+                        r_config_fsm                    = CONFIG_LOOP;
+
+#if DEBUG_MEMC_CONFIG
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " CONFIG_PUT_REQ> post PUT request to IXR_CMD_FSM"
+                                << " / address = " << std::hex << r_config_address.read() << std::endl; 
+#endif
+                    }
+                    break;
+                }
+                /////////////////////
+            case CONFIG_IVT_LOCK:  // enter this state in case of INVAL command
+                // Keep DIR lock and Try to get IVT lock.
+                // Return to LOOP state if IVT full.
+                // Register inval in IVT, and invalidate the
+                // directory if IVT not full. 
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_CONFIG) and
+                            "MEMC ERROR in CONFIG_IVT_LOCK state: bad DIR allocation");
+
+                    if ( r_alloc_ivt_fsm.read() == ALLOC_IVT_CONFIG )
+                    {
+                        size_t set        = m_y[(addr_t)(r_config_address.read())];
+                        size_t way        = r_config_dir_way.read();
+
+                        if ( r_config_dir_count.read() == 0 )     // inval DIR and return to LOOP
+                        {
+                            m_cache_directory.inval( way, set );
+                            r_config_cmd_lines  = r_config_cmd_lines.read() - 1;
+                            r_config_address    = r_config_address.read() + (m_words<<2);
+                            r_config_fsm        = CONFIG_LOOP;
+
+#if DEBUG_MEMC_CONFIG
+                            if(m_debug)
+                                std::cout << "  <MEMC " << name() << " CONFIG_IVT_LOCK>"
+                                    << " No copies in L1 : inval DIR entry"  << std::endl;
+#endif
+                        }
+                        else    // try to register inval in IVT
+                        {
+                            bool        wok       = false;
+                            size_t      index     = 0;
+                            bool        broadcast = r_config_dir_is_cnt.read();
+                            size_t      srcid     = r_config_srcid.read();
+                            size_t      trdid     = r_config_trdid.read();
+                            size_t      pktid     = r_config_pktid.read();
+                            addr_t      nline     = m_nline[(addr_t)(r_config_address.read())];
+                            size_t      nb_copies = r_config_dir_count.read();
+
+                            wok = m_ivt.set(false,       // it's an inval transaction
+                                            broadcast,   
+                                            false,       // no response required
+                                            true,        // acknowledge required
+                                            srcid,
+                                            trdid,
+                                            pktid,
+                                            nline,
+                                            nb_copies,
+                                            index);
+
+                            if ( wok )  // IVT success => inval DIR slot
+                            {
+                                m_cache_directory.inval( way, set );
+                                r_config_ivt_index = index;
+                                config_rsp_lines_incr = true;
+                                if ( broadcast )  r_config_fsm = CONFIG_BC_SEND;
+                                else              r_config_fsm = CONFIG_INVAL_SEND;
+
+#if DEBUG_MEMC_CONFIG
+                                if(m_debug)
+                                    std::cout << "  <MEMC " << name() << " CONFIG_IVT_LOCK>"
+                                        << " Inval DIR entry and register inval in IVT"
+                                        << " : index = " << std::dec << index
+                                        << " / broadcast = " << broadcast << std::endl;
+#endif
+                            }
+                            else       // IVT full => release both DIR and IVT locks
+                            {
+                                r_config_fsm = CONFIG_LOOP;
+
+#if DEBUG_MEMC_CONFIG
+                                if(m_debug)
+                                    std::cout << "  <MEMC " << name() << " CONFIG_IVT_LOCK>"
+                                        << " IVT full : release DIR & IVT locks and retry" << std::endl;
+#endif
+                            }
+                        }
+                    }
+                    break;
+                }
+                ////////////////////
+            case CONFIG_BC_SEND:    // Post a broadcast inval request to CC_SEND FSM
+                {
+                    if( not r_config_to_cc_send_multi_req.read() and 
+                            not r_config_to_cc_send_brdcast_req.read() )
+                    {
+                        // post bc inval request
+                        r_config_to_cc_send_multi_req   = false;
+                        r_config_to_cc_send_brdcast_req = true;
+                        r_config_to_cc_send_trdid       = r_config_ivt_index.read();
+                        r_config_to_cc_send_nline       = m_nline[(addr_t)(r_config_address.read())];
+
+                        // prepare next iteration
+                        r_config_cmd_lines              = r_config_cmd_lines.read() - 1;
+                        r_config_address                = r_config_address.read() + (m_words<<2);
+                        r_config_fsm                    = CONFIG_LOOP;
+
+#if DEBUG_MEMC_CONFIG
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " CONFIG_BC_SEND>"
+                                << " Post a broadcast inval request to CC_SEND FSM" 
+                                << " / address = " << r_config_address.read() <<std::endl;
+#endif
+                    }
+                    break;
+                }
+                ///////////////////////
+            case CONFIG_INVAL_SEND:    // Post a multi inval request to CC_SEND FSM
+                {
+                    if( not r_config_to_cc_send_multi_req.read() and 
+                            not r_config_to_cc_send_brdcast_req.read() )
+                    {
+                        r_config_to_cc_send_multi_req   = true;
+                        r_config_to_cc_send_brdcast_req = false;
+                        r_config_to_cc_send_trdid       = r_config_ivt_index.read();
+                        r_config_to_cc_send_nline       = m_nline[(addr_t)(r_config_address.read())];
+
+                        // post data into FIFO
+                        config_to_cc_send_fifo_srcid    = r_config_dir_copy_srcid.read();
+                        config_to_cc_send_fifo_inst     = r_config_dir_copy_inst.read();
+                        config_to_cc_send_fifo_put      = true;
+
+                        if ( r_config_dir_count.read() == 1 )  // one copy
+                        {
+                            // prepare next iteration
+                            r_config_cmd_lines          = r_config_cmd_lines.read() - 1;
+                            r_config_address            = r_config_address.read() + (m_words<<2);
+                            r_config_fsm                = CONFIG_LOOP;
+                        }
+                        else                                   // several copies
+                        {
+                            r_config_fsm = CONFIG_HEAP_REQ;
+                        }
+
+#if DEBUG_MEMC_CONFIG
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " CONFIG_INVAL_SEND>"
+                                << " Post multi inval request to CC_SEND FSM" 
+                                << " / address = " << std::hex << r_config_address.read() 
+                                << " / copy = " << r_config_dir_copy_srcid.read() 
+                                << " / inst = " << std::dec << r_config_dir_copy_inst.read() << std::endl;
+#endif
+                    }
+                    break;
+                }
+                /////////////////////
+            case CONFIG_HEAP_REQ:  // Try to get access to Heap
+                {
+                    if ( r_alloc_heap_fsm.read() == ALLOC_HEAP_CONFIG )
+                    {
+                        r_config_fsm       = CONFIG_HEAP_SCAN;
+                        r_config_heap_next = r_config_dir_ptr.read();
+                    }
+
+#if DEBUG_MEMC_CONFIG
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CONFIG_HEAP_REQ>"
+                            << " Requesting HEAP lock" << std::endl;
+#endif
+                    break;
+                }
+                //////////////////////
+            case CONFIG_HEAP_SCAN:      // scan HEAP and send inval to CC_SEND FSM
+                {
+                    HeapEntry entry = m_heap.read( r_config_heap_next.read() );
+                    bool last_copy  = (entry.next == r_config_heap_next.read()); 
+
+                    config_to_cc_send_fifo_srcid = entry.owner.srcid;
+                    config_to_cc_send_fifo_inst  = entry.owner.inst;
+                    // config_to_cc_send_fifo_last  = last_copy;
+                    config_to_cc_send_fifo_put   = true;
+
+                    if ( m_config_to_cc_send_inst_fifo.wok() ) // inval request accepted
+                    {
+                        r_config_heap_next = entry.next;
+                        if ( last_copy ) r_config_fsm = CONFIG_HEAP_LAST;
+                    }
+
+#if DEBUG_MEMC_CONFIG
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CONFIG_HEAP_SCAN>"
+                            << " Post multi inval request to CC_SEND FSM" 
+                            << " / address = " << std::hex << r_config_address.read() 
+                            << " / copy = " << entry.owner.srcid 
+                            << " / inst = " << std::dec << entry.owner.inst << std::endl;
+#endif
+                    break;
+                }
+                //////////////////////
+            case CONFIG_HEAP_LAST:      // HEAP housekeeping
+                {
+                    size_t free_pointer = m_heap.next_free_ptr();
+                    HeapEntry last_entry;
+                    last_entry.owner.srcid = 0;
+                    last_entry.owner.inst  = false;
+
+                    if ( m_heap.is_full() )
+                    {
+                        last_entry.next = r_config_dir_ptr.read();
+                        m_heap.unset_full();
+                    }
+                    else
+                    { 
+                        last_entry.next = free_pointer;
+                    }
+
+                    m_heap.write_free_ptr( r_config_dir_ptr.read() );
+                    m_heap.write( r_config_heap_next.read(), last_entry );
+
+                    // prepare next iteration
+                    r_config_cmd_lines          = r_config_cmd_lines.read() - 1;
+                    r_config_address            = r_config_address.read() + (m_words<<2);
+                    r_config_fsm                = CONFIG_LOOP;
+
+#if DEBUG_MEMC_CONFIG
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CONFIG_HEAP_LAST>"
+                            << " Heap housekeeping" << std::endl;
+#endif
+                    break;
+                }
+        }  // end switch r_config_fsm
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    READ FSM
+        ////////////////////////////////////////////////////////////////////////////////////
+        // The READ FSM controls the VCI read  and ll requests.
+        // It takes the lock protecting the cache directory to check the cache line status:
+        // - In case of HIT
+        //   The fsm copies the data (one line, or one single word)
+        //   in the r_read_to_tgt_rsp buffer. It waits if this buffer is not empty.
+        //   The requesting initiator is registered in the cache directory.
+        //   If the number of copy is larger than 1, the new copy is registered
+        //   in the HEAP.
+        //   If the number of copy is larger than the threshold, the HEAP is cleared,
+        //   and the corresponding line switches to the counter mode.
+        // - In case of MISS
+        //   The READ fsm takes the lock protecting the transaction tab.
+        //   If a read transaction to the XRAM for this line already exists,
+        //   or if the transaction tab is full, the fsm is stalled.
+        //   If a TRT entry is free, the READ request is registered in TRT,
+        //   it is consumed in the request FIFO, and transmited to the IXR_CMD FSM.
+        //   The READ FSM returns in the IDLE state as the read transaction will be
+        //   completed when the missing line will be received.
+        ////////////////////////////////////////////////////////////////////////////////////
+
+        switch(r_read_fsm.read())
+        {
+            ///////////////
+            case READ_IDLE:  // waiting a read request
+                {
+                    if(m_cmd_read_addr_fifo.rok())
+                    {
+
+                        bool not_length_one_line   = m_cmd_read_length_fifo.read() != m_words;
+                        bool not_first_word_zero   = m_x[(addr_t) m_cmd_read_addr_fifo.read()];
+                        bool is_ll                 = (m_cmd_read_pktid_fifo.read() & 0x7) == TYPE_LL;
+
+#if DEBUG_MEMC_READ
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " READ_IDLE> Read request"
+                                << " : address = " << std::hex << m_cmd_read_addr_fifo.read()
+                                << " / srcid = " << m_cmd_read_srcid_fifo.read()
+                                << " / trdid = " << m_cmd_read_trdid_fifo.read()
+                                << " / pktid = " << m_cmd_read_pktid_fifo.read()
+                                << " / nwords = " << std::dec << m_cmd_read_length_fifo.read() << std::endl;
+#endif
+                        r_read_ll_done    = false;
+                        r_read_need_block = is_ll or not_length_one_line or not_first_word_zero; 
+                        r_read_fsm        = READ_DIR_REQ;
+                    }
+                    break;
+                }
+
+                //////////////////
+            case READ_DIR_REQ:  // Get the lock to the directory
+                {
+                    if(r_alloc_dir_fsm.read() == ALLOC_DIR_READ)
+                    {
+                        r_read_fsm = READ_DIR_LOCK;
+                        m_cpt_read_fsm_n_dir_lock++;
+                    }
+
+#if DEBUG_MEMC_READ
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " READ_DIR_REQ> Requesting DIR lock " << std::endl;
+#endif
+
+                    m_cpt_read_fsm_dir_lock++;
+
+                    break;
+                }
+
+                ///////////////////
+            case READ_DIR_LOCK:  // check directory for hit / miss
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_READ) and
+                            "MEMC ERROR in READ_DIR_LOCK state: Bad DIR allocation");
+
+                    size_t way = 0;
+                    DirectoryEntry entry =
+                        m_cache_directory.read(m_cmd_read_addr_fifo.read(), way);
+                    if(((m_cmd_read_pktid_fifo.read() & 0x7) == TYPE_LL) and not r_read_ll_done.read())   // access the global table ONLY when we have an LL cmd
+                    {
+                        r_read_ll_key   = m_llsc_table.ll(m_cmd_read_addr_fifo.read());
+                        /**//*std::cout << "MEMCACHE : from proc " << m_cmd_read_srcid_fifo.read()
+                              << " | @ " << std::hex << m_cmd_read_addr_fifo.read()
+                              << " | LL" << std::endl;*/
+                        r_read_ll_done  = true;
+                    }
+                    r_read_is_cnt           = entry.is_cnt;
+                    r_read_dirty            = entry.dirty;
+                    r_read_lock             = entry.lock;
+                    r_read_tag              = entry.tag;
+                    r_read_way              = way;
+                    r_read_count            = entry.count;
+                    r_read_copy             = entry.owner.srcid;
+                    r_read_copy_inst        = entry.owner.inst;
+                    r_read_ptr              = entry.ptr; // pointer to the heap
+                    r_read_state            = entry.state;
+
+                    // check if this is a cached read, this means pktid is either
+                    // TYPE_READ_DATA_MISS 0bX001 with TSAR encoding
+                    // TYPE_READ_INS_MISS  0bX011 with TSAR encoding
+                    bool cached_read = ((m_cmd_read_pktid_fifo.read() & 0x7) != 0) and ((m_cmd_read_pktid_fifo.read() & 0x7) != 0x2) and ((m_cmd_read_pktid_fifo.read() & 0x7) != 0x6);
+
+                    if(entry.state == ENTRY_SHARED or entry.state == ENTRY_EXCLUSIVE)    // hit
+                    {
+                        if ( (m_cmd_read_pktid_fifo.read() & 0x7) == TYPE_WRITE )
+                        {
+                                // Invalid the line in the others processors and put the line in trt with data.
+                                if( entry.count == 0 or ((entry.count == 1) and (entry.state == ENTRY_SHARED) and (entry.owner.srcid == m_cmd_read_srcid_fifo.read())))
+                                {
+                                    r_read_fsm = READ_DIR_HIT;
+                                }
+                                else
+                                {
+                                    if((entry.state == ENTRY_EXCLUSIVE) and (entry.owner.srcid == m_cmd_read_srcid_fifo.read())) 
+                                    {
+                                        std::cout <<"exclusive line && srcid != read srcid "<< std::endl;
+                                        exit(0);
+                                    }
+                                    r_read_fsm = READ_IVT_INVAL_LOCK;
+                                }
+                        }
+                        else // a read miss request 
+                        {
+                            if ( entry.state == ENTRY_SHARED or entry.count == 0)
+                            {
+                                if( entry.is_cnt or (entry.count == 0) or (not cached_read))
+                                {
+                                    r_read_fsm = READ_DIR_HIT;
+                                }
+                                else
+                                {
+                                    r_read_fsm = READ_HEAP_REQ;
+                                }
+                            }
+                            else if ( entry.state == ENTRY_EXCLUSIVE ) 
+                            {
+                                r_read_fsm = READ_IVT_UPDT_LOCK;
+                            }   
+                        } 
+                    }
+                    else if(entry.state == ENTRY_LOCKED) // the line is locked, can't use it at this time
+                    {
+                        r_read_fsm = READ_WAIT;
+                    }
+                    else      // miss
+                    {
+                        r_read_fsm = READ_TRT_LOCK;
+                    }
+
+#if DEBUG_MEMC_READ
+                    if(m_debug)
+                    {
+                        std::cout << "  <MEMC " << name() << " READ_DIR_LOCK> Accessing directory: "
+                            << " address = " << std::hex << m_cmd_read_addr_fifo.read()
+                            << " / hit = " << std::dec << entry.state
+                            << " / way = " << std::dec << way
+                            << " / count = " <<std::dec << entry.count
+                            << " / is_cnt = " << entry.is_cnt << std::endl;
+                        if((m_cmd_read_pktid_fifo.read() & 0x7) == TYPE_LL) std::cout << " / LL access" << std::endl;
+                        else                                                std::cout << std::endl;
+                    }
+#endif
+                    break;
+                }
+
+                ///////////////////
+            case READ_IVT_INVAL_LOCK:
+                {
+                    if (r_alloc_ivt_fsm.read() == ALLOC_IVT_READ)
+                    {
+                        size_t index;
+                        addr_t nline            = m_nline[(addr_t)(m_cmd_read_addr_fifo.read())];
+                        size_t set              = m_y[(addr_t)(m_cmd_read_addr_fifo.read())];
+                        bool multi_req          = not r_read_is_cnt.read();
+                        bool last_multi_req     = multi_req and (r_read_count.read() == 1);
+                        bool not_last_multi_req = multi_req and (r_read_count.read() != 1);
+                        bool match_send         = (r_read_copy.read() == m_cmd_read_srcid_fifo.read()) and
+                                                  (r_read_copy_inst.read() == 0);
+
+                        if(last_multi_req and match_send)
+                        {
+                            std::cout << "last_multi_req and match srcid are true" << std::endl;
+                            exit(0);
+                        }
+                        size_t ivt_send_count   = 0;
+
+                        if( m_ivt.is_full() or // not need to check match inval, because of the LOCKED STATE
+                            r_read_to_cc_send_multi_req.read() or 
+                            r_read_to_cc_send_brdcast_req.read() or
+                            (r_read_to_cleanup_req.read() and r_read_need_block.read())) // need block read if is ll or read non align 
+ 
+                        {
+                            r_read_fsm = READ_WAIT;
+#if DEBUG_MEMC_READ
+                            if(m_debug)
+                            {
+                                std::cout
+                                    << "  <MEMC " << name() << " READ_IVT_LOCK>" 
+                                    << " Wait cleanup completion"
+                                    << std::endl;
+                            }
+#endif
+                        }
+                        else
+                        {
+                            DirectoryEntry entry;
+                            entry.state         = ENTRY_LOCKED;  //lock the line in dir memcache
+                            entry.is_cnt        = r_read_is_cnt.read();
+                            entry.lock          = r_read_lock.read();
+                            entry.dirty         = r_read_dirty.read();
+                            entry.tag           = r_read_tag.read();
+                            entry.ptr           = r_read_ptr.read();
+                            entry.owner.srcid   = r_read_copy.read();
+                            entry.owner.inst    = r_read_copy_inst.read();
+                            entry.count         = r_read_count.read();
+                            m_cache_directory.write(set, r_read_way.read(), entry);
+                            
+                            r_read_to_cc_send_multi_req     = last_multi_req;
+                            r_read_to_cc_send_brdcast_req   = not multi_req;
+                            r_read_to_cc_send_nline         = nline;
+                            r_read_to_cc_send_srcid         = m_cmd_read_srcid_fifo.read();
+                            if(r_read_need_block.read())
+                            {
+                                r_read_to_cleanup_nline         = nline;
+                                r_read_to_cleanup_length        = m_cmd_read_length_fifo.read();
+                                r_read_to_cleanup_first_word    = m_x[(addr_t) m_cmd_read_addr_fifo.read()];
+                                r_read_to_cleanup_ll_key        = r_read_ll_key.read(); 
+                                r_read_to_cleanup_req           = true; 
+                            }
+                            r_read_to_cc_send_type          = true;
+
+                            if(not match_send)
+                            {
+                                read_to_cc_send_fifo_srcid      = r_read_copy.read();
+                                read_to_cc_send_fifo_inst       = r_read_copy_inst.read();
+                                read_to_cc_send_fifo_put        = multi_req;
+                            }   
+                            r_read_next_ptr                 = r_read_ptr.read();
+
+                            if(((m_cmd_read_pktid_fifo.read() & 0x8) == 0x8) and (r_read_state.read() == ENTRY_SHARED))  
+                                ivt_send_count = r_read_count.read() - 1;
+                            else
+                                ivt_send_count = r_read_count.read();
+                            m_ivt.set(false,            // it's an inval transaction
+                                      not multi_req,    // multi_inval or brdcast  
+                                      true,             // it needs a read response
+                                      false,            // no acknowledge required
+                                      m_cmd_read_srcid_fifo.read(),
+                                      m_cmd_read_trdid_fifo.read(),
+                                      m_cmd_read_pktid_fifo.read() & 0x7,
+                                      nline,
+                                      ivt_send_count,
+                                      index);
+                                
+                            if( not_last_multi_req ) 
+                            {
+                                r_read_fsm = READ_INVAL_HEAP_REQ;
+                            }
+                            else
+                            {
+                                 r_read_fsm        = READ_IDLE;
+                                 cmd_read_fifo_get = true;
+                            }    
+#if DEBUG_MEMC_READ
+                            if(m_debug)
+                            {
+                                std::cout
+                                    << "  <MEMC " << name() << " READ_IVT_INVAL_LOCK>" 
+                                    << " Inval req for a read for ownership request"
+                                    << " count " << ivt_send_count << " " << r_read_count.read() 
+                                    << std::endl;
+                            }
+#endif
+                        }
+                    }
+                    break;
+                }
+                //////////////////
+            case READ_INVAL_HEAP_REQ:
+                {
+                    if( r_alloc_heap_fsm.read() == ALLOC_HEAP_READ )
+                    {
+                        r_read_fsm = READ_INVAL_HEAP_ERASE;
+                    }
+#if DEBUG_MEMC_READ
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " READ_INVAL_HEAP_REQ>"
+                            << " Requesting HEAP lock" << std::endl;
+#endif
+                    break;
+                }
+                //////////////////
+            case READ_INVAL_HEAP_ERASE:
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_READ)
+                    {
+                        HeapEntry entry = m_heap.read(r_read_next_ptr.read());
+
+                        bool match_send         = ( entry.owner.srcid == m_cmd_read_srcid_fifo.read()) and
+                                                  ( entry.owner.inst  == 0);
+                        if(not match_send) 
+                        {
+                            read_to_cc_send_fifo_srcid    = entry.owner.srcid;
+                            read_to_cc_send_fifo_inst     = entry.owner.inst;
+                            read_to_cc_send_fifo_put      = true;
+                        }
+                     //   if(read_to_cc_send_inst_fifo.wok()) always not full
+                        r_read_next_ptr = entry.next;
+                        if(entry.next == r_read_next_ptr.read())   // last copy
+                        {
+                            r_read_to_cc_send_multi_req     = true;
+                            r_read_fsm                      = READ_INVAL_HEAP_LAST;
+                        }
+                        else
+                        {
+                            r_read_fsm = READ_INVAL_HEAP_ERASE;
+                        }
+
+#if DEBUG_MEMC_READ
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " READ_HEAP_ERASE>"
+                                << " Erase copy:"
+                                << " srcid = " << std::hex << entry.owner.srcid
+                                << " / inst = " << std::dec << entry.owner.inst << std::endl;
+#endif
+                    }
+                    break;
+                }
+                /////////////////////////
+            case READ_INVAL_HEAP_LAST:  // last copy
+                {
+                    if(r_alloc_heap_fsm.read() != ALLOC_HEAP_READ)
+                    {
+                        std::cout << "VCI_MEM_CACHE ERROR " << name() << " READ_INVAL_HEAP_LAST"
+                            << " bad HEAP allocation" << std::endl;
+                        exit(0);
+                    }
+                    size_t free_pointer = m_heap.next_free_ptr();
+
+                    HeapEntry last_entry;
+                    last_entry.owner.srcid    = 0;
+                    last_entry.owner.inst     = false;
+                    if(m_heap.is_full())
+                    {
+                        last_entry.next     = r_read_next_ptr.read();
+                        m_heap.unset_full();
+                    }
+                    else
+                    {
+                        last_entry.next     = free_pointer;
+                    }
+
+                    m_heap.write_free_ptr(r_read_ptr.read());
+                    m_heap.write(r_read_next_ptr.read(),last_entry);
+
+                    r_read_fsm        = READ_IDLE;
+                    cmd_read_fifo_get = true;
+
+#if DEBUG_MEMC_READ
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " READ_INVAL_HEAP_LAST>"
+                            << " Heap housekeeping" << std::endl;
+#endif
+                    break;
+                }
+                /////////////////////////
+            case READ_IVT_UPDT_LOCK:  // read miss in the e/m state, demand cache L1 for the updated line.
+                {
+                    if (r_alloc_ivt_fsm.read() == ALLOC_IVT_READ)
+                    {
+                        size_t index;
+                        addr_t nline            = m_nline[(addr_t)(m_cmd_read_addr_fifo.read())];
+                        size_t set              = m_y[(addr_t)(m_cmd_read_addr_fifo.read())];
+                        if( m_ivt.is_full() or 
+                            r_read_to_cc_send_multi_req.read() or 
+                            r_read_to_cc_send_brdcast_req.read() or 
+                           (r_read_to_multi_ack_req.read() and r_read_need_block.read())) // ll or read not align block the request
+                        {
+                            r_read_fsm = READ_WAIT;
+#if DEBUG_MEMC_READ
+                            if(m_debug)
+                            {
+                                std::cout
+                                    << "  <MEMC " << name() << " READ_IVT_LOCK>" 
+                                    << " Wait cleanup completion"
+                                    << std::endl;
+                            }
+#endif
+                        }
+                        else
+                        {
+                            DirectoryEntry entry;
+                            entry.state         = ENTRY_LOCKED;  //lock the line in dir memcache
+                            entry.is_cnt        = r_read_is_cnt.read();
+                            entry.lock          = r_read_lock.read();
+                            entry.dirty         = r_read_dirty.read();
+                            entry.tag           = r_read_tag.read();
+                            entry.ptr           = r_read_ptr.read();
+                            entry.owner.srcid   = r_read_copy.read();
+                            entry.owner.inst    = r_read_copy_inst.read();
+                            entry.count         = r_read_count.read();
+                            m_cache_directory.write(set, r_read_way.read(), entry);
+                            
+                            if(r_read_need_block.read())
+                            {
+                                r_read_to_multi_ack_nline       = nline;
+                                r_read_to_multi_ack_length      = m_cmd_read_length_fifo.read();
+                                r_read_to_multi_ack_first_word  = m_x[(addr_t) m_cmd_read_addr_fifo.read()];
+                                r_read_to_multi_ack_ll_key      = r_read_ll_key.read(); 
+                                r_read_to_multi_ack_req         = true; 
+                            }
+ 
+                            r_read_to_cc_send_multi_req     = true;
+                            r_read_to_cc_send_brdcast_req   = false;
+                            r_read_to_cc_send_nline         = nline;
+                            r_read_to_cc_send_type          = false;
+           
+                            read_to_cc_send_fifo_srcid      = r_read_copy.read();
+                            read_to_cc_send_fifo_inst       = r_read_copy_inst.read();
+                            read_to_cc_send_fifo_put        = true;
+
+                            bool ivt_set_valid = m_ivt.set(true,              // it's an updt request
+                                                           false,             // multi_inval  
+                                                           true,              // it needs a read response
+                                                           true,              // acknowledge required
+                                                           m_cmd_read_srcid_fifo.read(),
+                                                           m_cmd_read_trdid_fifo.read(),
+                                                           m_cmd_read_pktid_fifo.read(),
+                                                           nline,
+                                                           0x01,
+                                                           index);
+
+                            r_read_to_cc_send_ivt_index     = index;
+                            r_read_fsm        = READ_IDLE;
+                            cmd_read_fifo_get = true;
+
+#if DEBUG_MEMC_READ
+                            if(m_debug)
+                            {
+                                 std::cout
+                                     << "  <MEMC " << name() << " READ_IVT_UPDT_LOCK>" 
+                                    << " ivt index =" << index
+                                    << " ivt set valid =" << ivt_set_valid
+                                    << "read need block =" << r_read_need_block.read()
+                                    << "word =" << m_x[(addr_t) m_cmd_read_addr_fifo.read()]
+                                    << "length =" << m_cmd_read_length_fifo.read()
+                                    << std::endl;
+                            }  
+#endif
+                        }
+                    }
+
+                    break;
+                }
+                //////////////////
+            case READ_WAIT://Release the locks
+                {
+                    r_read_fsm = READ_DIR_REQ;
+#if DEBUG_MEMC_READ
+                    if(m_debug)
+                    {
+                        std::cout
+                            << "  <MEMC " << name() << " READ_WAIT>" << std::endl;
+                    }
+#endif
+                    break;
+                }
+                ///////////////////                      
+            case READ_DIR_HIT:    //  read data in cache & update the directory
+                //  we enter this state in 3 cases:
+                //  - the read request is uncachable
+                //  - the cache line is in counter mode
+                //  - the cache line is valid but not replicated
+
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_READ) and
+                            "MEMC ERROR in READ_DIR_HIT state: Bad DIR allocation");
+                    // check if this is an instruction read, this means pktid is either
+                    // TYPE_READ_INS_UNC   0bX010 with TSAR encoding
+                    // TYPE_READ_INS_MISS  0bX011 with TSAR encoding
+                    bool inst_read    = ((m_cmd_read_pktid_fifo.read() & 0x2) != 0);
+                    // check if this is a cached read, this means pktid is either
+                    // TYPE_READ_DATA_MISS 0bX001 with TSAR encoding
+                    // TYPE_READ_INS_MISS  0bX011 with TSAR encoding
+                    bool cached_read  = ((m_cmd_read_pktid_fifo.read() & 0x7) != 0) and ((m_cmd_read_pktid_fifo.read() & 0x7) != 0x2) and ((m_cmd_read_pktid_fifo.read() & 0x7) != 0x6);
+                    bool is_cnt       = r_read_is_cnt.read();
+
+                    bool is_getm      = (m_cmd_read_pktid_fifo.read() & 0x7) == TYPE_WRITE;
+                    // read data in the cache
+                    size_t set        = m_y[(addr_t)(m_cmd_read_addr_fifo.read())];
+                    size_t way        = r_read_way.read();
+
+                    m_cache_data.read_line(way, set, r_read_data);
+
+                    // update the cache directory
+                    DirectoryEntry entry;
+
+                    if(inst_read)
+                    {
+                        entry.state = ENTRY_SHARED;
+                    }
+                    else if(is_getm)
+                    {
+                        entry.state = ENTRY_EXCLUSIVE;
+                    }
+                    else 
+                    {
+                        entry.state = r_read_state.read();
+                    }
+ 
+                    //entry.cache_coherent = r_read_coherent.read() or inst_read or (!(cached_read)) or (r_read_copy.read() != m_cmd_read_srcid_fifo.read());
+                    if( entry.state == ENTRY_SHARED) r_read_shared = true;
+                        else    r_read_shared = false;
+                    entry.is_cnt  = is_cnt;
+                    entry.dirty   = r_read_dirty.read();
+                    entry.tag     = r_read_tag.read();
+                    entry.lock    = r_read_lock.read();
+                    entry.ptr     = r_read_ptr.read();
+                    if(cached_read)   // Cached read => we must update the copies
+                    {
+                        if(is_getm)
+                        {
+                            entry.owner.srcid    = m_cmd_read_srcid_fifo.read();
+                            entry.owner.inst     = 0;
+                            entry.count          = 1;
+ 
+                        }
+                        else if(!is_cnt)  // Not counter mode
+                        {
+                            entry.owner.srcid    = m_cmd_read_srcid_fifo.read();
+                            entry.owner.inst     = inst_read;
+                            entry.count          = r_read_count.read() + 1;
+                        }
+                        else  // Counter mode
+                        {
+                            entry.owner.srcid    = 0;
+                            entry.owner.inst     = false;
+                            entry.count          = r_read_count.read() + 1;
+                        }
+                    }
+                    else            // Uncached read
+                    {
+                        entry.owner.srcid     = r_read_copy.read();
+                        entry.owner.inst      = r_read_copy_inst.read();
+                        entry.count           = r_read_count.read();
+                    }
+
+#if DEBUG_MEMC_READ
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " READ_DIR_HIT> Update directory entry:"
+                            << " addr = " << std::hex << m_cmd_read_addr_fifo.read()
+                            << " / set = " << std::dec << set
+                            << " / way = " << way
+                            << " / cached read = " << cached_read
+                            << " / owner_id = " << std::hex << entry.owner.srcid
+                            << " / owner_ins = " << std::dec << entry.owner.inst
+                            << " / count = " << entry.count
+                            << " / is_cnt = " << entry.is_cnt << std::endl;
+#endif
+
+                    m_cache_directory.write(set, way, entry);
+                    r_read_fsm    = READ_RSP;
+
+                    break;
+                }
+                ///////////////////
+            case READ_HEAP_REQ:    // Get the lock to the HEAP directory
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_READ)
+                    {
+                        r_read_fsm = READ_HEAP_LOCK;
+                        m_cpt_read_fsm_n_heap_lock++;
+                    }
+
+#if DEBUG_MEMC_READ
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " READ_HEAP_REQ>"
+                            << " Requesting HEAP lock " << std::endl;
+#endif
+
+                    m_cpt_read_fsm_heap_lock++;
+
+                    break;
+                }
+
+                ////////////////////
+            case READ_HEAP_LOCK:   // read data in cache, update the directory
+                // and prepare the HEAP update
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_READ)
+                    {
+                        // enter counter mode when we reach the limit of copies or the heap is full
+                        bool go_cnt = (r_read_count.read() >= m_max_copies) or m_heap.is_full();
+
+                        assert (r_read_state.read() == ENTRY_SHARED && " access heap for a exlusive line ");
+                        // read data in the cache
+                        size_t set = m_y[(addr_t)(m_cmd_read_addr_fifo.read())];
+                        size_t way = r_read_way.read();
+
+                        m_cache_data.read_line(way, set, r_read_data);
+
+                        // update the cache directory
+                        DirectoryEntry entry;
+                        entry.state  = r_read_state.read();
+                        entry.is_cnt = go_cnt;
+                        entry.dirty  = r_read_dirty.read();
+                        entry.tag    = r_read_tag.read();
+                        entry.lock   = r_read_lock.read();
+                        entry.count  = r_read_count.read() + 1;
+
+                        if(not go_cnt)         // Not entering counter mode
+                        {
+                            entry.owner.srcid    = r_read_copy.read();
+                            entry.owner.inst     = r_read_copy_inst.read();
+                            entry.ptr            = m_heap.next_free_ptr();   // set pointer on the heap
+                        }
+                        else                // Entering Counter mode
+                        {
+                            entry.owner.srcid    = 0;
+                            entry.owner.inst     = false;
+                            entry.ptr            = 0;
+                        }
+
+                        m_cache_directory.write(set, way, entry);
+
+                        // prepare the heap update (add an entry, or clear the linked list)
+                        if(not go_cnt)      // not switching to counter mode
+                        {
+                            // We test if the next free entry in the heap is the last
+                            HeapEntry heap_entry = m_heap.next_free_entry();
+                            r_read_next_ptr      = heap_entry.next;
+                            r_read_last_free     = (heap_entry.next == m_heap.next_free_ptr());
+
+                            r_read_fsm           = READ_HEAP_WRITE; // add an entry in the HEAP
+                        }
+                        else            // switching to counter mode
+                        {
+                            if(r_read_count.read() >1)              // heap must be cleared
+                            {
+                                HeapEntry next_entry = m_heap.read(r_read_ptr.read());
+                                r_read_next_ptr      = m_heap.next_free_ptr();
+                                m_heap.write_free_ptr(r_read_ptr.read());
+
+                                if(next_entry.next == r_read_ptr.read())    // last entry
+                                {
+                                    r_read_fsm = READ_HEAP_LAST;    // erase the entry
+                                }
+                                else                                        // not the last entry
+                                {
+                                    r_read_ptr = next_entry.next;
+                                    r_read_fsm = READ_HEAP_ERASE;   // erase the list
+                                }
+                            }
+                            else  // the heap is not used / nothing to do
+                            {
+                                r_read_fsm = READ_RSP;
+                            }
+                        }
+
+#if DEBUG_MEMC_READ
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " READ_HEAP_LOCK> Update directory:"
+                                << " tag = " << std::hex << entry.tag
+                                << " set = " << std::dec << set
+                                << " way = " << way
+                                << " count = " << entry.count
+                                << " is_cnt = " << entry.is_cnt << std::endl;
+#endif
+                    }
+                    else
+                    {
+                        std::cout << "VCI_MEM_CACHE ERROR " << name() << " READ_HEAP_LOCK"
+                            << "Bad HEAP allocation"   << std::endl;
+                        exit(0);
+                    }
+                    break;
+                }
+                /////////////////////
+            case READ_HEAP_WRITE:       // add an entry in the heap
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_READ)
+                    {
+                        HeapEntry heap_entry;
+                        heap_entry.owner.srcid    = m_cmd_read_srcid_fifo.read();
+                        heap_entry.owner.inst     = ((m_cmd_read_pktid_fifo.read() & 0x2) != 0);
+
+                        if(r_read_count.read() == 1)  // creation of a new linked list
+                        {
+                            heap_entry.next         = m_heap.next_free_ptr();
+                        }
+                        else                         // head insertion in existing list
+                        {
+                            heap_entry.next         = r_read_ptr.read();
+                        }
+                        m_heap.write_free_entry(heap_entry);
+                        m_heap.write_free_ptr(r_read_next_ptr.read());
+                        if(r_read_last_free.read())  m_heap.set_full();
+
+                        r_read_shared = true;
+                        r_read_fsm    = READ_RSP;
+
+#if DEBUG_MEMC_READ
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " READ_HEAP_WRITE> Add an entry in the heap:"
+                                << " owner_id = " << std::hex << heap_entry.owner.srcid
+                                << " owner_ins = " << std::dec << heap_entry.owner.inst << std::endl;
+#endif
+                    }
+                    else
+                    {
+                        std::cout << "VCI_MEM_CACHE ERROR " << name() << " READ_HEAP_WRITE"
+                            << "Bad HEAP allocation" << std::endl;
+                        exit(0);
+                    }
+                    break;
+                }
+                /////////////////////
+            case READ_HEAP_ERASE:
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_READ)
+                    {
+                        HeapEntry next_entry = m_heap.read(r_read_ptr.read());
+                        if(next_entry.next == r_read_ptr.read())
+                        {
+                            r_read_fsm = READ_HEAP_LAST;
+                        }
+                        else
+                        {
+                            r_read_ptr = next_entry.next;
+                            r_read_fsm = READ_HEAP_ERASE;
+                        }
+                    }
+                    else
+                    {
+                        std::cout << "VCI_MEM_CACHE ERROR " << name() << " READ_HEAP_ERASE"
+                            << "Bad HEAP allocation" << std::endl;
+                        exit(0);
+                    }
+                    break;
+                }
+
+                ////////////////////
+            case READ_HEAP_LAST:
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_READ)
+                    {
+                        HeapEntry last_entry;
+                        last_entry.owner.srcid    = 0;
+                        last_entry.owner.inst     = false;
+
+                        if(m_heap.is_full())
+                        {
+                            last_entry.next       = r_read_ptr.read();
+                            m_heap.unset_full();
+                        }
+                        else
+                        {
+                            last_entry.next       = r_read_next_ptr.read();
+                        }
+                        m_heap.write(r_read_ptr.read(),last_entry);
+                        r_read_fsm = READ_RSP;
+                    }
+                    else
+                    {
+                        std::cout << "VCI_MEM_CACHE ERROR " << name() << " READ_HEAP_LAST"
+                            << "Bad HEAP allocation" << std::endl;
+                        exit(0);
+                    }
+                    break;
+                }
+                //////////////
+            case READ_RSP:    //  request the TGT_RSP FSM to return data
+                {
+                    if(not r_read_to_tgt_rsp_req.read())
+                    {
+                        for(size_t i=0 ; i<m_words ; i++)  r_read_to_tgt_rsp_data[i] = r_read_data[i];
+                        r_read_to_tgt_rsp_word   = m_x[(addr_t) m_cmd_read_addr_fifo.read()];
+                        r_read_to_tgt_rsp_length = m_cmd_read_length_fifo.read();
+                        r_read_to_tgt_rsp_srcid  = m_cmd_read_srcid_fifo.read();
+                        //r_read_to_tgt_rsp_type   = r_read_rsp_type;
+                        if (r_read_shared.read())
+                        {
+                            r_read_to_tgt_rsp_pktid = 0x0 + (m_cmd_read_pktid_fifo.read() & 0x7);
+                        }
+                        else
+                        {
+                            r_read_to_tgt_rsp_pktid = 0x8 + (m_cmd_read_pktid_fifo.read() & 0x7);
+                        }
+                        r_read_to_tgt_rsp_trdid  = m_cmd_read_trdid_fifo.read();
+                        r_read_to_tgt_rsp_ll_key = r_read_ll_key.read();
+                        cmd_read_fifo_get        = true;
+                        r_read_to_tgt_rsp_req    = true;
+                        r_read_fsm               = READ_IDLE;
+
+#if DEBUG_MEMC_READ
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " READ_RSP> Request TGT_RSP FSM to return data:"
+                                << " rsrcid = " << std::hex << m_cmd_read_srcid_fifo.read()
+                                << " / address = " << std::hex << m_cmd_read_addr_fifo.read()
+                                << " / nwords = " << std::dec << m_cmd_read_length_fifo.read() << std::endl;
+#endif
+                    }
+                    break;
+                }
+                ///////////////////
+            case READ_TRT_LOCK: // read miss : check the Transaction Table
+                {
+                    if(r_alloc_trt_fsm.read() == ALLOC_TRT_READ)
+                    {
+                        size_t      index     = 0;
+                        size_t      index_write     = 0;
+                        addr_t      addr      = (addr_t) m_cmd_read_addr_fifo.read();
+                        bool        hit_read  = m_trt.hit_read(m_nline[addr], index);
+                        bool        hit_write = m_trt.hit_write(m_nline[addr],&index_write);
+                        bool        wok       = !m_trt.full(index);
+                        
+                        //if(hit_write) m_trt.print(index_write);
+                        if(hit_read or !wok or hit_write)    // missing line already requested or no space
+                        {
+                            if(!wok)
+                            {
+                                m_cpt_trt_full++;
+                            }
+                            if(hit_read or hit_write)   m_cpt_trt_rb++;
+                            r_read_fsm = READ_IDLE;
+                        }
+                        else                  // missing line is requested to the XRAM
+                        {
+                            m_cpt_read_miss++;
+                            r_read_trt_index = index;
+                            r_read_fsm       = READ_TRT_SET;
+                        }
+
+#if DEBUG_MEMC_READ
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " READ_TRT_LOCK> Check TRT:"
+                                << " hit_read = " << hit_read
+                                << " / hit_write = " << hit_write
+                                << " / full = " << !wok << std::endl;
+                        m_cpt_read_fsm_n_trt_lock++;
+#endif
+                    }
+
+                    m_cpt_read_fsm_trt_lock++;
+
+                    break;
+                }
+
+                //////////////////
+            case READ_TRT_SET:      // register get transaction in TRT
+                {
+                    if(r_alloc_trt_fsm.read() == ALLOC_TRT_READ)
+                    {
+                        m_trt.set(r_read_trt_index.read(),
+                                  true,
+                                  m_nline[(addr_t)(m_cmd_read_addr_fifo.read())],
+                                  m_cmd_read_srcid_fifo.read(),
+                                  m_cmd_read_trdid_fifo.read(),
+                                  m_cmd_read_pktid_fifo.read() & 0x7,
+                                  true,
+                                  m_cmd_read_length_fifo.read(),
+                                  m_x[(addr_t)(m_cmd_read_addr_fifo.read())],
+                                  std::vector<be_t> (m_words,0),
+                                  std::vector<data_t> (m_words,0),
+                                  r_read_ll_key.read());
+
+#if DEBUG_MEMC_READ
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " READ_TRT_SET> Set a GET in TGT:"
+                                << " address = " << std::hex << m_cmd_read_addr_fifo.read()
+                                << " / srcid = " << std::hex << m_cmd_read_srcid_fifo.read() << std::endl;
+#endif
+                        r_read_fsm = READ_TRT_REQ;
+                    }
+                    break;
+                }
+
+                //////////////////
+            case READ_TRT_REQ:   // consume the read request in FIFO and send it to IXR_CMD_FSM
+                {
+                    if(not r_read_to_ixr_cmd_req)
+                    {
+                        cmd_read_fifo_get       = true;
+                        r_read_to_ixr_cmd_req   = true;
+                        //r_read_to_ixr_cmd_nline = m_nline[(addr_t)(m_cmd_read_addr_fifo.read())];
+                        r_read_to_ixr_cmd_index = r_read_trt_index.read();
+                        r_read_fsm              = READ_IDLE;
+
+#if DEBUG_MEMC_READ
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " READ_TRT_REQ> Request GET transaction for address "
+                                << std::hex << m_cmd_read_addr_fifo.read() << std::endl;
+#endif
+                    }
+                    break;
+                }
+        } // end switch read_fsm
+
+        ///////////////////////////////////////////////////////////////////////////////////
+        //    WRITE FSM
+        ///////////////////////////////////////////////////////////////////////////////////
+        // The WRITE FSM handles the write bursts and sc requests sent by the processors.
+        // All addresses in a burst must be in the same cache line.
+        // A complete write burst is consumed in the FIFO & copied to a local buffer.
+        // Then the FSM takes the lock protecting the cache directory, to check
+        // if the line is in the cache.
+        //
+        // - In case of HIT, the cache is updated.
+        //   If there is no other copy, an acknowledge response is immediately
+        //   returned to the writing processor.
+        //   If the data is cached by other processors, a coherence transaction must
+        //   be launched (sc requests always require a coherence transaction):
+        //   It is a multicast update if the line is not in counter mode: the processor
+        //   takes the lock protecting the Update Table (UPT) to register this transaction.
+        //   If the UPT is full, it releases the lock(s) and retry. Then, it sends
+        //   a multi-update request to all owners of the line (but the writer),
+        //   through the CC_SEND FSM. In case of coherence transaction, the WRITE FSM
+        //   does not respond to the writing processor, as this response will be sent by
+        //   the MULTI_ACK FSM when all update responses have been received.
+        //   It is a broadcast invalidate if the line is in counter mode: The line
+        //   should be erased in memory cache, and written in XRAM with a PUT transaction,
+        //   after registration in TRT.
+        //
+        // - In case of MISS, the WRITE FSM takes the lock protecting the transaction
+        //   table (TRT). If a read transaction to the XRAM for this line already exists,
+        //   it writes in the TRT (write buffer). Otherwise, if a TRT entry is free,
+        //   the WRITE FSM register a new transaction in TRT, and sends a GET request
+        //   to the XRAM. If the TRT is full, it releases the lock, and waits.
+        //   Finally, the WRITE FSM returns an aknowledge response to the writing processor.
+        /////////////////////////////////////////////////////////////////////////////////////
+
+        switch(r_write_fsm.read())
+        {
+            ////////////////
+            case WRITE_IDLE:  // copy first word of a write burst in local buffer
+                {
+                    if (not m_cmd_write_addr_fifo.rok()) break;
+                    // consume a word in the FIFO & write it in the local buffer
+                    cmd_write_fifo_get  = true;
+                    size_t index        = m_x[(addr_t)(m_cmd_write_addr_fifo.read())];
+
+                    r_write_address     = (addr_t)(m_cmd_write_addr_fifo.read());
+                    r_write_word_index  = index;
+                    r_write_word_count  = 0;
+                    r_write_data[index] = m_cmd_write_data_fifo.read();
+                    r_write_srcid       = m_cmd_write_srcid_fifo.read();
+                    r_write_trdid       = m_cmd_write_trdid_fifo.read();
+                    r_write_pktid       = m_cmd_write_pktid_fifo.read();
+
+                    // if SC command, get the SC key
+                    if ((m_cmd_write_pktid_fifo.read() & 0x7) == TYPE_SC)
+                    {
+                        assert( not m_cmd_write_eop_fifo.read() &&
+                                "MEMC ERROR in WRITE_IDLE state: "
+                                "invalid packet format for SC command");
+
+                        r_write_sc_key = m_cmd_write_data_fifo.read();
+                    }
+                    // initialize the be field for all words
+                    for(size_t word=0 ; word<m_words ; word++)
+                    {
+                        if(word == index) r_write_be[word] = m_cmd_write_be_fifo.read();
+                        else              r_write_be[word] = 0x0;
+                    }
+
+                    if (m_cmd_write_eop_fifo.read())
+                    {
+                        r_write_fsm = WRITE_DIR_REQ;
+                    }
+                    else
+                    {
+                        r_write_fsm = WRITE_NEXT;
+                    }
+
+#if DEBUG_MEMC_WRITE
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " WRITE_IDLE> Write request "
+                            << " srcid = " << std::hex << m_cmd_write_srcid_fifo.read()
+                            << " / address = " << std::hex << m_cmd_write_addr_fifo.read()
+                            << " / data = " << m_cmd_write_data_fifo.read() 
+                            << " / pktid = " << m_cmd_write_pktid_fifo.read() 
+                            << std::endl;
+#endif
+                    break;
+                }
+
+                ////////////////
+            case WRITE_NEXT:  // copy next word of a write burst in local buffer
+                {
+                    if (not m_cmd_write_addr_fifo.rok()) break;
+
+                    // check that the next word is in the same cache line
+                    assert((m_nline[(addr_t)(r_write_address.read())] == 
+                                m_nline[(addr_t)(m_cmd_write_addr_fifo.read())]) &&
+                            "MEMC ERROR in WRITE_NEXT state: Illegal write burst");
+
+                    size_t index = m_x[(addr_t)(m_cmd_write_addr_fifo.read())];
+                    bool   is_sc = ((m_cmd_write_pktid_fifo.read() & 0x7) == TYPE_SC);
+
+                    // check that SC command has constant address
+                    assert((not is_sc or (index == r_write_word_index)) &&
+                            "MEMC ERROR in WRITE_NEXT state: "
+                            "the address must be constant on a SC command");
+
+                    // check that SC command has two flits
+                    assert((not is_sc or m_cmd_write_eop_fifo.read()) &&
+                            "MEMC ERROR in WRITE_NEXT state: "
+                            "invalid packet format for SC command");
+                    // consume a word in the FIFO & write it in the local buffer
+                    cmd_write_fifo_get  = true;
+
+                    r_write_be[index]   = m_cmd_write_be_fifo.read();
+                    r_write_data[index] = m_cmd_write_data_fifo.read();
+
+                    // the first flit of a SC command is the reservation key and
+                    // therefore it must not be counted as a data to write
+                    if (not is_sc)
+                    {
+                        r_write_word_count = r_write_word_count.read() + 1;
+                    }
+
+                    if (m_cmd_write_eop_fifo.read()) r_write_fsm = WRITE_DIR_REQ;
+
+#if DEBUG_MEMC_WRITE
+                    if (m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " WRITE_NEXT> Write another word in local buffer"
+                            << std::endl;
+#endif
+                    break;
+                }
+
+                ////////////////////
+            case WRITE_DIR_REQ:
+                {
+                    // Get the lock to the directory
+                    // and access the llsc_global_table
+                    if (r_alloc_dir_fsm.read() != ALLOC_DIR_WRITE ) break;
+
+                    if ((r_write_pktid.read() & 0x7) == TYPE_SC)
+                    {
+                        // test address and key match of the SC command on the
+                        // LL/SC table without removing reservation. The reservation
+                        // will be erased after in this FSM. 
+                        bool sc_success = m_llsc_table.check(r_write_address.read(),
+                                r_write_sc_key.read());
+
+                        r_write_sc_fail     = not sc_success;
+
+                        if (not sc_success) r_write_fsm = WRITE_RSP;
+                        else                r_write_fsm = WRITE_DIR_LOCK;
+                    }
+                    else
+                    {
+                        // write burst 
+#define L2 soclib::common::uint32_log2
+                        addr_t min = r_write_address.read();
+                        addr_t max = r_write_address.read() +
+                            (r_write_word_count.read() << L2(vci_param_int::B));
+#undef L2
+
+                        m_llsc_table.sw(min, max);
+
+                        r_write_fsm = WRITE_DIR_LOCK;
+                    }
+
+#if DEBUG_MEMC_WRITE
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " WRITE_DIR_REQ> Requesting DIR lock "
+                            << std::endl;
+#endif
+                    break;
+                }
+
+                ////////////////////
+            case WRITE_DIR_LOCK:     // access directory to check hit/miss
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_WRITE) and
+                            "MEMC ERROR in ALLOC_DIR_LOCK state: Bad DIR allocation");
+                    size_t  way = 0;
+                    DirectoryEntry entry(m_cache_directory.read(r_write_address.read(), way));
+
+                    size_t set          = m_y[(addr_t)(r_write_address.read())];
+                    addr_t nline        = m_nline[(addr_t)(r_write_address.read())];
+                    if(entry.state != ENTRY_INVALID)    // hit
+                    {
+                        // copy directory entry in local buffer in case of hit
+                        r_write_is_cnt     = entry.is_cnt;
+                        r_write_lock       = entry.lock;
+                        r_write_tag        = entry.tag;
+                        r_write_copy       = entry.owner.srcid;
+                        r_write_copy_inst  = entry.owner.inst;
+                        r_write_count      = entry.count;
+                        r_write_ptr        = entry.ptr;
+                        r_write_way        = way;
+                        r_write_state      = entry.state;
+
+                        if( r_write_pktid == TYPE_DATA_UNC and entry.count != 0)
+                        {
+                            assert( false && " found a copy for an uncached write quest");
+                        }
+                        else
+                        { 
+                            if( not entry.count and (entry.state != ENTRY_LOCKED))
+                            {
+                                r_write_fsm = WRITE_DIR_HIT;    
+                            }
+                            else if (entry.state == ENTRY_LOCKED)//the line is locked
+                            {
+                                r_write_fsm = WRITE_WAIT;
+                            }
+                            else // invalid the line and send multi_inval or brdcast to cache L1, and set trt table to evict the line
+                            {
+                                if(entry.state == ENTRY_EXCLUSIVE)
+                                {
+                                    r_write_inval_trt_send = false;
+                                }
+                                else
+                                {
+                                    r_write_inval_trt_send = true;
+                                }
+                                r_write_fsm = WRITE_INVAL_TRT_LOCK;
+
+                            }
+                        }
+                    }
+                    else  // miss
+                    {
+                        // if a miss write matched with a trt wait situation(wait for dirty data), it must block the command write until the dirty data has arrived in memcache
+                        if(r_write_to_cleanup_req.read() and 
+                           r_write_to_cleanup_nline.read() == nline) 
+                        {
+                            std::cout << "hit write cleanup nline =" << std::hex << nline << std::endl;
+                            r_write_fsm = WRITE_WAIT;
+                        }
+                        else
+                        {
+                            r_write_fsm = WRITE_MISS_TRT_LOCK;
+                        }
+                    }
+
+#if DEBUG_MEMC_WRITE
+                    if(m_debug)
+                    {
+                        std::cout << "  <MEMC " << name() << " WRITE_DIR_LOCK> Check the directory: "
+                            << " address = " << std::hex << r_write_address.read()
+                            << " / hit = " << std::dec << entry.state
+                            << " / count = " << entry.count
+                            << " / is_cnt = " << entry.is_cnt ;
+                        if((r_write_pktid.read() & 0x7) == TYPE_SC)
+                            std::cout << " / SC access" << std::endl;
+                        else
+                            std::cout << " / SW access" << std::endl;
+                    }
+#endif
+                    break;
+                }
+                ////////////////////
+//            case WRITE_IVT_LOCK_HIT_WB:
+//                {
+//                    if(r_alloc_ivt_fsm.read() == ALLOC_IVT_WRITE)
+//                    {
+//
+//                        size_t index = 0;
+//                        bool   match_inval;
+//                        addr_t nline = m_nline[(addr_t)(r_write_address.read())];
+//
+//                        //std::cout << "WRITE on NCC on line" << std::hex << nline << std::dec << std::endl;
+//                        //if there is a matched updt req, we should wait until it is over. Because 
+//                        //we need the lastest updt data.
+//                        match_inval = m_ivt.search_inval(nline, index);
+//
+//                        assert ((r_write_count.read() == 1) and "NCC to CC req without copy");
+//
+//                        if( not match_inval                          and 
+//                            not r_write_to_cc_send_multi_req.read()  and
+//                            not r_write_to_cc_send_brdcast_req.read()   )
+//                        {
+//                            r_write_to_cc_send_multi_req   = true;
+//                            r_write_to_cc_send_dest        = r_write_copy;
+//                            r_write_to_cc_send_nline       = nline;
+//                            r_write_to_cleanup_req         = true;
+//                            r_write_to_cleanup_nline       = nline;
+//                            write_to_cc_send_fifo_put      = true;
+//                            write_to_cc_send_fifo_inst     = r_write_copy_inst.read();
+//                            write_to_cc_send_fifo_srcid    = r_write_copy.read();
+//     
+//                            m_ivt.set(false,  // it's an inval transaction
+//                                      false,     // it's not a broadcast
+//                                      false,      // it needs no response
+//                                      false,     // no acknowledge required
+//                                      m_cmd_write_srcid_fifo.read(), //never read, used for debug
+//                                      m_cmd_write_trdid_fifo.read(), //never read, used for debug
+//                                      m_cmd_write_pktid_fifo.read(), //never read, used for debug
+//                                      nline,
+//                                      0x1, //Expect only one answer
+//                                      index);
+//                        }
+//                        r_write_fsm = WRITE_WAIT;
+//#if DEBUG_MEMC_WRITE
+//                        if(m_debug)
+//                        {
+//                            std::cout << "  <MEMC " << name() << " WRITE_IVT_LOCK_HIT_WB> get access to the UPT: "
+//                                << " Inval requested =  " << (not match_inval and not r_write_to_cc_send_req.read())
+//                                << std::endl;
+//                        }
+//#endif
+//                        break;
+//                    }
+//#if DEBUG_MEMC_WRITE
+//                    if(m_debug)
+//                    {
+//                        std::cout << "  <MEMC " << name() << " WRITE_IVT_LOCK_HIT_WB> failed to access to the IVT: "
+//                            << std::endl;
+//                    }
+//#endif
+//                    break;
+//                }
+//
+                ///////////////////
+            case WRITE_DIR_HIT:
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_WRITE) and
+                            "MEMC ERROR in ALLOC_DIR_HIT state: Bad DIR allocation");
+
+                    // update the cache directory
+                    // update directory with Dirty bit
+                    DirectoryEntry entry;
+                    entry.state          = r_write_state.read();
+                    entry.dirty          = true;
+                    entry.tag            = r_write_tag.read();
+                    entry.is_cnt         = r_write_is_cnt.read();
+                    entry.lock           = r_write_lock.read();
+                    entry.owner.srcid    = r_write_copy.read();
+                    entry.owner.inst     = r_write_copy_inst.read();
+                    entry.count          = r_write_count.read();
+                    entry.ptr            = r_write_ptr.read();
+
+                    size_t set           = m_y[(addr_t)(r_write_address.read())];
+                    size_t way           = r_write_way.read();
+
+                    // update directory
+                    m_cache_directory.write(set, way, entry);
+
+                    r_write_fsm = WRITE_RSP;
+
+                    // owner is true when the  the first registered copy is the writer itself
+                    //bool owner = (((r_write_copy.read() == r_write_srcid.read())
+                    //            ) and not r_write_copy_inst.read());
+
+                    // no_update is true when there is no need for coherence transaction
+                    // bool no_update = ( (r_write_count.read() == 0) or
+                    //        (owner and (r_write_count.read() == 1) and 
+                    //         ((r_write_pktid.read() & 0x7) != TYPE_SC)));
+
+                    // write data in the cache if no coherence transaction
+                    //if(no_update)
+                    //{
+                    // SC command but zero copies 
+                    if ((r_write_pktid.read() & 0x7) == TYPE_SC)
+                    {
+                        m_llsc_table.sc(r_write_address.read(),
+                                r_write_sc_key.read());
+                    }
+
+                    for(size_t word=0 ; word<m_words ; word++)
+                    {
+                        m_cache_data.write(way, set, word, r_write_data[word].read(), r_write_be[word].read());
+
+                    }
+                    //}
+
+                    //if (owner and not no_update and ((r_write_pktid.read() & 0x7) != TYPE_SC))
+                    //{
+                    //    r_write_count = r_write_count.read() - 1;
+                    //}
+
+                    //if(no_update)
+                    //    // Write transaction completed
+                    //{
+                    //    r_write_fsm = WRITE_RSP;
+                    //}
+                    //else
+                    //    // coherence update required
+                    //{
+                    //    if( not r_write_to_cc_send_multi_req.read()   and
+                    //        not r_write_to_cc_send_brdcast_req.read() and
+                    //        not r_write_to_cc_send_req.read()            )
+                    //    {
+                    //        r_write_fsm = WRITE_UPT_LOCK;
+                    //    }
+                    //    else
+                    //    {
+                    //        r_write_fsm = WRITE_WAIT;
+                    //    }
+                    //}
+
+#if DEBUG_MEMC_WRITE
+                    if(m_debug)
+                    {
+                         std::cout << "  <MEMC " << name() 
+                             << " WRITE_DIR_HIT> Write into cache / No coherence transaction"
+                             << std::endl;
+                    }
+#endif
+                    break;
+                }
+                ///////////////////
+            case WRITE_HEAP_REQ:    // Get the lock to the HEAP directory
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_WRITE)
+                    {
+                        r_write_fsm = WRITE_HEAP_ERASE;
+                        m_cpt_write_fsm_n_heap_lock++;
+                    }
+
+#if DEBUG_MEMC_WRITE
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " WRITE_HEAP_REQ>"
+                            << " Requesting HEAP lock " << std::endl;
+#endif
+
+                    m_cpt_write_fsm_heap_lock++;
+
+                    break;
+                }
+
+                /////////////////////////
+            case WRITE_HEAP_ERASE:   // get access to heap
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_WRITE)
+                    {
+                        HeapEntry entry = m_heap.read(r_write_next_ptr.read());
+
+                        write_to_cc_send_fifo_srcid    = entry.owner.srcid;
+                        write_to_cc_send_fifo_inst     = entry.owner.inst;
+                        write_to_cc_send_fifo_put      = true;
+                        if(m_write_to_cc_send_inst_fifo.wok())
+                        {
+                            r_write_next_ptr = entry.next;
+                            if(entry.next == r_write_next_ptr.read())   // last copy
+                            {
+                                r_write_to_cc_send_multi_req = true;
+                                r_write_fsm = WRITE_HEAP_LAST;
+                            }
+                            else
+                            {
+                                r_write_fsm = WRITE_HEAP_ERASE;
+                            }
+                        }
+                        else
+                        {
+                            r_write_fsm = WRITE_HEAP_ERASE;
+                        }
+
+#if DEBUG_MEMC_WRITE
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() 
+                                << " WRITE_HEAP_LOCK> Get acces to the HEAP" << std::endl;
+#endif
+                    }
+
+                    m_cpt_write_fsm_heap_lock++;
+
+                    break;
+                }
+                /////////////////////////
+            case WRITE_HEAP_LAST:  // last copy
+                {
+                    if(r_alloc_heap_fsm.read() != ALLOC_HEAP_WRITE)
+                    {
+                        std::cout << "VCI_MEM_CACHE ERROR " << name() << " WRITE_HEAP_LAST"
+                            << " bad HEAP allocation" << std::endl;
+                        exit(0);
+                    }
+                    size_t free_pointer = m_heap.next_free_ptr();
+
+                    HeapEntry last_entry;
+                    last_entry.owner.srcid    = 0;
+                    last_entry.owner.inst     = false;
+                    if(m_heap.is_full())
+                    {
+                        last_entry.next     = r_write_next_ptr.read();
+                        m_heap.unset_full();
+                    }
+                    else
+                    {
+                        last_entry.next     = free_pointer;
+                    }
+
+                    m_heap.write_free_ptr(r_write_ptr.read());
+                    m_heap.write(r_write_next_ptr.read(),last_entry);
+
+                    r_write_fsm = WRITE_INVAL_XRAM_REQ;  //this is sure that this line is in shared state, it can be send to xram
+
+#if DEBUG_MEMC_XRAM_RSP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " WRITE_HEAP_LAST>"
+                            << " Heap housekeeping" << std::endl;
+#endif
+                    break;
+                }
+
+                //////////////////
+//            case WRITE_UPT_REQ:    // prepare the coherence transaction for the CC_SEND FSM
+//                // and write the first copy in the FIFO
+//                // send the request if only one copy
+//                {
+//                    assert( not r_write_to_cc_send_multi_req.read()   and
+//                            not r_write_to_cc_send_brdcast_req.read() and
+//                            not r_write_to_cc_send_req.read()         and
+//                            "Error in VCI_MEM_CACHE : pending multicast or broadcast\n"
+//                            "transaction in WRITE_UPT_REQ state"
+//                          );
+//
+//
+//                    r_write_to_cc_send_brdcast_req  = false;
+//                    r_write_to_cc_send_trdid        = r_write_ivt_index.read();
+//                    r_write_to_cc_send_nline        = m_nline[(addr_t)(r_write_address.read())];
+//                    r_write_to_cc_send_index        = r_write_word_index.read();
+//                    r_write_to_cc_send_count        = r_write_word_count.read();
+//
+//                    for(size_t i=0; i<m_words ; i++) r_write_to_cleanup_be[i]=r_write_be[i].read();
+//
+//                    size_t min = r_write_word_index.read();
+//                    size_t max = r_write_word_index.read() + r_write_word_count.read();
+//                    for(size_t i=min ; i<=max ; i++) r_write_to_cleanup_data[i] = r_write_data[i];
+//
+//                    if ((r_write_copy.read() != r_write_srcid.read()) or
+//                            ((r_write_pktid.read() & 0x7) == TYPE_SC)      or
+//                            r_write_copy_inst.read())
+//                    {
+//                        // put the first srcid in the fifo
+//                        write_to_cc_send_fifo_put     = true;
+//                        write_to_cc_send_fifo_inst    = r_write_copy_inst.read();
+//                        write_to_cc_send_fifo_srcid   = r_write_copy.read();
+//                        if(r_write_count.read() == 1)
+//                        {
+//                            r_write_fsm = WRITE_IDLE;
+//                            r_write_to_cc_send_multi_req = true;
+//                        }
+//                        else
+//                        {
+//                            r_write_fsm = WRITE_UPT_NEXT;
+//                            r_write_to_dec = false;
+//
+//                        }
+//                    }
+//                    else
+//                    {
+//                        r_write_fsm = WRITE_UPT_NEXT;
+//                        r_write_to_dec = false;
+//                    }
+//
+//#if DEBUG_MEMC_WRITE
+//                    if(m_debug)
+//                    {
+//                        std::cout
+//                            << "  <MEMC "    << name()
+//                            << " WRITE_UPT_REQ> Post first request to CC_SEND FSM"
+//                            << " / srcid = " << std::dec << r_write_copy.read()
+//                            << " / inst = "  << std::dec << r_write_copy_inst.read() << std::endl;
+//
+//                        if(r_write_count.read() == 1)
+//                            std::cout << "         ... and this is the last" << std::endl;
+//                    }
+//#endif
+//                    break;
+//                }
+//
+//                ///////////////////
+//            case WRITE_UPT_NEXT:
+//                {
+//                    // continue the multi-update request to CC_SEND fsm
+//                    // when there is copies in the heap.
+//                    // if one copy in the heap is the writer itself
+//                    // the corresponding SRCID should not be written in the fifo,
+//                    // but the UPT counter must be decremented.
+//                    // As this decrement is done in the WRITE_UPT_DEC state,
+//                    // after the last copy has been found, the decrement request
+//                    // must be  registered in the r_write_to_dec flip-flop.
+//
+//                    HeapEntry entry = m_heap.read(r_write_ptr.read());
+//
+//                    bool dec_upt_counter;
+//
+//                    // put the next srcid in the fifo
+//                    if ((entry.owner.srcid != r_write_srcid.read()) or 
+//                            ((r_write_pktid.read() & 0x7) == TYPE_SC)    or
+//                            entry.owner.inst)
+//                    {
+//                        dec_upt_counter                = false;
+//                        write_to_cc_send_fifo_put      = true;
+//                        write_to_cc_send_fifo_inst     = entry.owner.inst;
+//                        write_to_cc_send_fifo_srcid    = entry.owner.srcid;
+//
+//#if DEBUG_MEMC_WRITE
+//                        if(m_debug)
+//                        {
+//                            std::cout << "  <MEMC " << name() << " WRITE_UPT_NEXT> Post another request to CC_SEND FSM"
+//                                << " / heap_index = " << std::dec << r_write_ptr.read()
+//                                << " / srcid = " << std::dec << r_write_copy.read()
+//                                << " / inst = "  << std::dec << r_write_copy_inst.read() << std::endl;
+//                            if(entry.next == r_write_ptr.read())
+//                                std::cout << "        ... and this is the last" << std::endl;
+//                        }
+//#endif
+//                    }
+//                    else                                // the UPT counter must be decremented
+//                    {
+//                        dec_upt_counter = true;
+//
+//#if DEBUG_MEMC_WRITE
+//                        if(m_debug)
+//                        {
+//                            std::cout << "  <MEMC " << name() << " WRITE_UPT_NEXT> Skip one entry in heap matching the writer"
+//                                << " / heap_index = " << std::dec << r_write_ptr.read()
+//                                << " / srcid = " << std::dec << r_write_copy.read()
+//                                << " / inst = "  << std::dec << r_write_copy_inst.read() << std::endl;
+//                            if(entry.next == r_write_ptr.read())
+//                                std::cout << "        ... and this is the last" << std::endl;
+//                        }
+//#endif
+//                    }
+//
+//                    // register the possible UPT decrement request
+//                    r_write_to_dec = dec_upt_counter or r_write_to_dec.read();
+//
+//                    if(not m_write_to_cc_send_inst_fifo.wok())
+//                    {
+//                        std::cout << "VCI_MEM_CACHE ERROR " << name() << " WRITE_UPT_NEXT state" << std::endl
+//                            << "The write_to_cc_send_fifo should not be full" << std::endl
+//                            << "as the depth should be larger than the max number of copies" << std::endl;
+//                        exit(0);
+//                    }
+//
+//                    r_write_ptr = entry.next;
+//
+//                    if(entry.next == r_write_ptr.read())    // last copy
+//                    {
+//                        r_write_to_cc_send_multi_req = true;
+//                        if(r_write_to_dec.read() or dec_upt_counter)  r_write_fsm = WRITE_UPT_DEC;
+//                        else                                          r_write_fsm = WRITE_IDLE;
+//                    }
+//                    break;
+//                }
+//
+//                //////////////////
+//            case WRITE_UPT_DEC:
+//                {
+//                    // If the initial writer has a copy, it should not
+//                    // receive an update request, but the counter in the
+//                    // update table must be decremented by the MULTI_ACK FSM.
+//
+//                    if(!r_write_to_multi_ack_req.read())
+//                    {
+//                        r_write_to_multi_ack_req = true;
+//                        r_write_to_multi_ack_upt_index = r_write_upt_index.read();
+//                        r_write_fsm = WRITE_IDLE;
+//                    }
+//                    break;
+//                }
+//
+                ///////////////
+            case WRITE_RSP:
+                {
+                    // Post a request to TGT_RSP FSM to acknowledge the write
+                    // In order to increase the Write requests throughput,
+                    // we don't wait to return in the IDLE state to consume
+                    // a new request in the write FIFO
+
+                    if (not r_write_to_tgt_rsp_req.read())
+                    {
+                        // post the request to TGT_RSP_FSM
+                        r_write_to_tgt_rsp_req     = true;
+                        r_write_to_tgt_rsp_srcid   = r_write_srcid.read();
+                        r_write_to_tgt_rsp_trdid   = r_write_trdid.read();
+                        r_write_to_tgt_rsp_pktid   = r_write_pktid.read();
+                        r_write_to_tgt_rsp_sc_fail = r_write_sc_fail.read();
+
+                        // try to get a new write request from the FIFO
+                        if (not m_cmd_write_addr_fifo.rok())
+                        {
+                            r_write_fsm = WRITE_IDLE;
+                        }
+                        else
+                        {
+                            // consume a word in the FIFO & write it in the local buffer
+                            cmd_write_fifo_get  = true;
+                            size_t index        = m_x[(addr_t)(m_cmd_write_addr_fifo.read())];
+
+                            r_write_address     = (addr_t)(m_cmd_write_addr_fifo.read());
+                            r_write_word_index  = index;
+                            r_write_word_count  = 0;
+                            r_write_data[index] = m_cmd_write_data_fifo.read();
+                            r_write_srcid       = m_cmd_write_srcid_fifo.read();
+                            r_write_trdid       = m_cmd_write_trdid_fifo.read();
+                            r_write_pktid       = m_cmd_write_pktid_fifo.read();
+
+                            // if SC command, get the SC key
+                            if ((m_cmd_write_pktid_fifo.read() & 0x7) == TYPE_SC)
+                            {
+                                assert( not m_cmd_write_eop_fifo.read() &&
+                                        "MEMC ERROR in WRITE_RSP state: "
+                                        "invalid packet format for SC command");
+
+                                r_write_sc_key = m_cmd_write_data_fifo.read();
+                            } 
+
+                            // initialize the be field for all words
+                            for(size_t word=0 ; word<m_words ; word++)
+                            {
+                                if(word == index) r_write_be[word] = m_cmd_write_be_fifo.read();
+                                else              r_write_be[word] = 0x0;
+                            }
+
+                            if( m_cmd_write_eop_fifo.read())
+                            {
+                                r_write_fsm = WRITE_DIR_REQ;
+                            }
+                            else
+                            {
+                                r_write_fsm = WRITE_NEXT;
+                            }
+                        }
+
+#if DEBUG_MEMC_WRITE
+                        if(m_debug)
+                        {
+                            std::cout << "  <MEMC " << name() << " WRITE_RSP> Post a request to TGT_RSP FSM"
+                                << " : rsrcid = " << std::hex << r_write_srcid.read() 
+                                << " : rpktid = " << std::hex << r_write_pktid.read() 
+                                << " : sc_fail= " << std::hex << r_write_sc_fail.read()
+                                << std::endl;
+                            if(m_cmd_write_addr_fifo.rok())
+                            {
+                                std::cout << "                    New Write request: "
+                                    << " srcid = " << std::hex << m_cmd_write_srcid_fifo.read()
+                                    << " / address = " << m_cmd_write_addr_fifo.read()
+                                    << " / data = " << m_cmd_write_data_fifo.read() 
+                                    << " / pktid = " << m_cmd_write_pktid_fifo.read() 
+                                    << std::endl;
+                            }
+                        }
+#endif
+                    }
+                    break;
+                }
+//            case WRITE_MISS_IVT_LOCK: 
+//                {
+//                    if (r_alloc_ivt_fsm.read() == ALLOC_IVT_WRITE)
+//                    {
+//                        size_t index;
+//                        if(m_ivt.search_inval(m_nline[(addr_t)(r_write_address.read())], index))
+//                        {
+//                            r_write_fsm = WRITE_WAIT;
+//                        }
+//                        else
+//                        {
+//                            r_write_fsm = WRITE_MISS_TRT_LOCK;
+//                        }
+//                    }
+//                    break;
+//                }
+//
+                /////////////////////////
+            case WRITE_MISS_TRT_LOCK: // Miss : check Transaction Table
+                {
+                    if(r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE)
+                    {
+                        size_t  hit_index = 0;
+                        size_t  wok_index = 0;
+                        addr_t  addr  = (addr_t) r_write_address.read();
+                        bool    hit_read  = m_trt.hit_read(m_nline[addr], hit_index);
+                        bool    hit_write = m_trt.hit_write(m_nline[addr]);
+                        bool    wok       = not m_trt.full(wok_index);
+#if DEBUG_MEMC_WRITE
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " WRITE_MISS_TRT_LOCK> Check the TRT" 
+                                      << "hit read =" << hit_read
+                                      << "hit write = " << hit_write
+                                      << "wok =" << wok << std::endl;
+#endif
+
+
+                        // wait an empty entry in TRT
+                        if(not hit_read and (not wok or hit_write))
+                        {
+                            r_write_fsm       = WRITE_WAIT;
+                            m_cpt_trt_full++;
+
+                            break;
+                        }
+
+                        if ((r_write_pktid.read() & 0x7) == TYPE_SC)
+                        {
+                            m_llsc_table.sc(r_write_address.read(),
+                                    r_write_sc_key.read());
+                        }
+
+                        // register the modified data in TRT
+                        if (hit_read)
+                        {
+                            r_write_trt_index = hit_index;
+                            r_write_fsm       = WRITE_MISS_TRT_DATA;
+                            m_cpt_write_miss++;
+                            break;
+                        }
+                        // set a new entry in TRT
+                        if (wok and not hit_write)
+                        {
+                            r_write_trt_index = wok_index;
+                            r_write_fsm       = WRITE_MISS_TRT_SET;
+                            m_cpt_write_miss++;
+                            break;
+                        }
+
+                        assert(false && "VCI_MEM_CACHE ERROR: this part must not be reached");
+                    }
+ 
+                    break;
+                }
+
+                ////////////////
+            case WRITE_WAIT:  // release the locks protecting the shared ressources
+                {
+
+#if DEBUG_MEMC_WRITE
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " WRITE_WAIT> Releases the locks before retry" << std::endl;
+#endif
+                    r_write_fsm = WRITE_DIR_REQ;
+                    break;
+                }
+
+                ////////////////////////
+            case WRITE_MISS_TRT_SET:  // register a new transaction in TRT (Write Buffer)
+                {
+                    if(r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE)
+                    {
+                        std::vector<be_t>   be_vector;
+                        std::vector<data_t> data_vector;
+                        be_vector.clear();
+                        data_vector.clear();
+                        for(size_t i=0; i<m_words; i++)
+                        {
+                            be_vector.push_back(r_write_be[i]);
+                            data_vector.push_back(r_write_data[i]);
+                        }
+                        m_trt.set(r_write_trt_index.read(),
+                                  true,     // read request to XRAM
+                                  m_nline[(addr_t)(r_write_address.read())],
+                                  r_write_srcid.read(),
+                                  r_write_trdid.read(),
+                                  r_write_pktid.read(),
+                                  false,      // not a processor read
+                                  0,          // not a single word
+                                  0,          // word index
+                                  be_vector,
+                                  data_vector);
+                        r_write_fsm = WRITE_MISS_XRAM_REQ;
+
+#if DEBUG_MEMC_WRITE
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " WRITE_MISS_TRT_SET> Set a new entry in TRT" << std::endl;
+#endif
+                    }
+                    break;
+                }
+
+                /////////////////////////
+            case WRITE_MISS_TRT_DATA: // update an entry in TRT (used as a Write Buffer)
+                {
+                    if(r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE)
+                    {
+                        std::vector<be_t> be_vector;
+                        std::vector<data_t> data_vector;
+                        be_vector.clear();
+                        data_vector.clear();
+                        for(size_t i=0; i<m_words; i++)
+                        {
+                            be_vector.push_back(r_write_be[i]);
+                            data_vector.push_back(r_write_data[i]);
+                        }
+                        m_trt.write_data_mask(r_write_trt_index.read(),
+                                be_vector,
+                                data_vector);
+                        r_write_fsm = WRITE_RSP;
+
+#if DEBUG_MEMC_WRITE
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " WRITE_MISS_TRT_DATA> Modify an existing entry in TRT" << std::endl;
+#endif
+                    }
+                    break;
+                }
+
+                /////////////////////////
+            case WRITE_MISS_XRAM_REQ: // send a GET request to IXR_CMD FSM
+                {
+                    if(not r_write_to_ixr_cmd_req.read())
+                    {
+                        r_write_to_ixr_cmd_req   = true;
+                        r_write_to_ixr_cmd_index = r_write_trt_index.read();
+                        r_write_fsm              = WRITE_RSP;
+
+#if DEBUG_MEMC_WRITE
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() 
+                                << " WRITE_MISS_XRAM_REQ> Post a GET request to the"
+                                << " IXR_CMD FSM" << std::endl;
+#endif
+                    }
+                    break;
+                }
+
+//                ///////////////////////
+//            case WRITE_INVAL_DIR_READ:  // enter this state if a broadcast-inval is required
+//                // the cache line must be erased in mem-cache, and written
+//                // into XRAM.
+//                {
+//                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_WRITE) and
+//                            "MEMC ERROR in WRITE_INVAL_DIR_READ state: Bad DIR allocation");
+//
+//                    // write enable signal for data buffer.
+//                    r_write_bc_data_we = true;
+//
+//                    r_write_fsm = WRITE_INVAL_TRT_LOCK;
+//
+//#if DEBUG_MEMC_WRITE
+//                    if (m_debug)
+//                        std::cout << "  <MEMC " << name() << " WRITE_INVAL_DIR_READ>"
+//                            << " Read the cache to complete local buffer" << std::endl;
+//#endif
+//                    break;
+//                }
+                ///////////////////////
+            case WRITE_INVAL_TRT_LOCK:     // get TRT lock to check TRT not full
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_WRITE) and
+                            "MEMC ERROR in WRITE_INVAL_TRT_LOCK state: Bad DIR allocation");
+
+                    if (r_alloc_trt_fsm.read() != ALLOC_TRT_WRITE)
+                        break;
+
+                    // We read the cache and complete the buffer. As the DATA cache uses a
+                    // synchronous RAM, the read DATA request has been performed in the
+                    // WRITE_INVAL_DIR_READ state but the data is available in this state.
+                    size_t wok_index = 0;
+                    bool wok = not m_trt.full(wok_index);
+                    if(wok)       // set a new entry in TRT
+                    {
+                        r_write_trt_index = wok_index;
+                        r_write_fsm       = WRITE_INVAL_IVT_LOCK;
+                    }
+                    else  // wait an empty entry in TRT
+                    {
+                        r_write_fsm       = WRITE_WAIT;
+                    }
+
+#if DEBUG_MEMC_WRITE
+                    if(m_debug)
+                        std::cout << "  <MEMC "  << name()
+                            << " WRITE_INVAL_TRT_LOCK> Check TRT : wok = " << wok
+                            << " / index = " << wok_index << std::endl;
+#endif
+
+                    m_cpt_write_fsm_trt_lock++;
+
+                    break;
+                }
+
+                //////////////////////
+            case WRITE_INVAL_IVT_LOCK:      // register BC transaction in IVT
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_WRITE) and
+                            "MEMC ERROR in WRITE_INVAL_IVT_LOCK state: Bad DIR allocation");
+
+                    assert( (r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE) and
+                            "MEMC ERROR in WRITE_INVAL_IVT_LOCK state: Bad TRT allocation");
+
+                    size_t set          = m_y[(addr_t)(r_write_address.read())];
+
+                    bool cc_send_valid = not r_write_to_cc_send_multi_req.read() and
+                                         not r_write_to_cc_send_brdcast_req.read() and  
+                                            (r_write_inval_trt_send.read() or not r_write_to_cleanup_req.read());
+                    if(r_alloc_ivt_fsm.read() == ALLOC_IVT_WRITE)
+                    {
+                        bool        wok        = false;
+                        bool        is_brdcast = r_write_is_cnt.read();
+                        size_t      index      = 0;
+                        size_t      srcid      = r_write_srcid.read();
+                        size_t      trdid      = r_write_trdid.read();
+                        size_t      pktid      = r_write_pktid.read();
+                        addr_t      nline      = m_nline[(addr_t)(r_write_address.read())];
+                        size_t      nb_copies  = r_write_count.read();
+
+                        wok = m_ivt.set(false,        // it's an inval transaction
+                                        is_brdcast,   // it's a broadcast
+                                        true,         // response required
+                                        false,        // no acknowledge required
+                                        srcid,
+                                        trdid,
+                                        pktid,
+                                        nline,
+                                        nb_copies,
+                                        index);
+#if DEBUG_MEMC_WRITE
+                        if( m_debug and wok )
+                            std::cout << "  <MEMC " << name() << " WRITE_INVAL_IVT_LOCK> Register broadcast inval in IVT"
+                                << " / nb_copies = " << r_write_count.read() << std::endl;
+#endif
+                        //r_write_ivt_index = index;
+
+                        if(wok and cc_send_valid) //avoid to deadlock, we make sure that we can send cc_send request. 
+                        {   
+                         /*//   std::cout << " trt wait nline =" << std::hex << nline 
+                                     << " write data " << std::hex << std::endl;*/
+
+                            for(size_t word=0 ; word<m_words ; word++)
+                            {
+                                r_write_to_cleanup_be[word]   = r_write_be[word];
+                                r_write_to_cleanup_data[word] = r_write_data[word];
+
+                                data_t mask = 0;
+                                if(r_write_be[word].read() & 0x1) mask = mask | 0x000000FF;
+                                if(r_write_be[word].read() & 0x2) mask = mask | 0x0000FF00;
+                                if(r_write_be[word].read() & 0x4) mask = mask | 0x00FF0000;
+                                if(r_write_be[word].read() & 0x8) mask = mask | 0xFF000000;
+        
+                                // complete only if mask is not null (for energy consumption)
+                                r_write_data[word] =
+                                    (r_write_data[word].read()         &  mask) |
+                                    (m_cache_data.read(r_write_way.read(), set, word) & ~mask);
+                           /*//     std::cout << std::hex 
+                                         << ((r_write_data[word].read()         &  mask) |
+                                    (m_cache_data.read(r_write_way.read(), set, word) & ~mask)) << std::endl;*/
+                            }
+                            r_write_fsm     = WRITE_DIR_INVAL;
+                        }
+                        else
+                        {    
+                            r_write_fsm = WRITE_WAIT;
+                        }
+                    }
+
+                    m_cpt_write_fsm_upt_lock++;
+
+                    break;
+                }
+
+                ////////////////////////
+            case WRITE_DIR_INVAL:
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_WRITE) and
+                            "MEMC ERROR in WRITE_DIR_INVAL state: Bad DIR allocation");
+
+                    assert( (r_alloc_trt_fsm.read() == ALLOC_TRT_WRITE) and
+                            "MEMC ERROR in WRITE_DIR_INVAL state: Bad TRT allocation");
+
+                    assert( (r_alloc_ivt_fsm.read() == ALLOC_IVT_WRITE) and
+                            "MEMC ERROR in WRITE_DIR_INVAL state: Bad IVT allocation");
+
+                    // register PUT request in TRT
+                    std::vector<data_t> data_vector;
+                    data_vector.clear();
+                    for(size_t i=0; i<m_words; i++) data_vector.push_back(r_write_data[i].read());
+
+                    m_trt.set( r_write_trt_index.read(),
+                               false,             // PUT request
+                               m_nline[(addr_t)(r_write_address.read())],
+                               0,                 // unused
+                               0,                 // unused
+                               0,                 // unused
+                               false,             // not a processor read
+                               0,                 // unused
+                               0,                 // unused
+                               std::vector<be_t> (m_words,0),
+                               data_vector );
+
+                    // invalidate directory entry
+                    DirectoryEntry entry;
+                    entry.state         = ENTRY_INVALID;
+                    entry.dirty         = false;
+                    entry.tag           = 0;
+                    entry.is_cnt        = false;
+                    entry.lock          = false;
+                    entry.owner.srcid   = 0;
+                    entry.owner.inst    = false;
+                    entry.ptr           = 0;
+                    entry.count         = 0;
+                    size_t set          = m_y[(addr_t)(r_write_address.read())];
+                    size_t way          = r_write_way.read();
+
+                    m_cache_directory.write(set, way, entry);
+
+                    if ((r_write_pktid.read() & 0x7) == TYPE_SC)
+                    {
+                        m_llsc_table.sc(r_write_address.read(),
+                                r_write_sc_key.read());
+                    }
+
+#if DEBUG_MEMC_WRITE
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " WRITE_DIR_INVAL> Invalidate the directory entry: @ = "
+                            << r_write_address.read() << " / register the put transaction in TRT:" << std::endl;
+#endif
+                    r_write_fsm = WRITE_INVAL_CC_SEND;
+                    break;
+                }
+
+                //////////////////////
+            case WRITE_INVAL_CC_SEND:    // Post a coherence broadcast request to CC_SEND FSM
+                {
+                    if( not r_write_to_cc_send_multi_req.read()   and
+                        not r_write_to_cc_send_brdcast_req.read())
+                    {
+                        bool last_multi_inval          = (r_write_count.read()  == 1) and not r_write_is_cnt.read();
+                        bool not_last_multi_inval      = (r_write_count.read()  != 1) and not r_write_is_cnt.read();
+                        bool multi_inval               = not r_write_is_cnt.read();
+                        r_write_to_cc_send_multi_req   = last_multi_inval;
+                        r_write_to_cc_send_brdcast_req = not multi_inval;
+                        r_write_to_cc_send_nline       = m_nline[(addr_t)(r_write_address.read())];
+                        write_to_cc_send_fifo_srcid    = r_write_copy.read(); 
+                        write_to_cc_send_fifo_inst     = r_write_copy_inst.read(); 
+                        write_to_cc_send_fifo_put      = multi_inval;
+                        r_write_next_ptr               = r_write_ptr.read();
+
+                        if( not last_multi_inval and multi_inval)
+                        {
+                            r_write_fsm = WRITE_HEAP_REQ;
+                        }
+                        else
+                        {
+                            if(r_write_inval_trt_send.read())
+                            {
+                                r_write_fsm = WRITE_INVAL_XRAM_REQ;
+                            }
+                            else //the line is in exlusive state, must wait for the 
+                                 //response of multi_inval in reason of receiving the updated data
+                            {
+                                r_write_fsm              = WRITE_IDLE;
+                                r_write_to_cleanup_req   = true;
+                                r_write_to_cleanup_nline = m_nline[(addr_t)(r_write_address.read())]; 
+                            }
+                        }
+#if DEBUG_MEMC_WRITE
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name()
+                                << " WRITE_INVAL_CC_SEND> Post a inval request to CC_SEND FSM" << std::endl;
+#endif
+                    }
+                    else
+                    {
+                        assert( false && "CC SEND FLAGS IS TURE in WRITE_INVAL_CC_SEND state");
+                    }
+                    break;
+                }
+
+                ///////////////////////
+            case WRITE_INVAL_XRAM_REQ:   // Post a put request to IXR_CMD FSM
+                {
+                    if( not r_write_to_ixr_cmd_req.read() )
+                    {
+                        r_write_to_ixr_cmd_req     = true;
+                        r_write_to_ixr_cmd_index   = r_write_trt_index.read();
+                        r_write_fsm = WRITE_IDLE;
+
+#if DEBUG_MEMC_WRITE
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name()
+                                << " WRITE_INVAL_XRAM_REQ> Post a put request to IXR_CMD FSM" << std::endl;
+#endif
+                    }
+                    break;
+                }
+        } // end switch r_write_fsm
+
+        ///////////////////////////////////////////////////////////////////////
+        //    IXR_CMD FSM
+        ///////////////////////////////////////////////////////////////////////
+        // The IXR_CMD fsm controls the command packets to the XRAM :
+        // It handles requests from 5 FSMs with a round-robin priority:
+        //  READ > WRITE > CAS > XRAM_RSP > CONFIG
+        //
+        // - It sends a single flit VCI read to the XRAM in case of
+        //   GET request posted by the READ, WRITE or CAS FSMs. 
+        // - It sends a multi-flit VCI write in case of PUT request posted by
+        //   the XRAM_RSP, WRITE, CAS, or CONFIG FSMs.
+        //
+        // For each client, there is three steps:
+        // - IXR_CMD_*_IDLE : round-robin allocation to a client
+        // - IXR_CMD_*_TRT  : access to TRT for address and data
+        // - IXR_CMD_*_SEND : send the PUT or GET VCI command
+        //
+        // The address and data to be written (for a PUT) are stored in TRT.
+        // The trdid field contains always the TRT entry index.
+        ////////////////////////////////////////////////////////////////////////
+
+        switch(r_ixr_cmd_fsm.read())
+        {
+            ////////////////////////
+            case IXR_CMD_READ_IDLE:
+                if     (r_write_to_ixr_cmd_req.read())      r_ixr_cmd_fsm = IXR_CMD_WRITE_TRT;
+                else if(r_cas_to_ixr_cmd_req.read())        r_ixr_cmd_fsm = IXR_CMD_CAS_TRT;
+                else if(r_cleanup_to_ixr_cmd_req.read())    r_ixr_cmd_fsm = IXR_CMD_CLEANUP_TRT;
+                else if(r_xram_rsp_to_ixr_cmd_req.read())   r_ixr_cmd_fsm = IXR_CMD_XRAM_TRT;
+                else if(r_config_to_ixr_cmd_req.read())     r_ixr_cmd_fsm = IXR_CMD_CONFIG_TRT;
+                else if(r_read_to_ixr_cmd_req.read())       r_ixr_cmd_fsm = IXR_CMD_READ_TRT;
+                break;
+                ////////////////////////
+            case IXR_CMD_WRITE_IDLE:
+                if     (r_cas_to_ixr_cmd_req.read())        r_ixr_cmd_fsm = IXR_CMD_CAS_TRT;
+                else if(r_cleanup_to_ixr_cmd_req.read())    r_ixr_cmd_fsm = IXR_CMD_CLEANUP_TRT;
+                else if(r_xram_rsp_to_ixr_cmd_req.read())   r_ixr_cmd_fsm = IXR_CMD_XRAM_TRT;
+                else if(r_config_to_ixr_cmd_req.read())     r_ixr_cmd_fsm = IXR_CMD_CONFIG_TRT;
+                else if(r_read_to_ixr_cmd_req.read())       r_ixr_cmd_fsm = IXR_CMD_READ_TRT;
+                else if(r_write_to_ixr_cmd_req.read())      r_ixr_cmd_fsm = IXR_CMD_WRITE_TRT;
+                break;
+                ////////////////////////
+            case IXR_CMD_CAS_IDLE:
+                if     (r_cleanup_to_ixr_cmd_req.read())    r_ixr_cmd_fsm = IXR_CMD_CLEANUP_TRT;
+                else if(r_xram_rsp_to_ixr_cmd_req.read())   r_ixr_cmd_fsm = IXR_CMD_XRAM_TRT;
+                else if(r_config_to_ixr_cmd_req.read())     r_ixr_cmd_fsm = IXR_CMD_CONFIG_TRT;
+                else if(r_read_to_ixr_cmd_req.read())       r_ixr_cmd_fsm = IXR_CMD_READ_TRT;
+                else if(r_write_to_ixr_cmd_req.read())      r_ixr_cmd_fsm = IXR_CMD_WRITE_TRT;
+                else if(r_cas_to_ixr_cmd_req.read())        r_ixr_cmd_fsm = IXR_CMD_CAS_TRT;
+                break;
+                ////////////////////////
+            case IXR_CMD_XRAM_IDLE:
+                if     (r_config_to_ixr_cmd_req.read())     r_ixr_cmd_fsm = IXR_CMD_CONFIG_TRT;
+                else if(r_read_to_ixr_cmd_req.read())       r_ixr_cmd_fsm = IXR_CMD_READ_TRT;
+                else if(r_write_to_ixr_cmd_req.read())      r_ixr_cmd_fsm = IXR_CMD_WRITE_TRT;
+                else if(r_cas_to_ixr_cmd_req.read())        r_ixr_cmd_fsm = IXR_CMD_CAS_TRT;
+                else if(r_cleanup_to_ixr_cmd_req.read())    r_ixr_cmd_fsm = IXR_CMD_CLEANUP_TRT;
+                else if(r_xram_rsp_to_ixr_cmd_req.read())   r_ixr_cmd_fsm = IXR_CMD_XRAM_TRT;
+                break;
+                ////////////////////////
+            case IXR_CMD_CLEANUP_IDLE:
+                if     (r_read_to_ixr_cmd_req.read())       r_ixr_cmd_fsm = IXR_CMD_READ_TRT;
+                else if(r_write_to_ixr_cmd_req.read())      r_ixr_cmd_fsm = IXR_CMD_WRITE_TRT;
+                else if(r_cas_to_ixr_cmd_req.read())        r_ixr_cmd_fsm = IXR_CMD_CAS_TRT;
+                else if(r_xram_rsp_to_ixr_cmd_req.read())   r_ixr_cmd_fsm = IXR_CMD_XRAM_TRT;
+                else if(r_config_to_ixr_cmd_req.read())     r_ixr_cmd_fsm = IXR_CMD_CONFIG_TRT;
+                else if(r_cleanup_to_ixr_cmd_req)           r_ixr_cmd_fsm = IXR_CMD_CLEANUP_TRT;
+                break;      
+                /////////////////////////
+            case IXR_CMD_CONFIG_IDLE:
+                {
+                    if     (r_read_to_ixr_cmd_req.read())       r_ixr_cmd_fsm = IXR_CMD_READ_TRT;
+                    else if(r_write_to_ixr_cmd_req.read())      r_ixr_cmd_fsm = IXR_CMD_WRITE_TRT;
+                    else if(r_cas_to_ixr_cmd_req.read())        r_ixr_cmd_fsm = IXR_CMD_CAS_TRT;
+                    else if(r_cleanup_to_ixr_cmd_req)           r_ixr_cmd_fsm = IXR_CMD_CLEANUP_TRT;
+                    else if(r_xram_rsp_to_ixr_cmd_req.read())   r_ixr_cmd_fsm = IXR_CMD_XRAM_TRT;
+                    else if(r_config_to_ixr_cmd_req.read())     r_ixr_cmd_fsm = IXR_CMD_CONFIG_TRT;
+                    break;
+                }
+
+                //////////////////////
+            case IXR_CMD_READ_TRT:       // access TRT for a GET
+                {
+                    if ( r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_CMD )
+                    {
+                        TransactionTabEntry entry = m_trt.read( r_read_to_ixr_cmd_index.read() );
+                        r_ixr_cmd_address = entry.nline * (m_words<<2);
+                        r_ixr_cmd_trdid   = r_read_to_ixr_cmd_index.read();
+                        r_ixr_cmd_get     = true;
+                        r_ixr_cmd_word    = 0;
+                        r_ixr_cmd_fsm     = IXR_CMD_READ_SEND;
+
+#if DEBUG_MEMC_IXR_CMD
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " IXR_CMD_READ_TRT> TRT access"
+                                << " index = " << std::dec << r_read_to_ixr_cmd_index.read()
+                                << " / address = " << std::hex << (entry.nline*(m_words<<2)) << std::endl;
+#endif
+                    }
+                    break;
+                }
+                ///////////////////////
+            case IXR_CMD_WRITE_TRT:       // access TRT for a PUT or a GET
+                {
+                    if ( r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_CMD )
+                    {
+                        TransactionTabEntry entry = m_trt.read( r_write_to_ixr_cmd_index.read() );
+                        r_ixr_cmd_address = entry.nline * (m_words<<2);
+                        r_ixr_cmd_trdid   = r_write_to_ixr_cmd_index.read();
+                        r_ixr_cmd_get     = entry.xram_read;
+                        r_ixr_cmd_word    = 0;
+                        r_ixr_cmd_fsm     = IXR_CMD_WRITE_SEND;
+
+                        // Read data from TRT if PUT transaction
+                        if (not entry.xram_read)
+                        {
+                            for( size_t i=0 ; i<m_words ; i++ ) r_ixr_cmd_wdata[i] = entry.wdata[i];
+                        }
+
+#if DEBUG_MEMC_IXR_CMD
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " IXR_CMD_WRITE_TRT> TRT access"
+                                << " index = " << std::dec << r_write_to_ixr_cmd_index.read()
+                                << " / address = " << std::hex << (entry.nline*(m_words<<2)) << std::endl;
+#endif
+                    }
+                    break;
+                }
+                /////////////////////
+            case IXR_CMD_CAS_TRT:       // access TRT for a PUT or a GET 
+                {
+                    if ( r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_CMD )
+                    {
+                        TransactionTabEntry entry = m_trt.read( r_cas_to_ixr_cmd_index.read() );
+                        r_ixr_cmd_address = entry.nline * (m_words<<2);
+                        r_ixr_cmd_trdid   = r_cas_to_ixr_cmd_index.read();
+                        r_ixr_cmd_get     = entry.xram_read;
+                        r_ixr_cmd_word    = 0;
+                        r_ixr_cmd_fsm     = IXR_CMD_CAS_SEND;
+
+                        // Read data from TRT if PUT transaction
+                        if (not entry.xram_read)
+                        {
+                            for( size_t i=0 ; i<m_words ; i++ ) r_ixr_cmd_wdata[i] = entry.wdata[i];
+                        }
+
+#if DEBUG_MEMC_IXR_CMD
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " IXR_CMD_CAS_TRT> TRT access"
+                                << " index = " << std::dec << r_cas_to_ixr_cmd_index.read()
+                                << " / address = " << std::hex << (entry.nline*(m_words<<2)) << std::endl;
+#endif
+                    }
+                    break;
+                }
+                //////////////////////
+            case IXR_CMD_XRAM_TRT:       // access TRT for a PUT 
+                {
+                    if ( r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_CMD )
+                    {
+                        TransactionTabEntry entry = m_trt.read( r_xram_rsp_to_ixr_cmd_index.read() );
+                        r_ixr_cmd_address = entry.nline * (m_words<<2);
+                        r_ixr_cmd_trdid   = r_xram_rsp_to_ixr_cmd_index.read();
+                        r_ixr_cmd_get     = false;
+                        r_ixr_cmd_word    = 0;
+                        r_ixr_cmd_fsm     = IXR_CMD_XRAM_SEND;
+                        for( size_t i=0 ; i<m_words ; i++ ) r_ixr_cmd_wdata[i] = entry.wdata[i];
+
+#if DEBUG_MEMC_IXR_CMD
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " IXR_CMD_XRAM_TRT> TRT access"
+                                << " index = " << std::dec << r_xram_rsp_to_ixr_cmd_index.read()
+                                << " / address = " << std::hex << (entry.nline*(m_words<<2)) << std::endl;
+#endif
+                    }
+                    break;
+                }
+                //////////////////////
+            case IXR_CMD_CLEANUP_TRT:       // access TRT for a PUT 
+                {
+                    if ( r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_CMD )
+                    {
+
+                        TransactionTabEntry entry = m_trt.read( r_cleanup_to_ixr_cmd_index.read() );
+                        r_ixr_cmd_address = entry.nline * (m_words<<2);
+                        r_ixr_cmd_trdid   = r_cleanup_to_ixr_cmd_index.read();
+                        r_ixr_cmd_get     = false;
+                        r_ixr_cmd_word    = 0;
+                        r_ixr_cmd_fsm     = IXR_CMD_CLEANUP_DATA_SEND;
+                        for( size_t i=0 ; i<m_words ; i++ ) r_ixr_cmd_wdata[i] = entry.wdata[i];
+
+#if DEBUG_MEMC_IXR_CMD
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " IXR_CMD_CLEANUP_TRT> TRT access"
+                                << " index = " << std::dec << r_cleanup_to_ixr_cmd_index.read()
+                                << " / address = " << std::hex << (entry.nline*(m_words<<2)) << std::endl;
+#endif
+                    }
+                    break;
+                }
+                ////////////////////////
+            case IXR_CMD_CONFIG_TRT:       // access TRT for a PUT
+                {
+                    if ( r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_CMD )
+                    {
+                        TransactionTabEntry entry = m_trt.read( r_config_to_ixr_cmd_index.read() );
+                        r_ixr_cmd_address = entry.nline * (m_words<<2);
+                        r_ixr_cmd_trdid   = r_config_to_ixr_cmd_index.read();
+                        r_ixr_cmd_get     = false;
+                        r_ixr_cmd_word    = 0;
+                        r_ixr_cmd_fsm     = IXR_CMD_CONFIG_SEND;
+                        for( size_t i=0 ; i<m_words ; i++ ) r_ixr_cmd_wdata[i] = entry.wdata[i];
+
+#if DEBUG_MEMC_IXR_CMD
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " IXR_CMD_CONFIG_TRT> TRT access"
+                                << " index = " << std::dec << r_config_to_ixr_cmd_index.read()
+                                << " / address = " << std::hex << (entry.nline*(m_words<<2)) << std::endl;
+#endif
+                    }
+                    break;
+                }
+
+                ///////////////////////
+            case IXR_CMD_READ_SEND:      // send a get from READ FSM
+                {
+                    if(p_vci_ixr.cmdack)
+                    {
+                        r_ixr_cmd_fsm         = IXR_CMD_READ_IDLE;
+                        r_read_to_ixr_cmd_req = false;
+
+#if DEBUG_MEMC_IXR_CMD
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " IXR_CMD_READ_SEND> GET request:" << std::hex
+                                << " address = " << r_ixr_cmd_address.read() + (r_ixr_cmd_word.read()<<2) << std::endl;
+#endif
+                    }
+                    break;
+                }
+                ////////////////////////
+            case IXR_CMD_WRITE_SEND:     // send a put or get from WRITE FSM
+                {
+                    if(p_vci_ixr.cmdack)
+                    {
+                        if (not r_ixr_cmd_get.read())   // PUT
+                        {
+                            if(r_ixr_cmd_word.read() == (m_words - 2))
+                            {
+                                r_ixr_cmd_fsm          = IXR_CMD_WRITE_IDLE;
+                                r_write_to_ixr_cmd_req = false;
+                            }
+                            else
+                            {
+                                r_ixr_cmd_word = r_ixr_cmd_word.read() + 2;
+                            }
+
+#if DEBUG_MEMC_IXR_CMD
+                            if(m_debug)
+                                std::cout << "  <MEMC " << name() << " IXR_CMD_WRITE_SEND> PUT request:" << std::hex
+                                    << " address = " << r_ixr_cmd_address.read() + (r_ixr_cmd_word.read()<<2) << std::endl;
+#endif
+                        }
+                        else                                  // GET
+                        {
+                            r_ixr_cmd_fsm          = IXR_CMD_WRITE_IDLE;
+                            r_write_to_ixr_cmd_req = false;
+
+#if DEBUG_MEMC_IXR_CMD
+                            if(m_debug)
+                                std::cout << "  <MEMC " << name() << " IXR_CMD_WRITE_SEND> GET request:" << std::hex
+                                    << " address = " << r_ixr_cmd_address.read() + (r_ixr_cmd_word.read()<<2) << std::endl;
+#endif
+                        }
+                    }
+                    break;
+                }
+                //////////////////////
+            case IXR_CMD_CAS_SEND:      // send a put or get command from CAS FSM
+                {
+                    if(p_vci_ixr.cmdack)
+                    {
+                        if (not r_ixr_cmd_get.read()) // PUT
+                        {
+                            if(r_ixr_cmd_word.read() == (m_words - 2))
+                            {
+                                r_ixr_cmd_fsm        = IXR_CMD_CAS_IDLE;
+                                r_cas_to_ixr_cmd_req = false;
+                            }
+                            else
+                            {
+                                r_ixr_cmd_word = r_ixr_cmd_word.read() + 2;
+                            }
+
+#if DEBUG_MEMC_IXR_CMD
+                            if(m_debug)
+                                std::cout << "  <MEMC " << name() << " IXR_CMD_CAS_SEND> PUT request:" << std::hex
+                                    << " address = " << r_ixr_cmd_address.read() + (r_ixr_cmd_word.read()<<2) << std::endl;
+#endif
+                        }
+                        else                            // GET
+                        {
+                            r_ixr_cmd_fsm        = IXR_CMD_CAS_IDLE;
+                            r_cas_to_ixr_cmd_req = false;
+
+#if DEBUG_MEMC_IXR_CMD
+                            if(m_debug)
+                                std::cout << "  <MEMC " << name() << " IXR_CMD_CAS_SEND> GET request:" << std::hex
+                                    << " address = " << r_ixr_cmd_address.read() + (r_ixr_cmd_word.read()<<2) << std::endl;
+#endif
+                        }
+                    }
+                    break;
+                }
+                ///////////////////////
+            case IXR_CMD_XRAM_SEND:     // send a put from XRAM_RSP FSM
+                {
+                    if(p_vci_ixr.cmdack.read())
+                    {
+                        if(r_ixr_cmd_word.read() == (m_words - 2))
+                        {
+                            r_ixr_cmd_fsm = IXR_CMD_XRAM_IDLE;
+                            r_xram_rsp_to_ixr_cmd_req = false;
+                        }
+                        else
+                        {
+                            r_ixr_cmd_word = r_ixr_cmd_word.read() + 2;
+                        }
+#if DEBUG_MEMC_IXR_CMD
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " IXR_CMD_XRAM_SEND> PUT request:" << std::hex
+                                << " address = " << r_ixr_cmd_address.read() + (r_ixr_cmd_word.read()<<2) << std::endl;
+#endif
+                    }
+                    break;
+                }
+
+                ////////////////////////
+            case IXR_CMD_CLEANUP_DATA_SEND:     // send a put command to XRAM
+                {
+                    if(p_vci_ixr.cmdack.read())
+                    {
+                        if(r_ixr_cmd_word.read() == (m_words - 2))
+                        {
+                            r_ixr_cmd_fsm = IXR_CMD_CLEANUP_IDLE;
+                            r_cleanup_to_ixr_cmd_req = false;
+                            //r_ixr_cmd_word = 0;
+                            //r_xram_rsp_to_ixr_cmd_inval_ncc_pending = false;
+                        }
+                        else
+                        {
+                            r_ixr_cmd_word = r_ixr_cmd_word.read() + 2;
+                        }
+
+#if DEBUG_MEMC_IXR_CMD
+                        if(m_debug)
+                        {
+                            std::cout << "  <MEMC " << name() << ".IXR_CMD_CLEANUP_DATA_SEND> Send a put request to xram" << std::endl;
+                        }
+#endif
+                    }
+                    break;
+                }
+
+                /////////////////////////
+            case IXR_CMD_CONFIG_SEND:     // send a put from CONFIG FSM
+                {
+                    if(p_vci_ixr.cmdack.read())
+                    {
+                        if(r_ixr_cmd_word.read() == (m_words - 2))
+                        {
+                            r_ixr_cmd_fsm = IXR_CMD_CONFIG_IDLE;
+                            r_config_to_ixr_cmd_req = false;
+                        }
+                        else
+                        {
+                            r_ixr_cmd_word = r_ixr_cmd_word.read() + 2;
+                        }
+
+#if DEBUG_MEMC_IXR_CMD
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " IXR_CMD_CONFIG_SEND> PUT request:" << std::hex
+                                << " address = " << r_ixr_cmd_address.read() + (r_ixr_cmd_word.read()<<2) << std::endl;
+#endif
+                    }
+                    break;
+                }
+        } // end switch r_ixr_cmd_fsm
+
+        ////////////////////////////////////////////////////////////////////////////
+        //                IXR_RSP FSM
+        ////////////////////////////////////////////////////////////////////////////
+        // The IXR_RSP FSM receives the response packets from the XRAM,
+        // for both PUT transaction, and GET transaction.
+        //
+        // - A response to a PUT request is a single-cell VCI packet.
+        // The TRT index is contained in the RTRDID field.
+        // The FSM takes the lock protecting the TRT, and the corresponding
+        // entry is erased. If an acknowledge was required (in case of software SYNC)
+        // the r_config_rsp_lines counter is decremented.  
+        //
+        // - A response to a GET request is a multi-cell VCI packet.
+        // The TRT index is contained in the RTRDID field.
+        // The N cells contain the N words of the cache line in the RDATA field.
+        // The FSM takes the lock protecting the TRT to store the line in the TRT
+        // (taking into account the write requests already stored in the TRT).
+        // When the line is completely written, the r_ixr_rsp_to_xram_rsp_rok[index]  
+        // signal is set to inform the XRAM_RSP FSM.
+        ///////////////////////////////////////////////////////////////////////////////
+
+        switch(r_ixr_rsp_fsm.read())
+        {
+            //////////////////
+            case IXR_RSP_IDLE:  // test transaction type: PUT/GET
+                {
+                    if(p_vci_ixr.rspval.read())
+                    {
+                        r_ixr_rsp_cpt       = 0;
+                        r_ixr_rsp_trt_index = p_vci_ixr.rtrdid.read();
+
+                        assert( ((p_vci_ixr.rerror.read() & 0x1) == 0) and
+                                "MEMC ERROR in IXR_RSP state: XRAM response error !");
+
+                        if(p_vci_ixr.reop.read())   // PUT
+                        {
+                            r_ixr_rsp_fsm = IXR_RSP_TRT_ERASE;
+                        }
+
+                        else                       // GET transaction
+                        {
+                            r_ixr_rsp_fsm = IXR_RSP_TRT_READ;
+
+#if DEBUG_MEMC_IXR_RSP
+                            if(m_debug)
+                                std::cout << "  <MEMC " << name()
+                                    << " IXR_RSP_IDLE> Response from XRAM to a get transaction" << std::endl;
+#endif
+                        }     
+                    } 
+                    break;
+                }
+                ////////////////////////
+            case IXR_RSP_ACK:     // Acknowledge PUT transaction
+                {
+                    r_ixr_rsp_fsm = IXR_RSP_IDLE;
+                    break;
+                }
+
+                ////////////////////////
+            case IXR_RSP_TRT_ERASE:   // erase the entry in the TRT
+                // decrease the line counter if config request
+                {
+                    if(r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_RSP)
+                    {
+                        size_t  index = r_ixr_rsp_trt_index.read(); 
+                        if (m_trt.is_config(index))     // it's a config transaction
+                        {
+                            config_rsp_lines_ixr_rsp_decr = true;
+                            m_trt.erase(index);
+                            r_ixr_rsp_fsm = IXR_RSP_IDLE;
+                        }
+                        else                            // not a config transaction
+                        {
+                            m_trt.erase(index);
+                            r_ixr_rsp_fsm = IXR_RSP_IDLE;
+                        }
+
+#if DEBUG_MEMC_IXR_RSP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " IXR_RSP_TRT_ERASE> Erase TRT entry "
+                                << r_ixr_rsp_trt_index.read() << std::endl;
+#endif
+                    }
+                    break;
+                }
+                //////////////////////
+            case IXR_RSP_TRT_READ:    // write a 64 bits data in the TRT
+                {
+                    if((r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_RSP) and  p_vci_ixr.rspval)
+                    {
+                        size_t      index    = r_ixr_rsp_trt_index.read();
+                        size_t      word     = r_ixr_rsp_cpt.read();
+                        bool        eop      = p_vci_ixr.reop.read();
+                        wide_data_t data     = p_vci_ixr.rdata.read();
+                        bool        error    = ((p_vci_ixr.rerror.read() & 0x1) == 1);
+
+                        assert(((eop == (word == (m_words-2))) or error) and
+                                "MEMC ERROR in IXR_RSP_TRT_READ state : invalid response from XRAM");
+
+                        m_trt.write_rsp( index,
+                                word,
+                                data );
+
+                        r_ixr_rsp_cpt = word + 2;
+
+                        if(eop)
+                        {
+                            r_ixr_rsp_to_xram_rsp_rok[r_ixr_rsp_trt_index.read()]=true;
+                            r_ixr_rsp_fsm = IXR_RSP_IDLE;
+                        }
+
+#if DEBUG_MEMC_IXR_RSP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " IXR_RSP_TRT_READ> Writing a word in TRT : "
+                                << " index = " << std::dec << index
+                                << " / word = " << word
+                                << " / data = " << std::hex << data << std::endl;
+#endif
+                        m_cpt_ixr_fsm_n_trt_lock++;
+                    }
+                    m_cpt_ixr_fsm_trt_lock++;
+                    break;
+                }
+        } // end swich r_ixr_rsp_fsm
+
+        ////////////////////////////////////////////////////////////////////////////
+        //                XRAM_RSP FSM
+        ////////////////////////////////////////////////////////////////////////////
+        // The XRAM_RSP FSM handles the incoming cache lines after an XRAM GET.
+        // The cache line has been written in the TRT by the IXR_CMD_FSM.
+        // As the IXR_RSP FSM and the XRAM_RSP FSM are running in parallel,
+        // there is as many flip-flops r_ixr_rsp_to_xram_rsp_rok[i] as the number 
+        // of entries in the TRT, that are handled with a round-robin priority...
+        //
+        // The FSM takes the lock protecting TRT, and the lock protecting DIR.
+        // The selected TRT entry is copied in the local buffer r_xram_rsp_trt_buf.
+        // It selects a cache slot and save the victim line in another local buffer
+        // r_xram_rsp_victim_***.
+        // It writes the line extracted from TRT in the cache.
+        // If it was a read MISS, the XRAM_RSP FSM send a request to the TGT_RSP
+        // FSM to return the cache line to the registered processor.
+        // If there is no empty slot, a victim line is evicted, and
+        // invalidate requests are sent to the L1 caches containing copies.
+        // If this line is dirty, the XRAM_RSP FSM send a request to the IXR_CMD
+        // FSM to save the victim line to the XRAM, and register the write transaction
+        // in the TRT (using the entry previously used by the read transaction).
+        ///////////////////////////////////////////////////////////////////////////////
+
+        switch(r_xram_rsp_fsm.read())
+        {
+            ///////////////////
+            case XRAM_RSP_IDLE: // scan the XRAM responses / select a TRT index (round robin)
+                {
+                    size_t old   = r_xram_rsp_trt_index.read();
+                    size_t lines = m_trt_lines;
+                    for(size_t i=0 ; i<lines ; i++)
+                    {
+                        size_t index = (i+old+1) %lines;
+                        if(r_ixr_rsp_to_xram_rsp_rok[index])
+                        {
+                            r_xram_rsp_trt_index             = index;
+                            r_ixr_rsp_to_xram_rsp_rok[index] = false;
+                            r_xram_rsp_fsm                   = XRAM_RSP_DIR_LOCK;
+
+#if DEBUG_MEMC_XRAM_RSP
+                            if(m_debug)
+                                std::cout << "  <MEMC " << name() << " XRAM_RSP_IDLE>"
+                                    << " Available cache line in TRT:"
+                                    << " index = " << std::dec << index << std::endl;
+#endif
+                            break;
+                        }
+                    } 
+                    break;
+                }
+                ///////////////////////
+            case XRAM_RSP_DIR_LOCK: // Takes the DIR lock and the TRT lock
+                // Copy the TRT entry in a local buffer
+                {
+                    if((r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP) and
+                            (r_alloc_trt_fsm.read() == ALLOC_TRT_XRAM_RSP))
+                    {
+                        // copy the TRT entry in the r_xram_rsp_trt_buf local buffer
+                        size_t  index = r_xram_rsp_trt_index.read();
+                        r_xram_rsp_trt_buf.copy( m_trt.read(index) );
+                        r_xram_rsp_fsm = XRAM_RSP_TRT_COPY;
+
+#if DEBUG_MEMC_XRAM_RSP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " XRAM_RSP_DIR_LOCK>"
+                                << " Get access to DIR and TRT" << std::endl;
+#endif
+                        m_cpt_xram_rsp_fsm_n_dir_lock++;
+                        m_cpt_xram_rsp_fsm_n_trt_lock++;
+                    }
+                    m_cpt_xram_rsp_fsm_dir_lock++;
+                    m_cpt_xram_rsp_fsm_trt_lock++;
+                    break;
+                }
+                ///////////////////////
+            case XRAM_RSP_TRT_COPY: // Select a victim cache line
+                // and copy it in a local buffer
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP) and
+                            "MEMC ERROR in XRAM_RSP_TRT_COPY state: Bad DIR allocation");
+
+                    assert( (r_alloc_trt_fsm.read() == ALLOC_TRT_XRAM_RSP) and
+                            "MEMC ERROR in XRAM_RSP_TRT_COPY state: Bad TRT allocation");
+
+                    // selects & extracts a victim line from cache
+                    size_t way = 0;
+                    size_t set = m_y[(addr_t)(r_xram_rsp_trt_buf.nline * m_words * 4)];
+
+                    DirectoryEntry victim(m_cache_directory.select(set, way));
+
+                    bool inval = (victim.count != 0) and (victim.state != ENTRY_INVALID) ;
+
+                    // copy the victim line in a local buffer
+                    m_cache_data.read_line(way, set, r_xram_rsp_victim_data);
+
+                    r_xram_rsp_victim_copy      = victim.owner.srcid;
+                    r_xram_rsp_victim_copy_inst = victim.owner.inst;
+                    r_xram_rsp_victim_count     = victim.count;
+                    r_xram_rsp_victim_ptr       = victim.ptr;
+                    r_xram_rsp_victim_way       = way;
+                    r_xram_rsp_victim_set       = set;
+                    r_xram_rsp_victim_nline     = victim.tag*m_sets + set;
+                    r_xram_rsp_victim_is_cnt    = victim.is_cnt;
+                    r_xram_rsp_victim_inval     = inval;
+                    r_xram_rsp_victim_dirty     = victim.dirty or (victim.state == ENTRY_EXCLUSIVE); //a NCC line is by default considered as dirty in the L1: we must take a reservation on a TRT entry
+                    r_xram_rsp_victim_state     = victim.state;
+
+                    assert( victim.state != ENTRY_LOCKED && "XRAM RSP SELECTED A LOCKED VICTIM ");
+
+                    if( not r_xram_rsp_trt_buf.rerror ) r_xram_rsp_fsm = XRAM_RSP_IVT_LOCK;
+                    else                                r_xram_rsp_fsm = XRAM_RSP_ERROR_ERASE;
+                    
+                    if( way == -1) r_xram_rsp_fsm = XRAM_RSP_DIR_LOCK;
+
+#if DEBUG_MEMC_XRAM_RSP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " XRAM_RSP_TRT_COPY>"
+                            << " Select a victim slot: "
+                            << " / way = " << std::dec << way
+                            << " / state = " << std::dec << victim.state
+                            << " / is_cnt = " << std::dec << victim.is_cnt
+                            << " / set = " << set
+                            << "/ count = " << victim.count
+                            << " / inval_required = " << inval << std::endl;
+#endif
+                    break;
+                }
+                ///////////////////////
+            case XRAM_RSP_IVT_LOCK:   // Keep DIR and TRT locks and take the IVT lock 
+                // to check a possible pending inval
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP) and
+                            "MEMC ERROR in XRAM_RSP_IVT_LOCK state: Bad DIR allocation");
+
+                    assert( (r_alloc_trt_fsm.read() == ALLOC_TRT_XRAM_RSP) and
+                            "MEMC ERROR in XRAM_RSP_IVT_LOCK state: Bad TRT allocation");
+
+                    if(r_alloc_ivt_fsm == ALLOC_IVT_XRAM_RSP)
+                    {
+                        size_t index = 0;
+                        if(m_ivt.search_inval(r_xram_rsp_trt_buf.nline, index))  // pending inval
+                        {
+                            r_xram_rsp_fsm = XRAM_RSP_INVAL_WAIT;
+
+#if DEBUG_MEMC_XRAM_RSP
+                            if(m_debug)
+                                std::cout << "  <MEMC " << name() << " XRAM_RSP_IVT_LOCK>"
+                                    << " Get acces to IVT, but line invalidation registered"
+                                    << " / address = " << std::hex << r_xram_rsp_trt_buf.nline*m_words*4
+                                    << " / index = " << std::dec << index << std::endl;
+#endif
+
+                        }
+                        else if(m_ivt.is_full() and r_xram_rsp_victim_inval.read()) // IVT full
+                        {
+                            r_xram_rsp_fsm = XRAM_RSP_INVAL_WAIT;
+
+#if DEBUG_MEMC_XRAM_RSP
+                            if(m_debug)
+                                std::cout << "  <MEMC " << name() << " XRAM_RSP_IVT_LOCK>"
+                                    << " Get acces to IVT, but inval required and IVT full" << std::endl;
+#endif
+                        }
+                        else
+                        {
+                            r_xram_rsp_fsm = XRAM_RSP_DIR_UPDT;
+
+#if DEBUG_MEMC_XRAM_RSP
+                            if(m_debug)
+                                std::cout << "  <MEMC " << name() << " XRAM_RSP_IVT_LOCK>"
+                                    << " Get acces to IVT / no pending inval request" << std::endl;
+#endif
+                        }
+                    }
+                    break;
+                }
+                /////////////////////////
+            case XRAM_RSP_INVAL_WAIT: // release all locks and returns to DIR_LOCK to retry
+                {
+
+#if DEBUG_MEMC_XRAM_RSP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " XRAM_RSP_INVAL_WAIT>"
+                            << " Release all locks and retry" << std::endl;
+#endif
+                    r_xram_rsp_fsm = XRAM_RSP_DIR_LOCK;
+                    break;
+                }
+                ///////////////////////
+            case XRAM_RSP_DIR_UPDT:   // updates the cache (both data & directory),
+                // erases the TRT entry if victim not dirty,
+                // and set inval request in IVT if required
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP) and
+                            "MEMC ERROR in XRAM_RSP_DIR_UPDT state: Bad DIR allocation");
+
+                    assert( (r_alloc_trt_fsm.read() == ALLOC_TRT_XRAM_RSP) and
+                            "MEMC ERROR in XRAM_RSP_DIR_UPDT state: Bad TRT allocation");
+
+                    assert( (r_alloc_ivt_fsm.read() == ALLOC_IVT_XRAM_RSP) and
+                            "MEMC ERROR in XRAM_RSP_DIR_UPDT state: Bad IVT allocation");
+
+                    // check if this is an instruction read, this means pktid is either
+                    // TYPE_READ_INS_UNC   0bX010 with TSAR encoding
+                    // TYPE_READ_INS_MISS  0bX011 with TSAR encoding
+
+                    // check if this is a cached read, this means pktid is either
+                    // TYPE_READ_DATA_MISS 0bX001 with TSAR encoding
+                    // TYPE_READ_INS_MISS  0bX011 with TSAR encoding
+                    bool cached_read = (r_xram_rsp_trt_buf.pktid != 0) and //data unc
+                                       (r_xram_rsp_trt_buf.pktid != 0x2) and //inst unc
+                                       (r_xram_rsp_trt_buf.pktid != 0x6) and //LL
+                                        r_xram_rsp_trt_buf.proc_read;
+
+                    bool inst_read = ((r_xram_rsp_trt_buf.pktid == 0x3) or (r_xram_rsp_trt_buf.pktid == 0x2)) and r_xram_rsp_trt_buf.proc_read;
+
+
+                    bool dirty = false;
+
+                    // update cache data
+                    size_t set   = r_xram_rsp_victim_set.read();
+                    size_t way   = r_xram_rsp_victim_way.read();
+                    for(size_t word=0; word<m_words ; word++)
+                    {
+                        m_cache_data.write(way, set, word, r_xram_rsp_trt_buf.wdata[word]);
+                        dirty = dirty or (r_xram_rsp_trt_buf.wdata_be[word] != 0);
+
+                    }
+
+                    // update cache directory
+                    DirectoryEntry entry;
+
+                    if(inst_read and (r_xram_rsp_trt_buf.proc_read))
+                    {
+                        entry.state = ENTRY_SHARED;
+                    }
+                    else
+                    {
+                        entry.state = ENTRY_EXCLUSIVE;
+                    }
+
+                    entry.is_cnt  = false;
+                    entry.lock    = false;
+                    entry.dirty   = dirty;
+                    entry.tag     = r_xram_rsp_trt_buf.nline / m_sets;
+                    entry.ptr     = 0;
+                    if(cached_read and r_xram_rsp_trt_buf.proc_read)
+                    {
+                        entry.owner.srcid   = r_xram_rsp_trt_buf.srcid;
+                        entry.owner.inst    = inst_read;
+                        entry.count         = 1;
+                    }
+                    else
+                    {
+                        entry.owner.srcid    = 0;
+                        entry.owner.inst     = 0;
+                        entry.count          = 0;
+                    }
+                    m_cache_directory.write(set, way, entry);
+                    //RWT: keep the coherence information in order to send it to the read_rsp
+                    r_xram_rsp_coherent = inst_read; 
+                    // request an invalidattion request in IVT for victim line
+                    if(r_xram_rsp_victim_inval.read())
+                    {
+                        bool   broadcast    = r_xram_rsp_victim_is_cnt.read();
+                        size_t index        = 0;
+                        size_t count_copies = r_xram_rsp_victim_count.read();
+
+                        bool   wok = m_ivt.set(false,      // it's an inval transaction
+                                               broadcast,  // set broadcast bit
+                                               false,      // no response required 
+                                               false,      // no acknowledge required 
+                                               0,          // srcid
+                                               0,          // trdid
+                                               0,          // pktid
+                                               r_xram_rsp_victim_nline.read(),
+                                               count_copies,
+                                               index);
+
+                        r_xram_rsp_ivt_index = index;
+                        assert( wok and
+                                "MEMC ERROR in XRAM_RSP_DIR_UPDT state: IVT should not be full"); 
+
+                    }
+                    if (!r_xram_rsp_victim_coherent.read())
+                    {
+                        addr_t min = r_xram_rsp_victim_nline.read()*m_words*4 ;
+                        addr_t max = r_xram_rsp_victim_nline.read()*m_words*4 + (m_words - 1)*4;
+                        m_llsc_table.sw(min, max);
+                    }
+#if DEBUG_MEMC_XRAM_RSP
+                    if(m_debug)
+                    {
+                        std::cout << "  <MEMC " << name() << " XRAM_RSP_DIR_UPDT>"
+                            << " Cache update: "
+                            << " way = " << std::dec << way
+                            << " / set = " << set
+                            << " / owner_id = " << std::hex << entry.owner.srcid
+                            << " / owner_ins = " << std::dec << entry.owner.inst
+                            << " / count = " << entry.count
+                            << " / nline = " << r_xram_rsp_trt_buf.nline
+                            << " / is_cnt = " << entry.is_cnt << std::endl;
+                        if(r_xram_rsp_victim_inval.read())
+                            std::cout << "                           Invalidation request for victim line "
+                                << std::hex << r_xram_rsp_victim_nline.read()
+                                << " / broadcast = " << r_xram_rsp_victim_is_cnt.read() << std::endl;
+                    }
+#endif
+
+                    // If the victim is not dirty (RWT: if it is not coherent, we can not know wether it is dirty or not), we don't need another XRAM  put transaction,
+                    // and we can erase the TRT entry
+                    if( (not r_xram_rsp_victim_dirty.read()) or (r_xram_rsp_victim_state.read() == ENTRY_INVALID))  
+                    {
+                        m_trt.erase(r_xram_rsp_trt_index.read());
+                    }
+                    // Next state
+                    if(r_xram_rsp_victim_dirty.read())       r_xram_rsp_fsm = XRAM_RSP_TRT_DIRTY;
+                    else if(r_xram_rsp_trt_buf.proc_read)    r_xram_rsp_fsm = XRAM_RSP_DIR_RSP;
+                    else if(r_xram_rsp_victim_inval.read())  r_xram_rsp_fsm = XRAM_RSP_INVAL;
+                    else                                     r_xram_rsp_fsm = XRAM_RSP_IDLE;
+                    break;
+                }
+                ////////////////////////
+            case XRAM_RSP_TRT_DIRTY:  // set the TRT entry (write to XRAM) if the victim is dirty or not coherent (RWT)
+                {
+                    if(r_alloc_trt_fsm.read() == ALLOC_TRT_XRAM_RSP)
+                    {
+                        std::vector<data_t> data_vector;
+                        data_vector.clear();
+                        for(size_t i=0; i<m_words; i++)
+                        {
+                            data_vector.push_back(r_xram_rsp_victim_data[i].read());
+                        }
+
+                        m_trt.set( r_xram_rsp_trt_index.read(),
+                                   false,                             // PUT
+                                   r_xram_rsp_victim_nline.read(),    // line index
+                                   0,                                 // unused
+                                   0,                                 // unused
+                                   0,                                 // unused
+                                   false,                             // not proc_read
+                                   0,                                 // unused
+                                   0,                                 // unused
+                                   std::vector<be_t>(m_words,0xF),                         
+                                   data_vector);
+#if DEBUG_MEMC_XRAM_RSP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " XRAM_RSP_TRT_DIRTY>"
+                                << " Set TRT entry for the put transaction"
+                                << " / dirty victim line = " << r_xram_rsp_victim_nline.read() << std::endl;
+#endif
+
+                        //        if( not r_xram_rsp_victim_coherent )
+                        //            std::cout << "a victim coherent not sent trt index =" << r_xram_rsp_trt_index.read() << std::endl;
+                        if(r_xram_rsp_trt_buf.proc_read)         r_xram_rsp_fsm = XRAM_RSP_DIR_RSP;
+                        else if(r_xram_rsp_victim_inval.read())  r_xram_rsp_fsm = XRAM_RSP_INVAL;
+                        else                                     r_xram_rsp_fsm = XRAM_RSP_WRITE_DIRTY;
+                        m_cpt_xram_rsp_fsm_n_trt_lock++;
+                    }
+
+                    m_cpt_xram_rsp_fsm_trt_lock++;
+
+                    break;
+                }
+                //////////////////////
+            case XRAM_RSP_DIR_RSP:     // Request a response to TGT_RSP FSM
+                {
+                    if( not r_xram_rsp_to_tgt_rsp_req.read())
+                    {
+                        r_xram_rsp_to_tgt_rsp_srcid = r_xram_rsp_trt_buf.srcid;
+                        r_xram_rsp_to_tgt_rsp_trdid = r_xram_rsp_trt_buf.trdid;
+                        if (r_xram_rsp_coherent.read())
+                        {
+                            r_xram_rsp_to_tgt_rsp_pktid = 0x0 + r_xram_rsp_trt_buf.pktid;//SHARED
+                        }
+                        else
+                        {
+                            r_xram_rsp_to_tgt_rsp_pktid = 0x8 + r_xram_rsp_trt_buf.pktid;//EXCLUSIVE
+                        }
+                        for(size_t i=0; i < m_words; i++)
+                        {
+                            r_xram_rsp_to_tgt_rsp_data[i] = r_xram_rsp_trt_buf.wdata[i];
+                        }
+                        r_xram_rsp_to_tgt_rsp_word   = r_xram_rsp_trt_buf.word_index;
+                        r_xram_rsp_to_tgt_rsp_length = r_xram_rsp_trt_buf.read_length;
+                        r_xram_rsp_to_tgt_rsp_ll_key = r_xram_rsp_trt_buf.ll_key;
+                        r_xram_rsp_to_tgt_rsp_rerror = false;
+                        r_xram_rsp_to_tgt_rsp_req    = true;
+
+
+                        if(r_xram_rsp_victim_inval)      r_xram_rsp_fsm = XRAM_RSP_INVAL;
+                        else if(r_xram_rsp_victim_dirty) r_xram_rsp_fsm = XRAM_RSP_WRITE_DIRTY;
+                        else                             r_xram_rsp_fsm = XRAM_RSP_IDLE;
+
+#if DEBUG_MEMC_XRAM_RSP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " XRAM_RSP_DIR_RSP>"
+                                << " Request the TGT_RSP FSM to return data:"
+                                << " rsrcid = " << std::hex << r_xram_rsp_trt_buf.srcid
+                                << " / r_xram_rsp_coherent = " << std::hex << r_xram_rsp_coherent.read()
+                                << " / address = " << std::hex << r_xram_rsp_trt_buf.nline*m_words*4
+                                << " / nwords = " << std::dec << r_xram_rsp_trt_buf.read_length << std::endl;
+#endif
+                    }
+                    break;
+                }
+                ////////////////////
+            case XRAM_RSP_INVAL:  // send invalidate request to CC_SEND FSM
+                {
+                    if(!r_xram_rsp_to_cc_send_multi_req.read() and
+                            !r_xram_rsp_to_cc_send_brdcast_req.read())
+                    {
+                        bool multi_req = !r_xram_rsp_victim_is_cnt.read();
+                        bool last_multi_req  = multi_req and (r_xram_rsp_victim_count.read() == 1);
+                        bool not_last_multi_req = multi_req and (r_xram_rsp_victim_count.read() != 1);
+
+                        r_xram_rsp_to_cc_send_multi_req    = last_multi_req;
+                        r_xram_rsp_to_cc_send_brdcast_req  = r_xram_rsp_victim_is_cnt.read();
+                        r_xram_rsp_to_cc_send_nline        = r_xram_rsp_victim_nline.read();
+                        r_xram_rsp_to_cc_send_trdid        = r_xram_rsp_ivt_index;
+                        xram_rsp_to_cc_send_fifo_srcid     = r_xram_rsp_victim_copy.read();
+                        xram_rsp_to_cc_send_fifo_inst      = r_xram_rsp_victim_copy_inst.read();
+                        xram_rsp_to_cc_send_fifo_put       = multi_req;
+                        r_xram_rsp_next_ptr                = r_xram_rsp_victim_ptr.read();
+
+                        if(r_xram_rsp_victim_dirty.read() and (r_xram_rsp_victim_state.read() == ENTRY_SHARED))  
+                                                     r_xram_rsp_fsm = XRAM_RSP_WRITE_DIRTY;
+                        else if(not_last_multi_req)  r_xram_rsp_fsm = XRAM_RSP_HEAP_REQ;
+                        else                         r_xram_rsp_fsm = XRAM_RSP_IDLE;
+
+                        // std::cout << "cleanup sent for trt index =" << r_xram_rsp_trt_index.read() << std::endl;
+#if DEBUG_MEMC_XRAM_RSP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " XRAM_RSP_INVAL>"
+                                << " Send an inval request to CC_SEND FSM"
+                                << " / address = " << r_xram_rsp_victim_nline.read()*m_words*4 << std::endl;
+#endif
+                    }
+                    else
+                    {
+#if DEBUG_MEMC_XRAM_RSP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " XRAM_RSP_INVAL>"
+                                << " multi req = " << r_xram_rsp_to_cc_send_multi_req.read()
+                                << " / bdcast req " << r_xram_rsp_to_cc_send_brdcast_req.read() << std::endl;
+#endif
+                    }
+                    break;
+                }
+                //////////////////////////
+            case XRAM_RSP_WRITE_DIRTY:  // send a write request to IXR_CMD FSM
+                {
+                    if ( not r_xram_rsp_to_ixr_cmd_req.read() )
+                    {
+                        r_xram_rsp_to_ixr_cmd_req = true;
+                        r_xram_rsp_to_ixr_cmd_index = r_xram_rsp_trt_index.read();
+
+                        m_cpt_write_dirty++;
+
+                        bool multi_req = not r_xram_rsp_victim_is_cnt.read() and 
+                            r_xram_rsp_victim_inval.read();
+                        bool not_last_multi_req = multi_req and (r_xram_rsp_victim_count.read() != 1);
+
+                        if(not_last_multi_req)   r_xram_rsp_fsm = XRAM_RSP_HEAP_REQ;
+                        else                     r_xram_rsp_fsm = XRAM_RSP_IDLE;
+
+#if DEBUG_MEMC_XRAM_RSP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " XRAM_RSP_WRITE_DIRTY>"
+                                << " Send the put request to IXR_CMD FSM"
+                                << " / victim line = " << r_xram_rsp_victim_nline.read() << std::endl;
+#endif
+                    }
+                    break;
+                }
+                /////////////////////////
+            case XRAM_RSP_HEAP_REQ:    // Get the lock to the HEAP
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_XRAM_RSP)
+                    {
+                        r_xram_rsp_fsm = XRAM_RSP_HEAP_ERASE;
+                        m_cpt_xram_rsp_fsm_n_heap_lock++;
+                    }
+
+#if DEBUG_MEMC_XRAM_RSP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " XRAM_RSP_HEAP_REQ>"
+                            << " Requesting HEAP lock" << std::endl;
+#endif
+
+                    m_cpt_xram_rsp_fsm_heap_lock++;
+
+                    break;
+                }
+                /////////////////////////
+            case XRAM_RSP_HEAP_ERASE: // erase the copies and send invalidations
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_XRAM_RSP)
+                    {
+                        HeapEntry entry = m_heap.read(r_xram_rsp_next_ptr.read());
+
+                        xram_rsp_to_cc_send_fifo_srcid    = entry.owner.srcid;
+                        xram_rsp_to_cc_send_fifo_inst  = entry.owner.inst;
+                        xram_rsp_to_cc_send_fifo_put   = true;
+                        if(m_xram_rsp_to_cc_send_inst_fifo.wok())
+                        {
+                            r_xram_rsp_next_ptr = entry.next;
+                            if(entry.next == r_xram_rsp_next_ptr.read())   // last copy
+                            {
+                                r_xram_rsp_to_cc_send_multi_req = true;
+                                r_xram_rsp_fsm = XRAM_RSP_HEAP_LAST;
+                            }
+                            else
+                            {
+                                r_xram_rsp_fsm = XRAM_RSP_HEAP_ERASE;
+                            }
+                        }
+                        else
+                        {
+                            r_xram_rsp_fsm = XRAM_RSP_HEAP_ERASE;
+                        }
+
+#if DEBUG_MEMC_XRAM_RSP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " XRAM_RSP_HEAP_ERASE>"
+                                << " Erase copy:"
+                                << " srcid = " << std::hex << entry.owner.srcid
+                                << " entry next  = " << std::hex << entry.next
+                                << " r entry next  = " << std::hex << r_xram_rsp_next_ptr.read()
+                                << " / inst = " << std::dec << entry.owner.inst << std::endl;
+#endif
+                    }
+                    break;
+                }
+                /////////////////////////
+            case XRAM_RSP_HEAP_LAST:  // last copy
+                {
+                    if(r_alloc_heap_fsm.read() != ALLOC_HEAP_XRAM_RSP)
+                    {
+                        std::cout << "VCI_MEM_CACHE ERROR " << name() << " XRAM_RSP_HEAP_LAST"
+                            << " bad HEAP allocation" << std::endl;
+                        exit(0);
+                    }
+                    size_t free_pointer = m_heap.next_free_ptr();
+
+                    HeapEntry last_entry;
+                    last_entry.owner.srcid    = 0;
+                    last_entry.owner.inst     = false;
+                    if(m_heap.is_full())
+                    {
+                        last_entry.next     = r_xram_rsp_next_ptr.read();
+                        m_heap.unset_full();
+                    }
+                    else
+                    {
+                        last_entry.next     = free_pointer;
+                    }
+
+                    m_heap.write_free_ptr(r_xram_rsp_victim_ptr.read());
+                    m_heap.write(r_xram_rsp_next_ptr.read(),last_entry);
+
+                    r_xram_rsp_fsm = XRAM_RSP_IDLE;
+
+#if DEBUG_MEMC_XRAM_RSP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " XRAM_RSP_HEAP_LAST>"
+                            << " Heap housekeeping" << std::endl;
+#endif
+                    break;
+                }
+                /////////////////////////
+            case XRAM_RSP_ERROR_ERASE:  // erase TRT entry in case of error
+                {
+                    m_trt.erase(r_xram_rsp_trt_index.read());
+
+                    // Next state
+                    if(r_xram_rsp_trt_buf.proc_read) r_xram_rsp_fsm = XRAM_RSP_ERROR_RSP;
+                    else                             r_xram_rsp_fsm = XRAM_RSP_IDLE;
+
+#if DEBUG_MEMC_XRAM_RSP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " XRAM_RSP_ERROR_ERASE>"
+                            << " Error reported by XRAM / erase the TRT entry" << std::endl;
+#endif
+                    break;
+                }
+                ////////////////////////
+            case XRAM_RSP_ERROR_RSP:     // Request an error response to TGT_RSP FSM
+                {
+                    if(!r_xram_rsp_to_tgt_rsp_req.read())
+                    {
+                        r_xram_rsp_to_tgt_rsp_srcid  = r_xram_rsp_trt_buf.srcid;
+                        r_xram_rsp_to_tgt_rsp_trdid  = r_xram_rsp_trt_buf.trdid;
+                        r_xram_rsp_to_tgt_rsp_pktid  = r_xram_rsp_trt_buf.pktid;
+                        for(size_t i=0; i < m_words; i++)
+                        {
+                            r_xram_rsp_to_tgt_rsp_data[i] = r_xram_rsp_trt_buf.wdata[i];
+                        }
+                        r_xram_rsp_to_tgt_rsp_word   = r_xram_rsp_trt_buf.word_index;
+                        r_xram_rsp_to_tgt_rsp_length = r_xram_rsp_trt_buf.read_length;
+                        r_xram_rsp_to_tgt_rsp_rerror = true;
+                        r_xram_rsp_to_tgt_rsp_req    = true;
+
+                        r_xram_rsp_fsm = XRAM_RSP_IDLE;
+
+#if DEBUG_MEMC_XRAM_RSP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name()
+                                << " XRAM_RSP_ERROR_RSP> Request a response error to TGT_RSP FSM:"
+                                << " srcid = " << std::dec << r_xram_rsp_trt_buf.srcid << std::endl;
+#endif
+                    }
+                    break;
+                }
+        } // end swich r_xram_rsp_fsm
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    CLEANUP FSM
+        ////////////////////////////////////////////////////////////////////////////////////
+        // The CLEANUP FSM handles the cleanup request from L1 caches.
+        // It accesses the cache directory and the heap to update the list of copies.
+        ////////////////////////////////////////////////////////////////////////////////////
+
+        switch(r_cleanup_fsm.read())
+        {
+            //////////////////
+            case CLEANUP_IDLE:     // Get first DSPIN flit of the CLEANUP command
+                {
+                    if(not m_cc_receive_to_cleanup_fifo.rok()) break;
+
+                    uint64_t flit = m_cc_receive_to_cleanup_fifo.read();
+
+                    uint32_t srcid =
+                        DspinDhccpParam::dspin_get(
+                                flit,
+                                DspinDhccpParam::CLEANUP_SRCID);
+
+                    uint8_t type =
+                        DspinDhccpParam::dspin_get(
+                                flit,
+                                DspinDhccpParam::P2M_TYPE);
+
+                    r_cleanup_way_index =
+                        DspinDhccpParam::dspin_get(
+                                flit,
+                                DspinDhccpParam::CLEANUP_WAY_INDEX);
+
+                    r_cleanup_nline =
+                        DspinDhccpParam::dspin_get(
+                                flit,
+                                DspinDhccpParam::CLEANUP_NLINE_MSB) << 32;
+
+                    r_cleanup_inst  = (type == DspinDhccpParam::TYPE_CLEANUP_INST);
+                    r_cleanup_srcid = srcid;
+                    r_cleanup_ncc = 
+                        DspinDhccpParam::dspin_get(
+                                flit,
+                                DspinDhccpParam::DATA_NO_SHARED);
+
+                    assert( (srcid < m_initiators) and
+                            "MEMC ERROR in CLEANUP_IDLE state : illegal SRCID value");
+
+                    // <Activity Counters>
+                    if (is_local_req(srcid)) {
+                        m_cpt_cleanup_local++;
+                    }
+                    else {
+                        m_cpt_cleanup_remote++;
+                        m_cpt_cleanup_cost += req_distance(srcid);
+                    }
+                    // </Activity Counters>
+                    cc_receive_to_cleanup_fifo_get = true;
+                    r_cleanup_fsm                  = CLEANUP_GET_NLINE;
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                    {
+                        std::cout
+                            << "  <MEMC "         << name()
+                            << " CLEANUP_IDLE> Cleanup request:" << std::hex
+                            << " / owner_id = "   << srcid
+                            << " / owner_ins = "  << (type == DspinDhccpParam::TYPE_CLEANUP_INST)
+                            << " / ncc = " << DspinDhccpParam::dspin_get(
+                                    flit,
+                                    DspinDhccpParam::DATA_NO_SHARED)
+                            << std::endl;
+                    }
+#endif
+                    break;
+                }
+
+                ///////////////////////
+            case CLEANUP_GET_NLINE:  // GET second DSPIN flit of the cleanup command
+                {
+                    if(not m_cc_receive_to_cleanup_fifo.rok()) break;
+
+                    uint64_t flit = m_cc_receive_to_cleanup_fifo.read();
+
+                    addr_t nline = r_cleanup_nline.read() |
+                        DspinDhccpParam::dspin_get(flit, DspinDhccpParam::CLEANUP_NLINE_LSB);
+
+                    //A MODIFIER POUR DIRTY //
+                    bool eop =
+                        DspinDhccpParam::dspin_get(flit, DspinDhccpParam::P2M_EOP) == 0x1;
+                    if (! eop)
+                    {
+                        r_cleanup_fsm           = CLEANUP_GET_DATA;
+                        r_cleanup_data_index    = 0;
+                        r_cleanup_contains_data = true;
+                    }
+                    else
+                    {
+                       /*// if( (r_write_to_cleanup_req.read() == true) and (r_write_to_cleanup_nline.read() == nline ))
+                        {
+                            std::cout << "receive write nline without data" << std::hex << nline << std::endl;
+
+                        }*/
+                        r_cleanup_contains_data = false;
+                        r_cleanup_fsm = CLEANUP_DIR_REQ;
+                    }
+                    cc_receive_to_cleanup_fifo_get = true;
+                    r_cleanup_nline                = nline;
+                    
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                    {
+                        std::cout
+                            << "  <MEMC "         << name()
+                            << " CLEANUP_GET_NLINE> Cleanup request:"
+                            << std::hex
+                            << " / address = "    << nline * m_words * 4
+                            << " / contains data = " << (!eop)
+                            << std::endl;
+                    }
+#endif
+                    break;
+                }
+                /////////////////////
+            case CLEANUP_GET_DATA :
+                {
+                    if (m_cc_receive_to_cleanup_fifo.rok())
+                    {
+                        uint64_t flit = m_cc_receive_to_cleanup_fifo.read();
+
+                        uint32_t data = 
+                            DspinDhccpParam::dspin_get (flit, DspinDhccpParam::CLEANUP_DATA_UPDT);
+
+                        if( (r_write_to_cleanup_req.read() == true) and (r_write_to_cleanup_nline.read() == r_cleanup_nline.read()) )
+                        {
+                            data_t mask = 0;
+                            if(r_write_to_cleanup_be[r_cleanup_data_index.read()].read() & 0x1) mask = mask | 0x000000FF;
+                            if(r_write_to_cleanup_be[r_cleanup_data_index.read()].read() & 0x2) mask = mask | 0x0000FF00;
+                            if(r_write_to_cleanup_be[r_cleanup_data_index.read()].read() & 0x4) mask = mask | 0x00FF0000;
+                            if(r_write_to_cleanup_be[r_cleanup_data_index.read()].read() & 0x8) mask = mask | 0xFF000000;
+        
+                            // complete only if mask is not null (for energy consumption)
+                            r_cleanup_data[r_cleanup_data_index.read()] =
+                                (r_write_to_cleanup_data[r_cleanup_data_index.read()].read() & mask) |
+                                (data & ~mask);
+
+                            int data_out =  (r_write_to_cleanup_data[r_cleanup_data_index.read()].read() & mask) |
+                                (data & ~mask);
+
+                          /*//  std::cout << "receive write nline " << std::hex << r_cleanup_nline.read() 
+                                      << "word " << r_cleanup_data_index.read()
+                                      << "data " 
+                                      << data_out  << std::endl;*/
+
+                        }
+                        else
+                        {
+                            r_cleanup_data[r_cleanup_data_index] = data;
+                        }
+
+                        r_cleanup_data_index = r_cleanup_data_index.read() + 1;
+                        assert (r_cleanup_data_index.read() < m_words and "MEM_CACHE in CLEANUP_GET_DATA : too much flits in cleanup data updt");
+                        cc_receive_to_cleanup_fifo_get = true;
+                        if (r_cleanup_data_index.read() == m_words - 1)
+                        {
+                            m_cpt_cleanup_data ++;
+                            r_cleanup_fsm = CLEANUP_DIR_REQ;
+                        }
+#if DEBUG_MEMC_CLEANUP
+                        if(m_debug)
+                        {
+                            std::cout
+                                << "  <MEMC "         << name()
+                                << " CLEANUP_GET_DATA> "
+                                << " / word = "    << std::dec << r_cleanup_data_index.read()
+                                << " / data = " << std::hex << data
+                                << std::endl;
+                        }
+#endif
+                    }
+                    break;
+                }
+                /////////////////////
+            case CLEANUP_DIR_REQ:   // Get the lock to the directory
+                {
+                    m_cpt_cleanup_fsm_dir_lock++;
+                    if(r_alloc_dir_fsm.read() != ALLOC_DIR_CLEANUP) break;
+
+                    r_cleanup_fsm = CLEANUP_DIR_LOCK;
+                    //std::cout << " MEM_CACHE : CLEANUP_DIR_REQ" << std::endl;
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CLEANUP_DIR_REQ> Requesting DIR lock" << std::endl;
+#endif
+
+                    m_cpt_cleanup_fsm_n_dir_lock++;
+
+                    break;
+                }
+
+                //////////////////////
+            case CLEANUP_DIR_LOCK:
+                {
+                    // test directory status
+                    if(r_alloc_dir_fsm.read() != ALLOC_DIR_CLEANUP)
+                    {
+                        std::cout
+                            << "VCI_MEM_CACHE ERROR " << name()
+                            << " CLEANUP_DIR_LOCK state"
+                            << " bad DIR allocation" << std::endl;
+
+                        exit(0);
+                    }
+                    //std::cout << " MEM_CACHE : CLEANUP_DIR_LOCK" << std::endl;
+
+                    // Read the directory
+                    size_t way = 0;
+                    addr_t cleanup_address = r_cleanup_nline.read() * m_words * 4;
+
+                    DirectoryEntry entry   = m_cache_directory.read(cleanup_address , way);
+                    r_cleanup_is_cnt       = entry.is_cnt;
+                    r_cleanup_dirty        = entry.dirty;
+                    r_cleanup_tag          = entry.tag;
+                    r_cleanup_lock         = entry.lock;
+                    r_cleanup_way          = way;
+                    r_cleanup_count        = entry.count;
+                    r_cleanup_ptr          = entry.ptr;
+                    r_cleanup_copy         = entry.owner.srcid;
+                    r_cleanup_copy_inst    = entry.owner.inst;
+                    r_cleanup_state        = entry.state;
+
+                    //size_t set = m_y[(addr_t)(cleanup_address)];
+                    //m_cache_data.read_line(way, set, r_cleanup_old_data); 
+
+                    if(entry.state == ENTRY_LOCKED)      
+                    {
+                        assert(
+                                (entry.count > 0) and
+                                "VCI MEM CACHE ERROR: "
+                                "In CLEANUP_DIR_LOCK, CLEANUP command on a valid entry "
+                                "with no copies");
+
+                        r_cleanup_fsm = CLEANUP_LOCKED_IVT_LOCK;
+                    }
+                    else if(entry.state == ENTRY_INVALID)
+                    {
+                        r_cleanup_fsm = CLEANUP_MISS_IVT_LOCK;
+                    }
+                    else
+                    {
+                        assert(
+                                (entry.count > 0) and
+                                "VCI MEM CACHE ERROR: "
+                                "In CLEANUP_DIR_LOCK, CLEANUP command on a valid entry "
+                                "with no copies");
+                        if((entry.state == ENTRY_SHARED) and (entry.is_cnt == true))
+                        {
+                            r_cleanup_fsm = CLEANUP_DIR_WRITE;
+                        }
+                        else if((entry.state == ENTRY_EXCLUSIVE) or (entry.count == 1))
+                        {
+                            r_cleanup_fsm = CLEANUP_DIR_WRITE;
+                        }
+                        else 
+                        {
+                            r_cleanup_fsm = CLEANUP_HEAP_REQ;
+                        }
+                    }                    
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                    {
+                        std::cout
+                            << "  <MEMC " << name()
+                            << " CLEANUP_DIR_LOCK> Test directory status: "
+                            << std::hex
+                            << " line = "         << cleanup_address
+                            << " / hit = "        << entry.state
+                            << " / way = "        << way
+                            << " / dir_id = "     << entry.owner.srcid
+                            << " / dir_ins = "    << entry.owner.inst
+                            << " / search_id = "  << r_cleanup_srcid.read()
+                            << " / search_ins = " << r_cleanup_inst.read()
+                            << " / count = "      << entry.count
+                            << " / is_cnt = "     << entry.is_cnt
+                            << std::endl;
+                    }
+#endif
+                    break;
+                }
+
+                ///////////////////////
+            case CLEANUP_DIR_WRITE:
+                {
+                    // Update the directory entry without heap access
+                    if(r_alloc_dir_fsm.read() != ALLOC_DIR_CLEANUP)
+                    {
+                        std::cout
+                            << "VCI_MEM_CACHE ERROR " << name()
+                            << " CLEANUP_DIR_WRITE state"
+                            << " bad DIR allocation" << std::endl;
+
+                        exit(0);
+                    }
+
+                    size_t way         = r_cleanup_way.read();
+                    size_t set         = m_y[(addr_t)(r_cleanup_nline.read()*m_words*4)];
+                    bool   match_srcid = (r_cleanup_copy.read() == r_cleanup_srcid.read());
+
+                    bool   match_inst  = (r_cleanup_copy_inst.read() == r_cleanup_inst.read());
+                    bool   match       = match_srcid and match_inst;
+
+                    if( (r_cleanup_state.read() == ENTRY_EXCLUSIVE) and not match )
+                    {
+                        std::cout
+                            << "VCI_MEM_CACHE ERROR : Cleanup request on a valid"
+                            << "entry using linked list mode with no corresponding"
+                            << "directory or heap entry"
+                            << std::endl;
+
+                        exit(1);
+                    }
+
+                    // update the cache directory (for the copies)
+                    DirectoryEntry entry;
+                    entry.dirty          = r_cleanup_dirty.read() or r_cleanup_contains_data.read();
+                    entry.tag            = r_cleanup_tag.read();
+                    entry.lock           = r_cleanup_lock.read();
+                    entry.ptr            = r_cleanup_ptr.read();
+                    entry.count          = r_cleanup_count.read() - 1;
+                    entry.owner.srcid    = 0;
+                    entry.owner.inst     = 0;
+                    entry.state          = r_cleanup_state.read();
+
+                    if( entry.count == 0) 
+                    {
+                        //entry.state     = ENTRY_EXCLUSIVE;
+                        entry.is_cnt    = 0;
+                    }
+                    else
+                    {
+                        //entry.state     = ENTRY_SHARED;
+                        entry.is_cnt    = r_cleanup_is_cnt.read();
+                    }
+
+                    if (r_cleanup_contains_data.read())
+                    {
+                        for (size_t word = 0; word < m_words; word ++)
+                        {
+                            m_cache_data.write(way, set, word, r_cleanup_data[word].read(), 0xF);
+                        }
+                        addr_t min = r_cleanup_nline.read()*m_words*4 ;
+                        addr_t max = r_cleanup_nline.read()*m_words*4 + (m_words - 1)*4;
+                        m_llsc_table.sw(min, max);
+                    }
+
+                    m_cache_directory.write(set, way, entry);
+                    r_cleanup_fsm = CLEANUP_SEND_CLACK;
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                    {
+                        std::cout
+                            << "  <MEMC " << name()
+                            << " CLEANUP_DIR_WRITE> Update directory:"
+                            << std::hex
+                            << " address = "   << r_cleanup_nline.read() * m_words * 4
+                            << " / dir_id = "  << entry.owner.srcid
+                            << " / dir_ins = " << entry.owner.inst
+                            << " / state = "   << entry.state
+                            << " / count = "   << entry.count
+                            << " / is_cnt = "  << entry.is_cnt
+                            << std::endl;
+                    }
+#endif
+
+                    break;
+                }
+                /////////////////////
+            case CLEANUP_LOCKED_IVT_LOCK:
+                {
+                    //Search for a matching inval in the ivt (there must be one) and check if there is a pending read or cas.
+                    if(r_alloc_ivt_fsm.read() == ALLOC_IVT_CLEANUP)
+                    {
+                        size_t index = 0;
+                        bool   match_inval;
+
+                        match_inval = m_ivt.search_inval(r_cleanup_nline.read(), index);
+#if DEBUG_MEMC_CLEANUP
+                    if (m_debug)
+                    {
+                        std::cout
+                            << " <MEMC " << name()
+                            << " CLEANUP_LOCKED_IVT_LOCK> :"
+                            << "/ is_updt =" << m_ivt.is_update(index)
+                            << "/ match =" << match_inval
+                            << "/ need rsp  =" << m_ivt.need_rsp(index)
+                            << std::endl;
+                    }
+#endif
+
+                        r_cleanup_locked_srcid    = m_ivt.srcid(index);
+                        r_cleanup_locked_trdid    = m_ivt.trdid(index);
+                        r_cleanup_locked_pktid    = m_ivt.pktid(index);
+                        r_cleanup_locked_index    = index;
+                        r_cleanup_locked_is_updt  = m_ivt.is_update(index);
+
+                        if( not m_ivt.is_update(index))
+                        {
+                           r_cleanup_fsm = CLEANUP_LOCKED_IVT_DECREMENT;
+                        }
+                        else
+                        {
+                            r_cleanup_fsm = CLEANUP_LOCKED_IVT_CLEAR;
+                        }
+
+                        assert (match_inval && m_ivt.need_rsp(index) && "VCI MEM CACHE ERROR: In CLEANUP_LOCKED_IVT_LOCK, NO CORRESPONDING INVAL");
+                    }
+
+                    break;
+                }
+                ////////////////////////
+            case CLEANUP_LOCKED_IVT_DECREMENT: // decrement response counter in IVT matching entry
+                {
+                    assert( (r_alloc_ivt_fsm.read() == ALLOC_IVT_CLEANUP) and
+                            (r_alloc_dir_fsm.read() == ALLOC_DIR_CLEANUP) and
+                            "MEMC ERROR in CLEANUP_LOCKED_IVT_DECREMENT state: Bad IVT allocation");
+
+                    size_t count = 0;
+
+                    m_ivt.decrement(r_cleanup_locked_index.read(), count);
+
+                    if(count == 0)
+                    {
+                        r_cleanup_fsm = CLEANUP_LOCKED_IVT_CLEAR;
+                    }
+                    else  // don't need to mofidy dir,it is not finished.
+                    {
+                        r_cleanup_fsm = CLEANUP_SEND_CLACK;
+                        assert( not r_cleanup_contains_data.read() && " received the shared line with contain data ");
+                    }
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CLEANUP_LOCKED_IVT_DECREMENT>"
+                            << " Decrement response counter in IVT:"
+                            << " IVT_index = " << r_cleanup_locked_index.read()
+                            << " / rsp_count = " << count << std::endl;
+#endif
+                    break;
+                }
+ 
+                //////////////////////////
+            case CLEANUP_LOCKED_IVT_CLEAR:
+                {
+                    assert( (r_alloc_ivt_fsm.read() == ALLOC_IVT_CLEANUP) and
+                            (r_alloc_dir_fsm.read() == ALLOC_DIR_CLEANUP) and
+                            "MEMC ERROR in CLEANUP_LOCKED_IVT_CLEAR state: Bad IVT allocation");
+
+                    size_t set          = m_y[(addr_t)(r_cleanup_nline.read()*m_words*4)];
+                    size_t way          = r_cleanup_way.read();
+
+                    addr_t cleanup_address = r_cleanup_nline.read() * m_words * 4;
+                    size_t match_cas_multi_inval = r_cas_to_cleanup_req.read() and
+                                                  (r_cas_to_cleanup_nline.read() == r_cleanup_nline.read()); 
+                    DirectoryEntry  entry;
+                    entry.is_cnt        = false;
+                    entry.lock          = r_cleanup_lock.read();
+                    entry.dirty         = r_cleanup_dirty.read();
+                    entry.tag           = r_cleanup_tag.read();
+                    entry.ptr           = r_cleanup_ptr.read();
+                   
+                    if( not r_cleanup_contains_data.read() ) 
+                    {
+                        size_t set = m_y[(addr_t)(cleanup_address)];
+                        m_cache_data.read_line(way, set, r_cleanup_data); 
+                    }
+                    else
+                    {
+                        for (size_t word = 0; word < m_words; word ++)
+                        {
+                            m_cache_data.write(way, set, word, r_cleanup_data[word].read(), 0xF);
+                        }
+                        addr_t min = r_cleanup_nline.read()*m_words*4 ;
+                        addr_t max = r_cleanup_nline.read()*m_words*4 + (m_words - 1)*4;
+                        m_llsc_table.sw(min, max);
+                    }
+
+                    if(r_cleanup_locked_is_updt.read()) //cleanup req cross with multi ack rsp. here, just decrements the count and remains the state.
+                    {
+                        entry.state         = r_cleanup_state.read();  //cross with cc updt cmd, don't modify the state
+                        entry.count         = 0;
+                        entry.owner.srcid   = 0;
+                        entry.owner.inst    = 0;
+                        r_cleanup_fsm       = CLEANUP_SEND_CLACK;
+                    }
+                    else // cas, getm, one copy updated in dir
+                    {
+                        if(match_cas_multi_inval)
+                        {
+                            entry.state     = ENTRY_SHARED;
+                            entry.count     = 0;
+                        }
+                        else
+                        {
+                            entry.state     = ENTRY_EXCLUSIVE;
+                            entry.count     = 1;
+                        }
+                        entry.owner.srcid   = r_cleanup_locked_srcid.read();
+                        entry.owner.inst    = 0;
+                        r_cleanup_fsm       = CLEANUP_LOCKED_RSP;
+                        m_ivt.clear(r_cleanup_locked_index.read());
+                    }
+    
+                    m_cache_directory.write(set, r_cleanup_way.read(), entry);
+ 
+#if DEBUG_MEMC_CLEANUP
+                    if (m_debug)
+                    {
+                        std::cout
+                            << " <MEMC " << name()
+                            << " CLEANUP_LOCKED_IVT_CLEAR> clear UPT entry"
+                            << " contain data = " << r_cleanup_contains_data.read()
+                            << " updt dir count =" << entry.count
+                            << std::endl;
+                    }
+#endif
+                    break;
+                }
+
+                ////////////////////////
+            case CLEANUP_LOCKED_RSP:
+                {
+                    if(r_cleanup_to_tgt_rsp_req.read()) break;
+
+                    r_cleanup_to_tgt_rsp_req     = true;
+                    r_cleanup_to_tgt_rsp_srcid   = r_cleanup_locked_srcid.read();
+                    r_cleanup_to_tgt_rsp_trdid   = r_cleanup_locked_trdid.read();
+                    
+                    r_cleanup_to_tgt_rsp_pktid   = 0x8 + r_cleanup_locked_pktid.read(); // there is not a brdcast for cas operation. in cache L1, the line can be in M state
+                    
+                    if(r_read_to_cleanup_req.read() and (r_read_to_cleanup_nline.read() == r_cleanup_nline.read())) // rsp for LL or pheriph
+                    {
+                        r_cleanup_to_tgt_rsp_ll_key     = r_read_to_cleanup_ll_key.read(); 
+                        r_cleanup_to_tgt_rsp_length     = r_read_to_cleanup_length.read();
+                        r_cleanup_to_tgt_rsp_first_word = r_read_to_cleanup_first_word.read();
+                        r_read_to_cleanup_req           = false;
+                    }                        
+                    else
+                    {
+                        r_cleanup_to_tgt_rsp_ll_key     = 0;
+                        r_cleanup_to_tgt_rsp_length     = 16;
+                        r_cleanup_to_tgt_rsp_first_word = 0;
+                    }
+
+                    if(r_cas_to_cleanup_req.read())
+                    {
+                        r_cas_to_cleanup_req        = false;
+                        r_cleanup_to_tgt_rsp_type   = true;
+                    }
+                    else
+                    {
+                        r_cleanup_to_tgt_rsp_type   = false;
+                    }
+
+                    for(size_t i = 0; i<m_words; i++)
+                    {
+                        r_cleanup_to_tgt_rsp_data[i] = r_cleanup_data[i].read();
+                    }
+
+                    r_cleanup_fsm                = CLEANUP_SEND_CLACK;
+
+#if DEBUG_MEMC_CLEANUP
+                    if (m_debug)
+                    {
+                        std::cout
+                            << " <MEMC " << name()
+                            << " CLEANUP_LOCKED_RSP>"
+                            << "type rsp =" << r_cleanup_locked_pktid.read()
+                            << "r_read_to_cleanup_req  =" << r_read_to_cleanup_req.read()
+                            << "r_read_to_cleanup_length  =" << r_read_to_cleanup_length.read()
+                            << "r_read_to_cleanup_first_word  =" << r_read_to_cleanup_first_word.read()
+                            << std::endl;
+                    }
+#endif
+                    break;
+                }
+                //////////////////////
+            case CLEANUP_HEAP_REQ:
+                {
+                    // get the lock to the HEAP directory
+                    if(r_alloc_heap_fsm.read() != ALLOC_HEAP_CLEANUP) break;
+
+                    r_cleanup_fsm = CLEANUP_HEAP_LOCK;
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                    {
+                        std::cout
+                            << "  <MEMC " << name()
+                            << " CLEANUP_HEAP_REQ> HEAP lock acquired "
+                            << std::endl;
+                    }
+#endif
+                    m_cpt_cleanup_fsm_n_heap_lock++;
+                    break;
+                }
+
+                //////////////////////
+            case CLEANUP_HEAP_LOCK:
+                {
+                    // two cases are handled in this state :
+                    // 1. the matching copy is directly in the directory
+                    // 2. the matching copy is the first copy in the heap
+                    assert( (r_alloc_heap_fsm.read() == ALLOC_HEAP_CLEANUP) and
+                            "MEMC ERROR in CLEANUP_HEAP_LOCK state: bad HEAP allocation");
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_CLEANUP) and
+                            "MEMC ERROR in CLEANUP_HEAP_LOCK state: bad DIR allocation");
+                    size_t way            = r_cleanup_way.read();
+                    size_t set            = m_y[(addr_t)(r_cleanup_nline.read() *m_words*4)];
+
+                    HeapEntry heap_entry  = m_heap.read(r_cleanup_ptr.read());
+                    bool last             = (heap_entry.next == r_cleanup_ptr.read());
+
+                    // match_dir computation
+                    bool match_dir_srcid  = (r_cleanup_copy.read()      == r_cleanup_srcid.read());
+                    bool match_dir_inst   = (r_cleanup_copy_inst.read() == r_cleanup_inst.read());
+                    bool match_dir        = match_dir_srcid  and match_dir_inst;
+
+                    // match_heap computation
+                    bool match_heap_srcid = (heap_entry.owner.srcid == r_cleanup_srcid.read());
+                    bool match_heap_inst  = (heap_entry.owner.inst  == r_cleanup_inst.read());
+                    bool match_heap       = match_heap_srcid and match_heap_inst;
+
+                    r_cleanup_prev_ptr    = r_cleanup_ptr.read();
+                    r_cleanup_prev_srcid  = heap_entry.owner.srcid;
+                    r_cleanup_prev_inst   = heap_entry.owner.inst;
+
+                    assert( (not last or match_dir or match_heap) and
+                            "MEMC ERROR in CLEANUP_HEAP_LOCK state: hit but no copy found");
+
+                    assert( (not match_dir or not match_heap) and
+                            "MEMC ERROR in CLEANUP_HEAP_LOCK state: two matching copies found");
+
+                    DirectoryEntry dir_entry;
+                    dir_entry.state          = r_cleanup_state.read();
+                    dir_entry.is_cnt         = r_cleanup_is_cnt.read();
+                    dir_entry.dirty          = r_cleanup_dirty.read();
+                    dir_entry.tag            = r_cleanup_tag.read();
+                    dir_entry.lock           = r_cleanup_lock.read();
+                    dir_entry.count          = r_cleanup_count.read()-1;
+
+                    // the matching copy is registered in the directory and
+                    // it must be replaced by the first copy registered in
+                    // the heap. The corresponding entry must be freed
+                    if(match_dir)
+                    {
+                        dir_entry.ptr            = heap_entry.next;
+                        dir_entry.owner.srcid    = heap_entry.owner.srcid;
+                        dir_entry.owner.inst     = heap_entry.owner.inst;
+                        r_cleanup_next_ptr       = r_cleanup_ptr.read();
+                        r_cleanup_fsm            = CLEANUP_HEAP_FREE;
+                    }
+
+                    // the matching copy is the first copy in the heap
+                    // It must be freed and the copy registered in directory
+                    // must point to the next copy in heap
+                    else if(match_heap)
+                    {
+                        dir_entry.ptr            = heap_entry.next;
+                        dir_entry.owner.srcid    = r_cleanup_copy.read();
+                        dir_entry.owner.inst     = r_cleanup_copy_inst.read();
+                        r_cleanup_next_ptr       = r_cleanup_ptr.read();
+                        r_cleanup_fsm            = CLEANUP_HEAP_FREE;
+                    }
+
+                    // The matching copy is in the heap, but is not the first copy
+                    // The directory entry must be modified to decrement count
+                    else
+                    {
+                        dir_entry.ptr            = r_cleanup_ptr.read();
+                        dir_entry.owner.srcid    = r_cleanup_copy.read();
+                        dir_entry.owner.inst     = r_cleanup_copy_inst.read();
+                        r_cleanup_next_ptr       = heap_entry.next;
+                        r_cleanup_fsm            = CLEANUP_HEAP_SEARCH;
+                    }
+
+                    m_cache_directory.write(set,way,dir_entry);
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                    {
+                        std::cout
+                            << "  <MEMC " << name()
+                            << " CLEANUP_HEAP_LOCK> Checks matching:"
+                            << " address = "      << r_cleanup_nline.read() * m_words * 4
+                            << " / dir_id = "     << r_cleanup_copy.read()
+                            << " / dir_ins = "    << r_cleanup_copy_inst.read()
+                            << " / heap_id = "    << heap_entry.owner.srcid
+                            << " / heap_ins = "   << heap_entry.owner.inst
+                            << " / search_id = "  << r_cleanup_srcid.read()
+                            << " / search_ins = " << r_cleanup_inst.read()
+                            << std::endl;
+                    }
+#endif
+                    break;
+                }
+
+                ////////////////////////
+            case CLEANUP_HEAP_SEARCH:
+                {
+                    // This state is handling the case where the copy
+                    // is in the heap, but is not the first in the linked list
+                    assert( (r_alloc_heap_fsm.read() == ALLOC_HEAP_CLEANUP) and
+                            "MEMC ERROR in CLEANUP_HEAP_LOCK state: bad HEAP allocation");
+
+                    HeapEntry heap_entry  = m_heap.read(r_cleanup_next_ptr.read());
+
+                    bool last             = (heap_entry.next        == r_cleanup_next_ptr.read());
+                    bool match_heap_srcid = (heap_entry.owner.srcid == r_cleanup_srcid.read());
+                    bool match_heap_inst  = (heap_entry.owner.inst  == r_cleanup_inst.read());
+                    bool match_heap       = match_heap_srcid and match_heap_inst;
+
+                    assert( (not last or match_heap) and
+                            "MEMC ERROR in CLEANUP_HEAP_SEARCH state: no copy found");
+
+                    // the matching copy must be removed
+                    if(match_heap)
+                    {
+                        // re-use ressources
+                        r_cleanup_ptr = heap_entry.next;
+                        r_cleanup_fsm = CLEANUP_HEAP_CLEAN;
+                    }
+                    // test the next in the linked list
+                    else
+                    {
+                        r_cleanup_prev_ptr      = r_cleanup_next_ptr.read();
+                        r_cleanup_prev_srcid    = heap_entry.owner.srcid;
+                        r_cleanup_prev_inst     = heap_entry.owner.inst;
+                        r_cleanup_next_ptr      = heap_entry.next;
+                        r_cleanup_fsm           = CLEANUP_HEAP_SEARCH;
+                    }
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                    {
+                        if(not match_heap)
+                        {
+                            std::cout
+                                << "  <MEMC " << name()
+                                << " CLEANUP_HEAP_SEARCH> Matching copy not found, search next:"
+                                << std::endl;
+                        }
+                        else
+                        {
+                            std::cout
+                                << "  <MEMC " << name()
+                                << " CLEANUP_HEAP_SEARCH> Matching copy found:"
+                                << std::endl;
+                        }
+
+                        std::cout
+                            << " address = "      << r_cleanup_nline.read() * m_words * 4
+                            << " / heap_id = "    << heap_entry.owner.srcid
+                            << " / heap_ins = "   << heap_entry.owner.inst
+                            << " / search_id = "  << r_cleanup_srcid.read()
+                            << " / search_ins = " << r_cleanup_inst.read()
+                            << " / last = "       << last
+                            << std::endl;
+                    }
+#endif
+                    break;
+                }
+                ////////////////////////
+            case CLEANUP_HEAP_CLEAN:    // remove a copy in the linked list
+                {
+                    assert( (r_alloc_heap_fsm.read() == ALLOC_HEAP_CLEANUP) and
+                            "MEMC ERROR in CLEANUP_HEAP_LOCK state: bad HEAP allocation");
+
+                    HeapEntry heap_entry;
+                    heap_entry.owner.srcid    = r_cleanup_prev_srcid.read();
+                    heap_entry.owner.inst     = r_cleanup_prev_inst.read();
+                    bool last = (r_cleanup_next_ptr.read() == r_cleanup_ptr.read());
+
+                    // this is the last entry of the list of copies
+                    if(last)
+                    {
+                        heap_entry.next = r_cleanup_prev_ptr.read();
+                    }
+                    // this is not the last entry
+                    else
+                    {
+                        heap_entry.next = r_cleanup_ptr.read();
+                    }
+
+                    m_heap.write(r_cleanup_prev_ptr.read(), heap_entry);
+
+                    r_cleanup_fsm = CLEANUP_HEAP_FREE;
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CLEANUP_HEAP_SEARCH>"
+                            << " Remove the copy in the linked list" << std::endl;
+#endif
+                    break;
+                }
+                ///////////////////////
+            case CLEANUP_HEAP_FREE:   // The heap entry pointed by r_cleanup_next_ptr is freed
+                // and becomes the head of the list of free entries
+                {
+                    assert( (r_alloc_heap_fsm.read() == ALLOC_HEAP_CLEANUP) and
+                            "MEMC ERROR in CLEANUP_HEAP_LOCK state: bad HEAP allocation");
+                    HeapEntry heap_entry;
+                    heap_entry.owner.srcid    = 0;
+                    heap_entry.owner.inst     = false;
+
+                    if(m_heap.is_full())
+                    {
+                        heap_entry.next = r_cleanup_next_ptr.read();
+                    }
+                    else
+                    {
+                        heap_entry.next = m_heap.next_free_ptr();
+                    }
+
+                    m_heap.write(r_cleanup_next_ptr.read(),heap_entry);
+                    m_heap.write_free_ptr(r_cleanup_next_ptr.read());
+                    m_heap.unset_full();
+
+                    r_cleanup_fsm = CLEANUP_SEND_CLACK;
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CLEANUP_HEAP_FREE>"
+                            << " Update the list of free entries" << std::endl;
+#endif
+                    break;
+                }
+                //////////////////////
+            case CLEANUP_MISS_IVT_LOCK:   // get the lock protecting the IVT to search a pending
+                // invalidate transaction matching the cleanup 
+                {
+                    m_cpt_cleanup_fsm_ivt_lock++;
+                    if(r_alloc_ivt_fsm.read() != ALLOC_IVT_CLEANUP) break;
+
+                    size_t index = 0;
+                    bool   match_inval;
+
+                    match_inval = m_ivt.search_inval(r_cleanup_nline.read(), index);
+                    if ( not match_inval )     // no pending inval
+                    {
+                        r_cleanup_fsm = CLEANUP_SEND_CLACK;
+
+#if DEBUG_MEMC_CLEANUP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name()
+                                << " CLEANUP_MISS_IVT_LOCK> Unexpected cleanup"
+                                << " with no corresponding IVT entry:"
+                                << " address = " << std::hex
+                                << (r_cleanup_nline.read() *4*m_words)
+                                << std::endl;
+#endif
+                        m_cpt_cleanup_fsm_n_upt_lock++;
+                    }
+                    else
+                    {
+                        // pending inval
+                        r_cleanup_miss_srcid        = m_ivt.srcid(index);
+                        r_cleanup_miss_trdid        = m_ivt.trdid(index);
+                        r_cleanup_miss_pktid        = m_ivt.pktid(index);
+                        r_cleanup_miss_need_rsp     = m_ivt.need_rsp(index);
+                        r_cleanup_miss_need_ack     = m_ivt.need_ack(index);
+                        r_cleanup_miss_index        = index;
+                        r_cleanup_fsm               = CLEANUP_MISS_IVT_DECREMENT;
+#if DEBUG_MEMC_CLEANUP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name()
+                                << " CLEANUP_MISS_IVT_LOCK> Cleanup matching pending"
+                                << " invalidate transaction on IVT:"
+                                << " address = " << std::hex << r_cleanup_nline.read() * m_words * 4
+                                << " / ivt_entry = " << index << std::endl;
+#endif
+                    }
+                    break;
+                }
+                ///////////////////////////
+            case CLEANUP_MISS_IVT_DECREMENT: // decrement response counter in IVT matching entry
+                {
+                    assert( (r_alloc_ivt_fsm.read() == ALLOC_IVT_CLEANUP) and
+                            "MEMC ERROR in CLEANUP_MISS_IVT_DECREMENT state: Bad IVT allocation");
+
+                    size_t count = 0;
+
+                    m_ivt.decrement(r_cleanup_miss_index.read(), count);
+
+                    if(count == 0)   // multi inval transaction completed
+                    {
+                        r_cleanup_fsm = CLEANUP_MISS_IVT_CLEAR;
+                    }
+                    else             // multi inval transaction not completed
+                    {
+                        r_cleanup_fsm = CLEANUP_SEND_CLACK;
+                    }
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CLEANUP_MISS_IVT_DECREMENT>"
+                            << " Decrement response counter in IVT:"
+                            << " IVT_index = " << r_cleanup_miss_index.read()
+                            << " / rsp_count = " << count << std::endl;
+#endif
+                    break;
+                }
+                ///////////////////////
+            case CLEANUP_MISS_IVT_CLEAR:    // Clear IVT entry 
+                {
+                    assert( (r_alloc_ivt_fsm.read() == ALLOC_IVT_CLEANUP) and
+                            "MEMC ERROR in CLEANUP_IVT_CLEAR state : bad IVT allocation");
+
+                    m_ivt.clear(r_cleanup_miss_index.read());
+
+                    if ( r_cleanup_miss_need_ack.read() )
+                    {
+                        assert( (r_config_rsp_lines.read() > 0) and
+                                "MEMC ERROR in CLEANUP_IVT_CLEAR state");
+
+                        config_rsp_lines_cleanup_decr = true;
+                    }
+
+                    if (r_cleanup_miss_need_rsp.read())         
+                    {
+                        r_cleanup_fsm = CLEANUP_MISS_RSP;
+                    }
+                    else if ( r_cleanup_ncc.read() )
+                    {
+                        r_cleanup_fsm = CLEANUP_MISS_IXR_REQ;
+                    }
+                    else
+                    {
+                        r_cleanup_fsm = CLEANUP_SEND_CLACK;
+                    }
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                        std::cout << "  <MEMC "      << name()
+                            << " CLEANUP_MISS_IVT_CLEAR> Clear entry in IVT:"
+                            << " IVT_index = " << r_cleanup_miss_index.read() << std::endl;
+#endif
+                    break;
+                }
+                ///////////////////////
+            case CLEANUP_MISS_RSP:    // response to a previous write on the direct network
+                // wait if pending request to the TGT_RSP FSM
+                {
+                    if(r_cleanup_to_tgt_rsp_req.read()) break;
+
+                    // no pending request
+                    r_cleanup_to_tgt_rsp_req     = true;
+                    r_cleanup_to_tgt_rsp_srcid   = r_cleanup_miss_srcid.read();
+                    r_cleanup_to_tgt_rsp_trdid   = r_cleanup_miss_trdid.read();
+                    r_cleanup_to_tgt_rsp_pktid   = r_cleanup_miss_pktid.read(); // cas rsp: prevents the brdcast invalidate has been done. The L1 don't need to modify the state.
+                    r_cleanup_to_tgt_rsp_type    = true; 
+
+                    if ( r_cleanup_ncc.read() )
+                    {
+                        r_cleanup_fsm = CLEANUP_MISS_IXR_REQ;
+                    }
+                    else
+                    {
+                        r_cleanup_fsm = CLEANUP_SEND_CLACK;
+                    }
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CLEANUP_MISS_RSP>"
+                            << " Send a response to a previous write request: "
+                            << " rsrcid = "   << std::hex << r_cleanup_miss_srcid.read()
+                            << " / rtrdid = " << r_cleanup_miss_trdid.read()
+                            << " / rpktid = " << r_cleanup_miss_pktid.read() << std::endl;
+#endif
+                    break;
+                }
+                /////////////////////////
+            case CLEANUP_MISS_IXR_REQ:
+                {
+                    //Send a request to the ixr to write the data in the XRAM using the prereserved TRT entry
+                    if (r_alloc_trt_fsm.read() == ALLOC_TRT_CLEANUP)
+                    {
+                        if( not r_cleanup_to_ixr_cmd_req.read())
+                        {
+                            size_t index = 0;
+                            bool   hit   = m_trt.hit_write(r_cleanup_nline.read(), &index); 
+
+                            assert (hit and "CLEANUP_MISS_IXR_REQ found no matching entry in TRT");
+
+                            r_cleanup_to_ixr_cmd_req     = true;
+
+                            if( (r_write_to_cleanup_req == true) and (r_write_to_cleanup_nline == r_cleanup_nline.read()) )
+                            {
+                                r_write_to_cleanup_req   = false;
+                            }
+
+                            if (r_cleanup_contains_data.read())
+                            {  
+                                std::vector<data_t> data_vector;
+                                data_vector.clear();
+
+                                for(size_t i=0; i<m_words; i++)
+                                {
+                                    data_vector.push_back(r_cleanup_data[i]);
+                                }
+
+                                m_trt.set(index,
+                                          false,       // write to XRAM
+                                          r_cleanup_nline.read(),  // line index
+                                          0,
+                                          0,
+                                          0,
+                                          false,
+                                          0,
+                                          0,
+                                          std::vector<be_t> (m_words,0),
+                                          data_vector);
+                            }
+                            //std::cout << "cleanup with a non coherent ligne in trt index = " << index << std::endl;
+                            r_cleanup_to_ixr_cmd_srcid        = r_cleanup_srcid.read();
+                            r_cleanup_to_ixr_cmd_index        = index;
+                            r_cleanup_to_ixr_cmd_pktid        = r_cleanup_pktid.read();
+                            r_cleanup_to_ixr_cmd_nline        = r_cleanup_nline.read();
+                            //r_cleanup_to_ixr_cmd_l1_dirty_ncc = r_cleanup_contains_data.read();
+                            r_cleanup_fsm = CLEANUP_SEND_CLACK;
+#if DEBUG_MEMC_CLEANUP
+                            if(m_debug)
+                            {
+                                std::cout
+                                    << "  <MEMC " << name()
+                                    << " CLEANUP_IXR_REQ>"
+                                    << " request send to IXR_CMD"
+                                    << std::endl;
+                            }
+#endif
+                        }
+                        else
+                        {
+                            r_cleanup_fsm = CLEANUP_WAIT;
+#if DEBUG_MEMC_CLEANUP
+                            if(m_debug)
+                            {
+                                std::cout
+                                    << "  <MEMC " << name()
+                                    << " CLEANUP_IXR_REQ>"
+                                    << " waiting completion of previous request"
+                                    << std::endl;
+                            }
+#endif
+                        }
+                    }
+                    break;
+                }
+
+                /////////////////////
+            case CLEANUP_WAIT :
+                {
+                    r_cleanup_fsm = CLEANUP_MISS_IXR_REQ;
+                    break;
+                }
+
+                ////////////////////////
+            case CLEANUP_SEND_CLACK:  // acknowledgement to a cleanup command
+                // on the coherence CLACK network.
+                {
+                    if(not p_dspin_clack.read) break;
+
+                    r_cleanup_fsm = CLEANUP_IDLE;
+
+#if DEBUG_MEMC_CLEANUP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " CLEANUP_SEND_CLACK> Send the response to a cleanup request:"
+                            << " nline = "   << std::hex << r_cleanup_nline.read()
+                            << " / way = "   << std::dec << r_cleanup_way.read()
+                            << " / srcid = " << std::dec << r_cleanup_srcid.read() 
+                            << std::endl;
+#endif
+                    break;
+                }
+        } // end switch cleanup fsm
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    CAS FSM
+        ////////////////////////////////////////////////////////////////////////////////////
+        // The CAS FSM handles the CAS (Store Conditionnal) atomic commands,
+        // that are handled as "compare-and-swap instructions.
+        //
+        // This command contains two or four flits:
+        // - In case of 32 bits atomic access, the first flit contains the value read
+        // by a previous LL instruction, the second flit contains the value to be writen.
+        // - In case of 64 bits atomic access, the 2 first flits contains the value read
+        // by a previous LL instruction, the 2 next flits contains the value to be writen.
+        //
+        // The target address is cachable. If it is replicated in other L1 caches
+        // than the writer, a coherence operation is done.
+        //
+        // It access the directory to check hit / miss.
+        // - In case of miss, the CAS FSM must register a GET transaction in TRT.
+        // If a read transaction to the XRAM for this line already exists,
+        // or if the transaction table is full, it goes to the WAIT state
+        // to release the locks and try again. When the GET transaction has been
+        // launched, it goes to the WAIT state and try again.
+        // The CAS request is not consumed in the FIFO until a HIT is obtained.
+        // - In case of hit...
+        ///////////////////////////////////////////////////////////////////////////////////
+
+        switch(r_cas_fsm.read())
+        {
+            /////////////
+            case CAS_IDLE:     // fill the local rdata buffers
+                {
+                    if(m_cmd_cas_addr_fifo.rok())
+                    {
+
+#if DEBUG_MEMC_CAS
+                        if(m_debug)
+                        {
+                            std::cout << "  <MEMC " << name() << " CAS_IDLE> CAS command: " << std::hex
+                                << " srcid = " <<  std::dec << m_cmd_cas_srcid_fifo.read()
+                                << " addr = " << std::hex << m_cmd_cas_addr_fifo.read()
+                                << " wdata = " << m_cmd_cas_wdata_fifo.read()
+                                << " eop = " << std::dec << m_cmd_cas_eop_fifo.read()
+                                << " cpt  = " << std::dec << r_cas_cpt.read() << std::endl;
+                        }
+#endif
+                        if(m_cmd_cas_eop_fifo.read())
+                        {
+                            r_cas_fsm = CAS_DIR_REQ;
+                        }
+                        else  // we keep the last word in the FIFO
+                        {
+                            cmd_cas_fifo_get = true;
+                        }
+                        // We fill the two buffers
+                        if(r_cas_cpt.read() < 2)    // 32 bits access
+                            r_cas_rdata[r_cas_cpt.read()] = m_cmd_cas_wdata_fifo.read();
+
+                        if((r_cas_cpt.read() == 1) and m_cmd_cas_eop_fifo.read())
+                            r_cas_wdata = m_cmd_cas_wdata_fifo.read();
+
+                        assert( (r_cas_cpt.read() <= 3) and  // no more than 4 flits...
+                                "MEMC ERROR in CAS_IDLE state: illegal CAS command");
+
+                        if(r_cas_cpt.read() ==2)
+                            r_cas_wdata = m_cmd_cas_wdata_fifo.read();
+
+                        r_cas_cpt = r_cas_cpt.read() +1;
+                    }
+                    break;
+                }
+
+                /////////////////
+            case CAS_DIR_REQ:
+                {
+                    if(r_alloc_dir_fsm.read() == ALLOC_DIR_CAS)
+                    {
+                        r_cas_fsm = CAS_DIR_LOCK;
+                        m_cpt_cas_fsm_n_dir_lock++;
+                    }
+
+#if DEBUG_MEMC_CAS
+                    if(m_debug)
+                    {
+                        std::cout
+                            << "  <MEMC " << name() << " CAS_DIR_REQ> Requesting DIR lock "
+                            << std::endl;
+                    }
+#endif
+
+                    m_cpt_cas_fsm_dir_lock++;
+
+                    break;
+                }
+
+                /////////////////
+            case CAS_DIR_LOCK:  // Read the directory
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_CAS) and
+                            "MEMC ERROR in CAS_DIR_LOCK: Bad DIR allocation");
+
+                    size_t way = 0;
+                    DirectoryEntry entry(m_cache_directory.read(m_cmd_cas_addr_fifo.read(), way));
+
+                    r_cas_is_cnt     = entry.is_cnt;
+                    r_cas_state      = entry.state;
+                    r_cas_dirty      = entry.dirty;
+                    r_cas_tag        = entry.tag;
+                    r_cas_way        = way;
+                    r_cas_copy       = entry.owner.srcid;
+                    r_cas_copy_inst  = entry.owner.inst;
+                    r_cas_ptr        = entry.ptr;
+                    r_cas_count      = entry.count;
+                    
+                    if(entry.state == ENTRY_LOCKED)  r_cas_fsm = CAS_WAIT;
+                    else if(entry.state == ENTRY_INVALID)  r_cas_fsm = CAS_MISS_TRT_LOCK;
+                    else  r_cas_fsm = CAS_DIR_HIT_READ;
+
+#if DEBUG_MEMC_CAS
+                    if(m_debug)
+                    {
+                        std::cout << "  <MEMC " << name() << " CAS_DIR_LOCK> Directory acces"
+                            << " / address = " << std::hex << m_cmd_cas_addr_fifo.read()
+                            << " / hit = " << std::dec << entry.state
+                            << " / count = " << entry.count
+                            << " / is_cnt = " << entry.is_cnt << std::endl;
+                    }
+#endif
+                    break;
+                }
+                /////////////////////
+            case CAS_DIR_HIT_READ:  // update directory for lock and dirty bit
+                // and check data change in cache
+                {
+                    size_t way  = r_cas_way.read();
+                    size_t set  = m_y[(addr_t)(m_cmd_cas_addr_fifo.read())];
+
+                    // update directory (lock & dirty bits)
+                    DirectoryEntry entry;
+                    entry.state          = r_cas_state.read();
+                    entry.is_cnt         = r_cas_is_cnt.read();
+                    entry.dirty          = true;
+                    entry.lock           = true;
+                    entry.tag            = r_cas_tag.read();
+                    entry.owner.srcid    = r_cas_copy.read();
+                    entry.owner.inst     = r_cas_copy_inst.read();
+                    entry.count          = r_cas_count.read();
+                    entry.ptr            = r_cas_ptr.read();
+
+                    m_cache_directory.write(set, way, entry);
+
+                    // Stored data from cache in buffer to do the comparison in next state
+                    m_cache_data.read_line(way, set, r_cas_data);
+
+                    r_cas_fsm = CAS_DIR_HIT_COMPARE;
+
+#if DEBUG_MEMC_CAS
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CAS_DIR_HIT_READ> Read data from "
+                            << " cache and store it in buffer" << std::endl;
+#endif
+                    break;
+                }
+
+            case CAS_DIR_HIT_COMPARE:
+                {
+                    size_t word = m_x[(addr_t)(m_cmd_cas_addr_fifo.read())];
+
+                    // Read data in buffer & check data change
+                    bool ok = (r_cas_rdata[0].read() == r_cas_data[word].read());
+
+                    if(r_cas_cpt.read() == 4)     // 64 bits CAS
+                        ok &= (r_cas_rdata[1] == r_cas_data[word+1]);
+
+                    // to avoid livelock, force the atomic access to fail pseudo-randomly
+                    bool forced_fail = ((r_cas_lfsr % (64) == 0) and RANDOMIZE_CAS);
+                    r_cas_lfsr = (r_cas_lfsr >> 1) ^ ((- (r_cas_lfsr & 1)) & 0xd0000001);
+
+                    // cas success
+                    if(ok and not forced_fail)
+                    {
+                        r_cas_fsm = CAS_DIR_HIT_WRITE;
+                    }
+                    // cas failure
+                    else
+                    {
+                        r_cas_fsm = CAS_RSP_FAIL;
+                    }
+
+#if DEBUG_MEMC_CAS
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CAS_DIR_HIT_COMPARE> Compare the old"
+                            << " and the new data"
+                            << " / expected value = " << r_cas_rdata[0].read()
+                            << " / actual value = "   << r_cas_data[word].read()
+                            << " / forced_fail = "    << forced_fail << std::endl;
+#endif
+                    break;
+                }
+                //////////////////////
+            case CAS_DIR_HIT_WRITE:    // test if a CC transaction is required
+                // write data in cache if no CC request
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_CAS) and
+                            "MEMC ERROR in CAS_DIR_HIT_WRITE: Bad DIR allocation");
+
+                    // The CAS is a success => sw access to the llsc_global_table
+                    m_llsc_table.sw(m_cmd_cas_addr_fifo.read(), m_cmd_cas_addr_fifo.read());
+
+                    // test coherence request
+                    if(r_cas_count.read())   // replicated line
+                    {
+                        if(r_cas_count.read() == 1 and r_cas_state.read() == ENTRY_SHARED and r_cas_copy.read() == m_cmd_cas_srcid_fifo.read())
+                        {
+                            DirectoryEntry entry;
+                            entry.state       = r_cas_state.read();
+                            entry.is_cnt      = false;
+                            entry.lock        = false;
+                            entry.dirty       = r_cas_dirty.read();
+                            entry.tag         = r_cas_tag;
+                            entry.ptr         = 0;
+                            entry.owner.srcid = r_cas_copy.read();
+                            entry.owner.inst  = r_cas_copy_inst.read();
+                            entry.count       = 1;
+ 
+                            size_t way  = r_cas_way.read();
+                            size_t set  = m_y[(addr_t)(m_cmd_cas_addr_fifo.read())];
+                            size_t word = m_x[(addr_t)(m_cmd_cas_addr_fifo.read())];
+
+                            m_cache_directory.write(set, way, entry);
+                            // cache update
+                            m_cache_data.write(way, set, word, r_cas_wdata.read());
+                            if(r_cas_cpt.read() == 4)
+                                m_cache_data.write(way, set, word+1, m_cmd_cas_wdata_fifo.read());
+
+                            r_cas_fsm = CAS_RSP_SUCCESS;
+
+                        }
+//                        else if(r_cas_is_cnt.read() and r_cas_state.read() == ENTRY_SHARED)
+//                        {
+//                            r_cas_fsm = CAS_BC_TRT_LOCK;    // broadcast invalidate required
+//#if DEBUG_MEMC_CAS
+//                            if(m_debug)
+//                                std::cout << "  <MEMC " << name() << " CAS_DIR_HIT_WRITE>"
+//                                    << " Broacast Inval required" 
+//                                    << " / copies = " << r_cas_count.read() << std::endl;
+//#endif
+//
+//                        }
+                        else                         
+                        {
+                            r_cas_fsm = CAS_MULTI_INVAL_IVT_LOCK;       // multi invalidate required
+#if DEBUG_MEMC_CAS
+                            if(m_debug)
+                                std::cout << "  <MEMC " << name() << " CAS_DIR_HIT_WRITE>"
+                                    << " Multi Inval required" 
+                                    << " / copies = " << r_cas_count.read() << std::endl;
+#endif
+                        }
+//                        else
+//                        {
+//                            r_cas_fsm = CAS_WAIT;
+//#if DEBUG_MEMC_CAS
+//                            if(m_debug)
+//                                std::cout << "  <MEMC " << name() << " CAS_DIR_HIT_WRITE>"
+//                                    << " CC_SEND FSM busy: release all locks and retry" << std::endl;
+//#endif
+//                        }
+                    }
+                    else                    // no copies or multi_inval finished
+                    {
+                        size_t way  = r_cas_way.read();
+                        size_t set  = m_y[(addr_t)(m_cmd_cas_addr_fifo.read())];
+                        size_t word = m_x[(addr_t)(m_cmd_cas_addr_fifo.read())];
+
+                        // cache update
+                        m_cache_data.write(way, set, word, r_cas_wdata.read());
+                        if(r_cas_cpt.read() == 4)
+                            m_cache_data.write(way, set, word+1, m_cmd_cas_wdata_fifo.read());
+
+                        r_cas_fsm = CAS_RSP_SUCCESS;
+
+#if DEBUG_MEMC_CAS
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " CAS_DIR_HIT_WRITE> Update cache:"
+                                << " way = " << std::dec << way
+                                << " / set = " << set
+                                << " / word = " << word
+                                << " / value = " << r_cas_wdata.read()
+                                << " / count = " << r_cas_count.read()
+                                << " / global_llsc_table access" << std::endl;
+#endif
+                    }
+                    break;
+                }
+                /////////////////
+            case CAS_MULTI_INVAL_IVT_LOCK:  // try to register the transaction in ivt
+                // and write data in cache if successful registration
+                // releases locks to retry later if ivt full
+                {
+                    if(r_alloc_ivt_fsm.read() == ALLOC_IVT_CAS  and 
+                        not r_cas_to_cc_send_multi_req.read()   and
+                        not r_cas_to_cc_send_brdcast_req.read() and 
+                        not r_cas_to_cleanup_req.read()         and
+                            m_cas_to_cc_send_inst_fifo.wok())
+                    {
+                        bool        wok             = false;
+                        size_t      index           = 0;
+                        size_t      srcid           = m_cmd_cas_srcid_fifo.read();
+                        size_t      trdid           = m_cmd_cas_trdid_fifo.read();
+                        size_t      pktid           = m_cmd_cas_pktid_fifo.read();
+                        addr_t      nline           = m_nline[(addr_t)(m_cmd_cas_addr_fifo.read())];
+                        size_t      nb_copies_sent  = 0;
+                        if(r_cas_state.read() == ENTRY_EXCLUSIVE)
+                        {
+                            nb_copies_sent = 1;
+                        }
+                        else
+                        {  
+                            nb_copies_sent = r_cas_count.read(); 
+                        }
+//                        if(m_ivt.search_inval(nline, index) and r_cas_to_cleanup_req.read())
+//                        {
+//#if DEBUG_MEMC_CAS
+//                        if(m_debug)
+//                            std::cout << "  <MEMC " << name()
+//                                << " CAS_MULTI_INVAL_IVT_LOCK> pending ivt "
+//                                << std::endl;
+//#endif
+//                            r_cas_fsm = CAS_WAIT;
+//                            break;
+//                        }
+                        wok = m_ivt.set(false,   // it's an invalid transaction
+                                        false,   // it's not a broadcast
+                                        true,    // response required  
+                                        false,   // no acknowledge required
+                                        srcid,
+                                        trdid,
+                                        pktid,
+                                        nline,
+                                        nb_copies_sent,
+                                        index);
+                        if(wok)   // coherence transaction registered in ivt
+                        {
+                            // cache update
+                            DirectoryEntry    entry;
+                            entry.state       = ENTRY_LOCKED;
+                            entry.is_cnt      = false;
+                            entry.lock        = false;
+                            entry.dirty       = r_cas_dirty.read();
+                            entry.tag         = r_cas_tag.read();
+                            entry.ptr         = r_cas_ptr.read();
+                            entry.owner.srcid = r_cas_copy.read();
+                            entry.owner.inst  = r_cas_copy_inst.read();
+                            entry.count       = r_cas_count.read();  
+ 
+                            size_t way  = r_cas_way.read();
+                            size_t set  = m_y[(addr_t)(m_cmd_cas_addr_fifo.read())];
+                            size_t word = m_x[(addr_t)(m_cmd_cas_addr_fifo.read())];
+
+                            m_cache_directory.write(set, way, entry);
+
+                            // cache update we don't send the invalid request 
+                            // to the cache L1 which has sent the cas command.
+                            // So, the line is still valid in dir.
+                            m_cache_data.write(way, set, word, r_cas_wdata.read());
+                            if(r_cas_cpt.read() == 4)
+                                m_cache_data.write(way, set, word+1, m_cmd_cas_wdata_fifo.read());
+
+                            //r_cas_ivt_index = index;
+                            if((r_cas_count.read() != 1) and not r_cas_is_cnt.read())
+                            {
+                                r_cas_fsm = CAS_MULTI_INVAL_HEAP_LOCK;
+                            }
+                            else
+                            {
+                                assert(not r_cas_copy_inst.read() && "cas fsm: cas has a copy inst");
+
+                                if(not r_cas_is_cnt.read())
+                                {
+                                    cas_to_cc_send_fifo_put       = true;
+                                    cas_to_cc_send_fifo_inst      = r_cas_copy_inst.read();
+                                    cas_to_cc_send_fifo_srcid     = r_cas_copy.read();
+                                    r_cas_to_cc_send_multi_req    = true;
+                                }
+                                else
+                                {
+                                    r_cas_to_cc_send_brdcast_req  = true;
+                                }
+                         
+                                r_cas_to_cc_send_nline        = m_nline[(addr_t)(m_cmd_cas_addr_fifo.read())];
+                                r_cas_to_cleanup_req          = true;
+                                r_cas_to_cleanup_nline        = m_nline[(addr_t)(m_cmd_cas_addr_fifo.read())];
+                                r_cas_fsm        = CAS_IDLE; 
+                                cmd_cas_fifo_get = true;
+                                r_cas_cpt        = 0;
+ 
+                            }
+#if DEBUG_MEMC_CAS
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name()
+                                << " CAS_MULTI_INVAL_IVT_LOCK> Line is locked"
+                                << " / wok = " << wok
+                                << " / set = " << set
+                                << " / way = " << way
+                                << " / nline  = " << std::hex << nline
+                                << " / count = " << nb_copies_sent << std::endl;
+#endif
+                    }
+                        }
+                        else       //  releases the locks protecting UPT and DIR UPT full
+                        {
+                            r_cas_fsm = CAS_WAIT;
+                        }
+
+                    break;
+                }
+                /////////////
+            case CAS_WAIT:   // release all locks and retry from beginning
+                {
+
+#if DEBUG_MEMC_CAS
+                    if(m_debug)
+                    {
+                        std::cout << "  <MEMC " << name()
+                            << " CAS_WAIT> Release all locks" << std::endl;
+                    }
+#endif
+                    r_cas_fsm = CAS_DIR_REQ;
+                    break;
+                }
+                //////////////////
+            case CAS_MULTI_INVAL_HEAP_LOCK:  // lock the heap
+                {
+                    if(r_alloc_heap_fsm.read() == ALLOC_HEAP_CAS)
+                    {
+
+#if DEBUG_MEMC_CAS
+                        if(m_debug)
+                        {
+                            std::cout << "  <MEMC " << name()
+                                << " CAS_MULTI_INVAL_HEAP_LOCK> Get access to the heap" << std::endl;
+                        }
+#endif
+                        r_cas_fsm = CAS_MULTI_INVAL_REQ;
+                        m_cpt_cas_fsm_n_heap_lock++;
+                    }
+
+                    m_cpt_cas_fsm_heap_lock++;
+
+                    break;
+                }
+                ////////////////
+            case CAS_MULTI_INVAL_REQ:  // send a first update request to CC_SEND FSM
+                {
+                    assert((r_alloc_heap_fsm.read() == ALLOC_HEAP_CAS) and
+                            "VCI_MEM_CACHE ERROR : bad HEAP allocation");
+                    
+                    bool match_srcid = r_cas_copy.read() == m_cmd_cas_srcid_fifo.read();
+
+                    assert(not r_cas_copy_inst.read() && "cas fsm: cas has a copy inst");
+
+                    if(not r_cas_to_cc_send_multi_req.read() and not r_cas_to_cc_send_brdcast_req.read())
+                    {
+                        r_cas_next_ptr                = r_cas_ptr.read();
+                        r_cas_to_cc_send_nline        = m_nline[(addr_t)(m_cmd_cas_addr_fifo.read())];
+                        //r_cas_to_cc_send_trdid        = r_cas_ivt_index.read();
+                        //r_cas_to_cc_send_index        = m_x[(addr_t)(m_cmd_cas_addr_fifo.read())];
+                        //r_cas_to_cc_send_wdata        = r_cas_wdata.read();
+
+                        cas_to_cc_send_fifo_put       = true;
+                        cas_to_cc_send_fifo_inst      = r_cas_copy_inst.read();
+                        cas_to_cc_send_fifo_srcid     = r_cas_copy.read();
+                        // We put the first copy in the fifo
+                        if(r_cas_count.read() == 1)  // one single copy
+                        {
+                            assert( false && "it should be more than one copies in cas_multi_inval_req!!!!");
+                        }
+                        else      // several copies
+                        {
+                            r_cas_fsm = CAS_HEAP_NEXT;
+                        }
+
+#if DEBUG_MEMC_CAS
+                        if(m_debug)
+                        {
+                            std::cout << "  <MEMC " << name() << " CAS_MULTI_INVAL_REQ> Send the first update request to CC_SEND FSM "
+                                << " / address = " << std::hex << m_cmd_cas_addr_fifo.read()
+                                << " / wdata = " << std::hex << r_cas_wdata.read()
+                                << " / srcid = " << std::dec << r_cas_copy.read()
+                                << " / inst = " << std::dec << r_cas_copy_inst.read() << std::endl;
+                        }
+#endif
+                    }
+                    else
+                    {
+                        assert(false && "r_cas_cc_send_req for r_cas_cc_send_brdcast_req are true");
+                    }
+                    break;
+                }
+                /////////////////
+            case CAS_HEAP_NEXT:     // send a multi-update request to CC_SEND FSM
+                {
+                    assert((r_alloc_heap_fsm.read() == ALLOC_HEAP_CAS)
+                            and "VCI_MEM_CACHE ERROR : bad HEAP allocation");
+
+                    HeapEntry entry = m_heap.read(r_cas_next_ptr.read());
+
+                    bool match_srcid = (entry.owner.srcid == m_cmd_cas_srcid_fifo.read());
+     
+                    addr_t nline     = m_nline[(addr_t)(m_cmd_cas_addr_fifo.read())];
+
+                    assert(not entry.owner.inst && "cas fsm: cas has a copy inst");
+
+                    if(m_cas_to_cc_send_inst_fifo.wok())   // request accepted by CC_SEND FSM
+                    {   
+                        cas_to_cc_send_fifo_srcid    = entry.owner.srcid;
+                        cas_to_cc_send_fifo_inst     = entry.owner.inst;
+                        cas_to_cc_send_fifo_put      = true;
+                        r_cas_next_ptr               = entry.next;
+                        if(entry.next == r_cas_next_ptr.read())    // last copy
+                        {
+                            r_cas_to_cleanup_nline      = nline;
+                            r_cas_to_cc_send_multi_req  = true;
+                            r_cas_to_cleanup_req        = true;
+                            r_cas_fsm                   = CAS_HEAP_LAST;   // Response will be sent after receiving
+                        }   
+                    }
+#if DEBUG_MEMC_CAS
+                    if(m_debug)
+                    {
+                        std::cout << "  <MEMC " << name() << " CAS_HEAP_NEXT> Send the next update request to CC_SEND FSM "
+                            << " / address = " << std::hex << m_cmd_cas_addr_fifo.read()
+                            << " / wdata = " << std::hex << r_cas_wdata.read()
+                            << " / srcid = " << std::dec << entry.owner.srcid
+                            << " / match srcid = " << match_srcid
+                            << " / inst = " << std::dec << entry.owner.inst << std::endl;
+                    }
+#endif
+                    break;
+                }
+                /////////////////////////
+            case CAS_HEAP_LAST:  // last copy
+                {
+                    if(r_alloc_heap_fsm.read() != ALLOC_HEAP_CAS)
+                    {
+                        std::cout << "VCI_MEM_CACHE ERROR " << name() << " CAS_HEAP_LAST"
+                            << " bad HEAP allocation" << std::endl;
+                        exit(0);
+                    }
+                    size_t free_pointer = m_heap.next_free_ptr();
+
+                    addr_t nline = m_nline[(addr_t)(m_cmd_cas_addr_fifo.read())];
+
+                    HeapEntry last_entry;
+                    last_entry.owner.srcid    = 0;
+                    last_entry.owner.inst     = false;
+                    if(m_heap.is_full())
+                    {
+                        last_entry.next     = r_cas_next_ptr.read();
+                        m_heap.unset_full();
+                    }
+                    else
+                    {
+                        last_entry.next     = free_pointer;
+                    }
+
+                    m_heap.write_free_ptr(r_cas_ptr.read());
+                    m_heap.write(r_cas_next_ptr.read(),last_entry);
+
+                    r_cas_fsm        = CAS_IDLE; 
+                    cmd_cas_fifo_get = true;
+                    r_cas_cpt        = 0;
+ 
+#if DEBUG_MEMC_XRAM_RSP
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CAS_HEAP_LAST>"
+                            << " Heap housekeeping" << std::endl;
+#endif
+                    break;
+                }
+
+
+                /////////////////////
+            case CAS_BC_TRT_LOCK:      // check the TRT to register a PUT transaction
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_CAS) and
+                            "MEMC ERROR in CAS_BC_TRT_LOCK state: Bas DIR allocation");
+
+                    if(r_alloc_trt_fsm.read() == ALLOC_TRT_CAS)
+                    {
+                        size_t wok_index = 0;
+                        bool   wok       = !m_trt.full(wok_index);
+                        if( wok )
+                        {
+                            r_cas_trt_index = wok_index;
+                            r_cas_fsm       = CAS_BC_IVT_LOCK;
+                        }
+                        else
+                        {
+                            r_cas_fsm       = CAS_WAIT;
+                            m_cpt_cas_fsm_n_trt_lock++;
+                        }
+
+#if DEBUG_MEMC_CAS
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " CAS_BC_TRT_LOCK> Check TRT"
+                                << " : wok = " << wok << " / index = " << wok_index << std::endl;
+#endif
+                    }
+                    m_cpt_cas_fsm_trt_lock++;
+
+                    break;
+                }
+                /////////////////////
+            case CAS_BC_IVT_LOCK:  // register a broadcast inval transaction in IVT
+                // write data in cache in case of successful registration
+                {
+                    if(r_alloc_ivt_fsm.read() == ALLOC_IVT_CAS)
+                    {
+                        bool        wok       = false;
+                        size_t      index     = 0;
+                        size_t      srcid     = m_cmd_cas_srcid_fifo.read();
+                        size_t      trdid     = m_cmd_cas_trdid_fifo.read();
+                        size_t      pktid     = m_cmd_cas_pktid_fifo.read();
+                        addr_t      nline     = m_nline[(addr_t)(m_cmd_cas_addr_fifo.read())];
+                        size_t      nb_copies = r_cas_count.read();
+
+                        // register a broadcast inval transaction in IVT
+                        wok = m_ivt.set(false,  // it's an inval transaction
+                                        true,   // it's a broadcast
+                                        true,   // response required
+                                        false,  // no acknowledge required
+                                        srcid,
+                                        trdid,
+                                        pktid,
+                                        nline,
+                                        nb_copies,
+                                        index);
+
+                        if(wok)     // IVT not full
+                        {
+                            // cache update
+                            size_t way  = r_cas_way.read();
+                            size_t set  = m_y[(addr_t)(m_cmd_cas_addr_fifo.read())];
+                            size_t word = m_x[(addr_t)(m_cmd_cas_addr_fifo.read())];
+
+                            m_cache_data.write(way, set, word, r_cas_wdata.read());
+                            if(r_cas_cpt.read() ==4)
+                                m_cache_data.write(way, set, word+1, m_cmd_cas_wdata_fifo.read());
+
+                            r_cas_ivt_index = index;
+                            r_cas_fsm = CAS_BC_DIR_INVAL;
+
+#if DEBUG_MEMC_CAS
+                            if(m_debug)
+                                std::cout << "  <MEMC " << name()
+                                    << " CAS_BC_IVT_LOCK> Register a broadcast inval transaction in IVT"
+                                    << " / nline = " << std::hex << nline
+                                    << " / count = " << std::dec << nb_copies
+                                    << " / ivt_index = " << index << std::endl;
+#endif
+                        }
+                        else      //  releases the lock protecting IVT
+                        {
+                            r_cas_fsm = CAS_WAIT;
+                        }
+                        m_cpt_cas_fsm_n_upt_lock++;
+                    }
+
+                    m_cpt_cas_fsm_upt_lock++;
+
+                    break;
+                }
+                //////////////////////
+            case CAS_BC_DIR_INVAL:  // Register the PUT transaction in TRT, and inval the DIR entry
+                {
+                    assert( (r_alloc_dir_fsm.read() == ALLOC_DIR_CAS) and
+                            "MEMC ERROR in CAS_BC_DIR_INVAL state: Bad DIR allocation");
+
+                    assert( (r_alloc_trt_fsm.read() == ALLOC_TRT_CAS) and
+                            "MEMC ERROR in CAS_BC_DIR_INVAL state: Bad TRT allocation");
+
+                    assert( (r_alloc_ivt_fsm.read() == ALLOC_IVT_CAS) and
+                            "MEMC ERROR in CAS_BC_DIR_INVAL state: Bad IVT allocation");
+
+                    std::vector<data_t> data_vector;
+                    data_vector.clear();
+                    size_t word = m_x[(addr_t)(m_cmd_cas_addr_fifo.read())];
+
+                    for(size_t i=0; i<m_words; i++)
+                    {
+                        if(i == word)                                        // first modified word
+                            data_vector.push_back( r_cas_wdata.read() );     
+                        else if((i == word+1) and (r_cas_cpt.read() == 4))   // second modified word
+                            data_vector.push_back( m_cmd_cas_wdata_fifo.read() );
+                        else                                                 // unmodified words
+                            data_vector.push_back( r_cas_data[i].read() );
+                    }
+                    m_trt.set( r_cas_trt_index.read(),
+                               false,    // PUT request 
+                               m_nline[(addr_t)(m_cmd_cas_addr_fifo.read())],
+                               0,
+                               0,
+                               0,
+                               false,    // not a processor read
+                               0,
+                               0,
+                               std::vector<be_t> (m_words,0),
+                               data_vector );
+
+                    // invalidate directory entry
+                    DirectoryEntry entry;
+                    entry.state         = ENTRY_INVALID;
+                    entry.dirty         = false;
+                    entry.tag           = 0;
+                    entry.is_cnt        = false;
+                    entry.lock          = false;
+                    entry.count         = 0;
+                    entry.owner.srcid   = 0;
+                    entry.owner.inst    = false;
+                    entry.ptr           = 0;
+                    size_t set          = m_y[(addr_t)(m_cmd_cas_addr_fifo.read())];
+                    size_t way          = r_cas_way.read();
+                    m_cache_directory.write(set, way, entry);
+
+                    r_cas_fsm = CAS_BC_CC_SEND;
+
+#if DEBUG_MEMC_CAS
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name() << " CAS_BC_DIR_INVAL> Inval DIR & register in TRT:"
+                            << " address = " << m_cmd_cas_addr_fifo.read() << std::endl;
+#endif
+                    break;
+                }
+                ///////////////////
+            case CAS_BC_CC_SEND:  // Request the broadcast inval to CC_SEND FSM
+                {
+                    if( not r_cas_to_cc_send_multi_req.read() and
+                            not r_cas_to_cc_send_brdcast_req.read())
+                    {
+                        r_cas_to_cc_send_multi_req    = false;
+                        r_cas_to_cc_send_brdcast_req  = true;
+                        //r_cas_to_cc_send_trdid        = r_cas_ivt_index.read();
+                        r_cas_to_cc_send_nline        = m_nline[(addr_t)(m_cmd_cas_addr_fifo.read())];
+                        //r_cas_to_cc_send_index        = 0;
+                        //r_cas_to_cc_send_wdata        = 0;
+
+                        r_cas_fsm = CAS_BC_XRAM_REQ;
+                    }
+                    break;
+                }
+                ////////////////////
+            case CAS_BC_XRAM_REQ: // request the IXR FSM to start a put transaction
+                {
+                    if( not r_cas_to_ixr_cmd_req.read() )
+                    {
+                        r_cas_to_ixr_cmd_req     = true;
+                        r_cas_to_ixr_cmd_index   = r_cas_trt_index.read();
+                        r_cas_fsm                = CAS_IDLE;
+                        cmd_cas_fifo_get         = true;
+                        r_cas_cpt                = 0;
+
+#if DEBUG_MEMC_CAS
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name()
+                                << " CAS_BC_XRAM_REQ> Request a PUT transaction to IXR_CMD FSM" << std::hex
+                                << " / address = " << (addr_t) m_cmd_cas_addr_fifo.read()
+                                << " / trt_index = " << r_cas_trt_index.read() << std::endl;
+#endif
+                    }
+
+                    break;
+                }
+                /////////////////
+            case CAS_RSP_FAIL:  // request TGT_RSP FSM to send a failure response
+                {
+                    if( not r_cas_to_tgt_rsp_req.read() )
+                    {
+                        cmd_cas_fifo_get       = true;
+                        r_cas_cpt              = 0;
+                        r_cas_to_tgt_rsp_req   = true;
+                        r_cas_to_tgt_rsp_data  = 1;
+                        r_cas_to_tgt_rsp_srcid = m_cmd_cas_srcid_fifo.read();
+                        r_cas_to_tgt_rsp_trdid = m_cmd_cas_trdid_fifo.read();
+                        r_cas_to_tgt_rsp_pktid = m_cmd_cas_pktid_fifo.read();
+                        r_cas_fsm              = CAS_IDLE;
+
+#if DEBUG_MEMC_CAS
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name()
+                                << " CAS_RSP_FAIL> Request TGT_RSP to send a failure response" << std::endl;
+#endif
+                    }
+                    break;
+                }
+                ////////////////////
+            case CAS_RSP_SUCCESS:  // request TGT_RSP FSM to send a success response
+                {
+                    if( not r_cas_to_tgt_rsp_req.read() )
+                    {
+                        cmd_cas_fifo_get       = true;
+                        r_cas_cpt              = 0;
+                        r_cas_to_tgt_rsp_req = true;
+                        r_cas_to_tgt_rsp_data  = 0;
+                        r_cas_to_tgt_rsp_srcid = m_cmd_cas_srcid_fifo.read();
+                        r_cas_to_tgt_rsp_trdid = m_cmd_cas_trdid_fifo.read();
+                        r_cas_to_tgt_rsp_pktid = 0x8 + m_cmd_cas_pktid_fifo.read(); // should modify locally in cache L1
+                        r_cas_fsm              = CAS_IDLE;
+
+#if DEBUG_MEMC_CAS
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name()
+                                << " CAS_RSP_SUCCESS> Request TGT_RSP to send a success response" << std::endl;
+#endif
+                    }
+                    break;
+                }
+                /////////////////////
+            case CAS_MISS_TRT_LOCK:         // cache miss : request access to transaction Table
+                {
+                    if(r_alloc_trt_fsm.read() == ALLOC_TRT_CAS)
+                    {
+                        size_t   index = 0;
+                        bool hit_read = m_trt.hit_read(
+                                m_nline[(addr_t) m_cmd_cas_addr_fifo.read()],index);
+                        bool hit_write = m_trt.hit_write(
+                                m_nline[(addr_t) m_cmd_cas_addr_fifo.read()]);
+                        bool wok = not m_trt.full(index);
+
+#if DEBUG_MEMC_CAS
+                        if(m_debug)
+                        {
+                            std::cout << "  <MEMC " << name() << " CAS_MISS_TRT_LOCK> Check TRT state"
+                                << " / hit_read = "  << hit_read
+                                << " / hit_write = " << hit_write
+                                << " / wok = " << wok
+                                << " / index = " << index << std::endl;
+                        }
+#endif
+
+                        if(hit_read or !wok or hit_write)    // missing line already requested or no space in TRT
+                        {
+                            r_cas_fsm = CAS_WAIT;
+                        }
+                        else
+                        {
+                            r_cas_trt_index = index;
+                            r_cas_fsm       = CAS_MISS_TRT_SET;
+                        }
+                        m_cpt_cas_fsm_n_trt_lock++;
+                    }
+
+                    m_cpt_cas_fsm_trt_lock++;
+
+                    break;
+                }
+                ////////////////////
+            case CAS_MISS_TRT_SET: // register the GET transaction in TRT
+                {
+                    assert( (r_alloc_trt_fsm.read() == ALLOC_TRT_CAS) and
+                            "MEMC ERROR in CAS_MISS_TRT_SET state: Bad TRT allocation");
+
+                    std::vector<be_t> be_vector;
+                    std::vector<data_t> data_vector;
+                    be_vector.clear();
+                    data_vector.clear();
+                    for(size_t i=0; i<m_words; i++)
+                    {
+                        be_vector.push_back(0);
+                        data_vector.push_back(0);
+                    }
+
+                    m_trt.set(r_cas_trt_index.read(),
+                              true,   // read request
+                              m_nline[(addr_t) m_cmd_cas_addr_fifo.read()],
+                              m_cmd_cas_srcid_fifo.read(),
+                              m_cmd_cas_trdid_fifo.read(),
+                              m_cmd_cas_pktid_fifo.read(),
+                              false,    // write request from processor
+                              0,
+                              0,
+                              be_vector,
+                              data_vector);
+                    r_cas_fsm = CAS_MISS_XRAM_REQ;
+
+#if DEBUG_MEMC_CAS
+                    if(m_debug)
+                    {
+                        std::cout << "  <MEMC " << name() << " CAS_MISS_TRT_SET> Register a GET transaction in TRT" << std::hex
+                            << " / nline = " << m_nline[(addr_t) m_cmd_cas_addr_fifo.read()]
+                            << " / trt_index = " << r_cas_trt_index.read() << std::endl;
+                    }
+#endif
+                    break;
+                }
+                //////////////////////
+            case CAS_MISS_XRAM_REQ:  // request the IXR_CMD FSM to fetch the missing line
+                {
+                    if( not r_cas_to_ixr_cmd_req.read() )
+                    {
+                        r_cas_to_ixr_cmd_req        = true;
+                        r_cas_to_ixr_cmd_index      = r_cas_trt_index.read();
+                        r_cas_fsm                   = CAS_WAIT;
+
+#if DEBUG_MEMC_CAS
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " CAS_MISS_XRAM_REQ> Request a GET transaction"
+                                << " / address = " << std::hex << (addr_t) m_cmd_cas_addr_fifo.read()
+                                << " / trt_index = " << std::dec << r_cas_trt_index.read() << std::endl;
+#endif
+                    }
+                    break;
+                }
+        } // end switch r_cas_fsm
+
+
+        //////////////////////////////////////////////////////////////////////////////
+        //    CC_SEND FSM
+        //////////////////////////////////////////////////////////////////////////////
+        // The CC_SEND fsm controls the DSPIN initiator port on the coherence
+        // network, used to update or invalidate cache lines in L1 caches.
+        //
+        // It implements a round-robin priority between the four possible client FSMs
+        //     XRAM_RSP > CAS > WRITE > CONFIG 
+        //
+        // Each FSM can request the next services:
+        // - r_xram_rsp_to_cc_send_multi_req : multi-inval
+        //   r_xram_rsp_to_cc_send_brdcast_req : broadcast-inval
+        // - r_write_to_cc_send_multi_req : multi-update
+        //   r_write_to_cc_send_brdcast_req : broadcast-inval
+        // - r_cas_to_cc_send_multi_req : multi-update
+        //   r_cas_to_cc_send_brdcast_req : broadcast-inval
+        // - r_config_to_cc_send_multi_req : multi-inval
+        //   r_config_to_cc_send_brdcast_req : broadcast-inval
+        //   
+        // An inval request is a double DSPIN flit command containing:
+        // 1. the index of the line to be invalidated.
+        //
+        // An update request is a multi-flit DSPIN command containing:
+        // 1. the index of the cache line to be updated.
+        // 2. the index of the first modified word in the line.
+        // 3. the data to update
+        ///////////////////////////////////////////////////////////////////////////////
+
+        switch(r_cc_send_fsm.read())
+        {
+            /////////////////////////
+            case CC_SEND_CONFIG_IDLE:    // XRAM_RSP FSM has highest priority
+                {
+                    // XRAM_RSP
+                    if(m_xram_rsp_to_cc_send_inst_fifo.rok() or
+                            r_xram_rsp_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_XRAM_RSP_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_xram_rsp_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_XRAM_RSP_BRDCAST_HEADER;
+                        break;
+                    }
+                    // CAS
+                    if(m_cas_to_cc_send_inst_fifo.rok() or
+                            r_cas_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CAS_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_cas_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CAS_BRDCAST_HEADER;
+                        break;
+                    }
+
+                    // READ
+                    if(m_read_to_cc_send_inst_fifo.rok() or 
+                            r_read_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_READ_MULTI_HEADER;
+                        break;
+                    }
+                    if(r_read_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_READ_BRDCAST_HEADER;
+                        break;
+                    }
+
+                    // WRITE
+//                   if(r_write_to_cc_send_req.read())
+//                   {
+//                       r_cc_send_fsm = CC_SEND_WRITE_NCC_INVAL_HEADER;
+//                       break;
+//                   }
+
+                    if(m_write_to_cc_send_inst_fifo.rok() or
+                            r_write_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_WRITE_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_write_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_WRITE_BRDCAST_HEADER;
+                        break;
+                    }
+                    // CONFIG
+                    if(r_config_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CONFIG_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_config_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CONFIG_BRDCAST_HEADER;
+                        break;
+                    }
+                    break;
+                }
+                ////////////////////////
+            case CC_SEND_WRITE_IDLE:     // CONFIG FSM has highest priority
+                {
+                    // CONFIG
+                    if(r_config_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CONFIG_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_config_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CONFIG_BRDCAST_HEADER;
+                        break;
+                    }
+                    // XRAM_RSP
+                    if(m_xram_rsp_to_cc_send_inst_fifo.rok() or
+                            r_xram_rsp_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_XRAM_RSP_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_xram_rsp_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_XRAM_RSP_BRDCAST_HEADER;
+                        break;
+                    }
+                    // CAS
+                    if(m_cas_to_cc_send_inst_fifo.rok() or
+                            r_cas_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CAS_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_cas_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CAS_BRDCAST_HEADER;
+                        break;
+                    }
+                    // READ
+                    if(m_read_to_cc_send_inst_fifo.rok() or 
+                            r_read_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_READ_MULTI_HEADER;
+                        break;
+                    }
+                    if(r_read_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_READ_BRDCAST_HEADER;
+                        break;
+                    }
+                    // WRITE
+//                   if(r_write_to_cc_send_req.read())
+//                   {
+//                       r_cc_send_fsm = CC_SEND_WRITE_NCC_INVAL_HEADER;
+//                       break;
+//                   }
+                    if(m_write_to_cc_send_inst_fifo.rok() or
+                            r_write_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_WRITE_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_write_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_WRITE_BRDCAST_HEADER;
+                        break;
+                    }
+                    break;
+                }
+                ///////////////////////////
+            case CC_SEND_XRAM_RSP_IDLE:   // CAS FSM has highest priority
+                {
+                    // CAS
+                    if(m_cas_to_cc_send_inst_fifo.rok() or
+                            r_cas_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CAS_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_cas_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CAS_BRDCAST_HEADER;
+                        break;
+                    }
+                    // READ
+                    if(m_read_to_cc_send_inst_fifo.rok() or 
+                            r_read_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_READ_MULTI_HEADER;
+                        break;
+                    }
+                    if(r_read_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_READ_BRDCAST_HEADER;
+                        break;
+                    }
+                    //WRITE
+                    if(m_write_to_cc_send_inst_fifo.rok() or
+                            r_write_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_WRITE_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_write_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_WRITE_BRDCAST_HEADER;
+                        break;
+                    }
+                    // CONFIG
+                    if(r_config_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CONFIG_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_config_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CONFIG_BRDCAST_HEADER;
+                        break;
+                    }
+                    // XRAM_RSP
+                    if(m_xram_rsp_to_cc_send_inst_fifo.rok() or
+                            r_xram_rsp_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_XRAM_RSP_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_xram_rsp_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_XRAM_RSP_BRDCAST_HEADER;
+                        break;
+                    }
+                    break;
+                }
+                //////////////////////
+            case CC_SEND_CAS_IDLE:   // CLEANUP FSM has highest priority
+                {
+                    // READ
+                    if(m_read_to_cc_send_inst_fifo.rok() or 
+                            r_read_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_READ_MULTI_HEADER;
+                        break;
+                    }
+                    if(r_read_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_READ_BRDCAST_HEADER;
+                        break;
+                    }
+                    //WRITE
+                    if(m_write_to_cc_send_inst_fifo.rok() or
+                            r_write_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_WRITE_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_write_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_WRITE_BRDCAST_HEADER;
+                        break;
+                    }
+                    // CONFIG
+                    if(r_config_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CONFIG_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_config_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CONFIG_BRDCAST_HEADER;
+                        break;
+                    }
+                    //xram
+                    if(m_xram_rsp_to_cc_send_inst_fifo.rok() or
+                            r_xram_rsp_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_XRAM_RSP_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_xram_rsp_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_XRAM_RSP_BRDCAST_HEADER;
+                        break;
+                    }
+                    //cas
+                    if(m_cas_to_cc_send_inst_fifo.rok() or
+                            r_cas_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CAS_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_cas_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CAS_BRDCAST_HEADER;
+                        break;
+                    }
+                    break;
+                }
+                ////////////////////////////////
+            case CC_SEND_READ_IDLE:    // WRITE FSM has highest priority  
+                {
+                    //WRITE
+                    if(m_write_to_cc_send_inst_fifo.rok() or
+                            r_write_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_WRITE_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_write_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_WRITE_BRDCAST_HEADER;
+                        break;
+                    }
+                    // CONFIG
+                    if(r_config_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CONFIG_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_config_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CONFIG_BRDCAST_HEADER;
+                        break;
+                    }
+                    //xram
+                    if(m_xram_rsp_to_cc_send_inst_fifo.rok() or
+                            r_xram_rsp_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_XRAM_RSP_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_xram_rsp_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_XRAM_RSP_BRDCAST_HEADER;
+                        break;
+                    }
+                    //cas
+                    if(m_cas_to_cc_send_inst_fifo.rok() or
+                            r_cas_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CAS_INVAL_HEADER;
+                        break;
+                    }
+                    if(r_cas_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_CAS_BRDCAST_HEADER;
+                        break;
+                    }
+                    // READ
+                    if(m_read_to_cc_send_inst_fifo.rok() or 
+                            r_read_to_cc_send_multi_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_READ_MULTI_HEADER;
+                        break;
+                    }
+                    if(r_read_to_cc_send_brdcast_req.read())
+                    {
+                        r_cc_send_fsm = CC_SEND_READ_BRDCAST_HEADER;
+                        break;
+                    }
+ 
+                    break;
+                }
+                /////////////////////////////////
+            case CC_SEND_CONFIG_INVAL_HEADER:   // send first flit multi-inval (from CONFIG FSM)
+                {
+                    if(m_config_to_cc_send_inst_fifo.rok())
+                    {
+                        if(not p_dspin_m2p.read) break;
+                        // <Activity Counters>
+                        if (is_local_req(m_config_to_cc_send_srcid_fifo.read()))
+                        {
+                            m_cpt_minval_local++;
+                        }
+                        else
+                        {
+                            m_cpt_minval_remote++;
+                            m_cpt_minval_cost += req_distance(m_config_to_cc_send_srcid_fifo.read());
+                        }
+                        // </Activity Counters>
+                        r_cc_send_fsm = CC_SEND_CONFIG_INVAL_NLINE;
+                        break;
+                    }
+                    if(r_config_to_cc_send_multi_req.read()) r_config_to_cc_send_multi_req = false;
+                    // <Activity Counters>
+                    m_cpt_minval++;
+                    // </Activity Counters>
+                    r_cc_send_fsm = CC_SEND_CONFIG_IDLE;
+                    break;
+                }
+                ////////////////////////////////
+            case CC_SEND_CONFIG_INVAL_NLINE:    // send second flit multi-inval (from CONFIG FSM)
+                {
+                    if(not p_dspin_m2p.read) break;
+                    config_to_cc_send_fifo_get = true;
+                    r_cc_send_fsm = CC_SEND_CONFIG_INVAL_HEADER;
+
+#if DEBUG_MEMC_CC_SEND
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " CC_SEND_CONFIG_INVAL_NLINE> multi-inval for line "
+                            << std::hex << r_config_to_cc_send_nline.read() << std::endl;
+#endif
+                    break;
+                }
+                ///////////////////////////////////
+            case CC_SEND_CONFIG_BRDCAST_HEADER:   // send first flit BC-inval (from CONFIG FSM)
+                {
+                    if(not p_dspin_m2p.read) break;
+                    r_cc_send_fsm = CC_SEND_CONFIG_BRDCAST_NLINE;
+                    break;
+                }
+                //////////////////////////////////
+            case CC_SEND_CONFIG_BRDCAST_NLINE:    // send second flit BC-inval (from CONFIG FSM)
+                {
+                    if(not p_dspin_m2p.read) break;
+                    // <Activity Counters>
+                    m_cpt_binval++;
+                    // </Activity Counters>
+                    r_config_to_cc_send_brdcast_req = false;
+                    r_cc_send_fsm = CC_SEND_CONFIG_IDLE;
+
+#if DEBUG_MEMC_CC_SEND
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " CC_SEND_CONFIG_BRDCAST_NLINE> BC-Inval for line "
+                            << std::hex << r_config_to_cc_send_nline.read() << std::endl;
+#endif
+                    break;
+                }
+                ///////////////////////////////////
+            case CC_SEND_XRAM_RSP_INVAL_HEADER:   // send first flit multi-inval (from XRAM_RSP FSM)
+                {
+                    if(m_xram_rsp_to_cc_send_inst_fifo.rok())
+                    {
+                        if(not p_dspin_m2p.read) break;
+                        // <Activity Counters>
+                        if (is_local_req(m_xram_rsp_to_cc_send_srcid_fifo.read()))
+                        {
+                            m_cpt_minval_local++;
+                        }
+                        else
+                        {
+                            m_cpt_minval_remote++;
+                            m_cpt_minval_cost += req_distance(m_xram_rsp_to_cc_send_srcid_fifo.read());
+                        }
+                        // </Activity Counters>
+                        r_cc_send_fsm = CC_SEND_XRAM_RSP_INVAL_NLINE;
+                        break;
+                    }
+                    if(r_xram_rsp_to_cc_send_multi_req.read()) r_xram_rsp_to_cc_send_multi_req = false;
+                    // <Activity Counters>
+                    m_cpt_minval++;
+                    // </Activity Counters>
+                    r_cc_send_fsm = CC_SEND_XRAM_RSP_IDLE;
+                    break;
+                }
+                //////////////////////////////////
+            case CC_SEND_XRAM_RSP_INVAL_NLINE:   // send second flit multi-inval (from XRAM_RSP FSM)
+                {
+                    if(not p_dspin_m2p.read) break;
+                    xram_rsp_to_cc_send_fifo_get = true;
+                    r_cc_send_fsm = CC_SEND_XRAM_RSP_INVAL_HEADER;
+
+#if DEBUG_MEMC_CC_SEND
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " CC_SEND_XRAM_RSP_INVAL_NLINE> Multicast-Inval for line "
+                            << std::hex << r_xram_rsp_to_cc_send_nline.read() << std::endl;
+#endif
+                    break;
+                }
+                /////////////////////////////////////
+            case CC_SEND_XRAM_RSP_BRDCAST_HEADER:  // send first flit broadcast-inval (from XRAM_RSP FSM)
+                {
+                    if(not p_dspin_m2p.read) break;
+                    r_cc_send_fsm = CC_SEND_XRAM_RSP_BRDCAST_NLINE;
+                    break;
+                }
+                ////////////////////////////////////
+            case CC_SEND_XRAM_RSP_BRDCAST_NLINE:   // send second flit broadcast-inval (from XRAM_RSP FSM)
+                {
+                    if(not p_dspin_m2p.read) break;
+                    // <Activity Counters>
+                    m_cpt_binval++;
+                    // </Activity Counters>
+                    r_xram_rsp_to_cc_send_brdcast_req = false;
+                    r_cc_send_fsm = CC_SEND_XRAM_RSP_IDLE;
+
+#if DEBUG_MEMC_CC_SEND
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " CC_SEND_XRAM_RSP_BRDCAST_NLINE> BC-Inval for line "
+                            << std::hex << r_xram_rsp_to_cc_send_nline.read() << std::endl;
+#endif
+                    break;
+                }
+                /////////////////////////////////////
+            case CC_SEND_READ_BRDCAST_HEADER:
+                {
+                    if(not p_dspin_m2p.read) break;
+                    r_cc_send_fsm = CC_SEND_READ_BRDCAST_NLINE;
+                    break;
+                }   
+            case CC_SEND_READ_BRDCAST_NLINE:
+                {
+                    if(not p_dspin_m2p.read) break;
+                    r_read_to_cc_send_brdcast_req = false;
+                    r_cc_send_fsm = CC_SEND_READ_IDLE;
+                }
+
+            case CC_SEND_READ_MULTI_HEADER:
+                {
+                    if(m_read_to_cc_send_inst_fifo.rok())
+                    {
+                        if(not p_dspin_m2p.read) break;
+                        r_cc_send_fsm = CC_SEND_READ_MULTI_NLINE;
+                        break;
+                    }
+
+                    if(r_read_to_cc_send_multi_req.read())
+                    {
+                       r_read_to_cc_send_multi_req = false;
+                    }
+
+                    r_cc_send_fsm = CC_SEND_READ_IDLE;
+                    break;
+                }
+
+            case CC_SEND_READ_MULTI_NLINE:
+                {
+                    if(not p_dspin_m2p.read) break;
+
+                    read_to_cc_send_fifo_get = true;
+                    r_cc_send_fsm = CC_SEND_READ_MULTI_HEADER;
+
+#if DEBUG_MEMC_CC_SEND
+                    if(m_debug)
+                    {
+                        std::cout
+                            << "  <MEMC " << name()
+                            << " CC_SEND_READ_MULTI_HEADER> Inval for line "
+                            << r_read_to_cc_send_nline.read()
+                            << std::endl;
+                    }
+#endif
+                    break;
+                }
+//            case CC_SEND_WRITE_INVAL_HEADER:
+//                {
+//                    if(not p_dspin_m2p.read) break;
+//
+//                    r_cc_send_fsm = CC_SEND_WRITE_INVAL_NLINE;
+//                    break;
+//                }
+//
+//            case CC_SEND_WRITE_INVAL_NLINE:
+//                {
+//                    if(not p_dspin_m2p.read) break;
+//
+//                    r_write_to_cc_send_req = false;
+//                    r_cc_send_fsm = CC_SEND_WRITE_IDLE;
+//
+//#if DEBUG_MEMC_CC_SEND
+//                    if(m_debug)
+//                    {
+//                        std::cout
+//                            << "  <MEMC " << name()
+//                            << " CC_SEND_WRITE_INVAL_HEADER> Inval for line "
+//                            << r_write_to_cc_send_nline.read()
+//                            << std::endl;
+//                    }
+//#endif
+//                    break;
+//                }
+//
+
+                //////////////////////////////////
+            case CC_SEND_WRITE_BRDCAST_HEADER:   // send first flit broadcast-inval (from WRITE FSM)
+                {
+                    if(not p_dspin_m2p.read) break;
+                    r_cc_send_fsm = CC_SEND_WRITE_BRDCAST_NLINE;
+                    break;
+                }
+                /////////////////////////////////
+            case CC_SEND_WRITE_BRDCAST_NLINE:   // send second flit broadcast-inval (from WRITE FSM)
+                {
+                    if(not p_dspin_m2p.read) break;
+
+                    // <Activity Counters>
+                    m_cpt_binval++;
+                    // </Activity Counters>
+
+                    r_write_to_cc_send_brdcast_req = false;
+                    r_cc_send_fsm = CC_SEND_WRITE_IDLE;
+
+#if DEBUG_MEMC_CC_SEND
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " CC_SEND_WRITE_BRDCAST_NLINE> BC-Inval for line "
+                            << std::hex << r_write_to_cc_send_nline.read() << std::endl;
+#endif
+                    break;
+                }
+                ///////////////////////////////
+            case CC_SEND_WRITE_INVAL_HEADER:   // send first flit for a multi-inval (from WRITE FSM)
+                {
+                    if(m_write_to_cc_send_inst_fifo.rok())
+                    {
+                        if(not p_dspin_m2p.read) break;
+//                        // <Activity Counters>
+//                        if (is_local_req(m_write_to_cc_send_srcid_fifo.read()))
+//                        {
+//                            m_cpt_update_local++;
+//                        }
+//                        else
+//                        {
+//                            m_cpt_update_remote++;
+//                            m_cpt_update_cost += req_distance(m_write_to_cc_send_srcid_fifo.read());
+//                        }
+//                        // </Activity Counters>
+
+                        r_cc_send_fsm = CC_SEND_WRITE_INVAL_NLINE;
+                        break;
+                    }
+
+                    if(r_write_to_cc_send_multi_req.read())
+                    {
+                        r_write_to_cc_send_multi_req = false;
+                    }
+
+                    // <Activity Counters>
+                    m_cpt_update++;
+                    // </Activity Counters>
+                    r_cc_send_fsm = CC_SEND_WRITE_IDLE;
+                    break;
+                }
+                //////////////////////////////
+            case CC_SEND_WRITE_INVAL_NLINE:   // send second flit for a multi-update (from WRITE FSM)
+                {
+                    if(not p_dspin_m2p.read) break;
+                    write_to_cc_send_fifo_get = true;
+                    r_cc_send_fsm = CC_SEND_WRITE_INVAL_HEADER;
+
+#if DEBUG_MEMC_CC_SEND
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " CC_SEND_WRITE_INVAL_NLINE> Multicast-Inval for line "
+                            << std::hex << r_write_to_cc_send_nline.read() << std::endl;
+#endif
+                    break;
+                }
+                /////////////////////////////
+//            case CC_SEND_WRITE_UPDT_DATA:   // send N data flits for a multi-update (from WRITE FSM)
+//                {
+//                    if(not p_dspin_m2p.read) break;
+//                    if(r_cc_send_cpt.read() == r_write_to_cc_send_count.read())
+//                    {
+//                        write_to_cc_send_fifo_get = true;
+//                        r_cc_send_fsm = CC_SEND_WRITE_UPDT_HEADER;
+//                        break;
+//                    }
+//
+//                    r_cc_send_cpt = r_cc_send_cpt.read() + 1;
+//                    break;
+//                }
+                ////////////////////////////////
+            case CC_SEND_CAS_BRDCAST_HEADER:   // send first flit  broadcast-inval (from CAS FSM)
+                {
+                    if(not p_dspin_m2p.read) break;
+                    r_cc_send_fsm = CC_SEND_CAS_BRDCAST_NLINE;
+                    break;
+                }
+                ///////////////////////////////
+            case CC_SEND_CAS_BRDCAST_NLINE:   // send second flit broadcast-inval (from CAS FSM)
+                {
+                    if(not p_dspin_m2p.read) break;
+                    // <Activity Counters>
+                    m_cpt_binval++;
+                    // </Activity Counters>
+
+                    r_cas_to_cc_send_brdcast_req = false;
+                    r_cc_send_fsm = CC_SEND_CAS_IDLE;
+
+#if DEBUG_MEMC_CC_SEND
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " CC_SEND_CAS_BRDCAST_NLINE> Broadcast-Inval for line "
+                            << r_cas_to_cc_send_nline.read() << std::endl;
+#endif
+                    break;
+                }
+                /////////////////////////////
+            case CC_SEND_CAS_INVAL_HEADER:   // send first flit for a multi-update (from CAS FSM)
+                {
+                    if(m_cas_to_cc_send_inst_fifo.rok())
+                    {
+                        if(not p_dspin_m2p.read) break;
+                        // <Activity Counters>
+//                        if (is_local_req(m_cas_to_cc_send_srcid_fifo.read()))
+//                        {
+//                            m_cpt_update_local++;
+//                        }
+//                        else
+//                        {
+//                            m_cpt_update_remote++;
+//                            m_cpt_update_cost += req_distance(m_cas_to_cc_send_srcid_fifo.read());
+//                        }
+//                        // </Activity Counters>
+                        r_cc_send_fsm = CC_SEND_CAS_INVAL_NLINE;
+                        break;
+                    }
+
+                    // no more packets to send for the multi-update
+                    if(r_cas_to_cc_send_multi_req.read())
+                    {
+                        r_cas_to_cc_send_multi_req = false;
+                    }
+
+                    // <Activity Counters>
+//                    m_cpt_update++;
+                    // </Activity Counters>
+                    r_cc_send_fsm = CC_SEND_CAS_IDLE;
+                    break;
+                }
+                ////////////////////////////
+            case CC_SEND_CAS_INVAL_NLINE:   // send second flit for a multi-update (from CAS FSM)
+                {
+                    if(not p_dspin_m2p.read) break;
+                    cas_to_cc_send_fifo_get = true;
+                    r_cc_send_fsm = CC_SEND_CAS_INVAL_HEADER;
+
+#if DEBUG_MEMC_CC_SEND
+                    if(m_debug)
+                        std::cout << "  <MEMC " << name()
+                            << " CC_SEND_CAS_INVAL_NLINE> Multicast-Inval for line "
+                            << std::hex << r_cas_to_cc_send_nline.read() << std::endl;
+#endif
+                    break;
+                }
+                ///////////////////////////
+//            case CC_SEND_CAS_UPDT_DATA:   // send first data for a multi-update (from CAS FSM)
+//                {
+//                    if(not p_dspin_m2p.read) break;
+//
+//                    if(r_cas_to_cc_send_is_long.read())
+//                    {
+//                        r_cc_send_fsm = CC_SEND_CAS_UPDT_DATA_HIGH;
+//                        break;
+//                    }
+//
+//                    cas_to_cc_send_fifo_get = true;
+//                    r_cc_send_fsm = CC_SEND_CAS_UPDT_HEADER;
+//                    break;
+//                }
+                ////////////////////////////////
+//            case CC_SEND_CAS_UPDT_DATA_HIGH:   // send second data for a multi-update (from CAS FSM)
+//                {
+//                    if(not p_dspin_m2p.read) break;
+//                    cas_to_cc_send_fifo_get = true;
+//                    r_cc_send_fsm = CC_SEND_CAS_UPDT_HEADER;
+//                    break;
+//                }
+        }
+        // end switch r_cc_send_fsm
+
+        //////////////////////////////////////////////////////////////////////////////
+        //    CC_RECEIVE FSM
+        //////////////////////////////////////////////////////////////////////////////
+        // The CC_RECEIVE fsm controls the DSPIN target port on the coherence
+        // network.
+        //////////////////////////////////////////////////////////////////////////////
+
+        switch(r_cc_receive_fsm.read())
+        {
+            /////////////////////
+            case CC_RECEIVE_IDLE:
+                {
+                    if(not p_dspin_p2m.write) break;
+
+                    uint8_t type =
+                        DspinDhccpParam::dspin_get(
+                                p_dspin_p2m.data.read(),
+                                DspinDhccpParam::P2M_TYPE);
+
+                    if((type == DspinDhccpParam::TYPE_CLEANUP_DATA) or
+                            (type == DspinDhccpParam::TYPE_CLEANUP_INST))
+                    {
+                        r_cc_receive_fsm = CC_RECEIVE_CLEANUP;
+                        break;
+                    }
+
+                    if(type == DspinDhccpParam::TYPE_MULTI_ACK)
+                    {
+                        r_cc_receive_fsm = CC_RECEIVE_MULTI_ACK;
+                        break;
+                    }
+
+                    assert(false and
+                            "VCI_MEM_CACHE ERROR in CC_RECEIVE : "
+                            "Illegal type in coherence request");
+
+                    break;
+                }
+                ////////////////////////
+            case CC_RECEIVE_CLEANUP:
+                {
+                    // write first CLEANUP flit in CC_RECEIVE to CLEANUP fifo
+
+                    if(not p_dspin_p2m.write or not m_cc_receive_to_cleanup_fifo.wok())
+                        break;
+
+                    cc_receive_to_cleanup_fifo_put = true;
+                    if(p_dspin_p2m.eop.read())
+                        r_cc_receive_fsm               = CC_RECEIVE_IDLE;
+
+                    break;
+                }
+                ////////////////////////////
+            case CC_RECEIVE_CLEANUP_EOP:
+                {
+                    // write second CLEANUP flit in CC_RECEIVE to CLEANUP fifo
+
+                    if(not p_dspin_p2m.write or not m_cc_receive_to_cleanup_fifo.wok())
+                        break;
+
+                    assert(p_dspin_p2m.eop.read() and
+                            "VCI_MEM_CACHE ERROR in CC_RECEIVE : "
+                            "CLEANUP command must have two flits");
+
+                    cc_receive_to_cleanup_fifo_put = true;
+                    if(p_dspin_p2m.eop.read())
+                        r_cc_receive_fsm               = CC_RECEIVE_IDLE;
+                    break;
+                }
+
+                //////////////////////////
+            case CC_RECEIVE_MULTI_ACK:
+                {
+                    // write MULTI_ACK flit in CC_RECEIVE to MULTI_ACK fifo
+
+                    // wait for a WOK in the CC_RECEIVE to MULTI_ACK fifo
+                    if(not p_dspin_p2m.write or not m_cc_receive_to_multi_ack_fifo.wok())
+                        break;
+
+                    if( p_dspin_p2m.eop.read()) 
+                        r_cc_receive_fsm             = CC_RECEIVE_IDLE;
+
+                    cc_receive_to_multi_ack_fifo_put = true;
+                    break;
+                }
+        }
+        //////////////////////////////////////////////////////////////////////////
+        //    TGT_RSP FSM
+        //////////////////////////////////////////////////////////////////////////
+        // The TGT_RSP fsm sends the responses on the VCI target port
+        // with a round robin priority between eigth requests :
+        // - r_config_to_tgt_rsp_req
+        // - r_tgt_cmd_to_tgt_rsp_req
+        // - r_read_to_tgt_rsp_req
+        // - r_write_to_tgt_rsp_req
+        // - r_cas_to_tgt_rsp_req
+        // - r_cleanup_to_tgt_rsp_req
+        // - r_xram_rsp_to_tgt_rsp_req
+        // - r_multi_ack_to_tgt_rsp_req
+        //
+        // The ordering is :
+        //   config >tgt_cmd > read > write > cas > xram > multi_ack > cleanup
+        //////////////////////////////////////////////////////////////////////////
+
+        switch(r_tgt_rsp_fsm.read())
+        {
+            /////////////////////////
+            case TGT_RSP_CONFIG_IDLE:  // tgt_cmd requests have the highest priority
+                {
+                    if(r_tgt_cmd_to_tgt_rsp_req) r_tgt_rsp_fsm = TGT_RSP_TGT_CMD;
+                    else if(r_read_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_READ;
+                        r_tgt_rsp_cpt = r_read_to_tgt_rsp_word.read();
+                    }
+                    else if(r_write_to_tgt_rsp_req)     r_tgt_rsp_fsm = TGT_RSP_WRITE;
+                    else if(r_cas_to_tgt_rsp_req)       r_tgt_rsp_fsm = TGT_RSP_CAS;
+                    else if(r_xram_rsp_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_XRAM;
+                        r_tgt_rsp_cpt = r_xram_rsp_to_tgt_rsp_word.read();
+                    }
+                    else if(r_multi_ack_to_tgt_rsp_req) 
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_MULTI_ACK;
+                        r_tgt_rsp_cpt = r_multi_ack_to_tgt_rsp_word.read();
+                    }
+                    else if(r_cleanup_to_tgt_rsp_req)  
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_CLEANUP;
+                        r_tgt_rsp_cpt = r_cleanup_to_tgt_rsp_first_word.read();
+                    }
+                    else if(r_config_to_tgt_rsp_req)    r_tgt_rsp_fsm = TGT_RSP_CONFIG;
+                    break;
+                }
+                //////////////////////////
+            case TGT_RSP_TGT_CMD_IDLE: // read requests have the highest priority
+                {
+                    if(r_read_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_READ;
+                        r_tgt_rsp_cpt = r_read_to_tgt_rsp_word.read();
+                    }
+                    else if(r_write_to_tgt_rsp_req)     r_tgt_rsp_fsm = TGT_RSP_WRITE;
+                    else if(r_cas_to_tgt_rsp_req)       r_tgt_rsp_fsm = TGT_RSP_CAS;
+                    else if(r_xram_rsp_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_XRAM;
+                        r_tgt_rsp_cpt = r_xram_rsp_to_tgt_rsp_word.read();
+                    }
+                    else if(r_multi_ack_to_tgt_rsp_req) 
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_MULTI_ACK;
+                        r_tgt_rsp_cpt = r_multi_ack_to_tgt_rsp_word.read();
+                    }
+                    else if(r_cleanup_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_CLEANUP;
+                        r_tgt_rsp_cpt = r_cleanup_to_tgt_rsp_first_word.read();
+                    }
+                    else if(r_config_to_tgt_rsp_req)    r_tgt_rsp_fsm = TGT_RSP_CONFIG;
+                    else if(r_tgt_cmd_to_tgt_rsp_req)   r_tgt_rsp_fsm = TGT_RSP_TGT_CMD;
+                    break;
+                }
+                ///////////////////////
+            case TGT_RSP_READ_IDLE: // write requests have the highest priority
+                {
+                    if(r_write_to_tgt_rsp_req)          r_tgt_rsp_fsm = TGT_RSP_WRITE;
+                    else if(r_cas_to_tgt_rsp_req)       r_tgt_rsp_fsm = TGT_RSP_CAS;
+                    else if(r_xram_rsp_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_XRAM;
+                        r_tgt_rsp_cpt = r_xram_rsp_to_tgt_rsp_word.read();
+                    }
+                    else if(r_multi_ack_to_tgt_rsp_req) 
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_MULTI_ACK;
+                        r_tgt_rsp_cpt = r_multi_ack_to_tgt_rsp_word.read();
+                    }
+                    else if(r_cleanup_to_tgt_rsp_req) 
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_CLEANUP;
+                        r_tgt_rsp_cpt = r_cleanup_to_tgt_rsp_first_word.read();
+                    }
+                    else if(r_config_to_tgt_rsp_req)    r_tgt_rsp_fsm = TGT_RSP_CONFIG;
+                    else if(r_tgt_cmd_to_tgt_rsp_req)   r_tgt_rsp_fsm = TGT_RSP_TGT_CMD;
+                    else if(r_read_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_READ;
+                        r_tgt_rsp_cpt = r_read_to_tgt_rsp_word.read();
+                    }
+                    break;
+                }
+                ////////////////////////
+            case TGT_RSP_WRITE_IDLE: // cas requests have the highest priority
+                {
+                    if(r_cas_to_tgt_rsp_req)            r_tgt_rsp_fsm = TGT_RSP_CAS;
+                    else if(r_xram_rsp_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_XRAM;
+                        r_tgt_rsp_cpt = r_xram_rsp_to_tgt_rsp_word.read();
+                    }
+                    else if(r_multi_ack_to_tgt_rsp_req) 
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_MULTI_ACK;
+                        r_tgt_rsp_cpt = r_multi_ack_to_tgt_rsp_word.read();
+                    }
+                    else if(r_cleanup_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_CLEANUP;
+                        r_tgt_rsp_cpt = r_cleanup_to_tgt_rsp_first_word.read();
+                    }
+                    else if(r_config_to_tgt_rsp_req)    r_tgt_rsp_fsm = TGT_RSP_CONFIG;
+                    else if(r_tgt_cmd_to_tgt_rsp_req)   r_tgt_rsp_fsm = TGT_RSP_TGT_CMD;
+                    else if(r_read_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_READ;
+                        r_tgt_rsp_cpt = r_read_to_tgt_rsp_word.read();
+                    }
+                    else if(r_write_to_tgt_rsp_req)     r_tgt_rsp_fsm = TGT_RSP_WRITE;
+                    break;
+                }
+                ///////////////////////
+            case TGT_RSP_CAS_IDLE: // xram_rsp requests have the highest priority
+                {
+                    if(r_xram_rsp_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_XRAM;
+                        r_tgt_rsp_cpt = r_xram_rsp_to_tgt_rsp_word.read();
+                    }
+                    else if(r_multi_ack_to_tgt_rsp_req) 
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_MULTI_ACK;
+                        r_tgt_rsp_cpt = r_multi_ack_to_tgt_rsp_word.read();
+                    }
+                    else if(r_cleanup_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_CLEANUP;
+                        r_tgt_rsp_cpt = r_cleanup_to_tgt_rsp_first_word.read();
+                    }
+                    else if(r_config_to_tgt_rsp_req)    r_tgt_rsp_fsm = TGT_RSP_CONFIG;
+                    else if(r_tgt_cmd_to_tgt_rsp_req)   r_tgt_rsp_fsm = TGT_RSP_TGT_CMD;
+                    else if(r_read_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_READ;
+                        r_tgt_rsp_cpt = r_read_to_tgt_rsp_word.read();
+                    }
+                    else if(r_write_to_tgt_rsp_req)     r_tgt_rsp_fsm = TGT_RSP_WRITE;
+                    else if(r_cas_to_tgt_rsp_req)       r_tgt_rsp_fsm = TGT_RSP_CAS  ;
+                    break;
+                }
+                ///////////////////////
+            case TGT_RSP_XRAM_IDLE: // multi ack requests have the highest priority
+                {
+                    if(r_multi_ack_to_tgt_rsp_req.read()) 
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_MULTI_ACK;
+                        r_tgt_rsp_cpt = r_multi_ack_to_tgt_rsp_word.read();
+                    }
+                    else if(r_cleanup_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_CLEANUP;
+                        r_tgt_rsp_cpt = r_cleanup_to_tgt_rsp_first_word.read();
+                    }
+                    else if(r_config_to_tgt_rsp_req)    r_tgt_rsp_fsm = TGT_RSP_CONFIG;
+                    else if(r_tgt_cmd_to_tgt_rsp_req)   r_tgt_rsp_fsm = TGT_RSP_TGT_CMD;
+                    else if(r_read_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_READ;
+                        r_tgt_rsp_cpt = r_read_to_tgt_rsp_word.read();
+                    }
+                    else if(r_write_to_tgt_rsp_req)     r_tgt_rsp_fsm = TGT_RSP_WRITE;
+                    else if(r_cas_to_tgt_rsp_req)       r_tgt_rsp_fsm = TGT_RSP_CAS  ;
+                    else if(r_xram_rsp_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_XRAM;
+                        r_tgt_rsp_cpt = r_xram_rsp_to_tgt_rsp_word.read();
+                    }
+                    break;
+                }
+                ////////////////////////////
+            case TGT_RSP_MULTI_ACK_IDLE: // cleanup requests have the highest priority
+                {
+                    if(r_cleanup_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_CLEANUP;
+                        r_tgt_rsp_cpt = r_cleanup_to_tgt_rsp_first_word.read();
+                    }
+                    else if(r_config_to_tgt_rsp_req)    r_tgt_rsp_fsm = TGT_RSP_CONFIG;
+                    else if(r_tgt_cmd_to_tgt_rsp_req)   r_tgt_rsp_fsm = TGT_RSP_TGT_CMD;
+                    else if(r_read_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_READ;
+                        r_tgt_rsp_cpt = r_read_to_tgt_rsp_word.read();
+                    }
+                    else if(r_write_to_tgt_rsp_req)     r_tgt_rsp_fsm = TGT_RSP_WRITE;
+                    else if(r_cas_to_tgt_rsp_req)       r_tgt_rsp_fsm = TGT_RSP_CAS  ;
+                    else if(r_xram_rsp_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_XRAM;
+                        r_tgt_rsp_cpt = r_xram_rsp_to_tgt_rsp_word.read();
+                    }
+                    else if(r_multi_ack_to_tgt_rsp_req) 
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_MULTI_ACK;
+                        r_tgt_rsp_cpt = r_multi_ack_to_tgt_rsp_word.read();
+                    }
+                    break;
+                }
+                //////////////////////////
+            case TGT_RSP_CLEANUP_IDLE: // tgt cmd requests have the highest priority
+                {
+                    if(r_config_to_tgt_rsp_req)         r_tgt_rsp_fsm = TGT_RSP_CONFIG;
+                    else if(r_tgt_cmd_to_tgt_rsp_req)   r_tgt_rsp_fsm = TGT_RSP_TGT_CMD;
+                    else if(r_read_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_READ;
+                        r_tgt_rsp_cpt = r_read_to_tgt_rsp_word.read();
+                    }
+                    else if(r_write_to_tgt_rsp_req)     r_tgt_rsp_fsm = TGT_RSP_WRITE;
+                    else if(r_cas_to_tgt_rsp_req)       r_tgt_rsp_fsm = TGT_RSP_CAS  ;
+                    else if(r_xram_rsp_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_XRAM;
+                        r_tgt_rsp_cpt = r_xram_rsp_to_tgt_rsp_word.read();
+                    }
+                    else if(r_multi_ack_to_tgt_rsp_req) 
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_MULTI_ACK;
+                        r_tgt_rsp_cpt = r_multi_ack_to_tgt_rsp_word.read();
+                    }
+                    else if(r_cleanup_to_tgt_rsp_req)
+                    {
+                        r_tgt_rsp_fsm = TGT_RSP_CLEANUP;
+                        r_tgt_rsp_cpt = r_cleanup_to_tgt_rsp_first_word.read();
+                    }
+                    break;
+                }
+                ////////////////////
+            case TGT_RSP_CONFIG:  // send the response for a config transaction
+                {
+                    if ( p_vci_tgt.rspack )
+                    {
+                        r_config_to_tgt_rsp_req = false;
+                        r_tgt_rsp_fsm           = TGT_RSP_CONFIG_IDLE;
+
+#if DEBUG_MEMC_TGT_RSP
+                        if( m_debug )
+                        {
+                            std::cout
+                                << "  <MEMC " << name()
+                                << " TGT_RSP_CONFIG>  Config transaction completed response"
+                                << " / rsrcid = " << std::hex << r_config_to_tgt_rsp_srcid.read()
+                                << " / rtrdid = " << r_config_to_tgt_rsp_trdid.read()
+                                << " / rpktid = " << r_config_to_tgt_rsp_pktid.read()
+                                << std::endl;
+                        }
+#endif
+                    }
+                    break;
+                }
+                /////////////////////
+            case TGT_RSP_TGT_CMD: // send the response for a configuration access
+                {
+                    if ( p_vci_tgt.rspack )
+                    {
+                        r_tgt_cmd_to_tgt_rsp_req = false;
+                        r_tgt_rsp_fsm            = TGT_RSP_TGT_CMD_IDLE;
+
+#if DEBUG_MEMC_TGT_RSP
+                        if( m_debug )
+                        {
+                            std::cout
+                                << "  <MEMC " << name()
+                                << " TGT_RSP_TGT_CMD> Send response for a configuration access"
+                                << " / rsrcid = " << std::hex << r_tgt_cmd_to_tgt_rsp_srcid.read()
+                                << " / rtrdid = " << r_tgt_cmd_to_tgt_rsp_trdid.read()
+                                << " / rpktid = " << r_tgt_cmd_to_tgt_rsp_pktid.read()
+                                << " / error = " << r_tgt_cmd_to_tgt_rsp_error.read()
+                                << std::endl;
+                        }
+#endif
+                    }
+                    break;
+                }
+                //////////////////
+            case TGT_RSP_READ:    // send the response to a read
+                {
+                    if ( p_vci_tgt.rspack )
+                    {
+
+#if DEBUG_MEMC_TGT_RSP
+                        if( m_debug )
+                        {
+                            std::cout
+                                << "  <MEMC " << name() << " TGT_RSP_READ> Read response"
+                                << " / rsrcid = " << std::hex << r_read_to_tgt_rsp_srcid.read()
+                                << " / rtrdid = " << r_read_to_tgt_rsp_trdid.read()
+                                << " / rpktid = " << r_read_to_tgt_rsp_pktid.read()
+                                << " / rdata = " << r_read_to_tgt_rsp_data[r_tgt_rsp_cpt.read()].read()
+                                << " / cpt = " << std::dec << r_tgt_rsp_cpt.read() << std::endl;
+                        }
+#endif
+
+
+                        uint32_t last_word_idx = r_read_to_tgt_rsp_word.read() +
+                            r_read_to_tgt_rsp_length.read() - 1;
+                        bool     is_last_word  = (r_tgt_rsp_cpt.read() == last_word_idx);
+                        bool     is_ll         = ((r_read_to_tgt_rsp_pktid.read() & 0x7) == TYPE_LL);
+
+                        if ((is_last_word              and not is_ll) or
+                                (r_tgt_rsp_key_sent.read() and is_ll))
+                        {
+                            // Last word in case of READ or second flit in case if LL
+                            r_tgt_rsp_key_sent    = false;
+                            r_read_to_tgt_rsp_req = false;
+                            r_tgt_rsp_fsm         = TGT_RSP_READ_IDLE;
+                            if (r_read_to_tgt_rsp_pktid.read() == 0x0)
+                            {
+                                m_cpt_read_data_unc ++;
+                            }
+                            else if (r_read_to_tgt_rsp_pktid.read() == 0x1)
+                            {
+                                m_cpt_read_data_miss_CC ++;
+                            }
+                            else if (r_read_to_tgt_rsp_pktid.read() == 0x2)
+                            {
+                                m_cpt_read_ins_unc ++;
+                            }
+                            else if (r_read_to_tgt_rsp_pktid.read() == 0x3)
+                            {
+                                m_cpt_read_ins_miss ++;
+                            }
+                            else if (r_read_to_tgt_rsp_pktid.read() == 0x6)
+                            {
+                                m_cpt_read_ll_CC ++;
+                            }
+                            else if (r_read_to_tgt_rsp_pktid.read() == 0x9)
+                            {
+                                m_cpt_read_data_miss_NCC ++;
+                            }
+                            else if (r_read_to_tgt_rsp_pktid.read() == 0x14)
+                            {
+                                m_cpt_read_ll_NCC ++;
+                            }
+                            else
+                            {
+                                m_cpt_read_WTF ++;
+                            }
+                        }
+                        else
+                        {
+                            if (is_ll)
+                            {
+                                r_tgt_rsp_key_sent = true;                // Send second flit of ll
+                            }
+                            else
+                            {
+                                r_tgt_rsp_cpt = r_tgt_rsp_cpt.read() + 1; // Send next word of read
+                            }
+                        }
+                    }
+                    break;
+                }
+                //////////////////
+            case TGT_RSP_WRITE:   // send the write acknowledge
+                {
+                    if(p_vci_tgt.rspack)
+                    {
+
+#if DEBUG_MEMC_TGT_RSP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " TGT_RSP_WRITE> Write response"
+                                << " / rsrcid = " << std::hex << r_write_to_tgt_rsp_srcid.read()
+                                << " / rtrdid = " << r_write_to_tgt_rsp_trdid.read()
+                                << " / rpktid = " << r_write_to_tgt_rsp_pktid.read() << std::endl;
+#endif
+                        r_tgt_rsp_fsm = TGT_RSP_WRITE_IDLE;
+                        r_write_to_tgt_rsp_req = false;
+                    }
+                    break;
+                }
+                /////////////////////
+            case TGT_RSP_CLEANUP:   // pas clair pour moi (AG)
+                {
+                    if(p_vci_tgt.rspack)
+                    {
+                        uint32_t last_word_idx = r_cleanup_to_tgt_rsp_first_word.read() + r_cleanup_to_tgt_rsp_length.read() - 1;
+                        bool is_ll    = ((r_cleanup_to_tgt_rsp_pktid.read() & 0x7) == TYPE_LL);
+#if DEBUG_MEMC_TGT_RSP
+                        if(m_debug)
+                        {
+                            std::cout << "  <MEMC " << name() << " TGT_RSP_CLEANUP> Cleanup response"
+                                << " / rsrcid = " << std::dec << r_cleanup_to_tgt_rsp_srcid.read()
+                                << " / rtrdid = " << r_cleanup_to_tgt_rsp_trdid.read()
+                                << " / rpktid = " << r_cleanup_to_tgt_rsp_pktid.read() << std::endl
+                                << " / r_cleanup_to_tgt_rsp_type = " << r_cleanup_to_tgt_rsp_type.read()
+                                << " / r_cleanup_to_tgt_rsp_length = " << r_cleanup_to_tgt_rsp_length.read()
+                                << " / r_cleanup_to_tgt_rsp_first_word = " << r_cleanup_to_tgt_rsp_first_word.read()
+                                << " / last_word = " << last_word_idx
+                                << " / r_cpt = " << r_tgt_rsp_cpt.read()
+                                << " / data = " << std::hex << r_cleanup_to_tgt_rsp_data[r_tgt_rsp_cpt.read()].read() << std::dec << std::endl;
+                        }
+#endif
+                        if (r_cleanup_to_tgt_rsp_type.read() or ((r_tgt_rsp_cpt.read() == last_word_idx) and not is_ll) or (r_tgt_rsp_key_sent.read() and is_ll) )
+                        {
+                            r_tgt_rsp_fsm               = TGT_RSP_CLEANUP_IDLE;
+                            r_cleanup_to_tgt_rsp_req    = false;
+                            r_tgt_rsp_key_sent          = false;
+
+                            if (r_cleanup_to_tgt_rsp_pktid.read() == 0x0)
+                            {
+                                m_cpt_read_data_unc ++;
+                            }
+                            else if (r_cleanup_to_tgt_rsp_pktid.read() == 0x1)
+                            {
+                                m_cpt_read_data_miss_CC ++;
+                            }
+                            else if (r_cleanup_to_tgt_rsp_pktid.read() == 0x2)
+                            {
+                                m_cpt_read_ins_unc ++;
+                            }
+                            else if (r_cleanup_to_tgt_rsp_pktid.read() == 0x3)
+                            {
+                                m_cpt_read_ins_miss ++;
+                            }
+                            else if (r_cleanup_to_tgt_rsp_pktid.read() == 0x6)
+                            {
+                                m_cpt_read_ll_CC ++;
+                            }
+                            else if (r_cleanup_to_tgt_rsp_pktid.read() == 0x9)
+                            {
+                                m_cpt_read_data_miss_NCC ++;
+                            }
+                            else if (r_cleanup_to_tgt_rsp_pktid.read() == 0x14)
+                            {
+                                m_cpt_read_ll_NCC ++;
+                            }
+                            else if (!r_cleanup_to_tgt_rsp_type.read())
+                            {
+                                m_cpt_read_WTF ++;
+                            }
+
+                        }
+                        else
+                        {
+                            if (is_ll)
+                            {
+                                r_tgt_rsp_key_sent = true;
+                            }
+                            else
+                            {
+                                r_tgt_rsp_cpt = r_tgt_rsp_cpt.read() + 1;
+                            }
+                        }
+
+                    }
+                    break;
+                }
+                /////////////////
+            case TGT_RSP_CAS:    // send one atomic word response
+                {
+                    if(p_vci_tgt.rspack)
+                    {
+
+#if DEBUG_MEMC_TGT_RSP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " TGT_RSP_CAS> CAS response"
+                                << " / rsrcid = " << std::hex << r_cas_to_tgt_rsp_srcid.read()
+                                << " / rtrdid = " << r_cas_to_tgt_rsp_trdid.read()
+                                << " / rpktid = " << r_cas_to_tgt_rsp_pktid.read() << std::endl;
+#endif
+                        r_tgt_rsp_fsm = TGT_RSP_CAS_IDLE;
+                        r_cas_to_tgt_rsp_req = false;
+                    }
+                    break;
+                }
+                //////////////////
+            case TGT_RSP_XRAM:    // send the response after XRAM access
+                {
+                    if ( p_vci_tgt.rspack )
+                    {
+
+#if DEBUG_MEMC_TGT_RSP
+                        if( m_debug )
+                            std::cout << "  <MEMC " << name() << " TGT_RSP_XRAM> Response following XRAM access"
+                                << " / rsrcid = " << std::hex << r_xram_rsp_to_tgt_rsp_srcid.read()
+                                << " / rtrdid = " << r_xram_rsp_to_tgt_rsp_trdid.read()
+                                << " / rpktid = " << r_xram_rsp_to_tgt_rsp_pktid.read()
+                                << " / rdata = " << r_xram_rsp_to_tgt_rsp_data[r_tgt_rsp_cpt.read()].read()
+                                << " / cpt = " << std::dec << r_tgt_rsp_cpt.read() << std::endl;
+#endif
+                        uint32_t last_word_idx = r_xram_rsp_to_tgt_rsp_word.read() +
+                            r_xram_rsp_to_tgt_rsp_length.read() - 1;
+                        bool     is_last_word  = (r_tgt_rsp_cpt.read() == last_word_idx);
+                        bool     is_ll         = ((r_xram_rsp_to_tgt_rsp_pktid.read() & 0x7) == TYPE_LL);
+                        bool     is_error      = r_xram_rsp_to_tgt_rsp_rerror.read();
+
+                        if (((is_last_word or is_error) and not is_ll) or
+                                (r_tgt_rsp_key_sent.read() and     is_ll))
+                        {
+                            // Last word sent in case of READ or second flit sent in case if LL
+                            r_tgt_rsp_key_sent        = false;
+                            r_xram_rsp_to_tgt_rsp_req = false;
+                            r_tgt_rsp_fsm             = TGT_RSP_XRAM_IDLE;
+
+
+                            if (r_xram_rsp_to_tgt_rsp_pktid.read() == 0x0)
+                            {
+                                m_cpt_read_data_unc ++;
+                            }
+                            else if (r_xram_rsp_to_tgt_rsp_pktid.read() == 0x1)
+                            {
+                                m_cpt_read_data_miss_CC ++;
+                            }
+                            else if (r_xram_rsp_to_tgt_rsp_pktid.read() == 0x2)
+                            {
+                                m_cpt_read_ins_unc ++;
+                            }
+                            else if (r_xram_rsp_to_tgt_rsp_pktid.read() == 0x3)
+                            {
+                                m_cpt_read_ins_miss ++;
+                            }
+                            else if (r_xram_rsp_to_tgt_rsp_pktid.read() == 0x6)
+                            {
+                                m_cpt_read_ll_CC ++;
+                            }
+                            else if (r_xram_rsp_to_tgt_rsp_pktid.read() == 0x9)
+                            {
+                                m_cpt_read_data_miss_NCC ++;
+                            }
+                            else if (r_xram_rsp_to_tgt_rsp_pktid.read() == 0x14)
+                            {
+                                m_cpt_read_ll_NCC ++;
+                            }
+                            else
+                            {
+                                m_cpt_read_WTF ++;
+                            }
+
+                        }
+                        else
+                        {
+                            if (is_ll)
+                            {
+                                r_tgt_rsp_key_sent = true;                     // Send second flit of ll
+                            }
+                            else
+                            {
+                                r_tgt_rsp_cpt      = r_tgt_rsp_cpt.read() + 1; // Send next word of read
+                            }
+                        }
+                    }
+                    break;
+                }
+                ///////////////////////
+            case TGT_RSP_MULTI_ACK:    // send the read /LL response after coherence transaction
+                {
+                    if(p_vci_tgt.rspack)
+                    {
+
+                        uint32_t last_word_idx = r_multi_ack_to_tgt_rsp_word.read() +
+                                                 r_multi_ack_to_tgt_rsp_length.read() - 1;
+                        bool     is_last_word  = (r_tgt_rsp_cpt.read() == last_word_idx);
+                        bool     is_ll         = ((r_multi_ack_to_tgt_rsp_pktid.read() & 0x7) == TYPE_LL);
+ 
+
+#if DEBUG_MEMC_TGT_RSP
+                        if(m_debug)
+                            std::cout << "  <MEMC " << name() << " TGT_RSP_MULTI_ACK> Write response after coherence transaction"
+                                << " / rsrcid = " << std::hex << r_multi_ack_to_tgt_rsp_srcid.read()
+                                << " / data   = " << std::hex << r_multi_ack_to_tgt_rsp_data[r_tgt_rsp_cpt.read()].read()
+                                << " / rtrdid = " << r_multi_ack_to_tgt_rsp_trdid.read()
+                                << " / rpktid = " << r_multi_ack_to_tgt_rsp_pktid.read() << std::endl;
+#endif
+
+                        if (((is_last_word ) and not is_ll) or
+                                (r_tgt_rsp_key_sent.read() and     is_ll))
+                        {
+                            // Last word sent in case of READ or second flit sent in case if LL
+                            r_tgt_rsp_key_sent          = false;
+                            r_multi_ack_to_tgt_rsp_req  = false;
+                            r_tgt_rsp_fsm               = TGT_RSP_MULTI_ACK_IDLE;
+                        }
+                        else
+                        {
+                            if (is_ll)
+                            {
+                                r_tgt_rsp_key_sent = true;                     // Send second flit of ll
+                            }
+                            else
+                            {
+                                r_tgt_rsp_cpt      = r_tgt_rsp_cpt.read() + 1; // Send next word of read
+                            }
+                        }
+ 
+                   }
+                    break;
+                }
+        } // end switch tgt_rsp_fsm
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    ALLOC_UPT FSM
+        ////////////////////////////////////////////////////////////////////////////////////
+        // The ALLOC_UPT FSM allocates the access to the Update Table (UPT),
+        // with a round robin priority between three FSMs, with the following order:
+        //  WRITE -> CAS -> MULTI_ACK
+        // - The WRITE FSM initiates update transaction and sets a new entry in UPT.
+        // - The CAS FSM does the same thing as the WRITE FSM.
+        // - The MULTI_ACK FSM complete those trasactions and erase the UPT entry.
+        // The resource is always allocated.
+        /////////////////////////////////////////////////////////////////////////////////////
+//        switch(r_alloc_upt_fsm.read())
+//        {
+//            /////////////////////////
+//            case ALLOC_UPT_WRITE:         // allocated to WRITE FSM
+//                if (r_write_fsm.read() != WRITE_UPT_LOCK)
+//                {
+//                    if (r_cas_fsm.read() == CAS_MULTI_INVAL_IVT_LOCK)
+//                        r_alloc_upt_fsm = ALLOC_UPT_CAS;
+//
+//                    else if (r_multi_ack_fsm.read() == MULTI_ACK_UPT_LOCK)
+//                        r_alloc_upt_fsm = ALLOC_UPT_MULTI_ACK;
+//                    else
+//                        m_cpt_upt_unused++;
+//                }
+//                break;
+//
+//                /////////////////////////
+//            case ALLOC_UPT_CAS:           // allocated to CAS FSM
+//                if (r_cas_fsm.read() != CAS_MULTI_INVAL_IVT_LOCK)
+//                {
+//                    if (r_multi_ack_fsm.read() == MULTI_ACK_UPT_LOCK)
+//                        r_alloc_upt_fsm = ALLOC_UPT_MULTI_ACK;
+//
+//                    else if (r_write_fsm.read() == WRITE_UPT_LOCK)
+//                        r_alloc_upt_fsm = ALLOC_UPT_WRITE;
+//
+//                    else
+//                        m_cpt_upt_unused++;
+//                }
+//                break;
+//
+//                /////////////////////////
+//            case ALLOC_UPT_MULTI_ACK:     // allocated to MULTI_ACK FSM
+//                if ((r_multi_ack_fsm.read() != MULTI_ACK_UPT_LOCK ) and
+//                        (r_multi_ack_fsm.read() != MULTI_ACK_UPT_CLEAR))
+//                {
+//                    if (r_write_fsm.read() == WRITE_UPT_LOCK)
+//                        r_alloc_upt_fsm = ALLOC_UPT_WRITE;
+//
+//                    else if (r_cas_fsm.read() == CAS_MULTI_INVAL_IVT_LOCK)
+//                        r_alloc_upt_fsm = ALLOC_UPT_CAS;
+//                    else
+//                        m_cpt_upt_unused++;
+//                }
+//                break;
+//        } // end switch r_alloc_upt_fsm
+//
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    ALLOC_IVT FSM
+        ////////////////////////////////////////////////////////////////////////////////////
+        // The ALLOC_IVT FSM allocates the access to the Invalidate Table (IVT),
+        // with a round robin priority between five FSMs, with the following order:
+        //  WRITE -> XRAM_RSP -> CLEANUP -> CAS -> CONFIG
+        // - The WRITE FSM initiates broadcast invalidate transactions and sets a new entry
+        //   in IVT.
+        // - The CAS FSM does the same thing as the WRITE FSM.
+        // - The XRAM_RSP FSM initiates broadcast/multicast invalidate transaction and sets
+        //   a new entry in the IVT
+        // - The CONFIG FSM does the same thing as the XRAM_RSP FSM 
+        // - The CLEANUP FSM complete those trasactions and erase the IVT entry.
+        // The resource is always allocated.
+        /////////////////////////////////////////////////////////////////////////////////////
+        switch(r_alloc_ivt_fsm.read())
+        {
+            //////////////////////////
+            case ALLOC_IVT_WRITE:            // allocated to WRITE FSM
+                if (r_write_fsm.read() != WRITE_INVAL_IVT_LOCK) 
+                {
+                    if((r_read_fsm.read() == READ_IVT_INVAL_LOCK) or
+                       (r_read_fsm.read() == READ_IVT_UPDT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_READ;
+
+                    else if (r_xram_rsp_fsm.read() == XRAM_RSP_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_XRAM_RSP;
+
+                    else if ((r_cleanup_fsm.read() == CLEANUP_MISS_IVT_LOCK) or
+                             (r_cleanup_fsm.read() == CLEANUP_LOCKED_IVT_LOCK)) 
+                        r_alloc_ivt_fsm = ALLOC_IVT_CLEANUP;
+
+                    else if ((r_cas_fsm.read() == CAS_MULTI_INVAL_IVT_LOCK) or
+                             (r_cas_fsm.read() == CAS_BC_IVT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_CAS;
+
+                    else if (r_config_fsm.read() == CONFIG_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_CONFIG;
+
+                    else if (r_multi_ack_fsm.read() == MULTI_ACK_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_MULTI_ACK;
+
+                    else
+                        m_cpt_ivt_unused++;
+                }
+                break;
+
+                //////////////////////////
+            case ALLOC_IVT_READ:            // allocated to READ FSM
+               if((r_read_fsm.read() != READ_IVT_INVAL_LOCK) and
+                  (r_read_fsm.read() != READ_IVT_UPDT_LOCK))
+               {
+                    if (r_xram_rsp_fsm.read() == XRAM_RSP_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_XRAM_RSP;
+
+                    else if ((r_cleanup_fsm.read() == CLEANUP_MISS_IVT_LOCK) or
+                             (r_cleanup_fsm.read() == CLEANUP_LOCKED_IVT_LOCK)) 
+                        r_alloc_ivt_fsm = ALLOC_IVT_CLEANUP;
+
+                    else if ((r_cas_fsm.read() == CAS_MULTI_INVAL_IVT_LOCK) or
+                             (r_cas_fsm.read() == CAS_BC_IVT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_CAS;
+
+                    else if (r_config_fsm.read() == CONFIG_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_CONFIG;
+
+                    else if (r_multi_ack_fsm.read() == MULTI_ACK_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_MULTI_ACK;
+
+                    else if (r_write_fsm.read() == WRITE_INVAL_IVT_LOCK) 
+                        r_alloc_ivt_fsm = ALLOC_IVT_WRITE;
+
+                    else
+                        m_cpt_ivt_unused++;
+                }
+                break;
+
+                //////////////////////////
+            case ALLOC_IVT_XRAM_RSP:         // allocated to XRAM_RSP FSM
+                if(r_xram_rsp_fsm.read() != XRAM_RSP_IVT_LOCK)
+                {
+                    if ((r_cleanup_fsm.read() == CLEANUP_MISS_IVT_LOCK) or
+                        (r_cleanup_fsm.read() == CLEANUP_LOCKED_IVT_LOCK)) 
+                        r_alloc_ivt_fsm = ALLOC_IVT_CLEANUP;
+
+                    else if ((r_cas_fsm.read() == CAS_MULTI_INVAL_IVT_LOCK) or
+                             (r_cas_fsm.read() == CAS_BC_IVT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_CAS;
+
+                    else if (r_config_fsm.read() == CONFIG_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_CONFIG;
+
+                    else if (r_multi_ack_fsm.read() == MULTI_ACK_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_MULTI_ACK;
+
+                    else if (r_write_fsm.read() == WRITE_INVAL_IVT_LOCK) 
+                        r_alloc_ivt_fsm = ALLOC_IVT_WRITE;
+
+                    else if((r_read_fsm.read() == READ_IVT_INVAL_LOCK) or
+                            (r_read_fsm.read() == READ_IVT_UPDT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_READ;
+
+                    else
+                        m_cpt_ivt_unused++;
+                }
+                break;
+
+                //////////////////////////
+            case ALLOC_IVT_CLEANUP:          // allocated to CLEANUP FSM
+                if ((r_cleanup_fsm.read() != CLEANUP_MISS_IVT_LOCK     ) and
+                    (r_cleanup_fsm.read() != CLEANUP_MISS_IVT_DECREMENT) and
+                    (r_cleanup_fsm.read() != CLEANUP_LOCKED_IVT_LOCK     ) and
+                    (r_cleanup_fsm.read() != CLEANUP_LOCKED_IVT_DECREMENT))
+                {
+                    if ((r_cas_fsm.read() == CAS_MULTI_INVAL_IVT_LOCK) or
+                        (r_cas_fsm.read() == CAS_BC_IVT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_CAS;
+
+                    else if (r_config_fsm.read() == CONFIG_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_CONFIG;
+
+                    else if (r_multi_ack_fsm.read() == MULTI_ACK_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_MULTI_ACK;
+
+                    else if (r_write_fsm.read() == WRITE_INVAL_IVT_LOCK) 
+                        r_alloc_ivt_fsm = ALLOC_IVT_WRITE;
+
+                    else if((r_read_fsm.read() == READ_IVT_INVAL_LOCK) or
+                           (r_read_fsm.read() == READ_IVT_UPDT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_READ;
+
+                    else if (r_xram_rsp_fsm.read() == XRAM_RSP_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_XRAM_RSP;
+
+                    else
+                        m_cpt_ivt_unused++;
+                }
+                break;
+
+                //////////////////////////
+            case ALLOC_IVT_CAS:              // allocated to CAS FSM
+                if ((r_cas_fsm.read() != CAS_MULTI_INVAL_IVT_LOCK) and
+                    (r_cas_fsm.read() != CAS_BC_IVT_LOCK))
+                {
+                    if (r_config_fsm.read() == CONFIG_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_CONFIG;
+
+                    else if (r_multi_ack_fsm.read() == MULTI_ACK_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_MULTI_ACK;
+
+                    else if (r_write_fsm.read() == WRITE_INVAL_IVT_LOCK) 
+                        r_alloc_ivt_fsm = ALLOC_IVT_WRITE;
+
+                    else if((r_read_fsm.read() == READ_IVT_INVAL_LOCK) or
+                            (r_read_fsm.read() == READ_IVT_UPDT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_READ;
+
+                    else if (r_xram_rsp_fsm.read() == XRAM_RSP_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_XRAM_RSP;
+
+                    else if ((r_cleanup_fsm.read() == CLEANUP_MISS_IVT_LOCK) or
+                             (r_cleanup_fsm.read() == CLEANUP_LOCKED_IVT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_CLEANUP;
+
+                    else
+                        m_cpt_ivt_unused++;
+                }
+                break;
+
+                //////////////////////////
+            case ALLOC_IVT_CONFIG:           // allocated to CONFIG FSM
+                if (r_config_fsm.read() != CONFIG_IVT_LOCK)
+                {
+                    if (r_multi_ack_fsm.read() == MULTI_ACK_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_MULTI_ACK;
+
+                    else if ((r_write_fsm.read() == WRITE_INVAL_IVT_LOCK)) 
+                        r_alloc_ivt_fsm = ALLOC_IVT_WRITE;
+
+                    else if((r_read_fsm.read() == READ_IVT_INVAL_LOCK) or
+                            (r_read_fsm.read() == READ_IVT_UPDT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_READ;
+
+                    else if (r_xram_rsp_fsm.read() == XRAM_RSP_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_XRAM_RSP;
+
+                    else if ((r_cleanup_fsm.read() == CLEANUP_MISS_IVT_LOCK) or
+                             (r_cleanup_fsm.read() == CLEANUP_LOCKED_IVT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_CLEANUP;
+
+                    else if ((r_cas_fsm.read() == CAS_MULTI_INVAL_IVT_LOCK) or
+                             (r_cas_fsm.read() == CAS_BC_IVT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_CAS;
+
+                    else
+                        m_cpt_ivt_unused++;
+                }
+                break;
+                //////////////////////////
+            case ALLOC_IVT_MULTI_ACK:           // allocated to MULTI ACK FSM
+                if (r_multi_ack_fsm.read() != MULTI_ACK_IVT_LOCK)
+                {
+                    if ((r_write_fsm.read() == WRITE_INVAL_IVT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_WRITE;
+
+                    else if((r_read_fsm.read() == READ_IVT_INVAL_LOCK) or
+                            (r_read_fsm.read() == READ_IVT_UPDT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_READ;
+
+                    else if (r_xram_rsp_fsm.read() == XRAM_RSP_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_XRAM_RSP;
+
+                    else if ((r_cleanup_fsm.read() == CLEANUP_MISS_IVT_LOCK) or
+                             (r_cleanup_fsm.read() == CLEANUP_LOCKED_IVT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_CLEANUP;
+
+                    else if ((r_cas_fsm.read() == CAS_MULTI_INVAL_IVT_LOCK) or
+                             (r_cas_fsm.read() == CAS_BC_IVT_LOCK))
+                        r_alloc_ivt_fsm = ALLOC_IVT_CAS;
+
+                    else if (r_config_fsm.read() == CONFIG_IVT_LOCK)
+                        r_alloc_ivt_fsm = ALLOC_IVT_CONFIG;
+
+                    else
+                        m_cpt_ivt_unused++;
+                }
+                break;
+ 
+        } // end switch r_alloc_ivt_fsm
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    ALLOC_DIR FSM
+        ////////////////////////////////////////////////////////////////////////////////////
+        // The ALLOC_DIR FSM allocates the access to the directory and
+        // the data cache with a round robin priority between 6 user FSMs :
+        // The cyclic ordering is CONFIG > READ > WRITE > CAS > CLEANUP > XRAM_RSP
+        // The ressource is always allocated.
+        /////////////////////////////////////////////////////////////////////////////////////
+
+        switch(r_alloc_dir_fsm.read())
+        {
+            /////////////////////
+            case ALLOC_DIR_RESET: // Initializes the directory one SET per cycle.
+                // All the WAYS of a SET initialized in parallel
+
+                r_alloc_dir_reset_cpt.write(r_alloc_dir_reset_cpt.read() + 1);
+
+                if(r_alloc_dir_reset_cpt.read() == (m_sets - 1))
+                {
+                    m_cache_directory.init();
+                    r_alloc_dir_fsm = ALLOC_DIR_READ;
+                }
+                break;
+
+                //////////////////////
+            case ALLOC_DIR_CONFIG:    // allocated to CONFIG FSM
+                if ( (r_config_fsm.read()    != CONFIG_DIR_REQ) and
+                     (r_config_fsm.read()    != CONFIG_DIR_ACCESS) and
+                     (r_config_fsm.read()    != CONFIG_TRT_LOCK) and
+                     (r_config_fsm.read()    != CONFIG_TRT_SET) and
+                     (r_config_fsm.read()    != CONFIG_IVT_LOCK) )
+                {
+                    if(r_read_fsm.read() == READ_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_READ;
+
+                    else if(r_write_fsm.read() == WRITE_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_WRITE;
+
+                    else if(r_cas_fsm.read() == CAS_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CAS;
+
+                    else if(r_cleanup_fsm.read() == CLEANUP_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
+
+                    else if(r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK)
+                        r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
+
+                    else if(r_multi_ack_fsm.read() == MULTI_ACK_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_MULTI_ACK;
+
+                    else
+                        m_cpt_dir_unused++;
+ 
+                }
+                break;
+
+                ////////////////////
+            case ALLOC_DIR_READ:    // allocated to READ FSM
+                if( ((r_read_fsm.read()      != READ_DIR_REQ)   and
+                     (r_read_fsm.read()      != READ_DIR_LOCK)   and
+                     (r_read_fsm.read()      != READ_TRT_LOCK)   and
+                     (r_read_fsm.read()      != READ_HEAP_REQ)   and
+                     (r_read_fsm.read()      != READ_INVAL_HEAP_REQ) and
+                     (r_read_fsm.read()      != READ_IVT_UPDT_LOCK) and
+                     (r_read_fsm.read()      != READ_IVT_INVAL_LOCK))
+                    or
+                     ((r_read_fsm.read()      == READ_TRT_LOCK)   and
+                     (r_alloc_trt_fsm.read()  == ALLOC_TRT_READ)) )
+                {
+                    if(r_write_fsm.read() == WRITE_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_WRITE;
+
+                    else if(r_cas_fsm.read() == CAS_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CAS;
+
+                    else if(r_cleanup_fsm.read() == CLEANUP_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
+
+                    else if(r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK)
+                        r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
+
+                    else if(r_multi_ack_fsm.read() == MULTI_ACK_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_MULTI_ACK;
+
+                    else if(r_config_fsm.read() == CONFIG_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CONFIG;
+
+                    else
+                        m_cpt_dir_unused++;
+                }
+                else
+                    m_cpt_read_fsm_dir_used++;
+                break;
+
+                /////////////////////
+            case ALLOC_DIR_WRITE:
+                if(((r_write_fsm.read()       != WRITE_DIR_REQ)  and
+                    (r_write_fsm.read()       != WRITE_DIR_LOCK)  and
+                    (r_write_fsm.read()       != WRITE_DIR_HIT)  and
+                    (r_write_fsm.read()       != WRITE_HEAP_ERASE)  and
+                    (r_write_fsm.read()       != WRITE_HEAP_REQ)  and
+                    (r_write_fsm.read()       != WRITE_MISS_TRT_LOCK)  and
+                    (r_write_fsm.read()       != WRITE_INVAL_TRT_LOCK) and
+                    (r_write_fsm.read()       != WRITE_INVAL_IVT_LOCK))
+                   or
+                    ((r_write_fsm.read()      == WRITE_HEAP_ERASE)  and
+                     (r_alloc_heap_fsm.read() == ALLOC_HEAP_WRITE))
+                   or
+                    ((r_write_fsm.read()      == WRITE_MISS_TRT_LOCK)  and
+                     (r_alloc_trt_fsm.read()  == ALLOC_TRT_WRITE)))
+                {
+                    if(r_cas_fsm.read() == CAS_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CAS;
+
+                    else if(r_cleanup_fsm.read() == CLEANUP_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
+
+                    else if(r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK)
+                        r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
+
+                    else if(r_multi_ack_fsm.read() == MULTI_ACK_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_MULTI_ACK;
+
+                    else if(r_config_fsm.read() == CONFIG_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CONFIG;
+
+                    else if(r_read_fsm.read() == READ_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_READ;
+
+                    else
+                        m_cpt_dir_unused++;
+                }
+                else
+                    m_cpt_write_fsm_dir_used++;
+                break;
+
+                ///////////////////
+            case ALLOC_DIR_CAS:    // allocated to CAS FSM
+                if(((r_cas_fsm.read()         != CAS_DIR_REQ)  and
+                    (r_cas_fsm.read()         != CAS_DIR_LOCK)  and
+                    (r_cas_fsm.read()         != CAS_DIR_HIT_READ)  and
+                    (r_cas_fsm.read()         != CAS_DIR_HIT_COMPARE)  and
+                    (r_cas_fsm.read()         != CAS_DIR_HIT_WRITE)  and
+                    (r_cas_fsm.read()         != CAS_BC_TRT_LOCK)  and
+                    (r_cas_fsm.read()         != CAS_BC_IVT_LOCK)  and
+                    (r_cas_fsm.read()         != CAS_MISS_TRT_LOCK)  and
+                    (r_cas_fsm.read()         != CAS_MULTI_INVAL_IVT_LOCK)  and
+                    (r_cas_fsm.read()         != CAS_MULTI_INVAL_HEAP_LOCK))
+                    or
+                    ((r_cas_fsm.read()        == CAS_MULTI_INVAL_HEAP_LOCK)  and
+                     (r_alloc_heap_fsm.read() == ALLOC_HEAP_CAS))
+                    or
+                    ((r_cas_fsm.read()        == CAS_MISS_TRT_LOCK)  and
+                     (r_alloc_trt_fsm.read()  == ALLOC_TRT_CAS)))
+                {
+                    if(r_cleanup_fsm.read() == CLEANUP_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
+
+                    else if(r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK)
+                        r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
+
+                    else if(r_multi_ack_fsm.read() == MULTI_ACK_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_MULTI_ACK;
+
+                    else if(r_config_fsm.read() == CONFIG_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CONFIG;
+
+                    else if(r_read_fsm.read() == READ_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_READ;
+
+                    else if(r_write_fsm.read() == WRITE_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_WRITE;
+
+                    else
+                        m_cpt_dir_unused++;
+                }
+                else
+                    m_cpt_cas_fsm_dir_used++;
+                break;
+
+                ///////////////////////
+            case ALLOC_DIR_CLEANUP:    // allocated to CLEANUP FSM
+                if((r_cleanup_fsm.read() != CLEANUP_DIR_REQ) and
+                   (r_cleanup_fsm.read() != CLEANUP_DIR_LOCK) and
+                   (r_cleanup_fsm.read() != CLEANUP_LOCKED_IVT_LOCK) and
+                   (r_cleanup_fsm.read() != CLEANUP_LOCKED_IVT_DECREMENT) and
+                   (r_cleanup_fsm.read() != CLEANUP_HEAP_REQ) and
+                   (r_cleanup_fsm.read() != CLEANUP_HEAP_LOCK))
+                {
+                    if(r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK)
+                        r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
+
+                    else if(r_multi_ack_fsm.read() == MULTI_ACK_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_MULTI_ACK;
+
+                    else if(r_config_fsm.read() == CONFIG_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CONFIG;
+
+                    else if(r_read_fsm.read() == READ_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_READ;
+
+                    else if(r_write_fsm.read() == WRITE_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_WRITE;
+
+                    else if(r_cas_fsm.read() == CAS_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CAS;
+
+                    else
+                        m_cpt_dir_unused++;
+                }
+                else
+                    m_cpt_cleanup_fsm_dir_used++;
+                break;
+
+                ////////////////////////
+            case ALLOC_DIR_XRAM_RSP:    // allocated to XRAM_RSP FSM
+                if( (r_xram_rsp_fsm.read() != XRAM_RSP_DIR_LOCK) and
+                    (r_xram_rsp_fsm.read() != XRAM_RSP_TRT_COPY) and
+                    (r_xram_rsp_fsm.read() != XRAM_RSP_IVT_LOCK))
+                {
+                    if(r_multi_ack_fsm.read() == MULTI_ACK_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_MULTI_ACK;
+
+                    else if(r_config_fsm.read() == CONFIG_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CONFIG;
+
+                    else if(r_read_fsm.read() == READ_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_READ;
+
+                    else if(r_write_fsm.read() == WRITE_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_WRITE;
+
+                    else if(r_cas_fsm.read() == CAS_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CAS;
+
+                    else if(r_cleanup_fsm.read() == CLEANUP_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
+
+                    else
+                        m_cpt_dir_unused++;
+                }
+                else
+                    m_cpt_xram_rsp_fsm_dir_used++;
+                break;
+
+                ////////////////////////
+            case ALLOC_DIR_MULTI_ACK:    // allocated to MULTI_ACK FSM
+                if(((r_multi_ack_fsm.read() != MULTI_ACK_DIR_REQ) and
+                    (r_multi_ack_fsm.read() != MULTI_ACK_DIR_LOCK) and
+                    (r_multi_ack_fsm.read() != MULTI_ACK_DIR_UPDT)  and
+                    (r_multi_ack_fsm.read() != MULTI_ACK_HEAP_REQ)  and
+                    (r_multi_ack_fsm.read() != MULTI_ACK_HEAP_LOCK) and
+                    (r_multi_ack_fsm.read() != MULTI_ACK_HEAP_WRITE)))
+                 //   or TODO
+                 //   ((r_multi_ack_fsm.read() == MULTI_ACK_HEAP_LOCK) and
+                 //    (r_alloc_heap_fsm.read() == ALLOC_HEAP_MULTI_ACK)))
+                {
+                    if(r_config_fsm.read() == CONFIG_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CONFIG;
+
+                    else if(r_read_fsm.read() == READ_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_READ;
+
+                    else if(r_write_fsm.read() == WRITE_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_WRITE;
+
+                    else if(r_cas_fsm.read() == CAS_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CAS;
+
+                    else if(r_cleanup_fsm.read() == CLEANUP_DIR_REQ)
+                        r_alloc_dir_fsm = ALLOC_DIR_CLEANUP;
+
+                    else if(r_xram_rsp_fsm.read() == XRAM_RSP_DIR_LOCK)
+                        r_alloc_dir_fsm = ALLOC_DIR_XRAM_RSP;
+                    else
+                        m_cpt_dir_unused++;
+                }
+                else
+                    m_cpt_xram_rsp_fsm_dir_used++;
+                break;
+
+
+
+        } // end switch alloc_dir_fsm
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    ALLOC_TRT FSM
+        ////////////////////////////////////////////////////////////////////////////////////
+        // The ALLOC_TRT fsm allocates the access to the Transaction Table (write buffer)
+        // with a round robin priority between 4 user FSMs :
+        // The cyclic priority is READ > WRITE > CAS > XRAM_RSP
+        // The ressource is always allocated.
+        ///////////////////////////////////////////////////////////////////////////////////
+
+        switch(r_alloc_trt_fsm.read())
+        {
+            ////////////////////
+            case ALLOC_TRT_READ:
+                if(r_read_fsm.read() != READ_TRT_LOCK)
+                {
+                    if((r_write_fsm.read() == WRITE_MISS_TRT_LOCK) or
+                       (r_write_fsm.read() == WRITE_INVAL_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_WRITE;
+
+                    else if((r_cas_fsm.read() == CAS_MISS_TRT_LOCK) or
+                            (r_cas_fsm.read() == CAS_BC_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_CAS;
+
+                    else if((r_ixr_cmd_fsm.read() == IXR_CMD_READ_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_WRITE_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CAS_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_XRAM_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CLEANUP_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CONFIG_TRT) )
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_CMD;
+
+                    else if((r_xram_rsp_fsm.read()  == XRAM_RSP_DIR_LOCK) and
+                            (r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP))
+                        r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
+
+                    else if((r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE) or
+                            (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ))
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
+
+                    else if( r_config_fsm.read() == CONFIG_TRT_LOCK ) 
+                        r_alloc_trt_fsm = ALLOC_TRT_CONFIG;
+
+                    else if (r_cleanup_fsm.read() == CLEANUP_MISS_IXR_REQ)
+                        r_alloc_trt_fsm = ALLOC_TRT_CLEANUP;
+
+                    else
+                        m_cpt_trt_unused++;
+                }
+                else
+                    m_cpt_read_fsm_trt_used++;
+                break;
+
+                /////////////////////
+            case ALLOC_TRT_WRITE:
+                if((r_write_fsm.read() != WRITE_MISS_TRT_LOCK) and
+                        (r_write_fsm.read() != WRITE_INVAL_TRT_LOCK) and
+                        (r_write_fsm.read() != WRITE_INVAL_IVT_LOCK))
+                {
+                    if((r_cas_fsm.read() == CAS_MISS_TRT_LOCK) or
+                            (r_cas_fsm.read() == CAS_BC_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_CAS;
+
+                    else if((r_ixr_cmd_fsm.read() == IXR_CMD_READ_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_WRITE_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CAS_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_XRAM_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CLEANUP_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CONFIG_TRT) )
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_CMD;
+
+                    else if((r_xram_rsp_fsm.read()  == XRAM_RSP_DIR_LOCK) and
+                            (r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP))
+                        r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
+
+                    else if((r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE) or
+                            (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ))
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
+
+                    else if( r_config_fsm.read() == CONFIG_TRT_LOCK ) 
+                        r_alloc_trt_fsm = ALLOC_TRT_CONFIG;
+
+                    else if (r_cleanup_fsm.read() == CLEANUP_MISS_IXR_REQ)
+                        r_alloc_trt_fsm = ALLOC_TRT_CLEANUP;
+
+                    else if(r_read_fsm.read() == READ_TRT_LOCK)
+                        r_alloc_trt_fsm = ALLOC_TRT_READ;
+
+                    else
+                        m_cpt_trt_unused++;
+                }
+                else
+                    m_cpt_write_fsm_trt_used++;
+                break;
+
+                ////////////////////
+            case ALLOC_TRT_CAS:
+                if((r_cas_fsm.read() != CAS_MISS_TRT_LOCK) and
+                        (r_cas_fsm.read() != CAS_BC_TRT_LOCK) and
+                        (r_cas_fsm.read() != CAS_BC_IVT_LOCK))
+                {
+                    if((r_ixr_cmd_fsm.read() == IXR_CMD_READ_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_WRITE_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CAS_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_XRAM_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CLEANUP_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CONFIG_TRT) )
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_CMD;
+
+                    else if((r_xram_rsp_fsm.read()  == XRAM_RSP_DIR_LOCK) and
+                            (r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP))
+                        r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
+
+                    else if((r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE) or
+                            (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ))
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
+
+                    else if( r_config_fsm.read() == CONFIG_TRT_LOCK ) 
+                        r_alloc_trt_fsm = ALLOC_TRT_CONFIG;
+
+                    else if (r_cleanup_fsm.read() == CLEANUP_MISS_IXR_REQ)
+                        r_alloc_trt_fsm = ALLOC_TRT_CLEANUP;
+
+                    else if(r_read_fsm.read() == READ_TRT_LOCK)
+                        r_alloc_trt_fsm = ALLOC_TRT_READ;
+
+                    else if((r_write_fsm.read() == WRITE_MISS_TRT_LOCK) or
+                            (r_write_fsm.read() == WRITE_INVAL_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_WRITE;
+
+                    else
+                        m_cpt_trt_unused++;
+                }
+                else
+                    m_cpt_cas_fsm_trt_used++;
+                break;
+                ///////////////////////
+            case ALLOC_TRT_IXR_CMD:
+                if((r_ixr_cmd_fsm.read() != IXR_CMD_READ_TRT) and
+                        (r_ixr_cmd_fsm.read() != IXR_CMD_WRITE_TRT) and
+                        (r_ixr_cmd_fsm.read() != IXR_CMD_CAS_TRT) and
+                        (r_ixr_cmd_fsm.read() != IXR_CMD_XRAM_TRT) and
+                        (r_ixr_cmd_fsm.read() != IXR_CMD_CLEANUP_TRT) and
+                        (r_ixr_cmd_fsm.read() != IXR_CMD_CONFIG_TRT))
+                {
+                    if((r_xram_rsp_fsm.read()  == XRAM_RSP_DIR_LOCK) and
+                            (r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP))
+                        r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
+
+                    else if((r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE) or
+                            (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ))
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
+
+                    else if( r_config_fsm.read() == CONFIG_TRT_LOCK ) 
+                        r_alloc_trt_fsm = ALLOC_TRT_CONFIG;
+
+                    else if (r_cleanup_fsm.read() == CLEANUP_MISS_IXR_REQ)
+                        r_alloc_trt_fsm = ALLOC_TRT_CLEANUP;
+
+                    else if(r_read_fsm.read() == READ_TRT_LOCK)
+                        r_alloc_trt_fsm = ALLOC_TRT_READ;
+
+                    else if((r_write_fsm.read() == WRITE_MISS_TRT_LOCK) or
+                            (r_write_fsm.read() == WRITE_INVAL_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_WRITE;
+
+                    else if((r_cas_fsm.read() == CAS_MISS_TRT_LOCK) or
+                            (r_cas_fsm.read() == CAS_BC_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_CAS;
+                }
+                break;
+
+                ////////////////////////
+            case ALLOC_TRT_XRAM_RSP:
+                if(((r_xram_rsp_fsm.read()  != XRAM_RSP_DIR_LOCK)  or
+                            (r_alloc_dir_fsm.read() != ALLOC_DIR_XRAM_RSP)) and
+                        (r_xram_rsp_fsm.read()  != XRAM_RSP_TRT_COPY)  and
+                        (r_xram_rsp_fsm.read()  != XRAM_RSP_DIR_UPDT)  and
+                        (r_xram_rsp_fsm.read()  != XRAM_RSP_IVT_LOCK))
+                {
+                    if((r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE) or
+                            (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ))
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
+
+                    else if( r_config_fsm.read() == CONFIG_TRT_LOCK ) 
+                        r_alloc_trt_fsm = ALLOC_TRT_CONFIG;
+
+                    else if (r_cleanup_fsm.read() == CLEANUP_MISS_IXR_REQ)
+                        r_alloc_trt_fsm = ALLOC_TRT_CLEANUP;
+
+                    else if(r_read_fsm.read() == READ_TRT_LOCK)
+                        r_alloc_trt_fsm = ALLOC_TRT_READ;
+
+                    else if((r_write_fsm.read() == WRITE_MISS_TRT_LOCK) or
+                            (r_write_fsm.read() == WRITE_INVAL_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_WRITE;
+
+                    else if((r_cas_fsm.read() == CAS_MISS_TRT_LOCK) or
+                            (r_cas_fsm.read() == CAS_BC_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_CAS;
+
+                    else if((r_ixr_cmd_fsm.read() == IXR_CMD_READ_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_WRITE_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CAS_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_XRAM_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CLEANUP_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CONFIG_TRT) )
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_CMD;
+
+                    else
+                        m_cpt_trt_unused++;
+                }
+                else
+                    m_cpt_xram_rsp_fsm_trt_used++;
+                break;
+
+                ////////////////////////
+            case ALLOC_TRT_IXR_RSP:
+                if((r_ixr_rsp_fsm.read() != IXR_RSP_TRT_ERASE) and
+                        (r_ixr_rsp_fsm.read() != IXR_RSP_TRT_READ))
+                {
+                    if( r_config_fsm.read() == CONFIG_TRT_LOCK ) 
+                        r_alloc_trt_fsm = ALLOC_TRT_CONFIG;
+
+                    else if (r_cleanup_fsm.read() == CLEANUP_MISS_IXR_REQ)
+                        r_alloc_trt_fsm = ALLOC_TRT_CLEANUP;
+
+                    else if(r_read_fsm.read() == READ_TRT_LOCK)
+                        r_alloc_trt_fsm = ALLOC_TRT_READ;
+
+                    else if((r_write_fsm.read() == WRITE_MISS_TRT_LOCK) ||
+                            (r_write_fsm.read() == WRITE_INVAL_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_WRITE;
+
+                    else if((r_cas_fsm.read() == CAS_MISS_TRT_LOCK) ||
+                            (r_cas_fsm.read() == CAS_BC_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_CAS;
+
+                    else if((r_ixr_cmd_fsm.read() == IXR_CMD_READ_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_WRITE_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CAS_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_XRAM_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CLEANUP_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CONFIG_TRT) )
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_CMD;
+
+                    else if((r_xram_rsp_fsm.read()  == XRAM_RSP_DIR_LOCK) &&
+                            (r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP))
+                        r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
+
+                    else
+                        m_cpt_trt_unused++;
+                }
+                else
+                    m_cpt_ixr_fsm_trt_used++;
+                break;
+
+                //////////////////////
+            case ALLOC_TRT_CONFIG:
+                if((r_config_fsm.read() != CONFIG_TRT_LOCK) and
+                        (r_config_fsm.read() != CONFIG_TRT_SET))
+                {
+                    if (r_cleanup_fsm.read() == CLEANUP_MISS_IXR_REQ)
+                        r_alloc_trt_fsm = ALLOC_TRT_CLEANUP;
+
+                    else if(r_read_fsm.read() == READ_TRT_LOCK)
+                        r_alloc_trt_fsm = ALLOC_TRT_READ;
+
+                    else if((r_write_fsm.read() == WRITE_MISS_TRT_LOCK) or
+                            (r_write_fsm.read() == WRITE_INVAL_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_WRITE;
+
+                    else if((r_cas_fsm.read() == CAS_MISS_TRT_LOCK) or
+                            (r_cas_fsm.read() == CAS_BC_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_CAS;
+
+                    else if((r_ixr_cmd_fsm.read() == IXR_CMD_READ_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_WRITE_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CAS_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_XRAM_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CLEANUP_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CONFIG_TRT) )
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_CMD;
+
+                    else if((r_xram_rsp_fsm.read()  == XRAM_RSP_DIR_LOCK) and
+                            (r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP))
+                        r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
+
+                    else if((r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE) or
+                            (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ))
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
+                }
+                break;
+
+                ////////////////////////
+            case ALLOC_TRT_CLEANUP:
+                if(r_cleanup_fsm.read() != CLEANUP_MISS_IXR_REQ)
+                {
+                    if(r_read_fsm.read() == READ_TRT_LOCK)
+                        r_alloc_trt_fsm = ALLOC_TRT_READ;
+
+                    else if((r_write_fsm.read() == WRITE_MISS_TRT_LOCK) or
+                            (r_write_fsm.read() == WRITE_INVAL_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_WRITE;
+
+                    else if((r_cas_fsm.read() == CAS_MISS_TRT_LOCK) or
+                            (r_cas_fsm.read() == CAS_BC_TRT_LOCK))
+                        r_alloc_trt_fsm = ALLOC_TRT_CAS;
+
+                    else if((r_ixr_cmd_fsm.read() == IXR_CMD_READ_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_WRITE_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CAS_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_XRAM_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CLEANUP_TRT) or
+                            (r_ixr_cmd_fsm.read() == IXR_CMD_CONFIG_TRT) )
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_CMD;
+
+                    else if((r_xram_rsp_fsm.read()  == XRAM_RSP_DIR_LOCK) and
+                            (r_alloc_dir_fsm.read() == ALLOC_DIR_XRAM_RSP))
+                        r_alloc_trt_fsm = ALLOC_TRT_XRAM_RSP;
+
+                    else if((r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE) ||
+                            (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ))
+                        r_alloc_trt_fsm = ALLOC_TRT_IXR_RSP;
+
+                    else if( r_config_fsm.read() == CONFIG_TRT_LOCK ) 
+                        r_alloc_trt_fsm = ALLOC_TRT_CONFIG;
+                }
+                break;
+
+
+        } // end switch alloc_trt_fsm
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    ALLOC_HEAP FSM
+        ////////////////////////////////////////////////////////////////////////////////////
+        // The ALLOC_HEAP FSM allocates the access to the heap
+        // with a round robin priority between 6 user FSMs :
+        // The cyclic ordering is READ > WRITE > CAS > CLEANUP > MUTLI_ACK > XRAM_RSP > CONFIG
+        // The ressource is always allocated.
+        /////////////////////////////////////////////////////////////////////////////////////
+
+        switch(r_alloc_heap_fsm.read())
+        {
+            ////////////////////
+            case ALLOC_HEAP_RESET:
+                // Initializes the heap one ENTRY each cycle.
+
+                r_alloc_heap_reset_cpt.write(r_alloc_heap_reset_cpt.read() + 1);
+
+                if(r_alloc_heap_reset_cpt.read() == (m_heap_size-1))
+                {
+                    m_heap.init();
+
+                    r_alloc_heap_fsm = ALLOC_HEAP_READ;
+                }
+                break;
+
+                ////////////////////
+            case ALLOC_HEAP_READ:
+                if((r_read_fsm.read() != READ_HEAP_REQ) and
+                   (r_read_fsm.read() != READ_HEAP_LOCK) and
+                   (r_read_fsm.read() != READ_HEAP_ERASE) and
+                   (r_read_fsm.read() != READ_INVAL_HEAP_REQ) and
+                   (r_read_fsm.read() != READ_INVAL_HEAP_ERASE)) 
+                {
+                    if(r_write_fsm.read() == WRITE_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
+
+                    else if(r_cas_fsm.read() == CAS_MULTI_INVAL_HEAP_LOCK)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CAS;
+
+                    else if(r_cleanup_fsm.read() == CLEANUP_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
+                
+                    else if(r_multi_ack_fsm.read() == MULTI_ACK_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_MULTI_ACK;
+
+                    else if(r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
+
+                    else if(r_config_fsm.read() == CONFIG_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CONFIG;
+
+                    else
+                        m_cpt_heap_unused++;
+                }
+                else
+                    m_cpt_read_fsm_heap_used++;
+                break;
+
+                /////////////////////
+            case ALLOC_HEAP_WRITE:
+                if((r_write_fsm.read() != WRITE_HEAP_REQ) and
+                   (r_write_fsm.read() != WRITE_HEAP_ERASE)) 
+                {
+                    if(r_cas_fsm.read() == CAS_MULTI_INVAL_HEAP_LOCK)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CAS;
+
+                    else if(r_cleanup_fsm.read() == CLEANUP_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
+
+                    else if(r_multi_ack_fsm.read() == MULTI_ACK_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_MULTI_ACK;
+
+                    else if(r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
+
+                    else if(r_config_fsm.read() == CONFIG_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CONFIG;
+
+                    else if((r_read_fsm.read() == READ_HEAP_REQ) or
+                            (r_read_fsm.read() == READ_INVAL_HEAP_REQ))
+                        r_alloc_heap_fsm = ALLOC_HEAP_READ;
+
+                    else
+                        m_cpt_heap_unused++;
+                }
+                else
+                    m_cpt_write_fsm_heap_used++;
+                break;
+
+                ////////////////////
+            case ALLOC_HEAP_CAS:
+                if((r_cas_fsm.read() != CAS_MULTI_INVAL_HEAP_LOCK) and
+                        (r_cas_fsm.read() != CAS_MULTI_INVAL_REQ) and
+                        (r_cas_fsm.read() != CAS_HEAP_NEXT))
+                {
+                    if(r_cleanup_fsm.read() == CLEANUP_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
+
+                    else if(r_multi_ack_fsm.read() == MULTI_ACK_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_MULTI_ACK;
+
+                    else if(r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
+
+                    else if(r_config_fsm.read() == CONFIG_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CONFIG;
+
+                    else if((r_read_fsm.read() == READ_HEAP_REQ) or
+                            (r_read_fsm.read() == READ_INVAL_HEAP_REQ))
+                        r_alloc_heap_fsm = ALLOC_HEAP_READ;
+
+                    else if(r_write_fsm.read() == WRITE_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
+
+                    else
+                        m_cpt_heap_unused++;
+                }
+                else
+                    m_cpt_cas_fsm_heap_used++;
+                break;
+
+                ///////////////////////
+            case ALLOC_HEAP_CLEANUP:
+                if((r_cleanup_fsm.read() != CLEANUP_HEAP_REQ) and
+                        (r_cleanup_fsm.read() != CLEANUP_HEAP_LOCK) and
+                        (r_cleanup_fsm.read() != CLEANUP_HEAP_SEARCH) and
+                        (r_cleanup_fsm.read() != CLEANUP_HEAP_CLEAN))
+                {
+                    if(r_multi_ack_fsm.read() == MULTI_ACK_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_MULTI_ACK;
+
+                    else if(r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
+
+                    else if(r_config_fsm.read() == CONFIG_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CONFIG;
+
+                    else if((r_read_fsm.read() == READ_HEAP_REQ) or
+                            (r_read_fsm.read() == READ_INVAL_HEAP_REQ))
+                        r_alloc_heap_fsm = ALLOC_HEAP_READ;
+
+                    else if(r_write_fsm.read() == WRITE_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
+
+                    else if(r_cas_fsm.read() == CAS_MULTI_INVAL_HEAP_LOCK)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CAS;
+
+                    else
+                        m_cpt_heap_unused++;
+                }
+                else
+                    m_cpt_cleanup_fsm_heap_used++;
+                break;
+
+                ////////////////////////
+             case ALLOC_HEAP_MULTI_ACK:
+                if((r_multi_ack_fsm.read() != MULTI_ACK_HEAP_REQ) and
+                        (r_multi_ack_fsm.read() != MULTI_ACK_HEAP_LOCK)) 
+                {
+                    if(r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
+
+                    else if(r_config_fsm.read() == CONFIG_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CONFIG;
+
+                    else if((r_read_fsm.read() == READ_HEAP_REQ) or
+                            (r_read_fsm.read() == READ_INVAL_HEAP_REQ))
+                        r_alloc_heap_fsm = ALLOC_HEAP_READ;
+
+                    else if(r_write_fsm.read() == WRITE_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
+
+                    else if(r_cas_fsm.read() == CAS_MULTI_INVAL_HEAP_LOCK)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CAS;
+
+                    else if(r_cleanup_fsm.read() == CLEANUP_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
+
+                    else
+                        m_cpt_heap_unused++;
+                }
+                else
+                    m_cpt_cleanup_fsm_heap_used++;
+                break;
+
+                ////////////////////////
+            case ALLOC_HEAP_XRAM_RSP:
+                if((r_xram_rsp_fsm.read() != XRAM_RSP_HEAP_REQ) and
+                        (r_xram_rsp_fsm.read() != XRAM_RSP_HEAP_ERASE))
+                {
+                    if(r_config_fsm.read() == CONFIG_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CONFIG;
+
+                    else if((r_read_fsm.read() == READ_HEAP_REQ) or
+                            (r_read_fsm.read() == READ_INVAL_HEAP_REQ))
+                        r_alloc_heap_fsm = ALLOC_HEAP_READ;
+
+                    else if(r_write_fsm.read() == WRITE_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
+
+                    else if(r_cas_fsm.read() == CAS_MULTI_INVAL_HEAP_LOCK)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CAS;
+
+                    else if(r_cleanup_fsm.read() == CLEANUP_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
+
+                    else if(r_multi_ack_fsm.read() == MULTI_ACK_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_MULTI_ACK;
+
+                    else
+                        m_cpt_heap_unused++;
+
+                }
+                break;
+
+                ///////////////////////
+            case ALLOC_HEAP_CONFIG:
+                if((r_config_fsm.read() != CONFIG_HEAP_REQ) and
+                        (r_config_fsm.read() != CONFIG_HEAP_SCAN))
+                {
+                    if((r_read_fsm.read() == READ_HEAP_REQ) or
+                            (r_read_fsm.read() == READ_INVAL_HEAP_REQ))
+                        r_alloc_heap_fsm = ALLOC_HEAP_READ;
+
+                    else if(r_write_fsm.read() == WRITE_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_WRITE;
+
+                    else if(r_cas_fsm.read() == CAS_MULTI_INVAL_HEAP_LOCK)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CAS;
+
+                    else if(r_cleanup_fsm.read() == CLEANUP_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_CLEANUP;
+
+                    else if(r_multi_ack_fsm.read() == MULTI_ACK_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_MULTI_ACK;
+
+                    else if(r_xram_rsp_fsm.read() == XRAM_RSP_HEAP_REQ)
+                        r_alloc_heap_fsm = ALLOC_HEAP_XRAM_RSP;
+                    else
+                        m_cpt_heap_unused++;
+                }
+                else
+                    m_cpt_xram_rsp_fsm_heap_used++;
+                break;
+
+        } // end switch alloc_heap_fsm
+
+        /////////////////////////////////////////////////////////////////////
+        //    TGT_CMD to READ FIFO
+        /////////////////////////////////////////////////////////////////////
+
+        m_cmd_read_addr_fifo.update(   cmd_read_fifo_get, cmd_read_fifo_put, 
+                p_vci_tgt.address.read() );
+        m_cmd_read_length_fifo.update( cmd_read_fifo_get, cmd_read_fifo_put, 
+                p_vci_tgt.plen.read()>>2 );
+        m_cmd_read_srcid_fifo.update(  cmd_read_fifo_get, cmd_read_fifo_put, 
+                p_vci_tgt.srcid.read() );
+        m_cmd_read_trdid_fifo.update(  cmd_read_fifo_get, cmd_read_fifo_put, 
+                p_vci_tgt.trdid.read() );
+        m_cmd_read_pktid_fifo.update(  cmd_read_fifo_get, cmd_read_fifo_put, 
+                p_vci_tgt.pktid.read() );
+
+        /////////////////////////////////////////////////////////////////////
+        //    TGT_CMD to WRITE FIFO
+        /////////////////////////////////////////////////////////////////////
+
+        m_cmd_write_addr_fifo.update(  cmd_write_fifo_get, cmd_write_fifo_put,
+                (addr_t)p_vci_tgt.address.read() );
+        m_cmd_write_eop_fifo.update(   cmd_write_fifo_get, cmd_write_fifo_put,
+                p_vci_tgt.eop.read() );
+        m_cmd_write_srcid_fifo.update( cmd_write_fifo_get, cmd_write_fifo_put,
+                p_vci_tgt.srcid.read() );
+        m_cmd_write_trdid_fifo.update( cmd_write_fifo_get, cmd_write_fifo_put,
+                p_vci_tgt.trdid.read() );
+        m_cmd_write_pktid_fifo.update( cmd_write_fifo_get, cmd_write_fifo_put,
+                p_vci_tgt.pktid.read() );
+        m_cmd_write_data_fifo.update(  cmd_write_fifo_get, cmd_write_fifo_put,
+                p_vci_tgt.wdata.read() );
+        m_cmd_write_be_fifo.update(    cmd_write_fifo_get, cmd_write_fifo_put,
+                p_vci_tgt.be.read() );
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    TGT_CMD to CAS FIFO
+        ////////////////////////////////////////////////////////////////////////////////////
+
+        m_cmd_cas_addr_fifo.update(  cmd_cas_fifo_get, cmd_cas_fifo_put,
+                (addr_t)p_vci_tgt.address.read() );
+        m_cmd_cas_eop_fifo.update(   cmd_cas_fifo_get, cmd_cas_fifo_put,
+                p_vci_tgt.eop.read() );
+        m_cmd_cas_srcid_fifo.update( cmd_cas_fifo_get, cmd_cas_fifo_put,
+                p_vci_tgt.srcid.read() );
+        m_cmd_cas_trdid_fifo.update( cmd_cas_fifo_get, cmd_cas_fifo_put,
+                p_vci_tgt.trdid.read() );
+        m_cmd_cas_pktid_fifo.update( cmd_cas_fifo_get, cmd_cas_fifo_put,
+                p_vci_tgt.pktid.read() );
+        m_cmd_cas_wdata_fifo.update( cmd_cas_fifo_get, cmd_cas_fifo_put,
+                p_vci_tgt.wdata.read() );
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    CC_RECEIVE to CLEANUP FIFO
+        ////////////////////////////////////////////////////////////////////////////////////
+
+        if(cc_receive_to_cleanup_fifo_put)
+        {
+            if(cc_receive_to_cleanup_fifo_get)
+            {
+                m_cc_receive_to_cleanup_fifo.put_and_get( ((uint64_t)(p_dspin_p2m.eop.read()&0x1) << 32) | p_dspin_p2m.data.read() );
+            }
+            else
+            {
+                m_cc_receive_to_cleanup_fifo.simple_put( ((uint64_t)(p_dspin_p2m.eop.read()&0x1) << 32) | p_dspin_p2m.data.read() );
+            }
+        }
+        else
+        {
+            if(cc_receive_to_cleanup_fifo_get)
+            {
+                m_cc_receive_to_cleanup_fifo.simple_get();
+            }
+        }
+        //m_cc_receive_to_cleanup_fifo.update( cc_receive_to_cleanup_fifo_get,
+        //                                     cc_receive_to_cleanup_fifo_put, 
+        //                                     p_dspin_p2m.data.read() );
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    CC_RECEIVE to MULTI_ACK FIFO
+        ////////////////////////////////////////////////////////////////////////////////////
+
+        if(cc_receive_to_multi_ack_fifo_put)
+        {
+            if(cc_receive_to_multi_ack_fifo_get)
+            {
+                m_cc_receive_to_multi_ack_fifo.put_and_get( ((uint64_t)(p_dspin_p2m.eop.read()&0x1) << 32) | p_dspin_p2m.data.read() );
+            }
+            else
+            {
+                m_cc_receive_to_multi_ack_fifo.simple_put( ((uint64_t)(p_dspin_p2m.eop.read()&0x1) << 32) | p_dspin_p2m.data.read() );
+            }
+        }
+        else
+        {
+            if(cc_receive_to_multi_ack_fifo_get)
+            {
+                m_cc_receive_to_multi_ack_fifo.simple_get();
+            }
+        }
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    READ to CC_SEND FIFO
+        ////////////////////////////////////////////////////////////////////////////////////
+
+        m_read_to_cc_send_inst_fifo.update( read_to_cc_send_fifo_get, read_to_cc_send_fifo_put,
+                read_to_cc_send_fifo_inst );
+        m_read_to_cc_send_srcid_fifo.update( read_to_cc_send_fifo_get, read_to_cc_send_fifo_put,
+                read_to_cc_send_fifo_srcid );
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    WRITE to CC_SEND FIFO
+        ////////////////////////////////////////////////////////////////////////////////////
+
+        m_write_to_cc_send_inst_fifo.update( write_to_cc_send_fifo_get, write_to_cc_send_fifo_put,
+                write_to_cc_send_fifo_inst );
+        m_write_to_cc_send_srcid_fifo.update( write_to_cc_send_fifo_get, write_to_cc_send_fifo_put,
+                write_to_cc_send_fifo_srcid );
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    CONFIG to CC_SEND FIFO
+        ////////////////////////////////////////////////////////////////////////////////////
+
+        m_config_to_cc_send_inst_fifo.update( config_to_cc_send_fifo_get, config_to_cc_send_fifo_put,
+                config_to_cc_send_fifo_inst );
+        m_config_to_cc_send_srcid_fifo.update( config_to_cc_send_fifo_get, config_to_cc_send_fifo_put,
+                config_to_cc_send_fifo_srcid );
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    XRAM_RSP to CC_SEND FIFO
+        ////////////////////////////////////////////////////////////////////////////////////
+
+        m_xram_rsp_to_cc_send_inst_fifo.update( xram_rsp_to_cc_send_fifo_get, xram_rsp_to_cc_send_fifo_put,
+                xram_rsp_to_cc_send_fifo_inst );
+        m_xram_rsp_to_cc_send_srcid_fifo.update( xram_rsp_to_cc_send_fifo_get, xram_rsp_to_cc_send_fifo_put,
+                xram_rsp_to_cc_send_fifo_srcid );
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //    CAS to CC_SEND FIFO
+        ////////////////////////////////////////////////////////////////////////////////////
+
+        m_cas_to_cc_send_inst_fifo.update( cas_to_cc_send_fifo_get, cas_to_cc_send_fifo_put,
+                cas_to_cc_send_fifo_inst );
+        m_cas_to_cc_send_srcid_fifo.update( cas_to_cc_send_fifo_get, cas_to_cc_send_fifo_put,
+                cas_to_cc_send_fifo_srcid );
+        m_cpt_cycles++;
+
+        ////////////////////////////////////////////////////////////////////////////////////
+        //            Update r_config_rsp_lines counter.
+        // The three sources of (increment / decrement) are CONFIG / CLEANUP / IXR_RSP FSMs
+        ////////////////////////////////////////////////////////////////////////////////////
+        if ( config_rsp_lines_incr and not 
+             (config_rsp_lines_cleanup_decr or config_rsp_lines_ixr_rsp_decr) )
+        {
+            r_config_rsp_lines = r_config_rsp_lines.read() + 1;
+        }
+        if ( not config_rsp_lines_incr and  
+             (config_rsp_lines_cleanup_decr or config_rsp_lines_ixr_rsp_decr) )
+        {
+            r_config_rsp_lines = r_config_rsp_lines.read() - 1;
+        }
+
+
+//        m_cache_data.read_line( 0,
+//                                0x40,
+//                                r_debug_data);
+//#if DEBUG_MEMC_MULTI_ACK
+//                    if(m_debug)
+//                        std::cout << "  <MEMC " << name() << " DEBUG DATA>"
+//                            << " / data0  = "  << r_debug_data[0].read()
+//                            << " / data1  = "  << r_debug_data[1].read()
+//                            << std::endl;
+//#endif
+
+
+    } // end transition()
+
+    /////////////////////////////
+    tmpl(void)::genMoore()
+        /////////////////////////////
+    {
+#if MONITOR_MEMCACHE_FSM == 1
+        p_read_fsm.write        (r_read_fsm.read()       );
+        p_write_fsm.write       (r_write_fsm.read()      );
+        p_xram_rsp_fsm.write    (r_xram_rsp_fsm.read()   );
+        p_cas_fsm.write         (r_cas_fsm.read()        );
+        p_cleanup_fsm.write     (r_cleanup_fsm.read()    );
+        p_config_fsm.write      (r_config_fsm.read()     );
+        p_alloc_heap_fsm.write  (r_alloc_heap_fsm.read() );
+        p_alloc_dir_fsm.write   (r_alloc_dir_fsm.read()  );
+        p_alloc_trt_fsm.write   (r_alloc_trt_fsm.read()  );
+//        p_alloc_upt_fsm.write   (r_alloc_upt_fsm.read()  );
+        p_alloc_ivt_fsm.write   (r_alloc_ivt_fsm.read()  );
+        p_tgt_cmd_fsm.write     (r_tgt_cmd_fsm.read()    );
+        p_tgt_rsp_fsm.write     (r_tgt_rsp_fsm.read()    );
+        p_ixr_cmd_fsm.write     (r_ixr_cmd_fsm.read()    );
+        p_ixr_rsp_fsm.write     (r_ixr_rsp_fsm.read()    );
+        p_cc_send_fsm.write     (r_cc_send_fsm.read()    );
+        p_cc_receive_fsm.write  (r_cc_receive_fsm.read() );
+        p_multi_ack_fsm.write   (r_multi_ack_fsm.read()  );
+#endif
+
+        ////////////////////////////////////////////////////////////
+        // Command signals on the p_vci_ixr port
+        ////////////////////////////////////////////////////////////
+        // DATA width is 8 bytes
+        // The following values are not transmitted to XRAM
+        //   p_vci_ixr.be 
+        //   p_vci_ixr.pktid  
+        //   p_vci_ixr.cons 
+        //   p_vci_ixr.wrap 
+        //   p_vci_ixr.contig 
+        //   p_vci_ixr.clen 
+        //   p_vci_ixr.cfixed 
+
+        p_vci_ixr.plen    = 64;
+        p_vci_ixr.srcid   = m_srcid_x;
+        p_vci_ixr.trdid   = r_ixr_cmd_trdid.read();
+        p_vci_ixr.address = (addr_t)r_ixr_cmd_address.read() + (r_ixr_cmd_word.read()<<2);
+        p_vci_ixr.be      = 0xFF; 
+        p_vci_ixr.pktid   = 0;
+        p_vci_ixr.cons    = false;
+        p_vci_ixr.wrap    = false;
+        p_vci_ixr.contig  = true;
+        p_vci_ixr.clen    = 0;
+        p_vci_ixr.cfixed  = false;
+
+        if ( (r_ixr_cmd_fsm.read() == IXR_CMD_READ_SEND) or
+                (r_ixr_cmd_fsm.read() == IXR_CMD_WRITE_SEND) or
+                (r_ixr_cmd_fsm.read() == IXR_CMD_CAS_SEND) or
+                (r_ixr_cmd_fsm.read() == IXR_CMD_XRAM_SEND) or
+                (r_ixr_cmd_fsm.read() == IXR_CMD_CONFIG_SEND) )
+        {
+            p_vci_ixr.cmdval    = true;
+
+            if ( r_ixr_cmd_get.read() )  // GET
+            {
+                p_vci_ixr.cmd     = vci_param_ext::CMD_READ;
+                p_vci_ixr.wdata   = 0;
+                p_vci_ixr.eop     = true;
+            }
+            else                         // PUT
+            {
+                size_t word       = r_ixr_cmd_word.read();
+                p_vci_ixr.cmd     = vci_param_ext::CMD_WRITE;
+                p_vci_ixr.wdata   = ((wide_data_t)(r_ixr_cmd_wdata[word].read()))  |
+                    ((wide_data_t)(r_ixr_cmd_wdata[word+1].read()) << 32);
+                p_vci_ixr.eop     = (word == (m_words-2));
+            }
+        }
+        else if (r_ixr_cmd_fsm.read() == IXR_CMD_CLEANUP_DATA_SEND)
+        {
+            p_vci_ixr.cmd     = vci_param_ext::CMD_WRITE;
+            p_vci_ixr.cmdval  = true;
+            /*p_vci_ixr.address = (addr_t)((r_cleanup_to_ixr_cmd_nline.read() * m_words + 
+              r_ixr_cmd_word.read()) * 4);*/
+            p_vci_ixr.address = (addr_t)r_ixr_cmd_address.read() + (r_ixr_cmd_word.read()<<2);
+            p_vci_ixr.wdata   = ((wide_data_t)(r_ixr_cmd_wdata[r_ixr_cmd_word.read()].read()) | 
+                    ((wide_data_t)(r_ixr_cmd_wdata[r_ixr_cmd_word.read() + 1].read()) << 32));
+            p_vci_ixr.trdid   = r_cleanup_to_ixr_cmd_index.read();
+            p_vci_ixr.eop     = (r_ixr_cmd_word == (m_words - 2));
+        }
+
+        else
+        {
+            p_vci_ixr.cmdval    = false;
+        }
+
+        ////////////////////////////////////////////////////
+        // Response signals on the p_vci_ixr port
+        ////////////////////////////////////////////////////
+
+        if( (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_READ) or
+                (r_ixr_rsp_fsm.read() == IXR_RSP_TRT_ERASE) )
+        { 
+            p_vci_ixr.rspack = (r_alloc_trt_fsm.read() == ALLOC_TRT_IXR_RSP);
+        }
+        else if (r_ixr_rsp_fsm.read() == IXR_RSP_ACK)
+        {
+            p_vci_ixr.rspack = true;
+        }
+        else // r_ixr_rsp_fsm == IXR_RSP_IDLE
+        {
+            p_vci_ixr.rspack = false;
+        }
+
+        ////////////////////////////////////////////////////
+        // Command signals on the p_vci_tgt port
+        ////////////////////////////////////////////////////
+
+        switch((tgt_cmd_fsm_state_e) r_tgt_cmd_fsm.read())
+        {
+            case TGT_CMD_IDLE:
+                p_vci_tgt.cmdack = false;
+                break;
+
+            case TGT_CMD_CONFIG:
+            case TGT_CMD_ERROR:
+                p_vci_tgt.cmdack = not r_tgt_cmd_to_tgt_rsp_req.read();
+                break;
+
+            case TGT_CMD_READ:
+                p_vci_tgt.cmdack = m_cmd_read_addr_fifo.wok();
+                break;
+
+            case TGT_CMD_WRITE:
+                p_vci_tgt.cmdack = m_cmd_write_addr_fifo.wok();
+                break;
+
+            case TGT_CMD_CAS:
+                p_vci_tgt.cmdack = m_cmd_cas_addr_fifo.wok();
+                break;
+        }
+
+        ////////////////////////////////////////////////////
+        // Response signals on the p_vci_tgt port
+        ////////////////////////////////////////////////////
+
+        switch(r_tgt_rsp_fsm.read())
+        {
+            case TGT_RSP_CONFIG_IDLE:
+            case TGT_RSP_TGT_CMD_IDLE:
+            case TGT_RSP_READ_IDLE:
+            case TGT_RSP_WRITE_IDLE:
+            case TGT_RSP_CAS_IDLE:
+            case TGT_RSP_XRAM_IDLE:
+            case TGT_RSP_MULTI_ACK_IDLE:
+            case TGT_RSP_CLEANUP_IDLE:
+                {
+                    p_vci_tgt.rspval  = false;
+                    p_vci_tgt.rsrcid  = 0;
+                    p_vci_tgt.rdata   = 0;
+                    p_vci_tgt.rpktid  = 0;
+                    p_vci_tgt.rtrdid  = 0;
+                    p_vci_tgt.rerror  = 0;
+                    p_vci_tgt.reop    = false;
+                    break;
+                }
+            case TGT_RSP_CONFIG:
+                {
+                    p_vci_tgt.rspval  = true;
+                    p_vci_tgt.rdata   = 0;
+                    p_vci_tgt.rsrcid  = r_config_to_tgt_rsp_srcid.read();
+                    p_vci_tgt.rtrdid  = r_config_to_tgt_rsp_trdid.read();
+                    p_vci_tgt.rpktid  = r_config_to_tgt_rsp_pktid.read();
+                    p_vci_tgt.rerror  = r_config_to_tgt_rsp_error.read();
+                    p_vci_tgt.reop    = true;
+
+                    break;
+                }
+
+            case TGT_RSP_TGT_CMD:
+                {
+                    p_vci_tgt.rspval  = true;
+                    p_vci_tgt.rdata   = r_tgt_cmd_to_tgt_rsp_rdata.read();
+                    p_vci_tgt.rsrcid  = r_tgt_cmd_to_tgt_rsp_srcid.read();
+                    p_vci_tgt.rtrdid  = r_tgt_cmd_to_tgt_rsp_trdid.read();
+                    p_vci_tgt.rpktid  = r_tgt_cmd_to_tgt_rsp_pktid.read();
+                    p_vci_tgt.rerror  = r_tgt_cmd_to_tgt_rsp_error.read();
+                    p_vci_tgt.reop    = true;
+
+                    break;
+                }
+
+            case TGT_RSP_READ:
+                {
+                    uint32_t last_word_idx = r_read_to_tgt_rsp_word.read() + r_read_to_tgt_rsp_length - 1;
+                    bool     is_last_word  = (r_tgt_rsp_cpt.read() == last_word_idx);
+                    bool     is_ll         = ((r_read_to_tgt_rsp_pktid.read() & 0x7) == TYPE_LL);
+
+                    p_vci_tgt.rspval  = true;
+
+                    if ( is_ll and not r_tgt_rsp_key_sent.read() )
+                    {
+                        // LL response first flit
+                        p_vci_tgt.rdata = r_read_to_tgt_rsp_ll_key.read();
+                    }
+                    else
+                    {
+                        // LL response second flit or READ response
+                        p_vci_tgt.rdata = r_read_to_tgt_rsp_data[r_tgt_rsp_cpt.read()].read();
+                    }
+
+                    p_vci_tgt.rsrcid  = r_read_to_tgt_rsp_srcid.read();
+                    p_vci_tgt.rtrdid  = r_read_to_tgt_rsp_trdid.read();
+                    p_vci_tgt.rpktid  = r_read_to_tgt_rsp_pktid.read();
+                    p_vci_tgt.rerror  = 0;
+                    p_vci_tgt.reop    = (is_last_word and not is_ll) or (r_tgt_rsp_key_sent.read() and is_ll);
+                    break;
+                }
+
+            case TGT_RSP_WRITE:
+                {
+                    p_vci_tgt.rspval   = true;
+                    if(((r_write_to_tgt_rsp_pktid.read() & 0x7) == TYPE_SC) and r_write_to_tgt_rsp_sc_fail.read())
+                        p_vci_tgt.rdata  = 1;
+                    else
+                        p_vci_tgt.rdata  = 0;
+                    p_vci_tgt.rsrcid   = r_write_to_tgt_rsp_srcid.read();
+                    p_vci_tgt.rtrdid   = r_write_to_tgt_rsp_trdid.read();
+                    p_vci_tgt.rpktid   = r_write_to_tgt_rsp_pktid.read();
+                    p_vci_tgt.rerror   = 0;
+                    p_vci_tgt.reop     = true;
+                    break;
+                }
+            case TGT_RSP_CLEANUP:
+                {
+                    uint32_t last_word_idx = r_cleanup_to_tgt_rsp_first_word.read() + r_cleanup_to_tgt_rsp_length - 1;
+                    bool     is_last_word  = (r_tgt_rsp_cpt.read() == last_word_idx);
+                    bool     is_ll         = ((r_cleanup_to_tgt_rsp_pktid.read() & 0x7) == TYPE_LL);
+
+                    p_vci_tgt.rspval   = true;
+                    if (is_ll and not r_tgt_rsp_key_sent.read())
+                    {
+                        p_vci_tgt.rdata   = r_cleanup_to_tgt_rsp_ll_key.read();
+                    }
+                    else if ( not r_cleanup_to_tgt_rsp_type.read())
+                    {
+                        p_vci_tgt.rdata    = r_cleanup_to_tgt_rsp_data[r_tgt_rsp_cpt.read()].read();
+                    }
+                    else  //if the CLEANUP fsm sends a SC_RSP, then it is a success (and it caused an inval)
+                    {
+                        p_vci_tgt.rdata    = 0;
+                    }
+                    p_vci_tgt.rsrcid   = r_cleanup_to_tgt_rsp_srcid.read();
+                    p_vci_tgt.rtrdid   = r_cleanup_to_tgt_rsp_trdid.read();
+                    p_vci_tgt.rpktid   = r_cleanup_to_tgt_rsp_pktid.read();
+                    p_vci_tgt.rerror   = 0; // Can be a CAS rsp
+                    p_vci_tgt.reop     = r_cleanup_to_tgt_rsp_type.read() or ((is_last_word and not is_ll) or
+                            (r_tgt_rsp_key_sent.read() and     is_ll));
+                    break;
+                }
+
+            case TGT_RSP_CAS:
+                {
+                    p_vci_tgt.rspval   = true;
+                    p_vci_tgt.rdata    = r_cas_to_tgt_rsp_data.read();
+                    p_vci_tgt.rsrcid   = r_cas_to_tgt_rsp_srcid.read();
+                    p_vci_tgt.rtrdid   = r_cas_to_tgt_rsp_trdid.read();
+                    p_vci_tgt.rpktid   = r_cas_to_tgt_rsp_pktid.read();
+                    p_vci_tgt.rerror   = 0;
+                    p_vci_tgt.reop     = true;
+                    break;
+                }
+            case TGT_RSP_XRAM:
+                {
+                    uint32_t last_word_idx = r_xram_rsp_to_tgt_rsp_word.read() + r_xram_rsp_to_tgt_rsp_length.read() - 1;
+                    bool     is_last_word  = (r_tgt_rsp_cpt.read() == last_word_idx);
+                    bool     is_ll         = ((r_xram_rsp_to_tgt_rsp_pktid.read() & 0x7) == TYPE_LL);
+                    bool     is_error      = r_xram_rsp_to_tgt_rsp_rerror.read();
+
+                    p_vci_tgt.rspval  = true;
+
+                    if( is_ll and not r_tgt_rsp_key_sent.read() ) 
+                    {
+                        // LL response first flit
+                        p_vci_tgt.rdata = r_xram_rsp_to_tgt_rsp_ll_key.read();
+                    }
+                    else 
+                    {
+                        // LL response second flit or READ response
+                        p_vci_tgt.rdata = r_xram_rsp_to_tgt_rsp_data[r_tgt_rsp_cpt.read()].read();
+                    }
+
+                    p_vci_tgt.rsrcid  = r_xram_rsp_to_tgt_rsp_srcid.read();
+                    p_vci_tgt.rtrdid  = r_xram_rsp_to_tgt_rsp_trdid.read();
+                    p_vci_tgt.rpktid  = r_xram_rsp_to_tgt_rsp_pktid.read();
+                    p_vci_tgt.rerror  = is_error;
+                    p_vci_tgt.reop    = (((is_last_word or is_error) and not is_ll) or
+                            (r_tgt_rsp_key_sent.read() and     is_ll));
+
+                    break;
+                }
+
+            case TGT_RSP_MULTI_ACK:
+                {
+                    uint32_t last_word_idx = r_multi_ack_to_tgt_rsp_word.read() +
+                                               r_multi_ack_to_tgt_rsp_length.read() - 1;
+                    bool     is_last_word  = (r_tgt_rsp_cpt.read() == last_word_idx);
+                    bool     is_ll         = ((r_multi_ack_to_tgt_rsp_pktid.read() & 0x7) == TYPE_LL);
+                    
+                    p_vci_tgt.rspval   = true;
+
+                    if(is_ll and not r_tgt_rsp_key_sent.read())
+                    {
+                        p_vci_tgt.rdata = r_cleanup_to_tgt_rsp_ll_key.read();
+                    }
+                    else
+                    {
+                        p_vci_tgt.rdata = r_multi_ack_to_tgt_rsp_data[r_tgt_rsp_cpt.read()].read();
+                    } 
+                    p_vci_tgt.rsrcid   = r_multi_ack_to_tgt_rsp_srcid.read();
+                    p_vci_tgt.rtrdid   = r_multi_ack_to_tgt_rsp_trdid.read();
+                    p_vci_tgt.rpktid   = r_multi_ack_to_tgt_rsp_pktid.read();
+                    p_vci_tgt.rerror   = 0;
+                    p_vci_tgt.reop     =((is_last_word and not is_ll) or
+                            (r_tgt_rsp_key_sent.read() and     is_ll));
+                    break;
+                }
+        } // end switch r_tgt_rsp_fsm
+
+        ////////////////////////////////////////////////////////////////////
+        //  p_dspin_m2p port (CC_SEND FSM)
+        ////////////////////////////////////////////////////////////////////
+
+        p_dspin_m2p.write = false;
+        p_dspin_m2p.eop   = false;
+        p_dspin_m2p.data  = 0;
+
+        switch(r_cc_send_fsm.read())
+        {
+            ///////////////////////////
+            case CC_SEND_CONFIG_IDLE:
+            case CC_SEND_XRAM_RSP_IDLE:
+            case CC_SEND_WRITE_IDLE:
+            case CC_SEND_CAS_IDLE:
+                {
+                    break;
+                }
+                ////////////////////////////////
+            case CC_SEND_CONFIG_INVAL_HEADER:
+                {
+                    uint8_t multi_inval_type;
+                    if(m_config_to_cc_send_inst_fifo.read())
+                    {
+                        multi_inval_type = DspinDhccpParam::TYPE_MULTI_INVAL_INST;
+                    }
+                    else
+                    {
+                        multi_inval_type = DspinDhccpParam::TYPE_MULTI_INVAL_DATA;
+                    }
+
+                    uint64_t flit = 0;
+                    uint64_t dest = m_config_to_cc_send_srcid_fifo.read() <<
+                        (DspinDhccpParam::SRCID_WIDTH - vci_param_int::S);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            dest,
+                            DspinDhccpParam::MULTI_INVAL_DEST);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            m_cc_global_id ,
+                            DspinDhccpParam::MULTI_INVAL_SRCID);
+
+                    // MODIFIED FOR CONFIG INVAL (solution 1 bit in flit multi_inval)
+                    DspinDhccpParam::dspin_set( flit,
+                            1,
+                            DspinDhccpParam::MULTI_INVAL_IS_CONFIG);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            r_config_to_cc_send_trdid.read(),
+                            DspinDhccpParam::MULTI_INVAL_UPDT_INDEX);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            multi_inval_type,
+                            DspinDhccpParam::M2P_TYPE);
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.data  = flit;
+                    break;
+                }
+                ////////////////////////////////
+            case CC_SEND_CONFIG_INVAL_NLINE:
+                {
+                    uint64_t flit = 0;
+                    DspinDhccpParam::dspin_set( flit,
+                            r_config_to_cc_send_nline.read(),
+                            DspinDhccpParam::MULTI_INVAL_NLINE);
+                    p_dspin_m2p.eop   = true;
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.data  = flit;
+                    break;
+                }
+                ///////////////////////////////////
+            case CC_SEND_XRAM_RSP_INVAL_HEADER:
+                {
+                    if(not m_xram_rsp_to_cc_send_inst_fifo.rok()) break;
+
+                    uint8_t multi_inval_type;
+                    if(m_xram_rsp_to_cc_send_inst_fifo.read())
+                    {
+                        multi_inval_type = DspinDhccpParam::TYPE_MULTI_INVAL_INST;
+                    }
+                    else
+                    {
+                        multi_inval_type = DspinDhccpParam::TYPE_MULTI_INVAL_DATA;
+                    }
+
+                    uint64_t flit = 0;
+                    uint64_t dest = m_xram_rsp_to_cc_send_srcid_fifo.read() <<
+                        (DspinDhccpParam::SRCID_WIDTH - vci_param_int::S);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            dest,
+                            DspinDhccpParam::MULTI_INVAL_DEST);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            m_cc_global_id ,
+                            DspinDhccpParam::MULTI_INVAL_SRCID);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            r_xram_rsp_to_cc_send_trdid.read(),
+                            DspinDhccpParam::MULTI_INVAL_UPDT_INDEX);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            multi_inval_type,
+                            DspinDhccpParam::M2P_TYPE);
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.data  = flit;
+                    break;
+                }
+
+                //////////////////////////////////
+            case CC_SEND_XRAM_RSP_INVAL_NLINE:
+                {
+                    uint64_t flit = 0;
+
+                    DspinDhccpParam::dspin_set( flit,
+                            r_xram_rsp_to_cc_send_nline.read(),
+                            DspinDhccpParam::MULTI_INVAL_NLINE);
+                    p_dspin_m2p.eop   = true;
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.data  = flit;
+                    break;
+                }
+
+                /////////////////////////////////////
+            case CC_SEND_CONFIG_BRDCAST_HEADER:
+                {
+                    uint64_t flit = 0;
+
+                    DspinDhccpParam::dspin_set( flit,
+                            m_broadcast_boundaries,
+                            DspinDhccpParam::BROADCAST_BOX);
+                    // MODIFIED FOR CONFIG INVAL (solution 1 bit in flit multi_inval)
+                    DspinDhccpParam::dspin_set( flit,
+                            1,
+                            DspinDhccpParam::MULTI_INVAL_IS_CONFIG);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            m_cc_global_id + 0xff,
+                            DspinDhccpParam::BROADCAST_SRCID);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            1ULL,
+                            DspinDhccpParam::M2P_BC);
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.data  = flit;
+                    break;
+                }
+                /////////////////////////////////////
+            case CC_SEND_XRAM_RSP_BRDCAST_HEADER:
+            case CC_SEND_WRITE_BRDCAST_HEADER:
+            case CC_SEND_CAS_BRDCAST_HEADER:
+                {
+                    uint64_t flit = 0;
+
+                    DspinDhccpParam::dspin_set( flit,
+                            m_broadcast_boundaries,
+                            DspinDhccpParam::BROADCAST_BOX);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            m_cc_global_id + 0xff,
+                            DspinDhccpParam::BROADCAST_SRCID);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            1ULL,
+                            DspinDhccpParam::M2P_BC);
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.data  = flit;
+                    break;
+                }
+                ////////////////////////////////////
+            case CC_SEND_READ_BRDCAST_HEADER:
+                {
+                    uint64_t flit = 0;
+
+                    DspinDhccpParam::dspin_set( flit,
+                            m_broadcast_boundaries,
+                            DspinDhccpParam::BROADCAST_BOX);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            r_read_to_cc_send_srcid.read(),    // send the srcid itself which demands the request getM
+                            DspinDhccpParam::BROADCAST_SRCID);
+
+                    DspinDhccpParam::dspin_set( flit,
+                            1ULL,
+                            DspinDhccpParam::M2P_BC);
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.data  = flit;
+                    break;
+                }
+                ////////////////////////////////////
+            case CC_SEND_XRAM_RSP_BRDCAST_NLINE:
+                {
+                    uint64_t flit = 0;
+                    DspinDhccpParam::dspin_set( flit,
+                            r_xram_rsp_to_cc_send_nline.read(),
+                            DspinDhccpParam::BROADCAST_NLINE);
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.eop   = true;
+                    p_dspin_m2p.data  = flit;
+                    break;
+                }
+                //////////////////////////////////
+            case CC_SEND_CONFIG_BRDCAST_NLINE:
+                {
+                    uint64_t flit = 0;
+                    DspinDhccpParam::dspin_set( flit,
+                            r_config_to_cc_send_nline.read(),
+                            DspinDhccpParam::BROADCAST_NLINE);
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.eop   = true;
+                    p_dspin_m2p.data  = flit;
+                    break;
+                }
+                /////////////////////////////////
+            case CC_SEND_READ_BRDCAST_NLINE:
+                {
+                    uint64_t flit = 0;
+                    DspinDhccpParam::dspin_set( flit,
+                            r_read_to_cc_send_nline.read(),
+                            DspinDhccpParam::BROADCAST_NLINE);
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.eop   = true;
+                    p_dspin_m2p.data  = flit;
+                    break;
+                }
+                /////////////////////////////////
+            case CC_SEND_READ_MULTI_HEADER:
+                {
+                    uint64_t flit = 0;
+
+                    if(not m_read_to_cc_send_inst_fifo.rok()) break;
+                    uint8_t multi_inval_type;
+
+                    uint64_t dest =
+                        m_read_to_cc_send_srcid_fifo.read() <<
+                        (DspinDhccpParam::SRCID_WIDTH - vci_param_int::S);
+
+                    if (m_read_to_cc_send_inst_fifo.read())
+                    {
+                        multi_inval_type = DspinDhccpParam::TYPE_MULTI_INVAL_INST;
+                    }
+                    else
+                    {
+                        multi_inval_type = DspinDhccpParam::TYPE_MULTI_INVAL_DATA;
+                    }
+
+                    DspinDhccpParam::dspin_set(
+                            flit,
+                            dest,
+                            DspinDhccpParam::MULTI_INVAL_DEST);
+
+                    DspinDhccpParam::dspin_set(
+                            flit,
+                            r_read_to_cc_send_srcid.read(),
+                            DspinDhccpParam::MULTI_INVAL_SRCID);
+
+                    if(r_read_to_cc_send_type.read())
+                    {
+                        DspinDhccpParam::dspin_set(
+                                flit,
+                                DspinDhccpParam::TYPE_MULTI_INVAL_DATA,
+                                DspinDhccpParam::M2P_TYPE);
+                    }
+                    else 
+                    {
+                        DspinDhccpParam::dspin_set(
+                                flit,
+                                DspinDhccpParam::TYPE_MULTI_UPDT_DATA,
+                                DspinDhccpParam::M2P_TYPE);
+
+                        DspinDhccpParam::dspin_set(
+                                flit,
+                                r_read_to_cc_send_ivt_index.read(),
+                                DspinDhccpParam::CC_UPDT_IVT_INDEX);
+
+                    }
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.data  = flit;
+
+                    break;
+
+                }
+
+            case CC_SEND_READ_MULTI_NLINE:
+                {
+                    uint64_t flit = 0;
+
+                    DspinDhccpParam::dspin_set(
+                            flit,
+                            r_read_to_cc_send_nline.read(),
+                            DspinDhccpParam::MULTI_INVAL_NLINE);
+
+
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.data  = flit;
+                    p_dspin_m2p.eop   = true;
+
+                    break;
+
+                }
+
+//            case CC_SEND_WRITE_INVAL_HEADER:
+//                {
+//                    uint64_t flit = 0;
+//
+//                    DspinDhccpParam::dspin_set(
+//                            flit,
+//                            r_write_to_cc_send_dest.read(),
+//                            DspinDhccpParam::MULTI_INVAL_DEST);
+//
+//                    DspinDhccpParam::dspin_set(
+//                            flit,
+//                            m_cc_global_id,
+//                            DspinDhccpParam::MULTI_INVAL_SRCID);
+//
+//                    DspinDhccpParam::dspin_set(
+//                            flit,
+//                            DspinDhccpParam::TYPE_MULTI_INVAL_DATA,
+//                            DspinDhccpParam::M2P_TYPE);
+//
+//                    p_dspin_m2p.write = true;
+//                    p_dspin_m2p.data  = flit;
+//
+//                    break;
+//
+//                }
+//
+//            case CC_SEND_WRITE_NCC_INVAL_NLINE:
+//                {
+//                    uint64_t flit = 0;
+//
+//                    DspinDhccpParam::dspin_set(
+//                            flit,
+//                            r_write_to_cc_send_nline.read(),
+//                            DspinDhccpParam::MULTI_INVAL_NLINE);
+//
+//
+//                    p_dspin_m2p.write = true;
+//                    p_dspin_m2p.data  = flit;
+//                    p_dspin_m2p.eop   = true;
+//
+//                    break;
+//
+//                }
+//
+//
+            case CC_SEND_WRITE_BRDCAST_NLINE:
+                {
+                    uint64_t flit = 0;
+                    DspinDhccpParam::dspin_set( flit,
+                            r_write_to_cc_send_nline.read(),
+                            DspinDhccpParam::BROADCAST_NLINE);
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.eop   = true;
+                    p_dspin_m2p.data  = flit;
+                    break;
+                }
+                ///////////////////////////////
+            case CC_SEND_CAS_BRDCAST_NLINE:
+                {
+                    uint64_t flit = 0;
+                    DspinDhccpParam::dspin_set( flit,
+                            r_cas_to_cc_send_nline.read(),
+                            DspinDhccpParam::BROADCAST_NLINE);
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.eop   = true;
+                    p_dspin_m2p.data  = flit;
+                    break;
+                }
+                ///////////////////////////////
+            case CC_SEND_WRITE_INVAL_HEADER:
+                {
+                    if(not m_write_to_cc_send_inst_fifo.rok()) break;
+
+                    uint8_t multi_inval_type;
+                    if(m_write_to_cc_send_inst_fifo.read())
+                    {
+                        multi_inval_type = DspinDhccpParam::TYPE_MULTI_INVAL_INST;
+                    }
+                    else
+                    {
+                        multi_inval_type = DspinDhccpParam::TYPE_MULTI_INVAL_DATA;
+                    }
+
+                    uint64_t flit = 0;
+                    uint64_t dest =
+                        m_write_to_cc_send_srcid_fifo.read() <<
+                        (DspinDhccpParam::SRCID_WIDTH - vci_param_int::S);
+
+                    DspinDhccpParam::dspin_set(
+                            flit,
+                            dest,
+                            DspinDhccpParam::MULTI_INVAL_DEST);
+
+                    DspinDhccpParam::dspin_set(
+                            flit,
+                            m_cc_global_id,
+                            DspinDhccpParam::MULTI_INVAL_SRCID);
+
+                    DspinDhccpParam::dspin_set(
+                            flit,
+                            multi_inval_type,
+                            DspinDhccpParam::M2P_TYPE);
+
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.data  = flit;
+
+                    break;
+                }
+                //////////////////////////////
+            case CC_SEND_WRITE_INVAL_NLINE:
+                {
+                    uint64_t flit = 0;
+
+                  // DspinDhccpParam::dspin_set(
+                  //         flit,
+                  //         r_write_to_cc_send_index.read(),
+                  //         DspinDhccpParam::MULTI_UPDT_WORD_INDEX);
+
+                    DspinDhccpParam::dspin_set(
+                            flit,
+                            r_write_to_cc_send_nline.read(),
+                            DspinDhccpParam::MULTI_UPDT_NLINE);
+
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.eop   = true;
+
+                    p_dspin_m2p.data  = flit;
+
+                    break;
+                }
+//                /////////////////////////////
+//            case CC_SEND_WRITE_UPDT_DATA:
+//                {
+//
+//                    uint8_t multi_updt_cpt  =
+//                        r_cc_send_cpt.read() + r_write_to_cc_send_index.read();
+//
+//                    uint8_t  multi_updt_be   = r_write_to_cleanup_be[multi_updt_cpt].read();
+//                    uint32_t multi_updt_data = r_write_to_cleanup_data[multi_updt_cpt].read();
+//
+//                    uint64_t flit = 0;
+//
+//                    DspinDhccpParam::dspin_set(
+//                            flit,
+//                            multi_updt_be,
+//                            DspinDhccpParam::MULTI_UPDT_BE);
+//
+//                    DspinDhccpParam::dspin_set(
+//                            flit,
+//                            multi_updt_data,
+//                            DspinDhccpParam::MULTI_UPDT_DATA);
+//
+//                    p_dspin_m2p.write = true;
+//                    p_dspin_m2p.eop   = (r_cc_send_cpt.read() == r_write_to_cc_send_count.read());
+//                    p_dspin_m2p.data  = flit;
+//
+//                    break;
+//                }
+                ////////////////////////////
+            case CC_SEND_CAS_INVAL_HEADER:
+                {
+                    if (not m_cas_to_cc_send_inst_fifo.rok()) break;
+
+                    uint8_t multi_inval_type;
+                    if(m_cas_to_cc_send_inst_fifo.read())
+                    {
+                        multi_inval_type = DspinDhccpParam::TYPE_MULTI_INVAL_INST;
+                    }
+                    else
+                    {
+                        multi_inval_type = DspinDhccpParam::TYPE_MULTI_INVAL_DATA;
+                    }
+
+                    uint64_t flit = 0;
+                    uint64_t dest =
+                        m_cas_to_cc_send_srcid_fifo.read() <<
+                        (DspinDhccpParam::SRCID_WIDTH - vci_param_int::S);
+
+                    DspinDhccpParam::dspin_set(
+                            flit,
+                            dest,
+                            DspinDhccpParam::MULTI_UPDT_DEST);
+
+                    DspinDhccpParam::dspin_set(
+                            flit,
+                            m_cc_global_id,
+                            DspinDhccpParam::MULTI_UPDT_SRCID);
+
+                    DspinDhccpParam::dspin_set(
+                            flit,
+                            multi_inval_type,
+                            DspinDhccpParam::M2P_TYPE);
+
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.data  = flit;
+
+                    break;
+                }
+                ////////////////////////////
+            case CC_SEND_CAS_INVAL_NLINE:
+                {
+                    uint64_t flit = 0;
+
+                  //  DspinDhccpParam::dspin_set(
+                  //          flit,
+                  //          r_cas_to_cc_send_index.read(),
+                  //          DspinDhccpParam::MULTI_UPDT_WORD_INDEX);
+
+                    DspinDhccpParam::dspin_set(
+                            flit,
+                            r_cas_to_cc_send_nline.read(),
+                            DspinDhccpParam::MULTI_UPDT_NLINE);
+
+                    p_dspin_m2p.write = true;
+                    p_dspin_m2p.eop   = true;
+                    p_dspin_m2p.data  = flit;
+
+                    break;
+                }
+                ///////////////////////////
+//            case CC_SEND_CAS_UPDT_DATA:
+//                {
+//                    uint64_t flit = 0;
+//
+//                    DspinDhccpParam::dspin_set(
+//                            flit,
+//                            0xF,
+//                            DspinDhccpParam::MULTI_UPDT_BE);
+//
+//                    DspinDhccpParam::dspin_set(
+//                            flit,
+//                            r_cas_to_cc_send_wdata.read(),
+//                            DspinDhccpParam::MULTI_UPDT_DATA);
+//
+//                    p_dspin_m2p.write = true;
+//                    p_dspin_m2p.eop   = not r_cas_to_cc_send_is_long.read();
+//                    p_dspin_m2p.data  = flit;
+//
+//                    break;
+//                }
+//                ////////////////////////////////
+//            case CC_SEND_CAS_UPDT_DATA_HIGH:
+//                {
+//                    uint64_t flit = 0;
+//
+//                    DspinDhccpParam::dspin_set(
+//                            flit,
+//                            0xF,
+//                            DspinDhccpParam::MULTI_UPDT_BE);
+//
+//                    DspinDhccpParam::dspin_set(
+//                            flit,
+//                            r_cas_to_cc_send_wdata_high.read(),
+//                            DspinDhccpParam::MULTI_UPDT_DATA);
+//
+//                    p_dspin_m2p.write = true;
+//                    p_dspin_m2p.eop   = true;
+//                    p_dspin_m2p.data  = flit;
+//
+//                    break;
+//                }
+        }
+
+        ////////////////////////////////////////////////////////////////////
+        //  p_dspin_clack port (CLEANUP FSM)
+        ////////////////////////////////////////////////////////////////////
+
+        if ( r_cleanup_fsm.read() == CLEANUP_SEND_CLACK )
+        {
+            uint8_t cleanup_ack_type;
+            if(r_cleanup_inst.read())
+            {
+                cleanup_ack_type = DspinDhccpParam::TYPE_CLACK_INST;
+            }
+            else
+            {
+                cleanup_ack_type = DspinDhccpParam::TYPE_CLACK_DATA;
+            }
+
+            uint64_t flit = 0;
+            uint64_t dest = r_cleanup_srcid.read() <<
+                (DspinDhccpParam::SRCID_WIDTH - vci_param_int::S);
+
+            DspinDhccpParam::dspin_set(
+                    flit,
+                    dest,
+                    DspinDhccpParam::CLACK_DEST);
+
+            DspinDhccpParam::dspin_set(
+                    flit,
+                    r_cleanup_nline.read() & 0xFFFF,
+                    DspinDhccpParam::CLACK_SET);
+
+            DspinDhccpParam::dspin_set(
+                    flit,
+                    r_cleanup_way_index.read(),
+                    DspinDhccpParam::CLACK_WAY);
+
+            DspinDhccpParam::dspin_set(
+                    flit,
+                    cleanup_ack_type,
+                    DspinDhccpParam::CLACK_TYPE);
+
+            p_dspin_clack.eop   = true;
+            p_dspin_clack.write = true;
+            p_dspin_clack.data  = flit;
+        }
+        else
+        {
+            p_dspin_clack.write = false;
+            p_dspin_clack.eop   = false;
+            p_dspin_clack.data  = 0;
+        }
+        ///////////////////////////////////////////////////////////////////
+        //  p_dspin_p2m port (CC_RECEIVE FSM)
+        ///////////////////////////////////////////////////////////////////
+        //
+        switch(r_cc_receive_fsm.read())
+        {
+            case CC_RECEIVE_IDLE:
+                {
+                    p_dspin_p2m.read = false;
+                    break;
+                }
+            case CC_RECEIVE_CLEANUP:
+            case CC_RECEIVE_CLEANUP_EOP:
+                {
+                    p_dspin_p2m.read = m_cc_receive_to_cleanup_fifo.wok();
+                    break;
+                }
+            case CC_RECEIVE_MULTI_ACK:
+                {
+                    p_dspin_p2m.read = m_cc_receive_to_multi_ack_fifo.wok();
+                    break;
+                }
+        }
+        // end switch r_cc_send_fsm
+    } // end genMoore()
+
+}
+} // end name space
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Index: /branches/MESI/modules/vci_mem_cache/include/soclib/mem_cache.h
===================================================================
--- /branches/MESI/modules/vci_mem_cache/include/soclib/mem_cache.h	(revision 670)
+++ /branches/MESI/modules/vci_mem_cache/include/soclib/mem_cache.h	(revision 670)
@@ -0,0 +1,200 @@
+/*
+ * SOCLIB_LGPL_HEADER_BEGIN
+ * 
+ * This file is part of SoCLib, GNU LGPLv2.1.
+ * 
+ * SoCLib is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 of the License.
+ * 
+ * SoCLib is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with SoCLib; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ * 
+ * SOCLIB_LGPL_HEADER_END
+ *
+ * Copyright (c) UPMC, Lip6, Asim
+ *         alain greiner
+ *
+ * Maintainers: alain
+ */
+#ifndef MEM_CACHE_REGS_H
+#define MEM_CACHE_REGS_H
+
+enum SoclibMemCacheFunc
+{
+    MEMC_CONFIG = 0,
+    MEMC_INSTRM = 1,
+    MEMC_RERROR = 2,
+
+    MEMC_FUNC_SPAN = 0x200
+};
+
+enum SoclibMemCacheConfigRegs
+{
+    MEMC_LOCK,
+    MEMC_ADDR_LO,
+    MEMC_ADDR_HI,
+    MEMC_BUF_LENGTH,
+    MEMC_CMD_TYPE
+};
+
+enum SoclibMemCacheConfigCmd
+{
+    MEMC_CMD_NOP,
+    MEMC_CMD_INVAL,
+    MEMC_CMD_SYNC
+};
+
+///////////////////////////////////////////////////////////
+//  Decoding CONFIG interface commands                   //
+//                                                       //
+//  VCI ADDRESS                                          //
+//  ================================================     //
+//  GLOBAL | LOCAL | ... | FUNC_IDX | REGS_IDX | 00      //
+//   IDX   |  IDX  |     | (3 bits) | (7 bits) |         //
+//  ================================================     //
+//                                                       //
+//  For instrumentation: FUNC_IDX = 0b001                //
+//                                                       //
+//  REGS_IDX                                             //
+//  ============================================         //
+//       Z     |    Y      |    X     |   W              //
+//    (1 bit)  | (2 bits)  | (3 bits) | (1 bit)          //
+//  ============================================         //
+//                                                       //
+//  For configuration: FUNC_IDX = 0b000                  //
+//                                                       //
+//  REGS_IDX                                             //
+//  ============================================         //
+//             RESERVED             |    X     |         //
+//             (4 bits)             | (3 bits) |         //
+//  ============================================         //
+//                                                       //
+//  X : REGISTER INDEX                                   //
+//                                                       //
+//  For WRITE MISS error signaling: FUNC = 0x010         //
+//                                                       //
+//  REGS_IDX                                             //
+//  ============================================         //
+//             RESERVED             |    X     |         //
+//             (4 bits)             | (3 bits) |         //
+//  ============================================         //
+//                                                       //
+//  X : REGISTER INDEX                                   //
+//                                                       //
+///////////////////////////////////////////////////////////
+
+enum SoclibMemCacheInstrRegs {
+    ///////////////////////////////////////////////////////
+    //          DIRECT instrumentation registers         //
+    ///////////////////////////////////////////////////////
+
+    // LOCAL
+
+    MEMC_LOCAL_READ_LO   = 0x00,
+    MEMC_LOCAL_READ_HI   = 0x01,
+    MEMC_LOCAL_WRITE_LO  = 0x02,
+    MEMC_LOCAL_WRITE_HI  = 0x03,
+    MEMC_LOCAL_LL_LO     = 0x04,
+    MEMC_LOCAL_LL_HI     = 0x05,
+    MEMC_LOCAL_SC_LO     = 0x06,
+    MEMC_LOCAL_SC_HI     = 0x07,
+    MEMC_LOCAL_CAS_LO    = 0x08,
+    MEMC_LOCAL_CAS_HI    = 0x09,
+
+    // REMOTE
+
+    MEMC_REMOTE_READ_LO  = 0x10,
+    MEMC_REMOTE_READ_HI  = 0x11,
+    MEMC_REMOTE_WRITE_LO = 0x12,
+    MEMC_REMOTE_WRITE_HI = 0x13,
+    MEMC_REMOTE_LL_LO    = 0x14,
+    MEMC_REMOTE_LL_HI    = 0x15,
+    MEMC_REMOTE_SC_LO    = 0x16,
+    MEMC_REMOTE_SC_HI    = 0x17,
+    MEMC_REMOTE_CAS_LO   = 0x18,
+    MEMC_REMOTE_CAS_HI   = 0x19,
+
+    // COST
+
+    MEMC_COST_READ_LO    = 0x20,
+    MEMC_COST_READ_HI    = 0x21,
+    MEMC_COST_WRITE_LO   = 0x22,
+    MEMC_COST_WRITE_HI   = 0x23,
+    MEMC_COST_LL_LO      = 0x24,
+    MEMC_COST_LL_HI      = 0x25,
+    MEMC_COST_SC_LO      = 0x26,
+    MEMC_COST_SC_HI      = 0x27,
+    MEMC_COST_CAS_LO     = 0x28,
+    MEMC_COST_CAS_HI     = 0x29,
+
+    ///////////////////////////////////////////////////////
+    //       COHERENCE instrumentation registers         //
+    ///////////////////////////////////////////////////////
+
+    // LOCAL
+
+    MEMC_LOCAL_MUPDATE_LO  = 0x40,
+    MEMC_LOCAL_MUPDATE_HI  = 0x41,
+    MEMC_LOCAL_MINVAL_LO   = 0x42,
+    MEMC_LOCAL_MINVAL_HI   = 0x43,
+    MEMC_LOCAL_CLEANUP_LO  = 0x44,
+    MEMC_LOCAL_CLEANUP_HI  = 0x45,
+
+    // REMOTE
+
+    MEMC_REMOTE_MUPDATE_LO = 0x50,
+    MEMC_REMOTE_MUPDATE_HI = 0x51,
+    MEMC_REMOTE_MINVAL_LO  = 0x52,
+    MEMC_REMOTE_MINVAL_HI  = 0x53,
+    MEMC_REMOTE_CLEANUP_LO = 0x54,
+    MEMC_REMOTE_CLEANUP_HI = 0x55,
+
+    // COST
+
+    MEMC_COST_MUPDATE_LO   = 0x60,
+    MEMC_COST_MUPDATE_HI   = 0x61,
+    MEMC_COST_MINVAL_LO    = 0x62,
+    MEMC_COST_MINVAL_HI    = 0x63,
+    MEMC_COST_CLEANUP_LO   = 0x64,
+    MEMC_COST_CLEANUP_HI   = 0x65,
+
+    // TOTAL
+
+    MEMC_TOTAL_MUPDATE_LO  = 0x68,
+    MEMC_TOTAL_MUPDATE_HI  = 0x69,
+    MEMC_TOTAL_MINVAL_LO   = 0x6A,
+    MEMC_TOTAL_MINVAL_HI   = 0x6B,
+    MEMC_TOTAL_BINVAL_LO   = 0x6C,
+    MEMC_TOTAL_BINVAL_HI   = 0x6D,
+};
+
+enum SoclibMemCacheRerrorRegs
+{
+    MEMC_RERROR_ADDR_LO = 0,
+    MEMC_RERROR_ADDR_HI,
+    MEMC_RERROR_SRCID, 
+    MEMC_RERROR_IRQ_RESET,
+    MEMC_RERROR_IRQ_ENABLE
+};
+
+#define MEMC_REG(func,idx) ((func<<7)|idx) 
+
+#endif /* MEM_CACHE_REGS_H */
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
