Index: /trunk/modules/vci_mem_cache/caba/source/include/mem_cache_directory.h
===================================================================
--- /trunk/modules/vci_mem_cache/caba/source/include/mem_cache_directory.h	(revision 448)
+++ /trunk/modules/vci_mem_cache/caba/source/include/mem_cache_directory.h	(revision 449)
@@ -12,4 +12,5 @@
 // to behave in an unpredicted way.
 // TODO Either remove the mechanism from the mem cache or update its behaviour.
+
 #define L1_MULTI_CACHE 0
 
@@ -247,5 +248,5 @@
     // The function returns a copy of a (valid or invalid) entry  
     /////////////////////////////////////////////////////////////////////
-    DirectoryEntry read(const addr_t &address,size_t &way)
+    DirectoryEntry read(const addr_t &address, size_t &way)
     {
 
@@ -277,5 +278,5 @@
     // way arguments. 
     /////////////////////////////////////////////////////////////////////
-    void inval( const size_t &set, const size_t &way )
+    void inval( const size_t &way, const size_t &set )
     {
         m_dir_tab[set][way].init();
@@ -289,22 +290,26 @@
     // The function returns a copy of a (valid or invalid) entry  
     /////////////////////////////////////////////////////////////////////
-    DirectoryEntry read_neutral(const addr_t &address)
+    DirectoryEntry read_neutral( const addr_t &address, 
+                                 size_t*      ret_way,
+                                 size_t*      ret_set )
     {
 
 #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));
+        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
 
-      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].valid;
-        hit = equal && valid;
-        if ( hit ) {			
-          return DirectoryEntry(m_dir_tab[set][i]);
+        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].valid;
+            if ( equal and valid )
+            {
+                *ret_set = set;
+                *ret_way = way; 
+                return DirectoryEntry(m_dir_tab[set][way]);
+            }
         } 
-      }
-      return DirectoryEntry();
+        return DirectoryEntry();
     } // end read_neutral()
 
@@ -406,6 +411,8 @@
     void init()
     {
-      for ( size_t set=0 ; set<m_sets ; set++ ) {
-        for ( size_t way=0 ; way<m_ways ; way++ ) {
+      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();
@@ -688,5 +695,5 @@
         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]);
Index: /trunk/modules/vci_mem_cache/caba/source/include/vci_mem_cache.h
===================================================================
--- /trunk/modules/vci_mem_cache/caba/source/include/vci_mem_cache.h	(revision 448)
+++ /trunk/modules/vci_mem_cache/caba/source/include/vci_mem_cache.h	(revision 449)
@@ -68,11 +68,9 @@
     {
       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;
+      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 */
@@ -390,7 +388,10 @@
 
       // debug variables (for each FSM)
-      bool         m_debug;
-      bool         m_debug_previous_hit;
-      size_t       m_debug_previous_count;
+      bool                 m_debug;
+      bool                 m_debug_previous_valid;
+      size_t               m_debug_previous_count;
+      bool                 m_debug_previous_dirty;
+      sc_signal<data_t>*   m_debug_previous_data;
+      sc_signal<data_t>*   m_debug_data;
 
       bool         m_monitor_ok;
@@ -474,5 +475,5 @@
       void print_stats();
       void print_trace();
-      void copies_monitor(addr_t addr);
+      void cache_monitor(addr_t addr);
       void start_monitor(addr_t addr, addr_t length);
       void stop_monitor();
@@ -482,5 +483,5 @@
       void transition();
       void genMoore();
-      void check_monitor( const char *buf, addr_t addr, data_t data, bool read);
+      void check_monitor(addr_t addr, data_t data, bool read);
 
       // Component attributes
Index: /trunk/modules/vci_mem_cache/caba/source/src/vci_mem_cache.cpp
===================================================================
--- /trunk/modules/vci_mem_cache/caba/source/src/vci_mem_cache.cpp	(revision 448)
+++ /trunk/modules/vci_mem_cache/caba/source/src/vci_mem_cache.cpp	(revision 449)
@@ -518,4 +518,7 @@
     r_cas_rdata                = new sc_signal<data_t>[2];
 
+    // Allocation for debug
+    m_debug_previous_data      = new sc_signal<data_t>[nwords];
+    m_debug_data               = new sc_signal<data_t>[nwords];
 
     SC_METHOD(transition);
@@ -545,6 +548,5 @@
 
 ////////////////////////////////////////////////
-tmpl(void) ::check_monitor( const char  *buf,
-                            addr_t      addr,
+tmpl(void) ::check_monitor( addr_t      addr,
                             data_t      data,
                             bool        read )
@@ -554,8 +556,7 @@
       (addr < m_monitor_base + m_monitor_length))
   {
-    if ( read ) std::cout << " Monitor MEMC Read  ";
-    else        std::cout << " Monitor MEMC Write ";
-    std::cout << buf
-              << " / Address = " << std::hex << addr
+    if ( read ) std::cout << " Monitor MEMC Read ";
+    else        std::cout << " Monitor MEMC Write";
+    std::cout << " / Address = " << std::hex << addr
               << " / Data = " << data
               << " at cycle " << std::dec << m_cpt_cycles << std::endl;
@@ -564,20 +565,43 @@
 
 /////////////////////////////////////////////////////
-tmpl(void) ::copies_monitor(addr_t addr)
+tmpl(void) ::cache_monitor(addr_t addr)
 /////////////////////////////////////////////////////
 {
-  DirectoryEntry entry = m_cache_directory.read_neutral(addr);
-
-  if((entry.count != m_debug_previous_count) or
-      (entry.valid != m_debug_previous_hit))
-  {
-    std::cout << "Monitor MEMC " << name()
-              << " at cycle " << std::dec << m_cpt_cycles
-              << " for address " << std::hex << addr
-              << " / HIT = " << entry.valid
-              << " / COUNT = " << std::dec << entry.count << std::endl;
-  }
-  m_debug_previous_count = entry.count;
-  m_debug_previous_hit = entry.valid;
+    size_t way = 0;
+    size_t set = 0;
+    DirectoryEntry entry = m_cache_directory.read_neutral(addr, &way, &set );
+
+    bool data_change = false;
+
+    if ( entry.valid )
+    {
+        m_cache_data.read_line( way, set, m_debug_data );
+
+        for ( size_t i = 0 ; i<m_words ; i++ )
+        {
+            if ( m_debug_previous_valid and
+                 (m_debug_data[i].read() != m_debug_previous_data[i].read()) )
+                 data_change = true;
+            m_debug_previous_data[i] = m_debug_data[i].read();
+        }
+    }
+    
+    if ( (entry.valid != m_debug_previous_valid) or
+         (entry.valid and (entry.count != m_debug_previous_count)) or
+         (entry.valid 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
+                  << " / HIT = " << std::dec << entry.valid
+                  << " / WAY = " << way
+                  << " / COUNT = " << entry.count 
+                  << " / DIRTY = " << entry.dirty
+                  << " / DATA_CHANGE = " << entry.count 
+                  << std::endl;
+    }
+    m_debug_previous_count = entry.count;
+    m_debug_previous_valid = entry.valid;
+    m_debug_previous_dirty = entry.dirty;
 }
 
@@ -683,5 +707,6 @@
 
     m_debug                = false;
-    m_debug_previous_hit   = false;
+    m_debug_previous_valid = false;
+    m_debug_previous_dirty = false;
     m_debug_previous_count = 0;
 
@@ -1428,5 +1453,5 @@
   //
   // From the software point of view, a configuration request is a sequence
-  // of 6 atomic accesses:
+  // of 6 atomic accesses in an uncached segment:
   // - Read  MEMC_LOCK       : Get the lock
   // - Write MEMC_ADDR_LO    : Set the buffer address LSB
@@ -1583,4 +1608,5 @@
                                   nb_copies,
                                   index);
+
                   if ( wok )  // UPT success => inval DIR slot
                   {
@@ -1865,5 +1891,6 @@
         DirectoryEntry entry =
           m_cache_directory.read(m_cmd_read_addr_fifo.read(), way);
-        if((m_cmd_read_pktid_fifo.read() & 0x7) == TYPE_LL)   // access the global table ONLY when we have an LL cmd
+        // access the global table ONLY when we have an LL cmd
+        if((m_cmd_read_pktid_fifo.read() & 0x7) == TYPE_LL)   
         {
           r_read_ll_key   = m_llsc_table.ll(m_cmd_read_addr_fifo.read());
@@ -1927,68 +1954,70 @@
 
     //////////////////
-    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 replcated
-
-      if(r_alloc_dir_fsm.read() == ALLOC_DIR_READ)
-      {
-        // 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() & 0x1);
-        bool is_cnt       = r_read_is_cnt.read();
-
-        // 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.valid   = true;
-        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_cnt)  // Not counter mode
-          {
-            entry.owner.srcid    = m_cmd_read_srcid_fifo.read();
+    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
+
+    {
+        if(r_alloc_dir_fsm.read() == ALLOC_DIR_READ)
+        {
+            // 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() & 0x1);
+            bool is_cnt       = r_read_is_cnt.read();
+
+            // 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);
+
+            if(m_monitor_ok) check_monitor( m_cmd_read_addr_fifo.read(), r_read_data[0], true);
+
+            // update the cache directory
+            DirectoryEntry entry;
+            entry.valid   = true;
+            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_cnt)  // Not counter mode
+                {
+                    entry.owner.srcid    = m_cmd_read_srcid_fifo.read();
 #if L1_MULTI_CACHE
-            entry.owner.cache_id = m_cmd_read_pktid_fifo.read();
-#endif
-            entry.owner.inst     = inst_read;
-            entry.count          = r_read_count.read() + 1;
-          }
-          else  // Counter mode
-          {
-            entry.owner.srcid    = 0;
+                    entry.owner.cache_id = m_cmd_read_pktid_fifo.read();
+#endif
+                    entry.owner.inst     = inst_read;
+                    entry.count          = r_read_count.read() + 1;
+                }
+                else  // Counter mode
+                {
+                    entry.owner.srcid    = 0;
 #if L1_MULTI_CACHE
-            entry.owner.cache_id = 0;
-#endif
-            entry.owner.inst     = false;
-            entry.count          = r_read_count.read() + 1;
-          }
-        }
-        else  // Uncached read
-        {
-          entry.owner.srcid     = r_read_copy.read();
+                    entry.owner.cache_id = 0;
+#endif
+                    entry.owner.inst     = false;
+                    entry.count          = r_read_count.read() + 1;
+                }
+            }
+            else            // Uncached read
+            {
+                entry.owner.srcid     = r_read_copy.read();
 #if L1_MULTI_CACHE
-          entry.owner.cache_id  = r_read_copy_cache.read();
-#endif
-          entry.owner.inst      = r_read_copy_inst.read();
-          entry.count           = r_read_count.read();
-        }
+                entry.owner.cache_id  = r_read_copy_cache.read();
+#endif
+                entry.owner.inst      = r_read_copy_inst.read();
+                entry.count           = r_read_count.read();
+            }
 
 #if DEBUG_MEMC_READ
@@ -2004,20 +2033,9 @@
 #endif
 
-          if(m_monitor_ok)
-          {
-            char buf[80];
-            snprintf(buf, 80, "READ_DIR_HIT srcid %d, ins %d",
-                     (int)m_cmd_read_srcid_fifo.read(),
-                     (int)((m_cmd_read_pktid_fifo.read()&0x2)!=0));
-            check_monitor(buf, m_cmd_read_addr_fifo.read(), r_read_data[0], true);
-          }
-
-
-        m_cache_directory.write(set, way, entry);
-        r_read_fsm    = READ_RSP;
-      }
-      break;
-    }
-
+            m_cache_directory.write(set, way, entry);
+            r_read_fsm    = READ_RSP;
+        }
+        break;
+    }
     ///////////////////
     case READ_HEAP_REQ:    // Get the lock to the HEAP directory
@@ -2050,4 +2068,6 @@
 
         m_cache_data.read_line(way, set, r_read_data);
+
+        if(m_monitor_ok) check_monitor( m_cmd_read_addr_fifo.read(), r_read_data[0], true);
 
         // update the cache directory
@@ -2417,11 +2437,9 @@
 
 #if DEBUG_MEMC_WRITE
-        if(m_debug)
-        {
-          std::cout << "  <MEMC " << name() << " WRITE_IDLE> Write request "
-                    << " srcid = " << std::dec << m_cmd_write_srcid_fifo.read()
-                    << " / address = " << std::hex << m_cmd_write_addr_fifo.read()
-                    << " / data = " << m_cmd_write_data_fifo.read() << std::endl;
-        }
+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() << std::endl;
 #endif
       }
@@ -2436,10 +2454,8 @@
 
 #if DEBUG_MEMC_WRITE
-        if(m_debug)
-        {
-          std::cout << "  <MEMC " << name()
-                    << " WRITE_NEXT> Write another word in local buffer"
-                    << std::endl;
-        }
+if(m_debug)
+std::cout << "  <MEMC " << name()
+          << " WRITE_NEXT> Write another word in local buffer"
+          << std::endl;
 #endif
         m_cpt_write_cells++;
@@ -2520,10 +2536,7 @@
 
 #if DEBUG_MEMC_WRITE
-      if(m_debug)
-      {
-        std::cout
-            << "  <MEMC " << name() << " WRITE_DIR_REQ> Requesting DIR lock "
-            << std::endl;
-      }
+if(m_debug)
+std::cout << "  <MEMC " << name() << " WRITE_DIR_REQ> Requesting DIR lock "
+          << std::endl;
 #endif
 
@@ -2532,6 +2545,5 @@
 
     ////////////////////
-    case WRITE_DIR_LOCK:
-      // access directory to check hit/miss
+    case WRITE_DIR_LOCK:     // access directory to check hit/miss
     {
       if(r_alloc_dir_fsm.read() == ALLOC_DIR_WRITE)
@@ -2570,16 +2582,16 @@
 
 #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.valid
-                    << " count = " << entry.count
-                    << " is_cnt = " << entry.is_cnt << std::endl;
-          if((r_write_pktid.read() & 0x7) == TYPE_SC)
-            std::cout << "  <MEMC " << name() << " WRITE_DIR_LOCK> global_llsc_table SC access" << std::endl;
-          else
-            std::cout << "  <MEMC " << name() << " WRITE_DIR_LOCK> global_llsc_table SW access" << std::endl;
-        }
+if(m_debug)
+{
+std::cout << "  <MEMC " << name() << " WRITE_DIR_LOCK> Check the directory: "
+          << " address = " << std::hex << r_write_address.read()
+          << " / hit = " << std::dec << entry.valid
+          << " / 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
       }
@@ -2592,8 +2604,6 @@
         exit(0);
       }
-
-      break;
-    }
-
+      break;
+    }
     ////////////////////
     case WRITE_DIR_READ:  // read the cache and complete the buffer when be!=0xF
@@ -2620,8 +2630,7 @@
 
 #if DEBUG_MEMC_WRITE
-      if(m_debug)
-      {
-        std::cout << "  <MEMC " << name() << " WRITE_DIR_READ> Read the cache to complete local buffer" << std::endl;
-      }
+if(m_debug)
+std::cout << "  <MEMC " << name() << " WRITE_DIR_READ>"
+          << " Read the cache to complete local buffer" << std::endl;
 #endif
       break;
@@ -2636,5 +2645,5 @@
       entry.valid          = true;
       entry.dirty          = true;
-      entry.tag          = r_write_tag.read();
+      entry.tag            = r_write_tag.read();
       entry.is_cnt         = r_write_is_cnt.read();
       entry.lock           = r_write_lock.read();
@@ -2663,5 +2672,6 @@
       // (tests for sc requests)
       bool no_update = ( (r_write_count.read() == 0) or
-                         (owner and (r_write_count.read() ==1) and (r_write_pktid.read() != TYPE_SC)));
+                         (owner and (r_write_count.read() ==1) and 
+                         (r_write_pktid.read() != TYPE_SC)));
 
       // write data in the cache if no coherence transaction
@@ -2675,8 +2685,5 @@
           {
             addr_t address = (r_write_address.read() & ~(addr_t) 0x3F) | word<<2;
-            char buf[80];
-            snprintf(buf, 80, "WRITE_DIR_HIT srcid %d",
-                     (int)r_write_srcid.read());
-            check_monitor(buf, address, r_write_data[word].read(), false);
+            check_monitor( address, r_write_data[word].read(), false);
           }
         }
@@ -2727,5 +2734,4 @@
       break;
     }
-
     ////////////////////
     case WRITE_UPT_LOCK:  // Try to register the update request in UPT
@@ -2766,7 +2772,5 @@
             {
               addr_t address = (r_write_address.read() & ~(addr_t) 0x3F) | word<<2;
-              char buf[80];
-              snprintf(buf, 80, "WRITE_UPT_LOCK srcid %d", (int)srcid);
-              check_monitor(buf, address, r_write_data[word].read(), false);
+              check_monitor( address, r_write_data[word].read(), false);
             }
           }
@@ -3868,5 +3872,5 @@
         {
           addr_t address = r_xram_rsp_trt_buf.nline<<6 | word<<2;
-          check_monitor("XRAM_RSP_DIR_UPDT", address, r_xram_rsp_trt_buf.wdata[word], false);
+          check_monitor( address, r_xram_rsp_trt_buf.wdata[word], false);
         }
       }
@@ -5262,11 +5266,8 @@
         {
           addr_t address = m_cmd_cas_addr_fifo.read();
-          char buf[80];
-          snprintf(buf, 80, "CAS_DIR_HIT_WRITE srcid %d",
-                   (int)m_cmd_cas_srcid_fifo.read());
-          check_monitor(buf, address, r_cas_wdata.read(), false);
+          check_monitor( address, r_cas_wdata.read(), false);
 
           if(r_cas_cpt.read() == 4)
-            check_monitor(buf, address+4, m_cmd_cas_wdata_fifo.read(), false);
+            check_monitor( address+4, m_cmd_cas_wdata_fifo.read(), false);
         }
 
@@ -5327,11 +5328,8 @@
           {
             addr_t address = m_cmd_cas_addr_fifo.read();
-            char buf[80];
-            snprintf(buf, 80, "CAS_DIR_HIT_WRITE srcid %d",
-                     (int)m_cmd_cas_srcid_fifo.read());
-            check_monitor(buf, address, r_cas_wdata.read(), false);
+            check_monitor( address, r_cas_wdata.read(), false);
 
             if(r_cas_cpt.read() ==4)
-              check_monitor(buf, address+4, m_cmd_cas_wdata_fifo.read(), false);
+              check_monitor( address+4, m_cmd_cas_wdata_fifo.read(), false);
           }
         }
@@ -5564,10 +5562,8 @@
           {
             addr_t address = m_cmd_cas_addr_fifo.read();
-            char buf[80];
-            snprintf(buf, 80, "CAS_DIR_HIT_WRITE srcid %d",
-                     (int)m_cmd_cas_srcid_fifo.read());
-            check_monitor(buf, address, r_cas_wdata.read(), false);
+            check_monitor( address, r_cas_wdata.read(), false);
+
             if(r_cas_cpt.read() ==4)
-              check_monitor(buf, address+4, m_cmd_cas_wdata_fifo.read(), false);
+              check_monitor( address+4, m_cmd_cas_wdata_fifo.read(), false);
           }
           r_cas_upt_index = index;
